@almadar/ui 2.42.0 → 2.45.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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var React113 = require('react');
3
+ var React114 = require('react');
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
  var providers = require('@almadar/ui/providers');
6
6
  require('react-dom');
@@ -58,7 +58,7 @@ function _interopNamespace(e) {
58
58
  return Object.freeze(n);
59
59
  }
60
60
 
61
- var React113__namespace = /*#__PURE__*/_interopNamespace(React113);
61
+ var React114__namespace = /*#__PURE__*/_interopNamespace(React114);
62
62
  var LucideIcons__namespace = /*#__PURE__*/_interopNamespace(LucideIcons);
63
63
  var L__default = /*#__PURE__*/_interopDefault(L);
64
64
  var ReactMarkdown__default = /*#__PURE__*/_interopDefault(ReactMarkdown);
@@ -186,7 +186,7 @@ var BUILT_IN_THEMES = [
186
186
  hasDarkMode: true
187
187
  }
188
188
  ];
189
- var ThemeContext = React113.createContext(void 0);
189
+ var ThemeContext = React114.createContext(void 0);
190
190
  var THEME_STORAGE_KEY = "theme";
191
191
  var MODE_STORAGE_KEY = "theme-mode";
192
192
  function getSystemMode() {
@@ -206,14 +206,14 @@ var ThemeProvider = ({
206
206
  defaultMode = "system",
207
207
  targetRef
208
208
  }) => {
209
- const availableThemes = React113.useMemo(() => {
209
+ const availableThemes = React114.useMemo(() => {
210
210
  const themeMap = /* @__PURE__ */ new Map();
211
211
  BUILT_IN_THEMES.forEach((t) => themeMap.set(t.name, t));
212
212
  themes.forEach((t) => themeMap.set(t.name, t));
213
213
  return Array.from(themeMap.values());
214
214
  }, [themes]);
215
215
  const isScoped = !!targetRef;
216
- const [theme, setThemeState] = React113.useState(() => {
216
+ const [theme, setThemeState] = React114.useState(() => {
217
217
  if (isScoped || typeof window === "undefined") return defaultTheme;
218
218
  const stored = localStorage.getItem(THEME_STORAGE_KEY);
219
219
  const validThemes = [
@@ -225,7 +225,7 @@ var ThemeProvider = ({
225
225
  }
226
226
  return defaultTheme;
227
227
  });
228
- const [mode, setModeState] = React113.useState(() => {
228
+ const [mode, setModeState] = React114.useState(() => {
229
229
  if (isScoped || typeof window === "undefined") return defaultMode;
230
230
  const stored = localStorage.getItem(MODE_STORAGE_KEY);
231
231
  if (stored === "light" || stored === "dark" || stored === "system") {
@@ -233,14 +233,14 @@ var ThemeProvider = ({
233
233
  }
234
234
  return defaultMode;
235
235
  });
236
- const [resolvedMode, setResolvedMode] = React113.useState(
236
+ const [resolvedMode, setResolvedMode] = React114.useState(
237
237
  () => resolveMode(mode)
238
238
  );
239
- const appliedTheme = React113.useMemo(
239
+ const appliedTheme = React114.useMemo(
240
240
  () => `${theme}-${resolvedMode}`,
241
241
  [theme, resolvedMode]
242
242
  );
243
- React113.useEffect(() => {
243
+ React114.useEffect(() => {
244
244
  const updateResolved = () => {
245
245
  setResolvedMode(resolveMode(mode));
246
246
  };
@@ -253,7 +253,7 @@ var ThemeProvider = ({
253
253
  }
254
254
  return void 0;
255
255
  }, [mode]);
256
- React113.useEffect(() => {
256
+ React114.useEffect(() => {
257
257
  if (isScoped) {
258
258
  if (targetRef?.current) {
259
259
  targetRef.current.setAttribute("data-theme", appliedTheme);
@@ -267,7 +267,7 @@ var ThemeProvider = ({
267
267
  root.classList.remove("light", "dark");
268
268
  root.classList.add(resolvedMode);
269
269
  }, [appliedTheme, resolvedMode, targetRef, isScoped]);
270
- const setTheme = React113.useCallback(
270
+ const setTheme = React114.useCallback(
271
271
  (newTheme) => {
272
272
  const validTheme = availableThemes.find((t) => t.name === newTheme);
273
273
  if (validTheme) {
@@ -283,17 +283,17 @@ var ThemeProvider = ({
283
283
  },
284
284
  [availableThemes]
285
285
  );
286
- const setMode = React113.useCallback((newMode) => {
286
+ const setMode = React114.useCallback((newMode) => {
287
287
  setModeState(newMode);
288
288
  if (!isScoped && typeof window !== "undefined") {
289
289
  localStorage.setItem(MODE_STORAGE_KEY, newMode);
290
290
  }
291
291
  }, []);
292
- const toggleMode = React113.useCallback(() => {
292
+ const toggleMode = React114.useCallback(() => {
293
293
  const newMode = resolvedMode === "dark" ? "light" : "dark";
294
294
  setMode(newMode);
295
295
  }, [resolvedMode, setMode]);
296
- const contextValue = React113.useMemo(
296
+ const contextValue2 = React114.useMemo(
297
297
  () => ({
298
298
  theme,
299
299
  mode,
@@ -315,30 +315,97 @@ var ThemeProvider = ({
315
315
  appliedTheme
316
316
  ]
317
317
  );
318
- return /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value: contextValue, children });
318
+ return /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value: contextValue2, children });
319
319
  };
320
320
  var store = /* @__PURE__ */ new Map();
321
321
  var storeListeners = /* @__PURE__ */ new Set();
322
322
  var watchCallbacks = /* @__PURE__ */ new Map();
323
- function advance(entityType, data) {
324
- const prev = store.get(entityType);
325
- const oldData = prev?.data ?? [];
326
- store.set(entityType, { data, version: (prev?.version ?? 0) + 1 });
323
+ function extractId(record) {
324
+ const r = record;
325
+ return String(r.id ?? r._id ?? r.key ?? "");
326
+ }
327
+ function materialize(snap) {
328
+ return snap.ids.map((id) => snap.entities.get(id));
329
+ }
330
+ function notifyListeners(entityType, prev) {
327
331
  for (const listener of storeListeners) {
328
332
  listener();
329
333
  }
330
334
  const cbs = watchCallbacks.get(entityType);
331
335
  if (cbs) {
336
+ const oldData = prev ? materialize(prev) : [];
337
+ const cur = store.get(entityType);
338
+ const newData = cur ? materialize(cur) : [];
332
339
  for (const cb of cbs) {
333
340
  try {
334
- cb(oldData, data);
341
+ cb(oldData, newData);
335
342
  } catch {
336
343
  }
337
344
  }
338
345
  }
339
346
  }
347
+ function setAll(entityType, records) {
348
+ const entities = /* @__PURE__ */ new Map();
349
+ const ids = [];
350
+ for (const r of records) {
351
+ const rec = r;
352
+ const id = extractId(rec);
353
+ if (id) {
354
+ entities.set(id, rec);
355
+ ids.push(id);
356
+ }
357
+ }
358
+ const prev = store.get(entityType);
359
+ store.set(entityType, { entities, ids, version: (prev?.version ?? 0) + 1 });
360
+ notifyListeners(entityType, prev);
361
+ }
362
+ function upsertOne(entityType, record) {
363
+ const id = extractId(record);
364
+ if (!id) return;
365
+ const prev = store.get(entityType);
366
+ const snapshot = prev ? { entities: new Map(prev.entities), ids: [...prev.ids], version: prev.version } : { entities: /* @__PURE__ */ new Map(), ids: [], version: 0 };
367
+ snapshot.entities.set(id, record);
368
+ if (!snapshot.ids.includes(id)) snapshot.ids.push(id);
369
+ snapshot.version++;
370
+ store.set(entityType, snapshot);
371
+ notifyListeners(entityType, prev);
372
+ }
373
+ function addOne(entityType, record) {
374
+ upsertOne(entityType, record);
375
+ }
376
+ function updateOne(entityType, id, changes) {
377
+ const prev = store.get(entityType);
378
+ if (!prev?.entities.has(id)) return;
379
+ const snapshot = {
380
+ entities: new Map(prev.entities),
381
+ ids: [...prev.ids],
382
+ version: prev.version
383
+ };
384
+ snapshot.entities.set(id, { ...snapshot.entities.get(id), ...changes });
385
+ snapshot.version++;
386
+ store.set(entityType, snapshot);
387
+ notifyListeners(entityType, prev);
388
+ }
389
+ function removeOne(entityType, id) {
390
+ const prev = store.get(entityType);
391
+ if (!prev) return;
392
+ const snapshot = {
393
+ entities: new Map(prev.entities),
394
+ ids: prev.ids.filter((i) => i !== id),
395
+ version: prev.version
396
+ };
397
+ snapshot.entities.delete(id);
398
+ snapshot.version++;
399
+ store.set(entityType, snapshot);
400
+ notifyListeners(entityType, prev);
401
+ }
340
402
  function getSnapshot(entityType) {
341
- return store.get(entityType)?.data ?? [];
403
+ const snap = store.get(entityType);
404
+ if (!snap) return [];
405
+ return materialize(snap);
406
+ }
407
+ function getById(entityType, id) {
408
+ return store.get(entityType)?.entities.get(id) ?? null;
342
409
  }
343
410
  function getVersion(entityType) {
344
411
  return store.get(entityType)?.version ?? 0;
@@ -361,9 +428,9 @@ function addWatch(entityType, callback) {
361
428
  };
362
429
  }
363
430
  function useEntityRef(entityType) {
364
- const versionRef = React113.useRef(0);
365
- const dataRef = React113.useRef([]);
366
- const getSnapshotStable = React113__namespace.default.useCallback(() => {
431
+ const versionRef = React114.useRef(0);
432
+ const dataRef = React114.useRef([]);
433
+ const getSnapshotStable = React114__namespace.default.useCallback(() => {
367
434
  const currentVersion = getVersion(entityType);
368
435
  if (currentVersion !== versionRef.current) {
369
436
  versionRef.current = currentVersion;
@@ -371,26 +438,46 @@ function useEntityRef(entityType) {
371
438
  }
372
439
  return dataRef.current;
373
440
  }, [entityType]);
374
- return React113.useSyncExternalStore(subscribeToStore, getSnapshotStable, () => []);
441
+ return React114.useSyncExternalStore(subscribeToStore, getSnapshotStable, () => []);
442
+ }
443
+ function useEntityById(entityType, id) {
444
+ const versionRef = React114.useRef(0);
445
+ const dataRef = React114.useRef(null);
446
+ const getSnapshotStable = React114__namespace.default.useCallback(() => {
447
+ if (!id) return null;
448
+ const currentVersion = getVersion(entityType);
449
+ if (currentVersion !== versionRef.current) {
450
+ versionRef.current = currentVersion;
451
+ dataRef.current = getById(entityType, id);
452
+ }
453
+ return dataRef.current;
454
+ }, [entityType, id]);
455
+ return React114.useSyncExternalStore(subscribeToStore, getSnapshotStable, () => null);
375
456
  }
376
457
  function useEntityWatch(entityType, callback) {
377
- const callbackRef = React113.useRef(callback);
458
+ const callbackRef = React114.useRef(callback);
378
459
  callbackRef.current = callback;
379
- React113.useEffect(() => {
460
+ React114.useEffect(() => {
380
461
  return addWatch(entityType, (oldData, newData) => {
381
462
  callbackRef.current(oldData, newData);
382
463
  });
383
464
  }, [entityType]);
384
465
  }
385
- var EntityStoreContext = React113.createContext({
386
- advance,
387
- getSnapshot
388
- });
466
+ var contextValue = {
467
+ setAll,
468
+ upsertOne,
469
+ addOne,
470
+ updateOne,
471
+ removeOne,
472
+ getSnapshot,
473
+ getById
474
+ };
475
+ var EntityStoreContext = React114.createContext(contextValue);
389
476
  function useEntityStore() {
390
- return React113.useContext(EntityStoreContext);
477
+ return React114.useContext(EntityStoreContext);
391
478
  }
392
479
  function EntityStoreProvider({ children }) {
393
- return /* @__PURE__ */ jsxRuntime.jsx(EntityStoreContext.Provider, { value: { advance, getSnapshot }, children });
480
+ return /* @__PURE__ */ jsxRuntime.jsx(EntityStoreContext.Provider, { value: contextValue, children });
394
481
  }
395
482
  function setGlobalEventBus(bus) {
396
483
  if (typeof window !== "undefined") {
@@ -464,15 +551,15 @@ var fallbackEventBus = {
464
551
  }
465
552
  };
466
553
  function useEventBus() {
467
- const context = React113.useContext(providers.EventBusContext);
554
+ const context = React114.useContext(providers.EventBusContext);
468
555
  return context ?? getGlobalEventBus() ?? fallbackEventBus;
469
556
  }
470
- var EventBusContext2 = React113.createContext(null);
557
+ var EventBusContext2 = React114.createContext(null);
471
558
  function EventBusProvider({ children, debug: debug2 = false }) {
472
- const listenersRef = React113.useRef(/* @__PURE__ */ new Map());
473
- const anyListenersRef = React113.useRef(/* @__PURE__ */ new Set());
474
- const deprecationWarningShown = React113.useRef(false);
475
- const getSelectedEntity = React113.useCallback(() => {
559
+ const listenersRef = React114.useRef(/* @__PURE__ */ new Map());
560
+ const anyListenersRef = React114.useRef(/* @__PURE__ */ new Set());
561
+ const deprecationWarningShown = React114.useRef(false);
562
+ const getSelectedEntity = React114.useCallback(() => {
476
563
  if (!deprecationWarningShown.current) {
477
564
  console.warn(
478
565
  "[EventBus] getSelectedEntity is deprecated. Use SelectionProvider and useSelection hook instead. See SelectionProvider.tsx for migration guide."
@@ -481,7 +568,7 @@ function EventBusProvider({ children, debug: debug2 = false }) {
481
568
  }
482
569
  return null;
483
570
  }, []);
484
- const clearSelectedEntity = React113.useCallback(() => {
571
+ const clearSelectedEntity = React114.useCallback(() => {
485
572
  if (!deprecationWarningShown.current) {
486
573
  console.warn(
487
574
  "[EventBus] clearSelectedEntity is deprecated. Use SelectionProvider and useSelection hook instead. See SelectionProvider.tsx for migration guide."
@@ -489,7 +576,7 @@ function EventBusProvider({ children, debug: debug2 = false }) {
489
576
  deprecationWarningShown.current = true;
490
577
  }
491
578
  }, []);
492
- const emit = React113.useCallback((type, payload) => {
579
+ const emit = React114.useCallback((type, payload) => {
493
580
  const event = {
494
581
  type,
495
582
  payload,
@@ -523,7 +610,7 @@ function EventBusProvider({ children, debug: debug2 = false }) {
523
610
  }
524
611
  }
525
612
  }, [debug2]);
526
- const on = React113.useCallback((type, listener) => {
613
+ const on = React114.useCallback((type, listener) => {
527
614
  if (!listenersRef.current.has(type)) {
528
615
  listenersRef.current.set(type, /* @__PURE__ */ new Set());
529
616
  }
@@ -542,18 +629,18 @@ function EventBusProvider({ children, debug: debug2 = false }) {
542
629
  }
543
630
  };
544
631
  }, [debug2]);
545
- const once = React113.useCallback((type, listener) => {
632
+ const once = React114.useCallback((type, listener) => {
546
633
  const wrappedListener = (event) => {
547
634
  listenersRef.current.get(type)?.delete(wrappedListener);
548
635
  listener(event);
549
636
  };
550
637
  return on(type, wrappedListener);
551
638
  }, [on]);
552
- const hasListeners = React113.useCallback((type) => {
639
+ const hasListeners = React114.useCallback((type) => {
553
640
  const listeners6 = listenersRef.current.get(type);
554
641
  return listeners6 !== void 0 && listeners6.size > 0;
555
642
  }, []);
556
- const onAny = React113.useCallback((listener) => {
643
+ const onAny = React114.useCallback((listener) => {
557
644
  anyListenersRef.current.add(listener);
558
645
  if (debug2) {
559
646
  console.log(`[EventBus] onAny subscribed, total: ${anyListenersRef.current.size}`);
@@ -565,7 +652,7 @@ function EventBusProvider({ children, debug: debug2 = false }) {
565
652
  }
566
653
  };
567
654
  }, [debug2]);
568
- const contextValue = React113.useMemo(
655
+ const contextValue2 = React114.useMemo(
569
656
  () => ({
570
657
  emit,
571
658
  on,
@@ -577,15 +664,15 @@ function EventBusProvider({ children, debug: debug2 = false }) {
577
664
  }),
578
665
  [emit, on, once, hasListeners, onAny, getSelectedEntity, clearSelectedEntity]
579
666
  );
580
- React113.useEffect(() => {
581
- setGlobalEventBus(contextValue);
667
+ React114.useEffect(() => {
668
+ setGlobalEventBus(contextValue2);
582
669
  return () => {
583
670
  setGlobalEventBus(null);
584
671
  };
585
- }, [contextValue]);
586
- return /* @__PURE__ */ jsxRuntime.jsx(EventBusContext2.Provider, { value: contextValue, children });
672
+ }, [contextValue2]);
673
+ return /* @__PURE__ */ jsxRuntime.jsx(EventBusContext2.Provider, { value: contextValue2, children });
587
674
  }
588
- var SelectionContext = React113.createContext(null);
675
+ var SelectionContext = React114.createContext(null);
589
676
  var defaultCompareEntities = (a, b) => {
590
677
  if (a === b) return true;
591
678
  if (!a || !b) return false;
@@ -602,8 +689,8 @@ function SelectionProvider({
602
689
  compareEntities = defaultCompareEntities
603
690
  }) {
604
691
  const eventBus = useEventBus();
605
- const [selected, setSelectedState] = React113.useState(null);
606
- const setSelected = React113.useCallback(
692
+ const [selected, setSelectedState] = React114.useState(null);
693
+ const setSelected = React114.useCallback(
607
694
  (entity) => {
608
695
  setSelectedState(entity);
609
696
  if (debug2) {
@@ -612,19 +699,19 @@ function SelectionProvider({
612
699
  },
613
700
  [debug2]
614
701
  );
615
- const clearSelection = React113.useCallback(() => {
702
+ const clearSelection = React114.useCallback(() => {
616
703
  setSelectedState(null);
617
704
  if (debug2) {
618
705
  console.log("[SelectionProvider] Selection cleared");
619
706
  }
620
707
  }, [debug2]);
621
- const isSelected = React113.useCallback(
708
+ const isSelected = React114.useCallback(
622
709
  (entity) => {
623
710
  return compareEntities(selected, entity);
624
711
  },
625
712
  [selected, compareEntities]
626
713
  );
627
- React113.useEffect(() => {
714
+ React114.useEffect(() => {
628
715
  const handleSelect = (event) => {
629
716
  const row = event.payload?.row;
630
717
  if (row) {
@@ -653,25 +740,26 @@ function SelectionProvider({
653
740
  unsubCancel();
654
741
  };
655
742
  }, [eventBus, setSelected, clearSelection, debug2]);
656
- const contextValue = {
743
+ const contextValue2 = {
657
744
  selected,
658
745
  setSelected,
659
746
  clearSelection,
660
747
  isSelected
661
748
  };
662
- return /* @__PURE__ */ jsxRuntime.jsx(SelectionContext.Provider, { value: contextValue, children });
749
+ return /* @__PURE__ */ jsxRuntime.jsx(SelectionContext.Provider, { value: contextValue2, children });
663
750
  }
664
751
  function useSelection() {
665
- const context = React113.useContext(SelectionContext);
752
+ const context = React114.useContext(SelectionContext);
666
753
  if (!context) {
667
754
  throw new Error("useSelection must be used within a SelectionProvider");
668
755
  }
669
756
  return context;
670
757
  }
671
758
  function useSelectionOptional() {
672
- const context = React113.useContext(SelectionContext);
759
+ const context = React114.useContext(SelectionContext);
673
760
  return context;
674
761
  }
762
+ React114.createContext(null);
675
763
  function cn(...inputs) {
676
764
  return tailwindMerge.twMerge(clsx.clsx(inputs));
677
765
  }
@@ -812,7 +900,7 @@ var positionStyles = {
812
900
  fixed: "fixed",
813
901
  sticky: "sticky"
814
902
  };
815
- var Box = React113__namespace.default.forwardRef(
903
+ var Box = React114__namespace.default.forwardRef(
816
904
  ({
817
905
  padding,
818
906
  paddingX,
@@ -841,20 +929,20 @@ var Box = React113__namespace.default.forwardRef(
841
929
  ...rest
842
930
  }, ref) => {
843
931
  const eventBus = useEventBus();
844
- const handleClick = React113.useCallback((e) => {
932
+ const handleClick = React114.useCallback((e) => {
845
933
  if (action) {
846
934
  e.stopPropagation();
847
935
  eventBus.emit(`UI:${action}`, actionPayload ?? {});
848
936
  }
849
937
  onClick?.(e);
850
938
  }, [action, actionPayload, eventBus, onClick]);
851
- const handleMouseEnter = React113.useCallback((e) => {
939
+ const handleMouseEnter = React114.useCallback((e) => {
852
940
  if (hoverEvent) {
853
941
  eventBus.emit(`UI:${hoverEvent}`, { hovered: true });
854
942
  }
855
943
  onMouseEnter?.(e);
856
944
  }, [hoverEvent, eventBus, onMouseEnter]);
857
- const handleMouseLeave = React113.useCallback((e) => {
945
+ const handleMouseLeave = React114.useCallback((e) => {
858
946
  if (hoverEvent) {
859
947
  eventBus.emit(`UI:${hoverEvent}`, { hovered: false });
860
948
  }
@@ -1083,7 +1171,7 @@ function resolveIconProp(value, sizeClass) {
1083
1171
  const IconComp = value;
1084
1172
  return /* @__PURE__ */ jsxRuntime.jsx(IconComp, { className: sizeClass });
1085
1173
  }
1086
- if (React113__namespace.default.isValidElement(value)) {
1174
+ if (React114__namespace.default.isValidElement(value)) {
1087
1175
  return value;
1088
1176
  }
1089
1177
  if (typeof value === "object" && value !== null && "render" in value) {
@@ -1092,7 +1180,7 @@ function resolveIconProp(value, sizeClass) {
1092
1180
  }
1093
1181
  return value;
1094
1182
  }
1095
- var Button = React113__namespace.default.forwardRef(
1183
+ var Button = React114__namespace.default.forwardRef(
1096
1184
  ({
1097
1185
  className,
1098
1186
  variant = "primary",
@@ -1188,7 +1276,7 @@ var sizeStyles3 = {
1188
1276
  md: "px-2.5 py-1 text-sm",
1189
1277
  lg: "px-3 py-1.5 text-base"
1190
1278
  };
1191
- var Badge = React113__namespace.default.forwardRef(
1279
+ var Badge = React114__namespace.default.forwardRef(
1192
1280
  ({ className, variant = "default", size = "sm", amount, label, icon, children, ...props }, ref) => {
1193
1281
  const iconSizes2 = { sm: "w-3 h-3", md: "w-3.5 h-3.5", lg: "w-4 h-4" };
1194
1282
  const resolvedIcon = typeof icon === "string" ? (() => {
@@ -1215,7 +1303,7 @@ var Badge = React113__namespace.default.forwardRef(
1215
1303
  }
1216
1304
  );
1217
1305
  Badge.displayName = "Badge";
1218
- var Input = React113__namespace.default.forwardRef(
1306
+ var Input = React114__namespace.default.forwardRef(
1219
1307
  ({
1220
1308
  className,
1221
1309
  inputType,
@@ -1327,7 +1415,7 @@ var Input = React113__namespace.default.forwardRef(
1327
1415
  }
1328
1416
  );
1329
1417
  Input.displayName = "Input";
1330
- var Label = React113__namespace.default.forwardRef(
1418
+ var Label = React114__namespace.default.forwardRef(
1331
1419
  ({ className, required, children, ...props }, ref) => {
1332
1420
  return /* @__PURE__ */ jsxRuntime.jsxs(
1333
1421
  "label",
@@ -1347,7 +1435,7 @@ var Label = React113__namespace.default.forwardRef(
1347
1435
  }
1348
1436
  );
1349
1437
  Label.displayName = "Label";
1350
- var Textarea = React113__namespace.default.forwardRef(
1438
+ var Textarea = React114__namespace.default.forwardRef(
1351
1439
  ({ className, error, ...props }, ref) => {
1352
1440
  return /* @__PURE__ */ jsxRuntime.jsx(
1353
1441
  "textarea",
@@ -1370,7 +1458,7 @@ var Textarea = React113__namespace.default.forwardRef(
1370
1458
  }
1371
1459
  );
1372
1460
  Textarea.displayName = "Textarea";
1373
- var Select = React113__namespace.default.forwardRef(
1461
+ var Select = React114__namespace.default.forwardRef(
1374
1462
  ({ className, options, placeholder, error, ...props }, ref) => {
1375
1463
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
1376
1464
  /* @__PURE__ */ jsxRuntime.jsxs(
@@ -1406,7 +1494,7 @@ var Select = React113__namespace.default.forwardRef(
1406
1494
  }
1407
1495
  );
1408
1496
  Select.displayName = "Select";
1409
- var Checkbox = React113__namespace.default.forwardRef(
1497
+ var Checkbox = React114__namespace.default.forwardRef(
1410
1498
  ({ className, label, id, ...props }, ref) => {
1411
1499
  const inputId = id || `checkbox-${Math.random().toString(36).substr(2, 9)}`;
1412
1500
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center", children: [
@@ -1482,7 +1570,7 @@ var shadowStyles2 = {
1482
1570
  md: "shadow",
1483
1571
  lg: "shadow-lg"
1484
1572
  };
1485
- var Card = React113__namespace.default.forwardRef(
1573
+ var Card = React114__namespace.default.forwardRef(
1486
1574
  ({
1487
1575
  className,
1488
1576
  variant = "bordered",
@@ -1518,9 +1606,9 @@ var Card = React113__namespace.default.forwardRef(
1518
1606
  }
1519
1607
  );
1520
1608
  Card.displayName = "Card";
1521
- var CardHeader = React113__namespace.default.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn("mb-4", className), ...props }));
1609
+ var CardHeader = React114__namespace.default.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn("mb-4", className), ...props }));
1522
1610
  CardHeader.displayName = "CardHeader";
1523
- var CardTitle = React113__namespace.default.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1611
+ var CardTitle = React114__namespace.default.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1524
1612
  "h3",
1525
1613
  {
1526
1614
  ref,
@@ -1533,11 +1621,11 @@ var CardTitle = React113__namespace.default.forwardRef(({ className, ...props },
1533
1621
  }
1534
1622
  ));
1535
1623
  CardTitle.displayName = "CardTitle";
1536
- var CardContent = React113__namespace.default.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn("", className), ...props }));
1624
+ var CardContent = React114__namespace.default.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn("", className), ...props }));
1537
1625
  CardContent.displayName = "CardContent";
1538
1626
  var CardBody = CardContent;
1539
1627
  CardBody.displayName = "CardBody";
1540
- var CardFooter = React113__namespace.default.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1628
+ var CardFooter = React114__namespace.default.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1541
1629
  "div",
1542
1630
  {
1543
1631
  ref,
@@ -1552,7 +1640,7 @@ var sizeStyles4 = {
1552
1640
  md: "h-6 w-6",
1553
1641
  lg: "h-8 w-8"
1554
1642
  };
1555
- var Spinner = React113__namespace.default.forwardRef(
1643
+ var Spinner = React114__namespace.default.forwardRef(
1556
1644
  ({ className, size = "md", ...props }, ref) => {
1557
1645
  return /* @__PURE__ */ jsxRuntime.jsx(
1558
1646
  "div",
@@ -1566,7 +1654,7 @@ var Spinner = React113__namespace.default.forwardRef(
1566
1654
  }
1567
1655
  );
1568
1656
  Spinner.displayName = "Spinner";
1569
- var Radio = React113__namespace.default.forwardRef(
1657
+ var Radio = React114__namespace.default.forwardRef(
1570
1658
  ({
1571
1659
  label,
1572
1660
  helperText,
@@ -1670,7 +1758,7 @@ var Radio = React113__namespace.default.forwardRef(
1670
1758
  }
1671
1759
  );
1672
1760
  Radio.displayName = "Radio";
1673
- var Switch = React113__namespace.forwardRef(
1761
+ var Switch = React114__namespace.forwardRef(
1674
1762
  ({
1675
1763
  checked,
1676
1764
  defaultChecked = false,
@@ -1681,10 +1769,10 @@ var Switch = React113__namespace.forwardRef(
1681
1769
  name,
1682
1770
  className
1683
1771
  }, ref) => {
1684
- const [isChecked, setIsChecked] = React113__namespace.useState(
1772
+ const [isChecked, setIsChecked] = React114__namespace.useState(
1685
1773
  checked !== void 0 ? checked : defaultChecked
1686
1774
  );
1687
- React113__namespace.useEffect(() => {
1775
+ React114__namespace.useEffect(() => {
1688
1776
  if (checked !== void 0) {
1689
1777
  setIsChecked(checked);
1690
1778
  }
@@ -1842,7 +1930,7 @@ var sizeStyles5 = {
1842
1930
  md: "w-2.5 h-2.5",
1843
1931
  lg: "w-3 h-3"
1844
1932
  };
1845
- var StatusDot = React113__namespace.default.forwardRef(
1933
+ var StatusDot = React114__namespace.default.forwardRef(
1846
1934
  ({ className, status = "offline", pulse = false, size = "md", label, ...props }, ref) => {
1847
1935
  return /* @__PURE__ */ jsxRuntime.jsx(
1848
1936
  "span",
@@ -1889,7 +1977,7 @@ var iconMap2 = {
1889
1977
  down: LucideIcons.TrendingDown,
1890
1978
  flat: LucideIcons.ArrowRight
1891
1979
  };
1892
- var TrendIndicator = React113__namespace.default.forwardRef(
1980
+ var TrendIndicator = React114__namespace.default.forwardRef(
1893
1981
  ({
1894
1982
  className,
1895
1983
  value,
@@ -1948,7 +2036,7 @@ var thumbSizes = {
1948
2036
  md: "w-4 h-4",
1949
2037
  lg: "w-5 h-5"
1950
2038
  };
1951
- var RangeSlider = React113__namespace.default.forwardRef(
2039
+ var RangeSlider = React114__namespace.default.forwardRef(
1952
2040
  ({
1953
2041
  className,
1954
2042
  min = 0,
@@ -1966,14 +2054,14 @@ var RangeSlider = React113__namespace.default.forwardRef(
1966
2054
  formatValue: formatValue5,
1967
2055
  ...props
1968
2056
  }, ref) => {
1969
- const [isDragging, setIsDragging] = React113.useState(false);
1970
- const [showTip, setShowTip] = React113.useState(false);
1971
- const inputRef = React113.useRef(null);
2057
+ const [isDragging, setIsDragging] = React114.useState(false);
2058
+ const [showTip, setShowTip] = React114.useState(false);
2059
+ const inputRef = React114.useRef(null);
1972
2060
  const eventBus = useSafeEventBus();
1973
2061
  const percentage = max !== min ? (value - min) / (max - min) * 100 : 0;
1974
2062
  const bufferedPercentage = buffered !== void 0 ? Math.min(buffered, 100) : void 0;
1975
2063
  const displayValue = formatValue5 ? formatValue5(value) : String(value);
1976
- const handleChange = React113.useCallback(
2064
+ const handleChange = React114.useCallback(
1977
2065
  (e) => {
1978
2066
  const newValue = Number(e.target.value);
1979
2067
  onChange?.(newValue);
@@ -2151,7 +2239,7 @@ var paddingClasses = {
2151
2239
  md: "py-16",
2152
2240
  lg: "py-24"
2153
2241
  };
2154
- var ContentSection = React113__namespace.default.forwardRef(
2242
+ var ContentSection = React114__namespace.default.forwardRef(
2155
2243
  ({ children, background = "default", padding = "lg", id, className }, ref) => {
2156
2244
  return /* @__PURE__ */ jsxRuntime.jsx(
2157
2245
  Box,
@@ -2190,7 +2278,7 @@ var animatedStyles = {
2190
2278
  "scale-up": { opacity: 1, transform: "scale(1) translateY(0)" },
2191
2279
  "none": {}
2192
2280
  };
2193
- var AnimatedReveal = React113__namespace.default.forwardRef(
2281
+ var AnimatedReveal = React114__namespace.default.forwardRef(
2194
2282
  ({
2195
2283
  trigger = "scroll",
2196
2284
  animation = "fade-up",
@@ -2205,10 +2293,10 @@ var AnimatedReveal = React113__namespace.default.forwardRef(
2205
2293
  style,
2206
2294
  ...props
2207
2295
  }, forwardedRef) => {
2208
- const [isAnimated, setIsAnimated] = React113.useState(false);
2209
- const internalRef = React113.useRef(null);
2210
- const hasAnimated = React113.useRef(false);
2211
- const setRef = React113.useCallback(
2296
+ const [isAnimated, setIsAnimated] = React114.useState(false);
2297
+ const internalRef = React114.useRef(null);
2298
+ const hasAnimated = React114.useRef(false);
2299
+ const setRef = React114.useCallback(
2212
2300
  (node) => {
2213
2301
  internalRef.current = node;
2214
2302
  if (typeof forwardedRef === "function") forwardedRef(node);
@@ -2216,7 +2304,7 @@ var AnimatedReveal = React113__namespace.default.forwardRef(
2216
2304
  },
2217
2305
  [forwardedRef]
2218
2306
  );
2219
- React113.useEffect(() => {
2307
+ React114.useEffect(() => {
2220
2308
  if (trigger !== "scroll") return;
2221
2309
  const el = internalRef.current;
2222
2310
  if (!el) return;
@@ -2242,7 +2330,7 @@ var AnimatedReveal = React113__namespace.default.forwardRef(
2242
2330
  setIsAnimated(false);
2243
2331
  }
2244
2332
  } : void 0;
2245
- React113.useEffect(() => {
2333
+ React114.useEffect(() => {
2246
2334
  if (trigger === "manual" && manualAnimate !== void 0) {
2247
2335
  setIsAnimated(manualAnimate);
2248
2336
  }
@@ -2272,9 +2360,9 @@ var AnimatedReveal = React113__namespace.default.forwardRef(
2272
2360
  );
2273
2361
  AnimatedReveal.displayName = "AnimatedReveal";
2274
2362
  function useFetchedSvg(src) {
2275
- const [svg, setSvg] = React113.useState(null);
2276
- const cache = React113.useRef({});
2277
- React113.useEffect(() => {
2363
+ const [svg, setSvg] = React114.useState(null);
2364
+ const cache = React114.useRef({});
2365
+ React114.useEffect(() => {
2278
2366
  if (!src) {
2279
2367
  setSvg(null);
2280
2368
  return;
@@ -2343,7 +2431,7 @@ function applyMorphAnimation(container, animate, duration, delay, easing) {
2343
2431
  el.style.opacity = animate ? "1" : "0";
2344
2432
  });
2345
2433
  }
2346
- var AnimatedGraphic = React113__namespace.default.forwardRef(
2434
+ var AnimatedGraphic = React114__namespace.default.forwardRef(
2347
2435
  ({
2348
2436
  src,
2349
2437
  svgContent,
@@ -2362,11 +2450,11 @@ var AnimatedGraphic = React113__namespace.default.forwardRef(
2362
2450
  children,
2363
2451
  ...props
2364
2452
  }, ref) => {
2365
- const containerRef = React113.useRef(null);
2453
+ const containerRef = React114.useRef(null);
2366
2454
  const fetchedSvg = useFetchedSvg(svgContent ? void 0 : src);
2367
2455
  const resolvedSvg = svgContent ?? fetchedSvg;
2368
- const prevAnimateRef = React113.useRef(animate);
2369
- const setRef = React113__namespace.default.useCallback(
2456
+ const prevAnimateRef = React114.useRef(animate);
2457
+ const setRef = React114__namespace.default.useCallback(
2370
2458
  (node) => {
2371
2459
  containerRef.current = node;
2372
2460
  if (typeof ref === "function") ref(node);
@@ -2374,7 +2462,7 @@ var AnimatedGraphic = React113__namespace.default.forwardRef(
2374
2462
  },
2375
2463
  [ref]
2376
2464
  );
2377
- React113.useEffect(() => {
2465
+ React114.useEffect(() => {
2378
2466
  const el = containerRef.current;
2379
2467
  if (!el || !strokeColor) return;
2380
2468
  const paths = el.querySelectorAll("path, line, polyline, polygon, circle, ellipse, rect");
@@ -2382,7 +2470,7 @@ var AnimatedGraphic = React113__namespace.default.forwardRef(
2382
2470
  p2.style.stroke = strokeColor;
2383
2471
  });
2384
2472
  }, [resolvedSvg, strokeColor]);
2385
- React113.useEffect(() => {
2473
+ React114.useEffect(() => {
2386
2474
  const el = containerRef.current;
2387
2475
  if (!el || !resolvedSvg) return;
2388
2476
  if (animation === "draw" || animation === "fill") {
@@ -2407,7 +2495,7 @@ var AnimatedGraphic = React113__namespace.default.forwardRef(
2407
2495
  });
2408
2496
  }
2409
2497
  }, [resolvedSvg, animation]);
2410
- React113.useEffect(() => {
2498
+ React114.useEffect(() => {
2411
2499
  const el = containerRef.current;
2412
2500
  if (!el) return;
2413
2501
  const id = requestAnimationFrame(() => {
@@ -2563,7 +2651,7 @@ var en_default = {
2563
2651
  // hooks/useTranslate.ts
2564
2652
  var { $meta: _meta, ...coreMessages } = en_default;
2565
2653
  var coreLocale = coreMessages;
2566
- var I18nContext = React113.createContext({
2654
+ var I18nContext = React114.createContext({
2567
2655
  locale: "en",
2568
2656
  direction: "ltr",
2569
2657
  t: (key) => coreLocale[key] ?? key
@@ -2572,7 +2660,7 @@ var I18nContext = React113.createContext({
2572
2660
  I18nContext.displayName = "I18nContext";
2573
2661
  I18nContext.Provider;
2574
2662
  function useTranslate() {
2575
- return React113.useContext(I18nContext);
2663
+ return React114.useContext(I18nContext);
2576
2664
  }
2577
2665
  var ErrorState = ({
2578
2666
  title,
@@ -2608,7 +2696,7 @@ var ErrorState = ({
2608
2696
  );
2609
2697
  };
2610
2698
  ErrorState.displayName = "ErrorState";
2611
- var ErrorBoundary = class extends React113__namespace.default.Component {
2699
+ var ErrorBoundary = class extends React114__namespace.default.Component {
2612
2700
  constructor(props) {
2613
2701
  super(props);
2614
2702
  __publicField(this, "reset", () => {
@@ -2707,7 +2795,7 @@ function executeNotify(message, options, config) {
2707
2795
  function executeEmit(event, payload, config) {
2708
2796
  config.eventBus.emit(event, payload);
2709
2797
  }
2710
- var ClientEffectConfigContext = React113.createContext(null);
2798
+ var ClientEffectConfigContext = React114.createContext(null);
2711
2799
  ClientEffectConfigContext.Provider;
2712
2800
  var effectIdCounter = 0;
2713
2801
  function generateEffectId() {
@@ -2946,14 +3034,14 @@ var OfflineExecutor = class {
2946
3034
  }
2947
3035
  };
2948
3036
  function useOfflineExecutor(options) {
2949
- const executorRef = React113.useRef(null);
2950
- const [state, setState] = React113.useState({
3037
+ const executorRef = React114.useRef(null);
3038
+ const [state, setState] = React114.useState({
2951
3039
  isOffline: false,
2952
3040
  syncQueue: [],
2953
3041
  localEffectsProcessed: 0,
2954
3042
  effectsSynced: 0
2955
3043
  });
2956
- React113.useEffect(() => {
3044
+ React114.useEffect(() => {
2957
3045
  const executor = new OfflineExecutor({
2958
3046
  ...options,
2959
3047
  onQueueChange: (queue) => {
@@ -2968,7 +3056,7 @@ function useOfflineExecutor(options) {
2968
3056
  executorRef.current = null;
2969
3057
  };
2970
3058
  }, []);
2971
- React113.useEffect(() => {
3059
+ React114.useEffect(() => {
2972
3060
  if (!options.autoSync || !options.serverUrl) return;
2973
3061
  const handleOnline = async () => {
2974
3062
  if (executorRef.current) {
@@ -2982,13 +3070,13 @@ function useOfflineExecutor(options) {
2982
3070
  window.addEventListener("online", handleOnline);
2983
3071
  return () => window.removeEventListener("online", handleOnline);
2984
3072
  }, [options.autoSync, options.serverUrl, options.authToken]);
2985
- const executeEffects = React113.useCallback((effects) => {
3073
+ const executeEffects = React114.useCallback((effects) => {
2986
3074
  executorRef.current?.executeClientEffects(effects);
2987
3075
  if (executorRef.current) {
2988
3076
  setState(executorRef.current.getState());
2989
3077
  }
2990
3078
  }, []);
2991
- const processEventOffline = React113.useCallback(
3079
+ const processEventOffline = React114.useCallback(
2992
3080
  (event, payload, effects) => {
2993
3081
  const result = executorRef.current?.processEventOffline(event, payload, effects);
2994
3082
  if (executorRef.current) {
@@ -2998,7 +3086,7 @@ function useOfflineExecutor(options) {
2998
3086
  },
2999
3087
  []
3000
3088
  );
3001
- const sync = React113.useCallback(async () => {
3089
+ const sync = React114.useCallback(async () => {
3002
3090
  if (!executorRef.current || !options.serverUrl) return 0;
3003
3091
  const count = await executorRef.current.syncPendingEffects(
3004
3092
  options.serverUrl,
@@ -3007,7 +3095,7 @@ function useOfflineExecutor(options) {
3007
3095
  setState(executorRef.current.getState());
3008
3096
  return count;
3009
3097
  }, [options.serverUrl, options.authToken]);
3010
- const clearQueue = React113.useCallback(() => {
3098
+ const clearQueue = React114.useCallback(() => {
3011
3099
  executorRef.current?.clearQueue();
3012
3100
  if (executorRef.current) {
3013
3101
  setState(executorRef.current.getState());
@@ -3023,7 +3111,7 @@ function useOfflineExecutor(options) {
3023
3111
  clearQueue
3024
3112
  };
3025
3113
  }
3026
- React113.createContext(null);
3114
+ React114.createContext(null);
3027
3115
  var defaultIcon = L__default.default.icon({
3028
3116
  iconUrl: "https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon.png",
3029
3117
  iconRetinaUrl: "https://unpkg.com/leaflet@1.9.4/dist/images/marker-icon-2x.png",
@@ -3052,13 +3140,13 @@ function getState() {
3052
3140
  }
3053
3141
  return { checks: /* @__PURE__ */ new Map(), transitions: [], bridgeHealth: null, listeners: /* @__PURE__ */ new Set() };
3054
3142
  }
3055
- function notifyListeners() {
3143
+ function notifyListeners2() {
3056
3144
  getState().listeners.forEach((l) => l());
3057
3145
  exposeOnWindow();
3058
3146
  }
3059
3147
  function registerCheck(id, label, status = "pending", details) {
3060
3148
  getState().checks.set(id, { id, label, status, details, updatedAt: Date.now() });
3061
- notifyListeners();
3149
+ notifyListeners2();
3062
3150
  }
3063
3151
  function getAllChecks() {
3064
3152
  return Array.from(getState().checks.values());
@@ -3102,7 +3190,7 @@ function recordTransition(trace) {
3102
3190
  failedEffects.map((e) => `${e.type}: ${e.error}`).join("; ")
3103
3191
  );
3104
3192
  }
3105
- notifyListeners();
3193
+ notifyListeners2();
3106
3194
  }
3107
3195
  function getTransitions() {
3108
3196
  return [...getState().transitions];
@@ -3201,7 +3289,7 @@ function bindTraitStateGetter(getter) {
3201
3289
  }
3202
3290
  }
3203
3291
  exposeOnWindow();
3204
- var MarkdownContent = React113__namespace.default.memo(
3292
+ var MarkdownContent = React114__namespace.default.memo(
3205
3293
  ({ content, direction, className }) => {
3206
3294
  const { t: _t } = useTranslate();
3207
3295
  const safeContent = typeof content === "string" ? content : String(content ?? "");
@@ -3267,7 +3355,7 @@ var MarkdownContent = React113__namespace.default.memo(
3267
3355
  "th",
3268
3356
  {
3269
3357
  ...props,
3270
- className: "border border-gray-300 dark:border-gray-600 bg-gray-100 dark:bg-gray-800 px-4 py-2 text-left font-semibold",
3358
+ className: "border border-gray-300 dark:border-gray-600 bg-[var(--color-muted)] px-4 py-2 text-left font-semibold",
3271
3359
  children
3272
3360
  }
3273
3361
  );
@@ -3348,13 +3436,50 @@ var orbStyleOverrides = {
3348
3436
  "orb-op-async": { color: syntax.ORB_COLORS.dark.async }
3349
3437
  };
3350
3438
  var orbStyle = { ...dark__default.default, ...orbStyleOverrides };
3351
- var CodeBlock = React113__namespace.default.memo(
3439
+ function computeFoldRegions(code) {
3440
+ const lines = code.split("\n");
3441
+ const regions = [];
3442
+ const stack = [];
3443
+ for (let i = 0; i < lines.length; i++) {
3444
+ const line = lines[i];
3445
+ let inString = false;
3446
+ for (let j = 0; j < line.length; j++) {
3447
+ const ch = line[j];
3448
+ if (ch === "\\" && inString) {
3449
+ j++;
3450
+ continue;
3451
+ }
3452
+ if (ch === '"') {
3453
+ inString = !inString;
3454
+ continue;
3455
+ }
3456
+ if (inString) continue;
3457
+ if (ch === "{" || ch === "[") {
3458
+ stack.push({ line: i, bracket: ch });
3459
+ } else if (ch === "}" || ch === "]") {
3460
+ const open = stack.pop();
3461
+ if (open && open.line < i) {
3462
+ regions.push({
3463
+ start: open.line,
3464
+ end: i,
3465
+ closeBracket: ch
3466
+ });
3467
+ }
3468
+ }
3469
+ }
3470
+ }
3471
+ return regions.sort((a, b) => a.start - b.start);
3472
+ }
3473
+ var LINE_PROPS_FN = (n) => ({ "data-line": String(n - 1) });
3474
+ var HIDDEN_LINE_NUMBERS = { display: "none" };
3475
+ var CodeBlock = React114__namespace.default.memo(
3352
3476
  ({
3353
3477
  code: rawCode,
3354
3478
  language = "text",
3355
3479
  showCopyButton = true,
3356
3480
  showLanguageBadge = true,
3357
3481
  maxHeight = "60vh",
3482
+ foldable: foldableProp,
3358
3483
  className
3359
3484
  }) => {
3360
3485
  const code = typeof rawCode === "string" ? rawCode : String(rawCode ?? "");
@@ -3362,20 +3487,126 @@ var CodeBlock = React113__namespace.default.memo(
3362
3487
  const activeStyle = isOrb ? orbStyle : dark__default.default;
3363
3488
  const eventBus = useEventBus();
3364
3489
  const { t: _t } = useTranslate();
3365
- const scrollRef = React113.useRef(null);
3366
- const savedScrollLeftRef = React113.useRef(0);
3367
- const [copied, setCopied] = React113.useState(false);
3368
- React113.useLayoutEffect(() => {
3490
+ const scrollRef = React114.useRef(null);
3491
+ const codeRef = React114.useRef(null);
3492
+ const savedScrollLeftRef = React114.useRef(0);
3493
+ const [copied, setCopied] = React114.useState(false);
3494
+ const isFoldable = foldableProp ?? (language === "orb" || language === "json");
3495
+ const [collapsed, setCollapsed] = React114.useState(() => /* @__PURE__ */ new Set());
3496
+ const foldRegions = React114.useMemo(
3497
+ () => isFoldable ? computeFoldRegions(code) : [],
3498
+ [code, isFoldable]
3499
+ );
3500
+ const foldStartMap = React114.useMemo(() => {
3501
+ const m = /* @__PURE__ */ new Map();
3502
+ for (const r of foldRegions) m.set(r.start, r);
3503
+ return m;
3504
+ }, [foldRegions]);
3505
+ const hiddenLines = React114.useMemo(() => {
3506
+ const h = /* @__PURE__ */ new Set();
3507
+ for (const r of foldRegions) {
3508
+ if (!collapsed.has(r.start)) continue;
3509
+ for (let i = r.start + 1; i <= r.end; i++) h.add(i);
3510
+ }
3511
+ return h;
3512
+ }, [foldRegions, collapsed]);
3513
+ const collapsedRef = React114.useRef(collapsed);
3514
+ collapsedRef.current = collapsed;
3515
+ const foldStartMapRef = React114.useRef(foldStartMap);
3516
+ foldStartMapRef.current = foldStartMap;
3517
+ const toggleFold = React114.useCallback((lineNum) => {
3518
+ setCollapsed((prev) => {
3519
+ const next = new Set(prev);
3520
+ if (next.has(lineNum)) next.delete(lineNum);
3521
+ else next.add(lineNum);
3522
+ return next;
3523
+ });
3524
+ }, []);
3525
+ const toggleFoldRef = React114.useRef(toggleFold);
3526
+ toggleFoldRef.current = toggleFold;
3527
+ React114.useEffect(() => {
3528
+ setCollapsed(/* @__PURE__ */ new Set());
3529
+ }, [code]);
3530
+ const highlightedElement = React114.useMemo(
3531
+ () => /* @__PURE__ */ jsxRuntime.jsx(
3532
+ SyntaxHighlighter__default.default,
3533
+ {
3534
+ PreTag: "div",
3535
+ language,
3536
+ style: activeStyle,
3537
+ wrapLines: true,
3538
+ showLineNumbers: true,
3539
+ showInlineLineNumbers: false,
3540
+ lineNumberContainerStyle: HIDDEN_LINE_NUMBERS,
3541
+ lineProps: LINE_PROPS_FN,
3542
+ customStyle: {
3543
+ backgroundColor: "transparent",
3544
+ borderRadius: 0,
3545
+ padding: 0,
3546
+ margin: 0,
3547
+ whiteSpace: "pre",
3548
+ minWidth: "100%"
3549
+ },
3550
+ children: code
3551
+ }
3552
+ ),
3553
+ [code, language, activeStyle]
3554
+ );
3555
+ React114.useLayoutEffect(() => {
3556
+ const container = codeRef.current;
3557
+ if (!container) return;
3558
+ container.querySelectorAll(".fold-toggle, .fold-summary").forEach((el) => el.remove());
3559
+ const lineEls = container.querySelectorAll("[data-line]");
3560
+ if (!isFoldable || foldRegions.length === 0) {
3561
+ lineEls.forEach((el) => {
3562
+ el.style.display = "";
3563
+ el.style.position = "";
3564
+ el.style.paddingLeft = "";
3565
+ });
3566
+ return;
3567
+ }
3568
+ lineEls.forEach((el) => {
3569
+ const num = parseInt(el.getAttribute("data-line") ?? "-1", 10);
3570
+ if (hiddenLines.has(num)) {
3571
+ el.style.display = "none";
3572
+ return;
3573
+ }
3574
+ el.style.display = "";
3575
+ el.style.position = "relative";
3576
+ el.style.paddingLeft = "1.2em";
3577
+ const region = foldStartMap.get(num);
3578
+ if (!region) return;
3579
+ const isCollapsed = collapsed.has(num);
3580
+ const toggle = document.createElement("span");
3581
+ toggle.className = "fold-toggle";
3582
+ toggle.textContent = isCollapsed ? "\u25B6" : "\u25BC";
3583
+ toggle.style.cssText = "position:absolute;left:0;top:0;width:1.2em;text-align:center;cursor:pointer;color:#858585;font-size:10px;user-select:none;line-height:inherit;height:100%";
3584
+ toggle.addEventListener("click", (e) => {
3585
+ e.stopPropagation();
3586
+ toggleFoldRef.current(num);
3587
+ });
3588
+ el.insertBefore(toggle, el.firstChild);
3589
+ if (isCollapsed) {
3590
+ const summary = document.createElement("span");
3591
+ summary.className = "fold-summary";
3592
+ summary.style.cssText = "color:#858585;font-style:italic";
3593
+ const count = region.end - region.start - 1;
3594
+ summary.textContent = ` ... ${count} line${count !== 1 ? "s" : ""} ${region.closeBracket}`;
3595
+ el.appendChild(summary);
3596
+ }
3597
+ });
3598
+ }, [collapsed, hiddenLines, foldStartMap, foldRegions, isFoldable]);
3599
+ React114.useLayoutEffect(() => {
3369
3600
  const el = scrollRef.current;
3370
3601
  return () => {
3371
3602
  if (el) savedScrollLeftRef.current = el.scrollLeft;
3372
3603
  };
3373
3604
  }, [language, code]);
3374
- React113.useLayoutEffect(() => {
3605
+ React114.useLayoutEffect(() => {
3375
3606
  const el = scrollRef.current;
3376
3607
  if (el) el.scrollLeft = savedScrollLeftRef.current;
3377
3608
  }, [language, code]);
3378
- React113.useEffect(() => {
3609
+ React114.useEffect(() => {
3379
3610
  const el = scrollRef.current;
3380
3611
  if (!el) return;
3381
3612
  const handle = () => {
@@ -3395,13 +3626,14 @@ var CodeBlock = React113__namespace.default.memo(
3395
3626
  eventBus.emit("UI:COPY_CODE", { language, success: false });
3396
3627
  }
3397
3628
  };
3629
+ const hasHeader = showLanguageBadge || showCopyButton;
3398
3630
  return /* @__PURE__ */ jsxRuntime.jsxs(Box, { className: `relative group ${className || ""}`, children: [
3399
- (showLanguageBadge || showCopyButton) && /* @__PURE__ */ jsxRuntime.jsxs(
3631
+ hasHeader && /* @__PURE__ */ jsxRuntime.jsxs(
3400
3632
  HStack,
3401
3633
  {
3402
3634
  justify: "between",
3403
3635
  align: "center",
3404
- className: "px-3 py-2 bg-gray-800 rounded-t-lg border-b border-gray-700",
3636
+ className: "px-3 py-2 bg-[var(--color-card)] rounded-t-lg border-b border-gray-700",
3405
3637
  children: [
3406
3638
  showLanguageBadge && /* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: "default", size: "sm", children: language }),
3407
3639
  showCopyButton && /* @__PURE__ */ jsxRuntime.jsx(
@@ -3431,48 +3663,31 @@ var CodeBlock = React113__namespace.default.memo(
3431
3663
  touchAction: "pan-x pan-y",
3432
3664
  contain: "paint",
3433
3665
  backgroundColor: "#1e1e1e",
3434
- borderRadius: showLanguageBadge || showCopyButton ? "0 0 0.5rem 0.5rem" : "0.5rem",
3435
- padding: "1rem"
3666
+ borderRadius: hasHeader ? "0 0 0.5rem 0.5rem" : "0.5rem"
3436
3667
  },
3437
- children: /* @__PURE__ */ jsxRuntime.jsx(
3438
- SyntaxHighlighter__default.default,
3439
- {
3440
- PreTag: "div",
3441
- language,
3442
- style: activeStyle,
3443
- customStyle: {
3444
- backgroundColor: "transparent",
3445
- borderRadius: 0,
3446
- padding: 0,
3447
- margin: 0,
3448
- whiteSpace: "pre",
3449
- minWidth: "100%"
3450
- },
3451
- children: code
3452
- }
3453
- )
3668
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: codeRef, style: { padding: "1rem" }, children: highlightedElement })
3454
3669
  }
3455
3670
  )
3456
3671
  ] });
3457
3672
  },
3458
- (prev, next) => prev.language === next.language && prev.code === next.code && prev.showCopyButton === next.showCopyButton && prev.maxHeight === next.maxHeight
3673
+ (prev, next) => prev.language === next.language && prev.code === next.code && prev.showCopyButton === next.showCopyButton && prev.maxHeight === next.maxHeight && prev.foldable === next.foldable
3459
3674
  );
3460
3675
  CodeBlock.displayName = "CodeBlock";
3461
3676
 
3462
3677
  // lib/debug.ts
3463
3678
  typeof window !== "undefined" && (localStorage.getItem("debug") === "true" || process.env.NODE_ENV === "development");
3464
- React113.lazy(() => import('react-markdown'));
3465
- var GameAudioContext = React113.createContext(null);
3679
+ React114.lazy(() => import('react-markdown'));
3680
+ var GameAudioContext = React114.createContext(null);
3466
3681
  GameAudioContext.displayName = "GameAudioContext";
3467
3682
 
3468
3683
  // components/organisms/component-registry.generated.ts
3469
3684
  function lazyThree(name, loader) {
3470
- const Lazy = React113__namespace.default.lazy(() => loader().then((m) => ({ default: m[name] })));
3685
+ const Lazy = React114__namespace.default.lazy(() => loader().then((m) => ({ default: m[name] })));
3471
3686
  function ThreeWrapper(props) {
3472
- return React113__namespace.default.createElement(
3473
- React113__namespace.default.Suspense,
3687
+ return React114__namespace.default.createElement(
3688
+ React114__namespace.default.Suspense,
3474
3689
  { fallback: null },
3475
- React113__namespace.default.createElement(Lazy, props)
3690
+ React114__namespace.default.createElement(Lazy, props)
3476
3691
  );
3477
3692
  }
3478
3693
  ThreeWrapper.displayName = `Lazy(${name})`;
@@ -3493,13 +3708,13 @@ lazyThree("PhysicsObject3D", () => import('@almadar/ui/components/organisms/game
3493
3708
  lazyThree("Scene3D", () => import('@almadar/ui/components/organisms/game/three'));
3494
3709
  lazyThree("TileRenderer", () => import('@almadar/ui/components/organisms/game/three'));
3495
3710
  lazyThree("UnitRenderer", () => import('@almadar/ui/components/organisms/game/three'));
3496
- var SuspenseConfigContext = React113.createContext({ enabled: false });
3497
- React113.createContext(false);
3711
+ var SuspenseConfigContext = React114.createContext({ enabled: false });
3712
+ React114.createContext(false);
3498
3713
  function SuspenseConfigProvider({
3499
3714
  config,
3500
3715
  children
3501
3716
  }) {
3502
- return React113__namespace.default.createElement(
3717
+ return React114__namespace.default.createElement(
3503
3718
  SuspenseConfigContext.Provider,
3504
3719
  { value: config },
3505
3720
  children
@@ -3544,8 +3759,8 @@ function VerificationProvider({
3544
3759
  }) {
3545
3760
  const isEnabled = enabled ?? (typeof process !== "undefined" && process.env?.NODE_ENV !== "production");
3546
3761
  const eventBus = useEventBus();
3547
- const pendingRef = React113.useRef(/* @__PURE__ */ new Map());
3548
- React113.useEffect(() => {
3762
+ const pendingRef = React114.useRef(/* @__PURE__ */ new Map());
3763
+ React114.useEffect(() => {
3549
3764
  if (!isEnabled) return;
3550
3765
  if (!eventBus.onAny) return;
3551
3766
  const unsub = eventBus.onAny((evt) => {
@@ -3641,7 +3856,7 @@ function VerificationProvider({
3641
3856
  );
3642
3857
  return unsub;
3643
3858
  }, [isEnabled, eventBus]);
3644
- React113.useEffect(() => {
3859
+ React114.useEffect(() => {
3645
3860
  if (!isEnabled) return;
3646
3861
  if (!runtimeManager) return;
3647
3862
  runtimeManager.setObserver({
@@ -3663,11 +3878,11 @@ function VerificationProvider({
3663
3878
  "pass"
3664
3879
  );
3665
3880
  }, [isEnabled, runtimeManager]);
3666
- React113.useEffect(() => {
3881
+ React114.useEffect(() => {
3667
3882
  if (!isEnabled) return;
3668
3883
  bindEventBus(eventBus);
3669
3884
  }, [isEnabled, eventBus]);
3670
- React113.useEffect(() => {
3885
+ React114.useEffect(() => {
3671
3886
  if (!isEnabled) return;
3672
3887
  if (traitStateGetter) {
3673
3888
  bindTraitStateGetter(traitStateGetter);
@@ -3691,7 +3906,7 @@ function OrbitalProvider({
3691
3906
  suspense = false,
3692
3907
  verification
3693
3908
  }) {
3694
- const suspenseConfig = React113.useMemo(
3909
+ const suspenseConfig = React114.useMemo(
3695
3910
  () => ({ enabled: suspense }),
3696
3911
  [suspense]
3697
3912
  );
@@ -3711,43 +3926,43 @@ function OrbitalProvider({
3711
3926
  );
3712
3927
  }
3713
3928
  OrbitalProvider.displayName = "OrbitalProvider";
3714
- var FetchedDataContext = React113.createContext(null);
3929
+ var FetchedDataContext = React114.createContext(null);
3715
3930
  function FetchedDataProvider({
3716
3931
  initialData,
3717
3932
  children
3718
3933
  }) {
3719
- const [state, setState] = React113.useState(() => ({
3934
+ const [state, setState] = React114.useState(() => ({
3720
3935
  data: initialData || {},
3721
3936
  fetchedAt: {},
3722
3937
  loading: false,
3723
3938
  error: null
3724
3939
  }));
3725
- const getData = React113.useCallback(
3940
+ const getData = React114.useCallback(
3726
3941
  (entityName) => {
3727
3942
  return state.data[entityName] || [];
3728
3943
  },
3729
3944
  [state.data]
3730
3945
  );
3731
- const getById = React113.useCallback(
3946
+ const getById2 = React114.useCallback(
3732
3947
  (entityName, id) => {
3733
3948
  const records = state.data[entityName];
3734
3949
  return records?.find((r) => r.id === id);
3735
3950
  },
3736
3951
  [state.data]
3737
3952
  );
3738
- const hasData = React113.useCallback(
3953
+ const hasData = React114.useCallback(
3739
3954
  (entityName) => {
3740
3955
  return entityName in state.data && state.data[entityName].length > 0;
3741
3956
  },
3742
3957
  [state.data]
3743
3958
  );
3744
- const getFetchedAt = React113.useCallback(
3959
+ const getFetchedAt = React114.useCallback(
3745
3960
  (entityName) => {
3746
3961
  return state.fetchedAt[entityName];
3747
3962
  },
3748
3963
  [state.fetchedAt]
3749
3964
  );
3750
- const setData = React113.useCallback((data) => {
3965
+ const setData = React114.useCallback((data) => {
3751
3966
  const now = Date.now();
3752
3967
  setState((prev) => ({
3753
3968
  ...prev,
@@ -3766,14 +3981,14 @@ function FetchedDataProvider({
3766
3981
  error: null
3767
3982
  }));
3768
3983
  }, []);
3769
- const clearData = React113.useCallback(() => {
3984
+ const clearData = React114.useCallback(() => {
3770
3985
  setState((prev) => ({
3771
3986
  ...prev,
3772
3987
  data: {},
3773
3988
  fetchedAt: {}
3774
3989
  }));
3775
3990
  }, []);
3776
- const clearEntity = React113.useCallback((entityName) => {
3991
+ const clearEntity = React114.useCallback((entityName) => {
3777
3992
  setState((prev) => {
3778
3993
  const newData = { ...prev.data };
3779
3994
  const newFetchedAt = { ...prev.fetchedAt };
@@ -3786,16 +4001,16 @@ function FetchedDataProvider({
3786
4001
  };
3787
4002
  });
3788
4003
  }, []);
3789
- const setLoading = React113.useCallback((loading) => {
4004
+ const setLoading = React114.useCallback((loading) => {
3790
4005
  setState((prev) => ({ ...prev, loading }));
3791
4006
  }, []);
3792
- const setError = React113.useCallback((error) => {
4007
+ const setError = React114.useCallback((error) => {
3793
4008
  setState((prev) => ({ ...prev, error, loading: false }));
3794
4009
  }, []);
3795
- const contextValue = React113.useMemo(
4010
+ const contextValue2 = React114.useMemo(
3796
4011
  () => ({
3797
4012
  getData,
3798
- getById,
4013
+ getById: getById2,
3799
4014
  hasData,
3800
4015
  getFetchedAt,
3801
4016
  setData,
@@ -3808,7 +4023,7 @@ function FetchedDataProvider({
3808
4023
  }),
3809
4024
  [
3810
4025
  getData,
3811
- getById,
4026
+ getById2,
3812
4027
  hasData,
3813
4028
  getFetchedAt,
3814
4029
  setData,
@@ -3820,13 +4035,13 @@ function FetchedDataProvider({
3820
4035
  setError
3821
4036
  ]
3822
4037
  );
3823
- return /* @__PURE__ */ jsxRuntime.jsx(FetchedDataContext.Provider, { value: contextValue, children });
4038
+ return /* @__PURE__ */ jsxRuntime.jsx(FetchedDataContext.Provider, { value: contextValue2, children });
3824
4039
  }
3825
4040
  function useFetchedDataContext() {
3826
- return React113.useContext(FetchedDataContext);
4041
+ return React114.useContext(FetchedDataContext);
3827
4042
  }
3828
4043
  function useFetchedData() {
3829
- const context = React113.useContext(FetchedDataContext);
4044
+ const context = React114.useContext(FetchedDataContext);
3830
4045
  if (!context) {
3831
4046
  return {
3832
4047
  getData: () => [],
@@ -3866,15 +4081,15 @@ function useFetchedEntity(entityName) {
3866
4081
  error: context.error
3867
4082
  };
3868
4083
  }
3869
- var OfflineModeContext = React113.createContext(null);
4084
+ var OfflineModeContext = React114.createContext(null);
3870
4085
  function OfflineModeProvider({
3871
4086
  children,
3872
4087
  ...executorOptions
3873
4088
  }) {
3874
- const [forceOffline, setForceOffline] = React113.useState(false);
4089
+ const [forceOffline, setForceOffline] = React114.useState(false);
3875
4090
  const executor = useOfflineExecutor(executorOptions);
3876
4091
  const effectivelyOffline = executor.isOffline || forceOffline;
3877
- const contextValue = React113.useMemo(
4092
+ const contextValue2 = React114.useMemo(
3878
4093
  () => ({
3879
4094
  ...executor,
3880
4095
  forceOffline,
@@ -3883,17 +4098,17 @@ function OfflineModeProvider({
3883
4098
  }),
3884
4099
  [executor, forceOffline, effectivelyOffline]
3885
4100
  );
3886
- return /* @__PURE__ */ jsxRuntime.jsx(OfflineModeContext.Provider, { value: contextValue, children });
4101
+ return /* @__PURE__ */ jsxRuntime.jsx(OfflineModeContext.Provider, { value: contextValue2, children });
3887
4102
  }
3888
4103
  function useOfflineMode() {
3889
- const context = React113.useContext(OfflineModeContext);
4104
+ const context = React114.useContext(OfflineModeContext);
3890
4105
  if (!context) {
3891
4106
  throw new Error("useOfflineMode must be used within OfflineModeProvider");
3892
4107
  }
3893
4108
  return context;
3894
4109
  }
3895
4110
  function useOptionalOfflineMode() {
3896
- return React113.useContext(OfflineModeContext);
4111
+ return React114.useContext(OfflineModeContext);
3897
4112
  }
3898
4113
 
3899
4114
  exports.EntityStoreContext = EntityStoreContext;
@@ -3907,6 +4122,7 @@ exports.OrbitalProvider = OrbitalProvider;
3907
4122
  exports.SelectionContext = SelectionContext;
3908
4123
  exports.SelectionProvider = SelectionProvider;
3909
4124
  exports.VerificationProvider = VerificationProvider;
4125
+ exports.useEntityById = useEntityById;
3910
4126
  exports.useEntityRef = useEntityRef;
3911
4127
  exports.useEntityStore = useEntityStore;
3912
4128
  exports.useEntityWatch = useEntityWatch;