@jahia/data-helper 1.0.5 → 1.0.7
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/esm/fragments/PredefinedFragments.js +21 -221
- package/esm/fragments/fragments.utils.js +17 -43
- package/esm/fragments/getIsNodeTypeFragment.js +2 -15
- package/esm/fragments/getPermissionFragment.js +3 -28
- package/esm/hooks/useContentPreview/useContentPreview.gql-queries.js +2 -12
- package/esm/hooks/useContentPreview/useContentPreview.js +7 -7
- package/esm/hooks/useDeepCompareMemo/useDeepCompareMemo.js +0 -2
- package/esm/hooks/useDeepCompareMemo/useDeepCompareMemo.spec.js +0 -1
- package/esm/hooks/useNodeChecks/useNodeChecks.js +13 -28
- package/esm/hooks/useNodeChecks/useNodeChecks.spec.js +156 -67
- package/esm/hooks/useNodeInfo/useMemoRequest.js +49 -0
- package/esm/hooks/useNodeInfo/useNodeInfo.gql-queries.js +23 -104
- package/esm/hooks/useNodeInfo/useNodeInfo.js +139 -57
- package/esm/hooks/useNodeInfo/useNodeInfo.spec.js +429 -233
- package/esm/hooks/useNodeInfo/useNodeInfo.utils.js +52 -0
- package/esm/hooks/useSchemaFields/useSchemaFields.gql-queries.js +2 -12
- package/esm/hooks/useSiteInfo/useSiteInfo.gql-queries.js +2 -12
- package/esm/hooks/useSiteInfo/useSiteInfo.js +2 -9
- package/esm/hooks/useTreeEntries/useTreeEntries.gql-queries.js +2 -12
- package/esm/hooks/useTreeEntries/useTreeEntries.js +18 -40
- package/esm/legacy/Picker.gql-fragments.js +4 -34
- package/esm/legacy/Picker.js +31 -113
- package/js/fragments/PredefinedFragments.js +21 -224
- package/js/fragments/encodeName.js +0 -2
- package/js/fragments/fragments.utils.js +17 -44
- package/js/fragments/getIsNodeTypeFragment.js +2 -23
- package/js/fragments/getPermissionFragment.js +3 -38
- package/js/fragments/index.js +0 -4
- package/js/hooks/index.js +0 -10
- package/js/hooks/useContentPreview/index.js +0 -2
- package/js/hooks/useContentPreview/useContentPreview.gql-queries.js +2 -16
- package/js/hooks/useContentPreview/useContentPreview.js +7 -11
- package/js/hooks/useContentPreview/useContentPreview.spec.js +0 -2
- package/js/hooks/useDeepCompareMemo/index.js +0 -2
- package/js/hooks/useDeepCompareMemo/useDeepCompareMemo.js +0 -7
- package/js/hooks/useDeepCompareMemo/useDeepCompareMemo.spec.js +0 -2
- package/js/hooks/useNodeChecks/index.js +0 -2
- package/js/hooks/useNodeChecks/useNodeChecks.js +13 -30
- package/js/hooks/useNodeChecks/useNodeChecks.spec.js +157 -69
- package/js/hooks/useNodeInfo/index.js +0 -2
- package/js/hooks/useNodeInfo/useMemoRequest.js +56 -0
- package/js/hooks/useNodeInfo/useNodeInfo.gql-queries.js +25 -111
- package/js/hooks/useNodeInfo/useNodeInfo.js +139 -65
- package/js/hooks/useNodeInfo/useNodeInfo.spec.js +430 -236
- package/js/hooks/useNodeInfo/useNodeInfo.utils.js +60 -0
- package/js/hooks/useSchemaFields/index.js +0 -2
- package/js/hooks/useSchemaFields/useSchemaFields.gql-queries.js +2 -15
- package/js/hooks/useSchemaFields/useSchemaFields.jsx +0 -4
- package/js/hooks/useSiteInfo/index.js +0 -2
- package/js/hooks/useSiteInfo/useSiteInfo.gql-queries.js +2 -16
- package/js/hooks/useSiteInfo/useSiteInfo.js +2 -12
- package/js/hooks/useSiteInfo/useSiteInfo.spec.js +0 -4
- package/js/hooks/useTreeEntries/index.js +0 -2
- package/js/hooks/useTreeEntries/useTreeEntries.gql-queries.js +2 -16
- package/js/hooks/useTreeEntries/useTreeEntries.js +18 -46
- package/js/hooks/useTreeEntries/useTreeEntries.spec.js +0 -3
- package/js/index.js +0 -6
- package/js/legacy/Picker.gql-fragments.js +4 -37
- package/js/legacy/Picker.js +31 -134
- package/js/legacy/index.js +0 -4
- package/package.json +1 -1
package/js/legacy/Picker.js
CHANGED
|
@@ -1,132 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.Picker = void 0;
|
|
9
|
-
|
|
10
8
|
var _includes2 = _interopRequireDefault(require("lodash/includes"));
|
|
11
|
-
|
|
12
9
|
var _startsWith2 = _interopRequireDefault(require("lodash/startsWith"));
|
|
13
|
-
|
|
14
10
|
var _split2 = _interopRequireDefault(require("lodash/split"));
|
|
15
|
-
|
|
16
11
|
var _tail2 = _interopRequireDefault(require("lodash/tail"));
|
|
17
|
-
|
|
18
12
|
var _each2 = _interopRequireDefault(require("lodash/each"));
|
|
19
|
-
|
|
20
13
|
var _map2 = _interopRequireDefault(require("lodash/map"));
|
|
21
|
-
|
|
22
14
|
var _forEachRight2 = _interopRequireDefault(require("lodash/forEachRight"));
|
|
23
|
-
|
|
24
15
|
var _sortBy2 = _interopRequireDefault(require("lodash/sortBy"));
|
|
25
|
-
|
|
26
16
|
var _forEach2 = _interopRequireDefault(require("lodash/forEach"));
|
|
27
|
-
|
|
28
17
|
var _repeat2 = _interopRequireDefault(require("lodash/repeat"));
|
|
29
|
-
|
|
30
18
|
var _indexOf2 = _interopRequireDefault(require("lodash/indexOf"));
|
|
31
|
-
|
|
32
19
|
var _assign2 = _interopRequireDefault(require("lodash/assign"));
|
|
33
|
-
|
|
34
20
|
var _union2 = _interopRequireDefault(require("lodash/union"));
|
|
35
|
-
|
|
36
21
|
var _eq2 = _interopRequireDefault(require("lodash/eq"));
|
|
37
|
-
|
|
38
22
|
var _clone2 = _interopRequireDefault(require("lodash/clone"));
|
|
39
|
-
|
|
40
23
|
var _filter2 = _interopRequireDefault(require("lodash/filter"));
|
|
41
|
-
|
|
42
24
|
var _react = _interopRequireDefault(require("react"));
|
|
43
|
-
|
|
44
25
|
var _reactApollo = require("react-apollo");
|
|
45
|
-
|
|
46
26
|
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
47
|
-
|
|
48
27
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
49
|
-
|
|
50
28
|
var _fragments = require("../fragments");
|
|
51
|
-
|
|
52
29
|
var _Picker = require("./Picker.gql-fragments");
|
|
53
|
-
|
|
30
|
+
var _templateObject;
|
|
54
31
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
55
|
-
|
|
56
32
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
57
|
-
|
|
58
33
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
59
|
-
|
|
60
34
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
61
|
-
|
|
62
35
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
63
|
-
|
|
64
36
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
65
|
-
|
|
66
37
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
67
|
-
|
|
68
38
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
69
|
-
|
|
70
39
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
71
|
-
|
|
72
40
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
73
|
-
|
|
74
|
-
function _templateObject() {
|
|
75
|
-
var data = _taggedTemplateLiteral(["\n query PickerQuery($rootPaths:[String!]!, $selectable:[String]!, $openable:[String]!, $openPaths:[String!]!, $types:[String]!) {\n jcr {\n rootNodes:nodesByPath(paths: $rootPaths) {\n name\n children(typesFilter:{types:$types}, limit:1) {\n pageInfo {\n nodesCount\n }\n }\n selectable : isNodeType(type: {types:$selectable})\n openable : isNodeType(type: {types:$openable})\n ... NodeCacheRequiredFields\n ... node\n },\n openNodes:nodesByPath(paths: $openPaths) {\n ... NodeCacheRequiredFields\n children(typesFilter:{types:$types}) {\n nodes {\n name\n children(typesFilter:{types:$types}, limit:1) {\n pageInfo {\n nodesCount\n }\n }\n selectable : isNodeType(type: {types:$selectable})\n openable : isNodeType(type: {types:$openable})\n ... NodeCacheRequiredFields\n ... node\n }\n }\n }\n }\n }\n ", ""]);
|
|
76
|
-
|
|
77
|
-
_templateObject = function _templateObject() {
|
|
78
|
-
return data;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
return data;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
41
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
85
|
-
|
|
86
42
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
87
|
-
|
|
88
43
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
89
|
-
|
|
90
44
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
91
|
-
|
|
92
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
93
|
-
|
|
94
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
95
|
-
|
|
96
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
97
|
-
|
|
98
45
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
99
|
-
|
|
100
46
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
101
|
-
|
|
47
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
48
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
49
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
50
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
51
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
102
52
|
var Picker = /*#__PURE__*/function (_React$Component) {
|
|
103
53
|
_inherits(Picker, _React$Component);
|
|
104
|
-
|
|
54
|
+
var _super = _createSuper(Picker);
|
|
105
55
|
function Picker(props) {
|
|
106
56
|
var _this;
|
|
107
|
-
|
|
108
57
|
_classCallCheck(this, Picker);
|
|
109
|
-
|
|
110
|
-
_this = _possibleConstructorReturn(this, _getPrototypeOf(Picker).call(this, props));
|
|
58
|
+
_this = _super.call(this, props);
|
|
111
59
|
var fragments = props.fragments,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
_this.query = (0, _graphqlTag["default"])(_templateObject(), _fragments.nodeCacheRequiredFields.gql);
|
|
60
|
+
rootPaths = props.rootPaths,
|
|
61
|
+
onOpenItem = props.onOpenItem,
|
|
62
|
+
onSelectItem = props.onSelectItem,
|
|
63
|
+
openPaths = props.openPaths,
|
|
64
|
+
selectedPaths = props.selectedPaths,
|
|
65
|
+
defaultSelectedPaths = props.defaultSelectedPaths,
|
|
66
|
+
onSelectionChange = props.onSelectionChange,
|
|
67
|
+
defaultOpenPaths = props.defaultOpenPaths;
|
|
68
|
+
_this.query = (0, _graphqlTag["default"])(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n query PickerQuery($rootPaths:[String!]!, $selectable:[String]!, $openable:[String]!, $openPaths:[String!]!, $types:[String]!) {\n jcr {\n rootNodes:nodesByPath(paths: $rootPaths) {\n name\n children(typesFilter:{types:$types}, limit:1) {\n pageInfo {\n nodesCount\n }\n }\n selectable : isNodeType(type: {types:$selectable})\n openable : isNodeType(type: {types:$openable})\n ... NodeCacheRequiredFields\n ... node\n },\n openNodes:nodesByPath(paths: $openPaths) {\n ... NodeCacheRequiredFields\n children(typesFilter:{types:$types}) {\n nodes {\n name\n children(typesFilter:{types:$types}, limit:1) {\n pageInfo {\n nodesCount\n }\n }\n selectable : isNodeType(type: {types:$selectable})\n openable : isNodeType(type: {types:$openable})\n ... NodeCacheRequiredFields\n ... node\n }\n }\n }\n }\n }\n ", ""])), _fragments.nodeCacheRequiredFields.gql);
|
|
121
69
|
_this.query = (0, _fragments.replaceFragmentsInDocument)(_this.query, fragments);
|
|
122
70
|
var state = {};
|
|
123
71
|
_this.eventsHandlers = {};
|
|
124
|
-
|
|
125
72
|
if (openPaths === null) {
|
|
126
73
|
// Uncontrolled mode
|
|
127
74
|
state.isOpenControlled = false;
|
|
128
75
|
state.openPaths = [];
|
|
129
|
-
|
|
130
76
|
_this.eventsHandlers.onOpenItem = function (path, open) {
|
|
131
77
|
_this.setState(function (prevState) {
|
|
132
78
|
return {
|
|
@@ -136,27 +82,23 @@ var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
136
82
|
};
|
|
137
83
|
});
|
|
138
84
|
};
|
|
139
|
-
|
|
140
85
|
if (defaultOpenPaths) {
|
|
141
86
|
state.openPaths = _this.addPathToOpenPath(defaultOpenPaths, rootPaths, state.openPaths);
|
|
142
87
|
}
|
|
143
88
|
} else {
|
|
144
89
|
state.isOpenControlled = true;
|
|
145
|
-
|
|
146
90
|
if (onOpenItem) {
|
|
147
91
|
_this.eventsHandlers.onOpenItem = onOpenItem;
|
|
148
92
|
}
|
|
149
93
|
}
|
|
150
|
-
|
|
151
94
|
if (selectedPaths === null) {
|
|
152
95
|
// Uncontrolled mode
|
|
153
96
|
state.isSelectControlled = false;
|
|
154
|
-
state.selectedPaths = defaultSelectedPaths ? (0, _clone2["default"])(defaultSelectedPaths) : [];
|
|
155
|
-
|
|
97
|
+
state.selectedPaths = defaultSelectedPaths ? (0, _clone2["default"])(defaultSelectedPaths) : [];
|
|
98
|
+
// Open selected path if open is uncontrolled
|
|
156
99
|
if (defaultSelectedPaths && !state.isOpenControlled) {
|
|
157
100
|
state.openPaths = _this.addPathToOpenPath(defaultSelectedPaths, rootPaths, state.openPaths);
|
|
158
101
|
}
|
|
159
|
-
|
|
160
102
|
_this.eventsHandlers.onSelectItem = function (path, selected, multiple) {
|
|
161
103
|
_this.setState(function (prevState) {
|
|
162
104
|
var newSelectedPaths = selected ? [].concat(_toConsumableArray(multiple ? prevState.selectedPaths : []), [path]) : (0, _filter2["default"])(prevState.selectedPaths, function (thispath) {
|
|
@@ -170,26 +112,24 @@ var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
170
112
|
};
|
|
171
113
|
} else if (onSelectItem) {
|
|
172
114
|
state.isSelectControlled = true;
|
|
173
|
-
|
|
174
115
|
if (onSelectItem) {
|
|
175
116
|
_this.eventsHandlers.onSelectItem = onSelectItem;
|
|
176
117
|
}
|
|
177
118
|
}
|
|
119
|
+
_this.state = state;
|
|
178
120
|
|
|
179
|
-
|
|
180
|
-
|
|
121
|
+
// Binding
|
|
181
122
|
_this.openPaths = _this.openPaths.bind(_assertThisInitialized(_this));
|
|
182
123
|
return _this;
|
|
183
124
|
}
|
|
184
|
-
|
|
185
125
|
_createClass(Picker, [{
|
|
186
126
|
key: "getVariables",
|
|
187
127
|
value: function getVariables(selectedPaths, openPaths) {
|
|
188
128
|
var _this$props = this.props,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
129
|
+
rootPaths = _this$props.rootPaths,
|
|
130
|
+
openableTypes = _this$props.openableTypes,
|
|
131
|
+
selectableTypes = _this$props.selectableTypes,
|
|
132
|
+
queryVariables = _this$props.queryVariables;
|
|
193
133
|
var vars = {
|
|
194
134
|
rootPaths: rootPaths,
|
|
195
135
|
types: (0, _union2["default"])(openableTypes, selectableTypes),
|
|
@@ -197,29 +137,23 @@ var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
197
137
|
openable: openableTypes,
|
|
198
138
|
openPaths: openPaths
|
|
199
139
|
};
|
|
200
|
-
|
|
201
140
|
if (queryVariables) {
|
|
202
141
|
(0, _assign2["default"])(vars, queryVariables);
|
|
203
142
|
}
|
|
204
|
-
|
|
205
143
|
return vars;
|
|
206
144
|
}
|
|
207
145
|
}, {
|
|
208
146
|
key: "getPickerEntries",
|
|
209
147
|
value: function getPickerEntries(data, selectedPaths, openPaths) {
|
|
210
148
|
var _this2 = this;
|
|
211
|
-
|
|
212
149
|
var pickerEntries = [];
|
|
213
150
|
var nodesById = {};
|
|
214
151
|
var jcr = data.jcr;
|
|
215
|
-
|
|
216
152
|
var addNode = function addNode(node, depth, index) {
|
|
217
153
|
var selected = false;
|
|
218
|
-
|
|
219
154
|
if (node.selectable) {
|
|
220
155
|
selected = (0, _indexOf2["default"])(selectedPaths, node.path) !== -1;
|
|
221
156
|
}
|
|
222
|
-
|
|
223
157
|
var pickerNode = {
|
|
224
158
|
name: node.name,
|
|
225
159
|
path: node.path,
|
|
@@ -237,7 +171,6 @@ var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
237
171
|
nodesById[node.uuid] = pickerNode;
|
|
238
172
|
return pickerNode;
|
|
239
173
|
};
|
|
240
|
-
|
|
241
174
|
if (jcr) {
|
|
242
175
|
if (jcr.rootNodes) {
|
|
243
176
|
(0, _forEach2["default"])(jcr.rootNodes, function (rootNode) {
|
|
@@ -245,11 +178,9 @@ var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
245
178
|
root.hidden = _this2.props.hideRoot;
|
|
246
179
|
});
|
|
247
180
|
}
|
|
248
|
-
|
|
249
181
|
if (jcr.openNodes) {
|
|
250
182
|
(0, _sortBy2["default"])(jcr.openNodes, ['path']).forEach(function (node) {
|
|
251
183
|
var parent = nodesById[node.uuid];
|
|
252
|
-
|
|
253
184
|
if (parent) {
|
|
254
185
|
var parentIndex = (0, _indexOf2["default"])(pickerEntries, parent);
|
|
255
186
|
(0, _forEachRight2["default"])(node.children.nodes, function (child) {
|
|
@@ -258,9 +189,9 @@ var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
258
189
|
}
|
|
259
190
|
});
|
|
260
191
|
}
|
|
261
|
-
}
|
|
262
|
-
|
|
192
|
+
}
|
|
263
193
|
|
|
194
|
+
// Nodes loaded, fill selection list
|
|
264
195
|
var selectedNodes = (0, _filter2["default"])(pickerEntries, function (node) {
|
|
265
196
|
return node.selected;
|
|
266
197
|
}).map(function (node) {
|
|
@@ -277,26 +208,21 @@ var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
277
208
|
value: function addPathToOpenPath(pathsToOpen, rootPaths, openPaths) {
|
|
278
209
|
(0, _each2["default"])(pathsToOpen, function (path) {
|
|
279
210
|
var rootFound = false;
|
|
280
|
-
|
|
281
211
|
if (!path.endsWith('/')) {
|
|
282
212
|
path += '/';
|
|
283
213
|
}
|
|
284
|
-
|
|
285
214
|
(0, _tail2["default"])((0, _split2["default"])(path, '/')).reduce(function (acc, it) {
|
|
286
215
|
if (!rootFound) {
|
|
287
216
|
(0, _forEach2["default"])(rootPaths, function (rootPath) {
|
|
288
217
|
rootFound = rootFound || (0, _startsWith2["default"])(acc, rootPath) && rootPath;
|
|
289
218
|
});
|
|
290
219
|
}
|
|
291
|
-
|
|
292
220
|
if (rootFound && !(0, _includes2["default"])(openPaths, acc)) {
|
|
293
221
|
openPaths.push(acc);
|
|
294
|
-
|
|
295
222
|
if (!(0, _includes2["default"])(openPaths, rootFound)) {
|
|
296
223
|
openPaths.push(rootFound);
|
|
297
224
|
}
|
|
298
225
|
}
|
|
299
|
-
|
|
300
226
|
return acc + '/' + it;
|
|
301
227
|
}, '');
|
|
302
228
|
});
|
|
@@ -306,14 +232,11 @@ var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
306
232
|
key: "openPaths",
|
|
307
233
|
value: function openPaths(paths) {
|
|
308
234
|
var _this3 = this;
|
|
309
|
-
|
|
310
235
|
if (!(paths instanceof Array)) {
|
|
311
236
|
paths = [paths];
|
|
312
237
|
}
|
|
313
|
-
|
|
314
238
|
this.setState(function (prevState) {
|
|
315
239
|
var openPaths = _this3.addPathToOpenPath(paths, _this3.props.rootPaths, prevState.openPaths);
|
|
316
|
-
|
|
317
240
|
return {
|
|
318
241
|
openPaths: openPaths
|
|
319
242
|
};
|
|
@@ -323,22 +246,20 @@ var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
323
246
|
key: "render",
|
|
324
247
|
value: function render() {
|
|
325
248
|
var _this4 = this;
|
|
326
|
-
|
|
327
249
|
var selectedPaths = this.state.selectedPaths ? this.state.selectedPaths : this.props.selectedPaths;
|
|
328
250
|
var openPaths = this.state.openPaths ? this.state.openPaths : this.props.openPaths;
|
|
329
251
|
var setRefetch = this.props.setRefetch;
|
|
330
252
|
openPaths = (0, _clone2["default"])(openPaths);
|
|
331
253
|
var vars = this.getVariables(selectedPaths, openPaths);
|
|
332
|
-
return _react["default"].createElement(_reactApollo.Query, {
|
|
254
|
+
return /*#__PURE__*/_react["default"].createElement(_reactApollo.Query, {
|
|
333
255
|
query: this.query,
|
|
334
256
|
variables: vars,
|
|
335
257
|
fetchPolicy: "cache-first"
|
|
336
258
|
}, function (_ref) {
|
|
337
259
|
var error = _ref.error,
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
260
|
+
loading = _ref.loading,
|
|
261
|
+
data = _ref.data,
|
|
262
|
+
refetch = _ref.refetch;
|
|
342
263
|
if (setRefetch) {
|
|
343
264
|
setRefetch({
|
|
344
265
|
query: _this4.query,
|
|
@@ -346,13 +267,10 @@ var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
346
267
|
refetch: refetch
|
|
347
268
|
});
|
|
348
269
|
}
|
|
349
|
-
|
|
350
270
|
var renderProp = _this4.props.children;
|
|
351
|
-
|
|
352
271
|
if (_this4.props.onLoading) {
|
|
353
272
|
_this4.props.onLoading(loading);
|
|
354
273
|
}
|
|
355
|
-
|
|
356
274
|
if (loading) {
|
|
357
275
|
if (_this4.previousEntries) {
|
|
358
276
|
return renderProp(_objectSpread({
|
|
@@ -360,13 +278,11 @@ var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
360
278
|
loading: loading
|
|
361
279
|
}, _this4.eventsHandlers));
|
|
362
280
|
}
|
|
363
|
-
|
|
364
281
|
return renderProp(_objectSpread({
|
|
365
282
|
pickerEntries: [],
|
|
366
283
|
loading: loading
|
|
367
284
|
}, _this4.eventsHandlers));
|
|
368
285
|
}
|
|
369
|
-
|
|
370
286
|
if (error) {
|
|
371
287
|
return renderProp(_objectSpread({
|
|
372
288
|
pickerEntries: [],
|
|
@@ -374,9 +290,7 @@ var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
374
290
|
loading: loading
|
|
375
291
|
}, _this4.eventsHandlers));
|
|
376
292
|
}
|
|
377
|
-
|
|
378
293
|
var pickerEntries = _this4.getPickerEntries(data, selectedPaths, openPaths);
|
|
379
|
-
|
|
380
294
|
_this4.previousEntries = pickerEntries;
|
|
381
295
|
return renderProp(_objectSpread({
|
|
382
296
|
pickerEntries: pickerEntries,
|
|
@@ -390,28 +304,21 @@ var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
390
304
|
if (prevState.isOpenControlled !== (nextProps.openPaths !== null) || prevState.isSelectControlled !== (nextProps.selectedPaths !== null)) {
|
|
391
305
|
console.warn('Cannot change between controlled/uncontrolled modes');
|
|
392
306
|
}
|
|
393
|
-
|
|
394
307
|
var newState = {};
|
|
395
|
-
|
|
396
308
|
if (prevState.isOpenControlled && !(0, _eq2["default"])(nextProps.openPaths, prevState.openPaths)) {
|
|
397
309
|
newState.openPaths = nextProps.openPaths;
|
|
398
310
|
}
|
|
399
|
-
|
|
400
311
|
if (prevState.isSelectControlled && !(0, _eq2["default"])(nextProps.selectedPaths, prevState.selectedPaths)) {
|
|
401
312
|
newState.selectedPaths = nextProps.selectedPaths;
|
|
402
313
|
}
|
|
403
|
-
|
|
404
314
|
if (newState.openPaths || newState.selectedPaths) {
|
|
405
315
|
return newState;
|
|
406
316
|
}
|
|
407
|
-
|
|
408
317
|
return null;
|
|
409
318
|
}
|
|
410
319
|
}]);
|
|
411
|
-
|
|
412
320
|
return Picker;
|
|
413
321
|
}(_react["default"].Component);
|
|
414
|
-
|
|
415
322
|
exports.Picker = Picker;
|
|
416
323
|
Picker.defaultProps = {
|
|
417
324
|
onLoading: null,
|
|
@@ -433,47 +340,38 @@ Picker.propTypes = {
|
|
|
433
340
|
* List of root paths for the picker
|
|
434
341
|
*/
|
|
435
342
|
rootPaths: _propTypes["default"].arrayOf(_propTypes["default"].string).isRequired,
|
|
436
|
-
|
|
437
343
|
/**
|
|
438
344
|
* List of folder paths that are open by default (uncontrolled mode)
|
|
439
345
|
*/
|
|
440
346
|
defaultOpenPaths: _propTypes["default"].arrayOf(_propTypes["default"].string),
|
|
441
|
-
|
|
442
347
|
/**
|
|
443
348
|
* List of node types that can be "opened" (folders)
|
|
444
349
|
*/
|
|
445
350
|
openableTypes: _propTypes["default"].arrayOf(_propTypes["default"].string).isRequired,
|
|
446
|
-
|
|
447
351
|
/**
|
|
448
352
|
* List of open folders in controlled mode
|
|
449
353
|
*/
|
|
450
354
|
openPaths: _propTypes["default"].arrayOf(_propTypes["default"].string),
|
|
451
|
-
|
|
452
355
|
/**
|
|
453
356
|
* List of node types that can be "selected" (items)
|
|
454
357
|
*/
|
|
455
358
|
selectableTypes: _propTypes["default"].arrayOf(_propTypes["default"].string).isRequired,
|
|
456
|
-
|
|
457
359
|
/**
|
|
458
360
|
* Preselected items path (uncontrolled mode)
|
|
459
361
|
*/
|
|
460
362
|
defaultSelectedPaths: _propTypes["default"].arrayOf(_propTypes["default"].string),
|
|
461
|
-
|
|
462
363
|
/**
|
|
463
364
|
* List of selected path in controlled mode
|
|
464
365
|
*/
|
|
465
366
|
selectedPaths: _propTypes["default"].arrayOf(_propTypes["default"].string),
|
|
466
|
-
|
|
467
367
|
/**
|
|
468
368
|
* Callback when the selection has changed
|
|
469
369
|
*/
|
|
470
370
|
onSelectionChange: _propTypes["default"].func,
|
|
471
|
-
|
|
472
371
|
/**
|
|
473
372
|
* Optional function which receives refetch function of the Query component when the component is strapped
|
|
474
373
|
*/
|
|
475
374
|
setRefetch: _propTypes["default"].func,
|
|
476
|
-
|
|
477
375
|
/**
|
|
478
376
|
* Optional set of fragments to add to the graphQL query. Can be a string that identify a predefinedFragment or a fragment definition
|
|
479
377
|
*/
|
|
@@ -482,7 +380,6 @@ Picker.propTypes = {
|
|
|
482
380
|
variables: _propTypes["default"].object,
|
|
483
381
|
gql: _propTypes["default"].object.isRequired
|
|
484
382
|
})])),
|
|
485
|
-
|
|
486
383
|
/**
|
|
487
384
|
* Optional set of variable to pass to the graphQL query, in order to fulfill fragments needs
|
|
488
385
|
*/
|
package/js/legacy/index.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _Picker = require("./Picker");
|
|
8
|
-
|
|
9
7
|
Object.keys(_Picker).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _Picker[key]) return;
|
|
@@ -16,9 +14,7 @@ Object.keys(_Picker).forEach(function (key) {
|
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
16
|
});
|
|
19
|
-
|
|
20
17
|
var _Picker2 = require("./Picker.gql-fragments");
|
|
21
|
-
|
|
22
18
|
Object.keys(_Picker2).forEach(function (key) {
|
|
23
19
|
if (key === "default" || key === "__esModule") return;
|
|
24
20
|
if (key in exports && exports[key] === _Picker2[key]) return;
|