vasille-context 5.0.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.
package/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # Steel Frame
2
+
3
+ ![Vasille.js logo](https://raw.githubusercontent.com/vasille-js/vasille-js/refs/heads/v5/doc/img/logo.png)
4
+
5
+ `SteelFrameKit` is a front-end development kit, which is developed to provide bulletproof frontends.
6
+
7
+ [![npm](https://img.shields.io/npm/v/vasille?style=flat-square)](https://www.npmjs.com/package/vasille)
8
+
9
+ ## Table of content
10
+
11
+ - [Steel Frame](#steel-frame)
12
+ - [Table of content](#table-of-content)
13
+ - [Installation](#installation)
14
+ - [How to use SteelFramekit](#how-to-use-steelframekit)
15
+ - [Full documentation:](#full-documentation)
16
+ - [Examples](#examples)
17
+ - [How SAFE is SteelFrameKit](#how-safe-is-steelframekit)
18
+ - [How INTUITIVE is SteelFrameKit](#how-intuitive-is-steelframekit)
19
+ - [How POWERFUL is SteelFrameKit](#how-powerful-is-steelframekit)
20
+ - [Road map](#road-map)
21
+ - [Change log](#change-log)
22
+ - [5.0.0](#500)
23
+ - [4.3.0](#430)
24
+ - [4.2.0](#420)
25
+ - [4.1.0](#410)
26
+ - [4.0.0](#400)
27
+ - [Questions](#questions)
28
+
29
+
30
+ <hr>
31
+
32
+ ## Installation
33
+
34
+ ```
35
+ npm install steel-frame --save
36
+ ```
37
+
38
+ ## How to use SteelFramekit
39
+
40
+ Create an app from a template
41
+
42
+ ```bash
43
+ $ npm create steel-frame
44
+ ```
45
+
46
+ ### Full documentation:
47
+ * [Learn `SteelFrameKit` in 5 minutes](https://github.com/vasille-js/vasille-js/blob/v4/doc/V4-API.md)
48
+ * [Router Documentation](https://github.com/vasille-js/vasille-js/blob/v4/doc/Router-API.md)
49
+ * [Compostion functions](https://github.com/vasille-js/vasille-js/blob/v4/doc/Compositions.md)
50
+ * [Dependency injection](https://github.com/vasille-js/vasille-js/blob/v4/doc/Context.md)
51
+
52
+ ### Examples
53
+ * [TypeScript Example](https://github.com/vasille-js/example-typescript)
54
+ * [JavaScript Example](https://github.com/vasille-js/example-javascript)
55
+
56
+ <hr>
57
+
58
+ ## How SAFE is SteelFrameKit
59
+
60
+ The safe of your application is ensured by
61
+ * `100%` coverage of code by unit tests.
62
+ Each function, each branch is working as designed.
63
+ * OOP, DRY, KISS and SOLID principles are applied.
64
+ * `strong typing` makes your javascript/typescript code safe as C++ code.
65
+ All entities of `SteelFrameKit` core library are strongly typed, including:
66
+ * data fields & properties.
67
+ * computed properties (function parameters and result).
68
+ * methods.
69
+ * events (defined handlers & event emit).
70
+ * DOM events & DOM operation (attributing, styling, etc.).
71
+ * slots of components.
72
+ * references to children.
73
+ * No asynchronous code, when the line of code is executed, the DOM and reactive things are already synced.
74
+
75
+ ## How INTUITIVE is SteelFrameKit
76
+
77
+ There is the "Hello World":
78
+ ```typescript jsx
79
+ import { compose, mount } from "steel-frame";
80
+
81
+ const App = compose(() => {
82
+ <p>Hello world</p>;
83
+ });
84
+
85
+ mount(document.body, App, {});
86
+ ```
87
+
88
+ ## How POWERFUL is SteelFrameKit
89
+
90
+ All of these are supported:
91
+ * Components.
92
+ * Reactive values (observables).
93
+ * Inline computed values.
94
+ * Multiline computed values.
95
+ * HTML & SVG tags.
96
+ * Component custom slots.
97
+ * 2-way data binding in components.
98
+ * Logic block (if, else).
99
+ * Loops (array, map, set).
100
+ * Dependency injection.
101
+
102
+ <hr>
103
+
104
+ ## Road map
105
+
106
+ * [x] Update the `core` library to version 3.0.
107
+ * [x] `100%` Test Coverage for core Library v3.
108
+ * [x] Develop the `JSX` library.
109
+ * [x] `100%` Test Coverage for the JSX library.
110
+ * [x] Develop the `Babel Plugin`.
111
+ * [x] `100%` Test Coverage fot babel plugin.
112
+ * [x] Add CSS support (define styles in components).
113
+ * [x] Add router.
114
+ * [x] Add SSG (static site generation).
115
+ * [ ] Develop tools extension for debugging (WIP).
116
+ * [ ] Add SSR (server side rendering).
117
+
118
+ ## Change log
119
+
120
+ ### 5.0.0
121
+
122
+ Add support for context and dependencies injection.
123
+
124
+ ### 4.3.0
125
+
126
+ Add new function `safe` which make functions safe, errors are reported automatically.
127
+
128
+ ### 4.2.0
129
+
130
+ Add support for inlined conditions in JSX, binary `&&` and ternary `?:` operator.
131
+
132
+ ### 4.1.0
133
+
134
+ Added SSG (static site generation) as build option `sf build static`.
135
+
136
+ ### 4.0.0
137
+
138
+ Initial version of the framework with file based routing and building scripts (`sf dev` and `sf build spa`).
139
+
140
+ ## Questions
141
+
142
+ If you have questions, feel free to contact the maintainer of the project:
143
+
144
+ * [Author's Email](mailto:vas.lixcode@gmail.com)
package/lib/index.js ADDED
@@ -0,0 +1,52 @@
1
+ import { Fragment } from "vasille";
2
+ const searchMap = new Map();
3
+ function lookUp(node, key) {
4
+ let it = node;
5
+ while (it) {
6
+ const value = searchMap.get(it)?.get(key);
7
+ if (value !== undefined) {
8
+ return value;
9
+ }
10
+ it = it instanceof Fragment ? it.parent : null;
11
+ }
12
+ }
13
+ function setUp(node, key, value) {
14
+ let map = searchMap.get(node);
15
+ if (!map) {
16
+ const created = (map = new Map());
17
+ searchMap.set(node, created);
18
+ node.runOnDestroy(() => created.delete(node));
19
+ }
20
+ map.set(key, value);
21
+ return value;
22
+ }
23
+ export class SteelContext {
24
+ fn;
25
+ constructor(fn) {
26
+ this.fn = fn;
27
+ }
28
+ }
29
+ export function context(fn) {
30
+ return new SteelContext(fn);
31
+ }
32
+ export function share(node, target, ...args) {
33
+ if (target instanceof SteelContext) {
34
+ return setUp(node, target, target.fn(...args));
35
+ }
36
+ return setUp(node, target, args[0]);
37
+ }
38
+ export function receive(node, key) {
39
+ const value = lookUp(node, key);
40
+ if (value === undefined) {
41
+ throw new Error(`Missing value for key "${key}"`);
42
+ }
43
+ return value;
44
+ }
45
+ export function impute(node, target, ...args) {
46
+ if (target instanceof SteelContext || typeof target === "string") {
47
+ // @ts-expect-error
48
+ return lookUp(node, target) ?? share(node, target, ...args);
49
+ }
50
+ // @ts-expect-error
51
+ return lookUp(node, target) ?? share(node, target, args[0]());
52
+ }
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "vasille-context",
3
+ "version": "5.0.0",
4
+ "description": "Provide contextual data between Vasille.JS components",
5
+ "keywords": [
6
+ "frontend",
7
+ "framework",
8
+ "safe",
9
+ "fast",
10
+ "simple"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "lixcode",
14
+ "type": "module",
15
+ "main": "lib/index.js",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./types/index.d.ts",
19
+ "import": "./lib/index.js",
20
+ "browser": "./lib/index.js"
21
+ }
22
+ },
23
+ "scripts": {
24
+ "prepack": "cp -f ../README.md ./README.md",
25
+ "prettier": "npx prettier src test --write",
26
+ "prebuild": "rm -rf types lib",
27
+ "build": "tsc --build tsconfig.json",
28
+ "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
29
+ "test-coverage": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/vasille-js/steel-frame.git"
34
+ },
35
+ "devDependencies": {
36
+ "@types/jest": "^30.0.0",
37
+ "cross-env": "^10.1.0",
38
+ "jest": "^30.2.0",
39
+ "prettier": "^3.8.1",
40
+ "ts-jest": "^29.4.6",
41
+ "typescript": "^5.9.3"
42
+ },
43
+ "dependencies": {
44
+ "vasille": "^5.0.0"
45
+ }
46
+ }
@@ -0,0 +1,15 @@
1
+ import { Reactive } from "vasille";
2
+ export declare class SteelContext<Args extends unknown[], Value> {
3
+ readonly fn: (...args: Args) => Value;
4
+ constructor(fn: (...args: Args) => Value);
5
+ }
6
+ export declare function context<Value, Args extends unknown[] = never[]>(fn: (...args: Args) => Value): SteelContext<Args, Value>;
7
+ export declare function share<Args extends unknown[], Value>(node: Reactive, ctx: SteelContext<Args, Value>, ...args: Args): Value;
8
+ export declare function share<Class>(node: Reactive, className: abstract new (...args: unknown[]) => Class, value: Class): Class;
9
+ export declare function share(node: Reactive, key: string, value: string): string;
10
+ export declare function receive<Args extends unknown[], Value>(node: Reactive, ctx: SteelContext<Args, Value>): Value;
11
+ export declare function receive<Class>(node: Reactive, className: abstract new (...args: unknown[]) => Class): Class;
12
+ export declare function receive(node: Reactive, key: string): string;
13
+ export declare function impute<Args extends unknown[], Value>(node: Reactive, ctx: SteelContext<Args, Value>, ...args: Args): Value;
14
+ export declare function impute<Class>(node: Reactive, className: abstract new (...args: unknown[]) => Class, value: () => Class): Class;
15
+ export declare function impute(node: Reactive, key: string, value: string): string;