@sanity/hierarchical-document-list 0.1.0-next.1 → 0.1.1
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/README.md +91 -40
- package/lib/TreeDeskStructure.js +56 -28
- package/lib/TreeInputComponent.d.ts +3 -3
- package/lib/TreeInputComponent.js +14 -3
- package/lib/components/DeskWarning.d.ts +6 -0
- package/lib/components/DeskWarning.js +25 -0
- package/lib/components/DocumentInNode.d.ts +2 -2
- package/lib/components/DocumentInNode.js +29 -17
- package/lib/components/DocumentPreviewStatus.js +26 -7
- package/lib/components/NodeActions.d.ts +2 -2
- package/lib/components/NodeActions.js +24 -10
- package/lib/components/NodeContentRenderer.js +42 -40
- package/lib/components/PlaceholderDropzone.js +19 -8
- package/lib/components/TreeEditor.d.ts +2 -2
- package/lib/components/TreeEditor.js +29 -16
- package/lib/components/TreeEditorErrorBoundary.d.ts +1 -15
- package/lib/components/TreeEditorErrorBoundary.js +26 -28
- package/lib/components/TreeNodeRenderer.js +25 -12
- package/lib/components/TreeNodeRendererScaffold.js +12 -134
- package/lib/createDeskHierarchy.d.ts +4 -0
- package/lib/createDeskHierarchy.js +34 -19
- package/lib/createHierarchicalField.js +40 -19
- package/lib/{hiearchy.tree.d.ts → schemas/hierarchy.tree.d.ts} +0 -0
- package/lib/schemas/hierarchy.tree.js +31 -0
- package/lib/utils/flatDataToTree.d.ts +3 -3
- package/lib/utils/flatDataToTree.js +15 -6
- package/lib/utils/getAdjescentNodes.js +7 -6
- package/lib/utils/getCommonTreeProps.js +14 -2
- package/lib/utils/getTreeHeight.js +3 -3
- package/lib/utils/gradientPatchAdapter.js +16 -15
- package/lib/utils/idUtils.js +4 -2
- package/lib/utils/moveItemInArray.js +15 -5
- package/lib/utils/treeData.d.ts +7 -7
- package/lib/utils/treeData.js +65 -36
- package/lib/utils/treePatches.d.ts +10 -8
- package/lib/utils/treePatches.js +58 -50
- package/lib/utils/useAllItems.js +43 -41
- package/lib/utils/useLocalTree.d.ts +5 -5
- package/lib/utils/useLocalTree.js +21 -11
- package/lib/utils/useTreeOperations.js +1 -1
- package/lib/utils/useTreeOperationsProvider.d.ts +7 -8
- package/lib/utils/useTreeOperationsProvider.js +25 -17
- package/package.json +11 -9
- package/sanity.json +1 -1
- package/screenshot-1.jpg +0 -0
- package/tsconfig.json +1 -1
- package/lib/hiearchy.tree.js +0 -28
|
@@ -1,3 +1,18 @@
|
|
|
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
|
+
};
|
|
1
16
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
17
|
import { cyan, gray, red } from '@sanity/color';
|
|
3
18
|
import { ChevronDownIcon, ChevronRightIcon, DragHandleIcon } from '@sanity/icons';
|
|
@@ -5,39 +20,22 @@ import { Box, Button, Flex, Spinner } from '@sanity/ui';
|
|
|
5
20
|
import React from 'react';
|
|
6
21
|
import { isDescendant } from 'react-sortable-tree';
|
|
7
22
|
import styled from 'styled-components';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
`;
|
|
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);
|
|
32
30
|
/**
|
|
33
31
|
* Customization of react-sortable-tree's default node.
|
|
34
32
|
* Created in order to use Sanity UI for styles.
|
|
35
33
|
* Reference: https://github.com/frontend-collective/react-sortable-tree/blob/master/src/node-renderer-default.js
|
|
36
34
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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 () {
|
|
41
39
|
if (!canDrag) {
|
|
42
40
|
return null;
|
|
43
41
|
}
|
|
@@ -46,10 +44,10 @@ const NodeContentRenderer = (props) => {
|
|
|
46
44
|
// and yet still defined by a function (a callback to fetch the children)
|
|
47
45
|
return _jsx(Spinner, {}, void 0);
|
|
48
46
|
}
|
|
49
|
-
|
|
47
|
+
var BtnElement = (_jsx("div", { children: _jsx(Button, __assign({ mode: "bleed", paddingX: 0, paddingY: 1, style: {
|
|
50
48
|
cursor: node.publishedId ? 'grab' : 'default',
|
|
51
49
|
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));
|
|
50
|
+
}, "data-ui": "DragHandleButton", "data-drag-handle": canDrag, disabled: !node.publishedId }, { children: _jsx(DragHandleIcon, { style: { marginBottom: '-0.1em' } }, void 0) }), void 0) }, void 0));
|
|
53
51
|
// Don't allow editors to drag invalid documents
|
|
54
52
|
if (!node.publishedId) {
|
|
55
53
|
return BtnElement;
|
|
@@ -59,21 +57,25 @@ const NodeContentRenderer = (props) => {
|
|
|
59
57
|
dropEffect: 'copy'
|
|
60
58
|
});
|
|
61
59
|
}, [canDrag, node, typeof node.children === 'function']);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return (_jsxs(Box, { style: { position: 'relative' }, children: [props.toggleChildrenVisibility &&
|
|
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 &&
|
|
65
63
|
node.children &&
|
|
66
|
-
(node.children.length > 0 || typeof node.children === 'function') && (_jsx("div", { style: {
|
|
64
|
+
(node.children.length > 0 || typeof node.children === 'function') && (_jsx("div", __assign({ style: {
|
|
67
65
|
position: 'absolute',
|
|
68
66
|
left: '-2px',
|
|
69
67
|
top: '40%',
|
|
70
68
|
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: ()
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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: {
|
|
76
77
|
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));
|
|
78
|
+
} }, { children: _jsxs(Flex, __assign({ align: "center" }, { children: [Handle, typeof nodeTitle === 'function' ? nodeTitle(props) : nodeTitle] }), void 0) }), void 0) }, void 0))] }), void 0));
|
|
78
79
|
};
|
|
79
80
|
export default NodeContentRenderer;
|
|
81
|
+
var templateObject_1;
|
|
@@ -1,17 +1,28 @@
|
|
|
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
|
+
};
|
|
1
12
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Card, Stack, Text } from '@sanity/ui';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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';
|
|
7
18
|
if (isValid) {
|
|
8
19
|
tone = 'positive';
|
|
9
20
|
}
|
|
10
21
|
if (isInvalid) {
|
|
11
22
|
tone = 'caution';
|
|
12
23
|
}
|
|
13
|
-
return (_jsx(Card, { padding: 5, radius: 2, border: true, tone: tone, style: {
|
|
14
|
-
|
|
15
|
-
|
|
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));
|
|
16
27
|
};
|
|
17
28
|
export default PlaceholderDropzone;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { StoredTreeItem, TreeInputOptions } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* The loaded tree users interact with
|
|
5
5
|
*/
|
|
6
6
|
declare const TreeEditor: React.FC<{
|
|
7
|
-
tree:
|
|
7
|
+
tree: StoredTreeItem[];
|
|
8
8
|
onChange: (patch: unknown) => void;
|
|
9
9
|
options: TreeInputOptions;
|
|
10
10
|
patchPrefix?: string;
|
|
@@ -1,3 +1,14 @@
|
|
|
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
|
+
};
|
|
1
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
13
|
import { AddCircleIcon } from '@sanity/icons';
|
|
3
14
|
import { Box, Button, Card, Flex, Spinner, Stack, Text, Tooltip } from '@sanity/ui';
|
|
@@ -14,28 +25,30 @@ import TreeEditorErrorBoundary from './TreeEditorErrorBoundary';
|
|
|
14
25
|
/**
|
|
15
26
|
* The loaded tree users interact with
|
|
16
27
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
28
|
+
var TreeEditor = function (props) {
|
|
29
|
+
var _a = useAllItems(props.options), allItemsStatus = _a.status, allItems = _a.allItems;
|
|
30
|
+
var unaddedItems = getUnaddedItems({ tree: props.tree, allItems: allItems });
|
|
31
|
+
var _b = useLocalTree({
|
|
21
32
|
tree: props.tree,
|
|
22
|
-
allItems
|
|
23
|
-
});
|
|
24
|
-
|
|
33
|
+
allItems: allItems
|
|
34
|
+
}), localTree = _b.localTree, handleVisibilityToggle = _b.handleVisibilityToggle;
|
|
35
|
+
var operations = useTreeOperationsProvider({
|
|
25
36
|
patchPrefix: props.patchPrefix,
|
|
26
37
|
onChange: props.onChange,
|
|
27
|
-
localTree
|
|
38
|
+
localTree: localTree
|
|
28
39
|
});
|
|
29
|
-
return (_jsx(TreeEditorErrorBoundary, { children: _jsx(TreeOperationsContext.Provider, { value: {
|
|
40
|
+
return (_jsx(TreeEditorErrorBoundary, { children: _jsx(TreeOperationsContext.Provider, __assign({ value: __assign(__assign({}, operations), { allItemsStatus: allItemsStatus }) }, { children: _jsxs(Stack, __assign({ space: 4, paddingTop: 4 }, { children: [_jsx(Card, __assign({ style: { minHeight: getTreeHeight(localTree) },
|
|
30
41
|
// Only include borderBottom if there's something to show in unadded items
|
|
31
|
-
borderBottom: allItemsStatus !== 'success' || unaddedItems
|
|
42
|
+
borderBottom: allItemsStatus !== 'success' || (unaddedItems === null || unaddedItems === void 0 ? void 0 : unaddedItems.length) > 0 }, { children: _jsx(SortableTree, __assign({ maxDepth: props.options.maxDepth, onChange: function () {
|
|
32
43
|
// Do nothing. onMoveNode will do all the work
|
|
33
|
-
}, onVisibilityToggle: handleVisibilityToggle, onMoveNode:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
}, onVisibilityToggle: handleVisibilityToggle, onMoveNode: function (data) {
|
|
45
|
+
return operations.handleMovedNode(data);
|
|
46
|
+
}, treeData: localTree }, getCommonTreeProps({
|
|
47
|
+
placeholder: {
|
|
48
|
+
title: 'Add items from the list below'
|
|
49
|
+
}
|
|
50
|
+
})), void 0) }), void 0), allItemsStatus === 'success' && (unaddedItems === null || unaddedItems === void 0 ? void 0 : unaddedItems.length) > 0 && (_jsxs(Stack, __assign({ space: 1, paddingX: 2, paddingTop: 3 }, { children: [_jsxs(Stack, __assign({ space: 2, paddingX: 2, paddingBottom: 3 }, { children: [_jsx(Text, __assign({ size: 2, as: "h2", weight: "semibold" }, { children: "Add more items" }), void 0), _jsx(Text, __assign({ size: 1, muted: true }, { children: "Only published documents are shown." }), void 0)] }), void 0), unaddedItems.map(function (item) { return (_jsx(DocumentInNode, { item: item, action: _jsx(Tooltip, __assign({ portal: true, placement: "left", content: _jsx(Box, __assign({ padding: 2 }, { children: _jsx(Text, __assign({ size: 1 }, { children: "Add to list" }), void 0) }), void 0) }, { children: _jsx(Button, { onClick: function () {
|
|
38
51
|
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));
|
|
52
|
+
}, mode: "bleed", icon: AddCircleIcon, style: { cursor: 'pointer' } }, void 0) }), void 0) }, item.publishedId || item.draftId)); })] }), void 0)), allItemsStatus === 'loading' && (_jsx(Flex, __assign({ padding: 4, align: 'center', justify: 'center' }, { children: _jsx(Spinner, { size: 3, muted: true }, void 0) }), void 0)), allItemsStatus === 'error' && (_jsx(Flex, __assign({ padding: 4, align: 'center', justify: 'center' }, { children: _jsx(Text, __assign({ size: 2, weight: "semibold" }, { children: "Something went wrong when loading documents" }), void 0) }), void 0))] }), void 0) }), void 0) }, void 0));
|
|
40
53
|
};
|
|
41
54
|
export default TreeEditor;
|
|
@@ -1,17 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
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
|
-
}
|
|
2
|
+
declare const TreeEditorErrorBoundary: React.FC;
|
|
17
3
|
export default TreeEditorErrorBoundary;
|
|
@@ -1,13 +1,26 @@
|
|
|
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
|
+
};
|
|
1
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useToast } from '@sanity/ui';
|
|
13
|
+
import { ErrorBoundary, useToast } from '@sanity/ui';
|
|
3
14
|
import React from 'react';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
15
|
+
var DISPLAY_ERROR = false;
|
|
16
|
+
var ErrorToast = function (_a) {
|
|
17
|
+
var error = _a.error;
|
|
18
|
+
var push = useToast().push;
|
|
19
|
+
React.useEffect(function () {
|
|
20
|
+
if ((error === null || error === void 0 ? void 0 : error.error) && DISPLAY_ERROR) {
|
|
8
21
|
push({
|
|
9
|
-
title: error.
|
|
10
|
-
description: error.
|
|
22
|
+
title: error.error.name,
|
|
23
|
+
description: error.error.message,
|
|
11
24
|
closable: true,
|
|
12
25
|
status: 'error',
|
|
13
26
|
id: 'hierarchical-error'
|
|
@@ -16,25 +29,10 @@ const ErrorToast = ({ error }) => {
|
|
|
16
29
|
}, [error]);
|
|
17
30
|
return null;
|
|
18
31
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
}
|
|
32
|
+
var TreeEditorErrorBoundary = function (props) {
|
|
33
|
+
var _a = React.useState(undefined), exception = _a[0], setException = _a[1];
|
|
34
|
+
return (_jsxs(ErrorBoundary, __assign({ onCatch: function (newException) {
|
|
35
|
+
setException(newException);
|
|
36
|
+
} }, { children: [_jsx(ErrorToast, { error: exception }, void 0), props.children] }), void 0));
|
|
37
|
+
};
|
|
40
38
|
export default TreeEditorErrorBoundary;
|
|
@@ -1,22 +1,35 @@
|
|
|
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
|
+
};
|
|
1
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
13
|
import React from 'react';
|
|
3
14
|
import TreeNodeRendererScaffold from './TreeNodeRendererScaffold';
|
|
4
15
|
/**
|
|
5
16
|
* To prevent expand buttons from overflowing on the left, we add a minimum left padding to all entries
|
|
6
17
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
18
|
+
var BASE_LEFT_PADDING = 10;
|
|
19
|
+
var NESTING_PADDING = 14;
|
|
20
|
+
var TreeNodeRenderer = function (props) {
|
|
21
|
+
var children = props.children, lowerSiblingCounts = props.lowerSiblingCounts, connectDropTarget = props.connectDropTarget, isOver = props.isOver, draggedNode = props.draggedNode, canDrop = props.canDrop;
|
|
11
22
|
// Construct the scaffold representing the structure of the tree
|
|
12
|
-
|
|
13
|
-
return connectDropTarget(_jsxs("div", { style: props.style, children: [_jsx("div", { style: {
|
|
23
|
+
var scaffoldBlockCount = lowerSiblingCounts.length;
|
|
24
|
+
return connectDropTarget(_jsxs("div", __assign({ style: props.style }, { children: [_jsx("div", __assign({ style: {
|
|
14
25
|
// prettier-ignore
|
|
15
|
-
paddingLeft:
|
|
16
|
-
}, children: React.Children.map(children, (child)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
paddingLeft: "".concat(BASE_LEFT_PADDING + (NESTING_PADDING * scaffoldBlockCount), "px")
|
|
27
|
+
} }, { children: React.Children.map(children, function (child) {
|
|
28
|
+
return React.cloneElement(child, {
|
|
29
|
+
isOver: isOver,
|
|
30
|
+
canDrop: canDrop,
|
|
31
|
+
draggedNode: draggedNode
|
|
32
|
+
});
|
|
33
|
+
}) }), void 0), _jsx(TreeNodeRendererScaffold, __assign({}, props), void 0)] }), void 0));
|
|
21
34
|
};
|
|
22
35
|
export default TreeNodeRenderer;
|
|
@@ -1,145 +1,22 @@
|
|
|
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
|
+
};
|
|
1
5
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
6
|
import { blue } from '@sanity/color';
|
|
3
7
|
import { createGlobalStyle } from 'styled-components';
|
|
4
8
|
// Adapted from react-sortable-tree/src/tree-node.js
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
height: 100%;
|
|
9
|
-
position: relative;
|
|
10
|
-
display: inline-block;
|
|
11
|
-
--stroke-width: 3px;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.rst__absoluteLineBlock {
|
|
15
|
-
position: absolute;
|
|
16
|
-
top: 0;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/* Highlight line for pointing to dragged row destination
|
|
20
|
-
========================================================================== */
|
|
21
|
-
/**
|
|
22
|
-
* +--+--+
|
|
23
|
-
* | | |
|
|
24
|
-
* | | |
|
|
25
|
-
* | | |
|
|
26
|
-
* +--+--+
|
|
27
|
-
*/
|
|
28
|
-
.rst__highlightLineVertical {
|
|
29
|
-
z-index: 3;
|
|
30
|
-
}
|
|
31
|
-
.rst__highlightLineVertical::before {
|
|
32
|
-
position: absolute;
|
|
33
|
-
content: '';
|
|
34
|
-
background-color: ${blue[400].hex};
|
|
35
|
-
width: calc(var(--stroke-width) * 2);
|
|
36
|
-
margin-left: calc(var(--stroke-width) * -1);
|
|
37
|
-
left: 50%;
|
|
38
|
-
top: 0;
|
|
39
|
-
height: 100%;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
@keyframes arrow-pulse {
|
|
43
|
-
0% {
|
|
44
|
-
transform: translate(0, 0);
|
|
45
|
-
opacity: 0;
|
|
46
|
-
}
|
|
47
|
-
30% {
|
|
48
|
-
transform: translate(0, 300%);
|
|
49
|
-
opacity: 1;
|
|
50
|
-
}
|
|
51
|
-
70% {
|
|
52
|
-
transform: translate(0, 700%);
|
|
53
|
-
opacity: 1;
|
|
54
|
-
}
|
|
55
|
-
100% {
|
|
56
|
-
transform: translate(0, 1000%);
|
|
57
|
-
opacity: 0;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
.rst__highlightLineVertical::after {
|
|
61
|
-
content: '';
|
|
62
|
-
position: absolute;
|
|
63
|
-
height: 0;
|
|
64
|
-
margin-left: calc(var(--stroke-width) * -1);
|
|
65
|
-
left: 50%;
|
|
66
|
-
top: 0;
|
|
67
|
-
border-left: var(--stroke-width) solid transparent;
|
|
68
|
-
border-right: var(--stroke-width) solid transparent;
|
|
69
|
-
border-top: var(--stroke-width) solid white;
|
|
70
|
-
animation: arrow-pulse 1s infinite linear both;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* +-----+
|
|
75
|
-
* | |
|
|
76
|
-
* | +--+
|
|
77
|
-
* | | |
|
|
78
|
-
* +--+--+
|
|
79
|
-
*/
|
|
80
|
-
.rst__highlightTopLeftCorner::before {
|
|
81
|
-
z-index: 3;
|
|
82
|
-
content: '';
|
|
83
|
-
position: absolute;
|
|
84
|
-
border-top: solid calc(var(--stroke-width) * 2) ${blue[400].hex};
|
|
85
|
-
border-left: solid calc(var(--stroke-width) * 2) ${blue[400].hex};
|
|
86
|
-
box-sizing: border-box;
|
|
87
|
-
height: calc(50% + var(--stroke-width));
|
|
88
|
-
top: 50%;
|
|
89
|
-
margin-top: calc(var(--stroke-width) * -1);
|
|
90
|
-
right: 0;
|
|
91
|
-
width: calc(50% + var(--stroke-width));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* +--+--+
|
|
96
|
-
* | | |
|
|
97
|
-
* | | |
|
|
98
|
-
* | +->|
|
|
99
|
-
* +-----+
|
|
100
|
-
*/
|
|
101
|
-
.rst__highlightBottomLeftCorner {
|
|
102
|
-
z-index: 3;
|
|
103
|
-
}
|
|
104
|
-
.rst__highlightBottomLeftCorner::before {
|
|
105
|
-
content: '';
|
|
106
|
-
position: absolute;
|
|
107
|
-
border-bottom: solid calc(var(--stroke-width) * 2) ${blue[400].hex};
|
|
108
|
-
border-left: solid calc(var(--stroke-width) * 2) ${blue[400].hex};
|
|
109
|
-
box-sizing: border-box;
|
|
110
|
-
height: calc(100% + var(--stroke-width));
|
|
111
|
-
top: 0;
|
|
112
|
-
right: calc(var(--stroke-width) * 3);
|
|
113
|
-
width: calc(50% - calc(var(--stroke-width) * 2));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
.rst__highlightBottomLeftCorner::after {
|
|
117
|
-
content: '';
|
|
118
|
-
position: absolute;
|
|
119
|
-
height: 0;
|
|
120
|
-
right: 0;
|
|
121
|
-
top: 100%;
|
|
122
|
-
margin-top: calc(var(--stroke-width) * -3);
|
|
123
|
-
border-top: calc(var(--stroke-width) * 3) solid transparent;
|
|
124
|
-
border-bottom: calc(var(--stroke-width) * 3) solid transparent;
|
|
125
|
-
border-left: calc(var(--stroke-width) * 3) solid ${blue[400].hex};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
.rst__unclickable {
|
|
129
|
-
pointer-events: none;
|
|
130
|
-
margin-top: -calc(var(--stroke-width) * 3);
|
|
131
|
-
}
|
|
132
|
-
`;
|
|
133
|
-
const TreeNodeRendererScaffold = (props) => {
|
|
134
|
-
const { lowerSiblingCounts, scaffoldBlockPxWidth, listIndex, swapDepth, swapFrom, swapLength, treeIndex } = props;
|
|
9
|
+
var ScaffoldStyles = createGlobalStyle(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n .rst__lineBlock,\n .rst__absoluteLineBlock {\n height: 100%;\n position: relative;\n display: inline-block;\n --stroke-width: 3px;\n }\n\n .rst__absoluteLineBlock {\n position: absolute;\n top: 0;\n }\n\n /* Highlight line for pointing to dragged row destination\n ========================================================================== */\n /**\n * +--+--+\n * | | |\n * | | |\n * | | |\n * +--+--+\n */\n .rst__highlightLineVertical {\n z-index: 3;\n }\n .rst__highlightLineVertical::before {\n position: absolute;\n content: '';\n background-color: ", ";\n width: calc(var(--stroke-width) * 2);\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n height: 100%;\n }\n\n @keyframes arrow-pulse {\n 0% {\n transform: translate(0, 0);\n opacity: 0;\n }\n 30% {\n transform: translate(0, 300%);\n opacity: 1;\n }\n 70% {\n transform: translate(0, 700%);\n opacity: 1;\n }\n 100% {\n transform: translate(0, 1000%);\n opacity: 0;\n }\n }\n .rst__highlightLineVertical::after {\n content: '';\n position: absolute;\n height: 0;\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n border-left: var(--stroke-width) solid transparent;\n border-right: var(--stroke-width) solid transparent;\n border-top: var(--stroke-width) solid white;\n animation: arrow-pulse 1s infinite linear both;\n }\n\n /**\n * +-----+\n * | |\n * | +--+\n * | | |\n * +--+--+\n */\n .rst__highlightTopLeftCorner::before {\n z-index: 3;\n content: '';\n position: absolute;\n border-top: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(50% + var(--stroke-width));\n top: 50%;\n margin-top: calc(var(--stroke-width) * -1);\n right: 0;\n width: calc(50% + var(--stroke-width));\n }\n\n /**\n * +--+--+\n * | | |\n * | | |\n * | +->|\n * +-----+\n */\n .rst__highlightBottomLeftCorner {\n z-index: 3;\n }\n .rst__highlightBottomLeftCorner::before {\n content: '';\n position: absolute;\n border-bottom: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(100% + var(--stroke-width));\n top: 0;\n right: calc(var(--stroke-width) * 3);\n width: calc(50% - calc(var(--stroke-width) * 2));\n }\n\n .rst__highlightBottomLeftCorner::after {\n content: '';\n position: absolute;\n height: 0;\n right: 0;\n top: 100%;\n margin-top: calc(var(--stroke-width) * -3);\n border-top: calc(var(--stroke-width) * 3) solid transparent;\n border-bottom: calc(var(--stroke-width) * 3) solid transparent;\n border-left: calc(var(--stroke-width) * 3) solid ", ";\n }\n\n .rst__unclickable {\n pointer-events: none;\n margin-top: -calc(var(--stroke-width) * 3);\n }\n"], ["\n .rst__lineBlock,\n .rst__absoluteLineBlock {\n height: 100%;\n position: relative;\n display: inline-block;\n --stroke-width: 3px;\n }\n\n .rst__absoluteLineBlock {\n position: absolute;\n top: 0;\n }\n\n /* Highlight line for pointing to dragged row destination\n ========================================================================== */\n /**\n * +--+--+\n * | | |\n * | | |\n * | | |\n * +--+--+\n */\n .rst__highlightLineVertical {\n z-index: 3;\n }\n .rst__highlightLineVertical::before {\n position: absolute;\n content: '';\n background-color: ", ";\n width: calc(var(--stroke-width) * 2);\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n height: 100%;\n }\n\n @keyframes arrow-pulse {\n 0% {\n transform: translate(0, 0);\n opacity: 0;\n }\n 30% {\n transform: translate(0, 300%);\n opacity: 1;\n }\n 70% {\n transform: translate(0, 700%);\n opacity: 1;\n }\n 100% {\n transform: translate(0, 1000%);\n opacity: 0;\n }\n }\n .rst__highlightLineVertical::after {\n content: '';\n position: absolute;\n height: 0;\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n border-left: var(--stroke-width) solid transparent;\n border-right: var(--stroke-width) solid transparent;\n border-top: var(--stroke-width) solid white;\n animation: arrow-pulse 1s infinite linear both;\n }\n\n /**\n * +-----+\n * | |\n * | +--+\n * | | |\n * +--+--+\n */\n .rst__highlightTopLeftCorner::before {\n z-index: 3;\n content: '';\n position: absolute;\n border-top: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(50% + var(--stroke-width));\n top: 50%;\n margin-top: calc(var(--stroke-width) * -1);\n right: 0;\n width: calc(50% + var(--stroke-width));\n }\n\n /**\n * +--+--+\n * | | |\n * | | |\n * | +->|\n * +-----+\n */\n .rst__highlightBottomLeftCorner {\n z-index: 3;\n }\n .rst__highlightBottomLeftCorner::before {\n content: '';\n position: absolute;\n border-bottom: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(100% + var(--stroke-width));\n top: 0;\n right: calc(var(--stroke-width) * 3);\n width: calc(50% - calc(var(--stroke-width) * 2));\n }\n\n .rst__highlightBottomLeftCorner::after {\n content: '';\n position: absolute;\n height: 0;\n right: 0;\n top: 100%;\n margin-top: calc(var(--stroke-width) * -3);\n border-top: calc(var(--stroke-width) * 3) solid transparent;\n border-bottom: calc(var(--stroke-width) * 3) solid transparent;\n border-left: calc(var(--stroke-width) * 3) solid ", ";\n }\n\n .rst__unclickable {\n pointer-events: none;\n margin-top: -calc(var(--stroke-width) * 3);\n }\n"])), blue[400].hex, blue[400].hex, blue[400].hex, blue[400].hex, blue[400].hex, blue[400].hex);
|
|
10
|
+
var TreeNodeRendererScaffold = function (props) {
|
|
11
|
+
var lowerSiblingCounts = props.lowerSiblingCounts, scaffoldBlockPxWidth = props.scaffoldBlockPxWidth, listIndex = props.listIndex, swapDepth = props.swapDepth, swapFrom = props.swapFrom, swapLength = props.swapLength, treeIndex = props.treeIndex;
|
|
135
12
|
// Construct the scaffold representing the structure of the tree
|
|
136
|
-
|
|
13
|
+
var scaffold = lowerSiblingCounts.map(function (lowerSiblingCount, i) {
|
|
137
14
|
if (lowerSiblingCount < 0 || treeIndex === listIndex || i !== swapDepth) {
|
|
138
15
|
return null;
|
|
139
16
|
}
|
|
140
17
|
// This row has been shifted, and is at the depth of
|
|
141
18
|
// the line pointing to the new destination
|
|
142
|
-
|
|
19
|
+
var highlightLineClass = '';
|
|
143
20
|
if (listIndex === (swapFrom || 0) + (swapLength || 0) - 1) {
|
|
144
21
|
// This block is on the bottom (target) line
|
|
145
22
|
// This block points at the target block (where the row will go when released)
|
|
@@ -153,12 +30,13 @@ const TreeNodeRendererScaffold = (props) => {
|
|
|
153
30
|
// This block is between the bottom and top
|
|
154
31
|
highlightLineClass = 'rst__highlightLineVertical';
|
|
155
32
|
}
|
|
156
|
-
|
|
33
|
+
var style = {
|
|
157
34
|
width: scaffoldBlockPxWidth,
|
|
158
35
|
left: scaffoldBlockPxWidth * i
|
|
159
36
|
};
|
|
160
|
-
return (_jsx("div", { style: style, className:
|
|
37
|
+
return (_jsx("div", { style: style, className: "rst__unclickable rst__absoluteLineBlock ".concat(highlightLineClass || ''), tabIndex: -1 }, i));
|
|
161
38
|
});
|
|
162
39
|
return (_jsxs(_Fragment, { children: [scaffold, _jsx(ScaffoldStyles, {}, void 0)] }, void 0));
|
|
163
40
|
};
|
|
164
41
|
export default TreeNodeRendererScaffold;
|
|
42
|
+
var templateObject_1;
|
|
@@ -5,6 +5,10 @@ interface TreeProps extends TreeDeskStructureProps {
|
|
|
5
5
|
* Also used as the label in the desk list item.
|
|
6
6
|
*/
|
|
7
7
|
title: string;
|
|
8
|
+
/**
|
|
9
|
+
* Optional icon for rendering the item in the desk structure.
|
|
10
|
+
*/
|
|
11
|
+
icon?: any;
|
|
8
12
|
}
|
|
9
13
|
export default function createDeskHierarchy(props: TreeProps): import("@sanity/structure/dist/dts/ListItem").ListItemBuilder;
|
|
10
14
|
export {};
|