@wordpress/block-editor 12.3.5 → 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.
@@ -88,36 +88,6 @@ function bubbleEvents(doc) {
88
88
  }
89
89
  }
90
90
 
91
- function useParsedAssets(html) {
92
- return (0, _element.useMemo)(() => {
93
- const doc = document.implementation.createHTMLDocument('');
94
- doc.body.innerHTML = html;
95
- return Array.from(doc.body.children);
96
- }, [html]);
97
- }
98
-
99
- async function loadScript(head, {
100
- id,
101
- src
102
- }) {
103
- return new Promise((resolve, reject) => {
104
- const script = head.ownerDocument.createElement('script');
105
- script.id = id;
106
-
107
- if (src) {
108
- script.src = src;
109
-
110
- script.onload = () => resolve();
111
-
112
- script.onerror = () => reject();
113
- } else {
114
- resolve();
115
- }
116
-
117
- head.appendChild(script);
118
- });
119
- }
120
-
121
91
  function Iframe({
122
92
  contentRef,
123
93
  children,
@@ -129,20 +99,23 @@ function Iframe({
129
99
  forwardedRef: ref,
130
100
  ...props
131
101
  }) {
132
- var _assets$styles;
133
-
134
- const assets = (0, _data.useSelect)(select => select(_store.store).getSettings().__unstableResolvedAssets, []);
135
- const [, forceRender] = (0, _element.useReducer)(() => ({}));
102
+ const {
103
+ styles = '',
104
+ scripts = ''
105
+ } = (0, _data.useSelect)(select => select(_store.store).getSettings().__unstableResolvedAssets, []);
136
106
  const [iframeDocument, setIframeDocument] = (0, _element.useState)();
137
107
  const [bodyClasses, setBodyClasses] = (0, _element.useState)([]);
138
108
  const compatStyles = (0, _useCompatibilityStyles.useCompatibilityStyles)();
139
- const scripts = useParsedAssets(assets?.scripts);
140
109
  const clearerRef = (0, _blockSelectionClearer.useBlockSelectionClearer)();
141
110
  const [before, writingFlowRef, after] = (0, _writingFlow.useWritingFlow)();
142
111
  const [contentResizeListener, {
143
112
  height: contentHeight
144
113
  }] = (0, _compose.useResizeObserver)();
145
114
  const setRef = (0, _compose.useRefEffect)(node => {
115
+ node._load = () => {
116
+ setIframeDocument(node.contentDocument);
117
+ };
118
+
146
119
  let iFrameDocument; // Prevent the default browser action for files dropped outside of dropzones.
147
120
 
148
121
  function preventFileDropDefault(event) {
@@ -159,14 +132,12 @@ function Iframe({
159
132
  } = contentDocument;
160
133
  iFrameDocument = contentDocument;
161
134
  bubbleEvents(contentDocument);
162
- setIframeDocument(contentDocument);
163
135
  clearerRef(documentElement); // Ideally ALL classes that are added through get_body_class should
164
136
  // be added in the editor too, which we'll somehow have to get from
165
137
  // the server in the future (which will run the PHP filters).
166
138
 
167
139
  setBodyClasses(Array.from(ownerDocument.body.classList).filter(name => name.startsWith('admin-color-') || name.startsWith('post-type-') || name === 'wp-embed-responsive'));
168
140
  contentDocument.dir = ownerDocument.dir;
169
- documentElement.removeChild(contentDocument.body);
170
141
 
171
142
  for (const compatStyle of compatStyles) {
172
143
  if (contentDocument.getElementById(compatStyle.id)) {
@@ -189,21 +160,25 @@ function Iframe({
189
160
  iFrameDocument?.removeEventListener('drop', preventFileDropDefault);
190
161
  };
191
162
  }, []);
192
- const headRef = (0, _compose.useRefEffect)(element => {
193
- scripts.reduce((promise, script) => promise.then(() => loadScript(element, script)), Promise.resolve()).finally(() => {
194
- // When script are loaded, re-render blocks to allow them
195
- // to initialise.
196
- forceRender();
197
- });
198
- }, []);
199
163
  const disabledRef = (0, _compose.useDisabled)({
200
164
  isDisabled: !readonly
201
165
  });
202
- const bodyRef = (0, _compose.useMergeRefs)([contentRef, clearerRef, writingFlowRef, disabledRef, headRef]); // Correct doctype is required to enable rendering in standards
166
+ const bodyRef = (0, _compose.useMergeRefs)([contentRef, clearerRef, writingFlowRef, disabledRef]); // Correct doctype is required to enable rendering in standards
203
167
  // mode. Also preload the styles to avoid a flash of unstyled
204
168
  // content.
205
169
 
206
- const html = '<!doctype html>' + '<style>html{height:auto!important;min-height:100%;}body{margin:0}</style>' + ((_assets$styles = assets?.styles) !== null && _assets$styles !== void 0 ? _assets$styles : '');
170
+ const html = `<!doctype html>
171
+ <html>
172
+ <head>
173
+ <script>window.frameElement._load()</script>
174
+ <style>html{height:auto!important;min-height:100%;}body{margin:0}</style>
175
+ ${styles}
176
+ ${scripts}
177
+ </head>
178
+ <body>
179
+ <script>document.currentScript.parentElement.remove()</script>
180
+ </body>
181
+ </html>`;
207
182
  const [src, cleanup] = (0, _element.useMemo)(() => {
208
183
  const _src = URL.createObjectURL(new window.Blob([html], {
209
184
  type: 'text/html'
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/iframe/index.js"],"names":["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","blockEditorStore","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":";;;;;;;;;AAQA;;AALA;;AAaA;;AACA;;AAMA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AAhCA;AACA;AACA;;AAGA;AACA;AACA;;AAmBA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,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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":["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","blockEditorStore","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":";;;;;;;;;AAQA;;AALA;;AAYA;;AACA;;AAMA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AA/BA;AACA;AACA;;AAGA;AACA;AACA;;AAkBA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,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,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,CAnBP;AAoBC,IAAA,QAAQ,EAAG1B,QApBZ,CAqBC;AACA;AACA;AAvBD;AAwBC,IAAA,GAAG,EAAGuD,GAxBP;AAyBC,IAAA,KAAK,EAAG,cAAI,eAAJ;AAzBT,KA2BGzC,cAAc,IACf,2BACC;AACC,IAAA,GAAG,EAAGuC,OADP;AAEC,IAAA,SAAS,EAAG,yBACX,2BADW,EAEX,uBAFW,EAGX,GAAGrC,WAHQ;AAFb,KAQGO,qBARH,EASC,4BAAC,uCAAD;AAAe,IAAA,QAAQ,EAAGT;AAA1B,KACGf,QADH,CATD,CADD,EAcCe,cAAc,CAACoB,eAdhB,CA5BF,CAFD,EA+CGlC,QAAQ,IAAI,CAAZ,IAAiBsB,KA/CpB,CADD;AAmDA;;AAED,SAAS8C,aAAT,CAAwB7D,KAAxB,EAA+BD,GAA/B,EAAqC;AACpC,QAAM+D,aAAa,GAAG,qBACnB3D,MAAF,IACCA,MAAM,CAAEC,YAAF,CAAN,CAA2BC,WAA3B,GAAyC0D,uBAFrB,EAGrB,EAHqB,CAAtB,CADoC,CAOpC;AACA;AACA;AACA;AACA;;AACA,MAAK,CAAED,aAAP,EAAuB;AACtB,WAAO,IAAP;AACA;;AAED,SAAO,4BAAC,MAAD,OAAa9D,KAAb;AAAqB,IAAA,YAAY,EAAGD;AAApC,IAAP;AACA;;eAEc,yBAAY8D,aAAZ,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\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"]}
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.Content = void 0;
9
- exports.getRichTextValues = getRichTextValues;
10
9
 
11
10
  var _element = require("@wordpress/element");
12
11
 
@@ -61,39 +60,4 @@ const Content = ({
61
60
  };
62
61
 
63
62
  exports.Content = Content;
64
- Content.__unstableIsRichTextContent = {};
65
-
66
- function findContent(blocks, richTextValues = []) {
67
- if (!Array.isArray(blocks)) {
68
- blocks = [blocks];
69
- }
70
-
71
- for (const block of blocks) {
72
- if (block?.type?.__unstableIsRichTextContent === Content.__unstableIsRichTextContent) {
73
- richTextValues.push(block.props.value);
74
- continue;
75
- }
76
-
77
- if (block?.props?.children) {
78
- findContent(block.props.children, richTextValues);
79
- }
80
- }
81
-
82
- return richTextValues;
83
- }
84
-
85
- function _getSaveElement({
86
- name,
87
- attributes,
88
- innerBlocks
89
- }) {
90
- return (0, _blocks.getSaveElement)(name, attributes, innerBlocks.map(_getSaveElement));
91
- }
92
-
93
- function getRichTextValues(blocks = []) {
94
- _blocks.__unstableGetBlockProps.skipFilters = true;
95
- const values = findContent((Array.isArray(blocks) ? blocks : [blocks]).map(_getSaveElement));
96
- _blocks.__unstableGetBlockProps.skipFilters = false;
97
- return values;
98
- }
99
63
  //# sourceMappingURL=content.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/content.js"],"names":["Content","value","tagName","Tag","multiline","props","Array","isArray","since","version","alternative","link","childrenSource","toHTML","MultilineTag","content","format","restProps","__unstableIsRichTextContent","findContent","blocks","richTextValues","block","type","push","children","_getSaveElement","name","attributes","innerBlocks","map","getRichTextValues","getBlockProps","skipFilters","values"],"mappings":";;;;;;;;;;AAGA;;AACA;;AAKA;;AAKA;;AAdA;AACA;AACA;;AASA;AACA;AACA;AAGO,MAAMA,OAAO,GAAG,CAAE;AAAEC,EAAAA,KAAF;AAASC,EAAAA,OAAO,EAAEC,GAAlB;AAAuBC,EAAAA,SAAvB;AAAkC,KAAGC;AAArC,CAAF,KAAoD;AAC1E;AACA,MAAKC,KAAK,CAACC,OAAN,CAAeN,KAAf,CAAL,EAA8B;AAC7B,6BAAY,qDAAZ,EAAmE;AAClEO,MAAAA,KAAK,EAAE,KAD2D;AAElEC,MAAAA,OAAO,EAAE,KAFyD;AAGlEC,MAAAA,WAAW,EAAE,sBAHqD;AAIlEC,MAAAA,IAAI,EAAE;AAJ4D,KAAnE;AAOAV,IAAAA,KAAK,GAAGW,iBAAeC,MAAf,CAAuBZ,KAAvB,CAAR;AACA;;AAED,QAAMa,YAAY,GAAG,4BAAiBV,SAAjB,CAArB;;AAEA,MAAK,CAAEH,KAAF,IAAWa,YAAhB,EAA+B;AAC9Bb,IAAAA,KAAK,GAAI,IAAIa,YAAc,MAAMA,YAAc,GAA/C;AACA;;AAED,QAAMC,OAAO,GAAG,4BAAC,gBAAD,QAAWd,KAAX,CAAhB;;AAEA,MAAKE,GAAL,EAAW;AACV,UAAM;AAAEa,MAAAA,MAAF;AAAU,SAAGC;AAAb,QAA2BZ,KAAjC;AACA,WAAO,4BAAC,GAAD,OAAUY;AAAV,OAAwBF,OAAxB,CAAP;AACA;;AAED,SAAOA,OAAP;AACA,CA3BM;;;AA6BPf,OAAO,CAACkB,2BAAR,GAAsC,EAAtC;;AAEA,SAASC,WAAT,CAAsBC,MAAtB,EAA8BC,cAAc,GAAG,EAA/C,EAAoD;AACnD,MAAK,CAAEf,KAAK,CAACC,OAAN,CAAea,MAAf,CAAP,EAAiC;AAChCA,IAAAA,MAAM,GAAG,CAAEA,MAAF,CAAT;AACA;;AAED,OAAM,MAAME,KAAZ,IAAqBF,MAArB,EAA8B;AAC7B,QACCE,KAAK,EAAEC,IAAP,EAAaL,2BAAb,KACAlB,OAAO,CAACkB,2BAFT,EAGE;AACDG,MAAAA,cAAc,CAACG,IAAf,CAAqBF,KAAK,CAACjB,KAAN,CAAYJ,KAAjC;AACA;AACA;;AAED,QAAKqB,KAAK,EAAEjB,KAAP,EAAcoB,QAAnB,EAA8B;AAC7BN,MAAAA,WAAW,CAAEG,KAAK,CAACjB,KAAN,CAAYoB,QAAd,EAAwBJ,cAAxB,CAAX;AACA;AACD;;AAED,SAAOA,cAAP;AACA;;AAED,SAASK,eAAT,CAA0B;AAAEC,EAAAA,IAAF;AAAQC,EAAAA,UAAR;AAAoBC,EAAAA;AAApB,CAA1B,EAA8D;AAC7D,SAAO,4BACNF,IADM,EAENC,UAFM,EAGNC,WAAW,CAACC,GAAZ,CAAiBJ,eAAjB,CAHM,CAAP;AAKA;;AAEM,SAASK,iBAAT,CAA4BX,MAAM,GAAG,EAArC,EAA0C;AAChDY,kCAAcC,WAAd,GAA4B,IAA5B;AACA,QAAMC,MAAM,GAAGf,WAAW,CACzB,CAAEb,KAAK,CAACC,OAAN,CAAea,MAAf,IAA0BA,MAA1B,GAAmC,CAAEA,MAAF,CAArC,EAAkDU,GAAlD,CAAuDJ,eAAvD,CADyB,CAA1B;AAGAM,kCAAcC,WAAd,GAA4B,KAA5B;AACA,SAAOC,MAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { RawHTML } from '@wordpress/element';\nimport {\n\tchildren as childrenSource,\n\tgetSaveElement,\n\t__unstableGetBlockProps as getBlockProps,\n} from '@wordpress/blocks';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { getMultilineTag } from './utils';\n\nexport const Content = ( { value, tagName: Tag, multiline, ...props } ) => {\n\t// Handle deprecated `children` and `node` sources.\n\tif ( Array.isArray( value ) ) {\n\t\tdeprecated( 'wp.blockEditor.RichText value prop as children type', {\n\t\t\tsince: '6.1',\n\t\t\tversion: '6.3',\n\t\t\talternative: 'value prop as string',\n\t\t\tlink: 'https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/introducing-attributes-and-editable-fields/',\n\t\t} );\n\n\t\tvalue = childrenSource.toHTML( value );\n\t}\n\n\tconst MultilineTag = getMultilineTag( multiline );\n\n\tif ( ! value && MultilineTag ) {\n\t\tvalue = `<${ MultilineTag }></${ MultilineTag }>`;\n\t}\n\n\tconst content = <RawHTML>{ value }</RawHTML>;\n\n\tif ( Tag ) {\n\t\tconst { format, ...restProps } = props;\n\t\treturn <Tag { ...restProps }>{ content }</Tag>;\n\t}\n\n\treturn content;\n};\n\nContent.__unstableIsRichTextContent = {};\n\nfunction findContent( blocks, richTextValues = [] ) {\n\tif ( ! Array.isArray( blocks ) ) {\n\t\tblocks = [ blocks ];\n\t}\n\n\tfor ( const block of blocks ) {\n\t\tif (\n\t\t\tblock?.type?.__unstableIsRichTextContent ===\n\t\t\tContent.__unstableIsRichTextContent\n\t\t) {\n\t\t\trichTextValues.push( block.props.value );\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( block?.props?.children ) {\n\t\t\tfindContent( block.props.children, richTextValues );\n\t\t}\n\t}\n\n\treturn richTextValues;\n}\n\nfunction _getSaveElement( { name, attributes, innerBlocks } ) {\n\treturn getSaveElement(\n\t\tname,\n\t\tattributes,\n\t\tinnerBlocks.map( _getSaveElement )\n\t);\n}\n\nexport function getRichTextValues( blocks = [] ) {\n\tgetBlockProps.skipFilters = true;\n\tconst values = findContent(\n\t\t( Array.isArray( blocks ) ? blocks : [ blocks ] ).map( _getSaveElement )\n\t);\n\tgetBlockProps.skipFilters = false;\n\treturn values;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/content.js"],"names":["Content","value","tagName","Tag","multiline","props","Array","isArray","since","version","alternative","link","childrenSource","toHTML","MultilineTag","content","format","restProps"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;AAGO,MAAMA,OAAO,GAAG,CAAE;AAAEC,EAAAA,KAAF;AAASC,EAAAA,OAAO,EAAEC,GAAlB;AAAuBC,EAAAA,SAAvB;AAAkC,KAAGC;AAArC,CAAF,KAAoD;AAC1E;AACA,MAAKC,KAAK,CAACC,OAAN,CAAeN,KAAf,CAAL,EAA8B;AAC7B,6BAAY,qDAAZ,EAAmE;AAClEO,MAAAA,KAAK,EAAE,KAD2D;AAElEC,MAAAA,OAAO,EAAE,KAFyD;AAGlEC,MAAAA,WAAW,EAAE,sBAHqD;AAIlEC,MAAAA,IAAI,EAAE;AAJ4D,KAAnE;AAOAV,IAAAA,KAAK,GAAGW,iBAAeC,MAAf,CAAuBZ,KAAvB,CAAR;AACA;;AAED,QAAMa,YAAY,GAAG,4BAAiBV,SAAjB,CAArB;;AAEA,MAAK,CAAEH,KAAF,IAAWa,YAAhB,EAA+B;AAC9Bb,IAAAA,KAAK,GAAI,IAAIa,YAAc,MAAMA,YAAc,GAA/C;AACA;;AAED,QAAMC,OAAO,GAAG,4BAAC,gBAAD,QAAWd,KAAX,CAAhB;;AAEA,MAAKE,GAAL,EAAW;AACV,UAAM;AAAEa,MAAAA,MAAF;AAAU,SAAGC;AAAb,QAA2BZ,KAAjC;AACA,WAAO,4BAAC,GAAD,OAAUY;AAAV,OAAwBF,OAAxB,CAAP;AACA;;AAED,SAAOA,OAAP;AACA,CA3BM","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { RawHTML } from '@wordpress/element';\nimport { children as childrenSource } from '@wordpress/blocks';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { getMultilineTag } from './utils';\n\nexport const Content = ( { value, tagName: Tag, multiline, ...props } ) => {\n\t// Handle deprecated `children` and `node` sources.\n\tif ( Array.isArray( value ) ) {\n\t\tdeprecated( 'wp.blockEditor.RichText value prop as children type', {\n\t\t\tsince: '6.1',\n\t\t\tversion: '6.3',\n\t\t\talternative: 'value prop as string',\n\t\t\tlink: 'https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/introducing-attributes-and-editable-fields/',\n\t\t} );\n\n\t\tvalue = childrenSource.toHTML( value );\n\t}\n\n\tconst MultilineTag = getMultilineTag( multiline );\n\n\tif ( ! value && MultilineTag ) {\n\t\tvalue = `<${ MultilineTag }></${ MultilineTag }>`;\n\t}\n\n\tconst content = <RawHTML>{ value }</RawHTML>;\n\n\tif ( Tag ) {\n\t\tconst { format, ...restProps } = props;\n\t\treturn <Tag { ...restProps }>{ content }</Tag>;\n\t}\n\n\treturn content;\n};\n"]}
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.getRichTextValues = getRichTextValues;
9
+
10
+ var _element = require("@wordpress/element");
11
+
12
+ var _blocks = require("@wordpress/blocks");
13
+
14
+ var _innerBlocks = _interopRequireDefault(require("../inner-blocks"));
15
+
16
+ var _content = require("./content");
17
+
18
+ /**
19
+ * WordPress dependencies
20
+ */
21
+
22
+ /**
23
+ * Internal dependencies
24
+ */
25
+
26
+ /*
27
+ * This function is similar to `@wordpress/element`'s `renderToString` function,
28
+ * except that it does not render the elements to a string, but instead collects
29
+ * the values of all rich text `Content` elements.
30
+ */
31
+ function addValuesForElement(element, ...args) {
32
+ if (null === element || undefined === element || false === element) {
33
+ return;
34
+ }
35
+
36
+ if (Array.isArray(element)) {
37
+ return addValuesForElements(element, ...args);
38
+ }
39
+
40
+ switch (typeof element) {
41
+ case 'string':
42
+ case 'number':
43
+ return;
44
+ }
45
+
46
+ const {
47
+ type,
48
+ props
49
+ } = element;
50
+
51
+ switch (type) {
52
+ case _element.StrictMode:
53
+ case _element.Fragment:
54
+ return addValuesForElements(props.children, ...args);
55
+
56
+ case _element.RawHTML:
57
+ return;
58
+
59
+ case _innerBlocks.default.Content:
60
+ return addValuesForBlocks(...args);
61
+
62
+ case _content.Content:
63
+ const [values] = args;
64
+ values.push(props.value);
65
+ return;
66
+ }
67
+
68
+ switch (typeof type) {
69
+ case 'string':
70
+ if (typeof props.children !== 'undefined') {
71
+ return addValuesForElements(props.children, ...args);
72
+ }
73
+
74
+ return;
75
+
76
+ case 'function':
77
+ if (type.prototype && typeof type.prototype.render === 'function') {
78
+ return addValuesForElement(new type(props).render(), ...args);
79
+ }
80
+
81
+ return addValuesForElement(type(props), ...args);
82
+ }
83
+ }
84
+
85
+ function addValuesForElements(children, ...args) {
86
+ children = Array.isArray(children) ? children : [children];
87
+
88
+ for (let i = 0; i < children.length; i++) {
89
+ addValuesForElement(children[i], ...args);
90
+ }
91
+ }
92
+
93
+ function addValuesForBlocks(values, blocks) {
94
+ for (let i = 0; i < blocks.length; i++) {
95
+ const {
96
+ name,
97
+ attributes,
98
+ innerBlocks
99
+ } = blocks[i];
100
+ const saveElement = (0, _blocks.getSaveElement)(name, attributes);
101
+ addValuesForElement(saveElement, values, innerBlocks);
102
+ }
103
+ }
104
+
105
+ function getRichTextValues(blocks = []) {
106
+ _blocks.__unstableGetBlockProps.skipFilters = true;
107
+ const values = [];
108
+ addValuesForBlocks(values, blocks);
109
+ _blocks.__unstableGetBlockProps.skipFilters = false;
110
+ return values;
111
+ }
112
+ //# sourceMappingURL=get-rich-text-values.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/get-rich-text-values.js"],"names":["addValuesForElement","element","args","undefined","Array","isArray","addValuesForElements","type","props","StrictMode","Fragment","children","RawHTML","InnerBlocks","Content","addValuesForBlocks","values","push","value","prototype","render","i","length","blocks","name","attributes","innerBlocks","saveElement","getRichTextValues","getBlockProps","skipFil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TML, StrictMode, Fragment } from '@wordpress/element';\nimport {\n\tgetSaveElement,\n\t__unstableGetBlockProps as getBlockProps,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport InnerBlocks from '../inner-blocks';\nimport { Content } from './content';\n\n/*\n * This function is similar to `@wordpress/element`'s `renderToString` function,\n * except that it does not render the elements to a string, but instead collects\n * the values of all rich text `Content` elements.\n */\nfunction addValuesForElement( element, ...args ) {\n\tif ( null === element || undefined === element || false === element ) {\n\t\treturn;\n\t}\n\n\tif ( Array.isArray( element ) ) {\n\t\treturn addValuesForElements( element, ...args );\n\t}\n\n\tswitch ( typeof element ) {\n\t\tcase 'string':\n\t\tcase 'number':\n\t\t\treturn;\n\t}\n\n\tconst { type, props } = element;\n\n\tswitch ( type ) {\n\t\tcase StrictMode:\n\t\tcase Fragment:\n\t\t\treturn addValuesForElements( props.children, ...args );\n\t\tcase RawHTML:\n\t\t\treturn;\n\t\tcase InnerBlocks.Content:\n\t\t\treturn addValuesForBlocks( ...args );\n\t\tcase Content:\n\t\t\tconst [ values ] = args;\n\t\t\tvalues.push( props.value );\n\t\t\treturn;\n\t}\n\n\tswitch ( typeof type ) {\n\t\tcase 'string':\n\t\t\tif ( typeof props.children !== 'undefined' ) {\n\t\t\t\treturn addValuesForElements( props.children, ...args );\n\t\t\t}\n\t\t\treturn;\n\t\tcase 'function':\n\t\t\tif (\n\t\t\t\ttype.prototype &&\n\t\t\t\ttypeof type.prototype.render === 'function'\n\t\t\t) {\n\t\t\t\treturn addValuesForElement(\n\t\t\t\t\tnew type( props ).render(),\n\t\t\t\t\t...args\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn addValuesForElement( type( props ), ...args );\n\t}\n}\n\nfunction addValuesForElements( children, ...args ) {\n\tchildren = Array.isArray( children ) ? children : [ children ];\n\n\tfor ( let i = 0; i < children.length; i++ ) {\n\t\taddValuesForElement( children[ i ], ...args );\n\t}\n}\n\nfunction addValuesForBlocks( values, blocks ) {\n\tfor ( let i = 0; i < blocks.length; i++ ) {\n\t\tconst { name, attributes, innerBlocks } = blocks[ i ];\n\t\tconst saveElement = getSaveElement( name, attributes );\n\t\taddValuesForElement( saveElement, values, innerBlocks );\n\t}\n}\n\nexport function getRichTextValues( blocks = [] ) {\n\tgetBlockProps.skipFilters = true;\n\tconst values = [];\n\taddValuesForBlocks( values, blocks );\n\tgetBlockProps.skipFilters = false;\n\treturn values;\n}\n"]}
@@ -13,7 +13,7 @@ var _provider = require("./components/provider");
13
13
 
14
14
  var _lockUnlock = require("./lock-unlock");
15
15
 
16
- var _content = require("./components/rich-text/content");
16
+ var _getRichTextValues = require("./components/rich-text/get-rich-text-values");
17
17
 
18
18
  var _resizableBoxPopover = _interopRequireDefault(require("./components/resizable-box-popover"));
19
19
 
@@ -56,7 +56,7 @@ const privateApis = {};
56
56
  exports.privateApis = privateApis;
57
57
  (0, _lockUnlock.lock)(privateApis, { ...globalStyles,
58
58
  ExperimentalBlockEditorProvider: _provider.ExperimentalBlockEditorProvider,
59
- getRichTextValues: _content.getRichTextValues,
59
+ getRichTextValues: _getRichTextValues.getRichTextValues,
60
60
  PrivateInserter: _inserter.ComposedPrivateInserter,
61
61
  PrivateListView: _listView.PrivateListView,
62
62
  ResizableBoxPopover: _resizableBoxPopover.default,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/private-apis.js"],"names":["privateApis","globalStyles","ExperimentalBlockEditorProvider","getRichTextValues","PrivateInserter","PrivateListView","ResizableBoxPopover","BlockInfo","useShouldContextualToolbarShow","cleanEmptyObject","useBlockEditingMode","BlockQuickNavigation","LayoutStyle","BlockRemovalWarningModal","useLayoutClasses","useLayoutStyles","DimensionsTool","ResolutionTool"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAnBA;AACA;AACA;;AAmBA;AACA;AACA;AACO,MAAMA,WAAW,GAAG,EAApB;;AACP,sBAAMA,WAAN,EAAmB,EAClB,GAAGC,YADe;AAElBC,EAAAA,+BAA+B,EAA/BA,yCAFkB;AAGlBC,EAAAA,iBAAiB,EAAjBA,0BAHkB;AAIlBC,EAAAA,eAAe,EAAfA,iCAJkB;AAKlBC,EAAAA,eAAe,EAAfA,yBALkB;AAMlBC,EAAAA,mBAAmB,EAAnBA,4BANkB;AAOlBC,EAAAA,SAAS,EAATA,0BAPkB;AAQlBC,EAAAA,8BAA8B,EAA9BA,8DARkB;AASlBC,EAAAA,gBAAgB,EAAhBA,uBATkB;AAUlBC,EAAAA,mBAAmB,EAAnBA,qCAVkB;AAWlBC,EAAAA,oBAAoB,EAApBA,6BAXkB;AAYlBC,EAAAA,WAAW,EAAXA,mBAZkB;AAalBC,EAAAA,wBAAwB,EAAxBA,kDAbkB;AAclBC,EAAAA,gBAAgB,EAAhBA,uBAdkB;AAelBC,EAAAA,eAAe,EAAfA,sBAfkB;AAgBlBC,EAAAA,cAAc,EAAdA,uBAhBkB;AAiBlBC,EAAAA,cAAc,EAAdA;AAjBkB,CAAnB","sourcesContent":["/**\n * Internal dependencies\n */\nimport * as globalStyles from './components/global-styles';\nimport { ExperimentalBlockEditorProvider } from './components/provider';\nimport { lock } from './lock-unlock';\nimport { getRichTextValues } from './components/rich-text/content';\nimport ResizableBoxPopover from './components/resizable-box-popover';\nimport { ComposedPrivateInserter as PrivateInserter } from './components/inserter';\nimport { PrivateListView } from './components/list-view';\nimport BlockInfo from './components/block-info-slot-fill';\nimport { useShouldContextualToolbarShow } from './utils/use-should-contextual-toolbar-show';\nimport { cleanEmptyObject } from './hooks/utils';\nimport { useBlockEditingMode } from './components/block-editing-mode';\nimport BlockQuickNavigation from './components/block-quick-navigation';\nimport { LayoutStyle } from './components/block-list/layout';\nimport { BlockRemovalWarningModal } from './components/block-removal-warning-modal';\nimport { useLayoutClasses, useLayoutStyles } from './hooks';\nimport DimensionsTool from './components/dimensions-tool';\nimport ResolutionTool from './components/resolution-tool';\n\n/**\n * Private @wordpress/block-editor APIs.\n */\nexport const privateApis = {};\nlock( privateApis, {\n\t...globalStyles,\n\tExperimentalBlockEditorProvider,\n\tgetRichTextValues,\n\tPrivateInserter,\n\tPrivateListView,\n\tResizableBoxPopover,\n\tBlockInfo,\n\tuseShouldContextualToolbarShow,\n\tcleanEmptyObject,\n\tuseBlockEditingMode,\n\tBlockQuickNavigation,\n\tLayoutStyle,\n\tBlockRemovalWarningModal,\n\tuseLayoutClasses,\n\tuseLayoutStyles,\n\tDimensionsTool,\n\tResolutionTool,\n} );\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/private-apis.js"],"names":["privateApis","globalStyles","ExperimentalBlockEditorProvider","getRichTextValues","PrivateInserter","PrivateListView","ResizableBoxPopover","BlockInfo","useShouldContextualToolbarShow","cleanEmptyObject","useBlockEditingMode","BlockQuickNavigation","LayoutStyle","BlockRemovalWarningModal","useLayoutClasses","useLayoutStyles","DimensionsTool","ResolutionTool"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAnBA;AACA;AACA;;AAmBA;AACA;AACA;AACO,MAAMA,WAAW,GAAG,EAApB;;AACP,sBAAMA,WAAN,EAAmB,EAClB,GAAGC,YADe;AAElBC,EAAAA,+BAA+B,EAA/BA,yCAFkB;AAGlBC,EAAAA,iBAAiB,EAAjBA,oCAHkB;AAIlBC,EAAAA,eAAe,EAAfA,iCAJkB;AAKlBC,EAAAA,eAAe,EAAfA,yBALkB;AAMlBC,EAAAA,mBAAmB,EAAnBA,4BANkB;AAOlBC,EAAAA,SAAS,EAATA,0BAPkB;AAQlBC,EAAAA,8BAA8B,EAA9BA,8DARkB;AASlBC,EAAAA,gBAAgB,EAAhBA,uBATkB;AAUlBC,EAAAA,mBAAmB,EAAnBA,qCAVkB;AAWlBC,EAAAA,oBAAoB,EAApBA,6BAXkB;AAYlBC,EAAAA,WAAW,EAAXA,mBAZkB;AAalBC,EAAAA,wBAAwB,EAAxBA,kDAbkB;AAclBC,EAAAA,gBAAgB,EAAhBA,uBAdkB;AAelBC,EAAAA,eAAe,EAAfA,sBAfkB;AAgBlBC,EAAAA,cAAc,EAAdA,uBAhBkB;AAiBlBC,EAAAA,cAAc,EAAdA;AAjBkB,CAAnB","sourcesContent":["/**\n * Internal dependencies\n */\nimport * as globalStyles from './components/global-styles';\nimport { ExperimentalBlockEditorProvider } from './components/provider';\nimport { lock } from './lock-unlock';\nimport { getRichTextValues } from './components/rich-text/get-rich-text-values';\nimport ResizableBoxPopover from './components/resizable-box-popover';\nimport { ComposedPrivateInserter as PrivateInserter } from './components/inserter';\nimport { PrivateListView } from './components/list-view';\nimport BlockInfo from './components/block-info-slot-fill';\nimport { useShouldContextualToolbarShow } from './utils/use-should-contextual-toolbar-show';\nimport { cleanEmptyObject } from './hooks/utils';\nimport { useBlockEditingMode } from './components/block-editing-mode';\nimport BlockQuickNavigation from './components/block-quick-navigation';\nimport { LayoutStyle } from './components/block-list/layout';\nimport { BlockRemovalWarningModal } from './components/block-removal-warning-modal';\nimport { useLayoutClasses, useLayoutStyles } from './hooks';\nimport DimensionsTool from './components/dimensions-tool';\nimport ResolutionTool from './components/resolution-tool';\n\n/**\n * Private @wordpress/block-editor APIs.\n */\nexport const privateApis = {};\nlock( privateApis, {\n\t...globalStyles,\n\tExperimentalBlockEditorProvider,\n\tgetRichTextValues,\n\tPrivateInserter,\n\tPrivateListView,\n\tResizableBoxPopover,\n\tBlockInfo,\n\tuseShouldContextualToolbarShow,\n\tcleanEmptyObject,\n\tuseBlockEditingMode,\n\tBlockQuickNavigation,\n\tLayoutStyle,\n\tBlockRemovalWarningModal,\n\tuseLayoutClasses,\n\tuseLayoutStyles,\n\tDimensionsTool,\n\tResolutionTool,\n} );\n"]}
@@ -8,7 +8,7 @@ import classnames from 'classnames';
8
8
  * WordPress dependencies
9
9
  */
10
10
 
11
- import { useState, createPortal, forwardRef, useMemo, useReducer, useEffect } from '@wordpress/element';
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
- var _assets$styles;
116
-
117
- const assets = useSelect(select => select(blockEditorStore).getSettings().__unstableResolvedAssets, []);
118
- const [, forceRender] = useReducer(() => ({}));
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, headRef]); // Correct doctype is required to enable rendering in standards
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 = '<!doctype html>' + '<style>html{height:auto!important;min-height:100%;}body{margin:0}</style>' + ((_assets$styles = assets?.styles) !== null && _assets$styles !== void 0 ? _assets$styles : '');
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,SAC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C,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;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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,EAAaG,SAdV;AAePC,MAAAA,UAAU,EAAE;AAfL,KAFT;AAmBC,IAAA,GAAG,EAAG9G,YAAY,CAAE,CAAEkD,GAAF,EAAOmB,MAAP,CAAF,CAnBnB;AAoBC,IAAA,QAAQ,EAAGzB,QApBZ,CAqBC;AACA;AACA;AAvBD;AAwBC,IAAA,GAAG,EAAGsD,GAxBP;AAyBC,IAAA,KAAK,EAAGpG,EAAE,CAAE,eAAF;AAzBX,KA2BG2D,cAAc,IACf/D,YAAY,CACX;AACC,IAAA,GAAG,EAAGsG,OADP;AAEC,IAAA,SAAS,EAAGxG,UAAU,CACrB,2BADqB,EAErB,uBAFqB,EAGrB,GAAGmE,WAHkB;AAFvB,KAQGO,qBARH,EASC,cAAC,aAAD;AAAe,IAAA,QAAQ,EAAGT;AAA1B,KACGd,QADH,CATD,CADW,EAcXc,cAAc,CAACoB,eAdJ,CA5Bd,CAFD,EA+CGjC,QAAQ,IAAI,CAAZ,IAAiBqB,KA/CpB,CADD;AAmDA;;AAED,SAAS8C,aAAT,CAAwB5D,KAAxB,EAA+BD,GAA/B,EAAqC;AACpC,QAAM8D,aAAa,GAAG3G,SAAS,CAC5BiD,MAAF,IACCA,MAAM,CAAE5C,gBAAF,CAAN,CAA2B6C,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,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"]}
@@ -4,7 +4,7 @@ import { createElement } from "@wordpress/element";
4
4
  * WordPress dependencies
5
5
  */
6
6
  import { RawHTML } from '@wordpress/element';
7
- import { children as childrenSource, getSaveElement, __unstableGetBlockProps as getBlockProps } from '@wordpress/blocks';
7
+ import { children as childrenSource } from '@wordpress/blocks';
8
8
  import deprecated from '@wordpress/deprecated';
9
9
  /**
10
10
  * Internal dependencies
@@ -47,39 +47,4 @@ export const Content = ({
47
47
 
48
48
  return content;
49
49
  };
50
- Content.__unstableIsRichTextContent = {};
51
-
52
- function findContent(blocks, richTextValues = []) {
53
- if (!Array.isArray(blocks)) {
54
- blocks = [blocks];
55
- }
56
-
57
- for (const block of blocks) {
58
- if (block?.type?.__unstableIsRichTextContent === Content.__unstableIsRichTextContent) {
59
- richTextValues.push(block.props.value);
60
- continue;
61
- }
62
-
63
- if (block?.props?.children) {
64
- findContent(block.props.children, richTextValues);
65
- }
66
- }
67
-
68
- return richTextValues;
69
- }
70
-
71
- function _getSaveElement({
72
- name,
73
- attributes,
74
- innerBlocks
75
- }) {
76
- return getSaveElement(name, attributes, innerBlocks.map(_getSaveElement));
77
- }
78
-
79
- export function getRichTextValues(blocks = []) {
80
- getBlockProps.skipFilters = true;
81
- const values = findContent((Array.isArray(blocks) ? blocks : [blocks]).map(_getSaveElement));
82
- getBlockProps.skipFilters = false;
83
- return values;
84
- }
85
50
  //# sourceMappingURL=content.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/content.js"],"names":["RawHTML","children","childrenSource","getSaveElement","__unstableGetBlockProps","getBlockProps","deprecated","getMultilineTag","Content","value","tagName","Tag","multiline","props","Array","isArray","since","version","alternative","link","toHTML","MultilineTag","content","format","restProps","__unstableIsRichTextContent","findContent","blocks","richTextValues","block","type","push","_getSaveElement","name","attributes","innerBlocks","map","getRichTextValues","skipFilters","values"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,oBAAxB;AACA,SACCC,QAAQ,IAAIC,cADb,EAECC,cAFD,EAGCC,uBAAuB,IAAIC,aAH5B,QAIO,mBAJP;AAKA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,SAASC,eAAT,QAAgC,SAAhC;AAEA,OAAO,MAAMC,OAAO,GAAG,CAAE;AAAEC,EAAAA,KAAF;AAASC,EAAAA,OAAO,EAAEC,GAAlB;AAAuBC,EAAAA,SAAvB;AAAkC,KAAGC;AAArC,CAAF,KAAoD;AAC1E;AACA,MAAKC,KAAK,CAACC,OAAN,CAAeN,KAAf,CAAL,EAA8B;AAC7BH,IAAAA,UAAU,CAAE,qDAAF,EAAyD;AAClEU,MAAAA,KAAK,EAAE,KAD2D;AAElEC,MAAAA,OAAO,EAAE,KAFyD;AAGlEC,MAAAA,WAAW,EAAE,sBAHqD;AAIlEC,MAAAA,IAAI,EAAE;AAJ4D,KAAzD,CAAV;AAOAV,IAAAA,KAAK,GAAGP,cAAc,CAACkB,MAAf,CAAuBX,KAAvB,CAAR;AACA;;AAED,QAAMY,YAAY,GAAGd,eAAe,CAAEK,SAAF,CAAp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AAM,GAAG,EAArC,EAA0C;AAChDtB,EAAAA,aAAa,CAACiC,WAAd,GAA4B,IAA5B;AACA,QAAMC,MAAM,GAAGb,WAAW,CACzB,CAAEZ,KAAK,CAACC,OAAN,CAAeY,MAAf,IAA0BA,MAA1B,GAAmC,CAAEA,MAAF,CAArC,EAAkDS,GAAlD,CAAuDJ,eAAvD,CADyB,CAA1B;AAGA3B,EAAAA,aAAa,CAACiC,WAAd,GAA4B,KAA5B;AACA,SAAOC,MAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { RawHTML } from '@wordpress/element';\nimport {\n\tchildren as childrenSource,\n\tgetSaveElement,\n\t__unstableGetBlockProps as getBlockProps,\n} from '@wordpress/blocks';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { getMultilineTag } from './utils';\n\nexport const Content = ( { value, tagName: Tag, multiline, ...props } ) => {\n\t// Handle deprecated `children` and `node` sources.\n\tif ( Array.isArray( value ) ) {\n\t\tdeprecated( 'wp.blockEditor.RichText value prop as children type', {\n\t\t\tsince: '6.1',\n\t\t\tversion: '6.3',\n\t\t\talternative: 'value prop as string',\n\t\t\tlink: 'https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/introducing-attributes-and-editable-fields/',\n\t\t} );\n\n\t\tvalue = childrenSource.toHTML( value );\n\t}\n\n\tconst MultilineTag = getMultilineTag( multiline );\n\n\tif ( ! value && MultilineTag ) {\n\t\tvalue = `<${ MultilineTag }></${ MultilineTag }>`;\n\t}\n\n\tconst content = <RawHTML>{ value }</RawHTML>;\n\n\tif ( Tag ) {\n\t\tconst { format, ...restProps } = props;\n\t\treturn <Tag { ...restProps }>{ content }</Tag>;\n\t}\n\n\treturn content;\n};\n\nContent.__unstableIsRichTextContent = {};\n\nfunction findContent( blocks, richTextValues = [] ) {\n\tif ( ! Array.isArray( blocks ) ) {\n\t\tblocks = [ blocks ];\n\t}\n\n\tfor ( const block of blocks ) {\n\t\tif (\n\t\t\tblock?.type?.__unstableIsRichTextContent ===\n\t\t\tContent.__unstableIsRichTextContent\n\t\t) {\n\t\t\trichTextValues.push( block.props.value );\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( block?.props?.children ) {\n\t\t\tfindContent( block.props.children, richTextValues );\n\t\t}\n\t}\n\n\treturn richTextValues;\n}\n\nfunction _getSaveElement( { name, attributes, innerBlocks } ) {\n\treturn getSaveElement(\n\t\tname,\n\t\tattributes,\n\t\tinnerBlocks.map( _getSaveElement )\n\t);\n}\n\nexport function getRichTextValues( blocks = [] ) {\n\tgetBlockProps.skipFilters = true;\n\tconst values = findContent(\n\t\t( Array.isArray( blocks ) ? blocks : [ blocks ] ).map( _getSaveElement )\n\t);\n\tgetBlockProps.skipFilters = false;\n\treturn values;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/content.js"],"names":["RawHTML","children","childrenSource","deprecated","getMultilineTag","Content","value","tagName","Tag","multiline","props","Array","isArray","since","version","alternative","link","toHTML","MultilineTag","content","format","restProps"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,OAAT,QAAwB,oBAAxB;AACA,SAASC,QAAQ,IAAIC,cAArB,QAA2C,mBAA3C;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,SAASC,eAAT,QAAgC,SAAhC;AAEA,OAAO,MAAMC,OAAO,GAAG,CAAE;AAAEC,EAAAA,KAAF;AAASC,EAAAA,OAAO,EAAEC,GAAlB;AAAuBC,EAAAA,SAAvB;AAAkC,KAAGC;AAArC,CAAF,KAAoD;AAC1E;AACA,MAAKC,KAAK,CAACC,OAAN,CAAeN,KAAf,CAAL,EAA8B;AAC7BH,IAAAA,UAAU,CAAE,qDAAF,EAAyD;AAClEU,MAAAA,KAAK,EAAE,KAD2D;AAElEC,MAAAA,OAAO,EAAE,KAFyD;AAGlEC,MAAAA,WAAW,EAAE,sBAHqD;AAIlEC,MAAAA,IAAI,EAAE;AAJ4D,KAAzD,CAAV;AAOAV,IAAAA,KAAK,GAAGJ,cAAc,CAACe,MAAf,CAAuBX,KAAvB,CAAR;AACA;;AAED,QAAMY,YAAY,GAAGd,eAAe,CAAEK,SAAF,CAApC;;AAEA,MAAK,CAAEH,KAAF,IAAWY,YAAhB,EAA+B;AAC9BZ,IAAAA,KAAK,GAAI,IAAIY,YAAc,MAAMA,YAAc,GAA/C;AACA;;AAED,QAAMC,OAAO,GAAG,cAAC,OAAD,QAAWb,KAAX,CAAhB;;AAEA,MAAKE,GAAL,EAAW;AACV,UAAM;AAAEY,MAAAA,MAAF;AAAU,SAAGC;AAAb,QAA2BX,KAAjC;AACA,WAAO,cAAC,GAAD,OAAUW;AAAV,OAAwBF,OAAxB,CAAP;AACA;;AAED,SAAOA,OAAP;AACA,CA3BM","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { RawHTML } from '@wordpress/element';\nimport { children as childrenSource } from '@wordpress/blocks';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { getMultilineTag } from './utils';\n\nexport const Content = ( { value, tagName: Tag, multiline, ...props } ) => {\n\t// Handle deprecated `children` and `node` sources.\n\tif ( Array.isArray( value ) ) {\n\t\tdeprecated( 'wp.blockEditor.RichText value prop as children type', {\n\t\t\tsince: '6.1',\n\t\t\tversion: '6.3',\n\t\t\talternative: 'value prop as string',\n\t\t\tlink: 'https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/introducing-attributes-and-editable-fields/',\n\t\t} );\n\n\t\tvalue = childrenSource.toHTML( value );\n\t}\n\n\tconst MultilineTag = getMultilineTag( multiline );\n\n\tif ( ! value && MultilineTag ) {\n\t\tvalue = `<${ MultilineTag }></${ MultilineTag }>`;\n\t}\n\n\tconst content = <RawHTML>{ value }</RawHTML>;\n\n\tif ( Tag ) {\n\t\tconst { format, ...restProps } = props;\n\t\treturn <Tag { ...restProps }>{ content }</Tag>;\n\t}\n\n\treturn content;\n};\n"]}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { RawHTML, StrictMode, Fragment } from '@wordpress/element';
5
+ import { getSaveElement, __unstableGetBlockProps as getBlockProps } from '@wordpress/blocks';
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+
10
+ import InnerBlocks from '../inner-blocks';
11
+ import { Content } from './content';
12
+ /*
13
+ * This function is similar to `@wordpress/element`'s `renderToString` function,
14
+ * except that it does not render the elements to a string, but instead collects
15
+ * the values of all rich text `Content` elements.
16
+ */
17
+
18
+ function addValuesForElement(element, ...args) {
19
+ if (null === element || undefined === element || false === element) {
20
+ return;
21
+ }
22
+
23
+ if (Array.isArray(element)) {
24
+ return addValuesForElements(element, ...args);
25
+ }
26
+
27
+ switch (typeof element) {
28
+ case 'string':
29
+ case 'number':
30
+ return;
31
+ }
32
+
33
+ const {
34
+ type,
35
+ props
36
+ } = element;
37
+
38
+ switch (type) {
39
+ case StrictMode:
40
+ case Fragment:
41
+ return addValuesForElements(props.children, ...args);
42
+
43
+ case RawHTML:
44
+ return;
45
+
46
+ case InnerBlocks.Content:
47
+ return addValuesForBlocks(...args);
48
+
49
+ case Content:
50
+ const [values] = args;
51
+ values.push(props.value);
52
+ return;
53
+ }
54
+
55
+ switch (typeof type) {
56
+ case 'string':
57
+ if (typeof props.children !== 'undefined') {
58
+ return addValuesForElements(props.children, ...args);
59
+ }
60
+
61
+ return;
62
+
63
+ case 'function':
64
+ if (type.prototype && typeof type.prototype.render === 'function') {
65
+ return addValuesForElement(new type(props).render(), ...args);
66
+ }
67
+
68
+ return addValuesForElement(type(props), ...args);
69
+ }
70
+ }
71
+
72
+ function addValuesForElements(children, ...args) {
73
+ children = Array.isArray(children) ? children : [children];
74
+
75
+ for (let i = 0; i < children.length; i++) {
76
+ addValuesForElement(children[i], ...args);
77
+ }
78
+ }
79
+
80
+ function addValuesForBlocks(values, blocks) {
81
+ for (let i = 0; i < blocks.length; i++) {
82
+ const {
83
+ name,
84
+ attributes,
85
+ innerBlocks
86
+ } = blocks[i];
87
+ const saveElement = getSaveElement(name, attributes);
88
+ addValuesForElement(saveElement, values, innerBlocks);
89
+ }
90
+ }
91
+
92
+ export function getRichTextValues(blocks = []) {
93
+ getBlockProps.skipFilters = true;
94
+ const values = [];
95
+ addValuesForBlocks(values, blocks);
96
+ getBlockProps.skipFilters = false;
97
+ return values;
98
+ }
99
+ //# sourceMappingURL=get-rich-text-values.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/block-editor/src/components/rich-text/get-rich-text-values.js"],"names":["RawHTML","StrictMode","Fragment","getSaveElement","__unstableGetBlockProps","getBlockProps","InnerBlocks","Content","addValuesForElement","element","args","undefined","Array","isArray","addValuesForElements","type","props","children","addValuesForBlocks","values","push","value","prototype","render","i","length","blocks","name","attributes","innerBlocks","saveElement","getRichTextValues","skipFilters"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,UAAlB,EAA8BC,QAA9B,QAA8C,oBAA9C;AACA,SACCC,cADD,EAECC,uBAAuB,IAAIC,aAF5B,QAGO,mBAHP;AAKA;AACA;AACA;;AACA,OAAOC,WAAP,MAAwB,iBAAxB;AACA,SAASC,OAAT,QAAwB,WAAxB;AAEA;AACA;AACA;AACA;AACA;;AACA,SAASC,mBAAT,CAA8BC,OAA9B,EAAuC,GAAGC,IAA1C,EAAiD;AAChD,MAAK,SAASD,OAAT,IAAoBE,SAAS,KAAKF,OAAlC,IAA6C,UAAUA,OAA5D,EAAsE;AACrE;AACA;;AAED,MAAKG,KAAK,CAACC,OAAN,CAAeJ,OAAf,CAAL,EAAgC;AAC/B,WAAOK,oBAAoB,CAAEL,OAAF,EAAW,GAAGC,IAAd,CAA3B;AACA;;AAED,UAAS,OAAOD,OAAhB;AACC,SAAK,QAAL;AACA,SAAK,QAAL;AACC;AAHF;;AAMA,QAAM;AAAEM,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAkBP,OAAxB;;AAEA,UAASM,IAAT;AACC,SAAKd,UAAL;AACA,SAAKC,Q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,MAArC,EAA8C;AAC7C,OAAM,IAAIF,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGE,MAAM,CAACD,MAA5B,EAAoCD,CAAC,EAArC,EAA0C;AACzC,UAAM;AAAEG,MAAAA,IAAF;AAAQC,MAAAA,UAAR;AAAoBC,MAAAA;AAApB,QAAoCH,MAAM,CAAEF,CAAF,CAAhD;AACA,UAAMM,WAAW,GAAG3B,cAAc,CAAEwB,IAAF,EAAQC,UAAR,CAAlC;AACApB,IAAAA,mBAAmB,CAAEsB,WAAF,EAAeX,MAAf,EAAuBU,WAAvB,CAAnB;AACA;AACD;;AAED,OAAO,SAASE,iBAAT,CAA4BL,MAAM,GAAG,EAArC,EAA0C;AAChDrB,EAAAA,aAAa,CAAC2B,WAAd,GAA4B,IAA5B;AACA,QAAMb,MAAM,GAAG,EAAf;AACAD,EAAAA,kBAAkB,CAAEC,MAAF,EAAUO,MAAV,CAAlB;AACArB,EAAAA,aAAa,CAAC2B,WAAd,GAA4B,KAA5B;AACA,SAAOb,MAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { RawHTML, StrictMode, Fragment } from '@wordpress/element';\nimport {\n\tgetSaveElement,\n\t__unstableGetBlockProps as getBlockProps,\n} from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport InnerBlocks from '../inner-blocks';\nimport { Content } from './content';\n\n/*\n * This function is similar to `@wordpress/element`'s `renderToString` function,\n * except that it does not render the elements to a string, but instead collects\n * the values of all rich text `Content` elements.\n */\nfunction addValuesForElement( element, ...args ) {\n\tif ( null === element || undefined === element || false === element ) {\n\t\treturn;\n\t}\n\n\tif ( Array.isArray( element ) ) {\n\t\treturn addValuesForElements( element, ...args );\n\t}\n\n\tswitch ( typeof element ) {\n\t\tcase 'string':\n\t\tcase 'number':\n\t\t\treturn;\n\t}\n\n\tconst { type, props } = element;\n\n\tswitch ( type ) {\n\t\tcase StrictMode:\n\t\tcase Fragment:\n\t\t\treturn addValuesForElements( props.children, ...args );\n\t\tcase RawHTML:\n\t\t\treturn;\n\t\tcase InnerBlocks.Content:\n\t\t\treturn addValuesForBlocks( ...args );\n\t\tcase Content:\n\t\t\tconst [ values ] = args;\n\t\t\tvalues.push( props.value );\n\t\t\treturn;\n\t}\n\n\tswitch ( typeof type ) {\n\t\tcase 'string':\n\t\t\tif ( typeof props.children !== 'undefined' ) {\n\t\t\t\treturn addValuesForElements( props.children, ...args );\n\t\t\t}\n\t\t\treturn;\n\t\tcase 'function':\n\t\t\tif (\n\t\t\t\ttype.prototype &&\n\t\t\t\ttypeof type.prototype.render === 'function'\n\t\t\t) {\n\t\t\t\treturn addValuesForElement(\n\t\t\t\t\tnew type( props ).render(),\n\t\t\t\t\t...args\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn addValuesForElement( type( props ), ...args );\n\t}\n}\n\nfunction addValuesForElements( children, ...args ) {\n\tchildren = Array.isArray( children ) ? children : [ children ];\n\n\tfor ( let i = 0; i < children.length; i++ ) {\n\t\taddValuesForElement( children[ i ], ...args );\n\t}\n}\n\nfunction addValuesForBlocks( values, blocks ) {\n\tfor ( let i = 0; i < blocks.length; i++ ) {\n\t\tconst { name, attributes, innerBlocks } = blocks[ i ];\n\t\tconst saveElement = getSaveElement( name, attributes );\n\t\taddValuesForElement( saveElement, values, innerBlocks );\n\t}\n}\n\nexport function getRichTextValues( blocks = [] ) {\n\tgetBlockProps.skipFilters = true;\n\tconst values = [];\n\taddValuesForBlocks( values, blocks );\n\tgetBlockProps.skipFilters = false;\n\treturn values;\n}\n"]}
@@ -4,7 +4,7 @@
4
4
  import * as globalStyles from './components/global-styles';
5
5
  import { ExperimentalBlockEditorProvider } from './components/provider';
6
6
  import { lock } from './lock-unlock';
7
- import { getRichTextValues } from './components/rich-text/content';
7
+ import { getRichTextValues } from './components/rich-text/get-rich-text-values';
8
8
  import ResizableBoxPopover from './components/resizable-box-popover';
9
9
  import { ComposedPrivateInserter as PrivateInserter } from './components/inserter';
10
10
  import { PrivateListView } from './components/list-view';
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/block-editor/src/private-apis.js"],"names":["globalStyles","ExperimentalBlockEditorProvider","lock","getRichTextValues","ResizableBoxPopover","ComposedPrivateInserter","PrivateInserter","PrivateListView","BlockInfo","useShouldContextualToolbarShow","cleanEmptyObject","useBlockEditingMode","BlockQuickNavigation","LayoutStyle","BlockRemovalWarningModal","useLayoutClasses","useLayoutStyles","DimensionsTool","ResolutionTool","privateApis"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,KAAKA,YAAZ,MAA8B,4BAA9B;AACA,SAASC,+BAAT,QAAgD,uBAAhD;AACA,SAASC,IAAT,QAAqB,eAArB;AACA,SAASC,iBAAT,QAAkC,gCAAlC;AACA,OAAOC,mBAAP,MAAgC,oCAAhC;AACA,SAASC,uBAAuB,IAAIC,eAApC,QAA2D,uBAA3D;AACA,SAASC,eAAT,QAAgC,wBAAhC;AACA,OAAOC,SAAP,MAAsB,mCAAtB;AACA,SAASC,8BAAT,QAA+C,4CAA/C;AACA,SAASC,gBAAT,QAAiC,eAAjC;AACA,SAASC,mBAAT,QAAoC,iCAApC;AACA,OAAOC,oBAAP,MAAiC,qCAAjC;AACA,SAASC,WAAT,QAA4B,gCAA5B;AACA,SAASC,wBAAT,QAAyC,0CAAzC;AACA,SAASC,gBAAT,EAA2BC,eAA3B,QAAkD,SAAlD;AACA,OAAOC,cAAP,MAA2B,8BAA3B;AACA,OAAOC,cAAP,MAA2B,8BAA3B;AAEA;AACA;AACA;;AACA,OAAO,MAAMC,WAAW,GAAG,EAApB;AACPjB,IAAI,CAAEiB,WAAF,EAAe,EAClB,GAAGnB,YADe;AAElBC,EAAAA,+BAFkB;AAGlBE,EAAAA,iBAHkB;AAIlBG,EAAAA,eAJkB;AAKlBC,EAAAA,eALkB;AAMlBH,EAAAA,mBANkB;AAOlBI,EAAAA,SAPkB;AAQlBC,EAAAA,8BARkB;AASlBC,EAAAA,gBATkB;AAUlBC,EAAAA,mBAVkB;AAWlBC,EAAAA,oBAXkB;AAYlBC,EAAAA,WAZkB;AAalBC,EAAAA,wBAbkB;AAclBC,EAAAA,gBAdkB;AAelBC,EAAAA,eAfkB;AAgBlBC,EAAAA,cAhBkB;AAiBlBC,EAAAA;AAjBkB,CAAf,CAAJ","sourcesContent":["/**\n * Internal dependencies\n */\nimport * as globalStyles from './components/global-styles';\nimport { ExperimentalBlockEditorProvider } from './components/provider';\nimport { lock } from './lock-unlock';\nimport { getRichTextValues } from './components/rich-text/content';\nimport ResizableBoxPopover from './components/resizable-box-popover';\nimport { ComposedPrivateInserter as PrivateInserter } from './components/inserter';\nimport { PrivateListView } from './components/list-view';\nimport BlockInfo from './components/block-info-slot-fill';\nimport { useShouldContextualToolbarShow } from './utils/use-should-contextual-toolbar-show';\nimport { cleanEmptyObject } from './hooks/utils';\nimport { useBlockEditingMode } from './components/block-editing-mode';\nimport BlockQuickNavigation from './components/block-quick-navigation';\nimport { LayoutStyle } from './components/block-list/layout';\nimport { BlockRemovalWarningModal } from './components/block-removal-warning-modal';\nimport { useLayoutClasses, useLayoutStyles } from './hooks';\nimport DimensionsTool from './components/dimensions-tool';\nimport ResolutionTool from './components/resolution-tool';\n\n/**\n * Private @wordpress/block-editor APIs.\n */\nexport const privateApis = {};\nlock( privateApis, {\n\t...globalStyles,\n\tExperimentalBlockEditorProvider,\n\tgetRichTextValues,\n\tPrivateInserter,\n\tPrivateListView,\n\tResizableBoxPopover,\n\tBlockInfo,\n\tuseShouldContextualToolbarShow,\n\tcleanEmptyObject,\n\tuseBlockEditingMode,\n\tBlockQuickNavigation,\n\tLayoutStyle,\n\tBlockRemovalWarningModal,\n\tuseLayoutClasses,\n\tuseLayoutStyles,\n\tDimensionsTool,\n\tResolutionTool,\n} );\n"]}
1
+ {"version":3,"sources":["@wordpress/block-editor/src/private-apis.js"],"names":["globalStyles","ExperimentalBlockEditorProvider","lock","getRichTextValues","ResizableBoxPopover","ComposedPrivateInserter","PrivateInserter","PrivateListView","BlockInfo","useShouldContextualToolbarShow","cleanEmptyObject","useBlockEditingMode","BlockQuickNavigation","LayoutStyle","BlockRemovalWarningModal","useLayoutClasses","useLayoutStyles","DimensionsTool","ResolutionTool","privateApis"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,KAAKA,YAAZ,MAA8B,4BAA9B;AACA,SAASC,+BAAT,QAAgD,uBAAhD;AACA,SAASC,IAAT,QAAqB,eAArB;AACA,SAASC,iBAAT,QAAkC,6CAAlC;AACA,OAAOC,mBAAP,MAAgC,oCAAhC;AACA,SAASC,uBAAuB,IAAIC,eAApC,QAA2D,uBAA3D;AACA,SAASC,eAAT,QAAgC,wBAAhC;AACA,OAAOC,SAAP,MAAsB,mCAAtB;AACA,SAASC,8BAAT,QAA+C,4CAA/C;AACA,SAASC,gBAAT,QAAiC,eAAjC;AACA,SAASC,mBAAT,QAAoC,iCAApC;AACA,OAAOC,oBAAP,MAAiC,qCAAjC;AACA,SAASC,WAAT,QAA4B,gCAA5B;AACA,SAASC,wBAAT,QAAyC,0CAAzC;AACA,SAASC,gBAAT,EAA2BC,eAA3B,QAAkD,SAAlD;AACA,OAAOC,cAAP,MAA2B,8BAA3B;AACA,OAAOC,cAAP,MAA2B,8BAA3B;AAEA;AACA;AACA;;AACA,OAAO,MAAMC,WAAW,GAAG,EAApB;AACPjB,IAAI,CAAEiB,WAAF,EAAe,EAClB,GAAGnB,YADe;AAElBC,EAAAA,+BAFkB;AAGlBE,EAAAA,iBAHkB;AAIlBG,EAAAA,eAJkB;AAKlBC,EAAAA,eALkB;AAMlBH,EAAAA,mBANkB;AAOlBI,EAAAA,SAPkB;AAQlBC,EAAAA,8BARkB;AASlBC,EAAAA,gBATkB;AAUlBC,EAAAA,mBAVkB;AAWlBC,EAAAA,oBAXkB;AAYlBC,EAAAA,WAZkB;AAalBC,EAAAA,wBAbkB;AAclBC,EAAAA,gBAdkB;AAelBC,EAAAA,eAfkB;AAgBlBC,EAAAA,cAhBkB;AAiBlBC,EAAAA;AAjBkB,CAAf,CAAJ","sourcesContent":["/**\n * Internal dependencies\n */\nimport * as globalStyles from './components/global-styles';\nimport { ExperimentalBlockEditorProvider } from './components/provider';\nimport { lock } from './lock-unlock';\nimport { getRichTextValues } from './components/rich-text/get-rich-text-values';\nimport ResizableBoxPopover from './components/resizable-box-popover';\nimport { ComposedPrivateInserter as PrivateInserter } from './components/inserter';\nimport { PrivateListView } from './components/list-view';\nimport BlockInfo from './components/block-info-slot-fill';\nimport { useShouldContextualToolbarShow } from './utils/use-should-contextual-toolbar-show';\nimport { cleanEmptyObject } from './hooks/utils';\nimport { useBlockEditingMode } from './components/block-editing-mode';\nimport BlockQuickNavigation from './components/block-quick-navigation';\nimport { LayoutStyle } from './components/block-list/layout';\nimport { BlockRemovalWarningModal } from './components/block-removal-warning-modal';\nimport { useLayoutClasses, useLayoutStyles } from './hooks';\nimport DimensionsTool from './components/dimensions-tool';\nimport ResolutionTool from './components/resolution-tool';\n\n/**\n * Private @wordpress/block-editor APIs.\n */\nexport const privateApis = {};\nlock( privateApis, {\n\t...globalStyles,\n\tExperimentalBlockEditorProvider,\n\tgetRichTextValues,\n\tPrivateInserter,\n\tPrivateListView,\n\tResizableBoxPopover,\n\tBlockInfo,\n\tuseShouldContextualToolbarShow,\n\tcleanEmptyObject,\n\tuseBlockEditingMode,\n\tBlockQuickNavigation,\n\tLayoutStyle,\n\tBlockRemovalWarningModal,\n\tuseLayoutClasses,\n\tuseLayoutStyles,\n\tDimensionsTool,\n\tResolutionTool,\n} );\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/block-editor",
3
- "version": "12.3.5",
3
+ "version": "12.3.6",
4
4
  "description": "Generic block editor.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -38,7 +38,7 @@
38
38
  "@wordpress/api-fetch": "^6.32.1",
39
39
  "@wordpress/blob": "^3.35.1",
40
40
  "@wordpress/blocks": "^12.12.3",
41
- "@wordpress/components": "^25.1.5",
41
+ "@wordpress/components": "^25.1.6",
42
42
  "@wordpress/compose": "^6.12.1",
43
43
  "@wordpress/data": "^9.5.3",
44
44
  "@wordpress/date": "^4.35.1",
@@ -54,9 +54,9 @@
54
54
  "@wordpress/keyboard-shortcuts": "^4.12.3",
55
55
  "@wordpress/keycodes": "^3.35.1",
56
56
  "@wordpress/notices": "^4.3.3",
57
- "@wordpress/preferences": "^3.12.5",
57
+ "@wordpress/preferences": "^3.12.6",
58
58
  "@wordpress/private-apis": "^0.17.1",
59
- "@wordpress/rich-text": "^6.12.3",
59
+ "@wordpress/rich-text": "^6.12.4",
60
60
  "@wordpress/shortcode": "^3.35.1",
61
61
  "@wordpress/style-engine": "^1.18.1",
62
62
  "@wordpress/token-list": "^2.35.1",
@@ -85,5 +85,5 @@
85
85
  "publishConfig": {
86
86
  "access": "public"
87
87
  },
88
- "gitHead": "3eeb607ebb76c3bf06cb8acb462f0dc068f340f9"
88
+ "gitHead": "86ecd96b3bcada6b4cc35bb2455b3029cebb0ff3"
89
89
  }
@@ -11,7 +11,6 @@ import {
11
11
  createPortal,
12
12
  forwardRef,
13
13
  useMemo,
14
- useReducer,
15
14
  useEffect,
16
15
  } from '@wordpress/element';
17
16
  import { __ } from '@wordpress/i18n';
@@ -78,29 +77,6 @@ function bubbleEvents( doc ) {
78
77
  }
79
78
  }
80
79
 
81
- function useParsedAssets( html ) {
82
- return useMemo( () => {
83
- const doc = document.implementation.createHTMLDocument( '' );
84
- doc.body.innerHTML = html;
85
- return Array.from( doc.body.children );
86
- }, [ html ] );
87
- }
88
-
89
- async function loadScript( head, { id, src } ) {
90
- return new Promise( ( resolve, reject ) => {
91
- const script = head.ownerDocument.createElement( 'script' );
92
- script.id = id;
93
- if ( src ) {
94
- script.src = src;
95
- script.onload = () => resolve();
96
- script.onerror = () => reject();
97
- } else {
98
- resolve();
99
- }
100
- head.appendChild( script );
101
- } );
102
- }
103
-
104
80
  function Iframe( {
105
81
  contentRef,
106
82
  children,
@@ -112,21 +88,22 @@ function Iframe( {
112
88
  forwardedRef: ref,
113
89
  ...props
114
90
  } ) {
115
- const assets = useSelect(
91
+ const { styles = '', scripts = '' } = useSelect(
116
92
  ( select ) =>
117
93
  select( blockEditorStore ).getSettings().__unstableResolvedAssets,
118
94
  []
119
95
  );
120
- const [ , forceRender ] = useReducer( () => ( {} ) );
121
96
  const [ iframeDocument, setIframeDocument ] = useState();
122
97
  const [ bodyClasses, setBodyClasses ] = useState( [] );
123
98
  const compatStyles = useCompatibilityStyles();
124
- const scripts = useParsedAssets( assets?.scripts );
125
99
  const clearerRef = useBlockSelectionClearer();
126
100
  const [ before, writingFlowRef, after ] = useWritingFlow();
127
101
  const [ contentResizeListener, { height: contentHeight } ] =
128
102
  useResizeObserver();
129
103
  const setRef = useRefEffect( ( node ) => {
104
+ node._load = () => {
105
+ setIframeDocument( node.contentDocument );
106
+ };
130
107
  let iFrameDocument;
131
108
  // Prevent the default browser action for files dropped outside of dropzones.
132
109
  function preventFileDropDefault( event ) {
@@ -138,7 +115,6 @@ function Iframe( {
138
115
  iFrameDocument = contentDocument;
139
116
 
140
117
  bubbleEvents( contentDocument );
141
- setIframeDocument( contentDocument );
142
118
  clearerRef( documentElement );
143
119
 
144
120
  // Ideally ALL classes that are added through get_body_class should
@@ -154,7 +130,6 @@ function Iframe( {
154
130
  );
155
131
 
156
132
  contentDocument.dir = ownerDocument.dir;
157
- documentElement.removeChild( contentDocument.body );
158
133
 
159
134
  for ( const compatStyle of compatStyles ) {
160
135
  if ( contentDocument.getElementById( compatStyle.id ) ) {
@@ -199,35 +174,29 @@ function Iframe( {
199
174
  };
200
175
  }, [] );
201
176
 
202
- const headRef = useRefEffect( ( element ) => {
203
- scripts
204
- .reduce(
205
- ( promise, script ) =>
206
- promise.then( () => loadScript( element, script ) ),
207
- Promise.resolve()
208
- )
209
- .finally( () => {
210
- // When script are loaded, re-render blocks to allow them
211
- // to initialise.
212
- forceRender();
213
- } );
214
- }, [] );
215
177
  const disabledRef = useDisabled( { isDisabled: ! readonly } );
216
178
  const bodyRef = useMergeRefs( [
217
179
  contentRef,
218
180
  clearerRef,
219
181
  writingFlowRef,
220
182
  disabledRef,
221
- headRef,
222
183
  ] );
223
184
 
224
185
  // Correct doctype is required to enable rendering in standards
225
186
  // mode. Also preload the styles to avoid a flash of unstyled
226
187
  // content.
227
- const html =
228
- '<!doctype html>' +
229
- '<style>html{height:auto!important;min-height:100%;}body{margin:0}</style>' +
230
- ( assets?.styles ?? '' );
188
+ const html = `<!doctype html>
189
+ <html>
190
+ <head>
191
+ <script>window.frameElement._load()</script>
192
+ <style>html{height:auto!important;min-height:100%;}body{margin:0}</style>
193
+ ${ styles }
194
+ ${ scripts }
195
+ </head>
196
+ <body>
197
+ <script>document.currentScript.parentElement.remove()</script>
198
+ </body>
199
+ </html>`;
231
200
 
232
201
  const [ src, cleanup ] = useMemo( () => {
233
202
  const _src = URL.createObjectURL(
@@ -2,11 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { RawHTML } from '@wordpress/element';
5
- import {
6
- children as childrenSource,
7
- getSaveElement,
8
- __unstableGetBlockProps as getBlockProps,
9
- } from '@wordpress/blocks';
5
+ import { children as childrenSource } from '@wordpress/blocks';
10
6
  import deprecated from '@wordpress/deprecated';
11
7
 
12
8
  /**
@@ -42,44 +38,3 @@ export const Content = ( { value, tagName: Tag, multiline, ...props } ) => {
42
38
 
43
39
  return content;
44
40
  };
45
-
46
- Content.__unstableIsRichTextContent = {};
47
-
48
- function findContent( blocks, richTextValues = [] ) {
49
- if ( ! Array.isArray( blocks ) ) {
50
- blocks = [ blocks ];
51
- }
52
-
53
- for ( const block of blocks ) {
54
- if (
55
- block?.type?.__unstableIsRichTextContent ===
56
- Content.__unstableIsRichTextContent
57
- ) {
58
- richTextValues.push( block.props.value );
59
- continue;
60
- }
61
-
62
- if ( block?.props?.children ) {
63
- findContent( block.props.children, richTextValues );
64
- }
65
- }
66
-
67
- return richTextValues;
68
- }
69
-
70
- function _getSaveElement( { name, attributes, innerBlocks } ) {
71
- return getSaveElement(
72
- name,
73
- attributes,
74
- innerBlocks.map( _getSaveElement )
75
- );
76
- }
77
-
78
- export function getRichTextValues( blocks = [] ) {
79
- getBlockProps.skipFilters = true;
80
- const values = findContent(
81
- ( Array.isArray( blocks ) ? blocks : [ blocks ] ).map( _getSaveElement )
82
- );
83
- getBlockProps.skipFilters = false;
84
- return values;
85
- }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { RawHTML, StrictMode, Fragment } from '@wordpress/element';
5
+ import {
6
+ getSaveElement,
7
+ __unstableGetBlockProps as getBlockProps,
8
+ } from '@wordpress/blocks';
9
+
10
+ /**
11
+ * Internal dependencies
12
+ */
13
+ import InnerBlocks from '../inner-blocks';
14
+ import { Content } from './content';
15
+
16
+ /*
17
+ * This function is similar to `@wordpress/element`'s `renderToString` function,
18
+ * except that it does not render the elements to a string, but instead collects
19
+ * the values of all rich text `Content` elements.
20
+ */
21
+ function addValuesForElement( element, ...args ) {
22
+ if ( null === element || undefined === element || false === element ) {
23
+ return;
24
+ }
25
+
26
+ if ( Array.isArray( element ) ) {
27
+ return addValuesForElements( element, ...args );
28
+ }
29
+
30
+ switch ( typeof element ) {
31
+ case 'string':
32
+ case 'number':
33
+ return;
34
+ }
35
+
36
+ const { type, props } = element;
37
+
38
+ switch ( type ) {
39
+ case StrictMode:
40
+ case Fragment:
41
+ return addValuesForElements( props.children, ...args );
42
+ case RawHTML:
43
+ return;
44
+ case InnerBlocks.Content:
45
+ return addValuesForBlocks( ...args );
46
+ case Content:
47
+ const [ values ] = args;
48
+ values.push( props.value );
49
+ return;
50
+ }
51
+
52
+ switch ( typeof type ) {
53
+ case 'string':
54
+ if ( typeof props.children !== 'undefined' ) {
55
+ return addValuesForElements( props.children, ...args );
56
+ }
57
+ return;
58
+ case 'function':
59
+ if (
60
+ type.prototype &&
61
+ typeof type.prototype.render === 'function'
62
+ ) {
63
+ return addValuesForElement(
64
+ new type( props ).render(),
65
+ ...args
66
+ );
67
+ }
68
+
69
+ return addValuesForElement( type( props ), ...args );
70
+ }
71
+ }
72
+
73
+ function addValuesForElements( children, ...args ) {
74
+ children = Array.isArray( children ) ? children : [ children ];
75
+
76
+ for ( let i = 0; i < children.length; i++ ) {
77
+ addValuesForElement( children[ i ], ...args );
78
+ }
79
+ }
80
+
81
+ function addValuesForBlocks( values, blocks ) {
82
+ for ( let i = 0; i < blocks.length; i++ ) {
83
+ const { name, attributes, innerBlocks } = blocks[ i ];
84
+ const saveElement = getSaveElement( name, attributes );
85
+ addValuesForElement( saveElement, values, innerBlocks );
86
+ }
87
+ }
88
+
89
+ export function getRichTextValues( blocks = [] ) {
90
+ getBlockProps.skipFilters = true;
91
+ const values = [];
92
+ addValuesForBlocks( values, blocks );
93
+ getBlockProps.skipFilters = false;
94
+ return values;
95
+ }
@@ -4,7 +4,7 @@
4
4
  import * as globalStyles from './components/global-styles';
5
5
  import { ExperimentalBlockEditorProvider } from './components/provider';
6
6
  import { lock } from './lock-unlock';
7
- import { getRichTextValues } from './components/rich-text/content';
7
+ import { getRichTextValues } from './components/rich-text/get-rich-text-values';
8
8
  import ResizableBoxPopover from './components/resizable-box-popover';
9
9
  import { ComposedPrivateInserter as PrivateInserter } from './components/inserter';
10
10
  import { PrivateListView } from './components/list-view';