-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use fewer data attributes * Add changeset
- Loading branch information
Showing
9 changed files
with
142 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
"corset": minor | ||
--- | ||
|
||
Consolidate data properties | ||
|
||
This consolidates data attributes, grouping them by type, so that you might have: | ||
|
||
```html | ||
<div data-corset-props="--one --two --three"></div> | ||
``` | ||
|
||
Instead of: | ||
|
||
```html | ||
<div data-corset-prop-one data-corset-prop-two data-corset-prop-three></div> | ||
``` | ||
|
||
This means less clutter in the DOM. | ||
|
||
In addition to `data-corset-props` there is also `data-corset-stores` for stores and `data-corset-scope` for each scope values (item and index). |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,69 @@ | ||
|
||
/** | ||
* | ||
* @param {string} dataPropName | ||
* @param {string | null} dataPropName | ||
* @param {string} dataSelector | ||
* @param {string} propName | ||
* @returns | ||
*/ | ||
export function lookup(element, dataPropName, dataSelector, propName) { | ||
export function lookup(element, dataSelector, propName) { | ||
/** @type {Element | null} */ | ||
let el = element; | ||
do { | ||
if(el.hasAttribute(dataPropName)) { | ||
if(el.matches(dataSelector)) { | ||
return /** @type {any} */(el)[Symbol.for(propName)]; | ||
} | ||
el = element.closest(dataSelector); | ||
} while(el); | ||
} | ||
|
||
|
||
|
||
/** | ||
* | ||
* @param {HTMLElement} element | ||
* @param {symbol} listSym | ||
* @param {string} key | ||
* @param {symbol} keySym | ||
* @param {string} dataProp | ||
* @param {any} value | ||
*/ | ||
export function addItemToScope(element, listSym, key, keySym, dataProp, value) { | ||
let e = /** @type {any} */(element); | ||
/** @type {Set<string>} */ | ||
|
||
let list = e[listSym]; | ||
if(!list) { | ||
list = e[listSym] = new Set(); | ||
} | ||
list.add(key); | ||
let str = Array.from(list).join(' '); | ||
element.dataset[dataProp] = str; | ||
|
||
e[keySym] = value; | ||
} | ||
|
||
/** | ||
* | ||
* @param {HTMLElement} element | ||
* @param {symbol} listSym | ||
* @param {string} key | ||
* @param {symbol} keySym | ||
* @param {string} dataProp | ||
*/ | ||
export function removeItemFromScope(element, listSym, key, keySym, dataProp) { | ||
let e = /** @type {any} */(element); | ||
/** @type {Set<string> | undefined} */ | ||
let list = e[listSym]; | ||
if(list) { | ||
list.delete(key); | ||
delete e[keySym]; | ||
if(list.size) { | ||
let str = Array.from(list).join(' '); | ||
element.dataset[dataProp] = str; | ||
} else { | ||
delete e[keySym]; | ||
delete element.dataset[dataProp]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters