@sanity/hierarchical-document-list 1.0.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.
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +4 -0
- package/.idea/hierarchical-document-list.iml +11 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +7 -0
- package/.idea/vcs.xml +6 -0
- package/CHANGELOG.md +15 -0
- package/README.md +329 -297
- package/commitlint.config.js +3 -0
- package/lib/TreeDeskStructure.d.ts +8 -8
- package/lib/TreeDeskStructure.js +96 -96
- package/lib/TreeInputComponent.d.ts +19 -19
- package/lib/TreeInputComponent.js +50 -52
- package/lib/components/DeskWarning.d.ts +6 -6
- package/lib/components/DeskWarning.js +46 -46
- package/lib/components/DocumentInNode.d.ts +11 -11
- package/lib/components/DocumentInNode.js +81 -82
- package/lib/components/DocumentPreviewStatus.d.ts +7 -7
- package/lib/components/DocumentPreviewStatus.js +39 -39
- package/lib/components/NodeActions.d.ts +10 -10
- package/lib/components/NodeActions.js +61 -61
- package/lib/components/NodeContentRenderer.d.ts +8 -8
- package/lib/components/NodeContentRenderer.js +105 -105
- package/lib/components/PlaceholderDropzone.d.ts +9 -9
- package/lib/components/PlaceholderDropzone.js +30 -30
- package/lib/components/SuppressedDnDManager.d.ts +2 -0
- package/lib/components/SuppressedDnDManager.js +59 -0
- package/lib/components/TreeEditor.d.ts +12 -12
- package/lib/components/TreeEditor.js +74 -59
- package/lib/components/TreeEditorErrorBoundary.d.ts +16 -3
- package/lib/components/TreeEditorErrorBoundary.js +74 -59
- package/lib/components/TreeNodeRenderer.d.ts +3 -3
- package/lib/components/TreeNodeRenderer.js +59 -59
- package/lib/components/TreeNodeRendererScaffold.d.ts +4 -4
- package/lib/components/TreeNodeRendererScaffold.js +44 -44
- package/lib/createDeskHierarchy.d.ts +14 -14
- package/lib/createDeskHierarchy.js +84 -85
- package/lib/createHierarchicalSchemas.d.ts +98 -78
- package/lib/createHierarchicalSchemas.js +138 -138
- package/lib/hooks/useAllItems.d.ts +7 -7
- package/lib/hooks/useAllItems.js +119 -119
- package/lib/hooks/useLocalTree.d.ts +17 -17
- package/lib/hooks/useLocalTree.js +59 -59
- package/lib/hooks/useTreeOperations.d.ts +9 -9
- package/lib/hooks/useTreeOperations.js +39 -39
- package/lib/hooks/useTreeOperationsProvider.d.ts +14 -14
- package/lib/hooks/useTreeOperationsProvider.js +85 -85
- package/lib/index.d.ts +3 -3
- package/lib/index.js +12 -12
- package/lib/schemas/hierarchy.tree.d.ts +13 -13
- package/lib/schemas/hierarchy.tree.js +19 -19
- package/lib/types.d.ts +128 -0
- package/lib/types.js +2 -0
- package/lib/utils/flatDataToTree.d.ts +6 -6
- package/lib/utils/flatDataToTree.js +26 -26
- package/lib/utils/getAdjescentNodes.d.ts +12 -12
- package/lib/utils/getAdjescentNodes.js +19 -19
- package/lib/utils/getCommonTreeProps.d.ts +7 -7
- package/lib/utils/getCommonTreeProps.js +33 -33
- package/lib/utils/getTreeHeight.d.ts +3 -3
- package/lib/utils/getTreeHeight.js +11 -11
- package/lib/utils/gradientPatchAdapter.d.ts +4 -4
- package/lib/utils/gradientPatchAdapter.js +40 -42
- package/lib/utils/idUtils.d.ts +2 -2
- package/lib/utils/idUtils.js +13 -13
- package/lib/utils/injectNodeTypeInPatches.d.ts +12 -12
- package/lib/utils/injectNodeTypeInPatches.js +59 -58
- package/lib/utils/moveItemInArray.d.ts +5 -5
- package/lib/utils/moveItemInArray.js +26 -26
- package/lib/utils/throwError.d.ts +7 -7
- package/lib/utils/throwError.js +12 -12
- package/lib/utils/treeData.d.ts +18 -18
- package/lib/utils/treeData.js +118 -118
- package/lib/utils/treePatches.d.ts +15 -15
- package/lib/utils/treePatches.js +171 -171
- package/lint-staged.config.js +4 -0
- package/package.json +65 -55
- package/sanity.json +12 -12
- package/tsconfig.json +20 -20
|
@@ -1,105 +1,105 @@
|
|
|
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
|
+
"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 * 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
|
+
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,30 +1,30 @@
|
|
|
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;
|
|
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,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 * 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;
|
|
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;
|
|
@@ -1,59 +1,74 @@
|
|
|
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
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
59
|
-
|
|
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_1 = require("react");
|
|
21
|
+
var react_sortable_tree_1 = require("react-sortable-tree");
|
|
22
|
+
var getCommonTreeProps_1 = __importDefault(require("../utils/getCommonTreeProps"));
|
|
23
|
+
var getTreeHeight_1 = __importDefault(require("../utils/getTreeHeight"));
|
|
24
|
+
var treeData_1 = require("../utils/treeData");
|
|
25
|
+
var useAllItems_1 = __importDefault(require("../hooks/useAllItems"));
|
|
26
|
+
var useLocalTree_1 = __importDefault(require("../hooks/useLocalTree"));
|
|
27
|
+
var useTreeOperations_1 = require("../hooks/useTreeOperations");
|
|
28
|
+
var useTreeOperationsProvider_1 = __importDefault(require("../hooks/useTreeOperationsProvider"));
|
|
29
|
+
var DocumentInNode_1 = __importDefault(require("./DocumentInNode"));
|
|
30
|
+
var react_dnd_1 = require("react-dnd");
|
|
31
|
+
var TreeEditorErrorBoundary_1 = require("./TreeEditorErrorBoundary");
|
|
32
|
+
var SuppressedDnDManager_1 = require("./SuppressedDnDManager");
|
|
33
|
+
/**
|
|
34
|
+
* The loaded tree users interact with
|
|
35
|
+
*/
|
|
36
|
+
var TreeEditor = function (props) {
|
|
37
|
+
var _a = (0, useAllItems_1.default)(props.options), allItemsStatus = _a.status, allItems = _a.allItems;
|
|
38
|
+
var unaddedItems = (0, treeData_1.getUnaddedItems)({ tree: props.tree, allItems: allItems });
|
|
39
|
+
var _b = (0, useLocalTree_1.default)({
|
|
40
|
+
tree: props.tree,
|
|
41
|
+
allItems: allItems
|
|
42
|
+
}), localTree = _b.localTree, handleVisibilityToggle = _b.handleVisibilityToggle;
|
|
43
|
+
var operations = (0, useTreeOperationsProvider_1.default)({
|
|
44
|
+
patchPrefix: props.patchPrefix,
|
|
45
|
+
onChange: props.onChange,
|
|
46
|
+
localTree: localTree
|
|
47
|
+
});
|
|
48
|
+
var onMoveNode = (0, react_1.useCallback)(function (data) {
|
|
49
|
+
return operations.handleMovedNode(data);
|
|
50
|
+
}, [operations]);
|
|
51
|
+
var treeProps = (0, react_1.useMemo)(function () {
|
|
52
|
+
return (0, getCommonTreeProps_1.default)({
|
|
53
|
+
placeholder: {
|
|
54
|
+
title: 'Add items from the list below'
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}, []);
|
|
58
|
+
var operationContext = (0, react_1.useMemo)(function () { return (__assign(__assign({}, operations), { allItemsStatus: allItemsStatus })); }, [operations, allItemsStatus]);
|
|
59
|
+
return ((0, jsx_runtime_1.jsx)(TreeEditorErrorBoundary_1.TreeEditorErrorBoundary, { children: (0, jsx_runtime_1.jsx)(react_dnd_1.DndProvider, __assign({ manager: SuppressedDnDManager_1.suppressedDnDManager }, { children: (0, jsx_runtime_1.jsx)(useTreeOperations_1.TreeOperationsContext.Provider, __assign({ value: operationContext }, { 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) },
|
|
60
|
+
// Only include borderBottom if there's something to show in unadded items
|
|
61
|
+
borderBottom: allItemsStatus !== 'success' || (unaddedItems === null || unaddedItems === void 0 ? void 0 : unaddedItems.length) > 0 }, { children: (0, jsx_runtime_1.jsx)(react_sortable_tree_1.SortableTreeWithoutDndContext, __assign({ maxDepth: props.options.maxDepth, onChange: doNothingOnChange, onVisibilityToggle: handleVisibilityToggle, canDrop: canDrop, onMoveNode: onMoveNode, treeData: localTree }, treeProps), 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 () {
|
|
62
|
+
operations.addItem(item);
|
|
63
|
+
}, 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) }, void 0));
|
|
64
|
+
};
|
|
65
|
+
function canDrop(_a) {
|
|
66
|
+
var nextPath = _a.nextPath, prevPath = _a.prevPath;
|
|
67
|
+
var insideItself = nextPath.length >= prevPath.length &&
|
|
68
|
+
prevPath.every(function (pathIndex, index) { return nextPath[index] === pathIndex; });
|
|
69
|
+
return !insideItself;
|
|
70
|
+
}
|
|
71
|
+
var doNothingOnChange = function () {
|
|
72
|
+
// Do nothing. onMoveNode will do all the work
|
|
73
|
+
};
|
|
74
|
+
exports.default = TreeEditor;
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* react-sortable-tree emits a lot of random errors when dragging to invalid states,
|
|
4
|
+
* even when drag-targets are disabled.
|
|
5
|
+
*
|
|
6
|
+
* This boundary is a workaround so users are not pestered with error-toasts for things
|
|
7
|
+
* that have no functional impact.
|
|
8
|
+
*
|
|
9
|
+
* This boundry does NOT handle errors that happen in the React dnd
|
|
10
|
+
* event handlers, so there is addtional workarounds in the
|
|
11
|
+
* DnDManager.
|
|
12
|
+
* */
|
|
13
|
+
export declare class TreeEditorErrorBoundary extends React.Component {
|
|
14
|
+
componentDidCatch(): void;
|
|
15
|
+
render(): React.ReactNode;
|
|
16
|
+
}
|