@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.
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +4 -0
- package/.idea/hierarchical-document-list.iml +11 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +7 -0
- package/.idea/vcs.xml +6 -0
- package/CHANGELOG.md +15 -0
- package/README.md +329 -297
- package/commitlint.config.js +3 -0
- package/lib/TreeDeskStructure.d.ts +8 -8
- package/lib/TreeDeskStructure.js +96 -96
- package/lib/TreeInputComponent.d.ts +19 -19
- package/lib/TreeInputComponent.js +50 -52
- package/lib/components/DeskWarning.d.ts +6 -6
- package/lib/components/DeskWarning.js +46 -46
- package/lib/components/DocumentInNode.d.ts +11 -11
- package/lib/components/DocumentInNode.js +81 -82
- package/lib/components/DocumentPreviewStatus.d.ts +7 -7
- package/lib/components/DocumentPreviewStatus.js +39 -39
- package/lib/components/NodeActions.d.ts +10 -10
- package/lib/components/NodeActions.js +61 -61
- package/lib/components/NodeContentRenderer.d.ts +8 -8
- package/lib/components/NodeContentRenderer.js +105 -105
- package/lib/components/PlaceholderDropzone.d.ts +9 -9
- package/lib/components/PlaceholderDropzone.js +30 -30
- package/lib/components/SuppressedDnDManager.d.ts +2 -0
- package/lib/components/SuppressedDnDManager.js +59 -0
- package/lib/components/TreeEditor.d.ts +12 -12
- package/lib/components/TreeEditor.js +74 -59
- package/lib/components/TreeEditorErrorBoundary.d.ts +16 -3
- package/lib/components/TreeEditorErrorBoundary.js +74 -59
- package/lib/components/TreeNodeRenderer.d.ts +3 -3
- package/lib/components/TreeNodeRenderer.js +59 -59
- package/lib/components/TreeNodeRendererScaffold.d.ts +4 -4
- package/lib/components/TreeNodeRendererScaffold.js +44 -44
- package/lib/createDeskHierarchy.d.ts +14 -14
- package/lib/createDeskHierarchy.js +84 -85
- package/lib/createHierarchicalSchemas.d.ts +98 -78
- package/lib/createHierarchicalSchemas.js +138 -138
- package/lib/hooks/useAllItems.d.ts +7 -7
- package/lib/hooks/useAllItems.js +119 -119
- package/lib/hooks/useLocalTree.d.ts +17 -17
- package/lib/hooks/useLocalTree.js +59 -59
- package/lib/hooks/useTreeOperations.d.ts +9 -9
- package/lib/hooks/useTreeOperations.js +39 -39
- package/lib/hooks/useTreeOperationsProvider.d.ts +14 -14
- package/lib/hooks/useTreeOperationsProvider.js +85 -85
- package/lib/index.d.ts +3 -3
- package/lib/index.js +12 -12
- package/lib/schemas/hierarchy.tree.d.ts +13 -13
- package/lib/schemas/hierarchy.tree.js +19 -19
- package/lib/types.d.ts +128 -0
- package/lib/types.js +2 -0
- package/lib/utils/flatDataToTree.d.ts +6 -6
- package/lib/utils/flatDataToTree.js +26 -26
- package/lib/utils/getAdjescentNodes.d.ts +12 -12
- package/lib/utils/getAdjescentNodes.js +19 -19
- package/lib/utils/getCommonTreeProps.d.ts +7 -7
- package/lib/utils/getCommonTreeProps.js +33 -33
- package/lib/utils/getTreeHeight.d.ts +3 -3
- package/lib/utils/getTreeHeight.js +11 -11
- package/lib/utils/gradientPatchAdapter.d.ts +4 -4
- package/lib/utils/gradientPatchAdapter.js +40 -42
- package/lib/utils/idUtils.d.ts +2 -2
- package/lib/utils/idUtils.js +13 -13
- package/lib/utils/injectNodeTypeInPatches.d.ts +12 -12
- package/lib/utils/injectNodeTypeInPatches.js +59 -58
- package/lib/utils/moveItemInArray.d.ts +5 -5
- package/lib/utils/moveItemInArray.js +26 -26
- package/lib/utils/throwError.d.ts +7 -7
- package/lib/utils/throwError.js +12 -12
- package/lib/utils/treeData.d.ts +18 -18
- package/lib/utils/treeData.js +118 -118
- package/lib/utils/treePatches.d.ts +15 -15
- package/lib/utils/treePatches.js +171 -171
- package/lint-staged.config.js +4 -0
- package/package.json +65 -55
- package/sanity.json +12 -12
- package/tsconfig.json +20 -20
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
22
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
23
|
-
if (ar || !(i in from)) {
|
|
24
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
25
|
-
ar[i] = from[i];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
29
|
-
};
|
|
30
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
-
};
|
|
33
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
var Patch = __importStar(require("@sanity/form-builder/lib/patch/patches"));
|
|
35
|
-
var PatchEvent_1 = __importDefault(require("@sanity/form-builder/PatchEvent"));
|
|
36
|
-
var treePatches_1 = require("../utils/treePatches");
|
|
37
|
-
function useTreeOperationsProvider(props) {
|
|
38
|
-
var localTree = props.localTree;
|
|
39
|
-
function runPatches(patches) {
|
|
40
|
-
var finalPatches = __spreadArray([
|
|
41
|
-
// Ensure tree array exists before any operation
|
|
42
|
-
Patch.setIfMissing([])
|
|
43
|
-
], (patches || []), true);
|
|
44
|
-
var patchEvent = PatchEvent_1.default.from(finalPatches);
|
|
45
|
-
if (props.patchPrefix) {
|
|
46
|
-
patchEvent = PatchEvent_1.default.from(finalPatches.map(function (patch) { return Patch.prefixPath(patch, props.patchPrefix); }));
|
|
47
|
-
}
|
|
48
|
-
props.onChange(patchEvent);
|
|
49
|
-
}
|
|
50
|
-
function handleMovedNode(data) {
|
|
51
|
-
runPatches((0, treePatches_1.getMovedNodePatch)(data));
|
|
52
|
-
}
|
|
53
|
-
function addItem(item) {
|
|
54
|
-
runPatches((0, treePatches_1.getAddItemPatch)(item));
|
|
55
|
-
}
|
|
56
|
-
function duplicateItem(nodeProps) {
|
|
57
|
-
runPatches((0, treePatches_1.getDuplicateItemPatch)(nodeProps));
|
|
58
|
-
}
|
|
59
|
-
function removeItem(nodeProps) {
|
|
60
|
-
runPatches((0, treePatches_1.getRemoveItemPatch)(nodeProps));
|
|
61
|
-
}
|
|
62
|
-
function moveItemUp(nodeProps) {
|
|
63
|
-
runPatches((0, treePatches_1.getMoveItemPatch)({
|
|
64
|
-
nodeProps: nodeProps,
|
|
65
|
-
localTree: localTree,
|
|
66
|
-
direction: 'up'
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
69
|
-
function moveItemDown(nodeProps) {
|
|
70
|
-
runPatches((0, treePatches_1.getMoveItemPatch)({
|
|
71
|
-
nodeProps: nodeProps,
|
|
72
|
-
localTree: localTree,
|
|
73
|
-
direction: 'down'
|
|
74
|
-
}));
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
handleMovedNode: handleMovedNode,
|
|
78
|
-
addItem: addItem,
|
|
79
|
-
removeItem: removeItem,
|
|
80
|
-
moveItemUp: moveItemUp,
|
|
81
|
-
moveItemDown: moveItemDown,
|
|
82
|
-
duplicateItem: duplicateItem
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
exports.default = useTreeOperationsProvider;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
22
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
23
|
+
if (ar || !(i in from)) {
|
|
24
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
25
|
+
ar[i] = from[i];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
29
|
+
};
|
|
30
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
31
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
var Patch = __importStar(require("@sanity/form-builder/lib/patch/patches"));
|
|
35
|
+
var PatchEvent_1 = __importDefault(require("@sanity/form-builder/PatchEvent"));
|
|
36
|
+
var treePatches_1 = require("../utils/treePatches");
|
|
37
|
+
function useTreeOperationsProvider(props) {
|
|
38
|
+
var localTree = props.localTree;
|
|
39
|
+
function runPatches(patches) {
|
|
40
|
+
var finalPatches = __spreadArray([
|
|
41
|
+
// Ensure tree array exists before any operation
|
|
42
|
+
Patch.setIfMissing([])
|
|
43
|
+
], (patches || []), true);
|
|
44
|
+
var patchEvent = PatchEvent_1.default.from(finalPatches);
|
|
45
|
+
if (props.patchPrefix) {
|
|
46
|
+
patchEvent = PatchEvent_1.default.from(finalPatches.map(function (patch) { return Patch.prefixPath(patch, props.patchPrefix); }));
|
|
47
|
+
}
|
|
48
|
+
props.onChange(patchEvent);
|
|
49
|
+
}
|
|
50
|
+
function handleMovedNode(data) {
|
|
51
|
+
runPatches((0, treePatches_1.getMovedNodePatch)(data));
|
|
52
|
+
}
|
|
53
|
+
function addItem(item) {
|
|
54
|
+
runPatches((0, treePatches_1.getAddItemPatch)(item));
|
|
55
|
+
}
|
|
56
|
+
function duplicateItem(nodeProps) {
|
|
57
|
+
runPatches((0, treePatches_1.getDuplicateItemPatch)(nodeProps));
|
|
58
|
+
}
|
|
59
|
+
function removeItem(nodeProps) {
|
|
60
|
+
runPatches((0, treePatches_1.getRemoveItemPatch)(nodeProps));
|
|
61
|
+
}
|
|
62
|
+
function moveItemUp(nodeProps) {
|
|
63
|
+
runPatches((0, treePatches_1.getMoveItemPatch)({
|
|
64
|
+
nodeProps: nodeProps,
|
|
65
|
+
localTree: localTree,
|
|
66
|
+
direction: 'up'
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
function moveItemDown(nodeProps) {
|
|
70
|
+
runPatches((0, treePatches_1.getMoveItemPatch)({
|
|
71
|
+
nodeProps: nodeProps,
|
|
72
|
+
localTree: localTree,
|
|
73
|
+
direction: 'down'
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
handleMovedNode: handleMovedNode,
|
|
78
|
+
addItem: addItem,
|
|
79
|
+
removeItem: removeItem,
|
|
80
|
+
moveItemUp: moveItemUp,
|
|
81
|
+
moveItemDown: moveItemDown,
|
|
82
|
+
duplicateItem: duplicateItem
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
exports.default = useTreeOperationsProvider;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default as createHierarchicalSchemas } from './createHierarchicalSchemas';
|
|
2
|
-
export { default as createDeskHierarchy } from './createDeskHierarchy';
|
|
3
|
-
export { default as flatDataToTree } from './utils/flatDataToTree';
|
|
1
|
+
export { default as createHierarchicalSchemas } from './createHierarchicalSchemas';
|
|
2
|
+
export { default as createDeskHierarchy } from './createDeskHierarchy';
|
|
3
|
+
export { default as flatDataToTree } from './utils/flatDataToTree';
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.flatDataToTree = exports.createDeskHierarchy = exports.createHierarchicalSchemas = void 0;
|
|
7
|
-
var createHierarchicalSchemas_1 = require("./createHierarchicalSchemas");
|
|
8
|
-
Object.defineProperty(exports, "createHierarchicalSchemas", { enumerable: true, get: function () { return __importDefault(createHierarchicalSchemas_1).default; } });
|
|
9
|
-
var createDeskHierarchy_1 = require("./createDeskHierarchy");
|
|
10
|
-
Object.defineProperty(exports, "createDeskHierarchy", { enumerable: true, get: function () { return __importDefault(createDeskHierarchy_1).default; } });
|
|
11
|
-
var flatDataToTree_1 = require("./utils/flatDataToTree");
|
|
12
|
-
Object.defineProperty(exports, "flatDataToTree", { enumerable: true, get: function () { return __importDefault(flatDataToTree_1).default; } });
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.flatDataToTree = exports.createDeskHierarchy = exports.createHierarchicalSchemas = void 0;
|
|
7
|
+
var createHierarchicalSchemas_1 = require("./createHierarchicalSchemas");
|
|
8
|
+
Object.defineProperty(exports, "createHierarchicalSchemas", { enumerable: true, get: function () { return __importDefault(createHierarchicalSchemas_1).default; } });
|
|
9
|
+
var createDeskHierarchy_1 = require("./createDeskHierarchy");
|
|
10
|
+
Object.defineProperty(exports, "createDeskHierarchy", { enumerable: true, get: function () { return __importDefault(createDeskHierarchy_1).default; } });
|
|
11
|
+
var flatDataToTree_1 = require("./utils/flatDataToTree");
|
|
12
|
+
Object.defineProperty(exports, "flatDataToTree", { enumerable: true, get: function () { return __importDefault(flatDataToTree_1).default; } });
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
declare const _default: {
|
|
2
|
-
name: string;
|
|
3
|
-
title: string;
|
|
4
|
-
type: string;
|
|
5
|
-
liveEdit: boolean;
|
|
6
|
-
fields: {
|
|
7
|
-
name: string;
|
|
8
|
-
title: string;
|
|
9
|
-
type: string;
|
|
10
|
-
hidden: boolean;
|
|
11
|
-
}[];
|
|
12
|
-
};
|
|
13
|
-
export default _default;
|
|
1
|
+
declare const _default: {
|
|
2
|
+
name: string;
|
|
3
|
+
title: string;
|
|
4
|
+
type: string;
|
|
5
|
+
liveEdit: boolean;
|
|
6
|
+
fields: {
|
|
7
|
+
name: string;
|
|
8
|
+
title: string;
|
|
9
|
+
type: string;
|
|
10
|
+
hidden: boolean;
|
|
11
|
+
}[];
|
|
12
|
+
};
|
|
13
|
+
export default _default;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = {
|
|
4
|
-
name: 'hierarchy.tree',
|
|
5
|
-
title: 'Hierarchical tree',
|
|
6
|
-
type: 'document',
|
|
7
|
-
// The plugin needs to define a `schemaType` with liveEdit enabled so that
|
|
8
|
-
// `useDocumentOperation` in TreeDeskStructure.tsx doesn't create drafts at every patch.
|
|
9
|
-
liveEdit: true,
|
|
10
|
-
// Let's avoid defining the actual hierarchical field, else GraphQL users won't be able to deploy schemas
|
|
11
|
-
fields: [
|
|
12
|
-
{
|
|
13
|
-
name: 'unusedField',
|
|
14
|
-
title: 'Unused field',
|
|
15
|
-
type: 'string',
|
|
16
|
-
hidden: true
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = {
|
|
4
|
+
name: 'hierarchy.tree',
|
|
5
|
+
title: 'Hierarchical tree',
|
|
6
|
+
type: 'document',
|
|
7
|
+
// The plugin needs to define a `schemaType` with liveEdit enabled so that
|
|
8
|
+
// `useDocumentOperation` in TreeDeskStructure.tsx doesn't create drafts at every patch.
|
|
9
|
+
liveEdit: true,
|
|
10
|
+
// Let's avoid defining the actual hierarchical field, else GraphQL users won't be able to deploy schemas
|
|
11
|
+
fields: [
|
|
12
|
+
{
|
|
13
|
+
name: 'unusedField',
|
|
14
|
+
title: 'Unused field',
|
|
15
|
+
type: 'string',
|
|
16
|
+
hidden: true
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
};
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { SanityDocument } from '@sanity/client';
|
|
2
|
+
import { ArraySchemaType, ObjectSchemaType } from '@sanity/types';
|
|
3
|
+
import { NodeRendererProps, TreeItem } from 'react-sortable-tree';
|
|
4
|
+
import { INTERNAL_NODE_TYPE, INTERNAL_NODE_VALUE_TYPE } from './utils/injectNodeTypeInPatches';
|
|
5
|
+
interface SanityReference {
|
|
6
|
+
_type: 'reference';
|
|
7
|
+
_ref: string;
|
|
8
|
+
_weak?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Objects saved to tree documents in Sanity's Content Lake
|
|
12
|
+
*/
|
|
13
|
+
export interface StoredTreeItem {
|
|
14
|
+
_key: string;
|
|
15
|
+
_type: typeof INTERNAL_NODE_TYPE | string;
|
|
16
|
+
value?: {
|
|
17
|
+
_type: typeof INTERNAL_NODE_VALUE_TYPE | string;
|
|
18
|
+
reference?: SanityReference;
|
|
19
|
+
docType?: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* _key of parent node
|
|
23
|
+
*/
|
|
24
|
+
parent?: string | null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Tree items enhanced locally in the client with info from `allItems` and `visibilityMap`.
|
|
28
|
+
* `allItems` stop here and never become LocalTreeItems as they aren't added to react-sortable-tree.
|
|
29
|
+
*
|
|
30
|
+
* See `useLocalTree.ts` and `dataToEditorTree()`.
|
|
31
|
+
*/
|
|
32
|
+
export interface EnhancedTreeItem extends StoredTreeItem {
|
|
33
|
+
expanded?: boolean | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Used by DocumentInNode to render the preview for drafts if they exist.
|
|
36
|
+
* Also informs document status icons.
|
|
37
|
+
*/
|
|
38
|
+
draftId?: string;
|
|
39
|
+
draftUpdatedAt?: string;
|
|
40
|
+
/**
|
|
41
|
+
* If not present, DocumentInNode will show up an error for invalid document.
|
|
42
|
+
* - undefined `publishedId` could mean the document is either deleted, or it doesn't match GROQ filters anymore
|
|
43
|
+
*/
|
|
44
|
+
publishedId?: string;
|
|
45
|
+
publishedUpdatedAt?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Tree items as found in the sortable tree itself.
|
|
49
|
+
*/
|
|
50
|
+
export declare type LocalTreeItem = EnhancedTreeItem & Pick<TreeItem, 'title' | 'children'>;
|
|
51
|
+
export interface TreeInputOptions {
|
|
52
|
+
/**
|
|
53
|
+
* What document types this hierarchy can refer to.
|
|
54
|
+
* Similar to the `to` property of the [reference field](https://www.sanity.io/docs/reference-type).
|
|
55
|
+
*/
|
|
56
|
+
referenceTo: string[];
|
|
57
|
+
/**
|
|
58
|
+
* Used to provide fine-grained filtering for documents.
|
|
59
|
+
*/
|
|
60
|
+
referenceOptions?: {
|
|
61
|
+
/**
|
|
62
|
+
* Static filter to apply to tree document queries.
|
|
63
|
+
*/
|
|
64
|
+
filter?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Parameters / variables to pass to the GROQ query ran to fetch documents.
|
|
67
|
+
*/
|
|
68
|
+
filterParams?: Record<string, unknown>;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* How deep should editors be allowed to nest items.
|
|
72
|
+
*/
|
|
73
|
+
maxDepth?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Schema type for your hierarchical documents.
|
|
76
|
+
* Refer to documentation on how to provide these schemas in your studio.
|
|
77
|
+
*
|
|
78
|
+
* Defautlt: 'hierarchy.tree' - this schema is bundled with the plugin
|
|
79
|
+
*/
|
|
80
|
+
documentType?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface TreeFieldSchema extends Omit<ArraySchemaType, 'of' | 'type' | 'inputComponent' | 'jsonType'> {
|
|
83
|
+
options: ArraySchemaType['options'] & TreeInputOptions;
|
|
84
|
+
}
|
|
85
|
+
export interface TreeNodeObjectSchema extends Omit<ObjectSchemaType, 'name' | 'fields' | 'type' | 'inputComponent' | 'jsonType'> {
|
|
86
|
+
options: ObjectSchemaType['options'] & TreeInputOptions;
|
|
87
|
+
}
|
|
88
|
+
export interface TreeDeskStructureProps extends TreeInputOptions {
|
|
89
|
+
/**
|
|
90
|
+
* _id of the document that will hold the tree data.
|
|
91
|
+
*/
|
|
92
|
+
documentId: string;
|
|
93
|
+
/**
|
|
94
|
+
* (Optional)
|
|
95
|
+
* Key for the field representing the hierarchical tree inside the document.
|
|
96
|
+
* `tree` by default.
|
|
97
|
+
*/
|
|
98
|
+
fieldKeyInDocument?: string;
|
|
99
|
+
}
|
|
100
|
+
export interface DocumentPair {
|
|
101
|
+
draft?: SanityDocument;
|
|
102
|
+
published?: SanityDocument;
|
|
103
|
+
}
|
|
104
|
+
export interface AllItems {
|
|
105
|
+
[publishedId: string]: DocumentPair | undefined;
|
|
106
|
+
}
|
|
107
|
+
declare type DocumentOperation<Payload = unknown> = {
|
|
108
|
+
execute?: (payload?: Payload) => void;
|
|
109
|
+
disabled?: boolean | string;
|
|
110
|
+
};
|
|
111
|
+
export interface DocumentOperations {
|
|
112
|
+
patch?: DocumentOperation<unknown[]>;
|
|
113
|
+
commit?: DocumentOperation;
|
|
114
|
+
del?: DocumentOperation;
|
|
115
|
+
delete?: DocumentOperation;
|
|
116
|
+
discardChanges?: DocumentOperation;
|
|
117
|
+
duplicate?: DocumentOperation;
|
|
118
|
+
restore?: DocumentOperation;
|
|
119
|
+
unpublish?: DocumentOperation;
|
|
120
|
+
publish?: DocumentOperation;
|
|
121
|
+
}
|
|
122
|
+
export interface VisibilityMap {
|
|
123
|
+
[_key: string]: boolean;
|
|
124
|
+
}
|
|
125
|
+
export interface NodeProps extends NodeRendererProps {
|
|
126
|
+
node: LocalTreeItem;
|
|
127
|
+
}
|
|
128
|
+
export {};
|
package/lib/types.js
ADDED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { StoredTreeItem } from '../types';
|
|
2
|
-
interface TreeItemWithChildren extends StoredTreeItem {
|
|
3
|
-
children?: TreeItemWithChildren[];
|
|
4
|
-
}
|
|
5
|
-
export default function flatDataToTree(data: StoredTreeItem[]): TreeItemWithChildren[];
|
|
6
|
-
export {};
|
|
1
|
+
import { StoredTreeItem } from '../types';
|
|
2
|
+
interface TreeItemWithChildren extends StoredTreeItem {
|
|
3
|
+
children?: TreeItemWithChildren[];
|
|
4
|
+
}
|
|
5
|
+
export default function flatDataToTree(data: StoredTreeItem[]): TreeItemWithChildren[];
|
|
6
|
+
export {};
|
|
@@ -1,26 +1,26 @@
|
|
|
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
|
-
var react_sortable_tree_1 = require("react-sortable-tree");
|
|
15
|
-
function flatDataToTree(data) {
|
|
16
|
-
return (0, react_sortable_tree_1.getTreeFromFlatData)({
|
|
17
|
-
flatData: data.map(function (item) { return (__assign(__assign({}, item), {
|
|
18
|
-
// if parent: undefined, the tree won't be constructed
|
|
19
|
-
parent: item.parent || null })); }),
|
|
20
|
-
getKey: function (item) { return item._key; },
|
|
21
|
-
getParentKey: function (item) { return item.parent; },
|
|
22
|
-
// without rootKey, the tree won't be constructed
|
|
23
|
-
rootKey: null
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
exports.default = flatDataToTree;
|
|
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
|
+
var react_sortable_tree_1 = require("react-sortable-tree");
|
|
15
|
+
function flatDataToTree(data) {
|
|
16
|
+
return (0, react_sortable_tree_1.getTreeFromFlatData)({
|
|
17
|
+
flatData: data.map(function (item) { return (__assign(__assign({}, item), {
|
|
18
|
+
// if parent: undefined, the tree won't be constructed
|
|
19
|
+
parent: item.parent || null })); }),
|
|
20
|
+
getKey: function (item) { return item._key; },
|
|
21
|
+
getParentKey: function (item) { return item.parent; },
|
|
22
|
+
// without rootKey, the tree won't be constructed
|
|
23
|
+
rootKey: null
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.default = flatDataToTree;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { FlatDataItem, TreeItem } from 'react-sortable-tree';
|
|
2
|
-
/**
|
|
3
|
-
* Gets adjescent non-children nodes of a given treeIndex.
|
|
4
|
-
*/
|
|
5
|
-
export default function getAdjescentNodes({ flatTree, node, treeIndex }: {
|
|
6
|
-
flatTree: FlatDataItem[];
|
|
7
|
-
node: TreeItem;
|
|
8
|
-
treeIndex: number;
|
|
9
|
-
}): {
|
|
10
|
-
leadingNode?: FlatDataItem;
|
|
11
|
-
followingNode?: FlatDataItem;
|
|
12
|
-
};
|
|
1
|
+
import { FlatDataItem, TreeItem } from 'react-sortable-tree';
|
|
2
|
+
/**
|
|
3
|
+
* Gets adjescent non-children nodes of a given treeIndex.
|
|
4
|
+
*/
|
|
5
|
+
export default function getAdjescentNodes({ flatTree, node, treeIndex }: {
|
|
6
|
+
flatTree: FlatDataItem[];
|
|
7
|
+
node: TreeItem;
|
|
8
|
+
treeIndex: number;
|
|
9
|
+
}): {
|
|
10
|
+
leadingNode?: FlatDataItem;
|
|
11
|
+
followingNode?: FlatDataItem;
|
|
12
|
+
};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Gets adjescent non-children nodes of a given treeIndex.
|
|
5
|
-
*/
|
|
6
|
-
function getAdjescentNodes(_a) {
|
|
7
|
-
var flatTree = _a.flatTree, node = _a.node, treeIndex = _a.treeIndex;
|
|
8
|
-
var leadingNode = flatTree
|
|
9
|
-
.slice(0, treeIndex)
|
|
10
|
-
.reverse()
|
|
11
|
-
// Disregard children nodes - these include the current node's key in their `path` array
|
|
12
|
-
.find(function (item) { return !item.path.includes(node._key); });
|
|
13
|
-
var followingNode = flatTree.slice(treeIndex + 1).find(function (item) { return !item.path.includes(node._key); });
|
|
14
|
-
return {
|
|
15
|
-
leadingNode: leadingNode,
|
|
16
|
-
followingNode: followingNode
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
exports.default = getAdjescentNodes;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Gets adjescent non-children nodes of a given treeIndex.
|
|
5
|
+
*/
|
|
6
|
+
function getAdjescentNodes(_a) {
|
|
7
|
+
var flatTree = _a.flatTree, node = _a.node, treeIndex = _a.treeIndex;
|
|
8
|
+
var leadingNode = flatTree
|
|
9
|
+
.slice(0, treeIndex)
|
|
10
|
+
.reverse()
|
|
11
|
+
// Disregard children nodes - these include the current node's key in their `path` array
|
|
12
|
+
.find(function (item) { return !item.path.includes(node._key); });
|
|
13
|
+
var followingNode = flatTree.slice(treeIndex + 1).find(function (item) { return !item.path.includes(node._key); });
|
|
14
|
+
return {
|
|
15
|
+
leadingNode: leadingNode,
|
|
16
|
+
followingNode: followingNode
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.default = getAdjescentNodes;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ReactSortableTreeProps } from 'react-sortable-tree';
|
|
2
|
-
export default function getCommonTreeProps({ placeholder }: {
|
|
3
|
-
placeholder: {
|
|
4
|
-
title: string;
|
|
5
|
-
subtitle?: string;
|
|
6
|
-
};
|
|
7
|
-
}): Partial<ReactSortableTreeProps>;
|
|
1
|
+
import { ReactSortableTreeProps } from 'react-sortable-tree';
|
|
2
|
+
export default function getCommonTreeProps({ placeholder }: {
|
|
3
|
+
placeholder: {
|
|
4
|
+
title: string;
|
|
5
|
+
subtitle?: string;
|
|
6
|
+
};
|
|
7
|
+
}): Partial<ReactSortableTreeProps>;
|
|
@@ -1,33 +1,33 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
18
|
-
var NodeContentRenderer_1 = __importDefault(require("../components/NodeContentRenderer"));
|
|
19
|
-
var PlaceholderDropzone_1 = __importDefault(require("../components/PlaceholderDropzone"));
|
|
20
|
-
var TreeNodeRenderer_1 = __importDefault(require("../components/TreeNodeRenderer"));
|
|
21
|
-
var getTreeHeight_1 = require("./getTreeHeight");
|
|
22
|
-
function getCommonTreeProps(_a) {
|
|
23
|
-
var placeholder = _a.placeholder;
|
|
24
|
-
return {
|
|
25
|
-
theme: {
|
|
26
|
-
nodeContentRenderer: NodeContentRenderer_1.default,
|
|
27
|
-
placeholderRenderer: function (props) { return (0, jsx_runtime_1.jsx)(PlaceholderDropzone_1.default, __assign({}, placeholder, props), void 0); },
|
|
28
|
-
treeNodeRenderer: TreeNodeRenderer_1.default,
|
|
29
|
-
rowHeight: getTreeHeight_1.ROW_HEIGHT
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
exports.default = getCommonTreeProps;
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
18
|
+
var NodeContentRenderer_1 = __importDefault(require("../components/NodeContentRenderer"));
|
|
19
|
+
var PlaceholderDropzone_1 = __importDefault(require("../components/PlaceholderDropzone"));
|
|
20
|
+
var TreeNodeRenderer_1 = __importDefault(require("../components/TreeNodeRenderer"));
|
|
21
|
+
var getTreeHeight_1 = require("./getTreeHeight");
|
|
22
|
+
function getCommonTreeProps(_a) {
|
|
23
|
+
var placeholder = _a.placeholder;
|
|
24
|
+
return {
|
|
25
|
+
theme: {
|
|
26
|
+
nodeContentRenderer: NodeContentRenderer_1.default,
|
|
27
|
+
placeholderRenderer: function (props) { return (0, jsx_runtime_1.jsx)(PlaceholderDropzone_1.default, __assign({}, placeholder, props), void 0); },
|
|
28
|
+
treeNodeRenderer: TreeNodeRenderer_1.default,
|
|
29
|
+
rowHeight: getTreeHeight_1.ROW_HEIGHT
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.default = getCommonTreeProps;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { TreeItem } from 'react-sortable-tree';
|
|
2
|
-
export declare const ROW_HEIGHT = 51;
|
|
3
|
-
export default function getTreeHeight(treeData: TreeItem[]): string;
|
|
1
|
+
import { TreeItem } from 'react-sortable-tree';
|
|
2
|
+
export declare const ROW_HEIGHT = 51;
|
|
3
|
+
export default function getTreeHeight(treeData: TreeItem[]): string;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ROW_HEIGHT = void 0;
|
|
4
|
-
var react_sortable_tree_1 = require("react-sortable-tree");
|
|
5
|
-
exports.ROW_HEIGHT = 51;
|
|
6
|
-
function getTreeHeight(treeData) {
|
|
7
|
-
var visibleNodeCount = (0, react_sortable_tree_1.getVisibleNodeCount)({ treeData: treeData });
|
|
8
|
-
// prettier-ignore
|
|
9
|
-
return "".concat(50 + (exports.ROW_HEIGHT * visibleNodeCount), "px");
|
|
10
|
-
}
|
|
11
|
-
exports.default = getTreeHeight;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ROW_HEIGHT = void 0;
|
|
4
|
+
var react_sortable_tree_1 = require("react-sortable-tree");
|
|
5
|
+
exports.ROW_HEIGHT = 51;
|
|
6
|
+
function getTreeHeight(treeData) {
|
|
7
|
+
var visibleNodeCount = (0, react_sortable_tree_1.getVisibleNodeCount)({ treeData: treeData });
|
|
8
|
+
// prettier-ignore
|
|
9
|
+
return "".concat(50 + (exports.ROW_HEIGHT * visibleNodeCount), "px");
|
|
10
|
+
}
|
|
11
|
+
exports.default = getTreeHeight;
|