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
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ Custom blocks can stay atomic or declare one default child content region for ne
|
|
|
8
8
|
|
|
9
9
|

|
|
10
10
|

|
|
11
|
+
|
|
11
12
|
## What ships today
|
|
12
13
|
|
|
13
14
|
- Shared block definitions for editor and renderer
|
|
@@ -56,6 +57,7 @@ Then register and use that component as an Uncial block:
|
|
|
56
57
|
|
|
57
58
|
```svelte
|
|
58
59
|
<script lang="ts">
|
|
60
|
+
import 'uncial/styles';
|
|
59
61
|
import {
|
|
60
62
|
Editor,
|
|
61
63
|
Renderer,
|
|
@@ -111,8 +113,7 @@ Object.assign(editor, { blocks, schema, json: document, attributesController });
|
|
|
111
113
|
```
|
|
112
114
|
|
|
113
115
|
```html
|
|
114
|
-
<uncial-editor></uncial-editor>
|
|
115
|
-
<uncial-renderer></uncial-renderer>
|
|
116
|
+
<uncial-editor></uncial-editor> <uncial-renderer></uncial-renderer>
|
|
116
117
|
```
|
|
117
118
|
|
|
118
119
|
Validation callbacks are emitted as bubbling, composed DOM events. Editor document updates are emitted as `uncial-change` because non-Svelte hosts cannot use `bind:json`:
|
|
@@ -148,7 +149,102 @@ export function defineReactBlock(config) {
|
|
|
148
149
|
|
|
149
150
|
## Styling and customization
|
|
150
151
|
|
|
151
|
-
The root `Editor` and `Renderer` exports ship
|
|
152
|
+
The root `Editor` and `Renderer` exports ship stable `uncial-*` classes and optional default CSS. Import the CSS layer you want once in your app:
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
// Full default editor, renderer, controls, and rich text prose styles.
|
|
156
|
+
import 'uncial/styles';
|
|
157
|
+
|
|
158
|
+
// Editor chrome only. Use this if your app owns rich text typography.
|
|
159
|
+
import 'uncial/styles/chrome';
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Uncial does not require Tailwind or DaisyUI. The default styles are plain CSS and are driven by `--uncial-*` custom properties that you can scope to your app, page, or a wrapper around the editor:
|
|
163
|
+
|
|
164
|
+
```css
|
|
165
|
+
.my-editor-theme {
|
|
166
|
+
--brand-primary: #8b5cf6;
|
|
167
|
+
--brand-surface: #101012;
|
|
168
|
+
--brand-border: #303039;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.my-editor-theme .uncial-editor-shell,
|
|
172
|
+
.my-editor-theme .uncial-renderer,
|
|
173
|
+
.my-editor-theme .uncial-attrs-panel,
|
|
174
|
+
.my-editor-theme .uncial-link-panel,
|
|
175
|
+
.my-editor-theme .uncial-richtext-wrapper,
|
|
176
|
+
.my-editor-theme .uncial-block-menu {
|
|
177
|
+
--uncial-color-surface: var(--brand-surface);
|
|
178
|
+
--uncial-color-surface-elevated: #19191d;
|
|
179
|
+
--uncial-color-border: var(--brand-border);
|
|
180
|
+
--uncial-color-text: #f4f4f5;
|
|
181
|
+
--uncial-color-primary: var(--brand-primary);
|
|
182
|
+
--uncial-color-primary-contrast: #ffffff;
|
|
183
|
+
--uncial-color-accent: #f59e0b;
|
|
184
|
+
--uncial-color-focus-ring: var(--brand-primary);
|
|
185
|
+
--uncial-color-code-bg: #171717;
|
|
186
|
+
--uncial-color-code-text: #fafafa;
|
|
187
|
+
|
|
188
|
+
--uncial-radius-sm: 0.375rem;
|
|
189
|
+
--uncial-radius-md: 0.625rem;
|
|
190
|
+
--uncial-radius-lg: 1rem;
|
|
191
|
+
|
|
192
|
+
--uncial-font-body: Inter, system-ui, sans-serif;
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Wrap the editor with that class:
|
|
197
|
+
|
|
198
|
+
```svelte
|
|
199
|
+
<div class="my-editor-theme">
|
|
200
|
+
<Editor {blocks} {schema} bind:json={document} />
|
|
201
|
+
<Renderer content={document} {blocks} {schema} />
|
|
202
|
+
</div>
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Core token groups:
|
|
206
|
+
|
|
207
|
+
| Token | Purpose |
|
|
208
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------ |
|
|
209
|
+
| `--uncial-color-bg`, `--uncial-color-surface`, `--uncial-color-surface-elevated` | Page/editor surfaces |
|
|
210
|
+
| `--uncial-color-border`, `--uncial-color-border-strong` | Borders and separators |
|
|
211
|
+
| `--uncial-color-text`, `--uncial-color-text-muted`, `--uncial-color-text-inverted` | Foreground colors |
|
|
212
|
+
| `--uncial-color-primary`, `--uncial-color-primary-contrast`, `--uncial-color-accent`, `--uncial-color-danger`, `--uncial-color-focus-ring` | Actions, links, errors, focus states |
|
|
213
|
+
| `--uncial-color-code-bg`, `--uncial-color-code-text` | Fenced code block colors |
|
|
214
|
+
| `--uncial-font-body`, `--uncial-font-display`, `--uncial-font-mono` | Typography families |
|
|
215
|
+
| `--uncial-font-size-base`, `--uncial-line-height`, `--uncial-font-weight-regular`, `--uncial-font-weight-strong` | Typography scale |
|
|
216
|
+
| `--uncial-radius-sm`, `--uncial-radius-md`, `--uncial-radius-lg` | Control and shell radii |
|
|
217
|
+
| `--uncial-space-1` through `--uncial-space-6` | Spacing scale |
|
|
218
|
+
| `--uncial-gutter-width`, `--uncial-gutter-width-sm`, `--uncial-toolbar-gap`, `--uncial-panel-width` | Editor structure |
|
|
219
|
+
| `--uncial-shadow-sm`, `--uncial-shadow-md`, `--uncial-transition` | Depth and motion |
|
|
220
|
+
|
|
221
|
+
Rich text output uses the stable `.uncial-rich-content` hook. To bring your own prose styles, import only the chrome layer and target that class:
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
import 'uncial/styles/chrome';
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
```css
|
|
228
|
+
.article-editor .uncial-rich-content {
|
|
229
|
+
font: 400 1rem/1.7 var(--site-body-font);
|
|
230
|
+
color: var(--site-ink);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.article-editor .uncial-rich-content h2 {
|
|
234
|
+
font: 700 1.75rem/1.2 var(--site-display-font);
|
|
235
|
+
margin-block: 2rem 0.75rem;
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
If you use Tailwind Typography, apply it to the same hook in your app stylesheet:
|
|
240
|
+
|
|
241
|
+
```css
|
|
242
|
+
.article-editor .uncial-rich-content {
|
|
243
|
+
@apply prose prose-neutral max-w-none;
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Phosphor is the default icon set for Uncial controls. Icon override props are planned for a future theming tier.
|
|
152
248
|
|
|
153
249
|
If you want to own the editor layout yourself, use `bindEditor(...)` on an element you control:
|
|
154
250
|
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { defineRuntimeBlock } from './defineBlock.js';
|
|
2
2
|
export { coerceAttributeValue, inferAttributeInputKind, normalizeAttributeOptions, normalizeBlockAttributes, parseBlockDraftAttributes, serializeBlockAttributes, toAttributeDraftValues } from './attributes.js';
|
|
3
|
+
export { normalizeMeta, parseMetaDraftValues, serializeMeta, toMetaDraftValues, validateMeta } from './meta.js';
|
|
3
4
|
export { createBlockRegistry, createSchema, resolveRegistry } from './registry.js';
|
|
4
5
|
export { CURRENT_DOCUMENT_VERSION, normalizeDocument } from './normalize.js';
|
|
5
6
|
export { validateDocument } from './validate.js';
|
|
6
7
|
export type { BlockEditorMountHandle, BlockEditorMountOptions, BlockRuntimePlugin, NormalizedBlockComponentDefinition } from './runtime.js';
|
|
7
8
|
export { coerceRichTextDocument, emptyRichTextDocument, hasRichTextContent, isRichTextDocument, richTextDocument, resolveRichTextFeatures } from '../shared/richText.js';
|
|
8
|
-
export type { AttributeConfig, AttributeInputKind, AttributeOption, AttrParser, AttrSerializer, AttributeSpec, BlockAttributes, BlockBehavior, BlockComponentProps, BlockConfig, BlockContentDefinition, BlockContentKind, BlockDefinition, BlockIcon, BlockMetadata, BlockRegistry, ContentDocument, ContentSchema, CreateSchemaOptions, RichTextFeature, RichTextFeatureSelection, RuntimeBlockConfig, ValidateDocumentOptions, ValidationCode, ValidationIssue, ValidationResult } from './types.js';
|
|
9
|
+
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';
|
package/dist/core/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { defineRuntimeBlock } from './defineBlock.js';
|
|
2
2
|
export { coerceAttributeValue, inferAttributeInputKind, normalizeAttributeOptions, normalizeBlockAttributes, parseBlockDraftAttributes, serializeBlockAttributes, toAttributeDraftValues } from './attributes.js';
|
|
3
|
+
export { normalizeMeta, parseMetaDraftValues, serializeMeta, toMetaDraftValues, validateMeta } from './meta.js';
|
|
3
4
|
export { createBlockRegistry, createSchema, resolveRegistry } from './registry.js';
|
|
4
5
|
export { CURRENT_DOCUMENT_VERSION, normalizeDocument } from './normalize.js';
|
|
5
6
|
export { validateDocument } from './validate.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PMPath } from '../shared/document.js';
|
|
2
|
+
import type { AttributeSpec, ValidateDocumentOptions, ValidationIssue } from './types.js';
|
|
3
|
+
export declare function normalizeMeta(meta: unknown, metaFields: ReadonlyMap<string, AttributeSpec<unknown>>): Record<string, unknown>;
|
|
4
|
+
export declare function validateMeta(meta: unknown, metaFields: ReadonlyMap<string, AttributeSpec<unknown>>, issues: ValidationIssue[], options?: ValidateDocumentOptions, path?: PMPath): void;
|
|
5
|
+
export declare function toMetaDraftValues(metaFields: ReadonlyMap<string, AttributeSpec<unknown>>, meta?: Record<string, unknown>): Record<string, unknown>;
|
|
6
|
+
export declare function parseMetaDraftValues(metaFields: ReadonlyMap<string, AttributeSpec<unknown>>, draft: Record<string, unknown>): Record<string, unknown>;
|
|
7
|
+
export declare function serializeMeta(metaFields: ReadonlyMap<string, AttributeSpec<unknown>>, meta?: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { coerceAttributeValue, serializeAttributeValue, toAttributeDraftValue } from './attributes.js';
|
|
2
|
+
function isRecord(value) {
|
|
3
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function pushIssue(issues, options, issue) {
|
|
6
|
+
issues.push(issue);
|
|
7
|
+
options?.onIssue?.(issue);
|
|
8
|
+
}
|
|
9
|
+
export function normalizeMeta(meta, metaFields) {
|
|
10
|
+
const source = isRecord(meta) ? meta : {};
|
|
11
|
+
return Object.fromEntries(Array.from(metaFields, ([name, spec]) => [name, coerceAttributeValue(spec, source[name])]));
|
|
12
|
+
}
|
|
13
|
+
export function validateMeta(meta, metaFields, issues, options, path = ['meta']) {
|
|
14
|
+
const source = isRecord(meta) ? meta : {};
|
|
15
|
+
if (meta !== undefined && !isRecord(meta)) {
|
|
16
|
+
pushIssue(issues, options, {
|
|
17
|
+
code: 'INVALID_META',
|
|
18
|
+
path,
|
|
19
|
+
message: 'Document metadata must be an object',
|
|
20
|
+
severity: 'error',
|
|
21
|
+
details: { value: meta }
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
for (const name of Object.keys(source)) {
|
|
26
|
+
if (!metaFields.has(name)) {
|
|
27
|
+
pushIssue(issues, options, {
|
|
28
|
+
code: 'UNKNOWN_META',
|
|
29
|
+
path: [...path, name],
|
|
30
|
+
message: `Unknown metadata field "${name}"`,
|
|
31
|
+
severity: 'warning',
|
|
32
|
+
details: { field: name }
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
for (const [name, spec] of metaFields) {
|
|
37
|
+
const value = source[name];
|
|
38
|
+
const missing = value === undefined || value === null || value === '';
|
|
39
|
+
if (missing && spec.required) {
|
|
40
|
+
pushIssue(issues, options, {
|
|
41
|
+
code: 'INVALID_META',
|
|
42
|
+
path: [...path, name],
|
|
43
|
+
message: `Required metadata field "${name}" is missing`,
|
|
44
|
+
severity: 'error'
|
|
45
|
+
});
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (missing)
|
|
49
|
+
continue;
|
|
50
|
+
if (spec.validate && !spec.validate(value)) {
|
|
51
|
+
pushIssue(issues, options, {
|
|
52
|
+
code: 'INVALID_META',
|
|
53
|
+
path: [...path, name],
|
|
54
|
+
message: `Metadata field "${name}" is invalid`,
|
|
55
|
+
severity: 'error',
|
|
56
|
+
details: { value }
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export function toMetaDraftValues(metaFields, meta = {}) {
|
|
62
|
+
return Object.fromEntries(Array.from(metaFields, ([name, spec]) => [name, toAttributeDraftValue(spec, meta[name])]));
|
|
63
|
+
}
|
|
64
|
+
export function parseMetaDraftValues(metaFields, draft) {
|
|
65
|
+
return Object.fromEntries(Array.from(metaFields, ([name, spec]) => [name, coerceAttributeValue(spec, draft[name])]));
|
|
66
|
+
}
|
|
67
|
+
export function serializeMeta(metaFields, meta = {}) {
|
|
68
|
+
return Object.fromEntries(Array.from(metaFields, ([name, spec]) => [
|
|
69
|
+
name,
|
|
70
|
+
serializeAttributeValue(spec, coerceAttributeValue(spec, meta[name]))
|
|
71
|
+
]));
|
|
72
|
+
}
|
package/dist/core/normalize.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { resolveRegistry } from './registry.js';
|
|
2
2
|
import { normalizeBlockAttributes } from './attributes.js';
|
|
3
|
+
import { normalizeMeta } from './meta.js';
|
|
3
4
|
export const CURRENT_DOCUMENT_VERSION = 1;
|
|
4
5
|
function normalizeMarks(marks, schema) {
|
|
5
6
|
if (!marks)
|
|
@@ -30,9 +31,14 @@ export function normalizeDocument(document, blocks, schema) {
|
|
|
30
31
|
const registry = resolveRegistry(blocks);
|
|
31
32
|
const registryBlocks = new Map(registry.blocks.map((block) => [block.id, block]));
|
|
32
33
|
const content = Array.isArray(document?.content) ? document.content : [];
|
|
33
|
-
|
|
34
|
+
const metaFields = schema?.metaFields ?? new Map();
|
|
35
|
+
const normalized = {
|
|
34
36
|
type: 'doc',
|
|
35
37
|
version: CURRENT_DOCUMENT_VERSION,
|
|
36
38
|
content: content.map((node) => normalizeNode(node, registryBlocks, schema))
|
|
37
39
|
};
|
|
40
|
+
if (metaFields.size > 0) {
|
|
41
|
+
normalized.meta = normalizeMeta(document?.meta, metaFields);
|
|
42
|
+
}
|
|
43
|
+
return normalized;
|
|
38
44
|
}
|
package/dist/core/registry.js
CHANGED
|
@@ -36,9 +36,11 @@ export function createSchema(registry, options = {}) {
|
|
|
36
36
|
? new Set(options.allowedBlocks.filter((id) => registry.has(id)))
|
|
37
37
|
: new Set(registry.blocks.map((block) => block.id));
|
|
38
38
|
const allowedMarks = new Set(options.allowedMarks ?? DEFAULT_MARKS);
|
|
39
|
+
const metaFields = new Map(Object.entries(options.metaFields ?? {}));
|
|
39
40
|
return {
|
|
40
41
|
allowedBlocks,
|
|
41
|
-
allowedMarks
|
|
42
|
+
allowedMarks,
|
|
43
|
+
metaFields
|
|
42
44
|
};
|
|
43
45
|
}
|
|
44
46
|
export function resolveRegistry(blocks) {
|
package/dist/core/types.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface AttributeSpec<T> {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
export type AttributeConfig<T> = AttributeSpec<T> | T;
|
|
29
|
+
export type MetaFieldSpec<T> = AttributeSpec<T>;
|
|
30
|
+
export type DocumentMetaSchema = Record<string, MetaFieldSpec<unknown>>;
|
|
29
31
|
export type BlockAttributes = Record<string, unknown>;
|
|
30
32
|
export type BlockIcon = string | unknown;
|
|
31
33
|
export type HtmlSpecValue = string | number | boolean | null | undefined;
|
|
@@ -105,8 +107,9 @@ export interface BlockRegistry {
|
|
|
105
107
|
export interface ContentSchema {
|
|
106
108
|
allowedBlocks: ReadonlySet<string>;
|
|
107
109
|
allowedMarks: ReadonlySet<string>;
|
|
110
|
+
metaFields: ReadonlyMap<string, AttributeSpec<unknown>>;
|
|
108
111
|
}
|
|
109
|
-
export type ValidationCode = 'UNKNOWN_BLOCK' | 'INVALID_ATTR' | 'INVALID_CONTENT' | 'DISALLOWED_BLOCK' | 'DISALLOWED_MARK' | 'MALFORMED_NODE';
|
|
112
|
+
export type ValidationCode = 'UNKNOWN_BLOCK' | 'INVALID_ATTR' | 'INVALID_META' | 'UNKNOWN_META' | 'INVALID_CONTENT' | 'DISALLOWED_BLOCK' | 'DISALLOWED_MARK' | 'MALFORMED_NODE';
|
|
110
113
|
export interface ValidationIssue {
|
|
111
114
|
code: ValidationCode;
|
|
112
115
|
path: PMPath;
|
|
@@ -121,6 +124,7 @@ export interface ValidationResult {
|
|
|
121
124
|
export interface CreateSchemaOptions {
|
|
122
125
|
allowedBlocks?: string[];
|
|
123
126
|
allowedMarks?: string[];
|
|
127
|
+
metaFields?: DocumentMetaSchema;
|
|
124
128
|
}
|
|
125
129
|
export interface ValidateDocumentOptions {
|
|
126
130
|
onIssue?: (issue: ValidationIssue) => void;
|
package/dist/core/validate.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { resolveRegistry } from './registry.js';
|
|
2
|
+
import { validateMeta } from './meta.js';
|
|
2
3
|
const BUILTIN_NODE_TYPES = new Set([
|
|
3
4
|
'doc',
|
|
4
5
|
'paragraph',
|
|
@@ -170,6 +171,7 @@ export function validateDocument(document, blocks, schema, options) {
|
|
|
170
171
|
});
|
|
171
172
|
return { ok: false, issues };
|
|
172
173
|
}
|
|
174
|
+
validateMeta(document.meta, schema.metaFields, issues, options);
|
|
173
175
|
const registryBlocks = new Map(registry.blocks.map((block) => [block.id, block]));
|
|
174
176
|
document.content?.forEach((node, index) => {
|
|
175
177
|
validateNode(node, ['content', index], registryBlocks, schema, issues, options);
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { inferAttributeInputKind, normalizeAttributeOptions } from '../core/attributes.js';
|
|
3
|
+
import type { AttributeSpec } from '../core/types.js';
|
|
4
|
+
import RichTextAttributeEditor from './RichTextAttributeEditor.svelte';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
name: string;
|
|
8
|
+
spec: AttributeSpec<unknown>;
|
|
9
|
+
value?: unknown;
|
|
10
|
+
error?: string;
|
|
11
|
+
onChange: (value: unknown) => void;
|
|
12
|
+
onCustom?: (name: string, inputKind: string) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let { name, spec, value = undefined, error = '', onChange, onCustom }: Props = $props();
|
|
16
|
+
|
|
17
|
+
const inputKind = $derived(inferAttributeInputKind(spec));
|
|
18
|
+
const options = $derived(normalizeAttributeOptions(spec) ?? []);
|
|
19
|
+
const stringValue = $derived.by(() => {
|
|
20
|
+
if (typeof value === 'string') return value;
|
|
21
|
+
if (value === undefined || value === null) return '';
|
|
22
|
+
return String(value);
|
|
23
|
+
});
|
|
24
|
+
const customLabel = $derived(value ? `Change ${name}: ${value}` : `Choose ${name}`);
|
|
25
|
+
|
|
26
|
+
function isBuiltInInputKind(kind: string): boolean {
|
|
27
|
+
return ['checkbox', 'number', 'richtext', 'select', 'textarea', 'json', 'text', 'hidden'].includes(
|
|
28
|
+
kind
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
{#if inputKind !== 'hidden'}
|
|
34
|
+
<div class="uncial-field">
|
|
35
|
+
<span class="uncial-field__label">{name}</span>
|
|
36
|
+
{#if !isBuiltInInputKind(inputKind)}
|
|
37
|
+
<button
|
|
38
|
+
type="button"
|
|
39
|
+
class="uncial-btn uncial-btn--outline uncial-btn--sm uncial-btn--start"
|
|
40
|
+
onclick={() => onCustom?.(name, inputKind)}
|
|
41
|
+
>
|
|
42
|
+
{customLabel}
|
|
43
|
+
</button>
|
|
44
|
+
{:else if inputKind === 'checkbox'}
|
|
45
|
+
<input
|
|
46
|
+
class="uncial-checkbox uncial-checkbox--sm"
|
|
47
|
+
type="checkbox"
|
|
48
|
+
checked={Boolean(value)}
|
|
49
|
+
onchange={(event) => {
|
|
50
|
+
const target = event.currentTarget as HTMLInputElement;
|
|
51
|
+
onChange(target.checked);
|
|
52
|
+
}}
|
|
53
|
+
/>
|
|
54
|
+
{:else if inputKind === 'number'}
|
|
55
|
+
<input
|
|
56
|
+
class="uncial-input uncial-input--sm"
|
|
57
|
+
type="number"
|
|
58
|
+
placeholder={spec.placeholder ?? name}
|
|
59
|
+
value={value ?? ''}
|
|
60
|
+
oninput={(event) => {
|
|
61
|
+
const target = event.currentTarget as HTMLInputElement;
|
|
62
|
+
onChange(target.value === '' ? '' : target.valueAsNumber);
|
|
63
|
+
}}
|
|
64
|
+
/>
|
|
65
|
+
{:else if inputKind === 'richtext'}
|
|
66
|
+
<RichTextAttributeEditor
|
|
67
|
+
{value}
|
|
68
|
+
features={spec.richText?.features}
|
|
69
|
+
placeholder={spec.richText?.placeholder ?? spec.placeholder ?? name}
|
|
70
|
+
{onChange}
|
|
71
|
+
/>
|
|
72
|
+
{:else if inputKind === 'select'}
|
|
73
|
+
<select
|
|
74
|
+
class="uncial-select uncial-select--sm"
|
|
75
|
+
aria-label={name}
|
|
76
|
+
value={stringValue}
|
|
77
|
+
onchange={(event) => {
|
|
78
|
+
const target = event.currentTarget as HTMLSelectElement;
|
|
79
|
+
onChange(target.value);
|
|
80
|
+
}}
|
|
81
|
+
>
|
|
82
|
+
{#each options as option (String(option.value))}
|
|
83
|
+
<option value={String(option.value)}>{option.label ?? String(option.value)}</option>
|
|
84
|
+
{/each}
|
|
85
|
+
</select>
|
|
86
|
+
{:else if inputKind === 'textarea' || inputKind === 'json'}
|
|
87
|
+
<textarea
|
|
88
|
+
class="uncial-textarea uncial-textarea--tall"
|
|
89
|
+
placeholder={spec.placeholder ?? name}
|
|
90
|
+
spellcheck={inputKind !== 'json'}
|
|
91
|
+
value={stringValue}
|
|
92
|
+
oninput={(event) => {
|
|
93
|
+
const target = event.currentTarget as HTMLTextAreaElement;
|
|
94
|
+
onChange(target.value);
|
|
95
|
+
}}
|
|
96
|
+
></textarea>
|
|
97
|
+
{:else}
|
|
98
|
+
<input
|
|
99
|
+
class="uncial-input uncial-input--sm"
|
|
100
|
+
type="text"
|
|
101
|
+
placeholder={spec.placeholder ?? name}
|
|
102
|
+
value={stringValue}
|
|
103
|
+
oninput={(event) => {
|
|
104
|
+
const target = event.currentTarget as HTMLInputElement;
|
|
105
|
+
onChange(target.value);
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
{/if}
|
|
109
|
+
{#if error}
|
|
110
|
+
<span class="uncial-field__error">{error}</span>
|
|
111
|
+
{/if}
|
|
112
|
+
</div>
|
|
113
|
+
{/if}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AttributeSpec } from '../core/types.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
name: string;
|
|
4
|
+
spec: AttributeSpec<unknown>;
|
|
5
|
+
value?: unknown;
|
|
6
|
+
error?: string;
|
|
7
|
+
onChange: (value: unknown) => void;
|
|
8
|
+
onCustom?: (name: string, inputKind: string) => void;
|
|
9
|
+
}
|
|
10
|
+
declare const AttributeFieldControl: import("svelte").Component<Props, {}, "">;
|
|
11
|
+
type AttributeFieldControl = ReturnType<typeof AttributeFieldControl>;
|
|
12
|
+
export default AttributeFieldControl;
|