@astl/editor-tiptap 0.2.1 → 0.2.3
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 +38 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +27 -11
- package/dist/adapter.js.map +1 -1
- package/dist/element.js +2 -2
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +115 -1
- 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 +130 -52
- package/dist/styles.js.map +1 -1
- package/package.json +6 -6
- package/src/adapter.ts +32 -14
- package/src/element.ts +2 -2
- package/src/nodes.ts +122 -1
- package/src/source-view.ts +2 -2
- package/src/styles.ts +130 -52
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;AA0lC5C,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,9 +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);
|
|
186
|
-
}
|
|
187
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
188
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
189
|
+
}
|
|
190
|
+
/* The surface's authoring controls (the page heads' buttons, a page box's, the blocks' "Add option", a frame's
|
|
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). */
|
|
187
196
|
.astl-surface
|
|
188
197
|
:is(
|
|
189
198
|
.astl-page-join,
|
|
@@ -194,17 +203,52 @@ const baseSurfaceStyles = css `
|
|
|
194
203
|
.astl-help-remove,
|
|
195
204
|
.astl-help-free
|
|
196
205
|
) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
206
|
+
box-sizing: border-box;
|
|
207
|
+
display: inline-flex;
|
|
208
|
+
align-items: center;
|
|
209
|
+
justify-content: center;
|
|
210
|
+
gap: 0.25rem;
|
|
211
|
+
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
212
|
+
min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
213
|
+
padding-block: 0;
|
|
214
|
+
padding-inline: var(--astl-space-2);
|
|
215
|
+
border: 1px solid var(--astl-outline);
|
|
201
216
|
border-radius: var(--astl-radius-s);
|
|
202
|
-
background:
|
|
203
|
-
color: var(--astl-ink);
|
|
217
|
+
background: transparent;
|
|
218
|
+
color: var(--astl-ink-muted);
|
|
204
219
|
font: inherit;
|
|
205
|
-
font-
|
|
220
|
+
font-family: var(--astl-font-body);
|
|
221
|
+
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
222
|
+
font-weight: 600;
|
|
223
|
+
line-height: 1.2;
|
|
224
|
+
white-space: nowrap;
|
|
206
225
|
cursor: pointer;
|
|
207
226
|
}
|
|
227
|
+
.astl-surface .astl-help-remove {
|
|
228
|
+
border-color: transparent;
|
|
229
|
+
}
|
|
230
|
+
.astl-surface .astl-page-add-title {
|
|
231
|
+
padding-inline-start: var(--astl-space-1);
|
|
232
|
+
border-color: transparent;
|
|
233
|
+
color: var(--astl-accent);
|
|
234
|
+
}
|
|
235
|
+
.astl-surface
|
|
236
|
+
:is(
|
|
237
|
+
.astl-page-join,
|
|
238
|
+
.astl-page-delete,
|
|
239
|
+
.astl-page-add-title,
|
|
240
|
+
.astl-page-remove-title,
|
|
241
|
+
.astl-page-check,
|
|
242
|
+
.astl-help-remove,
|
|
243
|
+
.astl-help-free
|
|
244
|
+
):hover {
|
|
245
|
+
background: var(--astl-accent-soft);
|
|
246
|
+
color: var(--astl-ink);
|
|
247
|
+
}
|
|
248
|
+
.astl-surface :is(.astl-help-remove, .astl-block-add button, .astl-page-add-title) .astl-icon {
|
|
249
|
+
inline-size: var(--astl-editor-control-icon-size, 0.875rem);
|
|
250
|
+
block-size: var(--astl-editor-control-icon-size, 0.875rem);
|
|
251
|
+
}
|
|
208
252
|
.astl-surface
|
|
209
253
|
:is(.astl-page-join, .astl-page-delete, .astl-page-add-title, .astl-page-remove-title, .astl-help-free)[hidden] {
|
|
210
254
|
display: none;
|
|
@@ -213,6 +257,7 @@ const baseSurfaceStyles = css `
|
|
|
213
257
|
.astl-surface .astl-page-check[aria-pressed='true'] {
|
|
214
258
|
border-color: var(--astl-accent);
|
|
215
259
|
background: var(--astl-accent-soft);
|
|
260
|
+
color: var(--astl-ink);
|
|
216
261
|
}
|
|
217
262
|
.astl-surface .astl-page-check[aria-pressed='true']::before {
|
|
218
263
|
content: '✓ ' / '';
|
|
@@ -411,8 +456,7 @@ const baseSurfaceStyles = css `
|
|
|
411
456
|
.astl-surface .astl-frame-note[data-severity='warning'] .astl-icon {
|
|
412
457
|
color: var(--astl-warning);
|
|
413
458
|
}
|
|
414
|
-
.astl-surface .astl-flag
|
|
415
|
-
.astl-surface .astl-block-add button {
|
|
459
|
+
.astl-surface .astl-flag {
|
|
416
460
|
box-sizing: border-box;
|
|
417
461
|
display: inline-flex;
|
|
418
462
|
align-items: center;
|
|
@@ -429,14 +473,14 @@ const baseSurfaceStyles = css `
|
|
|
429
473
|
font: inherit;
|
|
430
474
|
cursor: pointer;
|
|
431
475
|
}
|
|
432
|
-
.astl-surface .astl-block-add button:hover {
|
|
433
|
-
border-color: var(--astl-line);
|
|
476
|
+
.astl-surface .astl-block-add button:hover:not(:disabled) {
|
|
434
477
|
background: var(--astl-accent-soft);
|
|
478
|
+
color: var(--astl-ink);
|
|
435
479
|
}
|
|
436
480
|
.astl-surface .astl-block-add :focus-visible,
|
|
437
481
|
.astl-surface .astl-flag:focus-visible {
|
|
438
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
439
|
-
outline-offset: var(--astl-focus-offset);
|
|
482
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
483
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
440
484
|
}
|
|
441
485
|
.astl-surface .astl-icon {
|
|
442
486
|
flex: none;
|
|
@@ -490,35 +534,42 @@ const baseSurfaceStyles = css `
|
|
|
490
534
|
position: relative;
|
|
491
535
|
z-index: 1;
|
|
492
536
|
box-sizing: border-box;
|
|
537
|
+
display: inline-flex;
|
|
538
|
+
align-items: center;
|
|
493
539
|
visibility: hidden;
|
|
494
|
-
min-block-size: var(--astl-
|
|
540
|
+
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
495
541
|
margin-block: 0 var(--astl-space-1);
|
|
496
542
|
margin-inline-start: auto;
|
|
497
|
-
padding-block:
|
|
543
|
+
padding-block: 0;
|
|
498
544
|
padding-inline: var(--astl-space-2);
|
|
499
|
-
border:
|
|
545
|
+
border: 1px solid transparent;
|
|
500
546
|
border-radius: var(--astl-radius-s);
|
|
501
|
-
background:
|
|
502
|
-
color: var(--astl-ink);
|
|
547
|
+
background: transparent;
|
|
548
|
+
color: var(--astl-ink-muted);
|
|
503
549
|
font: inherit;
|
|
504
550
|
font-family: var(--astl-font-body);
|
|
505
|
-
font-size: var(--astl-editor-
|
|
551
|
+
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
506
552
|
font-style: normal;
|
|
507
|
-
font-weight:
|
|
508
|
-
line-height: 1.
|
|
553
|
+
font-weight: 600;
|
|
554
|
+
line-height: 1.2;
|
|
555
|
+
white-space: nowrap;
|
|
509
556
|
}
|
|
510
557
|
.astl-surface .astl-frame-head-current > .astl-frame-line {
|
|
511
558
|
visibility: visible;
|
|
512
559
|
}
|
|
560
|
+
/* As a button it opens the component's style form: outlined, with the selects' chevron. */
|
|
513
561
|
.astl-surface button.astl-frame-line {
|
|
562
|
+
border-color: var(--astl-outline);
|
|
514
563
|
cursor: pointer;
|
|
515
564
|
}
|
|
565
|
+
${unsafeCSS(nativeSelectCss('.astl-surface button.astl-frame-line'))}
|
|
516
566
|
.astl-surface button.astl-frame-line:hover {
|
|
517
|
-
background: var(--astl-accent-soft);
|
|
567
|
+
background-color: var(--astl-accent-soft);
|
|
568
|
+
color: var(--astl-ink);
|
|
518
569
|
}
|
|
519
570
|
.astl-surface .astl-frame-line:focus-visible {
|
|
520
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
521
|
-
outline-offset: var(--astl-focus-offset);
|
|
571
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
572
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
522
573
|
}
|
|
523
574
|
.astl-surface .astl-block.astl-atom {
|
|
524
575
|
cursor: pointer;
|
|
@@ -554,19 +605,21 @@ const baseSurfaceStyles = css `
|
|
|
554
605
|
}
|
|
555
606
|
.astl-surface .astl-help-head select {
|
|
556
607
|
box-sizing: border-box;
|
|
557
|
-
min-block-size: var(--astl-
|
|
608
|
+
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
609
|
+
padding-block: 0;
|
|
558
610
|
padding-inline: var(--astl-space-2);
|
|
559
|
-
border:
|
|
611
|
+
border: 1px solid var(--astl-outline);
|
|
560
612
|
border-radius: var(--astl-radius-s);
|
|
561
613
|
background: var(--astl-surface);
|
|
562
614
|
color: var(--astl-ink);
|
|
563
615
|
font: inherit;
|
|
616
|
+
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
564
617
|
font-weight: 400;
|
|
565
618
|
cursor: pointer;
|
|
566
619
|
}
|
|
567
620
|
.astl-surface .astl-help-head select:focus-visible {
|
|
568
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
569
|
-
outline-offset: var(--astl-focus-offset);
|
|
621
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
622
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
570
623
|
}
|
|
571
624
|
${unsafeCSS(nativeSelectCss('.astl-surface .astl-help-head select'))}
|
|
572
625
|
/* "Remove" closes the head: a cross, a page button's look. */
|
|
@@ -603,14 +656,16 @@ const baseSurfaceStyles = css `
|
|
|
603
656
|
color: var(--astl-ink-muted);
|
|
604
657
|
pointer-events: none;
|
|
605
658
|
}
|
|
606
|
-
/* A frame's tags: the help for students its component has, small pills in its tab. Each is a
|
|
607
|
-
the tab as high as its line. */
|
|
659
|
+
/* A frame's tags: the help for students its component has, small pills in its tab. Each is a 24px target that keeps
|
|
660
|
+
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. */
|
|
608
661
|
.astl-surface .astl-frame-help {
|
|
609
662
|
box-sizing: border-box;
|
|
610
663
|
display: inline-flex;
|
|
611
664
|
align-items: center;
|
|
612
|
-
|
|
613
|
-
|
|
665
|
+
justify-content: center;
|
|
666
|
+
min-block-size: 24px;
|
|
667
|
+
min-inline-size: 24px;
|
|
668
|
+
margin-block: calc((1.3em - 24px) / 2);
|
|
614
669
|
padding: 0;
|
|
615
670
|
border: 0;
|
|
616
671
|
background: none;
|
|
@@ -632,8 +687,11 @@ const baseSurfaceStyles = css `
|
|
|
632
687
|
color: var(--astl-ink);
|
|
633
688
|
}
|
|
634
689
|
.astl-surface .astl-frame-help:focus-visible {
|
|
635
|
-
outline:
|
|
636
|
-
|
|
690
|
+
outline: none;
|
|
691
|
+
}
|
|
692
|
+
.astl-surface .astl-frame-help:focus-visible > span {
|
|
693
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
694
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
637
695
|
}
|
|
638
696
|
.astl-surface .astl-child {
|
|
639
697
|
padding-block: var(--astl-space-1);
|
|
@@ -702,17 +760,35 @@ const baseSurfaceStyles = css `
|
|
|
702
760
|
.astl-surface .astl-block-add {
|
|
703
761
|
display: flex;
|
|
704
762
|
flex-wrap: wrap;
|
|
705
|
-
gap: var(--astl-space-
|
|
763
|
+
gap: var(--astl-space-1);
|
|
706
764
|
padding-block-start: var(--astl-space-1);
|
|
707
765
|
}
|
|
708
766
|
.astl-surface .astl-block-add button[hidden],
|
|
709
767
|
.astl-surface .astl-block-add:not(:has(button:not([hidden]))) {
|
|
710
768
|
display: none;
|
|
711
769
|
}
|
|
770
|
+
/* A small text button under the last child, as the page heads' are. */
|
|
712
771
|
.astl-surface .astl-block-add button {
|
|
713
|
-
|
|
772
|
+
box-sizing: border-box;
|
|
773
|
+
display: inline-flex;
|
|
774
|
+
align-items: center;
|
|
775
|
+
gap: 0.25rem;
|
|
776
|
+
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
777
|
+
min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
778
|
+
margin: 0;
|
|
779
|
+
padding-block: 0;
|
|
780
|
+
padding-inline: var(--astl-space-1) var(--astl-space-2);
|
|
781
|
+
border: 1px solid transparent;
|
|
782
|
+
border-radius: var(--astl-radius-s);
|
|
783
|
+
background: transparent;
|
|
714
784
|
color: var(--astl-accent);
|
|
785
|
+
font: inherit;
|
|
786
|
+
font-family: var(--astl-font-body);
|
|
787
|
+
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
715
788
|
font-weight: 600;
|
|
789
|
+
line-height: 1.2;
|
|
790
|
+
white-space: nowrap;
|
|
791
|
+
cursor: pointer;
|
|
716
792
|
}
|
|
717
793
|
.astl-surface .astl-block-add button:disabled {
|
|
718
794
|
color: var(--astl-ink-muted);
|
|
@@ -737,11 +813,11 @@ const baseSurfaceStyles = css `
|
|
|
737
813
|
words beside it: its ring is inside it, and it is filled (its border is the accent already). An empty chip keeps
|
|
738
814
|
its colours: the solid ring stands out on its dashed one. */
|
|
739
815
|
.astl-surface .ProseMirror-selectednode {
|
|
740
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
741
|
-
outline-offset: var(--astl-focus-offset);
|
|
816
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
817
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
742
818
|
}
|
|
743
819
|
.astl-surface .astl-chip.ProseMirror-selectednode {
|
|
744
|
-
outline-offset: calc(-1 * var(--astl-focus-width));
|
|
820
|
+
outline-offset: calc(-1 * var(--astl-editor-focus-width, 2px));
|
|
745
821
|
}
|
|
746
822
|
.astl-surface .astl-chip.ProseMirror-selectednode:not([data-empty]) {
|
|
747
823
|
background: var(--astl-accent);
|
|
@@ -862,28 +938,30 @@ const baseSurfaceStyles = css `
|
|
|
862
938
|
font-size: var(--astl-size-small);
|
|
863
939
|
}
|
|
864
940
|
.astl-surface button.astl-picture-place {
|
|
865
|
-
min-block-size: var(--astl-
|
|
866
|
-
min-inline-size: var(--astl-
|
|
941
|
+
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
942
|
+
min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
943
|
+
padding-block: 0;
|
|
867
944
|
padding-inline: var(--astl-space-2);
|
|
868
|
-
border:
|
|
945
|
+
border: 1px solid var(--astl-outline);
|
|
869
946
|
border-radius: var(--astl-radius-s);
|
|
870
947
|
background: var(--astl-surface);
|
|
871
948
|
color: var(--astl-ink);
|
|
872
949
|
font: inherit;
|
|
873
|
-
font-size: var(--astl-size
|
|
950
|
+
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
874
951
|
cursor: pointer;
|
|
875
952
|
}
|
|
876
953
|
.astl-surface .astl-picture-edit {
|
|
877
954
|
align-self: flex-start;
|
|
878
|
-
min-block-size: var(--astl-
|
|
879
|
-
min-inline-size: var(--astl-
|
|
955
|
+
min-block-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
956
|
+
min-inline-size: max(24px, var(--astl-editor-control-size, 1.75rem));
|
|
957
|
+
padding-block: 0;
|
|
880
958
|
padding-inline: var(--astl-space-2);
|
|
881
|
-
border:
|
|
959
|
+
border: 1px solid var(--astl-outline);
|
|
882
960
|
border-radius: var(--astl-radius-s);
|
|
883
961
|
background: var(--astl-surface);
|
|
884
962
|
color: var(--astl-ink);
|
|
885
963
|
font: inherit;
|
|
886
|
-
font-size: var(--astl-size
|
|
964
|
+
font-size: var(--astl-editor-control-font-size, 0.8125rem);
|
|
887
965
|
cursor: pointer;
|
|
888
966
|
}
|
|
889
967
|
.astl-surface .astl-figure {
|
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,E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AAE,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.2.
|
|
3
|
+
"version": "0.2.3",
|
|
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.2.
|
|
57
|
-
"@astl/editor": "0.2.
|
|
58
|
-
"@astl/engine": "0.2.
|
|
59
|
-
"@astl/player": "0.2.
|
|
60
|
-
"@astl/tokens": "0.2.
|
|
56
|
+
"@astl/core": "0.2.3",
|
|
57
|
+
"@astl/editor": "0.2.3",
|
|
58
|
+
"@astl/engine": "0.2.3",
|
|
59
|
+
"@astl/player": "0.2.3",
|
|
60
|
+
"@astl/tokens": "0.2.3",
|
|
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
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
import { scanElements } from '@astl/editor';
|
|
15
15
|
import type { ChainedCommands, Editor } from '@tiptap/core';
|
|
16
16
|
import { closeHistory } from '@tiptap/pm/history';
|
|
17
|
-
import { DOMSerializer, type Node as PMNode, DOMParser as SchemaParser } from '@tiptap/pm/model';
|
|
17
|
+
import { DOMSerializer, Fragment, type Node as PMNode, DOMParser as SchemaParser } from '@tiptap/pm/model';
|
|
18
18
|
import { NodeSelection, type Selection, TextSelection, type Transaction } from '@tiptap/pm/state';
|
|
19
19
|
import { cursorIn, isBlockOf, LAYOUT, LAYOUT_COLUMN, moveBlockIn, removeBlockIn } from './blocks.js';
|
|
20
20
|
import {
|
|
@@ -70,26 +70,44 @@ function formatCommand(
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* Changes `from` (at `pos`) into `to` with the least replaced, so that a selection inside it maps through: attributes in
|
|
75
|
+
* place; the children both have at the start and at the end (by type, text by text) patched in place, each the same
|
|
76
|
+
* way; only the run between them replaced, so a child added or taken away (a hint, a row) is just that step. Replacing
|
|
77
|
+
* the whole content instead threw a cursor in the block's prompt out of the block, and the inspector lost its element.
|
|
78
|
+
*/
|
|
74
79
|
function patch(tr: Transaction, pos: number, from: PMNode, to: PMNode): void {
|
|
75
80
|
if (!from.sameMarkup(to)) tr.setNodeMarkup(pos, undefined, to.attrs, from.marks);
|
|
76
81
|
if (from.isLeaf || from.content.eq(to.content)) return;
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
const same = (a: PMNode, b: PMNode) => a.type === b.type && (!a.isText || a.eq(b));
|
|
83
|
+
const shortest = Math.min(from.childCount, to.childCount);
|
|
84
|
+
let start = 0;
|
|
85
|
+
while (start < shortest && same(from.child(start), to.child(start))) start++;
|
|
86
|
+
let end = 0;
|
|
87
|
+
while (
|
|
88
|
+
end < shortest - start &&
|
|
89
|
+
same(from.child(from.childCount - 1 - end), to.child(to.childCount - 1 - end))
|
|
90
|
+
)
|
|
91
|
+
end++;
|
|
87
92
|
const offsets: number[] = [];
|
|
88
93
|
from.forEach((_, offset) => {
|
|
89
94
|
offsets.push(offset);
|
|
90
95
|
});
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
const at = (i: number) => pos + 1 + (i < from.childCount ? (offsets[i] ?? 0) : from.content.size);
|
|
97
|
+
// Last first, so earlier positions stay valid: the children at the end, the run between, the children at the start.
|
|
98
|
+
for (let k = 0; k < end; k++) {
|
|
99
|
+
patch(
|
|
100
|
+
tr,
|
|
101
|
+
at(from.childCount - 1 - k),
|
|
102
|
+
from.child(from.childCount - 1 - k),
|
|
103
|
+
to.child(to.childCount - 1 - k),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
const [fromEnd, toEnd] = [from.childCount - end, to.childCount - end];
|
|
107
|
+
if (start < fromEnd || start < toEnd) {
|
|
108
|
+
tr.replaceWith(at(start), at(fromEnd), Fragment.fromArray(to.content.content.slice(start, toEnd)));
|
|
109
|
+
}
|
|
110
|
+
for (let i = start - 1; i >= 0; i--) patch(tr, at(i), from.child(i), to.child(i));
|
|
93
111
|
}
|
|
94
112
|
|
|
95
113
|
/**
|
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
|
`,
|
package/src/nodes.ts
CHANGED
|
@@ -67,6 +67,7 @@ import {
|
|
|
67
67
|
type DOMOutputSpec,
|
|
68
68
|
DOMSerializer,
|
|
69
69
|
Fragment,
|
|
70
|
+
type MarkType,
|
|
70
71
|
type Mark as PMMark,
|
|
71
72
|
type Node as PMNode,
|
|
72
73
|
Slice,
|
|
@@ -1032,8 +1033,19 @@ function blockNode(manifest: ComponentManifest, pictures?: PictureView, authorin
|
|
|
1032
1033
|
add.addEventListener('click', () => {
|
|
1033
1034
|
const pos = getPos();
|
|
1034
1035
|
const block = typeof pos === 'number' ? editor.state.doc.nodeAt(pos) : null;
|
|
1036
|
+
if (typeof pos !== 'number' || block === null) return;
|
|
1037
|
+
// In a rich block the child is a mark in its text (Select words' word): a new word ends its last line.
|
|
1038
|
+
const markType = editor.schema.marks[childType];
|
|
1039
|
+
if (markType !== undefined) {
|
|
1040
|
+
const word = authoring.t(EDITOR_NAMESPACE, 'surface.newWord');
|
|
1041
|
+
const tr = addMarkedWord(editor.state, pos, block, markType, repeated.tag, word);
|
|
1042
|
+
if (tr === null) return;
|
|
1043
|
+
editor.view.dispatch(tr.scrollIntoView());
|
|
1044
|
+
editor.view.focus();
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1035
1047
|
const type = editor.schema.nodes[childType];
|
|
1036
|
-
if (
|
|
1048
|
+
if (type === undefined) return;
|
|
1037
1049
|
// After the last child of that tag (an option goes after the options, before anything after them).
|
|
1038
1050
|
let at = pos + block.nodeSize - 1;
|
|
1039
1051
|
block.forEach((child, offset) => {
|
|
@@ -1093,6 +1105,113 @@ function blockNode(manifest: ComponentManifest, pictures?: PictureView, authorin
|
|
|
1093
1105
|
});
|
|
1094
1106
|
}
|
|
1095
1107
|
|
|
1108
|
+
/**
|
|
1109
|
+
* A new child of a rich block that is a mark in its text (Select words' word, `markType`): `text` at the end of the
|
|
1110
|
+
* block's last line (after a space), with a fresh id, selected so that typing replaces it and keeps the mark; one undo
|
|
1111
|
+
* step. A block without a line of text gets one.
|
|
1112
|
+
*/
|
|
1113
|
+
function addMarkedWord(
|
|
1114
|
+
state: EditorState,
|
|
1115
|
+
pos: number,
|
|
1116
|
+
block: PMNode,
|
|
1117
|
+
markType: MarkType,
|
|
1118
|
+
tag: string,
|
|
1119
|
+
text: string,
|
|
1120
|
+
): Transaction | null {
|
|
1121
|
+
const tr = closeHistory(state.tr);
|
|
1122
|
+
let end: number | null = null;
|
|
1123
|
+
block.descendants((node, offset) => {
|
|
1124
|
+
if (node.type.name === 'paragraph' || node.type.name === 'heading')
|
|
1125
|
+
end = pos + 2 + offset + node.content.size;
|
|
1126
|
+
return !node.isTextblock;
|
|
1127
|
+
});
|
|
1128
|
+
if (end === null) {
|
|
1129
|
+
const paragraph = state.schema.nodes.paragraph;
|
|
1130
|
+
if (paragraph === undefined) return null;
|
|
1131
|
+
const at = pos + block.nodeSize - 1;
|
|
1132
|
+
tr.insert(at, paragraph.create());
|
|
1133
|
+
end = at + 1;
|
|
1134
|
+
}
|
|
1135
|
+
let at: number = end;
|
|
1136
|
+
const $end = tr.doc.resolve(at);
|
|
1137
|
+
const before = $end.parent.textBetween(0, $end.parentOffset, undefined, '\ufffc');
|
|
1138
|
+
// A plain space before it: inserted text would take the mark of a word that ends the line.
|
|
1139
|
+
if (before !== '' && !/\s$/u.test(before)) {
|
|
1140
|
+
tr.insert(at, state.schema.text(' '));
|
|
1141
|
+
at += 1;
|
|
1142
|
+
}
|
|
1143
|
+
const taken = idsIn(tr.doc);
|
|
1144
|
+
tr.doc.descendants((node) => {
|
|
1145
|
+
for (const mark of node.marks) if (mark.type === markType) taken.add(markId(mark));
|
|
1146
|
+
return true;
|
|
1147
|
+
});
|
|
1148
|
+
const id = freshId(tag.replace(/^astl-/, ''), taken);
|
|
1149
|
+
tr.insert(at, state.schema.text(text, [markType.create({ attributes: { id } })]));
|
|
1150
|
+
// The word grows as the author types over it or at its end (`growingWordExtension`).
|
|
1151
|
+
return tr
|
|
1152
|
+
.setSelection(TextSelection.create(tr.doc, at, at + text.length))
|
|
1153
|
+
.setMeta(GROWING, { id, type: markType });
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
/** The word "Add option" just added in a rich block: its id and mark type, until the cursor leaves it. */
|
|
1157
|
+
interface Growing {
|
|
1158
|
+
readonly id: string;
|
|
1159
|
+
readonly type: MarkType;
|
|
1160
|
+
}
|
|
1161
|
+
const GROWING = new PluginKey<Growing | null>('astlGrowingWord');
|
|
1162
|
+
|
|
1163
|
+
/** Where the run of text marked `growing` is (one word), with its mark, or null. */
|
|
1164
|
+
function growingRun(doc: PMNode, growing: Growing): { from: number; to: number; mark: PMMark } | null {
|
|
1165
|
+
let run: { from: number; to: number; mark: PMMark } | null = null;
|
|
1166
|
+
doc.descendants((node, pos) => {
|
|
1167
|
+
if (!node.isText) return run === null;
|
|
1168
|
+
const mark = node.marks.find((m) => m.type === growing.type && markId(m) === growing.id);
|
|
1169
|
+
if (mark === undefined) return false;
|
|
1170
|
+
run = run === null ? { from: pos, to: pos + node.nodeSize, mark } : { ...run, to: pos + node.nodeSize };
|
|
1171
|
+
return false;
|
|
1172
|
+
});
|
|
1173
|
+
return run;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
/**
|
|
1177
|
+
* A word "Add option" added keeps growing while the author types it: text typed over it (it comes selected) or at its
|
|
1178
|
+
* end joins it, though the words' marks end with them, until a space or the cursor leaves it. Other words keep their
|
|
1179
|
+
* marks as they are.
|
|
1180
|
+
*/
|
|
1181
|
+
const growingWordExtension = Extension.create({
|
|
1182
|
+
name: 'astlGrowingWord',
|
|
1183
|
+
addProseMirrorPlugins: () => [
|
|
1184
|
+
new Plugin<Growing | null>({
|
|
1185
|
+
key: GROWING,
|
|
1186
|
+
state: {
|
|
1187
|
+
init: () => null,
|
|
1188
|
+
apply: (tr, value, _, state) => {
|
|
1189
|
+
const set = tr.getMeta(GROWING) as Growing | null | undefined;
|
|
1190
|
+
const growing = set === undefined ? value : set;
|
|
1191
|
+
if (growing === null) return null;
|
|
1192
|
+
const run = growingRun(state.doc, growing);
|
|
1193
|
+
const { from, to } = state.selection;
|
|
1194
|
+
return run !== null && from >= run.from && to <= run.to ? growing : null;
|
|
1195
|
+
},
|
|
1196
|
+
},
|
|
1197
|
+
props: {
|
|
1198
|
+
handleTextInput: (view, from, to, text) => {
|
|
1199
|
+
const growing = GROWING.getState(view.state);
|
|
1200
|
+
if (growing === null || growing === undefined || !/^[\p{L}\p{N}\p{M}'’-]+$/u.test(text))
|
|
1201
|
+
return false;
|
|
1202
|
+
const run = growingRun(view.state.doc, growing);
|
|
1203
|
+
if (run === null) return false;
|
|
1204
|
+
const over = from === run.from && to === run.to;
|
|
1205
|
+
if (!over && !(from === to && from === run.to)) return false;
|
|
1206
|
+
const tr = view.state.tr.insertText(text, from, to);
|
|
1207
|
+
view.dispatch(tr.addMark(from, from + text.length, run.mark));
|
|
1208
|
+
return true;
|
|
1209
|
+
},
|
|
1210
|
+
},
|
|
1211
|
+
}),
|
|
1212
|
+
],
|
|
1213
|
+
});
|
|
1214
|
+
|
|
1096
1215
|
/**
|
|
1097
1216
|
* A rich child of a block (prompt, option): one line of rich text, in a plain element so no custom element claims
|
|
1098
1217
|
* it. A child the manifest allows once (a prompt) is marked `single`.
|
|
@@ -1814,6 +1933,7 @@ export function pageNode(authoring: Authoring): Node {
|
|
|
1814
1933
|
return button;
|
|
1815
1934
|
};
|
|
1816
1935
|
const addTitle = named('add-title', t('surface.pageAddTitle'));
|
|
1936
|
+
addTitle.prepend(lineIcon('add', 'astl-icon'));
|
|
1817
1937
|
// "Check this page", pressed while the page has `check`: its own Check in practice, then its help.
|
|
1818
1938
|
const check = named('check', t('surface.pageCheck'));
|
|
1819
1939
|
// Hidden until numbered: the first page has no join button, the only page no delete button.
|
|
@@ -3054,6 +3174,7 @@ export function astrolabeExtensions(
|
|
|
3054
3174
|
referencesExtension(authoring, manifests),
|
|
3055
3175
|
childrenExtension(manifests),
|
|
3056
3176
|
richBlocksExtension(authoring, manifests),
|
|
3177
|
+
growingWordExtension,
|
|
3057
3178
|
pastedIdsExtension(authoring, manifests, hooks),
|
|
3058
3179
|
blocksExtension(
|
|
3059
3180
|
authoring,
|
package/src/source-view.ts
CHANGED
|
@@ -101,8 +101,8 @@ const sourceStyles = css`
|
|
|
101
101
|
font: var(--astl-size-small) / 1.5 var(--astl-font-mono);
|
|
102
102
|
}
|
|
103
103
|
.source textarea:focus-visible {
|
|
104
|
-
outline: var(--astl-focus-width) solid var(--astl-focus);
|
|
105
|
-
outline-offset: var(--astl-focus-offset);
|
|
104
|
+
outline: var(--astl-editor-focus-width, 2px) solid var(--astl-focus);
|
|
105
|
+
outline-offset: var(--astl-editor-focus-offset, 1px);
|
|
106
106
|
}
|
|
107
107
|
`;
|
|
108
108
|
|