@stdex/create 0.0.0-stage → 1.2.0

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.
Files changed (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +66 -2
  3. package/README_EN.md +67 -0
  4. package/package.json +40 -3
  5. package/src/eslint.config.js +2 -0
  6. package/src/index.js +233 -0
  7. package/templates/base/eslint.config.js +2 -0
  8. package/templates/base/index.js +3 -0
  9. package/templates/base/package.json +16 -0
  10. package/templates/miniprogram/README.md +27 -0
  11. package/templates/miniprogram/_gitignore +3 -0
  12. package/templates/miniprogram/eslint.config.cjs +25 -0
  13. package/templates/miniprogram/gulpfile.js +81 -0
  14. package/templates/miniprogram/package.json +22 -0
  15. package/templates/miniprogram/project.config.json +31 -0
  16. package/templates/miniprogram/project.private.config.json +8 -0
  17. package/templates/miniprogram/src/app.json +16 -0
  18. package/templates/miniprogram/src/app.scss +0 -0
  19. package/templates/miniprogram/src/app.ts +6 -0
  20. package/templates/miniprogram/src/lib/app-data.ts +46 -0
  21. package/templates/miniprogram/src/pages/index/index.json +3 -0
  22. package/templates/miniprogram/src/pages/index/index.scss +11 -0
  23. package/templates/miniprogram/src/pages/index/index.ts +13 -0
  24. package/templates/miniprogram/src/pages/index/index.wxml +1 -0
  25. package/templates/miniprogram/src/sitemap.json +9 -0
  26. package/templates/miniprogram/tsconfig.json +11 -0
  27. package/templates/miniprogram/typings/index.d.ts +5 -0
  28. package/templates/miniprogram/typings/types/index.d.ts +1 -0
  29. package/templates/miniprogram/typings/types/wx/index.d.ts +162 -0
  30. package/templates/miniprogram/typings/types/wx/lib.wx.api.d.ts +32387 -0
  31. package/templates/miniprogram/typings/types/wx/lib.wx.app.d.ts +400 -0
  32. package/templates/miniprogram/typings/types/wx/lib.wx.behavior.d.ts +68 -0
  33. package/templates/miniprogram/typings/types/wx/lib.wx.canvas.d.ts +2623 -0
  34. package/templates/miniprogram/typings/types/wx/lib.wx.cloud.d.ts +1016 -0
  35. package/templates/miniprogram/typings/types/wx/lib.wx.component.d.ts +700 -0
  36. package/templates/miniprogram/typings/types/wx/lib.wx.event.d.ts +1436 -0
  37. package/templates/miniprogram/typings/types/wx/lib.wx.page.d.ts +272 -0
  38. package/templates/miniprogram/typings/types/wx/lib.wx.phys3D.d.ts +409 -0
  39. package/templates/miniprogram/typings/types/wx/lib.wx.wasm.d.ts +152 -0
  40. package/templates/miniprogram/typings/types/wx/lib.wx.xr-frame.d.ts +15631 -0
  41. package/templates/miniprogram/variables.json +11 -0
  42. package/templates/service/README.md +64 -0
  43. package/templates/service/_env +1 -0
  44. package/templates/service/_gitignore +5 -0
  45. package/templates/service/eslint.config.js +2 -0
  46. package/templates/service/package.json +48 -0
  47. package/templates/service/prisma/schema.prisma +40 -0
  48. package/templates/service/prisma/sql/demoTypedSql.sql +1 -0
  49. package/templates/service/prisma.config.ts +12 -0
  50. package/templates/service/setup.js +4 -0
  51. package/templates/service/src/cache.ts +28 -0
  52. package/templates/service/src/config.ts +49 -0
  53. package/templates/service/src/controllers/common.ts +43 -0
  54. package/templates/service/src/controllers/demo-school.ts +7 -0
  55. package/templates/service/src/controllers/demo-student.ts +7 -0
  56. package/templates/service/src/controllers/index.ts +15 -0
  57. package/templates/service/src/database.ts +52 -0
  58. package/templates/service/src/index.ts +15 -0
  59. package/templates/service/src/logger.ts +10 -0
  60. package/templates/service/src/routes/demo-school.ts +9 -0
  61. package/templates/service/src/routes/index.ts +3 -0
  62. package/templates/service/src/routes/router.ts +42 -0
  63. package/templates/service/src/tasks/common.ts +25 -0
  64. package/templates/service/src/tasks/demo-school.ts +10 -0
  65. package/templates/service/src/tasks/index.ts +1 -0
  66. package/templates/service/tsconfig.build.json +9 -0
  67. package/templates/service/tsconfig.json +10 -0
  68. package/templates/site/_gitignore +3 -0
  69. package/templates/site/_pnpm-workspace.yaml +4 -0
  70. package/templates/site/eslint.config.js +19 -0
  71. package/templates/site/package.json +41 -0
  72. package/templates/site/public/favicon.png +0 -0
  73. package/templates/site/src/app/header.tsx +31 -0
  74. package/templates/site/src/app/index.tsx +38 -0
  75. package/templates/site/src/app/layout.tsx +63 -0
  76. package/templates/site/src/app/menu.tsx +115 -0
  77. package/templates/site/src/app/router.tsx +50 -0
  78. package/templates/site/src/app/style.css +9 -0
  79. package/templates/site/src/assets/logo.png +0 -0
  80. package/templates/site/src/components/Breadcrumb.tsx +47 -0
  81. package/templates/site/src/components/DevStatus.tsx +14 -0
  82. package/templates/site/src/index.html +13 -0
  83. package/templates/site/src/index.tsx +5 -0
  84. package/templates/site/src/lib/config.ts +6 -0
  85. package/templates/site/src/lib/init-dayjs.ts +8 -0
  86. package/templates/site/src/lib/logging.ts +5 -0
  87. package/templates/site/src/views/dashboard.tsx +7 -0
  88. package/templates/site/src/views/school-detail.tsx +13 -0
  89. package/templates/site/src/views/school-ranking.tsx +7 -0
  90. package/templates/site/src/views/schools.tsx +43 -0
  91. package/templates/site/src/views/setting.tsx +7 -0
  92. package/templates/site/src/views/student-score.tsx +7 -0
  93. package/templates/site/src/views/students.tsx +7 -0
  94. package/templates/site/tsconfig.json +10 -0
  95. package/templates/site/vite.config.js +60 -0
@@ -0,0 +1,700 @@
1
+ /*! *****************************************************************************
2
+ Copyright (c) 2023 Tencent, Inc. All rights reserved.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the "Software"), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8
+ of the Software, and to permit persons to whom the Software is furnished to do
9
+ so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ ***************************************************************************** */
22
+
23
+ declare namespace WechatMiniprogram.Component {
24
+ type Instance<
25
+ TData extends DataOption,
26
+ TProperty extends PropertyOption,
27
+ TMethod extends Partial<MethodOption>,
28
+ TCustomInstanceProperty extends IAnyObject = {},
29
+ TIsPage extends boolean = false
30
+ > = InstanceProperties &
31
+ InstanceMethods<TData> &
32
+ TMethod &
33
+ (TIsPage extends true ? Page.ILifetime : {}) &
34
+ TCustomInstanceProperty & {
35
+ /** 组件数据,**包括内部数据和属性值** */
36
+ data: TData & PropertyOptionToData<TProperty>
37
+ /** 组件数据,**包括内部数据和属性值**(与 `data` 一致) */
38
+ properties: TData & PropertyOptionToData<TProperty>
39
+ }
40
+ type TrivialInstance = Instance<
41
+ IAnyObject,
42
+ IAnyObject,
43
+ IAnyObject,
44
+ IAnyObject
45
+ >
46
+ type TrivialOption = Options<IAnyObject, IAnyObject, IAnyObject, IAnyObject>
47
+ type Options<
48
+ TData extends DataOption,
49
+ TProperty extends PropertyOption,
50
+ TMethod extends MethodOption,
51
+ TCustomInstanceProperty extends IAnyObject = {},
52
+ TIsPage extends boolean = false
53
+ > = Partial<Data<TData>> &
54
+ Partial<Property<TProperty>> &
55
+ Partial<Method<TMethod, TIsPage>> &
56
+ Partial<OtherOption> &
57
+ Partial<Lifetimes> &
58
+ ThisType<
59
+ Instance<
60
+ TData,
61
+ TProperty,
62
+ TMethod,
63
+ TCustomInstanceProperty,
64
+ TIsPage
65
+ >
66
+ >
67
+ interface Constructor {
68
+ <
69
+ TData extends DataOption,
70
+ TProperty extends PropertyOption,
71
+ TMethod extends MethodOption,
72
+ TCustomInstanceProperty extends IAnyObject = {},
73
+ TIsPage extends boolean = false
74
+ >(
75
+ options: Options<
76
+ TData,
77
+ TProperty,
78
+ TMethod,
79
+ TCustomInstanceProperty,
80
+ TIsPage
81
+ >
82
+ ): string
83
+ }
84
+ type DataOption = Record<string, any>
85
+ type PropertyOption = Record<string, AllProperty>
86
+ type MethodOption = Record<string, Function>
87
+
88
+ interface Data<D extends DataOption> {
89
+ /** 组件的内部数据,和 `properties` 一同用于组件的模板渲染 */
90
+ data?: D
91
+ }
92
+ interface Property<P extends PropertyOption> {
93
+ /** 组件的对外属性,是属性名到属性设置的映射表 */
94
+ properties: P
95
+ }
96
+ interface Method<M extends MethodOption, TIsPage extends boolean = false> {
97
+ /** 组件的方法,包括事件响应函数和任意的自定义方法,关于事件响应函数的使用,参见 [组件间通信与事件](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/events.html) */
98
+ methods: M & (TIsPage extends true ? Partial<Page.ILifetime> : {})
99
+ }
100
+ type PropertyType =
101
+ | StringConstructor
102
+ | NumberConstructor
103
+ | BooleanConstructor
104
+ | ArrayConstructor
105
+ | ObjectConstructor
106
+ | null
107
+ type ValueType<T extends PropertyType> = T extends null
108
+ ? any
109
+ : T extends StringConstructor
110
+ ? string
111
+ : T extends NumberConstructor
112
+ ? number
113
+ : T extends BooleanConstructor
114
+ ? boolean
115
+ : T extends ArrayConstructor
116
+ ? any[]
117
+ : T extends ObjectConstructor
118
+ ? IAnyObject
119
+ : never
120
+ type FullProperty<T extends PropertyType> = {
121
+ /** 属性类型 */
122
+ type: T
123
+ /** 属性初始值 */
124
+ value?: ValueType<T>
125
+ /** 属性值被更改时的响应函数 */
126
+ observer?:
127
+ | string
128
+ | ((
129
+ newVal: ValueType<T>,
130
+ oldVal: ValueType<T>,
131
+ changedPath: Array<string | number>
132
+ ) => void)
133
+ /** 属性的类型(可以指定多个) */
134
+ optionalTypes?: ShortProperty[]
135
+ }
136
+ type AllFullProperty =
137
+ | FullProperty<StringConstructor>
138
+ | FullProperty<NumberConstructor>
139
+ | FullProperty<BooleanConstructor>
140
+ | FullProperty<ArrayConstructor>
141
+ | FullProperty<ObjectConstructor>
142
+ | FullProperty<null>
143
+ type ShortProperty =
144
+ | StringConstructor
145
+ | NumberConstructor
146
+ | BooleanConstructor
147
+ | ArrayConstructor
148
+ | ObjectConstructor
149
+ | null
150
+ type AllProperty = AllFullProperty | ShortProperty
151
+ type PropertyToData<T extends AllProperty> = T extends ShortProperty
152
+ ? ValueType<T>
153
+ : FullPropertyToData<Exclude<T, ShortProperty>>
154
+ type FullPropertyToData<T extends AllFullProperty> = ValueType<T['type']>
155
+ // type FullPropertyToData<T extends AllFullProperty> = unknown extends T['value'] ? ValueType<T['type']> : T['value']
156
+ type PropertyOptionToData<P extends PropertyOption> = {
157
+ [name in keyof P]: PropertyToData<P[name]>
158
+ }
159
+
160
+ interface InstanceProperties {
161
+ /** 组件的文件路径 */
162
+ is: string
163
+ /** 节点id */
164
+ id: string
165
+ /** 节点dataset */
166
+ dataset: Record<string, string>
167
+ }
168
+
169
+ interface InstanceMethods<D extends DataOption> {
170
+ /** `setData` 函数用于将数据从逻辑层发送到视图层
171
+ *(异步),同时改变对应的 `this.data` 的值(同步)。
172
+ *
173
+ * **注意:**
174
+ *
175
+ * 1. **直接修改 this.data 而不调用 this.setData 是无法改变页面的状态的,还会造成数据不一致**。
176
+ * 1. 仅支持设置可 JSON 化的数据。
177
+ * 1. 单次设置的数据不能超过1024kB,请尽量避免一次设置过多的数据。
178
+ * 1. 请不要把 data 中任何一项的 value 设为 `undefined` ,否则这一项将不被设置并可能遗留一些潜在问题。
179
+ */
180
+ setData(
181
+ /** 这次要改变的数据
182
+ *
183
+ * 以 `key: value` 的形式表示,将 `this.data` 中的 `key` 对应的值改变成 `value`。
184
+ *
185
+ * 其中 `key` 可以以数据路径的形式给出,支持改变数组中的某一项或对象的某个属性,如 `array[2].message`,`a.b.c.d`,并且不需要在 this.data 中预先定义。
186
+ */
187
+ data: Partial<D> & IAnyObject,
188
+ /** setData引起的界面更新渲染完毕后的回调函数,最低基础库: `1.5.0` */
189
+ callback?: () => void
190
+ ): void
191
+
192
+ /** 检查组件是否具有 `behavior` (检查时会递归检查被直接或间接引入的所有behavior) */
193
+ hasBehavior(behavior: Behavior.BehaviorIdentifier): void
194
+ /** 触发事件,参见组件事件 */
195
+ triggerEvent<DetailType = any>(
196
+ name: string,
197
+ detail?: DetailType,
198
+ options?: TriggerEventOption
199
+ ): void
200
+ /** 创建一个 SelectorQuery 对象,选择器选取范围为这个组件实例内 */
201
+ createSelectorQuery(): SelectorQuery
202
+ /** 创建一个 IntersectionObserver 对象,选择器选取范围为这个组件实例内 */
203
+ createIntersectionObserver(
204
+ options: CreateIntersectionObserverOption
205
+ ): IntersectionObserver
206
+ /** 使用选择器选择组件实例节点,返回匹配到的第一个组件实例对象(会被 `wx://component-export` 影响) */
207
+ selectComponent(selector: string): TrivialInstance
208
+ /** 使用选择器选择组件实例节点,返回匹配到的全部组件实例对象组成的数组 */
209
+ selectAllComponents(selector: string): TrivialInstance[]
210
+ /**
211
+ * 选取当前组件节点所在的组件实例(即组件的引用者),返回它的组件实例对象(会被 `wx://component-export` 影响)
212
+ *
213
+ * 最低基础库版本:[`2.8.2`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
214
+ **/
215
+ selectOwnerComponent(): TrivialInstance
216
+ /** 获取这个关系所对应的所有关联节点,参见 组件间关系 */
217
+ getRelationNodes(relationKey: string): TrivialInstance[]
218
+ /**
219
+ * 立刻执行 callback ,其中的多个 setData 之间不会触发界面绘制(只有某些特殊场景中需要,如用于在不同组件同时 setData 时进行界面绘制同步)
220
+ *
221
+ * 最低基础库版本:[`2.4.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
222
+ **/
223
+ groupSetData(callback?: () => void): void
224
+ /**
225
+ * 返回当前页面的 custom-tab-bar 的组件实例
226
+ *
227
+ * 最低基础库版本:[`2.6.2`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
228
+ **/
229
+ getTabBar(): TrivialInstance
230
+ /**
231
+ * 返回页面标识符(一个字符串),可以用来判断几个自定义组件实例是不是在同一个页面内
232
+ *
233
+ * 最低基础库版本:[`2.7.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
234
+ **/
235
+ getPageId(): string
236
+ /**
237
+ * 执行关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
238
+ *
239
+ * 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
240
+ **/
241
+ animate(
242
+ selector: string,
243
+ keyFrames: KeyFrame[],
244
+ duration: number,
245
+ callback?: () => void
246
+ ): void
247
+ /**
248
+ * 执行关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
249
+ *
250
+ * 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
251
+ **/
252
+ animate(
253
+ selector: string,
254
+ keyFrames: ScrollTimelineKeyframe[],
255
+ duration: number,
256
+ scrollTimeline: ScrollTimelineOption
257
+ ): void
258
+ /**
259
+ * 清除关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
260
+ *
261
+ * 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
262
+ **/
263
+ clearAnimation(selector: string, callback: () => void): void
264
+ /**
265
+ * 清除关键帧动画,详见[动画](https://developers.weixin.qq.com/miniprogram/dev/framework/view/animation.html)
266
+ *
267
+ * 最低基础库版本:[`2.9.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
268
+ **/
269
+ clearAnimation(
270
+ selector: string,
271
+ options?: ClearAnimationOptions,
272
+ callback?: () => void
273
+ ): void
274
+ /**
275
+ * 当从另一页面跳转到该页面时,获得与来源页面实例通信当事件通道,详见 [wx.navigateTo]((wx.navigateTo))
276
+ *
277
+ * 最低基础库版本:[`2.7.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
278
+ */
279
+ getOpenerEventChannel(): EventChannel
280
+ /**
281
+ * 获取更新性能统计信息,详见 [获取更新性能统计信息]((custom-component/update-perf-stat))
282
+ *
283
+ *
284
+ * 最低基础库版本:[`2.12.0`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
285
+ */
286
+ setUpdatePerformanceListener<WithDataPath extends boolean = false>(
287
+ options: SetUpdatePerformanceListenerOption<WithDataPath>,
288
+ callback?: UpdatePerformanceListener<WithDataPath>
289
+ ): void
290
+
291
+ /**
292
+ * 在运行时获取页面或组件所在页面 `touch` 相关事件的 passive 配置,详见 [enablePassiveEvent]((configuration/app#enablePassiveEvent))
293
+ *
294
+ * 最低基础库版本:[`2.25.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
295
+ */
296
+ getPassiveEvent(callback: (config: PassiveConfig) => void): void
297
+ /**
298
+ * 在运行时切换页面或组件所在页面 `touch` 相关事件的 passive 配置,详见 [enablePassiveEvent]((configuration/app#enablePassiveEvent))
299
+ *
300
+ * 最低基础库版本:[`2.25.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
301
+ */
302
+ setPassiveEvent(config: PassiveConfig): void
303
+ }
304
+
305
+ interface ComponentOptions {
306
+ /**
307
+ * [启用多slot支持](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件wxml的slot)
308
+ */
309
+ multipleSlots?: boolean
310
+ /**
311
+ * [组件样式隔离](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件样式隔离)
312
+ */
313
+ addGlobalClass?: boolean
314
+ /**
315
+ * [组件样式隔离](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#组件样式隔离)
316
+ */
317
+ styleIsolation?:
318
+ | 'isolated'
319
+ | 'apply-shared'
320
+ | 'shared'
321
+ | 'page-isolated'
322
+ | 'page-apply-shared'
323
+ | 'page-shared'
324
+ /**
325
+ * [纯数据字段](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/pure-data.html) 是一些不用于界面渲染的 data 字段,可以用于提升页面更新性能。从小程序基础库版本 2.8.2 开始支持。
326
+ */
327
+ pureDataPattern?: RegExp
328
+ /**
329
+ * [虚拟化组件节点](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html#%E8%99%9A%E6%8B%9F%E5%8C%96%E7%BB%84%E4%BB%B6%E8%8A%82%E7%82%B9) 使自定义组件内部的第一层节点由自定义组件本身完全决定。从小程序基础库版本 [`2.11.2`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) 开始支持 */
330
+ virtualHost?: boolean
331
+ }
332
+
333
+ interface TriggerEventOption {
334
+ /** 事件是否冒泡
335
+ *
336
+ * 默认值: `false`
337
+ */
338
+ bubbles?: boolean
339
+ /** 事件是否可以穿越组件边界,为false时,事件将只能在引用组件的节点树上触发,不进入其他任何组件内部
340
+ *
341
+ * 默认值: `false`
342
+ */
343
+ composed?: boolean
344
+ /** 事件是否拥有捕获阶段
345
+ *
346
+ * 默认值: `false`
347
+ */
348
+ capturePhase?: boolean
349
+ }
350
+
351
+ interface RelationOption {
352
+ /** 目标组件的相对关系 */
353
+ type: 'parent' | 'child' | 'ancestor' | 'descendant'
354
+ /** 关系生命周期函数,当关系被建立在页面节点树中时触发,触发时机在组件attached生命周期之后 */
355
+ linked?(target: TrivialInstance): void
356
+ /** 关系生命周期函数,当关系在页面节点树中发生改变时触发,触发时机在组件moved生命周期之后 */
357
+ linkChanged?(target: TrivialInstance): void
358
+ /** 关系生命周期函数,当关系脱离页面节点树时触发,触发时机在组件detached生命周期之后 */
359
+ unlinked?(target: TrivialInstance): void
360
+ /** 如果这一项被设置,则它表示关联的目标节点所应具有的behavior,所有拥有这一behavior的组件节点都会被关联 */
361
+ target?: string
362
+ }
363
+
364
+ interface PageLifetimes {
365
+ /** 页面生命周期回调—监听页面显示
366
+ *
367
+ * 页面显示/切入前台时触发。
368
+ */
369
+ show(): void
370
+ /** 页面生命周期回调—监听页面隐藏
371
+ *
372
+ * 页面隐藏/切入后台时触发。 如 `navigateTo` 或底部 `tab` 切换到其他页面,小程序切入后台等。
373
+ */
374
+ hide(): void
375
+ /** 页面生命周期回调—监听页面尺寸变化
376
+ *
377
+ * 所在页面尺寸变化时执行
378
+ */
379
+ resize(size: Page.IResizeOption): void
380
+ }
381
+
382
+ type DefinitionFilter = <T extends TrivialOption>(
383
+ /** 使用该 behavior 的 component/behavior 的定义对象 */
384
+ defFields: T,
385
+ /** 该 behavior 所使用的 behavior 的 definitionFilter 函数列表 */
386
+ definitionFilterArr?: DefinitionFilter[]
387
+ ) => void
388
+
389
+ interface Lifetimes {
390
+ /** 组件生命周期声明对象,组件的生命周期:`created`、`attached`、`ready`、`moved`、`detached` 将收归到 `lifetimes` 字段内进行声明,原有声明方式仍旧有效,如同时存在两种声明方式,则 `lifetimes` 字段内声明方式优先级最高
391
+ *
392
+ * 最低基础库: `2.2.3` */
393
+ lifetimes: Partial<{
394
+ /**
395
+ * 在组件实例刚刚被创建时执行,注意此时不能调用 `setData`
396
+ *
397
+ * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
398
+ */
399
+ created(): void
400
+ /**
401
+ * 在组件实例进入页面节点树时执行
402
+ *
403
+ * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
404
+ */
405
+ attached(): void
406
+ /**
407
+ * 在组件在视图层布局完成后执行
408
+ *
409
+ * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
410
+ */
411
+ ready(): void
412
+ /**
413
+ * 在组件实例被移动到节点树另一个位置时执行
414
+ *
415
+ * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
416
+ */
417
+ moved(): void
418
+ /**
419
+ * 在组件实例被从页面节点树移除时执行
420
+ *
421
+ * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
422
+ */
423
+ detached(): void
424
+ /**
425
+ * 每当组件方法抛出错误时执行
426
+ *
427
+ * 最低基础库版本:[`2.4.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
428
+ */
429
+ error(err: Error): void
430
+ }>
431
+ /**
432
+ * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
433
+ *
434
+ * 在组件实例刚刚被创建时执行
435
+ *
436
+ * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
437
+ */
438
+ created(): void
439
+ /**
440
+ * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
441
+ *
442
+ * 在组件实例进入页面节点树时执行
443
+ *
444
+ * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
445
+ */
446
+ attached(): void
447
+ /**
448
+ * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
449
+ *
450
+ * 在组件在视图层布局完成后执行
451
+ *
452
+ * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
453
+ */
454
+ ready(): void
455
+ /**
456
+ * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
457
+ *
458
+ * 在组件实例被移动到节点树另一个位置时执行
459
+ *
460
+ * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
461
+ */
462
+ moved(): void
463
+ /**
464
+ * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
465
+ *
466
+ * 在组件实例被从页面节点树移除时执行
467
+ *
468
+ * 最低基础库版本:[`1.6.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
469
+ */
470
+ detached(): void
471
+ /**
472
+ * @deprecated 旧式的定义方式,基础库 `2.2.3` 起请在 lifetimes 中定义
473
+ *
474
+ * 每当组件方法抛出错误时执行
475
+ *
476
+ * 最低基础库版本:[`2.4.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
477
+ */
478
+ error(err: Error): void
479
+ }
480
+
481
+ interface OtherOption {
482
+ /** 类似于mixins和traits的组件间代码复用机制,参见 [behaviors](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/behaviors.html) */
483
+ behaviors: Behavior.BehaviorIdentifier[]
484
+ /**
485
+ * 组件数据字段监听器,用于监听 properties 和 data 的变化,参见 [数据监听器](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/observer.html)
486
+ *
487
+ * 最低基础库版本:[`2.6.1`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html)
488
+ */
489
+ observers: Record<string, (...args: any[]) => any>
490
+ /** 组件间关系定义,参见 [组件间关系](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/lifetimes.html) */
491
+ relations: {
492
+ [componentName: string]: RelationOption
493
+ }
494
+ /** 组件接受的外部样式类,参见 [外部样式类](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html) */
495
+ externalClasses?: string[]
496
+ /** 组件所在页面的生命周期声明对象,参见 [组件生命周期](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/lifetimes.html)
497
+ *
498
+ * 最低基础库版本: [`2.2.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) */
499
+ pageLifetimes?: Partial<PageLifetimes>
500
+ /** 一些选项(文档中介绍相关特性时会涉及具体的选项设置,这里暂不列举) */
501
+ options: ComponentOptions
502
+
503
+ /** 定义段过滤器,用于自定义组件扩展,参见 [自定义组件扩展](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/extend.html)
504
+ *
505
+ * 最低基础库版本: [`2.2.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) */
506
+ definitionFilter?: DefinitionFilter
507
+ /**
508
+ * 组件自定义导出,当使用 `behavior: wx://component-export` 时,这个定义段可以用于指定组件被 selectComponent 调用时的返回值,参见 [组件间通信与事件](https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/events.html)
509
+ * 最低基础库版本: [`2.2.3`](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) */
510
+ export: () => IAnyObject
511
+ }
512
+
513
+ interface KeyFrame {
514
+ /** 关键帧的偏移,范围[0-1] */
515
+ offset?: number
516
+ /** 动画缓动函数 */
517
+ ease?: string
518
+ /** 基点位置,即 CSS transform-origin */
519
+ transformOrigin?: string
520
+ /** 背景颜色,即 CSS background-color */
521
+ backgroundColor?: string
522
+ /** 底边位置,即 CSS bottom */
523
+ bottom?: number | string
524
+ /** 高度,即 CSS height */
525
+ height?: number | string
526
+ /** 左边位置,即 CSS left */
527
+ left?: number | string
528
+ /** 宽度,即 CSS width */
529
+ width?: number | string
530
+ /** 不透明度,即 CSS opacity */
531
+ opacity?: number | string
532
+ /** 右边位置,即 CSS right */
533
+ right?: number | string
534
+ /** 顶边位置,即 CSS top */
535
+ top?: number | string
536
+ /** 变换矩阵,即 CSS transform matrix */
537
+ matrix?: number[]
538
+ /** 三维变换矩阵,即 CSS transform matrix3d */
539
+ matrix3d?: number[]
540
+ /** 旋转,即 CSS transform rotate */
541
+ rotate?: number
542
+ /** 三维旋转,即 CSS transform rotate3d */
543
+ rotate3d?: number[]
544
+ /** X 方向旋转,即 CSS transform rotateX */
545
+ rotateX?: number
546
+ /** Y 方向旋转,即 CSS transform rotateY */
547
+ rotateY?: number
548
+ /** Z 方向旋转,即 CSS transform rotateZ */
549
+ rotateZ?: number
550
+ /** 缩放,即 CSS transform scale */
551
+ scale?: number[]
552
+ /** 三维缩放,即 CSS transform scale3d */
553
+ scale3d?: number[]
554
+ /** X 方向缩放,即 CSS transform scaleX */
555
+ scaleX?: number
556
+ /** Y 方向缩放,即 CSS transform scaleY */
557
+ scaleY?: number
558
+ /** Z 方向缩放,即 CSS transform scaleZ */
559
+ scaleZ?: number
560
+ /** 倾斜,即 CSS transform skew */
561
+ skew?: number[]
562
+ /** X 方向倾斜,即 CSS transform skewX */
563
+ skewX?: number
564
+ /** Y 方向倾斜,即 CSS transform skewY */
565
+ skewY?: number
566
+ /** 位移,即 CSS transform translate */
567
+ translate?: Array<number | string>
568
+ /** 三维位移,即 CSS transform translate3d */
569
+ translate3d?: Array<number | string>
570
+ /** X 方向位移,即 CSS transform translateX */
571
+ translateX?: number | string
572
+ /** Y 方向位移,即 CSS transform translateY */
573
+ translateY?: number | string
574
+ /** Z 方向位移,即 CSS transform translateZ */
575
+ translateZ?: number | string
576
+ }
577
+ interface ClearAnimationOptions {
578
+ /** 基点位置,即 CSS transform-origin */
579
+ transformOrigin?: boolean
580
+ /** 背景颜色,即 CSS background-color */
581
+ backgroundColor?: boolean
582
+ /** 底边位置,即 CSS bottom */
583
+ bottom?: boolean
584
+ /** 高度,即 CSS height */
585
+ height?: boolean
586
+ /** 左边位置,即 CSS left */
587
+ left?: boolean
588
+ /** 宽度,即 CSS width */
589
+ width?: boolean
590
+ /** 不透明度,即 CSS opacity */
591
+ opacity?: boolean
592
+ /** 右边位置,即 CSS right */
593
+ right?: boolean
594
+ /** 顶边位置,即 CSS top */
595
+ top?: boolean
596
+ /** 变换矩阵,即 CSS transform matrix */
597
+ matrix?: boolean
598
+ /** 三维变换矩阵,即 CSS transform matrix3d */
599
+ matrix3d?: boolean
600
+ /** 旋转,即 CSS transform rotate */
601
+ rotate?: boolean
602
+ /** 三维旋转,即 CSS transform rotate3d */
603
+ rotate3d?: boolean
604
+ /** X 方向旋转,即 CSS transform rotateX */
605
+ rotateX?: boolean
606
+ /** Y 方向旋转,即 CSS transform rotateY */
607
+ rotateY?: boolean
608
+ /** Z 方向旋转,即 CSS transform rotateZ */
609
+ rotateZ?: boolean
610
+ /** 缩放,即 CSS transform scale */
611
+ scale?: boolean
612
+ /** 三维缩放,即 CSS transform scale3d */
613
+ scale3d?: boolean
614
+ /** X 方向缩放,即 CSS transform scaleX */
615
+ scaleX?: boolean
616
+ /** Y 方向缩放,即 CSS transform scaleY */
617
+ scaleY?: boolean
618
+ /** Z 方向缩放,即 CSS transform scaleZ */
619
+ scaleZ?: boolean
620
+ /** 倾斜,即 CSS transform skew */
621
+ skew?: boolean
622
+ /** X 方向倾斜,即 CSS transform skewX */
623
+ skewX?: boolean
624
+ /** Y 方向倾斜,即 CSS transform skewY */
625
+ skewY?: boolean
626
+ /** 位移,即 CSS transform translate */
627
+ translate?: boolean
628
+ /** 三维位移,即 CSS transform translate3d */
629
+ translate3d?: boolean
630
+ /** X 方向位移,即 CSS transform translateX */
631
+ translateX?: boolean
632
+ /** Y 方向位移,即 CSS transform translateY */
633
+ translateY?: boolean
634
+ /** Z 方向位移,即 CSS transform translateZ */
635
+ translateZ?: boolean
636
+ }
637
+ interface ScrollTimelineKeyframe {
638
+ composite?: 'replace' | 'add' | 'accumulate' | 'auto'
639
+ easing?: string
640
+ offset?: number | null
641
+ [property: string]: string | number | null | undefined
642
+ }
643
+ interface ScrollTimelineOption {
644
+ /** 指定滚动元素的选择器(只支持 scroll-view),该元素滚动时会驱动动画的进度 */
645
+ scrollSource: string
646
+ /** 指定滚动的方向。有效值为 horizontal 或 vertical */
647
+ orientation?: string
648
+ /** 指定开始驱动动画进度的滚动偏移量,单位 px */
649
+ startScrollOffset: number
650
+ /** 指定停止驱动动画进度的滚动偏移量,单位 px */
651
+ endScrollOffset: number
652
+ /** 起始和结束的滚动范围映射的时间长度,该时间可用于与关键帧动画里的时间 (duration) 相匹配,单位 ms */
653
+ timeRange: number
654
+ }
655
+
656
+ interface SetUpdatePerformanceListenerOption<WithDataPath> {
657
+ /** 是否返回变更的 data 字段信息 */
658
+ withDataPaths?: WithDataPath
659
+ }
660
+ interface UpdatePerformanceListener<WithDataPath> {
661
+ (res: UpdatePerformance<WithDataPath>): void
662
+ }
663
+ interface UpdatePerformance<WithDataPath> {
664
+ /** 此次更新过程的 ID */
665
+ updateProcessId: number
666
+ /** 对于子更新,返回它所属的更新过程 ID */
667
+ parentUpdateProcessId?: number
668
+ /** 是否是被合并更新,如果是,则 updateProcessId 表示被合并到的更新过程 ID */
669
+ isMergedUpdate: boolean
670
+ /** 此次更新的 data 字段信息,只有 withDataPaths 设为 true 时才会返回 */
671
+ dataPaths: WithDataPath extends true ? string[] : undefined
672
+ /** 此次更新进入等待队列时的时间戳 */
673
+ pendingStartTimestamp: number
674
+ /** 更新运算开始时的时间戳 */
675
+ updateStartTimestamp: number
676
+ /** 更新运算结束时的时间戳 */
677
+ updateEndTimestamp: number
678
+ }
679
+
680
+ type PassiveConfig =
681
+ | {
682
+ /** 是否设置 touchmove 事件为 passive,默认为 `false` */
683
+ touchmove?: boolean
684
+ /** 是否设置 touchstart 事件为 passive,默认为 `false` */
685
+ touchstart?: boolean
686
+ /** 是否设置 wheel 事件为 passive,默认为 `false` */
687
+ wheel?: boolean
688
+ }
689
+ | boolean
690
+ }
691
+ /** Component构造器可用于定义组件,调用Component构造器时可以指定组件的属性、数据、方法等。
692
+ *
693
+ * * 使用 `this.data` 可以获取内部数据和属性值,但不要直接修改它们,应使用 `setData` 修改。
694
+ * * 生命周期函数无法在组件方法中通过 `this` 访问到。
695
+ * * 属性名应避免以 data 开头,即不要命名成 `dataXyz` 这样的形式,因为在 WXML 中, `data-xyz=""` 会被作为节点 dataset 来处理,而不是组件属性。
696
+ * * 在一个组件的定义和使用时,组件的属性名和 data 字段相互间都不能冲突(尽管它们位于不同的定义段中)。
697
+ * * 从基础库 `2.0.9` 开始,对象类型的属性和 data 字段中可以包含函数类型的子字段,即可以通过对象类型的属性字段来传递函数。低于这一版本的基础库不支持这一特性。
698
+ * * `bug` : 对于 type 为 Object 或 Array 的属性,如果通过该组件自身的 `this.setData` 来改变属性值的一个子字段,则依旧会触发属性 observer ,且 observer 接收到的 `newVal` 是变化的那个子字段的值, `oldVal` 为空, `changedPath` 包含子字段的字段名相关信息。
699
+ */
700
+ declare let Component: WechatMiniprogram.Component.Constructor