@wordpress/abilities 0.2.0 → 0.2.1-next.738bb1424.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/README.md +32 -40
- package/build/{api.js → api.cjs} +22 -69
- package/build/api.cjs.map +7 -0
- package/build/{index.js → index.cjs} +4 -4
- package/build/{index.js.map → index.cjs.map} +2 -2
- package/build/store/{actions.js → actions.cjs} +43 -33
- package/build/store/actions.cjs.map +7 -0
- package/build/store/{constants.js → constants.cjs} +7 -16
- package/build/store/constants.cjs.map +7 -0
- package/build/store/{index.js → index.cjs} +6 -32
- package/build/store/index.cjs.map +7 -0
- package/build/store/{reducer.js → reducer.cjs} +4 -24
- package/build/store/reducer.cjs.map +7 -0
- package/build/store/{selectors.js → selectors.cjs} +2 -2
- package/build/store/selectors.cjs.map +7 -0
- package/build/store/types.cjs +19 -0
- package/build/store/types.cjs.map +7 -0
- package/build/{types.js → types.cjs} +1 -1
- package/build/types.cjs.map +7 -0
- package/build/{validation.js → validation.cjs} +3 -3
- package/build-module/api.js +22 -59
- package/build-module/api.js.map +2 -2
- package/build-module/index.js +3 -3
- package/build-module/index.js.map +2 -2
- package/build-module/store/actions.js +44 -33
- package/build-module/store/actions.js.map +2 -2
- package/build-module/store/constants.js +4 -10
- package/build-module/store/constants.js.map +2 -2
- package/build-module/store/index.js +6 -37
- package/build-module/store/index.js.map +2 -2
- package/build-module/store/reducer.js +3 -25
- package/build-module/store/reducer.js.map +2 -2
- package/build-module/store/selectors.js +1 -1
- package/build-module/store/selectors.js.map +2 -2
- package/build-module/store/types.js +1 -0
- package/build-module/store/types.js.map +7 -0
- package/build-types/api.d.ts +16 -23
- package/build-types/api.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/store/actions.d.ts +5 -27
- package/build-types/store/actions.d.ts.map +1 -1
- package/build-types/store/constants.d.ts +2 -5
- package/build-types/store/constants.d.ts.map +1 -1
- package/build-types/store/index.d.ts +1 -1
- package/build-types/store/index.d.ts.map +1 -1
- package/build-types/store/reducer.d.ts +21 -11
- package/build-types/store/reducer.d.ts.map +1 -1
- package/build-types/store/selectors.d.ts +2 -1
- package/build-types/store/selectors.d.ts.map +1 -1
- package/build-types/store/types.d.ts +18 -0
- package/build-types/store/types.d.ts.map +1 -0
- package/build-types/types.d.ts +14 -24
- package/build-types/types.d.ts.map +1 -1
- package/package.json +8 -10
- package/src/api.ts +43 -123
- package/src/index.ts +0 -1
- package/src/store/actions.ts +61 -46
- package/src/store/constants.ts +4 -5
- package/src/store/index.ts +2 -34
- package/src/store/reducer.ts +27 -33
- package/src/store/selectors.ts +3 -7
- package/src/store/tests/actions.test.ts +100 -244
- package/src/store/tests/reducer.test.ts +0 -451
- package/src/store/tests/selectors.test.ts +1 -1
- package/src/store/types.ts +19 -0
- package/src/tests/api.test.ts +112 -158
- package/src/types.ts +14 -26
- package/build/api.js.map +0 -7
- package/build/store/actions.js.map +0 -7
- package/build/store/constants.js.map +0 -7
- package/build/store/index.js.map +0 -7
- package/build/store/reducer.js.map +0 -7
- package/build/store/resolvers.js +0 -107
- package/build/store/resolvers.js.map +0 -7
- package/build/store/selectors.js.map +0 -7
- package/build/types.js.map +0 -7
- package/build-module/store/resolvers.js +0 -84
- package/build-module/store/resolvers.js.map +0 -7
- package/build-types/store/resolvers.d.ts +0 -47
- package/build-types/store/resolvers.d.ts.map +0 -1
- package/src/store/resolvers.ts +0 -151
- package/src/store/tests/resolvers.test.ts +0 -642
- /package/build/{validation.js.map → validation.cjs.map} +0 -0
package/src/store/constants.ts
CHANGED
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
* Store constants
|
|
3
3
|
*/
|
|
4
4
|
export const STORE_NAME = 'core/abilities';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export const
|
|
5
|
+
|
|
6
|
+
// Validation patterns
|
|
7
|
+
export const ABILITY_NAME_PATTERN = /^[a-z0-9-]+\/[a-z0-9-]+$/;
|
|
8
|
+
export const CATEGORY_SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
8
9
|
|
|
9
10
|
// Action types
|
|
10
|
-
export const RECEIVE_ABILITIES = 'RECEIVE_ABILITIES';
|
|
11
11
|
export const REGISTER_ABILITY = 'REGISTER_ABILITY';
|
|
12
12
|
export const UNREGISTER_ABILITY = 'UNREGISTER_ABILITY';
|
|
13
|
-
export const RECEIVE_CATEGORIES = 'RECEIVE_CATEGORIES';
|
|
14
13
|
export const REGISTER_ABILITY_CATEGORY = 'REGISTER_ABILITY_CATEGORY';
|
|
15
14
|
export const UNREGISTER_ABILITY_CATEGORY = 'UNREGISTER_ABILITY_CATEGORY';
|
package/src/store/index.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { createReduxStore, register
|
|
5
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
6
|
-
import { __ } from '@wordpress/i18n';
|
|
4
|
+
import { createReduxStore, register } from '@wordpress/data';
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* Internal dependencies
|
|
@@ -11,13 +9,7 @@ import { __ } from '@wordpress/i18n';
|
|
|
11
9
|
import reducer from './reducer';
|
|
12
10
|
import * as actions from './actions';
|
|
13
11
|
import * as selectors from './selectors';
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
16
|
-
STORE_NAME,
|
|
17
|
-
ENTITY_KIND,
|
|
18
|
-
ENTITY_NAME,
|
|
19
|
-
ENTITY_NAME_CATEGORIES,
|
|
20
|
-
} from './constants';
|
|
12
|
+
import { STORE_NAME } from './constants';
|
|
21
13
|
|
|
22
14
|
/**
|
|
23
15
|
* The abilities store definition.
|
|
@@ -26,30 +18,6 @@ export const store = createReduxStore( STORE_NAME, {
|
|
|
26
18
|
reducer,
|
|
27
19
|
actions,
|
|
28
20
|
selectors,
|
|
29
|
-
resolvers,
|
|
30
21
|
} );
|
|
31
22
|
|
|
32
23
|
register( store );
|
|
33
|
-
|
|
34
|
-
dispatch( coreStore ).addEntities( [
|
|
35
|
-
{
|
|
36
|
-
name: ENTITY_NAME,
|
|
37
|
-
kind: ENTITY_KIND,
|
|
38
|
-
key: 'name',
|
|
39
|
-
baseURL: '/wp-abilities/v1/abilities',
|
|
40
|
-
baseURLParams: { context: 'edit' },
|
|
41
|
-
plural: 'abilities',
|
|
42
|
-
label: __( 'Abilities' ),
|
|
43
|
-
supportsPagination: true,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: ENTITY_NAME_CATEGORIES,
|
|
47
|
-
kind: ENTITY_KIND,
|
|
48
|
-
key: 'slug',
|
|
49
|
-
baseURL: '/wp-abilities/v1/categories',
|
|
50
|
-
baseURLParams: { context: 'edit' },
|
|
51
|
-
plural: 'ability-categories',
|
|
52
|
-
label: __( 'Ability Categories' ),
|
|
53
|
-
supportsPagination: true,
|
|
54
|
-
},
|
|
55
|
-
] );
|
package/src/store/reducer.ts
CHANGED
|
@@ -8,10 +8,8 @@ import { combineReducers } from '@wordpress/data';
|
|
|
8
8
|
*/
|
|
9
9
|
import type { Ability, AbilityCategory } from '../types';
|
|
10
10
|
import {
|
|
11
|
-
RECEIVE_ABILITIES,
|
|
12
11
|
REGISTER_ABILITY,
|
|
13
12
|
UNREGISTER_ABILITY,
|
|
14
|
-
RECEIVE_CATEGORIES,
|
|
15
13
|
REGISTER_ABILITY_CATEGORY,
|
|
16
14
|
UNREGISTER_ABILITY_CATEGORY,
|
|
17
15
|
} from './constants';
|
|
@@ -78,16 +76,32 @@ function sanitizeCategory( category: any ): AbilityCategory {
|
|
|
78
76
|
);
|
|
79
77
|
}
|
|
80
78
|
|
|
81
|
-
interface
|
|
82
|
-
type:
|
|
83
|
-
|
|
84
|
-
ability?: Ability;
|
|
85
|
-
categories?: AbilityCategory[];
|
|
86
|
-
category?: AbilityCategory;
|
|
87
|
-
name?: string;
|
|
88
|
-
slug?: string;
|
|
79
|
+
interface RegisterAbilityAction {
|
|
80
|
+
type: typeof REGISTER_ABILITY;
|
|
81
|
+
ability: Ability;
|
|
89
82
|
}
|
|
90
83
|
|
|
84
|
+
interface UnregisterAbilityAction {
|
|
85
|
+
type: typeof UNREGISTER_ABILITY;
|
|
86
|
+
name: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface RegisterAbilityCategoryAction {
|
|
90
|
+
type: typeof REGISTER_ABILITY_CATEGORY;
|
|
91
|
+
category: AbilityCategory;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface UnregisterAbilityCategoryAction {
|
|
95
|
+
type: typeof UNREGISTER_ABILITY_CATEGORY;
|
|
96
|
+
slug: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
type AbilitiesAction = RegisterAbilityAction | UnregisterAbilityAction;
|
|
100
|
+
|
|
101
|
+
type AbilitiesCategoryAction =
|
|
102
|
+
| RegisterAbilityCategoryAction
|
|
103
|
+
| UnregisterAbilityCategoryAction;
|
|
104
|
+
|
|
91
105
|
const DEFAULT_STATE: Record< string, Ability > = {};
|
|
92
106
|
|
|
93
107
|
/**
|
|
@@ -102,16 +116,6 @@ function abilitiesByName(
|
|
|
102
116
|
action: AbilitiesAction
|
|
103
117
|
): Record< string, Ability > {
|
|
104
118
|
switch ( action.type ) {
|
|
105
|
-
case RECEIVE_ABILITIES: {
|
|
106
|
-
if ( ! action.abilities ) {
|
|
107
|
-
return state;
|
|
108
|
-
}
|
|
109
|
-
const newState: Record< string, Ability > = {};
|
|
110
|
-
action.abilities.forEach( ( ability ) => {
|
|
111
|
-
newState[ ability.name ] = sanitizeAbility( ability );
|
|
112
|
-
} );
|
|
113
|
-
return newState;
|
|
114
|
-
}
|
|
115
119
|
case REGISTER_ABILITY: {
|
|
116
120
|
if ( ! action.ability ) {
|
|
117
121
|
return state;
|
|
@@ -122,7 +126,7 @@ function abilitiesByName(
|
|
|
122
126
|
};
|
|
123
127
|
}
|
|
124
128
|
case UNREGISTER_ABILITY: {
|
|
125
|
-
if ( !
|
|
129
|
+
if ( ! state[ action.name ] ) {
|
|
126
130
|
return state;
|
|
127
131
|
}
|
|
128
132
|
const { [ action.name ]: _, ...newState } = state;
|
|
@@ -144,19 +148,9 @@ const DEFAULT_CATEGORIES_STATE: Record< string, AbilityCategory > = {};
|
|
|
144
148
|
*/
|
|
145
149
|
function categoriesBySlug(
|
|
146
150
|
state: Record< string, AbilityCategory > = DEFAULT_CATEGORIES_STATE,
|
|
147
|
-
action:
|
|
151
|
+
action: AbilitiesCategoryAction
|
|
148
152
|
): Record< string, AbilityCategory > {
|
|
149
153
|
switch ( action.type ) {
|
|
150
|
-
case RECEIVE_CATEGORIES: {
|
|
151
|
-
if ( ! action.categories ) {
|
|
152
|
-
return state;
|
|
153
|
-
}
|
|
154
|
-
const newState: Record< string, AbilityCategory > = {};
|
|
155
|
-
action.categories.forEach( ( category ) => {
|
|
156
|
-
newState[ category.slug ] = sanitizeCategory( category );
|
|
157
|
-
} );
|
|
158
|
-
return newState;
|
|
159
|
-
}
|
|
160
154
|
case REGISTER_ABILITY_CATEGORY: {
|
|
161
155
|
if ( ! action.category ) {
|
|
162
156
|
return state;
|
|
@@ -167,7 +161,7 @@ function categoriesBySlug(
|
|
|
167
161
|
};
|
|
168
162
|
}
|
|
169
163
|
case UNREGISTER_ABILITY_CATEGORY: {
|
|
170
|
-
if ( !
|
|
164
|
+
if ( ! state[ action.slug ] ) {
|
|
171
165
|
return state;
|
|
172
166
|
}
|
|
173
167
|
const { [ action.slug ]: _, ...newState } = state;
|
package/src/store/selectors.ts
CHANGED
|
@@ -6,12 +6,8 @@ import { createSelector } from '@wordpress/data';
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
-
import type {
|
|
10
|
-
|
|
11
|
-
AbilityCategory,
|
|
12
|
-
AbilitiesQueryArgs,
|
|
13
|
-
AbilitiesState,
|
|
14
|
-
} from '../types';
|
|
9
|
+
import type { Ability, AbilityCategory, AbilitiesQueryArgs } from '../types';
|
|
10
|
+
import type { AbilitiesState } from './types';
|
|
15
11
|
|
|
16
12
|
/**
|
|
17
13
|
* Returns all registered abilities.
|
|
@@ -34,7 +30,7 @@ export const getAbilities = createSelector(
|
|
|
34
30
|
}
|
|
35
31
|
return abilities;
|
|
36
32
|
},
|
|
37
|
-
( state: AbilitiesState, category
|
|
33
|
+
( state: AbilitiesState, { category }: AbilitiesQueryArgs = {} ) => [
|
|
38
34
|
state.abilitiesByName,
|
|
39
35
|
category,
|
|
40
36
|
]
|