@wysio/react 0.0.0-stage → 0.1.0-alpha.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # @wysio/react
2
+
3
+ ## 0.1.0-alpha.1
4
+
5
+ ### Minor Changes
6
+
7
+ - 22876f8: Form fields:
8
+
9
+ - New `attributes` option and `editor.setAttributes()` for extra attributes on the editing area, such as `aria-invalid` and `aria-describedby` for validation errors. `@wysio/vue` and `@wysio/react` get an `attributes` prop that applies changes without recreating the editor.
10
+ - `<wysio-editor>`: an `options` attribute (JSON) for any other option; a `<label for>` or wrapping `<label>` names the editor and focuses it; `focus()` focuses the editing area; new `ready` and `error` events.
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [51886e3]
15
+ - Updated dependencies [22876f8]
16
+ - Updated dependencies [e091b7c]
17
+ - wysio@0.2.0-alpha.7
18
+
19
+ ## 0.1.0-alpha.0
20
+
21
+ ### Minor Changes
22
+
23
+ - a8fa535: New package: `<WysioEditor>` for React 18 and 19. Controlled (`value` + `onChange`) or uncontrolled (`defaultValue`), with `format`, `toolbar`, `plugins`, `locale`, `placeholder`, `editable`, `id`, `minHeight`, `options` and `className` props, `onReady` / `onFocus` / `onBlur` / `onError`, and the editor instance through `ref`. StrictMode-safe; values the editor reported coming back late never reset the cursor.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rens Verhaeven
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,80 @@
1
- # Temporary Holding Version
1
+ # @wysio/react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ React component for [Wysio Editor](https://www.wysio-editor.com). MIT licensed. Works with React 18 and 19, including StrictMode.
4
+
5
+ > Under active development. Not ready for production use yet.
6
+
7
+ ```sh
8
+ npm install @wysio/react
9
+ ```
10
+
11
+ ```tsx
12
+ import { useRef, useState } from 'react';
13
+ import { WysioEditor } from '@wysio/react';
14
+ import type { Editor } from 'wysio';
15
+ import 'wysio/style.css';
16
+
17
+ const toolbar = ['heading', '|', 'bold', 'italic', '|', 'bulletList', 'link'];
18
+
19
+ export function PostForm() {
20
+ const [body, setBody] = useState('<p>Hello</p>');
21
+ const editor = useRef<Editor | null>(null);
22
+
23
+ return (
24
+ <>
25
+ <label htmlFor="body">Body</label>
26
+ <WysioEditor
27
+ id="body"
28
+ ref={editor}
29
+ value={body}
30
+ onChange={(value) => setBody(value as string)}
31
+ toolbar={toolbar}
32
+ locale="nl"
33
+ />
34
+ </>
35
+ );
36
+ }
37
+ ```
38
+
39
+ ## Props
40
+
41
+ | Prop | Type | Default |
42
+ | -------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
43
+ | `value` | `string`, or a ProseMirror JSON object with `format="json"`; controlled | |
44
+ | `defaultValue` | the same, for an uncontrolled editor | `''` |
45
+ | `onChange` | `(value, editor) => void`, on every change made in the editor | |
46
+ | `format` | `'html' \| 'markdown' \| 'json'` | `'html'` |
47
+ | `toolbar` | `string[] \| false` | the default toolbar |
48
+ | `plugins` | plugins or registered names, e.g. `['markdown']` | |
49
+ | `locale` | `'en' \| 'nl' \| 'fr' \| …` or a messages object | `'en'` |
50
+ | `placeholder` | `string` | |
51
+ | `id` | id of the editing area, so `<label htmlFor>` names and focuses it | |
52
+ | `minHeight` | pixels or a CSS length (`'20rem'`) | `10rem` |
53
+ | `attributes` | extra attributes for the editing area, e.g. `{ 'aria-invalid': 'true', 'aria-describedby': 'body-error' }`; applied live | |
54
+ | `editable` | `boolean` | `true` |
55
+ | `options` | any other `createEditor` option from the [`wysio` README](https://www.npmjs.com/package/wysio) (`upload`, `sticky`, `messages`, …) | `{}` |
56
+ | `className` | class names for the wrapper (`.wysio-react`) | |
57
+ | `onReady` | `(editor) => void`, when an editor is created | |
58
+ | `onFocus` | `(event, editor) => void` | |
59
+ | `onBlur` | `(event, editor) => void` | |
60
+ | `onError` | `(error, { source, file }) => void`, e.g. a failed upload | |
61
+
62
+ `editable` and `attributes` apply immediately. Changing `toolbar`, `plugins`, `locale`, `format`, `placeholder`, `id`, `minHeight` or `options` recreates the editor and keeps its content (`onReady` is called again). Inline arrays and objects are fine: only real changes count. Define functions such as `upload` outside the component (or with `useCallback`), since a new function counts as a change. The callbacks (`onChange`, `onFocus`, …) can change freely.
63
+
64
+ A controlled `value` only replaces the editor content when it is an outside change. The values the editor reported through `onChange` coming back (also an older one, while typing faster than React renders) never reset the cursor.
65
+
66
+ For Markdown, import `wysio/markdown` once (it registers the plugin) and use `format="markdown" plugins={['markdown']}`.
67
+
68
+ ## Editor instance
69
+
70
+ The `ref` gives the `Editor` (`null` until it is created, and briefly while it is recreated); `onReady` passes it too:
71
+
72
+ ```tsx
73
+ const editor = useRef<Editor | null>(null);
74
+ <WysioEditor ref={editor} defaultValue="<p>Hi</p>" />;
75
+ // editor.current?.getMarkdown(), .focus(), …
76
+ ```
77
+
78
+ ## Server-side rendering
79
+
80
+ The editor needs the DOM, so it is created in an effect: on the server, and in the first client render, the component renders an empty wrapper. In Next.js, use it in a Client Component (`'use client'`).
@@ -0,0 +1,57 @@
1
+ import { type ContentFormat, type Editor, type EditorErrorInfo, type EditorOptions, type JSONContent, type Messages, type WysioPlugin } from 'wysio';
2
+ /**
3
+ * Structural equality for editor configuration: arrays and plain objects by content,
4
+ * everything else (functions, plugin objects, …) by identity. Components create new
5
+ * arrays and objects on every render (`toolbar={['bold']}`), which must not count as
6
+ * a change.
7
+ */
8
+ export declare function sameConfig(a: unknown, b: unknown): boolean;
9
+ /** The value: a string in `format`, or a ProseMirror JSON object when `format` is `json`. */
10
+ export type WysioValue = string | JSONContent;
11
+ export interface WysioEditorProps {
12
+ /**
13
+ * The content, controlled: update it from `onChange`. HTML by default; see `format`.
14
+ * Leave it out (and use `defaultValue`) for an uncontrolled editor.
15
+ */
16
+ value?: WysioValue | null;
17
+ /** Initial content of an uncontrolled editor. */
18
+ defaultValue?: WysioValue | null;
19
+ /** Called with the new value on every change made in the editor. */
20
+ onChange?: (value: WysioValue, editor: Editor) => void;
21
+ /** `html` (default), `markdown` (needs the markdown plugin) or `json` (an object). */
22
+ format?: ContentFormat;
23
+ toolbar?: readonly string[] | false;
24
+ plugins?: readonly (WysioPlugin | string)[];
25
+ locale?: string | Messages;
26
+ placeholder?: string;
27
+ /** Default `true`. Applied without recreating the editor. */
28
+ editable?: boolean;
29
+ /** Id of the editing area, so `<label htmlFor>` names and focuses the editor. */
30
+ id?: string;
31
+ /** Minimum height of the editing area: pixels, or a CSS length such as `'20rem'`. */
32
+ minHeight?: number | string;
33
+ /**
34
+ * Extra attributes for the editing area, e.g. `{ 'aria-invalid': 'true',
35
+ * 'aria-describedby': 'body-error' }`. Applied without recreating the editor.
36
+ */
37
+ attributes?: Record<string, string>;
38
+ /** Any other `createEditor` options. The props above take precedence. */
39
+ options?: EditorOptions;
40
+ /** Class names for the wrapper element (`wysio-react`). */
41
+ className?: string;
42
+ onReady?: (editor: Editor) => void;
43
+ onFocus?: (event: FocusEvent, editor: Editor) => void;
44
+ onBlur?: (event: FocusEvent, editor: Editor) => void;
45
+ onError?: (error: unknown, info: EditorErrorInfo) => void;
46
+ }
47
+ /**
48
+ * React component around `createEditor`:
49
+ *
50
+ * ```tsx
51
+ * <WysioEditor value={body} onChange={setBody} locale="nl" ref={editorRef} />
52
+ * ```
53
+ *
54
+ * The ref gives the editor instance (null until it is created).
55
+ */
56
+ export declare const WysioEditor: import("react").ForwardRefExoticComponent<WysioEditorProps & import("react").RefAttributes<Editor | null>>;
57
+ //# sourceMappingURL=WysioEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WysioEditor.d.ts","sourceRoot":"","sources":["../src/WysioEditor.ts"],"names":[],"mappings":"AASA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,WAAW,EACjB,MAAM,OAAO,CAAC;AAEf;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAe1D;AAYD,6FAA6F;AAC7F,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,WAAW,CAAC;AAE9C,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,KAAK,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1B,iDAAiD;IACjD,YAAY,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;IACjC,oEAAoE;IACpE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACvD,sFAAsF;IACtF,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,KAAK,CAAC;IACpC,OAAO,CAAC,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,CAAC,EAAE,CAAC;IAC5C,MAAM,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iFAAiF;IACjF,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,qFAAqF;IACrF,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,yEAAyE;IACzE,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACtD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,KAAK,IAAI,CAAC;CAC3D;AAoID;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,4GAA+B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { sameConfig, WysioEditor, type WysioEditorProps, type WysioValue } from './WysioEditor';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,96 @@
1
+ import { createElement as e, forwardRef as t, useEffect as n, useImperativeHandle as r, useRef as i, useState as a } from "react";
2
+ import { createEditor as o } from "wysio";
3
+ // src/WysioEditor.ts
4
+ function s(e, t) {
5
+ if (e === t) return !0;
6
+ if (Array.isArray(e) && Array.isArray(t)) return e.length === t.length && e.every((e, n) => s(e, t[n]));
7
+ let n = (e) => !!e && typeof e == "object" && Object.getPrototypeOf(e) === Object.prototype;
8
+ if (n(e) && n(t)) {
9
+ let n = Object.keys(e);
10
+ return n.length === Object.keys(t).length && n.every((n) => n in t && s(e[n], t[n]));
11
+ }
12
+ return !1;
13
+ }
14
+ function c(e, t) {
15
+ let n = { ...t };
16
+ for (let r of Object.keys(e ?? {})) r in (t ?? {}) || (n[r] = null);
17
+ return n;
18
+ }
19
+ var l = (e, t) => t === "json" ? e.isEmpty ? "" : e.getJSON() : e.serialize(t);
20
+ function u(e, t) {
21
+ return e == null || e === "" ? t == null || t === "" : typeof e == "object" || typeof t == "object" ? JSON.stringify(e) === JSON.stringify(t) : e === t;
22
+ }
23
+ var d = 100;
24
+ function f(e) {
25
+ let t = i({
26
+ config: e,
27
+ version: 0
28
+ });
29
+ return s(t.current.config, e) || (t.current = {
30
+ config: e,
31
+ version: t.current.version + 1
32
+ }), t.current.version;
33
+ }
34
+ function p(t, p) {
35
+ let { format: m = "html", editable: h = !0 } = t, g = i(null), [_, v] = a(null), y = i(t);
36
+ y.current = t;
37
+ let b = i(null), x = i([]), S = i(void 0);
38
+ r(p, () => _, [_]);
39
+ let C = f([
40
+ t.toolbar,
41
+ t.plugins,
42
+ t.locale,
43
+ m,
44
+ t.placeholder,
45
+ t.id,
46
+ t.minHeight,
47
+ t.options
48
+ ]);
49
+ n(() => {
50
+ let e = y.current, t = e.options ?? {}, n = e.value === void 0 ? b.current ?? e.defaultValue ?? t.content ?? "" : e.value ?? "", r = o(g.current, {
51
+ ...t,
52
+ content: n,
53
+ format: m,
54
+ toolbar: e.toolbar ?? t.toolbar,
55
+ plugins: [...t.plugins ?? [], ...e.plugins ?? []],
56
+ locale: e.locale ?? t.locale,
57
+ placeholder: e.placeholder ?? t.placeholder,
58
+ editable: e.editable ?? !0,
59
+ id: e.id ?? t.id,
60
+ minHeight: e.minHeight ?? t.minHeight,
61
+ attributes: {
62
+ ...t.attributes,
63
+ ...e.attributes
64
+ }
65
+ });
66
+ return S.current = e.attributes, x.current = [], r.on("change", () => {
67
+ let e = l(r, m);
68
+ x.current.push(e), x.current.length > d && x.current.shift(), y.current.onChange?.(e, r);
69
+ }), r.on("focus", (e, t) => y.current.onFocus?.(t, r)), r.on("blur", (e, t) => y.current.onBlur?.(t, r)), r.on("error", (e, t, n) => y.current.onError?.(t, n)), v(r), e.onReady?.(r), () => {
70
+ b.current = r.getJSON(), r.destroy(), g.current?.replaceChildren(), v(null);
71
+ };
72
+ }, [C]);
73
+ let { value: w } = t;
74
+ n(() => {
75
+ if (!_ || w === void 0) return;
76
+ let e = x.current.findIndex((e) => u(e, w));
77
+ e >= 0 ? x.current.splice(0, e + 1) : (x.current = [], u(l(_, m), w) || _.setContent(w ?? ""));
78
+ }, [
79
+ _,
80
+ w,
81
+ m
82
+ ]), n(() => {
83
+ _?.setEditable(h);
84
+ }, [_, h]);
85
+ let { attributes: T } = t;
86
+ n(() => {
87
+ _ && !s(S.current, T) && (_.setAttributes(c(S.current, T)), S.current = T);
88
+ }, [_, T]);
89
+ let E = t.className ? `wysio-react ${t.className}` : "wysio-react";
90
+ return e("div", { className: E }, e("div", { ref: g }));
91
+ }
92
+ var m = t(p);
93
+ m.displayName = "WysioEditor";
94
+ export { m as WysioEditor, s as sameConfig };
95
+
96
+ //# sourceMappingURL=wysio-react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wysio-react.js","names":["createElement","forwardRef","useEffect","useImperativeHandle","useRef","useState","createEditor","sameConfig","a","b","item","i","plain","v","keys","key","attributeChanges","previous","next","changes","name","valueOf","editor","format","sameValue","MAX_PENDING","useConfigVersion","config","ref","WysioEditorInner","props","editable","target","setEditor","latest","kept","pending","appliedAttributes","version","p","options","content","ed","_e","event","error","info","value","echo","attributes","className","WysioEditor"],"sources":["../src/WysioEditor.ts"],"sourcesContent":["import {\n createElement,\n forwardRef,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n type ForwardedRef,\n} from 'react';\nimport {\n createEditor,\n type Content,\n type ContentFormat,\n type Editor,\n type EditorErrorInfo,\n type EditorOptions,\n type JSONContent,\n type Messages,\n type WysioPlugin,\n} from 'wysio';\n\n/**\n * Structural equality for editor configuration: arrays and plain objects by content,\n * everything else (functions, plugin objects, …) by identity. Components create new\n * arrays and objects on every render (`toolbar={['bold']}`), which must not count as\n * a change.\n */\nexport function sameConfig(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (Array.isArray(a) && Array.isArray(b)) {\n return a.length === b.length && a.every((item, i) => sameConfig(item, b[i]));\n }\n const plain = (v: unknown): v is Record<string, unknown> =>\n !!v && typeof v === 'object' && Object.getPrototypeOf(v) === Object.prototype;\n if (plain(a) && plain(b)) {\n const keys = Object.keys(a);\n return (\n keys.length === Object.keys(b).length &&\n keys.every((key) => key in b && sameConfig(a[key], b[key]))\n );\n }\n return false;\n}\n\n/** What setAttributes() needs to go from one attributes object to the next. */\nfunction attributeChanges(\n previous: Record<string, string> | undefined,\n next: Record<string, string> | undefined,\n): Record<string, string | null> {\n const changes: Record<string, string | null> = { ...next };\n for (const name of Object.keys(previous ?? {})) if (!(name in (next ?? {}))) changes[name] = null;\n return changes;\n}\n\n/** The value: a string in `format`, or a ProseMirror JSON object when `format` is `json`. */\nexport type WysioValue = string | JSONContent;\n\nexport interface WysioEditorProps {\n /**\n * The content, controlled: update it from `onChange`. HTML by default; see `format`.\n * Leave it out (and use `defaultValue`) for an uncontrolled editor.\n */\n value?: WysioValue | null;\n /** Initial content of an uncontrolled editor. */\n defaultValue?: WysioValue | null;\n /** Called with the new value on every change made in the editor. */\n onChange?: (value: WysioValue, editor: Editor) => void;\n /** `html` (default), `markdown` (needs the markdown plugin) or `json` (an object). */\n format?: ContentFormat;\n toolbar?: readonly string[] | false;\n plugins?: readonly (WysioPlugin | string)[];\n locale?: string | Messages;\n placeholder?: string;\n /** Default `true`. Applied without recreating the editor. */\n editable?: boolean;\n /** Id of the editing area, so `<label htmlFor>` names and focuses the editor. */\n id?: string;\n /** Minimum height of the editing area: pixels, or a CSS length such as `'20rem'`. */\n minHeight?: number | string;\n /**\n * Extra attributes for the editing area, e.g. `{ 'aria-invalid': 'true',\n * 'aria-describedby': 'body-error' }`. Applied without recreating the editor.\n */\n attributes?: Record<string, string>;\n /** Any other `createEditor` options. The props above take precedence. */\n options?: EditorOptions;\n /** Class names for the wrapper element (`wysio-react`). */\n className?: string;\n onReady?: (editor: Editor) => void;\n onFocus?: (event: FocusEvent, editor: Editor) => void;\n onBlur?: (event: FocusEvent, editor: Editor) => void;\n onError?: (error: unknown, info: EditorErrorInfo) => void;\n}\n\nconst valueOf = (editor: Editor, format: ContentFormat): WysioValue =>\n format === 'json' ? (editor.isEmpty ? '' : editor.getJSON()) : editor.serialize(format);\n\n/** Values compared as the editor reports them: null and '' are the same, JSON by content. */\nfunction sameValue(a: WysioValue | null, b: WysioValue | null): boolean {\n if (a == null || a === '') return b == null || b === '';\n if (typeof a === 'object' || typeof b === 'object')\n return JSON.stringify(a) === JSON.stringify(b);\n return a === b;\n}\n\n/** Reported values not yet seen back as `value`; more means the parent ignores onChange. */\nconst MAX_PENDING = 100;\n\n/** A number that only changes when the configuration really changes (see sameConfig). */\nfunction useConfigVersion(config: unknown[]): number {\n const ref = useRef({ config, version: 0 });\n if (!sameConfig(ref.current.config, config)) {\n ref.current = { config, version: ref.current.version + 1 };\n }\n return ref.current.version;\n}\n\nfunction WysioEditorInner(props: WysioEditorProps, ref: ForwardedRef<Editor | null>) {\n const { format = 'html', editable = true } = props;\n const target = useRef<HTMLDivElement>(null);\n const [editor, setEditor] = useState<Editor | null>(null);\n // Callbacks and the value as of the latest render, for listeners set up once.\n const latest = useRef(props);\n latest.current = props;\n // The content when an editor is torn down, for the next one (config change, StrictMode).\n const kept = useRef<JSONContent | null>(null);\n // Values reported through onChange that haven't come back as `value` yet. React runs\n // effects after paint, so while typing fast a render can carry an older reported value\n // than the editor now has: that is an echo, not an outside change.\n const pending = useRef<WysioValue[]>([]);\n // The `attributes` prop as last applied to the editor.\n const appliedAttributes = useRef<Record<string, string> | undefined>(undefined);\n\n useImperativeHandle<Editor | null, Editor | null>(ref, () => editor, [editor]);\n\n const version = useConfigVersion([\n props.toolbar,\n props.plugins,\n props.locale,\n format,\n props.placeholder,\n props.id,\n props.minHeight,\n props.options,\n ]);\n\n // These are fixed when an editor is created: recreate it, keeping the content, but\n // only for real changes.\n useEffect(() => {\n const p = latest.current;\n const options = p.options ?? {};\n const controlled = p.value !== undefined;\n const content: Content = controlled\n ? (p.value ?? '')\n : (kept.current ?? p.defaultValue ?? options.content ?? '');\n const ed = createEditor(target.current!, {\n ...options,\n content,\n format,\n toolbar: p.toolbar ?? options.toolbar,\n plugins: [...(options.plugins ?? []), ...(p.plugins ?? [])],\n locale: p.locale ?? options.locale,\n placeholder: p.placeholder ?? options.placeholder,\n editable: p.editable ?? true,\n id: p.id ?? options.id,\n minHeight: p.minHeight ?? options.minHeight,\n attributes: { ...options.attributes, ...p.attributes },\n });\n appliedAttributes.current = p.attributes;\n pending.current = [];\n ed.on('change', () => {\n const next = valueOf(ed, format);\n pending.current.push(next);\n if (pending.current.length > MAX_PENDING) pending.current.shift();\n latest.current.onChange?.(next, ed);\n });\n ed.on('focus', (_e, event) => latest.current.onFocus?.(event, ed));\n ed.on('blur', (_e, event) => latest.current.onBlur?.(event, ed));\n ed.on('error', (_e, error, info) => latest.current.onError?.(error, info));\n setEditor(ed);\n p.onReady?.(ed);\n\n return () => {\n kept.current = ed.getJSON();\n ed.destroy();\n // destroy() leaves the final HTML in the element; the next editor brings its own.\n target.current?.replaceChildren();\n setEditor(null);\n };\n // Only `version`: everything else is read from `latest` when the editor is created.\n }, [version]);\n\n // Outside changes only: values the editor reported come back here too (possibly an\n // older one than the editor has by now), and setContent for those would reset the\n // cursor and drop what was typed since.\n const { value } = props;\n useEffect(() => {\n if (!editor || value === undefined) return;\n const echo = pending.current.findIndex((v) => sameValue(v, value));\n if (echo >= 0) {\n pending.current.splice(0, echo + 1);\n return;\n }\n pending.current = [];\n if (!sameValue(valueOf(editor, format), value)) editor.setContent(value ?? '');\n }, [editor, value, format]);\n\n useEffect(() => {\n editor?.setEditable(editable);\n }, [editor, editable]);\n\n const { attributes } = props;\n useEffect(() => {\n if (!editor || sameConfig(appliedAttributes.current, attributes)) return;\n editor.setAttributes(attributeChanges(appliedAttributes.current, attributes));\n appliedAttributes.current = attributes;\n }, [editor, attributes]);\n\n const className = props.className ? `wysio-react ${props.className}` : 'wysio-react';\n // The editor owns the inner element (it adds the `wysio` class and its own children),\n // so React never re-renders its attributes.\n return createElement('div', { className }, createElement('div', { ref: target }));\n}\n\n/**\n * React component around `createEditor`:\n *\n * ```tsx\n * <WysioEditor value={body} onChange={setBody} locale=\"nl\" ref={editorRef} />\n * ```\n *\n * The ref gives the editor instance (null until it is created).\n */\nexport const WysioEditor = forwardRef(WysioEditorInner);\nWysioEditor.displayName = 'WysioEditor';\n"],"mappings":";;;AA2BA,SAAgBO,EAAWC,GAAYC,GAAqB;CAC1D,IAAID,MAAMC,GAAG,OAAO;CACpB,IAAI,MAAM,QAAQD,CAAC,KAAK,MAAM,QAAQC,CAAC,GACrC,OAAOD,EAAE,WAAWC,EAAE,UAAUD,EAAE,OAAOE,GAAMC,MAAMJ,EAAWG,GAAMD,EAAEE,EAAE,CAAC;CAE7E,IAAMC,KAASC,MACb,CAAC,CAACA,KAAK,OAAOA,KAAM,YAAY,OAAO,eAAeA,CAAC,MAAM,OAAO;CACtE,IAAID,EAAMJ,CAAC,KAAKI,EAAMH,CAAC,GAAG;EACxB,IAAMK,IAAO,OAAO,KAAKN,CAAC;EAC1B,OACEM,EAAK,WAA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": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "React component for Wysio Editor, the ProseMirror-based WYSIWYG editor.",
5
+ "license": "MIT",
6
+ "author": "EveraertCooreman",
7
+ "homepage": "https://www.wysio-editor.com",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/wysio-editor/wysio.git",
11
+ "directory": "packages/react"
12
+ },
13
+ "bugs": "https://github.com/wysio-editor/wysio/issues",
14
+ "keywords": [
15
+ "wysiwyg",
16
+ "editor",
17
+ "rich-text",
18
+ "prosemirror",
19
+ "react"
20
+ ],
21
+ "type": "module",
22
+ "main": "./dist/wysio-react.js",
23
+ "module": "./dist/wysio-react.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/wysio-react.js"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "CHANGELOG.md"
35
+ ],
36
+ "sideEffects": false,
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "scripts": {
41
+ "build": "vite build && tsc -p tsconfig.build.json",
42
+ "test": "vitest run",
43
+ "test:watch": "vitest",
44
+ "typecheck": "tsc --noEmit"
45
+ },
46
+ "peerDependencies": {
47
+ "react": "^18.0.0 || ^19.0.0",
48
+ "react-dom": "^18.0.0 || ^19.0.0"
49
+ },
50
+ "dependencies": {
51
+ "wysio": "^0.2.0-alpha.7"
52
+ },
53
+ "devDependencies": {
54
+ "@testing-library/react": "^16.3.3",
55
+ "@types/react": "^19.3.3",
56
+ "@types/react-dom": "^19.3.0",
57
+ "react": "^19.3.1",
58
+ "react-dom": "^19.3.1"
59
+ }
60
+ }