@inkindcards/semantic-layer 2.2.1 → 2.2.3

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,81 +861,103 @@ 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);
866
+ const registryRef = react.useRef(registry);
867
+ registryRef.current = registry;
849
868
  const inferredColumns = columns ?? (data?.[0] ? Object.keys(data[0]) : []);
850
869
  const sampleValues = data?.slice(0, 3) ?? [];
870
+ const columnsKey = inferredColumns.join(",");
851
871
  react.useEffect(() => {
852
- if (!registry) return;
853
- registry.register({
872
+ const reg = registryRef.current;
873
+ if (!reg) return;
874
+ reg.register({
854
875
  id,
855
876
  label,
856
877
  currentSource,
857
- columns: inferredColumns,
878
+ columns: columnsKey.split(",").filter(Boolean),
858
879
  sampleValues,
859
- element: ref.current
880
+ element: wrapperRef.current
860
881
  });
861
- return () => registry.unregister(id);
862
- }, [id, label, currentSource, inferredColumns.join(","), registry]);
882
+ return () => reg.unregister(id);
883
+ }, [id, label, currentSource, columnsKey]);
884
+ const inspectActive = registry?.inspectActive ?? false;
885
+ react.useEffect(() => {
886
+ if (!inspectActive || !wrapperRef.current) {
887
+ setRect(null);
888
+ return;
889
+ }
890
+ const measure = () => {
891
+ if (wrapperRef.current) {
892
+ setRect(getChildrenBounds(wrapperRef.current));
893
+ }
894
+ };
895
+ measure();
896
+ window.addEventListener("scroll", measure, true);
897
+ window.addEventListener("resize", measure);
898
+ const interval = setInterval(measure, 300);
899
+ return () => {
900
+ window.removeEventListener("scroll", measure, true);
901
+ window.removeEventListener("resize", measure);
902
+ clearInterval(interval);
903
+ };
904
+ }, [inspectActive]);
863
905
  if (!registry) {
864
906
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
865
907
  }
866
908
  const isSelected = registry.selectedId === id;
867
- const inspecting = registry.inspectActive;
868
909
  const handleClick = (e) => {
869
910
  e.stopPropagation();
870
911
  e.preventDefault();
871
912
  registry.setSelectedId(isSelected ? null : id);
872
913
  };
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
- );
914
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: wrapperRef, style: { display: "contents" }, children: [
915
+ children,
916
+ registry.inspectActive && rect && reactDom.createPortal(
917
+ /* @__PURE__ */ jsxRuntime.jsx(
918
+ "div",
919
+ {
920
+ onClick: handleClick,
921
+ style: {
922
+ position: "fixed",
923
+ top: rect.top,
924
+ left: rect.left,
925
+ width: rect.width,
926
+ height: rect.height,
927
+ zIndex: 9999,
928
+ cursor: "pointer",
929
+ outline: isSelected ? "2px solid #3b82f6" : "2px dashed #93c5fd",
930
+ outlineOffset: 2,
931
+ borderRadius: 4,
932
+ transition: "outline 0.15s ease",
933
+ background: isSelected ? "rgba(59,130,246,0.05)" : "transparent",
934
+ pointerEvents: "auto"
935
+ },
936
+ children: /* @__PURE__ */ jsxRuntime.jsx(
937
+ "div",
938
+ {
939
+ style: {
940
+ position: "absolute",
941
+ top: -10,
942
+ left: 4,
943
+ fontSize: 10,
944
+ fontWeight: 600,
945
+ fontFamily: "system-ui, -apple-system, sans-serif",
946
+ color: "#fff",
947
+ backgroundColor: isSelected ? "#3b82f6" : "#93c5fd",
948
+ padding: "1px 6px",
949
+ borderRadius: 3,
950
+ pointerEvents: "none",
951
+ whiteSpace: "nowrap"
952
+ },
953
+ children: label
954
+ }
955
+ )
956
+ }
957
+ ),
958
+ document.body
959
+ )
960
+ ] });
923
961
  }
924
962
 
925
963
  // src/components/field-matcher.ts