vasille-web 3.1.5 → 3.2.1

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 CHANGED
@@ -11,7 +11,7 @@
11
11
  * [Installation](#installation)
12
12
  * [How to use Vasille](#how-to-use-vasille)
13
13
  * [How SAFE is Vasille](#how-safe-is-vasille)
14
- * [How SIMPLE is Vasille](#how-simple-is-vasille)
14
+ * [How INTUITIVE is Vasille](#how-intuitive-is-vasille)
15
15
  * [How POWERFUL is Vasille](#how-powerful-is-vasille)
16
16
  * [Road Map](#road-map)
17
17
 
@@ -44,6 +44,7 @@ $ npx degit vasille-js/example-javascript my-project
44
44
 
45
45
  ### Full documentation:
46
46
  * [Learn `Vasille` in 5 minutes](https://github.com/vasille-js/vasille-js/blob/v3/doc/V3-API.md)
47
+ * [Vasille Router Documentation](https://github.com/vasille-js/vasille-js/blob/v3/doc/Router-API.md)
47
48
 
48
49
  ### Examples
49
50
  * [TypeScript Example](https://github.com/vasille-js/example-typescript)
@@ -60,7 +61,7 @@ The safe of your application is ensured by
60
61
  * `strong typing` makes your javascript/typescript code safe as C++ code.
61
62
  All entities of `vasille` core library are strongly typed, including:
62
63
  * data fields & properties.
63
- * computed properties (function parameters & result).
64
+ * computed properties (function parameters and result).
64
65
  * methods.
65
66
  * events (defined handlers & event emit).
66
67
  * DOM events & DOM operation (attributing, styling, etc.).
@@ -68,7 +69,7 @@ All entities of `vasille` core library are strongly typed, including:
68
69
  * references to children.
69
70
  * No asynchronous code, when the line of code is executed, the DOM and reactive things are already synced.
70
71
 
71
- ## How SIMPLE is Vasille
72
+ ## How INTUITIVE is Vasille
72
73
 
73
74
  There is the "Hello World":
74
75
  ```typescript jsx
@@ -105,7 +106,7 @@ All of these are supported:
105
106
  * [x] Develop the `Vasille Babel Plugin`.
106
107
  * [x] `100%` Test Coverage fot babel plugin.
107
108
  * [x] Add CSS support (define styles in components).
108
- * [ ] Add router.
109
+ * [x] Add router.
109
110
  * [ ] Add SSR (server side rendering).
110
111
  * [ ] Develop tools extension for debugging.
111
112
 
@@ -1,52 +1,197 @@
1
+ import { ArrayModel, SetModel, MapModel, IValue, App, Fragment } from "vasille";
2
+ import type { TagOptions } from "vasille/web-runner";
1
3
  import type { StyleProps } from "../spec/css.d.ts";
4
+ import type { ScreenProps } from "vasille-router";
5
+ import type { Router } from "vasille-router/web-router";
2
6
 
3
- export {
4
- ref,
5
- bind,
6
- calculate,
7
- forward,
8
- arrayModel,
9
- setModel,
10
- mapModel,
11
- reactiveObject,
12
- value,
13
- watch,
14
- } from "vasille-dx";
15
-
16
- export {
17
- compose,
18
- Debug,
19
- Delay,
20
- Else,
21
- ElseIf,
22
- For,
23
- If,
24
- Slot,
25
- Watch,
26
- awaited,
27
- store,
28
- } from "vasille-dx";
29
-
30
- export {
31
- theme,
32
- tablet,
33
- dark,
34
- mobile,
35
- laptop,
36
- prefersLight,
37
- prefersDark,
38
- setMobileMaxWidth,
39
- setTabletMaxWidth,
40
- setLaptopMaxWidth,
41
- } from "vasille-css";
42
-
43
- export declare const styleSheet: <T extends {
44
- [className: string]: {
45
- [media: `@${string}`]: {
7
+ declare interface Params {
8
+ slot?(...args: unknown[]): unknown;
9
+ }
10
+
11
+ declare type Composed<In extends Params, Out> = (
12
+ $: (In["slot"] extends (() => unknown) | undefined ? Omit<In, "slot"> & { slot?: unknown } : In) & {
13
+ callback?(data: Out | undefined): void;
14
+ },
15
+ slot?: In["slot"],
16
+ ) => void;
17
+ declare type ComposedNoCallback<In extends Params, Out> = (
18
+ $: In["slot"] extends (() => unknown) | undefined ? Omit<In, "slot"> & { slot?: unknown } : In,
19
+ slot?: In["slot"],
20
+ ) => void;
21
+
22
+ /**
23
+ * create an MVVM view, which can receive external reactive value as props
24
+ * @param renderer is the view constructor
25
+ */
26
+ export declare function compose<In extends object>(renderer: (input: In) => void): ComposedNoCallback<In, void>;
27
+ export declare function compose<In extends object, Out>(renderer: (input: In) => Out): Composed<In, Out>;
28
+
29
+ /**
30
+ * create an MVVM view, which can receive external reactive value as props
31
+ * @param renderer is the view constructor
32
+ */
33
+ export declare function view(renderer: () => void): ComposedNoCallback<NonNullable<unknown>, void>;
34
+ export declare function view<In extends object>(renderer: (input: In) => void): ComposedNoCallback<In, void>;
35
+ export declare function view<Out>(renderer: (input: NonNullable<unknown>) => Out): Composed<NonNullable<unknown>, Out>;
36
+ export declare function view<In extends object, Out>(renderer: (input: In) => Out): Composed<In, Out>;
37
+
38
+ /**
39
+ * create an MVVM view, which can receive external reactive value as props
40
+ * @param renderer is the view constructor
41
+ */
42
+ export declare function mvvmView(renderer: () => void): ComposedNoCallback<NonNullable<unknown>, void>;
43
+ export declare function mvvmView<In extends object>(renderer: (input: In) => void): ComposedNoCallback<In, void>;
44
+ export declare function mvvmView<Out>(
45
+ renderer: (input: NonNullable<unknown>) => Out,
46
+ ): Composed<NonNullable<unknown>, Out>;
47
+ export declare function mvvmView<In extends object, Out>(renderer: (input: In) => Out): Composed<In, Out>;
48
+
49
+ /**
50
+ * create an MVC view, which can receive models from the parent component
51
+ * @param renderer is the view constructor
52
+ */
53
+ export declare function mvcView<In extends object>(renderer: (input: In) => void): ComposedNoCallback<In, void>;
54
+ export declare function mvcView<In extends object, Out>(renderer: (input: In) => Out): Composed<In, Out>;
55
+
56
+ /**
57
+ * create a hybrid view, which can receive external models and reactive values
58
+ * @param renderer is the view constructor
59
+ */
60
+ export declare function hybridView<Models extends object, Props extends object>(
61
+ renderer: (models: Models, props: Props) => void,
62
+ ): ComposedNoCallback<Models & Props, void>;
63
+ export declare function hybridView<Models extends object, Props extends object, Out>(
64
+ renderer: (models: Models, props: Props) => Out,
65
+ ): Composed<Models & Props, Out>;
66
+
67
+ export declare function value<T>(v: T): T;
68
+ export declare function ref<T>(v: T): T;
69
+ export declare function bind<T>(v: T): T;
70
+ export declare function calculate<T>(fn: () => T): T;
71
+ export declare function arrayModel<T>(v?: T[]): T[] & { destroy(): void };
72
+ export declare function setModel<T>(v?: T[]): Set<T> & { destroy(): void };
73
+ export declare function mapModel<K, T>(v?: [K, T][]): Map<K, T> & { destroy(): void };
74
+ export declare function reactiveObject<T extends object>(o: T): T;
75
+
76
+ export declare function Slot(options: { model?: () => void; slot?: () => void }): void;
77
+ export declare function Slot<Props extends object>(
78
+ options: {
79
+ model?: (props: Props) => void;
80
+ slot?: () => void;
81
+ } & Props,
82
+ ): void;
83
+
84
+ export declare function If(props: { condition: unknown; slot?: unknown }): void;
85
+
86
+ export declare function ElseIf(props: { condition: unknown; slot?: unknown }): void;
87
+
88
+ export declare function Else(props: { slot?: unknown }): void;
89
+
90
+ export declare function For<T>(props: { of: T[]; slot?: (value: T) => void }): void;
91
+ export declare function For<T>(props: { of: Set<T>; slot?: (value: T) => void }): void;
92
+ export declare function For<K, T>(props: { of: Map<K, T>; slot?: (value: T, index: K) => void }): void;
93
+
94
+ export declare function Watch<T>(props: { model: T; slot?: (value: T) => void }): void;
95
+
96
+ export declare function Debug(props: { model: unknown }): void;
97
+
98
+ export declare function Delay(props: { time?: number; slot?: unknown }): void;
99
+
100
+ export declare function forward<T>(value: T): T;
101
+
102
+ export declare function calculate<T>(f: () => T): T;
103
+
104
+ export declare function watch(f: () => void): void;
105
+
106
+ export declare function awaited<T>(target: Promise<T>): [unknown, T | undefined];
107
+ export declare function awaited<T>(target: () => Promise<T>): [unknown, T | undefined, () => void];
108
+
109
+ export declare function store<Return extends object>(fn: () => Return): () => Return;
110
+ export declare function store<Input extends object, Return extends object>(
111
+ fn: (input: Input) => Return,
112
+ ): (input: Input) => Return;
113
+
114
+ export { $ } from "vasille-jsx";
115
+
116
+ export { QueryParams, ScreenProps, RouteParameters } from "vasille-router";
117
+ export { Router, NavigationMode } from "vasille-router/web-router";
118
+
119
+ export declare function theme<T>(name: string, value: T): T;
120
+ export declare function dark<T>($: T): T;
121
+ // rules with target
122
+ export declare function mobile<T>($: T): T;
123
+ export declare function tablet<T>($: T): T;
124
+ export declare function laptop<T>($: T): T;
125
+ export declare function prefersDark<T>($: T): T;
126
+ export declare function prefersLight<T>($: T): T;
127
+
128
+ export { setMobileMaxWidth, setTabletMaxWidth, setLaptopMaxWidth } from "vasille-css";
129
+
130
+ export declare const styleSheet: <
131
+ T extends {
132
+ [className: string]: {
133
+ [media: `@${string}`]: {
134
+ [state: `:${string}`]: StyleProps;
135
+ } & StyleProps;
46
136
  [state: `:${string}`]: StyleProps;
47
137
  } & StyleProps;
48
- [state: `:${string}`]: StyleProps;
49
- } & StyleProps;
50
- }>(input: T) => { [K in keyof T]: string; };
51
- export declare function mount<T>(element: Element, component: ($: T) => void, $: T, debugUi?: boolean): void;
138
+ },
139
+ >(
140
+ input: T,
141
+ ) => { [K in keyof T]: string };
142
+
143
+ export declare function mount<T>(
144
+ element: Element,
145
+ component: ($: T) => void,
146
+ $: T,
147
+ debugUi?: boolean,
148
+ ): App<Node, Element, TagOptions>;
149
+
150
+ type Screen<Route extends string> = (input: ScreenProps<Route>) => Promise<void>;
151
+
152
+ export declare function screen<Route extends string>(renderer: Screen<Route>): Screen<Route>;
153
+
154
+ interface RouterInitialization<Routes extends string> {
155
+ routes: {
156
+ [K in Routes]: {
157
+ screen: Screen<K>;
158
+ minAccessLevel?: number;
159
+ };
160
+ };
161
+ getAccessLevel?(): Promise<number>;
162
+ fallbackScreen?(arg: { cause: "not-found" | "no-access" }): void;
163
+ errorScreen?(data: { error: unknown }): void;
164
+ loadingScreen?(props: object): void;
165
+ loadingOverlay?(props: object): void;
166
+ }
167
+
168
+ export declare function routerApp<Routes extends string>(
169
+ init: RouterInitialization<Routes>,
170
+ element?: Element,
171
+ debugUi?: boolean,
172
+ ): App<Node, Element, TagOptions>;
173
+
174
+ export declare function runOnDestroy(fn: () => void): void;
175
+
176
+ declare const VasilleKey: unique symbol;
177
+
178
+ export interface BridgeValue<T> {
179
+ [VasilleKey]: T;
180
+ }
181
+
182
+ export declare const bridge: {
183
+ ref<T>(v: T): BridgeValue<T>;
184
+ bind<T>(v: T): BridgeValue<T>;
185
+ calculate<T>(fn: () => T): BridgeValue<T>;
186
+ watch(fn: () => void): void;
187
+ arrayModel<T>(arr?: T[]): ArrayModel<T>;
188
+ setModel<T>(data?: T[]): SetModel<T>;
189
+ mapModel<K, T>(data?: [K, T][]): MapModel<K, T>;
190
+ reactiveObject<T extends object>(obj: T): { [K in keyof T]: BridgeValue<T[K]> };
191
+ value<T>(of: BridgeValue<T>): T;
192
+ setValue<T>(of: BridgeValue<T>, value: T): T;
193
+ stored<T>(v: T | IValue<T> | BridgeValue<T>): T;
194
+ destroy(v: BridgeValue<unknown>): void;
195
+ };
52
196
 
197
+ export declare function router(): Router<string> | undefined;
package/lib/index.js CHANGED
@@ -1,8 +1,21 @@
1
1
  import { Runner } from "vasille/web-runner";
2
- import { mount as coreMount } from "vasille-dx";
2
+ import { mount as coreMount } from "vasille-jsx";
3
+ import { mvvmView as coreMvvmView } from "vasille-jsx";
3
4
  import { styleSheet as coreStyleSheet } from "vasille-css";
4
- export { compose, Debug, Delay, Else, ElseIf, For, If, Slot, Watch, awaited, store, } from "vasille-dx";
5
+ import { routeApp as coreRouteApp } from "vasille-router/web-router";
6
+ export { $, mvvmView as view, mvvmView, mvcView, hybridView, Debug, Delay, Else, ElseIf, For, If, Slot, Watch, awaited, store, } from "vasille-jsx";
7
+ export { screen } from "vasille-router";
8
+ export { Router, routeApp } from "vasille-router/web-router";
5
9
  export const styleSheet = coreStyleSheet;
10
+ export function compose(renderer, name) {
11
+ if (name) {
12
+ console.warn("Vasille: compose function is deprecated, please use view function instead.");
13
+ }
14
+ return coreMvvmView(renderer, name);
15
+ }
6
16
  export function mount(element, component, $, debugUi) {
7
- coreMount(element, component, new Runner(debugUi ?? false, window.document), $);
17
+ return coreMount(element, component, new Runner(debugUi ?? false, window.document), $);
18
+ }
19
+ export function routerApp(init, element, debugUi) {
20
+ return coreRouteApp(element ?? document.body, window, window.location, init, debugUi);
8
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vasille-web",
3
- "version": "3.1.5",
3
+ "version": "3.2.1",
4
4
  "description": "The first Developer eXperience Orientated web front-end framework.",
5
5
  "main": "index.js",
6
6
  "types": "./index.d.ts",
@@ -20,8 +20,9 @@
20
20
  },
21
21
  "scripts": {
22
22
  "prepack": "cp -f ../README.md ./README.md",
23
+ "prettier": "prettier src fake-types --write",
23
24
  "build": "tsc --build tsconfig.json",
24
- "check-types": "tsc --noEmit --lib es2020 --types web ./fake-types/index.d.ts",
25
+ "check-types": "tsc --noEmit --lib es2020 --types web --moduleResolution Node16 --module Node16 ./fake-types/index.d.ts",
25
26
  "update-types": "tsc --build tsconfig-types.json"
26
27
  },
27
28
  "type": "module",
@@ -43,13 +44,14 @@
43
44
  },
44
45
  "homepage": "https://github.com/vasille-js/vasille-js#readme",
45
46
  "dependencies": {
46
- "babel-plugin-vasille": "^0.99.2",
47
47
  "csstype": "^3.1.3",
48
- "vasille": "^3.1.0",
49
- "vasille-css": "^3.1.0",
50
- "vasille-dx": "^3.1.3"
48
+ "vasille": "^3.2.1",
49
+ "vasille-css": "^3.2.1",
50
+ "vasille-jsx": "^3.2.1",
51
+ "vasille-router": "^3.2.1"
51
52
  },
52
53
  "devDependencies": {
54
+ "prettier": "^3.6.2",
53
55
  "@types/web": "^0.0.256",
54
56
  "typescript": "^5.8.3"
55
57
  }