@panneau/core 4.0.37 → 4.0.40-alpha.1
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/dist/contexts.d.ts +78 -34
- package/dist/contexts.js +1332 -621
- package/dist/hooks.d.ts +41 -0
- package/dist/hooks.js +1395 -847
- package/dist/index.d.ts +26 -9
- package/dist/index.js +485 -609
- package/dist/utils.d.ts +40 -6
- package/dist/utils.js +232 -354
- package/package.json +4 -4
package/dist/utils.js
CHANGED
|
@@ -1,38 +1,26 @@
|
|
|
1
1
|
import isNumber from 'lodash/isNumber';
|
|
2
2
|
import { snakeCase } from 'snake-case';
|
|
3
|
-
import _regenerator from '@babel/runtime/helpers/regenerator';
|
|
4
|
-
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
5
3
|
import isObject from 'lodash/isObject';
|
|
6
4
|
import { useEffect, isValidElement } from 'react';
|
|
7
|
-
import
|
|
8
|
-
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
9
|
-
import ReactIs from 'react-is';
|
|
10
|
-
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
5
|
+
import { isValidElementType } from 'react-is';
|
|
11
6
|
import isString from 'lodash/isString';
|
|
12
7
|
import { pascalCase, kebabCase, snakeCase as snakeCase$1 } from 'change-case';
|
|
13
8
|
export { kebabCase as dashCase, pascalCase, snakeCase } from 'change-case';
|
|
14
9
|
import isArray from 'lodash/isArray';
|
|
15
|
-
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
16
10
|
import get from 'lodash/get';
|
|
17
11
|
import capitalize from 'lodash/capitalize';
|
|
18
12
|
import EventEmitter from 'wolfy87-eventemitter';
|
|
19
13
|
import slugify from 'slugify';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
tags = _ref$tags === void 0 ? ['BUTTON', 'A', 'INPUT', 'I', 'TEXTAREA'] : _ref$tags;
|
|
31
|
-
var _ref2 = el || {},
|
|
32
|
-
_ref2$tagName = _ref2.tagName,
|
|
33
|
-
tagName = _ref2$tagName === void 0 ? null : _ref2$tagName,
|
|
34
|
-
_ref2$parentNode = _ref2.parentNode,
|
|
35
|
-
parentNode = _ref2$parentNode === void 0 ? null : _ref2$parentNode;
|
|
14
|
+
|
|
15
|
+
function checkClickable(el, options = {}, parentDistance = 1) {
|
|
16
|
+
const {
|
|
17
|
+
maxParentDistance = 5,
|
|
18
|
+
tags = ['BUTTON', 'A', 'INPUT', 'I', 'TEXTAREA']
|
|
19
|
+
} = options || {};
|
|
20
|
+
const {
|
|
21
|
+
tagName = null,
|
|
22
|
+
parentNode = null
|
|
23
|
+
} = el || {};
|
|
36
24
|
if (tagName === 'BODY') {
|
|
37
25
|
return false;
|
|
38
26
|
}
|
|
@@ -46,9 +34,7 @@ function checkClickable(el) {
|
|
|
46
34
|
// return true;
|
|
47
35
|
// }
|
|
48
36
|
|
|
49
|
-
if (tagName && tags.map(
|
|
50
|
-
return it.toLowerCase();
|
|
51
|
-
}).indexOf(tagName.toLowerCase()) !== -1) {
|
|
37
|
+
if (tagName && tags.map(it => it.toLowerCase()).indexOf(tagName.toLowerCase()) !== -1) {
|
|
52
38
|
return true;
|
|
53
39
|
}
|
|
54
40
|
if (parentDistance < maxParentDistance) {
|
|
@@ -58,19 +44,14 @@ function checkClickable(el) {
|
|
|
58
44
|
}
|
|
59
45
|
|
|
60
46
|
function convertStyleToString(style) {
|
|
61
|
-
return style !== null ? Object.keys(style).map(
|
|
62
|
-
return "".concat(snakeCase(key), ":").concat(isNumber(style[key]) ? "".concat(style[key], "px") : style[key], ";");
|
|
63
|
-
}).join('\n') : '';
|
|
47
|
+
return style !== null ? Object.keys(style).map(key => `${snakeCase(key)}:${isNumber(style[key]) ? `${style[key]}px` : style[key]};`).join('\n') : '';
|
|
64
48
|
}
|
|
65
49
|
|
|
66
|
-
function createNullableOnChange() {
|
|
67
|
-
var onChange = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
50
|
+
function createNullableOnChange(onChange = null) {
|
|
68
51
|
return function nullableOnChange(newValue) {
|
|
69
|
-
|
|
52
|
+
let nullableValue = newValue;
|
|
70
53
|
if (isObject(newValue)) {
|
|
71
|
-
|
|
72
|
-
return acc && newValue[key] === null;
|
|
73
|
-
}, true);
|
|
54
|
+
const allNull = Object.keys(newValue).reduce((acc, key) => acc && newValue[key] === null, true);
|
|
74
55
|
if (allNull) {
|
|
75
56
|
nullableValue = null;
|
|
76
57
|
}
|
|
@@ -82,13 +63,12 @@ function createNullableOnChange() {
|
|
|
82
63
|
}
|
|
83
64
|
|
|
84
65
|
function createUseEvent(eventsManager) {
|
|
85
|
-
return function useEvent(event, callback) {
|
|
86
|
-
|
|
87
|
-
useEffect(function () {
|
|
66
|
+
return function useEvent(event, callback, enabled = true) {
|
|
67
|
+
useEffect(() => {
|
|
88
68
|
if (enabled && eventsManager !== null) {
|
|
89
69
|
eventsManager.subscribe(event, callback);
|
|
90
70
|
}
|
|
91
|
-
return
|
|
71
|
+
return () => {
|
|
92
72
|
if (enabled && eventsManager !== null) {
|
|
93
73
|
eventsManager.unsubscribe(event, callback);
|
|
94
74
|
}
|
|
@@ -105,248 +85,184 @@ function createUseEvent(eventsManager) {
|
|
|
105
85
|
function makeError() {
|
|
106
86
|
return new DOMException('The request is not allowed', 'NotAllowedError');
|
|
107
87
|
}
|
|
108
|
-
function copyClipboardApi(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
try {
|
|
159
|
-
success = window.document.execCommand('copy');
|
|
160
|
-
} finally {
|
|
161
|
-
// Cleanup
|
|
162
|
-
selection === null || selection === void 0 || selection.removeAllRanges();
|
|
163
|
-
window.document.body.removeChild(span);
|
|
164
|
-
}
|
|
165
|
-
if (success) {
|
|
166
|
-
_context2.n = 1;
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
throw makeError();
|
|
170
|
-
case 1:
|
|
171
|
-
return _context2.a(2);
|
|
172
|
-
}
|
|
173
|
-
}, _callee2);
|
|
174
|
-
}));
|
|
175
|
-
return _copyExecCommand.apply(this, arguments);
|
|
176
|
-
}
|
|
177
|
-
function copyToClipboard(_x3) {
|
|
178
|
-
return _copyToClipboard.apply(this, arguments);
|
|
179
|
-
}
|
|
180
|
-
function _copyToClipboard() {
|
|
181
|
-
_copyToClipboard = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(text) {
|
|
182
|
-
var _t, _t2;
|
|
183
|
-
return _regenerator().w(function (_context3) {
|
|
184
|
-
while (1) switch (_context3.p = _context3.n) {
|
|
185
|
-
case 0:
|
|
186
|
-
_context3.p = 0;
|
|
187
|
-
_context3.n = 1;
|
|
188
|
-
return copyClipboardApi(text);
|
|
189
|
-
case 1:
|
|
190
|
-
_context3.n = 6;
|
|
191
|
-
break;
|
|
192
|
-
case 2:
|
|
193
|
-
_context3.p = 2;
|
|
194
|
-
_t = _context3.v;
|
|
195
|
-
_context3.p = 3;
|
|
196
|
-
_context3.n = 4;
|
|
197
|
-
return copyExecCommand(text);
|
|
198
|
-
case 4:
|
|
199
|
-
_context3.n = 6;
|
|
200
|
-
break;
|
|
201
|
-
case 5:
|
|
202
|
-
_context3.p = 5;
|
|
203
|
-
_t2 = _context3.v;
|
|
204
|
-
throw _t2 || _t || makeError();
|
|
205
|
-
case 6:
|
|
206
|
-
return _context3.a(2);
|
|
207
|
-
}
|
|
208
|
-
}, _callee3, null, [[3, 5], [0, 2]]);
|
|
209
|
-
}));
|
|
210
|
-
return _copyToClipboard.apply(this, arguments);
|
|
88
|
+
async function copyClipboardApi(text) {
|
|
89
|
+
// Use the Async Clipboard API when available. Requires a secure browsing
|
|
90
|
+
// context (i.e. HTTPS)
|
|
91
|
+
if (!navigator.clipboard) {
|
|
92
|
+
throw makeError();
|
|
93
|
+
}
|
|
94
|
+
return navigator.clipboard.writeText(text);
|
|
95
|
+
}
|
|
96
|
+
async function copyExecCommand(text) {
|
|
97
|
+
// Put the text to copy into a <span>
|
|
98
|
+
const span = document.createElement('span');
|
|
99
|
+
span.textContent = text;
|
|
100
|
+
|
|
101
|
+
// Preserve consecutive spaces and newlines
|
|
102
|
+
span.style.whiteSpace = 'pre';
|
|
103
|
+
span.style.webkitUserSelect = 'auto';
|
|
104
|
+
span.style.userSelect = 'all';
|
|
105
|
+
|
|
106
|
+
// Add the <span> to the page
|
|
107
|
+
document.body.appendChild(span);
|
|
108
|
+
|
|
109
|
+
// Make a selection object representing the range of text selected by the user
|
|
110
|
+
const selection = window.getSelection();
|
|
111
|
+
const range = window.document.createRange();
|
|
112
|
+
selection?.removeAllRanges();
|
|
113
|
+
range.selectNode(span);
|
|
114
|
+
selection?.addRange(range);
|
|
115
|
+
|
|
116
|
+
// Copy text to the clipboard
|
|
117
|
+
let success = false;
|
|
118
|
+
try {
|
|
119
|
+
success = window.document.execCommand('copy');
|
|
120
|
+
} finally {
|
|
121
|
+
// Cleanup
|
|
122
|
+
selection?.removeAllRanges();
|
|
123
|
+
window.document.body.removeChild(span);
|
|
124
|
+
}
|
|
125
|
+
if (!success) throw makeError();
|
|
126
|
+
}
|
|
127
|
+
async function copyToClipboard(text) {
|
|
128
|
+
try {
|
|
129
|
+
await copyClipboardApi(text);
|
|
130
|
+
} catch (err) {
|
|
131
|
+
// ...Otherwise, use document.execCommand() fallback
|
|
132
|
+
try {
|
|
133
|
+
await copyExecCommand(text);
|
|
134
|
+
} catch (err2) {
|
|
135
|
+
throw err2 || err || makeError();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
211
138
|
}
|
|
212
139
|
|
|
213
|
-
function flattenComponents(components) {
|
|
214
|
-
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
140
|
+
function flattenComponents(components, prefix = null) {
|
|
215
141
|
if (components === null) {
|
|
216
142
|
return null;
|
|
217
143
|
}
|
|
218
|
-
return Object.keys(components).reduce(
|
|
219
|
-
|
|
144
|
+
return Object.keys(components).reduce((newMap, key) => isValidElementType(components[key]) ? {
|
|
145
|
+
...newMap,
|
|
146
|
+
[prefix !== null ? `${prefix}.${key}` : key]: components[key]
|
|
147
|
+
} : {
|
|
148
|
+
...newMap,
|
|
149
|
+
...flattenComponents(components[key], key)
|
|
220
150
|
}, {});
|
|
221
151
|
}
|
|
222
152
|
|
|
223
153
|
function formatDuration(timeInSeconds) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
154
|
+
const numberOfSeconds = parseInt(String(timeInSeconds), 10); // don't forget the second param
|
|
155
|
+
let hours = Math.floor(numberOfSeconds / 3600);
|
|
156
|
+
let minutes = Math.floor((numberOfSeconds - hours * 3600) / 60);
|
|
157
|
+
let seconds = numberOfSeconds - hours * 3600 - minutes * 60;
|
|
228
158
|
if (hours < 10) {
|
|
229
|
-
hours =
|
|
159
|
+
hours = `0${hours}`;
|
|
230
160
|
}
|
|
231
161
|
if (minutes < 10) {
|
|
232
|
-
minutes =
|
|
162
|
+
minutes = `0${minutes}`;
|
|
233
163
|
}
|
|
234
164
|
if (seconds < 10) {
|
|
235
|
-
seconds =
|
|
165
|
+
seconds = `0${seconds}`;
|
|
236
166
|
}
|
|
237
|
-
return
|
|
167
|
+
return `${hours}:${minutes}:${seconds}`;
|
|
238
168
|
}
|
|
239
169
|
|
|
240
|
-
var _excluded$1 = ["component"];
|
|
241
170
|
function getComponent(component) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
171
|
+
const {
|
|
172
|
+
component: name,
|
|
173
|
+
...props
|
|
174
|
+
} = isObject(component) ? component : {
|
|
175
|
+
component
|
|
176
|
+
};
|
|
247
177
|
return {
|
|
248
178
|
name: component,
|
|
249
179
|
props: Object.keys(props).length > 0 ? props : null
|
|
250
180
|
};
|
|
251
181
|
}
|
|
252
182
|
|
|
253
|
-
var _excluded = ["id", "field"];
|
|
254
183
|
function getColumnFromField(field) {
|
|
255
184
|
if (field === null) {
|
|
256
185
|
return null;
|
|
257
186
|
}
|
|
258
187
|
// eslint-disable-next-line camelcase
|
|
259
|
-
|
|
260
|
-
name
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
188
|
+
const {
|
|
189
|
+
name,
|
|
190
|
+
components: {
|
|
191
|
+
display = null
|
|
192
|
+
} = {},
|
|
193
|
+
label
|
|
194
|
+
} = field;
|
|
195
|
+
const {
|
|
196
|
+
name: componentName = null,
|
|
197
|
+
props: componentProps = null
|
|
198
|
+
} = getComponent(display);
|
|
199
|
+
return {
|
|
200
|
+
...componentProps,
|
|
272
201
|
id: name,
|
|
273
|
-
label
|
|
202
|
+
label,
|
|
274
203
|
valueKey: name,
|
|
275
204
|
component: componentName,
|
|
276
|
-
field
|
|
277
|
-
}
|
|
205
|
+
field
|
|
206
|
+
};
|
|
278
207
|
}
|
|
279
208
|
function getColumnsWithFields(resource, columns) {
|
|
280
|
-
|
|
281
|
-
fields =
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
return
|
|
293
|
-
|
|
294
|
-
|
|
209
|
+
const {
|
|
210
|
+
fields = []
|
|
211
|
+
} = resource;
|
|
212
|
+
const newColumns = columns !== null ? columns.map(column => {
|
|
213
|
+
const {
|
|
214
|
+
id: colId = null,
|
|
215
|
+
field: colField = null,
|
|
216
|
+
...otherProps
|
|
217
|
+
} = isString(column) ? {
|
|
218
|
+
field: column
|
|
219
|
+
} : column;
|
|
220
|
+
const fieldName = colField || colId;
|
|
221
|
+
return {
|
|
222
|
+
...(fieldName !== null ? getColumnFromField(fields.find(it => it.name === fieldName) || null) : null),
|
|
223
|
+
...otherProps,
|
|
295
224
|
id: colId || (isString(column) ? column : null) || null
|
|
296
|
-
}
|
|
297
|
-
}).filter(
|
|
298
|
-
return it !== null;
|
|
299
|
-
}) : [];
|
|
225
|
+
};
|
|
226
|
+
}).filter(it => it !== null) : [];
|
|
300
227
|
return newColumns;
|
|
301
228
|
}
|
|
302
229
|
|
|
303
|
-
function getComponentFromName() {
|
|
304
|
-
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
305
|
-
var components = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
306
|
-
var defaultComponent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
230
|
+
function getComponentFromName(name = null, components = {}, defaultComponent = null) {
|
|
307
231
|
if (components === null || name === null) {
|
|
308
232
|
return defaultComponent;
|
|
309
233
|
}
|
|
310
|
-
|
|
311
|
-
|
|
234
|
+
const pascalName = pascalCase(name);
|
|
235
|
+
const component = components[pascalName] || components[name] || defaultComponent;
|
|
312
236
|
if (!component) {
|
|
313
237
|
console.warn('Could not find component from name', name, pascalName, components);
|
|
314
238
|
}
|
|
315
239
|
return component;
|
|
316
240
|
}
|
|
317
241
|
|
|
318
|
-
function getDefinitionFromId() {
|
|
319
|
-
var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
320
|
-
var items = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
321
|
-
var defaultObject = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
242
|
+
function getDefinitionFromId(id = null, items = [], defaultObject = null) {
|
|
322
243
|
if (items === null || id === null || isArray(items) && items.length === 0) {
|
|
323
244
|
return defaultObject;
|
|
324
245
|
}
|
|
325
|
-
|
|
326
|
-
return items.find(
|
|
327
|
-
return i.id === pascalId;
|
|
328
|
-
}) || items.find(function (i) {
|
|
329
|
-
return i.id === id;
|
|
330
|
-
}) || defaultObject;
|
|
246
|
+
const pascalId = pascalCase(id);
|
|
247
|
+
return items.find(i => i.id === pascalId) || items.find(i => i.id === id) || defaultObject;
|
|
331
248
|
}
|
|
332
249
|
|
|
333
|
-
function getDisplayName(
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
name = _ref$name === void 0 ? null : _ref$name;
|
|
250
|
+
function getDisplayName({
|
|
251
|
+
displayName = null,
|
|
252
|
+
name = null
|
|
253
|
+
}) {
|
|
338
254
|
return displayName || name || 'Component';
|
|
339
255
|
}
|
|
340
256
|
|
|
341
257
|
function getFieldByName(fields, name) {
|
|
342
|
-
return fields.reduce(
|
|
258
|
+
return fields.reduce((foundField, it) => {
|
|
343
259
|
if (foundField !== null) {
|
|
344
260
|
return foundField;
|
|
345
261
|
}
|
|
346
|
-
|
|
347
|
-
fieldName =
|
|
348
|
-
|
|
349
|
-
|
|
262
|
+
const {
|
|
263
|
+
name: fieldName = null,
|
|
264
|
+
fields: subFields = []
|
|
265
|
+
} = it;
|
|
350
266
|
if (name !== null && fieldName === name) {
|
|
351
267
|
return it;
|
|
352
268
|
}
|
|
@@ -355,73 +271,68 @@ function getFieldByName(fields, name) {
|
|
|
355
271
|
}
|
|
356
272
|
|
|
357
273
|
function getFieldFromPath(path, fields, fieldManager) {
|
|
358
|
-
return (isArray(path) ? path : [path]).reduce(
|
|
274
|
+
return (isArray(path) ? path : [path]).reduce((foundField, key) => {
|
|
359
275
|
if (foundField === null) {
|
|
360
276
|
return null;
|
|
361
277
|
}
|
|
362
|
-
|
|
363
|
-
type =
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
settings = _ref$settings === void 0 ? null : _ref$settings,
|
|
374
|
-
_ref$itemsField = _ref.itemsField,
|
|
375
|
-
itemsField = _ref$itemsField === void 0 ? null : _ref$itemsField;
|
|
278
|
+
const {
|
|
279
|
+
type = null,
|
|
280
|
+
fields: fieldFields = null,
|
|
281
|
+
field = null
|
|
282
|
+
} = foundField;
|
|
283
|
+
const finalType = field !== null ? field.type || type : type;
|
|
284
|
+
const {
|
|
285
|
+
fields: subFields = null,
|
|
286
|
+
settings = null,
|
|
287
|
+
itemsField = null
|
|
288
|
+
} = finalType !== null ? fieldManager.getDefinition(finalType) : foundField;
|
|
376
289
|
if (itemsField !== null && key.match(/^[0-9]+$/)) {
|
|
377
|
-
return
|
|
290
|
+
return {
|
|
291
|
+
...itemsField,
|
|
378
292
|
name: (isArray(path) ? path : [path]).join('/'),
|
|
379
293
|
listItems: true
|
|
380
|
-
}
|
|
294
|
+
};
|
|
381
295
|
}
|
|
382
|
-
return getFieldByName([
|
|
296
|
+
return getFieldByName([...(fieldFields || []), ...(subFields || []), ...(settings || [])], key);
|
|
383
297
|
}, {
|
|
384
|
-
fields
|
|
298
|
+
fields
|
|
385
299
|
});
|
|
386
300
|
}
|
|
387
301
|
|
|
388
|
-
function getFileName() {
|
|
389
|
-
var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
302
|
+
function getFileName(url = null) {
|
|
390
303
|
if (url === null || typeof url.match === 'undefined') {
|
|
391
304
|
return null;
|
|
392
305
|
}
|
|
393
|
-
|
|
306
|
+
const match = url.match(/([^/]+)(\?.*)?$/);
|
|
394
307
|
return match ? match[1] : url;
|
|
395
308
|
}
|
|
396
309
|
|
|
397
310
|
function getPathValue(it, path) {
|
|
398
|
-
|
|
399
|
-
return value !== null && isObject(value) ? Object.values(value).reduce(
|
|
400
|
-
return foundValue !== null ? foundValue : val;
|
|
401
|
-
}, null) : value;
|
|
311
|
+
const value = get(it, path, null);
|
|
312
|
+
return value !== null && isObject(value) ? Object.values(value).reduce((foundValue, val) => foundValue !== null ? foundValue : val, null) : value;
|
|
402
313
|
}
|
|
403
314
|
|
|
404
315
|
function getSelectOptions(options) {
|
|
405
|
-
return options.map(
|
|
316
|
+
return options.map(it => {
|
|
406
317
|
if (isObject(it)) {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
318
|
+
const {
|
|
319
|
+
label = null,
|
|
320
|
+
value
|
|
321
|
+
} = it;
|
|
411
322
|
if (label === null) {
|
|
412
323
|
return {
|
|
413
|
-
value
|
|
414
|
-
label: capitalize(
|
|
324
|
+
value,
|
|
325
|
+
label: capitalize(`${value}`)
|
|
415
326
|
};
|
|
416
327
|
}
|
|
417
328
|
return {
|
|
418
|
-
value
|
|
419
|
-
label: /*#__PURE__*/isValidElement(label) ? label :
|
|
329
|
+
value,
|
|
330
|
+
label: /*#__PURE__*/isValidElement(label) ? label : `${label}`
|
|
420
331
|
};
|
|
421
332
|
}
|
|
422
333
|
return {
|
|
423
334
|
value: it,
|
|
424
|
-
label: capitalize(
|
|
335
|
+
label: capitalize(`${it}`)
|
|
425
336
|
};
|
|
426
337
|
});
|
|
427
338
|
}
|
|
@@ -433,135 +344,102 @@ function isMessage(message) {
|
|
|
433
344
|
/**
|
|
434
345
|
* Locale loader
|
|
435
346
|
*/
|
|
436
|
-
|
|
437
|
-
|
|
347
|
+
const loaders = {};
|
|
348
|
+
const events = new EventEmitter();
|
|
438
349
|
function loadPackage(name, loader) {
|
|
439
350
|
if (typeof loaders[name] === 'undefined') {
|
|
440
351
|
loaders[name] = {
|
|
441
|
-
loader: loader().then(
|
|
352
|
+
loader: loader().then(response => {
|
|
442
353
|
loaders[name].loader = null;
|
|
443
354
|
loaders[name].loaded = true;
|
|
444
355
|
loaders[name].resource = response;
|
|
445
|
-
events.emit(
|
|
356
|
+
events.emit(`loaded:${name}`, response);
|
|
446
357
|
return response;
|
|
447
358
|
}),
|
|
448
359
|
loaded: false,
|
|
449
360
|
resource: null
|
|
450
361
|
};
|
|
451
362
|
}
|
|
452
|
-
return new Promise(
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
363
|
+
return new Promise(resolve => {
|
|
364
|
+
const {
|
|
365
|
+
loaded = false,
|
|
366
|
+
resource
|
|
367
|
+
} = loaders[name] || {};
|
|
457
368
|
if (loaded === true) {
|
|
458
369
|
resolve(resource);
|
|
459
370
|
} else {
|
|
460
|
-
events.once(
|
|
371
|
+
events.once(`loaded:${name}`, response => {
|
|
461
372
|
resolve(response);
|
|
462
373
|
});
|
|
463
374
|
}
|
|
464
375
|
});
|
|
465
376
|
}
|
|
466
377
|
|
|
467
|
-
function
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
})
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
var multipleSelection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
481
|
-
var _ref = item || {},
|
|
482
|
-
_ref$id = _ref.id,
|
|
483
|
-
itemId = _ref$id === void 0 ? null : _ref$id;
|
|
484
|
-
var selectedItemsArray = getItemsArray(selectedItems);
|
|
485
|
-
var oldItem = selectedItemsArray.find(function (_ref2) {
|
|
486
|
-
var id = _ref2.id;
|
|
487
|
-
return id === itemId;
|
|
488
|
-
}) || null;
|
|
489
|
-
var newItems = [];
|
|
490
|
-
if (oldItem === null) {
|
|
491
|
-
newItems = selectedItems !== null && multipleSelection ? [].concat(_toConsumableArray(selectedItemsArray), [item]) : [item];
|
|
492
|
-
} else {
|
|
493
|
-
newItems = selectedItemsArray.filter(function (_ref3) {
|
|
494
|
-
var id = _ref3.id;
|
|
495
|
-
return id !== itemId;
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
if (onSelectionChange !== null) {
|
|
499
|
-
var _ref4 = newItems || [],
|
|
500
|
-
_ref5 = _slicedToArray(_ref4, 1),
|
|
501
|
-
_ref5$ = _ref5[0],
|
|
502
|
-
firstItem = _ref5$ === void 0 ? null : _ref5$;
|
|
503
|
-
var value = multipleSelection ? filterNullItems(newItems) : firstItem;
|
|
504
|
-
onSelectionChange(value);
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
function selectPage(pageSelected, items, selectedItems, onSelectionChange) {
|
|
508
|
-
var nextItems = [];
|
|
509
|
-
if (!pageSelected) {
|
|
510
|
-
nextItems = uniqBy([].concat(_toConsumableArray(items || []), _toConsumableArray(selectedItems || [])), function () {
|
|
511
|
-
var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
512
|
-
_ref6$id = _ref6.id,
|
|
513
|
-
id = _ref6$id === void 0 ? null : _ref6$id;
|
|
514
|
-
return id;
|
|
515
|
-
});
|
|
516
|
-
} else {
|
|
517
|
-
var ids = (items || []).map(function () {
|
|
518
|
-
var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
519
|
-
_ref7$id = _ref7.id,
|
|
520
|
-
id = _ref7$id === void 0 ? null : _ref7$id;
|
|
521
|
-
return id;
|
|
522
|
-
}).filter(function (id) {
|
|
523
|
-
return id !== null;
|
|
524
|
-
});
|
|
525
|
-
nextItems = uniqBy((selectedItems || []).filter(function (it) {
|
|
526
|
-
var _ref8 = it || {},
|
|
527
|
-
_ref8$id = _ref8.id,
|
|
528
|
-
id = _ref8$id === void 0 ? null : _ref8$id;
|
|
529
|
-
return ids.indexOf(id) === -1;
|
|
530
|
-
}), function () {
|
|
531
|
-
var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
532
|
-
_ref9$id = _ref9.id,
|
|
533
|
-
id = _ref9$id === void 0 ? null : _ref9$id;
|
|
534
|
-
return id;
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
var finalNextItems = nextItems;
|
|
538
|
-
if (onSelectionChange !== null) {
|
|
539
|
-
onSelectionChange(finalNextItems);
|
|
378
|
+
function toggleSelectedItem(items, item, {
|
|
379
|
+
multiple: multipleSelection = false
|
|
380
|
+
} = {}) {
|
|
381
|
+
const {
|
|
382
|
+
id: itemId = null
|
|
383
|
+
} = item || {};
|
|
384
|
+
const currentItem = (items || []).find(({
|
|
385
|
+
id
|
|
386
|
+
}) => id === itemId) || null;
|
|
387
|
+
if (currentItem !== null) {
|
|
388
|
+
return items.filter(({
|
|
389
|
+
id
|
|
390
|
+
}) => id !== itemId);
|
|
540
391
|
}
|
|
392
|
+
return multipleSelection ? [...(items || []), item] : [item];
|
|
393
|
+
}
|
|
394
|
+
function selectItems(items, itemsToSelect) {
|
|
395
|
+
const newItems = itemsToSelect.filter(item => {
|
|
396
|
+
const {
|
|
397
|
+
id: itemId = null
|
|
398
|
+
} = item || {};
|
|
399
|
+
const currentItem = (items || []).find(({
|
|
400
|
+
id
|
|
401
|
+
}) => id === itemId) || null;
|
|
402
|
+
return currentItem === null;
|
|
403
|
+
});
|
|
404
|
+
return newItems.length > 0 ? [...(items || []), ...newItems] : items;
|
|
405
|
+
}
|
|
406
|
+
function unselectItems(items, itemsToUnselect) {
|
|
407
|
+
const newItems = (items || []).filter(item => {
|
|
408
|
+
const {
|
|
409
|
+
id: itemId = null
|
|
410
|
+
} = item || {};
|
|
411
|
+
const currentItem = itemsToUnselect.find(({
|
|
412
|
+
id
|
|
413
|
+
}) => id === itemId) || null;
|
|
414
|
+
return currentItem === null;
|
|
415
|
+
});
|
|
416
|
+
return items !== null && newItems.length !== items.length ? newItems : items;
|
|
541
417
|
}
|
|
542
418
|
|
|
543
419
|
function setValue(value, keyParts, fieldValue) {
|
|
544
|
-
|
|
420
|
+
const key = keyParts.shift();
|
|
545
421
|
if (!key) {
|
|
546
422
|
return value;
|
|
547
423
|
}
|
|
548
|
-
|
|
424
|
+
const isArray = key.match(/^[0-9]+$/) !== null;
|
|
549
425
|
if (value !== null || fieldValue !== null) {
|
|
550
426
|
if (isArray) {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
427
|
+
const index = parseInt(key, 10);
|
|
428
|
+
const arrayValue = value;
|
|
429
|
+
const newArrayValue = fieldValue !== null ? [...arrayValue.slice(0, index), keyParts.length > 0 ? setValue(arrayValue !== null ? arrayValue[index] || null : null, keyParts, fieldValue) : fieldValue, ...arrayValue.slice(index + 1)] : [...arrayValue.slice(0, index), ...arrayValue.slice(index + 1)];
|
|
554
430
|
return newArrayValue.length > 0 ? newArrayValue : null;
|
|
555
431
|
}
|
|
556
|
-
|
|
557
|
-
return
|
|
432
|
+
const objectValue = value;
|
|
433
|
+
return {
|
|
434
|
+
...objectValue,
|
|
435
|
+
[key]: keyParts.length > 0 ? setValue(objectValue !== null ? objectValue[key] || null : null, keyParts, fieldValue) : fieldValue
|
|
436
|
+
};
|
|
558
437
|
}
|
|
559
438
|
return null;
|
|
560
439
|
}
|
|
561
440
|
|
|
562
|
-
function slug(str) {
|
|
563
|
-
|
|
564
|
-
var toSlug;
|
|
441
|
+
function slug(str, separator = null) {
|
|
442
|
+
let toSlug;
|
|
565
443
|
if (separator === '-') {
|
|
566
444
|
toSlug = kebabCase(str);
|
|
567
445
|
} else {
|
|
@@ -573,16 +451,16 @@ function slug(str) {
|
|
|
573
451
|
}
|
|
574
452
|
|
|
575
453
|
function validateFields(fields, value) {
|
|
576
|
-
return fields.reduce(
|
|
454
|
+
return fields.reduce((acc, field) => {
|
|
577
455
|
if (acc === true) {
|
|
578
456
|
if (field.type === 'fields' && field.fields) {
|
|
579
457
|
return validateFields(field.fields, value);
|
|
580
458
|
}
|
|
581
|
-
|
|
459
|
+
const val = value && field.name && value[field.name] ? value[field.name] : false;
|
|
582
460
|
return !(field.required && !val);
|
|
583
461
|
}
|
|
584
462
|
return acc;
|
|
585
463
|
}, true);
|
|
586
464
|
}
|
|
587
465
|
|
|
588
|
-
export { checkClickable, convertStyleToString, copyToClipboard, createNullableOnChange, createUseEvent, flattenComponents, formatDuration, getColumnsWithFields, getComponent, getComponentFromName, getDefinitionFromId, getDisplayName, getFieldByName, getFieldFromPath, getFileName, getPathValue, getSelectOptions, isMessage, loadPackage,
|
|
466
|
+
export { checkClickable, convertStyleToString, copyToClipboard, createNullableOnChange, createUseEvent, flattenComponents, formatDuration, getColumnsWithFields, getComponent, getComponentFromName, getDefinitionFromId, getDisplayName, getFieldByName, getFieldFromPath, getFileName, getPathValue, getSelectOptions, isMessage, loadPackage, selectItems, setValue as setFieldValue, slug, toggleSelectedItem, unselectItems, validateFields };
|