@wordpress/block-editor 8.5.5 → 8.5.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.
|
@@ -43,63 +43,63 @@ const BLOCK_PREFIX = 'wp-block';
|
|
|
43
43
|
*
|
|
44
44
|
* Ideally, this hook should be removed in the future and styles should be added
|
|
45
45
|
* explicitly as editor styles.
|
|
46
|
-
*
|
|
47
|
-
* @param {Document} doc The document to append cloned stylesheets to.
|
|
48
46
|
*/
|
|
49
47
|
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
function useStylesCompatibility() {
|
|
49
|
+
return (0, _compose.useRefEffect)(node => {
|
|
50
|
+
// Search the document for stylesheets targetting the editor canvas.
|
|
51
|
+
Array.from(document.styleSheets).forEach(styleSheet => {
|
|
52
|
+
try {
|
|
53
|
+
// May fail for external styles.
|
|
54
|
+
// eslint-disable-next-line no-unused-expressions
|
|
55
|
+
styleSheet.cssRules;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
const {
|
|
61
|
+
ownerNode,
|
|
62
|
+
cssRules
|
|
63
|
+
} = styleSheet;
|
|
65
64
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
if (!cssRules) {
|
|
66
|
+
return;
|
|
67
|
+
} // Generally, ignore inline styles. We add inline styles belonging to a
|
|
68
|
+
// stylesheet later, which may or may not match the selectors.
|
|
70
69
|
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
if (ownerNode.tagName !== 'LINK') {
|
|
72
|
+
return;
|
|
73
|
+
} // Don't try to add the reset styles, which were removed as a dependency
|
|
74
|
+
// from `edit-blocks` for the iframe since we don't need to reset admin
|
|
75
|
+
// styles.
|
|
77
76
|
|
|
78
77
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
if (ownerNode.id === 'wp-reset-editor-styles-css') {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
82
81
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
const isMatch = Array.from(cssRules).find(_ref => {
|
|
83
|
+
let {
|
|
84
|
+
selectorText
|
|
85
|
+
} = _ref;
|
|
86
|
+
return selectorText && (selectorText.includes(`.${BODY_CLASS_NAME}`) || selectorText.includes(`.${BLOCK_PREFIX}`));
|
|
87
|
+
});
|
|
89
88
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
if (isMatch && !node.ownerDocument.getElementById(ownerNode.id)) {
|
|
90
|
+
// Display warning once we have a way to add style dependencies to the editor.
|
|
91
|
+
// See: https://github.com/WordPress/gutenberg/pull/37466.
|
|
92
|
+
node.appendChild(ownerNode.cloneNode(true)); // Add inline styles belonging to the stylesheet.
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
const inlineCssId = ownerNode.id.replace('-css', '-inline-css');
|
|
95
|
+
const inlineCssElement = document.getElementById(inlineCssId);
|
|
97
96
|
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
if (inlineCssElement) {
|
|
98
|
+
node.appendChild(inlineCssElement.cloneNode(true));
|
|
99
|
+
}
|
|
100
100
|
}
|
|
101
|
-
}
|
|
102
|
-
});
|
|
101
|
+
});
|
|
102
|
+
}, []);
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
105
|
* Bubbles some event types (keydown, keypress, and dragover) to parent document
|
|
@@ -239,11 +239,7 @@ function Iframe(_ref3, ref) {
|
|
|
239
239
|
});
|
|
240
240
|
}, []);
|
|
241
241
|
const bodyRef = (0, _compose.useMergeRefs)([contentRef, clearerRef, writingFlowRef]);
|
|
242
|
-
|
|
243
|
-
if (iframeDocument) {
|
|
244
|
-
styleSheetsCompat(iframeDocument);
|
|
245
|
-
}
|
|
246
|
-
}, [iframeDocument]);
|
|
242
|
+
const styleCompatibilityRef = useStylesCompatibility();
|
|
247
243
|
head = (0, _element.createElement)(_element.Fragment, null, (0, _element.createElement)("style", null, 'body{margin:0}'), styles.map(_ref4 => {
|
|
248
244
|
let {
|
|
249
245
|
tagName,
|
|
@@ -281,7 +277,12 @@ function Iframe(_ref3, ref) {
|
|
|
281
277
|
}, head), (0, _element.createElement)("body", {
|
|
282
278
|
ref: bodyRef,
|
|
283
279
|
className: (0, _classnames.default)(BODY_CLASS_NAME, ...bodyClasses)
|
|
284
|
-
}, (0, _element.createElement)(
|
|
280
|
+
}, (0, _element.createElement)("div", {
|
|
281
|
+
style: {
|
|
282
|
+
display: 'none'
|
|
283
|
+
},
|
|
284
|
+
ref: styleCompatibilityRef
|
|
285
|
+
}), (0, _element.createElement)(_components.__experimentalStyleProvider, {
|
|
285
286
|
document: iframeDocument
|
|
286
287
|
}, children))), iframeDocument.documentElement)), tabIndex >= 0 && after);
|
|
287
288
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/iframe/index.js"],"names":["BODY_CLASS_NAME","BLOCK_PREFIX","styleSheetsCompat","doc","Array","from","document","styleSheets","forEach","styleSheet","cssRules","e","ownerNode","tagName","id","isMatch","find","selectorText","includes","getElementById","head","appendChild","cloneNode","inlineCssId","replace","inlineCssElement","bubbleEvents","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","implementation","createHTMLDocument","body","innerHTML","children","loadScript","src","Promise","resolve","reject","script","ownerDocument","createElement","onload","onerror","Iframe","ref","contentRef","tabIndex","assets","props","forceRender","iframeDocument","setIframeDocument","bodyClasses","setBodyClasses","styles","scripts","clearerRef","before","writingFlowRef","after","setRef","node","setDocumentIfReady","contentDocument","readyState","documentElement","classList","filter","startsWith","dir","removeChild","removeEventListener","headRef","element","reduce","promise","then","finally","bodyRef","map","href","rel","media","textContent","TagName","toLowerCase"],"mappings":";;;;;;;;;AAQA;;;;AALA;;AAaA;;AACA;;AACA;;AAKA;;AACA;;AAxBA;AACA;AACA;;AAGA;AACA;AACA;;AAaA;AACA;AACA;AAIA,MAAMA,eAAe,GAAG,uBAAxB;AACA,MAAMC,YAAY,GAAG,UAArB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,iBAAT,CAA4BC,GAA5B,EAAkC;AACjC;AACAC,EAAAA,KAAK,CAACC,IAAN,CAAYC,QAAQ,CAACC,WAArB,EAAmCC,OAAnC,CAA8CC,UAAF,IAAkB;AAC7D,QAAI;AACH;AACA;AACAA,MAAAA,UAAU,CAACC,QAAX;AACA,KAJD,CAIE,OAAQC,CAAR,EAAY;AACb;AACA;;AAED,UAAM;AAAEC,MAAAA,SAAF;AAAaF,MAAAA;AAAb,QAA0BD,UAAhC;;AAEA,QAAK,CAAEC,QAAP,EAAkB;AACjB;AACA,KAb4D,CAe7D;AACA;;;AACA,QAAKE,SAAS,CAACC,OAAV,KAAsB,MAA3B,EAAoC;AACnC;AACA,KAnB4D,CAqB7D;AACA;AACA;;;AACA,QAAKD,SAAS,CAACE,EAAV,KAAiB,4BAAtB,EAAqD;AACpD;AACA;;AAED,UAAMC,OAAO,GAAGX,KAAK,CAACC,IAAN,CAAYK,QAAZ,EAAuBM,IAAvB,CACf;AAAA,UAAE;AAAEC,QAAAA;AAAF,OAAF;AAAA,aACCA,YAAY,KACVA,YAAY,CAACC,QAAb,CAAwB,IAAIlB,eAAiB,EAA7C,KACDiB,YAAY,CAACC,QAAb,CAAwB,IAAIj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X,GAAGiF,WAFQ;AAFb,KAOC,4BAAC,uCAAD;AAAe,IAAA,QAAQ,EAAGF;AAA1B,KACGlB,QADH,CAPD,CAFD,CADD,EAeCkB,cAAc,CAACe,eAfhB,CATF,CAFD,EA6BGnB,QAAQ,IAAI,CAAZ,IAAiBa,KA7BpB,CADD;AAiCA;;eAEc,yBAAYhB,MAAZ,C","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseState,\n\tcreatePortal,\n\tforwardRef,\n\tuseEffect,\n\tuseMemo,\n\tuseReducer,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { useBlockSelectionClearer } from '../block-selection-clearer';\nimport { useWritingFlow } from '../writing-flow';\n\nconst BODY_CLASS_NAME = 'editor-styles-wrapper';\nconst BLOCK_PREFIX = 'wp-block';\n\n/**\n * Clones stylesheets targetting the editor canvas to the given document. A\n * stylesheet is considered targetting the editor a canvas if it contains the\n * `editor-styles-wrapper`, `wp-block`, or `wp-block-*` class selectors.\n *\n * Ideally, this hook should be removed in the future and styles should be added\n * explicitly as editor styles.\n *\n * @param {Document} doc The document to append cloned stylesheets to.\n */\nfunction styleSheetsCompat( doc ) {\n\t// Search the document for stylesheets targetting the editor canvas.\n\tArray.from( document.styleSheets ).forEach( ( styleSheet ) => {\n\t\ttry {\n\t\t\t// May fail for external styles.\n\t\t\t// eslint-disable-next-line no-unused-expressions\n\t\t\tstyleSheet.cssRules;\n\t\t} catch ( e ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { ownerNode, cssRules } = styleSheet;\n\n\t\tif ( ! cssRules ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Generally, ignore inline styles. We add inline styles belonging to a\n\t\t// stylesheet later, which may or may not match the selectors.\n\t\tif ( ownerNode.tagName !== 'LINK' ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Don't try to add the reset styles, which were removed as a dependency\n\t\t// from `edit-blocks` for the iframe since we don't need to reset admin\n\t\t// styles.\n\t\tif ( ownerNode.id === 'wp-reset-editor-styles-css' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst isMatch = Array.from( cssRules ).find(\n\t\t\t( { selectorText } ) =>\n\t\t\t\tselectorText &&\n\t\t\t\t( selectorText.includes( `.${ BODY_CLASS_NAME }` ) ||\n\t\t\t\t\tselectorText.includes( `.${ BLOCK_PREFIX }` ) )\n\t\t);\n\n\t\tif ( isMatch && ! doc.getElementById( ownerNode.id ) ) {\n\t\t\t// Display warning once we have a way to add style dependencies to the editor.\n\t\t\t// See: https://github.com/WordPress/gutenberg/pull/37466.\n\n\t\t\tdoc.head.appendChild( ownerNode.cloneNode( true ) );\n\n\t\t\t// Add inline styles belonging to the stylesheet.\n\t\t\tconst inlineCssId = ownerNode.id.replace( '-css', '-inline-css' );\n\t\t\tconst inlineCssElement = document.getElementById( inlineCssId );\n\n\t\t\tif ( inlineCssElement ) {\n\t\t\t\tdoc.head.appendChild( inlineCssElement.cloneNode( true ) );\n\t\t\t}\n\t\t}\n\t} );\n}\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' ];\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\t{ contentRef, children, head, tabIndex = 0, assets, ...props },\n\tref\n) {\n\tconst [ , forceRender ] = useReducer( () => ( {} ) );\n\tconst [ iframeDocument, setIframeDocument ] = useState();\n\tconst [ bodyClasses, setBodyClasses ] = useState( [] );\n\tconst styles = useParsedAssets( assets?.styles );\n\tconst scripts = useParsedAssets( assets?.scripts );\n\tconst clearerRef = useBlockSelectionClearer();\n\tconst [ before, writingFlowRef, after ] = useWritingFlow();\n\tconst setRef = useRefEffect( ( node ) => {\n\t\tfunction setDocumentIfReady() {\n\t\t\tconst { contentDocument, ownerDocument } = node;\n\t\t\tconst { readyState, documentElement } = contentDocument;\n\n\t\t\tif ( readyState !== 'interactive' && readyState !== 'complete' ) {\n\t\t\t\treturn false;\n\t\t\t}\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.head );\n\t\t\tdocumentElement.removeChild( contentDocument.body );\n\n\t\t\treturn true;\n\t\t}\n\n\t\t// Document set with srcDoc is not immediately ready.\n\t\tnode.addEventListener( 'load', setDocumentIfReady );\n\n\t\treturn () => node.removeEventListener( 'load', setDocumentIfReady );\n\t}, [] );\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 bodyRef = useMergeRefs( [ contentRef, clearerRef, writingFlowRef ] );\n\n\tuseEffect( () => {\n\t\tif ( iframeDocument ) {\n\t\t\tstyleSheetsCompat( iframeDocument );\n\t\t}\n\t}, [ iframeDocument ] );\n\n\thead = (\n\t\t<>\n\t\t\t<style>{ 'body{margin:0}' }</style>\n\t\t\t{ styles.map(\n\t\t\t\t( { tagName, href, id, rel, media, textContent } ) => {\n\t\t\t\t\tconst TagName = tagName.toLowerCase();\n\n\t\t\t\t\tif ( TagName === 'style' ) {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<TagName { ...{ id } } key={ id }>\n\t\t\t\t\t\t\t\t{ textContent }\n\t\t\t\t\t\t\t</TagName>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<TagName { ...{ href, id, rel, media } } key={ id } />\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t) }\n\t\t\t{ head }\n\t\t</>\n\t);\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\tref={ useMergeRefs( [ ref, setRef ] ) }\n\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\t// Correct doctype is required to enable rendering in standards mode\n\t\t\t\tsrcDoc=\"<!doctype html>\"\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<>\n\t\t\t\t\t\t\t<head ref={ headRef }>{ head }</head>\n\t\t\t\t\t\t\t<body\n\t\t\t\t\t\t\t\tref={ bodyRef }\n\t\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t\tBODY_CLASS_NAME,\n\t\t\t\t\t\t\t\t\t...bodyClasses\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<StyleProvider document={ iframeDocument }>\n\t\t\t\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t\t\t</StyleProvider>\n\t\t\t\t\t\t\t</body>\n\t\t\t\t\t\t</>,\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\nexport default forwardRef( Iframe );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/iframe/index.js"],"names":["BODY_CLASS_NAME","BLOCK_PREFIX","useStylesCompatibility","node","Array","from","document","styleSheets","forEach","styleSheet","cssRules","e","ownerNode","tagName","id","isMatch","find","selectorText","includes","ownerDocument","getElementById","appendChild","cloneNode","inlineCssId","replace","inlineCssElement","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","implementation","createHTMLDocument","body","innerHTML","children","loadScript","head","src","Promise","resolve","reject","script","createElement","onload","onerror","Iframe","ref","contentRef","tabIndex","assets","props","forceRender","iframeDocument","setIframeDocument","bodyClasses","setBodyClasses","styles","scripts","clearerRef","before","writingFlowRef","after","setRef","setDocumentIfReady","contentDocument","readyState","documentElement","classList","filter","startsWith","dir","removeChild","removeEventListener","headRef","element","reduce","promise","then","finally","bodyRef","styleCompatibilityRef","map","href","rel","media","textContent","TagName","toLowerCase","display"],"mappings":";;;;;;;;;AAQA;;;;AALA;;AAYA;;AACA;;AACA;;AAKA;;AACA;;AAvBA;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;AAIA,MAAMA,eAAe,GAAG,uBAAxB;AACA,MAAMC,YAAY,GAAG,UAArB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,sBAAT,GAAkC;AACjC,SAAO,2BAAgBC,IAAF,IAAY;AAChC;AACAC,IAAAA,KAAK,CAACC,IAAN,CAAYC,QAAQ,CAACC,WAArB,EAAmCC,OAAnC,CAA8CC,UAAF,IAAkB;AAC7D,UAAI;AACH;AACA;AACAA,QAAAA,UAAU,CAACC,QAAX;AACA,OAJD,CAIE,OAAQC,CAAR,EAAY;AACb;AACA;;AAED,YAAM;AAAEC,QAAAA,SAAF;AAAaF,QAAAA;AAAb,UAA0BD,UAAhC;;AAEA,UAAK,CAAEC,QAAP,EAAkB;AACjB;AACA,OAb4D,CAe7D;AACA;;;AACA,UAAKE,SAAS,C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,MAAP,CAAd,CAFP;AAGC,IAAA,QAAQ,EAAGd,QAHZ,CAIC;AAJD;AAKC,IAAA,MAAM,EAAC,iBALR;AAMC,IAAA,KAAK,EAAG,cAAI,eAAJ;AANT,MAQGI,cAAc,IACf,2BACC,qDACC;AAAM,IAAA,GAAG,EAAGqB;AAAZ,KAAwBrC,IAAxB,CADD,EAEC;AACC,IAAA,GAAG,EAAG2C,OADP;AAEC,IAAA,SAAS,EAAG,yBACX3G,eADW,EAEX,GAAGkF,WAFQ;AAFb,KAYC;AACC,IAAA,KAAK,EAAG;AAAEkC,MAAAA,OAAO,EAAE;AAAX,KADT;AAEC,IAAA,GAAG,EAAGR;AAFP,IAZD,EAgBC,4BAAC,uCAAD;AAAe,IAAA,QAAQ,EAAG5B;AAA1B,KACGlB,QADH,CAhBD,CAFD,CADD,EAwBCkB,cAAc,CAACc,eAxBhB,CATF,CAFD,EAsCGlB,QAAQ,IAAI,CAAZ,IAAiBa,KAtCpB,CADD;AA0CA;;eAEc,yBAAYhB,MAAZ,C","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} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { useBlockSelectionClearer } from '../block-selection-clearer';\nimport { useWritingFlow } from '../writing-flow';\n\nconst BODY_CLASS_NAME = 'editor-styles-wrapper';\nconst BLOCK_PREFIX = 'wp-block';\n\n/**\n * Clones stylesheets targetting the editor canvas to the given document. A\n * stylesheet is considered targetting the editor a canvas if it contains the\n * `editor-styles-wrapper`, `wp-block`, or `wp-block-*` class selectors.\n *\n * Ideally, this hook should be removed in the future and styles should be added\n * explicitly as editor styles.\n */\nfunction useStylesCompatibility() {\n\treturn useRefEffect( ( node ) => {\n\t\t// Search the document for stylesheets targetting the editor canvas.\n\t\tArray.from( document.styleSheets ).forEach( ( styleSheet ) => {\n\t\t\ttry {\n\t\t\t\t// May fail for external styles.\n\t\t\t\t// eslint-disable-next-line no-unused-expressions\n\t\t\t\tstyleSheet.cssRules;\n\t\t\t} catch ( e ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { ownerNode, cssRules } = styleSheet;\n\n\t\t\tif ( ! cssRules ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Generally, ignore inline styles. We add inline styles belonging to a\n\t\t\t// stylesheet later, which may or may not match the selectors.\n\t\t\tif ( ownerNode.tagName !== 'LINK' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Don't try to add the reset styles, which were removed as a dependency\n\t\t\t// from `edit-blocks` for the iframe since we don't need to reset admin\n\t\t\t// styles.\n\t\t\tif ( ownerNode.id === 'wp-reset-editor-styles-css' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isMatch = Array.from( cssRules ).find(\n\t\t\t\t( { selectorText } ) =>\n\t\t\t\t\tselectorText &&\n\t\t\t\t\t( selectorText.includes( `.${ BODY_CLASS_NAME }` ) ||\n\t\t\t\t\t\tselectorText.includes( `.${ BLOCK_PREFIX }` ) )\n\t\t\t);\n\n\t\t\tif (\n\t\t\t\tisMatch &&\n\t\t\t\t! node.ownerDocument.getElementById( ownerNode.id )\n\t\t\t) {\n\t\t\t\t// Display warning once we have a way to add style dependencies to the editor.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/pull/37466.\n\t\t\t\tnode.appendChild( ownerNode.cloneNode( true ) );\n\n\t\t\t\t// Add inline styles belonging to the stylesheet.\n\t\t\t\tconst inlineCssId = ownerNode.id.replace(\n\t\t\t\t\t'-css',\n\t\t\t\t\t'-inline-css'\n\t\t\t\t);\n\t\t\t\tconst inlineCssElement = document.getElementById( inlineCssId );\n\n\t\t\t\tif ( inlineCssElement ) {\n\t\t\t\t\tnode.appendChild( inlineCssElement.cloneNode( true ) );\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t}, [] );\n}\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' ];\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\t{ contentRef, children, head, tabIndex = 0, assets, ...props },\n\tref\n) {\n\tconst [ , forceRender ] = useReducer( () => ( {} ) );\n\tconst [ iframeDocument, setIframeDocument ] = useState();\n\tconst [ bodyClasses, setBodyClasses ] = useState( [] );\n\tconst styles = useParsedAssets( assets?.styles );\n\tconst scripts = useParsedAssets( assets?.scripts );\n\tconst clearerRef = useBlockSelectionClearer();\n\tconst [ before, writingFlowRef, after ] = useWritingFlow();\n\tconst setRef = useRefEffect( ( node ) => {\n\t\tfunction setDocumentIfReady() {\n\t\t\tconst { contentDocument, ownerDocument } = node;\n\t\t\tconst { readyState, documentElement } = contentDocument;\n\n\t\t\tif ( readyState !== 'interactive' && readyState !== 'complete' ) {\n\t\t\t\treturn false;\n\t\t\t}\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.head );\n\t\t\tdocumentElement.removeChild( contentDocument.body );\n\n\t\t\treturn true;\n\t\t}\n\n\t\t// Document set with srcDoc is not immediately ready.\n\t\tnode.addEventListener( 'load', setDocumentIfReady );\n\n\t\treturn () => node.removeEventListener( 'load', setDocumentIfReady );\n\t}, [] );\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 bodyRef = useMergeRefs( [ contentRef, clearerRef, writingFlowRef ] );\n\tconst styleCompatibilityRef = useStylesCompatibility();\n\n\thead = (\n\t\t<>\n\t\t\t<style>{ 'body{margin:0}' }</style>\n\t\t\t{ styles.map(\n\t\t\t\t( { tagName, href, id, rel, media, textContent } ) => {\n\t\t\t\t\tconst TagName = tagName.toLowerCase();\n\n\t\t\t\t\tif ( TagName === 'style' ) {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<TagName { ...{ id } } key={ id }>\n\t\t\t\t\t\t\t\t{ textContent }\n\t\t\t\t\t\t\t</TagName>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<TagName { ...{ href, id, rel, media } } key={ id } />\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t) }\n\t\t\t{ head }\n\t\t</>\n\t);\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\tref={ useMergeRefs( [ ref, setRef ] ) }\n\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\t// Correct doctype is required to enable rendering in standards mode\n\t\t\t\tsrcDoc=\"<!doctype html>\"\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<>\n\t\t\t\t\t\t\t<head ref={ headRef }>{ head }</head>\n\t\t\t\t\t\t\t<body\n\t\t\t\t\t\t\t\tref={ bodyRef }\n\t\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t\tBODY_CLASS_NAME,\n\t\t\t\t\t\t\t\t\t...bodyClasses\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ /*\n\t\t\t\t\t\t\t\t * This is a wrapper for the extra styles and scripts\n\t\t\t\t\t\t\t\t * rendered imperatively by cloning the parent,\n\t\t\t\t\t\t\t\t * it's important that this div's content remains uncontrolled.\n\t\t\t\t\t\t\t\t */ }\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tstyle={ { display: 'none' } }\n\t\t\t\t\t\t\t\t\tref={ styleCompatibilityRef }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<StyleProvider document={ iframeDocument }>\n\t\t\t\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t\t\t</StyleProvider>\n\t\t\t\t\t\t\t</body>\n\t\t\t\t\t\t</>,\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\nexport default forwardRef( Iframe );\n"]}
|
|
@@ -9,7 +9,7 @@ import classnames from 'classnames';
|
|
|
9
9
|
* WordPress dependencies
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { useState, createPortal, forwardRef,
|
|
12
|
+
import { useState, createPortal, forwardRef, useMemo, useReducer } from '@wordpress/element';
|
|
13
13
|
import { __ } from '@wordpress/i18n';
|
|
14
14
|
import { useMergeRefs, useRefEffect } from '@wordpress/compose';
|
|
15
15
|
import { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';
|
|
@@ -28,63 +28,63 @@ const BLOCK_PREFIX = 'wp-block';
|
|
|
28
28
|
*
|
|
29
29
|
* Ideally, this hook should be removed in the future and styles should be added
|
|
30
30
|
* explicitly as editor styles.
|
|
31
|
-
*
|
|
32
|
-
* @param {Document} doc The document to append cloned stylesheets to.
|
|
33
31
|
*/
|
|
34
32
|
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
function useStylesCompatibility() {
|
|
34
|
+
return useRefEffect(node => {
|
|
35
|
+
// Search the document for stylesheets targetting the editor canvas.
|
|
36
|
+
Array.from(document.styleSheets).forEach(styleSheet => {
|
|
37
|
+
try {
|
|
38
|
+
// May fail for external styles.
|
|
39
|
+
// eslint-disable-next-line no-unused-expressions
|
|
40
|
+
styleSheet.cssRules;
|
|
41
|
+
} catch (e) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
const {
|
|
46
|
+
ownerNode,
|
|
47
|
+
cssRules
|
|
48
|
+
} = styleSheet;
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
if (!cssRules) {
|
|
51
|
+
return;
|
|
52
|
+
} // Generally, ignore inline styles. We add inline styles belonging to a
|
|
53
|
+
// stylesheet later, which may or may not match the selectors.
|
|
55
54
|
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
if (ownerNode.tagName !== 'LINK') {
|
|
57
|
+
return;
|
|
58
|
+
} // Don't try to add the reset styles, which were removed as a dependency
|
|
59
|
+
// from `edit-blocks` for the iframe since we don't need to reset admin
|
|
60
|
+
// styles.
|
|
62
61
|
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
if (ownerNode.id === 'wp-reset-editor-styles-css') {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
const isMatch = Array.from(cssRules).find(_ref => {
|
|
68
|
+
let {
|
|
69
|
+
selectorText
|
|
70
|
+
} = _ref;
|
|
71
|
+
return selectorText && (selectorText.includes(`.${BODY_CLASS_NAME}`) || selectorText.includes(`.${BLOCK_PREFIX}`));
|
|
72
|
+
});
|
|
74
73
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
if (isMatch && !node.ownerDocument.getElementById(ownerNode.id)) {
|
|
75
|
+
// Display warning once we have a way to add style dependencies to the editor.
|
|
76
|
+
// See: https://github.com/WordPress/gutenberg/pull/37466.
|
|
77
|
+
node.appendChild(ownerNode.cloneNode(true)); // Add inline styles belonging to the stylesheet.
|
|
79
78
|
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
const inlineCssId = ownerNode.id.replace('-css', '-inline-css');
|
|
80
|
+
const inlineCssElement = document.getElementById(inlineCssId);
|
|
82
81
|
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
if (inlineCssElement) {
|
|
83
|
+
node.appendChild(inlineCssElement.cloneNode(true));
|
|
84
|
+
}
|
|
85
85
|
}
|
|
86
|
-
}
|
|
87
|
-
});
|
|
86
|
+
});
|
|
87
|
+
}, []);
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* Bubbles some event types (keydown, keypress, and dragover) to parent document
|
|
@@ -224,11 +224,7 @@ function Iframe(_ref3, ref) {
|
|
|
224
224
|
});
|
|
225
225
|
}, []);
|
|
226
226
|
const bodyRef = useMergeRefs([contentRef, clearerRef, writingFlowRef]);
|
|
227
|
-
|
|
228
|
-
if (iframeDocument) {
|
|
229
|
-
styleSheetsCompat(iframeDocument);
|
|
230
|
-
}
|
|
231
|
-
}, [iframeDocument]);
|
|
227
|
+
const styleCompatibilityRef = useStylesCompatibility();
|
|
232
228
|
head = createElement(Fragment, null, createElement("style", null, 'body{margin:0}'), styles.map(_ref4 => {
|
|
233
229
|
let {
|
|
234
230
|
tagName,
|
|
@@ -266,7 +262,12 @@ function Iframe(_ref3, ref) {
|
|
|
266
262
|
}, head), createElement("body", {
|
|
267
263
|
ref: bodyRef,
|
|
268
264
|
className: classnames(BODY_CLASS_NAME, ...bodyClasses)
|
|
269
|
-
}, createElement(
|
|
265
|
+
}, createElement("div", {
|
|
266
|
+
style: {
|
|
267
|
+
display: 'none'
|
|
268
|
+
},
|
|
269
|
+
ref: styleCompatibilityRef
|
|
270
|
+
}), createElement(StyleProvider, {
|
|
270
271
|
document: iframeDocument
|
|
271
272
|
}, children))), iframeDocument.documentElement)), tabIndex >= 0 && after);
|
|
272
273
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/block-editor/src/components/iframe/index.js"],"names":["classnames","useState","createPortal","forwardRef","useEffect","useMemo","useReducer","__","useMergeRefs","useRefEffect","__experimentalStyleProvider","StyleProvider","useBlockSelectionClearer","useWritingFlow","BODY_CLASS_NAME","BLOCK_PREFIX","styleSheetsCompat","doc","Array","from","document","styleSheets","forEach","styleSheet","cssRules","e","ownerNode","tagName","id","isMatch","find","selectorText","includes","getElementById","head","appendChild","cloneNode","inlineCssId","replace","inlineCssElement","bubbleEvents","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","implementation","createHTMLDocument","body","innerHTML","children","loadScript","src","Promise","resolve","reject","script","ownerDocument","createElement","onload","onerror","Iframe","ref","contentRef","tabIndex","assets","props","forceRender","iframeDocument","setIframeDocument","bodyClasses","setBodyClasses","styles","scripts","clearerRef","before","writingFlowRef","after","setRef","node","setDocumentIfReady","contentDocument","readyState","documentElement","classList","filter","startsWith","dir","removeChild","removeEventListener","headRef","element","reduce","promise","then","finally","bodyRef","map","href","rel","media","textContent","TagName","toLowerCase"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA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,IAAA,GAAG,EAAGuF,OADP;AAEC,IAAA,SAAS,EAAGzH,UAAU,CACrBc,eADqB,EAErB,GAAGiF,WAFkB;AAFvB,KAOC,cAAC,aAAD;AAAe,IAAA,QAAQ,EAAGF;AAA1B,KACGlB,QADH,CAPD,CAFD,CADW,EAeXkB,cAAc,CAACe,eAfJ,CATd,CAFD,EA6BGnB,QAAQ,IAAI,CAAZ,IAAiBa,KA7BpB,CADD;AAiCA;;AAED,eAAenG,UAAU,CAAEmF,MAAF,CAAzB","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseState,\n\tcreatePortal,\n\tforwardRef,\n\tuseEffect,\n\tuseMemo,\n\tuseReducer,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { useBlockSelectionClearer } from '../block-selection-clearer';\nimport { useWritingFlow } from '../writing-flow';\n\nconst BODY_CLASS_NAME = 'editor-styles-wrapper';\nconst BLOCK_PREFIX = 'wp-block';\n\n/**\n * Clones stylesheets targetting the editor canvas to the given document. A\n * stylesheet is considered targetting the editor a canvas if it contains the\n * `editor-styles-wrapper`, `wp-block`, or `wp-block-*` class selectors.\n *\n * Ideally, this hook should be removed in the future and styles should be added\n * explicitly as editor styles.\n *\n * @param {Document} doc The document to append cloned stylesheets to.\n */\nfunction styleSheetsCompat( doc ) {\n\t// Search the document for stylesheets targetting the editor canvas.\n\tArray.from( document.styleSheets ).forEach( ( styleSheet ) => {\n\t\ttry {\n\t\t\t// May fail for external styles.\n\t\t\t// eslint-disable-next-line no-unused-expressions\n\t\t\tstyleSheet.cssRules;\n\t\t} catch ( e ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { ownerNode, cssRules } = styleSheet;\n\n\t\tif ( ! cssRules ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Generally, ignore inline styles. We add inline styles belonging to a\n\t\t// stylesheet later, which may or may not match the selectors.\n\t\tif ( ownerNode.tagName !== 'LINK' ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Don't try to add the reset styles, which were removed as a dependency\n\t\t// from `edit-blocks` for the iframe since we don't need to reset admin\n\t\t// styles.\n\t\tif ( ownerNode.id === 'wp-reset-editor-styles-css' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst isMatch = Array.from( cssRules ).find(\n\t\t\t( { selectorText } ) =>\n\t\t\t\tselectorText &&\n\t\t\t\t( selectorText.includes( `.${ BODY_CLASS_NAME }` ) ||\n\t\t\t\t\tselectorText.includes( `.${ BLOCK_PREFIX }` ) )\n\t\t);\n\n\t\tif ( isMatch && ! doc.getElementById( ownerNode.id ) ) {\n\t\t\t// Display warning once we have a way to add style dependencies to the editor.\n\t\t\t// See: https://github.com/WordPress/gutenberg/pull/37466.\n\n\t\t\tdoc.head.appendChild( ownerNode.cloneNode( true ) );\n\n\t\t\t// Add inline styles belonging to the stylesheet.\n\t\t\tconst inlineCssId = ownerNode.id.replace( '-css', '-inline-css' );\n\t\t\tconst inlineCssElement = document.getElementById( inlineCssId );\n\n\t\t\tif ( inlineCssElement ) {\n\t\t\t\tdoc.head.appendChild( inlineCssElement.cloneNode( true ) );\n\t\t\t}\n\t\t}\n\t} );\n}\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' ];\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\t{ contentRef, children, head, tabIndex = 0, assets, ...props },\n\tref\n) {\n\tconst [ , forceRender ] = useReducer( () => ( {} ) );\n\tconst [ iframeDocument, setIframeDocument ] = useState();\n\tconst [ bodyClasses, setBodyClasses ] = useState( [] );\n\tconst styles = useParsedAssets( assets?.styles );\n\tconst scripts = useParsedAssets( assets?.scripts );\n\tconst clearerRef = useBlockSelectionClearer();\n\tconst [ before, writingFlowRef, after ] = useWritingFlow();\n\tconst setRef = useRefEffect( ( node ) => {\n\t\tfunction setDocumentIfReady() {\n\t\t\tconst { contentDocument, ownerDocument } = node;\n\t\t\tconst { readyState, documentElement } = contentDocument;\n\n\t\t\tif ( readyState !== 'interactive' && readyState !== 'complete' ) {\n\t\t\t\treturn false;\n\t\t\t}\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.head );\n\t\t\tdocumentElement.removeChild( contentDocument.body );\n\n\t\t\treturn true;\n\t\t}\n\n\t\t// Document set with srcDoc is not immediately ready.\n\t\tnode.addEventListener( 'load', setDocumentIfReady );\n\n\t\treturn () => node.removeEventListener( 'load', setDocumentIfReady );\n\t}, [] );\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 bodyRef = useMergeRefs( [ contentRef, clearerRef, writingFlowRef ] );\n\n\tuseEffect( () => {\n\t\tif ( iframeDocument ) {\n\t\t\tstyleSheetsCompat( iframeDocument );\n\t\t}\n\t}, [ iframeDocument ] );\n\n\thead = (\n\t\t<>\n\t\t\t<style>{ 'body{margin:0}' }</style>\n\t\t\t{ styles.map(\n\t\t\t\t( { tagName, href, id, rel, media, textContent } ) => {\n\t\t\t\t\tconst TagName = tagName.toLowerCase();\n\n\t\t\t\t\tif ( TagName === 'style' ) {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<TagName { ...{ id } } key={ id }>\n\t\t\t\t\t\t\t\t{ textContent }\n\t\t\t\t\t\t\t</TagName>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<TagName { ...{ href, id, rel, media } } key={ id } />\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t) }\n\t\t\t{ head }\n\t\t</>\n\t);\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\tref={ useMergeRefs( [ ref, setRef ] ) }\n\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\t// Correct doctype is required to enable rendering in standards mode\n\t\t\t\tsrcDoc=\"<!doctype html>\"\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<>\n\t\t\t\t\t\t\t<head ref={ headRef }>{ head }</head>\n\t\t\t\t\t\t\t<body\n\t\t\t\t\t\t\t\tref={ bodyRef }\n\t\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t\tBODY_CLASS_NAME,\n\t\t\t\t\t\t\t\t\t...bodyClasses\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<StyleProvider document={ iframeDocument }>\n\t\t\t\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t\t\t</StyleProvider>\n\t\t\t\t\t\t\t</body>\n\t\t\t\t\t\t</>,\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\nexport default forwardRef( Iframe );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/block-editor/src/components/iframe/index.js"],"names":["classnames","useState","createPortal","forwardRef","useMemo","useReducer","__","useMergeRefs","useRefEffect","__experimentalStyleProvider","StyleProvider","useBlockSelectionClearer","useWritingFlow","BODY_CLASS_NAME","BLOCK_PREFIX","useStylesCompatibility","node","Array","from","document","styleSheets","forEach","styleSheet","cssRules","e","ownerNode","tagName","id","isMatch","find","selectorText","includes","ownerDocument","getElementById","appendChild","cloneNode","inlineCssId","replace","inlineCssElement","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","implementation","createHTMLDocument","body","innerHTML","children","loadScript","head","src","Promise","resolve","reject","script","createElement","onload","onerror","Iframe","ref","contentRef","tabIndex","assets","props","forceRender","iframeDocument","setIframeDocument","bodyClasses","setBodyClasses","styles","scripts","clearerRef","before","writingFlowRef","after","setRef","setDocumentIfReady","contentDocument","readyState","documentElement","classList","filter","startsWith","dir","removeChild","removeEventListener","headRef","element","reduce","promise","then","finally","bodyRef","styleCompatibilityRef","map","href","rel","media","textContent","TagName","toLowerCase","display"],"mappings":";;;AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,YAAvB;AAEA;AACA;AACA;;AACA,SACCC,QADD,EAECC,YAFD,EAGCC,UAHD,EAICC,OAJD,EAKCC,UALD,QAMO,oBANP;AAOA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASC,YAAT,EAAuBC,YAAvB,QAA2C,oBAA3C;AACA,SAASC,2BAA2B,IAAIC,aAAxC,QAA6D,uBAA7D;AAEA;AACA;AACA;;AACA,SAASC,wBAAT,QAAyC,4BAAzC;AACA,SAASC,cAAT,QAA+B,iBAA/B;AAEA,MAAMC,eAAe,GAAG,uBAAxB;AACA,MAAMC,YAAY,GAAG,UAArB;AAEA;AACA;AACA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ependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseState,\n\tcreatePortal,\n\tforwardRef,\n\tuseMemo,\n\tuseReducer,\n} from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { useMergeRefs, useRefEffect } from '@wordpress/compose';\nimport { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport { useBlockSelectionClearer } from '../block-selection-clearer';\nimport { useWritingFlow } from '../writing-flow';\n\nconst BODY_CLASS_NAME = 'editor-styles-wrapper';\nconst BLOCK_PREFIX = 'wp-block';\n\n/**\n * Clones stylesheets targetting the editor canvas to the given document. A\n * stylesheet is considered targetting the editor a canvas if it contains the\n * `editor-styles-wrapper`, `wp-block`, or `wp-block-*` class selectors.\n *\n * Ideally, this hook should be removed in the future and styles should be added\n * explicitly as editor styles.\n */\nfunction useStylesCompatibility() {\n\treturn useRefEffect( ( node ) => {\n\t\t// Search the document for stylesheets targetting the editor canvas.\n\t\tArray.from( document.styleSheets ).forEach( ( styleSheet ) => {\n\t\t\ttry {\n\t\t\t\t// May fail for external styles.\n\t\t\t\t// eslint-disable-next-line no-unused-expressions\n\t\t\t\tstyleSheet.cssRules;\n\t\t\t} catch ( e ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst { ownerNode, cssRules } = styleSheet;\n\n\t\t\tif ( ! cssRules ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Generally, ignore inline styles. We add inline styles belonging to a\n\t\t\t// stylesheet later, which may or may not match the selectors.\n\t\t\tif ( ownerNode.tagName !== 'LINK' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Don't try to add the reset styles, which were removed as a dependency\n\t\t\t// from `edit-blocks` for the iframe since we don't need to reset admin\n\t\t\t// styles.\n\t\t\tif ( ownerNode.id === 'wp-reset-editor-styles-css' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst isMatch = Array.from( cssRules ).find(\n\t\t\t\t( { selectorText } ) =>\n\t\t\t\t\tselectorText &&\n\t\t\t\t\t( selectorText.includes( `.${ BODY_CLASS_NAME }` ) ||\n\t\t\t\t\t\tselectorText.includes( `.${ BLOCK_PREFIX }` ) )\n\t\t\t);\n\n\t\t\tif (\n\t\t\t\tisMatch &&\n\t\t\t\t! node.ownerDocument.getElementById( ownerNode.id )\n\t\t\t) {\n\t\t\t\t// Display warning once we have a way to add style dependencies to the editor.\n\t\t\t\t// See: https://github.com/WordPress/gutenberg/pull/37466.\n\t\t\t\tnode.appendChild( ownerNode.cloneNode( true ) );\n\n\t\t\t\t// Add inline styles belonging to the stylesheet.\n\t\t\t\tconst inlineCssId = ownerNode.id.replace(\n\t\t\t\t\t'-css',\n\t\t\t\t\t'-inline-css'\n\t\t\t\t);\n\t\t\t\tconst inlineCssElement = document.getElementById( inlineCssId );\n\n\t\t\t\tif ( inlineCssElement ) {\n\t\t\t\t\tnode.appendChild( inlineCssElement.cloneNode( true ) );\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t}, [] );\n}\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' ];\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\t{ contentRef, children, head, tabIndex = 0, assets, ...props },\n\tref\n) {\n\tconst [ , forceRender ] = useReducer( () => ( {} ) );\n\tconst [ iframeDocument, setIframeDocument ] = useState();\n\tconst [ bodyClasses, setBodyClasses ] = useState( [] );\n\tconst styles = useParsedAssets( assets?.styles );\n\tconst scripts = useParsedAssets( assets?.scripts );\n\tconst clearerRef = useBlockSelectionClearer();\n\tconst [ before, writingFlowRef, after ] = useWritingFlow();\n\tconst setRef = useRefEffect( ( node ) => {\n\t\tfunction setDocumentIfReady() {\n\t\t\tconst { contentDocument, ownerDocument } = node;\n\t\t\tconst { readyState, documentElement } = contentDocument;\n\n\t\t\tif ( readyState !== 'interactive' && readyState !== 'complete' ) {\n\t\t\t\treturn false;\n\t\t\t}\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.head );\n\t\t\tdocumentElement.removeChild( contentDocument.body );\n\n\t\t\treturn true;\n\t\t}\n\n\t\t// Document set with srcDoc is not immediately ready.\n\t\tnode.addEventListener( 'load', setDocumentIfReady );\n\n\t\treturn () => node.removeEventListener( 'load', setDocumentIfReady );\n\t}, [] );\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 bodyRef = useMergeRefs( [ contentRef, clearerRef, writingFlowRef ] );\n\tconst styleCompatibilityRef = useStylesCompatibility();\n\n\thead = (\n\t\t<>\n\t\t\t<style>{ 'body{margin:0}' }</style>\n\t\t\t{ styles.map(\n\t\t\t\t( { tagName, href, id, rel, media, textContent } ) => {\n\t\t\t\t\tconst TagName = tagName.toLowerCase();\n\n\t\t\t\t\tif ( TagName === 'style' ) {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<TagName { ...{ id } } key={ id }>\n\t\t\t\t\t\t\t\t{ textContent }\n\t\t\t\t\t\t\t</TagName>\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<TagName { ...{ href, id, rel, media } } key={ id } />\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t) }\n\t\t\t{ head }\n\t\t</>\n\t);\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\tref={ useMergeRefs( [ ref, setRef ] ) }\n\t\t\t\ttabIndex={ tabIndex }\n\t\t\t\t// Correct doctype is required to enable rendering in standards mode\n\t\t\t\tsrcDoc=\"<!doctype html>\"\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<>\n\t\t\t\t\t\t\t<head ref={ headRef }>{ head }</head>\n\t\t\t\t\t\t\t<body\n\t\t\t\t\t\t\t\tref={ bodyRef }\n\t\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t\tBODY_CLASS_NAME,\n\t\t\t\t\t\t\t\t\t...bodyClasses\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ /*\n\t\t\t\t\t\t\t\t * This is a wrapper for the extra styles and scripts\n\t\t\t\t\t\t\t\t * rendered imperatively by cloning the parent,\n\t\t\t\t\t\t\t\t * it's important that this div's content remains uncontrolled.\n\t\t\t\t\t\t\t\t */ }\n\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\tstyle={ { display: 'none' } }\n\t\t\t\t\t\t\t\t\tref={ styleCompatibilityRef }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<StyleProvider document={ iframeDocument }>\n\t\t\t\t\t\t\t\t\t{ children }\n\t\t\t\t\t\t\t\t</StyleProvider>\n\t\t\t\t\t\t\t</body>\n\t\t\t\t\t\t</>,\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\nexport default forwardRef( Iframe );\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/block-editor",
|
|
3
|
-
"version": "8.5.
|
|
3
|
+
"version": "8.5.6",
|
|
4
4
|
"description": "Generic block editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"publishConfig": {
|
|
78
78
|
"access": "public"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "89fbea298119228eea3ebdc8d30e87033a497f43"
|
|
81
81
|
}
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
useState,
|
|
11
11
|
createPortal,
|
|
12
12
|
forwardRef,
|
|
13
|
-
useEffect,
|
|
14
13
|
useMemo,
|
|
15
14
|
useReducer,
|
|
16
15
|
} from '@wordpress/element';
|
|
@@ -34,61 +33,66 @@ const BLOCK_PREFIX = 'wp-block';
|
|
|
34
33
|
*
|
|
35
34
|
* Ideally, this hook should be removed in the future and styles should be added
|
|
36
35
|
* explicitly as editor styles.
|
|
37
|
-
*
|
|
38
|
-
* @param {Document} doc The document to append cloned stylesheets to.
|
|
39
36
|
*/
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const { ownerNode, cssRules } = styleSheet;
|
|
52
|
-
|
|
53
|
-
if ( ! cssRules ) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
37
|
+
function useStylesCompatibility() {
|
|
38
|
+
return useRefEffect( ( node ) => {
|
|
39
|
+
// Search the document for stylesheets targetting the editor canvas.
|
|
40
|
+
Array.from( document.styleSheets ).forEach( ( styleSheet ) => {
|
|
41
|
+
try {
|
|
42
|
+
// May fail for external styles.
|
|
43
|
+
// eslint-disable-next-line no-unused-expressions
|
|
44
|
+
styleSheet.cssRules;
|
|
45
|
+
} catch ( e ) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
56
48
|
|
|
57
|
-
|
|
58
|
-
// stylesheet later, which may or may not match the selectors.
|
|
59
|
-
if ( ownerNode.tagName !== 'LINK' ) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
49
|
+
const { ownerNode, cssRules } = styleSheet;
|
|
62
50
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if ( ownerNode.id === 'wp-reset-editor-styles-css' ) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const isMatch = Array.from( cssRules ).find(
|
|
71
|
-
( { selectorText } ) =>
|
|
72
|
-
selectorText &&
|
|
73
|
-
( selectorText.includes( `.${ BODY_CLASS_NAME }` ) ||
|
|
74
|
-
selectorText.includes( `.${ BLOCK_PREFIX }` ) )
|
|
75
|
-
);
|
|
51
|
+
if ( ! cssRules ) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
76
54
|
|
|
77
|
-
|
|
78
|
-
//
|
|
79
|
-
|
|
55
|
+
// Generally, ignore inline styles. We add inline styles belonging to a
|
|
56
|
+
// stylesheet later, which may or may not match the selectors.
|
|
57
|
+
if ( ownerNode.tagName !== 'LINK' ) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
80
60
|
|
|
81
|
-
|
|
61
|
+
// Don't try to add the reset styles, which were removed as a dependency
|
|
62
|
+
// from `edit-blocks` for the iframe since we don't need to reset admin
|
|
63
|
+
// styles.
|
|
64
|
+
if ( ownerNode.id === 'wp-reset-editor-styles-css' ) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
82
67
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
68
|
+
const isMatch = Array.from( cssRules ).find(
|
|
69
|
+
( { selectorText } ) =>
|
|
70
|
+
selectorText &&
|
|
71
|
+
( selectorText.includes( `.${ BODY_CLASS_NAME }` ) ||
|
|
72
|
+
selectorText.includes( `.${ BLOCK_PREFIX }` ) )
|
|
73
|
+
);
|
|
86
74
|
|
|
87
|
-
if (
|
|
88
|
-
|
|
75
|
+
if (
|
|
76
|
+
isMatch &&
|
|
77
|
+
! node.ownerDocument.getElementById( ownerNode.id )
|
|
78
|
+
) {
|
|
79
|
+
// Display warning once we have a way to add style dependencies to the editor.
|
|
80
|
+
// See: https://github.com/WordPress/gutenberg/pull/37466.
|
|
81
|
+
node.appendChild( ownerNode.cloneNode( true ) );
|
|
82
|
+
|
|
83
|
+
// Add inline styles belonging to the stylesheet.
|
|
84
|
+
const inlineCssId = ownerNode.id.replace(
|
|
85
|
+
'-css',
|
|
86
|
+
'-inline-css'
|
|
87
|
+
);
|
|
88
|
+
const inlineCssElement = document.getElementById( inlineCssId );
|
|
89
|
+
|
|
90
|
+
if ( inlineCssElement ) {
|
|
91
|
+
node.appendChild( inlineCssElement.cloneNode( true ) );
|
|
92
|
+
}
|
|
89
93
|
}
|
|
90
|
-
}
|
|
91
|
-
} );
|
|
94
|
+
} );
|
|
95
|
+
}, [] );
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
/**
|
|
@@ -222,12 +226,7 @@ function Iframe(
|
|
|
222
226
|
} );
|
|
223
227
|
}, [] );
|
|
224
228
|
const bodyRef = useMergeRefs( [ contentRef, clearerRef, writingFlowRef ] );
|
|
225
|
-
|
|
226
|
-
useEffect( () => {
|
|
227
|
-
if ( iframeDocument ) {
|
|
228
|
-
styleSheetsCompat( iframeDocument );
|
|
229
|
-
}
|
|
230
|
-
}, [ iframeDocument ] );
|
|
229
|
+
const styleCompatibilityRef = useStylesCompatibility();
|
|
231
230
|
|
|
232
231
|
head = (
|
|
233
232
|
<>
|
|
@@ -275,6 +274,15 @@ function Iframe(
|
|
|
275
274
|
...bodyClasses
|
|
276
275
|
) }
|
|
277
276
|
>
|
|
277
|
+
{ /*
|
|
278
|
+
* This is a wrapper for the extra styles and scripts
|
|
279
|
+
* rendered imperatively by cloning the parent,
|
|
280
|
+
* it's important that this div's content remains uncontrolled.
|
|
281
|
+
*/ }
|
|
282
|
+
<div
|
|
283
|
+
style={ { display: 'none' } }
|
|
284
|
+
ref={ styleCompatibilityRef }
|
|
285
|
+
/>
|
|
278
286
|
<StyleProvider document={ iframeDocument }>
|
|
279
287
|
{ children }
|
|
280
288
|
</StyleProvider>
|