@webiny/react-properties 0.0.0-unstable.c2780f51fe → 0.0.0-unstable.c27f4d8a31
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 +19 -3
- package/Properties.js +153 -153
- package/Properties.js.map +1 -1
- package/PropertyPriority.d.ts +8 -0
- package/PropertyPriority.js +15 -0
- package/PropertyPriority.js.map +1 -0
- package/README.md +7 -61
- package/createConfigurableComponent.d.ts +15 -0
- package/createConfigurableComponent.js +111 -0
- package/createConfigurableComponent.js.map +1 -0
- package/domain/PropertyStore.d.ts +48 -0
- package/domain/PropertyStore.js +200 -0
- package/domain/PropertyStore.js.map +1 -0
- package/domain/index.d.ts +1 -0
- package/domain/index.js +3 -0
- package/domain/index.js.map +1 -0
- package/index.d.ts +6 -2
- package/index.js +7 -26
- package/index.js.map +1 -1
- package/package.json +12 -15
- package/useDebugConfig.d.ts +7 -0
- package/useDebugConfig.js +19 -0
- package/useDebugConfig.js.map +1 -0
- package/useIdGenerator.d.ts +1 -0
- package/useIdGenerator.js +14 -0
- package/useIdGenerator.js.map +1 -0
- package/utils.d.ts +1 -1
- package/utils.js +36 -33
- package/utils.js.map +1 -1
package/utils.js
CHANGED
|
@@ -1,44 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
22
|
-
|
|
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 ? [
|
|
30
|
+
obj[root.name] = isArray ? [...obj[root.name], root.value] : root.value;
|
|
25
31
|
return;
|
|
26
32
|
}
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
+
}
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=utils.js.map
|
package/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["nanoid","
|
|
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 type { Property } from \"./Properties.js\";\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,IAAIJ,CAAC,CAACI,OAAO,EAAE;IACxB,OAAO,CAAC;EACZ;EAEA,OAAOF,MAAM,CAACH,CAAC,CAACK,OAAO,CAAC,GAAGF,MAAM,CAACF,CAAC,CAACI,OAAO,CAAC;AAChD,CAAC;AAED,MAAMC,cAAc,GAAIC,UAAsB,IAAK;EAC/C,OAAOA,UAAU,CAACC,IAAI,CAACT,sBAAsB,CAAC,CAACS,IAAI,CAACJ,yBAAyB,CAAC;AAClF,CAAC;AAED,SAASK,UAAUA,CAACC,KAAiB,EAAEH,UAAsB,EAAE;EAC3D,MAAMI,WAAW,GAAGL,cAAc,CAACI,KAAK,CAAC;EACzC,MAAME,GAA4B,GAAGD,WAAW,CAACE,MAAM,CAAC,CAACC,GAAG,EAAEC,IAAI,KAAK;IACnE,MAAMC,OAAO,GACTD,IAAI,CAACE,KAA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