phecda-vue 2.1.3-alpha.5 → 3.0.0-alpha.11
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 +26 -43
- package/dist/index.js +188 -319
- package/dist/index.mjs +175 -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, 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,26 @@ 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
|
+
install(app: App): void;
|
|
45
|
+
load(state: any): any;
|
|
46
|
+
unmount(): Promise<void>;
|
|
47
|
+
}>;
|
|
48
|
+
|
|
49
|
+
type DeepPartial<T> = {
|
|
50
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
declare function useO<T extends Construct>(module: T): UnwrapNestedRefs<InstanceType<T>>;
|
|
54
|
+
declare function useRaw<T extends Construct>(module: T): InstanceType<T>;
|
|
55
|
+
declare function usePatch<T extends Construct>(module: T, Data: DeepPartial<InstanceType<T>>): void;
|
|
56
|
+
declare function useR<T extends Construct>(module: T): UnwrapNestedRefs<InstanceType<T>>;
|
|
57
|
+
declare function useV<T extends Construct>(module: T): ReplaceInstanceValues<InstanceType<T>>;
|
|
58
|
+
declare function useEvent<Key extends keyof Events>(eventName: Key, cb: (event: Events[Key]) => void): {
|
|
59
|
+
emit: (arg: Events[Key]) => void;
|
|
60
|
+
cancel: () => void;
|
|
61
|
+
};
|
|
62
|
+
declare function initialize<M extends Construct>(module: M, deleteOtherProperty?: boolean): InstanceType<M> | void;
|
|
63
|
+
|
|
64
|
+
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,178 @@ 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
|
+
install(app) {
|
|
166
|
+
const instance = (0, import_phecda_web2.getActiveInstance)();
|
|
167
|
+
instance.app = app;
|
|
168
|
+
app.provide(phecdaSymbol, instance);
|
|
169
|
+
app.config.globalProperties.$phecda = instance;
|
|
170
|
+
},
|
|
171
|
+
load(state) {
|
|
172
|
+
const instance = (0, import_phecda_web2.getActiveInstance)();
|
|
173
|
+
instance.state = state;
|
|
174
|
+
return this;
|
|
175
|
+
},
|
|
176
|
+
async unmount() {
|
|
177
|
+
const { state } = (0, import_phecda_web2.getActiveInstance)();
|
|
178
|
+
await Object.values(state).map((ins) => (0, import_phecda_web2.unmountParallel)(ins));
|
|
179
|
+
(0, import_phecda_web2.resetActiveInstance)();
|
|
180
|
+
}
|
|
163
181
|
});
|
|
164
|
-
return
|
|
182
|
+
return phecda;
|
|
165
183
|
}
|
|
166
|
-
__name(
|
|
184
|
+
__name(createPhecda, "createPhecda");
|
|
167
185
|
|
|
168
|
-
// src/
|
|
169
|
-
var
|
|
170
|
-
var
|
|
186
|
+
// src/composable.ts
|
|
187
|
+
var import_vue4 = require("vue");
|
|
188
|
+
var import_phecda_web3 = require("phecda-web");
|
|
171
189
|
|
|
172
|
-
// src/
|
|
173
|
-
var
|
|
190
|
+
// src/utils.ts
|
|
191
|
+
var import_vue3 = require("vue");
|
|
174
192
|
function isObject(o) {
|
|
175
193
|
return Object.prototype.toString.call(o) === "[object Object]";
|
|
176
194
|
}
|
|
@@ -181,7 +199,7 @@ function mergeReactiveObjects(target, patchToApply) {
|
|
|
181
199
|
continue;
|
|
182
200
|
const subPatch = patchToApply[key];
|
|
183
201
|
const targetValue = target[key];
|
|
184
|
-
if (isObject(targetValue) && isObject(subPatch) && target.hasOwnProperty(key) && !(0,
|
|
202
|
+
if (isObject(targetValue) && isObject(subPatch) && target.hasOwnProperty(key) && !(0, import_vue3.isRef)(subPatch) && !(0, import_vue3.isReactive)(subPatch)) {
|
|
185
203
|
target[key] = mergeReactiveObjects(targetValue, subPatch);
|
|
186
204
|
} else {
|
|
187
205
|
target[key] = subPatch;
|
|
@@ -190,26 +208,6 @@ function mergeReactiveObjects(target, patchToApply) {
|
|
|
190
208
|
return target;
|
|
191
209
|
}
|
|
192
210
|
__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
211
|
function createSharedReactive(composable) {
|
|
214
212
|
let subscribers = 0;
|
|
215
213
|
let state;
|
|
@@ -223,34 +221,38 @@ function createSharedReactive(composable) {
|
|
|
223
221
|
return () => {
|
|
224
222
|
subscribers++;
|
|
225
223
|
if (!state) {
|
|
226
|
-
scope = (0,
|
|
224
|
+
scope = (0, import_vue3.effectScope)(true);
|
|
227
225
|
state = scope.run(() => composable());
|
|
228
226
|
}
|
|
229
|
-
(0,
|
|
227
|
+
(0, import_vue3.onScopeDispose)(dispose);
|
|
230
228
|
return state;
|
|
231
229
|
};
|
|
232
230
|
}
|
|
233
231
|
__name(createSharedReactive, "createSharedReactive");
|
|
234
232
|
|
|
235
|
-
// src/
|
|
233
|
+
// src/composable.ts
|
|
236
234
|
function useO(module2) {
|
|
237
|
-
const {
|
|
235
|
+
const { state, _o: oMap } = (0, import_phecda_web3.getActiveInstance)();
|
|
238
236
|
if (module2.prototype.__ISOLATE__) {
|
|
239
|
-
const instance = (0,
|
|
240
|
-
instance._promise = (0,
|
|
237
|
+
const instance = (0, import_vue4.reactive)(new module2());
|
|
238
|
+
instance._promise = (0, import_phecda_web3.registerSerial)(instance);
|
|
241
239
|
return instance;
|
|
242
240
|
}
|
|
243
|
-
const tag = (0,
|
|
244
|
-
if (!
|
|
245
|
-
const instance = (0,
|
|
246
|
-
instance._promise = (0,
|
|
247
|
-
|
|
241
|
+
const tag = (0, import_phecda_web3.getTag)(module2);
|
|
242
|
+
if (!(tag in state)) {
|
|
243
|
+
const instance = (0, import_vue4.reactive)(new module2());
|
|
244
|
+
instance._promise = (0, import_phecda_web3.registerSerial)(instance);
|
|
245
|
+
state[tag] = instance;
|
|
246
|
+
oMap.set(instance, module2);
|
|
247
|
+
} else {
|
|
248
|
+
if (oMap.get(state[tag]) !== module2)
|
|
249
|
+
console.warn(`Synonym module: Module taged "${String(tag)}" has been loaded before, so won't load Module "${module2.name}"`);
|
|
248
250
|
}
|
|
249
|
-
return
|
|
251
|
+
return state[tag];
|
|
250
252
|
}
|
|
251
253
|
__name(useO, "useO");
|
|
252
254
|
function useRaw(module2) {
|
|
253
|
-
return (0,
|
|
255
|
+
return (0, import_vue4.toRaw)(useO(module2));
|
|
254
256
|
}
|
|
255
257
|
__name(useRaw, "useRaw");
|
|
256
258
|
function usePatch(module2, Data) {
|
|
@@ -259,20 +261,20 @@ function usePatch(module2, Data) {
|
|
|
259
261
|
}
|
|
260
262
|
__name(usePatch, "usePatch");
|
|
261
263
|
function useR(module2) {
|
|
262
|
-
const {
|
|
264
|
+
const { _r: rmap, _f: fmap } = (0, import_phecda_web3.getActiveInstance)();
|
|
263
265
|
const instance = useO(module2);
|
|
264
|
-
if (
|
|
265
|
-
return
|
|
266
|
+
if (rmap.has(instance))
|
|
267
|
+
return rmap.get(instance);
|
|
266
268
|
const proxy = new Proxy(instance, {
|
|
267
269
|
get(target, key) {
|
|
268
270
|
if (typeof target[key] === "function") {
|
|
269
|
-
if (
|
|
270
|
-
return
|
|
271
|
-
const errorHandler = (0,
|
|
271
|
+
if (fmap.has(target[key]))
|
|
272
|
+
return fmap.get(target[key]);
|
|
273
|
+
const errorHandler = (0, import_phecda_web3.getHandler)(target, key).find((item) => item.error)?.error;
|
|
272
274
|
if (!errorHandler)
|
|
273
275
|
return target[key].bind(target);
|
|
274
|
-
const wrapper = wrapError(target, key, errorHandler);
|
|
275
|
-
|
|
276
|
+
const wrapper = (0, import_phecda_web3.wrapError)(target, key, errorHandler);
|
|
277
|
+
fmap.set(target[key], wrapper);
|
|
276
278
|
return wrapper;
|
|
277
279
|
}
|
|
278
280
|
return target[key];
|
|
@@ -282,33 +284,33 @@ function useR(module2) {
|
|
|
282
284
|
return true;
|
|
283
285
|
}
|
|
284
286
|
});
|
|
285
|
-
|
|
287
|
+
rmap.set(instance, proxy);
|
|
286
288
|
return proxy;
|
|
287
289
|
}
|
|
288
290
|
__name(useR, "useR");
|
|
289
291
|
function useV(module2) {
|
|
290
|
-
const {
|
|
292
|
+
const { _v: vmap, _f: fmap, _c: cmap } = (0, import_phecda_web3.getActiveInstance)();
|
|
291
293
|
const instance = useO(module2);
|
|
292
|
-
if (
|
|
293
|
-
return
|
|
294
|
-
|
|
294
|
+
if (vmap.has(instance))
|
|
295
|
+
return vmap.get(instance);
|
|
296
|
+
cmap.set(instance, {});
|
|
295
297
|
const proxy = new Proxy(instance, {
|
|
296
298
|
get(target, key) {
|
|
297
299
|
if (typeof target[key] === "function") {
|
|
298
|
-
if (
|
|
299
|
-
return
|
|
300
|
-
const errorHandler = (0,
|
|
300
|
+
if (fmap.has(target[key]))
|
|
301
|
+
return fmap.get(target[key]);
|
|
302
|
+
const errorHandler = (0, import_phecda_web3.getHandler)(target, key).find((item) => item.error)?.error;
|
|
301
303
|
if (!errorHandler)
|
|
302
304
|
return target[key].bind(target);
|
|
303
|
-
const wrapper = wrapError(target, key, errorHandler);
|
|
304
|
-
|
|
305
|
+
const wrapper = (0, import_phecda_web3.wrapError)(target, key, errorHandler);
|
|
306
|
+
fmap.set(target[key], wrapper);
|
|
305
307
|
return wrapper;
|
|
306
308
|
}
|
|
307
|
-
const cache =
|
|
309
|
+
const cache = cmap.get(instance);
|
|
308
310
|
if (key in cache)
|
|
309
311
|
return cache[key]();
|
|
310
312
|
cache[key] = createSharedReactive(() => {
|
|
311
|
-
return (0,
|
|
313
|
+
return (0, import_vue4.toRef)(target, key);
|
|
312
314
|
});
|
|
313
315
|
return cache[key]();
|
|
314
316
|
},
|
|
@@ -316,16 +318,19 @@ function useV(module2) {
|
|
|
316
318
|
return false;
|
|
317
319
|
}
|
|
318
320
|
});
|
|
319
|
-
|
|
321
|
+
vmap.set(instance, proxy);
|
|
320
322
|
return proxy;
|
|
321
323
|
}
|
|
322
324
|
__name(useV, "useV");
|
|
323
325
|
function useEvent(eventName, cb) {
|
|
324
|
-
(0,
|
|
325
|
-
emitter.off(eventName, cb);
|
|
326
|
+
(0, import_vue4.onBeforeUnmount)(() => {
|
|
327
|
+
import_phecda_web3.emitter.off(eventName, cb);
|
|
326
328
|
});
|
|
327
|
-
emitter.on(eventName, cb);
|
|
328
|
-
return
|
|
329
|
+
import_phecda_web3.emitter.on(eventName, cb);
|
|
330
|
+
return {
|
|
331
|
+
emit: (arg) => import_phecda_web3.emitter.emit(eventName, arg),
|
|
332
|
+
cancel: () => import_phecda_web3.emitter.off(eventName, cb)
|
|
333
|
+
};
|
|
329
334
|
}
|
|
330
335
|
__name(useEvent, "useEvent");
|
|
331
336
|
function initialize(module2, deleteOtherProperty = true) {
|
|
@@ -340,154 +345,18 @@ function initialize(module2, deleteOtherProperty = true) {
|
|
|
340
345
|
}
|
|
341
346
|
}
|
|
342
347
|
__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
348
|
// Annotate the CommonJS export names for ESM import in node:
|
|
473
349
|
0 && (module.exports = {
|
|
474
|
-
Isolate,
|
|
475
350
|
PV,
|
|
476
351
|
RE,
|
|
477
352
|
createFilter,
|
|
478
353
|
createPhecda,
|
|
479
|
-
emitter,
|
|
480
|
-
getActivePhecda,
|
|
481
|
-
getReactiveMap,
|
|
482
354
|
initialize,
|
|
483
|
-
interval,
|
|
484
355
|
phecdaSymbol,
|
|
485
|
-
setActivePhecda,
|
|
486
356
|
useEvent,
|
|
487
357
|
useO,
|
|
488
358
|
usePatch,
|
|
489
359
|
useR,
|
|
490
360
|
useRaw,
|
|
491
|
-
useV
|
|
492
|
-
waitUntilInit
|
|
361
|
+
useV
|
|
493
362
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,127 +1,158 @@
|
|
|
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, unmountParallel } from "phecda-web";
|
|
11
125
|
var phecdaSymbol = Symbol("phecda");
|
|
12
|
-
|
|
13
|
-
|
|
126
|
+
function createPhecda() {
|
|
127
|
+
resetActiveInstance();
|
|
14
128
|
const phecda = markRaw({
|
|
15
129
|
install(app) {
|
|
16
|
-
|
|
17
|
-
app
|
|
18
|
-
app.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
value
|
|
31
|
-
});
|
|
32
|
-
return ret;
|
|
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
|
-
};
|
|
130
|
+
const instance = getActiveInstance();
|
|
131
|
+
instance.app = app;
|
|
132
|
+
app.provide(phecdaSymbol, instance);
|
|
133
|
+
app.config.globalProperties.$phecda = instance;
|
|
134
|
+
},
|
|
135
|
+
load(state) {
|
|
136
|
+
const instance = getActiveInstance();
|
|
137
|
+
instance.state = state;
|
|
138
|
+
return this;
|
|
139
|
+
},
|
|
140
|
+
async unmount() {
|
|
141
|
+
const { state } = getActiveInstance();
|
|
142
|
+
await Object.values(state).map((ins) => unmountParallel(ins));
|
|
143
|
+
resetActiveInstance();
|
|
88
144
|
}
|
|
89
145
|
});
|
|
90
146
|
return phecda;
|
|
91
147
|
}
|
|
92
148
|
__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
149
|
|
|
119
|
-
// src/
|
|
150
|
+
// src/composable.ts
|
|
120
151
|
import { onBeforeUnmount, reactive, toRaw, toRef } from "vue";
|
|
121
|
-
import {
|
|
152
|
+
import { emitter as emitter2, getActiveInstance as getActiveInstance2, getHandler, getTag, registerSerial, wrapError } from "phecda-web";
|
|
122
153
|
|
|
123
|
-
// src/
|
|
124
|
-
import { effectScope, isReactive, isRef, onScopeDispose } from "vue";
|
|
154
|
+
// src/utils.ts
|
|
155
|
+
import { effectScope as effectScope2, isReactive, isRef, onScopeDispose } from "vue";
|
|
125
156
|
function isObject(o) {
|
|
126
157
|
return Object.prototype.toString.call(o) === "[object Object]";
|
|
127
158
|
}
|
|
@@ -141,26 +172,6 @@ function mergeReactiveObjects(target, patchToApply) {
|
|
|
141
172
|
return target;
|
|
142
173
|
}
|
|
143
174
|
__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
175
|
function createSharedReactive(composable) {
|
|
165
176
|
let subscribers = 0;
|
|
166
177
|
let state;
|
|
@@ -174,7 +185,7 @@ function createSharedReactive(composable) {
|
|
|
174
185
|
return () => {
|
|
175
186
|
subscribers++;
|
|
176
187
|
if (!state) {
|
|
177
|
-
scope =
|
|
188
|
+
scope = effectScope2(true);
|
|
178
189
|
state = scope.run(() => composable());
|
|
179
190
|
}
|
|
180
191
|
onScopeDispose(dispose);
|
|
@@ -183,21 +194,25 @@ function createSharedReactive(composable) {
|
|
|
183
194
|
}
|
|
184
195
|
__name(createSharedReactive, "createSharedReactive");
|
|
185
196
|
|
|
186
|
-
// src/
|
|
197
|
+
// src/composable.ts
|
|
187
198
|
function useO(module) {
|
|
188
|
-
const {
|
|
199
|
+
const { state, _o: oMap } = getActiveInstance2();
|
|
189
200
|
if (module.prototype.__ISOLATE__) {
|
|
190
201
|
const instance = reactive(new module());
|
|
191
|
-
instance._promise =
|
|
202
|
+
instance._promise = registerSerial(instance);
|
|
192
203
|
return instance;
|
|
193
204
|
}
|
|
194
|
-
const tag =
|
|
195
|
-
if (!
|
|
205
|
+
const tag = getTag(module);
|
|
206
|
+
if (!(tag in state)) {
|
|
196
207
|
const instance = reactive(new module());
|
|
197
|
-
instance._promise =
|
|
198
|
-
|
|
208
|
+
instance._promise = registerSerial(instance);
|
|
209
|
+
state[tag] = instance;
|
|
210
|
+
oMap.set(instance, module);
|
|
211
|
+
} else {
|
|
212
|
+
if (oMap.get(state[tag]) !== module)
|
|
213
|
+
console.warn(`Synonym module: Module taged "${String(tag)}" has been loaded before, so won't load Module "${module.name}"`);
|
|
199
214
|
}
|
|
200
|
-
return
|
|
215
|
+
return state[tag];
|
|
201
216
|
}
|
|
202
217
|
__name(useO, "useO");
|
|
203
218
|
function useRaw(module) {
|
|
@@ -210,20 +225,20 @@ function usePatch(module, Data) {
|
|
|
210
225
|
}
|
|
211
226
|
__name(usePatch, "usePatch");
|
|
212
227
|
function useR(module) {
|
|
213
|
-
const {
|
|
228
|
+
const { _r: rmap, _f: fmap } = getActiveInstance2();
|
|
214
229
|
const instance = useO(module);
|
|
215
|
-
if (
|
|
216
|
-
return
|
|
230
|
+
if (rmap.has(instance))
|
|
231
|
+
return rmap.get(instance);
|
|
217
232
|
const proxy = new Proxy(instance, {
|
|
218
233
|
get(target, key) {
|
|
219
234
|
if (typeof target[key] === "function") {
|
|
220
|
-
if (
|
|
221
|
-
return
|
|
235
|
+
if (fmap.has(target[key]))
|
|
236
|
+
return fmap.get(target[key]);
|
|
222
237
|
const errorHandler = getHandler(target, key).find((item) => item.error)?.error;
|
|
223
238
|
if (!errorHandler)
|
|
224
239
|
return target[key].bind(target);
|
|
225
240
|
const wrapper = wrapError(target, key, errorHandler);
|
|
226
|
-
|
|
241
|
+
fmap.set(target[key], wrapper);
|
|
227
242
|
return wrapper;
|
|
228
243
|
}
|
|
229
244
|
return target[key];
|
|
@@ -233,29 +248,29 @@ function useR(module) {
|
|
|
233
248
|
return true;
|
|
234
249
|
}
|
|
235
250
|
});
|
|
236
|
-
|
|
251
|
+
rmap.set(instance, proxy);
|
|
237
252
|
return proxy;
|
|
238
253
|
}
|
|
239
254
|
__name(useR, "useR");
|
|
240
255
|
function useV(module) {
|
|
241
|
-
const {
|
|
256
|
+
const { _v: vmap, _f: fmap, _c: cmap } = getActiveInstance2();
|
|
242
257
|
const instance = useO(module);
|
|
243
|
-
if (
|
|
244
|
-
return
|
|
245
|
-
|
|
258
|
+
if (vmap.has(instance))
|
|
259
|
+
return vmap.get(instance);
|
|
260
|
+
cmap.set(instance, {});
|
|
246
261
|
const proxy = new Proxy(instance, {
|
|
247
262
|
get(target, key) {
|
|
248
263
|
if (typeof target[key] === "function") {
|
|
249
|
-
if (
|
|
250
|
-
return
|
|
264
|
+
if (fmap.has(target[key]))
|
|
265
|
+
return fmap.get(target[key]);
|
|
251
266
|
const errorHandler = getHandler(target, key).find((item) => item.error)?.error;
|
|
252
267
|
if (!errorHandler)
|
|
253
268
|
return target[key].bind(target);
|
|
254
269
|
const wrapper = wrapError(target, key, errorHandler);
|
|
255
|
-
|
|
270
|
+
fmap.set(target[key], wrapper);
|
|
256
271
|
return wrapper;
|
|
257
272
|
}
|
|
258
|
-
const cache =
|
|
273
|
+
const cache = cmap.get(instance);
|
|
259
274
|
if (key in cache)
|
|
260
275
|
return cache[key]();
|
|
261
276
|
cache[key] = createSharedReactive(() => {
|
|
@@ -267,16 +282,19 @@ function useV(module) {
|
|
|
267
282
|
return false;
|
|
268
283
|
}
|
|
269
284
|
});
|
|
270
|
-
|
|
285
|
+
vmap.set(instance, proxy);
|
|
271
286
|
return proxy;
|
|
272
287
|
}
|
|
273
288
|
__name(useV, "useV");
|
|
274
289
|
function useEvent(eventName, cb) {
|
|
275
290
|
onBeforeUnmount(() => {
|
|
276
|
-
|
|
291
|
+
emitter2.off(eventName, cb);
|
|
277
292
|
});
|
|
278
|
-
|
|
279
|
-
return
|
|
293
|
+
emitter2.on(eventName, cb);
|
|
294
|
+
return {
|
|
295
|
+
emit: (arg) => emitter2.emit(eventName, arg),
|
|
296
|
+
cancel: () => emitter2.off(eventName, cb)
|
|
297
|
+
};
|
|
280
298
|
}
|
|
281
299
|
__name(useEvent, "useEvent");
|
|
282
300
|
function initialize(module, deleteOtherProperty = true) {
|
|
@@ -291,153 +309,17 @@ function initialize(module, deleteOtherProperty = true) {
|
|
|
291
309
|
}
|
|
292
310
|
}
|
|
293
311
|
__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
312
|
export {
|
|
424
|
-
Isolate,
|
|
425
313
|
PV,
|
|
426
314
|
RE,
|
|
427
315
|
createFilter,
|
|
428
316
|
createPhecda,
|
|
429
|
-
emitter,
|
|
430
|
-
getActivePhecda,
|
|
431
|
-
getReactiveMap,
|
|
432
317
|
initialize,
|
|
433
|
-
interval,
|
|
434
318
|
phecdaSymbol,
|
|
435
|
-
setActivePhecda,
|
|
436
319
|
useEvent,
|
|
437
320
|
useO,
|
|
438
321
|
usePatch,
|
|
439
322
|
useR,
|
|
440
323
|
useRaw,
|
|
441
|
-
useV
|
|
442
|
-
waitUntilInit
|
|
324
|
+
useV
|
|
443
325
|
};
|
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.11",
|
|
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.5"
|
|
18
17
|
},
|
|
19
18
|
"devDependencies": {
|
|
20
19
|
"tsup": "^6.5.0"
|