@lynx-js/react 0.108.0 → 0.109.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 (98) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/package.json +4 -4
  3. package/refresh/.turbo/turbo-build.log +1 -1
  4. package/runtime/jsx-dev-runtime/index.d.ts +13 -7
  5. package/runtime/jsx-runtime/index.d.ts +17 -7
  6. package/runtime/lib/gesture/processGesture.d.ts +2 -2
  7. package/runtime/lib/gesture/processGesture.js +14 -7
  8. package/runtime/lib/gesture/processGesture.js.map +1 -1
  9. package/runtime/lib/lifecycle/patch/isMainThreadHydrationFinished.d.ts +2 -0
  10. package/runtime/lib/lifecycle/patch/isMainThreadHydrationFinished.js +9 -0
  11. package/runtime/lib/lifecycle/patch/isMainThreadHydrationFinished.js.map +1 -0
  12. package/runtime/lib/lifecycle/patch/snapshotPatchApply.js +2 -2
  13. package/runtime/lib/lifecycle/patch/snapshotPatchApply.js.map +1 -1
  14. package/runtime/lib/lifecycle/patch/updateMainThread.js +4 -3
  15. package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -1
  16. package/runtime/lib/lifecycle/reload.js +2 -0
  17. package/runtime/lib/lifecycle/reload.js.map +1 -1
  18. package/runtime/lib/snapshot/gesture.d.ts +1 -1
  19. package/runtime/lib/snapshot/gesture.js +4 -3
  20. package/runtime/lib/snapshot/gesture.js.map +1 -1
  21. package/runtime/lib/snapshot/ref.js.map +1 -1
  22. package/runtime/lib/snapshot/spread.d.ts +0 -6
  23. package/runtime/lib/snapshot/spread.js +4 -10
  24. package/runtime/lib/snapshot/spread.js.map +1 -1
  25. package/runtime/lib/snapshot/workletEvent.d.ts +2 -1
  26. package/runtime/lib/snapshot/workletEvent.js +4 -3
  27. package/runtime/lib/snapshot/workletEvent.js.map +1 -1
  28. package/runtime/lib/snapshot/workletRef.d.ts +4 -4
  29. package/runtime/lib/snapshot/workletRef.js +6 -4
  30. package/runtime/lib/snapshot/workletRef.js.map +1 -1
  31. package/runtime/lib/snapshot.d.ts +1 -0
  32. package/runtime/lib/snapshot.js +5 -4
  33. package/runtime/lib/snapshot.js.map +1 -1
  34. package/runtime/lib/worklet/runOnBackground.js +21 -12
  35. package/runtime/lib/worklet/runOnBackground.js.map +1 -1
  36. package/runtime/lib/worklet/workletRef.d.ts +1 -0
  37. package/runtime/lib/worklet/workletRef.js +14 -12
  38. package/runtime/lib/worklet/workletRef.js.map +1 -1
  39. package/runtime/src/gesture/processGesture.ts +23 -15
  40. package/runtime/src/lifecycle/patch/isMainThreadHydrationFinished.ts +10 -0
  41. package/runtime/src/lifecycle/patch/snapshotPatchApply.ts +8 -2
  42. package/runtime/src/lifecycle/patch/updateMainThread.ts +4 -3
  43. package/runtime/src/lifecycle/reload.ts +2 -0
  44. package/runtime/src/snapshot/gesture.ts +6 -4
  45. package/runtime/src/snapshot/ref.ts +2 -2
  46. package/runtime/src/snapshot/spread.ts +15 -5
  47. package/runtime/src/snapshot/workletEvent.ts +5 -3
  48. package/runtime/src/snapshot/workletRef.ts +17 -18
  49. package/runtime/src/snapshot.ts +6 -4
  50. package/runtime/src/worklet/runOnBackground.ts +37 -15
  51. package/runtime/src/worklet/workletRef.ts +15 -12
  52. package/testing-library/dist/vitest-global-setup.js +7 -0
  53. package/transform/dist/wasm.cjs +1 -1
  54. package/transform/index.d.ts +443 -14
  55. package/types/react.d.ts +1 -1
  56. package/worklet-runtime/dist/dev.js +133 -33
  57. package/worklet-runtime/dist/dev.js.map +4 -4
  58. package/worklet-runtime/dist/main.js +133 -33
  59. package/worklet-runtime/dist/main.js.map +4 -4
  60. package/worklet-runtime/lib/api/element.d.ts +3 -3
  61. package/worklet-runtime/lib/api/element.js +3 -3
  62. package/worklet-runtime/lib/api/element.js.map +1 -1
  63. package/worklet-runtime/lib/api/lepusQuerySelector.js +1 -3
  64. package/worklet-runtime/lib/api/lepusQuerySelector.js.map +1 -1
  65. package/worklet-runtime/lib/api/lynxApi.js +10 -10
  66. package/worklet-runtime/lib/api/lynxApi.js.map +1 -1
  67. package/worklet-runtime/lib/bindings/bindings.d.ts +1 -1
  68. package/worklet-runtime/lib/bindings/bindings.js +21 -8
  69. package/worklet-runtime/lib/bindings/bindings.js.map +1 -1
  70. package/worklet-runtime/lib/bindings/events.d.ts +4 -1
  71. package/worklet-runtime/lib/bindings/events.js.map +1 -1
  72. package/worklet-runtime/lib/bindings/index.d.ts +1 -1
  73. package/worklet-runtime/lib/bindings/index.js +1 -1
  74. package/worklet-runtime/lib/bindings/index.js.map +1 -1
  75. package/worklet-runtime/lib/bindings/loadRuntime.js +0 -2
  76. package/worklet-runtime/lib/bindings/loadRuntime.js.map +1 -1
  77. package/worklet-runtime/lib/bindings/types.d.ts +15 -5
  78. package/worklet-runtime/lib/bindings/types.js +3 -0
  79. package/worklet-runtime/lib/bindings/types.js.map +1 -1
  80. package/worklet-runtime/lib/delayRunOnBackground.d.ts +12 -0
  81. package/worklet-runtime/lib/delayRunOnBackground.js +23 -0
  82. package/worklet-runtime/lib/delayRunOnBackground.js.map +1 -0
  83. package/worklet-runtime/lib/delayWorkletEvent.js +2 -2
  84. package/worklet-runtime/lib/delayWorkletEvent.js.map +1 -1
  85. package/worklet-runtime/lib/global.d.ts +6 -3
  86. package/worklet-runtime/lib/hydrate.d.ts +11 -0
  87. package/worklet-runtime/lib/hydrate.js +86 -0
  88. package/worklet-runtime/lib/hydrate.js.map +1 -0
  89. package/worklet-runtime/lib/jsFunctionLifecycle.js +2 -2
  90. package/worklet-runtime/lib/jsFunctionLifecycle.js.map +1 -1
  91. package/worklet-runtime/lib/listeners.js.map +1 -1
  92. package/worklet-runtime/lib/utils/profile.d.ts +1 -1
  93. package/worklet-runtime/lib/utils/version.js +1 -1
  94. package/worklet-runtime/lib/workletRef.d.ts +6 -3
  95. package/worklet-runtime/lib/workletRef.js +33 -6
  96. package/worklet-runtime/lib/workletRef.js.map +1 -1
  97. package/worklet-runtime/lib/workletRuntime.js +12 -14
  98. package/worklet-runtime/lib/workletRuntime.js.map +1 -1
@@ -45,41 +45,314 @@ export interface PartialLocation {
45
45
  suggestion?: string
46
46
  }
47
47
  export interface DarkModeConfig {
48
- /** @public */
48
+ /**
49
+ * @public
50
+ * Theme expression to be used for dark mode
51
+ */
49
52
  themeExpr: string
50
53
  }
54
+ /**
55
+ * {@inheritdoc CompatVisitorConfig.addComponentElement}
56
+ * @public
57
+ */
51
58
  export interface AddComponentElementConfig {
52
- /** @public */
59
+ /**
60
+ * @public
61
+ * Whether to only add component element during compilation
62
+ *
63
+ * @example
64
+ *
65
+ * Note that this only take effects on `Component` imported from {@link CompatVisitorConfig.oldRuntimePkg}.
66
+ *
67
+ * ```js
68
+ * import { defineConfig } from '@lynx-js/rspeedy'
69
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
70
+ *
71
+ * export default defineConfig({
72
+ * plugins: [
73
+ * pluginReactLynx({
74
+ * compat: {
75
+ * addComponentElement: { compilerOnly: true }
76
+ * },
77
+ * })
78
+ * ],
79
+ * })
80
+ * ```
81
+ */
53
82
  compilerOnly: boolean
54
83
  }
84
+ /**
85
+ * {@inheritdoc PluginReactLynxOptions.compat}
86
+ * @public
87
+ */
55
88
  export interface CompatVisitorConfig {
56
89
  /** @internal */
57
90
  target: 'LEPUS' | 'JS' | 'MIXED'
58
- /** @public */
91
+ /**
92
+ * @public
93
+ * Specifies the list of component package names that need compatibility processing
94
+ *
95
+ * @remarks
96
+ * Default value: `['@lynx-js/react-components']`
97
+ *
98
+ * @example
99
+ *
100
+ * ```js
101
+ * import { defineConfig } from '@lynx-js/rspeedy'
102
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
103
+ *
104
+ * export default defineConfig({
105
+ * plugins: [
106
+ * pluginReactLynx({
107
+ * compat: {
108
+ * componentsPkg: ['@my-org/components', '@legacy/ui-kit']
109
+ * },
110
+ * })
111
+ * ],
112
+ * })
113
+ * ```
114
+ */
59
115
  componentsPkg: Array<string>
60
- /** @public */
116
+ /**
117
+ * @public
118
+ * Specifies the list of old runtime package names that need compatibility processing
119
+ *
120
+ * @remarks
121
+ * Default value: `['@lynx-js/react-runtime']`
122
+ *
123
+ * @example
124
+ *
125
+ * ```js
126
+ * import { defineConfig } from '@lynx-js/rspeedy'
127
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
128
+ *
129
+ * export default defineConfig({
130
+ * plugins: [
131
+ * pluginReactLynx({
132
+ * compat: {
133
+ * oldRuntimePkg: ['@my-org/runtime', '@legacy/runtime']
134
+ * },
135
+ * })
136
+ * ],
137
+ * })
138
+ * ```
139
+ */
61
140
  oldRuntimePkg: Array<string>
62
- /** @public */
141
+ /**
142
+ * @public
143
+ * Specifies the new runtime package name
144
+ *
145
+ * @remarks
146
+ * Default value: `'@lynx-js/react'`
147
+ *
148
+ * @example
149
+ *
150
+ * ```js
151
+ * import { defineConfig } from '@lynx-js/rspeedy'
152
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
153
+ *
154
+ * export default defineConfig({
155
+ * plugins: [
156
+ * pluginReactLynx({
157
+ * compat: {
158
+ * newRuntimePkg: '@my-org/react'
159
+ * },
160
+ * })
161
+ * ],
162
+ * })
163
+ * ```
164
+ */
63
165
  newRuntimePkg: string
64
- /** @public */
166
+ /**
167
+ * @public
168
+ * Specifies additional component attributes list, these attributes will be passed to the wrapped `<view>` instead of the component.
169
+ *
170
+ * @remarks
171
+ * This only takes effect when {@link CompatVisitorConfig.addComponentElement} is enabled.
172
+ *
173
+ * Default value: `[]`
174
+ *
175
+ * @example
176
+ *
177
+ * ```js
178
+ * import { defineConfig } from '@lynx-js/rspeedy'
179
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
180
+ *
181
+ * export default defineConfig({
182
+ * plugins: [
183
+ * pluginReactLynx({
184
+ * compat: {
185
+ * additionalComponentAttributes: ['custom-attr', 'data-special']
186
+ * },
187
+ * })
188
+ * ],
189
+ * })
190
+ * ```
191
+ */
65
192
  additionalComponentAttributes: Array<string>
66
- /** @public */
193
+ /**
194
+ * @public
195
+ * Controls whether to add wrapper elements for components
196
+ *
197
+ * @remarks
198
+ * Default value: `false`
199
+ *
200
+ * @example
201
+ *
202
+ * Add a `<view>` wrapper element for all components during runtime.
203
+ *
204
+ * ```js
205
+ * import { defineConfig } from '@lynx-js/rspeedy'
206
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
207
+ *
208
+ * export default defineConfig({
209
+ * plugins: [
210
+ * pluginReactLynx({
211
+ * compat: {
212
+ * addComponentElement: true
213
+ * },
214
+ * })
215
+ * ],
216
+ * })
217
+ * ```
218
+ *
219
+ * @example
220
+ *
221
+ * Only add component element during compilation.
222
+ * Note that this only take effects on `Component` imported from {@link CompatVisitorConfig.oldRuntimePkg}.
223
+ *
224
+ * ```js
225
+ * import { defineConfig } from '@lynx-js/rspeedy'
226
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
227
+ *
228
+ * export default defineConfig({
229
+ * plugins: [
230
+ * pluginReactLynx({
231
+ * compat: {
232
+ * addComponentElement: { compilerOnly: true }
233
+ * },
234
+ * })
235
+ * ],
236
+ * })
237
+ * ```
238
+ */
67
239
  addComponentElement: boolean | AddComponentElementConfig
68
240
  /**
69
241
  * @public
242
+ * Whether to simplify constructor calls like ReactLynx 2
243
+ *
70
244
  * @deprecated
245
+ * Using `simplifyCtorLikeReactLynx2` is not recommended as it introduces implicit behaviors that can:
246
+ *
247
+ * - Make code harder to understand and maintain
248
+ *
249
+ * - Create hidden dependencies between components
250
+ *
251
+ * - Complicate debugging and testing processes
252
+ *
253
+ * Instead, use `background-only` on class methods for explicit and maintainable behavior
254
+ *
255
+ * @remarks
256
+ * Default value: `false`
257
+ *
258
+ * @example
259
+ *
260
+ * ```js
261
+ * import { defineConfig } from '@lynx-js/rspeedy'
262
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
263
+ *
264
+ * export default defineConfig({
265
+ * plugins: [
266
+ * pluginReactLynx({
267
+ * compat: {
268
+ * simplifyCtorLikeReactLynx2: true
269
+ * },
270
+ * })
271
+ * ],
272
+ * })
273
+ * ```
71
274
  */
72
275
  simplifyCtorLikeReactLynx2: boolean
73
276
  /**
74
277
  * @public
75
- * @deprecated
278
+ * Regular expression used to remove component attributes
279
+ *
280
+ * @deprecated It's recommended to use `background-only`.
281
+ *
282
+ * If your code depends on this switch, when distributing it to other projects through npm packages or other means, you'll also need to enable this switch. This will lead to the proliferation of switches, which is not conducive to code reuse between different projects.
283
+ *
284
+ * @remarks
285
+ * Default value: `None`
286
+ *
287
+ * @example
288
+ *
289
+ * ```js
290
+ * import { defineConfig } from '@lynx-js/rspeedy'
291
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
292
+ *
293
+ * export default defineConfig({
294
+ * plugins: [
295
+ * pluginReactLynx({
296
+ * compat: {
297
+ * removeComponentAttrRegex: '^data-test-'
298
+ * },
299
+ * })
300
+ * ],
301
+ * })
302
+ * ```
76
303
  */
77
304
  removeComponentAttrRegex?: string
78
- /** @public */
305
+ /**
306
+ * @public
307
+ * Whether to disable deprecated warnings
308
+ *
309
+ * @remarks
310
+ * Default value: `false`
311
+ *
312
+ * @example
313
+ *
314
+ * Disable all the `DEPRECATED:` warnings.
315
+ *
316
+ * ```js
317
+ * import { defineConfig } from '@lynx-js/rspeedy'
318
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
319
+ *
320
+ * export default defineConfig({
321
+ * plugins: [
322
+ * pluginReactLynx({
323
+ * compat: {
324
+ * disableDeprecatedWarning: true
325
+ * },
326
+ * })
327
+ * ],
328
+ * })
329
+ * ```
330
+ */
79
331
  disableDeprecatedWarning: boolean
80
332
  /**
81
333
  * @public
82
334
  * @deprecated
335
+ * Dark mode configuration
336
+ *
337
+ * @remarks
338
+ * Default value: `None`
339
+ *
340
+ * @example
341
+ *
342
+ * ```js
343
+ * import { defineConfig } from '@lynx-js/rspeedy'
344
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
345
+ *
346
+ * export default defineConfig({
347
+ * plugins: [
348
+ * pluginReactLynx({
349
+ * compat: {
350
+ * darkMode: true
351
+ * },
352
+ * })
353
+ * ],
354
+ * })
355
+ * ```
83
356
  */
84
357
  darkMode?: boolean | DarkModeConfig
85
358
  }
@@ -89,8 +362,57 @@ export interface CssScopeVisitorConfig {
89
362
  /** @public */
90
363
  filename: string
91
364
  }
365
+ /**
366
+ * {@inheritdoc PluginReactLynxOptions.defineDCE}
367
+ * @public
368
+ */
92
369
  export interface DefineDceVisitorConfig {
93
- /** @public */
370
+ /**
371
+ * @public
372
+ * Replaces variables in your code with other values or expressions at compile time.
373
+ *
374
+ * @remarks
375
+ * Caveat: differences between `source.define`
376
+ *
377
+ * `defineDCE` happens before transforming `background-only` directives.
378
+ * So it's useful for eliminating code that is only used in the background from main-thread.
379
+ *
380
+ * @example
381
+ *
382
+ * ```js
383
+ * import { defineConfig } from '@lynx-js/rspeedy'
384
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
385
+ *
386
+ * export default defineConfig({
387
+ * plugins: [
388
+ * pluginReactLynx({
389
+ * defineDCE: {
390
+ * define: {
391
+ * __FOO__: 'false',
392
+ * 'process.env.PLATFORM': '"lynx"',
393
+ * },
394
+ * },
395
+ * })
396
+ * ],
397
+ * })
398
+ * ```
399
+ *
400
+ * Then, `__FOO__` and `process.env.PLATFORM` could be used in source code.
401
+ *
402
+ * ```
403
+ * if (process.env.PLATFORM === 'lynx') {
404
+ * console.log('lynx')
405
+ * }
406
+ *
407
+ * function FooOrBar() {
408
+ * if (__FOO__) {
409
+ * return <text>foo</text>
410
+ * } else {
411
+ * return <text>bar</text>
412
+ * }
413
+ * }
414
+ * ```
415
+ */
94
416
  define: Record<string, string>
95
417
  }
96
418
  export interface DirectiveDceVisitorConfig {
@@ -103,8 +425,35 @@ export interface DynamicImportVisitorConfig {
103
425
  /** @internal */
104
426
  layer: string
105
427
  }
428
+ /**
429
+ * {@inheritdoc PluginReactLynxOptions.extractStr}
430
+ * @public
431
+ */
106
432
  export interface ExtractStrConfig {
107
- /** @public */
433
+ /**
434
+ * @public
435
+ * The minimum length of string literals to be extracted.
436
+ *
437
+ * @remarks
438
+ * Default value: `20`.
439
+ *
440
+ * @example
441
+ *
442
+ * ```js
443
+ * import { defineConfig } from '@lynx-js/rspeedy'
444
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
445
+ *
446
+ * export default defineConfig({
447
+ * plugins: [
448
+ * pluginReactLynx({
449
+ * extractStr: {
450
+ * strLength: 10,
451
+ * },
452
+ * })
453
+ * ],
454
+ * })
455
+ * ```
456
+ */
108
457
  strLength: number
109
458
  /** @internal */
110
459
  extractedStrArr?: Array<string>
@@ -115,18 +464,98 @@ export interface InjectVisitorConfig {
115
464
  export interface RefreshVisitorConfig {
116
465
  library?: Array<string>
117
466
  }
467
+ /**
468
+ * {@inheritdoc PluginReactLynxOptions.shake}
469
+ * @public
470
+ */
118
471
  export interface ShakeVisitorConfig {
119
- /** @public */
472
+ /**
473
+ * Package names to identify runtime imports that need to be processed
474
+ *
475
+ * @example
476
+ * ```js
477
+ * import { defineConfig } from '@lynx-js/rspeedy'
478
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
479
+ *
480
+ * export default defineConfig({
481
+ * plugins: [
482
+ * pluginReactLynx({
483
+ * shake: {
484
+ * pkgName: ['@lynx-js/react-runtime']
485
+ * }
486
+ * })
487
+ * ]
488
+ * })
489
+ * ```
490
+ *
491
+ * @remarks
492
+ * Default value: `['@lynx-js/react-runtime']`
493
+ * The provided values will be merged with the default values instead of replacing them.
494
+ * @public
495
+ */
120
496
  pkgName: Array<string>
121
- /** @public */
497
+ /**
498
+ * Properties that should be retained in the component class
499
+ *
500
+ * @example
501
+ * ```js
502
+ * import { defineConfig } from '@lynx-js/rspeedy'
503
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
504
+ *
505
+ * export default defineConfig({
506
+ * plugins: [
507
+ * pluginReactLynx({
508
+ * shake: {
509
+ * retainProp: ['myCustomMethod']
510
+ * }
511
+ * })
512
+ * ]
513
+ * })
514
+ * ```
515
+ *
516
+ * @remarks
517
+ * Default value: `['constructor', 'render', 'getDerivedStateFromProps', 'state', 'defaultDataProcessor', 'dataProcessors', 'contextType', 'defaultProps']`
518
+ * The provided values will be merged with the default values instead of replacing them.
519
+ *
520
+ * @public
521
+ */
122
522
  retainProp: Array<string>
123
- /** @public */
523
+ /**
524
+ * Function names whose parameters should be removed during transformation
525
+ *
526
+ * @example
527
+ * ```js
528
+ * import { defineConfig } from '@lynx-js/rspeedy'
529
+ * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'
530
+ *
531
+ * export default defineConfig({
532
+ * plugins: [
533
+ * pluginReactLynx({
534
+ * shake: {
535
+ * removeCallParams: ['useMyCustomEffect']
536
+ * }
537
+ * })
538
+ * ]
539
+ * })
540
+ * ```
541
+ *
542
+ * @remarks
543
+ * Default value: `['useEffect', 'useLayoutEffect', '__runInJS', 'useLynxGlobalEventListener', 'useImperativeHandle']`
544
+ * The provided values will be merged with the default values instead of replacing them.
545
+ *
546
+ * @public
547
+ */
124
548
  removeCallParams: Array<string>
125
549
  }
550
+ /** @internal */
126
551
  export interface JsxTransformerConfig {
552
+ /** @internal */
127
553
  preserveJsx: boolean
554
+ /** @internal */
128
555
  runtimePkg: string
556
+ /** @internal */
129
557
  jsxImportSource?: string
558
+ /** @internal */
130
559
  filename: string
131
560
  /** @internal */
132
561
  target: 'LEPUS' | 'JS' | 'MIXED'
package/types/react.d.ts CHANGED
@@ -95,7 +95,7 @@ declare module '@lynx-js/types' {
95
95
  interface StandardProps {
96
96
  children?: ReactNode;
97
97
  ref?: Ref<NodesRef>;
98
- key?: Key;
98
+ key?: Key | null | undefined;
99
99
  'main-thread:ref'?: Ref<MainThread.Element>;
100
100
  }
101
101