@astl/editor-tiptap 0.2.0 → 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
@@ -290,7 +290,7 @@ const baseSurfaceStyles = css `
290
290
  display: flex;
291
291
  flex-wrap: wrap;
292
292
  align-items: center;
293
- gap: 0 var(--astl-space-1);
293
+ gap: 0.2em var(--astl-space-1);
294
294
  inline-size: fit-content;
295
295
  max-inline-size: 100%;
296
296
  margin-block: var(--astl-space-4) calc(-1 * var(--frame-width));
@@ -526,13 +526,17 @@ const baseSurfaceStyles = css `
526
526
  .astl-surface .astl-atom-summary {
527
527
  color: var(--astl-ink);
528
528
  }
529
- /* 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
+ }
530
534
  .astl-surface .astl-help-box {
531
535
  box-sizing: border-box;
532
536
  max-inline-size: 100%;
533
537
  margin-block: var(--astl-space-2);
534
- padding-block: var(--astl-space-1) var(--astl-space-2);
535
- padding-inline: var(--astl-space-3);
538
+ padding-block: 0 var(--astl-space-1);
539
+ padding-inline: var(--astl-space-2);
536
540
  border: var(--astl-outline-width) dashed var(--astl-outline);
537
541
  border-radius: var(--astl-radius-s);
538
542
  background: var(--astl-surface-raised);
@@ -565,9 +569,13 @@ const baseSurfaceStyles = css `
565
569
  outline-offset: var(--astl-focus-offset);
566
570
  }
567
571
  ${unsafeCSS(nativeSelectCss('.astl-surface .astl-help-head select'))}
568
- /* "Remove" closes the head, a page button's look. */
572
+ /* "Remove" closes the head: a cross, a page button's look. */
569
573
  .astl-surface .astl-help-remove {
574
+ display: inline-flex;
575
+ align-items: center;
576
+ justify-content: center;
570
577
  margin-inline-start: auto;
578
+ padding-inline: 0;
571
579
  font-weight: 400;
572
580
  }
573
581
  /* A page's hint with a cost (an older source): what it costs, and "Make it free". */
@@ -582,11 +590,51 @@ const baseSurfaceStyles = css `
582
590
  display: none;
583
591
  }
584
592
  .astl-surface .astl-help-content > :first-child {
585
- margin-block-start: var(--astl-space-1);
593
+ margin-block-start: 0;
586
594
  }
587
595
  .astl-surface .astl-help-content > :last-child {
588
596
  margin-block-end: 0;
589
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
+ }
590
638
  .astl-surface .astl-child {
591
639
  padding-block: var(--astl-space-1);
592
640
  padding-inline-start: var(--astl-space-5);
@@ -1 +1 @@
1
- {"version":3,"file":"styles.js","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,eAAe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AE,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.0",
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.2.0",
57
- "@astl/editor": "0.2.0",
58
- "@astl/engine": "0.2.0",
59
- "@astl/player": "0.2.0",
60
- "@astl/tokens": "0.2.0",
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/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. */
package/src/nodes.ts CHANGED
@@ -50,6 +50,7 @@ import { cleanClass, cleanStyle, isStyleName } from '@astl/core/declarations';
50
50
  import {
51
51
  type Authoring,
52
52
  EDITOR_NAMESPACE,
53
+ type HelpPart,
53
54
  type PictureFields,
54
55
  type PictureRequest,
55
56
  type Placement,
@@ -74,6 +75,7 @@ import {
74
75
  type EditorState,
75
76
  NodeSelection,
76
77
  Plugin,
78
+ PluginKey,
77
79
  Selection,
78
80
  TextSelection,
79
81
  type Transaction,
@@ -375,7 +377,7 @@ const updater =
375
377
  function summary(manifest: ComponentManifest | null, attrs: Record<string, unknown>): string {
376
378
  const main = manifest?.attributes.find((a) => a.type === 'string')?.name;
377
379
  if (main !== undefined) return (attrs.attributes as Attributes)[main] ?? '';
378
- // Its help for students is not what it holds: the frame shows it apart (`keptHelp`).
380
+ // Its help for students is not what it holds: the frame's tags say it, the card edits it.
379
381
  const children = (attrs.children as readonly Kept[]).filter(
380
382
  (c) => typeof c === 'string' || !HELP_TAGS.has(c.tag),
381
383
  );
@@ -428,6 +430,7 @@ const SVG_ICONS = {
428
430
  check: 'M4 10.5l4 4 8-9',
429
431
  warning: 'M10 3l8 14H2zM10 8v4M10 14.5v.5',
430
432
  add: 'M10 4v12M4 10h12',
433
+ remove: 'M5 5l10 10M15 5L5 15',
431
434
  };
432
435
 
433
436
  /** A 20 by 20 line icon, hidden from assistive technology. */
@@ -541,9 +544,7 @@ function atomNode(
541
544
  if (picture !== null) dom.append(picture.dom);
542
545
  const body = dom.appendChild(document.createElement('div'));
543
546
  body.className = 'astl-atom-summary';
544
- // Its help for students, read only (the inspector edits it), under what it holds.
545
- const help = dom.appendChild(document.createElement('div'));
546
- help.className = 'astl-help-kept';
547
+ // Its help for students is not drawn: the frame's tags say what it has, the card edits it.
547
548
  // Inside the frame, not on it: an author's border must not hide what the frame says.
548
549
  const paint = placedPainter(body, tag);
549
550
  const showPlace = authoring === undefined ? null : componentPlacing(authoring, dom, editor, getPos);
@@ -554,8 +555,6 @@ function atomNode(
554
555
  // The picture shows the zones and pins; a summary of them would only repeat them.
555
556
  body.textContent = picture === null ? summary(manifest, attrs) : '';
556
557
  body.hidden = picture !== null;
557
- if (authoring !== undefined)
558
- help.replaceChildren(...keptHelp(attrs.children as readonly Kept[], authoring));
559
558
  };
560
559
  render(node.attrs);
561
560
  return {
@@ -582,41 +581,11 @@ const FLOW = `(${FLOW_NODES.join(' | ')})+`;
582
581
  /**
583
582
  * The group of the help for students (`<astl-hint>`, `<astl-explanation>`, `<astl-feedback>`): rich content in a page
584
583
  * or in a block component, never in a column or in text (an inline component or an atom keeps its own as data). In
585
- * the editor, a labelled box; its select sets a hint's cost or the verdict a feedback text is for.
584
+ * the editor, a page's is a labelled box; its select sets the verdict a feedback text is for. A block component's is
585
+ * kept, not drawn (the frame's tags say it, the card edits it): it cannot be selected, so no key reaches it unseen.
586
586
  */
587
587
  const HELP = 'help';
588
588
 
589
- /** The label of a help element in the UI language: what it is, with its cost or its verdict. */
590
- function helpLabel(
591
- tag: string,
592
- attributes: Attributes,
593
- t: (key: string, params?: MessageParams) => string,
594
- ): string {
595
- if (tag === HINT_TAG) {
596
- const percent = Math.round(Number(attributes.cost ?? 0) * 100);
597
- return percent > 0 ? `${t('insert.hint')}, ${t('help.cost', { percent })}` : t('insert.hint');
598
- }
599
- if (tag === EXPLANATION_TAG) return t('insert.explanation');
600
- return `${t('insert.feedback')}: ${t(`help.when.${attributes.when ?? ''}`)}`;
601
- }
602
-
603
- /** An atom's help kept as data, as read-only labelled boxes. */
604
- function keptHelp(children: readonly Kept[], authoring: Authoring): HTMLElement[] {
605
- const t = (key: string, params?: MessageParams) => authoring.t(EDITOR_NAMESPACE, key, params);
606
- return children.flatMap((c) => {
607
- if (typeof c === 'string' || !HELP_TAGS.has(c.tag)) return [];
608
- const box = document.createElement('div');
609
- box.className = 'astl-help-box';
610
- box.dataset.help = c.tag;
611
- const head = box.appendChild(document.createElement('div'));
612
- head.className = 'astl-help-head';
613
- head.lang = authoring.locale;
614
- head.textContent = helpLabel(c.tag, c.attributes, t);
615
- box.appendChild(document.createElement('div')).textContent = textOf(c).trim();
616
- return [box];
617
- });
618
- }
619
-
620
589
  /** Costs a question's hint offers, as written in `cost` ('0': free, no attribute); a cost besides them stays. */
621
590
  const COSTS: readonly string[] = ['0', '0.1', '0.25', '0.5'];
622
591
 
@@ -722,6 +691,7 @@ function helpNode(tag: string, authoring?: Authoring): Node {
722
691
  content: FLOW,
723
692
  defining: true,
724
693
  isolating: true,
694
+ selectable: false,
725
695
  addAttributes: () => sourceAttributes,
726
696
  parseHTML: () => [{ tag }],
727
697
  renderHTML: ({ node }) => [tag, { ...node.attrs.attributes }, 0],
@@ -838,11 +808,14 @@ function helpNode(tag: string, authoring?: Authoring): Node {
838
808
  else attributes[tag === HINT_TAG ? 'cost' : 'when'] = select.value;
839
809
  editor.view.dispatch(editor.state.tr.setNodeAttribute(pos, 'attributes', attributes));
840
810
  });
841
- // "Remove" at the end of the head, named by the kind of box: a box the menu added empty has no other way out.
811
+ // "Remove" at the end of the head, an icon named by the kind of box: a box the menu added empty has no other way
812
+ // out.
842
813
  const remove = head.appendChild(Object.assign(document.createElement('button'), { type: 'button' }));
843
814
  remove.className = 'astl-help-remove';
844
- remove.textContent = t('inspector.remove');
845
- remove.setAttribute('aria-label', t('surface.helpRemove', { kind: tag.replace(/^astl-/, '') }));
815
+ remove.append(lineIcon('remove', 'astl-icon'));
816
+ const removeName = t('surface.helpRemove', { kind: tag.replace(/^astl-/, '') });
817
+ remove.setAttribute('aria-label', removeName);
818
+ remove.title = removeName;
846
819
  remove.addEventListener('click', () => {
847
820
  const pos = getPos();
848
821
  if (typeof pos !== 'number') return;
@@ -927,6 +900,50 @@ export function helpNodes(authoring?: Authoring): Node[] {
927
900
  return [HINT_TAG, EXPLANATION_TAG, FEEDBACK_TAG].map((tag) => helpNode(tag, authoring));
928
901
  }
929
902
 
903
+ /**
904
+ * An empty help box's line says what to write there ("Write the hint..."): the box keeps one empty paragraph to type
905
+ * in, and a decoration marks it (`astl-help-empty`, the text in `data-placeholder`, which the surface's style shows).
906
+ */
907
+ function helpPlaceholderExtension(authoring: Authoring): Extension {
908
+ const kinds = new Map(
909
+ [HINT_TAG, EXPLANATION_TAG, FEEDBACK_TAG].map(
910
+ (tag) => [nodeName(tag), tag.replace(/^astl-/, '')] as const,
911
+ ),
912
+ );
913
+ const decorate = (doc: PMNode): DecorationSet => {
914
+ const decorations: Decoration[] = [];
915
+ doc.descendants((node, pos) => {
916
+ const kind = kinds.get(node.type.name);
917
+ if (kind === undefined) return !node.isTextblock;
918
+ const line = node.firstChild;
919
+ if (node.childCount === 1 && line !== null && line.isTextblock && line.content.size === 0) {
920
+ decorations.push(
921
+ Decoration.node(pos + 1, pos + 1 + line.nodeSize, {
922
+ class: 'astl-help-empty',
923
+ 'data-placeholder': authoring.t(EDITOR_NAMESPACE, 'surface.helpPlaceholder', { kind }),
924
+ }),
925
+ );
926
+ }
927
+ return false;
928
+ });
929
+ return DecorationSet.create(doc, decorations);
930
+ };
931
+ const key = new PluginKey<DecorationSet>('astlHelpPlaceholder');
932
+ return Extension.create({
933
+ name: 'astlHelpPlaceholder',
934
+ addProseMirrorPlugins: () => [
935
+ new Plugin<DecorationSet>({
936
+ key,
937
+ state: {
938
+ init: (_, state) => decorate(state.doc),
939
+ apply: (tr, previous) => (tr.docChanged ? decorate(tr.doc) : previous),
940
+ },
941
+ props: { decorations: (state) => key.getState(state) },
942
+ }),
943
+ ],
944
+ });
945
+ }
946
+
930
947
  /**
931
948
  * A block with rich children, or with rich content (`content: 'flow'`), framed and labelled in the editor, with its
932
949
  * picture when it has picture fields.
@@ -972,6 +989,9 @@ function blockNode(manifest: ComponentManifest, pictures?: PictureView, authorin
972
989
  ({ node, getPos, editor }) => {
973
990
  const dom = document.createElement('div');
974
991
  dom.className = 'astl-block';
992
+ // A graded one's help for students is not drawn (its frame's tags say it, the card edits it); an ungraded one
993
+ // shows help it should not hold, which the engine warns of, so it can be taken away.
994
+ dom.toggleAttribute('data-astl-graded', manifest.graded);
975
995
  const picture = pictures?.layers(manifest.tag).length ? pictures.create(manifest.tag) : null;
976
996
  const contentDOM = document.createElement('div');
977
997
  // Inside the frame, not on it: an author's border must not hide what the frame says.
@@ -1502,6 +1522,11 @@ export interface PictureHooks {
1502
1522
  * does).
1503
1523
  */
1504
1524
  style?(kind: 'picture' | 'figure' | 'component'): void;
1525
+ /**
1526
+ * Opens the help for students of the component at the cursor at a part, from a tag on its frame (`<astl-editor>`:
1527
+ * `astl-help-open`, else its inspector).
1528
+ */
1529
+ help?(part: HelpPart): void;
1505
1530
  }
1506
1531
 
1507
1532
  /** A width from the corner handle on the node at `pos`, one undo step; a figure's picture follows. */
@@ -3035,6 +3060,8 @@ export function astrolabeExtensions(
3035
3060
  (node) => types.get(node.type.name) ?? null,
3036
3061
  nodeName,
3037
3062
  hooks?.style === undefined ? undefined : () => hooks.style?.('component'),
3063
+ hooks?.help === undefined ? undefined : (part) => hooks.help?.(part),
3038
3064
  ),
3065
+ helpPlaceholderExtension(authoring),
3039
3066
  ];
3040
3067
  }
package/src/styles.ts CHANGED
@@ -292,7 +292,7 @@ const baseSurfaceStyles: CSSResult = css`
292
292
  display: flex;
293
293
  flex-wrap: wrap;
294
294
  align-items: center;
295
- gap: 0 var(--astl-space-1);
295
+ gap: 0.2em var(--astl-space-1);
296
296
  inline-size: fit-content;
297
297
  max-inline-size: 100%;
298
298
  margin-block: var(--astl-space-4) calc(-1 * var(--frame-width));
@@ -528,13 +528,17 @@ const baseSurfaceStyles: CSSResult = css`
528
528
  .astl-surface .astl-atom-summary {
529
529
  color: var(--astl-ink);
530
530
  }
531
- /* Help for students: a labelled box in its interaction or at its place on the page, never wider than either. */
531
+ /* Help for students on the page: a compact labelled box at its place, never wider than the page. A graded block
532
+ component's own help is kept, not drawn: its frame's tags say what it has, the card edits it. */
533
+ .astl-surface .astl-block[data-astl-graded] .astl-help-box {
534
+ display: none;
535
+ }
532
536
  .astl-surface .astl-help-box {
533
537
  box-sizing: border-box;
534
538
  max-inline-size: 100%;
535
539
  margin-block: var(--astl-space-2);
536
- padding-block: var(--astl-space-1) var(--astl-space-2);
537
- padding-inline: var(--astl-space-3);
540
+ padding-block: 0 var(--astl-space-1);
541
+ padding-inline: var(--astl-space-2);
538
542
  border: var(--astl-outline-width) dashed var(--astl-outline);
539
543
  border-radius: var(--astl-radius-s);
540
544
  background: var(--astl-surface-raised);
@@ -567,9 +571,13 @@ const baseSurfaceStyles: CSSResult = css`
567
571
  outline-offset: var(--astl-focus-offset);
568
572
  }
569
573
  ${unsafeCSS(nativeSelectCss('.astl-surface .astl-help-head select'))}
570
- /* "Remove" closes the head, a page button's look. */
574
+ /* "Remove" closes the head: a cross, a page button's look. */
571
575
  .astl-surface .astl-help-remove {
576
+ display: inline-flex;
577
+ align-items: center;
578
+ justify-content: center;
572
579
  margin-inline-start: auto;
580
+ padding-inline: 0;
573
581
  font-weight: 400;
574
582
  }
575
583
  /* A page's hint with a cost (an older source): what it costs, and "Make it free". */
@@ -584,11 +592,51 @@ const baseSurfaceStyles: CSSResult = css`
584
592
  display: none;
585
593
  }
586
594
  .astl-surface .astl-help-content > :first-child {
587
- margin-block-start: var(--astl-space-1);
595
+ margin-block-start: 0;
588
596
  }
589
597
  .astl-surface .astl-help-content > :last-child {
590
598
  margin-block-end: 0;
591
599
  }
600
+ /* An empty box's line says what to write there. */
601
+ .astl-surface .astl-help-content > .astl-help-empty::before {
602
+ content: attr(data-placeholder);
603
+ float: inline-start;
604
+ block-size: 0;
605
+ color: var(--astl-ink-muted);
606
+ pointer-events: none;
607
+ }
608
+ /* A frame's tags: the help for students its component has, small pills in its tab. Each is a 44px target that keeps
609
+ the tab as high as its line. */
610
+ .astl-surface .astl-frame-help {
611
+ box-sizing: border-box;
612
+ display: inline-flex;
613
+ align-items: center;
614
+ min-block-size: var(--astl-target-min);
615
+ margin-block: calc((1.3em - var(--astl-target-min)) / 2);
616
+ padding: 0;
617
+ border: 0;
618
+ background: none;
619
+ color: inherit;
620
+ font: inherit;
621
+ }
622
+ .astl-surface .astl-frame-help > span {
623
+ padding-inline: 0.45em;
624
+ border: 1px solid currentColor;
625
+ border-radius: var(--astl-radius-pill);
626
+ line-height: 1.3;
627
+ white-space: nowrap;
628
+ }
629
+ .astl-surface button.astl-frame-help {
630
+ cursor: pointer;
631
+ }
632
+ .astl-surface button.astl-frame-help:hover > span {
633
+ background: var(--astl-accent-soft);
634
+ color: var(--astl-ink);
635
+ }
636
+ .astl-surface .astl-frame-help:focus-visible {
637
+ outline: var(--astl-focus-width) solid var(--astl-focus);
638
+ outline-offset: var(--astl-focus-offset);
639
+ }
592
640
  .astl-surface .astl-child {
593
641
  padding-block: var(--astl-space-1);
594
642
  padding-inline-start: var(--astl-space-5);