@wordpress/abilities 0.24.0 → 0.26.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.
Files changed (41) hide show
  1. package/build/api.cjs +176 -122
  2. package/build/api.cjs.map +1 -7
  3. package/build/index.cjs +73 -52
  4. package/build/store/actions.cjs +119 -187
  5. package/build/store/actions.cjs.map +1 -7
  6. package/build/store/constants.cjs +23 -47
  7. package/build/store/constants.cjs.map +1 -7
  8. package/build/store/index.cjs +36 -40
  9. package/build/store/index.cjs.map +1 -7
  10. package/build/store/reducer.cjs +102 -94
  11. package/build/store/reducer.cjs.map +1 -7
  12. package/build/store/selectors.cjs +49 -58
  13. package/build/store/selectors.cjs.map +1 -7
  14. package/build/store/types.cjs +4 -18
  15. package/build/types.cjs +4 -18
  16. package/build/validation.cjs +122 -137
  17. package/build/validation.cjs.map +1 -7
  18. package/build-module/api.mjs +161 -87
  19. package/build-module/api.mjs.map +1 -7
  20. package/build-module/index.mjs +2 -26
  21. package/build-module/store/actions.mjs +112 -167
  22. package/build-module/store/actions.mjs.map +1 -7
  23. package/build-module/store/constants.mjs +13 -17
  24. package/build-module/store/constants.mjs.map +1 -7
  25. package/build-module/store/index.mjs +11 -9
  26. package/build-module/store/index.mjs.map +1 -7
  27. package/build-module/store/reducer.mjs +97 -78
  28. package/build-module/store/reducer.mjs.map +1 -7
  29. package/build-module/store/selectors.mjs +42 -31
  30. package/build-module/store/selectors.mjs.map +1 -7
  31. package/build-module/store/types.mjs +0 -1
  32. package/build-module/types.mjs +0 -1
  33. package/build-module/validation.mjs +101 -109
  34. package/build-module/validation.mjs.map +1 -7
  35. package/package.json +5 -5
  36. package/build/index.cjs.map +0 -7
  37. package/build/store/types.cjs.map +0 -7
  38. package/build/types.cjs.map +0 -7
  39. package/build-module/index.mjs.map +0 -7
  40. package/build-module/store/types.mjs.map +0 -7
  41. package/build-module/types.mjs.map +0 -7
@@ -1,106 +1,114 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
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
- module.exports = __toCommonJS(reducer_exports);
26
- var import_data = require("@wordpress/data");
27
- var import_constants = require("./constants.cjs");
28
- var ABILITY_KEYS = [
29
- "name",
30
- "label",
31
- "description",
32
- "category",
33
- "input_schema",
34
- "output_schema",
35
- "meta",
36
- "callback",
37
- "permissionCallback"
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
- var CATEGORY_KEYS = ["slug", "label", "description", "meta"];
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
- return Object.keys(ability).filter(
42
- (key) => ABILITY_KEYS.includes(key) && ability[key] !== void 0
43
- ).reduce(
44
- (obj, key) => ({ ...obj, [key]: ability[key] }),
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
- return Object.keys(category).filter(
50
- (key) => CATEGORY_KEYS.includes(key) && category[key] !== void 0
51
- ).reduce(
52
- (obj, key) => ({ ...obj, [key]: category[key] }),
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
- var DEFAULT_STATE = {};
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
- switch (action.type) {
59
- case import_constants.REGISTER_ABILITY: {
60
- if (!action.ability) {
61
- return state;
62
- }
63
- return {
64
- ...state,
65
- [action.ability.name]: sanitizeAbility(action.ability)
66
- };
67
- }
68
- case import_constants.UNREGISTER_ABILITY: {
69
- if (!state[action.name]) {
70
- return state;
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
- var DEFAULT_CATEGORIES_STATE = {};
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
- switch (action.type) {
82
- case import_constants.REGISTER_ABILITY_CATEGORY: {
83
- if (!action.category) {
84
- return state;
85
- }
86
- return {
87
- ...state,
88
- [action.category.slug]: sanitizeCategory(action.category)
89
- };
90
- }
91
- case import_constants.UNREGISTER_ABILITY_CATEGORY: {
92
- if (!state[action.slug]) {
93
- return state;
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, import_data.combineReducers)({
103
- abilitiesByName,
104
- categoriesBySlug
108
+ var reducer_default = (0, _wordpress_data.combineReducers)({
109
+ abilitiesByName,
110
+ categoriesBySlug
105
111
  });
106
- //# sourceMappingURL=reducer.cjs.map
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;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAgC;AAEhC,uBAKO;AAMP,IAAM,eAAe;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAMA,IAAM,gBAAgB,CAAE,QAAQ,SAAS,eAAe,MAAO;AAS/D,SAAS,gBAAiB,SAAwB;AACjD,SAAO,OAAO,KAAM,OAAQ,EAC1B;AAAA,IACA,CAAE,QACD,aAAa,SAAU,GAAW,KAClC,QAAS,GAAI,MAAM;AAAA,EACrB,EACC;AAAA,IACA,CAAE,KAAK,SAAW,EAAE,GAAG,KAAK,CAAE,GAAI,GAAG,QAAS,GAAI,EAAE;AAAA,IACpD,CAAC;AAAA,EACF;AACF;AASA,SAAS,iBAAkB,UAAiC;AAC3D,SAAO,OAAO,KAAM,QAAS,EAC3B;AAAA,IACA,CAAE,QACD,cAAc,SAAU,GAAW,KACnC,SAAU,GAAI,MAAM;AAAA,EACtB,EACC;AAAA,IACA,CAAE,KAAK,SAAW,EAAE,GAAG,KAAK,CAAE,GAAI,GAAG,SAAU,GAAI,EAAE;AAAA,IACrD,CAAC;AAAA,EACF;AACF;AA2BA,IAAM,gBAA2C,CAAC;AASlD,SAAS,gBACR,QAAmC,eACnC,QAC4B;AAC5B,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK,mCAAkB;AACtB,UAAK,CAAE,OAAO,SAAU;AACvB,eAAO;AAAA,MACR;AACA,aAAO;AAAA,QACN,GAAG;AAAA,QACH,CAAE,OAAO,QAAQ,IAAK,GAAG,gBAAiB,OAAO,OAAQ;AAAA,MAC1D;AAAA,IACD;AAAA,IACA,KAAK,qCAAoB;AACxB,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,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;;;;;;;;AAS/D,SAAS,gBAAiB,SAAwB;CACjD,OAAO,OAAO,KAAM,OAAQ,CAAC,CAC3B,QACE,QACD,aAAa,SAAU,GAAW,KAClC,QAAS,SAAU,KAAA,CACrB,CAAC,CACA,QACE,KAAK,SAAW;EAAE,GAAG;GAAO,MAAO,QAAS;CAAM,IACpD,CAAC,CACF;AACF;;;;;;;;AASA,SAAS,iBAAkB,UAAiC;CAC3D,OAAO,OAAO,KAAM,QAAS,CAAC,CAC5B,QACE,QACD,cAAc,SAAU,GAAW,KACnC,SAAU,SAAU,KAAA,CACtB,CAAC,CACA,QACE,KAAK,SAAW;EAAE,GAAG;GAAO,MAAO,SAAU;CAAM,IACrD,CAAC,CACF;AACF;AA2BA,MAAM,gBAA2C,CAAC;;;;;;;;AASlD,SAAS,gBACR,QAAmC,eACnC,QAC4B;CAC5B,QAAS,OAAO,MAAhB;EACC,KAAKA,eAAAA;GACJ,IAAK,CAAE,OAAO,SACb,OAAO;GAER,OAAO;IACN,GAAG;KACD,OAAO,QAAQ,OAAQ,gBAAiB,OAAO,OAAQ;GAC1D;EAED,KAAKC,eAAAA,oBAAoB;GACxB,IAAK,CAAE,MAAO,OAAO,OACpB,OAAO;GAER,MAAM,GAAI,OAAO,OAAQ,GAAG,GAAG,aAAa;GAC5C,OAAO;EACR;EACA,SACC,OAAO;CACT;AACD;AAEA,MAAM,2BAA8D,CAAC;;;;;;;;AASrE,SAAS,iBACR,QAA2C,0BAC3C,QACoC;CACpC,QAAS,OAAO,MAAhB;EACC,KAAKC,eAAAA;GACJ,IAAK,CAAE,OAAO,UACb,OAAO;GAER,OAAO;IACN,GAAG;KACD,OAAO,SAAS,OAAQ,iBAAkB,OAAO,QAAS;GAC7D;EAED,KAAKC,eAAAA,6BAA6B;GACjC,IAAK,CAAE,MAAO,OAAO,OACpB,OAAO;GAER,MAAM,GAAI,OAAO,OAAQ,GAAG,GAAG,aAAa;GAC5C,OAAO;EACR;EACA,SACC,OAAO;CACT;AACD;AAEA,IAAA,mBAAA,GAAeC,gBAAAA,gBAAAA,CAAiB;CAC/B;CACA;AACD,CAAE"}
@@ -1,64 +1,55 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
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
- module.exports = __toCommonJS(selectors_exports);
29
- var import_data = require("@wordpress/data");
30
- var getAbilities = (0, import_data.createSelector)(
31
- (state, { category } = {}) => {
32
- const abilities = Object.values(state.abilitiesByName);
33
- if (category) {
34
- return abilities.filter(
35
- (ability) => ability.category === category
36
- );
37
- }
38
- return abilities;
39
- },
40
- (state, { category } = {}) => [
41
- state.abilitiesByName,
42
- category
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
- return state.abilitiesByName[name];
29
+ return state.abilitiesByName[name];
47
30
  }
48
- var getAbilityCategories = (0, import_data.createSelector)(
49
- (state) => {
50
- return Object.values(state.categoriesBySlug);
51
- },
52
- (state) => [state.categoriesBySlug]
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
- return state.categoriesBySlug[slug];
48
+ return state.categoriesBySlug[slug];
56
49
  }
57
- // Annotate the CommonJS export names for ESM import in node:
58
- 0 && (module.exports = {
59
- getAbilities,
60
- getAbility,
61
- getAbilityCategories,
62
- getAbilityCategory
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"}
@@ -1,19 +1,5 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
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
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
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
+ });