uncial 0.0.5 → 0.0.7
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 +99 -3
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.js +1 -0
- package/dist/core/meta.d.ts +7 -0
- package/dist/core/meta.js +72 -0
- package/dist/core/normalize.js +7 -1
- package/dist/core/registry.js +3 -1
- package/dist/core/types.d.ts +5 -1
- package/dist/core/validate.js +2 -0
- package/dist/editor/AttributeFieldControl.svelte +113 -0
- package/dist/editor/AttributeFieldControl.svelte.d.ts +12 -0
- package/dist/editor/BlockAttributesPanel.svelte +41 -134
- package/dist/editor/BlockMenu.svelte +24 -35
- package/dist/editor/BlockMenu.svelte.d.ts +5 -19
- package/dist/editor/DocumentMetaPanel.svelte +69 -0
- package/dist/editor/DocumentMetaPanel.svelte.d.ts +10 -0
- package/dist/editor/Editor.svelte +128 -249
- package/dist/editor/Editor.svelte.d.ts +6 -2
- package/dist/editor/LinkAttributesPanel.svelte +32 -19
- package/dist/editor/RichTextAttributeEditor.svelte +40 -30
- package/dist/editor/Toolbar.svelte +40 -7
- package/dist/editor/bindEditor.d.ts +2 -0
- package/dist/editor/bindEditor.js +7 -2
- package/dist/editor/index.d.ts +4 -0
- package/dist/editor/index.js +3 -0
- package/dist/editor/metaController.d.ts +19 -0
- package/dist/editor/metaController.js +71 -0
- package/dist/render/Renderer.svelte +12 -3
- package/dist/render/Renderer.svelte.d.ts +2 -0
- package/dist/render/RichNode.svelte +3 -8
- package/dist/render/RichText.svelte +2 -1
- package/dist/shared/content.d.ts +2 -1
- package/dist/shared/content.js +7 -2
- package/dist/shared/document.d.ts +1 -0
- package/dist/styles/base.css +418 -0
- package/dist/styles/chrome.css +3 -0
- package/dist/styles/controls.css +306 -0
- package/dist/styles/index.css +2 -0
- package/dist/styles/prose.css +115 -0
- package/dist/styles/tokens.css +77 -0
- package/dist/ui/ThemeSwitcher.svelte +32 -0
- package/dist/ui/ThemeSwitcher.svelte.d.ts +3 -0
- package/dist/ui/theme.svelte.d.ts +8 -0
- package/dist/ui/theme.svelte.js +56 -0
- package/package.json +7 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { inferAttributeInputKind, normalizeAttributeOptions } from '../core/attributes.js';
|
|
3
2
|
import { resolveRegistry } from '../core/registry.js';
|
|
4
3
|
import type { AttributeSpec, BlockDefinition, BlockRegistry } from '../core/types.js';
|
|
5
4
|
import { CODE_BLOCK_ID, codeBlockAttributeTarget } from '../shared/codeBlockAttributes.js';
|
|
@@ -11,8 +10,8 @@
|
|
|
11
10
|
import DotsSixVerticalIcon from 'phosphor-svelte/lib/DotsSixVerticalIcon';
|
|
12
11
|
import PlusIcon from 'phosphor-svelte/lib/PlusIcon';
|
|
13
12
|
import TrashIcon from 'phosphor-svelte/lib/TrashIcon';
|
|
14
|
-
import RichTextAttributeEditor from './RichTextAttributeEditor.svelte';
|
|
15
13
|
import LinkAttributesPanel from './LinkAttributesPanel.svelte';
|
|
14
|
+
import AttributeFieldControl from './AttributeFieldControl.svelte';
|
|
16
15
|
|
|
17
16
|
interface Props {
|
|
18
17
|
controller: BlockAttributesController;
|
|
@@ -70,13 +69,6 @@
|
|
|
70
69
|
let draggingChildIndex = $state<number | null>(null);
|
|
71
70
|
let draggingPointerId = $state<number | null>(null);
|
|
72
71
|
|
|
73
|
-
function getDraftStringValue(name: string): string {
|
|
74
|
-
const value = controllerState.draftAttrs[name];
|
|
75
|
-
if (typeof value === 'string') return value;
|
|
76
|
-
if (value === undefined || value === null) return '';
|
|
77
|
-
return String(value);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
72
|
function moveUp(index: number): void {
|
|
81
73
|
if (index > 0) controller.moveContainerChild(index, index - 1);
|
|
82
74
|
}
|
|
@@ -110,12 +102,6 @@
|
|
|
110
102
|
);
|
|
111
103
|
}
|
|
112
104
|
|
|
113
|
-
function isBuiltInInputKind(inputKind: string): boolean {
|
|
114
|
-
return ['checkbox', 'number', 'richtext', 'select', 'textarea', 'json', 'text', 'hidden'].includes(
|
|
115
|
-
inputKind
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
105
|
function startChildDrag(event: PointerEvent, index: number): void {
|
|
120
106
|
event.stopPropagation();
|
|
121
107
|
draggingChildIndex = index;
|
|
@@ -167,144 +153,63 @@
|
|
|
167
153
|
onClose={() => controller.closeLinkAttributes()}
|
|
168
154
|
/>
|
|
169
155
|
{:else if controllerState.open && selectedBlock}
|
|
170
|
-
<p class="uncial-attrs-title
|
|
156
|
+
<p class="uncial-attrs-title">
|
|
171
157
|
{controllerState.mode === 'edit' ? 'Edit' : 'Configure'}
|
|
172
158
|
{selectedBlock.label || controllerState.selectedBlockId || 'block'}
|
|
173
159
|
</p>
|
|
174
160
|
{#each selectedAttributeSpecs as [name, spec] (name)}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
{
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
{#if !isBuiltInInputKind(inputKind)}
|
|
184
|
-
<button
|
|
185
|
-
type="button"
|
|
186
|
-
class="btn btn-outline btn-sm justify-start"
|
|
187
|
-
onclick={() => chooseCustomAttribute(name, inputKind)}
|
|
188
|
-
>
|
|
189
|
-
{controllerState.draftAttrs[name]
|
|
190
|
-
? `Change ${name}: ${controllerState.draftAttrs[name]}`
|
|
191
|
-
: `Choose ${name}`}
|
|
192
|
-
</button>
|
|
193
|
-
{:else if inputKind === 'checkbox'}
|
|
194
|
-
<input
|
|
195
|
-
class="checkbox checkbox-sm"
|
|
196
|
-
type="checkbox"
|
|
197
|
-
checked={Boolean(controllerState.draftAttrs[name])}
|
|
198
|
-
onchange={(event) => {
|
|
199
|
-
const target = event.currentTarget as HTMLInputElement;
|
|
200
|
-
controller.setDraftAttr(name, target.checked);
|
|
201
|
-
}}
|
|
202
|
-
/>
|
|
203
|
-
{:else if inputKind === 'number'}
|
|
204
|
-
<input
|
|
205
|
-
class="input input-bordered input-sm"
|
|
206
|
-
type="number"
|
|
207
|
-
placeholder={spec.placeholder ?? name}
|
|
208
|
-
value={controllerState.draftAttrs[name] ?? ''}
|
|
209
|
-
oninput={(event) => {
|
|
210
|
-
const target = event.currentTarget as HTMLInputElement;
|
|
211
|
-
controller.setDraftAttr(name, target.value === '' ? '' : target.valueAsNumber);
|
|
212
|
-
}}
|
|
213
|
-
/>
|
|
214
|
-
{:else if inputKind === 'richtext'}
|
|
215
|
-
<RichTextAttributeEditor
|
|
216
|
-
value={controllerState.draftAttrs[name]}
|
|
217
|
-
features={spec.richText?.features}
|
|
218
|
-
placeholder={spec.richText?.placeholder ?? spec.placeholder ?? name}
|
|
219
|
-
onChange={(value) => controller.setDraftAttr(name, value)}
|
|
220
|
-
/>
|
|
221
|
-
{:else if inputKind === 'select'}
|
|
222
|
-
{@const options = normalizeAttributeOptions(spec) ?? []}
|
|
223
|
-
<select
|
|
224
|
-
class="select select-bordered select-sm"
|
|
225
|
-
aria-label={name}
|
|
226
|
-
value={getDraftStringValue(name)}
|
|
227
|
-
onchange={(event) => {
|
|
228
|
-
const target = event.currentTarget as HTMLSelectElement;
|
|
229
|
-
controller.setDraftAttr(name, target.value);
|
|
230
|
-
}}
|
|
231
|
-
>
|
|
232
|
-
{#each options as option (String(option.value))}
|
|
233
|
-
<option value={String(option.value)}>{option.label ?? String(option.value)}</option>
|
|
234
|
-
{/each}
|
|
235
|
-
</select>
|
|
236
|
-
{:else if inputKind === 'textarea' || inputKind === 'json'}
|
|
237
|
-
<textarea
|
|
238
|
-
class="textarea textarea-bordered min-h-28"
|
|
239
|
-
placeholder={spec.placeholder ?? name}
|
|
240
|
-
spellcheck={inputKind !== 'json'}
|
|
241
|
-
value={getDraftStringValue(name)}
|
|
242
|
-
oninput={(event) => {
|
|
243
|
-
const target = event.currentTarget as HTMLTextAreaElement;
|
|
244
|
-
controller.setDraftAttr(name, target.value);
|
|
245
|
-
}}
|
|
246
|
-
></textarea>
|
|
247
|
-
{:else}
|
|
248
|
-
<input
|
|
249
|
-
class="input input-bordered input-sm"
|
|
250
|
-
type="text"
|
|
251
|
-
placeholder={spec.placeholder ?? name}
|
|
252
|
-
value={getDraftStringValue(name)}
|
|
253
|
-
oninput={(event) => {
|
|
254
|
-
const target = event.currentTarget as HTMLInputElement;
|
|
255
|
-
controller.setDraftAttr(name, target.value);
|
|
256
|
-
}}
|
|
257
|
-
/>
|
|
258
|
-
{/if}
|
|
259
|
-
{#if controllerState.validationErrors[name]}
|
|
260
|
-
<span class="text-xs text-error">{controllerState.validationErrors[name]}</span>
|
|
261
|
-
{/if}
|
|
262
|
-
</div>
|
|
263
|
-
{/if}
|
|
161
|
+
<AttributeFieldControl
|
|
162
|
+
{name}
|
|
163
|
+
{spec}
|
|
164
|
+
value={controllerState.draftAttrs[name]}
|
|
165
|
+
error={controllerState.validationErrors[name]}
|
|
166
|
+
onChange={(value) => controller.setDraftAttr(name, value)}
|
|
167
|
+
onCustom={chooseCustomAttribute}
|
|
168
|
+
/>
|
|
264
169
|
{/each}
|
|
265
|
-
<div
|
|
266
|
-
class="sticky -bottom-4 flex flex-wrap items-center justify-between gap-2 bg-base-100 pt-3"
|
|
267
|
-
>
|
|
170
|
+
<div class="uncial-panel__actions">
|
|
268
171
|
{#if controllerState.mode === 'edit'}
|
|
269
172
|
<button
|
|
270
173
|
type="button"
|
|
271
|
-
class="btn btn-
|
|
174
|
+
class="uncial-btn uncial-btn--danger uncial-btn--outline uncial-btn--sm"
|
|
272
175
|
onclick={() => controller.removeActiveBlock()}
|
|
273
176
|
>
|
|
274
177
|
Remove Block
|
|
275
178
|
</button>
|
|
276
179
|
{/if}
|
|
277
180
|
{#if controllerState.mode !== 'edit' && controllerState.selectedBlockId !== CODE_BLOCK_ID}
|
|
278
|
-
<button
|
|
181
|
+
<button
|
|
182
|
+
type="button"
|
|
183
|
+
class="uncial-btn uncial-btn--primary uncial-btn--sm"
|
|
184
|
+
onclick={() => controller.commit()}
|
|
185
|
+
>
|
|
279
186
|
Insert Block
|
|
280
187
|
</button>
|
|
281
188
|
{/if}
|
|
282
189
|
</div>
|
|
283
190
|
{:else}
|
|
284
|
-
<p class="
|
|
191
|
+
<p class="uncial-help-text">Select a block to edit its attributes.</p>
|
|
285
192
|
{/if}
|
|
286
193
|
|
|
287
194
|
{#if !controllerState.link.open && canAddNestedBlock}
|
|
288
|
-
<div class="uncial-children-section
|
|
289
|
-
<div class="
|
|
290
|
-
<p class="
|
|
195
|
+
<div class="uncial-children-section">
|
|
196
|
+
<div class="uncial-children-section__header">
|
|
197
|
+
<p class="uncial-section-label">Nested blocks</p>
|
|
291
198
|
{#if activeBlocks.length > 0}
|
|
292
|
-
<details class="dropdown dropdown
|
|
293
|
-
<summary class="btn btn
|
|
199
|
+
<details class="uncial-dropdown uncial-dropdown--end">
|
|
200
|
+
<summary class="uncial-btn uncial-btn--primary uncial-btn--xs">
|
|
294
201
|
<PlusIcon size={12} weight="bold" />
|
|
295
202
|
<span>Add block</span>
|
|
296
203
|
<CaretDownIcon size={10} weight="bold" />
|
|
297
204
|
</summary>
|
|
298
|
-
<div
|
|
299
|
-
class="dropdown-content z-20 mt-2 w-56 rounded-box border border-base-300 bg-base-100 p-2 shadow-xl"
|
|
300
|
-
>
|
|
205
|
+
<div class="uncial-dropdown__menu uncial-dropdown__menu--wide">
|
|
301
206
|
<input
|
|
302
|
-
class="input
|
|
207
|
+
class="uncial-input uncial-input--xs uncial-input--block uncial-dropdown__search"
|
|
303
208
|
type="search"
|
|
304
209
|
placeholder="Filter blocks..."
|
|
305
210
|
bind:value={childBlockQuery}
|
|
306
211
|
/>
|
|
307
|
-
<ul class="menu
|
|
212
|
+
<ul class="uncial-menu uncial-menu--scroll">
|
|
308
213
|
{#each filteredChildBlocks as block (block.id)}
|
|
309
214
|
<li>
|
|
310
215
|
<button type="button" onclick={() => addNestedBlock(block.id)}>
|
|
@@ -312,7 +217,7 @@
|
|
|
312
217
|
</button>
|
|
313
218
|
</li>
|
|
314
219
|
{:else}
|
|
315
|
-
<li class="
|
|
220
|
+
<li class="uncial-menu__empty">No matching blocks</li>
|
|
316
221
|
{/each}
|
|
317
222
|
</ul>
|
|
318
223
|
</div>
|
|
@@ -320,32 +225,34 @@
|
|
|
320
225
|
{/if}
|
|
321
226
|
</div>
|
|
322
227
|
{#if hasChildren}
|
|
323
|
-
<ul class="uncial-children-list
|
|
228
|
+
<ul class="uncial-children-list">
|
|
324
229
|
{#each controllerState.containerChildren as child, index (child.key)}
|
|
325
230
|
<li
|
|
326
|
-
class=
|
|
327
|
-
|
|
231
|
+
class={[
|
|
232
|
+
'uncial-child-item',
|
|
233
|
+
draggingChildIndex === index ? 'uncial-child-item--dragging' : ''
|
|
234
|
+
]}
|
|
328
235
|
data-child-index={index}
|
|
329
236
|
animate:flip={{ duration: 120 }}
|
|
330
237
|
>
|
|
331
238
|
<button
|
|
332
239
|
type="button"
|
|
333
|
-
class="btn btn
|
|
240
|
+
class="uncial-btn uncial-btn--ghost uncial-btn--xs uncial-btn--square uncial-btn--drag"
|
|
334
241
|
aria-label="Drag nested block"
|
|
335
242
|
onpointerdown={(event) => startChildDrag(event, index)}
|
|
336
243
|
>
|
|
337
244
|
<DotsSixVerticalIcon size={12} weight="bold" />
|
|
338
245
|
</button>
|
|
339
|
-
<div class="
|
|
340
|
-
<span class="
|
|
246
|
+
<div class="uncial-child-item__content">
|
|
247
|
+
<span class="uncial-child-item__label">{child.label}</span>
|
|
341
248
|
{#if child.summary}
|
|
342
|
-
<span class="
|
|
249
|
+
<span class="uncial-child-item__summary">{child.summary}</span>
|
|
343
250
|
{/if}
|
|
344
251
|
</div>
|
|
345
|
-
<div class="
|
|
252
|
+
<div class="uncial-child-item__actions">
|
|
346
253
|
<button
|
|
347
254
|
type="button"
|
|
348
|
-
class="btn btn
|
|
255
|
+
class="uncial-btn uncial-btn--ghost uncial-btn--xs uncial-btn--square"
|
|
349
256
|
aria-label="Move up"
|
|
350
257
|
disabled={index === 0}
|
|
351
258
|
onclick={(event) => {
|
|
@@ -357,7 +264,7 @@
|
|
|
357
264
|
</button>
|
|
358
265
|
<button
|
|
359
266
|
type="button"
|
|
360
|
-
class="btn btn
|
|
267
|
+
class="uncial-btn uncial-btn--ghost uncial-btn--xs uncial-btn--square"
|
|
361
268
|
aria-label="Move down"
|
|
362
269
|
disabled={index === controllerState.containerChildren.length - 1}
|
|
363
270
|
onclick={(event) => {
|
|
@@ -369,7 +276,7 @@
|
|
|
369
276
|
</button>
|
|
370
277
|
<button
|
|
371
278
|
type="button"
|
|
372
|
-
class="btn btn
|
|
279
|
+
class="uncial-btn uncial-btn--ghost uncial-btn--danger uncial-btn--xs uncial-btn--square"
|
|
373
280
|
aria-label="Remove nested block"
|
|
374
281
|
disabled={!canRemoveChild}
|
|
375
282
|
onclick={(event) => {
|
|
@@ -384,7 +291,7 @@
|
|
|
384
291
|
{/each}
|
|
385
292
|
</ul>
|
|
386
293
|
{:else}
|
|
387
|
-
<p class="
|
|
294
|
+
<p class="uncial-help-text">No nested blocks yet.</p>
|
|
388
295
|
{/if}
|
|
389
296
|
</div>
|
|
390
297
|
{/if}
|
|
@@ -4,16 +4,22 @@
|
|
|
4
4
|
import { resolveRegistry } from '../core/registry.js';
|
|
5
5
|
import { getBlockDefaultAttrs } from '../shared/tiptap.js';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
interface Props {
|
|
8
|
+
editor?: Editor | null;
|
|
9
|
+
blocks?: BlockRegistry | BlockDefinition[];
|
|
10
|
+
schema?: ContentSchema;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let { editor = null, blocks = [], schema = undefined }: Props = $props();
|
|
10
14
|
|
|
11
|
-
let query = '';
|
|
15
|
+
let query = $state('');
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
.
|
|
16
|
-
|
|
17
|
+
const registry = $derived(resolveRegistry(blocks));
|
|
18
|
+
const availableBlocks = $derived(
|
|
19
|
+
registry.blocks
|
|
20
|
+
.filter((block: BlockDefinition) => !schema || schema.allowedBlocks.has(block.id))
|
|
21
|
+
.filter((block: BlockDefinition) => block.label.toLowerCase().includes(query.toLowerCase()))
|
|
22
|
+
);
|
|
17
23
|
|
|
18
24
|
function insertBlock(id: string): void {
|
|
19
25
|
if (!editor) return;
|
|
@@ -31,33 +37,16 @@
|
|
|
31
37
|
}
|
|
32
38
|
</script>
|
|
33
39
|
|
|
34
|
-
<div class="uncial-toolbar">
|
|
35
|
-
<input
|
|
40
|
+
<div class="uncial-block-menu uncial-toolbar">
|
|
41
|
+
<input
|
|
42
|
+
class="uncial-input uncial-input--sm"
|
|
43
|
+
type="search"
|
|
44
|
+
placeholder="Filter blocks..."
|
|
45
|
+
bind:value={query}
|
|
46
|
+
/>
|
|
36
47
|
{#each availableBlocks as block (block.id)}
|
|
37
|
-
<button type="button"
|
|
48
|
+
<button type="button" class="uncial-btn uncial-btn--sm" onclick={() => insertBlock(block.id)}>
|
|
49
|
+
{block.label}
|
|
50
|
+
</button>
|
|
38
51
|
{/each}
|
|
39
52
|
</div>
|
|
40
|
-
|
|
41
|
-
<style>
|
|
42
|
-
.uncial-toolbar {
|
|
43
|
-
display: flex;
|
|
44
|
-
flex-wrap: wrap;
|
|
45
|
-
gap: 0.5rem;
|
|
46
|
-
padding: 0.75rem;
|
|
47
|
-
border-bottom: 1px solid #ececec;
|
|
48
|
-
background: #f9f9f9;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
.uncial-toolbar button,
|
|
52
|
-
.uncial-toolbar input {
|
|
53
|
-
font: inherit;
|
|
54
|
-
padding: 0.35rem 0.55rem;
|
|
55
|
-
border: 1px solid #cfcfcf;
|
|
56
|
-
border-radius: 8px;
|
|
57
|
-
background: #fff;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
.uncial-toolbar button {
|
|
61
|
-
cursor: pointer;
|
|
62
|
-
}
|
|
63
|
-
</style>
|
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
import type { Editor } from '@tiptap/core';
|
|
2
2
|
import type { BlockDefinition, BlockRegistry, ContentSchema } from '../core/types.js';
|
|
3
|
-
interface
|
|
4
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
5
|
-
$$bindings?: Bindings;
|
|
6
|
-
} & Exports;
|
|
7
|
-
(internal: unknown, props: Props & {
|
|
8
|
-
$$events?: Events;
|
|
9
|
-
$$slots?: Slots;
|
|
10
|
-
}): Exports & {
|
|
11
|
-
$set?: any;
|
|
12
|
-
$on?: any;
|
|
13
|
-
};
|
|
14
|
-
z_$$bindings?: Bindings;
|
|
15
|
-
}
|
|
16
|
-
declare const BlockMenu: $$__sveltets_2_IsomorphicComponent<{
|
|
3
|
+
interface Props {
|
|
17
4
|
editor?: Editor | null;
|
|
18
5
|
blocks?: BlockRegistry | BlockDefinition[];
|
|
19
|
-
schema?: ContentSchema
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
type BlockMenu = InstanceType<typeof BlockMenu>;
|
|
6
|
+
schema?: ContentSchema;
|
|
7
|
+
}
|
|
8
|
+
declare const BlockMenu: import("svelte").Component<Props, {}, "">;
|
|
9
|
+
type BlockMenu = ReturnType<typeof BlockMenu>;
|
|
24
10
|
export default BlockMenu;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { AttributeSpec } from '../core/types.js';
|
|
3
|
+
import AttributeFieldControl from './AttributeFieldControl.svelte';
|
|
4
|
+
import type { DocumentMetaController, DocumentMetaState } from './metaController.js';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
controller: DocumentMetaController;
|
|
8
|
+
fields?: ReadonlyMap<string, AttributeSpec<unknown>>;
|
|
9
|
+
onCommit?: (meta: Record<string, unknown>) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let { controller, fields = new Map(), onCommit }: Props = $props();
|
|
13
|
+
|
|
14
|
+
let controllerState = $state<DocumentMetaState>({
|
|
15
|
+
draft: {},
|
|
16
|
+
errors: {},
|
|
17
|
+
dirty: false
|
|
18
|
+
});
|
|
19
|
+
const fieldEntries = $derived(Array.from(fields.entries()));
|
|
20
|
+
|
|
21
|
+
function commitMeta(): void {
|
|
22
|
+
const result = controller.commit();
|
|
23
|
+
if (result.validation.ok) {
|
|
24
|
+
onCommit?.(result.meta);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
$effect(() => {
|
|
29
|
+
controller.setMetaFields(fields);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
$effect(() => {
|
|
33
|
+
const unsubscribe = controller.subscribe((state) => {
|
|
34
|
+
controllerState = state;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return unsubscribe;
|
|
38
|
+
});
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<div class="uncial-attrs-panel uncial-meta-panel">
|
|
42
|
+
<p class="uncial-attrs-title">Document metadata</p>
|
|
43
|
+
{#each fieldEntries as [name, spec] (name)}
|
|
44
|
+
<AttributeFieldControl
|
|
45
|
+
{name}
|
|
46
|
+
{spec}
|
|
47
|
+
value={controllerState.draft[name]}
|
|
48
|
+
error={controllerState.errors[name]}
|
|
49
|
+
onChange={(value) => controller.setDraft(name, value)}
|
|
50
|
+
/>
|
|
51
|
+
{:else}
|
|
52
|
+
<p class="uncial-help-text">No metadata fields configured.</p>
|
|
53
|
+
{/each}
|
|
54
|
+
{#if fieldEntries.length > 0}
|
|
55
|
+
<div class="uncial-panel__actions">
|
|
56
|
+
<button
|
|
57
|
+
type="button"
|
|
58
|
+
class="uncial-btn uncial-btn--outline uncial-btn--sm"
|
|
59
|
+
disabled={!controllerState.dirty}
|
|
60
|
+
onclick={() => controller.reset()}
|
|
61
|
+
>
|
|
62
|
+
Reset
|
|
63
|
+
</button>
|
|
64
|
+
<button type="button" class="uncial-btn uncial-btn--primary uncial-btn--sm" onclick={commitMeta}>
|
|
65
|
+
Save Metadata
|
|
66
|
+
</button>
|
|
67
|
+
</div>
|
|
68
|
+
{/if}
|
|
69
|
+
</div>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AttributeSpec } from '../core/types.js';
|
|
2
|
+
import type { DocumentMetaController } from './metaController.js';
|
|
3
|
+
interface Props {
|
|
4
|
+
controller: DocumentMetaController;
|
|
5
|
+
fields?: ReadonlyMap<string, AttributeSpec<unknown>>;
|
|
6
|
+
onCommit?: (meta: Record<string, unknown>) => void;
|
|
7
|
+
}
|
|
8
|
+
declare const DocumentMetaPanel: import("svelte").Component<Props, {}, "">;
|
|
9
|
+
type DocumentMetaPanel = ReturnType<typeof DocumentMetaPanel>;
|
|
10
|
+
export default DocumentMetaPanel;
|