@bitrix24/b24ui-nuxt 2.1.11 → 2.1.12
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-AI.md +1 -1
- package/dist/meta.d.mts +98220 -780
- package/dist/meta.mjs +98220 -780
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/components/ContextMenu.d.vue.ts +6 -2
- package/dist/runtime/components/ContextMenu.vue.d.ts +6 -2
- package/dist/runtime/components/ContextMenuContent.vue +2 -2
- package/dist/runtime/components/DropdownMenu.d.vue.ts +6 -2
- package/dist/runtime/components/DropdownMenu.vue.d.ts +6 -2
- package/dist/runtime/components/DropdownMenuContent.vue +2 -2
- package/dist/runtime/components/Editor.d.vue.ts +87 -0
- package/dist/runtime/components/Editor.vue +185 -0
- package/dist/runtime/components/Editor.vue.d.ts +87 -0
- package/dist/runtime/components/EditorDragHandle.d.vue.ts +60 -0
- package/dist/runtime/components/EditorDragHandle.vue +128 -0
- package/dist/runtime/components/EditorDragHandle.vue.d.ts +60 -0
- package/dist/runtime/components/EditorEmojiMenu.d.vue.ts +35 -0
- package/dist/runtime/components/EditorEmojiMenu.vue +70 -0
- package/dist/runtime/components/EditorEmojiMenu.vue.d.ts +35 -0
- package/dist/runtime/components/EditorMentionMenu.d.vue.ts +39 -0
- package/dist/runtime/components/EditorMentionMenu.vue +74 -0
- package/dist/runtime/components/EditorMentionMenu.vue.d.ts +39 -0
- package/dist/runtime/components/EditorSuggestionMenu.d.vue.ts +52 -0
- package/dist/runtime/components/EditorSuggestionMenu.vue +79 -0
- package/dist/runtime/components/EditorSuggestionMenu.vue.d.ts +52 -0
- package/dist/runtime/components/EditorToolbar.d.vue.ts +80 -0
- package/dist/runtime/components/EditorToolbar.vue +239 -0
- package/dist/runtime/components/EditorToolbar.vue.d.ts +80 -0
- package/dist/runtime/components/FormField.vue +2 -2
- package/dist/runtime/components/InputMenu.d.vue.ts +2 -0
- package/dist/runtime/components/InputMenu.vue +14 -1
- package/dist/runtime/components/InputMenu.vue.d.ts +2 -0
- package/dist/runtime/components/Pagination.d.vue.ts +0 -1
- package/dist/runtime/components/Pagination.vue.d.ts +0 -1
- package/dist/runtime/components/Select.d.vue.ts +2 -0
- package/dist/runtime/components/Select.vue +14 -1
- package/dist/runtime/components/Select.vue.d.ts +2 -0
- package/dist/runtime/components/SelectMenu.d.vue.ts +2 -0
- package/dist/runtime/components/SelectMenu.vue +14 -1
- package/dist/runtime/components/SelectMenu.vue.d.ts +2 -0
- package/dist/runtime/components/color-mode/ColorModeSelect.vue +1 -0
- package/dist/runtime/components/locale/LocaleSelect.vue +1 -0
- package/dist/runtime/components/prose/Accordion.vue +1 -1
- package/dist/runtime/composables/defineShortcuts.d.ts +1 -0
- package/dist/runtime/composables/defineShortcuts.js +60 -13
- package/dist/runtime/composables/useEditorMenu.d.ts +64 -0
- package/dist/runtime/composables/useEditorMenu.js +448 -0
- package/dist/runtime/dictionary/icons.d.ts +1 -0
- package/dist/runtime/dictionary/icons.js +5 -3
- package/dist/runtime/types/editor.d.ts +69 -0
- package/dist/runtime/types/editor.js +0 -0
- package/dist/runtime/types/index.d.ts +7 -0
- package/dist/runtime/types/index.js +7 -0
- package/dist/runtime/utils/editor.d.ts +69 -0
- package/dist/runtime/utils/editor.js +364 -0
- package/dist/runtime/vue/components/color-mode/ColorModeSelect.vue +1 -0
- package/dist/shared/{b24ui-nuxt.Dh5A-7HA.mjs → b24ui-nuxt.C8MyFqPm.mjs} +183 -1
- package/dist/unplugin.mjs +1 -1
- package/dist/vite.mjs +1 -1
- package/package.json +16 -3
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Editor } from '@tiptap/vue-3';
|
|
2
|
+
import type { Strategy, Placement, OffsetOptions, FlipOptions, ShiftOptions, SizeOptions, AutoPlacementOptions, HideOptions, InlineOptions } from '@floating-ui/dom';
|
|
3
|
+
export interface FloatingUIOptions {
|
|
4
|
+
strategy?: Strategy;
|
|
5
|
+
placement?: Placement;
|
|
6
|
+
offset?: OffsetOptions | boolean;
|
|
7
|
+
flip?: FlipOptions | boolean;
|
|
8
|
+
shift?: ShiftOptions | boolean;
|
|
9
|
+
size?: SizeOptions | boolean;
|
|
10
|
+
autoPlacement?: AutoPlacementOptions | boolean;
|
|
11
|
+
hide?: HideOptions | boolean;
|
|
12
|
+
inline?: InlineOptions | boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface EditorHandler {
|
|
15
|
+
canExecute: (editor: Editor, cmd?: any) => boolean;
|
|
16
|
+
execute: (editor: Editor, cmd?: any) => any;
|
|
17
|
+
isActive: (editor: Editor, cmd?: any) => boolean;
|
|
18
|
+
isDisabled?: (editor: Editor, cmd?: any) => boolean;
|
|
19
|
+
}
|
|
20
|
+
export type EditorCustomHandlers = Record<string, EditorHandler>;
|
|
21
|
+
export type EditorHandlers<H extends EditorCustomHandlers = EditorCustomHandlers> = {
|
|
22
|
+
mark: EditorHandler;
|
|
23
|
+
textAlign: EditorHandler;
|
|
24
|
+
heading: EditorHandler;
|
|
25
|
+
link: EditorHandler;
|
|
26
|
+
image: EditorHandler;
|
|
27
|
+
blockquote: EditorHandler;
|
|
28
|
+
bulletList: EditorHandler;
|
|
29
|
+
orderedList: EditorHandler;
|
|
30
|
+
codeBlock: EditorHandler;
|
|
31
|
+
horizontalRule: EditorHandler;
|
|
32
|
+
paragraph: EditorHandler;
|
|
33
|
+
undo: EditorHandler;
|
|
34
|
+
redo: EditorHandler;
|
|
35
|
+
clearFormatting: EditorHandler;
|
|
36
|
+
duplicate: EditorHandler;
|
|
37
|
+
delete: EditorHandler;
|
|
38
|
+
moveUp: EditorHandler;
|
|
39
|
+
moveDown: EditorHandler;
|
|
40
|
+
suggestion: EditorHandler;
|
|
41
|
+
mention: EditorHandler;
|
|
42
|
+
emoji: EditorHandler;
|
|
43
|
+
} & H;
|
|
44
|
+
export type EditorItem<H extends EditorCustomHandlers = EditorCustomHandlers> = {
|
|
45
|
+
kind: 'mark';
|
|
46
|
+
mark: 'bold' | 'italic' | 'strike' | 'code' | 'underline';
|
|
47
|
+
} | {
|
|
48
|
+
kind: 'textAlign';
|
|
49
|
+
align: 'left' | 'center' | 'right' | 'justify';
|
|
50
|
+
} | {
|
|
51
|
+
kind: 'heading';
|
|
52
|
+
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
53
|
+
} | {
|
|
54
|
+
kind: 'link';
|
|
55
|
+
href?: string;
|
|
56
|
+
} | {
|
|
57
|
+
kind: 'image';
|
|
58
|
+
src?: string;
|
|
59
|
+
} | {
|
|
60
|
+
kind: 'duplicate' | 'delete' | 'moveUp' | 'moveDown';
|
|
61
|
+
pos: number;
|
|
62
|
+
} | {
|
|
63
|
+
kind: 'clearFormatting' | 'suggestion';
|
|
64
|
+
pos?: number;
|
|
65
|
+
} | {
|
|
66
|
+
kind: 'blockquote' | 'bulletList' | 'orderedList' | 'codeBlock' | 'horizontalRule' | 'paragraph' | 'undo' | 'redo' | 'mention' | 'emoji';
|
|
67
|
+
} | {
|
|
68
|
+
kind: keyof H;
|
|
69
|
+
};
|
|
File without changes
|
|
@@ -29,6 +29,12 @@ export * from '../components/DashboardSearch.vue';
|
|
|
29
29
|
export * from '../components/DashboardSearchButton.vue';
|
|
30
30
|
export * from '../components/DescriptionList.vue';
|
|
31
31
|
export * from '../components/DropdownMenu.vue';
|
|
32
|
+
export * from '../components/Editor.vue';
|
|
33
|
+
export * from '../components/EditorDragHandle.vue';
|
|
34
|
+
export * from '../components/EditorEmojiMenu.vue';
|
|
35
|
+
export * from '../components/EditorMentionMenu.vue';
|
|
36
|
+
export * from '../components/EditorSuggestionMenu.vue';
|
|
37
|
+
export * from '../components/EditorToolbar.vue';
|
|
32
38
|
export * from '../components/Empty.vue';
|
|
33
39
|
export * from '../components/Error.vue';
|
|
34
40
|
export * from '../components/FieldGroup.vue';
|
|
@@ -92,6 +98,7 @@ export * from '../components/color-mode/ColorModeSelect.vue';
|
|
|
92
98
|
export * from '../components/color-mode/ColorModeSwitch.vue';
|
|
93
99
|
export * from '../components/locale/LocaleSelect.vue';
|
|
94
100
|
export * from './content';
|
|
101
|
+
export * from './editor';
|
|
95
102
|
export * from './form';
|
|
96
103
|
export * from './icons';
|
|
97
104
|
export * from './locale';
|
|
@@ -29,6 +29,12 @@ export * from "../components/DashboardSearch.vue";
|
|
|
29
29
|
export * from "../components/DashboardSearchButton.vue";
|
|
30
30
|
export * from "../components/DescriptionList.vue";
|
|
31
31
|
export * from "../components/DropdownMenu.vue";
|
|
32
|
+
export * from "../components/Editor.vue";
|
|
33
|
+
export * from "../components/EditorDragHandle.vue";
|
|
34
|
+
export * from "../components/EditorEmojiMenu.vue";
|
|
35
|
+
export * from "../components/EditorMentionMenu.vue";
|
|
36
|
+
export * from "../components/EditorSuggestionMenu.vue";
|
|
37
|
+
export * from "../components/EditorToolbar.vue";
|
|
32
38
|
export * from "../components/Empty.vue";
|
|
33
39
|
export * from "../components/Error.vue";
|
|
34
40
|
export * from "../components/FieldGroup.vue";
|
|
@@ -92,6 +98,7 @@ export * from "../components/color-mode/ColorModeSelect.vue";
|
|
|
92
98
|
export * from "../components/color-mode/ColorModeSwitch.vue";
|
|
93
99
|
export * from "../components/locale/LocaleSelect.vue";
|
|
94
100
|
export * from "./content.js";
|
|
101
|
+
export * from "./editor.js";
|
|
95
102
|
export * from "./form.js";
|
|
96
103
|
export * from "./icons.js";
|
|
97
104
|
export * from "./locale.js";
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Editor, Mark } from '@tiptap/vue-3';
|
|
2
|
+
import type { Middleware } from '@floating-ui/dom';
|
|
3
|
+
import type { EditorHandlers, EditorCustomHandlers, EditorItem, FloatingUIOptions } from '../types/editor';
|
|
4
|
+
export declare function isMarkInSchema(mark: string | Mark, editor: Editor | null): boolean;
|
|
5
|
+
export declare function isNodeTypeSelected(editor: Editor | null, nodeTypes: string[]): boolean;
|
|
6
|
+
export declare function isExtensionAvailable(editor: Editor | null, extensionName: string): boolean;
|
|
7
|
+
export declare function createToggleHandler(name: string): {
|
|
8
|
+
canExecute: (editor: Editor) => any;
|
|
9
|
+
execute: (editor: Editor) => any;
|
|
10
|
+
isActive: (editor: Editor) => boolean;
|
|
11
|
+
isDisabled: (editor: Editor) => boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare function createSetHandler(name: string): {
|
|
14
|
+
canExecute: (editor: Editor) => any;
|
|
15
|
+
execute: (editor: Editor) => any;
|
|
16
|
+
isActive: (editor: Editor) => boolean;
|
|
17
|
+
isDisabled: (editor: Editor) => boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare function createSimpleHandler(name: string): {
|
|
20
|
+
canExecute: (editor: Editor) => any;
|
|
21
|
+
execute: (editor: Editor) => any;
|
|
22
|
+
isActive: () => boolean;
|
|
23
|
+
isDisabled: undefined;
|
|
24
|
+
};
|
|
25
|
+
export declare function createMarkHandler(): {
|
|
26
|
+
canExecute: (editor: Editor, cmd: any) => any;
|
|
27
|
+
execute: (editor: Editor, cmd: any) => import("@tiptap/core").ChainedCommands;
|
|
28
|
+
isActive: (editor: Editor, cmd: any) => boolean;
|
|
29
|
+
isDisabled: (editor: Editor, cmd: any) => boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare function createTextAlignHandler(): {
|
|
32
|
+
canExecute: (editor: Editor, cmd: any) => any;
|
|
33
|
+
execute: (editor: Editor, cmd: any) => any;
|
|
34
|
+
isActive: (editor: Editor, cmd: any) => boolean;
|
|
35
|
+
isDisabled: (editor: Editor) => boolean;
|
|
36
|
+
};
|
|
37
|
+
export declare function createHeadingHandler(): {
|
|
38
|
+
canExecute: (editor: Editor, cmd: any) => any;
|
|
39
|
+
execute: (editor: Editor, cmd: any) => import("@tiptap/core").ChainedCommands;
|
|
40
|
+
isActive: (editor: Editor, cmd: any) => boolean;
|
|
41
|
+
isDisabled: (editor: Editor) => boolean;
|
|
42
|
+
};
|
|
43
|
+
export declare function createLinkHandler(): {
|
|
44
|
+
canExecute: (editor: Editor) => any;
|
|
45
|
+
execute: (editor: Editor, cmd: any) => import("@tiptap/core").ChainedCommands;
|
|
46
|
+
isActive: (editor: Editor) => boolean;
|
|
47
|
+
isDisabled: (editor: Editor) => boolean;
|
|
48
|
+
};
|
|
49
|
+
export declare function createImageHandler(): {
|
|
50
|
+
canExecute: (editor: Editor) => any;
|
|
51
|
+
execute: (editor: Editor, cmd: any) => import("@tiptap/core").ChainedCommands;
|
|
52
|
+
isActive: (editor: Editor) => boolean;
|
|
53
|
+
isDisabled: (editor: Editor) => boolean;
|
|
54
|
+
};
|
|
55
|
+
export declare function createListHandler(listType: 'bulletList' | 'orderedList'): {
|
|
56
|
+
canExecute: (editor: Editor) => any;
|
|
57
|
+
execute: (editor: Editor) => any;
|
|
58
|
+
isActive: (editor: Editor) => boolean;
|
|
59
|
+
isDisabled: (editor: Editor) => boolean;
|
|
60
|
+
};
|
|
61
|
+
export declare function createMoveHandler(direction: 'up' | 'down'): {
|
|
62
|
+
canExecute: (editor: Editor, cmd: any) => boolean;
|
|
63
|
+
execute: (editor: Editor, cmd: any) => import("@tiptap/core").ChainedCommands;
|
|
64
|
+
isActive: () => boolean;
|
|
65
|
+
isDisabled: undefined;
|
|
66
|
+
};
|
|
67
|
+
export declare function createHandlers(): EditorHandlers;
|
|
68
|
+
export declare function mapEditorItems(editor: Editor, items: (Partial<EditorItem> & Record<string, any>)[] | (Partial<EditorItem> & Record<string, any>)[][], customHandlers?: EditorCustomHandlers): any[] | any[][];
|
|
69
|
+
export declare function buildFloatingUIMiddleware(options: FloatingUIOptions): Middleware[];
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { flip, shift, offset, size, autoPlacement, hide, inline } from "@floating-ui/dom";
|
|
2
|
+
import { isArrayOfArray } from "./index.js";
|
|
3
|
+
export function isMarkInSchema(mark, editor) {
|
|
4
|
+
if (!editor?.schema) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
const markName = typeof mark === "string" ? mark : mark.name;
|
|
8
|
+
return editor.schema.spec.marks.get(markName) !== void 0;
|
|
9
|
+
}
|
|
10
|
+
export function isNodeTypeSelected(editor, nodeTypes) {
|
|
11
|
+
if (!editor) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const { selection } = editor.state;
|
|
15
|
+
const { $from, to } = selection;
|
|
16
|
+
return nodeTypes.some((nodeType) => {
|
|
17
|
+
return editor.state.doc.nodesBetween($from.pos, to, (node) => {
|
|
18
|
+
return node.type.name === nodeType;
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export function isExtensionAvailable(editor, extensionName) {
|
|
23
|
+
if (!editor) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return editor.extensionManager.extensions.some((ext) => ext.name === extensionName);
|
|
27
|
+
}
|
|
28
|
+
export function createToggleHandler(name) {
|
|
29
|
+
const fnName = `toggle${name.charAt(0).toUpperCase()}${name.slice(1)}`;
|
|
30
|
+
return {
|
|
31
|
+
canExecute: (editor) => editor.can()[fnName](),
|
|
32
|
+
execute: (editor) => editor.chain().focus()[fnName](),
|
|
33
|
+
isActive: (editor) => editor.isActive(name),
|
|
34
|
+
isDisabled: (editor) => isNodeTypeSelected(editor, ["image"]) || editor.isActive("code")
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function createSetHandler(name) {
|
|
38
|
+
const fnName = `set${name.charAt(0).toUpperCase()}${name.slice(1)}`;
|
|
39
|
+
return {
|
|
40
|
+
canExecute: (editor) => editor.can()[fnName](),
|
|
41
|
+
execute: (editor) => editor.chain().focus()[fnName](),
|
|
42
|
+
isActive: (editor) => editor.isActive(name),
|
|
43
|
+
isDisabled: (editor) => isNodeTypeSelected(editor, ["image"]) || editor.isActive("code")
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function createSimpleHandler(name) {
|
|
47
|
+
return {
|
|
48
|
+
canExecute: (editor) => editor.can()[name](),
|
|
49
|
+
execute: (editor) => editor.chain()[name](),
|
|
50
|
+
isActive: () => false,
|
|
51
|
+
isDisabled: void 0
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function createMarkHandler() {
|
|
55
|
+
return {
|
|
56
|
+
canExecute: (editor, cmd) => editor.can().toggleMark(cmd.mark),
|
|
57
|
+
execute: (editor, cmd) => editor.chain().focus().toggleMark(cmd.mark),
|
|
58
|
+
isActive: (editor, cmd) => editor.isActive(cmd.mark),
|
|
59
|
+
isDisabled: (editor, cmd) => !isMarkInSchema(cmd.mark, editor) || isNodeTypeSelected(editor, ["image"])
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export function createTextAlignHandler() {
|
|
63
|
+
return {
|
|
64
|
+
canExecute: (editor, cmd) => editor.can().setTextAlign(cmd.align),
|
|
65
|
+
execute: (editor, cmd) => editor.chain().focus().setTextAlign(cmd.align),
|
|
66
|
+
isActive: (editor, cmd) => editor.isActive({ textAlign: cmd.align }),
|
|
67
|
+
isDisabled: (editor) => !isExtensionAvailable(editor, "textAlign") || isNodeTypeSelected(editor, ["image", "horizontalRule"])
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function createHeadingHandler() {
|
|
71
|
+
return {
|
|
72
|
+
canExecute: (editor, cmd) => editor.can().toggleHeading({ level: cmd.level }),
|
|
73
|
+
execute: (editor, cmd) => editor.chain().focus().toggleHeading({ level: cmd.level }),
|
|
74
|
+
isActive: (editor, cmd) => editor.isActive("heading", { level: cmd.level }),
|
|
75
|
+
isDisabled: (editor) => isNodeTypeSelected(editor, ["image"]) || editor.isActive("code")
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export function createLinkHandler() {
|
|
79
|
+
return {
|
|
80
|
+
canExecute: (editor) => {
|
|
81
|
+
return editor.can().setLink({ href: "" }) || editor.can().unsetLink();
|
|
82
|
+
},
|
|
83
|
+
execute: (editor, cmd) => {
|
|
84
|
+
const chain = editor.chain();
|
|
85
|
+
const previousUrl = editor.getAttributes("link").href;
|
|
86
|
+
if (previousUrl) {
|
|
87
|
+
return chain.focus().unsetLink();
|
|
88
|
+
}
|
|
89
|
+
if (cmd?.href) {
|
|
90
|
+
return chain.focus().setLink({ href: cmd.href });
|
|
91
|
+
}
|
|
92
|
+
const href = prompt("Enter the URL:");
|
|
93
|
+
if (href) {
|
|
94
|
+
return chain.focus().setLink({ href });
|
|
95
|
+
}
|
|
96
|
+
return chain;
|
|
97
|
+
},
|
|
98
|
+
isActive: (editor) => editor.isActive("link"),
|
|
99
|
+
isDisabled: (editor) => {
|
|
100
|
+
if (!isExtensionAvailable(editor, "link") || isNodeTypeSelected(editor, ["image"])) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
const { selection } = editor.state;
|
|
104
|
+
return selection.empty && !editor.isActive("link");
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
export function createImageHandler() {
|
|
109
|
+
return {
|
|
110
|
+
canExecute: (editor) => {
|
|
111
|
+
return editor.can().setImage({ src: "" });
|
|
112
|
+
},
|
|
113
|
+
execute: (editor, cmd) => {
|
|
114
|
+
const chain = editor.chain().focus();
|
|
115
|
+
if (cmd?.src) {
|
|
116
|
+
return chain.setImage({ src: cmd.src });
|
|
117
|
+
}
|
|
118
|
+
const src = prompt("Enter the image URL:");
|
|
119
|
+
if (src) {
|
|
120
|
+
return chain.setImage({ src });
|
|
121
|
+
}
|
|
122
|
+
return chain;
|
|
123
|
+
},
|
|
124
|
+
isActive: (editor) => editor.isActive("image"),
|
|
125
|
+
isDisabled: (editor) => {
|
|
126
|
+
return !isExtensionAvailable(editor, "image");
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
export function createListHandler(listType) {
|
|
131
|
+
const fnName = listType === "bulletList" ? "toggleBulletList" : "toggleOrderedList";
|
|
132
|
+
return {
|
|
133
|
+
canExecute: (editor) => {
|
|
134
|
+
return editor.can()[fnName]() || editor.isActive("bulletList") || editor.isActive("orderedList");
|
|
135
|
+
},
|
|
136
|
+
execute: (editor) => {
|
|
137
|
+
const { state } = editor;
|
|
138
|
+
const { selection } = state;
|
|
139
|
+
let chain = editor.chain().focus();
|
|
140
|
+
if (selection.node) {
|
|
141
|
+
const node = selection.node;
|
|
142
|
+
const firstChild = node.firstChild?.firstChild;
|
|
143
|
+
const lastChild = node.lastChild?.lastChild;
|
|
144
|
+
const from = firstChild ? selection.from + firstChild.nodeSize : selection.from + 1;
|
|
145
|
+
const to = lastChild ? selection.to - lastChild.nodeSize : selection.to - 1;
|
|
146
|
+
chain = chain.setTextSelection({ from, to }).clearNodes();
|
|
147
|
+
}
|
|
148
|
+
if (editor.isActive(listType)) {
|
|
149
|
+
return chain.liftListItem("listItem").lift("bulletList").lift("orderedList").selectTextblockEnd();
|
|
150
|
+
}
|
|
151
|
+
return chain[fnName]().selectTextblockEnd();
|
|
152
|
+
},
|
|
153
|
+
isActive: (editor) => editor.isActive(listType),
|
|
154
|
+
isDisabled: (editor) => isNodeTypeSelected(editor, ["image"]) || editor.isActive("code")
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
export function createMoveHandler(direction) {
|
|
158
|
+
return {
|
|
159
|
+
canExecute: (editor, cmd) => {
|
|
160
|
+
if (cmd?.pos == null) return false;
|
|
161
|
+
const node = editor.state.doc.nodeAt(cmd.pos);
|
|
162
|
+
if (!node) return false;
|
|
163
|
+
const $pos = editor.state.doc.resolve(cmd.pos);
|
|
164
|
+
const parent = $pos.parent;
|
|
165
|
+
const index = $pos.index();
|
|
166
|
+
return direction === "up" ? index > 0 : index < parent.childCount - 1;
|
|
167
|
+
},
|
|
168
|
+
execute: (editor, cmd) => {
|
|
169
|
+
if (cmd?.pos == null) return editor.chain();
|
|
170
|
+
const node = editor.state.doc.nodeAt(cmd.pos);
|
|
171
|
+
if (!node) return editor.chain();
|
|
172
|
+
const $pos = editor.state.doc.resolve(cmd.pos);
|
|
173
|
+
const parent = $pos.parent;
|
|
174
|
+
const index = $pos.index();
|
|
175
|
+
if (direction === "up" && index > 0) {
|
|
176
|
+
const prevNode = parent.child(index - 1);
|
|
177
|
+
const targetPos = cmd.pos - prevNode.nodeSize;
|
|
178
|
+
return editor.chain().focus().deleteRange({ from: cmd.pos, to: cmd.pos + node.nodeSize }).insertContentAt(targetPos, node.toJSON());
|
|
179
|
+
}
|
|
180
|
+
if (direction === "down" && index < parent.childCount - 1) {
|
|
181
|
+
const nextNode = parent.child(index + 1);
|
|
182
|
+
const targetPos = cmd.pos + nextNode.nodeSize;
|
|
183
|
+
return editor.chain().focus().deleteRange({ from: cmd.pos, to: cmd.pos + node.nodeSize }).insertContentAt(targetPos, node.toJSON());
|
|
184
|
+
}
|
|
185
|
+
return editor.chain();
|
|
186
|
+
},
|
|
187
|
+
isActive: () => false,
|
|
188
|
+
isDisabled: void 0
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
export function createHandlers() {
|
|
192
|
+
return {
|
|
193
|
+
mark: createMarkHandler(),
|
|
194
|
+
textAlign: createTextAlignHandler(),
|
|
195
|
+
heading: createHeadingHandler(),
|
|
196
|
+
link: createLinkHandler(),
|
|
197
|
+
image: createImageHandler(),
|
|
198
|
+
blockquote: createToggleHandler("blockquote"),
|
|
199
|
+
bulletList: createListHandler("bulletList"),
|
|
200
|
+
orderedList: createListHandler("orderedList"),
|
|
201
|
+
codeBlock: createToggleHandler("codeBlock"),
|
|
202
|
+
horizontalRule: createSetHandler("horizontalRule"),
|
|
203
|
+
paragraph: createSetHandler("paragraph"),
|
|
204
|
+
undo: createSimpleHandler("undo"),
|
|
205
|
+
redo: createSimpleHandler("redo"),
|
|
206
|
+
clearFormatting: {
|
|
207
|
+
canExecute: (editor, cmd) => {
|
|
208
|
+
if (cmd?.pos != null) {
|
|
209
|
+
const node = editor.state.doc.nodeAt(cmd.pos);
|
|
210
|
+
return !!node;
|
|
211
|
+
}
|
|
212
|
+
return editor.can().clearNodes() || editor.can().unsetAllMarks();
|
|
213
|
+
},
|
|
214
|
+
execute: (editor, cmd) => {
|
|
215
|
+
if (cmd?.pos != null) {
|
|
216
|
+
const node = editor.state.doc.nodeAt(cmd.pos);
|
|
217
|
+
if (!node) return editor.chain();
|
|
218
|
+
const from = cmd.pos + 1;
|
|
219
|
+
const to = cmd.pos + node.nodeSize - 1;
|
|
220
|
+
return editor.chain().focus().setTextSelection({ from, to }).clearNodes().unsetAllMarks();
|
|
221
|
+
}
|
|
222
|
+
return editor.chain().focus().clearNodes().unsetAllMarks();
|
|
223
|
+
},
|
|
224
|
+
isActive: () => false,
|
|
225
|
+
isDisabled: void 0
|
|
226
|
+
},
|
|
227
|
+
duplicate: {
|
|
228
|
+
canExecute: (editor, cmd) => {
|
|
229
|
+
if (cmd?.pos == null) return false;
|
|
230
|
+
const node = editor.state.doc.nodeAt(cmd.pos);
|
|
231
|
+
return !!node;
|
|
232
|
+
},
|
|
233
|
+
execute: (editor, cmd) => {
|
|
234
|
+
if (cmd?.pos == null) return editor.chain();
|
|
235
|
+
const node = editor.state.doc.nodeAt(cmd.pos);
|
|
236
|
+
if (!node) return editor.chain();
|
|
237
|
+
return editor.chain().focus().insertContentAt(cmd.pos + node.nodeSize, node.toJSON());
|
|
238
|
+
},
|
|
239
|
+
isActive: () => false,
|
|
240
|
+
isDisabled: void 0
|
|
241
|
+
},
|
|
242
|
+
delete: {
|
|
243
|
+
canExecute: (editor, cmd) => {
|
|
244
|
+
if (cmd?.pos == null) return false;
|
|
245
|
+
const node = editor.state.doc.nodeAt(cmd.pos);
|
|
246
|
+
return !!node;
|
|
247
|
+
},
|
|
248
|
+
execute: (editor, cmd) => {
|
|
249
|
+
if (cmd?.pos == null) return editor.chain();
|
|
250
|
+
const node = editor.state.doc.nodeAt(cmd.pos);
|
|
251
|
+
if (!node) return editor.chain();
|
|
252
|
+
return editor.chain().focus().deleteRange({ from: cmd.pos, to: cmd.pos + node.nodeSize });
|
|
253
|
+
},
|
|
254
|
+
isActive: () => false,
|
|
255
|
+
isDisabled: void 0
|
|
256
|
+
},
|
|
257
|
+
moveUp: createMoveHandler("up"),
|
|
258
|
+
moveDown: createMoveHandler("down"),
|
|
259
|
+
suggestion: {
|
|
260
|
+
canExecute: () => true,
|
|
261
|
+
execute: (editor, cmd) => {
|
|
262
|
+
const { state } = editor;
|
|
263
|
+
const { selection } = state;
|
|
264
|
+
const { $from } = selection;
|
|
265
|
+
if (cmd?.pos !== void 0) {
|
|
266
|
+
const node = state.doc.nodeAt(cmd.pos);
|
|
267
|
+
if (node) {
|
|
268
|
+
const insertPos2 = cmd.pos + node.nodeSize;
|
|
269
|
+
return editor.chain().focus().insertContentAt(insertPos2, { type: "paragraph", content: [{ type: "text", text: "/" }] });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const currentNode = $from.node($from.depth);
|
|
273
|
+
const currentNodePos = $from.before($from.depth);
|
|
274
|
+
const insertPos = currentNodePos + currentNode.nodeSize;
|
|
275
|
+
return editor.chain().focus().insertContentAt(insertPos, { type: "paragraph", content: [{ type: "text", text: "/" }] });
|
|
276
|
+
},
|
|
277
|
+
isActive: () => false,
|
|
278
|
+
isDisabled: void 0
|
|
279
|
+
},
|
|
280
|
+
mention: {
|
|
281
|
+
canExecute: () => true,
|
|
282
|
+
execute: (editor) => {
|
|
283
|
+
const { state } = editor;
|
|
284
|
+
const { selection } = state;
|
|
285
|
+
const { $from } = selection;
|
|
286
|
+
const textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - 1), $from.parentOffset, void 0, " ");
|
|
287
|
+
const needsSpace = textBefore && textBefore !== " ";
|
|
288
|
+
return editor.chain().focus().insertContent(needsSpace ? " @" : "@");
|
|
289
|
+
},
|
|
290
|
+
isActive: () => false,
|
|
291
|
+
isDisabled: void 0
|
|
292
|
+
},
|
|
293
|
+
emoji: {
|
|
294
|
+
canExecute: () => true,
|
|
295
|
+
execute: (editor) => {
|
|
296
|
+
const { state } = editor;
|
|
297
|
+
const { selection } = state;
|
|
298
|
+
const { $from } = selection;
|
|
299
|
+
const textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - 1), $from.parentOffset, void 0, " ");
|
|
300
|
+
const needsSpace = textBefore && textBefore !== " ";
|
|
301
|
+
return editor.chain().focus().insertContent(needsSpace ? " :" : ":");
|
|
302
|
+
},
|
|
303
|
+
isActive: () => false,
|
|
304
|
+
isDisabled: void 0
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
export function mapEditorItems(editor, items, customHandlers) {
|
|
309
|
+
const handlers = { ...createHandlers(), ...customHandlers };
|
|
310
|
+
if (isArrayOfArray(items)) {
|
|
311
|
+
return items.map(
|
|
312
|
+
(group) => mapEditorItems(editor, group, customHandlers)
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
return items.filter(Boolean).map((item) => {
|
|
316
|
+
if ("type" in item) {
|
|
317
|
+
return item;
|
|
318
|
+
}
|
|
319
|
+
const { kind, children, ...rest } = item;
|
|
320
|
+
const processedChildren = children?.length ? mapEditorItems(editor, children, customHandlers) : void 0;
|
|
321
|
+
if (kind) {
|
|
322
|
+
const handler = handlers[kind];
|
|
323
|
+
if (!handler) {
|
|
324
|
+
return {
|
|
325
|
+
...rest,
|
|
326
|
+
children: processedChildren
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
...rest,
|
|
331
|
+
children: processedChildren,
|
|
332
|
+
disabled: handler.isDisabled?.(editor, item) || !handler.canExecute(editor, item),
|
|
333
|
+
active: handler.isActive(editor, item),
|
|
334
|
+
onSelect: () => handler.execute(editor, item).run()
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
return { ...rest, children: processedChildren };
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
export function buildFloatingUIMiddleware(options) {
|
|
341
|
+
const middleware = [];
|
|
342
|
+
if (options.offset) {
|
|
343
|
+
middleware.push(offset(typeof options.offset !== "boolean" ? options.offset : void 0));
|
|
344
|
+
}
|
|
345
|
+
if (options.flip) {
|
|
346
|
+
middleware.push(flip(typeof options.flip !== "boolean" ? options.flip : void 0));
|
|
347
|
+
}
|
|
348
|
+
if (options.shift) {
|
|
349
|
+
middleware.push(shift(typeof options.shift !== "boolean" ? options.shift : void 0));
|
|
350
|
+
}
|
|
351
|
+
if (options.size) {
|
|
352
|
+
middleware.push(size(typeof options.size !== "boolean" ? options.size : void 0));
|
|
353
|
+
}
|
|
354
|
+
if (options.autoPlacement) {
|
|
355
|
+
middleware.push(autoPlacement(typeof options.autoPlacement !== "boolean" ? options.autoPlacement : void 0));
|
|
356
|
+
}
|
|
357
|
+
if (options.hide) {
|
|
358
|
+
middleware.push(hide(typeof options.hide !== "boolean" ? options.hide : void 0));
|
|
359
|
+
}
|
|
360
|
+
if (options.inline) {
|
|
361
|
+
middleware.push(inline(typeof options.inline !== "boolean" ? options.inline : void 0));
|
|
362
|
+
}
|
|
363
|
+
return middleware;
|
|
364
|
+
}
|
|
@@ -33,6 +33,7 @@ const props = defineProps({
|
|
|
33
33
|
labelKey: { type: null, required: false },
|
|
34
34
|
descriptionKey: { type: null, required: false },
|
|
35
35
|
defaultValue: { type: null, required: false },
|
|
36
|
+
modelModifiers: { type: Object, required: false },
|
|
36
37
|
multiple: { type: Boolean, required: false },
|
|
37
38
|
highlight: { type: Boolean, required: false },
|
|
38
39
|
createItem: { type: [Boolean, String, Object], required: false },
|