Skip to content

Commit

Permalink
feat(omi): tag name can be obtained through exported class, preventin…
Browse files Browse the repository at this point in the history
…g tree shaking
  • Loading branch information
dntzhang committed Oct 28, 2023
1 parent 74a5d25 commit 6ea362c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions packages/omi/omi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ declare namespace Omi {
// Allow static members to reference class type parameters
// https://github.com/Microsoft/TypeScript/issues/24018
static css?: string | CSSStyleSheet | (string | CSSStyleSheet)[]
static tagName: string

props: OmiProps<P> | P
prevProps: OmiProps<P> | P
Expand Down Expand Up @@ -130,6 +131,7 @@ declare namespace Omi {
// https://github.com/Microsoft/TypeScript/issues/24018

static css?: string | CSSStyleSheet | (string | CSSStyleSheet)[]
static tagName: string

props: OmiProps<P> | P
prevProps: OmiProps<P> | P
Expand Down
2 changes: 1 addition & 1 deletion packages/omi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "omi",
"version": "7.1.14",
"version": "7.2.0",
"scripts": {
"start": "vite",
"dev-vite": "vite",
Expand Down
16 changes: 8 additions & 8 deletions packages/omi/src/define.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* Defines a custom element.
* @param name - The name of the custom element.
* @param tagName - The tagName of the custom element.
* @param ctor - The constructor function for the custom element.
*/
export function define(name: string, ctor: CustomElementConstructor): void {
if (customElements.get(name)) {
console.warn(`Failed to execute 'define' on 'CustomElementRegistry': the name "${name}" has already been used with this registry`)
export function define(tagName: string, ctor: CustomElementConstructor): void {
if (customElements.get(tagName)) {
console.warn(`Failed to execute 'define' on 'CustomElementRegistry': the tag name "${tagName}" has already been used with this registry`)
return
}

customElements.define(name, ctor)
Object.defineProperty(ctor, 'tagName', { value: tagName, writable: false })
customElements.define(tagName, ctor)
}

export function tag(name: string) {
export function tag(tagName: string) {
return function (target: CustomElementConstructor) {
define(name, target)
define(tagName, target)
}
}
2 changes: 1 addition & 1 deletion packages/omi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export type { SignalValue } from './reactivity'
export { Signal } from './signal'
export { css } from './css-tag'
export { mixin } from './options'
export const version = '7.1.14'
export const version = '7.2.0'


0 comments on commit 6ea362c

Please sign in to comment.