use-components 1.0.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/core/installer.d.ts +12 -0
- package/dist/core/loader.d.ts +26 -0
- package/dist/index.d.ts +2 -0
- package/dist/types/index.d.ts +59 -0
- package/dist/use-components.es.js +1 -0
- package/dist/use-components.umd.js +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { App, Component } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* 初始化 SDK,传入 Vue 实例
|
|
4
|
+
* @param app Vue createApp 返回的实例
|
|
5
|
+
*/
|
|
6
|
+
export declare const initVueComponentSDK: (app: App) => void;
|
|
7
|
+
/**
|
|
8
|
+
* 注册全局组件
|
|
9
|
+
* @param key 组件名称
|
|
10
|
+
* @param component 组件定义
|
|
11
|
+
*/
|
|
12
|
+
export declare const componentInstall: (key: string, component: Component) => void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 加载 CSS 资源
|
|
3
|
+
* @param url CSS 文件地址
|
|
4
|
+
*/
|
|
5
|
+
export declare const loadCss: (url: string) => void;
|
|
6
|
+
/**
|
|
7
|
+
* 动态加载 AMD 模块的 JS/CSS 资源
|
|
8
|
+
* @param version 组件版本号
|
|
9
|
+
* @param key 组件标识
|
|
10
|
+
* @param baseUrl 资源基础路径(可选,默认 /)
|
|
11
|
+
*/
|
|
12
|
+
export declare const loadComponentsFromAMD: (version: string, key: string, baseUrl?: string) => Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* 获取 AMD 模块中的组件
|
|
15
|
+
* @param version 组件版本号
|
|
16
|
+
* @param key 组件标识
|
|
17
|
+
*/
|
|
18
|
+
export declare const useGetComponents: <T extends {
|
|
19
|
+
default: () => any;
|
|
20
|
+
} = any>(version: string, key: string) => Promise<{
|
|
21
|
+
component: T;
|
|
22
|
+
config: {
|
|
23
|
+
default: () => any;
|
|
24
|
+
};
|
|
25
|
+
configVue: any;
|
|
26
|
+
}>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { App, Component } from 'vue';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* @Author: wangcong
|
|
5
|
+
* @Date: 2026-01-19 16:21:23
|
|
6
|
+
* @LastEditTime: 2026-01-20 09:16:54
|
|
7
|
+
* @LastEditors: wangcong
|
|
8
|
+
* @Description:
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
declare module 'use-components' {
|
|
13
|
+
/**
|
|
14
|
+
* 初始化 SDK
|
|
15
|
+
* @param app Vue 实例
|
|
16
|
+
*/
|
|
17
|
+
export function initVueComponentSDK(app: App): void;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 加载 CSS 资源
|
|
21
|
+
* @param url CSS 文件地址
|
|
22
|
+
*/
|
|
23
|
+
export function loadCss(url: string): void;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 加载 AMD 组件资源
|
|
27
|
+
* @param version 版本号
|
|
28
|
+
* @param key 组件标识
|
|
29
|
+
* @param baseUrl 基础路径
|
|
30
|
+
*/
|
|
31
|
+
export function loadComponentsFromAMD(
|
|
32
|
+
version: string,
|
|
33
|
+
key: string,
|
|
34
|
+
baseUrl?: string
|
|
35
|
+
): Promise<string>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 获取 AMD 模块中的组件
|
|
39
|
+
* @param version 版本号
|
|
40
|
+
* @param key 组件标识
|
|
41
|
+
*/
|
|
42
|
+
export function useGetComponents<T = any>(
|
|
43
|
+
version: string,
|
|
44
|
+
key: string
|
|
45
|
+
): Promise<{
|
|
46
|
+
[T: string]: {
|
|
47
|
+
component: T;
|
|
48
|
+
config: { default: () => any };
|
|
49
|
+
configVue: any;
|
|
50
|
+
}
|
|
51
|
+
}>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 注册全局组件
|
|
55
|
+
* @param key 组件名称
|
|
56
|
+
* @param component 组件定义
|
|
57
|
+
*/
|
|
58
|
+
export function componentInstall(key: string, component: Component): void;
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=new Map,r=e=>{if([...document.head.querySelectorAll("link")].some(r=>r.href===e))return;const r=document.createElement("link");r.setAttribute("rel","stylesheet"),r.setAttribute("type","text/css"),r.setAttribute("href",e),document.head.appendChild(r)},n=(n,t,o="/")=>{const s=`${t}@${n}`,c=`${o}${t}@${n}.js`,i=`${o}${t}@${n}.css`;if("loaded"===e.get(s))return Promise.resolve("already loaded");if("pending"===e.get(s))return e.get(s);const d=new Promise((t,o)=>{if(!n)return o(new Error("组件版本号为空"));e.set(s,"pending");const d=document.createElement("script"),u=document.getElementsByTagName("script")[0]||document.head;d.type="text/javascript",d.src=c,d.onload=()=>{e.set(s,"loaded"),t("load success")},d.onerror=r=>{e.delete(s),o(new Error(`加载组件失败: ${r.message}`))},u.parentNode?.insertBefore(d,u),r(i)});return e.set(s,d),d},t=(e,r)=>{const n=`${r}@${e}`;return new Promise((e,t)=>{try{require([n],n=>{e(n[r])})}catch(e){t(new Error(`获取组件失败: ${e.message}`))}})};let o=null;const s=e=>{o=e},c=(e,r)=>{if(!o)throw new Error("请先调用 initVueComponentSDK 初始化 SDK");o.component(e,r)};export{c as componentInstall,s as initVueComponentSDK,n as loadComponentsFromAMD,r as loadCss,t as useGetComponents};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).t={})}(this,function(e){"use strict";const n=new Map,t=e=>{if([...document.head.querySelectorAll("link")].some(n=>n.href===e))return;const n=document.createElement("link");n.setAttribute("rel","stylesheet"),n.setAttribute("type","text/css"),n.setAttribute("href",e),document.head.appendChild(n)};let r=null;e.o=(e,n)=>{if(!r)throw new Error("请先调用 initVueComponentSDK 初始化 SDK");r.component(e,n)},e.i=e=>{r=e},e.u=(e,r,o="/")=>{const s=`${r}@${e}`,i=`${o}${r}@${e}.js`,c=`${o}${r}@${e}.css`;if("loaded"===n.get(s))return Promise.resolve("already loaded");if("pending"===n.get(s))return n.get(s);const d=new Promise((r,o)=>{if(!e)return o(new Error("组件版本号为空"));n.set(s,"pending");const d=document.createElement("script"),u=document.getElementsByTagName("script")[0]||document.head;d.type="text/javascript",d.src=i,d.onload=()=>{n.set(s,"loaded"),r("load success")},d.onerror=e=>{n.delete(s),o(new Error(`加载组件失败: ${e.message}`))},u.parentNode?.insertBefore(d,u),t(c)});return n.set(s,d),d},e.l=t,e.p=(e,n)=>{const t=`${n}@${e}`;return new Promise((e,r)=>{try{require([t],t=>{e(t[n])})}catch(e){r(new Error(`获取组件失败: ${e.message}`))}})}});
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "use-components",
|
|
3
|
+
"author": "wangcong",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"description": "Vue3 动态加载 AMD 组件 SDK",
|
|
7
|
+
"main": "dist/use-components.umd.umd.js",
|
|
8
|
+
"module": "dist/use-components.es.js",
|
|
9
|
+
"types": "dist/types/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./dist/use-components.es.js",
|
|
16
|
+
"require": "./dist/use-components.umd.js",
|
|
17
|
+
"types": "./dist/types/index.d.ts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "rollup -c",
|
|
22
|
+
"dev": "rollup -c -w"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"vue": "^3.2.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
29
|
+
"@vue/tsconfig": "^0.5.1",
|
|
30
|
+
"rollup": "^4.9.6",
|
|
31
|
+
"rollup-plugin-dts": "^6.1.0",
|
|
32
|
+
"tslib": "^2.6.2",
|
|
33
|
+
"typescript": "^5.3.3",
|
|
34
|
+
"vue": "^3.4.15"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@rollup/plugin-terser": "^0.4.4"
|
|
38
|
+
}
|
|
39
|
+
}
|