@tarojs/shared 4.0.1-alpha.1 → 4.0.1

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.
@@ -0,0 +1,315 @@
1
+ declare const touchEvents: {
2
+ bindTouchStart: string;
3
+ bindTouchMove: string;
4
+ bindTouchEnd: string;
5
+ bindTouchCancel: string;
6
+ bindLongTap: string;
7
+ };
8
+ declare const animation: {
9
+ animation: string;
10
+ bindAnimationStart: string;
11
+ bindAnimationIteration: string;
12
+ bindAnimationEnd: string;
13
+ bindTransitionEnd: string;
14
+ };
15
+ declare function singleQuote(s: string): string;
16
+ declare const internalComponents: Record<string, Record<string, string>>;
17
+ declare const controlledComponent: Set<string>;
18
+ declare const focusComponents: Set<string>;
19
+ declare const voidElements: Set<string>;
20
+ declare const nestElements: Map<string, number>;
21
+ declare enum PLATFORM_TYPE {
22
+ MINI = "mini",
23
+ WEB = "web",
24
+ RN = "rn",
25
+ HARMONY = "harmony",
26
+ QUICK = "quickapp"
27
+ }
28
+ declare const PLATFORM_CONFIG_MAP: {
29
+ h5: {
30
+ type: PLATFORM_TYPE;
31
+ };
32
+ harmony: {
33
+ type: PLATFORM_TYPE;
34
+ };
35
+ mini: {
36
+ type: PLATFORM_TYPE;
37
+ };
38
+ rn: {
39
+ type: PLATFORM_TYPE;
40
+ };
41
+ quickapp: {
42
+ type: PLATFORM_TYPE;
43
+ };
44
+ };
45
+ type EventName = string | symbol;
46
+ type EventCallbacks = Record<EventName, Record<"next" | "tail", unknown>>;
47
+ declare class Events {
48
+ protected callbacks?: EventCallbacks;
49
+ static eventSplitter: string; // Note: Harmony ACE API 8 开发板不支持使用正则 split 字符串 /\s+/
50
+ constructor(opts?: 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;
55
+ }
56
+ interface RouteEvt extends Events {
57
+ addEvents: (events: any) => void;
58
+ emit?: (events: any, data: any) => void;
59
+ }
60
+ interface PageEvt extends Events {
61
+ exeList: any[];
62
+ emit?: (events: any, data: any) => void;
63
+ }
64
+ declare const EventChannel: {
65
+ pageChannel: PageEvt;
66
+ routeChannel: RouteEvt;
67
+ };
68
+ declare function isString(o: unknown): o is string;
69
+ declare function isUndefined(o: unknown): o is undefined;
70
+ declare function isNull(o: unknown): o is null;
71
+ declare function isObject<T>(o: unknown): o is T;
72
+ declare function isBoolean(o: unknown): o is boolean;
73
+ declare function isFunction(o: unknown): o is (...args: any[]) => any;
74
+ declare function isNumber(o: unknown): o is number;
75
+ declare function isBooleanStringLiteral(o: unknown): o is string;
76
+ declare const isArray: (arg: any) => arg is any[];
77
+ declare const isWebPlatform: () => boolean;
78
+ type IObject = Record<string, any>;
79
+ interface IProcessApisIOptions {
80
+ noPromiseApis?: Set<string>;
81
+ needPromiseApis?: Set<string>;
82
+ handleSyncApis?: (key: string, global: IObject, args: any[]) => any;
83
+ transformMeta?: (key: string, options: IObject) => {
84
+ key: string;
85
+ options: IObject;
86
+ };
87
+ modifyApis?: (apis: Set<string>) => void;
88
+ modifyAsyncResult?: (key: string, res: any) => void;
89
+ isOnlyPromisify?: boolean;
90
+ [propName: string]: any;
91
+ }
92
+ interface IApiDiff {
93
+ [key: string]: {
94
+ /** API重命名 */
95
+ alias?: string;
96
+ options?: {
97
+ /** API参数键名修改 */
98
+ change?: {
99
+ old: string;
100
+ new: string;
101
+ }[];
102
+ /** API参数值修改 */
103
+ set?: {
104
+ key: string;
105
+ value: ((options: Record<string, any>) => unknown) | unknown;
106
+ }[];
107
+ };
108
+ };
109
+ }
110
+ declare function processApis(taro: any, global: any, config?: IProcessApisIOptions): void;
111
+ // 字符串简写
112
+ declare const enum Shortcuts {
113
+ Container = "container",
114
+ Childnodes = "cn",
115
+ Text = "v",
116
+ NodeType = "nt",
117
+ NodeName = "nn",
118
+ // Attrtibutes
119
+ Style = "st",
120
+ Class = "cl",
121
+ Src = "src"
122
+ }
123
+ declare const EMPTY_OBJ: any;
124
+ declare const EMPTY_ARR: never[];
125
+ declare const noop: (..._: unknown[]) => void;
126
+ /**
127
+ * Boxed value.
128
+ *
129
+ * @typeparam T Value type.
130
+ */
131
+ interface Box<T> {
132
+ v: T;
133
+ }
134
+ /**
135
+ * box creates a boxed value.
136
+ *
137
+ * @typeparam T Value type.
138
+ * @param v Value.
139
+ * @returns Boxed value.
140
+ */
141
+ declare const box: <T>(v: T) => {
142
+ v: T;
143
+ };
144
+ /**
145
+ * box creates a boxed value.
146
+ *
147
+ * @typeparam T Value type.
148
+ * @param b Boxed value.
149
+ * @returns Value.
150
+ */
151
+ declare const unbox: <T>(b: Box<T>) => T;
152
+ declare function toDashed(s: string): string;
153
+ declare function toCamelCase(s: string): string;
154
+ declare const toKebabCase: (string: any) => any;
155
+ declare function capitalize(s: string): string;
156
+ declare const hasOwn: (val: Record<any, any>, key: string | symbol) => any;
157
+ /**
158
+ * ensure takes a condition and throw a error if the condition fails,
159
+ * like failure::ensure: https://docs.rs/failure/0.1.1/failure/macro.ensure.html
160
+ * @param condition condition.
161
+ * @param msg error message.
162
+ */
163
+ declare function ensure(condition: boolean, msg: string): asserts condition;
164
+ declare function warn(condition: boolean, msg: string): void;
165
+ declare function queryToJson(str: any): {};
166
+ declare function getUniqueKey(): string;
167
+ declare function cacheDataSet(key: any, val: any): void;
168
+ declare function cacheDataGet(key: any, delelteAfterGet?: any): any;
169
+ declare function cacheDataHas(key: any): boolean;
170
+ declare function mergeInternalComponents(components: any): Record<string, Record<string, string>>;
171
+ declare function getComponentsAlias(origin: typeof internalComponents): {};
172
+ declare function getPlatformType(platform?: string, configNameOrType?: string): PLATFORM_TYPE;
173
+ declare function mergeReconciler(hostConfig: any, hooksForTest?: any): void;
174
+ declare function nonsupport(api: any): () => void;
175
+ declare function setUniqueKeyToRoute(key: string, obj: any): void;
176
+ declare function indent(str: string, size: number): string;
177
+ // Note: @tarojs/runtime 不依赖 @tarojs/taro, 所以不能改为从 @tarojs/taro 引入 (可能导致循环依赖)
178
+ type TFunc = (...args: any[]) => any;
179
+ declare enum HOOK_TYPE {
180
+ SINGLE = 0,
181
+ MULTI = 1,
182
+ WATERFALL = 2
183
+ }
184
+ interface Hook {
185
+ type: HOOK_TYPE;
186
+ initial?: TFunc | null;
187
+ }
188
+ interface MiniLifecycle {
189
+ app: [
190
+ string,
191
+ /** onLaunch */ string,
192
+ /** onShow */ string /** onHide */
193
+ ];
194
+ page: [
195
+ string,
196
+ /** onLoad */ string,
197
+ /** onUnload */ string,
198
+ /** onReady */ string,
199
+ /** onShow */ string,
200
+ /** onHide */ string[],
201
+ /** others */ string[] /** side-effects */
202
+ ];
203
+ component: [
204
+ string,
205
+ /** attached */ string
206
+ ];
207
+ }
208
+ interface MiniElementData {
209
+ [Shortcuts.Childnodes]?: MiniData[];
210
+ [Shortcuts.NodeName]: string;
211
+ [Shortcuts.Class]?: string;
212
+ [Shortcuts.Style]?: string;
213
+ uid?: string;
214
+ sid: string;
215
+ [key: string]: unknown;
216
+ }
217
+ interface MiniTextData {
218
+ [Shortcuts.Text]: string;
219
+ [Shortcuts.NodeName]: string;
220
+ }
221
+ type MiniData = MiniElementData | MiniTextData;
222
+ interface UpdatePayload {
223
+ path: string;
224
+ value: string | boolean | (() => MiniData | MiniData[]);
225
+ }
226
+ type Target = Record<string, unknown> & {
227
+ dataset: Record<string, unknown>;
228
+ id: string;
229
+ };
230
+ interface MpEvent {
231
+ type: string;
232
+ detail: Record<string, unknown>;
233
+ target: Target;
234
+ currentTarget: Target;
235
+ }
236
+ declare function TaroHook(type: HOOK_TYPE, initial?: TFunc): Hook;
237
+ declare class TaroHooks<T extends Record<string, TFunc> = any> extends Events {
238
+ hooks: Record<keyof T, Hook>;
239
+ constructor(hooks: Record<keyof T, Hook>, opts?: any);
240
+ private tapOneOrMany;
241
+ tap<K extends Extract<keyof T, string>>(hookName: K, callback: T[K] | T[K][]): void;
242
+ call<K extends Extract<keyof T, string>>(hookName: K, ...rest: Parameters<T[K]>): ReturnType<T[K]> | undefined;
243
+ isExist(hookName: string): boolean;
244
+ }
245
+ type ITaroHooks = {
246
+ /** 小程序端 App、Page 构造对象的生命周期方法名称 */
247
+ getMiniLifecycle: (defaultConfig: MiniLifecycle) => MiniLifecycle;
248
+ getMiniLifecycleImpl: () => MiniLifecycle;
249
+ /** 解决 React 生命周期名称的兼容问题 */
250
+ getLifecycle: (instance: any, lifecyle: any) => TFunc | Array<TFunc> | undefined;
251
+ /** 提供Hook,为不同平台提供修改生命周期配置 */
252
+ modifyRecursiveComponentConfig: (defaultConfig: MiniLifecycle, options: any) => any;
253
+ /** 解决百度小程序的模版语法问题 */
254
+ getPathIndex: (indexOfNode: number) => string;
255
+ /** 解决支付宝小程序分包时全局作用域不一致的问题 */
256
+ getEventCenter: (EventsClass: typeof Events) => Events;
257
+ isBubbleEvents: (eventName: string) => boolean;
258
+ getSpecialNodes: () => string[];
259
+ /** 解决 Vue2 布尔值属性值的设置问题 */
260
+ onRemoveAttribute: (element: any, qualifiedName: string) => boolean;
261
+ /** 用于把 React 同一事件回调中的所有 setState 合并到同一个更新处理中 */
262
+ batchedEventUpdates: (cb: TFunc) => void;
263
+ /** 用于处理 React 中的小程序生命周期 hooks */
264
+ mergePageInstance: (prev: any, next: any) => void;
265
+ /** 用于修改传递给小程序 Page 构造器的对象 */
266
+ modifyPageObject: (config: Record<any, any>) => void;
267
+ /** H5 下拉刷新 wrapper */
268
+ createPullDownComponent: (el: any, path: string, framework: any, customWrapper?: any, stampId?: string) => void;
269
+ /** H5 获取原生 DOM 对象 */
270
+ getDOMNode: (instance: any) => any;
271
+ /**
272
+ * @todo: multi
273
+ * 修改 Taro DOM 序列化数据
274
+ **/
275
+ modifyHydrateData: (data: Record<string, any>, node: any) => void;
276
+ /**
277
+ * 自定义处理 Taro DOM 序列化数据,如使其脱离 data 树
278
+ */
279
+ transferHydrateData: (data: Record<string, any>, element: any, componentsAlias: Record<string, any>) => void;
280
+ /**
281
+ * @todo: multi
282
+ * 修改 Taro DOM 序列化数据
283
+ **/
284
+ modifySetAttrPayload: (element: any, key: string, payload: UpdatePayload, componentsAlias: Record<string, any>) => void;
285
+ /**
286
+ * @todo: multi
287
+ * 修改 Taro DOM 序列化数据
288
+ **/
289
+ modifyRmAttrPayload: (element: any, key: string, payload: UpdatePayload, componentsAlias: Record<string, any>) => void;
290
+ /**
291
+ * @todo: multi
292
+ * 调用 addEventListener 时触发
293
+ **/
294
+ onAddEvent: (type: string, handler: any, options: any, node: any) => void;
295
+ /** 用于修改小程序原生事件对象 */
296
+ modifyMpEvent: (event: MpEvent) => void;
297
+ modifyMpEventImpl: (event: MpEvent) => void;
298
+ /** 用于修改 Taro DOM 事件对象 */
299
+ modifyTaroEvent: (event: any, element: any) => void;
300
+ dispatchTaroEvent: (event: any, element: any) => void;
301
+ dispatchTaroEventFinish: (event: any, element: any) => void;
302
+ modifyTaroEventReturn: (node: any, event: any, returnVal: any) => any;
303
+ modifyDispatchEvent: (event: any, element: any) => void;
304
+ injectNewStyleProperties: (styleProperties: string[]) => void;
305
+ initNativeApi: (taro: Record<string, any>) => void;
306
+ patchElement: (node: any) => void;
307
+ /** 解 Proxy */
308
+ proxyToRaw: (proxyObj: any) => Record<any, any>;
309
+ /** 元素增加事件监听钩子 */
310
+ modifyAddEventListener: (element: any, sideEffect: boolean, getComponentsAlias: () => Record<string, any>) => void;
311
+ /** 元素删除事件监听钩子 */
312
+ modifyRemoveEventListener: (element: any, sideEffect: boolean, getComponentsAlias: () => Record<string, any>) => void;
313
+ };
314
+ declare const hooks: TaroHooks<ITaroHooks>;
315
+ export { touchEvents, animation, singleQuote, internalComponents, controlledComponent, focusComponents, voidElements, nestElements, PLATFORM_TYPE, PLATFORM_CONFIG_MAP, EventChannel, 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 };
@@ -548,7 +548,7 @@ const defaultMiniLifecycle = {
548
548
  'onReachBottom',
549
549
  'onPageScroll',
550
550
  'onResize',
551
- 'defer:onTabItemTap', // defer: 需要等页面组件挂载后再调用
551
+ 'defer:onTabItemTap',
552
552
  'onTitleClick',
553
553
  'onOptionMenuClick',
554
554
  'onPopMenuClick',
@@ -696,7 +696,6 @@ const hooks = new TaroHooks({
696
696
  patchElement: TaroHook(HOOK_TYPE.MULTI),
697
697
  modifyAddEventListener: TaroHook(HOOK_TYPE.SINGLE),
698
698
  modifyRemoveEventListener: TaroHook(HOOK_TYPE.SINGLE),
699
- getMemoryLevel: TaroHook(HOOK_TYPE.SINGLE),
700
699
  });
701
700
 
702
701
  const EMPTY_OBJ = {};