This commit is contained in:
2022-07-21 03:28:35 +00:00
parent d7c883d6df
commit 51b34b0e1d
30103 changed files with 4152204 additions and 23 deletions
+67
View File
@@ -0,0 +1,67 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.Mutate = void 0;
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function inserted(el, binding) {
var modifiers = binding.modifiers || {};
var value = binding.value;
var callback = _typeof(value) === 'object' ? value.handler : value;
var once = modifiers.once,
modifierKeys = _objectWithoutProperties(modifiers, ["once"]);
var hasModifiers = Object.keys(modifierKeys).length > 0; // Options take top priority
var options = _typeof(value) === 'object' && value.options ? value.options : hasModifiers // If we have modifiers, use only those provided
? {
attributes: modifierKeys.attr,
childList: modifierKeys.child,
subtree: modifierKeys.sub,
characterData: modifierKeys.char // Defaults to everything on
} : {
attributes: true,
childList: true,
subtree: true,
characterData: true
};
var observer = new MutationObserver(function (mutationsList, observer) {
/* istanbul ignore if */
if (!el._mutate) return; // Just in case, should never fire
callback(mutationsList, observer); // If has the once modifier, unbind
once && unbind(el);
});
observer.observe(el, options);
el._mutate = {
observer: observer
};
}
function unbind(el) {
/* istanbul ignore if */
if (!el._mutate) return;
el._mutate.observer.disconnect();
delete el._mutate;
}
var Mutate = {
inserted: inserted,
unbind: unbind
};
exports.Mutate = Mutate;
var _default = Mutate;
exports.default = _default;
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/directives/mutate/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAkBA,SAAS,QAAT,CAAmB,EAAnB,EAAoC,OAApC,EAAiE;AAC/D,MAAM,SAAS,GAAG,OAAO,CAAC,SAAR,IAAqB,EAAvC;AACA,MAAM,KAAK,GAAG,OAAO,CAAC,KAAtB;AACA,MAAM,QAAQ,GAAG,QAAO,KAAP,MAAiB,QAAjB,GAA4B,KAAK,CAAC,OAAlC,GAA4C,KAA7D;;AAH+D,MAIvD,IAJuD,GAI7B,SAJ6B,CAIvD,IAJuD;AAAA,MAI9C,YAJ8C,4BAI7B,SAJ6B;;AAK/D,MAAM,YAAY,GAAG,MAAM,CAAC,IAAP,CAAY,YAAZ,EAA0B,MAA1B,GAAmC,CAAxD,CAL+D,CAO/D;;AACA,MAAM,OAAO,GAAG,QAAO,KAAP,MAAiB,QAAjB,IAA6B,KAAK,CAAC,OAAnC,GACZ,KAAK,CAAC,OADM,GAEZ,YAAY,CACZ;AADY,IAEV;AACA,IAAA,UAAU,EAAE,YAAY,CAAC,IADzB;AAEA,IAAA,SAAS,EAAE,YAAY,CAAC,KAFxB;AAGA,IAAA,OAAO,EAAE,YAAY,CAAC,GAHtB;AAIA,IAAA,aAAa,EAAE,YAAY,CAAC,IAJ5B,CAMF;;AANE,GAFU,GASV;AACA,IAAA,UAAU,EAAE,IADZ;AAEA,IAAA,SAAS,EAAE,IAFX;AAGA,IAAA,OAAO,EAAE,IAHT;AAIA,IAAA,aAAa,EAAE;AAJf,GAXN;AAkBA,MAAM,QAAQ,GAAG,IAAI,gBAAJ,CAAqB,UACpC,aADoC,EAEpC,QAFoC,EAGlC;AACF;AACA,QAAI,CAAC,EAAE,CAAC,OAAR,EAAiB,OAFf,CAEsB;;AAExB,IAAA,QAAQ,CAAC,aAAD,EAAgB,QAAhB,CAAR,CAJE,CAMF;;AACA,IAAA,IAAI,IAAI,MAAM,CAAC,EAAD,CAAd;AACD,GAXgB,CAAjB;AAaA,EAAA,QAAQ,CAAC,OAAT,CAAiB,EAAjB,EAAqB,OAArB;AACA,EAAA,EAAE,CAAC,OAAH,GAAa;AAAE,IAAA,QAAQ,EAAR;AAAF,GAAb;AACD;;AAED,SAAS,MAAT,CAAiB,EAAjB,EAAgC;AAC9B;AACA,MAAI,CAAC,EAAE,CAAC,OAAR,EAAiB;;AAEjB,EAAA,EAAE,CAAC,OAAH,CAAW,QAAX,CAAoB,UAApB;;AACA,SAAO,EAAE,CAAC,OAAV;AACD;;AAEM,IAAM,MAAM,GAAG;AACpB,EAAA,QAAQ,EAAR,QADoB;AAEpB,EAAA,MAAM,EAAN;AAFoB,CAAf;;eAKQ,M","sourcesContent":["import { VNodeDirective } from 'vue'\n\ntype MutateHandler = (\n mutationsList: MutationRecord[],\n observer: MutationObserver,\n) => void\n\ninterface MutateVNodeDirective extends Omit<VNodeDirective, 'modifiers'> {\n value?: MutateHandler | { handler: MutateHandler, options?: MutationObserverInit }\n modifiers?: {\n once?: boolean\n attr?: boolean\n child?: boolean\n sub?: boolean\n char?: boolean\n }\n}\n\nfunction inserted (el: HTMLElement, binding: MutateVNodeDirective) {\n const modifiers = binding.modifiers || {}\n const value = binding.value\n const callback = typeof value === 'object' ? value.handler : value!\n const { once, ...modifierKeys } = modifiers\n const hasModifiers = Object.keys(modifierKeys).length > 0\n\n // Options take top priority\n const options = typeof value === 'object' && value.options\n ? value.options\n : hasModifiers\n // If we have modifiers, use only those provided\n ? {\n attributes: modifierKeys.attr,\n childList: modifierKeys.child,\n subtree: modifierKeys.sub,\n characterData: modifierKeys.char,\n }\n // Defaults to everything on\n : {\n attributes: true,\n childList: true,\n subtree: true,\n characterData: true,\n }\n\n const observer = new MutationObserver((\n mutationsList: MutationRecord[],\n observer: MutationObserver\n ) => {\n /* istanbul ignore if */\n if (!el._mutate) return // Just in case, should never fire\n\n callback(mutationsList, observer)\n\n // If has the once modifier, unbind\n once && unbind(el)\n })\n\n observer.observe(el, options)\n el._mutate = { observer }\n}\n\nfunction unbind (el: HTMLElement) {\n /* istanbul ignore if */\n if (!el._mutate) return\n\n el._mutate.observer.disconnect()\n delete el._mutate\n}\n\nexport const Mutate = {\n inserted,\n unbind,\n}\n\nexport default Mutate\n"],"sourceRoot":"","file":"index.js"}