@sanity/hierarchical-document-list 0.1.0-next.3 → 1.0.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/README.md +99 -26
- package/lib/TreeDeskStructure.d.ts +2 -1
- package/lib/TreeDeskStructure.js +82 -33
- package/lib/TreeInputComponent.d.ts +1 -1
- package/lib/TreeInputComponent.js +50 -8
- package/lib/components/DeskWarning.d.ts +1 -1
- package/lib/components/DeskWarning.js +43 -9
- package/lib/components/DocumentInNode.d.ts +1 -1
- package/lib/components/DocumentInNode.js +64 -28
- package/lib/components/DocumentPreviewStatus.d.ts +1 -1
- package/lib/components/DocumentPreviewStatus.js +36 -13
- package/lib/components/NodeActions.d.ts +1 -1
- package/lib/components/NodeActions.js +55 -18
- package/lib/components/NodeContentRenderer.js +75 -49
- package/lib/components/PlaceholderDropzone.d.ts +1 -1
- package/lib/components/PlaceholderDropzone.js +22 -9
- package/lib/components/TreeEditor.d.ts +1 -1
- package/lib/components/TreeEditor.js +48 -30
- package/lib/components/TreeEditorErrorBoundary.d.ts +2 -16
- package/lib/components/TreeEditorErrorBoundary.js +50 -31
- package/lib/components/TreeNodeRenderer.js +53 -16
- package/lib/components/TreeNodeRendererScaffold.d.ts +1 -1
- package/lib/components/TreeNodeRendererScaffold.js +19 -139
- package/lib/createDeskHierarchy.js +58 -27
- package/lib/createHierarchicalSchemas.d.ts +78 -0
- package/lib/createHierarchicalSchemas.js +138 -0
- package/lib/{utils → hooks}/useAllItems.d.ts +0 -0
- package/lib/hooks/useAllItems.js +119 -0
- package/lib/{utils → hooks}/useLocalTree.d.ts +0 -0
- package/lib/hooks/useLocalTree.js +59 -0
- package/lib/{utils → hooks}/useTreeOperations.d.ts +1 -1
- package/lib/hooks/useTreeOperations.js +39 -0
- package/lib/{utils → hooks}/useTreeOperationsProvider.d.ts +1 -1
- package/lib/hooks/useTreeOperationsProvider.js +85 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +12 -3
- package/lib/schemas/hierarchy.tree.d.ts +5 -15
- package/lib/schemas/hierarchy.tree.js +10 -21
- package/lib/utils/flatDataToTree.js +21 -9
- package/lib/utils/getAdjescentNodes.js +10 -6
- package/lib/utils/getCommonTreeProps.js +28 -10
- package/lib/utils/getTreeHeight.js +9 -5
- package/lib/utils/gradientPatchAdapter.js +26 -18
- package/lib/utils/idUtils.js +9 -2
- package/lib/utils/injectNodeTypeInPatches.d.ts +12 -0
- package/lib/utils/injectNodeTypeInPatches.js +58 -0
- package/lib/utils/moveItemInArray.js +18 -5
- package/lib/utils/throwError.d.ts +7 -0
- package/lib/utils/throwError.js +12 -0
- package/lib/utils/treeData.js +87 -46
- package/lib/utils/treePatches.js +96 -47
- package/package.json +1 -2
- package/tsconfig.json +4 -4
- package/lib/createHierarchicalField.d.ts +0 -8
- package/lib/createHierarchicalField.js +0 -36
- package/lib/utils/useAllItems.js +0 -92
- package/lib/utils/useLocalTree.js +0 -27
- package/lib/utils/useTreeOperations.js +0 -16
- package/lib/utils/useTreeOperationsProvider.js +0 -52
package/README.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# sanity-plugin-hierarchical-document-list
|
|
2
2
|
|
|
3
|
-
Plugin for
|
|
3
|
+
Plugin for visually organizing documents as hierarchies in the [Sanity studio](https://www.sanity.io/docs/sanity-studio). Applications include:
|
|
4
|
+
|
|
5
|
+
- Tables of content - such as a book's sections and chapters
|
|
6
|
+
- Navigational structure & menus - a website mega-menu with multiple levels, for example
|
|
7
|
+
- Taxonomy inheritance - "_Carbs_ is a parent of _Legumes_ which is a parent of _Beans_"
|
|
4
8
|
|
|
5
9
|

|
|
6
10
|
|
|
@@ -15,9 +19,9 @@ If you're looking for a way to order documents on a flat list, refer to [@sanity
|
|
|
15
19
|
sanity install @sanity/hierarchical-document-list
|
|
16
20
|
```
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
Once you've installed the plugin the next step is to add one or more hierarchy documents to your Structure Builder.
|
|
19
23
|
|
|
20
|
-
💡
|
|
24
|
+
💡 _To learn about custom desk structures, refer to the [Structure Builder docs](https://www.sanity.io/docs/overview-structure-builder)._
|
|
21
25
|
|
|
22
26
|
```js
|
|
23
27
|
// deskStructure.js
|
|
@@ -44,7 +48,10 @@ export default () => {
|
|
|
44
48
|
filterParams: {
|
|
45
49
|
acceptedStatuses: ['published', 'approved']
|
|
46
50
|
}
|
|
47
|
-
}
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
// ❓ Optional: limit the depth of your hierarachies
|
|
54
|
+
maxDept: 3
|
|
48
55
|
})
|
|
49
56
|
])
|
|
50
57
|
}
|
|
@@ -52,13 +59,15 @@ export default () => {
|
|
|
52
59
|
|
|
53
60
|
## How it works
|
|
54
61
|
|
|
55
|
-
The hierarchical data is stored in
|
|
62
|
+
The hierarchical data is stored in a centralized document with the `documentId` of your choosing. As compared to storing parent/child relationships in each individual document in the hierarchy, this makes it easier to implement different hierarchies for the same content according to the context.
|
|
56
63
|
|
|
57
|
-
|
|
64
|
+
This approach also simplifies querying the full structure - as you'll see in [querying data](#querying-data) below.
|
|
58
65
|
|
|
59
|
-
|
|
66
|
+
Keep in mind that this specified **document is live-edited**, meaning it has no draft and every change by editors will directly affect its published version.
|
|
60
67
|
|
|
61
|
-
|
|
68
|
+
Instead of requiring editors to manually add items one-by-one, the plugin will create a [GROQ](https://www.sanity.io/docs/overview-groq) query that matches all documents with a `_type` in the `referenceTo` option you specify, that also match the optional `referenceOptions.filter`. From these documents, editors are able to drag, nest and re-order them at will from the "Add more items" list.
|
|
69
|
+
|
|
70
|
+
If a document in the tree doesn't match the filters set, it'll keep existing in the data. This can happen if the document has a new, unfitting value, the configuration changed or it was deleted. Although the tree will still be publishable, editors will get a warning and won't be able to drag these faulty entries around.
|
|
62
71
|
|
|
63
72
|
## Querying data
|
|
64
73
|
|
|
@@ -170,6 +179,37 @@ const hierarchyDocument = await client.fetch(`*[_id == "book-v3-review-a"][0]{
|
|
|
170
179
|
}
|
|
171
180
|
}`)
|
|
172
181
|
const tree = flatDataToTree(data.tree)
|
|
182
|
+
|
|
183
|
+
/* Results in a recursively nested structure. Using the example data above:
|
|
184
|
+
{
|
|
185
|
+
"_key": "741b9edde2ba",
|
|
186
|
+
"_type": "hierarchy.node",
|
|
187
|
+
"value": {
|
|
188
|
+
"reference": {
|
|
189
|
+
"_ref": "75c47994-e6bb-487a-b8c9-b283f2436031",
|
|
190
|
+
"_type": "reference",
|
|
191
|
+
"_weak": true
|
|
192
|
+
},
|
|
193
|
+
"docType": "docs.article"
|
|
194
|
+
},
|
|
195
|
+
"parent": null,
|
|
196
|
+
"children": [
|
|
197
|
+
{
|
|
198
|
+
"_key": "f92eaeec96f7",
|
|
199
|
+
"_type": "hierarchy.node",
|
|
200
|
+
"value": {
|
|
201
|
+
"reference": {
|
|
202
|
+
"_ref": "7ad60a02-5d6e-47d8-92e2-6724cc130058",
|
|
203
|
+
"_type": "reference",
|
|
204
|
+
"_weak": true
|
|
205
|
+
},
|
|
206
|
+
"docType": "site.post"
|
|
207
|
+
},
|
|
208
|
+
"parent": "741b9edde2ba"
|
|
209
|
+
}
|
|
210
|
+
]
|
|
211
|
+
}
|
|
212
|
+
*/
|
|
173
213
|
```
|
|
174
214
|
|
|
175
215
|
After the transformation above, nodes with nested entries will include a `children` array. This data structure is recursive.
|
|
@@ -178,26 +218,51 @@ After the transformation above, nodes with nested entries will include a `childr
|
|
|
178
218
|
|
|
179
219
|
By default, this plugin will create and update documents of `_type: hierarchy.tree`, with a `tree` field holding the hierarchical data. When deploying a [GraphQL Sanity endpoint](https://www.sanity.io/docs/graphql), however, you'll need an explicit document type in your schema so that you get the proper types for querying.
|
|
180
220
|
|
|
181
|
-
To add this document type, create a
|
|
221
|
+
To add this document type, create a set of schemas with the `createHierarchicalSchemas`:
|
|
182
222
|
|
|
183
223
|
```js
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
224
|
+
// hierarchicalSchemas.js
|
|
225
|
+
import {createHierarchicalSchemas} from '@sanity/hierarchical-document-list'
|
|
226
|
+
|
|
227
|
+
export const hierarchicalOptions = {
|
|
228
|
+
// choose the document type name that suits you best
|
|
229
|
+
documentType: 'myCustomHierarchicalType',
|
|
230
|
+
|
|
231
|
+
// key for the tree field in the document - "tree" by default
|
|
232
|
+
fieldKeyInDocument: 'customTreeDataKey',
|
|
233
|
+
|
|
234
|
+
// Document types editors should be able to include in the hierarchy
|
|
235
|
+
referenceTo: ['site.page', 'site.post', 'docs.article', 'social.youtubeVideo'],
|
|
236
|
+
|
|
237
|
+
// ❓ Optional: provide filters and/or parameters for narrowing which documents can be added
|
|
238
|
+
referenceOptions: {
|
|
239
|
+
filter: 'status in $acceptedStatuses',
|
|
240
|
+
filterParams: {
|
|
241
|
+
acceptedStatuses: ['published', 'approved']
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
// ❓ Optional: limit the depth of your hierarachies
|
|
246
|
+
maxDept: 3
|
|
200
247
|
}
|
|
248
|
+
|
|
249
|
+
export default createHierarchicalSchemas(hierarchicalOptions)
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
And add these schemas to your studio:
|
|
253
|
+
|
|
254
|
+
```js
|
|
255
|
+
import createSchema from 'part:@sanity/base/schema-creator'
|
|
256
|
+
import schemaTypes from 'all:part:@sanity/base/schema-type'
|
|
257
|
+
import hierarchicalSchemas from './hierarchicalSchemas'
|
|
258
|
+
|
|
259
|
+
export default createSchema({
|
|
260
|
+
name: 'default',
|
|
261
|
+
types: schemaTypes.concat([
|
|
262
|
+
// ...Other schemas
|
|
263
|
+
...hierarchicalSchemas // add all items in the array of hierarchical schemas
|
|
264
|
+
])
|
|
265
|
+
})
|
|
201
266
|
```
|
|
202
267
|
|
|
203
268
|
Then, in your desk structure where you added the hierarchical document(s), include the right `documentType` and `fieldKeyInDocument` properties:
|
|
@@ -209,13 +274,21 @@ createDeskHierarchy({
|
|
|
209
274
|
fieldKeyInDocument: 'customTreeDataKey' // the name of the hierarchical field
|
|
210
275
|
// ...
|
|
211
276
|
})
|
|
277
|
+
|
|
278
|
+
// Ideally, use the same configuration object you defined in your schemas:
|
|
279
|
+
import {hierarchicalOptions} from './hierarchicalSchemas'
|
|
280
|
+
|
|
281
|
+
createDeskHierarchy({
|
|
282
|
+
...hierarchicalOptions
|
|
283
|
+
// ...
|
|
284
|
+
})
|
|
212
285
|
```
|
|
213
286
|
|
|
214
287
|
---
|
|
215
288
|
|
|
216
289
|
📌 **Note:** you can also use the method above to add hierarchies inside the schema of documents and objects, which would be editable outside the desk structure.
|
|
217
290
|
|
|
218
|
-
We're considering adapting this input to support any type of nest-able data, not only references. Until then, avoid
|
|
291
|
+
We're considering adapting this input to support any type of nest-able data, not only references. Until then, avoid using the generated schemas in nested schemas as, in these contexts, it lacks the necessary affordances for a good editing experience.
|
|
219
292
|
|
|
220
293
|
---
|
|
221
294
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
import { TreeDeskStructureProps } from './types';
|
|
3
3
|
interface ComponentProps {
|
|
4
4
|
options: TreeDeskStructureProps;
|
|
5
5
|
}
|
|
6
|
+
export declare const DEFAULT_FIELD_KEY = "tree";
|
|
6
7
|
declare const TreeDeskStructure: React.FC<ComponentProps>;
|
|
7
8
|
export default TreeDeskStructure;
|
package/lib/TreeDeskStructure.js
CHANGED
|
@@ -1,47 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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)) {
|
|
20
67
|
return;
|
|
21
68
|
}
|
|
22
|
-
patch.execute(toGradient(patchEvent.patches));
|
|
69
|
+
patch.execute((0, gradientPatchAdapter_1.toGradient)((0, injectNodeTypeInPatches_1.default)(patchEvent.patches, treeDocType)));
|
|
23
70
|
}, [patch]);
|
|
24
|
-
React.useEffect(()
|
|
25
|
-
|
|
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)) {
|
|
26
74
|
// If no published document, create it
|
|
27
|
-
patch.execute([{ setIfMissing: { [treeFieldKey]
|
|
75
|
+
patch.execute([{ setIfMissing: (_a = {}, _a[treeFieldKey] = [], _a) }]);
|
|
28
76
|
}
|
|
29
|
-
}, [published
|
|
77
|
+
}, [published === null || published === void 0 ? void 0 : published._id, patch]);
|
|
30
78
|
if (!liveEdit) {
|
|
31
|
-
return (
|
|
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));
|
|
32
80
|
}
|
|
33
|
-
if (draft
|
|
34
|
-
return (
|
|
35
|
-
|
|
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);
|
|
36
85
|
push({
|
|
37
86
|
status: 'info',
|
|
38
87
|
title: 'Publishing draft...'
|
|
39
88
|
});
|
|
40
|
-
} }, void 0) }, void 0));
|
|
89
|
+
} }, void 0) }), void 0));
|
|
41
90
|
}
|
|
42
|
-
if (!published
|
|
43
|
-
return (
|
|
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));
|
|
44
93
|
}
|
|
45
|
-
return (
|
|
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));
|
|
46
95
|
};
|
|
47
|
-
|
|
96
|
+
exports.default = TreeDeskStructure;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FormFieldPresence } from '@sanity/base/presence';
|
|
2
2
|
import { Marker, Path } from '@sanity/types';
|
|
3
|
-
import React from 'react';
|
|
3
|
+
import * as React from 'react';
|
|
4
4
|
import { StoredTreeItem, TreeFieldSchema } from './types';
|
|
5
5
|
export interface TreeInputComponentProps {
|
|
6
6
|
type: TreeFieldSchema;
|
|
@@ -1,10 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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,
|
|
7
49
|
// @ts-expect-error FormField's TS definitions are off - it doesn't include compareValue
|
|
8
|
-
compareValue: props.compareValue, children:
|
|
50
|
+
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));
|
|
9
51
|
});
|
|
10
|
-
|
|
52
|
+
exports.default = TreeInputComponent;
|
|
@@ -1,12 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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"));
|
|
4
36
|
// React component that wraps text between two delimiters in a <pre> tag
|
|
5
|
-
|
|
6
|
-
|
|
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));
|
|
7
40
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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));
|
|
11
45
|
};
|
|
12
|
-
|
|
46
|
+
exports.default = DeskWarning;
|
|
@@ -1,46 +1,82 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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"));
|
|
11
46
|
/**
|
|
12
47
|
* Renders a preview for each referenced document.
|
|
13
48
|
* Nested inside TreeNode.tsx
|
|
14
49
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 () {
|
|
20
55
|
// If some pane is active with the current document `_id`, it's active
|
|
21
|
-
return routerPanesState.some((pane)
|
|
56
|
+
return routerPanesState.some(function (pane) { return pane.some(function (group) { return group.id === (reference === null || reference === void 0 ? void 0 : reference._ref); }); });
|
|
22
57
|
}, [routerPanesState]);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
58
|
+
var schemaType = React.useMemo(function () { return schema_1.default.get(docType); }, [docType]);
|
|
59
|
+
var LinkComponent = React.useMemo(function () {
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
61
|
+
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: {
|
|
62
|
+
type: docType
|
|
63
|
+
} }), void 0)); });
|
|
64
|
+
}, [ChildLink, reference === null || reference === void 0 ? void 0 : reference._ref]);
|
|
65
|
+
if (!(reference === null || reference === void 0 ? void 0 : reference._ref)) {
|
|
30
66
|
return null;
|
|
31
67
|
}
|
|
32
|
-
return (
|
|
68
|
+
return ((0, jsx_runtime_1.jsxs)(ui_1.Flex, __assign({ gap: 2, align: "center", style: { flex: 1 } }, { children: [publishedId || allItemsStatus !== 'success' ? (
|
|
33
69
|
/* Card loosely copied from @sanity/desk-tool's PaneItem.tsx */
|
|
34
|
-
|
|
70
|
+
(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
|
|
35
71
|
? {
|
|
36
72
|
_id: draftId,
|
|
37
73
|
_type: docType,
|
|
38
74
|
_updatedAt: props.item.draftUpdatedAt
|
|
39
75
|
}
|
|
40
76
|
: undefined, published: {
|
|
41
|
-
_id: reference
|
|
77
|
+
_id: reference === null || reference === void 0 ? void 0 : reference._ref,
|
|
42
78
|
_type: docType,
|
|
43
79
|
_updatedAt: props.item.publishedUpdatedAt
|
|
44
|
-
} }, void 0) }, void 0) }, void 0)) : (
|
|
80
|
+
} }, 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));
|
|
45
81
|
};
|
|
46
|
-
|
|
82
|
+
exports.default = DocumentInNode;
|