@genesislcap/foundation-utils 14.134.0 → 14.136.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",
@@ -417,56 +475,6 @@
417
475
  }
418
476
  ]
419
477
  },
420
- {
421
- "kind": "javascript-module",
422
- "path": "src/design-system/design-system.ts",
423
- "declarations": [
424
- {
425
- "kind": "function",
426
- "name": "assureDesignSystem",
427
- "return": {
428
- "type": {
429
- "text": "DesignSystemModule"
430
- }
431
- },
432
- "parameters": [
433
- {
434
- "name": "module",
435
- "type": {
436
- "text": "DesignSystemModule"
437
- }
438
- }
439
- ],
440
- "description": "assureDesignSystem.",
441
- "privacy": "public"
442
- }
443
- ],
444
- "exports": [
445
- {
446
- "kind": "js",
447
- "name": "assureDesignSystem",
448
- "declaration": {
449
- "name": "assureDesignSystem",
450
- "module": "src/design-system/design-system.ts"
451
- }
452
- }
453
- ]
454
- },
455
- {
456
- "kind": "javascript-module",
457
- "path": "src/design-system/index.ts",
458
- "declarations": [],
459
- "exports": [
460
- {
461
- "kind": "js",
462
- "name": "*",
463
- "declaration": {
464
- "name": "*",
465
- "package": "./design-system"
466
- }
467
- }
468
- ]
469
- },
470
478
  {
471
479
  "kind": "javascript-module",
472
480
  "path": "src/env/index.ts",
@@ -1225,6 +1233,78 @@
1225
1233
  }
1226
1234
  ]
1227
1235
  },
1236
+ {
1237
+ "kind": "javascript-module",
1238
+ "path": "src/observer/index.ts",
1239
+ "declarations": [],
1240
+ "exports": [
1241
+ {
1242
+ "kind": "js",
1243
+ "name": "*",
1244
+ "declaration": {
1245
+ "name": "*",
1246
+ "package": "./observer"
1247
+ }
1248
+ }
1249
+ ]
1250
+ },
1251
+ {
1252
+ "kind": "javascript-module",
1253
+ "path": "src/observer/observer.ts",
1254
+ "declarations": [
1255
+ {
1256
+ "kind": "function",
1257
+ "name": "createObserver",
1258
+ "return": {
1259
+ "type": {
1260
+ "text": "Observer<EventType>"
1261
+ }
1262
+ },
1263
+ "description": "Creates a new event observer instance.",
1264
+ "privacy": "public"
1265
+ },
1266
+ {
1267
+ "kind": "function",
1268
+ "name": "respondToVisibility",
1269
+ "parameters": [
1270
+ {
1271
+ "name": "element",
1272
+ "type": {
1273
+ "text": "HTMLElement"
1274
+ },
1275
+ "description": "HTMLElement to observe"
1276
+ },
1277
+ {
1278
+ "name": "callback",
1279
+ "type": {
1280
+ "text": "(arg0: boolean) => any"
1281
+ },
1282
+ "description": "any function called when the visibility changes"
1283
+ }
1284
+ ],
1285
+ "description": "Setup an `IntersectionObserver` which will activate a callback function when an element becomes visible on screen",
1286
+ "privacy": "public"
1287
+ }
1288
+ ],
1289
+ "exports": [
1290
+ {
1291
+ "kind": "js",
1292
+ "name": "createObserver",
1293
+ "declaration": {
1294
+ "name": "createObserver",
1295
+ "module": "src/observer/observer.ts"
1296
+ }
1297
+ },
1298
+ {
1299
+ "kind": "js",
1300
+ "name": "respondToVisibility",
1301
+ "declaration": {
1302
+ "name": "respondToVisibility",
1303
+ "module": "src/observer/observer.ts"
1304
+ }
1305
+ }
1306
+ ]
1307
+ },
1228
1308
  {
1229
1309
  "kind": "javascript-module",
1230
1310
  "path": "src/resource/index.ts",
@@ -1283,7 +1363,7 @@
1283
1363
  },
1284
1364
  {
1285
1365
  "kind": "javascript-module",
1286
- "path": "src/observer/index.ts",
1366
+ "path": "src/state/index.ts",
1287
1367
  "declarations": [],
1288
1368
  "exports": [
1289
1369
  {
@@ -1291,64 +1371,118 @@
1291
1371
  "name": "*",
1292
1372
  "declaration": {
1293
1373
  "name": "*",
1294
- "package": "./observer"
1374
+ "package": "./reactive"
1375
+ }
1376
+ },
1377
+ {
1378
+ "kind": "js",
1379
+ "name": "*",
1380
+ "declaration": {
1381
+ "name": "*",
1382
+ "package": "./visitor"
1295
1383
  }
1296
1384
  }
1297
1385
  ]
1298
1386
  },
1299
1387
  {
1300
1388
  "kind": "javascript-module",
1301
- "path": "src/observer/observer.ts",
1389
+ "path": "src/state/reactive.ts",
1302
1390
  "declarations": [
1303
1391
  {
1304
1392
  "kind": "function",
1305
- "name": "createObserver",
1393
+ "name": "reactive",
1306
1394
  "return": {
1307
1395
  "type": {
1308
- "text": "Observer<EventType>"
1396
+ "text": ""
1309
1397
  }
1310
1398
  },
1311
- "description": "Creates a new event observer instance.",
1312
- "privacy": "public"
1313
- },
1314
- {
1315
- "kind": "function",
1316
- "name": "respondToVisibility",
1317
1399
  "parameters": [
1318
1400
  {
1319
- "name": "element",
1401
+ "name": "object",
1320
1402
  "type": {
1321
- "text": "HTMLElement"
1403
+ "text": "T"
1322
1404
  },
1323
- "description": "HTMLElement to observe"
1405
+ "description": "The object to make reactive."
1324
1406
  },
1325
1407
  {
1326
- "name": "callback",
1327
- "type": {
1328
- "text": "(arg0: boolean) => any"
1329
- },
1330
- "description": "any function called when the visibility changes"
1408
+ "name": "deep",
1409
+ "default": "false",
1410
+ "description": "Indicates whether to deeply convert the object."
1331
1411
  }
1332
1412
  ],
1333
- "description": "Setup an `IntersectionObserver` which will activate a callback function when an element becomes visible on screen",
1334
- "privacy": "public"
1413
+ "description": "Converts a plain object to a reactive, observable object."
1335
1414
  }
1336
1415
  ],
1337
1416
  "exports": [
1338
1417
  {
1339
1418
  "kind": "js",
1340
- "name": "createObserver",
1419
+ "name": "reactive",
1341
1420
  "declaration": {
1342
- "name": "createObserver",
1343
- "module": "src/observer/observer.ts"
1421
+ "name": "reactive",
1422
+ "module": "src/state/reactive.ts"
1344
1423
  }
1345
- },
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": [
1346
1480
  {
1347
1481
  "kind": "js",
1348
- "name": "respondToVisibility",
1482
+ "name": "visitObject",
1349
1483
  "declaration": {
1350
- "name": "respondToVisibility",
1351
- "module": "src/observer/observer.ts"
1484
+ "name": "visitObject",
1485
+ "module": "src/state/visitor.ts"
1352
1486
  }
1353
1487
  }
1354
1488
  ]
@@ -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
+ }