@panneau/core 1.0.1-alpha.0 → 1.0.3-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/contexts.js +1 -1
- package/es/contexts.js +1740 -0
- package/es/hooks.js +1116 -0
- package/es/index.js +991 -9
- package/es/utils.js +329 -1
- package/hooks.js +1 -0
- package/lib/contexts.js +1871 -0
- package/lib/hooks.js +1167 -0
- package/lib/index.js +1003 -44
- package/lib/utils.js +371 -12
- package/package.json +79 -49
- package/utils.js +1 -1
- package/components.js +0 -1
- package/es/components/Button.js +0 -157
- package/es/components/ButtonGroup.js +0 -87
- package/es/components/Errors.js +0 -33
- package/es/components/Label.js +0 -32
- package/es/components/Loading.js +0 -56
- package/es/components/index.js +0 -6
- package/es/contexts/Components.js +0 -52
- package/es/contexts/Definition.js +0 -21
- package/es/contexts/UrlGenerator.js +0 -33
- package/es/contexts/index.js +0 -3
- package/es/lib/ComponentsCollection.js +0 -107
- package/es/lib/Definition.js +0 -134
- package/es/lib/PropTypes.js +0 -75
- package/es/lib/Resource.js +0 -93
- package/es/lib/ResourceApi.js +0 -139
- package/es/lib/UrlGenerator.js +0 -66
- package/es/lib/requests.js +0 -165
- package/es/lib/useResourceApi.js +0 -19
- package/es/lib/utils.js +0 -19
- package/es/requests.js +0 -1
- package/lib/components/Button.js +0 -182
- package/lib/components/ButtonGroup.js +0 -104
- package/lib/components/Errors.js +0 -49
- package/lib/components/Label.js +0 -47
- package/lib/components/Loading.js +0 -70
- package/lib/components/index.js +0 -47
- package/lib/contexts/Components.js +0 -78
- package/lib/contexts/Definition.js +0 -45
- package/lib/contexts/UrlGenerator.js +0 -53
- package/lib/contexts/index.js +0 -73
- package/lib/lib/ComponentsCollection.js +0 -117
- package/lib/lib/Definition.js +0 -145
- package/lib/lib/PropTypes.js +0 -152
- package/lib/lib/Resource.js +0 -104
- package/lib/lib/ResourceApi.js +0 -154
- package/lib/lib/UrlGenerator.js +0 -76
- package/lib/lib/requests.js +0 -206
- package/lib/lib/useResourceApi.js +0 -33
- package/lib/lib/utils.js +0 -35
- package/lib/requests.js +0 -17
- package/requests.js +0 -1
- package/src/components/Button.jsx +0 -186
- package/src/components/ButtonGroup.jsx +0 -98
- package/src/components/Errors.jsx +0 -46
- package/src/components/Label.jsx +0 -32
- package/src/components/Loading.jsx +0 -51
- package/src/components/index.js +0 -7
- package/src/contexts/Components.jsx +0 -49
- package/src/contexts/Definition.jsx +0 -21
- package/src/contexts/UrlGenerator.jsx +0 -35
- package/src/contexts/index.js +0 -12
- package/src/index.js +0 -8
- package/src/lib/ComponentsCollection.js +0 -81
- package/src/lib/Definition.js +0 -87
- package/src/lib/PropTypes.js +0 -117
- package/src/lib/Resource.js +0 -65
- package/src/lib/ResourceApi.js +0 -114
- package/src/lib/UrlGenerator.js +0 -55
- package/src/lib/requests.js +0 -120
- package/src/lib/useResourceApi.jsx +0 -20
- package/src/lib/utils.js +0 -13
- package/src/requests.js +0 -1
- package/src/styles/components/button-group.scss +0 -10
- package/src/styles/components/errors.scss +0 -5
- package/src/styles/components/loading.scss +0 -36
- package/src/styles/variables.scss +0 -5
- package/src/utils.js +0 -1
package/es/utils.js
CHANGED
|
@@ -1 +1,329 @@
|
|
|
1
|
-
|
|
1
|
+
import isNumber from 'lodash/isNumber';
|
|
2
|
+
import { snakeCase } from 'snake-case';
|
|
3
|
+
import isObject from 'lodash/isObject';
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
import { pascalCase, paramCase, snakeCase as snakeCase$1 } from 'change-case';
|
|
6
|
+
export { paramCase as dashCase, pascalCase, snakeCase } from 'change-case';
|
|
7
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
8
|
+
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
9
|
+
import ReactIs from 'react-is';
|
|
10
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
11
|
+
import isString from 'lodash/isString';
|
|
12
|
+
import isArray from 'lodash/isArray';
|
|
13
|
+
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
14
|
+
import get from 'lodash/get';
|
|
15
|
+
import capitalize from 'lodash/capitalize';
|
|
16
|
+
import slugify from 'slugify';
|
|
17
|
+
|
|
18
|
+
var convertStyleToString = function convertStyleToString(style) {
|
|
19
|
+
return style !== null ? Object.keys(style).map(function (key) {
|
|
20
|
+
return "".concat(snakeCase(key), ":").concat(isNumber(style[key]) ? "".concat(style[key], "px") : style[key], ";");
|
|
21
|
+
}).join('\n') : '';
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var createNullableOnChange = function createNullableOnChange() {
|
|
25
|
+
var onChange = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
26
|
+
return function (newValue) {
|
|
27
|
+
var nullableValue = newValue;
|
|
28
|
+
|
|
29
|
+
if (isObject(newValue)) {
|
|
30
|
+
var allNull = Object.keys(newValue).reduce(function (acc, key) {
|
|
31
|
+
return acc && newValue[key] === null;
|
|
32
|
+
}, true);
|
|
33
|
+
|
|
34
|
+
if (allNull) {
|
|
35
|
+
nullableValue = null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (onChange !== null) {
|
|
40
|
+
onChange(nullableValue);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
var createUseEvent = function createUseEvent(eventsManager) {
|
|
46
|
+
return function (event, callback) {
|
|
47
|
+
var enabled = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
48
|
+
useEffect(function () {
|
|
49
|
+
if (enabled && eventsManager !== null) {
|
|
50
|
+
eventsManager.subscribe(event, callback);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return function () {
|
|
54
|
+
if (enabled && eventsManager !== null) {
|
|
55
|
+
eventsManager.unsubscribe(event, callback);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}, [eventsManager, event, callback, enabled]);
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
var flattenComponents = function flattenComponents(components) {
|
|
63
|
+
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
64
|
+
|
|
65
|
+
if (components === null) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return Object.keys(components).reduce(function (newMap, key) {
|
|
70
|
+
return ReactIs.isValidElementType(components[key]) ? _objectSpread(_objectSpread({}, newMap), {}, _defineProperty({}, prefix !== null ? "".concat(prefix, ".").concat(key) : key, components[key])) : _objectSpread(_objectSpread({}, newMap), flattenComponents(components[key], key));
|
|
71
|
+
}, {});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
var _excluded$1 = ["component"];
|
|
75
|
+
|
|
76
|
+
var getComponent = function getComponent(component) {
|
|
77
|
+
var _ref = isObject(component) ? component : {
|
|
78
|
+
component: component
|
|
79
|
+
};
|
|
80
|
+
_ref.component;
|
|
81
|
+
var props = _objectWithoutProperties(_ref, _excluded$1);
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
name: component,
|
|
85
|
+
props: props
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
var _excluded = ["field"];
|
|
90
|
+
var getColumnFromField = function getColumnFromField(field) {
|
|
91
|
+
if (field === null) {
|
|
92
|
+
return null;
|
|
93
|
+
} // eslint-disable-next-line camelcase
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
var name = field.name,
|
|
97
|
+
_field$components = field.components;
|
|
98
|
+
_field$components = _field$components === void 0 ? {} : _field$components;
|
|
99
|
+
var _field$components$dis = _field$components.display,
|
|
100
|
+
display = _field$components$dis === void 0 ? null : _field$components$dis,
|
|
101
|
+
label = field.label;
|
|
102
|
+
|
|
103
|
+
var _getComponent = getComponent(display),
|
|
104
|
+
_getComponent$name = _getComponent.name,
|
|
105
|
+
componentName = _getComponent$name === void 0 ? null : _getComponent$name,
|
|
106
|
+
_getComponent$props = _getComponent.props,
|
|
107
|
+
componentProps = _getComponent$props === void 0 ? null : _getComponent$props;
|
|
108
|
+
|
|
109
|
+
return _objectSpread(_objectSpread({}, componentProps), {}, {
|
|
110
|
+
id: name,
|
|
111
|
+
label: label,
|
|
112
|
+
valueKey: name,
|
|
113
|
+
component: componentName,
|
|
114
|
+
field: field
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
var getColumnsWithFields = function getColumnsWithFields(resource, columns) {
|
|
118
|
+
var fields = resource.fields;
|
|
119
|
+
var newColumns = columns !== null ? columns.map(function (column) {
|
|
120
|
+
var _ref = isString(column) ? {
|
|
121
|
+
field: column
|
|
122
|
+
} : column,
|
|
123
|
+
_ref$field = _ref.field,
|
|
124
|
+
fieldName = _ref$field === void 0 ? null : _ref$field,
|
|
125
|
+
otherProps = _objectWithoutProperties(_ref, _excluded);
|
|
126
|
+
|
|
127
|
+
return _objectSpread(_objectSpread({}, fieldName !== null ? getColumnFromField(fields.find(function (it) {
|
|
128
|
+
return it.name === fieldName;
|
|
129
|
+
}) || null) : null), otherProps);
|
|
130
|
+
}).filter(function (it) {
|
|
131
|
+
return it !== null;
|
|
132
|
+
}) : [];
|
|
133
|
+
return newColumns;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
var getComponentFromName = function getComponentFromName() {
|
|
137
|
+
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
138
|
+
var components = arguments.length > 1 ? arguments[1] : undefined;
|
|
139
|
+
var defaultComponent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
140
|
+
|
|
141
|
+
if (components === null || name === null) {
|
|
142
|
+
return defaultComponent;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
var pascalName = pascalCase(name);
|
|
146
|
+
var component = components[pascalName] || components[name] || defaultComponent;
|
|
147
|
+
|
|
148
|
+
if (!component) {
|
|
149
|
+
console.warn('Could not find component from name', name, pascalName, components);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return component;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
var getDefinitionFromId = function getDefinitionFromId() {
|
|
156
|
+
var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
157
|
+
var items = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
158
|
+
var defaultObject = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
159
|
+
|
|
160
|
+
if (items === null || id === null || isArray(items) && items.length === 0) {
|
|
161
|
+
return defaultObject;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
var pascalId = pascalCase(id);
|
|
165
|
+
return items.find(function (i) {
|
|
166
|
+
return i.id === pascalId;
|
|
167
|
+
}) || items.find(function (i) {
|
|
168
|
+
return i.id === id;
|
|
169
|
+
}) || defaultObject;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
var getDisplayName = function getDisplayName(_ref) {
|
|
173
|
+
var _ref$displayName = _ref.displayName,
|
|
174
|
+
displayName = _ref$displayName === void 0 ? null : _ref$displayName,
|
|
175
|
+
_ref$name = _ref.name,
|
|
176
|
+
name = _ref$name === void 0 ? null : _ref$name;
|
|
177
|
+
return displayName || name || 'Component';
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
var getFieldByName = function getFieldByName(fields, name) {
|
|
181
|
+
return fields.reduce(function (foundField, it) {
|
|
182
|
+
if (foundField !== null) {
|
|
183
|
+
return foundField;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
var _it$name = it.name,
|
|
187
|
+
fieldName = _it$name === void 0 ? null : _it$name,
|
|
188
|
+
_it$fields = it.fields,
|
|
189
|
+
subFields = _it$fields === void 0 ? [] : _it$fields;
|
|
190
|
+
|
|
191
|
+
if (name !== null && fieldName === name) {
|
|
192
|
+
return it;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return getFieldByName(subFields, name);
|
|
196
|
+
}, null);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
var getFieldFromPath = function getFieldFromPath(path, fields, fieldManager) {
|
|
200
|
+
return (isArray(path) ? path : [path]).reduce(function (foundField, key) {
|
|
201
|
+
if (foundField === null) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
var _foundField$type = foundField.type,
|
|
206
|
+
type = _foundField$type === void 0 ? null : _foundField$type,
|
|
207
|
+
_foundField$fields = foundField.fields,
|
|
208
|
+
fieldFields = _foundField$fields === void 0 ? null : _foundField$fields,
|
|
209
|
+
_foundField$field = foundField.field,
|
|
210
|
+
field = _foundField$field === void 0 ? null : _foundField$field;
|
|
211
|
+
var finalType = field !== null ? field.type || type : type;
|
|
212
|
+
|
|
213
|
+
var _ref = finalType !== null ? fieldManager.getDefinition(finalType) : foundField,
|
|
214
|
+
_ref$fields = _ref.fields,
|
|
215
|
+
subFields = _ref$fields === void 0 ? null : _ref$fields,
|
|
216
|
+
_ref$settings = _ref.settings,
|
|
217
|
+
settings = _ref$settings === void 0 ? null : _ref$settings,
|
|
218
|
+
_ref$itemsField = _ref.itemsField,
|
|
219
|
+
itemsField = _ref$itemsField === void 0 ? null : _ref$itemsField;
|
|
220
|
+
|
|
221
|
+
if (itemsField !== null && key.match(/^[0-9]+$/)) {
|
|
222
|
+
return _objectSpread(_objectSpread({}, itemsField), {}, {
|
|
223
|
+
name: path.join('/'),
|
|
224
|
+
listItems: true
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return getFieldByName([].concat(_toConsumableArray(fieldFields || []), _toConsumableArray(subFields || []), _toConsumableArray(settings || [])), key);
|
|
229
|
+
}, {
|
|
230
|
+
fields: fields
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
var getFileName = function getFileName() {
|
|
235
|
+
var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
236
|
+
|
|
237
|
+
if (url === null || typeof url.match === 'undefined') {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return url.match(/([^/]+)(\?.*)?$/)[1] || url;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
var getPathValue = function getPathValue(it, path) {
|
|
245
|
+
var value = get(it, path, null);
|
|
246
|
+
return value !== null && isObject(value) ? Object.values(value).reduce(function (foundValue, value) {
|
|
247
|
+
return foundValue !== null ? foundValue : value;
|
|
248
|
+
}, null) : value;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
var getSelectOptions = function getSelectOptions(options) {
|
|
252
|
+
return options.map(function (it) {
|
|
253
|
+
if (isObject(it)) {
|
|
254
|
+
var _it$label = it.label,
|
|
255
|
+
label = _it$label === void 0 ? null : _it$label,
|
|
256
|
+
value = it.value;
|
|
257
|
+
|
|
258
|
+
if (label === null) {
|
|
259
|
+
return {
|
|
260
|
+
value: value,
|
|
261
|
+
label: capitalize("".concat(value))
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
value: value,
|
|
267
|
+
label: "".concat(label)
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
value: it,
|
|
273
|
+
label: capitalize("".concat(it))
|
|
274
|
+
};
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
var isMessage = function isMessage(message) {
|
|
279
|
+
return isObject(message) && typeof message.defaultMessage !== 'undefined';
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
var setValue = function setValue(value, keyParts, fieldValue) {
|
|
283
|
+
var key = keyParts.shift();
|
|
284
|
+
var isArray = key.match(/^[0-9]+$/) !== null;
|
|
285
|
+
|
|
286
|
+
if (value !== null || fieldValue !== null) {
|
|
287
|
+
if (isArray) {
|
|
288
|
+
var index = parseInt(key, 10);
|
|
289
|
+
var newArrayValue = fieldValue !== null ? [].concat(_toConsumableArray(value.slice(0, index)), [keyParts.length > 0 ? setValue(value !== null ? value[index] || null : null, keyParts, fieldValue) : fieldValue], _toConsumableArray(value.slice(index + 1))) : [].concat(_toConsumableArray(value.slice(0, index)), _toConsumableArray(value.slice(index + 1)));
|
|
290
|
+
return newArrayValue.length > 0 ? newArrayValue : null;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return _objectSpread(_objectSpread({}, value), {}, _defineProperty({}, key, keyParts.length > 0 ? setValue(value !== null ? value[key] || null : null, keyParts, fieldValue) : fieldValue));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return null;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
var slug = function slug(str) {
|
|
300
|
+
var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
301
|
+
var toSlug;
|
|
302
|
+
|
|
303
|
+
if (separator === '-') {
|
|
304
|
+
toSlug = paramCase(str);
|
|
305
|
+
} else {
|
|
306
|
+
toSlug = snakeCase$1(str);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return slugify(toSlug, {
|
|
310
|
+
lower: true
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
var validateFields = function validateFields(fields, value) {
|
|
315
|
+
return fields.reduce(function (acc, field) {
|
|
316
|
+
if (acc === true) {
|
|
317
|
+
if (field.type === 'fields' && field.fields) {
|
|
318
|
+
return validateFields(field.fields, value);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
var val = value && value[field.name] ? value[field.name] : false;
|
|
322
|
+
return !(field.required && !val);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return acc;
|
|
326
|
+
}, true);
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
export { convertStyleToString, createNullableOnChange, createUseEvent, flattenComponents, getColumnsWithFields, getComponent, getComponentFromName, getDefinitionFromId, getDisplayName, getFieldByName, getFieldFromPath, getFileName, getPathValue, getSelectOptions, isMessage, setValue as setFieldValue, slug, validateFields };
|
package/hooks.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./lib/hooks');
|