@wordpress/widgets 3.15.0 → 3.17.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 (76) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/blocks/legacy-widget/edit/control.js +31 -63
  3. package/build/blocks/legacy-widget/edit/control.js.map +1 -1
  4. package/build/blocks/legacy-widget/edit/convert-to-blocks-button.js +1 -7
  5. package/build/blocks/legacy-widget/edit/convert-to-blocks-button.js.map +1 -1
  6. package/build/blocks/legacy-widget/edit/form.js +5 -22
  7. package/build/blocks/legacy-widget/edit/form.js.map +1 -1
  8. package/build/blocks/legacy-widget/edit/index.js +7 -24
  9. package/build/blocks/legacy-widget/edit/index.js.map +1 -1
  10. package/build/blocks/legacy-widget/edit/inspector-card.js +0 -2
  11. package/build/blocks/legacy-widget/edit/inspector-card.js.map +1 -1
  12. package/build/blocks/legacy-widget/edit/no-preview.js +1 -3
  13. package/build/blocks/legacy-widget/edit/no-preview.js.map +1 -1
  14. package/build/blocks/legacy-widget/edit/preview.js +11 -21
  15. package/build/blocks/legacy-widget/edit/preview.js.map +1 -1
  16. package/build/blocks/legacy-widget/edit/widget-type-selector.js +1 -11
  17. package/build/blocks/legacy-widget/edit/widget-type-selector.js.map +1 -1
  18. package/build/blocks/legacy-widget/index.js +0 -6
  19. package/build/blocks/legacy-widget/index.js.map +1 -1
  20. package/build/blocks/legacy-widget/transforms.js +1 -4
  21. package/build/blocks/legacy-widget/transforms.js.map +1 -1
  22. package/build/blocks/widget-group/deprecated.js +1 -5
  23. package/build/blocks/widget-group/deprecated.js.map +1 -1
  24. package/build/blocks/widget-group/edit.js +7 -13
  25. package/build/blocks/widget-group/edit.js.map +1 -1
  26. package/build/blocks/widget-group/index.js +7 -16
  27. package/build/blocks/widget-group/index.js.map +1 -1
  28. package/build/blocks/widget-group/save.js +1 -3
  29. package/build/blocks/widget-group/save.js.map +1 -1
  30. package/build/components/index.js +0 -2
  31. package/build/components/index.js.map +1 -1
  32. package/build/components/move-to-widget-area/index.js +1 -5
  33. package/build/components/move-to-widget-area/index.js.map +1 -1
  34. package/build/index.js +9 -18
  35. package/build/index.js.map +1 -1
  36. package/build/register-legacy-widget-variations.js +1 -6
  37. package/build/register-legacy-widget-variations.js.map +1 -1
  38. package/build/utils.js +5 -5
  39. package/build/utils.js.map +1 -1
  40. package/build-module/blocks/legacy-widget/edit/control.js +32 -58
  41. package/build-module/blocks/legacy-widget/edit/control.js.map +1 -1
  42. package/build-module/blocks/legacy-widget/edit/convert-to-blocks-button.js +0 -1
  43. package/build-module/blocks/legacy-widget/edit/convert-to-blocks-button.js.map +1 -1
  44. package/build-module/blocks/legacy-widget/edit/form.js +4 -15
  45. package/build-module/blocks/legacy-widget/edit/form.js.map +1 -1
  46. package/build-module/blocks/legacy-widget/edit/index.js +8 -11
  47. package/build-module/blocks/legacy-widget/edit/index.js.map +1 -1
  48. package/build-module/blocks/legacy-widget/edit/inspector-card.js.map +1 -1
  49. package/build-module/blocks/legacy-widget/edit/no-preview.js +0 -1
  50. package/build-module/blocks/legacy-widget/edit/no-preview.js.map +1 -1
  51. package/build-module/blocks/legacy-widget/edit/preview.js +11 -15
  52. package/build-module/blocks/legacy-widget/edit/preview.js.map +1 -1
  53. package/build-module/blocks/legacy-widget/edit/widget-type-selector.js +0 -5
  54. package/build-module/blocks/legacy-widget/edit/widget-type-selector.js.map +1 -1
  55. package/build-module/blocks/legacy-widget/index.js +1 -1
  56. package/build-module/blocks/legacy-widget/index.js.map +1 -1
  57. package/build-module/blocks/legacy-widget/transforms.js +0 -2
  58. package/build-module/blocks/legacy-widget/transforms.js.map +1 -1
  59. package/build-module/blocks/widget-group/deprecated.js +0 -3
  60. package/build-module/blocks/widget-group/deprecated.js.map +1 -1
  61. package/build-module/blocks/widget-group/edit.js +6 -7
  62. package/build-module/blocks/widget-group/edit.js.map +1 -1
  63. package/build-module/blocks/widget-group/index.js +8 -8
  64. package/build-module/blocks/widget-group/index.js.map +1 -1
  65. package/build-module/blocks/widget-group/save.js +0 -1
  66. package/build-module/blocks/widget-group/save.js.map +1 -1
  67. package/build-module/components/index.js.map +1 -1
  68. package/build-module/components/move-to-widget-area/index.js +0 -1
  69. package/build-module/components/move-to-widget-area/index.js.map +1 -1
  70. package/build-module/index.js +11 -7
  71. package/build-module/index.js.map +1 -1
  72. package/build-module/register-legacy-widget-variations.js +0 -2
  73. package/build-module/register-legacy-widget-variations.js.map +1 -1
  74. package/build-module/utils.js +5 -3
  75. package/build-module/utils.js.map +1 -1
  76. package/package.json +13 -13
@@ -4,6 +4,7 @@
4
4
  import apiFetch from '@wordpress/api-fetch';
5
5
  import { debounce } from '@wordpress/compose';
6
6
  import { __ } from '@wordpress/i18n';
7
+
7
8
  /**
8
9
  * An API for creating and loading a widget control (a <div class="widget">
9
10
  * element) that is compatible with most third party widget scripts. By not
@@ -13,7 +14,6 @@ import { __ } from '@wordpress/i18n';
13
14
  *
14
15
  * @property {Element} element The control's DOM element.
15
16
  */
16
-
17
17
  export default class Control {
18
18
  /**
19
19
  * Creates and loads a new control.
@@ -41,10 +41,11 @@ export default class Control {
41
41
  this._hasPreview = null;
42
42
  this.onChangeInstance = onChangeInstance;
43
43
  this.onChangeHasPreview = onChangeHasPreview;
44
- this.onError = onError; // We can't use the real widget number as this is calculated by the
44
+ this.onError = onError;
45
+
46
+ // We can't use the real widget number as this is calculated by the
45
47
  // server and we may not ever *actually* save this widget. Instead, use
46
48
  // a fake but unique number.
47
-
48
49
  this.number = ++lastNumber;
49
50
  this.handleFormChange = debounce(this.handleFormChange.bind(this), 200);
50
51
  this.handleFormSubmit = this.handleFormSubmit.bind(this);
@@ -52,28 +53,26 @@ export default class Control {
52
53
  this.bindEvents();
53
54
  this.loadContent();
54
55
  }
56
+
55
57
  /**
56
58
  * Clean up the control so that it can be garabge collected.
57
59
  *
58
60
  * @access public
59
61
  */
60
-
61
-
62
62
  destroy() {
63
63
  this.unbindEvents();
64
- this.element.remove(); // TODO: How do we make third party widget scripts remove their event
64
+ this.element.remove();
65
+ // TODO: How do we make third party widget scripts remove their event
65
66
  // listeners?
66
67
  }
68
+
67
69
  /**
68
70
  * Creates the control's DOM structure.
69
71
  *
70
72
  * @access private
71
73
  */
72
-
73
-
74
74
  initDOM() {
75
75
  var _this$id, _this$idBase;
76
-
77
76
  this.element = el('div', {
78
77
  class: 'widget open'
79
78
  }, [el('div', {
@@ -81,7 +80,8 @@ export default class Control {
81
80
  }, [this.form = el('form', {
82
81
  class: 'form',
83
82
  method: 'post'
84
- }, [// These hidden form inputs are what most widgets' scripts
83
+ }, [
84
+ // These hidden form inputs are what most widgets' scripts
85
85
  // use to access data about the widget.
86
86
  el('input', {
87
87
  class: 'widget-id',
@@ -110,19 +110,19 @@ export default class Control {
110
110
  value: this.idBase ? this.number.toString() : ''
111
111
  }), this.content = el('div', {
112
112
  class: 'widget-content'
113
- }), // Non-multi widgets can be saved via a Save button.
113
+ }),
114
+ // Non-multi widgets can be saved via a Save button.
114
115
  this.id && el('button', {
115
116
  class: 'button is-primary',
116
117
  type: 'submit'
117
118
  }, __('Save'))])])]);
118
119
  }
120
+
119
121
  /**
120
122
  * Adds the control's event listeners.
121
123
  *
122
124
  * @access private
123
125
  */
124
-
125
-
126
126
  bindEvents() {
127
127
  // Prefer jQuery 'change' event instead of the native 'change' event
128
128
  // because many widgets use jQuery's event bus to trigger an update.
@@ -139,13 +139,12 @@ export default class Control {
139
139
  this.form.addEventListener('submit', this.handleFormSubmit);
140
140
  }
141
141
  }
142
+
142
143
  /**
143
144
  * Removes the control's event listeners.
144
145
  *
145
146
  * @access private
146
147
  */
147
-
148
-
149
148
  unbindEvents() {
150
149
  if (window.jQuery) {
151
150
  const {
@@ -160,14 +159,13 @@ export default class Control {
160
159
  this.form.removeEventListener('submit', this.handleFormSubmit);
161
160
  }
162
161
  }
162
+
163
163
  /**
164
164
  * Fetches the widget's form HTML from the REST API and loads it into the
165
165
  * control's form.
166
166
  *
167
167
  * @access private
168
168
  */
169
-
170
-
171
169
  async loadContent() {
172
170
  try {
173
171
  if (this.id) {
@@ -185,9 +183,10 @@ export default class Control {
185
183
  number: this.number
186
184
  });
187
185
  this.content.innerHTML = form;
188
- this.hasPreview = !isEmptyHTML(preview); // If we don't have an instance, perform a save right away. This
189
- // happens when creating a new Legacy Widget block.
186
+ this.hasPreview = !isEmptyHTML(preview);
190
187
 
188
+ // If we don't have an instance, perform a save right away. This
189
+ // happens when creating a new Legacy Widget block.
191
190
  if (!this.instance.hash) {
192
191
  const {
193
192
  instance
@@ -199,13 +198,13 @@ export default class Control {
199
198
  });
200
199
  this.instance = instance;
201
200
  }
202
- } // Trigger 'widget-added' when widget is ready. This event is what
201
+ }
202
+
203
+ // Trigger 'widget-added' when widget is ready. This event is what
203
204
  // widgets' scripts use to initialize, attach events, etc. The event
204
205
  // must be fired using jQuery's event bus as this is what widget
205
206
  // scripts expect. If jQuery is not loaded, do nothing - some
206
207
  // widgets will still work regardless.
207
-
208
-
209
208
  if (window.jQuery) {
210
209
  const {
211
210
  jQuery: $
@@ -216,49 +215,44 @@ export default class Control {
216
215
  this.onError(error);
217
216
  }
218
217
  }
218
+
219
219
  /**
220
220
  * Perform a save when a multi widget's form is changed. Non-multi widgets
221
221
  * are saved manually.
222
222
  *
223
223
  * @access private
224
224
  */
225
-
226
-
227
225
  handleFormChange() {
228
226
  if (this.idBase) {
229
227
  this.saveForm();
230
228
  }
231
229
  }
230
+
232
231
  /**
233
232
  * Perform a save when the control's form is manually submitted.
234
233
  *
235
234
  * @access private
236
235
  * @param {Event} event
237
236
  */
238
-
239
-
240
237
  handleFormSubmit(event) {
241
238
  event.preventDefault();
242
239
  this.saveForm();
243
240
  }
241
+
244
242
  /**
245
243
  * Serialize the control's form, send it to the REST API, and update the
246
244
  * instance with the encoded instance that the REST API returns.
247
245
  *
248
246
  * @access private
249
247
  */
250
-
251
-
252
248
  async saveForm() {
253
249
  const formData = serializeForm(this.form);
254
-
255
250
  try {
256
251
  if (this.id) {
257
252
  const {
258
253
  form
259
254
  } = await saveWidget(this.id, formData);
260
255
  this.content.innerHTML = form;
261
-
262
256
  if (window.jQuery) {
263
257
  const {
264
258
  jQuery: $
@@ -282,63 +276,55 @@ export default class Control {
282
276
  this.onError(error);
283
277
  }
284
278
  }
279
+
285
280
  /**
286
281
  * The widget's instance object.
287
282
  *
288
283
  * @access private
289
284
  */
290
-
291
-
292
285
  get instance() {
293
286
  return this._instance;
294
287
  }
288
+
295
289
  /**
296
290
  * The widget's instance object.
297
291
  *
298
292
  * @access private
299
293
  */
300
-
301
-
302
294
  set instance(instance) {
303
295
  if (this._instance !== instance) {
304
296
  this._instance = instance;
305
297
  this.onChangeInstance(instance);
306
298
  }
307
299
  }
300
+
308
301
  /**
309
302
  * Whether or not the widget can be previewed.
310
303
  *
311
304
  * @access public
312
305
  */
313
-
314
-
315
306
  get hasPreview() {
316
307
  return this._hasPreview;
317
308
  }
309
+
318
310
  /**
319
311
  * Whether or not the widget can be previewed.
320
312
  *
321
313
  * @access private
322
314
  */
323
-
324
-
325
315
  set hasPreview(hasPreview) {
326
316
  if (this._hasPreview !== hasPreview) {
327
317
  this._hasPreview = hasPreview;
328
318
  this.onChangeHasPreview(hasPreview);
329
319
  }
330
320
  }
331
-
332
321
  }
333
322
  let lastNumber = 0;
334
-
335
323
  function el(tagName, attributes = {}, content = null) {
336
324
  const element = document.createElement(tagName);
337
-
338
325
  for (const [attribute, value] of Object.entries(attributes)) {
339
326
  element.setAttribute(attribute, value);
340
327
  }
341
-
342
328
  if (Array.isArray(content)) {
343
329
  for (const child of content) {
344
330
  if (child) {
@@ -348,13 +334,10 @@ function el(tagName, attributes = {}, content = null) {
348
334
  } else if (typeof content === 'string') {
349
335
  element.innerText = content;
350
336
  }
351
-
352
337
  return element;
353
338
  }
354
-
355
339
  async function saveWidget(id, formData = null) {
356
340
  let widget;
357
-
358
341
  if (formData) {
359
342
  widget = await apiFetch({
360
343
  path: `/wp/v2/widgets/${id}?context=edit`,
@@ -369,12 +352,10 @@ async function saveWidget(id, formData = null) {
369
352
  method: 'GET'
370
353
  });
371
354
  }
372
-
373
355
  return {
374
356
  form: widget.rendered_form
375
357
  };
376
358
  }
377
-
378
359
  async function encodeWidget({
379
360
  idBase,
380
361
  instance,
@@ -396,39 +377,32 @@ async function encodeWidget({
396
377
  preview: response.preview
397
378
  };
398
379
  }
399
-
400
380
  function isEmptyHTML(html) {
401
381
  const element = document.createElement('div');
402
382
  element.innerHTML = html;
403
383
  return isEmptyNode(element);
404
384
  }
405
-
406
385
  function isEmptyNode(node) {
407
386
  switch (node.nodeType) {
408
387
  case node.TEXT_NODE:
409
388
  // Text nodes are empty if it's entirely whitespace.
410
389
  return node.nodeValue.trim() === '';
411
-
412
390
  case node.ELEMENT_NODE:
413
391
  // Elements that are "embedded content" are not empty.
414
392
  // https://dev.w3.org/html5/spec-LC/content-models.html#embedded-content-0
415
393
  if (['AUDIO', 'CANVAS', 'EMBED', 'IFRAME', 'IMG', 'MATH', 'OBJECT', 'SVG', 'VIDEO'].includes(node.tagName)) {
416
394
  return false;
417
- } // Elements with no children are empty.
418
-
419
-
395
+ }
396
+ // Elements with no children are empty.
420
397
  if (!node.hasChildNodes()) {
421
398
  return true;
422
- } // Elements with children are empty if all their children are empty.
423
-
424
-
399
+ }
400
+ // Elements with children are empty if all their children are empty.
425
401
  return Array.from(node.childNodes).every(isEmptyNode);
426
-
427
402
  default:
428
403
  return true;
429
404
  }
430
405
  }
431
-
432
406
  function serializeForm(form) {
433
407
  return new window.URLSearchParams(Array.from(new window.FormData(form))).toString();
434
408
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/widgets/src/blocks/legacy-widget/edit/control.js"],"names":["apiFetch","debounce","__","Control","constructor","id","idBase","instance","onChangeInstance","onChangeHasPreview","onError","_instance","_hasPreview","number","lastNumber","handleFormChange","bind","handleFormSubmit","initDOM","bindEvents","loadContent","destroy","unbindEvents","element","remove","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","tagName","attributes","createElement","attribute","Object","entries","setAttribute","Array","isArray","child","appendChild","innerText","widget","path","data","form_data","rendered_form","response","html","isEmptyNode","node","nodeType","TEXT_NODE","nodeValue","trim","ELEMENT_NODE","includes","hasChildNodes","from","childNodes","every","URLSearchParams","FormData"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,MAAMC,OAAN,CAAc;AAC5B;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACCC,EAAAA,WAAW,CAAE;AACZC,IAAAA,EADY;AAEZC,IAAAA,MAFY;AAGZC,IAAAA,QAHY;AAIZC,IAAAA,gBAJY;AAKZC,IAAAA,kBALY;AAMZC,IAAAA;AANY,GAAF,EAOP;AACH,SAAKL,EAAL,GAAUA,EAAV;AACA,SAAKC,MAAL,GAAcA,MAAd;AACA,SAAKK,SAAL,GAAiBJ,QAAjB;AACA,SAAKK,WAAL,GAAmB,IAAnB;AACA,SAAKJ,gBAAL,GAAwBA,gBAAxB;AACA,SAAKC,kBAAL,GAA0BA,kBAA1B;AACA,SAAKC,OAAL,GAAeA,OAAf,CAPG,CASH;AACA;AACA;;AACA,SAAKG,MAAL,GAAc,EAAEC,UAAhB;AAEA,SAAKC,gBAAL,GAAwBd,QAAQ,CAC/B,KAAKc,gBAAL,CAAsBC,IAAtB,CAA4B,IAA5B,CAD+B,EAE/B,GAF+B,CAAhC;AAIA,SAAKC,gBAAL,GAAwB,KAAKA,gBAAL,CAAsBD,IAAtB,CAA4B,IAA5B,CAAxB;AAEA,SAAKE,OAAL;AACA,SAAKC,UAAL;AACA,SAAKC,WAAL;AACA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C;AACA,aAAOF,IAAI,CAACG,SAAL,CAAeC,IAAf,OAA0B,EAAjC;;AACD,SAAKJ,IAAI,CAACK,YAAV;AACC;AACA;AACA,UACC,CACC,OADD,EAEC,QAFD,EAGC,OAHD,EAIC,QAJD,EAKC,KALD,EAMC,MAND,EAOC,QAPD,EAQC,KARD,EASC,OATD,EAUEC,QAVF,CAUYN,IAAI,CAACpB,OAVjB,CADD,EAYE;AACD,eAAO,KAAP;AACA,OAjBF,CAkBC;;;AACA,UAAK,CAAEoB,IAAI,CAACO,aAAL,EAAP,EAA8B;AAC7B,eAAO,IAAP;AACA,OArBF,CAsBC;;;AACA,aAAOpB,KAAK,CAACqB,IAAN,CAAYR,IAAI,CAACS,UAAjB,EAA8BC,KAA9B,CAAqCX,WAArC,CAAP;;AACD;AACC,aAAO,IAAP;AA7BF;AA+BA;;AAED,SAAS1B,aAAT,CAAwBtB,IAAxB,EAA+B;AAC9B,SAAO,IAAIO,MAAM,CAACqD,eAAX,CACNxB,KAAK,CAACqB,IAAN,CAAY,IAAIlD,MAAM,CAACsD,QAAX,CAAqB7D,IAArB,CAAZ,CADM,EAELK,QAFK,EAAP;AAGA","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 contorl 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 garabge 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"]}
1
+ {"version":3,"names":["apiFetch","debounce","__","Control","constructor","id","idBase","instance","onChangeInstance","onChangeHasPreview","onError","_instance","_hasPreview","number","lastNumber","handleFormChange","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","tagName","attributes","createElement","attribute","Object","entries","setAttribute","Array","isArray","child","appendChild","innerText","widget","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 contorl 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 garabge 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":"AAAA;AACA;AACA;AACA,OAAOA,QAAQ,MAAM,sBAAsB;AAC3C,SAASC,QAAQ,QAAQ,oBAAoB;AAC7C,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,OAAO,CAAC;EAC5B;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACCC,WAAWA,CAAE;IACZC,EAAE;IACFC,MAAM;IACNC,QAAQ;IACRC,gBAAgB;IAChBC,kBAAkB;IAClBC;EACD,CAAC,EAAG;IACH,IAAI,CAACL,EAAE,GAAGA,EAAE;IACZ,IAAI,CAACC,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACK,SAAS,GAAGJ,QAAQ;IACzB,IAAI,CAACK,WAAW,GAAG,IAAI;IACvB,IAAI,CAACJ,gBAAgB,GAAGA,gBAAgB;IACxC,IAAI,CAACC,kBAAkB,GAAGA,kBAAkB;IAC5C,IAAI,CAACC,OAAO,GAAGA,OAAO;;IAEtB;IACA;IACA;IACA,IAAI,CAACG,MAAM,GAA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AAWA,CAAE4B,IAAI,EAAG;EAC5B,MAAMrD,OAAO,GAAG6B,QAAQ,CAACQ,aAAa,CAAE,KAAM,CAAC;EAC/CrC,OAAO,CAACqB,SAAS,GAAGgC,IAAI;EACxB,OAAOC,WAAW,CAAEtD,OAAQ,CAAC;AAC9B;AAEA,SAASsD,WAAWA,CAAEC,IAAI,EAAG;EAC5B,QAASA,IAAI,CAACC,QAAQ;IACrB,KAAKD,IAAI,CAACE,SAAS;MAClB;MACA,OAAOF,IAAI,CAACG,SAAS,CAACC,IAAI,CAAC,CAAC,KAAK,EAAE;IACpC,KAAKJ,IAAI,CAACK,YAAY;MACrB;MACA;MACA,IACC,CACC,OAAO,EACP,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,KAAK,EACL,MAAM,EACN,QAAQ,EACR,KAAK,EACL,OAAO,CACP,CAACC,QAAQ,CAAEN,IAAI,CAACpB,OAAQ,CAAC,EACzB;QACD,OAAO,KAAK;MACb;MACA;MACA,IAAK,CAAEoB,IAAI,CAACO,aAAa,CAAC,CAAC,EAAG;QAC7B,OAAO,IAAI;MACZ;MACA;MACA,OAAOpB,KAAK,CAACqB,IAAI,CAAER,IAAI,CAACS,UAAW,CAAC,CAACC,KAAK,CAAEX,WAAY,CAAC;IAC1D;MACC,OAAO,IAAI;EACb;AACD;AAEA,SAAS1B,aAAaA,CAAEtB,IAAI,EAAG;EAC9B,OAAO,IAAIO,MAAM,CAACqD,eAAe,CAChCxB,KAAK,CAACqB,IAAI,CAAE,IAAIlD,MAAM,CAACsD,QAAQ,CAAE7D,IAAK,CAAE,CACzC,CAAC,CAACK,QAAQ,CAAC,CAAC;AACb"}
@@ -1,5 +1,4 @@
1
1
  import { createElement } from "@wordpress/element";
2
-
3
2
  /**
4
3
  * WordPress dependencies
5
4
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/widgets/src/blocks/legacy-widget/edit/convert-to-blocks-button.js"],"names":["useDispatch","store","blockEditorStore","ToolbarButton","createBlock","rawHandler","__","ConvertToBlocksButton","clientId","rawInstance","replaceBlocks","title","content","HTML","text"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,WAAT,QAA4B,iBAA5B;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,yBAA1C;AACA,SAASC,aAAT,QAA8B,uBAA9B;AACA,SAASC,WAAT,EAAsBC,UAAtB,QAAwC,mBAAxC;AACA,SAASC,EAAT,QAAmB,iBAAnB;AAEA,eAAe,SAASC,qBAAT,CAAgC;AAAEC,EAAAA,QAAF;AAAYC,EAAAA;AAAZ,CAAhC,EAA4D;AAC1E,QAAM;AAAEC,IAAAA;AAAF,MAAoBV,WAAW,CAAEE,gBAAF,CAArC;AAEA,SACC,cAAC,aAAD;AACC,IAAA,OAAO,EAAG,MAAM;AACf,UAAKO,WAAW,CAACE,KAAjB,EAAyB;AACxBD,QAAAA,aAAa,CAAEF,QAAF,EAAY,CACxBJ,WAAW,CAAE,cAAF,EAAkB;AAC5BQ,UAAAA,OAAO,EAAEH,WAAW,CAACE;AADO,SAAlB,CADa,EAIxB,GAAGN,UAAU,CAAE;AAAEQ,UAAAA,IAAI,EAAEJ,WAAW,CAACK;AAApB,SAAF,CAJW,CAAZ,CAAb;AAMA,OAPD,MAOO;AACNJ,QAAAA,aAAa,CACZF,QADY,EAEZH,UAAU,CAAE;AAAEQ,UAAAA,IAAI,EAAEJ,WAAW,CAACK;AAApB,SAAF,CAFE,CAAb;AAIA;AACD;AAfF,KAiBGR,EAAE,CAAE,mBAAF,CAjBL,CADD;AAqBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { ToolbarButton } from '@wordpress/components';\nimport { createBlock, rawHandler } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\nexport default function ConvertToBlocksButton( { clientId, rawInstance } ) {\n\tconst { replaceBlocks } = useDispatch( blockEditorStore );\n\n\treturn (\n\t\t<ToolbarButton\n\t\t\tonClick={ () => {\n\t\t\t\tif ( rawInstance.title ) {\n\t\t\t\t\treplaceBlocks( clientId, [\n\t\t\t\t\t\tcreateBlock( 'core/heading', {\n\t\t\t\t\t\t\tcontent: rawInstance.title,\n\t\t\t\t\t\t} ),\n\t\t\t\t\t\t...rawHandler( { HTML: rawInstance.text } ),\n\t\t\t\t\t] );\n\t\t\t\t} else {\n\t\t\t\t\treplaceBlocks(\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\trawHandler( { HTML: rawInstance.text } )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} }\n\t\t>\n\t\t\t{ __( 'Convert to blocks' ) }\n\t\t</ToolbarButton>\n\t);\n}\n"]}
1
+ {"version":3,"names":["useDispatch","store","blockEditorStore","ToolbarButton","createBlock","rawHandler","__","ConvertToBlocksButton","clientId","rawInstance","replaceBlocks","createElement","onClick","title","content","HTML","text"],"sources":["@wordpress/widgets/src/blocks/legacy-widget/edit/convert-to-blocks-button.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { ToolbarButton } from '@wordpress/components';\nimport { createBlock, rawHandler } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\nexport default function ConvertToBlocksButton( { clientId, rawInstance } ) {\n\tconst { replaceBlocks } = useDispatch( blockEditorStore );\n\n\treturn (\n\t\t<ToolbarButton\n\t\t\tonClick={ () => {\n\t\t\t\tif ( rawInstance.title ) {\n\t\t\t\t\treplaceBlocks( clientId, [\n\t\t\t\t\t\tcreateBlock( 'core/heading', {\n\t\t\t\t\t\t\tcontent: rawInstance.title,\n\t\t\t\t\t\t} ),\n\t\t\t\t\t\t...rawHandler( { HTML: rawInstance.text } ),\n\t\t\t\t\t] );\n\t\t\t\t} else {\n\t\t\t\t\treplaceBlocks(\n\t\t\t\t\t\tclientId,\n\t\t\t\t\t\trawHandler( { HTML: rawInstance.text } )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} }\n\t\t>\n\t\t\t{ __( 'Convert to blocks' ) }\n\t\t</ToolbarButton>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,aAAa,QAAQ,uBAAuB;AACrD,SAASC,WAAW,EAAEC,UAAU,QAAQ,mBAAmB;AAC3D,SAASC,EAAE,QAAQ,iBAAiB;AAEpC,eAAe,SAASC,qBAAqBA,CAAE;EAAEC,QAAQ;EAAEC;AAAY,CAAC,EAAG;EAC1E,MAAM;IAAEC;EAAc,CAAC,GAAGV,WAAW,CAAEE,gBAAiB,CAAC;EAEzD,OACCS,aAAA,CAACR,aAAa;IACbS,OAAO,EAAGA,CAAA,KAAM;MACf,IAAKH,WAAW,CAACI,KAAK,EAAG;QACxBH,aAAa,CAAEF,QAAQ,EAAE,CACxBJ,WAAW,CAAE,cAAc,EAAE;UAC5BU,OAAO,EAAEL,WAAW,CAACI;QACtB,CAAE,CAAC,EACH,GAAGR,UAAU,CAAE;UAAEU,IAAI,EAAEN,WAAW,CAACO;QAAK,CAAE,CAAC,CAC1C,CAAC;MACJ,CAAC,MAAM;QACNN,aAAa,CACZF,QAAQ,EACRH,UAAU,CAAE;UAAEU,IAAI,EAAEN,WAAW,CAACO;QAAK,CAAE,CACxC,CAAC;MACF;IACD;EAAG,GAEDV,EAAE,CAAE,mBAAoB,CACZ,CAAC;AAElB"}
@@ -1,5 +1,4 @@
1
1
  import { createElement } from "@wordpress/element";
2
-
3
2
  /**
4
3
  * External dependencies
5
4
  */
@@ -7,7 +6,6 @@ import classnames from 'classnames';
7
6
  /**
8
7
  * WordPress dependencies
9
8
  */
10
-
11
9
  import { useRef, useEffect } from '@wordpress/element';
12
10
  import { useDispatch } from '@wordpress/data';
13
11
  import { store as noticesStore } from '@wordpress/notices';
@@ -17,7 +15,6 @@ import { useViewportMatch } from '@wordpress/compose';
17
15
  /**
18
16
  * Internal dependencies
19
17
  */
20
-
21
18
  import Control from './control';
22
19
  export default function Form({
23
20
  title,
@@ -30,11 +27,12 @@ export default function Form({
30
27
  onChangeHasPreview
31
28
  }) {
32
29
  const ref = useRef();
33
- const isMediumLargeViewport = useViewportMatch('small'); // We only want to remount the control when the instance changes
30
+ const isMediumLargeViewport = useViewportMatch('small');
31
+
32
+ // We only want to remount the control when the instance changes
34
33
  // *externally*. For example, if the user performs an undo. To do this, we
35
34
  // keep track of changes made to instance by the control itself and then
36
35
  // ignore those.
37
-
38
36
  const outgoingInstances = useRef(new Set());
39
37
  const incomingInstances = useRef(new Set());
40
38
  const {
@@ -45,27 +43,21 @@ export default function Form({
45
43
  incomingInstances.current.delete(instance);
46
44
  return;
47
45
  }
48
-
49
46
  const control = new Control({
50
47
  id,
51
48
  idBase,
52
49
  instance,
53
-
54
50
  onChangeInstance(nextInstance) {
55
51
  outgoingInstances.current.add(instance);
56
52
  incomingInstances.current.add(nextInstance);
57
53
  onChangeInstance(nextInstance);
58
54
  },
59
-
60
55
  onChangeHasPreview,
61
-
62
56
  onError(error) {
63
57
  window.console.error(error);
64
- createNotice('error', sprintf(
65
- /* translators: %s: the name of the affected block. */
58
+ createNotice('error', sprintf( /* translators: %s: the name of the affected block. */
66
59
  __('The "%s" block was affected by errors and may not function properly. Check the developer tools for more details.'), idBase || id));
67
60
  }
68
-
69
61
  });
70
62
  ref.current.appendChild(control.element);
71
63
  return () => {
@@ -73,11 +65,9 @@ export default function Form({
73
65
  outgoingInstances.current.delete(instance);
74
66
  return;
75
67
  }
76
-
77
68
  control.destroy();
78
69
  };
79
70
  }, [id, idBase, instance, onChangeInstance, onChangeHasPreview, isMediumLargeViewport]);
80
-
81
71
  if (isWide && isMediumLargeViewport) {
82
72
  return createElement("div", {
83
73
  className: classnames({
@@ -98,7 +88,6 @@ export default function Form({
98
88
  hidden: !isVisible
99
89
  })));
100
90
  }
101
-
102
91
  return createElement("div", {
103
92
  ref: ref,
104
93
  className: "wp-block-legacy-widget__edit-form",
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/widgets/src/blocks/legacy-widget/edit/form.js"],"names":["classnames","useRef","useEffect","useDispatch","store","noticesStore","__","sprintf","Popover","useViewportMatch","Control","Form","title","isVisible","id","idBase","instance","isWide","onChangeInstance","onChangeHasPreview","ref","isMediumLargeViewport","outgoingInstances","Set","incomingInstances","createNotice","current","has","delete","control","nextInstance","add","onError","error","window","console","appendChild","element","destroy"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AACA;AACA;AACA;;AACA,SAASC,MAAT,EAAiBC,SAAjB,QAAkC,oBAAlC;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,KAAK,IAAIC,YAAlB,QAAsC,oBAAtC;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASC,OAAT,QAAwB,uBAAxB;AACA,SAASC,gBAAT,QAAiC,oBAAjC;AACA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AAEA,eAAe,SAASC,IAAT,CAAe;AAC7BC,EAAAA,KAD6B;AAE7BC,EAAAA,SAF6B;AAG7BC,EAAAA,EAH6B;AAI7BC,EAAAA,MAJ6B;AAK7BC,EAAAA,QAL6B;AAM7BC,EAAAA,MAN6B;AAO7BC,EAAAA,gBAP6B;AAQ7BC,EAAAA;AAR6B,CAAf,EASX;AACH,QAAMC,GAAG,GAAGnB,MAAM,EAAlB;AAEA,QAAMoB,qBAAqB,GAAGZ,gBAAgB,CAAE,OAAF,CAA9C,CAHG,CAKH;AACA;AACA;AACA;;AACA,QAAMa,iBAAiB,GAAGrB,MAAM,CAAE,IAAIsB,GAAJ,EAAF,CAAhC;AACA,QAAMC,iBAAiB,GAAGvB,MAAM,CAAE,IAAIsB,GAAJ,EAAF,CAAhC;AAEA,QAAM;AAAEE,IAAAA;AAAF,MAAmBtB,WAAW,CAAEE,YAAF,C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zCM,CAAT;;AAkDA,MAAKJ,MAAM,IAAII,qBAAf,EAAuC;AACtC,WACC;AACC,MAAA,SAAS,EAAGrB,UAAU,CAAE;AACvB,6CAAqCa;AADd,OAAF;AADvB,OAKGA,SAAS,IACV;AAAI,MAAA,SAAS,EAAC;AAAd,OACGD,KADH,CANF,EAUC,cAAC,OAAD;AACC,MAAA,YAAY,EAAG,KADhB;AAEC,MAAA,SAAS,EAAC,OAFX;AAGC,MAAA,MAAM,EAAG,EAHV;AAIC,MAAA,MAAM,EAAG,KAJV;AAKC,MAAA,IAAI,EAAG,KALR;AAMC,MAAA,KAAK;AANN,OAQC;AACC,MAAA,GAAG,EAAGQ,GADP;AAEC,MAAA,SAAS,EAAC,mCAFX;AAGC,MAAA,MAAM,EAAG,CAAEP;AAHZ,MARD,CAVD,CADD;AA2BA;;AAED,SACC;AACC,IAAA,GAAG,EAAGO,GADP;AAEC,IAAA,SAAS,EAAC,mCAFX;AAGC,IAAA,MAAM,EAAG,CAAEP;AAHZ,KAKC;AAAI,IAAA,SAAS,EAAC;AAAd,KACGD,KADH,CALD,CADD;AAWA","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n/**\n * WordPress dependencies\n */\nimport { useRef, useEffect } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Popover } from '@wordpress/components';\nimport { useViewportMatch } from '@wordpress/compose';\n/**\n * Internal dependencies\n */\nimport Control from './control';\n\nexport default function Form( {\n\ttitle,\n\tisVisible,\n\tid,\n\tidBase,\n\tinstance,\n\tisWide,\n\tonChangeInstance,\n\tonChangeHasPreview,\n} ) {\n\tconst ref = useRef();\n\n\tconst isMediumLargeViewport = useViewportMatch( 'small' );\n\n\t// We only want to remount the control when the instance changes\n\t// *externally*. For example, if the user performs an undo. To do this, we\n\t// keep track of changes made to instance by the control itself and then\n\t// ignore those.\n\tconst outgoingInstances = useRef( new Set() );\n\tconst incomingInstances = useRef( new Set() );\n\n\tconst { createNotice } = useDispatch( noticesStore );\n\n\tuseEffect( () => {\n\t\tif ( incomingInstances.current.has( instance ) ) {\n\t\t\tincomingInstances.current.delete( instance );\n\t\t\treturn;\n\t\t}\n\n\t\tconst control = new Control( {\n\t\t\tid,\n\t\t\tidBase,\n\t\t\tinstance,\n\t\t\tonChangeInstance( nextInstance ) {\n\t\t\t\toutgoingInstances.current.add( instance );\n\t\t\t\tincomingInstances.current.add( nextInstance );\n\t\t\t\tonChangeInstance( nextInstance );\n\t\t\t},\n\t\t\tonChangeHasPreview,\n\t\t\tonError( error ) {\n\t\t\t\twindow.console.error( error );\n\t\t\t\tcreateNotice(\n\t\t\t\t\t'error',\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: %s: the name of the affected block. */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'The \"%s\" block was affected by errors and may not function properly. Check the developer tools for more details.'\n\t\t\t\t\t\t),\n\t\t\t\t\t\tidBase || id\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t},\n\t\t} );\n\n\t\tref.current.appendChild( control.element );\n\n\t\treturn () => {\n\t\t\tif ( outgoingInstances.current.has( instance ) ) {\n\t\t\t\toutgoingInstances.current.delete( instance );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tcontrol.destroy();\n\t\t};\n\t}, [\n\t\tid,\n\t\tidBase,\n\t\tinstance,\n\t\tonChangeInstance,\n\t\tonChangeHasPreview,\n\t\tisMediumLargeViewport,\n\t] );\n\n\tif ( isWide && isMediumLargeViewport ) {\n\t\treturn (\n\t\t\t<div\n\t\t\t\tclassName={ classnames( {\n\t\t\t\t\t'wp-block-legacy-widget__container': isVisible,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t{ isVisible && (\n\t\t\t\t\t<h3 className=\"wp-block-legacy-widget__edit-form-title\">\n\t\t\t\t\t\t{ title }\n\t\t\t\t\t</h3>\n\t\t\t\t) }\n\t\t\t\t<Popover\n\t\t\t\t\tfocusOnMount={ false }\n\t\t\t\t\tplacement=\"right\"\n\t\t\t\t\toffset={ 32 }\n\t\t\t\t\tresize={ false }\n\t\t\t\t\tflip={ false }\n\t\t\t\t\tshift\n\t\t\t\t>\n\t\t\t\t\t<div\n\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\tclassName=\"wp-block-legacy-widget__edit-form\"\n\t\t\t\t\t\thidden={ ! isVisible }\n\t\t\t\t\t></div>\n\t\t\t\t</Popover>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tref={ ref }\n\t\t\tclassName=\"wp-block-legacy-widget__edit-form\"\n\t\t\thidden={ ! isVisible }\n\t\t>\n\t\t\t<h3 className=\"wp-block-legacy-widget__edit-form-title\">\n\t\t\t\t{ title }\n\t\t\t</h3>\n\t\t</div>\n\t);\n}\n"]}
1
+ {"version":3,"names":["classnames","useRef","useEffect","useDispatch","store","noticesStore","__","sprintf","Popover","useViewportMatch","Control","Form","title","isVisible","id","idBase","instance","isWide","onChangeInstance","onChangeHasPreview","ref","isMediumLargeViewport","outgoingInstances","Set","incomingInstances","createNotice","current","has","delete","control","nextInstance","add","onError","error","window","console","appendChild","element","destroy","createElement","className","focusOnMount","placement","offset","resize","flip","shift","hidden"],"sources":["@wordpress/widgets/src/blocks/legacy-widget/edit/form.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n/**\n * WordPress dependencies\n */\nimport { useRef, useEffect } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { Popover } from '@wordpress/components';\nimport { useViewportMatch } from '@wordpress/compose';\n/**\n * Internal dependencies\n */\nimport Control from './control';\n\nexport default function Form( {\n\ttitle,\n\tisVisible,\n\tid,\n\tidBase,\n\tinstance,\n\tisWide,\n\tonChangeInstance,\n\tonChangeHasPreview,\n} ) {\n\tconst ref = useRef();\n\n\tconst isMediumLargeViewport = useViewportMatch( 'small' );\n\n\t// We only want to remount the control when the instance changes\n\t// *externally*. For example, if the user performs an undo. To do this, we\n\t// keep track of changes made to instance by the control itself and then\n\t// ignore those.\n\tconst outgoingInstances = useRef( new Set() );\n\tconst incomingInstances = useRef( new Set() );\n\n\tconst { createNotice } = useDispatch( noticesStore );\n\n\tuseEffect( () => {\n\t\tif ( incomingInstances.current.has( instance ) ) {\n\t\t\tincomingInstances.current.delete( instance );\n\t\t\treturn;\n\t\t}\n\n\t\tconst control = new Control( {\n\t\t\tid,\n\t\t\tidBase,\n\t\t\tinstance,\n\t\t\tonChangeInstance( nextInstance ) {\n\t\t\t\toutgoingInstances.current.add( instance );\n\t\t\t\tincomingInstances.current.add( nextInstance );\n\t\t\t\tonChangeInstance( nextInstance );\n\t\t\t},\n\t\t\tonChangeHasPreview,\n\t\t\tonError( error ) {\n\t\t\t\twindow.console.error( error );\n\t\t\t\tcreateNotice(\n\t\t\t\t\t'error',\n\t\t\t\t\tsprintf(\n\t\t\t\t\t\t/* translators: %s: the name of the affected block. */\n\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t'The \"%s\" block was affected by errors and may not function properly. Check the developer tools for more details.'\n\t\t\t\t\t\t),\n\t\t\t\t\t\tidBase || id\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t},\n\t\t} );\n\n\t\tref.current.appendChild( control.element );\n\n\t\treturn () => {\n\t\t\tif ( outgoingInstances.current.has( instance ) ) {\n\t\t\t\toutgoingInstances.current.delete( instance );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tcontrol.destroy();\n\t\t};\n\t}, [\n\t\tid,\n\t\tidBase,\n\t\tinstance,\n\t\tonChangeInstance,\n\t\tonChangeHasPreview,\n\t\tisMediumLargeViewport,\n\t] );\n\n\tif ( isWide && isMediumLargeViewport ) {\n\t\treturn (\n\t\t\t<div\n\t\t\t\tclassName={ classnames( {\n\t\t\t\t\t'wp-block-legacy-widget__container': isVisible,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t{ isVisible && (\n\t\t\t\t\t<h3 className=\"wp-block-legacy-widget__edit-form-title\">\n\t\t\t\t\t\t{ title }\n\t\t\t\t\t</h3>\n\t\t\t\t) }\n\t\t\t\t<Popover\n\t\t\t\t\tfocusOnMount={ false }\n\t\t\t\t\tplacement=\"right\"\n\t\t\t\t\toffset={ 32 }\n\t\t\t\t\tresize={ false }\n\t\t\t\t\tflip={ false }\n\t\t\t\t\tshift\n\t\t\t\t>\n\t\t\t\t\t<div\n\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\tclassName=\"wp-block-legacy-widget__edit-form\"\n\t\t\t\t\t\thidden={ ! isVisible }\n\t\t\t\t\t></div>\n\t\t\t\t</Popover>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tref={ ref }\n\t\t\tclassName=\"wp-block-legacy-widget__edit-form\"\n\t\t\thidden={ ! isVisible }\n\t\t>\n\t\t\t<h3 className=\"wp-block-legacy-widget__edit-form-title\">\n\t\t\t\t{ title }\n\t\t\t</h3>\n\t\t</div>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,YAAY;AACnC;AACA;AACA;AACA,SAASC,MAAM,EAAEC,SAAS,QAAQ,oBAAoB;AACtD,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,IAAIC,YAAY,QAAQ,oBAAoB;AAC1D,SAASC,EAAE,EAAEC,OAAO,QAAQ,iBAAiB;AAC7C,SAASC,OAAO,QAAQ,uBAAuB;AAC/C,SAASC,gBAAgB,QAAQ,oBAAoB;AACrD;AACA;AACA;AACA,OAAOC,OAAO,MAAM,WAAW;AAE/B,eAAe,SAASC,IAAIA,CAAE;EAC7BC,KAAK;EACLC,SAAS;EACTC,EAAE;EACFC,MAAM;EACNC,QAAQ;EACRC,MAAM;EACNC,gBAAgB;EAChBC;AACD,CAAC,EAAG;EACH,MAAMC,GAA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,CAAC;QAC5C;MACD;MAEAa,OAAO,CAACS,OAAO,CAAC,CAAC;IAClB,CAAC;EACF,CAAC,EAAE,CACFxB,EAAE,EACFC,MAAM,EACNC,QAAQ,EACRE,gBAAgB,EAChBC,kBAAkB,EAClBE,qBAAqB,CACpB,CAAC;EAEH,IAAKJ,MAAM,IAAII,qBAAqB,EAAG;IACtC,OACCkB,aAAA;MACCC,SAAS,EAAGxC,UAAU,CAAE;QACvB,mCAAmC,EAAEa;MACtC,CAAE;IAAG,GAEHA,SAAS,IACV0B,aAAA;MAAIC,SAAS,EAAC;IAAyC,GACpD5B,KACC,CACJ,EACD2B,aAAA,CAAC/B,OAAO;MACPiC,YAAY,EAAG,KAAO;MACtBC,SAAS,EAAC,OAAO;MACjBC,MAAM,EAAG,EAAI;MACbC,MAAM,EAAG,KAAO;MAChBC,IAAI,EAAG,KAAO;MACdC,KAAK;IAAA,GAELP,aAAA;MACCnB,GAAG,EAAGA,GAAK;MACXoB,SAAS,EAAC,mCAAmC;MAC7CO,MAAM,EAAG,CAAElC;IAAW,CACjB,CACE,CACL,CAAC;EAER;EAEA,OACC0B,aAAA;IACCnB,GAAG,EAAGA,GAAK;IACXoB,SAAS,EAAC,mCAAmC;IAC7CO,MAAM,EAAG,CAAElC;EAAW,GAEtB0B,aAAA;IAAIC,SAAS,EAAC;EAAyC,GACpD5B,KACC,CACA,CAAC;AAER"}
@@ -1,13 +1,12 @@
1
1
  import { createElement, Fragment } from "@wordpress/element";
2
-
3
2
  /**
4
3
  * External dependencies
5
4
  */
6
5
  import classnames from 'classnames';
6
+
7
7
  /**
8
8
  * WordPress dependencies
9
9
  */
10
-
11
10
  import { useBlockProps, BlockControls, InspectorControls, BlockIcon, store as blockEditorStore } from '@wordpress/block-editor';
12
11
  import { Flex, FlexBlock, Spinner, Placeholder } from '@wordpress/components';
13
12
  import { brush as brushIcon } from '@wordpress/icons';
@@ -15,10 +14,10 @@ import { __ } from '@wordpress/i18n';
15
14
  import { useState, useCallback } from '@wordpress/element';
16
15
  import { useSelect } from '@wordpress/data';
17
16
  import { useEntityRecord } from '@wordpress/core-data';
17
+
18
18
  /**
19
19
  * Internal dependencies
20
20
  */
21
-
22
21
  import WidgetTypeSelector from './widget-type-selector';
23
22
  import InspectorCard from './inspector-card';
24
23
  import Form from './form';
@@ -38,12 +37,14 @@ export default function Edit(props) {
38
37
  'is-wide-widget': isWide
39
38
  })
40
39
  });
41
- return createElement("div", { ...blockProps
42
- }, !id && !idBase ? createElement(Empty, { ...props
43
- }) : createElement(NotEmpty, { ...props
40
+ return createElement("div", {
41
+ ...blockProps
42
+ }, !id && !idBase ? createElement(Empty, {
43
+ ...props
44
+ }) : createElement(NotEmpty, {
45
+ ...props
44
46
  }));
45
47
  }
46
-
47
48
  function Empty({
48
49
  attributes: {
49
50
  id,
@@ -84,7 +85,6 @@ function Empty({
84
85
  }
85
86
  }))));
86
87
  }
87
-
88
88
  function NotEmpty({
89
89
  attributes: {
90
90
  id,
@@ -108,7 +108,6 @@ function NotEmpty({
108
108
  instance: nextInstance
109
109
  });
110
110
  }, []);
111
-
112
111
  if (!widgetType && hasResolvedWidgetType) {
113
112
  return createElement(Placeholder, {
114
113
  icon: createElement(BlockIcon, {
@@ -117,11 +116,9 @@ function NotEmpty({
117
116
  label: __('Legacy Widget')
118
117
  }, __('Widget is missing.'));
119
118
  }
120
-
121
119
  if (!hasResolvedWidgetType) {
122
120
  return createElement(Placeholder, null, createElement(Spinner, null));
123
121
  }
124
-
125
122
  const mode = idBase && (isNavigationMode || !isSelected) ? 'preview' : 'edit';
126
123
  return createElement(Fragment, null, idBase === 'text' && createElement(BlockControls, {
127
124
  group: "other"