PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 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 All 127 releases
extendify / src / Agent / tours / page-editor.js

page-editor.js in Extendify 3.2.1, at src/Agent/tours/page-editor.js

273 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { waitUntilExists, waitUntilGone } from '@agent/lib/tour-helpers';
2 import { createBlock } from '@wordpress/blocks';
3 import { __, isRTL } from '@wordpress/i18n';
4
5 const hasIframe = () =>
6 !!document.querySelector('iframe[name="editor-canvas"]');
7 const disableKeyboard = (e) => e.keyCode !== 13 ?? e.preventDefault();
8 const inserterButtonSelector = (extraState = '') =>
9 `.edit-post-header-toolbar__inserter-toggle${extraState}, .editor-document-tools__inserter-toggle${extraState}`;
10
11 export default {
12 id: 'page-editor-tour',
13 title: __('Page editor', 'extendify-local'),
14 message: __('Tour the page editor', 'extendify-local'),
15 settings: {
16 allowOverflow: true,
17 startFrom: [
18 window.extSharedData?.showAIPageCreation
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 },
85 },
86 },
87 {
88 title: __('Page Title', 'extendify-local'),
89 text: __(
90 '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.',
91 'extendify-local',
92 ),
93 attachTo: {
94 element: () =>
95 hasIframe() ? 'iframe[name="editor-canvas"]' : '.wp-block-post-title',
96 offset: () => ({
97 marginTop: hasIframe() ? 15 : 0,
98 marginLeft: isRTL()
99 ? hasIframe()
100 ? 15
101 : -15
102 : hasIframe()
103 ? -15
104 : 15,
105 }),
106 position: {
107 x: isRTL() ? 'left' : 'right',
108 y: 'top',
109 },
110 hook: () =>
111 isRTL()
112 ? hasIframe()
113 ? 'top left'
114 : 'top right'
115 : hasIframe()
116 ? 'top right'
117 : 'top left',
118 },
119 events: {
120 beforeAttach: async () => {
121 await window.wp.data
122 .dispatch('core/editor')
123 .editPost({ title: 'Sample Post' });
124 },
125 },
126 },
127 {
128 title: __('Blocks', 'extendify-local'),
129 text: __(
130 'Each block will show up on the page and can be edited by clicking on it.',
131 'extendify-local',
132 ),
133 attachTo: {
134 element: () =>
135 hasIframe()
136 ? 'iframe[name="editor-canvas"]'
137 : '.wp-block-post-content > p',
138 offset: () => ({
139 marginTop: hasIframe() ? 15 : 0,
140 marginLeft: isRTL()
141 ? hasIframe()
142 ? 15
143 : -15
144 : hasIframe()
145 ? -15
146 : 15,
147 }),
148 position: {
149 x: isRTL() ? 'left' : 'right',
150 y: 'top',
151 },
152 hook: () =>
153 isRTL()
154 ? hasIframe()
155 ? 'top left'
156 : 'top right'
157 : hasIframe()
158 ? 'top right'
159 : 'top left',
160 },
161 events: {
162 beforeAttach: async () => {
163 // get block count
164 const blockCount = await window.wp.data
165 .select('core/block-editor')
166 .getBlockCount();
167 if (blockCount > 0) return;
168 // create a block and insert it
169 const block = createBlock('core/paragraph', {
170 content: __(
171 "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.",
172 'extendify-local',
173 ),
174 });
175 await window.wp.data.dispatch('core/block-editor').insertBlock(block);
176 return hasIframe()
177 ? await window.wp.data
178 .dispatch('core/block-editor')
179 .flashBlock(block.clientId)
180 : null;
181 },
182 },
183 },
184 {
185 title: __('Page and Block Settings', 'extendify-local'),
186 text: __(
187 'Select either page or block to change the settings for the entire page or the block that is selected.',
188 'extendify-local',
189 ),
190 attachTo: {
191 element: '.interface-interface-skeleton__sidebar',
192 offset: {
193 marginTop: 0,
194 marginLeft: isRTL() ? 15 : -15,
195 },
196 position: {
197 x: isRTL() ? 'right' : 'left',
198 y: 'top',
199 },
200 hook: isRTL() ? 'top left' : 'top right',
201 },
202 events: {
203 beforeAttach: async () => {
204 const settingsButton = document.querySelector(
205 `[aria-label="${__('Settings')}"]:not(.is-pressed)`,
206 );
207 if (settingsButton) {
208 settingsButton?.click();
209 } else {
210 document
211 .querySelector('[aria-label="Settings"]:not(.is-pressed)')
212 ?.click();
213 }
214
215 await waitUntilExists('.interface-interface-skeleton__sidebar');
216 document
217 .querySelector(
218 '.edit-post-sidebar__panel-tab,[data-tab-id="edit-post/document"]',
219 )
220 ?.click();
221
222 await waitUntilExists('.editor-post-status');
223 document.querySelector('.edit-post-post-status button')?.click();
224 },
225 },
226 },
227 {
228 title: __('Preview', 'extendify-local'),
229 text: __(
230 'Click preview to view how your changes look on the front end of your site.',
231 'extendify-local',
232 ),
233 attachTo: {
234 element:
235 '.block-editor-post-preview__button-toggle,.editor-preview-dropdown__toggle',
236 offset: {
237 marginTop: 0,
238 marginLeft: isRTL() ? 15 : -15,
239 },
240 position: {
241 x: isRTL() ? 'right' : 'left',
242 y: 'top',
243 },
244 hook: isRTL() ? 'top left' : 'top right',
245 },
246 events: {},
247 },
248 {
249 title: __('Publish or Save', 'extendify-local'),
250 text: __(
251 'Click publish or update to save the changes you have made to the page and make them live on the site.',
252 'extendify-local',
253 ),
254 attachTo: {
255 element: '.editor-post-publish-button__button',
256 offset: {
257 marginTop: 15,
258 },
259 position: {
260 x: isRTL() ? 'left' : 'right',
261 y: 'bottom',
262 },
263 hook: isRTL() ? 'top left' : 'top right',
264 },
265 events: {},
266 },
267 ],
268 };
269
270 const onMutate = new MutationObserver(() => {
271 document.querySelector(inserterButtonSelector(':not(.is-pressed)'))?.click();
272 });
273