uncial 0.0.6 → 0.0.7

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.
Files changed (41) hide show
  1. package/README.md +99 -3
  2. package/dist/core/index.d.ts +2 -1
  3. package/dist/core/index.js +1 -0
  4. package/dist/core/meta.d.ts +7 -0
  5. package/dist/core/meta.js +72 -0
  6. package/dist/core/normalize.js +7 -1
  7. package/dist/core/registry.js +3 -1
  8. package/dist/core/types.d.ts +5 -1
  9. package/dist/core/validate.js +2 -0
  10. package/dist/editor/AttributeFieldControl.svelte +113 -0
  11. package/dist/editor/AttributeFieldControl.svelte.d.ts +12 -0
  12. package/dist/editor/BlockAttributesPanel.svelte +41 -134
  13. package/dist/editor/BlockMenu.svelte +24 -35
  14. package/dist/editor/BlockMenu.svelte.d.ts +5 -19
  15. package/dist/editor/DocumentMetaPanel.svelte +69 -0
  16. package/dist/editor/DocumentMetaPanel.svelte.d.ts +10 -0
  17. package/dist/editor/Editor.svelte +128 -249
  18. package/dist/editor/Editor.svelte.d.ts +6 -2
  19. package/dist/editor/LinkAttributesPanel.svelte +32 -19
  20. package/dist/editor/RichTextAttributeEditor.svelte +40 -30
  21. package/dist/editor/Toolbar.svelte +40 -7
  22. package/dist/editor/bindEditor.d.ts +2 -0
  23. package/dist/editor/bindEditor.js +7 -2
  24. package/dist/editor/index.d.ts +4 -0
  25. package/dist/editor/index.js +3 -0
  26. package/dist/editor/metaController.d.ts +19 -0
  27. package/dist/editor/metaController.js +71 -0
  28. package/dist/render/Renderer.svelte +12 -3
  29. package/dist/render/Renderer.svelte.d.ts +2 -0
  30. package/dist/render/RichNode.svelte +3 -8
  31. package/dist/render/RichText.svelte +2 -1
  32. package/dist/shared/content.d.ts +2 -1
  33. package/dist/shared/content.js +7 -2
  34. package/dist/shared/document.d.ts +1 -0
  35. package/dist/styles/base.css +418 -0
  36. package/dist/styles/chrome.css +3 -0
  37. package/dist/styles/controls.css +306 -0
  38. package/dist/styles/index.css +2 -0
  39. package/dist/styles/prose.css +115 -0
  40. package/dist/styles/tokens.css +77 -0
  41. package/package.json +7 -1
@@ -70,8 +70,7 @@
70
70
  extensions: createRichTextExtensions(resolvedFeatures),
71
71
  editorProps: {
72
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',
73
+ class: 'uncial-richtext-editor uncial-rich-content',
75
74
  'aria-label': placeholder
76
75
  }
77
76
  },
@@ -98,13 +97,15 @@
98
97
  });
99
98
  </script>
100
99
 
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">
100
+ <div class="uncial-richtext-wrapper">
101
+ <div class="uncial-richtext-toolbar">
103
102
  {#if canBold}
104
103
  <button
105
104
  type="button"
106
- class="tooltip btn btn-square btn-xs"
107
- class:btn-active={activeEditor?.isActive('bold')}
105
+ class={[
106
+ 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
107
+ activeEditor?.isActive('bold') ? 'uncial-btn--active' : 'uncial-btn--ghost'
108
+ ]}
108
109
  aria-label="Bold"
109
110
  data-tip="Bold"
110
111
  onclick={() => runCommand(() => editor?.chain().focus().toggleBold().run() ?? false)}
@@ -115,8 +116,10 @@
115
116
  {#if canItalic}
116
117
  <button
117
118
  type="button"
118
- class="tooltip btn btn-square btn-xs"
119
- class:btn-active={activeEditor?.isActive('italic')}
119
+ class={[
120
+ 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
121
+ activeEditor?.isActive('italic') ? 'uncial-btn--active' : 'uncial-btn--ghost'
122
+ ]}
120
123
  aria-label="Italic"
121
124
  data-tip="Italic"
122
125
  onclick={() => runCommand(() => editor?.chain().focus().toggleItalic().run() ?? false)}
@@ -127,8 +130,10 @@
127
130
  {#if canStrike}
128
131
  <button
129
132
  type="button"
130
- class="tooltip btn btn-square btn-xs"
131
- class:btn-active={activeEditor?.isActive('strike')}
133
+ class={[
134
+ 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
135
+ activeEditor?.isActive('strike') ? 'uncial-btn--active' : 'uncial-btn--ghost'
136
+ ]}
132
137
  aria-label="Strikethrough"
133
138
  data-tip="Strikethrough"
134
139
  onclick={() => runCommand(() => editor?.chain().focus().toggleStrike().run() ?? false)}
@@ -139,8 +144,10 @@
139
144
  {#if canCode}
140
145
  <button
141
146
  type="button"
142
- class="tooltip btn btn-square btn-xs"
143
- class:btn-active={activeEditor?.isActive('code')}
147
+ class={[
148
+ 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
149
+ activeEditor?.isActive('code') ? 'uncial-btn--active' : 'uncial-btn--ghost'
150
+ ]}
144
151
  aria-label="Inline code"
145
152
  data-tip="Inline code"
146
153
  onclick={() => runCommand(() => editor?.chain().focus().toggleCode().run() ?? false)}
@@ -151,8 +158,10 @@
151
158
  {#if canHeading}
152
159
  <button
153
160
  type="button"
154
- class="tooltip btn btn-square btn-xs"
155
- class:btn-active={activeEditor?.isActive('heading')}
161
+ class={[
162
+ 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
163
+ activeEditor?.isActive('heading') ? 'uncial-btn--active' : 'uncial-btn--ghost'
164
+ ]}
156
165
  aria-label="Heading"
157
166
  data-tip="Heading"
158
167
  onclick={() =>
@@ -164,8 +173,10 @@
164
173
  {#if canBulletList}
165
174
  <button
166
175
  type="button"
167
- class="tooltip btn btn-square btn-xs"
168
- class:btn-active={activeEditor?.isActive('bulletList')}
176
+ class={[
177
+ 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
178
+ activeEditor?.isActive('bulletList') ? 'uncial-btn--active' : 'uncial-btn--ghost'
179
+ ]}
169
180
  aria-label="Bullet list"
170
181
  data-tip="Bullet list"
171
182
  onclick={() => runCommand(() => editor?.chain().focus().toggleBulletList().run() ?? false)}
@@ -176,8 +187,10 @@
176
187
  {#if canOrderedList}
177
188
  <button
178
189
  type="button"
179
- class="tooltip btn btn-square btn-xs"
180
- class:btn-active={activeEditor?.isActive('orderedList')}
190
+ class={[
191
+ 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
192
+ activeEditor?.isActive('orderedList') ? 'uncial-btn--active' : 'uncial-btn--ghost'
193
+ ]}
181
194
  aria-label="Ordered list"
182
195
  data-tip="Ordered list"
183
196
  onclick={() => runCommand(() => editor?.chain().focus().toggleOrderedList().run() ?? false)}
@@ -188,8 +201,10 @@
188
201
  {#if canBlockquote}
189
202
  <button
190
203
  type="button"
191
- class="tooltip btn btn-square btn-xs"
192
- class:btn-active={activeEditor?.isActive('blockquote')}
204
+ class={[
205
+ 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
206
+ activeEditor?.isActive('blockquote') ? 'uncial-btn--active' : 'uncial-btn--ghost'
207
+ ]}
193
208
  aria-label="Blockquote"
194
209
  data-tip="Blockquote"
195
210
  onclick={() => runCommand(() => editor?.chain().focus().toggleBlockquote().run() ?? false)}
@@ -200,8 +215,10 @@
200
215
  {#if canCodeBlock}
201
216
  <button
202
217
  type="button"
203
- class="tooltip btn btn-square btn-xs"
204
- class:btn-active={activeEditor?.isActive('codeBlock')}
218
+ class={[
219
+ 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
220
+ activeEditor?.isActive('codeBlock') ? 'uncial-btn--active' : 'uncial-btn--ghost'
221
+ ]}
205
222
  aria-label="Code block"
206
223
  data-tip="Code block"
207
224
  onclick={() => runCommand(() => editor?.chain().focus().toggleCodeBlock().run() ?? false)}
@@ -212,7 +229,7 @@
212
229
  {#if canHorizontalRule}
213
230
  <button
214
231
  type="button"
215
- class="tooltip btn btn-square btn-xs"
232
+ class="uncial-btn uncial-btn--ghost uncial-btn--square uncial-btn--xs uncial-tooltip"
216
233
  aria-label="Horizontal rule"
217
234
  data-tip="Horizontal rule"
218
235
  onclick={() => runCommand(() => editor?.chain().focus().setHorizontalRule().run() ?? false)}
@@ -223,10 +240,3 @@
223
240
  </div>
224
241
  <div bind:this={element}></div>
225
242
  </div>
226
-
227
- <style>
228
- :global(.uncial-richtext-editor.ProseMirror:focus) {
229
- outline: none;
230
- box-shadow: none;
231
- }
232
- </style>
@@ -1,6 +1,7 @@
1
1
  <script lang="ts">
2
2
  import type { Editor } from '@tiptap/core';
3
3
  import type { Component } from 'svelte';
4
+ import { createSubscriber } from 'svelte/reactivity';
4
5
  import CodeIcon from 'phosphor-svelte/lib/CodeIcon';
5
6
  import CodeBlockIcon from 'phosphor-svelte/lib/CodeBlockIcon';
6
7
  import LinkIcon from 'phosphor-svelte/lib/LinkIcon';
@@ -55,6 +56,37 @@
55
56
  }
56
57
  return groups;
57
58
  });
59
+ const getEditorStateVersion = $derived.by(() => {
60
+ if (!editor) return () => 0;
61
+ const activeEditor = editor;
62
+
63
+ let version = 0;
64
+ const subscribe = createSubscriber((update) => {
65
+ const refreshToolbarState = () => {
66
+ version += 1;
67
+ update();
68
+ };
69
+
70
+ activeEditor.on('transaction', refreshToolbarState);
71
+ activeEditor.on('selectionUpdate', refreshToolbarState);
72
+ activeEditor.on('update', refreshToolbarState);
73
+
74
+ return () => {
75
+ activeEditor.off('transaction', refreshToolbarState);
76
+ activeEditor.off('selectionUpdate', refreshToolbarState);
77
+ activeEditor.off('update', refreshToolbarState);
78
+ };
79
+ });
80
+
81
+ return () => {
82
+ subscribe();
83
+ return version;
84
+ };
85
+ });
86
+ const toolbarContext = $derived.by(() => {
87
+ getEditorStateVersion();
88
+ return editor ? { editor, schema } : null;
89
+ });
58
90
 
59
91
  function runFeature(feature: ToolbarFeature): void {
60
92
  if (feature.id === 'link' && onEditLink) {
@@ -91,11 +123,11 @@
91
123
  }
92
124
  </script>
93
125
 
94
- <div class="contents">
126
+ <div>
95
127
  {#each groupedFeatures as group (group.group)}
96
- <div class="join">
128
+ <div class="uncial-join">
97
129
  {#each group.features as feature (feature.id)}
98
- {@const context = editor ? { editor, schema } : null}
130
+ {@const context = toolbarContext}
99
131
  {@const Icon = iconFor(feature.id)}
100
132
  {@const active = context ? (feature.isActive?.(context) ?? false) : false}
101
133
  {@const disabled = !context || !(feature.canRun?.(context) ?? true)}
@@ -103,12 +135,13 @@
103
135
  type="button"
104
136
  aria-label={feature.label}
105
137
  data-tip={feature.tooltip ?? feature.label}
138
+ data-uncial-tooltip-position="bottom"
106
139
  aria-pressed={active ? 'true' : 'false'}
107
- disabled={disabled}
140
+ {disabled}
108
141
  class={[
109
- 'btn btn-sm join-item tooltip tooltip-bottom',
110
- feature.label.length <= 2 ? 'btn-square' : '',
111
- active ? 'btn-neutral' : 'btn-ghost'
142
+ 'uncial-btn uncial-btn--sm uncial-join__item uncial-tooltip',
143
+ feature.label.length <= 2 ? 'uncial-btn--square' : '',
144
+ active ? 'uncial-btn--active' : 'uncial-btn--ghost'
112
145
  ]}
113
146
  onclick={() => runFeature(feature)}
114
147
  >
@@ -6,10 +6,12 @@ export interface BindEditorOptions {
6
6
  blocks?: BlockRegistry | BlockDefinition[];
7
7
  schema?: ContentSchema;
8
8
  json?: JSONContent;
9
+ meta?: Record<string, unknown>;
9
10
  extensions?: AnyExtension[];
10
11
  attributesController?: BlockAttributesController | null;
11
12
  onIssue?: (issue: ValidationIssue) => void;
12
13
  onChange?: (json: JSONContent) => void;
14
+ onMetaChange?: (meta: Record<string, unknown>) => void;
13
15
  onEditor?: (editor: TiptapEditor | null) => void;
14
16
  }
15
17
  export declare function bindEditor(node: HTMLElement, initialOptions?: BindEditorOptions): ActionReturn<BindEditorOptions>;
@@ -6,8 +6,9 @@ import { emptyDocument } from '../shared/content.js';
6
6
  import { createEditorExtensions } from '../shared/tiptap.js';
7
7
  import { createBlockAttributesController } from './attributesController.js';
8
8
  function toEditorDocument(document) {
9
- const { version: _version, ...editorDocument } = document;
9
+ const { version: _version, meta: _meta, ...editorDocument } = document;
10
10
  void _version;
11
+ void _meta;
11
12
  return editorDocument;
12
13
  }
13
14
  function createInitialControllerState() {
@@ -39,7 +40,7 @@ export function bindEditor(node, initialOptions = {}) {
39
40
  let editor = null;
40
41
  let lastSerialized = '';
41
42
  function normalizeAndValidate(document) {
42
- const normalized = normalizeDocument(document, registry, schema);
43
+ const normalized = normalizeDocument({ ...(document ?? emptyDocument()), meta: options.meta }, registry, schema);
43
44
  if (schema) {
44
45
  validateDocument(normalized, registry, schema, { onIssue: options.onIssue });
45
46
  }
@@ -80,6 +81,10 @@ export function bindEditor(node, initialOptions = {}) {
80
81
  if (serialized !== JSON.stringify(options.json ?? emptyDocument())) {
81
82
  options.onChange?.(nextDocument);
82
83
  }
84
+ const nextMeta = nextDocument.meta ?? {};
85
+ if (JSON.stringify(nextMeta) !== JSON.stringify(options.meta ?? {})) {
86
+ options.onMetaChange?.(nextMeta);
87
+ }
83
88
  }
84
89
  function createEditor() {
85
90
  const initialContent = normalizeAndValidate(options.json ?? emptyDocument());
@@ -1,11 +1,15 @@
1
1
  export { default as Editor } from './Editor.svelte';
2
2
  export { default as BlockAttributesPanel } from './BlockAttributesPanel.svelte';
3
+ export { default as AttributeFieldControl } from './AttributeFieldControl.svelte';
4
+ export { default as DocumentMetaPanel } from './DocumentMetaPanel.svelte';
3
5
  export { default as Toolbar } from './Toolbar.svelte';
4
6
  export { default as BlockMenu } from './BlockMenu.svelte';
5
7
  export { bindEditor } from './bindEditor.js';
6
8
  export { createEditorExtensions } from './createEditorExtensions.js';
7
9
  export { createBlockAttributesController } from './attributesController.js';
10
+ export { createDocumentMetaController } from './metaController.js';
8
11
  export { builtinToolbarFeatures, defaultToolbarFeatures, resolveToolbarFeatures } from './toolbarFeatures.js';
9
12
  export type { BindEditorOptions } from './bindEditor.js';
10
13
  export type { ToolbarFeature, ToolbarFeatureContext, ToolbarFeatureId, ToolbarFeatureSelection } from './toolbarFeatures.js';
11
14
  export type { ActiveBlockSelection, BlockAttributeMode, BlockAttributesController, BlockAttributesState, ContainerChildInfo, LinkAttributes, LinkAttributesState } from './attributesController.js';
15
+ export type { DocumentMetaCommitResult, DocumentMetaController, DocumentMetaState } from './metaController.js';
@@ -1,8 +1,11 @@
1
1
  export { default as Editor } from './Editor.svelte';
2
2
  export { default as BlockAttributesPanel } from './BlockAttributesPanel.svelte';
3
+ export { default as AttributeFieldControl } from './AttributeFieldControl.svelte';
4
+ export { default as DocumentMetaPanel } from './DocumentMetaPanel.svelte';
3
5
  export { default as Toolbar } from './Toolbar.svelte';
4
6
  export { default as BlockMenu } from './BlockMenu.svelte';
5
7
  export { bindEditor } from './bindEditor.js';
6
8
  export { createEditorExtensions } from './createEditorExtensions.js';
7
9
  export { createBlockAttributesController } from './attributesController.js';
10
+ export { createDocumentMetaController } from './metaController.js';
8
11
  export { builtinToolbarFeatures, defaultToolbarFeatures, resolveToolbarFeatures } from './toolbarFeatures.js';
@@ -0,0 +1,19 @@
1
+ import { type Readable } from 'svelte/store';
2
+ import type { AttributeSpec, ValidationResult } from '../core/types.js';
3
+ export interface DocumentMetaState {
4
+ draft: Record<string, unknown>;
5
+ errors: Record<string, string>;
6
+ dirty: boolean;
7
+ }
8
+ export interface DocumentMetaCommitResult {
9
+ meta: Record<string, unknown>;
10
+ validation: ValidationResult;
11
+ }
12
+ export interface DocumentMetaController extends Readable<DocumentMetaState> {
13
+ getMeta(): Record<string, unknown>;
14
+ setDraft(name: string, value: unknown): void;
15
+ reset(meta?: Record<string, unknown>): void;
16
+ commit(): DocumentMetaCommitResult;
17
+ setMetaFields(fields: ReadonlyMap<string, AttributeSpec<unknown>>): void;
18
+ }
19
+ export declare function createDocumentMetaController(fields?: ReadonlyMap<string, AttributeSpec<unknown>>, meta?: Record<string, unknown>): DocumentMetaController;
@@ -0,0 +1,71 @@
1
+ import { get, writable } from 'svelte/store';
2
+ import { parseMetaDraftValues, toMetaDraftValues, validateMeta } from '../core/meta.js';
3
+ const INITIAL_STATE = {
4
+ draft: {},
5
+ errors: {},
6
+ dirty: false
7
+ };
8
+ function errorsFromIssues(issues) {
9
+ const errors = {};
10
+ for (const issue of issues) {
11
+ if (issue.severity !== 'error')
12
+ continue;
13
+ const field = issue.path[0] === 'meta' ? String(issue.path[1] ?? '') : '';
14
+ if (field)
15
+ errors[field] = issue.message;
16
+ }
17
+ return errors;
18
+ }
19
+ export function createDocumentMetaController(fields = new Map(), meta = {}) {
20
+ const state = writable({
21
+ draft: toMetaDraftValues(fields, meta),
22
+ errors: {},
23
+ dirty: false
24
+ });
25
+ let metaFields = fields;
26
+ let currentMeta = parseMetaDraftValues(fields, get(state).draft);
27
+ return {
28
+ subscribe: state.subscribe,
29
+ getMeta() {
30
+ return currentMeta;
31
+ },
32
+ setDraft(name, value) {
33
+ state.update((current) => ({
34
+ ...current,
35
+ draft: { ...current.draft, [name]: value },
36
+ errors: { ...current.errors, [name]: '' },
37
+ dirty: true
38
+ }));
39
+ },
40
+ reset(nextMeta = currentMeta) {
41
+ currentMeta = parseMetaDraftValues(metaFields, toMetaDraftValues(metaFields, nextMeta));
42
+ state.set({
43
+ draft: toMetaDraftValues(metaFields, currentMeta),
44
+ errors: {},
45
+ dirty: false
46
+ });
47
+ },
48
+ commit() {
49
+ const nextMeta = parseMetaDraftValues(metaFields, get(state).draft);
50
+ const issues = [];
51
+ validateMeta(nextMeta, metaFields, issues);
52
+ const validation = {
53
+ ok: !issues.some((issue) => issue.severity === 'error'),
54
+ issues
55
+ };
56
+ if (validation.ok) {
57
+ currentMeta = nextMeta;
58
+ }
59
+ state.update((current) => ({
60
+ ...current,
61
+ errors: errorsFromIssues(issues),
62
+ dirty: !validation.ok
63
+ }));
64
+ return { meta: nextMeta, validation };
65
+ },
66
+ setMetaFields(fields) {
67
+ metaFields = fields;
68
+ this.reset(currentMeta);
69
+ }
70
+ };
71
+ }
@@ -1,5 +1,6 @@
1
1
  <script lang="ts">
2
2
  import type { JSONContent } from '@tiptap/core';
3
+ import type { Snippet } from 'svelte';
3
4
  import { normalizeDocument } from '../core/normalize.js';
4
5
  import { validateDocument } from '../core/validate.js';
5
6
  import type {
@@ -18,10 +19,17 @@
18
19
  content?: JSONContent;
19
20
  blocks?: BlockRegistry | BlockDefinition[];
20
21
  schema?: ContentSchema;
22
+ meta?: Snippet<[Record<string, unknown> | undefined]>;
21
23
  onIssue?: (issue: ValidationIssue) => void;
22
24
  }
23
25
 
24
- let { content = emptyDocument(), blocks = [], schema = undefined, onIssue }: Props = $props();
26
+ let {
27
+ content = emptyDocument(),
28
+ blocks = [],
29
+ schema = undefined,
30
+ meta: metaSnippet = undefined,
31
+ onIssue
32
+ }: Props = $props();
25
33
 
26
34
  const registry = $derived.by(() => {
27
35
  const resolved = resolveRegistry(blocks);
@@ -41,8 +49,9 @@
41
49
  });
42
50
  </script>
43
51
 
44
- <div class="uncial-renderer rounded-box border border-base-300 bg-base-100 shadow-sm">
45
- <div class="uncial-content uncial-rich-content min-h-112 p-5 leading-7 sm:p-8">
52
+ <div class="uncial-renderer">
53
+ {@render metaSnippet?.(normalizedContent.meta)}
54
+ <div class="uncial-content uncial-rich-content">
46
55
  <RichContent nodes={(normalizedContent.content ?? []) as PMNode[]} {registry} {schema} />
47
56
  </div>
48
57
  </div>
@@ -1,9 +1,11 @@
1
1
  import type { JSONContent } from '@tiptap/core';
2
+ import type { Snippet } from 'svelte';
2
3
  import type { BlockDefinition, BlockRegistry, ContentSchema, ValidationIssue } from '../core/types.js';
3
4
  interface Props {
4
5
  content?: JSONContent;
5
6
  blocks?: BlockRegistry | BlockDefinition[];
6
7
  schema?: ContentSchema;
8
+ meta?: Snippet<[Record<string, unknown> | undefined]>;
7
9
  onIssue?: (issue: ValidationIssue) => void;
8
10
  }
9
11
  declare const Renderer: import("svelte").Component<Props, {}, "">;
@@ -1,5 +1,4 @@
1
1
  <script lang="ts">
2
- import { resolve } from '$app/paths';
3
2
  import type { Component } from 'svelte';
4
3
  import type { BlockRegistry, ContentSchema } from '../core/types.js';
5
4
  import type { PMMark, PMNode } from '../shared/document.js';
@@ -56,12 +55,8 @@
56
55
  {:else if mark.type === 'link'}
57
56
  {@const href = sanitizeHref(mark.attrs?.href)}
58
57
  {#if href}
59
- {#if href.startsWith('/')}
60
- <a href={resolve(href as '/')}>{@render renderMarkedText(text, rest)}</a>
61
- {:else}
62
- <!-- eslint-disable-next-line svelte/no-navigation-without-resolve -- sanitized rich-text links may be external, mailto, tel, or hash URLs -->
63
- <a {href}>{@render renderMarkedText(text, rest)}</a>
64
- {/if}
58
+ <!-- eslint-disable-next-line svelte/no-navigation-without-resolve -- sanitized rich-text links may be external, app-relative, mailto, tel, or hash URLs -->
59
+ <a {href}>{@render renderMarkedText(text, rest)}</a>
65
60
  {:else}
66
61
  {@render renderMarkedText(text, rest)}
67
62
  {/if}
@@ -81,7 +76,7 @@
81
76
  {@const RenderComponent = getSvelteRenderComponent(block.components.render.component)}
82
77
  <RenderComponent
83
78
  {...blockAttrs}
84
- {...((block as unknown as { renderProps?: Record<string, unknown> }).renderProps ?? {})}
79
+ {...(block as unknown as { renderProps?: Record<string, unknown> }).renderProps ?? {}}
85
80
  content={blockContent}
86
81
  children={block.content ? blockChildren : undefined}
87
82
  />
@@ -22,7 +22,8 @@
22
22
  const nodes = $derived(filterRichTextNodes(document.content ?? [], resolvedFeatures));
23
23
  const schema = $derived<ContentSchema>({
24
24
  allowedBlocks: new Set(),
25
- allowedMarks: resolvedFeatures
25
+ allowedMarks: resolvedFeatures,
26
+ metaFields: new Map()
26
27
  });
27
28
  </script>
28
29
 
@@ -1,2 +1,3 @@
1
1
  import type { JSONContent } from '@tiptap/core';
2
- export declare function emptyDocument(): JSONContent;
2
+ import type { AttributeSpec } from '../core/types.js';
3
+ export declare function emptyDocument(metaFields?: ReadonlyMap<string, AttributeSpec<unknown>>): JSONContent;
@@ -1,7 +1,12 @@
1
- export function emptyDocument() {
2
- return {
1
+ import { normalizeMeta } from '../core/meta.js';
2
+ export function emptyDocument(metaFields = new Map()) {
3
+ const document = {
3
4
  type: 'doc',
4
5
  version: 1,
5
6
  content: [{ type: 'paragraph' }]
6
7
  };
8
+ if (metaFields.size > 0) {
9
+ document.meta = normalizeMeta({}, metaFields);
10
+ }
11
+ return document;
7
12
  }
@@ -12,6 +12,7 @@ export interface PMNode {
12
12
  export interface PMDoc {
13
13
  type: 'doc';
14
14
  version?: number;
15
+ meta?: Record<string, unknown>;
15
16
  content?: PMNode[];
16
17
  }
17
18
  export type PMPathSegment = number | 'attrs' | 'marks' | 'content' | 'text' | string;