@wordpress/widgets 4.32.0 → 4.32.1-next.ff1cebbba.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 (86) hide show
  1. package/build/blocks/legacy-widget/block.json +29 -0
  2. package/build/blocks/legacy-widget/edit/control.js +137 -167
  3. package/build/blocks/legacy-widget/edit/control.js.map +7 -1
  4. package/build/blocks/legacy-widget/edit/convert-to-blocks-button.js +51 -39
  5. package/build/blocks/legacy-widget/edit/convert-to-blocks-button.js.map +7 -1
  6. package/build/blocks/legacy-widget/edit/form.js +105 -75
  7. package/build/blocks/legacy-widget/edit/form.js.map +7 -1
  8. package/build/blocks/legacy-widget/edit/index.js +121 -131
  9. package/build/blocks/legacy-widget/edit/index.js.map +7 -1
  10. package/build/blocks/legacy-widget/edit/inspector-card.js +28 -20
  11. package/build/blocks/legacy-widget/edit/inspector-card.js.map +7 -1
  12. package/build/blocks/legacy-widget/edit/no-preview.js +29 -23
  13. package/build/blocks/legacy-widget/edit/no-preview.js.map +7 -1
  14. package/build/blocks/legacy-widget/edit/preview.js +107 -108
  15. package/build/blocks/legacy-widget/edit/preview.js.map +7 -1
  16. package/build/blocks/legacy-widget/edit/widget-type-selector.js +61 -52
  17. package/build/blocks/legacy-widget/edit/widget-type-selector.js.map +7 -1
  18. package/build/blocks/legacy-widget/index.js +49 -53
  19. package/build/blocks/legacy-widget/index.js.map +7 -1
  20. package/build/blocks/legacy-widget/transforms.js +189 -198
  21. package/build/blocks/legacy-widget/transforms.js.map +7 -1
  22. package/build/blocks/widget-group/block.json +20 -0
  23. package/build/blocks/widget-group/deprecated.js +38 -24
  24. package/build/blocks/widget-group/deprecated.js.map +7 -1
  25. package/build/blocks/widget-group/edit.js +63 -67
  26. package/build/blocks/widget-group/edit.js.map +7 -1
  27. package/build/blocks/widget-group/index.js +93 -80
  28. package/build/blocks/widget-group/index.js.map +7 -1
  29. package/build/blocks/widget-group/save.js +36 -25
  30. package/build/blocks/widget-group/save.js.map +7 -1
  31. package/build/components/index.js +36 -12
  32. package/build/components/index.js.map +7 -1
  33. package/build/components/move-to-widget-area/index.js +48 -37
  34. package/build/components/move-to-widget-area/index.js.map +7 -1
  35. package/build/index.js +67 -98
  36. package/build/index.js.map +7 -1
  37. package/build/register-legacy-widget-variations.js +42 -30
  38. package/build/register-legacy-widget-variations.js.map +7 -1
  39. package/build/utils.js +29 -29
  40. package/build/utils.js.map +7 -1
  41. package/build-module/blocks/legacy-widget/block.json +29 -0
  42. package/build-module/blocks/legacy-widget/edit/control.js +107 -158
  43. package/build-module/blocks/legacy-widget/edit/control.js.map +7 -1
  44. package/build-module/blocks/legacy-widget/edit/convert-to-blocks-button.js +33 -33
  45. package/build-module/blocks/legacy-widget/edit/convert-to-blocks-button.js.map +7 -1
  46. package/build-module/blocks/legacy-widget/edit/form.js +75 -64
  47. package/build-module/blocks/legacy-widget/edit/form.js.map +7 -1
  48. package/build-module/blocks/legacy-widget/edit/index.js +96 -122
  49. package/build-module/blocks/legacy-widget/edit/index.js.map +7 -1
  50. package/build-module/blocks/legacy-widget/edit/inspector-card.js +10 -15
  51. package/build-module/blocks/legacy-widget/edit/inspector-card.js.map +7 -1
  52. package/build-module/blocks/legacy-widget/edit/no-preview.js +11 -17
  53. package/build-module/blocks/legacy-widget/edit/no-preview.js.map +7 -1
  54. package/build-module/blocks/legacy-widget/edit/preview.js +76 -98
  55. package/build-module/blocks/legacy-widget/edit/preview.js.map +7 -1
  56. package/build-module/blocks/legacy-widget/edit/widget-type-selector.js +43 -46
  57. package/build-module/blocks/legacy-widget/edit/widget-type-selector.js.map +7 -1
  58. package/build-module/blocks/legacy-widget/index.js +12 -45
  59. package/build-module/blocks/legacy-widget/index.js.map +7 -1
  60. package/build-module/blocks/legacy-widget/transforms.js +171 -192
  61. package/build-module/blocks/legacy-widget/transforms.js.map +7 -1
  62. package/build-module/blocks/widget-group/block.json +20 -0
  63. package/build-module/blocks/widget-group/deprecated.js +20 -18
  64. package/build-module/blocks/widget-group/deprecated.js.map +7 -1
  65. package/build-module/blocks/widget-group/edit.js +53 -62
  66. package/build-module/blocks/widget-group/edit.js.map +7 -1
  67. package/build-module/blocks/widget-group/index.js +55 -71
  68. package/build-module/blocks/widget-group/index.js.map +7 -1
  69. package/build-module/blocks/widget-group/save.js +18 -19
  70. package/build-module/blocks/widget-group/save.js.map +7 -1
  71. package/build-module/components/index.js +5 -2
  72. package/build-module/components/index.js.map +7 -1
  73. package/build-module/components/move-to-widget-area/index.js +37 -32
  74. package/build-module/components/move-to-widget-area/index.js.map +7 -1
  75. package/build-module/index.js +34 -60
  76. package/build-module/index.js.map +7 -1
  77. package/build-module/register-legacy-widget-variations.js +24 -24
  78. package/build-module/register-legacy-widget-variations.js.map +7 -1
  79. package/build-module/utils.js +8 -25
  80. package/build-module/utils.js.map +7 -1
  81. package/build-style/style-rtl.css +10 -145
  82. package/build-style/style.css +10 -145
  83. package/package.json +21 -14
  84. package/src/blocks/legacy-widget/editor.scss +3 -0
  85. package/src/blocks/widget-group/editor.scss +3 -0
  86. package/src/style.scss +3 -2
@@ -0,0 +1,29 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 3,
4
+ "name": "core/legacy-widget",
5
+ "title": "Legacy Widget",
6
+ "category": "widgets",
7
+ "description": "Display a legacy widget.",
8
+ "textdomain": "default",
9
+ "attributes": {
10
+ "id": {
11
+ "type": "string",
12
+ "default": null
13
+ },
14
+ "idBase": {
15
+ "type": "string",
16
+ "default": null
17
+ },
18
+ "instance": {
19
+ "type": "object",
20
+ "default": null
21
+ }
22
+ },
23
+ "supports": {
24
+ "html": false,
25
+ "customClassName": false,
26
+ "reusable": false
27
+ },
28
+ "editorStyle": "wp-block-legacy-widget-editor"
29
+ }
@@ -1,27 +1,38 @@
1
- /* wp:polyfill */
2
- "use strict";
3
-
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var control_exports = {};
29
+ __export(control_exports, {
30
+ default: () => Control
7
31
  });
8
- exports.default = void 0;
9
- var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
10
- var _compose = require("@wordpress/compose");
11
- var _i18n = require("@wordpress/i18n");
12
- /**
13
- * WordPress dependencies
14
- */
15
-
16
- /**
17
- * An API for creating and loading a widget control (a <div class="widget">
18
- * element) that is compatible with most third party widget scripts. By not
19
- * using React for this, we ensure that we have complete control over the DOM
20
- * and do not accidentally remove any elements that a third party widget script
21
- * has attached an event listener to.
22
- *
23
- * @property {Element} element The control's DOM element.
24
- */
32
+ module.exports = __toCommonJS(control_exports);
33
+ var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
34
+ var import_compose = require("@wordpress/compose");
35
+ var import_i18n = require("@wordpress/i18n");
25
36
  class Control {
26
37
  /**
27
38
  * Creates and loads a new control.
@@ -50,18 +61,16 @@ class Control {
50
61
  this.onChangeInstance = onChangeInstance;
51
62
  this.onChangeHasPreview = onChangeHasPreview;
52
63
  this.onError = onError;
53
-
54
- // We can't use the real widget number as this is calculated by the
55
- // server and we may not ever *actually* save this widget. Instead, use
56
- // a fake but unique number.
57
64
  this.number = ++lastNumber;
58
- this.handleFormChange = (0, _compose.debounce)(this.handleFormChange.bind(this), 200);
65
+ this.handleFormChange = (0, import_compose.debounce)(
66
+ this.handleFormChange.bind(this),
67
+ 200
68
+ );
59
69
  this.handleFormSubmit = this.handleFormSubmit.bind(this);
60
70
  this.initDOM();
61
71
  this.bindEvents();
62
72
  this.loadContent();
63
73
  }
64
-
65
74
  /**
66
75
  * Clean up the control so that it can be garbage collected.
67
76
  *
@@ -70,84 +79,79 @@ class Control {
70
79
  destroy() {
71
80
  this.unbindEvents();
72
81
  this.element.remove();
73
- // TODO: How do we make third party widget scripts remove their event
74
- // listeners?
75
82
  }
76
-
77
83
  /**
78
84
  * Creates the control's DOM structure.
79
85
  *
80
86
  * @access private
81
87
  */
82
88
  initDOM() {
83
- var _this$id, _this$idBase;
84
- this.element = el('div', {
85
- class: 'widget open'
86
- }, [el('div', {
87
- class: 'widget-inside'
88
- }, [this.form = el('form', {
89
- class: 'form',
90
- method: 'post'
91
- }, [
92
- // These hidden form inputs are what most widgets' scripts
93
- // use to access data about the widget.
94
- el('input', {
95
- class: 'widget-id',
96
- type: 'hidden',
97
- name: 'widget-id',
98
- value: (_this$id = this.id) !== null && _this$id !== void 0 ? _this$id : `${this.idBase}-${this.number}`
99
- }), el('input', {
100
- class: 'id_base',
101
- type: 'hidden',
102
- name: 'id_base',
103
- value: (_this$idBase = this.idBase) !== null && _this$idBase !== void 0 ? _this$idBase : this.id
104
- }), el('input', {
105
- class: 'widget-width',
106
- type: 'hidden',
107
- name: 'widget-width',
108
- value: '250'
109
- }), el('input', {
110
- class: 'widget-height',
111
- type: 'hidden',
112
- name: 'widget-height',
113
- value: '200'
114
- }), el('input', {
115
- class: 'widget_number',
116
- type: 'hidden',
117
- name: 'widget_number',
118
- value: this.idBase ? this.number.toString() : ''
119
- }), this.content = el('div', {
120
- class: 'widget-content'
121
- }),
122
- // Non-multi widgets can be saved via a Save button.
123
- this.id && el('button', {
124
- class: 'button is-primary',
125
- type: 'submit'
126
- }, (0, _i18n.__)('Save'))])])]);
89
+ this.element = el("div", { class: "widget open" }, [
90
+ el("div", { class: "widget-inside" }, [
91
+ this.form = el("form", { class: "form", method: "post" }, [
92
+ // These hidden form inputs are what most widgets' scripts
93
+ // use to access data about the widget.
94
+ el("input", {
95
+ class: "widget-id",
96
+ type: "hidden",
97
+ name: "widget-id",
98
+ value: this.id ?? `${this.idBase}-${this.number}`
99
+ }),
100
+ el("input", {
101
+ class: "id_base",
102
+ type: "hidden",
103
+ name: "id_base",
104
+ value: this.idBase ?? this.id
105
+ }),
106
+ el("input", {
107
+ class: "widget-width",
108
+ type: "hidden",
109
+ name: "widget-width",
110
+ value: "250"
111
+ }),
112
+ el("input", {
113
+ class: "widget-height",
114
+ type: "hidden",
115
+ name: "widget-height",
116
+ value: "200"
117
+ }),
118
+ el("input", {
119
+ class: "widget_number",
120
+ type: "hidden",
121
+ name: "widget_number",
122
+ value: this.idBase ? this.number.toString() : ""
123
+ }),
124
+ this.content = el("div", { class: "widget-content" }),
125
+ // Non-multi widgets can be saved via a Save button.
126
+ this.id && el(
127
+ "button",
128
+ {
129
+ class: "button is-primary",
130
+ type: "submit"
131
+ },
132
+ (0, import_i18n.__)("Save")
133
+ )
134
+ ])
135
+ ])
136
+ ]);
127
137
  }
128
-
129
138
  /**
130
139
  * Adds the control's event listeners.
131
140
  *
132
141
  * @access private
133
142
  */
134
143
  bindEvents() {
135
- // Prefer jQuery 'change' event instead of the native 'change' event
136
- // because many widgets use jQuery's event bus to trigger an update.
137
144
  if (window.jQuery) {
138
- const {
139
- jQuery: $
140
- } = window;
141
- $(this.form).on('change', null, this.handleFormChange);
142
- $(this.form).on('input', null, this.handleFormChange);
143
- $(this.form).on('submit', this.handleFormSubmit);
145
+ const { jQuery: $ } = window;
146
+ $(this.form).on("change", null, this.handleFormChange);
147
+ $(this.form).on("input", null, this.handleFormChange);
148
+ $(this.form).on("submit", this.handleFormSubmit);
144
149
  } else {
145
- this.form.addEventListener('change', this.handleFormChange);
146
- this.form.addEventListener('input', this.handleFormChange);
147
- this.form.addEventListener('submit', this.handleFormSubmit);
150
+ this.form.addEventListener("change", this.handleFormChange);
151
+ this.form.addEventListener("input", this.handleFormChange);
152
+ this.form.addEventListener("submit", this.handleFormSubmit);
148
153
  }
149
154
  }
150
-
151
155
  /**
152
156
  * Removes the control's event listeners.
153
157
  *
@@ -155,19 +159,16 @@ class Control {
155
159
  */
156
160
  unbindEvents() {
157
161
  if (window.jQuery) {
158
- const {
159
- jQuery: $
160
- } = window;
161
- $(this.form).off('change', null, this.handleFormChange);
162
- $(this.form).off('input', null, this.handleFormChange);
163
- $(this.form).off('submit', this.handleFormSubmit);
162
+ const { jQuery: $ } = window;
163
+ $(this.form).off("change", null, this.handleFormChange);
164
+ $(this.form).off("input", null, this.handleFormChange);
165
+ $(this.form).off("submit", this.handleFormSubmit);
164
166
  } else {
165
- this.form.removeEventListener('change', this.handleFormChange);
166
- this.form.removeEventListener('input', this.handleFormChange);
167
- this.form.removeEventListener('submit', this.handleFormSubmit);
167
+ this.form.removeEventListener("change", this.handleFormChange);
168
+ this.form.removeEventListener("input", this.handleFormChange);
169
+ this.form.removeEventListener("submit", this.handleFormSubmit);
168
170
  }
169
171
  }
170
-
171
172
  /**
172
173
  * Fetches the widget's form HTML from the REST API and loads it into the
173
174
  * control's form.
@@ -177,28 +178,18 @@ class Control {
177
178
  async loadContent() {
178
179
  try {
179
180
  if (this.id) {
180
- const {
181
- form
182
- } = await saveWidget(this.id);
181
+ const { form } = await saveWidget(this.id);
183
182
  this.content.innerHTML = form;
184
183
  } else if (this.idBase) {
185
- const {
186
- form,
187
- preview
188
- } = await encodeWidget({
184
+ const { form, preview } = await encodeWidget({
189
185
  idBase: this.idBase,
190
186
  instance: this.instance,
191
187
  number: this.number
192
188
  });
193
189
  this.content.innerHTML = form;
194
190
  this.hasPreview = !isEmptyHTML(preview);
195
-
196
- // If we don't have an instance, perform a save right away. This
197
- // happens when creating a new Legacy Widget block.
198
191
  if (!this.instance.hash) {
199
- const {
200
- instance
201
- } = await encodeWidget({
192
+ const { instance } = await encodeWidget({
202
193
  idBase: this.idBase,
203
194
  instance: this.instance,
204
195
  number: this.number,
@@ -207,23 +198,14 @@ class Control {
207
198
  this.instance = instance;
208
199
  }
209
200
  }
210
-
211
- // Trigger 'widget-added' when widget is ready. This event is what
212
- // widgets' scripts use to initialize, attach events, etc. The event
213
- // must be fired using jQuery's event bus as this is what widget
214
- // scripts expect. If jQuery is not loaded, do nothing - some
215
- // widgets will still work regardless.
216
201
  if (window.jQuery) {
217
- const {
218
- jQuery: $
219
- } = window;
220
- $(document).trigger('widget-added', [$(this.element)]);
202
+ const { jQuery: $ } = window;
203
+ $(document).trigger("widget-added", [$(this.element)]);
221
204
  }
222
205
  } catch (error) {
223
206
  this.onError(error);
224
207
  }
225
208
  }
226
-
227
209
  /**
228
210
  * Perform a save when a multi widget's form is changed. Non-multi widgets
229
211
  * are saved manually.
@@ -235,7 +217,6 @@ class Control {
235
217
  this.saveForm();
236
218
  }
237
219
  }
238
-
239
220
  /**
240
221
  * Perform a save when the control's form is manually submitted.
241
222
  *
@@ -246,7 +227,6 @@ class Control {
246
227
  event.preventDefault();
247
228
  this.saveForm();
248
229
  }
249
-
250
230
  /**
251
231
  * Serialize the control's form, send it to the REST API, and update the
252
232
  * instance with the encoded instance that the REST API returns.
@@ -257,21 +237,16 @@ class Control {
257
237
  const formData = serializeForm(this.form);
258
238
  try {
259
239
  if (this.id) {
260
- const {
261
- form
262
- } = await saveWidget(this.id, formData);
240
+ const { form } = await saveWidget(this.id, formData);
263
241
  this.content.innerHTML = form;
264
242
  if (window.jQuery) {
265
- const {
266
- jQuery: $
267
- } = window;
268
- $(document).trigger('widget-updated', [$(this.element)]);
243
+ const { jQuery: $ } = window;
244
+ $(document).trigger("widget-updated", [
245
+ $(this.element)
246
+ ]);
269
247
  }
270
248
  } else if (this.idBase) {
271
- const {
272
- instance,
273
- preview
274
- } = await encodeWidget({
249
+ const { instance, preview } = await encodeWidget({
275
250
  idBase: this.idBase,
276
251
  instance: this.instance,
277
252
  number: this.number,
@@ -284,7 +259,6 @@ class Control {
284
259
  this.onError(error);
285
260
  }
286
261
  }
287
-
288
262
  /**
289
263
  * The widget's instance object.
290
264
  *
@@ -293,7 +267,6 @@ class Control {
293
267
  get instance() {
294
268
  return this._instance;
295
269
  }
296
-
297
270
  /**
298
271
  * The widget's instance object.
299
272
  *
@@ -305,7 +278,6 @@ class Control {
305
278
  this.onChangeInstance(instance);
306
279
  }
307
280
  }
308
-
309
281
  /**
310
282
  * Whether or not the widget can be previewed.
311
283
  *
@@ -314,7 +286,6 @@ class Control {
314
286
  get hasPreview() {
315
287
  return this._hasPreview;
316
288
  }
317
-
318
289
  /**
319
290
  * Whether or not the widget can be previewed.
320
291
  *
@@ -327,7 +298,6 @@ class Control {
327
298
  }
328
299
  }
329
300
  }
330
- exports.default = Control;
331
301
  let lastNumber = 0;
332
302
  function el(tagName, attributes = {}, content = null) {
333
303
  const element = document.createElement(tagName);
@@ -340,7 +310,7 @@ function el(tagName, attributes = {}, content = null) {
340
310
  element.appendChild(child);
341
311
  }
342
312
  }
343
- } else if (typeof content === 'string') {
313
+ } else if (typeof content === "string") {
344
314
  element.innerText = content;
345
315
  }
346
316
  return element;
@@ -348,32 +318,25 @@ function el(tagName, attributes = {}, content = null) {
348
318
  async function saveWidget(id, formData = null) {
349
319
  let widget;
350
320
  if (formData) {
351
- widget = await (0, _apiFetch.default)({
321
+ widget = await (0, import_api_fetch.default)({
352
322
  path: `/wp/v2/widgets/${id}?context=edit`,
353
- method: 'PUT',
323
+ method: "PUT",
354
324
  data: {
355
325
  form_data: formData
356
326
  }
357
327
  });
358
328
  } else {
359
- widget = await (0, _apiFetch.default)({
329
+ widget = await (0, import_api_fetch.default)({
360
330
  path: `/wp/v2/widgets/${id}?context=edit`,
361
- method: 'GET'
331
+ method: "GET"
362
332
  });
363
333
  }
364
- return {
365
- form: widget.rendered_form
366
- };
334
+ return { form: widget.rendered_form };
367
335
  }
368
- async function encodeWidget({
369
- idBase,
370
- instance,
371
- number,
372
- formData = null
373
- }) {
374
- const response = await (0, _apiFetch.default)({
336
+ async function encodeWidget({ idBase, instance, number, formData = null }) {
337
+ const response = await (0, import_api_fetch.default)({
375
338
  path: `/wp/v2/widget-types/${idBase}/encode`,
376
- method: 'POST',
339
+ method: "POST",
377
340
  data: {
378
341
  instance,
379
342
  number,
@@ -387,32 +350,39 @@ async function encodeWidget({
387
350
  };
388
351
  }
389
352
  function isEmptyHTML(html) {
390
- const element = document.createElement('div');
353
+ const element = document.createElement("div");
391
354
  element.innerHTML = html;
392
355
  return isEmptyNode(element);
393
356
  }
394
357
  function isEmptyNode(node) {
395
358
  switch (node.nodeType) {
396
359
  case node.TEXT_NODE:
397
- // Text nodes are empty if it's entirely whitespace.
398
- return node.nodeValue.trim() === '';
360
+ return node.nodeValue.trim() === "";
399
361
  case node.ELEMENT_NODE:
400
- // Elements that are "embedded content" are not empty.
401
- // https://dev.w3.org/html5/spec-LC/content-models.html#embedded-content-0
402
- if (['AUDIO', 'CANVAS', 'EMBED', 'IFRAME', 'IMG', 'MATH', 'OBJECT', 'SVG', 'VIDEO'].includes(node.tagName)) {
362
+ if ([
363
+ "AUDIO",
364
+ "CANVAS",
365
+ "EMBED",
366
+ "IFRAME",
367
+ "IMG",
368
+ "MATH",
369
+ "OBJECT",
370
+ "SVG",
371
+ "VIDEO"
372
+ ].includes(node.tagName)) {
403
373
  return false;
404
374
  }
405
- // Elements with no children are empty.
406
375
  if (!node.hasChildNodes()) {
407
376
  return true;
408
377
  }
409
- // Elements with children are empty if all their children are empty.
410
378
  return Array.from(node.childNodes).every(isEmptyNode);
411
379
  default:
412
380
  return true;
413
381
  }
414
382
  }
415
383
  function serializeForm(form) {
416
- return new window.URLSearchParams(Array.from(new window.FormData(form))).toString();
384
+ return new window.URLSearchParams(
385
+ Array.from(new window.FormData(form))
386
+ ).toString();
417
387
  }
418
- //# sourceMappingURL=control.js.map
388
+ //# sourceMappingURL=control.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_apiFetch","_interopRequireDefault","require","_compose","_i18n","Control","constructor","id","idBase","instance","onChangeInstance","onChangeHasPreview","onError","_instance","_hasPreview","number","lastNumber","handleFormChange","debounce","bind","handleFormSubmit","initDOM","bindEvents","loadContent","destroy","unbindEvents","element","remove","_this$id","_this$idBase","el","class","form","method","type","name","value","toString","content","__","window","jQuery","$","on","addEventListener","off","removeEventListener","saveWidget","innerHTML","preview","encodeWidget","hasPreview","isEmptyHTML","hash","formData","serializeForm","document","trigger","error","saveForm","event","preventDefault","exports","default","tagName","attributes","createElement","attribute","Object","entries","setAttribute","Array","isArray","child","appendChild","innerText","widget","apiFetch","path","data","form_data","rendered_form","response","html","isEmptyNode","node","nodeType","TEXT_NODE","nodeValue","trim","ELEMENT_NODE","includes","hasChildNodes","from","childNodes","every","URLSearchParams","FormData"],"sources":["@wordpress/widgets/src/blocks/legacy-widget/edit/control.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { debounce } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * An API for creating and loading a widget control (a <div class=\"widget\">\n * element) that is compatible with most third party widget scripts. By not\n * using React for this, we ensure that we have complete control over the DOM\n * and do not accidentally remove any elements that a third party widget script\n * has attached an event listener to.\n *\n * @property {Element} element The control's DOM element.\n */\nexport default class Control {\n\t/**\n\t * Creates and loads a new control.\n\t *\n\t * @access public\n\t * @param {Object} params\n\t * @param {string} params.id\n\t * @param {string} params.idBase\n\t * @param {Object} params.instance\n\t * @param {Function} params.onChangeInstance\n\t * @param {Function} params.onChangeHasPreview\n\t * @param {Function} params.onError\n\t */\n\tconstructor( {\n\t\tid,\n\t\tidBase,\n\t\tinstance,\n\t\tonChangeInstance,\n\t\tonChangeHasPreview,\n\t\tonError,\n\t} ) {\n\t\tthis.id = id;\n\t\tthis.idBase = idBase;\n\t\tthis._instance = instance;\n\t\tthis._hasPreview = null;\n\t\tthis.onChangeInstance = onChangeInstance;\n\t\tthis.onChangeHasPreview = onChangeHasPreview;\n\t\tthis.onError = onError;\n\n\t\t// We can't use the real widget number as this is calculated by the\n\t\t// server and we may not ever *actually* save this widget. Instead, use\n\t\t// a fake but unique number.\n\t\tthis.number = ++lastNumber;\n\n\t\tthis.handleFormChange = debounce(\n\t\t\tthis.handleFormChange.bind( this ),\n\t\t\t200\n\t\t);\n\t\tthis.handleFormSubmit = this.handleFormSubmit.bind( this );\n\n\t\tthis.initDOM();\n\t\tthis.bindEvents();\n\t\tthis.loadContent();\n\t}\n\n\t/**\n\t * Clean up the control so that it can be garbage collected.\n\t *\n\t * @access public\n\t */\n\tdestroy() {\n\t\tthis.unbindEvents();\n\t\tthis.element.remove();\n\t\t// TODO: How do we make third party widget scripts remove their event\n\t\t// listeners?\n\t}\n\n\t/**\n\t * Creates the control's DOM structure.\n\t *\n\t * @access private\n\t */\n\tinitDOM() {\n\t\tthis.element = el( 'div', { class: 'widget open' }, [\n\t\t\tel( 'div', { class: 'widget-inside' }, [\n\t\t\t\t( this.form = el( 'form', { class: 'form', method: 'post' }, [\n\t\t\t\t\t// These hidden form inputs are what most widgets' scripts\n\t\t\t\t\t// use to access data about the widget.\n\t\t\t\t\tel( 'input', {\n\t\t\t\t\t\tclass: 'widget-id',\n\t\t\t\t\t\ttype: 'hidden',\n\t\t\t\t\t\tname: 'widget-id',\n\t\t\t\t\t\tvalue: this.id ?? `${ this.idBase }-${ this.number }`,\n\t\t\t\t\t} ),\n\t\t\t\t\tel( 'input', {\n\t\t\t\t\t\tclass: 'id_base',\n\t\t\t\t\t\ttype: 'hidden',\n\t\t\t\t\t\tname: 'id_base',\n\t\t\t\t\t\tvalue: this.idBase ?? this.id,\n\t\t\t\t\t} ),\n\t\t\t\t\tel( 'input', {\n\t\t\t\t\t\tclass: 'widget-width',\n\t\t\t\t\t\ttype: 'hidden',\n\t\t\t\t\t\tname: 'widget-width',\n\t\t\t\t\t\tvalue: '250',\n\t\t\t\t\t} ),\n\t\t\t\t\tel( 'input', {\n\t\t\t\t\t\tclass: 'widget-height',\n\t\t\t\t\t\ttype: 'hidden',\n\t\t\t\t\t\tname: 'widget-height',\n\t\t\t\t\t\tvalue: '200',\n\t\t\t\t\t} ),\n\t\t\t\t\tel( 'input', {\n\t\t\t\t\t\tclass: 'widget_number',\n\t\t\t\t\t\ttype: 'hidden',\n\t\t\t\t\t\tname: 'widget_number',\n\t\t\t\t\t\tvalue: this.idBase ? this.number.toString() : '',\n\t\t\t\t\t} ),\n\t\t\t\t\t( this.content = el( 'div', { class: 'widget-content' } ) ),\n\t\t\t\t\t// Non-multi widgets can be saved via a Save button.\n\t\t\t\t\tthis.id &&\n\t\t\t\t\t\tel(\n\t\t\t\t\t\t\t'button',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tclass: 'button is-primary',\n\t\t\t\t\t\t\t\ttype: 'submit',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t__( 'Save' )\n\t\t\t\t\t\t),\n\t\t\t\t] ) ),\n\t\t\t] ),\n\t\t] );\n\t}\n\n\t/**\n\t * Adds the control's event listeners.\n\t *\n\t * @access private\n\t */\n\tbindEvents() {\n\t\t// Prefer jQuery 'change' event instead of the native 'change' event\n\t\t// because many widgets use jQuery's event bus to trigger an update.\n\t\tif ( window.jQuery ) {\n\t\t\tconst { jQuery: $ } = window;\n\t\t\t$( this.form ).on( 'change', null, this.handleFormChange );\n\t\t\t$( this.form ).on( 'input', null, this.handleFormChange );\n\t\t\t$( this.form ).on( 'submit', this.handleFormSubmit );\n\t\t} else {\n\t\t\tthis.form.addEventListener( 'change', this.handleFormChange );\n\t\t\tthis.form.addEventListener( 'input', this.handleFormChange );\n\t\t\tthis.form.addEventListener( 'submit', this.handleFormSubmit );\n\t\t}\n\t}\n\n\t/**\n\t * Removes the control's event listeners.\n\t *\n\t * @access private\n\t */\n\tunbindEvents() {\n\t\tif ( window.jQuery ) {\n\t\t\tconst { jQuery: $ } = window;\n\t\t\t$( this.form ).off( 'change', null, this.handleFormChange );\n\t\t\t$( this.form ).off( 'input', null, this.handleFormChange );\n\t\t\t$( this.form ).off( 'submit', this.handleFormSubmit );\n\t\t} else {\n\t\t\tthis.form.removeEventListener( 'change', this.handleFormChange );\n\t\t\tthis.form.removeEventListener( 'input', this.handleFormChange );\n\t\t\tthis.form.removeEventListener( 'submit', this.handleFormSubmit );\n\t\t}\n\t}\n\n\t/**\n\t * Fetches the widget's form HTML from the REST API and loads it into the\n\t * control's form.\n\t *\n\t * @access private\n\t */\n\tasync loadContent() {\n\t\ttry {\n\t\t\tif ( this.id ) {\n\t\t\t\tconst { form } = await saveWidget( this.id );\n\t\t\t\tthis.content.innerHTML = form;\n\t\t\t} else if ( this.idBase ) {\n\t\t\t\tconst { form, preview } = await encodeWidget( {\n\t\t\t\t\tidBase: this.idBase,\n\t\t\t\t\tinstance: this.instance,\n\t\t\t\t\tnumber: this.number,\n\t\t\t\t} );\n\t\t\t\tthis.content.innerHTML = form;\n\t\t\t\tthis.hasPreview = ! isEmptyHTML( preview );\n\n\t\t\t\t// If we don't have an instance, perform a save right away. This\n\t\t\t\t// happens when creating a new Legacy Widget block.\n\t\t\t\tif ( ! this.instance.hash ) {\n\t\t\t\t\tconst { instance } = await encodeWidget( {\n\t\t\t\t\t\tidBase: this.idBase,\n\t\t\t\t\t\tinstance: this.instance,\n\t\t\t\t\t\tnumber: this.number,\n\t\t\t\t\t\tformData: serializeForm( this.form ),\n\t\t\t\t\t} );\n\t\t\t\t\tthis.instance = instance;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Trigger 'widget-added' when widget is ready. This event is what\n\t\t\t// widgets' scripts use to initialize, attach events, etc. The event\n\t\t\t// must be fired using jQuery's event bus as this is what widget\n\t\t\t// scripts expect. If jQuery is not loaded, do nothing - some\n\t\t\t// widgets will still work regardless.\n\t\t\tif ( window.jQuery ) {\n\t\t\t\tconst { jQuery: $ } = window;\n\t\t\t\t$( document ).trigger( 'widget-added', [ $( this.element ) ] );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\tthis.onError( error );\n\t\t}\n\t}\n\n\t/**\n\t * Perform a save when a multi widget's form is changed. Non-multi widgets\n\t * are saved manually.\n\t *\n\t * @access private\n\t */\n\thandleFormChange() {\n\t\tif ( this.idBase ) {\n\t\t\tthis.saveForm();\n\t\t}\n\t}\n\n\t/**\n\t * Perform a save when the control's form is manually submitted.\n\t *\n\t * @access private\n\t * @param {Event} event\n\t */\n\thandleFormSubmit( event ) {\n\t\tevent.preventDefault();\n\t\tthis.saveForm();\n\t}\n\n\t/**\n\t * Serialize the control's form, send it to the REST API, and update the\n\t * instance with the encoded instance that the REST API returns.\n\t *\n\t * @access private\n\t */\n\tasync saveForm() {\n\t\tconst formData = serializeForm( this.form );\n\n\t\ttry {\n\t\t\tif ( this.id ) {\n\t\t\t\tconst { form } = await saveWidget( this.id, formData );\n\t\t\t\tthis.content.innerHTML = form;\n\n\t\t\t\tif ( window.jQuery ) {\n\t\t\t\t\tconst { jQuery: $ } = window;\n\t\t\t\t\t$( document ).trigger( 'widget-updated', [\n\t\t\t\t\t\t$( this.element ),\n\t\t\t\t\t] );\n\t\t\t\t}\n\t\t\t} else if ( this.idBase ) {\n\t\t\t\tconst { instance, preview } = await encodeWidget( {\n\t\t\t\t\tidBase: this.idBase,\n\t\t\t\t\tinstance: this.instance,\n\t\t\t\t\tnumber: this.number,\n\t\t\t\t\tformData,\n\t\t\t\t} );\n\t\t\t\tthis.instance = instance;\n\t\t\t\tthis.hasPreview = ! isEmptyHTML( preview );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\tthis.onError( error );\n\t\t}\n\t}\n\n\t/**\n\t * The widget's instance object.\n\t *\n\t * @access private\n\t */\n\tget instance() {\n\t\treturn this._instance;\n\t}\n\n\t/**\n\t * The widget's instance object.\n\t *\n\t * @access private\n\t */\n\tset instance( instance ) {\n\t\tif ( this._instance !== instance ) {\n\t\t\tthis._instance = instance;\n\t\t\tthis.onChangeInstance( instance );\n\t\t}\n\t}\n\n\t/**\n\t * Whether or not the widget can be previewed.\n\t *\n\t * @access public\n\t */\n\tget hasPreview() {\n\t\treturn this._hasPreview;\n\t}\n\n\t/**\n\t * Whether or not the widget can be previewed.\n\t *\n\t * @access private\n\t */\n\tset hasPreview( hasPreview ) {\n\t\tif ( this._hasPreview !== hasPreview ) {\n\t\t\tthis._hasPreview = hasPreview;\n\t\t\tthis.onChangeHasPreview( hasPreview );\n\t\t}\n\t}\n}\n\nlet lastNumber = 0;\n\nfunction el( tagName, attributes = {}, content = null ) {\n\tconst element = document.createElement( tagName );\n\tfor ( const [ attribute, value ] of Object.entries( attributes ) ) {\n\t\telement.setAttribute( attribute, value );\n\t}\n\tif ( Array.isArray( content ) ) {\n\t\tfor ( const child of content ) {\n\t\t\tif ( child ) {\n\t\t\t\telement.appendChild( child );\n\t\t\t}\n\t\t}\n\t} else if ( typeof content === 'string' ) {\n\t\telement.innerText = content;\n\t}\n\treturn element;\n}\n\nasync function saveWidget( id, formData = null ) {\n\tlet widget;\n\tif ( formData ) {\n\t\twidget = await apiFetch( {\n\t\t\tpath: `/wp/v2/widgets/${ id }?context=edit`,\n\t\t\tmethod: 'PUT',\n\t\t\tdata: {\n\t\t\t\tform_data: formData,\n\t\t\t},\n\t\t} );\n\t} else {\n\t\twidget = await apiFetch( {\n\t\t\tpath: `/wp/v2/widgets/${ id }?context=edit`,\n\t\t\tmethod: 'GET',\n\t\t} );\n\t}\n\treturn { form: widget.rendered_form };\n}\n\nasync function encodeWidget( { idBase, instance, number, formData = null } ) {\n\tconst response = await apiFetch( {\n\t\tpath: `/wp/v2/widget-types/${ idBase }/encode`,\n\t\tmethod: 'POST',\n\t\tdata: {\n\t\t\tinstance,\n\t\t\tnumber,\n\t\t\tform_data: formData,\n\t\t},\n\t} );\n\treturn {\n\t\tinstance: response.instance,\n\t\tform: response.form,\n\t\tpreview: response.preview,\n\t};\n}\n\nfunction isEmptyHTML( html ) {\n\tconst element = document.createElement( 'div' );\n\telement.innerHTML = html;\n\treturn isEmptyNode( element );\n}\n\nfunction isEmptyNode( node ) {\n\tswitch ( node.nodeType ) {\n\t\tcase node.TEXT_NODE:\n\t\t\t// Text nodes are empty if it's entirely whitespace.\n\t\t\treturn node.nodeValue.trim() === '';\n\t\tcase node.ELEMENT_NODE:\n\t\t\t// Elements that are \"embedded content\" are not empty.\n\t\t\t// https://dev.w3.org/html5/spec-LC/content-models.html#embedded-content-0\n\t\t\tif (\n\t\t\t\t[\n\t\t\t\t\t'AUDIO',\n\t\t\t\t\t'CANVAS',\n\t\t\t\t\t'EMBED',\n\t\t\t\t\t'IFRAME',\n\t\t\t\t\t'IMG',\n\t\t\t\t\t'MATH',\n\t\t\t\t\t'OBJECT',\n\t\t\t\t\t'SVG',\n\t\t\t\t\t'VIDEO',\n\t\t\t\t].includes( node.tagName )\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t// Elements with no children are empty.\n\t\t\tif ( ! node.hasChildNodes() ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\t// Elements with children are empty if all their children are empty.\n\t\t\treturn Array.from( node.childNodes ).every( isEmptyNode );\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\nfunction serializeForm( form ) {\n\treturn new window.URLSearchParams(\n\t\tArray.from( new window.FormData( form ) )\n\t).toString();\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,SAAA,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R,KAAK,EACL,OAAO,CACP,CAACC,QAAQ,CAAEN,IAAI,CAACrB,OAAQ,CAAC,EACzB;QACD,OAAO,KAAK;MACb;MACA;MACA,IAAK,CAAEqB,IAAI,CAACO,aAAa,CAAC,CAAC,EAAG;QAC7B,OAAO,IAAI;MACZ;MACA;MACA,OAAOrB,KAAK,CAACsB,IAAI,CAAER,IAAI,CAACS,UAAW,CAAC,CAACC,KAAK,CAAEX,WAAY,CAAC;IAC1D;MACC,OAAO,IAAI;EACb;AACD;AAEA,SAAS7B,aAAaA,CAAEvB,IAAI,EAAG;EAC9B,OAAO,IAAIQ,MAAM,CAACwD,eAAe,CAChCzB,KAAK,CAACsB,IAAI,CAAE,IAAIrD,MAAM,CAACyD,QAAQ,CAAEjE,IAAK,CAAE,CACzC,CAAC,CAACK,QAAQ,CAAC,CAAC;AACb","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/blocks/legacy-widget/edit/control.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { debounce } from '@wordpress/compose';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * An API for creating and loading a widget control (a <div class=\"widget\">\n * element) that is compatible with most third party widget scripts. By not\n * using React for this, we ensure that we have complete control over the DOM\n * and do not accidentally remove any elements that a third party widget script\n * has attached an event listener to.\n *\n * @property {Element} element The control's DOM element.\n */\nexport default class Control {\n\t/**\n\t * Creates and loads a new control.\n\t *\n\t * @access public\n\t * @param {Object} params\n\t * @param {string} params.id\n\t * @param {string} params.idBase\n\t * @param {Object} params.instance\n\t * @param {Function} params.onChangeInstance\n\t * @param {Function} params.onChangeHasPreview\n\t * @param {Function} params.onError\n\t */\n\tconstructor( {\n\t\tid,\n\t\tidBase,\n\t\tinstance,\n\t\tonChangeInstance,\n\t\tonChangeHasPreview,\n\t\tonError,\n\t} ) {\n\t\tthis.id = id;\n\t\tthis.idBase = idBase;\n\t\tthis._instance = instance;\n\t\tthis._hasPreview = null;\n\t\tthis.onChangeInstance = onChangeInstance;\n\t\tthis.onChangeHasPreview = onChangeHasPreview;\n\t\tthis.onError = onError;\n\n\t\t// We can't use the real widget number as this is calculated by the\n\t\t// server and we may not ever *actually* save this widget. Instead, use\n\t\t// a fake but unique number.\n\t\tthis.number = ++lastNumber;\n\n\t\tthis.handleFormChange = debounce(\n\t\t\tthis.handleFormChange.bind( this ),\n\t\t\t200\n\t\t);\n\t\tthis.handleFormSubmit = this.handleFormSubmit.bind( this );\n\n\t\tthis.initDOM();\n\t\tthis.bindEvents();\n\t\tthis.loadContent();\n\t}\n\n\t/**\n\t * Clean up the control so that it can be garbage collected.\n\t *\n\t * @access public\n\t */\n\tdestroy() {\n\t\tthis.unbindEvents();\n\t\tthis.element.remove();\n\t\t// TODO: How do we make third party widget scripts remove their event\n\t\t// listeners?\n\t}\n\n\t/**\n\t * Creates the control's DOM structure.\n\t *\n\t * @access private\n\t */\n\tinitDOM() {\n\t\tthis.element = el( 'div', { class: 'widget open' }, [\n\t\t\tel( 'div', { class: 'widget-inside' }, [\n\t\t\t\t( this.form = el( 'form', { class: 'form', method: 'post' }, [\n\t\t\t\t\t// These hidden form inputs are what most widgets' scripts\n\t\t\t\t\t// use to access data about the widget.\n\t\t\t\t\tel( 'input', {\n\t\t\t\t\t\tclass: 'widget-id',\n\t\t\t\t\t\ttype: 'hidden',\n\t\t\t\t\t\tname: 'widget-id',\n\t\t\t\t\t\tvalue: this.id ?? `${ this.idBase }-${ this.number }`,\n\t\t\t\t\t} ),\n\t\t\t\t\tel( 'input', {\n\t\t\t\t\t\tclass: 'id_base',\n\t\t\t\t\t\ttype: 'hidden',\n\t\t\t\t\t\tname: 'id_base',\n\t\t\t\t\t\tvalue: this.idBase ?? this.id,\n\t\t\t\t\t} ),\n\t\t\t\t\tel( 'input', {\n\t\t\t\t\t\tclass: 'widget-width',\n\t\t\t\t\t\ttype: 'hidden',\n\t\t\t\t\t\tname: 'widget-width',\n\t\t\t\t\t\tvalue: '250',\n\t\t\t\t\t} ),\n\t\t\t\t\tel( 'input', {\n\t\t\t\t\t\tclass: 'widget-height',\n\t\t\t\t\t\ttype: 'hidden',\n\t\t\t\t\t\tname: 'widget-height',\n\t\t\t\t\t\tvalue: '200',\n\t\t\t\t\t} ),\n\t\t\t\t\tel( 'input', {\n\t\t\t\t\t\tclass: 'widget_number',\n\t\t\t\t\t\ttype: 'hidden',\n\t\t\t\t\t\tname: 'widget_number',\n\t\t\t\t\t\tvalue: this.idBase ? this.number.toString() : '',\n\t\t\t\t\t} ),\n\t\t\t\t\t( this.content = el( 'div', { class: 'widget-content' } ) ),\n\t\t\t\t\t// Non-multi widgets can be saved via a Save button.\n\t\t\t\t\tthis.id &&\n\t\t\t\t\t\tel(\n\t\t\t\t\t\t\t'button',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tclass: 'button is-primary',\n\t\t\t\t\t\t\t\ttype: 'submit',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t__( 'Save' )\n\t\t\t\t\t\t),\n\t\t\t\t] ) ),\n\t\t\t] ),\n\t\t] );\n\t}\n\n\t/**\n\t * Adds the control's event listeners.\n\t *\n\t * @access private\n\t */\n\tbindEvents() {\n\t\t// Prefer jQuery 'change' event instead of the native 'change' event\n\t\t// because many widgets use jQuery's event bus to trigger an update.\n\t\tif ( window.jQuery ) {\n\t\t\tconst { jQuery: $ } = window;\n\t\t\t$( this.form ).on( 'change', null, this.handleFormChange );\n\t\t\t$( this.form ).on( 'input', null, this.handleFormChange );\n\t\t\t$( this.form ).on( 'submit', this.handleFormSubmit );\n\t\t} else {\n\t\t\tthis.form.addEventListener( 'change', this.handleFormChange );\n\t\t\tthis.form.addEventListener( 'input', this.handleFormChange );\n\t\t\tthis.form.addEventListener( 'submit', this.handleFormSubmit );\n\t\t}\n\t}\n\n\t/**\n\t * Removes the control's event listeners.\n\t *\n\t * @access private\n\t */\n\tunbindEvents() {\n\t\tif ( window.jQuery ) {\n\t\t\tconst { jQuery: $ } = window;\n\t\t\t$( this.form ).off( 'change', null, this.handleFormChange );\n\t\t\t$( this.form ).off( 'input', null, this.handleFormChange );\n\t\t\t$( this.form ).off( 'submit', this.handleFormSubmit );\n\t\t} else {\n\t\t\tthis.form.removeEventListener( 'change', this.handleFormChange );\n\t\t\tthis.form.removeEventListener( 'input', this.handleFormChange );\n\t\t\tthis.form.removeEventListener( 'submit', this.handleFormSubmit );\n\t\t}\n\t}\n\n\t/**\n\t * Fetches the widget's form HTML from the REST API and loads it into the\n\t * control's form.\n\t *\n\t * @access private\n\t */\n\tasync loadContent() {\n\t\ttry {\n\t\t\tif ( this.id ) {\n\t\t\t\tconst { form } = await saveWidget( this.id );\n\t\t\t\tthis.content.innerHTML = form;\n\t\t\t} else if ( this.idBase ) {\n\t\t\t\tconst { form, preview } = await encodeWidget( {\n\t\t\t\t\tidBase: this.idBase,\n\t\t\t\t\tinstance: this.instance,\n\t\t\t\t\tnumber: this.number,\n\t\t\t\t} );\n\t\t\t\tthis.content.innerHTML = form;\n\t\t\t\tthis.hasPreview = ! isEmptyHTML( preview );\n\n\t\t\t\t// If we don't have an instance, perform a save right away. This\n\t\t\t\t// happens when creating a new Legacy Widget block.\n\t\t\t\tif ( ! this.instance.hash ) {\n\t\t\t\t\tconst { instance } = await encodeWidget( {\n\t\t\t\t\t\tidBase: this.idBase,\n\t\t\t\t\t\tinstance: this.instance,\n\t\t\t\t\t\tnumber: this.number,\n\t\t\t\t\t\tformData: serializeForm( this.form ),\n\t\t\t\t\t} );\n\t\t\t\t\tthis.instance = instance;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Trigger 'widget-added' when widget is ready. This event is what\n\t\t\t// widgets' scripts use to initialize, attach events, etc. The event\n\t\t\t// must be fired using jQuery's event bus as this is what widget\n\t\t\t// scripts expect. If jQuery is not loaded, do nothing - some\n\t\t\t// widgets will still work regardless.\n\t\t\tif ( window.jQuery ) {\n\t\t\t\tconst { jQuery: $ } = window;\n\t\t\t\t$( document ).trigger( 'widget-added', [ $( this.element ) ] );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\tthis.onError( error );\n\t\t}\n\t}\n\n\t/**\n\t * Perform a save when a multi widget's form is changed. Non-multi widgets\n\t * are saved manually.\n\t *\n\t * @access private\n\t */\n\thandleFormChange() {\n\t\tif ( this.idBase ) {\n\t\t\tthis.saveForm();\n\t\t}\n\t}\n\n\t/**\n\t * Perform a save when the control's form is manually submitted.\n\t *\n\t * @access private\n\t * @param {Event} event\n\t */\n\thandleFormSubmit( event ) {\n\t\tevent.preventDefault();\n\t\tthis.saveForm();\n\t}\n\n\t/**\n\t * Serialize the control's form, send it to the REST API, and update the\n\t * instance with the encoded instance that the REST API returns.\n\t *\n\t * @access private\n\t */\n\tasync saveForm() {\n\t\tconst formData = serializeForm( this.form );\n\n\t\ttry {\n\t\t\tif ( this.id ) {\n\t\t\t\tconst { form } = await saveWidget( this.id, formData );\n\t\t\t\tthis.content.innerHTML = form;\n\n\t\t\t\tif ( window.jQuery ) {\n\t\t\t\t\tconst { jQuery: $ } = window;\n\t\t\t\t\t$( document ).trigger( 'widget-updated', [\n\t\t\t\t\t\t$( this.element ),\n\t\t\t\t\t] );\n\t\t\t\t}\n\t\t\t} else if ( this.idBase ) {\n\t\t\t\tconst { instance, preview } = await encodeWidget( {\n\t\t\t\t\tidBase: this.idBase,\n\t\t\t\t\tinstance: this.instance,\n\t\t\t\t\tnumber: this.number,\n\t\t\t\t\tformData,\n\t\t\t\t} );\n\t\t\t\tthis.instance = instance;\n\t\t\t\tthis.hasPreview = ! isEmptyHTML( preview );\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\tthis.onError( error );\n\t\t}\n\t}\n\n\t/**\n\t * The widget's instance object.\n\t *\n\t * @access private\n\t */\n\tget instance() {\n\t\treturn this._instance;\n\t}\n\n\t/**\n\t * The widget's instance object.\n\t *\n\t * @access private\n\t */\n\tset instance( instance ) {\n\t\tif ( this._instance !== instance ) {\n\t\t\tthis._instance = instance;\n\t\t\tthis.onChangeInstance( instance );\n\t\t}\n\t}\n\n\t/**\n\t * Whether or not the widget can be previewed.\n\t *\n\t * @access public\n\t */\n\tget hasPreview() {\n\t\treturn this._hasPreview;\n\t}\n\n\t/**\n\t * Whether or not the widget can be previewed.\n\t *\n\t * @access private\n\t */\n\tset hasPreview( hasPreview ) {\n\t\tif ( this._hasPreview !== hasPreview ) {\n\t\t\tthis._hasPreview = hasPreview;\n\t\t\tthis.onChangeHasPreview( hasPreview );\n\t\t}\n\t}\n}\n\nlet lastNumber = 0;\n\nfunction el( tagName, attributes = {}, content = null ) {\n\tconst element = document.createElement( tagName );\n\tfor ( const [ attribute, value ] of Object.entries( attributes ) ) {\n\t\telement.setAttribute( attribute, value );\n\t}\n\tif ( Array.isArray( content ) ) {\n\t\tfor ( const child of content ) {\n\t\t\tif ( child ) {\n\t\t\t\telement.appendChild( child );\n\t\t\t}\n\t\t}\n\t} else if ( typeof content === 'string' ) {\n\t\telement.innerText = content;\n\t}\n\treturn element;\n}\n\nasync function saveWidget( id, formData = null ) {\n\tlet widget;\n\tif ( formData ) {\n\t\twidget = await apiFetch( {\n\t\t\tpath: `/wp/v2/widgets/${ id }?context=edit`,\n\t\t\tmethod: 'PUT',\n\t\t\tdata: {\n\t\t\t\tform_data: formData,\n\t\t\t},\n\t\t} );\n\t} else {\n\t\twidget = await apiFetch( {\n\t\t\tpath: `/wp/v2/widgets/${ id }?context=edit`,\n\t\t\tmethod: 'GET',\n\t\t} );\n\t}\n\treturn { form: widget.rendered_form };\n}\n\nasync function encodeWidget( { idBase, instance, number, formData = null } ) {\n\tconst response = await apiFetch( {\n\t\tpath: `/wp/v2/widget-types/${ idBase }/encode`,\n\t\tmethod: 'POST',\n\t\tdata: {\n\t\t\tinstance,\n\t\t\tnumber,\n\t\t\tform_data: formData,\n\t\t},\n\t} );\n\treturn {\n\t\tinstance: response.instance,\n\t\tform: response.form,\n\t\tpreview: response.preview,\n\t};\n}\n\nfunction isEmptyHTML( html ) {\n\tconst element = document.createElement( 'div' );\n\telement.innerHTML = html;\n\treturn isEmptyNode( element );\n}\n\nfunction isEmptyNode( node ) {\n\tswitch ( node.nodeType ) {\n\t\tcase node.TEXT_NODE:\n\t\t\t// Text nodes are empty if it's entirely whitespace.\n\t\t\treturn node.nodeValue.trim() === '';\n\t\tcase node.ELEMENT_NODE:\n\t\t\t// Elements that are \"embedded content\" are not empty.\n\t\t\t// https://dev.w3.org/html5/spec-LC/content-models.html#embedded-content-0\n\t\t\tif (\n\t\t\t\t[\n\t\t\t\t\t'AUDIO',\n\t\t\t\t\t'CANVAS',\n\t\t\t\t\t'EMBED',\n\t\t\t\t\t'IFRAME',\n\t\t\t\t\t'IMG',\n\t\t\t\t\t'MATH',\n\t\t\t\t\t'OBJECT',\n\t\t\t\t\t'SVG',\n\t\t\t\t\t'VIDEO',\n\t\t\t\t].includes( node.tagName )\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\t// Elements with no children are empty.\n\t\t\tif ( ! node.hasChildNodes() ) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\t// Elements with children are empty if all their children are empty.\n\t\t\treturn Array.from( node.childNodes ).every( isEmptyNode );\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n\nfunction serializeForm( form ) {\n\treturn new window.URLSearchParams(\n\t\tArray.from( new window.FormData( form ) )\n\t).toString();\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAqB;AACrB,qBAAyB;AACzB,kBAAmB;AAWnB,MAAO,QAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAa5B,YAAa;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,GAAI;AACH,SAAK,KAAK;AACV,SAAK,SAAS;AACd,SAAK,YAAY;AACj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