@tarojs/shared 3.7.0-alpha.2 → 3.7.0-alpha.4

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/index.d.ts CHANGED
@@ -42,31 +42,16 @@ declare const PLATFORM_CONFIG_MAP: {
42
42
  type: PLATFORM_TYPE;
43
43
  };
44
44
  };
45
- type Callback1<T1> = (arg1: T1) => any;
46
- type Callback2<T1, T2> = (arg1: T1, arg2: T2) => any;
47
- type Callback3<T1, T2, T3> = (arg1: T1, arg2: T2, arg3: T3) => any;
48
- type Callback4<T1, T2, T3, T4> = (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => any;
49
- type Callback5<T1, T2, T3, T4, T5> = (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => any;
50
- type Callback6Rest<T1, T2, T3, T4, T5, T6> = (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, ...rest: any[]) => any;
45
+ type EventName = string | symbol;
46
+ type EventCallbacks = Record<EventName, Record<"next" | "tail", unknown>>;
51
47
  declare class Events {
52
- protected callbacks?: Record<string, unknown>;
48
+ protected callbacks?: EventCallbacks;
53
49
  static eventSplitter: string; // Note: Harmony ACE API 8 开发板不支持使用正则 split 字符串 /\s+/
54
50
  constructor(opts?: any);
55
- on<T>(event: string, callback: Callback1<T>, context?: any): this;
56
- on<T1, T2>(event: string, callback: Callback2<T1, T2>, context?: any): this;
57
- on<T1, T2, T3>(event: string, callback: Callback3<T1, T2, T3>, context?: any): this;
58
- on<T1, T2, T3, T4>(event: string, callback: Callback4<T1, T2, T3, T4>, comtext: any): this;
59
- on<T1, T2, T3, T4, T5>(event: string, callback: Callback5<T1, T2, T3, T4, T5>, context?: any): this;
60
- on<T1, T2, T3, T4, T5, T6>(event: string, callback: Callback6Rest<T1, T2, T3, T4, T5, T6>, context?: any): this;
61
- once(events: any, callback: any, context: any): this;
62
- off(events: any, callback?: any, context?: any): this;
63
- trigger(event: string): any;
64
- trigger<T1>(event: string, arg: T1): any;
65
- trigger<T1, T2>(event: string, arg1: T1, arg2: T2): any;
66
- trigger<T1, T2, T3>(event: string, arg1: T1, arg2: T2, arg3: T3): any;
67
- trigger<T1, T2, T3, T4>(event: string, arg1: T1, arg2: T2, arg3: T3, arg4: T4): any;
68
- trigger<T1, T2, T3, T4, T5>(event: string, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5): any;
69
- trigger<T1, T2, T3, T4, T5, T6>(event: string, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, ...rest: any[]): any;
51
+ on(eventName: EventName, callback: (...args: any[]) => void, context?: any): this;
52
+ once(events: EventName, callback: (...r: any[]) => void, context?: any): this;
53
+ off(events?: EventName, callback?: (...args: any[]) => void, context?: any): this;
54
+ trigger(events: EventName, ...args: any[]): this;
70
55
  }
71
56
  declare function isString(o: unknown): o is string;
72
57
  declare function isUndefined(o: unknown): o is undefined;
@@ -236,7 +221,7 @@ interface MpEvent {
236
221
  currentTarget: Target;
237
222
  }
238
223
  declare function TaroHook(type: HOOK_TYPE, initial?: Func): Hook;
239
- declare class TaroHooks<T extends Record<string, Func>> extends Events {
224
+ declare class TaroHooks<T extends Record<string, Func> = any> extends Events {
240
225
  hooks: Record<keyof T, Hook>;
241
226
  constructor(hooks: Record<keyof T, Hook>, opts?: any);
242
227
  private tapOneOrMany;
@@ -265,7 +250,7 @@ type ITaroHooks = {
265
250
  /** 用于修改传递给小程序 Page 构造器的对象 */
266
251
  modifyPageObject: (config: Record<any, any>) => void;
267
252
  /** H5 下拉刷新 wrapper */
268
- createPullDownComponent: (el: any, path: string, framework: any, customWrapper?: any) => void;
253
+ createPullDownComponent: (el: any, path: string, framework: any, customWrapper?: any, stampId?: string) => void;
269
254
  /** H5 获取原生 DOM 对象 */
270
255
  getDOMNode: (instance: any) => any;
271
256
  /**
@@ -293,9 +278,14 @@ type ITaroHooks = {
293
278
  modifyMpEventImpl: (event: MpEvent) => void;
294
279
  /** 用于修改 Taro DOM 事件对象 */
295
280
  modifyTaroEvent: (event: any, element: any) => void;
281
+ dispatchTaroEvent: (event: any, element: any) => void;
282
+ dispatchTaroEventFinish: (event: any, element: any) => void;
296
283
  modifyDispatchEvent: (event: any, element: any) => void;
284
+ injectNewStyleProperties: (styleProperties: string[]) => void;
297
285
  initNativeApi: (taro: Record<string, any>) => void;
298
286
  patchElement: (node: any) => void;
287
+ /** 解 Proxy */
288
+ proxyToRaw: (proxyObj: any) => Record<any, any>;
299
289
  };
300
290
  declare const hooks: TaroHooks<ITaroHooks>;
301
291
  export { touchEvents, animation, singleQuote, internalComponents, controlledComponent, focusComponents, voidElements, nestElements, PLATFORM_TYPE, PLATFORM_CONFIG_MAP, Events, isString, isUndefined, isNull, isObject, isBoolean, isFunction, isNumber, isBooleanStringLiteral, isArray, isWebPlatform, IApiDiff, processApis, HOOK_TYPE, TaroHook, TaroHooks, hooks, Shortcuts, EMPTY_OBJ, EMPTY_ARR, noop, Box, box, unbox, toDashed, toCamelCase, toKebabCase, capitalize, hasOwn, ensure, warn, queryToJson, getUniqueKey, cacheDataSet, cacheDataGet, cacheDataHas, mergeInternalComponents, getComponentsAlias, getPlatformType, mergeReconciler, nonsupport, setUniqueKeyToRoute, indent };
package/dist/index.js CHANGED
@@ -79,7 +79,7 @@ const Input = {
79
79
  focus: DEFAULT_FALSE,
80
80
  'confirm-type': singleQuote('done'),
81
81
  'confirm-hold': DEFAULT_FALSE,
82
- cursor: 'i.value.length',
82
+ cursor: '-1',
83
83
  'selection-start': '-1',
84
84
  'selection-end': '-1',
85
85
  bindInput: NO_DEFAULT_VALUE,
@@ -374,16 +374,21 @@ class Events {
374
374
  this.callbacks = (_a = opts === null || opts === void 0 ? void 0 : opts.callbacks) !== null && _a !== void 0 ? _a : {};
375
375
  }
376
376
  on(eventName, callback, context) {
377
- let event, node, tail, list;
377
+ let event, tail, _eventName;
378
378
  if (!callback) {
379
379
  return this;
380
380
  }
381
- eventName = eventName.split(Events.eventSplitter);
381
+ if (typeof eventName === 'symbol') {
382
+ _eventName = [eventName];
383
+ }
384
+ else {
385
+ _eventName = eventName.split(Events.eventSplitter);
386
+ }
382
387
  this.callbacks || (this.callbacks = {});
383
388
  const calls = this.callbacks;
384
- while ((event = eventName.shift())) {
385
- list = calls[event];
386
- node = list ? list.tail : {};
389
+ while ((event = _eventName.shift())) {
390
+ const list = calls[event];
391
+ const node = list ? list.tail : {};
387
392
  node.next = tail = {};
388
393
  node.context = context;
389
394
  node.callback = callback;
@@ -403,7 +408,7 @@ class Events {
403
408
  return this;
404
409
  }
405
410
  off(events, callback, context) {
406
- let event, calls, node, tail, cb, ctx;
411
+ let event, calls, _events;
407
412
  if (!(calls = this.callbacks)) {
408
413
  return this;
409
414
  }
@@ -411,17 +416,22 @@ class Events {
411
416
  delete this.callbacks;
412
417
  return this;
413
418
  }
414
- events = events ? events.split(Events.eventSplitter) : Object.keys(calls);
415
- while ((event = events.shift())) {
416
- node = calls[event];
419
+ if (typeof events === 'symbol') {
420
+ _events = [events];
421
+ }
422
+ else {
423
+ _events = events ? events.split(Events.eventSplitter) : Object.keys(calls);
424
+ }
425
+ while ((event = _events.shift())) {
426
+ let node = calls[event];
417
427
  delete calls[event];
418
428
  if (!node || !(callback || context)) {
419
429
  continue;
420
430
  }
421
- tail = node.tail;
431
+ const tail = node.tail;
422
432
  while ((node = node.next) !== tail) {
423
- cb = node.callback;
424
- ctx = node.context;
433
+ const cb = node.callback;
434
+ const ctx = node.context;
425
435
  if ((callback && cb !== callback) || (context && ctx !== context)) {
426
436
  this.on(event, cb, ctx);
427
437
  }
@@ -429,18 +439,22 @@ class Events {
429
439
  }
430
440
  return this;
431
441
  }
432
- trigger(events) {
433
- let event, node, calls, tail;
442
+ trigger(events, ...args) {
443
+ let event, node, calls, _events;
434
444
  if (!(calls = this.callbacks)) {
435
445
  return this;
436
446
  }
437
- events = events.split(Events.eventSplitter);
438
- const rest = [].slice.call(arguments, 1);
439
- while ((event = events.shift())) {
447
+ if (typeof events === 'symbol') {
448
+ _events = [events];
449
+ }
450
+ else {
451
+ _events = events.split(Events.eventSplitter);
452
+ }
453
+ while ((event = _events.shift())) {
440
454
  if ((node = calls[event])) {
441
- tail = node.tail;
455
+ const tail = node.tail;
442
456
  while ((node = node.next) !== tail) {
443
- node.callback.apply(node.context || this, rest);
457
+ node.callback.apply(node.context || this, args);
444
458
  }
445
459
  }
446
460
  }
@@ -620,6 +634,9 @@ const hooks = new TaroHooks({
620
634
  modifySetAttrPayload: TaroHook(exports.HOOK_TYPE.SINGLE),
621
635
  modifyRmAttrPayload: TaroHook(exports.HOOK_TYPE.SINGLE),
622
636
  onAddEvent: TaroHook(exports.HOOK_TYPE.SINGLE),
637
+ proxyToRaw: TaroHook(exports.HOOK_TYPE.SINGLE, function (proxyObj) {
638
+ return proxyObj;
639
+ }),
623
640
  modifyMpEvent: TaroHook(exports.HOOK_TYPE.MULTI),
624
641
  modifyMpEventImpl: TaroHook(exports.HOOK_TYPE.SINGLE, function (e) {
625
642
  try {
@@ -630,7 +647,12 @@ const hooks = new TaroHooks({
630
647
  console.warn('[Taro modifyMpEvent hook Error]: ' + (error === null || error === void 0 ? void 0 : error.message));
631
648
  }
632
649
  }),
650
+ injectNewStyleProperties: TaroHook(exports.HOOK_TYPE.SINGLE),
633
651
  modifyTaroEvent: TaroHook(exports.HOOK_TYPE.MULTI),
652
+ dispatchTaroEvent: TaroHook(exports.HOOK_TYPE.SINGLE, (e, node) => {
653
+ node.dispatchEvent(e);
654
+ }),
655
+ dispatchTaroEventFinish: TaroHook(exports.HOOK_TYPE.MULTI),
634
656
  modifyDispatchEvent: TaroHook(exports.HOOK_TYPE.MULTI),
635
657
  initNativeApi: TaroHook(exports.HOOK_TYPE.MULTI),
636
658
  patchElement: TaroHook(exports.HOOK_TYPE.MULTI)
@@ -1171,6 +1193,15 @@ function equipCommonApis(taro, global, apis = {}) {
1171
1193
  taro.addInterceptor = link.addInterceptor.bind(link);
1172
1194
  taro.cleanInterceptors = link.cleanInterceptors.bind(link);
1173
1195
  taro.miniGlobal = taro.options.miniGlobal = global;
1196
+ taro.getAppInfo = function () {
1197
+ return {
1198
+ platform: process.env.TARO_PLATFORM || 'MiniProgram',
1199
+ taroVersion: process.env.TARO_VERSION || 'unknown',
1200
+ designWidth: taro.config.designWidth
1201
+ };
1202
+ };
1203
+ taro.createSelectorQuery = delayRef(taro, global, 'createSelectorQuery', 'exec');
1204
+ taro.createIntersectionObserver = delayRef(taro, global, 'createIntersectionObserver', 'observe');
1174
1205
  }
1175
1206
  /**
1176
1207
  * 将Task对象中的方法挂载到promise对象中,适配小程序api原生返回结果
@@ -1187,6 +1218,16 @@ function equipTaskMethodsIntoPromise(task, promise) {
1187
1218
  }
1188
1219
  });
1189
1220
  }
1221
+ function delayRef(taro, global, name, method) {
1222
+ return function () {
1223
+ const res = global[name]();
1224
+ const raw = res[method].bind(res);
1225
+ res[method] = function (...args) {
1226
+ taro.nextTick(() => raw(...args));
1227
+ };
1228
+ return res;
1229
+ };
1230
+ }
1190
1231
 
1191
1232
  exports.EMPTY_ARR = EMPTY_ARR;
1192
1233
  exports.EMPTY_OBJ = EMPTY_OBJ;