-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrade element code to support define() & React
- Loading branch information
Showing
5 changed files
with
111 additions
and
43 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
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,35 @@ | ||
import {AutoCompleteElement} from './auto-complete-element.js' | ||
|
||
const root = (typeof globalThis !== 'undefined' ? globalThis : window) as typeof window | ||
try { | ||
// Lowercase C is here for backwards compat | ||
root.AutocompleteElement = root.AutoCompleteElement = AutoCompleteElement.define() | ||
} catch (e: unknown) { | ||
if ( | ||
!(root.DOMException && e instanceof DOMException && e.name === 'NotSupportedError') && | ||
!(e instanceof ReferenceError) | ||
) { | ||
throw e | ||
} | ||
} | ||
|
||
type JSXBase = JSX.IntrinsicElements extends {span: unknown} | ||
? JSX.IntrinsicElements | ||
: Record<string, Record<string, unknown>> | ||
declare global { | ||
interface Window { | ||
AutoCompleteElement: typeof AutoCompleteElement | ||
AutocompleteElement: typeof AutoCompleteElement | ||
} | ||
interface HTMLElementTagNameMap { | ||
'auto-complete': AutoCompleteElement | ||
} | ||
namespace JSX { | ||
interface IntrinsicElements { | ||
['auto-complete']: JSXBase['span'] & Partial<Omit<AutoCompleteElement, keyof HTMLElement>> | ||
} | ||
} | ||
} | ||
|
||
export default AutoCompleteElement | ||
export * from './auto-complete-element.js' |
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,14 +0,0 @@ | ||
type AutocompleteEventType = 'auto-complete-change' | ||
|
||
type AutocompleteEventInit = CustomEventInit & { | ||
relatedTarget: HTMLInputElement | ||
} | ||
|
||
export default class AutocompleteEvent extends CustomEvent<null> { | ||
relatedTarget: HTMLInputElement | ||
|
||
constructor(type: AutocompleteEventType, init: AutocompleteEventInit) { | ||
super(type, init) | ||
this.relatedTarget = init.relatedTarget | ||
} | ||
} | ||
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,3 +1,5 @@ | ||
import AutoCompleteElement from './auto-complete-element.js' | ||
export {AutoCompleteElement, AutoCompleteElement as default} | ||
export {default as AutocompleteEvent} from './auto-complete-event.js' | ||
import {AutoCompleteElement} from './auto-complete-element-define.js' | ||
|
||
export {AutoCompleteElement} | ||
export default AutoCompleteElement | ||
export * from './auto-complete-element-define.js' |