@wakastellar/ui 6.0.2 → 6.0.3

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 +1 @@
1
- "use client";const e=require("../../node_modules/.pnpm/@muyajs_core@file_vendor_muyajs-core/node_modules/@muyajs/core/lib/es/index.cjs.js"),t=require("./muyaCommands.cjs.js"),n=require("./fileIO.cjs.js"),r=require("./toolbar-config.cjs.js"),i=require("./injectStyles.cjs.js");let a=require("react"),o=require("react/jsx-runtime");i.injectMdEditorStyles();var s={fr:e.fr,en:e.en,de:e.de,es:e.es,ja:e.ja,ko:e.ko,pt:e.pt,zhCN:e.zhCN,zhTW:e.zhTW},ee={frontMatter:!0,footnote:!0,superSubScript:!0,focusMode:!1,spellcheckEnabled:!1,fontSize:16,lineHeight:1.6},c={},l=!1;function u(){l||(l=!0,e.Muya.use(e.EmojiSelector),e.Muya.use(e.FootnoteTool),e.Muya.use(e.InlineFormatToolbar),e.Muya.use(e.ImageEditTool,{imagePathPicker:async()=>await c.picker?.()??``,imageAction:async e=>await c.action?.(e)??e}),e.Muya.use(e.ImagePathPicker),e.Muya.use(e.ImageToolBar),e.Muya.use(e.ImageResizeBar),e.Muya.use(e.CodeBlockLanguageSelector),e.Muya.use(e.LinkTools,{jumpClick:e=>{let t=e?.href;t&&/^https?:\/\//.test(t)&&window.open(t,`_blank`,`noopener,noreferrer`)}}),e.Muya.use(e.ParagraphFrontButton),e.Muya.use(e.ParagraphFrontMenu),e.Muya.use(e.TableChessboard),e.Muya.use(e.TableColumnToolbar),e.Muya.use(e.ParagraphQuickInsertMenu),e.Muya.use(e.TableDragBar),e.Muya.use(e.TableRowColumMenu),e.Muya.use(e.PreviewToolBar))}async function te(){return new Promise((e,t)=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`image/*`,n.onchange=()=>{let r=n.files?.[0];if(!r){t(Error(`Aucune image sélectionnée`));return}let i=new FileReader;i.onload=()=>e(String(i.result)),i.onerror=()=>t(Error(`Lecture impossible`)),i.readAsDataURL(r)},n.click()})}var d=(0,a.forwardRef)(function(i,l){let{defaultValue:d=``,value:f,options:p,locale:m=`fr`,theme:h=`light`,toolbar:g=!0,onChange:_,onOpen:v,onSave:y,onDirtyChange:b,onLoadingChange:x,onSavingChange:S,getMuya:ne,className:C,style:re}=i;u(),c={picker:i.imagePathPicker??te,action:i.imageAction??(async e=>e)};let w=(0,a.useRef)(null),T=(0,a.useRef)(null),E=(0,a.useRef)(f??d),D=(0,a.useRef)(!1),O=(0,a.useRef)({handle:null,name:null}),[k,A]=(0,a.useState)(!1),j=(0,a.useRef)(!1),M=(0,a.useRef)(_);M.current=_;let N=(0,a.useRef)(b);N.current=b;let[P,ie]=(0,a.useState)({formats:new Set,blockName:null,headingLevel:null,inColorSpan:!1}),[F,I]=(0,a.useState)(null),[L,R]=(0,a.useState)(!1),[z,B]=(0,a.useState)(`idle`),V=(0,a.useRef)(null),H=(0,a.useCallback)(()=>{V.current&&=(clearTimeout(V.current),null),B(`saving`),S?.(!0)},[S]),U=(0,a.useCallback)(e=>{S?.(!1),B(e),e===`saved`&&(V.current&&clearTimeout(V.current),V.current=setTimeout(()=>B(`idle`),1200))},[S]);(0,a.useEffect)(()=>()=>{V.current&&clearTimeout(V.current)},[]);let W=(0,a.useCallback)(e=>{j.current!==e&&(j.current=e,A(e),N.current?.(e))},[]),G=(0,a.useCallback)(()=>{let e=T.current;e&&ie(t.getActiveState(e))},[]);(0,a.useEffect)(()=>{let t=w.current;if(!t)return;let n=new e.Muya(t,{...ee,...p,markdown:f??d});return n.locale(s[m]??e.fr),n.init(),T.current=n,ne?.(n),n.on(`json-change`,()=>{let e=n.getMarkdown();E.current=e,D.current||M.current?.(e),W(!0),G()}),n.on(`selection-change`,()=>G()),G(),()=>{n.destroy(),T.current=null}},[]),(0,a.useEffect)(()=>{let e=T.current;if(!(!e||f===void 0||f===E.current)){D.current=!0;try{e.setContent(f,!1),E.current=f}finally{D.current=!1}}},[f]),(0,a.useEffect)(()=>{T.current?.locale(s[m]??e.fr)},[m]),(0,a.useEffect)(()=>(document.body.classList.toggle(`wmd-theme-dark`,h===`dark`),()=>document.body.classList.remove(`wmd-theme-dark`)),[h]);let K=(0,a.useCallback)(async()=>{let e=await n.openMarkdownFile(),t=T.current;if(!(!e||!t)){R(!0),x?.(!0),await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(()=>e())));try{O.current={handle:e.handle,name:e.name},D.current=!0;try{t.setContent(e.markdown,!1),E.current=e.markdown}finally{D.current=!1}W(!1),G(),v?.(e.markdown,{name:e.name,handle:e.handle})}finally{R(!1),x?.(!1)}}},[v,G,W,x]),q=(0,a.useRef)(!1),J=(0,a.useCallback)(async()=>{let e=T.current;if(!(!e||q.current)){q.current=!0,H();try{let t=await n.saveMarkdownFile(e.getMarkdown(),O.current,!0);if(!t){U(`idle`);return}O.current={handle:t.handle,name:t.name},W(!1),y?.(e.getMarkdown(),{name:t.name,handle:t.handle}),U(`saved`)}catch(e){throw U(`idle`),e}finally{q.current=!1}}},[y,W,U,H]),Y=(0,a.useCallback)(async()=>{let e=T.current;if(!(!e||q.current)){if(!O.current.handle){await J();return}q.current=!0,H();try{let t=e.getMarkdown(),r=await n.saveMarkdownFile(t,O.current,!1);if(!r){U(`idle`);return}W(!1),y?.(t,{name:r.name,handle:r.handle}),U(`saved`)}catch(e){throw U(`idle`),e}finally{q.current=!1}}},[y,J,W,U,H]);(0,a.useEffect)(()=>{let e=e=>{if(!(e.metaKey||e.ctrlKey))return;let t=e.key.toLowerCase();t===`s`?(e.preventDefault(),e.shiftKey?J():Y()):t===`o`&&(e.preventDefault(),K())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[K,Y,J]);let X=(0,a.useCallback)(e=>{let n=T.current;if(n){switch(e){case`open`:K();break;case`save`:Y();break;case`saveAs`:J();break;case`undo`:n.undo();break;case`redo`:n.redo();break;case`paragraph`:t.turnIntoBlock(n,`paragraph`);break;case`heading1`:case`heading2`:case`heading3`:case`heading4`:case`heading5`:case`heading6`:t.turnIntoBlock(n,`heading ${Number(e.slice(-1))}`);break;case`bold`:t.applyInlineFormat(n,`strong`);break;case`italic`:t.applyInlineFormat(n,`em`);break;case`underline`:t.applyInlineFormat(n,`u`);break;case`strikethrough`:t.applyInlineFormat(n,`del`);break;case`highlight`:t.applyInlineFormat(n,`mark`);break;case`inlineCode`:t.applyInlineFormat(n,`inline_code`);break;case`clearFormat`:t.applyInlineFormat(n,`clear`);break;case`bulletList`:t.turnIntoBlock(n,`ul-bullet`);break;case`orderedList`:t.turnIntoBlock(n,`ol-order`);break;case`taskList`:t.turnIntoBlock(n,`ul-task`);break;case`blockquote`:t.turnIntoBlock(n,`blockquote`);break;case`codeBlock`:t.turnIntoBlock(n,`pre`);break;case`horizontalRule`:t.turnIntoBlock(n,`hr`);break;case`link`:t.applyInlineFormat(n,`link`);break;case`image`:t.applyInlineFormat(n,`image`);break;case`table`:t.insertTable(n);break;default:break}G()}},[K,Y,J,G]),Z=(0,a.useCallback)(e=>{let n=T.current;n&&(t.applyTextColor(n,e),I(null),G())},[G]);(0,a.useImperativeHandle)(l,()=>({getMarkdown:()=>T.current?.getMarkdown()??``,setMarkdown:(e,t=!1)=>{let n=T.current;if(n){D.current=!0;try{n.setContent(e,t),E.current=e}finally{D.current=!1}}},focus:()=>T.current?.focus(),toggleFormat:e=>T.current&&t.applyInlineFormat(T.current,e),turnInto:e=>T.current&&t.turnIntoBlock(T.current,e),applyColor:e=>Z(e),undo:()=>T.current?.undo(),redo:()=>T.current?.redo(),openFile:()=>K(),saveFile:()=>Y(),saveFileAs:()=>J(),isDirty:()=>j.current}),[K,Y,J,Z]);let Q=g===!1?!1:Array.isArray(g)?g:r.DEFAULT_TOOLBAR,$=e=>{switch(e){case`bold`:return P.formats.has(`strong`);case`italic`:return P.formats.has(`em`);case`underline`:return P.formats.has(`u`);case`strikethrough`:return P.formats.has(`del`);case`highlight`:return P.formats.has(`mark`);case`inlineCode`:return P.formats.has(`inline_code`);case`textColor`:return P.formats.has(`color`);case`paragraph`:return P.blockName===`paragraph`;case`heading1`:return P.blockName===`atx-heading`&&P.headingLevel===1;case`heading2`:return P.blockName===`atx-heading`&&P.headingLevel===2;case`heading3`:return P.blockName===`atx-heading`&&P.headingLevel===3;case`heading4`:return P.blockName===`atx-heading`&&P.headingLevel===4;case`heading5`:return P.blockName===`atx-heading`&&P.headingLevel===5;case`heading6`:return P.blockName===`atx-heading`&&P.headingLevel===6;case`bulletList`:return P.blockName===`bullet-list`;case`orderedList`:return P.blockName===`order-list`;case`taskList`:return P.blockName===`task-list`;case`blockquote`:return P.blockName===`block-quote`;case`codeBlock`:return P.blockName===`code-block`;case`save`:return k;default:return!1}};(0,a.useEffect)(()=>{if(!F)return;let e=e=>{e.target?.closest(`.wmd-popup-anchor`)||I(null)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[F]);let ae=P.blockName===`atx-heading`&&P.headingLevel?`T${P.headingLevel}`:P.blockName===`paragraph`?`¶`:`T`,oe=e=>e===`heading`?(0,o.jsxs)(`div`,{className:`wmd-popup-anchor`,children:[(0,o.jsxs)(`button`,{type:`button`,className:`wmd-btn${F===`heading`?` wmd-btn--active`:``}`,title:r.TOOLBAR_LABELS.heading,onMouseDown:e=>e.preventDefault(),onClick:()=>I(F===`heading`?null:`heading`),children:[r.TOOLBAR_ICONS.heading,(0,o.jsx)(`span`,{className:`wmd-btn-label`,children:ae}),r.TOOLBAR_ICONS.chevronDown]}),F===`heading`&&(0,o.jsx)(`div`,{className:`wmd-popup`,role:`menu`,children:r.HEADING_MENU.map(e=>(0,o.jsx)(`button`,{type:`button`,role:`menuitem`,className:`wmd-popup-item${$(e.id)?` wmd-popup-item--active`:``}`,onMouseDown:e=>e.preventDefault(),onClick:()=>{X(e.id),I(null)},children:(0,o.jsx)(`span`,{className:`wmd-heading-item`,"data-level":e.id===`paragraph`?0:e.id.slice(-1),children:e.label})},e.id))})]},e):e===`textColor`?(0,o.jsxs)(`div`,{className:`wmd-popup-anchor`,children:[(0,o.jsxs)(`button`,{type:`button`,className:`wmd-btn${P.formats.has(`color`)||F===`textColor`?` wmd-btn--active`:``}`,title:r.TOOLBAR_LABELS.textColor,onMouseDown:e=>e.preventDefault(),onClick:()=>I(F===`textColor`?null:`textColor`),children:[r.TOOLBAR_ICONS.textColor,(0,o.jsx)(`span`,{className:`wmd-btn-label`,style:{borderBottom:`2px solid currentColor`,paddingBottom:1},children:`A`}),r.TOOLBAR_ICONS.chevronDown]}),F===`textColor`&&(0,o.jsxs)(`div`,{className:`wmd-popup`,role:`menu`,children:[(0,o.jsx)(`div`,{className:`wmd-color-grid`,children:r.TEXT_COLORS.map(e=>(0,o.jsx)(`button`,{type:`button`,className:`wmd-color-swatch`,title:e.name,style:{background:e.value},onMouseDown:e=>e.preventDefault(),onClick:()=>Z(e.value)},e.value))}),(0,o.jsxs)(`label`,{className:`wmd-color-custom`,children:[(0,o.jsx)(`input`,{type:`color`,defaultValue:`#2563eb`,onMouseDown:e=>e.stopPropagation(),onChange:e=>Z(e.target.value)}),`Couleur personnalisée…`]})]})]},e):(0,o.jsx)(`button`,{type:`button`,className:[`wmd-btn`,$(e)?`wmd-btn--active`:``,e===`save`&&k?`wmd-btn--dirty`:``].filter(Boolean).join(` `),title:r.TOOLBAR_LABELS[e],disabled:e===`open`&&L||(e===`save`||e===`saveAs`)&&z===`saving`,onMouseDown:e=>e.preventDefault(),onClick:()=>X(e),children:r.TOOLBAR_ICONS[e]??e},e);return(0,o.jsxs)(`div`,{className:`wmd-editor${C?` ${C}`:``}`,"data-theme":h,style:re,children:[Q!==!1&&(0,o.jsx)(`div`,{className:`wmd-toolbar`,role:`toolbar`,"aria-label":`Barre d'outils Markdown`,children:Q.map((e,t)=>e===`|`?(0,o.jsx)(`span`,{className:`wmd-separator`},`sep-${t}`):(0,o.jsx)(`div`,{className:`wmd-toolbar-group`,children:oe(e)},e))}),(0,o.jsxs)(`div`,{className:`wmd-editor-surface`,children:[(0,o.jsx)(`div`,{ref:w}),L&&(0,o.jsxs)(`div`,{className:`wmd-loading-overlay`,role:`status`,"aria-live":`polite`,children:[(0,o.jsx)(`span`,{className:`wmd-spinner`,"aria-hidden":`true`}),(0,o.jsx)(`span`,{children:`Chargement du fichier…`})]})]}),z!==`idle`&&(0,o.jsx)(`div`,{className:`wmd-modal-backdrop`,role:`status`,"aria-live":`polite`,children:(0,o.jsx)(`div`,{className:`wmd-modal`,children:z===`saving`?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`span`,{className:`wmd-spinner`,"aria-hidden":`true`}),(0,o.jsx)(`span`,{className:`wmd-modal-text`,children:`Enregistrement…`})]}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(`svg`,{className:`wmd-modal-check`,viewBox:`0 0 24 24`,width:`28`,height:`28`,"aria-hidden":`true`,children:[(0,o.jsx)(`circle`,{cx:`12`,cy:`12`,r:`11`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`}),(0,o.jsx)(`path`,{d:`M7 12.5l3 3 7-7`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})]}),(0,o.jsxs)(`span`,{className:`wmd-modal-text`,children:[`Enregistré`,O.current.name?` — ${O.current.name}`:``]})]})})})]})});exports.WakaMdEditor=d,exports.default=d;
1
+ "use client";const e=require("../../node_modules/.pnpm/@muyajs_core@file_vendor_muyajs-core/node_modules/@muyajs/core/lib/es/index.cjs.js"),t=require("./muyaCommands.cjs.js"),n=require("./fileIO.cjs.js"),r=require("./toolbar-config.cjs.js"),i=require("./injectStyles.cjs.js");let a=require("react"),o=require("react/jsx-runtime");i.injectMdEditorStyles();var s={fr:e.fr,en:e.en,de:e.de,es:e.es,ja:e.ja,ko:e.ko,pt:e.pt,zhCN:e.zhCN,zhTW:e.zhTW},ee={frontMatter:!0,footnote:!0,superSubScript:!0,focusMode:!1,spellcheckEnabled:!1,fontSize:16,lineHeight:1.6},c={},l={};function u(e){/^https?:\/\//.test(e)&&window.open(e,`_blank`,`noopener,noreferrer`)}var d=!1;function te(){d||(d=!0,e.Muya.use(e.EmojiSelector),e.Muya.use(e.FootnoteTool),e.Muya.use(e.InlineFormatToolbar),e.Muya.use(e.ImageEditTool,{imagePathPicker:async()=>await c.picker?.()??``,imageAction:async e=>await c.action?.(e)??e}),e.Muya.use(e.ImagePathPicker),e.Muya.use(e.ImageToolBar),e.Muya.use(e.ImageResizeBar),e.Muya.use(e.CodeBlockLanguageSelector),e.Muya.use(e.LinkTools,{jumpClick:e=>{let t=e?.href;t&&(l.onLinkClick?l.onLinkClick(t,()=>u(t)):u(t))}}),e.Muya.use(e.ParagraphFrontButton),e.Muya.use(e.ParagraphFrontMenu),e.Muya.use(e.TableChessboard),e.Muya.use(e.TableColumnToolbar),e.Muya.use(e.ParagraphQuickInsertMenu),e.Muya.use(e.TableDragBar),e.Muya.use(e.TableRowColumMenu),e.Muya.use(e.PreviewToolBar))}async function ne(){return new Promise((e,t)=>{let n=document.createElement(`input`);n.type=`file`,n.accept=`image/*`,n.onchange=()=>{let r=n.files?.[0];if(!r){t(Error(`Aucune image sélectionnée`));return}let i=new FileReader;i.onload=()=>e(String(i.result)),i.onerror=()=>t(Error(`Lecture impossible`)),i.readAsDataURL(r)},n.click()})}var f=(0,a.forwardRef)(function(i,u){let{defaultValue:d=``,value:f,options:re,locale:p=`fr`,theme:m=`light`,toolbar:h=!0,onChange:g,onOpen:_,onSave:v,onDirtyChange:y,onLoadingChange:b,onSavingChange:x,onLinkClick:S,getMuya:ie,className:C,style:ae}=i;te(),c={picker:i.imagePathPicker??ne,action:i.imageAction??(async e=>e)},l={onLinkClick:S};let w=(0,a.useRef)(null),T=(0,a.useRef)(null),E=(0,a.useRef)(f??d),D=(0,a.useRef)(!1),O=(0,a.useRef)({handle:null,name:null}),[k,oe]=(0,a.useState)(!1),A=(0,a.useRef)(!1),j=(0,a.useRef)(g);j.current=g;let M=(0,a.useRef)(y);M.current=y;let[N,P]=(0,a.useState)({formats:new Set,blockName:null,headingLevel:null,inColorSpan:!1}),[F,I]=(0,a.useState)(null),[L,R]=(0,a.useState)(!1),[z,B]=(0,a.useState)(`idle`),V=(0,a.useRef)(null),H=(0,a.useCallback)(()=>{V.current&&=(clearTimeout(V.current),null),B(`saving`),x?.(!0)},[x]),U=(0,a.useCallback)(e=>{x?.(!1),B(e),e===`saved`&&(V.current&&clearTimeout(V.current),V.current=setTimeout(()=>B(`idle`),1200))},[x]);(0,a.useEffect)(()=>()=>{V.current&&clearTimeout(V.current)},[]);let W=(0,a.useCallback)(e=>{A.current!==e&&(A.current=e,oe(e),M.current?.(e))},[]),G=(0,a.useCallback)(()=>{let e=T.current;e&&P(t.getActiveState(e))},[]);(0,a.useEffect)(()=>{let t=w.current;if(!t)return;let n=new e.Muya(t,{...ee,...re,markdown:f??d});n.locale(s[p]??e.fr);try{n.init()}catch(e){if(!(e instanceof Error)||!/Range to be added to the Selection/.test(e.message))throw e}return T.current=n,ie?.(n),n.on(`json-change`,()=>{let e=n.getMarkdown();E.current=e,D.current||j.current?.(e),W(!0),G()}),n.on(`selection-change`,()=>G()),G(),()=>{n.destroy(),T.current=null}},[]),(0,a.useEffect)(()=>{let e=T.current;if(!(!e||f===void 0||f===E.current)){D.current=!0;try{e.setContent(f,!1),E.current=f}finally{D.current=!1}}},[f]),(0,a.useEffect)(()=>{T.current?.locale(s[p]??e.fr)},[p]),(0,a.useEffect)(()=>(document.body.classList.toggle(`wmd-theme-dark`,m===`dark`),()=>document.body.classList.remove(`wmd-theme-dark`)),[m]);let K=(0,a.useCallback)(async()=>{let e=await n.openMarkdownFile(),t=T.current;if(!(!e||!t)){R(!0),b?.(!0),await new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(()=>e())));try{O.current={handle:e.handle,name:e.name},D.current=!0;try{t.setContent(e.markdown,!1),E.current=e.markdown}finally{D.current=!1}W(!1),G(),_?.(e.markdown,{name:e.name,handle:e.handle})}finally{R(!1),b?.(!1)}}},[_,G,W,b]),q=(0,a.useRef)(!1),J=(0,a.useCallback)(async()=>{let e=T.current;if(!(!e||q.current)){q.current=!0,H();try{let t=await n.saveMarkdownFile(e.getMarkdown(),O.current,!0);if(!t){U(`idle`);return}O.current={handle:t.handle,name:t.name},W(!1),v?.(e.getMarkdown(),{name:t.name,handle:t.handle}),U(`saved`)}catch(e){throw U(`idle`),e}finally{q.current=!1}}},[v,W,U,H]),Y=(0,a.useCallback)(async()=>{let e=T.current;if(!(!e||q.current)){if(!O.current.handle){await J();return}q.current=!0,H();try{let t=e.getMarkdown(),r=await n.saveMarkdownFile(t,O.current,!1);if(!r){U(`idle`);return}W(!1),v?.(t,{name:r.name,handle:r.handle}),U(`saved`)}catch(e){throw U(`idle`),e}finally{q.current=!1}}},[v,J,W,U,H]);(0,a.useEffect)(()=>{let e=e=>{if(!(e.metaKey||e.ctrlKey))return;let t=e.key.toLowerCase();t===`s`?(e.preventDefault(),e.shiftKey?J():Y()):t===`o`&&(e.preventDefault(),K())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[K,Y,J]);let X=(0,a.useCallback)(e=>{let n=T.current;if(n){switch(e){case`open`:K();break;case`save`:Y();break;case`saveAs`:J();break;case`undo`:n.undo();break;case`redo`:n.redo();break;case`paragraph`:t.turnIntoBlock(n,`paragraph`);break;case`heading1`:case`heading2`:case`heading3`:case`heading4`:case`heading5`:case`heading6`:t.turnIntoBlock(n,`heading ${Number(e.slice(-1))}`);break;case`bold`:t.applyInlineFormat(n,`strong`);break;case`italic`:t.applyInlineFormat(n,`em`);break;case`underline`:t.applyInlineFormat(n,`u`);break;case`strikethrough`:t.applyInlineFormat(n,`del`);break;case`highlight`:t.applyInlineFormat(n,`mark`);break;case`inlineCode`:t.applyInlineFormat(n,`inline_code`);break;case`clearFormat`:t.applyInlineFormat(n,`clear`);break;case`bulletList`:t.turnIntoBlock(n,`ul-bullet`);break;case`orderedList`:t.turnIntoBlock(n,`ol-order`);break;case`taskList`:t.turnIntoBlock(n,`ul-task`);break;case`blockquote`:t.turnIntoBlock(n,`blockquote`);break;case`codeBlock`:t.turnIntoBlock(n,`pre`);break;case`horizontalRule`:t.turnIntoBlock(n,`hr`);break;case`link`:t.applyInlineFormat(n,`link`);break;case`image`:t.applyInlineFormat(n,`image`);break;case`table`:t.insertTable(n);break;default:break}G()}},[K,Y,J,G]),Z=(0,a.useCallback)(e=>{let n=T.current;n&&(t.applyTextColor(n,e),I(null),G())},[G]);(0,a.useImperativeHandle)(u,()=>({getMarkdown:()=>T.current?.getMarkdown()??``,setMarkdown:(e,t=!1)=>{let n=T.current;if(n){D.current=!0;try{n.setContent(e,t),E.current=e}finally{D.current=!1}}},focus:()=>T.current?.focus(),toggleFormat:e=>T.current&&t.applyInlineFormat(T.current,e),turnInto:e=>T.current&&t.turnIntoBlock(T.current,e),applyColor:e=>Z(e),undo:()=>T.current?.undo(),redo:()=>T.current?.redo(),openFile:()=>K(),saveFile:()=>Y(),saveFileAs:()=>J(),isDirty:()=>A.current}),[K,Y,J,Z]);let Q=h===!1?!1:Array.isArray(h)?h:r.DEFAULT_TOOLBAR,$=e=>{switch(e){case`bold`:return N.formats.has(`strong`);case`italic`:return N.formats.has(`em`);case`underline`:return N.formats.has(`u`);case`strikethrough`:return N.formats.has(`del`);case`highlight`:return N.formats.has(`mark`);case`inlineCode`:return N.formats.has(`inline_code`);case`textColor`:return N.formats.has(`color`);case`paragraph`:return N.blockName===`paragraph`;case`heading1`:return N.blockName===`atx-heading`&&N.headingLevel===1;case`heading2`:return N.blockName===`atx-heading`&&N.headingLevel===2;case`heading3`:return N.blockName===`atx-heading`&&N.headingLevel===3;case`heading4`:return N.blockName===`atx-heading`&&N.headingLevel===4;case`heading5`:return N.blockName===`atx-heading`&&N.headingLevel===5;case`heading6`:return N.blockName===`atx-heading`&&N.headingLevel===6;case`bulletList`:return N.blockName===`bullet-list`;case`orderedList`:return N.blockName===`order-list`;case`taskList`:return N.blockName===`task-list`;case`blockquote`:return N.blockName===`block-quote`;case`codeBlock`:return N.blockName===`code-block`;case`save`:return k;default:return!1}};(0,a.useEffect)(()=>{if(!F)return;let e=e=>{e.target?.closest(`.wmd-popup-anchor`)||I(null)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[F]);let se=N.blockName===`atx-heading`&&N.headingLevel?`T${N.headingLevel}`:N.blockName===`paragraph`?`¶`:`T`,ce=e=>e===`heading`?(0,o.jsxs)(`div`,{className:`wmd-popup-anchor`,children:[(0,o.jsxs)(`button`,{type:`button`,className:`wmd-btn${F===`heading`?` wmd-btn--active`:``}`,title:r.TOOLBAR_LABELS.heading,onMouseDown:e=>e.preventDefault(),onClick:()=>I(F===`heading`?null:`heading`),children:[r.TOOLBAR_ICONS.heading,(0,o.jsx)(`span`,{className:`wmd-btn-label`,children:se}),r.TOOLBAR_ICONS.chevronDown]}),F===`heading`&&(0,o.jsx)(`div`,{className:`wmd-popup`,role:`menu`,children:r.HEADING_MENU.map(e=>(0,o.jsx)(`button`,{type:`button`,role:`menuitem`,className:`wmd-popup-item${$(e.id)?` wmd-popup-item--active`:``}`,onMouseDown:e=>e.preventDefault(),onClick:()=>{X(e.id),I(null)},children:(0,o.jsx)(`span`,{className:`wmd-heading-item`,"data-level":e.id===`paragraph`?0:e.id.slice(-1),children:e.label})},e.id))})]},e):e===`textColor`?(0,o.jsxs)(`div`,{className:`wmd-popup-anchor`,children:[(0,o.jsxs)(`button`,{type:`button`,className:`wmd-btn${N.formats.has(`color`)||F===`textColor`?` wmd-btn--active`:``}`,title:r.TOOLBAR_LABELS.textColor,onMouseDown:e=>e.preventDefault(),onClick:()=>I(F===`textColor`?null:`textColor`),children:[r.TOOLBAR_ICONS.textColor,(0,o.jsx)(`span`,{className:`wmd-btn-label`,style:{borderBottom:`2px solid currentColor`,paddingBottom:1},children:`A`}),r.TOOLBAR_ICONS.chevronDown]}),F===`textColor`&&(0,o.jsxs)(`div`,{className:`wmd-popup`,role:`menu`,children:[(0,o.jsx)(`div`,{className:`wmd-color-grid`,children:r.TEXT_COLORS.map(e=>(0,o.jsx)(`button`,{type:`button`,className:`wmd-color-swatch`,title:e.name,style:{background:e.value},onMouseDown:e=>e.preventDefault(),onClick:()=>Z(e.value)},e.value))}),(0,o.jsxs)(`label`,{className:`wmd-color-custom`,children:[(0,o.jsx)(`input`,{type:`color`,defaultValue:`#2563eb`,onMouseDown:e=>e.stopPropagation(),onChange:e=>Z(e.target.value)}),`Couleur personnalisée…`]})]})]},e):(0,o.jsx)(`button`,{type:`button`,className:[`wmd-btn`,$(e)?`wmd-btn--active`:``,e===`save`&&k?`wmd-btn--dirty`:``].filter(Boolean).join(` `),title:r.TOOLBAR_LABELS[e],disabled:e===`open`&&L||(e===`save`||e===`saveAs`)&&z===`saving`,onMouseDown:e=>e.preventDefault(),onClick:()=>X(e),children:r.TOOLBAR_ICONS[e]??e},e);return(0,o.jsxs)(`div`,{className:`wmd-editor${C?` ${C}`:``}`,"data-theme":m,style:ae,children:[Q!==!1&&(0,o.jsx)(`div`,{className:`wmd-toolbar`,role:`toolbar`,"aria-label":`Barre d'outils Markdown`,children:Q.map((e,t)=>e===`|`?(0,o.jsx)(`span`,{className:`wmd-separator`},`sep-${t}`):(0,o.jsx)(`div`,{className:`wmd-toolbar-group`,children:ce(e)},e))}),(0,o.jsxs)(`div`,{className:`wmd-editor-surface`,children:[(0,o.jsx)(`div`,{ref:w}),L&&(0,o.jsxs)(`div`,{className:`wmd-loading-overlay`,role:`status`,"aria-live":`polite`,children:[(0,o.jsx)(`span`,{className:`wmd-spinner`,"aria-hidden":`true`}),(0,o.jsx)(`span`,{children:`Chargement du fichier…`})]})]}),z!==`idle`&&(0,o.jsx)(`div`,{className:`wmd-modal-backdrop`,role:`status`,"aria-live":`polite`,children:(0,o.jsx)(`div`,{className:`wmd-modal`,children:z===`saving`?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`span`,{className:`wmd-spinner`,"aria-hidden":`true`}),(0,o.jsx)(`span`,{className:`wmd-modal-text`,children:`Enregistrement…`})]}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(`svg`,{className:`wmd-modal-check`,viewBox:`0 0 24 24`,width:`28`,height:`28`,"aria-hidden":`true`,children:[(0,o.jsx)(`circle`,{cx:`12`,cy:`12`,r:`11`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`}),(0,o.jsx)(`path`,{d:`M7 12.5l3 3 7-7`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})]}),(0,o.jsxs)(`span`,{className:`wmd-modal-text`,children:[`Enregistré`,O.current.name?` — ${O.current.name}`:``]})]})})})]})});exports.WakaMdEditor=f,exports.default=f;
@@ -1,24 +1,24 @@
1
1
  "use client";
2
- import { CodeBlockLanguageSelector as e, EmojiSelector as t, FootnoteTool as n, ImageEditTool as r, ImagePathPicker as i, ImageResizeBar as a, ImageToolBar as o, InlineFormatToolbar as s, LinkTools as c, Muya as l, ParagraphFrontButton as u, ParagraphFrontMenu as d, ParagraphQuickInsertMenu as f, PreviewToolBar as p, TableChessboard as m, TableColumnToolbar as ee, TableDragBar as h, TableRowColumMenu as g, de as _, en as v, es as y, fr as b, ja as x, ko as S, pt as C, zhCN as te, zhTW as w } from "../../node_modules/.pnpm/@muyajs_core@file_vendor_muyajs-core/node_modules/@muyajs/core/lib/es/index.es.js";
3
- import { applyInlineFormat as T, applyTextColor as ne, getActiveState as re, insertTable as ie, turnIntoBlock as E } from "./muyaCommands.es.js";
4
- import { openMarkdownFile as ae, saveMarkdownFile as oe } from "./fileIO.es.js";
5
- import { DEFAULT_TOOLBAR as se, HEADING_MENU as ce, TEXT_COLORS as le, TOOLBAR_ICONS as D, TOOLBAR_LABELS as O } from "./toolbar-config.es.js";
6
- import { injectMdEditorStyles as k } from "./injectStyles.es.js";
7
- import { forwardRef as A, useCallback as j, useEffect as M, useImperativeHandle as ue, useRef as N, useState as P } from "react";
8
- import { Fragment as de, jsx as F, jsxs as I } from "react/jsx-runtime";
2
+ import { CodeBlockLanguageSelector as e, EmojiSelector as t, FootnoteTool as n, ImageEditTool as r, ImagePathPicker as i, ImageResizeBar as a, ImageToolBar as o, InlineFormatToolbar as s, LinkTools as c, Muya as l, ParagraphFrontButton as u, ParagraphFrontMenu as d, ParagraphQuickInsertMenu as f, PreviewToolBar as p, TableChessboard as m, TableColumnToolbar as ee, TableDragBar as te, TableRowColumMenu as h, de as ne, en as g, es as _, fr as v, ja as y, ko as b, pt as x, zhCN as S, zhTW as re } from "../../node_modules/.pnpm/@muyajs_core@file_vendor_muyajs-core/node_modules/@muyajs/core/lib/es/index.es.js";
3
+ import { applyInlineFormat as C, applyTextColor as ie, getActiveState as ae, insertTable as oe, turnIntoBlock as w } from "./muyaCommands.es.js";
4
+ import { openMarkdownFile as se, saveMarkdownFile as ce } from "./fileIO.es.js";
5
+ import { DEFAULT_TOOLBAR as le, HEADING_MENU as ue, TEXT_COLORS as de, TOOLBAR_ICONS as T, TOOLBAR_LABELS as E } from "./toolbar-config.es.js";
6
+ import { injectMdEditorStyles as D } from "./injectStyles.es.js";
7
+ import { forwardRef as O, useCallback as k, useEffect as A, useImperativeHandle as fe, useRef as j, useState as M } from "react";
8
+ import { Fragment as pe, jsx as N, jsxs as P } from "react/jsx-runtime";
9
9
  //#region src/blocks/md-editor/WakaMdEditor.tsx
10
- k();
11
- var fe = {
12
- fr: b,
13
- en: v,
14
- de: _,
15
- es: y,
16
- ja: x,
17
- ko: S,
18
- pt: C,
19
- zhCN: te,
20
- zhTW: w
21
- }, pe = {
10
+ D();
11
+ var me = {
12
+ fr: v,
13
+ en: g,
14
+ de: ne,
15
+ es: _,
16
+ ja: y,
17
+ ko: b,
18
+ pt: x,
19
+ zhCN: S,
20
+ zhTW: re
21
+ }, he = {
22
22
  frontMatter: !0,
23
23
  footnote: !0,
24
24
  superSubScript: !0,
@@ -26,17 +26,21 @@ var fe = {
26
26
  spellcheckEnabled: !1,
27
27
  fontSize: 16,
28
28
  lineHeight: 1.6
29
- }, L = {}, R = !1;
30
- function me() {
29
+ }, F = {}, I = {};
30
+ function L(e) {
31
+ /^https?:\/\//.test(e) && window.open(e, "_blank", "noopener,noreferrer");
32
+ }
33
+ var R = !1;
34
+ function ge() {
31
35
  R || (R = !0, l.use(t), l.use(n), l.use(s), l.use(r, {
32
- imagePathPicker: async () => await L.picker?.() ?? "",
33
- imageAction: async (e) => await L.action?.(e) ?? e
36
+ imagePathPicker: async () => await F.picker?.() ?? "",
37
+ imageAction: async (e) => await F.action?.(e) ?? e
34
38
  }), l.use(i), l.use(o), l.use(a), l.use(e), l.use(c, { jumpClick: (e) => {
35
39
  let t = e?.href;
36
- t && /^https?:\/\//.test(t) && window.open(t, "_blank", "noopener,noreferrer");
37
- } }), l.use(u), l.use(d), l.use(m), l.use(ee), l.use(f), l.use(h), l.use(g), l.use(p));
40
+ t && (I.onLinkClick ? I.onLinkClick(t, () => L(t)) : L(t));
41
+ } }), l.use(u), l.use(d), l.use(m), l.use(ee), l.use(f), l.use(te), l.use(h), l.use(p));
38
42
  }
39
- async function he() {
43
+ async function _e() {
40
44
  return new Promise((e, t) => {
41
45
  let n = document.createElement("input");
42
46
  n.type = "file", n.accept = "image/*", n.onchange = () => {
@@ -50,85 +54,91 @@ async function he() {
50
54
  }, n.click();
51
55
  });
52
56
  }
53
- var z = A(function(e, t) {
54
- let { defaultValue: n = "", value: r, options: i, locale: a = "fr", theme: o = "light", toolbar: s = !0, onChange: c, onOpen: u, onSave: d, onDirtyChange: f, onLoadingChange: p, onSavingChange: m, getMuya: ee, className: h, style: g } = e;
55
- me(), L = {
56
- picker: e.imagePathPicker ?? he,
57
+ var z = O(function(e, t) {
58
+ let { defaultValue: n = "", value: r, options: i, locale: a = "fr", theme: o = "light", toolbar: s = !0, onChange: c, onOpen: u, onSave: d, onDirtyChange: f, onLoadingChange: p, onSavingChange: m, onLinkClick: ee, getMuya: te, className: h, style: ne } = e;
59
+ ge(), F = {
60
+ picker: e.imagePathPicker ?? _e,
57
61
  action: e.imageAction ?? (async (e) => e)
58
- };
59
- let _ = N(null), v = N(null), y = N(r ?? n), x = N(!1), S = N({
62
+ }, I = { onLinkClick: ee };
63
+ let g = j(null), _ = j(null), y = j(r ?? n), b = j(!1), x = j({
60
64
  handle: null,
61
65
  name: null
62
- }), [C, te] = P(!1), w = N(!1), k = N(c);
63
- k.current = c;
64
- let A = N(f);
65
- A.current = f;
66
- let [R, z] = P({
66
+ }), [S, re] = M(!1), D = j(!1), O = j(c);
67
+ O.current = c;
68
+ let L = j(f);
69
+ L.current = f;
70
+ let [R, z] = M({
67
71
  formats: /* @__PURE__ */ new Set(),
68
72
  blockName: null,
69
73
  headingLevel: null,
70
74
  inColorSpan: !1
71
- }), [B, V] = P(null), [ge, _e] = P(!1), [H, U] = P("idle"), W = N(null), G = j(() => {
75
+ }), [B, V] = M(null), [ve, ye] = M(!1), [H, U] = M("idle"), W = j(null), G = k(() => {
72
76
  W.current &&= (clearTimeout(W.current), null), U("saving"), m?.(!0);
73
- }, [m]), K = j((e) => {
77
+ }, [m]), K = k((e) => {
74
78
  m?.(!1), U(e), e === "saved" && (W.current && clearTimeout(W.current), W.current = setTimeout(() => U("idle"), 1200));
75
79
  }, [m]);
76
- M(() => () => {
80
+ A(() => () => {
77
81
  W.current && clearTimeout(W.current);
78
82
  }, []);
79
- let q = j((e) => {
80
- w.current !== e && (w.current = e, te(e), A.current?.(e));
81
- }, []), J = j(() => {
82
- let e = v.current;
83
- e && z(re(e));
84
- }, []);
85
- M(() => {
83
+ let q = k((e) => {
84
+ D.current !== e && (D.current = e, re(e), L.current?.(e));
85
+ }, []), J = k(() => {
86
86
  let e = _.current;
87
+ e && z(ae(e));
88
+ }, []);
89
+ A(() => {
90
+ let e = g.current;
87
91
  if (!e) return;
88
92
  let t = new l(e, {
89
- ...pe,
93
+ ...he,
90
94
  ...i,
91
95
  markdown: r ?? n
92
96
  });
93
- return t.locale(fe[a] ?? b), t.init(), v.current = t, ee?.(t), t.on("json-change", () => {
97
+ t.locale(me[a] ?? v);
98
+ try {
99
+ t.init();
100
+ } catch (e) {
101
+ if (!(e instanceof Error) || !/Range to be added to the Selection/.test(e.message)) throw e;
102
+ }
103
+ return _.current = t, te?.(t), t.on("json-change", () => {
94
104
  let e = t.getMarkdown();
95
- y.current = e, x.current || k.current?.(e), q(!0), J();
105
+ y.current = e, b.current || O.current?.(e), q(!0), J();
96
106
  }), t.on("selection-change", () => J()), J(), () => {
97
- t.destroy(), v.current = null;
107
+ t.destroy(), _.current = null;
98
108
  };
99
- }, []), M(() => {
100
- let e = v.current;
109
+ }, []), A(() => {
110
+ let e = _.current;
101
111
  if (!(!e || r === void 0 || r === y.current)) {
102
- x.current = !0;
112
+ b.current = !0;
103
113
  try {
104
114
  e.setContent(r, !1), y.current = r;
105
115
  } finally {
106
- x.current = !1;
116
+ b.current = !1;
107
117
  }
108
118
  }
109
- }, [r]), M(() => {
110
- v.current?.locale(fe[a] ?? b);
111
- }, [a]), M(() => (document.body.classList.toggle("wmd-theme-dark", o === "dark"), () => document.body.classList.remove("wmd-theme-dark")), [o]);
112
- let Y = j(async () => {
113
- let e = await ae(), t = v.current;
119
+ }, [r]), A(() => {
120
+ _.current?.locale(me[a] ?? v);
121
+ }, [a]), A(() => (document.body.classList.toggle("wmd-theme-dark", o === "dark"), () => document.body.classList.remove("wmd-theme-dark")), [o]);
122
+ let Y = k(async () => {
123
+ let e = await se(), t = _.current;
114
124
  if (!(!e || !t)) {
115
- _e(!0), p?.(!0), await new Promise((e) => requestAnimationFrame(() => requestAnimationFrame(() => e())));
125
+ ye(!0), p?.(!0), await new Promise((e) => requestAnimationFrame(() => requestAnimationFrame(() => e())));
116
126
  try {
117
- S.current = {
127
+ x.current = {
118
128
  handle: e.handle,
119
129
  name: e.name
120
- }, x.current = !0;
130
+ }, b.current = !0;
121
131
  try {
122
132
  t.setContent(e.markdown, !1), y.current = e.markdown;
123
133
  } finally {
124
- x.current = !1;
134
+ b.current = !1;
125
135
  }
126
136
  q(!1), J(), u?.(e.markdown, {
127
137
  name: e.name,
128
138
  handle: e.handle
129
139
  });
130
140
  } finally {
131
- _e(!1), p?.(!1);
141
+ ye(!1), p?.(!1);
132
142
  }
133
143
  }
134
144
  }, [
@@ -136,17 +146,17 @@ var z = A(function(e, t) {
136
146
  J,
137
147
  q,
138
148
  p
139
- ]), X = N(!1), Z = j(async () => {
140
- let e = v.current;
149
+ ]), X = j(!1), Z = k(async () => {
150
+ let e = _.current;
141
151
  if (!(!e || X.current)) {
142
152
  X.current = !0, G();
143
153
  try {
144
- let t = await oe(e.getMarkdown(), S.current, !0);
154
+ let t = await ce(e.getMarkdown(), x.current, !0);
145
155
  if (!t) {
146
156
  K("idle");
147
157
  return;
148
158
  }
149
- S.current = {
159
+ x.current = {
150
160
  handle: t.handle,
151
161
  name: t.name
152
162
  }, q(!1), d?.(e.getMarkdown(), {
@@ -164,16 +174,16 @@ var z = A(function(e, t) {
164
174
  q,
165
175
  K,
166
176
  G
167
- ]), Q = j(async () => {
168
- let e = v.current;
177
+ ]), Q = k(async () => {
178
+ let e = _.current;
169
179
  if (!(!e || X.current)) {
170
- if (!S.current.handle) {
180
+ if (!x.current.handle) {
171
181
  await Z();
172
182
  return;
173
183
  }
174
184
  X.current = !0, G();
175
185
  try {
176
- let t = e.getMarkdown(), n = await oe(t, S.current, !1);
186
+ let t = e.getMarkdown(), n = await ce(t, x.current, !1);
177
187
  if (!n) {
178
188
  K("idle");
179
189
  return;
@@ -195,7 +205,7 @@ var z = A(function(e, t) {
195
205
  K,
196
206
  G
197
207
  ]);
198
- M(() => {
208
+ A(() => {
199
209
  let e = (e) => {
200
210
  if (!(e.metaKey || e.ctrlKey)) return;
201
211
  let t = e.key.toLowerCase();
@@ -207,8 +217,8 @@ var z = A(function(e, t) {
207
217
  Q,
208
218
  Z
209
219
  ]);
210
- let ve = j((e) => {
211
- let t = v.current;
220
+ let be = k((e) => {
221
+ let t = _.current;
212
222
  if (t) {
213
223
  switch (e) {
214
224
  case "open":
@@ -227,7 +237,7 @@ var z = A(function(e, t) {
227
237
  t.redo();
228
238
  break;
229
239
  case "paragraph":
230
- E(t, "paragraph");
240
+ w(t, "paragraph");
231
241
  break;
232
242
  case "heading1":
233
243
  case "heading2":
@@ -235,55 +245,55 @@ var z = A(function(e, t) {
235
245
  case "heading4":
236
246
  case "heading5":
237
247
  case "heading6":
238
- E(t, `heading ${Number(e.slice(-1))}`);
248
+ w(t, `heading ${Number(e.slice(-1))}`);
239
249
  break;
240
250
  case "bold":
241
- T(t, "strong");
251
+ C(t, "strong");
242
252
  break;
243
253
  case "italic":
244
- T(t, "em");
254
+ C(t, "em");
245
255
  break;
246
256
  case "underline":
247
- T(t, "u");
257
+ C(t, "u");
248
258
  break;
249
259
  case "strikethrough":
250
- T(t, "del");
260
+ C(t, "del");
251
261
  break;
252
262
  case "highlight":
253
- T(t, "mark");
263
+ C(t, "mark");
254
264
  break;
255
265
  case "inlineCode":
256
- T(t, "inline_code");
266
+ C(t, "inline_code");
257
267
  break;
258
268
  case "clearFormat":
259
- T(t, "clear");
269
+ C(t, "clear");
260
270
  break;
261
271
  case "bulletList":
262
- E(t, "ul-bullet");
272
+ w(t, "ul-bullet");
263
273
  break;
264
274
  case "orderedList":
265
- E(t, "ol-order");
275
+ w(t, "ol-order");
266
276
  break;
267
277
  case "taskList":
268
- E(t, "ul-task");
278
+ w(t, "ul-task");
269
279
  break;
270
280
  case "blockquote":
271
- E(t, "blockquote");
281
+ w(t, "blockquote");
272
282
  break;
273
283
  case "codeBlock":
274
- E(t, "pre");
284
+ w(t, "pre");
275
285
  break;
276
286
  case "horizontalRule":
277
- E(t, "hr");
287
+ w(t, "hr");
278
288
  break;
279
289
  case "link":
280
- T(t, "link");
290
+ C(t, "link");
281
291
  break;
282
292
  case "image":
283
- T(t, "image");
293
+ C(t, "image");
284
294
  break;
285
295
  case "table":
286
- ie(t);
296
+ oe(t);
287
297
  break;
288
298
  default: break;
289
299
  }
@@ -294,40 +304,40 @@ var z = A(function(e, t) {
294
304
  Q,
295
305
  Z,
296
306
  J
297
- ]), $ = j((e) => {
298
- let t = v.current;
299
- t && (ne(t, e), V(null), J());
307
+ ]), $ = k((e) => {
308
+ let t = _.current;
309
+ t && (ie(t, e), V(null), J());
300
310
  }, [J]);
301
- ue(t, () => ({
302
- getMarkdown: () => v.current?.getMarkdown() ?? "",
311
+ fe(t, () => ({
312
+ getMarkdown: () => _.current?.getMarkdown() ?? "",
303
313
  setMarkdown: (e, t = !1) => {
304
- let n = v.current;
314
+ let n = _.current;
305
315
  if (n) {
306
- x.current = !0;
316
+ b.current = !0;
307
317
  try {
308
318
  n.setContent(e, t), y.current = e;
309
319
  } finally {
310
- x.current = !1;
320
+ b.current = !1;
311
321
  }
312
322
  }
313
323
  },
314
- focus: () => v.current?.focus(),
315
- toggleFormat: (e) => v.current && T(v.current, e),
316
- turnInto: (e) => v.current && E(v.current, e),
324
+ focus: () => _.current?.focus(),
325
+ toggleFormat: (e) => _.current && C(_.current, e),
326
+ turnInto: (e) => _.current && w(_.current, e),
317
327
  applyColor: (e) => $(e),
318
- undo: () => v.current?.undo(),
319
- redo: () => v.current?.redo(),
328
+ undo: () => _.current?.undo(),
329
+ redo: () => _.current?.redo(),
320
330
  openFile: () => Y(),
321
331
  saveFile: () => Q(),
322
332
  saveFileAs: () => Z(),
323
- isDirty: () => w.current
333
+ isDirty: () => D.current
324
334
  }), [
325
335
  Y,
326
336
  Q,
327
337
  Z,
328
338
  $
329
339
  ]);
330
- let ye = s === !1 ? !1 : Array.isArray(s) ? s : se, be = (e) => {
340
+ let xe = s === !1 ? !1 : Array.isArray(s) ? s : le, Se = (e) => {
331
341
  switch (e) {
332
342
  case "bold": return R.formats.has("strong");
333
343
  case "italic": return R.formats.has("em");
@@ -348,62 +358,62 @@ var z = A(function(e, t) {
348
358
  case "taskList": return R.blockName === "task-list";
349
359
  case "blockquote": return R.blockName === "block-quote";
350
360
  case "codeBlock": return R.blockName === "code-block";
351
- case "save": return C;
361
+ case "save": return S;
352
362
  default: return !1;
353
363
  }
354
364
  };
355
- M(() => {
365
+ A(() => {
356
366
  if (!B) return;
357
367
  let e = (e) => {
358
368
  e.target?.closest(".wmd-popup-anchor") || V(null);
359
369
  };
360
370
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
361
371
  }, [B]);
362
- let xe = R.blockName === "atx-heading" && R.headingLevel ? `T${R.headingLevel}` : R.blockName === "paragraph" ? "¶" : "T", Se = (e) => e === "heading" ? /* @__PURE__ */ I("div", {
372
+ let Ce = R.blockName === "atx-heading" && R.headingLevel ? `T${R.headingLevel}` : R.blockName === "paragraph" ? "¶" : "T", we = (e) => e === "heading" ? /* @__PURE__ */ P("div", {
363
373
  className: "wmd-popup-anchor",
364
- children: [/* @__PURE__ */ I("button", {
374
+ children: [/* @__PURE__ */ P("button", {
365
375
  type: "button",
366
376
  className: `wmd-btn${B === "heading" ? " wmd-btn--active" : ""}`,
367
- title: O.heading,
377
+ title: E.heading,
368
378
  onMouseDown: (e) => e.preventDefault(),
369
379
  onClick: () => V(B === "heading" ? null : "heading"),
370
380
  children: [
371
- D.heading,
372
- /* @__PURE__ */ F("span", {
381
+ T.heading,
382
+ /* @__PURE__ */ N("span", {
373
383
  className: "wmd-btn-label",
374
- children: xe
384
+ children: Ce
375
385
  }),
376
- D.chevronDown
386
+ T.chevronDown
377
387
  ]
378
- }), B === "heading" && /* @__PURE__ */ F("div", {
388
+ }), B === "heading" && /* @__PURE__ */ N("div", {
379
389
  className: "wmd-popup",
380
390
  role: "menu",
381
- children: ce.map((e) => /* @__PURE__ */ F("button", {
391
+ children: ue.map((e) => /* @__PURE__ */ N("button", {
382
392
  type: "button",
383
393
  role: "menuitem",
384
- className: `wmd-popup-item${be(e.id) ? " wmd-popup-item--active" : ""}`,
394
+ className: `wmd-popup-item${Se(e.id) ? " wmd-popup-item--active" : ""}`,
385
395
  onMouseDown: (e) => e.preventDefault(),
386
396
  onClick: () => {
387
- ve(e.id), V(null);
397
+ be(e.id), V(null);
388
398
  },
389
- children: /* @__PURE__ */ F("span", {
399
+ children: /* @__PURE__ */ N("span", {
390
400
  className: "wmd-heading-item",
391
401
  "data-level": e.id === "paragraph" ? 0 : e.id.slice(-1),
392
402
  children: e.label
393
403
  })
394
404
  }, e.id))
395
405
  })]
396
- }, e) : e === "textColor" ? /* @__PURE__ */ I("div", {
406
+ }, e) : e === "textColor" ? /* @__PURE__ */ P("div", {
397
407
  className: "wmd-popup-anchor",
398
- children: [/* @__PURE__ */ I("button", {
408
+ children: [/* @__PURE__ */ P("button", {
399
409
  type: "button",
400
410
  className: `wmd-btn${R.formats.has("color") || B === "textColor" ? " wmd-btn--active" : ""}`,
401
- title: O.textColor,
411
+ title: E.textColor,
402
412
  onMouseDown: (e) => e.preventDefault(),
403
413
  onClick: () => V(B === "textColor" ? null : "textColor"),
404
414
  children: [
405
- D.textColor,
406
- /* @__PURE__ */ F("span", {
415
+ T.textColor,
416
+ /* @__PURE__ */ N("span", {
407
417
  className: "wmd-btn-label",
408
418
  style: {
409
419
  borderBottom: "2px solid currentColor",
@@ -411,14 +421,14 @@ var z = A(function(e, t) {
411
421
  },
412
422
  children: "A"
413
423
  }),
414
- D.chevronDown
424
+ T.chevronDown
415
425
  ]
416
- }), B === "textColor" && /* @__PURE__ */ I("div", {
426
+ }), B === "textColor" && /* @__PURE__ */ P("div", {
417
427
  className: "wmd-popup",
418
428
  role: "menu",
419
- children: [/* @__PURE__ */ F("div", {
429
+ children: [/* @__PURE__ */ N("div", {
420
430
  className: "wmd-color-grid",
421
- children: le.map((e) => /* @__PURE__ */ F("button", {
431
+ children: de.map((e) => /* @__PURE__ */ N("button", {
422
432
  type: "button",
423
433
  className: "wmd-color-swatch",
424
434
  title: e.name,
@@ -426,9 +436,9 @@ var z = A(function(e, t) {
426
436
  onMouseDown: (e) => e.preventDefault(),
427
437
  onClick: () => $(e.value)
428
438
  }, e.value))
429
- }), /* @__PURE__ */ I("label", {
439
+ }), /* @__PURE__ */ P("label", {
430
440
  className: "wmd-color-custom",
431
- children: [/* @__PURE__ */ F("input", {
441
+ children: [/* @__PURE__ */ N("input", {
432
442
  type: "color",
433
443
  defaultValue: "#2563eb",
434
444
  onMouseDown: (e) => e.stopPropagation(),
@@ -436,71 +446,71 @@ var z = A(function(e, t) {
436
446
  }), "Couleur personnalisée…"]
437
447
  })]
438
448
  })]
439
- }, e) : /* @__PURE__ */ F("button", {
449
+ }, e) : /* @__PURE__ */ N("button", {
440
450
  type: "button",
441
451
  className: [
442
452
  "wmd-btn",
443
- be(e) ? "wmd-btn--active" : "",
444
- e === "save" && C ? "wmd-btn--dirty" : ""
453
+ Se(e) ? "wmd-btn--active" : "",
454
+ e === "save" && S ? "wmd-btn--dirty" : ""
445
455
  ].filter(Boolean).join(" "),
446
- title: O[e],
447
- disabled: e === "open" && ge || (e === "save" || e === "saveAs") && H === "saving",
456
+ title: E[e],
457
+ disabled: e === "open" && ve || (e === "save" || e === "saveAs") && H === "saving",
448
458
  onMouseDown: (e) => e.preventDefault(),
449
- onClick: () => ve(e),
450
- children: D[e] ?? e
459
+ onClick: () => be(e),
460
+ children: T[e] ?? e
451
461
  }, e);
452
- return /* @__PURE__ */ I("div", {
462
+ return /* @__PURE__ */ P("div", {
453
463
  className: `wmd-editor${h ? ` ${h}` : ""}`,
454
464
  "data-theme": o,
455
- style: g,
465
+ style: ne,
456
466
  children: [
457
- ye !== !1 && /* @__PURE__ */ F("div", {
467
+ xe !== !1 && /* @__PURE__ */ N("div", {
458
468
  className: "wmd-toolbar",
459
469
  role: "toolbar",
460
470
  "aria-label": "Barre d'outils Markdown",
461
- children: ye.map((e, t) => e === "|" ? /* @__PURE__ */ F("span", { className: "wmd-separator" }, `sep-${t}`) : /* @__PURE__ */ F("div", {
471
+ children: xe.map((e, t) => e === "|" ? /* @__PURE__ */ N("span", { className: "wmd-separator" }, `sep-${t}`) : /* @__PURE__ */ N("div", {
462
472
  className: "wmd-toolbar-group",
463
- children: Se(e)
473
+ children: we(e)
464
474
  }, e))
465
475
  }),
466
- /* @__PURE__ */ I("div", {
476
+ /* @__PURE__ */ P("div", {
467
477
  className: "wmd-editor-surface",
468
- children: [/* @__PURE__ */ F("div", { ref: _ }), ge && /* @__PURE__ */ I("div", {
478
+ children: [/* @__PURE__ */ N("div", { ref: g }), ve && /* @__PURE__ */ P("div", {
469
479
  className: "wmd-loading-overlay",
470
480
  role: "status",
471
481
  "aria-live": "polite",
472
- children: [/* @__PURE__ */ F("span", {
482
+ children: [/* @__PURE__ */ N("span", {
473
483
  className: "wmd-spinner",
474
484
  "aria-hidden": "true"
475
- }), /* @__PURE__ */ F("span", { children: "Chargement du fichier…" })]
485
+ }), /* @__PURE__ */ N("span", { children: "Chargement du fichier…" })]
476
486
  })]
477
487
  }),
478
- H !== "idle" && /* @__PURE__ */ F("div", {
488
+ H !== "idle" && /* @__PURE__ */ N("div", {
479
489
  className: "wmd-modal-backdrop",
480
490
  role: "status",
481
491
  "aria-live": "polite",
482
- children: /* @__PURE__ */ F("div", {
492
+ children: /* @__PURE__ */ N("div", {
483
493
  className: "wmd-modal",
484
- children: H === "saving" ? /* @__PURE__ */ I(de, { children: [/* @__PURE__ */ F("span", {
494
+ children: H === "saving" ? /* @__PURE__ */ P(pe, { children: [/* @__PURE__ */ N("span", {
485
495
  className: "wmd-spinner",
486
496
  "aria-hidden": "true"
487
- }), /* @__PURE__ */ F("span", {
497
+ }), /* @__PURE__ */ N("span", {
488
498
  className: "wmd-modal-text",
489
499
  children: "Enregistrement…"
490
- })] }) : /* @__PURE__ */ I(de, { children: [/* @__PURE__ */ I("svg", {
500
+ })] }) : /* @__PURE__ */ P(pe, { children: [/* @__PURE__ */ P("svg", {
491
501
  className: "wmd-modal-check",
492
502
  viewBox: "0 0 24 24",
493
503
  width: "28",
494
504
  height: "28",
495
505
  "aria-hidden": "true",
496
- children: [/* @__PURE__ */ F("circle", {
506
+ children: [/* @__PURE__ */ N("circle", {
497
507
  cx: "12",
498
508
  cy: "12",
499
509
  r: "11",
500
510
  fill: "none",
501
511
  stroke: "currentColor",
502
512
  strokeWidth: "2"
503
- }), /* @__PURE__ */ F("path", {
513
+ }), /* @__PURE__ */ N("path", {
504
514
  d: "M7 12.5l3 3 7-7",
505
515
  fill: "none",
506
516
  stroke: "currentColor",
@@ -508,9 +518,9 @@ var z = A(function(e, t) {
508
518
  strokeLinecap: "round",
509
519
  strokeLinejoin: "round"
510
520
  })]
511
- }), /* @__PURE__ */ I("span", {
521
+ }), /* @__PURE__ */ P("span", {
512
522
  className: "wmd-modal-text",
513
- children: ["Enregistré", S.current.name ? ` — ${S.current.name}` : ""]
523
+ children: ["Enregistré", x.current.name ? ` — ${x.current.name}` : ""]
514
524
  })] })
515
525
  })
516
526
  })
@@ -45,6 +45,16 @@ export interface WakaMdEditorProps {
45
45
  onLoadingChange?: (loading: boolean) => void;
46
46
  /** Un enregistrement est en cours (entre le déclenchement et la confirmation). */
47
47
  onSavingChange?: (saving: boolean) => void;
48
+ /**
49
+ * Clic sur un lien du document. Sans ce callback, seuls les liens
50
+ * http(s) s'ouvrent (nouvel onglet) ; tout le reste (chemins relatifs,
51
+ * schémas applicatifs type `doc://…`) est silencieusement ignoré.
52
+ * Fourni, ce callback reçoit *tous* les clics — y compris http(s) — et
53
+ * décide : router en interne (ex. ouvrir un document applicatif dans
54
+ * votre propre visualiseur), ou appeler `openDefault()` pour retrouver
55
+ * le comportement d'origine sur ce lien précis.
56
+ */
57
+ onLinkClick?: (href: string, openDefault: () => void) => void;
48
58
  className?: string;
49
59
  style?: React.CSSProperties;
50
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wakastellar/ui",
3
- "version": "6.0.2",
3
+ "version": "6.0.3",
4
4
  "description": "Zero-config UI Library for Next.js with TweakCN theming and i18n support",
5
5
  "keywords": [
6
6
  "ui",
@@ -98,6 +98,22 @@ const EDITOR_DEFAULTS: Partial<IMuyaOptions> = {
98
98
  */
99
99
  let imageCallbacks: { picker?: () => Promise<string>; action?: (src: string) => Promise<string> } = {};
100
100
 
101
+ /**
102
+ * Clic sur un lien : même mécanisme délégué que les callbacks d'images.
103
+ * Sans `onLinkClick` fourni par l'hôte, le comportement par défaut (ouvrir
104
+ * les liens http(s) dans un nouvel onglet, ignorer le reste) est conservé.
105
+ * Avec `onLinkClick`, l'hôte reçoit *tous* les clics — y compris http(s) —
106
+ * et décide : router en interne (documents applicatifs, `doc://…`, chemins
107
+ * relatifs…), ou appeler `openDefault()` pour retrouver le comportement
108
+ * d'origine sur ce lien précis.
109
+ */
110
+ let linkCallbacks: { onLinkClick?: (href: string, openDefault: () => void) => void } = {};
111
+
112
+ function openLinkDefault(href: string): void {
113
+ if (/^https?:\/\//.test(href))
114
+ window.open(href, '_blank', 'noopener,noreferrer');
115
+ }
116
+
101
117
  let pluginsRegistered = false;
102
118
  function registerPluginsOnce(): void {
103
119
  if (pluginsRegistered)
@@ -118,8 +134,12 @@ function registerPluginsOnce(): void {
118
134
  Muya.use(LinkTools, {
119
135
  jumpClick: (linkInfo: { href?: string } | null) => {
120
136
  const href = linkInfo?.href;
121
- if (href && /^https?:\/\//.test(href))
122
- window.open(href, '_blank', 'noopener,noreferrer');
137
+ if (!href)
138
+ return;
139
+ if (linkCallbacks.onLinkClick)
140
+ linkCallbacks.onLinkClick(href, () => openLinkDefault(href));
141
+ else
142
+ openLinkDefault(href);
123
143
  },
124
144
  });
125
145
  Muya.use(ParagraphFrontButton);
@@ -166,6 +186,7 @@ export const WakaMdEditor = forwardRef<WakaMdEditorRef, WakaMdEditorProps>(funct
166
186
  onDirtyChange,
167
187
  onLoadingChange,
168
188
  onSavingChange,
189
+ onLinkClick,
169
190
  getMuya,
170
191
  className,
171
192
  style,
@@ -176,6 +197,7 @@ export const WakaMdEditor = forwardRef<WakaMdEditorRef, WakaMdEditorProps>(funct
176
197
  picker: props.imagePathPicker ?? pickImageAsDataUrl,
177
198
  action: props.imageAction ?? (async src => src),
178
199
  };
200
+ linkCallbacks = { onLinkClick };
179
201
 
180
202
  const containerRef = useRef<HTMLDivElement | null>(null);
181
203
  const muyaRef = useRef<Muya | null>(null);
@@ -258,7 +280,23 @@ export const WakaMdEditor = forwardRef<WakaMdEditorRef, WakaMdEditorProps>(funct
258
280
  markdown: value ?? defaultValue,
259
281
  } as Partial<IMuyaOptions>);
260
282
  muya.locale(LOCALES[locale] ?? fr);
261
- muya.init();
283
+ try {
284
+ muya.init();
285
+ }
286
+ catch (error) {
287
+ // Le moteur appelle focus()/setCursor() en interne à la fin de
288
+ // init(), qui échoue sur l'API Selection native du navigateur
289
+ // ("extend() requires a Range to be added to the Selection")
290
+ // quand cet effet est réinvoqué en double par React 19 en
291
+ // StrictMode (dev uniquement) : le Selection du document garde
292
+ // une référence périmée après le unmount/remount immédiat.
293
+ // Montage et contenu restent fonctionnels — seul le focus
294
+ // automatique initial échoue — donc on avale uniquement cette
295
+ // erreur précise plutôt que de casser tout l'effet de montage ;
296
+ // toute autre erreur d'init() reste une vraie régression à voir.
297
+ if (!(error instanceof Error) || !/Range to be added to the Selection/.test(error.message))
298
+ throw error;
299
+ }
262
300
  muyaRef.current = muya;
263
301
  getMuya?.(muya);
264
302
 
@@ -81,6 +81,16 @@ export interface WakaMdEditorProps {
81
81
  onLoadingChange?: (loading: boolean) => void;
82
82
  /** Un enregistrement est en cours (entre le déclenchement et la confirmation). */
83
83
  onSavingChange?: (saving: boolean) => void;
84
+ /**
85
+ * Clic sur un lien du document. Sans ce callback, seuls les liens
86
+ * http(s) s'ouvrent (nouvel onglet) ; tout le reste (chemins relatifs,
87
+ * schémas applicatifs type `doc://…`) est silencieusement ignoré.
88
+ * Fourni, ce callback reçoit *tous* les clics — y compris http(s) — et
89
+ * décide : router en interne (ex. ouvrir un document applicatif dans
90
+ * votre propre visualiseur), ou appeler `openDefault()` pour retrouver
91
+ * le comportement d'origine sur ce lien précis.
92
+ */
93
+ onLinkClick?: (href: string, openDefault: () => void) => void;
84
94
  className?: string;
85
95
  style?: React.CSSProperties;
86
96
  }