1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6319],{11640:(e,t,a)=>{"use strict";a.d(t,{V:()=>s});var n=a(95155),l=a(51115);let i=["eq","neq","gt","gte","lt","lte","contains","not_contains","contains_all","contains_any","in","not_in","exists","not_exists"];function s(e){var t;let{value:a,onChange:s,traits:r,classes:o,idPrefix:d,subject:c="class"}=e,u=a&&("trait"===a.kind||"class"===a.kind)?a:{kind:"none"},h=!!(a&&"trait"!==a.kind&&"class"!==a.kind);return(0,n.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,n.jsx)(l.D0,{label:"Eligibility type",htmlFor:"".concat(d,"-eligibility-kind"),children:(0,n.jsxs)(l.IM,{id:"".concat(d,"-eligibility-kind"),value:h?"complex":u.kind,onChange:e=>{var t,a;"none"===e.target.value&&s(null),"trait"===e.target.value&&s({kind:"trait",trait_id:(null==(t=r[0])?void 0:t.id)||"trait_id",operator:"gte",value:0}),"class"===e.target.value&&s({kind:"class",class_id:(null==(a=o[0])?void 0:a.id)||"class_id",operator:"assigned"})},children:[(0,n.jsx)("option",{value:"none",children:"story"===c?"Anyone can play":"No requirement"}),(0,n.jsx)("option",{value:"trait",children:"Trait requirement"}),(0,n.jsx)("option",{value:"class",children:"Class requirement"}),h?(0,n.jsx)("option",{value:"complex",children:"Compound rule (preserved)"}):null]})}),"trait"===u.kind?(0,n.jsx)(l.D0,{label:"Trait",htmlFor:"".concat(d,"-trait-id"),children:(0,n.jsxs)(l.IM,{id:"".concat(d,"-trait-id"),value:u.trait_id,onChange:e=>s({...u,trait_id:e.target.value}),children:[0===r.length?(0,n.jsx)("option",{value:u.trait_id,children:"Define a trait first"}):null,r.map(e=>(0,n.jsx)("option",{value:e.id,children:e.name},e.id))]})}):null,"class"===u.kind?(0,n.jsx)(l.D0,{label:"Class",htmlFor:"".concat(d,"-class-id"),children:(0,n.jsxs)(l.IM,{id:"".concat(d,"-class-id"),value:u.class_id,onChange:e=>s({...u,class_id:e.target.value}),children:[0===o.length?(0,n.jsx)("option",{value:u.class_id,children:"Define a class first"}):null,o.map(e=>(0,n.jsx)("option",{value:e.id,children:e.name},e.id))]})}):null,"trait"===u.kind?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(l.D0,{label:"Comparison",htmlFor:"".concat(d,"-trait-operator"),children:(0,n.jsx)(l.IM,{id:"".concat(d,"-trait-operator"),value:u.operator,onChange:e=>s({...u,operator:e.target.value}),children:i.map(e=>(0,n.jsx)("option",{value:e,children:e.replaceAll("_"," ")},e))})}),["exists","not_exists"].includes(u.operator)?null:(0,n.jsx)(l.D0,{label:"Required value",hint:"Numbers and true/false are saved as typed values.",htmlFor:"".concat(d,"-trait-value"),children:(0,n.jsx)(l.ks,{id:"".concat(d,"-trait-value"),value:"string"==typeof u.value?u.value:JSON.stringify(null!=(t=u.value)?t:""),onChange:e=>s({...u,value:(0,l.N5)(e.target.value)})})})]}):null,"class"===u.kind?(0,n.jsx)(l.D0,{label:"Requirement",htmlFor:"".concat(d,"-class-operator"),children:(0,n.jsxs)(l.IM,{id:"".concat(d,"-class-operator"),value:u.operator,onChange:e=>s({...u,operator:e.target.value}),children:[(0,n.jsx)("option",{value:"assigned",children:"Must be assigned"}),(0,n.jsx)("option",{value:"not_assigned",children:"Must not be assigned"})]})}):null,h?(0,n.jsxs)("p",{className:"self-end text-[11px] leading-5 text-[#a99a80] sm:col-span-2",children:["This ","story"===c?"Story":"class"," already uses a compound eligibility rule. It is preserved until you replace it with a simple trait or class requirement."]}):null]})}},16585:(e,t,a)=>{"use strict";a.d(t,{W:()=>d,i:()=>c});var n=a(95155),l=a(12115),i=a(63263),s=a(59338),r=a(47027),o=a(94515);let d=["location","character","faction","item","lore","rule","event"];function c(e){var t;let{initialKind:a,initialGroup:c,groups:u,preference:h,onSubmit:m,allowanceVersion:p=0,onDirty:x}=e,[g,v]=(0,l.useState)(a),[j,b]=(0,l.useState)(""),[y,f]=(0,l.useState)(""),[w,k]=(0,l.useState)(""),[C,N]=(0,l.useState)(c||""),_=!!(y.trim()||w.trim()||"element"===g&&j);(0,l.useEffect)(()=>{null==x||x(_)},[_,x]);let S=(0,r.l)(!0),D=(0,l.useRef)(p);(0,l.useEffect)(()=>{D.current!==p&&(D.current=p,S.refresh())},[p,S]);let A=h.loading||h.saving||!!h.error||!y.trim()||"element"===g&&!j||h.generateImage&&(S.loading||!S.allowance||S.allowance.remaining<=0);return(0,n.jsxs)("div",{children:["element"!==a&&(0,n.jsx)("nav",{className:"sg-panel-tabs",children:["story","group"].map(e=>(0,n.jsx)("button",{"aria-pressed":g===e,onClick:()=>v(e),children:"story"===e?"Story":"Story group"},e))}),(0,n.jsx)("h2",{className:"font-serif-accent text-2xl",children:"element"!==g||j?"New ".concat("group"===g?"story group":"element"===g?j:"story"):"What belongs here?"}),"element"!==g||j?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("fieldset",{children:[(0,n.jsxs)("label",{children:["Name",(0,n.jsx)("input",{value:y,maxLength:120,onChange:e=>f(e.target.value)})]}),"group"!==g&&(0,n.jsxs)("label",{children:["Description",(0,n.jsx)("textarea",{rows:5,value:w,onChange:e=>k(e.target.value)})]}),"story"===g&&u.length>0&&(0,n.jsxs)("label",{children:["Story group",(0,n.jsxs)("select",{value:C,onChange:e=>N(e.target.value),children:[(0,n.jsx)("option",{value:"",children:"Ungrouped"}),u.map(e=>(0,n.jsx)("option",{value:e.id,children:e.name},e.id))]})]})]}),(0,n.jsxs)("label",{className:"flex items-center justify-between gap-3",children:[(0,n.jsx)("span",{children:"Generate image"}),(0,n.jsx)("input",{type:"checkbox",checked:h.generateImage,disabled:h.loading||h.saving,onChange:e=>void h.choose(e.target.checked)})]}),(0,n.jsx)("p",{className:"text-xs text-[#b2afa8]",children:S.loading?"Loading image allowanceâ¦":S.allowance?"".concat(S.allowance.remaining," images remaining"):"Image allowance unavailable."}),S.error&&(0,n.jsxs)("p",{role:"alert",className:"mt-2 text-xs",children:[S.error," ",(0,n.jsx)("button",{onClick:()=>void S.refresh(),children:"Retry allowance"})]}),h.error&&(0,n.jsxs)("p",{role:"alert",className:"mt-2 text-xs",children:[h.error," ",(0,n.jsx)("button",{onClick:()=>void h.reload(),children:"Retry preference"})]}),h.generateImage&&(null==(t=S.allowance)?void 0:t.remaining)===0&&(0,n.jsx)("p",{className:"mt-3 text-xs",children:"Turn off Generate image to create without artwork."}),(0,n.jsxs)("button",{className:"sg-primary mt-6",disabled:A,onClick:()=>void(!A&&(m({kind:g,name:y.trim(),description:w.trim(),type:j,groupId:C||null},h.generateImage),f(""),k(""),null==x||x(!1))),children:[(0,n.jsx)(s.A,{size:14}),"Create ","group"===g?"story group":g]})]}):d.map(e=>(0,n.jsxs)("button",{className:"flex w-full items-center gap-4 border-b border-white/10 py-4 text-left",onClick:()=>b(e),children:[(0,n.jsx)(o.aw,{type:e}),(0,n.jsx)("span",{className:"flex-1 capitalize",children:e}),(0,n.jsx)(i.A,{size:16})]},e))]})}},27585:(e,t,a)=>{"use strict";a.d(t,{h:()=>i});var n=a(62114);let l=e=>"/storybooks/".concat(encodeURIComponent(e),"/journey"),i={admin:async(e,t)=>(await n.api.request({url:"".concat(l(e),"/config"),method:"GET",signal:t})).data,save:async(e,t,a)=>(await n.api.request({url:"".concat(l(e),"/config"),method:"PUT",data:{config:t,expected_revision:a}})).data,read:async(e,t,a)=>(await n.api.request({url:"".concat(l(e)).concat(void 0!==t?"?persona_id=".concat(encodeURIComponent(t||"self")):""),method:"GET",signal:a})).data}},46347:()=>{},69545:e=>{e.exports={drawer:"WorkspaceDrawer_drawer__1lnkm",enter:"WorkspaceDrawer_enter__U4_2X",shade:"WorkspaceDrawer_shade___A3b1"}},76319:(e,t,a)=>{"use strict";a.d(t,{default:()=>H});var n=a(95155),l=a(12115),i=a(55253),s=a(87205),r=a(32265),o=a(90109),d=a(63263),c=a(51190),u=a(20063),h=a(62114),m=a(98460),p=a(51115),x=a(99805),g=a(34282),v=a(90320),j=a(59317),b=a(11640);let y=[{value:"number",label:"Number"},{value:"currency",label:"Currency"},{value:"rank",label:"Ordered rank"},{value:"text",label:"Text / choice"},{value:"boolean",label:"Yes / no"},{value:"unlock_set",label:"Unlock collection"}];function f(e,t){let a={id:"new_trait_".concat(t+1),name:"New trait",description:"",scope:"persona"};return"currency"===e?{...a,type:e,min:0,precision:0,default_value:0}:"rank"===e?{...a,type:e,levels:[{id:"starting_rank",label:"Starting rank"}],default_value:"starting_rank"}:"text"===e?{...a,type:e,min_length:0,max_length:500,default_value:""}:"boolean"===e?{...a,type:e,default_value:!1}:"unlock_set"===e?{...a,type:e,unlocks:[],default_value:[]}:{...a,type:e,integer:!0,default_value:0}}let w=new Set(["number","currency","rank","text","boolean"]);function k(e){let{value:t,persisted:a,definition:l,onChange:i}=e,s="type"in t?t:null;return(0,n.jsxs)("div",{className:"space-y-5",children:[(0,n.jsx)(p.D0,{label:"Name",htmlFor:"definition-name",children:(0,n.jsx)(p.ks,{id:"definition-name",value:t.name,onChange:e=>i({...t,name:e.target.value})})}),(0,n.jsx)(p.D0,{label:"Description",htmlFor:"definition-description",children:(0,n.jsx)(p.fs,{id:"definition-description",value:t.description||"",onChange:e=>i({...t,description:e.target.value})})}),s&&(0,n.jsx)(p.D0,{label:"Tracks",htmlFor:"definition-type",children:(0,n.jsx)(p.IM,{id:"definition-type",disabled:a,value:s.type,onCh
1ange:e=>i({...f(e.target.value,0),id:s.id,name:s.name,description:s.description,scope:s.scope,discovery:s.discovery}),children:y.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})}),(0,n.jsx)(p.D0,{label:"Belongs to",htmlFor:"definition-scope",children:(0,n.jsxs)(p.IM,{id:"definition-scope",disabled:a,value:t.scope,onChange:e=>{let a=e.target.value;if(s&&"persona"!==a)return void i({...s,scope:a,initial:void 0,discovery:"known"});i({...t,scope:a})},children:[(0,n.jsx)("option",{value:"persona",children:"Each Persona"}),(0,n.jsx)("option",{value:"storybook",children:"The shared world"})]})}),s?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(S,{trait:s,prefix:"definition",persisted:a,onChange:i}),(0,n.jsx)(C,{trait:s,prefix:"definition",onChange:i})]}):(0,n.jsx)(b.V,{value:t.eligibility,traits:l.traits,classes:l.classes.filter(e=>e.id!==t.id),idPrefix:"class",onChange:e=>{let a={...t};e?a.eligibility=e:delete a.eligibility,i(a)}}),(0,n.jsxs)("details",{children:[(0,n.jsx)("summary",{className:"cursor-pointer text-sm text-[#aaa59c]",children:"Advanced"}),(0,n.jsx)(p.D0,{label:"Stable ID",hint:a?"Used by existing rules and saved progress.":"An identifier for rules that refer to this entry.",htmlFor:"definition-id",children:(0,n.jsx)(p.ks,{id:"definition-id",disabled:a,value:t.id,onChange:e=>i({...t,id:e.target.value.toLowerCase().trim().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"").slice(0,128)})})})]})]})}function C(e){let{trait:t,prefix:a,onChange:l}=e;if("persona"!==t.scope)return null;let i=t.initial||{mode:"default"},s=w.has(t.type),r="rank"===t.type?t.levels.map(e=>({id:e.id,label:e.label})):"text"===t.type?(t.allowed_values||[]).map(e=>({id:e,label:e})):[],o=("rank"===t.type||"text"===t.type)&&0===r.length,d=e=>l({...t,initial:e});return(0,n.jsxs)("div",{className:"space-y-5 border-t border-white/10 pt-5",children:[(0,n.jsx)(p.D0,{label:"Starting value",hint:s?"Every Persona starts the same, or is dealt one when they join.":"A collection always starts from its configured unlocks.",htmlFor:"".concat(a,"-initial-mode"),children:(0,n.jsxs)(p.IM,{id:"".concat(a,"-initial-mode"),disabled:!s||o,value:i.mode,onCh
1ange:e=>d("random"===e.target.value?function(e){if("boolean"===e.type)return{mode:"random",probability:.5};if("number"===e.type||"currency"===e.type){var t,a;return{mode:"random",min:null!=(t=e.min)?t:e.default_value,max:null!=(a=e.max)?a:e.default_value}}return{mode:"random"}}(t):{mode:"default"}),children:[(0,n.jsx)("option",{value:"default",children:"Fixed â the default above"}),(0,n.jsx)("option",{value:"random",children:"Random â rolled when they join"})]})}),o?(0,n.jsxs)("p",{className:"text-xs text-[#aaa59c]",children:["Add ","rank"===t.type?"ranks":"allowed choices"," before this trait can be rolled."]}):null,"random"===i.mode&&s?(0,n.jsx)(N,{trait:t,prefix:a,initial:i,choices:r,onChange:d}):null,(0,n.jsx)(p.D0,{label:"Discovery",hint:"A hidden value is real from the moment it is rolled: the world and the narrator know it, and the Persona is told only what a Story reveals.",htmlFor:"".concat(a,"-discovery"),children:(0,n.jsxs)(p.IM,{id:"".concat(a,"-discovery"),value:t.discovery||"known",onChange:e=>l({...t,discovery:e.target.value}),children:[(0,n.jsx)("option",{value:"known",children:"Known â the Persona sees it"}),(0,n.jsx)("option",{value:"hidden",children:"Hidden until revealed"})]})})]})}function N(e){var t,a,l;let{trait:i,prefix:s,initial:r,choices:o,onChange:d}=e;if("boolean"===i.type)return(0,n.jsx)(p.D0,{label:"Chance of yes",hint:"Between 0 and 1.",htmlFor:"".concat(s,"-probability"),children:(0,n.jsx)(p.ks,{id:"".concat(s,"-probability"),type:"number",min:0,max:1,step:.05,value:null!=(t=r.probability)?t:.5,onChange:e=>d({...r,probability:Number(e.target.value)})})});if("number"===i.type||"currency"===i.type)return(0,n.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,n.jsx)(p.D0,{label:"Lowest roll",htmlFor:"".concat(s,"-initial-min"),children:(0,n.jsx)(p.ks,{id:"".concat(s,"-initial-min"),type:"number",value:null!=(a=r.min)?a:"",onChange:e=>d({...r,min:""===e.target.value?void 0:Number(e.target.value)})})}),(0,n.jsx)(p.D0,{label:"Highest roll",htmlFor:"".concat(s,"-initial-max"),children:(0,n.jsx)(p.ks,{id:"".concat(s,"-initial-max"),type:"number",value:null!=(l=r.max)?l:"",onChange:e=>d({...r,max:""===e.target.value?void 0:Number(e.target.value)})})})]});let c=e=>{var t,a;return null!=(a=null==(t=r.weights)?void 0:t[e])?a:1},u=e=>!r.weights||void 0!==r.weights[e],h=e=>{let t=o.every(t=>1===e[t.id]);d({...r,weights:t?void 0:e})},m=()=>Object.fromEntries(o.filter(e=>u(e.id)).map(e=>[e.id,c(e.id)]));return(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsx)("p",{className:"text-sm",children:"Which may come up, and how often"}),o.map(e=>(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("input",{"aria-label":"".concat(e.label," may be rolled"),type:"checkbox",checked:u(e.id),onChange:t=>{let a=m();t.target.checked?a[e.id]=1:delete a[e.id],h(a)}}),(0,n.jsx)("span",{className:"flex-1 text-[13px] text-[#ddd3c3]",children:e.label}),(0,n.jsx)(p.ks,{"aria-label":"".concat(e.label," weight"),type:"number",min:1,className:"w-24",disabled:!u(e.id),value:u(e.id)?c(e.id):"",onChange:t=>h({...m(),[e.id]:Number(t.target.value)})})]},e.id)),(0,n.jsx)("p",{className:"text-xs text-[#aaa59c]",children:"Equal weights roll evenly. An unchecked option is never dealt."})]})}function _(e){let{items:t,defaults:a,multiple:l=!1,persisted:i,onChange:s}=e;return(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsx)("p",{className:"text-sm",children:l?"Available unlocks":"Ranks, lowest to highest"}),t.map((e,r)=>(0,n.jsxs)("div",{className:"space-y-2 border-b border-white/10 pb-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-[#aaa59c]",children:r+1}),(0,n.jsx)(p.ks,{"aria-label":"".concat(l?"Unlock":"Rank"," ").concat(r+1),value:e.label,onChange:e=>s(t.map((t,a)=>a===r?{...t,label:e.target.value}:t),a)}),(0,n.jsx)("input",{"aria-label":"".concat(e.label," default"),type:l?"checkbox":"radio",name:"definition-default-choice",checked:a.includes(e.id),onChange:n=>s(t,l?n.target.checked?[...a,e.id]:a.filter(t=>t!==e.id):[e.id])})]}),(0,n.jsx)(p.ks,{"aria-label":"".concat(e.label," description"),placeholder:"Description (optional)",value:e.description||"",onChange:e=>s(t.map((t,a)=>a===r?{...t,description:e.target.value}:t),a)}),(0,n.jsxs)("div",{className:"flex gap-3 text-xs",children:[(0,n.jsx)("button",{type:"button",disabled:0===r||i,onClick:()=>{let e=[...t];[e[r-1],e[r]]=[e[r],e[r-1]],s(e,a)},children:"Move up"}),(0,n.jsx)("button",{type:"button",disabled:i||!l&&t.length<2,onClick:()=>s(t.filter((e,t)=>
1r!==t),a.filter(t=>t!==e.id)),children:"Remove"})]})]},e.id)),(0,n.jsxs)(p.tA,{onClick:()=>{let e={id:crypto.randomUUID(),label:l?"New unlock":"New rank"};s([...t,e],a.length||l?a:[e.id])},children:["Add ",l?"unlock":"rank"]}),(0,n.jsx)("p",{className:"text-xs text-[#aaa59c]",children:l?"Select the unlocks granted by default.":"Select the starting rank."})]})}function S(e){var t,a,l;let{trait:i,prefix:s,onChange:r,persisted:o}=e;return"number"===i.type?(0,n.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-4",children:[(0,n.jsx)(p.D0,{label:"Default",htmlFor:"".concat(s,"-default"),children:(0,n.jsx)(p.ks,{id:"".concat(s,"-default"),type:"number",value:i.default_value,onChange:e=>r({...i,default_value:Number(e.target.value)})})}),(0,n.jsx)(p.D0,{label:"Minimum",htmlFor:"".concat(s,"-min"),children:(0,n.jsx)(p.ks,{id:"".concat(s,"-min"),type:"number",value:null!=(t=i.min)?t:"",onChange:e=>r({...i,min:""===e.target.value?void 0:Number(e.target.value)})})}),(0,n.jsx)(p.D0,{label:"Maximum",htmlFor:"".concat(s,"-max"),children:(0,n.jsx)(p.ks,{id:"".concat(s,"-max"),type:"number",value:null!=(a=i.max)?a:"",onChange:e=>r({...i,max:""===e.target.value?void 0:Number(e.target.value)})})}),(0,n.jsx)(p.lM,{checked:i.integer,onChange:e=>r({...i,integer:e}),label:"Whole numbers only"})]}):"currency"===i.type?(0,n.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-4",children:[(0,n.jsx)(p.D0,{label:"Default",htmlFor:"".concat(s,"-default"),children:(0,n.jsx)(p.ks,{id:"".concat(s,"-default"),type:"number",value:i.default_value,onChange:e=>r({...i,default_value:Number(e.target.value)})})}),(0,n.jsx)(p.D0,{label:"Minimum",htmlFor:"".concat(s,"-min"),children:(0,n.jsx)(p.ks,{id:"".concat(s,"-min"),type:"number",value:i.min,onChange:e=>r({...i,min:Number(e.target.value)})})}),(0,n.jsx)(p.D0,{label:"Maximum",htmlFor:"".concat(s,"-max"),children:(0,n.jsx)(p.ks,{id:"".concat(s,"-max"),type:"number",value:null!=(l=i.max)?l:"",onChange:e=>r({...i,max:""===e.target.value?void 0:Number(e.target.value)})})}),(0,n.jsx)(p.D0,{label:"Decimal places",htmlFor:"".concat(s,"-precision"),children:(0,n.jsx)(p.ks,{id:"".concat(s,"-precision"),type:"number",min:0,max:6,value:i.precision,onChange:e=>r({...i,precision:Number(e.target.value)})})})]}):"rank"===i.type?(0,n.jsx)(_,{items:i.levels,defaults:[i.default_value],persisted:o,onChange:(e,t)=>
1{var a;return r({...i,levels:e,default_value:t[0]||(null==(a=e[0])?void 0:a.id)||""})}}):"text"===i.type?(0,n.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2 xl:grid-cols-4",children:[(0,n.jsx)(p.D0,{label:"Default text",htmlFor:"".concat(s,"-default"),children:(0,n.jsx)(p.ks,{id:"".concat(s,"-default"),value:i.default_value,onChange:e=>r({...i,default_value:e.target.value})})}),(0,n.jsx)(p.D0,{label:"Minimum length",htmlFor:"".concat(s,"-min-length"),children:(0,n.jsx)(p.ks,{id:"".concat(s,"-min-length"),type:"number",min:0,value:i.min_length,onChange:e=>r({...i,min_length:Number(e.target.value)})})}),(0,n.jsx)(p.D0,{label:"Maximum length",htmlFor:"".concat(s,"-max-length"),children:(0,n.jsx)(p.ks,{id:"".concat(s,"-max-length"),type:"number",min:1,max:1e4,value:i.max_length,onChange:e=>r({...i,max_length:Number(e.target.value)})})}),(0,n.jsx)(p.D0,{label:"Allowed choices",hint:"Optional, separated by commas.",htmlFor:"".concat(s,"-choices"),children:(0,n.jsx)(p.ks,{id:"".concat(s,"-choices"),value:(i.allowed_values||[]).join(", "),onChange:e=>r({...i,allowed_values:(0,p.E1)(e.target.value).length?(0,p.E1)(e.target.value):void 0})})})]}):"boolean"===i.type?(0,n.jsx)(p.lM,{checked:i.default_value,onChange:e=>r({...i,default_value:e}),label:"Enabled by default",description:"New scope records begin with this value."}):(0,n.jsx)(_,{items:i.unlocks,defaults:i.default_value,multiple:!0,persisted:o,onChange:(e,t)=>
1r({...i,unlocks:e,default_value:t})})}var D=a(94515),A=a(16585),F=a(22539),I=a(76122);function E(e,t,a){let n=new Set([e]);for(;t;){var l;if(n.has(t))return!1;n.add(t),t=(null==(l=a[t])?void 0:l.parent_id)||null}return!0}a(8301);let M={catalog:function(e){let{data:t,isConnectable:a}=e;return(0,n.jsxs)("div",{className:"wc-node",children:[(0,n.jsx)(F.h7,{type:"target",position:I.yX.Left,className:t.incoming?"attached":"",isConnectable:a}),(0,n.jsx)("strong",{children:t.entry.name}),(0,n.jsx)("small",{children:"type"in t.entry?t.entry.type.replace("_"," "):"Class"}),t.children>0&&(0,n.jsxs)("button",{type:"button",className:"nodrag",onClick:e=>{e.stopPropagation(),t.expand()},children:[t.children," within \xb7 expand / collapse"]}),(0,n.jsx)(F.h7,{type:"source",position:I.yX.Right,className:t.outgoing?"attached":"",isConnectable:a})]})}};function R(e){return(0,n.jsx)(F.Ln,{children:(0,n.jsx)(T,{...e})})}function T(e){var t;let{entries:a,allEntries:i,placements:s,editable:r,onOpen:o,onSave:d}=e,[c,u]=(0,l.useState)(""),[h,m]=(0,l.useState)([]),[p,x]=(0,l.useState)(null),g=(0,F.VH)(),v=(0,l.useMemo)(()=>a.reduce((e,t)=>{var a;let n=(null==(a=s[t.id])?void 0:a.parent_id)||"";return(e[n]||(e[n]=[])).push(t),e},{}),[a,s]),j=(0,l.useMemo)(()=>{let e=[],t=new Set,n=(a,l)=>{t.has(a.id)||e.length>=40||(t.add(a.id),e.push({entry:a,depth:l}),(h.includes(a.id)||a.id===c)&&(v[a.id]||[]).forEach(e=>n(e,l+1)))},l=a.find(e=>e.id===c);return(l?[l]:a.filter(e=>!a.some(t=>{var a;return t.id===(null==(a=s[e.id])?void 0:a.parent_id)}))).forEach(e=>n(e,0)),e},[a,s,h,c,v]),b=(0,l.useMemo)(()=>{let e=new Set(j.map(e=>{let{entry:t}=e;return t.id})),t=j.flatMap(t=>{var a;let{entry:n}=t,l=null==(a=s[n.id])?void 0:a.parent_id;return l&&e.has(l)?[{id:"parent:".concat(n.id),source:l,target:n.id,type:"smoothstep",style:{stroke:"#a98746",strokeWidth:1.3}}]:[]}),a={};return{nodes:j.map(e=>{var n,l,i,r,o;let{entry:d,depth:c}=e,u=a[c]||0;return a[c]=u+1,{id:d.id,type:"catalog",position:{x:null!=(r=null==(n=s[d.id])?void 0:n.x)?r:280*c,y:null!=(o=null==(l=s[d.id])?void 0:l.y)?o:135*u},data:{entry:d,children:(null==(i=v[d.id])?void 0:i.length)||0,incoming:t.some(e=>e.target===d.id),outgoing:t.some(e=>e.source===d.id),expand:()=>m(e=>e.includes(d.id)?e.filter(e=>e!==d.id):[...e,d.id])}}}),edges:t}},[j,s,v]),[y,f,w]=(0,F.ck)(b.nodes);return(0,l.useEffect)(()=>{f(b.nodes)},[b.nodes,f]),(0,l.useEffect)(()=>{let e=requestAnimationFrame(()=>void g.fitView({padding:.25,maxZoom:1}));return()=>cancelAnimationFrame(e)},[b.nodes.length,c,g]),(0,n.jsxs)("div",{className:"wc-graph-shell",children:[(0,n.jsxs)("div",{className:"wc-graph-tools",children:[(0,n.jsxs)("label",{children:["Focus"," ",(0,n.jsxs)("select",{value:c,onChange:e=>{u(e.target.value),x(null)},children:[(0,n.jsx)("option",{value:"",children:"Whole catalog"}),a.map(e=>(0,n.jsx)("option",{value:e.id,children:e.name},e.id))]})]}),(0,n.jsx)("span",{children:"Drag to arrange \xb7 Connect a parent to a child"}),(0,n.jsx)("button",{onClick:()=>void g.fitView({padding:.25,maxZoom:1}),children:"Fit"}),(0,n.jsx)("button",{disabled:!r,onClick:function(){let e={...s},t={};j.forEach(a=>{var n,l;let{entry:i,depth:s}=a,r=t[s]||0;t[s]=r+1,e[i.id]={...e[i.id],parent_id:(null==(n=e[i.id])?void 0:n.parent_id)||null,order:(null==(l=e[i.id])?void 0:l.order)||0,x:280*s,y:135*r}}),d(e)},children:"Tidy"})]}),(0,n.jsxs)("div",{className:"wc-graph",children:[(0,n.jsxs)(F.Gc,{nodes:y,edges:b.edges,nodeTypes:M,onNodesChange:w,nodesDraggable:r,nodesConnectable:r,deleteKeyCode:null,proOptions:{hideAttribution:!0},fitView:!0,maxZoom:1.8,minZoom:.2,onNodeClick:(e,t)=>{x(null),o(t.data.entry)},onPaneClick:()=>x(null),onNodeDragStop:(e,t)=>{d(function(e,t,a,n){var l;let i=(null==(l=t[a.id])?void 0:l.parent_id)||null,s=e.filter(e=>{var a;return((null==(a=t[e.id])?void 0:a.parent_id)||null)===i}).sort((e,a)=>{var n,l;return((null==(n=t[e.id])?void 0:n.order)||0)-((null==(l=t[a.id])?void 0:l.order)||0)}),r=new Set(s.map(e=>e.id)),o=n.filter(e=>r.has(e.id)).map(e=>e.id===a.id?a:e).sort((e,t)=>e.position.y-t.position.y),d=new Map(o.map(e=>[e.id,e.position])),c={...t},u=0;
1return s.forEach((e,t)=>{let a=d.has(e.id)?o[u++].id:e.id;c[a]={...c[a],parent_id:i,order:t,...d.get(a)}}),c}(i,s,t,y))},onConnect:e=>{var t;e.source&&e.target&&d({...s,[e.target]:{...s[e.target],parent_id:e.source,order:(null==(t=s[e.target])?void 0:t.order)||0}})},onNodeContextMenu:(e,t)=>{e.preventDefault(),x({x:e.clientX,y:e.clientY,id:t.id})},onEdgeContextMenu:(e,t)=>{e.preventDefault(),x({x:e.clientX,y:e.clientY,id:t.target,edge:!0})},children:[(0,n.jsx)(F.VS,{gap:24,color:"#29251c"}),(0,n.jsx)(F.H2,{showInteractive:!1})]}),p&&(0,n.jsxs)("div",{className:"wc-context",role:"menu",style:{left:Math.min(p.x,window.innerWidth-210),top:Math.min(p.y,window.innerHeight-160)},children:[!p.edge&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{role:"menuitem",onClick:()=>{let e=a.find(e=>e.id===p.id);e&&o(e),x(null)},children:"Edit details"}),(0,n.jsx)("button",{role:"menuitem",onClick:()=>{u(p.id),x(null)},children:"Focus this branch"})]}),(0,n.jsx)("button",{role:"menuitem",disabled:!r||!(null==(t=s[p.id])?void 0:t.parent_id),onClick:()=>{var e;d({...s,[p.id]:{...s[p.id],parent_id:null,order:(null==(e=s[p.id])?void 0:e.order)||0}}),x(null)},children:"Remove parent"})]})]}),(0,n.jsxs)("p",{className:"wc-graph-count",children:[j.length," of ",a.length," entries shown",j.length>=40?" \xb7 Focus a branch or search to see more.":""]})]})}var L=a(98782),U=a(6784),q=a(27585);function P(e){var t;let{bookId:a,elementId:i,editable:s,onSaved:r}=e,[o,d]=(0,l.useState)(null),[c,u]=(0,l.useState)(""),[h,m]=(0,l.useState)(!1);async function p(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(s&&!h){m(!0),u("");try{let n=await q.h.admin(a),l=(n.config.references||[]).filter(t=>t.element_id!==i||t.story_id!==e);t||l.push({element_id:i,story_id:e});let s=await q.h.save(a,{...n.config,references:l},n.revision);d({...n,...s}),null==r||r()}catch(e){u((0,j.G0)(e))}finally{m(!1)}}}(0,l.useEffect)(()=>{let e=new AbortController;return q.h.admin(a,e.signal).then(d).catch(t=>{e.signal.aborted||u((0,j.G0)(t))}),()=>e.abort()},[a]);let x=(null==o||null==(t=o.config.references)?void 0:t.filter(e=>e.element_id===i))||[];return(0,n.jsxs)("section",{className:"space-y-3 border-t border-white/10 pt-4",children:[(0,n.jsx)("h3",{children:"Used in stories"}),(0,n.jsx)("p",{className:"text-xs text-[#aaa195]",children:"Appearance links show where this element belongs. They do not set prerequisites."}),c&&(0,n.jsx)("p",{role:"alert",className:"text-xs text-red-300",children:c}),!o&&!c&&(0,n.jsx)("p",{className:"text-xs",children:"Loading storiesâ¦"}),x.map(e=>{var t,a;return(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3 text-xs",children:[(0,n.jsx)("span",{children:(null==o||null==(t=o.stories.find(t=>t.id===e.story_id))?void 0:t.title)||"Story"}),s&&(0,n.jsx)("button",{type:"button",disabled:h,"aria-label":"Remove appearance in ".concat((null==o||null==(a=o.stories.find(t=>t.id===e.story_id))?void 0:a.title)||"Story"),onClick:()=>void p(e.story_id,!0),children:"Remove"})]},e.story_id)}),s&&o&&(0,n.jsxs)("label",{className:"block text-xs",children:["Appears in",(0,n.jsxs)("select",{"aria-label":"Appears in",className:"mt-2 w-full rounded border border-[#695336] bg-[#171614] p-2",value:"",disabled:h,onChange:e=>{e.target.value&&p(e.target.value)},children:[(0,n.jsx)("option",{value:"",children:"Choose a storyâ¦"}),o.stories.filter(e=>!x.some(t=>t.story_id===e.id)).map(e=>(0,n.jsx)("option",{value:e.id,children:e.title},e.id))]})]})]})}a(46347);let z={elements:"Elements",traits:"Traits",classes:"Classes"},G={elements:"element",traits:"trait",classes:"class"},W={processing:"Still being described",failed:"Description failed",named:"Name only"};function O(e){let{bookId:t,mayEdit:a,query:i,onAdded:s}=e,[r,o]=(0,l.useState)(),[d,c]=(0,l.useState)(""),[u,m]=(0,l.useState)(0),[p,g]=(0,l.useState)(!1),[v,b]=(0,l.useState)(null),[y,f]=(0,l.useState)(null);(0,l.useEffect)(()=>{let e=!1;return c(""),h.api.request({url:"/storybooks/".concat(encodeURIComponent(t),"/world/hydration"),method:"GET",...a?{params:{include_hidden:"true"}}:{}}).then(t=>{let{data:a}=t;e||o(a.elements)}).catch(t=>{e||c((0,j.G0)(t))}),()=>{e=!0}},[t,a,u]);let w=e=>o(t=>null==t?void 0:t.map(t=>t.key===e.key?{...t,...e}:t)),k=(r||[]).filter(e=>!e.promoted&&!e.superseded_by&&[e.name,...e.aliases||[]].join(" ").toLowerCase().includes(i.toLowerCase())).sort((e,t)=>
1Number(!!e.hidden)-Number(!!t.hidden)),C=k.filter(e=>"available"===e.status&&!e.hidden);async function N(e,a){g(!0),b(null);try{let n=await h.api.request({url:"/storybooks/".concat(encodeURIComponent(t),"/world/elements/").concat(encodeURIComponent(e.key)),method:"PATCH",data:a});w(n.data.element),f(null)}catch(t){b({error:!0,text:"".concat(e.name,": ").concat((0,j.G0)(t))})}finally{g(!1)}}async function _(e){g(!0),b(null);let a=[],n=0;for(let l of e)try{let e=await h.api.promoteStorybookElement(t,l.key);w({...l,...e.element,promoted:!0}),n+=1}catch(e){a.push("".concat(l.name," (").concat((0,j.G0)(e),")"))}n&&await s(),b(a.length?{error:!0,text:"".concat(n?"Added ".concat(n,". "):"","Could not add ").concat(a.join(", "),".")}:{error:!1,text:"Added ".concat(n," to world elements.")}),g(!1)}return(0,n.jsxs)("section",{className:"wc-discovered","aria-labelledby":"wc-discovered-title",children:[(0,n.jsxs)("header",{children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("h3",{id:"wc-discovered-title",children:["Discovered in play ",(0,n.jsx)("small",{children:r?k.length:""})]}),(0,n.jsx)("p",{children:"Places, people and things the narrator named while members played. Add the ones that belong to your world; hide the ones that donât."})]}),a&&C.length>1&&(0,n.jsxs)("button",{disabled:p,onClick:()=>void _(C),children:["Add all ",C.length]})]}),v&&(0,n.jsx)("p",{role:v.error?"alert":"status",className:v.error?"wc-error":"wc-discovered-notice",children:v.text}),d?(0,n.jsxs)("div",{role:"alert",className:"wc-error",children:[d," ",(0,n.jsx)("button",{onClick:()=>m(e=>e+1),children:"Retry"})]}):r?k.length?k.map(e=>(0,n.jsxs)("div",{className:"wc-row wc-discovered-row ".concat(e.hidden?"wc-hidden":""),children:[(0,n.jsxs)("div",{className:"wc-row-main",children:[(0,n.jsx)(D.aw,{image:e.image_url,type:e.type}),(0,n.jsxs)("span",{children:[(null==y?void 0:y.key)===e.key?(0,n.jsx)("input",{"aria-label":"New name for ".concat(e.name),autoFocus:!0,minLength:2,maxLength:80,value:y.name,onChange:t=>f({key:e.key,name:t.target.value})}):(0,n.jsx)("strong",{children:e.name}),(0,n.jsx)("small",{children:function(e){let t=e.first_seen_at?new Date(e.first_seen_at):null,a=e.mentions&&e.mentions>0?e.mentions:0;return[(0,x.ro)(e.type),t&&!Number.isNaN(t.getTime())?"first seen ".concat(t.toLocaleDateString()):null,a?"named in ".concat(a," ").concat(1===a?"turn":"turns"," since"):null,W[e.status]||null,e.hidden?"Hidden":null].filter(Boolean).join(" \xb7 ")}(e)}),e.definition&&(0,n.jsx)("p",{children:e.definition})]})]}),a&&(0,n.jsx)("div",{className:"wc-discovered-actions",children:(null==y?void 0:y.key)===e.key?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{disabled:p||y.name.trim().length<2||y.name.trim()===e.name,onClick:()=>void N(e,{name:y.name.trim()}),children:"Save name"}),(0,n.jsx)("button",{disabled:p,onClick:()=>f(null),children:"Cancel"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{disabled:p||e.hidden||"available"!==e.status,onClick:()=>void _([e]),children:"Add to world elements"}),(0,n.jsx)("button",{disabled:p,onClick:()=>f({key:e.key,name:e.name}),children:"Rename"}),(0,n.jsx)("button",{disabled:p,onClick:()=>void N(e,{hidden:!e.hidden}),children:e.hidden?"Show":"Hide"})]})})]},e.key)):(0,n.jsx)("p",{className:"wc-discovered-empty",children:i?"No discoveries match your search.":"Nothing new has been named in play yet."}):(0,n.jsx)("p",{role:"status",className:"wc-discovered-empty",children:"Loading discoveriesâ¦"})]})}function H(e){var t,b;let{initialSection:y="elements",onChanged:w}=e,{storybook:C,canManage:N}=(0,m.x)(),{storybook:_,world:S,loading:F,error:I,reload:M,saveWorld:T}=(0,g.p)(C.id),q=(0,u.useSearchParams)(),[W,H]=(0,l.useState)(()=>(null==q?void 0:q.get("section"))==="traits"?"traits":(null==q?void 0:q.get("section"))==="classes"?"classes":y),[X,V]=(0,l.useState)("list"),[Y,B]=(0,l.useState)(""),[Z,K]=(0,l.useState)("all"),[J,$]=(0,l.useState)("manual"),[Q,ee]=(0,l.useState)(0),[et,ea]=(0,l.useState)(null),[en,el]=(0,l.useState)(""),[ei,es]=(0,l.useState)(null),[er,eo]=(0,l.useState)(""),[ed,ec]=(0,l.useState)(!1),[eu,eh]=(0,l.useState)(!1),[em,ep]=(0,l.useState)(""),[ex,eg]=(0,l.useState)(!1),ev="/storybooks/".concat(encodeURIComponent(C.id),"/catalog"),ej=(0,l.useCallback)(async()=>{el("");try{let e=await h.api.request({url:ev,method:"GET"});ea(e.data)}catch(e){el((0,j.G0)(e))}},[ev]);(0,l.useEffect)(()=>{ej()},[ej]);let eb=(null==_||null==(t=_.metadata)?void 0:t.elements)||[],ey=(0,l.useMemo)(()=>{var e;return"elements"===W?(null==_||null==(e=_.metadata)?void 0:e.elements)||[]:(null==S?void 0:S.definition[W])||[]},[W,null==_||null==(b=_.metadata)?void 0:b.elements,null==S?void 0:S.definition]),ef=(0,l.useMemo)(()=>(null==et?void 0:et.sections[W])||{},[et,W]),ew=N("elements"===W?"world-elements":"traits"),ek=(0,l.useMemo)(()=>(function(e,t){let a=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=new Set(e.map(e=>e.id)),l=new Map;
1e.forEach(e=>{var a;let i=null==(a=t[e.id])?void 0:a.parent_id,s=i&&n.has(i)?i:null;l.set(s,[...l.get(s)||[],e])});let i=[],s=new Set,r=(e,n)=>{[...l.get(e)||[]].sort((e,n)=>{var l,i;return a?e.name.localeCompare(n.name):((null==(l=t[e.id])?void 0:l.order)||0)-((null==(i=t[n.id])?void 0:i.order)||0)}).forEach(e=>{s.has(e.id)||(s.add(e.id),i.push({...e,depth:n}),r(e.id,n+1))})};return r(null,0),i})(ey,ef,"name"===J),[ey,ef,J]),eC=ek.filter(e=>("all"===Z||"type"in e&&e.type===Z)&&"".concat(e.name," ").concat(e.description||"").toLowerCase().includes(Y.toLowerCase())),eN=Math.max(0,Math.ceil(eC.length/10)-1),e_=Math.min(Q,eN),eS=!!(ei&&ey.some(e=>e.id===ei.id));function eD(e){var t;es(structuredClone(function(e){let t={...e};return delete t.depth,t}(e))),eo((null==(t=ef[e.id])?void 0:t.parent_id)||""),ep(""),eg(!1),ec(!0)}async function eA(e){if(et&&ew&&!eu){for(let[t,a]of Object.entries(e))if(!E(t,a.parent_id,e))return void ep("An entry cannot contain itself or an ancestor.");eh(!0),ep("");try{let t=await h.api.request({url:ev,method:"PUT",data:{section:W,expected_revision:et.revision,placements:e}});ea(t.data)}catch(e){ep((0,j.G0)(e))}finally{eh(!1)}}}async function eF(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(ei&&_&&S&&et&&!eu&&ew){if(!E(ei.id,er||null,ef))return void ep("Choose a parent outside this entryâs own branch.");eh(!0),ep("");try{var t,a,n;if("elements"===W)await h.api.request({url:"/storybooks/".concat(encodeURIComponent(C.id),"/admin-elements/").concat(encodeURIComponent(ei.id)),method:e?"DELETE":"PUT",data:{expected_version:_.version||1,...e?{}:{element:ei}}});else{let e={...S.definition};"traits"===W?e.traits=eS?e.traits.map(e=>e.id===ei.id?ei:e):[...e.traits,ei]:e.classes=eS?e.classes.map(e=>e.id===ei.id?ei:e):[...e.classes,ei],await T(e,S.settings)}if(await M(),null==w||w(),e||((null==(t=ef[ei.id])?void 0:t.parent_id)||"")===er&&eS)e&&await ej();else{let e=await h.api.request({url:ev,method:"PUT",data:{section:W,expected_revision:et.revision,placements:{...ef,[ei.id]:{...ef[ei.id],parent_id:er||null,order:null!=(n=null==(a=ef[ei.id])?void 0:a.order)?n:ey.length}}}});ea(e.data)}ec(!1),es(null)}catch(e){ep((0,j.G0)(e))}finally{eh(!1)}}}return F||I||en||!et||!S?(0,n.jsx)("section",{className:"wc-page wc-state","aria-label":"World elements catalog",children:F?(0,n.jsx)(p.ld,{label:"Loading world elementsâ¦"}):I?(0,n.jsx)(p.bJ,{message:I,onRetry:()=>void M()}):en?(0,n.jsx)(p.bJ,{message:en,onRetry:()=>void ej()}):(0,n.jsx)(p.ld,{label:"Loading catalog organizationâ¦"})}):(0,n.jsxs)("section",{className:"wc-page","aria-label":"World elements catalog",children:[(0,n.jsxs)("header",{className:"wc-heading",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{children:"World elements"}),(0,n.jsx)("p",{children:"Build the places, things and progression that make this world."})]}),(0,n.jsxs)("div",{className:"wc-actions",children:[ew&&(0,n.jsx)(U.Ay,{bookId:C.id,kind:"world",disabled:eu||ed,onImported:async()=>{await Promise.all([M(),ej(),null==w?void 0:w()])}}),(0,n.jsxs)("div",{className:"wc-switch","aria-label":"Catalog view",children:[(0,n.jsxs)("button",{"aria-pressed":"list"===X,onClick:()=>V("list"),children:[(0,n.jsx)(i.A,{size:14})," List"]}),(0,n.jsxs)("button",{"aria-pressed":"graph"===X,onClick:()=>V("graph"),children:[(0,n.jsx)(s.A,{size:14})," Graph"]})]}),ew&&(0,n.jsxs)("button",{className:"wc-primary",onClick:function(){let e=new Date().toISOString(),t=crypto.randomUUID();eD("elements"===W?{id:t,name:"",type:"location",description:"",details:{},created_at:e,updated_at:e}:"traits"===W?{...f("number",ey.length),id:t,name:""}:{id:t,name:"",description:"",scope:"persona"})},children:[(0,n.jsx)(r.A,{size:14})," Add ",G[W]]})]})]}),(0,n.jsx)("nav",{className:"wc-sections","aria-label":"World catalog sections",children:Object.keys(z).map(e=>(0,n.jsxs)("button",{"aria-current":W===e?"page":void 0,onClick:()=>{H(e),ee(0),K("all"),B(""),ec(!1)},children:[z[e]," ",(0,n.jsx)("small",{children:"elements"===e?eb.length:S.definition[e].length})]},e))}),(0,n.jsxs)("div",{className:"wc-filters",children:[(0,n.jsxs)("label",{className:"wc-search",children:[(0,n.jsx)(o.A,{size:16}),(0,n.jsx)("input",{"aria-label":"Search ".concat(W),placeholder:"Search ".concat(W,"â¦"),value:Y,onChange:e=>{B(e.target.value),ee(0)}})]}),"classes"!==W&&(0,n.jsxs)("select",{"aria-label":"Filter type",value:Z,onChange:e=>{K(e.target.value),ee(0)},children:[(0,n.jsx)("option",{value:"all",children:"All types"}),[...new Set(ey.flatMap(e=>"type"in e?[e.type]:[]))].map(e=>(0,n.jsx)("option",{value:e,children:"elements"===W?(0,x.ro)(e):e.replace("_"," ")},e))]}),(0,n.jsxs)("select",{"aria-label":"Catalog order",value:J,onChange:e=>$(e.target.value),children:[(0,n.jsx)("option",{value:"manual",children:"Your order"}),(0,n.jsx)("option",{value:"name",children:"Name AâZ"})]}),(0,n.jsxs)("span",{children:[eC.length," ",1===eC.length?G[W]:W]}),(0,n.jsx)("button",{className:"wc-reload",onClick:()=>{M(),ej()},children:"Reload"})]}),em&&!ed&&(0,n.jsx)("div",{role:"alert",className:"wc-error",children:em}),"graph"===X?(0,n.jsx)(R,{entries:eC,allEntries:ey,placements:ef,editable:ew&&!eu,onOpen:eD,onSave:eA},W):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"wc-list",children:eC.slice(10*e_,(e_+1)*10).map(e=>(0,n.jsxs)("div",{className:"wc-row",children:[(0,n.jsxs)("button",{className:"wc-row-main",onClick:()=>eD(e),style:{paddingLeft:18*Math.min(e.depth,5)},children:[(0,n.jsx)(D.aw,{image:"image_url"in e?e.image_url:null,type:"type"in e?e.type:"class"}),(0,n.jsxs)("span",{children:[(0,n.jsx)("strong",{children:e.name}),(0,n.jsxs)("small",{children:["type"in e?e.type.replace("_"," "):"Class","scope"in e?" \xb7 ".concat("persona"===e.scope?"Each Persona":"Shared world"):""]}),(0,n.jsx)("p",{children:e.description})]}),(0,n.jsx)(d.A,{size:16})]}),ew&&"manual"===J&&(0,n.jsx)("div",{className:"wc-order-buttons",children:(0,n.jsx)("button",{"aria-label":"Move ".concat(e.name," earlier"),disabled:eu||0===ek.findIndex(t=>t.id===e.id),onClick:()=>{let t=ek.findIndex(t=>t.id===e.id);if(!ek.slice(0,t).reverse().find(t=>{var a,n;return((null==(a=ef[t.id])?void 0:a.parent_id)||null)===((null==(n=ef[e.id])?void 0:n.parent_id)||null)}))return;let a=ek.filter(t=>{var a,n;return((null==(a=ef[t.id])?void 0:a.parent_id)||null)===((null==(n=ef[e.id])?void 0:n.parent_id)||null)}),n=a.findIndex(t=>t.id===e.id);[a[n-1],a[n]]=[a[n],a[n-1]];let l={...ef};a.forEach((e,t)=>{var a;l[e.id]={...l[e.id],parent_id:(null==(a=l[e.id])?void 0:a.parent_id)||null,order:t}}),eA(l)},children:"â"})})]},e.id))}),!eC.length&&(0,n.jsx)("p",{className:"wc-empty",children:ey.length?"No entries match your search.":"Add your first ".concat(G[W],".")}),(0,n.jsxs)("footer",{className:"wc-pagination",children:[(0,n.jsxs)("span",{children:[eC.length?10*e_+1:0,"â",Math.min((e_+1)*10,eC.length)," of"," ",eC.length]}),(0,n.jsx)("button",{"aria-label":"Previous page",disabled:0===e_,onClick:()=>ee(e_-1),children:(0,n.jsx)(c.A,{size:16})}),(0,n.jsxs)("span",{children:[e_+1," / ",eN+1]}),(0,n.jsx)("button",{"aria-label":"Next page",disabled:e_===eN,onClick:()=>ee(e_+1),children:(0,n.jsx)(d.A,{size:16})})]}),"elements"===W&&(0,n.jsx)(O,{bookId:C.id,mayEdit:N("settings"),query:Y,onAdded:async()=>{await Promise.all([M(),ej(),null==w?void 0:w()])}})]}),ed&&ei&&(0,n.jsxs)(v.N,{compact:!0,title:ei.name||"New ".concat(G[W]),onClose:()=>ec(!1),footer:ew?(0,n.jsxs)(p.yY,{state:eu?"saving":"idle",disabled:eu||!ei.name.trim()||!ei.id.trim(),onClick:()=>void eF(),children:["Save ",G[W]]}):void 0,children:[(0,n.jsxs)("fieldset",{disabled:!ew||eu,className:"wc-editor space-y-5",children:["elements"===W?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"wc-editor-art",children:(0,n.jsx)(D.aw,{image:ei.image_url,type:ei.type})}),(0,n.jsx)(L.A,{type:"storybook",entityId:"draft-element-".concat(ei.id),attach:!1,prompt:"".concat(ei.name,". ").concat(ei.description||"",". In the world of ").concat(C.title,"."),currentImageUrl:ei.image_url||void 0,pickerTitle:"Art for ".concat(ei.name||"this element"),label:"Cho
1ose image",onGenerated:e=>es(t=>t?{...t,image_url:e}:t),onPicked:async e=>{let t=e.url;if("upload"===e.source&&e.file){let{uploadImageBlob:n}=await a.e(5528).then(a.bind(a,65528));try{t=await n(e.file,e.file.name)}finally{e.url.startsWith("blob:")&&URL.revokeObjectURL(e.url)}}es(e=>e?{...e,image_url:t}:e)}}),(0,n.jsx)(p.D0,{label:"Name",htmlFor:"element-name",children:(0,n.jsx)(p.ks,{id:"element-name",value:ei.name,onChange:e=>es({...ei,name:e.target.value})})}),(0,n.jsx)(p.D0,{label:"Type",htmlFor:"element-type",children:(0,n.jsx)(p.IM,{id:"element-type",value:ei.type,onChange:e=>es({...ei,type:e.target.value}),children:[...new Set([...A.W,ei.type])].map(e=>(0,n.jsx)("option",{value:e,children:(0,x.ro)(e)},e))})}),(0,n.jsx)(p.D0,{label:"Description",htmlFor:"element-description",children:(0,n.jsx)(p.fs,{id:"element-description",value:ei.description||"",onChange:e=>es({...ei,description:e.target.value})})}),Object.entries(ei.details||{}).map(e=>{let[t,a]=e;return(0,n.jsx)(p.D0,{label:t,htmlFor:"detail-".concat(t),children:(0,n.jsx)(p.ks,{id:"detail-".concat(t),value:a,onChange:e=>es({...ei,details:{...ei.details,[t]:e.target.value}})})},t)}),(0,n.jsx)("button",{type:"button",onClick:()=>{let e=window.prompt("Detail name");(null==e?void 0:e.trim())&&es({...ei,details:{...ei.details,[e.trim()]:""}})},children:"+ Add a detail"})]}):(0,n.jsx)(k,{value:ei,definition:S.definition,persisted:eS,onChange:es}),(0,n.jsx)(p.D0,{label:"Parent",hint:"Organizes this catalog; does not change gameplay rules.",htmlFor:"catalog-parent",children:(0,n.jsxs)(p.IM,{id:"catalog-parent",value:er,onChange:e=>eo(e.target.value),children:[(0,n.jsx)("option",{value:"",children:"Top level"}),ey.filter(e=>e.id!==ei.id&&E(ei.id,e.id,ef)).map(e=>(0,n.jsx)("option",{value:e.id,children:e.name},e.id))]})}),ew&&eS&&"elements"===W&&(0,n.jsx)("div",{className:"border-t border-white/10 pt-4",children:ex?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("p",{children:"Remove this element? Its children will move up one level."}),(0,n.jsx)("button",{className:"text-red-300",onClick:()=>void eF(!0),children:"Confirm removal"})]}):(0,n.jsx)("button",{onClick:()=>eg(!0),children:"Remove element"})}),(0,n.jsx)(p.Mo,{state:em?"error":"idle",error:em})]}),"elements"===W&&eS&&N("stories")&&(0,n.jsx)(P,{bookId:C.id,elementId:ei.id,editable:N("stories"),onSaved:w})]})]})}},90320:(e,t,a)=>{"use strict";a.d(t,{N:()=>o});var n=a(95155),l=a(12115),i=a(26615),s=a(69545),r=a.n(s);function o(e){let{title:t,onClose:a,children:s,footer:o,wide:d=!1,compact:c=!1}=e,u=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=document.activeElement instanceof HTMLElement?document.activeElement:null,t=u.current;return null==t||t.showModal(),()=>{null==t||t.close(),(null==e?void 0:e.isConnected)&&e.focus()}},[]),(0,n.jsx)("dialog",{ref:u,"aria-label":t,onCancel:e=>{e.preventDefault(),a()},onKeyDown:e=>{var t;"Escape"===e.key&&(null==(t=u.current)?void 0:t.contains(e.target))&&e.stopPropagation()},onClick:e=>{if(e.target!==e.currentTarget)return;let t=e.currentTarget.getBoundingClientRect();(e.clientX<t.left||e.clientX>t.right||e.clientY<t.top||e.clientY>t.bottom)&&a()},className:"".concat(r().drawer," fixed inset-y-0 left-auto right-0 m-0 h-dvh max-h-none w-full border-l border-white/10 bg-[#17191c] p-0 text-[#dfd9cc] shadow-2xl backdrop:bg-black/60 ").concat(d?"max-w-none":c?"max-w-[min(338px,90vw)]":"max-w-[460px]"),children:(0,n.jsxs)("div",{className:"flex h-full flex-col",children:[(0,n.jsxs)("header",{className:"flex items-center justify-between gap-4 border-b border-white/10 px-6 py-5",children:[(0,n.jsx)("h2",{className:"font-serif-accent text-2xl",children:t}),(0,n.jsx)("button",{type:"button",onClick:a,"aria-label":"Close panel",className:"rounded p-2 hover:bg-white/10",children:(0,n.jsx)(i.A,{size:20})})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 overflow-auto p-6",children:s}),o&&(0,n.jsx)("footer",{className:"flex items-center justify-end gap-3 border-t border-white/10 px-6 py-4",children:o})]})})}},94515:(e,t,a)=>{"use strict";a.d(t,{Ku:()=>b,aw:()=>v});var n=a(95155),l=a(12115),i=a(22539),s=a(76122),r=a(6943),o=a(10639),d=a(83403),c=a(27304),u=a(45148),h=a(77187),m=a(59338),p=a(63263),x=a(59007),g=a(32265);function v(e){let{image:t,type:a,className:i="",generating:s=!1}=e,[p,x]=(0,l.useState)(!1);(0,l.useEffect)(()=>x(!1),[t]);let g="character"===a?r.A:"location"===a?o.A:"faction"===a?d.A:"item"===a?c.A:"rule"===a?u.A:"story"===a||"book"===a?h.A:m.A;return(0,n.jsx)("span",{className:"sg-art ".concat(s?"sg-art-generating":""," ").concat(i),"aria-label":s?"Generating artwork":void 0,"aria-busy":s,children:t&&!p?(0,n.jsx)("img",{src:t,alt:"",onError:()=>x(!0)}):(0,n.jsx)(g,{size:25,strokeWidth:1.2})})}function j(e){let{isConnectable:t}=e,a=(0,i.d)({handleType:"target"}),l=(0,i.d)({handleType:"source"});return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(i.h7,{className:a.length?"sg-port-attached":"",type:"target",position:s.yX.Left,isConnectable:t}),(0,n.jsx)(i.h7,{className:l.length?"sg-port-attached":"",type:"source",position:s.yX.Right,isConnectable:t})]})}let b={entity:function(e){let{data:t,selected:a,isConnectable:l}=e;return(0,n.jsxs)("div",{className:"sg-node sg-".concat(t.kind,"-node ").concat(a?"sg-selected":""),children:[(0,n.jsx)(j,{isConnectable:l&&"book"!==t.kind}),(0,n.jsx)(v,{image:t.image,generating:!0===t.generatingImage,type:t.elementType||t.kind},t.image),(0,n.jsxs)("span",{className:"sg-node-copy",children:["story"!==t.kind&&(0,n.jsx)("small",{children:"book"===t.kind?"Storybook":t.elementType}),(0,n.jsx)("strong",{children:t.title}),(0,n.jsx)("small",{className:t.retired?"sg-retired":void 0,children:t.starting&&!t.retired?"Starting story":t.subtitle})]})]})},groupCard:function(e){let{data:t,selected:a,isConnectable:l}=e;return(0,n.jsxs)("div",{className:"sg-group ".concat(a?"sg-selected":""),children:[(0,n.jsx)(j,{isConnectable:l}),(0,n.jsxs)("header",{children:[(t.image||!0===t.generatingImage)&&(0,n.jsx)(v,{image:t.image,type:"group",generating:!0===t.generatingImage}),(0,n.jsxs)("span",{children:[(0,n.jsx)("small",{className:t.retired?"sg-retired":void 0,children:t.retired?"Story group \xb7 needs a retired requirement":"Story group"}),(0,n.jsx)("strong",{children:t.title})]}),(0,n.jsx)("button",{className:"nodrag","aria-label":"".concat(t.collapsed?"Expand":"Collapse"," ").concat(t.title),onClick:()=>{var e;return null==(e=t.onCollapse)?void 0:e.call(t,t.entityId)},children:t.collapsed?(0,n.jsx)(p.A,{size:16}):(0,n.jsx)(x.A,{size:16})})]}),!t.collapsed&&(0,n.jsxs)("footer",{children:[t.onAdd&&(0,n.jsxs)("button",{className:"nodrag",onClick:()=>{var e;return null==(e=t.onAdd)?void 0:e.call(t,t.entityId)},children:[(0,n.jsx)(g.A,{size:13})," Add story"]}),(0,n.jsxs)("small",{children:[t.count," ",1===t.count?"story":"stories"]})]})]})},referenceStory:function(e){let{data:t,selected:a,isConnectable:l}=e;return(0,n.jsxs)("div",{className:"sg-reference-story ".concat(a?"sg-selected":""),children:[(0,n.jsx)(j,{isConnectable:l}),(0,n.jsx)(v,{image:t.image,type:"story",generating:!0===t.generatingImage},t.image),(0,n.jsx)("span",{children:t.title})]})}}},99805:(e,t,a)=>{"use strict";function n(e){var t;return(null==e?void 0:e.account)&&(e.account.active_persona_id||(null==(t=e.personas.find(e=>"active"===e.status))?void 0:t.persona_id))||null}a.d(t,{qv:()=>n,ro:()=>i});let l={location:{singular:"Location",plural:"Locations"},faction:{singular:"Faction",plural:"Factions"},item:{singular:"Item",plural:"Items"},lore:{singular:"Lore",plural:"Lore"},event:{singular:"Event",plural:"Events"},rule:{singular:"Rule",plural:"Rules"},concept:{singular:"Concept",plural:"Concepts"},creature:{singular:"Creature",plural:"Creatures"},relationship:{singular:"Relationship",plural:"Relationships"}};function i(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,a=l[e];
1if(a)return 1===t?a.singular:a.plural;let n=e.replace(/[_-]+/g," ");return n.charAt(0).toUpperCase()+n.slice(1)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.