From 54b491d95c33b2c6d32c88b6e82b5424ffbf2e37 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 18 Jan 2022 17:37:44 +0800 Subject: [PATCH] wip(app): nvue --- .../uni-app-vue/dist/nvue.runtime.esm.dev.js | 157 +++++++++++++++++- .../uni-app-vue/dist/nvue.runtime.esm.prod.js | 157 +++++++++++++++++- packages/uni-app-vue/lib/nvue.runtime.esm.js | 138 ++++++++++++++- 3 files changed, 435 insertions(+), 17 deletions(-) diff --git a/packages/uni-app-vue/dist/nvue.runtime.esm.dev.js b/packages/uni-app-vue/dist/nvue.runtime.esm.dev.js index 2ece6d903..1219d6c2b 100644 --- a/packages/uni-app-vue/dist/nvue.runtime.esm.dev.js +++ b/packages/uni-app-vue/dist/nvue.runtime.esm.dev.js @@ -10978,12 +10978,161 @@ export function nvueFactory(exports, document) { nextSibling: node => node.nextSibling }; + function patchAttr(el, key, value) { + if (value == null) ;else { + el.setAttr(key, value); + } + } + + function addEventListener(el, event, handler, options) { + el.addEvent(event, handler); + } + + function removeEventListener(el, event) { + el.removeEvent(event); + } + + function patchEvent(el, rawName, prevValue, nextValue) { + var instance = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; + // vei = vue event invokers + var invokers = el._vei || (el._vei = {}); + var existingInvoker = invokers[rawName]; + + if (nextValue && existingInvoker) { + // patch + existingInvoker.value = nextValue; + } else { + var [name, options] = parseName(rawName); + + if (nextValue) { + // add + var invoker = invokers[rawName] = createInvoker(nextValue, instance); + addEventListener(el, name, invoker); + } else if (existingInvoker) { + // remove + removeEventListener(el, name); + invokers[rawName] = undefined; + } + } + } + + var optionsModifierRE = /(?:Once|Passive|Capture)$/; + + function parseName(name) { + var options; + + if (optionsModifierRE.test(name)) { + options = {}; + var m; + + while (m = name.match(optionsModifierRE)) { + name = name.slice(0, name.length - m[0].length); + options[m[0].toLowerCase()] = true; + } + } + + return [hyphenate(name.slice(2)), options]; + } + + function createInvoker(initialValue, instance) { + var invoker = e => { + callWithAsyncErrorHandling(invoker.value, instance, 5 + /* NATIVE_EVENT_HANDLER */ + , [e]); + }; + + invoker.value = initialValue; + var modifiers = new Set(); // 合并 modifiers + + if (isArray(invoker.value)) { + invoker.value.forEach(v => { + if (v.modifiers) { + v.modifiers.forEach(m => { + modifiers.add(m); + }); + } + }); + } else { + if (invoker.value.modifiers) { + invoker.value.modifiers.forEach(m => { + modifiers.add(m); + }); + } + + initWxsEvent(invoker, instance); + } + + invoker.modifiers = [...modifiers]; + return invoker; + } + + function initWxsEvent(invoker, instance) { + if (!instance) { + return; + } + + var { + $wxsModules + } = instance; + + if (!$wxsModules) { + return; + } + + var invokerSourceCode = invoker.value.toString(); + + if (!$wxsModules.find(module => invokerSourceCode.indexOf('.' + module + '.') > -1)) { + return; + } + + invoker.wxsEvent = invoker.value(); + } + + function patchStyle(el, prev, next) { + if (!next) ;else if (isString(next)) ;else { + var batchedStyles = {}; + var isPrevObj = prev && !isString(prev); + + if (isPrevObj) { + for (var key in prev) { + if (next[key] == null) { + batchedStyles[key] = ''; + } + } + + for (var _key21 in next) { + var value = next[_key21]; + + if (value !== prev[_key21]) { + batchedStyles[_key21] = value; + } + } + } else { + for (var _key22 in next) { + batchedStyles[_key22] = next[_key22]; + } + } + + el.setStyles(batchedStyles); + } + } + var patchProp = function (el, key, prevValue, nextValue) { var isSVG = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; var prevChildren = arguments.length > 5 ? arguments[5] : undefined; var parentComponent = arguments.length > 6 ? arguments[6] : undefined; var parentSuspense = arguments.length > 7 ? arguments[7] : undefined; var unmountChildren = arguments.length > 8 ? arguments[8] : undefined; + if (key === 'class') ;else if (key === 'style') { + patchStyle(el, prevValue, nextValue); + } else if (isOn(key)) { + // ignore v-model listeners + if (!isModelListener(key)) { + patchEvent(el, key, prevValue, nextValue, parentComponent); + } + } else { + patchAttr(el, key, nextValue); + } }; function useCssModule() { @@ -11070,10 +11219,6 @@ export function nvueFactory(exports, document) { } } - function addEventListener(el, event, handler, options) { - el.addEventListener(event, handler, options); - } - var getModelAssigner = vnode => { var fn = vnode.props['onUpdate:modelValue']; return isArray(fn) ? value => invokeArrayFns(fn, value) : fn; @@ -11149,8 +11294,8 @@ export function nvueFactory(exports, document) { if (guard && guard(event, modifiers)) return; } - for (var _len12 = arguments.length, args = new Array(_len12 > 1 ? _len12 - 1 : 0), _key21 = 1; _key21 < _len12; _key21++) { - args[_key21 - 1] = arguments[_key21]; + for (var _len12 = arguments.length, args = new Array(_len12 > 1 ? _len12 - 1 : 0), _key23 = 1; _key23 < _len12; _key23++) { + args[_key23 - 1] = arguments[_key23]; } return fn(event, ...args); diff --git a/packages/uni-app-vue/dist/nvue.runtime.esm.prod.js b/packages/uni-app-vue/dist/nvue.runtime.esm.prod.js index 992ed2b47..89cf77139 100644 --- a/packages/uni-app-vue/dist/nvue.runtime.esm.prod.js +++ b/packages/uni-app-vue/dist/nvue.runtime.esm.prod.js @@ -9151,12 +9151,161 @@ export function nvueFactory(exports, document) { nextSibling: node => node.nextSibling }; + function patchAttr(el, key, value) { + if (value == null) ;else { + el.setAttr(key, value); + } + } + + function addEventListener(el, event, handler, options) { + el.addEvent(event, handler); + } + + function removeEventListener(el, event) { + el.removeEvent(event); + } + + function patchEvent(el, rawName, prevValue, nextValue) { + var instance = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; + // vei = vue event invokers + var invokers = el._vei || (el._vei = {}); + var existingInvoker = invokers[rawName]; + + if (nextValue && existingInvoker) { + // patch + existingInvoker.value = nextValue; + } else { + var [name, options] = parseName(rawName); + + if (nextValue) { + // add + var invoker = invokers[rawName] = createInvoker(nextValue, instance); + addEventListener(el, name, invoker); + } else if (existingInvoker) { + // remove + removeEventListener(el, name); + invokers[rawName] = undefined; + } + } + } + + var optionsModifierRE = /(?:Once|Passive|Capture)$/; + + function parseName(name) { + var options; + + if (optionsModifierRE.test(name)) { + options = {}; + var m; + + while (m = name.match(optionsModifierRE)) { + name = name.slice(0, name.length - m[0].length); + options[m[0].toLowerCase()] = true; + } + } + + return [hyphenate(name.slice(2)), options]; + } + + function createInvoker(initialValue, instance) { + var invoker = e => { + callWithAsyncErrorHandling(invoker.value, instance, 5 + /* NATIVE_EVENT_HANDLER */ + , [e]); + }; + + invoker.value = initialValue; + var modifiers = new Set(); // 合并 modifiers + + if (isArray(invoker.value)) { + invoker.value.forEach(v => { + if (v.modifiers) { + v.modifiers.forEach(m => { + modifiers.add(m); + }); + } + }); + } else { + if (invoker.value.modifiers) { + invoker.value.modifiers.forEach(m => { + modifiers.add(m); + }); + } + + initWxsEvent(invoker, instance); + } + + invoker.modifiers = [...modifiers]; + return invoker; + } + + function initWxsEvent(invoker, instance) { + if (!instance) { + return; + } + + var { + $wxsModules + } = instance; + + if (!$wxsModules) { + return; + } + + var invokerSourceCode = invoker.value.toString(); + + if (!$wxsModules.find(module => invokerSourceCode.indexOf('.' + module + '.') > -1)) { + return; + } + + invoker.wxsEvent = invoker.value(); + } + + function patchStyle(el, prev, next) { + if (!next) ;else if (isString(next)) ;else { + var batchedStyles = {}; + var isPrevObj = prev && !isString(prev); + + if (isPrevObj) { + for (var key in prev) { + if (next[key] == null) { + batchedStyles[key] = ''; + } + } + + for (var _key14 in next) { + var value = next[_key14]; + + if (value !== prev[_key14]) { + batchedStyles[_key14] = value; + } + } + } else { + for (var _key15 in next) { + batchedStyles[_key15] = next[_key15]; + } + } + + el.setStyles(batchedStyles); + } + } + var patchProp = function (el, key, prevValue, nextValue) { var isSVG = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; var prevChildren = arguments.length > 5 ? arguments[5] : undefined; var parentComponent = arguments.length > 6 ? arguments[6] : undefined; var parentSuspense = arguments.length > 7 ? arguments[7] : undefined; var unmountChildren = arguments.length > 8 ? arguments[8] : undefined; + if (key === 'class') ;else if (key === 'style') { + patchStyle(el, prevValue, nextValue); + } else if (isOn(key)) { + // ignore v-model listeners + if (!isModelListener(key)) { + patchEvent(el, key, prevValue, nextValue, parentComponent); + } + } else { + patchAttr(el, key, nextValue); + } }; function useCssModule() { @@ -9239,10 +9388,6 @@ export function nvueFactory(exports, document) { } } - function addEventListener(el, event, handler, options) { - el.addEventListener(event, handler, options); - } - var getModelAssigner = vnode => { var fn = vnode.props['onUpdate:modelValue']; return isArray(fn) ? value => invokeArrayFns(fn, value) : fn; @@ -9318,8 +9463,8 @@ export function nvueFactory(exports, document) { if (guard && guard(event, modifiers)) return; } - for (var _len7 = arguments.length, args = new Array(_len7 > 1 ? _len7 - 1 : 0), _key14 = 1; _key14 < _len7; _key14++) { - args[_key14 - 1] = arguments[_key14]; + for (var _len7 = arguments.length, args = new Array(_len7 > 1 ? _len7 - 1 : 0), _key16 = 1; _key16 < _len7; _key16++) { + args[_key16 - 1] = arguments[_key16]; } return fn(event, ...args); diff --git a/packages/uni-app-vue/lib/nvue.runtime.esm.js b/packages/uni-app-vue/lib/nvue.runtime.esm.js index b5718220d..641a503da 100644 --- a/packages/uni-app-vue/lib/nvue.runtime.esm.js +++ b/packages/uni-app-vue/lib/nvue.runtime.esm.js @@ -8869,7 +8869,139 @@ const nodeOps = { nextSibling: node => node.nextSibling }; -const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => { }; +function patchAttr(el, key, value) { + if (value == null) ; + else { + el.setAttr(key, value); + } +} + +function addEventListener(el, event, handler, options) { + el.addEvent(event, handler); +} +function removeEventListener(el, event) { + el.removeEvent(event); +} +function patchEvent(el, rawName, prevValue, nextValue, instance = null) { + // vei = vue event invokers + const invokers = el._vei || (el._vei = {}); + const existingInvoker = invokers[rawName]; + if (nextValue && existingInvoker) { + // patch + existingInvoker.value = nextValue; + } + else { + const [name, options] = parseName(rawName); + if (nextValue) { + // add + const invoker = (invokers[rawName] = createInvoker(nextValue, instance)); + addEventListener(el, name, invoker); + } + else if (existingInvoker) { + // remove + removeEventListener(el, name); + invokers[rawName] = undefined; + } + } +} +const optionsModifierRE = /(?:Once|Passive|Capture)$/; +function parseName(name) { + let options; + if (optionsModifierRE.test(name)) { + options = {}; + let m; + while ((m = name.match(optionsModifierRE))) { + name = name.slice(0, name.length - m[0].length); + options[m[0].toLowerCase()] = true; + } + } + return [hyphenate(name.slice(2)), options]; +} +function createInvoker(initialValue, instance) { + const invoker = (e) => { + callWithAsyncErrorHandling(invoker.value, instance, 5 /* NATIVE_EVENT_HANDLER */, [e]); + }; + invoker.value = initialValue; + const modifiers = new Set(); + // 合并 modifiers + if (isArray(invoker.value)) { + invoker.value.forEach(v => { + if (v.modifiers) { + v.modifiers.forEach((m) => { + modifiers.add(m); + }); + } + }); + } + else { + if (invoker.value.modifiers) { + invoker.value.modifiers.forEach((m) => { + modifiers.add(m); + }); + } + initWxsEvent(invoker, instance); + } + invoker.modifiers = [...modifiers]; + return invoker; +} +function initWxsEvent(invoker, instance) { + if (!instance) { + return; + } + const { $wxsModules } = instance; + if (!$wxsModules) { + return; + } + const invokerSourceCode = invoker.value.toString(); + if (!$wxsModules.find(module => invokerSourceCode.indexOf('.' + module + '.') > -1)) { + return; + } + invoker.wxsEvent = invoker.value(); +} + +function patchStyle(el, prev, next) { + if (!next) ; + else if (isString(next)) ; + else { + const batchedStyles = {}; + const isPrevObj = prev && !isString(prev); + if (isPrevObj) { + for (const key in prev) { + if (next[key] == null) { + batchedStyles[key] = ''; + } + } + for (const key in next) { + const value = next[key]; + if (value !== prev[key]) { + batchedStyles[key] = value; + } + } + } + else { + for (const key in next) { + batchedStyles[key] = next[key]; + } + } + el.setStyles(batchedStyles); + } +} + +const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => { + if (key === 'class') ; + else if (key === 'style') { + patchStyle(el, prevValue, nextValue); + } + else if (isOn(key)) { + // ignore v-model listeners + if (!isModelListener(key)) { + patchEvent(el, key, prevValue, nextValue, parentComponent); + } + } + else { + patchAttr(el, key, nextValue); + } +}; function useCssModule(name = '$style') { /* istanbul ignore else */ @@ -8935,10 +9067,6 @@ function setVarsOnVNode(vnode, vars) { } } -function addEventListener(el, event, handler, options) { - el.addEventListener(event, handler, options); -} - const getModelAssigner = (vnode) => { const fn = vnode.props['onUpdate:modelValue']; return isArray(fn) ? value => invokeArrayFns(fn, value) : fn; -- GitLab