-
Notifications
You must be signed in to change notification settings - Fork 2
Bundle custom elements (web components) #199
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
08d9182
feat: Add first web component
razor-x e5d3769
Abstract element creation
razor-x 8c28923
Make react-to-web-component dev dep
razor-x 536dbd0
Do not build element source files
razor-x 4dc1239
Add vite react plugin to vite build
razor-x d7ad14b
Remove font link in webcomponent example
razor-x 8fc3a1b
Link to web-components example
razor-x 7cb4e78
Rename element to use tsx
razor-x 2857d5c
Wrap custom element in provider
razor-x 16d50c8
Update element.tsx path in tsconfig.build.json
razor-x 0e1b9e5
Add DeviceTable as element
razor-x 60c6f9d
Update title for web component example
razor-x 82098ae
Remove unused global declare
razor-x 4d549b1
Move type imports outside braces
razor-x 3a25909
Run format
seambot b3c703a
Add missing return type
razor-x f3fc7ea
Set disable-css-injection
razor-x 5d84c8d
Add global injection overrides for elements
razor-x 911be5c
Handle version injection for elements bundle
razor-x 35655ce
Add onBack prop
razor-x 8390285
Add other components custom elements
razor-x 31d93ca
Fix prepack script to handle other files
razor-x 5f159bf
Update elements.ts
razor-x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -5,3 +5,5 @@ interface ImportMeta { | |
SEAM_USER_IDENTIFIER_KEY: string | ||
} | ||
} | ||
|
||
declare module '@seamapi/react/elements.js' {} |
This file contains hidden or 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 hidden or 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,23 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<title>Web components example - Seam React Components</title> | ||
</head> | ||
<body> | ||
<main class="seam-components"> | ||
<seam-device-table | ||
publishable-key="%SEAM_PUBLISHABLE_KEY%" | ||
user-identifier-key="%SEAM_USER_IDENTIFIER_KEY%" | ||
disable-css-injection="true" | ||
></seam-device-table> | ||
<seam-supported-device-table | ||
publishable-key="%SEAM_PUBLISHABLE_KEY%" | ||
user-identifier-key="%SEAM_USER_IDENTIFIER_KEY%" | ||
disable-css-injection="true" | ||
></seam-supported-device-table> | ||
</main> | ||
<script type="module" src="/web-components/src/main.ts"></script> | ||
</body> | ||
</html> |
This file contains hidden or 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,11 @@ | ||
import 'vite/client' | ||
|
||
interface ImportMetaEnv { | ||
readonly SEAM_ENDPOINT: string | ||
readonly SEAM_PUBLISHABLE_KEY: string | ||
readonly SEAM_USER_IDENTIFIER_KEY: string | ||
} | ||
|
||
interface ImportMeta { | ||
readonly env: ImportMetaEnv | ||
} |
This file contains hidden or 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,2 @@ | ||
import '@seamapi/react/index.css' | ||
import '@seamapi/react/elements.js' |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,27 @@ | ||
import { defineCustomElement, type ElementDefinition } from 'lib/element.js' | ||
import * as components from 'lib/seam/components/elements.js' | ||
|
||
const elementDefinitions = components as unknown as Record< | ||
string, | ||
Partial<ElementDefinition> | ||
> | ||
|
||
for (const key of Object.keys(elementDefinitions)) { | ||
const elementDefinition = elementDefinitions[key] | ||
|
||
if (elementDefinition == null) { | ||
throw new Error(`Missing element element definition for ${key}`) | ||
} | ||
|
||
const { name, Component, props } = elementDefinition | ||
|
||
if (name == null) { | ||
throw new Error(`Missing element name for ${key}`) | ||
} | ||
|
||
if (Component == null) { | ||
throw new Error(`Missing element Component for ${key}`) | ||
} | ||
|
||
defineCustomElement({ name, Component, props }) | ||
} |
This file contains hidden or 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,86 @@ | ||
import r2wc from '@r2wc/react-to-web-component' | ||
import type { ComponentType } from 'react' | ||
import type { Container } from 'react-dom' | ||
|
||
import { | ||
SeamProvider, | ||
type SeamProviderPropsWithClientSessionToken, | ||
type SeamProviderPropsWithPublishableKey, | ||
} from 'lib/seam/SeamProvider.js' | ||
|
||
declare global { | ||
// eslint-disable-next-line no-var | ||
var disableSeamCssInjection: boolean | undefined | ||
// eslint-disable-next-line no-var | ||
var disableSeamFontInjection: boolean | undefined | ||
// eslint-disable-next-line no-var | ||
var unminifiySeamCss: boolean | undefined | ||
} | ||
|
||
export interface ElementDefinition { | ||
name: string | ||
Component: Parameters<typeof r2wc>[0] | ||
props?: ElementProps<Record<string, object>> | ||
} | ||
|
||
export type ElementProps<T> = Partial< | ||
Record<keyof T, 'string' | 'number' | 'boolean' | 'function' | 'json'> | ||
> | ||
|
||
type ProviderProps = SeamProviderPropsWithPublishableKey & | ||
SeamProviderPropsWithClientSessionToken | ||
|
||
const providerProps: ElementProps<ProviderProps> = { | ||
publishableKey: 'string', | ||
userIdentifierKey: 'string', | ||
clientSessionToken: 'string', | ||
disableCssInjection: 'boolean', | ||
disableFontInjection: 'boolean', | ||
unminifiyCss: 'boolean', | ||
} | ||
|
||
export const defineCustomElement = ({ | ||
name, | ||
Component, | ||
props = {}, | ||
}: ElementDefinition): void => { | ||
const element = r2wc(withProvider(Component), { | ||
props: { | ||
...props, | ||
...providerProps, | ||
}, | ||
}) | ||
globalThis?.customElements?.define(name, element) | ||
} | ||
|
||
function withProvider<P extends JSX.IntrinsicAttributes>( | ||
Component: ComponentType<P> | ||
) { | ||
razor-x marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ({ | ||
publishableKey, | ||
userIdentifierKey, | ||
clientSessionToken, | ||
disableCssInjection, | ||
disableFontInjection, | ||
unminifiyCss, | ||
container: _container, | ||
...props | ||
}: ProviderProps & { container: Container } & P): JSX.Element | null => { | ||
return ( | ||
<SeamProvider | ||
publishableKey={publishableKey} | ||
userIdentifierKey={userIdentifierKey} | ||
clientSessionToken={clientSessionToken} | ||
disableCssInjection={ | ||
disableCssInjection ?? globalThis.disableSeamCssInjection | ||
} | ||
disableFontInjection={ | ||
disableFontInjection ?? globalThis.disableSeamFontInjection | ||
} | ||
unminifiyCss={unminifiyCss ?? globalThis?.unminifiySeamCss} | ||
> | ||
<Component {...(props as P)} /> | ||
</SeamProvider> | ||
) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/lib/seam/components/AccessCodeDetails/AccessCodeDetails.element.ts
This file contains hidden or 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,12 @@ | ||
import type { ElementProps } from 'lib/element.js' | ||
|
||
import type { AccessCodeDetailsProps } from './AccessCodeDetails.js' | ||
|
||
export const name = 'seam-access-code-details' | ||
|
||
export const props: ElementProps<AccessCodeDetailsProps> = { | ||
accessCodeId: 'string', | ||
onBack: 'function', | ||
} | ||
|
||
export { AccessCodeDetails as Component } from './AccessCodeDetails.js' |
12 changes: 12 additions & 0 deletions
12
src/lib/seam/components/AccessCodeTable/AccessCodeTable.element.ts
This file contains hidden or 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,12 @@ | ||
import type { ElementProps } from 'lib/element.js' | ||
|
||
import type { AccessCodeTableProps } from './AccessCodeTable.js' | ||
|
||
export const name = 'seam-access-code-table' | ||
|
||
export const props: ElementProps<AccessCodeTableProps> = { | ||
deviceId: 'string', | ||
onBack: 'function', | ||
} | ||
|
||
export { AccessCodeTable as Component } from './AccessCodeTable.js' |
12 changes: 12 additions & 0 deletions
12
src/lib/seam/components/DeviceDetails/DeviceDetails.element.ts
This file contains hidden or 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,12 @@ | ||
import type { ElementProps } from 'lib/element.js' | ||
|
||
import type { DeviceDetailsProps } from './DeviceDetails.js' | ||
|
||
export const name = 'seam-device-details' | ||
|
||
export const props: ElementProps<DeviceDetailsProps> = { | ||
deviceId: 'string', | ||
onBack: 'function', | ||
} | ||
|
||
export { DeviceDetails as Component } from './DeviceDetails.js' |
11 changes: 11 additions & 0 deletions
11
src/lib/seam/components/DeviceTable/DeviceTable.element.ts
This file contains hidden or 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,11 @@ | ||
import type { ElementProps } from 'lib/element.js' | ||
|
||
import type { DeviceTableProps } from './DeviceTable.js' | ||
|
||
export const name = 'seam-device-table' | ||
|
||
export const props: ElementProps<DeviceTableProps> = { | ||
onBack: 'function', | ||
} | ||
|
||
export { DeviceTable as Component } from './DeviceTable.js' |
This file contains hidden or 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
11 changes: 11 additions & 0 deletions
11
src/lib/seam/components/SupportedDeviceTable/SupportedDeviceTable.element.ts
This file contains hidden or 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,11 @@ | ||
import type { ElementProps } from 'lib/element.js' | ||
|
||
import type { SupportedDeviceTableProps } from './SupportedDeviceTable.js' | ||
|
||
export const name = 'seam-supported-device-table' | ||
|
||
export const props: ElementProps<SupportedDeviceTableProps> = { | ||
cannotFilter: 'boolean', | ||
} | ||
|
||
export { SupportedDeviceTable as Component } from './SupportedDeviceTable.js' |
This file contains hidden or 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,5 @@ | ||
export * as AccessCodeDetails from './AccessCodeDetails/AccessCodeDetails.element.js' | ||
export * as AccessCodeTable from './AccessCodeTable/AccessCodeTable.element.js' | ||
export * as DeviceDetails from './DeviceDetails/DeviceDetails.element.js' | ||
export * as DeviceTable from './DeviceTable/DeviceTable.element.js' | ||
export * as SupportedDeviceTable from './SupportedDeviceTable/SupportedDeviceTable.element.js' |
This file contains hidden or 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,3 @@ | ||
export default null | ||
const seamapiReactVersion = null | ||
|
||
export default seamapiReactVersion |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -35,7 +35,8 @@ | |
"src/**/*", | ||
"test/**/*", | ||
"examples/**/*", | ||
"api/**/*", | ||
".storybook/**/*", | ||
"api/**/*" | ||
"vite.config.ts" | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.