@domternal/vue 0.14.0 → 1.0.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 +44 -6
- package/dist/index.d.ts +24 -7
- package/dist/index.js +198 -292
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
package/README.md
CHANGED
|
@@ -19,8 +19,8 @@ editor is created in `onMounted`. Requires Vue 3.3+ and the Composition API.
|
|
|
19
19
|
pnpm add @domternal/vue @domternal/core @domternal/theme vue
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
`vue` (>=3.3) and `@domternal/core` are peer dependencies. `@domternal/theme`
|
|
23
|
-
editor styles.
|
|
22
|
+
`vue` (>=3.3) and `@domternal/core` (>=1.0.0) are peer dependencies. `@domternal/theme`
|
|
23
|
+
supplies the editor styles.
|
|
24
24
|
|
|
25
25
|
## Usage
|
|
26
26
|
|
|
@@ -68,14 +68,52 @@ const { htmlContent, isEmpty } = useEditorState(editor);
|
|
|
68
68
|
|
|
69
69
|
<template>
|
|
70
70
|
<DomternalToolbar />
|
|
71
|
-
<div
|
|
71
|
+
<div class="dm-editor">
|
|
72
|
+
<div ref="editorRef" />
|
|
73
|
+
</div>
|
|
72
74
|
</template>
|
|
73
75
|
```
|
|
74
76
|
|
|
75
|
-
`useEditor` returns `editor` (a `ShallowRef<Editor | null>`, null until mounted
|
|
76
|
-
(bind to the mount element). `useEditorState`
|
|
77
|
-
`isFocused`, and `isEditable`, or pass a
|
|
77
|
+
`useEditor` returns `editor` (a `ShallowRef<Editor | null>`, null until mounted unless
|
|
78
|
+
`immediatelyRender` is set) and `editorRef` (bind to the mount element). `useEditorState`
|
|
79
|
+
returns `htmlContent`, `jsonContent`, `isEmpty`, `isFocused`, and `isEditable`, or pass a
|
|
80
|
+
selector for a granular `ComputedRef`:
|
|
78
81
|
|
|
79
82
|
```ts
|
|
80
83
|
const isBold = useEditorState(editor, (ed) => ed.isActive('bold'));
|
|
81
84
|
```
|
|
85
|
+
|
|
86
|
+
## Options
|
|
87
|
+
|
|
88
|
+
`useEditor(options)` takes:
|
|
89
|
+
|
|
90
|
+
| Option | Type | Default | Description |
|
|
91
|
+
|---|---|---|---|
|
|
92
|
+
| `extensions` | `AnyExtension[]` | `[]` | Extensions to load on top of `DEFAULT_EXTENSIONS`. |
|
|
93
|
+
| `history` | `boolean` | `true` | Whether the built-in History extension is loaded. Turn it off when an extension brings its own undo. |
|
|
94
|
+
| `content` | `Content` | `''` | Initial content, HTML string or JSON. |
|
|
95
|
+
| `editable` | `boolean` | `true` | Whether the editor is editable. |
|
|
96
|
+
| `preset` | `'classic' \| 'notion'` | `'classic'` | `'notion'` paints `dm-notion-mode` on the `.dm-editor` host and switches preset-aware extensions to their Notion behavior. Create-time only. |
|
|
97
|
+
| `autofocus` | `FocusPosition` | `false` | Where to place the caret on mount. |
|
|
98
|
+
| `outputFormat` | `'html' \| 'json'` | `'html'` | Format used when comparing incoming content against the document. |
|
|
99
|
+
| `immediatelyRender` | `boolean` | `false` | Create the editor during setup instead of in `onMounted`. Not SSR-safe. |
|
|
100
|
+
|
|
101
|
+
`onCreate`, `onUpdate`, `onSelectionChange`, `onFocus`, `onBlur`, and `onDestroy` callbacks are
|
|
102
|
+
accepted alongside them. `<Domternal>` and `<DomternalEditor>` take the same options as props,
|
|
103
|
+
except `history`: their prop lists are fixed, so `:history="false"` never reaches the composable.
|
|
104
|
+
Call `useEditor({ history: false })` with `provideEditor` instead.
|
|
105
|
+
|
|
106
|
+
## Exports
|
|
107
|
+
|
|
108
|
+
- **Composables**: `useEditor`, `useEditorState` (full state or a granular selector),
|
|
109
|
+
`useCurrentEditor`, `provideEditor`, `useNotionColorPicker`
|
|
110
|
+
- **Constants**: `DEFAULT_EXTENSIONS`, `EDITOR_KEY`
|
|
111
|
+
- **Composable component**: `Domternal` with `Domternal.Toolbar`, `Domternal.Content`,
|
|
112
|
+
`Domternal.BubbleMenu`, `Domternal.FloatingMenu`, `Domternal.EmojiPicker`, `Domternal.Loading`
|
|
113
|
+
- **Components**: `DomternalEditor` (supports `v-model`), `EditorContent`, `DomternalToolbar`,
|
|
114
|
+
`DomternalBubbleMenu`, `DomternalFloatingMenu`, `DomternalEmojiPicker`,
|
|
115
|
+
`DomternalNotionColorPicker`
|
|
116
|
+
- **Node views**: `VueNodeViewRenderer`, `NodeViewWrapper`, `NodeViewContent`, `useVueNodeView`
|
|
117
|
+
- **Core re-exports**: the `Editor` class plus the `Content`, `AnyExtension`, `FocusPosition`,
|
|
118
|
+
and `JSONContent` types
|
|
119
|
+
- **SSR helpers** (re-exported from core, work without an editor instance): `generateHTML`, `generateJSON`, `generateText`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as vue from 'vue';
|
|
2
2
|
import { ShallowRef, Ref, ComputedRef, InjectionKey, Component, PropType, VNode, AppContext } from 'vue';
|
|
3
|
-
import { AnyExtension, Content, FocusPosition, Editor, JSONContent, IconSet, ToolbarLayoutEntry, BubbleMenuOptions, FloatingMenuOptions, FloatingMenuItemsOverride, FloatingMenuKeymap } from '@domternal/core';
|
|
3
|
+
import { AnyExtension, Content, EditorPreset, FocusPosition, Editor, JSONContent, IconSet, ToolbarLayoutEntry, BubbleMenuOptions, BubbleContexts, FloatingMenuOptions, FloatingMenuItemsOverride, FloatingMenuKeymap } from '@domternal/core';
|
|
4
4
|
export { AnyExtension, Content, Editor, FocusPosition, GenerateHTMLOptions, GenerateJSONOptions, GenerateTextOptions, JSONContent, generateHTML, generateJSON, generateText } from '@domternal/core';
|
|
5
5
|
import * as prosemirror_state from 'prosemirror-state';
|
|
6
6
|
import * as prosemirror_view from 'prosemirror-view';
|
|
@@ -19,6 +19,12 @@ interface UseEditorOptions {
|
|
|
19
19
|
content?: Content;
|
|
20
20
|
/** Whether the editor is editable. @default true */
|
|
21
21
|
editable?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Editing experience preset. `'notion'` paints `dm-notion-mode` on the
|
|
24
|
+
* `.dm-editor` wrapper and switches preset-aware extensions to their
|
|
25
|
+
* Notion behavior, replacing the hand-written class. Create-time only.
|
|
26
|
+
*/
|
|
27
|
+
preset?: EditorPreset;
|
|
22
28
|
/** Where to autofocus on mount. @default false */
|
|
23
29
|
autofocus?: FocusPosition;
|
|
24
30
|
/** Output format for content comparison. @default 'html' */
|
|
@@ -169,6 +175,8 @@ interface DomternalEditorProps {
|
|
|
169
175
|
extensions?: AnyExtension[];
|
|
170
176
|
content?: Content;
|
|
171
177
|
editable?: boolean;
|
|
178
|
+
/** Editing experience preset; 'notion' paints dm-notion-mode on the wrapper. Create-time only. */
|
|
179
|
+
preset?: EditorPreset;
|
|
172
180
|
autofocus?: FocusPosition;
|
|
173
181
|
immediatelyRender?: boolean;
|
|
174
182
|
outputFormat?: 'html' | 'json';
|
|
@@ -231,6 +239,10 @@ declare const DomternalEditor: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
231
239
|
type: BooleanConstructor;
|
|
232
240
|
default: boolean;
|
|
233
241
|
};
|
|
242
|
+
preset: {
|
|
243
|
+
type: PropType<EditorPreset>;
|
|
244
|
+
default: undefined;
|
|
245
|
+
};
|
|
234
246
|
autofocus: {
|
|
235
247
|
type: PropType<FocusPosition>;
|
|
236
248
|
default: boolean;
|
|
@@ -304,6 +316,10 @@ declare const DomternalEditor: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
304
316
|
type: BooleanConstructor;
|
|
305
317
|
default: boolean;
|
|
306
318
|
};
|
|
319
|
+
preset: {
|
|
320
|
+
type: PropType<EditorPreset>;
|
|
321
|
+
default: undefined;
|
|
322
|
+
};
|
|
307
323
|
autofocus: {
|
|
308
324
|
type: PropType<FocusPosition>;
|
|
309
325
|
default: boolean;
|
|
@@ -376,11 +392,12 @@ declare const DomternalEditor: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
376
392
|
onDestroy: () => void;
|
|
377
393
|
content: Content;
|
|
378
394
|
class: string;
|
|
379
|
-
|
|
395
|
+
preset: EditorPreset;
|
|
380
396
|
onSelectionChange: (props: {
|
|
381
397
|
editor: Editor;
|
|
382
398
|
}) => void;
|
|
383
399
|
extensions: AnyExtension[];
|
|
400
|
+
editable: boolean;
|
|
384
401
|
autofocus: FocusPosition;
|
|
385
402
|
outputFormat: "html" | "json";
|
|
386
403
|
immediatelyRender: boolean;
|
|
@@ -475,7 +492,7 @@ interface DomternalBubbleMenuProps {
|
|
|
475
492
|
offset?: number;
|
|
476
493
|
updateDelay?: number;
|
|
477
494
|
items?: string[];
|
|
478
|
-
contexts?:
|
|
495
|
+
contexts?: BubbleContexts;
|
|
479
496
|
/** Custom icon overrides. Falls back to default Phosphor icons for unmapped keys. */
|
|
480
497
|
icons?: IconSet;
|
|
481
498
|
}
|
|
@@ -505,7 +522,7 @@ declare const DomternalBubbleMenu: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
505
522
|
default: undefined;
|
|
506
523
|
};
|
|
507
524
|
contexts: {
|
|
508
|
-
type: PropType<
|
|
525
|
+
type: PropType<BubbleContexts>;
|
|
509
526
|
default: undefined;
|
|
510
527
|
};
|
|
511
528
|
icons: {
|
|
@@ -540,7 +557,7 @@ declare const DomternalBubbleMenu: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
540
557
|
default: undefined;
|
|
541
558
|
};
|
|
542
559
|
contexts: {
|
|
543
|
-
type: PropType<
|
|
560
|
+
type: PropType<BubbleContexts>;
|
|
544
561
|
default: undefined;
|
|
545
562
|
};
|
|
546
563
|
icons: {
|
|
@@ -558,10 +575,10 @@ declare const DomternalBubbleMenu: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
|
558
575
|
to: number;
|
|
559
576
|
}) => boolean;
|
|
560
577
|
offset: number;
|
|
561
|
-
items: string[];
|
|
562
578
|
updateDelay: number;
|
|
579
|
+
contexts: BubbleContexts;
|
|
580
|
+
items: string[];
|
|
563
581
|
icons: IconSet;
|
|
564
|
-
contexts: Record<string, true | string[] | null>;
|
|
565
582
|
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
566
583
|
|
|
567
584
|
interface DomternalFloatingMenuProps {
|