Git Product home page Git Product logo

Comments (6)

Giwayume avatar Giwayume commented on July 17, 2024 1

Minipaint is all client code. A bunch of js, css, and html file. It doesn't really matter, the only real requirement is that it is served from the same domain that your react code is running on, so the Javascript can communicate across the boundaries of the iframe.

from minipaint.

Giwayume avatar Giwayume commented on July 17, 2024

This is an example of loading and saving images https://github.com/viliusle/miniPaint/blob/master/examples/open-edit-save.html

For React specifically, you can add a ref to the iframe element to retrieve it if you don't want to use the id.

import { useRef, useEffect } from 'react';

export default function ModalEditTemplate() {
    const minipaintIframe = useRef(null);
    const isMinipaintIframeLoaded = useRef(false);
    
    useEffect(() => {
        if (minipaintIframe.current && isMinipaintIframeLoaded.current) {
            // When the iframe ref is populated from the component template,
            // call API to load image...
            const Layers = minipaintIframe.current.contentWindow.Layers;
            const newLayer = {
                // Reference example I linked above
            };
            Layers.insert(newLayer);
        }
    }, []);

    function onMinipaintIframeLoad() {
        isMinipaintIframeLoaded.current = true;
    }

    return (
        <iframe
              ref={minipaintIframe}
              style={{ width: "70vw", height: "70vh" }}
              src={`https://YOURWEBSITE.COM/miniPaint/`}
              allow="camera"
              onLoad={onMinipaintIframeLoad}
        ></iframe>
    );
}

I haven't tested this code, but theoretically it should work. You need to wait for both the ref for the iframe element to be assigned, and for the iframe to load the minipaint page.

from minipaint.

Giwayume avatar Giwayume commented on July 17, 2024

Also, I didn't notice this at first, but you'll need to self-host minipaint on your own server, not reference it from https://viliusle.github.io/.

Javascript won't talk across iframes on different domains.

from minipaint.

exequiel-criss avatar exequiel-criss commented on July 17, 2024

Also, I didn't notice this at first, but you'll need to self-host minipaint on your own server, not reference it from https://viliusle.github.io/.

Javascript won't talk across iframes on different domains.

Thank you very much for your previous response, it has been very helpful to me.
One more question, I have my project separated into client with react and server with strapi (node.js). I have the client hosted on netlify, and the server on railway.
Where should I host mini paint? On railway or on netlify?

from minipaint.

Giwayume avatar Giwayume commented on July 17, 2024

@viliusle may want to consider adding a postMessage API so people can do basic things like load and save images from viliusle.github.io/miniPaint/ without having to self-host.

from minipaint.

geeeeeeeek avatar geeeeeeeek commented on July 17, 2024

from minipaint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.