@almadar/ui 4.0.1 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17266,6 +17266,16 @@ function statusVariant2(value) {
17266
17266
  if (["new", "created", "scheduled", "queued", "info"].includes(v)) return "info";
17267
17267
  return "default";
17268
17268
  }
17269
+ function resolveBadgeVariant(field, value) {
17270
+ const fromMap = field.colorMap?.[value];
17271
+ if (fromMap) {
17272
+ const normalised = fromMap === "destructive" ? "danger" : fromMap;
17273
+ if (BADGE_VARIANTS.has(normalised)) {
17274
+ return normalised;
17275
+ }
17276
+ }
17277
+ return statusVariant2(value);
17278
+ }
17269
17279
  function formatDate2(value) {
17270
17280
  if (!value) return "";
17271
17281
  const d = new Date(String(value));
@@ -17479,7 +17489,7 @@ function DataGrid({
17479
17489
  if (val === void 0 || val === null) return null;
17480
17490
  return /* @__PURE__ */ jsxRuntime.jsxs(exports.HStack, { gap: "xs", className: "items-center", children: [
17481
17491
  field.icon && /* @__PURE__ */ jsxRuntime.jsx(exports.Icon, { name: field.icon, size: "xs" }),
17482
- /* @__PURE__ */ jsxRuntime.jsx(exports.Badge, { variant: statusVariant2(String(val)), children: String(val) })
17492
+ /* @__PURE__ */ jsxRuntime.jsx(exports.Badge, { variant: resolveBadgeVariant(field, String(val)), children: String(val) })
17483
17493
  ] }, field.name);
17484
17494
  }) })
17485
17495
  ] }),
@@ -17572,7 +17582,7 @@ function DataGrid({
17572
17582
  )
17573
17583
  ] });
17574
17584
  }
17575
- var gapStyles6;
17585
+ var BADGE_VARIANTS, gapStyles6;
17576
17586
  var init_DataGrid = __esm({
17577
17587
  "components/molecules/DataGrid.tsx"() {
17578
17588
  "use client";
@@ -17587,6 +17597,17 @@ var init_DataGrid = __esm({
17587
17597
  init_Button();
17588
17598
  init_Icon();
17589
17599
  init_InfiniteScrollSentinel();
17600
+ BADGE_VARIANTS = /* @__PURE__ */ new Set([
17601
+ "default",
17602
+ "primary",
17603
+ "secondary",
17604
+ "success",
17605
+ "warning",
17606
+ "danger",
17607
+ "error",
17608
+ "info",
17609
+ "neutral"
17610
+ ]);
17590
17611
  gapStyles6 = {
17591
17612
  none: "gap-0",
17592
17613
  sm: "gap-2",
@@ -40645,30 +40666,76 @@ function useDeepAgentGeneration() {
40645
40666
 
40646
40667
  // hooks/index.ts
40647
40668
  init_useEventBus();
40648
- var DEFAULT_SLOTS = {
40649
- main: null,
40650
- sidebar: null,
40651
- modal: null,
40652
- drawer: null,
40653
- overlay: null,
40654
- center: null,
40655
- toast: null,
40656
- "hud-top": null,
40657
- "hud-bottom": null,
40658
- "hud-left": null,
40659
- "hud-right": null,
40660
- floating: null
40661
- };
40669
+ var DEFAULT_SOURCE_KEY = "__default__";
40670
+ var MULTI_SOURCE_STACK_TRAIT = "__multi_source_stack__";
40671
+ var ALL_SLOTS2 = [
40672
+ "main",
40673
+ "sidebar",
40674
+ "modal",
40675
+ "drawer",
40676
+ "overlay",
40677
+ "center",
40678
+ "toast",
40679
+ "hud-top",
40680
+ "hud-bottom",
40681
+ "hud-left",
40682
+ "hud-right",
40683
+ "floating"
40684
+ ];
40685
+ var DEFAULT_SLOTS = ALL_SLOTS2.reduce(
40686
+ (acc, slot) => {
40687
+ acc[slot] = null;
40688
+ return acc;
40689
+ },
40690
+ {}
40691
+ );
40692
+ var DEFAULT_SOURCES = ALL_SLOTS2.reduce(
40693
+ (acc, slot) => {
40694
+ acc[slot] = {};
40695
+ return acc;
40696
+ },
40697
+ {}
40698
+ );
40662
40699
  var idCounter = 0;
40663
40700
  function generateId() {
40664
40701
  return `slot-content-${++idCounter}-${Date.now()}`;
40665
40702
  }
40703
+ function aggregateSlot(sources) {
40704
+ if (!sources) return null;
40705
+ const entries = Object.entries(sources);
40706
+ if (entries.length === 0) return null;
40707
+ if (entries.length === 1) return entries[0][1];
40708
+ const children = entries.map(([, entry]) => ({
40709
+ type: entry.pattern,
40710
+ ...entry.props
40711
+ }));
40712
+ const stackId = `slot-content-stack-${entries.map(([k]) => k).join("-")}`;
40713
+ return {
40714
+ id: stackId,
40715
+ pattern: "stack",
40716
+ props: {
40717
+ direction: "vertical",
40718
+ gap: "lg",
40719
+ children
40720
+ },
40721
+ priority: 0,
40722
+ animation: "fade",
40723
+ sourceTrait: MULTI_SOURCE_STACK_TRAIT
40724
+ };
40725
+ }
40666
40726
  function useUISlotManager() {
40667
- const [slots, setSlots] = React110.useState(DEFAULT_SLOTS);
40727
+ const [sources, setSources] = React110.useState(DEFAULT_SOURCES);
40668
40728
  const subscribersRef = React110.useRef(/* @__PURE__ */ new Set());
40669
40729
  const timersRef = React110.useRef(/* @__PURE__ */ new Map());
40670
40730
  const traitIndexRef = React110.useRef(/* @__PURE__ */ new Map());
40671
40731
  const traitSubscribersRef = React110.useRef(/* @__PURE__ */ new Map());
40732
+ const slots = React110.useMemo(() => {
40733
+ const out = { ...DEFAULT_SLOTS };
40734
+ for (const slot of ALL_SLOTS2) {
40735
+ out[slot] = aggregateSlot(sources[slot]);
40736
+ }
40737
+ return out;
40738
+ }, [sources]);
40672
40739
  React110.useEffect(() => {
40673
40740
  return () => {
40674
40741
  timersRef.current.forEach((timer) => clearTimeout(timer));
@@ -40707,103 +40774,160 @@ function useUISlotManager() {
40707
40774
  const unindexTrait = React110.useCallback((traitName) => {
40708
40775
  traitIndexRef.current.delete(traitName);
40709
40776
  }, []);
40710
- const render = React110.useCallback((config) => {
40711
- const id = generateId();
40712
- const content = {
40713
- id,
40714
- pattern: config.pattern,
40715
- props: config.props ?? {},
40716
- priority: config.priority ?? 0,
40717
- animation: config.animation ?? "fade",
40718
- onDismiss: config.onDismiss,
40719
- sourceTrait: config.sourceTrait
40720
- };
40721
- if (config.autoDismissMs && config.autoDismissMs > 0) {
40722
- content.autoDismissAt = Date.now() + config.autoDismissMs;
40723
- const timer = setTimeout(() => {
40724
- setSlots((prev) => {
40725
- if (prev[config.target]?.id === id) {
40726
- content.onDismiss?.();
40727
- notifySubscribers(config.target, null);
40728
- return { ...prev, [config.target]: null };
40729
- }
40777
+ const render = React110.useCallback(
40778
+ (config) => {
40779
+ const id = generateId();
40780
+ const sourceKey = config.sourceTrait ?? DEFAULT_SOURCE_KEY;
40781
+ const content = {
40782
+ id,
40783
+ pattern: config.pattern,
40784
+ props: config.props ?? {},
40785
+ priority: config.priority ?? 0,
40786
+ animation: config.animation ?? "fade",
40787
+ onDismiss: config.onDismiss,
40788
+ sourceTrait: config.sourceTrait
40789
+ };
40790
+ if (config.autoDismissMs && config.autoDismissMs > 0) {
40791
+ content.autoDismissAt = Date.now() + config.autoDismissMs;
40792
+ const timer = setTimeout(() => {
40793
+ setSources((prev) => {
40794
+ const slotSources = prev[config.target];
40795
+ if (slotSources && slotSources[sourceKey]?.id === id) {
40796
+ content.onDismiss?.();
40797
+ const next = { ...slotSources };
40798
+ delete next[sourceKey];
40799
+ const updated = { ...prev, [config.target]: next };
40800
+ notifySubscribers(config.target, aggregateSlot(next));
40801
+ return updated;
40802
+ }
40803
+ return prev;
40804
+ });
40805
+ timersRef.current.delete(id);
40806
+ }, config.autoDismissMs);
40807
+ timersRef.current.set(id, timer);
40808
+ }
40809
+ setSources((prev) => {
40810
+ const slotSources = prev[config.target] ?? {};
40811
+ const existing = slotSources[sourceKey];
40812
+ if (existing && existing.priority > content.priority) {
40813
+ console.warn(
40814
+ `[UISlots] Slot "${config.target}" source "${sourceKey}" already has higher priority content (${existing.priority} > ${content.priority})`
40815
+ );
40730
40816
  return prev;
40731
- });
40732
- timersRef.current.delete(id);
40733
- }, config.autoDismissMs);
40734
- timersRef.current.set(id, timer);
40735
- }
40736
- setSlots((prev) => {
40737
- const existing = prev[config.target];
40738
- if (existing && existing.priority > content.priority) {
40739
- console.warn(
40740
- `[UISlots] Slot "${config.target}" already has higher priority content (${existing.priority} > ${content.priority})`
40741
- );
40742
- return prev;
40743
- }
40744
- if (content.sourceTrait) {
40745
- indexTraitRender(content.sourceTrait, content);
40746
- notifyTraitSubscribers(content.sourceTrait, content);
40747
- }
40748
- notifySubscribers(config.target, content);
40749
- return { ...prev, [config.target]: content };
40750
- });
40751
- return id;
40752
- }, [notifySubscribers, notifyTraitSubscribers, indexTraitRender]);
40753
- const clear = React110.useCallback((slot) => {
40754
- setSlots((prev) => {
40755
- const content = prev[slot];
40756
- if (content) {
40757
- const timer = timersRef.current.get(content.id);
40758
- if (timer) {
40759
- clearTimeout(timer);
40760
- timersRef.current.delete(content.id);
40761
40817
  }
40762
- content.onDismiss?.();
40818
+ const nextSources = {
40819
+ ...slotSources,
40820
+ [sourceKey]: content
40821
+ };
40822
+ const nextAll = { ...prev, [config.target]: nextSources };
40763
40823
  if (content.sourceTrait) {
40764
- unindexTrait(content.sourceTrait);
40765
- notifyTraitSubscribers(content.sourceTrait, null);
40824
+ indexTraitRender(content.sourceTrait, content);
40825
+ notifyTraitSubscribers(content.sourceTrait, content);
40826
+ }
40827
+ notifySubscribers(config.target, aggregateSlot(nextSources));
40828
+ return nextAll;
40829
+ });
40830
+ return id;
40831
+ },
40832
+ [notifySubscribers, notifyTraitSubscribers, indexTraitRender]
40833
+ );
40834
+ const clear = React110.useCallback(
40835
+ (slot) => {
40836
+ setSources((prev) => {
40837
+ const slotSources = prev[slot];
40838
+ if (!slotSources || Object.keys(slotSources).length === 0) {
40839
+ return prev;
40840
+ }
40841
+ for (const content of Object.values(slotSources)) {
40842
+ const timer = timersRef.current.get(content.id);
40843
+ if (timer) {
40844
+ clearTimeout(timer);
40845
+ timersRef.current.delete(content.id);
40846
+ }
40847
+ content.onDismiss?.();
40848
+ if (content.sourceTrait) {
40849
+ unindexTrait(content.sourceTrait);
40850
+ notifyTraitSubscribers(content.sourceTrait, null);
40851
+ }
40766
40852
  }
40767
40853
  notifySubscribers(slot, null);
40768
- }
40769
- return { ...prev, [slot]: null };
40770
- });
40771
- }, [notifySubscribers, notifyTraitSubscribers, unindexTrait]);
40772
- const clearById = React110.useCallback((id) => {
40773
- setSlots((prev) => {
40774
- const entry = Object.entries(prev).find(([, content]) => content?.id === id);
40775
- if (entry) {
40776
- const [slot, content] = entry;
40777
- const timer = timersRef.current.get(id);
40854
+ return { ...prev, [slot]: {} };
40855
+ });
40856
+ },
40857
+ [notifySubscribers, notifyTraitSubscribers, unindexTrait]
40858
+ );
40859
+ const clearBySource = React110.useCallback(
40860
+ (slot, sourceTrait) => {
40861
+ const sourceKey = sourceTrait;
40862
+ setSources((prev) => {
40863
+ const slotSources = prev[slot];
40864
+ if (!slotSources || !(sourceKey in slotSources)) return prev;
40865
+ const content = slotSources[sourceKey];
40866
+ const timer = timersRef.current.get(content.id);
40778
40867
  if (timer) {
40779
40868
  clearTimeout(timer);
40780
- timersRef.current.delete(id);
40869
+ timersRef.current.delete(content.id);
40781
40870
  }
40782
40871
  content.onDismiss?.();
40783
40872
  if (content.sourceTrait) {
40784
40873
  unindexTrait(content.sourceTrait);
40785
40874
  notifyTraitSubscribers(content.sourceTrait, null);
40786
40875
  }
40787
- notifySubscribers(slot, null);
40788
- return { ...prev, [slot]: null };
40789
- }
40790
- return prev;
40791
- });
40792
- }, [notifySubscribers, notifyTraitSubscribers, unindexTrait]);
40876
+ const nextSources = { ...slotSources };
40877
+ delete nextSources[sourceKey];
40878
+ notifySubscribers(slot, aggregateSlot(nextSources));
40879
+ return { ...prev, [slot]: nextSources };
40880
+ });
40881
+ },
40882
+ [notifySubscribers, notifyTraitSubscribers, unindexTrait]
40883
+ );
40884
+ const clearById = React110.useCallback(
40885
+ (id) => {
40886
+ setSources((prev) => {
40887
+ for (const slot of ALL_SLOTS2) {
40888
+ const slotSources = prev[slot];
40889
+ if (!slotSources) continue;
40890
+ const matchKey = Object.keys(slotSources).find(
40891
+ (k) => slotSources[k].id === id
40892
+ );
40893
+ if (!matchKey) continue;
40894
+ const content = slotSources[matchKey];
40895
+ const timer = timersRef.current.get(id);
40896
+ if (timer) {
40897
+ clearTimeout(timer);
40898
+ timersRef.current.delete(id);
40899
+ }
40900
+ content.onDismiss?.();
40901
+ if (content.sourceTrait) {
40902
+ unindexTrait(content.sourceTrait);
40903
+ notifyTraitSubscribers(content.sourceTrait, null);
40904
+ }
40905
+ const nextSources = { ...slotSources };
40906
+ delete nextSources[matchKey];
40907
+ notifySubscribers(slot, aggregateSlot(nextSources));
40908
+ return { ...prev, [slot]: nextSources };
40909
+ }
40910
+ return prev;
40911
+ });
40912
+ },
40913
+ [notifySubscribers, notifyTraitSubscribers, unindexTrait]
40914
+ );
40793
40915
  const clearAll = React110.useCallback(() => {
40794
40916
  timersRef.current.forEach((timer) => clearTimeout(timer));
40795
40917
  timersRef.current.clear();
40796
- setSlots((prev) => {
40797
- Object.entries(prev).forEach(([slot, content]) => {
40798
- if (content) {
40918
+ setSources((prev) => {
40919
+ for (const slot of ALL_SLOTS2) {
40920
+ const slotSources = prev[slot];
40921
+ if (!slotSources) continue;
40922
+ for (const content of Object.values(slotSources)) {
40799
40923
  content.onDismiss?.();
40800
40924
  if (content.sourceTrait) {
40801
40925
  notifyTraitSubscribers(content.sourceTrait, null);
40802
40926
  }
40803
- notifySubscribers(slot, null);
40804
40927
  }
40805
- });
40806
- return DEFAULT_SLOTS;
40928
+ notifySubscribers(slot, null);
40929
+ }
40930
+ return DEFAULT_SOURCES;
40807
40931
  });
40808
40932
  traitIndexRef.current.clear();
40809
40933
  }, [notifySubscribers, notifyTraitSubscribers]);
@@ -40813,16 +40937,16 @@ function useUISlotManager() {
40813
40937
  subscribersRef.current.delete(callback);
40814
40938
  };
40815
40939
  }, []);
40816
- const hasContent = React110.useCallback((slot) => {
40817
- return slots[slot] !== null;
40818
- }, [slots]);
40819
- const getContent = React110.useCallback((slot) => {
40820
- return slots[slot];
40821
- }, [slots]);
40940
+ const hasContent = React110.useCallback(
40941
+ (slot) => slots[slot] !== null,
40942
+ [slots]
40943
+ );
40944
+ const getContent = React110.useCallback(
40945
+ (slot) => slots[slot],
40946
+ [slots]
40947
+ );
40822
40948
  const getTraitContent = React110.useCallback(
40823
- (traitName) => {
40824
- return traitIndexRef.current.get(traitName) ?? null;
40825
- },
40949
+ (traitName) => traitIndexRef.current.get(traitName) ?? null,
40826
40950
  []
40827
40951
  );
40828
40952
  const subscribeTrait = React110.useCallback(
@@ -40848,6 +40972,7 @@ function useUISlotManager() {
40848
40972
  slots,
40849
40973
  render,
40850
40974
  clear,
40975
+ clearBySource,
40851
40976
  clearById,
40852
40977
  clearAll,
40853
40978
  subscribe: subscribe2,