-
Notifications
You must be signed in to change notification settings - Fork 798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map block: fix script loading to work with FSE #19552
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c2938ee
Initial proof of concept in loading vendor files into main window or …
b1b5d18
use correct document to create new elements
d68f4d6
Add webpack plugin to copy 3rd party scripts to build dir
df10149
Remove unused import
f8d0b9d
fix issue with callbacks running before mapbox-gl object instansiated
36fb8bb
Add a waitForObject method to have a standard way of waiting for requ…
1ef9d44
fix window reference
c2af10d
Add 3rd party asset loading methods
cceb949
Fix issue with block sizing and missing map markers
b5fe73e
Add changelog and doc comments
98a3342
Add missing doc comment
9946a98
Add missing dependency
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Significance: patch | ||
Type: compat | ||
Comment: Fixes to make the Map block compatible with full site editing | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
projects/plugins/jetpack/extensions/blocks/map/block-editor-assets.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"id": "mapbox-gl-js", | ||
"file": "node_modules/mapbox-gl/dist/mapbox-gl.js", | ||
"version": "1.13.0" | ||
}, | ||
{ | ||
"id": "mapbox-gl-css", | ||
"file": "node_modules/mapbox-gl/dist/mapbox-gl.css", | ||
"version": "1.13.0" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
projects/plugins/jetpack/tools/copy-block-editor-assets.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const fs = require( 'fs-extra' ); | ||
const glob = require( 'glob' ); | ||
const path = require( 'path' ); | ||
|
||
const PLUGIN_NAME = 'CopyEditorAssetsPlugin'; | ||
const EXPORT_PATH = '_inc/blocks/editor-assets'; | ||
|
||
module.exports = class CopyBlockEditorAssetsPlugin { | ||
apply( compiler ) { | ||
const logger = compiler.getInfrastructureLogger( PLUGIN_NAME ); | ||
logger.log( 'Starting copy of block editor assets' ); | ||
compiler.hooks.shouldEmit.tap( 'CopyPlugin_Custom', () => { | ||
/** | ||
* Checks that the export dir exists and creates if not. | ||
*/ | ||
async function makeDir() { | ||
await fs.mkdirp( path.resolve( EXPORT_PATH ) ); | ||
} | ||
/** | ||
* Copies an asset file into the assets export folder. | ||
* | ||
* @param {string} source - The source file to copy. | ||
* @param {string} dest - The destination location for file. | ||
*/ | ||
async function copyFile( source, dest ) { | ||
await makeDir(); | ||
const source_final = path.resolve( source ); | ||
const dest_final = path.resolve( dest ); | ||
|
||
fs.copyFile( source_final, dest_final, function ( err ) { | ||
if ( err ) { | ||
logger.error( err ); | ||
} | ||
} ); | ||
} | ||
|
||
glob( 'extensions/blocks/**/block-editor-assets.json', {}, function ( er, files ) { | ||
files.forEach( file => { | ||
const resources = require( path.resolve( file ) ); | ||
resources.forEach( resource => { | ||
const source = path.resolve( resource.file ); | ||
const filename = path.basename( source, path.extname( source ) ); | ||
const ext = path.extname( source ); | ||
const dest = `${ path.resolve( EXPORT_PATH ) }/${ filename }-${ | ||
resource.version | ||
}${ ext }`; | ||
copyFile( source, dest ); | ||
} ); | ||
} ); | ||
} ); | ||
} ); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8114,6 +8114,15 @@ fs-constants@^1.0.0: | |
resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad" | ||
integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow== | ||
|
||
[email protected]: | ||
version "10.0.0" | ||
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1" | ||
integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ== | ||
dependencies: | ||
graceful-fs "^4.2.0" | ||
jsonfile "^6.0.1" | ||
universalify "^2.0.0" | ||
|
||
fs-minipass@^1.2.5: | ||
version "1.2.6" | ||
resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.6.tgz#2c5cc30ded81282bfe8a0d7c7c1853ddeb102c07" | ||
|
@@ -8548,6 +8557,11 @@ graceful-fs@^4.1.4: | |
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.2.tgz#6f0952605d0140c1cfdb138ed005775b92d67b02" | ||
integrity sha512-IItsdsea19BoLC7ELy13q1iJFNmd7ofZH5+X/pJr90/nRoPEX0DJo1dHDbgtYWOhJhcCgMDTOw84RZ72q6lB+Q== | ||
|
||
graceful-fs@^4.2.0: | ||
version "4.2.6" | ||
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.6.tgz#ff040b2b0853b23c3d31027523706f1885d76bee" | ||
integrity sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ== | ||
|
||
graceful-fs@^4.2.2, graceful-fs@^4.2.4: | ||
version "4.2.4" | ||
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb" | ||
|
@@ -10637,6 +10651,15 @@ json5@^2.1.2: | |
dependencies: | ||
minimist "^1.2.5" | ||
|
||
jsonfile@^6.0.1: | ||
version "6.1.0" | ||
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae" | ||
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ== | ||
dependencies: | ||
universalify "^2.0.0" | ||
optionalDependencies: | ||
graceful-fs "^4.1.6" | ||
|
||
jsprim@^1.2.2: | ||
version "1.4.1" | ||
resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2" | ||
|
@@ -16289,6 +16312,11 @@ unique-stream@^2.0.2: | |
json-stable-stringify-without-jsonify "^1.0.1" | ||
through2-filter "^3.0.0" | ||
|
||
universalify@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" | ||
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== | ||
|
||
unquote@~1.1.1: | ||
version "1.1.1" | ||
resolved "https://registry.yarnpkg.com/unquote/-/unquote-1.1.1.tgz#8fded7324ec6e88a0ff8b905e7c098cdc086d544" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that by default Webpack dynamic imports are
lazy
, i.e. loaded asynchronously. Just noting in case you wanna ensure the same loading method with<script async>
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. With the way this is currently setup the script tag is not injected into the iframe header until after the page has loaded so adding async may not make any difference, but will do some double checking on that.