@sanity/hierarchical-document-list 0.1.0 → 1.1.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 (85) hide show
  1. package/.husky/commit-msg +4 -0
  2. package/.husky/pre-commit +4 -0
  3. package/.idea/hierarchical-document-list.iml +11 -0
  4. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  5. package/.idea/misc.xml +6 -0
  6. package/.idea/modules.xml +8 -0
  7. package/.idea/prettier.xml +7 -0
  8. package/.idea/vcs.xml +6 -0
  9. package/CHANGELOG.md +15 -0
  10. package/README.md +329 -224
  11. package/commitlint.config.js +3 -0
  12. package/lib/TreeDeskStructure.d.ts +8 -7
  13. package/lib/TreeDeskStructure.js +96 -71
  14. package/lib/TreeInputComponent.d.ts +19 -19
  15. package/lib/TreeInputComponent.js +50 -21
  16. package/lib/components/DeskWarning.d.ts +6 -6
  17. package/lib/components/DeskWarning.js +46 -25
  18. package/lib/components/DocumentInNode.d.ts +11 -11
  19. package/lib/components/DocumentInNode.js +81 -58
  20. package/lib/components/DocumentPreviewStatus.d.ts +7 -7
  21. package/lib/components/DocumentPreviewStatus.js +39 -35
  22. package/lib/components/NodeActions.d.ts +10 -10
  23. package/lib/components/NodeActions.js +61 -37
  24. package/lib/components/NodeContentRenderer.d.ts +8 -8
  25. package/lib/components/NodeContentRenderer.js +105 -81
  26. package/lib/components/PlaceholderDropzone.d.ts +9 -9
  27. package/lib/components/PlaceholderDropzone.js +30 -28
  28. package/lib/components/SuppressedDnDManager.d.ts +2 -0
  29. package/lib/components/SuppressedDnDManager.js +59 -0
  30. package/lib/components/TreeEditor.d.ts +12 -12
  31. package/lib/components/TreeEditor.js +74 -54
  32. package/lib/components/TreeEditorErrorBoundary.d.ts +16 -17
  33. package/lib/components/TreeEditorErrorBoundary.js +74 -69
  34. package/lib/components/TreeNodeRenderer.d.ts +3 -3
  35. package/lib/components/TreeNodeRenderer.js +59 -35
  36. package/lib/components/TreeNodeRendererScaffold.d.ts +4 -4
  37. package/lib/components/TreeNodeRendererScaffold.js +44 -42
  38. package/lib/createDeskHierarchy.d.ts +14 -14
  39. package/lib/createDeskHierarchy.js +84 -67
  40. package/lib/createHierarchicalSchemas.d.ts +98 -0
  41. package/lib/createHierarchicalSchemas.js +138 -0
  42. package/lib/{utils → hooks}/useAllItems.d.ts +7 -7
  43. package/lib/{utils → hooks}/useAllItems.js +119 -94
  44. package/lib/{utils → hooks}/useLocalTree.d.ts +17 -17
  45. package/lib/{utils → hooks}/useLocalTree.js +59 -37
  46. package/lib/{utils → hooks}/useTreeOperations.d.ts +9 -9
  47. package/lib/hooks/useTreeOperations.js +39 -0
  48. package/lib/{utils → hooks}/useTreeOperationsProvider.d.ts +14 -14
  49. package/lib/hooks/useTreeOperationsProvider.js +85 -0
  50. package/lib/index.d.ts +3 -3
  51. package/lib/index.js +12 -3
  52. package/lib/schemas/hierarchy.tree.d.ts +13 -23
  53. package/lib/schemas/hierarchy.tree.js +19 -31
  54. package/lib/types.d.ts +128 -0
  55. package/lib/types.js +2 -0
  56. package/lib/utils/flatDataToTree.d.ts +6 -6
  57. package/lib/utils/flatDataToTree.js +26 -23
  58. package/lib/utils/getAdjescentNodes.d.ts +12 -12
  59. package/lib/utils/getAdjescentNodes.js +19 -16
  60. package/lib/utils/getCommonTreeProps.d.ts +7 -7
  61. package/lib/utils/getCommonTreeProps.js +33 -27
  62. package/lib/utils/getTreeHeight.d.ts +3 -3
  63. package/lib/utils/getTreeHeight.js +11 -7
  64. package/lib/utils/gradientPatchAdapter.d.ts +4 -4
  65. package/lib/utils/gradientPatchAdapter.js +40 -35
  66. package/lib/utils/idUtils.d.ts +2 -2
  67. package/lib/utils/idUtils.js +13 -8
  68. package/lib/utils/injectNodeTypeInPatches.d.ts +12 -0
  69. package/lib/utils/injectNodeTypeInPatches.js +59 -0
  70. package/lib/utils/moveItemInArray.d.ts +5 -5
  71. package/lib/utils/moveItemInArray.js +26 -23
  72. package/lib/utils/throwError.d.ts +7 -0
  73. package/lib/utils/throwError.js +12 -0
  74. package/lib/utils/treeData.d.ts +18 -18
  75. package/lib/utils/treeData.js +118 -106
  76. package/lib/utils/treePatches.d.ts +15 -15
  77. package/lib/utils/treePatches.js +171 -141
  78. package/lint-staged.config.js +4 -0
  79. package/package.json +65 -56
  80. package/sanity.json +12 -12
  81. package/tsconfig.json +20 -20
  82. package/lib/createHierarchicalField.d.ts +0 -8
  83. package/lib/createHierarchicalField.js +0 -51
  84. package/lib/utils/useTreeOperations.js +0 -16
  85. package/lib/utils/useTreeOperationsProvider.js +0 -60
@@ -1,35 +1,39 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
13
- import { TextWithTone } from '@sanity/base/components';
14
- import { useTimeAgo } from '@sanity/base/hooks';
15
- import { EditIcon, PublishIcon } from '@sanity/icons';
16
- import { Box, Inline, Text, Tooltip } from '@sanity/ui';
17
- export function TimeAgo(_a) {
18
- var time = _a.time;
19
- var timeAgo = useTimeAgo(time);
20
- return (_jsxs("span", __assign({ title: timeAgo }, { children: [timeAgo, timeAgo.toLowerCase().trim().startsWith('just now') ? '' : ' ago'] }), void 0));
21
- }
22
- var PublishedStatus = function (_a) {
23
- var document = _a.document;
24
- return (_jsx(Tooltip, __assign({ portal: true, content: _jsx(Box, __assign({ padding: 2 }, { children: _jsx(Text, __assign({ 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, __assign({ tone: "positive", dimmed: !document, muted: !document, size: 1 }, { children: _jsx(PublishIcon, {}, void 0) }), void 0) }), void 0));
25
- };
26
- var DraftStatus = function (_a) {
27
- var document = _a.document;
28
- return (_jsx(Tooltip, __assign({ portal: true, content: _jsx(Box, __assign({ padding: 2 }, { children: _jsx(Text, __assign({ size: 1 }, { children: document ? (_jsxs(_Fragment, { children: ["Edited ", (document === null || document === void 0 ? void 0 : document._updatedAt) && _jsx(TimeAgo, { time: document === null || document === void 0 ? void 0 : document._updatedAt }, void 0)] }, void 0)) : (_jsx(_Fragment, { children: "No unpublished edits" }, void 0)) }), void 0) }), void 0) }, { children: _jsx(TextWithTone, __assign({ tone: "caution", dimmed: !document, muted: !document, size: 1 }, { children: _jsx(EditIcon, {}, void 0) }), void 0) }), void 0));
29
- };
30
- // Adapted from @sanity\desk-tool\src\components\paneItem\helpers.tsx
31
- var DocumentPreviewStatus = function (_a) {
32
- var draft = _a.draft, published = _a.published;
33
- return (_jsxs(Inline, __assign({ space: 4 }, { children: [_jsx(PublishedStatus, { document: published }, void 0), _jsx(DraftStatus, { document: draft }, void 0)] }), void 0));
34
- };
35
- export default DocumentPreviewStatus;
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));
24
+ }
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
+ };
34
+ // Adapted from @sanity\desk-tool\src\components\paneItem\helpers.tsx
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));
38
+ };
39
+ exports.default = DocumentPreviewStatus;
@@ -1,10 +1,10 @@
1
- import React from 'react';
2
- import { NodeProps } from '../types';
3
- /**
4
- * Applicable only to nodes inside the main tree.
5
- * Unadded items have their actions defined in TreeEditor.
6
- */
7
- declare const NodeActions: React.FC<{
8
- nodeProps: NodeProps;
9
- }>;
10
- export default NodeActions;
1
+ import * as React from 'react';
2
+ import { NodeProps } from '../types';
3
+ /**
4
+ * Applicable only to nodes inside the main tree.
5
+ * Unadded items have their actions defined in TreeEditor.
6
+ */
7
+ declare const NodeActions: React.FC<{
8
+ nodeProps: NodeProps;
9
+ }>;
10
+ export default NodeActions;
@@ -1,37 +1,61 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { IntentLink } from '@sanity/base/components';
14
- import { CopyIcon, EllipsisVerticalIcon, LaunchIcon, RemoveCircleIcon } from '@sanity/icons';
15
- import { Button, Menu, MenuButton, MenuDivider, MenuItem } from '@sanity/ui';
16
- import React from 'react';
17
- import useTreeOperations from '../utils/useTreeOperations';
18
- /**
19
- * Applicable only to nodes inside the main tree.
20
- * Unadded items have their actions defined in TreeEditor.
21
- */
22
- var NodeActions = function (_a) {
23
- var nodeProps = _a.nodeProps;
24
- var operations = useTreeOperations();
25
- var node = nodeProps.node;
26
- var _b = (node === null || node === void 0 ? void 0 : node.value) || {}, reference = _b.reference, docType = _b.docType;
27
- // Adapted from @sanity\form-builder\src\inputs\ReferenceInput\ArrayItemReferenceInput.tsx
28
- var OpenLink = React.useMemo(function () {
29
- // eslint-disable-next-line @typescript-eslint/no-shadow
30
- return React.forwardRef(function OpenLinkInner(restProps, _ref) {
31
- return (_jsx(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));
32
- });
33
- }, [reference === null || reference === void 0 ? void 0 : reference._ref, docType]);
34
- var isValid = !!node.publishedId;
35
- return (_jsx(MenuButton, { button: _jsx(Button, { padding: 2, mode: "bleed", icon: EllipsisVerticalIcon }, void 0), id: "hiearchical-doc-list--".concat(node._key, "-menuButton"), menu: _jsxs(Menu, { children: [_jsx(MenuItem, { text: "Remove from list", tone: "critical", icon: RemoveCircleIcon, onClick: function () { return operations.removeItem(nodeProps); } }, void 0), _jsx(MenuItem, { text: "Duplicate item", icon: CopyIcon, disabled: !isValid, onClick: function () { return 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));
36
- };
37
- export default NodeActions;
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"));
42
+ /**
43
+ * Applicable only to nodes inside the main tree.
44
+ * Unadded items have their actions defined in TreeEditor.
45
+ */
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;
51
+ // Adapted from @sanity\form-builder\src\inputs\ReferenceInput\ArrayItemReferenceInput.tsx
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));
60
+ };
61
+ exports.default = NodeActions;
@@ -1,8 +1,8 @@
1
- import { NodeRenderer } from 'react-sortable-tree';
2
- /**
3
- * Customization of react-sortable-tree's default node.
4
- * Created in order to use Sanity UI for styles.
5
- * Reference: https://github.com/frontend-collective/react-sortable-tree/blob/master/src/node-renderer-default.js
6
- */
7
- declare const NodeContentRenderer: NodeRenderer;
8
- export default NodeContentRenderer;
1
+ import { NodeRenderer } from 'react-sortable-tree';
2
+ /**
3
+ * Customization of react-sortable-tree's default node.
4
+ * Created in order to use Sanity UI for styles.
5
+ * Reference: https://github.com/frontend-collective/react-sortable-tree/blob/master/src/node-renderer-default.js
6
+ */
7
+ declare const NodeContentRenderer: NodeRenderer;
8
+ export default NodeContentRenderer;
@@ -1,81 +1,105 @@
1
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
- return cooked;
4
- };
5
- var __assign = (this && this.__assign) || function () {
6
- __assign = Object.assign || function(t) {
7
- for (var s, i = 1, n = arguments.length; i < n; i++) {
8
- s = arguments[i];
9
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10
- t[p] = s[p];
11
- }
12
- return t;
13
- };
14
- return __assign.apply(this, arguments);
15
- };
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"
24
- /**
25
- * Customization of react-sortable-tree's default node.
26
- * Created in order to use Sanity UI for styles.
27
- * Reference: https://github.com/frontend-collective/react-sortable-tree/blob/master/src/node-renderer-default.js
28
- */
29
- ])), cyan[50].hex, gray[400].hex, red[50].hex);
30
- /**
31
- * Customization of react-sortable-tree's default node.
32
- * Created in order to use Sanity UI for styles.
33
- * Reference: https://github.com/frontend-collective/react-sortable-tree/blob/master/src/node-renderer-default.js
34
- */
35
- var NodeContentRenderer = function (props) {
36
- var node = props.node, path = props.path, treeIndex = props.treeIndex, _a = props.canDrag, canDrag = _a === void 0 ? false : _a;
37
- var nodeTitle = node.title;
38
- var Handle = React.useMemo(function () {
39
- if (!canDrag) {
40
- return null;
41
- }
42
- if (typeof node.children === 'function' && node.expanded) {
43
- // Show a loading symbol on the handle when the children are expanded
44
- // and yet still defined by a function (a callback to fetch the children)
45
- return _jsx(Spinner, {}, void 0);
46
- }
47
- var BtnElement = (_jsx("div", { children: _jsx(Button, __assign({ mode: "bleed", paddingX: 0, paddingY: 1, style: {
48
- cursor: node.publishedId ? 'grab' : 'default',
49
- 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));
51
- // Don't allow editors to drag invalid documents
52
- if (!node.publishedId) {
53
- return BtnElement;
54
- }
55
- // Show the handle used to initiate a drag-and-drop
56
- return props.connectDragSource(BtnElement, {
57
- dropEffect: 'copy'
58
- });
59
- }, [canDrag, node, typeof node.children === 'function']);
60
- var isDraggedDescendant = props.draggedNode && isDescendant(props.draggedNode, node);
61
- var isLandingPadActive = !props.didDrop && props.isDragging;
62
- return (_jsxs(Box, __assign({ style: { position: 'relative' } }, { children: [props.toggleChildrenVisibility &&
63
- node.children &&
64
- (node.children.length > 0 || typeof node.children === 'function') && (_jsx("div", __assign({ style: {
65
- position: 'absolute',
66
- left: '-2px',
67
- top: '40%',
68
- 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 () {
70
- var _a;
71
- return (_a = props.toggleChildrenVisibility) === null || _a === void 0 ? void 0 : _a.call(props, {
72
- node: node,
73
- path: path,
74
- treeIndex: treeIndex
75
- });
76
- } }, void 0) }), void 0)), props.connectDragPreview(_jsx("div", { children: _jsx(Root, __assign({ "data-landing": isLandingPadActive, "data-cancel": isLandingPadActive && !props.canDrop, style: {
77
- 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));
79
- };
80
- export default NodeContentRenderer;
81
- var templateObject_1;
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);
54
+ /**
55
+ * Customization of react-sortable-tree's default node.
56
+ * Created in order to use Sanity UI for styles.
57
+ * Reference: https://github.com/frontend-collective/react-sortable-tree/blob/master/src/node-renderer-default.js
58
+ */
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 () {
63
+ if (!canDrag) {
64
+ return null;
65
+ }
66
+ if (typeof node.children === 'function' && node.expanded) {
67
+ // Show a loading symbol on the handle when the children are expanded
68
+ // and yet still defined by a function (a callback to fetch the children)
69
+ return (0, jsx_runtime_1.jsx)(ui_1.Spinner, {}, void 0);
70
+ }
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: {
72
+ cursor: node.publishedId ? 'grab' : 'default',
73
+ fontSize: '1.5625rem'
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));
75
+ // Don't allow editors to drag invalid documents
76
+ if (!node.publishedId) {
77
+ return BtnElement;
78
+ }
79
+ // Show the handle used to initiate a drag-and-drop
80
+ return props.connectDragSource(BtnElement, {
81
+ dropEffect: 'copy'
82
+ });
83
+ }, [canDrag, node, typeof node.children === 'function']);
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 &&
87
+ node.children &&
88
+ (node.children.length > 0 || typeof node.children === 'function') && ((0, jsx_runtime_1.jsx)("div", __assign({ style: {
89
+ position: 'absolute',
90
+ left: '-2px',
91
+ top: '40%',
92
+ transform: 'translate(-100%, -50%)'
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: {
101
+ opacity: isDraggedDescendant ? 0.5 : 1
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));
103
+ };
104
+ exports.default = NodeContentRenderer;
105
+ var templateObject_1;
@@ -1,9 +1,9 @@
1
- import { CardTone } from '@sanity/ui';
2
- import React from 'react';
3
- import { PlaceholderRendererProps } from 'react-sortable-tree';
4
- declare const PlaceholderDropzone: React.FC<{
5
- tone?: CardTone;
6
- title: string;
7
- subtitle?: string;
8
- } & PlaceholderRendererProps>;
9
- export default PlaceholderDropzone;
1
+ import { CardTone } from '@sanity/ui';
2
+ import * as React from 'react';
3
+ import { PlaceholderRendererProps } from 'react-sortable-tree';
4
+ declare const PlaceholderDropzone: React.FC<{
5
+ tone?: CardTone;
6
+ title: string;
7
+ subtitle?: string;
8
+ } & PlaceholderRendererProps>;
9
+ export default PlaceholderDropzone;
@@ -1,28 +1,30 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
13
- import { Box, Card, Stack, Text } from '@sanity/ui';
14
- var PlaceholderDropzone = function (props) {
15
- var isValid = props.isOver && props.canDrop;
16
- var isInvalid = props.isOver && !props.canDrop;
17
- var tone = 'transparent';
18
- if (isValid) {
19
- tone = 'positive';
20
- }
21
- if (isInvalid) {
22
- tone = 'caution';
23
- }
24
- return (_jsx(Box, __assign({ padding: 3 }, { children: _jsx(Card, __assign({ padding: 5, radius: 2, border: true, tone: tone, style: {
25
- 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));
27
- };
28
- export default PlaceholderDropzone;
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';
20
+ if (isValid) {
21
+ tone = 'positive';
22
+ }
23
+ if (isInvalid) {
24
+ tone = 'caution';
25
+ }
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: {
27
+ borderStyle: props.isOver ? undefined : 'dashed'
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));
29
+ };
30
+ exports.default = PlaceholderDropzone;
@@ -0,0 +1,2 @@
1
+ import { DragDropManager } from 'dnd-core';
2
+ export declare const suppressedDnDManager: DragDropManager;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.suppressedDnDManager = void 0;
4
+ var react_dnd_1 = require("react-dnd");
5
+ var react_dnd_html5_backend_1 = require("react-dnd-html5-backend");
6
+ /**
7
+ * Fix lifted from https://github.com/frontend-collective/react-sortable-tree/issues/510#issuecomment-731233436
8
+ * This DND context is used to resolve errors: "Error: Cannot have two HTML5 backends at the same time."
9
+ */
10
+ var DnDContext = (0, react_dnd_1.createDndContext)(react_dnd_html5_backend_1.HTML5Backend);
11
+ var manager = DnDContext.dragDropManager;
12
+ var monitor = manager.getMonitor();
13
+ /**
14
+ * The suppressing monitor (and manager that uses it),
15
+ * is an additional workaround to prevent non-functional errors in react-dnd from
16
+ * bubbling to the Sanity error handler (which will emit a toast that can be ignored by the user anyway).
17
+ */
18
+ var suppressedMonitor = {
19
+ canDragSource: monitor.canDragSource.bind(monitor),
20
+ canDropOnTarget: function (targetId) {
21
+ try {
22
+ return monitor.canDropOnTarget(targetId);
23
+ }
24
+ catch (e) {
25
+ // suppress error
26
+ return false;
27
+ }
28
+ },
29
+ didDrop: monitor.didDrop.bind(monitor),
30
+ getClientOffset: monitor.getClientOffset.bind(monitor),
31
+ getDifferenceFromInitialOffset: monitor.getDifferenceFromInitialOffset.bind(monitor),
32
+ getDropResult: monitor.getDropResult.bind(monitor),
33
+ getInitialClientOffset: monitor.getInitialClientOffset.bind(monitor),
34
+ getInitialSourceClientOffset: monitor.getInitialSourceClientOffset.bind(monitor),
35
+ getItem: function () {
36
+ var _a;
37
+ // return empty instead of undefined to work around property access failing
38
+ return (_a = monitor.getItem()) !== null && _a !== void 0 ? _a : {};
39
+ },
40
+ getItemType: monitor.getItemType.bind(monitor),
41
+ getSourceClientOffset: monitor.getSourceClientOffset.bind(monitor),
42
+ getSourceId: monitor.getSourceId.bind(monitor),
43
+ getTargetIds: monitor.getTargetIds.bind(monitor),
44
+ isDragging: monitor.isDragging.bind(monitor),
45
+ isDraggingSource: monitor.isDraggingSource.bind(monitor),
46
+ isOverTarget: monitor.isOverTarget.bind(monitor),
47
+ isSourcePublic: monitor.isSourcePublic.bind(monitor),
48
+ subscribeToOffsetChange: monitor.subscribeToOffsetChange.bind(monitor),
49
+ subscribeToStateChange: monitor.subscribeToStateChange.bind(monitor)
50
+ };
51
+ exports.suppressedDnDManager = {
52
+ getMonitor: function () {
53
+ return suppressedMonitor;
54
+ },
55
+ getBackend: manager.getBackend.bind(manager),
56
+ getRegistry: manager.getRegistry.bind(manager),
57
+ getActions: manager.getActions.bind(manager),
58
+ dispatch: manager.dispatch.bind(manager)
59
+ };
@@ -1,12 +1,12 @@
1
- import React from 'react';
2
- import { StoredTreeItem, TreeInputOptions } from '../types';
3
- /**
4
- * The loaded tree users interact with
5
- */
6
- declare const TreeEditor: React.FC<{
7
- tree: StoredTreeItem[];
8
- onChange: (patch: unknown) => void;
9
- options: TreeInputOptions;
10
- patchPrefix?: string;
11
- }>;
12
- export default TreeEditor;
1
+ import * as React from 'react';
2
+ import { StoredTreeItem, TreeInputOptions } from '../types';
3
+ /**
4
+ * The loaded tree users interact with
5
+ */
6
+ declare const TreeEditor: React.FC<{
7
+ tree: StoredTreeItem[];
8
+ onChange: (patch: unknown) => void;
9
+ options: TreeInputOptions;
10
+ patchPrefix?: string;
11
+ }>;
12
+ export default TreeEditor;