@wordpress/abilities 0.23.0 → 0.25.0
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/build/api.cjs +176 -122
- package/build/api.cjs.map +1 -7
- package/build/index.cjs +73 -52
- package/build/store/actions.cjs +119 -187
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +23 -47
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +36 -40
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +102 -94
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +49 -58
- package/build/store/selectors.cjs.map +1 -7
- package/build/store/types.cjs +4 -18
- package/build/types.cjs +4 -18
- package/build/validation.cjs +122 -137
- package/build/validation.cjs.map +1 -7
- package/build-module/api.mjs +161 -87
- package/build-module/api.mjs.map +1 -7
- package/build-module/index.mjs +2 -26
- package/build-module/store/actions.mjs +112 -167
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +13 -17
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +11 -9
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +97 -78
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +42 -31
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/store/types.mjs +0 -1
- package/build-module/types.mjs +0 -1
- package/build-module/validation.mjs +101 -109
- package/build-module/validation.mjs.map +1 -7
- package/build-types/index.d.ts +1 -1
- package/package.json +7 -8
- package/src/index.ts +1 -1
- package/CHANGELOG.md +0 -65
- package/build/index.cjs.map +0 -7
- package/build/store/types.cjs.map +0 -7
- package/build/types.cjs.map +0 -7
- package/build-module/index.mjs.map +0 -7
- package/build-module/store/types.mjs.map +0 -7
- package/build-module/types.mjs.map +0 -7
package/build/store/actions.cjs
CHANGED
|
@@ -1,199 +1,131 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/abilities/src/store/actions.ts
|
|
21
|
-
var actions_exports = {};
|
|
22
|
-
__export(actions_exports, {
|
|
23
|
-
registerAbility: () => registerAbility,
|
|
24
|
-
registerAbilityCategory: () => registerAbilityCategory,
|
|
25
|
-
unregisterAbility: () => unregisterAbility,
|
|
26
|
-
unregisterAbilityCategory: () => unregisterAbilityCategory
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
27
5
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
6
|
+
let _wordpress_i18n = require("@wordpress/i18n");
|
|
7
|
+
let __constants_ts = require("./constants.cjs");
|
|
8
|
+
// packages/abilities/src/store/actions.ts
|
|
9
|
+
/**
|
|
10
|
+
* Filters annotations to only include allowed keys with non-null values.
|
|
11
|
+
*
|
|
12
|
+
* @param sourceAnnotations The source annotations object to filter.
|
|
13
|
+
* @param allowedKeys Array of annotation keys to include.
|
|
14
|
+
* @return Filtered annotations object.
|
|
15
|
+
*/
|
|
31
16
|
function filterAnnotations(sourceAnnotations, allowedKeys) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return annotations;
|
|
17
|
+
const annotations = {};
|
|
18
|
+
if (sourceAnnotations) {
|
|
19
|
+
for (const key of allowedKeys) if (sourceAnnotations[key] !== void 0) annotations[key] = sourceAnnotations[key];
|
|
20
|
+
}
|
|
21
|
+
return annotations;
|
|
41
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Registers an ability in the store.
|
|
25
|
+
*
|
|
26
|
+
* This action validates the ability before registration. If validation fails,
|
|
27
|
+
* an error will be thrown.
|
|
28
|
+
*
|
|
29
|
+
* @param ability The ability to register.
|
|
30
|
+
* @return Action object or function.
|
|
31
|
+
* @throws {Error} If validation fails.
|
|
32
|
+
*/
|
|
42
33
|
function registerAbility(ability) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
)
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
const categories = select.getAbilityCategories();
|
|
77
|
-
const existingCategory = categories.find(
|
|
78
|
-
(cat) => cat.slug === ability.category
|
|
79
|
-
);
|
|
80
|
-
if (!existingCategory) {
|
|
81
|
-
throw new Error(
|
|
82
|
-
(0, import_i18n.sprintf)(
|
|
83
|
-
'Ability "%1$s" references non-existent category "%2$s". Please register the category first.',
|
|
84
|
-
ability.name,
|
|
85
|
-
ability.category
|
|
86
|
-
)
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
if (ability.callback && typeof ability.callback !== "function") {
|
|
90
|
-
throw new Error(
|
|
91
|
-
(0, import_i18n.sprintf)(
|
|
92
|
-
'Ability "%s" has an invalid callback. Callback must be a function',
|
|
93
|
-
ability.name
|
|
94
|
-
)
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
const existingAbility = select.getAbility(ability.name);
|
|
98
|
-
if (existingAbility) {
|
|
99
|
-
throw new Error(
|
|
100
|
-
(0, import_i18n.sprintf)('Ability "%s" is already registered', ability.name)
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
const annotations = filterAnnotations(ability.meta?.annotations, [
|
|
104
|
-
"readonly",
|
|
105
|
-
"destructive",
|
|
106
|
-
"idempotent",
|
|
107
|
-
"serverRegistered",
|
|
108
|
-
"clientRegistered"
|
|
109
|
-
]);
|
|
110
|
-
if (!annotations.serverRegistered) {
|
|
111
|
-
annotations.clientRegistered = true;
|
|
112
|
-
}
|
|
113
|
-
const meta = {
|
|
114
|
-
...ability.meta || {},
|
|
115
|
-
annotations
|
|
116
|
-
};
|
|
117
|
-
dispatch({
|
|
118
|
-
type: import_constants.REGISTER_ABILITY,
|
|
119
|
-
ability: {
|
|
120
|
-
...ability,
|
|
121
|
-
meta
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
};
|
|
34
|
+
return ({ select, dispatch }) => {
|
|
35
|
+
if (!ability.name) throw new Error("Ability name is required");
|
|
36
|
+
if (!__constants_ts.ABILITY_NAME_PATTERN.test(ability.name)) throw new Error("Ability name must be a string containing a namespace prefix with 2-4 segments, e.g. \"my-plugin/my-ability\" or \"core/posts/find\". It can only contain lowercase alphanumeric characters, dashes and the forward slash.");
|
|
37
|
+
if (!ability.label) throw new Error((0, _wordpress_i18n.sprintf)("Ability \"%s\" must have a label", ability.name));
|
|
38
|
+
if (!ability.description) throw new Error((0, _wordpress_i18n.sprintf)("Ability \"%s\" must have a description", ability.name));
|
|
39
|
+
if (!ability.category) throw new Error((0, _wordpress_i18n.sprintf)("Ability \"%s\" must have a category", ability.name));
|
|
40
|
+
if (!__constants_ts.CATEGORY_SLUG_PATTERN.test(ability.category)) throw new Error((0, _wordpress_i18n.sprintf)("Ability \"%1$s\" has an invalid category. Category must be lowercase alphanumeric with dashes only. Got: \"%2$s\"", ability.name, ability.category));
|
|
41
|
+
if (!select.getAbilityCategories().find((cat) => cat.slug === ability.category)) throw new Error((0, _wordpress_i18n.sprintf)("Ability \"%1$s\" references non-existent category \"%2$s\". Please register the category first.", ability.name, ability.category));
|
|
42
|
+
if (ability.callback && typeof ability.callback !== "function") throw new Error((0, _wordpress_i18n.sprintf)("Ability \"%s\" has an invalid callback. Callback must be a function", ability.name));
|
|
43
|
+
if (select.getAbility(ability.name)) throw new Error((0, _wordpress_i18n.sprintf)("Ability \"%s\" is already registered", ability.name));
|
|
44
|
+
const annotations = filterAnnotations(ability.meta?.annotations, [
|
|
45
|
+
"readonly",
|
|
46
|
+
"destructive",
|
|
47
|
+
"idempotent",
|
|
48
|
+
"serverRegistered",
|
|
49
|
+
"clientRegistered"
|
|
50
|
+
]);
|
|
51
|
+
if (!annotations.serverRegistered) annotations.clientRegistered = true;
|
|
52
|
+
const meta = {
|
|
53
|
+
...ability.meta || {},
|
|
54
|
+
annotations
|
|
55
|
+
};
|
|
56
|
+
dispatch({
|
|
57
|
+
type: __constants_ts.REGISTER_ABILITY,
|
|
58
|
+
ability: {
|
|
59
|
+
...ability,
|
|
60
|
+
meta
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
|
125
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns an action object used to unregister a client-side ability.
|
|
67
|
+
*
|
|
68
|
+
* @param name The name of the ability to unregister.
|
|
69
|
+
* @return Action object.
|
|
70
|
+
*/
|
|
126
71
|
function unregisterAbility(name) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
72
|
+
return {
|
|
73
|
+
type: __constants_ts.UNREGISTER_ABILITY,
|
|
74
|
+
name
|
|
75
|
+
};
|
|
131
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Registers a client-side ability category in the store.
|
|
79
|
+
*
|
|
80
|
+
* This action validates the category before registration. If validation fails,
|
|
81
|
+
* an error will be thrown.
|
|
82
|
+
*
|
|
83
|
+
* @param slug The unique category slug identifier.
|
|
84
|
+
* @param args Category arguments (label, description, optional meta).
|
|
85
|
+
* @return Action object or function.
|
|
86
|
+
* @throws {Error} If validation fails.
|
|
87
|
+
*/
|
|
132
88
|
function registerAbilityCategory(slug, args) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
if (args.meta !== void 0 && (typeof args.meta !== "object" || Array.isArray(args.meta))) {
|
|
159
|
-
throw new Error(
|
|
160
|
-
"The category properties should provide a valid `meta` object."
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
const annotations = filterAnnotations(args.meta?.annotations, [
|
|
164
|
-
"serverRegistered",
|
|
165
|
-
"clientRegistered"
|
|
166
|
-
]);
|
|
167
|
-
if (!annotations.serverRegistered) {
|
|
168
|
-
annotations.clientRegistered = true;
|
|
169
|
-
}
|
|
170
|
-
const meta = {
|
|
171
|
-
...args.meta || {},
|
|
172
|
-
annotations
|
|
173
|
-
};
|
|
174
|
-
const category = {
|
|
175
|
-
slug,
|
|
176
|
-
label: args.label,
|
|
177
|
-
description: args.description,
|
|
178
|
-
meta
|
|
179
|
-
};
|
|
180
|
-
dispatch({
|
|
181
|
-
type: import_constants.REGISTER_ABILITY_CATEGORY,
|
|
182
|
-
category
|
|
183
|
-
});
|
|
184
|
-
};
|
|
89
|
+
return ({ select, dispatch }) => {
|
|
90
|
+
if (!slug) throw new Error("Category slug is required");
|
|
91
|
+
if (!__constants_ts.CATEGORY_SLUG_PATTERN.test(slug)) throw new Error("Category slug must contain only lowercase alphanumeric characters and dashes.");
|
|
92
|
+
if (select.getAbilityCategory(slug)) throw new Error((0, _wordpress_i18n.sprintf)("Category \"%s\" is already registered.", slug));
|
|
93
|
+
if (!args.label || typeof args.label !== "string") throw new Error("The category properties must contain a `label` string.");
|
|
94
|
+
if (!args.description || typeof args.description !== "string") throw new Error("The category properties must contain a `description` string.");
|
|
95
|
+
if (args.meta !== void 0 && (typeof args.meta !== "object" || Array.isArray(args.meta))) throw new Error("The category properties should provide a valid `meta` object.");
|
|
96
|
+
const annotations = filterAnnotations(args.meta?.annotations, ["serverRegistered", "clientRegistered"]);
|
|
97
|
+
if (!annotations.serverRegistered) annotations.clientRegistered = true;
|
|
98
|
+
const meta = {
|
|
99
|
+
...args.meta || {},
|
|
100
|
+
annotations
|
|
101
|
+
};
|
|
102
|
+
const category = {
|
|
103
|
+
slug,
|
|
104
|
+
label: args.label,
|
|
105
|
+
description: args.description,
|
|
106
|
+
meta
|
|
107
|
+
};
|
|
108
|
+
dispatch({
|
|
109
|
+
type: __constants_ts.REGISTER_ABILITY_CATEGORY,
|
|
110
|
+
category
|
|
111
|
+
});
|
|
112
|
+
};
|
|
185
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Returns an action object used to unregister a client-side ability category.
|
|
116
|
+
*
|
|
117
|
+
* @param slug The slug of the category to unregister.
|
|
118
|
+
* @return Action object.
|
|
119
|
+
*/
|
|
186
120
|
function unregisterAbilityCategory(slug) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
121
|
+
return {
|
|
122
|
+
type: __constants_ts.UNREGISTER_ABILITY_CATEGORY,
|
|
123
|
+
slug
|
|
124
|
+
};
|
|
191
125
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
});
|
|
199
|
-
//# sourceMappingURL=actions.cjs.map
|
|
126
|
+
exports.registerAbility = registerAbility;
|
|
127
|
+
exports.registerAbilityCategory = registerAbilityCategory;
|
|
128
|
+
exports.unregisterAbility = unregisterAbility;
|
|
129
|
+
exports.unregisterAbilityCategory = unregisterAbilityCategory;
|
|
130
|
+
|
|
131
|
+
//# sourceMappingURL=actions.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/actions.ts"],
|
|
4
|
-
"sourcesContent": ["import { sprintf } from '@wordpress/i18n';\nimport type { Ability, AbilityCategory, AbilityCategoryArgs } from '../types';\nimport {\n\tREGISTER_ABILITY,\n\tUNREGISTER_ABILITY,\n\tREGISTER_ABILITY_CATEGORY,\n\tUNREGISTER_ABILITY_CATEGORY,\n\tABILITY_NAME_PATTERN,\n\tCATEGORY_SLUG_PATTERN,\n} from './constants';\n\ntype AbilityAnnotations = NonNullable< Ability[ 'meta' ] >[ 'annotations' ];\n\n/**\n * Filters annotations to only include allowed keys with non-null values.\n *\n * @param sourceAnnotations The source annotations object to filter.\n * @param allowedKeys Array of annotation keys to include.\n * @return Filtered annotations object.\n */\nfunction filterAnnotations< K extends keyof NonNullable< AbilityAnnotations > >(\n\tsourceAnnotations: Record< string, boolean > | undefined,\n\tallowedKeys: readonly K[]\n): NonNullable< AbilityAnnotations > {\n\tconst annotations: NonNullable< AbilityAnnotations > = {};\n\n\tif ( sourceAnnotations ) {\n\t\tfor ( const key of allowedKeys ) {\n\t\t\tif ( sourceAnnotations[ key ] !== undefined ) {\n\t\t\t\tannotations[ key ] = sourceAnnotations[ key ];\n\t\t\t}\n\t\t}\n\t}\n\treturn annotations;\n}\n\n/**\n * Registers an ability in the store.\n *\n * This action validates the ability before registration. If validation fails,\n * an error will be thrown.\n *\n * @param ability The ability to register.\n * @return Action object or function.\n * @throws {Error} If validation fails.\n */\nexport function registerAbility( ability: Ability ) {\n\t// @ts-expect-error - registry types are not yet available\n\treturn ( { select, dispatch } ) => {\n\t\tif ( ! ability.name ) {\n\t\t\tthrow new Error( 'Ability name is required' );\n\t\t}\n\n\t\t// Validate name format matches server implementation\n\t\tif ( ! ABILITY_NAME_PATTERN.test( ability.name ) ) {\n\t\t\tthrow new Error(\n\t\t\t\t'Ability name must be a string containing a namespace prefix with 2-4 segments, e.g. \"my-plugin/my-ability\" or \"core/posts/find\". It can only contain lowercase alphanumeric characters, dashes and the forward slash.'\n\t\t\t);\n\t\t}\n\n\t\tif ( ! ability.label ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" must have a label', ability.name )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! ability.description ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" must have a description', ability.name )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! ability.category ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" must have a category', ability.name )\n\t\t\t);\n\t\t}\n\n\t\t// Validate category format\n\t\tif ( ! CATEGORY_SLUG_PATTERN.test( ability.category ) ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%1$s\" has an invalid category. Category must be lowercase alphanumeric with dashes only. Got: \"%2$s\"',\n\t\t\t\t\tability.name,\n\t\t\t\t\tability.category\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// Check that the category exists\n\t\tconst categories = select.getAbilityCategories();\n\t\tconst existingCategory = categories.find(\n\t\t\t( cat: AbilityCategory ) => cat.slug === ability.category\n\t\t);\n\t\tif ( ! existingCategory ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%1$s\" references non-existent category \"%2$s\". Please register the category first.',\n\t\t\t\t\tability.name,\n\t\t\t\t\tability.category\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// Client-side abilities must have a callback\n\t\tif ( ability.callback && typeof ability.callback !== 'function' ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%s\" has an invalid callback. Callback must be a function',\n\t\t\t\t\tability.name\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// Check if ability is already registered\n\t\tconst existingAbility = select.getAbility( ability.name );\n\t\tif ( existingAbility ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" is already registered', ability.name )\n\t\t\t);\n\t\t}\n\n\t\tconst annotations = filterAnnotations( ability.meta?.annotations, [\n\t\t\t'readonly',\n\t\t\t'destructive',\n\t\t\t'idempotent',\n\t\t\t'serverRegistered',\n\t\t\t'clientRegistered',\n\t\t] );\n\n\t\tif ( ! annotations.serverRegistered ) {\n\t\t\tannotations.clientRegistered = true;\n\t\t}\n\n\t\tconst meta = {\n\t\t\t...( ability.meta || {} ),\n\t\t\tannotations,\n\t\t};\n\n\t\t// All validation passed, dispatch the registration action\n\t\tdispatch( {\n\t\t\ttype: REGISTER_ABILITY,\n\t\t\tability: {\n\t\t\t\t...ability,\n\t\t\t\tmeta,\n\t\t\t},\n\t\t} );\n\t};\n}\n\n/**\n * Returns an action object used to unregister a client-side ability.\n *\n * @param name The name of the ability to unregister.\n * @return Action object.\n */\nexport function unregisterAbility( name: string ) {\n\treturn {\n\t\ttype: UNREGISTER_ABILITY,\n\t\tname,\n\t};\n}\n\n/**\n * Registers a client-side ability category in the store.\n *\n * This action validates the category before registration. If validation fails,\n * an error will be thrown.\n *\n * @param slug The unique category slug identifier.\n * @param args Category arguments (label, description, optional meta).\n * @return Action object or function.\n * @throws {Error} If validation fails.\n */\nexport function registerAbilityCategory(\n\tslug: string,\n\targs: AbilityCategoryArgs\n) {\n\t// @ts-expect-error - registry types are not yet available\n\treturn ( { select, dispatch } ) => {\n\t\tif ( ! slug ) {\n\t\t\tthrow new Error( 'Category slug is required' );\n\t\t}\n\n\t\t// Validate slug format matches server implementation\n\t\tif ( ! CATEGORY_SLUG_PATTERN.test( slug ) ) {\n\t\t\tthrow new Error(\n\t\t\t\t'Category slug must contain only lowercase alphanumeric characters and dashes.'\n\t\t\t);\n\t\t}\n\n\t\t// Check for duplicates\n\t\tconst existingCategory = select.getAbilityCategory( slug );\n\t\tif ( existingCategory ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Category \"%s\" is already registered.', slug )\n\t\t\t);\n\t\t}\n\n\t\t// Validate label presence and type (matches PHP empty() + is_string())\n\t\tif ( ! args.label || typeof args.label !== 'string' ) {\n\t\t\tthrow new Error(\n\t\t\t\t'The category properties must contain a `label` string.'\n\t\t\t);\n\t\t}\n\n\t\t// Validate description presence and type (matches PHP empty() + is_string())\n\t\tif ( ! args.description || typeof args.description !== 'string' ) {\n\t\t\tthrow new Error(\n\t\t\t\t'The category properties must contain a `description` string.'\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\targs.meta !== undefined &&\n\t\t\t( typeof args.meta !== 'object' || Array.isArray( args.meta ) )\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t'The category properties should provide a valid `meta` object.'\n\t\t\t);\n\t\t}\n\n\t\tconst annotations = filterAnnotations( args.meta?.annotations, [\n\t\t\t'serverRegistered',\n\t\t\t'clientRegistered',\n\t\t] );\n\n\t\tif ( ! annotations.serverRegistered ) {\n\t\t\tannotations.clientRegistered = true;\n\t\t}\n\n\t\tconst meta = {\n\t\t\t...( args.meta || {} ),\n\t\t\tannotations,\n\t\t};\n\t\tconst category: AbilityCategory = {\n\t\t\tslug,\n\t\t\tlabel: args.label,\n\t\t\tdescription: args.description,\n\t\t\tmeta,\n\t\t};\n\n\t\tdispatch( {\n\t\t\ttype: REGISTER_ABILITY_CATEGORY,\n\t\t\tcategory,\n\t\t} );\n\t};\n}\n\n/**\n * Returns an action object used to unregister a client-side ability category.\n *\n * @param slug The slug of the category to unregister.\n * @return Action object.\n */\nexport function unregisterAbilityCategory( slug: string ) {\n\treturn {\n\t\ttype: UNREGISTER_ABILITY_CATEGORY,\n\t\tslug,\n\t};\n}\n"],
|
|
5
|
-
"mappings": "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",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"actions.cjs","names":["ABILITY_NAME_PATTERN","sprintf","CATEGORY_SLUG_PATTERN","REGISTER_ABILITY","UNREGISTER_ABILITY","REGISTER_ABILITY_CATEGORY","UNREGISTER_ABILITY_CATEGORY"],"sources":["../../src/store/actions.ts"],"sourcesContent":["import { sprintf } from '@wordpress/i18n';\nimport type { Ability, AbilityCategory, AbilityCategoryArgs } from '../types';\nimport {\n\tREGISTER_ABILITY,\n\tUNREGISTER_ABILITY,\n\tREGISTER_ABILITY_CATEGORY,\n\tUNREGISTER_ABILITY_CATEGORY,\n\tABILITY_NAME_PATTERN,\n\tCATEGORY_SLUG_PATTERN,\n} from './constants';\n\ntype AbilityAnnotations = NonNullable< Ability[ 'meta' ] >[ 'annotations' ];\n\n/**\n * Filters annotations to only include allowed keys with non-null values.\n *\n * @param sourceAnnotations The source annotations object to filter.\n * @param allowedKeys Array of annotation keys to include.\n * @return Filtered annotations object.\n */\nfunction filterAnnotations< K extends keyof NonNullable< AbilityAnnotations > >(\n\tsourceAnnotations: Record< string, boolean > | undefined,\n\tallowedKeys: readonly K[]\n): NonNullable< AbilityAnnotations > {\n\tconst annotations: NonNullable< AbilityAnnotations > = {};\n\n\tif ( sourceAnnotations ) {\n\t\tfor ( const key of allowedKeys ) {\n\t\t\tif ( sourceAnnotations[ key ] !== undefined ) {\n\t\t\t\tannotations[ key ] = sourceAnnotations[ key ];\n\t\t\t}\n\t\t}\n\t}\n\treturn annotations;\n}\n\n/**\n * Registers an ability in the store.\n *\n * This action validates the ability before registration. If validation fails,\n * an error will be thrown.\n *\n * @param ability The ability to register.\n * @return Action object or function.\n * @throws {Error} If validation fails.\n */\nexport function registerAbility( ability: Ability ) {\n\t// @ts-expect-error - registry types are not yet available\n\treturn ( { select, dispatch } ) => {\n\t\tif ( ! ability.name ) {\n\t\t\tthrow new Error( 'Ability name is required' );\n\t\t}\n\n\t\t// Validate name format matches server implementation\n\t\tif ( ! ABILITY_NAME_PATTERN.test( ability.name ) ) {\n\t\t\tthrow new Error(\n\t\t\t\t'Ability name must be a string containing a namespace prefix with 2-4 segments, e.g. \"my-plugin/my-ability\" or \"core/posts/find\". It can only contain lowercase alphanumeric characters, dashes and the forward slash.'\n\t\t\t);\n\t\t}\n\n\t\tif ( ! ability.label ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" must have a label', ability.name )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! ability.description ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" must have a description', ability.name )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! ability.category ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" must have a category', ability.name )\n\t\t\t);\n\t\t}\n\n\t\t// Validate category format\n\t\tif ( ! CATEGORY_SLUG_PATTERN.test( ability.category ) ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%1$s\" has an invalid category. Category must be lowercase alphanumeric with dashes only. Got: \"%2$s\"',\n\t\t\t\t\tability.name,\n\t\t\t\t\tability.category\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// Check that the category exists\n\t\tconst categories = select.getAbilityCategories();\n\t\tconst existingCategory = categories.find(\n\t\t\t( cat: AbilityCategory ) => cat.slug === ability.category\n\t\t);\n\t\tif ( ! existingCategory ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%1$s\" references non-existent category \"%2$s\". Please register the category first.',\n\t\t\t\t\tability.name,\n\t\t\t\t\tability.category\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// Client-side abilities must have a callback\n\t\tif ( ability.callback && typeof ability.callback !== 'function' ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf(\n\t\t\t\t\t'Ability \"%s\" has an invalid callback. Callback must be a function',\n\t\t\t\t\tability.name\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// Check if ability is already registered\n\t\tconst existingAbility = select.getAbility( ability.name );\n\t\tif ( existingAbility ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Ability \"%s\" is already registered', ability.name )\n\t\t\t);\n\t\t}\n\n\t\tconst annotations = filterAnnotations( ability.meta?.annotations, [\n\t\t\t'readonly',\n\t\t\t'destructive',\n\t\t\t'idempotent',\n\t\t\t'serverRegistered',\n\t\t\t'clientRegistered',\n\t\t] );\n\n\t\tif ( ! annotations.serverRegistered ) {\n\t\t\tannotations.clientRegistered = true;\n\t\t}\n\n\t\tconst meta = {\n\t\t\t...( ability.meta || {} ),\n\t\t\tannotations,\n\t\t};\n\n\t\t// All validation passed, dispatch the registration action\n\t\tdispatch( {\n\t\t\ttype: REGISTER_ABILITY,\n\t\t\tability: {\n\t\t\t\t...ability,\n\t\t\t\tmeta,\n\t\t\t},\n\t\t} );\n\t};\n}\n\n/**\n * Returns an action object used to unregister a client-side ability.\n *\n * @param name The name of the ability to unregister.\n * @return Action object.\n */\nexport function unregisterAbility( name: string ) {\n\treturn {\n\t\ttype: UNREGISTER_ABILITY,\n\t\tname,\n\t};\n}\n\n/**\n * Registers a client-side ability category in the store.\n *\n * This action validates the category before registration. If validation fails,\n * an error will be thrown.\n *\n * @param slug The unique category slug identifier.\n * @param args Category arguments (label, description, optional meta).\n * @return Action object or function.\n * @throws {Error} If validation fails.\n */\nexport function registerAbilityCategory(\n\tslug: string,\n\targs: AbilityCategoryArgs\n) {\n\t// @ts-expect-error - registry types are not yet available\n\treturn ( { select, dispatch } ) => {\n\t\tif ( ! slug ) {\n\t\t\tthrow new Error( 'Category slug is required' );\n\t\t}\n\n\t\t// Validate slug format matches server implementation\n\t\tif ( ! CATEGORY_SLUG_PATTERN.test( slug ) ) {\n\t\t\tthrow new Error(\n\t\t\t\t'Category slug must contain only lowercase alphanumeric characters and dashes.'\n\t\t\t);\n\t\t}\n\n\t\t// Check for duplicates\n\t\tconst existingCategory = select.getAbilityCategory( slug );\n\t\tif ( existingCategory ) {\n\t\t\tthrow new Error(\n\t\t\t\tsprintf( 'Category \"%s\" is already registered.', slug )\n\t\t\t);\n\t\t}\n\n\t\t// Validate label presence and type (matches PHP empty() + is_string())\n\t\tif ( ! args.label || typeof args.label !== 'string' ) {\n\t\t\tthrow new Error(\n\t\t\t\t'The category properties must contain a `label` string.'\n\t\t\t);\n\t\t}\n\n\t\t// Validate description presence and type (matches PHP empty() + is_string())\n\t\tif ( ! args.description || typeof args.description !== 'string' ) {\n\t\t\tthrow new Error(\n\t\t\t\t'The category properties must contain a `description` string.'\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\targs.meta !== undefined &&\n\t\t\t( typeof args.meta !== 'object' || Array.isArray( args.meta ) )\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t'The category properties should provide a valid `meta` object.'\n\t\t\t);\n\t\t}\n\n\t\tconst annotations = filterAnnotations( args.meta?.annotations, [\n\t\t\t'serverRegistered',\n\t\t\t'clientRegistered',\n\t\t] );\n\n\t\tif ( ! annotations.serverRegistered ) {\n\t\t\tannotations.clientRegistered = true;\n\t\t}\n\n\t\tconst meta = {\n\t\t\t...( args.meta || {} ),\n\t\t\tannotations,\n\t\t};\n\t\tconst category: AbilityCategory = {\n\t\t\tslug,\n\t\t\tlabel: args.label,\n\t\t\tdescription: args.description,\n\t\t\tmeta,\n\t\t};\n\n\t\tdispatch( {\n\t\t\ttype: REGISTER_ABILITY_CATEGORY,\n\t\t\tcategory,\n\t\t} );\n\t};\n}\n\n/**\n * Returns an action object used to unregister a client-side ability category.\n *\n * @param slug The slug of the category to unregister.\n * @return Action object.\n */\nexport function unregisterAbilityCategory( slug: string ) {\n\treturn {\n\t\ttype: UNREGISTER_ABILITY_CATEGORY,\n\t\tslug,\n\t};\n}\n"],"mappings":"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"}
|
|
@@ -1,49 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/abilities/src/store/constants.ts
|
|
21
|
-
var constants_exports = {};
|
|
22
|
-
__export(constants_exports, {
|
|
23
|
-
ABILITY_NAME_PATTERN: () => ABILITY_NAME_PATTERN,
|
|
24
|
-
CATEGORY_SLUG_PATTERN: () => CATEGORY_SLUG_PATTERN,
|
|
25
|
-
REGISTER_ABILITY: () => REGISTER_ABILITY,
|
|
26
|
-
REGISTER_ABILITY_CATEGORY: () => REGISTER_ABILITY_CATEGORY,
|
|
27
|
-
STORE_NAME: () => STORE_NAME,
|
|
28
|
-
UNREGISTER_ABILITY: () => UNREGISTER_ABILITY,
|
|
29
|
-
UNREGISTER_ABILITY_CATEGORY: () => UNREGISTER_ABILITY_CATEGORY
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(constants_exports);
|
|
32
|
-
var STORE_NAME = "core/abilities";
|
|
33
|
-
var ABILITY_NAME_PATTERN = /^[a-z0-9-]+(?:\/[a-z0-9-]+){1,3}$/;
|
|
34
|
-
var CATEGORY_SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
35
|
-
var REGISTER_ABILITY = "REGISTER_ABILITY";
|
|
36
|
-
var UNREGISTER_ABILITY = "UNREGISTER_ABILITY";
|
|
37
|
-
var REGISTER_ABILITY_CATEGORY = "REGISTER_ABILITY_CATEGORY";
|
|
38
|
-
var UNREGISTER_ABILITY_CATEGORY = "UNREGISTER_ABILITY_CATEGORY";
|
|
39
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
-
0 && (module.exports = {
|
|
41
|
-
ABILITY_NAME_PATTERN,
|
|
42
|
-
CATEGORY_SLUG_PATTERN,
|
|
43
|
-
REGISTER_ABILITY,
|
|
44
|
-
REGISTER_ABILITY_CATEGORY,
|
|
45
|
-
STORE_NAME,
|
|
46
|
-
UNREGISTER_ABILITY,
|
|
47
|
-
UNREGISTER_ABILITY_CATEGORY
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
48
5
|
});
|
|
49
|
-
|
|
6
|
+
// packages/abilities/src/store/constants.ts
|
|
7
|
+
/**
|
|
8
|
+
* Store constants
|
|
9
|
+
*/
|
|
10
|
+
const STORE_NAME = "core/abilities";
|
|
11
|
+
const ABILITY_NAME_PATTERN = /^[a-z0-9-]+(?:\/[a-z0-9-]+){1,3}$/;
|
|
12
|
+
const CATEGORY_SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
13
|
+
const REGISTER_ABILITY = "REGISTER_ABILITY";
|
|
14
|
+
const UNREGISTER_ABILITY = "UNREGISTER_ABILITY";
|
|
15
|
+
const REGISTER_ABILITY_CATEGORY = "REGISTER_ABILITY_CATEGORY";
|
|
16
|
+
const UNREGISTER_ABILITY_CATEGORY = "UNREGISTER_ABILITY_CATEGORY";
|
|
17
|
+
exports.ABILITY_NAME_PATTERN = ABILITY_NAME_PATTERN;
|
|
18
|
+
exports.CATEGORY_SLUG_PATTERN = CATEGORY_SLUG_PATTERN;
|
|
19
|
+
exports.REGISTER_ABILITY = REGISTER_ABILITY;
|
|
20
|
+
exports.REGISTER_ABILITY_CATEGORY = REGISTER_ABILITY_CATEGORY;
|
|
21
|
+
exports.STORE_NAME = STORE_NAME;
|
|
22
|
+
exports.UNREGISTER_ABILITY = UNREGISTER_ABILITY;
|
|
23
|
+
exports.UNREGISTER_ABILITY_CATEGORY = UNREGISTER_ABILITY_CATEGORY;
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=constants.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/constants.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Store constants\n */\nexport const STORE_NAME = 'core/abilities';\n\n// Validation patterns\nexport const ABILITY_NAME_PATTERN = /^[a-z0-9-]+(?:\\/[a-z0-9-]+){1,3}$/;\nexport const CATEGORY_SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\n\n// Action types\nexport const REGISTER_ABILITY = 'REGISTER_ABILITY';\nexport const UNREGISTER_ABILITY = 'UNREGISTER_ABILITY';\nexport const REGISTER_ABILITY_CATEGORY = 'REGISTER_ABILITY_CATEGORY';\nexport const UNREGISTER_ABILITY_CATEGORY = 'UNREGISTER_ABILITY_CATEGORY';\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,IAAM,aAAa;AAGnB,IAAM,uBAAuB;AAC7B,IAAM,wBAAwB;AAG9B,IAAM,mBAAmB;AACzB,IAAM,qBAAqB;AAC3B,IAAM,4BAA4B;AAClC,IAAM,8BAA8B;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"constants.cjs","names":[],"sources":["../../src/store/constants.ts"],"sourcesContent":["/**\n * Store constants\n */\nexport const STORE_NAME = 'core/abilities';\n\n// Validation patterns\nexport const ABILITY_NAME_PATTERN = /^[a-z0-9-]+(?:\\/[a-z0-9-]+){1,3}$/;\nexport const CATEGORY_SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\n\n// Action types\nexport const REGISTER_ABILITY = 'REGISTER_ABILITY';\nexport const UNREGISTER_ABILITY = 'UNREGISTER_ABILITY';\nexport const REGISTER_ABILITY_CATEGORY = 'REGISTER_ABILITY_CATEGORY';\nexport const UNREGISTER_ABILITY_CATEGORY = 'UNREGISTER_ABILITY_CATEGORY';\n"],"mappings":";;;;;;;;;AAGA,MAAa,aAAa;AAG1B,MAAa,uBAAuB;AACpC,MAAa,wBAAwB;AAGrC,MAAa,mBAAmB;AAChC,MAAa,qBAAqB;AAClC,MAAa,4BAA4B;AACzC,MAAa,8BAA8B"}
|
package/build/store/index.cjs
CHANGED
|
@@ -1,51 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
2
7
|
var __create = Object.create;
|
|
3
8
|
var __defProp = Object.defineProperty;
|
|
4
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
13
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
19
22
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
let _wordpress_data = require("@wordpress/data");
|
|
28
|
+
let __reducer_ts = require("./reducer.cjs");
|
|
29
|
+
__reducer_ts = __toESM(__reducer_ts);
|
|
30
|
+
let __actions_ts = require("./actions.cjs");
|
|
31
|
+
__actions_ts = __toESM(__actions_ts);
|
|
32
|
+
let __selectors_ts = require("./selectors.cjs");
|
|
33
|
+
__selectors_ts = __toESM(__selectors_ts);
|
|
34
|
+
let __constants_ts = require("./constants.cjs");
|
|
30
35
|
// packages/abilities/src/store/index.ts
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
/**
|
|
37
|
+
* The abilities store definition.
|
|
38
|
+
*/
|
|
39
|
+
const store = (0, _wordpress_data.createReduxStore)(__constants_ts.STORE_NAME, {
|
|
40
|
+
reducer: __reducer_ts.default,
|
|
41
|
+
actions: __actions_ts,
|
|
42
|
+
selectors: __selectors_ts
|
|
34
43
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var selectors = __toESM(require("./selectors.cjs"));
|
|
40
|
-
var import_constants = require("./constants.cjs");
|
|
41
|
-
var store = (0, import_data.createReduxStore)(import_constants.STORE_NAME, {
|
|
42
|
-
reducer: import_reducer.default,
|
|
43
|
-
actions,
|
|
44
|
-
selectors
|
|
45
|
-
});
|
|
46
|
-
(0, import_data.register)(store);
|
|
47
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
-
0 && (module.exports = {
|
|
49
|
-
store
|
|
50
|
-
});
|
|
51
|
-
//# sourceMappingURL=index.cjs.map
|
|
44
|
+
(0, _wordpress_data.register)(store);
|
|
45
|
+
exports.store = store;
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { createReduxStore, register } from '@wordpress/data';\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\nimport { STORE_NAME } from './constants';\n\n/**\n * The abilities store definition.\n */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA2C;AAC3C,qBAAoB;AACpB,cAAyB;AACzB,gBAA2B;AAC3B,uBAA2B;AAKpB,IAAM,YAAQ,8BAAkB,6BAAY;AAAA,EAClD,wBAAAA;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAAA,IAEF,sBAAU,KAAM;",
|
|
6
|
-
"names": ["reducer"]
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["createReduxStore","STORE_NAME","register"],"sources":["../../src/store/index.ts"],"sourcesContent":["import { createReduxStore, register } from '@wordpress/data';\nimport reducer from './reducer';\nimport * as actions from './actions';\nimport * as selectors from './selectors';\nimport { STORE_NAME } from './constants';\n\n/**\n * The abilities store definition.\n */\nexport const store = createReduxStore( STORE_NAME, {\n\treducer,\n\tactions,\n\tselectors,\n} );\n\nregister( store );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAa,SAAA,GAAQA,gBAAAA,iBAAAA,CAAkBC,eAAAA,YAAY;CAClD,SAAA,aAAA;CACA,SAAA;CACA,WAAA;AACD,CAAE;CAEFC,GAAAA,gBAAAA,SAAAA,CAAU,KAAM"}
|