@lvce-editor/virtual-dom 8.13.0 → 9.1.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/dist/index.js +16 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -455,6 +455,7 @@ const getWrappedListener = (listener, returnValue) => {
455
455
  return get(listener);
456
456
  };
457
457
 
458
+ const attachedListeners = new WeakMap();
458
459
  const getOptions = fn => {
459
460
  if (fn.passive) {
460
461
  return {
@@ -470,11 +471,21 @@ const getOptions = fn => {
470
471
  };
471
472
  const attachEvent = ($Node, eventMap, key, value, newEventMap) => {
472
473
  const keyLower = key.toLowerCase();
474
+ const listenersByEvent = attachedListeners.get($Node) || new Map();
475
+ const previous = listenersByEvent.get(keyLower);
476
+ if (previous) {
477
+ $Node.removeEventListener(keyLower, previous.listener, previous.options);
478
+ }
473
479
  if (newEventMap && newEventMap[value]) {
474
480
  const fn = newEventMap[value];
475
481
  const options = getOptions(fn);
476
482
  // TODO support event listener options
477
483
  $Node.addEventListener(keyLower, newEventMap[value], options);
484
+ listenersByEvent.set(keyLower, {
485
+ listener: newEventMap[value],
486
+ options
487
+ });
488
+ attachedListeners.set($Node, listenersByEvent);
478
489
  return;
479
490
  }
480
491
  const listener = eventMap[value];
@@ -485,6 +496,11 @@ const attachEvent = ($Node, eventMap, key, value, newEventMap) => {
485
496
  const options = getEventListenerOptions(key, value);
486
497
  const wrapped = getWrappedListener(listener, eventMap.returnValue);
487
498
  $Node.addEventListener(keyLower, wrapped, options);
499
+ listenersByEvent.set(keyLower, {
500
+ listener: wrapped,
501
+ options
502
+ });
503
+ attachedListeners.set($Node, listenersByEvent);
488
504
  };
489
505
 
490
506
  const STYLE_REGEX = /([^:;]+):\s*([^;]+)/g;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/virtual-dom",
3
- "version": "8.13.0",
3
+ "version": "9.1.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lvce-editor/virtual-dom.git"