@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,78 +1,98 @@
|
|
|
1
|
-
import { ArraySchemaType } from '@sanity/types';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { TreeDeskStructureProps, TreeFieldSchema } from './types';
|
|
4
|
-
declare type SchemaOptions = Omit<TreeDeskStructureProps, 'documentId' | 'maxDepth'>;
|
|
5
|
-
export declare function createHierarchicalField({ name, title, options, ...rest }: TreeFieldSchema): Omit<ArraySchemaType, 'type' | 'jsonType' | 'of'> & {
|
|
6
|
-
type: string;
|
|
7
|
-
inputComponent: React.FC<any>;
|
|
8
|
-
of?: any[];
|
|
9
|
-
};
|
|
10
|
-
export default function createHierarchicalSchemas(options: SchemaOptions): ({
|
|
11
|
-
name: string;
|
|
12
|
-
title: string;
|
|
13
|
-
type: string;
|
|
14
|
-
fields: ({
|
|
15
|
-
name: string;
|
|
16
|
-
type: string;
|
|
17
|
-
} | {
|
|
18
|
-
name: string;
|
|
19
|
-
type: string;
|
|
20
|
-
title: string;
|
|
21
|
-
fields: ({
|
|
22
|
-
name: string;
|
|
23
|
-
type: string;
|
|
24
|
-
weak?: undefined;
|
|
25
|
-
to?: undefined;
|
|
26
|
-
options?: undefined;
|
|
27
|
-
} | {
|
|
28
|
-
name: string;
|
|
29
|
-
type: string;
|
|
30
|
-
weak: boolean;
|
|
31
|
-
to: {
|
|
32
|
-
type: string;
|
|
33
|
-
}[];
|
|
34
|
-
options: {
|
|
35
|
-
filter?: string | undefined;
|
|
36
|
-
filterParams?: Record<string, unknown> | undefined;
|
|
37
|
-
} | undefined;
|
|
38
|
-
})[];
|
|
39
|
-
})[];
|
|
40
|
-
} | {
|
|
41
|
-
name: string;
|
|
42
|
-
title: string;
|
|
43
|
-
type: string;
|
|
44
|
-
of: ({
|
|
45
|
-
name: string;
|
|
46
|
-
title: string;
|
|
47
|
-
type: string;
|
|
48
|
-
fields: ({
|
|
49
|
-
name: string;
|
|
50
|
-
type: string;
|
|
51
|
-
} | {
|
|
52
|
-
name: string;
|
|
53
|
-
type: string;
|
|
54
|
-
title: string;
|
|
55
|
-
fields: ({
|
|
56
|
-
name: string;
|
|
57
|
-
type: string;
|
|
58
|
-
weak?: undefined;
|
|
59
|
-
to?: undefined;
|
|
60
|
-
options?: undefined;
|
|
61
|
-
} | {
|
|
62
|
-
name: string;
|
|
63
|
-
type: string;
|
|
64
|
-
weak: boolean;
|
|
65
|
-
to: {
|
|
66
|
-
type: string;
|
|
67
|
-
}[];
|
|
68
|
-
options: {
|
|
69
|
-
filter?: string | undefined;
|
|
70
|
-
filterParams?: Record<string, unknown> | undefined;
|
|
71
|
-
} | undefined;
|
|
72
|
-
})[];
|
|
73
|
-
})[];
|
|
74
|
-
} | {
|
|
75
|
-
type: string;
|
|
76
|
-
})[];
|
|
77
|
-
}
|
|
78
|
-
|
|
1
|
+
import { ArraySchemaType } from '@sanity/types';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { TreeDeskStructureProps, TreeFieldSchema } from './types';
|
|
4
|
+
declare type SchemaOptions = Omit<TreeDeskStructureProps, 'documentId' | 'maxDepth'>;
|
|
5
|
+
export declare function createHierarchicalField({ name, title, options, ...rest }: TreeFieldSchema): Omit<ArraySchemaType, 'type' | 'jsonType' | 'of'> & {
|
|
6
|
+
type: string;
|
|
7
|
+
inputComponent: React.FC<any>;
|
|
8
|
+
of?: any[];
|
|
9
|
+
};
|
|
10
|
+
export default function createHierarchicalSchemas(options: SchemaOptions): ({
|
|
11
|
+
name: string;
|
|
12
|
+
title: string;
|
|
13
|
+
type: string;
|
|
14
|
+
fields: ({
|
|
15
|
+
name: string;
|
|
16
|
+
type: string;
|
|
17
|
+
} | {
|
|
18
|
+
name: string;
|
|
19
|
+
type: string;
|
|
20
|
+
title: string;
|
|
21
|
+
fields: ({
|
|
22
|
+
name: string;
|
|
23
|
+
type: string;
|
|
24
|
+
weak?: undefined;
|
|
25
|
+
to?: undefined;
|
|
26
|
+
options?: undefined;
|
|
27
|
+
} | {
|
|
28
|
+
name: string;
|
|
29
|
+
type: string;
|
|
30
|
+
weak: boolean;
|
|
31
|
+
to: {
|
|
32
|
+
type: string;
|
|
33
|
+
}[];
|
|
34
|
+
options: {
|
|
35
|
+
filter?: string | undefined;
|
|
36
|
+
filterParams?: Record<string, unknown> | undefined;
|
|
37
|
+
} | undefined;
|
|
38
|
+
})[];
|
|
39
|
+
})[];
|
|
40
|
+
} | {
|
|
41
|
+
name: string;
|
|
42
|
+
title: string;
|
|
43
|
+
type: string;
|
|
44
|
+
of: ({
|
|
45
|
+
name: string;
|
|
46
|
+
title: string;
|
|
47
|
+
type: string;
|
|
48
|
+
fields: ({
|
|
49
|
+
name: string;
|
|
50
|
+
type: string;
|
|
51
|
+
} | {
|
|
52
|
+
name: string;
|
|
53
|
+
type: string;
|
|
54
|
+
title: string;
|
|
55
|
+
fields: ({
|
|
56
|
+
name: string;
|
|
57
|
+
type: string;
|
|
58
|
+
weak?: undefined;
|
|
59
|
+
to?: undefined;
|
|
60
|
+
options?: undefined;
|
|
61
|
+
} | {
|
|
62
|
+
name: string;
|
|
63
|
+
type: string;
|
|
64
|
+
weak: boolean;
|
|
65
|
+
to: {
|
|
66
|
+
type: string;
|
|
67
|
+
}[];
|
|
68
|
+
options: {
|
|
69
|
+
filter?: string | undefined;
|
|
70
|
+
filterParams?: Record<string, unknown> | undefined;
|
|
71
|
+
} | undefined;
|
|
72
|
+
})[];
|
|
73
|
+
})[];
|
|
74
|
+
} | {
|
|
75
|
+
type: string;
|
|
76
|
+
})[];
|
|
77
|
+
} | {
|
|
78
|
+
name: string | undefined;
|
|
79
|
+
title: string;
|
|
80
|
+
type: string;
|
|
81
|
+
liveEdit: boolean;
|
|
82
|
+
fields: (Omit<ArraySchemaType<unknown>, "type" | "of" | "jsonType"> & {
|
|
83
|
+
type: string;
|
|
84
|
+
inputComponent: React.FC<any>;
|
|
85
|
+
of?: any[] | undefined;
|
|
86
|
+
})[];
|
|
87
|
+
preview: {
|
|
88
|
+
select: {
|
|
89
|
+
id: string;
|
|
90
|
+
tree: string;
|
|
91
|
+
};
|
|
92
|
+
prepare({ id, tree }: {
|
|
93
|
+
id: string;
|
|
94
|
+
tree: unknown[];
|
|
95
|
+
}): Record<string, string>;
|
|
96
|
+
};
|
|
97
|
+
})[];
|
|
98
|
+
export {};
|
|
@@ -1,138 +1,138 @@
|
|
|
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 __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.createHierarchicalField = void 0;
|
|
29
|
-
var TreeDeskStructure_1 = require("./TreeDeskStructure");
|
|
30
|
-
var TreeInputComponent_1 = __importDefault(require("./TreeInputComponent"));
|
|
31
|
-
var injectNodeTypeInPatches_1 = require("./utils/injectNodeTypeInPatches");
|
|
32
|
-
var throwError_1 = __importDefault(require("./utils/throwError"));
|
|
33
|
-
function createHierarchicalNodeValueType(_a) {
|
|
34
|
-
var referenceTo = _a.referenceTo, referenceOptions = _a.referenceOptions, documentType = _a.documentType;
|
|
35
|
-
return {
|
|
36
|
-
// when used inside the field, name & type are overwritten by createHierarchicalNodeType
|
|
37
|
-
name: documentType ? (0, injectNodeTypeInPatches_1.getSchemaTypeName)(documentType, 'nodeValue') : injectNodeTypeInPatches_1.INTERNAL_NODE_VALUE_TYPE,
|
|
38
|
-
type: 'object',
|
|
39
|
-
title: "Hierarchical node value (".concat(documentType, ")"),
|
|
40
|
-
fields: [
|
|
41
|
-
{ name: 'docType', type: 'string' },
|
|
42
|
-
{
|
|
43
|
-
name: 'reference',
|
|
44
|
-
type: 'reference',
|
|
45
|
-
weak: true,
|
|
46
|
-
to: referenceTo.map(function (type) { return ({ type: type }); }),
|
|
47
|
-
options: referenceOptions
|
|
48
|
-
}
|
|
49
|
-
]
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
function createHierarchicalNodeType(options) {
|
|
53
|
-
return {
|
|
54
|
-
// name & type are overwritten by createHierarchicalField
|
|
55
|
-
name: options.documentType
|
|
56
|
-
? (0, injectNodeTypeInPatches_1.getSchemaTypeName)(options.documentType, 'node')
|
|
57
|
-
: injectNodeTypeInPatches_1.INTERNAL_NODE_TYPE,
|
|
58
|
-
title: "Hierarchical node (".concat(options.documentType, ")"),
|
|
59
|
-
type: 'object',
|
|
60
|
-
fields: [
|
|
61
|
-
{ name: 'parent', type: 'string' },
|
|
62
|
-
options.documentType
|
|
63
|
-
? { name: 'value', type: (0, injectNodeTypeInPatches_1.getSchemaTypeName)(options.documentType, 'nodeValue') }
|
|
64
|
-
: // If no documentType is defined, use an anonymized inline object to avoid
|
|
65
|
-
__assign(__assign({}, createHierarchicalNodeValueType(options)), { name: 'value', type: 'object' })
|
|
66
|
-
]
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
function createHierarchicalArrayType(options) {
|
|
70
|
-
return {
|
|
71
|
-
// name & type are overwritten by createHierarchicalField
|
|
72
|
-
name: options.documentType
|
|
73
|
-
? (0, injectNodeTypeInPatches_1.getSchemaTypeName)(options.documentType, 'array')
|
|
74
|
-
: injectNodeTypeInPatches_1.INTERNAL_NODE_ARRAY_TYPE,
|
|
75
|
-
title: "Hierarchical array of nodes (".concat(options.documentType, ")"),
|
|
76
|
-
type: 'array',
|
|
77
|
-
of: [
|
|
78
|
-
options.documentType
|
|
79
|
-
? { type: (0, injectNodeTypeInPatches_1.getSchemaTypeName)(options.documentType, 'node') }
|
|
80
|
-
: createHierarchicalNodeType(options)
|
|
81
|
-
]
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function createHierarchicalField(_a) {
|
|
85
|
-
var name = _a.name, title = _a.title, options = _a.options, rest = __rest(_a, ["name", "title", "options"]);
|
|
86
|
-
if (!Array.isArray(options === null || options === void 0 ? void 0 : options.referenceTo)) {
|
|
87
|
-
(0, throwError_1.default)('invalidReferenceTo', "(field of name \"".concat(name, "\")"));
|
|
88
|
-
}
|
|
89
|
-
return __assign(__assign(__assign({}, rest), { name: name, title: title, inputComponent: TreeInputComponent_1.default, options: options }), (options.documentType
|
|
90
|
-
? { type: (0, injectNodeTypeInPatches_1.getSchemaTypeName)(options.documentType, 'array') }
|
|
91
|
-
: __assign(__assign({}, createHierarchicalArrayType(options)), { name: name })));
|
|
92
|
-
}
|
|
93
|
-
exports.createHierarchicalField = createHierarchicalField;
|
|
94
|
-
function createHierarchicalDocType(options) {
|
|
95
|
-
return {
|
|
96
|
-
name: options.documentType,
|
|
97
|
-
title: 'Hierarchical tree',
|
|
98
|
-
type: 'document',
|
|
99
|
-
// The plugin needs to define a `schemaType` with liveEdit enabled so that
|
|
100
|
-
// `useDocumentOperation` in TreeDeskStructure.tsx doesn't create drafts at every patch.
|
|
101
|
-
liveEdit: true,
|
|
102
|
-
fields: [
|
|
103
|
-
createHierarchicalField({
|
|
104
|
-
name: options.fieldKeyInDocument || TreeDeskStructure_1.DEFAULT_FIELD_KEY,
|
|
105
|
-
title: 'Hierarchical Tree',
|
|
106
|
-
options: options
|
|
107
|
-
})
|
|
108
|
-
],
|
|
109
|
-
preview: {
|
|
110
|
-
select: {
|
|
111
|
-
id: '_id',
|
|
112
|
-
tree: 'tree'
|
|
113
|
-
},
|
|
114
|
-
prepare: function (_a) {
|
|
115
|
-
var id = _a.id, tree = _a.tree;
|
|
116
|
-
return {
|
|
117
|
-
title: "Hierarchical documents (ID: ".concat(id, ")"),
|
|
118
|
-
subtitle: "".concat((tree === null || tree === void 0 ? void 0 : tree.length) || 0, " document(s) in its list.")
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
function createHierarchicalSchemas(options) {
|
|
125
|
-
if (!Array.isArray(options.referenceTo) || options.referenceTo.length <= 0) {
|
|
126
|
-
(0, throwError_1.default)('invalidReferenceTo');
|
|
127
|
-
}
|
|
128
|
-
if (!options.documentType) {
|
|
129
|
-
(0, throwError_1.default)('invalidDocumentType');
|
|
130
|
-
}
|
|
131
|
-
return [
|
|
132
|
-
createHierarchicalDocType(options),
|
|
133
|
-
createHierarchicalArrayType(options),
|
|
134
|
-
createHierarchicalNodeType(options),
|
|
135
|
-
createHierarchicalNodeValueType(options)
|
|
136
|
-
];
|
|
137
|
-
}
|
|
138
|
-
exports.default = createHierarchicalSchemas;
|
|
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 __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
+
t[p[i]] = s[p[i]];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.createHierarchicalField = void 0;
|
|
29
|
+
var TreeDeskStructure_1 = require("./TreeDeskStructure");
|
|
30
|
+
var TreeInputComponent_1 = __importDefault(require("./TreeInputComponent"));
|
|
31
|
+
var injectNodeTypeInPatches_1 = require("./utils/injectNodeTypeInPatches");
|
|
32
|
+
var throwError_1 = __importDefault(require("./utils/throwError"));
|
|
33
|
+
function createHierarchicalNodeValueType(_a) {
|
|
34
|
+
var referenceTo = _a.referenceTo, referenceOptions = _a.referenceOptions, documentType = _a.documentType;
|
|
35
|
+
return {
|
|
36
|
+
// when used inside the field, name & type are overwritten by createHierarchicalNodeType
|
|
37
|
+
name: documentType ? (0, injectNodeTypeInPatches_1.getSchemaTypeName)(documentType, 'nodeValue') : injectNodeTypeInPatches_1.INTERNAL_NODE_VALUE_TYPE,
|
|
38
|
+
type: 'object',
|
|
39
|
+
title: "Hierarchical node value (".concat(documentType, ")"),
|
|
40
|
+
fields: [
|
|
41
|
+
{ name: 'docType', type: 'string' },
|
|
42
|
+
{
|
|
43
|
+
name: 'reference',
|
|
44
|
+
type: 'reference',
|
|
45
|
+
weak: true,
|
|
46
|
+
to: referenceTo.map(function (type) { return ({ type: type }); }),
|
|
47
|
+
options: referenceOptions
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function createHierarchicalNodeType(options) {
|
|
53
|
+
return {
|
|
54
|
+
// name & type are overwritten by createHierarchicalField
|
|
55
|
+
name: options.documentType
|
|
56
|
+
? (0, injectNodeTypeInPatches_1.getSchemaTypeName)(options.documentType, 'node')
|
|
57
|
+
: injectNodeTypeInPatches_1.INTERNAL_NODE_TYPE,
|
|
58
|
+
title: "Hierarchical node (".concat(options.documentType, ")"),
|
|
59
|
+
type: 'object',
|
|
60
|
+
fields: [
|
|
61
|
+
{ name: 'parent', type: 'string' },
|
|
62
|
+
options.documentType
|
|
63
|
+
? { name: 'value', type: (0, injectNodeTypeInPatches_1.getSchemaTypeName)(options.documentType, 'nodeValue') }
|
|
64
|
+
: // If no documentType is defined, use an anonymized inline object to avoid
|
|
65
|
+
__assign(__assign({}, createHierarchicalNodeValueType(options)), { name: 'value', type: 'object' })
|
|
66
|
+
]
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function createHierarchicalArrayType(options) {
|
|
70
|
+
return {
|
|
71
|
+
// name & type are overwritten by createHierarchicalField
|
|
72
|
+
name: options.documentType
|
|
73
|
+
? (0, injectNodeTypeInPatches_1.getSchemaTypeName)(options.documentType, 'array')
|
|
74
|
+
: injectNodeTypeInPatches_1.INTERNAL_NODE_ARRAY_TYPE,
|
|
75
|
+
title: "Hierarchical array of nodes (".concat(options.documentType, ")"),
|
|
76
|
+
type: 'array',
|
|
77
|
+
of: [
|
|
78
|
+
options.documentType
|
|
79
|
+
? { type: (0, injectNodeTypeInPatches_1.getSchemaTypeName)(options.documentType, 'node') }
|
|
80
|
+
: createHierarchicalNodeType(options)
|
|
81
|
+
]
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function createHierarchicalField(_a) {
|
|
85
|
+
var name = _a.name, title = _a.title, options = _a.options, rest = __rest(_a, ["name", "title", "options"]);
|
|
86
|
+
if (!Array.isArray(options === null || options === void 0 ? void 0 : options.referenceTo)) {
|
|
87
|
+
(0, throwError_1.default)('invalidReferenceTo', "(field of name \"".concat(name, "\")"));
|
|
88
|
+
}
|
|
89
|
+
return __assign(__assign(__assign({}, rest), { name: name, title: title, inputComponent: TreeInputComponent_1.default, options: options }), (options.documentType
|
|
90
|
+
? { type: (0, injectNodeTypeInPatches_1.getSchemaTypeName)(options.documentType, 'array') }
|
|
91
|
+
: __assign(__assign({}, createHierarchicalArrayType(options)), { name: name })));
|
|
92
|
+
}
|
|
93
|
+
exports.createHierarchicalField = createHierarchicalField;
|
|
94
|
+
function createHierarchicalDocType(options) {
|
|
95
|
+
return {
|
|
96
|
+
name: options.documentType,
|
|
97
|
+
title: 'Hierarchical tree',
|
|
98
|
+
type: 'document',
|
|
99
|
+
// The plugin needs to define a `schemaType` with liveEdit enabled so that
|
|
100
|
+
// `useDocumentOperation` in TreeDeskStructure.tsx doesn't create drafts at every patch.
|
|
101
|
+
liveEdit: true,
|
|
102
|
+
fields: [
|
|
103
|
+
createHierarchicalField({
|
|
104
|
+
name: options.fieldKeyInDocument || TreeDeskStructure_1.DEFAULT_FIELD_KEY,
|
|
105
|
+
title: 'Hierarchical Tree',
|
|
106
|
+
options: options
|
|
107
|
+
})
|
|
108
|
+
],
|
|
109
|
+
preview: {
|
|
110
|
+
select: {
|
|
111
|
+
id: '_id',
|
|
112
|
+
tree: 'tree'
|
|
113
|
+
},
|
|
114
|
+
prepare: function (_a) {
|
|
115
|
+
var id = _a.id, tree = _a.tree;
|
|
116
|
+
return {
|
|
117
|
+
title: "Hierarchical documents (ID: ".concat(id, ")"),
|
|
118
|
+
subtitle: "".concat((tree === null || tree === void 0 ? void 0 : tree.length) || 0, " document(s) in its list.")
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function createHierarchicalSchemas(options) {
|
|
125
|
+
if (!Array.isArray(options.referenceTo) || options.referenceTo.length <= 0) {
|
|
126
|
+
(0, throwError_1.default)('invalidReferenceTo');
|
|
127
|
+
}
|
|
128
|
+
if (!options.documentType) {
|
|
129
|
+
(0, throwError_1.default)('invalidDocumentType');
|
|
130
|
+
}
|
|
131
|
+
return [
|
|
132
|
+
createHierarchicalDocType(options),
|
|
133
|
+
createHierarchicalArrayType(options),
|
|
134
|
+
createHierarchicalNodeType(options),
|
|
135
|
+
createHierarchicalNodeValueType(options)
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
exports.default = createHierarchicalSchemas;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AllItems, TreeInputOptions } from '../types';
|
|
2
|
-
declare type Status = 'loading' | 'success' | 'error';
|
|
3
|
-
export default function useAllItems(options: TreeInputOptions): {
|
|
4
|
-
status: Status;
|
|
5
|
-
allItems: AllItems;
|
|
6
|
-
};
|
|
7
|
-
export {};
|
|
1
|
+
import { AllItems, TreeInputOptions } from '../types';
|
|
2
|
+
declare type Status = 'loading' | 'success' | 'error';
|
|
3
|
+
export default function useAllItems(options: TreeInputOptions): {
|
|
4
|
+
status: Status;
|
|
5
|
+
allItems: AllItems;
|
|
6
|
+
};
|
|
7
|
+
export {};
|