phecda-vue 2.1.3-alpha.5 → 3.0.0-alpha.7
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 +28 -43
- package/dist/index.js +189 -319
- package/dist/index.mjs +176 -293
- package/package.json +3 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Events, Construct } from 'phecda-core';
|
|
2
|
-
export * from 'phecda-core';
|
|
3
|
-
import { Ref, App, UnwrapNestedRefs } from 'vue';
|
|
4
1
|
import * as _vue_reactivity from '@vue/reactivity';
|
|
5
|
-
import {
|
|
2
|
+
import { Ref, App, UnwrapNestedRefs } from 'vue';
|
|
3
|
+
import { Events, Plugin, Construct } from 'phecda-web';
|
|
4
|
+
export * from 'phecda-web';
|
|
6
5
|
|
|
7
6
|
type ReplaceInstanceValues<I> = {
|
|
8
7
|
[P in keyof I]: I[P] extends (...args: any[]) => any ? I[P] : Ref<I[P]>;
|
|
@@ -10,44 +9,6 @@ type ReplaceInstanceValues<I> = {
|
|
|
10
9
|
type SchemaToObj<S> = {
|
|
11
10
|
[P in keyof S]: S[P] extends object ? SchemaToObj<S[P]> : (S[P] extends string ? any : S[P]);
|
|
12
11
|
};
|
|
13
|
-
interface PhecdaInstance {
|
|
14
|
-
useOMap: Map<any, any>;
|
|
15
|
-
useVMap: WeakMap<any, any>;
|
|
16
|
-
useRMap: WeakMap<any, any>;
|
|
17
|
-
fnMap: WeakMap<any, any>;
|
|
18
|
-
computedMap: WeakMap<any, any>;
|
|
19
|
-
}
|
|
20
|
-
interface PhecdaEmitter {
|
|
21
|
-
on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
22
|
-
off<N extends keyof Events>(eventName: N, cb?: (args: Events[N]) => void): void;
|
|
23
|
-
emit<N extends keyof Events>(eventName: N, param: Events[N]): void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
declare const emitter: PhecdaEmitter;
|
|
27
|
-
|
|
28
|
-
declare const phecdaSymbol: unique symbol;
|
|
29
|
-
declare const interval: any;
|
|
30
|
-
declare function createPhecda(symbol?: string): _vue_reactivity.Raw<{
|
|
31
|
-
install(app: App): void;
|
|
32
|
-
}>;
|
|
33
|
-
declare function setActivePhecda(phecda: PhecdaInstance): void;
|
|
34
|
-
declare function getActivePhecda(): PhecdaInstance;
|
|
35
|
-
declare function getReactiveMap(symbol: string): Map<string, any> | null;
|
|
36
|
-
|
|
37
|
-
type DeepPartial<T> = {
|
|
38
|
-
[K in keyof T]?: DeepPartial<T[K]>;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
declare function useO<T extends Construct>(module: T): UnwrapNestedRefs<InstanceType<T>>;
|
|
42
|
-
declare function useRaw<T extends Construct>(module: T): InstanceType<T>;
|
|
43
|
-
declare function usePatch<T extends Construct>(module: T, Data: DeepPartial<InstanceType<T>>): void;
|
|
44
|
-
declare function useR<T extends Construct>(module: T): UnwrapNestedRefs<InstanceType<T>>;
|
|
45
|
-
declare function useV<T extends Construct>(module: T): ReplaceInstanceValues<InstanceType<T>>;
|
|
46
|
-
declare function useEvent<Key extends keyof Events>(eventName: Key, cb: Handler<Events[Key]>): () => void;
|
|
47
|
-
declare function initialize<M extends Construct>(module: M, deleteOtherProperty?: boolean): InstanceType<M> | void;
|
|
48
|
-
declare function waitUntilInit(...modules: Construct[]): Promise<void>;
|
|
49
|
-
|
|
50
|
-
declare function Isolate(): (target: any) => void;
|
|
51
12
|
|
|
52
13
|
declare const RE: RegExp;
|
|
53
14
|
declare function createFilter<Data extends Record<string, any>>(initState?: Object, option?: {
|
|
@@ -78,4 +39,28 @@ declare class PV {
|
|
|
78
39
|
off<Key extends keyof Events>(type: Key, handler?: (arg: Events[Key]) => void): void;
|
|
79
40
|
}
|
|
80
41
|
|
|
81
|
-
|
|
42
|
+
declare const phecdaSymbol: unique symbol;
|
|
43
|
+
declare function createPhecda(): _vue_reactivity.Raw<{
|
|
44
|
+
plugins: Plugin[];
|
|
45
|
+
install(app: App): void;
|
|
46
|
+
use(...plugins: Plugin[]): any;
|
|
47
|
+
load(state: any): any;
|
|
48
|
+
unmount(): void;
|
|
49
|
+
}>;
|
|
50
|
+
|
|
51
|
+
type DeepPartial<T> = {
|
|
52
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
declare function useO<T extends Construct>(module: T): UnwrapNestedRefs<InstanceType<T>>;
|
|
56
|
+
declare function useRaw<T extends Construct>(module: T): InstanceType<T>;
|
|
57
|
+
declare function usePatch<T extends Construct>(module: T, Data: DeepPartial<InstanceType<T>>): void;
|
|
58
|
+
declare function useR<T extends Construct>(module: T): UnwrapNestedRefs<InstanceType<T>>;
|
|
59
|
+
declare function useV<T extends Construct>(module: T): ReplaceInstanceValues<InstanceType<T>>;
|
|
60
|
+
declare function useEvent<Key extends keyof Events>(eventName: Key, cb: (event: Events[Key]) => void): {
|
|
61
|
+
emit: (arg: Events[Key]) => void;
|
|
62
|
+
cancel: () => void;
|
|
63
|
+
};
|
|
64
|
+
declare function initialize<M extends Construct>(module: M, deleteOtherProperty?: boolean): InstanceType<M> | void;
|
|
65
|
+
|
|
66
|
+
export { PV, RE, createFilter, createPhecda, initialize, phecdaSymbol, useEvent, useO, usePatch, useR, useRaw, useV };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
7
|
var __export = (target, all) => {
|
|
@@ -19,158 +17,183 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
17
|
return to;
|
|
20
18
|
};
|
|
21
19
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
-
mod
|
|
25
|
-
));
|
|
26
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
21
|
|
|
28
22
|
// src/index.ts
|
|
29
23
|
var src_exports = {};
|
|
30
24
|
__export(src_exports, {
|
|
31
|
-
Isolate: () => Isolate,
|
|
32
25
|
PV: () => PV,
|
|
33
26
|
RE: () => RE,
|
|
34
27
|
createFilter: () => createFilter,
|
|
35
28
|
createPhecda: () => createPhecda,
|
|
36
|
-
emitter: () => emitter,
|
|
37
|
-
getActivePhecda: () => getActivePhecda,
|
|
38
|
-
getReactiveMap: () => getReactiveMap,
|
|
39
29
|
initialize: () => initialize,
|
|
40
|
-
interval: () => interval,
|
|
41
30
|
phecdaSymbol: () => phecdaSymbol,
|
|
42
|
-
setActivePhecda: () => setActivePhecda,
|
|
43
31
|
useEvent: () => useEvent,
|
|
44
32
|
useO: () => useO,
|
|
45
33
|
usePatch: () => usePatch,
|
|
46
34
|
useR: () => useR,
|
|
47
35
|
useRaw: () => useRaw,
|
|
48
|
-
useV: () => useV
|
|
49
|
-
waitUntilInit: () => waitUntilInit
|
|
36
|
+
useV: () => useV
|
|
50
37
|
});
|
|
51
38
|
module.exports = __toCommonJS(src_exports);
|
|
52
39
|
|
|
53
|
-
// src/
|
|
54
|
-
var import_mitt = __toESM(require("mitt"));
|
|
55
|
-
var emitter = (0, import_mitt.default)();
|
|
56
|
-
|
|
57
|
-
// src/vue/phecda.ts
|
|
40
|
+
// src/filter.ts
|
|
58
41
|
var import_vue = require("vue");
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
fn(...args);
|
|
92
|
-
emitter.off(eventName, handler);
|
|
93
|
-
}, "handler");
|
|
94
|
-
emitter.on(eventName, handler);
|
|
95
|
-
eventRecord.push([
|
|
96
|
-
eventName,
|
|
97
|
-
handler
|
|
98
|
-
]);
|
|
99
|
-
} else {
|
|
100
|
-
eventRecord.push([
|
|
101
|
-
eventName,
|
|
102
|
-
fn
|
|
103
|
-
]);
|
|
104
|
-
emitter.on(eventName, fn);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
if (!(0, import_phecda_core.getProperty)("storage")) {
|
|
109
|
-
(0, import_phecda_core.injectProperty)("storage", ({ tag, key, instance }) => {
|
|
110
|
-
if (!tag)
|
|
111
|
-
return;
|
|
112
|
-
const initstr = localStorage.getItem(tag);
|
|
113
|
-
if (initstr) {
|
|
114
|
-
const data = JSON.parse(initstr);
|
|
115
|
-
if (key) {
|
|
116
|
-
instance[key] = data;
|
|
117
|
-
} else {
|
|
118
|
-
for (const i in data) {
|
|
119
|
-
if (i)
|
|
120
|
-
instance[i] = data[i];
|
|
42
|
+
var RE = /{{(.*)}}/;
|
|
43
|
+
function createFilter(initState = {}, option = {}) {
|
|
44
|
+
const resolveOption = Object.assign({
|
|
45
|
+
RE,
|
|
46
|
+
exclude: []
|
|
47
|
+
}, option);
|
|
48
|
+
const scope = (0, import_vue.effectScope)(true);
|
|
49
|
+
let data = scope.run(() => (0, import_vue.ref)(initState));
|
|
50
|
+
let store = {};
|
|
51
|
+
function traverse(obj, path) {
|
|
52
|
+
for (const i in obj) {
|
|
53
|
+
if (resolveOption.exclude.includes(i))
|
|
54
|
+
continue;
|
|
55
|
+
const errorPath = path ? `${path}.${i}` : i;
|
|
56
|
+
if (typeof obj[i] === "object" && obj[i])
|
|
57
|
+
traverse(obj[i], errorPath);
|
|
58
|
+
if (typeof obj[i] === "string") {
|
|
59
|
+
if (resolveOption.RE.test(obj[i])) {
|
|
60
|
+
const body = obj[i].replace(resolveOption.RE, (_, s) => {
|
|
61
|
+
return s;
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(obj, i, {
|
|
64
|
+
get() {
|
|
65
|
+
return new Function(...Object.keys(data.value), "_eh", resolveOption.errorHandler ? `try{${resolveOption.needReturn ? "" : "return"} ${body}}catch(e){return _eh(e,"${errorPath}")}` : `${resolveOption.needReturn ? "" : "return"} ${body}`)(...Object.values(data.value), resolveOption.errorHandler);
|
|
66
|
+
},
|
|
67
|
+
set(value) {
|
|
68
|
+
try {
|
|
69
|
+
new Function("_data", "_v", `_data.${body}=_v`)(data.value, value);
|
|
70
|
+
return true;
|
|
71
|
+
} catch (e) {
|
|
72
|
+
resolveOption.errorHandler?.(e);
|
|
73
|
+
return false;
|
|
121
74
|
}
|
|
122
75
|
}
|
|
123
|
-
}
|
|
124
|
-
globalThis.addEventListener("beforeunload", () => {
|
|
125
|
-
localStorage.setItem(tag, JSON.stringify(key ? instance[key] : instance));
|
|
126
76
|
});
|
|
127
|
-
}
|
|
77
|
+
}
|
|
128
78
|
}
|
|
129
|
-
const originUnmount = app.unmount.bind(app);
|
|
130
|
-
app.unmount = () => {
|
|
131
|
-
eventRecord.forEach(([eventName, handler]) => emitter.off(eventName, handler));
|
|
132
|
-
eventRecord = [];
|
|
133
|
-
if (symbol)
|
|
134
|
-
delete window.__PHECDA_VUE__[symbol];
|
|
135
|
-
originUnmount();
|
|
136
|
-
};
|
|
137
79
|
}
|
|
138
|
-
}
|
|
139
|
-
|
|
80
|
+
}
|
|
81
|
+
__name(traverse, "traverse");
|
|
82
|
+
function filter(obj) {
|
|
83
|
+
traverse(obj);
|
|
84
|
+
return obj;
|
|
85
|
+
}
|
|
86
|
+
__name(filter, "filter");
|
|
87
|
+
function setState(key, value) {
|
|
88
|
+
data.value[key] = value;
|
|
89
|
+
}
|
|
90
|
+
__name(setState, "setState");
|
|
91
|
+
function storeState(key, params) {
|
|
92
|
+
store[key] = data.value;
|
|
93
|
+
init(params);
|
|
94
|
+
}
|
|
95
|
+
__name(storeState, "storeState");
|
|
96
|
+
function applyStore(key) {
|
|
97
|
+
if (!store[key])
|
|
98
|
+
return;
|
|
99
|
+
data.value = store[key];
|
|
100
|
+
}
|
|
101
|
+
__name(applyStore, "applyStore");
|
|
102
|
+
function init(params) {
|
|
103
|
+
data.value = params || initState || {};
|
|
104
|
+
}
|
|
105
|
+
__name(init, "init");
|
|
106
|
+
function delState(key) {
|
|
107
|
+
delete data.value[key];
|
|
108
|
+
}
|
|
109
|
+
__name(delState, "delState");
|
|
110
|
+
function clearStore(key) {
|
|
111
|
+
delete store[key];
|
|
112
|
+
}
|
|
113
|
+
__name(clearStore, "clearStore");
|
|
114
|
+
function dispose() {
|
|
115
|
+
data = null;
|
|
116
|
+
store = null;
|
|
117
|
+
scope.stop();
|
|
118
|
+
}
|
|
119
|
+
__name(dispose, "dispose");
|
|
120
|
+
return {
|
|
121
|
+
filter,
|
|
122
|
+
data,
|
|
123
|
+
init,
|
|
124
|
+
setState,
|
|
125
|
+
storeState,
|
|
126
|
+
store,
|
|
127
|
+
applyStore,
|
|
128
|
+
dispose,
|
|
129
|
+
clearStore,
|
|
130
|
+
delState
|
|
131
|
+
};
|
|
140
132
|
}
|
|
141
|
-
__name(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
133
|
+
__name(createFilter, "createFilter");
|
|
134
|
+
|
|
135
|
+
// src/index.ts
|
|
136
|
+
__reExport(src_exports, require("phecda-web"), module.exports);
|
|
137
|
+
|
|
138
|
+
// src/wrapper.ts
|
|
139
|
+
var import_phecda_web = require("phecda-web");
|
|
140
|
+
var PV = class {
|
|
141
|
+
constructor() {
|
|
142
|
+
}
|
|
143
|
+
get tag() {
|
|
144
|
+
return this.__TAG__;
|
|
145
|
+
}
|
|
146
|
+
on(type, handler) {
|
|
147
|
+
import_phecda_web.emitter.on(type, handler);
|
|
148
|
+
}
|
|
149
|
+
emit(type, param) {
|
|
150
|
+
import_phecda_web.emitter.emit(type, param);
|
|
151
|
+
}
|
|
152
|
+
off(type, handler) {
|
|
153
|
+
import_phecda_web.emitter.off(type, handler);
|
|
154
|
+
}
|
|
148
155
|
};
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
156
|
+
__name(PV, "PV");
|
|
157
|
+
|
|
158
|
+
// src/phecda.ts
|
|
159
|
+
var import_vue2 = require("vue");
|
|
160
|
+
var import_phecda_web2 = require("phecda-web");
|
|
161
|
+
var phecdaSymbol = Symbol("phecda");
|
|
162
|
+
function createPhecda() {
|
|
163
|
+
(0, import_phecda_web2.resetActiveInstance)();
|
|
164
|
+
const phecda = (0, import_vue2.markRaw)({
|
|
165
|
+
plugins: [],
|
|
166
|
+
install(app) {
|
|
167
|
+
const instance = (0, import_phecda_web2.getActiveInstance)();
|
|
168
|
+
instance.app = app;
|
|
169
|
+
app.provide(phecdaSymbol, instance);
|
|
170
|
+
app.config.globalProperties.$phecda = instance;
|
|
171
|
+
this.plugins.forEach((p) => p.setup(instance));
|
|
172
|
+
},
|
|
173
|
+
use(...plugins) {
|
|
174
|
+
plugins.forEach((p) => this.plugins.push(p));
|
|
175
|
+
return this;
|
|
176
|
+
},
|
|
177
|
+
load(state) {
|
|
178
|
+
const instance = (0, import_phecda_web2.getActiveInstance)();
|
|
179
|
+
instance.state = state;
|
|
180
|
+
return this;
|
|
181
|
+
},
|
|
182
|
+
unmount() {
|
|
183
|
+
const instance = (0, import_phecda_web2.getActiveInstance)();
|
|
184
|
+
this.plugins.forEach((p) => p.unmount?.(instance));
|
|
185
|
+
}
|
|
163
186
|
});
|
|
164
|
-
return
|
|
187
|
+
return phecda;
|
|
165
188
|
}
|
|
166
|
-
__name(
|
|
189
|
+
__name(createPhecda, "createPhecda");
|
|
167
190
|
|
|
168
|
-
// src/
|
|
169
|
-
var
|
|
170
|
-
var
|
|
191
|
+
// src/composable.ts
|
|
192
|
+
var import_vue4 = require("vue");
|
|
193
|
+
var import_phecda_web3 = require("phecda-web");
|
|
171
194
|
|
|
172
|
-
// src/
|
|
173
|
-
var
|
|
195
|
+
// src/utils.ts
|
|
196
|
+
var import_vue3 = require("vue");
|
|
174
197
|
function isObject(o) {
|
|
175
198
|
return Object.prototype.toString.call(o) === "[object Object]";
|
|
176
199
|
}
|
|
@@ -181,7 +204,7 @@ function mergeReactiveObjects(target, patchToApply) {
|
|
|
181
204
|
continue;
|
|
182
205
|
const subPatch = patchToApply[key];
|
|
183
206
|
const targetValue = target[key];
|
|
184
|
-
if (isObject(targetValue) && isObject(subPatch) && target.hasOwnProperty(key) && !(0,
|
|
207
|
+
if (isObject(targetValue) && isObject(subPatch) && target.hasOwnProperty(key) && !(0, import_vue3.isRef)(subPatch) && !(0, import_vue3.isReactive)(subPatch)) {
|
|
185
208
|
target[key] = mergeReactiveObjects(targetValue, subPatch);
|
|
186
209
|
} else {
|
|
187
210
|
target[key] = subPatch;
|
|
@@ -190,26 +213,6 @@ function mergeReactiveObjects(target, patchToApply) {
|
|
|
190
213
|
return target;
|
|
191
214
|
}
|
|
192
215
|
__name(mergeReactiveObjects, "mergeReactiveObjects");
|
|
193
|
-
function wrapError(target, key, errorHandler) {
|
|
194
|
-
if (isAsyncFunc(target[key])) {
|
|
195
|
-
return (...args) => {
|
|
196
|
-
return target[key].apply(target, args).catch(errorHandler);
|
|
197
|
-
};
|
|
198
|
-
} else {
|
|
199
|
-
return (...args) => {
|
|
200
|
-
try {
|
|
201
|
-
return target[key].apply(target, args);
|
|
202
|
-
} catch (e) {
|
|
203
|
-
return errorHandler(e);
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
__name(wrapError, "wrapError");
|
|
209
|
-
function isAsyncFunc(fn) {
|
|
210
|
-
return fn[Symbol.toStringTag] === "AsyncFunction";
|
|
211
|
-
}
|
|
212
|
-
__name(isAsyncFunc, "isAsyncFunc");
|
|
213
216
|
function createSharedReactive(composable) {
|
|
214
217
|
let subscribers = 0;
|
|
215
218
|
let state;
|
|
@@ -223,34 +226,34 @@ function createSharedReactive(composable) {
|
|
|
223
226
|
return () => {
|
|
224
227
|
subscribers++;
|
|
225
228
|
if (!state) {
|
|
226
|
-
scope = (0,
|
|
229
|
+
scope = (0, import_vue3.effectScope)(true);
|
|
227
230
|
state = scope.run(() => composable());
|
|
228
231
|
}
|
|
229
|
-
(0,
|
|
232
|
+
(0, import_vue3.onScopeDispose)(dispose);
|
|
230
233
|
return state;
|
|
231
234
|
};
|
|
232
235
|
}
|
|
233
236
|
__name(createSharedReactive, "createSharedReactive");
|
|
234
237
|
|
|
235
|
-
// src/
|
|
238
|
+
// src/composable.ts
|
|
236
239
|
function useO(module2) {
|
|
237
|
-
const {
|
|
240
|
+
const { state } = (0, import_phecda_web3.getActiveInstance)();
|
|
238
241
|
if (module2.prototype.__ISOLATE__) {
|
|
239
|
-
const instance = (0,
|
|
240
|
-
instance._promise = (0,
|
|
242
|
+
const instance = (0, import_vue4.reactive)(new module2());
|
|
243
|
+
instance._promise = (0, import_phecda_web3.registerSerial)(instance);
|
|
241
244
|
return instance;
|
|
242
245
|
}
|
|
243
|
-
const tag = (0,
|
|
244
|
-
if (!
|
|
245
|
-
const instance = (0,
|
|
246
|
-
instance._promise = (0,
|
|
247
|
-
|
|
246
|
+
const tag = (0, import_phecda_web3.getTag)(module2);
|
|
247
|
+
if (!(tag in state)) {
|
|
248
|
+
const instance = (0, import_vue4.reactive)(new module2());
|
|
249
|
+
instance._promise = (0, import_phecda_web3.registerSerial)(instance);
|
|
250
|
+
state[tag] = instance;
|
|
248
251
|
}
|
|
249
|
-
return
|
|
252
|
+
return state[tag];
|
|
250
253
|
}
|
|
251
254
|
__name(useO, "useO");
|
|
252
255
|
function useRaw(module2) {
|
|
253
|
-
return (0,
|
|
256
|
+
return (0, import_vue4.toRaw)(useO(module2));
|
|
254
257
|
}
|
|
255
258
|
__name(useRaw, "useRaw");
|
|
256
259
|
function usePatch(module2, Data) {
|
|
@@ -259,20 +262,20 @@ function usePatch(module2, Data) {
|
|
|
259
262
|
}
|
|
260
263
|
__name(usePatch, "usePatch");
|
|
261
264
|
function useR(module2) {
|
|
262
|
-
const {
|
|
265
|
+
const { _r: rmap, _f: fmap } = (0, import_phecda_web3.getActiveInstance)();
|
|
263
266
|
const instance = useO(module2);
|
|
264
|
-
if (
|
|
265
|
-
return
|
|
267
|
+
if (rmap.has(instance))
|
|
268
|
+
return rmap.get(instance);
|
|
266
269
|
const proxy = new Proxy(instance, {
|
|
267
270
|
get(target, key) {
|
|
268
271
|
if (typeof target[key] === "function") {
|
|
269
|
-
if (
|
|
270
|
-
return
|
|
271
|
-
const errorHandler = (0,
|
|
272
|
+
if (fmap.has(target[key]))
|
|
273
|
+
return fmap.get(target[key]);
|
|
274
|
+
const errorHandler = (0, import_phecda_web3.getHandler)(target, key).find((item) => item.error)?.error;
|
|
272
275
|
if (!errorHandler)
|
|
273
276
|
return target[key].bind(target);
|
|
274
|
-
const wrapper = wrapError(target, key, errorHandler);
|
|
275
|
-
|
|
277
|
+
const wrapper = (0, import_phecda_web3.wrapError)(target, key, errorHandler);
|
|
278
|
+
fmap.set(target[key], wrapper);
|
|
276
279
|
return wrapper;
|
|
277
280
|
}
|
|
278
281
|
return target[key];
|
|
@@ -282,33 +285,33 @@ function useR(module2) {
|
|
|
282
285
|
return true;
|
|
283
286
|
}
|
|
284
287
|
});
|
|
285
|
-
|
|
288
|
+
rmap.set(instance, proxy);
|
|
286
289
|
return proxy;
|
|
287
290
|
}
|
|
288
291
|
__name(useR, "useR");
|
|
289
292
|
function useV(module2) {
|
|
290
|
-
const {
|
|
293
|
+
const { _v: vmap, _f: fmap, _c: cmap } = (0, import_phecda_web3.getActiveInstance)();
|
|
291
294
|
const instance = useO(module2);
|
|
292
|
-
if (
|
|
293
|
-
return
|
|
294
|
-
|
|
295
|
+
if (vmap.has(instance))
|
|
296
|
+
return vmap.get(instance);
|
|
297
|
+
cmap.set(instance, {});
|
|
295
298
|
const proxy = new Proxy(instance, {
|
|
296
299
|
get(target, key) {
|
|
297
300
|
if (typeof target[key] === "function") {
|
|
298
|
-
if (
|
|
299
|
-
return
|
|
300
|
-
const errorHandler = (0,
|
|
301
|
+
if (fmap.has(target[key]))
|
|
302
|
+
return fmap.get(target[key]);
|
|
303
|
+
const errorHandler = (0, import_phecda_web3.getHandler)(target, key).find((item) => item.error)?.error;
|
|
301
304
|
if (!errorHandler)
|
|
302
305
|
return target[key].bind(target);
|
|
303
|
-
const wrapper = wrapError(target, key, errorHandler);
|
|
304
|
-
|
|
306
|
+
const wrapper = (0, import_phecda_web3.wrapError)(target, key, errorHandler);
|
|
307
|
+
fmap.set(target[key], wrapper);
|
|
305
308
|
return wrapper;
|
|
306
309
|
}
|
|
307
|
-
const cache =
|
|
310
|
+
const cache = cmap.get(instance);
|
|
308
311
|
if (key in cache)
|
|
309
312
|
return cache[key]();
|
|
310
313
|
cache[key] = createSharedReactive(() => {
|
|
311
|
-
return (0,
|
|
314
|
+
return (0, import_vue4.toRef)(target, key);
|
|
312
315
|
});
|
|
313
316
|
return cache[key]();
|
|
314
317
|
},
|
|
@@ -316,16 +319,19 @@ function useV(module2) {
|
|
|
316
319
|
return false;
|
|
317
320
|
}
|
|
318
321
|
});
|
|
319
|
-
|
|
322
|
+
vmap.set(instance, proxy);
|
|
320
323
|
return proxy;
|
|
321
324
|
}
|
|
322
325
|
__name(useV, "useV");
|
|
323
326
|
function useEvent(eventName, cb) {
|
|
324
|
-
(0,
|
|
325
|
-
emitter.off(eventName, cb);
|
|
327
|
+
(0, import_vue4.onBeforeUnmount)(() => {
|
|
328
|
+
import_phecda_web3.emitter.off(eventName, cb);
|
|
326
329
|
});
|
|
327
|
-
emitter.on(eventName, cb);
|
|
328
|
-
return
|
|
330
|
+
import_phecda_web3.emitter.on(eventName, cb);
|
|
331
|
+
return {
|
|
332
|
+
emit: (arg) => import_phecda_web3.emitter.emit(eventName, arg),
|
|
333
|
+
cancel: () => import_phecda_web3.emitter.off(eventName, cb)
|
|
334
|
+
};
|
|
329
335
|
}
|
|
330
336
|
__name(useEvent, "useEvent");
|
|
331
337
|
function initialize(module2, deleteOtherProperty = true) {
|
|
@@ -340,154 +346,18 @@ function initialize(module2, deleteOtherProperty = true) {
|
|
|
340
346
|
}
|
|
341
347
|
}
|
|
342
348
|
__name(initialize, "initialize");
|
|
343
|
-
async function waitUntilInit(...modules) {
|
|
344
|
-
await Promise.all(modules.map((m) => useO(m)._promise));
|
|
345
|
-
}
|
|
346
|
-
__name(waitUntilInit, "waitUntilInit");
|
|
347
|
-
|
|
348
|
-
// src/vue/decorator.ts
|
|
349
|
-
function Isolate() {
|
|
350
|
-
return (target) => {
|
|
351
|
-
target.prototype.__ISOLATE__ = true;
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
__name(Isolate, "Isolate");
|
|
355
|
-
|
|
356
|
-
// src/filter.ts
|
|
357
|
-
var import_vue4 = require("vue");
|
|
358
|
-
var RE = /{{(.*)}}/;
|
|
359
|
-
function createFilter(initState = {}, option = {}) {
|
|
360
|
-
const resolveOption = Object.assign({
|
|
361
|
-
RE,
|
|
362
|
-
exclude: []
|
|
363
|
-
}, option);
|
|
364
|
-
const scope = (0, import_vue4.effectScope)(true);
|
|
365
|
-
let data = scope.run(() => (0, import_vue4.ref)(initState));
|
|
366
|
-
let store = {};
|
|
367
|
-
function traverse(obj, path) {
|
|
368
|
-
for (const i in obj) {
|
|
369
|
-
if (resolveOption.exclude.includes(i))
|
|
370
|
-
continue;
|
|
371
|
-
const errorPath = path ? `${path}.${i}` : i;
|
|
372
|
-
if (typeof obj[i] === "object" && obj[i])
|
|
373
|
-
traverse(obj[i], errorPath);
|
|
374
|
-
if (typeof obj[i] === "string") {
|
|
375
|
-
if (resolveOption.RE.test(obj[i])) {
|
|
376
|
-
const body = obj[i].replace(resolveOption.RE, (_, s) => {
|
|
377
|
-
return s;
|
|
378
|
-
});
|
|
379
|
-
Object.defineProperty(obj, i, {
|
|
380
|
-
get() {
|
|
381
|
-
return new Function(...Object.keys(data.value), "_eh", resolveOption.errorHandler ? `try{${resolveOption.needReturn ? "" : "return"} ${body}}catch(e){return _eh(e,"${errorPath}")}` : `${resolveOption.needReturn ? "" : "return"} ${body}`)(...Object.values(data.value), resolveOption.errorHandler);
|
|
382
|
-
},
|
|
383
|
-
set(value) {
|
|
384
|
-
try {
|
|
385
|
-
new Function("_data", "_v", `_data.${body}=_v`)(data.value, value);
|
|
386
|
-
return true;
|
|
387
|
-
} catch (e) {
|
|
388
|
-
resolveOption.errorHandler?.(e);
|
|
389
|
-
return false;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
__name(traverse, "traverse");
|
|
398
|
-
function filter(obj) {
|
|
399
|
-
traverse(obj);
|
|
400
|
-
return obj;
|
|
401
|
-
}
|
|
402
|
-
__name(filter, "filter");
|
|
403
|
-
function setState(key, value) {
|
|
404
|
-
data.value[key] = value;
|
|
405
|
-
}
|
|
406
|
-
__name(setState, "setState");
|
|
407
|
-
function storeState(key, params) {
|
|
408
|
-
store[key] = data.value;
|
|
409
|
-
init(params);
|
|
410
|
-
}
|
|
411
|
-
__name(storeState, "storeState");
|
|
412
|
-
function applyStore(key) {
|
|
413
|
-
if (!store[key])
|
|
414
|
-
return;
|
|
415
|
-
data.value = store[key];
|
|
416
|
-
}
|
|
417
|
-
__name(applyStore, "applyStore");
|
|
418
|
-
function init(params) {
|
|
419
|
-
data.value = params || initState || {};
|
|
420
|
-
}
|
|
421
|
-
__name(init, "init");
|
|
422
|
-
function delState(key) {
|
|
423
|
-
delete data.value[key];
|
|
424
|
-
}
|
|
425
|
-
__name(delState, "delState");
|
|
426
|
-
function clearStore(key) {
|
|
427
|
-
delete store[key];
|
|
428
|
-
}
|
|
429
|
-
__name(clearStore, "clearStore");
|
|
430
|
-
function dispose() {
|
|
431
|
-
data = null;
|
|
432
|
-
store = null;
|
|
433
|
-
scope.stop();
|
|
434
|
-
}
|
|
435
|
-
__name(dispose, "dispose");
|
|
436
|
-
return {
|
|
437
|
-
filter,
|
|
438
|
-
data,
|
|
439
|
-
init,
|
|
440
|
-
setState,
|
|
441
|
-
storeState,
|
|
442
|
-
store,
|
|
443
|
-
applyStore,
|
|
444
|
-
dispose,
|
|
445
|
-
clearStore,
|
|
446
|
-
delState
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
__name(createFilter, "createFilter");
|
|
450
|
-
|
|
451
|
-
// src/index.ts
|
|
452
|
-
__reExport(src_exports, require("phecda-core"), module.exports);
|
|
453
|
-
|
|
454
|
-
// src/wrapper.ts
|
|
455
|
-
var PV = class {
|
|
456
|
-
constructor() {
|
|
457
|
-
}
|
|
458
|
-
get tag() {
|
|
459
|
-
return this.__TAG__;
|
|
460
|
-
}
|
|
461
|
-
on(type, handler) {
|
|
462
|
-
emitter.on(type, handler);
|
|
463
|
-
}
|
|
464
|
-
emit(type, param) {
|
|
465
|
-
emitter.emit(type, param);
|
|
466
|
-
}
|
|
467
|
-
off(type, handler) {
|
|
468
|
-
emitter.off(type, handler);
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
__name(PV, "PV");
|
|
472
349
|
// Annotate the CommonJS export names for ESM import in node:
|
|
473
350
|
0 && (module.exports = {
|
|
474
|
-
Isolate,
|
|
475
351
|
PV,
|
|
476
352
|
RE,
|
|
477
353
|
createFilter,
|
|
478
354
|
createPhecda,
|
|
479
|
-
emitter,
|
|
480
|
-
getActivePhecda,
|
|
481
|
-
getReactiveMap,
|
|
482
355
|
initialize,
|
|
483
|
-
interval,
|
|
484
356
|
phecdaSymbol,
|
|
485
|
-
setActivePhecda,
|
|
486
357
|
useEvent,
|
|
487
358
|
useO,
|
|
488
359
|
usePatch,
|
|
489
360
|
useR,
|
|
490
361
|
useRaw,
|
|
491
|
-
useV
|
|
492
|
-
waitUntilInit
|
|
362
|
+
useV
|
|
493
363
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,127 +1,163 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
|
-
// src/
|
|
5
|
-
import
|
|
6
|
-
var
|
|
4
|
+
// src/filter.ts
|
|
5
|
+
import { effectScope, ref } from "vue";
|
|
6
|
+
var RE = /{{(.*)}}/;
|
|
7
|
+
function createFilter(initState = {}, option = {}) {
|
|
8
|
+
const resolveOption = Object.assign({
|
|
9
|
+
RE,
|
|
10
|
+
exclude: []
|
|
11
|
+
}, option);
|
|
12
|
+
const scope = effectScope(true);
|
|
13
|
+
let data = scope.run(() => ref(initState));
|
|
14
|
+
let store = {};
|
|
15
|
+
function traverse(obj, path) {
|
|
16
|
+
for (const i in obj) {
|
|
17
|
+
if (resolveOption.exclude.includes(i))
|
|
18
|
+
continue;
|
|
19
|
+
const errorPath = path ? `${path}.${i}` : i;
|
|
20
|
+
if (typeof obj[i] === "object" && obj[i])
|
|
21
|
+
traverse(obj[i], errorPath);
|
|
22
|
+
if (typeof obj[i] === "string") {
|
|
23
|
+
if (resolveOption.RE.test(obj[i])) {
|
|
24
|
+
const body = obj[i].replace(resolveOption.RE, (_, s) => {
|
|
25
|
+
return s;
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(obj, i, {
|
|
28
|
+
get() {
|
|
29
|
+
return new Function(...Object.keys(data.value), "_eh", resolveOption.errorHandler ? `try{${resolveOption.needReturn ? "" : "return"} ${body}}catch(e){return _eh(e,"${errorPath}")}` : `${resolveOption.needReturn ? "" : "return"} ${body}`)(...Object.values(data.value), resolveOption.errorHandler);
|
|
30
|
+
},
|
|
31
|
+
set(value) {
|
|
32
|
+
try {
|
|
33
|
+
new Function("_data", "_v", `_data.${body}=_v`)(data.value, value);
|
|
34
|
+
return true;
|
|
35
|
+
} catch (e) {
|
|
36
|
+
resolveOption.errorHandler?.(e);
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
__name(traverse, "traverse");
|
|
46
|
+
function filter(obj) {
|
|
47
|
+
traverse(obj);
|
|
48
|
+
return obj;
|
|
49
|
+
}
|
|
50
|
+
__name(filter, "filter");
|
|
51
|
+
function setState(key, value) {
|
|
52
|
+
data.value[key] = value;
|
|
53
|
+
}
|
|
54
|
+
__name(setState, "setState");
|
|
55
|
+
function storeState(key, params) {
|
|
56
|
+
store[key] = data.value;
|
|
57
|
+
init(params);
|
|
58
|
+
}
|
|
59
|
+
__name(storeState, "storeState");
|
|
60
|
+
function applyStore(key) {
|
|
61
|
+
if (!store[key])
|
|
62
|
+
return;
|
|
63
|
+
data.value = store[key];
|
|
64
|
+
}
|
|
65
|
+
__name(applyStore, "applyStore");
|
|
66
|
+
function init(params) {
|
|
67
|
+
data.value = params || initState || {};
|
|
68
|
+
}
|
|
69
|
+
__name(init, "init");
|
|
70
|
+
function delState(key) {
|
|
71
|
+
delete data.value[key];
|
|
72
|
+
}
|
|
73
|
+
__name(delState, "delState");
|
|
74
|
+
function clearStore(key) {
|
|
75
|
+
delete store[key];
|
|
76
|
+
}
|
|
77
|
+
__name(clearStore, "clearStore");
|
|
78
|
+
function dispose() {
|
|
79
|
+
data = null;
|
|
80
|
+
store = null;
|
|
81
|
+
scope.stop();
|
|
82
|
+
}
|
|
83
|
+
__name(dispose, "dispose");
|
|
84
|
+
return {
|
|
85
|
+
filter,
|
|
86
|
+
data,
|
|
87
|
+
init,
|
|
88
|
+
setState,
|
|
89
|
+
storeState,
|
|
90
|
+
store,
|
|
91
|
+
applyStore,
|
|
92
|
+
dispose,
|
|
93
|
+
clearStore,
|
|
94
|
+
delState
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
__name(createFilter, "createFilter");
|
|
98
|
+
|
|
99
|
+
// src/index.ts
|
|
100
|
+
export * from "phecda-web";
|
|
7
101
|
|
|
8
|
-
// src/
|
|
102
|
+
// src/wrapper.ts
|
|
103
|
+
import { emitter } from "phecda-web";
|
|
104
|
+
var PV = class {
|
|
105
|
+
constructor() {
|
|
106
|
+
}
|
|
107
|
+
get tag() {
|
|
108
|
+
return this.__TAG__;
|
|
109
|
+
}
|
|
110
|
+
on(type, handler) {
|
|
111
|
+
emitter.on(type, handler);
|
|
112
|
+
}
|
|
113
|
+
emit(type, param) {
|
|
114
|
+
emitter.emit(type, param);
|
|
115
|
+
}
|
|
116
|
+
off(type, handler) {
|
|
117
|
+
emitter.off(type, handler);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
__name(PV, "PV");
|
|
121
|
+
|
|
122
|
+
// src/phecda.ts
|
|
9
123
|
import { markRaw } from "vue";
|
|
10
|
-
import {
|
|
124
|
+
import { getActiveInstance, resetActiveInstance } from "phecda-web";
|
|
11
125
|
var phecdaSymbol = Symbol("phecda");
|
|
12
|
-
|
|
13
|
-
|
|
126
|
+
function createPhecda() {
|
|
127
|
+
resetActiveInstance();
|
|
14
128
|
const phecda = markRaw({
|
|
129
|
+
plugins: [],
|
|
15
130
|
install(app) {
|
|
16
|
-
|
|
17
|
-
app
|
|
18
|
-
app.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
let eventRecord = [];
|
|
37
|
-
if (!getProperty("watcher")) {
|
|
38
|
-
injectProperty("watcher", ({ eventName, instance, key, options }) => {
|
|
39
|
-
const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
|
|
40
|
-
if (options?.once) {
|
|
41
|
-
const handler = /* @__PURE__ */ __name((...args) => {
|
|
42
|
-
fn(...args);
|
|
43
|
-
emitter.off(eventName, handler);
|
|
44
|
-
}, "handler");
|
|
45
|
-
emitter.on(eventName, handler);
|
|
46
|
-
eventRecord.push([
|
|
47
|
-
eventName,
|
|
48
|
-
handler
|
|
49
|
-
]);
|
|
50
|
-
} else {
|
|
51
|
-
eventRecord.push([
|
|
52
|
-
eventName,
|
|
53
|
-
fn
|
|
54
|
-
]);
|
|
55
|
-
emitter.on(eventName, fn);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
if (!getProperty("storage")) {
|
|
60
|
-
injectProperty("storage", ({ tag, key, instance }) => {
|
|
61
|
-
if (!tag)
|
|
62
|
-
return;
|
|
63
|
-
const initstr = localStorage.getItem(tag);
|
|
64
|
-
if (initstr) {
|
|
65
|
-
const data = JSON.parse(initstr);
|
|
66
|
-
if (key) {
|
|
67
|
-
instance[key] = data;
|
|
68
|
-
} else {
|
|
69
|
-
for (const i in data) {
|
|
70
|
-
if (i)
|
|
71
|
-
instance[i] = data[i];
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
globalThis.addEventListener("beforeunload", () => {
|
|
76
|
-
localStorage.setItem(tag, JSON.stringify(key ? instance[key] : instance));
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
const originUnmount = app.unmount.bind(app);
|
|
81
|
-
app.unmount = () => {
|
|
82
|
-
eventRecord.forEach(([eventName, handler]) => emitter.off(eventName, handler));
|
|
83
|
-
eventRecord = [];
|
|
84
|
-
if (symbol)
|
|
85
|
-
delete window.__PHECDA_VUE__[symbol];
|
|
86
|
-
originUnmount();
|
|
87
|
-
};
|
|
131
|
+
const instance = getActiveInstance();
|
|
132
|
+
instance.app = app;
|
|
133
|
+
app.provide(phecdaSymbol, instance);
|
|
134
|
+
app.config.globalProperties.$phecda = instance;
|
|
135
|
+
this.plugins.forEach((p) => p.setup(instance));
|
|
136
|
+
},
|
|
137
|
+
use(...plugins) {
|
|
138
|
+
plugins.forEach((p) => this.plugins.push(p));
|
|
139
|
+
return this;
|
|
140
|
+
},
|
|
141
|
+
load(state) {
|
|
142
|
+
const instance = getActiveInstance();
|
|
143
|
+
instance.state = state;
|
|
144
|
+
return this;
|
|
145
|
+
},
|
|
146
|
+
unmount() {
|
|
147
|
+
const instance = getActiveInstance();
|
|
148
|
+
this.plugins.forEach((p) => p.unmount?.(instance));
|
|
88
149
|
}
|
|
89
150
|
});
|
|
90
151
|
return phecda;
|
|
91
152
|
}
|
|
92
153
|
__name(createPhecda, "createPhecda");
|
|
93
|
-
var activePhecda = {
|
|
94
|
-
useVMap: /* @__PURE__ */ new WeakMap(),
|
|
95
|
-
useOMap: /* @__PURE__ */ new Map(),
|
|
96
|
-
useRMap: /* @__PURE__ */ new WeakMap(),
|
|
97
|
-
fnMap: /* @__PURE__ */ new WeakMap(),
|
|
98
|
-
computedMap: /* @__PURE__ */ new WeakMap()
|
|
99
|
-
};
|
|
100
|
-
function setActivePhecda(phecda) {
|
|
101
|
-
activePhecda = phecda;
|
|
102
|
-
}
|
|
103
|
-
__name(setActivePhecda, "setActivePhecda");
|
|
104
|
-
function getActivePhecda() {
|
|
105
|
-
return activePhecda;
|
|
106
|
-
}
|
|
107
|
-
__name(getActivePhecda, "getActivePhecda");
|
|
108
|
-
function getReactiveMap(symbol) {
|
|
109
|
-
if (!window.__PHECDA_VUE__?.[symbol])
|
|
110
|
-
return null;
|
|
111
|
-
const ret = /* @__PURE__ */ new Map();
|
|
112
|
-
window.__PHECDA_VUE__[symbol].snapshot.forEach(({ key, value }) => {
|
|
113
|
-
ret.set(key, value);
|
|
114
|
-
});
|
|
115
|
-
return ret;
|
|
116
|
-
}
|
|
117
|
-
__name(getReactiveMap, "getReactiveMap");
|
|
118
154
|
|
|
119
|
-
// src/
|
|
155
|
+
// src/composable.ts
|
|
120
156
|
import { onBeforeUnmount, reactive, toRaw, toRef } from "vue";
|
|
121
|
-
import {
|
|
157
|
+
import { emitter as emitter2, getActiveInstance as getActiveInstance2, getHandler, getTag, registerSerial, wrapError } from "phecda-web";
|
|
122
158
|
|
|
123
|
-
// src/
|
|
124
|
-
import { effectScope, isReactive, isRef, onScopeDispose } from "vue";
|
|
159
|
+
// src/utils.ts
|
|
160
|
+
import { effectScope as effectScope2, isReactive, isRef, onScopeDispose } from "vue";
|
|
125
161
|
function isObject(o) {
|
|
126
162
|
return Object.prototype.toString.call(o) === "[object Object]";
|
|
127
163
|
}
|
|
@@ -141,26 +177,6 @@ function mergeReactiveObjects(target, patchToApply) {
|
|
|
141
177
|
return target;
|
|
142
178
|
}
|
|
143
179
|
__name(mergeReactiveObjects, "mergeReactiveObjects");
|
|
144
|
-
function wrapError(target, key, errorHandler) {
|
|
145
|
-
if (isAsyncFunc(target[key])) {
|
|
146
|
-
return (...args) => {
|
|
147
|
-
return target[key].apply(target, args).catch(errorHandler);
|
|
148
|
-
};
|
|
149
|
-
} else {
|
|
150
|
-
return (...args) => {
|
|
151
|
-
try {
|
|
152
|
-
return target[key].apply(target, args);
|
|
153
|
-
} catch (e) {
|
|
154
|
-
return errorHandler(e);
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
__name(wrapError, "wrapError");
|
|
160
|
-
function isAsyncFunc(fn) {
|
|
161
|
-
return fn[Symbol.toStringTag] === "AsyncFunction";
|
|
162
|
-
}
|
|
163
|
-
__name(isAsyncFunc, "isAsyncFunc");
|
|
164
180
|
function createSharedReactive(composable) {
|
|
165
181
|
let subscribers = 0;
|
|
166
182
|
let state;
|
|
@@ -174,7 +190,7 @@ function createSharedReactive(composable) {
|
|
|
174
190
|
return () => {
|
|
175
191
|
subscribers++;
|
|
176
192
|
if (!state) {
|
|
177
|
-
scope =
|
|
193
|
+
scope = effectScope2(true);
|
|
178
194
|
state = scope.run(() => composable());
|
|
179
195
|
}
|
|
180
196
|
onScopeDispose(dispose);
|
|
@@ -183,21 +199,21 @@ function createSharedReactive(composable) {
|
|
|
183
199
|
}
|
|
184
200
|
__name(createSharedReactive, "createSharedReactive");
|
|
185
201
|
|
|
186
|
-
// src/
|
|
202
|
+
// src/composable.ts
|
|
187
203
|
function useO(module) {
|
|
188
|
-
const {
|
|
204
|
+
const { state } = getActiveInstance2();
|
|
189
205
|
if (module.prototype.__ISOLATE__) {
|
|
190
206
|
const instance = reactive(new module());
|
|
191
|
-
instance._promise =
|
|
207
|
+
instance._promise = registerSerial(instance);
|
|
192
208
|
return instance;
|
|
193
209
|
}
|
|
194
|
-
const tag =
|
|
195
|
-
if (!
|
|
210
|
+
const tag = getTag(module);
|
|
211
|
+
if (!(tag in state)) {
|
|
196
212
|
const instance = reactive(new module());
|
|
197
|
-
instance._promise =
|
|
198
|
-
|
|
213
|
+
instance._promise = registerSerial(instance);
|
|
214
|
+
state[tag] = instance;
|
|
199
215
|
}
|
|
200
|
-
return
|
|
216
|
+
return state[tag];
|
|
201
217
|
}
|
|
202
218
|
__name(useO, "useO");
|
|
203
219
|
function useRaw(module) {
|
|
@@ -210,20 +226,20 @@ function usePatch(module, Data) {
|
|
|
210
226
|
}
|
|
211
227
|
__name(usePatch, "usePatch");
|
|
212
228
|
function useR(module) {
|
|
213
|
-
const {
|
|
229
|
+
const { _r: rmap, _f: fmap } = getActiveInstance2();
|
|
214
230
|
const instance = useO(module);
|
|
215
|
-
if (
|
|
216
|
-
return
|
|
231
|
+
if (rmap.has(instance))
|
|
232
|
+
return rmap.get(instance);
|
|
217
233
|
const proxy = new Proxy(instance, {
|
|
218
234
|
get(target, key) {
|
|
219
235
|
if (typeof target[key] === "function") {
|
|
220
|
-
if (
|
|
221
|
-
return
|
|
236
|
+
if (fmap.has(target[key]))
|
|
237
|
+
return fmap.get(target[key]);
|
|
222
238
|
const errorHandler = getHandler(target, key).find((item) => item.error)?.error;
|
|
223
239
|
if (!errorHandler)
|
|
224
240
|
return target[key].bind(target);
|
|
225
241
|
const wrapper = wrapError(target, key, errorHandler);
|
|
226
|
-
|
|
242
|
+
fmap.set(target[key], wrapper);
|
|
227
243
|
return wrapper;
|
|
228
244
|
}
|
|
229
245
|
return target[key];
|
|
@@ -233,29 +249,29 @@ function useR(module) {
|
|
|
233
249
|
return true;
|
|
234
250
|
}
|
|
235
251
|
});
|
|
236
|
-
|
|
252
|
+
rmap.set(instance, proxy);
|
|
237
253
|
return proxy;
|
|
238
254
|
}
|
|
239
255
|
__name(useR, "useR");
|
|
240
256
|
function useV(module) {
|
|
241
|
-
const {
|
|
257
|
+
const { _v: vmap, _f: fmap, _c: cmap } = getActiveInstance2();
|
|
242
258
|
const instance = useO(module);
|
|
243
|
-
if (
|
|
244
|
-
return
|
|
245
|
-
|
|
259
|
+
if (vmap.has(instance))
|
|
260
|
+
return vmap.get(instance);
|
|
261
|
+
cmap.set(instance, {});
|
|
246
262
|
const proxy = new Proxy(instance, {
|
|
247
263
|
get(target, key) {
|
|
248
264
|
if (typeof target[key] === "function") {
|
|
249
|
-
if (
|
|
250
|
-
return
|
|
265
|
+
if (fmap.has(target[key]))
|
|
266
|
+
return fmap.get(target[key]);
|
|
251
267
|
const errorHandler = getHandler(target, key).find((item) => item.error)?.error;
|
|
252
268
|
if (!errorHandler)
|
|
253
269
|
return target[key].bind(target);
|
|
254
270
|
const wrapper = wrapError(target, key, errorHandler);
|
|
255
|
-
|
|
271
|
+
fmap.set(target[key], wrapper);
|
|
256
272
|
return wrapper;
|
|
257
273
|
}
|
|
258
|
-
const cache =
|
|
274
|
+
const cache = cmap.get(instance);
|
|
259
275
|
if (key in cache)
|
|
260
276
|
return cache[key]();
|
|
261
277
|
cache[key] = createSharedReactive(() => {
|
|
@@ -267,16 +283,19 @@ function useV(module) {
|
|
|
267
283
|
return false;
|
|
268
284
|
}
|
|
269
285
|
});
|
|
270
|
-
|
|
286
|
+
vmap.set(instance, proxy);
|
|
271
287
|
return proxy;
|
|
272
288
|
}
|
|
273
289
|
__name(useV, "useV");
|
|
274
290
|
function useEvent(eventName, cb) {
|
|
275
291
|
onBeforeUnmount(() => {
|
|
276
|
-
|
|
292
|
+
emitter2.off(eventName, cb);
|
|
277
293
|
});
|
|
278
|
-
|
|
279
|
-
return
|
|
294
|
+
emitter2.on(eventName, cb);
|
|
295
|
+
return {
|
|
296
|
+
emit: (arg) => emitter2.emit(eventName, arg),
|
|
297
|
+
cancel: () => emitter2.off(eventName, cb)
|
|
298
|
+
};
|
|
280
299
|
}
|
|
281
300
|
__name(useEvent, "useEvent");
|
|
282
301
|
function initialize(module, deleteOtherProperty = true) {
|
|
@@ -291,153 +310,17 @@ function initialize(module, deleteOtherProperty = true) {
|
|
|
291
310
|
}
|
|
292
311
|
}
|
|
293
312
|
__name(initialize, "initialize");
|
|
294
|
-
async function waitUntilInit(...modules) {
|
|
295
|
-
await Promise.all(modules.map((m) => useO(m)._promise));
|
|
296
|
-
}
|
|
297
|
-
__name(waitUntilInit, "waitUntilInit");
|
|
298
|
-
|
|
299
|
-
// src/vue/decorator.ts
|
|
300
|
-
function Isolate() {
|
|
301
|
-
return (target) => {
|
|
302
|
-
target.prototype.__ISOLATE__ = true;
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
__name(Isolate, "Isolate");
|
|
306
|
-
|
|
307
|
-
// src/filter.ts
|
|
308
|
-
import { effectScope as effectScope2, ref } from "vue";
|
|
309
|
-
var RE = /{{(.*)}}/;
|
|
310
|
-
function createFilter(initState = {}, option = {}) {
|
|
311
|
-
const resolveOption = Object.assign({
|
|
312
|
-
RE,
|
|
313
|
-
exclude: []
|
|
314
|
-
}, option);
|
|
315
|
-
const scope = effectScope2(true);
|
|
316
|
-
let data = scope.run(() => ref(initState));
|
|
317
|
-
let store = {};
|
|
318
|
-
function traverse(obj, path) {
|
|
319
|
-
for (const i in obj) {
|
|
320
|
-
if (resolveOption.exclude.includes(i))
|
|
321
|
-
continue;
|
|
322
|
-
const errorPath = path ? `${path}.${i}` : i;
|
|
323
|
-
if (typeof obj[i] === "object" && obj[i])
|
|
324
|
-
traverse(obj[i], errorPath);
|
|
325
|
-
if (typeof obj[i] === "string") {
|
|
326
|
-
if (resolveOption.RE.test(obj[i])) {
|
|
327
|
-
const body = obj[i].replace(resolveOption.RE, (_, s) => {
|
|
328
|
-
return s;
|
|
329
|
-
});
|
|
330
|
-
Object.defineProperty(obj, i, {
|
|
331
|
-
get() {
|
|
332
|
-
return new Function(...Object.keys(data.value), "_eh", resolveOption.errorHandler ? `try{${resolveOption.needReturn ? "" : "return"} ${body}}catch(e){return _eh(e,"${errorPath}")}` : `${resolveOption.needReturn ? "" : "return"} ${body}`)(...Object.values(data.value), resolveOption.errorHandler);
|
|
333
|
-
},
|
|
334
|
-
set(value) {
|
|
335
|
-
try {
|
|
336
|
-
new Function("_data", "_v", `_data.${body}=_v`)(data.value, value);
|
|
337
|
-
return true;
|
|
338
|
-
} catch (e) {
|
|
339
|
-
resolveOption.errorHandler?.(e);
|
|
340
|
-
return false;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
__name(traverse, "traverse");
|
|
349
|
-
function filter(obj) {
|
|
350
|
-
traverse(obj);
|
|
351
|
-
return obj;
|
|
352
|
-
}
|
|
353
|
-
__name(filter, "filter");
|
|
354
|
-
function setState(key, value) {
|
|
355
|
-
data.value[key] = value;
|
|
356
|
-
}
|
|
357
|
-
__name(setState, "setState");
|
|
358
|
-
function storeState(key, params) {
|
|
359
|
-
store[key] = data.value;
|
|
360
|
-
init(params);
|
|
361
|
-
}
|
|
362
|
-
__name(storeState, "storeState");
|
|
363
|
-
function applyStore(key) {
|
|
364
|
-
if (!store[key])
|
|
365
|
-
return;
|
|
366
|
-
data.value = store[key];
|
|
367
|
-
}
|
|
368
|
-
__name(applyStore, "applyStore");
|
|
369
|
-
function init(params) {
|
|
370
|
-
data.value = params || initState || {};
|
|
371
|
-
}
|
|
372
|
-
__name(init, "init");
|
|
373
|
-
function delState(key) {
|
|
374
|
-
delete data.value[key];
|
|
375
|
-
}
|
|
376
|
-
__name(delState, "delState");
|
|
377
|
-
function clearStore(key) {
|
|
378
|
-
delete store[key];
|
|
379
|
-
}
|
|
380
|
-
__name(clearStore, "clearStore");
|
|
381
|
-
function dispose() {
|
|
382
|
-
data = null;
|
|
383
|
-
store = null;
|
|
384
|
-
scope.stop();
|
|
385
|
-
}
|
|
386
|
-
__name(dispose, "dispose");
|
|
387
|
-
return {
|
|
388
|
-
filter,
|
|
389
|
-
data,
|
|
390
|
-
init,
|
|
391
|
-
setState,
|
|
392
|
-
storeState,
|
|
393
|
-
store,
|
|
394
|
-
applyStore,
|
|
395
|
-
dispose,
|
|
396
|
-
clearStore,
|
|
397
|
-
delState
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
__name(createFilter, "createFilter");
|
|
401
|
-
|
|
402
|
-
// src/index.ts
|
|
403
|
-
export * from "phecda-core";
|
|
404
|
-
|
|
405
|
-
// src/wrapper.ts
|
|
406
|
-
var PV = class {
|
|
407
|
-
constructor() {
|
|
408
|
-
}
|
|
409
|
-
get tag() {
|
|
410
|
-
return this.__TAG__;
|
|
411
|
-
}
|
|
412
|
-
on(type, handler) {
|
|
413
|
-
emitter.on(type, handler);
|
|
414
|
-
}
|
|
415
|
-
emit(type, param) {
|
|
416
|
-
emitter.emit(type, param);
|
|
417
|
-
}
|
|
418
|
-
off(type, handler) {
|
|
419
|
-
emitter.off(type, handler);
|
|
420
|
-
}
|
|
421
|
-
};
|
|
422
|
-
__name(PV, "PV");
|
|
423
313
|
export {
|
|
424
|
-
Isolate,
|
|
425
314
|
PV,
|
|
426
315
|
RE,
|
|
427
316
|
createFilter,
|
|
428
317
|
createPhecda,
|
|
429
|
-
emitter,
|
|
430
|
-
getActivePhecda,
|
|
431
|
-
getReactiveMap,
|
|
432
318
|
initialize,
|
|
433
|
-
interval,
|
|
434
319
|
phecdaSymbol,
|
|
435
|
-
setActivePhecda,
|
|
436
320
|
useEvent,
|
|
437
321
|
useO,
|
|
438
322
|
usePatch,
|
|
439
323
|
useR,
|
|
440
324
|
useRaw,
|
|
441
|
-
useV
|
|
442
|
-
waitUntilInit
|
|
325
|
+
useV
|
|
443
326
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-vue",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "provide
|
|
3
|
+
"version": "3.0.0-alpha.7",
|
|
4
|
+
"description": "provide phecda function to vue",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -12,9 +12,8 @@
|
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"mitt": "^3.0.0",
|
|
16
15
|
"vue": "^3.2.45",
|
|
17
|
-
"phecda-
|
|
16
|
+
"phecda-web": "1.0.1-alpha.1"
|
|
18
17
|
},
|
|
19
18
|
"devDependencies": {
|
|
20
19
|
"tsup": "^6.5.0"
|