uncial 2.0.3 → 3.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.
@@ -1,11 +1,11 @@
1
1
  export { defineRuntimeBlock } from './defineBlock.js';
2
2
  export { coerceAttributeValue, inferAttributeInputKind, normalizeAttributeOptions, normalizeBlockAttributes, parseBlockDraftAttributes, serializeBlockAttributes, toAttributeDraftValues } from './attributes.js';
3
3
  export { normalizeMeta, parseMetaDraftValues, serializeMeta, toMetaDraftValues, validateMeta } from './meta.js';
4
- export { createBlockRegistry, createSchema, resolveRegistry } from './registry.js';
4
+ export { createBlockRegistry, createMarkRegistry, createSchema, resolveMarkRegistry, resolveRegistry } from './registry.js';
5
5
  export { CURRENT_DOCUMENT_VERSION, registerDocumentMigration, runDocumentMigrations } from './migrations.js';
6
6
  export type { DocumentMigration } from './migrations.js';
7
7
  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, MetaFieldSpec, RichTextFeature, RichTextFeatureSelection, RuntimeBlockConfig, ValidateDocumentOptions, ValidationCode, ValidationIssue, ValidationResult } from './types.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, RichTextFeature, RichTextFeatureSelection, RuntimeBlockConfig, ValidateDocumentOptions, ValidationCode, ValidationIssue, ValidationResult } from './types.js';
@@ -1,7 +1,7 @@
1
1
  export { defineRuntimeBlock } from './defineBlock.js';
2
2
  export { coerceAttributeValue, inferAttributeInputKind, normalizeAttributeOptions, normalizeBlockAttributes, parseBlockDraftAttributes, serializeBlockAttributes, toAttributeDraftValues } from './attributes.js';
3
3
  export { normalizeMeta, parseMetaDraftValues, serializeMeta, toMetaDraftValues, validateMeta } from './meta.js';
4
- export { createBlockRegistry, createSchema, resolveRegistry } from './registry.js';
4
+ export { createBlockRegistry, createMarkRegistry, createSchema, resolveMarkRegistry, resolveRegistry } from './registry.js';
5
5
  export { CURRENT_DOCUMENT_VERSION, registerDocumentMigration, runDocumentMigrations } from './migrations.js';
6
6
  export { normalizeDocument } from './normalize.js';
7
7
  export { validateDocument } from './validate.js';
@@ -1,4 +1,4 @@
1
- import type { BlockDefinition, BlockRegistry, ContentSchema, CreateSchemaOptions } from './types.js';
1
+ import type { BlockDefinition, BlockRegistry, ContentSchema, CreateSchemaOptions, MarkDefinition, MarkRegistry } from './types.js';
2
2
  /**
3
3
  * The default mark universe a schema allows when the host does not pass an
4
4
  * explicit `allowedMarks`. This is the single source of truth for the default
@@ -7,5 +7,12 @@ import type { BlockDefinition, BlockRegistry, ContentSchema, CreateSchemaOptions
7
7
  */
8
8
  export declare const DEFAULT_MARKS: readonly ["bold", "italic", "strike", "code", "link"];
9
9
  export declare function createBlockRegistry(blocks: BlockDefinition[]): BlockRegistry;
10
+ /**
11
+ * Registered renderers are what the renderer can *draw*; `allowedMarks` is what
12
+ * a schema *permits*. They stay separate: registering a mark does not admit it
13
+ * through normalization, and permitting one does not give it a wrapper element.
14
+ */
15
+ export declare function createMarkRegistry(marks: MarkDefinition[]): MarkRegistry;
10
16
  export declare function createSchema(registry: BlockRegistry, options?: CreateSchemaOptions): ContentSchema;
11
17
  export declare function resolveRegistry(blocks: BlockRegistry | BlockDefinition[]): BlockRegistry;
18
+ export declare function resolveMarkRegistry(marks: MarkRegistry | MarkDefinition[]): MarkRegistry;
@@ -50,6 +50,30 @@ export function createBlockRegistry(blocks) {
50
50
  }
51
51
  };
52
52
  }
53
+ /**
54
+ * Registered renderers are what the renderer can *draw*; `allowedMarks` is what
55
+ * a schema *permits*. They stay separate: registering a mark does not admit it
56
+ * through normalization, and permitting one does not give it a wrapper element.
57
+ */
58
+ export function createMarkRegistry(marks) {
59
+ const byId = new Map();
60
+ for (const mark of marks) {
61
+ if (byId.has(mark.id)) {
62
+ throw new Error(`Duplicate mark id "${mark.id}"`);
63
+ }
64
+ byId.set(mark.id, mark);
65
+ }
66
+ return {
67
+ marks,
68
+ byId,
69
+ get(id) {
70
+ return byId.get(id);
71
+ },
72
+ has(id) {
73
+ return byId.has(id);
74
+ }
75
+ };
76
+ }
53
77
  export function createSchema(registry, options = {}) {
54
78
  let allowedBlocks;
55
79
  if (options.allowedBlocks) {
@@ -77,3 +101,6 @@ export function createSchema(registry, options = {}) {
77
101
  export function resolveRegistry(blocks) {
78
102
  return Array.isArray(blocks) ? createBlockRegistry(blocks) : blocks;
79
103
  }
104
+ export function resolveMarkRegistry(marks) {
105
+ return Array.isArray(marks) ? createMarkRegistry(marks) : marks;
106
+ }
@@ -132,6 +132,26 @@ export interface BlockRegistry {
132
132
  get(id: string): BlockDefinition | undefined;
133
133
  has(id: string): boolean;
134
134
  }
135
+ /**
136
+ * Props a custom mark's render component receives: the mark's own attrs
137
+ * spread as individual props, plus the marked text (and any marks nested
138
+ * inside it) as children.
139
+ */
140
+ export interface MarkComponentProps {
141
+ children: Snippet;
142
+ [name: string]: unknown;
143
+ }
144
+ export interface MarkDefinition {
145
+ /** The ProseMirror mark type this renders, e.g. `superscript`. */
146
+ id: string;
147
+ component: Component<MarkComponentProps>;
148
+ }
149
+ export interface MarkRegistry {
150
+ marks: MarkDefinition[];
151
+ byId: ReadonlyMap<string, MarkDefinition>;
152
+ get(id: string): MarkDefinition | undefined;
153
+ has(id: string): boolean;
154
+ }
135
155
  export interface ContentSchema {
136
156
  allowedBlocks: ReadonlySet<string>;
137
157
  allowedMarks: ReadonlySet<string>;
@@ -7,10 +7,12 @@
7
7
  BlockDefinition,
8
8
  BlockRegistry,
9
9
  ContentSchema,
10
+ MarkDefinition,
11
+ MarkRegistry,
10
12
  ValidationIssue
11
13
  } from '../core/types.js';
12
14
  import type { PMDoc, PMNode } from '../shared/document.js';
13
- import { resolveRegistry } from '../core/registry.js';
15
+ import { resolveMarkRegistry, resolveRegistry } from '../core/registry.js';
14
16
  import { emptyDocument } from '../shared/content.js';
15
17
  import { SVELTE_RUNTIME_ID } from '../shared/runtimeId.js';
16
18
  import RichContent from './RichContent.svelte';
@@ -18,6 +20,7 @@
18
20
  interface Props {
19
21
  content?: JSONContent;
20
22
  blocks?: BlockRegistry | BlockDefinition[];
23
+ marks?: MarkRegistry | MarkDefinition[];
21
24
  schema?: ContentSchema;
22
25
  meta?: Snippet<[Record<string, unknown> | undefined]>;
23
26
  onIssue?: (issue: ValidationIssue) => void;
@@ -26,6 +29,7 @@
26
29
  let {
27
30
  content = emptyDocument(),
28
31
  blocks = [],
32
+ marks = [],
29
33
  schema = undefined,
30
34
  meta: metaSnippet = undefined,
31
35
  onIssue
@@ -39,6 +43,7 @@
39
43
  }
40
44
  return resolved;
41
45
  });
46
+ const markRegistry = $derived(resolveMarkRegistry(marks));
42
47
  const normalizedContent = $derived(
43
48
  normalizeDocument(content as Partial<PMDoc>, registry, schema)
44
49
  );
@@ -52,6 +57,11 @@
52
57
  <div class="uncial-renderer">
53
58
  {@render metaSnippet?.(normalizedContent.meta)}
54
59
  <div class="uncial-content uncial-rich-content">
55
- <RichContent nodes={(normalizedContent.content ?? []) as PMNode[]} {registry} {schema} />
60
+ <RichContent
61
+ nodes={(normalizedContent.content ?? []) as PMNode[]}
62
+ {registry}
63
+ {markRegistry}
64
+ {schema}
65
+ />
56
66
  </div>
57
67
  </div>
@@ -1,9 +1,10 @@
1
1
  import type { JSONContent } from '@tiptap/core';
2
2
  import type { Snippet } from 'svelte';
3
- import type { BlockDefinition, BlockRegistry, ContentSchema, ValidationIssue } from '../core/types.js';
3
+ import type { BlockDefinition, BlockRegistry, ContentSchema, MarkDefinition, MarkRegistry, ValidationIssue } from '../core/types.js';
4
4
  interface Props {
5
5
  content?: JSONContent;
6
6
  blocks?: BlockRegistry | BlockDefinition[];
7
+ marks?: MarkRegistry | MarkDefinition[];
7
8
  schema?: ContentSchema;
8
9
  meta?: Snippet<[Record<string, unknown> | undefined]>;
9
10
  onIssue?: (issue: ValidationIssue) => void;
@@ -1,11 +1,12 @@
1
1
  <script lang="ts">
2
- import type { BlockRegistry, ContentSchema } from '../core/types.js';
2
+ import type { BlockRegistry, ContentSchema, MarkRegistry } from '../core/types.js';
3
3
  import type { PMNode } from '../shared/document.js';
4
4
  import RichNode from './RichNode.svelte';
5
5
 
6
6
  interface Props {
7
7
  nodes?: PMNode[];
8
8
  registry: BlockRegistry;
9
+ markRegistry?: MarkRegistry;
9
10
  schema?: ContentSchema;
10
11
  tabsGroup?: string;
11
12
  tabsLabels?: string[];
@@ -14,6 +15,7 @@
14
15
  let {
15
16
  nodes = [],
16
17
  registry,
18
+ markRegistry = undefined,
17
19
  schema = undefined,
18
20
  tabsGroup = undefined,
19
21
  tabsLabels = undefined
@@ -34,5 +36,5 @@
34
36
  </script>
35
37
 
36
38
  {#each nodes as node, index (getNodeKey(node, index))}
37
- <RichNode {node} {registry} {schema} {tabsGroup} {tabsLabels} />
39
+ <RichNode {node} {registry} {markRegistry} {schema} {tabsGroup} {tabsLabels} />
38
40
  {/each}
@@ -1,8 +1,9 @@
1
- import type { BlockRegistry, ContentSchema } from '../core/types.js';
1
+ import type { BlockRegistry, ContentSchema, MarkRegistry } from '../core/types.js';
2
2
  import type { PMNode } from '../shared/document.js';
3
3
  interface Props {
4
4
  nodes?: PMNode[];
5
5
  registry: BlockRegistry;
6
+ markRegistry?: MarkRegistry;
6
7
  schema?: ContentSchema;
7
8
  tabsGroup?: string;
8
9
  tabsLabels?: string[];
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import type { Component } from 'svelte';
3
- import type { BlockRegistry, ContentSchema } from '../core/types.js';
3
+ import type { BlockRegistry, ContentSchema, MarkRegistry } from '../core/types.js';
4
4
  import type { PMMark, PMNode } from '../shared/document.js';
5
5
  import { getCodeLanguageClass, highlightCodeToHtml } from '../shared/syntaxHighlight.js';
6
6
  import RichContent from './RichContent.svelte';
@@ -9,6 +9,7 @@
9
9
  interface Props {
10
10
  node: PMNode;
11
11
  registry: BlockRegistry;
12
+ markRegistry?: MarkRegistry;
12
13
  schema?: ContentSchema;
13
14
  tabsGroup?: string;
14
15
  tabsLabels?: string[];
@@ -17,6 +18,7 @@
17
18
  let {
18
19
  node,
19
20
  registry,
21
+ markRegistry = undefined,
20
22
  schema = undefined,
21
23
  tabsGroup = undefined,
22
24
  tabsLabels = undefined
@@ -73,6 +75,7 @@
73
75
  <RichContent
74
76
  nodes={blockContent}
75
77
  {registry}
78
+ {markRegistry}
76
79
  {schema}
77
80
  tabsGroup={childTabsGroup}
78
81
  tabsLabels={childTabsLabels}
@@ -84,7 +87,11 @@
84
87
  {text}
85
88
  {:else}
86
89
  {@const [mark, ...rest] = marks}
87
- {#if mark.type === 'bold'}
90
+ {@const customMark = markRegistry?.get(mark.type)}
91
+ {#if customMark}
92
+ {@const MarkComponent = customMark.component}
93
+ <MarkComponent {...mark.attrs ?? {}}>{@render renderMarkedText(text, rest)}</MarkComponent>
94
+ {:else if mark.type === 'bold'}
88
95
  <strong>{@render renderMarkedText(text, rest)}</strong>
89
96
  {:else if mark.type === 'italic'}
90
97
  <em>{@render renderMarkedText(text, rest)}</em>
@@ -124,7 +131,7 @@
124
131
  />
125
132
  {:else if node.type === 'paragraph'}
126
133
  <p>
127
- <RichContent nodes={node.content ?? []} {registry} {schema} />
134
+ <RichContent nodes={node.content ?? []} {registry} {markRegistry} {schema} />
128
135
  </p>
129
136
  {:else if node.type === 'heading'}
130
137
  {@const level = Math.min(6, Math.max(1, Number(node.attrs?.level ?? 1)))}
@@ -137,53 +144,65 @@
137
144
  ? node.attrs.slug
138
145
  : undefined}
139
146
  {#if level === 1}
140
- <h1 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h1>
147
+ <h1 id={anchor}>
148
+ <RichContent nodes={node.content ?? []} {registry} {markRegistry} {schema} />
149
+ </h1>
141
150
  {:else if level === 2}
142
- <h2 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h2>
151
+ <h2 id={anchor}>
152
+ <RichContent nodes={node.content ?? []} {registry} {markRegistry} {schema} />
153
+ </h2>
143
154
  {:else if level === 3}
144
- <h3 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h3>
155
+ <h3 id={anchor}>
156
+ <RichContent nodes={node.content ?? []} {registry} {markRegistry} {schema} />
157
+ </h3>
145
158
  {:else if level === 4}
146
- <h4 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h4>
159
+ <h4 id={anchor}>
160
+ <RichContent nodes={node.content ?? []} {registry} {markRegistry} {schema} />
161
+ </h4>
147
162
  {:else if level === 5}
148
- <h5 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h5>
163
+ <h5 id={anchor}>
164
+ <RichContent nodes={node.content ?? []} {registry} {markRegistry} {schema} />
165
+ </h5>
149
166
  {:else}
150
- <h6 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h6>
167
+ <h6 id={anchor}>
168
+ <RichContent nodes={node.content ?? []} {registry} {markRegistry} {schema} />
169
+ </h6>
151
170
  {/if}
152
171
  {:else if node.type === 'table'}
153
172
  <div class="uncial-table-scroll">
154
173
  <table>
155
174
  <tbody>
156
- <RichContent nodes={node.content ?? []} {registry} {schema} />
175
+ <RichContent nodes={node.content ?? []} {registry} {markRegistry} {schema} />
157
176
  </tbody>
158
177
  </table>
159
178
  </div>
160
179
  {:else if node.type === 'tableRow'}
161
180
  <tr>
162
- <RichContent nodes={node.content ?? []} {registry} {schema} />
181
+ <RichContent nodes={node.content ?? []} {registry} {markRegistry} {schema} />
163
182
  </tr>
164
183
  {:else if node.type === 'tableHeader'}
165
184
  <th>
166
- <RichContent nodes={node.content ?? []} {registry} {schema} />
185
+ <RichContent nodes={node.content ?? []} {registry} {markRegistry} {schema} />
167
186
  </th>
168
187
  {:else if node.type === 'tableCell'}
169
188
  <td>
170
- <RichContent nodes={node.content ?? []} {registry} {schema} />
189
+ <RichContent nodes={node.content ?? []} {registry} {markRegistry} {schema} />
171
190
  </td>
172
191
  {:else if node.type === 'bulletList'}
173
192
  <ul>
174
- <RichContent nodes={node.content ?? []} {registry} {schema} />
193
+ <RichContent nodes={node.content ?? []} {registry} {markRegistry} {schema} />
175
194
  </ul>
176
195
  {:else if node.type === 'orderedList'}
177
196
  <ol>
178
- <RichContent nodes={node.content ?? []} {registry} {schema} />
197
+ <RichContent nodes={node.content ?? []} {registry} {markRegistry} {schema} />
179
198
  </ol>
180
199
  {:else if node.type === 'listItem'}
181
200
  <li>
182
- <RichContent nodes={node.content ?? []} {registry} {schema} />
201
+ <RichContent nodes={node.content ?? []} {registry} {markRegistry} {schema} />
183
202
  </li>
184
203
  {:else if node.type === 'blockquote'}
185
204
  <blockquote>
186
- <RichContent nodes={node.content ?? []} {registry} {schema} />
205
+ <RichContent nodes={node.content ?? []} {registry} {markRegistry} {schema} />
187
206
  </blockquote>
188
207
  {:else if node.type === 'horizontalRule'}
189
208
  <hr />
@@ -1,9 +1,10 @@
1
1
  import type { Component } from 'svelte';
2
- import type { BlockRegistry, ContentSchema } from '../core/types.js';
2
+ import type { BlockRegistry, ContentSchema, MarkRegistry } from '../core/types.js';
3
3
  import type { PMNode } from '../shared/document.js';
4
4
  interface Props {
5
5
  node: PMNode;
6
6
  registry: BlockRegistry;
7
+ markRegistry?: MarkRegistry;
7
8
  schema?: ContentSchema;
8
9
  tabsGroup?: string;
9
10
  tabsLabels?: string[];
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { MarkComponentProps } from '../core/types.js';
3
+
4
+ let { children }: MarkComponentProps = $props();
5
+ </script>
6
+
7
+ <sup>{@render children()}</sup>
@@ -0,0 +1,4 @@
1
+ import type { MarkComponentProps } from '../core/types.js';
2
+ declare const SuperscriptMarkFixture: import("svelte").Component<MarkComponentProps, {}, "">;
3
+ type SuperscriptMarkFixture = ReturnType<typeof SuperscriptMarkFixture>;
4
+ export default SuperscriptMarkFixture;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uncial",
3
- "version": "2.0.3",
3
+ "version": "3.0.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",