@webiny/react-properties 5.43.2-beta.0 → 6.0.0-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/Properties.d.ts CHANGED
@@ -1,17 +1,26 @@
1
1
  import React from "react";
2
+ export interface ConnectToPropertiesProps {
3
+ name: string;
4
+ children: React.ReactNode;
5
+ }
6
+ export declare const ConnectToProperties: ({ name, children }: ConnectToPropertiesProps) => React.JSX.Element;
2
7
  export interface Property {
3
8
  id: string;
4
9
  parent: string;
5
10
  name: string;
6
11
  value?: unknown;
7
12
  array?: boolean;
13
+ $isFirst?: boolean;
14
+ $isLast?: boolean;
8
15
  }
9
16
  interface AddPropertyOptions {
10
17
  after?: string;
11
18
  before?: string;
12
19
  }
13
20
  interface PropertiesContext {
21
+ name?: string;
14
22
  properties: Property[];
23
+ getAncestor(name: string): PropertiesContext | undefined;
15
24
  getObject<T = unknown>(): T;
16
25
  addProperty(property: Property, options?: AddPropertyOptions): void;
17
26
  removeProperty(id: string): void;
@@ -19,11 +28,13 @@ interface PropertiesContext {
19
28
  }
20
29
  declare const PropertiesContext: React.Context<PropertiesContext | undefined>;
21
30
  interface PropertiesProps {
31
+ name?: string;
22
32
  onChange?(properties: Property[]): void;
23
33
  children: React.ReactNode;
24
34
  }
25
- export declare const Properties: ({ onChange, children }: PropertiesProps) => React.JSX.Element;
35
+ export declare const Properties: ({ name, onChange, children }: PropertiesProps) => React.JSX.Element;
26
36
  export declare function useProperties(): PropertiesContext;
37
+ export declare function useAncestorByName(name: string | undefined): PropertiesContext | undefined;
27
38
  interface PropertyProps {
28
39
  id?: string;
29
40
  name: string;
package/Properties.js CHANGED
@@ -1,213 +1,196 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.Property = exports.Properties = void 0;
9
- exports.useAncestor = useAncestor;
10
- exports.useParentProperty = useParentProperty;
11
- exports.useProperties = useProperties;
12
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
13
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
14
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
15
- var _react = _interopRequireWildcard(require("react"));
16
- var _utils = require("./utils");
1
+ import React, { createContext, useContext, useEffect, useMemo, useState } from "react";
2
+ import { getUniqueId, toObject } from "./utils";
3
+ const PropertiesTargetContext = /*#__PURE__*/createContext(undefined);
4
+ export const ConnectToProperties = ({
5
+ name,
6
+ children
7
+ }) => {
8
+ return /*#__PURE__*/React.createElement(PropertiesTargetContext.Provider, {
9
+ value: name
10
+ }, children);
11
+ };
17
12
  function removeByParent(id, properties) {
18
- return properties.filter(function (prop) {
19
- return prop.parent === id;
20
- }).reduce(function (acc, item) {
21
- return removeByParent(item.id, acc.filter(function (prop) {
22
- return prop.id !== item.id;
23
- }));
13
+ return properties.filter(prop => prop.parent === id).reduce((acc, item) => {
14
+ return removeByParent(item.id, acc.filter(prop => prop.id !== item.id));
24
15
  }, properties);
25
16
  }
26
17
  function putPropertyBefore(properties, property, before) {
27
- var existingIndex = properties.findIndex(function (prop) {
28
- return prop.id === property.id;
29
- });
18
+ const existingIndex = properties.findIndex(prop => prop.id === property.id);
30
19
  if (existingIndex > -1) {
31
- var existingProperty = properties[existingIndex];
32
- var newProperties = properties.filter(function (p) {
33
- return p.id !== property.id;
34
- });
35
- var _targetIndex = before.endsWith("$first") ? 0 : newProperties.findIndex(function (prop) {
36
- return prop.id === before;
37
- });
38
- return [].concat((0, _toConsumableArray2.default)(newProperties.slice(0, _targetIndex)), [existingProperty], (0, _toConsumableArray2.default)(newProperties.slice(_targetIndex)));
20
+ const existingProperty = properties[existingIndex];
21
+ const newProperties = properties.filter(p => p.id !== property.id);
22
+ const targetIndex = before.endsWith("$first") ? 0 : newProperties.findIndex(prop => prop.id === before);
23
+ return [...newProperties.slice(0, targetIndex), existingProperty, ...newProperties.slice(targetIndex)];
39
24
  }
40
- var targetIndex = properties.findIndex(function (prop) {
41
- return prop.id === before;
42
- });
43
- return [].concat((0, _toConsumableArray2.default)(properties.slice(0, targetIndex)), [property], (0, _toConsumableArray2.default)(properties.slice(targetIndex)));
25
+ const targetIndex = properties.findIndex(prop => prop.id === before);
26
+ return [...properties.slice(0, targetIndex), property, ...properties.slice(targetIndex)];
44
27
  }
45
28
  function putPropertyAfter(properties, property, after) {
46
- var existingIndex = properties.findIndex(function (prop) {
47
- return prop.id === property.id;
48
- });
29
+ const existingIndex = properties.findIndex(prop => prop.id === property.id);
49
30
  if (existingIndex > -1) {
50
- var _properties$splice = properties.splice(existingIndex, 1),
51
- _properties$splice2 = (0, _slicedToArray2.default)(_properties$splice, 1),
52
- removedProperty = _properties$splice2[0];
53
- var _targetIndex2 = after.endsWith("$last") ? properties.length - 1 : properties.findIndex(function (prop) {
54
- return prop.id === after;
55
- });
56
- return [].concat((0, _toConsumableArray2.default)(properties.slice(0, _targetIndex2 + 1)), [removedProperty], (0, _toConsumableArray2.default)(properties.slice(_targetIndex2 + 1)));
31
+ const [removedProperty] = properties.splice(existingIndex, 1);
32
+ const targetIndex = after.endsWith("$last") ? properties.length - 1 : properties.findIndex(prop => prop.id === after);
33
+ return [...properties.slice(0, targetIndex + 1), removedProperty, ...properties.slice(targetIndex + 1)];
57
34
  }
58
- var targetIndex = properties.findIndex(function (prop) {
59
- return prop.id === after;
60
- });
61
- return [].concat((0, _toConsumableArray2.default)(properties.slice(0, targetIndex + 1)), [property], (0, _toConsumableArray2.default)(properties.slice(targetIndex + 1)));
35
+ const targetIndex = properties.findIndex(prop => prop.id === after);
36
+ return [...properties.slice(0, targetIndex + 1), property, ...properties.slice(targetIndex + 1)];
62
37
  }
63
38
  function mergeProperty(properties, property) {
64
- var index = properties.findIndex(function (prop) {
65
- return prop.id === property.id;
66
- });
39
+ const index = properties.findIndex(prop => prop.id === property.id);
67
40
  if (index > -1) {
68
- return [].concat((0, _toConsumableArray2.default)(properties.slice(0, index)), [(0, _objectSpread2.default)((0, _objectSpread2.default)({}, properties[index]), property)], (0, _toConsumableArray2.default)(properties.slice(index + 1)));
41
+ return [...properties.slice(0, index), {
42
+ ...properties[index],
43
+ ...property
44
+ }, ...properties.slice(index + 1)];
69
45
  }
70
46
  return properties;
71
47
  }
72
- var PropertiesContext = /*#__PURE__*/(0, _react.createContext)(undefined);
73
- var Properties = exports.Properties = function Properties(_ref) {
74
- var onChange = _ref.onChange,
75
- children = _ref.children;
76
- var _useState = (0, _react.useState)([]),
77
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
78
- properties = _useState2[0],
79
- setProperties = _useState2[1];
80
- (0, _react.useEffect)(function () {
48
+ const PropertiesContext = /*#__PURE__*/createContext(undefined);
49
+ export const Properties = ({
50
+ name,
51
+ onChange,
52
+ children
53
+ }) => {
54
+ const [properties, setProperties] = useState([]);
55
+ let parent;
56
+ try {
57
+ parent = useProperties();
58
+ } catch {
59
+ // Do nothing, if there's no parent.
60
+ }
61
+ useEffect(() => {
81
62
  if (onChange) {
82
63
  onChange(properties);
83
64
  }
84
65
  }, [properties]);
85
- var context = (0, _react.useMemo)(function () {
86
- return {
87
- properties: properties,
88
- getObject: function getObject() {
89
- return (0, _utils.toObject)(properties);
90
- },
91
- addProperty: function addProperty(property) {
92
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
93
- setProperties(function (properties) {
94
- var index = properties.findIndex(function (prop) {
95
- return prop.id === property.id;
96
- });
97
- if (index > -1) {
98
- var newProperties = mergeProperty(properties, property);
99
- if (options.after) {
100
- return putPropertyAfter(newProperties, property, options.after);
101
- }
102
- if (options.before) {
103
- return putPropertyBefore(newProperties, property, options.before);
104
- }
105
- return newProperties;
106
- }
66
+ const context = useMemo(() => ({
67
+ name,
68
+ properties,
69
+ getAncestor(ancestorName) {
70
+ if (!parent) {
71
+ return undefined;
72
+ }
73
+ return parent && parent.name === ancestorName ? parent : parent.getAncestor(ancestorName);
74
+ },
75
+ getObject() {
76
+ return toObject(properties);
77
+ },
78
+ addProperty(property, options = {}) {
79
+ setProperties(properties => {
80
+ const index = properties.findIndex(prop => prop.id === property.id);
81
+ if (index > -1) {
82
+ const newProperties = mergeProperty(properties, property);
107
83
  if (options.after) {
108
- return putPropertyAfter(properties, property, options.after);
84
+ return putPropertyAfter(newProperties, property, options.after);
109
85
  }
110
86
  if (options.before) {
111
- return putPropertyBefore(properties, property, options.before);
112
- }
113
- return [].concat((0, _toConsumableArray2.default)(properties), [property]);
114
- });
115
- },
116
- removeProperty: function removeProperty(id) {
117
- setProperties(function (properties) {
118
- return removeByParent(id, properties.filter(function (prop) {
119
- return prop.id !== id;
120
- }));
121
- });
122
- },
123
- replaceProperty: function replaceProperty(id, property) {
124
- setProperties(function (properties) {
125
- var toReplace = properties.findIndex(function (prop) {
126
- return prop.id === id;
127
- });
128
- if (toReplace > -1) {
129
- // Replace the property and remove all remaining child properties.
130
- return removeByParent(id, [].concat((0, _toConsumableArray2.default)(properties.slice(0, toReplace)), [property], (0, _toConsumableArray2.default)(properties.slice(toReplace + 1))));
87
+ return putPropertyBefore(newProperties, property, options.before);
131
88
  }
132
- return properties;
133
- });
134
- }
135
- };
136
- }, [properties]);
137
- return /*#__PURE__*/_react.default.createElement(PropertiesContext.Provider, {
89
+ return newProperties;
90
+ }
91
+ if (options.after) {
92
+ return putPropertyAfter(properties, property, options.after);
93
+ }
94
+ if (options.before) {
95
+ return putPropertyBefore(properties, property, options.before);
96
+ }
97
+ return [...properties, property];
98
+ });
99
+ },
100
+ removeProperty(id) {
101
+ setProperties(properties => {
102
+ return removeByParent(id, properties.filter(prop => prop.id !== id));
103
+ });
104
+ },
105
+ replaceProperty(id, property) {
106
+ setProperties(properties => {
107
+ const toReplace = properties.findIndex(prop => prop.id === id);
108
+ if (toReplace > -1) {
109
+ // Replace the property and remove all remaining child properties.
110
+ return removeByParent(id, [...properties.slice(0, toReplace), property, ...properties.slice(toReplace + 1)]);
111
+ }
112
+ return properties;
113
+ });
114
+ }
115
+ }), [properties]);
116
+ return /*#__PURE__*/React.createElement(PropertiesContext.Provider, {
138
117
  value: context
139
118
  }, children);
140
119
  };
141
- function useProperties() {
142
- var properties = (0, _react.useContext)(PropertiesContext);
120
+ export function useProperties() {
121
+ const properties = useContext(PropertiesContext);
143
122
  if (!properties) {
144
123
  throw Error("Properties context provider is missing!");
145
124
  }
146
125
  return properties;
147
126
  }
148
- var PropertyContext = /*#__PURE__*/(0, _react.createContext)(undefined);
149
- function useParentProperty() {
150
- return (0, _react.useContext)(PropertyContext);
127
+ export function useAncestorByName(name) {
128
+ const parent = useProperties();
129
+ return useMemo(() => {
130
+ if (!name) {
131
+ return undefined;
132
+ }
133
+ if (parent.name === name) {
134
+ return parent;
135
+ }
136
+ return parent.getAncestor(name);
137
+ }, [name]);
151
138
  }
152
- function useAncestor(params) {
153
- var property = useParentProperty();
154
- var _useProperties = useProperties(),
155
- properties = _useProperties.properties;
156
- var _matchOrGetAncestor = function matchOrGetAncestor(property, params) {
157
- var matchedProps = properties.filter(function (prop) {
158
- return prop.parent === property.id;
159
- }).filter(function (prop) {
160
- return prop.name in params && prop.value === params[prop.name];
161
- });
139
+ const PropertyContext = /*#__PURE__*/createContext(undefined);
140
+ export function useParentProperty() {
141
+ return useContext(PropertyContext);
142
+ }
143
+ export function useAncestor(params) {
144
+ const property = useParentProperty();
145
+ const {
146
+ properties
147
+ } = useProperties();
148
+ const matchOrGetAncestor = (property, params) => {
149
+ const matchedProps = properties.filter(prop => prop.parent === property.id).filter(prop => prop.name in params && prop.value === params[prop.name]);
162
150
  if (matchedProps.length === Object.keys(params).length) {
163
151
  return property;
164
152
  }
165
- var newParent = property.parent ? properties.find(function (prop) {
166
- return prop.id === property.parent;
167
- }) : undefined;
168
- return newParent ? _matchOrGetAncestor(newParent, params) : undefined;
153
+ const newParent = property.parent ? properties.find(prop => prop.id === property.parent) : undefined;
154
+ return newParent ? matchOrGetAncestor(newParent, params) : undefined;
169
155
  };
170
- return property ? _matchOrGetAncestor(property, params) : undefined;
156
+ return property ? matchOrGetAncestor(property, params) : undefined;
171
157
  }
172
- var Property = exports.Property = function Property(_ref2) {
173
- var id = _ref2.id,
174
- name = _ref2.name,
175
- value = _ref2.value,
176
- children = _ref2.children,
177
- _ref2$after = _ref2.after,
178
- after = _ref2$after === void 0 ? undefined : _ref2$after,
179
- _ref2$before = _ref2.before,
180
- before = _ref2$before === void 0 ? undefined : _ref2$before,
181
- _ref2$replace = _ref2.replace,
182
- replace = _ref2$replace === void 0 ? undefined : _ref2$replace,
183
- _ref2$remove = _ref2.remove,
184
- remove = _ref2$remove === void 0 ? false : _ref2$remove,
185
- _ref2$array = _ref2.array,
186
- array = _ref2$array === void 0 ? false : _ref2$array,
187
- _ref2$root = _ref2.root,
188
- root = _ref2$root === void 0 ? false : _ref2$root,
189
- _ref2$parent = _ref2.parent,
190
- parent = _ref2$parent === void 0 ? undefined : _ref2$parent;
191
- var uniqueId = (0, _react.useMemo)(function () {
192
- return id || (0, _utils.getUniqueId)();
193
- }, []);
194
- var parentProperty = useParentProperty();
195
- var properties = useProperties();
158
+ export const Property = ({
159
+ id,
160
+ name,
161
+ value,
162
+ children,
163
+ after = undefined,
164
+ before = undefined,
165
+ replace = undefined,
166
+ remove = false,
167
+ array = false,
168
+ root = false,
169
+ parent = undefined
170
+ }) => {
171
+ const targetName = useContext(PropertiesTargetContext);
172
+ const uniqueId = useMemo(() => id || getUniqueId(), []);
173
+ const parentProperty = useParentProperty();
174
+ const immediateProperties = useProperties();
175
+ const ancestorByName = useAncestorByName(targetName);
176
+ const properties = targetName ? ancestorByName : immediateProperties;
196
177
  if (!properties) {
197
178
  throw Error("<Properties> provider is missing higher in the hierarchy!");
198
179
  }
199
- var addProperty = properties.addProperty,
200
- removeProperty = properties.removeProperty,
201
- replaceProperty = properties.replaceProperty;
202
- var parentId = parent ? parent : root ? "" : parentProperty?.id || "";
203
- var property = {
180
+ const {
181
+ addProperty,
182
+ removeProperty,
183
+ replaceProperty
184
+ } = properties;
185
+ const parentId = parent ? parent : root ? "" : parentProperty?.id || "";
186
+ const property = {
204
187
  id: uniqueId,
205
- name: name,
206
- value: value,
188
+ name,
189
+ value,
207
190
  parent: parentId,
208
- array: array
191
+ array
209
192
  };
210
- (0, _react.useEffect)(function () {
193
+ useEffect(() => {
211
194
  if (remove) {
212
195
  removeProperty(uniqueId);
213
196
  return;
@@ -216,16 +199,22 @@ var Property = exports.Property = function Property(_ref2) {
216
199
  replaceProperty(replace, property);
217
200
  return;
218
201
  }
219
- addProperty(property, {
220
- after: after,
221
- before: before
202
+ const $isFirst = before === "$first";
203
+ const $isLast = after === "$last";
204
+ addProperty({
205
+ ...property,
206
+ $isFirst,
207
+ $isLast
208
+ }, {
209
+ after,
210
+ before
222
211
  });
223
- return function () {
212
+ return () => {
224
213
  removeProperty(uniqueId);
225
214
  };
226
215
  }, []);
227
216
  if (children) {
228
- return /*#__PURE__*/_react.default.createElement(PropertyContext.Provider, {
217
+ return /*#__PURE__*/React.createElement(PropertyContext.Provider, {
229
218
  value: property
230
219
  }, children);
231
220
  }
package/Properties.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_utils","removeByParent","id","properties","filter","prop","parent","reduce","acc","item","putPropertyBefore","property","before","existingIndex","findIndex","existingProperty","newProperties","p","targetIndex","endsWith","concat","_toConsumableArray2","default","slice","putPropertyAfter","after","_properties$splice","splice","_properties$splice2","_slicedToArray2","removedProperty","length","mergeProperty","index","_objectSpread2","PropertiesContext","createContext","undefined","Properties","exports","_ref","onChange","children","_useState","useState","_useState2","setProperties","useEffect","context","useMemo","getObject","toObject","addProperty","options","arguments","removeProperty","replaceProperty","toReplace","createElement","Provider","value","useProperties","useContext","Error","PropertyContext","useParentProperty","useAncestor","params","_useProperties","matchOrGetAncestor","matchedProps","name","Object","keys","newParent","find","Property","_ref2","_ref2$after","_ref2$before","_ref2$replace","replace","_ref2$remove","remove","_ref2$array","array","_ref2$root","root","_ref2$parent","uniqueId","getUniqueId","parentProperty","parentId"],"sources":["Properties.tsx"],"sourcesContent":["import React, { createContext, useContext, useEffect, useMemo, useState } from \"react\";\nimport { getUniqueId, toObject } from \"./utils\";\n\nexport interface Property {\n id: string;\n parent: string;\n name: string;\n value?: unknown;\n array?: boolean;\n}\n\nfunction removeByParent(id: string, properties: Property[]): Property[] {\n return properties\n .filter(prop => prop.parent === id)\n .reduce((acc, item) => {\n return removeByParent(\n item.id,\n acc.filter(prop => prop.id !== item.id)\n );\n }, properties);\n}\n\ninterface AddPropertyOptions {\n after?: string;\n before?: string;\n}\n\ninterface PropertiesContext {\n properties: Property[];\n getObject<T = unknown>(): T;\n addProperty(property: Property, options?: AddPropertyOptions): void;\n removeProperty(id: string): void;\n replaceProperty(id: string, property: Property): void;\n}\n\nfunction putPropertyBefore(properties: Property[], property: Property, before: string) {\n const existingIndex = properties.findIndex(prop => prop.id === property.id);\n if (existingIndex > -1) {\n const existingProperty = properties[existingIndex];\n const newProperties = properties.filter(p => p.id !== property.id);\n const targetIndex = before.endsWith(\"$first\")\n ? 0\n : newProperties.findIndex(prop => prop.id === before);\n return [\n ...newProperties.slice(0, targetIndex),\n existingProperty,\n ...newProperties.slice(targetIndex)\n ];\n }\n\n const targetIndex = properties.findIndex(prop => prop.id === before);\n\n return [...properties.slice(0, targetIndex), property, ...properties.slice(targetIndex)];\n}\n\nfunction putPropertyAfter(properties: Property[], property: Property, after: string) {\n const existingIndex = properties.findIndex(prop => prop.id === property.id);\n\n if (existingIndex > -1) {\n const [removedProperty] = properties.splice(existingIndex, 1);\n const targetIndex = after.endsWith(\"$last\")\n ? properties.length - 1\n : properties.findIndex(prop => prop.id === after);\n return [\n ...properties.slice(0, targetIndex + 1),\n removedProperty,\n ...properties.slice(targetIndex + 1)\n ];\n }\n\n const targetIndex = properties.findIndex(prop => prop.id === after);\n\n return [\n ...properties.slice(0, targetIndex + 1),\n property,\n ...properties.slice(targetIndex + 1)\n ];\n}\n\nfunction mergeProperty(properties: Property[], property: Property) {\n const index = properties.findIndex(prop => prop.id === property.id);\n if (index > -1) {\n return [\n ...properties.slice(0, index),\n { ...properties[index], ...property },\n ...properties.slice(index + 1)\n ];\n }\n return properties;\n}\n\nconst PropertiesContext = createContext<PropertiesContext | undefined>(undefined);\n\ninterface PropertiesProps {\n onChange?(properties: Property[]): void;\n children: React.ReactNode;\n}\n\nexport const Properties = ({ onChange, children }: PropertiesProps) => {\n const [properties, setProperties] = useState<Property[]>([]);\n\n useEffect(() => {\n if (onChange) {\n onChange(properties);\n }\n }, [properties]);\n\n const context: PropertiesContext = useMemo(\n () => ({\n properties,\n getObject<T>() {\n return toObject(properties) as T;\n },\n addProperty(property, options = {}) {\n setProperties(properties => {\n const index = properties.findIndex(prop => prop.id === property.id);\n\n if (index > -1) {\n const newProperties = mergeProperty(properties, property);\n if (options.after) {\n return putPropertyAfter(newProperties, property, options.after);\n }\n if (options.before) {\n return putPropertyBefore(newProperties, property, options.before);\n }\n\n return newProperties;\n }\n\n if (options.after) {\n return putPropertyAfter(properties, property, options.after);\n }\n\n if (options.before) {\n return putPropertyBefore(properties, property, options.before);\n }\n\n return [...properties, property];\n });\n },\n removeProperty(id) {\n setProperties(properties => {\n return removeByParent(\n id,\n properties.filter(prop => prop.id !== id)\n );\n });\n },\n replaceProperty(id, property) {\n setProperties(properties => {\n const toReplace = properties.findIndex(prop => prop.id === id);\n\n if (toReplace > -1) {\n // Replace the property and remove all remaining child properties.\n return removeByParent(id, [\n ...properties.slice(0, toReplace),\n property,\n ...properties.slice(toReplace + 1)\n ]);\n }\n return properties;\n });\n }\n }),\n [properties]\n );\n\n return <PropertiesContext.Provider value={context}>{children}</PropertiesContext.Provider>;\n};\n\nexport function useProperties() {\n const properties = useContext(PropertiesContext);\n if (!properties) {\n throw Error(\"Properties context provider is missing!\");\n }\n\n return properties;\n}\n\ninterface PropertyProps {\n id?: string;\n name: string;\n value?: unknown;\n array?: boolean;\n after?: string;\n before?: string;\n replace?: string;\n remove?: boolean;\n parent?: string;\n root?: boolean;\n children?: React.ReactNode;\n}\n\nconst PropertyContext = createContext<Property | undefined>(undefined);\n\nexport function useParentProperty() {\n return useContext(PropertyContext);\n}\n\ninterface AncestorMatch {\n [key: string]: string | boolean | number | null | undefined;\n}\n\nexport function useAncestor(params: AncestorMatch) {\n const property = useParentProperty();\n const { properties } = useProperties();\n\n const matchOrGetAncestor = (\n property: Property,\n params: AncestorMatch\n ): Property | undefined => {\n const matchedProps = properties\n .filter(prop => prop.parent === property.id)\n .filter(prop => prop.name in params && prop.value === params[prop.name]);\n\n if (matchedProps.length === Object.keys(params).length) {\n return property;\n }\n\n const newParent = property.parent\n ? properties.find(prop => prop.id === property.parent)\n : undefined;\n\n return newParent ? matchOrGetAncestor(newParent, params) : undefined;\n };\n\n return property ? matchOrGetAncestor(property, params) : undefined;\n}\n\nexport const Property = ({\n id,\n name,\n value,\n children,\n after = undefined,\n before = undefined,\n replace = undefined,\n remove = false,\n array = false,\n root = false,\n parent = undefined\n}: PropertyProps) => {\n const uniqueId = useMemo(() => id || getUniqueId(), []);\n const parentProperty = useParentProperty();\n const properties = useProperties();\n\n if (!properties) {\n throw Error(\"<Properties> provider is missing higher in the hierarchy!\");\n }\n\n const { addProperty, removeProperty, replaceProperty } = properties;\n const parentId = parent ? parent : root ? \"\" : parentProperty?.id || \"\";\n const property = { id: uniqueId, name, value, parent: parentId, array };\n\n useEffect(() => {\n if (remove) {\n removeProperty(uniqueId);\n return;\n }\n\n if (replace) {\n replaceProperty(replace, property);\n return;\n }\n\n addProperty(property, { after, before });\n\n return () => {\n removeProperty(uniqueId);\n };\n }, []);\n\n if (children) {\n return <PropertyContext.Provider value={property}>{children}</PropertyContext.Provider>;\n }\n\n return null;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CA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ect","useMemo","useState","getUniqueId","toObject","PropertiesTargetContext","undefined","ConnectToProperties","name","children","createElement","Provider","value","removeByParent","id","properties","filter","prop","parent","reduce","acc","item","putPropertyBefore","property","before","existingIndex","findIndex","existingProperty","newProperties","p","targetIndex","endsWith","slice","putPropertyAfter","after","removedProperty","splice","length","mergeProperty","index","PropertiesContext","Properties","onChange","setProperties","useProperties","context","getAncestor","ancestorName","getObject","addProperty","options","removeProperty","replaceProperty","toReplace","Error","useAncestorByName","PropertyContext","useParentProperty","useAncestor","params","matchOrGetAncestor","matchedProps","Object","keys","newParent","find","Property","replace","remove","array","root","targetName","uniqueId","parentProperty","immediateProperties","ancestorByName","parentId","$isFirst","$isLast"],"sources":["Properties.tsx"],"sourcesContent":["import React, { createContext, useContext, useEffect, useMemo, useState } from \"react\";\nimport { getUniqueId, toObject } from \"./utils\";\n\nconst PropertiesTargetContext = createContext<string | undefined>(undefined);\n\nexport interface ConnectToPropertiesProps {\n name: string;\n children: React.ReactNode;\n}\n\nexport const ConnectToProperties = ({ name, children }: ConnectToPropertiesProps) => {\n return (\n <PropertiesTargetContext.Provider value={name}>{children}</PropertiesTargetContext.Provider>\n );\n};\n\nexport interface Property {\n id: string;\n parent: string;\n name: string;\n value?: unknown;\n array?: boolean;\n $isFirst?: boolean;\n $isLast?: boolean;\n}\n\nfunction removeByParent(id: string, properties: Property[]): Property[] {\n return properties\n .filter(prop => prop.parent === id)\n .reduce((acc, item) => {\n return removeByParent(\n item.id,\n acc.filter(prop => prop.id !== item.id)\n );\n }, properties);\n}\n\ninterface AddPropertyOptions {\n after?: string;\n before?: string;\n}\n\ninterface PropertiesContext {\n name?: string;\n properties: Property[];\n getAncestor(name: string): PropertiesContext | undefined;\n getObject<T = unknown>(): T;\n addProperty(property: Property, options?: AddPropertyOptions): void;\n removeProperty(id: string): void;\n replaceProperty(id: string, property: Property): void;\n}\n\nfunction putPropertyBefore(properties: Property[], property: Property, before: string) {\n const existingIndex = properties.findIndex(prop => prop.id === property.id);\n if (existingIndex > -1) {\n const existingProperty = properties[existingIndex];\n const newProperties = properties.filter(p => p.id !== property.id);\n const targetIndex = before.endsWith(\"$first\")\n ? 0\n : newProperties.findIndex(prop => prop.id === before);\n return [\n ...newProperties.slice(0, targetIndex),\n existingProperty,\n ...newProperties.slice(targetIndex)\n ];\n }\n\n const targetIndex = properties.findIndex(prop => prop.id === before);\n\n return [...properties.slice(0, targetIndex), property, ...properties.slice(targetIndex)];\n}\n\nfunction putPropertyAfter(properties: Property[], property: Property, after: string) {\n const existingIndex = properties.findIndex(prop => prop.id === property.id);\n\n if (existingIndex > -1) {\n const [removedProperty] = properties.splice(existingIndex, 1);\n const targetIndex = after.endsWith(\"$last\")\n ? properties.length - 1\n : properties.findIndex(prop => prop.id === after);\n return [\n ...properties.slice(0, targetIndex + 1),\n removedProperty,\n ...properties.slice(targetIndex + 1)\n ];\n }\n\n const targetIndex = properties.findIndex(prop => prop.id === after);\n\n return [\n ...properties.slice(0, targetIndex + 1),\n property,\n ...properties.slice(targetIndex + 1)\n ];\n}\n\nfunction mergeProperty(properties: Property[], property: Property) {\n const index = properties.findIndex(prop => prop.id === property.id);\n if (index > -1) {\n return [\n ...properties.slice(0, index),\n { ...properties[index], ...property },\n ...properties.slice(index + 1)\n ];\n }\n return properties;\n}\n\nconst PropertiesContext = createContext<PropertiesContext | undefined>(undefined);\n\ninterface PropertiesProps {\n name?: string;\n onChange?(properties: Property[]): void;\n children: React.ReactNode;\n}\n\nexport const Properties = ({ name, onChange, children }: PropertiesProps) => {\n const [properties, setProperties] = useState<Property[]>([]);\n let parent: PropertiesContext;\n\n try {\n parent = useProperties();\n } catch {\n // Do nothing, if there's no parent.\n }\n\n useEffect(() => {\n if (onChange) {\n onChange(properties);\n }\n }, [properties]);\n\n const context: PropertiesContext = useMemo(\n () => ({\n name,\n properties,\n getAncestor(ancestorName: string) {\n if (!parent) {\n return undefined;\n }\n\n return parent && parent.name === ancestorName\n ? parent\n : parent.getAncestor(ancestorName);\n },\n getObject<T>() {\n return toObject(properties) as T;\n },\n addProperty(property, options = {}) {\n setProperties(properties => {\n const index = properties.findIndex(prop => prop.id === property.id);\n\n if (index > -1) {\n const newProperties = mergeProperty(properties, property);\n if (options.after) {\n return putPropertyAfter(newProperties, property, options.after);\n }\n if (options.before) {\n return putPropertyBefore(newProperties, property, options.before);\n }\n\n return newProperties;\n }\n\n if (options.after) {\n return putPropertyAfter(properties, property, options.after);\n }\n\n if (options.before) {\n return putPropertyBefore(properties, property, options.before);\n }\n\n return [...properties, property];\n });\n },\n removeProperty(id) {\n setProperties(properties => {\n return removeByParent(\n id,\n properties.filter(prop => prop.id !== id)\n );\n });\n },\n replaceProperty(id, property) {\n setProperties(properties => {\n const toReplace = properties.findIndex(prop => prop.id === id);\n\n if (toReplace > -1) {\n // Replace the property and remove all remaining child properties.\n return removeByParent(id, [\n ...properties.slice(0, toReplace),\n property,\n ...properties.slice(toReplace + 1)\n ]);\n }\n return properties;\n });\n }\n }),\n [properties]\n );\n\n return <PropertiesContext.Provider value={context}>{children}</PropertiesContext.Provider>;\n};\n\nexport function useProperties() {\n const properties = useContext(PropertiesContext);\n if (!properties) {\n throw Error(\"Properties context provider is missing!\");\n }\n\n return properties;\n}\n\nexport function useAncestorByName(name: string | undefined) {\n const parent = useProperties();\n\n return useMemo(() => {\n if (!name) {\n return undefined;\n }\n\n if (parent.name === name) {\n return parent;\n }\n\n return parent.getAncestor(name);\n }, [name]);\n}\n\ninterface PropertyProps {\n id?: string;\n name: string;\n value?: unknown;\n array?: boolean;\n after?: string;\n before?: string;\n replace?: string;\n remove?: boolean;\n parent?: string;\n root?: boolean;\n children?: React.ReactNode;\n}\n\nconst PropertyContext = createContext<Property | undefined>(undefined);\n\nexport function useParentProperty() {\n return useContext(PropertyContext);\n}\n\ninterface AncestorMatch {\n [key: string]: string | boolean | number | null | undefined;\n}\n\nexport function useAncestor(params: AncestorMatch) {\n const property = useParentProperty();\n const { properties } = useProperties();\n\n const matchOrGetAncestor = (\n property: Property,\n params: AncestorMatch\n ): Property | undefined => {\n const matchedProps = properties\n .filter(prop => prop.parent === property.id)\n .filter(prop => prop.name in params && prop.value === params[prop.name]);\n\n if (matchedProps.length === Object.keys(params).length) {\n return property;\n }\n\n const newParent = property.parent\n ? properties.find(prop => prop.id === property.parent)\n : undefined;\n\n return newParent ? matchOrGetAncestor(newParent, params) : undefined;\n };\n\n return property ? matchOrGetAncestor(property, params) : undefined;\n}\n\nexport const Property = ({\n id,\n name,\n value,\n children,\n after = undefined,\n before = undefined,\n replace = undefined,\n remove = false,\n array = false,\n root = false,\n parent = undefined\n}: PropertyProps) => {\n const targetName = useContext(PropertiesTargetContext);\n const uniqueId = useMemo(() => id || getUniqueId(), []);\n const parentProperty = useParentProperty();\n const immediateProperties = useProperties();\n const ancestorByName = useAncestorByName(targetName);\n\n const properties = targetName ? ancestorByName : immediateProperties;\n\n if (!properties) {\n throw Error(\"<Properties> provider is missing higher in the hierarchy!\");\n }\n\n const { addProperty, removeProperty, replaceProperty } = properties;\n const parentId = parent ? parent : root ? \"\" : parentProperty?.id || \"\";\n const property = { id: uniqueId, name, value, parent: parentId, array };\n\n useEffect(() => {\n if (remove) {\n removeProperty(uniqueId);\n return;\n }\n\n if (replace) {\n replaceProperty(replace, property);\n return;\n }\n\n const $isFirst = before === \"$first\";\n const $isLast = after === \"$last\";\n\n addProperty({ ...property, $isFirst, $isLast }, { after, before });\n\n return () => {\n removeProperty(uniqueId);\n };\n }, []);\n\n if (children) {\n return <PropertyContext.Provider value={property}>{children}</PropertyContext.Provider>;\n }\n\n return null;\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACtF,SAASC,WAAW,EAAEC,QAAQ;AAE9B,MAAMC,uBAAuB,gBAAGP,aAAa,CAAqBQ,SAAS,CAAC;AAO5E,OAAO,MAAMC,mBAAmB,GAAGA,CAAC;EAAEC,IAAI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E,GAAG1B,QAAQ;MAAEsD,QAAQ;MAAEC;IAAQ,CAAC,EAAE;MAAE5C,KAAK;MAAEV;IAAO,CAAC,CAAC;IAElE,OAAO,MAAM;MACT2B,cAAc,CAACqB,QAAQ,CAAC;IAC5B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,IAAI/D,QAAQ,EAAE;IACV,oBAAOZ,KAAA,CAAAa,aAAA,CAAC8C,eAAe,CAAC7C,QAAQ;MAACC,KAAK,EAAEW;IAAS,GAAEd,QAAmC,CAAC;EAC3F;EAEA,OAAO,IAAI;AACf,CAAC","ignoreList":[]}
@@ -1,95 +1,84 @@
1
- "use strict";
2
-
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createConfigurableComponent = createConfigurableComponent;
9
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
- var _react = _interopRequireWildcard(require("react"));
11
- var _reactComposition = require("@webiny/react-composition");
12
- var _index = require("./index");
13
- var _useDebugConfig = require("./useDebugConfig");
14
- var createHOC = function createHOC(newChildren) {
15
- return function (BaseComponent) {
16
- return function ConfigHOC(_ref) {
17
- var children = _ref.children;
18
- return /*#__PURE__*/_react.default.createElement(BaseComponent, null, newChildren, children);
19
- };
1
+ import React, { useContext, useEffect, useMemo, useState } from "react";
2
+ import { Compose, makeDecoratable } from "@webiny/react-composition";
3
+ import { Properties, toObject } from "./index";
4
+ import { useDebugConfig } from "./useDebugConfig";
5
+ const createHOC = newChildren => BaseComponent => {
6
+ return function ConfigHOC({
7
+ children
8
+ }) {
9
+ return /*#__PURE__*/React.createElement(BaseComponent, null, newChildren, children);
20
10
  };
21
11
  };
22
- function createConfigurableComponent(name) {
12
+ export function createConfigurableComponent(name) {
23
13
  /**
24
14
  * This component is used when we want to mount all composed configs.
25
15
  */
26
- var ConfigApplyPrimary = (0, _reactComposition.makeDecoratable)("".concat(name, "ConfigApply<Primary>"), function (_ref2) {
27
- var children = _ref2.children;
28
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
16
+ const ConfigApplyPrimary = makeDecoratable(`${name}ConfigApply<Primary>`, ({
17
+ children
18
+ }) => {
19
+ return /*#__PURE__*/React.createElement(React.Fragment, null, children);
29
20
  });
30
- var ConfigApplySecondary = (0, _reactComposition.makeDecoratable)("".concat(name, "ConfigApply<Secondary>"), function (_ref3) {
31
- var children = _ref3.children;
32
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
21
+ const ConfigApplySecondary = makeDecoratable(`${name}ConfigApply<Secondary>`, ({
22
+ children
23
+ }) => {
24
+ return /*#__PURE__*/React.createElement(React.Fragment, null, children);
33
25
  });
34
26
 
35
27
  /**
36
28
  * This component is used to configure the component (it can be mounted many times).
37
29
  */
38
- var Config = function Config(_ref4) {
39
- var _ref4$priority = _ref4.priority,
40
- priority = _ref4$priority === void 0 ? "primary" : _ref4$priority,
41
- children = _ref4.children;
30
+ const Config = ({
31
+ priority = "primary",
32
+ children
33
+ }) => {
42
34
  if (priority === "primary") {
43
- return /*#__PURE__*/_react.default.createElement(_reactComposition.Compose, {
35
+ return /*#__PURE__*/React.createElement(Compose, {
44
36
  component: ConfigApplyPrimary,
45
37
  with: createHOC(children)
46
38
  });
47
39
  }
48
- return /*#__PURE__*/_react.default.createElement(_reactComposition.Compose, {
40
+ return /*#__PURE__*/React.createElement(Compose, {
49
41
  component: ConfigApplySecondary,
50
42
  with: createHOC(children)
51
43
  });
52
44
  };
53
- var defaultContext = {
45
+ const defaultContext = {
54
46
  properties: []
55
47
  };
56
- var ViewContext = /*#__PURE__*/_react.default.createContext(defaultContext);
57
- var WithConfig = function WithConfig(_ref5) {
58
- var onProperties = _ref5.onProperties,
59
- children = _ref5.children;
60
- var _useState = (0, _react.useState)([]),
61
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
62
- properties = _useState2[0],
63
- setProperties = _useState2[1];
64
- (0, _useDebugConfig.useDebugConfig)(name, properties);
65
- var context = {
66
- properties: properties
48
+ const ViewContext = /*#__PURE__*/React.createContext(defaultContext);
49
+ const WithConfig = ({
50
+ onProperties,
51
+ children
52
+ }) => {
53
+ const [properties, setProperties] = useState([]);
54
+ useDebugConfig(name, properties);
55
+ const context = {
56
+ properties
67
57
  };
68
- (0, _react.useEffect)(function () {
58
+ useEffect(() => {
69
59
  if (typeof onProperties === "function") {
70
60
  onProperties(properties);
71
61
  }
72
62
  }, [properties]);
73
- var stateUpdater = function stateUpdater(properties) {
63
+ const stateUpdater = properties => {
74
64
  setProperties(properties);
75
65
  };
76
- return /*#__PURE__*/_react.default.createElement(ViewContext.Provider, {
66
+ return /*#__PURE__*/React.createElement(ViewContext.Provider, {
77
67
  value: context
78
- }, /*#__PURE__*/_react.default.createElement(_index.Properties, {
68
+ }, /*#__PURE__*/React.createElement(Properties, {
79
69
  onChange: stateUpdater
80
- }, /*#__PURE__*/_react.default.createElement(ConfigApplyPrimary, null), /*#__PURE__*/_react.default.createElement(ConfigApplySecondary, null), children));
70
+ }, /*#__PURE__*/React.createElement(ConfigApplyPrimary, null), /*#__PURE__*/React.createElement(ConfigApplySecondary, null), children));
81
71
  };
82
72
  function useConfig() {
83
- var _useContext = (0, _react.useContext)(ViewContext),
84
- properties = _useContext.properties;
85
- return (0, _react.useMemo)(function () {
86
- return (0, _index.toObject)(properties);
87
- }, [properties]);
73
+ const {
74
+ properties
75
+ } = useContext(ViewContext);
76
+ return useMemo(() => toObject(properties), [properties]);
88
77
  }
89
78
  return {
90
- WithConfig: WithConfig,
91
- Config: Config,
92
- useConfig: useConfig
79
+ WithConfig,
80
+ Config,
81
+ useConfig
93
82
  };
94
83
  }
95
84
 
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_reactComposition","_index","_useDebugConfig","createHOC","newChildren","BaseComponent","ConfigHOC","_ref","children","default","createElement","createConfigurableComponent","name","ConfigApplyPrimary","makeDecoratable","concat","_ref2","Fragment","ConfigApplySecondary","_ref3","Config","_ref4","_ref4$priority","priority","Compose","component","with","defaultContext","properties","ViewContext","React","createContext","WithConfig","_ref5","onProperties","_useState","useState","_useState2","_slicedToArray2","setProperties","useDebugConfig","context","useEffect","stateUpdater","Provider","value","Properties","onChange","useConfig","_useContext","useContext","useMemo","toObject"],"sources":["createConfigurableComponent.tsx"],"sourcesContent":["import React, { useContext, useEffect, useMemo, useState } from \"react\";\nimport { Compose, Decorator, makeDecoratable } from \"@webiny/react-composition\";\nimport { GenericComponent } from \"@webiny/react-composition/types\";\nimport { Property, Properties, toObject } from \"~/index\";\nimport { useDebugConfig } from \"./useDebugConfig\";\n\nconst createHOC =\n (newChildren: React.ReactNode): Decorator<GenericComponent<{ children?: React.ReactNode }>> =>\n BaseComponent => {\n return function ConfigHOC({ children }) {\n return (\n <BaseComponent>\n {newChildren}\n {children}\n </BaseComponent>\n );\n };\n };\n\nexport interface WithConfigProps {\n children: React.ReactNode;\n onProperties?(properties: Property[]): void;\n}\n\ninterface ConfigApplyProps {\n children?: React.ReactNode;\n}\n\nexport interface ConfigProps {\n children: React.ReactNode;\n priority?: \"primary\" | \"secondary\";\n}\n\nexport function createConfigurableComponent<TConfig>(name: string) {\n /**\n * This component is used when we want to mount all composed configs.\n */\n const ConfigApplyPrimary = makeDecoratable(\n `${name}ConfigApply<Primary>`,\n ({ children }: ConfigApplyProps) => {\n return <>{children}</>;\n }\n );\n\n const ConfigApplySecondary = makeDecoratable(\n `${name}ConfigApply<Secondary>`,\n ({ children }: ConfigApplyProps) => {\n return <>{children}</>;\n }\n );\n\n /**\n * This component is used to configure the component (it can be mounted many times).\n */\n const Config = ({ priority = \"primary\", children }: ConfigProps) => {\n if (priority === \"primary\") {\n return <Compose component={ConfigApplyPrimary} with={createHOC(children)} />;\n }\n return <Compose component={ConfigApplySecondary} with={createHOC(children)} />;\n };\n\n interface ViewContext {\n properties: Property[];\n }\n\n const defaultContext = { properties: [] };\n\n const ViewContext = React.createContext<ViewContext>(defaultContext);\n\n const WithConfig = ({ onProperties, children }: WithConfigProps) => {\n const [properties, setProperties] = useState<Property[]>([]);\n useDebugConfig(name, properties);\n const context = { properties };\n\n useEffect(() => {\n if (typeof onProperties === \"function\") {\n onProperties(properties);\n }\n }, [properties]);\n\n const stateUpdater = (properties: Property[]) => {\n setProperties(properties);\n };\n\n return (\n <ViewContext.Provider value={context}>\n <Properties onChange={stateUpdater}>\n <ConfigApplyPrimary />\n <ConfigApplySecondary />\n {children}\n </Properties>\n </ViewContext.Provider>\n );\n };\n\n function useConfig<TExtra extends object>(): TConfig & TExtra {\n const { properties } = useContext(ViewContext);\n return useMemo(() => toObject<TConfig & TExtra>(properties), [properties]);\n }\n\n return {\n WithConfig,\n Config,\n useConfig\n };\n}\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AAEA,IAAMI,SAAS,GACX,SADEA,SAASA,CACVC,WAA4B;EAAA,OAC7B,UAAAC,aAAa,EAAI;IACb,OAAO,SAASC,SAASA,CAAAC,IAAA,EAAe;MAAA,IAAZC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;MAChC,oBACIX,MAAA,CAAAY,OAAA,CAAAC,aAAA,CAACL,aAAa,QACTD,WAAW,EACXI,QACU,CAAC;IAExB,CAAC;EACL,CAAC;AAAA;AAgBE,SAASG,2BAA2BA,CAAUC,IAAY,EAAE;EAC/D;AACJ;AACA;EACI,IAAMC,kBAAkB,GAAG,IAAAC,iCAAe,KAAAC,MAAA,CACnCH,IAAI,2BACP,UAAAI,KAAA,EAAoC;IAAA,IAAjCR,QAAQ,GAAAQ,KAAA,CAARR,QAAQ;IACP,oBAAOX,MAAA,CAAAY,OAAA,CAAAC,aAAA,CAAAb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AS,EAATA;EACJ,CAAC;AACL","ignoreList":[]}
1
+ {"version":3,"names":["React","useContext","useEffect","useMemo","useState","Compose","makeDecoratable","Properties","toObject","useDebugConfig","createHOC","newChildren","BaseComponent","ConfigHOC","children","createElement","createConfigurableComponent","name","ConfigApplyPrimary","Fragment","ConfigApplySecondary","Config","priority","component","with","defaultContext","properties","ViewContext","createContext","WithConfig","onProperties","setProperties","context","stateUpdater","Provider","value","onChange","useConfig"],"sources":["createConfigurableComponent.tsx"],"sourcesContent":["import React, { useContext, useEffect, useMemo, useState } from \"react\";\nimport { Compose, Decorator, makeDecoratable } from \"@webiny/react-composition\";\nimport { GenericComponent } from \"@webiny/react-composition/types\";\nimport { Property, Properties, toObject } from \"~/index\";\nimport { useDebugConfig } from \"./useDebugConfig\";\n\nconst createHOC =\n (newChildren: React.ReactNode): Decorator<GenericComponent<{ children?: React.ReactNode }>> =>\n BaseComponent => {\n return function ConfigHOC({ children }) {\n return (\n <BaseComponent>\n {newChildren}\n {children}\n </BaseComponent>\n );\n };\n };\n\nexport interface WithConfigProps {\n children: React.ReactNode;\n onProperties?(properties: Property[]): void;\n}\n\ninterface ConfigApplyProps {\n children?: React.ReactNode;\n}\n\nexport interface ConfigProps {\n children: React.ReactNode;\n priority?: \"primary\" | \"secondary\";\n}\n\nexport function createConfigurableComponent<TConfig>(name: string) {\n /**\n * This component is used when we want to mount all composed configs.\n */\n const ConfigApplyPrimary = makeDecoratable(\n `${name}ConfigApply<Primary>`,\n ({ children }: ConfigApplyProps) => {\n return <>{children}</>;\n }\n );\n\n const ConfigApplySecondary = makeDecoratable(\n `${name}ConfigApply<Secondary>`,\n ({ children }: ConfigApplyProps) => {\n return <>{children}</>;\n }\n );\n\n /**\n * This component is used to configure the component (it can be mounted many times).\n */\n const Config = ({ priority = \"primary\", children }: ConfigProps) => {\n if (priority === \"primary\") {\n return <Compose component={ConfigApplyPrimary} with={createHOC(children)} />;\n }\n return <Compose component={ConfigApplySecondary} with={createHOC(children)} />;\n };\n\n interface ViewContext {\n properties: Property[];\n }\n\n const defaultContext = { properties: [] };\n\n const ViewContext = React.createContext<ViewContext>(defaultContext);\n\n const WithConfig = ({ onProperties, children }: WithConfigProps) => {\n const [properties, setProperties] = useState<Property[]>([]);\n useDebugConfig(name, properties);\n const context = { properties };\n\n useEffect(() => {\n if (typeof onProperties === \"function\") {\n onProperties(properties);\n }\n }, [properties]);\n\n const stateUpdater = (properties: Property[]) => {\n setProperties(properties);\n };\n\n return (\n <ViewContext.Provider value={context}>\n <Properties onChange={stateUpdater}>\n <ConfigApplyPrimary />\n <ConfigApplySecondary />\n {children}\n </Properties>\n </ViewContext.Provider>\n );\n };\n\n function useConfig<TExtra extends object>(): TConfig & TExtra {\n const { properties } = useContext(ViewContext);\n return useMemo(() => toObject<TConfig & TExtra>(properties), [properties]);\n }\n\n return {\n WithConfig,\n Config,\n useConfig\n };\n}\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACvE,SAASC,OAAO,EAAaC,eAAe,QAAQ,2BAA2B;AAE/E,SAAmBC,UAAU,EAAEC,QAAQ;AACvC,SAASC,cAAc;AAEvB,MAAMC,SAAS,GACVC,WAA4B,IAC7BC,aAAa,IAAI;EACb,OAAO,SAASC,SAASA,CAAC;IAAEC;EAAS,CAAC,EAAE;IACpC,oBACId,KAAA,CAAAe,aAAA,CAACH,aAAa,QACTD,WAAW,EACXG,QACU,CAAC;EAExB,CAAC;AACL,CAAC;AAgBL,OAAO,SAASE,2BAA2BA,CAAUC,IAAY,EAAE;EAC/D;AACJ;AACA;EACI,MAAMC,kBAAkB,GAAGZ,eAAe,CACtC,GAAGW,IAAI,sBAAsB,EAC7B,CAAC;IAAEH;EAA2B,CAAC,KAAK;IAChC,oBAAOd,KAAA,CAAAe,aAAA,CAAAf,KAAA,CAAAmB,QAAA,QAAGL,QAAW,CAAC;EAC1B,CACJ,CAAC;EAED,MAAMM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KAAA,CAAAe,aAAA,CAACY,WAAW,CAACO,QAAQ;MAACC,KAAK,EAAEH;IAAQ,gBACjChC,KAAA,CAAAe,aAAA,CAACR,UAAU;MAAC6B,QAAQ,EAAEH;IAAa,gBAC/BjC,KAAA,CAAAe,aAAA,CAACG,kBAAkB,MAAE,CAAC,eACtBlB,KAAA,CAAAe,aAAA,CAACK,oBAAoB,MAAE,CAAC,EACvBN,QACO,CACM,CAAC;EAE/B,CAAC;EAED,SAASuB,SAASA,CAAA,EAA4C;IAC1D,MAAM;MAAEX;IAAW,CAAC,GAAGzB,UAAU,CAAC0B,WAAW,CAAC;IAC9C,OAAOxB,OAAO,CAAC,MAAMK,QAAQ,CAAmBkB,UAAU,CAAC,EAAE,CAACA,UAAU,CAAC,CAAC;EAC9E;EAEA,OAAO;IACHG,UAAU;IACVR,MAAM;IACNgB;EACJ,CAAC;AACL","ignoreList":[]}
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./utils";
2
2
  export * from "./Properties";
3
+ export * from "./useDebugConfig";
3
4
  export * from "./useIdGenerator";
4
5
  export * from "./createConfigurableComponent";
package/index.js CHANGED
@@ -1,51 +1,7 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _utils = require("./utils");
7
- Object.keys(_utils).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _utils[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function get() {
13
- return _utils[key];
14
- }
15
- });
16
- });
17
- var _Properties = require("./Properties");
18
- Object.keys(_Properties).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _Properties[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function get() {
24
- return _Properties[key];
25
- }
26
- });
27
- });
28
- var _useIdGenerator = require("./useIdGenerator");
29
- Object.keys(_useIdGenerator).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _useIdGenerator[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function get() {
35
- return _useIdGenerator[key];
36
- }
37
- });
38
- });
39
- var _createConfigurableComponent = require("./createConfigurableComponent");
40
- Object.keys(_createConfigurableComponent).forEach(function (key) {
41
- if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _createConfigurableComponent[key]) return;
43
- Object.defineProperty(exports, key, {
44
- enumerable: true,
45
- get: function get() {
46
- return _createConfigurableComponent[key];
47
- }
48
- });
49
- });
1
+ export * from "./utils";
2
+ export * from "./Properties";
3
+ export * from "./useDebugConfig";
4
+ export * from "./useIdGenerator";
5
+ export * from "./createConfigurableComponent";
50
6
 
51
7
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_utils","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_Properties","_useIdGenerator","_createConfigurableComponent"],"sources":["index.ts"],"sourcesContent":["export * from \"./utils\";\nexport * from \"./Properties\";\nexport * from \"./useIdGenerator\";\nexport * from \"./createConfigurableComponent\";\n"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,WAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,WAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,WAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAC,WAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,eAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,eAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,eAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAE,eAAA,CAAAN,GAAA;IAAA;EAAA;AAAA;AACA,IAAAO,4BAAA,GAAAX,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAS,4BAAA,EAAAR,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAO,4BAAA,CAAAP,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAG,4BAAA,CAAAP,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./utils\";\nexport * from \"./Properties\";\nexport * from \"./useDebugConfig\";\nexport * from \"./useIdGenerator\";\nexport * from \"./createConfigurableComponent\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/react-properties",
3
- "version": "5.43.2-beta.0",
3
+ "version": "6.0.0-alpha.0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,13 +11,13 @@
11
11
  "license": "MIT",
12
12
  "dependencies": {
13
13
  "@types/react": "18.2.79",
14
- "@webiny/react-composition": "5.43.2-beta.0",
14
+ "@webiny/react-composition": "6.0.0-alpha.0",
15
15
  "nanoid": "3.3.8",
16
16
  "react": "18.2.0"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@testing-library/react": "15.0.7",
20
- "@webiny/project-utils": "5.43.2-beta.0",
20
+ "@webiny/project-utils": "6.0.0-alpha.0",
21
21
  "prettier": "2.8.8"
22
22
  },
23
23
  "publishConfig": {
@@ -28,5 +28,5 @@
28
28
  "build": "node ../cli/bin.js run build",
29
29
  "watch": "node ../cli/bin.js run watch"
30
30
  },
31
- "gitHead": "ec6176f001f6350221d992981e110a0351addbaf"
31
+ "gitHead": "a5b28fed7a242d8f56712197a8ea83aa6d2ed101"
32
32
  }
package/useDebugConfig.js CHANGED
@@ -1,23 +1,15 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useDebugConfig = useDebugConfig;
7
- var _react = require("react");
8
- var _utils = require("./utils");
9
- function useDebugConfig(name, properties) {
10
- (0, _react.useEffect)(function () {
1
+ import { useEffect } from "react";
2
+ import { toObject } from "./utils";
3
+ export function useDebugConfig(name, properties) {
4
+ useEffect(() => {
11
5
  if (process.env.NODE_ENV !== "development") {
12
6
  return;
13
7
  }
14
- var configs = window.__debugConfigs ?? {};
15
- configs[name] = function () {
16
- return console.log((0, _utils.toObject)(properties));
17
- };
8
+ const configs = window.__debugConfigs ?? {};
9
+ configs[name] = () => console.log(toObject(properties));
18
10
  window.__debugConfigs = configs;
19
- return function () {
20
- var configs = window.__debugConfigs ?? {};
11
+ return () => {
12
+ const configs = window.__debugConfigs ?? {};
21
13
  delete configs[name];
22
14
  window.__debugConfigs = configs;
23
15
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_utils","useDebugConfig","name","properties","useEffect","process","env","NODE_ENV","configs","window","__debugConfigs","console","log","toObject"],"sources":["useDebugConfig.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { Property } from \"./Properties\";\nimport { toObject } from \"./utils\";\n\ndeclare global {\n interface Window {\n __debugConfigs: Record<string, () => void>;\n }\n}\n\nexport function useDebugConfig(name: string, properties: Property[]) {\n useEffect(() => {\n if (process.env.NODE_ENV !== \"development\") {\n return;\n }\n\n const configs = window.__debugConfigs ?? {};\n configs[name] = () => console.log(toObject(properties));\n window.__debugConfigs = configs;\n\n return () => {\n const configs = window.__debugConfigs ?? {};\n delete configs[name];\n window.__debugConfigs = configs;\n };\n }, [properties]);\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AAQO,SAASE,cAAcA,CAACC,IAAY,EAAEC,UAAsB,EAAE;EACjE,IAAAC,gBAAS,EAAC,YAAM;IACZ,IAAIC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,aAAa,EAAE;MACxC;IACJ;IAEA,IAAMC,OAAO,GAAGC,MAAM,CAACC,cAAc,IAAI,CAAC,CAAC;IAC3CF,OAAO,CAACN,IAAI,CAAC,GAAG;MAAA,OAAMS,OAAO,CAACC,GAAG,CAAC,IAAAC,eAAQ,EAACV,UAAU,CAAC,CAAC;IAAA;IACvDM,MAAM,CAACC,cAAc,GAAGF,OAAO;IAE/B,OAAO,YAAM;MACT,IAAMA,OAAO,GAAGC,MAAM,CAACC,cAAc,IAAI,CAAC,CAAC;MAC3C,OAAOF,OAAO,CAACN,IAAI,CAAC;MACpBO,MAAM,CAACC,cAAc,GAAGF,OAAO;IACnC,CAAC;EACL,CAAC,EAAE,CAACL,UAAU,CAAC,CAAC;AACpB","ignoreList":[]}
1
+ {"version":3,"names":["useEffect","toObject","useDebugConfig","name","properties","process","env","NODE_ENV","configs","window","__debugConfigs","console","log"],"sources":["useDebugConfig.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { Property } from \"./Properties\";\nimport { toObject } from \"./utils\";\n\ndeclare global {\n interface Window {\n __debugConfigs: Record<string, () => void>;\n }\n}\n\nexport function useDebugConfig(name: string, properties: Property[]) {\n useEffect(() => {\n if (process.env.NODE_ENV !== \"development\") {\n return;\n }\n\n const configs = window.__debugConfigs ?? {};\n configs[name] = () => console.log(toObject(properties));\n window.__debugConfigs = configs;\n\n return () => {\n const configs = window.__debugConfigs ?? {};\n delete configs[name];\n window.__debugConfigs = configs;\n };\n }, [properties]);\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAO;AAEjC,SAASC,QAAQ;AAQjB,OAAO,SAASC,cAAcA,CAACC,IAAY,EAAEC,UAAsB,EAAE;EACjEJ,SAAS,CAAC,MAAM;IACZ,IAAIK,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,aAAa,EAAE;MACxC;IACJ;IAEA,MAAMC,OAAO,GAAGC,MAAM,CAACC,cAAc,IAAI,CAAC,CAAC;IAC3CF,OAAO,CAACL,IAAI,CAAC,GAAG,MAAMQ,OAAO,CAACC,GAAG,CAACX,QAAQ,CAACG,UAAU,CAAC,CAAC;IACvDK,MAAM,CAACC,cAAc,GAAGF,OAAO;IAE/B,OAAO,MAAM;MACT,MAAMA,OAAO,GAAGC,MAAM,CAACC,cAAc,IAAI,CAAC,CAAC;MAC3C,OAAOF,OAAO,CAACL,IAAI,CAAC;MACpBM,MAAM,CAACC,cAAc,GAAGF,OAAO;IACnC,CAAC;EACL,CAAC,EAAE,CAACJ,UAAU,CAAC,CAAC;AACpB","ignoreList":[]}
package/useIdGenerator.js CHANGED
@@ -1,18 +1,13 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useIdGenerator = useIdGenerator;
7
- var _react = require("react");
8
- var _Properties = require("./Properties");
9
- function useIdGenerator(name) {
10
- var parentProperty = (0, _Properties.useParentProperty)();
11
- return (0, _react.useCallback)(function () {
12
- for (var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++) {
13
- parts[_key] = arguments[_key];
1
+ import { useCallback } from "react";
2
+ import { useParentProperty } from "./Properties";
3
+ const keywords = ["$first", "$last"];
4
+ export function useIdGenerator(name) {
5
+ const parentProperty = useParentProperty();
6
+ return useCallback((...parts) => {
7
+ if (keywords.includes(parts[0])) {
8
+ return parts[0];
14
9
  }
15
- return [parentProperty?.id, name].concat(parts).filter(Boolean).join(":");
10
+ return [parentProperty?.id, name, ...parts].filter(Boolean).join(":");
16
11
  }, [name, parentProperty]);
17
12
  }
18
13
 
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_Properties","useIdGenerator","name","parentProperty","useParentProperty","useCallback","_len","arguments","length","parts","Array","_key","id","concat","filter","Boolean","join"],"sources":["useIdGenerator.ts"],"sourcesContent":["import { useCallback } from \"react\";\nimport { useParentProperty } from \"~/Properties\";\n\nexport function useIdGenerator(name: string) {\n const parentProperty = useParentProperty();\n\n return useCallback(\n (...parts: string[]) => {\n return [parentProperty?.id, name, ...parts].filter(Boolean).join(\":\");\n },\n [name, parentProperty]\n );\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAEO,SAASE,cAAcA,CAACC,IAAY,EAAE;EACzC,IAAMC,cAAc,GAAG,IAAAC,6BAAiB,EAAC,CAAC;EAE1C,OAAO,IAAAC,kBAAW,EACd,YAAwB;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAApBC,KAAK,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAALF,KAAK,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IAAA;IACL,OAAO,CAACR,cAAc,EAAES,EAAE,EAAEV,IAAI,EAAAW,MAAA,CAAKJ,KAAK,EAAEK,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;EACzE,CAAC,EACD,CAACd,IAAI,EAAEC,cAAc,CACzB,CAAC;AACL","ignoreList":[]}
1
+ {"version":3,"names":["useCallback","useParentProperty","keywords","useIdGenerator","name","parentProperty","parts","includes","id","filter","Boolean","join"],"sources":["useIdGenerator.ts"],"sourcesContent":["import { useCallback } from \"react\";\nimport { useParentProperty } from \"~/Properties\";\n\nconst keywords = [\"$first\", \"$last\"];\n\nexport function useIdGenerator(name: string) {\n const parentProperty = useParentProperty();\n\n return useCallback(\n (...parts: string[]) => {\n if (keywords.includes(parts[0])) {\n return parts[0];\n }\n return [parentProperty?.id, name, ...parts].filter(Boolean).join(\":\");\n },\n [name, parentProperty]\n );\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,OAAO;AACnC,SAASC,iBAAiB;AAE1B,MAAMC,QAAQ,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC;AAEpC,OAAO,SAASC,cAAcA,CAACC,IAAY,EAAE;EACzC,MAAMC,cAAc,GAAGJ,iBAAiB,CAAC,CAAC;EAE1C,OAAOD,WAAW,CACd,CAAC,GAAGM,KAAe,KAAK;IACpB,IAAIJ,QAAQ,CAACK,QAAQ,CAACD,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;MAC7B,OAAOA,KAAK,CAAC,CAAC,CAAC;IACnB;IACA,OAAO,CAACD,cAAc,EAAEG,EAAE,EAAEJ,IAAI,EAAE,GAAGE,KAAK,CAAC,CAACG,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;EACzE,CAAC,EACD,CAACP,IAAI,EAAEC,cAAc,CACzB,CAAC;AACL","ignoreList":[]}
package/utils.js CHANGED
@@ -1,45 +1,46 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getUniqueId = getUniqueId;
8
- exports.toObject = toObject;
9
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
- var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
- var _nanoid = require("nanoid");
13
- var nanoid = (0, _nanoid.customAlphabet)("1234567890abcdef");
1
+ import { customAlphabet } from "nanoid";
2
+ const nanoid = customAlphabet("1234567890abcdef");
3
+ const sortPropertiesToTheTop = (a, b) => {
4
+ if (a.$isFirst && b.$isFirst) {
5
+ return -1;
6
+ }
7
+ return Number(b.$isFirst) - Number(a.$isFirst);
8
+ };
9
+ const sortPropertiesToTheBottom = (a, b) => {
10
+ if (a.$isLast && b.$isLast) {
11
+ return 1;
12
+ }
13
+ return Number(a.$isLast) - Number(b.$isLast);
14
+ };
15
+ const sortProperties = properties => {
16
+ return properties.sort(sortPropertiesToTheTop).sort(sortPropertiesToTheBottom);
17
+ };
14
18
  function buildRoots(roots, properties) {
15
- var obj = roots.reduce(function (acc, item) {
16
- var isArray = item.array === true || roots.filter(function (r) {
17
- return r.name === item.name;
18
- }).length > 1;
19
- return (0, _objectSpread3.default)((0, _objectSpread3.default)({}, acc), {}, (0, _defineProperty2.default)({}, item.name, isArray ? [] : {}));
19
+ const sortedRoots = sortProperties(roots);
20
+ const obj = sortedRoots.reduce((acc, item) => {
21
+ const isArray = item.array === true || sortedRoots.filter(r => r.name === item.name).length > 1;
22
+ return {
23
+ ...acc,
24
+ [item.name]: isArray ? [] : {}
25
+ };
20
26
  }, {});
21
- roots.forEach(function (root) {
22
- var isArray = root.array === true || Array.isArray(obj[root.name]);
27
+ sortedRoots.forEach(root => {
28
+ const isArray = root.array === true || Array.isArray(obj[root.name]);
23
29
  if (root.value !== undefined) {
24
- obj[root.name] = isArray ? [].concat((0, _toConsumableArray2.default)(obj[root.name]), [root.value]) : root.value;
30
+ obj[root.name] = isArray ? [...obj[root.name], root.value] : root.value;
25
31
  return;
26
32
  }
27
- var nextRoots = properties.filter(function (p) {
28
- return p.parent === root.id;
29
- });
30
- var value = buildRoots(nextRoots, properties);
31
- obj[root.name] = isArray ? [].concat((0, _toConsumableArray2.default)(obj[root.name]), [value]) : value;
33
+ const nextRoots = properties.filter(p => p.parent === root.id);
34
+ const value = buildRoots(nextRoots, properties);
35
+ obj[root.name] = isArray ? [...obj[root.name], value] : value;
32
36
  });
33
37
  return obj;
34
38
  }
35
- function toObject(properties) {
36
- var roots = properties.filter(function (prop) {
37
- return prop.parent === "";
38
- });
39
+ export function toObject(properties) {
40
+ const roots = properties.filter(prop => prop.parent === "");
39
41
  return buildRoots(roots, properties);
40
42
  }
41
- function getUniqueId() {
42
- var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 12;
43
+ export function getUniqueId(length = 12) {
43
44
  return nanoid(length);
44
45
  }
45
46
 
package/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_nanoid","require","nanoid","customAlphabet","buildRoots","roots","properties","obj","reduce","acc","item","isArray","array","filter","r","name","length","_objectSpread3","default","_defineProperty2","forEach","root","Array","value","undefined","concat","_toConsumableArray2","nextRoots","p","parent","id","toObject","prop","getUniqueId","arguments"],"sources":["utils.ts"],"sourcesContent":["import { customAlphabet } from \"nanoid\";\nconst nanoid = customAlphabet(\"1234567890abcdef\");\nimport { Property } from \"./Properties\";\n\nfunction buildRoots(roots: Property[], properties: Property[]) {\n const obj: Record<string, unknown> = roots.reduce((acc, item) => {\n const isArray = item.array === true || roots.filter(r => r.name === item.name).length > 1;\n return { ...acc, [item.name]: isArray ? [] : {} };\n }, {});\n\n roots.forEach(root => {\n const isArray = root.array === true || Array.isArray(obj[root.name]);\n if (root.value !== undefined) {\n obj[root.name] = isArray ? [...(obj[root.name] as Array<any>), root.value] : root.value;\n return;\n }\n\n const nextRoots = properties.filter(p => p.parent === root.id);\n const value = buildRoots(nextRoots, properties);\n obj[root.name] = isArray ? [...(obj[root.name] as Property[]), value] : value;\n });\n\n return obj;\n}\n\nexport function toObject<T = unknown>(properties: Property[]): T {\n const roots = properties.filter(prop => prop.parent === \"\");\n return buildRoots(roots, properties) as T;\n}\n\nexport function getUniqueId(length = 12) {\n return nanoid(length);\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAMC,MAAM,GAAG,IAAAC,sBAAc,EAAC,kBAAkB,CAAC;AAGjD,SAASC,UAAUA,CAACC,KAAiB,EAAEC,UAAsB,EAAE;EAC3D,IAAMC,GAA4B,GAAGF,KAAK,CAACG,MAAM,CAAC,UAACC,GAAG,EAAEC,IAAI,EAAK;IAC7D,IAAMC,OAAO,GAAGD,IAAI,CAACE,KAAK,KAAK,IAAI,IAAIP,KAAK,CAACQ,MAAM,CAAC,UAAAC,CAAC;MAAA,OAAIA,CAAC,CAACC,IAAI,KAAKL,IAAI,CAACK,IAAI;IAAA,EAAC,CAACC,MAAM,GAAG,CAAC;IACzF,WAAAC,cAAA,CAAAC,OAAA,MAAAD,cAAA,CAAAC,OAAA,MAAYT,GAAG,WAAAU,gBAAA,CAAAD,OAAA,MAAGR,IAAI,CAACK,IAAI,EAAGJ,OAAO,GAAG,EAAE,GAAG,CAAC,CAAC;EACnD,CAAC,EAAE,CAAC,CAAC,CAAC;EAENN,KAAK,CAACe,OAAO,CAAC,UAAAC,IAAI,EAAI;IAClB,IAAMV,OAAO,GAAGU,IAAI,CAACT,KAAK,KAAK,IAAI,IAAIU,KAAK,CAACX,OAAO,CAACJ,GAAG,CAACc,IAAI,CAACN,IAAI,CAAC,CAAC;IACpE,IAAIM,IAAI,CAACE,KAAK,KAAKC,SAAS,EAAE;MAC1BjB,GAAG,CAACc,IAAI,CAACN,IAAI,CAAC,GAAGJ,OAAO,MAAAc,MAAA,KAAAC,mBAAA,CAAAR,OAAA,EAAQX,GAAG,CAACc,IAAI,CAACN,IAAI,CAAC,IAAiBM,IAAI,CAACE,KAAK,KAAIF,IAAI,CAACE,KAAK;MACvF;IACJ;IAEA,IAAMI,SAAS,GAAGrB,UAAU,CAACO,MAAM,CAAC,UAAAe,CAAC;MAAA,OAAIA,CAAC,CAACC,MAAM,KAAKR,IAAI,CAACS,EAAE;IAAA,EAAC;IAC9D,IAAMP,KAAK,GAAGnB,UAAU,CAACuB,SAAS,EAAErB,UAAU,CAAC;IAC/CC,GAAG,CAACc,IAAI,CAACN,IAAI,CAAC,GAAGJ,OAAO,MAAAc,MAAA,KAAAC,mBAAA,CAAAR,OAAA,EAAQX,GAAG,CAACc,IAAI,CAACN,IAAI,CAAC,IAAiBQ,KAAK,KAAIA,KAAK;EACjF,CAAC,CAAC;EAEF,OAAOhB,GAAG;AACd;AAEO,SAASwB,QAAQA,CAAczB,UAAsB,EAAK;EAC7D,IAAMD,KAAK,GAAGC,UAAU,CAACO,MAAM,CAAC,UAAAmB,IAAI;IAAA,OAAIA,IAAI,CAACH,MAAM,KAAK,EAAE;EAAA,EAAC;EAC3D,OAAOzB,UAAU,CAACC,KAAK,EAAEC,UAAU,CAAC;AACxC;AAEO,SAAS2B,WAAWA,CAAA,EAAc;EAAA,IAAbjB,MAAM,GAAAkB,SAAA,CAAAlB,MAAA,QAAAkB,SAAA,QAAAV,SAAA,GAAAU,SAAA,MAAG,EAAE;EACnC,OAAOhC,MAAM,CAACc,MAAM,CAAC;AACzB","ignoreList":[]}
1
+ {"version":3,"names":["customAlphabet","nanoid","sortPropertiesToTheTop","a","b","$isFirst","Number","sortPropertiesToTheBottom","$isLast","sortProperties","properties","sort","buildRoots","roots","sortedRoots","obj","reduce","acc","item","isArray","array","filter","r","name","length","forEach","root","Array","value","undefined","nextRoots","p","parent","id","toObject","prop","getUniqueId"],"sources":["utils.ts"],"sourcesContent":["import { customAlphabet } from \"nanoid\";\nconst nanoid = customAlphabet(\"1234567890abcdef\");\nimport { Property } from \"./Properties\";\n\nconst sortPropertiesToTheTop = (a: Property, b: Property) => {\n if (a.$isFirst && b.$isFirst) {\n return -1;\n }\n\n return Number(b.$isFirst) - Number(a.$isFirst);\n};\n\nconst sortPropertiesToTheBottom = (a: Property, b: Property) => {\n if (a.$isLast && b.$isLast) {\n return 1;\n }\n\n return Number(a.$isLast) - Number(b.$isLast);\n};\n\nconst sortProperties = (properties: Property[]) => {\n return properties.sort(sortPropertiesToTheTop).sort(sortPropertiesToTheBottom);\n};\n\nfunction buildRoots(roots: Property[], properties: Property[]) {\n const sortedRoots = sortProperties(roots);\n const obj: Record<string, unknown> = sortedRoots.reduce((acc, item) => {\n const isArray =\n item.array === true || sortedRoots.filter(r => r.name === item.name).length > 1;\n return { ...acc, [item.name]: isArray ? [] : {} };\n }, {});\n\n sortedRoots.forEach(root => {\n const isArray = root.array === true || Array.isArray(obj[root.name]);\n if (root.value !== undefined) {\n obj[root.name] = isArray ? [...(obj[root.name] as Array<any>), root.value] : root.value;\n return;\n }\n\n const nextRoots = properties.filter(p => p.parent === root.id);\n const value = buildRoots(nextRoots, properties);\n obj[root.name] = isArray ? [...(obj[root.name] as Property[]), value] : value;\n });\n\n return obj;\n}\n\nexport function toObject<T = unknown>(properties: Property[]): T {\n const roots = properties.filter(prop => prop.parent === \"\");\n return buildRoots(roots, properties) as T;\n}\n\nexport function getUniqueId(length = 12) {\n return nanoid(length);\n}\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ,QAAQ;AACvC,MAAMC,MAAM,GAAGD,cAAc,CAAC,kBAAkB,CAAC;AAGjD,MAAME,sBAAsB,GAAGA,CAACC,CAAW,EAAEC,CAAW,KAAK;EACzD,IAAID,CAAC,CAACE,QAAQ,IAAID,CAAC,CAACC,QAAQ,EAAE;IAC1B,OAAO,CAAC,CAAC;EACb;EAEA,OAAOC,MAAM,CAACF,CAAC,CAACC,QAAQ,CAAC,GAAGC,MAAM,CAACH,CAAC,CAACE,QAAQ,CAAC;AAClD,CAAC;AAED,MAAME,yBAAyB,GAAGA,CAACJ,CAAW,EAAEC,CAAW,KAAK;EAC5D,IAAID,CAAC,CAACK,OAAO,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