@wordpress/block-editor 12.3.4 → 12.3.6
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/README.md +4 -0
- package/build/components/block-edit/edit.js +25 -13
- package/build/components/block-edit/edit.js.map +1 -1
- package/build/components/block-parent-selector/index.js +8 -5
- package/build/components/block-parent-selector/index.js.map +1 -1
- package/build/components/block-removal-warning-modal/index.js +4 -1
- package/build/components/block-removal-warning-modal/index.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +7 -11
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/iframe/index.js +21 -46
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/index.js +10 -1
- package/build/components/index.js.map +1 -1
- package/build/components/inserter/reusable-block-rename-hint.js +62 -0
- package/build/components/inserter/reusable-block-rename-hint.js.map +1 -0
- package/build/components/inserter/reusable-blocks-tab.js +5 -1
- package/build/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build/components/list-view/use-list-view-client-ids.js +2 -2
- package/build/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build/components/rich-text/content.js +0 -36
- package/build/components/rich-text/content.js.map +1 -1
- package/build/components/rich-text/get-rich-text-values.js +112 -0
- package/build/components/rich-text/get-rich-text-values.js.map +1 -0
- package/build/private-apis.js +2 -2
- package/build/private-apis.js.map +1 -1
- package/build/store/private-selectors.js +5 -6
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/selectors.js +6 -4
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/block-edit/edit.js +27 -10
- package/build-module/components/block-edit/edit.js.map +1 -1
- package/build-module/components/block-parent-selector/index.js +7 -5
- package/build-module/components/block-parent-selector/index.js.map +1 -1
- package/build-module/components/block-removal-warning-modal/index.js +4 -1
- package/build-module/components/block-removal-warning-modal/index.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +8 -11
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/iframe/index.js +22 -47
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/index.js +5 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inserter/reusable-block-rename-hint.js +48 -0
- package/build-module/components/inserter/reusable-block-rename-hint.js.map +1 -0
- package/build-module/components/inserter/reusable-blocks-tab.js +4 -1
- package/build-module/components/inserter/reusable-blocks-tab.js.map +1 -1
- package/build-module/components/list-view/use-list-view-client-ids.js +2 -2
- package/build-module/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build-module/components/rich-text/content.js +1 -36
- package/build-module/components/rich-text/content.js.map +1 -1
- package/build-module/components/rich-text/get-rich-text-values.js +99 -0
- package/build-module/components/rich-text/get-rich-text-values.js.map +1 -0
- package/build-module/private-apis.js +1 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/private-selectors.js +3 -3
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/selectors.js +6 -4
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +71 -20
- package/build-style/style.css +71 -20
- package/package.json +9 -9
- package/src/components/block-edit/edit.js +26 -9
- package/src/components/block-edit/test/edit.js +1 -1
- package/src/components/block-parent-selector/index.js +13 -8
- package/src/components/block-removal-warning-modal/index.js +3 -0
- package/src/components/block-tools/block-contextual-toolbar.js +5 -11
- package/src/components/block-tools/style.scss +69 -26
- package/src/components/iframe/index.js +16 -47
- package/src/components/index.js +5 -0
- package/src/components/inserter/reusable-block-rename-hint.js +52 -0
- package/src/components/inserter/reusable-blocks-tab.js +4 -0
- package/src/components/inserter/style.scss +28 -0
- package/src/components/list-view/use-list-view-client-ids.js +2 -2
- package/src/components/rich-text/content.js +1 -46
- package/src/components/rich-text/get-rich-text-values.js +95 -0
- package/src/private-apis.js +1 -1
- package/src/store/private-selectors.js +3 -6
- package/src/store/selectors.js +9 -6
- package/src/store/test/private-selectors.js +5 -5
|
@@ -26,17 +26,12 @@ import BlockContext from '../block-context';
|
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
28
|
const DEFAULT_BLOCK_CONTEXT = {};
|
|
29
|
-
|
|
29
|
+
|
|
30
|
+
const Edit = props => {
|
|
30
31
|
const {
|
|
31
|
-
attributes = {},
|
|
32
32
|
name
|
|
33
33
|
} = props;
|
|
34
34
|
const blockType = getBlockType(name);
|
|
35
|
-
const blockContext = useContext(BlockContext); // Assign context values using the block type's declared context needs.
|
|
36
|
-
|
|
37
|
-
const context = useMemo(() => {
|
|
38
|
-
return blockType && blockType.usesContext ? Object.fromEntries(Object.entries(blockContext).filter(([key]) => blockType.usesContext.includes(key))) : DEFAULT_BLOCK_CONTEXT;
|
|
39
|
-
}, [blockType, blockContext]);
|
|
40
35
|
|
|
41
36
|
if (!blockType) {
|
|
42
37
|
return null;
|
|
@@ -46,9 +41,30 @@ export const Edit = props => {
|
|
|
46
41
|
|
|
47
42
|
|
|
48
43
|
const Component = blockType.edit || blockType.save;
|
|
44
|
+
return createElement(Component, { ...props
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const EditWithFilters = withFilters('editor.BlockEdit')(Edit);
|
|
49
|
+
|
|
50
|
+
const EditWithGeneratedProps = props => {
|
|
51
|
+
const {
|
|
52
|
+
attributes = {},
|
|
53
|
+
name
|
|
54
|
+
} = props;
|
|
55
|
+
const blockType = getBlockType(name);
|
|
56
|
+
const blockContext = useContext(BlockContext); // Assign context values using the block type's declared context needs.
|
|
57
|
+
|
|
58
|
+
const context = useMemo(() => {
|
|
59
|
+
return blockType && blockType.usesContext ? Object.fromEntries(Object.entries(blockContext).filter(([key]) => blockType.usesContext.includes(key))) : DEFAULT_BLOCK_CONTEXT;
|
|
60
|
+
}, [blockType, blockContext]);
|
|
61
|
+
|
|
62
|
+
if (!blockType) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
49
65
|
|
|
50
66
|
if (blockType.apiVersion > 1) {
|
|
51
|
-
return createElement(
|
|
67
|
+
return createElement(EditWithFilters, { ...props,
|
|
52
68
|
context: context
|
|
53
69
|
});
|
|
54
70
|
} // Generate a class name for the block's editable form.
|
|
@@ -56,10 +72,11 @@ export const Edit = props => {
|
|
|
56
72
|
|
|
57
73
|
const generatedClassName = hasBlockSupport(blockType, 'className', true) ? getBlockDefaultClassName(name) : null;
|
|
58
74
|
const className = classnames(generatedClassName, attributes.className, props.className);
|
|
59
|
-
return createElement(
|
|
75
|
+
return createElement(EditWithFilters, { ...props,
|
|
60
76
|
context: context,
|
|
61
77
|
className: className
|
|
62
78
|
});
|
|
63
79
|
};
|
|
64
|
-
|
|
80
|
+
|
|
81
|
+
export default EditWithGeneratedProps;
|
|
65
82
|
//# sourceMappingURL=edit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-edit/edit.js"],"names":["classnames","withFilters","getBlockDefaultClassName","hasBlockSupport","getBlockType","useContext","useMemo","BlockContext","DEFAULT_BLOCK_CONTEXT","Edit","props","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-edit/edit.js"],"names":["classnames","withFilters","getBlockDefaultClassName","hasBlockSupport","getBlockType","useContext","useMemo","BlockContext","DEFAULT_BLOCK_CONTEXT","Edit","props","name","blockType","Component","edit","save","EditWithFilters","EditWithGeneratedProps","attributes","blockContext","context","usesContext","Object","fromEntries","entries","filter","key","includes","apiVersion","generatedClassName","className"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,WAAT,QAA4B,uBAA5B;AACA,SACCC,wBADD,EAECC,eAFD,EAGCC,YAHD,QAIO,mBAJP;AAKA,SAASC,UAAT,EAAqBC,OAArB,QAAoC,oBAApC;AAEA;AACA;AACA;;AACA,OAAOC,YAAP,MAAyB,kBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,qBAAqB,GAAG,EAA9B;;AAEA,MAAMC,IAAI,GAAKC,K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1B,eAAe,CAAES,SAAF,EAAa,WAAb,EAA0B,IAA1B,CAAf,GACxBV,wBAAwB,CAAES,IAAF,CADA,GAExB,IAFH;AAGA,QAAMmB,SAAS,GAAG9B,UAAU,CAC3B6B,kBAD2B,EAE3BX,UAAU,CAACY,SAFgB,EAG3BpB,KAAK,CAACoB,SAHqB,CAA5B;AAMA,SACC,cAAC,eAAD,OACMpB,KADN;AAEC,IAAA,OAAO,EAAGU,OAFX;AAGC,IAAA,SAAS,EAAGU;AAHb,IADD;AAOA,CAzCD;;AA2CA,eAAeb,sBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { withFilters } from '@wordpress/components';\nimport {\n\tgetBlockDefaultClassName,\n\thasBlockSupport,\n\tgetBlockType,\n} from '@wordpress/blocks';\nimport { useContext, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport BlockContext from '../block-context';\n\n/**\n * Default value used for blocks which do not define their own context needs,\n * used to guarantee that a block's `context` prop will always be an object. It\n * is assigned as a constant since it is always expected to be an empty object,\n * and in order to avoid unnecessary React reconciliations of a changing object.\n *\n * @type {{}}\n */\nconst DEFAULT_BLOCK_CONTEXT = {};\n\nconst Edit = ( props ) => {\n\tconst { name } = props;\n\tconst blockType = getBlockType( name );\n\n\tif ( ! blockType ) {\n\t\treturn null;\n\t}\n\n\t// `edit` and `save` are functions or components describing the markup\n\t// with which a block is displayed. If `blockType` is valid, assign\n\t// them preferentially as the render value for the block.\n\tconst Component = blockType.edit || blockType.save;\n\n\treturn <Component { ...props } />;\n};\n\nconst EditWithFilters = withFilters( 'editor.BlockEdit' )( Edit );\n\nconst EditWithGeneratedProps = ( props ) => {\n\tconst { attributes = {}, name } = props;\n\tconst blockType = getBlockType( name );\n\tconst blockContext = useContext( BlockContext );\n\n\t// Assign context values using the block type's declared context needs.\n\tconst context = useMemo( () => {\n\t\treturn blockType && blockType.usesContext\n\t\t\t? Object.fromEntries(\n\t\t\t\t\tObject.entries( blockContext ).filter( ( [ key ] ) =>\n\t\t\t\t\t\tblockType.usesContext.includes( key )\n\t\t\t\t\t)\n\t\t\t )\n\t\t\t: DEFAULT_BLOCK_CONTEXT;\n\t}, [ blockType, blockContext ] );\n\n\tif ( ! blockType ) {\n\t\treturn null;\n\t}\n\n\tif ( blockType.apiVersion > 1 ) {\n\t\treturn <EditWithFilters { ...props } context={ context } />;\n\t}\n\n\t// Generate a class name for the block's editable form.\n\tconst generatedClassName = hasBlockSupport( blockType, 'className', true )\n\t\t? getBlockDefaultClassName( name )\n\t\t: null;\n\tconst className = classnames(\n\t\tgeneratedClassName,\n\t\tattributes.className,\n\t\tprops.className\n\t);\n\n\treturn (\n\t\t<EditWithFilters\n\t\t\t{ ...props }\n\t\t\tcontext={ context }\n\t\t\tclassName={ className }\n\t\t/>\n\t);\n};\n\nexport default EditWithGeneratedProps;\n"]}
|
|
@@ -16,6 +16,7 @@ import useBlockDisplayInformation from '../use-block-display-information';
|
|
|
16
16
|
import BlockIcon from '../block-icon';
|
|
17
17
|
import { useShowMoversGestures } from '../block-toolbar/utils';
|
|
18
18
|
import { store as blockEditorStore } from '../../store';
|
|
19
|
+
import { unlock } from '../../lock-unlock';
|
|
19
20
|
/**
|
|
20
21
|
* Block parent selector component, displaying the hierarchy of the
|
|
21
22
|
* current block selection as a single icon to "go up" a level.
|
|
@@ -30,15 +31,16 @@ export default function BlockParentSelector() {
|
|
|
30
31
|
} = useDispatch(blockEditorStore);
|
|
31
32
|
const {
|
|
32
33
|
firstParentClientId,
|
|
33
|
-
|
|
34
|
+
isVisible,
|
|
34
35
|
isDistractionFree
|
|
35
36
|
} = useSelect(select => {
|
|
36
37
|
const {
|
|
37
38
|
getBlockName,
|
|
38
39
|
getBlockParents,
|
|
39
40
|
getSelectedBlockClientId,
|
|
40
|
-
getSettings
|
|
41
|
-
|
|
41
|
+
getSettings,
|
|
42
|
+
getBlockEditingMode
|
|
43
|
+
} = unlock(select(blockEditorStore));
|
|
42
44
|
const {
|
|
43
45
|
hasBlockSupport
|
|
44
46
|
} = select(blocksStore);
|
|
@@ -52,7 +54,7 @@ export default function BlockParentSelector() {
|
|
|
52
54
|
const settings = getSettings();
|
|
53
55
|
return {
|
|
54
56
|
firstParentClientId: _firstParentClientId,
|
|
55
|
-
|
|
57
|
+
isVisible: _firstParentClientId && getBlockEditingMode(_firstParentClientId) === 'default' && hasBlockSupport(_parentBlockType, '__experimentalParentSelector', true),
|
|
56
58
|
isDistractionFree: settings.isDistractionFree
|
|
57
59
|
};
|
|
58
60
|
}, []);
|
|
@@ -75,7 +77,7 @@ export default function BlockParentSelector() {
|
|
|
75
77
|
|
|
76
78
|
});
|
|
77
79
|
|
|
78
|
-
if (
|
|
80
|
+
if (!isVisible) {
|
|
79
81
|
return null;
|
|
80
82
|
}
|
|
81
83
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-parent-selector/index.js"],"names":["getBlockType","store","blocksStore","ToolbarButton","useSelect","useDispatch","__","sprintf","useRef","useBlockDisplayInformation","BlockIcon","useShowMoversGestures","blockEditorStore","BlockParentSelector","selectBlock","toggleBlockHighlight","firstParentClientId","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-parent-selector/index.js"],"names":["getBlockType","store","blocksStore","ToolbarButton","useSelect","useDispatch","__","sprintf","useRef","useBlockDisplayInformation","BlockIcon","useShowMoversGestures","blockEditorStore","unlock","BlockParentSelector","selectBlock","toggleBlockHighlight","firstParentClientId","isVisible","isDistractionFree","select","getBlockName","getBlockParents","getSelectedBlockClientId","getSettings","getBlockEditingMode","hasBlockSupport","selectedBlockClientId","parents","_firstParentClientId","length","parentBlockName","_parentBlockType","settings","blockInformation","nodeRef","gestures","showMoversGestures","ref","onChange","isFocused","title","icon"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,YAAT,EAAuBC,KAAK,IAAIC,WAAhC,QAAmD,mBAAnD;AACA,SAASC,aA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AAoB,IACpBJ,mBAAmB,CAAEI,oBAAF,CAAnB,KAAgD,SADhD,IAEAH,eAAe,CACdM,gBADc,EAEd,8BAFc,EAGd,IAHc,CALV;AAUNb,MAAAA,iBAAiB,EAAEc,QAAQ,CAACd;AAVtB,KAAP;AAYA,GA5BqE,EA6BtE,EA7BsE,CAAvE;AA+BA,QAAMe,gBAAgB,GAAGzB,0BAA0B,CAAEQ,mBAAF,CAAnD,CAlC6C,CAoC7C;AACA;;AACA,QAAMkB,OAAO,GAAG3B,MAAM,EAAtB;AACA,QAAM;AAAE4B,IAAAA,QAAQ,EAAEC;AAAZ,MAAmC1B,qBAAqB,CAAE;AAC/D2B,IAAAA,GAAG,EAAEH,OAD0D;;AAE/DI,IAAAA,QAAQ,CAAEC,SAAF,EAAc;AACrB,UAAKA,SAAS,IAAIrB,iBAAlB,EAAsC;AACrC;AACA;;AACDH,MAAAA,oBAAoB,CAAEC,mBAAF,EAAuBuB,SAAvB,CAApB;AACA;;AAP8D,GAAF,CAA9D;;AAUA,MAAK,CAAEtB,SAAP,EAAmB;AAClB,WAAO,IAAP;AACA;;AAED,SACC;AACC,IAAA,SAAS,EAAC,oCADX;AAEC,IAAA,GAAG,EAAGD,mBAFP;AAGC,IAAA,GAAG,EAAGkB,OAHP;AAAA,OAIME;AAJN,KAMC,cAAC,aAAD;AACC,IAAA,SAAS,EAAC,4CADX;AAEC,IAAA,OAAO,EAAG,MAAMtB,WAAW,CAAEE,mBAAF,CAF5B;AAGC,IAAA,KAAK,EAAGV,OAAO;AACd;AACAD,IAAAA,EAAE,CAAE,WAAF,CAFY,EAGd4B,gBAAgB,EAAEO,KAHJ,CAHhB;AAQC,IAAA,WAAW,MARZ;AASC,IAAA,IAAI,EAAG,cAAC,SAAD;AAAW,MAAA,IAAI,EAAGP,gBAAgB,EAAEQ;AAApC;AATR,IAND,CADD;AAoBA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { getBlockType, store as blocksStore } from '@wordpress/blocks';\nimport { ToolbarButton } from '@wordpress/components';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useBlockDisplayInformation from '../use-block-display-information';\nimport BlockIcon from '../block-icon';\nimport { useShowMoversGestures } from '../block-toolbar/utils';\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\n/**\n * Block parent selector component, displaying the hierarchy of the\n * current block selection as a single icon to \"go up\" a level.\n *\n * @return {WPComponent} Parent block selector.\n */\nexport default function BlockParentSelector() {\n\tconst { selectBlock, toggleBlockHighlight } =\n\t\tuseDispatch( blockEditorStore );\n\tconst { firstParentClientId, isVisible, isDistractionFree } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockName,\n\t\t\t\tgetBlockParents,\n\t\t\t\tgetSelectedBlockClientId,\n\t\t\t\tgetSettings,\n\t\t\t\tgetBlockEditingMode,\n\t\t\t} = unlock( select( blockEditorStore ) );\n\t\t\tconst { hasBlockSupport } = select( blocksStore );\n\t\t\tconst selectedBlockClientId = getSelectedBlockClientId();\n\t\t\tconst parents = getBlockParents( selectedBlockClientId );\n\t\t\tconst _firstParentClientId = parents[ parents.length - 1 ];\n\t\t\tconst parentBlockName = getBlockName( _firstParentClientId );\n\t\t\tconst _parentBlockType = getBlockType( parentBlockName );\n\t\t\tconst settings = getSettings();\n\t\t\treturn {\n\t\t\t\tfirstParentClientId: _firstParentClientId,\n\t\t\t\tisVisible:\n\t\t\t\t\t_firstParentClientId &&\n\t\t\t\t\tgetBlockEditingMode( _firstParentClientId ) === 'default' &&\n\t\t\t\t\thasBlockSupport(\n\t\t\t\t\t\t_parentBlockType,\n\t\t\t\t\t\t'__experimentalParentSelector',\n\t\t\t\t\t\ttrue\n\t\t\t\t\t),\n\t\t\t\tisDistractionFree: settings.isDistractionFree,\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\tconst blockInformation = useBlockDisplayInformation( firstParentClientId );\n\n\t// Allows highlighting the parent block outline when focusing or hovering\n\t// the parent block selector within the child.\n\tconst nodeRef = useRef();\n\tconst { gestures: showMoversGestures } = useShowMoversGestures( {\n\t\tref: nodeRef,\n\t\tonChange( isFocused ) {\n\t\t\tif ( isFocused && isDistractionFree ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttoggleBlockHighlight( firstParentClientId, isFocused );\n\t\t},\n\t} );\n\n\tif ( ! isVisible ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div\n\t\t\tclassName=\"block-editor-block-parent-selector\"\n\t\t\tkey={ firstParentClientId }\n\t\t\tref={ nodeRef }\n\t\t\t{ ...showMoversGestures }\n\t\t>\n\t\t\t<ToolbarButton\n\t\t\t\tclassName=\"block-editor-block-parent-selector__button\"\n\t\t\t\tonClick={ () => selectBlock( firstParentClientId ) }\n\t\t\t\tlabel={ sprintf(\n\t\t\t\t\t/* translators: %s: Name of the block's parent. */\n\t\t\t\t\t__( 'Select %s' ),\n\t\t\t\t\tblockInformation?.title\n\t\t\t\t) }\n\t\t\t\tshowTooltip\n\t\t\t\ticon={ <BlockIcon icon={ blockInformation?.icon } /> }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"]}
|
|
@@ -55,7 +55,10 @@ export function BlockRemovalWarningModal() {
|
|
|
55
55
|
|
|
56
56
|
return createElement(Modal, {
|
|
57
57
|
title: __('Are you sure?'),
|
|
58
|
-
onRequestClose: clearRemovalPrompt
|
|
58
|
+
onRequestClose: clearRemovalPrompt,
|
|
59
|
+
style: {
|
|
60
|
+
maxWidth: '40rem'
|
|
61
|
+
}
|
|
59
62
|
}, blockNamesForPrompt.length === 1 ? createElement("p", null, blockTypePromptMessages[blockNamesForPrompt[0]]) : createElement("ul", {
|
|
60
63
|
style: {
|
|
61
64
|
listStyleType: 'disc',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-removal-warning-modal/index.js"],"names":["useEffect","useDispatch","useSelect","Modal","Button","__experimentalHStack","HStack","__","store","blockEditorStore","unlock","blockTypePromptMessages","BlockRemovalWarningModal","clientIds","selectPrevious","blockNamesForPrompt","select","getRemovalPromptData","clearRemovalPrompt","toggleRemovalPromptSupport","privateRemoveBlocks","onConfirmRemoval","length","listStyleType","paddingLeft","map","name"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,oBAA1B;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SACCC,KADD,EAECC,MAFD,EAGCC,oBAAoB,IAAIC,MAHzB,QAIO,uBAJP;AAKA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,MAAT,QAAuB,mBAAvB,C,CAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,uBAAuB,GAAG;AACtC,gBAAcJ,EAAE,CAAE,+CAAF,CADsB;AAEtC,uBAAqBA,EAAE,CACtB,sDADsB;AAFe,CAAhC;AAOP,OAAO,SAASK,wBAAT,GAAoC;AAC1C,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,cAAb;AAA6BC,IAAAA;AAA7B,MAAqDb,SAAS,CACjEc,MAAF,IACCN,MAAM,CAAEM,MAAM,CAAEP,gBAAF,CAAR,CAAN,CAAqCQ,oBAArC,EAFkE,CAApE;AAKA,QAAM;AACLC,IAAAA,kBADK;AAELC,IAAAA,0BAFK;AAGLC,IAAAA;AAHK,MAIFV,MAAM,CAAET,WAAW,CAAEQ,gBAAF,CAAb,CAJV,CAN0C,CAY1C;;AACAT,EAAAA,SAAS,CAAE,MAAM;AAChBmB,IAAAA,0BAA0B,CAAE,IAAF,CAA1B;AACA,WAAO,MAAM;AACZA,MAAAA,0BAA0B,CAAE,KAAF,CAA1B;AACA,KAFD;AAGA,GALQ,EAKN,CAAEA,0BAAF,CALM,CAAT;;AAOA,MAAK,CAAEJ,mBAAP,EAA6B;AAC5B;AACA;;AAED,QAAMM,gBAAgB,GAAG,MAAM;AAC9BD,IAAAA,mBAAmB,CAAEP,SAAF,EAAaC,cAAb;AAA6B;AAAY,QAAzC,CAAnB;AACAI,IAAAA,kBAAkB;AAClB,GAHD;;AAKA,SACC,cAAC,KAAD;AACC,IAAA,KAAK,EAAGX,EAAE,CAAE,eAAF,CADX;AAEC,IAAA,cAAc,EAAGW;
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-removal-warning-modal/index.js"],"names":["useEffect","useDispatch","useSelect","Modal","Button","__experimentalHStack","HStack","__","store","blockEditorStore","unlock","blockTypePromptMessages","BlockRemovalWarningModal","clientIds","selectPrevious","blockNamesForPrompt","select","getRemovalPromptData","clearRemovalPrompt","toggleRemovalPromptSupport","privateRemoveBlocks","onConfirmRemoval","maxWidth","length","listStyleType","paddingLeft","map","name"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,oBAA1B;AACA,SAASC,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SACCC,KADD,EAECC,MAFD,EAGCC,oBAAoB,IAAIC,MAHzB,QAIO,uBAJP;AAKA,SAASC,EAAT,QAAmB,iBAAnB;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AACA,SAASC,MAAT,QAAuB,mBAAvB,C,CAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,uBAAuB,GAAG;AACtC,gBAAcJ,EAAE,CAAE,+CAAF,CADsB;AAEtC,uBAAqBA,EAAE,CACtB,sDADsB;AAFe,CAAhC;AAOP,OAAO,SAASK,wBAAT,GAAoC;AAC1C,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,cAAb;AAA6BC,IAAAA;AAA7B,MAAqDb,SAAS,CACjEc,MAAF,IACCN,MAAM,CAAEM,MAAM,CAAEP,gBAAF,CAAR,CAAN,CAAqCQ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C,cAAC,MAAD;AAAQ,IAAA,OAAO,EAAC,UAAhB;AAA2B,IAAA,OAAO,EAAGW;AAArC,KACGX,EAAE,CAAE,QAAF,CADL,CADD,EAIC,cAAC,MAAD;AAAQ,IAAA,OAAO,EAAC,SAAhB;AAA0B,IAAA,OAAO,EAAGc;AAApC,KACGd,EAAE,CAAE,QAAF,CADL,CAJD,CAvBD,CADD;AAkCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport {\n\tModal,\n\tButton,\n\t__experimentalHStack as HStack,\n} from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\n// In certain editing contexts, we'd like to prevent accidental removal of\n// important blocks. For example, in the site editor, the Query Loop block is\n// deemed important. In such cases, we'll ask the user for confirmation that\n// they intended to remove such block(s).\n//\n// @see https://github.com/WordPress/gutenberg/pull/51145\nexport const blockTypePromptMessages = {\n\t'core/query': __( 'Query Loop displays a list of posts or pages.' ),\n\t'core/post-content': __(\n\t\t'Post Content displays the content of a post or page.'\n\t),\n};\n\nexport function BlockRemovalWarningModal() {\n\tconst { clientIds, selectPrevious, blockNamesForPrompt } = useSelect(\n\t\t( select ) =>\n\t\t\tunlock( select( blockEditorStore ) ).getRemovalPromptData()\n\t);\n\n\tconst {\n\t\tclearRemovalPrompt,\n\t\ttoggleRemovalPromptSupport,\n\t\tprivateRemoveBlocks,\n\t} = unlock( useDispatch( blockEditorStore ) );\n\n\t// Signalling the removal prompt is in place.\n\tuseEffect( () => {\n\t\ttoggleRemovalPromptSupport( true );\n\t\treturn () => {\n\t\t\ttoggleRemovalPromptSupport( false );\n\t\t};\n\t}, [ toggleRemovalPromptSupport ] );\n\n\tif ( ! blockNamesForPrompt ) {\n\t\treturn;\n\t}\n\n\tconst onConfirmRemoval = () => {\n\t\tprivateRemoveBlocks( clientIds, selectPrevious, /* force */ true );\n\t\tclearRemovalPrompt();\n\t};\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ __( 'Are you sure?' ) }\n\t\t\tonRequestClose={ clearRemovalPrompt }\n\t\t\tstyle={ {\n\t\t\t\tmaxWidth: '40rem',\n\t\t\t} }\n\t\t>\n\t\t\t{ blockNamesForPrompt.length === 1 ? (\n\t\t\t\t<p>{ blockTypePromptMessages[ blockNamesForPrompt[ 0 ] ] }</p>\n\t\t\t) : (\n\t\t\t\t<ul style={ { listStyleType: 'disc', paddingLeft: '1rem' } }>\n\t\t\t\t\t{ blockNamesForPrompt.map( ( name ) => (\n\t\t\t\t\t\t<li key={ name }>\n\t\t\t\t\t\t\t{ blockTypePromptMessages[ name ] }\n\t\t\t\t\t\t</li>\n\t\t\t\t\t) ) }\n\t\t\t\t</ul>\n\t\t\t) }\n\t\t\t<p>\n\t\t\t\t{ blockNamesForPrompt.length > 1\n\t\t\t\t\t? __( 'Removing these blocks is not advised.' )\n\t\t\t\t\t: __( 'Removing this block is not advised.' ) }\n\t\t\t</p>\n\t\t\t<HStack justify=\"right\">\n\t\t\t\t<Button variant=\"tertiary\" onClick={ clearRemovalPrompt }>\n\t\t\t\t\t{ __( 'Cancel' ) }\n\t\t\t\t</Button>\n\t\t\t\t<Button variant=\"primary\" onClick={ onConfirmRemoval }>\n\t\t\t\t\t{ __( 'Delete' ) }\n\t\t\t\t</Button>\n\t\t\t</HStack>\n\t\t</Modal>\n\t);\n}\n"]}
|
|
@@ -13,7 +13,7 @@ import { useEffect, useRef, useState } from '@wordpress/element';
|
|
|
13
13
|
import { hasBlockSupport, store as blocksStore } from '@wordpress/blocks';
|
|
14
14
|
import { useSelect } from '@wordpress/data';
|
|
15
15
|
import { ToolbarItem, ToolbarButton, ToolbarGroup } from '@wordpress/components';
|
|
16
|
-
import {
|
|
16
|
+
import { next, previous } from '@wordpress/icons';
|
|
17
17
|
import { useViewportMatch } from '@wordpress/compose';
|
|
18
18
|
/**
|
|
19
19
|
* Internal dependencies
|
|
@@ -22,7 +22,6 @@ import { useViewportMatch } from '@wordpress/compose';
|
|
|
22
22
|
import NavigableToolbar from '../navigable-toolbar';
|
|
23
23
|
import BlockToolbar from '../block-toolbar';
|
|
24
24
|
import { store as blockEditorStore } from '../../store';
|
|
25
|
-
import BlockIcon from '../block-icon';
|
|
26
25
|
import { unlock } from '../../lock-unlock';
|
|
27
26
|
|
|
28
27
|
function BlockContextualToolbar({
|
|
@@ -59,7 +58,7 @@ function BlockContextualToolbar({
|
|
|
59
58
|
selectedBlockClientId: _selectedBlockClientId,
|
|
60
59
|
blockType: _selectedBlockClientId && getBlockType(getBlockName(_selectedBlockClientId)),
|
|
61
60
|
hasParents: parents.length,
|
|
62
|
-
showParentSelector: parentBlockType && hasBlockSupport(parentBlockType, '__experimentalParentSelector', true) && selectedBlockClientIds.length <= 1 && getBlockEditingMode(_selectedBlockClientId) === 'default'
|
|
61
|
+
showParentSelector: parentBlockType && getBlockEditingMode(firstParentClientId) === 'default' && hasBlockSupport(parentBlockType, '__experimentalParentSelector', true) && selectedBlockClientIds.length <= 1 && getBlockEditingMode(_selectedBlockClientId) === 'default'
|
|
63
62
|
};
|
|
64
63
|
}, []);
|
|
65
64
|
useEffect(() => {
|
|
@@ -83,22 +82,20 @@ function BlockContextualToolbar({
|
|
|
83
82
|
,
|
|
84
83
|
"aria-label": __('Block tools'),
|
|
85
84
|
...props
|
|
86
|
-
},
|
|
85
|
+
}, !isCollapsed && createElement(BlockToolbar, {
|
|
86
|
+
hideDragHandle: isFixed
|
|
87
|
+
}), isFixed && isLargeViewport && blockType && createElement(ToolbarGroup, {
|
|
87
88
|
className: isCollapsed ? 'block-editor-block-toolbar__group-expand-fixed-toolbar' : 'block-editor-block-toolbar__group-collapse-fixed-toolbar'
|
|
88
89
|
}, createElement(ToolbarItem, {
|
|
89
90
|
as: ToolbarButton,
|
|
90
91
|
ref: toolbarButtonRef,
|
|
91
|
-
icon: isCollapsed ?
|
|
92
|
-
icon: blockType.icon
|
|
93
|
-
}) : levelUp,
|
|
92
|
+
icon: isCollapsed ? next : previous,
|
|
94
93
|
onClick: () => {
|
|
95
94
|
setIsCollapsed(collapsed => !collapsed);
|
|
96
95
|
toolbarButtonRef.current.focus();
|
|
97
96
|
},
|
|
98
|
-
label: isCollapsed ? __('Show block tools') : __('
|
|
99
|
-
}))
|
|
100
|
-
hideDragHandle: isFixed
|
|
101
|
-
}));
|
|
97
|
+
label: isCollapsed ? __('Show block tools') : __('Hide block tools')
|
|
98
|
+
})));
|
|
102
99
|
}
|
|
103
100
|
|
|
104
101
|
export default BlockContextualToolbar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/block-tools/block-contextual-toolbar.js"],"names":["classnames","__","useEffect","useRef","useState","hasBlockSupport","store","blocksStore","useSelect","ToolbarItem","ToolbarButton","ToolbarGroup","
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/block-tools/block-contextual-toolbar.js"],"names":["classnames","__","useEffect","useRef","useState","hasBlockSupport","store","blocksStore","useSelect","ToolbarItem","ToolbarButton","ToolbarGroup","next","previous","useViewportMatch","NavigableToolbar","BlockToolbar","blockEditorStore","unlock","BlockContextualToolbar","focusOnMount","isFixed","props","isCollapsed","setIsCollapsed","toolbarButtonRef","isLargeViewport","blockType","hasParents","showParentSelector","selectedBlockClientId","select","getBlockName","getBlockParents","getSelectedBlockClientIds","getBlockEditingMode","getBlockType","selectedBlockClientIds","_selectedBlockClientId","parents","firstParentClientId","length","parentBlockName","parentBlockType","classes","collapsed","current","focus"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,SAAT,EAAoBC,MAApB,EAA4BC,QAA5B,QAA4C,oBAA5C;AACA,SAASC,eAAT,EAA0BC,KAAK,IAAIC,WAAnC,QAAsD,mBAAtD;AACA,S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,EACRJ,WAAW,GACR,wDADQ,GAER;AAJL,KAOC,cAAC,WAAD;AACC,IAAA,EAAE,EAAGb,aADN;AAEC,IAAA,GAAG,EAAGe,gBAFP;AAGC,IAAA,IAAI,EAAGF,WAAW,GAAGX,IAAH,GAAUC,QAH7B;AAIC,IAAA,OAAO,EAAG,MAAM;AACfW,MAAAA,cAAc,CAAIqB,SAAF,IAAiB,CAAEA,SAArB,CAAd;AACApB,MAAAA,gBAAgB,CAACqB,OAAjB,CAAyBC,KAAzB;AACA,KAPF;AAQC,IAAA,KAAK,EACJxB,WAAW,GACRtB,EAAE,CAAE,kBAAF,CADM,GAERA,EAAE,CAAE,kBAAF;AAXP,IAPD,CATF,CADD;AAmCA;;AAED,eAAekB,sBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useEffect, useRef, useState } from '@wordpress/element';\nimport { hasBlockSupport, store as blocksStore } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\nimport {\n\tToolbarItem,\n\tToolbarButton,\n\tToolbarGroup,\n} from '@wordpress/components';\nimport { next, previous } from '@wordpress/icons';\nimport { useViewportMatch } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport NavigableToolbar from '../navigable-toolbar';\nimport BlockToolbar from '../block-toolbar';\nimport { store as blockEditorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nfunction BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {\n\t// When the toolbar is fixed it can be collapsed\n\tconst [ isCollapsed, setIsCollapsed ] = useState( false );\n\tconst toolbarButtonRef = useRef();\n\n\tconst isLargeViewport = useViewportMatch( 'medium' );\n\tconst { blockType, hasParents, showParentSelector, selectedBlockClientId } =\n\t\tuseSelect( ( select ) => {\n\t\t\tconst {\n\t\t\t\tgetBlockName,\n\t\t\t\tgetBlockParents,\n\t\t\t\tgetSelectedBlockClientIds,\n\t\t\t\tgetBlockEditingMode,\n\t\t\t} = unlock( select( blockEditorStore ) );\n\t\t\tconst { getBlockType } = select( blocksStore );\n\t\t\tconst selectedBlockClientIds = getSelectedBlockClientIds();\n\t\t\tconst _selectedBlockClientId = selectedBlockClientIds[ 0 ];\n\t\t\tconst parents = getBlockParents( _selectedBlockClientId );\n\t\t\tconst firstParentClientId = parents[ parents.length - 1 ];\n\t\t\tconst parentBlockName = getBlockName( firstParentClientId );\n\t\t\tconst parentBlockType = getBlockType( parentBlockName );\n\n\t\t\treturn {\n\t\t\t\tselectedBlockClientId: _selectedBlockClientId,\n\t\t\t\tblockType:\n\t\t\t\t\t_selectedBlockClientId &&\n\t\t\t\t\tgetBlockType( getBlockName( _selectedBlockClientId ) ),\n\t\t\t\thasParents: parents.length,\n\t\t\t\tshowParentSelector:\n\t\t\t\t\tparentBlockType &&\n\t\t\t\t\tgetBlockEditingMode( firstParentClientId ) === 'default' &&\n\t\t\t\t\thasBlockSupport(\n\t\t\t\t\t\tparentBlockType,\n\t\t\t\t\t\t'__experimentalParentSelector',\n\t\t\t\t\t\ttrue\n\t\t\t\t\t) &&\n\t\t\t\t\tselectedBlockClientIds.length <= 1 &&\n\t\t\t\t\tgetBlockEditingMode( _selectedBlockClientId ) === 'default',\n\t\t\t};\n\t\t}, [] );\n\n\tuseEffect( () => {\n\t\tsetIsCollapsed( false );\n\t}, [ selectedBlockClientId ] );\n\n\tif (\n\t\tblockType &&\n\t\t! hasBlockSupport( blockType, '__experimentalToolbar', true )\n\t) {\n\t\treturn null;\n\t}\n\n\t// Shifts the toolbar to make room for the parent block selector.\n\tconst classes = classnames( 'block-editor-block-contextual-toolbar', {\n\t\t'has-parent': hasParents && showParentSelector,\n\t\t'is-fixed': isFixed,\n\t\t'is-collapsed': isCollapsed,\n\t} );\n\n\treturn (\n\t\t<NavigableToolbar\n\t\t\tfocusOnMount={ focusOnMount }\n\t\t\tclassName={ classes }\n\t\t\t/* translators: accessibility text for the block toolbar */\n\t\t\taria-label={ __( 'Block tools' ) }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ ! isCollapsed && <BlockToolbar hideDragHandle={ isFixed } /> }\n\t\t\t{ isFixed && isLargeViewport && blockType && (\n\t\t\t\t<ToolbarGroup\n\t\t\t\t\tclassName={\n\t\t\t\t\t\tisCollapsed\n\t\t\t\t\t\t\t? 'block-editor-block-toolbar__group-expand-fixed-toolbar'\n\t\t\t\t\t\t\t: 'block-editor-block-toolbar__group-collapse-fixed-toolbar'\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\tas={ ToolbarButton }\n\t\t\t\t\t\tref={ toolbarButtonRef }\n\t\t\t\t\t\ticon={ isCollapsed ? next : previous }\n\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\tsetIsCollapsed( ( collapsed ) => ! collapsed );\n\t\t\t\t\t\t\ttoolbarButtonRef.current.focus();\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\tisCollapsed\n\t\t\t\t\t\t\t\t? __( 'Show block tools' )\n\t\t\t\t\t\t\t\t: __( 'Hide block tools' )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</ToolbarGroup>\n\t\t\t) }\n\t\t</NavigableToolbar>\n\t);\n}\n\nexport default BlockContextualToolbar;\n"]}
|
|
@@ -8,7 +8,7 @@ import classnames from 'classnames';
|
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { useState, createPortal, forwardRef, useMemo,
|
|
11
|
+
import { useState, createPortal, forwardRef, useMemo, useEffect } from '@wordpress/element';
|
|
12
12
|
import { __ } from '@wordpress/i18n';
|
|
13
13
|
import { useResizeObserver, useMergeRefs, useRefEffect, useDisabled } from '@wordpress/compose';
|
|
14
14
|
import { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';
|
|
@@ -71,36 +71,6 @@ function bubbleEvents(doc) {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
function useParsedAssets(html) {
|
|
75
|
-
return useMemo(() => {
|
|
76
|
-
const doc = document.implementation.createHTMLDocument('');
|
|
77
|
-
doc.body.innerHTML = html;
|
|
78
|
-
return Array.from(doc.body.children);
|
|
79
|
-
}, [html]);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async function loadScript(head, {
|
|
83
|
-
id,
|
|
84
|
-
src
|
|
85
|
-
}) {
|
|
86
|
-
return new Promise((resolve, reject) => {
|
|
87
|
-
const script = head.ownerDocument.createElement('script');
|
|
88
|
-
script.id = id;
|
|
89
|
-
|
|
90
|
-
if (src) {
|
|
91
|
-
script.src = src;
|
|
92
|
-
|
|
93
|
-
script.onload = () => resolve();
|
|
94
|
-
|
|
95
|
-
script.onerror = () => reject();
|
|
96
|
-
} else {
|
|
97
|
-
resolve();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
head.appendChild(script);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
74
|
function Iframe({
|
|
105
75
|
contentRef,
|
|
106
76
|
children,
|
|
@@ -112,20 +82,23 @@ function Iframe({
|
|
|
112
82
|
forwardedRef: ref,
|
|
113
83
|
...props
|
|
114
84
|
}) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
85
|
+
const {
|
|
86
|
+
styles = '',
|
|
87
|
+
scripts = ''
|
|
88
|
+
} = useSelect(select => select(blockEditorStore).getSettings().__unstableResolvedAssets, []);
|
|
119
89
|
const [iframeDocument, setIframeDocument] = useState();
|
|
120
90
|
const [bodyClasses, setBodyClasses] = useState([]);
|
|
121
91
|
const compatStyles = useCompatibilityStyles();
|
|
122
|
-
const scripts = useParsedAssets(assets?.scripts);
|
|
123
92
|
const clearerRef = useBlockSelectionClearer();
|
|
124
93
|
const [before, writingFlowRef, after] = useWritingFlow();
|
|
125
94
|
const [contentResizeListener, {
|
|
126
95
|
height: contentHeight
|
|
127
96
|
}] = useResizeObserver();
|
|
128
97
|
const setRef = useRefEffect(node => {
|
|
98
|
+
node._load = () => {
|
|
99
|
+
setIframeDocument(node.contentDocument);
|
|
100
|
+
};
|
|
101
|
+
|
|
129
102
|
let iFrameDocument; // Prevent the default browser action for files dropped outside of dropzones.
|
|
130
103
|
|
|
131
104
|
function preventFileDropDefault(event) {
|
|
@@ -142,14 +115,12 @@ function Iframe({
|
|
|
142
115
|
} = contentDocument;
|
|
143
116
|
iFrameDocument = contentDocument;
|
|
144
117
|
bubbleEvents(contentDocument);
|
|
145
|
-
setIframeDocument(contentDocument);
|
|
146
118
|
clearerRef(documentElement); // Ideally ALL classes that are added through get_body_class should
|
|
147
119
|
// be added in the editor too, which we'll somehow have to get from
|
|
148
120
|
// the server in the future (which will run the PHP filters).
|
|
149
121
|
|
|
150
122
|
setBodyClasses(Array.from(ownerDocument.body.classList).filter(name => name.startsWith('admin-color-') || name.startsWith('post-type-') || name === 'wp-embed-responsive'));
|
|
151
123
|
contentDocument.dir = ownerDocument.dir;
|
|
152
|
-
documentElement.removeChild(contentDocument.body);
|
|
153
124
|
|
|
154
125
|
for (const compatStyle of compatStyles) {
|
|
155
126
|
if (contentDocument.getElementById(compatStyle.id)) {
|
|
@@ -172,21 +143,25 @@ function Iframe({
|
|
|
172
143
|
iFrameDocument?.removeEventListener('drop', preventFileDropDefault);
|
|
173
144
|
};
|
|
174
145
|
}, []);
|
|
175
|
-
const headRef = useRefEffect(element => {
|
|
176
|
-
scripts.reduce((promise, script) => promise.then(() => loadScript(element, script)), Promise.resolve()).finally(() => {
|
|
177
|
-
// When script are loaded, re-render blocks to allow them
|
|
178
|
-
// to initialise.
|
|
179
|
-
forceRender();
|
|
180
|
-
});
|
|
181
|
-
}, []);
|
|
182
146
|
const disabledRef = useDisabled({
|
|
183
147
|
isDisabled: !readonly
|
|
184
148
|
});
|
|
185
|
-
const bodyRef = useMergeRefs([contentRef, clearerRef, writingFlowRef, disabledRef
|
|
149
|
+
const bodyRef = useMergeRefs([contentRef, clearerRef, writingFlowRef, disabledRef]); // Correct doctype is required to enable rendering in standards
|
|
186
150
|
// mode. Also preload the styles to avoid a flash of unstyled
|
|
187
151
|
// content.
|
|
188
152
|
|
|
189
|
-
const html =
|
|
153
|
+
const html = `<!doctype html>
|
|
154
|
+
<html>
|
|
155
|
+
<head>
|
|
156
|
+
<script>window.frameElement._load()</script>
|
|
157
|
+
<style>html{height:auto!important;min-height:100%;}body{margin:0}</style>
|
|
158
|
+
${styles}
|
|
159
|
+
${scripts}
|
|
160
|
+
</head>
|
|
161
|
+
<body>
|
|
162
|
+
<script>document.currentScript.parentElement.remove()</script>
|
|
163
|
+
</body>
|
|
164
|
+
</html>`;
|
|
190
165
|
const [src, cleanup] = useMemo(() => {
|
|
191
166
|
const _src = URL.createObjectURL(new window.Blob([html], {
|
|
192
167
|
type: 'text/html'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/iframe/index.js"],"names":["classnames","useState","createPortal","forwardRef","useMemo","useReducer","useEffect","__","useResizeObserver","useMergeRefs","useRefEffect","useDisabled","__experimentalStyleProvider","StyleProvider","useSelect","useBlockSelectionClearer","useWritingFlow","useCompatibilityStyles","store","blockEditorStore","bubbleEvents","doc","defaultView","frameElement","bubbleEvent","event","prototype","Object","getPrototypeOf","constructorName","constructor","name","Constructor","window","init","key","MouseEvent","rect","getBoundingClientRect","clientX","left","clientY","top","newEvent","type","cancelled","dispatchEvent","preventDefault","eventTypes","addEventListener","useParsedAssets","html","document","implementation","createHTMLDocument","body","innerHTML","Array","from","children","loadScript","head","id","src","Promise","resolve","reject","script","ownerDocument","createElement","onload","onerror","appendChild","Iframe","contentRef","tabIndex","scale","frameSize","expand","readonly","forwardedRef","ref","props","assets","select","getSettings","__unstableResolvedAssets","forceRender","iframeDocument","setIframeDocument","bodyClasses","setBodyClasses","compatStyles","scripts","clearerRef","before","writingFlowRef","after","contentResizeListener","height","contentHeight","setRef","node","iFrameDocument","preventFileDropDefault","onLoad","contentDocument","documentElement","classList","filter","startsWith","dir","removeChild","compatStyle","getElementById","cloneNode","console","warn","removeEventListener","headRef","element","reduce","promise","then","finally","disabledRef","isDisabled","bodyRef","styles","cleanup","_src","URL","createObjectURL","Blob","revokeObjectURL","marginFromScaling","style","marginTop","marginBottom","transform","transition","IframeIfReady","isInitialised","__internalIsInitialized"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SACCC,QADD,EAECC,YAFD,EAGCC,UAHD,EAICC,OAJD,EAKCC,UALD,EAMCC,SAND,QAOO,oBAPP;AAQA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SACCC,iBADD,EAECC,YAFD,EAGCC,YAHD,EAICC,WAJD,QAKO,oBALP;AAMA,SAASC,2BAA2B,IAAIC,aAAxC,QAA6D,uBAA7D;AACA,SAASC,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,wBAAT,QAAyC,4BAAzC;AACA,SAASC,cAAT,QAA+B,iBAA/B;AACA,SAASC,sBAAT,QAAuC,4BAAvC;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,YAAT,CAAuBC,GAAvB,EAA6B;AAC5B,QAAM;AAAEC,IAAAA;AAAF,MAAkBD,GAAxB;AACA,QAAM;AAAEE,IAAAA;AAAF,MAAmBD,WAAzB;;AAEA,WAASE,WAAT,CAAsBC,KAAtB,EAA8B;AAC7B,UAAMC,SAAS,GAAGC,MAAM,CAACC,cAAP,CAAuBH,KAAvB,CAAlB;AACA,UAAMI,eAAe,GAAGH,SAAS,CAACI,WAAV,CAAsBC,IAA9C;AACA,UAAMC,WAAW,GAAGC,MAAM,CAAEJ,eAAF,CAA1B;AAEA,UAAMK,IAAI,GAAG,EAAb;;AAEA,SAAM,MAAMC,GAAZ,IAAmBV,KAAnB,EAA2B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AE;AAfL,KAFT;AAmBC,IAAA,GAAG,EAAGnI,YAAY,CAAE,CAAEwE,GAAF,EAAOoB,MAAP,CAAF,CAnBnB;AAoBC,IAAA,QAAQ,EAAG1B,QApBZ,CAqBC;AACA;AACA;AAvBD;AAwBC,IAAA,GAAG,EAAGZ,GAxBP;AAyBC,IAAA,KAAK,EAAGxD,EAAE,CAAE,eAAF;AAzBX,KA2BGiF,cAAc,IACftF,YAAY,CACX;AACC,IAAA,GAAG,EAAG6H,OADP;AAEC,IAAA,SAAS,EAAG/H,UAAU,CACrB,2BADqB,EAErB,uBAFqB,EAGrB,GAAG0F,WAHkB;AAFvB,KAQGQ,qBARH,EASC,cAAC,aAAD;AAAe,IAAA,QAAQ,EAAGV;AAA1B,KACG7B,QADH,CATD,CADW,EAcX6B,cAAc,CAACmB,eAdJ,CA5Bd,CAFD,EA+CGhC,QAAQ,IAAI,CAAZ,IAAiBsB,KA/CpB,CADD;AAmDA;;AAED,SAAS4C,aAAT,CAAwB3D,KAAxB,EAA+BD,GAA/B,EAAqC;AACpC,QAAM6D,aAAa,GAAGhI,SAAS,CAC5BsE,MAAF,IACCA,MAAM,CAAEjE,gBAAF,CAAN,CAA2BkE,WAA3B,GAAyC0D,uBAFZ,EAG9B,EAH8B,CAA/B,CADoC,CAOpC;AACA;AACA;AACA;AACA;;AACA,MAAK,CAAED,aAAP,EAAuB;AACtB,WAAO,IAAP;AACA;;AAED,SAAO,cAAC,MAAD,OAAa5D,KAAb;AAAqB,IAAA,YAAY,EAAGD;AAApC,IAAP;AACA;;AAED,eAAe9E,UAAU,CAAE0I,aAAF,CAAzB","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseState,\n\tcreatePortal,\n\tforwardRef,\n\tuseMemo,\n\tuseReducer,\n\tuseEffect,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tuseResizeObserver,\n\tuseMergeRefs,\n\tuseRefEffect,\n\tuseDisabled,\n} from '@wordpress/compose';\nimport { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { useBlockSelectionClearer } from '../block-selection-clearer';\nimport { useWritingFlow } from '../writing-flow';\nimport { useCompatibilityStyles } from './use-compatibility-styles';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Bubbles some event types (keydown, keypress, and dragover) to parent document\n * document to ensure that the keyboard shortcuts and drag and drop work.\n *\n * Ideally, we should remove event bubbling in the future. Keyboard shortcuts\n * should be context dependent, e.g. actions on blocks like Cmd+A should not\n * work globally outside the block editor.\n *\n * @param {Document} doc Document to attach listeners to.\n */\nfunction bubbleEvents( doc ) {\n\tconst { defaultView } = doc;\n\tconst { frameElement } = defaultView;\n\n\tfunction bubbleEvent( event ) {\n\t\tconst prototype = Object.getPrototypeOf( event );\n\t\tconst constructorName = prototype.constructor.name;\n\t\tconst Constructor = window[ constructorName ];\n\n\t\tconst init = {};\n\n\t\tfor ( const key in event ) {\n\t\t\tinit[ key ] = event[ key ];\n\t\t}\n\n\t\tif ( event instanceof defaultView.MouseEvent ) {\n\t\t\tconst rect = frameElement.getBoundingClientRect();\n\t\t\tinit.clientX += rect.left;\n\t\t\tinit.clientY += rect.top;\n\t\t}\n\n\t\tconst newEvent = new Constructor( event.type, init );\n\t\tconst cancelled = ! frameElement.dispatchEvent( newEvent );\n\n\t\tif ( cancelled ) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t}\n\n\tconst eventTypes = [ 'dragover', 'mousemove' ];\n\n\tfor ( const name of eventTypes ) {\n\t\tdoc.addEventListener( name, bubbleEvent );\n\t}\n}\n\nfunction useParsedAssets( html ) {\n\treturn useMemo( () => {\n\t\tconst doc = document.implementation.createHTMLDocument( '' );\n\t\tdoc.body.innerHTML = html;\n\t\treturn Array.from( doc.body.children );\n\t}, [ html ] );\n}\n\nasync function loadScript( head, { id, src } ) {\n\treturn new Promise( ( resolve, reject ) => {\n\t\tconst script = head.ownerDocument.createElement( 'script' );\n\t\tscript.id = id;\n\t\tif ( src ) {\n\t\t\tscript.src = src;\n\t\t\tscript.onload = () => resolve();\n\t\t\tscript.onerror = () => reject();\n\t\t} else {\n\t\t\tresolve();\n\t\t}\n\t\thead.appendChild( script );\n\t} );\n}\n\nfunction Iframe( {\n\tcontentRef,\n\tchildren,\n\ttabIndex = 0,\n\tscale = 1,\n\tframeSize = 0,\n\texpand = false,\n\treadonly,\n\tforwardedRef: ref,\n\t...props\n} ) {\n\tconst assets = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings().__unstableResolvedAssets,\n\t\t[]\n\t);\n\tconst [ , forceRender ] = useReducer( () => ( {} ) );\n\tconst [ iframeDocument, setIframeDocument ] = useState();\n\tconst [ bodyClasses, setBodyClasses ] = useState( [] );\n\tconst compatStyles = useCompatibilityStyles();\n\tconst scripts = useParsedAssets( assets?.scripts );\n\tconst clearerRef = useBlockSelectionClearer();\n\tconst [ before, writingFlowRef, after ] = useWritingFlow();\n\tconst [ contentResizeListener, { height: contentHeight } ] =\n\t\tuseResizeObserver();\n\tconst setRef = useRefEffect( ( node ) => {\n\t\tlet iFrameDocument;\n\t\t// Prevent the default browser action for files dropped outside of dropzones.\n\t\tfunction preventFileDropDefault( event ) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t\tfunction onLoad() {\n\t\t\tconst { contentDocument, ownerDocument } = node;\n\t\t\tconst { documentElement } = contentDocument;\n\t\t\tiFrameDocument = contentDocument;\n\n\t\t\tbubbleEvents( contentDocument );\n\t\t\tsetIframeDocument( contentDocument );\n\t\t\tclearerRef( documentElement );\n\n\t\t\t// Ideally ALL classes that are added through get_body_class should\n\t\t\t// be added in the editor too, which we'll somehow have to get from\n\t\t\t// the server in the future (which will run the PHP filters).\n\t\t\tsetBodyClasses(\n\t\t\t\tArray.from( ownerDocument.body.classList ).filter(\n\t\t\t\t\t( name ) =>\n\t\t\t\t\t\tname.startsWith( 'admin-color-' ) ||\n\t\t\t\t\t\tname.startsWith( 'post-type-' ) ||\n\t\t\t\t\t\tname === 'wp-embed-responsive'\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tcontentDocument.dir = ownerDocument.dir;\n\t\t\tdocumentElement.removeChild( contentDocument.body );\n\n\t\t\tfor ( const compatStyle of compatStyles ) {\n\t\t\t\tif ( contentDocument.getElementById( compatStyle.id ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tcontentDocument.head.appendChild(\n\t\t\t\t\tcompatStyle.cloneNode( true )\n\t\t\t\t);\n\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`${ compatStyle.id } was added to the iframe incorrectly. Please use block.json or enqueue_block_assets to add styles to the iframe.`,\n\t\t\t\t\tcompatStyle\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tiFrameDocument.addEventListener(\n\t\t\t\t'dragover',\n\t\t\t\tpreventFileDropDefault,\n\t\t\t\tfalse\n\t\t\t);\n\t\t\tiFrameDocument.addEventListener(\n\t\t\t\t'drop',\n\t\t\t\tpreventFileDropDefault,\n\t\t\t\tfalse\n\t\t\t);\n\t\t}\n\n\t\tnode.addEventListener( 'load', onLoad );\n\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'load', onLoad );\n\t\t\tiFrameDocument?.removeEventListener(\n\t\t\t\t'dragover',\n\t\t\t\tpreventFileDropDefault\n\t\t\t);\n\t\t\tiFrameDocument?.removeEventListener(\n\t\t\t\t'drop',\n\t\t\t\tpreventFileDropDefault\n\t\t\t);\n\t\t};\n\t}, [] );\n\n\tconst headRef = useRefEffect( ( element ) => {\n\t\tscripts\n\t\t\t.reduce(\n\t\t\t\t( promise, script ) =>\n\t\t\t\t\tpromise.then( () => loadScript( element, script ) ),\n\t\t\t\tPromise.resolve()\n\t\t\t)\n\t\t\t.finally( () => {\n\t\t\t\t// When script are loaded, re-render blocks to allow them\n\t\t\t\t// to initialise.\n\t\t\t\tforceRender();\n\t\t\t} );\n\t}, [] );\n\tconst disabledRef = useDisabled( { isDisabled: ! readonly } );\n\tconst bodyRef = useMergeRefs( [\n\t\tcontentRef,\n\t\tclearerRef,\n\t\twritingFlowRef,\n\t\tdisabledRef,\n\t\theadRef,\n\t] );\n\n\t// Correct doctype is required to enable rendering in standards\n\t// mode. Also preload the styles to avoid a flash of unstyled\n\t// content.\n\tconst html =\n\t\t'<!doctype html>' +\n\t\t'<style>html{height:auto!important;min-height:100%;}body{margin:0}</style>' +\n\t\t( assets?.styles ?? '' );\n\n\tconst [ src, cleanup ] = useMemo( () => {\n\t\tconst _src = URL.createObjectURL(\n\t\t\tnew window.Blob( [ html ], { type: 'text/html' } )\n\t\t);\n\t\treturn [ _src, () => URL.revokeObjectURL( _src ) ];\n\t}, [ html ] );\n\n\tuseEffect( () => cleanup, [ cleanup ] );\n\n\t// We need to counter the margin created by scaling the iframe. If the scale\n\t// is e.g. 0.45, then the top + bottom margin is 0.55 (1 - scale). Just the\n\t// top or bottom margin is 0.55 / 2 ((1 - scale) / 2).\n\tconst marginFromScaling = ( contentHeight * ( 1 - scale ) ) / 2;\n\n\treturn (\n\t\t<>\n\t\t\t{ tabIndex >= 0 && before }\n\t\t\t<iframe\n\t\t\t\t{ ...props }\n\t\t\t\tstyle={ {\n\t\t\t\t\t...props.style,\n\t\t\t\t\theight: expand ? contentHeight : props.style?.height,\n\t\t\t\t\tmarginTop:\n\t\t\t\t\t\tscale !== 1\n\t\t\t\t\t\t\t? -marginFromScaling + frameSize\n\t\t\t\t\t\t\t: props.style?.marginTop,\n\t\t\t\t\tmarginBottom:\n\t\t\t\t\t\tscale !== 1\n\t\t\t\t\t\t\t? -marginFromScaling + frameSize\n\t\t\t\t\t\t\t: props.style?.marginBottom,\n\t\t\t\t\ttransform:\n\t\t\t\t\t\tscale !== 1\n\t\t\t\t\t\t\t? `scale( ${ scale } )`\n\t\t\t\t\t\t\t: props.style?.transform,\n\t\t\t\t\ttransition: 'all .3s',\n\t\t\t\t} }\n\t\t\t\tref={ useMergeRefs( [ ref, setRef ] ) }\n\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\t// Correct doctype is required to enable rendering in standards\n\t\t\t\t// mode. Also preload the styles to avoid a flash of unstyled\n\t\t\t\t// content.\n\t\t\t\tsrc={ src }\n\t\t\t\ttitle={ __( 'Editor canvas' ) }\n\t\t\t>\n\t\t\t\t{ iframeDocument &&\n\t\t\t\t\tcreatePortal(\n\t\t\t\t\t\t<body\n\t\t\t\t\t\t\tref={ bodyRef }\n\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t'block-editor-iframe__body',\n\t\t\t\t\t\t\t\t'editor-styles-wrapper',\n\t\t\t\t\t\t\t\t...bodyClasses\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ contentResizeListener }\n\t\t\t\t\t\t\t<StyleProvider document={ iframeDocument }>\n\t\t\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t\t</StyleProvider>\n\t\t\t\t\t\t</body>,\n\t\t\t\t\t\tiframeDocument.documentElement\n\t\t\t\t\t) }\n\t\t\t</iframe>\n\t\t\t{ tabIndex >= 0 && after }\n\t\t</>\n\t);\n}\n\nfunction IframeIfReady( props, ref ) {\n\tconst isInitialised = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings().__internalIsInitialized,\n\t\t[]\n\t);\n\n\t// We shouldn't render the iframe until the editor settings are initialised.\n\t// The initial settings are needed to get the styles for the srcDoc, which\n\t// cannot be changed after the iframe is mounted. srcDoc is used to to set\n\t// the initial iframe HTML, which is required to avoid a flash of unstyled\n\t// content.\n\tif ( ! isInitialised ) {\n\t\treturn null;\n\t}\n\n\treturn <Iframe { ...props } forwardedRef={ ref } />;\n}\n\nexport default forwardRef( IframeIfReady );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/iframe/index.js"],"names":["classnames","useState","createPortal","forwardRef","useMemo","useEffect","__","useResizeObserver","useMergeRefs","useRefEffect","useDisabled","__experimentalStyleProvider","StyleProvider","useSelect","useBlockSelectionClearer","useWritingFlow","useCompatibilityStyles","store","blockEditorStore","bubbleEvents","doc","defaultView","frameElement","bubbleEvent","event","prototype","Object","getPrototypeOf","constructorName","constructor","name","Constructor","window","init","key","MouseEvent","rect","getBoundingClientRect","clientX","left","clientY","top","newEvent","type","cancelled","dispatchEvent","preventDefault","eventTypes","addEventListener","Iframe","contentRef","children","tabIndex","scale","frameSize","expand","readonly","forwardedRef","ref","props","styles","scripts","select","getSettings","__unstableResolvedAssets","iframeDocument","setIframeDocument","bodyClasses","setBodyClasses","compatStyles","clearerRef","before","writingFlowRef","after","contentResizeListener","height","contentHeight","setRef","node","_load","contentDocument","iFrameDocument","preventFileDropDefault","onLoad","ownerDocument","documentElement","Array","from","body","classList","filter","startsWith","dir","compatStyle","getElementById","id","head","appendChild","cloneNode","console","warn","removeEventListener","disabledRef","isDisabled","bodyRef","html","src","cleanup","_src","URL","createObjectURL","Blob","revokeObjectURL","marginFromScaling","style","marginTop","marginBottom","transform","transition","IframeIfReady","isInitialised","__internalIsInitialized"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SACCC,QADD,EAECC,YAFD,EAGCC,UAHD,EAICC,OAJD,EAKCC,SALD,QAMO,oBANP;AAOA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SACCC,iBADD,EAECC,YAFD,EAGCC,YAHD,EAICC,WAJD,QAKO,oBALP;AAMA,SAASC,2BAA2B,IAAIC,aAAxC,QAA6D,uBAA7D;AACA,SAASC,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,SAASC,wBAAT,QAAyC,4BAAzC;AACA,SAASC,cAAT,QAA+B,iBAA/B;AACA,SAASC,sBAAT,QAAuC,4BAAvC;AACA,SAASC,KAAK,IAAIC,gBAAlB,QAA0C,aAA1C;AAEA;A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AAED,SAAO,cAAC,MAAD,OAAa7D,KAAb;AAAqB,IAAA,YAAY,EAAGD;AAApC,IAAP;AACA;;AAED,eAAevD,UAAU,CAAEoH,aAAF,CAAzB","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseState,\n\tcreatePortal,\n\tforwardRef,\n\tuseMemo,\n\tuseEffect,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tuseResizeObserver,\n\tuseMergeRefs,\n\tuseRefEffect,\n\tuseDisabled,\n} from '@wordpress/compose';\nimport { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { useBlockSelectionClearer } from '../block-selection-clearer';\nimport { useWritingFlow } from '../writing-flow';\nimport { useCompatibilityStyles } from './use-compatibility-styles';\nimport { store as blockEditorStore } from '../../store';\n\n/**\n * Bubbles some event types (keydown, keypress, and dragover) to parent document\n * document to ensure that the keyboard shortcuts and drag and drop work.\n *\n * Ideally, we should remove event bubbling in the future. Keyboard shortcuts\n * should be context dependent, e.g. actions on blocks like Cmd+A should not\n * work globally outside the block editor.\n *\n * @param {Document} doc Document to attach listeners to.\n */\nfunction bubbleEvents( doc ) {\n\tconst { defaultView } = doc;\n\tconst { frameElement } = defaultView;\n\n\tfunction bubbleEvent( event ) {\n\t\tconst prototype = Object.getPrototypeOf( event );\n\t\tconst constructorName = prototype.constructor.name;\n\t\tconst Constructor = window[ constructorName ];\n\n\t\tconst init = {};\n\n\t\tfor ( const key in event ) {\n\t\t\tinit[ key ] = event[ key ];\n\t\t}\n\n\t\tif ( event instanceof defaultView.MouseEvent ) {\n\t\t\tconst rect = frameElement.getBoundingClientRect();\n\t\t\tinit.clientX += rect.left;\n\t\t\tinit.clientY += rect.top;\n\t\t}\n\n\t\tconst newEvent = new Constructor( event.type, init );\n\t\tconst cancelled = ! frameElement.dispatchEvent( newEvent );\n\n\t\tif ( cancelled ) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t}\n\n\tconst eventTypes = [ 'dragover', 'mousemove' ];\n\n\tfor ( const name of eventTypes ) {\n\t\tdoc.addEventListener( name, bubbleEvent );\n\t}\n}\n\nfunction Iframe( {\n\tcontentRef,\n\tchildren,\n\ttabIndex = 0,\n\tscale = 1,\n\tframeSize = 0,\n\texpand = false,\n\treadonly,\n\tforwardedRef: ref,\n\t...props\n} ) {\n\tconst { styles = '', scripts = '' } = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings().__unstableResolvedAssets,\n\t\t[]\n\t);\n\tconst [ iframeDocument, setIframeDocument ] = useState();\n\tconst [ bodyClasses, setBodyClasses ] = useState( [] );\n\tconst compatStyles = useCompatibilityStyles();\n\tconst clearerRef = useBlockSelectionClearer();\n\tconst [ before, writingFlowRef, after ] = useWritingFlow();\n\tconst [ contentResizeListener, { height: contentHeight } ] =\n\t\tuseResizeObserver();\n\tconst setRef = useRefEffect( ( node ) => {\n\t\tnode._load = () => {\n\t\t\tsetIframeDocument( node.contentDocument );\n\t\t};\n\t\tlet iFrameDocument;\n\t\t// Prevent the default browser action for files dropped outside of dropzones.\n\t\tfunction preventFileDropDefault( event ) {\n\t\t\tevent.preventDefault();\n\t\t}\n\t\tfunction onLoad() {\n\t\t\tconst { contentDocument, ownerDocument } = node;\n\t\t\tconst { documentElement } = contentDocument;\n\t\t\tiFrameDocument = contentDocument;\n\n\t\t\tbubbleEvents( contentDocument );\n\t\t\tclearerRef( documentElement );\n\n\t\t\t// Ideally ALL classes that are added through get_body_class should\n\t\t\t// be added in the editor too, which we'll somehow have to get from\n\t\t\t// the server in the future (which will run the PHP filters).\n\t\t\tsetBodyClasses(\n\t\t\t\tArray.from( ownerDocument.body.classList ).filter(\n\t\t\t\t\t( name ) =>\n\t\t\t\t\t\tname.startsWith( 'admin-color-' ) ||\n\t\t\t\t\t\tname.startsWith( 'post-type-' ) ||\n\t\t\t\t\t\tname === 'wp-embed-responsive'\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tcontentDocument.dir = ownerDocument.dir;\n\n\t\t\tfor ( const compatStyle of compatStyles ) {\n\t\t\t\tif ( contentDocument.getElementById( compatStyle.id ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tcontentDocument.head.appendChild(\n\t\t\t\t\tcompatStyle.cloneNode( true )\n\t\t\t\t);\n\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`${ compatStyle.id } was added to the iframe incorrectly. Please use block.json or enqueue_block_assets to add styles to the iframe.`,\n\t\t\t\t\tcompatStyle\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tiFrameDocument.addEventListener(\n\t\t\t\t'dragover',\n\t\t\t\tpreventFileDropDefault,\n\t\t\t\tfalse\n\t\t\t);\n\t\t\tiFrameDocument.addEventListener(\n\t\t\t\t'drop',\n\t\t\t\tpreventFileDropDefault,\n\t\t\t\tfalse\n\t\t\t);\n\t\t}\n\n\t\tnode.addEventListener( 'load', onLoad );\n\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'load', onLoad );\n\t\t\tiFrameDocument?.removeEventListener(\n\t\t\t\t'dragover',\n\t\t\t\tpreventFileDropDefault\n\t\t\t);\n\t\t\tiFrameDocument?.removeEventListener(\n\t\t\t\t'drop',\n\t\t\t\tpreventFileDropDefault\n\t\t\t);\n\t\t};\n\t}, [] );\n\n\tconst disabledRef = useDisabled( { isDisabled: ! readonly } );\n\tconst bodyRef = useMergeRefs( [\n\t\tcontentRef,\n\t\tclearerRef,\n\t\twritingFlowRef,\n\t\tdisabledRef,\n\t] );\n\n\t// Correct doctype is required to enable rendering in standards\n\t// mode. Also preload the styles to avoid a flash of unstyled\n\t// content.\n\tconst html = `<!doctype html>\n<html>\n\t<head>\n\t\t<script>window.frameElement._load()</script>\n\t\t<style>html{height:auto!important;min-height:100%;}body{margin:0}</style>\n\t\t${ styles }\n\t\t${ scripts }\n\t</head>\n\t<body>\n\t\t<script>document.currentScript.parentElement.remove()</script>\n\t</body>\n</html>`;\n\n\tconst [ src, cleanup ] = useMemo( () => {\n\t\tconst _src = URL.createObjectURL(\n\t\t\tnew window.Blob( [ html ], { type: 'text/html' } )\n\t\t);\n\t\treturn [ _src, () => URL.revokeObjectURL( _src ) ];\n\t}, [ html ] );\n\n\tuseEffect( () => cleanup, [ cleanup ] );\n\n\t// We need to counter the margin created by scaling the iframe. If the scale\n\t// is e.g. 0.45, then the top + bottom margin is 0.55 (1 - scale). Just the\n\t// top or bottom margin is 0.55 / 2 ((1 - scale) / 2).\n\tconst marginFromScaling = ( contentHeight * ( 1 - scale ) ) / 2;\n\n\treturn (\n\t\t<>\n\t\t\t{ tabIndex >= 0 && before }\n\t\t\t<iframe\n\t\t\t\t{ ...props }\n\t\t\t\tstyle={ {\n\t\t\t\t\t...props.style,\n\t\t\t\t\theight: expand ? contentHeight : props.style?.height,\n\t\t\t\t\tmarginTop:\n\t\t\t\t\t\tscale !== 1\n\t\t\t\t\t\t\t? -marginFromScaling + frameSize\n\t\t\t\t\t\t\t: props.style?.marginTop,\n\t\t\t\t\tmarginBottom:\n\t\t\t\t\t\tscale !== 1\n\t\t\t\t\t\t\t? -marginFromScaling + frameSize\n\t\t\t\t\t\t\t: props.style?.marginBottom,\n\t\t\t\t\ttransform:\n\t\t\t\t\t\tscale !== 1\n\t\t\t\t\t\t\t? `scale( ${ scale } )`\n\t\t\t\t\t\t\t: props.style?.transform,\n\t\t\t\t\ttransition: 'all .3s',\n\t\t\t\t} }\n\t\t\t\tref={ useMergeRefs( [ ref, setRef ] ) }\n\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\t// Correct doctype is required to enable rendering in standards\n\t\t\t\t// mode. Also preload the styles to avoid a flash of unstyled\n\t\t\t\t// content.\n\t\t\t\tsrc={ src }\n\t\t\t\ttitle={ __( 'Editor canvas' ) }\n\t\t\t>\n\t\t\t\t{ iframeDocument &&\n\t\t\t\t\tcreatePortal(\n\t\t\t\t\t\t<body\n\t\t\t\t\t\t\tref={ bodyRef }\n\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t'block-editor-iframe__body',\n\t\t\t\t\t\t\t\t'editor-styles-wrapper',\n\t\t\t\t\t\t\t\t...bodyClasses\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ contentResizeListener }\n\t\t\t\t\t\t\t<StyleProvider document={ iframeDocument }>\n\t\t\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t\t</StyleProvider>\n\t\t\t\t\t\t</body>,\n\t\t\t\t\t\tiframeDocument.documentElement\n\t\t\t\t\t) }\n\t\t\t</iframe>\n\t\t\t{ tabIndex >= 0 && after }\n\t\t</>\n\t);\n}\n\nfunction IframeIfReady( props, ref ) {\n\tconst isInitialised = useSelect(\n\t\t( select ) =>\n\t\t\tselect( blockEditorStore ).getSettings().__internalIsInitialized,\n\t\t[]\n\t);\n\n\t// We shouldn't render the iframe until the editor settings are initialised.\n\t// The initial settings are needed to get the styles for the srcDoc, which\n\t// cannot be changed after the iframe is mounted. srcDoc is used to to set\n\t// the initial iframe HTML, which is required to avoid a flash of unstyled\n\t// content.\n\tif ( ! isInitialised ) {\n\t\treturn null;\n\t}\n\n\treturn <Iframe { ...props } forwardedRef={ ref } />;\n}\n\nexport default forwardRef( IframeIfReady );\n"]}
|
|
@@ -116,4 +116,9 @@ export { default as __experimentalInspectorPopoverHeader } from './inspector-pop
|
|
|
116
116
|
|
|
117
117
|
export { default as BlockEditorProvider } from './provider';
|
|
118
118
|
export { default as useSetting } from './use-setting';
|
|
119
|
+
/*
|
|
120
|
+
* The following rename hint component can be removed in 6.4.
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
export { default as ReusableBlocksRenameHint } from './inserter/reusable-block-rename-hint';
|
|
119
124
|
//# sourceMappingURL=index.js.map
|