@plaudit/gutenberg-api-extensions 2.83.0 → 2.84.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/CHANGELOG.md +11 -0
- package/dist/blocks/SNPGroupComponent.js.map +1 -1
- package/dist/blocks/common-native-property-constructors.js +3 -2
- package/dist/blocks/common-native-property-constructors.js.map +1 -1
- package/dist/blocks/data-controller/actions.d.ts +135 -0
- package/dist/blocks/data-controller/actions.js +19 -0
- package/dist/blocks/data-controller/actions.js.map +1 -0
- package/dist/blocks/data-controller/reducer.d.ts +4 -0
- package/dist/blocks/data-controller/reducer.js +143 -0
- package/dist/blocks/data-controller/reducer.js.map +1 -0
- package/dist/blocks/data-controller/trigger-handlers.d.ts +140 -0
- package/dist/blocks/data-controller/trigger-handlers.js +117 -0
- package/dist/blocks/data-controller/trigger-handlers.js.map +1 -0
- package/dist/blocks/data-controller/utils.d.ts +43 -0
- package/dist/blocks/data-controller/utils.js +359 -0
- package/dist/blocks/data-controller/utils.js.map +1 -0
- package/dist/blocks/data-controller.d.ts +4 -37
- package/dist/blocks/data-controller.js +33 -604
- package/dist/blocks/data-controller.js.map +1 -1
- package/dist/blocks/layered-styles-impl.js +9 -8
- package/dist/blocks/layered-styles-impl.js.map +1 -1
- package/dist/blocks/layout/NodeContext.js +3 -3
- package/dist/blocks/layout/NodeContext.js.map +1 -1
- package/dist/blocks/simple-native-property-api.d.ts +9 -7
- package/dist/blocks/simple-native-property-api.js.map +1 -1
- package/dist/blocks/simple-native-property-impl.js +26 -24
- package/dist/blocks/simple-native-property-impl.js.map +1 -1
- package/dist/blocks/snp-data-store.d.ts +9 -6
- package/dist/blocks/snp-data-store.js +17 -12
- package/dist/blocks/snp-data-store.js.map +1 -1
- package/dist/controls/FullSizeToggleControl.d.ts +1 -1
- package/dist/controls/FullSizeToggleControl.js.map +1 -1
- package/dist/lib/gutenberg-api-extensions-state/layered-block-styles-logic.js +12 -12
- package/dist/lib/gutenberg-api-extensions-state/layered-block-styles-logic.js.map +1 -1
- package/dist/lib/gutenberg-api-extensions-state/snp-logic.js +2 -2
- package/dist/lib/gutenberg-api-extensions-state/snp-logic.js.map +1 -1
- package/package.json +7 -7
- package/src/blocks/SNPGroupComponent.tsx +1 -1
- package/src/blocks/common-native-property-constructors.tsx +3 -2
- package/src/blocks/data-controller/actions.ts +20 -0
- package/src/blocks/data-controller/reducer.ts +149 -0
- package/src/blocks/data-controller/trigger-handlers.ts +138 -0
- package/src/blocks/data-controller/utils.ts +339 -0
- package/src/blocks/data-controller.ts +38 -605
- package/src/blocks/layered-styles-impl.ts +10 -9
- package/src/blocks/layout/NodeContext.tsx +3 -3
- package/src/blocks/simple-native-property-api.ts +10 -9
- package/src/blocks/simple-native-property-impl.tsx +26 -24
- package/src/blocks/snp-data-store.ts +22 -13
- package/src/controls/FullSizeToggleControl.tsx +3 -3
- package/src/lib/gutenberg-api-extensions-state/layered-block-styles-logic.ts +12 -11
- package/src/lib/gutenberg-api-extensions-state/snp-logic.ts +2 -2
|
@@ -17,18 +17,18 @@ exports.layeredBlockStylesLogicSelectors = {
|
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
function layeredBlockStylesLogic(state, action) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
switch (action.type) {
|
|
21
|
+
case "ADD_LAYERED_BLOCK_STYLES":
|
|
22
|
+
return (0, immer_1.produce)(state, (draft) => {
|
|
23
|
+
const blockLayeredStyles = draft.layeredBlockStyles[action.blockName] ?? (draft.layeredBlockStyles[action.blockName] = {});
|
|
24
|
+
for (const layer of action.properties) {
|
|
25
|
+
blockLayeredStyles[layer.name] = layer;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
case "SET_LAYERED_BLOCK_STYLES":
|
|
29
|
+
return (0, immer_1.produce)(state, (draft) => {
|
|
30
|
+
draft.layeredBlockStyles[action.blockName] = action.properties;
|
|
31
|
+
});
|
|
32
32
|
}
|
|
33
33
|
return state;
|
|
34
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layered-block-styles-logic.js","sourceRoot":"","sources":["../../../src/lib/gutenberg-api-extensions-state/layered-block-styles-logic.ts"],"names":[],"mappings":";;;AA2BA,
|
|
1
|
+
{"version":3,"file":"layered-block-styles-logic.js","sourceRoot":"","sources":["../../../src/lib/gutenberg-api-extensions-state/layered-block-styles-logic.ts"],"names":[],"mappings":";;;AA2BA,0DAeC;AA1CD,iCAA8B;AAajB,QAAA,8BAA8B,GAAG;IAC7C,qBAAqB,CAAC,SAAoB,EAAE,UAAoC;QAC/E,OAAO,EAAC,IAAI,EAAE,0BAA0B,EAAE,SAAS,EAAE,UAAU,EAAC,CAAC;IAClE,CAAC;CACD,CAAC;AACW,QAAA,gCAAgC,GAAG;IAC/C,gBAAgB,CAAC,KAAmC,EAAE,SAAoB,EAAE,SAAiB;QAC5F,OAAO,KAAK,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;IACD,iBAAiB,CAAC,KAAmC,EAAE,SAAoB;QAC1E,OAAO,KAAK,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC;CACD,CAAC;AAEF,SAAgB,uBAAuB,CAAC,KAAmC,EAAE,MAA2D;IACvI,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACrB,KAAK,0BAA0B;YAC9B,OAAO,IAAA,eAAO,EAAC,KAAK,EAAE,CAAC,KAAmB,EAAE,EAAE;gBAC7C,MAAM,kBAAkB,GAAG,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAAC;gBAC3H,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;oBACvC,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;gBACxC,CAAC;YACF,CAAC,CAAC,CAAC;QACJ,KAAK,0BAA0B;YAC9B,OAAO,IAAA,eAAO,EAAC,KAAK,EAAE,CAAC,KAAmB,EAAE,EAAE;gBAC7C,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC;YAChE,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -62,7 +62,7 @@ function snpLogic(state, action) {
|
|
|
62
62
|
});
|
|
63
63
|
case "ADD_OR_UPDATE_EXTRA_PROP_TRANSFORM":
|
|
64
64
|
return (0, immer_1.produce)(state, (draft) => {
|
|
65
|
-
const blockTransforms =
|
|
65
|
+
const blockTransforms = (draft.extraPropTransforms[action.blockName] ??= {});
|
|
66
66
|
if (blockTransforms[action.propPath]) {
|
|
67
67
|
blockTransforms[action.propPath].styleProperty = action.extraPropTransform.styleProperty;
|
|
68
68
|
}
|
|
@@ -88,7 +88,7 @@ function snpLogic(state, action) {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
function addProperties(block, properties, simpleNativePanelsAndTabs) {
|
|
91
|
-
const panels = (simpleNativePanelsAndTabs[block]
|
|
91
|
+
const panels = (simpleNativePanelsAndTabs[block] ??= []);
|
|
92
92
|
if ('title' in properties) {
|
|
93
93
|
panels.push(properties);
|
|
94
94
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snp-logic.js","sourceRoot":"","sources":["../../../src/lib/gutenberg-api-extensions-state/snp-logic.ts"],"names":[],"mappings":";;;AAqEA,4BAoCC;AAED,sCA2BC;AAyCD,sEAqDC;AAED,gEASC;AA/OD,8CAA+C;AAC/C,0CAAyC;AAEzC,iCAA8B;AA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./dist",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"./controls": "./dist/controls/index.js"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@reduxjs/toolkit": "^
|
|
24
|
+
"@reduxjs/toolkit": "^2.11.2",
|
|
25
25
|
"@types/react": "^18.3.27",
|
|
26
|
-
"@types/wordpress__block-editor": "^
|
|
26
|
+
"@types/wordpress__block-editor": "^15.0.0",
|
|
27
27
|
"@types/wordpress__blocks": "^12.5.18",
|
|
28
28
|
"@wordpress/block-editor": "^15.10.0",
|
|
29
29
|
"@wordpress/blocks": "^15.10.0",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"@wordpress/hooks": "^4.37.0",
|
|
37
37
|
"@wordpress/i18n": "^6.10.0",
|
|
38
38
|
"@wordpress/icons": "^11.4.0",
|
|
39
|
-
"framer-motion": "^12.
|
|
39
|
+
"framer-motion": "^12.26.2",
|
|
40
40
|
"html-react-parser": "^5.2.11",
|
|
41
|
-
"immer": "^
|
|
41
|
+
"immer": "^11.1.3",
|
|
42
42
|
"react": "^18.3.1",
|
|
43
43
|
"react-dom": "^18.3.1",
|
|
44
|
-
"react-error-boundary": "^6.0.
|
|
45
|
-
"redux": "^
|
|
44
|
+
"react-error-boundary": "^6.0.3",
|
|
45
|
+
"redux": "^5.0.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"typescript": "^5.9.3"
|
|
@@ -19,7 +19,7 @@ export function SNPGroupComponent({config, hydratedProperties, Label, Messages}:
|
|
|
19
19
|
className={config.component?.className ? `plaudit-snp-group-component ${config.component.className}` : "plaudit-snp-group-component"}
|
|
20
20
|
label={config.label}
|
|
21
21
|
resetAll={useCallback(resetAllFilters => {
|
|
22
|
-
setValue((resetAllFilters ?? []).reduce((q: any, filter
|
|
22
|
+
setValue((resetAllFilters ?? []).reduce((q: any, filter) => filter(q), value))
|
|
23
23
|
}, [value, setValue])}
|
|
24
24
|
>
|
|
25
25
|
{...hydratedProperties.map(property => <LaidOutPropertyRow property={property} inToolsPanel={true} />)}
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
import {normalizePickableOptionsToObjects, normalizePickableOptionsToPairs} from "../controls/shared";
|
|
26
26
|
import {useSuspendableOptions} from "./hooks/useSuspendableOptions";
|
|
27
27
|
import {makeToolsPanelContextValue, ToolsPanelContext} from "./layout/ToolsPanelContext";
|
|
28
|
+
import {store as gutenbergApiExtensionsStore} from "../lib/gutenberg-api-extensions-state";
|
|
28
29
|
import {clone} from "../lib/helpers";
|
|
29
30
|
import {arrayIsNotEmpty, BlockName} from "../lib/useful-types";
|
|
30
31
|
import type {CSNPControlComponentProps} from "./shared-internal-types";
|
|
@@ -65,14 +66,14 @@ function validateAndRecordPotentialStyleProperty(
|
|
|
65
66
|
if (parentTypes.includes('array')) {
|
|
66
67
|
console.error(`A SNP was configured with a styleProperty, but it is within an array-type SNP. This is unsupported`, "SNP in error:", config);
|
|
67
68
|
} else {
|
|
68
|
-
dispatch(
|
|
69
|
+
dispatch(gutenbergApiExtensionsStore)
|
|
69
70
|
.addOrUpdateExtraPropTransform(blockName, propPath, {propName: config.name, forLayeredStyles, styleProperty: config.styleProperty});
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
function injectBlockSourcedDefault(config: PDSimpleNativeProperty, blockName: BlockName): typeof config {
|
|
74
75
|
if (config.default === undefined) {
|
|
75
|
-
const existingAttr = select(
|
|
76
|
+
const existingAttr = select(gutenbergApiExtensionsStore).baselineBlockAttrs(blockName)?.attributes?.[config.name];
|
|
76
77
|
if (existingAttr && typeof existingAttr === 'object' && 'default' in existingAttr) {
|
|
77
78
|
if (existingAttr.default !== undefined) {
|
|
78
79
|
const expectedPropType = getPropType(config);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {HydratedLaidOutProperties} from "../simple-native-property-internal-shared";
|
|
2
|
+
import type {DataStore} from "../simple-native-property-api";
|
|
3
|
+
import {createGlobalAction, createPathedAction} from "./trigger-handlers";
|
|
4
|
+
|
|
5
|
+
export const actions = {
|
|
6
|
+
addProperties: createGlobalAction<{properties: HydratedLaidOutProperties, dataStore: DataStore}>('addProperties', {conditionChecks: true, changedByManagedControl: true}),
|
|
7
|
+
checkConditions: createGlobalAction('checkConditions', {conditionChecks: true}), // This action is handled implicitly
|
|
8
|
+
commitBatchAddedProperties: createGlobalAction('commitBatchAddedProperties'),
|
|
9
|
+
markManagedControlChangeHandled: createGlobalAction('markManagedControlChangeHandled'),
|
|
10
|
+
validateNodes: createGlobalAction('validateNodes'),
|
|
11
|
+
node: {
|
|
12
|
+
add: createPathedAction<{value?: any, subtype?: string}>('node/add', {conditionChecks: true, changedByManagedControl: true}),
|
|
13
|
+
remove: createPathedAction('node/remove', {conditionChecks: true, changedByManagedControl: true}),
|
|
14
|
+
move: createPathedAction<{from: number, to: number}|{from: string, to: string}>('node/move', {conditionChecks: true}),
|
|
15
|
+
validate: createPathedAction('node/validate', {validation: true}), // This action is handled implicitly
|
|
16
|
+
write: createPathedAction<{value?: any}>('node/write', {conditionChecks: true, validation: true, changedByManagedControl: true}),
|
|
17
|
+
}
|
|
18
|
+
} as const;
|
|
19
|
+
|
|
20
|
+
export type DataControllerActions = ReturnType<typeof actions[Exclude<keyof typeof actions, 'node'>]|typeof actions['node'][keyof typeof actions['node']]>;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import {createReducer} from "@reduxjs/toolkit";
|
|
2
|
+
import {produce} from "immer";
|
|
3
|
+
|
|
4
|
+
import {actions} from "./actions";
|
|
5
|
+
import {DCStoreState, walkToNodeInValue} from "../data-controller";
|
|
6
|
+
import {PathError} from "../PathError";
|
|
7
|
+
import {buildDefaultValueFromDefinition} from "../simple-native-property-internal-shared";
|
|
8
|
+
import type {HydratedSimpleNativeProperty} from "../simple-native-property-api";
|
|
9
|
+
import {triggerHandlers, validateFoundNode} from "./trigger-handlers";
|
|
10
|
+
import {
|
|
11
|
+
applyToTree,
|
|
12
|
+
buildNodeFromDataAndDefinition, getDataStore,
|
|
13
|
+
moveNodeWithinParent,
|
|
14
|
+
populateValueBasedOnDefinition,
|
|
15
|
+
removeFromParentNode, removeValueFromBackingDataStore,
|
|
16
|
+
resolveParentNodeDefinition, TreeMutatorResult,
|
|
17
|
+
walkToNode, writeValueToBackingDataStoreWithCorrections
|
|
18
|
+
} from "./utils";
|
|
19
|
+
|
|
20
|
+
export function buildReducer(blockClientId: string) {
|
|
21
|
+
const initialState: DCStoreState = {
|
|
22
|
+
treeRoot: {children: {}, rendered: true}, dataStores: {byProperty: {}, list: []}, blockClientId, changedByManagedControl: false, rerenderTrigger: 0,
|
|
23
|
+
batchAddedPropertiesThatNeedWriteThrough: []
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return createReducer(initialState, builder => {
|
|
27
|
+
builder
|
|
28
|
+
.addCase(actions.addProperties, (state, {payload: {properties, dataStore}, meta}) => {
|
|
29
|
+
if (!state.dataStores.list.includes(dataStore)) {
|
|
30
|
+
state.dataStores.list.push(dataStore);
|
|
31
|
+
}
|
|
32
|
+
for (const property of properties) {
|
|
33
|
+
for (const prop of Array.isArray(property) ? property : [property]) {
|
|
34
|
+
if (dataStore.getValue(prop.name) === undefined && meta.inBatch) {
|
|
35
|
+
state.batchAddedPropertiesThatNeedWriteThrough.push(prop);
|
|
36
|
+
}
|
|
37
|
+
dataStore.addProperty(prop, !meta.inBatch);
|
|
38
|
+
state.dataStores.byProperty[prop.name] = dataStore;
|
|
39
|
+
state.treeRoot.children[prop.name] = buildNodeFromDataAndDefinition(dataStore.getValue(prop.name), prop);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return state;
|
|
43
|
+
})
|
|
44
|
+
.addCase(actions.validateNodes, state => {
|
|
45
|
+
let hasChanged = false;
|
|
46
|
+
applyToTree(state.treeRoot, (node, path) => {
|
|
47
|
+
if (!node.rendered) {
|
|
48
|
+
return TreeMutatorResult.SKIP_DESCENDANTS;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (validateFoundNode(node, path, state)) {
|
|
52
|
+
hasChanged = true;
|
|
53
|
+
}
|
|
54
|
+
return TreeMutatorResult.CONTINUE;
|
|
55
|
+
});
|
|
56
|
+
if (hasChanged) {
|
|
57
|
+
state.rerenderTrigger++;
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
.addCase(actions.markManagedControlChangeHandled, state => {
|
|
61
|
+
state.changedByManagedControl = false;
|
|
62
|
+
})
|
|
63
|
+
.addCase(actions.commitBatchAddedProperties, state => {
|
|
64
|
+
const batch = [...state.batchAddedPropertiesThatNeedWriteThrough];
|
|
65
|
+
state.batchAddedPropertiesThatNeedWriteThrough = [];
|
|
66
|
+
for (const batchAddedProperty of batch) {
|
|
67
|
+
if (state.treeRoot.children[batchAddedProperty.name]?.rendered) {
|
|
68
|
+
writeValueToBackingDataStoreWithCorrections([batchAddedProperty.name], state, buildDefaultValueFromDefinition(batchAddedProperty));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
.addCase(actions.node.add, (state, {payload: {path, value, subtype}}) => {
|
|
73
|
+
const parentDefinition = resolveParentNodeDefinition(state.treeRoot, path);
|
|
74
|
+
if (!parentDefinition) {
|
|
75
|
+
throw new Error("Cannot add children to a node without a definition");
|
|
76
|
+
}
|
|
77
|
+
const nodeNameOrIndex = path[path.length - 1];
|
|
78
|
+
let parentDefinitionChildren: HydratedSimpleNativeProperty[] | undefined;
|
|
79
|
+
if (Array.isArray(parentDefinition.children) || parentDefinition.children === undefined) {
|
|
80
|
+
parentDefinitionChildren = parentDefinition.children;
|
|
81
|
+
} else {
|
|
82
|
+
const actualSubtype = value?.type ?? subtype;
|
|
83
|
+
if (!actualSubtype || !parentDefinition.children[actualSubtype]) {
|
|
84
|
+
throw new PathError("Unable to locate the definition of the named node because its type could not be resolved.", path);
|
|
85
|
+
}
|
|
86
|
+
parentDefinitionChildren = parentDefinition.children[actualSubtype];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (typeof nodeNameOrIndex === 'string') {
|
|
90
|
+
const definition = parentDefinitionChildren?.find(definition => definition.name === nodeNameOrIndex);
|
|
91
|
+
if (definition === undefined) {
|
|
92
|
+
throw new PathError("Unable to locate the definition of the named node.", path);
|
|
93
|
+
}
|
|
94
|
+
const data = populateValueBasedOnDefinition(value, parentDefinition);
|
|
95
|
+
const builtNode = buildNodeFromDataAndDefinition(data, definition);
|
|
96
|
+
const parentNode = walkToNode(state.treeRoot, path.slice(0, path.length - 1));
|
|
97
|
+
if (parentNode.children === undefined) {
|
|
98
|
+
parentNode.children = {[nodeNameOrIndex]: builtNode};
|
|
99
|
+
} else {
|
|
100
|
+
if (Array.isArray(parentNode.children)) {
|
|
101
|
+
throw new PathError("Encountered a node with indexed descendants while expecting one with string-keyed descendants.", path);
|
|
102
|
+
}
|
|
103
|
+
parentNode.children[nodeNameOrIndex] = builtNode;
|
|
104
|
+
}
|
|
105
|
+
writeValueToBackingDataStoreWithCorrections(path, state, data);
|
|
106
|
+
} else if (nodeNameOrIndex === undefined) {
|
|
107
|
+
throw new PathError("Encountered an undefined name in a path.", path);
|
|
108
|
+
} else {
|
|
109
|
+
const data = populateValueBasedOnDefinition(value, parentDefinition);
|
|
110
|
+
const builtNode = buildNodeFromDataAndDefinition(data, parentDefinition);
|
|
111
|
+
const parentNode = walkToNode(state.treeRoot, path.slice(0, path.length - 1));
|
|
112
|
+
if (parentNode.children === undefined) {
|
|
113
|
+
parentNode.children = [];
|
|
114
|
+
parentNode.children[nodeNameOrIndex] = builtNode;
|
|
115
|
+
} else {
|
|
116
|
+
if (!Array.isArray(parentNode.children)) {
|
|
117
|
+
throw new PathError("Encountered a node with string-keyed descendants while expecting one with indexed descendants.", path);
|
|
118
|
+
}
|
|
119
|
+
parentNode.children[nodeNameOrIndex] = builtNode;
|
|
120
|
+
}
|
|
121
|
+
writeValueToBackingDataStoreWithCorrections(path, state, data);
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
.addCase(actions.node.remove, (state, {payload: {path}}) => {
|
|
125
|
+
const parentNode = walkToNode(state.treeRoot, path.slice(0, path.length - 1));
|
|
126
|
+
removeFromParentNode(parentNode.children, path);
|
|
127
|
+
removeValueFromBackingDataStore(getDataStore(path[0], state), path);
|
|
128
|
+
})
|
|
129
|
+
.addCase(actions.node.move, (state, {payload: {path, ...action}}) => {
|
|
130
|
+
// If from and to are the same, then this is a no-op, so we can just skip it
|
|
131
|
+
if (action.from === action.to) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
state.changedByManagedControl = true;
|
|
135
|
+
moveNodeWithinParent(walkToNode(state.treeRoot, path).children, path, action);
|
|
136
|
+
const dataStore = getDataStore(path[0], state);
|
|
137
|
+
dataStore.setValue(path[0], produce(dataStore.getValue(path[0]), (dsDraft: any) => {
|
|
138
|
+
moveNodeWithinParent(walkToNodeInValue(dsDraft, path), path, action);
|
|
139
|
+
}));
|
|
140
|
+
})
|
|
141
|
+
.addCase(actions.node.write, (state, {payload: {path, value}}) => {
|
|
142
|
+
writeValueToBackingDataStoreWithCorrections(path, state, value);
|
|
143
|
+
})
|
|
144
|
+
;
|
|
145
|
+
for (const {attachTo} of Object.values(triggerHandlers)) {
|
|
146
|
+
attachTo(builder);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import {ActionReducerMapBuilder, CaseReducer, createAction, PayloadAction, PayloadActionCreator} from "@reduxjs/toolkit";
|
|
2
|
+
import type {Draft} from "immer";
|
|
3
|
+
|
|
4
|
+
import type {NodePath, RawPath} from "../simple-native-property-api";
|
|
5
|
+
import {PathError} from "../PathError";
|
|
6
|
+
import type {DCNode, DCStoreState} from "../data-controller";
|
|
7
|
+
import {buildDefaultValueFromDefinition} from "../simple-native-property-internal-shared";
|
|
8
|
+
import {resolveValueForCondition, testCondition} from "../conditions";
|
|
9
|
+
import {
|
|
10
|
+
applyToTree,
|
|
11
|
+
getDataStore,
|
|
12
|
+
getOptionalValue,
|
|
13
|
+
removeValueFromBackingDataStore,
|
|
14
|
+
TreeMutatorResult,
|
|
15
|
+
walkToNode,
|
|
16
|
+
walkToNodeInValue,
|
|
17
|
+
writeValueToBackingDataStore
|
|
18
|
+
} from "./utils";
|
|
19
|
+
|
|
20
|
+
type BasePayload = {[key in string]: any}&{type?: never, inBatch?: never};
|
|
21
|
+
type BaseMetadata = {[key in string]: any}&{inBatch?: never};
|
|
22
|
+
type BaseReducer<State, P extends BasePayload, M extends BaseMetadata> = CaseReducer<State, PayloadAction<P, string, M&{inBatch?: boolean}>>;
|
|
23
|
+
function makeTriggerHandler<State, P extends BasePayload = {}, M extends BaseMetadata = {}>(reducer: BaseReducer<State, P, M>) {
|
|
24
|
+
type ActionType = PayloadAction<P, string, M&{inBatch?: boolean}>&{meta: M&{inBatch?: boolean}};
|
|
25
|
+
type TriggeringActionCreator = PayloadActionCreator<P, string, (...args: any[]) => {payload: P, meta: M&{inBatch?: boolean}}>;
|
|
26
|
+
const triggeringActionCreators: TriggeringActionCreator[] = [];
|
|
27
|
+
const isInstance = (action: any): action is ActionType => {
|
|
28
|
+
return triggeringActionCreators.some(actionCreator => actionCreator.match(action));
|
|
29
|
+
};
|
|
30
|
+
const shouldTrigger = (action: any): action is ActionType => isInstance(action) && (action.meta.inBatch !== true);
|
|
31
|
+
return {
|
|
32
|
+
addAction: (action: TriggeringActionCreator) => triggeringActionCreators.push(action), isInstance, shouldTrigger,
|
|
33
|
+
attachTo: (builder: ActionReducerMapBuilder<State>) => builder.addMatcher(shouldTrigger, reducer)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const triggerHandlers = {
|
|
38
|
+
validation: makeTriggerHandler<DCStoreState, {path: NodePath}>((state, {payload: {path}}) => {
|
|
39
|
+
validateNode(path, state);
|
|
40
|
+
return state;
|
|
41
|
+
}),
|
|
42
|
+
conditionChecks: makeTriggerHandler<DCStoreState>(performConditionChecks),
|
|
43
|
+
changedByManagedControl: makeTriggerHandler<DCStoreState>(state => {
|
|
44
|
+
state.changedByManagedControl = true;
|
|
45
|
+
}),
|
|
46
|
+
} as const;
|
|
47
|
+
|
|
48
|
+
type CommonTriggers = {changedByManagedControl?: boolean, conditionChecks?: boolean};
|
|
49
|
+
type BaseActionMeta<ADDITIONAL_TRIGGERS extends {[K in Exclude<keyof typeof triggerHandlers, keyof CommonTriggers>]?: boolean}> = {inBatch?: boolean, triggers: CommonTriggers&ADDITIONAL_TRIGGERS};
|
|
50
|
+
|
|
51
|
+
export type GlobalActionMeta = BaseActionMeta<{}>;
|
|
52
|
+
export function createGlobalAction<P extends {[key: Exclude<string, 'type'|'inBatch'>]: any} = {}, T extends string = string>(type: T, triggers: GlobalActionMeta['triggers'] = {}) {
|
|
53
|
+
const res = createAction(type, (payload: P, inBatch: boolean = false) => ({payload, meta: {inBatch, triggers}}));
|
|
54
|
+
for (const [trigger, enabled] of Object.entries(triggers)) {
|
|
55
|
+
if (enabled) {
|
|
56
|
+
triggerHandlers[trigger as keyof typeof triggers].addAction(res);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return res;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type PathedActionMeta = BaseActionMeta<{validation?: boolean}>;
|
|
63
|
+
export function createPathedAction<P extends {[key: Exclude<string, 'type'|'path'|'inBatch'>]: any} = {}, T extends string = string>(type: T, triggers: PathedActionMeta['triggers'] = {}) {
|
|
64
|
+
const res = createAction(type, (payload: P&{path: NodePath}, inBatch: boolean = false) => ({payload, meta: {inBatch, triggers}}));
|
|
65
|
+
for (const [trigger, enabled] of Object.entries(triggers)) {
|
|
66
|
+
if (enabled) {
|
|
67
|
+
triggerHandlers[trigger as keyof typeof triggers].addAction(res);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return res;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function validateNode(path: NodePath, draft: Draft<DCStoreState>) {
|
|
74
|
+
if (validateFoundNode(walkToNode(draft.treeRoot, path), path, draft)) {
|
|
75
|
+
draft.rerenderTrigger = draft.rerenderTrigger + 1;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @return true iff the validation state changed
|
|
81
|
+
*/
|
|
82
|
+
export function validateFoundNode(node: DCNode, path: NodePath, draft: Draft<DCStoreState>) {
|
|
83
|
+
const definition = node.definition;
|
|
84
|
+
if (definition) {
|
|
85
|
+
let validationError: string;
|
|
86
|
+
const value = getOptionalValue(path, draft);
|
|
87
|
+
if (definition.required && !value) {
|
|
88
|
+
validationError = `"${definition.label || definition.name}" is required.`;
|
|
89
|
+
} else {
|
|
90
|
+
validationError = definition.validator?.(value) ?? "";
|
|
91
|
+
}
|
|
92
|
+
if (node.validationError !== validationError) {
|
|
93
|
+
node.validationError = validationError;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
type PropertyValueResolverBuilder = (path: RawPath) => (propertyPath: RawPath) => any;
|
|
101
|
+
function performConditionChecks(state: Draft<DCStoreState>) {
|
|
102
|
+
const blockClientId = state.blockClientId;
|
|
103
|
+
const propertyValueResolverBuilder: PropertyValueResolverBuilder =
|
|
104
|
+
path => propertyPath => resolveValueForCondition(propertyPath, path, blockClientId,
|
|
105
|
+
property => getDataStore(property, state, false));
|
|
106
|
+
applyToTree(state.treeRoot, (node, path) => {
|
|
107
|
+
const condition = node.condition;
|
|
108
|
+
if (condition === undefined) {
|
|
109
|
+
node.rendered = true;
|
|
110
|
+
return TreeMutatorResult.CONTINUE;
|
|
111
|
+
} else {
|
|
112
|
+
const newRendered = testCondition(condition, propertyValueResolverBuilder(path));
|
|
113
|
+
if (newRendered !== node.rendered) {
|
|
114
|
+
const dataStore = getDataStore(path[0], state);
|
|
115
|
+
let currentValue: any;
|
|
116
|
+
try {
|
|
117
|
+
currentValue = walkToNodeInValue(dataStore.getValue(path[0]), path);
|
|
118
|
+
} catch (e) {
|
|
119
|
+
if (!(e instanceof PathError)) {
|
|
120
|
+
throw e;
|
|
121
|
+
}
|
|
122
|
+
currentValue = undefined;
|
|
123
|
+
}
|
|
124
|
+
if (!newRendered) {
|
|
125
|
+
// Create a backup if we are transitioning from rendered -> unrendered
|
|
126
|
+
node.backup = currentValue;
|
|
127
|
+
removeValueFromBackingDataStore(dataStore, path);
|
|
128
|
+
} else if (currentValue === undefined) {
|
|
129
|
+
// Restore from backup if we are transitioning from unrendered -> rendered
|
|
130
|
+
const stateNode = walkToNode(state.treeRoot, path);
|
|
131
|
+
writeValueToBackingDataStore(dataStore, path, stateNode.backup ?? buildDefaultValueFromDefinition(stateNode.definition));
|
|
132
|
+
}
|
|
133
|
+
node.rendered = newRendered;
|
|
134
|
+
}
|
|
135
|
+
return node.rendered ? TreeMutatorResult.CONTINUE : TreeMutatorResult.SKIP_DESCENDANTS;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|