@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,116 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { useRefEffect } from '@wordpress/compose';
|
|
10
|
-
import { useEffect, useState } from '@wordpress/element';
|
|
11
|
-
import { Disabled, Placeholder, Spinner } from '@wordpress/components';
|
|
12
|
-
import { __ } from '@wordpress/i18n';
|
|
13
|
-
import apiFetch from '@wordpress/api-fetch';
|
|
14
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
-
export default function Preview({
|
|
16
|
-
idBase,
|
|
17
|
-
instance,
|
|
18
|
-
isVisible
|
|
19
|
-
}) {
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import clsx from "clsx";
|
|
3
|
+
import { useRefEffect } from "@wordpress/compose";
|
|
4
|
+
import { useEffect, useState } from "@wordpress/element";
|
|
5
|
+
import { Disabled, Placeholder, Spinner } from "@wordpress/components";
|
|
6
|
+
import { __ } from "@wordpress/i18n";
|
|
7
|
+
import apiFetch from "@wordpress/api-fetch";
|
|
8
|
+
function Preview({ idBase, instance, isVisible }) {
|
|
20
9
|
const [isLoaded, setIsLoaded] = useState(false);
|
|
21
|
-
const [srcDoc, setSrcDoc] = useState(
|
|
10
|
+
const [srcDoc, setSrcDoc] = useState("");
|
|
22
11
|
useEffect(() => {
|
|
23
|
-
const abortController = typeof window.AbortController ===
|
|
12
|
+
const abortController = typeof window.AbortController === "undefined" ? void 0 : new window.AbortController();
|
|
24
13
|
async function fetchPreviewHTML() {
|
|
25
14
|
const restRoute = `/wp/v2/widget-types/${idBase}/render`;
|
|
26
15
|
return await apiFetch({
|
|
27
16
|
path: restRoute,
|
|
28
|
-
method:
|
|
17
|
+
method: "POST",
|
|
29
18
|
signal: abortController?.signal,
|
|
30
|
-
data: instance ? {
|
|
31
|
-
instance
|
|
32
|
-
} : {}
|
|
19
|
+
data: instance ? { instance } : {}
|
|
33
20
|
});
|
|
34
21
|
}
|
|
35
|
-
fetchPreviewHTML().then(response => {
|
|
22
|
+
fetchPreviewHTML().then((response) => {
|
|
36
23
|
setSrcDoc(response.preview);
|
|
37
|
-
}).catch(error => {
|
|
38
|
-
if (
|
|
39
|
-
// We don't want to log aborted requests.
|
|
24
|
+
}).catch((error) => {
|
|
25
|
+
if ("AbortError" === error.name) {
|
|
40
26
|
return;
|
|
41
27
|
}
|
|
42
28
|
throw error;
|
|
43
29
|
});
|
|
44
30
|
return () => abortController?.abort();
|
|
45
31
|
}, [idBase, instance]);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// or it will grow to an unexpected large height in Safari if it's hidden initially.
|
|
51
|
-
if (!isLoaded) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
// If the preview frame has another origin then this won't work.
|
|
55
|
-
// One possible solution is to add custom script to call `postMessage` in the preview frame.
|
|
56
|
-
// Or, better yet, we migrate away from iframe.
|
|
57
|
-
function setHeight() {
|
|
58
|
-
var _iframe$contentDocume, _iframe$contentDocume2;
|
|
59
|
-
// Pick the maximum of these two values to account for margin collapsing.
|
|
60
|
-
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);
|
|
61
|
-
|
|
62
|
-
// Fallback to a height of 100px if the height cannot be determined.
|
|
63
|
-
// This ensures the block is still selectable. 100px should hopefully
|
|
64
|
-
// be not so big that it's annoying, and not so small that nothing
|
|
65
|
-
// can be seen.
|
|
66
|
-
iframe.style.height = `${height !== 0 ? height : 100}px`;
|
|
67
|
-
}
|
|
68
|
-
const {
|
|
69
|
-
IntersectionObserver
|
|
70
|
-
} = iframe.ownerDocument.defaultView;
|
|
71
|
-
|
|
72
|
-
// Observe for intersections that might cause a change in the height of
|
|
73
|
-
// the iframe, e.g. a Widget Area becoming expanded.
|
|
74
|
-
const intersectionObserver = new IntersectionObserver(([entry]) => {
|
|
75
|
-
if (entry.isIntersecting) {
|
|
76
|
-
setHeight();
|
|
32
|
+
const ref = useRefEffect(
|
|
33
|
+
(iframe) => {
|
|
34
|
+
if (!isLoaded) {
|
|
35
|
+
return;
|
|
77
36
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
iframe.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
37
|
+
function setHeight() {
|
|
38
|
+
const height = Math.max(
|
|
39
|
+
iframe.contentDocument.documentElement?.offsetHeight ?? 0,
|
|
40
|
+
iframe.contentDocument.body?.offsetHeight ?? 0
|
|
41
|
+
);
|
|
42
|
+
iframe.style.height = `${height !== 0 ? height : 100}px`;
|
|
43
|
+
}
|
|
44
|
+
const { IntersectionObserver } = iframe.ownerDocument.defaultView;
|
|
45
|
+
const intersectionObserver = new IntersectionObserver(
|
|
46
|
+
([entry]) => {
|
|
47
|
+
if (entry.isIntersecting) {
|
|
48
|
+
setHeight();
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
threshold: 1
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
intersectionObserver.observe(iframe);
|
|
56
|
+
iframe.addEventListener("load", setHeight);
|
|
57
|
+
return () => {
|
|
58
|
+
intersectionObserver.disconnect();
|
|
59
|
+
iframe.removeEventListener("load", setHeight);
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
[isLoaded]
|
|
63
|
+
);
|
|
64
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
65
|
+
isVisible && !isLoaded && /* @__PURE__ */ jsx(Placeholder, { children: /* @__PURE__ */ jsx(Spinner, {}) }),
|
|
66
|
+
/* @__PURE__ */ jsx(
|
|
67
|
+
"div",
|
|
68
|
+
{
|
|
69
|
+
className: clsx("wp-block-legacy-widget__edit-preview", {
|
|
70
|
+
"is-offscreen": !isVisible || !isLoaded
|
|
71
|
+
}),
|
|
72
|
+
children: /* @__PURE__ */ jsx(Disabled, { children: /* @__PURE__ */ jsx(
|
|
73
|
+
"iframe",
|
|
74
|
+
{
|
|
75
|
+
ref,
|
|
76
|
+
className: "wp-block-legacy-widget__edit-preview-iframe",
|
|
77
|
+
tabIndex: "-1",
|
|
78
|
+
title: __("Legacy Widget Preview"),
|
|
79
|
+
srcDoc,
|
|
80
|
+
onLoad: (event) => {
|
|
81
|
+
event.target.contentDocument.body.style.overflow = "hidden";
|
|
82
|
+
setIsLoaded(true);
|
|
83
|
+
},
|
|
84
|
+
height: 100
|
|
85
|
+
}
|
|
86
|
+
) })
|
|
87
|
+
}
|
|
88
|
+
)
|
|
89
|
+
] });
|
|
115
90
|
}
|
|
116
|
-
|
|
91
|
+
export {
|
|
92
|
+
Preview as default
|
|
93
|
+
};
|
|
94
|
+
//# 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": "AAqGE,mBAUG,KAVH;AAlGF,OAAO,UAAU;AAKjB,SAAS,oBAAoB;AAC7B,SAAS,WAAW,gBAAgB;AACpC,SAAS,UAAU,aAAa,eAAe;AAC/C,SAAS,UAAU;AACnB,OAAO,cAAc;AAEN,SAAR,QAA0B,EAAE,QAAQ,UAAU,UAAU,GAAI;AAClE,QAAM,CAAE,UAAU,WAAY,IAAI,SAAU,KAAM;AAClD,QAAM,CAAE,QAAQ,SAAU,IAAI,SAAU,EAAG;AAE3C,YAAW,MAAM;AAChB,UAAM,kBACL,OAAO,OAAO,oBAAoB,cAC/B,SACA,IAAI,OAAO,gBAAgB;AAE/B,mBAAe,mBAAmB;AACjC,YAAM,YAAY,uBAAwB,MAAO;AACjD,aAAO,MAAM,SAAU;AAAA,QACtB,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,QAAQ,iBAAiB;AAAA,QACzB,MAAM,WAAW,EAAE,SAAS,IAAI,CAAC;AAAA,MAClC,CAAE;AAAA,IACH;AAEA,qBAAiB,EACf,KAAM,CAAE,aAAc;AACtB,gBAAW,SAAS,OAAQ;AAAA,IAC7B,CAAE,EACD,MAAO,CAAE,UAAW;AACpB,UAAK,iBAAiB,MAAM,MAAO;AAElC;AAAA,MACD;AACA,YAAM;AAAA,IACP,CAAE;AAEH,WAAO,MAAM,iBAAiB,MAAM;AAAA,EACrC,GAAG,CAAE,QAAQ,QAAS,CAAE;AAGxB,QAAM,MAAM;AAAA,IACX,CAAE,WAAY;AAGb,UAAK,CAAE,UAAW;AACjB;AAAA,MACD;AAIA,eAAS,YAAY;AAEpB,cAAM,SAAS,KAAK;AAAA,UACnB,OAAO,gBAAgB,iBAAiB,gBAAgB;AAAA,UACxD,OAAO,gBAAgB,MAAM,gBAAgB;AAAA,QAC9C;AAMA,eAAO,MAAM,SAAS,GAAI,WAAW,IAAI,SAAS,GAAI;AAAA,MACvD;AAEA,YAAM,EAAE,qBAAqB,IAAI,OAAO,cAAc;AAItD,YAAM,uBAAuB,IAAI;AAAA,QAChC,CAAE,CAAE,KAAM,MAAO;AAChB,cAAK,MAAM,gBAAiB;AAC3B,sBAAU;AAAA,UACX;AAAA,QACD;AAAA,QACA;AAAA,UACC,WAAW;AAAA,QACZ;AAAA,MACD;AACA,2BAAqB,QAAS,MAAO;AAErC,aAAO,iBAAkB,QAAQ,SAAU;AAE3C,aAAO,MAAM;AACZ,6BAAqB,WAAW;AAChC,eAAO,oBAAqB,QAAQ,SAAU;AAAA,MAC/C;AAAA,IACD;AAAA,IACA,CAAE,QAAS;AAAA,EACZ;AAEA,SACC,iCAQG;AAAA,iBAAa,CAAE,YAChB,oBAAC,eACA,8BAAC,WAAQ,GACV;AAAA,IAED;AAAA,MAAC;AAAA;AAAA,QACA,WAAY,KAAM,wCAAwC;AAAA,UACzD,gBAAgB,CAAE,aAAa,CAAE;AAAA,QAClC,CAAE;AAAA,QAEF,8BAAC,YAKA;AAAA,UAAC;AAAA;AAAA,YACA;AAAA,YACA,WAAU;AAAA,YACV,UAAS;AAAA,YACT,OAAQ,GAAI,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": []
|
|
7
|
+
}
|
|
@@ -1,54 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
selectedId,
|
|
12
|
-
onSelect
|
|
13
|
-
}) {
|
|
14
|
-
const widgetTypes = useSelect(select => {
|
|
15
|
-
var _select$getSettings$w;
|
|
16
|
-
const hiddenIds = (_select$getSettings$w = select(blockEditorStore).getSettings()?.widgetTypesToHideFromLegacyWidgetBlock) !== null && _select$getSettings$w !== void 0 ? _select$getSettings$w : [];
|
|
17
|
-
return select(coreStore).getWidgetTypes({
|
|
18
|
-
per_page: -1
|
|
19
|
-
})?.filter(widgetType => !hiddenIds.includes(widgetType.id));
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Spinner, SelectControl } from "@wordpress/components";
|
|
3
|
+
import { __ } from "@wordpress/i18n";
|
|
4
|
+
import { useSelect } from "@wordpress/data";
|
|
5
|
+
import { store as coreStore } from "@wordpress/core-data";
|
|
6
|
+
import { store as blockEditorStore } from "@wordpress/block-editor";
|
|
7
|
+
function WidgetTypeSelector({ selectedId, onSelect }) {
|
|
8
|
+
const widgetTypes = useSelect((select) => {
|
|
9
|
+
const hiddenIds = select(blockEditorStore).getSettings()?.widgetTypesToHideFromLegacyWidgetBlock ?? [];
|
|
10
|
+
return select(coreStore).getWidgetTypes({ per_page: -1 })?.filter((widgetType) => !hiddenIds.includes(widgetType.id));
|
|
20
11
|
}, []);
|
|
21
12
|
if (!widgetTypes) {
|
|
22
|
-
return
|
|
13
|
+
return /* @__PURE__ */ jsx(Spinner, {});
|
|
23
14
|
}
|
|
24
15
|
if (widgetTypes.length === 0) {
|
|
25
|
-
return __(
|
|
16
|
+
return __("There are no widgets available.");
|
|
26
17
|
}
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
value:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
18
|
+
return /* @__PURE__ */ jsx(
|
|
19
|
+
SelectControl,
|
|
20
|
+
{
|
|
21
|
+
__next40pxDefaultSize: true,
|
|
22
|
+
__nextHasNoMarginBottom: true,
|
|
23
|
+
label: __("Legacy widget"),
|
|
24
|
+
value: selectedId ?? "",
|
|
25
|
+
options: [
|
|
26
|
+
{ value: "", label: __("Select widget") },
|
|
27
|
+
...widgetTypes.map((widgetType) => ({
|
|
28
|
+
value: widgetType.id,
|
|
29
|
+
label: widgetType.name
|
|
30
|
+
}))
|
|
31
|
+
],
|
|
32
|
+
onChange: (value) => {
|
|
33
|
+
if (value) {
|
|
34
|
+
const selected = widgetTypes.find(
|
|
35
|
+
(widgetType) => widgetType.id === value
|
|
36
|
+
);
|
|
37
|
+
onSelect({
|
|
38
|
+
selectedId: selected.id,
|
|
39
|
+
isMulti: selected.is_multi
|
|
40
|
+
});
|
|
41
|
+
} else {
|
|
42
|
+
onSelect({ selectedId: null });
|
|
43
|
+
}
|
|
50
44
|
}
|
|
51
45
|
}
|
|
52
|
-
|
|
46
|
+
);
|
|
53
47
|
}
|
|
54
|
-
|
|
48
|
+
export {
|
|
49
|
+
WidgetTypeSelector as default
|
|
50
|
+
};
|
|
51
|
+
//# 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} }\n\t\t/>\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAoBS;AAjBT,SAAS,SAAS,qBAAqB;AACvC,SAAS,UAAU;AACnB,SAAS,iBAAiB;AAC1B,SAAS,SAAS,iBAAiB;AACnC,SAAS,SAAS,wBAAwB;AAE3B,SAAR,mBAAqC,EAAE,YAAY,SAAS,GAAI;AACtE,QAAM,cAAc,UAAW,CAAE,WAAY;AAC5C,UAAM,YACL,OAAQ,gBAAiB,EAAE,YAAY,GACpC,0CAA0C,CAAC;AAC/C,WAAO,OAAQ,SAAU,EACvB,eAAgB,EAAE,UAAU,GAAG,CAAE,GAChC,OAAQ,CAAE,eAAgB,CAAE,UAAU,SAAU,WAAW,EAAG,CAAE;AAAA,EACpE,GAAG,CAAC,CAAE;AAEN,MAAK,CAAE,aAAc;AACpB,WAAO,oBAAC,WAAQ;AAAA,EACjB;AAEA,MAAK,YAAY,WAAW,GAAI;AAC/B,WAAO,GAAI,iCAAkC;AAAA,EAC9C;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,uBAAqB;AAAA,MACrB,yBAAuB;AAAA,MACvB,OAAQ,GAAI,eAAgB;AAAA,MAC5B,OAAQ,cAAc;AAAA,MACtB,SAAU;AAAA,QACT,EAAE,OAAO,IAAI,OAAO,GAAI,eAAgB,EAAE;AAAA,QAC1C,GAAG,YAAY,IAAK,CAAE,gBAAkB;AAAA,UACvC,OAAO,WAAW;AAAA,UAClB,OAAO,WAAW;AAAA,QACnB,EAAI;AAAA,MACL;AAAA,MACA,UAAW,CAAE,UAAW;AACvB,YAAK,OAAQ;AACZ,gBAAM,WAAW,YAAY;AAAA,YAC5B,CAAE,eAAgB,WAAW,OAAO;AAAA,UACrC;AACA,mBAAU;AAAA,YACT,YAAY,SAAS;AAAA,YACrB,SAAS,SAAS;AAAA,UACnB,CAAE;AAAA,QACH,OAAO;AACN,mBAAU,EAAE,YAAY,KAAK,CAAE;AAAA,QAChC;AAAA,MACD;AAAA;AAAA,EACD;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,49 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
const metadata = {
|
|
10
|
-
$schema: "https://schemas.wp.org/trunk/block.json",
|
|
11
|
-
apiVersion: 3,
|
|
12
|
-
name: "core/legacy-widget",
|
|
13
|
-
title: "Legacy Widget",
|
|
14
|
-
category: "widgets",
|
|
15
|
-
description: "Display a legacy widget.",
|
|
16
|
-
textdomain: "default",
|
|
17
|
-
attributes: {
|
|
18
|
-
id: {
|
|
19
|
-
type: "string",
|
|
20
|
-
"default": null
|
|
21
|
-
},
|
|
22
|
-
idBase: {
|
|
23
|
-
type: "string",
|
|
24
|
-
"default": null
|
|
25
|
-
},
|
|
26
|
-
instance: {
|
|
27
|
-
type: "object",
|
|
28
|
-
"default": null
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
supports: {
|
|
32
|
-
html: false,
|
|
33
|
-
customClassName: false,
|
|
34
|
-
reusable: false
|
|
35
|
-
},
|
|
36
|
-
editorStyle: "wp-block-legacy-widget-editor"
|
|
37
|
-
};
|
|
38
|
-
import edit from './edit';
|
|
39
|
-
import transforms from './transforms';
|
|
40
|
-
const {
|
|
41
|
-
name
|
|
42
|
-
} = metadata;
|
|
43
|
-
export { metadata, name };
|
|
44
|
-
export const settings = {
|
|
1
|
+
import { widget as icon } from "@wordpress/icons";
|
|
2
|
+
import metadata from "./block.json";
|
|
3
|
+
import edit from "./edit";
|
|
4
|
+
import transforms from "./transforms";
|
|
5
|
+
const { name } = metadata;
|
|
6
|
+
const settings = {
|
|
45
7
|
icon,
|
|
46
8
|
edit,
|
|
47
9
|
transforms
|
|
48
10
|
};
|
|
49
|
-
|
|
11
|
+
export {
|
|
12
|
+
metadata,
|
|
13
|
+
name,
|
|
14
|
+
settings
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/blocks/legacy-widget/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { widget as icon } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport metadata from './block.json';\nimport edit from './edit';\nimport transforms from './transforms';\n\nconst { name } = metadata;\nexport { metadata, name };\n\nexport const settings = {\n\ticon,\n\tedit,\n\ttransforms,\n};\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,UAAU,YAAY;AAK/B,OAAO,cAAc;AACrB,OAAO,UAAU;AACjB,OAAO,gBAAgB;AAEvB,MAAM,EAAE,KAAK,IAAI;AAGV,MAAM,WAAW;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|