@webiny/react-properties 6.0.0-beta.0 → 6.0.0-rc.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/Properties.d.ts +16 -2
- package/Properties.js +149 -191
- 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 +1 -1
- package/createConfigurableComponent.js +67 -64
- package/createConfigurableComponent.js.map +1 -1
- 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 -4
- package/index.js +6 -49
- package/index.js.map +1 -1
- package/package.json +9 -12
- package/useDebugConfig.d.ts +7 -0
- package/useDebugConfig.js +19 -0
- package/useDebugConfig.js.map +1 -0
- package/useIdGenerator.js +9 -14
- package/useIdGenerator.js.map +1 -1
- package/utils.d.ts +1 -1
- package/utils.js +33 -32
- package/utils.js.map +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { toObject } from "./utils.js";
|
|
3
|
+
export function useDebugConfig(name, properties) {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
if (process.env.NODE_ENV !== "development") {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const configs = window.__debugConfigs ?? {};
|
|
9
|
+
configs[name] = () => console.log(toObject(properties));
|
|
10
|
+
window.__debugConfigs = configs;
|
|
11
|
+
return () => {
|
|
12
|
+
const configs = window.__debugConfigs ?? {};
|
|
13
|
+
delete configs[name];
|
|
14
|
+
window.__debugConfigs = configs;
|
|
15
|
+
};
|
|
16
|
+
}, [properties]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=useDebugConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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 type { Property } from \"./Properties.js\";\nimport { toObject } from \"./utils.js\";\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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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.js";
|
|
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].
|
|
10
|
+
return [parentProperty?.id, name, ...parts].filter(Boolean).join(":");
|
|
16
11
|
}, [name, parentProperty]);
|
|
17
12
|
}
|
|
18
13
|
|
package/useIdGenerator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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.js\";\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.d.ts
CHANGED
package/utils.js
CHANGED
|
@@ -1,45 +1,46 @@
|
|
|
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
|
}
|
|
45
46
|
|
package/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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,sBAAs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