@graphysdk/react-renderer 1.9.0-beta.1795708068076 → 1.9.0-beta.1795773309240

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- require('./rich-text-editor-module.css');const o=require("./history-chords-DDZ_6FBc.cjs"),a=require("./start-arrow-button-DjGnXDVD.cjs");let m=require("@graphysdk/viz-engine"),h=require("react"),t=require("react/jsx-runtime"),P=require("@floating-ui/react-dom"),N=require("@base-ui/react/tooltip"),L=require("@base-ui/react/popover"),T=require("@base-ui/react/menu"),H=require("@base-ui/react/toolbar"),_=require("@tiptap/react"),re=require("@tiptap/core"),Ae=require("@tiptap/extension-bold"),D=require("@tiptap/extension-document"),Ee=require("@tiptap/extension-hard-break"),Pe=require("@tiptap/extension-heading"),Ne=require("@tiptap/extension-italic"),Le=require("@tiptap/extension-link"),Me=require("@tiptap/extension-text"),Ie=require("@tiptap/extension-text-align"),w=require("@tiptap/extension-text-style"),Oe=require("@tiptap/extension-underline"),B=require("@tiptap/extensions"),oe=require("@tiptap/extension-paragraph"),ze=require("@base-ui/react/toggle");var ae=e=>(0,t.jsx)(o.Icon,{...e,children:(0,t.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,t.jsx)("path",{d:"M21 5H3"}),(0,t.jsx)("path",{d:"M17 12H7"}),(0,t.jsx)("path",{d:"M19 19H5"})]})}),ie=e=>(0,t.jsx)(o.Icon,{...e,children:(0,t.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,t.jsx)("path",{d:"M21 5H3"}),(0,t.jsx)("path",{d:"M21 12H9"}),(0,t.jsx)("path",{d:"M21 19H7"})]})}),le=e=>(0,t.jsx)(o.Icon,{...e,children:(0,t.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,t.jsx)("path",{d:"M21 5H3"}),(0,t.jsx)("path",{d:"M15 12H3"}),(0,t.jsx)("path",{d:"M17 19H3"})]})}),De=({textColor:e,...n})=>(0,t.jsxs)(o.Icon,{...n,children:[(0,t.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",children:[(0,t.jsx)("path",{d:"M6 4h12"}),(0,t.jsx)("path",{d:"M12 4v12"})]}),(0,t.jsx)("path",{d:"M5 20h14",stroke:e??"currentColor",strokeWidth:3,strokeLinecap:"round"})]});var se=[{id:"modern",key:"graph.annotations.textToolbar.font.modern"},{id:"fresh",key:"graph.annotations.textToolbar.font.fresh"},{id:"timeless",key:"graph.annotations.textToolbar.font.timeless"},{id:"technical",key:"graph.annotations.textToolbar.font.technical"},{id:"fineliner",key:"graph.annotations.textToolbar.font.fineliner"},{id:"handwritten",key:"graph.annotations.textToolbar.font.handwritten"}].map(({id:e,key:n})=>({id:e,key:n,fontFamily:o.RICH_TEXT_FONT_FAMILIES[e]??e})),we=e=>se.find(n=>n.id===(e??"modern"))??null;var ce=[{size:12,key:"graph.annotations.textToolbar.fontSize.small"},{size:15,key:"graph.annotations.textToolbar.fontSize.medium"},{size:18,key:"graph.annotations.textToolbar.fontSize.large"},{size:24,key:"graph.annotations.textToolbar.fontSize.extraLarge"},{size:30,key:"graph.annotations.textToolbar.fontSize.huge"}],Re=e=>ce.find(n=>n.size===(e??15))??null,He=e=>`${e}px`,Be=[{alignment:"left",Icon:le},{alignment:"center",Icon:ae},{alignment:"right",Icon:ie}],qe=({annotation:e,textBox:n,panelRect:r,frameWidth:u,frameHeight:i,frameElement:c})=>{const l=o.useI18n(),{commands:d}=o.useGraphContext(),p=a.useRemoveAnnotation(r),x=o.useSceneSelector(s=>s.spec.styles.overrides),y=o.useSceneSelector(s=>(0,m.readStyleCoord)(s.spec)),g=o.useEditorStore(),j=a.useToolbarPopups(),f=a.usePlaceholderWidthFit(),v=(0,m.resolveTextAnnotationStyle)(o.useStyleReaderTree(),e.id),C=a.readTextAnnotationStyle(e.content),S=o.useEditorState(s=>s.caret?.editor??null),A=(0,_.useEditorState)({editor:S,selector:()=>a.readPickedFontSize(S)}),M=(0,_.useEditorState)({editor:S,selector:()=>a.readPickedFont(S)}),I=we(C.font??M),q=Re(C.fontSize??A),ve=o.useTextAnnotationTextColor(v),be=C.color??ve,V=(0,h.useMemo)(()=>({target:"annotation",kind:"text",annotation:e.id}),[e.id]),J=(s,b)=>{const k=(0,m.findStyleRule)(x,{select:V},y)?.declarations??{};d.dispatch(new m.SetStyleRuleCommand({list:"overrides",rule:{select:V,declarations:{...k,...s}}}),b)},U=(s,b)=>{d.dispatch(new m.UpdateAnnotationCommand({kind:"text",id:e.id,patch:s}),b)},E=()=>g.getState().caret?.editor?.getJSON()??e.content,W=(s,b)=>{const k=E(),z=g.getState().caret?.editor??null;if(z!==null&&!a.hasStyleableText(k)){z.chain().focus().setMark(a.TEXT_STYLE_MARK,s).run();return}U({content:a.applyTextStyle(k,s)},b)},je=()=>{p(e.id),c.focus({preventScroll:!0})},ye=s=>J(Ue(s),{transient:!0}),Se=s=>J({fillAlpha:s},{transient:!0}),O=v.fill!==a.TRANSPARENT_COLOR,ke=s=>W({color:s===m.AUTO_COLOR?void 0:s},{transient:!0}),_e=s=>()=>{a.hasStyleableText(E())||Y({font:s}),W({font:s}),j.close()},Ce=s=>()=>{a.hasStyleableText(E())||Y({fontSize:s}),W({fontSize:s}),j.close()},Y=s=>{const b=(n.x+(0,m.alignUnitFractions)(e.align).x*n.width)/r.width,k=f({annotationId:e.id,anchorX:b,align:e.align,panelWidth:r.width,minWidth:e.width,pickedFontSize:s.fontSize??A,pickedFont:s.font??M});k>e.width&&U({width:k})},Fe=s=>{const b=g.getState().caret?.editor??null;if(b===null||a.hasStyleableText(E())){U({content:a.applyTextAlignment(E(),s)});return}const k=b.state.storedMarks;b.chain().focus().setTextAlign(s).command(({tr:z})=>(z.setStoredMarks(k),!0)).run()};return(0,t.jsxs)(a.SelectionToolbar.Root,{anchorBox:n,panelRect:r,frameWidth:u,frameHeight:i,label:l("graph.annotations.textToolbar.label"),testId:"text-toolbar",children:[(0,t.jsx)(a.SelectionToolbar.ColorPicker,{color:(0,m.toPaintColor)(v.fill),label:l("graph.annotations.textToolbar.background"),hasTransparentOption:!0,onChange:ye,opacity:O?v.fillAlpha:void 0,onOpacityChange:O?Se:void 0,...j.bind("background"),children:(0,t.jsx)(a.SelectionToolbar.Swatch,{color:O?(0,m.toPaintColor)(v.fill):a.TRANSPARENT_SWATCH_FILL,opacity:O?v.fillAlpha:void 0})}),(0,t.jsx)(a.SelectionToolbar.ColorPicker,{color:C.color??m.AUTO_COLOR,label:l("graph.annotations.textToolbar.color"),hasAutomaticOption:!0,onChange:ke,...j.bind("color"),children:(0,t.jsx)(De,{size:"sm",textColor:be,title:""})}),(0,t.jsx)(a.SelectionToolbar.Dropdown,{label:l("graph.annotations.textToolbar.font.ariaLabel"),trigger:(0,t.jsx)("span",{style:{fontFamily:I?.fontFamily},children:"Aa"}),...j.bind("font"),children:se.map(s=>(0,t.jsx)(a.SelectionToolbar.MenuItem,{selected:s.id===I?.id,onClick:_e(s.id),children:(0,t.jsx)("span",{style:{fontFamily:s.fontFamily},children:l(s.key)})},s.id))}),(0,t.jsx)(a.SelectionToolbar.Dropdown,{label:l("graph.annotations.textToolbar.fontSize.ariaLabel"),trigger:q===null?"":l(q.key),...j.bind("fontSize"),children:ce.map(s=>(0,t.jsx)(a.SelectionToolbar.MenuItem,{selected:s.size===q?.size,onClick:Ce(s.size),children:(0,t.jsx)("span",{style:{fontSize:He(s.size)},children:l(s.key)})},s.size))}),(0,t.jsx)(a.SelectionToolbar.Separator,{}),(0,t.jsx)(We,{current:C.alignment??"center",onPick:Fe}),(0,t.jsx)(a.SelectionToolbar.Separator,{}),(0,t.jsx)(a.StartArrowButton,{annotationId:e.id}),(0,t.jsx)(a.SelectionToolbar.IconButton,{label:l("graph.annotations.textToolbar.remove"),onClick:je,children:(0,t.jsx)(a.TrashIcon,{size:"sm",title:""})})]})},Ue=e=>e==="transparent"?{fill:a.TRANSPARENT_COLOR}:{fill:e,fillAlpha:a.isCanvasColor(e)?m.TEXT_ANNOTATION_FADE_ALPHA:1},We=({current:e,onPick:n})=>{const r=o.useI18n(),u=i=>()=>n(i);return(0,t.jsx)(t.Fragment,{children:Be.map(i=>(0,t.jsx)(a.SelectionToolbar.ToggleButton,{label:r(`graph.annotations.textToolbar.align.${i.alignment}`),pressed:i.alignment===e,onClick:u(i.alignment),children:(0,t.jsx)(i.Icon,{size:"sm",title:""})},i.alignment))})},$e="data-variant",de=oe.Paragraph.extend({addAttributes(){return{variant:{default:null,parseHTML:e=>e.getAttribute("data-variant")??null,renderHTML:e=>e.variant?{[$e]:e.variant}:{}}}}}),Ge=re.Extension.create({name:"preventBackspaceAcrossTitleBoundary",addOptions(){return{showTitle:!0}},addKeyboardShortcuts(){return{Backspace:({editor:e})=>{if(!this.options.showTitle)return!1;const{selection:n}=e.state;if(!n.empty)return!1;const{$from:r}=n;return r.depth!==1||r.parentOffset!==0?!1:r.index(0)===1}}}}),K=()=>[Me.Text,B.UndoRedo,Pe.Heading.configure({levels:[1,2,3]}),Ae.Bold,Ne.Italic,Oe.Underline,Ie.TextAlign.configure({types:["heading","paragraph"]}),Le.Link.configure({openOnClick:!1,autolink:!0}),w.TextStyle,w.Color,Ee.HardBreak],Ke=({titlePlaceholder:e,subtitlePlaceholder:n,showTitle:r,showSubtitle:u})=>[Ve({showTitle:r,showSubtitle:u}),de,...K(),w.FontFamily,Ge.configure({showTitle:r}),B.Placeholder.configure({showOnlyCurrent:!1,placeholder:({pos:i,editor:c})=>{if(r&&i===0)return e;const l=r?c.state.doc.firstChild?.nodeSize??-1:0;return u&&i===l?n:""}})],Xe=({placeholder:e})=>[D.Document,de,...K(),w.FontFamily,B.Placeholder.configure({showOnlyCurrent:!1,placeholder:({pos:n})=>n===0?e:""})],Ve=({showTitle:e,showSubtitle:n})=>e&&n?D.Document.extend({content:"block{2,}"}):D.Document,ue=(e,n)=>{if(n===null)return;let r=null;try{r=e.view.posAtCoords({left:n.x,top:n.y})}catch{r=null}e.commands.focus(r===null?"end":r.pos,{scrollIntoView:!1})},Je="'Noto Serif', Georgia, 'Times New Roman', serif, 'Apple Color Emoji', 'NotoColorEmoji'",Ye=`'Aeonik', 'Aeonik Fallback', ${o.DEFAULT_FONT_FAMILY}`,Ze="'PT Mono', 'Courier New', monospace, 'Apple Color Emoji', 'NotoColorEmoji'",Qe="'Intruding Cat', cursive, 'Apple Color Emoji', 'NotoColorEmoji'",G=[{id:"modern",label:"Modern",preview:"Aa",fontFamily:o.DEFAULT_FONT_FAMILY},{id:"fresh",label:"Fresh",preview:"Aa",fontFamily:Ye},{id:"timeless",label:"Timeless",preview:"Aa",fontFamily:Je},{id:"technical",label:"Technical",preview:"00",fontFamily:Ze},{id:"fineliner",label:"Fineliner",preview:"Aa",fontFamily:Qe}],et=e=>e?G.find(n=>n.fontFamily===e)??null:null,pe="_70l3rt0",he="_70l3rt1",fe="_70l3rt3",xe="_70l3rt4",ge="_70l3rt5",tt=({editor:e,currentFontFamily:n,open:r,onOpenChange:u})=>{const i=o.useI18n(),c=et(n)??G[0],l=d=>{e.chain().focus().setFontFamily(d.fontFamily).run()};return(0,t.jsxs)(T.Menu.Root,{open:r,onOpenChange:u,children:[(0,t.jsxs)(T.Menu.Trigger,{render:(0,t.jsx)(H.Toolbar.Button,{}),"aria-label":i("graph.toolbar.font.ariaLabel"),className:pe,onMouseDown:d=>d.preventDefault(),children:[(0,t.jsx)("span",{className:he,style:{fontFamily:c?.fontFamily},children:c?.preview}),(0,t.jsx)(a.ChevronDownIcon,{size:"sm"})]}),(0,t.jsx)(T.Menu.Portal,{container:o.resolvePortalContainer(),className:a.basePortal,children:(0,t.jsx)(o.PortalThemeProvider,{children:(0,t.jsx)(T.Menu.Positioner,{side:"bottom",align:"start",sideOffset:6,className:fe,children:(0,t.jsx)(T.Menu.Popup,{className:xe,onMouseDown:d=>d.preventDefault(),children:G.map(d=>(0,t.jsx)(T.Menu.Item,{className:ge,"data-selected":d.id===c?.id,onClick:()=>l(d),children:(0,t.jsx)("span",{style:{fontFamily:d.fontFamily},children:d.label})},d.id))})})})})]})},me={id:"text",translationKey:"graph.toolbar.heading.text",previewFont:o.vars.fontTextEditorBody},Z=[{id:"caption",translationKey:"graph.toolbar.heading.caption",previewFont:o.vars.fontTextEditorH6},me,{id:"h3",translationKey:"graph.toolbar.heading.heading3",previewFont:o.vars.fontTextEditorH3},{id:"h2",translationKey:"graph.toolbar.heading.heading2",previewFont:o.vars.fontTextEditorH2},{id:"h1",translationKey:"graph.toolbar.heading.heading1",previewFont:o.vars.fontTextEditorH1}],nt=({editor:e,activeStyle:n,open:r,onOpenChange:u})=>{const i=o.useI18n(),c=Z.find(l=>l.id===n)??me;return(0,t.jsxs)(T.Menu.Root,{open:r,onOpenChange:u,children:[(0,t.jsxs)(T.Menu.Trigger,{render:(0,t.jsx)(H.Toolbar.Button,{}),"aria-label":i("graph.toolbar.heading.ariaLabel"),className:pe,onMouseDown:l=>l.preventDefault(),children:[(0,t.jsx)("span",{className:he,children:i(c.translationKey)}),(0,t.jsx)(a.ChevronDownIcon,{size:"sm"})]}),(0,t.jsx)(T.Menu.Portal,{container:o.resolvePortalContainer(),className:a.basePortal,children:(0,t.jsx)(o.PortalThemeProvider,{children:(0,t.jsx)(T.Menu.Positioner,{side:"bottom",align:"start",sideOffset:6,className:fe,children:(0,t.jsx)(T.Menu.Popup,{className:xe,onMouseDown:l=>l.preventDefault(),children:Z.map(l=>(0,t.jsx)(T.Menu.Item,{className:ge,"data-selected":l.id===c.id,onClick:()=>rt(e,l.id),children:(0,t.jsx)(ot,{font:l.previewFont,children:i(l.translationKey)})},l.id))})})})})]})},rt=(e,n)=>{switch(n){case"caption":e.chain().focus().setNode("paragraph",{variant:"caption"}).run();return;case"text":e.chain().focus().setNode("paragraph",{variant:null}).run();return;case"h1":e.chain().focus().setHeading({level:1}).run();return;case"h2":e.chain().focus().setHeading({level:2}).run();return;case"h3":e.chain().focus().setHeading({level:3}).run()}},ot=({font:e,children:n})=>(0,t.jsx)("span",{style:{font:e,margin:0},children:n}),at=e=>(0,t.jsx)(o.Icon,{...e,children:(0,t.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,t.jsx)("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),(0,t.jsx)("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})]})}),it=e=>(0,t.jsx)(o.Icon,{...e,children:(0,t.jsxs)("g",{stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,t.jsx)("path",{d:"M18 6 6 18"}),(0,t.jsx)("path",{d:"m6 6 12 12"})]})}),lt=e=>!e.content||e.content.length===0?!0:e.content.every(n=>!n.content||n.content.length===0),st=e=>{const{$from:n}=e.state.selection,r=n.parent.textContent,u=n.parentOffset,i=n.start();let c=u;for(;c>0&&Q(r[c-1]);)c-=1;let l=u;for(;l<r.length&&Q(r[l]);)l+=1;return{from:i+c,to:i+l}},Q=e=>e!==void 0&&/\S/.test(e),ct="fop13s0",dt="fop13s1",ut="fop13s2",pt="fop13s3",ee="fop13s4",ht=({editor:e,currentUrl:n,active:r,open:u,onOpenChange:i})=>{const c=o.useI18n(),[l,d]=(0,h.useState)(""),p=(0,h.useRef)(null);(0,h.useEffect)(()=>{u&&d(n??"")},[u,n]);const x=()=>{ft(e,l),i(!1)},y=()=>{d(""),i(!1)},g=f=>{d(f.target.value)},j=f=>{f.key==="Enter"&&(f.preventDefault(),x())};return(0,t.jsxs)(L.Popover.Root,{open:u,onOpenChange:i,children:[(0,t.jsx)(L.Popover.Trigger,{render:(0,t.jsx)(H.Toolbar.Button,{}),"aria-label":c("graph.toolbar.formatting.link"),"data-active":r,className:ct,onMouseDown:f=>f.preventDefault(),children:(0,t.jsx)(at,{})}),(0,t.jsx)(L.Popover.Portal,{container:o.resolvePortalContainer(),className:a.basePortal,children:(0,t.jsx)(o.PortalThemeProvider,{children:(0,t.jsx)(L.Popover.Positioner,{sideOffset:6,align:"end",className:dt,children:(0,t.jsxs)(L.Popover.Popup,{className:ut,initialFocus:p,onMouseDown:f=>f.preventDefault(),children:[(0,t.jsx)("input",{ref:p,type:"url",value:l,placeholder:c("graph.toolbar.link.placeholder"),"aria-label":c("graph.toolbar.link.urlLabel"),className:pt,onMouseDown:f=>f.stopPropagation(),onChange:g,onKeyDown:j}),(0,t.jsx)("button",{type:"button","aria-label":c("common.cancel"),className:ee,onClick:y,children:(0,t.jsx)(it,{})}),(0,t.jsx)("button",{type:"button","aria-label":c("graph.toolbar.link.apply"),className:ee,onClick:x,children:(0,t.jsx)(a.CheckIcon,{})})]})})})})]})},ft=(e,n)=>{const r=n.trim(),{selection:u}=e.state;if(!r){e.chain().focus().extendMarkRange("link").unsetLink().run();return}if(!u.empty){e.chain().focus().setLink({href:r}).run();return}if(e.isActive("link")){e.chain().focus().extendMarkRange("link").setLink({href:r}).run();return}const i=st(e);e.chain().focus().setTextSelection(i).setLink({href:r}).run()},xt="_1d66w570",gt="_1d66w571",F=({label:e,active:n,onToggle:r,children:u})=>{const i=c=>c.preventDefault();return(0,t.jsxs)(N.Tooltip.Root,{children:[(0,t.jsx)(N.Tooltip.Trigger,{render:(0,t.jsx)(ze.Toggle,{render:(0,t.jsx)(H.Toolbar.Button,{}),pressed:n,onPressedChange:()=>r()}),"aria-label":e,className:xt,onMouseDown:i,children:u}),(0,t.jsx)(N.Tooltip.Portal,{container:o.resolvePortalContainer(),className:a.basePortal,children:(0,t.jsx)(a.EditorPortalThemeProvider,{children:(0,t.jsx)(N.Tooltip.Positioner,{sideOffset:6,className:gt,children:(0,t.jsx)(N.Tooltip.Popup,{className:a.popup,children:e})})})})]})},mt=({editor:e,activeAlignment:n="left"})=>{const r=o.useI18n();return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(F,{label:r("graph.toolbar.textAlign.left"),active:n==="left",onToggle:()=>e.chain().focus().setTextAlign("left").run(),children:(0,t.jsx)(le,{})}),(0,t.jsx)(F,{label:r("graph.toolbar.textAlign.center"),active:n==="center",onToggle:()=>e.chain().focus().setTextAlign("center").run(),children:(0,t.jsx)(ae,{})}),(0,t.jsx)(F,{label:r("graph.toolbar.textAlign.right"),active:n==="right",onToggle:()=>e.chain().focus().setTextAlign("right").run(),children:(0,t.jsx)(ie,{})})]})},Tt="_1u34vl40",vt=({editor:e})=>({bold:e?.isActive("bold")??!1,italic:e?.isActive("italic")??!1,underlined:e?.isActive("underline")??!1,linked:e?.isActive("link")??!1,linkUrl:e?.getAttributes("link").href??null,color:e?.getAttributes("textStyle").color??null,fontFamily:e?.getAttributes("textStyle").fontFamily??null,fontSize:bt(e),textAlign:jt(e)}),bt=e=>e?e.isActive("heading",{level:1})?"h1":e.isActive("heading",{level:2})?"h2":e.isActive("heading",{level:3})?"h3":e.isActive("paragraph",{variant:"caption"})?"caption":"text":"text",jt=e=>e?e.isActive({textAlign:"center"})?"center":e.isActive({textAlign:"right"})?"right":"left":"left",yt=8,St=8,kt=({editor:e})=>{const n=o.useI18n(),[r,u]=(0,h.useState)(!1),[i,c]=(0,h.useState)(null),l=i!==null,d=f=>v=>{c(v?f:null)},{refs:p,floatingStyles:x}=(0,P.useFloating)({placement:"top-start",strategy:"fixed",middleware:[(0,P.offset)(yt),(0,P.flip)(),(0,P.shift)({padding:St})],whileElementsMounted:P.autoUpdate}),y=(0,h.useRef)(null),g=(0,_.useEditorState)({editor:e,selector:vt}),j=(0,h.useCallback)(f=>{y.current=f,p.setFloating(f)},[p]);return(0,h.useEffect)(()=>{e&&p.setReference(e.view.dom)},[e,p]),(0,h.useEffect)(()=>{if(!e)return;const f=()=>u(!0),v=({event:C})=>{const{relatedTarget:S,currentTarget:A}=C,M=S instanceof Node&&y.current?.contains(S),I=S instanceof Node&&A instanceof Node&&A.contains(S);!M&&!I&&u(!1)};return e.on("focus",f),e.on("blur",v),()=>{e.off("focus",f),e.off("blur",v)}},[e]),!e||!r&&!l?null:(0,t.jsx)(a.FloatingToolbar.Portal,{children:(0,t.jsxs)(a.FloatingToolbar.Root,{ref:j,className:Tt,style:x,children:[(0,t.jsxs)(a.FloatingToolbar.Group,{children:[(0,t.jsx)(a.FloatingToolbar.ColorPicker,{color:g?.color??null,onChange:f=>e.chain().setColor(f).run(),open:i==="color",onOpenChange:d("color")}),(0,t.jsx)(tt,{editor:e,currentFontFamily:g?.fontFamily??null,open:i==="fontFamily",onOpenChange:d("fontFamily")})]}),(0,t.jsx)(a.FloatingToolbar.Separator,{}),(0,t.jsx)(a.FloatingToolbar.Group,{children:(0,t.jsx)(nt,{editor:e,activeStyle:g?.fontSize??"text",open:i==="fontSize",onOpenChange:d("fontSize")})}),(0,t.jsx)(a.FloatingToolbar.Separator,{}),(0,t.jsxs)(a.FloatingToolbar.Group,{children:[(0,t.jsx)(F,{label:n("graph.toolbar.formatting.bold"),active:g?.bold??!1,onToggle:()=>e.chain().focus().toggleBold().run(),children:(0,t.jsx)("strong",{children:"B"})}),(0,t.jsx)(F,{label:n("graph.toolbar.formatting.italic"),active:g?.italic??!1,onToggle:()=>e.chain().focus().toggleItalic().run(),children:(0,t.jsx)("em",{children:"I"})}),(0,t.jsx)(F,{label:n("graph.toolbar.formatting.underline"),active:g?.underlined??!1,onToggle:()=>e.chain().focus().toggleUnderline().run(),children:(0,t.jsx)("u",{children:"U"})})]}),(0,t.jsx)(a.FloatingToolbar.Separator,{}),(0,t.jsx)(a.FloatingToolbar.Group,{children:(0,t.jsx)(mt,{editor:e,activeAlignment:g?.textAlign})}),(0,t.jsx)(a.FloatingToolbar.Separator,{}),(0,t.jsx)(a.FloatingToolbar.Group,{children:(0,t.jsx)(ht,{editor:e,currentUrl:g?.linkUrl??null,active:g?.linked??!1,open:i==="link",onOpenChange:d("link")})})]})})},_t="_1uy50v30",Te=({editor:e,ariaLabel:n})=>(0,t.jsxs)("div",{className:_t,children:[(0,t.jsx)(kt,{editor:e}),(0,t.jsx)(_.EditorContent,{editor:e,"aria-label":n})]}),Ct=200,X=({content:e,extensions:n,editable:r,onUpdate:u,updateDebounceMs:i=Ct})=>{const c=(0,h.useRef)(te(e)),l=(0,h.useRef)(c.current),d=o.useDebouncedCallback(x=>{l.current=x,u?.(x)},i),p=(0,_.useEditor)({extensions:n,content:c.current,editable:r,immediatelyRender:!1,onUpdate:({editor:x})=>{const y=x.getJSON();if($(l.current,y))return d.cancel();d.run(y)}});return(0,h.useEffect)(()=>{p?.setEditable(r)},[p,r]),(0,h.useEffect)(()=>{if(!p)return;const x=te(e);$(l.current,x)||(l.current=x,!$(p.getJSON(),x)&&(d.cancel(),Ft(p,x)))},[p,e,d]),(0,h.useEffect)(()=>()=>d.flush(),[d]),p},te=e=>e===null?{type:"doc",content:[]}:typeof e=="string"?{type:"doc",content:[{type:"paragraph",content:e?[{type:"text",text:e}]:[]}]}:e,Ft=(e,n)=>{const{from:r,to:u}=e.state.selection;e.commands.setContent(n,{emitUpdate:!1});const i=e.state.doc.content.size;e.commands.setTextSelection({from:Math.min(r,i),to:Math.min(u,i)})},$=(e,n)=>JSON.stringify(R(e))===JSON.stringify(R(n)),R=e=>Array.isArray(e)?e.map(R):e===null||typeof e!="object"?e:Object.fromEntries(Object.entries(e).map(([n,r])=>[n,R(r)]).filter(([,n])=>!At(n)).sort(([n],[r])=>String(n).localeCompare(String(r)))),At=e=>e==null||typeof e=="object"&&Object.keys(e).length===0,Et=({caption:e,captionStyle:n})=>{const{dispatch:r}=o.useGraphCommands(),u=o.useEditorStore(),i=X({content:e,extensions:(0,h.useMemo)(()=>Xe({placeholder:o.CAPTION_PLACEHOLDER}),[]),editable:!0,onUpdate:c=>{const l=lt(c)?null:c;r(new m.SetContentCaptionCommand({caption:l}))}});return(0,h.useLayoutEffect)(()=>{i!==null&&ue(i,u.getState().takePendingTextCaret("caption"))},[i,u]),(0,t.jsx)("div",{"data-testid":"caption-editor",style:o.toHtmlTextCss(n),children:i===null?(0,t.jsx)(o.CaptionTextSurface,{caption:e}):(0,t.jsx)(Te,{editor:i,ariaLabel:"Chart caption"})})},Pt=e=>[D.Document,oe.Paragraph,...K(),Lt,B.Placeholder.configure({showOnlyCurrent:!1,placeholder:({pos:n})=>n===0?e:""})],Nt=({annotation:e})=>{const n=o.useI18n(),{dispatch:r}=o.useGraphCommands(),u=o.useEditorStore(),i=(0,h.useMemo)(()=>Pt(n("graph.annotations.text.placeholder")),[n]),c=X({content:e.content,extensions:i,editable:!0,onUpdate:p=>{r(new m.UpdateAnnotationCommand({kind:"text",id:e.id,patch:{content:p}}))}});(0,h.useEffect)(()=>{const{setCaretEditor:p}=u.getState();return p(c),()=>p(null)},[c,u]),(0,h.useEffect)(()=>{c?.commands.focus("end",{scrollIntoView:!1})},[c]);const l=(0,_.useEditorState)({editor:c,selector:({editor:p})=>a.readPickedFontSize(p)}),d=(0,_.useEditorState)({editor:c,selector:({editor:p})=>a.readPickedFont(p)});return(0,t.jsx)(_.EditorContent,{"aria-label":n("graph.annotations.text.editLabel"),className:o.editor,editor:c,style:{...l===null?{}:{fontSize:`calc(${l}px * ${o.vars.textScale})`},...d===null?{}:{fontFamily:o.resolveRichTextFontFamily(d)}},"data-testid":"text-annotation-editor"})},ne=e=>{const n=o.resolveRichTextFontFamily(e);return n===void 0?{}:{style:`font-family: ${n}`}},Lt=re.Extension.create({name:"annotationTextStyleAttributes",addGlobalAttributes(){return[{types:["textStyle"],attributes:{fontFamily:{default:null,renderHTML:e=>ne(e.fontFamily)},font:{default:null,renderHTML:e=>ne(e.font)},fontSize:{default:null,renderHTML:e=>typeof e.fontSize=="number"&&Number.isFinite(e.fontSize)?{style:`font-size: calc(${e.fontSize}px * ${o.vars.textScale})`}:{}}}}]}}),Mt=({title:e,showTitle:n,showSubtitle:r,subtitle:u})=>{const{dispatch:i}=o.useGraphCommands(),c=o.useEditorStore(),l=(0,h.useMemo)(()=>Ke({titlePlaceholder:o.TITLE_PLACEHOLDER,subtitlePlaceholder:o.TITLE_PLACEHOLDER,showTitle:n,showSubtitle:r}),[n,r]),d=X({content:(0,h.useMemo)(()=>o.buildTitleEditorDoc({title:e,showTitle:n,subtitle:u,showSubtitle:r}),[e,n,u,r]),extensions:l,editable:!0,onUpdate:p=>{const x=o.splitTitleEditorDoc(p,n);n&&i(new m.SetContentTitleCommand({title:x.title})),r&&i(new m.SetContentSubtitleCommand({subtitle:x.subtitle}))}});return(0,h.useLayoutEffect)(()=>{d!==null&&ue(d,c.getState().takePendingTextCaret("header"))},[d,c]),(0,t.jsx)("div",{className:o.textStyleEditor,"data-testid":"title-editor",children:d===null?(0,t.jsx)(o.HeaderTextSurface,{title:e,showTitle:n,showSubtitle:r,subtitle:u}):(0,t.jsx)(Te,{editor:d,ariaLabel:"Chart title and subtitle"})})};exports.CaptionEditor=Et;exports.TextAnnotationEditor=Nt;exports.TextToolbar=qe;exports.TitleEditor=Mt;