Skip to content
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

Zero dependency (vanilla js) #172

Closed
abalter opened this issue Jan 11, 2023 · 11 comments · Fixed by #174
Closed

Zero dependency (vanilla js) #172

abalter opened this issue Jan 11, 2023 · 11 comments · Fixed by #174
Labels
inprogress vanillajs Support plain-old JS/TS

Comments

@abalter
Copy link

abalter commented Jan 11, 2023

Does "zero dependency" mean it can run as a vanilla js library?

Is there an example of how to do that?

@mathuo
Copy link
Owner

mathuo commented Jan 12, 2023

Currently dockview is specifically designed for use with React. Dockview has zero dependencies but it does have a peer dependency on the react and react-dom libraries.

Although, the entire project is written in vanilla js and exposes a react layer on top for people to use. It would easily work in vanilla js if the react peer dependency could be isolated. Let me take a look at this and see if I can provide an example of using dockview using only vanilla js.

@mathuo mathuo changed the title Zero dependency Zero dependency (vanilla js) Jan 18, 2023
@mathuo mathuo linked a pull request Jan 18, 2023 that will close this issue
@mathuo
Copy link
Owner

mathuo commented Feb 12, 2023

Progress Update

I've published an experimental build to npm under the experimental tag 0.0.0-experimental-ff3f0b23-20230207.

There are numerous issues with this still but I wanted to show where I was at on this. It's very reasonable to assume dockview can support Vanilla JS/TS (and I believe it would be a benefit to have) since the core of the library is written in plain TypeScript with the React components simply wrappers on top of that core logic.

The sandbox example here shows a "running example" (not necessarily a working example) written in plain TypeScript. As you will see there are issues:

  1. The interface simply isn't clear. You need to implement the IContentRenderer interface to provide your own panel but this interface isn't "clean" enough for public use. I will need to work on cleaning this interface, making the purpose of the methods clearer and reducing the number of required methods to implement to a minimum. Additionally documentation will need to be written for usage with Vanilla JS/TS.

For example in the React version there is an implementation of this interface with the React world which you can see here

  1. Some of the required types in the TypeScript world are not exposed correctly which you will see as errors in the sandbox.

  2. dockview has a peer dependency on react and react-dom. To circumvent this causing compliation issues (if you import anything from dockview you as a by-product will import things from react and react-dom) I've seperated and isolated the react code and you can avoid importing this section of the code by importing from dockview/dist/cjs/core rather than dockview (which in itself is a big usability problem that needs fixing). To address this the library would probably need to be split into two seperate packages, one contains the core contents and another that exposes only the react wrappers that has a peer dependency to the core package.

You can see the isolation of code in this file.

I will be looking into these issues but I can't really give a hard timeline currently, however the message here is that I do intend to support Vanilla JS/TS in the near future.

@abalter
Copy link
Author

abalter commented Feb 22, 2023

I wonder if something in the spirit of this would be possible:

<html>
<head>
    <link type="text/css" rel="stylesheet" href="link to dockview.css">
    <script type="text/javascript" src="cdn for jquery">
    <script type="text/javascript" src="cdn for react">
    <script type="text/javascript" src="link to a single file with no dependencies other than react and maybe jquery dockview.min.js">
<head>
<html>
    <body>
        <div class="dockview-div"></div>
        <script>
            dock = new DockView("dockview-div")
            dock
                .addPanel(title="Panel1", location="top-left", width=0.5, height=0.5)
                .addPanel(title = "Panel2", location="top-right", width=0.5)
                .addPanel(title = "Panel3", location='bottom', width=1.0)
        </script>
    <body>
<html>

Or, to follow an existing paradigm, something like this: https://www.jqwidgets.com/jquery-widgets-documentation/documentation/jqxdockinglayout/jquery-docking-layout-getting-started.htm?search=

@mathuo mathuo added the vanillajs Support plain-old JS/TS label Feb 28, 2023
@mathuo mathuo reopened this Mar 6, 2023
@mathuo
Copy link
Owner

mathuo commented Apr 3, 2023

Moving this under the Discussions section here.

@abalter
Copy link
Author

abalter commented Oct 6, 2023

Hi @mathuo. This example (linked to in the discussion referenced above) uses both react and typescript. Is it actually possible in vanilla JS?

index.tsx

import { StrictMode } from 'react';
import * as ReactDOMClient from 'react-dom/client';
import './styles.css';
import 'dockview/dist/styles/dockview.css';

import App from './app';

const rootElement = document.getElementById('root');

if (rootElement) {
    const root = ReactDOMClient.createRoot(rootElement);

    root.render(
        <StrictMode>
            <div className="app">
                <App />
            </div>
        </StrictMode>
    );
}

@abalter
Copy link
Author

abalter commented Oct 6, 2023

I see now there is a drop-down on the example for a javascript version. However that still isn't vanilla javascript.

@mathuo mathuo reopened this Oct 6, 2023
@mathuo
Copy link
Owner

mathuo commented Oct 6, 2023

I see now there is a drop-down on the example for a javascript version. However that still isn't vanilla javascript.

What are you defining as vanilla javascript?

@abalter
Copy link
Author

abalter commented Oct 6, 2023

index.html

<html>
    <head>
        <script src="js/main_library.js"></script>
        <link rel="stylesheet" href="css/styles.css">
    </head>
    <body>
        <div id="the-div-for-the-app"></div>
        <script src="js/custom-script-for-myapp.js"></script>
    </body>
</html>

Here is a (really bad) web app that uses an extensive and complex pure-javascript widget library. I use the library by loading a single javascript file.

https://arielbalter.org/session-practice/

@abalter
Copy link
Author

abalter commented Oct 6, 2023

Overall, I like dock-view the best in terms of functionality and appearance. But there are a number of pure-js libraries that require only loading a single library file. Also, some are not FOSS, for example JQWidgets. Dock Spawn TS is a pure JS library (no react) but not something you can link to as a single file.

What would be really awesome is an algorithm to drag and dock jspanel objects.

@eclipse313
Copy link

I'm speaking for the Vue community here. It would be great if there was also a Vue version of this. Especially since dockview-core is not related to React, this should be possible in principle.

I've just had a look at the source code, but I'm struggling a bit with porting the React portal stuff to Vue.

Can anyone help?

@mathuo mathuo linked a pull request Nov 8, 2023 that will close this issue
@mathuo
Copy link
Owner

mathuo commented Mar 31, 2024

Moving discussion to here

@yoshiok @eclipse313

@mathuo mathuo closed this as completed Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inprogress vanillajs Support plain-old JS/TS
Projects
None yet
3 participants