@zxiaosi/sdk 0.1.3 → 0.1.4
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/index.d.ts +46 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -48,16 +48,60 @@ interface ConfigResults extends Required<ConfigOptions> {}
|
|
|
48
48
|
*/
|
|
49
49
|
declare const SdkConfigPlugin: Plugin<'config'>;
|
|
50
50
|
//#endregion
|
|
51
|
+
//#region src/plugins/storage/index.d.ts
|
|
52
|
+
interface StorageOptions {
|
|
53
|
+
/** 国际化存储名称 */
|
|
54
|
+
localeKey?: string;
|
|
55
|
+
/** 主题存储名称 */
|
|
56
|
+
themeKey?: string;
|
|
57
|
+
/** Token存储名称 */
|
|
58
|
+
tokenKey?: string;
|
|
59
|
+
}
|
|
60
|
+
interface StorageResults extends Required<StorageOptions> {
|
|
61
|
+
/** 获取当前国际化 */
|
|
62
|
+
getLocale(): LocaleProps;
|
|
63
|
+
/** 设置/切换切换国际化 */
|
|
64
|
+
setLocale(locale: LocaleProps): void;
|
|
65
|
+
/** 清空国际化 */
|
|
66
|
+
clearLocale(): void;
|
|
67
|
+
/** 获取当前主题 */
|
|
68
|
+
getTheme(): ThemeProps;
|
|
69
|
+
/** 设置/切换主题 */
|
|
70
|
+
setTheme(theme: ThemeProps): void;
|
|
71
|
+
/** 清空主题 */
|
|
72
|
+
clearTheme(): void;
|
|
73
|
+
/** 获取当前 Token */
|
|
74
|
+
getToken(): string;
|
|
75
|
+
/** 设置 Token */
|
|
76
|
+
setToken(token: string): void;
|
|
77
|
+
/** 清空 Token */
|
|
78
|
+
clearToken(): void;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 本地缓存
|
|
82
|
+
* - 详情参考 {@link StorageOptions} {@link StorageResults}
|
|
83
|
+
* - 配置 localStorage 变量名称
|
|
84
|
+
* - 提供 国际化、主题、Token 的 get、change、clear 方法
|
|
85
|
+
* @example sdk.storage.getToken() // 获取 Token
|
|
86
|
+
* @example sdk.storage.setTheme('dark') // 设置主题
|
|
87
|
+
* @example sdk.storage.clearLocale() // 清空国际化
|
|
88
|
+
*/
|
|
89
|
+
declare const SdkStoragePlugin: Plugin<'storage'>;
|
|
90
|
+
//#endregion
|
|
51
91
|
//#region src/types.d.ts
|
|
52
92
|
type ThemeProps = 'light' | 'dark' | (string & {});
|
|
53
93
|
type LocaleProps = 'zh-CN' | 'en-US' | (string & {});
|
|
54
94
|
interface PluginOptions {
|
|
55
95
|
/** Sdk 配置信息 */
|
|
56
96
|
config?: ConfigOptions;
|
|
97
|
+
/** 本地缓存 */
|
|
98
|
+
storage?: StorageOptions;
|
|
57
99
|
}
|
|
58
100
|
interface PluginResults {
|
|
59
101
|
/** Sdk 配置信息 */
|
|
60
102
|
config: ConfigResults;
|
|
103
|
+
/** 本地缓存 */
|
|
104
|
+
storage: StorageResults;
|
|
61
105
|
}
|
|
62
106
|
type PluginName = keyof PluginOptions;
|
|
63
107
|
interface Plugin<K extends PluginName> {
|
|
@@ -87,6 +131,7 @@ declare class Sdk implements SdkResult {
|
|
|
87
131
|
name: SdkResult['name'];
|
|
88
132
|
_plugins: SdkResult['_plugins'];
|
|
89
133
|
config: SdkResult['config'];
|
|
134
|
+
storage: SdkResult['storage'];
|
|
90
135
|
constructor();
|
|
91
136
|
mount(name: string): void;
|
|
92
137
|
extend(name: string): void;
|
|
@@ -97,5 +142,5 @@ declare class Sdk implements SdkResult {
|
|
|
97
142
|
*/
|
|
98
143
|
declare const sdk: Sdk;
|
|
99
144
|
//#endregion
|
|
100
|
-
export { type ConfigOptions, type ConfigResults, SdkConfigPlugin, sdk };
|
|
145
|
+
export { type ConfigOptions, type ConfigResults, SdkConfigPlugin, SdkStoragePlugin, type StorageOptions, type StorageResults, sdk };
|
|
101
146
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=new class{name;_plugins;config;constructor(){this.name=``,this._plugins=new Map}mount(e){if(window[e])throw Error(`The SDK already exists - ${e}`);console.log(`%c SDK mounted:`,`color: pink; font-weight: bold;`,e),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}extend(e){if(!window[e])throw Error(`The SDK not found - ${e}`);console.log(`%c SDK extended:`,`color: pink; font-weight: bold;`,e),Object.assign(this,window[e])}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,loginPath:`/login`,defaultPath:``,customRoutes:[],antdConfig:{},proLayoutConfig:{title:`Demo`}},t)}};export{a as SdkConfigPlugin,e as sdk};
|
|
1
|
+
const e=new class{name;_plugins;config;storage;constructor(){this.name=``,this._plugins=new Map}mount(e){if(window[e])throw Error(`The SDK already exists - ${e}`);console.log(`%c SDK mounted:`,`color: pink; font-weight: bold;`,e),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}extend(e){if(!window[e])throw Error(`The SDK not found - ${e}`);console.log(`%c SDK extended:`,`color: pink; font-weight: bold;`,e),Object.assign(this,window[e])}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,loginPath:`/login`,defaultPath:``,customRoutes:[],antdConfig:{},proLayoutConfig:{title:`Demo`}},t)}},o=`storage`,s={name:o,install(e,t={}){e[o]=r({localeKey:`locale`,themeKey:`theme`,tokenKey:`token`,getLocale:()=>localStorage.getItem(e.storage.localeKey),setLocale:t=>{localStorage.setItem(e.storage.localeKey,t)},clearLocale:()=>{localStorage.removeItem(e.storage.localeKey)},getTheme:()=>localStorage.getItem(e.storage.themeKey),setTheme:t=>{localStorage.setItem(e.storage.themeKey,t)},clearTheme:()=>{localStorage.removeItem(e.storage.themeKey)},getToken:()=>localStorage.getItem(e.storage.tokenKey),setToken:t=>{localStorage.setItem(e.storage.tokenKey,t)},clearToken:()=>{localStorage.removeItem(e.storage.tokenKey)}},t)}};export{a as SdkConfigPlugin,s as SdkStoragePlugin,e as sdk};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["SdkConfigPlugin: Plugin<'config'>"],"sources":["../src/core/index.ts","../../node_modules/.pnpm/es-toolkit@1.42.0/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs","../../node_modules/.pnpm/es-toolkit@1.42.0/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs","../../node_modules/.pnpm/es-toolkit@1.42.0/node_modules/es-toolkit/dist/object/merge.mjs","../src/plugins/config/index.ts"],"sourcesContent":["import type { Plugin, PluginOptions, SdkResult } from '@/types';\n\nclass Sdk implements SdkResult {\n name: SdkResult['name'];\n _plugins: SdkResult['_plugins'];\n\n config: SdkResult['config'];\n\n constructor() {\n this.name = '';\n this._plugins = new Map();\n }\n\n mount(name: string) {\n if (window[name]) throw new Error(`The SDK already exists - ${name}`);\n console.log('%c SDK mounted:', 'color: pink; font-weight: bold;', name);\n\n // 设置名称\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 extend(name: string) {\n if (!window[name]) throw new Error(`The SDK not found - ${name}`);\n console.log('%c SDK extended:', 'color: pink; font-weight: bold;', name);\n\n // 合并实例属性\n Object.assign(this, window[name]);\n }\n\n use<K extends keyof PluginOptions>(\n plugin: Plugin<K>,\n options?: PluginOptions[K],\n ) {\n const { name, install } = plugin;\n\n if (!name) throw new Error(`${name} plugin has no name`);\n\n if (typeof install !== 'function')\n throw new Error(`${name} plugin is not a function`);\n\n // 插件安装\n install(this, options);\n\n // 添加到插件列表\n this._plugins.set(name, { ...plugin, options });\n\n // 链式调用\n return this;\n }\n}\n\n/**\n * sdk 实例\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 type { LocaleProps, Plugin, ThemeProps } from '@/types';\nimport type { ProLayoutProps } from '@ant-design/pro-layout';\nimport type { ConfigProviderProps } from 'antd';\nimport { merge } from 'es-toolkit';\nimport type { RouteObject } from 'react-router-dom';\n\ninterface ConfigOptions {\n /** 环境变量(主应用共享给子应用变量) */\n env?: Record<string, any>;\n\n /** 主题 */\n theme?: ThemeProps;\n /** 国际化 */\n locale?: LocaleProps;\n\n /**\n * Qiankun模式(切换模式后请重新打开页面)\n * - router: 基于路由模式\n * - load: 手动加载模式\n */\n qiankunMode?: 'router' | 'load';\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 ConfigResults extends Required<ConfigOptions> {}\n\n/** 插件名称 */\nconst pluginName = 'config';\n\n/**\n * Sdk 配置信息\n * - 详情参考 {@link ConfigOptions} {@link ConfigResults}\n * - 配置 env 环境变量\n * - 配置 默认主题、国际化\n * - 配置 Qiankun 模式\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 loginPath: '/login',\n defaultPath: '',\n customRoutes: [],\n\n antdConfig: {},\n proLayoutConfig: {\n title: 'Demo',\n },\n } satisfies ConfigResults;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { SdkConfigPlugin };\nexport type { ConfigOptions, ConfigResults };\n"],"x_google_ignoreList":[1,2,3],"mappings":"AAyEA,MAAM,EAAM,IAvEZ,KAA+B,CAC7B,KACA,SAEA,OAEA,aAAc,CACZ,KAAK,KAAO,GACZ,KAAK,SAAW,IAAI,IAGtB,MAAM,EAAc,CAClB,GAAI,OAAO,GAAO,MAAU,MAAM,4BAA4B,IAAO,CACrE,QAAQ,IAAI,kBAAmB,kCAAmC,EAAK,CAGvE,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,IAE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A,IAAa,IAAgB,IAAA,MAClD,EAAO,GAAO,GAGtB,OAAO,ECeX,MAAM,EAAa,SAWbA,EAAoC,CACxC,KAAM,EACN,QAAQ,EAAK,EAAU,EAAE,CAAE,CAoBzB,EAAI,GAAc,EAlBK,CACrB,IAAK,EAAE,CAEP,YAAa,SAEb,MAAO,KACP,OAAQ,KAER,UAAW,SACX,YAAa,GACb,aAAc,EAAE,CAEhB,WAAY,EAAE,CACd,gBAAiB,CACf,MAAO,OACR,CACF,CAEuC,EAAQ,EAEnD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["pluginName","SdkConfigPlugin: Plugin<'config'>","SdkStoragePlugin: Plugin<'storage'>","sdk"],"sources":["../src/core/index.ts","../../node_modules/.pnpm/es-toolkit@1.42.0/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs","../../node_modules/.pnpm/es-toolkit@1.42.0/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs","../../node_modules/.pnpm/es-toolkit@1.42.0/node_modules/es-toolkit/dist/object/merge.mjs","../src/plugins/config/index.ts","../src/plugins/storage/index.ts"],"sourcesContent":["import type { Plugin, PluginOptions, SdkResult } from '@/types';\n\nclass Sdk implements SdkResult {\n name: SdkResult['name'];\n _plugins: SdkResult['_plugins'];\n\n config: SdkResult['config'];\n storage: SdkResult['storage'];\n\n constructor() {\n this.name = '';\n this._plugins = new Map();\n }\n\n mount(name: string) {\n if (window[name]) throw new Error(`The SDK already exists - ${name}`);\n console.log('%c SDK mounted:', 'color: pink; font-weight: bold;', name);\n\n // 设置名称\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 extend(name: string) {\n if (!window[name]) throw new Error(`The SDK not found - ${name}`);\n console.log('%c SDK extended:', 'color: pink; font-weight: bold;', name);\n\n // 合并实例属性\n Object.assign(this, window[name]);\n }\n\n use<K extends keyof PluginOptions>(\n plugin: Plugin<K>,\n options?: PluginOptions[K],\n ) {\n const { name, install } = plugin;\n\n if (!name) throw new Error(`${name} plugin has no name`);\n\n if (typeof install !== 'function')\n throw new Error(`${name} plugin is not a function`);\n\n // 插件安装\n install(this, options);\n\n // 添加到插件列表\n this._plugins.set(name, { ...plugin, options });\n\n // 链式调用\n return this;\n }\n}\n\n/**\n * sdk 实例\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 type { LocaleProps, Plugin, ThemeProps } from '@/types';\nimport type { ProLayoutProps } from '@ant-design/pro-layout';\nimport type { ConfigProviderProps } from 'antd';\nimport { merge } from 'es-toolkit';\nimport type { RouteObject } from 'react-router-dom';\n\ninterface ConfigOptions {\n /** 环境变量(主应用共享给子应用变量) */\n env?: Record<string, any>;\n\n /** 主题 */\n theme?: ThemeProps;\n /** 国际化 */\n locale?: LocaleProps;\n\n /**\n * Qiankun模式(切换模式后请重新打开页面)\n * - router: 基于路由模式\n * - load: 手动加载模式\n */\n qiankunMode?: 'router' | 'load';\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 ConfigResults extends Required<ConfigOptions> {}\n\n/** 插件名称 */\nconst pluginName = 'config';\n\n/**\n * Sdk 配置信息\n * - 详情参考 {@link ConfigOptions} {@link ConfigResults}\n * - 配置 env 环境变量\n * - 配置 默认主题、国际化\n * - 配置 Qiankun 模式\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 loginPath: '/login',\n defaultPath: '',\n customRoutes: [],\n\n antdConfig: {},\n proLayoutConfig: {\n title: 'Demo',\n },\n } satisfies ConfigResults;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { SdkConfigPlugin };\nexport type { ConfigOptions, ConfigResults };\n","import type { LocaleProps, Plugin, ThemeProps } from '@/types';\nimport { merge } from 'es-toolkit';\n\ninterface StorageOptions {\n /** 国际化存储名称 */\n localeKey?: string;\n /** 主题存储名称 */\n themeKey?: string;\n /** Token存储名称 */\n tokenKey?: string;\n}\n\ninterface StorageResults extends Required<StorageOptions> {\n /** 获取当前国际化 */\n getLocale(): LocaleProps;\n /** 设置/切换切换国际化 */\n setLocale(locale: LocaleProps): void;\n /** 清空国际化 */\n clearLocale(): void;\n\n /** 获取当前主题 */\n getTheme(): ThemeProps;\n /** 设置/切换主题 */\n setTheme(theme: ThemeProps): void;\n /** 清空主题 */\n clearTheme(): void;\n\n /** 获取当前 Token */\n getToken(): string;\n /** 设置 Token */\n setToken(token: string): void;\n /** 清空 Token */\n clearToken(): void;\n}\n\n/** 插件名称 */\nconst pluginName = 'storage';\n\n/**\n * 本地缓存\n * - 详情参考 {@link StorageOptions} {@link StorageResults}\n * - 配置 localStorage 变量名称\n * - 提供 国际化、主题、Token 的 get、change、clear 方法\n * @example sdk.storage.getToken() // 获取 Token\n * @example sdk.storage.setTheme('dark') // 设置主题\n * @example sdk.storage.clearLocale() // 清空国际化\n */\nconst SdkStoragePlugin: Plugin<'storage'> = {\n name: pluginName,\n install(sdk, options = {}) {\n // 默认插件配置\n const defaultOptions = {\n localeKey: 'locale',\n themeKey: 'theme',\n tokenKey: 'token',\n\n getLocale: () => {\n return localStorage.getItem(sdk.storage.localeKey);\n },\n setLocale: (locale: string) => {\n localStorage.setItem(sdk.storage.localeKey, locale);\n },\n clearLocale: () => {\n localStorage.removeItem(sdk.storage.localeKey);\n },\n getTheme: () => {\n return localStorage.getItem(sdk.storage.themeKey);\n },\n setTheme: (theme: string) => {\n localStorage.setItem(sdk.storage.themeKey, theme);\n },\n clearTheme: () => {\n localStorage.removeItem(sdk.storage.themeKey);\n },\n getToken: () => {\n return localStorage.getItem(sdk.storage.tokenKey);\n },\n setToken: (token: string) => {\n localStorage.setItem(sdk.storage.tokenKey, token);\n },\n clearToken: () => {\n localStorage.removeItem(sdk.storage.tokenKey);\n },\n } satisfies StorageResults;\n\n sdk[pluginName] = merge(defaultOptions, options);\n },\n};\n\nexport { SdkStoragePlugin };\nexport type { StorageOptions, StorageResults };\n"],"x_google_ignoreList":[1,2,3],"mappings":"AA0EA,MAAM,EAAM,IAxEZ,KAA+B,CAC7B,KACA,SAEA,OACA,QAEA,aAAc,CACZ,KAAK,KAAO,GACZ,KAAK,SAAW,IAAI,IAGtB,MAAM,EAAc,CAClB,GAAI,OAAO,GAAO,MAAU,MAAM,4BAA4B,IAAO,CACrE,QAAQ,IAAI,kBAAmB,kCAAmC,EAAK,CAGvE,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,EAGtB,OAAO,EAAc,CACnB,GAAI,CAAC,OAAO,GAAO,MAAU,MAAM,uBAAuB,IAAO,CACjE,QAAQ,IAAI,mBAAoB,kCAAmC,EAAK,CAGxE,OAAO,OAAO,KAAM,OAAO,GAAM,CAGnC,IACE,EACA,EACA,CACA,GAAM,CAAE,OAAM,WAAY,EAE1B,GAAI,CAAC,EAAM,MAAU,MAAM,GAAG,EAAK,qBAAqB,CAExD,GAAI,OAAO,GAAY,WACrB,MAAU,MAAM,GAAG,EAAK,2BAA2B,CASrD,OANA,EAAQ,KAAM,EAAQ,CAGtB,KAAK,SAAS,IAAI,EAAM,CAAE,GAAG,EAAQ,UAAS,CAAC,CAGxC,OCnEX,SAAS,EAAc,EAAO,CAC1B,GAAI,CAAC,GAAS,OAAO,GAAU,SAC3B,MAAO,GAEX,IAAM,EAAQ,OAAO,eAAe,EAAM,CAO1C,OAN2B,IAAU,MACjC,IAAU,OAAO,WACjB,OAAO,eAAe,EAAM,GAAK,KAI9B,OAAO,UAAU,SAAS,KAA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,SAAS,CAEnD,SAAW,GAAkB,CAC3B,aAAa,QAAQA,EAAI,QAAQ,SAAU,EAAM,EAEnD,eAAkB,CAChB,aAAa,WAAWA,EAAI,QAAQ,SAAS,EAE/C,aACS,aAAa,QAAQA,EAAI,QAAQ,SAAS,CAEnD,SAAW,GAAkB,CAC3B,aAAa,QAAQA,EAAI,QAAQ,SAAU,EAAM,EAEnD,eAAkB,CAChB,aAAa,WAAWA,EAAI,QAAQ,SAAS,EAEhD,CAEuC,EAAQ,EAEnD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zxiaosi/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "A micro frontend kit",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"author": "zxiaosi",
|
|
12
|
+
"keywords": ["micro frontend", "qiankun", "vite"],
|
|
12
13
|
"type": "module",
|
|
13
14
|
"main": "dist/index.js",
|
|
14
15
|
"module": "dist/index.js",
|