@wordpress/e2e-test-utils-playwright 1.36.1-next.738bb1424.0 → 1.37.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.
Files changed (227) hide show
  1. package/build/admin/create-new-post.js +48 -28
  2. package/build/admin/create-new-post.js.map +7 -1
  3. package/build/admin/edit-post.js +37 -17
  4. package/build/admin/edit-post.js.map +7 -1
  5. package/build/admin/get-page-error.js +33 -23
  6. package/build/admin/get-page-error.js.map +7 -1
  7. package/build/admin/index.js +58 -36
  8. package/build/admin/index.js.map +7 -1
  9. package/build/admin/visit-admin-page.js +44 -29
  10. package/build/admin/visit-admin-page.js.map +7 -1
  11. package/build/admin/visit-site-editor.js +73 -64
  12. package/build/admin/visit-site-editor.js.map +7 -1
  13. package/build/config.js +43 -11
  14. package/build/config.js.map +7 -1
  15. package/build/editor/click-block-options-menu-item.js +31 -14
  16. package/build/editor/click-block-options-menu-item.js.map +7 -1
  17. package/build/editor/click-block-toolbar-button.js +35 -13
  18. package/build/editor/click-block-toolbar-button.js.map +7 -1
  19. package/build/editor/get-blocks.js +61 -43
  20. package/build/editor/get-blocks.js.map +7 -1
  21. package/build/editor/get-edited-post-content.js +33 -12
  22. package/build/editor/get-edited-post-content.js.map +7 -1
  23. package/build/editor/index.js +96 -74
  24. package/build/editor/index.js.map +7 -1
  25. package/build/editor/insert-block.js +52 -21
  26. package/build/editor/insert-block.js.map +7 -1
  27. package/build/editor/open-document-settings-sidebar.js +39 -24
  28. package/build/editor/open-document-settings-sidebar.js.map +7 -1
  29. package/build/editor/preview.js +39 -18
  30. package/build/editor/preview.js.map +7 -1
  31. package/build/editor/publish-post.js +44 -42
  32. package/build/editor/publish-post.js.map +7 -1
  33. package/build/editor/save-draft.js +31 -15
  34. package/build/editor/save-draft.js.map +7 -1
  35. package/build/editor/select-blocks.js +48 -25
  36. package/build/editor/select-blocks.js.map +7 -1
  37. package/build/editor/set-content.js +36 -14
  38. package/build/editor/set-content.js.map +7 -1
  39. package/build/editor/set-is-fixed-toolbar.js +33 -15
  40. package/build/editor/set-is-fixed-toolbar.js.map +7 -1
  41. package/build/editor/set-preferences.js +40 -18
  42. package/build/editor/set-preferences.js.map +7 -1
  43. package/build/editor/show-block-toolbar.js +32 -16
  44. package/build/editor/show-block-toolbar.js.map +7 -1
  45. package/build/editor/site-editor.js +48 -41
  46. package/build/editor/site-editor.js.map +7 -1
  47. package/build/editor/switch-editor-tool.js +44 -30
  48. package/build/editor/switch-editor-tool.js.map +7 -1
  49. package/build/editor/switch-to-legacy-canvas.js +35 -14
  50. package/build/editor/switch-to-legacy-canvas.js.map +7 -1
  51. package/build/editor/transform-block-to.js +43 -21
  52. package/build/editor/transform-block-to.js.map +7 -1
  53. package/build/index.js +53 -18
  54. package/build/index.js.map +7 -1
  55. package/build/lighthouse/index.js +93 -55
  56. package/build/lighthouse/index.js.map +7 -1
  57. package/build/metrics/index.js +302 -251
  58. package/build/metrics/index.js.map +7 -1
  59. package/build/page-utils/drag-files.js +136 -112
  60. package/build/page-utils/drag-files.js.map +7 -1
  61. package/build/page-utils/emulate-network-conditions.js +95 -67
  62. package/build/page-utils/emulate-network-conditions.js.map +7 -1
  63. package/build/page-utils/index.js +58 -36
  64. package/build/page-utils/index.js.map +7 -1
  65. package/build/page-utils/is-current-url.js +33 -18
  66. package/build/page-utils/is-current-url.js.map +7 -1
  67. package/build/page-utils/keycodes.js +53 -39
  68. package/build/page-utils/keycodes.js.map +7 -1
  69. package/build/page-utils/press-keys.js +153 -130
  70. package/build/page-utils/press-keys.js.map +7 -1
  71. package/build/page-utils/set-browser-viewport.js +35 -42
  72. package/build/page-utils/set-browser-viewport.js.map +7 -1
  73. package/build/request-utils/blocks.js +51 -40
  74. package/build/request-utils/blocks.js.map +7 -1
  75. package/build/request-utils/comments.js +59 -45
  76. package/build/request-utils/comments.js.map +7 -1
  77. package/build/request-utils/gutenberg-experiments.js +63 -38
  78. package/build/request-utils/gutenberg-experiments.js.map +7 -1
  79. package/build/request-utils/index.js +191 -155
  80. package/build/request-utils/index.js.map +7 -1
  81. package/build/request-utils/login.js +45 -18
  82. package/build/request-utils/login.js.map +7 -1
  83. package/build/request-utils/media.js +74 -64
  84. package/build/request-utils/media.js.map +7 -1
  85. package/build/request-utils/menus.js +121 -109
  86. package/build/request-utils/menus.js.map +7 -1
  87. package/build/request-utils/pages.js +63 -50
  88. package/build/request-utils/pages.js.map +7 -1
  89. package/build/request-utils/patterns.js +41 -24
  90. package/build/request-utils/patterns.js.map +7 -1
  91. package/build/request-utils/plugins.js +70 -74
  92. package/build/request-utils/plugins.js.map +7 -1
  93. package/build/request-utils/posts.js +55 -41
  94. package/build/request-utils/posts.js.map +7 -1
  95. package/build/request-utils/preferences.js +38 -17
  96. package/build/request-utils/preferences.js.map +7 -1
  97. package/build/request-utils/rest.js +155 -129
  98. package/build/request-utils/rest.js.map +7 -1
  99. package/build/request-utils/site-settings.js +40 -28
  100. package/build/request-utils/site-settings.js.map +7 -1
  101. package/build/request-utils/templates.js +60 -46
  102. package/build/request-utils/templates.js.map +7 -1
  103. package/build/request-utils/themes.js +80 -53
  104. package/build/request-utils/themes.js.map +7 -1
  105. package/build/request-utils/users.js +74 -72
  106. package/build/request-utils/users.js.map +7 -1
  107. package/build/request-utils/widgets.js +73 -55
  108. package/build/request-utils/widgets.js.map +7 -1
  109. package/build/test.js +130 -146
  110. package/build/test.js.map +7 -1
  111. package/build/types.js +18 -2
  112. package/build/types.js.map +7 -1
  113. package/build-types/index.d.ts +1 -1
  114. package/build-types/index.d.ts.map +1 -1
  115. package/package.json +2 -2
  116. package/build/admin/create-new-post.cjs +0 -51
  117. package/build/admin/create-new-post.cjs.map +0 -7
  118. package/build/admin/edit-post.cjs +0 -40
  119. package/build/admin/edit-post.cjs.map +0 -7
  120. package/build/admin/get-page-error.cjs +0 -36
  121. package/build/admin/get-page-error.cjs.map +0 -7
  122. package/build/admin/index.cjs +0 -59
  123. package/build/admin/index.cjs.map +0 -7
  124. package/build/admin/visit-admin-page.cjs +0 -47
  125. package/build/admin/visit-admin-page.cjs.map +0 -7
  126. package/build/admin/visit-site-editor.cjs +0 -77
  127. package/build/admin/visit-site-editor.cjs.map +0 -7
  128. package/build/config.cjs +0 -45
  129. package/build/config.cjs.map +0 -7
  130. package/build/editor/click-block-options-menu-item.cjs +0 -34
  131. package/build/editor/click-block-options-menu-item.cjs.map +0 -7
  132. package/build/editor/click-block-toolbar-button.cjs +0 -38
  133. package/build/editor/click-block-toolbar-button.cjs.map +0 -7
  134. package/build/editor/get-blocks.cjs +0 -64
  135. package/build/editor/get-blocks.cjs.map +0 -7
  136. package/build/editor/get-edited-post-content.cjs +0 -36
  137. package/build/editor/get-edited-post-content.cjs.map +0 -7
  138. package/build/editor/index.cjs +0 -97
  139. package/build/editor/index.cjs.map +0 -7
  140. package/build/editor/insert-block.cjs +0 -55
  141. package/build/editor/insert-block.cjs.map +0 -7
  142. package/build/editor/open-document-settings-sidebar.cjs +0 -42
  143. package/build/editor/open-document-settings-sidebar.cjs.map +0 -7
  144. package/build/editor/preview.cjs +0 -42
  145. package/build/editor/preview.cjs.map +0 -7
  146. package/build/editor/publish-post.cjs +0 -47
  147. package/build/editor/publish-post.cjs.map +0 -7
  148. package/build/editor/save-draft.cjs +0 -34
  149. package/build/editor/save-draft.cjs.map +0 -7
  150. package/build/editor/select-blocks.cjs +0 -51
  151. package/build/editor/select-blocks.cjs.map +0 -7
  152. package/build/editor/set-content.cjs +0 -39
  153. package/build/editor/set-content.cjs.map +0 -7
  154. package/build/editor/set-is-fixed-toolbar.cjs +0 -36
  155. package/build/editor/set-is-fixed-toolbar.cjs.map +0 -7
  156. package/build/editor/set-preferences.cjs +0 -43
  157. package/build/editor/set-preferences.cjs.map +0 -7
  158. package/build/editor/show-block-toolbar.cjs +0 -35
  159. package/build/editor/show-block-toolbar.cjs.map +0 -7
  160. package/build/editor/site-editor.cjs +0 -51
  161. package/build/editor/site-editor.cjs.map +0 -7
  162. package/build/editor/switch-editor-tool.cjs +0 -47
  163. package/build/editor/switch-editor-tool.cjs.map +0 -7
  164. package/build/editor/switch-to-legacy-canvas.cjs +0 -39
  165. package/build/editor/switch-to-legacy-canvas.cjs.map +0 -7
  166. package/build/editor/transform-block-to.cjs +0 -46
  167. package/build/editor/transform-block-to.cjs.map +0 -7
  168. package/build/index.cjs +0 -51
  169. package/build/index.cjs.map +0 -7
  170. package/build/lighthouse/index.cjs +0 -96
  171. package/build/lighthouse/index.cjs.map +0 -7
  172. package/build/metrics/index.cjs +0 -309
  173. package/build/metrics/index.cjs.map +0 -7
  174. package/build/page-utils/drag-files.cjs +0 -143
  175. package/build/page-utils/drag-files.cjs.map +0 -7
  176. package/build/page-utils/emulate-network-conditions.cjs +0 -99
  177. package/build/page-utils/emulate-network-conditions.cjs.map +0 -7
  178. package/build/page-utils/index.cjs +0 -59
  179. package/build/page-utils/index.cjs.map +0 -7
  180. package/build/page-utils/is-current-url.cjs +0 -36
  181. package/build/page-utils/is-current-url.cjs.map +0 -7
  182. package/build/page-utils/keycodes.cjs +0 -55
  183. package/build/page-utils/keycodes.cjs.map +0 -7
  184. package/build/page-utils/press-keys.cjs +0 -165
  185. package/build/page-utils/press-keys.cjs.map +0 -7
  186. package/build/page-utils/set-browser-viewport.cjs +0 -39
  187. package/build/page-utils/set-browser-viewport.cjs.map +0 -7
  188. package/build/request-utils/blocks.cjs +0 -56
  189. package/build/request-utils/blocks.cjs.map +0 -7
  190. package/build/request-utils/comments.cjs +0 -66
  191. package/build/request-utils/comments.cjs.map +0 -7
  192. package/build/request-utils/gutenberg-experiments.cjs +0 -66
  193. package/build/request-utils/gutenberg-experiments.cjs.map +0 -7
  194. package/build/request-utils/index.cjs +0 -194
  195. package/build/request-utils/index.cjs.map +0 -7
  196. package/build/request-utils/login.cjs +0 -48
  197. package/build/request-utils/login.cjs.map +0 -7
  198. package/build/request-utils/media.cjs +0 -83
  199. package/build/request-utils/media.cjs.map +0 -7
  200. package/build/request-utils/menus.cjs +0 -132
  201. package/build/request-utils/menus.cjs.map +0 -7
  202. package/build/request-utils/pages.cjs +0 -71
  203. package/build/request-utils/pages.cjs.map +0 -7
  204. package/build/request-utils/patterns.cjs +0 -44
  205. package/build/request-utils/patterns.cjs.map +0 -7
  206. package/build/request-utils/plugins.cjs +0 -81
  207. package/build/request-utils/plugins.cjs.map +0 -7
  208. package/build/request-utils/posts.cjs +0 -61
  209. package/build/request-utils/posts.cjs.map +0 -7
  210. package/build/request-utils/preferences.cjs +0 -41
  211. package/build/request-utils/preferences.cjs.map +0 -7
  212. package/build/request-utils/rest.cjs +0 -174
  213. package/build/request-utils/rest.cjs.map +0 -7
  214. package/build/request-utils/site-settings.cjs +0 -45
  215. package/build/request-utils/site-settings.cjs.map +0 -7
  216. package/build/request-utils/templates.cjs +0 -68
  217. package/build/request-utils/templates.cjs.map +0 -7
  218. package/build/request-utils/themes.cjs +0 -89
  219. package/build/request-utils/themes.cjs.map +0 -7
  220. package/build/request-utils/users.cjs +0 -83
  221. package/build/request-utils/users.cjs.map +0 -7
  222. package/build/request-utils/widgets.cjs +0 -79
  223. package/build/request-utils/widgets.cjs.map +0 -7
  224. package/build/test.cjs +0 -136
  225. package/build/test.cjs.map +0 -7
  226. package/build/types.cjs +0 -19
  227. package/build/types.cjs.map +0 -7
@@ -1,62 +1,89 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.activateTheme = activateTheme;
4
- exports.getCurrentThemeGlobalStylesPostId = getCurrentThemeGlobalStylesPostId;
5
- exports.getThemeGlobalStylesRevisions = getThemeGlobalStylesRevisions;
6
- const config_1 = require("../config");
7
- const THEMES_URL = new URL('wp-admin/themes.php', config_1.WP_BASE_URL).href;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/e2e-test-utils-playwright/src/request-utils/themes.ts
21
+ var themes_exports = {};
22
+ __export(themes_exports, {
23
+ activateTheme: () => activateTheme,
24
+ getCurrentThemeGlobalStylesPostId: () => getCurrentThemeGlobalStylesPostId,
25
+ getThemeGlobalStylesRevisions: () => getThemeGlobalStylesRevisions
26
+ });
27
+ module.exports = __toCommonJS(themes_exports);
28
+ var import_config = require("../config");
29
+ var THEMES_URL = new URL("wp-admin/themes.php", import_config.WP_BASE_URL).href;
8
30
  async function activateTheme(themeSlug) {
9
- let response = await this.request.get(THEMES_URL);
10
- const html = await response.text();
11
- const optionalFolder = '([a-z0-9-]+%2F)?';
12
- // The `optionalFolder` regex part matches paths with a folder,
13
- // so it will return the first match, which might contain a folder.
14
- // First try to honor the included theme slug, that is, without a folder.
15
- let matchGroup = html.match(`action=activate&stylesheet=${encodeURIComponent(themeSlug)}&_wpnonce=[a-z0-9]+`);
16
- // If the theme is not found, try to match the theme slug with a folder.
17
- if (!matchGroup) {
18
- matchGroup = html.match(`action=activate&stylesheet=${optionalFolder}${encodeURIComponent(themeSlug)}&_wpnonce=[a-z0-9]+`);
31
+ let response = await this.request.get(THEMES_URL);
32
+ const html = await response.text();
33
+ const optionalFolder = "([a-z0-9-]+%2F)?";
34
+ let matchGroup = html.match(
35
+ `action=activate&stylesheet=${encodeURIComponent(
36
+ themeSlug
37
+ )}&_wpnonce=[a-z0-9]+`
38
+ );
39
+ if (!matchGroup) {
40
+ matchGroup = html.match(
41
+ `action=activate&stylesheet=${optionalFolder}${encodeURIComponent(
42
+ themeSlug
43
+ )}&_wpnonce=[a-z0-9]+`
44
+ );
45
+ }
46
+ if (!matchGroup) {
47
+ if (html.includes(`data-slug="${themeSlug}"`)) {
48
+ return;
19
49
  }
20
- if (!matchGroup) {
21
- if (html.includes(`data-slug="${themeSlug}"`)) {
22
- // The theme is already activated.
23
- return;
24
- }
25
- throw new Error(`The theme "${themeSlug}" is not installed`);
26
- }
27
- const [activateQuery] = matchGroup;
28
- const activateLink = THEMES_URL + `?${activateQuery}`.replace(/&/g, '&');
29
- response = await this.request.get(activateLink);
30
- await response.dispose();
50
+ throw new Error(`The theme "${themeSlug}" is not installed`);
51
+ }
52
+ const [activateQuery] = matchGroup;
53
+ const activateLink = THEMES_URL + `?${activateQuery}`.replace(/&/g, "&");
54
+ response = await this.request.get(activateLink);
55
+ await response.dispose();
31
56
  }
32
- // https://developer.wordpress.org/rest-api/reference/themes/#definition
33
57
  async function getCurrentThemeGlobalStylesPostId() {
34
- const themes = await this.rest({
35
- path: '/wp/v2/themes',
36
- });
37
- let themeGlobalStylesId = '';
38
- if (themes && themes.length) {
39
- const currentTheme = themes.find(({ status }) => status === 'active');
40
- const globalStylesURL = currentTheme?._links?.['wp:user-global-styles']?.[0]?.href;
41
- if (globalStylesURL) {
42
- themeGlobalStylesId = globalStylesURL?.split('rest_route=/wp/v2/global-styles/')[1];
43
- }
58
+ const themes = await this.rest({
59
+ path: "/wp/v2/themes"
60
+ });
61
+ let themeGlobalStylesId = "";
62
+ if (themes && themes.length) {
63
+ const currentTheme = themes.find(
64
+ ({ status }) => status === "active"
65
+ );
66
+ const globalStylesURL = currentTheme?._links?.["wp:user-global-styles"]?.[0]?.href;
67
+ if (globalStylesURL) {
68
+ themeGlobalStylesId = globalStylesURL?.split(
69
+ "rest_route=/wp/v2/global-styles/"
70
+ )[1];
44
71
  }
45
- return themeGlobalStylesId;
72
+ }
73
+ return themeGlobalStylesId;
46
74
  }
47
- /**
48
- * Deletes all post revisions using the REST API.
49
- *
50
- * @param {} this RequestUtils.
51
- * @param {string|number} parentId Post attributes.
52
- */
53
75
  async function getThemeGlobalStylesRevisions(parentId) {
54
- // Lists all global styles revisions.
55
- return await this.rest({
56
- path: `/wp/v2/global-styles/${parentId}/revisions`,
57
- params: {
58
- per_page: 100,
59
- },
60
- });
76
+ return await this.rest({
77
+ path: `/wp/v2/global-styles/${parentId}/revisions`,
78
+ params: {
79
+ per_page: 100
80
+ }
81
+ });
61
82
  }
62
- //# sourceMappingURL=themes.js.map
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {
85
+ activateTheme,
86
+ getCurrentThemeGlobalStylesPostId,
87
+ getThemeGlobalStylesRevisions
88
+ });
89
+ //# sourceMappingURL=themes.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"themes.js","sourceRoot":"","sources":["../../src/request-utils/themes.ts"],"names":[],"mappings":";;AAmGC,sCAAa;AACb,8EAAiC;AACjC,sEAA6B;AAjG9B,sCAAwC;AAExC,MAAM,UAAU,GAAG,IAAI,GAAG,CAAE,qBAAqB,EAAE,oBAAW,CAAE,CAAC,IAAI,CAAC;AAEtE,KAAK,UAAU,aAAa,CAE3B,SAAiB;IAEjB,IAAI,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAE,UAAU,CAAE,CAAC;IACpD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACnC,MAAM,cAAc,GAAG,kBAAkB,CAAC;IAE1C,+DAA+D;IAC/D,mEAAmE;IACnE,yEAAyE;IACzE,IAAI,UAAU,GAAG,IAAI,CAAC,KAAK,CAC1B,kCAAmC,kBAAkB,CACpD,SAAS,CACR,yBAAyB,CAC3B,CAAC;IAEF,wEAAwE;IACxE,IAAK,CAAE,UAAU,EAAG,CAAC;QACpB,UAAU,GAAG,IAAI,CAAC,KAAK,CACtB,kCAAmC,cAAe,GAAI,kBAAkB,CACvE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,CAE3C,QAAyB;IAEzB,qCAAqC;IACrC,OAAO,MAAM,IAAI,CAAC,IAAI,CAAgC;QACrD,IAAI,EAAE,wBAAyB,QAAS,YAAY;QACpD,MAAM,EAAE;YACP,QAAQ,EAAE,GAAG;SACb;KACD,CAAE,CAAC;AACL,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/request-utils/themes.ts"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RequestUtils } from './index';\nimport { WP_BASE_URL } from '../config';\n\nconst THEMES_URL = new URL( 'wp-admin/themes.php', WP_BASE_URL ).href;\n\nasync function activateTheme(\n\tthis: RequestUtils,\n\tthemeSlug: string\n): Promise< void > {\n\tlet response = await this.request.get( THEMES_URL );\n\tconst html = await response.text();\n\tconst optionalFolder = '([a-z0-9-]+%2F)?';\n\n\t// The `optionalFolder` regex part matches paths with a folder,\n\t// so it will return the first match, which might contain a folder.\n\t// First try to honor the included theme slug, that is, without a folder.\n\tlet matchGroup = html.match(\n\t\t`action=activate&amp;stylesheet=${ encodeURIComponent(\n\t\t\tthemeSlug\n\t\t) }&amp;_wpnonce=[a-z0-9]+`\n\t);\n\n\t// If the theme is not found, try to match the theme slug with a folder.\n\tif ( ! matchGroup ) {\n\t\tmatchGroup = html.match(\n\t\t\t`action=activate&amp;stylesheet=${ optionalFolder }${ encodeURIComponent(\n\t\t\t\tthemeSlug\n\t\t\t) }&amp;_wpnonce=[a-z0-9]+`\n\t\t);\n\t}\n\n\tif ( ! matchGroup ) {\n\t\tif ( html.includes( `data-slug=\"${ themeSlug }\"` ) ) {\n\t\t\t// The theme is already activated.\n\t\t\treturn;\n\t\t}\n\n\t\tthrow new Error( `The theme \"${ themeSlug }\" is not installed` );\n\t}\n\n\tconst [ activateQuery ] = matchGroup;\n\tconst activateLink =\n\t\tTHEMES_URL + `?${ activateQuery }`.replace( /&amp;/g, '&' );\n\n\tresponse = await this.request.get( activateLink );\n\n\tawait response.dispose();\n}\n\n// https://developer.wordpress.org/rest-api/reference/themes/#definition\nasync function getCurrentThemeGlobalStylesPostId( this: RequestUtils ) {\n\ttype ThemeItem = {\n\t\tstylesheet: string;\n\t\tstatus: string;\n\t\t_links: { 'wp:user-global-styles': { href: string }[] };\n\t};\n\tconst themes = await this.rest< ThemeItem[] >( {\n\t\tpath: '/wp/v2/themes',\n\t} );\n\tlet themeGlobalStylesId: string = '';\n\tif ( themes && themes.length ) {\n\t\tconst currentTheme: ThemeItem | undefined = themes.find(\n\t\t\t( { status } ) => status === 'active'\n\t\t);\n\n\t\tconst globalStylesURL =\n\t\t\tcurrentTheme?._links?.[ 'wp:user-global-styles' ]?.[ 0 ]?.href;\n\t\tif ( globalStylesURL ) {\n\t\t\tthemeGlobalStylesId = globalStylesURL?.split(\n\t\t\t\t'rest_route=/wp/v2/global-styles/'\n\t\t\t)[ 1 ];\n\t\t}\n\t}\n\treturn themeGlobalStylesId;\n}\n\n/**\n * Deletes all post revisions using the REST API.\n *\n * @param {} this RequestUtils.\n * @param {string|number} parentId Post attributes.\n */\nasync function getThemeGlobalStylesRevisions(\n\tthis: RequestUtils,\n\tparentId: number | string\n) {\n\t// Lists all global styles revisions.\n\treturn await this.rest< Record< string, Object >[] >( {\n\t\tpath: `/wp/v2/global-styles/${ parentId }/revisions`,\n\t\tparams: {\n\t\t\tper_page: 100,\n\t\t},\n\t} );\n}\n\nexport {\n\tactivateTheme,\n\tgetCurrentThemeGlobalStylesPostId,\n\tgetThemeGlobalStylesRevisions,\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAA4B;AAE5B,IAAM,aAAa,IAAI,IAAK,uBAAuB,yBAAY,EAAE;AAEjE,eAAe,cAEd,WACkB;AAClB,MAAI,WAAW,MAAM,KAAK,QAAQ,IAAK,UAAW;AAClD,QAAM,OAAO,MAAM,SAAS,KAAK;AACjC,QAAM,iBAAiB;AAKvB,MAAI,aAAa,KAAK;AAAA,IACrB,kCAAmC;AAAA,MAClC;AAAA,IACD,CAAE;AAAA,EACH;AAGA,MAAK,CAAE,YAAa;AACnB,iBAAa,KAAK;AAAA,MACjB,kCAAmC,cAAe,GAAI;AAAA,QACrD;AAAA,MACD,CAAE;AAAA,IACH;AAAA,EACD;AAEA,MAAK,CAAE,YAAa;AACnB,QAAK,KAAK,SAAU,cAAe,SAAU,GAAI,GAAI;AAEpD;AAAA,IACD;AAEA,UAAM,IAAI,MAAO,cAAe,SAAU,oBAAqB;AAAA,EAChE;AAEA,QAAM,CAAE,aAAc,IAAI;AAC1B,QAAM,eACL,aAAa,IAAK,aAAc,GAAG,QAAS,UAAU,GAAI;AAE3D,aAAW,MAAM,KAAK,QAAQ,IAAK,YAAa;AAEhD,QAAM,SAAS,QAAQ;AACxB;AAGA,eAAe,oCAAwD;AAMtE,QAAM,SAAS,MAAM,KAAK,KAAqB;AAAA,IAC9C,MAAM;AAAA,EACP,CAAE;AACF,MAAI,sBAA8B;AAClC,MAAK,UAAU,OAAO,QAAS;AAC9B,UAAM,eAAsC,OAAO;AAAA,MAClD,CAAE,EAAE,OAAO,MAAO,WAAW;AAAA,IAC9B;AAEA,UAAM,kBACL,cAAc,SAAU,uBAAwB,IAAK,CAAE,GAAG;AAC3D,QAAK,iBAAkB;AACtB,4BAAsB,iBAAiB;AAAA,QACtC;AAAA,MACD,EAAG,CAAE;AAAA,IACN;AAAA,EACD;AACA,SAAO;AACR;AAQA,eAAe,8BAEd,UACC;AAED,SAAO,MAAM,KAAK,KAAoC;AAAA,IACrD,MAAM,wBAAyB,QAAS;AAAA,IACxC,QAAQ;AAAA,MACP,UAAU;AAAA,IACX;AAAA,EACD,CAAE;AACH;",
6
+ "names": []
7
+ }
@@ -1,81 +1,83 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createUser = createUser;
4
- exports.deleteAllUsers = deleteAllUsers;
5
- /**
6
- * List all users.
7
- *
8
- * @see https://developer.wordpress.org/rest-api/reference/users/#list-users
9
- * @param this
10
- */
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/e2e-test-utils-playwright/src/request-utils/users.ts
21
+ var users_exports = {};
22
+ __export(users_exports, {
23
+ createUser: () => createUser,
24
+ deleteAllUsers: () => deleteAllUsers
25
+ });
26
+ module.exports = __toCommonJS(users_exports);
11
27
  async function listUsers() {
12
- const response = await this.rest({
13
- method: 'GET',
14
- path: '/wp/v2/users',
15
- params: {
16
- per_page: 100,
17
- },
18
- });
19
- return response;
28
+ const response = await this.rest({
29
+ method: "GET",
30
+ path: "/wp/v2/users",
31
+ params: {
32
+ per_page: 100
33
+ }
34
+ });
35
+ return response;
20
36
  }
21
- /**
22
- * Add a test user.
23
- *
24
- * @see https://developer.wordpress.org/rest-api/reference/users/#create-a-user
25
- * @param this
26
- * @param user User data to create.
27
- */
28
37
  async function createUser(user) {
29
- const userData = {
30
- username: user.username,
31
- email: user.email,
32
- };
33
- if (user.firstName) {
34
- userData.first_name = user.firstName;
35
- }
36
- if (user.lastName) {
37
- userData.last_name = user.lastName;
38
- }
39
- if (user.password) {
40
- userData.password = user.password;
41
- }
42
- if (user.roles) {
43
- userData.roles = user.roles;
44
- }
45
- const response = await this.rest({
46
- method: 'POST',
47
- path: '/wp/v2/users',
48
- data: userData,
49
- });
50
- return response;
38
+ const userData = {
39
+ username: user.username,
40
+ email: user.email
41
+ };
42
+ if (user.firstName) {
43
+ userData.first_name = user.firstName;
44
+ }
45
+ if (user.lastName) {
46
+ userData.last_name = user.lastName;
47
+ }
48
+ if (user.password) {
49
+ userData.password = user.password;
50
+ }
51
+ if (user.roles) {
52
+ userData.roles = user.roles;
53
+ }
54
+ const response = await this.rest({
55
+ method: "POST",
56
+ path: "/wp/v2/users",
57
+ data: userData
58
+ });
59
+ return response;
51
60
  }
52
- /**
53
- * Delete a user.
54
- *
55
- * @see https://developer.wordpress.org/rest-api/reference/users/#delete-a-user
56
- * @param this
57
- * @param userId The ID of the user.
58
- */
59
61
  async function deleteUser(userId) {
60
- const response = await this.rest({
61
- method: 'DELETE',
62
- path: `/wp/v2/users/${userId}`,
63
- params: { force: true, reassign: 1 },
64
- });
65
- return response;
62
+ const response = await this.rest({
63
+ method: "DELETE",
64
+ path: `/wp/v2/users/${userId}`,
65
+ params: { force: true, reassign: 1 }
66
+ });
67
+ return response;
66
68
  }
67
- /**
68
- * Delete all users except main root user.
69
- *
70
- * @param this
71
- */
72
69
  async function deleteAllUsers() {
73
- const users = await listUsers.bind(this)();
74
- // The users endpoint doesn't support batch request yet.
75
- const responses = await Promise.all(users
76
- // Do not delete neither root user nor the current user.
77
- .filter((user) => user.id !== 1 && user.name !== this.user.username)
78
- .map((user) => deleteUser.bind(this)(user.id)));
79
- return responses;
70
+ const users = await listUsers.bind(this)();
71
+ const responses = await Promise.all(
72
+ users.filter(
73
+ (user) => user.id !== 1 && user.name !== this.user.username
74
+ ).map((user) => deleteUser.bind(this)(user.id))
75
+ );
76
+ return responses;
80
77
  }
81
- //# sourceMappingURL=users.js.map
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ createUser,
81
+ deleteAllUsers
82
+ });
83
+ //# sourceMappingURL=users.js.map
@@ -1 +1,7 @@
1
- {"version":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AE;QACjC,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,gBAAiB,MAAO,EAAE;QAChC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE;KACpC,CAAE,CAAC;IAEJ,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,cAAc;IAC5B,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,IAAI,CAAE,IAAI,CAAE,EAAE,CAAC;IAE7C,wDAAwD;IACxD,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,CAClC,KAAK;QACJ,wDAAwD;SACvD,MAAM,CACN,CAAE,IAAU,EAAG,EAAE,CAChB,IAAI,CAAC,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,QAAQ,CAClD;SACA,GAAG,CAAE,CAAE,IAAU,EAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAE,IAAI,CAAE,CAAE,IAAI,CAAC,EAAE,CAAE,CAAE,CAC7D,CAAC;IAEF,OAAO,SAAS,CAAC;AAClB,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/request-utils/users.ts"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RequestUtils } from './index';\n\nexport interface User {\n\tid: number;\n\tname: string;\n\temail: string;\n}\n\nexport interface UserData {\n\tusername: string;\n\temail: string;\n\tfirstName?: string;\n\tlastName?: string;\n\tpassword?: string;\n\troles?: string[];\n}\n\nexport interface UserRequestData {\n\tusername: string;\n\temail: string;\n\tfirst_name?: string;\n\tlast_name?: string;\n\tpassword?: string;\n\troles?: string[];\n}\n\n/**\n * List all users.\n *\n * @see https://developer.wordpress.org/rest-api/reference/users/#list-users\n * @param this\n */\nasync function listUsers( this: RequestUtils ) {\n\tconst response = await this.rest< User[] >( {\n\t\tmethod: 'GET',\n\t\tpath: '/wp/v2/users',\n\t\tparams: {\n\t\t\tper_page: 100,\n\t\t},\n\t} );\n\n\treturn response;\n}\n\n/**\n * Add a test user.\n *\n * @see https://developer.wordpress.org/rest-api/reference/users/#create-a-user\n * @param this\n * @param user User data to create.\n */\nasync function createUser( this: RequestUtils, user: UserData ) {\n\tconst userData: UserRequestData = {\n\t\tusername: user.username,\n\t\temail: user.email,\n\t};\n\n\tif ( user.firstName ) {\n\t\tuserData.first_name = user.firstName;\n\t}\n\n\tif ( user.lastName ) {\n\t\tuserData.last_name = user.lastName;\n\t}\n\n\tif ( user.password ) {\n\t\tuserData.password = user.password;\n\t}\n\n\tif ( user.roles ) {\n\t\tuserData.roles = user.roles;\n\t}\n\n\tconst response = await this.rest< User >( {\n\t\tmethod: 'POST',\n\t\tpath: '/wp/v2/users',\n\t\tdata: userData,\n\t} );\n\n\treturn response;\n}\n\n/**\n * Delete a user.\n *\n * @see https://developer.wordpress.org/rest-api/reference/users/#delete-a-user\n * @param this\n * @param userId The ID of the user.\n */\nasync function deleteUser( this: RequestUtils, userId: number ) {\n\tconst response = await this.rest( {\n\t\tmethod: 'DELETE',\n\t\tpath: `/wp/v2/users/${ userId }`,\n\t\tparams: { force: true, reassign: 1 },\n\t} );\n\n\treturn response;\n}\n\n/**\n * Delete all users except main root user.\n *\n * @param this\n */\nasync function deleteAllUsers( this: RequestUtils ) {\n\tconst users = await listUsers.bind( this )();\n\n\t// The users endpoint doesn't support batch request yet.\n\tconst responses = await Promise.all(\n\t\tusers\n\t\t\t// Do not delete neither root user nor the current user.\n\t\t\t.filter(\n\t\t\t\t( user: User ) =>\n\t\t\t\t\tuser.id !== 1 && user.name !== this.user.username\n\t\t\t)\n\t\t\t.map( ( user: User ) => deleteUser.bind( this )( user.id ) )\n\t);\n\n\treturn responses;\n}\n\nexport { createUser, deleteAllUsers };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCA,eAAe,YAAgC;AAC9C,QAAM,WAAW,MAAM,KAAK,KAAgB;AAAA,IAC3C,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,QAAQ;AAAA,MACP,UAAU;AAAA,IACX;AAAA,EACD,CAAE;AAEF,SAAO;AACR;AASA,eAAe,WAAgC,MAAiB;AAC/D,QAAM,WAA4B;AAAA,IACjC,UAAU,KAAK;AAAA,IACf,OAAO,KAAK;AAAA,EACb;AAEA,MAAK,KAAK,WAAY;AACrB,aAAS,aAAa,KAAK;AAAA,EAC5B;AAEA,MAAK,KAAK,UAAW;AACpB,aAAS,YAAY,KAAK;AAAA,EAC3B;AAEA,MAAK,KAAK,UAAW;AACpB,aAAS,WAAW,KAAK;AAAA,EAC1B;AAEA,MAAK,KAAK,OAAQ;AACjB,aAAS,QAAQ,KAAK;AAAA,EACvB;AAEA,QAAM,WAAW,MAAM,KAAK,KAAc;AAAA,IACzC,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,MAAM;AAAA,EACP,CAAE;AAEF,SAAO;AACR;AASA,eAAe,WAAgC,QAAiB;AAC/D,QAAM,WAAW,MAAM,KAAK,KAAM;AAAA,IACjC,QAAQ;AAAA,IACR,MAAM,gBAAiB,MAAO;AAAA,IAC9B,QAAQ,EAAE,OAAO,MAAM,UAAU,EAAE;AAAA,EACpC,CAAE;AAEF,SAAO;AACR;AAOA,eAAe,iBAAqC;AACnD,QAAM,QAAQ,MAAM,UAAU,KAAM,IAAK,EAAE;AAG3C,QAAM,YAAY,MAAM,QAAQ;AAAA,IAC/B,MAEE;AAAA,MACA,CAAE,SACD,KAAK,OAAO,KAAK,KAAK,SAAS,KAAK,KAAK;AAAA,IAC3C,EACC,IAAK,CAAE,SAAgB,WAAW,KAAM,IAAK,EAAG,KAAK,EAAG,CAAE;AAAA,EAC7D;AAEA,SAAO;AACR;",
6
+ "names": []
7
+ }
@@ -1,61 +1,79 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deleteAllWidgets = deleteAllWidgets;
4
- exports.addWidgetBlock = addWidgetBlock;
5
- /**
6
- * Delete all the widgets in the widgets screen.
7
- *
8
- * @this {import('./index').RequestUtils}
9
- */
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/e2e-test-utils-playwright/src/request-utils/widgets.js
21
+ var widgets_exports = {};
22
+ __export(widgets_exports, {
23
+ addWidgetBlock: () => addWidgetBlock,
24
+ deleteAllWidgets: () => deleteAllWidgets
25
+ });
26
+ module.exports = __toCommonJS(widgets_exports);
10
27
  async function deleteAllWidgets() {
11
- const [widgets, sidebars] = await Promise.all([
12
- this.rest({ path: '/wp/v2/widgets' }),
13
- this.rest({ path: '/wp/v2/sidebars' }),
14
- ]);
15
- await this.batchRest(widgets.map((widget) => ({
16
- method: 'DELETE',
17
- path: `/wp/v2/widgets/${widget.id}?force=true`,
18
- })));
19
- // The endpoint doesn't support batch requests yet.
20
- await Promise.all(sidebars.map((sidebar) => this.rest({
21
- method: 'POST',
28
+ const [widgets, sidebars] = await Promise.all([
29
+ this.rest({ path: "/wp/v2/widgets" }),
30
+ this.rest({ path: "/wp/v2/sidebars" })
31
+ ]);
32
+ await this.batchRest(
33
+ widgets.map((widget) => ({
34
+ method: "DELETE",
35
+ path: `/wp/v2/widgets/${widget.id}?force=true`
36
+ }))
37
+ );
38
+ await Promise.all(
39
+ sidebars.map(
40
+ (sidebar) => this.rest({
41
+ method: "POST",
22
42
  path: `/wp/v2/sidebars/${sidebar.id}`,
23
- data: { id: sidebar.id, widgets: [] },
24
- })));
43
+ data: { id: sidebar.id, widgets: [] }
44
+ })
45
+ )
46
+ );
25
47
  }
26
- /**
27
- * Add a widget block to the widget area.
28
- *
29
- * @this {import('./index').RequestUtils}
30
- * @param {string} serializedBlock The serialized content of the inserted block HTML.
31
- * @param {string} widgetAreaId The ID of the widget area.
32
- */
33
48
  async function addWidgetBlock(serializedBlock, widgetAreaId) {
34
- const { id: blockId } = await this.rest({
35
- method: 'POST',
36
- path: '/wp/v2/widgets',
37
- data: {
38
- id_base: 'block',
39
- sidebar: widgetAreaId,
40
- instance: {
41
- raw: { content: serializedBlock },
42
- },
43
- },
44
- });
45
- const { widgets } = await this.rest({
46
- path: `/wp/v2/sidebars/${widgetAreaId}`,
47
- });
48
- const updatedWidgets = new Set(widgets);
49
- // Remove duplicate.
50
- updatedWidgets.delete(blockId);
51
- // Add to last block.
52
- updatedWidgets.add(blockId);
53
- await this.rest({
54
- method: 'PUT',
55
- path: `/wp/v2/sidebars/${widgetAreaId}`,
56
- data: {
57
- widgets: [...updatedWidgets],
58
- },
59
- });
49
+ const { id: blockId } = await this.rest({
50
+ method: "POST",
51
+ path: "/wp/v2/widgets",
52
+ data: {
53
+ id_base: "block",
54
+ sidebar: widgetAreaId,
55
+ instance: {
56
+ raw: { content: serializedBlock }
57
+ }
58
+ }
59
+ });
60
+ const { widgets } = await this.rest({
61
+ path: `/wp/v2/sidebars/${widgetAreaId}`
62
+ });
63
+ const updatedWidgets = new Set(widgets);
64
+ updatedWidgets.delete(blockId);
65
+ updatedWidgets.add(blockId);
66
+ await this.rest({
67
+ method: "PUT",
68
+ path: `/wp/v2/sidebars/${widgetAreaId}`,
69
+ data: {
70
+ widgets: [...updatedWidgets]
71
+ }
72
+ });
60
73
  }
61
- //# sourceMappingURL=widgets.js.map
74
+ // Annotate the CommonJS export names for ESM import in node:
75
+ 0 && (module.exports = {
76
+ addWidgetBlock,
77
+ deleteAllWidgets
78
+ });
79
+ //# sourceMappingURL=widgets.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"widgets.js","sourceRoot":"","sources":["../../src/request-utils/widgets.js"],"names":[],"mappings":";;AAKA,4CAuBC;AASD,wCA8BC;AAnED;;;;GAIG;AACI,KAAK,UAAU,gBAAgB;IACrC,MAAM,CAAE,OAAO,EAAE,QAAQ,CAAE,GAAG,MAAM,OAAO,CAAC,GAAG,CAAE;QAChD,IAAI,CAAC,IAAI,CAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAE;QACvC,IAAI,CAAC,IAAI,CAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAE;KACxC,CAAE,CAAC;IAEJ,MAAM,IAAI,CAAC,SAAS,CACnB,OAAO,CAAC,GAAG,CAAE,CAAE,MAAM,EAAG,EAAE,CAAC,CAAE;QAC5B,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,kBAAmB,MAAM,CAAC,EAAG,aAAa;KAChD,CAAE,CAAE,CACL,CAAC;IAEF,mDAAmD;IACnD,MAAM,OAAO,CAAC,GAAG,CAChB,QAAQ,CAAC,GAAG,CAAE,CAAE,OAAO,EAAG,EAAE,CAC3B,IAAI,CAAC,IAAI,CAAE;QACV,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,mBAAoB,OAAO,CAAC,EAAG,EAAE;QACvC,IAAI,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;KACrC,CAAE,CACH,CACD,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,cAAc,CAAE,eAAe,EAAE,YAAY;IAClE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAE;QACxC,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE;YACL,OAAO,EAAE,OAAO;YAChB,OAAO,EAAE,YAAY;YACrB,QAAQ,EAAE;gBACT,GAAG,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE;aACjC;SACD;KACD,CAAE,CAAC;IAEJ,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAE;QACpC,IAAI,EAAE,mBAAoB,YAAa,EAAE;KACzC,CAAE,CAAC;IAEJ,MAAM,cAAc,GAAG,IAAI,GAAG,CAAE,OAAO,CAAE,CAAC;IAC1C,oBAAoB;IACpB,cAAc,CAAC,MAAM,CAAE,OAAO,CAAE,CAAC;IACjC,qBAAqB;IACrB,cAAc,CAAC,GAAG,CAAE,OAAO,CAAE,CAAC;IAE9B,MAAM,IAAI,CAAC,IAAI,CAAE;QAChB,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,mBAAoB,YAAa,EAAE;QACzC,IAAI,EAAE;YACL,OAAO,EAAE,CAAE,GAAG,cAAc,CAAE;SAC9B;KACD,CAAE,CAAC;AACL,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/request-utils/widgets.js"],
4
+ "sourcesContent": ["/**\n * Delete all the widgets in the widgets screen.\n *\n * @this {import('./index').RequestUtils}\n */\nexport async function deleteAllWidgets() {\n\tconst [ widgets, sidebars ] = await Promise.all( [\n\t\tthis.rest( { path: '/wp/v2/widgets' } ),\n\t\tthis.rest( { path: '/wp/v2/sidebars' } ),\n\t] );\n\n\tawait this.batchRest(\n\t\twidgets.map( ( widget ) => ( {\n\t\t\tmethod: 'DELETE',\n\t\t\tpath: `/wp/v2/widgets/${ widget.id }?force=true`,\n\t\t} ) )\n\t);\n\n\t// The endpoint doesn't support batch requests yet.\n\tawait Promise.all(\n\t\tsidebars.map( ( sidebar ) =>\n\t\t\tthis.rest( {\n\t\t\t\tmethod: 'POST',\n\t\t\t\tpath: `/wp/v2/sidebars/${ sidebar.id }`,\n\t\t\t\tdata: { id: sidebar.id, widgets: [] },\n\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Add a widget block to the widget area.\n *\n * @this {import('./index').RequestUtils}\n * @param {string} serializedBlock The serialized content of the inserted block HTML.\n * @param {string} widgetAreaId The ID of the widget area.\n */\nexport async function addWidgetBlock( serializedBlock, widgetAreaId ) {\n\tconst { id: blockId } = await this.rest( {\n\t\tmethod: 'POST',\n\t\tpath: '/wp/v2/widgets',\n\t\tdata: {\n\t\t\tid_base: 'block',\n\t\t\tsidebar: widgetAreaId,\n\t\t\tinstance: {\n\t\t\t\traw: { content: serializedBlock },\n\t\t\t},\n\t\t},\n\t} );\n\n\tconst { widgets } = await this.rest( {\n\t\tpath: `/wp/v2/sidebars/${ widgetAreaId }`,\n\t} );\n\n\tconst updatedWidgets = new Set( widgets );\n\t// Remove duplicate.\n\tupdatedWidgets.delete( blockId );\n\t// Add to last block.\n\tupdatedWidgets.add( blockId );\n\n\tawait this.rest( {\n\t\tmethod: 'PUT',\n\t\tpath: `/wp/v2/sidebars/${ widgetAreaId }`,\n\t\tdata: {\n\t\t\twidgets: [ ...updatedWidgets ],\n\t\t},\n\t} );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,eAAsB,mBAAmB;AACxC,QAAM,CAAE,SAAS,QAAS,IAAI,MAAM,QAAQ,IAAK;AAAA,IAChD,KAAK,KAAM,EAAE,MAAM,iBAAiB,CAAE;AAAA,IACtC,KAAK,KAAM,EAAE,MAAM,kBAAkB,CAAE;AAAA,EACxC,CAAE;AAEF,QAAM,KAAK;AAAA,IACV,QAAQ,IAAK,CAAE,YAAc;AAAA,MAC5B,QAAQ;AAAA,MACR,MAAM,kBAAmB,OAAO,EAAG;AAAA,IACpC,EAAI;AAAA,EACL;AAGA,QAAM,QAAQ;AAAA,IACb,SAAS;AAAA,MAAK,CAAE,YACf,KAAK,KAAM;AAAA,QACV,QAAQ;AAAA,QACR,MA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