@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/reducer.cjs
CHANGED
|
@@ -1,106 +1,114 @@
|
|
|
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/reducer.ts
|
|
21
|
-
var reducer_exports = {};
|
|
22
|
-
__export(reducer_exports, {
|
|
23
|
-
default: () => reducer_default
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
5
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
6
|
+
let _wordpress_data = require("@wordpress/data");
|
|
7
|
+
let __constants_ts = require("./constants.cjs");
|
|
8
|
+
// packages/abilities/src/store/reducer.ts
|
|
9
|
+
/**
|
|
10
|
+
* Valid keys for an Ability object.
|
|
11
|
+
* Used to filter out non-standard properties from server responses.
|
|
12
|
+
*/
|
|
13
|
+
const ABILITY_KEYS = [
|
|
14
|
+
"name",
|
|
15
|
+
"label",
|
|
16
|
+
"description",
|
|
17
|
+
"category",
|
|
18
|
+
"input_schema",
|
|
19
|
+
"output_schema",
|
|
20
|
+
"meta",
|
|
21
|
+
"callback",
|
|
22
|
+
"permissionCallback"
|
|
38
23
|
];
|
|
39
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Valid keys for an AbilityCategory object.
|
|
26
|
+
* Used to filter out non-standard properties from server responses.
|
|
27
|
+
*/
|
|
28
|
+
const CATEGORY_KEYS = [
|
|
29
|
+
"slug",
|
|
30
|
+
"label",
|
|
31
|
+
"description",
|
|
32
|
+
"meta"
|
|
33
|
+
];
|
|
34
|
+
/**
|
|
35
|
+
* Sanitizes an ability object to only include valid properties.
|
|
36
|
+
* This ensures consistent shape regardless of source (server/client).
|
|
37
|
+
*
|
|
38
|
+
* @param ability Raw ability object that may contain extra properties.
|
|
39
|
+
* @return Sanitized ability with only valid properties.
|
|
40
|
+
*/
|
|
40
41
|
function sanitizeAbility(ability) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
{}
|
|
46
|
-
);
|
|
42
|
+
return Object.keys(ability).filter((key) => ABILITY_KEYS.includes(key) && ability[key] !== void 0).reduce((obj, key) => ({
|
|
43
|
+
...obj,
|
|
44
|
+
[key]: ability[key]
|
|
45
|
+
}), {});
|
|
47
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Sanitizes a category object to only include valid properties.
|
|
49
|
+
* This ensures consistent shape regardless of source.
|
|
50
|
+
*
|
|
51
|
+
* @param category Raw category object that may contain extra properties.
|
|
52
|
+
* @return Sanitized category with only valid properties.
|
|
53
|
+
*/
|
|
48
54
|
function sanitizeCategory(category) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{}
|
|
54
|
-
);
|
|
55
|
+
return Object.keys(category).filter((key) => CATEGORY_KEYS.includes(key) && category[key] !== void 0).reduce((obj, key) => ({
|
|
56
|
+
...obj,
|
|
57
|
+
[key]: category[key]
|
|
58
|
+
}), {});
|
|
55
59
|
}
|
|
56
|
-
|
|
60
|
+
const DEFAULT_STATE = {};
|
|
61
|
+
/**
|
|
62
|
+
* Reducer managing the abilities by name.
|
|
63
|
+
*
|
|
64
|
+
* @param state Current state.
|
|
65
|
+
* @param action Dispatched action.
|
|
66
|
+
* @return New state.
|
|
67
|
+
*/
|
|
57
68
|
function abilitiesByName(state = DEFAULT_STATE, action) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const { [action.name]: _, ...newState } = state;
|
|
73
|
-
return newState;
|
|
74
|
-
}
|
|
75
|
-
default:
|
|
76
|
-
return state;
|
|
77
|
-
}
|
|
69
|
+
switch (action.type) {
|
|
70
|
+
case __constants_ts.REGISTER_ABILITY:
|
|
71
|
+
if (!action.ability) return state;
|
|
72
|
+
return {
|
|
73
|
+
...state,
|
|
74
|
+
[action.ability.name]: sanitizeAbility(action.ability)
|
|
75
|
+
};
|
|
76
|
+
case __constants_ts.UNREGISTER_ABILITY: {
|
|
77
|
+
if (!state[action.name]) return state;
|
|
78
|
+
const { [action.name]: _, ...newState } = state;
|
|
79
|
+
return newState;
|
|
80
|
+
}
|
|
81
|
+
default: return state;
|
|
82
|
+
}
|
|
78
83
|
}
|
|
79
|
-
|
|
84
|
+
const DEFAULT_CATEGORIES_STATE = {};
|
|
85
|
+
/**
|
|
86
|
+
* Reducer managing the categories by slug.
|
|
87
|
+
*
|
|
88
|
+
* @param state Current state.
|
|
89
|
+
* @param action Dispatched action.
|
|
90
|
+
* @return New state.
|
|
91
|
+
*/
|
|
80
92
|
function categoriesBySlug(state = DEFAULT_CATEGORIES_STATE, action) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const { [action.slug]: _, ...newState } = state;
|
|
96
|
-
return newState;
|
|
97
|
-
}
|
|
98
|
-
default:
|
|
99
|
-
return state;
|
|
100
|
-
}
|
|
93
|
+
switch (action.type) {
|
|
94
|
+
case __constants_ts.REGISTER_ABILITY_CATEGORY:
|
|
95
|
+
if (!action.category) return state;
|
|
96
|
+
return {
|
|
97
|
+
...state,
|
|
98
|
+
[action.category.slug]: sanitizeCategory(action.category)
|
|
99
|
+
};
|
|
100
|
+
case __constants_ts.UNREGISTER_ABILITY_CATEGORY: {
|
|
101
|
+
if (!state[action.slug]) return state;
|
|
102
|
+
const { [action.slug]: _, ...newState } = state;
|
|
103
|
+
return newState;
|
|
104
|
+
}
|
|
105
|
+
default: return state;
|
|
106
|
+
}
|
|
101
107
|
}
|
|
102
|
-
var reducer_default = (0,
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
var reducer_default = (0, _wordpress_data.combineReducers)({
|
|
109
|
+
abilitiesByName,
|
|
110
|
+
categoriesBySlug
|
|
105
111
|
});
|
|
106
|
-
|
|
112
|
+
exports.default = reducer_default;
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=reducer.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/reducer.ts"],
|
|
4
|
-
"sourcesContent": ["import { combineReducers } from '@wordpress/data';\nimport type { Ability, AbilityCategory } from '../types';\nimport {\n\tREGISTER_ABILITY,\n\tUNREGISTER_ABILITY,\n\tREGISTER_ABILITY_CATEGORY,\n\tUNREGISTER_ABILITY_CATEGORY,\n} from './constants';\n\n/**\n * Valid keys for an Ability object.\n * Used to filter out non-standard properties from server responses.\n */\nconst ABILITY_KEYS = [\n\t'name',\n\t'label',\n\t'description',\n\t'category',\n\t'input_schema',\n\t'output_schema',\n\t'meta',\n\t'callback',\n\t'permissionCallback',\n] as const;\n\n/**\n * Valid keys for an AbilityCategory object.\n * Used to filter out non-standard properties from server responses.\n */\nconst CATEGORY_KEYS = [ 'slug', 'label', 'description', 'meta' ] as const;\n\n/**\n * Sanitizes an ability object to only include valid properties.\n * This ensures consistent shape regardless of source (server/client).\n *\n * @param ability Raw ability object that may contain extra properties.\n * @return Sanitized ability with only valid properties.\n */\nfunction sanitizeAbility( ability: any ): Ability {\n\treturn Object.keys( ability )\n\t\t.filter(\n\t\t\t( key ) =>\n\t\t\t\tABILITY_KEYS.includes( key as any ) &&\n\t\t\t\tability[ key ] !== undefined\n\t\t)\n\t\t.reduce(\n\t\t\t( obj, key ) => ( { ...obj, [ key ]: ability[ key ] } ),\n\t\t\t{} as Ability\n\t\t);\n}\n\n/**\n * Sanitizes a category object to only include valid properties.\n * This ensures consistent shape regardless of source.\n *\n * @param category Raw category object that may contain extra properties.\n * @return Sanitized category with only valid properties.\n */\nfunction sanitizeCategory( category: any ): AbilityCategory {\n\treturn Object.keys( category )\n\t\t.filter(\n\t\t\t( key ) =>\n\t\t\t\tCATEGORY_KEYS.includes( key as any ) &&\n\t\t\t\tcategory[ key ] !== undefined\n\t\t)\n\t\t.reduce(\n\t\t\t( obj, key ) => ( { ...obj, [ key ]: category[ key ] } ),\n\t\t\t{} as AbilityCategory\n\t\t);\n}\n\ninterface RegisterAbilityAction {\n\ttype: typeof REGISTER_ABILITY;\n\tability: Ability;\n}\n\ninterface UnregisterAbilityAction {\n\ttype: typeof UNREGISTER_ABILITY;\n\tname: string;\n}\n\ninterface RegisterAbilityCategoryAction {\n\ttype: typeof REGISTER_ABILITY_CATEGORY;\n\tcategory: AbilityCategory;\n}\n\ninterface UnregisterAbilityCategoryAction {\n\ttype: typeof UNREGISTER_ABILITY_CATEGORY;\n\tslug: string;\n}\n\ntype AbilitiesAction = RegisterAbilityAction | UnregisterAbilityAction;\n\ntype AbilitiesCategoryAction =\n\tRegisterAbilityCategoryAction | UnregisterAbilityCategoryAction;\n\nconst DEFAULT_STATE: Record< string, Ability > = {};\n\n/**\n * Reducer managing the abilities by name.\n *\n * @param state Current state.\n * @param action Dispatched action.\n * @return New state.\n */\nfunction abilitiesByName(\n\tstate: Record< string, Ability > = DEFAULT_STATE,\n\taction: AbilitiesAction\n): Record< string, Ability > {\n\tswitch ( action.type ) {\n\t\tcase REGISTER_ABILITY: {\n\t\t\tif ( ! action.ability ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.ability.name ]: sanitizeAbility( action.ability ),\n\t\t\t};\n\t\t}\n\t\tcase UNREGISTER_ABILITY: {\n\t\t\tif ( ! state[ action.name ] ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\tconst { [ action.name ]: _, ...newState } = state;\n\t\t\treturn newState;\n\t\t}\n\t\tdefault:\n\t\t\treturn state;\n\t}\n}\n\nconst DEFAULT_CATEGORIES_STATE: Record< string, AbilityCategory > = {};\n\n/**\n * Reducer managing the categories by slug.\n *\n * @param state Current state.\n * @param action Dispatched action.\n * @return New state.\n */\nfunction categoriesBySlug(\n\tstate: Record< string, AbilityCategory > = DEFAULT_CATEGORIES_STATE,\n\taction: AbilitiesCategoryAction\n): Record< string, AbilityCategory > {\n\tswitch ( action.type ) {\n\t\tcase REGISTER_ABILITY_CATEGORY: {\n\t\t\tif ( ! action.category ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.category.slug ]: sanitizeCategory( action.category ),\n\t\t\t};\n\t\t}\n\t\tcase UNREGISTER_ABILITY_CATEGORY: {\n\t\t\tif ( ! state[ action.slug ] ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\tconst { [ action.slug ]: _, ...newState } = state;\n\t\t\treturn newState;\n\t\t}\n\t\tdefault:\n\t\t\treturn state;\n\t}\n}\n\nexport default combineReducers( {\n\tabilitiesByName,\n\tcategoriesBySlug,\n} );\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAA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aAAO;AAAA,EACT;AACD;AAEA,IAAM,2BAA8D,CAAC;AASrE,SAAS,iBACR,QAA2C,0BAC3C,QACoC;AACpC,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK,4CAA2B;AAC/B,UAAK,CAAE,OAAO,UAAW;AACxB,eAAO;AAAA,MACR;AACA,aAAO;AAAA,QACN,GAAG;AAAA,QACH,CAAE,OAAO,SAAS,IAAK,GAAG,iBAAkB,OAAO,QAAS;AAAA,MAC7D;AAAA,IACD;AAAA,IACA,KAAK,8CAA6B;AACjC,UAAK,CAAE,MAAO,OAAO,IAAK,GAAI;AAC7B,eAAO;AAAA,MACR;AACA,YAAM,EAAE,CAAE,OAAO,IAAK,GAAG,GAAG,GAAG,SAAS,IAAI;AAC5C,aAAO;AAAA,IACR;AAAA,IACA;AACC,aAAO;AAAA,EACT;AACD;AAEA,IAAO,sBAAQ,6BAAiB;AAAA,EAC/B;AAAA,EACA;AACD,CAAE;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"reducer.cjs","names":["REGISTER_ABILITY","UNREGISTER_ABILITY","REGISTER_ABILITY_CATEGORY","UNREGISTER_ABILITY_CATEGORY","combineReducers"],"sources":["../../src/store/reducer.ts"],"sourcesContent":["import { combineReducers } from '@wordpress/data';\nimport type { Ability, AbilityCategory } from '../types';\nimport {\n\tREGISTER_ABILITY,\n\tUNREGISTER_ABILITY,\n\tREGISTER_ABILITY_CATEGORY,\n\tUNREGISTER_ABILITY_CATEGORY,\n} from './constants';\n\n/**\n * Valid keys for an Ability object.\n * Used to filter out non-standard properties from server responses.\n */\nconst ABILITY_KEYS = [\n\t'name',\n\t'label',\n\t'description',\n\t'category',\n\t'input_schema',\n\t'output_schema',\n\t'meta',\n\t'callback',\n\t'permissionCallback',\n] as const;\n\n/**\n * Valid keys for an AbilityCategory object.\n * Used to filter out non-standard properties from server responses.\n */\nconst CATEGORY_KEYS = [ 'slug', 'label', 'description', 'meta' ] as const;\n\n/**\n * Sanitizes an ability object to only include valid properties.\n * This ensures consistent shape regardless of source (server/client).\n *\n * @param ability Raw ability object that may contain extra properties.\n * @return Sanitized ability with only valid properties.\n */\nfunction sanitizeAbility( ability: any ): Ability {\n\treturn Object.keys( ability )\n\t\t.filter(\n\t\t\t( key ) =>\n\t\t\t\tABILITY_KEYS.includes( key as any ) &&\n\t\t\t\tability[ key ] !== undefined\n\t\t)\n\t\t.reduce(\n\t\t\t( obj, key ) => ( { ...obj, [ key ]: ability[ key ] } ),\n\t\t\t{} as Ability\n\t\t);\n}\n\n/**\n * Sanitizes a category object to only include valid properties.\n * This ensures consistent shape regardless of source.\n *\n * @param category Raw category object that may contain extra properties.\n * @return Sanitized category with only valid properties.\n */\nfunction sanitizeCategory( category: any ): AbilityCategory {\n\treturn Object.keys( category )\n\t\t.filter(\n\t\t\t( key ) =>\n\t\t\t\tCATEGORY_KEYS.includes( key as any ) &&\n\t\t\t\tcategory[ key ] !== undefined\n\t\t)\n\t\t.reduce(\n\t\t\t( obj, key ) => ( { ...obj, [ key ]: category[ key ] } ),\n\t\t\t{} as AbilityCategory\n\t\t);\n}\n\ninterface RegisterAbilityAction {\n\ttype: typeof REGISTER_ABILITY;\n\tability: Ability;\n}\n\ninterface UnregisterAbilityAction {\n\ttype: typeof UNREGISTER_ABILITY;\n\tname: string;\n}\n\ninterface RegisterAbilityCategoryAction {\n\ttype: typeof REGISTER_ABILITY_CATEGORY;\n\tcategory: AbilityCategory;\n}\n\ninterface UnregisterAbilityCategoryAction {\n\ttype: typeof UNREGISTER_ABILITY_CATEGORY;\n\tslug: string;\n}\n\ntype AbilitiesAction = RegisterAbilityAction | UnregisterAbilityAction;\n\ntype AbilitiesCategoryAction =\n\tRegisterAbilityCategoryAction | UnregisterAbilityCategoryAction;\n\nconst DEFAULT_STATE: Record< string, Ability > = {};\n\n/**\n * Reducer managing the abilities by name.\n *\n * @param state Current state.\n * @param action Dispatched action.\n * @return New state.\n */\nfunction abilitiesByName(\n\tstate: Record< string, Ability > = DEFAULT_STATE,\n\taction: AbilitiesAction\n): Record< string, Ability > {\n\tswitch ( action.type ) {\n\t\tcase REGISTER_ABILITY: {\n\t\t\tif ( ! action.ability ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.ability.name ]: sanitizeAbility( action.ability ),\n\t\t\t};\n\t\t}\n\t\tcase UNREGISTER_ABILITY: {\n\t\t\tif ( ! state[ action.name ] ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\tconst { [ action.name ]: _, ...newState } = state;\n\t\t\treturn newState;\n\t\t}\n\t\tdefault:\n\t\t\treturn state;\n\t}\n}\n\nconst DEFAULT_CATEGORIES_STATE: Record< string, AbilityCategory > = {};\n\n/**\n * Reducer managing the categories by slug.\n *\n * @param state Current state.\n * @param action Dispatched action.\n * @return New state.\n */\nfunction categoriesBySlug(\n\tstate: Record< string, AbilityCategory > = DEFAULT_CATEGORIES_STATE,\n\taction: AbilitiesCategoryAction\n): Record< string, AbilityCategory > {\n\tswitch ( action.type ) {\n\t\tcase REGISTER_ABILITY_CATEGORY: {\n\t\t\tif ( ! action.category ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.category.slug ]: sanitizeCategory( action.category ),\n\t\t\t};\n\t\t}\n\t\tcase UNREGISTER_ABILITY_CATEGORY: {\n\t\t\tif ( ! state[ action.slug ] ) {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t\tconst { [ action.slug ]: _, ...newState } = state;\n\t\t\treturn newState;\n\t\t}\n\t\tdefault:\n\t\t\treturn state;\n\t}\n}\n\nexport default combineReducers( {\n\tabilitiesByName,\n\tcategoriesBySlug,\n} );\n"],"mappings":";;;;;;;;;;;;AAaA,MAAM,eAAe;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;;;;AAMA,MAAM,gBAAgB;CAAE;CAAQ;CAAS;CAAe;AAAO;;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,IAAA,mBAAA,GAAeC,gBAAAA,gBAAAA,CAAiB;CAC/B;CACA;AACD,CAAE"}
|
|
@@ -1,64 +1,55 @@
|
|
|
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/selectors.ts
|
|
21
|
-
var selectors_exports = {};
|
|
22
|
-
__export(selectors_exports, {
|
|
23
|
-
getAbilities: () => getAbilities,
|
|
24
|
-
getAbility: () => getAbility,
|
|
25
|
-
getAbilityCategories: () => getAbilityCategories,
|
|
26
|
-
getAbilityCategory: () => getAbilityCategory
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
27
5
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
6
|
+
let _wordpress_data = require("@wordpress/data");
|
|
7
|
+
// packages/abilities/src/store/selectors.ts
|
|
8
|
+
/**
|
|
9
|
+
* Returns all registered abilities.
|
|
10
|
+
* Optionally filters by query arguments.
|
|
11
|
+
*
|
|
12
|
+
* @param state Store state.
|
|
13
|
+
* @param args Optional query arguments to filter. Defaults to empty object.
|
|
14
|
+
* @return Array of abilities.
|
|
15
|
+
*/
|
|
16
|
+
const getAbilities = (0, _wordpress_data.createSelector)((state, { category } = {}) => {
|
|
17
|
+
const abilities = Object.values(state.abilitiesByName);
|
|
18
|
+
if (category) return abilities.filter((ability) => ability.category === category);
|
|
19
|
+
return abilities;
|
|
20
|
+
}, (state, { category } = {}) => [state.abilitiesByName, category]);
|
|
21
|
+
/**
|
|
22
|
+
* Returns a specific ability by name.
|
|
23
|
+
*
|
|
24
|
+
* @param state Store state.
|
|
25
|
+
* @param name Ability name.
|
|
26
|
+
* @return Ability object or undefined if not found.
|
|
27
|
+
*/
|
|
45
28
|
function getAbility(state, name) {
|
|
46
|
-
|
|
29
|
+
return state.abilitiesByName[name];
|
|
47
30
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Returns all registered ability categories.
|
|
33
|
+
*
|
|
34
|
+
* @param state Store state.
|
|
35
|
+
* @return Array of categories.
|
|
36
|
+
*/
|
|
37
|
+
const getAbilityCategories = (0, _wordpress_data.createSelector)((state) => {
|
|
38
|
+
return Object.values(state.categoriesBySlug);
|
|
39
|
+
}, (state) => [state.categoriesBySlug]);
|
|
40
|
+
/**
|
|
41
|
+
* Returns a specific ability category by slug.
|
|
42
|
+
*
|
|
43
|
+
* @param state Store state.
|
|
44
|
+
* @param slug Category slug.
|
|
45
|
+
* @return Category object or undefined if not found.
|
|
46
|
+
*/
|
|
54
47
|
function getAbilityCategory(state, slug) {
|
|
55
|
-
|
|
48
|
+
return state.categoriesBySlug[slug];
|
|
56
49
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
//# sourceMappingURL=selectors.cjs.map
|
|
50
|
+
exports.getAbilities = getAbilities;
|
|
51
|
+
exports.getAbility = getAbility;
|
|
52
|
+
exports.getAbilityCategories = getAbilityCategories;
|
|
53
|
+
exports.getAbilityCategory = getAbilityCategory;
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=selectors.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/selectors.ts"],
|
|
4
|
-
"sourcesContent": ["import { createSelector } from '@wordpress/data';\nimport type { Ability, AbilityCategory, AbilitiesQueryArgs } from '../types';\nimport type { AbilitiesState } from './types';\n\n/**\n * Returns all registered abilities.\n * Optionally filters by query arguments.\n *\n * @param state Store state.\n * @param args Optional query arguments to filter. Defaults to empty object.\n * @return Array of abilities.\n */\nexport const getAbilities = createSelector(\n\t(\n\t\tstate: AbilitiesState,\n\t\t{ category }: AbilitiesQueryArgs = {}\n\t): Ability[] => {\n\t\tconst abilities = Object.values( state.abilitiesByName );\n\t\tif ( category ) {\n\t\t\treturn abilities.filter(\n\t\t\t\t( ability ) => ability.category === category\n\t\t\t);\n\t\t}\n\t\treturn abilities;\n\t},\n\t( state: AbilitiesState, { category }: AbilitiesQueryArgs = {} ) => [\n\t\tstate.abilitiesByName,\n\t\tcategory,\n\t]\n);\n\n/**\n * Returns a specific ability by name.\n *\n * @param state Store state.\n * @param name Ability name.\n * @return Ability object or undefined if not found.\n */\nexport function getAbility(\n\tstate: AbilitiesState,\n\tname: string\n): Ability | undefined {\n\treturn state.abilitiesByName[ name ];\n}\n\n/**\n * Returns all registered ability categories.\n *\n * @param state Store state.\n * @return Array of categories.\n */\nexport const getAbilityCategories = createSelector(\n\t( state: AbilitiesState ): AbilityCategory[] => {\n\t\treturn Object.values( state.categoriesBySlug );\n\t},\n\t( state: AbilitiesState ) => [ state.categoriesBySlug ]\n);\n\n/**\n * Returns a specific ability category by slug.\n *\n * @param state Store state.\n * @param slug Category slug.\n * @return Category object or undefined if not found.\n */\nexport function getAbilityCategory(\n\tstate: AbilitiesState,\n\tslug: string\n): AbilityCategory | undefined {\n\treturn state.categoriesBySlug[ slug ];\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA+B;AAYxB,IAAM,mBAAe;AAAA,EAC3B,CACC,OACA,EAAE,SAAS,IAAwB,CAAC,MACrB;AACf,UAAM,YAAY,OAAO,OAAQ,MAAM,eAAgB;AACvD,QAAK,UAAW;AACf,aAAO,UAAU;AAAA,QAChB,CAAE,YAAa,QAAQ,aAAa;AAAA,MACrC;AAAA,IACD;AACA,WAAO;AAAA,EACR;AAAA,EACA,CAAE,OAAuB,EAAE,SAAS,IAAwB,CAAC,MAAO;AAAA,IACnE,MAAM;AAAA,IACN;AAAA,EACD;AACD;AASO,SAAS,WACf,OACA,MACsB;AACtB,SAAO,MAAM,gBAAiB,IAAK;AACpC;AAQO,IAAM,2BAAuB;AAAA,EACnC,CAAE,UAA8C;AAC/C,WAAO,OAAO,OAAQ,MAAM,gBAAiB;AAAA,EAC9C;AAAA,EACA,CAAE,UAA2B,CAAE,MAAM,gBAAiB;AACvD;AASO,SAAS,mBACf,OACA,MAC8B;AAC9B,SAAO,MAAM,iBAAkB,IAAK;AACrC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"selectors.cjs","names":["createSelector"],"sources":["../../src/store/selectors.ts"],"sourcesContent":["import { createSelector } from '@wordpress/data';\nimport type { Ability, AbilityCategory, AbilitiesQueryArgs } from '../types';\nimport type { AbilitiesState } from './types';\n\n/**\n * Returns all registered abilities.\n * Optionally filters by query arguments.\n *\n * @param state Store state.\n * @param args Optional query arguments to filter. Defaults to empty object.\n * @return Array of abilities.\n */\nexport const getAbilities = createSelector(\n\t(\n\t\tstate: AbilitiesState,\n\t\t{ category }: AbilitiesQueryArgs = {}\n\t): Ability[] => {\n\t\tconst abilities = Object.values( state.abilitiesByName );\n\t\tif ( category ) {\n\t\t\treturn abilities.filter(\n\t\t\t\t( ability ) => ability.category === category\n\t\t\t);\n\t\t}\n\t\treturn abilities;\n\t},\n\t( state: AbilitiesState, { category }: AbilitiesQueryArgs = {} ) => [\n\t\tstate.abilitiesByName,\n\t\tcategory,\n\t]\n);\n\n/**\n * Returns a specific ability by name.\n *\n * @param state Store state.\n * @param name Ability name.\n * @return Ability object or undefined if not found.\n */\nexport function getAbility(\n\tstate: AbilitiesState,\n\tname: string\n): Ability | undefined {\n\treturn state.abilitiesByName[ name ];\n}\n\n/**\n * Returns all registered ability categories.\n *\n * @param state Store state.\n * @return Array of categories.\n */\nexport const getAbilityCategories = createSelector(\n\t( state: AbilitiesState ): AbilityCategory[] => {\n\t\treturn Object.values( state.categoriesBySlug );\n\t},\n\t( state: AbilitiesState ) => [ state.categoriesBySlug ]\n);\n\n/**\n * Returns a specific ability category by slug.\n *\n * @param state Store state.\n * @param slug Category slug.\n * @return Category object or undefined if not found.\n */\nexport function getAbilityCategory(\n\tstate: AbilitiesState,\n\tslug: string\n): AbilityCategory | undefined {\n\treturn state.categoriesBySlug[ slug ];\n}\n"],"mappings":";;;;;;;;;;;;;;;AAYA,MAAa,gBAAA,GAAeA,gBAAAA,eAAAA,EAE1B,OACA,EAAE,aAAiC,CAAC,MACrB;CACf,MAAM,YAAY,OAAO,OAAQ,MAAM,eAAgB;CACvD,IAAK,UACJ,OAAO,UAAU,QACd,YAAa,QAAQ,aAAa,QACrC;CAED,OAAO;AACR,IACE,OAAuB,EAAE,aAAiC,CAAC,MAAO,CACnE,MAAM,iBACN,QACD,CACD;;;;;;;;AASA,SAAgB,WACf,OACA,MACsB;CACtB,OAAO,MAAM,gBAAiB;AAC/B;;;;;;;AAQA,MAAa,wBAAA,GAAuBA,gBAAAA,eAAAA,EACjC,UAA8C;CAC/C,OAAO,OAAO,OAAQ,MAAM,gBAAiB;AAC9C,IACE,UAA2B,CAAE,MAAM,gBAAiB,CACvD;;;;;;;;AASA,SAAgB,mBACf,OACA,MAC8B;CAC9B,OAAO,MAAM,iBAAkB;AAChC"}
|
package/build/store/types.cjs
CHANGED
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
|
|
16
|
-
// packages/abilities/src/store/types.ts
|
|
17
|
-
var types_exports = {};
|
|
18
|
-
module.exports = __toCommonJS(types_exports);
|
|
19
|
-
//# sourceMappingURL=types.cjs.map
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
package/build/types.cjs
CHANGED
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
|
|
16
|
-
// packages/abilities/src/types.ts
|
|
17
|
-
var types_exports = {};
|
|
18
|
-
module.exports = __toCommonJS(types_exports);
|
|
19
|
-
//# sourceMappingURL=types.cjs.map
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|