assign-gingerly 0.0.13 → 0.0.15
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 +37 -3
- package/assignGingerly.ts +1 -1
- package/object-extension.js +13 -13
- package/object-extension.ts +17 -17
- package/package.json +10 -9
- package/parseWithAttrs.ts +1 -1
- package/types/LICENSE +21 -0
- package/types/README.md +2 -0
- /package/{types.d.ts → types/assign-gingerly/types.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1400,14 +1400,48 @@ console.log(instance.count); // 42 (parsed from attribute)
|
|
|
1400
1400
|
console.log(instance.theme); // 'dark' (parsed from attribute)
|
|
1401
1401
|
```
|
|
1402
1402
|
|
|
1403
|
+
**Example without enhKey:**
|
|
1404
|
+
|
|
1405
|
+
```TypeScript
|
|
1406
|
+
// withAttrs works even without enhKey
|
|
1407
|
+
class SimpleEnhancement {
|
|
1408
|
+
element;
|
|
1409
|
+
ctx;
|
|
1410
|
+
value = null;
|
|
1411
|
+
|
|
1412
|
+
constructor(oElement, ctx, initVals) {
|
|
1413
|
+
this.element = oElement;
|
|
1414
|
+
this.ctx = ctx;
|
|
1415
|
+
if (initVals) {
|
|
1416
|
+
Object.assign(this, initVals);
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
const element = document.createElement('div');
|
|
1422
|
+
element.setAttribute('data-value', 'test123');
|
|
1423
|
+
|
|
1424
|
+
const config = {
|
|
1425
|
+
spawn: SimpleEnhancement,
|
|
1426
|
+
// No enhKey - attributes still parsed!
|
|
1427
|
+
withAttrs: {
|
|
1428
|
+
base: 'data-',
|
|
1429
|
+
value: '${base}value'
|
|
1430
|
+
}
|
|
1431
|
+
};
|
|
1432
|
+
|
|
1433
|
+
const instance = element.enh.get(config);
|
|
1434
|
+
console.log(instance.value); // 'test123' (parsed from attribute)
|
|
1435
|
+
```
|
|
1436
|
+
|
|
1403
1437
|
**How it works:**
|
|
1404
1438
|
1. When an enhancement is spawned via `enh.get()`, `enh.set`, or `assignGingerly()`
|
|
1405
1439
|
2. If the registry item has a `withAttrs` property defined
|
|
1406
1440
|
3. `parseWithAttrs(element, registryItem.withAttrs)` is automatically called
|
|
1407
|
-
4. The parsed attributes are
|
|
1408
|
-
5.
|
|
1441
|
+
4. The parsed attributes are passed to the enhancement constructor as `initVals`
|
|
1442
|
+
5. If the registry item also has an `enhKey`, the parsed attributes are merged with any existing values from `element.enh[enhKey]` (existing values take precedence)
|
|
1409
1443
|
|
|
1410
|
-
**
|
|
1444
|
+
**Note**: `withAttrs` works with or without `enhKey`. When there's no `enhKey`, the parsed attributes are passed directly to the constructor. When there is an `enhKey`, they're merged with any pre-existing values on the enh container.
|
|
1411
1445
|
|
|
1412
1446
|
|
|
1413
1447
|
|
package/assignGingerly.ts
CHANGED
package/object-extension.js
CHANGED
|
@@ -82,21 +82,21 @@ class ElementEnhancementContainer {
|
|
|
82
82
|
return undefined;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
+
// Parse attributes if withAttrs is defined (regardless of enhKey)
|
|
86
|
+
let attrInitVals = undefined;
|
|
87
|
+
if (registryItem.withAttrs && element) {
|
|
88
|
+
try {
|
|
89
|
+
attrInitVals = parseWithAttrs(element, registryItem.withAttrs, registryItem.allowUnprefixed || false);
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
console.error('Error parsing attributes:', e);
|
|
93
|
+
throw e;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
85
96
|
// Check if there's an enhKey
|
|
86
97
|
if (registryItem.enhKey) {
|
|
87
98
|
const ctx = { config: registryItem, mountCtx };
|
|
88
99
|
const self = this;
|
|
89
|
-
// Parse attributes if withAttrs is defined
|
|
90
|
-
let attrInitVals = undefined;
|
|
91
|
-
if (registryItem.withAttrs && element) {
|
|
92
|
-
try {
|
|
93
|
-
attrInitVals = parseWithAttrs(element, registryItem.withAttrs, registryItem.allowUnprefixed || false);
|
|
94
|
-
}
|
|
95
|
-
catch (e) {
|
|
96
|
-
console.error('Error parsing attributes:', e);
|
|
97
|
-
throw e;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
100
|
// Get existing initVals from enhKey
|
|
101
101
|
const existingInitVals = self[registryItem.enhKey] &&
|
|
102
102
|
!(self[registryItem.enhKey] instanceof SpawnClass)
|
|
@@ -111,9 +111,9 @@ class ElementEnhancementContainer {
|
|
|
111
111
|
self[registryItem.enhKey] = instance;
|
|
112
112
|
}
|
|
113
113
|
else {
|
|
114
|
-
// No enhKey,
|
|
114
|
+
// No enhKey, still pass attrInitVals
|
|
115
115
|
const ctx = { config: registryItem, mountCtx };
|
|
116
|
-
instance = new SpawnClass(element, ctx);
|
|
116
|
+
instance = new SpawnClass(element, ctx, attrInitVals);
|
|
117
117
|
}
|
|
118
118
|
// Store in global instance map
|
|
119
119
|
instances.set(registryItem, instance);
|
package/object-extension.ts
CHANGED
|
@@ -156,26 +156,26 @@ class ElementEnhancementContainer {
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
+
// Parse attributes if withAttrs is defined (regardless of enhKey)
|
|
160
|
+
let attrInitVals: any = undefined;
|
|
161
|
+
if (registryItem.withAttrs && element) {
|
|
162
|
+
try {
|
|
163
|
+
attrInitVals = parseWithAttrs(
|
|
164
|
+
element,
|
|
165
|
+
registryItem.withAttrs,
|
|
166
|
+
registryItem.allowUnprefixed || false
|
|
167
|
+
);
|
|
168
|
+
} catch (e) {
|
|
169
|
+
console.error('Error parsing attributes:', e);
|
|
170
|
+
throw e;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
159
174
|
// Check if there's an enhKey
|
|
160
175
|
if (registryItem.enhKey) {
|
|
161
176
|
const ctx = { config: registryItem, mountCtx };
|
|
162
177
|
const self = this as any;
|
|
163
178
|
|
|
164
|
-
// Parse attributes if withAttrs is defined
|
|
165
|
-
let attrInitVals: any = undefined;
|
|
166
|
-
if (registryItem.withAttrs && element) {
|
|
167
|
-
try {
|
|
168
|
-
attrInitVals = parseWithAttrs(
|
|
169
|
-
element,
|
|
170
|
-
registryItem.withAttrs,
|
|
171
|
-
registryItem.allowUnprefixed || false
|
|
172
|
-
);
|
|
173
|
-
} catch (e) {
|
|
174
|
-
console.error('Error parsing attributes:', e);
|
|
175
|
-
throw e;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
179
|
// Get existing initVals from enhKey
|
|
180
180
|
const existingInitVals = self[registryItem.enhKey] &&
|
|
181
181
|
!(self[registryItem.enhKey] instanceof SpawnClass)
|
|
@@ -192,9 +192,9 @@ class ElementEnhancementContainer {
|
|
|
192
192
|
// Store on enh container
|
|
193
193
|
self[registryItem.enhKey] = instance;
|
|
194
194
|
} else {
|
|
195
|
-
// No enhKey,
|
|
195
|
+
// No enhKey, still pass attrInitVals
|
|
196
196
|
const ctx = { config: registryItem, mountCtx };
|
|
197
|
-
instance = new SpawnClass(element, ctx);
|
|
197
|
+
instance = new SpawnClass(element, ctx, attrInitVals);
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
// Store in global instance map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assign-gingerly",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "This package provides a utility function for carefully merging one object into another.",
|
|
5
5
|
"homepage": "https://github.com/bahrus/assign-gingerly#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -13,25 +13,26 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"author": "Bruce B. Anderson <andeson.bruce.b@gmail.com>",
|
|
15
15
|
"type": "module",
|
|
16
|
-
"types": "types.d.ts",
|
|
16
|
+
"types": "types/assign-gingerly/types.d.ts",
|
|
17
17
|
"files": [
|
|
18
18
|
"*.js",
|
|
19
19
|
"*.ts",
|
|
20
20
|
"README.md",
|
|
21
|
-
"LICENSE"
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"types/assign-gingerly/types.d.ts"
|
|
22
23
|
],
|
|
23
24
|
"exports": {
|
|
24
25
|
".": {
|
|
25
26
|
"default": "./index.js",
|
|
26
|
-
"types": "./
|
|
27
|
+
"types": "./index.ts"
|
|
27
28
|
},
|
|
28
29
|
"./assignGingerly.js": {
|
|
29
30
|
"default": "./assignGingerly.js",
|
|
30
|
-
"types": "./
|
|
31
|
+
"types": "./assignGingerly.ts"
|
|
31
32
|
},
|
|
32
33
|
"./assignTentatively.js": {
|
|
33
34
|
"default": "./assignTentatively.js",
|
|
34
|
-
"types": "./
|
|
35
|
+
"types": "./assignTentatively.ts"
|
|
35
36
|
},
|
|
36
37
|
"./waitForEvent.js": {
|
|
37
38
|
"default": "./waitForEvent.js"
|
|
@@ -41,7 +42,7 @@
|
|
|
41
42
|
},
|
|
42
43
|
"./parseWithAttrs.js": {
|
|
43
44
|
"default": "./parseWithAttrs.js",
|
|
44
|
-
"types": "./
|
|
45
|
+
"types": "./parseWithAttrs.ts"
|
|
45
46
|
}
|
|
46
47
|
},
|
|
47
48
|
"main": "index.js",
|
|
@@ -53,8 +54,8 @@
|
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@playwright/test": "^1.58.2",
|
|
56
|
-
"spa-ssi": "0.0.
|
|
57
|
-
"@types/node": "^25.
|
|
57
|
+
"spa-ssi": "0.0.27",
|
|
58
|
+
"@types/node": "^25.3.0",
|
|
58
59
|
"typescript": "^5.9.3"
|
|
59
60
|
}
|
|
60
61
|
}
|
package/parseWithAttrs.ts
CHANGED
package/types/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bruce B. Anderson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/types/README.md
ADDED
|
File without changes
|