uncial 0.0.1
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/LICENSE +21 -0
- package/README.md +228 -0
- package/dist/core/attributes.d.ts +11 -0
- package/dist/core/attributes.js +149 -0
- package/dist/core/defineBlock.d.ts +2 -0
- package/dist/core/defineBlock.js +77 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.js +6 -0
- package/dist/core/normalize.d.ts +5 -0
- package/dist/core/normalize.js +38 -0
- package/dist/core/registry.d.ts +4 -0
- package/dist/core/registry.js +41 -0
- package/dist/core/types.d.ts +130 -0
- package/dist/core/types.js +1 -0
- package/dist/core/validate.d.ts +4 -0
- package/dist/core/validate.js +181 -0
- package/dist/editor/BlockAttributesPanel.svelte +354 -0
- package/dist/editor/BlockAttributesPanel.svelte.d.ts +9 -0
- package/dist/editor/BlockMenu.svelte +63 -0
- package/dist/editor/BlockMenu.svelte.d.ts +24 -0
- package/dist/editor/BlockNodeView.svelte +88 -0
- package/dist/editor/BlockNodeView.svelte.d.ts +14 -0
- package/dist/editor/Editor.svelte +453 -0
- package/dist/editor/Editor.svelte.d.ts +17 -0
- package/dist/editor/LinkAttributesPanel.svelte +96 -0
- package/dist/editor/LinkAttributesPanel.svelte.d.ts +17 -0
- package/dist/editor/RichTextAttributeEditor.svelte +232 -0
- package/dist/editor/RichTextAttributeEditor.svelte.d.ts +11 -0
- package/dist/editor/Toolbar.svelte +124 -0
- package/dist/editor/Toolbar.svelte.d.ts +14 -0
- package/dist/editor/attributesController.d.ts +64 -0
- package/dist/editor/attributesController.js +608 -0
- package/dist/editor/bindEditor.d.ts +15 -0
- package/dist/editor/bindEditor.js +159 -0
- package/dist/editor/createEditorExtensions.d.ts +1 -0
- package/dist/editor/createEditorExtensions.js +1 -0
- package/dist/editor/index.d.ts +11 -0
- package/dist/editor/index.js +8 -0
- package/dist/editor/toolbarFeatures.d.ts +26 -0
- package/dist/editor/toolbarFeatures.js +144 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/render/ContainerBlockFixture.svelte +22 -0
- package/dist/render/ContainerBlockFixture.svelte.d.ts +10 -0
- package/dist/render/Renderer.svelte +40 -0
- package/dist/render/Renderer.svelte.d.ts +11 -0
- package/dist/render/RichContent.svelte +30 -0
- package/dist/render/RichContent.svelte.d.ts +10 -0
- package/dist/render/RichNode.svelte +105 -0
- package/dist/render/RichNode.svelte.d.ts +10 -0
- package/dist/render/RichText.svelte +29 -0
- package/dist/render/RichText.svelte.d.ts +8 -0
- package/dist/render/index.d.ts +2 -0
- package/dist/render/index.js +2 -0
- package/dist/render/sanitize.d.ts +1 -0
- package/dist/render/sanitize.js +17 -0
- package/dist/shared/codeBlockAttributes.d.ts +31 -0
- package/dist/shared/codeBlockAttributes.js +25 -0
- package/dist/shared/content.d.ts +2 -0
- package/dist/shared/content.js +7 -0
- package/dist/shared/document.d.ts +18 -0
- package/dist/shared/document.js +1 -0
- package/dist/shared/richText.d.ts +11 -0
- package/dist/shared/richText.js +108 -0
- package/dist/shared/syntaxHighlight.d.ts +16 -0
- package/dist/shared/syntaxHighlight.js +47 -0
- package/dist/shared/tiptap.d.ts +7 -0
- package/dist/shared/tiptap.js +259 -0
- package/package.json +116 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import XIcon from 'phosphor-svelte/lib/XIcon';
|
|
3
|
+
|
|
4
|
+
interface LinkAttributes {
|
|
5
|
+
href?: string | null;
|
|
6
|
+
target?: string | null;
|
|
7
|
+
rel?: string | null;
|
|
8
|
+
title?: string | null;
|
|
9
|
+
class?: string | null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
attrs?: LinkAttributes;
|
|
14
|
+
onChange: (name: keyof LinkAttributes, value: string | null) => void;
|
|
15
|
+
onApply: () => void;
|
|
16
|
+
onRemove: () => void;
|
|
17
|
+
onClose: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let { attrs = {}, onChange, onApply, onRemove, onClose }: Props = $props();
|
|
21
|
+
|
|
22
|
+
const href = $derived(typeof attrs.href === 'string' ? attrs.href : '');
|
|
23
|
+
const title = $derived(typeof attrs.title === 'string' ? attrs.title : '');
|
|
24
|
+
const className = $derived(typeof attrs.class === 'string' ? attrs.class : '');
|
|
25
|
+
const openInNewTab = $derived(attrs.target === '_blank');
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<form
|
|
29
|
+
class="grid gap-3"
|
|
30
|
+
onsubmit={(event) => {
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
onApply();
|
|
33
|
+
}}
|
|
34
|
+
>
|
|
35
|
+
<div class="flex items-start justify-between gap-3">
|
|
36
|
+
<div>
|
|
37
|
+
<p class="text-sm font-bold">Edit link</p>
|
|
38
|
+
<p class="text-xs opacity-60">Configure the selected link mark.</p>
|
|
39
|
+
</div>
|
|
40
|
+
<button type="button" class="btn btn-ghost btn-xs btn-square" aria-label="Close link editor" onclick={onClose}>
|
|
41
|
+
<XIcon size={12} weight="bold" />
|
|
42
|
+
</button>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
<label class="form-control grid gap-1">
|
|
46
|
+
<span class="label-text text-xs font-semibold uppercase tracking-wide opacity-70">URL</span>
|
|
47
|
+
<input
|
|
48
|
+
class="input input-bordered input-sm"
|
|
49
|
+
type="url"
|
|
50
|
+
value={href}
|
|
51
|
+
placeholder="https://example.com"
|
|
52
|
+
oninput={(event) => onChange('href', event.currentTarget.value)}
|
|
53
|
+
/>
|
|
54
|
+
</label>
|
|
55
|
+
|
|
56
|
+
<label class="form-control grid gap-1">
|
|
57
|
+
<span class="label-text text-xs font-semibold uppercase tracking-wide opacity-70">Title</span>
|
|
58
|
+
<input
|
|
59
|
+
class="input input-bordered input-sm"
|
|
60
|
+
type="text"
|
|
61
|
+
value={title}
|
|
62
|
+
placeholder="Optional title"
|
|
63
|
+
oninput={(event) => onChange('title', event.currentTarget.value)}
|
|
64
|
+
/>
|
|
65
|
+
</label>
|
|
66
|
+
|
|
67
|
+
<label class="form-control grid gap-1">
|
|
68
|
+
<span class="label-text text-xs font-semibold uppercase tracking-wide opacity-70">Class</span>
|
|
69
|
+
<input
|
|
70
|
+
class="input input-bordered input-sm"
|
|
71
|
+
type="text"
|
|
72
|
+
value={className}
|
|
73
|
+
placeholder="Optional CSS class"
|
|
74
|
+
oninput={(event) => onChange('class', event.currentTarget.value)}
|
|
75
|
+
/>
|
|
76
|
+
</label>
|
|
77
|
+
|
|
78
|
+
<label class="flex items-center gap-2 text-sm">
|
|
79
|
+
<input
|
|
80
|
+
class="checkbox checkbox-sm"
|
|
81
|
+
type="checkbox"
|
|
82
|
+
checked={openInNewTab}
|
|
83
|
+
onchange={(event) => {
|
|
84
|
+
const target = event.currentTarget as HTMLInputElement;
|
|
85
|
+
onChange('target', target.checked ? '_blank' : null);
|
|
86
|
+
onChange('rel', target.checked ? 'noopener noreferrer' : null);
|
|
87
|
+
}}
|
|
88
|
+
/>
|
|
89
|
+
<span>Open in a new tab</span>
|
|
90
|
+
</label>
|
|
91
|
+
|
|
92
|
+
<div class="flex flex-wrap justify-between gap-2 border-t border-base-300 pt-3">
|
|
93
|
+
<button type="button" class="btn btn-error btn-outline btn-sm" onclick={onRemove}>Remove Link</button>
|
|
94
|
+
<button type="submit" class="btn btn-primary btn-sm" disabled={!href.trim()}>Update Link</button>
|
|
95
|
+
</div>
|
|
96
|
+
</form>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface LinkAttributes {
|
|
2
|
+
href?: string | null;
|
|
3
|
+
target?: string | null;
|
|
4
|
+
rel?: string | null;
|
|
5
|
+
title?: string | null;
|
|
6
|
+
class?: string | null;
|
|
7
|
+
}
|
|
8
|
+
interface Props {
|
|
9
|
+
attrs?: LinkAttributes;
|
|
10
|
+
onChange: (name: keyof LinkAttributes, value: string | null) => void;
|
|
11
|
+
onApply: () => void;
|
|
12
|
+
onRemove: () => void;
|
|
13
|
+
onClose: () => void;
|
|
14
|
+
}
|
|
15
|
+
declare const LinkAttributesPanel: import("svelte").Component<Props, {}, "">;
|
|
16
|
+
type LinkAttributesPanel = ReturnType<typeof LinkAttributesPanel>;
|
|
17
|
+
export default LinkAttributesPanel;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Editor } from '@tiptap/core';
|
|
3
|
+
import CodeIcon from 'phosphor-svelte/lib/CodeIcon';
|
|
4
|
+
import CodeBlockIcon from 'phosphor-svelte/lib/CodeBlockIcon';
|
|
5
|
+
import ListBulletsIcon from 'phosphor-svelte/lib/ListBulletsIcon';
|
|
6
|
+
import ListNumbersIcon from 'phosphor-svelte/lib/ListNumbersIcon';
|
|
7
|
+
import MinusIcon from 'phosphor-svelte/lib/MinusIcon';
|
|
8
|
+
import QuotesIcon from 'phosphor-svelte/lib/QuotesIcon';
|
|
9
|
+
import TextBIcon from 'phosphor-svelte/lib/TextBIcon';
|
|
10
|
+
import TextHThreeIcon from 'phosphor-svelte/lib/TextHThreeIcon';
|
|
11
|
+
import TextItalicIcon from 'phosphor-svelte/lib/TextItalicIcon';
|
|
12
|
+
import TextStrikethroughIcon from 'phosphor-svelte/lib/TextStrikethroughIcon';
|
|
13
|
+
import { untrack } from 'svelte';
|
|
14
|
+
import type { PMDoc } from '../shared/document.js';
|
|
15
|
+
import { coerceRichTextDocument, resolveRichTextFeatures } from '../shared/richText.js';
|
|
16
|
+
import { createRichTextExtensions } from '../shared/tiptap.js';
|
|
17
|
+
import type { RichTextFeatureSelection } from '../core/types.js';
|
|
18
|
+
|
|
19
|
+
interface Props {
|
|
20
|
+
value?: unknown;
|
|
21
|
+
features?: RichTextFeatureSelection;
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
onChange: (value: PMDoc) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let {
|
|
27
|
+
value = undefined,
|
|
28
|
+
features = undefined,
|
|
29
|
+
placeholder = 'Write rich text...',
|
|
30
|
+
onChange
|
|
31
|
+
}: Props = $props();
|
|
32
|
+
|
|
33
|
+
let element = $state<HTMLElement>();
|
|
34
|
+
let editor = $state.raw<Editor | null>(null);
|
|
35
|
+
let lastJson = '';
|
|
36
|
+
|
|
37
|
+
const resolvedFeatures = $derived(resolveRichTextFeatures(features));
|
|
38
|
+
const activeEditor = $derived(editor);
|
|
39
|
+
const canBold = $derived(resolvedFeatures.has('bold'));
|
|
40
|
+
const canItalic = $derived(resolvedFeatures.has('italic'));
|
|
41
|
+
const canStrike = $derived(resolvedFeatures.has('strike'));
|
|
42
|
+
const canCode = $derived(resolvedFeatures.has('code'));
|
|
43
|
+
const canHeading = $derived(resolvedFeatures.has('heading'));
|
|
44
|
+
const canBulletList = $derived(resolvedFeatures.has('bulletList'));
|
|
45
|
+
const canOrderedList = $derived(resolvedFeatures.has('orderedList'));
|
|
46
|
+
const canBlockquote = $derived(resolvedFeatures.has('blockquote'));
|
|
47
|
+
const canCodeBlock = $derived(resolvedFeatures.has('codeBlock'));
|
|
48
|
+
const canHorizontalRule = $derived(resolvedFeatures.has('horizontalRule'));
|
|
49
|
+
|
|
50
|
+
function emitChange(nextEditor: Editor): void {
|
|
51
|
+
const json = nextEditor.getJSON() as PMDoc;
|
|
52
|
+
lastJson = JSON.stringify(json);
|
|
53
|
+
onChange(json);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function runCommand(command: () => boolean): void {
|
|
57
|
+
command();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const iconSize = 14;
|
|
61
|
+
|
|
62
|
+
$effect(() => {
|
|
63
|
+
if (!element) return;
|
|
64
|
+
|
|
65
|
+
const initialContent = untrack(() => coerceRichTextDocument(value));
|
|
66
|
+
lastJson = JSON.stringify(initialContent);
|
|
67
|
+
const nextEditor = new Editor({
|
|
68
|
+
element,
|
|
69
|
+
content: initialContent,
|
|
70
|
+
extensions: createRichTextExtensions(resolvedFeatures),
|
|
71
|
+
editorProps: {
|
|
72
|
+
attributes: {
|
|
73
|
+
class:
|
|
74
|
+
'uncial-richtext-editor uncial-rich-content min-h-28 rounded-b-lg border border-t-0 border-base-300 bg-base-100 px-3 py-2 text-sm leading-6 outline-none',
|
|
75
|
+
'aria-label': placeholder
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
onUpdate: ({ editor: updatedEditor }) => {
|
|
79
|
+
emitChange(updatedEditor);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
editor = nextEditor;
|
|
84
|
+
|
|
85
|
+
return () => {
|
|
86
|
+
nextEditor.destroy();
|
|
87
|
+
editor = null;
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
$effect(() => {
|
|
92
|
+
if (!editor) return;
|
|
93
|
+
const nextContent = coerceRichTextDocument(value);
|
|
94
|
+
const nextJson = JSON.stringify(nextContent);
|
|
95
|
+
if (nextJson === lastJson) return;
|
|
96
|
+
lastJson = nextJson;
|
|
97
|
+
editor.commands.setContent(nextContent, { emitUpdate: false });
|
|
98
|
+
});
|
|
99
|
+
</script>
|
|
100
|
+
|
|
101
|
+
<div class="rounded-lg border-base-300">
|
|
102
|
+
<div class="flex flex-wrap gap-1 rounded-t-lg border border-base-300 bg-base-200/70 p-1.5">
|
|
103
|
+
{#if canBold}
|
|
104
|
+
<button
|
|
105
|
+
type="button"
|
|
106
|
+
class="tooltip btn btn-square btn-xs"
|
|
107
|
+
class:btn-active={activeEditor?.isActive('bold')}
|
|
108
|
+
aria-label="Bold"
|
|
109
|
+
data-tip="Bold"
|
|
110
|
+
onclick={() => runCommand(() => editor?.chain().focus().toggleBold().run() ?? false)}
|
|
111
|
+
>
|
|
112
|
+
<TextBIcon size={iconSize} weight="bold" />
|
|
113
|
+
</button>
|
|
114
|
+
{/if}
|
|
115
|
+
{#if canItalic}
|
|
116
|
+
<button
|
|
117
|
+
type="button"
|
|
118
|
+
class="tooltip btn btn-square btn-xs"
|
|
119
|
+
class:btn-active={activeEditor?.isActive('italic')}
|
|
120
|
+
aria-label="Italic"
|
|
121
|
+
data-tip="Italic"
|
|
122
|
+
onclick={() => runCommand(() => editor?.chain().focus().toggleItalic().run() ?? false)}
|
|
123
|
+
>
|
|
124
|
+
<TextItalicIcon size={iconSize} weight="bold" />
|
|
125
|
+
</button>
|
|
126
|
+
{/if}
|
|
127
|
+
{#if canStrike}
|
|
128
|
+
<button
|
|
129
|
+
type="button"
|
|
130
|
+
class="tooltip btn btn-square btn-xs"
|
|
131
|
+
class:btn-active={activeEditor?.isActive('strike')}
|
|
132
|
+
aria-label="Strikethrough"
|
|
133
|
+
data-tip="Strikethrough"
|
|
134
|
+
onclick={() => runCommand(() => editor?.chain().focus().toggleStrike().run() ?? false)}
|
|
135
|
+
>
|
|
136
|
+
<TextStrikethroughIcon size={iconSize} weight="bold" />
|
|
137
|
+
</button>
|
|
138
|
+
{/if}
|
|
139
|
+
{#if canCode}
|
|
140
|
+
<button
|
|
141
|
+
type="button"
|
|
142
|
+
class="tooltip btn btn-square btn-xs"
|
|
143
|
+
class:btn-active={activeEditor?.isActive('code')}
|
|
144
|
+
aria-label="Inline code"
|
|
145
|
+
data-tip="Inline code"
|
|
146
|
+
onclick={() => runCommand(() => editor?.chain().focus().toggleCode().run() ?? false)}
|
|
147
|
+
>
|
|
148
|
+
<CodeIcon size={iconSize} weight="bold" />
|
|
149
|
+
</button>
|
|
150
|
+
{/if}
|
|
151
|
+
{#if canHeading}
|
|
152
|
+
<button
|
|
153
|
+
type="button"
|
|
154
|
+
class="tooltip btn btn-square btn-xs"
|
|
155
|
+
class:btn-active={activeEditor?.isActive('heading')}
|
|
156
|
+
aria-label="Heading"
|
|
157
|
+
data-tip="Heading"
|
|
158
|
+
onclick={() =>
|
|
159
|
+
runCommand(() => editor?.chain().focus().toggleHeading({ level: 3 }).run() ?? false)}
|
|
160
|
+
>
|
|
161
|
+
<TextHThreeIcon size={iconSize} weight="bold" />
|
|
162
|
+
</button>
|
|
163
|
+
{/if}
|
|
164
|
+
{#if canBulletList}
|
|
165
|
+
<button
|
|
166
|
+
type="button"
|
|
167
|
+
class="tooltip btn btn-square btn-xs"
|
|
168
|
+
class:btn-active={activeEditor?.isActive('bulletList')}
|
|
169
|
+
aria-label="Bullet list"
|
|
170
|
+
data-tip="Bullet list"
|
|
171
|
+
onclick={() => runCommand(() => editor?.chain().focus().toggleBulletList().run() ?? false)}
|
|
172
|
+
>
|
|
173
|
+
<ListBulletsIcon size={iconSize} weight="bold" />
|
|
174
|
+
</button>
|
|
175
|
+
{/if}
|
|
176
|
+
{#if canOrderedList}
|
|
177
|
+
<button
|
|
178
|
+
type="button"
|
|
179
|
+
class="tooltip btn btn-square btn-xs"
|
|
180
|
+
class:btn-active={activeEditor?.isActive('orderedList')}
|
|
181
|
+
aria-label="Ordered list"
|
|
182
|
+
data-tip="Ordered list"
|
|
183
|
+
onclick={() => runCommand(() => editor?.chain().focus().toggleOrderedList().run() ?? false)}
|
|
184
|
+
>
|
|
185
|
+
<ListNumbersIcon size={iconSize} weight="bold" />
|
|
186
|
+
</button>
|
|
187
|
+
{/if}
|
|
188
|
+
{#if canBlockquote}
|
|
189
|
+
<button
|
|
190
|
+
type="button"
|
|
191
|
+
class="tooltip btn btn-square btn-xs"
|
|
192
|
+
class:btn-active={activeEditor?.isActive('blockquote')}
|
|
193
|
+
aria-label="Blockquote"
|
|
194
|
+
data-tip="Blockquote"
|
|
195
|
+
onclick={() => runCommand(() => editor?.chain().focus().toggleBlockquote().run() ?? false)}
|
|
196
|
+
>
|
|
197
|
+
<QuotesIcon size={iconSize} weight="bold" />
|
|
198
|
+
</button>
|
|
199
|
+
{/if}
|
|
200
|
+
{#if canCodeBlock}
|
|
201
|
+
<button
|
|
202
|
+
type="button"
|
|
203
|
+
class="tooltip btn btn-square btn-xs"
|
|
204
|
+
class:btn-active={activeEditor?.isActive('codeBlock')}
|
|
205
|
+
aria-label="Code block"
|
|
206
|
+
data-tip="Code block"
|
|
207
|
+
onclick={() => runCommand(() => editor?.chain().focus().toggleCodeBlock().run() ?? false)}
|
|
208
|
+
>
|
|
209
|
+
<CodeBlockIcon size={iconSize} weight="bold" />
|
|
210
|
+
</button>
|
|
211
|
+
{/if}
|
|
212
|
+
{#if canHorizontalRule}
|
|
213
|
+
<button
|
|
214
|
+
type="button"
|
|
215
|
+
class="tooltip btn btn-square btn-xs"
|
|
216
|
+
aria-label="Horizontal rule"
|
|
217
|
+
data-tip="Horizontal rule"
|
|
218
|
+
onclick={() => runCommand(() => editor?.chain().focus().setHorizontalRule().run() ?? false)}
|
|
219
|
+
>
|
|
220
|
+
<MinusIcon size={iconSize} weight="bold" />
|
|
221
|
+
</button>
|
|
222
|
+
{/if}
|
|
223
|
+
</div>
|
|
224
|
+
<div bind:this={element}></div>
|
|
225
|
+
</div>
|
|
226
|
+
|
|
227
|
+
<style>
|
|
228
|
+
:global(.uncial-richtext-editor.ProseMirror:focus) {
|
|
229
|
+
outline: none;
|
|
230
|
+
box-shadow: none;
|
|
231
|
+
}
|
|
232
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PMDoc } from '../shared/document.js';
|
|
2
|
+
import type { RichTextFeatureSelection } from '../core/types.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
value?: unknown;
|
|
5
|
+
features?: RichTextFeatureSelection;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
onChange: (value: PMDoc) => void;
|
|
8
|
+
}
|
|
9
|
+
declare const RichTextAttributeEditor: import("svelte").Component<Props, {}, "">;
|
|
10
|
+
type RichTextAttributeEditor = ReturnType<typeof RichTextAttributeEditor>;
|
|
11
|
+
export default RichTextAttributeEditor;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Editor } from '@tiptap/core';
|
|
3
|
+
import type { Component } from 'svelte';
|
|
4
|
+
import CodeIcon from 'phosphor-svelte/lib/CodeIcon';
|
|
5
|
+
import CodeBlockIcon from 'phosphor-svelte/lib/CodeBlockIcon';
|
|
6
|
+
import LinkIcon from 'phosphor-svelte/lib/LinkIcon';
|
|
7
|
+
import ListBulletsIcon from 'phosphor-svelte/lib/ListBulletsIcon';
|
|
8
|
+
import ListNumbersIcon from 'phosphor-svelte/lib/ListNumbersIcon';
|
|
9
|
+
import MinusIcon from 'phosphor-svelte/lib/MinusIcon';
|
|
10
|
+
import QuotesIcon from 'phosphor-svelte/lib/QuotesIcon';
|
|
11
|
+
import TextBIcon from 'phosphor-svelte/lib/TextBIcon';
|
|
12
|
+
import TextHFiveIcon from 'phosphor-svelte/lib/TextHFiveIcon';
|
|
13
|
+
import TextHFourIcon from 'phosphor-svelte/lib/TextHFourIcon';
|
|
14
|
+
import TextHSixIcon from 'phosphor-svelte/lib/TextHSixIcon';
|
|
15
|
+
import TextHThreeIcon from 'phosphor-svelte/lib/TextHThreeIcon';
|
|
16
|
+
import TextHTwoIcon from 'phosphor-svelte/lib/TextHTwoIcon';
|
|
17
|
+
import TextItalicIcon from 'phosphor-svelte/lib/TextItalicIcon';
|
|
18
|
+
import TextStrikethroughIcon from 'phosphor-svelte/lib/TextStrikethroughIcon';
|
|
19
|
+
import type { ContentSchema } from '../core/types.js';
|
|
20
|
+
import {
|
|
21
|
+
resolveToolbarFeatures,
|
|
22
|
+
type ToolbarFeature,
|
|
23
|
+
type ToolbarFeatureSelection
|
|
24
|
+
} from './toolbarFeatures.js';
|
|
25
|
+
|
|
26
|
+
interface Props {
|
|
27
|
+
editor?: Editor | null;
|
|
28
|
+
schema?: ContentSchema;
|
|
29
|
+
toolbarFeatures?: ToolbarFeatureSelection;
|
|
30
|
+
toolbarExtensions?: ToolbarFeature[];
|
|
31
|
+
onEditLink?: () => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let {
|
|
35
|
+
editor = null,
|
|
36
|
+
schema = undefined,
|
|
37
|
+
toolbarFeatures = undefined,
|
|
38
|
+
toolbarExtensions = [],
|
|
39
|
+
onEditLink
|
|
40
|
+
}: Props = $props();
|
|
41
|
+
|
|
42
|
+
const features = $derived(
|
|
43
|
+
resolveToolbarFeatures({ editor, schema, toolbarFeatures, toolbarExtensions })
|
|
44
|
+
);
|
|
45
|
+
const groupedFeatures = $derived.by(() => {
|
|
46
|
+
const groups: { group: string; features: ToolbarFeature[] }[] = [];
|
|
47
|
+
for (const feature of features) {
|
|
48
|
+
const group = feature.group ?? 'default';
|
|
49
|
+
const existing = groups.find((entry) => entry.group === group);
|
|
50
|
+
if (existing) {
|
|
51
|
+
existing.features.push(feature);
|
|
52
|
+
} else {
|
|
53
|
+
groups.push({ group, features: [feature] });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return groups;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
function runFeature(feature: ToolbarFeature): void {
|
|
60
|
+
if (feature.id === 'link' && onEditLink) {
|
|
61
|
+
if (editor && !editor.isActive('link')) {
|
|
62
|
+
feature.run({ editor, schema });
|
|
63
|
+
}
|
|
64
|
+
onEditLink();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!editor) return;
|
|
68
|
+
feature.run({ editor, schema });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function iconFor(featureId: string): Component<Record<string, unknown>> | null {
|
|
72
|
+
return (
|
|
73
|
+
{
|
|
74
|
+
bold: TextBIcon,
|
|
75
|
+
italic: TextItalicIcon,
|
|
76
|
+
strike: TextStrikethroughIcon,
|
|
77
|
+
code: CodeIcon,
|
|
78
|
+
link: LinkIcon,
|
|
79
|
+
heading2: TextHTwoIcon,
|
|
80
|
+
heading3: TextHThreeIcon,
|
|
81
|
+
heading4: TextHFourIcon,
|
|
82
|
+
heading5: TextHFiveIcon,
|
|
83
|
+
heading6: TextHSixIcon,
|
|
84
|
+
bulletList: ListBulletsIcon,
|
|
85
|
+
orderedList: ListNumbersIcon,
|
|
86
|
+
blockquote: QuotesIcon,
|
|
87
|
+
codeBlock: CodeBlockIcon,
|
|
88
|
+
horizontalRule: MinusIcon
|
|
89
|
+
}[featureId] ?? null
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
<div class="contents">
|
|
95
|
+
{#each groupedFeatures as group (group.group)}
|
|
96
|
+
<div class="join">
|
|
97
|
+
{#each group.features as feature (feature.id)}
|
|
98
|
+
{@const context = editor ? { editor, schema } : null}
|
|
99
|
+
{@const Icon = iconFor(feature.id)}
|
|
100
|
+
{@const active = context ? (feature.isActive?.(context) ?? false) : false}
|
|
101
|
+
{@const disabled = !context || !(feature.canRun?.(context) ?? true)}
|
|
102
|
+
<button
|
|
103
|
+
type="button"
|
|
104
|
+
aria-label={feature.label}
|
|
105
|
+
data-tip={feature.tooltip ?? feature.label}
|
|
106
|
+
aria-pressed={active ? 'true' : 'false'}
|
|
107
|
+
disabled={disabled}
|
|
108
|
+
class={[
|
|
109
|
+
'btn btn-sm join-item tooltip tooltip-bottom',
|
|
110
|
+
feature.label.length <= 2 ? 'btn-square' : '',
|
|
111
|
+
active ? 'btn-neutral' : 'btn-ghost'
|
|
112
|
+
]}
|
|
113
|
+
onclick={() => runFeature(feature)}
|
|
114
|
+
>
|
|
115
|
+
{#if Icon}
|
|
116
|
+
<Icon size={16} weight="bold" />
|
|
117
|
+
{:else}
|
|
118
|
+
{feature.label}
|
|
119
|
+
{/if}
|
|
120
|
+
</button>
|
|
121
|
+
{/each}
|
|
122
|
+
</div>
|
|
123
|
+
{/each}
|
|
124
|
+
</div>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Editor } from '@tiptap/core';
|
|
2
|
+
import type { Component } from 'svelte';
|
|
3
|
+
import type { ContentSchema } from '../core/types.js';
|
|
4
|
+
import { type ToolbarFeature, type ToolbarFeatureSelection } from './toolbarFeatures.js';
|
|
5
|
+
interface Props {
|
|
6
|
+
editor?: Editor | null;
|
|
7
|
+
schema?: ContentSchema;
|
|
8
|
+
toolbarFeatures?: ToolbarFeatureSelection;
|
|
9
|
+
toolbarExtensions?: ToolbarFeature[];
|
|
10
|
+
onEditLink?: () => void;
|
|
11
|
+
}
|
|
12
|
+
declare const Toolbar: Component<Props, {}, "">;
|
|
13
|
+
type Toolbar = ReturnType<typeof Toolbar>;
|
|
14
|
+
export default Toolbar;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Editor } from '@tiptap/core';
|
|
2
|
+
import { type Readable } from 'svelte/store';
|
|
3
|
+
import type { BlockRegistry, ContentSchema } from '../core/types.js';
|
|
4
|
+
export type BlockAttributeMode = 'insert' | 'edit' | null;
|
|
5
|
+
export interface LinkAttributes {
|
|
6
|
+
href?: string | null;
|
|
7
|
+
target?: string | null;
|
|
8
|
+
rel?: string | null;
|
|
9
|
+
title?: string | null;
|
|
10
|
+
class?: string | null;
|
|
11
|
+
}
|
|
12
|
+
export interface LinkAttributesState {
|
|
13
|
+
open: boolean;
|
|
14
|
+
attrs: LinkAttributes;
|
|
15
|
+
}
|
|
16
|
+
export interface ActiveBlockSelection {
|
|
17
|
+
id: string;
|
|
18
|
+
attrs: Record<string, unknown>;
|
|
19
|
+
pos: number;
|
|
20
|
+
}
|
|
21
|
+
export interface ContainerChildInfo {
|
|
22
|
+
index: number;
|
|
23
|
+
key: string;
|
|
24
|
+
blockId: string;
|
|
25
|
+
label: string;
|
|
26
|
+
summary: string;
|
|
27
|
+
}
|
|
28
|
+
export interface BlockAttributesState {
|
|
29
|
+
open: boolean;
|
|
30
|
+
mode: BlockAttributeMode;
|
|
31
|
+
selectedBlockId: string;
|
|
32
|
+
draftAttrs: Record<string, unknown>;
|
|
33
|
+
validationErrors: Record<string, string>;
|
|
34
|
+
activeBlock: ActiveBlockSelection | null;
|
|
35
|
+
allowedBlockIds: string[];
|
|
36
|
+
containerChildren: ContainerChildInfo[];
|
|
37
|
+
link: LinkAttributesState;
|
|
38
|
+
}
|
|
39
|
+
export interface BlockAttributesController extends Readable<BlockAttributesState> {
|
|
40
|
+
attach(editor: Editor, registry: BlockRegistry, schema?: ContentSchema): void;
|
|
41
|
+
detach(): void;
|
|
42
|
+
openAttributes(blockId?: string): void;
|
|
43
|
+
openAttributesAt(pos: number): void;
|
|
44
|
+
closeAttributes(): void;
|
|
45
|
+
openLinkAttributes(): void;
|
|
46
|
+
closeLinkAttributes(): void;
|
|
47
|
+
setLinkAttr(name: keyof LinkAttributes, value: string | null): void;
|
|
48
|
+
commitLinkAttributes(): boolean;
|
|
49
|
+
removeLink(): boolean;
|
|
50
|
+
selectBlock(blockId: string): void;
|
|
51
|
+
setDraftAttr(name: string, value: unknown): void;
|
|
52
|
+
commit(): boolean;
|
|
53
|
+
insertBlock(blockId: string, attrs?: Record<string, unknown>): boolean;
|
|
54
|
+
updateSelectedBlockAttrs(blockId: string, partialAttrs: Record<string, unknown>): boolean;
|
|
55
|
+
canEditSelectedBlock(blockId: string): boolean;
|
|
56
|
+
getActiveBlock(): ActiveBlockSelection | null;
|
|
57
|
+
syncFromSelection(source?: 'selection' | 'update'): void;
|
|
58
|
+
isSelectionAutoOpenSuppressed(): boolean;
|
|
59
|
+
moveContainerChild(fromIndex: number, toIndex: number): boolean;
|
|
60
|
+
insertContainerChild(blockId: string, attrs?: Record<string, unknown>): boolean;
|
|
61
|
+
removeActiveBlock(): boolean;
|
|
62
|
+
removeContainerChild(index: number): boolean;
|
|
63
|
+
}
|
|
64
|
+
export declare function createBlockAttributesController(): BlockAttributesController;
|