open-edit 0.1.1 → 0.1.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.
package/README.md CHANGED
@@ -521,15 +521,20 @@ export function Editor({ onChange }: { onChange: (html: string) => void }) {
521
521
  const editorRef = useRef<EditorInterface | null>(null);
522
522
 
523
523
  useEffect(() => {
524
- if (!ref.current) return;
524
+ if (!ref.current || editorRef.current) return;
525
525
  editorRef.current = OpenEdit.create(ref.current, { onChange });
526
- return () => editorRef.current?.destroy();
526
+ return () => {
527
+ editorRef.current?.destroy();
528
+ editorRef.current = null;
529
+ };
527
530
  }, []);
528
531
 
529
532
  return <div ref={ref} />;
530
533
  }
531
534
  ```
532
535
 
536
+ > **Note:** The guard `|| editorRef.current` prevents double-initialisation in React 18 Strict Mode, which intentionally mounts effects twice in development.
537
+
533
538
  ### Vue 3
534
539
 
535
540
  ```vue
@@ -779,5 +779,5 @@ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{val
779
779
  <div class="oe-slash-menu-title">${e.title}</div>
780
780
  ${e.description?`<div class="oe-slash-menu-desc">${e.description}</div>`:``}
781
781
  </div>
782
- </div>`).join(``),i.querySelector(`.oe-slash-active`)?.scrollIntoView({block:`nearest`})}}function p(){if(!i)return;a=!0,i.style.display=`block`;let{top:e,left:t}=u();i.style.top=`${e}px`,i.style.left=`${t}px`,requestAnimationFrame(()=>{if(!i)return;let n=d(i,e,t);i.style.top=`${n.top}px`,i.style.left=`${n.left}px`}),f()}function m(){i&&(a=!1,i.style.display=`none`,i.innerHTML=``,o=0,s=[])}function h(e){if(!r||!n)return;let t=c(),i=-1;if(t){let e=t.blockEl;i=Array.from(n.children).indexOf(e),e.innerHTML=``;let r=window.getSelection();if(r){let t=document.createRange();t.setStart(e,0),t.collapse(!0),r.removeAllRanges(),r.addRange(t)}}m(),e.execute(r),i>=0&&requestAnimationFrame(()=>{if(!n)return;let e=n.children[i];if(!e)return;let t=g(e),r=window.getSelection();if(!r)return;let a=document.createRange();if(t)a.setStart(t,t.length);else if(e instanceof HTMLElement&&e.tagName===`HR`){let t=n.children[i+1]??e;a.setStart(t,0)}else a.setStart(e,0);a.collapse(!0),r.removeAllRanges(),r.addRange(a)})}function g(e){for(let t=e.childNodes.length-1;t>=0;t--){let n=g(e.childNodes[t]);if(n)return n}return e.nodeType===Node.TEXT_NODE?e:null}let _=()=>{let e=c();if(!e){a&&m();return}let{query:t}=e;s=l(t),o>=s.length&&(o=0),s.length,p()},v=e=>{if(a)switch(e.key){case`ArrowDown`:e.preventDefault(),e.stopImmediatePropagation(),o=(o+1)%Math.max(s.length,1),f();break;case`ArrowUp`:e.preventDefault(),e.stopImmediatePropagation(),o=(o-1+Math.max(s.length,1))%Math.max(s.length,1),f();break;case`Enter`:s.length>0&&s[o]&&(e.preventDefault(),e.stopImmediatePropagation(),h(s[o]));break;case`Escape`:e.preventDefault(),e.stopImmediatePropagation(),m();break;case`Tab`:s.length>0&&s[o]&&(e.preventDefault(),e.stopImmediatePropagation(),h(s[o]));break}},y=e=>{!a||!i||i.contains(e.target)||m()},b=e=>{let t=e.target.closest(`.oe-slash-menu-item`);if(!t)return;let n=parseInt(t.dataset.index??`0`,10),r=s[n];r&&h(r)},x=()=>{a&&m()};return{name:`slash-commands`,onInit(e){r=e,n=e.editorEl,n&&(wt(),i=document.createElement(`div`),i.className=`oe-slash-menu`,i.style.display=`none`,document.body.appendChild(i),n.addEventListener(`keydown`,v,!0),n.addEventListener(`input`,_),i.addEventListener(`click`,b),document.addEventListener(`click`,y,!0),window.addEventListener(`scroll`,x,{passive:!0}))},onDestroy(e){n&&(n.removeEventListener(`keydown`,v,!0),n.removeEventListener(`input`,_)),i&&=(i.removeEventListener(`click`,b),i.remove(),null),document.removeEventListener(`click`,y,!0),window.removeEventListener(`scroll`,x),n=null,r=null,a=!1}}}function Et(e,t){return new Ue({element:e,...t})}var Dt={create:Et,version:`0.1.0`,locales:{en:W,de:J},plugins:{highlight:$e,emoji:rt,templateTags:at,ai:lt,callout:dt,slashCommands:Tt},markdown:{serialize:D,deserialize:k}};exports.Editor=Ue,exports.OpenEdit=Dt,exports.default=Dt,exports.createAIPlugin=lt,exports.createCalloutPlugin=dt,exports.createEmojiPlugin=rt,exports.createHighlightPlugin=$e,exports.createSlashCommandsPlugin=Tt,exports.createTemplateTagPlugin=at,exports.de=J,exports.deserializeMarkdown=k,exports.en=W,exports.serializeToMarkdown=D;
782
+ </div>`).join(``),i.querySelector(`.oe-slash-active`)?.scrollIntoView({block:`nearest`})}}function p(){if(!i)return;a=!0,i.style.display=`block`;let{top:e,left:t}=u();i.style.top=`${e}px`,i.style.left=`${t}px`,requestAnimationFrame(()=>{if(!i)return;let n=d(i,e,t);i.style.top=`${n.top}px`,i.style.left=`${n.left}px`}),f()}function m(){i&&(a=!1,i.style.display=`none`,i.innerHTML=``,o=0,s=[])}function h(e){if(!r||!n)return;let t=c(),i=-1;if(t){let e=t.blockEl;i=Array.from(n.children).indexOf(e),e.innerHTML=``;let r=window.getSelection();if(r){let t=document.createRange();t.setStart(e,0),t.collapse(!0),r.removeAllRanges(),r.addRange(t)}}m(),e.execute(r),i>=0&&requestAnimationFrame(()=>{if(!n)return;let e=n.children[i];if(!e)return;let t=g(e),r=window.getSelection();if(!r)return;let a=document.createRange();if(t)a.setStart(t,t.length);else if(e instanceof HTMLElement&&e.tagName===`HR`){let t=n.children[i+1]??e;a.setStart(t,0)}else a.setStart(e,0);a.collapse(!0),r.removeAllRanges(),r.addRange(a)})}function g(e){for(let t=e.childNodes.length-1;t>=0;t--){let n=g(e.childNodes[t]);if(n)return n}return e.nodeType===Node.TEXT_NODE?e:null}let _=()=>{let e=c();if(!e){a&&m();return}let{query:t}=e;s=l(t),o>=s.length&&(o=0),s.length,p()},v=e=>{if(a)switch(e.key){case`ArrowDown`:e.preventDefault(),e.stopImmediatePropagation(),o=(o+1)%Math.max(s.length,1),f();break;case`ArrowUp`:e.preventDefault(),e.stopImmediatePropagation(),o=(o-1+Math.max(s.length,1))%Math.max(s.length,1),f();break;case`Enter`:s.length>0&&s[o]&&(e.preventDefault(),e.stopImmediatePropagation(),h(s[o]));break;case`Escape`:e.preventDefault(),e.stopImmediatePropagation(),m();break;case`Tab`:s.length>0&&s[o]&&(e.preventDefault(),e.stopImmediatePropagation(),h(s[o]));break}},y=e=>{!a||!i||i.contains(e.target)||m()},b=e=>{let t=e.target.closest(`.oe-slash-menu-item`);if(!t)return;let n=parseInt(t.dataset.index??`0`,10),r=s[n];r&&h(r)},x=()=>{a&&m()};return{name:`slash-commands`,onInit(e){r=e,n=e.editorEl,n&&(wt(),i=document.createElement(`div`),i.className=`oe-slash-menu`,i.style.display=`none`,document.body.appendChild(i),n.addEventListener(`keydown`,v,!0),n.addEventListener(`input`,_),i.addEventListener(`click`,b),document.addEventListener(`click`,y,!0),window.addEventListener(`scroll`,x,{passive:!0}))},onDestroy(e){n&&(n.removeEventListener(`keydown`,v,!0),n.removeEventListener(`input`,_)),i&&=(i.removeEventListener(`click`,b),i.remove(),null),document.removeEventListener(`click`,y,!0),window.removeEventListener(`scroll`,x),n=null,r=null,a=!1}}}function Et(e,t){return new Ue({element:e,...t})}var Dt={create:Et,version:`0.1.3`,locales:{en:W,de:J},plugins:{highlight:$e,emoji:rt,templateTags:at,ai:lt,callout:dt,slashCommands:Tt},markdown:{serialize:D,deserialize:k}};exports.Editor=Ue,exports.OpenEdit=Dt,exports.default=Dt,exports.createAIPlugin=lt,exports.createCalloutPlugin=dt,exports.createEmojiPlugin=rt,exports.createHighlightPlugin=$e,exports.createSlashCommandsPlugin=Tt,exports.createTemplateTagPlugin=at,exports.de=J,exports.deserializeMarkdown=k,exports.en=W,exports.serializeToMarkdown=D;
783
783
  //# sourceMappingURL=open-edit.cjs.js.map