@svadmin/editor 0.1.0 → 0.2.4
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/{src → dist}/components/BubbleMenu.svelte +11 -20
- package/dist/components/BubbleMenu.svelte.d.ts +7 -0
- package/{src → dist}/components/ColorPicker.svelte +1 -1
- package/dist/components/ColorPicker.svelte.d.ts +7 -0
- package/{src → dist}/components/Editor.svelte +4 -4
- package/dist/components/Editor.svelte.d.ts +42 -0
- package/{src → dist}/components/FloatingMenu.svelte +14 -16
- package/dist/components/FloatingMenu.svelte.d.ts +7 -0
- package/{src → dist}/components/ImageUpload.svelte +12 -2
- package/dist/components/ImageUpload.svelte.d.ts +9 -0
- package/{src → dist}/components/LinkPopover.svelte +1 -1
- package/dist/components/LinkPopover.svelte.d.ts +8 -0
- package/{src → dist}/components/TableMenu.svelte +1 -1
- package/dist/components/TableMenu.svelte.d.ts +8 -0
- package/{src → dist}/components/Toolbar.svelte +3 -5
- package/dist/components/Toolbar.svelte.d.ts +9 -0
- package/dist/components/ToolbarButton.svelte.d.ts +11 -0
- package/dist/components/ToolbarGroup.svelte.d.ts +7 -0
- package/{src → dist}/components/ToolbarSelect.svelte +1 -1
- package/dist/components/ToolbarSelect.svelte.d.ts +12 -0
- package/dist/editor.svelte.d.ts +36 -0
- package/dist/editor.svelte.js +54 -0
- package/dist/extensions/index.d.ts +53 -0
- package/dist/extensions/index.js +156 -0
- package/dist/extensions/slash-command.d.ts +35 -0
- package/dist/extensions/slash-command.js +127 -0
- package/dist/index.d.ts +29 -0
- package/{src/index.ts → dist/index.js} +2 -34
- package/package.json +68 -38
- package/src/editor.svelte.ts +0 -99
- package/src/extensions/index.ts +0 -211
- package/src/extensions/slash-command.ts +0 -150
- /package/{src → dist}/components/ToolbarButton.svelte +0 -0
- /package/{src → dist}/components/ToolbarGroup.svelte +0 -0
- /package/{src → dist}/styles/editor.css +0 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @svadmin/editor — Extension presets
|
|
3
|
+
*
|
|
4
|
+
* Pre-configured extension bundles for different use cases.
|
|
5
|
+
* Users can pick a preset or compose their own extension array.
|
|
6
|
+
*/
|
|
7
|
+
import StarterKit from '@tiptap/starter-kit';
|
|
8
|
+
import Underline from '@tiptap/extension-underline';
|
|
9
|
+
import TextAlign from '@tiptap/extension-text-align';
|
|
10
|
+
import { TextStyle } from '@tiptap/extension-text-style';
|
|
11
|
+
import Color from '@tiptap/extension-color';
|
|
12
|
+
import Highlight from '@tiptap/extension-highlight';
|
|
13
|
+
import Link from '@tiptap/extension-link';
|
|
14
|
+
import Image from '@tiptap/extension-image';
|
|
15
|
+
import Placeholder from '@tiptap/extension-placeholder';
|
|
16
|
+
import CharacterCount from '@tiptap/extension-character-count';
|
|
17
|
+
import Typography from '@tiptap/extension-typography';
|
|
18
|
+
import Subscript from '@tiptap/extension-subscript';
|
|
19
|
+
import Superscript from '@tiptap/extension-superscript';
|
|
20
|
+
import TaskList from '@tiptap/extension-task-list';
|
|
21
|
+
import TaskItem from '@tiptap/extension-task-item';
|
|
22
|
+
import { Table } from '@tiptap/extension-table';
|
|
23
|
+
import TableRow from '@tiptap/extension-table-row';
|
|
24
|
+
import TableHeader from '@tiptap/extension-table-header';
|
|
25
|
+
import TableCell from '@tiptap/extension-table-cell';
|
|
26
|
+
import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight';
|
|
27
|
+
/**
|
|
28
|
+
* Full preset: all extensions enabled.
|
|
29
|
+
* Suitable for content management, article editing, knowledge bases.
|
|
30
|
+
*/
|
|
31
|
+
export function fullPreset(options = {}) {
|
|
32
|
+
const extensions = [
|
|
33
|
+
StarterKit.configure({
|
|
34
|
+
// Disable default code block in favor of CodeBlockLowlight
|
|
35
|
+
codeBlock: options.codeHighlight ? false : undefined,
|
|
36
|
+
}),
|
|
37
|
+
Underline,
|
|
38
|
+
TextStyle,
|
|
39
|
+
Color,
|
|
40
|
+
Highlight.configure({ multicolor: true }),
|
|
41
|
+
TextAlign.configure({
|
|
42
|
+
types: ['heading', 'paragraph'],
|
|
43
|
+
}),
|
|
44
|
+
Link.configure({
|
|
45
|
+
openOnClick: false,
|
|
46
|
+
autolink: true,
|
|
47
|
+
HTMLAttributes: {
|
|
48
|
+
rel: 'noopener noreferrer',
|
|
49
|
+
target: '_blank',
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
Image.configure({
|
|
53
|
+
allowBase64: true,
|
|
54
|
+
HTMLAttributes: {
|
|
55
|
+
loading: 'lazy',
|
|
56
|
+
},
|
|
57
|
+
}),
|
|
58
|
+
Subscript,
|
|
59
|
+
Superscript,
|
|
60
|
+
TaskList,
|
|
61
|
+
TaskItem.configure({ nested: true }),
|
|
62
|
+
Table.configure({
|
|
63
|
+
resizable: true,
|
|
64
|
+
HTMLAttributes: {
|
|
65
|
+
class: 'svadmin-table',
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
TableRow,
|
|
69
|
+
TableHeader,
|
|
70
|
+
TableCell,
|
|
71
|
+
Typography,
|
|
72
|
+
CharacterCount.configure({
|
|
73
|
+
limit: options.maxLength || undefined,
|
|
74
|
+
}),
|
|
75
|
+
];
|
|
76
|
+
if (options.placeholder) {
|
|
77
|
+
extensions.push(Placeholder.configure({
|
|
78
|
+
placeholder: options.placeholder,
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
if (options.codeHighlight && options.lowlight) {
|
|
82
|
+
extensions.push(CodeBlockLowlight.configure({
|
|
83
|
+
lowlight: options.lowlight,
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
return extensions;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Minimal preset: basic text formatting only.
|
|
90
|
+
* Suitable for comments, short descriptions, inline editing.
|
|
91
|
+
*/
|
|
92
|
+
export function minimalPreset(options = {}) {
|
|
93
|
+
const extensions = [
|
|
94
|
+
StarterKit.configure({
|
|
95
|
+
heading: { levels: [1, 2, 3] },
|
|
96
|
+
codeBlock: false,
|
|
97
|
+
}),
|
|
98
|
+
Underline,
|
|
99
|
+
Link.configure({
|
|
100
|
+
openOnClick: false,
|
|
101
|
+
autolink: true,
|
|
102
|
+
}),
|
|
103
|
+
CharacterCount.configure({
|
|
104
|
+
limit: options.maxLength || undefined,
|
|
105
|
+
}),
|
|
106
|
+
];
|
|
107
|
+
if (options.placeholder) {
|
|
108
|
+
extensions.push(Placeholder.configure({
|
|
109
|
+
placeholder: options.placeholder,
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
return extensions;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Prose preset: optimized for long-form writing.
|
|
116
|
+
* Includes typography, highlights, but no tables.
|
|
117
|
+
*/
|
|
118
|
+
export function prosePreset(options = {}) {
|
|
119
|
+
const extensions = [
|
|
120
|
+
StarterKit.configure({
|
|
121
|
+
codeBlock: options.codeHighlight ? false : undefined,
|
|
122
|
+
}),
|
|
123
|
+
Underline,
|
|
124
|
+
TextStyle,
|
|
125
|
+
Color,
|
|
126
|
+
Highlight.configure({ multicolor: true }),
|
|
127
|
+
TextAlign.configure({
|
|
128
|
+
types: ['heading', 'paragraph'],
|
|
129
|
+
}),
|
|
130
|
+
Link.configure({
|
|
131
|
+
openOnClick: false,
|
|
132
|
+
autolink: true,
|
|
133
|
+
}),
|
|
134
|
+
Image.configure({ allowBase64: true }),
|
|
135
|
+
TaskList,
|
|
136
|
+
TaskItem.configure({ nested: true }),
|
|
137
|
+
Typography,
|
|
138
|
+
CharacterCount.configure({
|
|
139
|
+
limit: options.maxLength || undefined,
|
|
140
|
+
}),
|
|
141
|
+
];
|
|
142
|
+
if (options.placeholder) {
|
|
143
|
+
extensions.push(Placeholder.configure({
|
|
144
|
+
placeholder: options.placeholder,
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
147
|
+
if (options.codeHighlight && options.lowlight) {
|
|
148
|
+
extensions.push(CodeBlockLowlight.configure({
|
|
149
|
+
lowlight: options.lowlight,
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
return extensions;
|
|
153
|
+
}
|
|
154
|
+
export {
|
|
155
|
+
// Re-export individual extensions for custom composition
|
|
156
|
+
StarterKit, Underline, TextAlign, TextStyle, Color, Highlight, Link, Image, Placeholder, CharacterCount, Typography, Subscript, Superscript, TaskList, TaskItem, Table, TableRow, TableHeader, TableCell, CodeBlockLowlight, };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slash command extension for Tiptap
|
|
3
|
+
*
|
|
4
|
+
* Type "/" on an empty line to open a command menu.
|
|
5
|
+
* Uses @tiptap/suggestion under the hood.
|
|
6
|
+
*/
|
|
7
|
+
import { Extension } from '@tiptap/core';
|
|
8
|
+
import { type SuggestionOptions } from '@tiptap/suggestion';
|
|
9
|
+
import type { Editor } from '@tiptap/core';
|
|
10
|
+
export interface SlashCommandItem {
|
|
11
|
+
title: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
icon?: string;
|
|
14
|
+
category?: string;
|
|
15
|
+
command: (editor: Editor) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Default slash command items
|
|
19
|
+
*/
|
|
20
|
+
export declare function getDefaultSlashItems(): SlashCommandItem[];
|
|
21
|
+
export interface SlashCommandOptions {
|
|
22
|
+
items?: SlashCommandItem[];
|
|
23
|
+
/** Custom rendering handlers — follows @tiptap/suggestion render interface */
|
|
24
|
+
render?: SuggestionOptions['render'];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create a slash command extension.
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { createSlashCommand } from '@svadmin/editor/extensions/slash-command';
|
|
32
|
+
* const SlashCommand = createSlashCommand();
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function createSlashCommand(options?: SlashCommandOptions): Extension;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slash command extension for Tiptap
|
|
3
|
+
*
|
|
4
|
+
* Type "/" on an empty line to open a command menu.
|
|
5
|
+
* Uses @tiptap/suggestion under the hood.
|
|
6
|
+
*/
|
|
7
|
+
import { Extension } from '@tiptap/core';
|
|
8
|
+
import Suggestion, {} from '@tiptap/suggestion';
|
|
9
|
+
import { t } from '@svadmin/core';
|
|
10
|
+
/**
|
|
11
|
+
* Default slash command items
|
|
12
|
+
*/
|
|
13
|
+
export function getDefaultSlashItems() {
|
|
14
|
+
return [
|
|
15
|
+
{
|
|
16
|
+
title: t('editor.h1'),
|
|
17
|
+
description: 'Large section heading',
|
|
18
|
+
category: 'Headings',
|
|
19
|
+
command: (editor) => editor.chain().focus().toggleHeading({ level: 1 }).run(),
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
title: t('editor.h2'),
|
|
23
|
+
description: 'Medium section heading',
|
|
24
|
+
category: 'Headings',
|
|
25
|
+
command: (editor) => editor.chain().focus().toggleHeading({ level: 2 }).run(),
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
title: t('editor.h3'),
|
|
29
|
+
description: 'Small section heading',
|
|
30
|
+
category: 'Headings',
|
|
31
|
+
command: (editor) => editor.chain().focus().toggleHeading({ level: 3 }).run(),
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
title: t('editor.bulletList'),
|
|
35
|
+
description: 'Create a bulleted list',
|
|
36
|
+
category: 'Lists',
|
|
37
|
+
command: (editor) => editor.chain().focus().toggleBulletList().run(),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
title: t('editor.orderedList'),
|
|
41
|
+
description: 'Create a numbered list',
|
|
42
|
+
category: 'Lists',
|
|
43
|
+
command: (editor) => editor.chain().focus().toggleOrderedList().run(),
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
title: t('editor.taskList'),
|
|
47
|
+
description: 'Create a task checklist',
|
|
48
|
+
category: 'Lists',
|
|
49
|
+
command: (editor) => editor.chain().focus().toggleTaskList().run(),
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
title: t('editor.blockquote'),
|
|
53
|
+
description: 'Insert a blockquote',
|
|
54
|
+
category: 'Blocks',
|
|
55
|
+
command: (editor) => editor.chain().focus().toggleBlockquote().run(),
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
title: t('editor.codeBlock'),
|
|
59
|
+
description: 'Insert a code block',
|
|
60
|
+
category: 'Blocks',
|
|
61
|
+
command: (editor) => editor.chain().focus().toggleCodeBlock().run(),
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
title: 'Divider',
|
|
65
|
+
description: 'Insert a horizontal rule',
|
|
66
|
+
category: 'Blocks',
|
|
67
|
+
command: (editor) => editor.chain().focus().setHorizontalRule().run(),
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
title: t('editor.table'),
|
|
71
|
+
description: 'Insert a 3×3 table',
|
|
72
|
+
category: 'Media',
|
|
73
|
+
command: (editor) => editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run(),
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
title: 'Image',
|
|
77
|
+
description: 'Insert image from URL',
|
|
78
|
+
category: 'Media',
|
|
79
|
+
command: (editor) => {
|
|
80
|
+
const url = window.prompt('Enter image URL:');
|
|
81
|
+
if (url) {
|
|
82
|
+
editor.chain().focus().setImage({ src: url }).run();
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create a slash command extension.
|
|
90
|
+
*
|
|
91
|
+
* Usage:
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { createSlashCommand } from '@svadmin/editor/extensions/slash-command';
|
|
94
|
+
* const SlashCommand = createSlashCommand();
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export function createSlashCommand(options = {}) {
|
|
98
|
+
const items = options.items ?? getDefaultSlashItems();
|
|
99
|
+
return Extension.create({
|
|
100
|
+
name: 'slashCommand',
|
|
101
|
+
addOptions() {
|
|
102
|
+
return {
|
|
103
|
+
suggestion: {
|
|
104
|
+
char: '/',
|
|
105
|
+
command: ({ editor, range, props }) => {
|
|
106
|
+
// Delete the slash and trigger text
|
|
107
|
+
editor.chain().focus().deleteRange(range).run();
|
|
108
|
+
// Execute the command
|
|
109
|
+
props.command(editor);
|
|
110
|
+
},
|
|
111
|
+
items: ({ query }) => {
|
|
112
|
+
return items.filter((item) => item.title.toLowerCase().includes(query.toLowerCase()));
|
|
113
|
+
},
|
|
114
|
+
...(options.render ? { render: options.render } : {}),
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
addProseMirrorPlugins() {
|
|
119
|
+
return [
|
|
120
|
+
Suggestion({
|
|
121
|
+
editor: this.editor,
|
|
122
|
+
...this.options.suggestion,
|
|
123
|
+
}),
|
|
124
|
+
];
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @svadmin/editor — Modern Tiptap-based rich text editor for Svelte 5
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```svelte
|
|
6
|
+
* <script>
|
|
7
|
+
* import { Editor } from '@svadmin/editor';
|
|
8
|
+
*
|
|
9
|
+
* let content = $state('<p>Hello World</p>');
|
|
10
|
+
* </script>
|
|
11
|
+
*
|
|
12
|
+
* <Editor bind:value={content} placeholder="Start writing..." />
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export { default as Editor } from './components/Editor.svelte';
|
|
16
|
+
export { default as Toolbar } from './components/Toolbar.svelte';
|
|
17
|
+
export { default as ToolbarButton } from './components/ToolbarButton.svelte';
|
|
18
|
+
export { default as ToolbarGroup } from './components/ToolbarGroup.svelte';
|
|
19
|
+
export { default as ToolbarSelect } from './components/ToolbarSelect.svelte';
|
|
20
|
+
export { default as BubbleMenu } from './components/BubbleMenu.svelte';
|
|
21
|
+
export { default as FloatingMenu } from './components/FloatingMenu.svelte';
|
|
22
|
+
export { default as ColorPicker } from './components/ColorPicker.svelte';
|
|
23
|
+
export { default as LinkPopover } from './components/LinkPopover.svelte';
|
|
24
|
+
export { default as TableMenu } from './components/TableMenu.svelte';
|
|
25
|
+
export { default as ImageUpload } from './components/ImageUpload.svelte';
|
|
26
|
+
export { fullPreset, minimalPreset, prosePreset, type EditorPresetOptions, } from './extensions/index.js';
|
|
27
|
+
export { StarterKit, Underline, TextAlign, TextStyle, Color, Highlight, Link, Image, Placeholder, CharacterCount, Typography, Subscript, Superscript, TaskList, TaskItem, Table, TableRow, TableHeader, TableCell, CodeBlockLowlight, } from './extensions/index.js';
|
|
28
|
+
export { Editor as TiptapEditor } from '@tiptap/core';
|
|
29
|
+
export type { AnyExtension, Extension, Mark, Node } from '@tiptap/core';
|
|
@@ -12,10 +12,8 @@
|
|
|
12
12
|
* <Editor bind:value={content} placeholder="Start writing..." />
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
15
|
// ─── Main component ──────────────────────────────────────────────
|
|
17
16
|
export { default as Editor } from './components/Editor.svelte';
|
|
18
|
-
|
|
19
17
|
// ─── Sub-components (for custom layouts) ─────────────────────────
|
|
20
18
|
export { default as Toolbar } from './components/Toolbar.svelte';
|
|
21
19
|
export { default as ToolbarButton } from './components/ToolbarButton.svelte';
|
|
@@ -27,39 +25,9 @@ export { default as ColorPicker } from './components/ColorPicker.svelte';
|
|
|
27
25
|
export { default as LinkPopover } from './components/LinkPopover.svelte';
|
|
28
26
|
export { default as TableMenu } from './components/TableMenu.svelte';
|
|
29
27
|
export { default as ImageUpload } from './components/ImageUpload.svelte';
|
|
30
|
-
|
|
31
28
|
// ─── Extension presets ───────────────────────────────────────────
|
|
32
|
-
export {
|
|
33
|
-
fullPreset,
|
|
34
|
-
minimalPreset,
|
|
35
|
-
prosePreset,
|
|
36
|
-
type EditorPresetOptions,
|
|
37
|
-
} from './extensions/index.js';
|
|
38
|
-
|
|
29
|
+
export { fullPreset, minimalPreset, prosePreset, } from './extensions/index.js';
|
|
39
30
|
// ─── Individual extensions (re-exports for custom composition) ──
|
|
40
|
-
export {
|
|
41
|
-
StarterKit,
|
|
42
|
-
Underline,
|
|
43
|
-
TextAlign,
|
|
44
|
-
TextStyle,
|
|
45
|
-
Color,
|
|
46
|
-
Highlight,
|
|
47
|
-
Link,
|
|
48
|
-
Image,
|
|
49
|
-
Placeholder,
|
|
50
|
-
CharacterCount,
|
|
51
|
-
Typography,
|
|
52
|
-
Subscript,
|
|
53
|
-
Superscript,
|
|
54
|
-
TaskList,
|
|
55
|
-
TaskItem,
|
|
56
|
-
Table,
|
|
57
|
-
TableRow,
|
|
58
|
-
TableHeader,
|
|
59
|
-
TableCell,
|
|
60
|
-
CodeBlockLowlight,
|
|
61
|
-
} from './extensions/index.js';
|
|
62
|
-
|
|
31
|
+
export { StarterKit, Underline, TextAlign, TextStyle, Color, Highlight, Link, Image, Placeholder, CharacterCount, Typography, Subscript, Superscript, TaskList, TaskItem, Table, TableRow, TableHeader, TableCell, CodeBlockLowlight, } from './extensions/index.js';
|
|
63
32
|
// ─── Tiptap core re-exports (convenience) ────────────────────────
|
|
64
33
|
export { Editor as TiptapEditor } from '@tiptap/core';
|
|
65
|
-
export type { AnyExtension, Extension, Mark, Node } from '@tiptap/core';
|
package/package.json
CHANGED
|
@@ -1,56 +1,78 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svadmin/editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Modern Tiptap-based rich text editor for Svelte 5 — headless, modular, production-ready",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"./dist/styles/editor.css"
|
|
8
|
+
],
|
|
6
9
|
"files": [
|
|
7
|
-
"
|
|
10
|
+
"dist",
|
|
11
|
+
"!dist/**/*.test.*",
|
|
12
|
+
"!dist/**/*.test-*",
|
|
13
|
+
"!dist/**/*.spec.*",
|
|
14
|
+
"!dist/**/*.spec-*"
|
|
8
15
|
],
|
|
9
|
-
"main": "
|
|
10
|
-
"types": "
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"svelte": "./dist/index.js",
|
|
11
19
|
"exports": {
|
|
12
20
|
".": {
|
|
13
|
-
"types": "./
|
|
14
|
-
"
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"svelte": "./dist/index.js",
|
|
23
|
+
"default": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./components/*.svelte": {
|
|
26
|
+
"types": "./dist/components/*.svelte.d.ts",
|
|
27
|
+
"svelte": "./dist/components/*.svelte",
|
|
28
|
+
"default": "./dist/components/*.svelte"
|
|
15
29
|
},
|
|
16
|
-
"./components/*": "./
|
|
17
|
-
"./editor.css":
|
|
30
|
+
"./components/*": "./dist/components/*",
|
|
31
|
+
"./editor.css": {
|
|
32
|
+
"svelte": "./dist/styles/editor.css",
|
|
33
|
+
"style": "./dist/styles/editor.css",
|
|
34
|
+
"import": "./dist/styles/editor.css",
|
|
35
|
+
"default": "./dist/styles/editor.css"
|
|
36
|
+
}
|
|
18
37
|
},
|
|
19
38
|
"peerDependencies": {
|
|
20
|
-
"svelte": "^5.
|
|
21
|
-
"@svadmin/core": "^0.
|
|
39
|
+
"svelte": "^5.56.8",
|
|
40
|
+
"@svadmin/core": "^0.34.2"
|
|
22
41
|
},
|
|
23
42
|
"devDependencies": {
|
|
24
|
-
"@svadmin/core": "^0.
|
|
43
|
+
"@svadmin/core": "^0.34.2"
|
|
25
44
|
},
|
|
26
45
|
"dependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"@tiptap/
|
|
29
|
-
"@tiptap/
|
|
30
|
-
"@tiptap/extension-
|
|
31
|
-
"@tiptap/extension-
|
|
32
|
-
"@tiptap/extension-
|
|
33
|
-
"@tiptap/extension-
|
|
34
|
-
"@tiptap/extension-
|
|
35
|
-
"@tiptap/extension-
|
|
36
|
-
"@tiptap/extension-
|
|
37
|
-
"@tiptap/extension-
|
|
38
|
-
"@tiptap/extension-
|
|
39
|
-
"@tiptap/extension-
|
|
40
|
-
"@tiptap/extension-
|
|
41
|
-
"@tiptap/extension-table": "^
|
|
42
|
-
"@tiptap/extension-table-
|
|
43
|
-
"@tiptap/extension-table-
|
|
44
|
-
"@tiptap/extension-
|
|
45
|
-
"@tiptap/extension-task-
|
|
46
|
-
"@tiptap/extension-
|
|
47
|
-
"@tiptap/extension-text-
|
|
48
|
-
"@tiptap/extension-
|
|
49
|
-
"@tiptap/extension-
|
|
50
|
-
"@tiptap/
|
|
51
|
-
"@tiptap/
|
|
52
|
-
"
|
|
53
|
-
"
|
|
46
|
+
"@lucide/svelte": "^1.30.0",
|
|
47
|
+
"@tiptap/core": "^3.29.2",
|
|
48
|
+
"@tiptap/extension-bubble-menu": "^3.29.2",
|
|
49
|
+
"@tiptap/extension-character-count": "^3.29.2",
|
|
50
|
+
"@tiptap/extension-code-block-lowlight": "^3.29.2",
|
|
51
|
+
"@tiptap/extension-color": "^3.29.2",
|
|
52
|
+
"@tiptap/extension-floating-menu": "^3.29.2",
|
|
53
|
+
"@tiptap/extension-highlight": "^3.29.2",
|
|
54
|
+
"@tiptap/extension-image": "^3.29.2",
|
|
55
|
+
"@tiptap/extension-link": "^3.29.2",
|
|
56
|
+
"@tiptap/extension-placeholder": "^3.29.2",
|
|
57
|
+
"@tiptap/extension-subscript": "^3.29.2",
|
|
58
|
+
"@tiptap/extension-superscript": "^3.29.2",
|
|
59
|
+
"@tiptap/extension-table": "^3.29.2",
|
|
60
|
+
"@tiptap/extension-table-cell": "^3.29.2",
|
|
61
|
+
"@tiptap/extension-table-header": "^3.29.2",
|
|
62
|
+
"@tiptap/extension-table-row": "^3.29.2",
|
|
63
|
+
"@tiptap/extension-task-item": "^3.29.2",
|
|
64
|
+
"@tiptap/extension-task-list": "^3.29.2",
|
|
65
|
+
"@tiptap/extension-text-align": "^3.29.2",
|
|
66
|
+
"@tiptap/extension-text-style": "^3.29.2",
|
|
67
|
+
"@tiptap/extension-typography": "^3.29.2",
|
|
68
|
+
"@tiptap/extension-underline": "^3.29.2",
|
|
69
|
+
"@tiptap/pm": "^3.29.2",
|
|
70
|
+
"@tiptap/starter-kit": "^3.29.2",
|
|
71
|
+
"@tiptap/suggestion": "^3.29.2",
|
|
72
|
+
"lowlight": "^3.3.0"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"build": "node ../../node_modules/@sveltejs/package/svelte-package.js -i src -o dist"
|
|
54
76
|
},
|
|
55
77
|
"license": "MIT",
|
|
56
78
|
"publishConfig": {
|
|
@@ -62,5 +84,13 @@
|
|
|
62
84
|
"type": "git",
|
|
63
85
|
"url": "https://github.com/zuohuadong/svadmin.git",
|
|
64
86
|
"directory": "packages/editor"
|
|
87
|
+
},
|
|
88
|
+
"peerDependenciesMeta": {
|
|
89
|
+
"svelte": {
|
|
90
|
+
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"@svadmin/core": {
|
|
93
|
+
"optional": true
|
|
94
|
+
}
|
|
65
95
|
}
|
|
66
96
|
}
|
package/src/editor.svelte.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @svadmin/editor — Editor factory
|
|
3
|
-
*
|
|
4
|
-
* Creates and manages a Tiptap editor instance with Svelte 5 reactivity.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { Editor, type EditorOptions } from '@tiptap/core';
|
|
8
|
-
import { fullPreset, minimalPreset, prosePreset, type EditorPresetOptions } from './extensions/index.js';
|
|
9
|
-
import type { AnyExtension } from '@tiptap/core';
|
|
10
|
-
|
|
11
|
-
export interface SvadminEditorOptions {
|
|
12
|
-
/** Initial HTML content */
|
|
13
|
-
content?: string;
|
|
14
|
-
/** Placeholder text shown when editor is empty */
|
|
15
|
-
placeholder?: string;
|
|
16
|
-
/** Whether the editor is editable */
|
|
17
|
-
editable?: boolean;
|
|
18
|
-
/** Autofocus on mount */
|
|
19
|
-
autofocus?: boolean | 'start' | 'end';
|
|
20
|
-
/** Maximum character count (0 = unlimited) */
|
|
21
|
-
maxLength?: number;
|
|
22
|
-
/** Extension preset: 'full' | 'minimal' | 'prose' */
|
|
23
|
-
preset?: 'full' | 'minimal' | 'prose';
|
|
24
|
-
/** Custom extensions (overrides preset) */
|
|
25
|
-
extensions?: AnyExtension[];
|
|
26
|
-
/** Preset options */
|
|
27
|
-
presetOptions?: EditorPresetOptions;
|
|
28
|
-
/** Image upload handler */
|
|
29
|
-
onUpload?: (file: File) => Promise<string>;
|
|
30
|
-
/** Called on every content update */
|
|
31
|
-
onUpdate?: (html: string) => void;
|
|
32
|
-
/** Additional Tiptap EditorOptions overrides */
|
|
33
|
-
editorProps?: Partial<EditorOptions>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Create a Tiptap editor instance with svadmin defaults.
|
|
38
|
-
*/
|
|
39
|
-
export function createSvadminEditor(
|
|
40
|
-
element: HTMLElement,
|
|
41
|
-
options: SvadminEditorOptions = {}
|
|
42
|
-
): Editor {
|
|
43
|
-
const {
|
|
44
|
-
content = '',
|
|
45
|
-
placeholder = '',
|
|
46
|
-
editable = true,
|
|
47
|
-
autofocus = false,
|
|
48
|
-
maxLength = 0,
|
|
49
|
-
preset = 'full',
|
|
50
|
-
extensions: customExtensions,
|
|
51
|
-
presetOptions,
|
|
52
|
-
onUpdate,
|
|
53
|
-
editorProps,
|
|
54
|
-
} = options;
|
|
55
|
-
|
|
56
|
-
// Resolve extensions
|
|
57
|
-
let extensions: AnyExtension[];
|
|
58
|
-
if (customExtensions) {
|
|
59
|
-
extensions = customExtensions;
|
|
60
|
-
} else {
|
|
61
|
-
const opts: EditorPresetOptions = {
|
|
62
|
-
placeholder,
|
|
63
|
-
maxLength,
|
|
64
|
-
...presetOptions,
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
switch (preset) {
|
|
68
|
-
case 'minimal':
|
|
69
|
-
extensions = minimalPreset(opts);
|
|
70
|
-
break;
|
|
71
|
-
case 'prose':
|
|
72
|
-
extensions = prosePreset(opts);
|
|
73
|
-
break;
|
|
74
|
-
case 'full':
|
|
75
|
-
default:
|
|
76
|
-
extensions = fullPreset(opts);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const editor = new Editor({
|
|
81
|
-
element,
|
|
82
|
-
extensions,
|
|
83
|
-
content,
|
|
84
|
-
editable,
|
|
85
|
-
autofocus,
|
|
86
|
-
editorProps: {
|
|
87
|
-
attributes: {
|
|
88
|
-
class: 'tiptap',
|
|
89
|
-
},
|
|
90
|
-
...editorProps?.editorProps,
|
|
91
|
-
},
|
|
92
|
-
onUpdate({ editor: e }) {
|
|
93
|
-
onUpdate?.(e.getHTML());
|
|
94
|
-
},
|
|
95
|
-
...editorProps,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
return editor;
|
|
99
|
-
}
|