@webiny/react-properties 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9

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.
Files changed (42) hide show
  1. package/DevToolsSection.d.ts +40 -0
  2. package/DevToolsSection.js +54 -0
  3. package/DevToolsSection.js.map +1 -0
  4. package/Properties.d.ts +60 -0
  5. package/Properties.js +130 -191
  6. package/Properties.js.map +1 -1
  7. package/PropertyPriority.d.ts +8 -0
  8. package/PropertyPriority.js +11 -0
  9. package/PropertyPriority.js.map +1 -0
  10. package/README.md +7 -61
  11. package/createConfigurableComponent.d.ts +15 -0
  12. package/createConfigurableComponent.js +67 -0
  13. package/createConfigurableComponent.js.map +1 -0
  14. package/domain/PropertyStore.d.ts +51 -0
  15. package/domain/PropertyStore.js +154 -0
  16. package/domain/PropertyStore.js.map +1 -0
  17. package/domain/index.d.ts +1 -0
  18. package/domain/index.js +1 -0
  19. package/index.d.ts +7 -0
  20. package/index.js +7 -31
  21. package/package.json +19 -17
  22. package/useDebugConfig.d.ts +32 -0
  23. package/useDebugConfig.js +45 -0
  24. package/useDebugConfig.js.map +1 -0
  25. package/useIdGenerator.d.ts +1 -0
  26. package/useIdGenerator.js +23 -0
  27. package/useIdGenerator.js.map +1 -0
  28. package/utils.d.ts +3 -0
  29. package/utils.js +42 -48
  30. package/utils.js.map +1 -1
  31. package/__tests__/cases/dashboard/App.d.ts +0 -23
  32. package/__tests__/cases/dashboard/dashboard.test.d.ts +0 -1
  33. package/__tests__/cases/pbEditorSettings/PbEditorSettingsView.d.ts +0 -21
  34. package/__tests__/cases/pbEditorSettings/createConfigurableView.d.ts +0 -9
  35. package/__tests__/cases/pbEditorSettings/pbEditorSettings.test.d.ts +0 -1
  36. package/__tests__/properties.test.d.ts +0 -1
  37. package/__tests__/setupEnv.d.ts +0 -1
  38. package/__tests__/utils.d.ts +0 -2
  39. package/index.js.map +0 -1
  40. package/src/Properties.d.ts +0 -38
  41. package/src/index.d.ts +0 -2
  42. package/src/utils.d.ts +0 -3
package/utils.js CHANGED
@@ -1,54 +1,48 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.getUniqueId = getUniqueId;
9
- exports.toObject = toObject;
10
-
11
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
12
-
13
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
-
15
- var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
-
17
- var _nanoid = require("nanoid");
18
-
19
- var nanoid = (0, _nanoid.customAlphabet)("1234567890abcdef", 6);
20
-
1
+ import { customAlphabet } from "nanoid";
2
+ const nanoid = customAlphabet("1234567890abcdef");
3
+ const sortPropertiesToTheTop = (a, b)=>{
4
+ if (a.$isFirst && b.$isFirst) return -1;
5
+ return Number(b.$isFirst) - Number(a.$isFirst);
6
+ };
7
+ const sortPropertiesToTheBottom = (a, b)=>{
8
+ if (a.$isLast && b.$isLast) return 1;
9
+ return Number(a.$isLast) - Number(b.$isLast);
10
+ };
11
+ const sortProperties = (properties)=>properties.sort(sortPropertiesToTheTop).sort(sortPropertiesToTheBottom);
21
12
  function buildRoots(roots, properties) {
22
- var obj = roots.reduce(function (acc, item) {
23
- var isArray = item.array === true || roots.filter(function (r) {
24
- return r.name === item.name;
25
- }).length > 1;
26
- return (0, _objectSpread3.default)((0, _objectSpread3.default)({}, acc), {}, (0, _defineProperty2.default)({}, item.name, isArray ? [] : {}));
27
- }, {});
28
- roots.forEach(function (root) {
29
- var isArray = root.array === true || Array.isArray(obj[root.name]);
30
-
31
- if (root.value !== undefined) {
32
- obj[root.name] = isArray ? [].concat((0, _toConsumableArray2.default)(obj[root.name]), [root.value]) : root.value;
33
- return;
34
- }
35
-
36
- var nextRoots = properties.filter(function (p) {
37
- return p.parent === root.id;
13
+ const sortedRoots = sortProperties(roots);
14
+ const obj = sortedRoots.reduce((acc, item)=>{
15
+ const isArray = true === item.array || sortedRoots.filter((r)=>r.name === item.name).length > 1;
16
+ return {
17
+ ...acc,
18
+ [item.name]: isArray ? [] : {}
19
+ };
20
+ }, {});
21
+ sortedRoots.forEach((root)=>{
22
+ const isArray = true === root.array || Array.isArray(obj[root.name]);
23
+ if (void 0 !== root.value) {
24
+ obj[root.name] = isArray ? [
25
+ ...obj[root.name],
26
+ root.value
27
+ ] : root.value;
28
+ return;
29
+ }
30
+ const nextRoots = properties.filter((p)=>p.parent === root.id);
31
+ const value = buildRoots(nextRoots, properties);
32
+ obj[root.name] = isArray ? [
33
+ ...obj[root.name],
34
+ value
35
+ ] : value;
38
36
  });
39
- var value = buildRoots(nextRoots, properties);
40
- obj[root.name] = isArray ? [].concat((0, _toConsumableArray2.default)(obj[root.name]), [value]) : value;
41
- });
42
- return obj;
37
+ return obj;
43
38
  }
44
-
45
39
  function toObject(properties) {
46
- var roots = properties.filter(function (prop) {
47
- return prop.parent === "";
48
- });
49
- return buildRoots(roots, properties);
40
+ const roots = properties.filter((prop)=>"" === prop.parent);
41
+ return buildRoots(roots, properties);
42
+ }
43
+ function getUniqueId(length = 12) {
44
+ return nanoid(length);
50
45
  }
46
+ export { getUniqueId, toObject };
51
47
 
52
- function getUniqueId() {
53
- return nanoid();
54
- }
48
+ //# sourceMappingURL=utils.js.map
package/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["nanoid","customAlphabet","buildRoots","roots","properties","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\", 6);\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() {\n return nanoid();\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;;AACA,IAAMA,MAAM,GAAG,IAAAC,sBAAA,EAAe,kBAAf,EAAmC,CAAnC,CAAf;;AAGA,SAASC,UAAT,CAAoBC,KAApB,EAAuCC,UAAvC,EAA+D;EAC3D,IAAMC,GAA4B,GAAGF,KAAK,CAACG,MAAN,CAAa,UAACC,GAAD,EAAMC,IAAN,EAAe;IAC7D,IAAMC,OAAO,GAAGD,IAAI,CAACE,KAAL,KAAe,IAAf,IAAuBP,KAAK,CAACQ,MAAN,CAAa,UAAAC,CAAC;MAAA,OAAIA,CAAC,CAACC,IAAF,KAAWL,IAAI,CAACK,IAApB;IAAA,CAAd,EAAwCC,MAAxC,GAAiD,CAAxF;IACA,mEAAYP,GAAZ,yCAAkBC,IAAI,CAACK,IAAvB,EAA8BJ,OAAO,GAAG,EAAH,GAAQ,EAA7C;EACH,CAHoC,EAGlC,EAHkC,CAArC;EAKAN,KAAK,CAACY,OAAN,CAAc,UAAAC,IAAI,EAAI;IAClB,IAAMP,OAAO,GAAGO,IAAI,CAACN,KAAL,KAAe,IAAf,IAAuBO,KAAK,CAACR,OAAN,CAAcJ,GAAG,CAACW,IAAI,CAACH,IAAN,CAAjB,CAAvC;;IACA,IAAIG,IAAI,CAACE,KAAL,KAAeC,SAAnB,EAA8B;MAC1Bd,GAAG,CAACW,IAAI,CAACH,IAAN,CAAH,GAAiBJ,OAAO,8CAAQJ,GAAG,CAACW,IAAI,CAACH,IAAN,CAAX,IAAuCG,IAAI,CAACE,KAA5C,KAAqDF,IAAI,CAACE,KAAlF;MACA;IACH;;IAED,IAAME,SAAS,GAAGhB,UAAU,CAACO,MAAX,CAAkB,UAAAU,CAAC;MAAA,OAAIA,CAAC,CAACC,MAAF,KAAaN,IAAI,CAACO,EAAtB;IAAA,CAAnB,CAAlB;IACA,IAAML,KAAK,GAAGhB,UAAU,CAACkB,SAAD,EAAYhB,UAAZ,CAAxB;IACAC,GAAG,CAACW,IAAI,CAACH,IAAN,CAAH,GAAiBJ,OAAO,8CAAQJ,GAAG,CAACW,IAAI,CAACH,IAAN,CAAX,IAAuCK,KAAvC,KAAgDA,KAAxE;EACH,CAVD;EAYA,OAAOb,GAAP;AACH;;AAEM,SAASmB,QAAT,CAA+BpB,UAA/B,EAA0D;EAC7D,IAAMD,KAAK,GAAGC,UAAU,CAACO,MAAX,CAAkB,UAAAc,IAAI;IAAA,OAAIA,IAAI,CAACH,MAAL,KAAgB,EAApB;EAAA,CAAtB,CAAd;EACA,OAAOpB,UAAU,CAACC,KAAD,EAAQC,UAAR,CAAjB;AACH;;AAEM,SAASsB,WAAT,GAAuB;EAC1B,OAAO1B,MAAM,EAAb;AACH"}
1
+ {"version":3,"file":"utils.js","sources":["../src/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"],"names":["nanoid","customAlphabet","sortPropertiesToTheTop","a","b","Number","sortPropertiesToTheBottom","sortProperties","properties","buildRoots","roots","sortedRoots","obj","acc","item","isArray","r","root","Array","undefined","nextRoots","p","value","toObject","prop","getUniqueId","length"],"mappings":";AACA,MAAMA,SAASC,eAAe;AAG9B,MAAMC,yBAAyB,CAACC,GAAaC;IACzC,IAAID,EAAE,QAAQ,IAAIC,EAAE,QAAQ,EACxB,OAAO;IAGX,OAAOC,OAAOD,EAAE,QAAQ,IAAIC,OAAOF,EAAE,QAAQ;AACjD;AAEA,MAAMG,4BAA4B,CAACH,GAAaC;IAC5C,IAAID,EAAE,OAAO,IAAIC,EAAE,OAAO,EACtB,OAAO;IAGX,OAAOC,OAAOF,EAAE,OAAO,IAAIE,OAAOD,EAAE,OAAO;AAC/C;AAEA,MAAMG,iBAAiB,CAACC,aACbA,WAAW,IAAI,CAACN,wBAAwB,IAAI,CAACI;AAGxD,SA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{
4
- name: string;
5
- type: string;
6
- }
7
- declare const AddWidget: <T extends Record<string, unknown>>(props: T & AddWidgetProps) => JSX.Element;
8
- export interface CardWidget extends Record<string, unknown> {
9
- title: string;
10
- description: string;
11
- button: React.ReactElement;
12
- }
13
- interface DashboardConfig extends React.FC<unknown> {
14
- AddWidget: typeof AddWidget;
15
- DashboardRenderer: typeof DashboardRenderer;
16
- }
17
- export declare const DashboardConfig: DashboardConfig;
18
- declare const DashboardRenderer: import("@webiny/react-composition").ComposableFC<unknown>;
19
- interface DashboardViewProps {
20
- onProperties(properties: Property[]): void;
21
- }
22
- export declare const App: React.FC<DashboardViewProps>;
23
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,21 +0,0 @@
1
- import React from "react";
2
- interface SettingsGroupProps {
3
- name: string;
4
- title?: string;
5
- icon?: string;
6
- remove?: boolean;
7
- replace?: string;
8
- }
9
- interface FormFieldProps extends Record<string, unknown> {
10
- name: string;
11
- component?: string;
12
- after?: string;
13
- remove?: boolean;
14
- replace?: string;
15
- }
16
- declare const PageSettingsView: React.FC<import("./createConfigurableView").ViewProps>;
17
- declare const PageSettingsConfig: React.FC<{}> & {
18
- FormField: React.FC<FormFieldProps>;
19
- SettingsGroup: React.FC<SettingsGroupProps>;
20
- };
21
- export { PageSettingsView, PageSettingsConfig };
@@ -1,9 +0,0 @@
1
- import * as React from "react";
2
- import { Property } from "../../../src/index";
3
- export interface ViewProps {
4
- onProperties?(properties: Property[]): void;
5
- }
6
- export declare function createConfigurableView(name: string): {
7
- View: React.FC<ViewProps>;
8
- Config: React.FC<{}>;
9
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- declare const randomFillSync: any;
@@ -1,2 +0,0 @@
1
- /// <reference types="jest" />
2
- export declare function getLastCall(callable: jest.Mock): any;
package/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./utils\";\nexport * from \"./Properties\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
@@ -1,38 +0,0 @@
1
- import React from "react";
2
- export interface Property {
3
- id: string;
4
- parent: string;
5
- name: string;
6
- value: unknown;
7
- array?: boolean;
8
- }
9
- interface AddPropertyOptions {
10
- after?: string;
11
- before?: string;
12
- }
13
- interface PropertiesContext {
14
- properties: Property[];
15
- getObject<T = unknown>(): T;
16
- addProperty(property: Property, options?: AddPropertyOptions): void;
17
- removeProperty(id: string): void;
18
- replaceProperty(id: string, property: Property): void;
19
- }
20
- declare const PropertiesContext: React.Context<PropertiesContext | undefined>;
21
- interface PropertiesProps {
22
- onChange?(properties: Property[]): void;
23
- }
24
- export declare const Properties: React.FC<PropertiesProps>;
25
- export declare function useProperties(): PropertiesContext;
26
- interface PropertyProps {
27
- id?: string;
28
- name: string;
29
- value?: unknown;
30
- array?: boolean;
31
- after?: string;
32
- before?: string;
33
- replace?: string;
34
- remove?: boolean;
35
- }
36
- export declare function useParentProperty(): Property | undefined;
37
- export declare const Property: React.FC<PropertyProps>;
38
- export {};
package/src/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./utils";
2
- export * from "./Properties";
package/src/utils.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { Property } from "./Properties";
2
- export declare function toObject<T = unknown>(properties: Property[]): T;
3
- export declare function getUniqueId(): string;