@srfnstack/fntags 0.3.6 → 0.3.8
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/package.json +1 -1
- package/src/fntags.mjs +22 -0
package/package.json
CHANGED
package/src/fntags.mjs
CHANGED
|
@@ -29,9 +29,21 @@ export function h (tag, ...children) {
|
|
|
29
29
|
if (isAttrs(children[firstChildIdx])) {
|
|
30
30
|
const attrs = children[firstChildIdx]
|
|
31
31
|
firstChildIdx += 1
|
|
32
|
+
let hasValue = false
|
|
32
33
|
for (const a in attrs) {
|
|
34
|
+
// set value last to ensure value constraints are set before trying to set the value to avoid modification
|
|
35
|
+
// For example, when using a range and specifying a min and max
|
|
36
|
+
// if the value is set first and is outside the default 1 to 100 range
|
|
37
|
+
// the value will be adjusted to be within the range, even though the value attribute will be set correctly
|
|
38
|
+
if (a === 'value') {
|
|
39
|
+
hasValue = true
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
33
42
|
setAttribute(a, attrs[a], element)
|
|
34
43
|
}
|
|
44
|
+
if (hasValue) {
|
|
45
|
+
setAttribute('value', attrs.value, element)
|
|
46
|
+
}
|
|
35
47
|
}
|
|
36
48
|
for (let i = firstChildIdx; i < children.length; i++) {
|
|
37
49
|
const child = children[i]
|
|
@@ -169,6 +181,16 @@ export const fnstate = (initialValue, mapKey) => {
|
|
|
169
181
|
*/
|
|
170
182
|
ctx.state.bindAs = (element, update) => doBindAs(ctx, element ?? ctx.state, update)
|
|
171
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Bind a property of an object stored in this state as a simple value.
|
|
186
|
+
*
|
|
187
|
+
* Shortcut for `mystate.bindAs((current)=> current[prop])`
|
|
188
|
+
*
|
|
189
|
+
* @param {string} prop The object property to bind as
|
|
190
|
+
* @returns {(HTMLDivElement|Text)[]|HTMLDivElement|Text}
|
|
191
|
+
*/
|
|
192
|
+
ctx.state.bindProp = (prop) => doBindAs(ctx, (st) => st[prop])
|
|
193
|
+
|
|
172
194
|
/**
|
|
173
195
|
* Bind attribute values to state changes
|
|
174
196
|
* @param [attribute] A function that returns an attribute value. If not passed, defaults to the state's value
|