saasufy-components 7.8.0 → 7.9.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils.js +32 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "7.8.0",
3
+ "version": "7.9.0",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils.js CHANGED
@@ -484,6 +484,38 @@ export function formatError(error) {
484
484
  return error.code === 1009 ? 'Resource exceeded the maximum size' : error.message;
485
485
  }
486
486
 
487
+ export function logAttributeChanges(...elementSelectors) {
488
+ let domObserverCallback = (mutationList) => {
489
+ for (let mutation of mutationList) {
490
+ let matchingSelector = (elementSelectors || []).find(elementSelector => mutation.target?.matches(elementSelector));
491
+ let isWatchingElement = !elementSelectors.length || !!matchingSelector;
492
+ if (mutation.type === 'attributes' && isWatchingElement) {
493
+ let identifier = mutation.target.id || matchingSelector || mutation.target.nodeName?.toLowerCase();
494
+ console.log(
495
+ `[${identifier}] Attribute ${
496
+ mutation.attributeName
497
+ } changed to: ${
498
+ mutation.target.getAttribute(mutation.attributeName)
499
+ }`
500
+ );
501
+ }
502
+ }
503
+ };
504
+
505
+ let observer = new MutationObserver(domObserverCallback);
506
+
507
+ let config = {
508
+ attributes: true,
509
+ subtree: true,
510
+ attributeOldValue: true
511
+ };
512
+
513
+ observer.observe(document, config);
514
+ return () => {
515
+ observer.disconnect();
516
+ };
517
+ }
518
+
487
519
  export function wait(duration) {
488
520
  return new Promise((resolve) => setTimeout(resolve, duration));
489
521
  }