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