@panneau/core 1.0.0-y.0 → 1.0.3-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/es/contexts.js +139 -94
- package/es/hooks.js +35 -14
- package/es/index.js +43 -11
- package/es/utils.js +86 -71
- package/lib/contexts.js +338 -293
- package/lib/hooks.js +82 -61
- package/lib/index.js +193 -160
- package/lib/utils.js +107 -93
- package/package.json +24 -23
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,84 +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 _excluded = ["component"];
|
|
132
|
-
|
|
133
|
-
var getComponent = function getComponent(component) {
|
|
134
|
-
var _ref = isObject(component) ? component : {
|
|
135
|
-
component: component
|
|
136
|
-
};
|
|
137
|
-
_ref.component;
|
|
138
|
-
var props = _objectWithoutProperties(_ref, _excluded);
|
|
139
|
-
|
|
140
|
-
return {
|
|
141
|
-
name: component,
|
|
142
|
-
props: props
|
|
143
|
-
};
|
|
132
|
+
}) : [];
|
|
133
|
+
return newColumns;
|
|
144
134
|
};
|
|
145
135
|
|
|
146
136
|
var getComponentFromName = function getComponentFromName() {
|
|
@@ -251,11 +241,36 @@ var getFileName = function getFileName() {
|
|
|
251
241
|
return url.match(/([^/]+)(\?.*)?$/)[1] || url;
|
|
252
242
|
};
|
|
253
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
|
+
|
|
254
251
|
var getSelectOptions = function getSelectOptions(options) {
|
|
255
252
|
return options.map(function (it) {
|
|
256
|
-
|
|
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 {
|
|
257
272
|
value: it,
|
|
258
|
-
label: it
|
|
273
|
+
label: capitalize("".concat(it))
|
|
259
274
|
};
|
|
260
275
|
});
|
|
261
276
|
};
|
|
@@ -311,4 +326,4 @@ var validateFields = function validateFields(fields, value) {
|
|
|
311
326
|
}, true);
|
|
312
327
|
};
|
|
313
328
|
|
|
314
|
-
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 };
|