@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.
- package/dist/components.cjs +96 -58
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +4 -3
- package/dist/components.d.ts +4 -3
- package/dist/components.js +96 -58
- package/dist/components.js.map +1 -1
- package/package.json +2 -2
package/dist/components.cjs
CHANGED
|
@@ -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
|
|
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
|
-
|
|
853
|
-
|
|
872
|
+
const reg = registryRef.current;
|
|
873
|
+
if (!reg) return;
|
|
874
|
+
reg.register({
|
|
854
875
|
id,
|
|
855
876
|
label,
|
|
856
877
|
currentSource,
|
|
857
|
-
columns:
|
|
878
|
+
columns: columnsKey.split(",").filter(Boolean),
|
|
858
879
|
sampleValues,
|
|
859
|
-
element:
|
|
880
|
+
element: wrapperRef.current
|
|
860
881
|
});
|
|
861
|
-
return () =>
|
|
862
|
-
}, [id, label, currentSource,
|
|
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
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
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
|