@sanity/hierarchical-document-list 0.1.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 -224
- package/commitlint.config.js +3 -0
- package/lib/TreeDeskStructure.d.ts +8 -7
- package/lib/TreeDeskStructure.js +96 -71
- package/lib/TreeInputComponent.d.ts +19 -19
- package/lib/TreeInputComponent.js +50 -21
- package/lib/components/DeskWarning.d.ts +6 -6
- package/lib/components/DeskWarning.js +46 -25
- package/lib/components/DocumentInNode.d.ts +11 -11
- package/lib/components/DocumentInNode.js +81 -58
- package/lib/components/DocumentPreviewStatus.d.ts +7 -7
- package/lib/components/DocumentPreviewStatus.js +39 -35
- package/lib/components/NodeActions.d.ts +10 -10
- package/lib/components/NodeActions.js +61 -37
- package/lib/components/NodeContentRenderer.d.ts +8 -8
- package/lib/components/NodeContentRenderer.js +105 -81
- package/lib/components/PlaceholderDropzone.d.ts +9 -9
- package/lib/components/PlaceholderDropzone.js +30 -28
- 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 -54
- package/lib/components/TreeEditorErrorBoundary.d.ts +16 -17
- package/lib/components/TreeEditorErrorBoundary.js +74 -69
- package/lib/components/TreeNodeRenderer.d.ts +3 -3
- package/lib/components/TreeNodeRenderer.js +59 -35
- package/lib/components/TreeNodeRendererScaffold.d.ts +4 -4
- package/lib/components/TreeNodeRendererScaffold.js +44 -42
- package/lib/createDeskHierarchy.d.ts +14 -14
- package/lib/createDeskHierarchy.js +84 -67
- package/lib/createHierarchicalSchemas.d.ts +98 -0
- package/lib/createHierarchicalSchemas.js +138 -0
- package/lib/{utils → hooks}/useAllItems.d.ts +7 -7
- package/lib/{utils → hooks}/useAllItems.js +119 -94
- package/lib/{utils → hooks}/useLocalTree.d.ts +17 -17
- package/lib/{utils → hooks}/useLocalTree.js +59 -37
- package/lib/{utils → hooks}/useTreeOperations.d.ts +9 -9
- package/lib/hooks/useTreeOperations.js +39 -0
- package/lib/{utils → hooks}/useTreeOperationsProvider.d.ts +14 -14
- package/lib/hooks/useTreeOperationsProvider.js +85 -0
- package/lib/index.d.ts +3 -3
- package/lib/index.js +12 -3
- package/lib/schemas/hierarchy.tree.d.ts +13 -23
- package/lib/schemas/hierarchy.tree.js +19 -31
- 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 -23
- package/lib/utils/getAdjescentNodes.d.ts +12 -12
- package/lib/utils/getAdjescentNodes.js +19 -16
- package/lib/utils/getCommonTreeProps.d.ts +7 -7
- package/lib/utils/getCommonTreeProps.js +33 -27
- package/lib/utils/getTreeHeight.d.ts +3 -3
- package/lib/utils/getTreeHeight.js +11 -7
- package/lib/utils/gradientPatchAdapter.d.ts +4 -4
- package/lib/utils/gradientPatchAdapter.js +40 -35
- package/lib/utils/idUtils.d.ts +2 -2
- package/lib/utils/idUtils.js +13 -8
- package/lib/utils/injectNodeTypeInPatches.d.ts +12 -0
- package/lib/utils/injectNodeTypeInPatches.js +59 -0
- package/lib/utils/moveItemInArray.d.ts +5 -5
- package/lib/utils/moveItemInArray.js +26 -23
- package/lib/utils/throwError.d.ts +7 -0
- package/lib/utils/throwError.js +12 -0
- package/lib/utils/treeData.d.ts +18 -18
- package/lib/utils/treeData.js +118 -106
- package/lib/utils/treePatches.d.ts +15 -15
- package/lib/utils/treePatches.js +171 -141
- package/lint-staged.config.js +4 -0
- package/package.json +65 -56
- package/sanity.json +12 -12
- package/tsconfig.json +20 -20
- package/lib/createHierarchicalField.d.ts +0 -8
- package/lib/createHierarchicalField.js +0 -51
- package/lib/utils/useTreeOperations.js +0 -16
- package/lib/utils/useTreeOperationsProvider.js +0 -60
package/package.json
CHANGED
|
@@ -1,56 +1,65 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@sanity/hierarchical-document-list",
|
|
3
|
-
"version": "
|
|
4
|
-
"author": "Sanity <hello@sanity.io>",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"main": "lib/index.js",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/sanity-io/hierarchical-document-list.git"
|
|
10
|
-
},
|
|
11
|
-
"bugs": {
|
|
12
|
-
"url": "https://github.com/sanity-io/hierarchical-document-list/issues"
|
|
13
|
-
},
|
|
14
|
-
"homepage": "https://github.com/sanity-io/hierarchical-document-list#readme",
|
|
15
|
-
"scripts": {
|
|
16
|
-
"dev": "tsc -w -d",
|
|
17
|
-
"build": "tsc -d",
|
|
18
|
-
"format": "prettier src -w",
|
|
19
|
-
"lint": "eslint src"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"react
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@sanity/hierarchical-document-list",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"author": "Sanity <hello@sanity.io>",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/sanity-io/hierarchical-document-list.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/sanity-io/hierarchical-document-list/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/sanity-io/hierarchical-document-list#readme",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "tsc -w -d",
|
|
17
|
+
"build": "tsc -d",
|
|
18
|
+
"format": "prettier src -w",
|
|
19
|
+
"lint": "eslint src",
|
|
20
|
+
"prepare": "npm run build && husky install",
|
|
21
|
+
"clean": "rimraf lib",
|
|
22
|
+
"release": "standard-version",
|
|
23
|
+
"prepublishOnly": "npm run clean && npm run lint && npm run build"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@commitlint/cli": "^16.2.3",
|
|
27
|
+
"@commitlint/config-conventional": "^16.2.1",
|
|
28
|
+
"@sanity/base": ">= 2.25.0",
|
|
29
|
+
"@sanity/color": "^2.1.6",
|
|
30
|
+
"@sanity/desk-tool": ">= 2.25.0",
|
|
31
|
+
"@sanity/form-builder": "^2.25.0",
|
|
32
|
+
"@sanity/icons": ">= 1.2.0",
|
|
33
|
+
"@sanity/ui": ">= 0.37.0",
|
|
34
|
+
"@types/assert": "^1.5.6",
|
|
35
|
+
"@types/react": "^17.0.38",
|
|
36
|
+
"@types/react-dom": "^17.0.11",
|
|
37
|
+
"@types/react-sortable-tree": "^0.3.14",
|
|
38
|
+
"@types/styled-components": "^5.1.21",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^5.10.1",
|
|
40
|
+
"@typescript-eslint/parser": "^5.10.1",
|
|
41
|
+
"eslint": "^8.7.0",
|
|
42
|
+
"eslint-config-prettier": "^8.3.0",
|
|
43
|
+
"eslint-config-sanity": "^5.1.0",
|
|
44
|
+
"husky": "^7.0.4",
|
|
45
|
+
"lint-staged": "^12.3.7",
|
|
46
|
+
"prettier": "^2.5.1",
|
|
47
|
+
"react": "^17.0.2",
|
|
48
|
+
"react-dom": "^17.0.2",
|
|
49
|
+
"rimraf": "^3.0.2",
|
|
50
|
+
"standard-version": "^9.3.2",
|
|
51
|
+
"styled-components": "^5.3.3",
|
|
52
|
+
"typescript": "^4.5.5"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"assert": "^2.0.0",
|
|
56
|
+
"react-sortable-tree": "^2.8.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@sanity/base": ">= 2.25.0",
|
|
60
|
+
"@sanity/desk-tool": ">= 2.25.0",
|
|
61
|
+
"react": "^17.0.2",
|
|
62
|
+
"react-dom": "^17.0.2",
|
|
63
|
+
"styled-components": ">= 5.2.0"
|
|
64
|
+
}
|
|
65
|
+
}
|
package/sanity.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
{
|
|
2
|
-
"paths": {
|
|
3
|
-
"source": "./src",
|
|
4
|
-
"compiled": "./lib"
|
|
5
|
-
},
|
|
6
|
-
"parts": [
|
|
7
|
-
{
|
|
8
|
-
"implements": "part:@sanity/base/schema-type",
|
|
9
|
-
"path": "schemas/hierarchy.tree.js"
|
|
10
|
-
}
|
|
11
|
-
]
|
|
12
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"paths": {
|
|
3
|
+
"source": "./src",
|
|
4
|
+
"compiled": "./lib"
|
|
5
|
+
},
|
|
6
|
+
"parts": [
|
|
7
|
+
{
|
|
8
|
+
"implements": "part:@sanity/base/schema-type",
|
|
9
|
+
"path": "schemas/hierarchy.tree.js"
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es5",
|
|
4
|
-
"useDefineForClassFields": true,
|
|
5
|
-
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
6
|
-
"allowJs": false,
|
|
7
|
-
"skipLibCheck": true,
|
|
8
|
-
"esModuleInterop":
|
|
9
|
-
"allowSyntheticDefaultImports":
|
|
10
|
-
"strict": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"module": "
|
|
13
|
-
"moduleResolution": "Node",
|
|
14
|
-
"resolveJsonModule": true,
|
|
15
|
-
"isolatedModules": true,
|
|
16
|
-
"jsx": "react-jsx",
|
|
17
|
-
"outDir": "lib"
|
|
18
|
-
},
|
|
19
|
-
"include": ["./src"]
|
|
20
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
|
6
|
+
"allowJs": false,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"allowSyntheticDefaultImports": false,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"module": "CommonJS",
|
|
13
|
+
"moduleResolution": "Node",
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"jsx": "react-jsx",
|
|
17
|
+
"outDir": "lib"
|
|
18
|
+
},
|
|
19
|
+
"include": ["./src"]
|
|
20
|
+
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ArraySchemaType } from '@sanity/types';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { TreeFieldSchema } from './types';
|
|
4
|
-
export default function createHierarchicalField({ name, title, options, ...rest }: TreeFieldSchema): Omit<ArraySchemaType, 'type' | 'jsonType' | 'of'> & {
|
|
5
|
-
type: string;
|
|
6
|
-
inputComponent: React.FC<any>;
|
|
7
|
-
of: any[];
|
|
8
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
-
var t = {};
|
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
-
t[p] = s[p];
|
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
-
t[p[i]] = s[p[i]];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
|
-
import TreeInputComponent from './TreeInputComponent';
|
|
24
|
-
export default function createHierarchicalField(_a) {
|
|
25
|
-
var name = _a.name, title = _a.title, options = _a.options, rest = __rest(_a, ["name", "title", "options"]);
|
|
26
|
-
if (!Array.isArray(options === null || options === void 0 ? void 0 : options.referenceTo)) {
|
|
27
|
-
throw new Error("[hierarchical input] Missing valid options.referenceTo in createHierarchicalField (field of name \"".concat(name, "\")"));
|
|
28
|
-
}
|
|
29
|
-
return __assign(__assign({}, rest), { options: options, name: name, title: title, type: 'array', of: [
|
|
30
|
-
{
|
|
31
|
-
type: 'object',
|
|
32
|
-
fields: [
|
|
33
|
-
{ name: 'parent', type: 'string' },
|
|
34
|
-
{
|
|
35
|
-
name: 'value',
|
|
36
|
-
type: 'object',
|
|
37
|
-
fields: [
|
|
38
|
-
{ name: 'docType', type: 'string' },
|
|
39
|
-
{
|
|
40
|
-
name: 'reference',
|
|
41
|
-
type: 'reference',
|
|
42
|
-
weak: true,
|
|
43
|
-
to: options.referenceTo.map(function (type) { return ({ type: type }); }),
|
|
44
|
-
options: options.referenceOptions
|
|
45
|
-
}
|
|
46
|
-
]
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
}
|
|
50
|
-
], inputComponent: TreeInputComponent });
|
|
51
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
function placeholder() {
|
|
3
|
-
// no-op
|
|
4
|
-
}
|
|
5
|
-
export var TreeOperationsContext = React.createContext({
|
|
6
|
-
addItem: placeholder,
|
|
7
|
-
duplicateItem: placeholder,
|
|
8
|
-
removeItem: placeholder,
|
|
9
|
-
handleMovedNode: placeholder,
|
|
10
|
-
moveItemDown: placeholder,
|
|
11
|
-
moveItemUp: placeholder,
|
|
12
|
-
allItemsStatus: 'loading'
|
|
13
|
-
});
|
|
14
|
-
export default function useTreeOperations() {
|
|
15
|
-
return React.useContext(TreeOperationsContext);
|
|
16
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
-
if (ar || !(i in from)) {
|
|
4
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
-
ar[i] = from[i];
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
-
};
|
|
10
|
-
import * as Patch from '@sanity/form-builder/lib/patch/patches';
|
|
11
|
-
import PatchEvent from '@sanity/form-builder/PatchEvent';
|
|
12
|
-
import { getAddItemPatch, getDuplicateItemPatch, getMovedNodePatch, getMoveItemPatch, getRemoveItemPatch } from './treePatches';
|
|
13
|
-
export default function useTreeOperationsProvider(props) {
|
|
14
|
-
var localTree = props.localTree;
|
|
15
|
-
function runPatches(patches) {
|
|
16
|
-
var finalPatches = __spreadArray([
|
|
17
|
-
// Ensure tree array exists before any operation
|
|
18
|
-
Patch.setIfMissing([])
|
|
19
|
-
], (patches || []), true);
|
|
20
|
-
var patchEvent = PatchEvent.from(finalPatches);
|
|
21
|
-
if (props.patchPrefix) {
|
|
22
|
-
patchEvent = PatchEvent.from(finalPatches.map(function (patch) { return Patch.prefixPath(patch, props.patchPrefix); }));
|
|
23
|
-
}
|
|
24
|
-
props.onChange(patchEvent);
|
|
25
|
-
}
|
|
26
|
-
function handleMovedNode(data) {
|
|
27
|
-
runPatches(getMovedNodePatch(data));
|
|
28
|
-
}
|
|
29
|
-
function addItem(item) {
|
|
30
|
-
runPatches(getAddItemPatch(item));
|
|
31
|
-
}
|
|
32
|
-
function duplicateItem(nodeProps) {
|
|
33
|
-
runPatches(getDuplicateItemPatch(nodeProps));
|
|
34
|
-
}
|
|
35
|
-
function removeItem(nodeProps) {
|
|
36
|
-
runPatches(getRemoveItemPatch(nodeProps));
|
|
37
|
-
}
|
|
38
|
-
function moveItemUp(nodeProps) {
|
|
39
|
-
runPatches(getMoveItemPatch({
|
|
40
|
-
nodeProps: nodeProps,
|
|
41
|
-
localTree: localTree,
|
|
42
|
-
direction: 'up'
|
|
43
|
-
}));
|
|
44
|
-
}
|
|
45
|
-
function moveItemDown(nodeProps) {
|
|
46
|
-
runPatches(getMoveItemPatch({
|
|
47
|
-
nodeProps: nodeProps,
|
|
48
|
-
localTree: localTree,
|
|
49
|
-
direction: 'down'
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
handleMovedNode: handleMovedNode,
|
|
54
|
-
addItem: addItem,
|
|
55
|
-
removeItem: removeItem,
|
|
56
|
-
moveItemUp: moveItemUp,
|
|
57
|
-
moveItemDown: moveItemDown,
|
|
58
|
-
duplicateItem: duplicateItem
|
|
59
|
-
};
|
|
60
|
-
}
|