@rs-x/cli 2.0.0-next.2 → 2.0.0-next.21

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.
Files changed (66) hide show
  1. package/README.md +5 -0
  2. package/bin/rsx.cjs +2868 -595
  3. package/package.json +5 -1
  4. package/{rs-x-vscode-extension-2.0.0-next.2.vsix → rs-x-vscode-extension-2.0.0-next.21.vsix} +0 -0
  5. package/scripts/prepare-local-rsx-packages.sh +20 -0
  6. package/scripts/verify-rsx-cli-mutations.sh +296 -0
  7. package/scripts/verify-rsx-projects.sh +220 -0
  8. package/scripts/verify-rsx-setup.sh +190 -0
  9. package/templates/angular-demo/README.md +115 -0
  10. package/templates/angular-demo/src/app/app.component.css +97 -0
  11. package/templates/angular-demo/src/app/app.component.html +58 -0
  12. package/templates/angular-demo/src/app/app.component.ts +52 -0
  13. package/templates/angular-demo/src/app/virtual-table/row-data.ts +35 -0
  14. package/templates/angular-demo/src/app/virtual-table/row-model.ts +45 -0
  15. package/templates/angular-demo/src/app/virtual-table/virtual-table-data.service.ts +136 -0
  16. package/templates/angular-demo/src/app/virtual-table/virtual-table-model.ts +224 -0
  17. package/templates/angular-demo/src/app/virtual-table/virtual-table.component.css +174 -0
  18. package/templates/angular-demo/src/app/virtual-table/virtual-table.component.html +50 -0
  19. package/templates/angular-demo/src/app/virtual-table/virtual-table.component.ts +83 -0
  20. package/templates/angular-demo/src/index.html +11 -0
  21. package/templates/angular-demo/src/main.ts +16 -0
  22. package/templates/angular-demo/src/styles.css +261 -0
  23. package/templates/next-demo/README.md +26 -0
  24. package/templates/next-demo/app/globals.css +431 -0
  25. package/templates/next-demo/app/layout.tsx +22 -0
  26. package/templates/next-demo/app/page.tsx +5 -0
  27. package/templates/next-demo/components/demo-app.tsx +114 -0
  28. package/templates/next-demo/components/virtual-table-row.tsx +40 -0
  29. package/templates/next-demo/components/virtual-table-shell.tsx +86 -0
  30. package/templates/next-demo/hooks/use-virtual-table-controller.ts +26 -0
  31. package/templates/next-demo/hooks/use-virtual-table-viewport.ts +41 -0
  32. package/templates/next-demo/lib/row-data.ts +35 -0
  33. package/templates/next-demo/lib/row-model.ts +45 -0
  34. package/templates/next-demo/lib/rsx-bootstrap.ts +46 -0
  35. package/templates/next-demo/lib/virtual-table-controller.ts +259 -0
  36. package/templates/next-demo/lib/virtual-table-data.service.ts +132 -0
  37. package/templates/react-demo/README.md +113 -0
  38. package/templates/react-demo/index.html +12 -0
  39. package/templates/react-demo/src/app/app.tsx +87 -0
  40. package/templates/react-demo/src/app/hooks/use-virtual-table-controller.ts +24 -0
  41. package/templates/react-demo/src/app/hooks/use-virtual-table-viewport.ts +39 -0
  42. package/templates/react-demo/src/app/virtual-table/row-data.ts +35 -0
  43. package/templates/react-demo/src/app/virtual-table/row-model.ts +45 -0
  44. package/templates/react-demo/src/app/virtual-table/virtual-table-controller.ts +259 -0
  45. package/templates/react-demo/src/app/virtual-table/virtual-table-data.service.ts +132 -0
  46. package/templates/react-demo/src/app/virtual-table/virtual-table-row.tsx +38 -0
  47. package/templates/react-demo/src/app/virtual-table/virtual-table-shell.tsx +84 -0
  48. package/templates/react-demo/src/main.tsx +24 -0
  49. package/templates/react-demo/src/rsx-bootstrap.ts +48 -0
  50. package/templates/react-demo/src/styles.css +422 -0
  51. package/templates/react-demo/tsconfig.json +17 -0
  52. package/templates/react-demo/vite.config.ts +6 -0
  53. package/templates/vue-demo/README.md +27 -0
  54. package/templates/vue-demo/src/App.vue +89 -0
  55. package/templates/vue-demo/src/components/VirtualTableRow.vue +33 -0
  56. package/templates/vue-demo/src/components/VirtualTableShell.vue +71 -0
  57. package/templates/vue-demo/src/composables/use-virtual-table-controller.ts +33 -0
  58. package/templates/vue-demo/src/composables/use-virtual-table-viewport.ts +40 -0
  59. package/templates/vue-demo/src/env.d.ts +10 -0
  60. package/templates/vue-demo/src/lib/row-data.ts +35 -0
  61. package/templates/vue-demo/src/lib/row-model.ts +45 -0
  62. package/templates/vue-demo/src/lib/rsx-bootstrap.ts +46 -0
  63. package/templates/vue-demo/src/lib/virtual-table-controller.ts +259 -0
  64. package/templates/vue-demo/src/lib/virtual-table-data.service.ts +132 -0
  65. package/templates/vue-demo/src/main.ts +13 -0
  66. package/templates/vue-demo/src/style.css +440 -0
@@ -0,0 +1,132 @@
1
+ import {
2
+ createRowData,
3
+ type RowData,
4
+ type SortDirection,
5
+ type SortKey,
6
+ } from '@/lib/row-data';
7
+
8
+ export type VirtualTablePage = {
9
+ total: number;
10
+ items: RowData[];
11
+ };
12
+
13
+ const TOTAL_ROWS = 1_000_000;
14
+ const REQUEST_DELAY_MS = 120;
15
+ const CATEGORY_COUNT = 4;
16
+ const PRICE_BUCKET_COUNT = 1_000;
17
+ const QUANTITY_BUCKET_COUNT = 100;
18
+ const MAX_CACHED_PAGES = 24;
19
+
20
+ export class VirtualTableDataService {
21
+ private readonly pageCache = new Map<string, VirtualTablePage>();
22
+
23
+ public get totalRows(): number {
24
+ return TOTAL_ROWS;
25
+ }
26
+
27
+ public async fetchPage(
28
+ pageIndex: number,
29
+ pageSize: number,
30
+ sortKey: SortKey,
31
+ sortDirection: SortDirection,
32
+ ): Promise<VirtualTablePage> {
33
+ const cacheKey = `${sortKey}:${sortDirection}:${pageIndex}:${pageSize}`;
34
+ const cached = this.pageCache.get(cacheKey);
35
+ if (cached) {
36
+ return cached;
37
+ }
38
+
39
+ await this.delay(REQUEST_DELAY_MS + (pageIndex % 5) * 35);
40
+
41
+ const startIndex = pageIndex * pageSize;
42
+ const items: RowData[] = [];
43
+ const endIndex = Math.min(startIndex + pageSize, TOTAL_ROWS);
44
+
45
+ for (
46
+ let visualIndex = startIndex;
47
+ visualIndex < endIndex;
48
+ visualIndex += 1
49
+ ) {
50
+ const id = this.getIdAtVisualIndex(visualIndex, sortKey, sortDirection);
51
+ items.push(createRowData(id));
52
+ }
53
+
54
+ const page = { total: TOTAL_ROWS, items };
55
+ this.pageCache.set(cacheKey, page);
56
+ this.trimCache();
57
+ return page;
58
+ }
59
+
60
+ private getIdAtVisualIndex(
61
+ visualIndex: number,
62
+ sortKey: SortKey,
63
+ sortDirection: SortDirection,
64
+ ): number {
65
+ const normalizedIndex =
66
+ sortDirection === 'asc' ? visualIndex : TOTAL_ROWS - 1 - visualIndex;
67
+
68
+ if (sortKey === 'price') {
69
+ return this.getPriceSortedId(normalizedIndex);
70
+ }
71
+
72
+ if (sortKey === 'quantity') {
73
+ return this.getQuantitySortedId(normalizedIndex);
74
+ }
75
+
76
+ if (sortKey === 'category') {
77
+ return this.getCategorySortedId(normalizedIndex);
78
+ }
79
+
80
+ return normalizedIndex + 1;
81
+ }
82
+
83
+ private getPriceSortedId(visualIndex: number): number {
84
+ const groupSize = TOTAL_ROWS / PRICE_BUCKET_COUNT;
85
+ const priceBucket = Math.floor(visualIndex / groupSize);
86
+ const offsetInBucket = visualIndex % groupSize;
87
+
88
+ return priceBucket + offsetInBucket * PRICE_BUCKET_COUNT + 1;
89
+ }
90
+
91
+ private getQuantitySortedId(visualIndex: number): number {
92
+ const groupSize = TOTAL_ROWS / QUANTITY_BUCKET_COUNT;
93
+ const quantityBucket = Math.floor(visualIndex / groupSize);
94
+ const offsetInBucket = visualIndex % groupSize;
95
+ const quantityStride = PRICE_BUCKET_COUNT * QUANTITY_BUCKET_COUNT;
96
+ const quantityBlock = Math.floor(offsetInBucket / PRICE_BUCKET_COUNT);
97
+ const priceBucket = offsetInBucket % PRICE_BUCKET_COUNT;
98
+
99
+ return (
100
+ priceBucket +
101
+ quantityBucket * PRICE_BUCKET_COUNT +
102
+ quantityBlock * quantityStride +
103
+ 1
104
+ );
105
+ }
106
+
107
+ private getCategorySortedId(visualIndex: number): number {
108
+ const groupSize = TOTAL_ROWS / CATEGORY_COUNT;
109
+ const categoryBucket = Math.floor(visualIndex / groupSize);
110
+ const offsetInBucket = visualIndex % groupSize;
111
+
112
+ return categoryBucket + offsetInBucket * CATEGORY_COUNT + 1;
113
+ }
114
+
115
+ private delay(durationMs: number): Promise<void> {
116
+ return new Promise((resolve) => {
117
+ window.setTimeout(resolve, durationMs);
118
+ });
119
+ }
120
+
121
+ private trimCache(): void {
122
+ while (this.pageCache.size > MAX_CACHED_PAGES) {
123
+ const oldestKey = this.pageCache.keys().next().value as
124
+ | string
125
+ | undefined;
126
+ if (!oldestKey) {
127
+ return;
128
+ }
129
+ this.pageCache.delete(oldestKey);
130
+ }
131
+ }
132
+ }
@@ -0,0 +1,113 @@
1
+ # rsx-react-example
2
+
3
+ React demo app for RS-X.
4
+
5
+ **Website & docs:** [rsxjs.com](https://www.rsxjs.com/)
6
+
7
+ This example shows a million-row virtual table that:
8
+
9
+ - uses the `useRsxExpression` hook from `@rs-x/react`
10
+ - creates row expressions with `rsx(...)`
11
+ - keeps a fixed pool of row models and expressions
12
+ - loads pages on demand while scrolling
13
+ - keeps memory bounded by reusing the row pool and pruning old page data
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ cd rsx-react-example
19
+ npm install
20
+ ```
21
+
22
+ ## Start
23
+
24
+ ```bash
25
+ npm run dev
26
+ ```
27
+
28
+ `npm run dev` first runs the RS-X build step, then starts Vite.
29
+
30
+ ## Build
31
+
32
+ ```bash
33
+ npm run build
34
+ ```
35
+
36
+ This runs:
37
+
38
+ 1. `rsx build --project tsconfig.json --no-emit --prod`
39
+ 2. `vite build`
40
+
41
+ So the example gets:
42
+
43
+ - RS-X semantic checks
44
+ - generated AOT RS-X caches
45
+ - React production build output
46
+
47
+ ## Basic RS-X React setup
48
+
49
+ The example uses the normal React RS-X setup:
50
+
51
+ ### 1. Initialize RS-X before rendering React
52
+
53
+ In `src/rsx-bootstrap.ts`:
54
+
55
+ ```ts
56
+ import { InjectionContainer } from '@rs-x/core';
57
+ import { RsXExpressionParserModule } from '@rs-x/expression-parser';
58
+
59
+ export async function initRsx(): Promise<void> {
60
+ await InjectionContainer.load(RsXExpressionParserModule);
61
+ }
62
+ ```
63
+
64
+ ### 2. Create expressions with `rsx(...)`
65
+
66
+ In `src/app/virtual-table/row-model.ts`:
67
+
68
+ ```ts
69
+ idExpr: rsx<number>('id')(model),
70
+ nameExpr: rsx<string>('name')(model),
71
+ totalExpr: rsx<number>('price * quantity')(model),
72
+ ```
73
+
74
+ ### 3. Bind them with `useRsxExpression`
75
+
76
+ In `src/app/virtual-table/virtual-table-row.tsx`:
77
+
78
+ ```tsx
79
+ const total = useRsxExpression(row.totalExpr);
80
+ return <span>{total}</span>;
81
+ ```
82
+
83
+ ## Why this example is useful
84
+
85
+ The point of the demo is not just rendering a table. It shows how RS-X behaves in a realistic React scenario:
86
+
87
+ - large logical dataset: `1,000,000` rows
88
+ - small live expression pool: only the pooled row models stay active
89
+ - page loading is async to simulate real server requests
90
+ - old loaded pages are pruned so scrolling does not grow memory forever
91
+
92
+ ## About the React integration in this demo
93
+
94
+ This example uses `useRsxExpression` directly in row components so the RS-X behavior is easy to see.
95
+
96
+ That is a demo choice, not a restriction.
97
+
98
+ In a real React app, you can also bridge RS-X values into other React-friendly state shapes such as `useSyncExternalStore`, memoized selectors, or your preferred state container if that fits better.
99
+
100
+ ## Key files
101
+
102
+ - `src/main.tsx`
103
+ - `src/rsx-bootstrap.ts`
104
+ - `src/app/app.tsx`
105
+ - `src/app/virtual-table/virtual-table-shell.tsx`
106
+ - `src/app/virtual-table/virtual-table-row.tsx`
107
+ - `src/app/virtual-table/virtual-table-controller.ts`
108
+ - `src/app/virtual-table/virtual-table-data.service.ts`
109
+ - `src/app/virtual-table/row-model.ts`
110
+
111
+ ## Notes
112
+
113
+ - The virtual table uses a bounded pool and bounded page retention on purpose, so performance characteristics stay visible while memory stays under control.
@@ -0,0 +1,12 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>RS-X React Demo</title>
7
+ </head>
8
+ <body>
9
+ <div id="root"></div>
10
+ <script type="module" src="/src/main.tsx"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,87 @@
1
+ import { type FC, useEffect, useState } from 'react';
2
+
3
+ import { VirtualTableShell } from './virtual-table/virtual-table-shell';
4
+
5
+ type ThemeMode = 'light' | 'dark';
6
+
7
+ function getInitialTheme(): ThemeMode {
8
+ const storedTheme = window.localStorage.getItem('rsx-theme');
9
+ if (storedTheme === 'light' || storedTheme === 'dark') {
10
+ return storedTheme;
11
+ }
12
+
13
+ return 'dark';
14
+ }
15
+
16
+ export const App: FC = () => {
17
+ const [theme, setTheme] = useState<ThemeMode>(() => getInitialTheme());
18
+
19
+ useEffect(() => {
20
+ document.documentElement.setAttribute('data-theme', theme);
21
+ document.body.setAttribute('data-theme', theme);
22
+ window.localStorage.setItem('rsx-theme', theme);
23
+ }, [theme]);
24
+
25
+ return (
26
+ <main className="app-shell">
27
+ <section className="hero">
28
+ <div className="container">
29
+ <div className="heroGrid">
30
+ <div className="heroLeft">
31
+ <p className="app-eyebrow">RS-X React Demo</p>
32
+ <h1 className="hTitle">Virtual Table</h1>
33
+ <p className="hSubhead">
34
+ Million-row scrolling with a fixed RS-X expression pool.
35
+ </p>
36
+ <p className="hSub">
37
+ This demo keeps rendering bounded while streaming pages on
38
+ demand, so scrolling stays smooth without growing expression
39
+ memory with the dataset.
40
+ </p>
41
+
42
+ <div className="heroActions">
43
+ <a
44
+ className="btn btnGhost"
45
+ href="https://www.rsxjs.com/"
46
+ target="_blank"
47
+ rel="noreferrer"
48
+ >
49
+ rs-x
50
+ </a>
51
+ <button
52
+ type="button"
53
+ className="btn btnGhost theme-toggle"
54
+ aria-label={`Switch to ${theme === 'dark' ? 'light' : 'dark'} mode`}
55
+ onClick={() => {
56
+ setTheme((currentTheme) =>
57
+ currentTheme === 'dark' ? 'light' : 'dark',
58
+ );
59
+ }}
60
+ >
61
+ {theme === 'dark' ? 'Light mode' : 'Dark mode'}
62
+ </button>
63
+ </div>
64
+ </div>
65
+
66
+ <aside className="card heroNote">
67
+ <h2 className="cardTitle">What This Shows</h2>
68
+ <p className="cardText">
69
+ Only a small row-model pool stays alive while pages stream in
70
+ around the viewport. That means one million logical rows without
71
+ one million live bindings.
72
+ </p>
73
+ </aside>
74
+ </div>
75
+ </div>
76
+ </section>
77
+
78
+ <section className="section">
79
+ <div className="container">
80
+ <section className="app-panel card">
81
+ <VirtualTableShell />
82
+ </section>
83
+ </div>
84
+ </section>
85
+ </main>
86
+ );
87
+ };
@@ -0,0 +1,24 @@
1
+ import { useRef, useSyncExternalStore } from 'react';
2
+
3
+ import {
4
+ VirtualTableController,
5
+ type VirtualTableSnapshot,
6
+ } from '../virtual-table/virtual-table-controller';
7
+
8
+ export function useVirtualTableController(): {
9
+ controller: VirtualTableController;
10
+ snapshot: VirtualTableSnapshot;
11
+ } {
12
+ const controllerRef = useRef<VirtualTableController | null>(null);
13
+ if (!controllerRef.current) {
14
+ controllerRef.current = new VirtualTableController();
15
+ }
16
+ const controller = controllerRef.current;
17
+ const snapshot = useSyncExternalStore(
18
+ controller.subscribe,
19
+ controller.getSnapshot,
20
+ controller.getSnapshot,
21
+ );
22
+
23
+ return { controller, snapshot };
24
+ }
@@ -0,0 +1,39 @@
1
+ import { type RefObject, useEffect, useRef } from 'react';
2
+
3
+ import type { VirtualTableController } from '../virtual-table/virtual-table-controller';
4
+
5
+ const COMPACT_BREAKPOINT_PX = 720;
6
+ const DEFAULT_ROW_HEIGHT = 36;
7
+ const COMPACT_ROW_HEIGHT = 168;
8
+
9
+ export function useVirtualTableViewport(
10
+ controller: VirtualTableController,
11
+ ): RefObject<HTMLDivElement | null> {
12
+ const viewportRef = useRef<HTMLDivElement | null>(null);
13
+
14
+ useEffect(() => {
15
+ const viewport = viewportRef.current;
16
+ if (!viewport) {
17
+ return;
18
+ }
19
+
20
+ const syncMetrics = (): void => {
21
+ controller.setViewportHeight(viewport.clientHeight);
22
+ controller.setRowHeight(
23
+ viewport.clientWidth <= COMPACT_BREAKPOINT_PX
24
+ ? COMPACT_ROW_HEIGHT
25
+ : DEFAULT_ROW_HEIGHT,
26
+ );
27
+ };
28
+
29
+ syncMetrics();
30
+ const observer = new ResizeObserver(syncMetrics);
31
+ observer.observe(viewport);
32
+
33
+ return () => {
34
+ observer.disconnect();
35
+ };
36
+ }, [controller]);
37
+
38
+ return viewportRef;
39
+ }
@@ -0,0 +1,35 @@
1
+ export type SortKey = 'id' | 'name' | 'price' | 'quantity' | 'category';
2
+ export type SortDirection = 'asc' | 'desc';
3
+
4
+ export type RowData = {
5
+ id: number;
6
+ name: string;
7
+ price: number;
8
+ quantity: number;
9
+ category: string;
10
+ updatedAt: string;
11
+ };
12
+
13
+ const categories = ['Hardware', 'Software', 'Design', 'Ops'];
14
+
15
+ function pad(value: number): string {
16
+ return value.toString().padStart(2, '0');
17
+ }
18
+
19
+ export function createRowData(id: number): RowData {
20
+ const zeroBasedId = id - 1;
21
+ const price = 25 + (zeroBasedId % 1000) / 10;
22
+ const quantity = 1 + (Math.floor(zeroBasedId / 1000) % 100);
23
+ const category = categories[zeroBasedId % categories.length] ?? 'General';
24
+ const month = pad(((zeroBasedId * 7) % 12) + 1);
25
+ const day = pad(((zeroBasedId * 11) % 28) + 1);
26
+
27
+ return {
28
+ id,
29
+ name: `Product ${id.toString().padStart(7, '0')}`,
30
+ price,
31
+ quantity,
32
+ category,
33
+ updatedAt: `2026-${month}-${day}`,
34
+ };
35
+ }
@@ -0,0 +1,45 @@
1
+ import { type IExpression, rsx } from '@rs-x/expression-parser';
2
+
3
+ import type { RowData } from './row-data';
4
+
5
+ export type RowModel = {
6
+ model: RowData;
7
+ idExpr: IExpression<number>;
8
+ nameExpr: IExpression<string>;
9
+ categoryExpr: IExpression<string>;
10
+ priceExpr: IExpression<number>;
11
+ quantityExpr: IExpression<number>;
12
+ updatedAtExpr: IExpression<string>;
13
+ totalExpr: IExpression<number>;
14
+ };
15
+
16
+ export function createRowModel(): RowModel {
17
+ const model: RowData = {
18
+ id: 0,
19
+ name: '',
20
+ price: 0,
21
+ quantity: 0,
22
+ category: 'General',
23
+ updatedAt: '2026-01-01',
24
+ };
25
+
26
+ return {
27
+ model,
28
+ idExpr: rsx<number>('id')(model),
29
+ nameExpr: rsx<string>('name')(model),
30
+ categoryExpr: rsx<string>('category')(model),
31
+ priceExpr: rsx<number>('price')(model),
32
+ quantityExpr: rsx<number>('quantity')(model),
33
+ updatedAtExpr: rsx<string>('updatedAt')(model),
34
+ totalExpr: rsx<number>('price * quantity')(model),
35
+ };
36
+ }
37
+
38
+ export function updateRowModel(target: RowModel, data: RowData): void {
39
+ target.model.id = data.id;
40
+ target.model.name = data.name;
41
+ target.model.price = data.price;
42
+ target.model.quantity = data.quantity;
43
+ target.model.category = data.category;
44
+ target.model.updatedAt = data.updatedAt;
45
+ }