@stratakit/bricks
Version:
Small, modular components for StrataKit
99 lines (98 loc) • 2.52 kB
JavaScript
import { c as _c } from "react-compiler-runtime";
import { jsx } from "react/jsx-runtime";
import * as React from "react";
import { Collection, useCollectionStore } from "@ariakit/react/collection";
import { useStoreState } from "@ariakit/react/store";
function FieldCollection(props) {
const $ = _c(11);
let t0;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t0 = {
defaultItems: []
};
$[0] = t0;
} else {
t0 = $[0];
}
const fieldElementCollection = useCollectionStore(t0);
const renderedItems = useStoreState(fieldElementCollection, "renderedItems");
let t1;
if ($[1] !== renderedItems) {
t1 = renderedItems.findIndex(_temp);
$[1] = renderedItems;
$[2] = t1;
} else {
t1 = $[2];
}
const controlIndex2 = t1;
const t2 = renderedItems[controlIndex2]?.controlType;
let t3;
if ($[3] !== controlIndex2 || $[4] !== t2) {
t3 = [t2, controlIndex2];
$[3] = controlIndex2;
$[4] = t2;
$[5] = t3;
} else {
t3 = $[5];
}
const [controlType, controlIndex] = t3;
let t4;
bb0: {
const labelIndex = renderedItems.findIndex(_temp2);
if (controlIndex === -1 || labelIndex === -1) {
t4 = void 0;
break bb0;
}
t4 = labelIndex < controlIndex ? "before" : "after";
}
const labelPlacement = t4;
let t5;
if ($[6] !== controlType || $[7] !== fieldElementCollection || $[8] !== labelPlacement || $[9] !== props) {
t5 = jsx(Collection, {
...props,
store: fieldElementCollection,
"data-_sk-label-placement": labelPlacement,
"data-_sk-control-type": controlType
});
$[6] = controlType;
$[7] = fieldElementCollection;
$[8] = labelPlacement;
$[9] = props;
$[10] = t5;
} else {
t5 = $[10];
}
return t5;
}
function _temp2(item_0) {
return item_0.elementType === "label";
}
function _temp(item) {
return item.elementType === "control";
}
const FieldControlTypeContext = React.createContext(void 0);
function useFieldControlType(controlType) {
const $ = _c(4);
const setControlType = React.useContext(FieldControlTypeContext);
let t0;
let t1;
if ($[0] !== controlType || $[1] !== setControlType) {
t0 = () => {
setControlType?.(controlType);
};
t1 = [controlType, setControlType];
$[0] = controlType;
$[1] = setControlType;
$[2] = t0;
$[3] = t1;
} else {
t0 = $[2];
t1 = $[3];
}
React.useEffect(t0, t1);
}
export {
FieldCollection,
FieldControlTypeContext,
useFieldControlType
};