@sanity/hierarchical-document-list 0.1.0-next.3 → 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 (59) hide show
  1. package/README.md +99 -26
  2. package/lib/TreeDeskStructure.d.ts +2 -1
  3. package/lib/TreeDeskStructure.js +82 -33
  4. package/lib/TreeInputComponent.d.ts +1 -1
  5. package/lib/TreeInputComponent.js +50 -8
  6. package/lib/components/DeskWarning.d.ts +1 -1
  7. package/lib/components/DeskWarning.js +43 -9
  8. package/lib/components/DocumentInNode.d.ts +1 -1
  9. package/lib/components/DocumentInNode.js +64 -28
  10. package/lib/components/DocumentPreviewStatus.d.ts +1 -1
  11. package/lib/components/DocumentPreviewStatus.js +36 -13
  12. package/lib/components/NodeActions.d.ts +1 -1
  13. package/lib/components/NodeActions.js +55 -18
  14. package/lib/components/NodeContentRenderer.js +75 -49
  15. package/lib/components/PlaceholderDropzone.d.ts +1 -1
  16. package/lib/components/PlaceholderDropzone.js +22 -9
  17. package/lib/components/TreeEditor.d.ts +1 -1
  18. package/lib/components/TreeEditor.js +48 -30
  19. package/lib/components/TreeEditorErrorBoundary.d.ts +2 -16
  20. package/lib/components/TreeEditorErrorBoundary.js +50 -31
  21. package/lib/components/TreeNodeRenderer.js +53 -16
  22. package/lib/components/TreeNodeRendererScaffold.d.ts +1 -1
  23. package/lib/components/TreeNodeRendererScaffold.js +19 -139
  24. package/lib/createDeskHierarchy.js +58 -27
  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/hooks/useAllItems.js +119 -0
  29. package/lib/{utils → hooks}/useLocalTree.d.ts +0 -0
  30. package/lib/hooks/useLocalTree.js +59 -0
  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 -21
  39. package/lib/utils/flatDataToTree.js +21 -9
  40. package/lib/utils/getAdjescentNodes.js +10 -6
  41. package/lib/utils/getCommonTreeProps.js +28 -10
  42. package/lib/utils/getTreeHeight.js +9 -5
  43. package/lib/utils/gradientPatchAdapter.js +26 -18
  44. package/lib/utils/idUtils.js +9 -2
  45. package/lib/utils/injectNodeTypeInPatches.d.ts +12 -0
  46. package/lib/utils/injectNodeTypeInPatches.js +58 -0
  47. package/lib/utils/moveItemInArray.js +18 -5
  48. package/lib/utils/throwError.d.ts +7 -0
  49. package/lib/utils/throwError.js +12 -0
  50. package/lib/utils/treeData.js +87 -46
  51. package/lib/utils/treePatches.js +96 -47
  52. package/package.json +1 -2
  53. package/tsconfig.json +4 -4
  54. package/lib/createHierarchicalField.d.ts +0 -8
  55. package/lib/createHierarchicalField.js +0 -36
  56. package/lib/utils/useAllItems.js +0 -92
  57. package/lib/utils/useLocalTree.js +0 -27
  58. package/lib/utils/useTreeOperations.js +0 -16
  59. package/lib/utils/useTreeOperationsProvider.js +0 -52
@@ -1,16 +1,39 @@
1
- import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { TextWithTone } from '@sanity/base/components';
3
- import { useTimeAgo } from '@sanity/base/hooks';
4
- import { EditIcon, PublishIcon } from '@sanity/icons';
5
- import { Box, Inline, Text, Tooltip } from '@sanity/ui';
6
- export function TimeAgo({ time }) {
7
- const timeAgo = useTimeAgo(time);
8
- return (_jsxs("span", { title: timeAgo, children: [timeAgo, timeAgo.toLowerCase().trim().startsWith('just now') ? '' : ' ago'] }, void 0));
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.TimeAgo = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var components_1 = require("@sanity/base/components");
17
+ var hooks_1 = require("@sanity/base/hooks");
18
+ var icons_1 = require("@sanity/icons");
19
+ var ui_1 = require("@sanity/ui");
20
+ function TimeAgo(_a) {
21
+ var time = _a.time;
22
+ var timeAgo = (0, hooks_1.useTimeAgo)(time);
23
+ return ((0, jsx_runtime_1.jsxs)("span", __assign({ title: timeAgo }, { children: [timeAgo, timeAgo.toLowerCase().trim().startsWith('just now') ? '' : ' ago'] }), void 0));
9
24
  }
10
- const PublishedStatus = ({ document }) => (_jsx(Tooltip, { portal: true, content: _jsx(Box, { padding: 2, children: _jsx(Text, { size: 1, children: document ? (_jsxs(_Fragment, { children: ["Published ", document._updatedAt && _jsx(TimeAgo, { time: document._updatedAt }, void 0)] }, void 0)) : (_jsx(_Fragment, { children: "Not published" }, void 0)) }, void 0) }, void 0), children: _jsx(TextWithTone, { tone: "positive", dimmed: !document, muted: !document, size: 1, children: _jsx(PublishIcon, {}, void 0) }, void 0) }, void 0));
11
- const DraftStatus = ({ document }) => (_jsx(Tooltip, { portal: true, content: _jsx(Box, { padding: 2, children: _jsx(Text, { size: 1, children: document ? (_jsxs(_Fragment, { children: ["Edited ", document?._updatedAt && _jsx(TimeAgo, { time: document?._updatedAt }, void 0)] }, void 0)) : (_jsx(_Fragment, { children: "No unpublished edits" }, void 0)) }, void 0) }, void 0), children: _jsx(TextWithTone, { tone: "caution", dimmed: !document, muted: !document, size: 1, children: _jsx(EditIcon, {}, void 0) }, void 0) }, void 0));
25
+ exports.TimeAgo = TimeAgo;
26
+ var PublishedStatus = function (_a) {
27
+ var document = _a.document;
28
+ return ((0, jsx_runtime_1.jsx)(ui_1.Tooltip, __assign({ portal: true, 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: document ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Published ", document._updatedAt && (0, jsx_runtime_1.jsx)(TimeAgo, { time: document._updatedAt }, void 0)] }, void 0)) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: "Not published" }, void 0)) }), void 0) }), void 0) }, { children: (0, jsx_runtime_1.jsx)(components_1.TextWithTone, __assign({ tone: "positive", dimmed: !document, muted: !document, size: 1 }, { children: (0, jsx_runtime_1.jsx)(icons_1.PublishIcon, {}, void 0) }), void 0) }), void 0));
29
+ };
30
+ var DraftStatus = function (_a) {
31
+ var document = _a.document;
32
+ return ((0, jsx_runtime_1.jsx)(ui_1.Tooltip, __assign({ portal: true, 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: document ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Edited ", (document === null || document === void 0 ? void 0 : document._updatedAt) && (0, jsx_runtime_1.jsx)(TimeAgo, { time: document === null || document === void 0 ? void 0 : document._updatedAt }, void 0)] }, void 0)) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: "No unpublished edits" }, void 0)) }), void 0) }), void 0) }, { children: (0, jsx_runtime_1.jsx)(components_1.TextWithTone, __assign({ tone: "caution", dimmed: !document, muted: !document, size: 1 }, { children: (0, jsx_runtime_1.jsx)(icons_1.EditIcon, {}, void 0) }), void 0) }), void 0));
33
+ };
12
34
  // Adapted from @sanity\desk-tool\src\components\paneItem\helpers.tsx
13
- const DocumentPreviewStatus = ({ draft, published }) => {
14
- return (_jsxs(Inline, { space: 4, children: [_jsx(PublishedStatus, { document: published }, void 0), _jsx(DraftStatus, { document: draft }, void 0)] }, void 0));
35
+ var DocumentPreviewStatus = function (_a) {
36
+ var draft = _a.draft, published = _a.published;
37
+ return ((0, jsx_runtime_1.jsxs)(ui_1.Inline, __assign({ space: 4 }, { children: [(0, jsx_runtime_1.jsx)(PublishedStatus, { document: published }, void 0), (0, jsx_runtime_1.jsx)(DraftStatus, { document: draft }, void 0)] }), void 0));
15
38
  };
16
- export default DocumentPreviewStatus;
39
+ exports.default = DocumentPreviewStatus;
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import * as React from 'react';
2
2
  import { NodeProps } from '../types';
3
3
  /**
4
4
  * Applicable only to nodes inside the main tree.
@@ -1,24 +1,61 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { IntentLink } from '@sanity/base/components';
3
- import { CopyIcon, EllipsisVerticalIcon, LaunchIcon, RemoveCircleIcon } from '@sanity/icons';
4
- import { Button, Menu, MenuButton, MenuDivider, MenuItem } from '@sanity/ui';
5
- import React from 'react';
6
- import useTreeOperations from '../utils/useTreeOperations';
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
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 components_1 = require("@sanity/base/components");
38
+ var icons_1 = require("@sanity/icons");
39
+ var ui_1 = require("@sanity/ui");
40
+ var React = __importStar(require("react"));
41
+ var useTreeOperations_1 = __importDefault(require("../hooks/useTreeOperations"));
7
42
  /**
8
43
  * Applicable only to nodes inside the main tree.
9
44
  * Unadded items have their actions defined in TreeEditor.
10
45
  */
11
- const NodeActions = ({ nodeProps }) => {
12
- const operations = useTreeOperations();
13
- const { node } = nodeProps;
14
- const { reference, docType } = node?.value || {};
46
+ var NodeActions = function (_a) {
47
+ var nodeProps = _a.nodeProps;
48
+ var operations = (0, useTreeOperations_1.default)();
49
+ var node = nodeProps.node;
50
+ var _b = (node === null || node === void 0 ? void 0 : node.value) || {}, reference = _b.reference, docType = _b.docType;
15
51
  // Adapted from @sanity\form-builder\src\inputs\ReferenceInput\ArrayItemReferenceInput.tsx
16
- const OpenLink = React.useMemo(() =>
17
- // eslint-disable-next-line @typescript-eslint/no-shadow
18
- React.forwardRef(function OpenLinkInner(restProps, _ref) {
19
- return (_jsx(IntentLink, { ...restProps, intent: "edit", params: { id: reference?._ref, type: docType }, target: "_blank", rel: "noopener noreferrer", ref: _ref }, void 0));
20
- }), [reference?._ref, docType]);
21
- const isValid = !!node.publishedId;
22
- return (_jsx(MenuButton, { button: _jsx(Button, { padding: 2, mode: "bleed", icon: EllipsisVerticalIcon }, void 0), id: `hiearchical-doc-list--${node._key}-menuButton`, menu: _jsxs(Menu, { children: [_jsx(MenuItem, { text: "Remove from list", tone: "critical", icon: RemoveCircleIcon, onClick: () => operations.removeItem(nodeProps) }, void 0), _jsx(MenuItem, { text: "Duplicate item", icon: CopyIcon, disabled: !isValid, onClick: () => operations.duplicateItem(nodeProps) }, void 0), _jsx(MenuDivider, {}, void 0), _jsx(MenuItem, { text: "Open in new tab", icon: LaunchIcon, disabled: !isValid, as: OpenLink, "data-as": "a" }, void 0)] }, void 0), placement: "right", popover: { portal: true, tone: 'default' } }, void 0));
52
+ var OpenLink = React.useMemo(function () {
53
+ // eslint-disable-next-line @typescript-eslint/no-shadow
54
+ return React.forwardRef(function OpenLinkInner(restProps, _ref) {
55
+ return ((0, jsx_runtime_1.jsx)(components_1.IntentLink, __assign({}, restProps, { intent: "edit", params: { id: reference === null || reference === void 0 ? void 0 : reference._ref, type: docType }, target: "_blank", rel: "noopener noreferrer", ref: _ref }), void 0));
56
+ });
57
+ }, [reference === null || reference === void 0 ? void 0 : reference._ref, docType]);
58
+ var isValid = !!node.publishedId;
59
+ return ((0, jsx_runtime_1.jsx)(ui_1.MenuButton, { button: (0, jsx_runtime_1.jsx)(ui_1.Button, { padding: 2, mode: "bleed", icon: icons_1.EllipsisVerticalIcon }, void 0), id: "hiearchical-doc-list--".concat(node._key, "-menuButton"), menu: (0, jsx_runtime_1.jsxs)(ui_1.Menu, { children: [(0, jsx_runtime_1.jsx)(ui_1.MenuItem, { text: "Remove from list", tone: "critical", icon: icons_1.RemoveCircleIcon, onClick: function () { return operations.removeItem(nodeProps); } }, void 0), (0, jsx_runtime_1.jsx)(ui_1.MenuItem, { text: "Duplicate item", icon: icons_1.CopyIcon, disabled: !isValid, onClick: function () { return operations.duplicateItem(nodeProps); } }, void 0), (0, jsx_runtime_1.jsx)(ui_1.MenuDivider, {}, void 0), (0, jsx_runtime_1.jsx)(ui_1.MenuItem, { text: "Open in new tab", icon: icons_1.LaunchIcon, disabled: !isValid, as: OpenLink, "data-as": "a" }, void 0)] }, void 0), placement: "right", popover: { portal: true, tone: 'default' } }, void 0));
23
60
  };
24
- export default NodeActions;
61
+ exports.default = NodeActions;
@@ -1,55 +1,77 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { cyan, gray, red } from '@sanity/color';
3
- import { ChevronDownIcon, ChevronRightIcon, DragHandleIcon } from '@sanity/icons';
4
- import { Box, Button, Flex, Spinner } from '@sanity/ui';
5
- import React from 'react';
6
- import { isDescendant } from 'react-sortable-tree';
7
- import styled from 'styled-components';
8
- const Root = styled.div `
9
- // Adapted from react-sortable-tree/style.css
10
- &[data-landing='true'] > *,
11
- &[data-cancel='true'] > * {
12
- opacity: 0 !important;
13
- }
14
- &[data-landing='true']::before,
15
- &[data-cancel='true']::before {
16
- background-color: ${cyan[50].hex};
17
- border: 2px dashed ${gray[400].hex};
18
- border-radius: 3px;
19
- content: '';
20
- position: absolute;
21
- top: 0;
22
- right: 0;
23
- bottom: 0;
24
- left: 0;
25
- z-index: -1;
26
- }
27
-
28
- &[data-cancel='true']::before {
29
- background-color: ${red[50].hex};
30
- }
31
- `;
1
+ "use strict";
2
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
+ return cooked;
5
+ };
6
+ var __assign = (this && this.__assign) || function () {
7
+ __assign = Object.assign || function(t) {
8
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
9
+ s = arguments[i];
10
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
11
+ t[p] = s[p];
12
+ }
13
+ return t;
14
+ };
15
+ return __assign.apply(this, arguments);
16
+ };
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"
48
+ /**
49
+ * Customization of react-sortable-tree's default node.
50
+ * Created in order to use Sanity UI for styles.
51
+ * Reference: https://github.com/frontend-collective/react-sortable-tree/blob/master/src/node-renderer-default.js
52
+ */
53
+ ])), color_1.cyan[50].hex, color_1.gray[400].hex, color_1.red[50].hex);
32
54
  /**
33
55
  * Customization of react-sortable-tree's default node.
34
56
  * Created in order to use Sanity UI for styles.
35
57
  * Reference: https://github.com/frontend-collective/react-sortable-tree/blob/master/src/node-renderer-default.js
36
58
  */
37
- const NodeContentRenderer = (props) => {
38
- const { node, path, treeIndex, canDrag = false } = props;
39
- const nodeTitle = node.title;
40
- const Handle = React.useMemo(() => {
59
+ var NodeContentRenderer = function (props) {
60
+ var node = props.node, path = props.path, treeIndex = props.treeIndex, _a = props.canDrag, canDrag = _a === void 0 ? false : _a;
61
+ var nodeTitle = node.title;
62
+ var Handle = React.useMemo(function () {
41
63
  if (!canDrag) {
42
64
  return null;
43
65
  }
44
66
  if (typeof node.children === 'function' && node.expanded) {
45
67
  // Show a loading symbol on the handle when the children are expanded
46
68
  // and yet still defined by a function (a callback to fetch the children)
47
- return _jsx(Spinner, {}, void 0);
69
+ return (0, jsx_runtime_1.jsx)(ui_1.Spinner, {}, void 0);
48
70
  }
49
- const BtnElement = (_jsx("div", { children: _jsx(Button, { 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: {
50
72
  cursor: node.publishedId ? 'grab' : 'default',
51
73
  fontSize: '1.5625rem'
52
- }, "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));
53
75
  // Don't allow editors to drag invalid documents
54
76
  if (!node.publishedId) {
55
77
  return BtnElement;
@@ -59,21 +81,25 @@ const NodeContentRenderer = (props) => {
59
81
  dropEffect: 'copy'
60
82
  });
61
83
  }, [canDrag, node, typeof node.children === 'function']);
62
- const isDraggedDescendant = props.draggedNode && isDescendant(props.draggedNode, node);
63
- const isLandingPadActive = !props.didDrop && props.isDragging;
64
- return (_jsxs(Box, { style: { position: 'relative' }, children: [props.toggleChildrenVisibility &&
84
+ var isDraggedDescendant = props.draggedNode && (0, react_sortable_tree_1.isDescendant)(props.draggedNode, node);
85
+ var isLandingPadActive = !props.didDrop && props.isDragging;
86
+ return ((0, jsx_runtime_1.jsxs)(ui_1.Box, __assign({ style: { position: 'relative' } }, { children: [props.toggleChildrenVisibility &&
65
87
  node.children &&
66
- (node.children.length > 0 || typeof node.children === 'function') && (_jsx("div", { style: {
88
+ (node.children.length > 0 || typeof node.children === 'function') && ((0, jsx_runtime_1.jsx)("div", __assign({ style: {
67
89
  position: 'absolute',
68
90
  left: '-2px',
69
91
  top: '40%',
70
92
  transform: 'translate(-100%, -50%)'
71
- }, 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: () => props.toggleChildrenVisibility?.({
72
- node,
73
- path,
74
- treeIndex
75
- }) }, void 0) }, void 0)), props.connectDragPreview(_jsx("div", { children: _jsx(Root, { "data-landing": isLandingPadActive, "data-cancel": isLandingPadActive && !props.canDrop, style: {
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 () {
94
+ var _a;
95
+ return (_a = props.toggleChildrenVisibility) === null || _a === void 0 ? void 0 : _a.call(props, {
96
+ node: node,
97
+ path: path,
98
+ treeIndex: treeIndex
99
+ });
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: {
76
101
  opacity: isDraggedDescendant ? 0.5 : 1
77
- }, children: _jsxs(Flex, { 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));
78
103
  };
79
- export default NodeContentRenderer;
104
+ exports.default = NodeContentRenderer;
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,17 +1,30 @@
1
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
- import { Box, Card, Stack, Text } from '@sanity/ui';
3
- const PlaceholderDropzone = (props) => {
4
- const isValid = props.isOver && props.canDrop;
5
- const isInvalid = props.isOver && !props.canDrop;
6
- let tone = 'transparent';
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ var jsx_runtime_1 = require("react/jsx-runtime");
15
+ var ui_1 = require("@sanity/ui");
16
+ var PlaceholderDropzone = function (props) {
17
+ var isValid = props.isOver && props.canDrop;
18
+ var isInvalid = props.isOver && !props.canDrop;
19
+ var tone = 'transparent';
7
20
  if (isValid) {
8
21
  tone = 'positive';
9
22
  }
10
23
  if (isInvalid) {
11
24
  tone = 'caution';
12
25
  }
13
- return (_jsx(Box, { padding: 3, children: _jsx(Card, { 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: {
14
27
  borderStyle: props.isOver ? undefined : 'dashed'
15
- }, children: _jsxs(Stack, { space: 2, style: { textAlign: 'center' }, children: [_jsxs(Text, { 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, { 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));
16
29
  };
17
- 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,41 +1,59 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { AddCircleIcon } from '@sanity/icons';
3
- import { Box, Button, Card, Flex, Spinner, Stack, Text, Tooltip } from '@sanity/ui';
4
- import SortableTree from 'react-sortable-tree';
5
- import getCommonTreeProps from '../utils/getCommonTreeProps';
6
- import getTreeHeight from '../utils/getTreeHeight';
7
- import { getUnaddedItems } from '../utils/treeData';
8
- import useAllItems from '../utils/useAllItems';
9
- import useLocalTree from '../utils/useLocalTree';
10
- import { TreeOperationsContext } from '../utils/useTreeOperations';
11
- import useTreeOperationsProvider from '../utils/useTreeOperationsProvider';
12
- import DocumentInNode from './DocumentInNode';
13
- import TreeEditorErrorBoundary from './TreeEditorErrorBoundary';
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
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"));
14
30
  /**
15
31
  * The loaded tree users interact with
16
32
  */
17
- const TreeEditor = (props) => {
18
- const { status: allItemsStatus, allItems } = useAllItems(props.options);
19
- const unaddedItems = getUnaddedItems({ tree: props.tree, allItems });
20
- const { localTree, handleVisibilityToggle } = useLocalTree({
33
+ var TreeEditor = function (props) {
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)({
21
37
  tree: props.tree,
22
- allItems
23
- });
24
- const operations = useTreeOperationsProvider({
38
+ allItems: allItems
39
+ }), localTree = _b.localTree, handleVisibilityToggle = _b.handleVisibilityToggle;
40
+ var operations = (0, useTreeOperationsProvider_1.default)({
25
41
  patchPrefix: props.patchPrefix,
26
42
  onChange: props.onChange,
27
- localTree
43
+ localTree: localTree
28
44
  });
29
- return (_jsx(TreeEditorErrorBoundary, { children: _jsx(TreeOperationsContext.Provider, { value: { ...operations, allItemsStatus }, children: _jsxs(Stack, { space: 4, paddingTop: 4, children: [_jsx(Card, { 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) },
30
46
  // Only include borderBottom if there's something to show in unadded items
31
- borderBottom: allItemsStatus !== 'success' || unaddedItems?.length > 0, children: _jsx(SortableTree, { maxDepth: props.options.maxDepth, onChange: () => {
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 () {
32
48
  // Do nothing. onMoveNode will do all the work
33
- }, onVisibilityToggle: handleVisibilityToggle, onMoveNode: (data) => operations.handleMovedNode(data), treeData: localTree, ...getCommonTreeProps({
34
- placeholder: {
35
- title: 'Add items from the list below'
36
- }
37
- }) }, void 0) }, void 0), allItemsStatus === 'success' && unaddedItems?.length > 0 && (_jsxs(Stack, { space: 1, paddingX: 2, paddingTop: 3, children: [_jsxs(Stack, { space: 2, paddingX: 2, paddingBottom: 3, children: [_jsx(Text, { size: 2, as: "h2", weight: "semibold", children: "Add more items" }, void 0), _jsx(Text, { size: 1, muted: true, children: "Only published documents are shown." }, void 0)] }, void 0), unaddedItems.map((item) => (_jsx(DocumentInNode, { item: item, action: _jsx(Tooltip, { portal: true, placement: "left", content: _jsx(Box, { padding: 2, children: _jsx(Text, { size: 1, children: "Add to list" }, void 0) }, void 0), children: _jsx(Button, { onClick: () => {
49
+ }, onVisibilityToggle: handleVisibilityToggle, onMoveNode: function (data) {
50
+ return operations.handleMovedNode(data);
51
+ }, treeData: localTree }, (0, getCommonTreeProps_1.default)({
52
+ placeholder: {
53
+ title: 'Add items from the list below'
54
+ }
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 () {
38
56
  operations.addItem(item);
39
- }, mode: "bleed", icon: AddCircleIcon, style: { cursor: 'pointer' } }, void 0) }, void 0) }, item.publishedId || item.draftId)))] }, void 0)), allItemsStatus === 'loading' && (_jsx(Flex, { padding: 4, align: 'center', justify: 'center', children: _jsx(Spinner, { size: 3, muted: true }, void 0) }, void 0)), allItemsStatus === 'error' && (_jsx(Flex, { padding: 4, align: 'center', justify: 'center', children: _jsx(Text, { 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));
40
58
  };
41
- export default TreeEditor;
59
+ exports.default = TreeEditor;
@@ -1,17 +1,3 @@
1
- import React from 'react';
2
- interface ErrorInfo {
3
- title: string;
4
- description?: string;
5
- }
6
- declare class TreeEditorErrorBoundary extends React.Component<any, {
7
- error?: ErrorInfo;
8
- }> {
9
- constructor(props: any);
10
- static getDerivedStateFromError(error: unknown): {
11
- error: undefined;
12
- } | {
13
- error: ErrorInfo;
14
- };
15
- render(): JSX.Element;
16
- }
1
+ import * as React from 'react';
2
+ declare const TreeEditorErrorBoundary: React.FC;
17
3
  export default TreeEditorErrorBoundary;
@@ -1,13 +1,47 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useToast } from '@sanity/ui';
3
- import React from 'react';
4
- const ErrorToast = ({ error }) => {
5
- const { push } = useToast();
6
- React.useEffect(() => {
7
- if (error?.title) {
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
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"));
36
+ var DISPLAY_ERROR = false;
37
+ var ErrorToast = function (_a) {
38
+ var error = _a.error;
39
+ var push = (0, ui_1.useToast)().push;
40
+ React.useEffect(function () {
41
+ if ((error === null || error === void 0 ? void 0 : error.error) && DISPLAY_ERROR) {
8
42
  push({
9
- title: error.title,
10
- description: error.description,
43
+ title: error.error.name,
44
+ description: error.error.message,
11
45
  closable: true,
12
46
  status: 'error',
13
47
  id: 'hierarchical-error'
@@ -16,25 +50,10 @@ const ErrorToast = ({ error }) => {
16
50
  }, [error]);
17
51
  return null;
18
52
  };
19
- class TreeEditorErrorBoundary extends React.Component {
20
- constructor(props) {
21
- super(props);
22
- this.state = { error: undefined };
23
- }
24
- static getDerivedStateFromError(error) {
25
- if (!error) {
26
- return {
27
- error: undefined
28
- };
29
- }
30
- return {
31
- error: {
32
- title: 'Something went wrong'
33
- }
34
- };
35
- }
36
- render() {
37
- return (_jsxs(React.Fragment, { children: [_jsx(ErrorToast, { error: this.state.error }, void 0), this.props.children] }, void 0));
38
- }
39
- }
40
- export default TreeEditorErrorBoundary;
53
+ var TreeEditorErrorBoundary = function (props) {
54
+ var _a = React.useState(undefined), exception = _a[0], setException = _a[1];
55
+ return ((0, jsx_runtime_1.jsxs)(ui_1.ErrorBoundary, __assign({ onCatch: function (newException) {
56
+ setException(newException);
57
+ } }, { children: [(0, jsx_runtime_1.jsx)(ErrorToast, { error: exception }, void 0), props.children] }), void 0));
58
+ };
59
+ exports.default = TreeEditorErrorBoundary;