phecda-core 1.1.0 → 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 ADDED
@@ -0,0 +1,3 @@
1
+ # phecda-core
2
+ provide base function and abstract limit to other phecda module
3
+
package/dist/index.d.ts CHANGED
@@ -22,6 +22,8 @@ interface Phecda {
22
22
  type ClassValue<I> = {
23
23
  [P in keyof I]: I[P] extends Function ? undefined : I[P];
24
24
  };
25
+ interface PhecdaEvents {
26
+ }
25
27
 
26
28
  declare function plainToClass<M extends new (...args: any) => any, Data extends Record<PropertyKey, any>>(Model: M, input: Data, options?: UsePipeOptions): Promise<{
27
29
  err: string[];
@@ -77,7 +79,6 @@ declare function Err<Fn extends (...args: any) => any>(cb: Fn): (target: any, ke
77
79
  declare function P(target: any, key: PropertyKey): void;
78
80
  declare function Pipe(v: ReturnType<typeof to>): (obj: any, key: PropertyKey) => void;
79
81
  declare function Tag(tag: string): (target: any) => void;
80
- declare function Storage(target: any): void;
81
82
  declare function Global(target: any): void;
82
83
 
83
84
  declare function validate(p: RegExp | string | Function | Object | Number, v: any): Promise<any>;
@@ -124,6 +125,9 @@ declare const activeInstance: Record<string, any>;
124
125
  declare function injectProperty(key: string, value: any): Record<string, any>;
125
126
  declare function getProperty(key: string): any;
126
127
 
127
- declare function Watcher(eventName: string): (obj: any, key: string) => void;
128
+ declare function Watcher(eventName: keyof PhecdaEvents, options?: {
129
+ once: boolean;
130
+ }): (obj: any, key: string) => void;
131
+ declare function Storage(storeKey?: string): (target: any, key?: PropertyKey) => void;
128
132
 
129
- export { ClassValue, Clear, Err, Global, Ignore, Init, P, Phecda, 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 };
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__ = {};
@@ -498,7 +475,7 @@ function getProperty(key) {
498
475
  __name(getProperty, "getProperty");
499
476
 
500
477
  // src/custom/decorator.ts
501
- function Watcher(eventName) {
478
+ function Watcher(eventName, options) {
502
479
  return (obj, key) => {
503
480
  setModalVar(obj, key);
504
481
  regisHandler(obj, key, {
@@ -506,13 +483,49 @@ function Watcher(eventName) {
506
483
  getProperty("watcher")?.({
507
484
  eventName,
508
485
  instance,
509
- key
486
+ key,
487
+ options
510
488
  });
511
489
  }
512
490
  });
513
491
  };
514
492
  }
515
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");
516
529
  // Annotate the CommonJS export names for ESM import in node:
517
530
  0 && (module.exports = {
518
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__ = {};
@@ -420,7 +397,7 @@ function getProperty(key) {
420
397
  __name(getProperty, "getProperty");
421
398
 
422
399
  // src/custom/decorator.ts
423
- function Watcher(eventName) {
400
+ function Watcher(eventName, options) {
424
401
  return (obj, key) => {
425
402
  setModalVar(obj, key);
426
403
  regisHandler(obj, key, {
@@ -428,13 +405,49 @@ function Watcher(eventName) {
428
405
  getProperty("watcher")?.({
429
406
  eventName,
430
407
  instance,
431
- key
408
+ key,
409
+ options
432
410
  });
433
411
  }
434
412
  });
435
413
  };
436
414
  }
437
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");
438
451
  export {
439
452
  Clear,
440
453
  Err,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "phecda-core",
3
- "version": "1.1.0",
4
- "description": "",
3
+ "version": "1.2.0",
4
+ "description": "provide base function and abstract limit to other phecda module ",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",