@panneau/core 1.0.0-alpha.21 → 1.0.0-alpha.224
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/es/contexts.js +130 -103
- package/es/hooks.js +37 -16
- package/es/index.js +51 -11
- package/es/utils.js +86 -69
- package/lib/contexts.js +328 -305
- package/lib/hooks.js +82 -61
- package/lib/index.js +198 -157
- package/lib/utils.js +107 -91
- package/package.json +8 -7
package/es/index.js
CHANGED
|
@@ -11,10 +11,13 @@ import 'snake-case';
|
|
|
11
11
|
import isObject from 'lodash/isObject';
|
|
12
12
|
import 'react';
|
|
13
13
|
import { pascalCase } from 'change-case';
|
|
14
|
-
import '
|
|
14
|
+
import ReactIs from 'react-is';
|
|
15
15
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
16
|
+
import 'lodash/isString';
|
|
16
17
|
import isArray from 'lodash/isArray';
|
|
17
18
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
19
|
+
import 'lodash/get';
|
|
20
|
+
import 'lodash/capitalize';
|
|
18
21
|
import 'slugify';
|
|
19
22
|
import uniqBy from 'lodash/uniqBy';
|
|
20
23
|
import uniq from 'lodash/uniq';
|
|
@@ -60,6 +63,14 @@ var toggle = PropTypes$1.shape({
|
|
|
60
63
|
label: PropTypes$1.string
|
|
61
64
|
});
|
|
62
65
|
var toggles = PropTypes$1.arrayOf(toggle);
|
|
66
|
+
var tableColumn = PropTypes$1.shape({
|
|
67
|
+
id: PropTypes$1.string,
|
|
68
|
+
component: PropTypes$1.string,
|
|
69
|
+
path: PropTypes$1.string,
|
|
70
|
+
field: PropTypes$1.string,
|
|
71
|
+
columnClassName: PropTypes$1.string
|
|
72
|
+
});
|
|
73
|
+
var tableColumns = PropTypes$1.arrayOf(tableColumn);
|
|
63
74
|
/**
|
|
64
75
|
* Panneau Definitions
|
|
65
76
|
*/
|
|
@@ -71,6 +82,7 @@ var routes = PropTypes$1.shape({
|
|
|
71
82
|
'resources.show': PropTypes$1.string.isRequired,
|
|
72
83
|
'resources.edit': PropTypes$1.string.isRequired,
|
|
73
84
|
'resources.update': PropTypes$1.string.isRequired,
|
|
85
|
+
'resources.delete': PropTypes$1.string.isRequired,
|
|
74
86
|
'resources.destroy': PropTypes$1.string.isRequired
|
|
75
87
|
});
|
|
76
88
|
var intl = PropTypes$1.shape({
|
|
@@ -85,8 +97,9 @@ var pages = PropTypes$1.objectOf(page);
|
|
|
85
97
|
var field = PropTypes$1.shape({
|
|
86
98
|
// type: PropTypes.string.isRequired,
|
|
87
99
|
name: PropTypes$1.isRequired,
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
type: PropTypes$1.string,
|
|
101
|
+
component: PropTypes$1.string,
|
|
102
|
+
label: PropTypes$1.node
|
|
90
103
|
});
|
|
91
104
|
var fields = PropTypes$1.arrayOf(field);
|
|
92
105
|
var form = PropTypes$1.shape({
|
|
@@ -97,11 +110,10 @@ var form = PropTypes$1.shape({
|
|
|
97
110
|
var forms = PropTypes$1.arrayOf(form);
|
|
98
111
|
var resource = PropTypes$1.shape({
|
|
99
112
|
id: PropTypes$1.string.isRequired,
|
|
100
|
-
|
|
113
|
+
name: PropTypes$1.string.isRequired,
|
|
101
114
|
intl: intl,
|
|
102
115
|
fields: fields,
|
|
103
116
|
forms: PropTypes$1.shape({}),
|
|
104
|
-
has_routes: PropTypes$1.bool,
|
|
105
117
|
shows_in_navbar: PropTypes$1.bool
|
|
106
118
|
});
|
|
107
119
|
var resources = PropTypes$1.arrayOf(resource);
|
|
@@ -138,6 +150,11 @@ var formError = PropTypes$1.shape({
|
|
|
138
150
|
message: PropTypes$1.string
|
|
139
151
|
});
|
|
140
152
|
var formErrors = PropTypes$1.arrayOf(formError);
|
|
153
|
+
var uppy = PropTypes$1.shape({
|
|
154
|
+
tus: PropTypes$1.object
|
|
155
|
+
}); // eslint-disable-line
|
|
156
|
+
|
|
157
|
+
var triggerUpdate = PropTypes$1.string;
|
|
141
158
|
|
|
142
159
|
var PropTypes = /*#__PURE__*/Object.freeze({
|
|
143
160
|
__proto__: null,
|
|
@@ -158,6 +175,8 @@ var PropTypes = /*#__PURE__*/Object.freeze({
|
|
|
158
175
|
fieldOptions: fieldOptions,
|
|
159
176
|
toggle: toggle,
|
|
160
177
|
toggles: toggles,
|
|
178
|
+
tableColumn: tableColumn,
|
|
179
|
+
tableColumns: tableColumns,
|
|
161
180
|
routes: routes,
|
|
162
181
|
intl: intl,
|
|
163
182
|
page: page,
|
|
@@ -178,9 +197,23 @@ var PropTypes = /*#__PURE__*/Object.freeze({
|
|
|
178
197
|
selectOptions: selectOptions,
|
|
179
198
|
feedback: feedback,
|
|
180
199
|
formError: formError,
|
|
181
|
-
formErrors: formErrors
|
|
200
|
+
formErrors: formErrors,
|
|
201
|
+
uppy: uppy,
|
|
202
|
+
triggerUpdate: triggerUpdate
|
|
182
203
|
});
|
|
183
204
|
|
|
205
|
+
var flattenComponents = function flattenComponents(components) {
|
|
206
|
+
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
207
|
+
|
|
208
|
+
if (components === null) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return Object.keys(components).reduce(function (newMap, key) {
|
|
213
|
+
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));
|
|
214
|
+
}, {});
|
|
215
|
+
};
|
|
216
|
+
|
|
184
217
|
var getComponentFromName = function getComponentFromName() {
|
|
185
218
|
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
186
219
|
var components = arguments.length > 1 ? arguments[1] : undefined;
|
|
@@ -213,7 +246,7 @@ var ComponentsManager = /*#__PURE__*/function (_EventEmitter) {
|
|
|
213
246
|
_classCallCheck(this, ComponentsManager);
|
|
214
247
|
|
|
215
248
|
_this = _super.call(this);
|
|
216
|
-
_this.components = components;
|
|
249
|
+
_this.components = flattenComponents(components);
|
|
217
250
|
return _this;
|
|
218
251
|
}
|
|
219
252
|
|
|
@@ -456,6 +489,8 @@ var FieldsManager$1 = /*#__PURE__*/function (_DefinitionsManager) {
|
|
|
456
489
|
return FieldsManager;
|
|
457
490
|
}(DefinitionsManager);
|
|
458
491
|
|
|
492
|
+
var _excluded$2 = ["fonts"];
|
|
493
|
+
|
|
459
494
|
var FontsParser = /*#__PURE__*/function () {
|
|
460
495
|
function FontsParser(_ref) {
|
|
461
496
|
var fieldsManager = _ref.fieldsManager,
|
|
@@ -501,7 +536,7 @@ var FontsParser = /*#__PURE__*/function () {
|
|
|
501
536
|
var _this$parse = this.parse(theme),
|
|
502
537
|
_this$parse$fonts = _this$parse.fonts,
|
|
503
538
|
themeFonts = _this$parse$fonts === void 0 ? [] : _this$parse$fonts,
|
|
504
|
-
newTheme = _objectWithoutProperties(_this$parse,
|
|
539
|
+
newTheme = _objectWithoutProperties(_this$parse, _excluded$2);
|
|
505
540
|
|
|
506
541
|
return fonts.length > 0 || themeFonts.length > 0 ? _objectSpread(_objectSpread({}, story), {}, {
|
|
507
542
|
theme: newTheme,
|
|
@@ -599,6 +634,8 @@ var FieldsManager = /*#__PURE__*/function (_ComponentsManager) {
|
|
|
599
634
|
return FieldsManager;
|
|
600
635
|
}(ComponentsManager);
|
|
601
636
|
|
|
637
|
+
var _excluded$1 = ["medias"];
|
|
638
|
+
|
|
602
639
|
var MediasParser = /*#__PURE__*/function () {
|
|
603
640
|
function MediasParser(_ref) {
|
|
604
641
|
var fieldsManager = _ref.fieldsManager,
|
|
@@ -655,7 +692,7 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
655
692
|
if (theme !== null) {
|
|
656
693
|
var _this$toPath = this.toPath(theme),
|
|
657
694
|
themeMedias = _this$toPath.medias,
|
|
658
|
-
newTheme = _objectWithoutProperties(_this$toPath,
|
|
695
|
+
newTheme = _objectWithoutProperties(_this$toPath, _excluded$1);
|
|
659
696
|
|
|
660
697
|
return medias !== null || themeMedias !== null ? _objectSpread(_objectSpread({}, story), {}, {
|
|
661
698
|
theme: newTheme,
|
|
@@ -838,6 +875,9 @@ var MediasParser = /*#__PURE__*/function () {
|
|
|
838
875
|
return MediasParser;
|
|
839
876
|
}();
|
|
840
877
|
|
|
878
|
+
var _excluded = ["value"],
|
|
879
|
+
_excluded2 = ["value"];
|
|
880
|
+
|
|
841
881
|
var Tracking = /*#__PURE__*/function (_BaseTracking) {
|
|
842
882
|
_inherits(Tracking, _BaseTracking);
|
|
843
883
|
|
|
@@ -899,7 +939,7 @@ var Tracking = /*#__PURE__*/function (_BaseTracking) {
|
|
|
899
939
|
var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
900
940
|
_ref2$value = _ref2.value,
|
|
901
941
|
value = _ref2$value === void 0 ? null : _ref2$value,
|
|
902
|
-
opts = _objectWithoutProperties(_ref2,
|
|
942
|
+
opts = _objectWithoutProperties(_ref2, _excluded);
|
|
903
943
|
|
|
904
944
|
var data = _objectSpread(_objectSpread({}, opts), {}, {
|
|
905
945
|
event: 'eventInteraction',
|
|
@@ -917,7 +957,7 @@ var Tracking = /*#__PURE__*/function (_BaseTracking) {
|
|
|
917
957
|
var _ref3 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
|
|
918
958
|
_ref3$value = _ref3.value,
|
|
919
959
|
value = _ref3$value === void 0 ? null : _ref3$value,
|
|
920
|
-
opts = _objectWithoutProperties(_ref3,
|
|
960
|
+
opts = _objectWithoutProperties(_ref3, _excluded2);
|
|
921
961
|
|
|
922
962
|
var _ref4 = media || {},
|
|
923
963
|
_ref4$id = _ref4.id,
|
package/es/utils.js
CHANGED
|
@@ -4,12 +4,15 @@ import isObject from 'lodash/isObject';
|
|
|
4
4
|
import { useEffect } from 'react';
|
|
5
5
|
import { pascalCase, paramCase, snakeCase as snakeCase$1 } from 'change-case';
|
|
6
6
|
export { paramCase as dashCase, pascalCase, snakeCase } from 'change-case';
|
|
7
|
-
import
|
|
7
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
8
|
+
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
9
|
+
import ReactIs from 'react-is';
|
|
8
10
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
11
|
+
import isString from 'lodash/isString';
|
|
9
12
|
import isArray from 'lodash/isArray';
|
|
10
13
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
11
|
-
import
|
|
12
|
-
import
|
|
14
|
+
import get from 'lodash/get';
|
|
15
|
+
import capitalize from 'lodash/capitalize';
|
|
13
16
|
import slugify from 'slugify';
|
|
14
17
|
|
|
15
18
|
var convertStyleToString = function convertStyleToString(style) {
|
|
@@ -56,6 +59,34 @@ var createUseEvent = function createUseEvent(eventsManager) {
|
|
|
56
59
|
};
|
|
57
60
|
};
|
|
58
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"];
|
|
59
90
|
var getColumnFromField = function getColumnFromField(field) {
|
|
60
91
|
if (field === null) {
|
|
61
92
|
return null;
|
|
@@ -63,82 +94,43 @@ var getColumnFromField = function getColumnFromField(field) {
|
|
|
63
94
|
|
|
64
95
|
|
|
65
96
|
var name = field.name,
|
|
66
|
-
_field$components = field.components
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
var order = _field$settings.orderInIndex,
|
|
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,
|
|
71
101
|
label = field.label;
|
|
72
|
-
|
|
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), {}, {
|
|
73
110
|
id: name,
|
|
74
111
|
label: label,
|
|
75
112
|
valueKey: name,
|
|
76
|
-
|
|
77
|
-
component: components !== null ? components.index_column || components.index || null : null,
|
|
113
|
+
component: componentName,
|
|
78
114
|
field: field
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
var sortColumns = function sortColumns(columns) {
|
|
82
|
-
return columns.sort(function (_ref, _ref2) {
|
|
83
|
-
var _ref$order = _ref.order,
|
|
84
|
-
aOrder = _ref$order === void 0 ? null : _ref$order;
|
|
85
|
-
var _ref2$order = _ref2.order,
|
|
86
|
-
bOrder = _ref2$order === void 0 ? null : _ref2$order;
|
|
87
|
-
|
|
88
|
-
if (aOrder === bOrder) {
|
|
89
|
-
return 0;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (aOrder === null) {
|
|
93
|
-
return 1;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (bOrder === null) {
|
|
97
|
-
return -1;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return aOrder > bOrder ? 1 : -1;
|
|
101
115
|
});
|
|
102
116
|
};
|
|
103
|
-
var
|
|
104
|
-
var fields = resource.fields
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
var newColumns = resourceColumns !== null ? resourceColumns.map(function (column) {
|
|
108
|
-
var _ref3 = isString(column) ? {
|
|
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) ? {
|
|
109
121
|
field: column
|
|
110
122
|
} : column,
|
|
111
|
-
|
|
112
|
-
fieldName =
|
|
123
|
+
_ref$field = _ref.field,
|
|
124
|
+
fieldName = _ref$field === void 0 ? null : _ref$field,
|
|
125
|
+
otherProps = _objectWithoutProperties(_ref, _excluded);
|
|
113
126
|
|
|
114
|
-
return fieldName !== null ? getColumnFromField(fields.find(function (it) {
|
|
127
|
+
return _objectSpread(_objectSpread({}, fieldName !== null ? getColumnFromField(fields.find(function (it) {
|
|
115
128
|
return it.name === fieldName;
|
|
116
|
-
}) || null) :
|
|
129
|
+
}) || null) : null), otherProps);
|
|
117
130
|
}).filter(function (it) {
|
|
118
131
|
return it !== null;
|
|
119
|
-
}) :
|
|
120
|
-
|
|
121
|
-
_ref4$settings = _ref4$settings === void 0 ? {} : _ref4$settings;
|
|
122
|
-
var _ref4$settings$hidden = _ref4$settings.hiddenInIndex,
|
|
123
|
-
hiddenInIndex = _ref4$settings$hidden === void 0 ? false : _ref4$settings$hidden;
|
|
124
|
-
return !hiddenInIndex;
|
|
125
|
-
}).map(function (field) {
|
|
126
|
-
return getColumnFromField(field);
|
|
127
|
-
});
|
|
128
|
-
return sortColumns(newColumns);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
var getComponent = function getComponent(component) {
|
|
132
|
-
var _ref = isObject(component) ? component : {
|
|
133
|
-
component: component
|
|
134
|
-
};
|
|
135
|
-
_ref.component;
|
|
136
|
-
var props = _objectWithoutProperties(_ref, ["component"]);
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
name: component,
|
|
140
|
-
props: props
|
|
141
|
-
};
|
|
132
|
+
}) : [];
|
|
133
|
+
return newColumns;
|
|
142
134
|
};
|
|
143
135
|
|
|
144
136
|
var getComponentFromName = function getComponentFromName() {
|
|
@@ -249,11 +241,36 @@ var getFileName = function getFileName() {
|
|
|
249
241
|
return url.match(/([^/]+)(\?.*)?$/)[1] || url;
|
|
250
242
|
};
|
|
251
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
|
+
|
|
252
251
|
var getSelectOptions = function getSelectOptions(options) {
|
|
253
252
|
return options.map(function (it) {
|
|
254
|
-
|
|
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 {
|
|
255
272
|
value: it,
|
|
256
|
-
label: it
|
|
273
|
+
label: capitalize("".concat(it))
|
|
257
274
|
};
|
|
258
275
|
});
|
|
259
276
|
};
|
|
@@ -309,4 +326,4 @@ var validateFields = function validateFields(fields, value) {
|
|
|
309
326
|
}, true);
|
|
310
327
|
};
|
|
311
328
|
|
|
312
|
-
export { convertStyleToString, createNullableOnChange, createUseEvent,
|
|
329
|
+
export { convertStyleToString, createNullableOnChange, createUseEvent, flattenComponents, getColumnsWithFields, getComponent, getComponentFromName, getDefinitionFromId, getDisplayName, getFieldByName, getFieldFromPath, getFileName, getPathValue, getSelectOptions, isMessage, setValue as setFieldValue, slug, validateFields };
|