@wordpress/widgets 3.33.0 → 3.35.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 +8 -0
- package/build/blocks/legacy-widget/edit/form.js +2 -2
- package/build/blocks/legacy-widget/edit/form.js.map +1 -1
- package/build/blocks/legacy-widget/edit/index.js +2 -2
- package/build/blocks/legacy-widget/edit/index.js.map +1 -1
- package/build/blocks/legacy-widget/edit/preview.js +2 -2
- package/build/blocks/legacy-widget/edit/preview.js.map +1 -1
- package/build-module/blocks/legacy-widget/edit/form.js +2 -2
- package/build-module/blocks/legacy-widget/edit/form.js.map +1 -1
- package/build-module/blocks/legacy-widget/edit/index.js +2 -2
- package/build-module/blocks/legacy-widget/edit/index.js.map +1 -1
- package/build-module/blocks/legacy-widget/edit/preview.js +2 -2
- package/build-module/blocks/legacy-widget/edit/preview.js.map +1 -1
- package/package.json +14 -14
- package/src/blocks/legacy-widget/edit/form.js +2 -2
- package/src/blocks/legacy-widget/edit/index.js +2 -2
- package/src/blocks/legacy-widget/edit/preview.js +4 -7
- package/src/blocks/legacy-widget/index.php +6 -0
- package/src/blocks/widget-group/index.php +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 3.35.0 (2024-05-16)
|
|
6
|
+
|
|
7
|
+
### Internal
|
|
8
|
+
|
|
9
|
+
- Replaced `classnames` package with the faster and smaller `clsx` package ([#61138](https://github.com/WordPress/gutenberg/pull/61138)).
|
|
10
|
+
|
|
11
|
+
## 3.34.0 (2024-05-02)
|
|
12
|
+
|
|
5
13
|
## 3.33.0 (2024-04-19)
|
|
6
14
|
|
|
7
15
|
## 3.32.0 (2024-04-03)
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = Form;
|
|
8
8
|
var _react = require("react");
|
|
9
|
-
var
|
|
9
|
+
var _clsx = _interopRequireDefault(require("clsx"));
|
|
10
10
|
var _element = require("@wordpress/element");
|
|
11
11
|
var _data = require("@wordpress/data");
|
|
12
12
|
var _notices = require("@wordpress/notices");
|
|
@@ -80,7 +80,7 @@ function Form({
|
|
|
80
80
|
}, [id, idBase, instance, onChangeInstance, onChangeHasPreview, isMediumLargeViewport]);
|
|
81
81
|
if (isWide && isMediumLargeViewport) {
|
|
82
82
|
return (0, _react.createElement)("div", {
|
|
83
|
-
className: (0,
|
|
83
|
+
className: (0, _clsx.default)({
|
|
84
84
|
'wp-block-legacy-widget__container': isVisible
|
|
85
85
|
})
|
|
86
86
|
}, isVisible && (0, _react.createElement)("h3", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_clsx","_interopRequireDefault","require","_element","_data","_notices","_i18n","_components","_compose","_control","Form","title","isVisible","id","idBase","instance","isWide","onChangeInstance","onChangeHasPreview","ref","useRef","isMediumLargeViewport","useViewportMatch","outgoingInstances","Set","incomingInstances","createNotice","useDispatch","noticesStore","useEffect","current","has","delete","control","Control","nextInstance","add","onError","error","window","console","sprintf","__","appendChild","element","destroy","_react","createElement","className","clsx","Popover","focusOnMount","placement","offset","resize","flip","shift","hidden"],"sources":["@wordpress/widgets/src/blocks/legacy-widget/edit/form.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\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={ clsx( {\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":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAIA,IAAAO,QAAA,GAAAR,sBAAA,CAAAC,OAAA;AAhBA;AACA;AACA;;AAEA;AACA;AACA;;AAOA;AACA;AACA;;AAGe,SAASQ,IAAIA,CAAE;EAC7BC,KAAK;EACLC,SAAS;EACTC,EAAE;EACFC,MAAM;EACNC,QAAQ;EACRC,MAAM;EACNC,gBAAgB;EAChBC;AACD,CAAC,EAAG;EACH,MAAMC,GAAG,GAAG,I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iB,CAACO,OAAO,CAACE,MAAM,CAAEjB,QAAS,CAAC;QAC5C;MACD;MAEAkB,OAAO,CAACY,OAAO,CAAC,CAAC;IAClB,CAAC;EACF,CAAC,EAAE,CACFhC,EAAE,EACFC,MAAM,EACNC,QAAQ,EACRE,gBAAgB,EAChBC,kBAAkB,EAClBG,qBAAqB,CACpB,CAAC;EAEH,IAAKL,MAAM,IAAIK,qBAAqB,EAAG;IACtC,OACC,IAAAyB,MAAA,CAAAC,aAAA;MACCC,SAAS,EAAG,IAAAC,aAAI,EAAE;QACjB,mCAAmC,EAAErC;MACtC,CAAE;IAAG,GAEHA,SAAS,IACV,IAAAkC,MAAA,CAAAC,aAAA;MAAIC,SAAS,EAAC;IAAyC,GACpDrC,KACC,CACJ,EACD,IAAAmC,MAAA,CAAAC,aAAA,EAACxC,WAAA,CAAA2C,OAAO;MACPC,YAAY,EAAG,KAAO;MACtBC,SAAS,EAAC,OAAO;MACjBC,MAAM,EAAG,EAAI;MACbC,MAAM,EAAG,KAAO;MAChBC,IAAI,EAAG,KAAO;MACdC,KAAK;IAAA,GAEL,IAAAV,MAAA,CAAAC,aAAA;MACC5B,GAAG,EAAGA,GAAK;MACX6B,SAAS,EAAC,mCAAmC;MAC7CS,MAAM,EAAG,CAAE7C;IAAW,CACjB,CACE,CACL,CAAC;EAER;EAEA,OACC,IAAAkC,MAAA,CAAAC,aAAA;IACC5B,GAAG,EAAGA,GAAK;IACX6B,SAAS,EAAC,mCAAmC;IAC7CS,MAAM,EAAG,CAAE7C;EAAW,GAEtB,IAAAkC,MAAA,CAAAC,aAAA;IAAIC,SAAS,EAAC;EAAyC,GACpDrC,KACC,CACA,CAAC;AAER","ignoreList":[]}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = Edit;
|
|
8
8
|
var _react = require("react");
|
|
9
|
-
var
|
|
9
|
+
var _clsx = _interopRequireDefault(require("clsx"));
|
|
10
10
|
var _blockEditor = require("@wordpress/block-editor");
|
|
11
11
|
var _components = require("@wordpress/components");
|
|
12
12
|
var _icons = require("@wordpress/icons");
|
|
@@ -41,7 +41,7 @@ function Edit(props) {
|
|
|
41
41
|
isWide = false
|
|
42
42
|
} = props;
|
|
43
43
|
const blockProps = (0, _blockEditor.useBlockProps)({
|
|
44
|
-
className: (0,
|
|
44
|
+
className: (0, _clsx.default)({
|
|
45
45
|
'is-wide-widget': isWide
|
|
46
46
|
})
|
|
47
47
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_classnames","_interopRequireDefault","require","_blockEditor","_components","_icons","_i18n","_element","_data","_coreData","_widgetTypeSelector","_inspectorCard","_form","_preview","_noPreview","_convertToBlocksButton","Edit","props","id","idBase","attributes","isWide","blockProps","useBlockProps","className","classnames","_react","createElement","Empty","NotEmpty","setAttributes","Placeholder","icon","BlockIcon","brushIcon","label","__","Flex","FlexBlock","default","selectedId","onSelect","isMulti","instance","clientId","isSelected","hasPreview","setHasPreview","useState","widgetTypeId","record","widgetType","hasResolved","hasResolvedWidgetType","useEntityRecord","isNavigationMode","useSelect","select","blockEditorStore","setInstance","useCallback","nextInstance","Spinner","mode","Fragment","BlockControls","group","rawInstance","raw","InspectorControls","name","description","title","isVisible","onChangeInstance","onChangeHasPreview"],"sources":["@wordpress/widgets/src/blocks/legacy-widget/edit/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseBlockProps,\n\tBlockControls,\n\tInspectorControls,\n\tBlockIcon,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { Flex, FlexBlock, Spinner, Placeholder } from '@wordpress/components';\nimport { brush as brushIcon } from '@wordpress/icons';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useCallback } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { useEntityRecord } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport WidgetTypeSelector from './widget-type-selector';\nimport InspectorCard from './inspector-card';\nimport Form from './form';\nimport Preview from './preview';\nimport NoPreview from './no-preview';\nimport ConvertToBlocksButton from './convert-to-blocks-button';\n\nexport default function Edit( props ) {\n\tconst { id, idBase } = props.attributes;\n\tconst { isWide = false } = props;\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: classnames( {\n\t\t\t'is-wide-widget': isWide,\n\t\t} ),\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ ! id && ! idBase ? (\n\t\t\t\t<Empty { ...props } />\n\t\t\t) : (\n\t\t\t\t<NotEmpty { ...props } />\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nfunction Empty( { attributes: { id, idBase }, setAttributes } ) {\n\treturn (\n\t\t<Placeholder\n\t\t\ticon={ <BlockIcon icon={ brushIcon } /> }\n\t\t\tlabel={ __( 'Legacy Widget' ) }\n\t\t>\n\t\t\t<Flex>\n\t\t\t\t<FlexBlock>\n\t\t\t\t\t<WidgetTypeSelector\n\t\t\t\t\t\tselectedId={ id ?? idBase }\n\t\t\t\t\t\tonSelect={ ( { selectedId, isMulti } ) => {\n\t\t\t\t\t\t\tif ( ! selectedId ) {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tid: null,\n\t\t\t\t\t\t\t\t\tidBase: null,\n\t\t\t\t\t\t\t\t\tinstance: null,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} else if ( isMulti ) {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tid: null,\n\t\t\t\t\t\t\t\t\tidBase: selectedId,\n\t\t\t\t\t\t\t\t\tinstance: {},\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tid: selectedId,\n\t\t\t\t\t\t\t\t\tidBase: null,\n\t\t\t\t\t\t\t\t\tinstance: null,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</FlexBlock>\n\t\t\t</Flex>\n\t\t</Placeholder>\n\t);\n}\n\nfunction NotEmpty( {\n\tattributes: { id, idBase, instance },\n\tsetAttributes,\n\tclientId,\n\tisSelected,\n\tisWide = false,\n} ) {\n\tconst [ hasPreview, setHasPreview ] = useState( null );\n\n\tconst widgetTypeId = id ?? idBase;\n\tconst { record: widgetType, hasResolved: hasResolvedWidgetType } =\n\t\tuseEntityRecord( 'root', 'widgetType', widgetTypeId );\n\n\tconst isNavigationMode = useSelect(\n\t\t( select ) => select( blockEditorStore ).isNavigationMode(),\n\t\t[]\n\t);\n\n\tconst setInstance = useCallback( ( nextInstance ) => {\n\t\tsetAttributes( { instance: nextInstance } );\n\t}, [] );\n\n\tif ( ! widgetType && hasResolvedWidgetType ) {\n\t\treturn (\n\t\t\t<Placeholder\n\t\t\t\ticon={ <BlockIcon icon={ brushIcon } /> }\n\t\t\t\tlabel={ __( 'Legacy Widget' ) }\n\t\t\t>\n\t\t\t\t{ __( 'Widget is missing.' ) }\n\t\t\t</Placeholder>\n\t\t);\n\t}\n\n\tif ( ! hasResolvedWidgetType ) {\n\t\treturn (\n\t\t\t<Placeholder>\n\t\t\t\t<Spinner />\n\t\t\t</Placeholder>\n\t\t);\n\t}\n\n\tconst mode =\n\t\tidBase && ( isNavigationMode || ! isSelected ) ? 'preview' : 'edit';\n\n\treturn (\n\t\t<>\n\t\t\t{ idBase === 'text' && (\n\t\t\t\t<BlockControls group=\"other\">\n\t\t\t\t\t<ConvertToBlocksButton\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\trawInstance={ instance.raw }\n\t\t\t\t\t/>\n\t\t\t\t</BlockControls>\n\t\t\t) }\n\n\t\t\t<InspectorControls>\n\t\t\t\t<InspectorCard\n\t\t\t\t\tname={ widgetType.name }\n\t\t\t\t\tdescription={ widgetType.description }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\n\t\t\t<Form\n\t\t\t\ttitle={ widgetType.name }\n\t\t\t\tisVisible={ mode === 'edit' }\n\t\t\t\tid={ id }\n\t\t\t\tidBase={ idBase }\n\t\t\t\tinstance={ instance }\n\t\t\t\tisWide={ isWide }\n\t\t\t\tonChangeInstance={ setInstance }\n\t\t\t\tonChangeHasPreview={ setHasPreview }\n\t\t\t/>\n\n\t\t\t{ idBase && (\n\t\t\t\t<>\n\t\t\t\t\t{ hasPreview === null && mode === 'preview' && (\n\t\t\t\t\t\t<Placeholder>\n\t\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t\t</Placeholder>\n\t\t\t\t\t) }\n\t\t\t\t\t{ hasPreview === true && (\n\t\t\t\t\t\t<Preview\n\t\t\t\t\t\t\tidBase={ idBase }\n\t\t\t\t\t\t\tinstance={ instance }\n\t\t\t\t\t\t\tisVisible={ mode === 'preview' }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t{ hasPreview === false && mode === 'preview' && (\n\t\t\t\t\t\t<NoPreview name={ widgetType.name } />\n\t\t\t\t\t) }\n\t\t\t\t</>\n\t\t\t) }\n\t\t</>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,YAAA,GAAAD,OAAA;AAOA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,SAAA,GAAAP,OAAA;AAKA,IAAAQ,mBAAA,GAAAT,sBAAA,CAAAC,OAAA;AACA,IAAAS,cAAA,GAAAV,sBAAA,CAAAC,OAAA;AACA,IAAAU,KAAA,GAAAX,sBAAA,CAAAC,OAAA;AACA,IAAAW,QAAA,GAAAZ,sBAAA,CAAAC,OAAA;AACA,IAAAY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UAAU,CAACoB;EAAa,CACtC,CACiB,CAAC,EAEpB,IAAA7C,MAAA,CAAAC,aAAA,EAACf,KAAA,CAAA2B,OAAI;IACJiC,KAAK,EAAGrB,UAAU,CAACmB,IAAM;IACzBG,SAAS,EAAGV,IAAI,KAAK,MAAQ;IAC7B7C,EAAE,EAAGA,EAAI;IACTC,MAAM,EAAGA,MAAQ;IACjBwB,QAAQ,EAAGA,QAAU;IACrBtB,MAAM,EAAGA,MAAQ;IACjBqD,gBAAgB,EAAGf,WAAa;IAChCgB,kBAAkB,EAAG5B;EAAe,CACpC,CAAC,EAEA5B,MAAM,IACP,IAAAO,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAsC,QAAA,QACGlB,UAAU,KAAK,IAAI,IAAIiB,IAAI,KAAK,SAAS,IAC1C,IAAArC,MAAA,CAAAC,aAAA,EAACvB,WAAA,CAAA2B,WAAW,QACX,IAAAL,MAAA,CAAAC,aAAA,EAACvB,WAAA,CAAA0D,OAAO,MAAE,CACE,CACb,EACChB,UAAU,KAAK,IAAI,IACpB,IAAApB,MAAA,CAAAC,aAAA,EAACd,QAAA,CAAA0B,OAAO;IACPpB,MAAM,EAAGA,MAAQ;IACjBwB,QAAQ,EAAGA,QAAU;IACrB8B,SAAS,EAAGV,IAAI,KAAK;EAAW,CAChC,CACD,EACCjB,UAAU,KAAK,KAAK,IAAIiB,IAAI,KAAK,SAAS,IAC3C,IAAArC,MAAA,CAAAC,aAAA,EAACb,UAAA,CAAAyB,OAAS;IAAC+B,IAAI,EAAGnB,UAAU,CAACmB;EAAM,CAAE,CAErC,CAEF,CAAC;AAEL","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_clsx","_interopRequireDefault","require","_blockEditor","_components","_icons","_i18n","_element","_data","_coreData","_widgetTypeSelector","_inspectorCard","_form","_preview","_noPreview","_convertToBlocksButton","Edit","props","id","idBase","attributes","isWide","blockProps","useBlockProps","className","clsx","_react","createElement","Empty","NotEmpty","setAttributes","Placeholder","icon","BlockIcon","brushIcon","label","__","Flex","FlexBlock","default","selectedId","onSelect","isMulti","instance","clientId","isSelected","hasPreview","setHasPreview","useState","widgetTypeId","record","widgetType","hasResolved","hasResolvedWidgetType","useEntityRecord","isNavigationMode","useSelect","select","blockEditorStore","setInstance","useCallback","nextInstance","Spinner","mode","Fragment","BlockControls","group","rawInstance","raw","InspectorControls","name","description","title","isVisible","onChangeInstance","onChangeHasPreview"],"sources":["@wordpress/widgets/src/blocks/legacy-widget/edit/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseBlockProps,\n\tBlockControls,\n\tInspectorControls,\n\tBlockIcon,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { Flex, FlexBlock, Spinner, Placeholder } from '@wordpress/components';\nimport { brush as brushIcon } from '@wordpress/icons';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useCallback } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { useEntityRecord } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport WidgetTypeSelector from './widget-type-selector';\nimport InspectorCard from './inspector-card';\nimport Form from './form';\nimport Preview from './preview';\nimport NoPreview from './no-preview';\nimport ConvertToBlocksButton from './convert-to-blocks-button';\n\nexport default function Edit( props ) {\n\tconst { id, idBase } = props.attributes;\n\tconst { isWide = false } = props;\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( {\n\t\t\t'is-wide-widget': isWide,\n\t\t} ),\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ ! id && ! idBase ? (\n\t\t\t\t<Empty { ...props } />\n\t\t\t) : (\n\t\t\t\t<NotEmpty { ...props } />\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nfunction Empty( { attributes: { id, idBase }, setAttributes } ) {\n\treturn (\n\t\t<Placeholder\n\t\t\ticon={ <BlockIcon icon={ brushIcon } /> }\n\t\t\tlabel={ __( 'Legacy Widget' ) }\n\t\t>\n\t\t\t<Flex>\n\t\t\t\t<FlexBlock>\n\t\t\t\t\t<WidgetTypeSelector\n\t\t\t\t\t\tselectedId={ id ?? idBase }\n\t\t\t\t\t\tonSelect={ ( { selectedId, isMulti } ) => {\n\t\t\t\t\t\t\tif ( ! selectedId ) {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tid: null,\n\t\t\t\t\t\t\t\t\tidBase: null,\n\t\t\t\t\t\t\t\t\tinstance: null,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} else if ( isMulti ) {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tid: null,\n\t\t\t\t\t\t\t\t\tidBase: selectedId,\n\t\t\t\t\t\t\t\t\tinstance: {},\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tid: selectedId,\n\t\t\t\t\t\t\t\t\tidBase: null,\n\t\t\t\t\t\t\t\t\tinstance: null,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</FlexBlock>\n\t\t\t</Flex>\n\t\t</Placeholder>\n\t);\n}\n\nfunction NotEmpty( {\n\tattributes: { id, idBase, instance },\n\tsetAttributes,\n\tclientId,\n\tisSelected,\n\tisWide = false,\n} ) {\n\tconst [ hasPreview, setHasPreview ] = useState( null );\n\n\tconst widgetTypeId = id ?? idBase;\n\tconst { record: widgetType, hasResolved: hasResolvedWidgetType } =\n\t\tuseEntityRecord( 'root', 'widgetType', widgetTypeId );\n\n\tconst isNavigationMode = useSelect(\n\t\t( select ) => select( blockEditorStore ).isNavigationMode(),\n\t\t[]\n\t);\n\n\tconst setInstance = useCallback( ( nextInstance ) => {\n\t\tsetAttributes( { instance: nextInstance } );\n\t}, [] );\n\n\tif ( ! widgetType && hasResolvedWidgetType ) {\n\t\treturn (\n\t\t\t<Placeholder\n\t\t\t\ticon={ <BlockIcon icon={ brushIcon } /> }\n\t\t\t\tlabel={ __( 'Legacy Widget' ) }\n\t\t\t>\n\t\t\t\t{ __( 'Widget is missing.' ) }\n\t\t\t</Placeholder>\n\t\t);\n\t}\n\n\tif ( ! hasResolvedWidgetType ) {\n\t\treturn (\n\t\t\t<Placeholder>\n\t\t\t\t<Spinner />\n\t\t\t</Placeholder>\n\t\t);\n\t}\n\n\tconst mode =\n\t\tidBase && ( isNavigationMode || ! isSelected ) ? 'preview' : 'edit';\n\n\treturn (\n\t\t<>\n\t\t\t{ idBase === 'text' && (\n\t\t\t\t<BlockControls group=\"other\">\n\t\t\t\t\t<ConvertToBlocksButton\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\trawInstance={ instance.raw }\n\t\t\t\t\t/>\n\t\t\t\t</BlockControls>\n\t\t\t) }\n\n\t\t\t<InspectorControls>\n\t\t\t\t<InspectorCard\n\t\t\t\t\tname={ widgetType.name }\n\t\t\t\t\tdescription={ widgetType.description }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\n\t\t\t<Form\n\t\t\t\ttitle={ widgetType.name }\n\t\t\t\tisVisible={ mode === 'edit' }\n\t\t\t\tid={ id }\n\t\t\t\tidBase={ idBase }\n\t\t\t\tinstance={ instance }\n\t\t\t\tisWide={ isWide }\n\t\t\t\tonChangeInstance={ setInstance }\n\t\t\t\tonChangeHasPreview={ setHasPreview }\n\t\t\t/>\n\n\t\t\t{ idBase && (\n\t\t\t\t<>\n\t\t\t\t\t{ hasPreview === null && mode === 'preview' && (\n\t\t\t\t\t\t<Placeholder>\n\t\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t\t</Placeholder>\n\t\t\t\t\t) }\n\t\t\t\t\t{ hasPreview === true && (\n\t\t\t\t\t\t<Preview\n\t\t\t\t\t\t\tidBase={ idBase }\n\t\t\t\t\t\t\tinstance={ instance }\n\t\t\t\t\t\t\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,QACX,IAAAL,MAAA,CAAAC,aAAA,EAACvB,WAAA,CAAA0D,OAAO,MAAE,CACE,CACb,EACChB,UAAU,KAAK,IAAI,IACpB,IAAApB,MAAA,CAAAC,aAAA,EAACd,QAAA,CAAA0B,OAAO;IACPpB,MAAM,EAAGA,MAAQ;IACjBwB,QAAQ,EAAGA,QAAU;IACrB8B,SAAS,EAAGV,IAAI,KAAK;EAAW,CAChC,CACD,EACCjB,UAAU,KAAK,KAAK,IAAIiB,IAAI,KAAK,SAAS,IAC3C,IAAArC,MAAA,CAAAC,aAAA,EAACb,UAAA,CAAAyB,OAAS;IAAC+B,IAAI,EAAGnB,UAAU,CAACmB;EAAM,CAAE,CAErC,CAEF,CAAC;AAEL","ignoreList":[]}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = Preview;
|
|
8
8
|
var _react = require("react");
|
|
9
|
-
var
|
|
9
|
+
var _clsx = _interopRequireDefault(require("clsx"));
|
|
10
10
|
var _compose = require("@wordpress/compose");
|
|
11
11
|
var _element = require("@wordpress/element");
|
|
12
12
|
var _components = require("@wordpress/components");
|
|
@@ -94,7 +94,7 @@ function Preview({
|
|
|
94
94
|
};
|
|
95
95
|
}, [isLoaded]);
|
|
96
96
|
return (0, _react.createElement)(_react.Fragment, null, isVisible && !isLoaded && (0, _react.createElement)(_components.Placeholder, null, (0, _react.createElement)(_components.Spinner, null)), (0, _react.createElement)("div", {
|
|
97
|
-
className: (0,
|
|
97
|
+
className: (0, _clsx.default)('wp-block-legacy-widget__edit-preview', {
|
|
98
98
|
'is-offscreen': !isVisible || !isLoaded
|
|
99
99
|
})
|
|
100
100
|
}, (0, _react.createElement)(_components.Disabled, null, (0, _react.createElement)("iframe", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_clsx","_interopRequireDefault","require","_compose","_element","_components","_i18n","_apiFetch","Preview","idBase","instance","isVisible","isLoaded","setIsLoaded","useState","srcDoc","setSrcDoc","useEffect","abortController","window","AbortController","undefined","fetchPreviewHTML","restRoute","apiFetch","path","method","signal","data","then","response","preview","catch","error","name","abort","ref","useRefEffect","iframe","setHeight","_iframe$contentDocume","_iframe$contentDocume2","height","Math","max","contentDocument","documentElement","offsetHeight","body","style","IntersectionObserver","ownerDocument","defaultView","intersectionObserver","entry","isIntersecting","threshold","observe","addEventListener","disconnect","removeEventListener","_react","createElement","Fragment","Placeholder","Spinner","className","clsx","Disabled","tabIndex","title","__","onLoad","event","target","overflow"],"sources":["@wordpress/widgets/src/blocks/legacy-widget/edit/preview.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useRefEffect } from '@wordpress/compose';\nimport { useEffect, useState } from '@wordpress/element';\nimport { Disabled, Placeholder, Spinner } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\n\nexport default function Preview( { idBase, instance, isVisible } ) {\n\tconst [ isLoaded, setIsLoaded ] = useState( false );\n\tconst [ srcDoc, setSrcDoc ] = useState( '' );\n\n\tuseEffect( () => {\n\t\tconst abortController =\n\t\t\ttypeof window.AbortController === 'undefined'\n\t\t\t\t? undefined\n\t\t\t\t: new window.AbortController();\n\n\t\tasync function fetchPreviewHTML() {\n\t\t\tconst restRoute = `/wp/v2/widget-types/${ idBase }/render`;\n\t\t\treturn await apiFetch( {\n\t\t\t\tpath: restRoute,\n\t\t\t\tmethod: 'POST',\n\t\t\t\tsignal: abortController?.signal,\n\t\t\t\tdata: instance ? { instance } : {},\n\t\t\t} );\n\t\t}\n\n\t\tfetchPreviewHTML()\n\t\t\t.then( ( response ) => {\n\t\t\t\tsetSrcDoc( response.preview );\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tif ( 'AbortError' === error.name ) {\n\t\t\t\t\t// We don't want to log aborted requests.\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t} );\n\n\t\treturn () => abortController?.abort();\n\t}, [ idBase, instance ] );\n\n\t// Resize the iframe on either the load event, or when the iframe becomes visible.\n\tconst ref = useRefEffect(\n\t\t( iframe ) => {\n\t\t\t// Only set height if the iframe is loaded,\n\t\t\t// or it will grow to an unexpected large height in Safari if it's hidden initially.\n\t\t\tif ( ! isLoaded ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// If the preview frame has another origin then this won't work.\n\t\t\t// One possible solution is to add custom script to call `postMessage` in the preview frame.\n\t\t\t// Or, better yet, we migrate away from iframe.\n\t\t\tfunction setHeight() {\n\t\t\t\t// Pick the maximum of these two values to account for margin collapsing.\n\t\t\t\tconst height = Math.max(\n\t\t\t\t\tiframe.contentDocument.documentElement?.offsetHeight ?? 0,\n\t\t\t\t\tiframe.contentDocument.body?.offsetHeight ?? 0\n\t\t\t\t);\n\n\t\t\t\t// Fallback to a height of 100px if the height cannot be determined.\n\t\t\t\t// This ensures the block is still selectable. 100px should hopefully\n\t\t\t\t// be not so big that it's annoying, and not so small that nothing\n\t\t\t\t// can be seen.\n\t\t\t\tiframe.style.height = `${ height !== 0 ? height : 100 }px`;\n\t\t\t}\n\n\t\t\tconst { IntersectionObserver } = iframe.ownerDocument.defaultView;\n\n\t\t\t// Observe for intersections that might cause a change in the height of\n\t\t\t// the iframe, e.g. a Widget Area becoming expanded.\n\t\t\tconst intersectionObserver = new IntersectionObserver(\n\t\t\t\t( [ entry ] ) => {\n\t\t\t\t\tif ( entry.isIntersecting ) {\n\t\t\t\t\t\tsetHeight();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tthreshold: 1,\n\t\t\t\t}\n\t\t\t);\n\t\t\tintersectionObserver.observe( iframe );\n\n\t\t\tiframe.addEventListener( 'load', setHeight );\n\n\t\t\treturn () => {\n\t\t\t\tintersectionObserver.disconnect();\n\t\t\t\tiframe.removeEventListener( 'load', setHeight );\n\t\t\t};\n\t\t},\n\t\t[ isLoaded ]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{ /*\n\t\t\tWhile the iframe contents are loading, we move the iframe off-screen\n\t\t\tand display a placeholder instead. This ensures that the user\n\t\t\tdoesn't see the iframe resize (which looks really janky). We have to\n\t\t\tmove the iframe off-screen instead of hiding it because web browsers\n\t\t\twill not trigger onLoad if the iframe is hidden.\n\t\t\t*/ }\n\t\t\t{ isVisible && ! isLoaded && (\n\t\t\t\t<Placeholder>\n\t\t\t\t\t<Spinner />\n\t\t\t\t</Placeholder>\n\t\t\t) }\n\t\t\t<div\n\t\t\t\tclassName={ clsx( 'wp-block-legacy-widget__edit-preview', {\n\t\t\t\t\t'is-offscreen': ! isVisible || ! isLoaded,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<Disabled>\n\t\t\t\t\t{ /*\n\t\t\t\t\tWe use an iframe so that the widget has an opportunity to\n\t\t\t\t\tload scripts and styles that it needs to run.\n\t\t\t\t\t*/ }\n\t\t\t\t\t<iframe\n\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\tclassName=\"wp-block-legacy-widget__edit-preview-iframe\"\n\t\t\t\t\t\ttabIndex=\"-1\"\n\t\t\t\t\t\ttitle={ __( 'Legacy Widget Preview' ) }\n\t\t\t\t\t\tsrcDoc={ srcDoc }\n\t\t\t\t\t\tonLoad={ ( event ) => {\n\t\t\t\t\t\t\t// To hide the scrollbars of the preview frame for some edge cases,\n\t\t\t\t\t\t\t// such as negative margins in the Gallery Legacy Widget.\n\t\t\t\t\t\t\t// It can't be scrolled anyway.\n\t\t\t\t\t\t\t// TODO: Ideally, this should be fixed in core.\n\t\t\t\t\t\t\tevent.target.contentDocument.body.style.overflow =\n\t\t\t\t\t\t\t\t'hidden';\n\n\t\t\t\t\t\t\tsetIsLoaded( true );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\theight={ 100 }\n\t\t\t\t\t/>\n\t\t\t\t</Disabled>\n\t\t\t</div>\n\t\t</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U,CAAC;IAChD,CAAC;EACF,CAAC,EACD,CAAE3B,QAAQ,CACX,CAAC;EAED,OACC,IAAAiD,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAE,QAAA,QAQGpD,SAAS,IAAI,CAAEC,QAAQ,IACxB,IAAAiD,MAAA,CAAAC,aAAA,EAACzD,WAAA,CAAA2D,WAAW,QACX,IAAAH,MAAA,CAAAC,aAAA,EAACzD,WAAA,CAAA4D,OAAO,MAAE,CACE,CACb,EACD,IAAAJ,MAAA,CAAAC,aAAA;IACCI,SAAS,EAAG,IAAAC,aAAI,EAAE,sCAAsC,EAAE;MACzD,cAAc,EAAE,CAAExD,SAAS,IAAI,CAAEC;IAClC,CAAE;EAAG,GAEL,IAAAiD,MAAA,CAAAC,aAAA,EAACzD,WAAA,CAAA+D,QAAQ,QAKR,IAAAP,MAAA,CAAAC,aAAA;IACC1B,GAAG,EAAGA,GAAK;IACX8B,SAAS,EAAC,6CAA6C;IACvDG,QAAQ,EAAC,IAAI;IACbC,KAAK,EAAG,IAAAC,QAAE,EAAE,uBAAwB,CAAG;IACvCxD,MAAM,EAAGA,MAAQ;IACjByD,MAAM,EAAKC,KAAK,IAAM;MACrB;MACA;MACA;MACA;MACAA,KAAK,CAACC,MAAM,CAAC7B,eAAe,CAACG,IAAI,CAACC,KAAK,CAAC0B,QAAQ,GAC/C,QAAQ;MAET9D,WAAW,CAAE,IAAK,CAAC;IACpB,CAAG;IACH6B,MAAM,EAAG;EAAK,CACd,CACQ,CACN,CACJ,CAAC;AAEL","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@ import { createElement } from "react";
|
|
|
2
2
|
/**
|
|
3
3
|
* External dependencies
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
5
|
+
import clsx from 'clsx';
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
@@ -70,7 +70,7 @@ export default function Form({
|
|
|
70
70
|
}, [id, idBase, instance, onChangeInstance, onChangeHasPreview, isMediumLargeViewport]);
|
|
71
71
|
if (isWide && isMediumLargeViewport) {
|
|
72
72
|
return createElement("div", {
|
|
73
|
-
className:
|
|
73
|
+
className: clsx({
|
|
74
74
|
'wp-block-legacy-widget__container': isVisible
|
|
75
75
|
})
|
|
76
76
|
}, isVisible && createElement("h3", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["clsx","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 clsx from 'clsx';\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={ clsx( {\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,IAAI,MAAM,MAAM;AACvB;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,GAAG,GAAGnB,MAAM,CAAC,CAAC;EAEpB,MAAMoB,qBAAqB,GAAGZ,gBAAgB,CAAE,OAAQ,CAAC;;EAEzD;EACA;EACA;EACA;EACA,MAAMa,iBAAiB,GAAGrB,MAAM,CAAE,IAAIsB,GAAG,CAAC,CAAE,CAAC;EAC7C,MAAMC,iBAAiB,GAAGvB,MAAM,CAAE,IAAIsB,GAAG,CAAC,CAAE,CAAC;EAE7C,MAAM;IAAEE;EAAa,CAAC,GAAGtB,WAA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E;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","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@ import { createElement, Fragment } from "react";
|
|
|
2
2
|
/**
|
|
3
3
|
* External dependencies
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
5
|
+
import clsx from 'clsx';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
@@ -33,7 +33,7 @@ export default function Edit(props) {
|
|
|
33
33
|
isWide = false
|
|
34
34
|
} = props;
|
|
35
35
|
const blockProps = useBlockProps({
|
|
36
|
-
className:
|
|
36
|
+
className: clsx({
|
|
37
37
|
'is-wide-widget': isWide
|
|
38
38
|
})
|
|
39
39
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["clsx","useBlockProps","BlockControls","InspectorControls","BlockIcon","store","blockEditorStore","Flex","FlexBlock","Spinner","Placeholder","brush","brushIcon","__","useState","useCallback","useSelect","useEntityRecord","WidgetTypeSelector","InspectorCard","Form","Preview","NoPreview","ConvertToBlocksButton","Edit","props","id","idBase","attributes","isWide","blockProps","className","createElement","Empty","NotEmpty","setAttributes","icon","label","selectedId","onSelect","isMulti","instance","clientId","isSelected","hasPreview","setHasPreview","widgetTypeId","record","widgetType","hasResolved","hasResolvedWidgetType","isNavigationMode","select","setInstance","nextInstance","mode","Fragment","group","rawInstance","raw","name","description","title","isVisible","onChangeInstance","onChangeHasPreview"],"sources":["@wordpress/widgets/src/blocks/legacy-widget/edit/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseBlockProps,\n\tBlockControls,\n\tInspectorControls,\n\tBlockIcon,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { Flex, FlexBlock, Spinner, Placeholder } from '@wordpress/components';\nimport { brush as brushIcon } from '@wordpress/icons';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useCallback } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { useEntityRecord } from '@wordpress/core-data';\n\n/**\n * Internal dependencies\n */\nimport WidgetTypeSelector from './widget-type-selector';\nimport InspectorCard from './inspector-card';\nimport Form from './form';\nimport Preview from './preview';\nimport NoPreview from './no-preview';\nimport ConvertToBlocksButton from './convert-to-blocks-button';\n\nexport default function Edit( props ) {\n\tconst { id, idBase } = props.attributes;\n\tconst { isWide = false } = props;\n\n\tconst blockProps = useBlockProps( {\n\t\tclassName: clsx( {\n\t\t\t'is-wide-widget': isWide,\n\t\t} ),\n\t} );\n\n\treturn (\n\t\t<div { ...blockProps }>\n\t\t\t{ ! id && ! idBase ? (\n\t\t\t\t<Empty { ...props } />\n\t\t\t) : (\n\t\t\t\t<NotEmpty { ...props } />\n\t\t\t) }\n\t\t</div>\n\t);\n}\n\nfunction Empty( { attributes: { id, idBase }, setAttributes } ) {\n\treturn (\n\t\t<Placeholder\n\t\t\ticon={ <BlockIcon icon={ brushIcon } /> }\n\t\t\tlabel={ __( 'Legacy Widget' ) }\n\t\t>\n\t\t\t<Flex>\n\t\t\t\t<FlexBlock>\n\t\t\t\t\t<WidgetTypeSelector\n\t\t\t\t\t\tselectedId={ id ?? idBase }\n\t\t\t\t\t\tonSelect={ ( { selectedId, isMulti } ) => {\n\t\t\t\t\t\t\tif ( ! selectedId ) {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tid: null,\n\t\t\t\t\t\t\t\t\tidBase: null,\n\t\t\t\t\t\t\t\t\tinstance: null,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} else if ( isMulti ) {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tid: null,\n\t\t\t\t\t\t\t\t\tidBase: selectedId,\n\t\t\t\t\t\t\t\t\tinstance: {},\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tid: selectedId,\n\t\t\t\t\t\t\t\t\tidBase: null,\n\t\t\t\t\t\t\t\t\tinstance: null,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t/>\n\t\t\t\t</FlexBlock>\n\t\t\t</Flex>\n\t\t</Placeholder>\n\t);\n}\n\nfunction NotEmpty( {\n\tattributes: { id, idBase, instance },\n\tsetAttributes,\n\tclientId,\n\tisSelected,\n\tisWide = false,\n} ) {\n\tconst [ hasPreview, setHasPreview ] = useState( null );\n\n\tconst widgetTypeId = id ?? idBase;\n\tconst { record: widgetType, hasResolved: hasResolvedWidgetType } =\n\t\tuseEntityRecord( 'root', 'widgetType', widgetTypeId );\n\n\tconst isNavigationMode = useSelect(\n\t\t( select ) => select( blockEditorStore ).isNavigationMode(),\n\t\t[]\n\t);\n\n\tconst setInstance = useCallback( ( nextInstance ) => {\n\t\tsetAttributes( { instance: nextInstance } );\n\t}, [] );\n\n\tif ( ! widgetType && hasResolvedWidgetType ) {\n\t\treturn (\n\t\t\t<Placeholder\n\t\t\t\ticon={ <BlockIcon icon={ brushIcon } /> }\n\t\t\t\tlabel={ __( 'Legacy Widget' ) }\n\t\t\t>\n\t\t\t\t{ __( 'Widget is missing.' ) }\n\t\t\t</Placeholder>\n\t\t);\n\t}\n\n\tif ( ! hasResolvedWidgetType ) {\n\t\treturn (\n\t\t\t<Placeholder>\n\t\t\t\t<Spinner />\n\t\t\t</Placeholder>\n\t\t);\n\t}\n\n\tconst mode =\n\t\tidBase && ( isNavigationMode || ! isSelected ) ? 'preview' : 'edit';\n\n\treturn (\n\t\t<>\n\t\t\t{ idBase === 'text' && (\n\t\t\t\t<BlockControls group=\"other\">\n\t\t\t\t\t<ConvertToBlocksButton\n\t\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\t\trawInstance={ instance.raw }\n\t\t\t\t\t/>\n\t\t\t\t</BlockControls>\n\t\t\t) }\n\n\t\t\t<InspectorControls>\n\t\t\t\t<InspectorCard\n\t\t\t\t\tname={ widgetType.name }\n\t\t\t\t\tdescription={ widgetType.description }\n\t\t\t\t/>\n\t\t\t</InspectorControls>\n\n\t\t\t<Form\n\t\t\t\ttitle={ widgetType.name }\n\t\t\t\tisVisible={ mode === 'edit' }\n\t\t\t\tid={ id }\n\t\t\t\tidBase={ idBase }\n\t\t\t\tinstance={ instance }\n\t\t\t\tisWide={ isWide }\n\t\t\t\tonChangeInstance={ setInstance }\n\t\t\t\tonChangeHasPreview={ setHasPreview }\n\t\t\t/>\n\n\t\t\t{ idBase && (\n\t\t\t\t<>\n\t\t\t\t\t{ hasPreview === null && mode === 'preview' && (\n\t\t\t\t\t\t<Placeholder>\n\t\t\t\t\t\t\t<Spinner />\n\t\t\t\t\t\t</Placeholder>\n\t\t\t\t\t) }\n\t\t\t\t\t{ hasPreview === true && (\n\t\t\t\t\t\t<Preview\n\t\t\t\t\t\t\tidBase={ idBase }\n\t\t\t\t\t\t\tinstance={ instance }\n\t\t\t\t\t\t\tisVisible={ mode === 'preview' }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\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,iBAAiB,QACjB6B,aAAA,CAACb,aAAa;IACbyC,IAAI,EAAGZ,UAAU,CAACY,IAAM;IACxBC,WAAW,EAAGb,UAAU,CAACa;EAAa,CACtC,CACiB,CAAC,EAEpB7B,aAAA,CAACZ,IAAI;IACJ0C,KAAK,EAAGd,UAAU,CAACY,IAAM;IACzBG,SAAS,EAAGR,IAAI,KAAK,MAAQ;IAC7B7B,EAAE,EAAGA,EAAI;IACTC,MAAM,EAAGA,MAAQ;IACjBc,QAAQ,EAAGA,QAAU;IACrBZ,MAAM,EAAGA,MAAQ;IACjBmC,gBAAgB,EAAGX,WAAa;IAChCY,kBAAkB,EAAGpB;EAAe,CACpC,CAAC,EAEAlB,MAAM,IACPK,aAAA,CAAAwB,QAAA,QACGZ,UAAU,KAAK,IAAI,IAAIW,IAAI,KAAK,SAAS,IAC1CvB,aAAA,CAACtB,WAAW,QACXsB,aAAA,CAACvB,OAAO,MAAE,CACE,CACb,EACCmC,UAAU,KAAK,IAAI,IACpBZ,aAAA,CAACX,OAAO;IACPM,MAAM,EAAGA,MAAQ;IACjBc,QAAQ,EAAGA,QAAU;IACrBsB,SAAS,EAAGR,IAAI,KAAK;EAAW,CAChC,CACD,EACCX,UAAU,KAAK,KAAK,IAAIW,IAAI,KAAK,SAAS,IAC3CvB,aAAA,CAACV,SAAS;IAACsC,IAAI,EAAGZ,UAAU,CAACY;EAAM,CAAE,CAErC,CAEF,CAAC;AAEL","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@ import { createElement, Fragment } from "react";
|
|
|
2
2
|
/**
|
|
3
3
|
* External dependencies
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
5
|
+
import clsx from 'clsx';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
@@ -86,7 +86,7 @@ export default function Preview({
|
|
|
86
86
|
};
|
|
87
87
|
}, [isLoaded]);
|
|
88
88
|
return createElement(Fragment, null, isVisible && !isLoaded && createElement(Placeholder, null, createElement(Spinner, null)), createElement("div", {
|
|
89
|
-
className:
|
|
89
|
+
className: clsx('wp-block-legacy-widget__edit-preview', {
|
|
90
90
|
'is-offscreen': !isVisible || !isLoaded
|
|
91
91
|
})
|
|
92
92
|
}, createElement(Disabled, null, createElement("iframe", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["clsx","useRefEffect","useEffect","useState","Disabled","Placeholder","Spinner","__","apiFetch","Preview","idBase","instance","isVisible","isLoaded","setIsLoaded","srcDoc","setSrcDoc","abortController","window","AbortController","undefined","fetchPreviewHTML","restRoute","path","method","signal","data","then","response","preview","catch","error","name","abort","ref","iframe","setHeight","_iframe$contentDocume","_iframe$contentDocume2","height","Math","max","contentDocument","documentElement","offsetHeight","body","style","IntersectionObserver","ownerDocument","defaultView","intersectionObserver","entry","isIntersecting","threshold","observe","addEventListener","disconnect","removeEventListener","createElement","Fragment","className","tabIndex","title","onLoad","event","target","overflow"],"sources":["@wordpress/widgets/src/blocks/legacy-widget/edit/preview.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { useRefEffect } from '@wordpress/compose';\nimport { useEffect, useState } from '@wordpress/element';\nimport { Disabled, Placeholder, Spinner } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\n\nexport default function Preview( { idBase, instance, isVisible } ) {\n\tconst [ isLoaded, setIsLoaded ] = useState( false );\n\tconst [ srcDoc, setSrcDoc ] = useState( '' );\n\n\tuseEffect( () => {\n\t\tconst abortController =\n\t\t\ttypeof window.AbortController === 'undefined'\n\t\t\t\t? undefined\n\t\t\t\t: new window.AbortController();\n\n\t\tasync function fetchPreviewHTML() {\n\t\t\tconst restRoute = `/wp/v2/widget-types/${ idBase }/render`;\n\t\t\treturn await apiFetch( {\n\t\t\t\tpath: restRoute,\n\t\t\t\tmethod: 'POST',\n\t\t\t\tsignal: abortController?.signal,\n\t\t\t\tdata: instance ? { instance } : {},\n\t\t\t} );\n\t\t}\n\n\t\tfetchPreviewHTML()\n\t\t\t.then( ( response ) => {\n\t\t\t\tsetSrcDoc( response.preview );\n\t\t\t} )\n\t\t\t.catch( ( error ) => {\n\t\t\t\tif ( 'AbortError' === error.name ) {\n\t\t\t\t\t// We don't want to log aborted requests.\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t} );\n\n\t\treturn () => abortController?.abort();\n\t}, [ idBase, instance ] );\n\n\t// Resize the iframe on either the load event, or when the iframe becomes visible.\n\tconst ref = useRefEffect(\n\t\t( iframe ) => {\n\t\t\t// Only set height if the iframe is loaded,\n\t\t\t// or it will grow to an unexpected large height in Safari if it's hidden initially.\n\t\t\tif ( ! isLoaded ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// If the preview frame has another origin then this won't work.\n\t\t\t// One possible solution is to add custom script to call `postMessage` in the preview frame.\n\t\t\t// Or, better yet, we migrate away from iframe.\n\t\t\tfunction setHeight() {\n\t\t\t\t// Pick the maximum of these two values to account for margin collapsing.\n\t\t\t\tconst height = Math.max(\n\t\t\t\t\tiframe.contentDocument.documentElement?.offsetHeight ?? 0,\n\t\t\t\t\tiframe.contentDocument.body?.offsetHeight ?? 0\n\t\t\t\t);\n\n\t\t\t\t// Fallback to a height of 100px if the height cannot be determined.\n\t\t\t\t// This ensures the block is still selectable. 100px should hopefully\n\t\t\t\t// be not so big that it's annoying, and not so small that nothing\n\t\t\t\t// can be seen.\n\t\t\t\tiframe.style.height = `${ height !== 0 ? height : 100 }px`;\n\t\t\t}\n\n\t\t\tconst { IntersectionObserver } = iframe.ownerDocument.defaultView;\n\n\t\t\t// Observe for intersections that might cause a change in the height of\n\t\t\t// the iframe, e.g. a Widget Area becoming expanded.\n\t\t\tconst intersectionObserver = new IntersectionObserver(\n\t\t\t\t( [ entry ] ) => {\n\t\t\t\t\tif ( entry.isIntersecting ) {\n\t\t\t\t\t\tsetHeight();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tthreshold: 1,\n\t\t\t\t}\n\t\t\t);\n\t\t\tintersectionObserver.observe( iframe );\n\n\t\t\tiframe.addEventListener( 'load', setHeight );\n\n\t\t\treturn () => {\n\t\t\t\tintersectionObserver.disconnect();\n\t\t\t\tiframe.removeEventListener( 'load', setHeight );\n\t\t\t};\n\t\t},\n\t\t[ isLoaded ]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t{ /*\n\t\t\tWhile the iframe contents are loading, we move the iframe off-screen\n\t\t\tand display a placeholder instead. This ensures that the user\n\t\t\tdoesn't see the iframe resize (which looks really janky). We have to\n\t\t\tmove the iframe off-screen instead of hiding it because web browsers\n\t\t\twill not trigger onLoad if the iframe is hidden.\n\t\t\t*/ }\n\t\t\t{ isVisible && ! isLoaded && (\n\t\t\t\t<Placeholder>\n\t\t\t\t\t<Spinner />\n\t\t\t\t</Placeholder>\n\t\t\t) }\n\t\t\t<div\n\t\t\t\tclassName={ clsx( 'wp-block-legacy-widget__edit-preview', {\n\t\t\t\t\t'is-offscreen': ! isVisible || ! isLoaded,\n\t\t\t\t} ) }\n\t\t\t>\n\t\t\t\t<Disabled>\n\t\t\t\t\t{ /*\n\t\t\t\t\tWe use an iframe so that the widget has an opportunity to\n\t\t\t\t\tload scripts and styles that it needs to run.\n\t\t\t\t\t*/ }\n\t\t\t\t\t<iframe\n\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\tclassName=\"wp-block-legacy-widget__edit-preview-iframe\"\n\t\t\t\t\t\ttabIndex=\"-1\"\n\t\t\t\t\t\ttitle={ __( 'Legacy Widget Preview' ) }\n\t\t\t\t\t\tsrcDoc={ srcDoc }\n\t\t\t\t\t\tonLoad={ ( event ) => {\n\t\t\t\t\t\t\t// To hide the scrollbars of the preview frame for some edge cases,\n\t\t\t\t\t\t\t// such as negative margins in the Gallery Legacy Widget.\n\t\t\t\t\t\t\t// It can't be scrolled anyway.\n\t\t\t\t\t\t\t// TODO: Ideally, this should be fixed in core.\n\t\t\t\t\t\t\tevent.target.contentDocument.body.style.overflow =\n\t\t\t\t\t\t\t\t'hidden';\n\n\t\t\t\t\t\t\tsetIsLoaded( true );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\theight={ 100 }\n\t\t\t\t\t/>\n\t\t\t\t</Disabled>\n\t\t\t</div>\n\t\t</>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,SAAS,EAAEC,QAAQ,QAAQ,oBAAoB;AACxD,SAASC,QAAQ,EAAEC,WAAW,EAAEC,OAAO,QAAQ,uBAAuB;AACtE,SAASC,EAAE,QAAQ,iBAAiB;AACpC,OAAOC,QAAQ,MAAM,sBAAsB;AAE3C,eAAe,SAASC,OAAOA,CAAE;EAAEC,MAAM;EAAEC,QAAQ;EAAEC;AAAU,CAAC,EAAG;EAClE,MAAM,CAAEC,QAAQ,EAAEC,WAAW,CAAE,GAAGX,QAAQ,CAAE,KAAM,CAAC;EACnD,MAAM,CAAEY,MAAM,EAAEC,SAAS,CAAE,GAAGb,QAAQ,CAAE,EAAG,CAAC;EAE5CD,SAAS,CAAE,MAAM;IAChB,MAAMe,eAAe,GACpB,OAAOC,MAAM,CAACC,eAAe,KAAK,WAAW,GAC1CC,SAAS,GACT,IAAIF,MAAM,CAACC,eAAe,CAAC,CAAC;IAEhC,eAAeE,gBAAgBA,CAAA,EAAG;MACjC,MAAMC,SAAS,GAAI,uBAAuBZ,MAAQ,SAAQ;MAC1D,OAAO,MAAMF,QAAQ,CAAE;QACtBe,IAAI,EAAED,SAAS;QACfE,MAAM,EAAE,MAAM;QACdC,MAAM,EAAER,eAAe,EAAEQ,MAAM;QAC/BC,IAAI,EAAEf,QAAQ,GAAG;UAAEA;QAAS,CAAC,GAAG,CAAC;MAClC,CAAE,CAAC;IACJ;IAEA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,CACD,CAAC;IACDH,oBAAoB,CAACI,OAAO,CAAEnB,MAAO,CAAC;IAEtCA,MAAM,CAACoB,gBAAgB,CAAE,MAAM,EAAEnB,SAAU,CAAC;IAE5C,OAAO,MAAM;MACZc,oBAAoB,CAACM,UAAU,CAAC,CAAC;MACjCrB,MAAM,CAACsB,mBAAmB,CAAE,MAAM,EAAErB,SAAU,CAAC;IAChD,CAAC;EACF,CAAC,EACD,CAAEvB,QAAQ,CACX,CAAC;EAED,OACC6C,aAAA,CAAAC,QAAA,QAQG/C,SAAS,IAAI,CAAEC,QAAQ,IACxB6C,aAAA,CAACrD,WAAW,QACXqD,aAAA,CAACpD,OAAO,MAAE,CACE,CACb,EACDoD,aAAA;IACCE,SAAS,EAAG5D,IAAI,CAAE,sCAAsC,EAAE;MACzD,cAAc,EAAE,CAAEY,SAAS,IAAI,CAAEC;IAClC,CAAE;EAAG,GAEL6C,aAAA,CAACtD,QAAQ,QAKRsD,aAAA;IACCxB,GAAG,EAAGA,GAAK;IACX0B,SAAS,EAAC,6CAA6C;IACvDC,QAAQ,EAAC,IAAI;IACbC,KAAK,EAAGvD,EAAE,CAAE,uBAAwB,CAAG;IACvCQ,MAAM,EAAGA,MAAQ;IACjBgD,MAAM,EAAKC,KAAK,IAAM;MACrB;MACA;MACA;MACA;MACAA,KAAK,CAACC,MAAM,CAACvB,eAAe,CAACG,IAAI,CAACC,KAAK,CAACoB,QAAQ,GAC/C,QAAQ;MAETpD,WAAW,CAAE,IAAK,CAAC;IACpB,CAAG;IACHyB,MAAM,EAAG;EAAK,CACd,CACQ,CACN,CACJ,CAAC;AAEL","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/widgets",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.35.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",
|
|
@@ -21,18 +21,18 @@
|
|
|
21
21
|
"react-native": "src/index",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@babel/runtime": "^7.16.0",
|
|
24
|
-
"@wordpress/api-fetch": "^6.
|
|
25
|
-
"@wordpress/block-editor": "^12.
|
|
26
|
-
"@wordpress/blocks": "^12.
|
|
27
|
-
"@wordpress/components": "^27.
|
|
28
|
-
"@wordpress/compose": "^6.
|
|
29
|
-
"@wordpress/core-data": "^6.
|
|
30
|
-
"@wordpress/data": "^9.
|
|
31
|
-
"@wordpress/element": "^5.
|
|
32
|
-
"@wordpress/i18n": "^4.
|
|
33
|
-
"@wordpress/icons": "^9.
|
|
34
|
-
"@wordpress/notices": "^4.
|
|
35
|
-
"
|
|
24
|
+
"@wordpress/api-fetch": "^6.55.0",
|
|
25
|
+
"@wordpress/block-editor": "^12.26.0",
|
|
26
|
+
"@wordpress/blocks": "^12.35.0",
|
|
27
|
+
"@wordpress/components": "^27.6.0",
|
|
28
|
+
"@wordpress/compose": "^6.35.0",
|
|
29
|
+
"@wordpress/core-data": "^6.35.0",
|
|
30
|
+
"@wordpress/data": "^9.28.0",
|
|
31
|
+
"@wordpress/element": "^5.35.0",
|
|
32
|
+
"@wordpress/i18n": "^4.58.0",
|
|
33
|
+
"@wordpress/icons": "^9.49.0",
|
|
34
|
+
"@wordpress/notices": "^4.26.0",
|
|
35
|
+
"clsx": "^2.1.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": "^18.0.0",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "42f38f287506a6b3ed8ccba839b18ad066821044"
|
|
45
45
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import clsx from 'clsx';
|
|
5
5
|
/**
|
|
6
6
|
* WordPress dependencies
|
|
7
7
|
*/
|
|
@@ -92,7 +92,7 @@ export default function Form( {
|
|
|
92
92
|
if ( isWide && isMediumLargeViewport ) {
|
|
93
93
|
return (
|
|
94
94
|
<div
|
|
95
|
-
className={
|
|
95
|
+
className={ clsx( {
|
|
96
96
|
'wp-block-legacy-widget__container': isVisible,
|
|
97
97
|
} ) }
|
|
98
98
|
>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import clsx from 'clsx';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -35,7 +35,7 @@ export default function Edit( props ) {
|
|
|
35
35
|
const { isWide = false } = props;
|
|
36
36
|
|
|
37
37
|
const blockProps = useBlockProps( {
|
|
38
|
-
className:
|
|
38
|
+
className: clsx( {
|
|
39
39
|
'is-wide-widget': isWide,
|
|
40
40
|
} ),
|
|
41
41
|
} );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import clsx from 'clsx';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -113,12 +113,9 @@ export default function Preview( { idBase, instance, isVisible } ) {
|
|
|
113
113
|
</Placeholder>
|
|
114
114
|
) }
|
|
115
115
|
<div
|
|
116
|
-
className={
|
|
117
|
-
'
|
|
118
|
-
|
|
119
|
-
'is-offscreen': ! isVisible || ! isLoaded,
|
|
120
|
-
}
|
|
121
|
-
) }
|
|
116
|
+
className={ clsx( 'wp-block-legacy-widget__edit-preview', {
|
|
117
|
+
'is-offscreen': ! isVisible || ! isLoaded,
|
|
118
|
+
} ) }
|
|
122
119
|
>
|
|
123
120
|
<Disabled>
|
|
124
121
|
{ /*
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Renders the 'core/legacy-widget' block.
|
|
10
10
|
*
|
|
11
|
+
* @since 5.8.0
|
|
12
|
+
*
|
|
11
13
|
* @global int $wp_widget_factory.
|
|
12
14
|
*
|
|
13
15
|
* @param array $attributes The block attributes.
|
|
@@ -56,6 +58,8 @@ function render_block_core_legacy_widget( $attributes ) {
|
|
|
56
58
|
|
|
57
59
|
/**
|
|
58
60
|
* Registers the 'core/legacy-widget' block.
|
|
61
|
+
*
|
|
62
|
+
* @since 5.8.0
|
|
59
63
|
*/
|
|
60
64
|
function register_block_core_legacy_widget() {
|
|
61
65
|
register_block_type_from_metadata(
|
|
@@ -72,6 +76,8 @@ add_action( 'init', 'register_block_core_legacy_widget' );
|
|
|
72
76
|
* Intercepts any request with legacy-widget-preview in the query param and, if
|
|
73
77
|
* set, renders a page containing a preview of the requested Legacy Widget
|
|
74
78
|
* block.
|
|
79
|
+
*
|
|
80
|
+
* @since 5.8.0
|
|
75
81
|
*/
|
|
76
82
|
function handle_legacy_widget_preview_iframe() {
|
|
77
83
|
if ( empty( $_GET['legacy-widget-preview'] ) ) {
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Renders the 'core/widget-group' block.
|
|
10
10
|
*
|
|
11
|
+
* @since 5.9.0
|
|
12
|
+
*
|
|
11
13
|
* @global array $wp_registered_sidebars
|
|
12
14
|
* @global int|string $_sidebar_being_rendered
|
|
13
15
|
*
|
|
@@ -45,6 +47,8 @@ function render_block_core_widget_group( $attributes, $content, $block ) {
|
|
|
45
47
|
|
|
46
48
|
/**
|
|
47
49
|
* Registers the 'core/widget-group' block.
|
|
50
|
+
*
|
|
51
|
+
* @since 5.9.0
|
|
48
52
|
*/
|
|
49
53
|
function register_block_core_widget_group() {
|
|
50
54
|
register_block_type_from_metadata(
|
|
@@ -62,6 +66,8 @@ add_action( 'init', 'register_block_core_widget_group' );
|
|
|
62
66
|
* it. This lets us get to the current sidebar in
|
|
63
67
|
* render_block_core_widget_group().
|
|
64
68
|
*
|
|
69
|
+
* @since 5.9.0
|
|
70
|
+
*
|
|
65
71
|
* @global int|string $_sidebar_being_rendered
|
|
66
72
|
*
|
|
67
73
|
* @param int|string $index Index, name, or ID of the dynamic sidebar.
|
|
@@ -76,6 +82,8 @@ add_action( 'dynamic_sidebar_before', 'note_sidebar_being_rendered' );
|
|
|
76
82
|
* Clear whatever we set in note_sidebar_being_rendered() after WordPress
|
|
77
83
|
* finishes rendering a sidebar.
|
|
78
84
|
*
|
|
85
|
+
* @since 5.9.0
|
|
86
|
+
*
|
|
79
87
|
* @global int|string $_sidebar_being_rendered
|
|
80
88
|
*/
|
|
81
89
|
function discard_sidebar_being_rendered() {
|