x4js 2.2.73 → 2.3.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/bin/x4js.mjs +3 -0
- package/cli/build-options.mjs +68 -0
- package/cli/build.mjs +33 -0
- package/cli/config.mjs +166 -0
- package/cli/copy-plugin.mjs +115 -0
- package/cli/create.mjs +141 -0
- package/cli/dev-client.js +41 -0
- package/cli/dev.mjs +188 -0
- package/cli/less-plugin.mjs +47 -0
- package/cli/log.mjs +41 -0
- package/cli/main.mjs +74 -0
- package/cli/templates-source.mjs +61 -0
- package/cli/templates.mjs +13 -0
- package/package.json +10 -1
- package/readme.npm.md +248 -0
- package/src/components/boxes/boxes.ts +3 -3
- package/src/components/canvas/canvas.ts +43 -47
- package/src/components/form/form.ts +1 -1
- package/src/components/gridview/gridview.ts +4 -5
- package/src/components/propgrid/propgrid.ts +7 -1
- package/src/components/tickline/tickline.ts +3 -2
- package/src/components/treeview/treeview.ts +2 -2
- package/src/core/core_data.ts +1 -1
- package/src/core/core_element.ts +1 -0
package/cli/dev.mjs
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import esbuild from "esbuild";
|
|
6
|
+
import { loadConfig, resolveTls } from "./config.mjs";
|
|
7
|
+
import { createBuildOptions } from "./build-options.mjs";
|
|
8
|
+
import { info, success, failure } from "./log.mjs";
|
|
9
|
+
|
|
10
|
+
function openBrowser(url) {
|
|
11
|
+
let command;
|
|
12
|
+
let args;
|
|
13
|
+
|
|
14
|
+
if (process.platform === "win32") {
|
|
15
|
+
command = "cmd";
|
|
16
|
+
args = ["/c", "start", "", url];
|
|
17
|
+
}
|
|
18
|
+
else if (process.platform === "darwin") {
|
|
19
|
+
command = "open";
|
|
20
|
+
args = [url];
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
command = "xdg-open";
|
|
24
|
+
args = [url];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const child = spawn(command, args, {
|
|
28
|
+
detached: true,
|
|
29
|
+
stdio: "ignore",
|
|
30
|
+
});
|
|
31
|
+
child.unref();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function protocolConfig(config, values) {
|
|
35
|
+
if (values.http && values.https)
|
|
36
|
+
throw new Error("--http and --https are mutually exclusive");
|
|
37
|
+
|
|
38
|
+
let https = config.dev.https;
|
|
39
|
+
if (values.http)
|
|
40
|
+
https = false;
|
|
41
|
+
if (values.https)
|
|
42
|
+
https = true;
|
|
43
|
+
|
|
44
|
+
return https;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function serverUrl(host, port, https) {
|
|
48
|
+
let displayHost = host;
|
|
49
|
+
if (host === "0.0.0.0")
|
|
50
|
+
displayHost = "127.0.0.1";
|
|
51
|
+
else if (host === "::")
|
|
52
|
+
displayHost = "[::1]";
|
|
53
|
+
else if (host.includes(":") && !host.startsWith("["))
|
|
54
|
+
displayHost = `[${host}]`;
|
|
55
|
+
return `${https ? "https" : "http"}://${displayHost}:${port}/`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function dev(argv = [], root = process.cwd()) {
|
|
59
|
+
const { values, positionals } = parseArgs({
|
|
60
|
+
args: argv,
|
|
61
|
+
options: {
|
|
62
|
+
host: { type: "string" },
|
|
63
|
+
port: { type: "string" },
|
|
64
|
+
http: { type: "boolean", default: false },
|
|
65
|
+
https: { type: "boolean", default: false },
|
|
66
|
+
open: { type: "boolean", default: false },
|
|
67
|
+
},
|
|
68
|
+
allowPositionals: true,
|
|
69
|
+
strict: true,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (positionals.length)
|
|
73
|
+
throw new Error(`Unexpected argument: ${positionals[0]}`);
|
|
74
|
+
|
|
75
|
+
if (values.port !== undefined && !/^\d+$/.test(values.port))
|
|
76
|
+
throw new Error("--port must be an integer");
|
|
77
|
+
|
|
78
|
+
let context;
|
|
79
|
+
let packageWatcher;
|
|
80
|
+
let stopping = false;
|
|
81
|
+
let restartTimer;
|
|
82
|
+
let restartChain = Promise.resolve();
|
|
83
|
+
let browserOpened = false;
|
|
84
|
+
|
|
85
|
+
async function start(config) {
|
|
86
|
+
const host = values.host ?? config.dev.host;
|
|
87
|
+
const port = values.port === undefined ? config.dev.port : Number(values.port);
|
|
88
|
+
if (port < 0 || port > 65535)
|
|
89
|
+
throw new Error("--port must be between 0 and 65535");
|
|
90
|
+
|
|
91
|
+
const useHttps = protocolConfig(config, values);
|
|
92
|
+
const serveOptions = {
|
|
93
|
+
host,
|
|
94
|
+
port,
|
|
95
|
+
servedir: config.outdir,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
if (useHttps)
|
|
99
|
+
Object.assign(serveOptions, resolveTls(config));
|
|
100
|
+
|
|
101
|
+
const next = await esbuild.context(createBuildOptions(config, "dev"));
|
|
102
|
+
try {
|
|
103
|
+
await next.watch();
|
|
104
|
+
const result = await next.serve(serveOptions);
|
|
105
|
+
context = next;
|
|
106
|
+
|
|
107
|
+
const actualHost = result.hosts.includes(host) ? host : (result.hosts[0] ?? host);
|
|
108
|
+
const url = serverUrl(actualHost, result.port, useHttps);
|
|
109
|
+
info("mode", "dev");
|
|
110
|
+
info("outdir", config.outdir);
|
|
111
|
+
success("listening", url);
|
|
112
|
+
|
|
113
|
+
if (values.open && !browserOpened) {
|
|
114
|
+
browserOpened = true;
|
|
115
|
+
openBrowser(url);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
await next.dispose();
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async function reload() {
|
|
125
|
+
let config;
|
|
126
|
+
try {
|
|
127
|
+
config = loadConfig(root);
|
|
128
|
+
protocolConfig(config, values);
|
|
129
|
+
if ((values.https || (!values.http && config.dev.https)))
|
|
130
|
+
resolveTls(config);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
failure(`config: ${error.message}`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const previous = context;
|
|
138
|
+
context = undefined;
|
|
139
|
+
if (previous)
|
|
140
|
+
await previous.dispose();
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
await start(config);
|
|
144
|
+
success("config", "reloaded");
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
failure(`restart: ${error.message}`);
|
|
148
|
+
// The old context cannot be restored after dispose. Keep watching
|
|
149
|
+
// package.json so fixing the configuration starts dev again.
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function scheduleReload() {
|
|
154
|
+
clearTimeout(restartTimer);
|
|
155
|
+
restartTimer = setTimeout(() => {
|
|
156
|
+
restartChain = restartChain.then(reload, reload);
|
|
157
|
+
}, 150);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const initialConfig = loadConfig(root);
|
|
161
|
+
await start(initialConfig);
|
|
162
|
+
|
|
163
|
+
packageWatcher = fs.watch(path.resolve(root), { persistent: true }, (_event, filename) => {
|
|
164
|
+
if (filename === null || filename.toString() === "package.json")
|
|
165
|
+
scheduleReload();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
async function stop() {
|
|
169
|
+
if (stopping)
|
|
170
|
+
return;
|
|
171
|
+
stopping = true;
|
|
172
|
+
clearTimeout(restartTimer);
|
|
173
|
+
packageWatcher?.close();
|
|
174
|
+
await restartChain.catch(() => {});
|
|
175
|
+
await context?.dispose();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
process.once("SIGINT", async () => {
|
|
179
|
+
await stop();
|
|
180
|
+
process.exit(0);
|
|
181
|
+
});
|
|
182
|
+
process.once("SIGTERM", async () => {
|
|
183
|
+
await stop();
|
|
184
|
+
process.exit(0);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
return { stop };
|
|
188
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
|
|
6
|
+
async function loadLess(projectRoot) {
|
|
7
|
+
const require = createRequire(path.join(projectRoot, "package.json"));
|
|
8
|
+
let resolved;
|
|
9
|
+
try {
|
|
10
|
+
resolved = require.resolve("less");
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
throw new Error(
|
|
14
|
+
'LESS support requires the "less" package.\n' +
|
|
15
|
+
'Install it with: npm install -D less',
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const module = await import(pathToFileURL(resolved).href);
|
|
20
|
+
return module.default ?? module;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function lessPlugin(projectRoot) {
|
|
24
|
+
let lessPromise;
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
name: "x4-less",
|
|
28
|
+
setup(build) {
|
|
29
|
+
build.onLoad({ filter: /\.less$/ }, async (args) => {
|
|
30
|
+
const source = await fs.readFile(args.path, "utf8");
|
|
31
|
+
lessPromise ??= loadLess(projectRoot);
|
|
32
|
+
const less = await lessPromise;
|
|
33
|
+
|
|
34
|
+
const result = await less.render(source, {
|
|
35
|
+
filename: args.path,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
contents: result.css,
|
|
40
|
+
loader: "css",
|
|
41
|
+
resolveDir: path.dirname(args.path),
|
|
42
|
+
watchFiles: [args.path, ...(result.imports ?? [])],
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
package/cli/log.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
|
|
3
|
+
function useColor(stream = process.stdout) {
|
|
4
|
+
if (process.env.NO_COLOR !== undefined)
|
|
5
|
+
return false;
|
|
6
|
+
if (process.env.FORCE_COLOR !== undefined)
|
|
7
|
+
return process.env.FORCE_COLOR !== "0";
|
|
8
|
+
return !!stream.isTTY;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function paint(style, value, stream = process.stdout) {
|
|
12
|
+
const text = String(value);
|
|
13
|
+
return useColor(stream) ? styleText(style, text) : text;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const color = {
|
|
17
|
+
cyan: (value) => paint("cyan", value),
|
|
18
|
+
green: (value) => paint("green", value),
|
|
19
|
+
yellow: (value) => paint("yellow", value),
|
|
20
|
+
red: (value) => paint("red", value, process.stderr),
|
|
21
|
+
gray: (value) => paint("gray", value),
|
|
22
|
+
white: (value) => paint("white", value),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function info(label, value = "") {
|
|
26
|
+
const left = color.cyan(String(label).padEnd(11));
|
|
27
|
+
console.log(value === "" ? left.trimEnd() : `${left}${value}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function success(label, value = "") {
|
|
31
|
+
const left = color.green(String(label).padEnd(11));
|
|
32
|
+
console.log(value === "" ? left.trimEnd() : `${left}${value}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function warning(message) {
|
|
36
|
+
console.warn(color.yellow(message));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function failure(message) {
|
|
40
|
+
console.error(color.red(message));
|
|
41
|
+
}
|
package/cli/main.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { failure } from "./log.mjs";
|
|
5
|
+
|
|
6
|
+
const cliDir = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const packageFile = path.join(cliDir, "..", "package.json");
|
|
8
|
+
|
|
9
|
+
function getVersion() {
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(fs.readFileSync(packageFile, "utf8")).version ?? "unknown";
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return "unknown";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function printHelp(version) {
|
|
19
|
+
console.log(`x4js ${version}
|
|
20
|
+
|
|
21
|
+
Usage:
|
|
22
|
+
x4js create <project> [--template <name>] [--no-install]
|
|
23
|
+
x4js templates
|
|
24
|
+
x4js dev [--host <host>] [--port <port>] [--http|--https] [--open]
|
|
25
|
+
x4js build [--debug]
|
|
26
|
+
|
|
27
|
+
Options:
|
|
28
|
+
-h, --help Show help
|
|
29
|
+
-v, --version Show version`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const version = getVersion();
|
|
33
|
+
const [command, ...argv] = process.argv.slice(2);
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
switch (command) {
|
|
37
|
+
case "create": {
|
|
38
|
+
const { create } = await import("./create.mjs");
|
|
39
|
+
await create(argv, { version });
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case "templates": {
|
|
43
|
+
const { templates } = await import("./templates.mjs");
|
|
44
|
+
await templates(argv, { version });
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "dev": {
|
|
48
|
+
const { dev } = await import("./dev.mjs");
|
|
49
|
+
await dev(argv);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case "build": {
|
|
53
|
+
const { build } = await import("./build.mjs");
|
|
54
|
+
await build(argv);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
case undefined:
|
|
58
|
+
case "help":
|
|
59
|
+
case "--help":
|
|
60
|
+
case "-h":
|
|
61
|
+
printHelp(version);
|
|
62
|
+
break;
|
|
63
|
+
case "--version":
|
|
64
|
+
case "-v":
|
|
65
|
+
console.log(version);
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
throw new Error(`Unknown command '${command}'. Run 'x4js --help'.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
failure(error instanceof Error ? error.message : String(error));
|
|
73
|
+
process.exitCode = 1;
|
|
74
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const OWNER = "rlibre";
|
|
2
|
+
const REPO = "x4-templates";
|
|
3
|
+
const REF = "main";
|
|
4
|
+
|
|
5
|
+
function headers(version = "unknown") {
|
|
6
|
+
return {
|
|
7
|
+
"Accept": "application/vnd.github+json",
|
|
8
|
+
"User-Agent": `x4js/${version}`,
|
|
9
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function checkedFetch(url, options) {
|
|
14
|
+
const response = await fetch(url, options);
|
|
15
|
+
if (!response.ok)
|
|
16
|
+
throw new Error(`Template repository request failed (${response.status} ${response.statusText})`);
|
|
17
|
+
return response;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function fetchTemplates(version = "unknown") {
|
|
21
|
+
const url = `https://raw.githubusercontent.com/${OWNER}/${REPO}/${REF}/templates.json`;
|
|
22
|
+
const response = await checkedFetch(url, { headers: headers(version) });
|
|
23
|
+
const manifest = await response.json();
|
|
24
|
+
|
|
25
|
+
if (!manifest || typeof manifest !== "object" || Array.isArray(manifest))
|
|
26
|
+
throw new Error("Invalid templates.json");
|
|
27
|
+
|
|
28
|
+
for (const [name, description] of Object.entries(manifest)) {
|
|
29
|
+
if (!name || typeof description !== "string")
|
|
30
|
+
throw new Error("Invalid templates.json entry");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return manifest;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function fetchTemplateFiles(name, version = "unknown") {
|
|
37
|
+
const treeUrl = `https://api.github.com/repos/${OWNER}/${REPO}/git/trees/${REF}?recursive=1`;
|
|
38
|
+
const response = await checkedFetch(treeUrl, { headers: headers(version) });
|
|
39
|
+
const tree = await response.json();
|
|
40
|
+
|
|
41
|
+
if (!Array.isArray(tree.tree))
|
|
42
|
+
throw new Error("Invalid template repository tree");
|
|
43
|
+
|
|
44
|
+
const prefix = `${name}/`;
|
|
45
|
+
const files = tree.tree
|
|
46
|
+
.filter((item) => item.type === "blob" && item.path.startsWith(prefix))
|
|
47
|
+
.map((item) => ({
|
|
48
|
+
path: item.path.slice(prefix.length),
|
|
49
|
+
url: `https://raw.githubusercontent.com/${OWNER}/${REPO}/${REF}/${item.path.split("/").map(encodeURIComponent).join("/")}`,
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
if (!files.length)
|
|
53
|
+
throw new Error(`Template '${name}' contains no files`);
|
|
54
|
+
|
|
55
|
+
return files;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function downloadTemplateFile(url, version = "unknown") {
|
|
59
|
+
const response = await checkedFetch(url, { headers: headers(version) });
|
|
60
|
+
return Buffer.from(await response.arrayBuffer());
|
|
61
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { fetchTemplates } from "./templates-source.mjs";
|
|
2
|
+
import { color } from "./log.mjs";
|
|
3
|
+
|
|
4
|
+
export async function templates(_argv = [], { version = "unknown" } = {}) {
|
|
5
|
+
const manifest = await fetchTemplates(version);
|
|
6
|
+
const names = Object.keys(manifest).sort();
|
|
7
|
+
const width = names.reduce((max, name) => Math.max(max, name.length), 0) + 3;
|
|
8
|
+
|
|
9
|
+
console.log(color.cyan("Available templates"));
|
|
10
|
+
console.log();
|
|
11
|
+
for (const name of names)
|
|
12
|
+
console.log(` ${color.green(name.padEnd(width))}${manifest[name]}`);
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "x4js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/x4.ts",
|
|
6
6
|
"module": "src/x4.ts",
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
".": "./src/x4.ts",
|
|
10
10
|
"./monaco": "./src/components/monaco/monaco.ts"
|
|
11
11
|
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"x4js": "./bin/x4js.mjs"
|
|
14
|
+
},
|
|
12
15
|
"scripts": {
|
|
13
16
|
"build-publish": "deno run --allow-all ./publish.ts",
|
|
14
17
|
"build-doc": "typedoc",
|
|
@@ -16,6 +19,8 @@
|
|
|
16
19
|
},
|
|
17
20
|
"files": [
|
|
18
21
|
"src",
|
|
22
|
+
"bin",
|
|
23
|
+
"cli",
|
|
19
24
|
"README.md",
|
|
20
25
|
"LICENSE"
|
|
21
26
|
],
|
|
@@ -32,6 +37,10 @@
|
|
|
32
37
|
"desktop",
|
|
33
38
|
"application"
|
|
34
39
|
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"esbuild": "0.28",
|
|
42
|
+
"esbuild-sass-plugin": "^3.7"
|
|
43
|
+
},
|
|
35
44
|
"devDependencies": {
|
|
36
45
|
"typescript": "^5.8.3",
|
|
37
46
|
"typedoc": "^0.28.19",
|
package/readme.npm.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# x4js
|
|
2
|
+
|
|
3
|
+
**A TypeScript framework for building applications, not markup.**
|
|
4
|
+
|
|
5
|
+
x4js is designed for rich web and desktop applications: business software, industrial interfaces, dashboards, data-heavy tools and desktop-like applications.
|
|
6
|
+
|
|
7
|
+
It uses persistent TypeScript objects associated with the real DOM. No virtual DOM, no reconciliation layer, and no application architecture imposed by JSX.
|
|
8
|
+
|
|
9
|
+
**TypeScript objects. JSX when it helps. Real DOM.**
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install x4js
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
Create a project:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx x4build create demo --type=html
|
|
23
|
+
cd demo
|
|
24
|
+
npm install
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Run it in development mode with HMR:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npx x4build --watch --hmr --serve
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## More than 50 UI components
|
|
34
|
+
|
|
35
|
+
x4 includes a complete UI toolkit for building real applications.
|
|
36
|
+
|
|
37
|
+
Among the available components:
|
|
38
|
+
|
|
39
|
+
`Button`, `Input`, `TextEdit`, `TextArea`, `Checkbox`, `Radio`, `Switch`, `Select`, `Combobox`, `Slider`, `ColorPicker`, `Form`, `Dialog`, `Popup`, `Menu`, `Tabs`, `Gridview`, `Treeview`, `PropertyGrid`, `Spreadsheet`, `Calendar`, `Gauge`, `Progress`, `FileDrop`, `MonacoEditor`, layouts and more.
|
|
40
|
+
|
|
41
|
+
The framework also provides:
|
|
42
|
+
|
|
43
|
+
* drag & drop
|
|
44
|
+
* SVG primitives and builder
|
|
45
|
+
* routing
|
|
46
|
+
* PDF generation
|
|
47
|
+
* internationalization
|
|
48
|
+
* data stores and views
|
|
49
|
+
* application-wide events
|
|
50
|
+
* persistence helpers
|
|
51
|
+
* CSS infrastructure and theming
|
|
52
|
+
|
|
53
|
+
## Easy to extend
|
|
54
|
+
|
|
55
|
+
x4 components are ordinary TypeScript classes.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { Component, ComponentProps } from 'x4js'
|
|
59
|
+
|
|
60
|
+
interface StatusBadgeProps extends ComponentProps {
|
|
61
|
+
text: string
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
class StatusBadge extends Component<StatusBadgeProps> {
|
|
65
|
+
constructor(props: StatusBadgeProps) {
|
|
66
|
+
super(props)
|
|
67
|
+
|
|
68
|
+
this.setContent(props.text)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Your own components use the same DOM, lifecycle and event model as the components provided by x4.
|
|
74
|
+
|
|
75
|
+
Because x4 works with the real browser DOM, third-party UI libraries can also be integrated where they make sense. There is no separate plugin architecture to satisfy.
|
|
76
|
+
|
|
77
|
+
## Real DOM
|
|
78
|
+
|
|
79
|
+
A `Component` is a persistent TypeScript object associated with an actual DOM element.
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const button = new Button({
|
|
83
|
+
label: 'Restart'
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
button.on('click', () => restartMachine())
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The object remains alive for the lifetime of the component. You can keep references, call methods and listen to events directly.
|
|
90
|
+
|
|
91
|
+
There is no virtual tree to rebuild or reconcile.
|
|
92
|
+
|
|
93
|
+
## JSX is optional
|
|
94
|
+
|
|
95
|
+
x4 supports JSX, but JSX is syntax — not the application architecture.
|
|
96
|
+
|
|
97
|
+
Object API:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
this.setContent([
|
|
101
|
+
new Label({
|
|
102
|
+
text: 'Temperature'
|
|
103
|
+
}),
|
|
104
|
+
|
|
105
|
+
new Gauge({
|
|
106
|
+
min: 0,
|
|
107
|
+
max: 100
|
|
108
|
+
})
|
|
109
|
+
])
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
JSX:
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
this.setContent(
|
|
116
|
+
<VBox>
|
|
117
|
+
<Label text="Temperature" />
|
|
118
|
+
<Gauge min={0} max={100} />
|
|
119
|
+
</VBox>
|
|
120
|
+
)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Both create the same x4 Components and the same real DOM.
|
|
124
|
+
|
|
125
|
+
Use whichever makes the code clearer.
|
|
126
|
+
|
|
127
|
+
## Data-heavy applications
|
|
128
|
+
|
|
129
|
+
x4 treats grids, trees, forms and structured data as first-class application concerns.
|
|
130
|
+
|
|
131
|
+
`DataStore`, `DataView` and `Gridview` are designed to work together for tabular data:
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
const store = new DataStore({
|
|
135
|
+
model,
|
|
136
|
+
data
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
const grid = new Gridview({
|
|
140
|
+
store,
|
|
141
|
+
columns: [
|
|
142
|
+
{ id: 'name', title: 'Name', width: 200 },
|
|
143
|
+
{ id: 'age', title: 'Age', width: 80 }
|
|
144
|
+
]
|
|
145
|
+
})
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Changes to the data are reflected by the components using it.
|
|
149
|
+
|
|
150
|
+
## Routing
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
const router = new Router(true)
|
|
154
|
+
|
|
155
|
+
router.get('/home', () => showHome())
|
|
156
|
+
router.get('/device/:id', p => showDevice(p.id))
|
|
157
|
+
|
|
158
|
+
router.init()
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Internationalization
|
|
162
|
+
|
|
163
|
+
Internationalization support is built in.
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
createLanguage('de', 'en')
|
|
167
|
+
addTranslation('de', translations)
|
|
168
|
+
|
|
169
|
+
selectLanguage('de')
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
x4 includes French and English translations by default and allows applications to add their own languages.
|
|
173
|
+
|
|
174
|
+
## SVG and PDF
|
|
175
|
+
|
|
176
|
+
SVG is part of the framework surface through `SvgComponent` and `SvgBuilder`.
|
|
177
|
+
|
|
178
|
+
PDF documents can be generated programmatically with `X4PDFBuilder`:
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
const pdf = new X4PDFBuilder()
|
|
182
|
+
|
|
183
|
+
pdf.page(595, 842, page => {
|
|
184
|
+
// draw page
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
const data = pdf.build()
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## CSS and themes
|
|
191
|
+
|
|
192
|
+
x4 includes the CSS foundation used by its components.
|
|
193
|
+
|
|
194
|
+
Applications can use the default styling, adapt it to their product, or provide their own CSS. Components expose their real DOM and CSS classes, so standard browser styling techniques remain available.
|
|
195
|
+
|
|
196
|
+
No CSS-in-JS runtime is required.
|
|
197
|
+
|
|
198
|
+
## HMR and development workflow
|
|
199
|
+
|
|
200
|
+
The standard x4 build workflow supports watch mode, development serving and HMR:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
x4build --watch --hmr --serve
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Edit the application, save, see the result.
|
|
207
|
+
|
|
208
|
+
## Ship only what you use
|
|
209
|
+
|
|
210
|
+
The `x4js` npm package ships its TypeScript sources directly.
|
|
211
|
+
|
|
212
|
+
Your application and x4 therefore participate in the same module graph, allowing the bundler to tree-shake unused code.
|
|
213
|
+
|
|
214
|
+
Import a small part of x4 and the rest of the component library does not need to become part of your application bundle.
|
|
215
|
+
|
|
216
|
+
## Web and desktop
|
|
217
|
+
|
|
218
|
+
x4 targets both browser and desktop applications.
|
|
219
|
+
|
|
220
|
+
The same component model can be used in the browser or inside a desktop wrapper such as Electron, Tauri or NW.js.
|
|
221
|
+
|
|
222
|
+
## AI-friendly documentation
|
|
223
|
+
|
|
224
|
+
x4 provides a generated `aicontext.md` containing the actual TypeScript API signatures.
|
|
225
|
+
|
|
226
|
+
AI coding agents can also inspect the framework sources directly because they are distributed with the npm package:
|
|
227
|
+
|
|
228
|
+
```text
|
|
229
|
+
node_modules/x4js/src/
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
The goal is not to make x4 an “AI framework”.
|
|
233
|
+
|
|
234
|
+
The goal is simpler: an explicit architecture and an API that are readable by humans and predictable for machines.
|
|
235
|
+
|
|
236
|
+
## Philosophy
|
|
237
|
+
|
|
238
|
+
x4 deliberately keeps its conceptual model small.
|
|
239
|
+
|
|
240
|
+
Use TypeScript when TypeScript is enough.
|
|
241
|
+
Use the browser when the browser is enough.
|
|
242
|
+
Add an abstraction only when it solves a real problem.
|
|
243
|
+
|
|
244
|
+
**Use the simplest tool that fits.**
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
MIT License
|