autumnnote-react 1.14.0 → 1.16.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.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("react/jsx-runtime"),e=require("react"),d=require("autumnnote"),n=e.forwardRef(function({options:o={},className:c,style:s},i){const r=e.useRef(null),t=e.useRef(null);return e.useEffect(()=>(t.current=d.create(r.current,o),()=>{var u;(u=t.current)==null||u.destroy(),t.current=null}),[]),e.useImperativeHandle(i,()=>t.current,[]),l.jsx("div",{ref:r,className:c,style:s})});exports.AutumnNoteEditor=n;exports.default=n;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react"),l=require("autumnnote");l=s(l,1);let u=require("react/jsx-runtime");var d=typeof window>`u`?c.useEffect:c.useLayoutEffect,f=(0,c.forwardRef)(function({options:e={},value:t,defaultValue:n,onChange:r,className:i,style:a},o){let s=(0,c.useRef)(null),f=(0,c.useRef)(null),p=(0,c.useRef)({onChange:r,optionOnChange:e.onChange}),m=(0,c.useRef)(null),h=(0,c.useRef)(null);return p.current={onChange:r,optionOnChange:e.onChange},h.current||=e=>{if(p.current.optionOnChange?.(e),e===m.current){m.current=null;return}p.current.onChange?.(e)},d(()=>{f.current=l.default.create(s.current,{...e,onChange:h.current});let r=t??n;return r!=null&&(t!=null&&(m.current=t),f.current.setHTML(r),f.current.clearHistory()),()=>{f.current?.destroy(),f.current=null}},[]),(0,c.useEffect)(()=>{f.current?.updateOptions({...e,onChange:h.current})},[e]),(0,c.useEffect)(()=>{let e=f.current;t==null||!e||e.getHTML()===t||(m.current=t,e.setHTML(t),e.clearHistory())},[t]),(0,c.useImperativeHandle)(o,()=>f.current,[]),(0,u.jsx)(`div`,{ref:s,className:i,style:a})});exports.AutumnNoteEditor=f,exports.default=f;
package/dist/index.js CHANGED
@@ -1,14 +1,43 @@
1
- import { jsx as i } from "react/jsx-runtime";
2
- import { forwardRef as m, useRef as n, useEffect as s, useImperativeHandle as d } from "react";
3
- import l from "autumnnote";
4
- const E = m(function({ options: u = {}, className: o, style: f }, c) {
5
- const t = n(null), r = n(null);
6
- return s(() => (r.current = l.create(t.current, u), () => {
7
- var e;
8
- (e = r.current) == null || e.destroy(), r.current = null;
9
- }), []), d(c, () => r.current, []), /* @__PURE__ */ i("div", { ref: t, className: o, style: f });
1
+ import { forwardRef as e, useEffect as t, useImperativeHandle as n, useLayoutEffect as r, useRef as i } from "react";
2
+ import a from "autumnnote";
3
+ import { jsx as o } from "react/jsx-runtime";
4
+ //#region src/index.jsx
5
+ var s = typeof window > "u" ? t : r, c = e(function({ options: e = {}, value: r, defaultValue: c, onChange: l, className: u, style: d }, f) {
6
+ let p = i(null), m = i(null), h = i({
7
+ onChange: l,
8
+ optionOnChange: e.onChange
9
+ }), g = i(null), _ = i(null);
10
+ return h.current = {
11
+ onChange: l,
12
+ optionOnChange: e.onChange
13
+ }, _.current ||= (e) => {
14
+ if (h.current.optionOnChange?.(e), e === g.current) {
15
+ g.current = null;
16
+ return;
17
+ }
18
+ h.current.onChange?.(e);
19
+ }, s(() => {
20
+ m.current = a.create(p.current, {
21
+ ...e,
22
+ onChange: _.current
23
+ });
24
+ let t = r ?? c;
25
+ return t != null && (r != null && (g.current = r), m.current.setHTML(t), m.current.clearHistory()), () => {
26
+ m.current?.destroy(), m.current = null;
27
+ };
28
+ }, []), t(() => {
29
+ m.current?.updateOptions({
30
+ ...e,
31
+ onChange: _.current
32
+ });
33
+ }, [e]), t(() => {
34
+ let e = m.current;
35
+ r == null || !e || e.getHTML() === r || (g.current = r, e.setHTML(r), e.clearHistory());
36
+ }, [r]), n(f, () => m.current, []), /* @__PURE__ */ o("div", {
37
+ ref: p,
38
+ className: u,
39
+ style: d
40
+ });
10
41
  });
11
- export {
12
- E as AutumnNoteEditor,
13
- E as default
14
- };
42
+ //#endregion
43
+ export { c as AutumnNoteEditor, c as default };
package/index.d.ts CHANGED
@@ -4,6 +4,12 @@ import type { CSSProperties, ForwardRefExoticComponent, RefAttributes } from 're
4
4
  export interface AutumnNoteEditorProps {
5
5
  /** Editor configuration object. All AsnOptions fields are accepted. */
6
6
  options?: AsnOptions;
7
+ /** Controlled HTML value. */
8
+ value?: string;
9
+ /** Initial HTML value for uncontrolled usage. */
10
+ defaultValue?: string;
11
+ /** Called when editor HTML changes. */
12
+ onChange?: (html: string) => void;
7
13
  /** CSS class applied to the container <div>. */
8
14
  className?: string;
9
15
  /** Inline styles applied to the container <div>. */
@@ -19,7 +25,7 @@ export interface AutumnNoteEditorProps {
19
25
  * <AutumnNoteEditor ref={editorRef} options={{ height: 300 }} />
20
26
  * editorRef.current?.getHTML();
21
27
  * ```
22
- * To reinitialise with new options, change the `key` prop.
28
+ * Runtime-safe option changes are applied without remounting.
23
29
  */
24
30
  declare const AutumnNoteEditor: ForwardRefExoticComponent<
25
31
  AutumnNoteEditorProps & RefAttributes<Context>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autumnnote-react",
3
- "version": "1.14.0",
3
+ "version": "1.16.0",
4
4
  "description": "Official React wrapper for Autumn Note — zero-dependency WYSIWYG editor. Mount the editor with a single component and access the full Context API via ref.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -8,9 +8,9 @@
8
8
  "types": "index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
+ "types": "./index.d.ts",
11
12
  "import": "./dist/index.js",
12
- "require": "./dist/index.cjs",
13
- "types": "./index.d.ts"
13
+ "require": "./dist/index.cjs"
14
14
  }
15
15
  },
16
16
  "files": [
@@ -53,17 +53,20 @@
53
53
  "license": "MIT",
54
54
  "peerDependencies": {
55
55
  "autumnnote": ">=1.4.0",
56
- "react": ">=16.8.0",
57
- "react-dom": ">=16.8.0"
56
+ "react": ">=18.0.0",
57
+ "react-dom": ">=18.0.0"
58
58
  },
59
59
  "devDependencies": {
60
- "@vitejs/plugin-react": "^4.3.0",
60
+ "@types/react": "^18.3.0",
61
+ "@vitejs/plugin-react": "^6.0.3",
61
62
  "react": "^18.0.0",
62
63
  "react-dom": "^18.0.0",
63
- "vite": "^6.0.0",
64
- "autumnnote": "1.14.0"
64
+ "vite": "^8.1.5",
65
+ "autumnnote": "1.16.0"
65
66
  },
66
67
  "scripts": {
67
- "build": "vite build"
68
+ "build": "vite build",
69
+ "test": "vitest run",
70
+ "typecheck": "tsc --project tsconfig.test.json"
68
71
  }
69
72
  }