@microsoft/fast-html 1.0.0-alpha.32 → 1.0.0-alpha.34

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.
@@ -20,6 +20,7 @@ export declare class ObserverMap {
20
20
  * Creates a property change handler function for observable properties
21
21
  * This handler is called when an observable property transitions from undefined to a defined value
22
22
  * @param propertyName - The name of the property for which to create the change handler
23
+ * @param existingChangedMethod - Optional existing changed method to call after the instance resolver logic
23
24
  * @returns A function that handles property changes and sets up proxies for object values
24
25
  */
25
26
  private defineChanged;
@@ -165,4 +165,20 @@ export declare function getRootPropertyName(rootPropertyName: string | null, pat
165
165
  * @returns null, or a custom element name and attribute name
166
166
  */
167
167
  export declare function getChildrenMap(previousString: string | null): ChildrenMap | null;
168
+ /**
169
+ * Deeply compares two objects for equality.
170
+ *
171
+ * @param obj1 - First object to compare
172
+ * @param obj2 - Second object to compare
173
+ * @returns True if the objects are deeply equal, false otherwise
174
+ */
175
+ export declare function deepEqual(obj1: any, obj2: any): boolean;
176
+ /**
177
+ * Deeply merges the source object into the target object.
178
+ *
179
+ * @param target - The target object to merge into
180
+ * @param source - The source object to merge from
181
+ * @returns void
182
+ */
183
+ export declare function deepMerge(target: any, source: any): void;
168
184
  export {};
@@ -10,20 +10,24 @@ export class ObserverMap {
10
10
  * Creates a property change handler function for observable properties
11
11
  * This handler is called when an observable property transitions from undefined to a defined value
12
12
  * @param propertyName - The name of the property for which to create the change handler
13
+ * @param existingChangedMethod - Optional existing changed method to call after the instance resolver logic
13
14
  * @returns A function that handles property changes and sets up proxies for object values
14
15
  */
15
- this.defineChanged = (propertyName) => {
16
+ this.defineChanged = (propertyName, existingChangedMethod) => {
16
17
  const getAndAssignObservablesAlias = this.getAndAssignObservables;
17
18
  const schema = this.schema;
18
19
  function instanceResolverChanged(prev, next) {
19
- if (prev === undefined ||
20
+ if (next === null || typeof next !== "object") {
21
+ this[propertyName] = next;
22
+ }
23
+ else if (prev === undefined ||
20
24
  ((prev === null || prev === void 0 ? void 0 : prev.$isProxy) && !(next === null || next === void 0 ? void 0 : next.$isProxy)) ||
21
25
  (Array.isArray(prev) &&
22
26
  Array.isArray(next) &&
23
27
  !(next === null || next === void 0 ? void 0 : next.$fastController))) {
24
- const proxy = getAndAssignObservablesAlias(this, propertyName, next, schema);
25
- this[propertyName] = proxy;
28
+ this[propertyName] = getAndAssignObservablesAlias(this, propertyName, next, schema);
26
29
  }
30
+ existingChangedMethod === null || existingChangedMethod === void 0 ? void 0 : existingChangedMethod.call(this, prev, next);
27
31
  }
28
32
  return instanceResolverChanged;
29
33
  };
@@ -32,10 +36,15 @@ export class ObserverMap {
32
36
  }
33
37
  defineProperties() {
34
38
  const propertyNames = this.schema.getRootProperties();
39
+ const existingAccessors = Observable.getAccessors(this.classPrototype);
35
40
  for (const propertyName of propertyNames) {
36
- Observable.defineProperty(this.classPrototype, propertyName);
37
- this.classPrototype[`${propertyName}Changed`] =
38
- this.defineChanged(propertyName);
41
+ // Skip if property already has an accessor (from `@attr` or `@observable` decorator)
42
+ if (!existingAccessors.some(accessor => accessor.name === propertyName)) {
43
+ Observable.defineProperty(this.classPrototype, propertyName);
44
+ }
45
+ const changedMethodName = `${propertyName}Changed`;
46
+ const existingChangedMethod = this.classPrototype[changedMethodName];
47
+ this.classPrototype[changedMethodName] = this.defineChanged(propertyName, existingChangedMethod);
39
48
  }
40
49
  }
41
50
  /**
@@ -970,3 +970,104 @@ function getAttributeName(previousString) {
970
970
  }
971
971
  return attributeName;
972
972
  }
973
+ /**
974
+ * Deeply compares two objects for equality.
975
+ *
976
+ * @param obj1 - First object to compare
977
+ * @param obj2 - Second object to compare
978
+ * @returns True if the objects are deeply equal, false otherwise
979
+ */
980
+ export function deepEqual(obj1, obj2) {
981
+ if (Object.is(obj1, obj2)) {
982
+ return true;
983
+ }
984
+ if (obj1 == null || obj2 == null) {
985
+ return false;
986
+ }
987
+ const type1 = typeof obj1;
988
+ const type2 = typeof obj2;
989
+ if (type1 !== type2 || type1 !== "object") {
990
+ return false;
991
+ }
992
+ const isArray1 = Array.isArray(obj1);
993
+ const isArray2 = Array.isArray(obj2);
994
+ if (isArray1 !== isArray2) {
995
+ return false;
996
+ }
997
+ if (isArray1) {
998
+ const len = obj1.length;
999
+ if (len !== obj2.length) {
1000
+ return false;
1001
+ }
1002
+ for (let i = 0; i < len; i++) {
1003
+ if (!deepEqual(obj1[i], obj2[i])) {
1004
+ return false;
1005
+ }
1006
+ }
1007
+ return true;
1008
+ }
1009
+ const hasOwn = Object.prototype.hasOwnProperty;
1010
+ let keyCount = 0;
1011
+ for (const key in obj1) {
1012
+ if (hasOwn.call(obj1, key)) {
1013
+ keyCount++;
1014
+ if (!hasOwn.call(obj2, key) || !deepEqual(obj1[key], obj2[key])) {
1015
+ return false;
1016
+ }
1017
+ }
1018
+ }
1019
+ let obj2KeyCount = 0;
1020
+ for (const key in obj2) {
1021
+ if (hasOwn.call(obj2, key)) {
1022
+ obj2KeyCount++;
1023
+ }
1024
+ }
1025
+ return keyCount === obj2KeyCount;
1026
+ }
1027
+ /**
1028
+ * Deeply merges the source object into the target object.
1029
+ *
1030
+ * @param target - The target object to merge into
1031
+ * @param source - The source object to merge from
1032
+ * @returns void
1033
+ */
1034
+ export function deepMerge(target, source) {
1035
+ const hasOwn = Object.prototype.hasOwnProperty;
1036
+ for (const key in source) {
1037
+ if (!hasOwn.call(source, key)) {
1038
+ continue;
1039
+ }
1040
+ const sourceValue = source[key];
1041
+ if (sourceValue === void 0) {
1042
+ continue;
1043
+ }
1044
+ const targetValue = target[key];
1045
+ if (deepEqual(targetValue, sourceValue)) {
1046
+ continue;
1047
+ }
1048
+ const isSourceArray = Array.isArray(sourceValue);
1049
+ if (isSourceArray) {
1050
+ const isTargetArray = Array.isArray(targetValue);
1051
+ const clonedItems = sourceValue.map((item) => item && typeof item === "object" ? Object.assign({}, item) : item);
1052
+ if (isTargetArray) {
1053
+ // Use splice to maintain observable array tracking
1054
+ targetValue.splice(0, targetValue.length, ...clonedItems);
1055
+ }
1056
+ else {
1057
+ // Target isn't an array, replace it
1058
+ target[key] = clonedItems;
1059
+ }
1060
+ continue;
1061
+ }
1062
+ if (sourceValue && typeof sourceValue === "object") {
1063
+ if (!targetValue ||
1064
+ typeof targetValue !== "object" ||
1065
+ Array.isArray(targetValue)) {
1066
+ target[key] = {};
1067
+ }
1068
+ deepMerge(target[key], sourceValue);
1069
+ continue;
1070
+ }
1071
+ target[key] = sourceValue;
1072
+ }
1073
+ }
@@ -105,6 +105,7 @@ export declare class ObserverMap {
105
105
  * Creates a property change handler function for observable properties
106
106
  * This handler is called when an observable property transitions from undefined to a defined value
107
107
  * @param propertyName - The name of the property for which to create the change handler
108
+ * @param existingChangedMethod - Optional existing changed method to call after the instance resolver logic
108
109
  * @returns A function that handles property changes and sets up proxies for object values
109
110
  */
110
111
  private defineChanged;
@@ -105,6 +105,7 @@ export declare class ObserverMap {
105
105
  * Creates a property change handler function for observable properties
106
106
  * This handler is called when an observable property transitions from undefined to a defined value
107
107
  * @param propertyName - The name of the property for which to create the change handler
108
+ * @param existingChangedMethod - Optional existing changed method to call after the instance resolver logic
108
109
  * @returns A function that handles property changes and sets up proxies for object values
109
110
  */
110
111
  private defineChanged;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/fast-html",
3
- "version": "1.0.0-alpha.32",
3
+ "version": "1.0.0-alpha.34",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Microsoft",
@@ -11,7 +11,7 @@
11
11
  "repository": {
12
12
  "type": "git",
13
13
  "url": "git+https://github.com/Microsoft/fast.git",
14
- "directory": "packages/web-components/fast-html"
14
+ "directory": "packages/fast-html"
15
15
  },
16
16
  "bugs": {
17
17
  "url": "https://github.com/Microsoft/fast/issues/new/choose"
@@ -47,6 +47,10 @@
47
47
  "types": "./dist/dts/index.d.ts",
48
48
  "default": "./dist/esm/index.js"
49
49
  },
50
+ "./utilities.js": {
51
+ "types": "./dist/dts/components/utilities.d.ts",
52
+ "default": "./dist/esm/components/utilities.js"
53
+ },
50
54
  "./rules/*.yml": "./rules/*.yml",
51
55
  "./package.json": "./package.json"
52
56
  },
@@ -54,12 +58,12 @@
54
58
  "./dist/esm/index.js"
55
59
  ],
56
60
  "peerDependencies": {
57
- "@microsoft/fast-element": "^2.8.2"
61
+ "@microsoft/fast-element": "^2.8.3"
58
62
  },
59
63
  "devDependencies": {
60
64
  "@ast-grep/cli": "^0.37.0",
61
65
  "@microsoft/api-extractor": "^7.47.0",
62
- "@microsoft/fast-element": "^2.8.2",
66
+ "@microsoft/fast-element": "^2.8.3",
63
67
  "@types/express": "^4.17.21",
64
68
  "@types/node": "^17.0.17",
65
69
  "typescript": "~5.3.0"