@wordpress/widgets 4.32.0 → 4.32.1-next.ff1cebbba.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/blocks/legacy-widget/block.json +29 -0
- package/build/blocks/legacy-widget/edit/control.js +137 -167
- package/build/blocks/legacy-widget/edit/control.js.map +7 -1
- package/build/blocks/legacy-widget/edit/convert-to-blocks-button.js +51 -39
- package/build/blocks/legacy-widget/edit/convert-to-blocks-button.js.map +7 -1
- package/build/blocks/legacy-widget/edit/form.js +105 -75
- package/build/blocks/legacy-widget/edit/form.js.map +7 -1
- package/build/blocks/legacy-widget/edit/index.js +121 -131
- package/build/blocks/legacy-widget/edit/index.js.map +7 -1
- package/build/blocks/legacy-widget/edit/inspector-card.js +28 -20
- package/build/blocks/legacy-widget/edit/inspector-card.js.map +7 -1
- package/build/blocks/legacy-widget/edit/no-preview.js +29 -23
- package/build/blocks/legacy-widget/edit/no-preview.js.map +7 -1
- package/build/blocks/legacy-widget/edit/preview.js +107 -108
- package/build/blocks/legacy-widget/edit/preview.js.map +7 -1
- package/build/blocks/legacy-widget/edit/widget-type-selector.js +61 -52
- package/build/blocks/legacy-widget/edit/widget-type-selector.js.map +7 -1
- package/build/blocks/legacy-widget/index.js +49 -53
- package/build/blocks/legacy-widget/index.js.map +7 -1
- package/build/blocks/legacy-widget/transforms.js +189 -198
- package/build/blocks/legacy-widget/transforms.js.map +7 -1
- package/build/blocks/widget-group/block.json +20 -0
- package/build/blocks/widget-group/deprecated.js +38 -24
- package/build/blocks/widget-group/deprecated.js.map +7 -1
- package/build/blocks/widget-group/edit.js +63 -67
- package/build/blocks/widget-group/edit.js.map +7 -1
- package/build/blocks/widget-group/index.js +93 -80
- package/build/blocks/widget-group/index.js.map +7 -1
- package/build/blocks/widget-group/save.js +36 -25
- package/build/blocks/widget-group/save.js.map +7 -1
- package/build/components/index.js +36 -12
- package/build/components/index.js.map +7 -1
- package/build/components/move-to-widget-area/index.js +48 -37
- package/build/components/move-to-widget-area/index.js.map +7 -1
- package/build/index.js +67 -98
- package/build/index.js.map +7 -1
- package/build/register-legacy-widget-variations.js +42 -30
- package/build/register-legacy-widget-variations.js.map +7 -1
- package/build/utils.js +29 -29
- package/build/utils.js.map +7 -1
- package/build-module/blocks/legacy-widget/block.json +29 -0
- package/build-module/blocks/legacy-widget/edit/control.js +107 -158
- package/build-module/blocks/legacy-widget/edit/control.js.map +7 -1
- package/build-module/blocks/legacy-widget/edit/convert-to-blocks-button.js +33 -33
- package/build-module/blocks/legacy-widget/edit/convert-to-blocks-button.js.map +7 -1
- package/build-module/blocks/legacy-widget/edit/form.js +75 -64
- package/build-module/blocks/legacy-widget/edit/form.js.map +7 -1
- package/build-module/blocks/legacy-widget/edit/index.js +96 -122
- package/build-module/blocks/legacy-widget/edit/index.js.map +7 -1
- package/build-module/blocks/legacy-widget/edit/inspector-card.js +10 -15
- package/build-module/blocks/legacy-widget/edit/inspector-card.js.map +7 -1
- package/build-module/blocks/legacy-widget/edit/no-preview.js +11 -17
- package/build-module/blocks/legacy-widget/edit/no-preview.js.map +7 -1
- package/build-module/blocks/legacy-widget/edit/preview.js +76 -98
- package/build-module/blocks/legacy-widget/edit/preview.js.map +7 -1
- package/build-module/blocks/legacy-widget/edit/widget-type-selector.js +43 -46
- package/build-module/blocks/legacy-widget/edit/widget-type-selector.js.map +7 -1
- package/build-module/blocks/legacy-widget/index.js +12 -45
- package/build-module/blocks/legacy-widget/index.js.map +7 -1
- package/build-module/blocks/legacy-widget/transforms.js +171 -192
- package/build-module/blocks/legacy-widget/transforms.js.map +7 -1
- package/build-module/blocks/widget-group/block.json +20 -0
- package/build-module/blocks/widget-group/deprecated.js +20 -18
- package/build-module/blocks/widget-group/deprecated.js.map +7 -1
- package/build-module/blocks/widget-group/edit.js +53 -62
- package/build-module/blocks/widget-group/edit.js.map +7 -1
- package/build-module/blocks/widget-group/index.js +55 -71
- package/build-module/blocks/widget-group/index.js.map +7 -1
- package/build-module/blocks/widget-group/save.js +18 -19
- package/build-module/blocks/widget-group/save.js.map +7 -1
- package/build-module/components/index.js +5 -2
- package/build-module/components/index.js.map +7 -1
- package/build-module/components/move-to-widget-area/index.js +37 -32
- package/build-module/components/move-to-widget-area/index.js.map +7 -1
- package/build-module/index.js +34 -60
- package/build-module/index.js.map +7 -1
- package/build-module/register-legacy-widget-variations.js +24 -24
- package/build-module/register-legacy-widget-variations.js.map +7 -1
- package/build-module/utils.js +8 -25
- package/build-module/utils.js.map +7 -1
- package/build-style/style-rtl.css +10 -145
- package/build-style/style.css +10 -145
- package/package.json +21 -14
- package/src/blocks/legacy-widget/editor.scss +3 -0
- package/src/blocks/widget-group/editor.scss +3 -0
- package/src/style.scss +3 -2
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["_clsx","_interopRequireDefault","require","_blockEditor","_components","_icons","_i18n","_element","_coreData","_widgetTypeSelector","_inspectorCard","_form","_preview","_noPreview","_convertToBlocksButton","_jsxRuntime","Edit","props","id","idBase","attributes","isWide","blockProps","useBlockProps","className","clsx","jsx","children","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","setInstance","useCallback","nextInstance","Spinner","mode","jsxs","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} 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 { 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 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 = idBase && ! 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,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,YAAA,GAAAD,OAAA;AAMA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAKA,IAAAO,mBAAA,GAAAR,sBAAA,CAAAC,OAAA;AACA,IAAAQ,cAAA,GAAAT,sBAAA,CAAAC,OAAA;AACA,IAAAS,KAAA,GAAAV,sBAAA,CAAAC,OAAA;AACA,IAAAU,QAAA,GAAAX,sBAAA,CAAAC,OAAA;AACA,IAAAW,UAAA,GAAAZ,sBAAA,CAAAC,OAAA;AACA,IA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dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseBlockProps,\n\tBlockControls,\n\tInspectorControls,\n\tBlockIcon,\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 { 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 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 = idBase && ! 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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2CI;AAxCJ,kBAAiB;AAKjB,0BAKO;AACP,wBAAsD;AACtD,mBAAmC;AACnC,kBAAmB;AACnB,qBAAsC;AACtC,uBAAgC;AAKhC,kCAA+B;AAC/B,4BAA0B;AAC1B,kBAAiB;AACjB,qBAAoB;AACpB,wBAAsB;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WAAY,SAAS;AAAA;AAAA,MACtB;AAAA,MAEC,eAAe,SAAS,SAAS,aAClC,4CAAC,kBAAAC,SAAA,EAAU,MAAO,WAAW,MAAO;AAAA,OAEtC;AAAA,KAEF;AAEF;",
|
|
6
|
+
"names": ["clsx", "brushIcon", "WidgetTypeSelector", "ConvertToBlocksButton", "InspectorCard", "Form", "Preview", "NoPreview"]
|
|
7
|
+
}
|
|
@@ -1,22 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var inspector_card_exports = {};
|
|
19
|
+
__export(inspector_card_exports, {
|
|
20
|
+
default: () => InspectorCard
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
function InspectorCard({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
className: "wp-block-legacy-widget-inspector-card",
|
|
14
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
|
|
15
|
-
className: "wp-block-legacy-widget-inspector-card__name",
|
|
16
|
-
children: name
|
|
17
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
18
|
-
children: description
|
|
19
|
-
})]
|
|
20
|
-
});
|
|
22
|
+
module.exports = __toCommonJS(inspector_card_exports);
|
|
23
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
|
+
function InspectorCard({ name, description }) {
|
|
25
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "wp-block-legacy-widget-inspector-card", children: [
|
|
26
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { className: "wp-block-legacy-widget-inspector-card__name", children: name }),
|
|
27
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: description })
|
|
28
|
+
] });
|
|
21
29
|
}
|
|
22
|
-
//# sourceMappingURL=inspector-card.js.map
|
|
30
|
+
//# sourceMappingURL=inspector-card.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/blocks/legacy-widget/edit/inspector-card.js"],
|
|
4
|
+
"sourcesContent": ["export default function InspectorCard( { name, description } ) {\n\treturn (\n\t\t<div className=\"wp-block-legacy-widget-inspector-card\">\n\t\t\t<h3 className=\"wp-block-legacy-widget-inspector-card__name\">\n\t\t\t\t{ name }\n\t\t\t</h3>\n\t\t\t<span>{ description }</span>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEE;AAFa,SAAR,cAAgC,EAAE,MAAM,YAAY,GAAI;AAC9D,SACC,6CAAC,SAAI,WAAU,yCACd;AAAA,gDAAC,QAAG,WAAU,+CACX,gBACH;AAAA,IACA,4CAAC,UAAO,uBAAa;AAAA,KACtB;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var no_preview_exports = {};
|
|
19
|
+
__export(no_preview_exports, {
|
|
20
|
+
default: () => NoPreview
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
name
|
|
15
|
-
}) {
|
|
16
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
17
|
-
className: "wp-block-legacy-widget__edit-no-preview",
|
|
18
|
-
children: [name && /*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
|
|
19
|
-
children: name
|
|
20
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
|
|
21
|
-
children: (0, _i18n.__)('No preview available.')
|
|
22
|
-
})]
|
|
23
|
-
});
|
|
22
|
+
module.exports = __toCommonJS(no_preview_exports);
|
|
23
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
|
+
var import_i18n = require("@wordpress/i18n");
|
|
25
|
+
function NoPreview({ name }) {
|
|
26
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "wp-block-legacy-widget__edit-no-preview", children: [
|
|
27
|
+
name && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { children: name }),
|
|
28
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: (0, import_i18n.__)("No preview available.") })
|
|
29
|
+
] });
|
|
24
30
|
}
|
|
25
|
-
//# sourceMappingURL=no-preview.js.map
|
|
31
|
+
//# sourceMappingURL=no-preview.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/blocks/legacy-widget/edit/no-preview.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\n\nexport default function NoPreview( { name } ) {\n\treturn (\n\t\t<div className=\"wp-block-legacy-widget__edit-no-preview\">\n\t\t\t{ name && <h3>{ name }</h3> }\n\t\t\t<p>{ __( 'No preview available.' ) }</p>\n\t\t</div>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOE;AAJF,kBAAmB;AAEJ,SAAR,UAA4B,EAAE,KAAK,GAAI;AAC7C,SACC,6CAAC,SAAI,WAAU,2CACZ;AAAA,YAAQ,4CAAC,QAAK,gBAAM;AAAA,IACtB,4CAAC,OAAI,8BAAI,uBAAwB,GAAG;AAAA,KACrC;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,124 +1,123 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var preview_exports = {};
|
|
29
|
+
__export(preview_exports, {
|
|
30
|
+
default: () => Preview
|
|
6
31
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* WordPress dependencies
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
function Preview({
|
|
24
|
-
idBase,
|
|
25
|
-
instance,
|
|
26
|
-
isVisible
|
|
27
|
-
}) {
|
|
28
|
-
const [isLoaded, setIsLoaded] = (0, _element.useState)(false);
|
|
29
|
-
const [srcDoc, setSrcDoc] = (0, _element.useState)('');
|
|
30
|
-
(0, _element.useEffect)(() => {
|
|
31
|
-
const abortController = typeof window.AbortController === 'undefined' ? undefined : new window.AbortController();
|
|
32
|
+
module.exports = __toCommonJS(preview_exports);
|
|
33
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
+
var import_clsx = __toESM(require("clsx"));
|
|
35
|
+
var import_compose = require("@wordpress/compose");
|
|
36
|
+
var import_element = require("@wordpress/element");
|
|
37
|
+
var import_components = require("@wordpress/components");
|
|
38
|
+
var import_i18n = require("@wordpress/i18n");
|
|
39
|
+
var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
|
|
40
|
+
function Preview({ idBase, instance, isVisible }) {
|
|
41
|
+
const [isLoaded, setIsLoaded] = (0, import_element.useState)(false);
|
|
42
|
+
const [srcDoc, setSrcDoc] = (0, import_element.useState)("");
|
|
43
|
+
(0, import_element.useEffect)(() => {
|
|
44
|
+
const abortController = typeof window.AbortController === "undefined" ? void 0 : new window.AbortController();
|
|
32
45
|
async function fetchPreviewHTML() {
|
|
33
46
|
const restRoute = `/wp/v2/widget-types/${idBase}/render`;
|
|
34
|
-
return await (0,
|
|
47
|
+
return await (0, import_api_fetch.default)({
|
|
35
48
|
path: restRoute,
|
|
36
|
-
method:
|
|
49
|
+
method: "POST",
|
|
37
50
|
signal: abortController?.signal,
|
|
38
|
-
data: instance ? {
|
|
39
|
-
instance
|
|
40
|
-
} : {}
|
|
51
|
+
data: instance ? { instance } : {}
|
|
41
52
|
});
|
|
42
53
|
}
|
|
43
|
-
fetchPreviewHTML().then(response => {
|
|
54
|
+
fetchPreviewHTML().then((response) => {
|
|
44
55
|
setSrcDoc(response.preview);
|
|
45
|
-
}).catch(error => {
|
|
46
|
-
if (
|
|
47
|
-
// We don't want to log aborted requests.
|
|
56
|
+
}).catch((error) => {
|
|
57
|
+
if ("AbortError" === error.name) {
|
|
48
58
|
return;
|
|
49
59
|
}
|
|
50
60
|
throw error;
|
|
51
61
|
});
|
|
52
62
|
return () => abortController?.abort();
|
|
53
63
|
}, [idBase, instance]);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// or it will grow to an unexpected large height in Safari if it's hidden initially.
|
|
59
|
-
if (!isLoaded) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
// If the preview frame has another origin then this won't work.
|
|
63
|
-
// One possible solution is to add custom script to call `postMessage` in the preview frame.
|
|
64
|
-
// Or, better yet, we migrate away from iframe.
|
|
65
|
-
function setHeight() {
|
|
66
|
-
var _iframe$contentDocume, _iframe$contentDocume2;
|
|
67
|
-
// Pick the maximum of these two values to account for margin collapsing.
|
|
68
|
-
const height = Math.max((_iframe$contentDocume = iframe.contentDocument.documentElement?.offsetHeight) !== null && _iframe$contentDocume !== void 0 ? _iframe$contentDocume : 0, (_iframe$contentDocume2 = iframe.contentDocument.body?.offsetHeight) !== null && _iframe$contentDocume2 !== void 0 ? _iframe$contentDocume2 : 0);
|
|
69
|
-
|
|
70
|
-
// Fallback to a height of 100px if the height cannot be determined.
|
|
71
|
-
// This ensures the block is still selectable. 100px should hopefully
|
|
72
|
-
// be not so big that it's annoying, and not so small that nothing
|
|
73
|
-
// can be seen.
|
|
74
|
-
iframe.style.height = `${height !== 0 ? height : 100}px`;
|
|
75
|
-
}
|
|
76
|
-
const {
|
|
77
|
-
IntersectionObserver
|
|
78
|
-
} = iframe.ownerDocument.defaultView;
|
|
79
|
-
|
|
80
|
-
// Observe for intersections that might cause a change in the height of
|
|
81
|
-
// the iframe, e.g. a Widget Area becoming expanded.
|
|
82
|
-
const intersectionObserver = new IntersectionObserver(([entry]) => {
|
|
83
|
-
if (entry.isIntersecting) {
|
|
84
|
-
setHeight();
|
|
64
|
+
const ref = (0, import_compose.useRefEffect)(
|
|
65
|
+
(iframe) => {
|
|
66
|
+
if (!isLoaded) {
|
|
67
|
+
return;
|
|
85
68
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
iframe.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
69
|
+
function setHeight() {
|
|
70
|
+
const height = Math.max(
|
|
71
|
+
iframe.contentDocument.documentElement?.offsetHeight ?? 0,
|
|
72
|
+
iframe.contentDocument.body?.offsetHeight ?? 0
|
|
73
|
+
);
|
|
74
|
+
iframe.style.height = `${height !== 0 ? height : 100}px`;
|
|
75
|
+
}
|
|
76
|
+
const { IntersectionObserver } = iframe.ownerDocument.defaultView;
|
|
77
|
+
const intersectionObserver = new IntersectionObserver(
|
|
78
|
+
([entry]) => {
|
|
79
|
+
if (entry.isIntersecting) {
|
|
80
|
+
setHeight();
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
threshold: 1
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
intersectionObserver.observe(iframe);
|
|
88
|
+
iframe.addEventListener("load", setHeight);
|
|
89
|
+
return () => {
|
|
90
|
+
intersectionObserver.disconnect();
|
|
91
|
+
iframe.removeEventListener("load", setHeight);
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
[isLoaded]
|
|
95
|
+
);
|
|
96
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
97
|
+
isVisible && !isLoaded && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Placeholder, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Spinner, {}) }),
|
|
98
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
99
|
+
"div",
|
|
100
|
+
{
|
|
101
|
+
className: (0, import_clsx.default)("wp-block-legacy-widget__edit-preview", {
|
|
102
|
+
"is-offscreen": !isVisible || !isLoaded
|
|
103
|
+
}),
|
|
104
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Disabled, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
105
|
+
"iframe",
|
|
106
|
+
{
|
|
107
|
+
ref,
|
|
108
|
+
className: "wp-block-legacy-widget__edit-preview-iframe",
|
|
109
|
+
tabIndex: "-1",
|
|
110
|
+
title: (0, import_i18n.__)("Legacy Widget Preview"),
|
|
111
|
+
srcDoc,
|
|
112
|
+
onLoad: (event) => {
|
|
113
|
+
event.target.contentDocument.body.style.overflow = "hidden";
|
|
114
|
+
setIsLoaded(true);
|
|
115
|
+
},
|
|
116
|
+
height: 100
|
|
117
|
+
}
|
|
118
|
+
) })
|
|
119
|
+
}
|
|
120
|
+
)
|
|
121
|
+
] });
|
|
123
122
|
}
|
|
124
|
-
//# sourceMappingURL=preview.js.map
|
|
123
|
+
//# sourceMappingURL=preview.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/blocks/legacy-widget/edit/preview.js"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqGE;AAlGF,kBAAiB;AAKjB,qBAA6B;AAC7B,qBAAoC;AACpC,wBAA+C;AAC/C,kBAAmB;AACnB,uBAAqB;AAEN,SAAR,QAA0B,EAAE,QAAQ,UAAU,UAAU,GAAI;AAClE,QAAM,CAAE,UAAU,WAAY,QAAI,yBAAU,KAAM;AAClD,QAAM,CAAE,QAAQ,SAAU,QAAI,yBAAU,EAAG;AAE3C,gCAAW,MAAM;AAChB,UAAM,kBACL,OAAO,OAAO,oBAAoB,cAC/B,SACA,IAAI,OAAO,gBAAgB;AAE/B,mBAAe,mBAAmB;AACjC,YAAM,YAAY,uBAAwB,MAAO;A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AAA;AAAA,QACA,eAAY,YAAAC,SAAM,wCAAwC;AAAA,UACzD,gBAAgB,CAAE,aAAa,CAAE;AAAA,QAClC,CAAE;AAAA,QAEF,sDAAC,8BAKA;AAAA,UAAC;AAAA;AAAA,YACA;AAAA,YACA,WAAU;AAAA,YACV,UAAS;AAAA,YACT,WAAQ,gBAAI,uBAAwB;AAAA,YACpC;AAAA,YACA,QAAS,CAAE,UAAW;AAKrB,oBAAM,OAAO,gBAAgB,KAAK,MAAM,WACvC;AAED,0BAAa,IAAK;AAAA,YACnB;AAAA,YACA,QAAS;AAAA;AAAA,QACV,GACD;AAAA;AAAA,IACD;AAAA,KACD;AAEF;",
|
|
6
|
+
"names": ["apiFetch", "clsx"]
|
|
7
|
+
}
|
|
@@ -1,61 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var widget_type_selector_exports = {};
|
|
19
|
+
__export(widget_type_selector_exports, {
|
|
20
|
+
default: () => WidgetTypeSelector
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
function WidgetTypeSelector({
|
|
18
|
-
selectedId,
|
|
19
|
-
onSelect
|
|
20
|
-
}) {
|
|
21
|
-
const widgetTypes = (0, _data.useSelect)(select => {
|
|
22
|
-
var _select$getSettings$w;
|
|
23
|
-
const hiddenIds = (_select$getSettings$w = select(_blockEditor.store).getSettings()?.widgetTypesToHideFromLegacyWidgetBlock) !== null && _select$getSettings$w !== void 0 ? _select$getSettings$w : [];
|
|
24
|
-
return select(_coreData.store).getWidgetTypes({
|
|
25
|
-
per_page: -1
|
|
26
|
-
})?.filter(widgetType => !hiddenIds.includes(widgetType.id));
|
|
22
|
+
module.exports = __toCommonJS(widget_type_selector_exports);
|
|
23
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
24
|
+
var import_components = require("@wordpress/components");
|
|
25
|
+
var import_i18n = require("@wordpress/i18n");
|
|
26
|
+
var import_data = require("@wordpress/data");
|
|
27
|
+
var import_core_data = require("@wordpress/core-data");
|
|
28
|
+
var import_block_editor = require("@wordpress/block-editor");
|
|
29
|
+
function WidgetTypeSelector({ selectedId, onSelect }) {
|
|
30
|
+
const widgetTypes = (0, import_data.useSelect)((select) => {
|
|
31
|
+
const hiddenIds = select(import_block_editor.store).getSettings()?.widgetTypesToHideFromLegacyWidgetBlock ?? [];
|
|
32
|
+
return select(import_core_data.store).getWidgetTypes({ per_page: -1 })?.filter((widgetType) => !hiddenIds.includes(widgetType.id));
|
|
27
33
|
}, []);
|
|
28
34
|
if (!widgetTypes) {
|
|
29
|
-
return
|
|
35
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Spinner, {});
|
|
30
36
|
}
|
|
31
37
|
if (widgetTypes.length === 0) {
|
|
32
|
-
return (0,
|
|
38
|
+
return (0, import_i18n.__)("There are no widgets available.");
|
|
33
39
|
}
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
value:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
40
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
41
|
+
import_components.SelectControl,
|
|
42
|
+
{
|
|
43
|
+
__next40pxDefaultSize: true,
|
|
44
|
+
__nextHasNoMarginBottom: true,
|
|
45
|
+
label: (0, import_i18n.__)("Legacy widget"),
|
|
46
|
+
value: selectedId ?? "",
|
|
47
|
+
options: [
|
|
48
|
+
{ value: "", label: (0, import_i18n.__)("Select widget") },
|
|
49
|
+
...widgetTypes.map((widgetType) => ({
|
|
50
|
+
value: widgetType.id,
|
|
51
|
+
label: widgetType.name
|
|
52
|
+
}))
|
|
53
|
+
],
|
|
54
|
+
onChange: (value) => {
|
|
55
|
+
if (value) {
|
|
56
|
+
const selected = widgetTypes.find(
|
|
57
|
+
(widgetType) => widgetType.id === value
|
|
58
|
+
);
|
|
59
|
+
onSelect({
|
|
60
|
+
selectedId: selected.id,
|
|
61
|
+
isMulti: selected.is_multi
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
onSelect({ selectedId: null });
|
|
65
|
+
}
|
|
57
66
|
}
|
|
58
67
|
}
|
|
59
|
-
|
|
68
|
+
);
|
|
60
69
|
}
|
|
61
|
-
//# sourceMappingURL=widget-type-selector.js.map
|
|
70
|
+
//# sourceMappingURL=widget-type-selector.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/blocks/legacy-widget/edit/widget-type-selector.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Spinner, SelectControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\nexport default function WidgetTypeSelector( { selectedId, onSelect } ) {\n\tconst widgetTypes = useSelect( ( select ) => {\n\t\tconst hiddenIds =\n\t\t\tselect( blockEditorStore ).getSettings()\n\t\t\t\t?.widgetTypesToHideFromLegacyWidgetBlock ?? [];\n\t\treturn select( coreStore )\n\t\t\t.getWidgetTypes( { per_page: -1 } )\n\t\t\t?.filter( ( widgetType ) => ! hiddenIds.includes( widgetType.id ) );\n\t}, [] );\n\n\tif ( ! widgetTypes ) {\n\t\treturn <Spinner />;\n\t}\n\n\tif ( widgetTypes.length === 0 ) {\n\t\treturn __( 'There are no widgets available.' );\n\t}\n\n\treturn (\n\t\t<SelectControl\n\t\t\t__next40pxDefaultSize\n\t\t\t__nextHasNoMarginBottom\n\t\t\tlabel={ __( 'Legacy widget' ) }\n\t\t\tvalue={ selectedId ?? '' }\n\t\t\toptions={ [\n\t\t\t\t{ value: '', label: __( 'Select widget' ) },\n\t\t\t\t...widgetTypes.map( ( widgetType ) => ( {\n\t\t\t\t\tvalue: widgetType.id,\n\t\t\t\t\tlabel: widgetType.name,\n\t\t\t\t} ) ),\n\t\t\t] }\n\t\t\tonChange={ ( value ) => {\n\t\t\t\tif ( value ) {\n\t\t\t\t\tconst selected = widgetTypes.find(\n\t\t\t\t\t\t( widgetType ) => widgetType.id === value\n\t\t\t\t\t);\n\t\t\t\t\tonSelect( {\n\t\t\t\t\t\tselectedId: selected.id,\n\t\t\t\t\t\tisMulti: selected.is_multi,\n\t\t\t\t\t} );\n\t\t\t\t} else {\n\t\t\t\t\tonSelect( { selectedId: null } );\n\t\t\t\t}\n\t\t\t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