@astl/editor-tiptap 0.1.4 → 0.2.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/dist/styles.js CHANGED
@@ -177,13 +177,23 @@ const baseSurfaceStyles = css `
177
177
  .astl-page-delete,
178
178
  .astl-page-add-title,
179
179
  .astl-page-remove-title,
180
- .astl-help-remove
180
+ .astl-page-check,
181
+ .astl-help-remove,
182
+ .astl-help-free
181
183
  ):focus-visible {
182
184
  outline: var(--astl-focus-width) solid var(--astl-focus);
183
185
  outline-offset: var(--astl-focus-offset);
184
186
  }
185
187
  .astl-surface
186
- :is(.astl-page-join, .astl-page-delete, .astl-page-add-title, .astl-page-remove-title, .astl-help-remove) {
188
+ :is(
189
+ .astl-page-join,
190
+ .astl-page-delete,
191
+ .astl-page-add-title,
192
+ .astl-page-remove-title,
193
+ .astl-page-check,
194
+ .astl-help-remove,
195
+ .astl-help-free
196
+ ) {
187
197
  min-block-size: var(--astl-target-min);
188
198
  min-inline-size: var(--astl-target-min);
189
199
  padding-inline: var(--astl-space-3);
@@ -195,9 +205,18 @@ const baseSurfaceStyles = css `
195
205
  font-size: var(--astl-size-small);
196
206
  cursor: pointer;
197
207
  }
198
- .astl-surface :is(.astl-page-join, .astl-page-delete, .astl-page-add-title, .astl-page-remove-title)[hidden] {
208
+ .astl-surface
209
+ :is(.astl-page-join, .astl-page-delete, .astl-page-add-title, .astl-page-remove-title, .astl-help-free)[hidden] {
199
210
  display: none;
200
211
  }
212
+ /* "Check this page" pressed: filled, with a tick beside its words, so the state shows without colour alone. */
213
+ .astl-surface .astl-page-check[aria-pressed='true'] {
214
+ border-color: var(--astl-accent);
215
+ background: var(--astl-accent-soft);
216
+ }
217
+ .astl-surface .astl-page-check[aria-pressed='true']::before {
218
+ content: '✓ ' / '';
219
+ }
201
220
  /* Beside the title the button keeps its words whole (it broke "Remove" at 320 px): the title gives way instead. */
202
221
  .astl-surface .astl-page-remove-title {
203
222
  flex: none;
@@ -271,7 +290,7 @@ const baseSurfaceStyles = css `
271
290
  display: flex;
272
291
  flex-wrap: wrap;
273
292
  align-items: center;
274
- gap: 0 var(--astl-space-1);
293
+ gap: 0.2em var(--astl-space-1);
275
294
  inline-size: fit-content;
276
295
  max-inline-size: 100%;
277
296
  margin-block: var(--astl-space-4) calc(-1 * var(--frame-width));
@@ -507,13 +526,17 @@ const baseSurfaceStyles = css `
507
526
  .astl-surface .astl-atom-summary {
508
527
  color: var(--astl-ink);
509
528
  }
510
- /* Help for students: a labelled box in its interaction or at its place on the page, never wider than either. */
529
+ /* Help for students on the page: a compact labelled box at its place, never wider than the page. A graded block
530
+ component's own help is kept, not drawn: its frame's tags say what it has, the card edits it. */
531
+ .astl-surface .astl-block[data-astl-graded] .astl-help-box {
532
+ display: none;
533
+ }
511
534
  .astl-surface .astl-help-box {
512
535
  box-sizing: border-box;
513
536
  max-inline-size: 100%;
514
537
  margin-block: var(--astl-space-2);
515
- padding-block: var(--astl-space-1) var(--astl-space-2);
516
- padding-inline: var(--astl-space-3);
538
+ padding-block: 0 var(--astl-space-1);
539
+ padding-inline: var(--astl-space-2);
517
540
  border: var(--astl-outline-width) dashed var(--astl-outline);
518
541
  border-radius: var(--astl-radius-s);
519
542
  background: var(--astl-surface-raised);
@@ -546,17 +569,72 @@ const baseSurfaceStyles = css `
546
569
  outline-offset: var(--astl-focus-offset);
547
570
  }
548
571
  ${unsafeCSS(nativeSelectCss('.astl-surface .astl-help-head select'))}
549
- /* "Remove" closes the head, a page button's look. */
572
+ /* "Remove" closes the head: a cross, a page button's look. */
550
573
  .astl-surface .astl-help-remove {
574
+ display: inline-flex;
575
+ align-items: center;
576
+ justify-content: center;
551
577
  margin-inline-start: auto;
578
+ padding-inline: 0;
579
+ font-weight: 400;
580
+ }
581
+ /* A page's hint with a cost (an older source): what it costs, and "Make it free". */
582
+ .astl-surface .astl-help-notice {
583
+ flex: 1 1 12rem;
584
+ font-weight: 400;
585
+ }
586
+ .astl-surface .astl-help-free {
552
587
  font-weight: 400;
553
588
  }
589
+ .astl-surface :is(.astl-help-notice, .astl-help-head select)[hidden] {
590
+ display: none;
591
+ }
554
592
  .astl-surface .astl-help-content > :first-child {
555
- margin-block-start: var(--astl-space-1);
593
+ margin-block-start: 0;
556
594
  }
557
595
  .astl-surface .astl-help-content > :last-child {
558
596
  margin-block-end: 0;
559
597
  }
598
+ /* An empty box's line says what to write there. */
599
+ .astl-surface .astl-help-content > .astl-help-empty::before {
600
+ content: attr(data-placeholder);
601
+ float: inline-start;
602
+ block-size: 0;
603
+ color: var(--astl-ink-muted);
604
+ pointer-events: none;
605
+ }
606
+ /* A frame's tags: the help for students its component has, small pills in its tab. Each is a 44px target that keeps
607
+ the tab as high as its line. */
608
+ .astl-surface .astl-frame-help {
609
+ box-sizing: border-box;
610
+ display: inline-flex;
611
+ align-items: center;
612
+ min-block-size: var(--astl-target-min);
613
+ margin-block: calc((1.3em - var(--astl-target-min)) / 2);
614
+ padding: 0;
615
+ border: 0;
616
+ background: none;
617
+ color: inherit;
618
+ font: inherit;
619
+ }
620
+ .astl-surface .astl-frame-help > span {
621
+ padding-inline: 0.45em;
622
+ border: 1px solid currentColor;
623
+ border-radius: var(--astl-radius-pill);
624
+ line-height: 1.3;
625
+ white-space: nowrap;
626
+ }
627
+ .astl-surface button.astl-frame-help {
628
+ cursor: pointer;
629
+ }
630
+ .astl-surface button.astl-frame-help:hover > span {
631
+ background: var(--astl-accent-soft);
632
+ color: var(--astl-ink);
633
+ }
634
+ .astl-surface .astl-frame-help:focus-visible {
635
+ outline: var(--astl-focus-width) solid var(--astl-focus);
636
+ outline-offset: var(--astl-focus-offset);
637
+ }
560
638
  .astl-surface .astl-child {
561
639
  padding-block: var(--astl-space-1);
562
640
  padding-inline-start: var(--astl-space-5);
@@ -895,11 +973,12 @@ const zoneStyles = css `
895
973
  `;
896
974
  /** The palette slot of a zone's number: `c1` to `c8`. */
897
975
  const zonePalette = unsafeCSS(Array.from({ length: 8 }, (_, i) => `.astl-surface .astl-zones .c${i + 1}{--line:var(--astl-palette-${i + 1});--soft:var(--astl-palette-${i + 1}-soft)}`).join(''));
898
- // Authors' styles and layouts, as the player draws them: floats stay in their page, no style makes the surface scroll
899
- // sideways, and columns wrap by themselves. A column's edge is the surface's own: the student sees none.
976
+ // Authors' styles and layouts, as the player draws them: floats stay in their page (its content, not its head, which
977
+ // stays a row of its own), no style makes the surface scroll sideways, and columns wrap by themselves. A column's edge
978
+ // is the surface's own: the student sees none.
900
979
  const layoutStyles = css `
901
980
  .astl-surface .ProseMirror,
902
- .astl-surface .astl-page > div {
981
+ .astl-surface .astl-page > div:not(.astl-page-head) {
903
982
  display: flow-root;
904
983
  }
905
984
  .astl-surface .ProseMirror [style] {
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;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.1.4",
3
+ "version": "0.2.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.1.4",
57
- "@astl/editor": "0.1.4",
58
- "@astl/engine": "0.1.4",
59
- "@astl/player": "0.1.4",
60
- "@astl/tokens": "0.1.4",
56
+ "@astl/core": "0.2.1",
57
+ "@astl/editor": "0.2.1",
58
+ "@astl/engine": "0.2.1",
59
+ "@astl/player": "0.2.1",
60
+ "@astl/tokens": "0.2.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
@@ -17,7 +17,15 @@ import { closeHistory } from '@tiptap/pm/history';
17
17
  import { DOMSerializer, 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
- import { addPageIn, attributesOf, mergePageIn, nodeName, removePageIn, splitPageIn } from './nodes.js';
20
+ import {
21
+ addPageIn,
22
+ attributesOf,
23
+ mergePageIn,
24
+ nodeName,
25
+ removePageIn,
26
+ setPageCheckIn,
27
+ splitPageIn,
28
+ } from './nodes.js';
21
29
  import { inert, sourceOf, toHtml } from './source.js';
22
30
  import { createStyles } from './style.js';
23
31
 
@@ -353,6 +361,12 @@ export function createTiptapAdapter(editor: Editor, manifests: readonly Componen
353
361
  if (removed) editor.view.dispatch(tr);
354
362
  return removed;
355
363
  },
364
+ setPageCheck(check, page) {
365
+ const tr = editor.state.tr;
366
+ const changed = setPageCheckIn(tr, check, page);
367
+ if (changed) editor.view.dispatch(tr);
368
+ return changed;
369
+ },
356
370
  format(format, href) {
357
371
  if (!allowed().includes(format)) return false;
358
372
  const active = formatState().active.includes(format);
package/src/blocks.ts CHANGED
@@ -9,6 +9,9 @@ import {
9
9
  type ComponentManifest,
10
10
  directionOf,
11
11
  type EditorBlockPlace,
12
+ EXPLANATION_TAG,
13
+ FEEDBACK_TAG,
14
+ HINT_TAG,
12
15
  type Issue,
13
16
  type MessageParams,
14
17
  type Severity,
@@ -18,6 +21,7 @@ import {
18
21
  type Authoring,
19
22
  EDITOR_NAMESPACE,
20
23
  GLYPHS,
24
+ type HelpPart,
21
25
  type Placement,
22
26
  positionOf,
23
27
  splitPlacement,
@@ -300,6 +304,8 @@ interface Tab {
300
304
  readonly glyph: string;
301
305
  readonly label: string;
302
306
  readonly meta: readonly string[];
307
+ /** Its tags: the help for students the component has, one per kind, each opening it in the card. */
308
+ readonly help: readonly { readonly part: HelpPart; readonly text: string }[];
303
309
  readonly classes: string;
304
310
  /** Where the component is placed (`placedStyle`): its tab goes with it. */
305
311
  readonly place: string;
@@ -342,10 +348,33 @@ const withoutBlockEnd = (place: string): string =>
342
348
  .filter((one) => !one.startsWith('margin-block-end') && !one.startsWith('display'))
343
349
  .join('; ');
344
350
 
351
+ /** The help for students a component holds, by kind: its hints (how many), its explanation, its feedback texts. */
352
+ function helpIn(node: PMNode, name: (tag: string) => string): Record<HelpPart, number> {
353
+ const count = { hints: 0, explanation: 0, feedback: 0 };
354
+ const add = (tag: string) => {
355
+ if (tag === HINT_TAG) count.hints++;
356
+ else if (tag === EXPLANATION_TAG) count.explanation++;
357
+ else if (tag === FEEDBACK_TAG) count.feedback++;
358
+ };
359
+ if (node.isAtom) {
360
+ for (const kept of (node.attrs.children as readonly (string | { readonly tag: string })[]) ?? [])
361
+ if (typeof kept !== 'string') add(kept.tag);
362
+ return count;
363
+ }
364
+ const tags = new Map([HINT_TAG, EXPLANATION_TAG, FEEDBACK_TAG].map((tag) => [name(tag), tag]));
365
+ node.forEach((child) => {
366
+ const tag = tags.get(child.type.name);
367
+ if (tag !== undefined) add(tag);
368
+ });
369
+ return count;
370
+ }
371
+
345
372
  /**
346
373
  * Frames over the pages: decorations only. Text runs flow on the sheet unframed; each block component directly on a
347
374
  * page is framed (`astl-frame` on its node), with a label tab at the frame's top start (`astl-frame-tab`: the type's
348
- * icon, its label and a summary: how many repeated children it holds, `surface.items`, and its points). The frame with
375
+ * icon, its label and a summary: how many repeated children it holds, `surface.items`, and its points, then a graded
376
+ * one's tags for the help for students it has, `astl-frame-help`: "2 hints", "Explanation", "Feedback", each of which
377
+ * puts the cursor in it and opens that help in the card, `openHelp`; its help itself is not drawn). The frame with
349
378
  * the cursor takes `astl-frame-current` and `data-astl-current` (the accent; its tab filled). The frames validate the document a moment after
350
379
  * each change: one with issues (those of its components, as the outline counts them) takes `astl-frame-error` or
351
380
  * `astl-frame-warning`, dashed in that colour, and says them under its tab, errors first, as `authoring.describe`
@@ -356,6 +385,7 @@ export function blocksExtension(
356
385
  typeOf: TypeOf,
357
386
  name: (tag: string) => string,
358
387
  openStyle?: () => void,
388
+ openHelp?: (part: HelpPart) => void,
359
389
  ): Extension {
360
390
  const t = (key: string, params?: MessageParams) => authoring.t(EDITOR_NAMESPACE, key, params);
361
391
  const ui = { lang: authoring.locale, dir: directionOf(authoring.locale) };
@@ -394,13 +424,29 @@ export function blocksExtension(
394
424
  * hidden, so the row is as high with the cursor in the frame as without it; on a row too narrow for both, it goes
395
425
  * above the tab, never over it.
396
426
  */
397
- const tabDom = (tab: Tab): HTMLElement => {
427
+ const tabDom = (tab: Tab, view: EditorView, getPos: () => number | undefined): HTMLElement => {
398
428
  const head = Object.assign(document.createElement('div'), { className: 'astl-frame-head', ...ui });
399
429
  head.contentEditable = 'false';
400
430
  if (tab.place !== '') head.style.cssText = withoutBlockEnd(tab.place);
401
431
  if (tab.classes.includes('astl-frame-current')) head.classList.add('astl-frame-head-current');
402
432
  const dom = head.appendChild(Object.assign(document.createElement('div'), { className: tab.classes }));
403
433
  fillTab(dom, tab);
434
+ // The tags: a press puts the cursor in the component and opens that help in the card.
435
+ for (const { part, text } of tab.help) {
436
+ const tag = dom.appendChild(document.createElement(openHelp === undefined ? 'span' : 'button'));
437
+ tag.className = 'astl-frame-help';
438
+ tag.dataset.helpPart = part;
439
+ tag.appendChild(document.createElement('span')).textContent = text;
440
+ if (openHelp === undefined) continue;
441
+ Object.assign(tag, { type: 'button', tabIndex: -1, title: t('surface.helpOpen') });
442
+ tag.addEventListener('click', (event) => {
443
+ event.preventDefault();
444
+ const pos = getPos();
445
+ if (pos === undefined) return;
446
+ view.dispatch(view.state.tr.setSelection(selectionAt(view.state.doc, pos)));
447
+ openHelp(part);
448
+ });
449
+ }
404
450
  const line = head.appendChild(document.createElement(openStyle === undefined ? 'span' : 'button'));
405
451
  line.className = 'astl-frame-line';
406
452
  line.textContent = tab.line.text;
@@ -486,19 +532,33 @@ export function blocksExtension(
486
532
  ...(items === null ? [] : [t('surface.items', { n: items })]),
487
533
  ...(manifest.graded ? [t('surface.points', { points: pointsOf(component) })] : []),
488
534
  ];
535
+ const help = manifest.graded ? helpIn(component, name) : null;
536
+ const tags =
537
+ help === null
538
+ ? []
539
+ : [
540
+ ...(help.hints > 0
541
+ ? [{ part: 'hints' as const, text: t('surface.helpHints', { n: help.hints }) }]
542
+ : []),
543
+ ...(help.explanation > 0
544
+ ? [{ part: 'explanation' as const, text: t('insert.explanation') }]
545
+ : []),
546
+ ...(help.feedback > 0 ? [{ part: 'feedback' as const, text: t('insert.feedback') }] : []),
547
+ ];
489
548
  const place = placedStyle(component);
490
549
  const style = (component.attrs.attributes as Record<string, string> | undefined)?.style ?? '';
491
550
  const tab: Tab = {
492
551
  glyph: authoring.descriptor(manifest.tag)?.icon ?? '',
493
552
  label: label(manifest),
494
553
  meta,
554
+ help: tags,
495
555
  classes: classes.join(' ').replace('astl-frame', 'astl-frame-tab'),
496
556
  place,
497
557
  line: placeLabel(t, positionOf(style), widthPercent(style)),
498
558
  };
499
559
  // The tab first, then the notes: the lower side comes first at one position.
500
560
  decorations.push(
501
- Decoration.widget(block.from, () => tabDom(tab), {
561
+ Decoration.widget(block.from, (view, getPos) => tabDom(tab, view, getPos), {
502
562
  key: `tab\n${JSON.stringify(tab)}`,
503
563
  side: -2,
504
564
  stopEvent: () => true,
package/src/element.ts CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  type UrlPolicy,
24
24
  } from '@astl/core';
25
25
  import {
26
+ type AstlInspector,
26
27
  type AstlPictureDialog,
27
28
  type AstlPreview,
28
29
  type AstlToolbar,
@@ -34,6 +35,9 @@ import {
34
35
  type EditorFont,
35
36
  type EditorStylePreset,
36
37
  editorMessages,
38
+ HELP_OPEN,
39
+ type HelpOpen,
40
+ type HelpPart,
37
41
  type Outline,
38
42
  type PickPicture,
39
43
  type ToolbarView,
@@ -453,7 +457,7 @@ const KIT_ICONS: readonly string[] = [
453
457
 
454
458
  /** The inspector's parts, forwarded so hosts can restyle its header, banners and fields (`::part(inspector-issue)`). */
455
459
  const INSPECTOR_PARTS =
456
- 'header: inspector-header, id: inspector-id, actions: inspector-actions, issue: inspector-issue, field: inspector-field, label: inspector-label, style: inspector-style';
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';
457
461
 
458
462
  /** The built-in surface module, once imported. */
459
463
  let surfaces: typeof import('./surface.js') | null = null;
@@ -553,6 +557,15 @@ export class AstlEditor extends LitElement {
553
557
  style: (kind: 'picture' | 'figure' | 'component') => {
554
558
  void this.renderRoot.querySelector<AstlToolbar>('astl-toolbar')?.openStyle(kind);
555
559
  },
560
+ // A tag on a frame: `astl-help-open` for a host's inspector, else this element's own opens the help there.
561
+ help: (part: HelpPart) => {
562
+ const element = this.adapter?.getSelection()?.id;
563
+ if (element === undefined) return;
564
+ const detail: HelpOpen = { element, part };
565
+ const event = new CustomEvent(HELP_OPEN, { detail, bubbles: true, composed: true, cancelable: true });
566
+ if (this.dispatchEvent(event))
567
+ void this.renderRoot.querySelector<AstlInspector>('astl-inspector')?.openHelp(part);
568
+ },
556
569
  };
557
570
 
558
571
  /** What the surface tells of pages and blocks: a page added, joined or deleted, a block moved or deleted. */