@astl/editor-tiptap 0.2.3 → 0.3.1
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/CHANGELOG.md +37 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +19 -12
- package/dist/adapter.js.map +1 -1
- package/dist/blocks.d.ts +5 -3
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +6 -4
- package/dist/blocks.js.map +1 -1
- package/dist/element.js +1 -1
- package/dist/element.js.map +1 -1
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +255 -6
- package/dist/nodes.js.map +1 -1
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js +109 -5
- package/dist/styles.js.map +1 -1
- package/package.json +6 -6
- package/src/adapter.ts +27 -11
- package/src/blocks.ts +7 -4
- package/src/element.ts +1 -1
- package/src/nodes.ts +255 -5
- package/src/styles.ts +109 -5
package/dist/styles.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAOA,wGAAwG;AACxG,eAAO,MAAM,aAAa,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAOA,wGAAwG;AACxG,eAAO,MAAM,aAAa,iBAAiB,CAAC;AAksC5C,2FAA2F;AAC3F,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAKnD"}
|
package/dist/styles.js
CHANGED
|
@@ -147,9 +147,12 @@ const baseSurfaceStyles = css `
|
|
|
147
147
|
letter-spacing: var(--astl-editor-page-number-letter-spacing, normal);
|
|
148
148
|
text-transform: var(--astl-editor-page-number-text-transform, none);
|
|
149
149
|
}
|
|
150
|
+
/* The title and "Remove title" share a row while the title keeps 6rem; narrower (a phone with larger text) the button
|
|
151
|
+
goes under the title, its words wrapping only where it is wider than the row alone. */
|
|
150
152
|
.astl-surface .astl-page-field {
|
|
151
153
|
flex: 1 0 100%;
|
|
152
154
|
display: flex;
|
|
155
|
+
flex-wrap: wrap;
|
|
153
156
|
align-items: center;
|
|
154
157
|
gap: var(--astl-space-2);
|
|
155
158
|
min-inline-size: 0;
|
|
@@ -159,7 +162,7 @@ const baseSurfaceStyles = css `
|
|
|
159
162
|
}
|
|
160
163
|
.astl-surface .astl-page-label {
|
|
161
164
|
box-sizing: border-box;
|
|
162
|
-
flex: 1 1
|
|
165
|
+
flex: 1 1 6rem;
|
|
163
166
|
min-inline-size: 0;
|
|
164
167
|
min-block-size: var(--astl-target-min);
|
|
165
168
|
margin: 0;
|
|
@@ -201,7 +204,8 @@ const baseSurfaceStyles = css `
|
|
|
201
204
|
.astl-page-remove-title,
|
|
202
205
|
.astl-page-check,
|
|
203
206
|
.astl-help-remove,
|
|
204
|
-
.astl-help-free
|
|
207
|
+
.astl-help-free,
|
|
208
|
+
.astl-check-make
|
|
205
209
|
) {
|
|
206
210
|
box-sizing: border-box;
|
|
207
211
|
display: inline-flex;
|
|
@@ -240,7 +244,8 @@ const baseSurfaceStyles = css `
|
|
|
240
244
|
.astl-page-remove-title,
|
|
241
245
|
.astl-page-check,
|
|
242
246
|
.astl-help-remove,
|
|
243
|
-
.astl-help-free
|
|
247
|
+
.astl-help-free,
|
|
248
|
+
.astl-check-make
|
|
244
249
|
):hover {
|
|
245
250
|
background: var(--astl-accent-soft);
|
|
246
251
|
color: var(--astl-ink);
|
|
@@ -265,6 +270,8 @@ const baseSurfaceStyles = css `
|
|
|
265
270
|
/* Beside the title the button keeps its words whole (it broke "Remove" at 320 px): the title gives way instead. */
|
|
266
271
|
.astl-surface .astl-page-remove-title {
|
|
267
272
|
flex: none;
|
|
273
|
+
max-inline-size: 100%;
|
|
274
|
+
white-space: normal;
|
|
268
275
|
}
|
|
269
276
|
|
|
270
277
|
/* A component in text (a gap): a chip with an icon, its answer and a badge counting the other answers, a long word
|
|
@@ -321,6 +328,102 @@ const baseSurfaceStyles = css `
|
|
|
321
328
|
color: var(--astl-danger);
|
|
322
329
|
}
|
|
323
330
|
|
|
331
|
+
/* A Check element (astl-check): the compact button it puts in the player, the accent's outline, then a tag saying how
|
|
332
|
+
many questions it checks; without any, the tag says so, dashed in the warning colour: never by colour alone. While
|
|
333
|
+
it is selected, the questions it checks have a dashed accent outline (astl-check-target), apart from the solid
|
|
334
|
+
focus ring. */
|
|
335
|
+
.astl-surface .astl-check {
|
|
336
|
+
box-sizing: border-box;
|
|
337
|
+
display: flex;
|
|
338
|
+
flex-wrap: wrap;
|
|
339
|
+
align-items: center;
|
|
340
|
+
gap: var(--astl-space-2);
|
|
341
|
+
inline-size: fit-content;
|
|
342
|
+
max-inline-size: 100%;
|
|
343
|
+
margin-block: var(--astl-space-2);
|
|
344
|
+
border-radius: var(--astl-radius-s);
|
|
345
|
+
font-family: var(--astl-font-body);
|
|
346
|
+
cursor: pointer;
|
|
347
|
+
}
|
|
348
|
+
.astl-surface .astl-check-button {
|
|
349
|
+
box-sizing: border-box;
|
|
350
|
+
display: inline-flex;
|
|
351
|
+
align-items: center;
|
|
352
|
+
gap: 0.25rem;
|
|
353
|
+
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
354
|
+
max-inline-size: 100%;
|
|
355
|
+
padding-inline: var(--astl-space-3);
|
|
356
|
+
border: var(--astl-outline-width) solid var(--astl-accent);
|
|
357
|
+
border-radius: var(--astl-radius-s);
|
|
358
|
+
background: var(--astl-surface);
|
|
359
|
+
color: var(--astl-ink);
|
|
360
|
+
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
361
|
+
font-weight: 600;
|
|
362
|
+
line-height: 1.2;
|
|
363
|
+
overflow-wrap: anywhere;
|
|
364
|
+
}
|
|
365
|
+
.astl-surface .astl-check-button .astl-icon {
|
|
366
|
+
flex: none;
|
|
367
|
+
inline-size: var(--astl-editor-control-icon-size, 0.875rem);
|
|
368
|
+
block-size: var(--astl-editor-control-icon-size, 0.875rem);
|
|
369
|
+
fill: none;
|
|
370
|
+
stroke: var(--astl-accent);
|
|
371
|
+
stroke-width: 2.2;
|
|
372
|
+
stroke-linecap: round;
|
|
373
|
+
stroke-linejoin: round;
|
|
374
|
+
}
|
|
375
|
+
.astl-surface .astl-check-tag {
|
|
376
|
+
padding-inline: 0.5em;
|
|
377
|
+
border: 1px solid transparent;
|
|
378
|
+
border-radius: var(--astl-radius-pill);
|
|
379
|
+
background: var(--astl-accent-soft);
|
|
380
|
+
color: var(--astl-ink);
|
|
381
|
+
font-size: var(--astl-size-small);
|
|
382
|
+
font-weight: 600;
|
|
383
|
+
line-height: 1.4;
|
|
384
|
+
}
|
|
385
|
+
.astl-surface .astl-check-tag:empty {
|
|
386
|
+
display: none;
|
|
387
|
+
}
|
|
388
|
+
.astl-surface .astl-check[data-empty] .astl-check-tag {
|
|
389
|
+
border-style: dashed;
|
|
390
|
+
border-color: var(--astl-warning);
|
|
391
|
+
background: var(--astl-warning-soft);
|
|
392
|
+
}
|
|
393
|
+
.astl-surface .astl-check-target {
|
|
394
|
+
outline: var(--astl-editor-focus-width, 2px) dashed var(--astl-accent);
|
|
395
|
+
outline-offset: 2px;
|
|
396
|
+
}
|
|
397
|
+
/* A chip sits in running text: its outline hugs it, never over the words beside it. */
|
|
398
|
+
.astl-surface .astl-chip.astl-check-target {
|
|
399
|
+
outline-offset: 0;
|
|
400
|
+
}
|
|
401
|
+
/* An automatic Check is the player's, not the exercise's: in a dashed box, its button dashed and muted, with "Make it
|
|
402
|
+
a button" after its tag. */
|
|
403
|
+
.astl-surface .astl-check-auto {
|
|
404
|
+
padding-block: var(--astl-space-1);
|
|
405
|
+
padding-inline: var(--astl-space-2);
|
|
406
|
+
border: 1px dashed var(--astl-outline);
|
|
407
|
+
cursor: default;
|
|
408
|
+
}
|
|
409
|
+
.astl-surface .astl-check-auto .astl-check-button {
|
|
410
|
+
border-style: dashed;
|
|
411
|
+
border-color: var(--astl-outline);
|
|
412
|
+
color: var(--astl-ink-muted);
|
|
413
|
+
}
|
|
414
|
+
.astl-surface .astl-check-make:focus-visible {
|
|
415
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
416
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
417
|
+
}
|
|
418
|
+
@media (forced-colors: active) {
|
|
419
|
+
.astl-surface .astl-check-target {
|
|
420
|
+
outline-color: Highlight;
|
|
421
|
+
}
|
|
422
|
+
.astl-surface .astl-check-button .astl-icon {
|
|
423
|
+
stroke: CanvasText;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
324
427
|
/* The page is one flowing text; a block component on it is framed, with a label tab at the frame's top start (its
|
|
325
428
|
type's icon, its label, a summary). The tab sits on the frame's top border, covering it. The frame with the cursor
|
|
326
429
|
is the accent, its tab filled; one with an error or a warning is dashed in that colour and says its issues under
|
|
@@ -767,7 +870,8 @@ const baseSurfaceStyles = css `
|
|
|
767
870
|
.astl-surface .astl-block-add:not(:has(button:not([hidden]))) {
|
|
768
871
|
display: none;
|
|
769
872
|
}
|
|
770
|
-
/* A small text button under the last child, as the page heads' are.
|
|
873
|
+
/* A small text button under the last child, as the page heads' are. Its words wrap only where it is wider than its
|
|
874
|
+
row alone (larger text on a phone), not to run past the frame. */
|
|
771
875
|
.astl-surface .astl-block-add button {
|
|
772
876
|
box-sizing: border-box;
|
|
773
877
|
display: inline-flex;
|
|
@@ -787,7 +891,7 @@ const baseSurfaceStyles = css `
|
|
|
787
891
|
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
788
892
|
font-weight: 600;
|
|
789
893
|
line-height: 1.2;
|
|
790
|
-
|
|
894
|
+
text-align: start;
|
|
791
895
|
cursor: pointer;
|
|
792
896
|
}
|
|
793
897
|
.astl-surface .astl-block-add button:disabled {
|
package/dist/styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../src/styles.ts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+CAA+C;AAC/C,MAAM,YAAY,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmDvB,CAAC;AAEF,MAAM,aAAa,GAAc,GAAG,CAAA,GAAG,iBAAiB,GAAG,UAAU,GAAG,WAAW,GAAG,YAAY,EAAE,CAAC;AAErG,2FAA2F;AAC3F,MAAM,UAAU,kBAAkB,CAAC,IAAU;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAmC,CAAC;IACjE,MAAM,KAAK,GAAG,aAAa,CAAC,UAAU,CAAC;IACvC,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,kBAAkB,KAAK,SAAS;QAAE,OAAO;IACzE,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,IAAI,CAAC,kBAAkB,GAAG,CAAC,GAAG,IAAI,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;AAC9G,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astl/editor-tiptap",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "<astl-editor>: the authoring kit around a TipTap surface, loaded only when no other editor is plugged in through an adapter.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astrolabe",
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@astl/core": "0.
|
|
57
|
-
"@astl/editor": "0.
|
|
58
|
-
"@astl/engine": "0.
|
|
59
|
-
"@astl/player": "0.
|
|
60
|
-
"@astl/tokens": "0.
|
|
56
|
+
"@astl/core": "0.3.1",
|
|
57
|
+
"@astl/editor": "0.3.1",
|
|
58
|
+
"@astl/engine": "0.3.1",
|
|
59
|
+
"@astl/player": "0.3.1",
|
|
60
|
+
"@astl/tokens": "0.3.1",
|
|
61
61
|
"@tiptap/core": "3.32.0",
|
|
62
62
|
"@tiptap/pm": "3.32.0",
|
|
63
63
|
"@tiptap/starter-kit": "3.32.0",
|
package/src/adapter.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* authoring kit never sees a ProseMirror node, and this file is the whole integration.
|
|
4
4
|
*/
|
|
5
5
|
import {
|
|
6
|
+
CHECK_TAG,
|
|
6
7
|
type ComponentManifest,
|
|
7
8
|
type EditorAdapter,
|
|
8
9
|
type EditorFormat,
|
|
@@ -16,7 +17,15 @@ import type { ChainedCommands, Editor } from '@tiptap/core';
|
|
|
16
17
|
import { closeHistory } from '@tiptap/pm/history';
|
|
17
18
|
import { DOMSerializer, Fragment, type Node as PMNode, DOMParser as SchemaParser } from '@tiptap/pm/model';
|
|
18
19
|
import { NodeSelection, type Selection, TextSelection, type Transaction } from '@tiptap/pm/state';
|
|
19
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
CHECK_NODE,
|
|
22
|
+
cursorIn,
|
|
23
|
+
isBlockOf,
|
|
24
|
+
LAYOUT,
|
|
25
|
+
LAYOUT_COLUMN,
|
|
26
|
+
moveBlockIn,
|
|
27
|
+
removeBlockIn,
|
|
28
|
+
} from './blocks.js';
|
|
20
29
|
import {
|
|
21
30
|
addPageIn,
|
|
22
31
|
attributesOf,
|
|
@@ -116,7 +125,8 @@ function patch(tr: Transaction, pos: number, from: PMNode, to: PMNode): void {
|
|
|
116
125
|
* its schema, as given to `astrolabeExtensions`.
|
|
117
126
|
*/
|
|
118
127
|
export function createTiptapAdapter(editor: Editor, manifests: readonly ComponentManifest[]): EditorAdapter {
|
|
119
|
-
|
|
128
|
+
// The elements the kit selects, reads and replaces by id: the components and the Check elements.
|
|
129
|
+
const tags = new Map([...manifests.map((m) => [nodeName(m.tag), m.tag] as const), [CHECK_NODE, CHECK_TAG]]);
|
|
120
130
|
const types = new Map(manifests.map((m) => [nodeName(m.tag), m]));
|
|
121
131
|
const childTags = new Map(
|
|
122
132
|
manifests.flatMap((m) => (m.children ?? []).map((child) => [nodeName(child.tag), child.tag] as const)),
|
|
@@ -124,7 +134,10 @@ export function createTiptapAdapter(editor: Editor, manifests: readonly Componen
|
|
|
124
134
|
const isBlock = isBlockOf((node) => types.get(node.type.name) ?? null);
|
|
125
135
|
const serializer = DOMSerializer.fromSchema(editor.schema);
|
|
126
136
|
const parser = SchemaParser.fromSchema(editor.schema);
|
|
127
|
-
|
|
137
|
+
/** A component: what takes formats and styles as one. */
|
|
138
|
+
const isComponent = (node: PMNode): boolean => types.has(node.type.name);
|
|
139
|
+
/** A component or a Check element: what the kit selects, reads and replaces by id, never inserts into. */
|
|
140
|
+
const isElement = (node: PMNode): boolean => tags.has(node.type.name);
|
|
128
141
|
const toSelection = (node: PMNode): EditorSelection | null => {
|
|
129
142
|
const id = node.attrs.attributes.id;
|
|
130
143
|
return typeof id === 'string' && id !== '' ? { id, tag: tags.get(node.type.name) ?? '' } : null;
|
|
@@ -135,7 +148,7 @@ export function createTiptapAdapter(editor: Editor, manifests: readonly Componen
|
|
|
135
148
|
let found: { node: PMNode; pos: number } | null = null;
|
|
136
149
|
editor.state.doc.descendants((node, pos) => {
|
|
137
150
|
if (found !== null) return false;
|
|
138
|
-
if ((
|
|
151
|
+
if ((isElement(node) || node.type.name === 'astlPage') && node.attrs.attributes.id === id) {
|
|
139
152
|
found = { node, pos };
|
|
140
153
|
}
|
|
141
154
|
return found === null;
|
|
@@ -143,10 +156,13 @@ export function createTiptapAdapter(editor: Editor, manifests: readonly Componen
|
|
|
143
156
|
return found;
|
|
144
157
|
};
|
|
145
158
|
|
|
146
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
* The component the cursor is on: a selected atom (a Check element too), a block around the cursor, or an atom next
|
|
161
|
+
* to it.
|
|
162
|
+
*/
|
|
147
163
|
const selection = (): EditorSelection | null => {
|
|
148
164
|
const current = editor.state.selection;
|
|
149
|
-
if (current instanceof NodeSelection &&
|
|
165
|
+
if (current instanceof NodeSelection && isElement(current.node)) return toSelection(current.node);
|
|
150
166
|
const { $from } = current;
|
|
151
167
|
for (let depth = $from.depth; depth > 0; depth--) {
|
|
152
168
|
if (isComponent($from.node(depth))) return toSelection($from.node(depth));
|
|
@@ -183,7 +199,7 @@ export function createTiptapAdapter(editor: Editor, manifests: readonly Componen
|
|
|
183
199
|
/** Where formats apply: nowhere on a selected component, marks only in a component's children. */
|
|
184
200
|
const allowed = (): readonly EditorFormat[] => {
|
|
185
201
|
const current = editor.state.selection;
|
|
186
|
-
if (current instanceof NodeSelection &&
|
|
202
|
+
if (current instanceof NodeSelection && isElement(current.node)) return [];
|
|
187
203
|
for (let depth = current.$from.depth; depth > 0; depth--) {
|
|
188
204
|
const node = current.$from.node(depth);
|
|
189
205
|
if (isComponent(node)) return types.get(node.type.name)?.content === 'flow' ? FORMATS : MARKS;
|
|
@@ -195,7 +211,7 @@ export function createTiptapAdapter(editor: Editor, manifests: readonly Componen
|
|
|
195
211
|
const { selection: current } = editor.state;
|
|
196
212
|
const active: EditorFormat[] = [];
|
|
197
213
|
const parent = current.$from.parent;
|
|
198
|
-
const component = current instanceof NodeSelection &&
|
|
214
|
+
const component = current instanceof NodeSelection && isElement(current.node);
|
|
199
215
|
for (const mark of ['bold', 'italic', 'underline', 'link'] as const)
|
|
200
216
|
if (editor.isActive(mark)) active.push(mark);
|
|
201
217
|
if (!component && parent.type.name === 'paragraph') active.push('paragraph');
|
|
@@ -267,7 +283,7 @@ export function createTiptapAdapter(editor: Editor, manifests: readonly Componen
|
|
|
267
283
|
const layout = first?.type.name === LAYOUT;
|
|
268
284
|
// Never replace or nest into the component at the cursor: insert after it. A selected component in text takes
|
|
269
285
|
// inline snippets after it; a block goes after its block, below.
|
|
270
|
-
const selected = current instanceof NodeSelection &&
|
|
286
|
+
const selected = current instanceof NodeSelection && isElement(current.node) ? current.node : null;
|
|
271
287
|
let at: number | { from: number; to: number } | null =
|
|
272
288
|
selected !== null && (inline || !selected.isInline) ? current.to : null;
|
|
273
289
|
for (let depth = current.$from.depth; at === null && depth > 0; depth--) {
|
|
@@ -315,13 +331,13 @@ export function createTiptapAdapter(editor: Editor, manifests: readonly Componen
|
|
|
315
331
|
},
|
|
316
332
|
getElement(id) {
|
|
317
333
|
const hit = find(id);
|
|
318
|
-
return hit !== null &&
|
|
334
|
+
return hit !== null && isElement(hit.node)
|
|
319
335
|
? toHtml(serializer.serializeNode(hit.node, { document: inert }))
|
|
320
336
|
: null;
|
|
321
337
|
},
|
|
322
338
|
replaceElement(id, html) {
|
|
323
339
|
const hit = find(id);
|
|
324
|
-
if (hit === null || !
|
|
340
|
+
if (hit === null || !isElement(hit.node)) return;
|
|
325
341
|
const box = inert.createElement('div');
|
|
326
342
|
box.innerHTML = inertStyles(html);
|
|
327
343
|
let next: PMNode | null = null;
|
package/src/blocks.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Blocks (`EditorBlockPlace`): a page's content as the adapter moves and deletes it. Each block component directly on a
|
|
3
|
-
* page or in a column of a layout is one block; the nodes between two of them are one text
|
|
4
|
-
* reading order, through the columns. The content format has no blocks, so nothing here changes the schema: the page is
|
|
3
|
+
* page or in a column of a layout is one block, and so is each Check element; the nodes between two of them are one text
|
|
4
|
+
* block; they are numbered in reading order, through the columns. The content format has no blocks, so nothing here changes the schema: the page is
|
|
5
5
|
* one flowing text, and decorations frame each block component, with a label tab and its issues; the adapter (and the
|
|
6
6
|
* inspector through it) moves and deletes blocks, each as one undo step.
|
|
7
7
|
*/
|
|
@@ -50,6 +50,9 @@ const PAGE = 'astlPage';
|
|
|
50
50
|
export const LAYOUT = 'astlLayout';
|
|
51
51
|
export const LAYOUT_COLUMN = 'astlLayoutColumn';
|
|
52
52
|
|
|
53
|
+
/** The node of `<astl-check>`, a Check for several questions: a block of its own. */
|
|
54
|
+
export const CHECK_NODE = 'astlCheck';
|
|
55
|
+
|
|
53
56
|
/** The frames validate this long after the last change, as the issues list does, so typing is not interrupted. */
|
|
54
57
|
const CHECK_DELAY_MS = 300;
|
|
55
58
|
|
|
@@ -81,11 +84,11 @@ export type IsBlock = (node: PMNode) => boolean;
|
|
|
81
84
|
/** The component type of an editor node, or null for content and children. */
|
|
82
85
|
export type TypeOf = (node: PMNode) => ComponentManifest | null;
|
|
83
86
|
|
|
84
|
-
/** Block components are blocks of their own. */
|
|
87
|
+
/** Block components are blocks of their own, and so are Check elements. */
|
|
85
88
|
export const isBlockOf =
|
|
86
89
|
(typeOf: TypeOf): IsBlock =>
|
|
87
90
|
(node) =>
|
|
88
|
-
typeOf(node)?.display === 'block';
|
|
91
|
+
node.type.name === CHECK_NODE || typeOf(node)?.display === 'block';
|
|
89
92
|
|
|
90
93
|
/**
|
|
91
94
|
* What a block or a page transaction did, as the status line says it: a key of the kit's namespace and its parameters,
|
package/src/element.ts
CHANGED
|
@@ -457,7 +457,7 @@ const KIT_ICONS: readonly string[] = [
|
|
|
457
457
|
|
|
458
458
|
/** The inspector's parts, forwarded so hosts can restyle its header, banners and fields (`::part(inspector-issue)`). */
|
|
459
459
|
const INSPECTOR_PARTS =
|
|
460
|
-
'header: inspector-header, id: inspector-id, actions: inspector-actions, issue: inspector-issue, field: inspector-field, label: inspector-label, style: inspector-style, help: inspector-help, help-toggle: inspector-help-toggle, help-summary: inspector-help-summary, help-body: inspector-help-body, help-add: inspector-help-add, help-move: inspector-help-move, help-remove: inspector-help-remove';
|
|
460
|
+
'header: inspector-header, id: inspector-id, actions: inspector-actions, issue: inspector-issue, field: inspector-field, label: inspector-label, style: inspector-style, help: inspector-help, help-toggle: inspector-help-toggle, help-summary: inspector-help-summary, help-body: inspector-help-body, help-add: inspector-help-add, help-move: inspector-help-move, help-remove: inspector-help-remove, check-targets: inspector-check-targets, checked-by: inspector-checked-by';
|
|
461
461
|
|
|
462
462
|
/** The built-in surface module, once imported. */
|
|
463
463
|
let surfaces: typeof import('./surface.js') | null = null;
|