@sanity/hierarchical-document-list 0.1.0-next.3 → 0.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.
@@ -1,10 +1,26 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
1
16
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
17
  import { useToast } from '@sanity/ui';
3
18
  import React from 'react';
4
- const ErrorToast = ({ error }) => {
5
- const { push } = useToast();
6
- React.useEffect(() => {
7
- if (error?.title) {
19
+ var ErrorToast = function (_a) {
20
+ var error = _a.error;
21
+ var push = useToast().push;
22
+ React.useEffect(function () {
23
+ if (error === null || error === void 0 ? void 0 : error.title) {
8
24
  push({
9
25
  title: error.title,
10
26
  description: error.description,
@@ -16,25 +32,38 @@ const ErrorToast = ({ error }) => {
16
32
  }, [error]);
17
33
  return null;
18
34
  };
19
- class TreeEditorErrorBoundary extends React.Component {
20
- constructor(props) {
21
- super(props);
22
- this.state = { error: undefined };
35
+ var TreeEditorErrorBoundary = /** @class */ (function (_super) {
36
+ __extends(TreeEditorErrorBoundary, _super);
37
+ function TreeEditorErrorBoundary(props) {
38
+ var _this = _super.call(this, props) || this;
39
+ _this.state = { error: undefined };
40
+ return _this;
23
41
  }
24
- static getDerivedStateFromError(error) {
25
- if (!error) {
42
+ Object.defineProperty(TreeEditorErrorBoundary, "getDerivedStateFromError", {
43
+ enumerable: false,
44
+ configurable: true,
45
+ writable: true,
46
+ value: function (error) {
47
+ if (!error) {
48
+ return {
49
+ error: undefined
50
+ };
51
+ }
26
52
  return {
27
- error: undefined
53
+ error: {
54
+ title: 'Something went wrong'
55
+ }
28
56
  };
29
57
  }
30
- return {
31
- error: {
32
- title: 'Something went wrong'
33
- }
34
- };
35
- }
36
- render() {
37
- return (_jsxs(React.Fragment, { children: [_jsx(ErrorToast, { error: this.state.error }, void 0), this.props.children] }, void 0));
38
- }
39
- }
58
+ });
59
+ Object.defineProperty(TreeEditorErrorBoundary.prototype, "render", {
60
+ enumerable: false,
61
+ configurable: true,
62
+ writable: true,
63
+ value: function () {
64
+ return (_jsxs(React.Fragment, { children: [_jsx(ErrorToast, { error: this.state.error }, void 0), this.props.children] }, void 0));
65
+ }
66
+ });
67
+ return TreeEditorErrorBoundary;
68
+ }(React.Component));
40
69
  export default TreeEditorErrorBoundary;
@@ -1,22 +1,35 @@
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
+ };
1
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
13
  import React from 'react';
3
14
  import TreeNodeRendererScaffold from './TreeNodeRendererScaffold';
4
15
  /**
5
16
  * To prevent expand buttons from overflowing on the left, we add a minimum left padding to all entries
6
17
  */
7
- const BASE_LEFT_PADDING = 10;
8
- const NESTING_PADDING = 14;
9
- const TreeNodeRenderer = (props) => {
10
- const { children, lowerSiblingCounts, connectDropTarget, isOver, draggedNode, canDrop } = props;
18
+ var BASE_LEFT_PADDING = 10;
19
+ var NESTING_PADDING = 14;
20
+ var TreeNodeRenderer = function (props) {
21
+ var children = props.children, lowerSiblingCounts = props.lowerSiblingCounts, connectDropTarget = props.connectDropTarget, isOver = props.isOver, draggedNode = props.draggedNode, canDrop = props.canDrop;
11
22
  // Construct the scaffold representing the structure of the tree
12
- const scaffoldBlockCount = lowerSiblingCounts.length;
13
- return connectDropTarget(_jsxs("div", { style: props.style, children: [_jsx("div", { style: {
23
+ var scaffoldBlockCount = lowerSiblingCounts.length;
24
+ return connectDropTarget(_jsxs("div", __assign({ style: props.style }, { children: [_jsx("div", __assign({ style: {
14
25
  // prettier-ignore
15
- paddingLeft: `${BASE_LEFT_PADDING + (NESTING_PADDING * scaffoldBlockCount)}px`
16
- }, children: React.Children.map(children, (child) => React.cloneElement(child, {
17
- isOver,
18
- canDrop,
19
- draggedNode
20
- })) }, void 0), _jsx(TreeNodeRendererScaffold, { ...props }, void 0)] }, void 0));
26
+ paddingLeft: "".concat(BASE_LEFT_PADDING + (NESTING_PADDING * scaffoldBlockCount), "px")
27
+ } }, { children: React.Children.map(children, function (child) {
28
+ return React.cloneElement(child, {
29
+ isOver: isOver,
30
+ canDrop: canDrop,
31
+ draggedNode: draggedNode
32
+ });
33
+ }) }), void 0), _jsx(TreeNodeRendererScaffold, __assign({}, props), void 0)] }), void 0));
21
34
  };
22
35
  export default TreeNodeRenderer;
@@ -1,145 +1,22 @@
1
+ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
+ if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
+ return cooked;
4
+ };
1
5
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
6
  import { blue } from '@sanity/color';
3
7
  import { createGlobalStyle } from 'styled-components';
4
8
  // Adapted from react-sortable-tree/src/tree-node.js
5
- const ScaffoldStyles = createGlobalStyle `
6
- .rst__lineBlock,
7
- .rst__absoluteLineBlock {
8
- height: 100%;
9
- position: relative;
10
- display: inline-block;
11
- --stroke-width: 3px;
12
- }
13
-
14
- .rst__absoluteLineBlock {
15
- position: absolute;
16
- top: 0;
17
- }
18
-
19
- /* Highlight line for pointing to dragged row destination
20
- ========================================================================== */
21
- /**
22
- * +--+--+
23
- * | | |
24
- * | | |
25
- * | | |
26
- * +--+--+
27
- */
28
- .rst__highlightLineVertical {
29
- z-index: 3;
30
- }
31
- .rst__highlightLineVertical::before {
32
- position: absolute;
33
- content: '';
34
- background-color: ${blue[400].hex};
35
- width: calc(var(--stroke-width) * 2);
36
- margin-left: calc(var(--stroke-width) * -1);
37
- left: 50%;
38
- top: 0;
39
- height: 100%;
40
- }
41
-
42
- @keyframes arrow-pulse {
43
- 0% {
44
- transform: translate(0, 0);
45
- opacity: 0;
46
- }
47
- 30% {
48
- transform: translate(0, 300%);
49
- opacity: 1;
50
- }
51
- 70% {
52
- transform: translate(0, 700%);
53
- opacity: 1;
54
- }
55
- 100% {
56
- transform: translate(0, 1000%);
57
- opacity: 0;
58
- }
59
- }
60
- .rst__highlightLineVertical::after {
61
- content: '';
62
- position: absolute;
63
- height: 0;
64
- margin-left: calc(var(--stroke-width) * -1);
65
- left: 50%;
66
- top: 0;
67
- border-left: var(--stroke-width) solid transparent;
68
- border-right: var(--stroke-width) solid transparent;
69
- border-top: var(--stroke-width) solid white;
70
- animation: arrow-pulse 1s infinite linear both;
71
- }
72
-
73
- /**
74
- * +-----+
75
- * | |
76
- * | +--+
77
- * | | |
78
- * +--+--+
79
- */
80
- .rst__highlightTopLeftCorner::before {
81
- z-index: 3;
82
- content: '';
83
- position: absolute;
84
- border-top: solid calc(var(--stroke-width) * 2) ${blue[400].hex};
85
- border-left: solid calc(var(--stroke-width) * 2) ${blue[400].hex};
86
- box-sizing: border-box;
87
- height: calc(50% + var(--stroke-width));
88
- top: 50%;
89
- margin-top: calc(var(--stroke-width) * -1);
90
- right: 0;
91
- width: calc(50% + var(--stroke-width));
92
- }
93
-
94
- /**
95
- * +--+--+
96
- * | | |
97
- * | | |
98
- * | +->|
99
- * +-----+
100
- */
101
- .rst__highlightBottomLeftCorner {
102
- z-index: 3;
103
- }
104
- .rst__highlightBottomLeftCorner::before {
105
- content: '';
106
- position: absolute;
107
- border-bottom: solid calc(var(--stroke-width) * 2) ${blue[400].hex};
108
- border-left: solid calc(var(--stroke-width) * 2) ${blue[400].hex};
109
- box-sizing: border-box;
110
- height: calc(100% + var(--stroke-width));
111
- top: 0;
112
- right: calc(var(--stroke-width) * 3);
113
- width: calc(50% - calc(var(--stroke-width) * 2));
114
- }
115
-
116
- .rst__highlightBottomLeftCorner::after {
117
- content: '';
118
- position: absolute;
119
- height: 0;
120
- right: 0;
121
- top: 100%;
122
- margin-top: calc(var(--stroke-width) * -3);
123
- border-top: calc(var(--stroke-width) * 3) solid transparent;
124
- border-bottom: calc(var(--stroke-width) * 3) solid transparent;
125
- border-left: calc(var(--stroke-width) * 3) solid ${blue[400].hex};
126
- }
127
-
128
- .rst__unclickable {
129
- pointer-events: none;
130
- margin-top: -calc(var(--stroke-width) * 3);
131
- }
132
- `;
133
- const TreeNodeRendererScaffold = (props) => {
134
- const { lowerSiblingCounts, scaffoldBlockPxWidth, listIndex, swapDepth, swapFrom, swapLength, treeIndex } = props;
9
+ var ScaffoldStyles = createGlobalStyle(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n .rst__lineBlock,\n .rst__absoluteLineBlock {\n height: 100%;\n position: relative;\n display: inline-block;\n --stroke-width: 3px;\n }\n\n .rst__absoluteLineBlock {\n position: absolute;\n top: 0;\n }\n\n /* Highlight line for pointing to dragged row destination\n ========================================================================== */\n /**\n * +--+--+\n * | | |\n * | | |\n * | | |\n * +--+--+\n */\n .rst__highlightLineVertical {\n z-index: 3;\n }\n .rst__highlightLineVertical::before {\n position: absolute;\n content: '';\n background-color: ", ";\n width: calc(var(--stroke-width) * 2);\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n height: 100%;\n }\n\n @keyframes arrow-pulse {\n 0% {\n transform: translate(0, 0);\n opacity: 0;\n }\n 30% {\n transform: translate(0, 300%);\n opacity: 1;\n }\n 70% {\n transform: translate(0, 700%);\n opacity: 1;\n }\n 100% {\n transform: translate(0, 1000%);\n opacity: 0;\n }\n }\n .rst__highlightLineVertical::after {\n content: '';\n position: absolute;\n height: 0;\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n border-left: var(--stroke-width) solid transparent;\n border-right: var(--stroke-width) solid transparent;\n border-top: var(--stroke-width) solid white;\n animation: arrow-pulse 1s infinite linear both;\n }\n\n /**\n * +-----+\n * | |\n * | +--+\n * | | |\n * +--+--+\n */\n .rst__highlightTopLeftCorner::before {\n z-index: 3;\n content: '';\n position: absolute;\n border-top: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(50% + var(--stroke-width));\n top: 50%;\n margin-top: calc(var(--stroke-width) * -1);\n right: 0;\n width: calc(50% + var(--stroke-width));\n }\n\n /**\n * +--+--+\n * | | |\n * | | |\n * | +->|\n * +-----+\n */\n .rst__highlightBottomLeftCorner {\n z-index: 3;\n }\n .rst__highlightBottomLeftCorner::before {\n content: '';\n position: absolute;\n border-bottom: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(100% + var(--stroke-width));\n top: 0;\n right: calc(var(--stroke-width) * 3);\n width: calc(50% - calc(var(--stroke-width) * 2));\n }\n\n .rst__highlightBottomLeftCorner::after {\n content: '';\n position: absolute;\n height: 0;\n right: 0;\n top: 100%;\n margin-top: calc(var(--stroke-width) * -3);\n border-top: calc(var(--stroke-width) * 3) solid transparent;\n border-bottom: calc(var(--stroke-width) * 3) solid transparent;\n border-left: calc(var(--stroke-width) * 3) solid ", ";\n }\n\n .rst__unclickable {\n pointer-events: none;\n margin-top: -calc(var(--stroke-width) * 3);\n }\n"], ["\n .rst__lineBlock,\n .rst__absoluteLineBlock {\n height: 100%;\n position: relative;\n display: inline-block;\n --stroke-width: 3px;\n }\n\n .rst__absoluteLineBlock {\n position: absolute;\n top: 0;\n }\n\n /* Highlight line for pointing to dragged row destination\n ========================================================================== */\n /**\n * +--+--+\n * | | |\n * | | |\n * | | |\n * +--+--+\n */\n .rst__highlightLineVertical {\n z-index: 3;\n }\n .rst__highlightLineVertical::before {\n position: absolute;\n content: '';\n background-color: ", ";\n width: calc(var(--stroke-width) * 2);\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n height: 100%;\n }\n\n @keyframes arrow-pulse {\n 0% {\n transform: translate(0, 0);\n opacity: 0;\n }\n 30% {\n transform: translate(0, 300%);\n opacity: 1;\n }\n 70% {\n transform: translate(0, 700%);\n opacity: 1;\n }\n 100% {\n transform: translate(0, 1000%);\n opacity: 0;\n }\n }\n .rst__highlightLineVertical::after {\n content: '';\n position: absolute;\n height: 0;\n margin-left: calc(var(--stroke-width) * -1);\n left: 50%;\n top: 0;\n border-left: var(--stroke-width) solid transparent;\n border-right: var(--stroke-width) solid transparent;\n border-top: var(--stroke-width) solid white;\n animation: arrow-pulse 1s infinite linear both;\n }\n\n /**\n * +-----+\n * | |\n * | +--+\n * | | |\n * +--+--+\n */\n .rst__highlightTopLeftCorner::before {\n z-index: 3;\n content: '';\n position: absolute;\n border-top: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(50% + var(--stroke-width));\n top: 50%;\n margin-top: calc(var(--stroke-width) * -1);\n right: 0;\n width: calc(50% + var(--stroke-width));\n }\n\n /**\n * +--+--+\n * | | |\n * | | |\n * | +->|\n * +-----+\n */\n .rst__highlightBottomLeftCorner {\n z-index: 3;\n }\n .rst__highlightBottomLeftCorner::before {\n content: '';\n position: absolute;\n border-bottom: solid calc(var(--stroke-width) * 2) ", ";\n border-left: solid calc(var(--stroke-width) * 2) ", ";\n box-sizing: border-box;\n height: calc(100% + var(--stroke-width));\n top: 0;\n right: calc(var(--stroke-width) * 3);\n width: calc(50% - calc(var(--stroke-width) * 2));\n }\n\n .rst__highlightBottomLeftCorner::after {\n content: '';\n position: absolute;\n height: 0;\n right: 0;\n top: 100%;\n margin-top: calc(var(--stroke-width) * -3);\n border-top: calc(var(--stroke-width) * 3) solid transparent;\n border-bottom: calc(var(--stroke-width) * 3) solid transparent;\n border-left: calc(var(--stroke-width) * 3) solid ", ";\n }\n\n .rst__unclickable {\n pointer-events: none;\n margin-top: -calc(var(--stroke-width) * 3);\n }\n"])), blue[400].hex, blue[400].hex, blue[400].hex, blue[400].hex, blue[400].hex, blue[400].hex);
10
+ var TreeNodeRendererScaffold = function (props) {
11
+ var lowerSiblingCounts = props.lowerSiblingCounts, scaffoldBlockPxWidth = props.scaffoldBlockPxWidth, listIndex = props.listIndex, swapDepth = props.swapDepth, swapFrom = props.swapFrom, swapLength = props.swapLength, treeIndex = props.treeIndex;
135
12
  // Construct the scaffold representing the structure of the tree
136
- const scaffold = lowerSiblingCounts.map((lowerSiblingCount, i) => {
13
+ var scaffold = lowerSiblingCounts.map(function (lowerSiblingCount, i) {
137
14
  if (lowerSiblingCount < 0 || treeIndex === listIndex || i !== swapDepth) {
138
15
  return null;
139
16
  }
140
17
  // This row has been shifted, and is at the depth of
141
18
  // the line pointing to the new destination
142
- let highlightLineClass = '';
19
+ var highlightLineClass = '';
143
20
  if (listIndex === (swapFrom || 0) + (swapLength || 0) - 1) {
144
21
  // This block is on the bottom (target) line
145
22
  // This block points at the target block (where the row will go when released)
@@ -153,12 +30,13 @@ const TreeNodeRendererScaffold = (props) => {
153
30
  // This block is between the bottom and top
154
31
  highlightLineClass = 'rst__highlightLineVertical';
155
32
  }
156
- const style = {
33
+ var style = {
157
34
  width: scaffoldBlockPxWidth,
158
35
  left: scaffoldBlockPxWidth * i
159
36
  };
160
- return (_jsx("div", { style: style, className: `rst__unclickable rst__absoluteLineBlock ${highlightLineClass || ''}`, tabIndex: -1 }, i));
37
+ return (_jsx("div", { style: style, className: "rst__unclickable rst__absoluteLineBlock ".concat(highlightLineClass || ''), tabIndex: -1 }, i));
161
38
  });
162
39
  return (_jsxs(_Fragment, { children: [scaffold, _jsx(ScaffoldStyles, {}, void 0)] }, void 0));
163
40
  };
164
41
  export default TreeNodeRendererScaffold;
42
+ var templateObject_1;
@@ -1,32 +1,45 @@
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
+ };
1
12
  import { jsx as _jsx } from "react/jsx-runtime";
2
13
  import S from '@sanity/desk-tool/structure-builder';
3
14
  import { AddIcon } from '@sanity/icons';
4
15
  import TreeDeskStructure from './TreeDeskStructure';
5
- const deskTreeValidator = (props) => {
6
- const { documentId, referenceTo } = props;
16
+ var deskTreeValidator = function (props) {
17
+ var documentId = props.documentId, referenceTo = props.referenceTo;
7
18
  if (typeof documentId !== 'string' && !documentId) {
8
19
  throw new Error('[hierarchical input] Please add a documentId to your tree');
9
20
  }
10
21
  if (!Array.isArray(referenceTo)) {
11
- throw new Error(`[hierarchical input] Missing valid 'referenceTo' in createDeskHierarchy (documentId "${documentId}")`);
22
+ throw new Error("[hierarchical input] Missing valid 'referenceTo' in createDeskHierarchy (documentId \"".concat(documentId, "\")"));
12
23
  }
13
- return (deskProps) => _jsx(TreeDeskStructure, { ...deskProps, options: props }, void 0);
24
+ return function (deskProps) { return _jsx(TreeDeskStructure, __assign({}, deskProps, { options: props }), void 0); };
14
25
  };
15
26
  export default function createDeskHierarchy(props) {
16
- const { documentId, referenceTo, referenceOptions } = props;
17
- let mainList = (referenceTo?.length === 1
27
+ var documentId = props.documentId, referenceTo = props.referenceTo, referenceOptions = props.referenceOptions;
28
+ var mainList = ((referenceTo === null || referenceTo === void 0 ? void 0 : referenceTo.length) === 1
18
29
  ? S.documentTypeList(referenceTo[0]).schemaType(referenceTo[0])
19
30
  : S.documentList().filter('_type in $types').params({ types: referenceTo }))
20
31
  .id(documentId)
21
- .menuItems((referenceTo || []).map((schemaType) => S.menuItem()
22
- .intent({
23
- type: 'create',
24
- params: { type: schemaType, template: schemaType }
25
- })
26
- // @TODO: get the title for each schema type
27
- .title(schemaType)
28
- .icon(AddIcon)))
29
- .canHandleIntent((intent, context) => {
32
+ .menuItems((referenceTo || []).map(function (schemaType) {
33
+ return S.menuItem()
34
+ .intent({
35
+ type: 'create',
36
+ params: { type: schemaType, template: schemaType }
37
+ })
38
+ // @TODO: get the title for each schema type
39
+ .title(schemaType)
40
+ .icon(AddIcon);
41
+ }))
42
+ .canHandleIntent(function (intent, context) {
30
43
  if (intent === 'edit' && context.id === props.documentId) {
31
44
  return true;
32
45
  }
@@ -35,10 +48,10 @@ export default function createDeskHierarchy(props) {
35
48
  }
36
49
  return false;
37
50
  });
38
- if (referenceOptions?.filter) {
51
+ if (referenceOptions === null || referenceOptions === void 0 ? void 0 : referenceOptions.filter) {
39
52
  mainList = mainList.filter(referenceOptions.filter);
40
53
  }
41
- if (referenceOptions?.filterParams) {
54
+ if (referenceOptions === null || referenceOptions === void 0 ? void 0 : referenceOptions.filterParams) {
42
55
  mainList = mainList.params(referenceOptions.filterParams);
43
56
  }
44
57
  return S.listItem()
@@ -1,15 +1,32 @@
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
+ };
1
23
  import TreeInputComponent from './TreeInputComponent';
2
- export default function createHierarchicalField({ name, title, options, ...rest }) {
3
- if (!Array.isArray(options?.referenceTo)) {
4
- throw new Error(`[hierarchical input] Missing valid options.referenceTo in createHierarchicalField (field of name "${name}")`);
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, "\")"));
5
28
  }
6
- return {
7
- ...rest,
8
- options,
9
- name,
10
- title,
11
- type: 'array',
12
- of: [
29
+ return __assign(__assign({}, rest), { options: options, name: name, title: title, type: 'array', of: [
13
30
  {
14
31
  type: 'object',
15
32
  fields: [
@@ -23,14 +40,12 @@ export default function createHierarchicalField({ name, title, options, ...rest
23
40
  name: 'reference',
24
41
  type: 'reference',
25
42
  weak: true,
26
- to: options.referenceTo.map((type) => ({ type })),
43
+ to: options.referenceTo.map(function (type) { return ({ type: type }); }),
27
44
  options: options.referenceOptions
28
45
  }
29
46
  ]
30
47
  }
31
48
  ]
32
49
  }
33
- ],
34
- inputComponent: TreeInputComponent
35
- };
50
+ ], inputComponent: TreeInputComponent });
36
51
  }
@@ -20,10 +20,11 @@ export default {
20
20
  id: '_id',
21
21
  tree: 'tree'
22
22
  },
23
- prepare({ id, tree }) {
23
+ prepare: function (_a) {
24
+ var id = _a.id, tree = _a.tree;
24
25
  return {
25
- title: `Hierarchical documents (ID: ${id})`,
26
- subtitle: `${tree?.length || 0} document(s) in its list.`
26
+ title: "Hierarchical documents (ID: ".concat(id, ")"),
27
+ subtitle: "".concat((tree === null || tree === void 0 ? void 0 : tree.length) || 0, " document(s) in its list.")
27
28
  };
28
29
  }
29
30
  }
@@ -1,13 +1,22 @@
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
+ };
1
12
  import { getTreeFromFlatData } from 'react-sortable-tree';
2
13
  export default function flatDataToTree(data) {
3
14
  return getTreeFromFlatData({
4
- flatData: data.map((item) => ({
5
- ...item,
15
+ flatData: data.map(function (item) { return (__assign(__assign({}, item), {
6
16
  // if parent: undefined, the tree won't be constructed
7
- parent: item.parent || null
8
- })),
9
- getKey: (item) => item._key,
10
- getParentKey: (item) => item.parent,
17
+ parent: item.parent || null })); }),
18
+ getKey: function (item) { return item._key; },
19
+ getParentKey: function (item) { return item.parent; },
11
20
  // without rootKey, the tree won't be constructed
12
21
  rootKey: null
13
22
  });
@@ -1,15 +1,16 @@
1
1
  /**
2
2
  * Gets adjescent non-children nodes of a given treeIndex.
3
3
  */
4
- export default function getAdjescentNodes({ flatTree, node, treeIndex }) {
5
- const leadingNode = flatTree
4
+ export default function getAdjescentNodes(_a) {
5
+ var flatTree = _a.flatTree, node = _a.node, treeIndex = _a.treeIndex;
6
+ var leadingNode = flatTree
6
7
  .slice(0, treeIndex)
7
8
  .reverse()
8
9
  // Disregard children nodes - these include the current node's key in their `path` array
9
- .find((item) => !item.path.includes(node._key));
10
- const followingNode = flatTree.slice(treeIndex + 1).find((item) => !item.path.includes(node._key));
10
+ .find(function (item) { return !item.path.includes(node._key); });
11
+ var followingNode = flatTree.slice(treeIndex + 1).find(function (item) { return !item.path.includes(node._key); });
11
12
  return {
12
- leadingNode,
13
- followingNode
13
+ leadingNode: leadingNode,
14
+ followingNode: followingNode
14
15
  };
15
16
  }
@@ -1,13 +1,25 @@
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
+ };
1
12
  import { jsx as _jsx } from "react/jsx-runtime";
2
13
  import NodeContentRenderer from '../components/NodeContentRenderer';
3
14
  import PlaceholderDropzone from '../components/PlaceholderDropzone';
4
15
  import TreeNodeRenderer from '../components/TreeNodeRenderer';
5
16
  import { ROW_HEIGHT } from './getTreeHeight';
6
- export default function getCommonTreeProps({ placeholder }) {
17
+ export default function getCommonTreeProps(_a) {
18
+ var placeholder = _a.placeholder;
7
19
  return {
8
20
  theme: {
9
21
  nodeContentRenderer: NodeContentRenderer,
10
- placeholderRenderer: (props) => _jsx(PlaceholderDropzone, { ...placeholder, ...props }, void 0),
22
+ placeholderRenderer: function (props) { return _jsx(PlaceholderDropzone, __assign({}, placeholder, props), void 0); },
11
23
  treeNodeRenderer: TreeNodeRenderer,
12
24
  rowHeight: ROW_HEIGHT
13
25
  }
@@ -1,7 +1,7 @@
1
1
  import { getVisibleNodeCount } from 'react-sortable-tree';
2
- export const ROW_HEIGHT = 51;
2
+ export var ROW_HEIGHT = 51;
3
3
  export default function getTreeHeight(treeData) {
4
- const visibleNodeCount = getVisibleNodeCount({ treeData });
4
+ var visibleNodeCount = getVisibleNodeCount({ treeData: treeData });
5
5
  // prettier-ignore
6
- return `${50 + (ROW_HEIGHT * visibleNodeCount)}px`;
6
+ return "".concat(50 + (ROW_HEIGHT * visibleNodeCount), "px");
7
7
  }
@@ -5,14 +5,15 @@ export function toGradient(patches) {
5
5
  return patches.map(toGradientPatch);
6
6
  }
7
7
  function toGradientPatch(patch) {
8
- const matchPath = arrayToJSONMatchPath(patch.path || []);
8
+ var _a, _b, _c, _d;
9
+ var matchPath = arrayToJSONMatchPath(patch.path || []);
9
10
  if (patch.type === 'insert') {
10
- const { position, items } = patch;
11
+ var position = patch.position, items = patch.items;
11
12
  return {
12
- insert: {
13
- [position]: matchPath,
14
- items: items
15
- }
13
+ insert: (_a = {},
14
+ _a[position] = matchPath,
15
+ _a.items = items,
16
+ _a)
16
17
  };
17
18
  }
18
19
  if (patch.type === 'unset') {
@@ -20,15 +21,15 @@ function toGradientPatch(patch) {
20
21
  unset: [matchPath]
21
22
  };
22
23
  }
23
- assert(patch.type, `Missing patch type in patch ${JSON.stringify(patch)}`);
24
+ assert(patch.type, "Missing patch type in patch ".concat(JSON.stringify(patch)));
24
25
  if (matchPath) {
25
- return {
26
- [patch.type]: {
27
- [matchPath]: patch.value
28
- }
29
- };
26
+ return _b = {},
27
+ _b[patch.type] = (_c = {},
28
+ _c[matchPath] = patch.value,
29
+ _c),
30
+ _b;
30
31
  }
31
- return {
32
- [patch.type]: patch.value
33
- };
32
+ return _d = {},
33
+ _d[patch.type] = patch.value,
34
+ _d;
34
35
  }
@@ -1,6 +1,8 @@
1
- export function unprefixId(_id = '') {
1
+ export function unprefixId(_id) {
2
+ if (_id === void 0) { _id = ''; }
2
3
  return _id.replace('drafts.', '');
3
4
  }
4
- export function isDraft(_id = '') {
5
+ export function isDraft(_id) {
6
+ if (_id === void 0) { _id = ''; }
5
7
  return _id.startsWith('drafts.');
6
8
  }
@@ -1,11 +1,21 @@
1
- export default function moveItemInArray({ array, fromIndex, toIndex }) {
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
+ export default function moveItemInArray(_a) {
11
+ var array = _a.array, fromIndex = _a.fromIndex, toIndex = _a.toIndex;
2
12
  if (fromIndex === toIndex) {
3
13
  return array;
4
14
  }
5
- const newArray = [...array];
6
- const target = newArray[fromIndex];
7
- const inc = toIndex < fromIndex ? -1 : 1;
8
- for (let i = fromIndex; i !== toIndex; i += inc) {
15
+ var newArray = __spreadArray([], array, true);
16
+ var target = newArray[fromIndex];
17
+ var inc = toIndex < fromIndex ? -1 : 1;
18
+ for (var i = fromIndex; i !== toIndex; i += inc) {
9
19
  newArray[i] = newArray[i + inc];
10
20
  }
11
21
  newArray[toIndex] = target;