@viewfly/core 1.0.0-alpha.15 → 1.0.0-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/index.d.ts +69 -66
- package/bundles/index.esm.js +30 -26
- package/bundles/index.js +30 -26
- package/jsx-dev-runtime/node_modules/.bin/rimraf +17 -0
- package/jsx-dev-runtime/node_modules/.bin/rollup +17 -0
- package/jsx-dev-runtime/node_modules/.bin/tsc +17 -0
- package/jsx-dev-runtime/node_modules/.bin/tsserver +17 -0
- package/jsx-runtime/index.d.ts +7 -7
- package/package.json +2 -2
package/bundles/index.d.ts
CHANGED
|
@@ -191,6 +191,22 @@ declare class ReflectiveInjector implements Injector {
|
|
|
191
191
|
|
|
192
192
|
declare function makeError(name: string): (message: string) => Error;
|
|
193
193
|
|
|
194
|
+
interface Props {
|
|
195
|
+
children?: JSXNode | JSXNode[];
|
|
196
|
+
}
|
|
197
|
+
declare function Fragment(props: Props): () => any;
|
|
198
|
+
type Key = number | string;
|
|
199
|
+
declare function jsx(type: string | ComponentSetup, props: Props & Record<string, any>, key?: Key): ViewFlyNode;
|
|
200
|
+
declare const jsxs: typeof jsx;
|
|
201
|
+
interface ViewFlyNode<T = string | ComponentSetup> {
|
|
202
|
+
type: T;
|
|
203
|
+
props: Props & Record<string, any>;
|
|
204
|
+
key?: Key;
|
|
205
|
+
}
|
|
206
|
+
declare const JSXNodeFactory: {
|
|
207
|
+
createNode<T = string | ComponentSetup<any>>(type: T, props: Props & Record<string, any>, key?: Key): ViewFlyNode<T>;
|
|
208
|
+
};
|
|
209
|
+
|
|
194
210
|
type NativeNode = Record<string, any>;
|
|
195
211
|
declare abstract class NativeRenderer<ElementNode = NativeNode, TextNode = NativeNode> {
|
|
196
212
|
abstract createElement(name: string, isSvg: boolean): ElementNode;
|
|
@@ -210,32 +226,52 @@ declare abstract class NativeRenderer<ElementNode = NativeNode, TextNode = Nativ
|
|
|
210
226
|
abstract insertAfter(newNode: ElementNode | TextNode, ref: ElementNode | TextNode, isSvg: boolean): void;
|
|
211
227
|
}
|
|
212
228
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
229
|
+
declare namespace JSX {
|
|
230
|
+
type Element<P = any> = IntrinsicElements[string] | ComponentSetup<P>;
|
|
231
|
+
interface IntrinsicAttributes {
|
|
232
|
+
key?: Key;
|
|
233
|
+
ref?: any;
|
|
234
|
+
}
|
|
235
|
+
interface RefAttributes<T> extends IntrinsicAttributes {
|
|
236
|
+
ref?: DynamicRef<ExtractInstanceType<T>> | DynamicRef<ExtractInstanceType<T>>[];
|
|
237
|
+
}
|
|
238
|
+
interface ElementClass<P = any> extends ComponentInstance<P> {
|
|
239
|
+
}
|
|
240
|
+
interface ElementChildrenAttribute {
|
|
241
|
+
}
|
|
242
|
+
interface IntrinsicElements {
|
|
243
|
+
[name: string]: any;
|
|
244
|
+
}
|
|
245
|
+
interface IntrinsicClassAttributes<T> {
|
|
246
|
+
ref?: DynamicRef<T>;
|
|
247
|
+
}
|
|
224
248
|
}
|
|
225
|
-
declare const JSXNodeFactory: {
|
|
226
|
-
createNode<T = string | JSXInternal.ComponentSetup<any>>(type: T, props: Props & Record<string, any>, key?: Key): JSXNode<T>;
|
|
227
|
-
};
|
|
228
249
|
|
|
250
|
+
type ClassNames = string | Record<string, unknown> | false | null | undefined | ClassNames[];
|
|
251
|
+
interface ComponentInstance<P> {
|
|
252
|
+
$portalHost?: NativeNode;
|
|
253
|
+
$render(): JSXNode;
|
|
254
|
+
$useMemo?(currentProps: P, prevProps: P): boolean;
|
|
255
|
+
}
|
|
256
|
+
type JSXNode = JSX.Element | JSX.ElementClass | string | number | boolean | null | undefined | Iterable<JSXNode>;
|
|
257
|
+
interface ComponentAnnotation {
|
|
258
|
+
scope?: Scope;
|
|
259
|
+
providers?: Provider[];
|
|
260
|
+
}
|
|
261
|
+
interface ComponentSetup<P = any> {
|
|
262
|
+
(props: P): (() => JSXNode) | ComponentInstance<P>;
|
|
263
|
+
annotation?: ComponentAnnotation;
|
|
264
|
+
}
|
|
229
265
|
/**
|
|
230
266
|
* Viewfly 组件管理类,用于管理组件的生命周期,上下文等
|
|
231
267
|
*/
|
|
232
268
|
declare class Component extends ReflectiveInjector {
|
|
233
269
|
private readonly parentComponent;
|
|
234
|
-
readonly type:
|
|
270
|
+
readonly type: ComponentSetup;
|
|
235
271
|
props: Props;
|
|
236
272
|
readonly key?: Key | undefined;
|
|
237
|
-
instance:
|
|
238
|
-
template:
|
|
273
|
+
instance: ComponentInstance<Props>;
|
|
274
|
+
template: JSXNode;
|
|
239
275
|
changedSubComponents: Set<Component>;
|
|
240
276
|
get dirty(): boolean;
|
|
241
277
|
get changed(): boolean;
|
|
@@ -250,7 +286,7 @@ declare class Component extends ReflectiveInjector {
|
|
|
250
286
|
private unWatch?;
|
|
251
287
|
private isFirstRendering;
|
|
252
288
|
private refs;
|
|
253
|
-
constructor(parentComponent: Injector | null, type:
|
|
289
|
+
constructor(parentComponent: Injector | null, type: ComponentSetup, props: Props, key?: Key | undefined);
|
|
254
290
|
markAsDirtied(): void;
|
|
255
291
|
markAsChanged(changedComponent?: Component): void;
|
|
256
292
|
render(): {
|
|
@@ -328,9 +364,9 @@ declare function onUnmounted(callback: () => void): void;
|
|
|
328
364
|
interface RefListener<T> {
|
|
329
365
|
(current: T): void | (() => void);
|
|
330
366
|
}
|
|
331
|
-
type ExtractInstanceType<T, U = T extends (...args: any) => any ? ReturnType<T> : T> = U extends
|
|
367
|
+
type ExtractInstanceType<T, U = T extends (...args: any) => any ? ReturnType<T> : T> = U extends ComponentInstance<any> ? Omit<U, keyof ComponentInstance<any>> : U extends Function ? never : T;
|
|
332
368
|
interface AbstractInstanceType<T extends Record<string, any>> {
|
|
333
|
-
(): T &
|
|
369
|
+
(): T & ComponentInstance<any>;
|
|
334
370
|
}
|
|
335
371
|
declare class DynamicRef<T> {
|
|
336
372
|
private callback;
|
|
@@ -457,7 +493,7 @@ declare function watch<T = any>(deps: Signal<any>[], callback: WatchCallback<T[]
|
|
|
457
493
|
* })
|
|
458
494
|
* ```
|
|
459
495
|
*/
|
|
460
|
-
declare function withAnnotation<T extends
|
|
496
|
+
declare function withAnnotation<T extends ComponentSetup>(annotation: ComponentAnnotation, componentSetup: T): T;
|
|
461
497
|
/**
|
|
462
498
|
* 通过组件上下文获取 IoC 容器内数据的勾子方法
|
|
463
499
|
*/
|
|
@@ -467,7 +503,7 @@ declare function inject<T extends Type<any> | AbstractType<any> | InjectionToken
|
|
|
467
503
|
*/
|
|
468
504
|
declare function getCurrentInstance(): Component;
|
|
469
505
|
|
|
470
|
-
declare function withMemo<T extends Props = Props>(canUseMemo:
|
|
506
|
+
declare function withMemo<T extends Props = Props>(canUseMemo: ComponentInstance<T>['$useMemo'], render: () => JSXNode): ComponentInstance<T>;
|
|
471
507
|
|
|
472
508
|
declare function createRenderer(component: Component, nativeRenderer: NativeRenderer): (host: NativeNode) => void;
|
|
473
509
|
|
|
@@ -476,49 +512,10 @@ declare function createRenderer(component: Component, nativeRenderer: NativeRend
|
|
|
476
512
|
*/
|
|
477
513
|
declare class RootComponent extends Component {
|
|
478
514
|
private refresh;
|
|
479
|
-
constructor(parentInjector: Injector | null, factory:
|
|
515
|
+
constructor(parentInjector: Injector | null, factory: ComponentSetup, refresh: () => void);
|
|
480
516
|
markAsChanged(changedComponent?: Component): void;
|
|
481
517
|
}
|
|
482
518
|
|
|
483
|
-
type ViewNode = JSXInternal.ViewNode;
|
|
484
|
-
declare global {
|
|
485
|
-
namespace JSXInternal {
|
|
486
|
-
type ClassNames = string | Record<string, unknown> | false | null | undefined | ClassNames[];
|
|
487
|
-
interface ComponentInstance<P> {
|
|
488
|
-
$portalHost?: NativeNode;
|
|
489
|
-
$render(): ViewNode;
|
|
490
|
-
$useMemo?(currentProps: P, prevProps: P): boolean;
|
|
491
|
-
}
|
|
492
|
-
type ViewNode = Element | JSXInternal.ElementClass | string | number | boolean | null | undefined | Iterable<ViewNode>;
|
|
493
|
-
interface ComponentAnnotation {
|
|
494
|
-
scope?: Scope;
|
|
495
|
-
providers?: Provider[];
|
|
496
|
-
}
|
|
497
|
-
interface ComponentSetup<P = any> {
|
|
498
|
-
(props: P): (() => ViewNode) | ComponentInstance<P>;
|
|
499
|
-
annotation?: ComponentAnnotation;
|
|
500
|
-
}
|
|
501
|
-
type Element<P = any, C extends string | ComponentSetup<P> = string | ComponentSetup<P>> = C extends string ? IntrinsicElements[C] : (() => Element) | ComponentInstance<P>;
|
|
502
|
-
interface IntrinsicAttributes {
|
|
503
|
-
key?: Key;
|
|
504
|
-
ref?: any;
|
|
505
|
-
}
|
|
506
|
-
interface RefAttributes<T> extends IntrinsicAttributes {
|
|
507
|
-
ref?: DynamicRef<ExtractInstanceType<T>> | DynamicRef<ExtractInstanceType<T>>[];
|
|
508
|
-
}
|
|
509
|
-
interface ElementClass<P = any> extends ComponentInstance<P> {
|
|
510
|
-
}
|
|
511
|
-
interface ElementChildrenAttribute {
|
|
512
|
-
}
|
|
513
|
-
interface IntrinsicElements {
|
|
514
|
-
[name: string]: any;
|
|
515
|
-
}
|
|
516
|
-
interface IntrinsicClassAttributes<T> {
|
|
517
|
-
ref?: DynamicRef<T>;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
519
|
declare const TextAtomType: unique symbol;
|
|
523
520
|
declare const ElementAtomType: unique symbol;
|
|
524
521
|
declare const ComponentAtomType: unique symbol;
|
|
@@ -526,6 +523,8 @@ interface TextAtom {
|
|
|
526
523
|
type: typeof TextAtomType;
|
|
527
524
|
index: number;
|
|
528
525
|
jsxNode: string;
|
|
526
|
+
nodeType: string;
|
|
527
|
+
key?: null;
|
|
529
528
|
nativeNode: NativeNode | null;
|
|
530
529
|
child: Atom | null;
|
|
531
530
|
sibling: Atom | null;
|
|
@@ -534,7 +533,9 @@ interface TextAtom {
|
|
|
534
533
|
interface ElementAtom {
|
|
535
534
|
type: typeof ElementAtomType;
|
|
536
535
|
index: number;
|
|
537
|
-
|
|
536
|
+
nodeType: string;
|
|
537
|
+
key?: Key;
|
|
538
|
+
jsxNode: ViewFlyNode<string>;
|
|
538
539
|
nativeNode: NativeNode | null;
|
|
539
540
|
child: Atom | null;
|
|
540
541
|
sibling: Atom | null;
|
|
@@ -543,7 +544,9 @@ interface ElementAtom {
|
|
|
543
544
|
interface ComponentAtom {
|
|
544
545
|
type: typeof ComponentAtomType;
|
|
545
546
|
index: number;
|
|
546
|
-
|
|
547
|
+
nodeType: ComponentSetup;
|
|
548
|
+
key?: Key;
|
|
549
|
+
jsxNode: ViewFlyNode<ComponentSetup> | Component;
|
|
547
550
|
nativeNode: NativeNode | null;
|
|
548
551
|
child: Atom | null;
|
|
549
552
|
sibling: Atom | null;
|
|
@@ -562,7 +565,7 @@ interface ComponentView {
|
|
|
562
565
|
*/
|
|
563
566
|
interface Config {
|
|
564
567
|
/** 根节点 */
|
|
565
|
-
root:
|
|
568
|
+
root: JSXNode;
|
|
566
569
|
/** 平台渲染器 */
|
|
567
570
|
nativeRenderer: NativeRenderer;
|
|
568
571
|
/** 应用的上下文 */
|
|
@@ -584,4 +587,4 @@ interface Module {
|
|
|
584
587
|
}
|
|
585
588
|
declare function viewfly<T extends NativeNode>(config: Config): Application<T>;
|
|
586
589
|
|
|
587
|
-
export { type AbstractInstanceType, type AbstractProvider, type AbstractType, type Application, type Atom, type ClassProvider, Component, type ComponentView, type Config, type ConstructorProvider, DynamicRef, type ExistingProvider, type ExtractInstanceType, type ExtractValueType, type FactoryProvider, ForwardRef, Fragment, Inject, type InjectDecorator, InjectFlags, Injectable, type InjectableDecorator, type InjectableOptions, InjectionToken, Injector, type JSXNode, JSXNodeFactory, type Key, type LifeCycleCallback, type Module, type NativeNode, NativeRenderer, type NormalizedProvider, NullInjector, Optional, type OptionalDecorator, Prop, type PropDecorator, type Props, type PropsChangedCallback, type ProvideScope, type Provider, type RefListener, type ReflectiveDependency, ReflectiveInjector, RootComponent, Scope, Self, type SelfDecorator, type Signal, SkipSelf, type SkipSelfDecorator, type StaticProvider, StaticRef, THROW_IF_NOT_FOUND, Type, type TypeProvider, type ValueProvider, type
|
|
590
|
+
export { type AbstractInstanceType, type AbstractProvider, type AbstractType, type Application, type Atom, type ClassNames, type ClassProvider, Component, type ComponentAnnotation, type ComponentInstance, type ComponentSetup, type ComponentView, type Config, type ConstructorProvider, DynamicRef, type ExistingProvider, type ExtractInstanceType, type ExtractValueType, type FactoryProvider, ForwardRef, Fragment, Inject, type InjectDecorator, InjectFlags, Injectable, type InjectableDecorator, type InjectableOptions, InjectionToken, Injector, JSX, type JSXNode, JSXNodeFactory, type Key, type LifeCycleCallback, type Module, type NativeNode, NativeRenderer, type NormalizedProvider, NullInjector, Optional, type OptionalDecorator, Prop, type PropDecorator, type Props, type PropsChangedCallback, type ProvideScope, type Provider, type RefListener, type ReflectiveDependency, ReflectiveInjector, RootComponent, Scope, Self, type SelfDecorator, type Signal, SkipSelf, type SkipSelfDecorator, type StaticProvider, StaticRef, THROW_IF_NOT_FOUND, Type, type TypeProvider, type ValueProvider, type ViewFlyNode, type WatchCallback, createDerived, createDynamicRef, createRef, createRenderer, createSignal, forwardRef, getCurrentInstance, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, viewfly, watch, withAnnotation, withMemo };
|
package/bundles/index.esm.js
CHANGED
|
@@ -1294,6 +1294,7 @@ function createRenderer(component, nativeRenderer) {
|
|
|
1294
1294
|
const atom = {
|
|
1295
1295
|
type: ComponentAtomType,
|
|
1296
1296
|
index: 0,
|
|
1297
|
+
nodeType: component.type,
|
|
1297
1298
|
jsxNode: component,
|
|
1298
1299
|
sibling: null,
|
|
1299
1300
|
child: null,
|
|
@@ -1397,28 +1398,19 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
|
|
|
1397
1398
|
}
|
|
1398
1399
|
function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, effect) {
|
|
1399
1400
|
const startDiffAtom = oldAtom;
|
|
1400
|
-
const { jsxNode: newJsxNode, type } = newAtom;
|
|
1401
|
-
const key = newJsxNode.key;
|
|
1402
1401
|
let prev = null;
|
|
1403
1402
|
while (oldAtom) {
|
|
1404
|
-
|
|
1403
|
+
const newAtomType = newAtom.type;
|
|
1404
|
+
if (oldAtom.type === newAtomType && oldAtom.nodeType === newAtom.nodeType && oldAtom.key === newAtom.key) {
|
|
1405
1405
|
let commit;
|
|
1406
|
-
if (
|
|
1406
|
+
if (newAtomType === TextAtomType) {
|
|
1407
1407
|
commit = updateText(newAtom, oldAtom, nativeRenderer, context);
|
|
1408
1408
|
}
|
|
1409
|
+
else if (newAtomType === ComponentAtomType) {
|
|
1410
|
+
commit = updateComponent(newAtom, oldAtom, nativeRenderer, context);
|
|
1411
|
+
}
|
|
1409
1412
|
else {
|
|
1410
|
-
|
|
1411
|
-
if (diffKey !== key || newJsxNode.type !== diffType) {
|
|
1412
|
-
prev = oldAtom;
|
|
1413
|
-
oldAtom = oldAtom.sibling;
|
|
1414
|
-
continue;
|
|
1415
|
-
}
|
|
1416
|
-
if (type === ComponentAtomType) {
|
|
1417
|
-
commit = updateComponent(newAtom, oldAtom, nativeRenderer, context);
|
|
1418
|
-
}
|
|
1419
|
-
else {
|
|
1420
|
-
commit = updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponent);
|
|
1421
|
-
}
|
|
1413
|
+
commit = updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponent);
|
|
1422
1414
|
}
|
|
1423
1415
|
commits.push(commit);
|
|
1424
1416
|
const next = oldAtom.sibling;
|
|
@@ -1441,12 +1433,12 @@ function createNewView(start, nativeRenderer, context, parentComponent, effect)
|
|
|
1441
1433
|
};
|
|
1442
1434
|
}
|
|
1443
1435
|
function updateText(newAtom, oldAtom, nativeRenderer, context) {
|
|
1444
|
-
return function () {
|
|
1436
|
+
return function (offset) {
|
|
1445
1437
|
const nativeNode = oldAtom.nativeNode;
|
|
1446
|
-
if (newAtom.jsxNode !== oldAtom.jsxNode) {
|
|
1447
|
-
nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode, newAtom.isSvg);
|
|
1448
|
-
}
|
|
1449
1438
|
newAtom.nativeNode = nativeNode;
|
|
1439
|
+
if (newAtom.index - offset !== oldAtom.index) {
|
|
1440
|
+
insertNode(nativeRenderer, newAtom, context);
|
|
1441
|
+
}
|
|
1450
1442
|
context.host = nativeNode;
|
|
1451
1443
|
context.isParent = false;
|
|
1452
1444
|
};
|
|
@@ -1560,7 +1552,7 @@ function componentRender(nativeRenderer, component, from, context) {
|
|
|
1560
1552
|
}
|
|
1561
1553
|
component.rendered();
|
|
1562
1554
|
}
|
|
1563
|
-
function createChainByJSXNode(type, jsxNode, prevAtom, isSvg) {
|
|
1555
|
+
function createChainByJSXNode(type, jsxNode, nodeType, prevAtom, isSvg, key) {
|
|
1564
1556
|
const atom = {
|
|
1565
1557
|
type,
|
|
1566
1558
|
index: prevAtom.index + 1,
|
|
@@ -1568,7 +1560,9 @@ function createChainByJSXNode(type, jsxNode, prevAtom, isSvg) {
|
|
|
1568
1560
|
sibling: null,
|
|
1569
1561
|
child: null,
|
|
1570
1562
|
nativeNode: null,
|
|
1571
|
-
isSvg
|
|
1563
|
+
isSvg,
|
|
1564
|
+
nodeType,
|
|
1565
|
+
key
|
|
1572
1566
|
};
|
|
1573
1567
|
prevAtom.sibling = atom;
|
|
1574
1568
|
return atom;
|
|
@@ -1577,7 +1571,7 @@ function createChainByNode(jsxNode, prevAtom, isSvg) {
|
|
|
1577
1571
|
const type = typeof jsxNode;
|
|
1578
1572
|
if (jsxNode !== null && type !== 'undefined' && type !== 'boolean') {
|
|
1579
1573
|
if (typeof jsxNode === 'string') {
|
|
1580
|
-
return createChainByJSXNode(TextAtomType, jsxNode, prevAtom, isSvg);
|
|
1574
|
+
return createChainByJSXNode(TextAtomType, jsxNode, jsxNode, prevAtom, isSvg);
|
|
1581
1575
|
}
|
|
1582
1576
|
if (Array.isArray(jsxNode)) {
|
|
1583
1577
|
return createChainByChildren(jsxNode, prevAtom, isSvg);
|
|
@@ -1585,13 +1579,14 @@ function createChainByNode(jsxNode, prevAtom, isSvg) {
|
|
|
1585
1579
|
if (type === 'object') {
|
|
1586
1580
|
const nodeType = typeof jsxNode.type;
|
|
1587
1581
|
if (nodeType === 'string') {
|
|
1588
|
-
return createChainByJSXNode(ElementAtomType, jsxNode, prevAtom, isSvg || jsxNode.type === 'svg');
|
|
1582
|
+
return createChainByJSXNode(ElementAtomType, jsxNode, jsxNode.type, prevAtom, isSvg || jsxNode.type === 'svg', jsxNode.key);
|
|
1589
1583
|
}
|
|
1590
1584
|
else if (nodeType === 'function') {
|
|
1591
|
-
return createChainByJSXNode(ComponentAtomType, jsxNode, prevAtom, isSvg);
|
|
1585
|
+
return createChainByJSXNode(ComponentAtomType, jsxNode, jsxNode.type, prevAtom, isSvg, jsxNode.key);
|
|
1592
1586
|
}
|
|
1593
1587
|
}
|
|
1594
|
-
|
|
1588
|
+
const text = String(jsxNode);
|
|
1589
|
+
return createChainByJSXNode(TextAtomType, text, text, prevAtom, isSvg);
|
|
1595
1590
|
}
|
|
1596
1591
|
return prevAtom;
|
|
1597
1592
|
}
|
|
@@ -1685,10 +1680,12 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1685
1680
|
let unBindRefs;
|
|
1686
1681
|
let bindRefs;
|
|
1687
1682
|
newAtom.child = oldAtom.child;
|
|
1683
|
+
let updatedSubComponent = false;
|
|
1688
1684
|
for (const [key, value] of changes.remove) {
|
|
1689
1685
|
if (key === 'children') {
|
|
1690
1686
|
cleanElementChildren(oldAtom, nativeRenderer);
|
|
1691
1687
|
newAtom.child = null;
|
|
1688
|
+
updatedSubComponent = true;
|
|
1692
1689
|
continue;
|
|
1693
1690
|
}
|
|
1694
1691
|
if (key === 'class') {
|
|
@@ -1726,6 +1723,7 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1726
1723
|
rootHost: context.rootHost
|
|
1727
1724
|
});
|
|
1728
1725
|
}
|
|
1726
|
+
updatedSubComponent = true;
|
|
1729
1727
|
continue;
|
|
1730
1728
|
}
|
|
1731
1729
|
if (key === 'class') {
|
|
@@ -1762,6 +1760,7 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1762
1760
|
if (key === 'children') {
|
|
1763
1761
|
newAtom.child = createChildChain(value, isSvg);
|
|
1764
1762
|
buildElementChildren(newAtom, nativeRenderer, parentComponent, context);
|
|
1763
|
+
updatedSubComponent = true;
|
|
1765
1764
|
continue;
|
|
1766
1765
|
}
|
|
1767
1766
|
if (key === 'class') {
|
|
@@ -1787,6 +1786,11 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1787
1786
|
}
|
|
1788
1787
|
nativeRenderer.setProperty(nativeNode, key, value, isSvg);
|
|
1789
1788
|
}
|
|
1789
|
+
if (!updatedSubComponent) {
|
|
1790
|
+
parentComponent.changedSubComponents.forEach(child => {
|
|
1791
|
+
updateView(nativeRenderer, child);
|
|
1792
|
+
});
|
|
1793
|
+
}
|
|
1790
1794
|
applyRefs(unBindRefs, nativeNode, false);
|
|
1791
1795
|
applyRefs(bindRefs, nativeNode, true);
|
|
1792
1796
|
}
|
package/bundles/index.js
CHANGED
|
@@ -1296,6 +1296,7 @@ function createRenderer(component, nativeRenderer) {
|
|
|
1296
1296
|
const atom = {
|
|
1297
1297
|
type: ComponentAtomType,
|
|
1298
1298
|
index: 0,
|
|
1299
|
+
nodeType: component.type,
|
|
1299
1300
|
jsxNode: component,
|
|
1300
1301
|
sibling: null,
|
|
1301
1302
|
child: null,
|
|
@@ -1399,28 +1400,19 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
|
|
|
1399
1400
|
}
|
|
1400
1401
|
function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, effect) {
|
|
1401
1402
|
const startDiffAtom = oldAtom;
|
|
1402
|
-
const { jsxNode: newJsxNode, type } = newAtom;
|
|
1403
|
-
const key = newJsxNode.key;
|
|
1404
1403
|
let prev = null;
|
|
1405
1404
|
while (oldAtom) {
|
|
1406
|
-
|
|
1405
|
+
const newAtomType = newAtom.type;
|
|
1406
|
+
if (oldAtom.type === newAtomType && oldAtom.nodeType === newAtom.nodeType && oldAtom.key === newAtom.key) {
|
|
1407
1407
|
let commit;
|
|
1408
|
-
if (
|
|
1408
|
+
if (newAtomType === TextAtomType) {
|
|
1409
1409
|
commit = updateText(newAtom, oldAtom, nativeRenderer, context);
|
|
1410
1410
|
}
|
|
1411
|
+
else if (newAtomType === ComponentAtomType) {
|
|
1412
|
+
commit = updateComponent(newAtom, oldAtom, nativeRenderer, context);
|
|
1413
|
+
}
|
|
1411
1414
|
else {
|
|
1412
|
-
|
|
1413
|
-
if (diffKey !== key || newJsxNode.type !== diffType) {
|
|
1414
|
-
prev = oldAtom;
|
|
1415
|
-
oldAtom = oldAtom.sibling;
|
|
1416
|
-
continue;
|
|
1417
|
-
}
|
|
1418
|
-
if (type === ComponentAtomType) {
|
|
1419
|
-
commit = updateComponent(newAtom, oldAtom, nativeRenderer, context);
|
|
1420
|
-
}
|
|
1421
|
-
else {
|
|
1422
|
-
commit = updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponent);
|
|
1423
|
-
}
|
|
1415
|
+
commit = updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponent);
|
|
1424
1416
|
}
|
|
1425
1417
|
commits.push(commit);
|
|
1426
1418
|
const next = oldAtom.sibling;
|
|
@@ -1443,12 +1435,12 @@ function createNewView(start, nativeRenderer, context, parentComponent, effect)
|
|
|
1443
1435
|
};
|
|
1444
1436
|
}
|
|
1445
1437
|
function updateText(newAtom, oldAtom, nativeRenderer, context) {
|
|
1446
|
-
return function () {
|
|
1438
|
+
return function (offset) {
|
|
1447
1439
|
const nativeNode = oldAtom.nativeNode;
|
|
1448
|
-
if (newAtom.jsxNode !== oldAtom.jsxNode) {
|
|
1449
|
-
nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode, newAtom.isSvg);
|
|
1450
|
-
}
|
|
1451
1440
|
newAtom.nativeNode = nativeNode;
|
|
1441
|
+
if (newAtom.index - offset !== oldAtom.index) {
|
|
1442
|
+
insertNode(nativeRenderer, newAtom, context);
|
|
1443
|
+
}
|
|
1452
1444
|
context.host = nativeNode;
|
|
1453
1445
|
context.isParent = false;
|
|
1454
1446
|
};
|
|
@@ -1562,7 +1554,7 @@ function componentRender(nativeRenderer, component, from, context) {
|
|
|
1562
1554
|
}
|
|
1563
1555
|
component.rendered();
|
|
1564
1556
|
}
|
|
1565
|
-
function createChainByJSXNode(type, jsxNode, prevAtom, isSvg) {
|
|
1557
|
+
function createChainByJSXNode(type, jsxNode, nodeType, prevAtom, isSvg, key) {
|
|
1566
1558
|
const atom = {
|
|
1567
1559
|
type,
|
|
1568
1560
|
index: prevAtom.index + 1,
|
|
@@ -1570,7 +1562,9 @@ function createChainByJSXNode(type, jsxNode, prevAtom, isSvg) {
|
|
|
1570
1562
|
sibling: null,
|
|
1571
1563
|
child: null,
|
|
1572
1564
|
nativeNode: null,
|
|
1573
|
-
isSvg
|
|
1565
|
+
isSvg,
|
|
1566
|
+
nodeType,
|
|
1567
|
+
key
|
|
1574
1568
|
};
|
|
1575
1569
|
prevAtom.sibling = atom;
|
|
1576
1570
|
return atom;
|
|
@@ -1579,7 +1573,7 @@ function createChainByNode(jsxNode, prevAtom, isSvg) {
|
|
|
1579
1573
|
const type = typeof jsxNode;
|
|
1580
1574
|
if (jsxNode !== null && type !== 'undefined' && type !== 'boolean') {
|
|
1581
1575
|
if (typeof jsxNode === 'string') {
|
|
1582
|
-
return createChainByJSXNode(TextAtomType, jsxNode, prevAtom, isSvg);
|
|
1576
|
+
return createChainByJSXNode(TextAtomType, jsxNode, jsxNode, prevAtom, isSvg);
|
|
1583
1577
|
}
|
|
1584
1578
|
if (Array.isArray(jsxNode)) {
|
|
1585
1579
|
return createChainByChildren(jsxNode, prevAtom, isSvg);
|
|
@@ -1587,13 +1581,14 @@ function createChainByNode(jsxNode, prevAtom, isSvg) {
|
|
|
1587
1581
|
if (type === 'object') {
|
|
1588
1582
|
const nodeType = typeof jsxNode.type;
|
|
1589
1583
|
if (nodeType === 'string') {
|
|
1590
|
-
return createChainByJSXNode(ElementAtomType, jsxNode, prevAtom, isSvg || jsxNode.type === 'svg');
|
|
1584
|
+
return createChainByJSXNode(ElementAtomType, jsxNode, jsxNode.type, prevAtom, isSvg || jsxNode.type === 'svg', jsxNode.key);
|
|
1591
1585
|
}
|
|
1592
1586
|
else if (nodeType === 'function') {
|
|
1593
|
-
return createChainByJSXNode(ComponentAtomType, jsxNode, prevAtom, isSvg);
|
|
1587
|
+
return createChainByJSXNode(ComponentAtomType, jsxNode, jsxNode.type, prevAtom, isSvg, jsxNode.key);
|
|
1594
1588
|
}
|
|
1595
1589
|
}
|
|
1596
|
-
|
|
1590
|
+
const text = String(jsxNode);
|
|
1591
|
+
return createChainByJSXNode(TextAtomType, text, text, prevAtom, isSvg);
|
|
1597
1592
|
}
|
|
1598
1593
|
return prevAtom;
|
|
1599
1594
|
}
|
|
@@ -1687,10 +1682,12 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1687
1682
|
let unBindRefs;
|
|
1688
1683
|
let bindRefs;
|
|
1689
1684
|
newAtom.child = oldAtom.child;
|
|
1685
|
+
let updatedSubComponent = false;
|
|
1690
1686
|
for (const [key, value] of changes.remove) {
|
|
1691
1687
|
if (key === 'children') {
|
|
1692
1688
|
cleanElementChildren(oldAtom, nativeRenderer);
|
|
1693
1689
|
newAtom.child = null;
|
|
1690
|
+
updatedSubComponent = true;
|
|
1694
1691
|
continue;
|
|
1695
1692
|
}
|
|
1696
1693
|
if (key === 'class') {
|
|
@@ -1728,6 +1725,7 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1728
1725
|
rootHost: context.rootHost
|
|
1729
1726
|
});
|
|
1730
1727
|
}
|
|
1728
|
+
updatedSubComponent = true;
|
|
1731
1729
|
continue;
|
|
1732
1730
|
}
|
|
1733
1731
|
if (key === 'class') {
|
|
@@ -1764,6 +1762,7 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1764
1762
|
if (key === 'children') {
|
|
1765
1763
|
newAtom.child = createChildChain(value, isSvg);
|
|
1766
1764
|
buildElementChildren(newAtom, nativeRenderer, parentComponent, context);
|
|
1765
|
+
updatedSubComponent = true;
|
|
1767
1766
|
continue;
|
|
1768
1767
|
}
|
|
1769
1768
|
if (key === 'class') {
|
|
@@ -1789,6 +1788,11 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1789
1788
|
}
|
|
1790
1789
|
nativeRenderer.setProperty(nativeNode, key, value, isSvg);
|
|
1791
1790
|
}
|
|
1791
|
+
if (!updatedSubComponent) {
|
|
1792
|
+
parentComponent.changedSubComponents.forEach(child => {
|
|
1793
|
+
updateView(nativeRenderer, child);
|
|
1794
|
+
});
|
|
1795
|
+
}
|
|
1792
1796
|
applyRefs(unBindRefs, nativeNode, false);
|
|
1793
1797
|
applyRefs(bindRefs, nativeNode, true);
|
|
1794
1798
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
+
|
|
4
|
+
case `uname` in
|
|
5
|
+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
+
esac
|
|
7
|
+
|
|
8
|
+
if [ -z "$NODE_PATH" ]; then
|
|
9
|
+
export NODE_PATH="/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/rimraf@3.0.2/node_modules/rimraf/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/rimraf@3.0.2/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/node_modules"
|
|
10
|
+
else
|
|
11
|
+
export NODE_PATH="/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/rimraf@3.0.2/node_modules/rimraf/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/rimraf@3.0.2/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
|
+
fi
|
|
13
|
+
if [ -x "$basedir/node" ]; then
|
|
14
|
+
exec "$basedir/node" "$basedir/../rimraf/bin.js" "$@"
|
|
15
|
+
else
|
|
16
|
+
exec node "$basedir/../rimraf/bin.js" "$@"
|
|
17
|
+
fi
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
+
|
|
4
|
+
case `uname` in
|
|
5
|
+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
+
esac
|
|
7
|
+
|
|
8
|
+
if [ -z "$NODE_PATH" ]; then
|
|
9
|
+
export NODE_PATH="/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/dist/bin/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/dist/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/rollup@3.29.4/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/node_modules"
|
|
10
|
+
else
|
|
11
|
+
export NODE_PATH="/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/dist/bin/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/dist/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/rollup@3.29.4/node_modules/rollup/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/rollup@3.29.4/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
|
+
fi
|
|
13
|
+
if [ -x "$basedir/node" ]; then
|
|
14
|
+
exec "$basedir/node" "$basedir/../rollup/dist/bin/rollup" "$@"
|
|
15
|
+
else
|
|
16
|
+
exec node "$basedir/../rollup/dist/bin/rollup" "$@"
|
|
17
|
+
fi
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
+
|
|
4
|
+
case `uname` in
|
|
5
|
+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
+
esac
|
|
7
|
+
|
|
8
|
+
if [ -z "$NODE_PATH" ]; then
|
|
9
|
+
export NODE_PATH="/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/bin/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/typescript@5.4.5/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/node_modules"
|
|
10
|
+
else
|
|
11
|
+
export NODE_PATH="/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/bin/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/typescript@5.4.5/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
|
+
fi
|
|
13
|
+
if [ -x "$basedir/node" ]; then
|
|
14
|
+
exec "$basedir/node" "$basedir/../../../../../node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/bin/tsc" "$@"
|
|
15
|
+
else
|
|
16
|
+
exec node "$basedir/../../../../../node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/bin/tsc" "$@"
|
|
17
|
+
fi
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
+
|
|
4
|
+
case `uname` in
|
|
5
|
+
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
+
esac
|
|
7
|
+
|
|
8
|
+
if [ -z "$NODE_PATH" ]; then
|
|
9
|
+
export NODE_PATH="/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/bin/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/typescript@5.4.5/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/node_modules"
|
|
10
|
+
else
|
|
11
|
+
export NODE_PATH="/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/bin/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/typescript@5.4.5/node_modules:/Users/tanbo/Documents/lib/viewfly/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
|
+
fi
|
|
13
|
+
if [ -x "$basedir/node" ]; then
|
|
14
|
+
exec "$basedir/node" "$basedir/../../../../../node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/bin/tsserver" "$@"
|
|
15
|
+
else
|
|
16
|
+
exec node "$basedir/../../../../../node_modules/.pnpm/typescript@5.4.5/node_modules/typescript/bin/tsserver" "$@"
|
|
17
|
+
fi
|
package/jsx-runtime/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx, jsxs, Fragment } from '@viewfly/core';
|
|
1
|
+
import { jsx, jsxs, Fragment, JSX as ViewflyJSX } from '@viewfly/core';
|
|
2
2
|
/**
|
|
3
3
|
* JSX namespace for usage with @jsxImportsSource directive
|
|
4
4
|
* when ts compilerOptions.jsx is 'react-jsx'
|
|
@@ -7,15 +7,15 @@ import { jsx, jsxs, Fragment } from '@viewfly/core';
|
|
|
7
7
|
declare const jsxDEV: typeof jsx;
|
|
8
8
|
export { jsx, jsxs, Fragment, jsxDEV };
|
|
9
9
|
export declare namespace JSX {
|
|
10
|
-
type Element =
|
|
11
|
-
interface ElementClass extends
|
|
10
|
+
type Element = ViewflyJSX.Element;
|
|
11
|
+
interface ElementClass extends ViewflyJSX.ElementClass {
|
|
12
12
|
}
|
|
13
|
-
interface IntrinsicElements extends
|
|
13
|
+
interface IntrinsicElements extends ViewflyJSX.IntrinsicElements {
|
|
14
14
|
}
|
|
15
|
-
interface IntrinsicAttributes extends
|
|
15
|
+
interface IntrinsicAttributes extends ViewflyJSX.IntrinsicAttributes {
|
|
16
16
|
}
|
|
17
|
-
interface ElementChildrenAttribute extends
|
|
17
|
+
interface ElementChildrenAttribute extends ViewflyJSX.ElementChildrenAttribute {
|
|
18
18
|
}
|
|
19
|
-
interface IntrinsicClassAttributes<T> extends
|
|
19
|
+
interface IntrinsicClassAttributes<T> extends ViewflyJSX.IntrinsicClassAttributes<T> {
|
|
20
20
|
}
|
|
21
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/core",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.17",
|
|
4
4
|
"description": "Viewfly is a simple and easy-to-use JavaScript framework with an intuitive development experience.",
|
|
5
5
|
"main": "./bundles/index.js",
|
|
6
6
|
"module": "./bundles/index.esm.js",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"bugs": {
|
|
51
51
|
"url": "https://github.com/viewfly/viewfly.git/issues"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "4fd97b73e7808b45660f2b802f4b327a67366a7e",
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"reflect-metadata": "^0.2.2"
|
|
56
56
|
}
|