@wordpress/widgets 4.15.0 → 4.16.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.16.0 (2025-01-15)
6
+
5
7
  ## 4.15.0 (2025-01-02)
6
8
 
7
9
  ## 4.14.0 (2024-12-11)
@@ -16,7 +16,7 @@ var _i18n = require("@wordpress/i18n");
16
16
  /**
17
17
  * An API for creating and loading a widget control (a <div class="widget">
18
18
  * element) that is compatible with most third party widget scripts. By not
19
- * using React for this, we ensure that we have complete contorl over the DOM
19
+ * using React for this, we ensure that we have complete control over the DOM
20
20
  * and do not accidentally remove any elements that a third party widget script
21
21
  * has attached an event listener to.
22
22
  *
@@ -63,7 +63,7 @@ class Control {
63
63
  }
64
64
 
65
65
  /**
66
- * Clean up the control so that it can be garabge collected.
66
+ * Clean up the control so that it can be garbage collected.
67
67
  *
68
68
  * @access public
69
69
  */
@@ -1 +1 @@
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 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":";;;;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AALA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,MAAMG,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,GAAG,EAAEC,UAAU;IAE1B,IAAI,CAACC,gBAAgB,GAAG,IAAAC,iBAAQ,EAC/B,IAAI,CAACD,gBAAgB,CAACE,IAAI,CAAE,IAAK,CAAC,EAClC,GACD,CAAC;IACD,IAAI,CAACC,gBAAgB,GAAG,IAAI,CAACA,gBAAgB,CAACD,IAAI,CAAE,IAAK,CAAC;IAE1D,IAAI,CAACE,OAAO,CAAC,CAAC;IACd,IAAI,CAACC,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WA,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,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
+ {"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,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AALA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,MAAMG,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,GAAG,EAAEC,UAAU;IAE1B,IAAI,CAACC,gBAAgB,GAAG,IAAAC,iBAAQ,EAC/B,IAAI,CAACD,gBAAgB,CAACE,IAAI,CAAE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MzD,OAAO,GAAG8B,QAAQ,CAACU,aAAa,CAAE,KAAM,CAAC;EAC/CxC,OAAO,CAACsB,SAAS,GAAGmC,IAAI;EACxB,OAAOC,WAAW,CAAE1D,OAAQ,CAAC;AAC9B;AAEA,SAAS0D,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,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":[]}
@@ -9,7 +9,7 @@ import { __ } from '@wordpress/i18n';
9
9
  /**
10
10
  * An API for creating and loading a widget control (a <div class="widget">
11
11
  * element) that is compatible with most third party widget scripts. By not
12
- * using React for this, we ensure that we have complete contorl over the DOM
12
+ * using React for this, we ensure that we have complete control over the DOM
13
13
  * and do not accidentally remove any elements that a third party widget script
14
14
  * has attached an event listener to.
15
15
  *
@@ -56,7 +56,7 @@ export default class Control {
56
56
  }
57
57
 
58
58
  /**
59
- * Clean up the control so that it can be garabge collected.
59
+ * Clean up the control so that it can be garbage collected.
60
60
  *
61
61
  * @access public
62
62
  */
@@ -1 +1 @@
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,E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A,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","ignoreList":[]}
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 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":";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;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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","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/widgets",
3
- "version": "4.15.0",
3
+ "version": "4.16.0",
4
4
  "description": "Functionality used by the widgets block editor in the Widgets screen and the Customizer.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -26,17 +26,17 @@
26
26
  "wpScript": true,
27
27
  "dependencies": {
28
28
  "@babel/runtime": "7.25.7",
29
- "@wordpress/api-fetch": "^7.15.0",
30
- "@wordpress/block-editor": "^14.10.0",
31
- "@wordpress/blocks": "^14.4.0",
32
- "@wordpress/components": "^29.1.0",
33
- "@wordpress/compose": "^7.15.0",
34
- "@wordpress/core-data": "^7.15.0",
35
- "@wordpress/data": "^10.15.0",
36
- "@wordpress/element": "^6.15.0",
37
- "@wordpress/i18n": "^5.15.0",
38
- "@wordpress/icons": "^10.15.0",
39
- "@wordpress/notices": "^5.15.0",
29
+ "@wordpress/api-fetch": "^7.16.0",
30
+ "@wordpress/block-editor": "^14.11.0",
31
+ "@wordpress/blocks": "^14.5.0",
32
+ "@wordpress/components": "^29.2.0",
33
+ "@wordpress/compose": "^7.16.0",
34
+ "@wordpress/core-data": "^7.16.0",
35
+ "@wordpress/data": "^10.16.0",
36
+ "@wordpress/element": "^6.16.0",
37
+ "@wordpress/i18n": "^5.16.0",
38
+ "@wordpress/icons": "^10.16.0",
39
+ "@wordpress/notices": "^5.16.0",
40
40
  "clsx": "^2.1.1"
41
41
  },
42
42
  "peerDependencies": {
@@ -46,5 +46,5 @@
46
46
  "publishConfig": {
47
47
  "access": "public"
48
48
  },
49
- "gitHead": "75a65eb8ffc168a92042544052f46d080a71ea45"
49
+ "gitHead": "f48b9f56629e400891abb5ae491504de475237ff"
50
50
  }
@@ -8,7 +8,7 @@ import { __ } from '@wordpress/i18n';
8
8
  /**
9
9
  * An API for creating and loading a widget control (a <div class="widget">
10
10
  * element) that is compatible with most third party widget scripts. By not
11
- * using React for this, we ensure that we have complete contorl over the DOM
11
+ * using React for this, we ensure that we have complete control over the DOM
12
12
  * and do not accidentally remove any elements that a third party widget script
13
13
  * has attached an event listener to.
14
14
  *
@@ -60,7 +60,7 @@ export default class Control {
60
60
  }
61
61
 
62
62
  /**
63
- * Clean up the control so that it can be garabge collected.
63
+ * Clean up the control so that it can be garbage collected.
64
64
  *
65
65
  * @access public
66
66
  */