From 6ea362c043f9f0e10ef158118075fd7d56ff54a8 Mon Sep 17 00:00:00 2001 From: dntzhang Date: Sat, 28 Oct 2023 08:44:11 +0800 Subject: [PATCH] feat(omi): tag name can be obtained through exported class, preventing tree shaking --- packages/omi/omi.d.ts | 2 ++ packages/omi/package.json | 2 +- packages/omi/src/define.ts | 16 ++++++++-------- packages/omi/src/index.ts | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/omi/omi.d.ts b/packages/omi/omi.d.ts index 857b31c8fa..978cca6005 100644 --- a/packages/omi/omi.d.ts +++ b/packages/omi/omi.d.ts @@ -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 prevProps: OmiProps

| P @@ -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 prevProps: OmiProps

| P diff --git a/packages/omi/package.json b/packages/omi/package.json index ecf1f0f326..4873168cab 100644 --- a/packages/omi/package.json +++ b/packages/omi/package.json @@ -1,6 +1,6 @@ { "name": "omi", - "version": "7.1.14", + "version": "7.2.0", "scripts": { "start": "vite", "dev-vite": "vite", diff --git a/packages/omi/src/define.ts b/packages/omi/src/define.ts index 6ea21b3807..fa71e2eac1 100644 --- a/packages/omi/src/define.ts +++ b/packages/omi/src/define.ts @@ -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) } } diff --git a/packages/omi/src/index.ts b/packages/omi/src/index.ts index 401257dc40..d30ca70241 100644 --- a/packages/omi/src/index.ts +++ b/packages/omi/src/index.ts @@ -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'