@plaudit/gutenberg-api-extensions 2.84.2 → 2.84.4
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 +9 -0
- package/dist/blocks/basic-custom-block-bindings-support.js +1 -1
- package/dist/blocks/basic-custom-block-bindings-support.js.map +1 -1
- package/dist/blocks/common-native-property-constructors.d.ts +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 +1 -1
- package/dist/blocks/data-controller/reducer.js +2 -3
- package/dist/blocks/data-controller/reducer.js.map +1 -1
- package/dist/blocks/data-controller/trigger-handlers.js +1 -2
- package/dist/blocks/data-controller/trigger-handlers.js.map +1 -1
- package/dist/blocks/data-controller/utils.d.ts +16 -3
- package/dist/blocks/data-controller/utils.js +57 -13
- package/dist/blocks/data-controller/utils.js.map +1 -1
- package/dist/blocks/data-controller.d.ts +7 -3
- package/dist/blocks/data-controller.js.map +1 -1
- package/dist/blocks/simple-native-property-api.d.ts +3 -3
- package/dist/blocks/simple-native-property-internal-shared.d.ts +0 -1
- package/dist/blocks/simple-native-property-internal-shared.js +0 -29
- package/dist/blocks/simple-native-property-internal-shared.js.map +1 -1
- package/dist/blocks/snp-data-store.d.ts +4 -1
- package/dist/blocks/snp-data-store.js +3 -3
- package/dist/blocks/snp-data-store.js.map +1 -1
- package/dist/lib/gutenberg-api-extensions-state/custom-block-bindings-support-logic.d.ts +2 -2
- package/dist/lib/gutenberg-api-extensions-state/custom-block-bindings-support-logic.js.map +1 -1
- package/dist/lib/gutenberg-api-extensions-state/layered-block-styles-logic.d.ts +2 -2
- package/dist/lib/gutenberg-api-extensions-state/layered-block-styles-logic.js.map +1 -1
- package/dist/lib/gutenberg-api-extensions-state/snp-logic.d.ts +2 -2
- package/dist/lib/gutenberg-api-extensions-state/snp-logic.js.map +1 -1
- package/dist/lib/gutenberg-api-extensions-state.d.ts +2 -2
- package/dist/lib/gutenberg-api-extensions-state.js +2 -2
- package/dist/lib/gutenberg-api-extensions-state.js.map +1 -1
- package/dist/lib/helpers.d.ts +1 -12
- package/dist/lib/helpers.js +1 -7
- package/dist/lib/helpers.js.map +1 -1
- package/dist/lib/useful-types.d.ts +5 -30
- package/dist/lib/useful-types.js.map +1 -1
- package/package.json +15 -15
- package/src/blocks/basic-custom-block-bindings-support.tsx +1 -1
- package/src/blocks/common-native-property-constructors.tsx +4 -6
- package/src/blocks/data-controller/actions.ts +1 -1
- package/src/blocks/data-controller/reducer.ts +3 -4
- package/src/blocks/data-controller/trigger-handlers.ts +1 -1
- package/src/blocks/data-controller/utils.ts +55 -12
- package/src/blocks/data-controller.ts +4 -6
- package/src/blocks/simple-native-property-api.ts +2 -2
- package/src/blocks/simple-native-property-internal-shared.ts +0 -27
- package/src/blocks/snp-data-store.ts +2 -2
- package/src/lib/gutenberg-api-extensions-state/custom-block-bindings-support-logic.ts +4 -3
- package/src/lib/gutenberg-api-extensions-state/layered-block-styles-logic.ts +2 -2
- package/src/lib/gutenberg-api-extensions-state/snp-logic.ts +2 -2
- package/src/lib/gutenberg-api-extensions-state.ts +3 -3
- package/src/lib/helpers.ts +1 -23
- package/src/lib/useful-types.ts +4 -20
|
@@ -5,7 +5,6 @@ import {Draft, produce} from "immer";
|
|
|
5
5
|
import type {DCNode, DCStoreState} from "../data-controller";
|
|
6
6
|
import {MoveError} from "../MoveError";
|
|
7
7
|
import {PathError, PathErrorType} from "../PathError";
|
|
8
|
-
import {buildDefaultValueFromDefinition} from "../simple-native-property-internal-shared";
|
|
9
8
|
import type {DataStore, HydratedSimpleNativeProperty, NodePath, RawPath} from "../simple-native-property-api";
|
|
10
9
|
|
|
11
10
|
export function removeFromParentNode(parentNode: any|undefined, path: RawPath) {
|
|
@@ -58,14 +57,14 @@ export function isNumericMove(move: {from: number, to: number}|{from: string, to
|
|
|
58
57
|
return typeof move.from === 'number' && typeof move.to === 'number';
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
export function resolveParentNodeDefinition(root: DCNode, path: RawPath):
|
|
60
|
+
export function resolveParentNodeDefinition(root: DCNode, path: RawPath): DCNode['definition'] {
|
|
62
61
|
if (path.length < 2) {
|
|
63
62
|
throw new PathError("Unable to get the parent node of a path with less than two nodes", path, path.length - 1, PathErrorType.INSUFFICIENT_LENGTH);
|
|
64
63
|
}
|
|
65
64
|
return walkToNode(root, path.slice(0, path.length - (typeof path[path.length - 2] === 'number' ? 2 : 1))).definition;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
export function populateValueBasedOnDefinition(value: any, definition: HydratedSimpleNativeProperty
|
|
67
|
+
export function populateValueBasedOnDefinition(value: any, definition: HydratedSimpleNativeProperty<{uuid: UUID}>|undefined): any {
|
|
69
68
|
const typedChildren = Array.isArray(definition?.children) ? definition.children : definition?.children?.[value?.type];
|
|
70
69
|
if (!typedChildren?.length) {
|
|
71
70
|
return value ?? buildDefaultValueFromDefinition(definition);
|
|
@@ -166,7 +165,7 @@ export function writeValueToBackingDataStoreWithCorrections(path: NodePath, stat
|
|
|
166
165
|
const dataStore = getDataStore(path[0], state);
|
|
167
166
|
|
|
168
167
|
// This path both handles scalar values and ensures that the root "value" of Groups and Lists are initialized before writing the actual attribute
|
|
169
|
-
//
|
|
168
|
+
// To avoid accidentally overwriting group data when lazily adding items (i.e., via a ToolsPanel instance), we skip this code path if the group's root value has already been initialized
|
|
170
169
|
if (path.length === 1 || (value === undefined && dataStore.getValue(path[0]) === undefined)) {
|
|
171
170
|
const writtenValue = value ?? buildDefaultValueFromDefinition(rootDCNode.definition, path.length === 1);
|
|
172
171
|
dataStore.setValue(path[0], writtenValue);
|
|
@@ -290,27 +289,71 @@ export function applyToTree(tree: DCNode, mutator: (node: DCNode, path: NodePath
|
|
|
290
289
|
return TreeMutatorResult.CONTINUE;
|
|
291
290
|
}
|
|
292
291
|
|
|
293
|
-
export
|
|
292
|
+
export type UUID = ReturnType<typeof crypto.randomUUID>;
|
|
293
|
+
const cloneableDefaultValuesForNodes: Record<UUID, HydratedSimpleNativeProperty['default']> = {};
|
|
294
|
+
export function recordCloneableDefaultValueForNode<T extends HydratedSimpleNativeProperty<{uuid?: UUID}>>(definition: T) {
|
|
295
|
+
if (!definition.uuid) {
|
|
296
|
+
definition.uuid = crypto.randomUUID();
|
|
297
|
+
}
|
|
298
|
+
if (!(definition.uuid in cloneableDefaultValuesForNodes)) {
|
|
299
|
+
try {
|
|
300
|
+
cloneableDefaultValuesForNodes[definition.uuid] = (definition.default === undefined ? undefined : structuredClone(definition.default));
|
|
301
|
+
} catch (e) {
|
|
302
|
+
console.error(`Encountered an unexpected un-cloneable default value: ${e}`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return definition as HydratedSimpleNativeProperty<{uuid: UUID}>;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export function buildDefaultValueFromDefinition(definition: (HydratedSimpleNativeProperty<{uuid: UUID}>)|undefined, requireNonNullValueOnObject = true): any {
|
|
310
|
+
if (definition === undefined) {
|
|
311
|
+
return undefined;
|
|
312
|
+
} else if (definition.default !== undefined) {
|
|
313
|
+
return structuredClone(definition.uuid in cloneableDefaultValuesForNodes ? cloneableDefaultValuesForNodes[definition.uuid] : definition.default);
|
|
314
|
+
}
|
|
315
|
+
const typedChildren = Array.isArray(definition.children) ? definition.children : undefined;
|
|
316
|
+
if (!typedChildren?.length) {
|
|
317
|
+
return structuredClone(definition.uuid in cloneableDefaultValuesForNodes ? cloneableDefaultValuesForNodes[definition.uuid] : definition.default);
|
|
318
|
+
} else if (definition.type === 'array') {
|
|
319
|
+
return [];
|
|
320
|
+
} else if (definition.type !== 'object') {
|
|
321
|
+
return undefined;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const res = Object.fromEntries(typedChildren.map(def => [def.name, buildDefaultValueFromDefinition(def)]));
|
|
325
|
+
if (requireNonNullValueOnObject) {
|
|
326
|
+
for (const value of Object.values(res)) {
|
|
327
|
+
if (value !== undefined) {
|
|
328
|
+
return res;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return undefined;
|
|
332
|
+
}
|
|
333
|
+
return res;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export function buildNodeFromDataAndDefinition(data: any, definition: HydratedSimpleNativeProperty<{uuid?: UUID}>): DCNode {
|
|
294
337
|
const children = definition.children;
|
|
295
338
|
if (children) {
|
|
296
339
|
if (data === undefined || data === null) {
|
|
297
340
|
if (definition.type === 'array') {
|
|
298
|
-
return {rendered: true, condition: definition.condition, definition, validationError: "", children: []};
|
|
341
|
+
return {rendered: true, condition: definition.condition, definition: recordCloneableDefaultValueForNode(definition), validationError: "", children: []};
|
|
299
342
|
} else if (definition.type === 'object') {
|
|
300
343
|
if (Array.isArray(children)) {
|
|
301
344
|
return {
|
|
302
|
-
rendered: true, condition: definition.condition, definition, validationError: "",
|
|
345
|
+
rendered: true, condition: definition.condition, definition: recordCloneableDefaultValueForNode(definition), validationError: "",
|
|
303
346
|
children: Object.fromEntries(children.map(def => [def.name, buildNodeFromDataAndDefinition(undefined, def)]))
|
|
304
347
|
};
|
|
305
348
|
} else {
|
|
306
349
|
//TODO: We might need to throw an error here
|
|
307
|
-
return {rendered: true, condition: definition.condition, definition, validationError: "", children: {}};
|
|
350
|
+
return {rendered: true, condition: definition.condition, definition: recordCloneableDefaultValueForNode(definition), validationError: "", children: {}};
|
|
308
351
|
}
|
|
309
352
|
}
|
|
310
353
|
} else if (typeof data === 'object') {
|
|
311
354
|
if (Array.isArray(data)) {
|
|
312
355
|
return {
|
|
313
|
-
rendered: true, condition: definition.condition, definition, validationError: "", children: data.map(item => {
|
|
356
|
+
rendered: true, condition: definition.condition, definition: recordCloneableDefaultValueForNode(definition), validationError: "", children: data.map(item => {
|
|
314
357
|
const typedChildren = Array.isArray(children) ? children : children[item.type];
|
|
315
358
|
if (typedChildren === undefined) {
|
|
316
359
|
//TODO: We might need to throw an error here
|
|
@@ -326,14 +369,14 @@ export function buildNodeFromDataAndDefinition(data: any, definition: HydratedSi
|
|
|
326
369
|
const typedChildren = Array.isArray(children) ? children : children[data.type];
|
|
327
370
|
if (typedChildren === undefined) {
|
|
328
371
|
//TODO: We might need to throw an error here
|
|
329
|
-
return {rendered: true, condition: definition.condition, definition, validationError: "", children: []};
|
|
372
|
+
return {rendered: true, condition: definition.condition, definition: recordCloneableDefaultValueForNode(definition), validationError: "", children: []};
|
|
330
373
|
}
|
|
331
374
|
return {
|
|
332
|
-
rendered: true, condition: definition.condition, definition, validationError: "",
|
|
375
|
+
rendered: true, condition: definition.condition, definition: recordCloneableDefaultValueForNode(definition), validationError: "",
|
|
333
376
|
children: Object.fromEntries(typedChildren.map(def => [def.name, buildNodeFromDataAndDefinition(data[def.name], def)]))
|
|
334
377
|
};
|
|
335
378
|
}
|
|
336
379
|
}
|
|
337
380
|
}
|
|
338
|
-
return {rendered: true, condition: definition.condition, definition, validationError: ""};
|
|
381
|
+
return {rendered: true, condition: definition.condition, definition: recordCloneableDefaultValueForNode(definition), validationError: ""};
|
|
339
382
|
}
|
|
@@ -9,11 +9,9 @@ import {type Condition, resolveValueForCondition} from "./conditions";
|
|
|
9
9
|
import {PathError, PathErrorType} from "./PathError";
|
|
10
10
|
import type {DataController, DataStore, HydratedSimpleNativeProperty, NodePath} from "./simple-native-property-api";
|
|
11
11
|
|
|
12
|
-
import {actions, DataControllerActions} from "./data-controller/actions";
|
|
12
|
+
import {actions, type DataControllerActions} from "./data-controller/actions";
|
|
13
13
|
import {buildReducer} from "./data-controller/reducer";
|
|
14
|
-
import {getDataStore, getOptionalValue, walkToNode} from "./data-controller/utils";
|
|
15
|
-
|
|
16
|
-
export type {DataControllerActions} from "./data-controller/actions";
|
|
14
|
+
import {getDataStore, getOptionalValue, UUID, walkToNode} from "./data-controller/utils";
|
|
17
15
|
|
|
18
16
|
type DescendantsWrapper = {[key: string]: DCNode}|DCNode[];
|
|
19
17
|
export type DCNode = {
|
|
@@ -21,7 +19,7 @@ export type DCNode = {
|
|
|
21
19
|
rendered?: boolean,
|
|
22
20
|
condition?: Condition,
|
|
23
21
|
children?: DescendantsWrapper,
|
|
24
|
-
definition?: HydratedSimpleNativeProperty
|
|
22
|
+
definition?: HydratedSimpleNativeProperty<{uuid: UUID}>,
|
|
25
23
|
validationError?: string
|
|
26
24
|
};
|
|
27
25
|
export type DCStoreState = {
|
|
@@ -30,7 +28,7 @@ export type DCStoreState = {
|
|
|
30
28
|
blockClientId: string,
|
|
31
29
|
changedByManagedControl: boolean,
|
|
32
30
|
rerenderTrigger: number,
|
|
33
|
-
batchAddedPropertiesThatNeedWriteThrough: HydratedSimpleNativeProperty[]
|
|
31
|
+
batchAddedPropertiesThatNeedWriteThrough: HydratedSimpleNativeProperty<{uuid: UUID}>[]
|
|
34
32
|
};
|
|
35
33
|
type DCThunkDispatch = ThunkDispatch<DCStoreState, unknown, DataControllerActions>;
|
|
36
34
|
|
|
@@ -94,8 +94,8 @@ export type SimpleNativeProperty = GenericSimpleNativeProperty<string, 'string'>
|
|
|
94
94
|
export type PDSimpleNativeProperty = SimpleNativeProperty|CSNPConfig;
|
|
95
95
|
export type PotentiallyDesiccatedSimpleNativeProperty = PDSimpleNativeProperty;
|
|
96
96
|
|
|
97
|
-
export type HydratedSimpleNativeProperty = SimpleNativeProperty
|
|
98
|
-
&{children?: {[subtype: string]: HydratedSimpleNativeProperty[]}|HydratedSimpleNativeProperty[], controlType?: string, branching?: boolean, initializing?: ReactNode|(() => ReactNode)};
|
|
97
|
+
export type HydratedSimpleNativeProperty<ADDITIONAL_DATA extends Record<string, any> = {}> = SimpleNativeProperty&ADDITIONAL_DATA
|
|
98
|
+
&{children?: {[subtype: string]: HydratedSimpleNativeProperty<ADDITIONAL_DATA>[]}|HydratedSimpleNativeProperty<ADDITIONAL_DATA>[], controlType?: string, branching?: boolean, initializing?: ReactNode|(() => ReactNode)};
|
|
99
99
|
export type SNPControlSlots = {Label: ProvidedSlot, Messages: ProvidedSlot};
|
|
100
100
|
|
|
101
101
|
export type LaidOutProperties = Array<PDSimpleNativeProperty|Array<PDSimpleNativeProperty>>;
|
|
@@ -17,30 +17,3 @@ export type PreppedSimpleNativePanelsAndTabs = {panels: [string, HydratedSimpleN
|
|
|
17
17
|
export function isRootLevelPanelGroup(panelGroup: string|undefined) {
|
|
18
18
|
return panelGroup === undefined || panelGroup === "default" || panelGroup === "advanced" || panelGroup === "settings" || panelGroup === "styles";
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
export function buildDefaultValueFromDefinition(definition: HydratedSimpleNativeProperty|undefined, requireNonNullValueOnObject = true): any {
|
|
22
|
-
if (definition === undefined) {
|
|
23
|
-
return undefined;
|
|
24
|
-
} else if (definition.default !== undefined) {
|
|
25
|
-
return structuredClone(definition.default);
|
|
26
|
-
}
|
|
27
|
-
const typedChildren = Array.isArray(definition.children) ? definition.children : undefined;
|
|
28
|
-
if (!typedChildren?.length) {
|
|
29
|
-
return structuredClone(definition.default);
|
|
30
|
-
} else if (definition.type === 'array') {
|
|
31
|
-
return [];
|
|
32
|
-
} else if (definition.type !== 'object') {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const res = Object.fromEntries(typedChildren.map(def => [def.name, buildDefaultValueFromDefinition(def)]));
|
|
37
|
-
if (requireNonNullValueOnObject) {
|
|
38
|
-
for (const value of Object.values(res)) {
|
|
39
|
-
if (value !== undefined) {
|
|
40
|
-
return res;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
return res;
|
|
46
|
-
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {store as blockEditorStore} from "@wordpress/block-editor";
|
|
2
2
|
import {dispatch, select} from "@wordpress/data";
|
|
3
3
|
|
|
4
|
+
import {buildDefaultValueFromDefinition, UUID} from "./data-controller/utils";
|
|
4
5
|
import type {ActualBlockEditProps, BlockName} from "../lib/useful-types";
|
|
5
6
|
import type {DataStore, HydratedSimpleNativeProperty} from "./simple-native-property-api";
|
|
6
|
-
import {buildDefaultValueFromDefinition} from "./simple-native-property-internal-shared";
|
|
7
7
|
|
|
8
8
|
export abstract class SNPDataStore implements DataStore {
|
|
9
9
|
private readonly managedPropertyNames: {[propertyName in string]: true};
|
|
@@ -58,7 +58,7 @@ export abstract class SNPDataStore implements DataStore {
|
|
|
58
58
|
return attr in this.attributeCache;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
addProperty(property: HydratedSimpleNativeProperty
|
|
61
|
+
addProperty(property: HydratedSimpleNativeProperty<{uuid: UUID}>, writeThroughOnUndefined = true) {
|
|
62
62
|
if (this.managedPropertyNames[property.name]) {
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {registerBlockBindingsSource} from "@wordpress/blocks";
|
|
2
2
|
|
|
3
|
-
import type {DbSource} from "../../blocks";
|
|
4
|
-
import type {WordPressMetaActions} from "../useful-types";
|
|
5
3
|
import {produce} from "immer";
|
|
6
4
|
|
|
5
|
+
import type {DbSource} from "../../blocks";
|
|
6
|
+
import type {WorkableUnknownAction} from "../useful-types";
|
|
7
|
+
|
|
7
8
|
export type CustomBlockBindingsSupportLogicActions = {type: 'ADD_CUSTOM_BLOCK_BINDINGS_SOURCE', name: string, value: {dbSources?: DbSource[]}};
|
|
8
9
|
export type CustomBlockBindingsSupportLogicState = {
|
|
9
10
|
customBlockBindingsSupport: {[name in string]?: {dbSources?: DbSource[]}}
|
|
@@ -23,7 +24,7 @@ export const customBlockBindingsSupportLogicSelectors = {
|
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
export function customBlockBindingsSupportLogic(
|
|
26
|
-
state: CustomBlockBindingsSupportLogicState, action: CustomBlockBindingsSupportLogicActions|
|
|
27
|
+
state: CustomBlockBindingsSupportLogicState, action: CustomBlockBindingsSupportLogicActions|WorkableUnknownAction
|
|
27
28
|
): typeof state {
|
|
28
29
|
if (action.type === "ADD_CUSTOM_BLOCK_BINDINGS_SOURCE") {
|
|
29
30
|
return produce(state, (draft: typeof state) => {
|
|
@@ -2,7 +2,7 @@ import {produce} from "immer";
|
|
|
2
2
|
|
|
3
3
|
import type {PDSimpleNativeProperty} from "../../blocks";
|
|
4
4
|
import type {NamedBlockAction} from "../gutenberg-api-extensions-state";
|
|
5
|
-
import type {BlockName,
|
|
5
|
+
import type {BlockName, WorkableUnknownAction} from "../useful-types";
|
|
6
6
|
|
|
7
7
|
export type LayeredBlockStylesLogicActions =
|
|
8
8
|
NamedBlockAction<'ADD_LAYERED_BLOCK_STYLES', {properties: PDSimpleNativeProperty[]}>|
|
|
@@ -25,7 +25,7 @@ export const layeredBlockStylesLogicSelectors = {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
export function layeredBlockStylesLogic(state: LayeredBlockStylesLogicState, action: LayeredBlockStylesLogicActions|
|
|
28
|
+
export function layeredBlockStylesLogic(state: LayeredBlockStylesLogicState, action: LayeredBlockStylesLogicActions|WorkableUnknownAction): typeof state {
|
|
29
29
|
switch (action.type) {
|
|
30
30
|
case "ADD_LAYERED_BLOCK_STYLES":
|
|
31
31
|
return produce(state, (draft: typeof state) => {
|
|
@@ -13,7 +13,7 @@ import type {
|
|
|
13
13
|
PreppedSimpleNativePanelsAndTabs
|
|
14
14
|
} from "../../blocks/simple-native-property-internal-shared";
|
|
15
15
|
import {BareProperties, NamedBlockAction, store} from "../gutenberg-api-extensions-state";
|
|
16
|
-
import {BlockName, isBlockJsonNativePropsConfig, RegisterBlockAttrs,
|
|
16
|
+
import {BlockName, isBlockJsonNativePropsConfig, RegisterBlockAttrs, WorkableUnknownAction} from "../useful-types";
|
|
17
17
|
|
|
18
18
|
export type SNPLogicState = {
|
|
19
19
|
desiccatedProperties: {[blockName in BlockName]?: Array<SimpleNativePanel|SimpleNativeTab>},
|
|
@@ -67,7 +67,7 @@ export const snpLogicSelectors = {
|
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
-
export function snpLogic(state: SNPLogicState, action: SNPLogicActions|
|
|
70
|
+
export function snpLogic(state: SNPLogicState, action: SNPLogicActions|WorkableUnknownAction) {
|
|
71
71
|
switch (action.type) {
|
|
72
72
|
case "ADD_PROPERTIES":
|
|
73
73
|
return produce(state, (draft: typeof state) => {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
layeredBlockStylesLogic, layeredBlockStylesLogicActions, LayeredBlockStylesLogicActions, layeredBlockStylesLogicSelectors, LayeredBlockStylesLogicState
|
|
11
11
|
} from "./gutenberg-api-extensions-state/layered-block-styles-logic";
|
|
12
12
|
import {snpLogic, snpLogicActions, SNPLogicActions, snpLogicSelectors, SNPLogicState} from "./gutenberg-api-extensions-state/snp-logic";
|
|
13
|
-
import {combineSelectors
|
|
13
|
+
import {combineSelectors} from "./helpers";
|
|
14
14
|
import type {BlockName} from "./useful-types";
|
|
15
15
|
|
|
16
16
|
export type State = {
|
|
@@ -42,7 +42,7 @@ const DEFAULT_STATE: State = {
|
|
|
42
42
|
|
|
43
43
|
type ReducerActions = CustomBlockBindingsSupportLogicActions|LayeredBlockStylesLogicActions|SNPLogicActions|GeneralLogicActions;
|
|
44
44
|
|
|
45
|
-
export const store = createReduxStore('plaudit/gutenberg-api-extensions',
|
|
45
|
+
export const store = createReduxStore('plaudit/gutenberg-api-extensions', {
|
|
46
46
|
initialState: DEFAULT_STATE,
|
|
47
47
|
reducer: combineReducers({
|
|
48
48
|
customBlockBindingsSupportLogic,
|
|
@@ -62,7 +62,7 @@ export const store = createReduxStore('plaudit/gutenberg-api-extensions', withEx
|
|
|
62
62
|
snpLogic: snpLogicSelectors,
|
|
63
63
|
generalLogic: generalLogicSelectors
|
|
64
64
|
})
|
|
65
|
-
})
|
|
65
|
+
});
|
|
66
66
|
|
|
67
67
|
export function registerStore() {
|
|
68
68
|
register(store);
|
package/src/lib/helpers.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type * as MetaActions from "@wordpress/data/redux-store/metadata/actions";
|
|
3
|
-
import type * as MetaSelectors from "@wordpress/data/redux-store/metadata/selectors";
|
|
4
|
-
|
|
5
|
-
import type {store as apiStore} from "./gutenberg-api-extensions-state";
|
|
6
|
-
import type {store as endpointsStore} from "../editor/simple-gutenberg-endpoints-impl";
|
|
7
|
-
import type {PromisifyFunctionReturns, SubsequentArgsOfFunc} from "./useful-types";
|
|
1
|
+
import type {SubsequentArgsOfFunc} from "./useful-types";
|
|
8
2
|
|
|
9
3
|
export function clone<T>(value: T): T {
|
|
10
4
|
if (value === null || value === undefined) {
|
|
@@ -15,14 +9,6 @@ export function clone<T>(value: T): T {
|
|
|
15
9
|
return typeof value === 'object' ? Object.fromEntries(Object.entries(value).map(([k, v]) => [k, clone(v)])) as T : value;
|
|
16
10
|
}
|
|
17
11
|
|
|
18
|
-
type Mapping<K> = K extends 'plaudit/gutenberg-api-extensions'|(typeof apiStore)
|
|
19
|
-
? PromisifyFunctionReturns<ReturnType<typeof select<typeof apiStore>>>
|
|
20
|
-
: K extends 'plaudit/simple-gutenberg-apis'|(typeof endpointsStore)
|
|
21
|
-
? PromisifyFunctionReturns<ReturnType<typeof select<typeof endpointsStore>>>
|
|
22
|
-
: never;
|
|
23
|
-
export const fixedResolveSelect:
|
|
24
|
-
(<K extends 'plaudit/gutenberg-api-extensions'|(typeof apiStore)|'plaudit/simple-gutenberg-apis'|(typeof endpointsStore)>(key: K) => Mapping<K>) = resolveSelect;
|
|
25
|
-
|
|
26
12
|
// This is madness. I do not know why it works, only that it does.
|
|
27
13
|
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
|
|
28
14
|
|
|
@@ -51,14 +37,6 @@ export function combineSelectors<S extends SelectorsArg<any>>(selectors: S) {
|
|
|
51
37
|
})) as CombinedSelectors<typeof selectors>;
|
|
52
38
|
}
|
|
53
39
|
|
|
54
|
-
export function withExposedWordpressMetadata<
|
|
55
|
-
State, Actions extends Record<Exclude<string, keyof typeof MetaActions>, ActionCreator>, Selectors extends Omit<Selectors, keyof typeof MetaSelectors>
|
|
56
|
-
>(
|
|
57
|
-
options: ReduxStoreConfig<State, Actions, Selectors>
|
|
58
|
-
): Omit<typeof options, 'actions'|'selectors'>&{actions: (typeof MetaActions)&(typeof options)['actions'], selectors: (typeof MetaSelectors)&(typeof options)['selectors']} {
|
|
59
|
-
return options as any;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
40
|
export class TemporalLRUCache<K, V extends NonNullable<any>|undefined> {
|
|
63
41
|
private readonly cache: Map<K, [V, number]> = new Map();
|
|
64
42
|
private timeout?: ReturnType<Window['setTimeout']>;
|
package/src/lib/useful-types.ts
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import {Block, BlockSupports} from "@wordpress/blocks";
|
|
2
|
-
import {
|
|
3
|
-
import {FormTokenField} from '@wordpress/components';
|
|
4
|
-
import type * as MetaActions from "@wordpress/data/redux-store/metadata/actions";
|
|
5
|
-
import type * as MetaSelectors from "@wordpress/data/redux-store/metadata/selectors";
|
|
1
|
+
import type {Block, BlockSupports} from "@wordpress/blocks";
|
|
2
|
+
import type {FormTokenField} from '@wordpress/components';
|
|
6
3
|
|
|
7
4
|
import type {ComponentProps} from "react";
|
|
8
5
|
|
|
9
6
|
import type {PropertiesParameter} from "../blocks";
|
|
10
7
|
|
|
11
|
-
export type TokenItem = Exclude<NonNullable<ComponentProps<typeof FormTokenField>['value']>[number], string
|
|
12
|
-
|
|
13
|
-
export type NormalizedReduxActionExtractor<V> = V extends {[key in string]: (...args: any[]) => infer R}
|
|
14
|
-
? NormalizedReduxActionExtractor<R> : V extends {type: string} ? V : (V extends (...args: any[]) => {type: string} ? ReturnType<V> : never);
|
|
15
|
-
export type WordPressMetaActions = NormalizedReduxActionExtractor<typeof MetaActions>;
|
|
8
|
+
export type TokenItem = Exclude<NonNullable<ComponentProps<typeof FormTokenField>['value']>[number], string>;
|
|
9
|
+
export type WorkableUnknownAction = {type: "@@UNKNOWN_ACTION"};
|
|
16
10
|
|
|
17
11
|
export type SubsequentArgsOfFunc<F> = F extends (arg: any, ...args: infer R) => any ? R : never;
|
|
18
12
|
|
|
@@ -45,16 +39,6 @@ export type NonEmptyArray<T> = [T, ...T[]];
|
|
|
45
39
|
export function arrayIsNotEmpty<T>(arr: T[]|null|undefined): arr is NonEmptyArray<T> {
|
|
46
40
|
return !!arr && arr.length > 0;
|
|
47
41
|
}
|
|
48
|
-
|
|
49
|
-
type CurriedWordPressMetaSelectors = {[key in keyof typeof MetaSelectors]: (...args: SubsequentArgsOfFunc<(typeof MetaSelectors)[key]>) => ReturnType<(typeof MetaSelectors)[key]>};
|
|
50
|
-
export type MinThunkParams<S, A> = {
|
|
51
|
-
select<R>(selector: (state: {root: S}) => R): R, dispatch(action: A|WordPressMetaActions): Promise<unknown>, resolveSelect: any
|
|
52
|
-
};
|
|
53
|
-
export type ThunkParams<T extends StoreDescriptor, S, A> = {
|
|
54
|
-
select: ReturnType<typeof select<T>>&{<R>(selector: (state: {root: S}) => R): R},
|
|
55
|
-
dispatch: ReturnType<typeof dispatch<T>>&{(action: A|(typeof MetaActions)): Promise<unknown>},
|
|
56
|
-
resolveSelect: PromisifyFunctionReturns<ReturnType<typeof select<T>>>
|
|
57
|
-
};
|
|
58
42
|
export type PromisifyFunctionReturns<T extends {[K in string]: (...args: any[]) => any}> = {[K in keyof T]: (...args: Parameters<T[K]>) => Promise<ReturnType<T[K]>>};
|
|
59
43
|
|
|
60
44
|
export type WPTaxonomyQuery = {
|