@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
|
|
3
|
-
import { applyInlineFormat as
|
|
4
|
-
import { openMarkdownFile as
|
|
5
|
-
import { DEFAULT_TOOLBAR as
|
|
6
|
-
import { injectMdEditorStyles as
|
|
7
|
-
import { forwardRef as
|
|
8
|
-
import { Fragment as
|
|
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
|
-
|
|
11
|
-
var
|
|
12
|
-
fr:
|
|
13
|
-
en:
|
|
14
|
-
de:
|
|
15
|
-
es:
|
|
16
|
-
ja:
|
|
17
|
-
ko:
|
|
18
|
-
pt:
|
|
19
|
-
zhCN:
|
|
20
|
-
zhTW:
|
|
21
|
-
},
|
|
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
|
-
},
|
|
30
|
-
function
|
|
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
|
|
33
|
-
imageAction: async (e) => await
|
|
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 &&
|
|
37
|
-
} }), l.use(u), l.use(d), l.use(m), l.use(ee), l.use(f), l.use(
|
|
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
|
|
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 =
|
|
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,
|
|
55
|
-
|
|
56
|
-
picker: e.imagePathPicker ??
|
|
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
|
|
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
|
-
}), [
|
|
63
|
-
|
|
64
|
-
let
|
|
65
|
-
|
|
66
|
-
let [R, z] =
|
|
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] =
|
|
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 =
|
|
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
|
-
|
|
80
|
+
A(() => () => {
|
|
77
81
|
W.current && clearTimeout(W.current);
|
|
78
82
|
}, []);
|
|
79
|
-
let q =
|
|
80
|
-
|
|
81
|
-
}, []), 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
|
-
...
|
|
93
|
+
...he,
|
|
90
94
|
...i,
|
|
91
95
|
markdown: r ?? n
|
|
92
96
|
});
|
|
93
|
-
|
|
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,
|
|
105
|
+
y.current = e, b.current || O.current?.(e), q(!0), J();
|
|
96
106
|
}), t.on("selection-change", () => J()), J(), () => {
|
|
97
|
-
t.destroy(),
|
|
107
|
+
t.destroy(), _.current = null;
|
|
98
108
|
};
|
|
99
|
-
}, []),
|
|
100
|
-
let e =
|
|
109
|
+
}, []), A(() => {
|
|
110
|
+
let e = _.current;
|
|
101
111
|
if (!(!e || r === void 0 || r === y.current)) {
|
|
102
|
-
|
|
112
|
+
b.current = !0;
|
|
103
113
|
try {
|
|
104
114
|
e.setContent(r, !1), y.current = r;
|
|
105
115
|
} finally {
|
|
106
|
-
|
|
116
|
+
b.current = !1;
|
|
107
117
|
}
|
|
108
118
|
}
|
|
109
|
-
}, [r]),
|
|
110
|
-
|
|
111
|
-
}, [a]),
|
|
112
|
-
let Y =
|
|
113
|
-
let e = await
|
|
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
|
-
|
|
125
|
+
ye(!0), p?.(!0), await new Promise((e) => requestAnimationFrame(() => requestAnimationFrame(() => e())));
|
|
116
126
|
try {
|
|
117
|
-
|
|
127
|
+
x.current = {
|
|
118
128
|
handle: e.handle,
|
|
119
129
|
name: e.name
|
|
120
|
-
},
|
|
130
|
+
}, b.current = !0;
|
|
121
131
|
try {
|
|
122
132
|
t.setContent(e.markdown, !1), y.current = e.markdown;
|
|
123
133
|
} finally {
|
|
124
|
-
|
|
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
|
-
|
|
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 =
|
|
140
|
-
let e =
|
|
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
|
|
154
|
+
let t = await ce(e.getMarkdown(), x.current, !0);
|
|
145
155
|
if (!t) {
|
|
146
156
|
K("idle");
|
|
147
157
|
return;
|
|
148
158
|
}
|
|
149
|
-
|
|
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 =
|
|
168
|
-
let e =
|
|
177
|
+
]), Q = k(async () => {
|
|
178
|
+
let e = _.current;
|
|
169
179
|
if (!(!e || X.current)) {
|
|
170
|
-
if (!
|
|
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
|
|
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
|
-
|
|
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
|
|
211
|
-
let t =
|
|
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
|
-
|
|
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
|
-
|
|
248
|
+
w(t, `heading ${Number(e.slice(-1))}`);
|
|
239
249
|
break;
|
|
240
250
|
case "bold":
|
|
241
|
-
|
|
251
|
+
C(t, "strong");
|
|
242
252
|
break;
|
|
243
253
|
case "italic":
|
|
244
|
-
|
|
254
|
+
C(t, "em");
|
|
245
255
|
break;
|
|
246
256
|
case "underline":
|
|
247
|
-
|
|
257
|
+
C(t, "u");
|
|
248
258
|
break;
|
|
249
259
|
case "strikethrough":
|
|
250
|
-
|
|
260
|
+
C(t, "del");
|
|
251
261
|
break;
|
|
252
262
|
case "highlight":
|
|
253
|
-
|
|
263
|
+
C(t, "mark");
|
|
254
264
|
break;
|
|
255
265
|
case "inlineCode":
|
|
256
|
-
|
|
266
|
+
C(t, "inline_code");
|
|
257
267
|
break;
|
|
258
268
|
case "clearFormat":
|
|
259
|
-
|
|
269
|
+
C(t, "clear");
|
|
260
270
|
break;
|
|
261
271
|
case "bulletList":
|
|
262
|
-
|
|
272
|
+
w(t, "ul-bullet");
|
|
263
273
|
break;
|
|
264
274
|
case "orderedList":
|
|
265
|
-
|
|
275
|
+
w(t, "ol-order");
|
|
266
276
|
break;
|
|
267
277
|
case "taskList":
|
|
268
|
-
|
|
278
|
+
w(t, "ul-task");
|
|
269
279
|
break;
|
|
270
280
|
case "blockquote":
|
|
271
|
-
|
|
281
|
+
w(t, "blockquote");
|
|
272
282
|
break;
|
|
273
283
|
case "codeBlock":
|
|
274
|
-
|
|
284
|
+
w(t, "pre");
|
|
275
285
|
break;
|
|
276
286
|
case "horizontalRule":
|
|
277
|
-
|
|
287
|
+
w(t, "hr");
|
|
278
288
|
break;
|
|
279
289
|
case "link":
|
|
280
|
-
|
|
290
|
+
C(t, "link");
|
|
281
291
|
break;
|
|
282
292
|
case "image":
|
|
283
|
-
|
|
293
|
+
C(t, "image");
|
|
284
294
|
break;
|
|
285
295
|
case "table":
|
|
286
|
-
|
|
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
|
-
]), $ =
|
|
298
|
-
let t =
|
|
299
|
-
t && (
|
|
307
|
+
]), $ = k((e) => {
|
|
308
|
+
let t = _.current;
|
|
309
|
+
t && (ie(t, e), V(null), J());
|
|
300
310
|
}, [J]);
|
|
301
|
-
|
|
302
|
-
getMarkdown: () =>
|
|
311
|
+
fe(t, () => ({
|
|
312
|
+
getMarkdown: () => _.current?.getMarkdown() ?? "",
|
|
303
313
|
setMarkdown: (e, t = !1) => {
|
|
304
|
-
let n =
|
|
314
|
+
let n = _.current;
|
|
305
315
|
if (n) {
|
|
306
|
-
|
|
316
|
+
b.current = !0;
|
|
307
317
|
try {
|
|
308
318
|
n.setContent(e, t), y.current = e;
|
|
309
319
|
} finally {
|
|
310
|
-
|
|
320
|
+
b.current = !1;
|
|
311
321
|
}
|
|
312
322
|
}
|
|
313
323
|
},
|
|
314
|
-
focus: () =>
|
|
315
|
-
toggleFormat: (e) =>
|
|
316
|
-
turnInto: (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: () =>
|
|
319
|
-
redo: () =>
|
|
328
|
+
undo: () => _.current?.undo(),
|
|
329
|
+
redo: () => _.current?.redo(),
|
|
320
330
|
openFile: () => Y(),
|
|
321
331
|
saveFile: () => Q(),
|
|
322
332
|
saveFileAs: () => Z(),
|
|
323
|
-
isDirty: () =>
|
|
333
|
+
isDirty: () => D.current
|
|
324
334
|
}), [
|
|
325
335
|
Y,
|
|
326
336
|
Q,
|
|
327
337
|
Z,
|
|
328
338
|
$
|
|
329
339
|
]);
|
|
330
|
-
let
|
|
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
|
|
361
|
+
case "save": return S;
|
|
352
362
|
default: return !1;
|
|
353
363
|
}
|
|
354
364
|
};
|
|
355
|
-
|
|
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
|
|
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__ */
|
|
374
|
+
children: [/* @__PURE__ */ P("button", {
|
|
365
375
|
type: "button",
|
|
366
376
|
className: `wmd-btn${B === "heading" ? " wmd-btn--active" : ""}`,
|
|
367
|
-
title:
|
|
377
|
+
title: E.heading,
|
|
368
378
|
onMouseDown: (e) => e.preventDefault(),
|
|
369
379
|
onClick: () => V(B === "heading" ? null : "heading"),
|
|
370
380
|
children: [
|
|
371
|
-
|
|
372
|
-
/* @__PURE__ */
|
|
381
|
+
T.heading,
|
|
382
|
+
/* @__PURE__ */ N("span", {
|
|
373
383
|
className: "wmd-btn-label",
|
|
374
|
-
children:
|
|
384
|
+
children: Ce
|
|
375
385
|
}),
|
|
376
|
-
|
|
386
|
+
T.chevronDown
|
|
377
387
|
]
|
|
378
|
-
}), B === "heading" && /* @__PURE__ */
|
|
388
|
+
}), B === "heading" && /* @__PURE__ */ N("div", {
|
|
379
389
|
className: "wmd-popup",
|
|
380
390
|
role: "menu",
|
|
381
|
-
children:
|
|
391
|
+
children: ue.map((e) => /* @__PURE__ */ N("button", {
|
|
382
392
|
type: "button",
|
|
383
393
|
role: "menuitem",
|
|
384
|
-
className: `wmd-popup-item${
|
|
394
|
+
className: `wmd-popup-item${Se(e.id) ? " wmd-popup-item--active" : ""}`,
|
|
385
395
|
onMouseDown: (e) => e.preventDefault(),
|
|
386
396
|
onClick: () => {
|
|
387
|
-
|
|
397
|
+
be(e.id), V(null);
|
|
388
398
|
},
|
|
389
|
-
children: /* @__PURE__ */
|
|
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__ */
|
|
406
|
+
}, e) : e === "textColor" ? /* @__PURE__ */ P("div", {
|
|
397
407
|
className: "wmd-popup-anchor",
|
|
398
|
-
children: [/* @__PURE__ */
|
|
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:
|
|
411
|
+
title: E.textColor,
|
|
402
412
|
onMouseDown: (e) => e.preventDefault(),
|
|
403
413
|
onClick: () => V(B === "textColor" ? null : "textColor"),
|
|
404
414
|
children: [
|
|
405
|
-
|
|
406
|
-
/* @__PURE__ */
|
|
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
|
-
|
|
424
|
+
T.chevronDown
|
|
415
425
|
]
|
|
416
|
-
}), B === "textColor" && /* @__PURE__ */
|
|
426
|
+
}), B === "textColor" && /* @__PURE__ */ P("div", {
|
|
417
427
|
className: "wmd-popup",
|
|
418
428
|
role: "menu",
|
|
419
|
-
children: [/* @__PURE__ */
|
|
429
|
+
children: [/* @__PURE__ */ N("div", {
|
|
420
430
|
className: "wmd-color-grid",
|
|
421
|
-
children:
|
|
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__ */
|
|
439
|
+
}), /* @__PURE__ */ P("label", {
|
|
430
440
|
className: "wmd-color-custom",
|
|
431
|
-
children: [/* @__PURE__ */
|
|
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__ */
|
|
449
|
+
}, e) : /* @__PURE__ */ N("button", {
|
|
440
450
|
type: "button",
|
|
441
451
|
className: [
|
|
442
452
|
"wmd-btn",
|
|
443
|
-
|
|
444
|
-
e === "save" &&
|
|
453
|
+
Se(e) ? "wmd-btn--active" : "",
|
|
454
|
+
e === "save" && S ? "wmd-btn--dirty" : ""
|
|
445
455
|
].filter(Boolean).join(" "),
|
|
446
|
-
title:
|
|
447
|
-
disabled: e === "open" &&
|
|
456
|
+
title: E[e],
|
|
457
|
+
disabled: e === "open" && ve || (e === "save" || e === "saveAs") && H === "saving",
|
|
448
458
|
onMouseDown: (e) => e.preventDefault(),
|
|
449
|
-
onClick: () =>
|
|
450
|
-
children:
|
|
459
|
+
onClick: () => be(e),
|
|
460
|
+
children: T[e] ?? e
|
|
451
461
|
}, e);
|
|
452
|
-
return /* @__PURE__ */
|
|
462
|
+
return /* @__PURE__ */ P("div", {
|
|
453
463
|
className: `wmd-editor${h ? ` ${h}` : ""}`,
|
|
454
464
|
"data-theme": o,
|
|
455
|
-
style:
|
|
465
|
+
style: ne,
|
|
456
466
|
children: [
|
|
457
|
-
|
|
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:
|
|
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:
|
|
473
|
+
children: we(e)
|
|
464
474
|
}, e))
|
|
465
475
|
}),
|
|
466
|
-
/* @__PURE__ */
|
|
476
|
+
/* @__PURE__ */ P("div", {
|
|
467
477
|
className: "wmd-editor-surface",
|
|
468
|
-
children: [/* @__PURE__ */
|
|
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__ */
|
|
482
|
+
children: [/* @__PURE__ */ N("span", {
|
|
473
483
|
className: "wmd-spinner",
|
|
474
484
|
"aria-hidden": "true"
|
|
475
|
-
}), /* @__PURE__ */
|
|
485
|
+
}), /* @__PURE__ */ N("span", { children: "Chargement du fichier…" })]
|
|
476
486
|
})]
|
|
477
487
|
}),
|
|
478
|
-
H !== "idle" && /* @__PURE__ */
|
|
488
|
+
H !== "idle" && /* @__PURE__ */ N("div", {
|
|
479
489
|
className: "wmd-modal-backdrop",
|
|
480
490
|
role: "status",
|
|
481
491
|
"aria-live": "polite",
|
|
482
|
-
children: /* @__PURE__ */
|
|
492
|
+
children: /* @__PURE__ */ N("div", {
|
|
483
493
|
className: "wmd-modal",
|
|
484
|
-
children: H === "saving" ? /* @__PURE__ */
|
|
494
|
+
children: H === "saving" ? /* @__PURE__ */ P(pe, { children: [/* @__PURE__ */ N("span", {
|
|
485
495
|
className: "wmd-spinner",
|
|
486
496
|
"aria-hidden": "true"
|
|
487
|
-
}), /* @__PURE__ */
|
|
497
|
+
}), /* @__PURE__ */ N("span", {
|
|
488
498
|
className: "wmd-modal-text",
|
|
489
499
|
children: "Enregistrement…"
|
|
490
|
-
})] }) : /* @__PURE__ */
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
521
|
+
}), /* @__PURE__ */ P("span", {
|
|
512
522
|
className: "wmd-modal-text",
|
|
513
|
-
children: ["Enregistré",
|
|
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
|
@@ -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
|
|
122
|
-
|
|
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
|
-
|
|
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
|
}
|