@webiny/react-properties 5.44.0 → 5.44.1-beta.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.
|
@@ -8,8 +8,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.createConfigurableComponent = createConfigurableComponent;
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _debounce = _interopRequireDefault(require("lodash/debounce.js"));
|
|
11
12
|
var _reactComposition = require("@webiny/react-composition");
|
|
12
|
-
var
|
|
13
|
+
var _Properties = require("./Properties");
|
|
14
|
+
var _utils = require("./utils");
|
|
13
15
|
var _useDebugConfig = require("./useDebugConfig");
|
|
14
16
|
var createHOC = function createHOC(newChildren) {
|
|
15
17
|
return function (BaseComponent) {
|
|
@@ -75,17 +77,40 @@ function createConfigurableComponent(name) {
|
|
|
75
77
|
};
|
|
76
78
|
return /*#__PURE__*/_react.default.createElement(ViewContext.Provider, {
|
|
77
79
|
value: context
|
|
78
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
80
|
+
}, /*#__PURE__*/_react.default.createElement(_Properties.Properties, {
|
|
79
81
|
onChange: stateUpdater
|
|
80
|
-
}, /*#__PURE__*/_react.default.createElement(ConfigApplyPrimary, null), /*#__PURE__*/_react.default.createElement(ConfigApplySecondary, null), children));
|
|
82
|
+
}, /*#__PURE__*/_react.default.createElement(ConfigApplyPrimary, null), /*#__PURE__*/_react.default.createElement(DebounceRenderer, null, /*#__PURE__*/_react.default.createElement(ConfigApplySecondary, null), /*#__PURE__*/_react.default.createElement(DebounceRenderer, null, children))));
|
|
81
83
|
};
|
|
82
84
|
function useConfig() {
|
|
83
85
|
var _useContext = (0, _react.useContext)(ViewContext),
|
|
84
86
|
properties = _useContext.properties;
|
|
85
87
|
return (0, _react.useMemo)(function () {
|
|
86
|
-
return (0,
|
|
88
|
+
return (0, _utils.toObject)(properties);
|
|
87
89
|
}, [properties]);
|
|
88
90
|
}
|
|
91
|
+
var DebounceRenderer = function DebounceRenderer(_ref6) {
|
|
92
|
+
var children = _ref6.children;
|
|
93
|
+
var _useState3 = (0, _react.useState)(false),
|
|
94
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
95
|
+
render = _useState4[0],
|
|
96
|
+
setRender = _useState4[1];
|
|
97
|
+
var editorConfig = useConfig();
|
|
98
|
+
var debouncedRender = (0, _react.useMemo)(function () {
|
|
99
|
+
return (0, _debounce.default)(function () {
|
|
100
|
+
setRender(true);
|
|
101
|
+
}, 10);
|
|
102
|
+
}, [setRender]);
|
|
103
|
+
(0, _react.useEffect)(function () {
|
|
104
|
+
if (render) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
debouncedRender();
|
|
108
|
+
return function () {
|
|
109
|
+
debouncedRender.cancel();
|
|
110
|
+
};
|
|
111
|
+
}, [editorConfig]);
|
|
112
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, render ? children : null);
|
|
113
|
+
};
|
|
89
114
|
return {
|
|
90
115
|
WithConfig: WithConfig,
|
|
91
116
|
Config: Config,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactComposition","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_debounce","_interopRequireDefault","_reactComposition","_Properties","_utils","_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","DebounceRenderer","useConfig","_useContext","useContext","useMemo","toObject","_ref6","_useState3","_useState4","render","setRender","editorConfig","debouncedRender","debounce","cancel"],"sources":["createConfigurableComponent.tsx"],"sourcesContent":["import React, { useContext, useEffect, useMemo, useState } from \"react\";\nimport debounce from \"lodash/debounce.js\";\nimport type { Decorator } from \"@webiny/react-composition\";\nimport { Compose, makeDecoratable } from \"@webiny/react-composition\";\nimport type { GenericComponent } from \"@webiny/react-composition/types.js\";\nimport type { Property } from \"./Properties\";\nimport { Properties } from \"./Properties\";\nimport { toObject } from \"./utils\";\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 <DebounceRenderer>\n <ConfigApplySecondary />\n <DebounceRenderer>{children}</DebounceRenderer>\n </DebounceRenderer>\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 interface Props {\n children?: React.ReactNode;\n }\n\n const DebounceRenderer = ({ children }: Props) => {\n const [render, setRender] = useState(false);\n const editorConfig = useConfig();\n\n const debouncedRender = useMemo(() => {\n return debounce(() => {\n setRender(true);\n }, 10);\n }, [setRender]);\n\n useEffect(() => {\n if (render) {\n return;\n }\n\n debouncedRender();\n\n return () => {\n debouncedRender.cancel();\n };\n }, [editorConfig]);\n\n return <>{render ? children : null}</>;\n };\n\n return {\n WithConfig,\n Config,\n useConfig\n };\n}\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,iBAAA,GAAAH,OAAA;AAGA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,eAAA,GAAAN,OAAA;AAEA,IAAMO,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,oBACId,MAAA,CAAAe,OAAA,CAAAC,aAAA,CAACL,aAAa,QACTD,WAAW,EACXI,QACU,CAAC;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OAAO;IACHwB,UAAU,EAAVA,UAAU;IACVZ,MAAM,EAANA,MAAM;IACN6B,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.44.
|
|
3
|
+
"version": "5.44.1-beta.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,13 +11,14 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@types/react": "18.2.79",
|
|
14
|
-
"@webiny/react-composition": "5.44.
|
|
14
|
+
"@webiny/react-composition": "5.44.1-beta.1",
|
|
15
|
+
"lodash": "4.17.21",
|
|
15
16
|
"nanoid": "3.3.11",
|
|
16
17
|
"react": "18.2.0"
|
|
17
18
|
},
|
|
18
19
|
"devDependencies": {
|
|
19
20
|
"@testing-library/react": "15.0.7",
|
|
20
|
-
"@webiny/project-utils": "5.44.
|
|
21
|
+
"@webiny/project-utils": "5.44.1-beta.1",
|
|
21
22
|
"prettier": "2.8.8"
|
|
22
23
|
},
|
|
23
24
|
"publishConfig": {
|
|
@@ -28,5 +29,5 @@
|
|
|
28
29
|
"build": "node ../cli/bin.js run build",
|
|
29
30
|
"watch": "node ../cli/bin.js run watch"
|
|
30
31
|
},
|
|
31
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "ff5f085c417040291d39fdbe5153067f3a23ed86"
|
|
32
33
|
}
|