uncial 0.0.7 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +82 -15
  2. package/dist/core/attributes.d.ts +21 -3
  3. package/dist/core/attributes.js +86 -15
  4. package/dist/core/defineBlock.js +26 -12
  5. package/dist/core/index.d.ts +3 -1
  6. package/dist/core/index.js +2 -1
  7. package/dist/core/issues.d.ts +7 -0
  8. package/dist/core/issues.js +9 -0
  9. package/dist/core/meta.js +2 -7
  10. package/dist/core/migrations.d.ts +30 -0
  11. package/dist/core/migrations.js +50 -0
  12. package/dist/core/normalize.d.ts +12 -1
  13. package/dist/core/normalize.js +123 -22
  14. package/dist/core/registry.d.ts +7 -0
  15. package/dist/core/registry.js +35 -4
  16. package/dist/core/runtime.d.ts +7 -0
  17. package/dist/core/types.d.ts +31 -3
  18. package/dist/core/validate.js +27 -7
  19. package/dist/editor/AttributeFieldControl.svelte +155 -7
  20. package/dist/editor/AttributeFieldControl.svelte.d.ts +1 -0
  21. package/dist/editor/BlockAttributesPanel.svelte +76 -44
  22. package/dist/editor/BlockAttributesPanel.svelte.d.ts +9 -1
  23. package/dist/editor/Editor.svelte +149 -27
  24. package/dist/editor/Editor.svelte.d.ts +37 -0
  25. package/dist/editor/RichTextAttributeEditor.svelte +75 -145
  26. package/dist/editor/RichTextAttributeEditor.svelte.d.ts +2 -1
  27. package/dist/editor/Toolbar.svelte +2 -3
  28. package/dist/editor/attributeTargets.d.ts +23 -0
  29. package/dist/editor/attributeTargets.js +21 -0
  30. package/dist/editor/attributesController.d.ts +12 -0
  31. package/dist/editor/attributesController.js +142 -230
  32. package/dist/editor/bindEditor.d.ts +7 -0
  33. package/dist/editor/bindEditor.js +141 -27
  34. package/dist/editor/chooseAttribute.d.ts +26 -0
  35. package/dist/editor/chooseAttribute.js +10 -0
  36. package/dist/editor/containerChildOps.d.ts +33 -0
  37. package/dist/editor/containerChildOps.js +115 -0
  38. package/dist/editor/dropdownDismiss.d.ts +18 -0
  39. package/dist/editor/dropdownDismiss.js +46 -0
  40. package/dist/editor/dropdownFloat.d.ts +16 -0
  41. package/dist/editor/dropdownFloat.js +127 -0
  42. package/dist/editor/index.d.ts +3 -1
  43. package/dist/editor/index.js +2 -1
  44. package/dist/editor/linkController.d.ts +19 -0
  45. package/dist/editor/linkController.js +72 -0
  46. package/dist/editor/toolbarFeatures.d.ts +12 -0
  47. package/dist/editor/toolbarFeatures.js +36 -0
  48. package/dist/index.d.ts +1 -0
  49. package/dist/index.js +1 -0
  50. package/dist/render/Renderer.svelte +1 -1
  51. package/dist/render/RichContent.svelte +12 -4
  52. package/dist/render/RichContent.svelte.d.ts +2 -0
  53. package/dist/render/RichNode.svelte +80 -10
  54. package/dist/render/RichNode.svelte.d.ts +2 -0
  55. package/dist/render/Tab.svelte +27 -0
  56. package/dist/render/Tab.svelte.d.ts +10 -0
  57. package/dist/render/Tabs.svelte +57 -0
  58. package/dist/render/Tabs.svelte.d.ts +10 -0
  59. package/dist/render/index.d.ts +3 -0
  60. package/dist/render/index.js +6 -0
  61. package/dist/render/sanitize.d.ts +6 -0
  62. package/dist/render/sanitize.js +20 -1
  63. package/dist/render/tabSelection.svelte.d.ts +8 -0
  64. package/dist/render/tabSelection.svelte.js +40 -0
  65. package/dist/runtime/reactiveProps.svelte.d.ts +16 -0
  66. package/dist/runtime/reactiveProps.svelte.js +16 -0
  67. package/dist/runtime/svelte.d.ts +2 -1
  68. package/dist/runtime/svelte.js +26 -6
  69. package/dist/shared/EditorBlockFixture.svelte +24 -0
  70. package/dist/shared/EditorBlockFixture.svelte.d.ts +9 -0
  71. package/dist/shared/content.js +2 -1
  72. package/dist/shared/documentIdentity.d.ts +6 -0
  73. package/dist/shared/documentIdentity.js +64 -0
  74. package/dist/shared/guards.d.ts +13 -0
  75. package/dist/shared/guards.js +16 -0
  76. package/dist/shared/richText.js +20 -4
  77. package/dist/shared/runtimeId.d.ts +8 -0
  78. package/dist/shared/runtimeId.js +8 -0
  79. package/dist/shared/syntaxHighlight.d.ts +14 -0
  80. package/dist/shared/syntaxHighlight.js +36 -3
  81. package/dist/shared/tiptap.js +140 -27
  82. package/dist/styles/base.css +177 -0
  83. package/dist/styles/prose.css +26 -0
  84. package/dist/styles/tokens.css +53 -69
  85. package/dist/tabs.d.ts +6 -0
  86. package/dist/tabs.js +36 -0
  87. package/dist/web-components/UncialEditor.svelte +23 -7
  88. package/dist/web-components/UncialEditor.svelte.d.ts +7 -2
  89. package/dist/web-components/index.d.ts +45 -10
  90. package/dist/web-components/index.js +98 -36
  91. package/dist/web-components/reactiveProps.svelte.d.ts +10 -0
  92. package/dist/web-components/reactiveProps.svelte.js +13 -0
  93. package/package.json +134 -133
@@ -1,5 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { Editor } from '@tiptap/core';
3
+ import type { Component } from 'svelte';
4
+ import { createSubscriber } from 'svelte/reactivity';
3
5
  import CodeIcon from 'phosphor-svelte/lib/CodeIcon';
4
6
  import CodeBlockIcon from 'phosphor-svelte/lib/CodeBlockIcon';
5
7
  import ListBulletsIcon from 'phosphor-svelte/lib/ListBulletsIcon';
@@ -14,7 +16,8 @@
14
16
  import type { PMDoc } from '../shared/document.js';
15
17
  import { coerceRichTextDocument, resolveRichTextFeatures } from '../shared/richText.js';
16
18
  import { createRichTextExtensions } from '../shared/tiptap.js';
17
- import type { RichTextFeatureSelection } from '../core/types.js';
19
+ import type { RichTextFeature, RichTextFeatureSelection } from '../core/types.js';
20
+ import { richTextAttributeToolbarFeatures, type ToolbarFeature } from './toolbarFeatures.js';
18
21
 
19
22
  interface Props {
20
23
  value?: unknown;
@@ -35,17 +38,43 @@
35
38
  let lastJson = '';
36
39
 
37
40
  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'));
41
+ const visibleFeatures = $derived(
42
+ richTextAttributeToolbarFeatures.filter((feature) =>
43
+ resolvedFeatures.has(feature.id as RichTextFeature)
44
+ )
45
+ );
46
+
47
+ const getEditorStateVersion = $derived.by(() => {
48
+ if (!editor) return () => 0;
49
+ const activeEditor = editor;
50
+
51
+ let version = 0;
52
+ const subscribe = createSubscriber((update) => {
53
+ const refreshToolbarState = () => {
54
+ version += 1;
55
+ update();
56
+ };
57
+
58
+ activeEditor.on('transaction', refreshToolbarState);
59
+ activeEditor.on('selectionUpdate', refreshToolbarState);
60
+ activeEditor.on('update', refreshToolbarState);
61
+
62
+ return () => {
63
+ activeEditor.off('transaction', refreshToolbarState);
64
+ activeEditor.off('selectionUpdate', refreshToolbarState);
65
+ activeEditor.off('update', refreshToolbarState);
66
+ };
67
+ });
68
+
69
+ return () => {
70
+ subscribe();
71
+ return version;
72
+ };
73
+ });
74
+ const toolbarContext = $derived.by(() => {
75
+ getEditorStateVersion();
76
+ return editor ? { editor } : null;
77
+ });
49
78
 
50
79
  function emitChange(nextEditor: Editor): void {
51
80
  const json = nextEditor.getJSON() as PMDoc;
@@ -53,8 +82,26 @@
53
82
  onChange(json);
54
83
  }
55
84
 
56
- function runCommand(command: () => boolean): void {
57
- command();
85
+ function runFeature(feature: ToolbarFeature): void {
86
+ if (!editor) return;
87
+ feature.run({ editor });
88
+ }
89
+
90
+ function iconFor(featureId: string): Component<Record<string, unknown>> | null {
91
+ return (
92
+ {
93
+ bold: TextBIcon,
94
+ italic: TextItalicIcon,
95
+ strike: TextStrikethroughIcon,
96
+ code: CodeIcon,
97
+ heading: TextHThreeIcon,
98
+ bulletList: ListBulletsIcon,
99
+ orderedList: ListNumbersIcon,
100
+ blockquote: QuotesIcon,
101
+ codeBlock: CodeBlockIcon,
102
+ horizontalRule: MinusIcon
103
+ }[featureId] ?? null
104
+ );
58
105
  }
59
106
 
60
107
  const iconSize = 14;
@@ -99,144 +146,27 @@
99
146
 
100
147
  <div class="uncial-richtext-wrapper">
101
148
  <div class="uncial-richtext-toolbar">
102
- {#if canBold}
149
+ {#each visibleFeatures as feature (feature.id)}
150
+ {@const context = toolbarContext}
151
+ {@const Icon = iconFor(feature.id)}
152
+ {@const active = context ? (feature.isActive?.(context) ?? false) : false}
103
153
  <button
104
154
  type="button"
105
155
  class={[
106
156
  'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
107
- activeEditor?.isActive('bold') ? 'uncial-btn--active' : 'uncial-btn--ghost'
157
+ active ? 'uncial-btn--active' : 'uncial-btn--ghost'
108
158
  ]}
109
- aria-label="Bold"
110
- data-tip="Bold"
111
- onclick={() => runCommand(() => editor?.chain().focus().toggleBold().run() ?? false)}
112
- >
113
- <TextBIcon size={iconSize} weight="bold" />
114
- </button>
115
- {/if}
116
- {#if canItalic}
117
- <button
118
- type="button"
119
- class={[
120
- 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
121
- activeEditor?.isActive('italic') ? 'uncial-btn--active' : 'uncial-btn--ghost'
122
- ]}
123
- aria-label="Italic"
124
- data-tip="Italic"
125
- onclick={() => runCommand(() => editor?.chain().focus().toggleItalic().run() ?? false)}
126
- >
127
- <TextItalicIcon size={iconSize} weight="bold" />
128
- </button>
129
- {/if}
130
- {#if canStrike}
131
- <button
132
- type="button"
133
- class={[
134
- 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
135
- activeEditor?.isActive('strike') ? 'uncial-btn--active' : 'uncial-btn--ghost'
136
- ]}
137
- aria-label="Strikethrough"
138
- data-tip="Strikethrough"
139
- onclick={() => runCommand(() => editor?.chain().focus().toggleStrike().run() ?? false)}
140
- >
141
- <TextStrikethroughIcon size={iconSize} weight="bold" />
142
- </button>
143
- {/if}
144
- {#if canCode}
145
- <button
146
- type="button"
147
- class={[
148
- 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
149
- activeEditor?.isActive('code') ? 'uncial-btn--active' : 'uncial-btn--ghost'
150
- ]}
151
- aria-label="Inline code"
152
- data-tip="Inline code"
153
- onclick={() => runCommand(() => editor?.chain().focus().toggleCode().run() ?? false)}
154
- >
155
- <CodeIcon size={iconSize} weight="bold" />
156
- </button>
157
- {/if}
158
- {#if canHeading}
159
- <button
160
- type="button"
161
- class={[
162
- 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
163
- activeEditor?.isActive('heading') ? 'uncial-btn--active' : 'uncial-btn--ghost'
164
- ]}
165
- aria-label="Heading"
166
- data-tip="Heading"
167
- onclick={() =>
168
- runCommand(() => editor?.chain().focus().toggleHeading({ level: 3 }).run() ?? false)}
169
- >
170
- <TextHThreeIcon size={iconSize} weight="bold" />
171
- </button>
172
- {/if}
173
- {#if canBulletList}
174
- <button
175
- type="button"
176
- class={[
177
- 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
178
- activeEditor?.isActive('bulletList') ? 'uncial-btn--active' : 'uncial-btn--ghost'
179
- ]}
180
- aria-label="Bullet list"
181
- data-tip="Bullet list"
182
- onclick={() => runCommand(() => editor?.chain().focus().toggleBulletList().run() ?? false)}
183
- >
184
- <ListBulletsIcon size={iconSize} weight="bold" />
185
- </button>
186
- {/if}
187
- {#if canOrderedList}
188
- <button
189
- type="button"
190
- class={[
191
- 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
192
- activeEditor?.isActive('orderedList') ? 'uncial-btn--active' : 'uncial-btn--ghost'
193
- ]}
194
- aria-label="Ordered list"
195
- data-tip="Ordered list"
196
- onclick={() => runCommand(() => editor?.chain().focus().toggleOrderedList().run() ?? false)}
197
- >
198
- <ListNumbersIcon size={iconSize} weight="bold" />
199
- </button>
200
- {/if}
201
- {#if canBlockquote}
202
- <button
203
- type="button"
204
- class={[
205
- 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
206
- activeEditor?.isActive('blockquote') ? 'uncial-btn--active' : 'uncial-btn--ghost'
207
- ]}
208
- aria-label="Blockquote"
209
- data-tip="Blockquote"
210
- onclick={() => runCommand(() => editor?.chain().focus().toggleBlockquote().run() ?? false)}
211
- >
212
- <QuotesIcon size={iconSize} weight="bold" />
213
- </button>
214
- {/if}
215
- {#if canCodeBlock}
216
- <button
217
- type="button"
218
- class={[
219
- 'uncial-btn uncial-btn--square uncial-btn--xs uncial-tooltip',
220
- activeEditor?.isActive('codeBlock') ? 'uncial-btn--active' : 'uncial-btn--ghost'
221
- ]}
222
- aria-label="Code block"
223
- data-tip="Code block"
224
- onclick={() => runCommand(() => editor?.chain().focus().toggleCodeBlock().run() ?? false)}
225
- >
226
- <CodeBlockIcon size={iconSize} weight="bold" />
227
- </button>
228
- {/if}
229
- {#if canHorizontalRule}
230
- <button
231
- type="button"
232
- class="uncial-btn uncial-btn--ghost uncial-btn--square uncial-btn--xs uncial-tooltip"
233
- aria-label="Horizontal rule"
234
- data-tip="Horizontal rule"
235
- onclick={() => runCommand(() => editor?.chain().focus().setHorizontalRule().run() ?? false)}
159
+ aria-label={feature.label}
160
+ data-tip={feature.tooltip ?? feature.label}
161
+ onclick={() => runFeature(feature)}
236
162
  >
237
- <MinusIcon size={iconSize} weight="bold" />
163
+ {#if Icon}
164
+ <Icon size={iconSize} weight="bold" />
165
+ {:else}
166
+ {feature.label}
167
+ {/if}
238
168
  </button>
239
- {/if}
169
+ {/each}
240
170
  </div>
241
171
  <div bind:this={element}></div>
242
172
  </div>
@@ -1,3 +1,4 @@
1
+ import type { Component } from 'svelte';
1
2
  import type { PMDoc } from '../shared/document.js';
2
3
  import type { RichTextFeatureSelection } from '../core/types.js';
3
4
  interface Props {
@@ -6,6 +7,6 @@ interface Props {
6
7
  placeholder?: string;
7
8
  onChange: (value: PMDoc) => void;
8
9
  }
9
- declare const RichTextAttributeEditor: import("svelte").Component<Props, {}, "">;
10
+ declare const RichTextAttributeEditor: Component<Props, {}, "">;
10
11
  type RichTextAttributeEditor = ReturnType<typeof RichTextAttributeEditor>;
11
12
  export default RichTextAttributeEditor;
@@ -90,9 +90,8 @@
90
90
 
91
91
  function runFeature(feature: ToolbarFeature): void {
92
92
  if (feature.id === 'link' && onEditLink) {
93
- if (editor && !editor.isActive('link')) {
94
- feature.run({ editor, schema });
95
- }
93
+ // Only open the link panel; the link mark is applied when the panel
94
+ // commits, so cancelling never leaves a dangling placeholder link.
96
95
  onEditLink();
97
96
  return;
98
97
  }
@@ -0,0 +1,23 @@
1
+ import type { BlockRegistry } from '../core/types.js';
2
+ import type { AttributeDefinition } from '../core/attributes.js';
3
+ /** A block type's attribute metadata; `content` (when present) marks a container. */
4
+ export type AttributeTarget = AttributeDefinition & {
5
+ content?: unknown;
6
+ };
7
+ /**
8
+ * Resolves attribute metadata for a block type, treating the built-in code block
9
+ * as a *virtual* registry entry. The code block carries editable attributes
10
+ * (its language) but is deliberately NOT part of `registry.blocks`, so it never
11
+ * leaks into block-insertion menus. Routing every `has`/`get`/`defaultAttrs`
12
+ * lookup through here keeps the `codeBlock` special case in one place instead of
13
+ * scattering `if (id === CODE_BLOCK_ID)` branches across the controller.
14
+ */
15
+ export interface AttributeTargets {
16
+ /** True for any type that carries editable attributes (a registry block or the code block). */
17
+ has(typeName: string): boolean;
18
+ /** The attribute definition for a type, or null if it has none. */
19
+ get(id: string): AttributeTarget | null;
20
+ /** Default attribute values used to seed an insert-mode draft for a type. */
21
+ defaultAttrs(id: string): Record<string, unknown>;
22
+ }
23
+ export declare function createAttributeTargets(registry: BlockRegistry | null): AttributeTargets;
@@ -0,0 +1,21 @@
1
+ import { getBlockDefaultAttrs } from '../shared/tiptap.js';
2
+ import { CODE_BLOCK_ID, codeBlockAttributeTarget } from '../shared/codeBlockAttributes.js';
3
+ export function createAttributeTargets(registry) {
4
+ return {
5
+ has(typeName) {
6
+ return typeName === CODE_BLOCK_ID || Boolean(registry?.has(typeName));
7
+ },
8
+ get(id) {
9
+ if (id === CODE_BLOCK_ID)
10
+ return codeBlockAttributeTarget;
11
+ return registry?.get(id) ?? null;
12
+ },
13
+ defaultAttrs(id) {
14
+ // The code block's language defaults are seeded from an empty draft.
15
+ if (id === CODE_BLOCK_ID)
16
+ return {};
17
+ const block = registry?.get(id);
18
+ return block ? getBlockDefaultAttrs(block) : {};
19
+ }
20
+ };
21
+ }
@@ -24,6 +24,11 @@ export interface ContainerChildInfo {
24
24
  blockId: string;
25
25
  label: string;
26
26
  summary: string;
27
+ /**
28
+ * Absolute document position of the child node, so the panel can select it
29
+ * with `openAttributesAt` without re-walking the document.
30
+ */
31
+ pos: number;
27
32
  }
28
33
  export interface BlockAttributesState {
29
34
  open: boolean;
@@ -61,4 +66,11 @@ export interface BlockAttributesController extends Readable<BlockAttributesState
61
66
  removeActiveBlock(): boolean;
62
67
  removeContainerChild(index: number): boolean;
63
68
  }
69
+ /**
70
+ * The single source of truth for a fresh controller state snapshot. Every
71
+ * consumer that needs an initial `BlockAttributesState` (the controller store,
72
+ * `bindEditor`, and the Svelte panels) imports this factory rather than
73
+ * duplicating the literal, so the shape can never drift between them.
74
+ */
75
+ export declare function createInitialState(): BlockAttributesState;
64
76
  export declare function createBlockAttributesController(): BlockAttributesController;