@mx-sose-front/mx-sose-graph 1.0.4 → 1.0.5
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 +9 -1
- package/dist/index.esm.js +7 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +32 -8
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { App, Plugin } from 'vue'
|
|
2
2
|
import GraphView from './view/graph.vue'
|
|
3
3
|
import ElementPlus from 'element-plus'
|
|
4
|
+
import { setActivePinia, type Pinia } from 'pinia'
|
|
4
5
|
// import { pinia } from './store'
|
|
5
6
|
|
|
6
7
|
// 导出组件
|
|
@@ -11,17 +12,40 @@ export { useGraphStore, eventBus } from './store'
|
|
|
11
12
|
|
|
12
13
|
// 导出类型
|
|
13
14
|
export type { Shape, Bounds, Style, NameObject, TaggedValueLabel, Comparent, GraphEvents } from './types'
|
|
14
|
-
|
|
15
|
+
/**
|
|
16
|
+
* 可选的安装参数:允许使用方主动把 pinia 传进来
|
|
17
|
+
*/
|
|
18
|
+
export interface MxSoseGraphOptions {
|
|
19
|
+
pinia?: Pinia
|
|
20
|
+
}
|
|
15
21
|
// 插件安装函数
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
//
|
|
20
|
-
|
|
22
|
+
// 注意:这里给 Plugin 加了一个 [MxSoseGraphOptions?] 的泛型,方便 TS 类型推断
|
|
23
|
+
export const MxSoseGraphPlugin: Plugin<[MxSoseGraphOptions?]> = {
|
|
24
|
+
install(app: App, options?: MxSoseGraphOptions) {
|
|
25
|
+
// 1️⃣ 尝试获取外部应用里的 pinia 实例
|
|
26
|
+
const externalPinia =
|
|
27
|
+
options?.pinia || // 优先使用显式传入的
|
|
28
|
+
(app._context.provides.pinia as Pinia | undefined) || // Vue3 内部提供的
|
|
29
|
+
(app.config.globalProperties.$pinia as Pinia | undefined) // 部分写法下可用
|
|
30
|
+
|
|
31
|
+
if (externalPinia) {
|
|
32
|
+
// 2️⃣ 用「库这份 pinia 模块」设置 activePinia
|
|
33
|
+
setActivePinia(externalPinia)
|
|
34
|
+
} else {
|
|
35
|
+
if (import.meta.env.DEV) {
|
|
36
|
+
console.warn(
|
|
37
|
+
'[mx-sose-graph] 未找到 pinia 实例,请确保:' +
|
|
38
|
+
'1)先 app.use(pinia),2)再 app.use(MxSoseGraphPlugin, { pinia })'
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 3️⃣ 注册组件
|
|
21
44
|
app.component('GraphView', GraphView)
|
|
22
|
-
|
|
45
|
+
|
|
46
|
+
// 4️⃣ 安装 ElementPlus(如果你希望由宿主项目自己安装,也可以删掉这行)
|
|
23
47
|
app.use(ElementPlus)
|
|
24
|
-
}
|
|
48
|
+
},
|
|
25
49
|
}
|
|
26
50
|
|
|
27
51
|
// 默认导出插件
|