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
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
import { resolveRegistry } from '../core/registry.js';
|
|
3
3
|
import type { AttributeSpec, BlockDefinition, BlockRegistry } from '../core/types.js';
|
|
4
4
|
import { CODE_BLOCK_ID, codeBlockAttributeTarget } from '../shared/codeBlockAttributes.js';
|
|
5
|
-
import
|
|
5
|
+
import {
|
|
6
|
+
createInitialState,
|
|
7
|
+
type BlockAttributesController,
|
|
8
|
+
type BlockAttributesState
|
|
9
|
+
} from './attributesController.js';
|
|
6
10
|
import { flip } from 'svelte/animate';
|
|
7
11
|
import ArrowUpIcon from 'phosphor-svelte/lib/ArrowUpIcon';
|
|
8
12
|
import ArrowDownIcon from 'phosphor-svelte/lib/ArrowDownIcon';
|
|
@@ -12,28 +16,25 @@
|
|
|
12
16
|
import TrashIcon from 'phosphor-svelte/lib/TrashIcon';
|
|
13
17
|
import LinkAttributesPanel from './LinkAttributesPanel.svelte';
|
|
14
18
|
import AttributeFieldControl from './AttributeFieldControl.svelte';
|
|
19
|
+
import { dropdownDismiss } from './dropdownDismiss.js';
|
|
20
|
+
import { dropdownFloat } from './dropdownFloat.js';
|
|
21
|
+
import { CHOOSE_ATTRIBUTE_EVENT, type ChooseAttributeRequest } from './chooseAttribute.js';
|
|
15
22
|
|
|
16
23
|
interface Props {
|
|
17
24
|
controller: BlockAttributesController;
|
|
18
25
|
blocks?: BlockRegistry | BlockDefinition[];
|
|
26
|
+
/**
|
|
27
|
+
* Resolve a custom attribute value through host-provided UI. Preferred
|
|
28
|
+
* over the deprecated `window`-level `uncial:choose-attribute` event,
|
|
29
|
+
* which cross-talks between multiple editors on one page. When omitted,
|
|
30
|
+
* the panel falls back to dispatching that window event for back-compat.
|
|
31
|
+
*/
|
|
32
|
+
onChooseAttribute?: (request: ChooseAttributeRequest) => void;
|
|
19
33
|
}
|
|
20
34
|
|
|
21
|
-
let { controller, blocks = [] }: Props = $props();
|
|
35
|
+
let { controller, blocks = [], onChooseAttribute }: Props = $props();
|
|
22
36
|
|
|
23
|
-
let controllerState = $state<BlockAttributesState>(
|
|
24
|
-
open: false,
|
|
25
|
-
mode: null,
|
|
26
|
-
selectedBlockId: '',
|
|
27
|
-
draftAttrs: {},
|
|
28
|
-
validationErrors: {},
|
|
29
|
-
activeBlock: null,
|
|
30
|
-
allowedBlockIds: [],
|
|
31
|
-
containerChildren: [],
|
|
32
|
-
link: {
|
|
33
|
-
open: false,
|
|
34
|
-
attrs: {}
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
+
let controllerState = $state<BlockAttributesState>(createInitialState());
|
|
37
38
|
|
|
38
39
|
const registry = $derived(resolveRegistry(blocks));
|
|
39
40
|
const selectedBlock = $derived.by(() => {
|
|
@@ -47,6 +48,9 @@
|
|
|
47
48
|
? (Object.entries(selectedBlock.attributes) as Array<[string, AttributeSpec<unknown>]>)
|
|
48
49
|
: []
|
|
49
50
|
);
|
|
51
|
+
const selectedBlockReadOnly = $derived(
|
|
52
|
+
Boolean(selectedBlock && 'readOnly' in selectedBlock && selectedBlock.readOnly)
|
|
53
|
+
);
|
|
50
54
|
let childBlockQuery = $state('');
|
|
51
55
|
const hasChildren = $derived(controllerState.containerChildren.length > 0);
|
|
52
56
|
const canRemoveChild = $derived(controllerState.containerChildren.length > 1);
|
|
@@ -62,9 +66,18 @@
|
|
|
62
66
|
Boolean(controllerState.activeBlock) &&
|
|
63
67
|
Boolean(selectedBlock && 'content' in selectedBlock && selectedBlock.content)
|
|
64
68
|
);
|
|
69
|
+
// The open container's own declaration narrows what "Add block" may offer;
|
|
70
|
+
// a container declaring nothing offers everything the schema allows.
|
|
71
|
+
const admissibleChildBlocks = $derived.by(() => {
|
|
72
|
+
const declared =
|
|
73
|
+
selectedBlock && 'content' in selectedBlock ? selectedBlock.content?.allowedBlocks : undefined;
|
|
74
|
+
return declared ? activeBlocks.filter((block) => declared.includes(block.id)) : activeBlocks;
|
|
75
|
+
});
|
|
65
76
|
const filteredChildBlocks = $derived.by(() => {
|
|
66
77
|
const query = childBlockQuery.trim().toLowerCase();
|
|
67
|
-
return
|
|
78
|
+
return admissibleChildBlocks.filter(
|
|
79
|
+
(block) => !query || block.label.toLowerCase().includes(query)
|
|
80
|
+
);
|
|
68
81
|
});
|
|
69
82
|
let draggingChildIndex = $state<number | null>(null);
|
|
70
83
|
let draggingPointerId = $state<number | null>(null);
|
|
@@ -86,20 +99,25 @@
|
|
|
86
99
|
}
|
|
87
100
|
|
|
88
101
|
function chooseCustomAttribute(name: string, inputKind: string): void {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
for (const [key, value] of Object.entries(attrs)) {
|
|
97
|
-
controller.setDraftAttr(key, value);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
102
|
+
const request: ChooseAttributeRequest = {
|
|
103
|
+
inputKind,
|
|
104
|
+
name,
|
|
105
|
+
attrs: controllerState.draftAttrs,
|
|
106
|
+
setAttrs: (attrs: Record<string, unknown>) => {
|
|
107
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
108
|
+
controller.setDraftAttr(key, value);
|
|
100
109
|
}
|
|
101
|
-
}
|
|
102
|
-
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
if (onChooseAttribute) {
|
|
114
|
+
onChooseAttribute(request);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Deprecated fallback: a window-global channel that cross-talks between
|
|
119
|
+
// editors. Retained for one release for hosts not yet passing the prop.
|
|
120
|
+
window.dispatchEvent(new CustomEvent(CHOOSE_ATTRIBUTE_EVENT, { detail: request }));
|
|
103
121
|
}
|
|
104
122
|
|
|
105
123
|
function startChildDrag(event: PointerEvent, index: number): void {
|
|
@@ -157,16 +175,18 @@
|
|
|
157
175
|
{controllerState.mode === 'edit' ? 'Edit' : 'Configure'}
|
|
158
176
|
{selectedBlock.label || controllerState.selectedBlockId || 'block'}
|
|
159
177
|
</p>
|
|
160
|
-
{#
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
178
|
+
{#if !selectedBlockReadOnly}
|
|
179
|
+
{#each selectedAttributeSpecs as [name, spec] (name)}
|
|
180
|
+
<AttributeFieldControl
|
|
181
|
+
{name}
|
|
182
|
+
{spec}
|
|
183
|
+
value={controllerState.draftAttrs[name]}
|
|
184
|
+
error={controllerState.validationErrors[name]}
|
|
185
|
+
onChange={(value) => controller.setDraftAttr(name, value)}
|
|
186
|
+
onCustom={chooseCustomAttribute}
|
|
187
|
+
/>
|
|
188
|
+
{/each}
|
|
189
|
+
{/if}
|
|
170
190
|
<div class="uncial-panel__actions">
|
|
171
191
|
{#if controllerState.mode === 'edit'}
|
|
172
192
|
<button
|
|
@@ -195,8 +215,12 @@
|
|
|
195
215
|
<div class="uncial-children-section">
|
|
196
216
|
<div class="uncial-children-section__header">
|
|
197
217
|
<p class="uncial-section-label">Nested blocks</p>
|
|
198
|
-
{#if
|
|
199
|
-
<details
|
|
218
|
+
{#if admissibleChildBlocks.length > 0}
|
|
219
|
+
<details
|
|
220
|
+
class="uncial-dropdown uncial-dropdown--end"
|
|
221
|
+
use:dropdownDismiss
|
|
222
|
+
use:dropdownFloat
|
|
223
|
+
>
|
|
200
224
|
<summary class="uncial-btn uncial-btn--primary uncial-btn--xs">
|
|
201
225
|
<PlusIcon size={12} weight="bold" />
|
|
202
226
|
<span>Add block</span>
|
|
@@ -243,12 +267,20 @@
|
|
|
243
267
|
>
|
|
244
268
|
<DotsSixVerticalIcon size={12} weight="bold" />
|
|
245
269
|
</button>
|
|
246
|
-
<
|
|
270
|
+
<button
|
|
271
|
+
type="button"
|
|
272
|
+
class="uncial-child-item__content"
|
|
273
|
+
aria-current={child.pos === controllerState.activeBlock?.pos ? 'true' : undefined}
|
|
274
|
+
onclick={(event) => {
|
|
275
|
+
event.stopPropagation();
|
|
276
|
+
controller.openAttributesAt(child.pos);
|
|
277
|
+
}}
|
|
278
|
+
>
|
|
247
279
|
<span class="uncial-child-item__label">{child.label}</span>
|
|
248
280
|
{#if child.summary}
|
|
249
281
|
<span class="uncial-child-item__summary">{child.summary}</span>
|
|
250
282
|
{/if}
|
|
251
|
-
</
|
|
283
|
+
</button>
|
|
252
284
|
<div class="uncial-child-item__actions">
|
|
253
285
|
<button
|
|
254
286
|
type="button"
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import type { BlockDefinition, BlockRegistry } from '../core/types.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type BlockAttributesController } from './attributesController.js';
|
|
3
|
+
import { type ChooseAttributeRequest } from './chooseAttribute.js';
|
|
3
4
|
interface Props {
|
|
4
5
|
controller: BlockAttributesController;
|
|
5
6
|
blocks?: BlockRegistry | BlockDefinition[];
|
|
7
|
+
/**
|
|
8
|
+
* Resolve a custom attribute value through host-provided UI. Preferred
|
|
9
|
+
* over the deprecated `window`-level `uncial:choose-attribute` event,
|
|
10
|
+
* which cross-talks between multiple editors on one page. When omitted,
|
|
11
|
+
* the panel falls back to dispatching that window event for back-compat.
|
|
12
|
+
*/
|
|
13
|
+
onChooseAttribute?: (request: ChooseAttributeRequest) => void;
|
|
6
14
|
}
|
|
7
15
|
declare const BlockAttributesPanel: import("svelte").Component<Props, {}, "">;
|
|
8
16
|
type BlockAttributesPanel = ReturnType<typeof BlockAttributesPanel>;
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import { emptyDocument } from '../shared/content.js';
|
|
15
15
|
import {
|
|
16
16
|
createBlockAttributesController,
|
|
17
|
+
createInitialState,
|
|
17
18
|
type BlockAttributesController,
|
|
18
19
|
type BlockAttributesState
|
|
19
20
|
} from './attributesController.js';
|
|
@@ -23,8 +24,11 @@
|
|
|
23
24
|
type DocumentMetaController,
|
|
24
25
|
type DocumentMetaState
|
|
25
26
|
} from './metaController.js';
|
|
27
|
+
import BlockAttributesPanel from './BlockAttributesPanel.svelte';
|
|
26
28
|
import DocumentMetaPanel from './DocumentMetaPanel.svelte';
|
|
27
29
|
import Toolbar from './Toolbar.svelte';
|
|
30
|
+
import type { ChooseAttributeRequest } from './chooseAttribute.js';
|
|
31
|
+
import { dropdownDismiss } from './dropdownDismiss.js';
|
|
28
32
|
import type { ToolbarFeature, ToolbarFeatureSelection } from './toolbarFeatures.js';
|
|
29
33
|
|
|
30
34
|
interface Props {
|
|
@@ -38,7 +42,43 @@
|
|
|
38
42
|
toolbarExtensions?: ToolbarFeature[];
|
|
39
43
|
attributesController?: BlockAttributesController | null;
|
|
40
44
|
metaController?: DocumentMetaController | null;
|
|
45
|
+
/**
|
|
46
|
+
* Whether, and how, the editor renders its own block/link attributes
|
|
47
|
+
* panel. Registering a block is meant to be all it takes to edit one, so
|
|
48
|
+
* a panel is on by default; set `'off'` in a host that places
|
|
49
|
+
* `BlockAttributesPanel` itself, or the two panels both render.
|
|
50
|
+
*
|
|
51
|
+
* `'docked'` gives the panel a column of its own, which narrows the
|
|
52
|
+
* document by the panel's width. `'overlay'` floats it against the
|
|
53
|
+
* viewport edge for as long as a block is selected, so the document
|
|
54
|
+
* keeps exactly the width the host gave it — what a host rendering the
|
|
55
|
+
* document at its published width wants.
|
|
56
|
+
*/
|
|
57
|
+
attributesPanel?: boolean | 'docked' | 'overlay' | 'off';
|
|
58
|
+
/**
|
|
59
|
+
* `'card'` draws the editor as a bordered, padded surface — right when
|
|
60
|
+
* the editor sits in a page of its own chrome. `'bare'` draws no surface
|
|
61
|
+
* and reserves no inline space: `.uncial-content`'s content box is
|
|
62
|
+
* exactly the box the host gave the shell, and the block handles float
|
|
63
|
+
* over each block instead of pushing it inwards. A host that renders the
|
|
64
|
+
* document in its published layout wants `'bare'`, or every width the
|
|
65
|
+
* page's CSS derives from the container is wrong under the editor.
|
|
66
|
+
*/
|
|
67
|
+
presentation?: 'card' | 'bare';
|
|
68
|
+
/** Forwarded to the built-in panel; see `BlockAttributesPanel`. */
|
|
69
|
+
onChooseAttribute?: (request: ChooseAttributeRequest) => void;
|
|
41
70
|
onIssue?: (issue: ValidationIssue) => void;
|
|
71
|
+
/**
|
|
72
|
+
* The document after an edit, and the metadata after one.
|
|
73
|
+
*
|
|
74
|
+
* `json` and `meta` are bindable, so a host that only mirrors them needs
|
|
75
|
+
* neither of these. A host that has to *act* on an edit — persist it,
|
|
76
|
+
* mark itself dirty, debounce a save — does: binding alone cannot tell
|
|
77
|
+
* an edit the user made from a document the host itself just loaded, and
|
|
78
|
+
* every such host would otherwise reimplement the same guard flag.
|
|
79
|
+
*/
|
|
80
|
+
onChange?: (json: JSONContent) => void;
|
|
81
|
+
onMetaChange?: (meta: Record<string, unknown>) => void;
|
|
42
82
|
}
|
|
43
83
|
|
|
44
84
|
let {
|
|
@@ -52,26 +92,18 @@
|
|
|
52
92
|
toolbarExtensions = [],
|
|
53
93
|
attributesController = null,
|
|
54
94
|
metaController = null,
|
|
55
|
-
|
|
95
|
+
attributesPanel = true,
|
|
96
|
+
presentation = 'card',
|
|
97
|
+
onChooseAttribute,
|
|
98
|
+
onIssue,
|
|
99
|
+
onChange,
|
|
100
|
+
onMetaChange
|
|
56
101
|
}: Props = $props();
|
|
57
102
|
|
|
58
103
|
let editorHost: HTMLDivElement;
|
|
59
104
|
let editor = $state<TiptapEditor | null>(null);
|
|
60
105
|
let interactedNodeView = $state<HTMLElement | null>(null);
|
|
61
|
-
let controllerState = $state<BlockAttributesState>(
|
|
62
|
-
open: false,
|
|
63
|
-
mode: null,
|
|
64
|
-
selectedBlockId: '',
|
|
65
|
-
draftAttrs: {},
|
|
66
|
-
validationErrors: {},
|
|
67
|
-
activeBlock: null,
|
|
68
|
-
allowedBlockIds: [],
|
|
69
|
-
containerChildren: [],
|
|
70
|
-
link: {
|
|
71
|
-
open: false,
|
|
72
|
-
attrs: {}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
106
|
+
let controllerState = $state<BlockAttributesState>(createInitialState());
|
|
75
107
|
let attrsTriggerEl = $state<HTMLElement | null>(null);
|
|
76
108
|
let metaTriggerEl = $state<HTMLElement | null>(null);
|
|
77
109
|
const internalController = createBlockAttributesController();
|
|
@@ -82,9 +114,34 @@
|
|
|
82
114
|
dirty: false
|
|
83
115
|
});
|
|
84
116
|
let committedMetaSerialized = JSON.stringify(meta);
|
|
117
|
+
/**
|
|
118
|
+
* Whether the metadata controller has been told what the document's metadata
|
|
119
|
+
* is.
|
|
120
|
+
*
|
|
121
|
+
* The two effects that keep the `meta` prop and the controller in step are a
|
|
122
|
+
* pair, and neither may assume it runs first. Until the controller has been
|
|
123
|
+
* seeded it holds the schema's defaults, and pushing those outward would
|
|
124
|
+
* overwrite the metadata it has not been given yet. That is invisible to a
|
|
125
|
+
* host that mounts the editor first and supplies `meta` afterwards — the
|
|
126
|
+
* prop changes, so the sync runs — and fatal to one that has the document in
|
|
127
|
+
* hand before it renders, where the prop never changes and the seeding
|
|
128
|
+
* comparison below would otherwise match on the first pass and skip.
|
|
129
|
+
*/
|
|
130
|
+
let metaSeeded = $state(false);
|
|
85
131
|
|
|
86
132
|
const registry = $derived(resolveRegistry(blocks));
|
|
87
133
|
const controller = $derived(attributesController ?? internalController);
|
|
134
|
+
const panelMode = $derived.by(() => {
|
|
135
|
+
if (attributesPanel === true) return 'docked';
|
|
136
|
+
if (attributesPanel === false) return 'off';
|
|
137
|
+
return attributesPanel;
|
|
138
|
+
});
|
|
139
|
+
// An overlay panel covers the page, so it is only mounted while it has
|
|
140
|
+
// something to edit; a docked one holds its column either way.
|
|
141
|
+
const panelVisible = $derived(
|
|
142
|
+
panelMode === 'docked' ||
|
|
143
|
+
(panelMode === 'overlay' && (controllerState.open || controllerState.link.open))
|
|
144
|
+
);
|
|
88
145
|
const resolvedMetaFields = $derived.by(() => {
|
|
89
146
|
if (metaFields instanceof Map) return metaFields;
|
|
90
147
|
if (metaFields) return new Map(Object.entries(metaFields));
|
|
@@ -99,12 +156,13 @@
|
|
|
99
156
|
meta,
|
|
100
157
|
extensions,
|
|
101
158
|
attributesController: controller,
|
|
159
|
+
autoOpenAttributes: panelMode !== 'overlay',
|
|
102
160
|
onIssue,
|
|
103
161
|
onChange: (nextDocument) => {
|
|
104
|
-
|
|
162
|
+
setDocument(nextDocument);
|
|
105
163
|
},
|
|
106
164
|
onMetaChange: (nextMeta) => {
|
|
107
|
-
|
|
165
|
+
setMeta(nextMeta);
|
|
108
166
|
committedMetaSerialized = JSON.stringify(nextMeta);
|
|
109
167
|
documentMetaController.reset(nextMeta);
|
|
110
168
|
},
|
|
@@ -119,13 +177,25 @@
|
|
|
119
177
|
: !schema || schema.allowedBlocks.has(block.id)
|
|
120
178
|
)
|
|
121
179
|
);
|
|
180
|
+
/**
|
|
181
|
+
* Room for the block labels the gutter draws.
|
|
182
|
+
*
|
|
183
|
+
* A label wraps, so what has to fit on one line is its longest word, not the
|
|
184
|
+
* whole label. Reserving the whole label let one long block name in the
|
|
185
|
+
* registry take that width away from every document — "Content State
|
|
186
|
+
* conformance table" is thirty-one characters, which reserved about 365px of
|
|
187
|
+
* every editing surface, including in documents that never use the block.
|
|
188
|
+
*/
|
|
122
189
|
const editorGutterWidth = $derived.by(() => {
|
|
123
|
-
const
|
|
124
|
-
(longest, block) =>
|
|
190
|
+
const longestWord = registry.blocks.reduce(
|
|
191
|
+
(longest, block) =>
|
|
192
|
+
block.label
|
|
193
|
+
.split(/\s+/)
|
|
194
|
+
.reduce((widest, word) => Math.max(widest, word.length), longest),
|
|
125
195
|
0
|
|
126
196
|
);
|
|
127
197
|
|
|
128
|
-
return `max(var(--uncial-gutter-width), ${
|
|
198
|
+
return `max(var(--uncial-gutter-width), ${longestWord * 0.68 + 1.75}rem)`;
|
|
129
199
|
});
|
|
130
200
|
function insertBlock(blockId: string): void {
|
|
131
201
|
const ok = controller.insertBlock(blockId);
|
|
@@ -141,9 +211,27 @@
|
|
|
141
211
|
});
|
|
142
212
|
}
|
|
143
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Assign the document and tell the host, in that order.
|
|
216
|
+
*
|
|
217
|
+
* Metadata is part of the document, so a metadata commit has to reach a host
|
|
218
|
+
* that persists on `onChange` exactly as a keystroke does. Assigning `json`
|
|
219
|
+
* directly is what would silently drop it.
|
|
220
|
+
*/
|
|
221
|
+
function setDocument(next: JSONContent): void {
|
|
222
|
+
json = next;
|
|
223
|
+
onChange?.(next);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** The same for metadata: assign, then tell the host. */
|
|
227
|
+
function setMeta(next: Record<string, unknown>): void {
|
|
228
|
+
meta = next;
|
|
229
|
+
onMetaChange?.(next);
|
|
230
|
+
}
|
|
231
|
+
|
|
144
232
|
function commitMeta(nextMeta: Record<string, unknown>): void {
|
|
145
|
-
|
|
146
|
-
|
|
233
|
+
setMeta(nextMeta);
|
|
234
|
+
setDocument({ ...json, meta: nextMeta });
|
|
147
235
|
committedMetaSerialized = JSON.stringify(nextMeta);
|
|
148
236
|
metaTriggerEl?.closest('details')?.removeAttribute('open');
|
|
149
237
|
}
|
|
@@ -205,8 +293,9 @@
|
|
|
205
293
|
|
|
206
294
|
$effect(() => {
|
|
207
295
|
const serialized = JSON.stringify(meta);
|
|
208
|
-
if (serialized === committedMetaSerialized) return;
|
|
296
|
+
if (metaSeeded && serialized === committedMetaSerialized) return;
|
|
209
297
|
committedMetaSerialized = serialized;
|
|
298
|
+
metaSeeded = true;
|
|
210
299
|
documentMetaController.reset(meta);
|
|
211
300
|
});
|
|
212
301
|
|
|
@@ -218,8 +307,16 @@
|
|
|
218
307
|
return unsubscribe;
|
|
219
308
|
});
|
|
220
309
|
|
|
310
|
+
/*
|
|
311
|
+
* Reconcile the metadata panel's state into the document without reporting an
|
|
312
|
+
* edit. This runs on mount, when the panel still holds the schema's defaults
|
|
313
|
+
* and the loaded document's own metadata has not reached it yet: a host that
|
|
314
|
+
* persists on `onChange` would take those defaults for an edit and save a
|
|
315
|
+
* document whose required metadata is empty. A metadata change the author
|
|
316
|
+
* actually made arrives through `commitMeta`, which does report it.
|
|
317
|
+
*/
|
|
221
318
|
$effect(() => {
|
|
222
|
-
if (metaState.dirty) return;
|
|
319
|
+
if (!metaSeeded || metaState.dirty) return;
|
|
223
320
|
const nextMeta = documentMetaController.getMeta();
|
|
224
321
|
const serialized = JSON.stringify(nextMeta);
|
|
225
322
|
if (serialized === committedMetaSerialized) return;
|
|
@@ -266,7 +363,7 @@
|
|
|
266
363
|
});
|
|
267
364
|
</script>
|
|
268
365
|
|
|
269
|
-
<div class=
|
|
366
|
+
<div class={['uncial-editor-shell', presentation === 'bare' && 'uncial-editor-shell--bare']}>
|
|
270
367
|
<div class="uncial-toolbar">
|
|
271
368
|
<Toolbar
|
|
272
369
|
{editor}
|
|
@@ -278,7 +375,7 @@
|
|
|
278
375
|
{#if hasMetaFields || activeBlocks.length > 0}
|
|
279
376
|
<div class="uncial-toolbar__actions">
|
|
280
377
|
{#if hasMetaFields}
|
|
281
|
-
<details class="uncial-dropdown uncial-dropdown--end">
|
|
378
|
+
<details class="uncial-dropdown uncial-dropdown--end" use:dropdownDismiss>
|
|
282
379
|
<summary
|
|
283
380
|
bind:this={metaTriggerEl}
|
|
284
381
|
aria-label="Edit document metadata"
|
|
@@ -297,7 +394,7 @@
|
|
|
297
394
|
</details>
|
|
298
395
|
{/if}
|
|
299
396
|
{#if activeBlocks.length > 0}
|
|
300
|
-
<details class="uncial-dropdown uncial-dropdown--end">
|
|
397
|
+
<details class="uncial-dropdown uncial-dropdown--end" use:dropdownDismiss>
|
|
301
398
|
<summary
|
|
302
399
|
bind:this={attrsTriggerEl}
|
|
303
400
|
aria-label="Insert block"
|
|
@@ -329,4 +426,29 @@
|
|
|
329
426
|
use:bindEditor={editorBinding}
|
|
330
427
|
></div>
|
|
331
428
|
</div>
|
|
429
|
+
{#if panelVisible}
|
|
430
|
+
<aside
|
|
431
|
+
class={[
|
|
432
|
+
'uncial-editor-sidebar',
|
|
433
|
+
panelMode === 'overlay' && 'uncial-editor-sidebar--overlay'
|
|
434
|
+
]}
|
|
435
|
+
aria-label="Block attributes"
|
|
436
|
+
>
|
|
437
|
+
{#if panelMode === 'overlay'}
|
|
438
|
+
<div class="uncial-editor-sidebar__head">
|
|
439
|
+
<button
|
|
440
|
+
type="button"
|
|
441
|
+
class="uncial-btn uncial-btn--ghost uncial-btn--sm"
|
|
442
|
+
onclick={() => {
|
|
443
|
+
controller.closeLinkAttributes();
|
|
444
|
+
controller.closeAttributes();
|
|
445
|
+
}}
|
|
446
|
+
>
|
|
447
|
+
Close
|
|
448
|
+
</button>
|
|
449
|
+
</div>
|
|
450
|
+
{/if}
|
|
451
|
+
<BlockAttributesPanel {controller} {blocks} {onChooseAttribute} />
|
|
452
|
+
</aside>
|
|
453
|
+
{/if}
|
|
332
454
|
</div>
|
|
@@ -2,6 +2,7 @@ import type { AnyExtension, JSONContent } from '@tiptap/core';
|
|
|
2
2
|
import type { 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
|
+
import type { ChooseAttributeRequest } from './chooseAttribute.js';
|
|
5
6
|
import type { ToolbarFeature, ToolbarFeatureSelection } from './toolbarFeatures.js';
|
|
6
7
|
interface Props {
|
|
7
8
|
blocks?: BlockRegistry | BlockDefinition[];
|
|
@@ -14,7 +15,43 @@ interface Props {
|
|
|
14
15
|
toolbarExtensions?: ToolbarFeature[];
|
|
15
16
|
attributesController?: BlockAttributesController | null;
|
|
16
17
|
metaController?: DocumentMetaController | null;
|
|
18
|
+
/**
|
|
19
|
+
* Whether, and how, the editor renders its own block/link attributes
|
|
20
|
+
* panel. Registering a block is meant to be all it takes to edit one, so
|
|
21
|
+
* a panel is on by default; set `'off'` in a host that places
|
|
22
|
+
* `BlockAttributesPanel` itself, or the two panels both render.
|
|
23
|
+
*
|
|
24
|
+
* `'docked'` gives the panel a column of its own, which narrows the
|
|
25
|
+
* document by the panel's width. `'overlay'` floats it against the
|
|
26
|
+
* viewport edge for as long as a block is selected, so the document
|
|
27
|
+
* keeps exactly the width the host gave it — what a host rendering the
|
|
28
|
+
* document at its published width wants.
|
|
29
|
+
*/
|
|
30
|
+
attributesPanel?: boolean | 'docked' | 'overlay' | 'off';
|
|
31
|
+
/**
|
|
32
|
+
* `'card'` draws the editor as a bordered, padded surface — right when
|
|
33
|
+
* the editor sits in a page of its own chrome. `'bare'` draws no surface
|
|
34
|
+
* and reserves no inline space: `.uncial-content`'s content box is
|
|
35
|
+
* exactly the box the host gave the shell, and the block handles float
|
|
36
|
+
* over each block instead of pushing it inwards. A host that renders the
|
|
37
|
+
* document in its published layout wants `'bare'`, or every width the
|
|
38
|
+
* page's CSS derives from the container is wrong under the editor.
|
|
39
|
+
*/
|
|
40
|
+
presentation?: 'card' | 'bare';
|
|
41
|
+
/** Forwarded to the built-in panel; see `BlockAttributesPanel`. */
|
|
42
|
+
onChooseAttribute?: (request: ChooseAttributeRequest) => void;
|
|
17
43
|
onIssue?: (issue: ValidationIssue) => void;
|
|
44
|
+
/**
|
|
45
|
+
* The document after an edit, and the metadata after one.
|
|
46
|
+
*
|
|
47
|
+
* `json` and `meta` are bindable, so a host that only mirrors them needs
|
|
48
|
+
* neither of these. A host that has to *act* on an edit — persist it,
|
|
49
|
+
* mark itself dirty, debounce a save — does: binding alone cannot tell
|
|
50
|
+
* an edit the user made from a document the host itself just loaded, and
|
|
51
|
+
* every such host would otherwise reimplement the same guard flag.
|
|
52
|
+
*/
|
|
53
|
+
onChange?: (json: JSONContent) => void;
|
|
54
|
+
onMetaChange?: (meta: Record<string, unknown>) => void;
|
|
18
55
|
}
|
|
19
56
|
declare const Editor: import("svelte").Component<Props, {}, "json" | "meta">;
|
|
20
57
|
type Editor = ReturnType<typeof Editor>;
|