@viewfly/core 3.0.1 → 3.0.2

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/README.en.md ADDED
@@ -0,0 +1,71 @@
1
+ # @viewfly/core
2
+
3
+ **Languages:** [简体中文](./README.md)
4
+
5
+ The **core** Viewfly package: function components, JSX, reactivity and `signal`, `watch`, lifecycle, `inject` / IoC APIs, and **`withMark`** for UI-facing utilities.
6
+
7
+ To mount in the browser use **`createApp`** from **`@viewfly/platform-browser`** (built on this package’s application model).
8
+
9
+ ---
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @viewfly/core
15
+ ```
16
+
17
+ This package depends on **`reflect-metadata`**. Importing from the **`@viewfly/core`** main entry initializes it; if DI breaks after aggressive splitting, add at the **top** of your entry:
18
+
19
+ ```ts
20
+ import 'reflect-metadata'
21
+ ```
22
+
23
+ Prefer the **`.d.ts`** shipped with your installed version and the official docs (<https://viewfly.org>) as the source of truth.
24
+
25
+ ---
26
+
27
+ ## JSX / TSX setup
28
+
29
+ Enable automatic JSX runtime and point it at this package:
30
+
31
+ ```json
32
+ {
33
+ "compilerOptions": {
34
+ "jsx": "react-jsx",
35
+ "jsxImportSource": "@viewfly/core"
36
+ }
37
+ }
38
+ ```
39
+
40
+ With Babel, align `@babel/preset-react` (`runtime: "automatic"`, `importSource: "@viewfly/core"`).
41
+
42
+ ---
43
+
44
+ ## Capabilities (user-facing)
45
+
46
+ Common directions below — **exact types and parameters come from `.d.ts` and the docs**.
47
+
48
+ | Area | Public API hints |
49
+ |------|------------------|
50
+ | Components | Function components as JSX tags; pair with lifecycle hooks. |
51
+ | Lifecycle | **`onMounted`**, **`onUpdated`**, **`onUnmounted`**, etc. (call during component setup). |
52
+ | Reactivity | **`reactive`**, **`shallowReactive`**, **`watch`**, … (`reactive` module). |
53
+ | `signal` / derived | **`createSignal`**, **`computed`**, … (see `reactive` exports). |
54
+ | DI | **`inject`** in components; **`Injectable()`** on classes; **`withAnnotation`** or **`createContext`** / **`createContextProvider`** for providers; root **`createApp(...).provide(...)`** from **`@viewfly/platform-browser`**. |
55
+ | DOM marks | **`withMark(marks, setup)`** — attach attributes (e.g. scoped CSS `scopeId`). |
56
+
57
+ Symbols marked **`@internal`** or undocumented on the site are for framework/experimental use — **avoid relying on them** in apps; they may change without semver guarantees.
58
+
59
+ ---
60
+
61
+ ## Docs & examples
62
+
63
+ - **Official docs:** <https://viewfly.org> (install, components, reactivity, DI).
64
+ - **Types & comments:** published **`.d.ts`** and source comments.
65
+ - **This repo:** `pnpm install` at root, then `pnpm dev` for the playground.
66
+
67
+ ---
68
+
69
+ ## License
70
+
71
+ MIT
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @viewfly/core
2
2
 
3
+ **Languages:** [English](./README.en.md)
4
+
3
5
  Viewfly 的**内核包**:函数组件、`JSX`、响应式与 `signal`、`watch`、生命周期、`inject` 与 IoC 相关 API、以及 **`withMark`** 等与 UI 逻辑直接相关的入口均由此包提供。
4
6
 
5
7
  在浏览器里挂载应用请使用 **`@viewfly/platform-browser`** 的 **`createApp`**(其内部使用本包提供的应用模型)。
@@ -48,9 +48,8 @@ export declare class Component {
48
48
  constructor(parentComponent: Component | null, type: ComponentSetup, props: Record<string, any>, key?: Key);
49
49
  markAsDirtied(): void;
50
50
  markAsChanged(changedComponent?: Component): void;
51
- render(update: (template: JSXNode) => void): void;
51
+ render(): JSXNode;
52
52
  updateProps(newProps: Record<string, any>): void;
53
- rerender(): JSXNode;
54
53
  destroy(): void;
55
54
  rendered(): void;
56
55
  private invokeMountHooks;
package/dist/index.esm.js CHANGED
@@ -1475,7 +1475,6 @@ var Component = class {
1475
1475
  constructor(parentComponent, type, props, key) {
1476
1476
  this.parentComponent = parentComponent;
1477
1477
  this.type = type;
1478
- this.props = props;
1479
1478
  this.key = key;
1480
1479
  this.instance = null;
1481
1480
  this.changedSubComponents = null;
@@ -1507,7 +1506,14 @@ var Component = class {
1507
1506
  this._changed = true;
1508
1507
  if (this.parentComponent) this.parentComponent.markAsChanged(this);
1509
1508
  }
1510
- render(update) {
1509
+ render() {
1510
+ if (this.instance) {
1511
+ this.listener.destroy();
1512
+ pushDepContext(this.listener);
1513
+ const template = this.instance.render();
1514
+ popDepContext();
1515
+ return template;
1516
+ }
1511
1517
  componentSetupStack.push(this);
1512
1518
  const render = this.type(this.props);
1513
1519
  const isRenderFn = typeof render === "function";
@@ -1529,8 +1535,7 @@ var Component = class {
1529
1535
  pushDepContext(this.listener);
1530
1536
  const template = this.instance.render();
1531
1537
  popDepContext();
1532
- update(template);
1533
- this.rendered();
1538
+ return template;
1534
1539
  }
1535
1540
  updateProps(newProps) {
1536
1541
  const oldProps = this.rawProps;
@@ -1554,13 +1559,6 @@ var Component = class {
1554
1559
  });
1555
1560
  });
1556
1561
  }
1557
- rerender() {
1558
- this.listener.destroy();
1559
- pushDepContext(this.listener);
1560
- const template = this.instance.render();
1561
- popDepContext();
1562
- return template;
1563
- }
1564
1562
  destroy() {
1565
1563
  this.listener.destroy();
1566
1564
  if (this.updatedDestroyCallbacks) this.updatedDestroyCallbacks.forEach((fn) => {
@@ -1569,7 +1567,8 @@ var Component = class {
1569
1567
  if (this.unmountedCallbacks) this.unmountedCallbacks.forEach((fn) => {
1570
1568
  fn();
1571
1569
  });
1572
- this.parentComponent = this.changedSubComponents = this.refEffects = this.updatedDestroyCallbacks = this.mountCallbacks = this.updatedCallbacks = this.unmountedCallbacks = null;
1570
+ this.isFirstRendering = true;
1571
+ this.changedSubComponents = this.refEffects = this.updatedDestroyCallbacks = this.mountCallbacks = this.updatedCallbacks = this.unmountedCallbacks = this.instance = null;
1573
1572
  }
1574
1573
  rendered() {
1575
1574
  this.changedSubComponents?.clear();
@@ -1998,7 +1997,7 @@ function buildElementChildren(atom, nativeRenderer, parentComponent, context) {
1998
1997
  }
1999
1998
  }
2000
1999
  function patchComponent(nativeRenderer, component, oldChildAtom, newAtom, context, needMove) {
2001
- const newTemplate = component.rerender();
2000
+ const newTemplate = component.render();
2002
2001
  const portalContainer = getContainer();
2003
2002
  const rawContext = context;
2004
2003
  const { computedContainer, contextContainer } = component.viewMetadata;
@@ -2218,26 +2217,26 @@ function cleanChildren(atom, nativeRenderer, needClean) {
2218
2217
  }
2219
2218
  }
2220
2219
  function componentRender(nativeRenderer, component, from, context) {
2221
- component.render((template) => {
2222
- const portalContainer = getContainer();
2223
- popContainer();
2224
- from.child = createChildChain(template, nativeRenderer, from.namespace);
2225
- if (portalContainer && portalContainer !== context.contextContainer) context = {
2226
- isParent: true,
2227
- anchorNode: portalContainer,
2228
- contextContainer: context.contextContainer,
2229
- computedContainer: portalContainer
2230
- };
2231
- component.viewMetadata = {
2232
- atom: from,
2233
- ...context
2234
- };
2235
- let child = from.child;
2236
- while (child) {
2237
- buildView(nativeRenderer, component, child, context);
2238
- child = child.sibling;
2239
- }
2240
- });
2220
+ const template = component.render();
2221
+ const portalContainer = getContainer();
2222
+ popContainer();
2223
+ from.child = createChildChain(template, nativeRenderer, from.namespace);
2224
+ if (portalContainer && portalContainer !== context.contextContainer) context = {
2225
+ isParent: true,
2226
+ anchorNode: portalContainer,
2227
+ contextContainer: context.contextContainer,
2228
+ computedContainer: portalContainer
2229
+ };
2230
+ component.viewMetadata = {
2231
+ atom: from,
2232
+ ...context
2233
+ };
2234
+ let child = from.child;
2235
+ while (child) {
2236
+ buildView(nativeRenderer, component, child, context);
2237
+ child = child.sibling;
2238
+ }
2239
+ component.rendered();
2241
2240
  }
2242
2241
  function createChainByJSXNode(type, jsxNode, nodeType, prevAtom, namespace, key) {
2243
2242
  const atom = {
package/dist/index.js CHANGED
@@ -1476,7 +1476,6 @@ var Component = class {
1476
1476
  constructor(parentComponent, type, props, key) {
1477
1477
  this.parentComponent = parentComponent;
1478
1478
  this.type = type;
1479
- this.props = props;
1480
1479
  this.key = key;
1481
1480
  this.instance = null;
1482
1481
  this.changedSubComponents = null;
@@ -1508,7 +1507,14 @@ var Component = class {
1508
1507
  this._changed = true;
1509
1508
  if (this.parentComponent) this.parentComponent.markAsChanged(this);
1510
1509
  }
1511
- render(update) {
1510
+ render() {
1511
+ if (this.instance) {
1512
+ this.listener.destroy();
1513
+ pushDepContext(this.listener);
1514
+ const template = this.instance.render();
1515
+ popDepContext();
1516
+ return template;
1517
+ }
1512
1518
  componentSetupStack.push(this);
1513
1519
  const render = this.type(this.props);
1514
1520
  const isRenderFn = typeof render === "function";
@@ -1530,8 +1536,7 @@ var Component = class {
1530
1536
  pushDepContext(this.listener);
1531
1537
  const template = this.instance.render();
1532
1538
  popDepContext();
1533
- update(template);
1534
- this.rendered();
1539
+ return template;
1535
1540
  }
1536
1541
  updateProps(newProps) {
1537
1542
  const oldProps = this.rawProps;
@@ -1555,13 +1560,6 @@ var Component = class {
1555
1560
  });
1556
1561
  });
1557
1562
  }
1558
- rerender() {
1559
- this.listener.destroy();
1560
- pushDepContext(this.listener);
1561
- const template = this.instance.render();
1562
- popDepContext();
1563
- return template;
1564
- }
1565
1563
  destroy() {
1566
1564
  this.listener.destroy();
1567
1565
  if (this.updatedDestroyCallbacks) this.updatedDestroyCallbacks.forEach((fn) => {
@@ -1570,7 +1568,8 @@ var Component = class {
1570
1568
  if (this.unmountedCallbacks) this.unmountedCallbacks.forEach((fn) => {
1571
1569
  fn();
1572
1570
  });
1573
- this.parentComponent = this.changedSubComponents = this.refEffects = this.updatedDestroyCallbacks = this.mountCallbacks = this.updatedCallbacks = this.unmountedCallbacks = null;
1571
+ this.isFirstRendering = true;
1572
+ this.changedSubComponents = this.refEffects = this.updatedDestroyCallbacks = this.mountCallbacks = this.updatedCallbacks = this.unmountedCallbacks = this.instance = null;
1574
1573
  }
1575
1574
  rendered() {
1576
1575
  this.changedSubComponents?.clear();
@@ -1999,7 +1998,7 @@ function buildElementChildren(atom, nativeRenderer, parentComponent, context) {
1999
1998
  }
2000
1999
  }
2001
2000
  function patchComponent(nativeRenderer, component, oldChildAtom, newAtom, context, needMove) {
2002
- const newTemplate = component.rerender();
2001
+ const newTemplate = component.render();
2003
2002
  const portalContainer = getContainer();
2004
2003
  const rawContext = context;
2005
2004
  const { computedContainer, contextContainer } = component.viewMetadata;
@@ -2219,26 +2218,26 @@ function cleanChildren(atom, nativeRenderer, needClean) {
2219
2218
  }
2220
2219
  }
2221
2220
  function componentRender(nativeRenderer, component, from, context) {
2222
- component.render((template) => {
2223
- const portalContainer = getContainer();
2224
- popContainer();
2225
- from.child = createChildChain(template, nativeRenderer, from.namespace);
2226
- if (portalContainer && portalContainer !== context.contextContainer) context = {
2227
- isParent: true,
2228
- anchorNode: portalContainer,
2229
- contextContainer: context.contextContainer,
2230
- computedContainer: portalContainer
2231
- };
2232
- component.viewMetadata = {
2233
- atom: from,
2234
- ...context
2235
- };
2236
- let child = from.child;
2237
- while (child) {
2238
- buildView(nativeRenderer, component, child, context);
2239
- child = child.sibling;
2240
- }
2241
- });
2221
+ const template = component.render();
2222
+ const portalContainer = getContainer();
2223
+ popContainer();
2224
+ from.child = createChildChain(template, nativeRenderer, from.namespace);
2225
+ if (portalContainer && portalContainer !== context.contextContainer) context = {
2226
+ isParent: true,
2227
+ anchorNode: portalContainer,
2228
+ contextContainer: context.contextContainer,
2229
+ computedContainer: portalContainer
2230
+ };
2231
+ component.viewMetadata = {
2232
+ atom: from,
2233
+ ...context
2234
+ };
2235
+ let child = from.child;
2236
+ while (child) {
2237
+ buildView(nativeRenderer, component, child, context);
2238
+ child = child.sibling;
2239
+ }
2240
+ component.rendered();
2242
2241
  }
2243
2242
  function createChainByJSXNode(type, jsxNode, nodeType, prevAtom, namespace, key) {
2244
2243
  const atom = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Viewfly is a simple and easy-to-use JavaScript framework with an intuitive development experience.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.esm.js",