Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/auth/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export interface AuthContext {
}

export const DEFAULT_AUTH_CONTEXT = new NoopAuth()
export const authContext = createContext<AuthContext>(Symbol('auth'))
export const authContext = createContext<AuthContext>(Symbol.for('solid-ui.auth'))
13 changes: 13 additions & 0 deletions src/lib/components/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* See https://github.com/SolidOS/solidos/issues/300
*/

const customElementTagNames = new WeakMap<CustomElementConstructor, string>()

function defineCustomElement (tagName: string, elementClass: CustomElementConstructor): void {
if (customElements.get(tagName)) {
return
Expand All @@ -16,8 +18,19 @@ function defineCustomElement (tagName: string, elementClass: CustomElementConstr
customElements.define(tagName, elementClass)
}

export function getCustomElementTagName (elementClass: CustomElementConstructor): string {
const tagName = customElementTagNames.get(elementClass)
if (!tagName) {
throw new Error('Cannot create dialog: the component is not registered with customElement().')
}

return tagName
}

export function customElement (tagName: string) {
return (elementClass: CustomElementConstructor, context?: ClassDecoratorContext) => {
customElementTagNames.set(elementClass, tagName)

if (context) {
context.addInitializer(() => defineCustomElement(tagName, elementClass))

Expand Down
3 changes: 2 additions & 1 deletion src/lib/dialogs/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ShowDialogEvent } from './events/show-dialog'
import Dialog, { DialogConfig } from './Dialog'
import type WebComponent from '@/lib/components/web-component/WebComponent'
import { getCustomElementTagName } from '@/lib/components/decorators'
import type { GetWebComponentMetadata, WebComponentConstructor } from '@/lib/components/web-component/WebComponent'

export type GetDialogResult<T, TFallback = unknown> = GetWebComponentMetadata<T> extends { dialogResult: infer TResult } ? TResult : TFallback
Expand All @@ -9,7 +10,7 @@ export function showDialog<T extends WebComponent> (
DialogComponent: WebComponentConstructor<T>,
config?: DialogConfig<GetDialogResult<T>> & { props?: Partial<T> }
): T {
const element = new DialogComponent()
const element = document.createElement(getCustomElementTagName(DialogComponent)) as T

Object.assign(element, config?.props)

Expand Down
1 change: 1 addition & 0 deletions test/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('Index', () => {
'dom',
'fileExplorerContext',
'generateId',
'getCustomElementTagName',
'getRelevantPanes',
'icons',
'infiniteMessageArea',
Expand Down
Loading