uncial 5.1.0 → 5.2.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.
@@ -13,6 +13,8 @@ export declare function attributeListValueSpec(list: AttributeListSpec): Attribu
13
13
  /** A new item carrying each declared default, ready to append to a list. */
14
14
  export declare function createAttributeListItem(list: AttributeListSpec): unknown;
15
15
  export declare function normalizeAttributeOptions<T>(spec: AttributeSpec<T>): AttributeOption<T>[] | undefined;
16
+ /** False for a host-defined kind, which a host input component or chooser edits. */
17
+ export declare function isBuiltInInputKind(kind: string): boolean;
16
18
  export declare function inferAttributeInputKind(spec: AttributeSpec<unknown>): AttributeInputKind;
17
19
  export declare function coerceAttributeValue<T>(spec: AttributeSpec<T>, value: unknown): T;
18
20
  export declare function normalizeBlockAttributes(block: AttributeDefinition, attrs?: Record<string, unknown>): Record<string, unknown>;
@@ -80,6 +80,24 @@ export function normalizeAttributeOptions(spec) {
80
80
  };
81
81
  });
82
82
  }
83
+ const BUILT_IN_INPUT_KINDS = new Set([
84
+ 'checkbox',
85
+ 'number',
86
+ 'date',
87
+ 'datetime',
88
+ 'richtext',
89
+ 'select',
90
+ 'textarea',
91
+ 'json',
92
+ 'list',
93
+ 'text',
94
+ 'hidden',
95
+ 'image'
96
+ ]);
97
+ /** False for a host-defined kind, which a host input component or chooser edits. */
98
+ export function isBuiltInInputKind(kind) {
99
+ return BUILT_IN_INPUT_KINDS.has(kind);
100
+ }
83
101
  export function inferAttributeInputKind(spec) {
84
102
  if (spec.input)
85
103
  return spec.input;
@@ -203,6 +221,10 @@ export function toAttributeDraftValue(spec, value) {
203
221
  // A list is edited as the array itself, one control per item.
204
222
  if (input === 'list')
205
223
  return Array.isArray(normalized) ? normalized : [];
224
+ // A host input edits the stored JSON itself.
225
+ if (!isBuiltInInputKind(input) && typeof normalized === 'object' && normalized !== null) {
226
+ return normalized;
227
+ }
206
228
  return String(normalized ?? '');
207
229
  }
208
230
  export function toAttributeDraftValues(block, attrs) {
@@ -1,5 +1,5 @@
1
1
  export { defineRuntimeBlock } from './defineBlock.js';
2
- export { coerceAttributeValue, inferAttributeInputKind, normalizeAttributeOptions, normalizeBlockAttributes, parseBlockDraftAttributes, serializeBlockAttributes, toAttributeDraftValues } from './attributes.js';
2
+ export { coerceAttributeValue, inferAttributeInputKind, isBuiltInInputKind, normalizeAttributeOptions, normalizeBlockAttributes, parseBlockDraftAttributes, serializeBlockAttributes, toAttributeDraftValues } from './attributes.js';
3
3
  export { normalizeMeta, parseMetaDraftValues, serializeMeta, toMetaDraftValues, validateMeta } from './meta.js';
4
4
  export { createBlockRegistry, createMarkRegistry, createSchema, resolveMarkRegistry, resolveRegistry } from './registry.js';
5
5
  export { CURRENT_DOCUMENT_VERSION, registerDocumentMigration, runDocumentMigrations } from './migrations.js';
@@ -8,4 +8,4 @@ export { normalizeDocument } from './normalize.js';
8
8
  export { validateDocument } from './validate.js';
9
9
  export type { BlockEditorMountHandle, BlockEditorMountOptions, BlockRuntimePlugin, NormalizedBlockComponentDefinition } from './runtime.js';
10
10
  export { coerceRichTextDocument, emptyRichTextDocument, hasRichTextContent, isRichTextDocument, richTextDocument, resolveRichTextFeatures } from '../shared/richText.js';
11
- export type { AttributeConfig, AttributeInputKind, AttributeOption, AttrParser, AttrSerializer, AttributeSpec, BlockAttributes, BlockBehavior, BlockComponentProps, BlockConfig, BlockContentDefinition, BlockContentKind, BlockDefinition, BlockIcon, BlockMetadata, BlockRegistry, ContentDocument, ContentSchema, CreateSchemaOptions, DocumentMetaSchema, MarkComponentProps, MarkDefinition, MarkRegistry, MetaFieldSpec, MetaValues, RichTextFeature, RichTextFeatureSelection, RuntimeBlockConfig, ValidateDocumentOptions, ValidationCode, ValidationIssue, ValidationResult } from './types.js';
11
+ export type { AttributeConfig, AttributeInputKind, AttributeInputProps, AttributeInputs, AttributeOption, AttrParser, AttrSerializer, AttributeSpec, BlockAttributes, BlockBehavior, BlockComponentProps, BlockConfig, BlockContentDefinition, BlockContentKind, BlockDefinition, BlockIcon, BlockMetadata, BlockRegistry, ContentDocument, ContentSchema, CreateSchemaOptions, DocumentMetaSchema, MarkComponentProps, MarkDefinition, MarkRegistry, MetaFieldSpec, MetaValues, RichTextFeature, RichTextFeatureSelection, RuntimeBlockConfig, ValidateDocumentOptions, ValidationCode, ValidationIssue, ValidationResult } from './types.js';
@@ -1,5 +1,5 @@
1
1
  export { defineRuntimeBlock } from './defineBlock.js';
2
- export { coerceAttributeValue, inferAttributeInputKind, normalizeAttributeOptions, normalizeBlockAttributes, parseBlockDraftAttributes, serializeBlockAttributes, toAttributeDraftValues } from './attributes.js';
2
+ export { coerceAttributeValue, inferAttributeInputKind, isBuiltInInputKind, normalizeAttributeOptions, normalizeBlockAttributes, parseBlockDraftAttributes, serializeBlockAttributes, toAttributeDraftValues } from './attributes.js';
3
3
  export { normalizeMeta, parseMetaDraftValues, serializeMeta, toMetaDraftValues, validateMeta } from './meta.js';
4
4
  export { createBlockRegistry, createMarkRegistry, createSchema, resolveMarkRegistry, resolveRegistry } from './registry.js';
5
5
  export { CURRENT_DOCUMENT_VERSION, registerDocumentMigration, runDocumentMigrations } from './migrations.js';
@@ -45,6 +45,16 @@ export interface AttributeSpec<T> {
45
45
  };
46
46
  }
47
47
  export type AttributeConfig<T> = AttributeSpec<T> | T;
48
+ /** Props a host-defined attribute input receives in the attributes and metadata panels. */
49
+ export interface AttributeInputProps<T = unknown> {
50
+ name: string;
51
+ spec: AttributeSpec<T>;
52
+ value: T;
53
+ /** Store a new value, which must be plain JSON. */
54
+ update: (value: T) => void;
55
+ }
56
+ /** Host components for host-defined `input` kinds, keyed by kind. */
57
+ export type AttributeInputs = Record<string, Component<AttributeInputProps<any>>>;
48
58
  export type MetaFieldSpec<T> = AttributeSpec<T>;
49
59
  export type DocumentMetaSchema = Record<string, MetaFieldSpec<unknown>>;
50
60
  export type MetaValues<Fields extends DocumentMetaSchema> = {
@@ -11,10 +11,11 @@
11
11
  attributeListValueSpec,
12
12
  createAttributeListItem,
13
13
  inferAttributeInputKind,
14
+ isBuiltInInputKind,
14
15
  normalizeAttributeOptions
15
16
  } from '../core/attributes.js';
16
17
  import { onDestroy } from 'svelte';
17
- import type { AttributeSpec } from '../core/types.js';
18
+ import type { AttributeInputs, AttributeSpec } from '../core/types.js';
18
19
  import type { ImagePreviews } from '../shared/imagePreviews.js';
19
20
  import type { ImageSource } from './imageSource.js';
20
21
  import ArrowUpIcon from 'phosphor-svelte/lib/ArrowUpIcon';
@@ -36,6 +37,8 @@
36
37
  errors?: Record<string, string>;
37
38
  onChange: (value: unknown) => void;
38
39
  onCustom?: (name: string, inputKind: string) => void;
40
+ /** Components that edit host-defined input kinds in place of the `onCustom` chooser. */
41
+ attributeInputs?: AttributeInputs;
39
42
  imageSource?: ImageSource;
40
43
  imagePreviews?: ImagePreviews;
41
44
  }
@@ -49,6 +52,7 @@
49
52
  errors = {},
50
53
  onChange,
51
54
  onCustom,
55
+ attributeInputs,
52
56
  imageSource,
53
57
  imagePreviews
54
58
  }: Props = $props();
@@ -122,23 +126,6 @@
122
126
  }
123
127
  }
124
128
 
125
- function isBuiltInInputKind(kind: string): boolean {
126
- return [
127
- 'checkbox',
128
- 'number',
129
- 'date',
130
- 'datetime',
131
- 'richtext',
132
- 'select',
133
- 'textarea',
134
- 'json',
135
- 'list',
136
- 'text',
137
- 'hidden',
138
- 'image'
139
- ].includes(kind);
140
- }
141
-
142
129
  function replaceItem(index: number, next: unknown): void {
143
130
  onChange(items.map((item, position) => (position === index ? next : item)));
144
131
  }
@@ -173,13 +160,18 @@
173
160
  <span class="uncial-field__label">{name}</span>
174
161
  {/if}
175
162
  {#if !isBuiltInInputKind(inputKind)}
176
- <button
177
- type="button"
178
- class="uncial-btn uncial-btn--outline uncial-btn--sm uncial-btn--start"
179
- onclick={() => onCustom?.(name, inputKind)}
180
- >
181
- {customLabel}
182
- </button>
163
+ {@const CustomInput = attributeInputs?.[inputKind]}
164
+ {#if CustomInput}
165
+ <CustomInput {name} {spec} {value} update={onChange} />
166
+ {:else}
167
+ <button
168
+ type="button"
169
+ class="uncial-btn uncial-btn--outline uncial-btn--sm uncial-btn--start"
170
+ onclick={() => onCustom?.(name, inputKind)}
171
+ >
172
+ {customLabel}
173
+ </button>
174
+ {/if}
183
175
  {:else if inputKind === 'checkbox'}
184
176
  <input
185
177
  id={fieldId}
@@ -292,6 +284,7 @@
292
284
  {errors}
293
285
  onChange={(next) => replaceItem(index, next)}
294
286
  {onCustom}
287
+ {attributeInputs}
295
288
  {imageSource}
296
289
  {imagePreviews}
297
290
  />
@@ -307,6 +300,7 @@
307
300
  {errors}
308
301
  onChange={(next) => setItemField(index, fieldName, next)}
309
302
  {onCustom}
303
+ {attributeInputs}
310
304
  {imageSource}
311
305
  {imagePreviews}
312
306
  />
@@ -1,4 +1,4 @@
1
- import type { AttributeSpec } from '../core/types.js';
1
+ import type { AttributeInputs, AttributeSpec } from '../core/types.js';
2
2
  import type { ImagePreviews } from '../shared/imagePreviews.js';
3
3
  import type { ImageSource } from './imageSource.js';
4
4
  import AttributeFieldControl from './AttributeFieldControl.svelte';
@@ -11,6 +11,8 @@ interface Props {
11
11
  errors?: Record<string, string>;
12
12
  onChange: (value: unknown) => void;
13
13
  onCustom?: (name: string, inputKind: string) => void;
14
+ /** Components that edit host-defined input kinds in place of the `onCustom` chooser. */
15
+ attributeInputs?: AttributeInputs;
14
16
  imageSource?: ImageSource;
15
17
  imagePreviews?: ImagePreviews;
16
18
  }
@@ -1,6 +1,11 @@
1
1
  <script lang="ts">
2
2
  import { resolveRegistry } from '../core/registry.js';
3
- import type { AttributeSpec, BlockDefinition, BlockRegistry } from '../core/types.js';
3
+ import type {
4
+ AttributeInputs,
5
+ AttributeSpec,
6
+ BlockDefinition,
7
+ BlockRegistry
8
+ } from '../core/types.js';
4
9
  import { CODE_BLOCK_ID, codeBlockAttributeTarget } from '../shared/codeBlockAttributes.js';
5
10
  import {
6
11
  createInitialState,
@@ -32,12 +37,21 @@
32
37
  * the panel falls back to dispatching that window event for back-compat.
33
38
  */
34
39
  onChooseAttribute?: (request: ChooseAttributeRequest) => void;
40
+ /** Components that edit host-defined input kinds in place; see `AttributeFieldControl`. */
41
+ attributeInputs?: AttributeInputs;
35
42
  imageSource?: ImageSource;
36
43
  /** Where a successful upload registers its preview; see `Editor`. */
37
44
  imagePreviews?: ImagePreviews;
38
45
  }
39
46
 
40
- let { controller, blocks = [], onChooseAttribute, imageSource, imagePreviews }: Props = $props();
47
+ let {
48
+ controller,
49
+ blocks = [],
50
+ onChooseAttribute,
51
+ attributeInputs,
52
+ imageSource,
53
+ imagePreviews
54
+ }: Props = $props();
41
55
 
42
56
  let controllerState = $state<BlockAttributesState>(createInitialState());
43
57
 
@@ -197,6 +211,7 @@
197
211
  error={controllerState.validationErrors[name]}
198
212
  onChange={(value) => controller.setDraftAttr(name, value)}
199
213
  onCustom={chooseCustomAttribute}
214
+ {attributeInputs}
200
215
  {imageSource}
201
216
  {imagePreviews}
202
217
  />
@@ -1,4 +1,4 @@
1
- import type { BlockDefinition, BlockRegistry } from '../core/types.js';
1
+ import type { AttributeInputs, BlockDefinition, BlockRegistry } from '../core/types.js';
2
2
  import { type BlockAttributesController } from './attributesController.js';
3
3
  import { type ChooseAttributeRequest } from './chooseAttribute.js';
4
4
  import type { ImageSource } from './imageSource.js';
@@ -13,6 +13,8 @@ interface Props {
13
13
  * the panel falls back to dispatching that window event for back-compat.
14
14
  */
15
15
  onChooseAttribute?: (request: ChooseAttributeRequest) => void;
16
+ /** Components that edit host-defined input kinds in place; see `AttributeFieldControl`. */
17
+ attributeInputs?: AttributeInputs;
16
18
  imageSource?: ImageSource;
17
19
  /** Where a successful upload registers its preview; see `Editor`. */
18
20
  imagePreviews?: ImagePreviews;
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import type { AttributeSpec } from '../core/types.js';
2
+ import type { AttributeInputs, AttributeSpec } from '../core/types.js';
3
3
  import type { ImagePreviews } from '../shared/imagePreviews.js';
4
4
  import AttributeFieldControl from './AttributeFieldControl.svelte';
5
5
  import type { ImageSource } from './imageSource.js';
@@ -9,11 +9,19 @@
9
9
  controller: DocumentMetaController;
10
10
  fields?: ReadonlyMap<string, AttributeSpec<unknown>>;
11
11
  onCommit?: (meta: Record<string, unknown>) => void;
12
+ attributeInputs?: AttributeInputs;
12
13
  imageSource?: ImageSource;
13
14
  imagePreviews?: ImagePreviews;
14
15
  }
15
16
 
16
- let { controller, fields = new Map(), onCommit, imageSource, imagePreviews }: Props = $props();
17
+ let {
18
+ controller,
19
+ fields = new Map(),
20
+ onCommit,
21
+ attributeInputs,
22
+ imageSource,
23
+ imagePreviews
24
+ }: Props = $props();
17
25
 
18
26
  let controllerState = $state<DocumentMetaState>({
19
27
  draft: {},
@@ -52,6 +60,7 @@
52
60
  error={controllerState.errors[name]}
53
61
  errors={controllerState.errors}
54
62
  onChange={(value) => controller.setDraft(name, value)}
63
+ {attributeInputs}
55
64
  {imageSource}
56
65
  {imagePreviews}
57
66
  />
@@ -1,4 +1,4 @@
1
- import type { AttributeSpec } from '../core/types.js';
1
+ import type { AttributeInputs, AttributeSpec } from '../core/types.js';
2
2
  import type { ImagePreviews } from '../shared/imagePreviews.js';
3
3
  import type { ImageSource } from './imageSource.js';
4
4
  import type { DocumentMetaController } from './metaController.js';
@@ -6,6 +6,7 @@ interface Props {
6
6
  controller: DocumentMetaController;
7
7
  fields?: ReadonlyMap<string, AttributeSpec<unknown>>;
8
8
  onCommit?: (meta: Record<string, unknown>) => void;
9
+ attributeInputs?: AttributeInputs;
9
10
  imageSource?: ImageSource;
10
11
  imagePreviews?: ImagePreviews;
11
12
  }
@@ -5,6 +5,7 @@
5
5
  import CaretDownIcon from 'phosphor-svelte/lib/CaretDownIcon';
6
6
  import { resolveRegistry } from '../core/registry.js';
7
7
  import type {
8
+ AttributeInputs,
8
9
  AttributeSpec,
9
10
  BlockDefinition,
10
11
  BlockRegistry,
@@ -73,6 +74,8 @@
73
74
  onChooseAttribute?: (request: ChooseAttributeRequest) => void;
74
75
  /** Uploads, existing images and thumbnails for `input: 'image'` attributes. */
75
76
  imageSource?: ImageSource;
77
+ /** Components that edit host-defined `input` kinds in the attributes and metadata panels. */
78
+ attributeInputs?: AttributeInputs;
76
79
  onIssue?: (issue: ValidationIssue) => void;
77
80
  /**
78
81
  * The document after an edit, and the metadata after one.
@@ -102,6 +105,7 @@
102
105
  presentation = 'card',
103
106
  onChooseAttribute,
104
107
  imageSource,
108
+ attributeInputs,
105
109
  onIssue,
106
110
  onChange,
107
111
  onMetaChange
@@ -387,7 +391,11 @@
387
391
  {#if hasMetaFields || activeBlocks.length > 0}
388
392
  <div class="uncial-toolbar__actions">
389
393
  {#if hasMetaFields}
390
- <details class="uncial-dropdown uncial-dropdown--end" use:dropdownDismiss use:dropdownFloat>
394
+ <details
395
+ class="uncial-dropdown uncial-dropdown--end"
396
+ use:dropdownDismiss
397
+ use:dropdownFloat
398
+ >
391
399
  <summary
392
400
  bind:this={metaTriggerEl}
393
401
  aria-label="Edit document metadata"
@@ -401,6 +409,7 @@
401
409
  controller={documentMetaController}
402
410
  fields={resolvedMetaFields}
403
411
  onCommit={commitMeta}
412
+ {attributeInputs}
404
413
  {imageSource}
405
414
  {imagePreviews}
406
415
  />
@@ -463,6 +472,7 @@
463
472
  {controller}
464
473
  {blocks}
465
474
  {onChooseAttribute}
475
+ {attributeInputs}
466
476
  {imageSource}
467
477
  {imagePreviews}
468
478
  />
@@ -1,5 +1,5 @@
1
1
  import type { AnyExtension, JSONContent } from '@tiptap/core';
2
- import type { AttributeSpec, BlockDefinition, BlockRegistry, ContentSchema, DocumentMetaSchema, ValidationIssue } from '../core/types.js';
2
+ import type { AttributeInputs, AttributeSpec, BlockDefinition, BlockRegistry, ContentSchema, DocumentMetaSchema, ValidationIssue } from '../core/types.js';
3
3
  import { type BlockAttributesController } from './attributesController.js';
4
4
  import { type DocumentMetaController } from './metaController.js';
5
5
  import type { ChooseAttributeRequest } from './chooseAttribute.js';
@@ -43,6 +43,8 @@ interface Props {
43
43
  onChooseAttribute?: (request: ChooseAttributeRequest) => void;
44
44
  /** Uploads, existing images and thumbnails for `input: 'image'` attributes. */
45
45
  imageSource?: ImageSource;
46
+ /** Components that edit host-defined `input` kinds in the attributes and metadata panels. */
47
+ attributeInputs?: AttributeInputs;
46
48
  onIssue?: (issue: ValidationIssue) => void;
47
49
  /**
48
50
  * The document after an edit, and the metadata after one.
@@ -17,6 +17,8 @@
17
17
  import TextHTwoIcon from 'phosphor-svelte/lib/TextHTwoIcon';
18
18
  import TextItalicIcon from 'phosphor-svelte/lib/TextItalicIcon';
19
19
  import TextStrikethroughIcon from 'phosphor-svelte/lib/TextStrikethroughIcon';
20
+ import TextSubscriptIcon from 'phosphor-svelte/lib/TextSubscriptIcon';
21
+ import TextSuperscriptIcon from 'phosphor-svelte/lib/TextSuperscriptIcon';
20
22
  import type { ContentSchema } from '../core/types.js';
21
23
  import {
22
24
  resolveToolbarFeatures,
@@ -107,6 +109,8 @@
107
109
  strike: TextStrikethroughIcon,
108
110
  code: CodeIcon,
109
111
  link: LinkIcon,
112
+ superscript: TextSuperscriptIcon,
113
+ subscript: TextSubscriptIcon,
110
114
  heading2: TextHTwoIcon,
111
115
  heading3: TextHThreeIcon,
112
116
  heading4: TextHFourIcon,
@@ -1,6 +1,6 @@
1
1
  import type { Editor } from '@tiptap/core';
2
2
  import type { ContentSchema } from '../core/types.js';
3
- export type ToolbarFeatureId = 'bold' | 'italic' | 'strike' | 'code' | 'link' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'bulletList' | 'orderedList' | 'blockquote' | 'codeBlock' | 'horizontalRule';
3
+ export type ToolbarFeatureId = 'bold' | 'italic' | 'strike' | 'code' | 'link' | 'superscript' | 'subscript' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6' | 'bulletList' | 'orderedList' | 'blockquote' | 'codeBlock' | 'horizontalRule';
4
4
  export type ToolbarFeatureSelection = '*' | '__all__' | readonly string[];
5
5
  export interface ToolbarFeatureContext {
6
6
  editor: Editor;
@@ -4,6 +4,8 @@ export const defaultToolbarFeatures = [
4
4
  'strike',
5
5
  'code',
6
6
  'link',
7
+ 'superscript',
8
+ 'subscript',
7
9
  'heading2',
8
10
  'heading3',
9
11
  'heading4',
@@ -27,6 +29,19 @@ function toggleMark(command) {
27
29
  function canToggleMark(command) {
28
30
  return ({ editor }) => editor.can().chain().focus()[command]().run();
29
31
  }
32
+ // Opt-in marks: only a schema that names them has them.
33
+ function scriptFeature(mark, label) {
34
+ const toggle = mark === 'superscript' ? 'toggleSuperscript' : 'toggleSubscript';
35
+ return {
36
+ id: mark,
37
+ label,
38
+ group: 'mark',
39
+ isAllowed: ({ schema }) => schema?.allowedMarks.has(mark) ?? false,
40
+ isActive: activeMark(mark),
41
+ canRun: ({ editor }) => editor.can().chain().focus()[toggle]().run(),
42
+ run: ({ editor }) => editor.chain().focus()[toggle]().run()
43
+ };
44
+ }
30
45
  function headingFeature(level) {
31
46
  return {
32
47
  id: `heading${level}`,
@@ -84,6 +99,8 @@ export const builtinToolbarFeatures = [
84
99
  canRun: ({ editor }) => editor.can().chain().focus().toggleLink({ href: '#' }).run(),
85
100
  run: ({ editor }) => editor.chain().focus().toggleLink({ href: '#' }).run()
86
101
  },
102
+ scriptFeature('superscript', 'Superscript'),
103
+ scriptFeature('subscript', 'Subscript'),
87
104
  headingFeature(2),
88
105
  headingFeature(3),
89
106
  headingFeature(4),
@@ -168,7 +185,11 @@ export const richTextAttributeToolbarFeatures = [
168
185
  export function resolveToolbarFeatures({ editor, schema, toolbarFeatures, toolbarExtensions = [] }) {
169
186
  if (!editor)
170
187
  return [];
171
- const descriptors = [...builtinToolbarFeatures, ...toolbarExtensions];
188
+ const overridden = new Set(toolbarExtensions.map((feature) => feature.id));
189
+ const descriptors = [
190
+ ...builtinToolbarFeatures.filter((feature) => !overridden.has(feature.id)),
191
+ ...toolbarExtensions
192
+ ];
172
193
  const selection = toolbarFeatures ?? defaultToolbarFeatures;
173
194
  const selectedIds = selection === '*' || selection === '__all__' ? null : new Set(selection);
174
195
  const context = { editor, schema };
@@ -0,0 +1,4 @@
1
+ export declare const embedBlock: import("./index.ts").BlockDefinition<{
2
+ url: string;
3
+ title: string;
4
+ }>;
package/dist/embed.js ADDED
@@ -0,0 +1,12 @@
1
+ import { defineSvelteBlock } from './runtime/svelte.js';
2
+ import Embed from './render/Embed.svelte';
3
+ export const embedBlock = defineSvelteBlock({
4
+ id: 'embed',
5
+ label: 'Embed',
6
+ description: 'A YouTube or Vimeo player, or a link for any other URL.',
7
+ attributes: {
8
+ url: { default: '', required: true, placeholder: 'https://www.youtube.com/watch?v=…' },
9
+ title: { default: '', placeholder: 'What the embed shows, for screen readers' }
10
+ },
11
+ component: Embed
12
+ });
package/dist/index.d.ts CHANGED
@@ -2,4 +2,5 @@ export * from './core/index.js';
2
2
  export * from './runtime/svelte.js';
3
3
  export * from './editor/index.js';
4
4
  export * from './render/index.js';
5
+ export { embedBlock } from './embed.js';
5
6
  export { tabBlock, tabsBlock } from './tabs.js';
package/dist/index.js CHANGED
@@ -2,4 +2,5 @@ export * from './core/index.js';
2
2
  export * from './runtime/svelte.js';
3
3
  export * from './editor/index.js';
4
4
  export * from './render/index.js';
5
+ export { embedBlock } from './embed.js';
5
6
  export { tabBlock, tabsBlock } from './tabs.js';
@@ -0,0 +1,39 @@
1
+ <script lang="ts">
2
+ import { embedPlayerSrc } from './embedPlayer.js';
3
+ import { sanitizeHref } from './sanitize.js';
4
+
5
+ interface Props {
6
+ url?: string;
7
+ title?: string;
8
+ }
9
+
10
+ let { url = '', title = '' }: Props = $props();
11
+
12
+ const player = $derived(embedPlayerSrc(url));
13
+ const href = $derived(sanitizeHref(url));
14
+ </script>
15
+
16
+ {#if player}
17
+ <iframe
18
+ class="uncial-embed"
19
+ src={player}
20
+ title={title || 'Embedded video'}
21
+ allow="autoplay; encrypted-media; fullscreen; picture-in-picture"
22
+ allowfullscreen
23
+ loading="lazy"
24
+ ></iframe>
25
+ {:else if href}
26
+ <p class="uncial-embed-link">
27
+ <!-- eslint-disable-next-line svelte/no-navigation-without-resolve -- an embed points off-site -->
28
+ <a {href}>{title || url}</a>
29
+ </p>
30
+ {/if}
31
+
32
+ <style>
33
+ .uncial-embed {
34
+ display: block;
35
+ width: 100%;
36
+ aspect-ratio: 16 / 9;
37
+ border: 0;
38
+ }
39
+ </style>
@@ -0,0 +1,7 @@
1
+ interface Props {
2
+ url?: string;
3
+ title?: string;
4
+ }
5
+ declare const Embed: import("svelte").Component<Props, {}, "">;
6
+ type Embed = ReturnType<typeof Embed>;
7
+ export default Embed;
@@ -99,6 +99,10 @@
99
99
  <s>{@render renderMarkedText(text, rest)}</s>
100
100
  {:else if mark.type === 'code'}
101
101
  <code>{@render renderMarkedText(text, rest)}</code>
102
+ {:else if mark.type === 'superscript'}
103
+ <sup>{@render renderMarkedText(text, rest)}</sup>
104
+ {:else if mark.type === 'subscript'}
105
+ <sub>{@render renderMarkedText(text, rest)}</sub>
102
106
  {:else if mark.type === 'link'}
103
107
  {@const href = sanitizeHref(mark.attrs?.href)}
104
108
  {#if href}
@@ -0,0 +1,2 @@
1
+ /** The player URL for a YouTube or Vimeo page URL; null for anything else. */
2
+ export declare function embedPlayerSrc(value: string): string | null;
@@ -0,0 +1,26 @@
1
+ const YOUTUBE_HOSTS = new Set(['youtube.com', 'www.youtube.com', 'm.youtube.com', 'youtu.be']);
2
+ const VIMEO_HOSTS = new Set(['vimeo.com', 'www.vimeo.com', 'player.vimeo.com']);
3
+ /** The player URL for a YouTube or Vimeo page URL; null for anything else. */
4
+ export function embedPlayerSrc(value) {
5
+ let url;
6
+ try {
7
+ url = new URL(value.trim());
8
+ }
9
+ catch {
10
+ return null;
11
+ }
12
+ const segments = url.pathname.split('/').filter(Boolean);
13
+ if (YOUTUBE_HOSTS.has(url.hostname)) {
14
+ const id = url.hostname === 'youtu.be'
15
+ ? segments[0]
16
+ : ['embed', 'shorts', 'live'].includes(segments[0] ?? '')
17
+ ? segments[1]
18
+ : url.searchParams.get('v');
19
+ return id && /^[\w-]+$/.test(id) ? `https://www.youtube-nocookie.com/embed/${id}` : null;
20
+ }
21
+ if (VIMEO_HOSTS.has(url.hostname)) {
22
+ const id = segments.find((segment) => /^\d+$/.test(segment));
23
+ return id ? `https://player.vimeo.com/video/${id}` : null;
24
+ }
25
+ return null;
26
+ }
@@ -1,6 +1,8 @@
1
1
  import StarterKit from '@tiptap/starter-kit';
2
2
  import Code from '@tiptap/extension-code';
3
3
  import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight';
4
+ import Subscript from '@tiptap/extension-subscript';
5
+ import Superscript from '@tiptap/extension-superscript';
4
6
  import { Table, TableCell, TableHeader, TableRow } from '@tiptap/extension-table';
5
7
  import { Extension, Mark, mergeAttributes, Node } from '@tiptap/core';
6
8
  import { DEFAULT_MARKS, resolveRegistry } from '../core/registry.js';
@@ -333,6 +335,8 @@ function createBaseExtensions(schema, extensions = []) {
333
335
  const includeStrike = marks.has('strike');
334
336
  const includeCode = marks.has('code');
335
337
  const includeLink = marks.has('link');
338
+ // A host that already registers its own copy keeps it; Tiptap rejects duplicate names.
339
+ const includeMark = (name) => marks.has(name) && !extensions.some((extension) => extension.name === name);
336
340
  return [
337
341
  StarterKit.configure({
338
342
  bold: includeBold ? {} : false,
@@ -355,7 +359,8 @@ function createBaseExtensions(schema, extensions = []) {
355
359
  TableCell,
356
360
  ...(includeCode ? [CombinableCode] : []),
357
361
  ...(includeLink ? [LinkMark] : []),
358
- ...extensions
362
+ ...(includeMark('superscript') ? [Superscript] : []),
363
+ ...(includeMark('subscript') ? [Subscript] : [])
359
364
  ];
360
365
  }
361
366
  export function createRichTextExtensions(features) {
@@ -384,7 +389,7 @@ export function createEditorExtensions(blocks = [], schema, onActivateBlock, ext
384
389
  .filter((block) => !schema || schema.allowedBlocks.has(block.id))
385
390
  .map((block) => createBlockNodeExtension(block, onActivateBlock, imagePreviews));
386
391
  return [
387
- ...createBaseExtensions(schema),
392
+ ...createBaseExtensions(schema, extensions),
388
393
  createDocumentIdentityExtension(registry),
389
394
  ...blockExtensions,
390
395
  ...extensions
@@ -8,6 +8,7 @@
8
8
  ToolbarFeatureSelection
9
9
  } from '../editor/index.js';
10
10
  import type {
11
+ AttributeInputs,
11
12
  AttributeSpec,
12
13
  BlockDefinition,
13
14
  BlockRegistry,
@@ -30,6 +31,7 @@
30
31
  attributesPanel?: boolean | 'docked' | 'overlay' | 'off';
31
32
  presentation?: 'card' | 'bare';
32
33
  imageSource?: ImageSource;
34
+ attributeInputs?: AttributeInputs;
33
35
  onIssue?: (issue: ValidationIssue) => void;
34
36
  onChange?: (document: JSONContent) => void;
35
37
  onMetaChange?: (meta: Record<string, unknown>) => void;
@@ -48,6 +50,7 @@
48
50
  attributesPanel = true,
49
51
  presentation = 'card',
50
52
  imageSource,
53
+ attributeInputs,
51
54
  onIssue,
52
55
  onChange,
53
56
  onMetaChange
@@ -74,6 +77,7 @@
74
77
  {attributesPanel}
75
78
  {presentation}
76
79
  {imageSource}
80
+ {attributeInputs}
77
81
  onIssue={dispatchIssue}
78
82
  {onChange}
79
83
  {onMetaChange}
@@ -1,6 +1,6 @@
1
1
  import type { AnyExtension, JSONContent } from '@tiptap/core';
2
2
  import type { BlockAttributesController, ImageSource, ToolbarFeature, ToolbarFeatureSelection } from '../editor/index.js';
3
- import type { AttributeSpec, BlockDefinition, BlockRegistry, ContentSchema, DocumentMetaSchema, ValidationIssue } from '../core/types.js';
3
+ import type { AttributeInputs, AttributeSpec, BlockDefinition, BlockRegistry, ContentSchema, DocumentMetaSchema, ValidationIssue } from '../core/types.js';
4
4
  interface Props {
5
5
  blocks?: BlockRegistry | BlockDefinition[];
6
6
  schema?: ContentSchema;
@@ -14,6 +14,7 @@ interface Props {
14
14
  attributesPanel?: boolean | 'docked' | 'overlay' | 'off';
15
15
  presentation?: 'card' | 'bare';
16
16
  imageSource?: ImageSource;
17
+ attributeInputs?: AttributeInputs;
17
18
  onIssue?: (issue: ValidationIssue) => void;
18
19
  onChange?: (document: JSONContent) => void;
19
20
  onMetaChange?: (meta: Record<string, unknown>) => void;
@@ -2,7 +2,7 @@ import UncialEditor from './UncialEditor.svelte';
2
2
  import UncialRenderer from './UncialRenderer.svelte';
3
3
  import type { AnyExtension, JSONContent } from '@tiptap/core';
4
4
  import type { BlockAttributesController, ImageSource, ToolbarFeature, ToolbarFeatureSelection } from '../editor/index.js';
5
- import type { AttributeSpec, BlockDefinition, BlockRegistry, ContentSchema, DocumentMetaSchema, ValidationIssue } from '../core/types.js';
5
+ import type { AttributeInputs, AttributeSpec, BlockDefinition, BlockRegistry, ContentSchema, DocumentMetaSchema, ValidationIssue } from '../core/types.js';
6
6
  type EditorProps = {
7
7
  blocks?: BlockRegistry | BlockDefinition[];
8
8
  schema?: ContentSchema;
@@ -16,6 +16,7 @@ type EditorProps = {
16
16
  attributesPanel?: boolean | 'docked' | 'overlay' | 'off';
17
17
  presentation?: 'card' | 'bare';
18
18
  imageSource?: ImageSource;
19
+ attributeInputs?: AttributeInputs;
19
20
  };
20
21
  type EditorHostProps = EditorProps & {
21
22
  onIssue?: (issue: ValidationIssue) => void;
@@ -85,6 +86,8 @@ declare class UncialEditorElement extends UncialElement<EditorHostProps> {
85
86
  set presentation(value: EditorProps['presentation']);
86
87
  get imageSource(): EditorProps['imageSource'];
87
88
  set imageSource(value: EditorProps['imageSource']);
89
+ get attributeInputs(): EditorProps['attributeInputs'];
90
+ set attributeInputs(value: EditorProps['attributeInputs']);
88
91
  protected mountComponent(target: ShadowRoot): Record<string, unknown>;
89
92
  }
90
93
  declare class UncialRendererElement extends UncialElement<RendererHostProps> {
@@ -155,6 +155,12 @@ class UncialEditorElement extends UncialElement {
155
155
  set imageSource(value) {
156
156
  this.setProp('imageSource', value);
157
157
  }
158
+ get attributeInputs() {
159
+ return this.props.attributeInputs;
160
+ }
161
+ set attributeInputs(value) {
162
+ this.setProp('attributeInputs', value);
163
+ }
158
164
  mountComponent(target) {
159
165
  return mount(UncialEditor, { target, props: this.props });
160
166
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uncial",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -108,6 +108,8 @@
108
108
  "@tiptap/core": "^3.20.0",
109
109
  "@tiptap/extension-code": "^3.20.0",
110
110
  "@tiptap/extension-code-block-lowlight": "3.20.0",
111
+ "@tiptap/extension-subscript": "^3.30.3",
112
+ "@tiptap/extension-superscript": "^3.30.3",
111
113
  "@tiptap/extension-table": "^3.20.0",
112
114
  "@tiptap/html": "^3.20.0",
113
115
  "@tiptap/pm": "^3.20.0",