Files
plume/.next/static/chunks/d1fde94eaf7c0d4d.js
2026-02-26 22:39:23 +01:00

8 lines
16 KiB
JavaScript

(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,41498,e=>{"use strict";let t=(0,e.i(78445).default)("check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);e.s(["Check",()=>t],41498)},96922,e=>{"use strict";let t=(0,e.i(78445).default)("list",[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]);e.s(["List",()=>t],96922)},81350,e=>{"use strict";var t=e.i(30064),n=e.i(59760),s=e.i(78445);let a=(0,s.default)("bold",[["path",{d:"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8",key:"mg9rjx"}]]),i=(0,s.default)("italic",[["line",{x1:"19",x2:"10",y1:"4",y2:"4",key:"15jd3p"}],["line",{x1:"14",x2:"5",y1:"20",y2:"20",key:"bu0au3"}],["line",{x1:"15",x2:"9",y1:"4",y2:"20",key:"uljnxc"}]]),l=(0,s.default)("underline",[["path",{d:"M6 4v6a6 6 0 0 0 12 0V4",key:"9kb039"}],["line",{x1:"4",x2:"20",y1:"20",y2:"20",key:"nun2al"}]]),r=(0,s.default)("text-align-start",[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M17 19H3",key:"z6ezky"}]]),o=(0,s.default)("text-align-center",[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 19H5",key:"vjpgq2"}]]),d=(0,s.default)("text-align-end",[["path",{d:"M21 5H3",key:"1fi0y6"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M21 19H7",key:"4cu937"}]]);var c=e.i(96922);let u=(0,s.default)("heading-1",[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"m17 12 3-2v8",key:"1hhhft"}]]),x=(0,s.default)("heading-2",[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1",key:"9jr5yi"}]]),p=(0,s.default)("copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]),h=(0,s.default)("wand-sparkles",[["path",{d:"m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72",key:"ul74o6"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"M5 6v4",key:"ilb8ba"}],["path",{d:"M19 14v4",key:"blhpug"}],["path",{d:"M10 2v2",key:"7u0qdc"}],["path",{d:"M7 8H3",key:"zfb6yr"}],["path",{d:"M21 16h-4",key:"1cnmox"}],["path",{d:"M11 3H9",key:"1obp7u"}]]);var m=e.i(41498),g=e.i(74080);let f=(0,s.default)("maximize-2",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]]);var y=e.i(44026),v=e.i(97794);let b=(0,s.default)("history",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]]),j=(0,s.default)("rotate-ccw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]),k=(0,s.default)("chevron-down",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]),w=(0,s.default)("chevron-up",[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]),M=(0,s.default)("layers",[["path",{d:"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z",key:"zw3jo"}],["path",{d:"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12",key:"1wduqc"}],["path",{d:"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17",key:"kqbvx6"}]]),N=(0,n.forwardRef)(({initialContent:e,onChange:s,onSave:N,onSelectionChange:C,onAiTransform:z},R)=>{let S=(0,n.useRef)(null),H=(0,n.useRef)(null),[L,A]=(0,n.useState)(!1),[T,q]=(0,n.useState)("saved"),D=(0,n.useRef)(null),[I,$]=(0,n.useState)(null),[O,V]=(0,n.useState)(!1),[B,E]=(0,n.useState)([]),[F,P]=(0,n.useState)(!0),[U,K]=(0,n.useState)(new Set),W=(0,n.useRef)(null),X=(0,n.useRef)(null),Y=(0,n.useMemo)(()=>{let e=[...B].sort((e,t)=>t.timestamp-e.timestamp),t=[];return e.forEach(e=>{let n=t.find(t=>60>Math.abs(t.topOffset-e.topOffset));n?(n.versions.push(e),n.versions.sort((e,t)=>t.timestamp-e.timestamp)):t.push({id:`group-${e.id}`,topOffset:e.topOffset,versions:[e]})}),t},[B]),G=(e,t)=>{if(!S.current)return;let n=(()=>{let e=window.getSelection();if(e&&e.rangeCount>0&&S.current){let t=e.getRangeAt(0).getBoundingClientRect(),n=S.current.getBoundingClientRect();return t.top-n.top}return 0})(),s={id:Date.now().toString(),timestamp:Date.now(),type:e,content:S.current.innerHTML,snippet:t.substring(0,80)+(t.length>80?"...":""),topOffset:n};E(e=>[s,...e]),P(!0)},J=e=>{S.current&&confirm("Restaurer cette version ? Le contenu actuel sera remplacé.")&&(S.current.innerHTML=e.content,Q())};(0,n.useImperativeHandle)(R,()=>({insertHtml:e=>{G("Insertion Chat","Insertion depuis le panneau IA"),S.current?.focus();let t=window.getSelection();if(X.current)t?.removeAllRanges(),t?.addRange(X.current);else if(S.current){let e=document.createRange();e.selectNodeContents(S.current),e.collapse(!1),t?.removeAllRanges(),t?.addRange(e)}let n=e.includes("<")?e:e.replace(/\n/g,"<br>");document.execCommand("insertHTML",!1,n),Q()}})),(0,n.useEffect)(()=>{S.current&&S.current.innerHTML!==e&&!L&&Math.abs(S.current.innerHTML.length-e.length)>5&&(S.current.innerHTML=e)},[e,L]);let Q=()=>{S.current&&(s&&s(S.current.innerHTML),N&&(q("unsaved"),D.current&&clearTimeout(D.current),D.current=setTimeout(async()=>{q("saving"),await N(S.current?.innerHTML||""),q("saved")},2e3)))},Z=()=>{let e=window.getSelection();e&&e.rangeCount>0&&S.current?.contains(e.anchorNode)&&(X.current=e.getRangeAt(0).cloneRange())},_=()=>{let e=window.getSelection();Z(),e&&e.toString().length>0&&C?C(e.toString()):C&&C("")},ee=async e=>{if(!z)return;let t=W.current,n=t?.toString()||"";if(n||"continue"===e){G({correct:"Correction",rewrite:"Reformulation",expand:"Développement",continue:"Continuation"}[e],n||"Position curseur"),V(!0);try{let s=await z(n,e);if(s){S.current?.focus();let n=window.getSelection();n?.removeAllRanges(),t&&n?.addRange(t),"continue"===e?(n?.collapseToEnd(),document.execCommand("insertText",!1," "+s)):document.execCommand("insertText",!1,s),Q()}}catch(e){console.error("AI Action failed",e)}finally{V(!1),$(null)}}},et=({icon:e,cmd:n,arg:s,label:a,onClick:i,isActive:l})=>(0,t.jsx)("button",{onMouseDown:e=>{if(i)e.preventDefault(),i();else e.preventDefault(),document.execCommand(n,!1,s),Q(),S.current?.focus()},className:`p-1.5 rounded transition-colors ${l?"bg-indigo-100 text-indigo-700":"text-slate-500 hover:text-slate-800 hover:bg-slate-200"}`,title:a,children:(0,t.jsx)(e,{size:18})}),en=W.current&&!W.current.collapsed;return(0,t.jsxs)("div",{className:"flex flex-col h-full bg-white rounded-lg shadow-sm border border-slate-200 overflow-hidden relative",children:[(0,t.jsx)("style",{children:`
.editor-content:empty::before {
content: attr(data-placeholder);
color: #cbd5e1;
font-style: italic;
cursor: text;
}
`}),(0,t.jsxs)("div",{className:"flex items-center gap-1 p-2 bg-slate-50 border-b border-slate-200 flex-wrap relative z-20 shadow-sm",children:[(0,t.jsx)(et,{icon:a,cmd:"bold",label:"Gras"}),(0,t.jsx)(et,{icon:i,cmd:"italic",label:"Italique"}),(0,t.jsx)(et,{icon:l,cmd:"underline",label:"Souligné"}),(0,t.jsx)("div",{className:"w-px h-6 bg-slate-300 mx-1"}),(0,t.jsx)(et,{icon:u,cmd:"formatBlock",arg:"H1",label:"Titre 1"}),(0,t.jsx)(et,{icon:x,cmd:"formatBlock",arg:"H2",label:"Titre 2"}),(0,t.jsx)("div",{className:"w-px h-6 bg-slate-300 mx-1"}),(0,t.jsx)(et,{icon:r,cmd:"justifyLeft",label:"Aligner à gauche"}),(0,t.jsx)(et,{icon:o,cmd:"justifyCenter",label:"Centrer"}),(0,t.jsx)(et,{icon:d,cmd:"justifyRight",label:"Aligner à droite"}),(0,t.jsx)("div",{className:"w-px h-6 bg-slate-300 mx-1"}),(0,t.jsx)(et,{icon:c.List,cmd:"insertUnorderedList",label:"Liste"}),(0,t.jsx)("div",{className:"flex-1"}),(0,t.jsxs)("div",{className:"flex items-center gap-2 mr-4 text-xs font-medium text-slate-400",children:["saving"===T&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(y.Loader2,{size:12,className:"animate-spin"})," Sauvegarde..."]}),"saved"===T&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(m.Check,{size:12,className:"text-green-500"})," Sauvegardé"]}),"unsaved"===T&&(0,t.jsx)("span",{className:"text-amber-500",children:"Modifications non enregistrées..."})]}),(0,t.jsx)("div",{className:"w-px h-6 bg-slate-300 mx-1"}),(0,t.jsx)(et,{icon:b,label:"Marge d'historique",onClick:()=>P(!F),isActive:F})]}),(0,t.jsx)("div",{className:"flex-1 overflow-y-auto relative bg-slate-100",ref:H,children:(0,t.jsxs)("div",{className:"flex justify-center relative min-h-full py-8",children:[(0,t.jsx)("div",{ref:S,contentEditable:!0,suppressContentEditableWarning:!0,className:"bg-white shadow-sm w-[800px] min-h-[1000px] p-12 outline-none font-serif text-lg leading-relaxed text-slate-900 editor-content",onInput:Q,onBlur:()=>{A(!1),Z()},onFocus:()=>A(!0),onKeyUp:Z,onMouseUp:Z,onSelect:_,onClick:()=>S.current?.focus(),onContextMenu:e=>{e.preventDefault();let t=window.getSelection();if(t&&t.rangeCount>0){let n=t.getRangeAt(0);if(S.current?.contains(n.commonAncestorContainer)){W.current=n.cloneRange(),$({x:e.clientX,y:e.clientY});return}}W.current=null,$({x:e.clientX,y:e.clientY})},"data-placeholder":"Commencez à écrire votre chef-d'œuvre... (Clic droit pour outils IA)"}),F&&(0,t.jsxs)("div",{className:"absolute left-[calc(50%+420px)] top-0 bottom-0 w-80 pt-8 pointer-events-none",children:[0===Y.length&&(0,t.jsxs)("div",{className:"sticky top-10 text-center text-slate-300 p-4",children:[(0,t.jsx)(b,{size:48,className:"mx-auto mb-2 opacity-20"}),(0,t.jsx)("p",{className:"text-xs",children:"L'historique des modifications IA apparaîtra ici, aligné avec votre texte."})]}),Y.map(e=>{let n=U.has(e.id),s=e.versions.length>1,a=e.versions[0];return(0,t.jsx)("div",{className:"absolute w-72 pointer-events-auto transition-all duration-300 ease-in-out",style:{top:`${e.topOffset+32}px`},children:(0,t.jsxs)("div",{className:`relative bg-white rounded-lg border shadow-sm transition-all duration-200 ${s&&!n?"border-indigo-200 shadow-md translate-x-1 translate-y-1":"border-slate-200"}`,children:[s&&!n&&(0,t.jsx)("div",{className:"absolute inset-0 bg-white border border-indigo-100 rounded-lg transform -translate-x-1 -translate-y-1 -z-10 shadow-sm"}),(0,t.jsxs)("div",{className:"p-2 border-b border-slate-100 flex justify-between items-center bg-slate-50 rounded-t-lg cursor-pointer hover:bg-slate-100",onClick:()=>{var t;let n;return s&&(t=e.id,void((n=new Set(U)).has(t)?n.delete(t):n.add(t),K(n)))},children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[s&&(0,t.jsx)(M,{size:14,className:"text-indigo-500"}),(0,t.jsx)("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded uppercase tracking-wide ${a.type.includes("Correction")?"bg-green-100 text-green-700":a.type.includes("Insertion")?"bg-blue-100 text-blue-700":"bg-purple-100 text-purple-700"}`,children:a.type})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)("span",{className:"text-[10px] text-slate-400",children:new Date(a.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),s&&(n?(0,t.jsx)(w,{size:14,className:"text-slate-400"}):(0,t.jsx)(k,{size:14,className:"text-slate-400"}))]})]}),!n&&(0,t.jsxs)("div",{className:"p-2",children:[(0,t.jsxs)("div",{className:"text-xs text-slate-500 italic line-clamp-2",children:['"',a.snippet,'"']}),(0,t.jsxs)("button",{onClick:()=>J(a),className:"mt-2 w-full flex items-center justify-center gap-1 text-[10px] bg-slate-50 hover:bg-indigo-50 text-slate-600 hover:text-indigo-700 py-1 rounded transition-colors",children:[(0,t.jsx)(j,{size:10})," Restaurer"]})]}),n&&(0,t.jsx)("div",{className:"divide-y divide-slate-100 max-h-64 overflow-y-auto",children:e.versions.map((e,n)=>(0,t.jsxs)("div",{className:"p-2 bg-white hover:bg-slate-50 transition-colors",children:[(0,t.jsxs)("div",{className:"flex justify-between items-center mb-1",children:[(0,t.jsx)("span",{className:"text-[10px] font-semibold text-slate-600",children:0===n?"Dernière version":`Version -${n}`}),(0,t.jsx)("span",{className:"text-[9px] text-slate-400",children:new Date(e.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"})})]}),(0,t.jsxs)("div",{className:"text-xs text-slate-500 italic bg-slate-50 p-1.5 rounded mb-2 border border-slate-100",children:['"',e.snippet,'"']}),(0,t.jsxs)("button",{onClick:()=>J(e),className:"w-full flex items-center justify-center gap-1 text-[10px] bg-white border border-slate-200 text-slate-600 hover:text-indigo-600 hover:border-indigo-200 py-1 rounded transition-colors",children:[(0,t.jsx)(j,{size:10})," Restaurer cette version"]})]},e.id))})]})},e.id)})]})]})}),I&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"fixed inset-0 z-40 bg-transparent",onClick:()=>$(null),onContextMenu:e=>{e.preventDefault(),$(null)}}),(0,t.jsx)("div",{className:"fixed z-50 bg-white border border-slate-200 rounded-lg shadow-xl py-1 w-56 animate-in fade-in zoom-in-95 duration-100 flex flex-col",style:{top:Math.min(I.y,window.innerHeight-200),left:Math.min(I.x,window.innerWidth-224)},children:O?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center py-4 text-indigo-600 gap-2",children:[(0,t.jsx)(y.Loader2,{className:"animate-spin",size:24}),(0,t.jsx)("span",{className:"text-xs font-medium",children:"L'IA travaille..."})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"px-3 py-1 text-[10px] font-bold text-slate-400 uppercase tracking-wider",children:"Outils IA"}),(0,t.jsxs)("button",{onClick:()=>ee("correct"),disabled:!en,className:`flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${!en?"text-slate-300 cursor-not-allowed":"text-slate-700 hover:bg-indigo-50 hover:text-indigo-700"}`,children:[(0,t.jsx)(m.Check,{size:14})," Corriger l'orthographe"]}),(0,t.jsxs)("button",{onClick:()=>ee("rewrite"),disabled:!en,className:`flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${!en?"text-slate-300 cursor-not-allowed":"text-slate-700 hover:bg-indigo-50 hover:text-indigo-700"}`,children:[(0,t.jsx)(g.RefreshCw,{size:14})," Reformuler"]}),(0,t.jsxs)("button",{onClick:()=>ee("expand"),disabled:!en,className:`flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${!en?"text-slate-300 cursor-not-allowed":"text-slate-700 hover:bg-indigo-50 hover:text-indigo-700"}`,children:[(0,t.jsx)(f,{size:14})," Développer"]}),(0,t.jsxs)("button",{onClick:()=>ee("continue"),className:"flex items-center gap-2 px-3 py-2 text-sm text-slate-700 hover:bg-indigo-50 hover:text-indigo-700 text-left transition-colors",children:[(0,t.jsx)(h,{size:14})," Continuer l'écriture"]}),(0,t.jsx)("div",{className:"h-px bg-slate-100 my-1"}),(0,t.jsx)("div",{className:"px-3 py-1 text-[10px] font-bold text-slate-400 uppercase tracking-wider",children:"Édition"}),(0,t.jsxs)("button",{onClick:()=>{if(W.current){let e=window.getSelection();e?.removeAllRanges(),e?.addRange(W.current),document.execCommand("copy")}$(null)},disabled:!en,className:`flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${!en?"text-slate-300 cursor-not-allowed":"text-slate-700 hover:bg-slate-50"}`,children:[(0,t.jsx)(p,{size:14})," Copier"]}),(0,t.jsxs)("button",{onClick:()=>{S.current?.focus(),document.execCommand("selectAll"),_(),$(null)},className:"flex items-center gap-2 px-3 py-2 text-sm text-slate-700 hover:bg-slate-50 text-left transition-colors",children:[(0,t.jsx)(v.MousePointerClick,{size:14})," Tout sélectionner"]})]})})]})]})});var C=e.i(24224),z=e.i(4301);function R(){let e=(0,n.useRef)(null),{project:s,user:a,currentChapterId:i,updateChapter:l,incrementUsage:r}=(0,C.useProjectContext)();if(!i)return null;let o=s.chapters?.find(e=>e.id===i);return(0,t.jsx)(N,{ref:e,initialContent:o?.content||"",onSave:e=>l(i,{content:e}),onAiTransform:async(e,t)=>{let n=await z.default.ai.transform(e,t,o?.content||"",a);return r(),n}})}e.s(["default",()=>R],81350)}]);