@sanity/hierarchical-document-list 0.1.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 -224
- package/commitlint.config.js +3 -0
- package/lib/TreeDeskStructure.d.ts +8 -7
- package/lib/TreeDeskStructure.js +96 -71
- package/lib/TreeInputComponent.d.ts +19 -19
- package/lib/TreeInputComponent.js +50 -21
- package/lib/components/DeskWarning.d.ts +6 -6
- package/lib/components/DeskWarning.js +46 -25
- package/lib/components/DocumentInNode.d.ts +11 -11
- package/lib/components/DocumentInNode.js +81 -58
- package/lib/components/DocumentPreviewStatus.d.ts +7 -7
- package/lib/components/DocumentPreviewStatus.js +39 -35
- package/lib/components/NodeActions.d.ts +10 -10
- package/lib/components/NodeActions.js +61 -37
- package/lib/components/NodeContentRenderer.d.ts +8 -8
- package/lib/components/NodeContentRenderer.js +105 -81
- package/lib/components/PlaceholderDropzone.d.ts +9 -9
- package/lib/components/PlaceholderDropzone.js +30 -28
- 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 -54
- package/lib/components/TreeEditorErrorBoundary.d.ts +16 -17
- package/lib/components/TreeEditorErrorBoundary.js +74 -69
- package/lib/components/TreeNodeRenderer.d.ts +3 -3
- package/lib/components/TreeNodeRenderer.js +59 -35
- package/lib/components/TreeNodeRendererScaffold.d.ts +4 -4
- package/lib/components/TreeNodeRendererScaffold.js +44 -42
- package/lib/createDeskHierarchy.d.ts +14 -14
- package/lib/createDeskHierarchy.js +84 -67
- package/lib/createHierarchicalSchemas.d.ts +98 -0
- package/lib/createHierarchicalSchemas.js +138 -0
- package/lib/{utils → hooks}/useAllItems.d.ts +7 -7
- package/lib/{utils → hooks}/useAllItems.js +119 -94
- package/lib/{utils → hooks}/useLocalTree.d.ts +17 -17
- package/lib/{utils → hooks}/useLocalTree.js +59 -37
- package/lib/{utils → hooks}/useTreeOperations.d.ts +9 -9
- package/lib/hooks/useTreeOperations.js +39 -0
- package/lib/{utils → hooks}/useTreeOperationsProvider.d.ts +14 -14
- package/lib/hooks/useTreeOperationsProvider.js +85 -0
- package/lib/index.d.ts +3 -3
- package/lib/index.js +12 -3
- package/lib/schemas/hierarchy.tree.d.ts +13 -23
- package/lib/schemas/hierarchy.tree.js +19 -31
- 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 -23
- package/lib/utils/getAdjescentNodes.d.ts +12 -12
- package/lib/utils/getAdjescentNodes.js +19 -16
- package/lib/utils/getCommonTreeProps.d.ts +7 -7
- package/lib/utils/getCommonTreeProps.js +33 -27
- package/lib/utils/getTreeHeight.d.ts +3 -3
- package/lib/utils/getTreeHeight.js +11 -7
- package/lib/utils/gradientPatchAdapter.d.ts +4 -4
- package/lib/utils/gradientPatchAdapter.js +40 -35
- package/lib/utils/idUtils.d.ts +2 -2
- package/lib/utils/idUtils.js +13 -8
- package/lib/utils/injectNodeTypeInPatches.d.ts +12 -0
- package/lib/utils/injectNodeTypeInPatches.js +59 -0
- package/lib/utils/moveItemInArray.d.ts +5 -5
- package/lib/utils/moveItemInArray.js +26 -23
- package/lib/utils/throwError.d.ts +7 -0
- package/lib/utils/throwError.js +12 -0
- package/lib/utils/treeData.d.ts +18 -18
- package/lib/utils/treeData.js +118 -106
- package/lib/utils/treePatches.d.ts +15 -15
- package/lib/utils/treePatches.js +171 -141
- package/lint-staged.config.js +4 -0
- package/package.json +65 -56
- package/sanity.json +12 -12
- package/tsconfig.json +20 -20
- package/lib/createHierarchicalField.d.ts +0 -8
- package/lib/createHierarchicalField.js +0 -51
- package/lib/utils/useTreeOperations.js +0 -16
- package/lib/utils/useTreeOperationsProvider.js +0 -60
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { TreeDeskStructureProps } from './types';
|
|
3
|
-
interface ComponentProps {
|
|
4
|
-
options: TreeDeskStructureProps;
|
|
5
|
-
}
|
|
6
|
-
declare const
|
|
7
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { TreeDeskStructureProps } from './types';
|
|
3
|
+
interface ComponentProps {
|
|
4
|
+
options: TreeDeskStructureProps;
|
|
5
|
+
}
|
|
6
|
+
export declare const DEFAULT_FIELD_KEY = "tree";
|
|
7
|
+
declare const TreeDeskStructure: React.FC<ComponentProps>;
|
|
8
|
+
export default TreeDeskStructure;
|
package/lib/TreeDeskStructure.js
CHANGED
|
@@ -1,71 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
var
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
};
|
|
71
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
33
|
+
var t = {};
|
|
34
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
35
|
+
t[p] = s[p];
|
|
36
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
37
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
38
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
39
|
+
t[p[i]] = s[p[i]];
|
|
40
|
+
}
|
|
41
|
+
return t;
|
|
42
|
+
};
|
|
43
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
44
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
45
|
+
};
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
exports.DEFAULT_FIELD_KEY = void 0;
|
|
48
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
49
|
+
var icons_1 = require("@sanity/icons");
|
|
50
|
+
var react_hooks_1 = require("@sanity/react-hooks");
|
|
51
|
+
var ui_1 = require("@sanity/ui");
|
|
52
|
+
var React = __importStar(require("react"));
|
|
53
|
+
var DeskWarning_1 = __importDefault(require("./components/DeskWarning"));
|
|
54
|
+
var TreeEditor_1 = __importDefault(require("./components/TreeEditor"));
|
|
55
|
+
var gradientPatchAdapter_1 = require("./utils/gradientPatchAdapter");
|
|
56
|
+
var injectNodeTypeInPatches_1 = __importStar(require("./utils/injectNodeTypeInPatches"));
|
|
57
|
+
exports.DEFAULT_FIELD_KEY = 'tree';
|
|
58
|
+
var TreeDeskStructure = function (props) {
|
|
59
|
+
var treeDocType = props.options.documentType || injectNodeTypeInPatches_1.DEFAULT_DOC_TYPE;
|
|
60
|
+
var treeFieldKey = props.options.fieldKeyInDocument || exports.DEFAULT_FIELD_KEY;
|
|
61
|
+
var _a = (0, react_hooks_1.useEditState)(props.options.documentId, treeDocType), published = _a.published, draft = _a.draft, liveEdit = _a.liveEdit;
|
|
62
|
+
var _b = (0, react_hooks_1.useDocumentOperation)(props.options.documentId, treeDocType), patch = _b.patch, ops = __rest(_b, ["patch"]);
|
|
63
|
+
var push = (0, ui_1.useToast)().push;
|
|
64
|
+
var treeValue = ((published === null || published === void 0 ? void 0 : published[treeFieldKey]) || []);
|
|
65
|
+
var handleChange = React.useCallback(function (patchEvent) {
|
|
66
|
+
if (!(patch === null || patch === void 0 ? void 0 : patch.execute)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
patch.execute((0, gradientPatchAdapter_1.toGradient)((0, injectNodeTypeInPatches_1.default)(patchEvent.patches, treeDocType)));
|
|
70
|
+
}, [patch]);
|
|
71
|
+
React.useEffect(function () {
|
|
72
|
+
var _a;
|
|
73
|
+
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)) {
|
|
74
|
+
// If no published document, create it
|
|
75
|
+
patch.execute([{ setIfMissing: (_a = {}, _a[treeFieldKey] = [], _a) }]);
|
|
76
|
+
}
|
|
77
|
+
}, [published === null || published === void 0 ? void 0 : published._id, patch]);
|
|
78
|
+
if (!liveEdit) {
|
|
79
|
+
return ((0, jsx_runtime_1.jsx)(DeskWarning_1.default, { 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));
|
|
80
|
+
}
|
|
81
|
+
if (draft === null || draft === void 0 ? void 0 : draft._id) {
|
|
82
|
+
return ((0, jsx_runtime_1.jsx)(DeskWarning_1.default, __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\n published document." }, { children: (0, jsx_runtime_1.jsx)(ui_1.Button, { fontSize: 1, tone: "positive", text: "Publish draft", icon: icons_1.PublishIcon, onClick: function () {
|
|
83
|
+
var _a, _b;
|
|
84
|
+
(_b = (_a = ops.publish) === null || _a === void 0 ? void 0 : _a.execute) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
85
|
+
push({
|
|
86
|
+
status: 'info',
|
|
87
|
+
title: 'Publishing draft...'
|
|
88
|
+
});
|
|
89
|
+
} }, void 0) }), void 0));
|
|
90
|
+
}
|
|
91
|
+
if (!(published === null || published === void 0 ? void 0 : published._id)) {
|
|
92
|
+
return ((0, jsx_runtime_1.jsx)(ui_1.Flex, __assign({ padding: 5, align: 'center', justify: 'center', height: 'fill' }, { children: (0, jsx_runtime_1.jsx)(ui_1.Spinner, { width: 4, muted: true }, void 0) }), void 0));
|
|
93
|
+
}
|
|
94
|
+
return ((0, jsx_runtime_1.jsx)(ui_1.Box, __assign({ paddingBottom: 5, paddingRight: 2 }, { children: (0, jsx_runtime_1.jsx)(TreeEditor_1.default, { options: props.options, tree: treeValue, onChange: handleChange, patchPrefix: treeFieldKey }, void 0) }), void 0));
|
|
95
|
+
};
|
|
96
|
+
exports.default = TreeDeskStructure;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { FormFieldPresence } from '@sanity/base/presence';
|
|
2
|
-
import { Marker, Path } from '@sanity/types';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { StoredTreeItem, TreeFieldSchema } from './types';
|
|
5
|
-
export interface TreeInputComponentProps {
|
|
6
|
-
type: TreeFieldSchema;
|
|
7
|
-
value: StoredTreeItem[];
|
|
8
|
-
compareValue: StoredTreeItem[];
|
|
9
|
-
markers: Marker[];
|
|
10
|
-
level: number;
|
|
11
|
-
onChange: (event: unknown) => void;
|
|
12
|
-
onFocus: (path: Path) => void;
|
|
13
|
-
onBlur: () => void;
|
|
14
|
-
focusPath: Path;
|
|
15
|
-
readOnly: boolean;
|
|
16
|
-
presence: FormFieldPresence[];
|
|
17
|
-
}
|
|
18
|
-
declare const TreeInputComponent: React.FC<TreeInputComponentProps>;
|
|
19
|
-
export default TreeInputComponent;
|
|
1
|
+
import { FormFieldPresence } from '@sanity/base/presence';
|
|
2
|
+
import { Marker, Path } from '@sanity/types';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { StoredTreeItem, TreeFieldSchema } from './types';
|
|
5
|
+
export interface TreeInputComponentProps {
|
|
6
|
+
type: TreeFieldSchema;
|
|
7
|
+
value: StoredTreeItem[];
|
|
8
|
+
compareValue: StoredTreeItem[];
|
|
9
|
+
markers: Marker[];
|
|
10
|
+
level: number;
|
|
11
|
+
onChange: (event: unknown) => void;
|
|
12
|
+
onFocus: (path: Path) => void;
|
|
13
|
+
onBlur: () => void;
|
|
14
|
+
focusPath: Path;
|
|
15
|
+
readOnly: boolean;
|
|
16
|
+
presence: FormFieldPresence[];
|
|
17
|
+
}
|
|
18
|
+
declare const TreeInputComponent: React.FC<TreeInputComponentProps>;
|
|
19
|
+
export default TreeInputComponent;
|
|
@@ -1,21 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
33
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
37
|
+
var components_1 = require("@sanity/base/components");
|
|
38
|
+
var PatchEvent_1 = __importDefault(require("@sanity/form-builder/PatchEvent"));
|
|
39
|
+
var React = __importStar(require("react"));
|
|
40
|
+
var TreeEditor_1 = __importDefault(require("./components/TreeEditor"));
|
|
41
|
+
var injectNodeTypeInPatches_1 = __importStar(require("./utils/injectNodeTypeInPatches"));
|
|
42
|
+
var TreeInputComponent = React.forwardRef(function (props) {
|
|
43
|
+
var documentType = props.type.options.documentType || injectNodeTypeInPatches_1.DEFAULT_DOC_TYPE;
|
|
44
|
+
var onChange = React.useCallback(function (patch) {
|
|
45
|
+
var patches = (0, injectNodeTypeInPatches_1.default)(patch === null || patch === void 0 ? void 0 : patch.patches, documentType);
|
|
46
|
+
props.onChange(new PatchEvent_1.default(patches));
|
|
47
|
+
}, [props.onChange]);
|
|
48
|
+
return ((0, jsx_runtime_1.jsx)(components_1.FormField, __assign({ description: props.type.description, title: props.type.title, __unstable_markers: props.markers, __unstable_presence: props.presence, compareValue: props.compareValue }, { children: (0, jsx_runtime_1.jsx)(TreeEditor_1.default, { options: props.type.options, tree: props.value || [], onChange: onChange }, void 0) }), void 0));
|
|
49
|
+
});
|
|
50
|
+
exports.default = TreeInputComponent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
declare const DeskWarning: React.FC<{
|
|
3
|
-
title: string;
|
|
4
|
-
subtitle?: string;
|
|
5
|
-
}>;
|
|
6
|
-
export default DeskWarning;
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
declare const DeskWarning: React.FC<{
|
|
3
|
+
title: string;
|
|
4
|
+
subtitle?: string;
|
|
5
|
+
}>;
|
|
6
|
+
export default DeskWarning;
|
|
@@ -1,25 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
34
|
+
var ui_1 = require("@sanity/ui");
|
|
35
|
+
var React = __importStar(require("react"));
|
|
36
|
+
// React component that wraps text between two delimiters in a <pre> tag
|
|
37
|
+
var WrapCodeBlocks = function (_a) {
|
|
38
|
+
var text = _a.text;
|
|
39
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: text.split('`').map(function (part, i) { return ((0, jsx_runtime_1.jsx)(React.Fragment, { children: i % 2 === 0 ? part : (0, jsx_runtime_1.jsx)("code", { children: part }, void 0) }, i)); }) }, void 0));
|
|
40
|
+
};
|
|
41
|
+
var DeskWarning = function (_a) {
|
|
42
|
+
var subtitle = _a.subtitle, title = _a.title, children = _a.children;
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(ui_1.Container, __assign({ padding: 5, style: { maxWidth: '25rem' }, sizing: 'content' }, { children: (0, jsx_runtime_1.jsx)(ui_1.Card, __assign({ padding: 4, border: true, radius: 2, width: 0, tone: "caution" }, { children: (0, jsx_runtime_1.jsxs)(ui_1.Stack, __assign({ space: 3 }, { children: [(0, jsx_runtime_1.jsx)(ui_1.Heading, __assign({ size: 1 }, { children: title }), void 0), subtitle &&
|
|
44
|
+
subtitle.split('\\n').map(function (line) { return ((0, jsx_runtime_1.jsx)(ui_1.Text, __assign({ size: 1 }, { children: (0, jsx_runtime_1.jsx)(WrapCodeBlocks, { text: line }, void 0) }), void 0)); }), children && (0, jsx_runtime_1.jsx)(ui_1.Box, __assign({ marginTop: 2 }, { children: children }), void 0)] }), void 0) }), void 0) }), void 0));
|
|
45
|
+
};
|
|
46
|
+
exports.default = DeskWarning;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { LocalTreeItem } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* Renders a preview for each referenced document.
|
|
5
|
-
* Nested inside TreeNode.tsx
|
|
6
|
-
*/
|
|
7
|
-
declare const DocumentInNode: React.FC<{
|
|
8
|
-
item: LocalTreeItem;
|
|
9
|
-
action?: React.ReactNode;
|
|
10
|
-
}>;
|
|
11
|
-
export default DocumentInNode;
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { LocalTreeItem } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Renders a preview for each referenced document.
|
|
5
|
+
* Nested inside TreeNode.tsx
|
|
6
|
+
*/
|
|
7
|
+
declare const DocumentInNode: React.FC<{
|
|
8
|
+
item: LocalTreeItem;
|
|
9
|
+
action?: React.ReactNode;
|
|
10
|
+
}>;
|
|
11
|
+
export default DocumentInNode;
|
|
@@ -1,58 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
|
|
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
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
33
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
|
+
};
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
37
|
+
var components_1 = require("@sanity/base/components");
|
|
38
|
+
var desk_tool_1 = require("@sanity/desk-tool");
|
|
39
|
+
var icons_1 = require("@sanity/icons");
|
|
40
|
+
var ui_1 = require("@sanity/ui");
|
|
41
|
+
var preview_1 = __importDefault(require("part:@sanity/base/preview"));
|
|
42
|
+
var schema_1 = __importDefault(require("part:@sanity/base/schema"));
|
|
43
|
+
var React = __importStar(require("react"));
|
|
44
|
+
var useTreeOperations_1 = __importDefault(require("../hooks/useTreeOperations"));
|
|
45
|
+
var DocumentPreviewStatus_1 = __importDefault(require("./DocumentPreviewStatus"));
|
|
46
|
+
/**
|
|
47
|
+
* Renders a preview for each referenced document.
|
|
48
|
+
* Nested inside TreeNode.tsx
|
|
49
|
+
*/
|
|
50
|
+
var DocumentInNode = function (props) {
|
|
51
|
+
var _a = props.item, _b = _a.value, _c = _b === void 0 ? {} : _b, reference = _c.reference, docType = _c.docType, draftId = _a.draftId, publishedId = _a.publishedId;
|
|
52
|
+
var _d = (0, desk_tool_1.usePaneRouter)(), routerPanesState = _d.routerPanesState, ChildLink = _d.ChildLink;
|
|
53
|
+
var allItemsStatus = (0, useTreeOperations_1.default)().allItemsStatus;
|
|
54
|
+
var isActive = React.useMemo(function () {
|
|
55
|
+
// If some pane is active with the current document `_id`, it's active
|
|
56
|
+
return routerPanesState.some(function (pane) { return pane.some(function (group) { return group.id === (reference === null || reference === void 0 ? void 0 : reference._ref); }); });
|
|
57
|
+
}, [routerPanesState]);
|
|
58
|
+
var schemaType = React.useMemo(function () { return schema_1.default.get(docType); }, [docType]);
|
|
59
|
+
var LinkComponent = React.useMemo(function () {
|
|
60
|
+
return React.forwardRef(function (linkProps, ref) { return ((0, jsx_runtime_1.jsx)(ChildLink, __assign({}, linkProps, { childId: reference === null || reference === void 0 ? void 0 : reference._ref, ref: ref, childParameters: {
|
|
61
|
+
type: docType
|
|
62
|
+
} }), void 0)); });
|
|
63
|
+
}, [ChildLink, reference === null || reference === void 0 ? void 0 : reference._ref]);
|
|
64
|
+
if (!(reference === null || reference === void 0 ? void 0 : reference._ref)) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return ((0, jsx_runtime_1.jsxs)(ui_1.Flex, __assign({ gap: 2, align: "center", style: { flex: 1 } }, { children: [publishedId || allItemsStatus !== 'success' ? (
|
|
68
|
+
/* Card loosely copied from @sanity/desk-tool's PaneItem.tsx */
|
|
69
|
+
(0, jsx_runtime_1.jsx)(ui_1.Card, __assign({ __unstable_focusRing: true, as: LinkComponent, tone: isActive ? 'primary' : 'default', padding: 1, radius: 2, flex: 1, "data-as": "a", "data-ui": "PaneItem" }, { children: (0, jsx_runtime_1.jsx)(preview_1.default, { layout: "default", type: schemaType, value: { _ref: draftId || (reference === null || reference === void 0 ? void 0 : reference._ref) }, status: (0, jsx_runtime_1.jsx)(DocumentPreviewStatus_1.default, { draft: draftId
|
|
70
|
+
? {
|
|
71
|
+
_id: draftId,
|
|
72
|
+
_type: docType,
|
|
73
|
+
_updatedAt: props.item.draftUpdatedAt
|
|
74
|
+
}
|
|
75
|
+
: undefined, published: {
|
|
76
|
+
_id: reference === null || reference === void 0 ? void 0 : reference._ref,
|
|
77
|
+
_type: docType,
|
|
78
|
+
_updatedAt: props.item.publishedUpdatedAt
|
|
79
|
+
} }, void 0) }, void 0) }), void 0)) : ((0, jsx_runtime_1.jsx)(ui_1.Card, __assign({ padding: 3, radius: 1, flex: 1 }, { children: (0, jsx_runtime_1.jsxs)(ui_1.Flex, __assign({ align: "center" }, { children: [(0, jsx_runtime_1.jsx)(ui_1.Text, __assign({ size: 2, muted: true, style: { flex: 1 } }, { children: "Invalid document" }), void 0), (0, jsx_runtime_1.jsx)(ui_1.Tooltip, __assign({ placement: "left", portal: true, content: (0, jsx_runtime_1.jsx)(ui_1.Box, __assign({ padding: 3 }, { children: (0, jsx_runtime_1.jsxs)(ui_1.Flex, __assign({ align: "flex-start", gap: 3 }, { children: [(0, jsx_runtime_1.jsx)(components_1.TextWithTone, __assign({ tone: "default", size: 3 }, { children: (0, jsx_runtime_1.jsx)(icons_1.HelpCircleIcon, {}, void 0) }), void 0), (0, jsx_runtime_1.jsxs)(ui_1.Stack, __assign({ space: 3 }, { children: [(0, jsx_runtime_1.jsx)(ui_1.Text, __assign({ as: "h2", size: 1, weight: "semibold" }, { children: "This document is not valid" }), void 0), (0, jsx_runtime_1.jsxs)(ui_1.Text, __assign({ size: 1 }, { children: ["ID: ", reference === null || reference === void 0 ? void 0 : reference._ref] }), void 0)] }), void 0)] }), void 0) }), void 0) }, { children: (0, jsx_runtime_1.jsx)(components_1.TextWithTone, __assign({ tone: "default", size: 2 }, { children: (0, jsx_runtime_1.jsx)(icons_1.HelpCircleIcon, {}, void 0) }), void 0) }), void 0)] }), void 0) }), void 0)), props.action] }), void 0));
|
|
80
|
+
};
|
|
81
|
+
exports.default = DocumentInNode;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { DocumentPair } from '../types';
|
|
3
|
-
export declare function TimeAgo({ time }: {
|
|
4
|
-
time: string | Date;
|
|
5
|
-
}): JSX.Element;
|
|
6
|
-
declare const DocumentPreviewStatus: React.FC<DocumentPair>;
|
|
7
|
-
export default DocumentPreviewStatus;
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { DocumentPair } from '../types';
|
|
3
|
+
export declare function TimeAgo({ time }: {
|
|
4
|
+
time: string | Date;
|
|
5
|
+
}): JSX.Element;
|
|
6
|
+
declare const DocumentPreviewStatus: React.FC<DocumentPair>;
|
|
7
|
+
export default DocumentPreviewStatus;
|