@wordpress/preferences 4.33.1 → 4.34.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/CHANGELOG.md +6 -0
- package/README.md +10 -10
- package/build/components/index.js +1 -0
- package/build/components/index.js.map +2 -2
- package/build/components/preference-base-option/index.js +8 -1
- package/build/components/preference-base-option/index.js.map +3 -3
- package/build/components/preference-base-option/types.js +17 -0
- package/build/components/preference-base-option/types.js.map +7 -0
- package/build/components/preference-toggle-control/index.js +3 -2
- package/build/components/preference-toggle-control/index.js.map +3 -3
- package/build/components/preference-toggle-menu-item/index.js +2 -1
- package/build/components/preference-toggle-menu-item/index.js.map +3 -3
- package/build/components/preferences-modal/index.js +5 -1
- package/build/components/preferences-modal/index.js.map +3 -3
- package/build/components/preferences-modal/types.js +17 -0
- package/build/components/preferences-modal/types.js.map +7 -0
- package/build/components/preferences-modal-section/index.js +1 -0
- package/build/components/preferences-modal-section/index.js.map +3 -3
- package/build/components/preferences-modal-tabs/index.js +25 -18
- package/build/components/preferences-modal-tabs/index.js.map +3 -3
- package/build/index.js +1 -0
- package/build/index.js.map +2 -2
- package/build/lock-unlock.js +1 -0
- package/build/lock-unlock.js.map +2 -2
- package/build/private-apis.js +1 -0
- package/build/private-apis.js.map +2 -2
- package/build/store/actions.js +1 -0
- package/build/store/actions.js.map +3 -3
- package/build/store/constants.js +1 -0
- package/build/store/constants.js.map +3 -3
- package/build/store/index.js +1 -0
- package/build/store/index.js.map +3 -3
- package/build/store/reducer.js +1 -0
- package/build/store/reducer.js.map +3 -3
- package/build/store/selectors.js +7 -4
- package/build/store/selectors.js.map +3 -3
- package/build/store/types.js +17 -0
- package/build/store/types.js.map +7 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/preference-base-option/index.js +7 -1
- package/build-module/components/preference-base-option/index.js.map +3 -3
- package/build-module/components/preference-base-option/types.js +1 -0
- package/build-module/components/preference-base-option/types.js.map +7 -0
- package/build-module/components/preference-toggle-control/index.js +2 -2
- package/build-module/components/preference-toggle-control/index.js.map +3 -3
- package/build-module/components/preference-toggle-menu-item/index.js +1 -1
- package/build-module/components/preference-toggle-menu-item/index.js.map +3 -3
- package/build-module/components/preferences-modal/index.js +4 -1
- package/build-module/components/preferences-modal/index.js.map +3 -3
- package/build-module/components/preferences-modal/types.js +1 -0
- package/build-module/components/preferences-modal/types.js.map +7 -0
- package/build-module/components/preferences-modal-section/index.js.map +3 -3
- package/build-module/components/preferences-modal-tabs/index.js +24 -18
- package/build-module/components/preferences-modal-tabs/index.js.map +3 -3
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js.map +3 -3
- package/build-module/store/constants.js.map +3 -3
- package/build-module/store/index.js.map +3 -3
- package/build-module/store/reducer.js.map +3 -3
- package/build-module/store/selectors.js +6 -4
- package/build-module/store/selectors.js.map +3 -3
- package/build-module/store/types.js +1 -0
- package/build-module/store/types.js.map +7 -0
- package/build-types/components/index.d.ts +2 -0
- package/build-types/components/index.d.ts.map +1 -0
- package/build-types/components/preference-base-option/index.d.ts +7 -0
- package/build-types/components/preference-base-option/index.d.ts.map +1 -0
- package/build-types/components/preference-base-option/types.d.ts +11 -0
- package/build-types/components/preference-base-option/types.d.ts.map +1 -0
- package/build-types/components/preference-toggle-control/index.d.ts +9 -0
- package/build-types/components/preference-toggle-control/index.d.ts.map +1 -0
- package/build-types/components/preference-toggle-menu-item/index.d.ts +18 -0
- package/build-types/components/preference-toggle-menu-item/index.d.ts.map +1 -0
- package/build-types/components/preferences-modal/index.d.ts +6 -0
- package/build-types/components/preferences-modal/index.d.ts.map +1 -0
- package/build-types/components/preferences-modal/types.d.ts +11 -0
- package/build-types/components/preferences-modal/types.d.ts.map +1 -0
- package/build-types/components/preferences-modal-section/index.d.ts +8 -0
- package/build-types/components/preferences-modal-section/index.d.ts.map +1 -0
- package/build-types/components/preferences-modal-tabs/index.d.ts +9 -0
- package/build-types/components/preferences-modal-tabs/index.d.ts.map +1 -0
- package/build-types/index.d.ts +4 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/lock-unlock.d.ts +2 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/private-apis.d.ts +2 -0
- package/build-types/private-apis.d.ts.map +1 -0
- package/build-types/store/actions.d.ts +69 -0
- package/build-types/store/actions.d.ts.map +1 -0
- package/build-types/store/constants.d.ts +5 -0
- package/build-types/store/constants.d.ts.map +1 -0
- package/build-types/store/index.d.ts +10 -0
- package/build-types/store/index.d.ts.map +1 -0
- package/build-types/store/reducer.d.ts +39 -0
- package/build-types/store/reducer.d.ts.map +1 -0
- package/build-types/store/selectors.d.ts +16 -0
- package/build-types/store/selectors.d.ts.map +1 -0
- package/build-types/store/types.d.ts +27 -0
- package/build-types/store/types.d.ts.map +1 -0
- package/package.json +16 -12
- package/src/components/preference-base-option/{index.js → index.tsx} +11 -1
- package/src/components/preference-base-option/types.ts +10 -0
- package/src/components/preference-toggle-control/{index.js → index.tsx} +9 -2
- package/src/components/preference-toggle-menu-item/{index.js → index.tsx} +14 -2
- package/src/components/preferences-modal/{index.js → index.tsx} +8 -1
- package/src/components/preferences-modal/types.ts +11 -0
- package/src/components/preferences-modal-section/{index.js → index.tsx} +7 -1
- package/src/components/preferences-modal-tabs/{index.js → index.tsx} +13 -3
- package/src/store/{actions.js → actions.ts} +48 -18
- package/src/store/{constants.js → constants.ts} +0 -2
- package/src/store/{index.js → index.ts} +6 -3
- package/src/store/{reducer.js → reducer.ts} +23 -10
- package/src/store/selectors.ts +67 -0
- package/src/store/types.ts +29 -0
- package/tsconfig.json +16 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/store/selectors.js +0 -57
- /package/src/components/{index.js → index.ts} +0 -0
- /package/src/{index.js → index.ts} +0 -0
- /package/src/{lock-unlock.js → lock-unlock.ts} +0 -0
- /package/src/{private-apis.js → private-apis.ts} +0 -0
- /package/src/store/test/{actions.js → actions.ts} +0 -0
- /package/src/store/test/{reducer.js → reducer.ts} +0 -0
- /package/src/store/test/{selectors.js → selectors.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/preference-base-option/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,KAAK,kBAAkB,GAAG,UAAU,CAAE,OAAO,aAAa,CAAE,CAAE,CAAC,CAAE,CAAC;AAClE,MAAM,MAAM,eAAe,GAAG,IAAI,CACjC,kBAAkB,EAClB,MAAM,GAAG,OAAO,GAAG,UAAU,CAC7B,GAAG;IAAE,SAAS,CAAC,EAAE,kBAAkB,CAAE,SAAS,CAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BaseOptionProps } from '../preference-base-option/types';
|
|
2
|
+
export type PreferenceToggleControlProps = {
|
|
3
|
+
scope: string;
|
|
4
|
+
featureName: string;
|
|
5
|
+
onToggle: () => void;
|
|
6
|
+
} & Omit<BaseOptionProps, 'onChange' | 'isChecked'>;
|
|
7
|
+
declare function PreferenceToggleControl(props: PreferenceToggleControlProps): import("react").JSX.Element;
|
|
8
|
+
export default PreferenceToggleControl;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/preference-toggle-control/index.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAGvE,MAAM,MAAM,4BAA4B,GAAG;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,IAAI,CAAC;CACrB,GAAG,IAAI,CAAE,eAAe,EAAE,UAAU,GAAG,WAAW,CAAE,CAAC;AAEtD,iBAAS,uBAAuB,CAAE,KAAK,EAAE,4BAA4B,+BAwBpE;AAED,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type PreferenceToggleMenuItemProps = {
|
|
2
|
+
scope: string;
|
|
3
|
+
name: string;
|
|
4
|
+
label: string;
|
|
5
|
+
info?: string;
|
|
6
|
+
messageActivated?: string;
|
|
7
|
+
messageDeactivated?: string;
|
|
8
|
+
shortcut?: string | {
|
|
9
|
+
display: string;
|
|
10
|
+
ariaLabel: string;
|
|
11
|
+
};
|
|
12
|
+
handleToggling?: boolean;
|
|
13
|
+
onToggle?: () => void;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export default function PreferenceToggleMenuItem({ scope, name, label, info, messageActivated, messageDeactivated, shortcut, handleToggling, onToggle, disabled, }: PreferenceToggleMenuItemProps): import("react").JSX.Element;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/preference-toggle-menu-item/index.tsx"],"names":[],"mappings":"AAcA,KAAK,6BAA6B,GAAG;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3D,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AACF,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAAE,EACjD,KAAK,EACL,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,gBAAgB,EAChB,kBAAkB,EAClB,QAAQ,EACR,cAAqB,EACrB,QAAqB,EACrB,QAAgB,GAChB,EAAE,6BAA6B,+BA+C/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/preferences-modal/index.tsx"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAE,EACzC,UAAU,EACV,QAAQ,GACR,EAAE,qBAAqB,+BAUvB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { Modal } from '@wordpress/components';
|
|
5
|
+
type ModalProps = Parameters<typeof Modal>[0];
|
|
6
|
+
export type PreferencesModalProps = {
|
|
7
|
+
closeModal: ModalProps['onRequestClose'];
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/components/preferences-modal/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,KAAK,UAAU,GAAG,UAAU,CAAE,OAAO,KAAK,CAAE,CAAE,CAAC,CAAE,CAAC;AAElD,MAAM,MAAM,qBAAqB,GAAG;IACnC,UAAU,EAAE,UAAU,CAAE,gBAAgB,CAAE,CAAC;IAC3C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC1B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type SectionProps = {
|
|
2
|
+
description?: React.ReactNode;
|
|
3
|
+
title?: React.ReactNode;
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
};
|
|
6
|
+
declare const Section: ({ description, title, children }: SectionProps) => import("react").JSX.Element;
|
|
7
|
+
export default Section;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/preferences-modal-section/index.tsx"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IAC1B,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACxB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF,QAAA,MAAM,OAAO,qCAAuC,YAAY,gCAY/D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type PreferencesModalTabsProps = {
|
|
2
|
+
sections: {
|
|
3
|
+
name: string;
|
|
4
|
+
tabLabel: string;
|
|
5
|
+
content: React.ReactNode;
|
|
6
|
+
}[];
|
|
7
|
+
};
|
|
8
|
+
export default function PreferencesModalTabs({ sections, }: PreferencesModalTabsProps): import("react").JSX.Element;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/preferences-modal-tabs/index.tsx"],"names":[],"mappings":"AA8BA,MAAM,MAAM,yBAAyB,GAAG;IACvC,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,KAAK,CAAC,SAAS,CAAA;KAAE,EAAE,CAAC;CACzE,CAAC;AACF,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAE,EAC7C,QAAQ,GACR,EAAE,yBAAyB,+BAgJ3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock-unlock.d.ts","sourceRoot":"","sources":["../src/lock-unlock.ts"],"names":[],"mappings":"AAIA,eAAO,MAAQ,IAAI,mDAAE,MAAM,iCAIzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private-apis.d.ts","sourceRoot":"","sources":["../src/private-apis.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,WAAW,IAAK,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ActionObject, StoreState, WPPreferencesPersistenceLayer } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Returns an action object used in signalling that a preference should be
|
|
7
|
+
* toggled.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} scope The preference scope (e.g. core/edit-post).
|
|
10
|
+
* @param {string} name The preference name.
|
|
11
|
+
*/
|
|
12
|
+
export declare function toggle(scope: string, name: string): ({ select, dispatch }: {
|
|
13
|
+
select: any;
|
|
14
|
+
dispatch: any;
|
|
15
|
+
}) => void;
|
|
16
|
+
type SetAction = ActionObject<'SET_PREFERENCE_VALUE', {
|
|
17
|
+
scope: string;
|
|
18
|
+
name: string;
|
|
19
|
+
value: any;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Returns an action object used in signalling that a preference should be set
|
|
23
|
+
* to a value
|
|
24
|
+
*
|
|
25
|
+
* @param {string} scope The preference scope (e.g. core/edit-post).
|
|
26
|
+
* @param {string} name The preference name.
|
|
27
|
+
* @param {*} value The value to set.
|
|
28
|
+
*
|
|
29
|
+
* @return {SetAction} Action object.
|
|
30
|
+
*/
|
|
31
|
+
export declare function set(scope: string, name: string, value: any): SetAction;
|
|
32
|
+
type ScopedDefaults = StoreState['defaults'][string];
|
|
33
|
+
type SetDefaultsAction = ActionObject<'SET_PREFERENCE_DEFAULTS', {
|
|
34
|
+
scope: string;
|
|
35
|
+
defaults: ScopedDefaults;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Returns an action object used in signalling that preference defaults should
|
|
39
|
+
* be set.
|
|
40
|
+
*
|
|
41
|
+
* @param scope The preference scope (e.g. core/edit-post).
|
|
42
|
+
* @param defaults A key/value map of preference names to values.
|
|
43
|
+
*
|
|
44
|
+
* @return Action object.
|
|
45
|
+
*/
|
|
46
|
+
export declare function setDefaults(scope: string, defaults: ScopedDefaults): SetDefaultsAction;
|
|
47
|
+
type SetPersistenceLayerAction<D extends Object> = ActionObject<'SET_PERSISTENCE_LAYER', {
|
|
48
|
+
persistenceLayer: WPPreferencesPersistenceLayer<D>;
|
|
49
|
+
persistedData: D;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Sets the persistence layer.
|
|
53
|
+
*
|
|
54
|
+
* When a persistence layer is set, the preferences store will:
|
|
55
|
+
* - call `get` immediately and update the store state to the value returned.
|
|
56
|
+
* - call `set` with all preferences whenever a preference changes value.
|
|
57
|
+
*
|
|
58
|
+
* `setPersistenceLayer` should ideally be dispatched at the start of an
|
|
59
|
+
* application's lifecycle, before any other actions have been dispatched to
|
|
60
|
+
* the preferences store.
|
|
61
|
+
*
|
|
62
|
+
* @param persistenceLayer The persistence layer.
|
|
63
|
+
*
|
|
64
|
+
* @return Action object.
|
|
65
|
+
*/
|
|
66
|
+
export declare function setPersistenceLayer<D extends Object>(persistenceLayer: WPPreferencesPersistenceLayer<D>): Promise<SetPersistenceLayerAction<D>>;
|
|
67
|
+
export type AvailableActions = SetAction | SetDefaultsAction | SetPersistenceLayerAction<any>;
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/store/actions.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EACX,YAAY,EACZ,UAAU,EACV,6BAA6B,EAC7B,MAAM,SAAS,CAAC;AAEjB;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;;;WAMlD;AAED,KAAK,SAAS,GAAG,YAAY,CAC5B,sBAAsB,EACtB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,GAAG,CAAA;CAAE,CAC3C,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,GAAG,CAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAI,SAAS,CAOxE;AAED,KAAK,cAAc,GAAG,UAAU,CAAE,UAAU,CAAE,CAAE,MAAM,CAAE,CAAC;AACzD,KAAK,iBAAiB,GAAG,YAAY,CACpC,yBAAyB,EACzB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,cAAc,CAAA;CAAE,CAC3C,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAC1B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,cAAc,GACtB,iBAAiB,CAMnB;AAED,KAAK,yBAAyB,CAAE,CAAC,SAAS,MAAM,IAAK,YAAY,CAChE,uBAAuB,EACvB;IACC,gBAAgB,EAAE,6BAA6B,CAAE,CAAC,CAAE,CAAC;IACrD,aAAa,EAAE,CAAC,CAAC;CACjB,CACD,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,mBAAmB,CAAE,CAAC,SAAS,MAAM,EAC1D,gBAAgB,EAAE,6BAA6B,CAAE,CAAC,CAAE,GAClD,OAAO,CAAE,yBAAyB,CAAE,CAAC,CAAE,CAAE,CAO3C;AAED,MAAM,MAAM,gBAAgB,GACzB,SAAS,GACT,iBAAiB,GACjB,yBAAyB,CAAE,GAAG,CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/store/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,UAAU,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as actions from './actions';
|
|
2
|
+
import * as selectors from './selectors';
|
|
3
|
+
import type { StoreState } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Store definition for the preferences namespace.
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
8
|
+
*/
|
|
9
|
+
export declare const store: import("@wordpress/data/build-types/types").StoreDescriptor<import("@wordpress/data/build-types/types").ReduxStoreConfig<StoreState, typeof actions, typeof selectors>>;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;GAIG;AACH,eAAO,MAAM,KAAK,yKAQf,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { StoreState } from './types';
|
|
5
|
+
import type { AvailableActions } from './actions';
|
|
6
|
+
/**
|
|
7
|
+
* Reducer returning the defaults for user preferences.
|
|
8
|
+
*
|
|
9
|
+
* This is kept intentionally separate from the preferences
|
|
10
|
+
* themselves so that defaults are not persisted.
|
|
11
|
+
*
|
|
12
|
+
* @param state Current state.
|
|
13
|
+
* @param action Dispatched action.
|
|
14
|
+
*
|
|
15
|
+
* @return Updated state.
|
|
16
|
+
*/
|
|
17
|
+
export declare function defaults(state: StoreState["defaults"] | undefined, action: AvailableActions): StoreState['defaults'];
|
|
18
|
+
/**
|
|
19
|
+
* Reducer returning the user preferences.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} state Current state.
|
|
22
|
+
* @param {Object} action Dispatched action.
|
|
23
|
+
*
|
|
24
|
+
* @return {Object} Updated state.
|
|
25
|
+
*/
|
|
26
|
+
export declare const preferences: (state: StoreState["preferences"], action: AvailableActions) => any;
|
|
27
|
+
declare const _default: import("redux").Reducer<{
|
|
28
|
+
defaults: {
|
|
29
|
+
[x: string]: {
|
|
30
|
+
[x: string]: any;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
preferences: any;
|
|
34
|
+
}, AvailableActions, Partial<{
|
|
35
|
+
defaults: never;
|
|
36
|
+
preferences: never;
|
|
37
|
+
}>>;
|
|
38
|
+
export default _default;
|
|
39
|
+
//# sourceMappingURL=reducer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/store/reducer.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAiC,MAAM,SAAS,CAAC;AACzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAElD;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CACvB,KAAK,EAAE,UAAU,CAAE,UAAU,CAAE,YAAK,EACpC,MAAM,EAAE,gBAAgB,GACtB,UAAU,CAAE,UAAU,CAAE,CAa1B;AAsCD;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,UA1BP,UAAU,CAAE,aAAa,CAAE,UAAU,gBAAgB,QAuCnE,CAAC;;;;;;;;;;;;AAEJ,wBAGI"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { StoreState } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Returns a boolean indicating whether a prefer is active for a particular
|
|
7
|
+
* scope.
|
|
8
|
+
*
|
|
9
|
+
* @param {StoreState} state The store state.
|
|
10
|
+
* @param {string} scope The scope of the feature (e.g. core/edit-post).
|
|
11
|
+
* @param {string} name The name of the feature.
|
|
12
|
+
*
|
|
13
|
+
* @return {*} Is the feature enabled?
|
|
14
|
+
*/
|
|
15
|
+
export declare const get: (state: StoreState, scope: string, name: string) => any;
|
|
16
|
+
//# sourceMappingURL=selectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/store/selectors.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AA4C1C;;;;;;;;;GASG;AACH,eAAO,MAAM,GAAG,UAhDN,UAAU,SAAS,MAAM,QAAQ,MAAM,QAqDhD,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type StoreState = {
|
|
2
|
+
preferences: {
|
|
3
|
+
[k in string]: {
|
|
4
|
+
[p in string]: any;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
defaults: {
|
|
8
|
+
[k in string]: {
|
|
9
|
+
[p in string]: any;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type OmitFirstArg<F> = F extends (x: any, ...args: infer P) => infer R ? (...args: P) => R : never;
|
|
14
|
+
export interface WPPreferencesPersistenceLayer<D extends Object> {
|
|
15
|
+
/**
|
|
16
|
+
* An async function that gets data from the persistence layer.
|
|
17
|
+
*/
|
|
18
|
+
get: () => Promise<D>;
|
|
19
|
+
/**
|
|
20
|
+
* A function that sets data in the persistence layer.
|
|
21
|
+
*/
|
|
22
|
+
set: (value: D) => void;
|
|
23
|
+
}
|
|
24
|
+
export type ActionObject<T extends string, D extends Record<Exclude<string, 'type'>, any> = {}> = {
|
|
25
|
+
type: T;
|
|
26
|
+
} & D;
|
|
27
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/store/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG;IACxB,WAAW,EAAE;SAAI,CAAC,IAAI,MAAM,GAAI;aAAI,CAAC,IAAI,MAAM,GAAI,GAAG;SAAE;KAAE,CAAC;IAC3D,QAAQ,EAAE;SAAI,CAAC,IAAI,MAAM,GAAI;aAAI,CAAC,IAAI,MAAM,GAAI,GAAG;SAAE;KAAE,CAAC;CACxD,CAAC;AAEF,MAAM,MAAM,YAAY,CAAE,CAAC,IAAK,CAAC,SAAS,CACzC,CAAC,EAAE,GAAG,EACN,GAAG,IAAI,EAAE,MAAM,CAAC,KACZ,MAAM,CAAC,GACT,CAAE,GAAG,IAAI,EAAE,CAAC,KAAM,CAAC,GACnB,KAAK,CAAC;AAET,MAAM,WAAW,6BAA6B,CAAE,CAAC,SAAS,MAAM;IAC/D;;OAEG;IACH,GAAG,EAAE,MAAM,OAAO,CAAE,CAAC,CAAE,CAAC;IACxB;;OAEG;IACH,GAAG,EAAE,CAAE,KAAK,EAAE,CAAC,KAAM,IAAI,CAAC;CAC1B;AAED,MAAM,MAAM,YAAY,CACvB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,CAAE,OAAO,CAAE,MAAM,EAAE,MAAM,CAAE,EAAE,GAAG,CAAE,GAAG,EAAE,IACpD;IACH,IAAI,EAAE,CAAC,CAAC;CACR,GAAG,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/preferences",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.34.0",
|
|
4
4
|
"description": "Utilities for managing WordPress preferences.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -36,18 +36,22 @@
|
|
|
36
36
|
},
|
|
37
37
|
"react-native": "src/index",
|
|
38
38
|
"wpScript": true,
|
|
39
|
+
"types": "build-types",
|
|
40
|
+
"wpScriptExtraDependencies": [
|
|
41
|
+
"wp-preferences-persistence"
|
|
42
|
+
],
|
|
39
43
|
"sideEffects": false,
|
|
40
44
|
"dependencies": {
|
|
41
|
-
"@wordpress/a11y": "^4.
|
|
42
|
-
"@wordpress/base-styles": "^6.
|
|
43
|
-
"@wordpress/components": "^30.
|
|
44
|
-
"@wordpress/compose": "^7.
|
|
45
|
-
"@wordpress/data": "^10.
|
|
46
|
-
"@wordpress/deprecated": "^4.
|
|
47
|
-
"@wordpress/element": "^6.
|
|
48
|
-
"@wordpress/i18n": "^6.
|
|
49
|
-
"@wordpress/icons": "^11.0
|
|
50
|
-
"@wordpress/private-apis": "^1.
|
|
45
|
+
"@wordpress/a11y": "^4.34.0",
|
|
46
|
+
"@wordpress/base-styles": "^6.10.0",
|
|
47
|
+
"@wordpress/components": "^30.7.0",
|
|
48
|
+
"@wordpress/compose": "^7.34.0",
|
|
49
|
+
"@wordpress/data": "^10.34.0",
|
|
50
|
+
"@wordpress/deprecated": "^4.34.0",
|
|
51
|
+
"@wordpress/element": "^6.34.0",
|
|
52
|
+
"@wordpress/i18n": "^6.7.0",
|
|
53
|
+
"@wordpress/icons": "^11.1.0",
|
|
54
|
+
"@wordpress/private-apis": "^1.34.0",
|
|
51
55
|
"clsx": "^2.1.1"
|
|
52
56
|
},
|
|
53
57
|
"peerDependencies": {
|
|
@@ -57,5 +61,5 @@
|
|
|
57
61
|
"publishConfig": {
|
|
58
62
|
"access": "public"
|
|
59
63
|
},
|
|
60
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "ceebff807958d2e8fc755b5a20473939c78b4d1d"
|
|
61
65
|
}
|
|
@@ -2,8 +2,18 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { ToggleControl } from '@wordpress/components';
|
|
5
|
+
/**
|
|
6
|
+
* Internal dependencies
|
|
7
|
+
*/
|
|
8
|
+
import type { BaseOptionProps } from './types';
|
|
5
9
|
|
|
6
|
-
function BaseOption( {
|
|
10
|
+
function BaseOption( {
|
|
11
|
+
help,
|
|
12
|
+
label,
|
|
13
|
+
isChecked,
|
|
14
|
+
onChange,
|
|
15
|
+
children,
|
|
16
|
+
}: BaseOptionProps ) {
|
|
7
17
|
return (
|
|
8
18
|
<div className="preference-base-option">
|
|
9
19
|
<ToggleControl
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ToggleControl } from '@wordpress/components';
|
|
5
|
+
|
|
6
|
+
type ToggleControlProps = Parameters< typeof ToggleControl >[ 0 ];
|
|
7
|
+
export type BaseOptionProps = Pick<
|
|
8
|
+
ToggleControlProps,
|
|
9
|
+
'help' | 'label' | 'onChange'
|
|
10
|
+
> & { isChecked?: ToggleControlProps[ 'checked' ]; children?: React.ReactNode };
|
|
@@ -7,9 +7,16 @@ import { useSelect, useDispatch } from '@wordpress/data';
|
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { store as preferencesStore } from '../../store';
|
|
10
|
+
import type { BaseOptionProps } from '../preference-base-option/types';
|
|
10
11
|
import PreferenceBaseOption from '../preference-base-option';
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
export type PreferenceToggleControlProps = {
|
|
14
|
+
scope: string;
|
|
15
|
+
featureName: string;
|
|
16
|
+
onToggle: () => void;
|
|
17
|
+
} & Omit< BaseOptionProps, 'onChange' | 'isChecked' >;
|
|
18
|
+
|
|
19
|
+
function PreferenceToggleControl( props: PreferenceToggleControlProps ) {
|
|
13
20
|
const {
|
|
14
21
|
scope,
|
|
15
22
|
featureName,
|
|
@@ -28,9 +35,9 @@ function PreferenceToggleControl( props ) {
|
|
|
28
35
|
|
|
29
36
|
return (
|
|
30
37
|
<PreferenceBaseOption
|
|
38
|
+
{ ...remainingProps }
|
|
31
39
|
onChange={ onChange }
|
|
32
40
|
isChecked={ isChecked }
|
|
33
|
-
{ ...remainingProps }
|
|
34
41
|
/>
|
|
35
42
|
);
|
|
36
43
|
}
|
|
@@ -12,6 +12,18 @@ import { speak } from '@wordpress/a11y';
|
|
|
12
12
|
*/
|
|
13
13
|
import { store as preferencesStore } from '../../store';
|
|
14
14
|
|
|
15
|
+
type PreferenceToggleMenuItemProps = {
|
|
16
|
+
scope: string;
|
|
17
|
+
name: string;
|
|
18
|
+
label: string;
|
|
19
|
+
info?: string;
|
|
20
|
+
messageActivated?: string;
|
|
21
|
+
messageDeactivated?: string;
|
|
22
|
+
shortcut?: string | { display: string; ariaLabel: string };
|
|
23
|
+
handleToggling?: boolean;
|
|
24
|
+
onToggle?: () => void;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
};
|
|
15
27
|
export default function PreferenceToggleMenuItem( {
|
|
16
28
|
scope,
|
|
17
29
|
name,
|
|
@@ -23,7 +35,7 @@ export default function PreferenceToggleMenuItem( {
|
|
|
23
35
|
handleToggling = true,
|
|
24
36
|
onToggle = () => null,
|
|
25
37
|
disabled = false,
|
|
26
|
-
} ) {
|
|
38
|
+
}: PreferenceToggleMenuItemProps ) {
|
|
27
39
|
const isActive = useSelect(
|
|
28
40
|
( select ) => !! select( preferencesStore ).get( scope, name ),
|
|
29
41
|
[ scope, name ]
|
|
@@ -53,7 +65,7 @@ export default function PreferenceToggleMenuItem( {
|
|
|
53
65
|
|
|
54
66
|
return (
|
|
55
67
|
<MenuItem
|
|
56
|
-
icon={ isActive
|
|
68
|
+
icon={ isActive ? check : null }
|
|
57
69
|
isSelected={ isActive }
|
|
58
70
|
onClick={ () => {
|
|
59
71
|
onToggle();
|
|
@@ -3,8 +3,15 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Modal } from '@wordpress/components';
|
|
5
5
|
import { __ } from '@wordpress/i18n';
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { PreferencesModalProps } from './types';
|
|
6
10
|
|
|
7
|
-
export default function PreferencesModal( {
|
|
11
|
+
export default function PreferencesModal( {
|
|
12
|
+
closeModal,
|
|
13
|
+
children,
|
|
14
|
+
}: PreferencesModalProps ) {
|
|
8
15
|
return (
|
|
9
16
|
<Modal
|
|
10
17
|
className="preferences-modal"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { Modal } from '@wordpress/components';
|
|
5
|
+
|
|
6
|
+
type ModalProps = Parameters< typeof Modal >[ 0 ];
|
|
7
|
+
|
|
8
|
+
export type PreferencesModalProps = {
|
|
9
|
+
closeModal: ModalProps[ 'onRequestClose' ];
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
export type SectionProps = {
|
|
2
|
+
description?: React.ReactNode;
|
|
3
|
+
title?: React.ReactNode;
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const Section = ( { description, title, children }: SectionProps ) => (
|
|
2
8
|
<fieldset className="preferences-modal__section">
|
|
3
9
|
<legend className="preferences-modal__section-legend">
|
|
4
10
|
<h2 className="preferences-modal__section-title">{ title }</h2>
|
|
@@ -28,7 +28,12 @@ const { Tabs } = unlock( componentsPrivateApis );
|
|
|
28
28
|
|
|
29
29
|
const PREFERENCES_MENU = 'preferences-menu';
|
|
30
30
|
|
|
31
|
-
export
|
|
31
|
+
export type PreferencesModalTabsProps = {
|
|
32
|
+
sections: { name: string; tabLabel: string; content: React.ReactNode }[];
|
|
33
|
+
};
|
|
34
|
+
export default function PreferencesModalTabs( {
|
|
35
|
+
sections,
|
|
36
|
+
}: PreferencesModalTabsProps ) {
|
|
32
37
|
const isLargeViewport = useViewportMatch( 'medium' );
|
|
33
38
|
|
|
34
39
|
// This is also used to sync the two different rendered components
|
|
@@ -40,12 +45,15 @@ export default function PreferencesModalTabs( { sections } ) {
|
|
|
40
45
|
* is used for easier access to active tab's content.
|
|
41
46
|
*/
|
|
42
47
|
const { tabs, sectionsContentMap } = useMemo( () => {
|
|
43
|
-
let mappedTabs
|
|
48
|
+
let mappedTabs: {
|
|
49
|
+
tabs: { name: string; title: string }[];
|
|
50
|
+
sectionsContentMap: Record< string, React.ReactNode >;
|
|
51
|
+
} = {
|
|
44
52
|
tabs: [],
|
|
45
53
|
sectionsContentMap: {},
|
|
46
54
|
};
|
|
47
55
|
if ( sections.length ) {
|
|
48
|
-
mappedTabs = sections.reduce(
|
|
56
|
+
mappedTabs = sections.reduce< typeof mappedTabs >(
|
|
49
57
|
( accumulator, { name, tabLabel: title, content } ) => {
|
|
50
58
|
accumulator.tabs.push( { name, title } );
|
|
51
59
|
accumulator.sectionsContentMap[ name ] = content;
|
|
@@ -102,6 +110,7 @@ export default function PreferencesModalTabs( { sections } ) {
|
|
|
102
110
|
<ItemGroup>
|
|
103
111
|
{ tabs.map( ( tab ) => {
|
|
104
112
|
return (
|
|
113
|
+
// @ts-expect-error: Navigator.Button is currently typed in a way that prevents Item from being passed in
|
|
105
114
|
<Navigator.Button
|
|
106
115
|
key={ tab.name }
|
|
107
116
|
path={ `/${ tab.name }` }
|
|
@@ -144,6 +153,7 @@ export default function PreferencesModalTabs( { sections } ) {
|
|
|
144
153
|
justify="left"
|
|
145
154
|
size="small"
|
|
146
155
|
gap="6"
|
|
156
|
+
as="div"
|
|
147
157
|
>
|
|
148
158
|
<Navigator.BackButton
|
|
149
159
|
icon={
|