@viewfly/core 3.0.1 → 3.0.3
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 +71 -0
- package/README.md +2 -0
- package/dist/base/component.d.ts +1 -2
- package/dist/base/injection-tokens.d.ts +1 -0
- package/dist/index.esm.js +34 -35
- package/dist/index.js +34 -35
- package/package.json +1 -1
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
package/dist/base/component.d.ts
CHANGED
|
@@ -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(
|
|
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;
|
|
@@ -17,4 +17,5 @@ export declare abstract class NativeRenderer<ElementNode = NativeNode, TextNode
|
|
|
17
17
|
abstract syncTextContent(target: TextNode, content: string, namespace: ElementNamespace): void;
|
|
18
18
|
abstract insertAfter(newNode: ElementNode | TextNode, ref: ElementNode | TextNode, namespace: ElementNamespace): void;
|
|
19
19
|
abstract getNameSpace(type: string, namespace: ElementNamespace): string | void;
|
|
20
|
+
abstract getChildrenNameSpace(type: string, namespace: ElementNamespace): string | void;
|
|
20
21
|
}
|
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(
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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(
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
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 = {
|
|
@@ -2262,7 +2261,7 @@ function createChainByNode(jsxNode, prevAtom, nativeRenderer, elementNamespace)
|
|
|
2262
2261
|
if (Array.isArray(jsxNode)) return createChainByChildren(jsxNode, prevAtom, nativeRenderer, elementNamespace);
|
|
2263
2262
|
const nodeType = typeof jsxNode.type;
|
|
2264
2263
|
if (nodeType === "string") return createChainByJSXNode(ElementAtomType, jsxNode, jsxNode.type, prevAtom, nativeRenderer.getNameSpace(jsxNode.type, elementNamespace), jsxNode.key);
|
|
2265
|
-
|
|
2264
|
+
if (nodeType === "function") return createChainByJSXNode(ComponentAtomType, jsxNode, jsxNode.type, prevAtom, elementNamespace, jsxNode.key);
|
|
2266
2265
|
}
|
|
2267
2266
|
const text = String(jsxNode);
|
|
2268
2267
|
return createChainByJSXNode(TextAtomType, text, text, prevAtom, elementNamespace);
|
|
@@ -2291,7 +2290,7 @@ function insertNode(nativeRenderer, atom, context) {
|
|
|
2291
2290
|
else nativeRenderer.insertAfter(atom.nativeNode, context.anchorNode, atom.namespace);
|
|
2292
2291
|
}
|
|
2293
2292
|
function createElementChildren(type, children, nativeRenderer, namespace) {
|
|
2294
|
-
return createChildChain(children, nativeRenderer, nativeRenderer.
|
|
2293
|
+
return createChildChain(children, nativeRenderer, nativeRenderer.getChildrenNameSpace(type, namespace));
|
|
2295
2294
|
}
|
|
2296
2295
|
function createElement(nativeRenderer, atom, parentComponent, context) {
|
|
2297
2296
|
const { namespace, jsxNode } = 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(
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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(
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
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 = {
|
|
@@ -2263,7 +2262,7 @@ function createChainByNode(jsxNode, prevAtom, nativeRenderer, elementNamespace)
|
|
|
2263
2262
|
if (Array.isArray(jsxNode)) return createChainByChildren(jsxNode, prevAtom, nativeRenderer, elementNamespace);
|
|
2264
2263
|
const nodeType = typeof jsxNode.type;
|
|
2265
2264
|
if (nodeType === "string") return createChainByJSXNode(ElementAtomType, jsxNode, jsxNode.type, prevAtom, nativeRenderer.getNameSpace(jsxNode.type, elementNamespace), jsxNode.key);
|
|
2266
|
-
|
|
2265
|
+
if (nodeType === "function") return createChainByJSXNode(ComponentAtomType, jsxNode, jsxNode.type, prevAtom, elementNamespace, jsxNode.key);
|
|
2267
2266
|
}
|
|
2268
2267
|
const text = String(jsxNode);
|
|
2269
2268
|
return createChainByJSXNode(TextAtomType, text, text, prevAtom, elementNamespace);
|
|
@@ -2292,7 +2291,7 @@ function insertNode(nativeRenderer, atom, context) {
|
|
|
2292
2291
|
else nativeRenderer.insertAfter(atom.nativeNode, context.anchorNode, atom.namespace);
|
|
2293
2292
|
}
|
|
2294
2293
|
function createElementChildren(type, children, nativeRenderer, namespace) {
|
|
2295
|
-
return createChildChain(children, nativeRenderer, nativeRenderer.
|
|
2294
|
+
return createChildChain(children, nativeRenderer, nativeRenderer.getChildrenNameSpace(type, namespace));
|
|
2296
2295
|
}
|
|
2297
2296
|
function createElement(nativeRenderer, atom, parentComponent, context) {
|
|
2298
2297
|
const { namespace, jsxNode } = atom;
|
package/package.json
CHANGED