@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.
Files changed (34) hide show
  1. package/bin/ui-foundation.mjs +28 -3
  2. package/conventions/docs/add-an-entity.md +39 -19
  3. package/conventions/docs/cell-patterns.md +8 -4
  4. package/conventions/docs/design-language.md +51 -11
  5. package/conventions/docs/entity-plan-template.md +3 -1
  6. package/conventions/docs/reminders.md +29 -1
  7. package/dist/api/schema.d.ts +1 -1
  8. package/dist/components/app/action-hint.d.ts +9 -0
  9. package/dist/components/app/action-hint.js +22 -0
  10. package/dist/components/app/edit-in-place-presets.d.ts +5 -1
  11. package/dist/components/app/edit-in-place-presets.js +2 -2
  12. package/dist/components/app/entity-view-facts.d.ts +19 -2
  13. package/dist/components/app/entity-view-facts.js +8 -4
  14. package/dist/components/app/entity-view.js +4 -20
  15. package/dist/components/app/fact-extras.d.ts +16 -0
  16. package/dist/components/app/fact-extras.js +49 -0
  17. package/dist/components/app/key-stats.d.ts +11 -0
  18. package/dist/components/app/key-stats.js +3 -1
  19. package/dist/components/app/list-header.d.ts +8 -1
  20. package/dist/components/app/list-header.js +18 -5
  21. package/dist/components/app/overview-page.d.ts +13 -1
  22. package/dist/components/app/overview-page.js +14 -2
  23. package/dist/components/app/recurrence-field.d.ts +15 -2
  24. package/dist/components/app/recurrence-field.js +54 -13
  25. package/dist/index.d.ts +5 -4
  26. package/dist/index.js +2 -1
  27. package/dist/lib/recurrence-format.d.ts +13 -4
  28. package/dist/lib/recurrence-format.js +14 -7
  29. package/dist/lib/recurrence-phrase.d.ts +24 -2
  30. package/dist/lib/recurrence-phrase.js +26 -8
  31. package/dist/lib/recurrence.d.ts +16 -1
  32. package/dist/lib/recurrence.js +29 -2
  33. package/openapi/foundation.yaml +9 -2
  34. package/package.json +1 -1
@@ -13,9 +13,10 @@
13
13
  // - a day of the year: `jan 1`, `1 jan`
14
14
  //
15
15
  // then, in any order: `at 9am, 5:30pm` (`noon`, `17:00`), `starting dec 1`
16
- // (`from`), `until mar 1` (`ending`), `for 10 times`. A day with no year is
17
- // the next one: from today for `starting`, from the start for `until`.
18
- import { normalizeRecurrence, RecurrenceError, formatRule, parseRule, WEEKDAY_CODES } from './recurrence.js';
16
+ // (`from`), `until mar 1` (`ending`), `for 10 times`, `weeks start sun`
17
+ // (WKST, 4.114). A day with no year is the next one: from today for
18
+ // `starting`, from the start for `until`.
19
+ import { formatRule, normalizeRecurrence, parseRule, RecurrenceError, WEEKDAY_CODES, weekStartMatters, } from './recurrence.js';
19
20
  const WEEKDAY_WORDS = [
20
21
  [/^mon(day)?$/, 0],
21
22
  [/^tue(s|sday)?$/, 1],
@@ -306,6 +307,7 @@ function readPhrase(text, options) {
306
307
  let untilAt;
307
308
  let untilText;
308
309
  let count = null;
310
+ let weekStart;
309
311
  const seen = new Set();
310
312
  const once = (word) => {
311
313
  if (seen.has(word))
@@ -316,7 +318,14 @@ function readPhrase(text, options) {
316
318
  reader.read(',');
317
319
  if (reader.done)
318
320
  break;
319
- if (reader.read('at')) {
321
+ const week = reader.read(String.raw `weeks?\s+(?:start|starts|starting|begin|begins|beginning)(?:\s+on)?\s+(${WEEKDAY})`);
322
+ if (week) {
323
+ once('weeks start');
324
+ weekStart = weekdayOf(week[1]);
325
+ }
326
+ else if (reader.read('at')) {
327
+ if (options.readTimes === false)
328
+ throw new Refusal('The times are set on their own here: leave out “at …”.');
320
329
  once('at');
321
330
  times = readTimes(reader);
322
331
  }
@@ -353,8 +362,9 @@ function readPhrase(text, options) {
353
362
  }
354
363
  const first = start ?? options.start ?? options.today;
355
364
  const until = untilText === undefined ? null : readDate(new Reader(untilText), first, 'until');
365
+ const defaultStart = body.freq === 'WEEKLY' && options.weekStart ? WEEKDAY_CODES.indexOf(options.weekStart) : 0;
356
366
  return normalizeRecurrence({
357
- rule: formatRule({ ...body, until, count }),
367
+ rule: formatRule({ ...body, until, count, weekStart: weekStart ?? defaultStart }),
358
368
  start: first,
359
369
  times: times ?? options.times ?? ['09:00'],
360
370
  timeZone: options.timeZone,
@@ -385,6 +395,9 @@ function phraseDate(day, today) {
385
395
  const WEEKDAYS_MO_FR = 'MO,TU,WE,TH,FR';
386
396
  /** The days part of a rule as a phrase ("every 2nd tue"), or null for one the reader can't write. */
387
397
  function phraseBody(parts) {
398
+ const first = parts.weekStart ?? 0;
399
+ // A week's days from its first day: "on sun and wed" when weeks start on Sunday.
400
+ const inWeek = (days) => [...days].sort((a, b) => ((a.day - first + 7) % 7) - ((b.day - first + 7) % 7));
388
401
  const { freq, interval, byDay, byMonthDay, byMonth } = parts;
389
402
  const codes = byDay.map(({ day }) => WEEKDAY_CODES[day]).join(',');
390
403
  const plain = byDay.every(({ nth }) => nth === null);
@@ -400,7 +413,7 @@ function phraseBody(parts) {
400
413
  return every;
401
414
  if (!plain)
402
415
  return null;
403
- const names = listWords(byDay.map(({ day }) => DAY_WORDS[day]));
416
+ const names = listWords(inWeek(byDay).map(({ day }) => DAY_WORDS[day]));
404
417
  if (interval === 1)
405
418
  return codes === WEEKDAYS_MO_FR ? 'weekday' : codes === 'SA,SU' ? 'weekend' : names;
406
419
  return `${every} on ${names}`;
@@ -442,7 +455,7 @@ function phraseBody(parts) {
442
455
  * (several month days, BYMONTH on a daily rule). The start is said only
443
456
  * when it's after `today`.
444
457
  */
445
- export function recurrencePhrase(value, today) {
458
+ export function recurrencePhrase(value, today, options = {}) {
446
459
  let parts;
447
460
  try {
448
461
  parts = parseRule(value.rule);
@@ -454,13 +467,18 @@ export function recurrencePhrase(value, today) {
454
467
  if (body === null)
455
468
  return null;
456
469
  const words = [`${value.fromCompletion ? 'every!' : 'every'} ${body}`];
457
- words.push(`at ${value.times.map(phraseTime).join(', ')}`);
470
+ if (options.times !== false)
471
+ words.push(`at ${value.times.map(phraseTime).join(', ')}`);
458
472
  if (today && value.start > today)
459
473
  words.push(`starting ${phraseDate(value.start, today)}`);
460
474
  if (parts.until)
461
475
  words.push(`until ${phraseDate(parts.until, today && value.start > today ? value.start : today)}`);
462
476
  if (parts.count !== null)
463
477
  words.push(`for ${parts.count} times`);
478
+ const weekStart = parts.weekStart ?? 0;
479
+ if (weekStartMatters(parts) && weekStart !== WEEKDAY_CODES.indexOf(options.weekStart ?? 'MO')) {
480
+ return `${words.join(' ')}, weeks start ${DAY_WORDS[weekStart]}`;
481
+ }
464
482
  return words.join(' ');
465
483
  }
466
484
  export { ordinal as ordinalWord, listWords };
@@ -5,6 +5,8 @@ export declare const FREQUENCIES: readonly ["DAILY", "WEEKLY", "MONTHLY", "YEARL
5
5
  export type Frequency = (typeof FREQUENCIES)[number];
6
6
  /** RFC 5545's weekday codes, Monday first (Monday is 0 everywhere here). */
7
7
  export declare const WEEKDAY_CODES: readonly ["MO", "TU", "WE", "TH", "FR", "SA", "SU"];
8
+ /** A weekday's code, `'MO'` to `'SU'`: a week start (WKST) as an app gives it. */
9
+ export type WeekdayCode = (typeof WEEKDAY_CODES)[number];
8
10
  export type ByDay = {
9
11
  nth: number | null;
10
12
  day: number;
@@ -18,6 +20,12 @@ export type RuleParts = {
18
20
  byMonth: number[];
19
21
  until: string | null;
20
22
  count: number | null;
23
+ /**
24
+ * WKST: the day weeks start on (Monday 0 to Sunday 6), or null for
25
+ * Monday, RFC 5545's default. `WKST=MO` reads as null, so it isn't stored.
26
+ * Optional (4.114), so parts an app builds without it still are parts.
27
+ */
28
+ weekStart?: number | null;
21
29
  };
22
30
  /** What's wrong with a rule or a recurrence, in words a person can act on. */
23
31
  export declare class RecurrenceError extends Error {
@@ -27,7 +35,7 @@ export declare function parseRule(text: string): RuleParts;
27
35
  /**
28
36
  * The stored form, its parts always in one order (so two rules that mean
29
37
  * the same are the same text): FREQ, INTERVAL (left out at 1), BYMONTH,
30
- * BYMONTHDAY, BYDAY, UNTIL, COUNT.
38
+ * BYMONTHDAY, BYDAY, UNTIL, COUNT, WKST (left out for Monday).
31
39
  */
32
40
  export declare function formatRule(parts: RuleParts): string;
33
41
  /** Whether `name` is an IANA zone this browser knows. */
@@ -68,6 +76,13 @@ export declare function nextOccurrence(value: Recurrence, after: Date): Date | n
68
76
  * first one after that day. A schedule rule's is just its next.
69
77
  */
70
78
  export declare function nextAfterCompletion(value: Recurrence, doneAt: Date): Date | null;
79
+ /**
80
+ * Whether the rule's WKST can change the days it falls on: only an
81
+ * every-N-weeks rule (`FREQ=WEEKLY`, INTERVAL over 1) with BYDAY counts
82
+ * its weeks from a week's first day. (BYWEEKNO, the other part it moves,
83
+ * isn't supported.)
84
+ */
85
+ export declare function weekStartMatters(parts: Pick<RuleParts, 'freq' | 'interval' | 'byDay'>): boolean;
71
86
  /**
72
87
  * The rule for a weekday set and one time (Monday 0, or `'mon,wed,fri'`
73
88
  * as the reminders table stores it), exactly: due on the same days at the
@@ -16,6 +16,12 @@
16
16
  // month doesn't have is skipped: the 31st falls only in months with 31
17
17
  // days, Feb 29 only in leap years, and -1 is every month's last day. COUNT
18
18
  // counts occurrences, each time of each day.
19
+ //
20
+ // WKST (4.114) says which day a week starts on, for the weeks an
21
+ // every-N-weeks rule counts: `FREQ=WEEKLY;INTERVAL=2;BYDAY=SU,WE;WKST=SU`
22
+ // from Wednesday 2026-11-04 next falls on Sunday the 15th (with weeks from
23
+ // Monday, the default, on the 8th). It changes nothing else here; a rule
24
+ // without it counts weeks from Monday, as before.
19
25
  import * as rruleModule from 'rrule';
20
26
  // rrule ships an ES module build without `"type": "module"`: a bundler reads
21
27
  // its named exports, Node its UMD build, whose exports sit on `default`.
@@ -31,7 +37,7 @@ const TIME = /^([01]\d|2[0-3]):[0-5]\d$/;
31
37
  const BYDAY = /^([+-]?[1-5])?(MO|TU|WE|TH|FR|SA|SU)$/;
32
38
  const UNTIL = /^(\d{4})(\d{2})(\d{2})$/;
33
39
  const DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
34
- const PARTS = new Set(['FREQ', 'INTERVAL', 'BYDAY', 'BYMONTHDAY', 'BYMONTH', 'UNTIL', 'COUNT']);
40
+ const PARTS = new Set(['FREQ', 'INTERVAL', 'BYDAY', 'BYMONTHDAY', 'BYMONTH', 'UNTIL', 'COUNT', 'WKST']);
35
41
  // How far ahead a rule must fall at least once (a 31st of February never does).
36
42
  const HORIZON_YEARS = 28;
37
43
  const DAY_MS = 86_400_000;
@@ -96,6 +102,13 @@ export function parseRule(text) {
96
102
  const count = fields.has('COUNT') ? integers('COUNT', fields.get('COUNT'), 1, 9999)[0] : null;
97
103
  if (until !== null && count !== null)
98
104
  throw new RecurrenceError('A rule has UNTIL or COUNT, not both.');
105
+ let weekStart = null;
106
+ if (fields.has('WKST')) {
107
+ const day = WEEKDAY_CODES.indexOf(fields.get('WKST'));
108
+ if (day < 0)
109
+ throw new RecurrenceError('WKST must be a weekday, MO to SU.');
110
+ weekStart = day === 0 ? null : day;
111
+ }
99
112
  return {
100
113
  freq,
101
114
  interval,
@@ -104,12 +117,13 @@ export function parseRule(text) {
104
117
  byMonth: byMonth.sort((a, b) => a - b),
105
118
  until,
106
119
  count,
120
+ weekStart,
107
121
  };
108
122
  }
109
123
  /**
110
124
  * The stored form, its parts always in one order (so two rules that mean
111
125
  * the same are the same text): FREQ, INTERVAL (left out at 1), BYMONTH,
112
- * BYMONTHDAY, BYDAY, UNTIL, COUNT.
126
+ * BYMONTHDAY, BYDAY, UNTIL, COUNT, WKST (left out for Monday).
113
127
  */
114
128
  export function formatRule(parts) {
115
129
  const out = [`FREQ=${parts.freq}`];
@@ -125,6 +139,8 @@ export function formatRule(parts) {
125
139
  out.push(`UNTIL=${parts.until.replaceAll('-', '')}`);
126
140
  if (parts.count !== null)
127
141
  out.push(`COUNT=${parts.count}`);
142
+ if (parts.weekStart)
143
+ out.push(`WKST=${WEEKDAY_CODES[parts.weekStart]}`);
128
144
  return out.join(';');
129
145
  }
130
146
  function isRealDay(value) {
@@ -226,6 +242,8 @@ function* days(parts, start, stop) {
226
242
  bymonthday: parts.byMonthDay.length ? parts.byMonthDay : null,
227
243
  bymonth: parts.byMonth.length ? parts.byMonth : null,
228
244
  until: last ? toUtcDay(last) : null,
245
+ // Monday (rrule's default) when the rule has no WKST.
246
+ wkst: parts.weekStart ?? 0,
229
247
  });
230
248
  let given = 0;
231
249
  for (let limit = 64;; limit *= 4) {
@@ -340,6 +358,15 @@ export function nextAfterCompletion(value, doneAt) {
340
358
  return null;
341
359
  }
342
360
  // ------------------------------------------ a weekday set and one time
361
+ /**
362
+ * Whether the rule's WKST can change the days it falls on: only an
363
+ * every-N-weeks rule (`FREQ=WEEKLY`, INTERVAL over 1) with BYDAY counts
364
+ * its weeks from a week's first day. (BYWEEKNO, the other part it moves,
365
+ * isn't supported.)
366
+ */
367
+ export function weekStartMatters(parts) {
368
+ return parts.freq === 'WEEKLY' && parts.interval > 1 && parts.byDay.length > 0;
369
+ }
343
370
  const DAY_NAMES = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
344
371
  /**
345
372
  * The rule for a weekday set and one time (Monday 0, or `'mon,wed,fri'`
@@ -348,13 +348,20 @@ components:
348
348
  type: string
349
349
  minLength: 1
350
350
  maxLength: 200
351
- pattern: "^FREQ=(DAILY|WEEKLY|MONTHLY|YEARLY)(;(INTERVAL|BYMONTH|BYMONTHDAY|BYDAY|UNTIL|COUNT)=[A-Z0-9,+-]+)*$"
351
+ pattern: "^FREQ=(DAILY|WEEKLY|MONTHLY|YEARLY)(;(INTERVAL|BYMONTH|BYMONTHDAY|BYDAY|UNTIL|COUNT|WKST)=[A-Z0-9,+-]+)*$"
352
+ # The pattern before WKST (4.95 to 4.113). check-contract still
353
+ # accepts an app's copy with it: such an app can't store WKST,
354
+ # and needn't copy this one until it wants to.
355
+ x-earlier-patterns:
356
+ - "^FREQ=(DAILY|WEEKLY|MONTHLY|YEARLY)(;(INTERVAL|BYMONTH|BYMONTHDAY|BYDAY|UNTIL|COUNT)=[A-Z0-9,+-]+)*$"
352
357
  description: >
353
358
  RFC 5545's RRULE value, without DTSTART: FREQ (daily, weekly,
354
359
  monthly, yearly), INTERVAL, BYMONTH, BYMONTHDAY (-1 is the last
355
360
  day), BYDAY (an nth for monthly and yearly: 2TU, -1FR), UNTIL
356
361
  (a date, YYYYMMDD, the last day it can fall on) or COUNT
357
- (occurrences, each time of each day). "FREQ=MONTHLY;BYDAY=2TU".
362
+ (occurrences, each time of each day), and WKST (the day weeks
363
+ start on, MO when left out: it moves an every-N-weeks rule's
364
+ weeks). "FREQ=MONTHLY;BYDAY=2TU", "FREQ=WEEKLY;INTERVAL=2;BYDAY=SU,WE;WKST=SU".
358
365
  start:
359
366
  type: string
360
367
  format: date
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.118.0",
3
+ "version": "4.120.0",
4
4
  "description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
5
5
  "license": "MIT",
6
6
  "repository": {