UNPKG

sanity

Version:

Sanity is a real-time content infrastructure with a scalable, hosted backend featuring a Graph Oriented Query Language (GROQ), asset pipelines and fast edge caches

145 lines (144 loc) 5.21 kB
"use strict"; var jsxRuntime = require("react/jsx-runtime"), ui = require("@sanity/ui"), sanity = require("sanity"), React = require("react"), getJsonStream = require("./getJsonStream.js"), StructureToolProvider = require("./StructureToolProvider.js"), icons = require("@sanity/icons"); require("sanity/router"); require("@sanity/types"); require("@sanity/util/paths"); require("lodash/omit.js"); require("lodash/isNumber.js"); require("lodash/isString.js"); require("react-rx"); var styled = require("styled-components"); function _interopDefaultCompat(e) { return e && typeof e == "object" && "default" in e ? e : { default: e }; } var styled__default = /* @__PURE__ */ _interopDefaultCompat(styled); const Divider = styled__default.default.hr` background-color: var(--card-border-color); height: 1px; margin: 0; border: none; `; function ListPaneContent(props) { const { childItemId, items, isActive, layout, showIcons, title } = props, { collapsed: layoutCollapsed } = StructureToolProvider.usePaneLayout(), getI18nText = sanity.useGetI18nText( items == null ? void 0 : items.filter( (item) => item.type !== "divider" ) ), getItemDisabled = React.useCallback( (itemIndex) => { var _a; return ((_a = items == null ? void 0 : items.find((_, i) => i === itemIndex)) == null ? void 0 : _a.type) === "divider"; }, [items] ), shouldShowIconForItem = React.useCallback( (item) => { var _a; const itemShowIcon = (_a = item.displayOptions) == null ? void 0 : _a.showIcon; return typeof itemShowIcon < "u" ? itemShowIcon !== !1 : showIcons !== !1; }, [showIcons] ), renderItem = React.useCallback( (item, ctx) => { const { virtualIndex: itemIndex } = ctx; if (item.type === "divider") return ( // eslint-disable-next-line react/no-array-index-key /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { marginBottom: 1, children: /* @__PURE__ */ jsxRuntime.jsx(Divider, {}) }, `divider-${itemIndex}`) ); const pressed = !isActive && childItemId === item.id, selected = isActive && childItemId === item.id, value = item._id && item.schemaType ? { _id: item._id, _type: item.schemaType.name, title: item.title } : void 0; return /* @__PURE__ */ jsxRuntime.jsx( StructureToolProvider.PaneItem, { icon: shouldShowIconForItem(item) ? item.icon : !1, id: item.id, layout, marginBottom: 1, pressed, schemaType: item.schemaType, selected, title: getI18nText(item).title, value }, item.id ); }, [childItemId, getI18nText, isActive, layout, shouldShowIconForItem] ); return /* @__PURE__ */ jsxRuntime.jsx(StructureToolProvider.PaneContent, { overflow: layoutCollapsed ? "hidden" : "auto", children: items && items.length > 0 && /* @__PURE__ */ jsxRuntime.jsx( sanity.CommandList, { activeItemDataAttr: "data-hovered", ariaLabel: title, canReceiveFocus: !0, getItemDisabled, itemHeight: 51, items, onlyShowSelectionWhenActive: !0, paddingBottom: 1, paddingX: 3, renderItem, wrapAround: !1 } ) }); } const ListPaneHeader = ({ index, menuItems, menuItemGroups, title }) => { const { features } = StructureToolProvider.useStructureTool(), { collapsed, isLast } = StructureToolProvider.usePane(), tabIndex = isLast && !collapsed ? -1 : 0; return /* @__PURE__ */ jsxRuntime.jsx( StructureToolProvider.PaneHeader, { actions: /* @__PURE__ */ jsxRuntime.jsx(StructureToolProvider.PaneHeaderActions, { menuItems, menuItemGroups }), backButton: features.backButton && index > 0 && /* @__PURE__ */ jsxRuntime.jsx( getJsonStream.Button, { as: StructureToolProvider.BackLink, "data-as": "a", icon: icons.ArrowLeftIcon, mode: "bleed", tooltipProps: { content: "Back" } } ), tabIndex, title } ); }; function ListPane(props) { const { childItemId, index, isActive, isSelected, pane, paneKey } = props, { defaultLayout, displayOptions, items, menuItems, menuItemGroups } = pane, showIcons = (displayOptions == null ? void 0 : displayOptions.showIcons) !== !1, { title } = sanity.useI18nText(pane); return /* @__PURE__ */ jsxRuntime.jsxs( StructureToolProvider.Pane, { currentMaxWidth: 350, "data-testid": "structure-tool-list-pane", "data-ui": "ListPane", id: paneKey, maxWidth: 640, minWidth: 320, selected: isSelected, children: [ StructureToolProvider._DEBUG, /* @__PURE__ */ jsxRuntime.jsx( ListPaneHeader, { index, menuItems, menuItemGroups, title } ), /* @__PURE__ */ jsxRuntime.jsx( ListPaneContent, { childItemId, isActive, items, layout: defaultLayout, showIcons, title }, paneKey ) ] } ); } exports.default = ListPane; //# sourceMappingURL=index2.js.map