@inkindcards/semantic-layer 2.2.1 → 2.2.2

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.
@@ -3,6 +3,7 @@
3
3
  var chunkT2C43AAL_cjs = require('./chunk-T2C43AAL.cjs');
4
4
  var react = require('react');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
+ var reactDom = require('react-dom');
6
7
 
7
8
  var containerStyle = {
8
9
  fontFamily: "system-ui, -apple-system, sans-serif",
@@ -836,6 +837,21 @@ function InspectableRegistry({ children }) {
836
837
  };
837
838
  return /* @__PURE__ */ jsxRuntime.jsx(InspectableRegistryContext.Provider, { value, children });
838
839
  }
840
+ function getChildrenBounds(el) {
841
+ const children = el.children;
842
+ if (children.length === 0) return null;
843
+ let top = Infinity, left = Infinity, bottom = -Infinity, right = -Infinity;
844
+ for (let i = 0; i < children.length; i++) {
845
+ const r = children[i].getBoundingClientRect();
846
+ if (r.width === 0 && r.height === 0) continue;
847
+ top = Math.min(top, r.top);
848
+ left = Math.min(left, r.left);
849
+ bottom = Math.max(bottom, r.bottom);
850
+ right = Math.max(right, r.right);
851
+ }
852
+ if (top === Infinity) return null;
853
+ return new DOMRect(left, top, right - left, bottom - top);
854
+ }
839
855
  function Inspectable({
840
856
  label,
841
857
  currentSource = "unknown",
@@ -845,7 +861,8 @@ function Inspectable({
845
861
  }) {
846
862
  const registry = react.useContext(InspectableRegistryContext);
847
863
  const id = react.useId();
848
- const ref = react.useRef(null);
864
+ const wrapperRef = react.useRef(null);
865
+ const [rect, setRect] = react.useState(null);
849
866
  const inferredColumns = columns ?? (data?.[0] ? Object.keys(data[0]) : []);
850
867
  const sampleValues = data?.slice(0, 3) ?? [];
851
868
  react.useEffect(() => {
@@ -856,70 +873,86 @@ function Inspectable({
856
873
  currentSource,
857
874
  columns: inferredColumns,
858
875
  sampleValues,
859
- element: ref.current
876
+ element: wrapperRef.current
860
877
  });
861
878
  return () => registry.unregister(id);
862
879
  }, [id, label, currentSource, inferredColumns.join(","), registry]);
880
+ react.useEffect(() => {
881
+ if (!registry?.inspectActive || !wrapperRef.current) {
882
+ setRect(null);
883
+ return;
884
+ }
885
+ const measure = () => {
886
+ if (wrapperRef.current) {
887
+ setRect(getChildrenBounds(wrapperRef.current));
888
+ }
889
+ };
890
+ measure();
891
+ window.addEventListener("scroll", measure, true);
892
+ window.addEventListener("resize", measure);
893
+ const interval = setInterval(measure, 300);
894
+ return () => {
895
+ window.removeEventListener("scroll", measure, true);
896
+ window.removeEventListener("resize", measure);
897
+ clearInterval(interval);
898
+ };
899
+ }, [registry?.inspectActive]);
863
900
  if (!registry) {
864
901
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
865
902
  }
866
903
  const isSelected = registry.selectedId === id;
867
- const inspecting = registry.inspectActive;
868
904
  const handleClick = (e) => {
869
905
  e.stopPropagation();
870
906
  e.preventDefault();
871
907
  registry.setSelectedId(isSelected ? null : id);
872
908
  };
873
- if (!inspecting) {
874
- return /* @__PURE__ */ jsxRuntime.jsx("div", { ref, children });
875
- }
876
- return /* @__PURE__ */ jsxRuntime.jsxs(
877
- "div",
878
- {
879
- ref,
880
- style: { position: "relative" },
881
- children: [
882
- children,
883
- /* @__PURE__ */ jsxRuntime.jsx(
884
- "div",
885
- {
886
- onClick: handleClick,
887
- style: {
888
- position: "absolute",
889
- inset: 0,
890
- zIndex: 9999,
891
- cursor: "pointer",
892
- outline: isSelected ? "2px solid #3b82f6" : "2px dashed #93c5fd",
893
- outlineOffset: 2,
894
- borderRadius: 4,
895
- transition: "outline 0.15s ease",
896
- background: isSelected ? "rgba(59,130,246,0.05)" : "transparent"
897
- },
898
- children: /* @__PURE__ */ jsxRuntime.jsx(
899
- "div",
900
- {
901
- style: {
902
- position: "absolute",
903
- top: -10,
904
- left: 4,
905
- fontSize: 10,
906
- fontWeight: 600,
907
- fontFamily: "system-ui, -apple-system, sans-serif",
908
- color: "#fff",
909
- backgroundColor: isSelected ? "#3b82f6" : "#93c5fd",
910
- padding: "1px 6px",
911
- borderRadius: 3,
912
- pointerEvents: "none",
913
- whiteSpace: "nowrap"
914
- },
915
- children: label
916
- }
917
- )
918
- }
919
- )
920
- ]
921
- }
922
- );
909
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: wrapperRef, style: { display: "contents" }, children: [
910
+ children,
911
+ registry.inspectActive && rect && reactDom.createPortal(
912
+ /* @__PURE__ */ jsxRuntime.jsx(
913
+ "div",
914
+ {
915
+ onClick: handleClick,
916
+ style: {
917
+ position: "fixed",
918
+ top: rect.top,
919
+ left: rect.left,
920
+ width: rect.width,
921
+ height: rect.height,
922
+ zIndex: 9999,
923
+ cursor: "pointer",
924
+ outline: isSelected ? "2px solid #3b82f6" : "2px dashed #93c5fd",
925
+ outlineOffset: 2,
926
+ borderRadius: 4,
927
+ transition: "outline 0.15s ease",
928
+ background: isSelected ? "rgba(59,130,246,0.05)" : "transparent",
929
+ pointerEvents: "auto"
930
+ },
931
+ children: /* @__PURE__ */ jsxRuntime.jsx(
932
+ "div",
933
+ {
934
+ style: {
935
+ position: "absolute",
936
+ top: -10,
937
+ left: 4,
938
+ fontSize: 10,
939
+ fontWeight: 600,
940
+ fontFamily: "system-ui, -apple-system, sans-serif",
941
+ color: "#fff",
942
+ backgroundColor: isSelected ? "#3b82f6" : "#93c5fd",
943
+ padding: "1px 6px",
944
+ borderRadius: 3,
945
+ pointerEvents: "none",
946
+ whiteSpace: "nowrap"
947
+ },
948
+ children: label
949
+ }
950
+ )
951
+ }
952
+ ),
953
+ document.body
954
+ )
955
+ ] });
923
956
  }
924
957
 
925
958
  // src/components/field-matcher.ts