@moltenship/calendar-core 1.0.0-rc.2 → 2.0.0-beta.1

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 (3) hide show
  1. package/dist/index.d.mts +51 -141
  2. package/dist/index.mjs +124 -165
  3. package/package.json +15 -5
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { compareInstants, comparePlainDateTimes, comparePlainDates, instantInterval, iteratePlainDates, monthGrid, plainDateInterval, plainDateIntervalContains, plainDateIntervalContainsInterval, plainDateTimeInterval, snapZonedWallTime, validateHalfOpenInterval, weekRange, zonedDayRange, zonedDayTransitions } from "@moltenship/calendar-temporal";
2
2
  import IntervalTree, { IntervalBase } from "@flatten-js/interval-tree";
3
- //#region src/format.ts
3
+ // src/format.ts
4
4
  /**
5
5
  * Intl output with thin and narrow no-break spaces as plain ones. Runtimes disagree on them: Node
6
6
  * 26 puts thin spaces around a range's dash, "Oct 12 – 18", where Chrome puts plain ones, so text
@@ -9,8 +9,7 @@ import IntervalTree, { IntervalBase } from "@flatten-js/interval-tree";
9
9
  function withAsciiSpaces(text) {
10
10
  return text.replace(/[\u2009\u202F]/gu, " ");
11
11
  }
12
- //#endregion
13
- //#region src/ids.ts
12
+ // src/ids.ts
14
13
  function isCalendarEntityId(value) {
15
14
  return typeof value === "string" && value.length > 0 || typeof value === "number" && Number.isFinite(value);
16
15
  }
@@ -23,8 +22,7 @@ function isResourceId(value) {
23
22
  function isAnnotationId(value) {
24
23
  return isCalendarEntityId(value);
25
24
  }
26
- //#endregion
27
- //#region src/events.ts
25
+ // src/events.ts
28
26
  function defineEventAdapter() {
29
27
  return (adapter) => adapter;
30
28
  }
@@ -75,8 +73,7 @@ function validateCalendarEvent(event) {
75
73
  value: event
76
74
  };
77
75
  }
78
- //#endregion
79
- //#region src/internal/interval-index.ts
76
+ // src/internal/interval-index.ts
80
77
  function assertNonEmptyInterval(start, end) {
81
78
  if (start >= end) throw new RangeError("start-not-before-end");
82
79
  }
@@ -119,8 +116,7 @@ var FlattenIntervalIndex = class {
119
116
  function createIntervalIndex(entries) {
120
117
  return new FlattenIntervalIndex(entries);
121
118
  }
122
- //#endregion
123
- //#region src/internal/interval-equality.ts
119
+ // src/internal/interval-equality.ts
124
120
  function intervalsEqual(left, right) {
125
121
  switch (left.kind) {
126
122
  case "timed": return right.kind === "timed" && left.start.equals(right.start) && left.end.equals(right.end) && left.sourceTimeZone === right.sourceTimeZone;
@@ -128,8 +124,7 @@ function intervalsEqual(left, right) {
128
124
  case "floating": return right.kind === "floating" && left.start.equals(right.start) && left.end.equals(right.end);
129
125
  }
130
126
  }
131
- //#endregion
132
- //#region src/internal/lru-cache.ts
127
+ // src/internal/lru-cache.ts
133
128
  var BoundedLruCache = class {
134
129
  #capacity;
135
130
  #values = /* @__PURE__ */ new Map();
@@ -172,8 +167,7 @@ var BoundedLruCache = class {
172
167
  });
173
168
  }
174
169
  };
175
- //#endregion
176
- //#region src/internal/readonly-map.ts
170
+ // src/internal/readonly-map.ts
177
171
  var ReadonlyMapView = class {
178
172
  #map;
179
173
  constructor(map) {
@@ -205,8 +199,7 @@ var ReadonlyMapView = class {
205
199
  return this.#map.values();
206
200
  }
207
201
  };
208
- //#endregion
209
- //#region src/internal/temporal-index-keys.ts
202
+ // src/internal/temporal-index-keys.ts
210
203
  const DAYS_PER_YEAR_KEY = 12n * 32n;
211
204
  const NANOSECONDS_PER_SECOND = 1000000000n;
212
205
  const SECONDS_PER_MINUTE = 60n;
@@ -228,8 +221,7 @@ function plainDateTimeIndexKey(dateTime) {
228
221
  const secondsWithinDay = BigInt(isoDateTime.hour) * MINUTES_PER_HOUR * SECONDS_PER_MINUTE + BigInt(isoDateTime.minute) * SECONDS_PER_MINUTE + BigInt(isoDateTime.second);
229
222
  return isoDateFieldsKey(isoDateTime.year, isoDateTime.month, isoDateTime.day) * NANOSECONDS_PER_DAY + secondsWithinDay * NANOSECONDS_PER_SECOND + nanosecondsWithinSecond;
230
223
  }
231
- //#endregion
232
- //#region src/snapshots/types.ts
224
+ // src/snapshots/types.ts
233
225
  var InvalidCalendarEventSnapshotError = class extends TypeError {
234
226
  issues;
235
227
  constructor(issues) {
@@ -238,8 +230,7 @@ var InvalidCalendarEventSnapshotError = class extends TypeError {
238
230
  this.issues = issues;
239
231
  }
240
232
  };
241
- //#endregion
242
- //#region src/snapshots/event-snapshot.ts
233
+ // src/snapshots/event-snapshot.ts
243
234
  const DEFAULT_QUERY_CACHE_SIZE = 128;
244
235
  function errorMessage(error) {
245
236
  return error instanceof Error ? error.message : String(error);
@@ -401,7 +392,7 @@ function normalizeEvent(event, index, adapter, previous, normalizedById) {
401
392
  message: errorMessage(error)
402
393
  });
403
394
  }
404
- if (typeof eventId === "string" && eventId.length === 0 || typeof eventId === "number" && !Number.isFinite(eventId) || typeof eventId !== "string" && typeof eventId !== "number") return Object.freeze({
395
+ if (!isEventId(eventId)) return Object.freeze({
405
396
  code: "invalid-event-id",
406
397
  event,
407
398
  index
@@ -551,7 +542,7 @@ function normalizeEvent(event, index, adapter, previous, normalizedById) {
551
542
  if (!Array.isArray(value)) throw new TypeError("resource-ids-must-be-an-array");
552
543
  const unique = [];
553
544
  for (const [resourceIndex, resourceId] of value.entries()) {
554
- if (typeof resourceId === "string" && resourceId.length === 0 || typeof resourceId === "number" && !Number.isFinite(resourceId) || typeof resourceId !== "string" && typeof resourceId !== "number") return Object.freeze({
545
+ if (!isResourceId(resourceId)) return Object.freeze({
555
546
  code: "invalid-resource-id",
556
547
  event,
557
548
  eventId,
@@ -691,8 +682,7 @@ function createEventSnapshotCache(adapter, options = {}) {
691
682
  function createEventSnapshot(events, adapter, options = {}) {
692
683
  return createEventSnapshotCacheInternal(adapter, options, false).getSnapshot(events);
693
684
  }
694
- //#endregion
695
- //#region src/projection/visible-events.ts
685
+ // src/projection/visible-events.ts
696
686
  /**
697
687
  * Returns the instants covered by a half-open date range in `timeZone`. Each boundary is the
698
688
  * start of its local day, so a skipped midnight resolves to the first instant that exists.
@@ -716,8 +706,7 @@ function queryVisibleEvents(snapshot, range, timeZone) {
716
706
  ...snapshot.queryFloating(wallTimes)
717
707
  ];
718
708
  }
719
- //#endregion
720
- //#region src/projection/day-fragments.ts
709
+ // src/projection/day-fragments.ts
721
710
  function earlierDate(left, right) {
722
711
  return comparePlainDates(left, right) <= 0 ? left : right;
723
712
  }
@@ -850,8 +839,7 @@ function fragmentsByDate(fragments) {
850
839
  for (const day of byDate.values()) day.sort(compareDayFragments);
851
840
  return byDate;
852
841
  }
853
- //#endregion
854
- //#region src/layout/day-grid.ts
842
+ // src/layout/day-grid.ts
855
843
  function toSegment(range, run) {
856
844
  const first = run[0];
857
845
  const last = run.at(-1);
@@ -932,8 +920,7 @@ function limitDayGridLanes(row, maxLanes) {
932
920
  segments: Object.freeze(visible)
933
921
  });
934
922
  }
935
- //#endregion
936
- //#region src/views/month/month.ts
923
+ // src/views/month/month.ts
937
924
  /** Whole weeks covering the anchor's month; four to six rows depending on the month. */
938
925
  function getMonthRange(anchor, environment) {
939
926
  return monthGrid(anchor, { weekStartsOn: environment.weekRules.firstDay }).range;
@@ -985,8 +972,7 @@ function projectMonthWeeks({ environment, snapshot, today }, range, month) {
985
972
  weeks: Object.freeze(weeks)
986
973
  });
987
974
  }
988
- //#endregion
989
- //#region src/navigation/day-events.ts
975
+ // src/navigation/day-events.ts
990
976
  function dayFocus(date) {
991
977
  return { focus: {
992
978
  date,
@@ -1024,8 +1010,7 @@ function dayEventNavigation(events, focus, command, below) {
1024
1010
  if (command === "up") return index > 0 ? eventFocus(date, events[index - 1]) : dayFocus(date);
1025
1011
  if (command === "down") return index < events.length - 1 ? eventFocus(date, events[index + 1]) : below;
1026
1012
  }
1027
- //#endregion
1028
- //#region src/navigation/month.ts
1013
+ // src/navigation/month.ts
1029
1014
  function entry$1(projection, command) {
1030
1015
  const days = projection.weeks.flatMap((week) => week.days);
1031
1016
  const month = days.filter((day) => day.inMonth);
@@ -1064,8 +1049,7 @@ function monthSpatialNavigation({ command, environment, focus, projection }) {
1064
1049
  const next = moveDate$1(date, command, environment.weekRules.firstDay, environment.direction);
1065
1050
  return next === null ? null : dayFocus(next);
1066
1051
  }
1067
- //#endregion
1068
- //#region src/views/month/scrolling.ts
1052
+ // src/views/month/scrolling.ts
1069
1053
  /** Rows every month fits in: fewer leave a long month's last days on no page at all. */
1070
1054
  const MINIMUM_WEEKS = 6;
1071
1055
  const MAXIMUM_WEEKS = 12;
@@ -1127,8 +1111,7 @@ function scrollingMonthStrategy(weeks = 6) {
1127
1111
  project: (input) => projectMonthWeeks(input, input.loadRange ?? input.range, scrollingMonthOf(input.range))
1128
1112
  });
1129
1113
  }
1130
- //#endregion
1131
- //#region src/views/year/year.ts
1114
+ // src/views/year/year.ts
1132
1115
  const noFragments = Object.freeze([]);
1133
1116
  /** The anchor's calendar year, from January 1 to the next January 1. */
1134
1117
  function getYearRange(anchor) {
@@ -1183,8 +1166,7 @@ function projectYear(input) {
1183
1166
  range
1184
1167
  });
1185
1168
  }
1186
- //#endregion
1187
- //#region src/views/list/list.ts
1169
+ // src/views/list/list.ts
1188
1170
  const DEFAULT_LIST_WEEKS = 4;
1189
1171
  /** The `weeks` option, four by default; anything but a positive whole number throws. */
1190
1172
  function listWeeks(options) {
@@ -1245,8 +1227,7 @@ function projectList(input) {
1245
1227
  range
1246
1228
  });
1247
1229
  }
1248
- //#endregion
1249
- //#region src/navigation/list.ts
1230
+ // src/navigation/list.ts
1250
1231
  function itemsOf(projection) {
1251
1232
  return projection.days.flatMap(({ date, items }, day) => items.map(({ event }) => ({
1252
1233
  date,
@@ -1289,8 +1270,7 @@ function listSpatialNavigation({ command, focus, projection }) {
1289
1270
  default: return null;
1290
1271
  }
1291
1272
  }
1292
- //#endregion
1293
- //#region src/views/list/scrolling.ts
1273
+ // src/views/list/scrolling.ts
1294
1274
  /**
1295
1275
  * An agenda that scrolls through days instead of paging. Its range is `weeks` from the anchor
1296
1276
  * date, the day a view shows on top, since a list comes to rest on any day rather than on a week;
@@ -1329,8 +1309,7 @@ function scrollingListStrategy() {
1329
1309
  })
1330
1310
  });
1331
1311
  }
1332
- //#endregion
1333
- //#region src/annotations/snapshot.ts
1312
+ // src/annotations/snapshot.ts
1334
1313
  function isAnnotation(value) {
1335
1314
  if (typeof value !== "object" || value === null) return false;
1336
1315
  const { end, resourceIds, sourceId, start, title } = value;
@@ -1372,8 +1351,7 @@ function createAnnotationSnapshot(input) {
1372
1351
  query: (start, end) => index.query(start.epochNanoseconds, end.epochNanoseconds)
1373
1352
  });
1374
1353
  }
1375
- //#endregion
1376
- //#region src/annotations/summary.ts
1354
+ // src/annotations/summary.ts
1377
1355
  /** Summarizes a column's marks per source, in source order. */
1378
1356
  function summarizeAnnotationMarks(marks) {
1379
1357
  const bySource = Map.groupBy(marks, (mark) => mark.source);
@@ -1398,8 +1376,7 @@ function summarizeAnnotationMarks(marks) {
1398
1376
  });
1399
1377
  }));
1400
1378
  }
1401
- //#endregion
1402
- //#region src/views/time-grid/geometry.ts
1379
+ // src/views/time-grid/geometry.ts
1403
1380
  const NOMINAL_DAY_NANOSECONDS$1 = 864e11;
1404
1381
  const DAY_NANOSECONDS$6 = 86400000000000n;
1405
1382
  const DEFAULT_SNAP = {
@@ -1501,8 +1478,7 @@ function timeGridDateTimeAt(column, y, options = {}) {
1501
1478
  timeZone: column.day.timeZone
1502
1479
  });
1503
1480
  }
1504
- //#endregion
1505
- //#region src/annotations/time-grid.ts
1481
+ // src/annotations/time-grid.ts
1506
1482
  const DEFAULT_MAX_LANES = 3;
1507
1483
  const DAY_NANOSECONDS$5 = 86400000000000n;
1508
1484
  const NOMINAL_DAY_NANOSECONDS = 864e11;
@@ -1741,8 +1717,7 @@ function projectTimeGridAnnotations(columns, snapshot, sources, geometry = {}) {
1741
1717
  });
1742
1718
  }));
1743
1719
  }
1744
- //#endregion
1745
- //#region src/internal/time-zone-id.ts
1720
+ // src/internal/time-zone-id.ts
1746
1721
  /**
1747
1722
  * A time zone identifier as Temporal spells it, such as "Asia/Tokyo" for "asia/tokyo", or `null`
1748
1723
  * when it isn't one. Only identifiers pass: an ISO date-time string with a zone in it doesn't.
@@ -1756,8 +1731,7 @@ function timeZoneIdOf(value) {
1756
1731
  return null;
1757
1732
  }
1758
1733
  }
1759
- //#endregion
1760
- //#region src/availability/schedule.ts
1734
+ // src/availability/schedule.ts
1761
1735
  /** A date's ISO year, month and day, whatever calendar it is in, such as `2026-10-08`. */
1762
1736
  function isoDateKey(date) {
1763
1737
  return date.toString({ calendarName: "never" });
@@ -1842,8 +1816,7 @@ function createAvailabilitySchedule({ exceptions, weekly }, timeZone) {
1842
1816
  unavailable
1843
1817
  });
1844
1818
  }
1845
- //#endregion
1846
- //#region src/availability/snapshot.ts
1819
+ // src/availability/snapshot.ts
1847
1820
  function isHours(value) {
1848
1821
  if (typeof value !== "object" || value === null) return false;
1849
1822
  const { end, start } = value;
@@ -1967,8 +1940,7 @@ function createAvailabilitySnapshot({ availability, resources = [], timeZone })
1967
1940
  timeZone
1968
1941
  });
1969
1942
  }
1970
- //#endregion
1971
- //#region src/availability/busy.ts
1943
+ // src/availability/busy.ts
1972
1944
  /** How far ahead a busy status looks. */
1973
1945
  const HORIZON = { hours: 744 };
1974
1946
  /**
@@ -2061,8 +2033,7 @@ function busyResources(events, range, { exclude, resourceIds, timeZone }) {
2061
2033
  }
2062
2034
  return busy;
2063
2035
  }
2064
- //#endregion
2065
- //#region src/views/resource-timeline/geometry.ts
2036
+ // src/views/resource-timeline/geometry.ts
2066
2037
  const DAY_NANOSECONDS$4 = 86400000000000n;
2067
2038
  function extent(start, end, length) {
2068
2039
  const from = start > 0n ? start : 0n;
@@ -2101,8 +2072,7 @@ function timelinePosition(columns, instant) {
2101
2072
  const position = timeGridPosition(columns, instant);
2102
2073
  return position === null ? null : (position.column + position.top) / columns.length;
2103
2074
  }
2104
- //#endregion
2105
- //#region src/availability/closures.ts
2075
+ // src/availability/closures.ts
2106
2076
  const DAY_NANOSECONDS$3 = 86400000000000n;
2107
2077
  /**
2108
2078
  * Every instant whose wall time can fall on `days` dates from `first`. Offsets stay within ±24
@@ -2176,8 +2146,7 @@ function availabilityClosures(schedule, range) {
2176
2146
  }
2177
2147
  return Object.freeze(closures);
2178
2148
  }
2179
- //#endregion
2180
- //#region src/availability/projection.ts
2149
+ // src/availability/projection.ts
2181
2150
  const noBands = Object.freeze([]);
2182
2151
  /** A closure's reason and label, with its edges open only inside `[0, 1]` of the view. */
2183
2152
  function placed({ label, opensAfter, opensBefore, reason }, start, end, geometry) {
@@ -2281,8 +2250,7 @@ function closedDates(range, schedule, timeZone) {
2281
2250
  }
2282
2251
  return closed;
2283
2252
  }
2284
- //#endregion
2285
- //#region src/availability/status.ts
2253
+ // src/availability/status.ts
2286
2254
  /** How far ahead a status looks for the next change: a week at a time, for a year. */
2287
2255
  const WEEK = { hours: 168 };
2288
2256
  const WEEKS = 53;
@@ -2334,8 +2302,7 @@ function resourceStatusAt(availability, events, at, query) {
2334
2302
  changesAt: changes.sort((left, right) => Temporal.Instant.compare(left, right))[0] ?? null
2335
2303
  });
2336
2304
  }
2337
- //#endregion
2338
- //#region src/resources/tree.ts
2305
+ // src/resources/tree.ts
2339
2306
  function freeze(node, depth, byId) {
2340
2307
  const frozen = Object.freeze({
2341
2308
  children: Object.freeze(node.children.map((child) => freeze(child, depth + 1, byId))),
@@ -2389,8 +2356,7 @@ function createResourceTree(resources) {
2389
2356
  roots: frozenRoots
2390
2357
  });
2391
2358
  }
2392
- //#endregion
2393
- //#region src/resources/visible.ts
2359
+ // src/resources/visible.ts
2394
2360
  const UNASSIGNED = Object.freeze({
2395
2361
  depth: 0,
2396
2362
  expanded: false,
@@ -2456,8 +2422,7 @@ function groupByResource(items, resources) {
2456
2422
  }
2457
2423
  return Object.freeze(groups.map((group) => Object.freeze(group)));
2458
2424
  }
2459
- //#endregion
2460
- //#region src/views.ts
2425
+ // src/views.ts
2461
2426
  /**
2462
2427
  * Resolves visible dates to the instants between their starts of day. `toZonedDateTime` uses the
2463
2428
  * start of day, so a date whose midnight is skipped by a DST gap begins at its first valid instant.
@@ -2475,8 +2440,7 @@ function resolveViewLoadRange(strategy, anchor, environment, options, range) {
2475
2440
  if (!plainDateIntervalContainsInterval(loadRange, range)) throw new RangeError("view-load-range-must-contain-range");
2476
2441
  return loadRange;
2477
2442
  }
2478
- //#endregion
2479
- //#region src/views/time-grid/range.ts
2443
+ // src/views/time-grid/range.ts
2480
2444
  const MAXIMUM_TIME_GRID_DAYS = 7;
2481
2445
  /** The span's number of days; a `days` count outside one to seven throws `RangeError`. */
2482
2446
  function timeGridDayCount(span) {
@@ -2506,8 +2470,7 @@ function timeGridTitle(range, locale) {
2506
2470
  year: "numeric"
2507
2471
  }).formatRange(range.start, last));
2508
2472
  }
2509
- //#endregion
2510
- //#region src/views/time-grid/columns.ts
2473
+ // src/views/time-grid/columns.ts
2511
2474
  function transitionBand(date, transition) {
2512
2475
  const top = columnFraction(date, wallEpochNanoseconds(transition.affectedWallRange.start));
2513
2476
  const bottom = columnFraction(date, wallEpochNanoseconds(transition.affectedWallRange.end));
@@ -2535,8 +2498,7 @@ function timeGridColumns(range, timeZone) {
2535
2498
  }
2536
2499
  return Object.freeze(columns);
2537
2500
  }
2538
- //#endregion
2539
- //#region src/views/time-grid/zones.ts
2501
+ // src/views/time-grid/zones.ts
2540
2502
  const DAY_MINUTES = 1440;
2541
2503
  const MINUTE_NANOSECONDS = 6e10;
2542
2504
  const noTimes = Object.freeze([]);
@@ -2722,8 +2684,7 @@ function timeGridZoneAxis(columns, timeZone, options = {}) {
2722
2684
  timeZone: zone
2723
2685
  });
2724
2686
  }
2725
- //#endregion
2726
- //#region src/layout/timed-overlap.ts
2687
+ // src/layout/timed-overlap.ts
2727
2688
  /**
2728
2689
  * Edges this close count as one, so rounding never makes back-to-back items collide: 10/24 + 1/24,
2729
2690
  * an hour from 10:00 as a share of the day, lands a hair past 11/24.
@@ -2852,8 +2813,7 @@ function layoutTimedOverlaps(items, options = {}) {
2852
2813
  placeGroup(group);
2853
2814
  return Object.freeze(placements);
2854
2815
  }
2855
- //#endregion
2856
- //#region src/views/time-grid/layout.ts
2816
+ // src/views/time-grid/layout.ts
2857
2817
  function fragmentBox(column, fragment) {
2858
2818
  const { event } = fragment;
2859
2819
  return event.kind === "timed" ? timedFragmentBox(column, instantInterval(event.start, event.end)) : wallRangeBox(column, fragment.start, fragment.end);
@@ -2883,8 +2843,7 @@ function layoutTimeGrid(columns, fragments, options) {
2883
2843
  const byDate = Map.groupBy(fragments, (fragment) => fragment.date.toString());
2884
2844
  return Object.freeze(columns.map((column) => layoutColumn(column, byDate.get(column.date.toString()) ?? [], options)));
2885
2845
  }
2886
- //#endregion
2887
- //#region src/transactions/wall-clock.ts
2846
+ // src/transactions/wall-clock.ts
2888
2847
  /** Applies a delta's calendar part on the wall clock, then its time part as exact time. */
2889
2848
  function shiftWallClock(point, delta) {
2890
2849
  const { days = 0, hours = 0, microseconds = 0, milliseconds = 0, minutes = 0, months = 0, nanoseconds = 0, seconds = 0, weeks = 0, years = 0 } = delta;
@@ -2933,8 +2892,7 @@ function withWallClockEndpoints(placement, start, end) {
2933
2892
  start: start.toPlainDateTime()
2934
2893
  };
2935
2894
  }
2936
- //#endregion
2937
- //#region src/transactions/placement.ts
2895
+ // src/transactions/placement.ts
2938
2896
  const DEFAULT_MINIMUM_DURATION = { minutes: 15 };
2939
2897
  function earlier(left, right, compare) {
2940
2898
  return compare(left, right) <= 0 ? left : right;
@@ -3059,8 +3017,7 @@ function isNonEmptyInterval(interval) {
3059
3017
  function placementsEqual(left, right) {
3060
3018
  return intervalsEqual(left, right) && left.resourceIds.length === right.resourceIds.length && left.resourceIds.every((resourceId) => right.resourceIds.includes(resourceId));
3061
3019
  }
3062
- //#endregion
3063
- //#region src/transactions/targets.ts
3020
+ // src/transactions/targets.ts
3064
3021
  /** Length of an all-day event dropped onto a time column. */
3065
3022
  const DROPPED_ALL_DAY_DURATION = { hours: 1 };
3066
3023
  /** One snap increment. */
@@ -3168,8 +3125,7 @@ function createPlacementBetween(anchor, target, { snap }) {
3168
3125
  }
3169
3126
  return null;
3170
3127
  }
3171
- //#endregion
3172
- //#region src/navigation/time-grid.ts
3128
+ // src/navigation/time-grid.ts
3173
3129
  /** A time-grid column's nominal height, which layout fractions measure; exact as a double. */
3174
3130
  const DAY_NANOSECONDS$2 = 864e11;
3175
3131
  const MIDNIGHT$1 = Temporal.PlainTime.from("00:00");
@@ -3377,8 +3333,7 @@ function timeGridSpatialNavigation(input) {
3377
3333
  isToday
3378
3334
  })));
3379
3335
  }
3380
- //#endregion
3381
- //#region src/views/time-grid/projection.ts
3336
+ // src/views/time-grid/projection.ts
3382
3337
  const DAY_NANOSECONDS$1 = 86400000000000n;
3383
3338
  /** Shorter events still reserve a quarter hour, so they stay readable and clickable. */
3384
3339
  const MINIMUM_EVENT_HEIGHT = 15 / 1440;
@@ -3454,8 +3409,7 @@ function timeGridStrategy(span) {
3454
3409
  })
3455
3410
  });
3456
3411
  }
3457
- //#endregion
3458
- //#region src/views/time-grid/scrolling.ts
3412
+ // src/views/time-grid/scrolling.ts
3459
3413
  /**
3460
3414
  * A time grid that scrolls through days instead of paging: the anchor's week, or `count` days
3461
3415
  * starting at the anchor, as `timeGridStrategy` shows them. A view swipes a page at a time, so
@@ -3493,8 +3447,7 @@ function scrollingTimeGridStrategy(span) {
3493
3447
  })
3494
3448
  });
3495
3449
  }
3496
- //#endregion
3497
- //#region src/navigation/resource-columns.ts
3450
+ // src/navigation/resource-columns.ts
3498
3451
  /**
3499
3452
  * Spatial navigation for resource columns from `projectResourceColumns`, laid out resource by
3500
3453
  * resource, each with its dates. Within a column it is `timeGridSpatialNavigation`'s; left and
@@ -3511,8 +3464,7 @@ function resourceColumnsSpatialNavigation(input) {
3511
3464
  resourceId: resource.id
3512
3465
  }))));
3513
3466
  }
3514
- //#endregion
3515
- //#region src/views/resource-columns/projection.ts
3467
+ // src/views/resource-columns/projection.ts
3516
3468
  /**
3517
3469
  * A time grid per visible resource, laid out like `projectTimeGrid`: fragments, overlapping
3518
3470
  * events as the resource's `getResourceOverlapLayout` or else `overlapLayout` chooses, refined by
@@ -3560,8 +3512,7 @@ function resourceColumnsStrategy(span) {
3560
3512
  })
3561
3513
  });
3562
3514
  }
3563
- //#endregion
3564
- //#region src/views/resource-timeline/range.ts
3515
+ // src/views/resource-timeline/range.ts
3565
3516
  function resourceTimelineRange(anchor, span, weekRules) {
3566
3517
  if (span.kind !== "month") return timeGridRange(anchor, span, weekRules);
3567
3518
  const first = anchor.with({ day: 1 });
@@ -3578,8 +3529,7 @@ function resourceTimelineTitle(range, span, locale) {
3578
3529
  year: "numeric"
3579
3530
  }).format(range.start) : timeGridTitle(range, locale);
3580
3531
  }
3581
- //#endregion
3582
- //#region src/navigation/resource-timeline.ts
3532
+ // src/navigation/resource-timeline.ts
3583
3533
  const DAY_NANOSECONDS = 864e11;
3584
3534
  const MIDNIGHT = Temporal.PlainTime.from("00:00");
3585
3535
  function inRow(cell, row) {
@@ -3742,8 +3692,7 @@ function resourceTimelineSpatialNavigation(input) {
3742
3692
  if (focus.kind === "event") return fromEvent(focus, rowIndex, input);
3743
3693
  return fromCell(focus.kind === "day" || projection.unit === "hour" ? focus : cellAt(focus.date, focus.time, input), rowIndex, input);
3744
3694
  }
3745
- //#endregion
3746
- //#region src/views/resource-timeline/projection.ts
3695
+ // src/views/resource-timeline/projection.ts
3747
3696
  /** Shorter events still reserve a quarter hour of the row when lanes are packed. */
3748
3697
  const MINIMUM_EVENT_MINUTES = 15;
3749
3698
  /** How far each level of a stack sits below the one it covers, in lanes. */
@@ -3911,8 +3860,23 @@ function resourceTimelineStrategy(span) {
3911
3860
  })
3912
3861
  });
3913
3862
  }
3914
- //#endregion
3915
- //#region src/history/event-history.ts
3863
+ // src/internal/listeners.ts
3864
+ function createListeners() {
3865
+ const entries = /* @__PURE__ */ new Set();
3866
+ return Object.freeze({
3867
+ notify() {
3868
+ for (const entry of entries) entry.listener();
3869
+ },
3870
+ subscribe(listener) {
3871
+ const entry = { listener };
3872
+ entries.add(entry);
3873
+ return () => {
3874
+ entries.delete(entry);
3875
+ };
3876
+ }
3877
+ });
3878
+ }
3879
+ // src/history/event-history.ts
3916
3880
  const DEFAULT_LIMIT = 100;
3917
3881
  function sameInterval(left, right) {
3918
3882
  switch (left.kind) {
@@ -3967,7 +3931,7 @@ function createEventHistory(options = {}) {
3967
3931
  * the event a new one, which `createdEventId` tells when a step for it is next taken.
3968
3932
  */
3969
3933
  const restores = /* @__PURE__ */ new Map();
3970
- const listeners = /* @__PURE__ */ new Set();
3934
+ const listeners = createListeners();
3971
3935
  function publish(activity) {
3972
3936
  if (activity !== void 0) latest = activity;
3973
3937
  snapshot = Object.freeze({
@@ -3979,7 +3943,7 @@ function createEventHistory(options = {}) {
3979
3943
  step: pending.entry.step
3980
3944
  })
3981
3945
  });
3982
- for (const listener of listeners) listener();
3946
+ listeners.notify();
3983
3947
  }
3984
3948
  function newStep(change, detail) {
3985
3949
  sequence += 1;
@@ -4256,22 +4220,15 @@ function createEventHistory(options = {}) {
4256
4220
  getSnapshot: () => snapshot,
4257
4221
  record,
4258
4222
  redo: (context) => enqueue("redo", context),
4259
- subscribe(listener) {
4260
- listeners.add(listener);
4261
- return () => {
4262
- listeners.delete(listener);
4263
- };
4264
- },
4223
+ subscribe: listeners.subscribe,
4265
4224
  undo: (context) => enqueue("undo", context)
4266
4225
  });
4267
4226
  }
4268
- //#endregion
4269
- //#region src/internal/promise-like.ts
4227
+ // src/internal/promise-like.ts
4270
4228
  function isPromiseLike(value) {
4271
4229
  return typeof value === "object" && value !== null && typeof value.then === "function";
4272
4230
  }
4273
- //#endregion
4274
- //#region src/policies/pipeline.ts
4231
+ // src/policies/pipeline.ts
4275
4232
  function applyDecision(change, decision) {
4276
4233
  if (decision.type === "accept") return change;
4277
4234
  if (decision.type === "reject") return {
@@ -4315,8 +4272,7 @@ function runEventPolicies(change, policies, context) {
4315
4272
  }
4316
4273
  return runFrom(change, 0);
4317
4274
  }
4318
- //#endregion
4319
- //#region src/transactions/overlay.ts
4275
+ // src/transactions/overlay.ts
4320
4276
  function pendingEvent(current, placement) {
4321
4277
  const base = {
4322
4278
  event: current.event,
@@ -4442,9 +4398,11 @@ function applyEventOverlay(snapshot, pending) {
4442
4398
  }
4443
4399
  return patched.size === 0 ? snapshot : new OverlayEventSnapshot(snapshot, patched);
4444
4400
  }
4445
- //#endregion
4446
- //#region src/transactions/event-transactions.ts
4401
+ // src/transactions/event-transactions.ts
4447
4402
  const noPending = new ReadonlyMapView(/* @__PURE__ */ new Map());
4403
+ /** A proposal that names no input is the application's own. */
4404
+ const apiDetail = Object.freeze({ input: "api" });
4405
+ const detailOf = (context) => context.detail ?? apiDetail;
4448
4406
  function createChange(proposal, id, events) {
4449
4407
  if (proposal.cause === "create") {
4450
4408
  const proposed = {
@@ -4482,6 +4440,14 @@ function createChange(proposal, id, events) {
4482
4440
  }
4483
4441
  };
4484
4442
  }
4443
+ function pendingProposal(change, phase, result) {
4444
+ return Object.freeze({
4445
+ change,
4446
+ phase,
4447
+ result,
4448
+ status: "pending"
4449
+ });
4450
+ }
4485
4451
  /**
4486
4452
  * Tracks proposed event changes from validation through persistence. Changes stay visible while
4487
4453
  * the handler runs; a rejection rolls them back, and the latest proposal for an event wins.
@@ -4492,7 +4458,7 @@ function createEventTransactions() {
4492
4458
  const records = /* @__PURE__ */ new Map();
4493
4459
  /** The newest proposal per event; older proposals still being validated are superseded. */
4494
4460
  const latest = /* @__PURE__ */ new Map();
4495
- const listeners = /* @__PURE__ */ new Set();
4461
+ const listeners = createListeners();
4496
4462
  let pending = noPending;
4497
4463
  let changes = noPending;
4498
4464
  let base;
@@ -4504,7 +4470,7 @@ function createEventTransactions() {
4504
4470
  function publish(placements = true, phases = false) {
4505
4471
  if (placements) pending = entries.size === 0 ? noPending : new ReadonlyMapView(new Map(Array.from(entries, ([eventId, entry]) => [eventId, entry.change.proposed])));
4506
4472
  if (phases) changes = records.size === 0 ? noPending : new ReadonlyMapView(new Map(records));
4507
- for (const listener of listeners) listener();
4473
+ listeners.notify();
4508
4474
  }
4509
4475
  function track(change, phase) {
4510
4476
  records.set(change.id, Object.freeze({
@@ -4641,7 +4607,7 @@ function createEventTransactions() {
4641
4607
  }
4642
4608
  let returned;
4643
4609
  try {
4644
- returned = context.onEventChange(change);
4610
+ returned = context.onEventChange(change, detailOf(context));
4645
4611
  } catch (error) {
4646
4612
  hide(change);
4647
4613
  return {
@@ -4690,20 +4656,20 @@ function createEventTransactions() {
4690
4656
  };
4691
4657
  });
4692
4658
  }
4693
- function propose(proposal, context) {
4659
+ function proposeNow(proposal, context) {
4694
4660
  reconcile(context.snapshot);
4695
4661
  sequence += 1;
4696
4662
  const events = applyEventOverlay(context.snapshot, pending);
4697
4663
  const change = createChange(proposal, `change-${sequence}`, events);
4698
- if (change === void 0) return Promise.resolve({
4664
+ if (change === void 0) return {
4699
4665
  reason: "unknown-event",
4700
4666
  status: "rejected"
4701
- });
4702
- if (change.proposed !== null && !isNonEmptyInterval(change.proposed)) return Promise.resolve({
4667
+ };
4668
+ if (change.proposed !== null && !isNonEmptyInterval(change.proposed)) return {
4703
4669
  change,
4704
4670
  reason: "invalid-placement",
4705
4671
  status: "rejected"
4706
- });
4672
+ };
4707
4673
  const revision = change.eventId === null ? void 0 : context.snapshot.get(change.eventId)?.revision;
4708
4674
  if (change.eventId !== null) latest.set(change.eventId, change.id);
4709
4675
  const policyError = (error) => {
@@ -4720,19 +4686,28 @@ function createEventTransactions() {
4720
4686
  try {
4721
4687
  outcome = runEventPolicies(change, context.policies ?? [], {
4722
4688
  availability: context.availability,
4689
+ detail: detailOf(context),
4723
4690
  events,
4724
4691
  timeZone: context.timeZone
4725
4692
  });
4726
- if (!isPromiseLike(outcome)) return Promise.resolve(commit(outcome, revision, context)).then(finish);
4693
+ if (!isPromiseLike(outcome)) {
4694
+ const committed = commit(outcome, revision, context);
4695
+ if (!isPromiseLike(committed)) return finish(committed);
4696
+ return pendingProposal(outcome.change, "saving", committed.then(finish));
4697
+ }
4727
4698
  } catch (error) {
4728
- return Promise.resolve(policyError(error));
4699
+ return policyError(error);
4729
4700
  }
4730
4701
  if (change.cause === "create") track(change, "validating");
4731
4702
  else show(change, {
4732
4703
  revision,
4733
4704
  validating: true
4734
4705
  }, "validating");
4735
- return outcome.then((result) => commit(result, revision, context)).catch(policyError).then(finish);
4706
+ return pendingProposal(change, "validating", outcome.then((result) => commit(result, revision, context)).catch(policyError).then(finish));
4707
+ }
4708
+ function propose(proposal, context) {
4709
+ const outcome = proposeNow(proposal, context);
4710
+ return outcome.status === "pending" ? outcome.result : Promise.resolve(outcome);
4736
4711
  }
4737
4712
  function check(proposal, context) {
4738
4713
  reconcile(context.snapshot);
@@ -4747,6 +4722,7 @@ function createEventTransactions() {
4747
4722
  try {
4748
4723
  const outcome = runEventPolicies(change, context.policies ?? [], {
4749
4724
  availability: context.availability,
4725
+ detail: detailOf(context),
4750
4726
  events,
4751
4727
  timeZone: context.timeZone
4752
4728
  });
@@ -4773,25 +4749,19 @@ function createEventTransactions() {
4773
4749
  getPending: () => pending,
4774
4750
  getPendingChanges: () => changes,
4775
4751
  propose,
4752
+ proposeNow,
4776
4753
  reconcile,
4777
- subscribe(listener) {
4778
- listeners.add(listener);
4779
- return () => {
4780
- listeners.delete(listener);
4781
- };
4782
- }
4754
+ subscribe: listeners.subscribe
4783
4755
  });
4784
4756
  }
4785
- //#endregion
4786
- //#region src/navigation/focus.ts
4757
+ // src/navigation/focus.ts
4787
4758
  function sameFocus(left, right) {
4788
4759
  if (left === null || right === null) return left === right;
4789
4760
  if (left.kind !== right.kind || left.resourceId !== right.resourceId || !left.date.equals(right.date)) return false;
4790
4761
  if (left.kind === "slot") return left.time.equals(right.time);
4791
4762
  return left.kind === "day" || left.eventId === right.eventId;
4792
4763
  }
4793
- //#endregion
4794
- //#region src/navigation/year.ts
4764
+ // src/navigation/year.ts
4795
4765
  /** Today when the year shows it, else the year's first day; its last day for `"end"`. */
4796
4766
  function entry(projection, command) {
4797
4767
  const { range } = projection;
@@ -4838,8 +4808,7 @@ function yearSpatialNavigation({ command, environment, focus, projection }) {
4838
4808
  const next = moveDate(focus.date, command, environment.weekRules.firstDay, environment.direction);
4839
4809
  return next === null ? null : dayFocus(next);
4840
4810
  }
4841
- //#endregion
4842
- //#region src/navigation/reveal.ts
4811
+ // src/navigation/reveal.ts
4843
4812
  /** Far enough for any keyboard step; a date further away is anchored directly. */
4844
4813
  const MAXIMUM_STEPS = 100;
4845
4814
  /**
@@ -4855,8 +4824,7 @@ function anchorShowingDate(strategy, anchor, date, environment, options) {
4855
4824
  }
4856
4825
  return date;
4857
4826
  }
4858
- //#endregion
4859
- //#region src/keyboard/session.ts
4827
+ // src/keyboard/session.ts
4860
4828
  /** The slot a wall time falls in. */
4861
4829
  function slotOf(wallTime, snap, resourceId) {
4862
4830
  const start = wallTime.round({
@@ -4995,8 +4963,7 @@ function keyboardSessionProposal(session) {
4995
4963
  proposed
4996
4964
  };
4997
4965
  }
4998
- //#endregion
4999
- //#region src/keyboard/announcements.ts
4966
+ // src/keyboard/announcements.ts
5000
4967
  const rangeFormats = /* @__PURE__ */ new Map();
5001
4968
  function formatsFor(locale) {
5002
4969
  const key = String(locale ?? "");
@@ -5036,8 +5003,7 @@ function formatPlacementRange(placement, { locale, timeZone }) {
5036
5003
  const nextMidnight = start.toPlainDate().add({ days: 1 }).toPlainDateTime();
5037
5004
  return Temporal.PlainDateTime.compare(end, nextMidnight) <= 0 ? formats.time.formatRange(start.toPlainTime(), end.toPlainTime()) : formats.dateTime.formatRange(start, end);
5038
5005
  }
5039
- //#endregion
5040
- //#region src/policies/availability.ts
5006
+ // src/policies/availability.ts
5041
5007
  const reason$1 = "outside-availability";
5042
5008
  /** Whether two placements cover the same time; a timed one's source time zone doesn't count. */
5043
5009
  function sameTime(left, right) {
@@ -5081,8 +5047,7 @@ function availabilityPolicy({ mode = "block" } = {}) {
5081
5047
  };
5082
5048
  };
5083
5049
  }
5084
- //#endregion
5085
- //#region src/policies/conflict.ts
5050
+ // src/policies/conflict.ts
5086
5051
  const reason = "resource-conflict";
5087
5052
  /**
5088
5053
  * Checks changes against double-booking: a busy event may not overlap another busy event of a
@@ -5127,8 +5092,7 @@ function conflictPolicy({ getResourceMode, mode = "block" } = {}) {
5127
5092
  };
5128
5093
  };
5129
5094
  }
5130
- //#endregion
5131
- //#region src/policies/bounds.ts
5095
+ // src/policies/bounds.ts
5132
5096
  function toInstant(point, timeZone) {
5133
5097
  if (point instanceof Temporal.Instant) return point;
5134
5098
  if (point instanceof Temporal.PlainDate) return point.toZonedDateTime(timeZone).toInstant();
@@ -5147,8 +5111,7 @@ function boundsPolicy(bounds) {
5147
5111
  } : { type: "accept" };
5148
5112
  };
5149
5113
  }
5150
- //#endregion
5151
- //#region src/policies/minimum-duration.ts
5114
+ // src/policies/minimum-duration.ts
5152
5115
  /**
5153
5116
  * Lengthens timed and floating changes shorter than `minimum`. A resized start moves earlier;
5154
5117
  * otherwise the end moves later.
@@ -5165,8 +5128,7 @@ function minimumDurationPolicy(minimum) {
5165
5128
  };
5166
5129
  };
5167
5130
  }
5168
- //#endregion
5169
- //#region src/policies/read-only.ts
5131
+ // src/policies/read-only.ts
5170
5132
  /** Rejects changes to events the adapter marks read-only. */
5171
5133
  function readOnlyPolicy() {
5172
5134
  return (change, { events }) => change.eventId !== null && events.get(change.eventId)?.isReadOnly === true ? {
@@ -5174,8 +5136,7 @@ function readOnlyPolicy() {
5174
5136
  type: "reject"
5175
5137
  } : { type: "accept" };
5176
5138
  }
5177
- //#endregion
5178
- //#region src/policies/read-only-resources.ts
5139
+ // src/policies/read-only-resources.ts
5179
5140
  /**
5180
5141
  * Rejects changes to the schedule of a resource `isReadOnly` marks: creating, deleting, or moving
5181
5142
  * an event on it in time, and assigning an event to it or taking one away. An event that keeps a
@@ -5192,8 +5153,7 @@ function readOnlyResourcesPolicy(isReadOnly) {
5192
5153
  } : { type: "accept" };
5193
5154
  };
5194
5155
  }
5195
- //#endregion
5196
- //#region src/policies/snap.ts
5156
+ // src/policies/snap.ts
5197
5157
  /**
5198
5158
  * Rounds timed and floating changes to a wall-clock grid in the display time zone, such as
5199
5159
  * `{ minutes: 15 }`. Moves keep their duration and resizes snap only the dragged edge. A change
@@ -5221,5 +5181,4 @@ function snapPolicy(increment) {
5221
5181
  };
5222
5182
  };
5223
5183
  }
5224
- //#endregion
5225
5184
  export { InvalidCalendarEventSnapshotError, anchorShowingDate, applyEventOverlay, availabilityAt, availabilityPolicy, belongsInTimeGridAllDayRow, boundsPolicy, busyAt, busyResources, closedDates, conflictPolicy, createAnnotationSnapshot, createAvailabilitySnapshot, createCanonicalEventAdapter, createEventHistory, createEventPlacement, createEventSnapshot, createEventSnapshotCache, createEventTransactions, createPlacementBetween, createResourceTree, defineEventAdapter, eventDateRanges, eventPlacement, fitsAvailability, formatPlacementRange, getListRange, getListTitle, getMonthRange, getMonthTitle, getYearRange, getYearTitle, groupByResource, isAnnotationId, isBusyEvent, isEventId, isResourceId, keyboardSessionProposal, layoutDayGridRow, layoutTimeGrid, limitDayGridLanes, listSpatialNavigation, minimumDurationPolicy, monthSpatialNavigation, moveEventPlacement, moveKeyboardCursor, movePlacementToTarget, navigateList, navigateMonth, navigateResourceTimeline, navigateTimeGrid, navigateYear, projectList, projectMonth, projectMonthWeeks, projectResourceColumns, projectResourceTimeline, projectTimeGrid, projectTimeGridAnnotations, projectTimeGridAvailability, projectTimelineAvailability, projectYear, queryVisibleEvents, readOnlyPolicy, readOnlyResourcesPolicy, resizeEventPlacement, resizePlacementToTarget, resolveSecondaryTimeZones, resolveViewInstantRange, resolveViewLoadRange, resourceColumnsSpatialNavigation, resourceColumnsStrategy, resourceStatusAt, resourceTimelineRange, resourceTimelineSpatialNavigation, resourceTimelineStrategy, resourceTimelineTitle, sameFocus, scrollingListStrategy, scrollingMonthAnchor, scrollingMonthOf, scrollingMonthStrategy, scrollingTimeGridStrategy, showsInResource, slotDuration, snapPolicy, splitEventsByDay, startKeyboardSession, summarizeAnnotationMarks, timeGridColumns, timeGridDateTimeAt, timeGridPosition, timeGridRange, timeGridSpatialNavigation, timeGridStrategy, timeGridTitle, timeGridZoneAxis, timeGridZoneRows, timeGridZoneTimes, timedFragmentBox, timelineExtent, timelinePosition, toAllDayPlacement, toTimedPlacement, validateCalendarEvent, validateCalendarEventInterval, visibleInstantRange, visibleResources, withAsciiSpaces, yearSpatialNavigation };