@slashsuite/ui-react 0.12.1 → 0.13.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/MIGRATING.md +386 -8
- package/README.md +89 -44
- package/agent-docs/components/app-shell.md +9 -6
- package/agent-docs/components/article-layout.md +140 -0
- package/agent-docs/components/audio.md +42 -0
- package/agent-docs/components/badge.md +2 -1
- package/agent-docs/components/body-text.md +26 -15
- package/agent-docs/components/bottom-sheet.md +27 -17
- package/agent-docs/components/breadcrumbs.md +10 -6
- package/agent-docs/components/button.md +2 -2
- package/agent-docs/components/call-to-action.md +59 -0
- package/agent-docs/components/callout.md +4 -3
- package/agent-docs/components/card-grid.md +15 -7
- package/agent-docs/components/card.md +33 -18
- package/agent-docs/components/cart-button.md +63 -0
- package/agent-docs/components/chat-composer.md +4 -3
- package/agent-docs/components/checkbox.md +11 -5
- package/agent-docs/components/cluster.md +10 -8
- package/agent-docs/components/code-example.md +2 -2
- package/agent-docs/components/code.md +7 -5
- package/agent-docs/components/colour-scheme-toggle.md +12 -6
- package/agent-docs/components/colour-swatch.md +41 -0
- package/agent-docs/components/combobox.md +88 -0
- package/agent-docs/components/confirm-dialog.md +98 -0
- package/agent-docs/components/container.md +2 -1
- package/agent-docs/components/copy-button.md +7 -5
- package/agent-docs/components/copy-line.md +6 -5
- package/agent-docs/components/date-field.md +14 -11
- package/agent-docs/components/date-range-picker.md +16 -9
- package/agent-docs/components/date-time-field.md +73 -0
- package/agent-docs/components/dialog.md +22 -68
- package/agent-docs/components/disclosure.md +4 -0
- package/agent-docs/components/docs-layout.md +10 -6
- package/agent-docs/components/drawer.md +13 -4
- package/agent-docs/components/embed-frame.md +48 -0
- package/agent-docs/components/empty-state.md +4 -1
- package/agent-docs/components/field-dialog.md +6 -5
- package/agent-docs/components/field.md +10 -7
- package/agent-docs/components/fieldset.md +4 -4
- package/agent-docs/components/flow-diagram.md +87 -0
- package/agent-docs/components/form-layout.md +4 -1
- package/agent-docs/components/form-row.md +7 -7
- package/agent-docs/components/full-bleed-layout.md +0 -2
- package/agent-docs/components/headings.md +13 -7
- package/agent-docs/components/hero.md +11 -2
- package/agent-docs/components/icon-button.md +1 -3
- package/agent-docs/components/icon.md +6 -13
- package/agent-docs/components/image.md +24 -14
- package/agent-docs/components/input.md +8 -7
- package/agent-docs/components/key-value-list.md +4 -1
- package/agent-docs/components/lightbox.md +1 -1
- package/agent-docs/components/list-layout.md +5 -7
- package/agent-docs/components/list-row.md +37 -34
- package/agent-docs/components/loading.md +2 -2
- package/agent-docs/components/markdown.md +13 -13
- package/agent-docs/components/media-tile.md +8 -4
- package/agent-docs/components/menu.md +19 -12
- package/agent-docs/components/meta-list.md +2 -2
- package/agent-docs/components/morph.md +11 -5
- package/agent-docs/components/navigation-progress.md +2 -2
- package/agent-docs/components/number-field.md +75 -0
- package/agent-docs/components/outline-region.md +19 -8
- package/agent-docs/components/page-fade.md +2 -1
- package/agent-docs/components/pill.md +7 -6
- package/agent-docs/components/popover.md +63 -0
- package/agent-docs/components/price.md +49 -0
- package/agent-docs/components/product-tile.md +78 -0
- package/agent-docs/components/promo-banner.md +46 -0
- package/agent-docs/components/prose-layout.md +1 -1
- package/agent-docs/components/radio-group.md +9 -6
- package/agent-docs/components/scroll-strip.md +3 -3
- package/agent-docs/components/segmented-control.md +4 -2
- package/agent-docs/components/select.md +8 -3
- package/agent-docs/components/show.md +2 -2
- package/agent-docs/components/side-column.md +13 -9
- package/agent-docs/components/sidebar-layout.md +1 -1
- package/agent-docs/components/site-footer.md +4 -4
- package/agent-docs/components/site-search.md +21 -9
- package/agent-docs/components/slider.md +59 -0
- package/agent-docs/components/sortable-list.md +15 -10
- package/agent-docs/components/stack.md +3 -3
- package/agent-docs/components/stacked-bar.md +7 -4
- package/agent-docs/components/state-machine.md +95 -0
- package/agent-docs/components/status-pages.md +13 -6
- package/agent-docs/components/stepper.md +54 -0
- package/agent-docs/components/switch.md +4 -4
- package/agent-docs/components/table-of-contents.md +78 -0
- package/agent-docs/components/table.md +35 -24
- package/agent-docs/components/tabs.md +24 -26
- package/agent-docs/components/text-link.md +12 -7
- package/agent-docs/components/textarea.md +4 -2
- package/agent-docs/components/toast.md +19 -14
- package/agent-docs/components/video.md +7 -2
- package/agent-docs/llms.txt +22 -3
- package/dist/AppShell.d.ts +25 -9
- package/dist/AppShell.js +67 -33
- package/dist/AppShellMenu.d.ts +31 -18
- package/dist/AppShellMenu.js +72 -45
- package/dist/ArticleLayout.d.ts +36 -0
- package/dist/ArticleLayout.js +27 -0
- package/dist/Audio.d.ts +16 -0
- package/dist/Audio.js +11 -0
- package/dist/Badge.d.ts +2 -1
- package/dist/Badge.js +3 -2
- package/dist/BottomSheet.d.ts +17 -6
- package/dist/BottomSheet.js +62 -11
- package/dist/Breadcrumbs.d.ts +8 -6
- package/dist/Breadcrumbs.js +17 -7
- package/dist/Button.d.ts +1 -0
- package/dist/Button.js +4 -3
- package/dist/CallToAction.d.ts +25 -0
- package/dist/CallToAction.js +17 -0
- package/dist/Callout.d.ts +2 -2
- package/dist/Callout.js +2 -2
- package/dist/Card.d.ts +88 -31
- package/dist/Card.js +55 -92
- package/dist/CardBody.d.ts +2 -0
- package/dist/CardBody.js +33 -3
- package/dist/CardGrid.d.ts +32 -4
- package/dist/CardGrid.js +42 -8
- package/dist/CardParts.d.ts +7 -1
- package/dist/CardParts.js +7 -2
- package/dist/CartButton.d.ts +33 -0
- package/dist/CartButton.js +18 -0
- package/dist/ChatComposer.d.ts +10 -4
- package/dist/ChatComposer.js +35 -13
- package/dist/Checkbox.d.ts +21 -3
- package/dist/Checkbox.js +66 -20
- package/dist/Chevron.js +1 -1
- package/dist/Cluster.d.ts +28 -15
- package/dist/Cluster.js +21 -4
- package/dist/Code.d.ts +15 -3
- package/dist/Code.js +23 -3
- package/dist/CodeBlock.d.ts +4 -4
- package/dist/CodeBlock.js +2 -2
- package/dist/CodeBody.d.ts +1 -1
- package/dist/CodeBody.js +4 -10
- package/dist/CodeExample.d.ts +1 -1
- package/dist/CodeExample.js +3 -2
- package/dist/ColourSchemeToggle.d.ts +21 -5
- package/dist/ColourSchemeToggle.js +15 -9
- package/dist/ColourSwatch.d.ts +15 -0
- package/dist/ColourSwatch.js +14 -0
- package/dist/Combobox.d.ts +42 -0
- package/dist/Combobox.js +43 -0
- package/dist/ConfirmDialog.d.ts +40 -0
- package/dist/ConfirmDialog.js +36 -0
- package/dist/Container.d.ts +3 -3
- package/dist/Container.js +1 -1
- package/dist/CopyButton.d.ts +8 -2
- package/dist/CopyButton.js +38 -28
- package/dist/CopyLine.d.ts +4 -2
- package/dist/CopyLine.js +4 -4
- package/dist/DateCalendar.d.ts +2 -0
- package/dist/DateCalendar.js +11 -9
- package/dist/DateField.d.ts +52 -21
- package/dist/DateField.js +73 -37
- package/dist/DateFieldCalendar.d.ts +12 -8
- package/dist/DateFieldCalendar.js +37 -18
- package/dist/DateRangePicker.d.ts +23 -3
- package/dist/DateRangePicker.js +10 -8
- package/dist/DateTimeField.d.ts +31 -0
- package/dist/DateTimeField.js +19 -0
- package/dist/Dialog.d.ts +42 -6
- package/dist/Dialog.js +50 -12
- package/dist/Disclosure.js +9 -1
- package/dist/DocsLayout.d.ts +13 -5
- package/dist/DocsLayout.js +11 -9
- package/dist/Drawer.d.ts +22 -7
- package/dist/Drawer.js +89 -8
- package/dist/EmbedFrame.d.ts +36 -0
- package/dist/EmbedFrame.js +18 -0
- package/dist/Field.d.ts +41 -4
- package/dist/Field.js +61 -25
- package/dist/FieldDialog.d.ts +8 -3
- package/dist/FieldDialog.js +19 -9
- package/dist/Fieldset.d.ts +3 -3
- package/dist/Fieldset.js +7 -9
- package/dist/FileDrop.js +2 -1
- package/dist/FlowDiagram.d.ts +92 -0
- package/dist/FlowDiagram.js +100 -0
- package/dist/FormRow.d.ts +6 -4
- package/dist/FormRow.js +11 -9
- package/dist/Hero.d.ts +30 -7
- package/dist/Hero.js +23 -9
- package/dist/Icon.d.ts +1 -1
- package/dist/Icon.js +1 -1
- package/dist/IconButton.js +1 -1
- package/dist/Image.d.ts +33 -9
- package/dist/Image.js +61 -16
- package/dist/Input.d.ts +1 -1
- package/dist/Input.js +4 -4
- package/dist/InputShell.d.ts +7 -0
- package/dist/InputShell.js +18 -3
- package/dist/KeyValueList.d.ts +2 -2
- package/dist/Lightbox.js +5 -3
- package/dist/ListRow.d.ts +4 -5
- package/dist/ListRow.js +36 -26
- package/dist/Mark.d.ts +10 -0
- package/dist/Mark.js +9 -0
- package/dist/Markdown.d.ts +18 -4
- package/dist/Markdown.js +176 -37
- package/dist/MediaTile.d.ts +9 -3
- package/dist/MediaTile.js +8 -4
- package/dist/Menu.d.ts +19 -8
- package/dist/Menu.js +13 -11
- package/dist/MetaList.d.ts +4 -3
- package/dist/MetaList.js +12 -4
- package/dist/Morph.d.ts +15 -1
- package/dist/Morph.js +70 -22
- package/dist/NavigationProgress.d.ts +2 -2
- package/dist/NavigationProgress.js +7 -5
- package/dist/NumberField.d.ts +66 -0
- package/dist/NumberField.js +68 -0
- package/dist/OutlineRegion.d.ts +41 -10
- package/dist/OutlineRegion.js +31 -6
- package/dist/PageFade.d.ts +9 -5
- package/dist/PageFade.js +39 -8
- package/dist/PageLayouts.d.ts +15 -5
- package/dist/PageLayouts.js +3 -3
- package/dist/Pill.d.ts +9 -4
- package/dist/Pill.js +15 -6
- package/dist/Popover.d.ts +31 -0
- package/dist/Popover.js +43 -0
- package/dist/Price.d.ts +21 -0
- package/dist/Price.js +34 -0
- package/dist/ProductTile.d.ts +36 -0
- package/dist/ProductTile.js +31 -0
- package/dist/ProgressBar.js +4 -2
- package/dist/PromoBanner.d.ts +25 -0
- package/dist/PromoBanner.js +16 -0
- package/dist/RadioGroup.d.ts +18 -8
- package/dist/RadioGroup.js +42 -18
- package/dist/ScrollStrip.d.ts +1 -1
- package/dist/ScrollStrip.js +1 -1
- package/dist/SearchInput.d.ts +17 -2
- package/dist/SearchInput.js +72 -13
- package/dist/SegmentedField.d.ts +15 -0
- package/dist/SegmentedField.js +15 -0
- package/dist/Select.js +5 -4
- package/dist/Show.d.ts +1 -1
- package/dist/Show.js +1 -1
- package/dist/SideColumn.d.ts +42 -15
- package/dist/SideColumn.js +45 -19
- package/dist/SiteFooter.d.ts +3 -3
- package/dist/SiteFooter.js +4 -3
- package/dist/SiteSearch.d.ts +57 -27
- package/dist/SiteSearch.js +13 -93
- package/dist/Slider.d.ts +27 -0
- package/dist/Slider.js +58 -0
- package/dist/SortableList.d.ts +19 -35
- package/dist/SortableList.js +36 -88
- package/dist/Stack.d.ts +4 -4
- package/dist/StackedBar.d.ts +13 -4
- package/dist/StackedBar.js +12 -7
- package/dist/StateMachine.d.ts +65 -0
- package/dist/StateMachine.js +113 -0
- package/dist/StatusPages.d.ts +28 -10
- package/dist/StatusPages.js +10 -10
- package/dist/Stepper.d.ts +21 -0
- package/dist/Stepper.js +33 -0
- package/dist/Steps.js +4 -3
- package/dist/Switch.d.ts +3 -3
- package/dist/Switch.js +18 -14
- package/dist/Table.d.ts +32 -9
- package/dist/Table.js +50 -20
- package/dist/TableCells.d.ts +24 -21
- package/dist/TableCells.js +68 -27
- package/dist/TableEditCell.d.ts +1 -1
- package/dist/TableOfContents.d.ts +34 -0
- package/dist/TableOfContents.js +23 -0
- package/dist/Tabs.d.ts +31 -16
- package/dist/Tabs.js +97 -22
- package/dist/TextLink.d.ts +18 -5
- package/dist/TextLink.js +19 -6
- package/dist/Textarea.d.ts +12 -1
- package/dist/Textarea.js +15 -2
- package/dist/ToastRegion.d.ts +17 -9
- package/dist/ToastRegion.js +70 -13
- package/dist/Tooltip.d.ts +10 -2
- package/dist/Tooltip.js +32 -11
- package/dist/Video.d.ts +19 -4
- package/dist/Video.js +15 -5
- package/dist/cardContext.d.ts +7 -0
- package/dist/cardContext.js +14 -0
- package/dist/cardControl.d.ts +15 -0
- package/dist/cardControl.js +32 -0
- package/dist/cardForm.d.ts +39 -0
- package/dist/cardForm.js +81 -0
- package/dist/cardWait.js +2 -1
- package/dist/colourScheme.d.ts +12 -2
- package/dist/colourScheme.js +32 -6
- package/dist/control.d.ts +30 -8
- package/dist/control.js +74 -7
- package/dist/copyScript.d.ts +7 -8
- package/dist/copyScript.js +8 -9
- package/dist/cx.d.ts +22 -3
- package/dist/cx.js +22 -3
- package/dist/dateLocale.d.ts +17 -0
- package/dist/dateLocale.js +30 -0
- package/dist/density.d.ts +15 -1
- package/dist/density.js +27 -8
- package/dist/emptySlot.d.ts +1 -0
- package/dist/fieldAnnounce.d.ts +11 -0
- package/dist/fieldAnnounce.js +36 -0
- package/dist/fieldControl.d.ts +7 -2
- package/dist/fieldControl.js +6 -2
- package/dist/fieldWait.d.ts +3 -3
- package/dist/fieldWait.js +3 -4
- package/dist/flowLayout.d.ts +68 -0
- package/dist/flowLayout.js +105 -0
- package/dist/fromXState.d.ts +73 -0
- package/dist/fromXState.js +110 -0
- package/dist/icons.d.ts +1 -1
- package/dist/icons.js +15 -0
- package/dist/index.d.ts +37 -11
- package/dist/index.js +24 -2
- package/dist/isoDate.d.ts +8 -1
- package/dist/isoDate.js +20 -1
- package/dist/labelWords.d.ts +16 -7
- package/dist/labelWords.js +14 -12
- package/dist/listRowProps.d.ts +17 -15
- package/dist/modal.d.ts +5 -0
- package/dist/modal.js +21 -1
- package/dist/navFold.js +6 -3
- package/dist/optionCard.d.ts +18 -0
- package/dist/optionCard.js +16 -0
- package/dist/scrollBody.d.ts +16 -0
- package/dist/scrollBody.js +15 -0
- package/dist/scrollEdges.d.ts +7 -0
- package/dist/scrollEdges.js +39 -5
- package/dist/scrollStop.d.ts +6 -2
- package/dist/scrollStop.js +24 -8
- package/dist/shownDate.d.ts +28 -10
- package/dist/shownDate.js +41 -22
- package/dist/siteSearchBody.d.ts +34 -0
- package/dist/siteSearchBody.js +117 -0
- package/dist/size.d.ts +7 -1
- package/dist/sortableDrop.d.ts +44 -0
- package/dist/sortableDrop.js +78 -0
- package/dist/sortableSlide.d.ts +9 -0
- package/dist/sortableSlide.js +70 -0
- package/dist/sortableTitle.d.ts +10 -0
- package/dist/sortableTitle.js +48 -0
- package/dist/stateMachineDots.d.ts +45 -0
- package/dist/stateMachineDots.js +162 -0
- package/dist/stickyColumn.d.ts +2 -2
- package/dist/stickyColumn.js +2 -2
- package/dist/switcher.d.ts +10 -5
- package/dist/switcher.js +7 -5
- package/dist/tableColumns.d.ts +17 -0
- package/dist/tableColumns.js +30 -2
- package/dist/tableEmpty.js +5 -5
- package/dist/tableRow.d.ts +26 -2
- package/dist/tableRow.js +23 -1
- package/dist/tableSort.d.ts +10 -5
- package/dist/tableSort.js +15 -4
- package/dist/target.d.ts +12 -0
- package/dist/target.js +12 -0
- package/dist/textBox.js +1 -1
- package/dist/truncated.d.ts +31 -0
- package/dist/truncated.js +51 -0
- package/dist/typography.d.ts +19 -11
- package/dist/typography.js +11 -13
- package/dist/useFlowLayout.d.ts +27 -0
- package/dist/useFlowLayout.js +119 -0
- package/package.json +3 -2
package/dist/cx.js
CHANGED
|
@@ -4,6 +4,25 @@ export function cx(...parts) {
|
|
|
4
4
|
}
|
|
5
5
|
/** The keyboard focus ring every interactive control shares. */
|
|
6
6
|
export const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-violet-600";
|
|
7
|
+
/**
|
|
8
|
+
* A heading's lines are balanced, so a two-line title does not end on one orphaned word; prose is
|
|
9
|
+
* wrapped `pretty`, which keeps a short last line off a paragraph. Only the wrap style is set, so a
|
|
10
|
+
* `lines` clamp (one line with an ellipsis) still wins; a browser that has neither wraps as before.
|
|
11
|
+
*/
|
|
12
|
+
export const balanced = "[text-wrap-style:balance]";
|
|
13
|
+
export const pretty = "[text-wrap-style:pretty]";
|
|
14
|
+
/**
|
|
15
|
+
* A fill that carries meaning (a bar's progress, the drop line, the current pill) in forced
|
|
16
|
+
* colours: there every background is painted the page's Canvas, so the fill would vanish. A system
|
|
17
|
+
* colour the page names is kept, so the fill takes the system's Highlight; `!` beats a theme's scoped remap of the stock fill.
|
|
18
|
+
*/
|
|
19
|
+
export const forcedFill = "forced-colors:bg-[color:Highlight]!";
|
|
20
|
+
/**
|
|
21
|
+
* The same ring drawn inside the control, for one that fills a box which clips anything outside
|
|
22
|
+
* it (a table's sortable title, a scroller). `focusRing` with `-outline-offset-2` added would not
|
|
23
|
+
* do, since `outline-offset-2` comes later in the CSS and wins.
|
|
24
|
+
*/
|
|
25
|
+
export const insetFocusRing = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-violet-600";
|
|
7
26
|
/**
|
|
8
27
|
* On a row or card that holds a stretched link (`link-stretch`): every interactive descendant sits
|
|
9
28
|
* above that link and is clickable on its own. `z-10` needs a position, so each gets `relative`,
|
|
@@ -13,9 +32,9 @@ export const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2
|
|
|
13
32
|
*/
|
|
14
33
|
export const liftInteractive = "isolate [&_:is(a,button,label,select,textarea,input,summary):not(.link-stretch):not(.absolute)]:relative [&_:is(a,button,label,select,textarea,input,summary):not(.link-stretch)]:z-10";
|
|
15
34
|
/**
|
|
16
|
-
* A
|
|
17
|
-
* scrolls sideways (code). `scrollbar-color` takes no Tailwind colour utility, so the thumb is the
|
|
35
|
+
* A scrollbar in the theme's muted ink instead of the native grey one, at the native width so it
|
|
36
|
+
* stays easy to grab, for a box that scrolls sideways (code). `scrollbar-color` takes no Tailwind colour utility, so the thumb is the
|
|
18
37
|
* element's own text colour (`currentColor`, a palette utility every theme remaps) and the track is
|
|
19
38
|
* transparent. The element must not hold text of its own: put the readable colour on an inner box.
|
|
20
39
|
*/
|
|
21
|
-
export const themedScrollbar = "text-slate-400 [scrollbar-
|
|
40
|
+
export const themedScrollbar = "text-slate-400 [scrollbar-color:currentColor_transparent]";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type DateValue } from "@internationalized/date";
|
|
2
|
+
import type { ReactElement, ReactNode } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* The locale a date field shows its segments, month names and messages in: `locale` when it is
|
|
5
|
+
* given, else the app's own `I18nProvider`, else the browser's.
|
|
6
|
+
*/
|
|
7
|
+
export declare function DateLocale({ locale, children, }: {
|
|
8
|
+
locale: string | undefined;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}): ReactElement;
|
|
11
|
+
/** The twelve month names in `locale`, January first. */
|
|
12
|
+
export declare function monthNames(locale: string): string[];
|
|
13
|
+
/**
|
|
14
|
+
* A date written the way its field shows it in `locale`, leading zeros and all: 15/10/2026 in
|
|
15
|
+
* en-GB, 10/15/2026 in en-US, 2026/10/15 in en-ZA. With `time`, its hours and minutes follow.
|
|
16
|
+
*/
|
|
17
|
+
export declare function shownIn(value: DateValue, locale: string, time: boolean): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DateFormatter, toCalendarDateTime } from "@internationalized/date";
|
|
3
|
+
import { I18nProvider } from "react-aria-components";
|
|
4
|
+
/**
|
|
5
|
+
* The locale a date field shows its segments, month names and messages in: `locale` when it is
|
|
6
|
+
* given, else the app's own `I18nProvider`, else the browser's.
|
|
7
|
+
*/
|
|
8
|
+
export function DateLocale({ locale, children, }) {
|
|
9
|
+
return locale ? _jsx(I18nProvider, { locale: locale, children: children }) : _jsx(_Fragment, { children: children });
|
|
10
|
+
}
|
|
11
|
+
/** The twelve month names in `locale`, January first. */
|
|
12
|
+
export function monthNames(locale) {
|
|
13
|
+
const months = new DateFormatter(locale, { month: "long", timeZone: "UTC" });
|
|
14
|
+
return Array.from({ length: 12 }, (_, i) => months.format(new Date(Date.UTC(2000, i, 1))));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A date written the way its field shows it in `locale`, leading zeros and all: 15/10/2026 in
|
|
18
|
+
* en-GB, 10/15/2026 in en-US, 2026/10/15 in en-ZA. With `time`, its hours and minutes follow.
|
|
19
|
+
*/
|
|
20
|
+
export function shownIn(value, locale, time) {
|
|
21
|
+
const clock = time ? { hour: "2-digit", minute: "2-digit" } : {};
|
|
22
|
+
const format = new DateFormatter(locale, {
|
|
23
|
+
day: "2-digit",
|
|
24
|
+
month: "2-digit",
|
|
25
|
+
year: "numeric",
|
|
26
|
+
...clock,
|
|
27
|
+
timeZone: "UTC",
|
|
28
|
+
});
|
|
29
|
+
return format.format(toCalendarDateTime(value).toDate("UTC"));
|
|
30
|
+
}
|
package/dist/density.d.ts
CHANGED
|
@@ -33,6 +33,20 @@ export declare const controlTextTables: {
|
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
35
35
|
* The type class of a control of `size` at `step`; `entry` adds the 16px floor on touch for a field
|
|
36
|
-
* a person types in. A responsive size adds its `md` size from the breakpoint up
|
|
36
|
+
* a person types in. A responsive size adds its `md` size from the breakpoint up, and the floor
|
|
37
|
+
* holds at both widths: `pointer-coarse:` comes after the breakpoints in Tailwind's order, so it
|
|
38
|
+
* wins over an `md:` size under 16px.
|
|
37
39
|
*/
|
|
38
40
|
export declare function controlText(size: Size | ResponsiveSize, step: TypeStep | undefined, entry: boolean): string;
|
|
41
|
+
/** The field type table, for the data test. */
|
|
42
|
+
export declare const fieldTypeTable: Record<"compact" | "default", {
|
|
43
|
+
label: string;
|
|
44
|
+
note: string;
|
|
45
|
+
line: string;
|
|
46
|
+
}>;
|
|
47
|
+
/** The type of a field's label and its notes at the step in force. */
|
|
48
|
+
export declare function useFieldType(): {
|
|
49
|
+
label: string;
|
|
50
|
+
note: string;
|
|
51
|
+
line: string;
|
|
52
|
+
};
|
package/dist/density.js
CHANGED
|
@@ -64,14 +64,33 @@ export const controlTextTables = {
|
|
|
64
64
|
};
|
|
65
65
|
/**
|
|
66
66
|
* The type class of a control of `size` at `step`; `entry` adds the 16px floor on touch for a field
|
|
67
|
-
* a person types in. A responsive size adds its `md` size from the breakpoint up
|
|
67
|
+
* a person types in. A responsive size adds its `md` size from the breakpoint up, and the floor
|
|
68
|
+
* holds at both widths: `pointer-coarse:` comes after the breakpoints in Tailwind's order, so it
|
|
69
|
+
* wins over an `md:` size under 16px.
|
|
68
70
|
*/
|
|
69
71
|
export function controlText(size, step, entry) {
|
|
70
|
-
|
|
71
|
-
const base = isResponsive(size) ? size.base : size;
|
|
72
|
-
const plain = `${
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
const table = CONTROL_TEXT[step ?? "default"];
|
|
73
|
+
const [base, wide] = isResponsive(size) ? [size.base, size.md] : [size, size];
|
|
74
|
+
const plain = `${table[base]} ${CONTROL_LEADING[base]}`;
|
|
75
|
+
const md = isResponsive(size)
|
|
76
|
+
? ` ${CONTROL_TEXT_MD[step ?? "default"][wide]} ${CONTROL_LEADING_MD[wide]}`
|
|
77
|
+
: "";
|
|
78
|
+
const small = [table[base], table[wide]].some((text) => !/text-(base|lg)/.test(text));
|
|
79
|
+
return `${plain}${md}${entry && small ? ` ${TOUCH_TEXT}` : ""}`;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The type of a field's words at each step: the label is the type of a `md` control (16px, 14px
|
|
83
|
+
* compact), so a label sits at the size of the text typed under it, and the notes under a control
|
|
84
|
+
* (the hint and the error) are one step below. `line` is the height of a note's first line, for the
|
|
85
|
+
* error's alert icon.
|
|
86
|
+
*/
|
|
87
|
+
const FIELD_TYPE = {
|
|
88
|
+
default: { label: "text-base", note: "text-sm", line: "h-5" },
|
|
89
|
+
compact: { label: "text-sm", note: "text-xs", line: "h-4" },
|
|
90
|
+
};
|
|
91
|
+
/** The field type table, for the data test. */
|
|
92
|
+
export const fieldTypeTable = FIELD_TYPE;
|
|
93
|
+
/** The type of a field's label and its notes at the step in force. */
|
|
94
|
+
export function useFieldType() {
|
|
95
|
+
return FIELD_TYPE[useTypeStep() ?? "default"];
|
|
77
96
|
}
|
package/dist/emptySlot.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
/** An `EmptyState`'s size: `md` a block with its heading, `sm` one muted line inside a card or a cell. */
|
|
2
3
|
export type EmptySize = "sm" | "md";
|
|
3
4
|
/** The size an `EmptyState` takes: its own, else its slot's, else `md`. */
|
|
4
5
|
export declare function useEmptySize(own: EmptySize | undefined): EmptySize;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReactNode, type ReactPortal, type RefCallback } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Announces a field's error through its page's (or dialog's) one polite live region, not a
|
|
4
|
+
* `role="alert"` of its own. Put `anchor` on the field's drawn error line: it places the field in
|
|
5
|
+
* its dialog, if any. The text leaves the region when the line unmounts. The field still draws its
|
|
6
|
+
* error in place and names it in the control's `aria-describedby`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useErrorAnnouncement(error: ReactNode): {
|
|
9
|
+
anchor: RefCallback<HTMLElement>;
|
|
10
|
+
announcement: ReactPortal | null;
|
|
11
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useState } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
/** The attribute that marks a field-error region. */
|
|
5
|
+
const REGION = "data-field-errors";
|
|
6
|
+
/**
|
|
7
|
+
* The polite live region for field errors under `host`, made on first use and shared by every field
|
|
8
|
+
* there: a hidden `<div aria-live="polite">` as the host's last child. The host is the open dialog the
|
|
9
|
+
* field sits in, or `body`: a modal dialog makes the rest of the page inert, and a screen reader
|
|
10
|
+
* does not announce a live region in inert content.
|
|
11
|
+
*/
|
|
12
|
+
function errorRegion(host) {
|
|
13
|
+
const found = host.querySelector(`:scope > [${REGION}]`);
|
|
14
|
+
if (found)
|
|
15
|
+
return found;
|
|
16
|
+
const region = document.createElement("div");
|
|
17
|
+
region.setAttribute(REGION, "");
|
|
18
|
+
region.setAttribute("aria-live", "polite");
|
|
19
|
+
region.className = "sr-only";
|
|
20
|
+
host.append(region);
|
|
21
|
+
return region;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Announces a field's error through its page's (or dialog's) one polite live region, not a
|
|
25
|
+
* `role="alert"` of its own. Put `anchor` on the field's drawn error line: it places the field in
|
|
26
|
+
* its dialog, if any. The text leaves the region when the line unmounts. The field still draws its
|
|
27
|
+
* error in place and names it in the control's `aria-describedby`.
|
|
28
|
+
*/
|
|
29
|
+
export function useErrorAnnouncement(error) {
|
|
30
|
+
const [region, setRegion] = useState(null);
|
|
31
|
+
const anchor = useCallback((node) => {
|
|
32
|
+
if (node)
|
|
33
|
+
setRegion(errorRegion(node.closest("dialog") ?? document.body));
|
|
34
|
+
}, []);
|
|
35
|
+
return { anchor, announcement: region ? createPortal(_jsx("p", { children: error }), region) : null };
|
|
36
|
+
}
|
package/dist/fieldControl.d.ts
CHANGED
|
@@ -2,22 +2,27 @@
|
|
|
2
2
|
export type FieldControlContext = {
|
|
3
3
|
/** The control's id, which the Field's label names. */
|
|
4
4
|
id: string;
|
|
5
|
-
/** The
|
|
5
|
+
/** The ids of the notes the Field draws (the hint, then the error), none when it draws neither. */
|
|
6
6
|
describedBy: string | undefined;
|
|
7
7
|
/** `true` when the Field shows an error. */
|
|
8
8
|
invalid: boolean;
|
|
9
|
+
/** `true` when the Field is `required`. */
|
|
10
|
+
required: boolean;
|
|
9
11
|
};
|
|
10
12
|
export declare const FieldContext: import("react").Context<FieldControlContext | undefined>;
|
|
11
13
|
type ControlA11y = {
|
|
12
14
|
id?: string | undefined;
|
|
13
15
|
"aria-describedby"?: string | undefined;
|
|
14
16
|
"aria-invalid"?: boolean | "true" | "false" | "grammar" | "spelling" | undefined;
|
|
17
|
+
required?: boolean | undefined;
|
|
15
18
|
};
|
|
16
19
|
/**
|
|
17
20
|
* Merges the enclosing `Field`'s id, note and invalid state into a control's own props. Inside a
|
|
18
21
|
* `Field` the id is the Field's, so its label always names the control; the caller's
|
|
19
22
|
* `aria-describedby` comes first and the Field's note after it; the caller's `aria-invalid` wins.
|
|
20
|
-
*
|
|
23
|
+
* With no error the control says `aria-invalid="false"` outright, so a browser does not read an
|
|
24
|
+
* empty required control as invalid before anyone has typed. A `required` Field makes the control
|
|
25
|
+
* `required`, unless the caller set it. Outside a `Field` it returns the props unchanged.
|
|
21
26
|
*/
|
|
22
27
|
export declare function useFieldControl(own: ControlA11y): ControlA11y;
|
|
23
28
|
export {};
|
package/dist/fieldControl.js
CHANGED
|
@@ -4,7 +4,9 @@ export const FieldContext = createContext(undefined);
|
|
|
4
4
|
* Merges the enclosing `Field`'s id, note and invalid state into a control's own props. Inside a
|
|
5
5
|
* `Field` the id is the Field's, so its label always names the control; the caller's
|
|
6
6
|
* `aria-describedby` comes first and the Field's note after it; the caller's `aria-invalid` wins.
|
|
7
|
-
*
|
|
7
|
+
* With no error the control says `aria-invalid="false"` outright, so a browser does not read an
|
|
8
|
+
* empty required control as invalid before anyone has typed. A `required` Field makes the control
|
|
9
|
+
* `required`, unless the caller set it. Outside a `Field` it returns the props unchanged.
|
|
8
10
|
*/
|
|
9
11
|
export function useFieldControl(own) {
|
|
10
12
|
const field = useContext(FieldContext);
|
|
@@ -13,12 +15,14 @@ export function useFieldControl(own) {
|
|
|
13
15
|
id: own.id,
|
|
14
16
|
"aria-describedby": own["aria-describedby"],
|
|
15
17
|
"aria-invalid": own["aria-invalid"],
|
|
18
|
+
required: own.required,
|
|
16
19
|
};
|
|
17
20
|
}
|
|
18
21
|
const describedBy = [own["aria-describedby"], field.describedBy].filter(Boolean).join(" ");
|
|
19
22
|
return {
|
|
20
23
|
id: field.id,
|
|
21
24
|
"aria-describedby": describedBy === "" ? undefined : describedBy,
|
|
22
|
-
"aria-invalid": own["aria-invalid"] ??
|
|
25
|
+
"aria-invalid": own["aria-invalid"] ?? field.invalid,
|
|
26
|
+
required: own.required ?? (field.required || undefined),
|
|
23
27
|
};
|
|
24
28
|
}
|
package/dist/fieldWait.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ReactElement, ReactNode } from "react";
|
|
2
|
-
import type { Size } from "./size.js";
|
|
2
|
+
import type { ResponsiveSize, Size } from "./size.js";
|
|
3
3
|
/** A bone the height of a text control at `size`, else the density around it (a `sm` table or card). */
|
|
4
4
|
export declare function ControlBone({ size }: {
|
|
5
|
-
size?: Size | undefined;
|
|
5
|
+
size?: Size | ResponsiveSize | undefined;
|
|
6
6
|
}): ReactElement;
|
|
7
7
|
/**
|
|
8
8
|
* A choice (a checkbox, a switch, a radio) waiting for its value: the mark a bone of its shape, the
|
|
@@ -25,6 +25,6 @@ export declare function WaitingField({ own, loadingLabel, label, look, size, att
|
|
|
25
25
|
loadingLabel: string | undefined;
|
|
26
26
|
label: ReactNode;
|
|
27
27
|
look: string;
|
|
28
|
-
size: Size | undefined;
|
|
28
|
+
size: Size | ResponsiveSize | undefined;
|
|
29
29
|
attrs: object;
|
|
30
30
|
}): ReactElement;
|
package/dist/fieldWait.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { cx } from "./cx.js";
|
|
3
|
-
import {
|
|
3
|
+
import { controlHeight } from "./control.js";
|
|
4
|
+
import { useResponsiveDensity } from "./density.js";
|
|
4
5
|
import { Bone, BusyLabel, busy, passthroughOf, useLoading } from "./skeleton.js";
|
|
5
6
|
/* The bones of a form part waiting for its value: the label is drawn, the control is a bone. */
|
|
6
|
-
/** A text control's height by `size`: its padding, line height and border, as `controlClass` draws it. */
|
|
7
|
-
const CONTROL_HEIGHT = { sm: "h-6.5", md: "h-9.5", lg: "h-11.5" };
|
|
8
7
|
/** A bone the height of a text control at `size`, else the density around it (a `sm` table or card). */
|
|
9
8
|
export function ControlBone({ size }) {
|
|
10
|
-
return _jsx(Bone, { shape: cx("block w-full rounded-lg",
|
|
9
|
+
return _jsx(Bone, { shape: cx("block w-full rounded-lg", controlHeight(useResponsiveDensity(size))) });
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
12
|
* A choice (a checkbox, a switch, a radio) waiting for its value: the mark a bone of its shape, the
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** A point in the diagram's own space, in CSS pixels from its top left corner. */
|
|
2
|
+
export type FlowPoint = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
};
|
|
6
|
+
/** Where a node or a group sits, its top left corner and its size, in CSS pixels. */
|
|
7
|
+
export type FlowBox = {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A node as laid out: its `id` and its box. A group's box (`group`) is the frame round its nodes.
|
|
15
|
+
*/
|
|
16
|
+
export type FlowNodeBox = FlowBox & {
|
|
17
|
+
id: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* An arrow as laid out: the `from` and `to` ids, its place in `edges` (`index`), the points dagre
|
|
21
|
+
* routed it through, the SVG path drawn through them (it ends on the target's edge, at the
|
|
22
|
+
* arrowhead's tip) and its label's centre when it has one.
|
|
23
|
+
*/
|
|
24
|
+
export type FlowEdgePath = {
|
|
25
|
+
from: string;
|
|
26
|
+
to: string;
|
|
27
|
+
index: number;
|
|
28
|
+
points: readonly FlowPoint[];
|
|
29
|
+
path: string;
|
|
30
|
+
labelAt: FlowPoint | null;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The whole diagram as laid out, in one coordinate space: `width` and `height`, a box per node and
|
|
34
|
+
* per group, and a path per arrow. `FlowDiagram` hands it to `overlay`.
|
|
35
|
+
*/
|
|
36
|
+
export type FlowLayout = {
|
|
37
|
+
width: number;
|
|
38
|
+
height: number;
|
|
39
|
+
nodes: readonly FlowNodeBox[];
|
|
40
|
+
groups: readonly (FlowBox & {
|
|
41
|
+
name: string;
|
|
42
|
+
})[];
|
|
43
|
+
edges: readonly FlowEdgePath[];
|
|
44
|
+
};
|
|
45
|
+
/** What the layout needs from a node: its id, its size and the group it sits in. */
|
|
46
|
+
export type LayoutNode = {
|
|
47
|
+
id: string;
|
|
48
|
+
width: number;
|
|
49
|
+
height: number;
|
|
50
|
+
group?: string | undefined;
|
|
51
|
+
};
|
|
52
|
+
/** What the layout needs from an arrow: its ends, and its label's size when it has one. */
|
|
53
|
+
export type LayoutEdge = {
|
|
54
|
+
from: string;
|
|
55
|
+
to: string;
|
|
56
|
+
label?: {
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
} | undefined;
|
|
60
|
+
};
|
|
61
|
+
/** `down` reads from the top, `right` from the start edge. */
|
|
62
|
+
export type FlowDirection = "down" | "right";
|
|
63
|
+
/**
|
|
64
|
+
* Lays the nodes and arrows out with dagre. An arrow whose end is not a node is left out, so a
|
|
65
|
+
* typo draws no stray box. Pure: the same input gives the same layout.
|
|
66
|
+
*/
|
|
67
|
+
export declare function layoutFlow(nodes: readonly LayoutNode[], edges: readonly LayoutEdge[], direction: FlowDirection): FlowLayout;
|
|
68
|
+
export declare function stepPath(points: readonly FlowPoint[], direction: FlowDirection, lane?: number): string;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The layout behind `FlowDiagram`: dagre places the boxes and routes the arrows, then this file
|
|
3
|
+
* turns its output into what the component draws. Internal: only the geometry types are exported
|
|
4
|
+
* from the package, for `FlowDiagram`'s `overlay`.
|
|
5
|
+
*/
|
|
6
|
+
import { Graph, layout } from "@dagrejs/dagre";
|
|
7
|
+
/** Space round the drawing, between boxes in a rank, and between ranks. */
|
|
8
|
+
const MARGIN = 16;
|
|
9
|
+
const NODE_GAP = 32;
|
|
10
|
+
const RANK_GAP = 48;
|
|
11
|
+
const EDGE_GAP = 16;
|
|
12
|
+
/** A group's dagre id, kept apart from every node id. */
|
|
13
|
+
const groupKey = (name) => `\u0000group:${name}`;
|
|
14
|
+
const round = (n) => Math.round(n * 10) / 10;
|
|
15
|
+
/**
|
|
16
|
+
* Lays the nodes and arrows out with dagre. An arrow whose end is not a node is left out, so a
|
|
17
|
+
* typo draws no stray box. Pure: the same input gives the same layout.
|
|
18
|
+
*/
|
|
19
|
+
export function layoutFlow(nodes, edges, direction) {
|
|
20
|
+
const groups = [...new Set(nodes.flatMap((n) => (n.group ? [n.group] : [])))];
|
|
21
|
+
const g = new Graph({
|
|
22
|
+
multigraph: true,
|
|
23
|
+
compound: groups.length > 0,
|
|
24
|
+
});
|
|
25
|
+
g.setGraph({
|
|
26
|
+
rankdir: direction === "right" ? "LR" : "TB",
|
|
27
|
+
nodesep: NODE_GAP,
|
|
28
|
+
ranksep: RANK_GAP,
|
|
29
|
+
edgesep: EDGE_GAP,
|
|
30
|
+
marginx: MARGIN,
|
|
31
|
+
marginy: MARGIN,
|
|
32
|
+
});
|
|
33
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
34
|
+
for (const name of groups)
|
|
35
|
+
g.setNode(groupKey(name), {});
|
|
36
|
+
const ids = new Set();
|
|
37
|
+
for (const n of nodes) {
|
|
38
|
+
ids.add(n.id);
|
|
39
|
+
g.setNode(n.id, { width: n.width, height: n.height });
|
|
40
|
+
if (n.group)
|
|
41
|
+
g.setParent(n.id, groupKey(n.group));
|
|
42
|
+
}
|
|
43
|
+
const kept = edges.flatMap((e, index) => ids.has(e.from) && ids.has(e.to) ? [{ e, index }] : []);
|
|
44
|
+
for (const { e, index } of kept) {
|
|
45
|
+
g.setEdge(e.from, e.to, e.label ? { width: e.label.width, height: e.label.height, labelpos: "c" } : {}, String(index));
|
|
46
|
+
}
|
|
47
|
+
layout(g);
|
|
48
|
+
const box = (key) => {
|
|
49
|
+
const { x = 0, y = 0, width = 0, height = 0 } = g.node(key);
|
|
50
|
+
return {
|
|
51
|
+
x: round(x - width / 2),
|
|
52
|
+
y: round(y - height / 2),
|
|
53
|
+
width: round(width),
|
|
54
|
+
height: round(height),
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const graph = g.graph();
|
|
58
|
+
return {
|
|
59
|
+
width: Math.ceil(graph.width ?? 0),
|
|
60
|
+
height: Math.ceil(graph.height ?? 0),
|
|
61
|
+
nodes: [...ids].map((id) => ({ id, ...box(id) })),
|
|
62
|
+
groups: groups.map((name) => ({ name, ...box(groupKey(name)) })),
|
|
63
|
+
edges: kept.map(({ e, index }) => {
|
|
64
|
+
const routed = g.edge(e.from, e.to, String(index));
|
|
65
|
+
const points = (routed.points ?? []).map((p) => ({ x: round(p.x), y: round(p.y) }));
|
|
66
|
+
return {
|
|
67
|
+
from: e.from,
|
|
68
|
+
to: e.to,
|
|
69
|
+
index,
|
|
70
|
+
points,
|
|
71
|
+
path: stepPath(points, direction, LANES[index % LANES.length]),
|
|
72
|
+
labelAt: e.label && routed.x !== undefined && routed.y !== undefined
|
|
73
|
+
? { x: round(routed.x), y: round(routed.y) }
|
|
74
|
+
: null,
|
|
75
|
+
};
|
|
76
|
+
}),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A square path through dagre's route points: each step leaves along the rank `direction`, turns
|
|
81
|
+
* once at `lane` of the way across (0.5 is halfway), and arrives along it again, so every arrow is
|
|
82
|
+
* made of straight runs at right angles and ends exactly on the last point, where its arrowhead
|
|
83
|
+
* sits. Arrows between the same two ranks take different lanes, so their cross runs do not overlap.
|
|
84
|
+
*/
|
|
85
|
+
/** Where each arrow turns between two ranks, by its index: spread so parallel runs stay apart. */
|
|
86
|
+
const LANES = [0.5, 0.3, 0.7, 0.4, 0.6];
|
|
87
|
+
export function stepPath(points, direction, lane = 0.5) {
|
|
88
|
+
const [first, ...rest] = points;
|
|
89
|
+
if (!first)
|
|
90
|
+
return "";
|
|
91
|
+
let d = `M${first.x},${first.y}`;
|
|
92
|
+
let from = first;
|
|
93
|
+
for (const to of rest) {
|
|
94
|
+
if (direction === "right") {
|
|
95
|
+
const mid = round(from.x + (to.x - from.x) * lane);
|
|
96
|
+
d += `H${mid}V${to.y}H${to.x}`;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const mid = round(from.y + (to.y - from.y) * lane);
|
|
100
|
+
d += `V${mid}H${to.x}V${to.y}`;
|
|
101
|
+
}
|
|
102
|
+
from = to;
|
|
103
|
+
}
|
|
104
|
+
return d;
|
|
105
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { StateMachineDefinition, StateMachineState } from "./StateMachine.js";
|
|
2
|
+
/** One transition: a target, or `{ target, meta }`, or a list of them (the first that passes its guard). */
|
|
3
|
+
export type XStateTransitionConfig = string | undefined | {
|
|
4
|
+
target?: string | readonly (string | undefined)[] | undefined;
|
|
5
|
+
meta?: Record<string, unknown> | undefined;
|
|
6
|
+
};
|
|
7
|
+
type XStateTransitions = XStateTransitionConfig | readonly XStateTransitionConfig[];
|
|
8
|
+
/** One `invoke`: where it goes when the invoked actor is done, and when it fails. */
|
|
9
|
+
export type XStateInvokeConfig = {
|
|
10
|
+
onDone?: XStateTransitions;
|
|
11
|
+
onError?: XStateTransitions;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The part of an xstate v5 state node `fromXState` reads: its `id`, `type` and `meta`, and the
|
|
15
|
+
* ways it moves on (`on`, `always`, `after`, and each `invoke`'s `onDone` and `onError`). Typed by
|
|
16
|
+
* shape, so the package does not depend on xstate.
|
|
17
|
+
*/
|
|
18
|
+
export type XStateNodeConfig = {
|
|
19
|
+
id?: string | undefined;
|
|
20
|
+
type?: string | undefined;
|
|
21
|
+
meta?: Record<string, unknown> | undefined;
|
|
22
|
+
on?: Record<string, XStateTransitions> | undefined;
|
|
23
|
+
always?: XStateTransitions;
|
|
24
|
+
after?: Record<string, XStateTransitions> | undefined;
|
|
25
|
+
invoke?: XStateInvokeConfig | readonly XStateInvokeConfig[] | undefined;
|
|
26
|
+
/** Its child states: only their `id`s are read, so a target `#id` lands on this state. */
|
|
27
|
+
states?: Record<string, XStateNodeConfig> | undefined;
|
|
28
|
+
};
|
|
29
|
+
/** Where a machine starts: a state's key, or `{ target }`. */
|
|
30
|
+
export type XStateInitial = string | {
|
|
31
|
+
target: string;
|
|
32
|
+
} | undefined;
|
|
33
|
+
/** A machine's config, or what `setup(…).createMachine(config)` returns (it keeps it as `config`). */
|
|
34
|
+
export type XStateMachineLike = {
|
|
35
|
+
id?: string | undefined;
|
|
36
|
+
initial?: XStateInitial;
|
|
37
|
+
states?: Record<string, XStateNodeConfig> | undefined;
|
|
38
|
+
} | {
|
|
39
|
+
config: {
|
|
40
|
+
id?: string | undefined;
|
|
41
|
+
initial?: XStateInitial;
|
|
42
|
+
states?: Record<string, XStateNodeConfig> | undefined;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/** What `fromXState` makes of one state node before `state` adjusts it. */
|
|
46
|
+
export type XStateStateInput = {
|
|
47
|
+
id: string;
|
|
48
|
+
/** The node's own config: its `type`, `meta` and `on`. */
|
|
49
|
+
node: XStateNodeConfig;
|
|
50
|
+
/** The state as read by the default rules. */
|
|
51
|
+
state: StateMachineState;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Turns an xstate v5 machine (the machine, or its config) into a `StateMachine` definition: one
|
|
55
|
+
* state per top-level state node, one transition per target in each node's `on`.
|
|
56
|
+
*
|
|
57
|
+
* - A state's `label` is its `meta.label`, else its key; its `owner` is `meta.owner`; its `kind`
|
|
58
|
+
* is `meta.kind` when that is one of the five, else `terminal` for a `type: "final"` node,
|
|
59
|
+
* `initial` for the machine's `initial`, and `normal` for the rest.
|
|
60
|
+
* - Each `on` event, `always`, each `after` delay and each `invoke`'s `onDone` and `onError` is a
|
|
61
|
+
* transition. Its `event` is its `meta.label`, else the event's name (`always`, `after 500`,
|
|
62
|
+
* `done`, `error`). A transition with no target
|
|
63
|
+
* (it stays where it is), one that stays inside its own state, or one whose target is not a
|
|
64
|
+
* top-level state is left out.
|
|
65
|
+
* - `state` adjusts each state, for a machine whose meta says it another way: return the state to
|
|
66
|
+
* draw, given its key, its config and the state the rules above made of it.
|
|
67
|
+
*
|
|
68
|
+
* Only the top level is read: a nested state is drawn as its parent.
|
|
69
|
+
*/
|
|
70
|
+
export declare function fromXState(machine: XStateMachineLike, options?: {
|
|
71
|
+
state?: ((input: XStateStateInput) => StateMachineState) | undefined;
|
|
72
|
+
}): StateMachineDefinition;
|
|
73
|
+
export {};
|