@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,119 +1,119 @@
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 client_1 = __importDefault(require("part:@sanity/base/client"));
37
- var React = __importStar(require("react"));
38
- var idUtils_1 = require("../utils/idUtils");
39
- var client = client_1.default.withConfig({
40
- apiVersion: '2021-09-01'
41
- });
42
- function getDeskFilter(_a) {
43
- var referenceTo = _a.referenceTo, referenceOptions = _a.referenceOptions;
44
- var filterParts = ['_type in $docTypes'];
45
- if (referenceOptions === null || referenceOptions === void 0 ? void 0 : referenceOptions.filter) {
46
- filterParts.push(referenceOptions.filter);
47
- }
48
- return {
49
- filter: filterParts.join(' && '),
50
- params: __assign(__assign({}, ((referenceOptions === null || referenceOptions === void 0 ? void 0 : referenceOptions.filterParams) || {})), { docTypes: referenceTo.map(function (schemaType) { return schemaType; }) })
51
- };
52
- }
53
- function updateItemInState(state, item) {
54
- var _a;
55
- var newState = __assign({}, state);
56
- var publishedId = (0, idUtils_1.unprefixId)(item._id);
57
- newState[publishedId] = __assign(__assign({}, (newState[publishedId] || {})), (_a = {}, _a[(0, idUtils_1.isDraft)(item._id) ? 'draft' : 'published'] = item, _a));
58
- return newState;
59
- }
60
- function allItemsReducer(state, action) {
61
- var _a;
62
- var _b, _c, _d;
63
- if (action.type === 'addOrEditItem' && ((_b = action.item) === null || _b === void 0 ? void 0 : _b._id)) {
64
- return updateItemInState(state, action.item);
65
- }
66
- if (action.type === 'removeItem') {
67
- var publishedId = (0, idUtils_1.unprefixId)(action.itemId);
68
- return __assign(__assign({}, state), (_a = {}, _a[publishedId] = (0, idUtils_1.isDraft)(action.itemId)
69
- ? // If a draft, keep only published
70
- {
71
- published: (_c = state[publishedId]) === null || _c === void 0 ? void 0 : _c.published
72
- }
73
- : {
74
- draft: (_d = state[publishedId]) === null || _d === void 0 ? void 0 : _d.draft
75
- }, _a));
76
- }
77
- if (action.type === 'setInitialData') {
78
- return action.items.reduce(updateItemInState, {});
79
- }
80
- return state;
81
- }
82
- function useAllItems(options) {
83
- var _a = React.useState('loading'), status = _a[0], setStatus = _a[1];
84
- var _b = React.useReducer(allItemsReducer, {}), allItems = _b[0], dispatch = _b[1];
85
- function handleListener(event) {
86
- if (event.type !== 'mutation') {
87
- return;
88
- }
89
- if (event.result) {
90
- dispatch({ type: 'addOrEditItem', item: event.result });
91
- }
92
- else {
93
- dispatch({ type: 'removeItem', itemId: event.documentId });
94
- }
95
- }
96
- function handleFirstLoad(items) {
97
- dispatch({ type: 'setInitialData', items: items });
98
- setStatus('success');
99
- }
100
- React.useEffect(function () {
101
- var _a = getDeskFilter(options), filter = _a.filter, params = _a.params;
102
- var query = "*[".concat(filter, "] {\n _id,\n _type,\n _updatedAt,\n }");
103
- client
104
- .fetch(query, params)
105
- .then(handleFirstLoad)
106
- .catch(function () {
107
- setStatus('error');
108
- });
109
- var listener = client.listen(query, params).subscribe(handleListener);
110
- return function () {
111
- listener.unsubscribe();
112
- };
113
- }, []);
114
- return {
115
- status: status,
116
- allItems: allItems
117
- };
118
- }
119
- exports.default = useAllItems;
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 client_1 = __importDefault(require("part:@sanity/base/client"));
37
+ var React = __importStar(require("react"));
38
+ var idUtils_1 = require("../utils/idUtils");
39
+ var client = client_1.default.withConfig({
40
+ apiVersion: '2021-09-01'
41
+ });
42
+ function getDeskFilter(_a) {
43
+ var referenceTo = _a.referenceTo, referenceOptions = _a.referenceOptions;
44
+ var filterParts = ['_type in $docTypes'];
45
+ if (referenceOptions === null || referenceOptions === void 0 ? void 0 : referenceOptions.filter) {
46
+ filterParts.push(referenceOptions.filter);
47
+ }
48
+ return {
49
+ filter: filterParts.join(' && '),
50
+ params: __assign(__assign({}, ((referenceOptions === null || referenceOptions === void 0 ? void 0 : referenceOptions.filterParams) || {})), { docTypes: referenceTo.map(function (schemaType) { return schemaType; }) })
51
+ };
52
+ }
53
+ function updateItemInState(state, item) {
54
+ var _a;
55
+ var newState = __assign({}, state);
56
+ var publishedId = (0, idUtils_1.unprefixId)(item._id);
57
+ newState[publishedId] = __assign(__assign({}, (newState[publishedId] || {})), (_a = {}, _a[(0, idUtils_1.isDraft)(item._id) ? 'draft' : 'published'] = item, _a));
58
+ return newState;
59
+ }
60
+ function allItemsReducer(state, action) {
61
+ var _a;
62
+ var _b, _c, _d;
63
+ if (action.type === 'addOrEditItem' && ((_b = action.item) === null || _b === void 0 ? void 0 : _b._id)) {
64
+ return updateItemInState(state, action.item);
65
+ }
66
+ if (action.type === 'removeItem') {
67
+ var publishedId = (0, idUtils_1.unprefixId)(action.itemId);
68
+ return __assign(__assign({}, state), (_a = {}, _a[publishedId] = (0, idUtils_1.isDraft)(action.itemId)
69
+ ? // If a draft, keep only published
70
+ {
71
+ published: (_c = state[publishedId]) === null || _c === void 0 ? void 0 : _c.published
72
+ }
73
+ : {
74
+ draft: (_d = state[publishedId]) === null || _d === void 0 ? void 0 : _d.draft
75
+ }, _a));
76
+ }
77
+ if (action.type === 'setInitialData') {
78
+ return action.items.reduce(updateItemInState, {});
79
+ }
80
+ return state;
81
+ }
82
+ function useAllItems(options) {
83
+ var _a = React.useState('loading'), status = _a[0], setStatus = _a[1];
84
+ var _b = React.useReducer(allItemsReducer, {}), allItems = _b[0], dispatch = _b[1];
85
+ function handleListener(event) {
86
+ if (event.type !== 'mutation') {
87
+ return;
88
+ }
89
+ if (event.result) {
90
+ dispatch({ type: 'addOrEditItem', item: event.result });
91
+ }
92
+ else {
93
+ dispatch({ type: 'removeItem', itemId: event.documentId });
94
+ }
95
+ }
96
+ function handleFirstLoad(items) {
97
+ dispatch({ type: 'setInitialData', items: items });
98
+ setStatus('success');
99
+ }
100
+ React.useEffect(function () {
101
+ var _a = getDeskFilter(options), filter = _a.filter, params = _a.params;
102
+ var query = "*[".concat(filter, "] {\n _id,\n _type,\n _updatedAt,\n }");
103
+ client
104
+ .fetch(query, params)
105
+ .then(handleFirstLoad)
106
+ .catch(function () {
107
+ setStatus('error');
108
+ });
109
+ var listener = client.listen(query, params).subscribe(handleListener);
110
+ return function () {
111
+ listener.unsubscribe();
112
+ };
113
+ }, []);
114
+ return {
115
+ status: status,
116
+ allItems: allItems
117
+ };
118
+ }
119
+ exports.default = useAllItems;
@@ -1,17 +1,17 @@
1
- import { OnVisibilityToggleData } from 'react-sortable-tree';
2
- import { AllItems, LocalTreeItem, StoredTreeItem } from '../types';
3
- /**
4
- * Enhances tree data with information on:
5
- * - `expanded` - native property of react-sortable-tree to determine collapsing & expanding of a node's children
6
- * - `draftId` & `publishedId` - refer to LocalTreeItem's type annotations
7
- *
8
- * Doesn't modify the main tree or has side-effects on data.
9
- * Has the added benefit of being local to the user, so external changes won't affect local visibility.
10
- */
11
- export default function useLocalTree({ tree, allItems }: {
12
- tree: StoredTreeItem[];
13
- allItems: AllItems;
14
- }): {
15
- handleVisibilityToggle: (data: OnVisibilityToggleData) => void;
16
- localTree: LocalTreeItem[];
17
- };
1
+ import { OnVisibilityToggleData } from 'react-sortable-tree';
2
+ import { AllItems, LocalTreeItem, StoredTreeItem } from '../types';
3
+ /**
4
+ * Enhances tree data with information on:
5
+ * - `expanded` - native property of react-sortable-tree to determine collapsing & expanding of a node's children
6
+ * - `draftId` & `publishedId` - refer to LocalTreeItem's type annotations
7
+ *
8
+ * Doesn't modify the main tree or has side-effects on data.
9
+ * Has the added benefit of being local to the user, so external changes won't affect local visibility.
10
+ */
11
+ export default function useLocalTree({ tree, allItems }: {
12
+ tree: StoredTreeItem[];
13
+ allItems: AllItems;
14
+ }): {
15
+ handleVisibilityToggle: (data: OnVisibilityToggleData) => void;
16
+ localTree: LocalTreeItem[];
17
+ };
@@ -1,59 +1,59 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
- }) : (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- o[k2] = m[k];
19
- }));
20
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
- Object.defineProperty(o, "default", { enumerable: true, value: v });
22
- }) : function(o, v) {
23
- o["default"] = v;
24
- });
25
- var __importStar = (this && this.__importStar) || function (mod) {
26
- if (mod && mod.__esModule) return mod;
27
- var result = {};
28
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
- __setModuleDefault(result, mod);
30
- return result;
31
- };
32
- Object.defineProperty(exports, "__esModule", { value: true });
33
- var React = __importStar(require("react"));
34
- var treeData_1 = require("../utils/treeData");
35
- /**
36
- * Enhances tree data with information on:
37
- * - `expanded` - native property of react-sortable-tree to determine collapsing & expanding of a node's children
38
- * - `draftId` & `publishedId` - refer to LocalTreeItem's type annotations
39
- *
40
- * Doesn't modify the main tree or has side-effects on data.
41
- * Has the added benefit of being local to the user, so external changes won't affect local visibility.
42
- */
43
- function useLocalTree(_a) {
44
- var tree = _a.tree, allItems = _a.allItems;
45
- var _b = React.useState({}), visibilityMap = _b[0], setVisibilityMap = _b[1];
46
- function handleVisibilityToggle(data) {
47
- var _a;
48
- setVisibilityMap(__assign(__assign({}, visibilityMap), (_a = {}, _a[data.node._key] = data.expanded, _a)));
49
- }
50
- return {
51
- localTree: (0, treeData_1.dataToEditorTree)({
52
- tree: tree,
53
- allItems: allItems,
54
- visibilityMap: visibilityMap
55
- }),
56
- handleVisibilityToggle: handleVisibilityToggle
57
- };
58
- }
59
- exports.default = useLocalTree;
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ var React = __importStar(require("react"));
34
+ var treeData_1 = require("../utils/treeData");
35
+ /**
36
+ * Enhances tree data with information on:
37
+ * - `expanded` - native property of react-sortable-tree to determine collapsing & expanding of a node's children
38
+ * - `draftId` & `publishedId` - refer to LocalTreeItem's type annotations
39
+ *
40
+ * Doesn't modify the main tree or has side-effects on data.
41
+ * Has the added benefit of being local to the user, so external changes won't affect local visibility.
42
+ */
43
+ function useLocalTree(_a) {
44
+ var tree = _a.tree, allItems = _a.allItems;
45
+ var _b = React.useState({}), visibilityMap = _b[0], setVisibilityMap = _b[1];
46
+ function handleVisibilityToggle(data) {
47
+ var _a;
48
+ setVisibilityMap(__assign(__assign({}, visibilityMap), (_a = {}, _a[data.node._key] = data.expanded, _a)));
49
+ }
50
+ return {
51
+ localTree: (0, treeData_1.dataToEditorTree)({
52
+ tree: tree,
53
+ allItems: allItems,
54
+ visibilityMap: visibilityMap
55
+ }),
56
+ handleVisibilityToggle: handleVisibilityToggle
57
+ };
58
+ }
59
+ exports.default = useLocalTree;
@@ -1,9 +1,9 @@
1
- import * as React from 'react';
2
- import useAllItems from './useAllItems';
3
- import useTreeOperationsProvider from './useTreeOperationsProvider';
4
- declare type ContextValue = ReturnType<typeof useTreeOperationsProvider> & {
5
- allItemsStatus: ReturnType<typeof useAllItems>['status'];
6
- };
7
- export declare const TreeOperationsContext: React.Context<ContextValue>;
8
- export default function useTreeOperations(): ContextValue;
9
- export {};
1
+ import * as React from 'react';
2
+ import useAllItems from './useAllItems';
3
+ import useTreeOperationsProvider from './useTreeOperationsProvider';
4
+ declare type ContextValue = ReturnType<typeof useTreeOperationsProvider> & {
5
+ allItemsStatus: ReturnType<typeof useAllItems>['status'];
6
+ };
7
+ export declare const TreeOperationsContext: React.Context<ContextValue>;
8
+ export default function useTreeOperations(): ContextValue;
9
+ export {};
@@ -1,39 +1,39 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.TreeOperationsContext = void 0;
23
- var React = __importStar(require("react"));
24
- function placeholder() {
25
- // no-op
26
- }
27
- exports.TreeOperationsContext = React.createContext({
28
- addItem: placeholder,
29
- duplicateItem: placeholder,
30
- removeItem: placeholder,
31
- handleMovedNode: placeholder,
32
- moveItemDown: placeholder,
33
- moveItemUp: placeholder,
34
- allItemsStatus: 'loading'
35
- });
36
- function useTreeOperations() {
37
- return React.useContext(exports.TreeOperationsContext);
38
- }
39
- exports.default = useTreeOperations;
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
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.TreeOperationsContext = void 0;
23
+ var React = __importStar(require("react"));
24
+ function placeholder() {
25
+ // no-op
26
+ }
27
+ exports.TreeOperationsContext = React.createContext({
28
+ addItem: placeholder,
29
+ duplicateItem: placeholder,
30
+ removeItem: placeholder,
31
+ handleMovedNode: placeholder,
32
+ moveItemDown: placeholder,
33
+ moveItemUp: placeholder,
34
+ allItemsStatus: 'loading'
35
+ });
36
+ function useTreeOperations() {
37
+ return React.useContext(exports.TreeOperationsContext);
38
+ }
39
+ exports.default = useTreeOperations;
@@ -1,14 +1,14 @@
1
- import { LocalTreeItem, NodeProps } from '../types';
2
- import { HandleMovedNode } from '../utils/treePatches';
3
- export default function useTreeOperationsProvider(props: {
4
- patchPrefix?: string;
5
- onChange: (patch: unknown) => void;
6
- localTree: LocalTreeItem[];
7
- }): {
8
- handleMovedNode: HandleMovedNode;
9
- addItem: (item: LocalTreeItem) => void;
10
- duplicateItem: (nodeProps: NodeProps) => void;
11
- removeItem: (nodeProps: NodeProps) => void;
12
- moveItemUp: (nodeProps: NodeProps) => void;
13
- moveItemDown: (nodeProps: NodeProps) => void;
14
- };
1
+ import { LocalTreeItem, NodeProps } from '../types';
2
+ import { HandleMovedNode } from '../utils/treePatches';
3
+ export default function useTreeOperationsProvider(props: {
4
+ patchPrefix?: string;
5
+ onChange: (patch: unknown) => void;
6
+ localTree: LocalTreeItem[];
7
+ }): {
8
+ handleMovedNode: HandleMovedNode;
9
+ addItem: (item: LocalTreeItem) => void;
10
+ duplicateItem: (nodeProps: NodeProps) => void;
11
+ removeItem: (nodeProps: NodeProps) => void;
12
+ moveItemUp: (nodeProps: NodeProps) => void;
13
+ moveItemDown: (nodeProps: NodeProps) => void;
14
+ };