提交 86f6afb8 编写于 作者: fxy060608's avatar fxy060608

fix(h5): initCustomDataset (question/139181)

上级 e351f355
......@@ -212,6 +212,67 @@ var serviceContext = (function (vue) {
.join(' ')}`;
}
function cache(fn) {
const cache = Object.create(null);
return (str) => {
const hit = cache[str];
return hit || (cache[str] = fn(str));
};
}
function cacheStringFunction(fn) {
return cache(fn);
}
function getLen(str = '') {
return ('' + str).replace(/[^\x00-\xff]/g, '**').length;
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
function removeLeadingSlash(str) {
return hasLeadingSlash(str) ? str.substr(1) : str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
function once(fn, ctx = null) {
let res;
return ((...args) => {
if (fn) {
res = fn.apply(ctx, args);
fn = null;
}
return res;
});
}
function callOptions(options, data) {
options = options || {};
if (typeof data === 'string') {
data = {
errMsg: data,
};
}
if (/:ok$/.test(data.errMsg)) {
if (typeof options.success === 'function') {
options.success(data);
}
}
else {
if (typeof options.fail === 'function') {
options.fail(data);
}
}
if (typeof options.complete === 'function') {
options.complete(data);
}
}
const encode$2 = encodeURIComponent;
function stringifyQuery$1(obj, encodeStr = encode$2) {
const res = obj
......@@ -533,67 +594,6 @@ var serviceContext = (function (vue) {
const ACTION_TYPE_PAGE_SCROLL = 15;
const ACTION_TYPE_EVENT = 20;
function cache(fn) {
const cache = Object.create(null);
return (str) => {
const hit = cache[str];
return hit || (cache[str] = fn(str));
};
}
function cacheStringFunction(fn) {
return cache(fn);
}
function getLen(str = '') {
return ('' + str).replace(/[^\x00-\xff]/g, '**').length;
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
function removeLeadingSlash(str) {
return hasLeadingSlash(str) ? str.substr(1) : str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
function once(fn, ctx = null) {
let res;
return ((...args) => {
if (fn) {
res = fn.apply(ctx, args);
fn = null;
}
return res;
});
}
function callOptions(options, data) {
options = options || {};
if (typeof data === 'string') {
data = {
errMsg: data,
};
}
if (/:ok$/.test(data.errMsg)) {
if (typeof options.success === 'function') {
options.success(data);
}
}
else {
if (typeof options.fail === 'function') {
options.fail(data);
}
}
if (typeof options.complete === 'function') {
options.complete(data);
}
}
function debounce(fn, delay) {
let timeout;
const newFn = function () {
......
import { initCustomDataset } from '@dcloudio/uni-shared'
import { initCustomDatasetOnce } from '@dcloudio/uni-shared'
import { initLongPress } from './longPress'
import { useRem } from './rem'
......@@ -7,7 +7,7 @@ export function initView() {
return
}
useRem()
initCustomDataset()
initCustomDatasetOnce()
if (__UNI_FEATURE_LONGPRESS__) {
initLongPress()
}
......
import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, openBlock, createElementBlock, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, injectHook, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, Comment, createTextVNode, onBeforeActivate, onBeforeDeactivate, createBlock, renderList, onDeactivated, createApp, Transition, effectScope, withCtx, KeepAlive, resolveDynamicComponent, createElementVNode, normalizeStyle, renderSlot } from "vue";
import { isString, extend, stringifyStyle, parseStringStyle, isPlainObject, isFunction, capitalize, camelize, isArray, hasOwn, isObject, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { once, UNI_STORAGE_LOCALE, I18N_JSON_DELIMITERS, Emitter, passive, initCustomDataset, resolveComponentInstance, addLeadingSlash, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, ON_LAUNCH, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, ON_LOAD, UniLifecycleHooks, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
import { once, UNI_STORAGE_LOCALE, I18N_JSON_DELIMITERS, Emitter, passive, initCustomDatasetOnce, resolveComponentInstance, addLeadingSlash, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, ON_LAUNCH, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, ON_LOAD, UniLifecycleHooks, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, formatDateTime, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
import { initVueI18n, isI18nStr, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n";
import { useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView } from "vue-router";
const isEnableLocale = /* @__PURE__ */ once(() => typeof __uniConfig !== "undefined" && __uniConfig.locales && !!Object.keys(__uniConfig.locales).length);
......@@ -498,7 +498,7 @@ function useRem() {
}
function initView() {
useRem();
initCustomDataset();
initCustomDatasetOnce();
if (__UNI_FEATURE_LONGPRESS__) {
initLongPress();
}
......
......@@ -30,6 +30,20 @@ function customizeEvent(str) {
return camelize(str.replace(customizeRE, '-'));
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
const res = obj
......@@ -50,20 +64,6 @@ function stringifyQuery(obj, encodeStr = encode) {
return res ? `?${res}` : '';
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
class EventChannel {
constructor(id, events) {
this.id = id;
......
......@@ -98,6 +98,20 @@ function customizeEvent(str) {
return camelize(str.replace(customizeRE, '-'));
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
const res = obj
......@@ -118,20 +132,6 @@ function stringifyQuery(obj, encodeStr = encode) {
return res ? `?${res}` : '';
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
class EventChannel {
constructor(id, events) {
this.id = id;
......
......@@ -93,6 +93,20 @@ function customizeEvent(str) {
return camelize(str.replace(customizeRE, '-'));
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
const res = obj
......@@ -113,20 +127,6 @@ function stringifyQuery(obj, encodeStr = encode) {
return res ? `?${res}` : '';
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
class EventChannel {
constructor(id, events) {
this.id = id;
......
......@@ -93,6 +93,20 @@ function customizeEvent(str) {
return camelize(str.replace(customizeRE, '-'));
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
const res = obj
......@@ -113,20 +127,6 @@ function stringifyQuery(obj, encodeStr = encode) {
return res ? `?${res}` : '';
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
class EventChannel {
constructor(id, events) {
this.id = id;
......
......@@ -93,6 +93,20 @@ function customizeEvent(str) {
return camelize(str.replace(customizeRE, '-'));
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
const res = obj
......@@ -113,20 +127,6 @@ function stringifyQuery(obj, encodeStr = encode) {
return res ? `?${res}` : '';
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
class EventChannel {
constructor(id, events) {
this.id = id;
......
......@@ -93,6 +93,20 @@ function customizeEvent(str) {
return camelize(str.replace(customizeRE, '-'));
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
const res = obj
......@@ -113,20 +127,6 @@ function stringifyQuery(obj, encodeStr = encode) {
return res ? `?${res}` : '';
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
class EventChannel {
constructor(id, events) {
this.id = id;
......
......@@ -28,6 +28,20 @@ function customizeEvent(str) {
return camelize(str.replace(customizeRE, '-'));
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
const res = obj
......@@ -48,20 +62,6 @@ function stringifyQuery(obj, encodeStr = encode) {
return res ? `?${res}` : '';
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
const MINI_PROGRAM_PAGE_RUNTIME_HOOKS = /*#__PURE__*/ (() => {
return {
onPageScroll: 1,
......
......@@ -93,6 +93,20 @@ function customizeEvent(str) {
return camelize(str.replace(customizeRE, '-'));
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
const encode = encodeURIComponent;
function stringifyQuery(obj, encodeStr = encode) {
const res = obj
......@@ -113,20 +127,6 @@ function stringifyQuery(obj, encodeStr = encode) {
return res ? `?${res}` : '';
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
class EventChannel {
constructor(id, events) {
this.id = id;
......
......@@ -300,10 +300,106 @@ function formatLog(module, ...args) {
.join(' ')}`;
}
function cache(fn) {
const cache = Object.create(null);
return (str) => {
const hit = cache[str];
return hit || (cache[str] = fn(str));
};
}
function cacheStringFunction(fn) {
return cache(fn);
}
function getLen(str = '') {
return ('' + str).replace(/[^\x00-\xff]/g, '**').length;
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
function removeLeadingSlash(str) {
return hasLeadingSlash(str) ? str.substr(1) : str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
function updateElementStyle(element, styles) {
for (const attrName in styles) {
element.style[attrName] = styles[attrName];
}
}
function once(fn, ctx = null) {
let res;
return ((...args) => {
if (fn) {
res = fn.apply(ctx, args);
fn = null;
}
return res;
});
}
const sanitise = (val) => (val && JSON.parse(JSON.stringify(val))) || val;
const _completeValue = (value) => (value > 9 ? value : '0' + value);
function formatDateTime({ date = new Date(), mode = 'date' }) {
if (mode === 'time') {
return (_completeValue(date.getHours()) + ':' + _completeValue(date.getMinutes()));
}
else {
return (date.getFullYear() +
'-' +
_completeValue(date.getMonth() + 1) +
'-' +
_completeValue(date.getDate()));
}
}
function callOptions(options, data) {
options = options || {};
if (typeof data === 'string') {
data = {
errMsg: data,
};
}
if (/:ok$/.test(data.errMsg)) {
if (typeof options.success === 'function') {
options.success(data);
}
}
else {
if (typeof options.fail === 'function') {
options.fail(data);
}
}
if (typeof options.complete === 'function') {
options.complete(data);
}
}
function getValueByDataPath(obj, path) {
if (!shared.isString(path)) {
return;
}
path = path.replace(/\[(\d+)\]/g, '.$1');
const parts = path.split('.');
let key = parts[0];
if (!obj) {
obj = {};
}
if (parts.length === 1) {
return obj[key];
}
return getValueByDataPath(obj[key], parts.slice(1).join('.'));
}
function formatKey(key) {
return shared.camelize(key.substring(5));
}
function initCustomDataset() {
// question/139181,增加副作用,避免 initCustomDataset 在 build 下被 tree-shaking
const initCustomDatasetOnce = /*#__PURE__*/ once(() => {
const prototype = HTMLElement.prototype;
const setAttribute = prototype.setAttribute;
prototype.setAttribute = function (key, value) {
......@@ -323,7 +419,7 @@ function initCustomDataset() {
}
removeAttribute.call(this, key);
};
}
});
function getCustomDataset(el) {
return shared.extend({}, el.dataset, el.__uniDataset);
}
......@@ -1063,101 +1159,6 @@ const ACTION_TYPE_ADD_WXS_EVENT = 12;
const ACTION_TYPE_PAGE_SCROLL = 15;
const ACTION_TYPE_EVENT = 20;
function cache(fn) {
const cache = Object.create(null);
return (str) => {
const hit = cache[str];
return hit || (cache[str] = fn(str));
};
}
function cacheStringFunction(fn) {
return cache(fn);
}
function getLen(str = '') {
return ('' + str).replace(/[^\x00-\xff]/g, '**').length;
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
function removeLeadingSlash(str) {
return hasLeadingSlash(str) ? str.substr(1) : str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
function updateElementStyle(element, styles) {
for (const attrName in styles) {
element.style[attrName] = styles[attrName];
}
}
function once(fn, ctx = null) {
let res;
return ((...args) => {
if (fn) {
res = fn.apply(ctx, args);
fn = null;
}
return res;
});
}
const sanitise = (val) => (val && JSON.parse(JSON.stringify(val))) || val;
const _completeValue = (value) => (value > 9 ? value : '0' + value);
function formatDateTime({ date = new Date(), mode = 'date' }) {
if (mode === 'time') {
return (_completeValue(date.getHours()) + ':' + _completeValue(date.getMinutes()));
}
else {
return (date.getFullYear() +
'-' +
_completeValue(date.getMonth() + 1) +
'-' +
_completeValue(date.getDate()));
}
}
function callOptions(options, data) {
options = options || {};
if (typeof data === 'string') {
data = {
errMsg: data,
};
}
if (/:ok$/.test(data.errMsg)) {
if (typeof options.success === 'function') {
options.success(data);
}
}
else {
if (typeof options.fail === 'function') {
options.fail(data);
}
}
if (typeof options.complete === 'function') {
options.complete(data);
}
}
function getValueByDataPath(obj, path) {
if (!shared.isString(path)) {
return;
}
path = path.replace(/\[(\d+)\]/g, '.$1');
const parts = path.split('.');
let key = parts[0];
if (!obj) {
obj = {};
}
if (parts.length === 1) {
return obj[key];
}
return getValueByDataPath(obj[key], parts.slice(1).join('.'));
}
function debounce(fn, delay) {
let timeout;
const newFn = function () {
......@@ -1471,7 +1472,7 @@ exports.getCustomDataset = getCustomDataset;
exports.getEnvLocale = getEnvLocale;
exports.getLen = getLen;
exports.getValueByDataPath = getValueByDataPath;
exports.initCustomDataset = initCustomDataset;
exports.initCustomDatasetOnce = initCustomDatasetOnce;
exports.invokeArrayFns = invokeArrayFns;
exports.isAppNVueNativeTag = isAppNVueNativeTag;
exports.isAppNativeTag = isAppNativeTag;
......
......@@ -231,7 +231,7 @@ declare interface HTMLElementWithDataset extends HTMLElement {
export declare const I18N_JSON_DELIMITERS: [string, string];
export declare function initCustomDataset(): void;
export declare const initCustomDatasetOnce: () => void;
/**
* nodeId
......
import { isHTMLTag, isSVGTag, hyphenate, camelize, extend, isString, isPlainObject, isArray, toTypeString, toRawType, capitalize } from '@vue/shared';
import { isHTMLTag, isSVGTag, hyphenate, camelize, isString, extend, isPlainObject, isArray, toTypeString, toRawType, capitalize } from '@vue/shared';
const BUILT_IN_TAG_NAMES = [
'ad',
......@@ -296,10 +296,106 @@ function formatLog(module, ...args) {
.join(' ')}`;
}
function cache(fn) {
const cache = Object.create(null);
return (str) => {
const hit = cache[str];
return hit || (cache[str] = fn(str));
};
}
function cacheStringFunction(fn) {
return cache(fn);
}
function getLen(str = '') {
return ('' + str).replace(/[^\x00-\xff]/g, '**').length;
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
function removeLeadingSlash(str) {
return hasLeadingSlash(str) ? str.substr(1) : str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
function updateElementStyle(element, styles) {
for (const attrName in styles) {
element.style[attrName] = styles[attrName];
}
}
function once(fn, ctx = null) {
let res;
return ((...args) => {
if (fn) {
res = fn.apply(ctx, args);
fn = null;
}
return res;
});
}
const sanitise = (val) => (val && JSON.parse(JSON.stringify(val))) || val;
const _completeValue = (value) => (value > 9 ? value : '0' + value);
function formatDateTime({ date = new Date(), mode = 'date' }) {
if (mode === 'time') {
return (_completeValue(date.getHours()) + ':' + _completeValue(date.getMinutes()));
}
else {
return (date.getFullYear() +
'-' +
_completeValue(date.getMonth() + 1) +
'-' +
_completeValue(date.getDate()));
}
}
function callOptions(options, data) {
options = options || {};
if (typeof data === 'string') {
data = {
errMsg: data,
};
}
if (/:ok$/.test(data.errMsg)) {
if (typeof options.success === 'function') {
options.success(data);
}
}
else {
if (typeof options.fail === 'function') {
options.fail(data);
}
}
if (typeof options.complete === 'function') {
options.complete(data);
}
}
function getValueByDataPath(obj, path) {
if (!isString(path)) {
return;
}
path = path.replace(/\[(\d+)\]/g, '.$1');
const parts = path.split('.');
let key = parts[0];
if (!obj) {
obj = {};
}
if (parts.length === 1) {
return obj[key];
}
return getValueByDataPath(obj[key], parts.slice(1).join('.'));
}
function formatKey(key) {
return camelize(key.substring(5));
}
function initCustomDataset() {
// question/139181,增加副作用,避免 initCustomDataset 在 build 下被 tree-shaking
const initCustomDatasetOnce = /*#__PURE__*/ once(() => {
const prototype = HTMLElement.prototype;
const setAttribute = prototype.setAttribute;
prototype.setAttribute = function (key, value) {
......@@ -319,7 +415,7 @@ function initCustomDataset() {
}
removeAttribute.call(this, key);
};
}
});
function getCustomDataset(el) {
return extend({}, el.dataset, el.__uniDataset);
}
......@@ -1059,101 +1155,6 @@ const ACTION_TYPE_ADD_WXS_EVENT = 12;
const ACTION_TYPE_PAGE_SCROLL = 15;
const ACTION_TYPE_EVENT = 20;
function cache(fn) {
const cache = Object.create(null);
return (str) => {
const hit = cache[str];
return hit || (cache[str] = fn(str));
};
}
function cacheStringFunction(fn) {
return cache(fn);
}
function getLen(str = '') {
return ('' + str).replace(/[^\x00-\xff]/g, '**').length;
}
function hasLeadingSlash(str) {
return str.indexOf('/') === 0;
}
function addLeadingSlash(str) {
return hasLeadingSlash(str) ? str : '/' + str;
}
function removeLeadingSlash(str) {
return hasLeadingSlash(str) ? str.substr(1) : str;
}
const invokeArrayFns = (fns, arg) => {
let ret;
for (let i = 0; i < fns.length; i++) {
ret = fns[i](arg);
}
return ret;
};
function updateElementStyle(element, styles) {
for (const attrName in styles) {
element.style[attrName] = styles[attrName];
}
}
function once(fn, ctx = null) {
let res;
return ((...args) => {
if (fn) {
res = fn.apply(ctx, args);
fn = null;
}
return res;
});
}
const sanitise = (val) => (val && JSON.parse(JSON.stringify(val))) || val;
const _completeValue = (value) => (value > 9 ? value : '0' + value);
function formatDateTime({ date = new Date(), mode = 'date' }) {
if (mode === 'time') {
return (_completeValue(date.getHours()) + ':' + _completeValue(date.getMinutes()));
}
else {
return (date.getFullYear() +
'-' +
_completeValue(date.getMonth() + 1) +
'-' +
_completeValue(date.getDate()));
}
}
function callOptions(options, data) {
options = options || {};
if (typeof data === 'string') {
data = {
errMsg: data,
};
}
if (/:ok$/.test(data.errMsg)) {
if (typeof options.success === 'function') {
options.success(data);
}
}
else {
if (typeof options.fail === 'function') {
options.fail(data);
}
}
if (typeof options.complete === 'function') {
options.complete(data);
}
}
function getValueByDataPath(obj, path) {
if (!isString(path)) {
return;
}
path = path.replace(/\[(\d+)\]/g, '.$1');
const parts = path.split('.');
let key = parts[0];
if (!obj) {
obj = {};
}
if (parts.length === 1) {
return obj[key];
}
return getValueByDataPath(obj[key], parts.slice(1).join('.'));
}
function debounce(fn, delay) {
let timeout;
const newFn = function () {
......@@ -1343,4 +1344,4 @@ function getEnvLocale() {
return (lang && lang.replace(/[.:].*/, '')) || 'en';
}
export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, BUILT_IN_TAG_NAMES, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, E$1 as Emitter, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, MINI_PROGRAM_PAGE_RUNTIME_HOOKS, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, NVUE_BUILT_IN_TAGS, NVUE_U_BUILT_IN_TAGS, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, SLOT_DEFAULT_NAME, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UNI_STORAGE_LOCALE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, addLeadingSlash, cache, cacheStringFunction, callOptions, createIsCustomElement, createRpx2Unit, createUniEvent, customizeEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultNVueRpx2Unit, defaultRpx2Unit, dynamicSlotName, forcePatchProp, formatAppLog, formatDateTime, formatH5Log, formatLog, getCustomDataset, getEnvLocale, getLen, getValueByDataPath, initCustomDataset, invokeArrayFns, isAppNVueNativeTag, isAppNativeTag, isBuiltInComponent, isComponentInternalInstance, isComponentTag, isH5CustomElement, isH5NativeTag, isMiniProgramNativeTag, isRootHook, normalizeDataset, normalizeEventType, normalizeTarget, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveComponentInstance, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, stringifyQuery, updateElementStyle };
export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, BUILT_IN_TAG_NAMES, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, E$1 as Emitter, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, MINI_PROGRAM_PAGE_RUNTIME_HOOKS, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, NVUE_BUILT_IN_TAGS, NVUE_U_BUILT_IN_TAGS, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, SLOT_DEFAULT_NAME, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UNI_STORAGE_LOCALE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, addLeadingSlash, cache, cacheStringFunction, callOptions, createIsCustomElement, createRpx2Unit, createUniEvent, customizeEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultNVueRpx2Unit, defaultRpx2Unit, dynamicSlotName, forcePatchProp, formatAppLog, formatDateTime, formatH5Log, formatLog, getCustomDataset, getEnvLocale, getLen, getValueByDataPath, initCustomDatasetOnce, invokeArrayFns, isAppNVueNativeTag, isAppNativeTag, isBuiltInComponent, isComponentInternalInstance, isComponentTag, isH5CustomElement, isH5NativeTag, isMiniProgramNativeTag, isRootHook, normalizeDataset, normalizeEventType, normalizeTarget, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveComponentInstance, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, stringifyQuery, updateElementStyle };
import { extend, camelize } from '@vue/shared'
import { once } from '../utils'
interface HTMLElementWithDataset extends HTMLElement {
__uniDataset?: Record<string, any>
}
......@@ -7,7 +8,8 @@ function formatKey(key: string) {
return camelize(key.substring(5))
}
export function initCustomDataset() {
// question/139181,增加副作用,避免 initCustomDataset 在 build 下被 tree-shaking
export const initCustomDatasetOnce = /*#__PURE__*/ once(() => {
const prototype = HTMLElement.prototype
const setAttribute = prototype.setAttribute
prototype.setAttribute = function (key, value) {
......@@ -30,7 +32,7 @@ export function initCustomDataset() {
}
removeAttribute.call(this, key)
}
}
})
export function getCustomDataset(el: HTMLElement | HTMLElementWithDataset) {
return extend({}, el.dataset, (el as HTMLElementWithDataset).__uniDataset)
......
import { isString } from '@vue/shared'
import { getCustomDataset } from './customDataset'
export { initCustomDataset, getCustomDataset } from './customDataset'
export { initCustomDatasetOnce, getCustomDataset } from './customDataset'
export * from './style'
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册