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