@wix/interact 1.76.0 → 1.78.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.
- package/dist/cjs/WixInteractElement.js +3 -0
- package/dist/cjs/WixInteractElement.js.map +1 -1
- package/dist/cjs/__tests__/interact.spec.js +87 -18
- package/dist/cjs/__tests__/interact.spec.js.map +1 -1
- package/dist/cjs/core/Interact.js +7 -0
- package/dist/cjs/core/Interact.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/WixInteractElement.js +3 -0
- package/dist/esm/WixInteractElement.js.map +1 -1
- package/dist/esm/__tests__/interact.spec.js +87 -18
- package/dist/esm/__tests__/interact.spec.js.map +1 -1
- package/dist/esm/core/Interact.js +7 -0
- package/dist/esm/core/Interact.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/types/WixInteractElement.d.ts +1 -0
- package/dist/types/core/Interact.d.ts +1 -0
- package/dist/types/types.d.ts +1 -0
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_add","require","_remove","WIX_INTERACT_EFFECT_DATA_ATTR","exports","getWixInteractElement","checkedForLegacyStateSyntax","isLegacyStateSyntax","WixInteractElement","HTMLElement","constructor","_defineProperty2","default","connected","sheet","_observers","WeakMap","attachInternals","_internals","states","add","delete","e","connectedCallback","connect","disconnectedCallback","key","dataset","wixPath","remove","index","document","adoptedStyleSheets","indexOf","splice","console","warn","renderStyle","cssRules","CSSStyleSheet","replace","join","push","position","length","cssRule","insertRule","error","toggleEffect","effectId","method","has","clear","_this$dataset$WIX_INT","currentEffects","Set","split","Array","from","watchChildList","listContainer","list","querySelector","observer","get","MutationObserver","_childListChangeHandler","bind","set","observe","childList","entries","removedElements","addedElements","forEach","entry","removedNodes","el","addedNodes","removeListItems","addListItems"],"sources":["../../src/WixInteractElement.ts"],"sourcesContent":["import type { StateParams } from './types';\nimport { add, addListItems } from './core/add';\nimport { remove, removeListItems } from './core/remove';\n\nexport const WIX_INTERACT_EFFECT_DATA_ATTR = 'wixInteractEffect';\n\nexport function getWixInteractElement() {\n let checkedForLegacyStateSyntax = false;\n let isLegacyStateSyntax = false;\n\n return class WixInteractElement extends HTMLElement {\n _internals: (ElementInternals & { states: Set<string> }) | null;\n connected: boolean;\n sheet: CSSStyleSheet | null;\n _observers: WeakMap<HTMLElement, MutationObserver>;\n\n constructor() {\n super();\n\n this.connected = false;\n this.sheet = null;\n this._observers = new WeakMap();\n\n if (this.attachInternals) {\n this._internals = this.attachInternals() as ElementInternals & {\n states: Set<string>;\n };\n\n if (!checkedForLegacyStateSyntax) {\n checkedForLegacyStateSyntax = true;\n\n try {\n this._internals.states.add('test');\n this._internals.states.delete('test');\n } catch (e) {\n isLegacyStateSyntax = true;\n }\n }\n } else {\n checkedForLegacyStateSyntax = true; // custom states not supported - skip syntax check\n this._internals = null;\n }\n }\n connectedCallback() {\n this.connect();\n }\n\n disconnectedCallback() {\n const key = this.dataset.wixPath;\n\n if (key) {\n remove(key);\n }\n\n if (this.sheet) {\n const index = document.adoptedStyleSheets.indexOf(this.sheet);\n document.adoptedStyleSheets.splice(index, 1);\n }\n\n this._observers = new WeakMap();\n\n this.connected = false;\n }\n\n connect(key?: string) {\n if (this.connected) {\n return;\n }\n\n key = key || this.dataset.wixPath;\n\n if (!key) {\n console.warn('WixInteractElement: No key provided');\n return;\n }\n\n this.connected = add(this, key);\n }\n\n renderStyle(cssRules: string[]) {\n if (!this.sheet) {\n this.sheet = new CSSStyleSheet();\n void this.sheet.replace(cssRules.join('\\n'));\n\n document.adoptedStyleSheets.push(this.sheet);\n } else {\n let position = this.sheet.cssRules.length;\n\n for (const cssRule of cssRules) {\n try {\n this.sheet.insertRule(cssRule, position);\n position++;\n } catch (e) {\n console.error(e);\n }\n }\n }\n }\n\n toggleEffect(effectId: string, method: StateParams['method']) {\n if (isLegacyStateSyntax) {\n effectId = `--${effectId}`;\n }\n\n if (this._internals) {\n if (method === 'toggle') {\n this._internals.states.has(effectId)\n ? this._internals.states.delete(effectId)\n : this._internals.states.add(effectId);\n } else if (method === 'add') {\n this._internals.states.add(effectId);\n } else if (method === 'remove') {\n this._internals.states.delete(effectId);\n } else if (method === 'clear') {\n this._internals.states.clear();\n }\n } else {\n const currentEffects = new Set(\n this.dataset[WIX_INTERACT_EFFECT_DATA_ATTR]?.split(' ') || [],\n );\n\n if (method === 'toggle') {\n currentEffects.has(effectId)\n ? currentEffects.delete(effectId)\n : currentEffects.add(effectId);\n } else if (method === 'add') {\n currentEffects.add(effectId);\n } else if (method === 'remove') {\n currentEffects.delete(effectId);\n } else if (method === 'clear') {\n currentEffects.clear();\n }\n\n this.dataset[WIX_INTERACT_EFFECT_DATA_ATTR] =\n Array.from(currentEffects).join(' ');\n }\n }\n\n watchChildList(listContainer: string): void {\n const list = this.querySelector(listContainer);\n\n if (list) {\n // TODO: we can probably improve this and use less observers, this impl. uses one per container element\n let observer = this._observers.get(list as HTMLElement);\n\n if (!observer) {\n observer = new MutationObserver(\n this._childListChangeHandler.bind(this, listContainer),\n );\n\n this._observers.set(list as HTMLElement, observer);\n\n observer.observe(list as HTMLElement, { childList: true });\n }\n }\n }\n\n _childListChangeHandler(listContainer: string, entries: MutationRecord[]) {\n const key = this.dataset.wixPath;\n const removedElements: HTMLElement[] = [];\n const addedElements: HTMLElement[] = [];\n\n entries.forEach((entry) => {\n entry.removedNodes.forEach((el) => {\n if (el instanceof HTMLElement) {\n removedElements.push(el);\n }\n });\n\n entry.addedNodes.forEach((el) => {\n if (el instanceof HTMLElement) {\n addedElements.push(el);\n }\n });\n });\n\n removeListItems(removedElements);\n key && addListItems(this, key, listContainer, addedElements);\n }\n };\n}\n"],"mappings":";;;;;;;AACA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEO,MAAME,6BAA6B,GAAAC,OAAA,CAAAD,6BAAA,GAAG,mBAAmB;AAEzD,SAASE,qBAAqBA,CAAA,EAAG;EACtC,IA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J,OAAO,CAAEG,EAAE,IAAK;UAC/B,IAAIA,EAAE,YAAYpE,WAAW,EAAE;YAC7BgE,aAAa,CAAC/B,IAAI,CAACmC,EAAE,CAAC;UACxB;QACF,CAAC,CAAC;MACJ,CAAC,CAAC;MAEF,IAAAE,uBAAe,EAACP,eAAe,CAAC;MAChC9C,GAAG,IAAI,IAAAsD,iBAAY,EAAC,IAAI,EAAEtD,GAAG,EAAEkC,aAAa,EAAEa,aAAa,CAAC;IAC9D;EACF,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_add","require","_remove","WIX_INTERACT_EFFECT_DATA_ATTR","exports","getWixInteractElement","checkedForLegacyStateSyntax","isLegacyStateSyntax","WixInteractElement","HTMLElement","constructor","_defineProperty2","default","connected","sheet","_observers","WeakMap","attachInternals","_internals","states","add","delete","e","connectedCallback","connect","disconnectedCallback","disconnect","key","dataset","wixPath","remove","index","document","adoptedStyleSheets","indexOf","splice","console","warn","renderStyle","cssRules","CSSStyleSheet","replace","join","push","position","length","cssRule","insertRule","error","toggleEffect","effectId","method","has","clear","_this$dataset$WIX_INT","currentEffects","Set","split","Array","from","watchChildList","listContainer","list","querySelector","observer","get","MutationObserver","_childListChangeHandler","bind","set","observe","childList","entries","removedElements","addedElements","forEach","entry","removedNodes","el","addedNodes","removeListItems","addListItems"],"sources":["../../src/WixInteractElement.ts"],"sourcesContent":["import type { StateParams } from './types';\nimport { add, addListItems } from './core/add';\nimport { remove, removeListItems } from './core/remove';\n\nexport const WIX_INTERACT_EFFECT_DATA_ATTR = 'wixInteractEffect';\n\nexport function getWixInteractElement() {\n let checkedForLegacyStateSyntax = false;\n let isLegacyStateSyntax = false;\n\n return class WixInteractElement extends HTMLElement {\n _internals: (ElementInternals & { states: Set<string> }) | null;\n connected: boolean;\n sheet: CSSStyleSheet | null;\n _observers: WeakMap<HTMLElement, MutationObserver>;\n\n constructor() {\n super();\n\n this.connected = false;\n this.sheet = null;\n this._observers = new WeakMap();\n\n if (this.attachInternals) {\n this._internals = this.attachInternals() as ElementInternals & {\n states: Set<string>;\n };\n\n if (!checkedForLegacyStateSyntax) {\n checkedForLegacyStateSyntax = true;\n\n try {\n this._internals.states.add('test');\n this._internals.states.delete('test');\n } catch (e) {\n isLegacyStateSyntax = true;\n }\n }\n } else {\n checkedForLegacyStateSyntax = true; // custom states not supported - skip syntax check\n this._internals = null;\n }\n }\n connectedCallback() {\n this.connect();\n }\n\n disconnectedCallback() {\n this.disconnect();\n }\n\n disconnect() {\n const key = this.dataset.wixPath;\n\n if (key) {\n remove(key);\n }\n\n if (this.sheet) {\n const index = document.adoptedStyleSheets.indexOf(this.sheet);\n document.adoptedStyleSheets.splice(index, 1);\n }\n\n this._observers = new WeakMap();\n\n this.connected = false;\n }\n\n connect(key?: string) {\n if (this.connected) {\n return;\n }\n\n key = key || this.dataset.wixPath;\n\n if (!key) {\n console.warn('WixInteractElement: No key provided');\n return;\n }\n\n this.connected = add(this, key);\n }\n\n renderStyle(cssRules: string[]) {\n if (!this.sheet) {\n this.sheet = new CSSStyleSheet();\n void this.sheet.replace(cssRules.join('\\n'));\n\n document.adoptedStyleSheets.push(this.sheet);\n } else {\n let position = this.sheet.cssRules.length;\n\n for (const cssRule of cssRules) {\n try {\n this.sheet.insertRule(cssRule, position);\n position++;\n } catch (e) {\n console.error(e);\n }\n }\n }\n }\n\n toggleEffect(effectId: string, method: StateParams['method']) {\n if (isLegacyStateSyntax) {\n effectId = `--${effectId}`;\n }\n\n if (this._internals) {\n if (method === 'toggle') {\n this._internals.states.has(effectId)\n ? this._internals.states.delete(effectId)\n : this._internals.states.add(effectId);\n } else if (method === 'add') {\n this._internals.states.add(effectId);\n } else if (method === 'remove') {\n this._internals.states.delete(effectId);\n } else if (method === 'clear') {\n this._internals.states.clear();\n }\n } else {\n const currentEffects = new Set(\n this.dataset[WIX_INTERACT_EFFECT_DATA_ATTR]?.split(' ') || [],\n );\n\n if (method === 'toggle') {\n currentEffects.has(effectId)\n ? currentEffects.delete(effectId)\n : currentEffects.add(effectId);\n } else if (method === 'add') {\n currentEffects.add(effectId);\n } else if (method === 'remove') {\n currentEffects.delete(effectId);\n } else if (method === 'clear') {\n currentEffects.clear();\n }\n\n this.dataset[WIX_INTERACT_EFFECT_DATA_ATTR] =\n Array.from(currentEffects).join(' ');\n }\n }\n\n watchChildList(listContainer: string): void {\n const list = this.querySelector(listContainer);\n\n if (list) {\n // TODO: we can probably improve this and use less observers, this impl. uses one per container element\n let observer = this._observers.get(list as HTMLElement);\n\n if (!observer) {\n observer = new MutationObserver(\n this._childListChangeHandler.bind(this, listContainer),\n );\n\n this._observers.set(list as HTMLElement, observer);\n\n observer.observe(list as HTMLElement, { childList: true });\n }\n }\n }\n\n _childListChangeHandler(listContainer: string, entries: MutationRecord[]) {\n const key = this.dataset.wixPath;\n const removedElements: HTMLElement[] = [];\n const addedElements: HTMLElement[] = [];\n\n entries.forEach((entry) => {\n entry.removedNodes.forEach((el) => {\n if (el instanceof HTMLElement) {\n removedElements.push(el);\n }\n });\n\n entry.addedNodes.forEach((el) => {\n if (el instanceof HTMLElement) {\n addedElements.push(el);\n }\n });\n });\n\n removeListItems(removedElements);\n key && addListItems(this, key, listContainer, addedElements);\n }\n };\n}\n"],"mappings":";;;;;;;AACA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAEO,MAAME,6BAA6B,GAAAC,OAAA,CAAAD,6BAAA,GAAG,mBAAmB;AAEzD,SAASE,qBAAqBA,CAAA,EAAG;EACtC,IAAIC,2BAA2B,GAAG,KAAK;EACvC,IAAIC,mBAAmB,GAAG,KAAK;EAE/B,OAAO,MAAMC,kBAAkB,SAASC,WAAW,CAAC;IAMlDC,WAAWA,CAAA,EAAG;MACZ,KAAK,CAAC,CAAC;MAAC,IAAAC,gBAAA,CAAAC,OAAA;MAAA,IAAAD,gBAAA,CAAAC,OAAA;MAAA,IAAAD,gBAAA,CAAAC,OAAA;MAAA,IAAAD,gBAAA,CAAAC,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AAAsD,iBAAY,EAAC,IAAI,EAAEtD,GAAG,EAAEkC,aAAa,EAAEa,aAAa,CAAC;IAC9D;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -391,23 +391,8 @@ describe('interact', () => {
|
|
|
391
391
|
}
|
|
392
392
|
afterEach(() => {
|
|
393
393
|
jest.clearAllMocks();
|
|
394
|
-
(0, _remove.remove)('logo-entrance');
|
|
395
|
-
(0, _remove.remove)('logo-loop');
|
|
396
|
-
(0, _remove.remove)('logo-animation-end');
|
|
397
|
-
(0, _remove.remove)('logo-mouse');
|
|
398
|
-
(0, _remove.remove)('logo-click');
|
|
399
|
-
(0, _remove.remove)('logo-hover');
|
|
400
|
-
(0, _remove.remove)('logo-scroll');
|
|
401
|
-
// Clean up cascading test elements
|
|
402
|
-
(0, _remove.remove)('cascade-source');
|
|
403
|
-
(0, _remove.remove)('cascade-target');
|
|
404
|
-
(0, _remove.remove)('cascade-target-1');
|
|
405
|
-
(0, _remove.remove)('cascade-target-2');
|
|
406
|
-
(0, _remove.remove)('multi-source-1');
|
|
407
|
-
(0, _remove.remove)('multi-source-2');
|
|
408
394
|
// Clear Interact instances to ensure test isolation
|
|
409
|
-
_Interact.Interact.
|
|
410
|
-
_Interact.Interact.elementCache.clear();
|
|
395
|
+
_Interact.Interact.destroy();
|
|
411
396
|
// Reset forceReducedMotion to default
|
|
412
397
|
_Interact.Interact.forceReducedMotion = false;
|
|
413
398
|
});
|
|
@@ -417,6 +402,86 @@ describe('interact', () => {
|
|
|
417
402
|
expect(customElements.get('wix-interact-element')).toBeDefined();
|
|
418
403
|
});
|
|
419
404
|
});
|
|
405
|
+
describe('destroy Interact', () => {
|
|
406
|
+
it('should clear all instances', () => {
|
|
407
|
+
_Interact.Interact.create(mockConfig);
|
|
408
|
+
_Interact.Interact.create(mockConfig);
|
|
409
|
+
expect(_Interact.Interact.instances.length).toBe(2);
|
|
410
|
+
_Interact.Interact.destroy();
|
|
411
|
+
expect(_Interact.Interact.instances.length).toBe(0);
|
|
412
|
+
});
|
|
413
|
+
it('should clear all elements from cache', () => {
|
|
414
|
+
_Interact.Interact.create(mockConfig);
|
|
415
|
+
element = document.createElement('wix-interact-element');
|
|
416
|
+
const div = document.createElement('div');
|
|
417
|
+
element.append(div);
|
|
418
|
+
(0, _add.add)(element, 'logo-hover');
|
|
419
|
+
expect(_Interact.Interact.elementCache.size).toBeGreaterThan(0);
|
|
420
|
+
_Interact.Interact.destroy();
|
|
421
|
+
expect(_Interact.Interact.elementCache.size).toBe(0);
|
|
422
|
+
});
|
|
423
|
+
it('should call disconnect on all cached elements', () => {
|
|
424
|
+
_Interact.Interact.create(mockConfig);
|
|
425
|
+
const element1 = document.createElement('wix-interact-element');
|
|
426
|
+
const div1 = document.createElement('div');
|
|
427
|
+
element1.append(div1);
|
|
428
|
+
const element2 = document.createElement('wix-interact-element');
|
|
429
|
+
const div2 = document.createElement('div');
|
|
430
|
+
element2.append(div2);
|
|
431
|
+
(0, _add.add)(element1, 'logo-hover');
|
|
432
|
+
(0, _add.add)(element2, 'logo-click');
|
|
433
|
+
const disconnectSpy1 = jest.spyOn(element1, 'disconnect');
|
|
434
|
+
const disconnectSpy2 = jest.spyOn(element2, 'disconnect');
|
|
435
|
+
_Interact.Interact.destroy();
|
|
436
|
+
expect(disconnectSpy1).toHaveBeenCalled();
|
|
437
|
+
expect(disconnectSpy2).toHaveBeenCalled();
|
|
438
|
+
});
|
|
439
|
+
it('should clean up interactions after destroy', () => {
|
|
440
|
+
_Interact.Interact.create(mockConfig);
|
|
441
|
+
element = document.createElement('wix-interact-element');
|
|
442
|
+
const div = document.createElement('div');
|
|
443
|
+
element.append(div);
|
|
444
|
+
(0, _add.add)(element, 'logo-click');
|
|
445
|
+
_Interact.Interact.destroy();
|
|
446
|
+
|
|
447
|
+
// After destroy, getInstance should return undefined
|
|
448
|
+
expect(_Interact.Interact.getInstance('logo-click')).toBeUndefined();
|
|
449
|
+
|
|
450
|
+
// Re-create instance and verify it works independently
|
|
451
|
+
_Interact.Interact.create(mockConfig);
|
|
452
|
+
const newElement = document.createElement('wix-interact-element');
|
|
453
|
+
const newDiv = document.createElement('div');
|
|
454
|
+
newElement.append(newDiv);
|
|
455
|
+
const newAddEventListenerSpy = jest.spyOn(newDiv, 'addEventListener');
|
|
456
|
+
(0, _add.add)(newElement, 'logo-click');
|
|
457
|
+
expect(newAddEventListenerSpy).toHaveBeenCalled();
|
|
458
|
+
expect(_Interact.Interact.getInstance('logo-click')).toBeDefined();
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
// TODO: fix this test - when adding this test it causes 2 other tests to fail
|
|
462
|
+
// it('should remove event listeners and styles when disconnect is called', () => {
|
|
463
|
+
// Interact.create(mockConfig);
|
|
464
|
+
|
|
465
|
+
// element = document.createElement(
|
|
466
|
+
// 'wix-interact-element',
|
|
467
|
+
// ) as IWixInteractElement;
|
|
468
|
+
// element.dataset.wixPath = 'logo-click';
|
|
469
|
+
// const div = document.createElement('div');
|
|
470
|
+
// element.append(div);
|
|
471
|
+
|
|
472
|
+
// add(element, 'logo-click');
|
|
473
|
+
|
|
474
|
+
// const removeEventListenerSpy = jest.spyOn(div, 'removeEventListener');
|
|
475
|
+
|
|
476
|
+
// Interact.destroy();
|
|
477
|
+
|
|
478
|
+
// expect(removeEventListenerSpy).toHaveBeenCalled();
|
|
479
|
+
// expect(removeEventListenerSpy).toHaveBeenCalledWith(
|
|
480
|
+
// 'click',
|
|
481
|
+
// expect.any(Function),
|
|
482
|
+
// );
|
|
483
|
+
// });
|
|
484
|
+
});
|
|
420
485
|
describe('reduced motion', () => {
|
|
421
486
|
it('should pass reducedMotion=true to getWebAnimation when forceReducedMotion is true', () => {
|
|
422
487
|
const {
|
|
@@ -458,6 +523,10 @@ describe('interact', () => {
|
|
|
458
523
|
beforeEach(() => {
|
|
459
524
|
_Interact.Interact.create(mockConfig);
|
|
460
525
|
});
|
|
526
|
+
afterEach(() => {
|
|
527
|
+
_Interact.Interact.destroy();
|
|
528
|
+
jest.clearAllMocks();
|
|
529
|
+
});
|
|
461
530
|
describe('hover', () => {
|
|
462
531
|
it('should add handler for hover trigger with alternate type', () => {
|
|
463
532
|
const {
|
|
@@ -520,11 +589,11 @@ describe('interact', () => {
|
|
|
520
589
|
} = require('@wix/motion');
|
|
521
590
|
element = document.createElement('wix-interact-element');
|
|
522
591
|
const div = document.createElement('div');
|
|
523
|
-
|
|
592
|
+
element.dataset.wixPath = 'logo-entrance';
|
|
524
593
|
element.append(div);
|
|
525
594
|
const elementClick = document.createElement('wix-interact-element');
|
|
526
595
|
const divClick = document.createElement('div');
|
|
527
|
-
|
|
596
|
+
elementClick.dataset.wixPath = 'logo-click';
|
|
528
597
|
elementClick.append(divClick);
|
|
529
598
|
(0, _add.add)(elementClick, 'logo-click');
|
|
530
599
|
(0, _add.add)(element, 'logo-entrance');
|