-
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.
- Loading branch information
1 parent
dea63f4
commit 3c99206
Showing
11 changed files
with
1,684 additions
and
1,251 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
289 changes: 289 additions & 0 deletions
289
embedded-components/.demo/html-js/EBComponentsWithReact.umd.js
Large diffs are not rendered by default.
Oops, something went wrong.
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,20 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Embedded Components demo - HTML+JS</title> | ||
</head> | ||
<body> | ||
<div id="component-container" style="border: 1px solid black; padding: 4px; width: 300px"></div> | ||
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js" | ||
></script> | ||
<script src="./EBComponents.umd.cjs"></script> | ||
<!-- <script type="module" src="./EBComponentsWithReact.umd.js"></script> --> | ||
<script type="module"> | ||
const EBComponentsManager = EBComponents.initEBComponentsManager(); | ||
EBComponentsManager.mountComponent('LinkAccountForm', null, 'component-container'); | ||
</script> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface EBConfig { | ||
apiBaseUrl: string; | ||
} |
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,54 @@ | ||
import React from 'react'; | ||
import ReactDOMClient from 'react-dom/client'; | ||
import { EBComponentsProvider } from '@/shared/EBComponentsProvider'; | ||
import { EBConfig } from '@/types'; | ||
import { componentRegistry, ComponentRegistry } from './componentRegistry'; | ||
|
||
class EBComponentsManager { | ||
private config: EBConfig; | ||
private components: ComponentRegistry; | ||
private roots: Map<string, ReactDOMClient.Root>; | ||
|
||
constructor(config: EBConfig) { | ||
this.config = config; | ||
this.components = componentRegistry; | ||
this.roots = new Map(); | ||
} | ||
|
||
public mountComponent( | ||
componentName: keyof ComponentRegistry, | ||
props: any, | ||
containerId: string | ||
): void { | ||
const container = document.getElementById(containerId); | ||
if (!container) { | ||
console.error(`Container #${containerId} not found`); | ||
return; | ||
} | ||
|
||
const Component = this.components[componentName]; | ||
if (Component) { | ||
const root = ReactDOMClient.createRoot(container); | ||
root.render( | ||
<EBComponentsProvider theme={{}}> | ||
<Component {...props} /> | ||
</EBComponentsProvider> | ||
); | ||
this.roots.set(containerId, root); | ||
} else { | ||
console.error(`Component ${componentName} not found`); | ||
} | ||
} | ||
|
||
public unmountComponent(containerId: string): void { | ||
const root = this.roots.get(containerId); | ||
if (root) { | ||
root.unmount(); | ||
this.roots.delete(containerId); | ||
} else { | ||
console.error(`No mounted component found in #${containerId}`); | ||
} | ||
} | ||
} | ||
|
||
export const initEBComponentsManager = (config: EBConfig) => new EBComponentsManager(config); |
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,7 @@ | ||
import { LinkAccountForm } from '@/components/LinkAccountForm/LinkAccountForm'; | ||
|
||
export const componentRegistry = { | ||
LinkAccountForm, | ||
}; | ||
|
||
export type ComponentRegistry = typeof componentRegistry; |
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,30 +1,38 @@ | ||
import { resolve } from 'path'; | ||
import { defineConfig } from 'vite'; | ||
import { defineConfig, loadEnv } from 'vite'; | ||
import react from '@vitejs/plugin-react'; | ||
import tsconfigPaths from 'vite-tsconfig-paths'; | ||
import dts from 'vite-plugin-dts'; | ||
import { libInjectCss } from 'vite-plugin-lib-inject-css'; | ||
|
||
export default defineConfig({ | ||
plugins: [react(), tsconfigPaths(), dts({ rollupTypes: true })], | ||
test: { | ||
globals: true, | ||
environment: 'jsdom', | ||
setupFiles: './vitest.setup.mjs', | ||
}, | ||
build: { | ||
lib: { | ||
entry: resolve(__dirname, 'src/index.tsx'), | ||
name: 'Embedded Banking Components', | ||
fileName: 'index', | ||
export default defineConfig(({ mode }) => { | ||
const env = loadEnv(mode, process.cwd()); | ||
return { | ||
plugins: [react(), tsconfigPaths(), dts({ rollupTypes: true }), libInjectCss()], | ||
test: { | ||
globals: true, | ||
environment: 'jsdom', | ||
setupFiles: './vitest.setup.mjs', | ||
}, | ||
rollupOptions: { | ||
external: ['react', 'react-dom'], | ||
output: { | ||
globals: { | ||
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
build: { | ||
lib: { | ||
entry: [resolve(__dirname, 'src/index.tsx')], | ||
name: 'EBComponents', | ||
formats: ['es', 'umd'], | ||
fileName: 'EBComponents', | ||
}, | ||
rollupOptions: { | ||
external: ['react', 'react-dom'], | ||
output: { | ||
globals: { | ||
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
define: { | ||
'process.env': env, | ||
}, | ||
}; | ||
}); |
Oops, something went wrong.