@sanity/hierarchical-document-list 1.0.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.
Files changed (81) hide show
  1. package/.husky/commit-msg +4 -0
  2. package/.husky/pre-commit +4 -0
  3. package/.idea/hierarchical-document-list.iml +11 -0
  4. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  5. package/.idea/misc.xml +6 -0
  6. package/.idea/modules.xml +8 -0
  7. package/.idea/prettier.xml +7 -0
  8. package/.idea/vcs.xml +6 -0
  9. package/CHANGELOG.md +15 -0
  10. package/README.md +329 -297
  11. package/commitlint.config.js +3 -0
  12. package/lib/TreeDeskStructure.d.ts +8 -8
  13. package/lib/TreeDeskStructure.js +96 -96
  14. package/lib/TreeInputComponent.d.ts +19 -19
  15. package/lib/TreeInputComponent.js +50 -52
  16. package/lib/components/DeskWarning.d.ts +6 -6
  17. package/lib/components/DeskWarning.js +46 -46
  18. package/lib/components/DocumentInNode.d.ts +11 -11
  19. package/lib/components/DocumentInNode.js +81 -82
  20. package/lib/components/DocumentPreviewStatus.d.ts +7 -7
  21. package/lib/components/DocumentPreviewStatus.js +39 -39
  22. package/lib/components/NodeActions.d.ts +10 -10
  23. package/lib/components/NodeActions.js +61 -61
  24. package/lib/components/NodeContentRenderer.d.ts +8 -8
  25. package/lib/components/NodeContentRenderer.js +105 -105
  26. package/lib/components/PlaceholderDropzone.d.ts +9 -9
  27. package/lib/components/PlaceholderDropzone.js +30 -30
  28. package/lib/components/SuppressedDnDManager.d.ts +2 -0
  29. package/lib/components/SuppressedDnDManager.js +59 -0
  30. package/lib/components/TreeEditor.d.ts +12 -12
  31. package/lib/components/TreeEditor.js +74 -59
  32. package/lib/components/TreeEditorErrorBoundary.d.ts +16 -3
  33. package/lib/components/TreeEditorErrorBoundary.js +74 -59
  34. package/lib/components/TreeNodeRenderer.d.ts +3 -3
  35. package/lib/components/TreeNodeRenderer.js +59 -59
  36. package/lib/components/TreeNodeRendererScaffold.d.ts +4 -4
  37. package/lib/components/TreeNodeRendererScaffold.js +44 -44
  38. package/lib/createDeskHierarchy.d.ts +14 -14
  39. package/lib/createDeskHierarchy.js +84 -85
  40. package/lib/createHierarchicalSchemas.d.ts +98 -78
  41. package/lib/createHierarchicalSchemas.js +138 -138
  42. package/lib/hooks/useAllItems.d.ts +7 -7
  43. package/lib/hooks/useAllItems.js +119 -119
  44. package/lib/hooks/useLocalTree.d.ts +17 -17
  45. package/lib/hooks/useLocalTree.js +59 -59
  46. package/lib/hooks/useTreeOperations.d.ts +9 -9
  47. package/lib/hooks/useTreeOperations.js +39 -39
  48. package/lib/hooks/useTreeOperationsProvider.d.ts +14 -14
  49. package/lib/hooks/useTreeOperationsProvider.js +85 -85
  50. package/lib/index.d.ts +3 -3
  51. package/lib/index.js +12 -12
  52. package/lib/schemas/hierarchy.tree.d.ts +13 -13
  53. package/lib/schemas/hierarchy.tree.js +19 -19
  54. package/lib/types.d.ts +128 -0
  55. package/lib/types.js +2 -0
  56. package/lib/utils/flatDataToTree.d.ts +6 -6
  57. package/lib/utils/flatDataToTree.js +26 -26
  58. package/lib/utils/getAdjescentNodes.d.ts +12 -12
  59. package/lib/utils/getAdjescentNodes.js +19 -19
  60. package/lib/utils/getCommonTreeProps.d.ts +7 -7
  61. package/lib/utils/getCommonTreeProps.js +33 -33
  62. package/lib/utils/getTreeHeight.d.ts +3 -3
  63. package/lib/utils/getTreeHeight.js +11 -11
  64. package/lib/utils/gradientPatchAdapter.d.ts +4 -4
  65. package/lib/utils/gradientPatchAdapter.js +40 -42
  66. package/lib/utils/idUtils.d.ts +2 -2
  67. package/lib/utils/idUtils.js +13 -13
  68. package/lib/utils/injectNodeTypeInPatches.d.ts +12 -12
  69. package/lib/utils/injectNodeTypeInPatches.js +59 -58
  70. package/lib/utils/moveItemInArray.d.ts +5 -5
  71. package/lib/utils/moveItemInArray.js +26 -26
  72. package/lib/utils/throwError.d.ts +7 -7
  73. package/lib/utils/throwError.js +12 -12
  74. package/lib/utils/treeData.d.ts +18 -18
  75. package/lib/utils/treeData.js +118 -118
  76. package/lib/utils/treePatches.d.ts +15 -15
  77. package/lib/utils/treePatches.js +171 -171
  78. package/lint-staged.config.js +4 -0
  79. package/package.json +65 -55
  80. package/sanity.json +12 -12
  81. package/tsconfig.json +20 -20
@@ -1,82 +1,81 @@
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
- // 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)) {
66
- return null;
67
- }
68
- return ((0, jsx_runtime_1.jsxs)(ui_1.Flex, __assign({ gap: 2, align: "center", style: { flex: 1 } }, { children: [publishedId || allItemsStatus !== 'success' ? (
69
- /* Card loosely copied from @sanity/desk-tool's PaneItem.tsx */
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
71
- ? {
72
- _id: draftId,
73
- _type: docType,
74
- _updatedAt: props.item.draftUpdatedAt
75
- }
76
- : undefined, published: {
77
- _id: reference === null || reference === void 0 ? void 0 : reference._ref,
78
- _type: docType,
79
- _updatedAt: props.item.publishedUpdatedAt
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));
81
- };
82
- exports.default = DocumentInNode;
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 * 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;
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;
@@ -1,39 +1,39 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.TimeAgo = void 0;
15
- var jsx_runtime_1 = require("react/jsx-runtime");
16
- var components_1 = require("@sanity/base/components");
17
- var hooks_1 = require("@sanity/base/hooks");
18
- var icons_1 = require("@sanity/icons");
19
- var ui_1 = require("@sanity/ui");
20
- function TimeAgo(_a) {
21
- var time = _a.time;
22
- var timeAgo = (0, hooks_1.useTimeAgo)(time);
23
- return ((0, jsx_runtime_1.jsxs)("span", __assign({ title: timeAgo }, { children: [timeAgo, timeAgo.toLowerCase().trim().startsWith('just now') ? '' : ' ago'] }), void 0));
24
- }
25
- exports.TimeAgo = TimeAgo;
26
- var PublishedStatus = function (_a) {
27
- var document = _a.document;
28
- return ((0, jsx_runtime_1.jsx)(ui_1.Tooltip, __assign({ portal: true, content: (0, jsx_runtime_1.jsx)(ui_1.Box, __assign({ padding: 2 }, { children: (0, jsx_runtime_1.jsx)(ui_1.Text, __assign({ size: 1 }, { children: document ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Published ", document._updatedAt && (0, jsx_runtime_1.jsx)(TimeAgo, { time: document._updatedAt }, void 0)] }, void 0)) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: "Not published" }, void 0)) }), void 0) }), void 0) }, { children: (0, jsx_runtime_1.jsx)(components_1.TextWithTone, __assign({ tone: "positive", dimmed: !document, muted: !document, size: 1 }, { children: (0, jsx_runtime_1.jsx)(icons_1.PublishIcon, {}, void 0) }), void 0) }), void 0));
29
- };
30
- var DraftStatus = function (_a) {
31
- var document = _a.document;
32
- return ((0, jsx_runtime_1.jsx)(ui_1.Tooltip, __assign({ portal: true, content: (0, jsx_runtime_1.jsx)(ui_1.Box, __assign({ padding: 2 }, { children: (0, jsx_runtime_1.jsx)(ui_1.Text, __assign({ size: 1 }, { children: document ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Edited ", (document === null || document === void 0 ? void 0 : document._updatedAt) && (0, jsx_runtime_1.jsx)(TimeAgo, { time: document === null || document === void 0 ? void 0 : document._updatedAt }, void 0)] }, void 0)) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: "No unpublished edits" }, void 0)) }), void 0) }), void 0) }, { children: (0, jsx_runtime_1.jsx)(components_1.TextWithTone, __assign({ tone: "caution", dimmed: !document, muted: !document, size: 1 }, { children: (0, jsx_runtime_1.jsx)(icons_1.EditIcon, {}, void 0) }), void 0) }), void 0));
33
- };
34
- // Adapted from @sanity\desk-tool\src\components\paneItem\helpers.tsx
35
- var DocumentPreviewStatus = function (_a) {
36
- var draft = _a.draft, published = _a.published;
37
- return ((0, jsx_runtime_1.jsxs)(ui_1.Inline, __assign({ space: 4 }, { children: [(0, jsx_runtime_1.jsx)(PublishedStatus, { document: published }, void 0), (0, jsx_runtime_1.jsx)(DraftStatus, { document: draft }, void 0)] }), void 0));
38
- };
39
- exports.default = 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
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.TimeAgo = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var components_1 = require("@sanity/base/components");
17
+ var hooks_1 = require("@sanity/base/hooks");
18
+ var icons_1 = require("@sanity/icons");
19
+ var ui_1 = require("@sanity/ui");
20
+ function TimeAgo(_a) {
21
+ var time = _a.time;
22
+ var timeAgo = (0, hooks_1.useTimeAgo)(time);
23
+ return ((0, jsx_runtime_1.jsxs)("span", __assign({ title: timeAgo }, { children: [timeAgo, timeAgo.toLowerCase().trim().startsWith('just now') ? '' : ' ago'] }), void 0));
24
+ }
25
+ exports.TimeAgo = TimeAgo;
26
+ var PublishedStatus = function (_a) {
27
+ var document = _a.document;
28
+ return ((0, jsx_runtime_1.jsx)(ui_1.Tooltip, __assign({ portal: true, content: (0, jsx_runtime_1.jsx)(ui_1.Box, __assign({ padding: 2 }, { children: (0, jsx_runtime_1.jsx)(ui_1.Text, __assign({ size: 1 }, { children: document ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Published ", document._updatedAt && (0, jsx_runtime_1.jsx)(TimeAgo, { time: document._updatedAt }, void 0)] }, void 0)) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: "Not published" }, void 0)) }), void 0) }), void 0) }, { children: (0, jsx_runtime_1.jsx)(components_1.TextWithTone, __assign({ tone: "positive", dimmed: !document, muted: !document, size: 1 }, { children: (0, jsx_runtime_1.jsx)(icons_1.PublishIcon, {}, void 0) }), void 0) }), void 0));
29
+ };
30
+ var DraftStatus = function (_a) {
31
+ var document = _a.document;
32
+ return ((0, jsx_runtime_1.jsx)(ui_1.Tooltip, __assign({ portal: true, content: (0, jsx_runtime_1.jsx)(ui_1.Box, __assign({ padding: 2 }, { children: (0, jsx_runtime_1.jsx)(ui_1.Text, __assign({ size: 1 }, { children: document ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["Edited ", (document === null || document === void 0 ? void 0 : document._updatedAt) && (0, jsx_runtime_1.jsx)(TimeAgo, { time: document === null || document === void 0 ? void 0 : document._updatedAt }, void 0)] }, void 0)) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: "No unpublished edits" }, void 0)) }), void 0) }), void 0) }, { children: (0, jsx_runtime_1.jsx)(components_1.TextWithTone, __assign({ tone: "caution", dimmed: !document, muted: !document, size: 1 }, { children: (0, jsx_runtime_1.jsx)(icons_1.EditIcon, {}, void 0) }), void 0) }), void 0));
33
+ };
34
+ // Adapted from @sanity\desk-tool\src\components\paneItem\helpers.tsx
35
+ var DocumentPreviewStatus = function (_a) {
36
+ var draft = _a.draft, published = _a.published;
37
+ return ((0, jsx_runtime_1.jsxs)(ui_1.Inline, __assign({ space: 4 }, { children: [(0, jsx_runtime_1.jsx)(PublishedStatus, { document: published }, void 0), (0, jsx_runtime_1.jsx)(DraftStatus, { document: draft }, void 0)] }), void 0));
38
+ };
39
+ exports.default = DocumentPreviewStatus;
@@ -1,10 +1,10 @@
1
- import * as React from 'react';
2
- import { NodeProps } from '../types';
3
- /**
4
- * Applicable only to nodes inside the main tree.
5
- * Unadded items have their actions defined in TreeEditor.
6
- */
7
- declare const NodeActions: React.FC<{
8
- nodeProps: NodeProps;
9
- }>;
10
- export default NodeActions;
1
+ import * as React from 'react';
2
+ import { NodeProps } from '../types';
3
+ /**
4
+ * Applicable only to nodes inside the main tree.
5
+ * Unadded items have their actions defined in TreeEditor.
6
+ */
7
+ declare const NodeActions: React.FC<{
8
+ nodeProps: NodeProps;
9
+ }>;
10
+ export default NodeActions;
@@ -1,61 +1,61 @@
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 icons_1 = require("@sanity/icons");
39
- var ui_1 = require("@sanity/ui");
40
- var React = __importStar(require("react"));
41
- var useTreeOperations_1 = __importDefault(require("../hooks/useTreeOperations"));
42
- /**
43
- * Applicable only to nodes inside the main tree.
44
- * Unadded items have their actions defined in TreeEditor.
45
- */
46
- var NodeActions = function (_a) {
47
- var nodeProps = _a.nodeProps;
48
- var operations = (0, useTreeOperations_1.default)();
49
- var node = nodeProps.node;
50
- var _b = (node === null || node === void 0 ? void 0 : node.value) || {}, reference = _b.reference, docType = _b.docType;
51
- // Adapted from @sanity\form-builder\src\inputs\ReferenceInput\ArrayItemReferenceInput.tsx
52
- var OpenLink = React.useMemo(function () {
53
- // eslint-disable-next-line @typescript-eslint/no-shadow
54
- return React.forwardRef(function OpenLinkInner(restProps, _ref) {
55
- return ((0, jsx_runtime_1.jsx)(components_1.IntentLink, __assign({}, restProps, { intent: "edit", params: { id: reference === null || reference === void 0 ? void 0 : reference._ref, type: docType }, target: "_blank", rel: "noopener noreferrer", ref: _ref }), void 0));
56
- });
57
- }, [reference === null || reference === void 0 ? void 0 : reference._ref, docType]);
58
- var isValid = !!node.publishedId;
59
- return ((0, jsx_runtime_1.jsx)(ui_1.MenuButton, { button: (0, jsx_runtime_1.jsx)(ui_1.Button, { padding: 2, mode: "bleed", icon: icons_1.EllipsisVerticalIcon }, void 0), id: "hiearchical-doc-list--".concat(node._key, "-menuButton"), menu: (0, jsx_runtime_1.jsxs)(ui_1.Menu, { children: [(0, jsx_runtime_1.jsx)(ui_1.MenuItem, { text: "Remove from list", tone: "critical", icon: icons_1.RemoveCircleIcon, onClick: function () { return operations.removeItem(nodeProps); } }, void 0), (0, jsx_runtime_1.jsx)(ui_1.MenuItem, { text: "Duplicate item", icon: icons_1.CopyIcon, disabled: !isValid, onClick: function () { return operations.duplicateItem(nodeProps); } }, void 0), (0, jsx_runtime_1.jsx)(ui_1.MenuDivider, {}, void 0), (0, jsx_runtime_1.jsx)(ui_1.MenuItem, { text: "Open in new tab", icon: icons_1.LaunchIcon, disabled: !isValid, as: OpenLink, "data-as": "a" }, void 0)] }, void 0), placement: "right", popover: { portal: true, tone: 'default' } }, void 0));
60
- };
61
- exports.default = NodeActions;
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 icons_1 = require("@sanity/icons");
39
+ var ui_1 = require("@sanity/ui");
40
+ var React = __importStar(require("react"));
41
+ var useTreeOperations_1 = __importDefault(require("../hooks/useTreeOperations"));
42
+ /**
43
+ * Applicable only to nodes inside the main tree.
44
+ * Unadded items have their actions defined in TreeEditor.
45
+ */
46
+ var NodeActions = function (_a) {
47
+ var nodeProps = _a.nodeProps;
48
+ var operations = (0, useTreeOperations_1.default)();
49
+ var node = nodeProps.node;
50
+ var _b = (node === null || node === void 0 ? void 0 : node.value) || {}, reference = _b.reference, docType = _b.docType;
51
+ // Adapted from @sanity\form-builder\src\inputs\ReferenceInput\ArrayItemReferenceInput.tsx
52
+ var OpenLink = React.useMemo(function () {
53
+ // eslint-disable-next-line @typescript-eslint/no-shadow
54
+ return React.forwardRef(function OpenLinkInner(restProps, _ref) {
55
+ return ((0, jsx_runtime_1.jsx)(components_1.IntentLink, __assign({}, restProps, { intent: "edit", params: { id: reference === null || reference === void 0 ? void 0 : reference._ref, type: docType }, target: "_blank", rel: "noopener noreferrer", ref: _ref }), void 0));
56
+ });
57
+ }, [reference === null || reference === void 0 ? void 0 : reference._ref, docType]);
58
+ var isValid = !!node.publishedId;
59
+ return ((0, jsx_runtime_1.jsx)(ui_1.MenuButton, { button: (0, jsx_runtime_1.jsx)(ui_1.Button, { padding: 2, mode: "bleed", icon: icons_1.EllipsisVerticalIcon }, void 0), id: "hiearchical-doc-list--".concat(node._key, "-menuButton"), menu: (0, jsx_runtime_1.jsxs)(ui_1.Menu, { children: [(0, jsx_runtime_1.jsx)(ui_1.MenuItem, { text: "Remove from list", tone: "critical", icon: icons_1.RemoveCircleIcon, onClick: function () { return operations.removeItem(nodeProps); } }, void 0), (0, jsx_runtime_1.jsx)(ui_1.MenuItem, { text: "Duplicate item", icon: icons_1.CopyIcon, disabled: !isValid, onClick: function () { return operations.duplicateItem(nodeProps); } }, void 0), (0, jsx_runtime_1.jsx)(ui_1.MenuDivider, {}, void 0), (0, jsx_runtime_1.jsx)(ui_1.MenuItem, { text: "Open in new tab", icon: icons_1.LaunchIcon, disabled: !isValid, as: OpenLink, "data-as": "a" }, void 0)] }, void 0), placement: "right", popover: { portal: true, tone: 'default' } }, void 0));
60
+ };
61
+ exports.default = NodeActions;
@@ -1,8 +1,8 @@
1
- import { NodeRenderer } from 'react-sortable-tree';
2
- /**
3
- * Customization of react-sortable-tree's default node.
4
- * Created in order to use Sanity UI for styles.
5
- * Reference: https://github.com/frontend-collective/react-sortable-tree/blob/master/src/node-renderer-default.js
6
- */
7
- declare const NodeContentRenderer: NodeRenderer;
8
- export default NodeContentRenderer;
1
+ import { NodeRenderer } from 'react-sortable-tree';
2
+ /**
3
+ * Customization of react-sortable-tree's default node.
4
+ * Created in order to use Sanity UI for styles.
5
+ * Reference: https://github.com/frontend-collective/react-sortable-tree/blob/master/src/node-renderer-default.js
6
+ */
7
+ declare const NodeContentRenderer: NodeRenderer;
8
+ export default NodeContentRenderer;