Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve source structure in the node api #6164

Merged
merged 8 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ All notable changes to this project are documented in this file.
- Skia renderer: Improve rendering quality of layers
- GridLayout: Fixed panic when rowspan or colspan is 0 (#6181)


tronical marked this conversation as resolved.
Show resolved Hide resolved
## [1.7.2] - 2024-08-14

### General
Expand Down
1 change: 1 addition & 0 deletions api/node/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ rust-module.d.ts
index.js
docs/
npm/
dist/
1 change: 1 addition & 0 deletions api/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ build = "build.rs"

[lib]
crate-type = ["cdylib"]
path = "rust/lib.rs"

[features]
default = ["backend-winit", "renderer-femtovg", "renderer-software", "backend-qt", "accessibility"]
Expand Down
4 changes: 1 addition & 3 deletions api/node/__test__/api.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import test from "ava";
import * as path from "node:path";
import { fileURLToPath } from "node:url";

import { loadFile, loadSource, CompileError } from "../index.js";
import { loadFile, loadSource, CompileError } from "../dist/index.js";

const dirname = path.dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -81,7 +81,6 @@ test("loadFile constructor parameters", (t) => {
});

test("loadFile component instances and modules are sealed", (t) => {
"use strict";
const demo = loadFile(path.join(dirname, "resources/test.slint")) as any;

t.throws(
Expand Down Expand Up @@ -182,7 +181,6 @@ test("loadSource constructor parameters", (t) => {
});

test("loadSource component instances and modules are sealed", (t) => {
"use strict";
const source = `export component Test {
out property <string> check: "Test";
}`;
Expand Down
2 changes: 1 addition & 1 deletion api/node/__test__/compiler.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import test from "ava";

import { private_api } from "../index.js";
import { private_api } from "../dist/index.js";

test("get/set include paths", (t) => {
const compiler = new private_api.ComponentCompiler();
Expand Down
2 changes: 1 addition & 1 deletion api/node/__test__/eventloop.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import test from "ava";
import * as http from "node:http";
import fetch from "node-fetch";

import { runEventLoop, quitEventLoop, private_api } from "../index.js";
import { runEventLoop, quitEventLoop, private_api } from "../dist/index.js";

test.serial("merged event loops with timer", async (t) => {
let invoked = false;
Expand Down
2 changes: 1 addition & 1 deletion api/node/__test__/globals.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import test from "ava";

import { private_api } from "../index.js";
import { private_api } from "../dist/index.js";

test("get/set global properties", (t) => {
const compiler = new private_api.ComponentCompiler();
Expand Down
9 changes: 5 additions & 4 deletions api/node/__test__/js_value_conversion.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
type ImageData,
ArrayModel,
type Model,
} from "../index.js";
} from "../dist/index.js";

const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
Expand Down Expand Up @@ -598,11 +598,12 @@ test("MapModel", (t) => {

instance!.setProperty("model", mapModel);

nameModel.setRowData(1, { first: "Simon", last: "Hausmann" });
nameModel.setRowData(0, { first: "Simon", last: "Hausmann" });
nameModel.setRowData(1, { first: "Olivier", last: "Goffart" });

const checkModel = instance!.getProperty("model") as Model<string>;
t.is(checkModel.rowData(0), "Emil, Hans");
t.is(checkModel.rowData(1), "Hausmann, Simon");
t.is(checkModel.rowData(0), "Hausmann, Simon");
t.is(checkModel.rowData(1), "Goffart, Olivier");
t.is(checkModel.rowData(2), "Tisch, Roman");
});

Expand Down
64 changes: 64 additions & 0 deletions api/node/__test__/models.spec.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

import test from "ava";
import * as path from "node:path";
import { fileURLToPath } from "node:url";

import {
loadFile,
loadSource,
CompileError,
ArrayModel,
private_api,
Model,
} from "../dist/index.js";

test("MapModel notify rowChanged", (t) => {
const source = `
export component App {

in-out property <[string]> model;
in-out property <string> changed-items;

for item in root.model : Text {
text: item;

changed text => {
root.changed-items += self.text;
}
}
}`;

const path = "api.spec.ts";

private_api.initTesting();
const demo = loadSource(source, path) as any;
const instance = new demo.App();

interface Name {
first: string;
last: string;
}

const nameModel: ArrayModel<Name> = new ArrayModel([
{ first: "Hans", last: "Emil" },
{ first: "Max", last: "Mustermann" },
{ first: "Roman", last: "Tisch" },
]);

const mapModel = new private_api.MapModel(nameModel, (data) => {
return data.last + ", " + data.first;
});

instance.model = mapModel;

private_api.send_mouse_click(instance, 5, 5);

nameModel.setRowData(0, { first: "Simon", last: "Hausmann" });
nameModel.setRowData(1, { first: "Olivier", last: "Goffart" });

private_api.send_mouse_click(instance, 5, 5);

t.is(instance.changed_items, "Goffart, OlivierHausmann, Simon");
});
2 changes: 1 addition & 1 deletion api/node/__test__/types.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import test from "ava";

import { private_api, ArrayModel } from "../index.js";
import { private_api, ArrayModel } from "../dist/index.js";

test("SlintColor from fromRgb", (t) => {
const color = private_api.SlintRgbaColor.fromRgb(100, 110, 120);
Expand Down
2 changes: 1 addition & 1 deletion api/node/__test__/window.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import test from "ava";

import { private_api, Window } from "../index.js";
import { private_api, Window } from "../dist/index.js";

test("Window constructor", (t) => {
t.throws(
Expand Down
8 changes: 4 additions & 4 deletions api/node/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "slint-ui",
"version": "1.9.0",
"main": "index.js",
"types": "index.d.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good idea to place the generated files into the dist/ sub-directory. Not in scope of this PR, but as a follow-up suggestion, it might make sense to place the remaining generated files into dist as well, specifically the napi generated ones.

"homepage": "https://github.com/slint-ui/slint",
"license": "SEE LICENSE IN LICENSE.md",
"repository": {
Expand All @@ -20,8 +20,8 @@
],
"description": "Slint is a declarative GUI toolkit to build native user interfaces for desktop and embedded applications.",
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@ava/typescript": "^4.1.0",
"@biomejs/biome": "1.8.3",
"@types/node": "^20.8.6",
"@types/node-fetch": "^2.6.7",
"ava": "^5.3.0",
Expand All @@ -40,7 +40,7 @@
"build:debug": "napi build --platform --js rust-module.cjs --dts rust-module.d.ts -c binaries.json && npm run compile",
"build:testing": "napi build --platform --js rust-module.cjs --dts rust-module.d.ts -c binaries.json --features testing && npm run compile",
"install": "node build-on-demand.mjs",
"docs": "npm run build && typedoc --hideGenerator --treatWarningsAsErrors --readme cover.md index.ts",
"docs": "npm run build && typedoc --hideGenerator --treatWarningsAsErrors --readme cover.md typescript/index.ts",
"check": "biome check",
"format": "biome format",
"format:fix": "biome format --write",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion api/node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"module": "CommonJS",
"target": "esnext",
"declaration": true,
"outDir": "dist"
},
"include": [
"index.ts"
"typescript/"
],
}
Loading
Loading