PluginProbe
Extendify / 2.2.0
Extendify v2.2.0
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / HelpCenter / tours / page-editor.js

page-editor.js in Extendify 2.2.0, at src/HelpCenter/tours/page-editor.js

278 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { createBlock } from '@wordpress/blocks';
2 import { __, isRTL } from '@wordpress/i18n';
3 import { waitUntilExists, waitUntilGone } from '@help-center/lib/tour-helpers';
4 import { hasPageCreatorEnabled } from '@help-center/lib/utils';
5
6 const hasIframe = () =>
7 !!document.querySelector('iframe[name="editor-canvas"]');
8 const disableKeyboard = (e) => e.keyCode !== 13 ?? e.preventDefault();
9 const inserterButtonSelector = (extraState = '') =>
10 `.edit-post-header-toolbar__inserter-toggle${extraState}, .editor-document-tools__inserter-toggle${extraState}`;
11
12 export default {
13 id: 'page-editor-tour',
14 title: __('Page editor', 'extendify-local'),
15 settings: {
16 allowOverflow: true,
17 startFrom: [
18 hasPageCreatorEnabled
19 ? window.extSharedData.adminUrl +
20 'post-new.php?post_type=page&ext-page-creator-close=1'
21 : window.extSharedData.adminUrl +
22 'post-new.php?post_type=page&ext-close=1',
23 window.extSharedData.adminUrl + 'post-new.php?post_type=page',
24 ],
25 },
26 steps: [
27 {
28 title: __('Add a Block', 'extendify-local'),
29 text: __('Click the plus to open the block inserter.', 'extendify-local'),
30 attachTo: {
31 element: inserterButtonSelector(),
32 offset: {
33 marginTop: 15,
34 marginLeft: 0,
35 },
36 position: {
37 x: isRTL() ? 'right' : 'left',
38 y: 'bottom',
39 },
40 hook: isRTL() ? 'top right' : 'top left',
41 },
42 events: {
43 beforeAttach: async () => {
44 return await waitUntilExists(inserterButtonSelector());
45 },
46 },
47 },
48 {
49 title: __('Block Inserter', 'extendify-local'),
50 text: __(
51 'Add a block by clicking or dragging it onto the page.',
52 'extendify-local',
53 ),
54 attachTo: {
55 element: '.block-editor-inserter__menu',
56 offset: {
57 marginTop: 0,
58 marginLeft: isRTL() ? -15 : 15,
59 },
60 position: {
61 x: isRTL() ? 'left' : 'right',
62 y: 'top',
63 },
64 hook: isRTL() ? 'top right' : 'top left',
65 },
66 events: {
67 beforeAttach: async () => {
68 document
69 .querySelector(inserterButtonSelector(':not(.is-pressed)'))
70 ?.click();
71
72 return await waitUntilExists('.block-editor-tabbed-sidebar');
73 },
74 onAttach: () => {
75 const toggle = document.querySelector(inserterButtonSelector());
76 onMutate.observe(toggle, { attributes: true });
77 window.addEventListener('keydown', disableKeyboard);
78 },
79 onDetach: async () => {
80 onMutate.disconnect();
81 window.removeEventListener('keydown', disableKeyboard);
82 document
83 .querySelector(inserterButtonSelector('.is-pressed'))
84 ?.click();
85 await waitUntilGone('.block-editor-inserter__block-list');
86 requestAnimationFrame(() => {
87 document.getElementById('help-center-tour-next-button')?.focus();
88 });
89 },
90 },
91 },
92 {
93 title: __('Page Title', 'extendify-local'),
94 text: __(
95 'Edit the page title by clicking it. Note: The title may or may not show up on the published page, depending on the page template used.',
96 'extendify-local',
97 ),
98 attachTo: {
99 element: () =>
100 hasIframe() ? 'iframe[name="editor-canvas"]' : '.wp-block-post-title',
101 offset: () => ({
102 marginTop: hasIframe() ? 15 : 0,
103 marginLeft: isRTL()
104 ? hasIframe()
105 ? 15
106 : -15
107 : hasIframe()
108 ? -15
109 : 15,
110 }),
111 position: {
112 x: isRTL() ? 'left' : 'right',
113 y: 'top',
114 },
115 hook: () =>
116 isRTL()
117 ? hasIframe()
118 ? 'top left'
119 : 'top right'
120 : hasIframe()
121 ? 'top right'
122 : 'top left',
123 },
124 events: {
125 beforeAttach: async () => {
126 await window.wp.data
127 .dispatch('core/editor')
128 .editPost({ title: 'Sample Post' });
129 },
130 },
131 },
132 {
133 title: __('Blocks', 'extendify-local'),
134 text: __(
135 'Each block will show up on the page and can be edited by clicking on it.',
136 'extendify-local',
137 ),
138 attachTo: {
139 element: () =>
140 hasIframe()
141 ? 'iframe[name="editor-canvas"]'
142 : '.wp-block-post-content > p',
143 offset: () => ({
144 marginTop: hasIframe() ? 15 : 0,
145 marginLeft: isRTL()
146 ? hasIframe()
147 ? 15
148 : -15
149 : hasIframe()
150 ? -15
151 : 15,
152 }),
153 position: {
154 x: isRTL() ? 'left' : 'right',
155 y: 'top',
156 },
157 hook: () =>
158 isRTL()
159 ? hasIframe()
160 ? 'top left'
161 : 'top right'
162 : hasIframe()
163 ? 'top right'
164 : 'top left',
165 },
166 events: {
167 beforeAttach: async () => {
168 // get block count
169 const blockCount = await window.wp.data
170 .select('core/block-editor')
171 .getBlockCount();
172 if (blockCount > 0) return;
173 // create a block and insert it
174 const block = createBlock('core/paragraph', {
175 content: __(
176 "This is a sample paragraph block. It can be several sentences long and will span multiple rows. You can add as many blocks as you'd like to the page.",
177 'extendify-local',
178 ),
179 });
180 await window.wp.data.dispatch('core/block-editor').insertBlock(block);
181 return hasIframe()
182 ? await window.wp.data
183 .dispatch('core/block-editor')
184 .flashBlock(block.clientId)
185 : null;
186 },
187 },
188 },
189 {
190 title: __('Page and Block Settings', 'extendify-local'),
191 text: __(
192 'Select either page or block to change the settings for the entire page or the block that is selected.',
193 'extendify-local',
194 ),
195 attachTo: {
196 element: '.interface-interface-skeleton__sidebar',
197 offset: {
198 marginTop: 0,
199 marginLeft: isRTL() ? 15 : -15,
200 },
201 position: {
202 x: isRTL() ? 'right' : 'left',
203 y: 'top',
204 },
205 hook: isRTL() ? 'top left' : 'top right',
206 },
207 events: {
208 beforeAttach: async () => {
209 const settingsButton = document.querySelector(
210 `[aria-label="${__('Settings')}"]:not(.is-pressed)`,
211 );
212 if (settingsButton) {
213 settingsButton?.click();
214 } else {
215 document
216 .querySelector('[aria-label="Settings"]:not(.is-pressed)')
217 ?.click();
218 }
219
220 await waitUntilExists('.interface-interface-skeleton__sidebar');
221 document
222 .querySelector(
223 '.edit-post-sidebar__panel-tab,[data-tab-id="edit-post/document"]',
224 )
225 ?.click();
226
227 await waitUntilExists('.editor-post-status');
228 document.querySelector('.edit-post-post-status button')?.click();
229 },
230 },
231 },
232 {
233 title: __('Preview', 'extendify-local'),
234 text: __(
235 'Click preview to view how your changes look on the front end of your site.',
236 'extendify-local',
237 ),
238 attachTo: {
239 element:
240 '.block-editor-post-preview__button-toggle,.editor-preview-dropdown__toggle',
241 offset: {
242 marginTop: 0,
243 marginLeft: isRTL() ? 15 : -15,
244 },
245 position: {
246 x: isRTL() ? 'right' : 'left',
247 y: 'top',
248 },
249 hook: isRTL() ? 'top left' : 'top right',
250 },
251 events: {},
252 },
253 {
254 title: __('Publish or Save', 'extendify-local'),
255 text: __(
256 'Click publish or update to save the changes you have made to the page and make them live on the site.',
257 'extendify-local',
258 ),
259 attachTo: {
260 element: '.editor-post-publish-button__button',
261 offset: {
262 marginTop: 15,
263 },
264 position: {
265 x: isRTL() ? 'left' : 'right',
266 y: 'bottom',
267 },
268 hook: isRTL() ? 'top left' : 'top right',
269 },
270 events: {},
271 },
272 ],
273 };
274
275 const onMutate = new MutationObserver(() => {
276 document.querySelector(inserterButtonSelector(':not(.is-pressed)'))?.click();
277 });
278