autumnnote-vue 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/README.md CHANGED
@@ -29,7 +29,7 @@ import 'autumnnote/dist/autumnnote.css';
29
29
  const editorRef = ref(null);
30
30
 
31
31
  function handleSave() {
32
- const html = editorRef.value.editor.value.getHTML();
32
+ const html = editorRef.value.editor?.getHTML();
33
33
  console.log(html);
34
34
  }
35
35
  </script>
@@ -55,17 +55,17 @@ function handleSave() {
55
55
 
56
56
  ## Accessing the editor instance
57
57
 
58
- The component uses `defineExpose({ editor })` where `editor` is a Vue `ref<Context | null>`. Access the instance via:
58
+ The component exposes the current `Context` as `editor`. Vue automatically unwraps the internal shallow ref on the public component instance:
59
59
 
60
60
  ```js
61
- editorRef.value.editor.value.getHTML();
62
- editorRef.value.editor.value.setHTML('<p>Hello <strong>world</strong></p>');
63
- editorRef.value.editor.value.getMarkdown();
64
- editorRef.value.editor.value.invoke('toolbar.rebuild');
65
- editorRef.value.editor.value.on('change', (html) => console.log(html));
61
+ editorRef.value.editor?.getHTML();
62
+ editorRef.value.editor?.setHTML('<p>Hello <strong>world</strong></p>');
63
+ editorRef.value.editor?.getMarkdown();
64
+ editorRef.value.editor?.invoke('toolbar.rebuild');
65
+ editorRef.value.editor?.on('change', (html) => console.log(html));
66
66
  ```
67
67
 
68
- The `editor` ref is `null` before mount — use it inside `onMounted` or after the component is mounted.
68
+ The exposed `editor` property is `null` before mount — use it inside `onMounted` or after the component is mounted.
69
69
 
70
70
  ## Reinitialising with new options
71
71
 
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),s=require("autumnnote"),u={__name:"AutumnNote",props:{options:{type:Object,default:()=>({})}},setup(r,{expose:l}){const c=r,n=e.ref(null),t=e.ref(null);return e.onMounted(()=>{t.value=s.create(n.value,c.options)}),e.onUnmounted(()=>{var o;(o=t.value)==null||o.destroy(),t.value=null}),l({editor:t}),(o,a)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"container",ref:n},null,512))}};exports.AutumnNoteEditor=u;exports.default=u;
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("vue"),l=require("autumnnote");l=s(l);var u={__name:`AutumnNote`,props:{options:{type:Object,default:()=>({})},modelValue:{type:String,default:void 0},defaultValue:{type:String,default:``}},emits:[`update:modelValue`,`change`],setup(e,{expose:t,emit:n}){let r=e,i=n,a=(0,c.ref)(null),o=(0,c.shallowRef)(null),s=null,u=e=>{if(r.options.onChange?.(e),i(`change`,e),e===s){s=null;return}i(`update:modelValue`,e)};return(0,c.onMounted)(()=>{o.value=l.default.create(a.value,{...r.options,onChange:u});let e=r.modelValue??r.defaultValue;e&&(r.modelValue!=null&&(s=r.modelValue),o.value.setHTML(e),o.value.clearHistory())}),(0,c.watch)(()=>r.options,e=>o.value?.updateOptions({...e,onChange:u}),{deep:!0}),(0,c.watch)(()=>r.modelValue,e=>{e==null||!o.value||o.value.getHTML()===e||(s=e,o.value.setHTML(e),o.value.clearHistory())}),(0,c.onUnmounted)(()=>{o.value?.destroy(),o.value=null}),t({editor:o}),(e,t)=>((0,c.openBlock)(),(0,c.createElementBlock)(`div`,{ref_key:`container`,ref:a},null,512))}};exports.AutumnNoteEditor=u,exports.default=u;
package/dist/index.js CHANGED
@@ -1,24 +1,50 @@
1
- import { ref as n, onMounted as a, onUnmounted as c, openBlock as s, createElementBlock as p } from "vue";
2
- import m from "autumnnote";
3
- const _ = {
4
- __name: "AutumnNote",
5
- props: {
6
- options: { type: Object, default: () => ({}) }
7
- },
8
- setup(r, { expose: u }) {
9
- const l = r, o = n(null), e = n(null);
10
- return a(() => {
11
- e.value = m.create(o.value, l.options);
12
- }), c(() => {
13
- var t;
14
- (t = e.value) == null || t.destroy(), e.value = null;
15
- }), u({ editor: e }), (t, i) => (s(), p("div", {
16
- ref_key: "container",
17
- ref: o
18
- }, null, 512));
19
- }
20
- };
21
- export {
22
- _ as AutumnNoteEditor,
23
- _ as default
1
+ import { createElementBlock as e, onMounted as t, onUnmounted as n, openBlock as r, ref as i, shallowRef as a, watch as o } from "vue";
2
+ import s from "autumnnote";
3
+ //#region src/AutumnNote.vue
4
+ var c = {
5
+ __name: "AutumnNote",
6
+ props: {
7
+ options: {
8
+ type: Object,
9
+ default: () => ({})
10
+ },
11
+ modelValue: {
12
+ type: String,
13
+ default: void 0
14
+ },
15
+ defaultValue: {
16
+ type: String,
17
+ default: ""
18
+ }
19
+ },
20
+ emits: ["update:modelValue", "change"],
21
+ setup(c, { expose: l, emit: u }) {
22
+ let d = c, f = u, p = i(null), m = a(null), h = null, g = (e) => {
23
+ if (d.options.onChange?.(e), f("change", e), e === h) {
24
+ h = null;
25
+ return;
26
+ }
27
+ f("update:modelValue", e);
28
+ };
29
+ return t(() => {
30
+ m.value = s.create(p.value, {
31
+ ...d.options,
32
+ onChange: g
33
+ });
34
+ let e = d.modelValue ?? d.defaultValue;
35
+ e && (d.modelValue != null && (h = d.modelValue), m.value.setHTML(e), m.value.clearHistory());
36
+ }), o(() => d.options, (e) => m.value?.updateOptions({
37
+ ...e,
38
+ onChange: g
39
+ }), { deep: !0 }), o(() => d.modelValue, (e) => {
40
+ e == null || !m.value || m.value.getHTML() === e || (h = e, m.value.setHTML(e), m.value.clearHistory());
41
+ }), n(() => {
42
+ m.value?.destroy(), m.value = null;
43
+ }), l({ editor: m }), (t, n) => (r(), e("div", {
44
+ ref_key: "container",
45
+ ref: p
46
+ }, null, 512));
47
+ }
24
48
  };
49
+ //#endregion
50
+ export { c as AutumnNoteEditor, c as default };
package/index.d.ts CHANGED
@@ -1,25 +1,29 @@
1
1
  import type { Context, AsnOptions } from 'autumnnote';
2
- import type { DefineComponent, Ref } from 'vue';
2
+ import type { DefineComponent } from 'vue';
3
3
 
4
4
  export interface AutumnNoteEditorProps {
5
5
  /** Editor configuration object. All AsnOptions fields are accepted. */
6
6
  options?: AsnOptions;
7
+ /** Controlled HTML value used by v-model. */
8
+ modelValue?: string;
9
+ /** Initial HTML value for uncontrolled usage. */
10
+ defaultValue?: string;
7
11
  }
8
12
 
9
13
  export interface AutumnNoteEditorExpose {
10
- /** Reactive ref holding the AutumnNote Context instance (available after mount). */
11
- editor: Ref<Context | null>;
14
+ /** AutumnNote Context instance, or null before the component mounts. */
15
+ editor: Context | null;
12
16
  }
13
17
 
14
18
  /**
15
19
  * Vue 3 component that mounts an AutumnNote WYSIWYG editor.
16
20
  *
17
- * Access the editor instance via the exposed `editor` ref:
21
+ * Access the editor instance via the exposed `editor` property:
18
22
  * ```vue
19
23
  * <AutumnNoteEditor ref="editorRef" :options="{ height: 300 }" />
20
- * // editorRef.value.editor.value?.getHTML()
24
+ * // editorRef.value.editor?.getHTML()
21
25
  * ```
22
- * Use `v-if` to force remount on options change.
26
+ * Supports `v-model` and applies runtime-safe option changes without remounting.
23
27
  */
24
28
  declare const AutumnNoteEditor: DefineComponent<
25
29
  AutumnNoteEditorProps,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autumnnote-vue",
3
- "version": "1.14.0",
3
+ "version": "1.16.0",
4
4
  "description": "Official Vue 3 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": [
@@ -54,15 +54,17 @@
54
54
  "license": "MIT",
55
55
  "peerDependencies": {
56
56
  "autumnnote": ">=1.4.0",
57
- "vue": "^3.0.0"
57
+ "vue": ">=3.4.0"
58
58
  },
59
59
  "devDependencies": {
60
- "@vitejs/plugin-vue": "^5.0.0",
61
- "vite": "^6.0.0",
60
+ "@vitejs/plugin-vue": "^6.0.8",
61
+ "vite": "^8.1.5",
62
62
  "vue": "^3.4.0",
63
- "autumnnote": "1.14.0"
63
+ "autumnnote": "1.16.0"
64
64
  },
65
65
  "scripts": {
66
- "build": "vite build"
66
+ "build": "vite build",
67
+ "test": "vitest run",
68
+ "typecheck": "tsc --project tsconfig.test.json"
67
69
  }
68
70
  }