@bimetal/calendar-headless 0.34.0 → 0.35.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/LICENSE +57 -0
- package/README.md +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/click-intent.d.ts +2 -0
- package/dist/click-intent.d.ts.map +1 -1
- package/dist/click-intent.js +2 -0
- package/dist/click-intent.js.map +1 -1
- package/dist/controller/agenda.d.ts +4 -1
- package/dist/controller/agenda.d.ts.map +1 -1
- package/dist/controller/agenda.js +3 -2
- package/dist/controller/agenda.js.map +1 -1
- package/dist/controller/config.d.ts +5 -0
- package/dist/controller/config.d.ts.map +1 -1
- package/dist/controller/config.js +6 -3
- package/dist/controller/config.js.map +1 -1
- package/dist/controller/create-controller.d.ts +2 -0
- package/dist/controller/create-controller.d.ts.map +1 -1
- package/dist/controller/create-controller.js +231 -65
- package/dist/controller/create-controller.js.map +1 -1
- package/dist/controller/types.d.ts +167 -23
- package/dist/controller/types.d.ts.map +1 -1
- package/dist/controller/view-configs.d.ts +4 -2
- package/dist/controller/view-configs.d.ts.map +1 -1
- package/dist/controller/view-configs.js +11 -4
- package/dist/controller/view-configs.js.map +1 -1
- package/dist/date-strings.d.ts +11 -9
- package/dist/date-strings.d.ts.map +1 -1
- package/dist/date-strings.js +8 -5
- package/dist/date-strings.js.map +1 -1
- package/dist/defaults.d.ts +0 -2
- package/dist/defaults.d.ts.map +1 -1
- package/dist/defaults.js +0 -2
- package/dist/defaults.js.map +1 -1
- package/dist/drag-helpers.js +1 -1
- package/dist/drag-helpers.js.map +1 -1
- package/dist/drag-preview.d.ts +1 -0
- package/dist/drag-preview.d.ts.map +1 -1
- package/dist/drag-preview.js +2 -1
- package/dist/drag-preview.js.map +1 -1
- package/dist/event-actions.d.ts +5 -3
- package/dist/event-actions.d.ts.map +1 -1
- package/dist/event-actions.js +7 -4
- package/dist/event-actions.js.map +1 -1
- package/dist/index.d.ts +11 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/dist/validate-save.d.ts.map +1 -1
- package/dist/validate-save.js +2 -1
- package/dist/validate-save.js.map +1 -1
- package/package.json +7 -7
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* re-export `mergeCalendarConfig` / `defaultCalendarConfig` from here.
|
|
7
7
|
*/
|
|
8
8
|
import { defaultConfig as defaultCoreConfig } from '@bimetal/calendar-core';
|
|
9
|
+
/** Default English (en-US) locale strings. */
|
|
9
10
|
export const defaultLocale = {
|
|
10
11
|
code: 'en-US',
|
|
11
12
|
dayNamesShort: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
|
|
@@ -40,9 +41,7 @@ export const defaultLocale = {
|
|
|
40
41
|
timeFrom: 'from',
|
|
41
42
|
timeUntil: 'until',
|
|
42
43
|
undo: 'Undo',
|
|
43
|
-
|
|
44
|
-
eventUpdated: 'Event updated',
|
|
45
|
-
eventDeleted: 'Event deleted',
|
|
44
|
+
redo: 'Redo',
|
|
46
45
|
location: 'Location',
|
|
47
46
|
description: 'Description',
|
|
48
47
|
moreEvents: 'more',
|
|
@@ -56,6 +55,7 @@ export const defaultLocale = {
|
|
|
56
55
|
resources: 'Resources',
|
|
57
56
|
unassigned: 'Unassigned',
|
|
58
57
|
};
|
|
58
|
+
/** Default calendar config: `defaultLocale`, no categories/resources, 300ms click threshold. */
|
|
59
59
|
export const defaultCalendarConfig = {
|
|
60
60
|
core: defaultCoreConfig,
|
|
61
61
|
locale: defaultLocale,
|
|
@@ -80,6 +80,9 @@ function warnLocaleEmptyStrings(locale) {
|
|
|
80
80
|
'Use `delete: false` to hide it (or omit the field to use the default label).');
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
+
/** Deep-merges a partial config over `defaultCalendarConfig`, filling in
|
|
84
|
+
* `core`/`locale` (including nested `views`/`historyEventTypes`/`recurUnits`)
|
|
85
|
+
* from the defaults for any field the caller omits. */
|
|
83
86
|
export function mergeCalendarConfig(partial) {
|
|
84
87
|
if (!partial)
|
|
85
88
|
return defaultCalendarConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/controller/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,IAAI,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG5E,MAAM,CAAC,MAAM,aAAa,GAAmB;IAC3C,IAAI,EAAE,OAAO;IACb,aAAa,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC;IAChE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE;IACxG,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,WAAW;IACrB,SAAS,EAAE,YAAY;IACvB,MAAM,EAAE,SAAS;IACjB,IAAI,EAAE,MAAM;IACZ,EAAE,EAAE,IAAI;IACR,QAAQ,EAAE,UAAU;IACpB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,SAAS;IACtB,QAAQ,EAAE,+BAA+B;IACzC,WAAW,EAAE,SAAS;IACtB,YAAY,EAAE,SAAS;IACvB,cAAc,EAAE,YAAY;IAC5B,YAAY,EAAE,wBAAwB;IACtC,iBAAiB,EAAE;QACjB,uCAAuC,EAAE,SAAS;QAClD,uCAAuC,EAAE,SAAS;QAClD,uCAAuC,EAAE,SAAS;QAClD,wCAAwC,EAAE,U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ptions } from './types.js';
|
|
19
|
+
/** Creates a canonical calendar controller instance bound to the given store,
|
|
20
|
+
* config, rules and custom views (see the module doc above for the full contract). */
|
|
19
21
|
export declare function createCalendarController(opts: CalendarControllerOptions): CalendarController;
|
|
20
22
|
//# sourceMappingURL=create-controller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-controller.d.ts","sourceRoot":"","sources":["../../src/controller/create-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;
|
|
1
|
+
{"version":3,"file":"create-controller.d.ts","sourceRoot":"","sources":["../../src/controller/create-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAoBH,OAAO,KAAK,EAEV,kBAAkB,EAAE,yBAAyB,EAG9C,MAAM,YAAY,CAAC;AAQpB;uFACuF;AACvF,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,yBAAyB,GAAG,kBAAkB,CAk1B5F"}
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
* Derived from the de-facto reference `packages/react-components/src/
|
|
16
16
|
* components/Calendar.tsx`.
|
|
17
17
|
*/
|
|
18
|
-
import { now as coreNow, getYear, getMonth, getDayOfMonth, createDateTime, addDays, createTimeRange,
|
|
19
|
-
import {
|
|
20
|
-
import { createRuleEngine, withRules
|
|
18
|
+
import { now as coreNow, getYear, getMonth, getDayOfMonth, createDateTime, addDays, createTimeRange, overlaps, monthIndex } from '@bimetal/temporal';
|
|
19
|
+
import { visibleRange, getRecurrenceInstanceMetadata, stripRecurrenceInstanceMetadata, expandRecurrence } from '@bimetal/calendar-core';
|
|
20
|
+
import { createRuleEngine, withRules } from '@bimetal/calendar-rules';
|
|
21
21
|
import { createControllerCore, deepCopy, createViewMemo, createRefSlotMemo, windowSlice, windowOffsets } from '@bimetal/headless-core';
|
|
22
22
|
import { createEventActions } from '../event-actions.js';
|
|
23
23
|
import { validateSavePreview } from '../validate-save.js';
|
|
@@ -32,12 +32,16 @@ import { buildAgendaDescriptors, materializeAgendaRow } from './agenda.js';
|
|
|
32
32
|
const AGENDA_ROW_HEIGHT = 44;
|
|
33
33
|
/** Extra agenda rows built above/below the viewport so a fast scroll doesn't flash. */
|
|
34
34
|
const AGENDA_OVERSCAN = 6;
|
|
35
|
+
/** Creates a canonical calendar controller instance bound to the given store,
|
|
36
|
+
* config, rules and custom views (see the module doc above for the full contract). */
|
|
35
37
|
export function createCalendarController(opts) {
|
|
36
38
|
const baseStore = opts.store;
|
|
37
39
|
const nowFn = opts.now ?? (() => coreNow(config.core.timezone, config.core.clock));
|
|
38
40
|
let eventDialogKind = opts.eventDialogKind ?? 'builtin';
|
|
39
41
|
const onError = opts.onError;
|
|
40
42
|
const onSelectionChange = opts.onSelectionChange;
|
|
43
|
+
const onHistoryChange = opts.onHistoryChange;
|
|
44
|
+
const onWarning = opts.onWarning;
|
|
41
45
|
// ── Mutable option state (reactive via setConfig/setRules/setCustomViews) ──
|
|
42
46
|
let config = mergeCalendarConfig(opts.config);
|
|
43
47
|
// v0.30 Slice 2b: an identity-STABLE defensive copy of config for the snapshot. Rebuilt
|
|
@@ -114,7 +118,15 @@ export function createCalendarController(opts) {
|
|
|
114
118
|
}
|
|
115
119
|
function rebuildViewConfigs() {
|
|
116
120
|
const viewConfigs = createViewConfigs(config.locale, config.core.weekStart);
|
|
117
|
-
|
|
121
|
+
// enabledViews SELECTS + ORDERS the built-ins (unknown ids ignored); unset = all
|
|
122
|
+
// built-ins in their default order (today's behaviour).
|
|
123
|
+
const selected = config.enabledViews
|
|
124
|
+
? config.enabledViews.map(t => viewConfigs[t]).filter((v) => v !== undefined)
|
|
125
|
+
: Object.values(viewConfigs);
|
|
126
|
+
// Data gate (unchanged): resource AND timeline are both resource-based, so they
|
|
127
|
+
// only appear when resources exist — enabledViews is the selection layer above this.
|
|
128
|
+
const passesDataGate = (v) => (v.type !== 'resource' && v.type !== 'timeline') || config.resources.length > 0;
|
|
129
|
+
const builtIns = selected.filter(passesDataGate);
|
|
118
130
|
const customs = customViews.map(v => ({
|
|
119
131
|
type: v.id,
|
|
120
132
|
label: v.label,
|
|
@@ -123,13 +135,38 @@ export function createCalendarController(opts) {
|
|
|
123
135
|
.format(new Date(dt.epochMs))),
|
|
124
136
|
}));
|
|
125
137
|
viewConfigList = [...builtIns, ...customs];
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
//
|
|
138
|
+
// Guard against a config that resolves to NO views (enabledViews: [], only
|
|
139
|
+
// invalid ids, or only resource/timeline without resources) AND no custom views:
|
|
140
|
+
// fall back to the default built-ins so the bar can never be empty — an empty bar
|
|
141
|
+
// would make activeViewConfig()/formatTitle crash. Warn in dev — it's a config error.
|
|
142
|
+
if (viewConfigList.length === 0) {
|
|
143
|
+
warnEmptyViewBar();
|
|
144
|
+
viewConfigList = Object.values(viewConfigs).filter(passesDataGate);
|
|
145
|
+
}
|
|
146
|
+
// F7: if the active view no longer exists (e.g. resources removed, a custom-view
|
|
147
|
+
// id dropped, or an enabledViews change dropped it), fall back to the first
|
|
148
|
+
// available view so `currentView` can never point at a non-existent view.
|
|
129
149
|
if (!viewConfigList.some(v => v.type === currentView) && viewConfigList.length > 0) {
|
|
130
150
|
currentView = viewConfigList[0].type;
|
|
131
151
|
}
|
|
132
152
|
}
|
|
153
|
+
/** Dev-only warning when `enabledViews` (+ resources + customViews) leaves the view
|
|
154
|
+
* bar empty; the controller then falls back to the default built-ins. */
|
|
155
|
+
function warnEmptyViewBar() {
|
|
156
|
+
if (typeof process !== 'undefined' && process.env?.NODE_ENV === 'production')
|
|
157
|
+
return;
|
|
158
|
+
// eslint-disable-next-line no-console
|
|
159
|
+
console.warn('[bimetal] `enabledViews` resolved to no available views (empty list, only ' +
|
|
160
|
+
'unknown ids, or only resource/timeline without `resources`). Falling back to ' +
|
|
161
|
+
'the default views.');
|
|
162
|
+
}
|
|
163
|
+
/** True if `view` is currently in the view bar (a built-in that survived
|
|
164
|
+
* enabledViews + the data gate, or a registered custom view). The single guard
|
|
165
|
+
* every view-setter routes through, so `currentView` never points at a view that
|
|
166
|
+
* is not in `viewConfigList` (the F7 invariant, for imperative setters too). */
|
|
167
|
+
function viewEnabled(view) {
|
|
168
|
+
return viewConfigList.some(v => v.type === view);
|
|
169
|
+
}
|
|
133
170
|
// ── Derivations ─────────────────────────────────────────────────
|
|
134
171
|
function activeViewConfig() {
|
|
135
172
|
return viewConfigList.find(v => v.type === currentView) ?? viewConfigList[0];
|
|
@@ -160,6 +197,24 @@ export function createCalendarController(opts) {
|
|
|
160
197
|
// leaves join the identity spine instead of deep-copying fresh every frame.
|
|
161
198
|
const expandMemo = createRefSlotMemo('calendar.expandRecurrence');
|
|
162
199
|
const memoInstanceCopy = createViewMemo((e) => deepCopy(e));
|
|
200
|
+
// ── Per-event interaction policy (ticket-19) ──
|
|
201
|
+
// The ONE resolver for both the enforcement (gating drop/save/delete below) and the
|
|
202
|
+
// affordance (`getEventInteraction`, read by bindings). Memoized on the event's
|
|
203
|
+
// identity-stable ref (same spine as the copy memos), so a pure-of-event hook runs
|
|
204
|
+
// at most once per event version — which is why the hook takes ONLY the event (no
|
|
205
|
+
// config/now: external state would go stale behind the memo). `locked` is the
|
|
206
|
+
// immutable shorthand.
|
|
207
|
+
const resolveInteraction = createViewMemo((ev) => {
|
|
208
|
+
const p = opts.eventInteraction?.(ev) ?? {};
|
|
209
|
+
if (p.locked)
|
|
210
|
+
return { draggable: false, resizable: false, editable: false, deletable: false };
|
|
211
|
+
return {
|
|
212
|
+
draggable: p.draggable !== false,
|
|
213
|
+
resizable: p.resizable !== false,
|
|
214
|
+
editable: p.editable !== false,
|
|
215
|
+
deletable: p.deletable !== false,
|
|
216
|
+
};
|
|
217
|
+
});
|
|
163
218
|
function expandVisible(range) {
|
|
164
219
|
const window = createTimeRange(range.start, range.end);
|
|
165
220
|
const rangeKey = [range.start.epochMs, range.end.epochMs, range.start.timezone];
|
|
@@ -308,47 +363,56 @@ export function createCalendarController(opts) {
|
|
|
308
363
|
selectedEvent: deepCopy(selectedEvent),
|
|
309
364
|
previewEvent: deepCopy(previewEvent),
|
|
310
365
|
expandedMonthDay,
|
|
311
|
-
|
|
366
|
+
// Same resolver as undo()/redo()/voidUndo/voidRedo → the button's enabled-state
|
|
367
|
+
// can never disagree with what the click does (target-scoped: multi-entity).
|
|
368
|
+
canUndo: computeCanUndo(),
|
|
369
|
+
canRedo: computeCanRedo(),
|
|
312
370
|
hiddenCategories: new Set(hiddenCategories),
|
|
313
371
|
hiddenResources: new Set(hiddenResources),
|
|
314
372
|
config: configView,
|
|
315
373
|
};
|
|
316
374
|
}
|
|
317
375
|
// ── Internal helpers ────────────────────────────────────────────
|
|
318
|
-
|
|
319
|
-
|
|
376
|
+
// A real Calendar-store mutation succeeded: advance the PERSISTENT undo cursor
|
|
377
|
+
// (ticket-31 — as long as the store lives, independent of any app-side feedback) and
|
|
378
|
+
// clear the now-stale redo pointer (a new fact diverges the timeline). Only the
|
|
379
|
+
// controller's own mutation paths call this. Carries NO presentation concern
|
|
380
|
+
// (ticket-32 — the old feedback toast text is gone; the app observes changes itself).
|
|
381
|
+
function recordMutation(entityId) {
|
|
382
|
+
lastUndoneEntityId = null;
|
|
383
|
+
lastMutatedEntityId = entityId;
|
|
320
384
|
}
|
|
321
|
-
// The
|
|
322
|
-
//
|
|
323
|
-
//
|
|
324
|
-
//
|
|
385
|
+
// The SINGLE controller error contract (ticket-32): EVERY dispatch rejection — a
|
|
386
|
+
// domain rule violation, a DataValidationError, a ConcurrencyError, storage, or a
|
|
387
|
+
// bug — is handed to the consumer via `onError`, or (if none given) rethrown so the
|
|
388
|
+
// intent's promise rejects loudly. The calendar never turns an error into a toast.
|
|
325
389
|
function handleError(err) {
|
|
326
|
-
if (err instanceof RuleViolationError) {
|
|
327
|
-
const msg = err.violations
|
|
328
|
-
.filter(v => !v.passed)
|
|
329
|
-
.map(v => !v.passed ? v.message : '')
|
|
330
|
-
.join(', ');
|
|
331
|
-
setLastAction('', msg);
|
|
332
|
-
markChanged();
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
if (err instanceof DataValidationError) {
|
|
336
|
-
setLastAction('', err.message);
|
|
337
|
-
markChanged();
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
390
|
if (onError) {
|
|
341
391
|
onError(err);
|
|
342
392
|
return;
|
|
343
393
|
}
|
|
344
394
|
throw err;
|
|
345
395
|
}
|
|
346
|
-
/** Undo through the SAME error router as save/delete/drop —
|
|
347
|
-
*
|
|
348
|
-
* `
|
|
396
|
+
/** Undo through the SAME error router as save/delete/drop — every rejection
|
|
397
|
+
* propagates via `onError`/rethrow (ticket-32). Returns whether the undo happened;
|
|
398
|
+
* fires `onHistoryChange` (fachliche observe point) only on a REAL change. */
|
|
399
|
+
/** The entity of the most recent successful undo — the target a keyboard redo
|
|
400
|
+
* (Ctrl+Shift+Z) acts on. Set on ANY successful undo (button OR keyboard), so redo
|
|
401
|
+
* works regardless of how the undo was triggered. */
|
|
402
|
+
let lastUndoneEntityId = null;
|
|
403
|
+
// ticket-31: persistent undo target (set in recordMutation on a real mutation). The undo
|
|
404
|
+
// history lives as long as the in-memory store (per session, until reload).
|
|
405
|
+
let lastMutatedEntityId = null;
|
|
349
406
|
async function undoSafely(entityId) {
|
|
407
|
+
// Set the redo target + emit onHistoryChange ONLY when an undo event was actually
|
|
408
|
+
// produced — an empty result (nothing on the stack) must not fake a redo affordance
|
|
409
|
+
// or notify. Belt-and-suspenders behind the computeCanUndo guard.
|
|
350
410
|
try {
|
|
351
|
-
await ruleStore.undo(entityId);
|
|
411
|
+
const events = await ruleStore.undo(entityId);
|
|
412
|
+
if (events.length > 0) {
|
|
413
|
+
lastUndoneEntityId = entityId;
|
|
414
|
+
onHistoryChange?.({ operation: 'undo', entityId, events });
|
|
415
|
+
}
|
|
352
416
|
return true;
|
|
353
417
|
}
|
|
354
418
|
catch (err) {
|
|
@@ -356,16 +420,35 @@ export function createCalendarController(opts) {
|
|
|
356
420
|
return false;
|
|
357
421
|
}
|
|
358
422
|
}
|
|
359
|
-
|
|
360
|
-
|
|
423
|
+
async function redoSafely(entityId) {
|
|
424
|
+
try {
|
|
425
|
+
const events = await ruleStore.redo(entityId);
|
|
426
|
+
if (events.length > 0)
|
|
427
|
+
onHistoryChange?.({ operation: 'redo', entityId, events });
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
430
|
+
catch (err) {
|
|
431
|
+
handleError(err);
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
// The SINGLE target resolver for both the action AND its enabled-state — undo/redo
|
|
436
|
+
// (keyboard + the no-arg void buttons) and buildSnapshot must never disagree on which
|
|
437
|
+
// entity they mean. Undo targets the LAST-MUTATED entity (persistent, ticket-31 — NOT the
|
|
438
|
+
// ephemeral toast); redo the last-undone entity, falling back to the last-mutated one.
|
|
439
|
+
// Enabled ⇔ that target's live stack is non-empty.
|
|
440
|
+
const resolveUndoTarget = () => lastMutatedEntityId;
|
|
441
|
+
const resolveRedoTarget = () => lastUndoneEntityId ?? lastMutatedEntityId;
|
|
442
|
+
const computeCanUndo = () => { const t = resolveUndoTarget(); return t != null && ruleStore.canUndo(t); };
|
|
443
|
+
const computeCanRedo = () => { const t = resolveRedoTarget(); return t != null && ruleStore.canRedo(t); };
|
|
444
|
+
/** Hand the non-blocking rule warnings from the last dispatch to the app via the
|
|
445
|
+
* `onWarning` observe hook (ticket-32) — domain-only, no toast inside the calendar. */
|
|
361
446
|
function pullWarnings() {
|
|
362
447
|
const warnings = ruleStore.lastWarnings;
|
|
363
448
|
if (warnings && warnings.length > 0) {
|
|
364
|
-
const
|
|
365
|
-
if (
|
|
366
|
-
|
|
367
|
-
markChanged();
|
|
368
|
-
}
|
|
449
|
+
const failed = warnings.filter(w => !w.passed);
|
|
450
|
+
if (failed.length > 0)
|
|
451
|
+
onWarning?.(failed);
|
|
369
452
|
}
|
|
370
453
|
}
|
|
371
454
|
// ── Init ────────────────────────────────────────────────────────
|
|
@@ -381,6 +464,7 @@ export function createCalendarController(opts) {
|
|
|
381
464
|
const controller = {
|
|
382
465
|
getSnapshot() { return core.getSnapshot(); },
|
|
383
466
|
subscribe(listener) { return core.subscribe(listener); },
|
|
467
|
+
getEventInteraction(event) { return resolveInteraction(event); },
|
|
384
468
|
destroy() {
|
|
385
469
|
actions.destroy();
|
|
386
470
|
core.destroy();
|
|
@@ -411,10 +495,17 @@ export function createCalendarController(opts) {
|
|
|
411
495
|
prev() { currentDate = activeViewConfig().step(currentDate, -1); markChanged(); },
|
|
412
496
|
next() { currentDate = activeViewConfig().step(currentDate, 1); markChanged(); },
|
|
413
497
|
today() { currentDate = nowFn(); markChanged(); },
|
|
414
|
-
|
|
498
|
+
// Guarded: a view that isn't in the bar (disabled via enabledViews / data gate)
|
|
499
|
+
// is ignored — currentView stays valid instead of pointing at a non-existent view.
|
|
500
|
+
setView(view) { if (viewEnabled(view)) {
|
|
501
|
+
currentView = view;
|
|
502
|
+
markChanged();
|
|
503
|
+
} },
|
|
415
504
|
goToMonth(year, month) {
|
|
505
|
+
// Always navigate the date; switch to month only if month is actually in the bar.
|
|
416
506
|
currentDate = createDateTime(year, month, 1, 0, 0, currentDate.timezone);
|
|
417
|
-
|
|
507
|
+
if (viewEnabled('month'))
|
|
508
|
+
currentView = 'month';
|
|
418
509
|
markChanged();
|
|
419
510
|
},
|
|
420
511
|
// v0.30 Slice 5b — additive/transient agenda viewport report; re-windows the agenda
|
|
@@ -442,6 +533,13 @@ export function createCalendarController(opts) {
|
|
|
442
533
|
const event = findExpandedEvent(currentEvents(), eventId, instanceDate);
|
|
443
534
|
if (!event)
|
|
444
535
|
return;
|
|
536
|
+
// ticket-19: a CONTROLLER-OWNED dialog (builtin AND custom — both render from
|
|
537
|
+
// snapshot.dialog) is an edit affordance — refuse to open it for a non-editable
|
|
538
|
+
// event, so the same policy that blocks save/delete also removes the way in (all
|
|
539
|
+
// stacks/views/keyboard). Only `none` delegates outward (returned above); that host
|
|
540
|
+
// can branch on getEventInteraction to show its own read-only view.
|
|
541
|
+
if (!resolveInteraction(event).editable)
|
|
542
|
+
return;
|
|
445
543
|
// C1: the EDIT draft is seeded in the controller (event → strings), so the
|
|
446
544
|
// binding's edit path is as parse-free as create.
|
|
447
545
|
dialog = {
|
|
@@ -509,6 +607,17 @@ export function createCalendarController(opts) {
|
|
|
509
607
|
},
|
|
510
608
|
async saveDialog(updated) {
|
|
511
609
|
const instanceMarkers = getRecurrenceInstanceMetadata(updated);
|
|
610
|
+
// ticket-19 gate: a non-editable event's edit no-ops (the dialog may still open
|
|
611
|
+
// read-only; enforcement backstop). Resolve the target from the RAW stored set —
|
|
612
|
+
// NOT currentEvents(), which is range-/category-FILTERED, so a hidden/off-range
|
|
613
|
+
// locked event would otherwise slip the gate on the programmatic path. A NEW event
|
|
614
|
+
// has no stored original → allowed.
|
|
615
|
+
const original = dialog?.event ?? masterEvents.find(e => e.id === (instanceMarkers ? instanceMarkers.masterEventId : updated.id));
|
|
616
|
+
if (original && !resolveInteraction(original).editable) {
|
|
617
|
+
dialog = null;
|
|
618
|
+
markChanged();
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
512
621
|
try {
|
|
513
622
|
if (instanceMarkers) {
|
|
514
623
|
const instanceDate = { epochMs: instanceMarkers.instanceDate, timezone: config.core.timezone };
|
|
@@ -520,12 +629,11 @@ export function createCalendarController(opts) {
|
|
|
520
629
|
domains: updated.domains,
|
|
521
630
|
resourceId: updated.resourceId,
|
|
522
631
|
});
|
|
523
|
-
|
|
632
|
+
recordMutation(instanceMarkers.masterEventId);
|
|
524
633
|
}
|
|
525
634
|
else {
|
|
526
|
-
const isNew = !currentEvents().some(e => e.id === updated.id);
|
|
527
635
|
await actions.saveEvent(updated);
|
|
528
|
-
|
|
636
|
+
recordMutation(updated.id);
|
|
529
637
|
}
|
|
530
638
|
dialog = null;
|
|
531
639
|
markChanged();
|
|
@@ -536,17 +644,25 @@ export function createCalendarController(opts) {
|
|
|
536
644
|
}
|
|
537
645
|
},
|
|
538
646
|
async deleteDialog(eventId) {
|
|
647
|
+
// ticket-19 gate: a non-deletable event's delete no-ops. Raw-set lookup (see
|
|
648
|
+
// saveDialog) so a hidden/off-range locked event is still gated programmatically.
|
|
649
|
+
const target = dialog?.event ?? masterEvents.find(e => e.id === eventId);
|
|
650
|
+
if (target && !resolveInteraction(target).deletable) {
|
|
651
|
+
dialog = null;
|
|
652
|
+
markChanged();
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
539
655
|
const dialogEvent = dialog?.event;
|
|
540
656
|
const instanceMarkers = dialogEvent ? getRecurrenceInstanceMetadata(dialogEvent) : null;
|
|
541
657
|
try {
|
|
542
658
|
if (instanceMarkers) {
|
|
543
659
|
const instanceDate = { epochMs: instanceMarkers.instanceDate, timezone: config.core.timezone };
|
|
544
660
|
await actions.deleteInstance(instanceMarkers.masterEventId, instanceDate);
|
|
545
|
-
|
|
661
|
+
recordMutation(instanceMarkers.masterEventId);
|
|
546
662
|
}
|
|
547
663
|
else {
|
|
548
664
|
await actions.deleteEvent(eventId);
|
|
549
|
-
|
|
665
|
+
recordMutation(eventId);
|
|
550
666
|
}
|
|
551
667
|
dialog = null;
|
|
552
668
|
markChanged();
|
|
@@ -566,12 +682,19 @@ export function createCalendarController(opts) {
|
|
|
566
682
|
controller.endDrag();
|
|
567
683
|
return;
|
|
568
684
|
}
|
|
685
|
+
// ticket-19: gate the gesture — a non-draggable/non-resizable event no-ops here
|
|
686
|
+
// (the enforcement backstop even if a binding still surfaced the affordance).
|
|
687
|
+
const policy = resolveInteraction(ev);
|
|
688
|
+
if (info.type.startsWith('resize') ? !policy.resizable : !policy.draggable) {
|
|
689
|
+
controller.endDrag();
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
569
692
|
try {
|
|
570
693
|
if (info.type === 'resize')
|
|
571
694
|
await actions.resizeEvent(ev, dropDate, info.edge);
|
|
572
695
|
else
|
|
573
696
|
await actions.moveEvent(ev, dropDate, info.dayOffset);
|
|
574
|
-
|
|
697
|
+
recordMutation(info.eventId);
|
|
575
698
|
pullWarnings();
|
|
576
699
|
}
|
|
577
700
|
catch (err) {
|
|
@@ -589,12 +712,19 @@ export function createCalendarController(opts) {
|
|
|
589
712
|
controller.endDrag();
|
|
590
713
|
return;
|
|
591
714
|
}
|
|
715
|
+
// ticket-19: gate the gesture — a non-draggable/non-resizable event no-ops here
|
|
716
|
+
// (the enforcement backstop even if a binding still surfaced the affordance).
|
|
717
|
+
const policy = resolveInteraction(ev);
|
|
718
|
+
if (info.type.startsWith('resize') ? !policy.resizable : !policy.draggable) {
|
|
719
|
+
controller.endDrag();
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
592
722
|
try {
|
|
593
723
|
if (info.type === 'resize-timed')
|
|
594
724
|
await actions.resizeTimedEvent(ev, dropDate, dropTime, info.edge);
|
|
595
725
|
else if (info.type === 'move-timed')
|
|
596
726
|
await actions.moveTimedEvent(ev, dropDate, dropTime, info.minuteOffset);
|
|
597
|
-
|
|
727
|
+
recordMutation(info.eventId);
|
|
598
728
|
pullWarnings();
|
|
599
729
|
}
|
|
600
730
|
catch (err) {
|
|
@@ -612,6 +742,13 @@ export function createCalendarController(opts) {
|
|
|
612
742
|
controller.endDrag();
|
|
613
743
|
return;
|
|
614
744
|
}
|
|
745
|
+
// ticket-19: gate the gesture — a non-draggable/non-resizable event no-ops here
|
|
746
|
+
// (the enforcement backstop even if a binding still surfaced the affordance).
|
|
747
|
+
const policy = resolveInteraction(ev);
|
|
748
|
+
if (info.type.startsWith('resize') ? !policy.resizable : !policy.draggable) {
|
|
749
|
+
controller.endDrag();
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
615
752
|
try {
|
|
616
753
|
if (info.type === 'resize-timed') {
|
|
617
754
|
// Resize keeps the resource binding — only the timeRange changes.
|
|
@@ -621,7 +758,7 @@ export function createCalendarController(opts) {
|
|
|
621
758
|
// Single resource per event: drop = atomic resourceId reassignment.
|
|
622
759
|
await actions.moveTimedEvent(ev, dropDate, dropTime, info.minuteOffset, resourceId);
|
|
623
760
|
}
|
|
624
|
-
|
|
761
|
+
recordMutation(info.eventId);
|
|
625
762
|
pullWarnings();
|
|
626
763
|
}
|
|
627
764
|
catch (err) {
|
|
@@ -639,6 +776,13 @@ export function createCalendarController(opts) {
|
|
|
639
776
|
controller.endDrag();
|
|
640
777
|
return;
|
|
641
778
|
}
|
|
779
|
+
// ticket-19: gate the gesture — a non-draggable/non-resizable event no-ops here
|
|
780
|
+
// (the enforcement backstop even if a binding still surfaced the affordance).
|
|
781
|
+
const policy = resolveInteraction(ev);
|
|
782
|
+
if (info.type.startsWith('resize') ? !policy.resizable : !policy.draggable) {
|
|
783
|
+
controller.endDrag();
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
642
786
|
try {
|
|
643
787
|
if (info.type === 'move') {
|
|
644
788
|
// Day-grain move + resource reassignment in one instance-aware op.
|
|
@@ -648,7 +792,7 @@ export function createCalendarController(opts) {
|
|
|
648
792
|
// Timeline always day-snaps the resized edge, regardless of allDay.
|
|
649
793
|
await actions.resizeEventByDay(ev, dropDate, info.edge);
|
|
650
794
|
}
|
|
651
|
-
|
|
795
|
+
recordMutation(info.eventId);
|
|
652
796
|
pullWarnings();
|
|
653
797
|
}
|
|
654
798
|
catch (err) {
|
|
@@ -726,11 +870,27 @@ export function createCalendarController(opts) {
|
|
|
726
870
|
hiddenResources = next;
|
|
727
871
|
markChanged();
|
|
728
872
|
},
|
|
729
|
-
// ── Undo / errors ──
|
|
730
|
-
|
|
731
|
-
|
|
873
|
+
// ── Undo / redo / errors ──
|
|
874
|
+
// Empty stack → silent no-op (not an error); real failures still route via handleError.
|
|
875
|
+
async undo(entityId) { if (!ruleStore.canUndo(entityId))
|
|
876
|
+
return; await undoSafely(entityId); },
|
|
877
|
+
async redo(entityId) { if (!ruleStore.canRedo(entityId))
|
|
878
|
+
return; if (await redoSafely(entityId))
|
|
732
879
|
markChanged(); },
|
|
733
|
-
|
|
880
|
+
// No-arg toolbar affordance (mirrors the other families' voidUndo/voidRedo): resolves
|
|
881
|
+
// the current target itself so the button binding is uniform. Enabled ⇔ canUndo/canRedo.
|
|
882
|
+
voidUndo() {
|
|
883
|
+
if (!computeCanUndo())
|
|
884
|
+
return;
|
|
885
|
+
void undoSafely(resolveUndoTarget()).then(ok => { if (ok)
|
|
886
|
+
markChanged(); }, () => { });
|
|
887
|
+
},
|
|
888
|
+
voidRedo() {
|
|
889
|
+
if (!computeCanRedo())
|
|
890
|
+
return;
|
|
891
|
+
void redoSafely(resolveRedoTarget()).then(ok => { if (ok)
|
|
892
|
+
markChanged(); }, () => { });
|
|
893
|
+
},
|
|
734
894
|
handleError,
|
|
735
895
|
getHistory(entityId) { return ruleStore.getHistory(entityId); },
|
|
736
896
|
// ── Keyboard ──
|
|
@@ -747,17 +907,23 @@ export function createCalendarController(opts) {
|
|
|
747
907
|
}
|
|
748
908
|
if ((e.ctrlKey || e.metaKey) && e.key === 'z' && !e.shiftKey) {
|
|
749
909
|
e.preventDefault();
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
910
|
+
// Empty stack → no-op (not an error). Route through the error contract.
|
|
911
|
+
// Fire-and-forget: a rejection (infra error, no onError) was already offered to
|
|
912
|
+
// the contract — swallow here so it never escapes as an unhandled global
|
|
913
|
+
// rejection (rereview F6). The public undo() still rejects loudly for awaiters.
|
|
914
|
+
if (computeCanUndo()) {
|
|
915
|
+
void undoSafely(resolveUndoTarget()).then(ok => { if (ok)
|
|
916
|
+
markChanged(); }, () => { });
|
|
917
|
+
}
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
// Redo (Ctrl/Cmd+Shift+Z or Ctrl/Cmd+Y) — mirror of undo. Targets the last
|
|
921
|
+
// undone entity.
|
|
922
|
+
if ((e.ctrlKey || e.metaKey) && (((e.key === 'z' || e.key === 'Z') && e.shiftKey) || e.key === 'y' || e.key === 'Y')) {
|
|
923
|
+
e.preventDefault();
|
|
924
|
+
if (computeCanRedo()) {
|
|
925
|
+
void redoSafely(resolveRedoTarget()).then(ok => { if (ok)
|
|
926
|
+
markChanged(); }, () => { });
|
|
761
927
|
}
|
|
762
928
|
return;
|
|
763
929
|
}
|