@morfira-dev/wysiwyg-react 1.3.0 → 1.5.0

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/dist/index.d.ts CHANGED
@@ -1,15 +1,3 @@
1
- import type { Editor, EditorChange, EditorPlugin } from '@morfira-dev/wysiwyg-core';
2
- export interface MorfiraEditorProps {
3
- value?: string;
4
- readOnly?: boolean;
5
- placeholder?: string;
6
- label?: string;
7
- plugins?: EditorPlugin[];
8
- className?: string;
9
- onChange?: (change: EditorChange) => void;
10
- onReady?: (editor: Editor) => void;
11
- }
12
- export interface MorfiraEditorHandle {
13
- getEditor(): Editor | undefined;
14
- }
1
+ import type { MorfiraEditorProps, MorfiraEditorHandle } from './types.js';
2
+ export type { MorfiraEditorProps, MorfiraEditorHandle } from './types.js';
15
3
  export declare const MorfiraEditor: import("react").ForwardRefExoticComponent<MorfiraEditorProps & import("react").RefAttributes<MorfiraEditorHandle>>;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{forwardRef as f,useEffect as d,useImperativeHandle as s,useRef as i}from"react";import{createEditor as g}from"@morfira-dev/wysiwyg-core";import{jsx as E}from"react/jsx-runtime";var v=f((e,u)=>{let l=i(null),r=i(void 0),n=i(e);n.current=e;let o=i(!1);return s(u,()=>({getEditor:()=>r.current}),[]),d(()=>{let t=n.current,a=g(l.current,{...t,onChange:c=>{o.current||n.current.onChange?.(c)}});return r.current=a,n.current.onReady?.(a),()=>{a.destroy(),r.current=void 0}},[]),d(()=>{let t=r.current;if(!(!t||e.value===void 0||e.value===t.getHTML())){o.current=!0;try{t.setHTML(e.value)}finally{o.current=!1}}},[e.value]),d(()=>{r.current?.setReadOnly(e.readOnly??!1)},[e.readOnly]),E("div",{ref:l,className:e.className??"mw-host"})});export{v as MorfiraEditor};
1
+ import{forwardRef as s,useEffect as d,useImperativeHandle as l,useRef as o}from"react";import{createEditor as y}from"@morfira-dev/wysiwyg-core";import{jsx as m}from"react/jsx-runtime";var v=s((r,u)=>{let f=o(null),e=o(void 0),n=o(r);n.current=r;let i=o(!1);return l(u,()=>({getEditor:()=>e.current}),[]),d(()=>{let t=n.current,a=y(f.current,{...t,onChange:c=>{i.current||n.current.onChange?.(c)}});return e.current=a,n.current.onReady?.(a),()=>{a.destroy(),e.current=void 0}},[]),d(()=>{let t=e.current;if(!(!t||r.value===void 0||r.value===t.getHTML())){i.current=!0;try{t.setHTML(r.value)}finally{i.current=!1}}},[r.value]),d(()=>{e.current?.setReadOnly(r.readOnly??!1)},[r.readOnly]),m("div",{ref:f,className:r.className??"mw-host"})});export{v as MorfiraEditor};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.tsx"],
4
- "sourcesContent": ["import { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';\nimport { createEditor } from '@morfira-dev/wysiwyg-core';\nimport type { Editor, EditorChange, EditorPlugin } from '@morfira-dev/wysiwyg-core';\n\nexport interface MorfiraEditorProps {\n value?: string;\n readOnly?: boolean;\n placeholder?: string;\n label?: string;\n plugins?: EditorPlugin[];\n className?: string;\n onChange?: (change: EditorChange) => void;\n onReady?: (editor: Editor) => void;\n}\nexport interface MorfiraEditorHandle { getEditor(): Editor | undefined; }\n\nexport const MorfiraEditor = forwardRef<MorfiraEditorHandle, MorfiraEditorProps>((props, ref) => {\n const host = useRef<HTMLDivElement>(null);\n const instance = useRef<Editor | undefined>(undefined);\n const latest = useRef(props);\n latest.current = props;\n const applying = useRef(false);\n useImperativeHandle(ref, () => ({ getEditor: () => instance.current }), []);\n useEffect(() => {\n const options = latest.current;\n const editor = createEditor(host.current!, {\n ...options,\n onChange: (change) => {\n if (!applying.current)\n latest.current.onChange?.(change);\n },\n });\n instance.current = editor;\n latest.current.onReady?.(editor);\n return () => { editor.destroy(); instance.current = undefined; };\n }, []);\n useEffect(() => {\n const editor = instance.current;\n if (!editor || props.value === undefined || props.value === editor.getHTML())\n return;\n applying.current = true;\n try {\n editor.setHTML(props.value);\n }\n finally {\n applying.current = false;\n }\n }, [props.value]);\n useEffect(() => { instance.current?.setReadOnly(props.readOnly ?? false); }, [props.readOnly]);\n return <div ref={host} className={props.className ?? 'mw-host'} />;\n});\n"],
5
- "mappings": "AAAA,OAAS,cAAAA,EAAY,aAAAC,EAAW,uBAAAC,EAAqB,UAAAC,MAAc,QACnE,OAAS,gBAAAC,MAAoB,4BAgDpB,cAAAC,MAAA,oBAjCF,IAAMC,EAAgBN,EAAoD,CAACO,EAAOC,IAAQ,CAC/F,IAAMC,EAAON,EAAuB,IAAI,EAClCO,EAAWP,EAA2B,MAAS,EAC/CQ,EAASR,EAAOI,CAAK,EAC3BI,EAAO,QAAUJ,EACjB,IAAMK,EAAWT,EAAO,EAAK,EAC7B,OAAAD,EAAoBM,EAAK,KAAO,CAAE,UAAW,IAAME,EAAS,OAAQ,GAAI,CAAC,CAAC,EAC1ET,EAAU,IAAM,CACd,IAAMY,EAAUF,EAAO,QACjBG,EAASV,EAAaK,EAAK,QAAU,CACzC,GAAGI,EACH,SAAWE,GAAW,CACfH,EAAS,SACZD,EAAO,QAAQ,WAAWI,CAAM,CACpC,CACF,CAAC,EACD,OAAAL,EAAS,QAAUI,EACnBH,EAAO,QAAQ,UAAUG,CAAM,EACxB,IAAM,CAAEA,EAAO,QAAQ,EAAGJ,EAAS,QAAU,MAAW,CACjE,EAAG,CAAC,CAAC,EACLT,EAAU,IAAM,CACd,IAAMa,EAASJ,EAAS,QACxB,GAAI,GAACI,GAAUP,EAAM,QAAU,QAAaA,EAAM,QAAUO,EAAO,QAAQ,GAE3E,CAAAF,EAAS,QAAU,GACnB,GAAI,CACFE,EAAO,QAAQP,EAAM,KAAK,CAC5B,QACA,CACEK,EAAS,QAAU,EACrB,EACF,EAAG,CAACL,EAAM,KAAK,CAAC,EAChBN,EAAU,IAAM,CAAES,EAAS,SAAS,YAAYH,EAAM,UAAY,EAAK,CAAG,EAAG,CAACA,EAAM,QAAQ,CAAC,EACtFF,EAAC,OAAI,IAAKI,EAAM,UAAWF,EAAM,WAAa,UAAW,CAClE,CAAC",
4
+ "sourcesContent": ["import type { MorfiraEditorProps, MorfiraEditorHandle } from './types.js';\nexport type { MorfiraEditorProps, MorfiraEditorHandle } from './types.js';\nimport { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';\nimport { createEditor } from '@morfira-dev/wysiwyg-core';\nimport type { Editor } from '@morfira-dev/wysiwyg-core';\n\nexport const MorfiraEditor = forwardRef<MorfiraEditorHandle, MorfiraEditorProps>((props, ref) => {\n const host = useRef<HTMLDivElement>(null);\n const instance = useRef<Editor | undefined>(undefined);\n const latest = useRef(props);\n latest.current = props;\n const applying = useRef(false);\n useImperativeHandle(ref, () => ({ getEditor: () => instance.current }), []);\n useEffect(() => {\n const options = latest.current;\n const editor = createEditor(host.current!, {\n ...options,\n onChange: (change) => {\n if (!applying.current)\n latest.current.onChange?.(change);\n },\n });\n instance.current = editor;\n latest.current.onReady?.(editor);\n return () => { editor.destroy(); instance.current = undefined; };\n }, []);\n useEffect(() => {\n const editor = instance.current;\n if (!editor || props.value === undefined || props.value === editor.getHTML())\n return;\n applying.current = true;\n try {\n editor.setHTML(props.value);\n }\n finally {\n applying.current = false;\n }\n }, [props.value]);\n useEffect(() => { instance.current?.setReadOnly(props.readOnly ?? false); }, [props.readOnly]);\n return <div ref={host} className={props.className ?? 'mw-host'} />;\n});\n"],
5
+ "mappings": "AAEA,OAAS,cAAAA,EAAY,aAAAC,EAAW,uBAAAC,EAAqB,UAAAC,MAAc,QACnE,OAAS,gBAAAC,MAAoB,4BAoCpB,cAAAC,MAAA,oBAjCF,IAAMC,EAAgBN,EAAoD,CAACO,EAAOC,IAAQ,CAC/F,IAAMC,EAAON,EAAuB,IAAI,EAClCO,EAAWP,EAA2B,MAAS,EAC/CQ,EAASR,EAAOI,CAAK,EAC3BI,EAAO,QAAUJ,EACjB,IAAMK,EAAWT,EAAO,EAAK,EAC7B,OAAAD,EAAoBM,EAAK,KAAO,CAAE,UAAW,IAAME,EAAS,OAAQ,GAAI,CAAC,CAAC,EAC1ET,EAAU,IAAM,CACd,IAAMY,EAAUF,EAAO,QACjBG,EAASV,EAAaK,EAAK,QAAU,CACzC,GAAGI,EACH,SAAWE,GAAW,CACfH,EAAS,SACZD,EAAO,QAAQ,WAAWI,CAAM,CACpC,CACF,CAAC,EACD,OAAAL,EAAS,QAAUI,EACnBH,EAAO,QAAQ,UAAUG,CAAM,EACxB,IAAM,CAAEA,EAAO,QAAQ,EAAGJ,EAAS,QAAU,MAAW,CACjE,EAAG,CAAC,CAAC,EACLT,EAAU,IAAM,CACd,IAAMa,EAASJ,EAAS,QACxB,GAAI,GAACI,GAAUP,EAAM,QAAU,QAAaA,EAAM,QAAUO,EAAO,QAAQ,GAE3E,CAAAF,EAAS,QAAU,GACnB,GAAI,CACFE,EAAO,QAAQP,EAAM,KAAK,CAC5B,QACA,CACEK,EAAS,QAAU,EACrB,EACF,EAAG,CAACL,EAAM,KAAK,CAAC,EAChBN,EAAU,IAAM,CAAES,EAAS,SAAS,YAAYH,EAAM,UAAY,EAAK,CAAG,EAAG,CAACA,EAAM,QAAQ,CAAC,EACtFF,EAAC,OAAI,IAAKI,EAAM,UAAWF,EAAM,WAAa,UAAW,CAClE,CAAC",
6
6
  "names": ["forwardRef", "useEffect", "useImperativeHandle", "useRef", "createEditor", "jsx", "MorfiraEditor", "props", "ref", "host", "instance", "latest", "applying", "options", "editor", "change"]
7
7
  }
@@ -0,0 +1,14 @@
1
+ import type { Editor, EditorChange, EditorPlugin } from '@morfira-dev/wysiwyg-core';
2
+ export interface MorfiraEditorProps {
3
+ value?: string;
4
+ readOnly?: boolean;
5
+ placeholder?: string;
6
+ label?: string;
7
+ plugins?: EditorPlugin[];
8
+ className?: string;
9
+ onChange?: (change: EditorChange) => void;
10
+ onReady?: (editor: Editor) => void;
11
+ }
12
+ export interface MorfiraEditorHandle {
13
+ getEditor(): Editor | undefined;
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morfira-dev/wysiwyg-react",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -19,7 +19,7 @@
19
19
  }
20
20
  },
21
21
  "peerDependencies": {
22
- "@morfira-dev/wysiwyg-core": "^1.3.0",
22
+ "@morfira-dev/wysiwyg-core": "^1.5.0",
23
23
  "react": "^18.0.0 || ^19.0.0"
24
24
  },
25
25
  "peerDependenciesMeta": {