-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove duplication in projects (#195)
Allow a single CSS import. When possible, fill the HTML with shared code. In all projects, add link to the bundler/tool in the title.
- Loading branch information
Showing
14 changed files
with
64 additions
and
104 deletions.
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,4 @@ | ||
@import url('@maxgraph/core/css/common.css'); | ||
|
||
@import url('./rubber-band.css'); | ||
@import url('./general-style.css'); |
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,26 @@ | ||
import {Client} from "@maxgraph/core"; | ||
|
||
/** Display the maxGraph version in the footer. */ | ||
const fillFooter = (): void => { | ||
const footer = document.querySelector<HTMLElement>('footer')!; | ||
footer.innerText = `Built with maxGraph ${Client.VERSION}`; | ||
}; | ||
|
||
export type FillMainContainerOptions = { | ||
toolName: string; | ||
toolUrl: string; | ||
}; | ||
|
||
export const fillMainContainerInnerHtml = (cssSelector: string, options: FillMainContainerOptions): void => { | ||
document.querySelector<HTMLDivElement>(cssSelector)!.innerHTML = ` | ||
<h1>maxGraph <a href="${options.toolUrl}" target="_blank" rel="noopener noreferrer">${options.toolName}</a> TypeScript example</h1> | ||
<p>Display a test graph. Activated behaviours:</p> | ||
<ul> | ||
<li>Panning: use mouse right button</li> | ||
<li>Cells selection with Rubberband: use mouse left button</li> | ||
</ul> | ||
<div id="graph-container"></div> | ||
<footer></footer> | ||
`; | ||
fillFooter(); | ||
}; |
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 |
---|---|---|
@@ -1 +1,9 @@ | ||
import { initializeGraph } from './generate-graph'; | ||
import {fillMainContainerInnerHtml, FillMainContainerOptions} from "./fill-html-content"; | ||
|
||
export {initializeGraph} from './generate-graph'; | ||
|
||
export const initializeHtmlAndGraph = (cssSelector: string, options: FillMainContainerOptions): void => { | ||
fillMainContainerInnerHtml(cssSelector, options); | ||
initializeGraph(); | ||
}; |
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 |
---|---|---|
@@ -1,23 +1,4 @@ | ||
import '@maxgraph/core/css/common.css'; | ||
import 'maxgraph-examples-shared/css/rubber-band.css' | ||
import 'maxgraph-examples-shared/css/general-style.css' | ||
import 'maxgraph-examples-shared/css/all.css'; | ||
import {initializeHtmlAndGraph} from 'maxgraph-examples-shared'; | ||
|
||
import {Client} from "@maxgraph/core"; | ||
import {initializeGraph} from 'maxgraph-examples-shared'; | ||
|
||
document.querySelector<HTMLDivElement>('#app')!.innerHTML = ` | ||
<h1>maxGraph Farm TypeScript example</h1> | ||
<p>Display a test graph. Activated behaviours:</p> | ||
<ul> | ||
<li>Panning: use mouse right button</li> | ||
<li>Cells selection with Rubberband: use mouse left button</li> | ||
</ul> | ||
<div id="graph-container"></div> | ||
<footer></footer> | ||
`; | ||
|
||
const footer = document.querySelector<HTMLElement>('footer')!; | ||
footer.innerText = `Built with maxGraph ${Client.VERSION}`; | ||
|
||
// Creates the graph inside the given container | ||
initializeGraph(<HTMLElement>document.querySelector('#graph-container')); | ||
initializeHtmlAndGraph('#app', {toolName: 'Farm', toolUrl: 'https://www.farmfe.org/'}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,4 @@ | ||
// import './style.css'; currently loaded by the HTML page | ||
import {Client} from '@maxgraph/core'; | ||
import {initializeGraph} from 'maxgraph-examples-shared'; | ||
import {initializeHtmlAndGraph} from 'maxgraph-examples-shared'; | ||
|
||
// display the maxGraph version in the footer | ||
const footer = document.querySelector<HTMLElement>('footer')!; | ||
footer.innerText = `Built with maxGraph ${Client.VERSION}`; | ||
|
||
// Creates the graph inside the given container | ||
const container = document.querySelector<HTMLElement>('#graph-container')!; | ||
|
||
initializeGraph(container); | ||
initializeHtmlAndGraph('#app', {toolName: 'Rollup', toolUrl: 'https://rollupjs.org/'}) |
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 |
---|---|---|
@@ -1,23 +1,4 @@ | ||
import '@maxgraph/core/css/common.css'; | ||
import 'maxgraph-examples-shared/css/rubber-band.css' | ||
import 'maxgraph-examples-shared/css/general-style.css' | ||
import 'maxgraph-examples-shared/css/all.css'; | ||
import {initializeHtmlAndGraph} from 'maxgraph-examples-shared'; | ||
|
||
import {Client} from "@maxgraph/core"; | ||
import {initializeGraph} from 'maxgraph-examples-shared'; | ||
|
||
document.querySelector('#root')!.innerHTML = ` | ||
<h1>maxGraph Rsbuild TypeScript example</h1> | ||
<p>Display a test graph. Activated behaviours:</p> | ||
<ul> | ||
<li>Panning: use mouse right button</li> | ||
<li>Cells selection with Rubberband: use mouse left button</li> | ||
</ul> | ||
<div id="graph-container"></div> | ||
<footer></footer> | ||
`; | ||
|
||
const footer = document.querySelector<HTMLElement>('footer')!; | ||
footer.innerText = `Built with maxGraph ${Client.VERSION}`; | ||
|
||
// Creates the graph inside the given container | ||
initializeGraph(<HTMLElement>document.querySelector('#graph-container')); | ||
initializeHtmlAndGraph('#root', {toolName: 'Rsbuild', toolUrl: 'https://rsbuild.dev/'}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,4 @@ | ||
import '@maxgraph/core/css/common.css'; | ||
import 'maxgraph-examples-shared/css/rubber-band.css' | ||
import 'maxgraph-examples-shared/css/general-style.css' | ||
import 'maxgraph-examples-shared/css/all.css'; | ||
import {initializeHtmlAndGraph} from 'maxgraph-examples-shared'; | ||
|
||
import {Client} from '@maxgraph/core'; | ||
import {initializeGraph} from 'maxgraph-examples-shared'; | ||
|
||
// display the maxGraph version in the footer | ||
const footer = document.querySelector<HTMLElement>('footer')!; | ||
footer.innerText = `Built with maxGraph ${Client.VERSION}`; | ||
|
||
// Creates the graph inside the given container | ||
initializeGraph(<HTMLElement>document.querySelector('#graph-container')); | ||
initializeHtmlAndGraph('#app', {toolName: 'Vite', toolUrl: 'https://vite.dev/'}) |