@plaudit/gutenberg-api-extensions 2.84.3 → 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 +4 -0
- 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 -2
- 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.d.ts +1 -1
- 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 +0 -5
- package/dist/lib/helpers.js +0 -4
- package/dist/lib/helpers.js.map +1 -1
- package/package.json +14 -14
- 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 +3 -3
- 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.ts +3 -3
- package/src/lib/helpers.ts +0 -10
|
@@ -89,10 +89,10 @@ export type SimpleNativeProperty = GenericSimpleNativeProperty<string, 'string'>
|
|
|
89
89
|
} | GenericSimpleNativeProperty<boolean, 'boolean'> | GenericSimpleNativeProperty<any[], 'array'> | GenericSimpleNativeProperty<Record<string | number, unknown>, 'object'>;
|
|
90
90
|
export type PDSimpleNativeProperty = SimpleNativeProperty | CSNPConfig;
|
|
91
91
|
export type PotentiallyDesiccatedSimpleNativeProperty = PDSimpleNativeProperty;
|
|
92
|
-
export type HydratedSimpleNativeProperty = SimpleNativeProperty & {
|
|
92
|
+
export type HydratedSimpleNativeProperty<ADDITIONAL_DATA extends Record<string, any> = {}> = SimpleNativeProperty & ADDITIONAL_DATA & {
|
|
93
93
|
children?: {
|
|
94
|
-
[subtype: string]: HydratedSimpleNativeProperty[];
|
|
95
|
-
} | HydratedSimpleNativeProperty[];
|
|
94
|
+
[subtype: string]: HydratedSimpleNativeProperty<ADDITIONAL_DATA>[];
|
|
95
|
+
} | HydratedSimpleNativeProperty<ADDITIONAL_DATA>[];
|
|
96
96
|
controlType?: string;
|
|
97
97
|
branching?: boolean;
|
|
98
98
|
initializing?: ReactNode | (() => ReactNode);
|
|
@@ -30,4 +30,3 @@ export type PreppedSimpleNativePanelsAndTabs = {
|
|
|
30
30
|
tabs: HydratedInspectorPanelGroupedTabs;
|
|
31
31
|
};
|
|
32
32
|
export declare function isRootLevelPanelGroup(panelGroup: string | undefined): panelGroup is "default" | "settings" | "advanced" | "styles" | undefined;
|
|
33
|
-
export declare function buildDefaultValueFromDefinition(definition: HydratedSimpleNativeProperty | undefined, requireNonNullValueOnObject?: boolean): any;
|
|
@@ -1,36 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isRootLevelPanelGroup = isRootLevelPanelGroup;
|
|
4
|
-
exports.buildDefaultValueFromDefinition = buildDefaultValueFromDefinition;
|
|
5
4
|
function isRootLevelPanelGroup(panelGroup) {
|
|
6
5
|
return panelGroup === undefined || panelGroup === "default" || panelGroup === "advanced" || panelGroup === "settings" || panelGroup === "styles";
|
|
7
6
|
}
|
|
8
|
-
function buildDefaultValueFromDefinition(definition, requireNonNullValueOnObject = true) {
|
|
9
|
-
if (definition === undefined) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
else if (definition.default !== undefined) {
|
|
13
|
-
return structuredClone(definition.default);
|
|
14
|
-
}
|
|
15
|
-
const typedChildren = Array.isArray(definition.children) ? definition.children : undefined;
|
|
16
|
-
if (!typedChildren?.length) {
|
|
17
|
-
return structuredClone(definition.default);
|
|
18
|
-
}
|
|
19
|
-
else if (definition.type === 'array') {
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
|
-
else if (definition.type !== 'object') {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
const res = Object.fromEntries(typedChildren.map(def => [def.name, buildDefaultValueFromDefinition(def)]));
|
|
26
|
-
if (requireNonNullValueOnObject) {
|
|
27
|
-
for (const value of Object.values(res)) {
|
|
28
|
-
if (value !== undefined) {
|
|
29
|
-
return res;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
return res;
|
|
35
|
-
}
|
|
36
7
|
//# sourceMappingURL=simple-native-property-internal-shared.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-native-property-internal-shared.js","sourceRoot":"","sources":["../../src/blocks/simple-native-property-internal-shared.ts"],"names":[],"mappings":";;AAgBA,sDAEC;
|
|
1
|
+
{"version":3,"file":"simple-native-property-internal-shared.js","sourceRoot":"","sources":["../../src/blocks/simple-native-property-internal-shared.ts"],"names":[],"mappings":";;AAgBA,sDAEC;AAFD,SAAgB,qBAAqB,CAAC,UAA4B;IACjE,OAAO,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,UAAU,IAAI,UAAU,KAAK,UAAU,IAAI,UAAU,KAAK,QAAQ,CAAC;AAClJ,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UUID } from "./data-controller/utils";
|
|
1
2
|
import type { ActualBlockEditProps, BlockName } from "../lib/useful-types";
|
|
2
3
|
import type { DataStore, HydratedSimpleNativeProperty } from "./simple-native-property-api";
|
|
3
4
|
export declare abstract class SNPDataStore implements DataStore {
|
|
@@ -17,5 +18,7 @@ export declare abstract class SNPDataStore implements DataStore {
|
|
|
17
18
|
protected setRawBlockAttributes(attributes: Record<string, any>): void;
|
|
18
19
|
protected getCachedValue(attr: string): any;
|
|
19
20
|
protected hasCachedValue(attr: string): boolean;
|
|
20
|
-
addProperty(property: HydratedSimpleNativeProperty
|
|
21
|
+
addProperty(property: HydratedSimpleNativeProperty<{
|
|
22
|
+
uuid: UUID;
|
|
23
|
+
}>, writeThroughOnUndefined?: boolean): void;
|
|
21
24
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SNPDataStore = void 0;
|
|
4
4
|
const block_editor_1 = require("@wordpress/block-editor");
|
|
5
5
|
const data_1 = require("@wordpress/data");
|
|
6
|
-
const
|
|
6
|
+
const utils_1 = require("./data-controller/utils");
|
|
7
7
|
class SNPDataStore {
|
|
8
8
|
attributeCache;
|
|
9
9
|
id;
|
|
@@ -52,10 +52,10 @@ class SNPDataStore {
|
|
|
52
52
|
}
|
|
53
53
|
if (this.getAttribute(property.name) === undefined) {
|
|
54
54
|
if (writeThroughOnUndefined) {
|
|
55
|
-
this.setValue(property.name, (0,
|
|
55
|
+
this.setValue(property.name, (0, utils_1.buildDefaultValueFromDefinition)(property));
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
58
|
-
this.attributeCache[property.name] = (0,
|
|
58
|
+
this.attributeCache[property.name] = (0, utils_1.buildDefaultValueFromDefinition)(property);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
this.managedPropertyNames[property.name] = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snp-data-store.js","sourceRoot":"","sources":["../../src/blocks/snp-data-store.ts"],"names":[],"mappings":";;;AAAA,0DAAkE;AAClE,0CAAiD;
|
|
1
|
+
{"version":3,"file":"snp-data-store.js","sourceRoot":"","sources":["../../src/blocks/snp-data-store.ts"],"names":[],"mappings":";;;AAAA,0DAAkE;AAClE,0CAAiD;AAEjD,mDAA8E;AAI9E,MAAsB,YAAY;IAQxB;IACQ;IARA,oBAAoB,CAAmC;IAErD,aAAa,CAAS;IACtB,SAAS,CAAY;IAExC,YACC,sBAA4C,EACpC,cAAmC,EAC3B,EAAU;QADlB,mBAAc,GAAd,cAAc,CAAqB;QAC3B,OAAE,GAAF,EAAE,CAAQ;QAE1B,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEhD,IAAI,CAAC,aAAa,GAAG,sBAAsB,CAAC,QAAQ,CAAC;QACrD,IAAI,CAAC,SAAS,GAAG,sBAAsB,CAAC,IAAI,CAAC;IAC9C,CAAC;IAED,QAAQ,CAAC,IAAY;QACpB,IAAI,IAAI,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;QACD,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC;IAClD,CAAC;IACD,QAAQ,CAAC,IAAY,EAAE,KAAU;QAChC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAClC,OAAO,IAAI,CAAC,YAAY,C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IAAI,CAAC,GAAG,IAAI,CAAC;IACjD,CAAC;CACD;AAnED,oCAmEC"}
|
|
@@ -15,7 +15,7 @@ export type NamedBlockAction<A extends string, P = {}> = {
|
|
|
15
15
|
type: A;
|
|
16
16
|
blockName: BlockName;
|
|
17
17
|
} & P;
|
|
18
|
-
export declare const store: import("@wordpress/data").StoreDescriptor<import("@wordpress/data").ReduxStoreConfig<State,
|
|
18
|
+
export declare const store: import("@wordpress/data").StoreDescriptor<import("@wordpress/data").ReduxStoreConfig<State, {
|
|
19
19
|
recordBaselineBlockAttrs(attrs: import("./useful-types").RegisterBlockAttrs<Record<string, any>>): GeneralLogicActions;
|
|
20
20
|
setFeatureProp(feature: string, prop: string, value: any): GeneralLogicActions;
|
|
21
21
|
addProperties(blockName: BlockName | BlockName[], properties: BareProperties): SNPLogicActions;
|
|
@@ -25,7 +25,7 @@ const DEFAULT_STATE = {
|
|
|
25
25
|
baselineBlockAttrs: {}, features: {}
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
-
exports.store = (0, data_1.createReduxStore)('plaudit/gutenberg-api-extensions',
|
|
28
|
+
exports.store = (0, data_1.createReduxStore)('plaudit/gutenberg-api-extensions', {
|
|
29
29
|
initialState: DEFAULT_STATE,
|
|
30
30
|
reducer: (0, data_1.combineReducers)({
|
|
31
31
|
customBlockBindingsSupportLogic: custom_block_bindings_support_logic_1.customBlockBindingsSupportLogic,
|
|
@@ -45,7 +45,7 @@ exports.store = (0, data_1.createReduxStore)('plaudit/gutenberg-api-extensions',
|
|
|
45
45
|
snpLogic: snp_logic_1.snpLogicSelectors,
|
|
46
46
|
generalLogic: general_logic_1.generalLogicSelectors
|
|
47
47
|
})
|
|
48
|
-
})
|
|
48
|
+
});
|
|
49
49
|
function registerStore() {
|
|
50
50
|
(0, data_1.register)(exports.store);
|
|
51
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gutenberg-api-extensions-state.js","sourceRoot":"","sources":["../../src/lib/gutenberg-api-extensions-state.ts"],"names":[],"mappings":";;;AAkEA,sCAEC;AApED,0CAA4E;AAG5E,8HAG8E;AAC9E,kFAAgK;AAChK,4GAEqE;AACrE,0EAAwI;AACxI,
|
|
1
|
+
{"version":3,"file":"gutenberg-api-extensions-state.js","sourceRoot":"","sources":["../../src/lib/gutenberg-api-extensions-state.ts"],"names":[],"mappings":";;;AAkEA,sCAEC;AApED,0CAA4E;AAG5E,8HAG8E;AAC9E,kFAAgK;AAChK,4GAEqE;AACrE,0EAAwI;AACxI,uCAA2C;AAY3C,MAAM,aAAa,GAAU;IAC5B,+BAA+B,EAAE;QAChC,0BAA0B,EAAE,EAAE;KAC9B;IACD,uBAAuB,EAAE;QACxB,kBAAkB,EAAE,EAAE;KACtB;IACD,QAAQ,EAAE;QACT,oBAAoB,EAAE,EAAE;QACxB,iBAAiB,EAAE,EAAE;QACrB,mBAAmB,EAAE,EAAE;QACvB,2BAA2B,EAAE,EAAE;KAC/B;IACD,YAAY,EAAE;QACb,kBAAkB,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE;KACpC;CACD,CAAC;AAIW,QAAA,KAAK,GAAG,IAAA,uBAAgB,EAAC,kCAAkC,EAAE;IACzE,YAAY,EAAE,aAAa;IAC3B,OAAO,EAAE,IAAA,sBAAe,EAAC;QACxB,+BAA+B,EAA/B,qEAA+B;QAC/B,uBAAuB,EAAvB,oDAAuB;QACvB,QAAQ,EAAR,oBAAQ;QACR,YAAY,EAAZ,4BAAY;KACZ,CAAC;IACF,OAAO,EAAE;QACR,GAAG,4EAAsC;QACzC,GAAG,2DAA8B;QACjC,GAAG,2BAAe;QAClB,GAAG,mCAAmB;KACtB;IACD,SAAS,EAAE,IAAA,0BAAgB,EAAC;QAC3B,+BAA+B,EAAE,8EAAwC;QACzE,uBAAuB,EAAE,6DAAgC;QACzD,QAAQ,EAAE,6BAAiB;QAC3B,YAAY,EAAE,qCAAqB;KACnC,CAAC;CACF,CAAC,CAAC;AAEH,SAAgB,aAAa;IAC5B,IAAA,eAAQ,EAAC,aAAK,CAAC,CAAC;AACjB,CAAC"}
|
package/dist/lib/helpers.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ActionCreator, MetaAction, ReduxStoreConfig } from "@wordpress/data";
|
|
2
1
|
import type { SubsequentArgsOfFunc } from "./useful-types";
|
|
3
2
|
export declare function clone<T>(value: T): T;
|
|
4
3
|
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
|
|
@@ -19,10 +18,6 @@ type SelectorsArg<S extends {}> = {
|
|
|
19
18
|
};
|
|
20
19
|
};
|
|
21
20
|
export declare function combineSelectors<S extends SelectorsArg<any>>(selectors: S): CombinedSelectors<typeof selectors>;
|
|
22
|
-
export declare function withExposedWordpressMetadata<State, Actions extends Record<Exclude<string, MetaAction['type']>, ActionCreator>, Selectors extends Omit<Selectors, keyof {}>>(options: ReduxStoreConfig<State, Actions, Selectors>): Omit<typeof options, 'actions' | 'selectors'> & {
|
|
23
|
-
actions: (Record<MetaAction['type'], ActionCreator>) & (typeof options)['actions'];
|
|
24
|
-
selectors: (typeof options)['selectors'];
|
|
25
|
-
};
|
|
26
21
|
export declare class TemporalLRUCache<K, V extends NonNullable<any> | undefined> {
|
|
27
22
|
private readonly capacity;
|
|
28
23
|
private readonly minDroppableAccessTime;
|
package/dist/lib/helpers.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TemporalLRUCache = void 0;
|
|
4
4
|
exports.clone = clone;
|
|
5
5
|
exports.combineSelectors = combineSelectors;
|
|
6
|
-
exports.withExposedWordpressMetadata = withExposedWordpressMetadata;
|
|
7
6
|
function clone(value) {
|
|
8
7
|
if (value === null || value === undefined) {
|
|
9
8
|
return value;
|
|
@@ -23,9 +22,6 @@ function combineSelectors(selectors) {
|
|
|
23
22
|
});
|
|
24
23
|
}));
|
|
25
24
|
}
|
|
26
|
-
function withExposedWordpressMetadata(options) {
|
|
27
|
-
return options;
|
|
28
|
-
}
|
|
29
25
|
class TemporalLRUCache {
|
|
30
26
|
capacity;
|
|
31
27
|
minDroppableAccessTime;
|
package/dist/lib/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/lib/helpers.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/lib/helpers.ts"],"names":[],"mappings":";;;AAEA,sBAOC;AAmBD,4CASC;AAnCD,SAAgB,KAAK,CAAI,KAAQ;IAChC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC3C,OAAO,KAAK,CAAC;IACd,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAM,CAAC;IACtC,CAAC;IACD,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAM,CAAC,CAAC,CAAC,KAAK,CAAC;AAC1H,CAAC;AAmBD,SAAgB,gBAAgB,CAA8B,SAAY;IACzE,OAAO,MAAM,CAAC,WAAW,CAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAA6B,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QAC9F,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QACnB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAA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4CAmDC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/gutenberg-api-extensions",
|
|
3
|
-
"version": "2.84.
|
|
3
|
+
"version": "2.84.4",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
5
5
|
"files": [
|
|
6
6
|
"./dist",
|
|
@@ -22,22 +22,22 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@reduxjs/toolkit": "^2.11.2",
|
|
25
|
-
"@types/react": "^18.3.
|
|
25
|
+
"@types/react": "^18.3.28",
|
|
26
26
|
"@types/wordpress__block-editor": "^15.0.0",
|
|
27
27
|
"@types/wordpress__blocks": "^12.5.18",
|
|
28
|
-
"@wordpress/block-editor": "^15.
|
|
29
|
-
"@wordpress/blocks": "^15.
|
|
28
|
+
"@wordpress/block-editor": "^15.12.0",
|
|
29
|
+
"@wordpress/blocks": "^15.12.0",
|
|
30
30
|
"@wordpress/components": "^30.9.0",
|
|
31
|
-
"@wordpress/compose": "^7.
|
|
32
|
-
"@wordpress/core-data": "^7.
|
|
33
|
-
"@wordpress/data": "^10.
|
|
34
|
-
"@wordpress/editor": "^14.
|
|
35
|
-
"@wordpress/element": "^6.
|
|
36
|
-
"@wordpress/hooks": "^4.
|
|
37
|
-
"@wordpress/i18n": "^6.
|
|
38
|
-
"@wordpress/icons": "^11.
|
|
39
|
-
"framer-motion": "^12.
|
|
40
|
-
"html-react-parser": "^5.2.
|
|
31
|
+
"@wordpress/compose": "^7.39.0",
|
|
32
|
+
"@wordpress/core-data": "^7.39.0",
|
|
33
|
+
"@wordpress/data": "^10.39.0",
|
|
34
|
+
"@wordpress/editor": "^14.39.0",
|
|
35
|
+
"@wordpress/element": "^6.39.0",
|
|
36
|
+
"@wordpress/hooks": "^4.39.0",
|
|
37
|
+
"@wordpress/i18n": "^6.12.0",
|
|
38
|
+
"@wordpress/icons": "^11.6.0",
|
|
39
|
+
"framer-motion": "^12.33.0",
|
|
40
|
+
"html-react-parser": "^5.2.16",
|
|
41
41
|
"immer": "^11.1.3",
|
|
42
42
|
"react": "^18.3.1",
|
|
43
43
|
"react-dom": "^18.3.1",
|
|
@@ -23,16 +23,14 @@ import {
|
|
|
23
23
|
FullSizeToggleControl, ToggleGroupControlOptionWithOptionalIcon, ExtendedTaxonomyPicker, ExtendedTermPicker, ExtendedUserPicker
|
|
24
24
|
} from "../controls";
|
|
25
25
|
import {normalizePickableOptionsToObjects, normalizePickableOptionsToPairs} from "../controls/shared";
|
|
26
|
+
import {recordCloneableDefaultValueForNode} from "./data-controller/utils";
|
|
26
27
|
import {useSuspendableOptions} from "./hooks/useSuspendableOptions";
|
|
27
28
|
import {makeToolsPanelContextValue, ToolsPanelContext} from "./layout/ToolsPanelContext";
|
|
28
29
|
import {store as gutenbergApiExtensionsStore} from "../lib/gutenberg-api-extensions-state";
|
|
29
30
|
import {clone} from "../lib/helpers";
|
|
30
31
|
import {arrayIsNotEmpty, BlockName} from "../lib/useful-types";
|
|
31
32
|
import type {CSNPControlComponentProps} from "./shared-internal-types";
|
|
32
|
-
import {
|
|
33
|
-
GenericSimpleNativeProperty,
|
|
34
|
-
HydratedSimpleNativeProperty, PDSimpleNativeProperty, SNPControlProps, SNPControlSlots
|
|
35
|
-
} from "./simple-native-property-api";
|
|
33
|
+
import type {GenericSimpleNativeProperty, HydratedSimpleNativeProperty, PDSimpleNativeProperty, SNPControlProps, SNPControlSlots} from "./simple-native-property-api";
|
|
36
34
|
import {SNPFlexibleItemsListComponent} from "./SNPFlexibleItemsListComponent";
|
|
37
35
|
import {SNPGroupComponent} from "./SNPGroupComponent";
|
|
38
36
|
import {SNPListComponent} from "./SNPListComponent";
|
|
@@ -54,8 +52,8 @@ export function hydrateSimpleNativeProperty(
|
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
config = applyFilters('plaudit.gutenbergApiExtensions.simpleNativeProperties.field', config, outsideHydrationInfo.blockName, propPath) as typeof config;
|
|
57
|
-
const res = typeof config.control === 'string'
|
|
58
|
-
? hydrateDesiccatedSimpleNativeProperty(config, propPath, outsideHydrationInfo, parentTypes) : config;
|
|
55
|
+
const res = recordCloneableDefaultValueForNode(typeof config.control === 'string'
|
|
56
|
+
? hydrateDesiccatedSimpleNativeProperty(config, propPath, outsideHydrationInfo, parentTypes) : config);
|
|
59
57
|
validateAndRecordPotentialStyleProperty(res, propPath, outsideHydrationInfo, parentTypes);
|
|
60
58
|
return res;
|
|
61
59
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {HydratedLaidOutProperties} from "../simple-native-property-internal-shared";
|
|
1
|
+
import type {HydratedLaidOutProperties} from "../simple-native-property-internal-shared";
|
|
2
2
|
import type {DataStore} from "../simple-native-property-api";
|
|
3
3
|
import {createGlobalAction, createPathedAction} from "./trigger-handlers";
|
|
4
4
|
|
|
@@ -4,14 +4,13 @@ import {produce} from "immer";
|
|
|
4
4
|
import {actions} from "./actions";
|
|
5
5
|
import {DCStoreState, walkToNodeInValue} from "../data-controller";
|
|
6
6
|
import {PathError} from "../PathError";
|
|
7
|
-
import {buildDefaultValueFromDefinition} from "../simple-native-property-internal-shared";
|
|
8
7
|
import type {HydratedSimpleNativeProperty} from "../simple-native-property-api";
|
|
9
8
|
import {triggerHandlers, validateFoundNode} from "./trigger-handlers";
|
|
10
9
|
import {
|
|
11
|
-
applyToTree,
|
|
10
|
+
applyToTree, buildDefaultValueFromDefinition,
|
|
12
11
|
buildNodeFromDataAndDefinition, getDataStore,
|
|
13
12
|
moveNodeWithinParent,
|
|
14
|
-
populateValueBasedOnDefinition,
|
|
13
|
+
populateValueBasedOnDefinition, recordCloneableDefaultValueForNode,
|
|
15
14
|
removeFromParentNode, removeValueFromBackingDataStore,
|
|
16
15
|
resolveParentNodeDefinition, TreeMutatorResult,
|
|
17
16
|
walkToNode, writeValueToBackingDataStoreWithCorrections
|
|
@@ -32,7 +31,7 @@ export function buildReducer(blockClientId: string) {
|
|
|
32
31
|
for (const property of properties) {
|
|
33
32
|
for (const prop of Array.isArray(property) ? property : [property]) {
|
|
34
33
|
if (dataStore.getValue(prop.name) === undefined && meta.inBatch) {
|
|
35
|
-
state.batchAddedPropertiesThatNeedWriteThrough.push(prop);
|
|
34
|
+
state.batchAddedPropertiesThatNeedWriteThrough.push(recordCloneableDefaultValueForNode(prop));
|
|
36
35
|
}
|
|
37
36
|
dataStore.addProperty(prop, !meta.inBatch);
|
|
38
37
|
state.dataStores.byProperty[prop.name] = dataStore;
|
|
@@ -4,10 +4,10 @@ import type {Draft} from "immer";
|
|
|
4
4
|
import type {NodePath, RawPath} from "../simple-native-property-api";
|
|
5
5
|
import {PathError} from "../PathError";
|
|
6
6
|
import type {DCNode, DCStoreState} from "../data-controller";
|
|
7
|
-
import {buildDefaultValueFromDefinition} from "../simple-native-property-internal-shared";
|
|
8
7
|
import {resolveValueForCondition, testCondition} from "../conditions";
|
|
9
8
|
import {
|
|
10
9
|
applyToTree,
|
|
10
|
+
buildDefaultValueFromDefinition,
|
|
11
11
|
getDataStore,
|
|
12
12
|
getOptionalValue,
|
|
13
13
|
removeValueFromBackingDataStore,
|
|
@@ -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
|
}
|
|
@@ -11,7 +11,7 @@ import type {DataController, DataStore, HydratedSimpleNativeProperty, NodePath}
|
|
|
11
11
|
|
|
12
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";
|
|
14
|
+
import {getDataStore, getOptionalValue, UUID, walkToNode} from "./data-controller/utils";
|
|
15
15
|
|
|
16
16
|
type DescendantsWrapper = {[key: string]: DCNode}|DCNode[];
|
|
17
17
|
export type DCNode = {
|
|
@@ -19,7 +19,7 @@ export type DCNode = {
|
|
|
19
19
|
rendered?: boolean,
|
|
20
20
|
condition?: Condition,
|
|
21
21
|
children?: DescendantsWrapper,
|
|
22
|
-
definition?: HydratedSimpleNativeProperty
|
|
22
|
+
definition?: HydratedSimpleNativeProperty<{uuid: UUID}>,
|
|
23
23
|
validationError?: string
|
|
24
24
|
};
|
|
25
25
|
export type DCStoreState = {
|
|
@@ -28,7 +28,7 @@ export type DCStoreState = {
|
|
|
28
28
|
blockClientId: string,
|
|
29
29
|
changedByManagedControl: boolean,
|
|
30
30
|
rerenderTrigger: number,
|
|
31
|
-
batchAddedPropertiesThatNeedWriteThrough: HydratedSimpleNativeProperty[]
|
|
31
|
+
batchAddedPropertiesThatNeedWriteThrough: HydratedSimpleNativeProperty<{uuid: UUID}>[]
|
|
32
32
|
};
|
|
33
33
|
type DCThunkDispatch = ThunkDispatch<DCStoreState, unknown, DataControllerActions>;
|
|
34
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
|
}
|
|
@@ -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,5 +1,3 @@
|
|
|
1
|
-
import type {ActionCreator, MetaAction, ReduxStoreConfig} from "@wordpress/data";
|
|
2
|
-
|
|
3
1
|
import type {SubsequentArgsOfFunc} from "./useful-types";
|
|
4
2
|
|
|
5
3
|
export function clone<T>(value: T): T {
|
|
@@ -39,14 +37,6 @@ export function combineSelectors<S extends SelectorsArg<any>>(selectors: S) {
|
|
|
39
37
|
})) as CombinedSelectors<typeof selectors>;
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
export function withExposedWordpressMetadata<
|
|
43
|
-
State, Actions extends Record<Exclude<string, MetaAction['type']>, ActionCreator>, Selectors extends Omit<Selectors, keyof {}>
|
|
44
|
-
>(
|
|
45
|
-
options: ReduxStoreConfig<State, Actions, Selectors>
|
|
46
|
-
): Omit<typeof options, 'actions'|'selectors'>&{actions: (Record<MetaAction['type'], ActionCreator>)&(typeof options)['actions'], selectors: (typeof options)['selectors']} {
|
|
47
|
-
return options as any;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
40
|
export class TemporalLRUCache<K, V extends NonNullable<any>|undefined> {
|
|
51
41
|
private readonly cache: Map<K, [V, number]> = new Map();
|
|
52
42
|
private timeout?: ReturnType<Window['setTimeout']>;
|