@webiny/react-properties 5.40.2 → 5.40.3-beta.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.
|
@@ -10,6 +10,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
var _reactComposition = require("@webiny/react-composition");
|
|
12
12
|
var _index = require("./index");
|
|
13
|
+
var _useDebugConfig = require("./useDebugConfig");
|
|
13
14
|
var createHOC = function createHOC(newChildren) {
|
|
14
15
|
return function (BaseComponent) {
|
|
15
16
|
return function ConfigHOC(_ref) {
|
|
@@ -60,6 +61,7 @@ function createConfigurableComponent(name) {
|
|
|
60
61
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
61
62
|
properties = _useState2[0],
|
|
62
63
|
setProperties = _useState2[1];
|
|
64
|
+
(0, _useDebugConfig.useDebugConfig)(name, properties);
|
|
63
65
|
var context = {
|
|
64
66
|
properties: properties
|
|
65
67
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactComposition","_index","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","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 { Property, Properties, toObject } from \"~/index\";\nimport {
|
|
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,o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AVA,UAAU;IACVZ,MAAM,EAANA,MAAM;IACN4B,SAAS,EAATA;EACJ,CAAC;AACL","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/react-properties",
|
|
3
|
-
"version": "5.40.
|
|
3
|
+
"version": "5.40.3-beta.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@babel/runtime": "7.24.1",
|
|
14
14
|
"@types/react": "18.2.79",
|
|
15
|
-
"@webiny/react-composition": "5.40.
|
|
15
|
+
"@webiny/react-composition": "5.40.3-beta.0",
|
|
16
16
|
"nanoid": "3.3.7",
|
|
17
17
|
"react": "18.2.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@testing-library/react": "15.0.7",
|
|
21
|
-
"@webiny/cli": "5.40.
|
|
22
|
-
"@webiny/project-utils": "5.40.
|
|
21
|
+
"@webiny/cli": "5.40.3-beta.0",
|
|
22
|
+
"@webiny/project-utils": "5.40.3-beta.0",
|
|
23
23
|
"prettier": "2.8.8"
|
|
24
24
|
},
|
|
25
25
|
"publishConfig": {
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"build": "yarn webiny run build",
|
|
31
31
|
"watch": "yarn webiny run watch"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "5d0f987f2b140c0383330ece647f3eb8637156ff"
|
|
34
34
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 () {
|
|
11
|
+
if (process.env.NODE_ENV !== "development") {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
var configs = window.__debugConfigs ?? {};
|
|
15
|
+
configs[name] = function () {
|
|
16
|
+
return console.log((0, _utils.toObject)(properties));
|
|
17
|
+
};
|
|
18
|
+
window.__debugConfigs = configs;
|
|
19
|
+
return function () {
|
|
20
|
+
var configs = window.__debugConfigs ?? {};
|
|
21
|
+
delete configs[name];
|
|
22
|
+
window.__debugConfigs = configs;
|
|
23
|
+
};
|
|
24
|
+
}, [properties]);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=useDebugConfig.js.map
|
|
@@ -0,0 +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":[]}
|