@01.software/sdk 0.4.3-dev.1774338319418 → 0.4.3-dev.1774340903661

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ui/flow.js CHANGED
@@ -39,19 +39,6 @@ var __async = (__this, __arguments, generator) => {
39
39
  });
40
40
  };
41
41
 
42
- // src/ui/Flow/index.tsx
43
- import React2 from "react";
44
- import {
45
- ReactFlow,
46
- ReactFlowProvider,
47
- Background,
48
- Controls,
49
- MiniMap,
50
- MarkerType,
51
- useReactFlow,
52
- useStoreApi
53
- } from "@xyflow/react";
54
-
55
42
  // src/ui/Flow/types.ts
56
43
  function isDynamicNode(node) {
57
44
  return node.type === "dynamic";
@@ -444,7 +431,21 @@ function clearTemplateCache() {
444
431
  componentCache.clear();
445
432
  }
446
433
 
447
- // src/ui/Flow/index.tsx
434
+ // src/ui/Flow/FlowRenderer.tsx
435
+ import React5 from "react";
436
+ import {
437
+ ReactFlow,
438
+ ReactFlowProvider,
439
+ Background,
440
+ Controls,
441
+ MiniMap
442
+ } from "@xyflow/react";
443
+
444
+ // src/ui/Flow/node-types-factory.tsx
445
+ import React3 from "react";
446
+
447
+ // src/ui/Flow/node-renderers.tsx
448
+ import React2 from "react";
448
449
  function sanitizeUrl(url) {
449
450
  if (!url) return url;
450
451
  try {
@@ -455,11 +456,6 @@ function sanitizeUrl(url) {
455
456
  return void 0;
456
457
  }
457
458
  }
458
- function toMarkerType(value) {
459
- if (value === "arrow") return MarkerType.Arrow;
460
- if (value === "arrowclosed") return MarkerType.ArrowClosed;
461
- return void 0;
462
- }
463
459
  function renderFieldValue(key, val, fieldDef) {
464
460
  if (val == null || val === "") return null;
465
461
  const fieldType = fieldDef == null ? void 0 : fieldDef.fieldType;
@@ -611,13 +607,15 @@ function DefaultFrameNode({ data }) {
611
607
  )
612
608
  );
613
609
  }
610
+
611
+ // src/ui/Flow/node-types-factory.tsx
614
612
  function createNodeTypes(nodeRenderers, nodeTypeDefsMap, frameRenderer, nodeWrapper, renderNode) {
615
613
  const types = {};
616
614
  types.dynamic = ((props) => {
617
615
  const d = props.data;
618
616
  const typeDef = nodeTypeDefsMap == null ? void 0 : nodeTypeDefsMap.get(d.nodeTypeSlug);
619
617
  const CustomRenderer = nodeRenderers == null ? void 0 : nodeRenderers[d.nodeTypeSlug];
620
- const defaultRender = typeDef ? /* @__PURE__ */ React2.createElement(
618
+ const defaultRender = typeDef ? /* @__PURE__ */ React3.createElement(
621
619
  EnhancedDynamicNode,
622
620
  {
623
621
  data: d,
@@ -625,7 +623,7 @@ function createNodeTypes(nodeRenderers, nodeTypeDefsMap, frameRenderer, nodeWrap
625
623
  width: props.width,
626
624
  height: props.height
627
625
  }
628
- ) : /* @__PURE__ */ React2.createElement(DefaultDynamicNode, __spreadValues({}, props));
626
+ ) : /* @__PURE__ */ React3.createElement(DefaultDynamicNode, __spreadValues({}, props));
629
627
  const slotProps = {
630
628
  id: props.id,
631
629
  nodeTypeSlug: d.nodeTypeSlug,
@@ -637,14 +635,14 @@ function createNodeTypes(nodeRenderers, nodeTypeDefsMap, frameRenderer, nodeWrap
637
635
  height: props.height,
638
636
  defaultRender
639
637
  };
640
- let content = CustomRenderer ? /* @__PURE__ */ React2.createElement(CustomRenderer, __spreadValues({}, slotProps)) : defaultRender;
638
+ let content = CustomRenderer ? /* @__PURE__ */ React3.createElement(CustomRenderer, __spreadValues({}, slotProps)) : defaultRender;
641
639
  if (renderNode) {
642
640
  const result = renderNode(slotProps, content);
643
641
  if (result !== null) content = result;
644
642
  }
645
643
  if (nodeWrapper) {
646
644
  const Wrapper = nodeWrapper;
647
- content = /* @__PURE__ */ React2.createElement(
645
+ content = /* @__PURE__ */ React3.createElement(
648
646
  Wrapper,
649
647
  {
650
648
  id: props.id,
@@ -661,7 +659,7 @@ function createNodeTypes(nodeRenderers, nodeTypeDefsMap, frameRenderer, nodeWrap
661
659
  types.frame = frameRenderer ? ((props) => {
662
660
  const d = props.data;
663
661
  const Renderer = frameRenderer;
664
- return /* @__PURE__ */ React2.createElement(
662
+ return /* @__PURE__ */ React3.createElement(
665
663
  Renderer,
666
664
  {
667
665
  id: props.id,
@@ -685,7 +683,7 @@ function createEdgeTypes(edgeRenderers, edgeTypeDefsMap) {
685
683
  types[slug] = ((props) => {
686
684
  var _a;
687
685
  const def = edgeTypeDefsMap == null ? void 0 : edgeTypeDefsMap.get(slug);
688
- return /* @__PURE__ */ React2.createElement(
686
+ return /* @__PURE__ */ React3.createElement(
689
687
  Renderer,
690
688
  {
691
689
  id: props.id,
@@ -702,6 +700,57 @@ function createEdgeTypes(edgeRenderers, edgeTypeDefsMap) {
702
700
  }
703
701
  return types;
704
702
  }
703
+
704
+ // src/ui/Flow/edge-styles.ts
705
+ import { MarkerType } from "@xyflow/react";
706
+ function toMarkerType(value) {
707
+ if (value === "arrow") return MarkerType.Arrow;
708
+ if (value === "arrowclosed") return MarkerType.ArrowClosed;
709
+ return void 0;
710
+ }
711
+ var EDGE_TYPE_MAP = {
712
+ step: "step",
713
+ smoothstep: "smoothstep",
714
+ bezier: "default",
715
+ default: "default"
716
+ };
717
+ function applyEdgeStyles(edges, edgeTypeDefsMap) {
718
+ if (!(edgeTypeDefsMap == null ? void 0 : edgeTypeDefsMap.size)) return edges;
719
+ return edges.map((edge) => {
720
+ var _a;
721
+ const slug = edge.edgeTypeSlug;
722
+ if (!slug) return edge;
723
+ const def = edgeTypeDefsMap.get(slug);
724
+ if (!def) return edge;
725
+ const styled = __spreadValues({}, edge);
726
+ if (!styled.type && def.lineStyle) {
727
+ styled.type = (_a = EDGE_TYPE_MAP[def.lineStyle]) != null ? _a : "default";
728
+ }
729
+ styled.style = __spreadValues(__spreadValues(__spreadValues({}, def.color ? { stroke: def.color } : void 0), def.strokeWidth ? { strokeWidth: def.strokeWidth } : void 0), edge.style);
730
+ if (styled.animated == null && def.animated) styled.animated = true;
731
+ if (!styled.markerStart) {
732
+ const startType = toMarkerType(def.markerStart);
733
+ if (startType) {
734
+ styled.markerStart = __spreadValues({
735
+ type: startType
736
+ }, def.color ? { color: def.color } : void 0);
737
+ }
738
+ }
739
+ if (!styled.markerEnd) {
740
+ const endType = toMarkerType(def.markerEnd);
741
+ if (endType) {
742
+ styled.markerEnd = __spreadValues({
743
+ type: endType
744
+ }, def.color ? { color: def.color } : void 0);
745
+ }
746
+ }
747
+ return styled;
748
+ });
749
+ }
750
+
751
+ // src/ui/Flow/focus-handler.tsx
752
+ import React4 from "react";
753
+ import { useReactFlow, useStoreApi } from "@xyflow/react";
705
754
  function clampViewport(vp, cw, ch, extent) {
706
755
  const left = -vp.x / vp.zoom;
707
756
  const right = (cw - vp.x) / vp.zoom;
@@ -724,18 +773,19 @@ function FocusHandler({
724
773
  responsive,
725
774
  extent,
726
775
  clampBounds,
727
- minZoomProp
776
+ minZoomProp,
777
+ onInitialFit
728
778
  }) {
729
779
  const { setViewport } = useReactFlow();
730
780
  const store = useStoreApi();
731
- const containerRef = React2.useRef(null);
781
+ const containerRef = React4.useRef(null);
732
782
  const boundsKey = `${bounds.x},${bounds.y},${bounds.width},${bounds.height}`;
733
- const boundsRef = React2.useRef(bounds);
783
+ const boundsRef = React4.useRef(bounds);
734
784
  boundsRef.current = bounds;
735
- const [containerSize, setContainerSize] = React2.useState({ w: 0, h: 0 });
736
- const prevBoundsKeyRef = React2.useRef(null);
737
- const prevSizeRef = React2.useRef({ w: 0, h: 0 });
738
- React2.useEffect(() => {
785
+ const [containerSize, setContainerSize] = React4.useState({ w: 0, h: 0 });
786
+ const prevBoundsKeyRef = React4.useRef(null);
787
+ const prevSizeRef = React4.useRef({ w: 0, h: 0 });
788
+ React4.useEffect(() => {
739
789
  const el = containerRef.current;
740
790
  if (!el) return;
741
791
  const observer = new ResizeObserver((entries) => {
@@ -747,7 +797,7 @@ function FocusHandler({
747
797
  observer.observe(el);
748
798
  return () => observer.disconnect();
749
799
  }, []);
750
- React2.useEffect(() => {
800
+ React4.useEffect(() => {
751
801
  if (containerSize.w === 0 || containerSize.h === 0) return;
752
802
  const prevKey = prevBoundsKeyRef.current;
753
803
  const prevSize = prevSizeRef.current;
@@ -757,18 +807,17 @@ function FocusHandler({
757
807
  const isResizeOnly = !isBoundsChange && (prevSize.w !== containerSize.w || prevSize.h !== containerSize.h);
758
808
  const isInitial = prevKey === null;
759
809
  if (isResizeOnly && !responsive) return;
760
- const duration = isInitial || isBoundsChange ? animation === true ? 300 : typeof animation === "number" ? animation : 0 : 0;
810
+ const duration = isInitial ? 0 : isBoundsChange ? animation === true ? 300 : typeof animation === "number" ? animation : 0 : 0;
761
811
  const b = boundsRef.current;
762
- const zoomTarget = mode === "cover" && clampBounds ? clampBounds : b;
763
- const padX = padding * zoomTarget.width;
764
- const padY = padding * zoomTarget.height;
765
- const bw = zoomTarget.width + padX * 2;
766
- const bh = zoomTarget.height + padY * 2;
812
+ const padX = padding * b.width;
813
+ const padY = padding * b.height;
814
+ const bw = b.width + padX * 2;
815
+ const bh = b.height + padY * 2;
767
816
  if (bw === 0 || bh === 0) return;
768
817
  const zoomFn = mode === "cover" ? Math.max : Math.min;
769
818
  const zoom = zoomFn(containerSize.w / bw, containerSize.h / bh);
770
- const cx = zoomTarget.x + zoomTarget.width / 2;
771
- const cy = zoomTarget.y + zoomTarget.height / 2;
819
+ const cx = b.x + b.width / 2;
820
+ const cy = b.y + b.height / 2;
772
821
  const x = containerSize.w / 2 - cx * zoom;
773
822
  const y = containerSize.h / 2 - cy * zoom;
774
823
  if (clampBounds) {
@@ -781,10 +830,15 @@ function FocusHandler({
781
830
  store.getState().setMinZoom(minZoomProp != null ? minZoomProp : 0.5);
782
831
  }
783
832
  let vp = { x, y, zoom };
784
- if (extent) {
785
- vp = clampViewport(vp, containerSize.w, containerSize.h, extent);
833
+ if (isInitial || isBoundsChange) {
834
+ setViewport(vp, { duration: isInitial ? 0 : duration });
835
+ onInitialFit == null ? void 0 : onInitialFit();
836
+ } else {
837
+ if (extent) {
838
+ vp = clampViewport(vp, containerSize.w, containerSize.h, extent);
839
+ }
840
+ setViewport(vp, { duration });
786
841
  }
787
- setViewport(vp, { duration });
788
842
  }, [
789
843
  boundsKey,
790
844
  padding,
@@ -797,9 +851,10 @@ function FocusHandler({
797
851
  setViewport,
798
852
  clampBounds,
799
853
  minZoomProp,
800
- store
854
+ store,
855
+ onInitialFit
801
856
  ]);
802
- return /* @__PURE__ */ React2.createElement(
857
+ return /* @__PURE__ */ React4.createElement(
803
858
  "div",
804
859
  {
805
860
  ref: containerRef,
@@ -812,45 +867,8 @@ function FocusHandler({
812
867
  }
813
868
  );
814
869
  }
815
- var EDGE_TYPE_MAP = {
816
- step: "step",
817
- smoothstep: "smoothstep",
818
- bezier: "default",
819
- default: "default"
820
- };
821
- function applyEdgeStyles(edges, edgeTypeDefsMap) {
822
- if (!(edgeTypeDefsMap == null ? void 0 : edgeTypeDefsMap.size)) return edges;
823
- return edges.map((edge) => {
824
- var _a;
825
- const slug = edge.edgeTypeSlug;
826
- if (!slug) return edge;
827
- const def = edgeTypeDefsMap.get(slug);
828
- if (!def) return edge;
829
- const styled = __spreadValues({}, edge);
830
- if (!styled.type && def.lineStyle) {
831
- styled.type = (_a = EDGE_TYPE_MAP[def.lineStyle]) != null ? _a : "default";
832
- }
833
- styled.style = __spreadValues(__spreadValues(__spreadValues({}, def.color ? { stroke: def.color } : void 0), def.strokeWidth ? { strokeWidth: def.strokeWidth } : void 0), edge.style);
834
- if (styled.animated == null && def.animated) styled.animated = true;
835
- if (!styled.markerStart) {
836
- const startType = toMarkerType(def.markerStart);
837
- if (startType) {
838
- styled.markerStart = __spreadValues({
839
- type: startType
840
- }, def.color ? { color: def.color } : void 0);
841
- }
842
- }
843
- if (!styled.markerEnd) {
844
- const endType = toMarkerType(def.markerEnd);
845
- if (endType) {
846
- styled.markerEnd = __spreadValues({
847
- type: endType
848
- }, def.color ? { color: def.color } : void 0);
849
- }
850
- }
851
- return styled;
852
- });
853
- }
870
+
871
+ // src/ui/Flow/FlowRenderer.tsx
854
872
  function FlowRenderer({
855
873
  data,
856
874
  className,
@@ -888,15 +906,15 @@ function FlowRenderer({
888
906
  maxZoom: maxZoomProp
889
907
  }) {
890
908
  var _a;
891
- const nodeTypeDefsMap = React2.useMemo(() => {
909
+ const nodeTypeDefsMap = React5.useMemo(() => {
892
910
  if (!(nodeTypeDefs == null ? void 0 : nodeTypeDefs.length)) return void 0;
893
911
  return new Map(nodeTypeDefs.map((d) => [d.slug, d]));
894
912
  }, [nodeTypeDefs]);
895
- const edgeTypeDefsMap = React2.useMemo(() => {
913
+ const edgeTypeDefsMap = React5.useMemo(() => {
896
914
  if (!(edgeTypeDefs == null ? void 0 : edgeTypeDefs.length)) return void 0;
897
915
  return new Map(edgeTypeDefs.map((d) => [d.slug, d]));
898
916
  }, [edgeTypeDefs]);
899
- const nodeTypes = React2.useMemo(
917
+ const nodeTypes = React5.useMemo(
900
918
  () => createNodeTypes(
901
919
  nodeRenderers,
902
920
  nodeTypeDefsMap,
@@ -906,15 +924,15 @@ function FlowRenderer({
906
924
  ),
907
925
  [nodeRenderers, nodeTypeDefsMap, frameRenderer, nodeWrapper, renderNode]
908
926
  );
909
- const customEdgeTypes = React2.useMemo(
927
+ const customEdgeTypes = React5.useMemo(
910
928
  () => createEdgeTypes(edgeRenderers, edgeTypeDefsMap),
911
929
  [edgeRenderers, edgeTypeDefsMap]
912
930
  );
913
- const mergedCSS = React2.useMemo(() => {
931
+ const mergedCSS = React5.useMemo(() => {
914
932
  if (!(nodeTypeDefs == null ? void 0 : nodeTypeDefs.length)) return "";
915
933
  return nodeTypeDefs.filter((d) => d.customCSS).map((d) => d.customCSS).join("\n");
916
934
  }, [nodeTypeDefs]);
917
- const styledEdges = React2.useMemo(() => {
935
+ const styledEdges = React5.useMemo(() => {
918
936
  var _a2;
919
937
  let edges = applyEdgeStyles((_a2 = data == null ? void 0 : data.edges) != null ? _a2 : [], edgeTypeDefsMap);
920
938
  if (edgeRenderers) {
@@ -928,7 +946,7 @@ function FlowRenderer({
928
946
  }
929
947
  return edges;
930
948
  }, [data == null ? void 0 : data.edges, edgeTypeDefsMap, edgeRenderers]);
931
- const translateExtent = React2.useMemo(() => {
949
+ const translateExtent = React5.useMemo(() => {
932
950
  if (translateExtentProp) return translateExtentProp;
933
951
  const es = clampBounds != null ? clampBounds : bounds;
934
952
  if (!es) return void 0;
@@ -938,9 +956,22 @@ function FlowRenderer({
938
956
  [es.x + es.width * (1 + ep), es.y + es.height * (1 + ep)]
939
957
  ];
940
958
  }, [translateExtentProp, clampBounds, bounds, focusPadding]);
959
+ const boundsKey = bounds ? `${bounds.x},${bounds.y},${bounds.width},${bounds.height}` : "";
960
+ const extentReadyRef = React5.useRef(false);
961
+ const prevBoundsKeyRef = React5.useRef(boundsKey);
962
+ if (prevBoundsKeyRef.current !== boundsKey) {
963
+ prevBoundsKeyRef.current = boundsKey;
964
+ extentReadyRef.current = false;
965
+ }
966
+ const [, rerender] = React5.useReducer((x) => x + 1, 0);
967
+ const handleInitialFit = React5.useCallback(() => {
968
+ extentReadyRef.current = true;
969
+ rerender();
970
+ }, []);
971
+ const activeExtent = !bounds || extentReadyRef.current ? translateExtent : void 0;
941
972
  if (!data) return null;
942
973
  const resolvedDefaultViewport = defaultViewportProp != null ? defaultViewportProp : !fitView && data.viewport ? data.viewport : void 0;
943
- return /* @__PURE__ */ React2.createElement(ReactFlowProvider, null, /* @__PURE__ */ React2.createElement(
974
+ return /* @__PURE__ */ React5.createElement(ReactFlowProvider, null, /* @__PURE__ */ React5.createElement(
944
975
  "div",
945
976
  {
946
977
  className,
@@ -950,7 +981,7 @@ function FlowRenderer({
950
981
  background: "transparent"
951
982
  }, style)
952
983
  },
953
- /* @__PURE__ */ React2.createElement(
984
+ /* @__PURE__ */ React5.createElement(
954
985
  ReactFlow,
955
986
  {
956
987
  nodes: (_a = data.nodes) != null ? _a : [],
@@ -959,7 +990,7 @@ function FlowRenderer({
959
990
  edgeTypes: customEdgeTypes,
960
991
  defaultViewport: resolvedDefaultViewport,
961
992
  fitView: bounds ? false : fitView,
962
- translateExtent,
993
+ translateExtent: activeExtent,
963
994
  onNodeClick,
964
995
  onNodeDoubleClick,
965
996
  onNodeContextMenu,
@@ -980,16 +1011,16 @@ function FlowRenderer({
980
1011
  maxZoom: maxZoomProp,
981
1012
  proOptions: { hideAttribution: true }
982
1013
  },
983
- mergedCSS && /* @__PURE__ */ React2.createElement("style", { dangerouslySetInnerHTML: { __html: mergedCSS } }),
984
- background && /* @__PURE__ */ React2.createElement(Background, null),
985
- controls && /* @__PURE__ */ React2.createElement(Controls, null),
986
- minimap && /* @__PURE__ */ React2.createElement(
1014
+ mergedCSS && /* @__PURE__ */ React5.createElement("style", { dangerouslySetInnerHTML: { __html: mergedCSS } }),
1015
+ background && /* @__PURE__ */ React5.createElement(Background, null),
1016
+ controls && /* @__PURE__ */ React5.createElement(Controls, null),
1017
+ minimap && /* @__PURE__ */ React5.createElement(
987
1018
  MiniMap,
988
1019
  {
989
1020
  nodeColor: minimapNodeColor
990
1021
  }
991
1022
  ),
992
- bounds && /* @__PURE__ */ React2.createElement(
1023
+ bounds && /* @__PURE__ */ React5.createElement(
993
1024
  FocusHandler,
994
1025
  {
995
1026
  bounds,
@@ -999,7 +1030,8 @@ function FlowRenderer({
999
1030
  responsive: responsiveFit != null ? responsiveFit : true,
1000
1031
  extent: translateExtent,
1001
1032
  clampBounds,
1002
- minZoomProp
1033
+ minZoomProp,
1034
+ onInitialFit: handleInitialFit
1003
1035
  }
1004
1036
  ),
1005
1037
  children