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.
- package/README.md +82 -15
- package/dist/core/attributes.d.ts +21 -3
- package/dist/core/attributes.js +86 -15
- package/dist/core/defineBlock.js +26 -12
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.js +2 -1
- package/dist/core/issues.d.ts +7 -0
- package/dist/core/issues.js +9 -0
- package/dist/core/meta.js +2 -7
- package/dist/core/migrations.d.ts +30 -0
- package/dist/core/migrations.js +50 -0
- package/dist/core/normalize.d.ts +12 -1
- package/dist/core/normalize.js +123 -22
- package/dist/core/registry.d.ts +7 -0
- package/dist/core/registry.js +35 -4
- package/dist/core/runtime.d.ts +7 -0
- package/dist/core/types.d.ts +31 -3
- package/dist/core/validate.js +27 -7
- package/dist/editor/AttributeFieldControl.svelte +155 -7
- package/dist/editor/AttributeFieldControl.svelte.d.ts +1 -0
- package/dist/editor/BlockAttributesPanel.svelte +76 -44
- package/dist/editor/BlockAttributesPanel.svelte.d.ts +9 -1
- package/dist/editor/Editor.svelte +149 -27
- package/dist/editor/Editor.svelte.d.ts +37 -0
- package/dist/editor/RichTextAttributeEditor.svelte +75 -145
- package/dist/editor/RichTextAttributeEditor.svelte.d.ts +2 -1
- package/dist/editor/Toolbar.svelte +2 -3
- package/dist/editor/attributeTargets.d.ts +23 -0
- package/dist/editor/attributeTargets.js +21 -0
- package/dist/editor/attributesController.d.ts +12 -0
- package/dist/editor/attributesController.js +142 -230
- package/dist/editor/bindEditor.d.ts +7 -0
- package/dist/editor/bindEditor.js +141 -27
- package/dist/editor/chooseAttribute.d.ts +26 -0
- package/dist/editor/chooseAttribute.js +10 -0
- package/dist/editor/containerChildOps.d.ts +33 -0
- package/dist/editor/containerChildOps.js +115 -0
- package/dist/editor/dropdownDismiss.d.ts +18 -0
- package/dist/editor/dropdownDismiss.js +46 -0
- package/dist/editor/dropdownFloat.d.ts +16 -0
- package/dist/editor/dropdownFloat.js +127 -0
- package/dist/editor/index.d.ts +3 -1
- package/dist/editor/index.js +2 -1
- package/dist/editor/linkController.d.ts +19 -0
- package/dist/editor/linkController.js +72 -0
- package/dist/editor/toolbarFeatures.d.ts +12 -0
- package/dist/editor/toolbarFeatures.js +36 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/render/Renderer.svelte +1 -1
- package/dist/render/RichContent.svelte +12 -4
- package/dist/render/RichContent.svelte.d.ts +2 -0
- package/dist/render/RichNode.svelte +80 -10
- package/dist/render/RichNode.svelte.d.ts +2 -0
- package/dist/render/Tab.svelte +27 -0
- package/dist/render/Tab.svelte.d.ts +10 -0
- package/dist/render/Tabs.svelte +57 -0
- package/dist/render/Tabs.svelte.d.ts +10 -0
- package/dist/render/index.d.ts +3 -0
- package/dist/render/index.js +6 -0
- package/dist/render/sanitize.d.ts +6 -0
- package/dist/render/sanitize.js +20 -1
- package/dist/render/tabSelection.svelte.d.ts +8 -0
- package/dist/render/tabSelection.svelte.js +40 -0
- package/dist/runtime/reactiveProps.svelte.d.ts +16 -0
- package/dist/runtime/reactiveProps.svelte.js +16 -0
- package/dist/runtime/svelte.d.ts +2 -1
- package/dist/runtime/svelte.js +26 -6
- package/dist/shared/EditorBlockFixture.svelte +24 -0
- package/dist/shared/EditorBlockFixture.svelte.d.ts +9 -0
- package/dist/shared/content.js +2 -1
- package/dist/shared/documentIdentity.d.ts +6 -0
- package/dist/shared/documentIdentity.js +64 -0
- package/dist/shared/guards.d.ts +13 -0
- package/dist/shared/guards.js +16 -0
- package/dist/shared/richText.js +20 -4
- package/dist/shared/runtimeId.d.ts +8 -0
- package/dist/shared/runtimeId.js +8 -0
- package/dist/shared/syntaxHighlight.d.ts +14 -0
- package/dist/shared/syntaxHighlight.js +36 -3
- package/dist/shared/tiptap.js +140 -27
- package/dist/styles/base.css +177 -0
- package/dist/styles/prose.css +26 -0
- package/dist/styles/tokens.css +53 -69
- package/dist/tabs.d.ts +6 -0
- package/dist/tabs.js +36 -0
- package/dist/web-components/UncialEditor.svelte +23 -7
- package/dist/web-components/UncialEditor.svelte.d.ts +7 -2
- package/dist/web-components/index.d.ts +45 -10
- package/dist/web-components/index.js +98 -36
- package/dist/web-components/reactiveProps.svelte.d.ts +10 -0
- package/dist/web-components/reactiveProps.svelte.js +13 -0
- package/package.json +134 -133
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Editor } from '@tiptap/core';
|
|
2
|
+
import { type Writable } from 'svelte/store';
|
|
3
|
+
import type { BlockAttributesState, LinkAttributes } from './attributesController.js';
|
|
4
|
+
/** The link mark's attributes for the current selection, or null if none is active. */
|
|
5
|
+
export declare function getActiveLinkAttrs(editor: Editor | null): LinkAttributes | null;
|
|
6
|
+
export interface LinkController {
|
|
7
|
+
open(): void;
|
|
8
|
+
close(): void;
|
|
9
|
+
setAttr(name: keyof LinkAttributes, value: string | null): void;
|
|
10
|
+
commit(): boolean;
|
|
11
|
+
remove(): boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Owns the `link` slice of the shared attributes state. It reads the editor
|
|
15
|
+
* lazily via `getEditor` (the controller's editor reference changes on
|
|
16
|
+
* attach/detach) and mutates only `state.link`, leaving the rest of the
|
|
17
|
+
* snapshot untouched.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createLinkController(getEditor: () => Editor | null, state: Writable<BlockAttributesState>): LinkController;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { get } from 'svelte/store';
|
|
2
|
+
import { sanitizeHref } from '../render/sanitize.js';
|
|
3
|
+
/** The link mark's attributes for the current selection, or null if none is active. */
|
|
4
|
+
export function getActiveLinkAttrs(editor) {
|
|
5
|
+
if (!editor?.isActive('link'))
|
|
6
|
+
return null;
|
|
7
|
+
return editor.getAttributes('link');
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Owns the `link` slice of the shared attributes state. It reads the editor
|
|
11
|
+
* lazily via `getEditor` (the controller's editor reference changes on
|
|
12
|
+
* attach/detach) and mutates only `state.link`, leaving the rest of the
|
|
13
|
+
* snapshot untouched.
|
|
14
|
+
*/
|
|
15
|
+
export function createLinkController(getEditor, state) {
|
|
16
|
+
function close() {
|
|
17
|
+
state.update((current) => ({ ...current, link: { open: false, attrs: {} } }));
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
open() {
|
|
21
|
+
const editor = getEditor();
|
|
22
|
+
if (!editor)
|
|
23
|
+
return;
|
|
24
|
+
const attrs = getActiveLinkAttrs(editor) ?? { href: '' };
|
|
25
|
+
state.update((current) => ({ ...current, link: { open: true, attrs } }));
|
|
26
|
+
},
|
|
27
|
+
close,
|
|
28
|
+
setAttr(name, value) {
|
|
29
|
+
state.update((current) => ({
|
|
30
|
+
...current,
|
|
31
|
+
link: {
|
|
32
|
+
open: true,
|
|
33
|
+
attrs: {
|
|
34
|
+
...current.link.attrs,
|
|
35
|
+
[name]: value
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
},
|
|
40
|
+
commit() {
|
|
41
|
+
const editor = getEditor();
|
|
42
|
+
if (!editor)
|
|
43
|
+
return false;
|
|
44
|
+
const attrs = get(state).link.attrs;
|
|
45
|
+
const href = sanitizeHref(attrs.href);
|
|
46
|
+
if (!href)
|
|
47
|
+
return false;
|
|
48
|
+
return editor
|
|
49
|
+
.chain()
|
|
50
|
+
.focus()
|
|
51
|
+
.extendMarkRange('link')
|
|
52
|
+
.setMark('link', {
|
|
53
|
+
...attrs,
|
|
54
|
+
href,
|
|
55
|
+
target: attrs.target || null,
|
|
56
|
+
rel: attrs.rel || null,
|
|
57
|
+
title: attrs.title?.trim() || null,
|
|
58
|
+
class: attrs.class?.trim() || null
|
|
59
|
+
})
|
|
60
|
+
.run();
|
|
61
|
+
},
|
|
62
|
+
remove() {
|
|
63
|
+
const editor = getEditor();
|
|
64
|
+
if (!editor)
|
|
65
|
+
return false;
|
|
66
|
+
const ok = editor.chain().focus().extendMarkRange('link').unsetLink().run();
|
|
67
|
+
if (ok)
|
|
68
|
+
close();
|
|
69
|
+
return ok;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -18,6 +18,18 @@ export interface ToolbarFeature {
|
|
|
18
18
|
}
|
|
19
19
|
export declare const defaultToolbarFeatures: readonly ToolbarFeatureId[];
|
|
20
20
|
export declare const builtinToolbarFeatures: readonly ToolbarFeature[];
|
|
21
|
+
/**
|
|
22
|
+
* A single generic heading toggle (level 3) whose active state matches any
|
|
23
|
+
* heading level. Used by editors that expose one heading control instead of
|
|
24
|
+
* the per-level `heading2`..`heading6` buttons.
|
|
25
|
+
*/
|
|
26
|
+
export declare const genericHeadingToolbarFeature: ToolbarFeature;
|
|
27
|
+
/**
|
|
28
|
+
* Toolbar descriptors for the rich text attribute editor. Ids line up with
|
|
29
|
+
* `RichTextFeature` names so the list can be filtered by a resolved rich text
|
|
30
|
+
* feature set; labels match that editor's existing button labels.
|
|
31
|
+
*/
|
|
32
|
+
export declare const richTextAttributeToolbarFeatures: readonly ToolbarFeature[];
|
|
21
33
|
export declare function resolveToolbarFeatures({ editor, schema, toolbarFeatures, toolbarExtensions }: {
|
|
22
34
|
editor: Editor | null | undefined;
|
|
23
35
|
schema?: ContentSchema;
|
|
@@ -129,6 +129,42 @@ export const builtinToolbarFeatures = [
|
|
|
129
129
|
run: ({ editor }) => editor.chain().focus().setHorizontalRule().run()
|
|
130
130
|
}
|
|
131
131
|
];
|
|
132
|
+
/**
|
|
133
|
+
* A single generic heading toggle (level 3) whose active state matches any
|
|
134
|
+
* heading level. Used by editors that expose one heading control instead of
|
|
135
|
+
* the per-level `heading2`..`heading6` buttons.
|
|
136
|
+
*/
|
|
137
|
+
export const genericHeadingToolbarFeature = {
|
|
138
|
+
id: 'heading',
|
|
139
|
+
label: 'Heading',
|
|
140
|
+
group: 'heading',
|
|
141
|
+
isActive: ({ editor }) => editor.isActive('heading'),
|
|
142
|
+
canRun: ({ editor }) => editor.can().chain().focus().toggleHeading({ level: 3 }).run(),
|
|
143
|
+
run: ({ editor }) => editor.chain().focus().toggleHeading({ level: 3 }).run()
|
|
144
|
+
};
|
|
145
|
+
function builtinFeature(id) {
|
|
146
|
+
const feature = builtinToolbarFeatures.find((entry) => entry.id === id);
|
|
147
|
+
if (!feature)
|
|
148
|
+
throw new Error(`Unknown builtin toolbar feature: ${id}`);
|
|
149
|
+
return feature;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Toolbar descriptors for the rich text attribute editor. Ids line up with
|
|
153
|
+
* `RichTextFeature` names so the list can be filtered by a resolved rich text
|
|
154
|
+
* feature set; labels match that editor's existing button labels.
|
|
155
|
+
*/
|
|
156
|
+
export const richTextAttributeToolbarFeatures = [
|
|
157
|
+
builtinFeature('bold'),
|
|
158
|
+
builtinFeature('italic'),
|
|
159
|
+
{ ...builtinFeature('strike'), label: 'Strikethrough' },
|
|
160
|
+
{ ...builtinFeature('code'), label: 'Inline code' },
|
|
161
|
+
genericHeadingToolbarFeature,
|
|
162
|
+
builtinFeature('bulletList'),
|
|
163
|
+
builtinFeature('orderedList'),
|
|
164
|
+
builtinFeature('blockquote'),
|
|
165
|
+
builtinFeature('codeBlock'),
|
|
166
|
+
builtinFeature('horizontalRule')
|
|
167
|
+
];
|
|
132
168
|
export function resolveToolbarFeatures({ editor, schema, toolbarFeatures, toolbarExtensions = [] }) {
|
|
133
169
|
if (!editor)
|
|
134
170
|
return [];
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import type { PMDoc, PMNode } from '../shared/document.js';
|
|
13
13
|
import { resolveRegistry } from '../core/registry.js';
|
|
14
14
|
import { emptyDocument } from '../shared/content.js';
|
|
15
|
-
import { SVELTE_RUNTIME_ID } from '../
|
|
15
|
+
import { SVELTE_RUNTIME_ID } from '../shared/runtimeId.js';
|
|
16
16
|
import RichContent from './RichContent.svelte';
|
|
17
17
|
|
|
18
18
|
interface Props {
|
|
@@ -7,18 +7,26 @@
|
|
|
7
7
|
nodes?: PMNode[];
|
|
8
8
|
registry: BlockRegistry;
|
|
9
9
|
schema?: ContentSchema;
|
|
10
|
+
tabsGroup?: string;
|
|
11
|
+
tabsLabels?: string[];
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
let {
|
|
14
|
+
let {
|
|
15
|
+
nodes = [],
|
|
16
|
+
registry,
|
|
17
|
+
schema = undefined,
|
|
18
|
+
tabsGroup = undefined,
|
|
19
|
+
tabsLabels = undefined
|
|
20
|
+
}: Props = $props();
|
|
13
21
|
|
|
14
22
|
function getNodeKey(node: PMNode, index: number): string {
|
|
15
23
|
const id = node.attrs?.id;
|
|
16
24
|
if (typeof id === 'string' || typeof id === 'number') {
|
|
17
|
-
return `${node.type}:${id}`;
|
|
25
|
+
return `${node.type}:${id}:${index}`;
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
if (typeof node.text === 'string' && node.text.length > 0) {
|
|
21
|
-
return `${node.type}:${node.text}`;
|
|
29
|
+
return `${node.type}:${node.text}:${index}`;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
return `${node.type}:${JSON.stringify(node.attrs ?? {})}:${index}`;
|
|
@@ -26,5 +34,5 @@
|
|
|
26
34
|
</script>
|
|
27
35
|
|
|
28
36
|
{#each nodes as node, index (getNodeKey(node, index))}
|
|
29
|
-
<RichNode {node} {registry} {schema} />
|
|
37
|
+
<RichNode {node} {registry} {schema} {tabsGroup} {tabsLabels} />
|
|
30
38
|
{/each}
|
|
@@ -4,6 +4,8 @@ interface Props {
|
|
|
4
4
|
nodes?: PMNode[];
|
|
5
5
|
registry: BlockRegistry;
|
|
6
6
|
schema?: ContentSchema;
|
|
7
|
+
tabsGroup?: string;
|
|
8
|
+
tabsLabels?: string[];
|
|
7
9
|
}
|
|
8
10
|
declare const RichContent: import("svelte").Component<Props, {}, "">;
|
|
9
11
|
type RichContent = ReturnType<typeof RichContent>;
|
|
@@ -4,15 +4,23 @@
|
|
|
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';
|
|
7
|
-
import { sanitizeHref } from './sanitize.js';
|
|
7
|
+
import { resolveLinkRel, sanitizeHref } from './sanitize.js';
|
|
8
8
|
|
|
9
9
|
interface Props {
|
|
10
10
|
node: PMNode;
|
|
11
11
|
registry: BlockRegistry;
|
|
12
12
|
schema?: ContentSchema;
|
|
13
|
+
tabsGroup?: string;
|
|
14
|
+
tabsLabels?: string[];
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
let {
|
|
17
|
+
let {
|
|
18
|
+
node,
|
|
19
|
+
registry,
|
|
20
|
+
schema = undefined,
|
|
21
|
+
tabsGroup = undefined,
|
|
22
|
+
tabsLabels = undefined
|
|
23
|
+
}: Props = $props();
|
|
16
24
|
|
|
17
25
|
const block = $derived(registry.get(node.type));
|
|
18
26
|
const blockAttrs = $derived((node.attrs ?? {}) as Record<string, unknown>);
|
|
@@ -25,6 +33,18 @@
|
|
|
25
33
|
.join('')
|
|
26
34
|
);
|
|
27
35
|
const highlightedCode = $derived(highlightCodeToHtml(codeText, codeLanguage));
|
|
36
|
+
const childTabsGroup = $derived.by(() => {
|
|
37
|
+
if (node.type !== 'tabs' || typeof node.attrs?.group !== 'string') return tabsGroup;
|
|
38
|
+
return node.attrs.group.trim() || undefined;
|
|
39
|
+
});
|
|
40
|
+
const childTabsLabels = $derived.by(() => {
|
|
41
|
+
if (node.type !== 'tabs') return tabsLabels;
|
|
42
|
+
return blockContent.flatMap((child) => {
|
|
43
|
+
if (child.type !== 'tab' || typeof child.attrs?.label !== 'string') return [];
|
|
44
|
+
const label = child.attrs.label.trim();
|
|
45
|
+
return label ? [label] : [];
|
|
46
|
+
});
|
|
47
|
+
});
|
|
28
48
|
|
|
29
49
|
function getActiveMarks(marks: PMMark[] = []): PMMark[] {
|
|
30
50
|
return schema ? marks.filter((mark) => schema.allowedMarks.has(mark.type)) : marks;
|
|
@@ -33,10 +53,30 @@
|
|
|
33
53
|
function getSvelteRenderComponent(component: unknown): Component<Record<string, unknown>> {
|
|
34
54
|
return component as Component<Record<string, unknown>>;
|
|
35
55
|
}
|
|
56
|
+
|
|
57
|
+
function getLinkAttrs(attrs: Record<string, unknown> | undefined): Record<string, string> {
|
|
58
|
+
const result: Record<string, string> = {};
|
|
59
|
+
if (attrs) {
|
|
60
|
+
if (typeof attrs.title === 'string' && attrs.title) result.title = attrs.title;
|
|
61
|
+
if (typeof attrs.class === 'string' && attrs.class) result.class = attrs.class;
|
|
62
|
+
const target =
|
|
63
|
+
typeof attrs.target === 'string' && attrs.target.trim() ? attrs.target.trim() : undefined;
|
|
64
|
+
if (target) result.target = target;
|
|
65
|
+
const rel = resolveLinkRel(attrs.rel, target);
|
|
66
|
+
if (rel) result.rel = rel;
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
36
70
|
</script>
|
|
37
71
|
|
|
38
72
|
{#snippet blockChildren()}
|
|
39
|
-
<RichContent
|
|
73
|
+
<RichContent
|
|
74
|
+
nodes={blockContent}
|
|
75
|
+
{registry}
|
|
76
|
+
{schema}
|
|
77
|
+
tabsGroup={childTabsGroup}
|
|
78
|
+
tabsLabels={childTabsLabels}
|
|
79
|
+
/>
|
|
40
80
|
{/snippet}
|
|
41
81
|
|
|
42
82
|
{#snippet renderMarkedText(text: string, marks: PMMark[])}
|
|
@@ -56,7 +96,7 @@
|
|
|
56
96
|
{@const href = sanitizeHref(mark.attrs?.href)}
|
|
57
97
|
{#if href}
|
|
58
98
|
<!-- 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>
|
|
99
|
+
<a {href} {...getLinkAttrs(mark.attrs)}>{@render renderMarkedText(text, rest)}</a>
|
|
60
100
|
{:else}
|
|
61
101
|
{@render renderMarkedText(text, rest)}
|
|
62
102
|
{/if}
|
|
@@ -78,6 +118,8 @@
|
|
|
78
118
|
{...blockAttrs}
|
|
79
119
|
{...(block as unknown as { renderProps?: Record<string, unknown> }).renderProps ?? {}}
|
|
80
120
|
content={blockContent}
|
|
121
|
+
{tabsGroup}
|
|
122
|
+
{tabsLabels}
|
|
81
123
|
children={block.content ? blockChildren : undefined}
|
|
82
124
|
/>
|
|
83
125
|
{:else if node.type === 'paragraph'}
|
|
@@ -86,19 +128,47 @@
|
|
|
86
128
|
</p>
|
|
87
129
|
{:else if node.type === 'heading'}
|
|
88
130
|
{@const level = Math.min(6, Math.max(1, Number(node.attrs?.level ?? 1)))}
|
|
131
|
+
<!-- The anchor is the heading's persisted slug, never its text: a slug is
|
|
132
|
+
stamped once at authoring time so that retitling a section leaves every
|
|
133
|
+
link into it resolving. A heading that carries no slug gets no id
|
|
134
|
+
rather than a text-derived one, which would rot on the next edit. -->
|
|
135
|
+
{@const anchor =
|
|
136
|
+
typeof node.attrs?.slug === 'string' && node.attrs.slug.length > 0
|
|
137
|
+
? node.attrs.slug
|
|
138
|
+
: undefined}
|
|
89
139
|
{#if level === 1}
|
|
90
|
-
<h1><RichContent nodes={node.content ?? []} {registry} {schema} /></h1>
|
|
140
|
+
<h1 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h1>
|
|
91
141
|
{:else if level === 2}
|
|
92
|
-
<h2><RichContent nodes={node.content ?? []} {registry} {schema} /></h2>
|
|
142
|
+
<h2 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h2>
|
|
93
143
|
{:else if level === 3}
|
|
94
|
-
<h3><RichContent nodes={node.content ?? []} {registry} {schema} /></h3>
|
|
144
|
+
<h3 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h3>
|
|
95
145
|
{:else if level === 4}
|
|
96
|
-
<h4><RichContent nodes={node.content ?? []} {registry} {schema} /></h4>
|
|
146
|
+
<h4 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h4>
|
|
97
147
|
{:else if level === 5}
|
|
98
|
-
<h5><RichContent nodes={node.content ?? []} {registry} {schema} /></h5>
|
|
148
|
+
<h5 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h5>
|
|
99
149
|
{:else}
|
|
100
|
-
<h6><RichContent nodes={node.content ?? []} {registry} {schema} /></h6>
|
|
150
|
+
<h6 id={anchor}><RichContent nodes={node.content ?? []} {registry} {schema} /></h6>
|
|
101
151
|
{/if}
|
|
152
|
+
{:else if node.type === 'table'}
|
|
153
|
+
<div class="uncial-table-scroll">
|
|
154
|
+
<table>
|
|
155
|
+
<tbody>
|
|
156
|
+
<RichContent nodes={node.content ?? []} {registry} {schema} />
|
|
157
|
+
</tbody>
|
|
158
|
+
</table>
|
|
159
|
+
</div>
|
|
160
|
+
{:else if node.type === 'tableRow'}
|
|
161
|
+
<tr>
|
|
162
|
+
<RichContent nodes={node.content ?? []} {registry} {schema} />
|
|
163
|
+
</tr>
|
|
164
|
+
{:else if node.type === 'tableHeader'}
|
|
165
|
+
<th>
|
|
166
|
+
<RichContent nodes={node.content ?? []} {registry} {schema} />
|
|
167
|
+
</th>
|
|
168
|
+
{:else if node.type === 'tableCell'}
|
|
169
|
+
<td>
|
|
170
|
+
<RichContent nodes={node.content ?? []} {registry} {schema} />
|
|
171
|
+
</td>
|
|
102
172
|
{:else if node.type === 'bulletList'}
|
|
103
173
|
<ul>
|
|
104
174
|
<RichContent nodes={node.content ?? []} {registry} {schema} />
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { getTabSelection } from './tabSelection.svelte.js';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
label?: string;
|
|
7
|
+
tabsGroup?: string;
|
|
8
|
+
tabsLabels?: string[];
|
|
9
|
+
children?: Snippet;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let { label = '', tabsGroup = undefined, tabsLabels = [], children }: Props = $props();
|
|
13
|
+
|
|
14
|
+
const normalizedLabel = $derived(label.trim());
|
|
15
|
+
const selection = $derived.by(() => (tabsGroup ? getTabSelection(tabsGroup) : null));
|
|
16
|
+
const activeTab = $derived.by(() => {
|
|
17
|
+
if (!selection) return true;
|
|
18
|
+
const selected = selection.value;
|
|
19
|
+
return (tabsLabels.includes(selected) ? selected : tabsLabels[0]) === normalizedLabel;
|
|
20
|
+
});
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<section role={tabsGroup ? 'tabpanel' : undefined} aria-label={normalizedLabel} hidden={!activeTab}>
|
|
24
|
+
{#if children}
|
|
25
|
+
{@render children()}
|
|
26
|
+
{/if}
|
|
27
|
+
</section>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
label?: string;
|
|
4
|
+
tabsGroup?: string;
|
|
5
|
+
tabsLabels?: string[];
|
|
6
|
+
children?: Snippet;
|
|
7
|
+
}
|
|
8
|
+
declare const Tab: import("svelte").Component<Props, {}, "">;
|
|
9
|
+
type Tab = ReturnType<typeof Tab>;
|
|
10
|
+
export default Tab;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import type { PMNode } from '../shared/document.js';
|
|
4
|
+
import { getTabSelection, loadTabSelection, saveTabSelection } from './tabSelection.svelte.js';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
group?: string;
|
|
8
|
+
content?: PMNode[];
|
|
9
|
+
children?: Snippet;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let { group = '', content = [], children }: Props = $props();
|
|
13
|
+
|
|
14
|
+
const tabs = $derived.by(() =>
|
|
15
|
+
content.flatMap((node) => {
|
|
16
|
+
if (node.type !== 'tab' || typeof node.attrs?.label !== 'string') return [];
|
|
17
|
+
const label = node.attrs.label.trim();
|
|
18
|
+
return label ? [label] : [];
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
const selection = $derived.by(() => (group ? getTabSelection(group) : null));
|
|
22
|
+
const activeTab = $derived.by(() => {
|
|
23
|
+
if (!selection) return tabs[0] ?? '';
|
|
24
|
+
return tabs.includes(selection.value) ? selection.value : (tabs[0] ?? '');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
$effect(() => {
|
|
28
|
+
if (!selection) return;
|
|
29
|
+
loadTabSelection(group, selection);
|
|
30
|
+
saveTabSelection(group, selection);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
function selectTab(label: string): void {
|
|
34
|
+
if (!selection) return;
|
|
35
|
+
selection.value = label;
|
|
36
|
+
saveTabSelection(group, selection);
|
|
37
|
+
}
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<section class="uncial-tabs">
|
|
41
|
+
<div role="tablist" aria-label={`${group} tabs`}>
|
|
42
|
+
{#each tabs as tab}
|
|
43
|
+
<button
|
|
44
|
+
type="button"
|
|
45
|
+
role="tab"
|
|
46
|
+
aria-selected={activeTab === tab}
|
|
47
|
+
tabindex={activeTab === tab ? 0 : -1}
|
|
48
|
+
onclick={() => selectTab(tab)}>{tab}</button
|
|
49
|
+
>
|
|
50
|
+
{/each}
|
|
51
|
+
</div>
|
|
52
|
+
<div class="uncial-tabs-content">
|
|
53
|
+
{#if children}
|
|
54
|
+
{@render children()}
|
|
55
|
+
{/if}
|
|
56
|
+
</div>
|
|
57
|
+
</section>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { PMNode } from '../shared/document.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
group?: string;
|
|
5
|
+
content?: PMNode[];
|
|
6
|
+
children?: Snippet;
|
|
7
|
+
}
|
|
8
|
+
declare const Tabs: import("svelte").Component<Props, {}, "">;
|
|
9
|
+
type Tabs = ReturnType<typeof Tabs>;
|
|
10
|
+
export default Tabs;
|
package/dist/render/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export { default as Renderer } from './Renderer.svelte';
|
|
2
2
|
export { default as RichText } from './RichText.svelte';
|
|
3
|
+
export { default as Tab } from './Tab.svelte';
|
|
4
|
+
export { default as Tabs } from './Tabs.svelte';
|
|
5
|
+
export { getCodeLanguageClass, highlightCodeToHtml } from '../shared/syntaxHighlight.js';
|
package/dist/render/index.js
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
export { default as Renderer } from './Renderer.svelte';
|
|
2
2
|
export { default as RichText } from './RichText.svelte';
|
|
3
|
+
export { default as Tab } from './Tab.svelte';
|
|
4
|
+
export { default as Tabs } from './Tabs.svelte';
|
|
5
|
+
// A consumer's own code block — one built from a component rather than placed in
|
|
6
|
+
// a document — has to read the same as a fence the renderer produced, so the
|
|
7
|
+
// highlighter the renderer uses is part of the render surface.
|
|
8
|
+
export { getCodeLanguageClass, highlightCodeToHtml } from '../shared/syntaxHighlight.js';
|
|
@@ -1 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the `rel` attribute for a rendered link: keeps any stored rel tokens
|
|
3
|
+
* and guarantees `noopener` is present whenever the link opens a new browsing
|
|
4
|
+
* context (`_blank` in any case variant, or a named window).
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolveLinkRel(rel: unknown, target: string | undefined): string | null;
|
|
1
7
|
export declare function sanitizeHref(value: unknown): string | null;
|
package/dist/render/sanitize.js
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
const SAFE_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'tel:']);
|
|
2
|
+
// Targets that reuse an existing browsing context and never hand the new page a
|
|
3
|
+
// window.opener; every other non-empty target (including named windows) does.
|
|
4
|
+
const OPENERLESS_TARGETS = new Set(['_self', '_parent', '_top']);
|
|
5
|
+
/**
|
|
6
|
+
* Resolve the `rel` attribute for a rendered link: keeps any stored rel tokens
|
|
7
|
+
* and guarantees `noopener` is present whenever the link opens a new browsing
|
|
8
|
+
* context (`_blank` in any case variant, or a named window).
|
|
9
|
+
*/
|
|
10
|
+
export function resolveLinkRel(rel, target) {
|
|
11
|
+
const stored = typeof rel === 'string' ? rel.trim() : '';
|
|
12
|
+
const tokens = stored ? stored.split(/\s+/) : [];
|
|
13
|
+
const opensNewContext = Boolean(target) && !OPENERLESS_TARGETS.has(target.toLowerCase());
|
|
14
|
+
if (opensNewContext && !tokens.includes('noopener')) {
|
|
15
|
+
tokens.push('noopener');
|
|
16
|
+
}
|
|
17
|
+
return tokens.length > 0 ? tokens.join(' ') : null;
|
|
18
|
+
}
|
|
2
19
|
export function sanitizeHref(value) {
|
|
3
20
|
if (typeof value !== 'string')
|
|
4
21
|
return null;
|
|
5
22
|
const trimmed = value.trim();
|
|
6
23
|
if (!trimmed)
|
|
7
24
|
return null;
|
|
8
|
-
|
|
25
|
+
// Protocol-relative URLs (`//host/...`) are NOT app-relative: they resolve to
|
|
26
|
+
// another origin, so they must go through the protocol check below.
|
|
27
|
+
if ((trimmed.startsWith('/') && !trimmed.startsWith('//')) || trimmed.startsWith('#'))
|
|
9
28
|
return trimmed;
|
|
10
29
|
try {
|
|
11
30
|
const url = new URL(trimmed, 'https://uncial.local');
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface TabSelectionState {
|
|
2
|
+
value: string;
|
|
3
|
+
loaded: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function getTabSelection(group: string): TabSelectionState;
|
|
6
|
+
export declare function loadTabSelection(group: string, selection: TabSelectionState): void;
|
|
7
|
+
export declare function saveTabSelection(group: string, selection: TabSelectionState): void;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const STORAGE_PREFIX = 'uncial-tabs:';
|
|
2
|
+
const selections = new Map();
|
|
3
|
+
class TabSelection {
|
|
4
|
+
value = $state('');
|
|
5
|
+
loaded = $state(false);
|
|
6
|
+
}
|
|
7
|
+
export function getTabSelection(group) {
|
|
8
|
+
if (typeof window === 'undefined') {
|
|
9
|
+
return { value: '', loaded: false };
|
|
10
|
+
}
|
|
11
|
+
let selection = selections.get(group);
|
|
12
|
+
if (!selection) {
|
|
13
|
+
selection = new TabSelection();
|
|
14
|
+
selections.set(group, selection);
|
|
15
|
+
}
|
|
16
|
+
return selection;
|
|
17
|
+
}
|
|
18
|
+
export function loadTabSelection(group, selection) {
|
|
19
|
+
if (selection.loaded || typeof window === 'undefined')
|
|
20
|
+
return;
|
|
21
|
+
selection.loaded = true;
|
|
22
|
+
try {
|
|
23
|
+
const stored = localStorage.getItem(`${STORAGE_PREFIX}${group}`);
|
|
24
|
+
if (stored)
|
|
25
|
+
selection.value = stored;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Tabs still work for readers whose browser denies storage access.
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function saveTabSelection(group, selection) {
|
|
32
|
+
if (!selection.loaded || typeof window === 'undefined')
|
|
33
|
+
return;
|
|
34
|
+
try {
|
|
35
|
+
localStorage.setItem(`${STORAGE_PREFIX}${group}`, selection.value);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Persistence is an enhancement; storage failures must not disable a tab group.
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `$state`-backed props for imperatively mounted Svelte components.
|
|
3
|
+
*
|
|
4
|
+
* `mount(Component, { props })` only propagates later prop changes when the
|
|
5
|
+
* props object is reactive, so this helper wraps the initial props in `$state`
|
|
6
|
+
* and exposes an `update()` that mutates the object in place. Runes are only
|
|
7
|
+
* available in `.svelte.ts` modules, which is why this lives outside
|
|
8
|
+
* `runtime/svelte.ts`.
|
|
9
|
+
*/
|
|
10
|
+
export interface ReactivePropsHandle {
|
|
11
|
+
/** The `$state`-backed props object to pass to `mount()`. */
|
|
12
|
+
props: Record<string, unknown>;
|
|
13
|
+
/** Mutates `props` in place so it exactly matches `next`. */
|
|
14
|
+
update(next: Record<string, unknown>): void;
|
|
15
|
+
}
|
|
16
|
+
export declare function createReactiveProps(initial: Record<string, unknown>): ReactivePropsHandle;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function createReactiveProps(initial) {
|
|
2
|
+
const props = $state({ ...initial });
|
|
3
|
+
return {
|
|
4
|
+
props,
|
|
5
|
+
update(next) {
|
|
6
|
+
for (const [key, value] of Object.entries(next)) {
|
|
7
|
+
props[key] = value;
|
|
8
|
+
}
|
|
9
|
+
for (const key of Object.keys(props)) {
|
|
10
|
+
if (!(key in next)) {
|
|
11
|
+
delete props[key];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
package/dist/runtime/svelte.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Component, Snippet } from 'svelte';
|
|
2
2
|
import type { BlockRuntimePlugin } from '../core/runtime.js';
|
|
3
3
|
import type { BlockAttributes, RuntimeBlockConfig } from '../core/types.js';
|
|
4
|
-
|
|
4
|
+
import { SVELTE_RUNTIME_ID } from '../shared/runtimeId.js';
|
|
5
|
+
export { SVELTE_RUNTIME_ID };
|
|
5
6
|
export interface SvelteBlockComponentProps {
|
|
6
7
|
content?: unknown[];
|
|
7
8
|
children?: Snippet;
|