@zxiaosi/sdk 0.0.7 → 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/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +106 -3
- package/dist/esm/index.d.mts +106 -3
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
var e=class{constructor(){this.name=``,this._plugins=new Map}mount(e){if(e&&window[e])Object.assign(this,window[e]);else{this.name=e;let t=new Proxy(this,{get:(e,t,n)=>e?Reflect.get(e,t,n):null,set:()=>(console.error(`The SDK cannot be modified.`),!1),deleteProperty:()=>(console.error(`The SDK cannot be deleted.`),!1)});window[this.name]=t}}unmount(){this._plugins.clear(),delete window[this.name]}use(e,t){let{name:n,install:r}=e;if(!n)throw Error(`${n} plugin has no name`);if(typeof r!=`function`)throw Error(`${n} plugin is not a function`);return r(this,t),this._plugins.set(n,{...e,options:t}),this}};const t=new e;function n(e){if(!e||typeof e!=`object`)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype||Object.getPrototypeOf(t)===null?Object.prototype.toString.call(e)===`[object Object]`:!1}function r(e){return e===`__proto__`}function i(e,t){let a=Object.keys(t);for(let o=0;o<a.length;o++){let s=a[o];if(r(s))continue;let c=t[s],l=e[s];Array.isArray(c)?Array.isArray(l)?e[s]=i(l,c):e[s]=i([],c):n(c)?n(l)?e[s]=i(l,c):e[s]=i({},c):(l===void 0||c!==void 0)&&(e[s]=c)}return e}const a=`config`,o={name:a,install(e,t={}){e[a]=i({env:{},qiankunMode:`router`,theme:null,locale:null,localeStorageKey:`locale`,themeStorageKey:`theme`,tokenStorageKey:`token`,loginPath:`/login`,defaultPath:``,customRoutes:[],antdConfig:{},proLayoutConfig:{title:`Demo`}},t)}};exports.SdkConfigPlugin=o,exports.sdk=t;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["const
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["isPlainObject","value","proto","Object","getPrototypeOf","hasObjectPrototype","prototype","toString","call","isUnsafeProperty","key","isUnsafeProperty","isPlainObject","merge","target","source","sourceKeys","Object","keys","i","length","key","sourceValue","targetValue","Array","isArray","undefined","SdkConfigPlugin: Plugin<'config'>"],"sources":["../../src/core/index.ts","../../../node_modules/.pnpm/es-toolkit@1.39.10/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs","../../../node_modules/.pnpm/es-toolkit@1.39.10/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs","../../../node_modules/.pnpm/es-toolkit@1.39.10/node_modules/es-toolkit/dist/object/merge.mjs","../../src/plugins/config/index.ts"],"sourcesContent":["import { Plugin, PluginOptions, SdkResult } from '@/types';\n\nclass Sdk implements SdkResult {\n name: SdkResult['name'];\n _plugins: SdkResult['_plugins'];\n\n constructor() {\n this.name = '';\n this._plugins = new Map();\n }\n\n mount(name: string) {\n // 如果已经存在同名的sdk实例,则直接返回(子应用)\n if (name && window[name]) {\n Object.assign(this, window[name]); // 合并实例属性\n } else {\n // 否则创建一个新的sdk实例, 并手动挂载到window上 (主应用)\n this.name = name;\n\n // 使用 new Proxy 禁止控制台对sdk属性的操作 (仅第一层属性)\n const _this = new Proxy(this, {\n get: (target, key, receiver) => {\n if (!target) return null;\n return Reflect.get(target, key, receiver);\n },\n set: () => {\n console.error('The SDK cannot be modified.');\n return false;\n },\n deleteProperty: () => {\n console.error('The SDK cannot be deleted.');\n return false;\n },\n });\n\n // 挂载到 Window 上\n window[this.name] = _this;\n }\n }\n\n unmount() {\n // 清空插件\n this._plugins.clear();\n // 删除window上的实例\n delete window[this.name];\n }\n\n use<K extends keyof PluginOptions>(plugin: Plugin<K>, options?: PluginOptions[K]) {\n const { name, install } = plugin;\n\n if (!name) throw new Error(`${name} plugin has no name`);\n\n if (typeof install !== 'function') throw new Error(`${name} plugin is not a function`);\n\n // 插件安装\n install(this as any, options);\n\n // 添加到插件列表\n this._plugins.set(name, { ...plugin, options });\n\n // 链式调用\n return this;\n }\n}\n\n/**\n * sdk 实例\n * @example sdk.use(SdkPlugin) // 使用插件\n * @example sdk.mount('SdkName') // 挂载到 window 上\n * @example sdk.unmount() // 卸载\n */\nconst sdk = new Sdk();\n\nexport { sdk };\n","function isPlainObject(value) {\n if (!value || typeof value !== 'object') {\n return false;\n }\n const proto = Object.getPrototypeOf(value);\n const hasObjectPrototype = proto === null ||\n proto === Object.prototype ||\n Object.getPrototypeOf(proto) === null;\n if (!hasObjectPrototype) {\n return false;\n }\n return Object.prototype.toString.call(value) === '[object Object]';\n}\n\nexport { isPlainObject };\n","function isUnsafeProperty(key) {\n return key === '__proto__';\n}\n\nexport { isUnsafeProperty };\n","import { isUnsafeProperty } from '../_internal/isUnsafeProperty.mjs';\nimport { isPlainObject } from '../predicate/isPlainObject.mjs';\n\nfunction merge(target, source) {\n const sourceKeys = Object.keys(source);\n for (let i = 0; i < sourceKeys.length; i++) {\n const key = sourceKeys[i];\n if (isUnsafeProperty(key)) {\n continue;\n }\n const sourceValue = source[key];\n const targetValue = target[key];\n if (Array.isArray(sourceValue)) {\n if (Array.isArray(targetValue)) {\n target[key] = merge(targetValue, sourceValue);\n }\n else {\n target[key] = merge([], sourceValue);\n }\n }\n else if (isPlainObject(sourceValue)) {\n if (isPlainObject(targetValue)) {\n target[key] = merge(targetValue, sourceValue);\n }\n else {\n target[key] = merge({}, sourceValue);\n }\n }\n else if (targetValue === undefined || sourceValue !== undefined) {\n target[key] = sourceValue;\n }\n }\n return target;\n}\n\nexport { merge };\n","import { LocaleProps, Plugin, ThemeProps } from '@/types';\nimport { ProLayoutProps } from '@ant-design/pro-layout';\nimport { ConfigProviderProps } from 'antd';\nimport { merge } from 'es-toolkit';\nimport { RouteObject } from 'react-router-dom';\n\ninterface ConfigOptions {\n /** 环境变量 */\n env?: Record<string, any>;\n\n /**\n * qiankun模式(切换模式后请打开新的窗口)\n * - 'router': 基于路由模式\n * - 'load': 手动加载模式\n */\n qiankunMode?: 'router' | 'load';\n\n /** 主题 */\n theme?: ThemeProps;\n /** 国际化 */\n locale?: LocaleProps;\n\n /** 国际化存储名称 */\n localeStorageKey?: string;\n /** 主题存储名称 */\n themeStorageKey?: string;\n /** Token存储名称 */\n tokenStorageKey?: string;\n\n /** 登录页路由 */\n loginPath?: string;\n /**\n * 登录后跳转的路由\n * - 优先使用指定值\n * - 其次使用重定向的值\n * - 最后使用菜单中第一项\n */\n defaultPath?: string;\n /**\n * 自定义路由信息\n * - 目前只支持最外层路由自定义\n * - 会合并到 sdk.app.allRoutes 中\n */\n customRoutes?: RouteObject[];\n\n /** Antd 配置 */\n antdConfig?: ConfigProviderProps;\n /** ProLayout 配置 */\n proLayoutConfig?: ProLayoutProps;\n}\n\ninterface ConfigResult extends Required<ConfigOptions> {}\n\n/** 插件名称 */\nconst pluginName = 'config';\n\n/**\n * 配置信息\n * - 详情参考 {@link ConfigOptions} {@link ConfigResult}\n * - 配置 localStorage 变量名称\n * - 配置 默认主题、国际化\n * - 配置 默认登录路径、跳转路径、自定义路由\n * - 配置 Antd 配置、ProLayout 配置\n */\nconst SdkConfigPlugin: Plugin<'config'> = {\n name: pluginName,\n install(sdk, options = {}) {\n // 默认插件配置\n const defaultOptions = {\n env: {},\n\n qiankunMode: 'router',\n\n theme: null,\n locale: null,\n\n localeStorageKey: 'locale',\n themeStorageKey: 'theme',\n tokenStorageKey: 'token',\n\n loginPath: '/login',\n defaultPath: '',\n customRoutes: [],\n\n antdConfig: {},\n proLayoutConfig: {\n title: 'Demo',\n },\n } satisfies ConfigResult;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { ConfigOptions, Config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AI,EAAGA,EAAIH,EAAWI,OAAQD,IAAK,CACxC,IAAME,EAAML,EAAWG,GACvB,GAAIR,EAAiBU,EAAI,CACrB,SAEJ,IAAMC,EAAcP,EAAOM,GACrBE,EAAcT,EAAOO,GACvBG,MAAMC,QAAQH,EAAY,CACtBE,MAAMC,QAAQF,EAAY,CAC1BT,EAAOO,GAAOR,EAAMU,EAAaD,EAAY,CAG7CR,EAAOO,GAAOR,EAAM,EAAE,CAAES,EAAY,CAGnCV,EAAcU,EAAY,CAC3BV,EAAcW,EAAY,CAC1BT,EAAOO,GAAOR,EAAMU,EAAaD,EAAY,CAG7CR,EAAOO,GAAOR,EAAM,EAAE,CAAES,EAAY,EAGnCC,IAAgBG,IAAAA,IAAaJ,IAAgBI,IAAAA,MAClDZ,EAAOO,GAAOC,GAGtB,OAAOR,ECsBX,MAAM,EAAa,SAUba,EAAoC,CACxC,KAAM,EACN,QAAQ,EAAK,EAAU,EAAE,CAAE,CAwBzB,EAAI,GAAc,EAtBK,CACrB,IAAK,EAAE,CAEP,YAAa,SAEb,MAAO,KACP,OAAQ,KAER,iBAAkB,SAClB,gBAAiB,QACjB,gBAAiB,QAEjB,UAAW,SACX,YAAa,GACb,aAAc,EAAE,CAEhB,WAAY,EAAE,CACd,gBAAiB,CACf,MAAO,OACR,CACF,CAEuC,EAAQ,EAEnD"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,5 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ProLayoutProps } from "@ant-design/pro-layout";
|
|
2
|
+
import { ConfigProviderProps } from "antd";
|
|
3
|
+
import { RouteObject } from "react-router-dom";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/config/index.d.ts
|
|
6
|
+
interface ConfigOptions {
|
|
7
|
+
/** 环境变量 */
|
|
8
|
+
env?: Record<string, any>;
|
|
9
|
+
/**
|
|
10
|
+
* qiankun模式(切换模式后请打开新的窗口)
|
|
11
|
+
* - 'router': 基于路由模式
|
|
12
|
+
* - 'load': 手动加载模式
|
|
13
|
+
*/
|
|
14
|
+
qiankunMode?: 'router' | 'load';
|
|
15
|
+
/** 主题 */
|
|
16
|
+
theme?: ThemeProps;
|
|
17
|
+
/** 国际化 */
|
|
18
|
+
locale?: LocaleProps;
|
|
19
|
+
/** 国际化存储名称 */
|
|
20
|
+
localeStorageKey?: string;
|
|
21
|
+
/** 主题存储名称 */
|
|
22
|
+
themeStorageKey?: string;
|
|
23
|
+
/** Token存储名称 */
|
|
24
|
+
tokenStorageKey?: string;
|
|
25
|
+
/** 登录页路由 */
|
|
26
|
+
loginPath?: string;
|
|
27
|
+
/**
|
|
28
|
+
* 登录后跳转的路由
|
|
29
|
+
* - 优先使用指定值
|
|
30
|
+
* - 其次使用重定向的值
|
|
31
|
+
* - 最后使用菜单中第一项
|
|
32
|
+
*/
|
|
33
|
+
defaultPath?: string;
|
|
34
|
+
/**
|
|
35
|
+
* 自定义路由信息
|
|
36
|
+
* - 目前只支持最外层路由自定义
|
|
37
|
+
* - 会合并到 sdk.app.allRoutes 中
|
|
38
|
+
*/
|
|
39
|
+
customRoutes?: RouteObject[];
|
|
40
|
+
/** Antd 配置 */
|
|
41
|
+
antdConfig?: ConfigProviderProps;
|
|
42
|
+
/** ProLayout 配置 */
|
|
43
|
+
proLayoutConfig?: ProLayoutProps;
|
|
44
|
+
}
|
|
45
|
+
interface ConfigResult extends Required<ConfigOptions> {}
|
|
46
|
+
/**
|
|
47
|
+
* 配置信息
|
|
48
|
+
* - 详情参考 {@link ConfigOptions} {@link ConfigResult}
|
|
49
|
+
* - 配置 localStorage 变量名称
|
|
50
|
+
* - 配置 默认主题、国际化
|
|
51
|
+
* - 配置 默认登录路径、跳转路径、自定义路由
|
|
52
|
+
* - 配置 Antd 配置、ProLayout 配置
|
|
53
|
+
*/
|
|
54
|
+
declare const SdkConfigPlugin: Plugin<'config'>;
|
|
3
55
|
//#endregion
|
|
4
|
-
|
|
56
|
+
//#region src/types.d.ts
|
|
57
|
+
type ThemeProps = 'light' | 'dark';
|
|
58
|
+
type LocaleProps = 'zh-CN' | 'en-US';
|
|
59
|
+
type PluginName = keyof PluginOptions;
|
|
60
|
+
interface PluginOptions {
|
|
61
|
+
/** 配置项插件 */
|
|
62
|
+
config?: ConfigOptions;
|
|
63
|
+
}
|
|
64
|
+
interface PluginResults {
|
|
65
|
+
/** 配置项插件 */
|
|
66
|
+
config: ConfigResult;
|
|
67
|
+
}
|
|
68
|
+
interface Plugin<K extends PluginName> {
|
|
69
|
+
/** 插件名字 */
|
|
70
|
+
name: K;
|
|
71
|
+
/** 插件安装方法 */
|
|
72
|
+
install: (sdk: SdkResult, options?: PluginOptions[K]) => void;
|
|
73
|
+
/** 插件配置项 */
|
|
74
|
+
options?: PluginOptions[K];
|
|
75
|
+
}
|
|
76
|
+
interface SdkBase {
|
|
77
|
+
/** SDK 名称 */
|
|
78
|
+
name: string;
|
|
79
|
+
/** 插件列表 */
|
|
80
|
+
_plugins: Map<string, Plugin<never>>;
|
|
81
|
+
/** 挂载sdk - Window */
|
|
82
|
+
mount: (name: string) => void;
|
|
83
|
+
/** 卸载sdk - Window */
|
|
84
|
+
unmount: () => void;
|
|
85
|
+
/** 使用插件 */
|
|
86
|
+
use: <K extends PluginName>(plugin: Plugin<K>, options?: PluginOptions[K]) => this;
|
|
87
|
+
}
|
|
88
|
+
type SdkResult = SdkBase & PluginResults;
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/core/index.d.ts
|
|
91
|
+
declare class Sdk implements SdkResult {
|
|
92
|
+
name: SdkResult['name'];
|
|
93
|
+
_plugins: SdkResult['_plugins'];
|
|
94
|
+
constructor();
|
|
95
|
+
mount(name: string): void;
|
|
96
|
+
unmount(): void;
|
|
97
|
+
use<K extends keyof PluginOptions>(plugin: Plugin<K>, options?: PluginOptions[K]): this;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* sdk 实例
|
|
101
|
+
* @example sdk.use(SdkPlugin) // 使用插件
|
|
102
|
+
* @example sdk.mount('SdkName') // 挂载到 window 上
|
|
103
|
+
* @example sdk.unmount() // 卸载
|
|
104
|
+
*/
|
|
105
|
+
declare const sdk: Sdk;
|
|
106
|
+
//#endregion
|
|
107
|
+
export { ConfigOptions, ConfigResult, SdkConfigPlugin, sdk };
|
|
5
108
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,5 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ProLayoutProps } from "@ant-design/pro-layout";
|
|
2
|
+
import { ConfigProviderProps } from "antd";
|
|
3
|
+
import { RouteObject } from "react-router-dom";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/config/index.d.ts
|
|
6
|
+
interface ConfigOptions {
|
|
7
|
+
/** 环境变量 */
|
|
8
|
+
env?: Record<string, any>;
|
|
9
|
+
/**
|
|
10
|
+
* qiankun模式(切换模式后请打开新的窗口)
|
|
11
|
+
* - 'router': 基于路由模式
|
|
12
|
+
* - 'load': 手动加载模式
|
|
13
|
+
*/
|
|
14
|
+
qiankunMode?: 'router' | 'load';
|
|
15
|
+
/** 主题 */
|
|
16
|
+
theme?: ThemeProps;
|
|
17
|
+
/** 国际化 */
|
|
18
|
+
locale?: LocaleProps;
|
|
19
|
+
/** 国际化存储名称 */
|
|
20
|
+
localeStorageKey?: string;
|
|
21
|
+
/** 主题存储名称 */
|
|
22
|
+
themeStorageKey?: string;
|
|
23
|
+
/** Token存储名称 */
|
|
24
|
+
tokenStorageKey?: string;
|
|
25
|
+
/** 登录页路由 */
|
|
26
|
+
loginPath?: string;
|
|
27
|
+
/**
|
|
28
|
+
* 登录后跳转的路由
|
|
29
|
+
* - 优先使用指定值
|
|
30
|
+
* - 其次使用重定向的值
|
|
31
|
+
* - 最后使用菜单中第一项
|
|
32
|
+
*/
|
|
33
|
+
defaultPath?: string;
|
|
34
|
+
/**
|
|
35
|
+
* 自定义路由信息
|
|
36
|
+
* - 目前只支持最外层路由自定义
|
|
37
|
+
* - 会合并到 sdk.app.allRoutes 中
|
|
38
|
+
*/
|
|
39
|
+
customRoutes?: RouteObject[];
|
|
40
|
+
/** Antd 配置 */
|
|
41
|
+
antdConfig?: ConfigProviderProps;
|
|
42
|
+
/** ProLayout 配置 */
|
|
43
|
+
proLayoutConfig?: ProLayoutProps;
|
|
44
|
+
}
|
|
45
|
+
interface ConfigResult extends Required<ConfigOptions> {}
|
|
46
|
+
/**
|
|
47
|
+
* 配置信息
|
|
48
|
+
* - 详情参考 {@link ConfigOptions} {@link ConfigResult}
|
|
49
|
+
* - 配置 localStorage 变量名称
|
|
50
|
+
* - 配置 默认主题、国际化
|
|
51
|
+
* - 配置 默认登录路径、跳转路径、自定义路由
|
|
52
|
+
* - 配置 Antd 配置、ProLayout 配置
|
|
53
|
+
*/
|
|
54
|
+
declare const SdkConfigPlugin: Plugin<'config'>;
|
|
3
55
|
//#endregion
|
|
4
|
-
|
|
56
|
+
//#region src/types.d.ts
|
|
57
|
+
type ThemeProps = 'light' | 'dark';
|
|
58
|
+
type LocaleProps = 'zh-CN' | 'en-US';
|
|
59
|
+
type PluginName = keyof PluginOptions;
|
|
60
|
+
interface PluginOptions {
|
|
61
|
+
/** 配置项插件 */
|
|
62
|
+
config?: ConfigOptions;
|
|
63
|
+
}
|
|
64
|
+
interface PluginResults {
|
|
65
|
+
/** 配置项插件 */
|
|
66
|
+
config: ConfigResult;
|
|
67
|
+
}
|
|
68
|
+
interface Plugin<K extends PluginName> {
|
|
69
|
+
/** 插件名字 */
|
|
70
|
+
name: K;
|
|
71
|
+
/** 插件安装方法 */
|
|
72
|
+
install: (sdk: SdkResult, options?: PluginOptions[K]) => void;
|
|
73
|
+
/** 插件配置项 */
|
|
74
|
+
options?: PluginOptions[K];
|
|
75
|
+
}
|
|
76
|
+
interface SdkBase {
|
|
77
|
+
/** SDK 名称 */
|
|
78
|
+
name: string;
|
|
79
|
+
/** 插件列表 */
|
|
80
|
+
_plugins: Map<string, Plugin<never>>;
|
|
81
|
+
/** 挂载sdk - Window */
|
|
82
|
+
mount: (name: string) => void;
|
|
83
|
+
/** 卸载sdk - Window */
|
|
84
|
+
unmount: () => void;
|
|
85
|
+
/** 使用插件 */
|
|
86
|
+
use: <K extends PluginName>(plugin: Plugin<K>, options?: PluginOptions[K]) => this;
|
|
87
|
+
}
|
|
88
|
+
type SdkResult = SdkBase & PluginResults;
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/core/index.d.ts
|
|
91
|
+
declare class Sdk implements SdkResult {
|
|
92
|
+
name: SdkResult['name'];
|
|
93
|
+
_plugins: SdkResult['_plugins'];
|
|
94
|
+
constructor();
|
|
95
|
+
mount(name: string): void;
|
|
96
|
+
unmount(): void;
|
|
97
|
+
use<K extends keyof PluginOptions>(plugin: Plugin<K>, options?: PluginOptions[K]): this;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* sdk 实例
|
|
101
|
+
* @example sdk.use(SdkPlugin) // 使用插件
|
|
102
|
+
* @example sdk.mount('SdkName') // 挂载到 window 上
|
|
103
|
+
* @example sdk.unmount() // 卸载
|
|
104
|
+
*/
|
|
105
|
+
declare const sdk: Sdk;
|
|
106
|
+
//#endregion
|
|
107
|
+
export { ConfigOptions, ConfigResult, SdkConfigPlugin, sdk };
|
|
5
108
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e
|
|
1
|
+
const e=new class{constructor(){this.name=``,this._plugins=new Map}mount(e){if(e&&window[e])Object.assign(this,window[e]);else{this.name=e;let t=new Proxy(this,{get:(e,t,n)=>e?Reflect.get(e,t,n):null,set:()=>(console.error(`The SDK cannot be modified.`),!1),deleteProperty:()=>(console.error(`The SDK cannot be deleted.`),!1)});window[this.name]=t}}unmount(){this._plugins.clear(),delete window[this.name]}use(e,t){let{name:n,install:r}=e;if(!n)throw Error(`${n} plugin has no name`);if(typeof r!=`function`)throw Error(`${n} plugin is not a function`);return r(this,t),this._plugins.set(n,{...e,options:t}),this}};function t(e){if(!e||typeof e!=`object`)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype||Object.getPrototypeOf(t)===null?Object.prototype.toString.call(e)===`[object Object]`:!1}function n(e){return e===`__proto__`}function r(e,i){let a=Object.keys(i);for(let o=0;o<a.length;o++){let s=a[o];if(n(s))continue;let c=i[s],l=e[s];Array.isArray(c)?Array.isArray(l)?e[s]=r(l,c):e[s]=r([],c):t(c)?t(l)?e[s]=r(l,c):e[s]=r({},c):(l===void 0||c!==void 0)&&(e[s]=c)}return e}const i=`config`,a={name:i,install(e,t={}){e[i]=r({env:{},qiankunMode:`router`,theme:null,locale:null,localeStorageKey:`locale`,themeStorageKey:`theme`,tokenStorageKey:`token`,loginPath:`/login`,defaultPath:``,customRoutes:[],antdConfig:{},proLayoutConfig:{title:`Demo`}},t)}};export{a as SdkConfigPlugin,e as sdk};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["const
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["isPlainObject","value","proto","Object","getPrototypeOf","hasObjectPrototype","prototype","toString","call","isUnsafeProperty","key","isUnsafeProperty","isPlainObject","merge","target","source","sourceKeys","Object","keys","i","length","key","sourceValue","targetValue","Array","isArray","undefined","SdkConfigPlugin: Plugin<'config'>"],"sources":["../../src/core/index.ts","../../../node_modules/.pnpm/es-toolkit@1.39.10/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs","../../../node_modules/.pnpm/es-toolkit@1.39.10/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs","../../../node_modules/.pnpm/es-toolkit@1.39.10/node_modules/es-toolkit/dist/object/merge.mjs","../../src/plugins/config/index.ts"],"sourcesContent":["import { Plugin, PluginOptions, SdkResult } from '@/types';\n\nclass Sdk implements SdkResult {\n name: SdkResult['name'];\n _plugins: SdkResult['_plugins'];\n\n constructor() {\n this.name = '';\n this._plugins = new Map();\n }\n\n mount(name: string) {\n // 如果已经存在同名的sdk实例,则直接返回(子应用)\n if (name && window[name]) {\n Object.assign(this, window[name]); // 合并实例属性\n } else {\n // 否则创建一个新的sdk实例, 并手动挂载到window上 (主应用)\n this.name = name;\n\n // 使用 new Proxy 禁止控制台对sdk属性的操作 (仅第一层属性)\n const _this = new Proxy(this, {\n get: (target, key, receiver) => {\n if (!target) return null;\n return Reflect.get(target, key, receiver);\n },\n set: () => {\n console.error('The SDK cannot be modified.');\n return false;\n },\n deleteProperty: () => {\n console.error('The SDK cannot be deleted.');\n return false;\n },\n });\n\n // 挂载到 Window 上\n window[this.name] = _this;\n }\n }\n\n unmount() {\n // 清空插件\n this._plugins.clear();\n // 删除window上的实例\n delete window[this.name];\n }\n\n use<K extends keyof PluginOptions>(plugin: Plugin<K>, options?: PluginOptions[K]) {\n const { name, install } = plugin;\n\n if (!name) throw new Error(`${name} plugin has no name`);\n\n if (typeof install !== 'function') throw new Error(`${name} plugin is not a function`);\n\n // 插件安装\n install(this as any, options);\n\n // 添加到插件列表\n this._plugins.set(name, { ...plugin, options });\n\n // 链式调用\n return this;\n }\n}\n\n/**\n * sdk 实例\n * @example sdk.use(SdkPlugin) // 使用插件\n * @example sdk.mount('SdkName') // 挂载到 window 上\n * @example sdk.unmount() // 卸载\n */\nconst sdk = new Sdk();\n\nexport { sdk };\n","function isPlainObject(value) {\n if (!value || typeof value !== 'object') {\n return false;\n }\n const proto = Object.getPrototypeOf(value);\n const hasObjectPrototype = proto === null ||\n proto === Object.prototype ||\n Object.getPrototypeOf(proto) === null;\n if (!hasObjectPrototype) {\n return false;\n }\n return Object.prototype.toString.call(value) === '[object Object]';\n}\n\nexport { isPlainObject };\n","function isUnsafeProperty(key) {\n return key === '__proto__';\n}\n\nexport { isUnsafeProperty };\n","import { isUnsafeProperty } from '../_internal/isUnsafeProperty.mjs';\nimport { isPlainObject } from '../predicate/isPlainObject.mjs';\n\nfunction merge(target, source) {\n const sourceKeys = Object.keys(source);\n for (let i = 0; i < sourceKeys.length; i++) {\n const key = sourceKeys[i];\n if (isUnsafeProperty(key)) {\n continue;\n }\n const sourceValue = source[key];\n const targetValue = target[key];\n if (Array.isArray(sourceValue)) {\n if (Array.isArray(targetValue)) {\n target[key] = merge(targetValue, sourceValue);\n }\n else {\n target[key] = merge([], sourceValue);\n }\n }\n else if (isPlainObject(sourceValue)) {\n if (isPlainObject(targetValue)) {\n target[key] = merge(targetValue, sourceValue);\n }\n else {\n target[key] = merge({}, sourceValue);\n }\n }\n else if (targetValue === undefined || sourceValue !== undefined) {\n target[key] = sourceValue;\n }\n }\n return target;\n}\n\nexport { merge };\n","import { LocaleProps, Plugin, ThemeProps } from '@/types';\nimport { ProLayoutProps } from '@ant-design/pro-layout';\nimport { ConfigProviderProps } from 'antd';\nimport { merge } from 'es-toolkit';\nimport { RouteObject } from 'react-router-dom';\n\ninterface ConfigOptions {\n /** 环境变量 */\n env?: Record<string, any>;\n\n /**\n * qiankun模式(切换模式后请打开新的窗口)\n * - 'router': 基于路由模式\n * - 'load': 手动加载模式\n */\n qiankunMode?: 'router' | 'load';\n\n /** 主题 */\n theme?: ThemeProps;\n /** 国际化 */\n locale?: LocaleProps;\n\n /** 国际化存储名称 */\n localeStorageKey?: string;\n /** 主题存储名称 */\n themeStorageKey?: string;\n /** Token存储名称 */\n tokenStorageKey?: string;\n\n /** 登录页路由 */\n loginPath?: string;\n /**\n * 登录后跳转的路由\n * - 优先使用指定值\n * - 其次使用重定向的值\n * - 最后使用菜单中第一项\n */\n defaultPath?: string;\n /**\n * 自定义路由信息\n * - 目前只支持最外层路由自定义\n * - 会合并到 sdk.app.allRoutes 中\n */\n customRoutes?: RouteObject[];\n\n /** Antd 配置 */\n antdConfig?: ConfigProviderProps;\n /** ProLayout 配置 */\n proLayoutConfig?: ProLayoutProps;\n}\n\ninterface ConfigResult extends Required<ConfigOptions> {}\n\n/** 插件名称 */\nconst pluginName = 'config';\n\n/**\n * 配置信息\n * - 详情参考 {@link ConfigOptions} {@link ConfigResult}\n * - 配置 localStorage 变量名称\n * - 配置 默认主题、国际化\n * - 配置 默认登录路径、跳转路径、自定义路由\n * - 配置 Antd 配置、ProLayout 配置\n */\nconst SdkConfigPlugin: Plugin<'config'> = {\n name: pluginName,\n install(sdk, options = {}) {\n // 默认插件配置\n const defaultOptions = {\n env: {},\n\n qiankunMode: 'router',\n\n theme: null,\n locale: null,\n\n localeStorageKey: 'locale',\n themeStorageKey: 'theme',\n tokenStorageKey: 'token',\n\n loginPath: '/login',\n defaultPath: '',\n customRoutes: [],\n\n antdConfig: {},\n proLayoutConfig: {\n title: 'Demo',\n },\n } satisfies ConfigResult;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { ConfigOptions, ConfigResult, SdkConfigPlugin };\n"],"x_google_ignoreList":[1,2,3],"mappings":"AAuEA,MAAM,EAAM,IArEZ,KAA+B,CAI7B,aAAc,CACZ,KAAK,KAAO,GACZ,KAAK,SAAW,IAAI,IAGtB,MAAM,EAAc,CAElB,GAAI,GAAQ,OAAO,GACjB,OAAO,OAAO,KAAM,OAAO,GAAM,KAC5B,CAEL,KAAK,KAAO,EAGZ,IAAM,EAAQ,IAAI,MAAM,KAAM,CAC5B,KAAM,EAAQ,EAAK,IACZ,EACE,QAAQ,IAAI,EAAQ,EAAK,EAAS,CADrB,KAGtB,SACE,QAAQ,MAAM,8BAA8B,CACrC,IAET,oBACE,QAAQ,MAAM,6BAA6B,CACpC,IAEV,CAAC,CAGF,OAAO,KAAK,MAAQ,GAIxB,SAAU,CAER,KAAK,SAAS,OAAO,CAErB,OAAO,OAAO,KAAK,MAGrB,IAAmC,EAAmB,EAA4B,CAChF,GAAM,CAAE,OAAM,WAAY,EAE1B,GAAI,CAAC,EAAM,MAAU,MAAM,GAAG,EAAK,qBAAqB,CAExD,GAAI,OAAO,GAAY,WAAY,MAAU,MAAM,GA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iB,QAEjB,UAAW,SACX,YAAa,GACb,aAAc,EAAE,CAEhB,WAAY,EAAE,CACd,gBAAiB,CACf,MAAO,OACR,CACF,CAEuC,EAAQ,EAEnD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zxiaosi/sdk",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "A micro frontend kit",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@babel/preset-react": "^7.27.1",
|
|
33
33
|
"@rollup/plugin-babel": "^6.0.4",
|
|
34
34
|
"@types/react": "^18.3.12",
|
|
35
|
-
"@types/react-dom": "^18.3.
|
|
35
|
+
"@types/react-dom": "^18.3.1",
|
|
36
36
|
"es-toolkit": "^1.39.10",
|
|
37
37
|
"rolldown": "^1.0.0-beta.40",
|
|
38
38
|
"rolldown-plugin-dts": "^0.16.8",
|