@genesislcap/foundation-utils 14.133.1 → 14.135.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.
@@ -117,6 +117,14 @@
117
117
  "package": "./serializers"
118
118
  }
119
119
  },
120
+ {
121
+ "kind": "js",
122
+ "name": "*",
123
+ "declaration": {
124
+ "name": "*",
125
+ "package": "./state"
126
+ }
127
+ },
120
128
  {
121
129
  "kind": "js",
122
130
  "name": "*",
@@ -341,6 +349,56 @@
341
349
  }
342
350
  ]
343
351
  },
352
+ {
353
+ "kind": "javascript-module",
354
+ "path": "src/design-system/design-system.ts",
355
+ "declarations": [
356
+ {
357
+ "kind": "function",
358
+ "name": "assureDesignSystem",
359
+ "return": {
360
+ "type": {
361
+ "text": "DesignSystemModule"
362
+ }
363
+ },
364
+ "parameters": [
365
+ {
366
+ "name": "module",
367
+ "type": {
368
+ "text": "DesignSystemModule"
369
+ }
370
+ }
371
+ ],
372
+ "description": "assureDesignSystem.",
373
+ "privacy": "public"
374
+ }
375
+ ],
376
+ "exports": [
377
+ {
378
+ "kind": "js",
379
+ "name": "assureDesignSystem",
380
+ "declaration": {
381
+ "name": "assureDesignSystem",
382
+ "module": "src/design-system/design-system.ts"
383
+ }
384
+ }
385
+ ]
386
+ },
387
+ {
388
+ "kind": "javascript-module",
389
+ "path": "src/design-system/index.ts",
390
+ "declarations": [],
391
+ "exports": [
392
+ {
393
+ "kind": "js",
394
+ "name": "*",
395
+ "declaration": {
396
+ "name": "*",
397
+ "package": "./design-system"
398
+ }
399
+ }
400
+ ]
401
+ },
344
402
  {
345
403
  "kind": "javascript-module",
346
404
  "path": "src/decorators/index.ts",
@@ -394,56 +452,6 @@
394
452
  }
395
453
  ]
396
454
  },
397
- {
398
- "kind": "javascript-module",
399
- "path": "src/design-system/design-system.ts",
400
- "declarations": [
401
- {
402
- "kind": "function",
403
- "name": "assureDesignSystem",
404
- "return": {
405
- "type": {
406
- "text": "DesignSystemModule"
407
- }
408
- },
409
- "parameters": [
410
- {
411
- "name": "module",
412
- "type": {
413
- "text": "DesignSystemModule"
414
- }
415
- }
416
- ],
417
- "description": "assureDesignSystem.",
418
- "privacy": "public"
419
- }
420
- ],
421
- "exports": [
422
- {
423
- "kind": "js",
424
- "name": "assureDesignSystem",
425
- "declaration": {
426
- "name": "assureDesignSystem",
427
- "module": "src/design-system/design-system.ts"
428
- }
429
- }
430
- ]
431
- },
432
- {
433
- "kind": "javascript-module",
434
- "path": "src/design-system/index.ts",
435
- "declarations": [],
436
- "exports": [
437
- {
438
- "kind": "js",
439
- "name": "*",
440
- "declaration": {
441
- "name": "*",
442
- "package": "./design-system"
443
- }
444
- }
445
- ]
446
- },
447
455
  {
448
456
  "kind": "javascript-module",
449
457
  "path": "src/directives/index.ts",
@@ -1353,6 +1361,132 @@
1353
1361
  }
1354
1362
  ]
1355
1363
  },
1364
+ {
1365
+ "kind": "javascript-module",
1366
+ "path": "src/state/index.ts",
1367
+ "declarations": [],
1368
+ "exports": [
1369
+ {
1370
+ "kind": "js",
1371
+ "name": "*",
1372
+ "declaration": {
1373
+ "name": "*",
1374
+ "package": "./reactive"
1375
+ }
1376
+ },
1377
+ {
1378
+ "kind": "js",
1379
+ "name": "*",
1380
+ "declaration": {
1381
+ "name": "*",
1382
+ "package": "./visitor"
1383
+ }
1384
+ }
1385
+ ]
1386
+ },
1387
+ {
1388
+ "kind": "javascript-module",
1389
+ "path": "src/state/reactive.ts",
1390
+ "declarations": [
1391
+ {
1392
+ "kind": "function",
1393
+ "name": "reactive",
1394
+ "return": {
1395
+ "type": {
1396
+ "text": ""
1397
+ }
1398
+ },
1399
+ "parameters": [
1400
+ {
1401
+ "name": "object",
1402
+ "type": {
1403
+ "text": "T"
1404
+ },
1405
+ "description": "The object to make reactive."
1406
+ },
1407
+ {
1408
+ "name": "deep",
1409
+ "default": "false",
1410
+ "description": "Indicates whether to deeply convert the object."
1411
+ }
1412
+ ],
1413
+ "description": "Converts a plain object to a reactive, observable object."
1414
+ }
1415
+ ],
1416
+ "exports": [
1417
+ {
1418
+ "kind": "js",
1419
+ "name": "reactive",
1420
+ "declaration": {
1421
+ "name": "reactive",
1422
+ "module": "src/state/reactive.ts"
1423
+ }
1424
+ }
1425
+ ]
1426
+ },
1427
+ {
1428
+ "kind": "javascript-module",
1429
+ "path": "src/state/visitor.ts",
1430
+ "declarations": [
1431
+ {
1432
+ "kind": "function",
1433
+ "name": "visitObject",
1434
+ "return": {
1435
+ "type": {
1436
+ "text": "void"
1437
+ }
1438
+ },
1439
+ "parameters": [
1440
+ {
1441
+ "name": "object",
1442
+ "type": {
1443
+ "text": "any"
1444
+ },
1445
+ "description": "The object."
1446
+ },
1447
+ {
1448
+ "name": "deep",
1449
+ "type": {
1450
+ "text": "boolean"
1451
+ },
1452
+ "description": "A flag to indicate if a recursive visit of sub objects should occur."
1453
+ },
1454
+ {
1455
+ "name": "visitor",
1456
+ "type": {
1457
+ "text": "ObjectVisitor<TVisitorData>"
1458
+ },
1459
+ "description": "The defined {@link ObjectVisitor}logic.\n * "
1460
+ },
1461
+ {
1462
+ "name": "data",
1463
+ "type": {
1464
+ "text": "TVisitorData"
1465
+ },
1466
+ "description": "Visitor data."
1467
+ },
1468
+ {
1469
+ "name": "traversed",
1470
+ "type": {
1471
+ "text": "WeakSet<any> | Set<any>"
1472
+ },
1473
+ "description": "The traversed object set."
1474
+ }
1475
+ ],
1476
+ "description": "Visit object utility."
1477
+ }
1478
+ ],
1479
+ "exports": [
1480
+ {
1481
+ "kind": "js",
1482
+ "name": "visitObject",
1483
+ "declaration": {
1484
+ "name": "visitObject",
1485
+ "module": "src/state/visitor.ts"
1486
+ }
1487
+ }
1488
+ ]
1489
+ },
1356
1490
  {
1357
1491
  "kind": "javascript-module",
1358
1492
  "path": "src/styles/color.ts",
@@ -11,6 +11,7 @@ export * from './mixins';
11
11
  export * from './observer';
12
12
  export * from './resource';
13
13
  export * from './serializers';
14
+ export * from './state';
14
15
  export * from './styles';
15
16
  export * from './uuid';
16
17
  export * from './window';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './reactive';
2
+ export * from './visitor';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/state/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Converts a plain object to a reactive, observable object.
3
+ *
4
+ * @privateRemarks
5
+ * Code borrowed from fast-element v2. We can remove post upgrade.
6
+ *
7
+ * @example
8
+ * An array or reactive items.
9
+ * ```ts
10
+ * this.todos = todosResponse.map((t) => reactive(t));
11
+ * ```
12
+ *
13
+ * @example
14
+ * Add item.
15
+ * ```ts
16
+ * add(description: string) {
17
+ * this.splice(this.todos.length, 0, reactive({ description, done: false }));
18
+ * }
19
+ * ```
20
+ *
21
+ * @example
22
+ * Remove item.
23
+ * ```ts
24
+ * remove(todo: Todo) {
25
+ * const index = this.todos.indexOf(todo);
26
+ * index !== -1 && this.splice(index, 1);
27
+ * }
28
+ *```
29
+ *
30
+ * @param object - The object to make reactive.
31
+ * @param deep - Indicates whether to deeply convert the object.
32
+ * @returns The converted object.
33
+ *
34
+ * @beta
35
+ */
36
+ export declare function reactive<T>(object: T, deep?: boolean): T;
37
+ //# sourceMappingURL=reactive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactive.d.ts","sourceRoot":"","sources":["../../../src/state/reactive.ts"],"names":[],"mappings":"AA6BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,UAAQ,GAAG,CAAC,CAGtD"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @privateRemarks
3
+ * Code borrowed from fast-element v2. We can remove post upgrade.
4
+ *
5
+ * @example
6
+ * Reactive visitor example.
7
+ * ```ts
8
+ * const makeObserverVisitor: ObjectVisitor<undefined> = {
9
+ * visitObject: noop,
10
+ * visitArray: noop,
11
+ * visitProperty(object: any, propertyName: string, value: any): void {
12
+ * Reflect.defineProperty(object, propertyName, {
13
+ * enumerable: true,
14
+ * get() {
15
+ * Observable.track(object, propertyName);
16
+ * return value;
17
+ * },
18
+ * set(newValue: any) {
19
+ * if (value !== newValue) {
20
+ * value = newValue;
21
+ * Observable.notify(object, propertyName);
22
+ * }
23
+ * },
24
+ * });
25
+ * },
26
+ * };
27
+ * ```
28
+ *
29
+ * @beta
30
+ */
31
+ export interface ObjectVisitor<TVisitorData> {
32
+ visitObject(object: any, data: TVisitorData): void;
33
+ visitArray(array: any[], data: TVisitorData): void;
34
+ visitProperty(object: any, key: PropertyKey, value: any, data: TVisitorData): void;
35
+ }
36
+ /**
37
+ * Visit object utility.
38
+ *
39
+ * @privateRemarks
40
+ * Code borrowed from fast-element v2. We can remove post upgrade.
41
+ *
42
+ * @example
43
+ * Reactive example.
44
+ * ```ts
45
+ * export function reactive<T>(object: T, deep = false): T {
46
+ * visitObject(object, deep, makeObserverVisitor, void 0, observed);
47
+ * return object;
48
+ * }
49
+ * ```
50
+ *
51
+ * @param object - The object.
52
+ * @param deep - A flag to indicate if a recursive visit of sub objects should occur.
53
+ * @param visitor - The defined {@link ObjectVisitor} logic.
54
+ * @param data - Visitor data.
55
+ * @param traversed - The traversed object set.
56
+ *
57
+ * @beta
58
+ */
59
+ export declare function visitObject<TVisitorData>(object: any, deep: boolean, visitor: ObjectVisitor<TVisitorData>, data: TVisitorData, traversed: WeakSet<any> | Set<any>): void;
60
+ //# sourceMappingURL=visitor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visitor.d.ts","sourceRoot":"","sources":["../../../src/state/visitor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,WAAW,aAAa,CAAC,YAAY;IACzC,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;IACnD,UAAU,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;IACnD,aAAa,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC;CACpF;AAMD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,CAAC,YAAY,EACtC,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,EACpC,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GACjC,IAAI,CA8BN"}
package/dist/esm/index.js CHANGED
@@ -11,6 +11,7 @@ export * from './mixins';
11
11
  export * from './observer';
12
12
  export * from './resource';
13
13
  export * from './serializers';
14
+ export * from './state';
14
15
  export * from './styles';
15
16
  export * from './uuid';
16
17
  export * from './window';
@@ -0,0 +1,2 @@
1
+ export * from './reactive';
2
+ export * from './visitor';
@@ -0,0 +1,65 @@
1
+ import { Observable } from '@microsoft/fast-element';
2
+ import { visitObject } from './visitor.js';
3
+ /**
4
+ * Code borrowed from fast-element v2. We can remove post upgrade.
5
+ */
6
+ const noop = () => void 0;
7
+ const observed = new WeakSet();
8
+ const makeObserverVisitor = {
9
+ visitObject: noop,
10
+ visitArray: noop,
11
+ visitProperty(object, propertyName, value) {
12
+ Reflect.defineProperty(object, propertyName, {
13
+ enumerable: true,
14
+ get() {
15
+ Observable.track(object, propertyName);
16
+ return value;
17
+ },
18
+ set(newValue) {
19
+ if (value !== newValue) {
20
+ value = newValue;
21
+ Observable.notify(object, propertyName);
22
+ }
23
+ },
24
+ });
25
+ },
26
+ };
27
+ /**
28
+ * Converts a plain object to a reactive, observable object.
29
+ *
30
+ * @privateRemarks
31
+ * Code borrowed from fast-element v2. We can remove post upgrade.
32
+ *
33
+ * @example
34
+ * An array or reactive items.
35
+ * ```ts
36
+ * this.todos = todosResponse.map((t) => reactive(t));
37
+ * ```
38
+ *
39
+ * @example
40
+ * Add item.
41
+ * ```ts
42
+ * add(description: string) {
43
+ * this.splice(this.todos.length, 0, reactive({ description, done: false }));
44
+ * }
45
+ * ```
46
+ *
47
+ * @example
48
+ * Remove item.
49
+ * ```ts
50
+ * remove(todo: Todo) {
51
+ * const index = this.todos.indexOf(todo);
52
+ * index !== -1 && this.splice(index, 1);
53
+ * }
54
+ *```
55
+ *
56
+ * @param object - The object to make reactive.
57
+ * @param deep - Indicates whether to deeply convert the object.
58
+ * @returns The converted object.
59
+ *
60
+ * @beta
61
+ */
62
+ export function reactive(object, deep = false) {
63
+ visitObject(object, deep, makeObserverVisitor, void 0, observed);
64
+ return object;
65
+ }
@@ -0,0 +1,53 @@
1
+ function shouldTraverse(value, traversed) {
2
+ return value !== null && value !== void 0 && typeof value === 'object' && !traversed.has(value);
3
+ }
4
+ /**
5
+ * Visit object utility.
6
+ *
7
+ * @privateRemarks
8
+ * Code borrowed from fast-element v2. We can remove post upgrade.
9
+ *
10
+ * @example
11
+ * Reactive example.
12
+ * ```ts
13
+ * export function reactive<T>(object: T, deep = false): T {
14
+ * visitObject(object, deep, makeObserverVisitor, void 0, observed);
15
+ * return object;
16
+ * }
17
+ * ```
18
+ *
19
+ * @param object - The object.
20
+ * @param deep - A flag to indicate if a recursive visit of sub objects should occur.
21
+ * @param visitor - The defined {@link ObjectVisitor} logic.
22
+ * @param data - Visitor data.
23
+ * @param traversed - The traversed object set.
24
+ *
25
+ * @beta
26
+ */
27
+ export function visitObject(object, deep, visitor, data, traversed) {
28
+ if (!shouldTraverse(object, traversed)) {
29
+ return;
30
+ }
31
+ traversed.add(object);
32
+ if (Array.isArray(object)) {
33
+ visitor.visitArray(object, data);
34
+ for (const item of object) {
35
+ visitObject(item, deep, visitor, data, traversed);
36
+ }
37
+ }
38
+ else {
39
+ visitor.visitObject(object, data);
40
+ for (const key in object) {
41
+ /**
42
+ * Added this hasOwnProperty guard
43
+ */
44
+ if (object.hasOwnProperty(key)) {
45
+ const value = object[key];
46
+ visitor.visitProperty(object, key, value, data);
47
+ if (deep) {
48
+ visitObject(value, deep, visitor, data, traversed);
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }