@yh-ui/utils 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vue.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Vue 相关的工具函数
3
+ * @description 获取组件名、添加安装方法等
4
+ */
5
+ import type { Component, Plugin, Directive } from 'vue';
6
+ import type { SFCWithInstall } from './types';
7
+ /**
8
+ * 为组件添加 install 方法,使其可以作为 Vue 插件使用
9
+ */
10
+ export declare const withInstall: <T extends Component, E extends Record<string, unknown>>(main: T, extra?: E) => SFCWithInstall<T> & E;
11
+ /**
12
+ * 空安装方法,用于不需要独立安装的子组件
13
+ */
14
+ export declare const withNoopInstall: <T extends Component>(component: T) => SFCWithInstall<T>;
15
+ /**
16
+ * 为函数式组件或工具添加 install 方法
17
+ */
18
+ export declare const withInstallFunction: <T>(fn: T, name: string) => SFCWithInstall<T>;
19
+ /**
20
+ * 为指令添加 install 方法
21
+ */
22
+ export declare const withInstallDirective: <T extends Directive>(directive: T, name: string) => SFCWithInstall<T>;
23
+ /**
24
+ * 批量注册组件和指令
25
+ */
26
+ export declare const withInstallAll: (components: Component[], directives?: Record<string, Directive>) => Plugin;
27
+ /**
28
+ * 用于 defineOptions 的类型辅助
29
+ */
30
+ export interface ComponentOptions {
31
+ name: string;
32
+ inheritAttrs?: boolean;
33
+ }
package/dist/vue.mjs ADDED
@@ -0,0 +1,55 @@
1
+ export const withInstall = (main, extra) => {
2
+ ;
3
+ main.install = (app) => {
4
+ for (const comp of [main, ...Object.values(extra ?? {})]) {
5
+ const name = comp.name || comp.__name;
6
+ if (name) {
7
+ app.component(name, comp);
8
+ }
9
+ }
10
+ };
11
+ if (extra) {
12
+ for (const [key, comp] of Object.entries(extra)) {
13
+ ;
14
+ main[key] = comp;
15
+ }
16
+ }
17
+ return main;
18
+ };
19
+ export const withNoopInstall = (component) => {
20
+ ;
21
+ component.install = () => {
22
+ };
23
+ return component;
24
+ };
25
+ export const withInstallFunction = (fn, name) => {
26
+ const func = fn;
27
+ func.install = (app) => {
28
+ app.config.globalProperties[name] = fn;
29
+ };
30
+ return func;
31
+ };
32
+ export const withInstallDirective = (directive, name) => {
33
+ const dir = directive;
34
+ dir.install = (app) => {
35
+ app.directive(name, dir);
36
+ };
37
+ return dir;
38
+ };
39
+ export const withInstallAll = (components, directives) => {
40
+ return {
41
+ install(app) {
42
+ components.forEach((component) => {
43
+ const name = component.name || component.__name;
44
+ if (name) {
45
+ app.component(name, component);
46
+ }
47
+ });
48
+ if (directives) {
49
+ Object.entries(directives).forEach(([name, directive]) => {
50
+ app.directive(name, directive);
51
+ });
52
+ }
53
+ }
54
+ };
55
+ };
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@yh-ui/utils",
3
+ "version": "0.1.0",
4
+ "description": "YH-UI utility functions",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.mjs",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.cjs"
15
+ },
16
+ "./*": {
17
+ "types": "./dist/*.d.ts",
18
+ "import": "./dist/*.mjs",
19
+ "require": "./dist/*.cjs"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "devDependencies": {
26
+ "vue": "^3.5.27",
27
+ "vue-tsc": "^2.2.0"
28
+ },
29
+ "peerDependencies": {
30
+ "vue": "^3.5.27"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/1079161148/yh-ui.git",
38
+ "directory": "packages/utils"
39
+ },
40
+ "keywords": [
41
+ "yh-ui",
42
+ "utils"
43
+ ],
44
+ "homepage": "https://yh-ui.dev",
45
+ "author": "YH-UI Team",
46
+ "license": "MIT",
47
+ "scripts": {
48
+ "build": "unbuild",
49
+ "dev": "unbuild --stub"
50
+ }
51
+ }