@astl/editor-tiptap 0.2.2 → 0.3.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/CHANGELOG.md +41 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +46 -23
- 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 +3 -3
- package/dist/element.js.map +1 -1
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +256 -6
- package/dist/nodes.js.map +1 -1
- package/dist/source-view.js +2 -2
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js +147 -30
- package/dist/styles.js.map +1 -1
- package/package.json +6 -6
- package/src/adapter.ts +59 -25
- package/src/blocks.ts +7 -4
- package/src/element.ts +3 -3
- package/src/nodes.ts +256 -5
- package/src/source-view.ts +2 -2
- package/src/styles.ts +147 -30
package/dist/source-view.js
CHANGED
|
@@ -83,8 +83,8 @@ const sourceStyles = css `
|
|
|
83
83
|
font: var(--astl-size-small) / 1.5 var(--astl-font-mono);
|
|
84
84
|
}
|
|
85
85
|
.source textarea:focus-visible {
|
|
86
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
87
|
-
outline-offset: var(--astl-focus-offset);
|
|
86
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
87
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
88
88
|
}
|
|
89
89
|
`;
|
|
90
90
|
/** Adopts the view's stylesheets into the shadow root holding `node`, once. */
|
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;AA4rC5C,2FAA2F;AAC3F,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAKnD"}
|
package/dist/styles.js
CHANGED
|
@@ -31,8 +31,8 @@ const baseSurfaceStyles = css `
|
|
|
31
31
|
}
|
|
32
32
|
/* A host with a focus cue of its own (the frame with the cursor) may set the sheet's ring to a quieter one. */
|
|
33
33
|
.astl-surface .tiptap:focus-visible {
|
|
34
|
-
outline: var(--astl-editor-sheet-focus-ring, var(--astl-focus-width) solid var(--astl-focus));
|
|
35
|
-
outline-offset: var(--astl-focus-offset);
|
|
34
|
+
outline: var(--astl-editor-sheet-focus-ring, var(--astl-editor-focus-width, 2px) solid var(--astl-focus));
|
|
35
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
36
36
|
}
|
|
37
37
|
.astl-surface .astl-vh {
|
|
38
38
|
position: absolute;
|
|
@@ -129,10 +129,13 @@ const baseSurfaceStyles = css `
|
|
|
129
129
|
padding-block-start: var(--astl-space-4);
|
|
130
130
|
border-block-start: var(--astl-outline-width) solid var(--astl-line);
|
|
131
131
|
}
|
|
132
|
+
/* A page head: its number, then its buttons at the end; in a narrow column a button that wraps stays at the end, under
|
|
133
|
+
the others, not under the number. */
|
|
132
134
|
.astl-surface .astl-page-head {
|
|
133
135
|
display: flex;
|
|
134
136
|
flex-wrap: wrap;
|
|
135
137
|
align-items: center;
|
|
138
|
+
justify-content: flex-end;
|
|
136
139
|
gap: var(--astl-space-2);
|
|
137
140
|
margin-block: 0 var(--astl-space-3);
|
|
138
141
|
}
|
|
@@ -181,13 +184,15 @@ const baseSurfaceStyles = css `
|
|
|
181
184
|
.astl-help-remove,
|
|
182
185
|
.astl-help-free
|
|
183
186
|
):focus-visible {
|
|
184
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
185
|
-
outline-offset: var(--astl-focus-offset);
|
|
187
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
188
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
186
189
|
}
|
|
187
190
|
/* The surface's authoring controls (the page heads' buttons, a page box's, the blocks' "Add option", a frame's
|
|
188
|
-
position line, a picture's buttons) are compact,
|
|
189
|
-
|
|
190
|
-
and
|
|
191
|
+
position line, a picture's buttons) are compact, so that the exercise looks as students see it, and each is
|
|
192
|
+
recognisable as a button at rest: a text button has a hairline in the outline colour (3:1 at least), an add action
|
|
193
|
+
a plus and the accent colour, an icon alone (a page box's cross) only its icon. A host sizes them with
|
|
194
|
+
--astl-editor-control-size (their height, 1.75rem), --astl-editor-control-font-size (0.8125rem) and
|
|
195
|
+
--astl-editor-control-icon-size (0.875rem); a target stays at least 24px (WCAG 2.5.8). */
|
|
191
196
|
.astl-surface
|
|
192
197
|
:is(
|
|
193
198
|
.astl-page-join,
|
|
@@ -196,7 +201,8 @@ const baseSurfaceStyles = css `
|
|
|
196
201
|
.astl-page-remove-title,
|
|
197
202
|
.astl-page-check,
|
|
198
203
|
.astl-help-remove,
|
|
199
|
-
.astl-help-free
|
|
204
|
+
.astl-help-free,
|
|
205
|
+
.astl-check-make
|
|
200
206
|
) {
|
|
201
207
|
box-sizing: border-box;
|
|
202
208
|
display: inline-flex;
|
|
@@ -207,7 +213,7 @@ const baseSurfaceStyles = css `
|
|
|
207
213
|
min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
208
214
|
padding-block: 0;
|
|
209
215
|
padding-inline: var(--astl-space-2);
|
|
210
|
-
border: var(--astl-outline
|
|
216
|
+
border: 1px solid var(--astl-outline);
|
|
211
217
|
border-radius: var(--astl-radius-s);
|
|
212
218
|
background: transparent;
|
|
213
219
|
color: var(--astl-ink-muted);
|
|
@@ -219,6 +225,14 @@ const baseSurfaceStyles = css `
|
|
|
219
225
|
white-space: nowrap;
|
|
220
226
|
cursor: pointer;
|
|
221
227
|
}
|
|
228
|
+
.astl-surface .astl-help-remove {
|
|
229
|
+
border-color: transparent;
|
|
230
|
+
}
|
|
231
|
+
.astl-surface .astl-page-add-title {
|
|
232
|
+
padding-inline-start: var(--astl-space-1);
|
|
233
|
+
border-color: transparent;
|
|
234
|
+
color: var(--astl-accent);
|
|
235
|
+
}
|
|
222
236
|
.astl-surface
|
|
223
237
|
:is(
|
|
224
238
|
.astl-page-join,
|
|
@@ -227,12 +241,13 @@ const baseSurfaceStyles = css `
|
|
|
227
241
|
.astl-page-remove-title,
|
|
228
242
|
.astl-page-check,
|
|
229
243
|
.astl-help-remove,
|
|
230
|
-
.astl-help-free
|
|
244
|
+
.astl-help-free,
|
|
245
|
+
.astl-check-make
|
|
231
246
|
):hover {
|
|
232
247
|
background: var(--astl-accent-soft);
|
|
233
248
|
color: var(--astl-ink);
|
|
234
249
|
}
|
|
235
|
-
.astl-surface :is(.astl-help-remove, .astl-block-add button) .astl-icon {
|
|
250
|
+
.astl-surface :is(.astl-help-remove, .astl-block-add button, .astl-page-add-title) .astl-icon {
|
|
236
251
|
inline-size: var(--astl-editor-control-icon-size, 0.875rem);
|
|
237
252
|
block-size: var(--astl-editor-control-icon-size, 0.875rem);
|
|
238
253
|
}
|
|
@@ -308,6 +323,102 @@ const baseSurfaceStyles = css `
|
|
|
308
323
|
color: var(--astl-danger);
|
|
309
324
|
}
|
|
310
325
|
|
|
326
|
+
/* A Check element (astl-check): the compact button it puts in the player, the accent's outline, then a tag saying how
|
|
327
|
+
many questions it checks; without any, the tag says so, dashed in the warning colour: never by colour alone. While
|
|
328
|
+
it is selected, the questions it checks have a dashed accent outline (astl-check-target), apart from the solid
|
|
329
|
+
focus ring. */
|
|
330
|
+
.astl-surface .astl-check {
|
|
331
|
+
box-sizing: border-box;
|
|
332
|
+
display: flex;
|
|
333
|
+
flex-wrap: wrap;
|
|
334
|
+
align-items: center;
|
|
335
|
+
gap: var(--astl-space-2);
|
|
336
|
+
inline-size: fit-content;
|
|
337
|
+
max-inline-size: 100%;
|
|
338
|
+
margin-block: var(--astl-space-2);
|
|
339
|
+
border-radius: var(--astl-radius-s);
|
|
340
|
+
font-family: var(--astl-font-body);
|
|
341
|
+
cursor: pointer;
|
|
342
|
+
}
|
|
343
|
+
.astl-surface .astl-check-button {
|
|
344
|
+
box-sizing: border-box;
|
|
345
|
+
display: inline-flex;
|
|
346
|
+
align-items: center;
|
|
347
|
+
gap: 0.25rem;
|
|
348
|
+
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
349
|
+
max-inline-size: 100%;
|
|
350
|
+
padding-inline: var(--astl-space-3);
|
|
351
|
+
border: var(--astl-outline-width) solid var(--astl-accent);
|
|
352
|
+
border-radius: var(--astl-radius-s);
|
|
353
|
+
background: var(--astl-surface);
|
|
354
|
+
color: var(--astl-ink);
|
|
355
|
+
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
356
|
+
font-weight: 600;
|
|
357
|
+
line-height: 1.2;
|
|
358
|
+
overflow-wrap: anywhere;
|
|
359
|
+
}
|
|
360
|
+
.astl-surface .astl-check-button .astl-icon {
|
|
361
|
+
flex: none;
|
|
362
|
+
inline-size: var(--astl-editor-control-icon-size, 0.875rem);
|
|
363
|
+
block-size: var(--astl-editor-control-icon-size, 0.875rem);
|
|
364
|
+
fill: none;
|
|
365
|
+
stroke: var(--astl-accent);
|
|
366
|
+
stroke-width: 2.2;
|
|
367
|
+
stroke-linecap: round;
|
|
368
|
+
stroke-linejoin: round;
|
|
369
|
+
}
|
|
370
|
+
.astl-surface .astl-check-tag {
|
|
371
|
+
padding-inline: 0.5em;
|
|
372
|
+
border: 1px solid transparent;
|
|
373
|
+
border-radius: var(--astl-radius-pill);
|
|
374
|
+
background: var(--astl-accent-soft);
|
|
375
|
+
color: var(--astl-ink);
|
|
376
|
+
font-size: var(--astl-size-small);
|
|
377
|
+
font-weight: 600;
|
|
378
|
+
line-height: 1.4;
|
|
379
|
+
}
|
|
380
|
+
.astl-surface .astl-check-tag:empty {
|
|
381
|
+
display: none;
|
|
382
|
+
}
|
|
383
|
+
.astl-surface .astl-check[data-empty] .astl-check-tag {
|
|
384
|
+
border-style: dashed;
|
|
385
|
+
border-color: var(--astl-warning);
|
|
386
|
+
background: var(--astl-warning-soft);
|
|
387
|
+
}
|
|
388
|
+
.astl-surface .astl-check-target {
|
|
389
|
+
outline: var(--astl-editor-focus-width, 2px) dashed var(--astl-accent);
|
|
390
|
+
outline-offset: 2px;
|
|
391
|
+
}
|
|
392
|
+
/* A chip sits in running text: its outline hugs it, never over the words beside it. */
|
|
393
|
+
.astl-surface .astl-chip.astl-check-target {
|
|
394
|
+
outline-offset: 0;
|
|
395
|
+
}
|
|
396
|
+
/* An automatic Check is the player's, not the exercise's: in a dashed box, its button dashed and muted, with "Make it
|
|
397
|
+
a button" after its tag. */
|
|
398
|
+
.astl-surface .astl-check-auto {
|
|
399
|
+
padding-block: var(--astl-space-1);
|
|
400
|
+
padding-inline: var(--astl-space-2);
|
|
401
|
+
border: 1px dashed var(--astl-outline);
|
|
402
|
+
cursor: default;
|
|
403
|
+
}
|
|
404
|
+
.astl-surface .astl-check-auto .astl-check-button {
|
|
405
|
+
border-style: dashed;
|
|
406
|
+
border-color: var(--astl-outline);
|
|
407
|
+
color: var(--astl-ink-muted);
|
|
408
|
+
}
|
|
409
|
+
.astl-surface .astl-check-make:focus-visible {
|
|
410
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
411
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
412
|
+
}
|
|
413
|
+
@media (forced-colors: active) {
|
|
414
|
+
.astl-surface .astl-check-target {
|
|
415
|
+
outline-color: Highlight;
|
|
416
|
+
}
|
|
417
|
+
.astl-surface .astl-check-button .astl-icon {
|
|
418
|
+
stroke: CanvasText;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
311
422
|
/* The page is one flowing text; a block component on it is framed, with a label tab at the frame's top start (its
|
|
312
423
|
type's icon, its label, a summary). The tab sits on the frame's top border, covering it. The frame with the cursor
|
|
313
424
|
is the accent, its tab filled; one with an error or a warning is dashed in that colour and says its issues under
|
|
@@ -466,8 +577,8 @@ const baseSurfaceStyles = css `
|
|
|
466
577
|
}
|
|
467
578
|
.astl-surface .astl-block-add :focus-visible,
|
|
468
579
|
.astl-surface .astl-flag:focus-visible {
|
|
469
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
470
|
-
outline-offset: var(--astl-focus-offset);
|
|
580
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
581
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
471
582
|
}
|
|
472
583
|
.astl-surface .astl-icon {
|
|
473
584
|
flex: none;
|
|
@@ -529,7 +640,7 @@ const baseSurfaceStyles = css `
|
|
|
529
640
|
margin-inline-start: auto;
|
|
530
641
|
padding-block: 0;
|
|
531
642
|
padding-inline: var(--astl-space-2);
|
|
532
|
-
border:
|
|
643
|
+
border: 1px solid transparent;
|
|
533
644
|
border-radius: var(--astl-radius-s);
|
|
534
645
|
background: transparent;
|
|
535
646
|
color: var(--astl-ink-muted);
|
|
@@ -544,16 +655,19 @@ const baseSurfaceStyles = css `
|
|
|
544
655
|
.astl-surface .astl-frame-head-current > .astl-frame-line {
|
|
545
656
|
visibility: visible;
|
|
546
657
|
}
|
|
658
|
+
/* As a button it opens the component's style form: outlined, with the selects' chevron. */
|
|
547
659
|
.astl-surface button.astl-frame-line {
|
|
660
|
+
border-color: var(--astl-outline);
|
|
548
661
|
cursor: pointer;
|
|
549
662
|
}
|
|
663
|
+
${unsafeCSS(nativeSelectCss('.astl-surface button.astl-frame-line'))}
|
|
550
664
|
.astl-surface button.astl-frame-line:hover {
|
|
551
|
-
background: var(--astl-accent-soft);
|
|
665
|
+
background-color: var(--astl-accent-soft);
|
|
552
666
|
color: var(--astl-ink);
|
|
553
667
|
}
|
|
554
668
|
.astl-surface .astl-frame-line:focus-visible {
|
|
555
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
556
|
-
outline-offset: var(--astl-focus-offset);
|
|
669
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
670
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
557
671
|
}
|
|
558
672
|
.astl-surface .astl-block.astl-atom {
|
|
559
673
|
cursor: pointer;
|
|
@@ -592,7 +706,7 @@ const baseSurfaceStyles = css `
|
|
|
592
706
|
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
593
707
|
padding-block: 0;
|
|
594
708
|
padding-inline: var(--astl-space-2);
|
|
595
|
-
border:
|
|
709
|
+
border: 1px solid var(--astl-outline);
|
|
596
710
|
border-radius: var(--astl-radius-s);
|
|
597
711
|
background: var(--astl-surface);
|
|
598
712
|
color: var(--astl-ink);
|
|
@@ -602,8 +716,8 @@ const baseSurfaceStyles = css `
|
|
|
602
716
|
cursor: pointer;
|
|
603
717
|
}
|
|
604
718
|
.astl-surface .astl-help-head select:focus-visible {
|
|
605
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
606
|
-
outline-offset: var(--astl-focus-offset);
|
|
719
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
720
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
607
721
|
}
|
|
608
722
|
${unsafeCSS(nativeSelectCss('.astl-surface .astl-help-head select'))}
|
|
609
723
|
/* "Remove" closes the head: a cross, a page button's look. */
|
|
@@ -641,7 +755,7 @@ const baseSurfaceStyles = css `
|
|
|
641
755
|
pointer-events: none;
|
|
642
756
|
}
|
|
643
757
|
/* A frame's tags: the help for students its component has, small pills in its tab. Each is a 24px target that keeps
|
|
644
|
-
the tab as high as its line. */
|
|
758
|
+
the tab as high as its line; its focus ring hugs the pill, so it stays off the tab's line above when the tab wraps. */
|
|
645
759
|
.astl-surface .astl-frame-help {
|
|
646
760
|
box-sizing: border-box;
|
|
647
761
|
display: inline-flex;
|
|
@@ -671,8 +785,11 @@ const baseSurfaceStyles = css `
|
|
|
671
785
|
color: var(--astl-ink);
|
|
672
786
|
}
|
|
673
787
|
.astl-surface .astl-frame-help:focus-visible {
|
|
674
|
-
outline:
|
|
675
|
-
|
|
788
|
+
outline: none;
|
|
789
|
+
}
|
|
790
|
+
.astl-surface .astl-frame-help:focus-visible > span {
|
|
791
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
792
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
676
793
|
}
|
|
677
794
|
.astl-surface .astl-child {
|
|
678
795
|
padding-block: var(--astl-space-1);
|
|
@@ -759,10 +876,10 @@ const baseSurfaceStyles = css `
|
|
|
759
876
|
margin: 0;
|
|
760
877
|
padding-block: 0;
|
|
761
878
|
padding-inline: var(--astl-space-1) var(--astl-space-2);
|
|
762
|
-
border:
|
|
879
|
+
border: 1px solid transparent;
|
|
763
880
|
border-radius: var(--astl-radius-s);
|
|
764
881
|
background: transparent;
|
|
765
|
-
color: var(--astl-
|
|
882
|
+
color: var(--astl-accent);
|
|
766
883
|
font: inherit;
|
|
767
884
|
font-family: var(--astl-font-body);
|
|
768
885
|
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
@@ -794,11 +911,11 @@ const baseSurfaceStyles = css `
|
|
|
794
911
|
words beside it: its ring is inside it, and it is filled (its border is the accent already). An empty chip keeps
|
|
795
912
|
its colours: the solid ring stands out on its dashed one. */
|
|
796
913
|
.astl-surface .ProseMirror-selectednode {
|
|
797
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
798
|
-
outline-offset: var(--astl-focus-offset);
|
|
914
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
915
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
799
916
|
}
|
|
800
917
|
.astl-surface .astl-chip.ProseMirror-selectednode {
|
|
801
|
-
outline-offset: calc(-1 * var(--astl-focus-width));
|
|
918
|
+
outline-offset: calc(-1 * var(--astl-editor-focus-width, 2px));
|
|
802
919
|
}
|
|
803
920
|
.astl-surface .astl-chip.ProseMirror-selectednode:not([data-empty]) {
|
|
804
921
|
background: var(--astl-accent);
|
|
@@ -923,7 +1040,7 @@ const baseSurfaceStyles = css `
|
|
|
923
1040
|
min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
924
1041
|
padding-block: 0;
|
|
925
1042
|
padding-inline: var(--astl-space-2);
|
|
926
|
-
border:
|
|
1043
|
+
border: 1px solid var(--astl-outline);
|
|
927
1044
|
border-radius: var(--astl-radius-s);
|
|
928
1045
|
background: var(--astl-surface);
|
|
929
1046
|
color: var(--astl-ink);
|
|
@@ -937,7 +1054,7 @@ const baseSurfaceStyles = css `
|
|
|
937
1054
|
min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
938
1055
|
padding-block: 0;
|
|
939
1056
|
padding-inline: var(--astl-space-2);
|
|
940
|
-
border:
|
|
1057
|
+
border: 1px solid var(--astl-outline);
|
|
941
1058
|
border-radius: var(--astl-radius-s);
|
|
942
1059
|
background: var(--astl-surface);
|
|
943
1060
|
color: var(--astl-ink);
|
package/dist/styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAkB,GAAG,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAErD,wGAAwG;AACxG,MAAM,CAAC,MAAM,aAAa,GAAG,cAAc,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,iBAAiB,GAAc,GAAG,CAAA
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAkB,GAA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AAC,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.0",
|
|
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.0",
|
|
57
|
+
"@astl/editor": "0.3.0",
|
|
58
|
+
"@astl/engine": "0.3.0",
|
|
59
|
+
"@astl/player": "0.3.0",
|
|
60
|
+
"@astl/tokens": "0.3.0",
|
|
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,
|
|
@@ -14,9 +15,17 @@ import {
|
|
|
14
15
|
import { scanElements } from '@astl/editor';
|
|
15
16
|
import type { ChainedCommands, Editor } from '@tiptap/core';
|
|
16
17
|
import { closeHistory } from '@tiptap/pm/history';
|
|
17
|
-
import { DOMSerializer, type Node as PMNode, DOMParser as SchemaParser } from '@tiptap/pm/model';
|
|
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,
|
|
@@ -70,26 +79,44 @@ function formatCommand(
|
|
|
70
79
|
}
|
|
71
80
|
}
|
|
72
81
|
|
|
73
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* Changes `from` (at `pos`) into `to` with the least replaced, so that a selection inside it maps through: attributes in
|
|
84
|
+
* place; the children both have at the start and at the end (by type, text by text) patched in place, each the same
|
|
85
|
+
* way; only the run between them replaced, so a child added or taken away (a hint, a row) is just that step. Replacing
|
|
86
|
+
* the whole content instead threw a cursor in the block's prompt out of the block, and the inspector lost its element.
|
|
87
|
+
*/
|
|
74
88
|
function patch(tr: Transaction, pos: number, from: PMNode, to: PMNode): void {
|
|
75
89
|
if (!from.sameMarkup(to)) tr.setNodeMarkup(pos, undefined, to.attrs, from.marks);
|
|
76
90
|
if (from.isLeaf || from.content.eq(to.content)) return;
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
const same = (a: PMNode, b: PMNode) => a.type === b.type && (!a.isText || a.eq(b));
|
|
92
|
+
const shortest = Math.min(from.childCount, to.childCount);
|
|
93
|
+
let start = 0;
|
|
94
|
+
while (start < shortest && same(from.child(start), to.child(start))) start++;
|
|
95
|
+
let end = 0;
|
|
96
|
+
while (
|
|
97
|
+
end < shortest - start &&
|
|
98
|
+
same(from.child(from.childCount - 1 - end), to.child(to.childCount - 1 - end))
|
|
99
|
+
)
|
|
100
|
+
end++;
|
|
87
101
|
const offsets: number[] = [];
|
|
88
102
|
from.forEach((_, offset) => {
|
|
89
103
|
offsets.push(offset);
|
|
90
104
|
});
|
|
91
|
-
|
|
92
|
-
|
|
105
|
+
const at = (i: number) => pos + 1 + (i < from.childCount ? (offsets[i] ?? 0) : from.content.size);
|
|
106
|
+
// Last first, so earlier positions stay valid: the children at the end, the run between, the children at the start.
|
|
107
|
+
for (let k = 0; k < end; k++) {
|
|
108
|
+
patch(
|
|
109
|
+
tr,
|
|
110
|
+
at(from.childCount - 1 - k),
|
|
111
|
+
from.child(from.childCount - 1 - k),
|
|
112
|
+
to.child(to.childCount - 1 - k),
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
const [fromEnd, toEnd] = [from.childCount - end, to.childCount - end];
|
|
116
|
+
if (start < fromEnd || start < toEnd) {
|
|
117
|
+
tr.replaceWith(at(start), at(fromEnd), Fragment.fromArray(to.content.content.slice(start, toEnd)));
|
|
118
|
+
}
|
|
119
|
+
for (let i = start - 1; i >= 0; i--) patch(tr, at(i), from.child(i), to.child(i));
|
|
93
120
|
}
|
|
94
121
|
|
|
95
122
|
/**
|
|
@@ -98,7 +125,8 @@ function patch(tr: Transaction, pos: number, from: PMNode, to: PMNode): void {
|
|
|
98
125
|
* its schema, as given to `astrolabeExtensions`.
|
|
99
126
|
*/
|
|
100
127
|
export function createTiptapAdapter(editor: Editor, manifests: readonly ComponentManifest[]): EditorAdapter {
|
|
101
|
-
|
|
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]]);
|
|
102
130
|
const types = new Map(manifests.map((m) => [nodeName(m.tag), m]));
|
|
103
131
|
const childTags = new Map(
|
|
104
132
|
manifests.flatMap((m) => (m.children ?? []).map((child) => [nodeName(child.tag), child.tag] as const)),
|
|
@@ -106,7 +134,10 @@ export function createTiptapAdapter(editor: Editor, manifests: readonly Componen
|
|
|
106
134
|
const isBlock = isBlockOf((node) => types.get(node.type.name) ?? null);
|
|
107
135
|
const serializer = DOMSerializer.fromSchema(editor.schema);
|
|
108
136
|
const parser = SchemaParser.fromSchema(editor.schema);
|
|
109
|
-
|
|
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);
|
|
110
141
|
const toSelection = (node: PMNode): EditorSelection | null => {
|
|
111
142
|
const id = node.attrs.attributes.id;
|
|
112
143
|
return typeof id === 'string' && id !== '' ? { id, tag: tags.get(node.type.name) ?? '' } : null;
|
|
@@ -117,7 +148,7 @@ export function createTiptapAdapter(editor: Editor, manifests: readonly Componen
|
|
|
117
148
|
let found: { node: PMNode; pos: number } | null = null;
|
|
118
149
|
editor.state.doc.descendants((node, pos) => {
|
|
119
150
|
if (found !== null) return false;
|
|
120
|
-
if ((
|
|
151
|
+
if ((isElement(node) || node.type.name === 'astlPage') && node.attrs.attributes.id === id) {
|
|
121
152
|
found = { node, pos };
|
|
122
153
|
}
|
|
123
154
|
return found === null;
|
|
@@ -125,10 +156,13 @@ export function createTiptapAdapter(editor: Editor, manifests: readonly Componen
|
|
|
125
156
|
return found;
|
|
126
157
|
};
|
|
127
158
|
|
|
128
|
-
/**
|
|
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
|
+
*/
|
|
129
163
|
const selection = (): EditorSelection | null => {
|
|
130
164
|
const current = editor.state.selection;
|
|
131
|
-
if (current instanceof NodeSelection &&
|
|
165
|
+
if (current instanceof NodeSelection && isElement(current.node)) return toSelection(current.node);
|
|
132
166
|
const { $from } = current;
|
|
133
167
|
for (let depth = $from.depth; depth > 0; depth--) {
|
|
134
168
|
if (isComponent($from.node(depth))) return toSelection($from.node(depth));
|
|
@@ -165,7 +199,7 @@ export function createTiptapAdapter(editor: Editor, manifests: readonly Componen
|
|
|
165
199
|
/** Where formats apply: nowhere on a selected component, marks only in a component's children. */
|
|
166
200
|
const allowed = (): readonly EditorFormat[] => {
|
|
167
201
|
const current = editor.state.selection;
|
|
168
|
-
if (current instanceof NodeSelection &&
|
|
202
|
+
if (current instanceof NodeSelection && isElement(current.node)) return [];
|
|
169
203
|
for (let depth = current.$from.depth; depth > 0; depth--) {
|
|
170
204
|
const node = current.$from.node(depth);
|
|
171
205
|
if (isComponent(node)) return types.get(node.type.name)?.content === 'flow' ? FORMATS : MARKS;
|
|
@@ -177,7 +211,7 @@ export function createTiptapAdapter(editor: Editor, manifests: readonly Componen
|
|
|
177
211
|
const { selection: current } = editor.state;
|
|
178
212
|
const active: EditorFormat[] = [];
|
|
179
213
|
const parent = current.$from.parent;
|
|
180
|
-
const component = current instanceof NodeSelection &&
|
|
214
|
+
const component = current instanceof NodeSelection && isElement(current.node);
|
|
181
215
|
for (const mark of ['bold', 'italic', 'underline', 'link'] as const)
|
|
182
216
|
if (editor.isActive(mark)) active.push(mark);
|
|
183
217
|
if (!component && parent.type.name === 'paragraph') active.push('paragraph');
|
|
@@ -249,7 +283,7 @@ export function createTiptapAdapter(editor: Editor, manifests: readonly Componen
|
|
|
249
283
|
const layout = first?.type.name === LAYOUT;
|
|
250
284
|
// Never replace or nest into the component at the cursor: insert after it. A selected component in text takes
|
|
251
285
|
// inline snippets after it; a block goes after its block, below.
|
|
252
|
-
const selected = current instanceof NodeSelection &&
|
|
286
|
+
const selected = current instanceof NodeSelection && isElement(current.node) ? current.node : null;
|
|
253
287
|
let at: number | { from: number; to: number } | null =
|
|
254
288
|
selected !== null && (inline || !selected.isInline) ? current.to : null;
|
|
255
289
|
for (let depth = current.$from.depth; at === null && depth > 0; depth--) {
|
|
@@ -297,13 +331,13 @@ export function createTiptapAdapter(editor: Editor, manifests: readonly Componen
|
|
|
297
331
|
},
|
|
298
332
|
getElement(id) {
|
|
299
333
|
const hit = find(id);
|
|
300
|
-
return hit !== null &&
|
|
334
|
+
return hit !== null && isElement(hit.node)
|
|
301
335
|
? toHtml(serializer.serializeNode(hit.node, { document: inert }))
|
|
302
336
|
: null;
|
|
303
337
|
},
|
|
304
338
|
replaceElement(id, html) {
|
|
305
339
|
const hit = find(id);
|
|
306
|
-
if (hit === null || !
|
|
340
|
+
if (hit === null || !isElement(hit.node)) return;
|
|
307
341
|
const box = inert.createElement('div');
|
|
308
342
|
box.innerHTML = inertStyles(html);
|
|
309
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
|
@@ -209,8 +209,8 @@ const editorStyles: CSSResultGroup = [
|
|
|
209
209
|
inset-block-start: var(--astl-editor-sticky-top, var(--astl-space-4));
|
|
210
210
|
max-block-size: calc(100dvh - var(--astl-editor-sticky-top, var(--astl-space-4)) - var(--astl-space-4));
|
|
211
211
|
overflow-y: auto;
|
|
212
|
-
padding: var(--astl-focus-width);
|
|
213
|
-
margin: calc(-1 * var(--astl-focus-width));
|
|
212
|
+
padding: var(--astl-editor-focus-width, 2px);
|
|
213
|
+
margin: calc(-1 * var(--astl-editor-focus-width, 2px));
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
`,
|
|
@@ -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;
|