@sanity/hierarchical-document-list 0.1.1 → 1.0.0

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.
Files changed (57) hide show
  1. package/README.md +55 -19
  2. package/lib/TreeDeskStructure.d.ts +2 -1
  3. package/lib/TreeDeskStructure.js +46 -21
  4. package/lib/TreeInputComponent.d.ts +1 -1
  5. package/lib/TreeInputComponent.js +39 -8
  6. package/lib/components/DeskWarning.d.ts +1 -1
  7. package/lib/components/DeskWarning.js +28 -7
  8. package/lib/components/DocumentInNode.d.ts +1 -1
  9. package/lib/components/DocumentInNode.js +42 -18
  10. package/lib/components/DocumentPreviewStatus.d.ts +1 -1
  11. package/lib/components/DocumentPreviewStatus.js +16 -12
  12. package/lib/components/NodeActions.d.ts +1 -1
  13. package/lib/components/NodeActions.js +34 -10
  14. package/lib/components/NodeContentRenderer.js +43 -19
  15. package/lib/components/PlaceholderDropzone.d.ts +1 -1
  16. package/lib/components/PlaceholderDropzone.js +7 -5
  17. package/lib/components/TreeEditor.d.ts +1 -1
  18. package/lib/components/TreeEditor.js +28 -23
  19. package/lib/components/TreeEditorErrorBoundary.d.ts +1 -1
  20. package/lib/components/TreeEditorErrorBoundary.js +28 -7
  21. package/lib/components/TreeNodeRenderer.js +30 -6
  22. package/lib/components/TreeNodeRendererScaffold.d.ts +1 -1
  23. package/lib/components/TreeNodeRendererScaffold.js +9 -7
  24. package/lib/createDeskHierarchy.js +37 -19
  25. package/lib/createHierarchicalSchemas.d.ts +78 -0
  26. package/lib/createHierarchicalSchemas.js +138 -0
  27. package/lib/{utils → hooks}/useAllItems.d.ts +0 -0
  28. package/lib/{utils → hooks}/useAllItems.js +34 -9
  29. package/lib/{utils → hooks}/useLocalTree.d.ts +0 -0
  30. package/lib/{utils → hooks}/useLocalTree.js +26 -4
  31. package/lib/{utils → hooks}/useTreeOperations.d.ts +1 -1
  32. package/lib/hooks/useTreeOperations.js +39 -0
  33. package/lib/{utils → hooks}/useTreeOperationsProvider.d.ts +1 -1
  34. package/lib/hooks/useTreeOperationsProvider.js +85 -0
  35. package/lib/index.d.ts +1 -1
  36. package/lib/index.js +12 -3
  37. package/lib/schemas/hierarchy.tree.d.ts +5 -15
  38. package/lib/schemas/hierarchy.tree.js +10 -22
  39. package/lib/utils/flatDataToTree.js +6 -3
  40. package/lib/utils/getAdjescentNodes.js +4 -1
  41. package/lib/utils/getCommonTreeProps.js +16 -10
  42. package/lib/utils/getTreeHeight.js +9 -5
  43. package/lib/utils/gradientPatchAdapter.js +12 -5
  44. package/lib/utils/idUtils.js +7 -2
  45. package/lib/utils/injectNodeTypeInPatches.d.ts +12 -0
  46. package/lib/utils/injectNodeTypeInPatches.js +58 -0
  47. package/lib/utils/moveItemInArray.js +4 -1
  48. package/lib/utils/throwError.d.ts +7 -0
  49. package/lib/utils/throwError.js +12 -0
  50. package/lib/utils/treeData.js +27 -15
  51. package/lib/utils/treePatches.js +51 -21
  52. package/package.json +1 -2
  53. package/tsconfig.json +3 -3
  54. package/lib/createHierarchicalField.d.ts +0 -8
  55. package/lib/createHierarchicalField.js +0 -51
  56. package/lib/utils/useTreeOperations.js +0 -16
  57. package/lib/utils/useTreeOperationsProvider.js +0 -60
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
3
  if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
4
  return cooked;
@@ -13,20 +14,43 @@ var __assign = (this && this.__assign) || function () {
13
14
  };
14
15
  return __assign.apply(this, arguments);
15
16
  };
16
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
17
- import { cyan, gray, red } from '@sanity/color';
18
- import { ChevronDownIcon, ChevronRightIcon, DragHandleIcon } from '@sanity/icons';
19
- import { Box, Button, Flex, Spinner } from '@sanity/ui';
20
- import React from 'react';
21
- import { isDescendant } from 'react-sortable-tree';
22
- import styled from 'styled-components';
23
- var Root = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n // Adapted from react-sortable-tree/style.css\n &[data-landing='true'] > *,\n &[data-cancel='true'] > * {\n opacity: 0 !important;\n }\n &[data-landing='true']::before,\n &[data-cancel='true']::before {\n background-color: ", ";\n border: 2px dashed ", ";\n border-radius: 3px;\n content: '';\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n z-index: -1;\n }\n\n &[data-cancel='true']::before {\n background-color: ", ";\n }\n"], ["\n // Adapted from react-sortable-tree/style.css\n &[data-landing='true'] > *,\n &[data-cancel='true'] > * {\n opacity: 0 !important;\n }\n &[data-landing='true']::before,\n &[data-cancel='true']::before {\n background-color: ", ";\n border: 2px dashed ", ";\n border-radius: 3px;\n content: '';\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n z-index: -1;\n }\n\n &[data-cancel='true']::before {\n background-color: ", ";\n }\n"
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ var jsx_runtime_1 = require("react/jsx-runtime");
41
+ var color_1 = require("@sanity/color");
42
+ var icons_1 = require("@sanity/icons");
43
+ var ui_1 = require("@sanity/ui");
44
+ var React = __importStar(require("react"));
45
+ var react_sortable_tree_1 = require("react-sortable-tree");
46
+ var styled_components_1 = __importDefault(require("styled-components"));
47
+ var Root = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n // Adapted from react-sortable-tree/style.css\n &[data-landing='true'] > *,\n &[data-cancel='true'] > * {\n opacity: 0 !important;\n }\n &[data-landing='true']::before,\n &[data-cancel='true']::before {\n background-color: ", ";\n border: 2px dashed ", ";\n border-radius: 3px;\n content: '';\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n z-index: -1;\n }\n\n &[data-cancel='true']::before {\n background-color: ", ";\n }\n"], ["\n // Adapted from react-sortable-tree/style.css\n &[data-landing='true'] > *,\n &[data-cancel='true'] > * {\n opacity: 0 !important;\n }\n &[data-landing='true']::before,\n &[data-cancel='true']::before {\n background-color: ", ";\n border: 2px dashed ", ";\n border-radius: 3px;\n content: '';\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n z-index: -1;\n }\n\n &[data-cancel='true']::before {\n background-color: ", ";\n }\n"
24
48
  /**
25
49
  * Customization of react-sortable-tree's default node.
26
50
  * Created in order to use Sanity UI for styles.
27
51
  * Reference: https://github.com/frontend-collective/react-sortable-tree/blob/master/src/node-renderer-default.js
28
52
  */
29
- ])), cyan[50].hex, gray[400].hex, red[50].hex);
53
+ ])), color_1.cyan[50].hex, color_1.gray[400].hex, color_1.red[50].hex);
30
54
  /**
31
55
  * Customization of react-sortable-tree's default node.
32
56
  * Created in order to use Sanity UI for styles.
@@ -42,12 +66,12 @@ var NodeContentRenderer = function (props) {
42
66
  if (typeof node.children === 'function' && node.expanded) {
43
67
  // Show a loading symbol on the handle when the children are expanded
44
68
  // and yet still defined by a function (a callback to fetch the children)
45
- return _jsx(Spinner, {}, void 0);
69
+ return (0, jsx_runtime_1.jsx)(ui_1.Spinner, {}, void 0);
46
70
  }
47
- var BtnElement = (_jsx("div", { children: _jsx(Button, __assign({ mode: "bleed", paddingX: 0, paddingY: 1, style: {
71
+ var BtnElement = ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(ui_1.Button, __assign({ mode: "bleed", paddingX: 0, paddingY: 1, style: {
48
72
  cursor: node.publishedId ? 'grab' : 'default',
49
73
  fontSize: '1.5625rem'
50
- }, "data-ui": "DragHandleButton", "data-drag-handle": canDrag, disabled: !node.publishedId }, { children: _jsx(DragHandleIcon, { style: { marginBottom: '-0.1em' } }, void 0) }), void 0) }, void 0));
74
+ }, "data-ui": "DragHandleButton", "data-drag-handle": canDrag, disabled: !node.publishedId }, { children: (0, jsx_runtime_1.jsx)(icons_1.DragHandleIcon, { style: { marginBottom: '-0.1em' } }, void 0) }), void 0) }, void 0));
51
75
  // Don't allow editors to drag invalid documents
52
76
  if (!node.publishedId) {
53
77
  return BtnElement;
@@ -57,25 +81,25 @@ var NodeContentRenderer = function (props) {
57
81
  dropEffect: 'copy'
58
82
  });
59
83
  }, [canDrag, node, typeof node.children === 'function']);
60
- var isDraggedDescendant = props.draggedNode && isDescendant(props.draggedNode, node);
84
+ var isDraggedDescendant = props.draggedNode && (0, react_sortable_tree_1.isDescendant)(props.draggedNode, node);
61
85
  var isLandingPadActive = !props.didDrop && props.isDragging;
62
- return (_jsxs(Box, __assign({ style: { position: 'relative' } }, { children: [props.toggleChildrenVisibility &&
86
+ return ((0, jsx_runtime_1.jsxs)(ui_1.Box, __assign({ style: { position: 'relative' } }, { children: [props.toggleChildrenVisibility &&
63
87
  node.children &&
64
- (node.children.length > 0 || typeof node.children === 'function') && (_jsx("div", __assign({ style: {
88
+ (node.children.length > 0 || typeof node.children === 'function') && ((0, jsx_runtime_1.jsx)("div", __assign({ style: {
65
89
  position: 'absolute',
66
90
  left: '-2px',
67
91
  top: '40%',
68
92
  transform: 'translate(-100%, -50%)'
69
- } }, { children: _jsx(Button, { "aria-label": node.expanded ? 'Collapse' : 'Expand', icon: node.expanded ? (_jsx(ChevronDownIcon, { color: gray[200].hex }, void 0)) : (_jsx(ChevronRightIcon, { color: gray[200].hex }, void 0)), mode: "bleed", fontSize: 2, padding: 1, type: "button", onClick: function () {
93
+ } }, { children: (0, jsx_runtime_1.jsx)(ui_1.Button, { "aria-label": node.expanded ? 'Collapse' : 'Expand', icon: node.expanded ? ((0, jsx_runtime_1.jsx)(icons_1.ChevronDownIcon, { color: color_1.gray[200].hex }, void 0)) : ((0, jsx_runtime_1.jsx)(icons_1.ChevronRightIcon, { color: color_1.gray[200].hex }, void 0)), mode: "bleed", fontSize: 2, padding: 1, type: "button", onClick: function () {
70
94
  var _a;
71
95
  return (_a = props.toggleChildrenVisibility) === null || _a === void 0 ? void 0 : _a.call(props, {
72
96
  node: node,
73
97
  path: path,
74
98
  treeIndex: treeIndex
75
99
  });
76
- } }, void 0) }), void 0)), props.connectDragPreview(_jsx("div", { children: _jsx(Root, __assign({ "data-landing": isLandingPadActive, "data-cancel": isLandingPadActive && !props.canDrop, style: {
100
+ } }, void 0) }), void 0)), props.connectDragPreview((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(Root, __assign({ "data-landing": isLandingPadActive, "data-cancel": isLandingPadActive && !props.canDrop, style: {
77
101
  opacity: isDraggedDescendant ? 0.5 : 1
78
- } }, { children: _jsxs(Flex, __assign({ align: "center" }, { children: [Handle, typeof nodeTitle === 'function' ? nodeTitle(props) : nodeTitle] }), void 0) }), void 0) }, void 0))] }), void 0));
102
+ } }, { children: (0, jsx_runtime_1.jsxs)(ui_1.Flex, __assign({ align: "center" }, { children: [Handle, typeof nodeTitle === 'function' ? nodeTitle(props) : nodeTitle] }), void 0) }), void 0) }, void 0))] }), void 0));
79
103
  };
80
- export default NodeContentRenderer;
104
+ exports.default = NodeContentRenderer;
81
105
  var templateObject_1;
@@ -1,5 +1,5 @@
1
1
  import { CardTone } from '@sanity/ui';
2
- import React from 'react';
2
+ import * as React from 'react';
3
3
  import { PlaceholderRendererProps } from 'react-sortable-tree';
4
4
  declare const PlaceholderDropzone: React.FC<{
5
5
  tone?: CardTone;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __assign = (this && this.__assign) || function () {
2
3
  __assign = Object.assign || function(t) {
3
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -9,8 +10,9 @@ var __assign = (this && this.__assign) || function () {
9
10
  };
10
11
  return __assign.apply(this, arguments);
11
12
  };
12
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
13
- import { Box, Card, Stack, Text } from '@sanity/ui';
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ var jsx_runtime_1 = require("react/jsx-runtime");
15
+ var ui_1 = require("@sanity/ui");
14
16
  var PlaceholderDropzone = function (props) {
15
17
  var isValid = props.isOver && props.canDrop;
16
18
  var isInvalid = props.isOver && !props.canDrop;
@@ -21,8 +23,8 @@ var PlaceholderDropzone = function (props) {
21
23
  if (isInvalid) {
22
24
  tone = 'caution';
23
25
  }
24
- return (_jsx(Box, __assign({ padding: 3 }, { children: _jsx(Card, __assign({ padding: 5, radius: 2, border: true, tone: tone, style: {
26
+ return ((0, jsx_runtime_1.jsx)(ui_1.Box, __assign({ padding: 3 }, { children: (0, jsx_runtime_1.jsx)(ui_1.Card, __assign({ padding: 5, radius: 2, border: true, tone: tone, style: {
25
27
  borderStyle: props.isOver ? undefined : 'dashed'
26
- } }, { children: _jsxs(Stack, __assign({ space: 2, style: { textAlign: 'center' } }, { children: [_jsxs(Text, __assign({ size: 2, as: "h2", muted: true }, { children: [!props.isOver && props.title, isValid && 'Drop here', isInvalid && 'Invalid location or element'] }), void 0), props.subtitle && _jsx(Text, __assign({ size: 1 }, { children: props.subtitle }), void 0), props.children] }), void 0) }), void 0) }), void 0));
28
+ } }, { children: (0, jsx_runtime_1.jsxs)(ui_1.Stack, __assign({ space: 2, style: { textAlign: 'center' } }, { children: [(0, jsx_runtime_1.jsxs)(ui_1.Text, __assign({ size: 2, as: "h2", muted: true }, { children: [!props.isOver && props.title, isValid && 'Drop here', isInvalid && 'Invalid location or element'] }), void 0), props.subtitle && (0, jsx_runtime_1.jsx)(ui_1.Text, __assign({ size: 1 }, { children: props.subtitle }), void 0), props.children] }), void 0) }), void 0) }), void 0));
27
29
  };
28
- export default PlaceholderDropzone;
30
+ exports.default = PlaceholderDropzone;
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import * as React from 'react';
2
2
  import { StoredTreeItem, TreeInputOptions } from '../types';
3
3
  /**
4
4
  * The loaded tree users interact with
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __assign = (this && this.__assign) || function () {
2
3
  __assign = Object.assign || function(t) {
3
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -9,46 +10,50 @@ var __assign = (this && this.__assign) || function () {
9
10
  };
10
11
  return __assign.apply(this, arguments);
11
12
  };
12
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { AddCircleIcon } from '@sanity/icons';
14
- import { Box, Button, Card, Flex, Spinner, Stack, Text, Tooltip } from '@sanity/ui';
15
- import SortableTree from 'react-sortable-tree';
16
- import getCommonTreeProps from '../utils/getCommonTreeProps';
17
- import getTreeHeight from '../utils/getTreeHeight';
18
- import { getUnaddedItems } from '../utils/treeData';
19
- import useAllItems from '../utils/useAllItems';
20
- import useLocalTree from '../utils/useLocalTree';
21
- import { TreeOperationsContext } from '../utils/useTreeOperations';
22
- import useTreeOperationsProvider from '../utils/useTreeOperationsProvider';
23
- import DocumentInNode from './DocumentInNode';
24
- import TreeEditorErrorBoundary from './TreeEditorErrorBoundary';
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ var jsx_runtime_1 = require("react/jsx-runtime");
18
+ var icons_1 = require("@sanity/icons");
19
+ var ui_1 = require("@sanity/ui");
20
+ var react_sortable_tree_1 = __importDefault(require("react-sortable-tree"));
21
+ var getCommonTreeProps_1 = __importDefault(require("../utils/getCommonTreeProps"));
22
+ var getTreeHeight_1 = __importDefault(require("../utils/getTreeHeight"));
23
+ var treeData_1 = require("../utils/treeData");
24
+ var useAllItems_1 = __importDefault(require("../hooks/useAllItems"));
25
+ var useLocalTree_1 = __importDefault(require("../hooks/useLocalTree"));
26
+ var useTreeOperations_1 = require("../hooks/useTreeOperations");
27
+ var useTreeOperationsProvider_1 = __importDefault(require("../hooks/useTreeOperationsProvider"));
28
+ var DocumentInNode_1 = __importDefault(require("./DocumentInNode"));
29
+ var TreeEditorErrorBoundary_1 = __importDefault(require("./TreeEditorErrorBoundary"));
25
30
  /**
26
31
  * The loaded tree users interact with
27
32
  */
28
33
  var TreeEditor = function (props) {
29
- var _a = useAllItems(props.options), allItemsStatus = _a.status, allItems = _a.allItems;
30
- var unaddedItems = getUnaddedItems({ tree: props.tree, allItems: allItems });
31
- var _b = useLocalTree({
34
+ var _a = (0, useAllItems_1.default)(props.options), allItemsStatus = _a.status, allItems = _a.allItems;
35
+ var unaddedItems = (0, treeData_1.getUnaddedItems)({ tree: props.tree, allItems: allItems });
36
+ var _b = (0, useLocalTree_1.default)({
32
37
  tree: props.tree,
33
38
  allItems: allItems
34
39
  }), localTree = _b.localTree, handleVisibilityToggle = _b.handleVisibilityToggle;
35
- var operations = useTreeOperationsProvider({
40
+ var operations = (0, useTreeOperationsProvider_1.default)({
36
41
  patchPrefix: props.patchPrefix,
37
42
  onChange: props.onChange,
38
43
  localTree: localTree
39
44
  });
40
- return (_jsx(TreeEditorErrorBoundary, { children: _jsx(TreeOperationsContext.Provider, __assign({ value: __assign(__assign({}, operations), { allItemsStatus: allItemsStatus }) }, { children: _jsxs(Stack, __assign({ space: 4, paddingTop: 4 }, { children: [_jsx(Card, __assign({ style: { minHeight: getTreeHeight(localTree) },
45
+ return ((0, jsx_runtime_1.jsx)(TreeEditorErrorBoundary_1.default, { children: (0, jsx_runtime_1.jsx)(useTreeOperations_1.TreeOperationsContext.Provider, __assign({ value: __assign(__assign({}, operations), { allItemsStatus: allItemsStatus }) }, { children: (0, jsx_runtime_1.jsxs)(ui_1.Stack, __assign({ space: 4, paddingTop: 4 }, { children: [(0, jsx_runtime_1.jsx)(ui_1.Card, __assign({ style: { minHeight: (0, getTreeHeight_1.default)(localTree) },
41
46
  // Only include borderBottom if there's something to show in unadded items
42
- borderBottom: allItemsStatus !== 'success' || (unaddedItems === null || unaddedItems === void 0 ? void 0 : unaddedItems.length) > 0 }, { children: _jsx(SortableTree, __assign({ maxDepth: props.options.maxDepth, onChange: function () {
47
+ borderBottom: allItemsStatus !== 'success' || (unaddedItems === null || unaddedItems === void 0 ? void 0 : unaddedItems.length) > 0 }, { children: (0, jsx_runtime_1.jsx)(react_sortable_tree_1.default, __assign({ maxDepth: props.options.maxDepth, onChange: function () {
43
48
  // Do nothing. onMoveNode will do all the work
44
49
  }, onVisibilityToggle: handleVisibilityToggle, onMoveNode: function (data) {
45
50
  return operations.handleMovedNode(data);
46
- }, treeData: localTree }, getCommonTreeProps({
51
+ }, treeData: localTree }, (0, getCommonTreeProps_1.default)({
47
52
  placeholder: {
48
53
  title: 'Add items from the list below'
49
54
  }
50
- })), void 0) }), void 0), allItemsStatus === 'success' && (unaddedItems === null || unaddedItems === void 0 ? void 0 : unaddedItems.length) > 0 && (_jsxs(Stack, __assign({ space: 1, paddingX: 2, paddingTop: 3 }, { children: [_jsxs(Stack, __assign({ space: 2, paddingX: 2, paddingBottom: 3 }, { children: [_jsx(Text, __assign({ size: 2, as: "h2", weight: "semibold" }, { children: "Add more items" }), void 0), _jsx(Text, __assign({ size: 1, muted: true }, { children: "Only published documents are shown." }), void 0)] }), void 0), unaddedItems.map(function (item) { return (_jsx(DocumentInNode, { item: item, action: _jsx(Tooltip, __assign({ portal: true, placement: "left", content: _jsx(Box, __assign({ padding: 2 }, { children: _jsx(Text, __assign({ size: 1 }, { children: "Add to list" }), void 0) }), void 0) }, { children: _jsx(Button, { onClick: function () {
55
+ })), void 0) }), void 0), allItemsStatus === 'success' && (unaddedItems === null || unaddedItems === void 0 ? void 0 : unaddedItems.length) > 0 && ((0, jsx_runtime_1.jsxs)(ui_1.Stack, __assign({ space: 1, paddingX: 2, paddingTop: 3 }, { children: [(0, jsx_runtime_1.jsxs)(ui_1.Stack, __assign({ space: 2, paddingX: 2, paddingBottom: 3 }, { children: [(0, jsx_runtime_1.jsx)(ui_1.Text, __assign({ size: 2, as: "h2", weight: "semibold" }, { children: "Add more items" }), void 0), (0, jsx_runtime_1.jsx)(ui_1.Text, __assign({ size: 1, muted: true }, { children: "Only published documents are shown." }), void 0)] }), void 0), unaddedItems.map(function (item) { return ((0, jsx_runtime_1.jsx)(DocumentInNode_1.default, { item: item, action: (0, jsx_runtime_1.jsx)(ui_1.Tooltip, __assign({ portal: true, placement: "left", content: (0, jsx_runtime_1.jsx)(ui_1.Box, __assign({ padding: 2 }, { children: (0, jsx_runtime_1.jsx)(ui_1.Text, __assign({ size: 1 }, { children: "Add to list" }), void 0) }), void 0) }, { children: (0, jsx_runtime_1.jsx)(ui_1.Button, { onClick: function () {
51
56
  operations.addItem(item);
52
- }, mode: "bleed", icon: AddCircleIcon, style: { cursor: 'pointer' } }, void 0) }), void 0) }, item.publishedId || item.draftId)); })] }), void 0)), allItemsStatus === 'loading' && (_jsx(Flex, __assign({ padding: 4, align: 'center', justify: 'center' }, { children: _jsx(Spinner, { size: 3, muted: true }, void 0) }), void 0)), allItemsStatus === 'error' && (_jsx(Flex, __assign({ padding: 4, align: 'center', justify: 'center' }, { children: _jsx(Text, __assign({ size: 2, weight: "semibold" }, { children: "Something went wrong when loading documents" }), void 0) }), void 0))] }), void 0) }), void 0) }, void 0));
57
+ }, mode: "bleed", icon: icons_1.AddCircleIcon, style: { cursor: 'pointer' } }, void 0) }), void 0) }, item.publishedId || item.draftId)); })] }), void 0)), allItemsStatus === 'loading' && ((0, jsx_runtime_1.jsx)(ui_1.Flex, __assign({ padding: 4, align: 'center', justify: 'center' }, { children: (0, jsx_runtime_1.jsx)(ui_1.Spinner, { size: 3, muted: true }, void 0) }), void 0)), allItemsStatus === 'error' && ((0, jsx_runtime_1.jsx)(ui_1.Flex, __assign({ padding: 4, align: 'center', justify: 'center' }, { children: (0, jsx_runtime_1.jsx)(ui_1.Text, __assign({ size: 2, weight: "semibold" }, { children: "Something went wrong when loading documents" }), void 0) }), void 0))] }), void 0) }), void 0) }, void 0));
53
58
  };
54
- export default TreeEditor;
59
+ exports.default = TreeEditor;
@@ -1,3 +1,3 @@
1
- import React from 'react';
1
+ import * as React from 'react';
2
2
  declare const TreeEditorErrorBoundary: React.FC;
3
3
  export default TreeEditorErrorBoundary;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __assign = (this && this.__assign) || function () {
2
3
  __assign = Object.assign || function(t) {
3
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -9,13 +10,33 @@ var __assign = (this && this.__assign) || function () {
9
10
  };
10
11
  return __assign.apply(this, arguments);
11
12
  };
12
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { ErrorBoundary, useToast } from '@sanity/ui';
14
- import React from 'react';
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ var jsx_runtime_1 = require("react/jsx-runtime");
34
+ var ui_1 = require("@sanity/ui");
35
+ var React = __importStar(require("react"));
15
36
  var DISPLAY_ERROR = false;
16
37
  var ErrorToast = function (_a) {
17
38
  var error = _a.error;
18
- var push = useToast().push;
39
+ var push = (0, ui_1.useToast)().push;
19
40
  React.useEffect(function () {
20
41
  if ((error === null || error === void 0 ? void 0 : error.error) && DISPLAY_ERROR) {
21
42
  push({
@@ -31,8 +52,8 @@ var ErrorToast = function (_a) {
31
52
  };
32
53
  var TreeEditorErrorBoundary = function (props) {
33
54
  var _a = React.useState(undefined), exception = _a[0], setException = _a[1];
34
- return (_jsxs(ErrorBoundary, __assign({ onCatch: function (newException) {
55
+ return ((0, jsx_runtime_1.jsxs)(ui_1.ErrorBoundary, __assign({ onCatch: function (newException) {
35
56
  setException(newException);
36
- } }, { children: [_jsx(ErrorToast, { error: exception }, void 0), props.children] }), void 0));
57
+ } }, { children: [(0, jsx_runtime_1.jsx)(ErrorToast, { error: exception }, void 0), props.children] }), void 0));
37
58
  };
38
- export default TreeEditorErrorBoundary;
59
+ exports.default = TreeEditorErrorBoundary;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __assign = (this && this.__assign) || function () {
2
3
  __assign = Object.assign || function(t) {
3
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -9,9 +10,32 @@ var __assign = (this && this.__assign) || function () {
9
10
  };
10
11
  return __assign.apply(this, arguments);
11
12
  };
12
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import React from 'react';
14
- import TreeNodeRendererScaffold from './TreeNodeRendererScaffold';
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ var __importDefault = (this && this.__importDefault) || function (mod) {
33
+ return (mod && mod.__esModule) ? mod : { "default": mod };
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ var jsx_runtime_1 = require("react/jsx-runtime");
37
+ var React = __importStar(require("react"));
38
+ var TreeNodeRendererScaffold_1 = __importDefault(require("./TreeNodeRendererScaffold"));
15
39
  /**
16
40
  * To prevent expand buttons from overflowing on the left, we add a minimum left padding to all entries
17
41
  */
@@ -21,7 +45,7 @@ var TreeNodeRenderer = function (props) {
21
45
  var children = props.children, lowerSiblingCounts = props.lowerSiblingCounts, connectDropTarget = props.connectDropTarget, isOver = props.isOver, draggedNode = props.draggedNode, canDrop = props.canDrop;
22
46
  // Construct the scaffold representing the structure of the tree
23
47
  var scaffoldBlockCount = lowerSiblingCounts.length;
24
- return connectDropTarget(_jsxs("div", __assign({ style: props.style }, { children: [_jsx("div", __assign({ style: {
48
+ return connectDropTarget((0, jsx_runtime_1.jsxs)("div", __assign({ style: props.style }, { children: [(0, jsx_runtime_1.jsx)("div", __assign({ style: {
25
49
  // prettier-ignore
26
50
  paddingLeft: "".concat(BASE_LEFT_PADDING + (NESTING_PADDING * scaffoldBlockCount), "px")
27
51
  } }, { children: React.Children.map(children, function (child) {
@@ -30,6 +54,6 @@ var TreeNodeRenderer = function (props) {
30
54
  canDrop: canDrop,
31
55
  draggedNode: draggedNode
32
56
  });
33
- }) }), void 0), _jsx(TreeNodeRendererScaffold, __assign({}, props), void 0)] }), void 0));
57
+ }) }), void 0), (0, jsx_runtime_1.jsx)(TreeNodeRendererScaffold_1.default, __assign({}, props), void 0)] }), void 0));
34
58
  };
35
- export default TreeNodeRenderer;
59
+ exports.default = TreeNodeRenderer;
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import * as React from 'react';
2
2
  import { TreeRendererProps } from 'react-sortable-tree';
3
3
  declare const TreeNodeRendererScaffold: React.FC<TreeRendererProps>;
4
4
  export default TreeNodeRendererScaffold;
@@ -1,12 +1,14 @@
1
+ "use strict";
1
2
  var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
3
  if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
4
  return cooked;
4
5
  };
5
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
6
- import { blue } from '@sanity/color';
7
- import { createGlobalStyle } from 'styled-components';
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ var jsx_runtime_1 = require("react/jsx-runtime");
8
+ var color_1 = require("@sanity/color");
9
+ var styled_components_1 = require("styled-components");
8
10
  // Adapted from react-sortable-tree/src/tree-node.js
9
- var ScaffoldStyles = createGlobalStyle(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n .rst__lineBlock,\n .rst__absoluteLineBlock {\n height: 100%;\n position: relative;\n display: inline-block;\n --stroke-width: 3px;\n }\n\n .rst__absoluteLineBlock {\n position: absolute;\n top: 0;\n }\n\n /* Highlight line for pointing to dragged row destination\n ========================================================================== */\n /**\n * +--+--+\n * | | |\n * | | |\n * | | |\n * +--+--+\n */\n .rst__highlightLineVertical {\n z-index: 3;\n }\n .rst__highlightLineVertical::before {\n position: absolute;\n content: '';\n background-color: ", ";\n width: calc(var(--stroke-width) * 2);\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n height: 100%;\n }\n\n @keyframes arrow-pulse {\n 0% {\n transform: translate(0, 0);\n opacity: 0;\n }\n 30% {\n transform: translate(0, 300%);\n opacity: 1;\n }\n 70% {\n transform: translate(0, 700%);\n opacity: 1;\n }\n 100% {\n transform: translate(0, 1000%);\n opacity: 0;\n }\n }\n .rst__highlightLineVertical::after {\n content: '';\n position: absolute;\n height: 0;\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n border-left: var(--stroke-width) solid transparent;\n border-right: var(--stroke-width) solid transparent;\n border-top: var(--stroke-width) solid white;\n animation: arrow-pulse 1s infinite linear both;\n }\n\n /**\n * +-----+\n * | |\n * | +--+\n * | | |\n * +--+--+\n */\n .rst__highlightTopLeftCorner::before {\n z-index: 3;\n content: '';\n position: absolute;\n border-top: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(50% + var(--stroke-width));\n top: 50%;\n margin-top: calc(var(--stroke-width) * -1);\n right: 0;\n width: calc(50% + var(--stroke-width));\n }\n\n /**\n * +--+--+\n * | | |\n * | | |\n * | +->|\n * +-----+\n */\n .rst__highlightBottomLeftCorner {\n z-index: 3;\n }\n .rst__highlightBottomLeftCorner::before {\n content: '';\n position: absolute;\n border-bottom: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(100% + var(--stroke-width));\n top: 0;\n right: calc(var(--stroke-width) * 3);\n width: calc(50% - calc(var(--stroke-width) * 2));\n }\n\n .rst__highlightBottomLeftCorner::after {\n content: '';\n position: absolute;\n height: 0;\n right: 0;\n top: 100%;\n margin-top: calc(var(--stroke-width) * -3);\n border-top: calc(var(--stroke-width) * 3) solid transparent;\n border-bottom: calc(var(--stroke-width) * 3) solid transparent;\n border-left: calc(var(--stroke-width) * 3) solid ", ";\n }\n\n .rst__unclickable {\n pointer-events: none;\n margin-top: -calc(var(--stroke-width) * 3);\n }\n"], ["\n .rst__lineBlock,\n .rst__absoluteLineBlock {\n height: 100%;\n position: relative;\n display: inline-block;\n --stroke-width: 3px;\n }\n\n .rst__absoluteLineBlock {\n position: absolute;\n top: 0;\n }\n\n /* Highlight line for pointing to dragged row destination\n ========================================================================== */\n /**\n * +--+--+\n * | | |\n * | | |\n * | | |\n * +--+--+\n */\n .rst__highlightLineVertical {\n z-index: 3;\n }\n .rst__highlightLineVertical::before {\n position: absolute;\n content: '';\n background-color: ", ";\n width: calc(var(--stroke-width) * 2);\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n height: 100%;\n }\n\n @keyframes arrow-pulse {\n 0% {\n transform: translate(0, 0);\n opacity: 0;\n }\n 30% {\n transform: translate(0, 300%);\n opacity: 1;\n }\n 70% {\n transform: translate(0, 700%);\n opacity: 1;\n }\n 100% {\n transform: translate(0, 1000%);\n opacity: 0;\n }\n }\n .rst__highlightLineVertical::after {\n content: '';\n position: absolute;\n height: 0;\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n border-left: var(--stroke-width) solid transparent;\n border-right: var(--stroke-width) solid transparent;\n border-top: var(--stroke-width) solid white;\n animation: arrow-pulse 1s infinite linear both;\n }\n\n /**\n * +-----+\n * | |\n * | +--+\n * | | |\n * +--+--+\n */\n .rst__highlightTopLeftCorner::before {\n z-index: 3;\n content: '';\n position: absolute;\n border-top: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(50% + var(--stroke-width));\n top: 50%;\n margin-top: calc(var(--stroke-width) * -1);\n right: 0;\n width: calc(50% + var(--stroke-width));\n }\n\n /**\n * +--+--+\n * | | |\n * | | |\n * | +->|\n * +-----+\n */\n .rst__highlightBottomLeftCorner {\n z-index: 3;\n }\n .rst__highlightBottomLeftCorner::before {\n content: '';\n position: absolute;\n border-bottom: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(100% + var(--stroke-width));\n top: 0;\n right: calc(var(--stroke-width) * 3);\n width: calc(50% - calc(var(--stroke-width) * 2));\n }\n\n .rst__highlightBottomLeftCorner::after {\n content: '';\n position: absolute;\n height: 0;\n right: 0;\n top: 100%;\n margin-top: calc(var(--stroke-width) * -3);\n border-top: calc(var(--stroke-width) * 3) solid transparent;\n border-bottom: calc(var(--stroke-width) * 3) solid transparent;\n border-left: calc(var(--stroke-width) * 3) solid ", ";\n }\n\n .rst__unclickable {\n pointer-events: none;\n margin-top: -calc(var(--stroke-width) * 3);\n }\n"])), blue[400].hex, blue[400].hex, blue[400].hex, blue[400].hex, blue[400].hex, blue[400].hex);
11
+ var ScaffoldStyles = (0, styled_components_1.createGlobalStyle)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n .rst__lineBlock,\n .rst__absoluteLineBlock {\n height: 100%;\n position: relative;\n display: inline-block;\n --stroke-width: 3px;\n }\n\n .rst__absoluteLineBlock {\n position: absolute;\n top: 0;\n }\n\n /* Highlight line for pointing to dragged row destination\n ========================================================================== */\n /**\n * +--+--+\n * | | |\n * | | |\n * | | |\n * +--+--+\n */\n .rst__highlightLineVertical {\n z-index: 3;\n }\n .rst__highlightLineVertical::before {\n position: absolute;\n content: '';\n background-color: ", ";\n width: calc(var(--stroke-width) * 2);\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n height: 100%;\n }\n\n @keyframes arrow-pulse {\n 0% {\n transform: translate(0, 0);\n opacity: 0;\n }\n 30% {\n transform: translate(0, 300%);\n opacity: 1;\n }\n 70% {\n transform: translate(0, 700%);\n opacity: 1;\n }\n 100% {\n transform: translate(0, 1000%);\n opacity: 0;\n }\n }\n .rst__highlightLineVertical::after {\n content: '';\n position: absolute;\n height: 0;\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n border-left: var(--stroke-width) solid transparent;\n border-right: var(--stroke-width) solid transparent;\n border-top: var(--stroke-width) solid white;\n animation: arrow-pulse 1s infinite linear both;\n }\n\n /**\n * +-----+\n * | |\n * | +--+\n * | | |\n * +--+--+\n */\n .rst__highlightTopLeftCorner::before {\n z-index: 3;\n content: '';\n position: absolute;\n border-top: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(50% + var(--stroke-width));\n top: 50%;\n margin-top: calc(var(--stroke-width) * -1);\n right: 0;\n width: calc(50% + var(--stroke-width));\n }\n\n /**\n * +--+--+\n * | | |\n * | | |\n * | +->|\n * +-----+\n */\n .rst__highlightBottomLeftCorner {\n z-index: 3;\n }\n .rst__highlightBottomLeftCorner::before {\n content: '';\n position: absolute;\n border-bottom: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(100% + var(--stroke-width));\n top: 0;\n right: calc(var(--stroke-width) * 3);\n width: calc(50% - calc(var(--stroke-width) * 2));\n }\n\n .rst__highlightBottomLeftCorner::after {\n content: '';\n position: absolute;\n height: 0;\n right: 0;\n top: 100%;\n margin-top: calc(var(--stroke-width) * -3);\n border-top: calc(var(--stroke-width) * 3) solid transparent;\n border-bottom: calc(var(--stroke-width) * 3) solid transparent;\n border-left: calc(var(--stroke-width) * 3) solid ", ";\n }\n\n .rst__unclickable {\n pointer-events: none;\n margin-top: -calc(var(--stroke-width) * 3);\n }\n"], ["\n .rst__lineBlock,\n .rst__absoluteLineBlock {\n height: 100%;\n position: relative;\n display: inline-block;\n --stroke-width: 3px;\n }\n\n .rst__absoluteLineBlock {\n position: absolute;\n top: 0;\n }\n\n /* Highlight line for pointing to dragged row destination\n ========================================================================== */\n /**\n * +--+--+\n * | | |\n * | | |\n * | | |\n * +--+--+\n */\n .rst__highlightLineVertical {\n z-index: 3;\n }\n .rst__highlightLineVertical::before {\n position: absolute;\n content: '';\n background-color: ", ";\n width: calc(var(--stroke-width) * 2);\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n height: 100%;\n }\n\n @keyframes arrow-pulse {\n 0% {\n transform: translate(0, 0);\n opacity: 0;\n }\n 30% {\n transform: translate(0, 300%);\n opacity: 1;\n }\n 70% {\n transform: translate(0, 700%);\n opacity: 1;\n }\n 100% {\n transform: translate(0, 1000%);\n opacity: 0;\n }\n }\n .rst__highlightLineVertical::after {\n content: '';\n position: absolute;\n height: 0;\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n border-left: var(--stroke-width) solid transparent;\n border-right: var(--stroke-width) solid transparent;\n border-top: var(--stroke-width) solid white;\n animation: arrow-pulse 1s infinite linear both;\n }\n\n /**\n * +-----+\n * | |\n * | +--+\n * | | |\n * +--+--+\n */\n .rst__highlightTopLeftCorner::before {\n z-index: 3;\n content: '';\n position: absolute;\n border-top: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(50% + var(--stroke-width));\n top: 50%;\n margin-top: calc(var(--stroke-width) * -1);\n right: 0;\n width: calc(50% + var(--stroke-width));\n }\n\n /**\n * +--+--+\n * | | |\n * | | |\n * | +->|\n * +-----+\n */\n .rst__highlightBottomLeftCorner {\n z-index: 3;\n }\n .rst__highlightBottomLeftCorner::before {\n content: '';\n position: absolute;\n border-bottom: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(100% + var(--stroke-width));\n top: 0;\n right: calc(var(--stroke-width) * 3);\n width: calc(50% - calc(var(--stroke-width) * 2));\n }\n\n .rst__highlightBottomLeftCorner::after {\n content: '';\n position: absolute;\n height: 0;\n right: 0;\n top: 100%;\n margin-top: calc(var(--stroke-width) * -3);\n border-top: calc(var(--stroke-width) * 3) solid transparent;\n border-bottom: calc(var(--stroke-width) * 3) solid transparent;\n border-left: calc(var(--stroke-width) * 3) solid ", ";\n }\n\n .rst__unclickable {\n pointer-events: none;\n margin-top: -calc(var(--stroke-width) * 3);\n }\n"])), color_1.blue[400].hex, color_1.blue[400].hex, color_1.blue[400].hex, color_1.blue[400].hex, color_1.blue[400].hex, color_1.blue[400].hex);
10
12
  var TreeNodeRendererScaffold = function (props) {
11
13
  var lowerSiblingCounts = props.lowerSiblingCounts, scaffoldBlockPxWidth = props.scaffoldBlockPxWidth, listIndex = props.listIndex, swapDepth = props.swapDepth, swapFrom = props.swapFrom, swapLength = props.swapLength, treeIndex = props.treeIndex;
12
14
  // Construct the scaffold representing the structure of the tree
@@ -34,9 +36,9 @@ var TreeNodeRendererScaffold = function (props) {
34
36
  width: scaffoldBlockPxWidth,
35
37
  left: scaffoldBlockPxWidth * i
36
38
  };
37
- return (_jsx("div", { style: style, className: "rst__unclickable rst__absoluteLineBlock ".concat(highlightLineClass || ''), tabIndex: -1 }, i));
39
+ return ((0, jsx_runtime_1.jsx)("div", { style: style, className: "rst__unclickable rst__absoluteLineBlock ".concat(highlightLineClass || ''), tabIndex: -1 }, i));
38
40
  });
39
- return (_jsxs(_Fragment, { children: [scaffold, _jsx(ScaffoldStyles, {}, void 0)] }, void 0));
41
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [scaffold, (0, jsx_runtime_1.jsx)(ScaffoldStyles, {}, void 0)] }, void 0));
40
42
  };
41
- export default TreeNodeRendererScaffold;
43
+ exports.default = TreeNodeRendererScaffold;
42
44
  var templateObject_1;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __assign = (this && this.__assign) || function () {
2
3
  __assign = Object.assign || function(t) {
3
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -9,41 +10,57 @@ var __assign = (this && this.__assign) || function () {
9
10
  };
10
11
  return __assign.apply(this, arguments);
11
12
  };
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- import S from '@sanity/desk-tool/structure-builder';
14
- import { AddIcon } from '@sanity/icons';
15
- import TreeDeskStructure from './TreeDeskStructure';
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ var jsx_runtime_1 = require("react/jsx-runtime");
18
+ var structure_builder_1 = __importDefault(require("@sanity/desk-tool/structure-builder"));
19
+ var icons_1 = require("@sanity/icons");
20
+ var schema_1 = __importDefault(require("part:@sanity/base/schema"));
21
+ var TreeDeskStructure_1 = __importDefault(require("./TreeDeskStructure"));
22
+ var throwError_1 = __importDefault(require("./utils/throwError"));
16
23
  var deskTreeValidator = function (props) {
17
24
  var documentId = props.documentId, referenceTo = props.referenceTo;
18
25
  if (typeof documentId !== 'string' && !documentId) {
19
- throw new Error('[hierarchical input] Please add a documentId to your tree');
26
+ (0, throwError_1.default)('invalidDocumentId');
20
27
  }
21
28
  if (!Array.isArray(referenceTo)) {
22
- throw new Error("[hierarchical input] Missing valid 'referenceTo' in createDeskHierarchy (documentId \"".concat(documentId, "\")"));
29
+ (0, throwError_1.default)('invalidReferenceTo', "(documentId \"".concat(documentId, "\")"));
23
30
  }
24
- return function (deskProps) { return _jsx(TreeDeskStructure, __assign({}, deskProps, { options: props }), void 0); };
31
+ return function (deskProps) { return (0, jsx_runtime_1.jsx)(TreeDeskStructure_1.default, __assign({}, deskProps, { options: props }), void 0); };
25
32
  };
26
- export default function createDeskHierarchy(props) {
33
+ function createDeskHierarchy(props) {
27
34
  var documentId = props.documentId, referenceTo = props.referenceTo, referenceOptions = props.referenceOptions;
28
- var mainList = ((referenceTo === null || referenceTo === void 0 ? void 0 : referenceTo.length) === 1
29
- ? S.documentTypeList(referenceTo[0]).schemaType(referenceTo[0])
30
- : S.documentList().filter('_type in $types').params({ types: referenceTo }))
35
+ // @TODO: allow creating all types once upstream desk fix is shipped
36
+ /**
37
+ * Context: With multiple referenced document types we can’t set S.documentList().schemaType(),
38
+ * which only accepts one type. So the desk doesn’t have an expanded schemaType to access and
39
+ * try creating a new document without that, which breaks resolveEnabledActions (and probably more)
40
+ * in packages\@sanity\base\src\actions\utils\legacy_documentActionUtils.js
41
+ */
42
+ var safelyCreatableTypes = referenceTo.slice(0, 1);
43
+ var mainList = ((safelyCreatableTypes === null || safelyCreatableTypes === void 0 ? void 0 : safelyCreatableTypes.length) === 1
44
+ ? structure_builder_1.default.documentTypeList(safelyCreatableTypes[0]).schemaType(safelyCreatableTypes[0])
45
+ : structure_builder_1.default.documentList().filter('_type in $types').params({ types: safelyCreatableTypes }))
31
46
  .id(documentId)
32
- .menuItems((referenceTo || []).map(function (schemaType) {
33
- return S.menuItem()
47
+ .menuItems((safelyCreatableTypes || []).map(function (schemaType) {
48
+ var _a, _b;
49
+ return structure_builder_1.default.menuItem()
34
50
  .intent({
35
51
  type: 'create',
36
- params: { type: schemaType, template: schemaType }
52
+ params: { type: schemaType }
37
53
  })
38
- // @TODO: get the title for each schema type
39
- .title(schemaType)
40
- .icon(AddIcon);
54
+ .title("Create ".concat((_a = schema_1.default.get(schemaType)) === null || _a === void 0 ? void 0 : _a.title))
55
+ .icon(((_b = schema_1.default.get(schemaType)) === null || _b === void 0 ? void 0 : _b.icon) || icons_1.AddIcon);
41
56
  }))
42
57
  .canHandleIntent(function (intent, context) {
58
+ // Can edit itself
43
59
  if (intent === 'edit' && context.id === props.documentId) {
44
60
  return true;
45
61
  }
46
- if (intent === 'create' && referenceTo.includes(context.type)) {
62
+ // Can create & edit referenced document types
63
+ if (safelyCreatableTypes.includes(context.type)) {
47
64
  return true;
48
65
  }
49
66
  return false;
@@ -54,7 +71,7 @@ export default function createDeskHierarchy(props) {
54
71
  if (referenceOptions === null || referenceOptions === void 0 ? void 0 : referenceOptions.filterParams) {
55
72
  mainList = mainList.params(referenceOptions.filterParams);
56
73
  }
57
- return S.listItem()
74
+ return structure_builder_1.default.listItem()
58
75
  .id(documentId)
59
76
  .title(props.title || documentId)
60
77
  .icon(props.icon)
@@ -65,3 +82,4 @@ export default function createDeskHierarchy(props) {
65
82
  __preserveInstance: true
66
83
  }, props.title ? { title: props.title } : {}));
67
84
  }
85
+ exports.default = createDeskHierarchy;
@@ -0,0 +1,78 @@
1
+ import { ArraySchemaType } from '@sanity/types';
2
+ import * as React from 'react';
3
+ import { TreeDeskStructureProps, TreeFieldSchema } from './types';
4
+ declare type SchemaOptions = Omit<TreeDeskStructureProps, 'documentId' | 'maxDepth'>;
5
+ export declare function createHierarchicalField({ name, title, options, ...rest }: TreeFieldSchema): Omit<ArraySchemaType, 'type' | 'jsonType' | 'of'> & {
6
+ type: string;
7
+ inputComponent: React.FC<any>;
8
+ of?: any[];
9
+ };
10
+ export default function createHierarchicalSchemas(options: SchemaOptions): ({
11
+ name: string;
12
+ title: string;
13
+ type: string;
14
+ fields: ({
15
+ name: string;
16
+ type: string;
17
+ } | {
18
+ name: string;
19
+ type: string;
20
+ title: string;
21
+ fields: ({
22
+ name: string;
23
+ type: string;
24
+ weak?: undefined;
25
+ to?: undefined;
26
+ options?: undefined;
27
+ } | {
28
+ name: string;
29
+ type: string;
30
+ weak: boolean;
31
+ to: {
32
+ type: string;
33
+ }[];
34
+ options: {
35
+ filter?: string | undefined;
36
+ filterParams?: Record<string, unknown> | undefined;
37
+ } | undefined;
38
+ })[];
39
+ })[];
40
+ } | {
41
+ name: string;
42
+ title: string;
43
+ type: string;
44
+ of: ({
45
+ name: string;
46
+ title: string;
47
+ type: string;
48
+ fields: ({
49
+ name: string;
50
+ type: string;
51
+ } | {
52
+ name: string;
53
+ type: string;
54
+ title: string;
55
+ fields: ({
56
+ name: string;
57
+ type: string;
58
+ weak?: undefined;
59
+ to?: undefined;
60
+ options?: undefined;
61
+ } | {
62
+ name: string;
63
+ type: string;
64
+ weak: boolean;
65
+ to: {
66
+ type: string;
67
+ }[];
68
+ options: {
69
+ filter?: string | undefined;
70
+ filterParams?: Record<string, unknown> | undefined;
71
+ } | undefined;
72
+ })[];
73
+ })[];
74
+ } | {
75
+ type: string;
76
+ })[];
77
+ })[];
78
+ export {};