@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.
Files changed (59) hide show
  1. package/README.md +99 -26
  2. package/lib/TreeDeskStructure.d.ts +2 -1
  3. package/lib/TreeDeskStructure.js +82 -33
  4. package/lib/TreeInputComponent.d.ts +1 -1
  5. package/lib/TreeInputComponent.js +50 -8
  6. package/lib/components/DeskWarning.d.ts +1 -1
  7. package/lib/components/DeskWarning.js +43 -9
  8. package/lib/components/DocumentInNode.d.ts +1 -1
  9. package/lib/components/DocumentInNode.js +64 -28
  10. package/lib/components/DocumentPreviewStatus.d.ts +1 -1
  11. package/lib/components/DocumentPreviewStatus.js +36 -13
  12. package/lib/components/NodeActions.d.ts +1 -1
  13. package/lib/components/NodeActions.js +55 -18
  14. package/lib/components/NodeContentRenderer.js +75 -49
  15. package/lib/components/PlaceholderDropzone.d.ts +1 -1
  16. package/lib/components/PlaceholderDropzone.js +22 -9
  17. package/lib/components/TreeEditor.d.ts +1 -1
  18. package/lib/components/TreeEditor.js +48 -30
  19. package/lib/components/TreeEditorErrorBoundary.d.ts +2 -16
  20. package/lib/components/TreeEditorErrorBoundary.js +50 -31
  21. package/lib/components/TreeNodeRenderer.js +53 -16
  22. package/lib/components/TreeNodeRendererScaffold.d.ts +1 -1
  23. package/lib/components/TreeNodeRendererScaffold.js +19 -139
  24. package/lib/createDeskHierarchy.js +58 -27
  25. package/lib/createHierarchicalSchemas.d.ts +78 -0
  26. package/lib/createHierarchicalSchemas.js +138 -0
  27. package/lib/{utils → hooks}/useAllItems.d.ts +0 -0
  28. package/lib/hooks/useAllItems.js +119 -0
  29. package/lib/{utils → hooks}/useLocalTree.d.ts +0 -0
  30. package/lib/hooks/useLocalTree.js +59 -0
  31. package/lib/{utils → hooks}/useTreeOperations.d.ts +1 -1
  32. package/lib/hooks/useTreeOperations.js +39 -0
  33. package/lib/{utils → hooks}/useTreeOperationsProvider.d.ts +1 -1
  34. package/lib/hooks/useTreeOperationsProvider.js +85 -0
  35. package/lib/index.d.ts +1 -1
  36. package/lib/index.js +12 -3
  37. package/lib/schemas/hierarchy.tree.d.ts +5 -15
  38. package/lib/schemas/hierarchy.tree.js +10 -21
  39. package/lib/utils/flatDataToTree.js +21 -9
  40. package/lib/utils/getAdjescentNodes.js +10 -6
  41. package/lib/utils/getCommonTreeProps.js +28 -10
  42. package/lib/utils/getTreeHeight.js +9 -5
  43. package/lib/utils/gradientPatchAdapter.js +26 -18
  44. package/lib/utils/idUtils.js +9 -2
  45. package/lib/utils/injectNodeTypeInPatches.d.ts +12 -0
  46. package/lib/utils/injectNodeTypeInPatches.js +58 -0
  47. package/lib/utils/moveItemInArray.js +18 -5
  48. package/lib/utils/throwError.d.ts +7 -0
  49. package/lib/utils/throwError.js +12 -0
  50. package/lib/utils/treeData.js +87 -46
  51. package/lib/utils/treePatches.js +96 -47
  52. package/package.json +1 -2
  53. package/tsconfig.json +4 -4
  54. package/lib/createHierarchicalField.d.ts +0 -8
  55. package/lib/createHierarchicalField.js +0 -36
  56. package/lib/utils/useAllItems.js +0 -92
  57. package/lib/utils/useLocalTree.js +0 -27
  58. package/lib/utils/useTreeOperations.js +0 -16
  59. 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 editing hierarchical references in the [Sanity studio](https://www.sanity.io/docs/sanity-studio).
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
  ![Screenshot of the plugin](/screenshot-1.jpg)
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
- With the plugin installed, you'll add the following to your Desk Structure:
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
- 💡 _If you don't have a custom desk structure, refer to the [Structure Builder docs](https://www.sanity.io/docs/overview-structure-builder) to learn how to do so._
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 the document specified by the `documentId` of your choosing. As compared to storing `parent` fields in each individual document in the hierarchy, this makes it easier to implement different hierarchies for the same content according to the context, and also simplifies querying the full structure - as you'll see in [Querying data](#querying-data) below.
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
- Keep in mind that **this document is live-edited**, meaning it has no draft and every change by editors will directly affect its published version.
64
+ This approach also simplifies querying the full structure - as you'll see in [querying data](#querying-data) below.
58
65
 
59
- Instead of manually adding 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 `referenceTo`, that also match the optional `referenceOptions.filter`. From these documents, editors are able to drag, nest and re-order them at will from the "Items not added" list.
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
- If a document in the tree doesn't match the filters set, it'll still exist in the tree. 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 entries around.
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 new document schema similar to the following:
221
+ To add this document type, create a set of schemas with the `createHierarchicalSchemas`:
182
222
 
183
223
  ```js
184
- import {createHierarchicalField} from '@sanity/hierarchical-document-list'
185
-
186
- export default {
187
- name: 'myCustomHierarchicalType',
188
- title: 'Custom document type for holding hierarchical data',
189
- type: 'document',
190
- liveEdit: true, // 👉 Important: set liveEdit to `true` to ensure the UI works properly
191
- fields: [
192
- createHierarchicalField({
193
- name: 'customTreeDataKey', // key for the tree field in the document
194
- title: 'Custom tree',
195
- options: {
196
- referenceTo: ['category']
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 `createHierarchicalField` for fields in nested schemas as, in these contexts, it lacks the necessary affordances for a good editing experience.
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;
@@ -1,47 +1,96 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { PublishIcon } from '@sanity/icons';
3
- import { useDocumentOperation, useEditState } from '@sanity/react-hooks';
4
- import { Box, Button, Flex, Spinner, useToast } from '@sanity/ui';
5
- import React from 'react';
6
- import DeskWarning from './components/DeskWarning';
7
- import TreeEditor from './components/TreeEditor';
8
- import { toGradient } from './utils/gradientPatchAdapter';
9
- const DEFAULT_TREE_FIELD_KEY = 'tree';
10
- const DEFAULT_TREE_DOC_TYPE = 'hierarchy.tree';
11
- const TreeDeskStructure = (props) => {
12
- const treeDocType = props.options.documentType || DEFAULT_TREE_DOC_TYPE;
13
- const treeFieldKey = props.options.fieldKeyInDocument || DEFAULT_TREE_FIELD_KEY;
14
- const { published, draft, liveEdit } = useEditState(props.options.documentId, treeDocType);
15
- const { patch, ...ops } = useDocumentOperation(props.options.documentId, treeDocType);
16
- const { push } = useToast();
17
- const treeValue = (published?.[treeFieldKey] || []);
18
- const handleChange = React.useCallback((patchEvent) => {
19
- if (!patch?.execute) {
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
- if (!published?._id && patch?.execute && !patch?.disabled) {
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?._id, patch]);
77
+ }, [published === null || published === void 0 ? void 0 : published._id, patch]);
30
78
  if (!liveEdit) {
31
- 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));
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?._id) {
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
- ops.publish?.execute?.();
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?._id) {
43
- return (_jsx(Flex, { padding: 5, align: 'center', justify: 'center', height: 'fill', children: _jsx(Spinner, { width: 4, muted: true }, void 0) }, void 0));
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 (_jsx(Box, { paddingBottom: 5, paddingRight: 2, children: _jsx(TreeEditor, { options: props.options, tree: treeValue, onChange: handleChange, patchPrefix: treeFieldKey }, void 0) }, void 0));
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
- export default TreeDeskStructure;
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
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React from 'react';
3
- import { FormField } from '@sanity/base/components';
4
- import TreeEditor from './components/TreeEditor';
5
- const TreeInputComponent = React.forwardRef((props, _ref) => {
6
- return (_jsx(FormField, { description: props.type.description, title: props.type.title, __unstable_markers: props.markers, __unstable_presence: props.presence,
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: _jsx(TreeEditor, { options: props.type.options, tree: props.value || [], onChange: props.onChange }, void 0) }, void 0));
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
- export default TreeInputComponent;
52
+ exports.default = TreeInputComponent;
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import * as React from 'react';
2
2
  declare const DeskWarning: React.FC<{
3
3
  title: string;
4
4
  subtitle?: string;
@@ -1,12 +1,46 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Box, Card, Container, Heading, Stack, Text } from '@sanity/ui';
3
- import React from 'react';
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
- const WrapCodeBlocks = ({ text }) => {
6
- return (_jsx(_Fragment, { children: text.split('`').map((part, i) => (_jsx(React.Fragment, { children: i % 2 === 0 ? part : _jsx("code", { children: part }, void 0) }, i))) }, void 0));
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
- const DeskWarning = ({ subtitle, title, children }) => {
9
- return (_jsx(Container, { padding: 5, style: { maxWidth: '25rem' }, sizing: 'content', children: _jsx(Card, { padding: 4, border: true, radius: 2, width: 0, tone: "caution", children: _jsxs(Stack, { space: 3, children: [_jsx(Heading, { size: 1, children: title }, void 0), subtitle &&
10
- subtitle.split('\\n').map((line) => (_jsx(Text, { size: 1, children: _jsx(WrapCodeBlocks, { text: line }, void 0) }, void 0))), children && _jsx(Box, { marginTop: 2, children: children }, void 0)] }, void 0) }, void 0) }, void 0));
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
- export default DeskWarning;
46
+ exports.default = DeskWarning;
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import * as React from 'react';
2
2
  import { LocalTreeItem } from '../types';
3
3
  /**
4
4
  * Renders a preview for each referenced document.
@@ -1,46 +1,82 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { TextWithTone } from '@sanity/base/components';
3
- import { usePaneRouter } from '@sanity/desk-tool';
4
- import { HelpCircleIcon } from '@sanity/icons';
5
- import { Box, Card, Flex, Stack, Text, Tooltip } from '@sanity/ui';
6
- import Preview from 'part:@sanity/base/preview';
7
- import schema from 'part:@sanity/base/schema';
8
- import React from 'react';
9
- import useTreeOperations from '../utils/useTreeOperations';
10
- import DocumentPreviewStatus from './DocumentPreviewStatus';
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
- const DocumentInNode = (props) => {
16
- const { value: { reference, docType } = {}, draftId, publishedId } = props.item;
17
- const { routerPanesState, ChildLink } = usePaneRouter();
18
- const { allItemsStatus } = useTreeOperations();
19
- const isActive = React.useMemo(() => {
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) => pane.some((group) => group.id === reference?._ref));
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
- const schemaType = React.useMemo(() => schema.get(docType), [docType]);
24
- const LinkComponent = React.useMemo(() =>
25
- // eslint-disable-next-line @typescript-eslint/no-shadow
26
- React.forwardRef((linkProps, ref) => (_jsx(ChildLink, { ...linkProps, childId: reference?._ref, ref: ref, childParameters: {
27
- type: docType
28
- } }, void 0))), [ChildLink, reference?._ref]);
29
- if (!reference?._ref) {
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 (_jsxs(Flex, { gap: 2, align: "center", style: { flex: 1 }, children: [publishedId || allItemsStatus !== 'success' ? (
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
- _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?._ref }, status: _jsx(DocumentPreviewStatus, { draft: draftId
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?._ref,
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)) : (_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?._ref] }, void 0)] }, void 0)] }, void 0) }, void 0), children: _jsx(TextWithTone, { tone: "default", size: 2, children: _jsx(HelpCircleIcon, {}, void 0) }, void 0) }, void 0)] }, void 0) }, void 0)), props.action] }, 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
- export default DocumentInNode;
82
+ exports.default = DocumentInNode;
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import * as React from 'react';
2
2
  import { DocumentPair } from '../types';
3
3
  export declare function TimeAgo({ time }: {
4
4
  time: string | Date;