From 2d4f42bfad10c039dee3023ae885f6c8e488ebe0 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Thu, 30 Dec 2021 17:48:30 +0100 Subject: [PATCH] adjust WidgetsProps/WidgetsBinding/StoreActions typings #163 #164 --- .../demo/src/material-ui/material-ui-code.tsx | 8 +- .../src/material-ui/material-ui-custom.tsx | 11 +-- .../src/material-ui/material-ui-dnd-grid.tsx | 11 ++- .../demo/src/material-ui/material-ui-dnd.tsx | 2 +- .../src/material-ui/material-ui-split.tsx | 7 +- .../content/docs/ds-material/InfoRenderer.md | 2 +- packages/docs/src/content/docs/widgets.md | 10 +-- packages/ds-material/package-lock.json | 6 +- packages/ds-material/package.json | 2 +- .../src/Widgets/Accordions/Accordions.tsx | 4 +- .../src/Widgets/FormGroup/FormGroup.tsx | 4 +- .../src/Widgets/OptionsCheck/OptionsCheck.tsx | 2 +- .../ds-material/src/Widgets/Select/Select.tsx | 2 +- .../src/Widgets/Select/SelectMulti.tsx | 2 +- .../src/Widgets/SelectChips/SelectChips.tsx | 2 +- .../Widgets/TableAdvanced/TableAdvanced.tsx | 5 +- .../src/Widgets/TextField/TextField.tsx | 6 +- .../Widgets/TextFieldCell/TextFieldCell.tsx | 6 +- .../TextFieldDebounced/TextFieldDebounced.tsx | 6 +- packages/ds-material/src/widgetsBinding.tsx | 42 ++++----- packages/material-dnd/package-lock.json | 4 +- packages/material-dnd/package.json | 2 +- .../src/Widgets/DragDropArea/DragDropArea.tsx | 6 +- .../src/Widgets/DropArea/DropArea.tsx | 2 +- packages/material-editorjs/package-lock.json | 4 +- packages/ui-schema/package-lock.json | 4 +- packages/ui-schema/package.json | 2 +- .../ui-schema/src/PluginStack/Plugin.d.ts | 2 +- .../src/PluginStack/PluginStack.d.ts | 2 +- .../ui-schema/src/UIMeta/UIMetaProvider.tsx | 15 ++-- packages/ui-schema/src/UIStore/UIStore.d.ts | 8 +- .../src/UIStoreActions/UIStoreActions.ts | 6 +- packages/ui-schema/src/Widget.ts | 15 ++-- .../applyPluginStack/applyPluginStack.d.ts | 10 +-- .../scopeUpdaterValues.test.tsx | 4 +- .../storeScopeUpdater/scopeUpdaterValues.ts | 9 +- packages/ui-schema/src/storeUpdater/index.ts | 1 - .../src/storeUpdater/storeActionHandler.ts | 4 +- .../src/storeUpdater/storeUpdater.ts | 86 ++++++++++++++++++- .../src/storeUpdater/storeUpdaterCreate.ts | 79 ----------------- 40 files changed, 200 insertions(+), 205 deletions(-) delete mode 100644 packages/ui-schema/src/storeUpdater/storeUpdaterCreate.ts diff --git a/packages/demo/src/material-ui/material-ui-code.tsx b/packages/demo/src/material-ui/material-ui-code.tsx index cb66fcc7..1ddbba22 100644 --- a/packages/demo/src/material-ui/material-ui-code.tsx +++ b/packages/demo/src/material-ui/material-ui-code.tsx @@ -24,7 +24,7 @@ import themeDark from 'codemirror/theme/duotone-dark.css' import themeLight from 'codemirror/theme/duotone-light.css' import useTheme from '@material-ui/core/styles/useTheme' import { CodeSelectable } from '@ui-schema/material-code/CodeSelectable/CodeSelectable' -import { UIMetaProvider, WidgetProps, WidgetsBindingFactory, WithScalarValue } from '@ui-schema/ui-schema' +import { UIMetaProvider, WidgetsBindingFactory } from '@ui-schema/ui-schema' /*import themeMaterial from 'codemirror/theme/gruvbox-dark.css'; import themeDark from 'codemirror/theme/xq-dark.css'; import themeLight from 'codemirror/theme/xq-light.css';*/ @@ -36,11 +36,7 @@ const useStyle = (styles) => { return () => styles.unuse() }, [styles]) } -type CustomWidgetsBinding = WidgetsBindingFactory<{}, MuiWidgetsBindingTypes<{}>, MuiWidgetsBindingCustom<{}> & { - Code: React.ComponentType & WithScalarValue> - CodeSelectable: React.ComponentType & WithScalarValue> - //[k: string]: React.ComponentType & WithScalarValue> -}> +type CustomWidgetsBinding = WidgetsBindingFactory<{}, MuiWidgetsBindingTypes<{}>, MuiWidgetsBindingCustom<{}>> const customWidgets: CustomWidgetsBinding = {...widgets} as CustomWidgetsBinding customWidgets.custom = { ...widgets.custom, diff --git a/packages/demo/src/material-ui/material-ui-custom.tsx b/packages/demo/src/material-ui/material-ui-custom.tsx index 621dd5f3..1e3147db 100644 --- a/packages/demo/src/material-ui/material-ui-custom.tsx +++ b/packages/demo/src/material-ui/material-ui-custom.tsx @@ -28,12 +28,7 @@ import { ObjectGroup } from '@ui-schema/ui-schema/ObjectGroup' import { memo } from '@ui-schema/ui-schema/Utils/memo' import { useProgress, PROGRESS_DONE, PROGRESS_ERROR, PROGRESS_START } from '@ui-schema/ui-schema/UIApi' -type CustomWidgetsBinding = WidgetsBindingFactory<{}, MuiWidgetsBindingTypes<{}>, MuiWidgetsBindingCustom<{}> & { - Table: React.ComponentType - TableAdvanced: React.ComponentType - Stepper: React.ComponentType - Step: React.ComponentType -}> +type CustomWidgetsBinding = WidgetsBindingFactory<{}, MuiWidgetsBindingTypes<{}>, MuiWidgetsBindingCustom<{}>> const customWidgets: CustomWidgetsBinding = {...widgets} as CustomWidgetsBinding const pluginStack = [...customWidgets.pluginStack] // the referencing network handler should be at first position @@ -43,7 +38,7 @@ const pluginStack = [...customWidgets.pluginStack] pluginStack.splice(0, 0, ReferencingNetworkHandler) customWidgets.pluginStack = pluginStack -const CustomTable: React.ComponentType = ({widgets, ...props}) => { +const CustomTable: React.ComponentType> = ({widgets, ...props}) => { const customWidgets = React.useMemo(() => ({ ...widgets, types: { @@ -167,7 +162,7 @@ const FileUpload: React.ComponentType = ({storeKeys, on const WidgetFileUpload = applyPluginStack(extractValue(FileUpload)) -const CountrySelect: React.ComponentType & WithScalarValue> = ({schema, ...props}) => { +const CountrySelect: React.ComponentType & WithScalarValue> = ({schema, ...props}) => { const [countries, setCountries] = React.useState>(List()) const [loading, setLoading] = useProgress() diff --git a/packages/demo/src/material-ui/material-ui-dnd-grid.tsx b/packages/demo/src/material-ui/material-ui-dnd-grid.tsx index 73afed83..f7143966 100644 --- a/packages/demo/src/material-ui/material-ui-dnd-grid.tsx +++ b/packages/demo/src/material-ui/material-ui-dnd-grid.tsx @@ -7,7 +7,7 @@ import Label from '@material-ui/core/FormLabel' import FormControl from '@material-ui/core/FormControl' import Select from '@material-ui/core/Select' import Dashboard from './dashboard/Dashboard' -import { MuiWidgetsBindingCustom, MuiWidgetsBindingTypes, widgets } from '@ui-schema/ds-material' +import { MuiWidgetBinding, MuiWidgetsBindingCustom, MuiWidgetsBindingTypes, widgets } from '@ui-schema/ds-material' import { browserT } from '../t' import { MuiSchemaDebug } from './component/MuiSchemaDebug' import { isInvalid } from '@ui-schema/ui-schema/ValidityReporter/isInvalid' @@ -27,8 +27,8 @@ import { storeUpdater, UIMetaProvider, UIStoreProvider, - UIStoreType, - WidgetsBindingFactory, + UIStoreType, WidgetProps, + WidgetsBindingFactory, WithOnChange, } from '@ui-schema/ui-schema' import { OrderedMap } from 'immutable' import { RichContent, RichContentInline, RichContentPane } from '@ui-schema/material-slate' @@ -43,7 +43,10 @@ import { DragDropBlockSelector } from '@ui-schema/material-dnd/DragDropBlockSele import { DragDropBlockComponentsBinding } from '@ui-schema/material-dnd/DragDropBlock' import { DropArea } from '@ui-schema/material-dnd/Widgets/DropArea' -export type CustomWidgetsBinding = WidgetsBindingFactory, MuiWidgetsBindingCustom<{}>> +export type CustomWidgetsBinding = WidgetsBindingFactory, MuiWidgetsBindingCustom<{}> & { + DragDropArea: React.ComponentType & WithOnChange> +}> + const customWidgets: CustomWidgetsBinding = { ...widgets, DndBlockSelector: DragDropBlockSelector, diff --git a/packages/demo/src/material-ui/material-ui-dnd.tsx b/packages/demo/src/material-ui/material-ui-dnd.tsx index de9303fd..0eac686f 100644 --- a/packages/demo/src/material-ui/material-ui-dnd.tsx +++ b/packages/demo/src/material-ui/material-ui-dnd.tsx @@ -24,7 +24,7 @@ import { DragDropSpec } from '@ui-schema/material-dnd/DragDropSpec' import { SortableList } from '@ui-schema/material-dnd/Widgets/SortableList/SortableList' type CustomWidgetsBinding = WidgetsBindingFactory<{}, MuiWidgetsBindingTypes<{}>, MuiWidgetsBindingCustom<{}> & { - SortableList: React.ComponentType & WithScalarValue> + SortableList: React.ComponentType & WithScalarValue> }> const customWidgets: CustomWidgetsBinding = {...widgets} as CustomWidgetsBinding customWidgets.custom = { diff --git a/packages/demo/src/material-ui/material-ui-split.tsx b/packages/demo/src/material-ui/material-ui-split.tsx index 0f6204fe..52a76290 100644 --- a/packages/demo/src/material-ui/material-ui-split.tsx +++ b/packages/demo/src/material-ui/material-ui-split.tsx @@ -30,12 +30,7 @@ import { InjectSplitSchemaPlugin, InjectSplitSchemaRootContext } from '@ui-schem import { MuiSchemaDebug } from './component/MuiSchemaDebug' import { OrderedMap } from 'immutable' -type CustomWidgetsBinding = WidgetsBindingFactory<{}, MuiWidgetsBindingTypes<{}>, MuiWidgetsBindingCustom<{}> & { - Table: React.ComponentType - TableAdvanced: React.ComponentType - Stepper: React.ComponentType - Step: React.ComponentType -}> +type CustomWidgetsBinding = WidgetsBindingFactory<{}, MuiWidgetsBindingTypes<{}>, MuiWidgetsBindingCustom<{}>> const customWidgets: CustomWidgetsBinding = {...widgets} as CustomWidgetsBinding const pluginStack = [...customWidgets.pluginStack] // the referencing network handler should be at first position diff --git a/packages/docs/src/content/docs/ds-material/InfoRenderer.md b/packages/docs/src/content/docs/ds-material/InfoRenderer.md index 07d0a0a0..b200cd41 100644 --- a/packages/docs/src/content/docs/ds-material/InfoRenderer.md +++ b/packages/docs/src/content/docs/ds-material/InfoRenderer.md @@ -60,7 +60,7 @@ import { WidgetProps, WithScalarValue } from '@ui-schema/ui-schema' import { MuiWidgetBinding } from '@ui-schema/ds-material/widgetsBinding' import { InfoRenderer } from '@ui-schema/ds-material/Component/InfoRenderer' -export const Widget: React.ComponentType & WithScalarValue> = ( +export const Widget: React.ComponentType & WithScalarValue> = ( { widgets, schema, valid, errors, storeKeys, } diff --git a/packages/docs/src/content/docs/widgets.md b/packages/docs/src/content/docs/widgets.md index 6a521b3e..8a10ae68 100644 --- a/packages/docs/src/content/docs/widgets.md +++ b/packages/docs/src/content/docs/widgets.md @@ -244,16 +244,16 @@ import React from "react"; import { widgets, MuiWidgetBinding, MuiWidgetsBindingTypes, MuiWidgetsBindingCustom } from "@ui-schema/ds-material/widgetsBinding"; import { WidgetProps, WidgetsBindingFactory, WithScalarValue } from "@ui-schema/ui-schema"; -const CustomNumberRenderer = (props: React.ComponentType & WithScalarValue>) => /* todo: implement */ null; -const CustomSelect = (props: React.ComponentType & WithScalarValue>) => /* todo: implement */ null; +const CustomNumberRenderer = (props: React.ComponentType & WithScalarValue>) => /* todo: implement */ null; +const CustomSelect = (props: React.ComponentType & WithScalarValue>) => /* todo: implement */ null; export interface CustomWidgetsType { types: { - integer: React.ComponentType & WithScalarValue> - number: React.ComponentType & WithScalarValue> + integer: React.ComponentType & WithScalarValue> + number: React.ComponentType & WithScalarValue> } custom: { - CustomSelect: React.ComponentType & WithScalarValue> + CustomSelect: React.ComponentType & WithScalarValue> } } diff --git a/packages/ds-material/package-lock.json b/packages/ds-material/package-lock.json index f849462c..814f45c9 100644 --- a/packages/ds-material/package-lock.json +++ b/packages/ds-material/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ui-schema/ds-material", - "version": "0.3.0-alpha.6", + "version": "0.3.0-alpha.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ui-schema/ds-material", - "version": "0.3.0-alpha.6", + "version": "0.3.0-alpha.7", "license": "MIT", "dependencies": { "react-uid": "^2.2.0" @@ -33,7 +33,7 @@ }, "../ui-schema": { "name": "@ui-schema/ui-schema", - "version": "0.3.0-alpha.8", + "version": "0.3.0-alpha.9", "license": "MIT", "peer": true, "devDependencies": { diff --git a/packages/ds-material/package.json b/packages/ds-material/package.json index 27cf5cc7..32959b86 100644 --- a/packages/ds-material/package.json +++ b/packages/ds-material/package.json @@ -1,6 +1,6 @@ { "name": "@ui-schema/ds-material", - "version": "0.3.0-alpha.6", + "version": "0.3.0-alpha.7", "description": "Material-UI Binding for UI-Schema", "homepage": "https://ui-schema.bemit.codes", "author": "Michael Becker ", diff --git a/packages/ds-material/src/Widgets/Accordions/Accordions.tsx b/packages/ds-material/src/Widgets/Accordions/Accordions.tsx index a4dffa10..bc6c4be4 100644 --- a/packages/ds-material/src/Widgets/Accordions/Accordions.tsx +++ b/packages/ds-material/src/Widgets/Accordions/Accordions.tsx @@ -15,7 +15,7 @@ export interface AccordionStackBaseProps { setOpen: (handler: (ownKey: string) => string) => void } -const AccordionStackBase: React.ComponentType & AccordionStackBaseProps> = (props) => { +const AccordionStackBase: React.ComponentType & AccordionStackBaseProps> = (props) => { const uid = useUID() const { storeKeys, schema, @@ -64,7 +64,7 @@ const AccordionStackBase: React.ComponentType export const AccordionStack = memo(AccordionStackBase) -export const AccordionsRendererBase = = WidgetProps<{}, MuiWidgetBinding>>( +export const AccordionsRendererBase = = WidgetProps>( { schema, storeKeys, level, errors, showValidity, diff --git a/packages/ds-material/src/Widgets/FormGroup/FormGroup.tsx b/packages/ds-material/src/Widgets/FormGroup/FormGroup.tsx index 30b71212..32eb2b3e 100644 --- a/packages/ds-material/src/Widgets/FormGroup/FormGroup.tsx +++ b/packages/ds-material/src/Widgets/FormGroup/FormGroup.tsx @@ -9,7 +9,7 @@ import { WidgetProps } from '@ui-schema/ui-schema/Widget' import { TransTitle } from '@ui-schema/ui-schema/Translate/TransTitle' import { MuiWidgetBinding } from '@ui-schema/ds-material/widgetsBinding' -export const FormGroupBase: React.ComponentType & WithValue> = (props) => { +export const FormGroupBase: React.ComponentType & WithValue> = (props) => { const {storeKeys, ownKey, widgets} = props const {WidgetRenderer} = widgets const {spacing} = useTheme() @@ -41,4 +41,4 @@ export const FormGroupBase: React.ComponentType } -export const FormGroup: React.ComponentType> = extractValue(memo(FormGroupBase)) +export const FormGroup: React.ComponentType> = extractValue(memo(FormGroupBase)) diff --git a/packages/ds-material/src/Widgets/OptionsCheck/OptionsCheck.tsx b/packages/ds-material/src/Widgets/OptionsCheck/OptionsCheck.tsx index 793ab43e..d6de1ce1 100644 --- a/packages/ds-material/src/Widgets/OptionsCheck/OptionsCheck.tsx +++ b/packages/ds-material/src/Widgets/OptionsCheck/OptionsCheck.tsx @@ -85,7 +85,7 @@ export interface OptionsCheckRendererProps { row?: boolean } -export const OptionsCheck: React.ComponentType & OptionsCheckRendererProps> = ( +export const OptionsCheck: React.ComponentType & OptionsCheckRendererProps> = ( { ownKey, schema, storeKeys, showValidity, valid, required, errors, row, widgets, diff --git a/packages/ds-material/src/Widgets/Select/Select.tsx b/packages/ds-material/src/Widgets/Select/Select.tsx index a15ea2c6..e8a800dc 100644 --- a/packages/ds-material/src/Widgets/Select/Select.tsx +++ b/packages/ds-material/src/Widgets/Select/Select.tsx @@ -10,7 +10,7 @@ import { ValidityHelperText } from '@ui-schema/ds-material/Component/LocaleHelpe import { getTranslatableEnum } from '@ui-schema/ui-schema/Translate' import { MuiWidgetBinding } from '@ui-schema/ds-material/widgetsBinding' -export const Select: React.ComponentType & WithScalarValue> = ( +export const Select: React.ComponentType & WithScalarValue> = ( { storeKeys, ownKey, schema, value, onChange, showValidity, valid, required, errors, t, diff --git a/packages/ds-material/src/Widgets/Select/SelectMulti.tsx b/packages/ds-material/src/Widgets/Select/SelectMulti.tsx index a5f86274..1004eb77 100644 --- a/packages/ds-material/src/Widgets/Select/SelectMulti.tsx +++ b/packages/ds-material/src/Widgets/Select/SelectMulti.tsx @@ -10,7 +10,7 @@ import { ValidityHelperText } from '@ui-schema/ds-material/Component/LocaleHelpe import { sortScalarList } from '@ui-schema/ui-schema/Utils/sortScalarList' import { MuiWidgetBinding } from '@ui-schema/ds-material/widgetsBinding' -export const SelectMultiBase: React.ComponentType & WithValue> = ( +export const SelectMultiBase: React.ComponentType & WithValue> = ( { storeKeys, ownKey, schema, value, onChange, showValidity, valid, required, errors, t, diff --git a/packages/ds-material/src/Widgets/SelectChips/SelectChips.tsx b/packages/ds-material/src/Widgets/SelectChips/SelectChips.tsx index 49f51c03..98c2732f 100644 --- a/packages/ds-material/src/Widgets/SelectChips/SelectChips.tsx +++ b/packages/ds-material/src/Widgets/SelectChips/SelectChips.tsx @@ -8,7 +8,7 @@ import Box from '@material-ui/core/Box' import { MuiWidgetBinding } from '@ui-schema/ds-material/widgetsBinding' import { List, Map, OrderedMap } from 'immutable' -export const SelectChipsBase: React.ComponentType & WithValue> = ( +export const SelectChipsBase: React.ComponentType & WithValue> = ( { storeKeys, ownKey, schema, value, onChange, showValidity, errors, required, diff --git a/packages/ds-material/src/Widgets/TableAdvanced/TableAdvanced.tsx b/packages/ds-material/src/Widgets/TableAdvanced/TableAdvanced.tsx index 65bb0efa..97cb369d 100644 --- a/packages/ds-material/src/Widgets/TableAdvanced/TableAdvanced.tsx +++ b/packages/ds-material/src/Widgets/TableAdvanced/TableAdvanced.tsx @@ -1,7 +1,8 @@ import React from 'react' import { extractValue, memo, PluginStack, StoreSchemaType, WidgetProps, WithValue } from '@ui-schema/ui-schema' +import { MuiWidgetBinding } from '@ui-schema/ds-material/widgetsBinding' -export const TableAdvancedBase: React.ComponentType = ( +export const TableAdvancedBase: React.ComponentType & WithValue> = ( { showValidity, schema, level, ...props } @@ -21,4 +22,4 @@ export const TableAdvancedBase: React.ComponentType = ( } -export const TableAdvanced: React.ComponentType = extractValue(memo(TableAdvancedBase)) +export const TableAdvanced: React.ComponentType> = extractValue(memo(TableAdvancedBase)) diff --git a/packages/ds-material/src/Widgets/TextField/TextField.tsx b/packages/ds-material/src/Widgets/TextField/TextField.tsx index c351217d..9d8467aa 100644 --- a/packages/ds-material/src/Widgets/TextField/TextField.tsx +++ b/packages/ds-material/src/Widgets/TextField/TextField.tsx @@ -54,7 +54,7 @@ export interface NumberRendererProps extends StringRendererBaseProps { steps?: number | 'any' } -export const StringRenderer =

= WidgetProps<{}, MuiWidgetBinding>>( +export const StringRenderer =

= WidgetProps>( { type, multiline, @@ -160,7 +160,7 @@ export const StringRenderer =

= Wid } -export const TextRenderer =

= WidgetProps<{}, MuiWidgetBinding>>({schema, ...props}: P & WithScalarValue & TextRendererProps): React.ReactElement => { +export const TextRenderer =

= WidgetProps>({schema, ...props}: P & WithScalarValue & TextRendererProps): React.ReactElement => { return = Widge /> } -export const NumberRenderer =

= WidgetProps<{}, MuiWidgetBinding>>(props: P & WithScalarValue & NumberRendererProps): React.ReactElement => { +export const NumberRenderer =

= WidgetProps>(props: P & WithScalarValue & NumberRendererProps): React.ReactElement => { const {schema, inputProps: inputPropsProps = {}, steps = 'any'} = props const schemaType = schema.get('type') as string | undefined const inputProps = React.useMemo(() => { diff --git a/packages/ds-material/src/Widgets/TextFieldCell/TextFieldCell.tsx b/packages/ds-material/src/Widgets/TextFieldCell/TextFieldCell.tsx index 206082ff..92bc5567 100644 --- a/packages/ds-material/src/Widgets/TextFieldCell/TextFieldCell.tsx +++ b/packages/ds-material/src/Widgets/TextFieldCell/TextFieldCell.tsx @@ -29,7 +29,7 @@ export interface StringRendererCellProps { labelledBy?: string } -export const StringRendererCell: React.ComponentType & WithScalarValue & StringRendererCellProps> = ( +export const StringRendererCell: React.ComponentType & WithScalarValue & StringRendererCellProps> = ( { type, multiline, rows, rowsMax, @@ -147,7 +147,7 @@ export const StringRendererCell: React.ComponentType } -export const TextRendererCell: React.ComponentType & WithScalarValue & StringRendererCellProps> = ({schema, ...props}) => { +export const TextRendererCell: React.ComponentType & WithScalarValue & StringRendererCellProps> = ({schema, ...props}) => { return } -export const NumberRendererCell: React.ComponentType & WithScalarValue & StringRendererCellProps> = (props) => { +export const NumberRendererCell: React.ComponentType & WithScalarValue & StringRendererCellProps> = (props) => { return = WidgetProps<{}, MuiWidgetBinding>>( +export const StringRendererDebounced =

= WidgetProps>( { type, multiline, @@ -158,7 +158,7 @@ export const StringRendererDebounced =

} -export const TextRendererDebounced =

= WidgetProps<{}, MuiWidgetBinding>>( +export const TextRendererDebounced =

= WidgetProps>( { schema, ...props @@ -181,7 +181,7 @@ export const TextRendererDebounced =

} -export const NumberRendererDebounced =

= WidgetProps<{}, MuiWidgetBinding>>(props: P & WithScalarValue & Omit & StringRendererDebouncedProps): React.ReactElement => { +export const NumberRendererDebounced =

= WidgetProps>(props: P & WithScalarValue & Omit & StringRendererDebouncedProps): React.ReactElement => { const {schema, inputProps: inputPropsProps = {}, steps = 'any'} = props const schemaType = schema.get('type') as string | undefined const inputProps = React.useMemo(() => { diff --git a/packages/ds-material/src/widgetsBinding.tsx b/packages/ds-material/src/widgetsBinding.tsx index 04c42c87..b9522b54 100644 --- a/packages/ds-material/src/widgetsBinding.tsx +++ b/packages/ds-material/src/widgetsBinding.tsx @@ -14,7 +14,7 @@ import { pluginStack } from './pluginStack' import { WidgetRenderer } from '@ui-schema/ui-schema/WidgetRenderer' import { validators } from '@ui-schema/ui-schema/Validators/validators' import { CardRenderer, FormGroup, LabelBox } from '@ui-schema/ds-material/Widgets' -import { WidgetProps, WidgetsBindingFactory, WithScalarValue } from '@ui-schema/ui-schema' +import { WidgetProps, WidgetsBindingFactory, WidgetType, WithScalarValue } from '@ui-schema/ui-schema' import { InfoRendererProps } from '@ui-schema/ds-material/Component/InfoRenderer' const MyFallbackComponent: React.ComponentType<{ @@ -30,28 +30,30 @@ const MyFallbackComponent: React.ComponentType<{ ) export interface MuiWidgetsBindingTypes { - string: React.ComponentType & WithScalarValue> - boolean: React.ComponentType & WithScalarValue> - number: React.ComponentType & WithScalarValue> - integer: React.ComponentType & WithScalarValue> + string: React.ComponentType & C & WithScalarValue> + boolean: React.ComponentType & C & WithScalarValue> + number: React.ComponentType & C & WithScalarValue> + integer: React.ComponentType & C & WithScalarValue> } export interface MuiWidgetsBindingCustom { - Accordions: React.ComponentType> - Text: React.ComponentType & WithScalarValue> - StringIcon: React.ComponentType & WithScalarValue> - TextIcon: React.ComponentType & WithScalarValue> - NumberIcon: React.ComponentType & WithScalarValue> - NumberSlider: React.ComponentType> - SimpleList: React.ComponentType> - GenericList: React.ComponentType> - OptionsCheck: React.ComponentType> - OptionsRadio: React.ComponentType> - Select: React.ComponentType & WithScalarValue> - SelectMulti: React.ComponentType> - Card: React.ComponentType> - LabelBox: React.ComponentType> - FormGroup: React.ComponentType> + Accordions: React.ComponentType & C> + Text: React.ComponentType & C & WithScalarValue> + StringIcon: React.ComponentType & C & WithScalarValue> + TextIcon: React.ComponentType & C & WithScalarValue> + NumberIcon: React.ComponentType & C & WithScalarValue> + NumberSlider: React.ComponentType & C> + SimpleList: React.ComponentType & C> + GenericList: React.ComponentType & C> + OptionsCheck: React.ComponentType & C> + OptionsRadio: React.ComponentType & C> + Select: React.ComponentType & C & WithScalarValue> + SelectMulti: React.ComponentType & C> + Card: React.ComponentType & C> + LabelBox: React.ComponentType & C> + FormGroup: React.ComponentType & C> + + [key: string]: WidgetType | WidgetType } export interface MuiWidgetBindingExtra { diff --git a/packages/material-dnd/package-lock.json b/packages/material-dnd/package-lock.json index 8ce01166..7b97a717 100644 --- a/packages/material-dnd/package-lock.json +++ b/packages/material-dnd/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ui-schema/material-dnd", - "version": "0.0.9", + "version": "0.0.10", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ui-schema/material-dnd", - "version": "0.0.9", + "version": "0.0.10", "license": "MIT", "dependencies": { "react-uid": "^2.2.0" diff --git a/packages/material-dnd/package.json b/packages/material-dnd/package.json index 5773d064..68ffc5ae 100644 --- a/packages/material-dnd/package.json +++ b/packages/material-dnd/package.json @@ -1,6 +1,6 @@ { "name": "@ui-schema/material-dnd", - "version": "0.0.9", + "version": "0.0.10", "description": "Drag and Drop Tools and Widgets for UI-Schema with Material-UI", "homepage": "https://ui-schema.bemit.codes", "author": "Michael Becker ", diff --git a/packages/material-dnd/src/Widgets/DragDropArea/DragDropArea.tsx b/packages/material-dnd/src/Widgets/DragDropArea/DragDropArea.tsx index 9d1f3f51..a4dd9c6e 100644 --- a/packages/material-dnd/src/Widgets/DragDropArea/DragDropArea.tsx +++ b/packages/material-dnd/src/Widgets/DragDropArea/DragDropArea.tsx @@ -1,6 +1,6 @@ import React from 'react' -import { memo, StoreKeys, Trans, TransTitle, UIStoreActionListItemAdd, UIStoreActionScoped, WidgetProps, WidgetsBindingFactory, WithOnChange } from '@ui-schema/ui-schema' -import { AccessTooltipIcon } from '@ui-schema/ds-material' +import { memo, StoreKeys, Trans, TransTitle, UIStoreActionListItemAdd, UIStoreActionScoped, WidgetProps, WithOnChange } from '@ui-schema/ui-schema' +import { AccessTooltipIcon, MuiWidgetBinding } from '@ui-schema/ds-material' import IconButton from '@material-ui/core/IconButton' import Add from '@material-ui/icons/Add' import Box from '@material-ui/core/Box' @@ -17,7 +17,7 @@ export const DragDropAreaBase = ( { widgets, block, ...props - }: WidgetProps<{}, WidgetsBindingFactory> & WithOnChange & WithDndBlock + }: WidgetProps & WithOnChange & WithDndBlock ): React.ReactElement => { const [showSelector, setShowSelector] = React.useState(false) const {schema, ownKey, storeKeys, onChange, required} = props diff --git a/packages/material-dnd/src/Widgets/DropArea/DropArea.tsx b/packages/material-dnd/src/Widgets/DropArea/DropArea.tsx index 810d7832..a310eeb2 100644 --- a/packages/material-dnd/src/Widgets/DropArea/DropArea.tsx +++ b/packages/material-dnd/src/Widgets/DropArea/DropArea.tsx @@ -17,7 +17,7 @@ export const DropAreaBase = ( { widgets, ...props - }: WidgetProps<{}, WidgetsBindingFactory> & WithOnChange + }: WidgetProps> & WithOnChange ): React.ReactElement => { const [showSelector, setShowSelector] = React.useState(false) const {schema, ownKey, storeKeys, onChange, required} = props diff --git a/packages/material-editorjs/package-lock.json b/packages/material-editorjs/package-lock.json index 584b19e7..573324ee 100644 --- a/packages/material-editorjs/package-lock.json +++ b/packages/material-editorjs/package-lock.json @@ -34,7 +34,7 @@ }, "../ds-material": { "name": "@ui-schema/ds-material", - "version": "0.3.0-alpha.6", + "version": "0.3.0-alpha.7", "license": "MIT", "peer": true, "dependencies": { @@ -66,7 +66,7 @@ }, "../ui-schema": { "name": "@ui-schema/ui-schema", - "version": "0.3.0-alpha.8", + "version": "0.3.0-alpha.9", "license": "MIT", "peer": true, "devDependencies": { diff --git a/packages/ui-schema/package-lock.json b/packages/ui-schema/package-lock.json index 53c2b7f7..0c7e9dce 100644 --- a/packages/ui-schema/package-lock.json +++ b/packages/ui-schema/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ui-schema/ui-schema", - "version": "0.3.0-alpha.8", + "version": "0.3.0-alpha.9", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@ui-schema/ui-schema", - "version": "0.3.0-alpha.8", + "version": "0.3.0-alpha.9", "license": "MIT", "devDependencies": { "@types/react": "^16.8.6 || ^17.0.0", diff --git a/packages/ui-schema/package.json b/packages/ui-schema/package.json index edf7997a..8a0a6377 100644 --- a/packages/ui-schema/package.json +++ b/packages/ui-schema/package.json @@ -1,6 +1,6 @@ { "name": "@ui-schema/ui-schema", - "version": "0.3.0-alpha.8", + "version": "0.3.0-alpha.9", "description": "UI and Form Generator for React using JSON-Schema for any Design-System", "homepage": "https://ui-schema.bemit.codes", "author": "Michael Becker ", diff --git a/packages/ui-schema/src/PluginStack/Plugin.d.ts b/packages/ui-schema/src/PluginStack/Plugin.d.ts index 7ece3f7f..6024cec3 100644 --- a/packages/ui-schema/src/PluginStack/Plugin.d.ts +++ b/packages/ui-schema/src/PluginStack/Plugin.d.ts @@ -4,7 +4,7 @@ import { List } from 'immutable' import { onErrors } from '@ui-schema/ui-schema/ValidatorErrors' import { WidgetsBindingFactory } from '@ui-schema/ui-schema/WidgetsBinding' -export interface PluginProps extends WidgetProps { +export interface PluginProps extends WidgetProps { // must be transformed from list to boolean `required` by a plugin requiredList?: List // current number of plugin in the stack diff --git a/packages/ui-schema/src/PluginStack/PluginStack.d.ts b/packages/ui-schema/src/PluginStack/PluginStack.d.ts index 353b0937..0860c180 100644 --- a/packages/ui-schema/src/PluginStack/PluginStack.d.ts +++ b/packages/ui-schema/src/PluginStack/PluginStack.d.ts @@ -37,7 +37,7 @@ export function PluginStack(next: number, widgets: W): ComponentPluginType | React.ComponentType> +export function getNextPlugin(next: number, widgets: W): ComponentPluginType | React.ComponentType> export function NextPluginRenderer

(props: P): React.ReactElement

diff --git a/packages/ui-schema/src/UIMeta/UIMetaProvider.tsx b/packages/ui-schema/src/UIMeta/UIMetaProvider.tsx index d55269b6..8f4d3c9d 100644 --- a/packages/ui-schema/src/UIMeta/UIMetaProvider.tsx +++ b/packages/ui-schema/src/UIMeta/UIMetaProvider.tsx @@ -7,26 +7,29 @@ import { WidgetsBindingFactory } from '@ui-schema/ui-schema/WidgetsBinding' // @ts-ignore const UIMetaContextObj = React.createContext({}) -export interface UIMetaContextData { +export interface UIMetaContext { widgets: W t: Translator } -export type UIMetaContext = C & UIMetaContextData +//export type UIMetaContext = C & UIMetaContextData +/*export interface UIMetaContext extends UIMetaContextData { -export function UIMetaProvider({children, ...props}: React.PropsWithChildren>): React.ReactElement { +}*/ + +export function UIMetaProvider({children, ...props}: React.PropsWithChildren & C>): React.ReactElement { return {children} } -export const useUIMeta = (): UIMetaContext => { +export const useUIMeta = (): UIMetaContext & C => { // @ts-ignore - return React.useContext>(UIMetaContextObj) + return React.useContext>(UIMetaContextObj) } export const withUIMeta =

( - Component: React.ComponentType

> + Component: React.ComponentType

& C> ): React.ComponentType

=> { const WithUIMeta = (p: P) => { const meta = useUIMeta() diff --git a/packages/ui-schema/src/UIStore/UIStore.d.ts b/packages/ui-schema/src/UIStore/UIStore.d.ts index b0888bc3..d327634f 100644 --- a/packages/ui-schema/src/UIStore/UIStore.d.ts +++ b/packages/ui-schema/src/UIStore/UIStore.d.ts @@ -1,6 +1,6 @@ import { OrderedMap, Map, List, RecordOf } from 'immutable' import { SchemaTypesType } from '@ui-schema/ui-schema/CommonTypings' -import { StoreActionDefinite, UIStoreActionScoped, UIStoreUpdaterData } from '@ui-schema/ui-schema/UIStoreActions' +import { UIStoreActions, UIStoreActionScoped, UIStoreUpdaterData } from '@ui-schema/ui-schema/UIStoreActions' export type Values = List | string | number | boolean | Map | OrderedMap export type ValuesJS = any[] | string | number | boolean | Object @@ -38,10 +38,10 @@ export const UIStore: UIStoreType export type UIStoreUpdaterFn = (data: D) => D -//export type OnChangeHandlerAction = UIStoreActionScoped[] | UIStoreActionScoped +//export type OnChangeHandlerAction = UIStoreActionScoped[] | UIStoreActionScoped -export type onChangeHandler = ( - actions: (UIStoreActionScoped & A)[] | (UIStoreActionScoped & A) +export type onChangeHandler = ( + actions: A[] | A ) => R // UIMetaContext diff --git a/packages/ui-schema/src/UIStoreActions/UIStoreActions.ts b/packages/ui-schema/src/UIStoreActions/UIStoreActions.ts index fd14270b..f081c084 100644 --- a/packages/ui-schema/src/UIStoreActions/UIStoreActions.ts +++ b/packages/ui-schema/src/UIStoreActions/UIStoreActions.ts @@ -7,13 +7,13 @@ export interface UIStoreUpdaterData { meta?: any } -export type UIStoreActionScoped = { +export type UIStoreActionScoped = { storeKeys: StoreKeys scopes: (keyof D)[] effect?: (newData: D, newStore: S) => void } -export interface UIStoreAction { +export interface UIStoreAction extends UIStoreActionScoped { type: string schema?: StoreSchemaType required?: boolean @@ -52,7 +52,7 @@ export interface UIStoreActionSet = - React.ComponentType

> | - React.ComponentType

& Pick> | - React.ComponentType

& WithScalarValue> +export type WidgetOverrideType = + React.ComponentType

& C> | + React.ComponentType

& C & WithOnChange> | + React.ComponentType

& C & WithScalarValue> -export type WidgetType = WidgetOverrideType<{}, C, W> +export type WidgetType = WidgetOverrideType /** * Base widget props which are expected to exist no matter which data "type" the widget is for @@ -18,8 +18,7 @@ export type WidgetType extends UIMetaContext { +export interface WidgetProps extends UIMetaContext { // the current schema level schema: StoreSchemaType // `parentSchema` must only be `undefined` in the root level of a schema diff --git a/packages/ui-schema/src/applyPluginStack/applyPluginStack.d.ts b/packages/ui-schema/src/applyPluginStack/applyPluginStack.d.ts index 52061063..a058746d 100644 --- a/packages/ui-schema/src/applyPluginStack/applyPluginStack.d.ts +++ b/packages/ui-schema/src/applyPluginStack/applyPluginStack.d.ts @@ -5,10 +5,10 @@ import { UIMetaContext } from '@ui-schema/ui-schema/UIMeta' import { WithValue } from '@ui-schema/ui-schema/UIStore' // todo: add also generic widgets here? -export type AppliedPluginStackProps = WidgetProps, C extends {} = {}> = - Omit | keyof WithValue | 'level'> - & Partial> +export type AppliedPluginStackProps = + Omit + & Partial & Partial> -export function applyPluginStack = WidgetProps>(CustomWidget: React.ComponentType): - React.ComponentType> +export function applyPluginStack(CustomWidget: React.ComponentType): + React.ComponentType> diff --git a/packages/ui-schema/src/storeScopeUpdater/scopeUpdaterValues.test.tsx b/packages/ui-schema/src/storeScopeUpdater/scopeUpdaterValues.test.tsx index 9b939f69..634b58ae 100644 --- a/packages/ui-schema/src/storeScopeUpdater/scopeUpdaterValues.test.tsx +++ b/packages/ui-schema/src/storeScopeUpdater/scopeUpdaterValues.test.tsx @@ -9,7 +9,7 @@ import { } from '@testing-library/jest-dom/matchers' import { List, Map, OrderedMap } from 'immutable' import { UIStore, StoreKeys, UIStoreType, createEmptyStore } from '@ui-schema/ui-schema/UIStore' -import { StoreActionDefinite } from '@ui-schema/ui-schema/UIStoreActions' +import { UIStoreActions } from '@ui-schema/ui-schema/UIStoreActions' import { scopeUpdaterValues } from '@ui-schema/ui-schema/storeScopeUpdater/scopeUpdaterValues' expect.extend({toBeInTheDocument, toHaveClass}) @@ -273,7 +273,7 @@ describe('scopeUpdaterValues', () => { ])('scopeUpdaterValues(%j, %s, %j, %j): %j', ( store: S, storeKeys: StoreKeys, newValue: any, - action: StoreActionDefinite, + action: UIStoreActions, expected: any ) => { const r = scopeUpdaterValues(store, storeKeys, newValue, action) diff --git a/packages/ui-schema/src/storeScopeUpdater/scopeUpdaterValues.ts b/packages/ui-schema/src/storeScopeUpdater/scopeUpdaterValues.ts index c8e1082d..c2efdfaf 100644 --- a/packages/ui-schema/src/storeScopeUpdater/scopeUpdaterValues.ts +++ b/packages/ui-schema/src/storeScopeUpdater/scopeUpdaterValues.ts @@ -1,13 +1,14 @@ import { - prependKey, shouldDeleteOnEmpty, StoreKeys, + prependKey, shouldDeleteOnEmpty, StoreKeys, UIStoreType, } from '@ui-schema/ui-schema/UIStore' import { List, Map } from 'immutable' -import { SchemaTypesType } from '@ui-schema/ui-schema' -import { ScopeOnChangeHandler } from '@ui-schema/ui-schema/storeUpdater' +import { SchemaTypesType, UIStoreActions } from '@ui-schema/ui-schema' import { updateStoreScope } from '@ui-schema/ui-schema/storeScopeUpdater/updateStoreScope' import { storeBuildScopeTree } from '@ui-schema/ui-schema/storeBuildScopeTree' -export const scopeUpdaterValues: ScopeOnChangeHandler = (store, storeKeys, newValue, action) => { +export const scopeUpdaterValues = ( + store: S, storeKeys: StoreKeys, newValue: any, action: A +): S => { //if (typeof oldValue === 'undefined') { // initializing the tree for correct data types // https://github.com/ui-schema/ui-schema/issues/119 diff --git a/packages/ui-schema/src/storeUpdater/index.ts b/packages/ui-schema/src/storeUpdater/index.ts index e217ac87..3a22e781 100644 --- a/packages/ui-schema/src/storeUpdater/index.ts +++ b/packages/ui-schema/src/storeUpdater/index.ts @@ -1,3 +1,2 @@ export * from './storeActionHandler' export * from './storeUpdater' -export * from './storeUpdaterCreate' diff --git a/packages/ui-schema/src/storeUpdater/storeActionHandler.ts b/packages/ui-schema/src/storeUpdater/storeActionHandler.ts index 9092f352..fe31fe55 100644 --- a/packages/ui-schema/src/storeUpdater/storeActionHandler.ts +++ b/packages/ui-schema/src/storeUpdater/storeActionHandler.ts @@ -2,9 +2,9 @@ import { UIStoreUpdaterFn } from '@ui-schema/ui-schema/UIStore' import { List, Map, OrderedMap } from 'immutable' import { moveItem } from '@ui-schema/ui-schema/Utils/moveItem' import { SchemaTypesType } from '@ui-schema/ui-schema/CommonTypings' -import { StoreActionDefinite, UIStoreUpdaterData } from '@ui-schema/ui-schema/UIStoreActions' +import { UIStoreActions, UIStoreUpdaterData } from '@ui-schema/ui-schema/UIStoreActions' -export const actionHandler = (action: A): UIStoreUpdaterFn | D => { +export const actionHandler = (action: A): UIStoreUpdaterFn | D => { switch (action.type) { case 'list-item-add': return ({value = List(), internal = Map(), ...r}) => { diff --git a/packages/ui-schema/src/storeUpdater/storeUpdater.ts b/packages/ui-schema/src/storeUpdater/storeUpdater.ts index 5edc0e26..446f5cb0 100644 --- a/packages/ui-schema/src/storeUpdater/storeUpdater.ts +++ b/packages/ui-schema/src/storeUpdater/storeUpdater.ts @@ -1,11 +1,33 @@ import { StoreKeys, UIStoreType, prependKey, addNestKey, - UIStoreStateData, + UIStoreStateData, onChangeHandler, } from '@ui-schema/ui-schema/UIStore' import { actionHandler } from '@ui-schema/ui-schema/storeUpdater/storeActionHandler' -import { ScopeUpdaterMapType, storeUpdaterCreate, storeUpdaterType } from '@ui-schema/ui-schema/storeUpdater/storeUpdaterCreate' import { scopeUpdaterValues, scopeUpdaterInternals, scopeUpdaterValidity } from '@ui-schema/ui-schema/storeScopeUpdater' +import { UIStoreActions, UIStoreUpdaterData } from '@ui-schema/ui-schema/UIStoreActions' + +// todo: unify this type and the `setter` in `ScopeUpdaterMapType` +export type ScopeOnChangeHandler = ( + store: S, + storeKeys: StoreKeys, + newValue: any, + action?: A | undefined +) => S + +export type ScopeUpdaterMapType = { + [k in keyof D]: { + setter: ( + store: S, + storeKeys: StoreKeys, + newValue: any, + action?: A | undefined + ) => S + getter: (storeKeys: StoreKeys, store: S) => any + } +} + +export type storeUpdaterType = onChangeHandler<(store: S) => S, A> const getScopedValueFactory = (scope: keyof UIStoreStateData, nestKey?: string) => (storeKeys: StoreKeys, store: S) => @@ -18,16 +40,19 @@ const getScopedValueFactory = (scope: keyof UIStoreStateData, nestKey?: string) export const scopeUpdaterMap: ScopeUpdaterMapType = { value: { // `store.values` + // @ts-ignore setter: scopeUpdaterValues, getter: getScopedValueFactory('values'), }, internal: { // `store.internals` + // @ts-ignore setter: scopeUpdaterInternals, getter: getScopedValueFactory('internals', 'internals'), }, valid: { // `store.validity` + // @ts-ignore setter: scopeUpdaterValidity, getter: getScopedValueFactory('validity'), }, @@ -38,4 +63,59 @@ export const scopeUpdaterMap: ScopeUpdaterMapType = { }, } -export const storeUpdater: storeUpdaterType = storeUpdaterCreate(actionHandler, scopeUpdaterMap) +//export const storeUpdater: storeUpdaterType = storeUpdaterCreate(actionHandler, scopeUpdaterMap) + +export const storeUpdater = + ( + actions: A[] | A + ) => ( + store: S + ): S => { + if (!Array.isArray(actions)) { + actions = [actions] + } + store = actions.reduce((store, action) => { + const {scopes, effect, storeKeys} = action + + // @ts-ignore + const scopeUpdater: ScopeUpdaterMapType = {} + scopes.forEach(scope => { + if (!scopeUpdaterMap[scope]) { + throw new Error('scopeUpdater for `' + scope + '` not found') + } + scopeUpdater[scope] = scopeUpdaterMap[scope] + }) + + const handler = actionHandler(action) + let res: UIStoreUpdaterData + if (typeof handler === 'function') { + // @ts-ignore + const values: UIStoreUpdaterData = {} + + scopes.forEach(scope => { + values[scope] = scopeUpdater[scope]?.getter(storeKeys, store) + }) + + res = handler(values) + } else { + res = handler + } + + scopes.forEach(scope => { + store = scopeUpdater[scope]?.setter( + store, storeKeys, + res[scope], + action, + ) || store + }) + + if (effect) { + effect(res, store) + } + + return store + }, store) + + return store + } diff --git a/packages/ui-schema/src/storeUpdater/storeUpdaterCreate.ts b/packages/ui-schema/src/storeUpdater/storeUpdaterCreate.ts deleted file mode 100644 index 3869f393..00000000 --- a/packages/ui-schema/src/storeUpdater/storeUpdaterCreate.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { StoreActionDefinite, UIStoreActionScoped, UIStoreUpdaterData } from '@ui-schema/ui-schema/UIStoreActions' -import { onChangeHandler, StoreKeys, UIStoreType, UIStoreUpdaterFn } from '@ui-schema/ui-schema/UIStore' - -export type ScopeOnChangeHandler = ( - store: S, - storeKeys: StoreKeys, - newValue: any, - action?: A | undefined -) => S - -export type ScopeUpdaterMapType = { - [k in keyof D]: { - setter: ScopeOnChangeHandler - getter: (storeKeys: StoreKeys, store: S) => any - } -} - -export type storeUpdaterType = onChangeHandler<(store: S) => S, A> - -export const storeUpdaterCreate = - = ScopeUpdaterMapType, - SA extends UIStoreActionScoped = UIStoreActionScoped>( - actionHandler: (action: A) => UIStoreUpdaterFn | D, - scopeUpdaterMap: SU, - ) => ( - actions: (A & SA)[] | (A & SA) - ) => ( - store: S - ): S => { - if (!Array.isArray(actions)) { - actions = [actions] - } - store = actions.reduce((store, action) => { - const {scopes, effect, storeKeys, ...definiteAction} = action - - // @ts-ignore - const scopeUpdater: SU = {} - scopes.forEach(scope => { - if (!scopeUpdaterMap[scope]) { - throw new Error('scopeUpdater for `' + scope + '` not found') - } - scopeUpdater[scope] = scopeUpdaterMap[scope] - }) - - const handler = actionHandler(definiteAction as unknown as A) - let res: D - if (typeof handler === 'function') { - // @ts-ignore - const values: D = {} - - scopes.forEach(scope => { - values[scope] = scopeUpdater[scope]?.getter(storeKeys, store) - }) - - res = handler(values) - } else { - res = handler - } - - scopes.forEach(scope => { - store = scopeUpdater[scope]?.setter( - store, storeKeys, - res[scope], - definiteAction as unknown as A, - ) || store - }) - - if (effect) { - effect(res, store) - } - - return store - }, store) - - return store - }