Files
plume/.next/static/chunks/8214509c661073ff.js

3 lines
15 KiB
JavaScript

(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,11690,e=>{"use strict";let t=(0,e.i(78445).default)("arrow-right",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);e.s(["ArrowRight",()=>t],11690)},38562,e=>{"use strict";var t=e.i(30064),r=e.i(59760),l=e.i(33907),i=e.i(22508),n=e.i(4917),o=e.i(11690),s=e.i(62746),a=e.i(15536),d=e.i(30914);let c=(0,e.i(78445).default)("palette",[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]]),u=["#ffffff","#dbeafe","#dcfce7","#fef9c3","#fee2e2","#f3e8ff"],x=r.default.memo(({node:e,isSelected:l,isEditing:i,activeColorPickerId:n,entities:u,savedColors:x,onMouseDown:f,onMouseUp:g,onStartConnection:p,onUpdate:h,onSetEditing:b,onToggleColorPicker:m,onSaveColor:y,onNavigateToEntity:w,onInputFocus:v,onInputCheckAutocomplete:k,onKeyDownInInput:j})=>{let[C,N]=(0,r.useState)(!1),S=(0,r.useMemo)(()=>((e,r,l)=>{if(!e)return(0,t.jsx)("span",{className:"text-slate-400 italic",children:"Description..."});let i=[e];return r.forEach(e=>{if(!e.name)return;let r=RegExp(`(${e.name})`,"gi");for(let n=0;n<i.length;n++){let o=i[n];if("string"==typeof o){let s=o.split(r);if(s.length>1){let r=s.map((r,i)=>r.toLowerCase()===e.name.toLowerCase()?(0,t.jsx)("span",{onClick:t=>{t.stopPropagation(),l(e.id)},className:"text-indigo-600 hover:text-indigo-800 underline decoration-indigo-300 hover:decoration-indigo-600 cursor-pointer font-medium bg-indigo-50 px-0.5 rounded transition-all",title:`Voir la fiche de ${e.name}`,children:r},`${e.id}-${i}`):r);i.splice(n,1,...r),n+=r.length-1}}}}),(0,t.jsx)(t.Fragment,{children:i})})(e.description,u,w),[e.description,u,w]);return(0,t.jsxs)("div",{className:`absolute flex flex-col rounded-xl shadow-sm border transition-all z-10 group
${l?"ring-2 ring-indigo-500 shadow-lg scale-[1.01]":"border-slate-200 hover:shadow-md"}
`,style:{transform:`translate3d(${e.x}px, ${e.y}px, 0)`,width:260,height:220,backgroundColor:e.color||"#ffffff",willChange:"transform"},onMouseDown:t=>f(t,e.id),onMouseUp:t=>g(t,e.id),onMouseLeave:()=>N(!1),children:[(0,t.jsx)("div",{className:"h-1.5 rounded-t-xl bg-black/5 w-full cursor-grab active:cursor-grabbing"}),(0,t.jsxs)("div",{className:"flex-1 px-4 pb-4 pt-2 flex flex-col overflow-hidden relative",children:[(0,t.jsxs)("div",{className:"flex justify-between items-start mb-2 relative",children:[i?(0,t.jsx)("input",{className:"font-bold text-slate-800 bg-white/50 border-b border-indigo-400 outline-none w-full mr-6 text-sm p-1 rounded",value:e.title,onChange:t=>h(e.id,{title:t.target.value}),onFocus:v,autoFocus:!0}):(0,t.jsx)("div",{className:"font-bold text-slate-800 cursor-text truncate mr-6 text-sm",onDoubleClick:()=>b(e.id),children:e.title}),(0,t.jsx)("button",{onClick:t=>{t.stopPropagation(),m(e.id)},className:"p-1 rounded-full hover:bg-black/10 text-slate-400 hover:text-indigo-600 transition-colors absolute right-0 top-0",children:(0,t.jsx)(c,{size:14})}),n===e.id&&(0,t.jsxs)("div",{className:"absolute right-[-10px] top-8 bg-white rounded-lg shadow-xl border border-slate-200 p-3 z-50 w-48 animate-in fade-in zoom-in-95 duration-100 cursor-default",onMouseDown:e=>e.stopPropagation(),children:[(0,t.jsx)("div",{className:"grid grid-cols-4 gap-2 mb-3",children:x.map(r=>(0,t.jsx)("button",{onClick:()=>h(e.id,{color:r}),className:`w-8 h-8 rounded-full border border-slate-200 shadow-sm transition-transform hover:scale-110 ${e.color===r?"ring-2 ring-offset-1 ring-indigo-400":""}`,style:{backgroundColor:r}},r))}),(0,t.jsxs)("div",{className:"flex items-center gap-2 pt-2 border-t border-slate-100",children:[(0,t.jsx)("div",{className:"relative w-8 h-8 rounded-full overflow-hidden border border-slate-300 shadow-inner",children:(0,t.jsx)("input",{type:"color",className:"absolute -top-2 -left-2 w-16 h-16 cursor-pointer",value:e.color||"#ffffff",onChange:t=>h(e.id,{color:t.target.value})})}),(0,t.jsx)("button",{onClick:()=>y(e.color||"#ffffff"),className:"text-[10px] font-bold text-indigo-600 hover:text-indigo-800 hover:underline flex-1 text-right",children:"+ SAUVER"})]})]})]}),(0,t.jsx)("div",{className:"flex-1 overflow-y-auto custom-scrollbar relative mb-4",children:i?(0,t.jsx)("textarea",{className:`w-full h-full bg-white/70 resize-none outline-none text-xs leading-relaxed p-2 rounded border border-indigo-100 shadow-inner ${"dialogue"===e.type?"font-mono text-slate-700":"text-slate-600"}`,placeholder:"dialogue"===e.type?"Héros: Salut !\nGuide: ...":"Résumé de l'intrigue...",value:e.description,onChange:t=>k(t,e.id,"description"),onKeyDown:t=>j(t,e.id),onFocus:v,onBlur:()=>b(null)}):(0,t.jsx)("div",{className:`w-full h-full text-xs text-slate-600 leading-relaxed p-1 cursor-text whitespace-pre-wrap ${"dialogue"===e.type?"font-mono bg-indigo-50/30 rounded pl-2 border-l-2 border-indigo-200":""}`,onClick:()=>b(e.id),children:S})}),(0,t.jsxs)("div",{className:"absolute bottom-2 right-2 z-20",children:[C&&(0,t.jsxs)("div",{className:"absolute bottom-full mb-2 right-0 bg-white shadow-xl border border-slate-200 rounded-lg p-1 flex gap-1 animate-in zoom-in-95 duration-100 w-max",onMouseDown:e=>e.stopPropagation(),children:[(0,t.jsx)("button",{onClick:t=>{t.stopPropagation(),h(e.id,{type:"story"}),N(!1)},className:`p-1.5 rounded hover:bg-slate-100 ${"story"===e.type?"bg-indigo-50 ring-1 ring-indigo-200":""}`,title:"Narration",children:(0,t.jsx)(s.BookOpen,{size:14,className:"text-slate-500"})}),(0,t.jsx)("button",{onClick:t=>{t.stopPropagation(),h(e.id,{type:"action"}),N(!1)},className:`p-1.5 rounded hover:bg-amber-50 ${"action"===e.type?"bg-amber-50 ring-1 ring-amber-200":""}`,title:"Action",children:(0,t.jsx)(d.Zap,{size:14,className:"text-amber-500"})}),(0,t.jsx)("button",{onClick:t=>{t.stopPropagation(),h(e.id,{type:"dialogue"}),N(!1)},className:`p-1.5 rounded hover:bg-blue-50 ${"dialogue"===e.type?"bg-blue-50 ring-1 ring-blue-200":""}`,title:"Dialogue",children:(0,t.jsx)(a.MessageCircle,{size:14,className:"text-blue-500"})})]}),(0,t.jsxs)("button",{className:"p-1.5 rounded-full bg-white/70 hover:bg-white shadow-sm border border-slate-100 hover:border-indigo-200 transition-all opacity-80 group-hover:opacity-100",onClick:e=>{e.stopPropagation(),N(!C)},children:["story"===e.type&&(0,t.jsx)(s.BookOpen,{size:14,className:"text-slate-500"}),"action"===e.type&&(0,t.jsx)(d.Zap,{size:14,className:"text-amber-500"}),"dialogue"===e.type&&(0,t.jsx)(a.MessageCircle,{size:14,className:"text-blue-500"})]})]})]}),(0,t.jsx)("button",{className:"absolute -right-3 top-1/2 -translate-y-1/2 w-6 h-6 bg-white border border-slate-300 rounded-full flex items-center justify-center text-slate-400 hover:text-indigo-600 hover:border-indigo-500 shadow-sm opacity-0 group-hover:opacity-100 transition-all z-20",onMouseDown:t=>p(t,e.id),children:(0,t.jsx)(o.ArrowRight,{size:12})})]})},(e,t)=>e.node===t.node&&e.isSelected===t.isSelected&&e.isEditing===t.isEditing&&e.activeColorPickerId===t.activeColorPickerId&&e.entities===t.entities),f=({data:e,onUpdate:o,entities:s,onNavigateToEntity:a})=>{let d=(0,r.useRef)(null),c=(0,r.useRef)(null),[f,g]=(0,r.useState)(e.nodes),p=(0,r.useRef)(f);(0,r.useEffect)(()=>{p.current=f},[f]),(0,r.useEffect)(()=>{g(e.nodes)},[e.nodes]),(0,r.useEffect)(()=>()=>{c.current&&cancelAnimationFrame(c.current)},[]);let[h,b]=(0,r.useState)(null),[m,y]=(0,r.useState)(new Set),[w,v]=(0,r.useState)(u),[k,j]=(0,r.useState)(null),[C,N]=(0,r.useState)(null),[S,E]=(0,r.useState)([]),[z,D]=(0,r.useState)(!1),[T,I]=(0,r.useState)(new Map),[M,P]=(0,r.useState)({x:0,y:0}),[$,A]=(0,r.useState)(null),[L,R]=(0,r.useState)({x:0,y:0}),[U,O]=(0,r.useState)(!1),[B,F]=(0,r.useState)({x:0,y:0}),[K,X]=(0,r.useState)({x:0,y:0}),Y=(0,r.useCallback)(()=>{E(t=>{let r=[...t,e];return r.length>20?r.slice(r.length-20):r})},[e]),H=(0,r.useCallback)((t,r)=>{let l=p.current;o({...e,nodes:l.map(e=>e.id===t?{...e,...r}:e)})},[e,o]),W=(0,r.useCallback)(e=>{e.stopPropagation()},[]),q=(0,r.useCallback)((e,t,r)=>{let i=e.target.value;H(t,{[r]:i});let n=e.target.selectionStart||0,o=i.slice(0,n).match(/([@#^])([^@#^\s]*)$/);if(o){let e=o[1],i=o[2].toLowerCase(),a="@"===e?l.EntityType.CHARACTER:"#"===e?l.EntityType.LOCATION:l.EntityType.OBJECT,d=s.filter(e=>e.type===a&&e.name.toLowerCase().includes(i));b({active:!0,trigger:e,query:i,nodeId:t,field:r,cursorIndex:n,selectedIndex:0,filteredEntities:d})}else b(null)},[H,s]),Z=e=>{if(!h)return;let{nodeId:t,field:r,trigger:l,query:i}=h,n=p.current.find(e=>e.id===t);if(!n)return;let o=n[r],s=h.cursorIndex,a=s-(l.length+i.length);if(a<0)return;let d=o.slice(0,a),c=o.slice(s),u="dialogue"===n.type&&"@"===h.trigger;H(t,{[r]:d+e.name+(u?": ":" ")+c}),b(null)},J=(0,r.useCallback)((e,t)=>{if(h&&h.nodeId===t){if("ArrowDown"===e.key){e.preventDefault(),b(e=>e?{...e,selectedIndex:(e.selectedIndex+1)%e.filteredEntities.length}:null);return}else if("ArrowUp"===e.key){e.preventDefault(),b(e=>e?{...e,selectedIndex:(e.selectedIndex-1+e.filteredEntities.length)%e.filteredEntities.length}:null);return}else if("Tab"===e.key||"Enter"===e.key){e.preventDefault(),h.filteredEntities.length>0?Z(h.filteredEntities[h.selectedIndex]):b(null);return}else if("Escape"===e.key)return void b(null)}},[h,s,H]),V=(0,r.useCallback)((e,t)=>{e.stopPropagation(),j(null),y(r=>{let l=new Set(r);e.ctrlKey?l.has(t)?l.delete(t):l.add(t):l.has(t)||(l.clear(),l.add(t));let i=e.ctrlKey||l.has(t)?l:new Set([t]),n=new Map;return p.current.forEach(e=>{i.has(e.id)&&n.set(e.id,{x:e.x,y:e.y})}),I(n),l}),D(!0),P({x:e.clientX,y:e.clientY}),Y()},[Y]),G=(0,r.useCallback)((e,t)=>{e.stopPropagation(),Y(),A(t)},[Y]),Q=(0,r.useCallback)((t,r)=>{if($&&$!==r&&!e.connections.some(e=>e.source===$&&e.target===r)){let t={id:`conn-${Date.now()}`,source:$,target:r};o({...e,nodes:p.current,connections:[...e.connections,t]})}A(null)},[e,o,$]),_=(0,r.useCallback)(e=>{j(t=>t===e?null:e)},[]),ee=(0,r.useCallback)(e=>{v(t=>t.includes(e)?t:[...t,e])},[]);return(0,t.jsxs)("div",{className:"h-full flex flex-col overflow-hidden bg-[#eef2ff] relative",children:[(0,t.jsxs)("div",{className:"h-12 bg-white border-b border-indigo-100 flex items-center justify-between px-4 z-10 shadow-sm shrink-0",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)("button",{onClick:()=>{Y();let t=d.current?.scrollLeft||0,r=d.current?.scrollTop||0,l=d.current?.clientWidth||800,i=d.current?.clientHeight||600,n={id:`node-${Date.now()}`,x:t+l/2-130,y:r+i/2-110,title:"Nouveau point d'intrigue",description:"",color:u[0],type:"story"};o({...e,nodes:[...p.current,n]}),y(new Set([n.id])),N(n.id)},className:"flex items-center gap-1.5 px-3 py-1.5 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 text-xs font-bold transition-all shadow-md shadow-indigo-100",children:[(0,t.jsx)(i.Plus,{size:14})," AJOUTER NŒUD"]}),(0,t.jsx)("div",{className:"w-px h-6 bg-slate-100 mx-2"}),(0,t.jsx)("div",{className:"text-[10px] uppercase font-bold text-slate-400 tracking-wider",children:m.size>0?`${m.size} S\xc9LECTIONN\xc9(S)`:"Double-cliquez sur le canvas pour créer"})]}),(0,t.jsx)("div",{className:"flex items-center gap-2",children:(0,t.jsx)("button",{onClick:()=>{0===m.size||(Y(),o({nodes:f.filter(e=>!m.has(e.id)),connections:e.connections.filter(e=>!m.has(e.source)&&!m.has(e.target))}),y(new Set))},disabled:0===m.size,className:"p-2 text-red-500 hover:bg-red-50 rounded-lg disabled:opacity-30 transition-colors",title:"Supprimer",children:(0,t.jsx)(n.Trash2,{size:16})})})]}),(0,t.jsxs)("div",{ref:d,className:"flex-1 overflow-auto relative cursor-grab active:cursor-grabbing bg-[#eef2ff]",onMouseDown:e=>{e.ctrlKey||y(new Set),b(null),j(null),N(null),O(!0),F({x:e.clientX,y:e.clientY}),d.current&&X({x:d.current.scrollLeft,y:d.current.scrollTop})},onMouseMove:e=>{let t=d.current?.getBoundingClientRect();if(!t)return;let r=e.clientX,l=e.clientY;if(U&&d.current){let e=r-B.x,t=l-B.y;d.current.scrollLeft=K.x-e,d.current.scrollTop=K.y-t;return}let i=d.current?.scrollLeft||0,n=d.current?.scrollTop||0;if(R({x:r-t.left+i,y:l-t.top+n}),z){if(c.current)return;c.current=requestAnimationFrame(()=>{let e=r-M.x,t=l-M.y;g(r=>r.map(r=>{let l=T.get(r.id);return l?{...r,x:l.x+e,y:l.y+t}:r})),c.current=null})}},onMouseUp:()=>{c.current&&(cancelAnimationFrame(c.current),c.current=null),z&&o({...e,nodes:p.current}),D(!1),O(!1),A(null)},onDoubleClick:t=>{t.preventDefault();let r=d.current?.getBoundingClientRect();if(!r)return;let l=t.clientX-r.left+(d.current?.scrollLeft||0)-130,i=t.clientY-r.top+(d.current?.scrollTop||0)-110;Y();let n={id:`node-${Date.now()}`,x:l,y:i,title:"Nouvel événement",description:"",color:u[0],type:"story"};o({...e,nodes:[...p.current,n]}),y(new Set([n.id])),N(n.id)},style:{backgroundImage:"radial-gradient(#d1d5db 1px, transparent 1px)",backgroundSize:"24px 24px"},children:[(0,t.jsxs)("svg",{className:"absolute top-0 left-0 w-[4000px] h-[4000px] pointer-events-none z-0",children:[e.connections.map(e=>{let r=f.find(t=>t.id===e.source),l=f.find(t=>t.id===e.target);if(!r||!l)return null;let i=r.x+130,n=r.y+110,o=l.x+130,s=l.y+110;return(0,t.jsx)("line",{x1:i,y1:n,x2:o,y2:s,stroke:"#cbd5e1",strokeWidth:"2",markerEnd:"url(#arrowhead)"},e.id)}),$&&(0,t.jsx)("line",{x1:(f.find(e=>e.id===$)?.x||0)+130,y1:(f.find(e=>e.id===$)?.y||0)+110,x2:L.x,y2:L.y,stroke:"#6366f1",strokeWidth:"2",strokeDasharray:"5,5",markerEnd:"url(#arrowhead-blue)"}),(0,t.jsxs)("defs",{children:[(0,t.jsx)("marker",{id:"arrowhead",markerWidth:"10",markerHeight:"7",refX:"28",refY:"3.5",orient:"auto",children:(0,t.jsx)("path",{d:"M0,0 L0,7 L10,3.5 Z",fill:"#cbd5e1"})}),(0,t.jsx)("marker",{id:"arrowhead-blue",markerWidth:"10",markerHeight:"7",refX:"10",refY:"3.5",orient:"auto",children:(0,t.jsx)("path",{d:"M0,0 L0,7 L10,3.5 Z",fill:"#6366f1"})})]})]}),f.map(e=>(0,t.jsx)(x,{node:e,isSelected:m.has(e.id),isEditing:C===e.id,activeColorPickerId:k,entities:s,savedColors:w,onMouseDown:V,onMouseUp:Q,onStartConnection:G,onUpdate:H,onSetEditing:N,onToggleColorPicker:_,onSaveColor:ee,onNavigateToEntity:a,onInputFocus:W,onInputCheckAutocomplete:q,onKeyDownInInput:J},e.id))]}),h&&(0,t.jsxs)("div",{className:"fixed z-50 bg-white rounded-xl shadow-2xl border border-indigo-100 w-64 max-h-48 overflow-y-auto",style:{left:"50%",top:"50%",transform:"translate(-50%, -50%)"},children:[(0,t.jsxs)("div",{className:"px-3 py-2 bg-indigo-600 text-white text-[10px] font-black uppercase tracking-widest",children:["Insérer ","@"===h.trigger?"Personnage":"#"===h.trigger?"Lieu":"Objet"]}),(0,t.jsx)("div",{className:"divide-y divide-slate-50",children:h.filteredEntities.length>0?h.filteredEntities.map((e,r)=>(0,t.jsx)("button",{className:`w-full text-left px-4 py-3 text-xs flex items-center gap-3 hover:bg-indigo-50 transition-colors ${r===h.selectedIndex?"bg-indigo-50 text-indigo-700 font-bold":"text-slate-700"}`,onClick:()=>Z(e),children:e.name},e.id)):(0,t.jsx)("div",{className:"p-4 text-xs text-slate-400 italic text-center",children:"Aucun résultat"})})]})]})};var g=e.i(12856);function p(e){let{project:r,updateProject:l}=e,i=(0,g.useParams)(),n=(0,g.useRouter)(),o=i.id;return r?(0,t.jsx)(f,{data:r.workflow||{nodes:[],connections:[]},onUpdate:e=>l?.({workflow:e}),entities:r.entities||[],onNavigateToEntity:e=>n.push(`/project/${o}/world`)}):null}e.s(["default",()=>p],38562)}]);