@sanity/hierarchical-document-list 0.1.0-next.3 → 0.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/lib/TreeDeskStructure.js +46 -22
- package/lib/TreeInputComponent.js +14 -3
- package/lib/components/DeskWarning.js +18 -5
- package/lib/components/DocumentInNode.js +29 -17
- package/lib/components/DocumentPreviewStatus.js +26 -7
- package/lib/components/NodeActions.js +24 -11
- package/lib/components/NodeContentRenderer.js +42 -40
- package/lib/components/PlaceholderDropzone.js +17 -6
- package/lib/components/TreeEditor.js +29 -16
- package/lib/components/TreeEditorErrorBoundary.js +50 -21
- package/lib/components/TreeNodeRenderer.js +25 -12
- package/lib/components/TreeNodeRendererScaffold.js +12 -134
- package/lib/createDeskHierarchy.js +30 -17
- package/lib/createHierarchicalField.js +29 -14
- package/lib/schemas/hierarchy.tree.js +4 -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.js +65 -36
- package/lib/utils/treePatches.js +57 -38
- package/lib/utils/useAllItems.js +43 -41
- package/lib/utils/useLocalTree.js +20 -10
- package/lib/utils/useTreeOperations.js +1 -1
- package/lib/utils/useTreeOperationsProvider.js +25 -17
- package/package.json +1 -1
- package/tsconfig.json +1 -1
package/lib/TreeDeskStructure.js
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
1
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
24
|
import { PublishIcon } from '@sanity/icons';
|
|
3
25
|
import { useDocumentOperation, useEditState } from '@sanity/react-hooks';
|
|
@@ -6,42 +28,44 @@ import React from 'react';
|
|
|
6
28
|
import DeskWarning from './components/DeskWarning';
|
|
7
29
|
import TreeEditor from './components/TreeEditor';
|
|
8
30
|
import { toGradient } from './utils/gradientPatchAdapter';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (!patch
|
|
31
|
+
var DEFAULT_TREE_FIELD_KEY = 'tree';
|
|
32
|
+
var DEFAULT_TREE_DOC_TYPE = 'hierarchy.tree';
|
|
33
|
+
var TreeDeskStructure = function (props) {
|
|
34
|
+
var treeDocType = props.options.documentType || DEFAULT_TREE_DOC_TYPE;
|
|
35
|
+
var treeFieldKey = props.options.fieldKeyInDocument || DEFAULT_TREE_FIELD_KEY;
|
|
36
|
+
var _a = useEditState(props.options.documentId, treeDocType), published = _a.published, draft = _a.draft, liveEdit = _a.liveEdit;
|
|
37
|
+
var _b = useDocumentOperation(props.options.documentId, treeDocType), patch = _b.patch, ops = __rest(_b, ["patch"]);
|
|
38
|
+
var push = useToast().push;
|
|
39
|
+
var treeValue = ((published === null || published === void 0 ? void 0 : published[treeFieldKey]) || []);
|
|
40
|
+
var handleChange = React.useCallback(function (patchEvent) {
|
|
41
|
+
if (!(patch === null || patch === void 0 ? void 0 : patch.execute)) {
|
|
20
42
|
return;
|
|
21
43
|
}
|
|
22
44
|
patch.execute(toGradient(patchEvent.patches));
|
|
23
45
|
}, [patch]);
|
|
24
|
-
React.useEffect(()
|
|
25
|
-
|
|
46
|
+
React.useEffect(function () {
|
|
47
|
+
var _a;
|
|
48
|
+
if (!(published === null || published === void 0 ? void 0 : published._id) && (patch === null || patch === void 0 ? void 0 : patch.execute) && !(patch === null || patch === void 0 ? void 0 : patch.disabled)) {
|
|
26
49
|
// If no published document, create it
|
|
27
|
-
patch.execute([{ setIfMissing: { [treeFieldKey]
|
|
50
|
+
patch.execute([{ setIfMissing: (_a = {}, _a[treeFieldKey] = [], _a) }]);
|
|
28
51
|
}
|
|
29
|
-
}, [published
|
|
52
|
+
}, [published === null || published === void 0 ? void 0 : published._id, patch]);
|
|
30
53
|
if (!liveEdit) {
|
|
31
54
|
return (_jsx(DeskWarning, { title: "Invalid configuration", subtitle: "The `documentType` passed to `createDeskHiearchy` isn't live editable. \\nTo continue using this plugin, add `liveEdit: true` to your custom schema type or unset `documentType` in your hierarchy configuration." }, void 0));
|
|
32
55
|
}
|
|
33
|
-
if (draft
|
|
34
|
-
return (_jsx(DeskWarning, { title: "This hierarchy tree contains a draft", subtitle: "Click on the button below to publish your draft in order to continue editing the live\r\n published document.", children: _jsx(Button, { fontSize: 1, tone: "positive", text: "Publish draft", icon: PublishIcon, onClick: ()
|
|
35
|
-
|
|
56
|
+
if (draft === null || draft === void 0 ? void 0 : draft._id) {
|
|
57
|
+
return (_jsx(DeskWarning, __assign({ title: "This hierarchy tree contains a draft", subtitle: "Click on the button below to publish your draft in order to continue editing the live\r\n published document." }, { children: _jsx(Button, { fontSize: 1, tone: "positive", text: "Publish draft", icon: PublishIcon, onClick: function () {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
(_b = (_a = ops.publish) === null || _a === void 0 ? void 0 : _a.execute) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
36
60
|
push({
|
|
37
61
|
status: 'info',
|
|
38
62
|
title: 'Publishing draft...'
|
|
39
63
|
});
|
|
40
|
-
} }, void 0) }, void 0));
|
|
64
|
+
} }, void 0) }), void 0));
|
|
41
65
|
}
|
|
42
|
-
if (!published
|
|
43
|
-
return (_jsx(Flex, { padding: 5, align: 'center', justify: 'center', height: 'fill', children: _jsx(Spinner, { width: 4, muted: true }, void 0) }, void 0));
|
|
66
|
+
if (!(published === null || published === void 0 ? void 0 : published._id)) {
|
|
67
|
+
return (_jsx(Flex, __assign({ padding: 5, align: 'center', justify: 'center', height: 'fill' }, { children: _jsx(Spinner, { width: 4, muted: true }, void 0) }), void 0));
|
|
44
68
|
}
|
|
45
|
-
return (_jsx(Box, { paddingBottom: 5, paddingRight: 2, children: _jsx(TreeEditor, { options: props.options, tree: treeValue, onChange: handleChange, patchPrefix: treeFieldKey }, void 0) }, void 0));
|
|
69
|
+
return (_jsx(Box, __assign({ paddingBottom: 5, paddingRight: 2 }, { children: _jsx(TreeEditor, { options: props.options, tree: treeValue, onChange: handleChange, patchPrefix: treeFieldKey }, void 0) }), void 0));
|
|
46
70
|
};
|
|
47
71
|
export default TreeDeskStructure;
|
|
@@ -1,10 +1,21 @@
|
|
|
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 } from "react/jsx-runtime";
|
|
2
13
|
import React from 'react';
|
|
3
14
|
import { FormField } from '@sanity/base/components';
|
|
4
15
|
import TreeEditor from './components/TreeEditor';
|
|
5
|
-
|
|
6
|
-
return (_jsx(FormField, { description: props.type.description, title: props.type.title, __unstable_markers: props.markers, __unstable_presence: props.presence,
|
|
16
|
+
var TreeInputComponent = React.forwardRef(function (props, _ref) {
|
|
17
|
+
return (_jsx(FormField, __assign({ description: props.type.description, title: props.type.title, __unstable_markers: props.markers, __unstable_presence: props.presence,
|
|
7
18
|
// @ts-expect-error FormField's TS definitions are off - it doesn't include compareValue
|
|
8
|
-
compareValue: props.compareValue, children: _jsx(TreeEditor, { options: props.type.options, tree: props.value || [], onChange: props.onChange }, void 0) }, void 0));
|
|
19
|
+
compareValue: props.compareValue }, { children: _jsx(TreeEditor, { options: props.type.options, tree: props.value || [], onChange: props.onChange }, void 0) }), void 0));
|
|
9
20
|
});
|
|
10
21
|
export default TreeInputComponent;
|
|
@@ -1,12 +1,25 @@
|
|
|
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, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
13
|
import { Box, Card, Container, Heading, Stack, Text } from '@sanity/ui';
|
|
3
14
|
import React from 'react';
|
|
4
15
|
// React component that wraps text between two delimiters in a <pre> tag
|
|
5
|
-
|
|
6
|
-
|
|
16
|
+
var WrapCodeBlocks = function (_a) {
|
|
17
|
+
var text = _a.text;
|
|
18
|
+
return (_jsx(_Fragment, { children: text.split('`').map(function (part, i) { return (_jsx(React.Fragment, { children: i % 2 === 0 ? part : _jsx("code", { children: part }, void 0) }, i)); }) }, void 0));
|
|
7
19
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
20
|
+
var DeskWarning = function (_a) {
|
|
21
|
+
var subtitle = _a.subtitle, title = _a.title, children = _a.children;
|
|
22
|
+
return (_jsx(Container, __assign({ padding: 5, style: { maxWidth: '25rem' }, sizing: 'content' }, { children: _jsx(Card, __assign({ padding: 4, border: true, radius: 2, width: 0, tone: "caution" }, { children: _jsxs(Stack, __assign({ space: 3 }, { children: [_jsx(Heading, __assign({ size: 1 }, { children: title }), void 0), subtitle &&
|
|
23
|
+
subtitle.split('\\n').map(function (line) { return (_jsx(Text, __assign({ size: 1 }, { children: _jsx(WrapCodeBlocks, { text: line }, void 0) }), void 0)); }), children && _jsx(Box, __assign({ marginTop: 2 }, { children: children }), void 0)] }), void 0) }), void 0) }), void 0));
|
|
11
24
|
};
|
|
12
25
|
export default DeskWarning;
|
|
@@ -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 { TextWithTone } from '@sanity/base/components';
|
|
3
14
|
import { usePaneRouter } from '@sanity/desk-tool';
|
|
@@ -12,35 +23,36 @@ import DocumentPreviewStatus from './DocumentPreviewStatus';
|
|
|
12
23
|
* Renders a preview for each referenced document.
|
|
13
24
|
* Nested inside TreeNode.tsx
|
|
14
25
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
var DocumentInNode = function (props) {
|
|
27
|
+
var _a = props.item, _b = _a.value, _c = _b === void 0 ? {} : _b, reference = _c.reference, docType = _c.docType, draftId = _a.draftId, publishedId = _a.publishedId;
|
|
28
|
+
var _d = usePaneRouter(), routerPanesState = _d.routerPanesState, ChildLink = _d.ChildLink;
|
|
29
|
+
var allItemsStatus = useTreeOperations().allItemsStatus;
|
|
30
|
+
var isActive = React.useMemo(function () {
|
|
20
31
|
// If some pane is active with the current document `_id`, it's active
|
|
21
|
-
return routerPanesState.some((pane)
|
|
32
|
+
return routerPanesState.some(function (pane) { return pane.some(function (group) { return group.id === (reference === null || reference === void 0 ? void 0 : reference._ref); }); });
|
|
22
33
|
}, [routerPanesState]);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
var schemaType = React.useMemo(function () { return schema.get(docType); }, [docType]);
|
|
35
|
+
var LinkComponent = React.useMemo(function () {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
37
|
+
return React.forwardRef(function (linkProps, ref) { return (_jsx(ChildLink, __assign({}, linkProps, { childId: reference === null || reference === void 0 ? void 0 : reference._ref, ref: ref, childParameters: {
|
|
38
|
+
type: docType
|
|
39
|
+
} }), void 0)); });
|
|
40
|
+
}, [ChildLink, reference === null || reference === void 0 ? void 0 : reference._ref]);
|
|
41
|
+
if (!(reference === null || reference === void 0 ? void 0 : reference._ref)) {
|
|
30
42
|
return null;
|
|
31
43
|
}
|
|
32
|
-
return (_jsxs(Flex, { gap: 2, align: "center", style: { flex: 1 }, children: [publishedId || allItemsStatus !== 'success' ? (
|
|
44
|
+
return (_jsxs(Flex, __assign({ gap: 2, align: "center", style: { flex: 1 } }, { children: [publishedId || allItemsStatus !== 'success' ? (
|
|
33
45
|
/* Card loosely copied from @sanity/desk-tool's PaneItem.tsx */
|
|
34
|
-
_jsx(Card, { __unstable_focusRing: true, as: LinkComponent, tone: isActive ? 'primary' : 'default', padding: 1, radius: 2, flex: 1, "data-as": "a", "data-ui": "PaneItem", children: _jsx(Preview, { layout: "default", type: schemaType, value: { _ref: draftId || reference
|
|
46
|
+
_jsx(Card, __assign({ __unstable_focusRing: true, as: LinkComponent, tone: isActive ? 'primary' : 'default', padding: 1, radius: 2, flex: 1, "data-as": "a", "data-ui": "PaneItem" }, { children: _jsx(Preview, { layout: "default", type: schemaType, value: { _ref: draftId || (reference === null || reference === void 0 ? void 0 : reference._ref) }, status: _jsx(DocumentPreviewStatus, { draft: draftId
|
|
35
47
|
? {
|
|
36
48
|
_id: draftId,
|
|
37
49
|
_type: docType,
|
|
38
50
|
_updatedAt: props.item.draftUpdatedAt
|
|
39
51
|
}
|
|
40
52
|
: undefined, published: {
|
|
41
|
-
_id: reference
|
|
53
|
+
_id: reference === null || reference === void 0 ? void 0 : reference._ref,
|
|
42
54
|
_type: docType,
|
|
43
55
|
_updatedAt: props.item.publishedUpdatedAt
|
|
44
|
-
} }, void 0) }, void 0) }, void 0)) : (_jsx(Card, { padding: 3, radius: 1, flex: 1, children: _jsxs(Flex, { align: "center", children: [_jsx(Text, { size: 2, muted: true, style: { flex: 1 }, children: "Invalid document" }, void 0), _jsx(Tooltip, { placement: "left", portal: true, content: _jsx(Box, { padding: 3, children: _jsxs(Flex, { align: "flex-start", gap: 3, children: [_jsx(TextWithTone, { tone: "default", size: 3, children: _jsx(HelpCircleIcon, {}, void 0) }, void 0), _jsxs(Stack, { space: 3, children: [_jsx(Text, { as: "h2", size: 1, weight: "semibold", children: "This document is not valid" }, void 0), _jsxs(Text, { size: 1, children: ["ID: ", reference
|
|
56
|
+
} }, void 0) }, void 0) }), void 0)) : (_jsx(Card, __assign({ padding: 3, radius: 1, flex: 1 }, { children: _jsxs(Flex, __assign({ align: "center" }, { children: [_jsx(Text, __assign({ size: 2, muted: true, style: { flex: 1 } }, { children: "Invalid document" }), void 0), _jsx(Tooltip, __assign({ placement: "left", portal: true, content: _jsx(Box, __assign({ padding: 3 }, { children: _jsxs(Flex, __assign({ align: "flex-start", gap: 3 }, { children: [_jsx(TextWithTone, __assign({ tone: "default", size: 3 }, { children: _jsx(HelpCircleIcon, {}, void 0) }), void 0), _jsxs(Stack, __assign({ space: 3 }, { children: [_jsx(Text, __assign({ as: "h2", size: 1, weight: "semibold" }, { children: "This document is not valid" }), void 0), _jsxs(Text, __assign({ size: 1 }, { children: ["ID: ", reference === null || reference === void 0 ? void 0 : reference._ref] }), void 0)] }), void 0)] }), void 0) }), void 0) }, { children: _jsx(TextWithTone, __assign({ tone: "default", size: 2 }, { children: _jsx(HelpCircleIcon, {}, void 0) }), void 0) }), void 0)] }), void 0) }), void 0)), props.action] }), void 0));
|
|
45
57
|
};
|
|
46
58
|
export default DocumentInNode;
|
|
@@ -1,16 +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 { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
13
|
import { TextWithTone } from '@sanity/base/components';
|
|
3
14
|
import { useTimeAgo } from '@sanity/base/hooks';
|
|
4
15
|
import { EditIcon, PublishIcon } from '@sanity/icons';
|
|
5
16
|
import { Box, Inline, Text, Tooltip } from '@sanity/ui';
|
|
6
|
-
export function TimeAgo(
|
|
7
|
-
|
|
8
|
-
|
|
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));
|
|
9
21
|
}
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
};
|
|
12
30
|
// Adapted from @sanity\desk-tool\src\components\paneItem\helpers.tsx
|
|
13
|
-
|
|
14
|
-
|
|
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));
|
|
15
34
|
};
|
|
16
35
|
export default DocumentPreviewStatus;
|
|
@@ -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 { IntentLink } from '@sanity/base/components';
|
|
3
14
|
import { CopyIcon, EllipsisVerticalIcon, LaunchIcon, RemoveCircleIcon } from '@sanity/icons';
|
|
@@ -8,17 +19,19 @@ import useTreeOperations from '../utils/useTreeOperations';
|
|
|
8
19
|
* Applicable only to nodes inside the main tree.
|
|
9
20
|
* Unadded items have their actions defined in TreeEditor.
|
|
10
21
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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;
|
|
15
27
|
// Adapted from @sanity\form-builder\src\inputs\ReferenceInput\ArrayItemReferenceInput.tsx
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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));
|
|
23
36
|
};
|
|
24
37
|
export default NodeActions;
|
|
@@ -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
13
|
import { Box, Card, Stack, Text } from '@sanity/ui';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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(Box, { padding: 3, children: _jsx(Card, { padding: 5, radius: 2, border: true, tone: tone, style: {
|
|
24
|
+
return (_jsx(Box, __assign({ padding: 3 }, { children: _jsx(Card, __assign({ padding: 5, radius: 2, border: true, tone: tone, style: {
|
|
14
25
|
borderStyle: props.isOver ? undefined : 'dashed'
|
|
15
|
-
}, children: _jsxs(Stack, { space: 2, style: { textAlign: 'center' }, children: [_jsxs(Text, { size: 2, as: "h2", muted: true, children: [!props.isOver && props.title, isValid && 'Drop here', isInvalid && 'Invalid location or element'] }, void 0), props.subtitle && _jsx(Text, { size: 1, children: props.subtitle }, void 0), props.children] }, void 0) }, void 0) }, void 0));
|
|
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,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;
|