@tristan2828/ui-foundation 4.77.0 → 4.79.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 +34 -14
- package/conventions/docs/cell-patterns.md +21 -15
- package/conventions/docs/design-language.md +26 -16
- package/conventions/docs/entity-plan-template.md +2 -0
- package/dist/components/app/edit-in-place-presets.d.ts +22 -0
- package/dist/components/app/edit-in-place-presets.js +35 -0
- package/dist/components/app/markdown.js +7 -2
- package/dist/components/app/milkdown-editor.js +65 -5
- package/dist/components/app/month-day-field.d.ts +31 -0
- package/dist/components/app/month-day-field.js +134 -0
- package/dist/components/app/rich-text-table-grips.d.ts +5 -1
- package/dist/components/app/rich-text-table-grips.js +120 -6
- package/dist/components/app/rich-text-table.d.ts +23 -1
- package/dist/components/app/rich-text-table.js +98 -8
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/lib/markdown-highlight.js +2 -1
- package/dist/lib/markdown-merge.js +18 -6
- package/dist/lib/markdown-table-widths.d.ts +51 -0
- package/dist/lib/markdown-table-widths.js +179 -0
- package/dist/lib/month-day.d.ts +27 -0
- package/dist/lib/month-day.js +62 -0
- package/package.json +1 -1
- package/styles/index.css +27 -0
|
@@ -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–802
|
|
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–689
|
|
14
|
+
- Step 7: Register routes · lines 690–705
|
|
15
|
+
- Step 8: Add Playwright specs for all three screens · lines 706–784
|
|
16
|
+
- Step 9: Register the nav entry and route names · lines 785–799
|
|
17
|
+
- Step 10: `npm run verify`. · lines 800–802
|
|
18
|
+
- [How a list opens a record](#how-a-list-opens-a-record) · lines 804–953
|
|
19
|
+
- [The record view](#the-record-view) · lines 917–953
|
|
20
|
+
- [What not to copy](#what-not-to-copy) · lines 955–981
|
|
21
|
+
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 983–1000
|
|
22
|
+
- [Deleting](#deleting) · lines 1002–1031
|
|
23
|
+
- [Fields only a script writes](#fields-only-a-script-writes) · lines 1033–1054
|
|
24
|
+
- [Searching one part of the app](#searching-one-part-of-the-app) · lines 1056–1065
|
|
25
|
+
- [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1068–1107
|
|
26
26
|
|
|
27
27
|
<!-- /index -->
|
|
28
28
|
|
|
@@ -225,6 +225,26 @@ is a filled-in example while the Widgets demo is still here).
|
|
|
225
225
|
Select is (the fixtures' `app/DateField` EditInPlace). The backend column
|
|
226
226
|
is a SQL `date` (`datetime.date` in the model).
|
|
227
227
|
|
|
228
|
+
**A `month-day`** (a day that comes round every year, with no year:
|
|
229
|
+
when a season starts, a yearly deadline) is `type: string` with
|
|
230
|
+
`pattern: '^(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$'` in
|
|
231
|
+
`openapi.yaml`, so the wire, the generated type and the form all hold
|
|
232
|
+
`'MM-DD'` (`'03-14'`), and `''` on the form for an optional one not set
|
|
233
|
+
(sent as `null`). It sorts as text in calendar order. On the form it's
|
|
234
|
+
the foundation's `MonthDayField` in a `Controller` (`clearable` when
|
|
235
|
+
optional); the schema is the string with
|
|
236
|
+
`.refine((v) => v === '' || isMonthDay(v), 'Pick a month and day')`
|
|
237
|
+
(`isMonthDay`: February 29 is a day, February 30 isn't), `min(1, …)`
|
|
238
|
+
too when required. The table and the view show `formatMonthDay(value)`
|
|
239
|
+
("Mar 14"), the not-set label when empty. Editing in place is
|
|
240
|
+
`inPlace.monthDay({ value, save })` (cell pattern 18, "Presets"). The
|
|
241
|
+
backend column is `varchar(5)` (`str` in the model) and the router
|
|
242
|
+
refuses a day the month can't have as a 422 on the field (the pattern
|
|
243
|
+
alone lets `02-30` through). Values typed before as free text are
|
|
244
|
+
rewritten to `'MM-DD'` by a migration; one it can't read stays as
|
|
245
|
+
written, and the field shows it as written with nothing picked, refused
|
|
246
|
+
until a day is picked.
|
|
247
|
+
|
|
228
248
|
**An image on a record** (a photo of it) is the stored file's id on the
|
|
229
249
|
wire (`string`, nullable), and on the form the foundation's
|
|
230
250
|
`ImageField` in a `Controller` (`z.string().nullable()`): `value` and
|
|
@@ -26,19 +26,19 @@
|
|
|
26
26
|
- [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 598–681
|
|
27
27
|
- [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 683–718
|
|
28
28
|
- [17. Quick action on the view](#17-quick-action-on-the-view) · lines 720–793
|
|
29
|
-
- [18. Editable value](#18-editable-value) · lines 795–
|
|
30
|
-
- [Presets: one line per field](#presets-one-line-per-field) · lines 1080–
|
|
31
|
-
- [Several fields edited as one](#several-fields-edited-as-one) · lines
|
|
32
|
-
- [A link and its label](#a-link-and-its-label) · lines
|
|
33
|
-
- [A list of sub-items](#a-list-of-sub-items) · lines
|
|
34
|
-
- [In a table's rows](#in-a-tables-rows) · lines
|
|
35
|
-
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines
|
|
36
|
-
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines
|
|
37
|
-
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines
|
|
38
|
-
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines
|
|
39
|
-
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines
|
|
40
|
-
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines
|
|
41
|
-
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines
|
|
29
|
+
- [18. Editable value](#18-editable-value) · lines 795–1436
|
|
30
|
+
- [Presets: one line per field](#presets-one-line-per-field) · lines 1080–1138
|
|
31
|
+
- [Several fields edited as one](#several-fields-edited-as-one) · lines 1140–1176
|
|
32
|
+
- [A link and its label](#a-link-and-its-label) · lines 1178–1202
|
|
33
|
+
- [A list of sub-items](#a-list-of-sub-items) · lines 1204–1337
|
|
34
|
+
- [In a table's rows](#in-a-tables-rows) · lines 1339–1424
|
|
35
|
+
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1426–1436
|
|
36
|
+
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1438–1504
|
|
37
|
+
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1506–1570
|
|
38
|
+
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1572–1670
|
|
39
|
+
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1672–1700
|
|
40
|
+
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1702–1778
|
|
41
|
+
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1780–1803
|
|
42
42
|
|
|
43
43
|
<!-- /index -->
|
|
44
44
|
|
|
@@ -1094,6 +1094,7 @@ fields: [
|
|
|
1094
1094
|
{ label: 'Hours', edit: inPlace.number({ value: project.hours, min: 0, max: 200, unit: 'h', save: (hours) => save({ hours }) }) },
|
|
1095
1095
|
{ label: 'Budget', edit: inPlace.money({ value: project.budget, save: (budget) => save({ budget }) }) },
|
|
1096
1096
|
{ label: 'Due', edit: inPlace.date({ value: project.due, required: true, save: (due) => save({ due }) }) },
|
|
1097
|
+
{ label: 'Renews on', edit: inPlace.monthDay({ value: project.renewsOn, save: (renewsOn) => save({ renewsOn }) }) },
|
|
1097
1098
|
{ label: 'Priority', edit: inPlace.select({ value: project.priority, options: PRIORITY_OPTIONS,
|
|
1098
1099
|
render: (priority, label) => <Badge variant={PRIORITY_BADGE[priority]}>{label}</Badge>,
|
|
1099
1100
|
save: (priority) => save({ priority }) }) },
|
|
@@ -1116,12 +1117,13 @@ fields: [
|
|
|
1116
1117
|
| `number` | `1,234 h` (`unit`) | a number; blank is `null` | not a number, under `min`, over `max`, a fraction with `integer` |
|
|
1117
1118
|
| `money` | `$1,234.56` (`currency`, `locale`) | the API's decimal string, two places (`"1234.50"`), built from the digits, never a float; `$` and commas typed are fine | a third decimal, words, under `min` (0 by default), over `max` |
|
|
1118
1119
|
| `date` | `Sep 2, 2026` | `'YYYY-MM-DD'`; Clear is `null` | Clear when `required` |
|
|
1120
|
+
| `monthDay` | `Mar 14` (`format`, `locale`); a stored value that isn't a day, as written | `'MM-DD'`, no year; February 29 is a day; Clear is `null` | Clear when `required`, a day the month can't have ("February has 29 days") |
|
|
1119
1121
|
| `select` | the option's label, or its `render` (a badge) | the option's value; "Not set" is `null` | "Not set" isn't offered when `required` |
|
|
1120
1122
|
| `reference` | the record's `label` (the view's lookup by id) | the picked record's id | "Not set" isn't offered when `required` |
|
|
1121
1123
|
|
|
1122
1124
|
- **They save the way their kind does** (the table above): `text`,
|
|
1123
|
-
`number` and `money` on Enter or leaving them, `date`, `
|
|
1124
|
-
`reference` on the pick (the list opens with the field).
|
|
1125
|
+
`number` and `money` on Enter or leaving them, `date`, `monthDay`,
|
|
1126
|
+
`select` and `reference` on the pick (the list opens with the field).
|
|
1125
1127
|
`required: true` types the save without `null`.
|
|
1126
1128
|
- **`reference` searches through the app.** The package knows no
|
|
1127
1129
|
endpoint: `search(text)` is the app's (its gateway's search by name,
|
|
@@ -1157,6 +1159,10 @@ value and save in one PATCH: `inPlace.fields`.
|
|
|
1157
1159
|
table above, with its own `label`), side by side under a small caption
|
|
1158
1160
|
of its label, and stacked when the row is narrow. At rest the parts
|
|
1159
1161
|
read joined by " · " ("Small · Low"), or as `shown`.
|
|
1162
|
+
- **A yearly range** is two `monthDay` parts (`{ kind: 'monthDay',
|
|
1163
|
+
label: 'From' }`, `'By'`). The package sets no rule across them: a
|
|
1164
|
+
range can run over New Year (Nov 1 to Feb 28), so "by after from" is
|
|
1165
|
+
the app's `rule` if it holds for its data.
|
|
1160
1166
|
- **Nothing saves until they agree.** Picking a part doesn't save it:
|
|
1161
1167
|
the pair saves on leaving it or Ctrl/Cmd+Enter (and on Enter too when
|
|
1162
1168
|
every part is typed into: numbers, money, text). Esc gives up both.
|
|
@@ -15,22 +15,22 @@
|
|
|
15
15
|
- [Depth ramps](#depth-ramps) · lines 408–486
|
|
16
16
|
- [A stored colour](#a-stored-colour) · lines 488–536
|
|
17
17
|
- [Shapes and sizes](#shapes-and-sizes) · lines 538–559
|
|
18
|
-
- [Typography](#typography) · lines 561–
|
|
19
|
-
- [Written text (notes)](#written-text-notes) · lines 595–
|
|
20
|
-
- [Density](#density) · lines
|
|
21
|
-
- [Rows on this device](#rows-on-this-device) · lines
|
|
22
|
-
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines
|
|
23
|
-
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines
|
|
24
|
-
- [Notices](#notices) · lines
|
|
25
|
-
- [A value over time](#a-value-over-time) · lines
|
|
26
|
-
- [Several values over time](#several-values-over-time) · lines
|
|
27
|
-
- [A list as a board](#a-list-as-a-board) · lines
|
|
28
|
-
- [A list as cards](#a-list-as-cards) · lines
|
|
29
|
-
- [Key numbers on a record](#key-numbers-on-a-record) · lines
|
|
30
|
-
- [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines
|
|
31
|
-
- [Picking at random](#picking-at-random) · lines
|
|
32
|
-
- [Filling in what's missing](#filling-in-whats-missing) · lines
|
|
33
|
-
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines
|
|
18
|
+
- [Typography](#typography) · lines 561–681
|
|
19
|
+
- [Written text (notes)](#written-text-notes) · lines 595–681
|
|
20
|
+
- [Density](#density) · lines 683–769
|
|
21
|
+
- [Rows on this device](#rows-on-this-device) · lines 742–769
|
|
22
|
+
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 771–885
|
|
23
|
+
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 887–964
|
|
24
|
+
- [Notices](#notices) · lines 966–994
|
|
25
|
+
- [A value over time](#a-value-over-time) · lines 996–1082
|
|
26
|
+
- [Several values over time](#several-values-over-time) · lines 1045–1082
|
|
27
|
+
- [A list as a board](#a-list-as-a-board) · lines 1084–1135
|
|
28
|
+
- [A list as cards](#a-list-as-cards) · lines 1137–1183
|
|
29
|
+
- [Key numbers on a record](#key-numbers-on-a-record) · lines 1185–1207
|
|
30
|
+
- [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1209–1253
|
|
31
|
+
- [Picking at random](#picking-at-random) · lines 1255–1286
|
|
32
|
+
- [Filling in what's missing](#filling-in-whats-missing) · lines 1288–1355
|
|
33
|
+
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1357–1382
|
|
34
34
|
|
|
35
35
|
<!-- /index -->
|
|
36
36
|
|
|
@@ -627,6 +627,16 @@ puts the text's own highest heading at `headingLevel` instead, the rest
|
|
|
627
627
|
keeping their distance from it (the editor reads it from the text it
|
|
628
628
|
opens with). The text isn't rewritten.
|
|
629
629
|
|
|
630
|
+
A column in a written table can have a width: dragged at its right edge
|
|
631
|
+
in `RichTextEditor` (the edge catches on 96, 160, 256 and 384px, 56px at
|
|
632
|
+
least), a column's menu has Narrower, Wider, Fit to content and Fit all
|
|
633
|
+
columns, and a double-click on the edge fits it again. The width is kept
|
|
634
|
+
in the Markdown as a comment after the table, naming its columns
|
|
635
|
+
(`<!-- table widths: Item=140, Cost=72 -->`), which `<Markdown>` and the
|
|
636
|
+
editor read and never show. A column named nowhere fits its words. A
|
|
637
|
+
phone ignores the widths and can't set them; on paper they scale to the
|
|
638
|
+
page.
|
|
639
|
+
|
|
630
640
|
A table wider than the text scrolls sideways. While it does, its box is a
|
|
631
641
|
tab stop and a region named "Table, scrolls sideways: " and its first
|
|
632
642
|
columns ("Item, Size, Colour, …"), so two such tables keep distinct
|
|
@@ -53,6 +53,8 @@ One or two sentences: what one record is, and who uses the screens.
|
|
|
53
53
|
check).
|
|
54
54
|
- *From the package, no Widget example:* `date` (a calendar day, no
|
|
55
55
|
time: OpenAPI `format: date`; the foundation's `DateField`; say
|
|
56
|
+
whether it's optional), `month-day` (a day that comes round every
|
|
57
|
+
year, no year: `'MM-DD'`; the foundation's `MonthDayField`; say
|
|
56
58
|
whether it's optional).
|
|
57
59
|
- *Not supported yet:* a yes/no that can also be unset (three states),
|
|
58
60
|
file, and anything else.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
+
import { type MonthDay } from '../../lib/month-day.js';
|
|
2
3
|
import { type PlainDate } from '../../lib/plain-date.js';
|
|
3
4
|
import type { EditInPlace } from './edit-in-place.js';
|
|
4
5
|
/** What the value saves as: with `required: true` never `null` (a blank is refused). */
|
|
@@ -58,6 +59,18 @@ export type InPlaceDateConfig<TRequired extends boolean = boolean> = {
|
|
|
58
59
|
locale?: string;
|
|
59
60
|
placeholder?: string;
|
|
60
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* A month and day with no year, `'MM-DD'` (MonthDayField): something that
|
|
64
|
+
* comes round every year. Not `required`: Clear saves `null`. February 29
|
|
65
|
+
* is a day; a stored `'02-30'` is refused ("February has 29 days").
|
|
66
|
+
*/
|
|
67
|
+
export type InPlaceMonthDayConfig<TRequired extends boolean = boolean> = {
|
|
68
|
+
required?: TRequired;
|
|
69
|
+
/** How the day reads. Defaults to `{ month: 'short', day: 'numeric' }` ("Mar 14"). */
|
|
70
|
+
format?: Pick<Intl.DateTimeFormatOptions, 'month' | 'day'>;
|
|
71
|
+
locale?: string;
|
|
72
|
+
placeholder?: string;
|
|
73
|
+
};
|
|
61
74
|
/** One option of a select: its value and its words. */
|
|
62
75
|
export type InPlaceOption<T> = {
|
|
63
76
|
value: T;
|
|
@@ -121,6 +134,9 @@ export type InPlacePart = ({
|
|
|
121
134
|
kind: 'date';
|
|
122
135
|
label: string;
|
|
123
136
|
} & InPlaceDateConfig) | ({
|
|
137
|
+
kind: 'monthDay';
|
|
138
|
+
label: string;
|
|
139
|
+
} & InPlaceMonthDayConfig) | ({
|
|
124
140
|
kind: 'select';
|
|
125
141
|
label: string;
|
|
126
142
|
} & InPlaceSelectConfig<any>) | ({
|
|
@@ -163,6 +179,12 @@ export declare const inPlace: {
|
|
|
163
179
|
money<R extends boolean = false>(options: Common<string | number | null | undefined, InPlaceSaved<string, R>> & InPlaceMoneyConfig<R>): EditInPlace;
|
|
164
180
|
/** A plain day (`'YYYY-MM-DD'`) in DateField's calendar, which opens with the field; a pick saves. */
|
|
165
181
|
date<R extends boolean = false>(options: Common<PlainDate | null | undefined, InPlaceSaved<PlainDate, R>> & InPlaceDateConfig<R>): EditInPlace;
|
|
182
|
+
/**
|
|
183
|
+
* A month and day with no year (`'MM-DD'`, every year's March 14) in
|
|
184
|
+
* MonthDayField's picker, which opens with the field; a pick saves.
|
|
185
|
+
* Reads as "Mar 14"; February 29 is a day, February 30 is refused.
|
|
186
|
+
*/
|
|
187
|
+
monthDay<R extends boolean = false>(options: Common<MonthDay | null | undefined, InPlaceSaved<MonthDay, R>> & InPlaceMonthDayConfig<R>): EditInPlace;
|
|
166
188
|
/** One of a fixed list; its list opens with the field and a pick saves. */
|
|
167
189
|
select<T extends string | number, R extends boolean = false>(options: Common<T | null | undefined, InPlaceSaved<T, R>> & InPlaceSelectConfig<T, R>): EditInPlace;
|
|
168
190
|
/** Another record, searched as you type through the app's `search`; a pick saves its id. */
|
|
@@ -3,8 +3,10 @@ import { Input } from '../ui/input.js';
|
|
|
3
3
|
import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from '../ui/input-group.js';
|
|
4
4
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select.js';
|
|
5
5
|
import { linkHost, linkRule } from '../../lib/link-href.js';
|
|
6
|
+
import { formatMonthDay, monthDayProblem } from '../../lib/month-day.js';
|
|
6
7
|
import { formatPlainDate } from '../../lib/plain-date.js';
|
|
7
8
|
import { DateField } from './date-field.js';
|
|
9
|
+
import { MonthDayField } from './month-day-field.js';
|
|
8
10
|
import { NONE, Parts, ReferencePicker } from './edit-in-place-controls.js';
|
|
9
11
|
import { LinkOut } from './row-edit-cells.js';
|
|
10
12
|
const REQUIRED = 'Required';
|
|
@@ -133,6 +135,29 @@ function dateKind(config) {
|
|
|
133
135
|
: undefined, "aria-label": props.label, "aria-describedby": props.describedBy })),
|
|
134
136
|
};
|
|
135
137
|
}
|
|
138
|
+
function monthDayKind(config) {
|
|
139
|
+
return {
|
|
140
|
+
editKind: 'choice',
|
|
141
|
+
toDraft: (value) => value ?? '',
|
|
142
|
+
check: (draft) => {
|
|
143
|
+
if (draft === '')
|
|
144
|
+
return config.required ? { ok: false, message: REQUIRED } : { ok: true, value: null };
|
|
145
|
+
const problem = monthDayProblem(draft, config.locale);
|
|
146
|
+
return problem ? { ok: false, message: problem } : { ok: true, value: draft };
|
|
147
|
+
},
|
|
148
|
+
// A stored value that isn't a day of the year reads as written.
|
|
149
|
+
show: (value) => (value ? formatMonthDay(value, config.format, config.locale) || value : null),
|
|
150
|
+
control: (props, alone) => (_jsx(MonthDayField, { id: props.id, value: props.value,
|
|
151
|
+
// Alone, a pick saves and the picker opens with the field; closing
|
|
152
|
+
// it with nothing picked gives up (a pick has already saved by then).
|
|
153
|
+
onChange: alone ? (day) => props.commit(day) : props.onChange, clearable: !config.required, placeholder: config.placeholder, format: config.format, locale: config.locale, invalid: props.invalid, readOnly: props.disabled, defaultOpen: alone, modal: alone ? false : undefined, onOpenChange: alone
|
|
154
|
+
? (open) => {
|
|
155
|
+
if (!open)
|
|
156
|
+
props.cancel();
|
|
157
|
+
}
|
|
158
|
+
: undefined, "aria-label": props.label, "aria-describedby": props.describedBy })),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
136
161
|
function selectKind(config) {
|
|
137
162
|
const labelOf = (value) => config.options.find((option) => option.value === value)?.label ?? String(value);
|
|
138
163
|
const shownOf = (value) => (config.render ? config.render(value, labelOf(value)) : labelOf(value));
|
|
@@ -198,6 +223,8 @@ function kindOf(part) {
|
|
|
198
223
|
return moneyKind(part);
|
|
199
224
|
case 'date':
|
|
200
225
|
return dateKind(part);
|
|
226
|
+
case 'monthDay':
|
|
227
|
+
return monthDayKind(part);
|
|
201
228
|
case 'select':
|
|
202
229
|
return selectKind(part);
|
|
203
230
|
case 'reference':
|
|
@@ -378,6 +405,14 @@ export const inPlace = {
|
|
|
378
405
|
date(options) {
|
|
379
406
|
return single(dateKind(options), { ...options, value: options.value || null });
|
|
380
407
|
},
|
|
408
|
+
/**
|
|
409
|
+
* A month and day with no year (`'MM-DD'`, every year's March 14) in
|
|
410
|
+
* MonthDayField's picker, which opens with the field; a pick saves.
|
|
411
|
+
* Reads as "Mar 14"; February 29 is a day, February 30 is refused.
|
|
412
|
+
*/
|
|
413
|
+
monthDay(options) {
|
|
414
|
+
return single(monthDayKind(options), { ...options, value: options.value || null });
|
|
415
|
+
},
|
|
381
416
|
/** One of a fixed list; its list opens with the field and a pick saves. */
|
|
382
417
|
select(options) {
|
|
383
418
|
return single(selectKind(options), { ...options, value: options.value ?? null });
|
|
@@ -7,7 +7,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
7
7
|
// Safe by default, and kept that way on purpose:
|
|
8
8
|
// - Raw HTML is never rendered. react-markdown escapes it, so `<b>` in the
|
|
9
9
|
// text shows as the characters `<b>`, never as markup, and nothing the
|
|
10
|
-
// author typed silently disappears. Never add rehype-raw.
|
|
10
|
+
// author typed silently disappears. Never add rehype-raw. The one thing
|
|
11
|
+
// taken out is a table's widths comment, read as its column widths.
|
|
11
12
|
// - URLs go through react-markdown's default urlTransform, which drops
|
|
12
13
|
// `javascript:` and other unsafe protocols. A link left with no URL
|
|
13
14
|
// renders as its text.
|
|
@@ -28,6 +29,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
28
29
|
// (`tableLook`, as on RichTextEditor: styles/index.css "Tables in written
|
|
29
30
|
// text"). A cell whose whole text is one highlight is painted in it, and
|
|
30
31
|
// a first column of bold cells is row headers (src/lib/markdown-table.ts).
|
|
32
|
+
// A column the rich-text editor set a width for keeps it, from the comment
|
|
33
|
+
// after the table (src/lib/markdown-table-widths.ts); on a phone columns
|
|
34
|
+
// still fit their words, and on paper the widths scale to the page.
|
|
31
35
|
// A table wider than the text scrolls sideways, and while it does, its
|
|
32
36
|
// box is a tab stop, named for its columns, that the arrow keys scroll
|
|
33
37
|
// (prose-table-scroll.ts). Its cells wrap first, so that's only a table
|
|
@@ -88,6 +92,7 @@ import { rehypeFold, toggleFold } from '../../lib/markdown-fold.js';
|
|
|
88
92
|
import { rehypeInline } from '../../lib/markdown-inline.js';
|
|
89
93
|
import { isHighlightColor, remarkHighlights } from '../../lib/markdown-highlight.js';
|
|
90
94
|
import { rehypeTables } from '../../lib/markdown-table.js';
|
|
95
|
+
import { remarkTableWidths } from '../../lib/markdown-table-widths.js';
|
|
91
96
|
import { remarkToggleHeadings } from '../../lib/markdown-toggle.js';
|
|
92
97
|
import { toggleTaskAt } from '../../lib/markdown-tasks.js';
|
|
93
98
|
import { textTopHeading } from '../../lib/markdown-top-heading.js';
|
|
@@ -95,7 +100,7 @@ import { CALLOUT_BOX, CALLOUT_LOOK, DEFAULT_HEADING_LEVEL, FOLD_BUTTON, FOLD_HEA
|
|
|
95
100
|
import { PageLinkView } from './page-link.js';
|
|
96
101
|
import { usePrinting } from './print-context.js';
|
|
97
102
|
import { headerTexts, TABLE_SCROLL_FOCUS, watchTableScroll } from './prose-table-scroll.js';
|
|
98
|
-
const REMARK_PLUGINS = [remarkGfm, remarkCallouts, remarkHighlights, remarkToggleHeadings];
|
|
103
|
+
const REMARK_PLUGINS = [remarkGfm, remarkCallouts, remarkHighlights, remarkToggleHeadings, remarkTableWidths];
|
|
99
104
|
const HIGHLIGHT_WASH = {
|
|
100
105
|
amber: 'bg-highlight-amber',
|
|
101
106
|
yellow: 'bg-highlight-yellow',
|
|
@@ -11,7 +11,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
11
11
|
// - No HTML in, ever. The preset's "preserve empty line" plugin is left
|
|
12
12
|
// out: it writes an empty paragraph as a raw `<br />`. Raw HTML already
|
|
13
13
|
// in the text shows as its characters (an uneditable chip, Milkdown's
|
|
14
|
-
// html node), and HTML pasted as such a chip becomes plain text.
|
|
14
|
+
// html node), and HTML pasted as such a chip becomes plain text. The
|
|
15
|
+
// one thing it writes is the comment after a table that keeps its column
|
|
16
|
+
// widths (src/lib/markdown-table-widths.ts).
|
|
15
17
|
// - Headings render from <h3>, like <Markdown>: the page owns <h1> and
|
|
16
18
|
// <h2>. `headingLevel` moves them to where the field sits in the page's
|
|
17
19
|
// outline, as it does <Markdown>'s; only the element moves, never the
|
|
@@ -27,7 +29,10 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
27
29
|
// on the column and one on the row the pointer or the caret is in, each
|
|
28
30
|
// a menu to insert, move, delete, align, sort and colour
|
|
29
31
|
// (rich-text-table-grips.tsx); right-click or Shift+F10 in a cell opens
|
|
30
|
-
// the cell's.
|
|
32
|
+
// the cell's. A column's right edge drags to a width (double-click:
|
|
33
|
+
// back to fit its words), and the menus hold Narrower, Wider and Fit to
|
|
34
|
+
// content; none of that on a phone, which fits columns to their words.
|
|
35
|
+
// Tab in the last cell adds a row and Enter goes down a
|
|
31
36
|
// column (rich-text-table.ts). Colours and a header column are kept as
|
|
32
37
|
// Markdown writes them (src/lib/markdown-table.ts).
|
|
33
38
|
// - Edited blocks are written in the document's own bullet and rule marks.
|
|
@@ -72,7 +77,7 @@ import { useInRouterContext, useNavigate } from 'react-router';
|
|
|
72
77
|
import { defaultValueCtx, Editor, editorViewCtx, editorViewOptionsCtx, parserCtx, remarkStringifyOptionsCtx, rootCtx, schemaCtx, serializerCtx, } from '@milkdown/kit/core';
|
|
73
78
|
import { history } from '@milkdown/kit/plugin/history';
|
|
74
79
|
import { commands, headingSchema, inputRules, keymap, markInputRules, plugins, remarkPreserveEmptyLinePlugin, schema, } from '@milkdown/kit/preset/commonmark';
|
|
75
|
-
import { gfm } from '@milkdown/kit/preset/gfm';
|
|
80
|
+
import { gfm, tableCellSchema, tableHeaderSchema, tableSchema } from '@milkdown/kit/preset/gfm';
|
|
76
81
|
import { Fragment, Slice } from '@milkdown/kit/prose/model';
|
|
77
82
|
import { NodeSelection, Plugin, TextSelection } from '@milkdown/kit/prose/state';
|
|
78
83
|
import { isInTable, TableMap } from '@milkdown/kit/prose/tables';
|
|
@@ -91,6 +96,7 @@ import { restorePage } from './page-restore.js';
|
|
|
91
96
|
import { insertPageLink, pageLinkInfo, pageLinksPlugin, pendingPagePlugin, refreshPageLinks, setPendingPage, } from './rich-text-page-links.js';
|
|
92
97
|
import { passEscapeThrough } from './escape-passthrough.js';
|
|
93
98
|
import { calloutHandler, remarkCalloutNodes } from '../../lib/markdown-callout.js';
|
|
99
|
+
import { formatTableWidths, remarkTableWidths } from '../../lib/markdown-table-widths.js';
|
|
94
100
|
import { DEFAULT_HIGHLIGHT, highlightHandler, isHighlightColor, remarkHighlightNodes } from '../../lib/markdown-highlight.js';
|
|
95
101
|
import { textTopHeading } from '../../lib/markdown-top-heading.js';
|
|
96
102
|
import { MarkdownMergeError, markdownStyle, mergeMarkdown } from '../../lib/markdown-merge.js';
|
|
@@ -105,7 +111,7 @@ import { droppedFiles, imageUploadPlugin, pastedImages, uploadImages, uploadPlac
|
|
|
105
111
|
import { handleShortcut } from './rich-text-shortcuts.js';
|
|
106
112
|
import { splitTaskItem, taskInputRule } from './rich-text-tasks.js';
|
|
107
113
|
import { toggleHeadingInputRule, toggleHeadingRemark, withToggle } from './rich-text-toggle-heading.js';
|
|
108
|
-
import { addRowAtEnd, colorTableCells, handleTableKey, runTableAction, tableLook as tableLookPlugin } from './rich-text-table.js';
|
|
114
|
+
import { addRowAtEnd, colorTableCells, fitAllColumns, handleTableKey, previewColumnWidth, runTableAction, setColumnWidth, tableLook as tableLookPlugin, tableWidthsOf } from './rich-text-table.js';
|
|
109
115
|
import { TABLE_MENU_EVENT, TableGrips } from './rich-text-table-grips.js';
|
|
110
116
|
import { applySlash, closeSlash, slashItems, slashOptionId, slashPlugin, slashQuery, } from './rich-text-slash.js';
|
|
111
117
|
import { RichTextSlashMenu } from './rich-text-slash-menu.js';
|
|
@@ -184,6 +190,39 @@ const highlightSchema = $markSchema('highlight', () => ({
|
|
|
184
190
|
// A table's cell colours and header column, drawn from the Markdown that
|
|
185
191
|
// keeps them (rich-text-table.ts tableLook).
|
|
186
192
|
const tableDecorations = $prose(() => tableLookPlugin());
|
|
193
|
+
// A table's column widths: read from the comment after it onto its cells
|
|
194
|
+
// (remarkTableWidths), and written back as that comment after the table,
|
|
195
|
+
// the one piece of HTML the editor writes (src/lib/markdown-table-widths.ts).
|
|
196
|
+
const tableWidthsRemark = $remark('remarkTableWidths', () => remarkTableWidths);
|
|
197
|
+
const tableWithWidths = tableSchema.extendSchema((previous) => (ctx) => {
|
|
198
|
+
const base = previous(ctx);
|
|
199
|
+
return {
|
|
200
|
+
...base,
|
|
201
|
+
toMarkdown: {
|
|
202
|
+
match: base.toMarkdown.match,
|
|
203
|
+
runner: (state, node) => {
|
|
204
|
+
base.toMarkdown.runner(state, node);
|
|
205
|
+
const { headers, widths } = tableWidthsOf(node);
|
|
206
|
+
const comment = formatTableWidths(headers, widths);
|
|
207
|
+
if (comment)
|
|
208
|
+
state.addNode('html', undefined, comment);
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
// Milkdown's own cell reader, with the width the comment put on the cell.
|
|
214
|
+
const readCell = (state, node, type) => {
|
|
215
|
+
const attrs = { alignment: node.align, colwidth: typeof node.columnWidth === 'number' ? [node.columnWidth] : null };
|
|
216
|
+
state.openNode(type, attrs).openNode(state.schema.nodes.paragraph).next(node.children).closeNode().closeNode();
|
|
217
|
+
};
|
|
218
|
+
const cellWithWidth = tableCellSchema.extendSchema((previous) => (ctx) => {
|
|
219
|
+
const base = previous(ctx);
|
|
220
|
+
return { ...base, parseMarkdown: { match: base.parseMarkdown.match, runner: readCell } };
|
|
221
|
+
});
|
|
222
|
+
const headerWithWidth = tableHeaderSchema.extendSchema((previous) => (ctx) => {
|
|
223
|
+
const base = previous(ctx);
|
|
224
|
+
return { ...base, parseMarkdown: { match: base.parseMarkdown.match, runner: readCell } };
|
|
225
|
+
});
|
|
187
226
|
function emptyImageTitles(node) {
|
|
188
227
|
if (node.type === 'image' && node.title == null)
|
|
189
228
|
node.title = '';
|
|
@@ -912,6 +951,10 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
912
951
|
.use(highlightRemark)
|
|
913
952
|
.use(highlightSchema)
|
|
914
953
|
.use(tableDecorations)
|
|
954
|
+
.use(tableWidthsRemark)
|
|
955
|
+
.use(tableWithWidths)
|
|
956
|
+
.use(cellWithWidth)
|
|
957
|
+
.use(headerWithWidth)
|
|
915
958
|
.use(imageTitles)
|
|
916
959
|
.use(history)
|
|
917
960
|
.use(changes)
|
|
@@ -1031,6 +1074,23 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1031
1074
|
colorTableCells(editorView.state, editorView.dispatch, scope, color);
|
|
1032
1075
|
editorView.focus();
|
|
1033
1076
|
};
|
|
1077
|
+
// A column's width from its edge or menu (`null`: automatic), `'all'`
|
|
1078
|
+
// every column automatic.
|
|
1079
|
+
const widthTableAt = (getPos, column, width) => {
|
|
1080
|
+
const pos = getPos();
|
|
1081
|
+
if (!editorView || pos === undefined)
|
|
1082
|
+
return;
|
|
1083
|
+
if (width === 'all')
|
|
1084
|
+
fitAllColumns(editorView.state, editorView.dispatch, pos);
|
|
1085
|
+
else
|
|
1086
|
+
setColumnWidth(editorView.state, editorView.dispatch, pos, column, width);
|
|
1087
|
+
};
|
|
1088
|
+
const previewTableWidth = (getPos, column, width) => {
|
|
1089
|
+
const tablePos = getPos();
|
|
1090
|
+
if (!editorView || tablePos === undefined)
|
|
1091
|
+
return;
|
|
1092
|
+
previewColumnWidth(editorView.state, editorView.dispatch, width === null ? null : { tablePos, column, width });
|
|
1093
|
+
};
|
|
1034
1094
|
// A callout's menu: its kind changed, or the callout taken away (its
|
|
1035
1095
|
// blocks kept). The menu gives focus back to the text.
|
|
1036
1096
|
const changeCallout = (getPos, kind) => {
|
|
@@ -1219,7 +1279,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1219
1279
|
createPortal(_jsx(TableBar, { side: "row", active: active, readOnly: readOnly, onAdd: () => addToTable(widget.getPos, 'row') }), widget.slot, `${widget.key}-row`),
|
|
1220
1280
|
createPortal(_jsx(TableBar, { side: "column", active: active, readOnly: readOnly, onAdd: () => addToTable(widget.getPos, 'column') }), widget.column, `${widget.key}-column`),
|
|
1221
1281
|
editorView &&
|
|
1222
|
-
createPortal(_jsx(TableGrips, { view: editorView, state: editorState, getPos: widget.getPos, frame: widget.frame, box: widget.box, table: widget.table, readOnly: readOnly, focused: focused, onAction: (cell, action) => runTableAt(widget.getPos, cell, action), onColor: (cell, scope, color) => colorTableAt(widget.getPos, cell, scope, color), text: textElement }), widget.grips, `${widget.key}-grips`),
|
|
1282
|
+
createPortal(_jsx(TableGrips, { view: editorView, state: editorState, getPos: widget.getPos, frame: widget.frame, box: widget.box, table: widget.table, readOnly: readOnly, focused: focused, onAction: (cell, action) => runTableAt(widget.getPos, cell, action), onColor: (cell, scope, color) => colorTableAt(widget.getPos, cell, scope, color), onWidth: (column, width) => widthTableAt(widget.getPos, column, width), onPreviewWidth: (column, width) => previewTableWidth(widget.getPos, column, width), text: textElement }), widget.grips, `${widget.key}-grips`),
|
|
1223
1283
|
];
|
|
1224
1284
|
}), slashOpen && slash && editorView && (_jsx(RichTextSlashMenu, { id: slashListId, view: editorView, at: slash.to, field: field, items: slashMatches, active: slashIndex, onHighlight: (index) => setSlashActive({ key: slashMenuKey, index }), onPick: (item) => (item === 'page' ? startPage(editorView, slash, '') : applySlash(editorView, slash, item)) })), toolsOpen && (_jsx(RichTextToolsBar, { ref: toolsRef, state: editorState, readOnly: readOnly, fullScreen: fullScreen, controls: editableId, onFormat: runFormat, onFullScreen: toggleFullScreen, onReturn: returnToText, onBlur: (event) => {
|
|
1225
1285
|
const next = event.relatedTarget;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type MonthDay } from '../../lib/month-day.js';
|
|
2
|
+
export type MonthDayFieldProps = {
|
|
3
|
+
/** The trigger button's id, for the field's `<FieldLabel htmlFor>`. */
|
|
4
|
+
id?: string;
|
|
5
|
+
/** `'MM-DD'`, or `''` for not set. */
|
|
6
|
+
value: MonthDay;
|
|
7
|
+
/** Called with the picked day as `'MM-DD'`, or `''` when cleared. */
|
|
8
|
+
onChange: (value: MonthDay) => void;
|
|
9
|
+
/** What the button says with no day set. Defaults to "Pick a day". */
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
/** Offer Clear in the picker, for an optional field. */
|
|
12
|
+
clearable?: boolean;
|
|
13
|
+
/** The value was refused: `aria-invalid` on the button. */
|
|
14
|
+
invalid?: boolean;
|
|
15
|
+
/** Saving: the button shows the day but won't open. */
|
|
16
|
+
readOnly?: boolean;
|
|
17
|
+
/** Open on mount: editing in place, where the picker opens with the field. */
|
|
18
|
+
defaultOpen?: boolean;
|
|
19
|
+
/** Passed to the Popover; `false` when editing in place, as for a Select. */
|
|
20
|
+
modal?: boolean;
|
|
21
|
+
/** Told when the picker opens or closes; editing in place gives up on a close with nothing picked. */
|
|
22
|
+
onOpenChange?: (open: boolean) => void;
|
|
23
|
+
/** How the day reads on the button. Defaults to `{ month: 'short', day: 'numeric' }` ("Mar 14"). */
|
|
24
|
+
format?: Pick<Intl.DateTimeFormatOptions, 'month' | 'day'>;
|
|
25
|
+
locale?: string;
|
|
26
|
+
className?: string;
|
|
27
|
+
'aria-label'?: string;
|
|
28
|
+
'aria-labelledby'?: string;
|
|
29
|
+
'aria-describedby'?: string;
|
|
30
|
+
};
|
|
31
|
+
export declare function MonthDayField({ id, value, onChange, placeholder, clearable, invalid, readOnly, defaultOpen, modal, onOpenChange, format, locale, className, ...aria }: MonthDayFieldProps): import("react").JSX.Element;
|