@tristan2828/ui-foundation 4.72.0 → 4.74.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/conventions/docs/add-an-entity.md +38 -14
- package/conventions/docs/design-language.md +103 -26
- package/dist/components/app/markdown.d.ts +13 -1
- package/dist/components/app/markdown.js +43 -8
- package/dist/components/app/milkdown-editor.d.ts +1 -1
- package/dist/components/app/milkdown-editor.js +184 -19
- package/dist/components/app/page-link.d.ts +13 -0
- package/dist/components/app/page-link.js +44 -0
- package/dist/components/app/page-restore.d.ts +3 -0
- package/dist/components/app/page-restore.js +14 -0
- package/dist/components/app/page-trail.d.ts +17 -0
- package/dist/components/app/page-trail.js +71 -0
- package/dist/components/app/rich-text-editor.d.ts +22 -0
- package/dist/components/app/rich-text-editor.js +8 -0
- package/dist/components/app/rich-text-floating-toolbar.d.ts +3 -1
- package/dist/components/app/rich-text-floating-toolbar.js +2 -2
- package/dist/components/app/rich-text-page-links.d.ts +44 -0
- package/dist/components/app/rich-text-page-links.js +201 -0
- package/dist/components/app/rich-text-slash-menu.d.ts +3 -4
- package/dist/components/app/rich-text-slash.d.ts +12 -3
- package/dist/components/app/rich-text-slash.js +16 -5
- package/dist/components/app/rich-text-toolbar.d.ts +3 -1
- package/dist/components/app/rich-text-toolbar.js +10 -7
- package/dist/components/ui/breadcrumb.d.ts +10 -0
- package/dist/components/ui/breadcrumb.js +37 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/lib/page-link.d.ts +40 -0
- package/dist/lib/page-link.js +32 -0
- package/dist/lib/page-trail.d.ts +7 -0
- package/dist/lib/page-trail.js +24 -0
- package/package.json +1 -1
- package/styles/index.css +73 -0
- package/styles/theme.css +55 -1
|
@@ -4,25 +4,25 @@
|
|
|
4
4
|
## Index
|
|
5
5
|
|
|
6
6
|
- [The reference files](#the-reference-files) · lines 41–63
|
|
7
|
-
- [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 65–
|
|
7
|
+
- [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 65–782
|
|
8
8
|
- Step 1: Add `<Entity>` to `openapi.yaml` · lines 107–114
|
|
9
9
|
- Step 2: `npm run gen:api` · lines 115–116
|
|
10
10
|
- Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 117–128
|
|
11
11
|
- Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 129–138
|
|
12
12
|
- Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 139–143
|
|
13
|
-
- Step 6: Copy the reference files, one for one, not just the two screens · lines 144–
|
|
14
|
-
- Step 7: Register routes · lines
|
|
15
|
-
- Step 8: Add Playwright specs for all three screens · lines
|
|
16
|
-
- Step 9: Register the nav entry and route names · lines
|
|
17
|
-
- Step 10: `npm run verify`. · lines
|
|
18
|
-
- [How a list opens a record](#how-a-list-opens-a-record) · lines
|
|
19
|
-
- [The record view](#the-record-view) · lines
|
|
20
|
-
- [What not to copy](#what-not-to-copy) · lines
|
|
21
|
-
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines
|
|
22
|
-
- [Deleting](#deleting) · lines
|
|
23
|
-
- [Fields only a script writes](#fields-only-a-script-writes) · lines
|
|
24
|
-
- [Searching one part of the app](#searching-one-part-of-the-app) · lines
|
|
25
|
-
- [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines
|
|
13
|
+
- Step 6: Copy the reference files, one for one, not just the two screens · lines 144–669
|
|
14
|
+
- Step 7: Register routes · lines 670–685
|
|
15
|
+
- Step 8: Add Playwright specs for all three screens · lines 686–764
|
|
16
|
+
- Step 9: Register the nav entry and route names · lines 765–779
|
|
17
|
+
- Step 10: `npm run verify`. · lines 780–782
|
|
18
|
+
- [How a list opens a record](#how-a-list-opens-a-record) · lines 784–922
|
|
19
|
+
- [The record view](#the-record-view) · lines 897–922
|
|
20
|
+
- [What not to copy](#what-not-to-copy) · lines 924–950
|
|
21
|
+
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 952–969
|
|
22
|
+
- [Deleting](#deleting) · lines 971–1000
|
|
23
|
+
- [Fields only a script writes](#fields-only-a-script-writes) · lines 1002–1023
|
|
24
|
+
- [Searching one part of the app](#searching-one-part-of-the-app) · lines 1025–1034
|
|
25
|
+
- [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1037–1076
|
|
26
26
|
|
|
27
27
|
<!-- /index -->
|
|
28
28
|
|
|
@@ -502,6 +502,30 @@ is a filled-in example while the Widgets demo is still here).
|
|
|
502
502
|
(`useEdit<Entity>Field`). Without the prop the boxes are pictures
|
|
503
503
|
and the text stays read-only. A list's "2/5" column counts them
|
|
504
504
|
with `countTasks(text)` (`{ done, total }`; `total` 0 for none).
|
|
505
|
+
- **Pages in the notes** (a record's notes linking to pages of their
|
|
506
|
+
own, each a title and its own Markdown at its own URL, and a page's
|
|
507
|
+
notes linking to pages under it, to any depth): the app keeps the
|
|
508
|
+
pages (a table, an API, a screen per page); the foundation only
|
|
509
|
+
draws and makes the links. A page is linked by an ordinary Markdown
|
|
510
|
+
link, `[Getting Started](/notes/12/pages/3)`, so the notes stay
|
|
511
|
+
Markdown and nothing about how they're stored changes. Give
|
|
512
|
+
`<Markdown>` and `RichTextEditor` the same `pageLink={(href) => …}`:
|
|
513
|
+
return `{ title, removed, onRestore }` for an address that is one of
|
|
514
|
+
the app's pages (look it up in the record's pages, already loaded),
|
|
515
|
+
`null` for any other link. A page link shows the page icon and the
|
|
516
|
+
page's title and opens it in this tab; alone on its line it's a row
|
|
517
|
+
of its own; a removed page (soft-deleted) shows "Page removed" and,
|
|
518
|
+
with `onRestore` (the app's undelete, returning its promise),
|
|
519
|
+
Restore. Give the editor `onCreatePage={(title) => createPage(title).then((page) => pagePath(page))}`
|
|
520
|
+
too: "/page" (and Turn into page on selected words) asks for a
|
|
521
|
+
title, awaits the new page's address and puts in the link; a
|
|
522
|
+
rejection shows in the title box in the gateway's words and leaves
|
|
523
|
+
the text as it was. The page's own screen puts `PageTrail` above its
|
|
524
|
+
title (`crumbs`: the list, the record, every page above this one,
|
|
525
|
+
then this one, last, with no `href`): it folds the middle into a "…"
|
|
526
|
+
menu when it doesn't fit. A page's notes take the same two props, so
|
|
527
|
+
nothing assumes one level: the app decides where a new page lives
|
|
528
|
+
(under the record, or under the page whose note it's in).
|
|
505
529
|
- **Notes worth taking on paper** (a visit's prep and questions, a
|
|
506
530
|
guide, a checklist to tick by hand): mark each of those sections
|
|
507
531
|
`print: true`. The header gets a Print notes button (`printLabel`
|
|
@@ -3,31 +3,32 @@
|
|
|
3
3
|
<!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
|
|
4
4
|
## Index
|
|
5
5
|
|
|
6
|
-
- [Palettes](#palettes) · lines
|
|
7
|
-
- [Glow](#glow) · lines
|
|
8
|
-
- [Semantic tones](#semantic-tones) · lines
|
|
9
|
-
- [The three badge styles](#the-three-badge-styles) · lines
|
|
10
|
-
- [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines
|
|
11
|
-
- [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines
|
|
12
|
-
- [Logos and brand marks](#logos-and-brand-marks) · lines
|
|
13
|
-
- [Categorical colour](#categorical-colour) · lines
|
|
14
|
-
- [
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
17
|
-
|
|
18
|
-
- [
|
|
19
|
-
|
|
20
|
-
- [
|
|
21
|
-
- [
|
|
22
|
-
- [
|
|
23
|
-
- [
|
|
24
|
-
|
|
25
|
-
- [
|
|
26
|
-
- [A list as
|
|
27
|
-
- [
|
|
28
|
-
- [
|
|
29
|
-
- [
|
|
30
|
-
- [
|
|
6
|
+
- [Palettes](#palettes) · lines 41–108
|
|
7
|
+
- [Glow](#glow) · lines 110–128
|
|
8
|
+
- [Semantic tones](#semantic-tones) · lines 130–158
|
|
9
|
+
- [The three badge styles](#the-three-badge-styles) · lines 160–177
|
|
10
|
+
- [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 179–208
|
|
11
|
+
- [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 210–223
|
|
12
|
+
- [Logos and brand marks](#logos-and-brand-marks) · lines 225–269
|
|
13
|
+
- [Categorical colour](#categorical-colour) · lines 271–341
|
|
14
|
+
- [Heat scale](#heat-scale) · lines 343–404
|
|
15
|
+
- [A stored colour](#a-stored-colour) · lines 406–454
|
|
16
|
+
- [Shapes and sizes](#shapes-and-sizes) · lines 456–477
|
|
17
|
+
- [Typography](#typography) · lines 479–585
|
|
18
|
+
- [Written text (notes)](#written-text-notes) · lines 513–585
|
|
19
|
+
- [Density](#density) · lines 587–673
|
|
20
|
+
- [Rows on this device](#rows-on-this-device) · lines 646–673
|
|
21
|
+
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 675–789
|
|
22
|
+
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 791–860
|
|
23
|
+
- [Notices](#notices) · lines 862–890
|
|
24
|
+
- [A value over time](#a-value-over-time) · lines 892–978
|
|
25
|
+
- [Several values over time](#several-values-over-time) · lines 941–978
|
|
26
|
+
- [A list as a board](#a-list-as-a-board) · lines 980–1031
|
|
27
|
+
- [A list as cards](#a-list-as-cards) · lines 1033–1079
|
|
28
|
+
- [Key numbers on a record](#key-numbers-on-a-record) · lines 1081–1103
|
|
29
|
+
- [Picking at random](#picking-at-random) · lines 1105–1136
|
|
30
|
+
- [Filling in what's missing](#filling-in-whats-missing) · lines 1138–1205
|
|
31
|
+
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1207–1232
|
|
31
32
|
|
|
32
33
|
<!-- /index -->
|
|
33
34
|
|
|
@@ -95,7 +96,8 @@ wear it too. An installed app's colours follow it with
|
|
|
95
96
|
|
|
96
97
|
The package's `e2e/fixtures-visual.spec.ts` runs every primitive,
|
|
97
98
|
composite and tone story through axe in each palette, and measures every
|
|
98
|
-
glyph
|
|
99
|
+
glyph, categorical slot and heat step against each palette's page and
|
|
100
|
+
card.
|
|
99
101
|
|
|
100
102
|
**An app's own axe specs** check its palettes instead of light and dark:
|
|
101
103
|
`defineA11ySuite({ …, palettes: ['indigo-cyan'] })` (and
|
|
@@ -338,6 +340,69 @@ If you find yourself wanting a thirteenth, that is a sign the column should
|
|
|
338
340
|
be showing a shape or a label rather than more colours: there is no more
|
|
339
341
|
room that stays readable.
|
|
340
342
|
|
|
343
|
+
## Heat scale
|
|
344
|
+
|
|
345
|
+
For values that have an **order**: how much, how often, how hot. A heat
|
|
346
|
+
map, a calendar shaded by activity, a grid of counts. Five steps from
|
|
347
|
+
cold to hot, `--heat-1` through `--heat-5`. Tailwind gives each one as
|
|
348
|
+
`fill-heat-1` (a shape), `bg-heat-1` (a cell) and `text-heat-1-foreground`
|
|
349
|
+
(text on that cell).
|
|
350
|
+
|
|
351
|
+
**Use it only for ordered values.** A value that's good or bad is a tone
|
|
352
|
+
(hot is not "bad" here, and red here says nothing about danger). A value
|
|
353
|
+
that's only different from its neighbours is a categorical slot: the scale
|
|
354
|
+
would claim one category is more than another. Beside tone badges, keep
|
|
355
|
+
heat out of the same column.
|
|
356
|
+
|
|
357
|
+
An app sorts its values into the five steps itself, on rules it writes
|
|
358
|
+
down (thresholds, or an even split of the range), and maps each to whole
|
|
359
|
+
class names:
|
|
360
|
+
|
|
361
|
+
```tsx
|
|
362
|
+
const HEAT = [
|
|
363
|
+
{ fill: 'fill-heat-1', cell: 'bg-heat-1 text-heat-1-foreground' },
|
|
364
|
+
{ fill: 'fill-heat-2', cell: 'bg-heat-2 text-heat-2-foreground' },
|
|
365
|
+
{ fill: 'fill-heat-3', cell: 'bg-heat-3 text-heat-3-foreground' },
|
|
366
|
+
{ fill: 'fill-heat-4', cell: 'bg-heat-4 text-heat-4-foreground' },
|
|
367
|
+
{ fill: 'fill-heat-5', cell: 'bg-heat-5 text-heat-5-foreground' },
|
|
368
|
+
] as const
|
|
369
|
+
|
|
370
|
+
<path className={`${HEAT[step - 1].fill} stroke-card`} d={shape} />
|
|
371
|
+
<td className={HEAT[step - 1].cell}>{count}</td>
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
- **Opaque, at full strength.** Each step clears 3:1 against the card and
|
|
375
|
+
the page in light, dark and every palette, so a shape stands out with
|
|
376
|
+
no outline. An opacity modifier (`bg-heat-3/50`) gives that up.
|
|
377
|
+
- **Text on a fill takes its own foreground.** Pair the two as above: the
|
|
378
|
+
right text colour depends on the step and the theme. `text-foreground`
|
|
379
|
+
or muted text on a fill fails. It measures 4.71:1 at the least.
|
|
380
|
+
- **Neighbours can touch.** Neighbouring steps are at least ΔE 17.8 apart
|
|
381
|
+
(the perceived difference) and 12.6 under simulated deuteranopia and
|
|
382
|
+
protanopia, the common red-green deficiencies. A thin `stroke-card`
|
|
383
|
+
between shapes still helps, since a boundary is easier to see than a
|
|
384
|
+
shade.
|
|
385
|
+
- **The order holds without hue.** Each step is darker than the one before
|
|
386
|
+
it in both themes, so the scale also reads in greyscale. Hot is always
|
|
387
|
+
the red end, which in the dark themes means it is the darker end too.
|
|
388
|
+
- **Never colour alone.** Show the value too, in the cell, a tooltip or
|
|
389
|
+
a legend of the steps. A shape holding a value needs a name for screen
|
|
390
|
+
readers.
|
|
391
|
+
- **Nothing to show is not step 1.** Step 1 is the coldest *value*. No data
|
|
392
|
+
stays `fill-muted` or an empty state, so "none" and "cold" don't look
|
|
393
|
+
alike.
|
|
394
|
+
- **Five steps, not more.** Past five, neighbours stop being readable as
|
|
395
|
+
different. Bin the values rather than interpolating between steps.
|
|
396
|
+
|
|
397
|
+
The package's fixtures render it (`patterns/HeatScale`). Its Default story
|
|
398
|
+
runs through axe and the token check in light and dark, axe in every
|
|
399
|
+
palette too, and a check that measures every step, as a fill and as a
|
|
400
|
+
cell, against the page and a card in each. `tests/heat-scale.test.ts`
|
|
401
|
+
holds the distance between neighbours, the order of lightness and every
|
|
402
|
+
step against every palette's card and raised surface. `SideBySide` shows
|
|
403
|
+
both themes at once, under normal vision and simulated deuteranopia and
|
|
404
|
+
protanopia.
|
|
405
|
+
|
|
341
406
|
## A stored colour
|
|
342
407
|
|
|
343
408
|
A colour the user stored as data (a paint's hex, a label's colour, a
|
|
@@ -494,6 +559,18 @@ shade: note `info`, tip `success`, important category slot 2, warning
|
|
|
494
559
|
`warning`, caution `destructive`. The package draws all of it; an app
|
|
495
560
|
only renders `<Markdown>` or the editor.
|
|
496
561
|
|
|
562
|
+
A page link (a link the app marks as one of its pages, `pageLink`) is the
|
|
563
|
+
page icon in `--muted-foreground`, then the title in the text's own
|
|
564
|
+
colour at medium weight, underlined in `--muted-foreground` (the colour
|
|
565
|
+
of the words around it, so the underline is what tells it apart). Alone
|
|
566
|
+
on its line it's a page line, a row that tints `--muted` on hover. A
|
|
567
|
+
removed page is muted and struck through, "Page removed" beside it in
|
|
568
|
+
the caption size, with an outline `xs` Restore button. Both renderers
|
|
569
|
+
draw it from the same CSS (styles/index.css "Page links in written
|
|
570
|
+
text"). The trail back from a page, `PageTrail`, is shadcn's Breadcrumb:
|
|
571
|
+
crumbs in `--muted-foreground`, the page itself in `--foreground`, on
|
|
572
|
+
one line, the middle folded into a "…" menu when it doesn't fit.
|
|
573
|
+
|
|
497
574
|
Highlighted words (`==words==` in the Markdown) have four colour tokens:
|
|
498
575
|
`--highlight-amber` (the default), `--highlight-yellow`,
|
|
499
576
|
`--highlight-green` and `--highlight-red` (`bg-highlight-amber`, …). Each
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ComponentProps } from 'react';
|
|
2
|
+
import type { PageLinkResolver } from '../../lib/page-link.js';
|
|
2
3
|
import { type HeadingFrom, type HeadingLevel, type TableLook } from './prose-look.js';
|
|
3
4
|
export type MarkdownProps = {
|
|
4
5
|
/** The Markdown source. Raw HTML in it is shown as text, never rendered. */
|
|
@@ -50,6 +51,17 @@ export type MarkdownProps = {
|
|
|
50
51
|
* RichTextEditor. Either way columns fit their words.
|
|
51
52
|
*/
|
|
52
53
|
tableLook?: TableLook;
|
|
54
|
+
/**
|
|
55
|
+
* Which links are the app's own pages (src/lib/page-link.ts): called
|
|
56
|
+
* with each link's address, it returns what the app knows of that page
|
|
57
|
+
* (its title, whether it's removed, how to restore it), or `null` for
|
|
58
|
+
* an ordinary link. A page link shows the page icon and the page's
|
|
59
|
+
* title and opens the page in this tab; alone in a paragraph it's a row
|
|
60
|
+
* of its own. A removed page shows "Page removed" and, with
|
|
61
|
+
* `onRestore`, a Restore button. The Markdown is never changed. Pages
|
|
62
|
+
* may nest to any depth: the package never asks whose page it is.
|
|
63
|
+
*/
|
|
64
|
+
pageLink?: PageLinkResolver;
|
|
53
65
|
className?: string;
|
|
54
66
|
} & Omit<ComponentProps<'div'>, 'children'>;
|
|
55
|
-
export declare function Markdown({ children, headingLevel, headingFrom, foldKey: foldKeyProp, foldable, onTasksChange: onTasksChangeProp, tableLook, className, ...rest }: MarkdownProps): import("react").JSX.Element;
|
|
67
|
+
export declare function Markdown({ children, headingLevel, headingFrom, foldKey: foldKeyProp, foldable, onTasksChange: onTasksChangeProp, tableLook, pageLink, className, ...rest }: MarkdownProps): import("react").JSX.Element;
|
|
@@ -55,6 +55,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
55
55
|
// Printed (EntityView's Print notes, PrintingContext), it's the whole
|
|
56
56
|
// text: nothing folded, no fold buttons, task boxes as glyphs.
|
|
57
57
|
//
|
|
58
|
+
// With `pageLink`, a link the app says is one of its pages (a child page
|
|
59
|
+
// of the record, or of a page, to any depth: src/lib/page-link.ts) is a
|
|
60
|
+
// page link: the page icon and the page's title, opening the page in this
|
|
61
|
+
// tab. Alone in its paragraph, it's a page line, a row of its own. A page
|
|
62
|
+
// the app reports removed shows "Page removed", with Restore when the app
|
|
63
|
+
// gives one. Every other link is as it was; the text is never changed.
|
|
64
|
+
//
|
|
58
65
|
// A task item (`- [ ] to do`, `- [x] done`) shows its box as a glyph
|
|
59
66
|
// with its state in words: read-only text has nothing to tick. With
|
|
60
67
|
// `onTasksChange`, each box is a real checkbox, named for its item's
|
|
@@ -76,6 +83,7 @@ import { remarkToggleHeadings } from '../../lib/markdown-toggle.js';
|
|
|
76
83
|
import { toggleTaskAt } from '../../lib/markdown-tasks.js';
|
|
77
84
|
import { textTopHeading } from '../../lib/markdown-top-heading.js';
|
|
78
85
|
import { CALLOUT_BOX, CALLOUT_LOOK, DEFAULT_HEADING_LEVEL, FOLD_BUTTON, FOLD_HEADING, headingBand, headingClass, headingTag, PROSE, PROSE_INSET, } from './prose-look.js';
|
|
86
|
+
import { PageLinkView } from './page-link.js';
|
|
79
87
|
import { usePrinting } from './print-context.js';
|
|
80
88
|
import { headerTexts, TABLE_SCROLL_FOCUS, watchTableScroll } from './prose-table-scroll.js';
|
|
81
89
|
const REMARK_PLUGINS = [remarkGfm, remarkCallouts, remarkHighlights, remarkToggleHeadings];
|
|
@@ -138,6 +146,37 @@ function TaskBox({ checked }) {
|
|
|
138
146
|
onClick: (event) => event.stopPropagation(), "aria-label": item.name || (checked ? 'Done' : 'Not done'), "data-slot": "task-box", className: "mr-2 inline-flex align-[-0.1875rem]" }));
|
|
139
147
|
return checked ? (_jsx(SquareCheckIcon, { role: "img", "aria-label": "Done", className: "mr-2 inline-block size-4 align-[-0.1875rem] text-foreground" })) : (_jsx(SquareIcon, { role: "img", "aria-label": "Not done", className: "mr-2 inline-block size-4 align-[-0.1875rem] text-muted-foreground" }));
|
|
140
148
|
}
|
|
149
|
+
// Says which links are the app's pages: given only with `pageLink`.
|
|
150
|
+
const PageLinkContext = createContext(null);
|
|
151
|
+
// The address of the one link a paragraph holds and nothing else (spaces
|
|
152
|
+
// aside), or null: a page line, when the app says it's a page.
|
|
153
|
+
function soleLinkHref(node) {
|
|
154
|
+
const children = (node?.children ?? []).filter((child) => !(child.type === 'text' && !(child.value ?? '').trim()));
|
|
155
|
+
const only = children.length === 1 ? children[0] : null;
|
|
156
|
+
const href = only?.tagName === 'a' ? only.properties?.href : undefined;
|
|
157
|
+
return typeof href === 'string' && href ? href : null;
|
|
158
|
+
}
|
|
159
|
+
// A link: a page link when the app says its address is one of its pages,
|
|
160
|
+
// else an ordinary one, opening in a new tab.
|
|
161
|
+
function MarkdownLink(props) {
|
|
162
|
+
const resolve = useContext(PageLinkContext);
|
|
163
|
+
const { href, children, ...rest } = omitNode(props);
|
|
164
|
+
if (!href)
|
|
165
|
+
return _jsx("span", { children: children });
|
|
166
|
+
const info = resolve?.(href);
|
|
167
|
+
if (info)
|
|
168
|
+
return _jsx(PageLinkView, { href: href, info: info, words: itemText(props.node), children: children });
|
|
169
|
+
return (_jsxs("a", { ...rest, href: href, target: "_blank", rel: "noreferrer", className: PROSE.link, children: [children, _jsx(ExternalLinkIcon, { "aria-hidden": "true", className: "ml-0.5 inline size-3 align-baseline" }), _jsx("span", { className: "sr-only", children: " (opens in a new tab)" })] }));
|
|
170
|
+
}
|
|
171
|
+
// A paragraph: a page line when all it holds is a page link.
|
|
172
|
+
function MarkdownParagraph(props) {
|
|
173
|
+
const resolve = useContext(PageLinkContext);
|
|
174
|
+
const rest = omitNode(props);
|
|
175
|
+
const href = resolve ? soleLinkHref(props.node) : null;
|
|
176
|
+
if (href && resolve?.(href))
|
|
177
|
+
return _jsx("p", { ...rest, "data-page-line": "", className: "page-line" });
|
|
178
|
+
return _jsx("p", { ...rest });
|
|
179
|
+
}
|
|
141
180
|
// Folds a section by its heading's id: given only with `foldKey`.
|
|
142
181
|
const FoldContext = createContext(null);
|
|
143
182
|
// A heading by its Markdown level: the element the page's outline gives
|
|
@@ -165,12 +204,8 @@ function heading(level, top, textTop) {
|
|
|
165
204
|
}
|
|
166
205
|
// Everything but the headings, which follow `headingLevel` (componentsFor).
|
|
167
206
|
const COMPONENTS = {
|
|
168
|
-
a:
|
|
169
|
-
|
|
170
|
-
if (!href)
|
|
171
|
-
return _jsx("span", { children: children });
|
|
172
|
-
return (_jsxs("a", { ...rest, href: href, target: "_blank", rel: "noreferrer", className: PROSE.link, children: [children, _jsx(ExternalLinkIcon, { "aria-hidden": "true", className: "ml-0.5 inline size-3 align-baseline" }), _jsx("span", { className: "sr-only", children: " (opens in a new tab)" })] }));
|
|
173
|
-
},
|
|
207
|
+
a: MarkdownLink,
|
|
208
|
+
p: MarkdownParagraph,
|
|
174
209
|
// A list can mix plain and task items (`- a` then `- [ ] b` is one
|
|
175
210
|
// list): each task item drops its own bullet, the rest keep theirs. Its
|
|
176
211
|
// box is inline, so a loose list's item (its text in a <p>) lays out
|
|
@@ -238,7 +273,7 @@ function componentsFor(top, textTop) {
|
|
|
238
273
|
}
|
|
239
274
|
return components;
|
|
240
275
|
}
|
|
241
|
-
export function Markdown({ children, headingLevel = DEFAULT_HEADING_LEVEL, headingFrom = 'hash', foldKey: foldKeyProp, foldable = true, onTasksChange: onTasksChangeProp, tableLook = 'compact', className, ...rest }) {
|
|
276
|
+
export function Markdown({ children, headingLevel = DEFAULT_HEADING_LEVEL, headingFrom = 'hash', foldKey: foldKeyProp, foldable = true, onTasksChange: onTasksChangeProp, tableLook = 'compact', pageLink, className, ...rest }) {
|
|
242
277
|
// On paper (EntityView's Print notes): every heading plain and open,
|
|
243
278
|
// every task box a picture.
|
|
244
279
|
const printing = usePrinting();
|
|
@@ -263,5 +298,5 @@ export function Markdown({ children, headingLevel = DEFAULT_HEADING_LEVEL, headi
|
|
|
263
298
|
if (saving && typeof saving.then === 'function')
|
|
264
299
|
saving.then(undefined, () => setPending((current) => (current?.sent.includes(next) ? null : current)));
|
|
265
300
|
}, [onTasksChange, children, shown, live]);
|
|
266
|
-
return (_jsx("div", { "data-slot": "markdown", "data-table-look": tableLook, "data-fold-scope": foldKey, ...rest, className: cn('flex min-w-0 flex-col gap-3 type-body text-foreground break-words', PROSE_INSET, className), children: _jsx(FoldContext.Provider, { value: foldKey === undefined ? null : toggle, children: _jsx(TaskToggleContext.Provider, { value: onTasksChange ? tickTask : null, children: _jsx(ReactMarkdown, { remarkPlugins: REMARK_PLUGINS, rehypePlugins: rehypePlugins, components: components, children: onTasksChange ? shown : children }) }) }) }));
|
|
301
|
+
return (_jsx("div", { "data-slot": "markdown", "data-table-look": tableLook, "data-fold-scope": foldKey, ...rest, className: cn('flex min-w-0 flex-col gap-3 type-body text-foreground break-words', PROSE_INSET, className), children: _jsx(PageLinkContext.Provider, { value: pageLink ?? null, children: _jsx(FoldContext.Provider, { value: foldKey === undefined ? null : toggle, children: _jsx(TaskToggleContext.Provider, { value: onTasksChange ? tickTask : null, children: _jsx(ReactMarkdown, { remarkPlugins: REMARK_PLUGINS, rehypePlugins: rehypePlugins, components: components, children: onTasksChange ? shown : children }) }) }) }) }));
|
|
267
302
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { RichTextEditorProps } from './rich-text-editor.js';
|
|
2
|
-
export default function MilkdownEditor({ id, defaultValue, onChange, onProblem, readOnly, autoFocus, placeholder, maxLength, toolbar, inline, upload, imageAccept, imageMaxSize, headingLevel, headingFrom, foldKey, tableLook, className, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, }: RichTextEditorProps): import("react").JSX.Element;
|
|
2
|
+
export default function MilkdownEditor({ id, defaultValue, onChange, onProblem, readOnly, autoFocus, placeholder, maxLength, toolbar, inline, upload, imageAccept, imageMaxSize, headingLevel, headingFrom, foldKey, tableLook, pageLink, onCreatePage, className, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, }: RichTextEditorProps): import("react").JSX.Element;
|