PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
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 3.1.5, at src/HelpCenter/tours/page-editor.js

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