@tristan2828/ui-foundation 4.118.0 → 4.120.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/bin/ui-foundation.mjs +28 -3
- package/conventions/docs/add-an-entity.md +39 -19
- package/conventions/docs/cell-patterns.md +8 -4
- package/conventions/docs/design-language.md +51 -11
- package/conventions/docs/entity-plan-template.md +3 -1
- package/conventions/docs/reminders.md +29 -1
- package/dist/api/schema.d.ts +1 -1
- package/dist/components/app/action-hint.d.ts +9 -0
- package/dist/components/app/action-hint.js +22 -0
- package/dist/components/app/edit-in-place-presets.d.ts +5 -1
- package/dist/components/app/edit-in-place-presets.js +2 -2
- package/dist/components/app/entity-view-facts.d.ts +19 -2
- package/dist/components/app/entity-view-facts.js +8 -4
- package/dist/components/app/entity-view.js +4 -20
- package/dist/components/app/fact-extras.d.ts +16 -0
- package/dist/components/app/fact-extras.js +49 -0
- package/dist/components/app/key-stats.d.ts +11 -0
- package/dist/components/app/key-stats.js +3 -1
- package/dist/components/app/list-header.d.ts +8 -1
- package/dist/components/app/list-header.js +18 -5
- package/dist/components/app/overview-page.d.ts +13 -1
- package/dist/components/app/overview-page.js +14 -2
- package/dist/components/app/recurrence-field.d.ts +15 -2
- package/dist/components/app/recurrence-field.js +54 -13
- package/dist/index.d.ts +5 -4
- package/dist/index.js +2 -1
- package/dist/lib/recurrence-format.d.ts +13 -4
- package/dist/lib/recurrence-format.js +14 -7
- package/dist/lib/recurrence-phrase.d.ts +24 -2
- package/dist/lib/recurrence-phrase.js +26 -8
- package/dist/lib/recurrence.d.ts +16 -1
- package/dist/lib/recurrence.js +29 -2
- package/openapi/foundation.yaml +9 -2
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { IconComponent } from './icon-component.js';
|
|
3
|
+
import type { EntityViewFactAction } from './entity-view-facts.js';
|
|
3
4
|
export type KeyStat = {
|
|
4
5
|
label: string;
|
|
5
6
|
value: ReactNode;
|
|
@@ -7,7 +8,17 @@ export type KeyStat = {
|
|
|
7
8
|
hint?: ReactNode;
|
|
8
9
|
/** The concept's icon, drawn at 13px before the label (decorative: the label still says it). */
|
|
9
10
|
icon?: IconComponent;
|
|
11
|
+
/**
|
|
12
|
+
* A few words on the value (4.120), behind an info button after it: a
|
|
13
|
+
* tooltip on hover and keyboard focus, a line under the value on a touch
|
|
14
|
+
* screen. A screen reader reads it with the value.
|
|
15
|
+
*/
|
|
16
|
+
info?: string;
|
|
17
|
+
/** A small button under the value (4.120), as a rail fact's `action`. */
|
|
18
|
+
action?: EntityViewFactAction;
|
|
10
19
|
};
|
|
20
|
+
/** A strip value's action: the same shape as a rail fact's. */
|
|
21
|
+
export type KeyStatAction = EntityViewFactAction;
|
|
11
22
|
export type KeyStatsProps = {
|
|
12
23
|
stats: readonly KeyStat[];
|
|
13
24
|
/** What an empty value reads as. Defaults to a dash, read as "Not set". */
|
|
@@ -2,11 +2,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { cn } from 'cn';
|
|
3
3
|
import { EmptyText } from './empty-value.js';
|
|
4
4
|
import { EMPTY_DASH } from '../../lib/empty-value.js';
|
|
5
|
+
import { FactAction, FactHint } from './fact-extras.js';
|
|
5
6
|
import { KeepPencilRoomContext } from './keep-pencil-room.js';
|
|
6
7
|
const isEmpty = (value) => value === null || value === undefined || value === false || value === '';
|
|
7
8
|
export function KeyStats({ stats, emptyLabel = EMPTY_DASH, width = 'content', className }) {
|
|
9
|
+
const shown = (stat) => isEmpty(stat.value) ? _jsx(EmptyText, { text: emptyLabel, className: "type-body text-muted-foreground" }) : stat.value;
|
|
8
10
|
return (_jsx(KeepPencilRoomContext.Provider, { value: true, children: _jsx("dl", { "data-slot": "key-stats", "data-width": width, className: cn('flex flex-wrap gap-x-8 gap-y-3 rounded-lg border border-border bg-card px-4 py-3 text-card-foreground', width === 'content' && 'w-fit max-w-full', className), children: stats.map((stat) => {
|
|
9
11
|
const Icon = stat.icon;
|
|
10
|
-
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-0.5", children: [_jsxs("dt", { className: cn('type-caption text-muted-foreground', Icon && 'inline-flex items-center gap-1'), children: [Icon && _jsx(Icon, { "aria-hidden": "true", className: "size-3.25 shrink-0" }), stat.label] }), _jsx("dd", { className: "type-section-title tabular-nums break-words text-foreground", children:
|
|
12
|
+
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-0.5", children: [_jsxs("dt", { className: cn('type-caption text-muted-foreground', Icon && 'inline-flex items-center gap-1'), children: [Icon && _jsx(Icon, { "aria-hidden": "true", className: "size-3.25 shrink-0" }), stat.label] }), _jsx("dd", { className: "type-section-title tabular-nums break-words text-foreground", children: stat.info ? (_jsxs("span", { className: "inline-flex max-w-full flex-wrap items-center gap-x-1", children: [_jsx("span", { className: "min-w-0 max-w-full", children: shown(stat) }), _jsx(FactHint, { label: stat.label, hint: stat.info })] })) : (shown(stat)) }), stat.hint && _jsx("dd", { className: "type-caption text-muted-foreground", children: stat.hint }), stat.action && (_jsx("dd", { "data-slot": "key-stats-action", className: "mt-1", children: _jsx(FactAction, { action: stat.action }) }))] }, stat.label));
|
|
11
13
|
}) }) }));
|
|
12
14
|
}
|
|
@@ -17,6 +17,8 @@ export type ListHeaderSecondaryAction = {
|
|
|
17
17
|
icon?: IconComponent;
|
|
18
18
|
/** Can't be used now (a refresh in flight): the button and its menu item are disabled. */
|
|
19
19
|
disabled?: boolean;
|
|
20
|
+
/** A few words under the button (4.120): "12 searches left". In ⋯ on a phone, under its words. */
|
|
21
|
+
hint?: string;
|
|
20
22
|
} & ({
|
|
21
23
|
to: To;
|
|
22
24
|
onClick?: never;
|
|
@@ -42,6 +44,11 @@ export type ListHeaderProps = {
|
|
|
42
44
|
title: string;
|
|
43
45
|
/** How many records there are, beside the title in the muted tone. Left out while loading. */
|
|
44
46
|
count?: number;
|
|
47
|
+
/**
|
|
48
|
+
* One short line under the title (4.120), in the muted tone: a sentence
|
|
49
|
+
* of context for a list that needs it. Wraps in the header's width.
|
|
50
|
+
*/
|
|
51
|
+
description?: string;
|
|
45
52
|
/** Related screens (Board, Change log). One stays a button; two or more fold into ⋯. */
|
|
46
53
|
links?: readonly ListHeaderLink[];
|
|
47
54
|
/** The New button: a link to the new-record page, or a function that opens its dialog. */
|
|
@@ -81,4 +88,4 @@ export type ListHeaderProps = {
|
|
|
81
88
|
siblingsLabel?: string;
|
|
82
89
|
className?: string;
|
|
83
90
|
};
|
|
84
|
-
export declare function ListHeader({ title, count, links, newAction, secondaryAction, more, deleted, siblings, siblingsLabel, className, }: ListHeaderProps): import("react").JSX.Element;
|
|
91
|
+
export declare function ListHeader({ title, count, description, links, newAction, secondaryAction, more, deleted, siblings, siblingsLabel, className, }: ListHeaderProps): import("react").JSX.Element;
|
|
@@ -23,10 +23,18 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
23
23
|
// for a list's second most common action ("Refresh Now", "Add from
|
|
24
24
|
// Catalog"): an outline button, so New stays the primary. On a phone it
|
|
25
25
|
// folds into ⋯, the menu's first item, so the row keeps the title, ⋯ and
|
|
26
|
-
// New.
|
|
26
|
+
// New. Its `hint` (4.120) is a short line under the button ("12 searches
|
|
27
|
+
// left", ActionHint), and the line under its words in ⋯ on a phone.
|
|
28
|
+
//
|
|
29
|
+
// `description` (4.120) is one short muted line under the title, for a
|
|
30
|
+
// list that needs a sentence of context ("Searches run against the
|
|
31
|
+
// catalog once a day."). It wraps in the header's width (under a framed
|
|
32
|
+
// table's, where DataTable's `pageHeader` shares it), never widening it,
|
|
33
|
+
// and on a phone it sits under the title's row, the buttons staying on it.
|
|
27
34
|
import { EllipsisIcon, PlusIcon, Trash2Icon } from 'lucide-react';
|
|
28
35
|
import { Link, NavLink } from 'react-router';
|
|
29
36
|
import { cn } from 'cn';
|
|
37
|
+
import { ActionHint } from './action-hint.js';
|
|
30
38
|
import { Notice } from './notice.js';
|
|
31
39
|
import { Button } from '../ui/button.js';
|
|
32
40
|
import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
|
|
@@ -42,7 +50,7 @@ function SiblingSwitch({ siblings, label }) {
|
|
|
42
50
|
return sibling.current === undefined ? (_jsx(NavLink, { to: sibling.to, end: true, className: SIBLING_CLASS, children: inner }, sibling.label)) : (_jsx(Link, { to: sibling.to, "aria-current": sibling.current ? 'page' : undefined, className: SIBLING_CLASS, children: inner }, sibling.label));
|
|
43
51
|
}) }) }));
|
|
44
52
|
}
|
|
45
|
-
export function ListHeader({ title, count, links = [], newAction, secondaryAction, more = [], deleted, siblings = [], siblingsLabel, className, }) {
|
|
53
|
+
export function ListHeader({ title, count, description, links = [], newAction, secondaryAction, more = [], deleted, siblings = [], siblingsLabel, className, }) {
|
|
46
54
|
// One link is a button of its own; two or more go in the menu.
|
|
47
55
|
const outLink = links.length === 1 ? links[0] : undefined;
|
|
48
56
|
const menuLinks = links.length > 1 ? links : [];
|
|
@@ -51,7 +59,12 @@ export function ListHeader({ title, count, links = [], newAction, secondaryActio
|
|
|
51
59
|
// phone even when nothing else is in it (and only there).
|
|
52
60
|
const hasMenu = hasOwnMenu || secondaryAction !== undefined;
|
|
53
61
|
const SecondaryIcon = secondaryAction?.icon;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
const secondaryButton = secondaryAction &&
|
|
63
|
+
(secondaryAction.to !== undefined && !secondaryAction.disabled ? (_jsxs(Button, { size: "sm", variant: "outline", "data-slot": "list-header-secondary", nativeButton: false, render: _jsx(Link, { to: secondaryAction.to }), children: [SecondaryIcon && _jsx(SecondaryIcon, { "aria-hidden": "true" }), secondaryAction.label] })) : (_jsxs(Button, { size: "sm", variant: "outline", "data-slot": "list-header-secondary", disabled: secondaryAction.disabled, onClick: secondaryAction.onClick, children: [SecondaryIcon && _jsx(SecondaryIcon, { "aria-hidden": "true" }), secondaryAction.label] })));
|
|
64
|
+
// A hint line under the button lines the row up by its tops (the title
|
|
65
|
+
// and the buttons level), the line hanging below.
|
|
66
|
+
const hinted = Boolean(secondaryAction?.hint);
|
|
67
|
+
return (_jsxs("div", { "data-slot": "list-header", className: cn('flex flex-col', className), children: [_jsxs("div", { className: cn('flex flex-wrap justify-between gap-x-4 gap-y-2', hinted ? 'items-start' : 'items-center'), children: [_jsxs("h1", { className: "flex items-baseline gap-2 type-page-title text-foreground", children: [title, count !== undefined && (_jsxs("span", { className: "type-body font-normal tabular-nums text-muted-foreground", children: [_jsx("span", { className: "sr-only", children: ", " }), count] }))] }), siblings.length > 1 && _jsx(SiblingSwitch, { siblings: siblings, label: siblingsLabel ?? `${title} Lists` }), _jsxs("div", { className: cn('ml-auto flex flex-wrap gap-2', hinted ? 'items-start' : 'items-center'), children: [outLink && (_jsxs(Button, { size: "sm", variant: "outline", nativeButton: false, render: _jsx(Link, { to: outLink.to }), children: [outLink.icon && _jsx(outLink.icon, { "aria-hidden": "true" }), outLink.label] })), hasMenu && (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { size: "icon-sm", variant: "outline", "aria-label": `More for ${title}`, "data-slot": "list-header-more", className: hasOwnMenu ? undefined : 'md:hidden' }), children: _jsx(EllipsisIcon, { "aria-hidden": "true" }) }), _jsxs(DropdownMenuContent, { align: "end", className: "w-max max-w-(--available-width) whitespace-nowrap", children: [secondaryAction && (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { "data-slot": "list-header-secondary-item", className: "md:hidden", disabled: secondaryAction.disabled, render: secondaryAction.to !== undefined ? _jsx(Link, { to: secondaryAction.to }) : undefined, onClick: secondaryAction.onClick, children: [SecondaryIcon && _jsx(SecondaryIcon, { "aria-hidden": "true" }), secondaryAction.hint ? (_jsxs("span", { className: "flex flex-col", children: [secondaryAction.label, _jsx("span", { className: "sr-only", children: ", " }), _jsx("span", { "data-slot": "list-header-secondary-item-hint", className: "type-caption text-muted-foreground", children: secondaryAction.hint })] })) : (secondaryAction.label)] }), hasOwnMenu && _jsx(DropdownMenuSeparator, { className: "md:hidden" })] })), menuLinks.map((link) => (_jsxs(DropdownMenuItem, { render: _jsx(Link, { to: link.to }), children: [link.icon && _jsx(link.icon, { "aria-hidden": "true" }), link.label] }, link.label))), more.map((action) => (_jsxs(DropdownMenuItem, { onClick: action.onSelect, children: [action.icon && _jsx(action.icon, { "aria-hidden": "true" }), action.label] }, action.label))), deleted && (menuLinks.length > 0 || more.length > 0) && _jsx(DropdownMenuSeparator, {}), deleted && (_jsxs(DropdownMenuCheckboxItem, { closeOnClick: true, checked: deleted.shown, onCheckedChange: deleted.onShownChange, children: [_jsx(Trash2Icon, { "aria-hidden": "true" }), "Show Deleted"] }))] })] })), secondaryButton &&
|
|
68
|
+
(secondaryAction?.hint ? (_jsx(ActionHint, { hint: secondaryAction.hint, className: "max-md:hidden", children: secondaryButton })) : (_jsx("span", { className: "contents max-md:hidden", children: secondaryButton }))), newAction &&
|
|
69
|
+
(newAction.to !== undefined ? (_jsxs(Button, { size: "sm", nativeButton: false, render: _jsx(Link, { to: newAction.to }), children: [_jsx(PlusIcon, { "aria-hidden": "true" }), newAction.label] })) : (_jsxs(Button, { size: "sm", onClick: newAction.onClick, children: [_jsx(PlusIcon, { "aria-hidden": "true" }), newAction.label] })))] })] }), description && (_jsx("p", { "data-slot": "list-header-description", className: "mt-1 max-w-prose type-body text-muted-foreground contain-inline-size", children: description })), _jsx("div", { role: "status", "data-slot": "list-header-notice", className: "not-empty:mt-3", children: deleted?.shown && (_jsxs(Notice, { tone: "info", icon: Trash2Icon, action: _jsx(Button, { size: "sm", variant: "outline", onClick: () => deleted.onShownChange(false), children: "Back to the List" }), children: ["Showing deleted ", deleted.noun ?? 'records', "."] })) })] }));
|
|
57
70
|
}
|
|
@@ -27,6 +27,14 @@ export type OverviewPart = {
|
|
|
27
27
|
error?: AppError | null;
|
|
28
28
|
onRetry?: () => void;
|
|
29
29
|
};
|
|
30
|
+
/** A page outside the app (4.120), in the overview's Links section. */
|
|
31
|
+
export type OverviewLink = {
|
|
32
|
+
label: string;
|
|
33
|
+
/** The page's address: opened in a new tab. */
|
|
34
|
+
href: string;
|
|
35
|
+
/** Decorative: the label names the page. */
|
|
36
|
+
icon?: IconComponent;
|
|
37
|
+
};
|
|
30
38
|
export type OverviewPageProps = {
|
|
31
39
|
/** The page's h1: the module's name. */
|
|
32
40
|
title: string;
|
|
@@ -37,8 +45,12 @@ export type OverviewPageProps = {
|
|
|
37
45
|
stats?: ReactNode;
|
|
38
46
|
/** Controls at the title's end. */
|
|
39
47
|
actions?: ReactNode;
|
|
48
|
+
/** Pages outside the app (4.120): one section after the parts, each opening in a new tab. */
|
|
49
|
+
links?: readonly OverviewLink[];
|
|
50
|
+
/** The links section's heading. Defaults to "Links". */
|
|
51
|
+
linksTitle?: string;
|
|
40
52
|
/** The part open at first; none when left out. */
|
|
41
53
|
defaultOpen?: string | null;
|
|
42
54
|
className?: string;
|
|
43
55
|
};
|
|
44
|
-
export declare function OverviewPage({ title, parts, needs, stats, actions, defaultOpen, className, }: OverviewPageProps): import("react").JSX.Element;
|
|
56
|
+
export declare function OverviewPage({ title, parts, needs, stats, actions, links, linksTitle, defaultOpen, className, }: OverviewPageProps): import("react").JSX.Element;
|
|
@@ -19,8 +19,15 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
19
19
|
// `onRetry` in the card), and `empty` (a part with nothing yet: "Nothing
|
|
20
20
|
// yet" in the tile, PartEmpty with its one way to start in the card).
|
|
21
21
|
//
|
|
22
|
+
// `links` (4.120) are a short list of pages outside the app (the
|
|
23
|
+
// module's account page, a supplier's site): one section after the parts,
|
|
24
|
+
// titled `linksTitle` ("Links"), each link its label with its icon if it
|
|
25
|
+
// has one and the external-link mark, opening in a new tab. In a row of
|
|
26
|
+
// as many as fit from 48rem, one per line under it. None draws nothing.
|
|
27
|
+
//
|
|
22
28
|
// The breakpoint is read with matchMedia; on the server, or where it's
|
|
23
29
|
// missing (a test's DOM), the page is drawn wide.
|
|
30
|
+
import { ExternalLinkIcon } from 'lucide-react';
|
|
24
31
|
import { useId, useState, useSyncExternalStore } from 'react';
|
|
25
32
|
import { cn } from 'cn';
|
|
26
33
|
import { Freshness } from './freshness.js';
|
|
@@ -38,7 +45,8 @@ function subscribeWide(listener) {
|
|
|
38
45
|
return () => query.removeEventListener('change', listener);
|
|
39
46
|
}
|
|
40
47
|
const useIsWide = () => useSyncExternalStore(subscribeWide, () => !canMatchMedia() || window.matchMedia(WIDE_QUERY).matches, () => true);
|
|
41
|
-
export function OverviewPage({ title, parts, needs = [], stats, actions, defaultOpen = null, className, }) {
|
|
48
|
+
export function OverviewPage({ title, parts, needs = [], stats, actions, links = [], linksTitle = 'Links', defaultOpen = null, className, }) {
|
|
49
|
+
const linksId = useId();
|
|
42
50
|
const wide = useIsWide();
|
|
43
51
|
const detailId = useId();
|
|
44
52
|
const [openId, setOpenId] = useState(defaultOpen);
|
|
@@ -52,7 +60,11 @@ export function OverviewPage({ title, parts, needs = [], stats, actions, default
|
|
|
52
60
|
setOpenId(null);
|
|
53
61
|
tile?.focus();
|
|
54
62
|
};
|
|
55
|
-
return (_jsxs("div", { "data-slot": "overview-page", className: cn('flex flex-col gap-4', className), children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsx("h1", { className: "type-page-title text-foreground", children: title }), actions && _jsx("div", { className: "flex shrink-0 items-center gap-2", children: actions })] }), stats, _jsx(NeedsYou, { items: needs }), wide ? (_jsxs(_Fragment, { children: [_jsx("ul", { "data-slot": "overview-tiles", className: "grid grid-cols-[repeat(auto-fill,minmax(170px,1fr))] gap-2.5", children: parts.map((part) => (_jsx("li", { className: "flex min-w-0", children: _jsx(OverviewTile, { id: tileId(part.id), part: part, open: part.id === openId, controls: detailId, onToggle: () => setOpenId(part.id === openId ? null : part.id) }) }, part.id))) }), _jsx("div", { id: detailId, "data-slot": "overview-detail", onKeyDown: onDetailKeyDown, children: open && _jsx(PartCard, { part: open }) })] })) : (_jsx(WidgetCardGroup, { accordion: true, defaultOpen: openId, className: "flex flex-col gap-2.5", children: parts.map((part) => (_jsx(PartCard, { part: part }, part.id))) }))] }));
|
|
63
|
+
return (_jsxs("div", { "data-slot": "overview-page", className: cn('flex flex-col gap-4', className), children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsx("h1", { className: "type-page-title text-foreground", children: title }), actions && _jsx("div", { className: "flex shrink-0 items-center gap-2", children: actions })] }), stats, _jsx(NeedsYou, { items: needs }), wide ? (_jsxs(_Fragment, { children: [_jsx("ul", { "data-slot": "overview-tiles", className: "grid grid-cols-[repeat(auto-fill,minmax(170px,1fr))] gap-2.5", children: parts.map((part) => (_jsx("li", { className: "flex min-w-0", children: _jsx(OverviewTile, { id: tileId(part.id), part: part, open: part.id === openId, controls: detailId, onToggle: () => setOpenId(part.id === openId ? null : part.id) }) }, part.id))) }), _jsx("div", { id: detailId, "data-slot": "overview-detail", onKeyDown: onDetailKeyDown, children: open && _jsx(PartCard, { part: open }) })] })) : (_jsx(WidgetCardGroup, { accordion: true, defaultOpen: openId, className: "flex flex-col gap-2.5", children: parts.map((part) => (_jsx(PartCard, { part: part }, part.id))) })), links.length > 0 && (_jsxs("section", { "data-slot": "overview-links", "aria-labelledby": linksId, className: "flex flex-col gap-2", children: [_jsx("h2", { id: linksId, className: "type-section-title text-foreground", children: linksTitle }), _jsx("ul", { className: "flex flex-col md:flex-row md:flex-wrap md:gap-x-6 md:gap-y-1", children: links.map((link) => (_jsx("li", { className: "min-w-0", children: _jsx(OverviewLinkItem, { link: link }) }, `${link.label}:${link.href}`))) })] }))] }));
|
|
64
|
+
}
|
|
65
|
+
function OverviewLinkItem({ link }) {
|
|
66
|
+
const { icon: Icon } = link;
|
|
67
|
+
return (_jsxs("a", { href: link.href, target: "_blank", rel: "noreferrer", "data-slot": "overview-link", className: cn('inline-flex max-w-full items-center gap-1.5 rounded-sm py-1 type-body font-medium text-link underline-offset-4 outline-none', 'hover:underline focus-visible:ring-3 focus-visible:ring-ring/50 max-md:min-h-11'), children: [Icon && _jsx(Icon, { "aria-hidden": "true", className: "size-4 shrink-0" }), _jsx("span", { className: "min-w-0 truncate", children: link.label }), _jsx(ExternalLinkIcon, { "aria-hidden": "true", className: "size-3.5 shrink-0" }), _jsx("span", { className: "sr-only", children: "(opens in a new tab)" })] }));
|
|
56
68
|
}
|
|
57
69
|
function PartCard({ part }) {
|
|
58
70
|
return (_jsx(WidgetCard, { id: part.id, title: part.title, icon: part.icon, to: part.to, value: part.value, line: part.line, freshness: part.freshness, isLoading: part.isLoading ?? false, error: part.error, onRetry: part.onRetry, isEmpty: part.empty !== undefined, emptyMessage: part.empty?.text ?? 'Nothing here yet', empty: part.empty, emptySummary: "Nothing yet", className: "w-full", children: part.detail }));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Recurrence } from '../../lib/recurrence.js';
|
|
1
|
+
import { type Recurrence, type WeekdayCode } from '../../lib/recurrence.js';
|
|
2
2
|
export type RecurrenceFieldProps = {
|
|
3
3
|
/** The phrase box's id, for the field's `<FieldLabel htmlFor>`. */
|
|
4
4
|
id?: string;
|
|
@@ -18,6 +18,19 @@ export type RecurrenceFieldProps = {
|
|
|
18
18
|
previewCount?: number;
|
|
19
19
|
/** Show the preset buttons (the default). */
|
|
20
20
|
presets?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Show times of day (the default). False, for a record whose times are
|
|
23
|
+
* its own fields: the preview lists dates only, from today on, the label
|
|
24
|
+
* and the box leave the times out, and "at …" in the box is refused.
|
|
25
|
+
*/
|
|
26
|
+
times?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The day the app's weeks start on (`'MO'` to `'SU'`; Monday when left
|
|
29
|
+
* out). Not Monday: every weekly rule the presets and the box build gets
|
|
30
|
+
* it as WKST (`'SU'` adds `WKST=SU`), which moves an every-N-weeks rule's
|
|
31
|
+
* weeks.
|
|
32
|
+
*/
|
|
33
|
+
weekStart?: WeekdayCode;
|
|
21
34
|
locale?: string;
|
|
22
35
|
/** The value was refused: `aria-invalid` on the box. */
|
|
23
36
|
invalid?: boolean;
|
|
@@ -33,4 +46,4 @@ export type RecurrenceFieldProps = {
|
|
|
33
46
|
'aria-label'?: string;
|
|
34
47
|
'aria-describedby'?: string;
|
|
35
48
|
};
|
|
36
|
-
export declare function RecurrenceField({ id, value, onChange, timeZone, defaultTimes, today, now, previewCount, presets, locale, invalid, readOnly, onProblem, onBlur, className, 'aria-label': ariaLabel, 'aria-describedby': describedBy, }: RecurrenceFieldProps): import("react").JSX.Element;
|
|
49
|
+
export declare function RecurrenceField({ id, value, onChange, timeZone, defaultTimes, today, now, previewCount, presets, times, weekStart, locale, invalid, readOnly, onProblem, onBlur, className, 'aria-label': ariaLabel, 'aria-describedby': describedBy, }: RecurrenceFieldProps): import("react").JSX.Element;
|
|
@@ -15,6 +15,17 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
15
15
|
// - **The preview**: the rule's label ("Every 2nd Tue at 9:00 AM") and its
|
|
16
16
|
// next five occurrences, in the rule's zone, or why it can't be read.
|
|
17
17
|
//
|
|
18
|
+
// Two options an app's own records may want (4.114):
|
|
19
|
+
// - `times={false}`, for a record whose times are fields of its own (a
|
|
20
|
+
// calendar's events): the preview lists dates only ("Tue, Dec 8", from
|
|
21
|
+
// today on), the label and the box say no times, and typing "at 9am" is
|
|
22
|
+
// refused. The value still carries `times` (the value's, `defaultTimes`
|
|
23
|
+
// or 09:00), as the contract needs one.
|
|
24
|
+
// - `weekStart`, the day the app's weeks start on: `'SU'` adds `WKST=SU`
|
|
25
|
+
// to every weekly rule the presets and the box build, so "every other
|
|
26
|
+
// week on sun, wed" counts its weeks Sunday to Saturday. A rule whose
|
|
27
|
+
// week start differs, where it matters, says so ("weeks start mon").
|
|
28
|
+
//
|
|
18
29
|
// One control for the form (a react-hook-form `Controller`) and for
|
|
19
30
|
// editing in place (`inPlace.recurrence`: Enter in the box or leaving the
|
|
20
31
|
// field saves). The box is the field's labelled control (`id`); the
|
|
@@ -26,15 +37,16 @@ import { Input } from '../ui/input.js';
|
|
|
26
37
|
import { ToggleGroup, ToggleGroupItem } from '../ui/toggle-group.js';
|
|
27
38
|
import { formatOccurrence, formatRecurrence, todayIn } from '../../lib/recurrence-format.js';
|
|
28
39
|
import { ordinalWord, parseRecurrencePhrase, recurrencePhrase } from '../../lib/recurrence-phrase.js';
|
|
29
|
-
import { nextOccurrences, normalizeRecurrence, recurrenceProblem, WEEKDAY_CODES } from '../../lib/recurrence.js';
|
|
40
|
+
import { atLocal, nextOccurrences, normalizeRecurrence, recurrenceProblem, wallClock, WEEKDAY_CODES, } from '../../lib/recurrence.js';
|
|
30
41
|
function weekdayOf(day) {
|
|
31
42
|
return (new Date(`${day}T00:00:00Z`).getUTCDay() + 6) % 7;
|
|
32
43
|
}
|
|
33
44
|
function dayName(day, locale) {
|
|
34
45
|
return new Intl.DateTimeFormat(locale, { weekday: 'short', timeZone: 'UTC' }).format(Date.UTC(2024, 0, 1 + day));
|
|
35
46
|
}
|
|
36
|
-
/** The presets for a start day: each a rule built from that day. */
|
|
37
|
-
function presetsFor(start, locale) {
|
|
47
|
+
/** The presets for a start day: each a rule built from that day; a weekly one with the app's week start. */
|
|
48
|
+
function presetsFor(start, locale, weekStart) {
|
|
49
|
+
const wkst = weekStart === 'MO' ? '' : `;WKST=${weekStart}`;
|
|
38
50
|
const [year, month, date] = start.split('-').map(Number);
|
|
39
51
|
const weekday = weekdayOf(start);
|
|
40
52
|
const lastOfMonth = new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
@@ -44,8 +56,8 @@ function presetsFor(start, locale) {
|
|
|
44
56
|
const yearDay = new Intl.DateTimeFormat(locale, { month: 'short', day: 'numeric', timeZone: 'UTC' }).format(Date.UTC(2024, month - 1, date));
|
|
45
57
|
return [
|
|
46
58
|
{ id: 'daily', label: 'Daily', rule: 'FREQ=DAILY' },
|
|
47
|
-
{ id: 'weekdays', label: 'Weekdays', rule:
|
|
48
|
-
{ id: 'weekly', label: `Weekly on ${dayName(weekday, locale)}`, rule: `FREQ=WEEKLY;BYDAY=${code}` },
|
|
59
|
+
{ id: 'weekdays', label: 'Weekdays', rule: `FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR${wkst}` },
|
|
60
|
+
{ id: 'weekly', label: `Weekly on ${dayName(weekday, locale)}`, rule: `FREQ=WEEKLY;BYDAY=${code}${wkst}` },
|
|
49
61
|
{ id: 'monthly', label: `Monthly on the ${ordinalWord(date)}`, rule: `FREQ=MONTHLY;BYMONTHDAY=${date}` },
|
|
50
62
|
{
|
|
51
63
|
id: 'nth',
|
|
@@ -65,7 +77,27 @@ function browserZone() {
|
|
|
65
77
|
}
|
|
66
78
|
}
|
|
67
79
|
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
68
|
-
|
|
80
|
+
// Every preset repeats each week or less often, where WKST changes nothing:
|
|
81
|
+
// a stored weekly rule with or without one is still its preset.
|
|
82
|
+
const sameDays = (a, b) => a.replace(/;WKST=[A-Z]{2}/, '') === b.replace(/;WKST=[A-Z]{2}/, '');
|
|
83
|
+
/** The next `count` days the value falls on, from today (in its zone) on: a date-only preview. */
|
|
84
|
+
function nextDays(value, today, count) {
|
|
85
|
+
const days = [];
|
|
86
|
+
const seen = new Set();
|
|
87
|
+
const from = new Date(atLocal(today, '00:00', value.timeZone).getTime() - 1);
|
|
88
|
+
// Each day once, however many times it has: ask for enough to fill the list.
|
|
89
|
+
for (const moment of nextOccurrences(value, from, count * value.times.length)) {
|
|
90
|
+
const day = wallClock(moment, value.timeZone).day;
|
|
91
|
+
if (seen.has(day))
|
|
92
|
+
continue;
|
|
93
|
+
seen.add(day);
|
|
94
|
+
days.push(moment);
|
|
95
|
+
if (days.length === count)
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
return days;
|
|
99
|
+
}
|
|
100
|
+
export function RecurrenceField({ id, value, onChange, timeZone, defaultTimes, today, now, previewCount = 5, presets = true, times = true, weekStart = 'MO', locale, invalid = false, readOnly = false, onProblem, onBlur, className, 'aria-label': ariaLabel, 'aria-describedby': describedBy, }) {
|
|
69
101
|
const zone = value?.timeZone ?? timeZone ?? browserZone();
|
|
70
102
|
const day = today ?? todayIn(zone, now);
|
|
71
103
|
const ownId = useId();
|
|
@@ -75,13 +107,14 @@ export function RecurrenceField({ id, value, onChange, timeZone, defaultTimes, t
|
|
|
75
107
|
const box = useRef(null);
|
|
76
108
|
// The box's text, and the value it last read (or was given). A new value
|
|
77
109
|
// from outside (a preset, the form's reset) is written back as its phrase.
|
|
78
|
-
const
|
|
110
|
+
const phraseOf = (recurrence) => recurrencePhrase(recurrence, day, { times, weekStart }) ?? '';
|
|
111
|
+
const [text, setText] = useState(() => (value ? phraseOf(value) : ''));
|
|
79
112
|
const [problem, setProblem] = useState(null);
|
|
80
113
|
const [known, setKnown] = useState(value);
|
|
81
114
|
if (!same(known, value)) {
|
|
82
115
|
setKnown(value);
|
|
83
116
|
if (value !== null || problem === null) {
|
|
84
|
-
setText(value ? (
|
|
117
|
+
setText(value ? phraseOf(value) : '');
|
|
85
118
|
setProblem(null);
|
|
86
119
|
}
|
|
87
120
|
}
|
|
@@ -102,6 +135,8 @@ export function RecurrenceField({ id, value, onChange, timeZone, defaultTimes, t
|
|
|
102
135
|
timeZone: zone,
|
|
103
136
|
times: value?.times ?? defaultTimes,
|
|
104
137
|
start: value?.start,
|
|
138
|
+
weekStart,
|
|
139
|
+
readTimes: times,
|
|
105
140
|
});
|
|
106
141
|
if (result.ok)
|
|
107
142
|
emit(result.value, null);
|
|
@@ -109,8 +144,10 @@ export function RecurrenceField({ id, value, onChange, timeZone, defaultTimes, t
|
|
|
109
144
|
emit(null, result.error);
|
|
110
145
|
};
|
|
111
146
|
const start = value?.start ?? day;
|
|
112
|
-
const options = presetsFor(start, locale);
|
|
113
|
-
const pressed = value
|
|
147
|
+
const options = presetsFor(start, locale, weekStart);
|
|
148
|
+
const pressed = value
|
|
149
|
+
? (options.find((option) => option.rule !== null && sameDays(option.rule, value.rule))?.id ?? 'custom')
|
|
150
|
+
: null;
|
|
114
151
|
const pick = (preset) => {
|
|
115
152
|
if (preset.rule === null) {
|
|
116
153
|
box.current?.focus();
|
|
@@ -123,7 +160,7 @@ export function RecurrenceField({ id, value, onChange, timeZone, defaultTimes, t
|
|
|
123
160
|
timeZone: zone,
|
|
124
161
|
fromCompletion: false,
|
|
125
162
|
});
|
|
126
|
-
setText(
|
|
163
|
+
setText(phraseOf(next));
|
|
127
164
|
emit(next, null);
|
|
128
165
|
};
|
|
129
166
|
// A press on a preset is its own: Enter there mustn't also reach editing
|
|
@@ -134,10 +171,14 @@ export function RecurrenceField({ id, value, onChange, timeZone, defaultTimes, t
|
|
|
134
171
|
};
|
|
135
172
|
const stored = value ? recurrenceProblem(value) : null;
|
|
136
173
|
const shownProblem = problem ?? stored;
|
|
137
|
-
const upcoming = value && !shownProblem && previewCount > 0
|
|
174
|
+
const upcoming = value && !shownProblem && previewCount > 0
|
|
175
|
+
? times
|
|
176
|
+
? nextOccurrences(value, now ?? new Date(), previewCount)
|
|
177
|
+
: nextDays(value, day, previewCount)
|
|
178
|
+
: [];
|
|
138
179
|
return (_jsxs("div", { "data-slot": "recurrence-field", className: cn('flex min-w-0 flex-col gap-2', className), children: [presets && (_jsx(ToggleGroup, { "data-slot": "recurrence-presets", variant: "outline", spacing: 1, "aria-label": "Presets", value: pressed ? [pressed] : [], onValueChange: (next) => {
|
|
139
180
|
const chosen = options.find((option) => option.id === (next[0] ?? pressed));
|
|
140
181
|
if (chosen)
|
|
141
182
|
pick(chosen);
|
|
142
|
-
}, onKeyDown: keepEnter, disabled: readOnly, className: "max-w-full flex-wrap", children: options.map((option) => (_jsx(ToggleGroupItem, { value: option.id, className: "h-(--control-height,--spacing(8)) px-3 font-normal text-muted-foreground aria-pressed:font-medium aria-pressed:text-foreground", children: option.label }, option.id))) })), _jsxs("div", { className: "relative", children: [_jsx(RepeatIcon, { "aria-hidden": "true", className: "pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" }), _jsx(Input, { ref: box, id: boxId, value: text, onChange: (event) => read(event.target.value), onBlur: onBlur, readOnly: readOnly, placeholder:
|
|
183
|
+
}, onKeyDown: keepEnter, disabled: readOnly, className: "max-w-full flex-wrap", children: options.map((option) => (_jsx(ToggleGroupItem, { value: option.id, className: "h-(--control-height,--spacing(8)) px-3 font-normal text-muted-foreground aria-pressed:font-medium aria-pressed:text-foreground", children: option.label }, option.id))) })), _jsxs("div", { className: "relative", children: [_jsx(RepeatIcon, { "aria-hidden": "true", className: "pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" }), _jsx(Input, { ref: box, id: boxId, value: text, onChange: (event) => read(event.target.value), onBlur: onBlur, readOnly: readOnly, placeholder: times ? 'every 2nd tue at 9am' : 'every 2nd tue', autoComplete: "off", spellCheck: false, className: "pl-8", "aria-label": ariaLabel, "aria-invalid": invalid || !!shownProblem || undefined, "aria-describedby": [shownProblem ? messageId : previewId, describedBy].filter(Boolean).join(' ') || undefined })] }), _jsx("div", { "data-slot": "recurrence-preview", "aria-live": "polite", className: "text-sm", children: shownProblem ? (_jsx("p", { id: messageId, className: "text-destructive-text", children: shownProblem })) : value ? (_jsxs("div", { id: previewId, children: [_jsx("p", { className: "font-medium text-foreground", children: formatRecurrence(value, { locale, times, weekStart }) }), previewCount > 0 && (_jsx(_Fragment, { children: upcoming.length ? (_jsx("ol", { "aria-label": "Next", className: "mt-1 flex flex-col gap-0.5 text-muted-foreground tabular-nums", children: upcoming.map((moment) => (_jsx("li", { children: formatOccurrence(moment, value.timeZone, { locale, now, time: times }) }, moment.getTime()))) })) : (_jsx("p", { className: "mt-1 text-muted-foreground", children: "No more to come." })) }))] })) : (_jsx("p", { id: previewId, className: "text-muted-foreground", children: "Doesn\u2019t repeat. Pick a preset or type how it repeats." })) })] }));
|
|
143
184
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,8 @@ export { OptionSelect, type OptionSelectOption, type OptionSelectProps } from '.
|
|
|
21
21
|
export { ChoiceButtons, type ChoiceButtonsOption, type ChoiceButtonsProps } from './components/app/choice-buttons.js';
|
|
22
22
|
export { ReferenceCombobox, type ReferenceComboboxProps, type ReferenceRecord } from './components/app/reference-combobox.js';
|
|
23
23
|
export { fieldRows, type FieldKind, type FieldRowItem, type FieldRowPlace, type FieldSize } from './lib/field-rows.js';
|
|
24
|
-
export { KeyStats, type KeyStat, type KeyStatsProps } from './components/app/key-stats.js';
|
|
24
|
+
export { KeyStats, type KeyStat, type KeyStatAction, type KeyStatsProps } from './components/app/key-stats.js';
|
|
25
|
+
export { ActionHint, type ActionHintProps } from './components/app/action-hint.js';
|
|
25
26
|
export { StatusMark, type StatusMarkProps } from './components/app/status-mark.js';
|
|
26
27
|
export { STATUS_KINDS, STATUS_KIND_ICONS, STATUS_KIND_LABELS, STATUS_KIND_TONES, type StatusKind, } from './lib/status-kinds.js';
|
|
27
28
|
export { EmptyText, type EmptyTextProps } from './components/app/empty-value.js';
|
|
@@ -100,13 +101,13 @@ export { DEFAULT_IMAGE_TYPES, type ImageUpload, type ImageUploadResult } from '.
|
|
|
100
101
|
export { formatPlainDate, parsePlainDate, plainDateExamples, unreadableDateMessage, type ParsePlainDateOptions, type PlainDate, } from './lib/plain-date.js';
|
|
101
102
|
export { formatMonthDay, isMonthDay, monthDayProblem, type MonthDay } from './lib/month-day.js';
|
|
102
103
|
export { RecurrenceField, type RecurrenceFieldProps } from './components/app/recurrence-field.js';
|
|
103
|
-
export { atLocal, formatRule, nextAfterCompletion, nextOccurrence, nextOccurrences, normalizeRecurrence, parseRule, RecurrenceError, recurrenceFromWeekdays, recurrenceProblem, type Recurrence, type RuleParts, } from './lib/recurrence.js';
|
|
104
|
-
export { parseRecurrencePhrase, recurrencePhrase, type PhraseOptions, type PhraseResult, } from './lib/recurrence-phrase.js';
|
|
104
|
+
export { atLocal, formatRule, nextAfterCompletion, nextOccurrence, nextOccurrences, normalizeRecurrence, parseRule, RecurrenceError, recurrenceFromWeekdays, recurrenceProblem, weekStartMatters, type Recurrence, type RuleParts, type WeekdayCode, } from './lib/recurrence.js';
|
|
105
|
+
export { parseRecurrencePhrase, recurrencePhrase, type PhraseOptions, type PhraseResult, type RecurrencePhraseOptions, } from './lib/recurrence-phrase.js';
|
|
105
106
|
export { formatOccurrence, formatRecurrence, todayIn, type OccurrenceFormatOptions, type RecurrenceFormatOptions, } from './lib/recurrence-format.js';
|
|
106
107
|
export { ChoiceCell, LinkCell, LinkOut, NameCell, type ChoiceCellProps, type LinkCellProps, type NameCellProps, } from './components/app/row-edit-cells.js';
|
|
107
108
|
export { ModuleCard, ModuleStrip, type CategorySlot, type ModuleCardLink, type ModuleCardPlace, type ModuleCardProps, type ModuleStripMobile, type ModuleStripProps, } from './components/app/module-card.js';
|
|
108
109
|
export { WidgetCard, WidgetCardGroup, WidgetList, WidgetListItem, type WidgetCardGroupProps, type WidgetCardLink, type WidgetCardProps, type WidgetListItemProps, } from './components/app/widget-card.js';
|
|
109
|
-
export { OverviewPage, type OverviewPageProps, type OverviewPart } from './components/app/overview-page.js';
|
|
110
|
+
export { OverviewPage, type OverviewLink, type OverviewPageProps, type OverviewPart } from './components/app/overview-page.js';
|
|
110
111
|
export { WidgetLayoutSheet, type WidgetLayoutSheetProps } from './components/app/widget-layout-sheet.js';
|
|
111
112
|
export { ThemeProvider } from './components/theme-provider.js';
|
|
112
113
|
export { LoginRoute, type LoginRouteProps } from './routes/login.js';
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ export { ChoiceButtons } from './components/app/choice-buttons.js';
|
|
|
26
26
|
export { ReferenceCombobox } from './components/app/reference-combobox.js';
|
|
27
27
|
export { fieldRows } from './lib/field-rows.js';
|
|
28
28
|
export { KeyStats } from './components/app/key-stats.js';
|
|
29
|
+
export { ActionHint } from './components/app/action-hint.js';
|
|
29
30
|
export { StatusMark } from './components/app/status-mark.js';
|
|
30
31
|
export { STATUS_KINDS, STATUS_KIND_ICONS, STATUS_KIND_LABELS, STATUS_KIND_TONES, } from './lib/status-kinds.js';
|
|
31
32
|
// The record's empty value (4.96): a muted dash read as "Not set", for an
|
|
@@ -106,7 +107,7 @@ export { DEFAULT_IMAGE_TYPES } from './lib/image-file.js';
|
|
|
106
107
|
export { formatPlainDate, parsePlainDate, plainDateExamples, unreadableDateMessage, } from './lib/plain-date.js';
|
|
107
108
|
export { formatMonthDay, isMonthDay, monthDayProblem } from './lib/month-day.js';
|
|
108
109
|
export { RecurrenceField } from './components/app/recurrence-field.js';
|
|
109
|
-
export { atLocal, formatRule, nextAfterCompletion, nextOccurrence, nextOccurrences, normalizeRecurrence, parseRule, RecurrenceError, recurrenceFromWeekdays, recurrenceProblem, } from './lib/recurrence.js';
|
|
110
|
+
export { atLocal, formatRule, nextAfterCompletion, nextOccurrence, nextOccurrences, normalizeRecurrence, parseRule, RecurrenceError, recurrenceFromWeekdays, recurrenceProblem, weekStartMatters, } from './lib/recurrence.js';
|
|
110
111
|
export { parseRecurrencePhrase, recurrencePhrase, } from './lib/recurrence-phrase.js';
|
|
111
112
|
export { formatOccurrence, formatRecurrence, todayIn, } from './lib/recurrence-format.js';
|
|
112
113
|
export { ChoiceCell, LinkCell, LinkOut, NameCell, } from './components/app/row-edit-cells.js';
|
|
@@ -1,25 +1,34 @@
|
|
|
1
|
-
import { type Recurrence } from './recurrence.js';
|
|
1
|
+
import { type Recurrence, type WeekdayCode } from './recurrence.js';
|
|
2
2
|
export type RecurrenceFormatOptions = {
|
|
3
3
|
locale?: string;
|
|
4
4
|
/** Leave the times out ("Every 2nd Tue"), for a cell beside a separate time. */
|
|
5
5
|
times?: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* The app's week start (4.114; Monday when left out). An every-N-weeks
|
|
8
|
+
* rule whose WKST differs says so: "Every other week on Sun and Wed,
|
|
9
|
+
* weeks start Sun".
|
|
10
|
+
*/
|
|
11
|
+
weekStart?: WeekdayCode;
|
|
6
12
|
};
|
|
7
13
|
/**
|
|
8
14
|
* The repeat's label: its days, "after done" when it repeats from
|
|
9
15
|
* completion, its times, and how it ends. "Every 2nd Tue at 9:00 AM",
|
|
10
16
|
* "Every 3 days after done, at 9:00 AM", "Every weekday at 8:00 AM and
|
|
11
|
-
* 5:30 PM, until Mar 1, 2027", "Every day at 9:00 AM, 10 times"
|
|
12
|
-
* it
|
|
17
|
+
* 5:30 PM, until Mar 1, 2027", "Every day at 9:00 AM, 10 times", and the
|
|
18
|
+
* week start when it matters and isn't the app's ("Every other week on Sun
|
|
19
|
+
* and Wed, weeks start Sun"). A rule it can't read shows as stored.
|
|
13
20
|
*/
|
|
14
21
|
export declare function formatRecurrence(value: Recurrence, options?: RecurrenceFormatOptions): string;
|
|
15
22
|
export type OccurrenceFormatOptions = {
|
|
16
23
|
locale?: string;
|
|
17
24
|
/** What "now" is, for leaving out this year. Defaults to the clock. */
|
|
18
25
|
now?: Date;
|
|
26
|
+
/** Leave the time out ("Tue, Dec 8"), for a record whose times are its own (4.114). */
|
|
27
|
+
time?: boolean;
|
|
19
28
|
};
|
|
20
29
|
/**
|
|
21
30
|
* One occurrence's day and time in the rule's zone: "Tue, Dec 8, 9:00 AM",
|
|
22
|
-
* with the year when it isn't this year's
|
|
31
|
+
* with the year when it isn't this year's; "Tue, Dec 8" with `time: false`.
|
|
23
32
|
*/
|
|
24
33
|
export declare function formatOccurrence(moment: Date, timeZone: string, options?: OccurrenceFormatOptions): string;
|
|
25
34
|
/** Today's date in `timeZone`, `'YYYY-MM-DD'`: where a phrase's days count from. */
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// locale given (the browser's when left out); the words around them are
|
|
6
6
|
// English, like the rest of the package.
|
|
7
7
|
import { listWords, ordinalWord } from './recurrence-phrase.js';
|
|
8
|
-
import { parseRule, wallClock } from './recurrence.js';
|
|
8
|
+
import { parseRule, wallClock, WEEKDAY_CODES, weekStartMatters } from './recurrence.js';
|
|
9
9
|
const WEEKDAYS_MO_FR = [0, 1, 2, 3, 4];
|
|
10
10
|
function dayName(day, locale, width = 'short') {
|
|
11
11
|
// 2024-01-01 was a Monday.
|
|
@@ -45,7 +45,10 @@ function days(parts, start, locale) {
|
|
|
45
45
|
return `${every(parts, 'day')}${inMonths}`;
|
|
46
46
|
case 'WEEKLY': {
|
|
47
47
|
const chosen = weekdays.length ? weekdays : [startWeekday];
|
|
48
|
-
|
|
48
|
+
// From the week's first day: "Sun and Wed" when weeks start on Sunday.
|
|
49
|
+
const first = parts.weekStart ?? 0;
|
|
50
|
+
const inWeek = [...chosen].sort((a, b) => ((a - first + 7) % 7) - ((b - first + 7) % 7));
|
|
51
|
+
const names = listWords(inWeek.map((day) => dayName(day, locale)));
|
|
49
52
|
if (parts.interval === 1) {
|
|
50
53
|
if (chosen.join() === WEEKDAYS_MO_FR.join())
|
|
51
54
|
return `Every weekday${inMonths}`;
|
|
@@ -92,8 +95,9 @@ function monthName(month, locale) {
|
|
|
92
95
|
* The repeat's label: its days, "after done" when it repeats from
|
|
93
96
|
* completion, its times, and how it ends. "Every 2nd Tue at 9:00 AM",
|
|
94
97
|
* "Every 3 days after done, at 9:00 AM", "Every weekday at 8:00 AM and
|
|
95
|
-
* 5:30 PM, until Mar 1, 2027", "Every day at 9:00 AM, 10 times"
|
|
96
|
-
* it
|
|
98
|
+
* 5:30 PM, until Mar 1, 2027", "Every day at 9:00 AM, 10 times", and the
|
|
99
|
+
* week start when it matters and isn't the app's ("Every other week on Sun
|
|
100
|
+
* and Wed, weeks start Sun"). A rule it can't read shows as stored.
|
|
97
101
|
*/
|
|
98
102
|
export function formatRecurrence(value, options = {}) {
|
|
99
103
|
let parts;
|
|
@@ -114,11 +118,15 @@ export function formatRecurrence(value, options = {}) {
|
|
|
114
118
|
label += `, until ${plainDay(parts.until, locale)}`;
|
|
115
119
|
if (parts.count !== null)
|
|
116
120
|
label += `, ${parts.count} ${parts.count === 1 ? 'time' : 'times'}`;
|
|
121
|
+
const weekStart = parts.weekStart ?? 0;
|
|
122
|
+
if (weekStartMatters(parts) && weekStart !== WEEKDAY_CODES.indexOf(options.weekStart ?? 'MO')) {
|
|
123
|
+
label += `, weeks start ${dayName(weekStart, locale)}`;
|
|
124
|
+
}
|
|
117
125
|
return label;
|
|
118
126
|
}
|
|
119
127
|
/**
|
|
120
128
|
* One occurrence's day and time in the rule's zone: "Tue, Dec 8, 9:00 AM",
|
|
121
|
-
* with the year when it isn't this year's
|
|
129
|
+
* with the year when it isn't this year's; "Tue, Dec 8" with `time: false`.
|
|
122
130
|
*/
|
|
123
131
|
export function formatOccurrence(moment, timeZone, options = {}) {
|
|
124
132
|
const thisYear = wallClock(options.now ?? new Date(), timeZone).day.slice(0, 4);
|
|
@@ -129,8 +137,7 @@ export function formatOccurrence(moment, timeZone, options = {}) {
|
|
|
129
137
|
month: 'short',
|
|
130
138
|
day: 'numeric',
|
|
131
139
|
year: year === thisYear ? undefined : 'numeric',
|
|
132
|
-
hour: 'numeric',
|
|
133
|
-
minute: '2-digit',
|
|
140
|
+
...(options.time === false ? {} : { hour: 'numeric', minute: '2-digit' }),
|
|
134
141
|
}).format(moment);
|
|
135
142
|
}
|
|
136
143
|
/** Today's date in `timeZone`, `'YYYY-MM-DD'`: where a phrase's days count from. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Recurrence } from './recurrence.js';
|
|
1
|
+
import { type Recurrence, type WeekdayCode } from './recurrence.js';
|
|
2
2
|
export type PhraseOptions = {
|
|
3
3
|
/** Today, `'YYYY-MM-DD'` in the rule's zone: where a day with no year counts from. */
|
|
4
4
|
today: string;
|
|
@@ -8,6 +8,18 @@ export type PhraseOptions = {
|
|
|
8
8
|
times?: string[];
|
|
9
9
|
/** The start when the phrase has no "starting". Defaults to `today`. */
|
|
10
10
|
start?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The day weeks start on (4.114): a weekly rule read with no "weeks
|
|
13
|
+
* start" gets it as its WKST (`'SU'` adds `WKST=SU`). Defaults to
|
|
14
|
+
* Monday, which is no WKST.
|
|
15
|
+
*/
|
|
16
|
+
weekStart?: WeekdayCode;
|
|
17
|
+
/**
|
|
18
|
+
* Whether the phrase may say its times ("at 9am"; the default). False
|
|
19
|
+
* refuses them, for a record whose times are fields of its own: the
|
|
20
|
+
* rule keeps `times` (or 09:00).
|
|
21
|
+
*/
|
|
22
|
+
readTimes?: boolean;
|
|
11
23
|
};
|
|
12
24
|
export type PhraseResult = {
|
|
13
25
|
ok: true;
|
|
@@ -23,11 +35,21 @@ export type PhraseResult = {
|
|
|
23
35
|
export declare function parseRecurrencePhrase(text: string, options: PhraseOptions): PhraseResult;
|
|
24
36
|
declare const ordinal: (value: number) => string;
|
|
25
37
|
declare const listWords: (words: string[], and?: string) => string;
|
|
38
|
+
export type RecurrencePhraseOptions = {
|
|
39
|
+
/** Leave out "at …" (false), for a field whose times are the record's own. */
|
|
40
|
+
times?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* The week start the phrase is read back with (PhraseOptions'
|
|
43
|
+
* `weekStart`; Monday when left out). An every-N-weeks rule whose WKST
|
|
44
|
+
* differs says it: "…, weeks start sun".
|
|
45
|
+
*/
|
|
46
|
+
weekStart?: WeekdayCode;
|
|
47
|
+
};
|
|
26
48
|
/**
|
|
27
49
|
* The Recurrence as a phrase parseRecurrencePhrase reads back to it
|
|
28
50
|
* ("every 2nd tue at 9am until mar 1"), or null for a rule it can't say
|
|
29
51
|
* (several month days, BYMONTH on a daily rule). The start is said only
|
|
30
52
|
* when it's after `today`.
|
|
31
53
|
*/
|
|
32
|
-
export declare function recurrencePhrase(value: Recurrence, today?: string): string | null;
|
|
54
|
+
export declare function recurrencePhrase(value: Recurrence, today?: string, options?: RecurrencePhraseOptions): string | null;
|
|
33
55
|
export { ordinal as ordinalWord, listWords };
|