@viewfly/core 1.0.5 → 1.1.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.
@@ -198,7 +198,7 @@ declare function Fragment(props: Props): () => JSXNode | JSXNode[];
198
198
  interface ContextProps extends Props {
199
199
  providers: Provider[];
200
200
  }
201
- declare function Context(props: ContextProps): () => JSXNode | JSXNode[];
201
+ declare function Context(props: ContextProps): () => ViewFlyNode<string | ComponentSetup<any>>;
202
202
  type Key = number | string;
203
203
  declare function jsx(type: string | ComponentSetup, props: Props & Record<string, any>, key?: Key): ViewFlyNode;
204
204
  declare const jsxs: typeof jsx;
@@ -211,23 +211,68 @@ declare const JSXNodeFactory: {
211
211
  createNode<T = string | ComponentSetup<any>>(type: T, props: Props & Record<string, any>, key?: Key): ViewFlyNode<T>;
212
212
  };
213
213
 
214
+ declare const TextAtomType: unique symbol;
215
+ declare const ElementAtomType: unique symbol;
216
+ declare const ComponentAtomType: unique symbol;
217
+ type ElementNamespace = string | undefined;
218
+ interface TextAtom {
219
+ type: typeof TextAtomType;
220
+ index: number;
221
+ jsxNode: string;
222
+ nodeType: string;
223
+ key?: null;
224
+ nativeNode: NativeNode | null;
225
+ child: Atom | null;
226
+ sibling: Atom | null;
227
+ namespace: ElementNamespace;
228
+ }
229
+ interface ElementAtom {
230
+ type: typeof ElementAtomType;
231
+ index: number;
232
+ nodeType: string;
233
+ key?: Key;
234
+ jsxNode: ViewFlyNode<string>;
235
+ nativeNode: NativeNode | null;
236
+ child: Atom | null;
237
+ sibling: Atom | null;
238
+ namespace: ElementNamespace;
239
+ }
240
+ interface ComponentAtom {
241
+ type: typeof ComponentAtomType;
242
+ index: number;
243
+ nodeType: ComponentSetup;
244
+ key?: Key;
245
+ jsxNode: ViewFlyNode<ComponentSetup> | Component;
246
+ nativeNode: NativeNode | null;
247
+ child: Atom | null;
248
+ sibling: Atom | null;
249
+ namespace: ElementNamespace;
250
+ }
251
+ type Atom = TextAtom | ElementAtom | ComponentAtom;
252
+ interface ComponentView {
253
+ atom: ComponentAtom;
254
+ host: NativeNode;
255
+ isParent: boolean;
256
+ rootHost: NativeNode;
257
+ }
258
+
214
259
  type NativeNode = Record<string, any>;
215
260
  declare abstract class NativeRenderer<ElementNode = NativeNode, TextNode = NativeNode> {
216
- abstract createElement(name: string, isSvg: boolean): ElementNode;
217
- abstract createTextNode(textContent: string, isSvg: boolean): TextNode;
218
- abstract setProperty(node: ElementNode, key: string, value: any, isSvg: boolean): void;
219
- abstract appendChild(parent: ElementNode, newChild: ElementNode | TextNode, isSvg: boolean): void;
220
- abstract prependChild(parent: ElementNode, newChild: ElementNode | TextNode, isSvg: boolean): void;
221
- abstract removeProperty(node: ElementNode, key: string, isSvg: boolean): void;
222
- abstract setStyle(target: ElementNode, key: string, value: any, isSvg: boolean): void;
223
- abstract removeStyle(target: ElementNode, key: string, isSvg: boolean): void;
224
- abstract setClass(target: ElementNode, value: string, isSvg: boolean): void;
225
- abstract listen<T = any>(node: ElementNode, type: string, callback: (ev: T) => any, isSvg: boolean): void;
226
- abstract unListen(node: ElementNode, type: string, callback: (ev: any) => any, isSvg: boolean): void;
227
- abstract remove(node: ElementNode | TextNode, isSvg: boolean): void;
228
- abstract cleanChildren(node: ElementNode, isSvg: boolean): void;
229
- abstract syncTextContent(target: TextNode, content: string, isSvg: boolean): void;
230
- abstract insertAfter(newNode: ElementNode | TextNode, ref: ElementNode | TextNode, isSvg: boolean): void;
261
+ abstract createElement(name: string, namespace: ElementNamespace): ElementNode;
262
+ abstract createTextNode(textContent: string, namespace: ElementNamespace): TextNode;
263
+ abstract setProperty(node: ElementNode, key: string, value: any, namespace: ElementNamespace): void;
264
+ abstract appendChild(parent: ElementNode, newChild: ElementNode | TextNode, namespace: ElementNamespace): void;
265
+ abstract prependChild(parent: ElementNode, newChild: ElementNode | TextNode, namespace: ElementNamespace): void;
266
+ abstract removeProperty(node: ElementNode, key: string, namespace: ElementNamespace): void;
267
+ abstract setStyle(target: ElementNode, key: string, value: any, namespace: ElementNamespace): void;
268
+ abstract removeStyle(target: ElementNode, key: string, namespace: ElementNamespace): void;
269
+ abstract setClass(target: ElementNode, value: string, namespace: ElementNamespace): void;
270
+ abstract listen<T = any>(node: ElementNode, type: string, callback: (ev: T) => any, namespace: ElementNamespace): void;
271
+ abstract unListen(node: ElementNode, type: string, callback: (ev: any) => any, namespace: ElementNamespace): void;
272
+ abstract remove(node: ElementNode | TextNode, namespace: ElementNamespace): void;
273
+ abstract cleanChildren(node: ElementNode, namespace: ElementNamespace): void;
274
+ abstract syncTextContent(target: TextNode, content: string, namespace: ElementNamespace): void;
275
+ abstract insertAfter(newNode: ElementNode | TextNode, ref: ElementNode | TextNode, namespace: ElementNamespace): void;
231
276
  }
232
277
 
233
278
  declare namespace JSX {
@@ -315,7 +360,7 @@ interface LifeCycleCallback {
315
360
  (): void | (() => void);
316
361
  }
317
362
  interface PropsChangedCallback<T extends Props> {
318
- (currentProps: T | null, oldProps: T | null): void | (() => void);
363
+ (currentProps: T, oldProps: T): void | (() => void);
319
364
  }
320
365
  /**
321
366
  * 当组件第一次渲染完成时触发
@@ -444,7 +489,8 @@ declare function getCurrentInstance(): Component;
444
489
 
445
490
  declare function withMemo<T extends Props = Props>(canUseMemo: ComponentInstance<T>['$useMemo'], render: () => JSXNode): ComponentInstance<T>;
446
491
 
447
- declare function createRenderer(component: Component, nativeRenderer: NativeRenderer): (host: NativeNode) => void;
492
+ declare const ElementNamespaceMap: Record<string, string>;
493
+ declare function createRenderer(component: Component, nativeRenderer: NativeRenderer, namespace: ElementNamespace): (host: NativeNode) => void;
448
494
 
449
495
  /**
450
496
  * Viewfly 根组件,用于实现组件状态更新事件通知
@@ -524,50 +570,6 @@ declare function watch<T, T1, T2, T3, T4, T5, T6, T7>(deps: [Signal<T>, Signal<T
524
570
  declare function watch<T>(deps: () => T, callback: WatchCallback<T>): () => void;
525
571
  declare function watch<T = any>(deps: Signal<any>[], callback: WatchCallback<T[]>): () => void;
526
572
 
527
- declare const TextAtomType: unique symbol;
528
- declare const ElementAtomType: unique symbol;
529
- declare const ComponentAtomType: unique symbol;
530
- interface TextAtom {
531
- type: typeof TextAtomType;
532
- index: number;
533
- jsxNode: string;
534
- nodeType: string;
535
- key?: null;
536
- nativeNode: NativeNode | null;
537
- child: Atom | null;
538
- sibling: Atom | null;
539
- isSvg: boolean;
540
- }
541
- interface ElementAtom {
542
- type: typeof ElementAtomType;
543
- index: number;
544
- nodeType: string;
545
- key?: Key;
546
- jsxNode: ViewFlyNode<string>;
547
- nativeNode: NativeNode | null;
548
- child: Atom | null;
549
- sibling: Atom | null;
550
- isSvg: boolean;
551
- }
552
- interface ComponentAtom {
553
- type: typeof ComponentAtomType;
554
- index: number;
555
- nodeType: ComponentSetup;
556
- key?: Key;
557
- jsxNode: ViewFlyNode<ComponentSetup> | Component;
558
- nativeNode: NativeNode | null;
559
- child: Atom | null;
560
- sibling: Atom | null;
561
- isSvg: boolean;
562
- }
563
- type Atom = TextAtom | ElementAtom | ComponentAtom;
564
- interface ComponentView {
565
- atom: ComponentAtom;
566
- host: NativeNode;
567
- isParent: boolean;
568
- rootHost: NativeNode;
569
- }
570
-
571
573
  /**
572
574
  * Viewfly 配置项
573
575
  */
@@ -580,6 +582,8 @@ interface Config {
580
582
  context?: Injector;
581
583
  /** 是否自动更新视图 */
582
584
  autoUpdate?: boolean;
585
+ /** 根节点命名空间 */
586
+ elementNamespace?: ElementNamespace;
583
587
  }
584
588
  interface Application<T extends NativeNode = NativeNode> {
585
589
  provide(providers: Provider | Provider[]): Application<T>;
@@ -595,4 +599,4 @@ interface Module {
595
599
  }
596
600
  declare function viewfly<T extends NativeNode>(config: Config): Application<T>;
597
601
 
598
- 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, Context, type ContextProps, 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, computed, createDerived, createDynamicRef, createRef, createRenderer, createSignal, forwardRef, getCurrentInstance, getSetupContext, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, viewfly, watch, withAnnotation, withMemo };
602
+ 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, Context, type ContextProps, DynamicRef, type ElementNamespace, ElementNamespaceMap, 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, computed, createDerived, createDynamicRef, createRef, createRenderer, createSignal, forwardRef, getCurrentInstance, getSetupContext, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, viewfly, watch, withAnnotation, withMemo };
@@ -1096,10 +1096,21 @@ function Fragment(props) {
1096
1096
  };
1097
1097
  }
1098
1098
  function Context(props) {
1099
- const instance = getCurrentInstance();
1100
- instance.provide(props.providers);
1099
+ function createContextComponent(providers) {
1100
+ return withAnnotation({
1101
+ providers,
1102
+ }, () => {
1103
+ return () => {
1104
+ return props.children;
1105
+ };
1106
+ });
1107
+ }
1108
+ let contextComponent = createContextComponent(props.providers);
1109
+ onPropsChanged((newProps) => {
1110
+ contextComponent = createContextComponent(newProps.providers);
1111
+ });
1101
1112
  return () => {
1102
- return props.children;
1113
+ return jsx(contextComponent, {});
1103
1114
  };
1104
1115
  }
1105
1116
  function jsx(type, props, key) {
@@ -1123,9 +1134,13 @@ function withMemo(canUseMemo, render) {
1123
1134
  };
1124
1135
  }
1125
1136
 
1137
+ const ElementNamespaceMap = {
1138
+ svg: 'svg',
1139
+ math: 'mathml',
1140
+ };
1126
1141
  const componentViewCache = new WeakMap();
1127
1142
  const listenerReg = /^on[A-Z]/;
1128
- function createRenderer(component, nativeRenderer) {
1143
+ function createRenderer(component, nativeRenderer, namespace) {
1129
1144
  let isInit = true;
1130
1145
  return function render(host) {
1131
1146
  if (isInit) {
@@ -1138,7 +1153,7 @@ function createRenderer(component, nativeRenderer) {
1138
1153
  sibling: null,
1139
1154
  child: null,
1140
1155
  nativeNode: null,
1141
- isSvg: false
1156
+ namespace
1142
1157
  };
1143
1158
  componentRender(nativeRenderer, component, atom, {
1144
1159
  isParent: true,
@@ -1191,7 +1206,7 @@ function updateView(nativeRenderer, component, needMove) {
1191
1206
  function applyChanges(nativeRenderer, component, atom, context, needMove) {
1192
1207
  const diffAtom = atom.child;
1193
1208
  component.update(component.props, newTemplate => {
1194
- atom.child = createChildChain(newTemplate, atom.isSvg);
1209
+ atom.child = createChildChain(newTemplate, atom.namespace);
1195
1210
  diff(nativeRenderer, component, atom.child, diffAtom, context, needMove);
1196
1211
  const next = atom.sibling;
1197
1212
  if (next && next.jsxNode instanceof Component) {
@@ -1304,7 +1319,7 @@ function updateComponent(newAtom, reusedAtom, nativeRenderer, context) {
1304
1319
  newAtom.jsxNode = component;
1305
1320
  component.update(newProps, newTemplate => {
1306
1321
  if (newTemplate) {
1307
- newAtom.child = createChildChain(newTemplate, newAtom.isSvg);
1322
+ newAtom.child = createChildChain(newTemplate, newAtom.namespace);
1308
1323
  }
1309
1324
  if (newAtom.child) {
1310
1325
  diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context, needMove || newAtom.index - offset !== reusedAtom.index);
@@ -1364,7 +1379,7 @@ function reuseElementChildrenView(nativeRenderer, atom, context, skipSubComponen
1364
1379
  }
1365
1380
  function cleanElementChildren(atom, nativeRenderer) {
1366
1381
  let child = atom.child;
1367
- nativeRenderer.cleanChildren(atom.nativeNode, atom.isSvg);
1382
+ nativeRenderer.cleanChildren(atom.nativeNode, atom.namespace);
1368
1383
  while (child) {
1369
1384
  cleanView(nativeRenderer, child, false);
1370
1385
  child = child.sibling;
@@ -1373,7 +1388,7 @@ function cleanElementChildren(atom, nativeRenderer) {
1373
1388
  function cleanView(nativeRenderer, atom, needClean) {
1374
1389
  if (atom.nativeNode) {
1375
1390
  if (needClean) {
1376
- nativeRenderer.remove(atom.nativeNode, atom.isSvg);
1391
+ nativeRenderer.remove(atom.nativeNode, atom.namespace);
1377
1392
  needClean = false;
1378
1393
  }
1379
1394
  if (atom.type === ElementAtomType) {
@@ -1395,7 +1410,7 @@ function cleanView(nativeRenderer, atom, needClean) {
1395
1410
  }
1396
1411
  function componentRender(nativeRenderer, component, from, context) {
1397
1412
  component.render((template, portalHost) => {
1398
- from.child = createChildChain(template, from.isSvg);
1413
+ from.child = createChildChain(template, from.namespace);
1399
1414
  context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
1400
1415
  componentViewCache.set(component, Object.assign({ atom: from }, context));
1401
1416
  let child = from.child;
@@ -1405,7 +1420,7 @@ function componentRender(nativeRenderer, component, from, context) {
1405
1420
  }
1406
1421
  });
1407
1422
  }
1408
- function createChainByJSXNode(type, jsxNode, nodeType, prevAtom, isSvg, key) {
1423
+ function createChainByJSXNode(type, jsxNode, nodeType, prevAtom, namespace, key) {
1409
1424
  const atom = {
1410
1425
  type,
1411
1426
  index: prevAtom.index + 1,
@@ -1413,88 +1428,88 @@ function createChainByJSXNode(type, jsxNode, nodeType, prevAtom, isSvg, key) {
1413
1428
  sibling: null,
1414
1429
  child: null,
1415
1430
  nativeNode: null,
1416
- isSvg,
1431
+ namespace,
1417
1432
  nodeType,
1418
1433
  key
1419
1434
  };
1420
1435
  prevAtom.sibling = atom;
1421
1436
  return atom;
1422
1437
  }
1423
- function createChainByNode(jsxNode, prevAtom, isSvg) {
1438
+ function createChainByNode(jsxNode, prevAtom, elementNamespace) {
1424
1439
  const type = typeof jsxNode;
1425
1440
  if (jsxNode !== null && type !== 'undefined' && type !== 'boolean') {
1426
1441
  if (typeof jsxNode === 'string') {
1427
- return createChainByJSXNode(TextAtomType, jsxNode, jsxNode, prevAtom, isSvg);
1442
+ return createChainByJSXNode(TextAtomType, jsxNode, jsxNode, prevAtom, elementNamespace);
1428
1443
  }
1429
1444
  if (Array.isArray(jsxNode)) {
1430
- return createChainByChildren(jsxNode, prevAtom, isSvg);
1445
+ return createChainByChildren(jsxNode, prevAtom, elementNamespace);
1431
1446
  }
1432
1447
  if (type === 'object') {
1433
1448
  const nodeType = typeof jsxNode.type;
1434
1449
  if (nodeType === 'string') {
1435
- return createChainByJSXNode(ElementAtomType, jsxNode, jsxNode.type, prevAtom, isSvg || jsxNode.type === 'svg', jsxNode.key);
1450
+ return createChainByJSXNode(ElementAtomType, jsxNode, jsxNode.type, prevAtom, elementNamespace || ElementNamespaceMap[jsxNode.type], jsxNode.key);
1436
1451
  }
1437
1452
  else if (nodeType === 'function') {
1438
- return createChainByJSXNode(ComponentAtomType, jsxNode, jsxNode.type, prevAtom, isSvg, jsxNode.key);
1453
+ return createChainByJSXNode(ComponentAtomType, jsxNode, jsxNode.type, prevAtom, ElementNamespaceMap[jsxNode.type], jsxNode.key);
1439
1454
  }
1440
1455
  }
1441
1456
  const text = String(jsxNode);
1442
- return createChainByJSXNode(TextAtomType, text, text, prevAtom, isSvg);
1457
+ return createChainByJSXNode(TextAtomType, text, text, prevAtom, ElementNamespaceMap[jsxNode.type]);
1443
1458
  }
1444
1459
  return prevAtom;
1445
1460
  }
1446
- function createChainByChildren(children, prevAtom, isSvg) {
1461
+ function createChainByChildren(children, prevAtom, elementNamespace) {
1447
1462
  for (const item of children) {
1448
- prevAtom = createChainByNode(item, prevAtom, isSvg);
1463
+ prevAtom = createChainByNode(item, prevAtom, elementNamespace);
1449
1464
  }
1450
1465
  return prevAtom;
1451
1466
  }
1452
- function createChildChain(template, isSvg) {
1467
+ function createChildChain(template, namespace) {
1453
1468
  const beforeAtom = { sibling: null, index: -1 };
1454
- createChainByNode(template, beforeAtom, isSvg);
1469
+ createChainByNode(template, beforeAtom, namespace);
1455
1470
  return beforeAtom.sibling;
1456
1471
  }
1457
1472
  function insertNode(nativeRenderer, atom, context) {
1458
1473
  if (context.isParent) {
1459
1474
  if (context.host === context.rootHost) {
1460
- nativeRenderer.appendChild(context.host, atom.nativeNode, atom.isSvg);
1475
+ nativeRenderer.appendChild(context.host, atom.nativeNode, atom.namespace);
1461
1476
  }
1462
1477
  else {
1463
- nativeRenderer.prependChild(context.host, atom.nativeNode, atom.isSvg);
1478
+ nativeRenderer.prependChild(context.host, atom.nativeNode, atom.namespace);
1464
1479
  }
1465
1480
  }
1466
1481
  else {
1467
- nativeRenderer.insertAfter(atom.nativeNode, context.host, atom.isSvg);
1482
+ nativeRenderer.insertAfter(atom.nativeNode, context.host, atom.namespace);
1468
1483
  }
1469
1484
  }
1470
1485
  function createElement(nativeRenderer, atom, parentComponent, context) {
1471
- const { isSvg, jsxNode } = atom;
1472
- const nativeNode = nativeRenderer.createElement(jsxNode.type, isSvg);
1486
+ const { namespace, jsxNode } = atom;
1487
+ const nativeNode = nativeRenderer.createElement(jsxNode.type, namespace);
1473
1488
  const props = jsxNode.props;
1474
1489
  let bindingRefs;
1475
1490
  for (const key in props) {
1476
1491
  if (key === 'children') {
1477
- atom.child = createChildChain(jsxNode.props.children, isSvg);
1492
+ atom.child = createChildChain(jsxNode.props.children, namespace);
1478
1493
  continue;
1479
1494
  }
1480
1495
  if (key === 'class') {
1481
1496
  const className = classToString(props[key]);
1482
1497
  if (className) {
1483
- nativeRenderer.setClass(nativeNode, className, isSvg);
1498
+ nativeRenderer.setClass(nativeNode, className, namespace);
1484
1499
  }
1485
1500
  continue;
1486
1501
  }
1487
1502
  if (key === 'style') {
1488
1503
  const style = styleToObject(props.style);
1489
1504
  for (const key in style) {
1490
- nativeRenderer.setStyle(nativeNode, key, style[key], isSvg);
1505
+ nativeRenderer.setStyle(nativeNode, key, style[key], namespace);
1491
1506
  }
1492
1507
  continue;
1493
1508
  }
1494
1509
  if (listenerReg.test(key)) {
1495
1510
  const listener = props[key];
1496
1511
  if (typeof listener === 'function') {
1497
- nativeRenderer.listen(nativeNode, key, listener, isSvg);
1512
+ nativeRenderer.listen(nativeNode, key, listener, namespace);
1498
1513
  }
1499
1514
  continue;
1500
1515
  }
@@ -1502,7 +1517,7 @@ function createElement(nativeRenderer, atom, parentComponent, context) {
1502
1517
  bindingRefs = props[key];
1503
1518
  continue;
1504
1519
  }
1505
- nativeRenderer.setProperty(nativeNode, key, props[key], isSvg);
1520
+ nativeRenderer.setProperty(nativeNode, key, props[key], namespace);
1506
1521
  }
1507
1522
  atom.nativeNode = nativeNode;
1508
1523
  insertNode(nativeRenderer, atom, context);
@@ -1516,7 +1531,7 @@ function createElement(nativeRenderer, atom, parentComponent, context) {
1516
1531
  applyRefs(bindingRefs, nativeNode, true);
1517
1532
  }
1518
1533
  function createTextNode(nativeRenderer, atom, context) {
1519
- const nativeNode = nativeRenderer.createTextNode(atom.jsxNode, atom.isSvg);
1534
+ const nativeNode = nativeRenderer.createTextNode(atom.jsxNode, atom.namespace);
1520
1535
  atom.nativeNode = nativeNode;
1521
1536
  insertNode(nativeRenderer, atom, context);
1522
1537
  context.host = nativeNode;
@@ -1524,7 +1539,7 @@ function createTextNode(nativeRenderer, atom, context) {
1524
1539
  }
1525
1540
  function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComponent, context) {
1526
1541
  const newVNode = newAtom.jsxNode;
1527
- const isSvg = newAtom.isSvg;
1542
+ const isSvg = newAtom.namespace;
1528
1543
  const nativeNode = newAtom.nativeNode;
1529
1544
  const oldVNode = oldAtom.jsxNode;
1530
1545
  if (newVNode === oldVNode) {
@@ -1824,7 +1839,7 @@ function viewfly(config) {
1824
1839
  render(appHost);
1825
1840
  });
1826
1841
  });
1827
- const render = createRenderer(rootComponent, nativeRenderer);
1842
+ const render = createRenderer(rootComponent, nativeRenderer, config.elementNamespace);
1828
1843
  let isStarted = false;
1829
1844
  let task = null;
1830
1845
  function nextTick(callback) {
@@ -1888,4 +1903,4 @@ function viewfly(config) {
1888
1903
  return app;
1889
1904
  }
1890
1905
 
1891
- export { Component, Context, DynamicRef, ForwardRef, Fragment, Inject, InjectFlags, Injectable, InjectionToken, Injector, JSXNodeFactory, NativeRenderer, NullInjector, Optional, Prop, ReflectiveInjector, RootComponent, Scope, Self, SkipSelf, StaticRef, THROW_IF_NOT_FOUND, Type, computed, createDerived, createDynamicRef, createRef, createRenderer, createSignal, forwardRef, getCurrentInstance, getSetupContext, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, viewfly, watch, withAnnotation, withMemo };
1906
+ export { Component, Context, DynamicRef, ElementNamespaceMap, ForwardRef, Fragment, Inject, InjectFlags, Injectable, InjectionToken, Injector, JSXNodeFactory, NativeRenderer, NullInjector, Optional, Prop, ReflectiveInjector, RootComponent, Scope, Self, SkipSelf, StaticRef, THROW_IF_NOT_FOUND, Type, computed, createDerived, createDynamicRef, createRef, createRenderer, createSignal, forwardRef, getCurrentInstance, getSetupContext, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, viewfly, watch, withAnnotation, withMemo };
package/bundles/index.js CHANGED
@@ -1098,10 +1098,21 @@ function Fragment(props) {
1098
1098
  };
1099
1099
  }
1100
1100
  function Context(props) {
1101
- const instance = getCurrentInstance();
1102
- instance.provide(props.providers);
1101
+ function createContextComponent(providers) {
1102
+ return withAnnotation({
1103
+ providers,
1104
+ }, () => {
1105
+ return () => {
1106
+ return props.children;
1107
+ };
1108
+ });
1109
+ }
1110
+ let contextComponent = createContextComponent(props.providers);
1111
+ onPropsChanged((newProps) => {
1112
+ contextComponent = createContextComponent(newProps.providers);
1113
+ });
1103
1114
  return () => {
1104
- return props.children;
1115
+ return jsx(contextComponent, {});
1105
1116
  };
1106
1117
  }
1107
1118
  function jsx(type, props, key) {
@@ -1125,9 +1136,13 @@ function withMemo(canUseMemo, render) {
1125
1136
  };
1126
1137
  }
1127
1138
 
1139
+ const ElementNamespaceMap = {
1140
+ svg: 'svg',
1141
+ math: 'mathml',
1142
+ };
1128
1143
  const componentViewCache = new WeakMap();
1129
1144
  const listenerReg = /^on[A-Z]/;
1130
- function createRenderer(component, nativeRenderer) {
1145
+ function createRenderer(component, nativeRenderer, namespace) {
1131
1146
  let isInit = true;
1132
1147
  return function render(host) {
1133
1148
  if (isInit) {
@@ -1140,7 +1155,7 @@ function createRenderer(component, nativeRenderer) {
1140
1155
  sibling: null,
1141
1156
  child: null,
1142
1157
  nativeNode: null,
1143
- isSvg: false
1158
+ namespace
1144
1159
  };
1145
1160
  componentRender(nativeRenderer, component, atom, {
1146
1161
  isParent: true,
@@ -1193,7 +1208,7 @@ function updateView(nativeRenderer, component, needMove) {
1193
1208
  function applyChanges(nativeRenderer, component, atom, context, needMove) {
1194
1209
  const diffAtom = atom.child;
1195
1210
  component.update(component.props, newTemplate => {
1196
- atom.child = createChildChain(newTemplate, atom.isSvg);
1211
+ atom.child = createChildChain(newTemplate, atom.namespace);
1197
1212
  diff(nativeRenderer, component, atom.child, diffAtom, context, needMove);
1198
1213
  const next = atom.sibling;
1199
1214
  if (next && next.jsxNode instanceof Component) {
@@ -1306,7 +1321,7 @@ function updateComponent(newAtom, reusedAtom, nativeRenderer, context) {
1306
1321
  newAtom.jsxNode = component;
1307
1322
  component.update(newProps, newTemplate => {
1308
1323
  if (newTemplate) {
1309
- newAtom.child = createChildChain(newTemplate, newAtom.isSvg);
1324
+ newAtom.child = createChildChain(newTemplate, newAtom.namespace);
1310
1325
  }
1311
1326
  if (newAtom.child) {
1312
1327
  diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context, needMove || newAtom.index - offset !== reusedAtom.index);
@@ -1366,7 +1381,7 @@ function reuseElementChildrenView(nativeRenderer, atom, context, skipSubComponen
1366
1381
  }
1367
1382
  function cleanElementChildren(atom, nativeRenderer) {
1368
1383
  let child = atom.child;
1369
- nativeRenderer.cleanChildren(atom.nativeNode, atom.isSvg);
1384
+ nativeRenderer.cleanChildren(atom.nativeNode, atom.namespace);
1370
1385
  while (child) {
1371
1386
  cleanView(nativeRenderer, child, false);
1372
1387
  child = child.sibling;
@@ -1375,7 +1390,7 @@ function cleanElementChildren(atom, nativeRenderer) {
1375
1390
  function cleanView(nativeRenderer, atom, needClean) {
1376
1391
  if (atom.nativeNode) {
1377
1392
  if (needClean) {
1378
- nativeRenderer.remove(atom.nativeNode, atom.isSvg);
1393
+ nativeRenderer.remove(atom.nativeNode, atom.namespace);
1379
1394
  needClean = false;
1380
1395
  }
1381
1396
  if (atom.type === ElementAtomType) {
@@ -1397,7 +1412,7 @@ function cleanView(nativeRenderer, atom, needClean) {
1397
1412
  }
1398
1413
  function componentRender(nativeRenderer, component, from, context) {
1399
1414
  component.render((template, portalHost) => {
1400
- from.child = createChildChain(template, from.isSvg);
1415
+ from.child = createChildChain(template, from.namespace);
1401
1416
  context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
1402
1417
  componentViewCache.set(component, Object.assign({ atom: from }, context));
1403
1418
  let child = from.child;
@@ -1407,7 +1422,7 @@ function componentRender(nativeRenderer, component, from, context) {
1407
1422
  }
1408
1423
  });
1409
1424
  }
1410
- function createChainByJSXNode(type, jsxNode, nodeType, prevAtom, isSvg, key) {
1425
+ function createChainByJSXNode(type, jsxNode, nodeType, prevAtom, namespace, key) {
1411
1426
  const atom = {
1412
1427
  type,
1413
1428
  index: prevAtom.index + 1,
@@ -1415,88 +1430,88 @@ function createChainByJSXNode(type, jsxNode, nodeType, prevAtom, isSvg, key) {
1415
1430
  sibling: null,
1416
1431
  child: null,
1417
1432
  nativeNode: null,
1418
- isSvg,
1433
+ namespace,
1419
1434
  nodeType,
1420
1435
  key
1421
1436
  };
1422
1437
  prevAtom.sibling = atom;
1423
1438
  return atom;
1424
1439
  }
1425
- function createChainByNode(jsxNode, prevAtom, isSvg) {
1440
+ function createChainByNode(jsxNode, prevAtom, elementNamespace) {
1426
1441
  const type = typeof jsxNode;
1427
1442
  if (jsxNode !== null && type !== 'undefined' && type !== 'boolean') {
1428
1443
  if (typeof jsxNode === 'string') {
1429
- return createChainByJSXNode(TextAtomType, jsxNode, jsxNode, prevAtom, isSvg);
1444
+ return createChainByJSXNode(TextAtomType, jsxNode, jsxNode, prevAtom, elementNamespace);
1430
1445
  }
1431
1446
  if (Array.isArray(jsxNode)) {
1432
- return createChainByChildren(jsxNode, prevAtom, isSvg);
1447
+ return createChainByChildren(jsxNode, prevAtom, elementNamespace);
1433
1448
  }
1434
1449
  if (type === 'object') {
1435
1450
  const nodeType = typeof jsxNode.type;
1436
1451
  if (nodeType === 'string') {
1437
- return createChainByJSXNode(ElementAtomType, jsxNode, jsxNode.type, prevAtom, isSvg || jsxNode.type === 'svg', jsxNode.key);
1452
+ return createChainByJSXNode(ElementAtomType, jsxNode, jsxNode.type, prevAtom, elementNamespace || ElementNamespaceMap[jsxNode.type], jsxNode.key);
1438
1453
  }
1439
1454
  else if (nodeType === 'function') {
1440
- return createChainByJSXNode(ComponentAtomType, jsxNode, jsxNode.type, prevAtom, isSvg, jsxNode.key);
1455
+ return createChainByJSXNode(ComponentAtomType, jsxNode, jsxNode.type, prevAtom, ElementNamespaceMap[jsxNode.type], jsxNode.key);
1441
1456
  }
1442
1457
  }
1443
1458
  const text = String(jsxNode);
1444
- return createChainByJSXNode(TextAtomType, text, text, prevAtom, isSvg);
1459
+ return createChainByJSXNode(TextAtomType, text, text, prevAtom, ElementNamespaceMap[jsxNode.type]);
1445
1460
  }
1446
1461
  return prevAtom;
1447
1462
  }
1448
- function createChainByChildren(children, prevAtom, isSvg) {
1463
+ function createChainByChildren(children, prevAtom, elementNamespace) {
1449
1464
  for (const item of children) {
1450
- prevAtom = createChainByNode(item, prevAtom, isSvg);
1465
+ prevAtom = createChainByNode(item, prevAtom, elementNamespace);
1451
1466
  }
1452
1467
  return prevAtom;
1453
1468
  }
1454
- function createChildChain(template, isSvg) {
1469
+ function createChildChain(template, namespace) {
1455
1470
  const beforeAtom = { sibling: null, index: -1 };
1456
- createChainByNode(template, beforeAtom, isSvg);
1471
+ createChainByNode(template, beforeAtom, namespace);
1457
1472
  return beforeAtom.sibling;
1458
1473
  }
1459
1474
  function insertNode(nativeRenderer, atom, context) {
1460
1475
  if (context.isParent) {
1461
1476
  if (context.host === context.rootHost) {
1462
- nativeRenderer.appendChild(context.host, atom.nativeNode, atom.isSvg);
1477
+ nativeRenderer.appendChild(context.host, atom.nativeNode, atom.namespace);
1463
1478
  }
1464
1479
  else {
1465
- nativeRenderer.prependChild(context.host, atom.nativeNode, atom.isSvg);
1480
+ nativeRenderer.prependChild(context.host, atom.nativeNode, atom.namespace);
1466
1481
  }
1467
1482
  }
1468
1483
  else {
1469
- nativeRenderer.insertAfter(atom.nativeNode, context.host, atom.isSvg);
1484
+ nativeRenderer.insertAfter(atom.nativeNode, context.host, atom.namespace);
1470
1485
  }
1471
1486
  }
1472
1487
  function createElement(nativeRenderer, atom, parentComponent, context) {
1473
- const { isSvg, jsxNode } = atom;
1474
- const nativeNode = nativeRenderer.createElement(jsxNode.type, isSvg);
1488
+ const { namespace, jsxNode } = atom;
1489
+ const nativeNode = nativeRenderer.createElement(jsxNode.type, namespace);
1475
1490
  const props = jsxNode.props;
1476
1491
  let bindingRefs;
1477
1492
  for (const key in props) {
1478
1493
  if (key === 'children') {
1479
- atom.child = createChildChain(jsxNode.props.children, isSvg);
1494
+ atom.child = createChildChain(jsxNode.props.children, namespace);
1480
1495
  continue;
1481
1496
  }
1482
1497
  if (key === 'class') {
1483
1498
  const className = classToString(props[key]);
1484
1499
  if (className) {
1485
- nativeRenderer.setClass(nativeNode, className, isSvg);
1500
+ nativeRenderer.setClass(nativeNode, className, namespace);
1486
1501
  }
1487
1502
  continue;
1488
1503
  }
1489
1504
  if (key === 'style') {
1490
1505
  const style = styleToObject(props.style);
1491
1506
  for (const key in style) {
1492
- nativeRenderer.setStyle(nativeNode, key, style[key], isSvg);
1507
+ nativeRenderer.setStyle(nativeNode, key, style[key], namespace);
1493
1508
  }
1494
1509
  continue;
1495
1510
  }
1496
1511
  if (listenerReg.test(key)) {
1497
1512
  const listener = props[key];
1498
1513
  if (typeof listener === 'function') {
1499
- nativeRenderer.listen(nativeNode, key, listener, isSvg);
1514
+ nativeRenderer.listen(nativeNode, key, listener, namespace);
1500
1515
  }
1501
1516
  continue;
1502
1517
  }
@@ -1504,7 +1519,7 @@ function createElement(nativeRenderer, atom, parentComponent, context) {
1504
1519
  bindingRefs = props[key];
1505
1520
  continue;
1506
1521
  }
1507
- nativeRenderer.setProperty(nativeNode, key, props[key], isSvg);
1522
+ nativeRenderer.setProperty(nativeNode, key, props[key], namespace);
1508
1523
  }
1509
1524
  atom.nativeNode = nativeNode;
1510
1525
  insertNode(nativeRenderer, atom, context);
@@ -1518,7 +1533,7 @@ function createElement(nativeRenderer, atom, parentComponent, context) {
1518
1533
  applyRefs(bindingRefs, nativeNode, true);
1519
1534
  }
1520
1535
  function createTextNode(nativeRenderer, atom, context) {
1521
- const nativeNode = nativeRenderer.createTextNode(atom.jsxNode, atom.isSvg);
1536
+ const nativeNode = nativeRenderer.createTextNode(atom.jsxNode, atom.namespace);
1522
1537
  atom.nativeNode = nativeNode;
1523
1538
  insertNode(nativeRenderer, atom, context);
1524
1539
  context.host = nativeNode;
@@ -1526,7 +1541,7 @@ function createTextNode(nativeRenderer, atom, context) {
1526
1541
  }
1527
1542
  function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComponent, context) {
1528
1543
  const newVNode = newAtom.jsxNode;
1529
- const isSvg = newAtom.isSvg;
1544
+ const isSvg = newAtom.namespace;
1530
1545
  const nativeNode = newAtom.nativeNode;
1531
1546
  const oldVNode = oldAtom.jsxNode;
1532
1547
  if (newVNode === oldVNode) {
@@ -1826,7 +1841,7 @@ function viewfly(config) {
1826
1841
  render(appHost);
1827
1842
  });
1828
1843
  });
1829
- const render = createRenderer(rootComponent, nativeRenderer);
1844
+ const render = createRenderer(rootComponent, nativeRenderer, config.elementNamespace);
1830
1845
  let isStarted = false;
1831
1846
  let task = null;
1832
1847
  function nextTick(callback) {
@@ -1893,6 +1908,7 @@ function viewfly(config) {
1893
1908
  exports.Component = Component;
1894
1909
  exports.Context = Context;
1895
1910
  exports.DynamicRef = DynamicRef;
1911
+ exports.ElementNamespaceMap = ElementNamespaceMap;
1896
1912
  exports.ForwardRef = ForwardRef;
1897
1913
  exports.Fragment = Fragment;
1898
1914
  exports.Inject = Inject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
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": "b66ca589f7662cd518fc2e5955b3e3ff9de83f94",
53
+ "gitHead": "56c28e6d0f87586ea6dda6597b00b4c5326edc07",
54
54
  "dependencies": {
55
55
  "reflect-metadata": "^0.2.2"
56
56
  }