@viewfly/core 2.1.0 → 3.0.0-alpha.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 (59) hide show
  1. package/README.md +67 -4
  2. package/dist/_utils/make-error.d.ts +1 -0
  3. package/dist/base/_api.d.ts +12 -0
  4. package/dist/base/_utils.d.ts +46 -0
  5. package/dist/base/component.d.ts +77 -0
  6. package/dist/base/context.d.ts +112 -0
  7. package/dist/base/dep.d.ts +9 -0
  8. package/dist/base/injection-tokens.d.ts +20 -0
  9. package/dist/base/jsx-element.d.ts +64 -0
  10. package/dist/base/lifecycle.d.ts +54 -0
  11. package/dist/base/ref.d.ts +50 -0
  12. package/dist/base/renderer.d.ts +4 -0
  13. package/dist/base/root.component.d.ts +9 -0
  14. package/dist/base/types.d.ts +29 -0
  15. package/dist/di/_api.d.ts +10 -0
  16. package/dist/di/forward-ref.d.ts +10 -0
  17. package/dist/di/injectable.d.ts +20 -0
  18. package/dist/di/injection-token.d.ts +8 -0
  19. package/dist/di/injector.d.ts +26 -0
  20. package/dist/di/metadata.d.ts +43 -0
  21. package/dist/di/null-injector.d.ts +6 -0
  22. package/dist/di/provider.d.ts +30 -0
  23. package/dist/di/reflective-injector.d.ts +30 -0
  24. package/dist/di/reflective-provider.d.ts +20 -0
  25. package/dist/di/type.d.ts +7 -0
  26. package/dist/di/utils/_api.d.ts +3 -0
  27. package/dist/di/utils/annotations.d.ts +33 -0
  28. package/dist/di/utils/decorators.d.ts +17 -0
  29. package/dist/di/utils/stringify.d.ts +1 -0
  30. package/dist/index.d.ts +5 -0
  31. package/dist/index.esm.js +2302 -0
  32. package/dist/index.js +2940 -0
  33. package/dist/jsx-runtime/index.d.ts +7 -0
  34. package/dist/jsx-runtime/index.esm.js +2 -0
  35. package/dist/jsx-runtime/index.js +26 -0
  36. package/dist/jsx-runtime.d.ts +7 -0
  37. package/dist/reactive/_api.d.ts +7 -0
  38. package/dist/reactive/_help.d.ts +15 -0
  39. package/dist/reactive/array-handlers.d.ts +30 -0
  40. package/dist/reactive/computed.d.ts +10 -0
  41. package/dist/reactive/effect.d.ts +13 -0
  42. package/dist/reactive/iterable-iterator.d.ts +5 -0
  43. package/dist/reactive/map-handlers.d.ts +12 -0
  44. package/dist/reactive/reactive.d.ts +141 -0
  45. package/dist/reactive/set-handlers.d.ts +11 -0
  46. package/dist/reactive/shallow-reactive.d.ts +6 -0
  47. package/dist/reactive/signal.d.ts +38 -0
  48. package/dist/reactive/watch-effect.d.ts +7 -0
  49. package/dist/reactive/watch.d.ts +8 -0
  50. package/dist/viewfly.d.ts +30 -0
  51. package/package.json +29 -29
  52. package/bundles/index.d.ts +0 -768
  53. package/bundles/index.esm.js +0 -2700
  54. package/bundles/index.js +0 -2777
  55. package/jsx-runtime/index.d.ts +0 -25
  56. package/jsx-runtime/index.esm.js +0 -11
  57. package/jsx-runtime/index.js +0 -14
  58. package/jsx-runtime/package.json +0 -29
  59. package/rollup-d.config.ts +0 -14
package/bundles/index.js DELETED
@@ -1,2777 +0,0 @@
1
- 'use strict';
2
-
3
- require('reflect-metadata');
4
-
5
- class ForwardRef {
6
- constructor(forwardRefFn) {
7
- Object.defineProperty(this, "forwardRefFn", {
8
- enumerable: true,
9
- configurable: true,
10
- writable: true,
11
- value: forwardRefFn
12
- });
13
- }
14
- getRef() {
15
- return this.forwardRefFn();
16
- }
17
- }
18
- /**
19
- * 引用后声明的类的工具函数
20
- * @param fn
21
- */
22
- function forwardRef(fn) {
23
- return new ForwardRef(fn);
24
- }
25
-
26
- /**
27
- * 用于保存 class 的元数据
28
- */
29
- class Annotations {
30
- constructor() {
31
- Object.defineProperty(this, "classes", {
32
- enumerable: true,
33
- configurable: true,
34
- writable: true,
35
- value: new Map()
36
- });
37
- Object.defineProperty(this, "props", {
38
- enumerable: true,
39
- configurable: true,
40
- writable: true,
41
- value: new Map()
42
- });
43
- Object.defineProperty(this, "params", {
44
- enumerable: true,
45
- configurable: true,
46
- writable: true,
47
- value: new Map()
48
- });
49
- }
50
- setClassMetadata(token, params) {
51
- this.classes.set(token, params);
52
- }
53
- getClassMetadata(token) {
54
- return this.classes.get(token);
55
- }
56
- pushParamMetadata(token, params) {
57
- if (this.params.has(token)) {
58
- this.params.get(token).push(params);
59
- }
60
- else {
61
- this.params.set(token, [params]);
62
- }
63
- }
64
- getParamMetadata(token) {
65
- return this.params.get(token);
66
- }
67
- getPropMetadataKeys() {
68
- return Array.from(this.props.keys());
69
- }
70
- pushPropMetadata(token, params) {
71
- if (this.props.has(token)) {
72
- this.props.get(token).push(params);
73
- }
74
- else {
75
- this.props.set(token, [params]);
76
- }
77
- }
78
- getPropMetadata(token) {
79
- return this.props.get(token);
80
- }
81
- }
82
-
83
- /**
84
- * 创建参数装饰器的工厂函数
85
- */
86
- function makeParamDecorator(token, metadata) {
87
- return function (target, propertyKey, parameterIndex) {
88
- const annotations = getAnnotations(target);
89
- annotations.pushParamMetadata(token, {
90
- propertyKey: propertyKey,
91
- parameterIndex,
92
- metadata
93
- });
94
- };
95
- }
96
- /**
97
- * 创建属性装饰器的工厂函数
98
- */
99
- function makePropertyDecorator(token, injectToken, contextCallback) {
100
- return function (target, propertyKey) {
101
- const annotations = getAnnotations(target.constructor);
102
- annotations.pushPropMetadata(token, {
103
- injectToken: injectToken || Reflect.getMetadata('design:type', target, propertyKey),
104
- propertyKey,
105
- contextCallback
106
- });
107
- };
108
- }
109
- /**
110
- * 创建类装饰器的工厂函数
111
- */
112
- function makeClassDecorator(token, metadata) {
113
- return function (target) {
114
- const annotations = getAnnotations(target);
115
- annotations.setClassMetadata(token, {
116
- paramTypes: Reflect.getMetadata('design:paramtypes', target),
117
- metadata
118
- });
119
- };
120
- }
121
- /**
122
- * 获取类注解的工具函数
123
- */
124
- function getAnnotations(target) {
125
- const key = '__annotations__';
126
- // eslint-disable-next-line no-prototype-builtins
127
- if (!target.hasOwnProperty(key)) {
128
- target[key] = new Annotations();
129
- }
130
- return target[key];
131
- }
132
-
133
- class Scope {
134
- constructor(name) {
135
- Object.defineProperty(this, "name", {
136
- enumerable: true,
137
- configurable: true,
138
- writable: true,
139
- value: name
140
- });
141
- }
142
- toString() {
143
- return this.name || '[anonymous provide scope]';
144
- }
145
- }
146
- /**
147
- * 可注入类的装饰器
148
- */
149
- const Injectable = function InjectableDecorator(options) {
150
- if (this instanceof InjectableDecorator) {
151
- this.provideIn = (options === null || options === void 0 ? void 0 : options.provideIn) || null;
152
- }
153
- else {
154
- return makeClassDecorator(Injectable, new Injectable(options));
155
- }
156
- };
157
-
158
- /**
159
- * 生成自定义依赖注入 token 的类
160
- */
161
- /* eslint-disable-next-line */
162
- class InjectionToken {
163
- constructor(description) {
164
- Object.defineProperty(this, "description", {
165
- enumerable: true,
166
- configurable: true,
167
- writable: true,
168
- value: description
169
- });
170
- }
171
- toString() {
172
- return this.description || '[anonymous injection token]';
173
- }
174
- }
175
-
176
- /**
177
- * 查找规则
178
- */
179
- exports.InjectFlags = void 0;
180
- (function (InjectFlags) {
181
- /** 默认查找规则 */
182
- InjectFlags["Default"] = "Default";
183
- /** 锁定当前容器 */
184
- InjectFlags["Self"] = "Self";
185
- /** 跳过当前容器 */
186
- InjectFlags["SkipSelf"] = "SkipSelf";
187
- /** 可选查找 */
188
- InjectFlags["Optional"] = "Optional";
189
- })(exports.InjectFlags || (exports.InjectFlags = {}));
190
- /**
191
- * DI 容器抽象基类
192
- */
193
- class Injector {
194
- }
195
-
196
- /**
197
- * 构造函数参数装饰器,用于改变注入 token
198
- */
199
- const Inject = function InjectDecorator(token) {
200
- if (this instanceof Inject) {
201
- this.token = token;
202
- }
203
- else {
204
- return makeParamDecorator(Inject, new Inject(token));
205
- }
206
- };
207
- const Self = function SelfDecorator() {
208
- if (!(this instanceof Self)) {
209
- return makeParamDecorator(Self, new Self());
210
- }
211
- };
212
- const SkipSelf = function SkipSelfDecorator() {
213
- if (!(this instanceof SkipSelf)) {
214
- return makeParamDecorator(SkipSelf, new SkipSelf());
215
- }
216
- };
217
- const Optional = function OptionalDecorator() {
218
- if (!(this instanceof Optional)) {
219
- return makeParamDecorator(Optional, new Optional());
220
- }
221
- };
222
- const Prop = function PropDecorator(token, notFoundValue, flags) {
223
- if (!(this instanceof Prop)) {
224
- return makePropertyDecorator(Prop, token, function (instance, propertyName, token, injector) {
225
- instance[propertyName] = injector.get(token instanceof ForwardRef ? token.getRef() : token, notFoundValue, flags);
226
- });
227
- }
228
- };
229
-
230
- function stringify(token) {
231
- if (typeof token === 'string') {
232
- return token;
233
- }
234
- if (Array.isArray(token)) {
235
- return '[' + token.map(stringify).join(', ') + ']';
236
- }
237
- if (token == null) {
238
- return '' + token;
239
- }
240
- if (token.name) {
241
- return `${token.name}`;
242
- }
243
- if (token.token) {
244
- return `${token.token}`;
245
- }
246
- const res = token.toString();
247
- if (res == null) {
248
- return '' + res;
249
- }
250
- const newLineIndex = res.indexOf('\n');
251
- return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
252
- }
253
-
254
- function makeError(name) {
255
- return function viewflyError(message) {
256
- const error = new Error(message);
257
- error.name = `[ViewflyError: ${name}]`;
258
- error.stack = error.stack.replace(/\n.*?(?=\n)/, '');
259
- return error;
260
- };
261
- }
262
-
263
- const THROW_IF_NOT_FOUND = {
264
- __debug_value__: 'THROW_IF_NOT_FOUND'
265
- };
266
- const nullInjectorErrorFn = (token) => {
267
- return makeError('NullInjector')(`No provide for \`${stringify(token)}\`!`);
268
- };
269
- class NullInjector {
270
- constructor() {
271
- Object.defineProperty(this, "parentInjector", {
272
- enumerable: true,
273
- configurable: true,
274
- writable: true,
275
- value: null
276
- });
277
- }
278
- /* eslint-disable-next-line */
279
- get(token, notFoundValue = THROW_IF_NOT_FOUND, _) {
280
- if (notFoundValue === THROW_IF_NOT_FOUND) {
281
- throw nullInjectorErrorFn(token);
282
- }
283
- return notFoundValue;
284
- }
285
- }
286
-
287
- /**
288
- * 标准化 provide,并返回统一数据结构
289
- * @param provider
290
- */
291
- function normalizeProvider(provider) {
292
- if (provider.useValue) {
293
- return normalizeValueProviderFactory(provider);
294
- }
295
- if (provider.useClass) {
296
- return normalizeClassProviderFactory(provider);
297
- }
298
- if (provider.useExisting) {
299
- return normalizeExistingProviderFactory(provider);
300
- }
301
- if (provider.useFactory) {
302
- return normalizeFactoryProviderFactory(provider);
303
- }
304
- if (provider.provide) {
305
- if (provider.provide instanceof InjectionToken) {
306
- return normalizeValueProviderFactory(provider);
307
- }
308
- return normalizeConstructorProviderFactory(provider);
309
- }
310
- return normalizeTypeProviderFactory(provider);
311
- }
312
- function normalizeValueProviderFactory(provider) {
313
- return {
314
- provide: provider.provide,
315
- scope: null,
316
- generateFactory() {
317
- return function () {
318
- return provider.useValue;
319
- };
320
- },
321
- deps: []
322
- };
323
- }
324
- function normalizeClassProviderFactory(provider) {
325
- let deps;
326
- let provideIn = null;
327
- if (provider.deps) {
328
- deps = normalizeDeps(provider.provide, provider.deps);
329
- }
330
- else {
331
- const resolvedClass = resolveClassParams(provider.useClass);
332
- provideIn = resolvedClass.scope;
333
- deps = normalizeDeps(provider.provide, resolvedClass.deps);
334
- }
335
- return {
336
- provide: provider.provide,
337
- scope: provideIn,
338
- deps,
339
- generateFactory(injector, cacheFn) {
340
- return function (...args) {
341
- const instance = new provider.useClass(...args);
342
- cacheFn(provider.provide, instance);
343
- const propMetadataKeys = getAnnotations(provider.useClass).getPropMetadataKeys();
344
- propMetadataKeys.forEach(key => {
345
- const propsMetadata = getAnnotations(provider.useClass).getPropMetadata(key);
346
- propsMetadata.forEach(item => {
347
- item.contextCallback(instance, item.propertyKey, item.injectToken, injector);
348
- });
349
- });
350
- return instance;
351
- };
352
- }
353
- };
354
- }
355
- function normalizeExistingProviderFactory(provider) {
356
- return {
357
- provide: provider.provide,
358
- scope: null,
359
- generateFactory(injector) {
360
- return function () {
361
- return injector.get(provider.useExisting);
362
- };
363
- },
364
- deps: []
365
- };
366
- }
367
- function normalizeFactoryProviderFactory(provider) {
368
- return {
369
- provide: provider.provide,
370
- scope: null,
371
- generateFactory() {
372
- return function (...args) {
373
- return provider.useFactory(...args);
374
- };
375
- },
376
- deps: normalizeDeps(provider.provide, provider.deps || [])
377
- };
378
- }
379
- function normalizeConstructorProviderFactory(provider) {
380
- return normalizeClassProviderFactory(Object.assign(Object.assign({}, provider), { useClass: provider.provide }));
381
- }
382
- function normalizeTypeProviderFactory(provider) {
383
- return normalizeClassProviderFactory({
384
- provide: provider,
385
- useClass: provider
386
- });
387
- }
388
- function resolveClassParams(construct) {
389
- const annotations = getAnnotations(construct);
390
- const metadata = annotations.getClassMetadata(Injectable);
391
- if (typeof metadata === 'undefined') {
392
- throw new Error(`Class \`${stringify(construct)}\` is not injectable!`);
393
- }
394
- const deps = (metadata.paramTypes || []).map(i => [i]);
395
- const metadataKeys = [Inject, Self, SkipSelf, Optional];
396
- metadataKeys.forEach(key => {
397
- (annotations.getParamMetadata(key) || []).forEach(item => {
398
- deps[item.parameterIndex].push(item.metadata);
399
- });
400
- });
401
- return {
402
- scope: metadata.metadata.provideIn,
403
- deps
404
- };
405
- }
406
- function normalizeDeps(provide, deps) {
407
- return deps.map((dep, index) => {
408
- const r = {
409
- injectKey: null,
410
- optional: false,
411
- visibility: null
412
- };
413
- if (!Array.isArray(dep)) {
414
- r.injectKey = dep;
415
- }
416
- else {
417
- for (let i = 0; i < dep.length; i++) {
418
- const item = dep[i];
419
- if (item instanceof Inject) {
420
- r.injectKey = item.token;
421
- }
422
- else if (item instanceof Self || item instanceof SkipSelf) {
423
- r.visibility = item;
424
- }
425
- else if (item instanceof Optional) {
426
- r.optional = true;
427
- }
428
- else {
429
- r.injectKey = item;
430
- }
431
- }
432
- }
433
- if (typeof r.injectKey === 'undefined') {
434
- /* eslint-disable max-len */
435
- throw new Error(`The ${index} th dependent parameter type of \`${stringify(provide)}\` was not obtained, if the dependency is declared later, you can refer to it using \`constructor(@Inject(forwardRef(() => [Type|InjectionToken])) paramName: [Type]) {}\``);
436
- }
437
- return r;
438
- });
439
- }
440
-
441
- const reflectiveInjectorErrorFn = (token) => {
442
- return makeError('ReflectiveInjector')(`No provide for \`${stringify(token)}\`!`);
443
- };
444
- const provideScopeError = (token) => {
445
- return makeError('ProvideScope')(`Can not found provide scope \`${stringify(token)}\`!`);
446
- };
447
- /**
448
- * 反射注入器
449
- */
450
- class ReflectiveInjector {
451
- constructor(parentInjector, staticProviders, scope) {
452
- Object.defineProperty(this, "parentInjector", {
453
- enumerable: true,
454
- configurable: true,
455
- writable: true,
456
- value: parentInjector
457
- });
458
- Object.defineProperty(this, "scope", {
459
- enumerable: true,
460
- configurable: true,
461
- writable: true,
462
- value: scope
463
- });
464
- Object.defineProperty(this, "normalizedProviders", {
465
- enumerable: true,
466
- configurable: true,
467
- writable: true,
468
- value: void 0
469
- });
470
- Object.defineProperty(this, "recordValues", {
471
- enumerable: true,
472
- configurable: true,
473
- writable: true,
474
- value: new Map()
475
- });
476
- this.normalizedProviders = staticProviders.map(provide => {
477
- return normalizeProvider(provide);
478
- });
479
- }
480
- /**
481
- * 用于获取当前注入器上下文内的实例、对象或数据
482
- * @param token 访问 token
483
- * @param notFoundValue 如未查找到的返回值
484
- * @param flags 查询规则
485
- */
486
- get(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
487
- var _a;
488
- flags = flags || exports.InjectFlags.Default;
489
- if (flags === exports.InjectFlags.SkipSelf) {
490
- if (this.parentInjector) {
491
- return this.parentInjector.get(token, notFoundValue);
492
- }
493
- if (notFoundValue !== THROW_IF_NOT_FOUND) {
494
- return notFoundValue;
495
- }
496
- throw reflectiveInjectorErrorFn(token);
497
- }
498
- if (this.recordValues.has(token)) {
499
- return this.recordValues.get(token);
500
- }
501
- for (let i = 0; i < this.normalizedProviders.length; i++) {
502
- const normalizedProvider = this.normalizedProviders[i];
503
- if (normalizedProvider.provide === token) {
504
- return this.getValue(token, normalizedProvider);
505
- }
506
- }
507
- if (!(token instanceof InjectionToken)) {
508
- const scope = (_a = getAnnotations(token).getClassMetadata(Injectable)) === null || _a === void 0 ? void 0 : _a.metadata.provideIn;
509
- if (scope) {
510
- const normalizedProvider = normalizeProvider(token);
511
- if (this.scope === scope) {
512
- this.normalizedProviders.push(normalizedProvider);
513
- return this.getValue(token, normalizedProvider);
514
- }
515
- const parentInjector = this.parentInjector;
516
- if (!parentInjector || parentInjector instanceof NullInjector) {
517
- if (normalizedProvider.scope === 'root') {
518
- this.normalizedProviders.push(normalizedProvider);
519
- return this.getValue(token, normalizedProvider);
520
- }
521
- if (notFoundValue !== THROW_IF_NOT_FOUND) {
522
- return notFoundValue;
523
- }
524
- throw provideScopeError(normalizedProvider.scope);
525
- }
526
- }
527
- }
528
- if (flags === exports.InjectFlags.Self) {
529
- if (notFoundValue === THROW_IF_NOT_FOUND) {
530
- throw reflectiveInjectorErrorFn(token);
531
- }
532
- return notFoundValue;
533
- }
534
- if (this.parentInjector) {
535
- return this.parentInjector.get(token, notFoundValue, flags === exports.InjectFlags.Optional ? exports.InjectFlags.Optional : exports.InjectFlags.Default);
536
- }
537
- if (notFoundValue === THROW_IF_NOT_FOUND) {
538
- // if (flags === InjectFlags.Optional) {
539
- // return null as U
540
- // }
541
- throw reflectiveInjectorErrorFn(token);
542
- }
543
- return notFoundValue;
544
- }
545
- getValue(token, normalizedProvider) {
546
- const { generateFactory, deps } = normalizedProvider;
547
- const params = this.resolveDeps(deps);
548
- let value = this.recordValues.get(token);
549
- if (value) {
550
- return value;
551
- }
552
- const factory = generateFactory(this, (token, value) => {
553
- this.recordValues.set(token, value);
554
- });
555
- value = factory(...params);
556
- this.recordValues.set(token, value);
557
- return value;
558
- }
559
- /**
560
- * 解决并获取依赖参数
561
- * @param deps 依赖规则
562
- * @private
563
- */
564
- resolveDeps(deps) {
565
- return deps.map(dep => {
566
- let reflectiveValue;
567
- const tryValue = {};
568
- const injectToken = dep.injectKey instanceof ForwardRef ? dep.injectKey.getRef() : dep.injectKey;
569
- if (dep.visibility instanceof Self) {
570
- reflectiveValue = this.get(injectToken, tryValue, exports.InjectFlags.Self);
571
- }
572
- else if (dep.visibility instanceof SkipSelf) {
573
- if (this.parentInjector) {
574
- reflectiveValue = this.parentInjector.get(injectToken, tryValue);
575
- }
576
- else {
577
- if (dep.optional) {
578
- // if (notFoundValue === THROW_IF_NOT_FOUND) {
579
- // return null
580
- // }
581
- return null;
582
- }
583
- throw reflectiveInjectorErrorFn(injectToken);
584
- }
585
- }
586
- else {
587
- reflectiveValue = this.get(injectToken, tryValue);
588
- }
589
- if (reflectiveValue === tryValue) {
590
- if (dep.optional) {
591
- // if (notFoundValue === THROW_IF_NOT_FOUND) {
592
- // return null
593
- // }
594
- // return notFoundValue
595
- return null;
596
- }
597
- throw reflectiveInjectorErrorFn(injectToken);
598
- }
599
- return reflectiveValue;
600
- });
601
- }
602
- }
603
-
604
- const Type = Function;
605
-
606
- /**
607
- * 当组件第一次渲染完成时触发
608
- * @param callback
609
- * ```tsx
610
- * function App() {
611
- * onMount(() => {
612
- * console.log('App mounted!')
613
- * })
614
- * return () => <div>...</div>
615
- * }
616
- * ```
617
- */
618
- function onMounted(callback) {
619
- const component = getSetupContext();
620
- if (!component.mountCallbacks) {
621
- component.mountCallbacks = [];
622
- }
623
- component.mountCallbacks.push(callback);
624
- }
625
- /**
626
- * 当组件视图更新后调用
627
- * @param callback
628
- * ```tsx
629
- * function App() {
630
- * onUpdated(() => {
631
- * console.log('App updated!')
632
- * return () => {
633
- * console.log('destroy prev update!')
634
- * }
635
- * })
636
- * return () => <div>...</div>
637
- * }
638
- * ```
639
- */
640
- function onUpdated(callback) {
641
- const component = getSetupContext();
642
- if (!component.updatedCallbacks) {
643
- component.updatedCallbacks = [];
644
- }
645
- component.updatedCallbacks.push(callback);
646
- return () => {
647
- const index = component.updatedCallbacks.indexOf(callback);
648
- if (index > -1) {
649
- component.updatedCallbacks.splice(index, 1);
650
- }
651
- };
652
- }
653
- /**
654
- * 当组件销毁时调用回调函数
655
- * @param callback
656
- */
657
- function onUnmounted(callback) {
658
- const component = getSetupContext();
659
- if (!component.unmountedCallbacks) {
660
- component.unmountedCallbacks = [];
661
- }
662
- component.unmountedCallbacks.push(callback);
663
- }
664
-
665
- class DynamicRef {
666
- constructor(callback) {
667
- Object.defineProperty(this, "callback", {
668
- enumerable: true,
669
- configurable: true,
670
- writable: true,
671
- value: callback
672
- });
673
- Object.defineProperty(this, "unBindMap", {
674
- enumerable: true,
675
- configurable: true,
676
- writable: true,
677
- value: new Map()
678
- });
679
- Object.defineProperty(this, "targetCaches", {
680
- enumerable: true,
681
- configurable: true,
682
- writable: true,
683
- value: new Set()
684
- });
685
- }
686
- bind(value) {
687
- if (typeof value !== 'object' || value === null) {
688
- return;
689
- }
690
- if (this.targetCaches.has(value)) {
691
- return;
692
- }
693
- const unBindFn = this.callback(value);
694
- if (typeof unBindFn === 'function') {
695
- this.unBindMap.set(value, unBindFn);
696
- }
697
- this.targetCaches.add(value);
698
- }
699
- unBind(value) {
700
- this.targetCaches.delete(value);
701
- const unBindFn = this.unBindMap.get(value);
702
- this.unBindMap.delete(value);
703
- if (typeof unBindFn === 'function') {
704
- unBindFn();
705
- }
706
- }
707
- }
708
- /**
709
- * 用于节点渲染完成时获取 DOM 节点
710
- * @param callback 获取 DOM 节点的回调函数
711
- * @example
712
- * ```tsx
713
- * function App() {
714
- * const ref = createDynamicRef(node => {
715
- * function fn() {
716
- * // do something...
717
- * }
718
- * node.addEventListener('click', fn)
719
- * return () => {
720
- * node.removeEventListener('click', fn)
721
- * }
722
- * })
723
- * return () => {
724
- * return <div ref={ref}>xxx</div>
725
- * }
726
- * }
727
- * ```
728
- */
729
- function createDynamicRef(callback) {
730
- return new DynamicRef(callback);
731
- }
732
- class StaticRef extends DynamicRef {
733
- get current() {
734
- return this._current;
735
- }
736
- constructor() {
737
- super(v => {
738
- this._current = v;
739
- return () => {
740
- this._current = null;
741
- };
742
- });
743
- Object.defineProperty(this, "_current", {
744
- enumerable: true,
745
- configurable: true,
746
- writable: true,
747
- value: null
748
- });
749
- }
750
- }
751
- function createRef() {
752
- return new StaticRef();
753
- }
754
-
755
- const toStr = Object.prototype.toString;
756
- function getStringType(v) {
757
- return toStr.call(v);
758
- }
759
- function isArray(v) {
760
- return Array.isArray(v);
761
- }
762
- const hasOwnProperty = Object.prototype.hasOwnProperty;
763
- function hasOwn(target, key) {
764
- return hasOwnProperty.call(target, key);
765
- }
766
-
767
- class Dep {
768
- constructor(effect) {
769
- Object.defineProperty(this, "effect", {
770
- enumerable: true,
771
- configurable: true,
772
- writable: true,
773
- value: effect
774
- });
775
- Object.defineProperty(this, "destroyCallbacks", {
776
- enumerable: true,
777
- configurable: true,
778
- writable: true,
779
- value: []
780
- });
781
- }
782
- destroy() {
783
- this.destroyCallbacks.forEach(callback => callback());
784
- this.destroyCallbacks = [];
785
- }
786
- }
787
- const deps = [];
788
- function getDepContext() {
789
- return deps.at(-1);
790
- }
791
- function pushDepContext(dep) {
792
- deps.push(dep);
793
- }
794
- function popDepContext() {
795
- deps.pop();
796
- }
797
-
798
- const subscribers = new WeakMap();
799
- function getSubscriber(target) {
800
- let subscriber = subscribers.get(target);
801
- if (!subscriber) {
802
- subscriber = new Map();
803
- subscribers.set(target, subscriber);
804
- }
805
- return subscriber;
806
- }
807
- exports.TrackOpTypes = void 0;
808
- (function (TrackOpTypes) {
809
- TrackOpTypes["Get"] = "Get";
810
- TrackOpTypes["Has"] = "Has";
811
- TrackOpTypes["Iterate"] = "Iterate";
812
- })(exports.TrackOpTypes || (exports.TrackOpTypes = {}));
813
- exports.TriggerOpTypes = void 0;
814
- (function (TriggerOpTypes) {
815
- TriggerOpTypes["Set"] = "Set";
816
- TriggerOpTypes["Add"] = "Add";
817
- TriggerOpTypes["Delete"] = "Delete";
818
- TriggerOpTypes["Clear"] = "Clear";
819
- })(exports.TriggerOpTypes || (exports.TriggerOpTypes = {}));
820
- const unKnownKey = Symbol('unKnownKey');
821
- function track(target, type, key = unKnownKey) {
822
- const dep = getDepContext();
823
- if (dep) {
824
- const subscriber = getSubscriber(target);
825
- let record = subscriber.get(type);
826
- if (!record) {
827
- record = new Map();
828
- subscriber.set(type, record);
829
- }
830
- let effects = record.get(key);
831
- if (!effects) {
832
- effects = new Set([dep]);
833
- record.set(key, effects);
834
- dep.destroyCallbacks.push(() => {
835
- effects.delete(dep);
836
- });
837
- }
838
- else if (!effects.has(dep)) {
839
- dep.destroyCallbacks.push(() => {
840
- effects.delete(dep);
841
- });
842
- effects.add(dep);
843
- }
844
- }
845
- }
846
- function runEffect(key, record) {
847
- if (!record) {
848
- return;
849
- }
850
- const effects = record.get(key);
851
- if (effects) {
852
- const fns = [...effects];
853
- fns.forEach(i => i.effect());
854
- }
855
- }
856
- function trigger(target, type, key = unKnownKey) {
857
- const subscriber = getSubscriber(target);
858
- if (subscriber) {
859
- switch (type) {
860
- case exports.TriggerOpTypes.Set:
861
- if (isArray(target)) {
862
- const iterateRecord = subscriber.get(exports.TrackOpTypes.Iterate);
863
- runEffect(unKnownKey, iterateRecord);
864
- }
865
- runEffect(key, subscriber.get(exports.TrackOpTypes.Get));
866
- runEffect(key, subscriber.get(exports.TrackOpTypes.Has));
867
- break;
868
- case exports.TriggerOpTypes.Add:
869
- case exports.TriggerOpTypes.Clear:
870
- case exports.TriggerOpTypes.Delete:
871
- {
872
- const iterateRecord = subscriber.get(exports.TrackOpTypes.Iterate);
873
- runEffect(unKnownKey, iterateRecord);
874
- runEffect(key, subscriber.get(exports.TrackOpTypes.Has));
875
- runEffect(key, subscriber.get(exports.TrackOpTypes.Get));
876
- }
877
- break;
878
- }
879
- }
880
- }
881
-
882
- function createIterableIterator(wrapper) {
883
- return {
884
- *entries() {
885
- const target = toRaw(this);
886
- track(target, exports.TrackOpTypes.Iterate);
887
- for (const [key, value] of target.entries()) {
888
- yield [wrapper(key), wrapper(value)];
889
- }
890
- },
891
- *keys() {
892
- const target = toRaw(this);
893
- track(target, exports.TrackOpTypes.Iterate);
894
- for (const item of target.keys()) {
895
- yield wrapper(item);
896
- }
897
- },
898
- *values() {
899
- const target = toRaw(this);
900
- track(target, exports.TrackOpTypes.Iterate);
901
- for (const item of target.values()) {
902
- yield wrapper(item);
903
- }
904
- }
905
- };
906
- }
907
-
908
- function applyPredicateMethod(self, methodName, predicate, wrapper, thisArg) {
909
- const target = toRaw(self);
910
- track(target, exports.TrackOpTypes.Iterate);
911
- return target[methodName]((value, index, array) => {
912
- return predicate.call(target, wrapper(value), index, array);
913
- }, thisArg);
914
- }
915
- function applySearchMethod(self, methodName, args) {
916
- const target = toRaw(self);
917
- track(target, exports.TrackOpTypes.Iterate);
918
- return target[methodName](...args.map(toRaw));
919
- }
920
- function createArrayHandlers(wrapper) {
921
- return Object.assign({ concat(...items) {
922
- const target = toRaw(this);
923
- trigger(target, exports.TriggerOpTypes.Add);
924
- return target.concat(...items);
925
- },
926
- every(predicate, thisArg) {
927
- return applyPredicateMethod(this, 'every', predicate, wrapper, thisArg);
928
- },
929
- filter(predicate, thisArg) {
930
- return applyPredicateMethod(this, 'filter', predicate, wrapper, thisArg);
931
- },
932
- find(predicate, thisArg) {
933
- return applyPredicateMethod(this, 'find', predicate, wrapper, thisArg);
934
- },
935
- findIndex(predicate, thisArg) {
936
- return applyPredicateMethod(this, 'findIndex', predicate, wrapper, thisArg);
937
- },
938
- findLast(predicate, thisArg) {
939
- return applyPredicateMethod(this, 'findLast', predicate, wrapper, thisArg);
940
- },
941
- findLastIndex(predicate, thisArg) {
942
- return applyPredicateMethod(this, 'findLastIndex', predicate, wrapper, thisArg);
943
- },
944
- forEach(callbackfn, thisArg) {
945
- return applyPredicateMethod(this, 'forEach', callbackfn, wrapper, thisArg);
946
- },
947
- includes(...args) {
948
- return applySearchMethod(this, 'includes', args);
949
- },
950
- indexOf(...args) {
951
- return applySearchMethod(this, 'indexOf', args);
952
- },
953
- join(separator) {
954
- const target = toRaw(this);
955
- track(target, exports.TrackOpTypes.Iterate);
956
- return target.join(separator);
957
- },
958
- lastIndexOf(...args) {
959
- return applySearchMethod(this, 'lastIndexOf', args);
960
- },
961
- map(callbackFn, thisArg) {
962
- return applyPredicateMethod(this, 'map', callbackFn, wrapper, thisArg);
963
- },
964
- pop() {
965
- const target = toRaw(this);
966
- trigger(target, exports.TriggerOpTypes.Delete);
967
- return target.pop();
968
- },
969
- push(...items) {
970
- const target = toRaw(this);
971
- trigger(target, exports.TriggerOpTypes.Add);
972
- return target.push(...items);
973
- },
974
- reduce(callbackFn, ...args) {
975
- const target = toRaw(this);
976
- track(target, exports.TrackOpTypes.Iterate);
977
- return target.reduce((p, c, i, a) => {
978
- if (args.length > 0) {
979
- return callbackFn(p, wrapper(c), i, a);
980
- }
981
- return callbackFn(wrapper(p), wrapper(c), i, a);
982
- }, ...args);
983
- },
984
- reduceRight(callbackFn, ...args) {
985
- const target = toRaw(this);
986
- track(target, exports.TrackOpTypes.Iterate);
987
- return target.reduceRight((p, c, i, a) => {
988
- if (args.length > 0) {
989
- return callbackFn(p, wrapper(c), i, a);
990
- }
991
- return callbackFn(wrapper(p), wrapper(c), i, a);
992
- }, ...args);
993
- },
994
- shift() {
995
- const target = toRaw(this);
996
- trigger(target, exports.TriggerOpTypes.Delete);
997
- return target.shift();
998
- },
999
- some(predicate, thisArg) {
1000
- return applyPredicateMethod(this, 'some', predicate, thisArg);
1001
- },
1002
- splice(start, deleteCount) {
1003
- const target = toRaw(this);
1004
- trigger(target, exports.TriggerOpTypes.Set);
1005
- trigger(target, exports.TriggerOpTypes.Add);
1006
- trigger(target, exports.TriggerOpTypes.Delete);
1007
- return target.splice(start, deleteCount).map(i => wrapper(i));
1008
- },
1009
- toReversed() {
1010
- const target = toRaw(this);
1011
- track(target, exports.TrackOpTypes.Iterate);
1012
- return target.toReversed();
1013
- },
1014
- toSorted(compareFn) {
1015
- const target = toRaw(this);
1016
- track(target, exports.TrackOpTypes.Iterate);
1017
- return target.toSorted(compareFn);
1018
- },
1019
- toSpliced(start, deleteCount, ...items) {
1020
- const target = toRaw(this);
1021
- track(target, exports.TrackOpTypes.Iterate);
1022
- return target.toSpliced(start, deleteCount, ...items);
1023
- },
1024
- unshift(...items) {
1025
- const target = toRaw(this);
1026
- trigger(target, exports.TriggerOpTypes.Add);
1027
- return target.unshift(...items);
1028
- },
1029
- [Symbol.iterator]() {
1030
- return this.values();
1031
- } }, createIterableIterator(wrapper));
1032
- }
1033
-
1034
- function createMapHandlers(wrapper) {
1035
- return Object.assign({ get(key) {
1036
- const target = toRaw(this);
1037
- track(target, exports.TrackOpTypes.Get, key);
1038
- return wrapper(target.get(key));
1039
- },
1040
- set(key, value) {
1041
- const target = toRaw(this);
1042
- key = toRaw(key);
1043
- value = toRaw(value);
1044
- const has = target.has(key);
1045
- const r = target.set(key, value);
1046
- trigger(target, has ? exports.TriggerOpTypes.Set : exports.TriggerOpTypes.Add, key);
1047
- return r;
1048
- },
1049
- has(key) {
1050
- const target = toRaw(this);
1051
- key = toRaw(key);
1052
- track(target, exports.TrackOpTypes.Has, key);
1053
- return target.has(key);
1054
- },
1055
- delete(key) {
1056
- const target = toRaw(this);
1057
- key = toRaw(key);
1058
- const r = target.delete(key);
1059
- trigger(target, exports.TriggerOpTypes.Delete, key);
1060
- return r;
1061
- },
1062
- forEach(callbackFn, thisArg) {
1063
- const target = toRaw(this);
1064
- track(target, exports.TrackOpTypes.Iterate, undefined);
1065
- target.forEach((v, k, m) => {
1066
- callbackFn.call(this, wrapper(v), wrapper(k), m);
1067
- }, thisArg);
1068
- },
1069
- clear() {
1070
- const target = toRaw(this);
1071
- target.clear();
1072
- trigger(target, exports.TriggerOpTypes.Clear, undefined);
1073
- },
1074
- [Symbol.iterator]() {
1075
- return this.entries();
1076
- } }, createIterableIterator(wrapper));
1077
- }
1078
-
1079
- function createSetHandlers(wrapper) {
1080
- return Object.assign({ add(value) {
1081
- const target = toRaw(this);
1082
- value = toRaw(value);
1083
- if (!target.has(value)) {
1084
- target.add(value);
1085
- trigger(target, exports.TriggerOpTypes.Add, undefined);
1086
- }
1087
- return this;
1088
- },
1089
- delete(value) {
1090
- const target = toRaw(this);
1091
- value = toRaw(value);
1092
- const has = target.has(value);
1093
- const b = target.delete(value);
1094
- if (!has) {
1095
- trigger(target, exports.TriggerOpTypes.Delete, undefined);
1096
- }
1097
- return b;
1098
- },
1099
- has(key) {
1100
- const target = toRaw(this);
1101
- key = toRaw(key);
1102
- track(target, exports.TrackOpTypes.Has, key);
1103
- return target.has(key);
1104
- },
1105
- forEach(callbackFn, thisArg) {
1106
- const target = toRaw(this);
1107
- track(target, exports.TrackOpTypes.Iterate, undefined);
1108
- target.forEach((v, k, m) => {
1109
- callbackFn.call(this, wrapper(v), wrapper(k), m);
1110
- }, thisArg);
1111
- },
1112
- clear() {
1113
- const target = toRaw(this);
1114
- const size = target.size;
1115
- if (size !== 0) {
1116
- target.clear();
1117
- trigger(target, exports.TriggerOpTypes.Clear, undefined);
1118
- }
1119
- },
1120
- [Symbol.iterator]() {
1121
- return this.values();
1122
- } }, createIterableIterator(wrapper));
1123
- }
1124
-
1125
- const reactiveErrorFn = makeError('reactive');
1126
- const rawToProxyCache = new WeakMap();
1127
- const proxyToRawCache = new WeakMap();
1128
- function toRaw(value) {
1129
- if (proxyToRawCache.has(value)) {
1130
- return proxyToRawCache.get(value);
1131
- }
1132
- return value;
1133
- }
1134
- function isReactive(value) {
1135
- return proxyToRawCache.has(value);
1136
- }
1137
- let fromInternalWrite = false;
1138
- function internalWrite(fn) {
1139
- fromInternalWrite = true;
1140
- fn();
1141
- fromInternalWrite = false;
1142
- }
1143
- class ObjectReactiveHandler {
1144
- constructor(config) {
1145
- Object.defineProperty(this, "isShallow", {
1146
- enumerable: true,
1147
- configurable: true,
1148
- writable: true,
1149
- value: void 0
1150
- });
1151
- Object.defineProperty(this, "isReadonly", {
1152
- enumerable: true,
1153
- configurable: true,
1154
- writable: true,
1155
- value: void 0
1156
- });
1157
- this.isReadonly = config.readonly;
1158
- this.isShallow = config.shallow;
1159
- }
1160
- set(target, p, newValue, receiver) {
1161
- if (this.isReadonly && !fromInternalWrite) {
1162
- throw reactiveErrorFn('Object is readonly!');
1163
- }
1164
- const rawValue = toRaw(newValue);
1165
- const oldValue = target[p];
1166
- const v = this.isShallow ? newValue : rawValue;
1167
- if (oldValue === rawValue) {
1168
- return Reflect.set(target, p, v, receiver);
1169
- }
1170
- const b = Reflect.set(target, p, v, receiver);
1171
- fromInternalWrite = false;
1172
- if (hasOwn(target, p)) {
1173
- trigger(target, exports.TriggerOpTypes.Set, p);
1174
- }
1175
- else {
1176
- trigger(target, exports.TriggerOpTypes.Add, p);
1177
- }
1178
- return b;
1179
- }
1180
- get(target, p, receiver) {
1181
- track(target, exports.TrackOpTypes.Get, p);
1182
- const value = Reflect.get(target, p, receiver);
1183
- if (this.isShallow) {
1184
- return value;
1185
- }
1186
- return reactive(value);
1187
- }
1188
- deleteProperty(target, p) {
1189
- const b = Reflect.deleteProperty(target, p);
1190
- trigger(target, exports.TriggerOpTypes.Delete, p);
1191
- return b;
1192
- }
1193
- ownKeys(target) {
1194
- track(target, exports.TrackOpTypes.Iterate);
1195
- return Reflect.ownKeys(target);
1196
- }
1197
- }
1198
- function noReactive(v) {
1199
- return v;
1200
- }
1201
- class ArrayReactiveHandler extends ObjectReactiveHandler {
1202
- constructor(config) {
1203
- super(config);
1204
- Object.defineProperty(this, "interceptors", {
1205
- enumerable: true,
1206
- configurable: true,
1207
- writable: true,
1208
- value: createArrayHandlers(this.isShallow ? noReactive : reactive)
1209
- });
1210
- }
1211
- get(target, p, receiver) {
1212
- if (Reflect.has(this.interceptors, p) && p in target) {
1213
- return this.interceptors[p];
1214
- }
1215
- return super.get(target, p, receiver);
1216
- }
1217
- }
1218
- class MapReactiveHandler extends ObjectReactiveHandler {
1219
- constructor(config) {
1220
- super(config);
1221
- Object.defineProperty(this, "interceptors", {
1222
- enumerable: true,
1223
- configurable: true,
1224
- writable: true,
1225
- value: createMapHandlers(this.isShallow ? noReactive : reactive)
1226
- });
1227
- }
1228
- get(target, p, receiver) {
1229
- if (Reflect.has(this.interceptors, p) && p in target) {
1230
- return this.interceptors[p];
1231
- }
1232
- if (p === 'size') {
1233
- track(target, exports.TrackOpTypes.Iterate, p);
1234
- return Reflect.get(target, p);
1235
- }
1236
- return super.get(target, p, receiver);
1237
- }
1238
- }
1239
- class SetReactiveHandler extends ObjectReactiveHandler {
1240
- constructor(config) {
1241
- super(config);
1242
- Object.defineProperty(this, "interceptors", {
1243
- enumerable: true,
1244
- configurable: true,
1245
- writable: true,
1246
- value: createSetHandlers(this.isShallow ? noReactive : reactive)
1247
- });
1248
- }
1249
- get(target, p, receiver) {
1250
- if (Reflect.has(this.interceptors, p) && p in target) {
1251
- return this.interceptors[p];
1252
- }
1253
- if (p === 'size') {
1254
- track(target, exports.TrackOpTypes.Iterate, p);
1255
- return Reflect.get(target, p);
1256
- }
1257
- return super.get(target, p, receiver);
1258
- }
1259
- }
1260
- const defaultObjectReactiveHandler = new ObjectReactiveHandler({
1261
- readonly: false,
1262
- shallow: false
1263
- });
1264
- const defaultArrayReactiveHandler = new ArrayReactiveHandler({
1265
- readonly: false,
1266
- shallow: false
1267
- });
1268
- const defaultMapReactiveHandler = new MapReactiveHandler({
1269
- readonly: false,
1270
- shallow: false
1271
- });
1272
- const defaultSetReactiveHandler = new SetReactiveHandler({
1273
- readonly: false,
1274
- shallow: false
1275
- });
1276
- const readonlyProxyHandler = new ObjectReactiveHandler({
1277
- shallow: true,
1278
- readonly: true
1279
- });
1280
- function reactive(raw) {
1281
- if (isReactive(raw)) {
1282
- return raw;
1283
- }
1284
- let proxy = rawToProxyCache.get(raw);
1285
- if (proxy) {
1286
- return proxy;
1287
- }
1288
- const type = getStringType(raw);
1289
- switch (type) {
1290
- case '[object Object]':
1291
- proxy = new Proxy(raw, defaultObjectReactiveHandler);
1292
- break;
1293
- case '[object Array]':
1294
- proxy = new Proxy(raw, defaultArrayReactiveHandler);
1295
- break;
1296
- case '[object Set]':
1297
- case '[object WeakSet]':
1298
- proxy = new Proxy(raw, defaultSetReactiveHandler);
1299
- break;
1300
- case '[object Map]':
1301
- case '[object WeakMap]':
1302
- proxy = new Proxy(raw, defaultMapReactiveHandler);
1303
- break;
1304
- default:
1305
- return raw;
1306
- }
1307
- rawToProxyCache.set(raw, proxy);
1308
- proxyToRawCache.set(proxy, raw);
1309
- return proxy;
1310
- }
1311
-
1312
- function hasChange(newProps, oldProps) {
1313
- const newKeys = Object.keys(oldProps);
1314
- const oldKeys = Object.keys(newProps);
1315
- if (oldKeys.length !== newKeys.length) {
1316
- return true;
1317
- }
1318
- const len = oldKeys.length;
1319
- for (let i = 0; i < len; i++) {
1320
- const key = newKeys[i];
1321
- if (newProps[key] !== oldProps[key]) {
1322
- return true;
1323
- }
1324
- }
1325
- return false;
1326
- }
1327
- const refKey = 'ref';
1328
- function comparePropsWithCallbacks(oldProps, newProps, onDeleted, onAdded, onUpdated) {
1329
- for (const key in oldProps) {
1330
- if (!(key in newProps)) {
1331
- onDeleted(key, oldProps[key]);
1332
- }
1333
- }
1334
- for (const key in newProps) {
1335
- if (!(key in oldProps)) {
1336
- onAdded(key, newProps[key]);
1337
- }
1338
- else if (oldProps[key] !== newProps[key]) {
1339
- onUpdated(key, newProps[key], oldProps[key]);
1340
- }
1341
- }
1342
- }
1343
- function classToString(config) {
1344
- if (typeof config === 'string') {
1345
- return config;
1346
- }
1347
- if (!config) {
1348
- return '';
1349
- }
1350
- if (Array.isArray(config)) {
1351
- const classes = [];
1352
- for (const i of config) {
1353
- const v = classToString(i);
1354
- if (v) {
1355
- classes.push(v);
1356
- }
1357
- }
1358
- return classes.join(' ');
1359
- }
1360
- if (typeof config === 'object') {
1361
- if (config.toString !== Object.prototype.toString && !config.toString.toString().includes('[native code]')) {
1362
- return config.toString();
1363
- }
1364
- const classes = [];
1365
- for (const key in config) {
1366
- if ({}.hasOwnProperty.call(config, key) && config[key]) {
1367
- classes.push(key);
1368
- }
1369
- }
1370
- return classes.join(' ');
1371
- }
1372
- return '';
1373
- }
1374
- function styleToObject(style) {
1375
- if (typeof style !== 'string') {
1376
- return style || {};
1377
- }
1378
- const obj = {};
1379
- style.split(';').map(s => s.split(':')).forEach(v => {
1380
- if (!v[0] || !v[1]) {
1381
- return;
1382
- }
1383
- obj[v[0].trim()] = v[1].trim();
1384
- });
1385
- return obj;
1386
- }
1387
- const TextAtomType = Symbol('Text');
1388
- const ElementAtomType = Symbol('Element');
1389
- const ComponentAtomType = Symbol('Component');
1390
-
1391
- const componentSetupStack = [];
1392
- const componentErrorFn = makeError('component');
1393
- function getSetupContext(need = true) {
1394
- const current = componentSetupStack[componentSetupStack.length - 1];
1395
- if (!current && need) {
1396
- // 防止因外部捕获异常引引起的缓存未清理的问题
1397
- throw componentErrorFn('cannot be called outside the component!');
1398
- }
1399
- return current;
1400
- }
1401
- function toRefs(ref) {
1402
- return (Array.isArray(ref) ? ref : [ref]).filter(i => {
1403
- return i instanceof DynamicRef;
1404
- });
1405
- }
1406
- function createReadonlyProxy(value) {
1407
- return new Proxy(value, readonlyProxyHandler);
1408
- }
1409
- /**
1410
- * Viewfly 组件管理类,用于管理组件的生命周期,上下文等
1411
- */
1412
- class Component {
1413
- get dirty() {
1414
- return this._dirty;
1415
- }
1416
- get changed() {
1417
- return this._changed;
1418
- }
1419
- constructor(parentComponent, type, props, key) {
1420
- this.parentComponent = parentComponent;
1421
- this.type = type;
1422
- this.props = props;
1423
- this.key = key;
1424
- this.instance = null;
1425
- this.changedSubComponents = new Set();
1426
- this.viewMetadata = null;
1427
- this.unmountedCallbacks = null;
1428
- this.mountCallbacks = null;
1429
- this.updatedCallbacks = null;
1430
- this.updatedDestroyCallbacks = null;
1431
- this._dirty = true;
1432
- this._changed = false;
1433
- this.isFirstRendering = true;
1434
- this.refs = null;
1435
- this.rawProps = props;
1436
- this.props = createReadonlyProxy(Object.assign({}, props));
1437
- this.listener = new Dep(() => {
1438
- this.markAsDirtied();
1439
- });
1440
- }
1441
- markAsDirtied() {
1442
- this._dirty = true;
1443
- this.markAsChanged();
1444
- }
1445
- markAsChanged(changedComponent) {
1446
- if (changedComponent) {
1447
- this.changedSubComponents.add(changedComponent);
1448
- }
1449
- if (this._changed) {
1450
- return;
1451
- }
1452
- this._changed = true;
1453
- if (this.parentComponent) {
1454
- this.parentComponent.markAsChanged(this);
1455
- }
1456
- }
1457
- render(update) {
1458
- componentSetupStack.push(this);
1459
- const render = this.type(this.props);
1460
- const isRenderFn = typeof render === 'function';
1461
- this.instance = isRenderFn ? { $render: render } : render;
1462
- const refs = toRefs(this.props.ref);
1463
- if (refs.length) {
1464
- this.refs = refs;
1465
- onMounted(() => {
1466
- const refs = this.refs;
1467
- const length = refs.length;
1468
- for (let i = 0; i < length; i++) {
1469
- const ref = refs[i];
1470
- ref.bind(this.instance);
1471
- }
1472
- return () => {
1473
- const refs = this.refs;
1474
- const length = refs.length;
1475
- for (let i = 0; i < length; i++) {
1476
- const ref = refs[i];
1477
- ref.unBind(this.instance);
1478
- }
1479
- };
1480
- });
1481
- }
1482
- componentSetupStack.pop();
1483
- pushDepContext(this.listener);
1484
- const template = this.instance.$render();
1485
- popDepContext();
1486
- update(template, this.instance.$portalHost);
1487
- this.rendered();
1488
- }
1489
- updateProps(newProps) {
1490
- const oldProps = this.rawProps;
1491
- this.rawProps = newProps;
1492
- const newRefs = toRefs(newProps.ref);
1493
- comparePropsWithCallbacks(oldProps, newProps, key => {
1494
- internalWrite(() => {
1495
- Reflect.deleteProperty(oldProps, key);
1496
- });
1497
- }, (key, value) => {
1498
- internalWrite(() => {
1499
- this.props[key] = value;
1500
- });
1501
- }, (key, value) => {
1502
- internalWrite(() => {
1503
- this.props[key] = value;
1504
- });
1505
- });
1506
- if (this.refs) {
1507
- const len = this.refs.length;
1508
- for (let i = 0; i < len; i++) {
1509
- const oldRef = this.refs[i];
1510
- if (!newRefs.includes(oldRef)) {
1511
- oldRef.unBind(this.instance);
1512
- }
1513
- }
1514
- }
1515
- const len = newRefs.length;
1516
- for (let i = 0; i < len; i++) {
1517
- const newRef = newRefs[i];
1518
- newRef.bind(this.instance);
1519
- }
1520
- if (len) {
1521
- this.refs = newRefs;
1522
- }
1523
- }
1524
- canUpdate(oldProps, newProps) {
1525
- if (typeof this.instance.$useMemo === 'function') {
1526
- if (this.instance.$useMemo(newProps, oldProps)) {
1527
- return false;
1528
- }
1529
- }
1530
- return true;
1531
- }
1532
- rerender() {
1533
- this.listener.destroy();
1534
- pushDepContext(this.listener);
1535
- const template = this.instance.$render();
1536
- popDepContext();
1537
- return template;
1538
- }
1539
- destroy() {
1540
- this.listener.destroy();
1541
- if (this.updatedDestroyCallbacks) {
1542
- this.updatedDestroyCallbacks.forEach(fn => {
1543
- fn();
1544
- });
1545
- }
1546
- if (this.unmountedCallbacks) {
1547
- this.unmountedCallbacks.forEach(fn => {
1548
- fn();
1549
- });
1550
- }
1551
- this.parentComponent =
1552
- this.updatedDestroyCallbacks =
1553
- this.mountCallbacks =
1554
- this.updatedCallbacks =
1555
- this.unmountedCallbacks = null;
1556
- }
1557
- rendered() {
1558
- this.changedSubComponents.clear();
1559
- const is = this.isFirstRendering;
1560
- this.isFirstRendering = false;
1561
- this._dirty = this._changed = false;
1562
- this.invokeUpdatedHooks();
1563
- if (is) {
1564
- this.invokeMountHooks();
1565
- }
1566
- if (this.changed) {
1567
- Promise.resolve().then(() => {
1568
- if (this.parentComponent) {
1569
- this.parentComponent.markAsChanged(this);
1570
- }
1571
- });
1572
- }
1573
- }
1574
- invokeMountHooks() {
1575
- const unmountedCallbacks = [];
1576
- if (this.mountCallbacks) {
1577
- const len = this.mountCallbacks.length;
1578
- for (let i = 0; i < len; ++i) {
1579
- const fn = this.mountCallbacks[i];
1580
- const destroyFn = fn();
1581
- if (typeof destroyFn === 'function') {
1582
- unmountedCallbacks.push(destroyFn);
1583
- }
1584
- }
1585
- }
1586
- if (unmountedCallbacks.length) {
1587
- if (this.unmountedCallbacks) {
1588
- this.unmountedCallbacks.push(...unmountedCallbacks);
1589
- }
1590
- else {
1591
- this.unmountedCallbacks = unmountedCallbacks;
1592
- }
1593
- }
1594
- this.mountCallbacks = null;
1595
- }
1596
- invokeUpdatedHooks() {
1597
- if (this.updatedCallbacks) {
1598
- if (this.updatedDestroyCallbacks) {
1599
- this.updatedDestroyCallbacks.forEach(fn => {
1600
- fn();
1601
- });
1602
- }
1603
- const updatedDestroyCallbacks = [];
1604
- const len = this.updatedCallbacks.length;
1605
- for (let i = 0; i < len; ++i) {
1606
- const fn = this.updatedCallbacks[i];
1607
- const destroyFn = fn();
1608
- if (typeof destroyFn === 'function') {
1609
- updatedDestroyCallbacks.push(destroyFn);
1610
- }
1611
- }
1612
- this.updatedDestroyCallbacks = updatedDestroyCallbacks.length ? updatedDestroyCallbacks : null;
1613
- }
1614
- }
1615
- }
1616
- /**
1617
- * 获取当前组件实例
1618
- */
1619
- function getCurrentInstance() {
1620
- return getSetupContext();
1621
- }
1622
- function registryComponentDestroyCallback(fn) {
1623
- const component = getSetupContext(false);
1624
- if (component) {
1625
- if (!component.unmountedCallbacks) {
1626
- component.unmountedCallbacks = [];
1627
- }
1628
- component.unmountedCallbacks.push(fn);
1629
- }
1630
- }
1631
-
1632
- function Fragment(props) {
1633
- return () => {
1634
- return props.children;
1635
- };
1636
- }
1637
- function jsx(type, props, key) {
1638
- return JSXNodeFactory.createNode(type, props, key);
1639
- }
1640
- const jsxs = jsx;
1641
- const JSXNodeFactory = {
1642
- createNode(type, props, key) {
1643
- return {
1644
- type,
1645
- props,
1646
- key
1647
- };
1648
- }
1649
- };
1650
- /**
1651
- * 给组件的视图元素节点添加自定义属性标记
1652
- * @param marks
1653
- * @param setup
1654
- * @example
1655
- * ```tsx
1656
- * const App = withMark('mark', function(props) {
1657
- * return () => {
1658
- * return <div>...</div>
1659
- * }
1660
- * })
1661
- * ```
1662
- */
1663
- function withMark(marks, setup) {
1664
- if (!marks) {
1665
- return setup;
1666
- }
1667
- return function (props) {
1668
- const componentRenderFn = setup(props);
1669
- const isFn = typeof componentRenderFn === 'function';
1670
- if (isFn) {
1671
- return function () {
1672
- return applyMark(marks, componentRenderFn);
1673
- };
1674
- }
1675
- const oldRender = componentRenderFn.$render;
1676
- componentRenderFn.$render = function () {
1677
- return applyMark(marks, () => {
1678
- return oldRender.call(componentRenderFn);
1679
- });
1680
- };
1681
- return componentRenderFn;
1682
- };
1683
- }
1684
- function applyMark(mark, render) {
1685
- const oldCreateNote = JSXNodeFactory.createNode;
1686
- const spaces = Array.isArray(mark) ? mark : [mark];
1687
- JSXNodeFactory.createNode = function (name, props, key) {
1688
- for (const scopedId of spaces) {
1689
- props[scopedId] = '';
1690
- }
1691
- return oldCreateNote.apply(JSXNodeFactory, [name, props, key]);
1692
- };
1693
- const vDom = render();
1694
- JSXNodeFactory.createNode = oldCreateNote;
1695
- return vDom;
1696
- }
1697
- /**
1698
- * 将子节点渲染到指定节点
1699
- * @param props
1700
- * @example
1701
- * ```tsx
1702
- * function App() {
1703
- * const modal = document.getElementById('modal')!
1704
- * return () => {
1705
- * return (
1706
- * <div>
1707
- * <Portal host={modal}>
1708
- * 这里的内容将渲染到 modal 节点
1709
- * </Portal>
1710
- * </div>
1711
- * )
1712
- * }
1713
- * }
1714
- * ```
1715
- */
1716
- function Portal(props) {
1717
- return {
1718
- $portalHost: props.host,
1719
- $render() {
1720
- return props.children;
1721
- }
1722
- };
1723
- }
1724
-
1725
- function watch(trigger, callback) {
1726
- let prevFn;
1727
- const dep = new Dep(() => {
1728
- pushDepContext(dep);
1729
- const newValue = trigger();
1730
- popDepContext();
1731
- if (newValue === oldValue) {
1732
- return;
1733
- }
1734
- if (prevFn) {
1735
- prevFn();
1736
- }
1737
- prevFn = callback(newValue, oldValue);
1738
- oldValue = newValue;
1739
- });
1740
- pushDepContext(dep);
1741
- let oldValue = trigger();
1742
- popDepContext();
1743
- dep.destroyCallbacks.push(() => {
1744
- prevFn === null || prevFn === void 0 ? void 0 : prevFn();
1745
- });
1746
- function unWatch() {
1747
- dep.destroy();
1748
- }
1749
- registryComponentDestroyCallback(unWatch);
1750
- return unWatch;
1751
- }
1752
-
1753
- const injectMap = new WeakMap();
1754
- function getInjector(start) {
1755
- while (start) {
1756
- const injector = injectMap.get(start);
1757
- if (injector) {
1758
- return injector;
1759
- }
1760
- start = start.parentComponent;
1761
- }
1762
- return new NullInjector();
1763
- }
1764
- function createContext(providers, scope, parentInjector) {
1765
- return function context(props) {
1766
- const instance = getCurrentInstance();
1767
- const injector = new ReflectiveInjector(parentInjector || getInjector(instance), providers, scope);
1768
- injectMap.set(instance, injector);
1769
- return () => {
1770
- return props.children;
1771
- };
1772
- };
1773
- }
1774
- function createContextProvider(params) {
1775
- return function contextProvider(props) {
1776
- let Context = createContext([Object.assign({ provide: params.provide }, props)]);
1777
- watch(() => {
1778
- return props.useClass || props.useFactory || props.useValue || props.useExisting;
1779
- }, () => {
1780
- Context = createContext([Object.assign({ provide: params.provide }, props)]);
1781
- });
1782
- return () => {
1783
- return jsx(Context, { children: props.children });
1784
- };
1785
- };
1786
- }
1787
- /**
1788
- * 通过组件上下文获取 IoC 容器内数据的勾子方法
1789
- */
1790
- function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
1791
- const component = getCurrentInstance();
1792
- const injector = getInjector(component);
1793
- return injector.get(token, notFoundValue, flags);
1794
- }
1795
- /**
1796
- * 给组件添加注解
1797
- * @param annotation
1798
- * @param componentSetup
1799
- * @example
1800
- * ```ts
1801
- * export customScope = new Scope('scopeName')
1802
- * export const App = withAnnotation({
1803
- * scope: customScope,
1804
- * providers: [
1805
- * ExampleService
1806
- * ]
1807
- * }, function(props: Props) {
1808
- * return () => {
1809
- * return <div>...</div>
1810
- * }
1811
- * })
1812
- * ```
1813
- */
1814
- function withAnnotation(annotation, componentSetup) {
1815
- return function (props) {
1816
- const instance = getCurrentInstance();
1817
- const parentInjector = injectMap.get(instance) || getInjector(instance.parentComponent);
1818
- const injector = new ReflectiveInjector(parentInjector, [{
1819
- provide: Injector,
1820
- useFactory() {
1821
- return injector;
1822
- }
1823
- }, ...(annotation.providers || [])], annotation.scope);
1824
- injectMap.set(instance, injector);
1825
- return componentSetup(props);
1826
- };
1827
- }
1828
-
1829
- class NativeRenderer {
1830
- }
1831
-
1832
- /**
1833
- * @deprecated 即将弃用,Viewfly 默认就有 memo 的效果
1834
- * @param canUseMemo
1835
- * @param render
1836
- */
1837
- function withMemo(canUseMemo, render) {
1838
- return {
1839
- $useMemo: canUseMemo,
1840
- $render: render
1841
- };
1842
- }
1843
-
1844
- const listenerReg = /^on[A-Z]/;
1845
- function createRenderer(component, nativeRenderer, namespace) {
1846
- let isInit = true;
1847
- return function render(host) {
1848
- if (isInit) {
1849
- isInit = false;
1850
- const atom = {
1851
- type: ComponentAtomType,
1852
- index: 0,
1853
- nodeType: component.type,
1854
- jsxNode: component,
1855
- sibling: null,
1856
- child: null,
1857
- nativeNode: null,
1858
- namespace
1859
- };
1860
- componentRender(nativeRenderer, component, atom, {
1861
- isParent: true,
1862
- host,
1863
- rootHost: host
1864
- });
1865
- }
1866
- else {
1867
- deepUpdateByComponentDirtyTree(nativeRenderer, component, false);
1868
- }
1869
- };
1870
- }
1871
- function buildView(nativeRenderer, parentComponent, atom, context) {
1872
- const { jsxNode, type } = atom;
1873
- if (type === ComponentAtomType) {
1874
- const component = new Component(parentComponent, jsxNode.type, jsxNode.props, jsxNode.key);
1875
- atom.jsxNode = component;
1876
- componentRender(nativeRenderer, component, atom, context);
1877
- }
1878
- else if (type === ElementAtomType) {
1879
- createElement(nativeRenderer, atom, parentComponent, context);
1880
- }
1881
- else {
1882
- createTextNode(nativeRenderer, atom, context);
1883
- }
1884
- }
1885
- function buildElementChildren(atom, nativeRenderer, parentComponent, context) {
1886
- let child = atom.child;
1887
- while (child) {
1888
- buildView(nativeRenderer, parentComponent, child, context);
1889
- child = child.sibling;
1890
- }
1891
- }
1892
- function patchComponent(nativeRenderer, component, oldChildAtom, newAtom, context, needMove) {
1893
- const newTemplate = component.rerender();
1894
- newAtom.child = createChildChain(newTemplate, nativeRenderer, newAtom.namespace);
1895
- diff(nativeRenderer, component, newAtom.child, oldChildAtom, context, needMove);
1896
- }
1897
- function deepUpdateByComponentDirtyTree(nativeRenderer, component, needMove) {
1898
- if (component.dirty) {
1899
- const canUpdate = component.canUpdate(component.props, component.props);
1900
- if (canUpdate) {
1901
- const { atom, host, isParent, rootHost } = component.viewMetadata;
1902
- const context = {
1903
- host,
1904
- isParent,
1905
- rootHost
1906
- };
1907
- const diffAtom = atom.child;
1908
- patchComponent(nativeRenderer, component, diffAtom, atom, context, needMove);
1909
- const next = atom.sibling;
1910
- if (next && next.jsxNode instanceof Component) {
1911
- const view = next.jsxNode.viewMetadata;
1912
- view.host = context.host;
1913
- view.isParent = context.isParent;
1914
- }
1915
- }
1916
- component.rendered();
1917
- }
1918
- else if (component.changed) {
1919
- component.changedSubComponents.forEach(child => {
1920
- deepUpdateByComponentDirtyTree(nativeRenderer, child, needMove);
1921
- });
1922
- component.rendered();
1923
- }
1924
- }
1925
- function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, needMove) {
1926
- const commits = [];
1927
- while (newAtom) {
1928
- oldAtom = createChanges(newAtom, oldAtom, commits);
1929
- newAtom = newAtom.sibling;
1930
- }
1931
- let dirtyDiffAtom = oldAtom;
1932
- while (dirtyDiffAtom) {
1933
- cleanView(nativeRenderer, dirtyDiffAtom, true);
1934
- dirtyDiffAtom = dirtyDiffAtom.sibling;
1935
- }
1936
- let offset = 0;
1937
- const len = commits.length;
1938
- for (let i = 0; i < len; i++) {
1939
- while (oldAtom) {
1940
- if (oldAtom.index <= i) {
1941
- offset--;
1942
- oldAtom = oldAtom.sibling;
1943
- continue;
1944
- }
1945
- break;
1946
- }
1947
- const { dirtyAtom, newAtom } = commits[i];
1948
- if (dirtyAtom) {
1949
- switch (dirtyAtom.type) {
1950
- case ElementAtomType:
1951
- updateElement(nativeRenderer, context, parentComponent, offset, needMove, newAtom, dirtyAtom);
1952
- break;
1953
- case TextAtomType:
1954
- updateText(nativeRenderer, context, offset, needMove, newAtom, dirtyAtom);
1955
- break;
1956
- case ComponentAtomType:
1957
- updateComponent(nativeRenderer, context, offset, needMove, newAtom, dirtyAtom);
1958
- break;
1959
- }
1960
- }
1961
- else {
1962
- buildView(nativeRenderer, parentComponent, newAtom, context);
1963
- offset++;
1964
- }
1965
- }
1966
- }
1967
- function createChanges(newAtom, oldAtom, commits) {
1968
- const startDiffAtom = oldAtom;
1969
- let prev = null;
1970
- while (oldAtom) {
1971
- if (oldAtom.type === newAtom.type && oldAtom.nodeType === newAtom.nodeType && oldAtom.key === newAtom.key) {
1972
- commits.push({
1973
- dirtyAtom: oldAtom,
1974
- newAtom
1975
- });
1976
- const next = oldAtom.sibling;
1977
- if (!prev) {
1978
- return next;
1979
- }
1980
- prev.sibling = next;
1981
- return startDiffAtom;
1982
- }
1983
- prev = oldAtom;
1984
- oldAtom = oldAtom.sibling;
1985
- }
1986
- commits.push({
1987
- dirtyAtom: null,
1988
- newAtom
1989
- });
1990
- return startDiffAtom;
1991
- }
1992
- function updateText(nativeRenderer, context, offset, needMove, newAtom, oldAtom) {
1993
- const nativeNode = oldAtom.nativeNode;
1994
- newAtom.nativeNode = nativeNode;
1995
- if (needMove || newAtom.index - offset !== oldAtom.index) {
1996
- insertNode(nativeRenderer, newAtom, context);
1997
- }
1998
- context.host = nativeNode;
1999
- context.isParent = false;
2000
- }
2001
- function updateElement(nativeRenderer, context, parentComponent, offset, needMove, newAtom, oldAtom) {
2002
- const nativeNode = oldAtom.nativeNode;
2003
- newAtom.nativeNode = nativeNode;
2004
- if (needMove || newAtom.index - offset !== oldAtom.index) {
2005
- insertNode(nativeRenderer, newAtom, context);
2006
- }
2007
- context.host = nativeNode;
2008
- context.isParent = false;
2009
- updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComponent, {
2010
- host: nativeNode,
2011
- isParent: true,
2012
- rootHost: context.rootHost
2013
- });
2014
- }
2015
- function updateComponent(nativeRenderer, context, offset, needMove, newAtom, oldAtom) {
2016
- const component = oldAtom.jsxNode;
2017
- const portalHost = component.instance.$portalHost;
2018
- context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
2019
- component.viewMetadata = Object.assign({ atom: newAtom }, context);
2020
- const newProps = newAtom.jsxNode.props;
2021
- newAtom.jsxNode = component;
2022
- needMove = needMove || newAtom.index - offset !== oldAtom.index;
2023
- const canUpdate = component.canUpdate(component.props, newProps);
2024
- const propsIsChanged = hasChange(newProps, component.props);
2025
- if (propsIsChanged) {
2026
- component.updateProps(newProps);
2027
- }
2028
- if (canUpdate && (propsIsChanged || component.dirty)) {
2029
- patchComponent(nativeRenderer, component, oldAtom.child, newAtom, context, needMove);
2030
- const next = oldAtom.sibling;
2031
- if (next && next.jsxNode instanceof Component) {
2032
- const view = next.jsxNode.viewMetadata;
2033
- view.host = context.host;
2034
- view.isParent = context.isParent;
2035
- }
2036
- }
2037
- else {
2038
- newAtom.child = oldAtom.child;
2039
- reuseComponentView(nativeRenderer, newAtom.child, context, needMove, !canUpdate || !component.changedSubComponents.size);
2040
- }
2041
- component.rendered();
2042
- }
2043
- function reuseComponentView(nativeRenderer, child, context, moveView, skipSubComponentDiff) {
2044
- const updateContext = (atom) => {
2045
- const jsxNode = atom.jsxNode;
2046
- if (jsxNode instanceof Component) {
2047
- reuseComponentView(nativeRenderer, atom.child, context, moveView, skipSubComponentDiff);
2048
- if (!skipSubComponentDiff) {
2049
- deepUpdateByComponentDirtyTree(nativeRenderer, jsxNode, moveView);
2050
- }
2051
- }
2052
- else {
2053
- if (moveView) {
2054
- insertNode(nativeRenderer, atom, context);
2055
- }
2056
- if (!skipSubComponentDiff) {
2057
- reuseElementChildrenView(nativeRenderer, atom);
2058
- }
2059
- context.isParent = false;
2060
- context.host = atom.nativeNode;
2061
- }
2062
- };
2063
- while (child) {
2064
- updateContext(child);
2065
- child = child.sibling;
2066
- }
2067
- }
2068
- function reuseElementChildrenView(nativeRenderer, atom, context) {
2069
- let child = atom.child;
2070
- while (child) {
2071
- if (child.jsxNode instanceof Component) {
2072
- deepUpdateByComponentDirtyTree(nativeRenderer, child.jsxNode, false);
2073
- }
2074
- else {
2075
- reuseElementChildrenView(nativeRenderer, child);
2076
- }
2077
- child = child.sibling;
2078
- }
2079
- }
2080
- function cleanElementChildren(atom, nativeRenderer) {
2081
- let child = atom.child;
2082
- nativeRenderer.cleanChildren(atom.nativeNode, atom.namespace);
2083
- while (child) {
2084
- cleanView(nativeRenderer, child, false);
2085
- child = child.sibling;
2086
- }
2087
- }
2088
- function cleanView(nativeRenderer, atom, needClean) {
2089
- if (atom.type === ComponentAtomType) {
2090
- const jsxNode = atom.jsxNode;
2091
- if (jsxNode.instance.$portalHost) {
2092
- needClean = true;
2093
- }
2094
- cleanChildren(atom, nativeRenderer, needClean);
2095
- jsxNode.destroy();
2096
- return;
2097
- }
2098
- if (needClean) {
2099
- nativeRenderer.remove(atom.nativeNode, atom.namespace);
2100
- needClean = false;
2101
- }
2102
- if (atom.type === ElementAtomType) {
2103
- const ref = atom.jsxNode.props[refKey];
2104
- applyRefs(ref, atom.nativeNode, false);
2105
- }
2106
- cleanChildren(atom, nativeRenderer, needClean);
2107
- }
2108
- function cleanChildren(atom, nativeRenderer, needClean) {
2109
- let child = atom.child;
2110
- while (child) {
2111
- cleanView(nativeRenderer, child, needClean);
2112
- child = child.sibling;
2113
- }
2114
- }
2115
- function componentRender(nativeRenderer, component, from, context) {
2116
- component.render((template, portalHost) => {
2117
- from.child = createChildChain(template, nativeRenderer, from.namespace);
2118
- context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
2119
- component.viewMetadata = Object.assign({ atom: from }, context);
2120
- let child = from.child;
2121
- while (child) {
2122
- buildView(nativeRenderer, component, child, context);
2123
- child = child.sibling;
2124
- }
2125
- });
2126
- }
2127
- function createChainByJSXNode(type, jsxNode, nodeType, prevAtom, namespace, key) {
2128
- const atom = {
2129
- type,
2130
- index: prevAtom.index + 1,
2131
- jsxNode,
2132
- sibling: null,
2133
- child: null,
2134
- nativeNode: null,
2135
- namespace,
2136
- nodeType,
2137
- key
2138
- };
2139
- prevAtom.sibling = atom;
2140
- return atom;
2141
- }
2142
- function createChainByNode(jsxNode, prevAtom, nativeRenderer, elementNamespace) {
2143
- const type = typeof jsxNode;
2144
- if (jsxNode != null && type !== 'boolean') {
2145
- if (type === 'string') {
2146
- return createChainByJSXNode(TextAtomType, jsxNode, jsxNode, prevAtom, elementNamespace);
2147
- }
2148
- if (type === 'object') {
2149
- if (Array.isArray(jsxNode)) {
2150
- return createChainByChildren(jsxNode, prevAtom, nativeRenderer, elementNamespace);
2151
- }
2152
- const nodeType = typeof jsxNode.type;
2153
- if (nodeType === 'string') {
2154
- return createChainByJSXNode(ElementAtomType, jsxNode, jsxNode.type, prevAtom, nativeRenderer.getNameSpace(jsxNode.type, elementNamespace), jsxNode.key);
2155
- }
2156
- else if (nodeType === 'function') {
2157
- return createChainByJSXNode(ComponentAtomType, jsxNode, jsxNode.type, prevAtom, elementNamespace, jsxNode.key);
2158
- }
2159
- }
2160
- const text = String(jsxNode);
2161
- return createChainByJSXNode(TextAtomType, text, text, prevAtom, elementNamespace);
2162
- }
2163
- return prevAtom;
2164
- }
2165
- function createChainByChildren(children, prevAtom, nativeRenderer, elementNamespace) {
2166
- const len = children.length;
2167
- for (let i = 0; i < len; i++) {
2168
- const item = children[i];
2169
- prevAtom = createChainByNode(item, prevAtom, nativeRenderer, elementNamespace);
2170
- }
2171
- return prevAtom;
2172
- }
2173
- function createChildChain(template, nativeRenderer, namespace) {
2174
- const beforeAtom = { sibling: null, index: -1 };
2175
- createChainByNode(template, beforeAtom, nativeRenderer, namespace);
2176
- return beforeAtom.sibling;
2177
- }
2178
- function insertNode(nativeRenderer, atom, context) {
2179
- if (context.isParent) {
2180
- if (context.host === context.rootHost) {
2181
- nativeRenderer.appendChild(context.host, atom.nativeNode, atom.namespace);
2182
- }
2183
- else {
2184
- nativeRenderer.prependChild(context.host, atom.nativeNode, atom.namespace);
2185
- }
2186
- }
2187
- else {
2188
- nativeRenderer.insertAfter(atom.nativeNode, context.host, atom.namespace);
2189
- }
2190
- }
2191
- function createElementChildren(type, children, nativeRenderer, namespace) {
2192
- const ns = nativeRenderer.getNameSpace(type, namespace);
2193
- return createChildChain(children, nativeRenderer, ns);
2194
- }
2195
- function createElement(nativeRenderer, atom, parentComponent, context) {
2196
- const { namespace, jsxNode } = atom;
2197
- const nativeNode = nativeRenderer.createElement(jsxNode.type, namespace);
2198
- const props = jsxNode.props;
2199
- let bindingRefs;
2200
- for (const key in props) {
2201
- if (key === 'children') {
2202
- atom.child = createElementChildren(jsxNode.type, props.children, nativeRenderer, namespace);
2203
- continue;
2204
- }
2205
- if (key === 'class') {
2206
- const className = classToString(props[key]);
2207
- if (className) {
2208
- nativeRenderer.setClass(nativeNode, className, namespace);
2209
- }
2210
- continue;
2211
- }
2212
- if (key === 'style') {
2213
- const style = styleToObject(props.style);
2214
- for (const key in style) {
2215
- nativeRenderer.setStyle(nativeNode, key, style[key], namespace);
2216
- }
2217
- continue;
2218
- }
2219
- if (listenerReg.test(key)) {
2220
- const listener = props[key];
2221
- if (typeof listener === 'function') {
2222
- nativeRenderer.listen(nativeNode, key, listener, namespace);
2223
- }
2224
- continue;
2225
- }
2226
- if (key === refKey) {
2227
- bindingRefs = props[key];
2228
- continue;
2229
- }
2230
- nativeRenderer.setProperty(nativeNode, key, props[key], namespace);
2231
- }
2232
- atom.nativeNode = nativeNode;
2233
- insertNode(nativeRenderer, atom, context);
2234
- buildElementChildren(atom, nativeRenderer, parentComponent, {
2235
- isParent: true,
2236
- host: nativeNode,
2237
- rootHost: context.rootHost
2238
- });
2239
- context.host = nativeNode;
2240
- context.isParent = false;
2241
- applyRefs(bindingRefs, nativeNode, true);
2242
- }
2243
- function createTextNode(nativeRenderer, atom, context) {
2244
- const nativeNode = nativeRenderer.createTextNode(atom.jsxNode, atom.namespace);
2245
- atom.nativeNode = nativeNode;
2246
- insertNode(nativeRenderer, atom, context);
2247
- context.host = nativeNode;
2248
- context.isParent = false;
2249
- }
2250
- function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComponent, context) {
2251
- const newVNode = newAtom.jsxNode;
2252
- const isSvg = newAtom.namespace;
2253
- const nativeNode = newAtom.nativeNode;
2254
- const oldVNode = oldAtom.jsxNode;
2255
- if (newVNode === oldVNode) {
2256
- newAtom.child = oldAtom.child;
2257
- reuseElementChildrenView(nativeRenderer, newAtom);
2258
- return;
2259
- }
2260
- let unBindRefs;
2261
- let bindRefs;
2262
- let updatedChildren = false;
2263
- comparePropsWithCallbacks(oldVNode.props, newVNode.props, (key, oldValue) => {
2264
- if (key === 'children') {
2265
- updatedChildren = true;
2266
- cleanElementChildren(oldAtom, nativeRenderer);
2267
- return;
2268
- }
2269
- if (key === 'class') {
2270
- nativeRenderer.setClass(nativeNode, '', isSvg);
2271
- return;
2272
- }
2273
- if (key === 'style') {
2274
- for (const styleName in styleToObject(oldValue)) {
2275
- nativeRenderer.removeStyle(nativeNode, styleName, isSvg);
2276
- }
2277
- return;
2278
- }
2279
- if (listenerReg.test(key)) {
2280
- if (typeof oldValue === 'function') {
2281
- nativeRenderer.unListen(nativeNode, key, oldValue, isSvg);
2282
- }
2283
- return;
2284
- }
2285
- if (key === refKey) {
2286
- unBindRefs = oldValue;
2287
- return;
2288
- }
2289
- nativeRenderer.removeProperty(nativeNode, key, isSvg);
2290
- }, (key, value) => {
2291
- if (key === 'children') {
2292
- updatedChildren = true;
2293
- newAtom.child = createElementChildren(newVNode.type, value, nativeRenderer, isSvg);
2294
- buildElementChildren(newAtom, nativeRenderer, parentComponent, context);
2295
- return;
2296
- }
2297
- if (key === 'class') {
2298
- nativeRenderer.setClass(nativeNode, classToString(value), isSvg);
2299
- return;
2300
- }
2301
- if (key === 'style') {
2302
- const styleObj = styleToObject(value);
2303
- for (const styleName in styleObj) {
2304
- nativeRenderer.setStyle(nativeNode, styleName, styleObj[styleName], isSvg);
2305
- }
2306
- return;
2307
- }
2308
- if (listenerReg.test(key)) {
2309
- if (typeof value === 'function') {
2310
- nativeRenderer.listen(nativeNode, key, value, isSvg);
2311
- }
2312
- return;
2313
- }
2314
- if (key === refKey) {
2315
- bindRefs = value;
2316
- return;
2317
- }
2318
- nativeRenderer.setProperty(nativeNode, key, value, isSvg);
2319
- }, (key, newValue, oldValue) => {
2320
- if (key === 'children') {
2321
- updatedChildren = true;
2322
- newAtom.child = createElementChildren(newVNode.type, newValue, nativeRenderer, isSvg);
2323
- if (!newAtom.child) {
2324
- cleanElementChildren(oldAtom, nativeRenderer);
2325
- }
2326
- else if (!oldAtom.child) {
2327
- buildElementChildren(newAtom, nativeRenderer, parentComponent, context);
2328
- }
2329
- else {
2330
- diff(nativeRenderer, parentComponent, newAtom.child, oldAtom.child, context, false);
2331
- }
2332
- return;
2333
- }
2334
- if (key === 'class') {
2335
- const oldClassName = classToString(oldValue);
2336
- const newClassName = classToString(newValue);
2337
- if (oldClassName !== newClassName) {
2338
- nativeRenderer.setClass(nativeNode, newClassName, isSvg);
2339
- }
2340
- return;
2341
- }
2342
- if (key === 'style') {
2343
- comparePropsWithCallbacks(styleToObject(oldValue), styleToObject(newValue), styleName => {
2344
- nativeRenderer.removeStyle(nativeNode, styleName, isSvg);
2345
- }, (styleName, styleValue) => {
2346
- nativeRenderer.setStyle(nativeNode, styleName, styleValue, isSvg);
2347
- }, (styleName, styleValue) => {
2348
- nativeRenderer.setStyle(nativeNode, styleName, styleValue, isSvg);
2349
- });
2350
- return;
2351
- }
2352
- if (listenerReg.test(key)) {
2353
- nativeRenderer.unListen(nativeNode, key, oldValue, isSvg);
2354
- nativeRenderer.listen(nativeNode, key, newValue, isSvg);
2355
- return;
2356
- }
2357
- if (key === refKey) {
2358
- unBindRefs = oldValue;
2359
- bindRefs = newValue;
2360
- return;
2361
- }
2362
- nativeRenderer.setProperty(nativeNode, key, newValue, isSvg);
2363
- });
2364
- if (!updatedChildren) {
2365
- newAtom.child = oldAtom.child;
2366
- // reuseElementChildrenView(nativeRenderer, newAtom, context)
2367
- }
2368
- applyRefs(unBindRefs, nativeNode, false);
2369
- applyRefs(bindRefs, nativeNode, true);
2370
- }
2371
- function applyRefs(refs, nativeNode, binding) {
2372
- if (refs) {
2373
- const refList = Array.isArray(refs) ? refs : [refs];
2374
- const len = refList.length;
2375
- for (let i = 0; i < len; i++) {
2376
- const item = refList[i];
2377
- if (item instanceof DynamicRef) {
2378
- binding ? item.bind(nativeNode) : item.unBind(nativeNode);
2379
- }
2380
- }
2381
- }
2382
- }
2383
-
2384
- /**
2385
- * Viewfly 根组件,用于实现组件状态更新事件通知
2386
- */
2387
- class RootComponent extends Component {
2388
- constructor(factory, refresh) {
2389
- super(null, factory, {});
2390
- Object.defineProperty(this, "refresh", {
2391
- enumerable: true,
2392
- configurable: true,
2393
- writable: true,
2394
- value: refresh
2395
- });
2396
- }
2397
- markAsChanged(changedComponent) {
2398
- this._changed = true;
2399
- if (changedComponent) {
2400
- this.changedSubComponents.add(changedComponent);
2401
- }
2402
- this.refresh();
2403
- }
2404
- }
2405
-
2406
- const viewflyErrorFn = makeError('Viewfly');
2407
- function viewfly(config) {
2408
- const { context, nativeRenderer, autoUpdate, root } = Object.assign({ autoUpdate: true }, config);
2409
- const modules = [];
2410
- let destroyed = false;
2411
- let appHost = null;
2412
- const rootProviders = [];
2413
- const rootComponent = new RootComponent(() => {
2414
- const rootContext = createContext(rootProviders, null, context);
2415
- return () => {
2416
- return jsx(rootContext, {
2417
- children: destroyed ? null : root
2418
- });
2419
- };
2420
- }, function () {
2421
- if (destroyed || !autoUpdate) {
2422
- return;
2423
- }
2424
- nextTick(() => {
2425
- render(appHost);
2426
- });
2427
- });
2428
- const render = createRenderer(rootComponent, nativeRenderer, config.elementNamespace);
2429
- let isStarted = false;
2430
- let task = null;
2431
- function nextTick(callback) {
2432
- if (task !== null) {
2433
- return;
2434
- }
2435
- task = Promise.resolve().then(() => {
2436
- task = null;
2437
- callback();
2438
- });
2439
- }
2440
- const app = {
2441
- provide(providers) {
2442
- providers = Array.isArray(providers) ? providers : [providers];
2443
- rootProviders.push(...providers);
2444
- return app;
2445
- },
2446
- use(module) {
2447
- if (Array.isArray(module)) {
2448
- modules.push(...module);
2449
- }
2450
- else {
2451
- modules.push(module);
2452
- }
2453
- return app;
2454
- },
2455
- mount(host) {
2456
- var _a, _b;
2457
- if (isStarted) {
2458
- throw viewflyErrorFn('application has already started.');
2459
- }
2460
- for (const module of modules) {
2461
- (_a = module.setup) === null || _a === void 0 ? void 0 : _a.call(module, app);
2462
- }
2463
- isStarted = true;
2464
- appHost = host;
2465
- render(host);
2466
- for (const module of modules) {
2467
- (_b = module.onAfterStartup) === null || _b === void 0 ? void 0 : _b.call(module, app);
2468
- }
2469
- if (!autoUpdate) {
2470
- return app;
2471
- }
2472
- return app;
2473
- },
2474
- render() {
2475
- if (appHost) {
2476
- render(appHost);
2477
- }
2478
- return app;
2479
- },
2480
- destroy() {
2481
- var _a;
2482
- destroyed = true;
2483
- rootComponent.markAsDirtied();
2484
- app.render();
2485
- for (const module of modules) {
2486
- (_a = module.onDestroy) === null || _a === void 0 ? void 0 : _a.call(module);
2487
- }
2488
- }
2489
- };
2490
- return app;
2491
- }
2492
-
2493
- function computed(callback, isContinue) {
2494
- let isStop = false;
2495
- const dep = new Dep(() => {
2496
- if (isStop) {
2497
- return;
2498
- }
2499
- isStop = true;
2500
- dep.destroy();
2501
- pushDepContext(dep);
2502
- const value = callback();
2503
- popDepContext();
2504
- internalWrite(() => {
2505
- proxy.value = value;
2506
- });
2507
- canListen(value);
2508
- isStop = false;
2509
- });
2510
- pushDepContext(dep);
2511
- const value = callback();
2512
- popDepContext();
2513
- const proxy = new Proxy({
2514
- value
2515
- }, readonlyProxyHandler);
2516
- function canListen(value) {
2517
- if (isContinue) {
2518
- const b = isContinue(value);
2519
- if (b === false) {
2520
- dep.destroy();
2521
- return false;
2522
- }
2523
- }
2524
- return true;
2525
- }
2526
- if (!canListen(value)) {
2527
- return proxy;
2528
- }
2529
- registryComponentDestroyCallback(() => {
2530
- dep.destroy();
2531
- });
2532
- return proxy;
2533
- }
2534
-
2535
- const defaultShallowObjectReactiveHandler = new ObjectReactiveHandler({
2536
- readonly: false,
2537
- shallow: true
2538
- });
2539
- const defaultShallowArrayReactiveHandler = new ArrayReactiveHandler({
2540
- readonly: false,
2541
- shallow: true
2542
- });
2543
- const defaultShallowMapReactiveHandler = new MapReactiveHandler({
2544
- readonly: false,
2545
- shallow: true
2546
- });
2547
- const defaultShallowSetReactiveHandler = new SetReactiveHandler({
2548
- readonly: false,
2549
- shallow: true
2550
- });
2551
- function shallowReactive(raw) {
2552
- if (isReactive(raw)) {
2553
- return raw;
2554
- }
2555
- let proxy = rawToProxyCache.get(raw);
2556
- if (proxy) {
2557
- return proxy;
2558
- }
2559
- const type = getStringType(raw);
2560
- switch (type) {
2561
- case '[object Object]':
2562
- proxy = new Proxy(raw, defaultShallowObjectReactiveHandler);
2563
- break;
2564
- case '[object Array]':
2565
- proxy = new Proxy(raw, defaultShallowArrayReactiveHandler);
2566
- break;
2567
- case '[object Set]':
2568
- case '[object WeakSet]':
2569
- proxy = new Proxy(raw, defaultShallowSetReactiveHandler);
2570
- break;
2571
- case '[object Map]':
2572
- case '[object WeakMap]':
2573
- proxy = new Proxy(raw, defaultShallowMapReactiveHandler);
2574
- break;
2575
- default:
2576
- return raw;
2577
- }
2578
- rawToProxyCache.set(raw, proxy);
2579
- proxyToRawCache.set(proxy, raw);
2580
- return proxy;
2581
- }
2582
-
2583
- /**
2584
- * 组件状态管理器
2585
- * @param state 初始状态
2586
- * @example
2587
- * ```tsx
2588
- * function App() {
2589
- * // 初始化状态
2590
- * const state = createSignal(1)
2591
- *
2592
- * return () => {
2593
- * <div>
2594
- * <div>当前值为:{state()}</div>
2595
- * <div>
2596
- * <button type="button" onClick={() => {
2597
- * // 当点击时更新状态
2598
- * state.set(state() + 1)
2599
- * }
2600
- * }>updateState</button>
2601
- * </div>
2602
- * </div>
2603
- * }
2604
- * }
2605
- */
2606
- function createSignal(state) {
2607
- const subscribers = new Set();
2608
- function signal() {
2609
- const listener = getDepContext();
2610
- if (listener && !subscribers.has(listener)) {
2611
- listener.destroyCallbacks.push(() => {
2612
- subscribers.delete(listener);
2613
- });
2614
- subscribers.add(listener);
2615
- }
2616
- return state;
2617
- }
2618
- signal.set = function (newValue) {
2619
- if (newValue === state) {
2620
- return;
2621
- }
2622
- state = newValue;
2623
- const listeners = Array.from(subscribers);
2624
- listeners.forEach(listener => listener.effect());
2625
- };
2626
- return signal;
2627
- }
2628
-
2629
- /**
2630
- * 使用派生值,Viewfly 会收集回调函数内同步执行时访问的 Signal,
2631
- * 并在你获取 createDerived 函数返回的 Signal 的值时,自动计算最新的值。
2632
- *
2633
- * @param fn
2634
- * @param isContinue 可选的停止函数,在每次值更新后调用,当返回值为 false 时,将不再监听依赖的变化
2635
- */
2636
- function createDerived(fn, isContinue) {
2637
- let isStop = false;
2638
- function canListen(value) {
2639
- if (isContinue) {
2640
- const b = isContinue(value);
2641
- if (b === false) {
2642
- listener.destroy();
2643
- return false;
2644
- }
2645
- }
2646
- return true;
2647
- }
2648
- const listener = new Dep(() => {
2649
- if (isStop) {
2650
- return;
2651
- }
2652
- isStop = true;
2653
- listener.destroy();
2654
- pushDepContext(listener);
2655
- const value = fn();
2656
- popDepContext();
2657
- signal.set(value);
2658
- canListen(value);
2659
- isStop = false;
2660
- });
2661
- pushDepContext(listener);
2662
- const value = fn();
2663
- const signal = createSignal(value);
2664
- popDepContext();
2665
- isStop = false;
2666
- if (canListen(value)) {
2667
- registryComponentDestroyCallback(() => listener.destroy());
2668
- }
2669
- return signal;
2670
- }
2671
-
2672
- /* eslint-enable max-len*/
2673
- function createEffect(deps, callback) {
2674
- let prevFn;
2675
- const isArray = Array.isArray(deps);
2676
- const effect = new Dep(function () {
2677
- if (prevFn) {
2678
- prevFn();
2679
- }
2680
- const newValue = isArray ? deps.map(fn => fn()) : deps();
2681
- prevFn = callback(newValue, oldValue);
2682
- oldValue = newValue;
2683
- });
2684
- pushDepContext(effect);
2685
- let oldValue = isArray ? deps.map(fn => fn()) : deps();
2686
- popDepContext();
2687
- let isUnWatch = false;
2688
- function unWatch() {
2689
- if (isUnWatch) {
2690
- return;
2691
- }
2692
- isUnWatch = true;
2693
- if (prevFn) {
2694
- prevFn();
2695
- }
2696
- effect.destroy();
2697
- }
2698
- registryComponentDestroyCallback(unWatch);
2699
- return unWatch;
2700
- }
2701
-
2702
- exports.ArrayReactiveHandler = ArrayReactiveHandler;
2703
- exports.Component = Component;
2704
- exports.Dep = Dep;
2705
- exports.DynamicRef = DynamicRef;
2706
- exports.ForwardRef = ForwardRef;
2707
- exports.Fragment = Fragment;
2708
- exports.Inject = Inject;
2709
- exports.Injectable = Injectable;
2710
- exports.InjectionToken = InjectionToken;
2711
- exports.Injector = Injector;
2712
- exports.JSXNodeFactory = JSXNodeFactory;
2713
- exports.MapReactiveHandler = MapReactiveHandler;
2714
- exports.NativeRenderer = NativeRenderer;
2715
- exports.NullInjector = NullInjector;
2716
- exports.ObjectReactiveHandler = ObjectReactiveHandler;
2717
- exports.Optional = Optional;
2718
- exports.Portal = Portal;
2719
- exports.Prop = Prop;
2720
- exports.ReflectiveInjector = ReflectiveInjector;
2721
- exports.RootComponent = RootComponent;
2722
- exports.Scope = Scope;
2723
- exports.Self = Self;
2724
- exports.SetReactiveHandler = SetReactiveHandler;
2725
- exports.SkipSelf = SkipSelf;
2726
- exports.StaticRef = StaticRef;
2727
- exports.THROW_IF_NOT_FOUND = THROW_IF_NOT_FOUND;
2728
- exports.Type = Type;
2729
- exports.applyMark = applyMark;
2730
- exports.comparePropsWithCallbacks = comparePropsWithCallbacks;
2731
- exports.computed = computed;
2732
- exports.createContext = createContext;
2733
- exports.createContextProvider = createContextProvider;
2734
- exports.createDerived = createDerived;
2735
- exports.createDynamicRef = createDynamicRef;
2736
- exports.createEffect = createEffect;
2737
- exports.createRef = createRef;
2738
- exports.createRenderer = createRenderer;
2739
- exports.createSignal = createSignal;
2740
- exports.defaultArrayReactiveHandler = defaultArrayReactiveHandler;
2741
- exports.defaultMapReactiveHandler = defaultMapReactiveHandler;
2742
- exports.defaultObjectReactiveHandler = defaultObjectReactiveHandler;
2743
- exports.defaultSetReactiveHandler = defaultSetReactiveHandler;
2744
- exports.defaultShallowArrayReactiveHandler = defaultShallowArrayReactiveHandler;
2745
- exports.defaultShallowMapReactiveHandler = defaultShallowMapReactiveHandler;
2746
- exports.defaultShallowObjectReactiveHandler = defaultShallowObjectReactiveHandler;
2747
- exports.defaultShallowSetReactiveHandler = defaultShallowSetReactiveHandler;
2748
- exports.forwardRef = forwardRef;
2749
- exports.getCurrentInstance = getCurrentInstance;
2750
- exports.getDepContext = getDepContext;
2751
- exports.getSetupContext = getSetupContext;
2752
- exports.inject = inject;
2753
- exports.internalWrite = internalWrite;
2754
- exports.isReactive = isReactive;
2755
- exports.jsx = jsx;
2756
- exports.jsxs = jsxs;
2757
- exports.makeError = makeError;
2758
- exports.normalizeProvider = normalizeProvider;
2759
- exports.onMounted = onMounted;
2760
- exports.onUnmounted = onUnmounted;
2761
- exports.onUpdated = onUpdated;
2762
- exports.popDepContext = popDepContext;
2763
- exports.proxyToRawCache = proxyToRawCache;
2764
- exports.pushDepContext = pushDepContext;
2765
- exports.rawToProxyCache = rawToProxyCache;
2766
- exports.reactive = reactive;
2767
- exports.readonlyProxyHandler = readonlyProxyHandler;
2768
- exports.registryComponentDestroyCallback = registryComponentDestroyCallback;
2769
- exports.shallowReactive = shallowReactive;
2770
- exports.toRaw = toRaw;
2771
- exports.track = track;
2772
- exports.trigger = trigger;
2773
- exports.viewfly = viewfly;
2774
- exports.watch = watch;
2775
- exports.withAnnotation = withAnnotation;
2776
- exports.withMark = withMark;
2777
- exports.withMemo = withMemo;