-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
defineComponent
& registerAllowedCustomElement
to allow tags …
…in Aegis Sanitizer Config
- Loading branch information
1 parent
ed6d9ff
commit c8db41d
Showing
4 changed files
with
28 additions
and
12 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 |
---|---|---|
@@ -1,25 +1,36 @@ | ||
/** | ||
* @copyright 2023 Chris Zuber <[email protected]> | ||
* @copyright 2023-2024 Chris Zuber <[email protected]> | ||
*/ | ||
import { HTML } from '@shgysk8zer0/consts/mimes.js'; | ||
import { registerComponent as reg } from '@aegisjsproject/core/componentRegistry.js'; | ||
|
||
export const supported = globalThis.customElements instanceof Object; | ||
|
||
export function isDefined(...tags) { | ||
return supported && tags.every(tag => typeof customElements.get(tag) !== 'undefined'); | ||
} | ||
|
||
export function registerCustomElement(tag, cls, ...rest) { | ||
if (! supported) { | ||
console.error(new Error('`customElements` not supported')); | ||
export function defineComponent(tag, cls, allow = false) { | ||
return allow ? registerAllowedCustomElement(tag, cls) : registerCustomElement(tag, cls); | ||
} | ||
|
||
export function registerAllowedCustomElement(tag, cls, ...rest) { | ||
try { | ||
reg(tag, cls, ...rest); | ||
return true; | ||
} catch(err) { | ||
console.error(err); | ||
return false; | ||
} else if (isDefined(tag)) { | ||
console.warn(new Error(`<${tag}> is already defined`)); | ||
// Returns true/false if element being registered matches given class | ||
return customElements.get(tag) === cls; | ||
} else { | ||
} | ||
} | ||
|
||
export function registerCustomElement(tag, cls, ...rest) { | ||
try { | ||
customElements.define(tag, cls, ...rest); | ||
return true; | ||
} catch(err) { | ||
console.error(err); | ||
return false; | ||
} | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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