phecda-core 1.1.1 → 1.2.0
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/README.md +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +35 -23
- package/dist/index.mjs +35 -23
- package/package.json +2 -2
package/README.md
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -79,7 +79,6 @@ declare function Err<Fn extends (...args: any) => any>(cb: Fn): (target: any, ke
|
|
|
79
79
|
declare function P(target: any, key: PropertyKey): void;
|
|
80
80
|
declare function Pipe(v: ReturnType<typeof to>): (obj: any, key: PropertyKey) => void;
|
|
81
81
|
declare function Tag(tag: string): (target: any) => void;
|
|
82
|
-
declare function Storage(target: any): void;
|
|
83
82
|
declare function Global(target: any): void;
|
|
84
83
|
|
|
85
84
|
declare function validate(p: RegExp | string | Function | Object | Number, v: any): Promise<any>;
|
|
@@ -129,5 +128,6 @@ declare function getProperty(key: string): any;
|
|
|
129
128
|
declare function Watcher(eventName: keyof PhecdaEvents, options?: {
|
|
130
129
|
once: boolean;
|
|
131
130
|
}): (obj: any, key: string) => void;
|
|
131
|
+
declare function Storage(storeKey?: string): (target: any, key?: PropertyKey) => void;
|
|
132
132
|
|
|
133
133
|
export { ClassValue, Clear, Err, Global, Ignore, Init, P, Phecda, PhecdaEvents, PhecdaHandler, PhecdaNameSpace, Pipe, Rule, Storage, Tag, UsePipeOptions, Watcher, activeInstance, addDecoToClass, classToValue, getExposeKey, getHandler, getIgnoreKey, getInitEvent, getModelState, getProperty, getState, getTag, init, injectProperty, isArray, isBoolean, isCnName, isDate, isEnName, isHexColor, isIdCard, isLandline, isMailBox, isMobile, isNumber, isObject, isPhecda, isPostalCode, isString, isWechat, mergeOptions, mergeState, plainToClass, regisHandler, regisInitEvent, register, registerAsync, setExposeKey, setIgnoreKey, setModalVar, snapShot, to, toNumber, toString, validate };
|
package/dist/index.js
CHANGED
|
@@ -301,29 +301,6 @@ function Tag(tag) {
|
|
|
301
301
|
};
|
|
302
302
|
}
|
|
303
303
|
__name(Tag, "Tag");
|
|
304
|
-
function Storage(target) {
|
|
305
|
-
init(target.prototype);
|
|
306
|
-
const tag = target.prototype._namespace.__TAG__;
|
|
307
|
-
if (tag === "")
|
|
308
|
-
throw new Error("miss tag");
|
|
309
|
-
const uniTag = Symbol(tag);
|
|
310
|
-
setModalVar(target.prototype, uniTag);
|
|
311
|
-
regisHandler(target.prototype, uniTag, {
|
|
312
|
-
init: (instance) => {
|
|
313
|
-
const { state } = instance;
|
|
314
|
-
globalThis.addEventListener("beforeunload", () => {
|
|
315
|
-
localStorage.setItem(`_phecda_${tag}`, JSON.stringify(state));
|
|
316
|
-
});
|
|
317
|
-
const lastObjStr = localStorage.getItem(`_phecda_${tag}`);
|
|
318
|
-
if (lastObjStr && lastObjStr !== "undefined") {
|
|
319
|
-
const lastObj = JSON.parse(lastObjStr);
|
|
320
|
-
for (const i in lastObj)
|
|
321
|
-
state[i] = lastObj[i];
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
__name(Storage, "Storage");
|
|
327
304
|
function Global(target) {
|
|
328
305
|
if (!globalThis.__PHECDA__)
|
|
329
306
|
globalThis.__PHECDA__ = {};
|
|
@@ -514,6 +491,41 @@ function Watcher(eventName, options) {
|
|
|
514
491
|
};
|
|
515
492
|
}
|
|
516
493
|
__name(Watcher, "Watcher");
|
|
494
|
+
function Storage(storeKey) {
|
|
495
|
+
return (target, key) => {
|
|
496
|
+
let tag;
|
|
497
|
+
if (key) {
|
|
498
|
+
init(target);
|
|
499
|
+
tag = storeKey || target._namespace.__TAG__;
|
|
500
|
+
const uniTag = Symbol(tag);
|
|
501
|
+
setModalVar(target, uniTag);
|
|
502
|
+
regisHandler(target, uniTag, {
|
|
503
|
+
init: (instance) => {
|
|
504
|
+
getProperty("storage")?.({
|
|
505
|
+
instance,
|
|
506
|
+
key,
|
|
507
|
+
tag
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
} else {
|
|
512
|
+
init(target.prototype);
|
|
513
|
+
tag = storeKey || `${target.prototype._namespace.__TAG__}_${key}`;
|
|
514
|
+
const uniTag = Symbol(tag);
|
|
515
|
+
setModalVar(target.prototype, uniTag);
|
|
516
|
+
regisHandler(target.prototype, uniTag, {
|
|
517
|
+
init: (instance) => {
|
|
518
|
+
getProperty("storage")?.({
|
|
519
|
+
instance,
|
|
520
|
+
key: "",
|
|
521
|
+
tag
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
__name(Storage, "Storage");
|
|
517
529
|
// Annotate the CommonJS export names for ESM import in node:
|
|
518
530
|
0 && (module.exports = {
|
|
519
531
|
Clear,
|
package/dist/index.mjs
CHANGED
|
@@ -223,29 +223,6 @@ function Tag(tag) {
|
|
|
223
223
|
};
|
|
224
224
|
}
|
|
225
225
|
__name(Tag, "Tag");
|
|
226
|
-
function Storage(target) {
|
|
227
|
-
init(target.prototype);
|
|
228
|
-
const tag = target.prototype._namespace.__TAG__;
|
|
229
|
-
if (tag === "")
|
|
230
|
-
throw new Error("miss tag");
|
|
231
|
-
const uniTag = Symbol(tag);
|
|
232
|
-
setModalVar(target.prototype, uniTag);
|
|
233
|
-
regisHandler(target.prototype, uniTag, {
|
|
234
|
-
init: (instance) => {
|
|
235
|
-
const { state } = instance;
|
|
236
|
-
globalThis.addEventListener("beforeunload", () => {
|
|
237
|
-
localStorage.setItem(`_phecda_${tag}`, JSON.stringify(state));
|
|
238
|
-
});
|
|
239
|
-
const lastObjStr = localStorage.getItem(`_phecda_${tag}`);
|
|
240
|
-
if (lastObjStr && lastObjStr !== "undefined") {
|
|
241
|
-
const lastObj = JSON.parse(lastObjStr);
|
|
242
|
-
for (const i in lastObj)
|
|
243
|
-
state[i] = lastObj[i];
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
__name(Storage, "Storage");
|
|
249
226
|
function Global(target) {
|
|
250
227
|
if (!globalThis.__PHECDA__)
|
|
251
228
|
globalThis.__PHECDA__ = {};
|
|
@@ -436,6 +413,41 @@ function Watcher(eventName, options) {
|
|
|
436
413
|
};
|
|
437
414
|
}
|
|
438
415
|
__name(Watcher, "Watcher");
|
|
416
|
+
function Storage(storeKey) {
|
|
417
|
+
return (target, key) => {
|
|
418
|
+
let tag;
|
|
419
|
+
if (key) {
|
|
420
|
+
init(target);
|
|
421
|
+
tag = storeKey || target._namespace.__TAG__;
|
|
422
|
+
const uniTag = Symbol(tag);
|
|
423
|
+
setModalVar(target, uniTag);
|
|
424
|
+
regisHandler(target, uniTag, {
|
|
425
|
+
init: (instance) => {
|
|
426
|
+
getProperty("storage")?.({
|
|
427
|
+
instance,
|
|
428
|
+
key,
|
|
429
|
+
tag
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
} else {
|
|
434
|
+
init(target.prototype);
|
|
435
|
+
tag = storeKey || `${target.prototype._namespace.__TAG__}_${key}`;
|
|
436
|
+
const uniTag = Symbol(tag);
|
|
437
|
+
setModalVar(target.prototype, uniTag);
|
|
438
|
+
regisHandler(target.prototype, uniTag, {
|
|
439
|
+
init: (instance) => {
|
|
440
|
+
getProperty("storage")?.({
|
|
441
|
+
instance,
|
|
442
|
+
key: "",
|
|
443
|
+
tag
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
__name(Storage, "Storage");
|
|
439
451
|
export {
|
|
440
452
|
Clear,
|
|
441
453
|
Err,
|
package/package.json
CHANGED