@almadar/ui 5.146.3 → 5.147.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.
@@ -27133,7 +27133,12 @@ function daysAgo(n) {
27133
27133
  d.setDate(d.getDate() - n);
27134
27134
  return d;
27135
27135
  }
27136
- var DEFAULT_PRESETS, DateRangePicker;
27136
+ function resolvePresetRange(preset) {
27137
+ if (typeof preset.range === "function") return preset.range();
27138
+ if (preset.range) return preset.range;
27139
+ return TOKEN_RANGES[preset.value]?.() ?? null;
27140
+ }
27141
+ var TOKEN_RANGES, DEFAULT_PRESETS, DateRangePicker;
27137
27142
  var init_DateRangePicker = __esm({
27138
27143
  "components/core/molecules/DateRangePicker.tsx"() {
27139
27144
  "use client";
@@ -27143,32 +27148,19 @@ var init_DateRangePicker = __esm({
27143
27148
  init_Stack();
27144
27149
  init_Typography();
27145
27150
  init_useEventBus();
27151
+ TOKEN_RANGES = {
27152
+ "7d": () => ({ from: toISODate(daysAgo(7)), to: toISODate(/* @__PURE__ */ new Date()) }),
27153
+ "30d": () => ({ from: toISODate(daysAgo(30)), to: toISODate(/* @__PURE__ */ new Date()) }),
27154
+ month: () => ({ from: toISODate(startOfMonth(/* @__PURE__ */ new Date())), to: toISODate(/* @__PURE__ */ new Date()) }),
27155
+ quarter: () => ({ from: toISODate(startOfQuarter(/* @__PURE__ */ new Date())), to: toISODate(/* @__PURE__ */ new Date()) }),
27156
+ ytd: () => ({ from: toISODate(startOfYear(/* @__PURE__ */ new Date())), to: toISODate(/* @__PURE__ */ new Date()) })
27157
+ };
27146
27158
  DEFAULT_PRESETS = [
27147
- {
27148
- label: "Last 7 days",
27149
- value: "7d",
27150
- range: () => ({ from: toISODate(daysAgo(7)), to: toISODate(/* @__PURE__ */ new Date()) })
27151
- },
27152
- {
27153
- label: "Last 30 days",
27154
- value: "30d",
27155
- range: () => ({ from: toISODate(daysAgo(30)), to: toISODate(/* @__PURE__ */ new Date()) })
27156
- },
27157
- {
27158
- label: "This Month",
27159
- value: "month",
27160
- range: () => ({ from: toISODate(startOfMonth(/* @__PURE__ */ new Date())), to: toISODate(/* @__PURE__ */ new Date()) })
27161
- },
27162
- {
27163
- label: "This Quarter",
27164
- value: "quarter",
27165
- range: () => ({ from: toISODate(startOfQuarter(/* @__PURE__ */ new Date())), to: toISODate(/* @__PURE__ */ new Date()) })
27166
- },
27167
- {
27168
- label: "YTD",
27169
- value: "ytd",
27170
- range: () => ({ from: toISODate(startOfYear(/* @__PURE__ */ new Date())), to: toISODate(/* @__PURE__ */ new Date()) })
27171
- }
27159
+ { label: "Last 7 days", value: "7d" },
27160
+ { label: "Last 30 days", value: "30d" },
27161
+ { label: "This Month", value: "month" },
27162
+ { label: "This Quarter", value: "quarter" },
27163
+ { label: "YTD", value: "ytd" }
27172
27164
  ];
27173
27165
  DateRangePicker = ({
27174
27166
  from: fromProp,
@@ -27209,7 +27201,8 @@ var init_DateRangePicker = __esm({
27209
27201
  );
27210
27202
  const handlePreset = useCallback(
27211
27203
  (preset) => {
27212
- const range = preset.range();
27204
+ const range = resolvePresetRange(preset);
27205
+ if (range === null) return;
27213
27206
  setFrom(range.from);
27214
27207
  setTo(range.to);
27215
27208
  setActivePreset(preset.value);
@@ -27217,8 +27210,12 @@ var init_DateRangePicker = __esm({
27217
27210
  },
27218
27211
  [emit]
27219
27212
  );
27213
+ const renderablePresets = useMemo(
27214
+ () => presets.filter((p) => p.range !== void 0 || TOKEN_RANGES[p.value] !== void 0),
27215
+ [presets]
27216
+ );
27220
27217
  const presetButtons = useMemo(
27221
- () => presets.map((preset) => /* @__PURE__ */ jsx(
27218
+ () => renderablePresets.map((preset) => /* @__PURE__ */ jsx(
27222
27219
  Button,
27223
27220
  {
27224
27221
  variant: activePreset === preset.value ? "primary" : "ghost",
@@ -27228,7 +27225,7 @@ var init_DateRangePicker = __esm({
27228
27225
  },
27229
27226
  preset.value
27230
27227
  )),
27231
- [presets, activePreset, handlePreset]
27228
+ [renderablePresets, activePreset, handlePreset]
27232
27229
  );
27233
27230
  return /* @__PURE__ */ jsxs(VStack, { gap: "sm", className: cn(className), children: [
27234
27231
  /* @__PURE__ */ jsxs(HStack, { gap: "md", align: "end", children: [
@@ -27255,7 +27252,7 @@ var init_DateRangePicker = __esm({
27255
27252
  )
27256
27253
  ] })
27257
27254
  ] }),
27258
- presets.length > 0 && /* @__PURE__ */ jsx(HStack, { gap: "xs", wrap: true, children: presetButtons })
27255
+ renderablePresets.length > 0 && /* @__PURE__ */ jsx(HStack, { gap: "xs", wrap: true, children: presetButtons })
27259
27256
  ] });
27260
27257
  };
27261
27258
  DateRangePicker.displayName = "DateRangePicker";
@@ -27697,6 +27694,208 @@ var init_PhysicsCanvas = __esm({
27697
27694
  };
27698
27695
  }
27699
27696
  });
27697
+
27698
+ // lib/graphViewLayouts.ts
27699
+ function buildAdjacency(nodeIds, edges) {
27700
+ const known = new Set(nodeIds);
27701
+ const out = /* @__PURE__ */ new Map();
27702
+ const inMap = /* @__PURE__ */ new Map();
27703
+ for (const id of nodeIds) {
27704
+ out.set(id, []);
27705
+ inMap.set(id, []);
27706
+ }
27707
+ for (const edge of edges) {
27708
+ if (!known.has(edge.source) || !known.has(edge.target)) continue;
27709
+ out.get(edge.source)?.push(edge.target);
27710
+ inMap.get(edge.target)?.push(edge.source);
27711
+ }
27712
+ return { out, in: inMap };
27713
+ }
27714
+ function findRoots(nodeIds, adjacency) {
27715
+ return nodeIds.filter((id) => (adjacency.in.get(id)?.length ?? 0) === 0);
27716
+ }
27717
+ function assignLayers(nodeIds, adjacency, roots) {
27718
+ const layer = new Map(nodeIds.map((id) => [id, 0]));
27719
+ const onStack = /* @__PURE__ */ new Set();
27720
+ const visit = (id) => {
27721
+ onStack.add(id);
27722
+ const currentLayer = layer.get(id) ?? 0;
27723
+ for (const next of adjacency.out.get(id) ?? []) {
27724
+ if (onStack.has(next)) continue;
27725
+ const candidate = currentLayer + 1;
27726
+ if (candidate > (layer.get(next) ?? 0)) {
27727
+ layer.set(next, candidate);
27728
+ }
27729
+ visit(next);
27730
+ }
27731
+ onStack.delete(id);
27732
+ };
27733
+ for (const root of roots) visit(root);
27734
+ return layer;
27735
+ }
27736
+ function computeVisitOrder(nodeIds, adjacency, roots) {
27737
+ const order = /* @__PURE__ */ new Map();
27738
+ const visited = /* @__PURE__ */ new Set();
27739
+ let counter = 0;
27740
+ const visit = (id) => {
27741
+ if (visited.has(id)) return;
27742
+ visited.add(id);
27743
+ order.set(id, counter++);
27744
+ for (const next of adjacency.out.get(id) ?? []) visit(next);
27745
+ };
27746
+ for (const root of roots) visit(root);
27747
+ for (const id of nodeIds) {
27748
+ if (!visited.has(id)) order.set(id, counter++);
27749
+ }
27750
+ return order;
27751
+ }
27752
+ function bfsDepthAndOrder(nodeIds, adjacency, roots) {
27753
+ const depth = new Map(nodeIds.map((id) => [id, 0]));
27754
+ const visitOrder = /* @__PURE__ */ new Map();
27755
+ const visited = /* @__PURE__ */ new Set();
27756
+ const queue = [];
27757
+ let counter = 0;
27758
+ for (const root of roots) {
27759
+ if (visited.has(root)) continue;
27760
+ visited.add(root);
27761
+ depth.set(root, 0);
27762
+ visitOrder.set(root, counter++);
27763
+ queue.push(root);
27764
+ }
27765
+ let head = 0;
27766
+ while (head < queue.length) {
27767
+ const id = queue[head++];
27768
+ const d = depth.get(id) ?? 0;
27769
+ for (const next of adjacency.out.get(id) ?? []) {
27770
+ if (visited.has(next)) continue;
27771
+ visited.add(next);
27772
+ depth.set(next, d + 1);
27773
+ visitOrder.set(next, counter++);
27774
+ queue.push(next);
27775
+ }
27776
+ }
27777
+ for (const id of nodeIds) {
27778
+ if (!visited.has(id)) visitOrder.set(id, counter++);
27779
+ }
27780
+ return { depth, visitOrder };
27781
+ }
27782
+ function edgeWalkOrder(nodeIds, adjacency) {
27783
+ const visited = /* @__PURE__ */ new Set();
27784
+ const result = [];
27785
+ for (const start of nodeIds) {
27786
+ if (visited.has(start)) continue;
27787
+ let current = start;
27788
+ while (current !== void 0 && !visited.has(current)) {
27789
+ visited.add(current);
27790
+ result.push(current);
27791
+ const outs = adjacency.out.get(current) ?? [];
27792
+ current = outs.find((next) => !visited.has(next));
27793
+ }
27794
+ }
27795
+ return result;
27796
+ }
27797
+ function groupByTier(nodeIds, tierOf, maxTier) {
27798
+ const groups = Array.from({ length: maxTier + 1 }, () => []);
27799
+ for (const id of nodeIds) {
27800
+ groups[tierOf.get(id) ?? 0].push(id);
27801
+ }
27802
+ return groups;
27803
+ }
27804
+ function distributeAxis(count, start, end) {
27805
+ if (count <= 0) return [];
27806
+ const slot = (end - start) / count;
27807
+ return Array.from({ length: count }, (_, i) => start + slot * (i + 0.5));
27808
+ }
27809
+ function orderByParentPositionThenInput(group, adjacency, positioned, inputIndex) {
27810
+ const withKey = group.map((id) => {
27811
+ const parentValues = (adjacency.in.get(id) ?? []).map((p) => positioned.get(p)).filter((v) => v !== void 0);
27812
+ const avg = parentValues.length > 0 ? parentValues.reduce((a, b) => a + b, 0) / parentValues.length : Number.POSITIVE_INFINITY;
27813
+ return { id, avg, idx: inputIndex.get(id) ?? 0 };
27814
+ });
27815
+ withKey.sort((a, b) => a.avg !== b.avg ? a.avg - b.avg : a.idx - b.idx);
27816
+ return withKey.map((k) => k.id);
27817
+ }
27818
+ function layoutFlow(nodeIds, adjacency, roots, width, height, margin) {
27819
+ const inputIndex = new Map(nodeIds.map((id, i) => [id, i]));
27820
+ const layers = assignLayers(nodeIds, adjacency, roots);
27821
+ const maxLayer = Math.max(...Array.from(layers.values()));
27822
+ const layerGroups = groupByTier(nodeIds, layers, maxLayer);
27823
+ const positions = /* @__PURE__ */ new Map();
27824
+ const yById = /* @__PURE__ */ new Map();
27825
+ for (let l = 0; l <= maxLayer; l++) {
27826
+ const x = margin + l * (width - 2 * margin) / Math.max(1, maxLayer);
27827
+ const ordered2 = orderByParentPositionThenInput(layerGroups[l], adjacency, yById, inputIndex);
27828
+ const ys = distributeAxis(ordered2.length, margin, height - margin);
27829
+ ordered2.forEach((id, i) => {
27830
+ positions.set(id, { id, x, y: ys[i] });
27831
+ yById.set(id, ys[i]);
27832
+ });
27833
+ }
27834
+ return nodeIds.map((id) => positions.get(id));
27835
+ }
27836
+ function layoutTree(nodeIds, adjacency, roots, width, height, margin) {
27837
+ const effectiveRoots = roots.length > 0 ? roots : [nodeIds[0]];
27838
+ const layers = assignLayers(nodeIds, adjacency, effectiveRoots);
27839
+ const maxLayer = Math.max(...Array.from(layers.values()));
27840
+ const visitOrder = computeVisitOrder(nodeIds, adjacency, effectiveRoots);
27841
+ const layerGroups = groupByTier(nodeIds, layers, maxLayer);
27842
+ const positions = /* @__PURE__ */ new Map();
27843
+ for (let l = 0; l <= maxLayer; l++) {
27844
+ const ordered2 = [...layerGroups[l]].sort(
27845
+ (a, b) => (visitOrder.get(a) ?? 0) - (visitOrder.get(b) ?? 0)
27846
+ );
27847
+ const y = margin + l * (height - 2 * margin) / Math.max(1, maxLayer);
27848
+ const xs = distributeAxis(ordered2.length, margin, width - margin);
27849
+ ordered2.forEach((id, i) => positions.set(id, { id, x: xs[i], y }));
27850
+ }
27851
+ return nodeIds.map((id) => positions.get(id));
27852
+ }
27853
+ function layoutRadial(nodeIds, adjacency, roots, width, height, margin) {
27854
+ const cx = width / 2;
27855
+ const cy = height / 2;
27856
+ const maxRadius = Math.min(width, height) / 2 - margin;
27857
+ if (roots.length === 0) {
27858
+ const order = edgeWalkOrder(nodeIds, adjacency);
27859
+ const k = order.length;
27860
+ const positions2 = /* @__PURE__ */ new Map();
27861
+ order.forEach((id, i) => {
27862
+ const angle = i / k * 2 * Math.PI;
27863
+ positions2.set(id, { id, x: cx + maxRadius * Math.cos(angle), y: cy + maxRadius * Math.sin(angle) });
27864
+ });
27865
+ return nodeIds.map((id) => positions2.get(id));
27866
+ }
27867
+ const { depth, visitOrder } = bfsDepthAndOrder(nodeIds, adjacency, roots);
27868
+ const maxDepth = Math.max(...Array.from(depth.values()));
27869
+ const ringGroups = groupByTier(nodeIds, depth, maxDepth);
27870
+ const positions = /* @__PURE__ */ new Map();
27871
+ for (let d = 0; d <= maxDepth; d++) {
27872
+ const ordered2 = [...ringGroups[d]].sort(
27873
+ (a, b) => (visitOrder.get(a) ?? 0) - (visitOrder.get(b) ?? 0)
27874
+ );
27875
+ const radius = d * maxRadius / Math.max(1, maxDepth);
27876
+ const k = ordered2.length;
27877
+ ordered2.forEach((id, i) => {
27878
+ const angle = i / k * 2 * Math.PI;
27879
+ positions.set(id, { id, x: cx + radius * Math.cos(angle), y: cy + radius * Math.sin(angle) });
27880
+ });
27881
+ }
27882
+ return nodeIds.map((id) => positions.get(id));
27883
+ }
27884
+ function computeStaticLayout(mode, input) {
27885
+ const { nodeIds, edges, width, height } = input;
27886
+ const margin = input.margin ?? 40;
27887
+ if (nodeIds.length === 0) return [];
27888
+ if (nodeIds.length === 1) return [{ id: nodeIds[0], x: width / 2, y: height / 2 }];
27889
+ const adjacency = buildAdjacency(nodeIds, edges);
27890
+ const roots = findRoots(nodeIds, adjacency);
27891
+ if (mode === "flow") return layoutFlow(nodeIds, adjacency, roots, width, height, margin);
27892
+ if (mode === "tree") return layoutTree(nodeIds, adjacency, roots, width, height, margin);
27893
+ return layoutRadial(nodeIds, adjacency, roots, width, height, margin);
27894
+ }
27895
+ var init_graphViewLayouts = __esm({
27896
+ "lib/graphViewLayouts.ts"() {
27897
+ }
27898
+ });
27700
27899
  function resolveNodeColor(node, groups) {
27701
27900
  if (node.color) return node.color;
27702
27901
  if (node.group) {
@@ -27711,6 +27910,7 @@ var init_GraphView = __esm({
27711
27910
  "use client";
27712
27911
  init_cn();
27713
27912
  init_atoms();
27913
+ init_graphViewLayouts();
27714
27914
  GROUP_COLORS = [
27715
27915
  "#3b82f6",
27716
27916
  // blue-500
@@ -27741,11 +27941,13 @@ var init_GraphView = __esm({
27741
27941
  height: propHeight,
27742
27942
  className,
27743
27943
  showLabels = true,
27744
- zoomToFit = true
27944
+ zoomToFit = true,
27945
+ layout = "force"
27745
27946
  }) => {
27746
27947
  const { t } = useTranslate();
27747
27948
  const containerRef = useRef(null);
27748
27949
  const animRef = useRef(0);
27950
+ const arrowMarkerId = useId();
27749
27951
  const [simNodes, setSimNodes] = useState([]);
27750
27952
  const [settled, setSettled] = useState(false);
27751
27953
  const [hoveredId, setHoveredId] = useState(null);
@@ -27802,6 +28004,22 @@ var init_GraphView = __esm({
27802
28004
  fy: 0
27803
28005
  };
27804
28006
  });
28007
+ if (layout !== "force") {
28008
+ const points = computeStaticLayout(layout, {
28009
+ nodeIds: nodes.map((n) => n.id),
28010
+ edges,
28011
+ width: w,
28012
+ height: h
28013
+ });
28014
+ const pointById = new Map(points.map((p) => [p.id, p]));
28015
+ const laidOut = initialNodes.map((node) => {
28016
+ const point = pointById.get(node.id);
28017
+ return point ? { ...node, x: point.x, y: point.y } : node;
28018
+ });
28019
+ setSimNodes(laidOut);
28020
+ setSettled(true);
28021
+ return;
28022
+ }
27805
28023
  let iterations = 0;
27806
28024
  const maxIterations = 120;
27807
28025
  let currentNodes = initialNodes;
@@ -27870,7 +28088,7 @@ var init_GraphView = __esm({
27870
28088
  return () => {
27871
28089
  cancelAnimationFrame(animRef.current);
27872
28090
  };
27873
- }, [nodes, edges, w, h, groups]);
28091
+ }, [nodes, edges, w, h, groups, layout]);
27874
28092
  const viewBox = useMemo(() => {
27875
28093
  if (!zoomToFit || !settled || simNodes.length === 0) {
27876
28094
  return `0 0 ${w} ${h}`;
@@ -27945,6 +28163,19 @@ var init_GraphView = __esm({
27945
28163
  viewBox,
27946
28164
  preserveAspectRatio: "xMidYMid meet",
27947
28165
  children: [
28166
+ layout !== "force" && /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx(
28167
+ "marker",
28168
+ {
28169
+ id: arrowMarkerId,
28170
+ viewBox: "0 0 10 10",
28171
+ refX: "9",
28172
+ refY: "5",
28173
+ markerWidth: "6",
28174
+ markerHeight: "6",
28175
+ orient: "auto-start-reverse",
28176
+ children: /* @__PURE__ */ jsx("path", { d: "M0,0 L10,5 L0,10 z", fill: "currentColor" })
28177
+ }
28178
+ ) }),
27948
28179
  edges.map((edge, idx) => {
27949
28180
  const source = nodeMap.get(edge.source);
27950
28181
  const target = nodeMap.get(edge.target);
@@ -27959,8 +28190,10 @@ var init_GraphView = __esm({
27959
28190
  x2: target.x,
27960
28191
  y2: target.y,
27961
28192
  stroke: edge.color ?? DEFAULT_EDGE_COLOR,
28193
+ color: edge.color ?? DEFAULT_EDGE_COLOR,
27962
28194
  strokeWidth: 1.5,
27963
- opacity: isHighlighted ? 0.8 : 0.15
28195
+ opacity: isHighlighted ? 0.8 : 0.15,
28196
+ markerEnd: layout !== "force" ? `url(#${arrowMarkerId})` : void 0
27964
28197
  }
27965
28198
  ),
27966
28199
  showLabels && edge.label && /* @__PURE__ */ jsx(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/ui",
3
- "version": "5.146.3",
3
+ "version": "5.147.0",
4
4
  "description": "React UI components, hooks, and providers for Almadar",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -118,12 +118,12 @@
118
118
  "access": "public"
119
119
  },
120
120
  "dependencies": {
121
- "@almadar/core": "^10.52.0",
122
- "@almadar/evaluator": "^2.39.0",
121
+ "@almadar/core": "^10.57.0",
122
+ "@almadar/evaluator": "^2.40.0",
123
123
  "@almadar/logger": "^1.11.0",
124
- "@almadar/runtime": "^6.51.0",
125
- "@almadar/std": "^16.163.0",
126
- "@almadar/syntax": "^1.14.0",
124
+ "@almadar/runtime": "^6.53.0",
125
+ "@almadar/std": "^16.170.0",
126
+ "@almadar/syntax": "^1.15.0",
127
127
  "@dnd-kit/core": "^6.3.1",
128
128
  "@dnd-kit/sortable": "^10.0.0",
129
129
  "@dnd-kit/utilities": "^3.2.2",