UNPKG

@wordpress/components

Version:
87 lines (85 loc) 3.19 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/components/src/tree-select/index.tsx var tree_select_exports = {}; __export(tree_select_exports, { TreeSelect: () => TreeSelect, default: () => tree_select_default }); module.exports = __toCommonJS(tree_select_exports); var import_element = require("@wordpress/element"); var import_html_entities = require("@wordpress/html-entities"); var import_select_control = require("../select-control"); var import_use_deprecated_props = require("../utils/use-deprecated-props"); var import_context = require("../context"); var import_deprecated_36px_size = require("../utils/deprecated-36px-size"); var import_jsx_runtime = require("react/jsx-runtime"); var CONTEXT_VALUE = { BaseControl: { // Temporary during deprecation grace period: Overrides the underlying `__associatedWPComponentName` // via the context system to override the value set by SelectControl. _overrides: { __associatedWPComponentName: "TreeSelect" } } }; function getSelectOptions(tree, level = 0) { return tree.flatMap((treeNode) => [{ value: treeNode.id, label: "\xA0".repeat(level * 3) + (0, import_html_entities.decodeEntities)(treeNode.name) }, ...getSelectOptions(treeNode.children || [], level + 1)]); } function TreeSelect(props) { const { label, noOptionLabel, onChange, selectedId, tree = [], ...restProps } = (0, import_use_deprecated_props.useDeprecated36pxDefaultSizeProp)(props); const options = (0, import_element.useMemo)(() => { return [noOptionLabel && { value: "", label: noOptionLabel }, ...getSelectOptions(tree)].filter((option) => !!option); }, [noOptionLabel, tree]); (0, import_deprecated_36px_size.maybeWarnDeprecated36pxSize)({ componentName: "TreeSelect", size: restProps.size, __next40pxDefaultSize: restProps.__next40pxDefaultSize }); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_context.ContextSystemProvider, { value: CONTEXT_VALUE, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_select_control.SelectControl, { __shouldNotWarnDeprecated36pxSize: true, label, options, onChange, value: selectedId, ...restProps }) }); } var tree_select_default = TreeSelect; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { TreeSelect }); //# sourceMappingURL=index.js.map