@almadar/ui 5.125.0 → 5.127.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.
@@ -21142,6 +21142,32 @@ var init_ButtonGroup = __esm({
21142
21142
  ButtonGroup.displayName = "ButtonGroup";
21143
21143
  }
21144
21144
  });
21145
+
21146
+ // lib/getNestedValue.ts
21147
+ function getNestedValue(obj, path) {
21148
+ if (obj === null || obj === void 0 || !path) {
21149
+ return void 0;
21150
+ }
21151
+ if (!path.includes(".")) {
21152
+ return obj[path];
21153
+ }
21154
+ const parts = path.split(".");
21155
+ let value = obj;
21156
+ for (const part of parts) {
21157
+ if (value === null || value === void 0) {
21158
+ return void 0;
21159
+ }
21160
+ if (typeof value !== "object" || Array.isArray(value)) {
21161
+ return void 0;
21162
+ }
21163
+ value = value[part];
21164
+ }
21165
+ return value;
21166
+ }
21167
+ var init_getNestedValue = __esm({
21168
+ "lib/getNestedValue.ts"() {
21169
+ }
21170
+ });
21145
21171
  function useSwipeGesture(callbacks, options = {}) {
21146
21172
  const { threshold = 50, velocityThreshold = 0.3, preventDefault = false } = options;
21147
21173
  const startX = React91.useRef(0);
@@ -21255,17 +21281,31 @@ function getWeekDays(start) {
21255
21281
  }
21256
21282
  return days;
21257
21283
  }
21258
- function generateDefaultTimeSlots() {
21284
+ function eventStartDate(event, startField) {
21285
+ const raw = getNestedValue(event, startField);
21286
+ return new Date(raw ?? "");
21287
+ }
21288
+ function generateDefaultTimeSlots(events2, startField) {
21289
+ let first = DEFAULT_FIRST_HOUR;
21290
+ let last = DEFAULT_LAST_HOUR;
21291
+ for (const ev of events2) {
21292
+ const start = eventStartDate(ev, startField);
21293
+ if (Number.isNaN(start.getTime())) continue;
21294
+ const hour = start.getHours();
21295
+ if (hour < first) first = hour;
21296
+ if (hour > last) last = hour;
21297
+ }
21259
21298
  const slots = [];
21260
- for (let hour = 9; hour <= 17; hour++) {
21261
- slots.push(`${hour.toString().padStart(2, "0")}:00`);
21299
+ for (let hour = first; hour <= last; hour++) {
21300
+ slots.push(slotLabel(hour));
21262
21301
  }
21263
21302
  return slots;
21264
21303
  }
21265
- function eventInSlot(event, day, slotTime) {
21266
- const eventStart = new Date(event.startTime);
21267
- const [slotHour, slotMinute] = slotTime.split(":").map(Number);
21268
- return eventStart.toDateString() === day.toDateString() && eventStart.getHours() === slotHour && eventStart.getMinutes() === slotMinute;
21304
+ function eventInSlot(event, day, slotTime, startField) {
21305
+ const eventStart = eventStartDate(event, startField);
21306
+ if (Number.isNaN(eventStart.getTime())) return false;
21307
+ const [slotHour] = slotTime.split(":").map(Number);
21308
+ return eventStart.toDateString() === day.toDateString() && eventStart.getHours() === slotHour;
21269
21309
  }
21270
21310
  function CalendarGrid({
21271
21311
  weekStart,
@@ -21279,7 +21319,12 @@ function CalendarGrid({
21279
21319
  longPressPayload,
21280
21320
  swipeLeftEvent,
21281
21321
  swipeRightEvent,
21282
- dayWindow = "auto"
21322
+ dayWindow = "auto",
21323
+ titleField = "title",
21324
+ startField = "startTime",
21325
+ colorField = "color",
21326
+ children,
21327
+ renderItem
21283
21328
  }) {
21284
21329
  const evs = Array.isArray(events2) ? events2 : events2 ? [events2] : [];
21285
21330
  const eventBus = useEventBus();
@@ -21294,8 +21339,8 @@ function CalendarGrid({
21294
21339
  [resolvedWeekStart]
21295
21340
  );
21296
21341
  const resolvedTimeSlots = React91.useMemo(
21297
- () => timeSlots ?? generateDefaultTimeSlots(),
21298
- [timeSlots]
21342
+ () => timeSlots ?? generateDefaultTimeSlots(evs, startField),
21343
+ [timeSlots, evs, startField]
21299
21344
  );
21300
21345
  const visibleCount = useDayWindow(dayWindow);
21301
21346
  const [dayOffset, setDayOffset] = React91.useState(0);
@@ -21332,9 +21377,9 @@ function CalendarGrid({
21332
21377
  );
21333
21378
  const eventsForDayCount = React91.useCallback(
21334
21379
  (day) => evs.filter(
21335
- (ev) => new Date(ev.startTime).toDateString() === day.toDateString()
21380
+ (ev) => eventStartDate(ev, startField).toDateString() === day.toDateString()
21336
21381
  ).length,
21337
- [events2]
21382
+ [events2, startField]
21338
21383
  );
21339
21384
  const swipeCallbacks = React91.useMemo(() => ({
21340
21385
  onSwipeLeft: swipeLeftEvent ? () => eventBus.emit(`UI:${swipeLeftEvent}`, {}) : void 0,
@@ -21353,8 +21398,11 @@ function CalendarGrid({
21353
21398
  eventBus.emit(`UI:${longPressEvent}`, { date: day.toISOString(), time, ...longPressPayload });
21354
21399
  }, 500);
21355
21400
  }, [longPressEvent, longPressPayload, eventBus]);
21401
+ const renderChip = children ?? renderItem;
21356
21402
  const renderEvent = (event) => {
21357
- const color = event.color;
21403
+ const color = getNestedValue(event, colorField);
21404
+ const label = String(getNestedValue(event, titleField) ?? "");
21405
+ const eventIndex = evs.indexOf(event);
21358
21406
  return /* @__PURE__ */ jsxRuntime.jsx(
21359
21407
  Box,
21360
21408
  {
@@ -21366,7 +21414,7 @@ function CalendarGrid({
21366
21414
  color ? color : "bg-primary/10 border-primary/30 text-primary"
21367
21415
  ),
21368
21416
  onClick: (e) => handleEventClick(event, e),
21369
- children: /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "small", className: "truncate font-medium", children: event.title })
21417
+ children: renderChip ? renderChip(event, eventIndex) : /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "small", className: "truncate font-medium", children: label })
21370
21418
  },
21371
21419
  event.id
21372
21420
  );
@@ -21450,7 +21498,7 @@ function CalendarGrid({
21450
21498
  ) }),
21451
21499
  visibleDays.map((day) => {
21452
21500
  const slotEvents = evs.filter(
21453
- (ev) => eventInSlot(ev, day, time)
21501
+ (ev) => eventInSlot(ev, day, time, startField)
21454
21502
  );
21455
21503
  const isToday = day.toDateString() === (/* @__PURE__ */ new Date()).toDateString();
21456
21504
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -21482,11 +21530,12 @@ function CalendarGrid({
21482
21530
  }
21483
21531
  );
21484
21532
  }
21485
- var SHORT_DATE;
21533
+ var SHORT_DATE, DEFAULT_FIRST_HOUR, DEFAULT_LAST_HOUR, slotLabel;
21486
21534
  var init_CalendarGrid = __esm({
21487
21535
  "components/core/molecules/CalendarGrid.tsx"() {
21488
21536
  "use client";
21489
21537
  init_cn();
21538
+ init_getNestedValue();
21490
21539
  init_Box();
21491
21540
  init_Button();
21492
21541
  init_Stack();
@@ -21497,35 +21546,12 @@ var init_CalendarGrid = __esm({
21497
21546
  init_useEventBus();
21498
21547
  init_useSwipeGesture();
21499
21548
  SHORT_DATE = { month: "short", day: "numeric" };
21549
+ DEFAULT_FIRST_HOUR = 9;
21550
+ DEFAULT_LAST_HOUR = 17;
21551
+ slotLabel = (hour) => `${hour.toString().padStart(2, "0")}:00`;
21500
21552
  CalendarGrid.displayName = "CalendarGrid";
21501
21553
  }
21502
21554
  });
21503
-
21504
- // lib/getNestedValue.ts
21505
- function getNestedValue(obj, path) {
21506
- if (obj === null || obj === void 0 || !path) {
21507
- return void 0;
21508
- }
21509
- if (!path.includes(".")) {
21510
- return obj[path];
21511
- }
21512
- const parts = path.split(".");
21513
- let value = obj;
21514
- for (const part of parts) {
21515
- if (value === null || value === void 0) {
21516
- return void 0;
21517
- }
21518
- if (typeof value !== "object" || Array.isArray(value)) {
21519
- return void 0;
21520
- }
21521
- value = value[part];
21522
- }
21523
- return value;
21524
- }
21525
- var init_getNestedValue = __esm({
21526
- "lib/getNestedValue.ts"() {
21527
- }
21528
- });
21529
21555
  var Pagination;
21530
21556
  var init_Pagination = __esm({
21531
21557
  "components/core/molecules/Pagination.tsx"() {
@@ -45833,6 +45859,13 @@ function MaybeTraitScope({
45833
45859
  if (wrap) {
45834
45860
  return /* @__PURE__ */ jsxRuntime.jsx(providers.TraitScopeProvider, { orbital, trait: sourceTrait, children });
45835
45861
  }
45862
+ if (sourceTrait !== void 0 && schemaCtx !== null) {
45863
+ scopeWrapLog.warn("decline", {
45864
+ sourceTrait,
45865
+ orbitalsByTraitSize: schemaCtx.orbitalsByTrait.size,
45866
+ reason: "sourceTrait not in orbitalsByTrait \u2014 children render unscoped"
45867
+ });
45868
+ }
45836
45869
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
45837
45870
  }
45838
45871
  function UISlotComponent({
@@ -46130,7 +46163,7 @@ function renderPatternChildren(children, onDismiss, parentId = "root", parentPat
46130
46163
  const childId = `${parentId}-${index}`;
46131
46164
  const childPath = parentPath === "root" ? `root.children.${index}` : `${parentPath}.children.${index}`;
46132
46165
  const childAsRecord = child;
46133
- const { type: _childType, props: nestedProps, _id: _childNodeId, children: _childChildren, ...flatProps } = childAsRecord;
46166
+ const { type: _childType, props: nestedProps, _id: _childNodeId, _sourceTrait: childSourceTrait, children: _childChildren, ...flatProps } = childAsRecord;
46134
46167
  const resolvedProps = nestedProps !== void 0 ? nestedProps : flatProps;
46135
46168
  if (_childChildren !== void 0 && nestedProps === void 0) {
46136
46169
  resolvedProps.children = _childChildren;
@@ -46145,11 +46178,14 @@ function renderPatternChildren(children, onDismiss, parentId = "root", parentPat
46145
46178
  // (e.g. form-section inside a stack) can resolve entityDef via
46146
46179
  // the trait's linkedEntity for form-field enrichment. The orbCtx
46147
46180
  // (slot/transition/state/entity) propagates the same way so every
46148
- // nested node carries a complete contextual-edit address.
46149
- ...sourceTrait !== void 0 && { sourceTrait },
46181
+ // nested node carries a complete contextual-edit address. A child
46182
+ // carrying its own `_sourceTrait` (multi-source slot stack) owns it
46183
+ // outright — inheriting the synthetic wrapper's sentinel instead
46184
+ // would erase the real owner.
46185
+ ...childSourceTrait !== void 0 ? { sourceTrait: childSourceTrait } : sourceTrait !== void 0 && { sourceTrait },
46150
46186
  ...orbCtx ?? {}
46151
46187
  };
46152
- return /* @__PURE__ */ jsxRuntime.jsx(
46188
+ const renderedChild = /* @__PURE__ */ jsxRuntime.jsx(
46153
46189
  SlotContentRenderer,
46154
46190
  {
46155
46191
  content: childContent,
@@ -46158,6 +46194,7 @@ function renderPatternChildren(children, onDismiss, parentId = "root", parentPat
46158
46194
  },
46159
46195
  childId
46160
46196
  );
46197
+ return childSourceTrait !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx(MaybeTraitScope, { sourceTrait: childSourceTrait, children: renderedChild }, childId) : renderedChild;
46161
46198
  });
46162
46199
  }
46163
46200
  function toDrawableNodes(children) {
@@ -51267,7 +51304,7 @@ function useTraitStateMachine(traitBindings, uiSlots, options) {
51267
51304
  crossTraitLog.debug("listen:fired", { busKey, targetTrait: binding.trait.name, triggers: listen.triggers });
51268
51305
  enqueueAndDrain(
51269
51306
  listen.triggers,
51270
- core.applyListenPayloadMapping(listen.payloadMapping, event.payload),
51307
+ core.applyListenPayloadMapping(listen.payloadMapping, event.payload, evaluator.evaluateListenPayloadExpr),
51271
51308
  binding.trait.name
51272
51309
  );
51273
51310
  });