Automattic / isolated-block-editor

Repackages Gutenberg's editor playground as a full-featured multi-instance editor that does not require WordPress.
343 stars 50 forks source link

Media Library #205

Closed xpalko closed 1 year ago

xpalko commented 1 year ago

Hi,

I have already solved the localization and pattern inserting problem, but I can't figure out how to integrate the image selection via the Media Library (MediaFrame).

The code logically ends with the non-existence of the wp.media function

node_modules/@wordpress/media-utils/src/components/media-upload/index.js:250

this.frame = wp.media( frameConfig );

I am going through the wordpress codes, gutenbergForDrupal but still stuck.

Some idea? Any examples or demos or anything?

Thanks

Pavel Kaspar

johngodley commented 1 year ago

Are you loading the WordPress media library? You will need to do that to use that code, otherwise you will need to supply your own media library.

xpalko commented 1 year ago

No, I'm not uploading any WP component, I'm literally lost in the wordpress code and I can't find any similar solution to this problem on the net :(

Can you point me in right direction how to upload this component?

A thousand thanks!

johngodley commented 1 year ago

You either use the WordPress media library (example https://github.com/Automattic/isolated-block-editor/blob/trunk/examples/wordpress-php/iso-gutenberg.php) or you supply your own media library (https://github.com/Automattic/isolated-block-editor#media-uploader)

xpalko commented 1 year ago

@johngodley I don't want to use any Wordpess components, so I want to write a MediaLibrary myself, but somehow I can't create a media Library button and bind a callback to it. I tried

https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/media-upload/README.md

but no success (probably not the whole code, just an idea).

johngodley commented 1 year ago

There seems to be a working example here:

https://github.com/Automattic/wp-calypso/blob/349d0ceaaf28278165e3a7578e4caade65dd6304/apps/wpcom-block-editor/src/calypso/features/iframe-bridge-server.js#L1148

Media library replacements are not in the scope of this project so if that doesn't help then you might want to ask your question in Gutenberg itself.

xpalko commented 1 year ago

@johngodley Looks good now, thanks!

xpalko commented 1 year ago

@johngodley Great, working!