@wordpress/edit-post 7.28.2 → 7.29.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 +2 -0
- package/build/components/editor-initialization/listener-hooks.js +14 -6
- package/build/components/editor-initialization/listener-hooks.js.map +1 -1
- package/build/components/header/index.js +1 -1
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/more-menu/index.js +6 -2
- package/build/components/header/more-menu/index.js.map +1 -1
- package/build/components/header/writing-menu/index.js +2 -6
- package/build/components/header/writing-menu/index.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js +1 -38
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/layout/index.js +3 -4
- package/build/components/layout/index.js.map +1 -1
- package/build/components/layout/index.native.js +2 -5
- package/build/components/layout/index.native.js.map +1 -1
- package/build/components/text-editor/index.js +1 -1
- package/build/components/text-editor/index.js.map +1 -1
- package/build/editor.js +2 -16
- package/build/editor.js.map +1 -1
- package/build/editor.native.js +2 -3
- package/build/editor.native.js.map +1 -1
- package/build/hooks/commands/use-common-commands.js +2 -135
- package/build/hooks/commands/use-common-commands.js.map +1 -1
- package/build/index.js +3 -31
- package/build/index.js.map +1 -1
- package/build/index.native.js +0 -1
- package/build/index.native.js.map +1 -1
- package/build/store/actions.js +24 -77
- package/build/store/actions.js.map +1 -1
- package/build/store/selectors.js +0 -12
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/editor-initialization/listener-hooks.js +14 -6
- package/build-module/components/editor-initialization/listener-hooks.js.map +1 -1
- package/build-module/components/header/index.js +1 -1
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/more-menu/index.js +5 -1
- package/build-module/components/header/more-menu/index.js.map +1 -1
- package/build-module/components/header/writing-menu/index.js +2 -6
- package/build-module/components/header/writing-menu/index.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js +1 -38
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/layout/index.js +4 -5
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/layout/index.native.js +2 -5
- package/build-module/components/layout/index.native.js.map +1 -1
- package/build-module/components/text-editor/index.js +1 -1
- package/build-module/components/text-editor/index.js.map +1 -1
- package/build-module/editor.js +3 -17
- package/build-module/editor.js.map +1 -1
- package/build-module/editor.native.js +3 -4
- package/build-module/editor.native.js.map +1 -1
- package/build-module/hooks/commands/use-common-commands.js +3 -136
- package/build-module/hooks/commands/use-common-commands.js.map +1 -1
- package/build-module/index.js +3 -31
- package/build-module/index.js.map +1 -1
- package/build-module/index.native.js +0 -1
- package/build-module/index.native.js.map +1 -1
- package/build-module/store/actions.js +23 -75
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/selectors.js +0 -12
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +6 -6
- package/build-style/style.css +6 -6
- package/package.json +32 -32
- package/src/components/editor-initialization/listener-hooks.js +16 -9
- package/src/components/editor-initialization/test/listener-hooks.js +40 -0
- package/src/components/header/index.js +1 -1
- package/src/components/header/more-menu/index.js +4 -1
- package/src/components/header/writing-menu/index.js +2 -6
- package/src/components/keyboard-shortcuts/index.js +3 -50
- package/src/components/layout/index.js +4 -5
- package/src/components/layout/index.native.js +1 -3
- package/src/components/text-editor/index.js +1 -1
- package/src/editor.js +31 -53
- package/src/editor.native.js +3 -4
- package/src/hooks/commands/use-common-commands.js +17 -170
- package/src/index.js +3 -44
- package/src/index.native.js +0 -1
- package/src/store/actions.js +24 -126
- package/src/store/selectors.js +0 -18
- package/src/store/test/actions.js +0 -146
- package/src/style.scss +1 -2
- package/build/components/header/mode-switcher/index.js +0 -87
- package/build/components/header/mode-switcher/index.js.map +0 -1
- package/build-module/components/header/mode-switcher/index.js +0 -81
- package/build-module/components/header/mode-switcher/index.js.map +0 -1
- package/src/components/header/mode-switcher/index.js +0 -91
|
@@ -53,18 +53,6 @@ describe( 'actions', () => {
|
|
|
53
53
|
).toBeNull();
|
|
54
54
|
} );
|
|
55
55
|
|
|
56
|
-
it( 'openGeneralSidebar - should turn off distraction free mode when opening a general sidebar', () => {
|
|
57
|
-
registry
|
|
58
|
-
.dispatch( preferencesStore )
|
|
59
|
-
.set( 'core', 'distractionFree', true );
|
|
60
|
-
registry
|
|
61
|
-
.dispatch( editPostStore )
|
|
62
|
-
.openGeneralSidebar( 'edit-post/block' );
|
|
63
|
-
expect(
|
|
64
|
-
registry.select( preferencesStore ).get( 'core', 'distractionFree' )
|
|
65
|
-
).toBe( false );
|
|
66
|
-
} );
|
|
67
|
-
|
|
68
56
|
it( 'toggleFeature', () => {
|
|
69
57
|
registry.dispatch( editPostStore ).toggleFeature( 'welcomeGuide' );
|
|
70
58
|
expect(
|
|
@@ -81,52 +69,6 @@ describe( 'actions', () => {
|
|
|
81
69
|
).toBe( false );
|
|
82
70
|
} );
|
|
83
71
|
|
|
84
|
-
describe( 'switchEditorMode', () => {
|
|
85
|
-
it( 'to visual', () => {
|
|
86
|
-
// Switch to text first, since the default is visual.
|
|
87
|
-
registry.dispatch( editPostStore ).switchEditorMode( 'text' );
|
|
88
|
-
expect( registry.select( editPostStore ).getEditorMode() ).toEqual(
|
|
89
|
-
'text'
|
|
90
|
-
);
|
|
91
|
-
registry.dispatch( editPostStore ).switchEditorMode( 'visual' );
|
|
92
|
-
expect( registry.select( editPostStore ).getEditorMode() ).toEqual(
|
|
93
|
-
'visual'
|
|
94
|
-
);
|
|
95
|
-
} );
|
|
96
|
-
|
|
97
|
-
it( 'to text', () => {
|
|
98
|
-
// It defaults to visual.
|
|
99
|
-
expect( registry.select( editPostStore ).getEditorMode() ).toEqual(
|
|
100
|
-
'visual'
|
|
101
|
-
);
|
|
102
|
-
// Add a selected client id and make sure it's there.
|
|
103
|
-
const clientId = 'clientId_1';
|
|
104
|
-
registry.dispatch( blockEditorStore ).selectionChange( clientId );
|
|
105
|
-
expect(
|
|
106
|
-
registry.select( blockEditorStore ).getSelectedBlockClientId()
|
|
107
|
-
).toEqual( clientId );
|
|
108
|
-
|
|
109
|
-
registry.dispatch( editPostStore ).switchEditorMode( 'text' );
|
|
110
|
-
expect(
|
|
111
|
-
registry.select( blockEditorStore ).getSelectedBlockClientId()
|
|
112
|
-
).toBeNull();
|
|
113
|
-
expect( registry.select( editPostStore ).getEditorMode() ).toEqual(
|
|
114
|
-
'text'
|
|
115
|
-
);
|
|
116
|
-
} );
|
|
117
|
-
it( 'should turn off distraction free mode when switching to code editor', () => {
|
|
118
|
-
registry
|
|
119
|
-
.dispatch( preferencesStore )
|
|
120
|
-
.set( 'core', 'distractionFree', true );
|
|
121
|
-
registry.dispatch( editPostStore ).switchEditorMode( 'text' );
|
|
122
|
-
expect(
|
|
123
|
-
registry
|
|
124
|
-
.select( preferencesStore )
|
|
125
|
-
.get( 'core', 'distractionFree' )
|
|
126
|
-
).toBe( false );
|
|
127
|
-
} );
|
|
128
|
-
} );
|
|
129
|
-
|
|
130
72
|
it( 'togglePinnedPluginItem', () => {
|
|
131
73
|
registry.dispatch( editPostStore ).togglePinnedPluginItem( 'rigatoni' );
|
|
132
74
|
// Sidebars are pinned by default.
|
|
@@ -199,92 +141,4 @@ describe( 'actions', () => {
|
|
|
199
141
|
).toEqual( expectedB );
|
|
200
142
|
} );
|
|
201
143
|
} );
|
|
202
|
-
|
|
203
|
-
describe( 'updatePreferredStyleVariations', () => {
|
|
204
|
-
it( 'sets a preferred style variation for a block when a style name is passed', () => {
|
|
205
|
-
registry
|
|
206
|
-
.dispatch( 'core/edit-post' )
|
|
207
|
-
.updatePreferredStyleVariations( 'core/paragraph', 'fancy' );
|
|
208
|
-
registry
|
|
209
|
-
.dispatch( 'core/edit-post' )
|
|
210
|
-
.updatePreferredStyleVariations( 'core/quote', 'posh' );
|
|
211
|
-
|
|
212
|
-
expect(
|
|
213
|
-
registry
|
|
214
|
-
.select( editPostStore )
|
|
215
|
-
.getPreference( 'preferredStyleVariations' )
|
|
216
|
-
).toEqual( {
|
|
217
|
-
'core/paragraph': 'fancy',
|
|
218
|
-
'core/quote': 'posh',
|
|
219
|
-
} );
|
|
220
|
-
|
|
221
|
-
// Expect a deprecation message for `getPreference`.
|
|
222
|
-
expect( console ).toHaveWarned();
|
|
223
|
-
} );
|
|
224
|
-
|
|
225
|
-
it( 'removes a preferred style variation for a block when a style name is omitted', () => {
|
|
226
|
-
registry
|
|
227
|
-
.dispatch( 'core/edit-post' )
|
|
228
|
-
.updatePreferredStyleVariations( 'core/paragraph', 'fancy' );
|
|
229
|
-
registry
|
|
230
|
-
.dispatch( 'core/edit-post' )
|
|
231
|
-
.updatePreferredStyleVariations( 'core/quote', 'posh' );
|
|
232
|
-
expect(
|
|
233
|
-
registry
|
|
234
|
-
.select( editPostStore )
|
|
235
|
-
.getPreference( 'preferredStyleVariations' )
|
|
236
|
-
).toEqual( {
|
|
237
|
-
'core/paragraph': 'fancy',
|
|
238
|
-
'core/quote': 'posh',
|
|
239
|
-
} );
|
|
240
|
-
|
|
241
|
-
registry
|
|
242
|
-
.dispatch( 'core/edit-post' )
|
|
243
|
-
.updatePreferredStyleVariations( 'core/paragraph' );
|
|
244
|
-
|
|
245
|
-
expect(
|
|
246
|
-
registry
|
|
247
|
-
.select( editPostStore )
|
|
248
|
-
.getPreference( 'preferredStyleVariations' )
|
|
249
|
-
).toEqual( {
|
|
250
|
-
'core/quote': 'posh',
|
|
251
|
-
} );
|
|
252
|
-
} );
|
|
253
|
-
} );
|
|
254
|
-
|
|
255
|
-
describe( 'toggleDistractionFree', () => {
|
|
256
|
-
it( 'should properly update settings to prevent layout corruption when enabling distraction free mode', () => {
|
|
257
|
-
// Enable everything that shouldn't be enabled in distraction free mode.
|
|
258
|
-
registry
|
|
259
|
-
.dispatch( preferencesStore )
|
|
260
|
-
.set( 'core', 'fixedToolbar', true );
|
|
261
|
-
registry.dispatch( editorStore ).setIsListViewOpened( true );
|
|
262
|
-
registry
|
|
263
|
-
.dispatch( editPostStore )
|
|
264
|
-
.openGeneralSidebar( 'edit-post/block' );
|
|
265
|
-
// Initial state is falsy.
|
|
266
|
-
registry.dispatch( editPostStore ).toggleDistractionFree();
|
|
267
|
-
expect(
|
|
268
|
-
registry
|
|
269
|
-
.select( preferencesStore )
|
|
270
|
-
.get( 'core', 'fixedToolbar' )
|
|
271
|
-
).toBe( true );
|
|
272
|
-
expect( registry.select( editorStore ).isListViewOpened() ).toBe(
|
|
273
|
-
false
|
|
274
|
-
);
|
|
275
|
-
expect( registry.select( editorStore ).isInserterOpened() ).toBe(
|
|
276
|
-
false
|
|
277
|
-
);
|
|
278
|
-
expect(
|
|
279
|
-
registry
|
|
280
|
-
.select( interfaceStore )
|
|
281
|
-
.getActiveComplementaryArea( editPostStore.name )
|
|
282
|
-
).toBeNull();
|
|
283
|
-
expect(
|
|
284
|
-
registry
|
|
285
|
-
.select( preferencesStore )
|
|
286
|
-
.get( 'core', 'distractionFree' )
|
|
287
|
-
).toBe( true );
|
|
288
|
-
} );
|
|
289
|
-
} );
|
|
290
144
|
} );
|
package/src/style.scss
CHANGED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _i18n = require("@wordpress/i18n");
|
|
9
|
-
var _components = require("@wordpress/components");
|
|
10
|
-
var _data = require("@wordpress/data");
|
|
11
|
-
var _keyboardShortcuts = require("@wordpress/keyboard-shortcuts");
|
|
12
|
-
var _editor = require("@wordpress/editor");
|
|
13
|
-
var _store = require("../../../store");
|
|
14
|
-
/**
|
|
15
|
-
* WordPress dependencies
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Internal dependencies
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Set of available mode options.
|
|
24
|
-
*
|
|
25
|
-
* @type {Array}
|
|
26
|
-
*/
|
|
27
|
-
const MODES = [{
|
|
28
|
-
value: 'visual',
|
|
29
|
-
label: (0, _i18n.__)('Visual editor')
|
|
30
|
-
}, {
|
|
31
|
-
value: 'text',
|
|
32
|
-
label: (0, _i18n.__)('Code editor')
|
|
33
|
-
}];
|
|
34
|
-
function ModeSwitcher() {
|
|
35
|
-
const {
|
|
36
|
-
shortcut,
|
|
37
|
-
isRichEditingEnabled,
|
|
38
|
-
isCodeEditingEnabled,
|
|
39
|
-
mode
|
|
40
|
-
} = (0, _data.useSelect)(select => ({
|
|
41
|
-
shortcut: select(_keyboardShortcuts.store).getShortcutRepresentation('core/edit-post/toggle-mode'),
|
|
42
|
-
isRichEditingEnabled: select(_editor.store).getEditorSettings().richEditingEnabled,
|
|
43
|
-
isCodeEditingEnabled: select(_editor.store).getEditorSettings().codeEditingEnabled,
|
|
44
|
-
mode: select(_store.store).getEditorMode()
|
|
45
|
-
}), []);
|
|
46
|
-
const {
|
|
47
|
-
switchEditorMode
|
|
48
|
-
} = (0, _data.useDispatch)(_store.store);
|
|
49
|
-
let selectedMode = mode;
|
|
50
|
-
if (!isRichEditingEnabled && mode === 'visual') {
|
|
51
|
-
selectedMode = 'text';
|
|
52
|
-
}
|
|
53
|
-
if (!isCodeEditingEnabled && mode === 'text') {
|
|
54
|
-
selectedMode = 'visual';
|
|
55
|
-
}
|
|
56
|
-
const choices = MODES.map(choice => {
|
|
57
|
-
if (!isCodeEditingEnabled && choice.value === 'text') {
|
|
58
|
-
choice = {
|
|
59
|
-
...choice,
|
|
60
|
-
disabled: true
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
if (!isRichEditingEnabled && choice.value === 'visual') {
|
|
64
|
-
choice = {
|
|
65
|
-
...choice,
|
|
66
|
-
disabled: true,
|
|
67
|
-
info: (0, _i18n.__)('You can enable the visual editor in your profile settings.')
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
if (choice.value !== selectedMode && !choice.disabled) {
|
|
71
|
-
return {
|
|
72
|
-
...choice,
|
|
73
|
-
shortcut
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
return choice;
|
|
77
|
-
});
|
|
78
|
-
return (0, _react.createElement)(_components.MenuGroup, {
|
|
79
|
-
label: (0, _i18n.__)('Editor')
|
|
80
|
-
}, (0, _react.createElement)(_components.MenuItemsChoice, {
|
|
81
|
-
choices: choices,
|
|
82
|
-
value: selectedMode,
|
|
83
|
-
onSelect: switchEditorMode
|
|
84
|
-
}));
|
|
85
|
-
}
|
|
86
|
-
var _default = exports.default = ModeSwitcher;
|
|
87
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_components","_data","_keyboardShortcuts","_editor","_store","MODES","value","label","__","ModeSwitcher","shortcut","isRichEditingEnabled","isCodeEditingEnabled","mode","useSelect","select","keyboardShortcutsStore","getShortcutRepresentation","editorStore","getEditorSettings","richEditingEnabled","codeEditingEnabled","editPostStore","getEditorMode","switchEditorMode","useDispatch","selectedMode","choices","map","choice","disabled","info","_react","createElement","MenuGroup","MenuItemsChoice","onSelect","_default","exports","default"],"sources":["@wordpress/edit-post/src/components/header/mode-switcher/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { MenuItemsChoice, MenuGroup } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../../store';\n\n/**\n * Set of available mode options.\n *\n * @type {Array}\n */\nconst MODES = [\n\t{\n\t\tvalue: 'visual',\n\t\tlabel: __( 'Visual editor' ),\n\t},\n\t{\n\t\tvalue: 'text',\n\t\tlabel: __( 'Code editor' ),\n\t},\n];\n\nfunction ModeSwitcher() {\n\tconst { shortcut, isRichEditingEnabled, isCodeEditingEnabled, mode } =\n\t\tuseSelect(\n\t\t\t( select ) => ( {\n\t\t\t\tshortcut: select(\n\t\t\t\t\tkeyboardShortcutsStore\n\t\t\t\t).getShortcutRepresentation( 'core/edit-post/toggle-mode' ),\n\t\t\t\tisRichEditingEnabled:\n\t\t\t\t\tselect( editorStore ).getEditorSettings()\n\t\t\t\t\t\t.richEditingEnabled,\n\t\t\t\tisCodeEditingEnabled:\n\t\t\t\t\tselect( editorStore ).getEditorSettings()\n\t\t\t\t\t\t.codeEditingEnabled,\n\t\t\t\tmode: select( editPostStore ).getEditorMode(),\n\t\t\t} ),\n\t\t\t[]\n\t\t);\n\tconst { switchEditorMode } = useDispatch( editPostStore );\n\n\tlet selectedMode = mode;\n\tif ( ! isRichEditingEnabled && mode === 'visual' ) {\n\t\tselectedMode = 'text';\n\t}\n\tif ( ! isCodeEditingEnabled && mode === 'text' ) {\n\t\tselectedMode = 'visual';\n\t}\n\n\tconst choices = MODES.map( ( choice ) => {\n\t\tif ( ! isCodeEditingEnabled && choice.value === 'text' ) {\n\t\t\tchoice = {\n\t\t\t\t...choice,\n\t\t\t\tdisabled: true,\n\t\t\t};\n\t\t}\n\t\tif ( ! isRichEditingEnabled && choice.value === 'visual' ) {\n\t\t\tchoice = {\n\t\t\t\t...choice,\n\t\t\t\tdisabled: true,\n\t\t\t\tinfo: __(\n\t\t\t\t\t'You can enable the visual editor in your profile settings.'\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\t\tif ( choice.value !== selectedMode && ! choice.disabled ) {\n\t\t\treturn { ...choice, shortcut };\n\t\t}\n\t\treturn choice;\n\t} );\n\n\treturn (\n\t\t<MenuGroup label={ __( 'Editor' ) }>\n\t\t\t<MenuItemsChoice\n\t\t\t\tchoices={ choices }\n\t\t\t\tvalue={ selectedMode }\n\t\t\t\tonSelect={ switchEditorMode }\n\t\t\t/>\n\t\t</MenuGroup>\n\t);\n}\n\nexport default ModeSwitcher;\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GA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GAAG,CAAIC,MAAM,IAAM;IACxC,IAAK,CAAEjB,oBAAoB,IAAIiB,MAAM,CAACvB,KAAK,KAAK,MAAM,EAAG;MACxDuB,MAAM,GAAG;QACR,GAAGA,MAAM;QACTC,QAAQ,EAAE;MACX,CAAC;IACF;IACA,IAAK,CAAEnB,oBAAoB,IAAIkB,MAAM,CAACvB,KAAK,KAAK,QAAQ,EAAG;MAC1DuB,MAAM,GAAG;QACR,GAAGA,MAAM;QACTC,QAAQ,EAAE,IAAI;QACdC,IAAI,EAAE,IAAAvB,QAAE,EACP,4DACD;MACD,CAAC;IACF;IACA,IAAKqB,MAAM,CAACvB,KAAK,KAAKoB,YAAY,IAAI,CAAEG,MAAM,CAACC,QAAQ,EAAG;MACzD,OAAO;QAAE,GAAGD,MAAM;QAAEnB;MAAS,CAAC;IAC/B;IACA,OAAOmB,MAAM;EACd,CAAE,CAAC;EAEH,OACC,IAAAG,MAAA,CAAAC,aAAA,EAACjC,WAAA,CAAAkC,SAAS;IAAC3B,KAAK,EAAG,IAAAC,QAAE,EAAE,QAAS;EAAG,GAClC,IAAAwB,MAAA,CAAAC,aAAA,EAACjC,WAAA,CAAAmC,eAAe;IACfR,OAAO,EAAGA,OAAS;IACnBrB,KAAK,EAAGoB,YAAc;IACtBU,QAAQ,EAAGZ;EAAkB,CAC7B,CACS,CAAC;AAEd;AAAC,IAAAa,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc9B,YAAY"}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { createElement } from "react";
|
|
2
|
-
/**
|
|
3
|
-
* WordPress dependencies
|
|
4
|
-
*/
|
|
5
|
-
import { __ } from '@wordpress/i18n';
|
|
6
|
-
import { MenuItemsChoice, MenuGroup } from '@wordpress/components';
|
|
7
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
8
|
-
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
9
|
-
import { store as editorStore } from '@wordpress/editor';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
import { store as editPostStore } from '../../../store';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Set of available mode options.
|
|
18
|
-
*
|
|
19
|
-
* @type {Array}
|
|
20
|
-
*/
|
|
21
|
-
const MODES = [{
|
|
22
|
-
value: 'visual',
|
|
23
|
-
label: __('Visual editor')
|
|
24
|
-
}, {
|
|
25
|
-
value: 'text',
|
|
26
|
-
label: __('Code editor')
|
|
27
|
-
}];
|
|
28
|
-
function ModeSwitcher() {
|
|
29
|
-
const {
|
|
30
|
-
shortcut,
|
|
31
|
-
isRichEditingEnabled,
|
|
32
|
-
isCodeEditingEnabled,
|
|
33
|
-
mode
|
|
34
|
-
} = useSelect(select => ({
|
|
35
|
-
shortcut: select(keyboardShortcutsStore).getShortcutRepresentation('core/edit-post/toggle-mode'),
|
|
36
|
-
isRichEditingEnabled: select(editorStore).getEditorSettings().richEditingEnabled,
|
|
37
|
-
isCodeEditingEnabled: select(editorStore).getEditorSettings().codeEditingEnabled,
|
|
38
|
-
mode: select(editPostStore).getEditorMode()
|
|
39
|
-
}), []);
|
|
40
|
-
const {
|
|
41
|
-
switchEditorMode
|
|
42
|
-
} = useDispatch(editPostStore);
|
|
43
|
-
let selectedMode = mode;
|
|
44
|
-
if (!isRichEditingEnabled && mode === 'visual') {
|
|
45
|
-
selectedMode = 'text';
|
|
46
|
-
}
|
|
47
|
-
if (!isCodeEditingEnabled && mode === 'text') {
|
|
48
|
-
selectedMode = 'visual';
|
|
49
|
-
}
|
|
50
|
-
const choices = MODES.map(choice => {
|
|
51
|
-
if (!isCodeEditingEnabled && choice.value === 'text') {
|
|
52
|
-
choice = {
|
|
53
|
-
...choice,
|
|
54
|
-
disabled: true
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
if (!isRichEditingEnabled && choice.value === 'visual') {
|
|
58
|
-
choice = {
|
|
59
|
-
...choice,
|
|
60
|
-
disabled: true,
|
|
61
|
-
info: __('You can enable the visual editor in your profile settings.')
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
if (choice.value !== selectedMode && !choice.disabled) {
|
|
65
|
-
return {
|
|
66
|
-
...choice,
|
|
67
|
-
shortcut
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
return choice;
|
|
71
|
-
});
|
|
72
|
-
return createElement(MenuGroup, {
|
|
73
|
-
label: __('Editor')
|
|
74
|
-
}, createElement(MenuItemsChoice, {
|
|
75
|
-
choices: choices,
|
|
76
|
-
value: selectedMode,
|
|
77
|
-
onSelect: switchEditorMode
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
export default ModeSwitcher;
|
|
81
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["__","MenuItemsChoice","MenuGroup","useSelect","useDispatch","store","keyboardShortcutsStore","editorStore","editPostStore","MODES","value","label","ModeSwitcher","shortcut","isRichEditingEnabled","isCodeEditingEnabled","mode","select","getShortcutRepresentation","getEditorSettings","richEditingEnabled","codeEditingEnabled","getEditorMode","switchEditorMode","selectedMode","choices","map","choice","disabled","info","createElement","onSelect"],"sources":["@wordpress/edit-post/src/components/header/mode-switcher/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { MenuItemsChoice, MenuGroup } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\nimport { store as editorStore } from '@wordpress/editor';\n\n/**\n * Internal dependencies\n */\nimport { store as editPostStore } from '../../../store';\n\n/**\n * Set of available mode options.\n *\n * @type {Array}\n */\nconst MODES = [\n\t{\n\t\tvalue: 'visual',\n\t\tlabel: __( 'Visual editor' ),\n\t},\n\t{\n\t\tvalue: 'text',\n\t\tlabel: __( 'Code editor' ),\n\t},\n];\n\nfunction ModeSwitcher() {\n\tconst { shortcut, isRichEditingEnabled, isCodeEditingEnabled, mode } =\n\t\tuseSelect(\n\t\t\t( select ) => ( {\n\t\t\t\tshortcut: select(\n\t\t\t\t\tkeyboardShortcutsStore\n\t\t\t\t).getShortcutRepresentation( 'core/edit-post/toggle-mode' ),\n\t\t\t\tisRichEditingEnabled:\n\t\t\t\t\tselect( editorStore ).getEditorSettings()\n\t\t\t\t\t\t.richEditingEnabled,\n\t\t\t\tisCodeEditingEnabled:\n\t\t\t\t\tselect( editorStore ).getEditorSettings()\n\t\t\t\t\t\t.codeEditingEnabled,\n\t\t\t\tmode: select( editPostStore ).getEditorMode(),\n\t\t\t} ),\n\t\t\t[]\n\t\t);\n\tconst { switchEditorMode } = useDispatch( editPostStore );\n\n\tlet selectedMode = mode;\n\tif ( ! isRichEditingEnabled && mode === 'visual' ) {\n\t\tselectedMode = 'text';\n\t}\n\tif ( ! isCodeEditingEnabled && mode === 'text' ) {\n\t\tselectedMode = 'visual';\n\t}\n\n\tconst choices = MODES.map( ( choice ) => {\n\t\tif ( ! isCodeEditingEnabled && choice.value === 'text' ) {\n\t\t\tchoice = {\n\t\t\t\t...choice,\n\t\t\t\tdisabled: true,\n\t\t\t};\n\t\t}\n\t\tif ( ! isRichEditingEnabled && choice.value === 'visual' ) {\n\t\t\tchoice = {\n\t\t\t\t...choice,\n\t\t\t\tdisabled: true,\n\t\t\t\tinfo: __(\n\t\t\t\t\t'You can enable the visual editor in your profile settings.'\n\t\t\t\t),\n\t\t\t};\n\t\t}\n\t\tif ( choice.value !== selectedMode && ! choice.disabled ) {\n\t\t\treturn { ...choice, shortcut };\n\t\t}\n\t\treturn choice;\n\t} );\n\n\treturn (\n\t\t<MenuGroup label={ __( 'Editor' ) }>\n\t\t\t<MenuItemsChoice\n\t\t\t\tchoices={ choices }\n\t\t\t\tvalue={ selectedMode }\n\t\t\t\tonSelect={ switchEditorMode }\n\t\t\t/>\n\t\t</MenuGroup>\n\t);\n}\n\nexport default ModeSwitcher;\n"],"mappings":";A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AoB,IAAIC,IAAI,KAAK,MAAM,EAAG;IAChDQ,YAAY,GAAG,QAAQ;EACxB;EAEA,MAAMC,OAAO,GAAGhB,KAAK,CAACiB,GAAG,CAAIC,MAAM,IAAM;IACxC,IAAK,CAAEZ,oBAAoB,IAAIY,MAAM,CAACjB,KAAK,KAAK,MAAM,EAAG;MACxDiB,MAAM,GAAG;QACR,GAAGA,MAAM;QACTC,QAAQ,EAAE;MACX,CAAC;IACF;IACA,IAAK,CAAEd,oBAAoB,IAAIa,MAAM,CAACjB,KAAK,KAAK,QAAQ,EAAG;MAC1DiB,MAAM,GAAG;QACR,GAAGA,MAAM;QACTC,QAAQ,EAAE,IAAI;QACdC,IAAI,EAAE7B,EAAE,CACP,4DACD;MACD,CAAC;IACF;IACA,IAAK2B,MAAM,CAACjB,KAAK,KAAKc,YAAY,IAAI,CAAEG,MAAM,CAACC,QAAQ,EAAG;MACzD,OAAO;QAAE,GAAGD,MAAM;QAAEd;MAAS,CAAC;IAC/B;IACA,OAAOc,MAAM;EACd,CAAE,CAAC;EAEH,OACCG,aAAA,CAAC5B,SAAS;IAACS,KAAK,EAAGX,EAAE,CAAE,QAAS;EAAG,GAClC8B,aAAA,CAAC7B,eAAe;IACfwB,OAAO,EAAGA,OAAS;IACnBf,KAAK,EAAGc,YAAc;IACtBO,QAAQ,EAAGR;EAAkB,CAC7B,CACS,CAAC;AAEd;AAEA,eAAeX,YAAY"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { __ } from '@wordpress/i18n';
|
|
5
|
-
import { MenuItemsChoice, MenuGroup } from '@wordpress/components';
|
|
6
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
7
|
-
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
|
|
8
|
-
import { store as editorStore } from '@wordpress/editor';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Internal dependencies
|
|
12
|
-
*/
|
|
13
|
-
import { store as editPostStore } from '../../../store';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Set of available mode options.
|
|
17
|
-
*
|
|
18
|
-
* @type {Array}
|
|
19
|
-
*/
|
|
20
|
-
const MODES = [
|
|
21
|
-
{
|
|
22
|
-
value: 'visual',
|
|
23
|
-
label: __( 'Visual editor' ),
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
value: 'text',
|
|
27
|
-
label: __( 'Code editor' ),
|
|
28
|
-
},
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
function ModeSwitcher() {
|
|
32
|
-
const { shortcut, isRichEditingEnabled, isCodeEditingEnabled, mode } =
|
|
33
|
-
useSelect(
|
|
34
|
-
( select ) => ( {
|
|
35
|
-
shortcut: select(
|
|
36
|
-
keyboardShortcutsStore
|
|
37
|
-
).getShortcutRepresentation( 'core/edit-post/toggle-mode' ),
|
|
38
|
-
isRichEditingEnabled:
|
|
39
|
-
select( editorStore ).getEditorSettings()
|
|
40
|
-
.richEditingEnabled,
|
|
41
|
-
isCodeEditingEnabled:
|
|
42
|
-
select( editorStore ).getEditorSettings()
|
|
43
|
-
.codeEditingEnabled,
|
|
44
|
-
mode: select( editPostStore ).getEditorMode(),
|
|
45
|
-
} ),
|
|
46
|
-
[]
|
|
47
|
-
);
|
|
48
|
-
const { switchEditorMode } = useDispatch( editPostStore );
|
|
49
|
-
|
|
50
|
-
let selectedMode = mode;
|
|
51
|
-
if ( ! isRichEditingEnabled && mode === 'visual' ) {
|
|
52
|
-
selectedMode = 'text';
|
|
53
|
-
}
|
|
54
|
-
if ( ! isCodeEditingEnabled && mode === 'text' ) {
|
|
55
|
-
selectedMode = 'visual';
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const choices = MODES.map( ( choice ) => {
|
|
59
|
-
if ( ! isCodeEditingEnabled && choice.value === 'text' ) {
|
|
60
|
-
choice = {
|
|
61
|
-
...choice,
|
|
62
|
-
disabled: true,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
if ( ! isRichEditingEnabled && choice.value === 'visual' ) {
|
|
66
|
-
choice = {
|
|
67
|
-
...choice,
|
|
68
|
-
disabled: true,
|
|
69
|
-
info: __(
|
|
70
|
-
'You can enable the visual editor in your profile settings.'
|
|
71
|
-
),
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
if ( choice.value !== selectedMode && ! choice.disabled ) {
|
|
75
|
-
return { ...choice, shortcut };
|
|
76
|
-
}
|
|
77
|
-
return choice;
|
|
78
|
-
} );
|
|
79
|
-
|
|
80
|
-
return (
|
|
81
|
-
<MenuGroup label={ __( 'Editor' ) }>
|
|
82
|
-
<MenuItemsChoice
|
|
83
|
-
choices={ choices }
|
|
84
|
-
value={ selectedMode }
|
|
85
|
-
onSelect={ switchEditorMode }
|
|
86
|
-
/>
|
|
87
|
-
</MenuGroup>
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export default ModeSwitcher;
|