@chayns-components/core
Version:
A set of beautiful React components for developing your own applications with chayns.
194 lines (192 loc) • 6.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.ListContext = void 0;
var _reactCompilerRuntime = require("react-compiler-runtime");
var _react = require("motion/react");
var _react2 = _interopRequireWildcard(require("react"));
var _ColorSchemeProvider = require("../color-scheme-provider/ColorSchemeProvider");
var _uuid = require("../../hooks/uuid");
var _List = require("./List.utils");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const ListContext = exports.ListContext = /*#__PURE__*/_react2.default.createContext({
isAnyItemExpandable: false,
isWrapped: false,
openItemUuid: undefined,
updateOpenItemUuid: () => {},
shouldEnableKeyboardHighlighting: false,
listGroupUuid: undefined,
listItemUuids: undefined,
registerListItemUuid: undefined,
unregisterListItemUuid: undefined,
activeListItemUuid: undefined,
updateActiveListItemUuid: undefined
});
ListContext.displayName = 'ListContext';
const List = t0 => {
"use memo";
const $ = (0, _reactCompilerRuntime.c)(24);
const {
children,
isWrapped: t1,
shouldEnableKeyboardHighlighting
} = t0;
const isWrapped = t1 === undefined ? false : t1;
const colorScheme = (0, _ColorSchemeProvider.useColorScheme)();
const shouldEnableKeyboardHighlightingEffective = shouldEnableKeyboardHighlighting ?? (colorScheme === null || colorScheme === void 0 ? void 0 : colorScheme.shouldEnableKeyboardHighlighting) ?? false;
const [openItemUuid, setOpenItemUuid] = (0, _react2.useState)(undefined);
const [listItemUuids, setListItemUuids] = (0, _react2.useState)();
const [activeListItemUuid, setActiveListItemUuid] = (0, _react2.useState)(undefined);
const listGroupUuid = (0, _uuid.useUuid)();
let t2;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t2 = (uuid, t3) => {
const {
shouldOnlyOpen
} = t3 === undefined ? {} : t3;
setOpenItemUuid(currentOpenItemUuid => {
if (currentOpenItemUuid === uuid && shouldOnlyOpen !== true) {
return;
}
return uuid;
});
};
$[0] = t2;
} else {
t2 = $[0];
}
const updateOpenItemUuid = t2;
let t3;
if ($[1] !== listGroupUuid) {
t3 = uuids => {
if (typeof document === "undefined") {
return uuids;
}
const domOrderedUuids = Array.from(document.querySelectorAll(`[data-uuid^="${listGroupUuid}---"]`)).map(_temp).filter(_temp2);
return domOrderedUuids.filter(uuid_1 => uuids.includes(uuid_1));
};
$[1] = listGroupUuid;
$[2] = t3;
} else {
t3 = $[2];
}
const sortListItemUuidsByDom = t3;
let t4;
if ($[3] !== sortListItemUuidsByDom) {
t4 = uuid_2 => {
setListItemUuids(t5 => {
const currentListItemUuids = t5 === undefined ? [] : t5;
const nextListItemUuids = currentListItemUuids.includes(uuid_2) ? currentListItemUuids : [...currentListItemUuids, uuid_2];
return sortListItemUuidsByDom(nextListItemUuids);
});
};
$[3] = sortListItemUuidsByDom;
$[4] = t4;
} else {
t4 = $[4];
}
const registerListItemUuid = t4;
let t5;
if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
t5 = uuid_3 => {
setListItemUuids(t6 => {
const currentListItemUuids_0 = t6 === undefined ? [] : t6;
return currentListItemUuids_0.filter(currentUuid => currentUuid !== uuid_3);
});
};
$[5] = t5;
} else {
t5 = $[5];
}
const unregisterListItemUuid = t5;
let t6;
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
t6 = uuid_4 => {
setActiveListItemUuid(uuid_4);
};
$[6] = t6;
} else {
t6 = $[6];
}
const updateActiveListItemUuid = t6;
let t7;
if ($[7] !== children) {
t7 = (0, _List.shouldShowExpandIndicator)(children);
$[7] = children;
$[8] = t7;
} else {
t7 = $[8];
}
let t8;
if ($[9] !== activeListItemUuid || $[10] !== isWrapped || $[11] !== listGroupUuid || $[12] !== listItemUuids || $[13] !== openItemUuid || $[14] !== registerListItemUuid || $[15] !== shouldEnableKeyboardHighlightingEffective || $[16] !== t7) {
t8 = {
isAnyItemExpandable: t7,
isWrapped,
openItemUuid,
updateOpenItemUuid,
shouldEnableKeyboardHighlighting: shouldEnableKeyboardHighlightingEffective,
listGroupUuid,
listItemUuids,
registerListItemUuid,
unregisterListItemUuid,
activeListItemUuid,
updateActiveListItemUuid
};
$[9] = activeListItemUuid;
$[10] = isWrapped;
$[11] = listGroupUuid;
$[12] = listItemUuids;
$[13] = openItemUuid;
$[14] = registerListItemUuid;
$[15] = shouldEnableKeyboardHighlightingEffective;
$[16] = t7;
$[17] = t8;
} else {
t8 = $[17];
}
const providerValue = t8;
let t9;
if ($[18] === Symbol.for("react.memo_cache_sentinel")) {
t9 = {
type: "tween"
};
$[18] = t9;
} else {
t9 = $[18];
}
let t10;
if ($[19] !== children) {
t10 = /*#__PURE__*/_react2.default.createElement(_react.MotionConfig, {
transition: t9
}, /*#__PURE__*/_react2.default.createElement(_react.AnimatePresence, {
initial: false
}, children));
$[19] = children;
$[20] = t10;
} else {
t10 = $[20];
}
let t11;
if ($[21] !== providerValue || $[22] !== t10) {
t11 = /*#__PURE__*/_react2.default.createElement(ListContext.Provider, {
value: providerValue
}, t10);
$[21] = providerValue;
$[22] = t10;
$[23] = t11;
} else {
t11 = $[23];
}
return t11;
};
List.displayName = 'List';
var _default = exports.default = List;
function _temp(element) {
var _element$getAttribute;
return (_element$getAttribute = element.getAttribute("data-uuid")) === null || _element$getAttribute === void 0 ? void 0 : _element$getAttribute.split("---")[1];
}
function _temp2(uuid_0) {
return Boolean(uuid_0);
}
//# sourceMappingURL=List.js.map