diff --git a/packages/shared/widget-harness/README.md b/packages/shared/widget-harness/README.md new file mode 100644 index 0000000000..4a2b7f132e --- /dev/null +++ b/packages/shared/widget-harness/README.md @@ -0,0 +1,36 @@ +# @mendix/widget-harness + +Renders real pluggable widgets in a plain browser page, with props backed by a live in-memory data store. +No mxbuild, Mendix runtime, JVM or Docker. It fakes only the pluggable widget API props (`mendix` typings) +and the data behind them; it is not a Mendix client. + +## Layout + +- `src/store`: framework-agnostic core (no React, no Jest). `DataStore` holds entity objects; + `LiveList` is a `ListValue` source that applies filter conditions, sort order, offset and limit, + total count and `hasMoreItems`, and goes `loading` → `available` after a configurable delay. +- `src/filters/builders.ts`: implementation of `mendix/filters/builders`. `evaluateFilter` runs the trees it builds. +- `src/props/Harness.ts`: live props on top of the store: list attributes, expressions, widgets, actions, + editable values and selections. `harness.version` changes whenever a widget-visible value changes. +- `host/`: Vite page that mounts a scenario and passes the widget fresh props on every change. +- `e2e/`: Playwright tests against the host page. + +## Run + +```sh +cd packages/shared/widget-harness +pnpm run dev # http://localhost:5199/?scenario=datagrid-basic&delay=50 +pnpm exec playwright install chromium # once +pnpm run test:e2e +``` + +In the page, `window.harness` exposes the harness (`harness.store`, `harness.calls`) and scenario handles, +so tests can change data and check recorded actions. + +## Semantics worth knowing + +- Attribute ids are the attribute names from the scenario schema. +- String comparisons and `contains`/`starts-with`/`ends-with` are case-insensitive, like XPath in Mendix. +- Empty values sort first in ascending order. +- A store change reloads every `LiveList` (like refresh in client), unless `reloadOnStoreChange: false`. +- Formatting is fixed en-US: numbers via `Big#toString`, booleans as Yes/No, dates as `M/D/YYYY HH:mm`. diff --git a/packages/shared/widget-harness/e2e/datagrid-basic.spec.ts b/packages/shared/widget-harness/e2e/datagrid-basic.spec.ts new file mode 100644 index 0000000000..e2a93e415c --- /dev/null +++ b/packages/shared/widget-harness/e2e/datagrid-basic.spec.ts @@ -0,0 +1,81 @@ +import { expect, Locator, Page, test } from "@playwright/test"; + +// Fixture: host/fixtures/people.ts. 30 people, page size 10, ages 20..49 all distinct. +const FIRST_NAME = 2; +const AGE = 4; + +class Grid { + readonly root: Locator; + readonly rows: Locator; + + constructor(public readonly page: Page) { + this.root = page.locator(".mx-name-datagrid1"); + this.rows = this.root.locator(".widget-datagrid-grid-body [role=row]"); + } + + column(n: number): Locator { + return this.rows.locator(`[role=gridcell]:nth-child(${n})`); + } + + header(name: string): Locator { + return this.root.getByRole("button", { name: `sort ${name}` }); + } + + get pagingStatus(): Locator { + return this.root.locator(".paging-status"); + } +} + +test.beforeEach(async ({ page }) => { + await page.goto("/?scenario=datagrid-basic"); +}); + +test("renders the first page of rows from the store", async ({ page }) => { + const grid = new Grid(page); + await expect(grid.rows).toHaveCount(10); + await expect(grid.column(FIRST_NAME).first()).toHaveText("Loretta"); + await expect(grid.pagingStatus).toHaveText("1 to 10 of 30"); +}); + +test("sorts by a column ascending, then descending", async ({ page }) => { + const grid = new Grid(page); + await grid.header("Age").click(); + await expect(grid.column(AGE).first()).toHaveText("20"); + await expect(grid.column(AGE).nth(9)).toHaveText("29"); + + await grid.header("Age").click(); + await expect(grid.column(AGE).first()).toHaveText("49"); + await expect(grid.column(AGE).nth(9)).toHaveText("40"); +}); + +test("filters rows with the column text filter, case-insensitively", async ({ page }) => { + const grid = new Grid(page); + await grid.root.getByRole("textbox", { name: "filter" }).fill("ADA"); + + await expect(grid.rows).toHaveCount(3); + await expect(grid.column(FIRST_NAME)).toHaveText(["Ada", "Ada", "Ada"]); + await expect(grid.pagingStatus).toHaveText("1 to 3 of 3"); +}); + +test("pages through the data source", async ({ page }) => { + const grid = new Grid(page); + await grid.root.getByRole("button", { name: "Go to next page" }).click(); + await expect(grid.pagingStatus).toHaveText("11 to 20 of 30"); + await expect(grid.column(AGE).first()).toHaveText("30"); + + await grid.root.getByRole("button", { name: "Go to last page" }).click(); + await expect(grid.pagingStatus).toHaveText("21 to 30 of 30"); + await expect(grid.rows).toHaveCount(10); +}); + +test("re-renders when the store changes and records row click actions", async ({ page }) => { + const grid = new Grid(page); + await expect(grid.column(FIRST_NAME).first()).toHaveText("Loretta"); + + await page.evaluate(() => (window as any).harness.harness.store.update("p01", { firstName: "Zed" })); + await expect(grid.column(FIRST_NAME).first()).toHaveText("Zed"); + + await grid.column(AGE).nth(1).click(); + const calls = await page.evaluate(() => (window as any).harness.harness.calls); + expect(calls).toEqual([{ name: "onClickRow", item: "p02" }]); +}); diff --git a/packages/shared/widget-harness/eslint.config.mjs b/packages/shared/widget-harness/eslint.config.mjs new file mode 100644 index 0000000000..ed68ae9e78 --- /dev/null +++ b/packages/shared/widget-harness/eslint.config.mjs @@ -0,0 +1,3 @@ +import config from "@mendix/eslint-config-web-widgets/widget-ts.mjs"; + +export default config; diff --git a/packages/shared/widget-harness/host/fixtures/people.ts b/packages/shared/widget-harness/host/fixtures/people.ts new file mode 100644 index 0000000000..1c3f32f06a --- /dev/null +++ b/packages/shared/widget-harness/host/fixtures/people.ts @@ -0,0 +1,27 @@ +import type { InputRecord, Schema } from "../../src/main"; + +export const peopleSchema: Schema = { + Person: { + attributes: { + firstName: "String", + lastName: "String", + age: "Integer", + active: "Boolean", + color: { type: "Enum", values: { red: "Red", green: "Green", blue: "Blue" } } + } + } +}; + +const firstNames = ["Loretta", "Chad", "Ada", "Brian", "Cleo", "Dmitri", "Elena", "Farah", "Gus", "Hana"]; +const lastNames = ["Moss", "Kent", "Lovelace", "Okafor", "Novak"]; +const colors = ["red", "green", "blue"]; + +/** 30 people; ids "p01".."p30"; ages 20..49 in a shuffled but fixed order. */ +export const people: InputRecord[] = Array.from({ length: 30 }, (_, i) => ({ + id: `p${String(i + 1).padStart(2, "0")}`, + firstName: firstNames[i % firstNames.length], + lastName: lastNames[i % lastNames.length], + age: 20 + ((i * 7) % 30), + active: i % 2 === 0, + color: colors[i % colors.length] +})); diff --git a/packages/shared/widget-harness/host/index.html b/packages/shared/widget-harness/host/index.html new file mode 100644 index 0000000000..a2975658d7 --- /dev/null +++ b/packages/shared/widget-harness/host/index.html @@ -0,0 +1,12 @@ + + + + + + Widget harness + + +
+ + + diff --git a/packages/shared/widget-harness/host/main.tsx b/packages/shared/widget-harness/host/main.tsx new file mode 100644 index 0000000000..d55e663f22 --- /dev/null +++ b/packages/shared/widget-harness/host/main.tsx @@ -0,0 +1,30 @@ +import { ReactElement, useSyncExternalStore } from "react"; +import { createRoot } from "react-dom/client"; +import { ScenarioFactory, ScenarioInstance } from "./scenario"; +import { filters } from "../src/main"; +import "./styles.scss"; + +const scenarios: Record Promise<{ default: ScenarioFactory }>> = { + "datagrid-basic": () => import("./scenarios/datagrid-basic") +}; + +function Host({ instance }: { instance: ScenarioInstance }): ReactElement { + useSyncExternalStore(instance.harness.subscribe, () => instance.harness.version); + return instance.render(); +} + +async function start(): Promise { + const name = new URLSearchParams(window.location.search).get("scenario") ?? "datagrid-basic"; + const load = scenarios[name]; + const root = document.getElementById("root")!; + if (!load) { + root.textContent = `Unknown scenario "${name}". Available: ${Object.keys(scenarios).join(", ")}`; + return; + } + const instance = (await load()).default(); + Object.assign(window, { harness: { ...instance.expose, harness: instance.harness, filters } }); + // No StrictMode: Datagrid's setup runs once per mount, as in the Mendix client. + createRoot(root).render(); +} + +start(); diff --git a/packages/shared/widget-harness/host/scenario.ts b/packages/shared/widget-harness/host/scenario.ts new file mode 100644 index 0000000000..a9b20a6a82 --- /dev/null +++ b/packages/shared/widget-harness/host/scenario.ts @@ -0,0 +1,12 @@ +import type { ReactElement } from "react"; +import type { Harness } from "../src/props/Harness"; + +export interface ScenarioInstance { + harness: Harness; + /** Called on every harness change; must read live values so the widget gets fresh props. */ + render(): ReactElement; + /** Extra handles exposed on `window.harness` for tests. */ + expose?: Record; +} + +export type ScenarioFactory = () => ScenarioInstance; diff --git a/packages/shared/widget-harness/host/scenarios/datagrid-basic.tsx b/packages/shared/widget-harness/host/scenarios/datagrid-basic.tsx new file mode 100644 index 0000000000..5589035ede --- /dev/null +++ b/packages/shared/widget-harness/host/scenarios/datagrid-basic.tsx @@ -0,0 +1,103 @@ +import DatagridTextFilter from "@mendix/datagrid-text-filter-web/src/DatagridTextFilter"; +import Datagrid from "@mendix/datagrid-web/src/Datagrid"; +import type { ColumnsType, DatagridContainerProps } from "@mendix/datagrid-web/typings/DatagridProps"; +import { dynamic, Harness } from "../../src/main"; +import { people, peopleSchema } from "../fixtures/people"; +import { ScenarioFactory } from "../scenario"; + +const delay = Number(new URLSearchParams(window.location.search).get("delay") ?? 50); + +const create: ScenarioFactory = () => { + const harness = new Harness(peopleSchema, { Person: people }); + const datasource = harness.list({ entity: "Person", delay }); + const selection = harness.selectionMulti(); + const onClick = harness.listAction("onClickRow"); + + function column(attr: string, header: string, extra: Partial = {}): ColumnsType { + return { + showContentAs: "attribute", + attribute: harness.listAttribute("Person", attr), + header: dynamic(header), + visible: dynamic(true), + exportType: "default", + sortable: true, + resizable: true, + draggable: false, + hidable: "yes", + allowEventPropagation: true, + width: "autoFill", + size: 1, + minWidth: "auto", + minWidthLimit: 100, + alignment: "left", + wrapText: false, + ...extra + }; + } + + function props(): DatagridContainerProps { + return { + name: "datagrid1", + // The Mendix client passes the mx-name class through `class`. + class: "mx-name-datagrid1", + datasource: datasource.value, + refreshInterval: 0, + columns: [ + column("firstName", "First name", { + filter: ( + + ) + }), + column("lastName", "Last name"), + column("age", "Age"), + column("color", "Color") + ], + columnsFilterable: true, + onClickTrigger: "single", + onClick, + itemSelection: selection.value, + itemSelectionMethod: "checkbox", + autoSelect: false, + itemSelectionMode: "toggle", + showSelectAllToggle: true, + enableSelectAll: false, + keepSelection: false, + selectionCounterPosition: "bottom", + loadingType: "spinner", + refreshIndicator: false, + pageSize: 10, + pagination: "buttons", + useCustomPagination: false, + showPagingButtons: "always", + showNumberOfRows: true, + pagingPosition: "bottom", + showEmptyPlaceholder: "none", + columnsSortable: true, + columnsResizable: true, + columnsDraggable: false, + columnsHidable: true, + configurationStorageType: "localStorage", + storeFiltersInPersonalization: false, + selectAllText: dynamic("Select all"), + selectAllTemplate: dynamic("Select all %d rows"), + allSelectedText: dynamic("All %d rows selected") + }; + } + + return { + harness, + render: () => , + expose: { datasource, selection } + }; +}; + +export default create; diff --git a/packages/shared/widget-harness/host/shims/mendix-filters.ts b/packages/shared/widget-harness/host/shims/mendix-filters.ts new file mode 100644 index 0000000000..cb0ff5c3b5 --- /dev/null +++ b/packages/shared/widget-harness/host/shims/mendix-filters.ts @@ -0,0 +1 @@ +export {}; diff --git a/packages/shared/widget-harness/host/shims/mendix.ts b/packages/shared/widget-harness/host/shims/mendix.ts new file mode 100644 index 0000000000..19b59d433f --- /dev/null +++ b/packages/shared/widget-harness/host/shims/mendix.ts @@ -0,0 +1,11 @@ +// The real `mendix` package only ships typings; const enums from it are inlined by tsc but not by esbuild. +export const ValueStatus = { + Available: "available", + Unavailable: "unavailable", + Loading: "loading" +} as const; + +export const FormatterType = { + Number: "number", + DateTime: "datetime" +} as const; diff --git a/packages/shared/widget-harness/host/styles.scss b/packages/shared/widget-harness/host/styles.scss new file mode 100644 index 0000000000..f38ba4e303 --- /dev/null +++ b/packages/shared/widget-harness/host/styles.scss @@ -0,0 +1,12 @@ +@import "../../../modules/data-widgets/src/themesource/datawidgets/web/variables"; +@import "../../../modules/data-widgets/src/themesource/datawidgets/web/pagination-bar"; +@import "../../../modules/data-widgets/src/themesource/datawidgets/web/datagrid"; +@import "../../../modules/data-widgets/src/themesource/datawidgets/web/datagrid-filters"; +@import "../../../modules/data-widgets/src/themesource/datawidgets/web/datagrid-dropdown-filter"; +@import "../../../modules/data-widgets/src/themesource/datawidgets/web/refresh-indicator"; +@import "../../../modules/data-widgets/src/themesource/datawidgets/web/three-state-checkbox"; + +body { + font-family: sans-serif; + margin: 16px; +} diff --git a/packages/shared/widget-harness/host/vite.config.ts b/packages/shared/widget-harness/host/vite.config.ts new file mode 100644 index 0000000000..4c592bde72 --- /dev/null +++ b/packages/shared/widget-harness/host/vite.config.ts @@ -0,0 +1,29 @@ +import { fileURLToPath } from "node:url"; +import { defineConfig } from "vite"; + +const here = (path: string): string => fileURLToPath(new URL(path, import.meta.url)); +const repoRoot = here("../../../../"); + +export default defineConfig({ + root: here("."), + resolve: { + alias: [ + { find: /^mendix$/, replacement: here("./shims/mendix.ts") }, + { find: /^mendix\/filters\/builders$/, replacement: here("../src/filters/builders.ts") }, + { find: /^mendix\/filters$/, replacement: here("./shims/mendix-filters.ts") }, + // Workspace libraries are consumed from source so the harness needs no prior build. + { + find: /^@mendix\/(widget-plugin-[a-z-]+|filter-commons)\/(.*)$/, + replacement: `${repoRoot}packages/shared/$1/src/$2` + }, + { find: /^big\.js$/, replacement: here("../node_modules/big.js/big.mjs") } + ], + dedupe: ["react", "react-dom", "mobx", "mobx-react-lite"] + }, + server: { + port: 5199, + strictPort: true, + fs: { allow: [repoRoot] } + }, + css: { preprocessorOptions: { scss: { quietDeps: true, silenceDeprecations: ["import", "global-builtin"] } } } +}); diff --git a/packages/shared/widget-harness/package.json b/packages/shared/widget-harness/package.json new file mode 100644 index 0000000000..a38ff231f8 --- /dev/null +++ b/packages/shared/widget-harness/package.json @@ -0,0 +1,36 @@ +{ + "name": "@mendix/widget-harness", + "version": "0.1.0", + "description": "Live in-memory data store and browser host page for exercising pluggable widgets without a Mendix runtime.", + "copyright": "© Mendix Technology BV 2025. All rights reserved.", + "license": "Apache-2.0", + "private": true, + "repository": { + "type": "git", + "url": "https://github.com/mendix/web-widgets.git" + }, + "type": "module", + "scripts": { + "dev": "vite --config host/vite.config.ts", + "format": "prettier --write .", + "lint": "eslint src/ host/ e2e/ package.json", + "test:e2e": "playwright test", + "typecheck": "tsc --noEmit -p tsconfig.core.json" + }, + "dependencies": { + "big.js": "^6.2.2", + "mendix": "10.24.75382" + }, + "devDependencies": { + "@mendix/datagrid-text-filter-web": "workspace:*", + "@mendix/datagrid-web": "workspace:*", + "@mendix/eslint-config-web-widgets": "workspace:*", + "@mendix/prettier-config-web-widgets": "workspace:*", + "@mendix/tsconfig-web-widgets": "workspace:*", + "@playwright/test": "^1.60.0", + "react": ">=18.0.0 <19.0.0", + "react-dom": ">=18.0.0 <19.0.0", + "sass": "1.102.0", + "vite": "7.3.7" + } +} diff --git a/packages/shared/widget-harness/playwright.config.ts b/packages/shared/widget-harness/playwright.config.ts new file mode 100644 index 0000000000..c564673ae3 --- /dev/null +++ b/packages/shared/widget-harness/playwright.config.ts @@ -0,0 +1,20 @@ +import { defineConfig, devices } from "@playwright/test"; + +const port = 5199; + +export default defineConfig({ + testDir: "./e2e", + fullyParallel: true, + reporter: process.env.CI ? "github" : "list", + use: { + baseURL: `http://localhost:${port}`, + trace: "retain-on-failure" + }, + projects: [{ name: "chromium", use: { ...devices["Desktop Chrome"] } }], + webServer: { + command: "pnpm run dev", + url: `http://localhost:${port}`, + reuseExistingServer: !process.env.CI, + timeout: 60_000 + } +}); diff --git a/packages/shared/widget-harness/src/filters/builders.ts b/packages/shared/widget-harness/src/filters/builders.ts new file mode 100644 index 0000000000..f3aa319184 --- /dev/null +++ b/packages/shared/widget-harness/src/filters/builders.ts @@ -0,0 +1,101 @@ +/** + * Browser and Node implementation of `mendix/filters/builders`, written against the public typings. + * Produces plain condition trees that `evaluateFilter` understands. + */ +import { Big } from "big.js"; +import type { ObjectItem } from "mendix"; +import type { + AndCondition, + AssociationExpression, + AttributeExpression, + FilterCondition, + LiteralExpression, + NotCondition, + OrCondition, + ValueExpression +} from "mendix/filters"; + +type LiteralInput = undefined | string | boolean | Date | Big | ObjectItem | ObjectItem[]; + +function isObjectItem(value: unknown): value is ObjectItem { + return typeof value === "object" && value !== null && "id" in value && typeof value.id === "string"; +} + +export function literal(value: LiteralInput): LiteralExpression { + const make = (valueType: string, v: unknown): LiteralExpression => + ({ type: "literal", value: v, valueType }) as LiteralExpression; + + if (value === undefined) { + return make("undefined", undefined); + } + if (typeof value === "string") { + return make("string", value); + } + if (typeof value === "boolean") { + return make("boolean", value); + } + if (value instanceof Date) { + return make("DateTime", value); + } + if (value instanceof Big) { + return make("Numeric", value); + } + if (Array.isArray(value)) { + return make( + "ReferenceSet", + value.map(item => item.id) + ); + } + if (isObjectItem(value)) { + return make("Reference", value.id); + } + throw new Error(`literal: unsupported value ${String(value)}`); +} + +export function empty(): LiteralExpression { + return literal(undefined); +} + +export function attribute(attributeId: string): AttributeExpression { + return { type: "attribute", attributeId } as AttributeExpression; +} + +export function association(associationId: string): AssociationExpression { + return { type: "association", associationId } as AssociationExpression; +} + +function binary(name: string) { + return (arg1: ValueExpression, arg2: ValueExpression): any => ({ type: "function", name, arg1, arg2 }); +} + +export const equals = binary("="); +export const notEqual = binary("!="); +export const greaterThan = binary(">"); +export const greaterThanOrEqual = binary(">="); +export const lessThan = binary("<"); +export const lessThanOrEqual = binary("<="); +export const dayEquals = binary("day:="); +export const dayNotEqual = binary("day:!="); +export const dayGreaterThan = binary("day:>"); +export const dayGreaterThanOrEqual = binary("day:>="); +export const dayLessThan = binary("day:<"); +export const dayLessThanOrEqual = binary("day:<="); +export const contains = binary("contains"); +export const startsWith = binary("starts-with"); +export const endsWith = binary("ends-with"); + +function multiary(name: "and" | "or") { + return (...args: FilterCondition[]): any => { + if (args.length < 2) { + throw new Error(`${name}: expects at least two arguments`); + } + return { type: "function", name, args }; + }; +} + +export const and: (...args: FilterCondition[]) => AndCondition = multiary("and"); +export const or: (...args: FilterCondition[]) => OrCondition = multiary("or"); + +export function not(arg: FilterCondition): NotCondition { + return { type: "function", name: "not", arg } as NotCondition; +} diff --git a/packages/shared/widget-harness/src/main.ts b/packages/shared/widget-harness/src/main.ts new file mode 100644 index 0000000000..9efe47ce0d --- /dev/null +++ b/packages/shared/widget-harness/src/main.ts @@ -0,0 +1,8 @@ +export * from "./store/DataStore.js"; +export * from "./store/Emitter.js"; +export * from "./store/evaluate.js"; +export * from "./store/LiveList.js"; +export * from "./store/schema.js"; +export * from "./props/formatters.js"; +export * from "./props/Harness.js"; +export * as filters from "./filters/builders.js"; diff --git a/packages/shared/widget-harness/src/props/Harness.ts b/packages/shared/widget-harness/src/props/Harness.ts new file mode 100644 index 0000000000..7d819123fa --- /dev/null +++ b/packages/shared/widget-harness/src/props/Harness.ts @@ -0,0 +1,307 @@ +import type { + ActionValue, + DynamicValue, + EditableValue, + GUID, + ListActionValue, + ListAttributeValue, + ListExpressionValue, + ListWidgetValue, + ObjectItem, + SelectionMultiValue, + SelectionSingleValue, + SimpleFormatter, + ValueStatus +} from "mendix"; +import { formatterFor } from "./formatters.js"; +import { DataStore, InputRecord } from "../store/DataStore.js"; +import { Emitter } from "../store/Emitter.js"; +import { LiveList, LiveListOptions } from "../store/LiveList.js"; +import { attributeType, EntityObject, Schema, StoredValue } from "../store/schema.js"; + +const Available = "available" as ValueStatus.Available; + +export type AttributeValue = NonNullable; + +export interface ActionCall { + name: string; + item?: GUID; + args?: unknown; +} + +export interface ActionOptions { + canExecute?: boolean; + run?: (harness: Harness, item?: ObjectItem, args?: unknown) => void; +} + +export interface EditableOptions { + value?: T; + readOnly?: boolean; + formatter?: SimpleFormatter; + universe?: T[]; +} + +export function dynamic(value: T): DynamicValue { + return { status: Available, value }; +} + +/** + * Owns the store and every stateful live prop. `version` changes whenever anything a widget can + * observe changes, so a host re-runs its props factory and passes the widget fresh props. + */ +export class Harness { + readonly store: DataStore; + readonly calls: ActionCall[] = []; + private readonly emitter = new Emitter(); + private readonly attributeCache = new Map }>(); + private _version = 0; + + constructor(schema: Schema, data: Record = {}) { + this.store = new DataStore(schema, data); + this.store.subscribe(() => this.bump()); + } + + get version(): number { + return this._version; + } + + subscribe = (listener: () => void): (() => void) => this.emitter.subscribe(listener); + + bump(): void { + this._version++; + this.emitter.emit(); + } + + list(options: LiveListOptions): LiveList { + const list = new LiveList(this.store, options); + list.subscribe(() => this.bump()); + return list; + } + + listAttribute( + entity: string, + attr: string, + options: { readOnly?: boolean } = {} + ): ListAttributeValue { + const key = `${entity}.${attr}.${options.readOnly ?? false}`; + const cached = this.attributeCache.get(key); + if (cached && cached.version === this.store.version) { + return cached.value; + } + const def = this.store.entity(entity).attributes[attr]; + if (!def) { + throw new Error(`Entity "${entity}" has no attribute "${attr}"`); + } + const formatter = formatterFor(def); + const type = attributeType(def); + const values = new Map>(); + const value = { + id: attr, + type, + sortable: true, + filterable: true, + isList: false, + formatter, + universe: + typeof def === "object" ? Object.keys(def.values) : type === "Boolean" ? [true, false] : undefined, + get: (item: ObjectItem) => { + let editable = values.get(item.id); + if (!editable) { + editable = this.objectAttribute(this.store.require(item.id), attr, formatter, options.readOnly); + values.set(item.id, editable); + } + return editable; + } + } as unknown as ListAttributeValue; + this.attributeCache.set(key, { version: this.store.version, value }); + return value; + } + + listExpression(fn: (obj: EntityObject, harness: Harness) => T): ListExpressionValue { + return { get: (item: ObjectItem) => dynamic(fn(this.store.require(item.id), this)) } as ListExpressionValue; + } + + listWidget(fn: (obj: EntityObject, harness: Harness) => unknown): ListWidgetValue { + return { get: (item: ObjectItem) => fn(this.store.require(item.id), this) } as ListWidgetValue; + } + + action(name: string, options: ActionOptions = {}): ActionValue { + return { + canExecute: options.canExecute ?? true, + isExecuting: false, + execute: (args?: unknown) => { + this.calls.push({ name, args }); + options.run?.(this, undefined, args); + this.bump(); + } + } as ActionValue; + } + + listAction(name: string, options: ActionOptions = {}): ListActionValue { + return { + get: (item: ObjectItem) => + ({ + canExecute: options.canExecute ?? true, + isExecuting: false, + execute: (args?: unknown) => { + this.calls.push({ name, item: item.id, args }); + options.run?.(this, item, args); + this.bump(); + } + }) as ActionValue + } as ListActionValue; + } + + editable(options: EditableOptions = {}): LiveEditable { + const editable = new LiveEditable(options); + editable.subscribe(() => this.bump()); + return editable; + } + + selectionSingle(): LiveSelection { + const selection = new LiveSelection("Single", undefined); + selection.subscribe(() => this.bump()); + return selection; + } + + selectionMulti(): LiveSelection { + const selection = new LiveSelection("Multi", []); + selection.subscribe(() => this.bump()); + return selection; + } + + private objectAttribute( + obj: EntityObject, + attr: string, + formatter: SimpleFormatter, + readOnly = false + ): EditableValue { + const value = obj.values[attr]; + return { + status: Available, + value, + displayValue: formatter.format(value), + validation: undefined, + readOnly, + formatter, + isList: false, + setFormatter: () => undefined, + setValidator: () => undefined, + setValue: (next: StoredValue) => { + if (!readOnly) { + this.store.update(obj.id, { [attr]: next }); + } + }, + setTextValue: (text: string) => { + const parsed = formatter.parse(text); + if (!readOnly && parsed.valid) { + this.store.update(obj.id, { [attr]: parsed.value }); + } + } + } as unknown as EditableValue; + } +} + +export class LiveEditable { + private readonly emitter = new Emitter(); + private validator: ((value: T | undefined) => string | undefined) | undefined; + private formatter: SimpleFormatter; + private current: T | undefined; + private validation: string | undefined; + private snapshot!: EditableValue; + readonly history: Array = []; + + constructor(private readonly options: EditableOptions) { + this.current = options.value; + this.formatter = options.formatter ?? { + format: v => (v === undefined ? "" : String(v)), + parse: text => ({ valid: true, value: text as T }) + }; + this.publish(); + } + + get value(): EditableValue { + return this.snapshot; + } + + subscribe = (listener: () => void): (() => void) => this.emitter.subscribe(listener); + + set(value: T | undefined): void { + this.current = value; + this.history.push(value); + this.validation = this.validator?.(value); + this.publish(); + } + + private publish(): void { + this.snapshot = { + status: Available, + value: this.current, + displayValue: this.formatter.format(this.current), + validation: this.validation, + readOnly: this.options.readOnly ?? false, + formatter: this.formatter, + universe: this.options.universe, + isList: false, + setValue: (value: T | undefined) => { + if (!this.options.readOnly) { + this.set(value); + } + }, + setTextValue: (text: string) => { + const parsed = this.formatter.parse(text); + if (parsed.valid) { + this.snapshot.setValue(parsed.value); + } else { + this.validation = `Invalid value "${text}"`; + this.publish(); + } + }, + setValidator: validator => { + this.validator = validator; + }, + setFormatter: formatter => { + this.formatter = formatter ?? this.formatter; + this.publish(); + } + } as EditableValue; + this.emitter.emit(); + } +} + +export class LiveSelection { + private readonly emitter = new Emitter(); + private snapshot!: V; + private current: T; + + constructor( + private readonly type: "Single" | "Multi", + initial: T + ) { + this.current = initial; + this.publish(); + } + + get value(): V { + return this.snapshot; + } + + get selection(): T { + return this.current; + } + + subscribe = (listener: () => void): (() => void) => this.emitter.subscribe(listener); + + private publish(): void { + this.snapshot = { + type: this.type, + selection: this.current, + setSelection: (value: T) => { + this.current = value; + this.publish(); + }, + setKeepSelection: () => undefined + } as V; + this.emitter.emit(); + } +} diff --git a/packages/shared/widget-harness/src/props/formatters.ts b/packages/shared/widget-harness/src/props/formatters.ts new file mode 100644 index 0000000000..5761961bb0 --- /dev/null +++ b/packages/shared/widget-harness/src/props/formatters.ts @@ -0,0 +1,61 @@ +import { Big } from "big.js"; +import type { ParseResult, SimpleFormatter } from "mendix"; +import { AttributeDef, attributeType, isNumeric } from "../store/schema.js"; + +function pad(n: number): string { + return String(n).padStart(2, "0"); +} + +/** Deterministic en-US style formatting, so tests don't depend on the machine locale. */ +export function formatterFor(def: AttributeDef): SimpleFormatter { + const type = attributeType(def); + const invalid: ParseResult = { valid: false }; + + if (isNumeric(type)) { + return { + format: (v?: Big) => (v === undefined ? "" : v.toString()), + parse: (text: string) => { + if (text.trim() === "") { + return { valid: true, value: undefined }; + } + try { + return { valid: true, value: new Big(text) }; + } catch { + return invalid; + } + } + }; + } + if (type === "DateTime") { + return { + format: (v?: Date) => + v === undefined + ? "" + : `${v.getMonth() + 1}/${v.getDate()}/${v.getFullYear()} ${pad(v.getHours())}:${pad(v.getMinutes())}`, + parse: (text: string) => { + const date = new Date(text); + return isNaN(date.getTime()) ? invalid : { valid: true, value: date }; + } + }; + } + if (type === "Boolean") { + return { + format: (v?: boolean) => (v === undefined ? "" : v ? "Yes" : "No"), + parse: (text: string) => ({ valid: true, value: text === "Yes" || text === "true" }) + }; + } + if (typeof def === "object") { + const captions = def.values; + return { + format: (v?: string) => (v === undefined ? "" : (captions[v] ?? v)), + parse: (text: string) => { + const key = Object.keys(captions).find(k => captions[k] === text || k === text); + return key === undefined ? invalid : { valid: true, value: key }; + } + }; + } + return { + format: (v?: string) => v ?? "", + parse: (text: string) => ({ valid: true, value: text }) + }; +} diff --git a/packages/shared/widget-harness/src/store/DataStore.ts b/packages/shared/widget-harness/src/store/DataStore.ts new file mode 100644 index 0000000000..0bbbbd949b --- /dev/null +++ b/packages/shared/widget-harness/src/store/DataStore.ts @@ -0,0 +1,141 @@ +import { Big } from "big.js"; +import type { GUID, ObjectItem } from "mendix"; +import { Emitter } from "./Emitter.js"; +import { attributeType, EntityObject, EntitySchema, isNumeric, MemberKind, Schema, StoredValue } from "./schema.js"; + +export type InputValue = StoredValue | number | string[] | null; +export type InputRecord = Record & { id?: string }; + +/** + * In-memory object store. Holds plain entity objects, hands out stable `ObjectItem`s + * and notifies subscribers after every mutation. + */ +export class DataStore { + private readonly objects = new Map(); + private readonly items = new Map(); + private readonly emitter = new Emitter(); + private nextId = 1; + private _version = 0; + + constructor( + public readonly schema: Schema, + data: Record = {} + ) { + for (const [entity, records] of Object.entries(data)) { + for (const record of records) { + this.put(entity, record); + } + } + } + + get version(): number { + return this._version; + } + + subscribe = (listener: () => void): (() => void) => this.emitter.subscribe(listener); + + entity(name: string): EntitySchema { + const entity = this.schema[name]; + if (!entity) { + throw new Error(`Unknown entity "${name}"`); + } + return entity; + } + + memberKind(entity: string, member: string): MemberKind { + const schema = this.entity(entity); + if (member in schema.attributes) { + return "attribute"; + } + const association = schema.associations?.[member]; + if (association) { + return association.type; + } + throw new Error(`Entity "${entity}" has no member "${member}"`); + } + + all(entity: string): EntityObject[] { + return [...this.objects.values()].filter(obj => obj.entity === entity); + } + + get(id: GUID): EntityObject | undefined { + return this.objects.get(id); + } + + require(id: GUID): EntityObject { + const obj = this.objects.get(id); + if (!obj) { + throw new Error(`Object "${id}" does not exist`); + } + return obj; + } + + item(id: GUID): ObjectItem { + let item = this.items.get(id); + if (!item) { + item = Object.freeze({ id }); + this.items.set(id, item); + } + return item; + } + + insert(entity: string, record: InputRecord): GUID { + const id = this.put(entity, record); + this.changed(); + return id; + } + + update(id: GUID, patch: Record): void { + const obj = this.require(id); + this.objects.set(id, { ...obj, values: { ...obj.values, ...this.normalize(obj.entity, patch) } }); + this.changed(); + } + + remove(id: GUID): void { + if (this.objects.delete(id)) { + this.changed(); + } + } + + private put(entity: string, record: InputRecord): GUID { + const { id: inputId, ...values } = record; + const id = (inputId ?? this.generateId()) as GUID; + if (this.objects.has(id)) { + throw new Error(`Duplicate object id "${id}"`); + } + this.objects.set(id, { id, entity, values: this.normalize(entity, values) }); + return id; + } + + private generateId(): string { + return String(this.nextId++).padStart(12, "0"); + } + + private normalize(entity: string, values: Record): Record { + const schema = this.entity(entity); + const result: Record = {}; + for (const [key, value] of Object.entries(values)) { + const kind = this.memberKind(entity, key); + if (value === null || value === undefined) { + result[key] = kind === "ReferenceSet" ? [] : undefined; + } else if (kind === "attribute") { + const type = attributeType(schema.attributes[key]); + if (isNumeric(type)) { + result[key] = new Big(value as number | string | Big); + } else if (type === "DateTime") { + result[key] = value instanceof Date ? value : new Date(value as string); + } else { + result[key] = value as StoredValue; + } + } else { + result[key] = value as GUID | GUID[]; + } + } + return result; + } + + private changed(): void { + this._version++; + this.emitter.emit(); + } +} diff --git a/packages/shared/widget-harness/src/store/Emitter.ts b/packages/shared/widget-harness/src/store/Emitter.ts new file mode 100644 index 0000000000..3ba6a3afdd --- /dev/null +++ b/packages/shared/widget-harness/src/store/Emitter.ts @@ -0,0 +1,16 @@ +export type Listener = () => void; + +export class Emitter { + private listeners = new Set(); + + subscribe = (listener: Listener): (() => void) => { + this.listeners.add(listener); + return () => this.listeners.delete(listener); + }; + + emit(): void { + for (const listener of [...this.listeners]) { + listener(); + } + } +} diff --git a/packages/shared/widget-harness/src/store/LiveList.ts b/packages/shared/widget-harness/src/store/LiveList.ts new file mode 100644 index 0000000000..23f46fc637 --- /dev/null +++ b/packages/shared/widget-harness/src/store/LiveList.ts @@ -0,0 +1,157 @@ +import type { ListValue, ObjectItem, ValueStatus } from "mendix"; +import type { FilterCondition } from "mendix/filters"; +import type { DataStore } from "./DataStore.js"; +import { Emitter } from "./Emitter.js"; +import { query, SortInstruction } from "./evaluate.js"; + +export interface LiveListOptions { + entity: string; + /** Fixed constraint of the data source (the XPath of a database source), combined with `setFilter`. */ + constraint?: FilterCondition; + /** Initial sort order, the data source's own sort setting. */ + sortOrder?: SortInstruction[]; + limit?: number; + /** Milliseconds between a request and the `available` result. */ + delay?: number; + /** Reload when the store changes, like a refresh-in-client. Defaults to `true`. */ + reloadOnStoreChange?: boolean; +} + +interface Params { + offset: number; + limit: number; + sortOrder: SortInstruction[]; + filter: FilterCondition | undefined; + needTotal: boolean; +} + +/** + * A data source over the store. `value` is an immutable `ListValue` snapshot; every change produces + * a new snapshot and notifies subscribers, the way the Mendix client hands widgets new props. + */ +export class LiveList { + private readonly emitter = new Emitter(); + private params: Params; + private status: ValueStatus = "loading" as ValueStatus; + private items: ObjectItem[] | undefined = undefined; + private totalCount: number | undefined = undefined; + private hasMoreItems: boolean | undefined = undefined; + private timer: ReturnType | undefined; + private snapshot: ListValue; + private readonly unsubscribeStore: () => void; + private readonly delay: number; + readonly requests: Array<{ kind: string; value: unknown }> = []; + + constructor( + private readonly store: DataStore, + private readonly options: LiveListOptions + ) { + store.entity(options.entity); + this.delay = options.delay ?? 0; + this.params = { + offset: 0, + limit: options.limit ?? Infinity, + sortOrder: options.sortOrder ?? [], + filter: undefined, + needTotal: false + }; + this.snapshot = this.createSnapshot(); + this.unsubscribeStore = + options.reloadOnStoreChange === false ? () => undefined : store.subscribe(() => this.request()); + this.schedule(); + } + + get value(): ListValue { + return this.snapshot; + } + + subscribe = (listener: () => void): (() => void) => this.emitter.subscribe(listener); + + /** Resolves once the list is `available` with no pending request. */ + settled(): Promise { + if (this.timer === undefined && this.status === "available") { + return Promise.resolve(); + } + return new Promise(resolve => { + const unsubscribe = this.subscribe(() => { + if (this.timer === undefined && this.status === "available") { + unsubscribe(); + resolve(); + } + }); + }); + } + + dispose(): void { + clearTimeout(this.timer); + this.unsubscribeStore(); + } + + private update(patch: Partial, kind: string, value: unknown): void { + this.requests.push({ kind, value }); + this.params = { ...this.params, ...patch }; + this.request(); + } + + private request(): void { + this.status = "loading" as ValueStatus; + this.publish(); + this.schedule(); + } + + private schedule(): void { + clearTimeout(this.timer); + this.timer = setTimeout(() => this.load(), this.delay); + } + + private load(): void { + this.timer = undefined; + const { offset, limit, sortOrder, filter, needTotal } = this.params; + const all = query(this.store, this.options.entity, [this.options.constraint, filter], sortOrder); + const page = all.slice(offset, limit === Infinity ? undefined : offset + limit); + this.items = page.map(obj => this.store.item(obj.id)); + this.hasMoreItems = offset + page.length < all.length; + this.totalCount = needTotal ? all.length : undefined; + this.status = "available" as ValueStatus; + this.publish(); + } + + private publish(): void { + this.snapshot = this.createSnapshot(); + this.emitter.emit(); + } + + private createSnapshot(): ListValue { + const { offset, limit, sortOrder, filter } = this.params; + return Object.freeze({ + status: this.status, + offset, + limit, + sortOrder: sortOrder as ListValue["sortOrder"], + filter, + items: this.items, + totalCount: this.totalCount, + hasMoreItems: this.hasMoreItems, + setOffset: (value: number) => { + if (value !== this.params.offset) { + this.update({ offset: value }, "setOffset", value); + } + }, + setLimit: (value: number | undefined) => { + const next = value ?? Infinity; + if (next !== this.params.limit) { + this.update({ limit: next }, "setLimit", value); + } + }, + requestTotalCount: (value: boolean) => { + if (value !== this.params.needTotal) { + this.update({ needTotal: value }, "requestTotalCount", value); + } + }, + setSortOrder: (value: ListValue["sortOrder"] | undefined) => + this.update({ sortOrder: (value ?? []) as SortInstruction[] }, "setSortOrder", value), + setFilter: (value: FilterCondition | undefined) => this.update({ filter: value }, "setFilter", value), + reload: () => this.update({}, "reload", undefined) + }) as ListValue; + } +} diff --git a/packages/shared/widget-harness/src/store/evaluate.ts b/packages/shared/widget-harness/src/store/evaluate.ts new file mode 100644 index 0000000000..9b7b789794 --- /dev/null +++ b/packages/shared/widget-harness/src/store/evaluate.ts @@ -0,0 +1,158 @@ +import { Big } from "big.js"; +import type { FilterCondition, FilterExpression } from "mendix/filters"; +import type { DataStore } from "./DataStore.js"; +import type { EntityObject, StoredValue } from "./schema.js"; + +type Expr = FilterExpression & Record; + +function resolve(expr: Expr, obj: EntityObject): StoredValue { + switch (expr.type) { + case "attribute": + return obj.values[expr.attributeId]; + case "association": + return obj.values[expr.associationId]; + case "literal": + return expr.value; + default: + throw new Error(`Unexpected expression type "${expr.type}" as a value`); + } +} + +function isEmpty(value: StoredValue): boolean { + return value === undefined || value === null || (Array.isArray(value) && value.length === 0); +} + +/** + * Three-way comparison. Strings compare case-insensitively, like XPath constraints in Mendix. + * Returns `undefined` when either side is empty, so ordering operators on empty values are false. + */ +export function compareValues(a: StoredValue, b: StoredValue): number | undefined { + if (isEmpty(a) || isEmpty(b)) { + return undefined; + } + if (a instanceof Big && b instanceof Big) { + return a.cmp(b); + } + if (a instanceof Date && b instanceof Date) { + return Math.sign(a.getTime() - b.getTime()); + } + if (typeof a === "string" && typeof b === "string") { + return a.toLowerCase().localeCompare(b.toLowerCase()); + } + if (typeof a === "boolean" && typeof b === "boolean") { + return Number(a) - Number(b); + } + throw new Error(`Cannot compare ${String(a)} with ${String(b)}`); +} + +function equalValues(a: StoredValue, b: StoredValue): boolean { + if (isEmpty(a) || isEmpty(b)) { + return isEmpty(a) && isEmpty(b); + } + if (Array.isArray(a) || Array.isArray(b)) { + const left = ([] as StoredValue[]).concat(a); + const right = ([] as StoredValue[]).concat(b); + return left.length === right.length && left.every(v => right.includes(v)); + } + return compareValues(a, b) === 0; +} + +function startOfDay(value: StoredValue): Date | undefined { + if (!(value instanceof Date)) { + return undefined; + } + return new Date(value.getFullYear(), value.getMonth(), value.getDate()); +} + +function stringTest(a: StoredValue, b: StoredValue, test: (a: string, b: string) => boolean): boolean { + if (Array.isArray(a)) { + return typeof b === "string" && a.includes(b as any); + } + if (isEmpty(a) || isEmpty(b)) { + return false; + } + return test(String(a).toLowerCase(), String(b).toLowerCase()); +} + +export function evaluateFilter(condition: FilterCondition, obj: EntityObject): boolean { + const c = condition as Expr; + switch (c.name) { + case "and": + return c.args.every((arg: FilterCondition) => evaluateFilter(arg, obj)); + case "or": + return c.args.some((arg: FilterCondition) => evaluateFilter(arg, obj)); + case "not": + return !evaluateFilter(c.arg, obj); + } + + const a = resolve(c.arg1, obj); + const b = resolve(c.arg2, obj); + const cmp = (): number | undefined => compareValues(a, b); + const dayCmp = (): number | undefined => compareValues(startOfDay(a), startOfDay(b)); + + switch (c.name) { + case "=": + return equalValues(a, b); + case "!=": + return !equalValues(a, b); + case ">": + return (cmp() ?? 0) > 0; + case ">=": + return (cmp() ?? -1) >= 0; + case "<": + return (cmp() ?? 0) < 0; + case "<=": + return (cmp() ?? 1) <= 0; + case "day:=": + return dayCmp() === 0; + case "day:!=": + return dayCmp() !== 0; + case "day:>": + return (dayCmp() ?? 0) > 0; + case "day:>=": + return (dayCmp() ?? -1) >= 0; + case "day:<": + return (dayCmp() ?? 0) < 0; + case "day:<=": + return (dayCmp() ?? 1) <= 0; + case "contains": + return stringTest(a, b, (x, y) => x.includes(y)); + case "starts-with": + return stringTest(a, b, (x, y) => x.startsWith(y)); + case "ends-with": + return stringTest(a, b, (x, y) => x.endsWith(y)); + default: + throw new Error(`Unsupported filter function "${c.name}"`); + } +} + +export type SortInstruction = [id: string, dir: "asc" | "desc"]; + +/** Empty values sort first in ascending order. Ties keep the store's insertion order. */ +export function sortObjects(objects: EntityObject[], sortOrder: readonly SortInstruction[]): EntityObject[] { + if (sortOrder.length === 0) { + return objects; + } + return [...objects].sort((x, y) => { + for (const [id, dir] of sortOrder) { + const a = x.values[id]; + const b = y.values[id]; + const result = isEmpty(a) ? (isEmpty(b) ? 0 : -1) : isEmpty(b) ? 1 : compareValues(a, b)!; + if (result !== 0) { + return dir === "asc" ? result : -result; + } + } + return 0; + }); +} + +export function query( + store: DataStore, + entity: string, + filters: Array, + sortOrder: readonly SortInstruction[] +): EntityObject[] { + const active = filters.filter((f): f is FilterCondition => f !== undefined); + const matching = store.all(entity).filter(obj => active.every(f => evaluateFilter(f, obj))); + return sortObjects(matching, sortOrder); +} diff --git a/packages/shared/widget-harness/src/store/schema.ts b/packages/shared/widget-harness/src/store/schema.ts new file mode 100644 index 0000000000..7148b0233d --- /dev/null +++ b/packages/shared/widget-harness/src/store/schema.ts @@ -0,0 +1,37 @@ +import type { Big } from "big.js"; +import type { GUID } from "mendix"; + +export type PrimitiveAttributeType = + "String" | "HashString" | "Integer" | "Long" | "Decimal" | "AutoNumber" | "Boolean" | "DateTime"; + +export type AttributeDef = PrimitiveAttributeType | { type: "Enum"; values: Record }; + +export interface AssociationDef { + type: "Reference" | "ReferenceSet"; + target: string; +} + +export interface EntitySchema { + attributes: Record; + associations?: Record; +} + +export type Schema = Record; + +export type StoredValue = string | boolean | Date | Big | GUID | GUID[] | undefined; + +export interface EntityObject { + readonly id: GUID; + readonly entity: string; + readonly values: Readonly>; +} + +export type MemberKind = "attribute" | "Reference" | "ReferenceSet"; + +export function attributeType(def: AttributeDef): PrimitiveAttributeType | "Enum" { + return typeof def === "string" ? def : def.type; +} + +export function isNumeric(type: string): boolean { + return type === "Integer" || type === "Long" || type === "Decimal" || type === "AutoNumber"; +} diff --git a/packages/shared/widget-harness/tsconfig.core.json b/packages/shared/widget-harness/tsconfig.core.json new file mode 100644 index 0000000000..bfe09f5748 --- /dev/null +++ b/packages/shared/widget-harness/tsconfig.core.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "include": ["./node_modules/mendix/index.d.ts", "./src/**/*", "./e2e/**/*", "./playwright.config.ts"] +} diff --git a/packages/shared/widget-harness/tsconfig.json b/packages/shared/widget-harness/tsconfig.json new file mode 100644 index 0000000000..efe5629264 --- /dev/null +++ b/packages/shared/widget-harness/tsconfig.json @@ -0,0 +1,18 @@ +{ + "extends": "@mendix/tsconfig-web-widgets/esm-library-with-jsx", + "include": [ + "./node_modules/mendix/index.d.ts", + "./src/**/*", + "./host/**/*", + "./e2e/**/*", + "./playwright.config.ts" + ], + "compilerOptions": { + "noEmit": true, + "jsx": "react-jsx", + "jsxFactory": "", + "moduleResolution": "bundler", + "module": "ESNext", + "types": ["react", "node"] + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e6693a5c2e..836df63fe2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2973,6 +2973,46 @@ importers: packages/shared/tsconfig-web-widgets: {} + packages/shared/widget-harness: + dependencies: + big.js: + specifier: ^6.2.2 + version: 6.2.2 + mendix: + specifier: 10.24.75382 + version: 10.24.75382 + devDependencies: + '@mendix/datagrid-text-filter-web': + specifier: workspace:* + version: link:../../pluggableWidgets/datagrid-text-filter-web + '@mendix/datagrid-web': + specifier: workspace:* + version: link:../../pluggableWidgets/datagrid-web + '@mendix/eslint-config-web-widgets': + specifier: workspace:* + version: link:../eslint-config-web-widgets + '@mendix/prettier-config-web-widgets': + specifier: workspace:* + version: link:../prettier-config-web-widgets + '@mendix/tsconfig-web-widgets': + specifier: workspace:* + version: link:../tsconfig-web-widgets + '@playwright/test': + specifier: ^1.60.0 + version: 1.62.0 + react: + specifier: '>=18.0.0 <19.0.0' + version: 18.3.1 + react-dom: + specifier: '>=18.0.0 <19.0.0' + version: 18.3.1(react@18.3.1) + sass: + specifier: 1.102.0 + version: 1.102.0 + vite: + specifier: 7.3.7 + version: 7.3.7(@types/node@26.6.6)(jiti@2.6.1)(sass@1.102.0)(terser@5.49.0) + packages/shared/widget-plugin-component-kit: devDependencies: '@mendix/eslint-config-web-widgets': @@ -4159,6 +4199,162 @@ packages: '@epic-web/invariant@1.0.0': resolution: {integrity: sha512-lrTPqgvfFQtR/eY/qkIzp98OGdNJu0m5ji3q/nJI8v3SXkRKEnWiOxMmbvcSoAIzv/cGiuvRy57k4suKQSAdwA==} + '@esbuild/aix-ppc64@0.28.2': + resolution: {integrity: sha512-XExcO+dvLKvVtNTibSTBej1NCAbaGhWn9Ww1ZPx80qsahhPFe/8jgWP0IchNe0F3HwkU7n8ejhH8bjonqht8mQ==} + engines: {node: '>=18'} + cpu: [ppc64] + os: [aix] + + '@esbuild/android-arm64@0.28.2': + resolution: {integrity: sha512-5YfKeeI8qWfBZIX+u2xZC3Zlb3Os/gLS2sbEKM+I4ZOcsWmHS2WLysCcQZDAFRslDUU5Oiq44gf6PYN1vGwG5A==} + engines: {node: '>=18'} + cpu: [arm64] + os: [android] + + '@esbuild/android-arm@0.28.2': + resolution: {integrity: sha512-kXXoiPVVGQcnIYGOeaovwOURpniDBpSq4A03qkQ+BMQqtGG6HYap3xne9C1O1yo4TR3qxlCX5IqqmX6fFo2Lqg==} + engines: {node: '>=18'} + cpu: [arm] + os: [android] + + '@esbuild/android-x64@0.28.2': + resolution: {integrity: sha512-O387ite7SzUyCcy3JQX4P4bLtEA7bLLkx+esve5JHnyYfNTxcVpXZo9jhdB0lTKN44gztELTdU7nS8Nr16Fs1Q==} + engines: {node: '>=18'} + cpu: [x64] + os: [android] + + '@esbuild/darwin-arm64@0.28.2': + resolution: {integrity: sha512-n4KqkOQrraxHJcgjM1RvwbigfQKIKJVpM7xp+KsxiyUSrRdIXnt73VhrPAx0fV44hgfmIVKjxMN9J1t5jySVkw==} + engines: {node: '>=18'} + cpu: [arm64] + os: [darwin] + + '@esbuild/darwin-x64@0.28.2': + resolution: {integrity: sha512-uq6suIWYP37qzGddBKPw5QEQPi6HiLGsO7UmkpfyaYNQ3D+rN6w6WfwH+nuqcGXWvawGwxOEroO4YGnFh95azw==} + engines: {node: '>=18'} + cpu: [x64] + os: [darwin] + + '@esbuild/freebsd-arm64@0.28.2': + resolution: {integrity: sha512-n+I0BTSRIoy+d6RPKnEVwql5UwBJolytvY4mAOIEJorKlqgPII8ix6slVVrfZ5Tnj7glIZvloylbB/EJPMWEXw==} + engines: {node: '>=18'} + cpu: [arm64] + os: [freebsd] + + '@esbuild/freebsd-x64@0.28.2': + resolution: {integrity: sha512-78XJTJkvPs0kz2w61301PJjXl4g7q3JqiYMZ/M/yVI73EHBrCRTgkhu9oqG7vPqq+a/yadEW8aD+agKlk5xrmg==} + engines: {node: '>=18'} + cpu: [x64] + os: [freebsd] + + '@esbuild/linux-arm64@0.28.2': + resolution: {integrity: sha512-pW4AC0P3it8c7do9MVM4p51FzHzdM/TZrerurgRcHJ2WTa1VQ1CIq18xncfpBJw4ojkiZZrKW2yIBWBP92j6Ug==} + engines: {node: '>=18'} + cpu: [arm64] + os: [linux] + + '@esbuild/linux-arm@0.28.2': + resolution: {integrity: sha512-XlDnu2q5yoqems+xay6wSAcg9DDD7K9RLKZEBOMZm3ckNpJBvOX20tSfby8KfrrhINDyv9V2YVZKY/SpoGJI8w==} + engines: {node: '>=18'} + cpu: [arm] + os: [linux] + + '@esbuild/linux-ia32@0.28.2': + resolution: {integrity: sha512-CYbnj78HsIeA+DhgUKgFCfvNsTHFhMMrinUrMZpDXJXKN8T3XViTZ/+wtHeVxEWY8ewSzTFN+nRmSwO2tZaLUQ==} + engines: {node: '>=18'} + cpu: [ia32] + os: [linux] + + '@esbuild/linux-loong64@0.28.2': + resolution: {integrity: sha512-buwkd8nsph4R+ajRvw0qM5Hja/TXQow3ptzWO2EbG/cqcIkHloRrdlBtQlshyYGTNFvfkfJ5tpPLVkY4DtsPfQ==} + engines: {node: '>=18'} + cpu: [loong64] + os: [linux] + + '@esbuild/linux-mips64el@0.28.2': + resolution: {integrity: sha512-ZVykbDyk7519VwiNb9Lcj9m8XM6v5V9uKPvrEMkkEedVewf+0itkhahp4HDpgERXhwLRpWFypsGbG/J8s0QjJA==} + engines: {node: '>=18'} + cpu: [mips64el] + os: [linux] + + '@esbuild/linux-ppc64@0.28.2': + resolution: {integrity: sha512-CAXl+Dtd9UUuJd8pKKdwh6MLm3MUMiqMPmhZ3tTSXPqfyQ3vDl6R5hZdZ/kYojK4ofXtdfSv1tFq8XzWx3heNQ==} + engines: {node: '>=18'} + cpu: [ppc64] + os: [linux] + + '@esbuild/linux-riscv64@0.28.2': + resolution: {integrity: sha512-GeXCej4IQtU1B+QlDV8W/RRvbzI3O/Stss+/bCXv4lZls5WGRtu2a+3JkA3i4qIUlMXpcHebWpF8AkJhATowuA==} + engines: {node: '>=18'} + cpu: [riscv64] + os: [linux] + + '@esbuild/linux-s390x@0.28.2': + resolution: {integrity: sha512-3H1weTYZPxt/WOhByszQZybS9w5lKzUn1FDMsgEChbHWQwHYQQRfBxgCcZvPhjHfKyJjIievvMmEUawJrdY9Dg==} + engines: {node: '>=18'} + cpu: [s390x] + os: [linux] + + '@esbuild/linux-x64@0.28.2': + resolution: {integrity: sha512-4xTZr1FUmSoQW4XIWmit3tzQrUTZM+N3P0XV8xROKYF50XfI7xeO90+1bZvNwxIufQ9hDQVRJH5YhgPVF8A/HQ==} + engines: {node: '>=18'} + cpu: [x64] + os: [linux] + + '@esbuild/netbsd-arm64@0.28.2': + resolution: {integrity: sha512-sSATRjPeDBg3pdgHoQfoYBob11Kk1FGa9lui5RIHZCoCkJa9QKlvl3/vKz2usCmYYjs7ymJR/2Nnsqe+Hjt5nw==} + engines: {node: '>=18'} + cpu: [arm64] + os: [netbsd] + + '@esbuild/netbsd-x64@0.28.2': + resolution: {integrity: sha512-lqnzCV+mM0gIADaKihiCg6ifgfU2L3h5E33rNQBN1Y4MaVGnzryzmvvf7UHxprpQdE8hpqLolJ9Rl+SkIRDpyw==} + engines: {node: '>=18'} + cpu: [x64] + os: [netbsd] + + '@esbuild/openbsd-arm64@0.28.2': + resolution: {integrity: sha512-AL2qJILH7lNjrDmCQDvdxMfAUIv8KMNZOvrwAQ8i8//ntL9FflhOyMJ8OZSMBb8/AWXe3/5v5S20y3zCoZWKoQ==} + engines: {node: '>=18'} + cpu: [arm64] + os: [openbsd] + + '@esbuild/openbsd-x64@0.28.2': + resolution: {integrity: sha512-QtiuPytchRyC4rwUKhexJdQKvDuZ6hWloi3igqPQNUJCS1/v9EiO3UTOXR6A3FoMo4fnAKbWJdqaIwhOzh8qEw==} + engines: {node: '>=18'} + cpu: [x64] + os: [openbsd] + + '@esbuild/openharmony-arm64@0.28.2': + resolution: {integrity: sha512-WkhYDmpTjLvGlScA1rwjRUmhl4k8oXR3cIbtqWmELgU/dFeHHlEllxDvdWcNJV9rbzCexB5vz8gtNewWLgCT7Q==} + engines: {node: '>=18'} + cpu: [arm64] + os: [openharmony] + + '@esbuild/sunos-x64@0.28.2': + resolution: {integrity: sha512-GPMSkTOtMnv2U2F8gxe4Io6qmVs+YKyp832Etqqxr0hFngmXQ3rzwytelm3GIn7T4VviRUlf3sOgBOiTdvaf7g==} + engines: {node: '>=18'} + cpu: [x64] + os: [sunos] + + '@esbuild/win32-arm64@0.28.2': + resolution: {integrity: sha512-PIhhEkE9uPBleRBrQEJpUn7MBnibZzbGzYWPmY3x+YoVg/95zbjB4CxPPOQ8l5tYYM4mMaCthF8/1DIfBQQyWQ==} + engines: {node: '>=18'} + cpu: [arm64] + os: [win32] + + '@esbuild/win32-ia32@0.28.2': + resolution: {integrity: sha512-YmJbfTlvU7Sdn9BB+4PRES4oB6pxgS37MAONj+hBr/cpXS1aBPKXxNnDbu+QCWPj0o9dgyxeq79g6c5P8KeuYA==} + engines: {node: '>=18'} + cpu: [ia32] + os: [win32] + + '@esbuild/win32-x64@0.28.2': + resolution: {integrity: sha512-5ebpxr3nWMzrL/rnUI755Jkuee0bHL/Gq0WTF9lvcpv73wAp5eu8MfBUgWK9bhWvZjj7yX8etf/8tI8Ney695g==} + engines: {node: '>=18'} + cpu: [x64] + os: [win32] + '@eslint-community/eslint-utils@4.10.1': resolution: {integrity: sha512-cuadcxVFE8sDK6iWJbs8Sn0av2Nrh2QSGQhVlBW9AaAHqHwjWsZHT8LJ4hFGPh7ASBV2deFdM7H/DPjulmh8rg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -7417,6 +7613,11 @@ packages: es6-weak-map@2.0.3: resolution: {integrity: sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA==} + esbuild@0.28.2: + resolution: {integrity: sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA==} + engines: {node: '>=18'} + hasBin: true + escalade@3.2.0: resolution: {integrity: sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==} engines: {node: '>=6'} @@ -10959,6 +11160,46 @@ packages: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'} + vite@7.3.7: + resolution: {integrity: sha512-AHEzTORMbi7/7aXp7w7KZ5+DCUdSeLsJz0grY8xHpc9DHdYb0vQu6DqJfm2tOw3gDExNgPgnJTXxM6syYFHaCA==} + engines: {node: ^20.19.0 || >=22.12.0} + hasBin: true + peerDependencies: + '@types/node': ~26.6.0 + jiti: '>=1.21.0' + less: ^4.0.0 + lightningcss: ^1.21.0 + sass: ^1.70.0 + sass-embedded: ^1.70.0 + stylus: '>=0.54.8' + sugarss: ^5.0.0 + terser: ^5.16.0 + tsx: ^4.8.1 + yaml: ^2.4.2 + peerDependenciesMeta: + '@types/node': + optional: true + jiti: + optional: true + less: + optional: true + lightningcss: + optional: true + sass: + optional: true + sass-embedded: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + tsx: + optional: true + yaml: + optional: true + vlq@0.2.3: resolution: {integrity: sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow==} @@ -12260,6 +12501,84 @@ snapshots: '@epic-web/invariant@1.0.0': {} + '@esbuild/aix-ppc64@0.28.2': + optional: true + + '@esbuild/android-arm64@0.28.2': + optional: true + + '@esbuild/android-arm@0.28.2': + optional: true + + '@esbuild/android-x64@0.28.2': + optional: true + + '@esbuild/darwin-arm64@0.28.2': + optional: true + + '@esbuild/darwin-x64@0.28.2': + optional: true + + '@esbuild/freebsd-arm64@0.28.2': + optional: true + + '@esbuild/freebsd-x64@0.28.2': + optional: true + + '@esbuild/linux-arm64@0.28.2': + optional: true + + '@esbuild/linux-arm@0.28.2': + optional: true + + '@esbuild/linux-ia32@0.28.2': + optional: true + + '@esbuild/linux-loong64@0.28.2': + optional: true + + '@esbuild/linux-mips64el@0.28.2': + optional: true + + '@esbuild/linux-ppc64@0.28.2': + optional: true + + '@esbuild/linux-riscv64@0.28.2': + optional: true + + '@esbuild/linux-s390x@0.28.2': + optional: true + + '@esbuild/linux-x64@0.28.2': + optional: true + + '@esbuild/netbsd-arm64@0.28.2': + optional: true + + '@esbuild/netbsd-x64@0.28.2': + optional: true + + '@esbuild/openbsd-arm64@0.28.2': + optional: true + + '@esbuild/openbsd-x64@0.28.2': + optional: true + + '@esbuild/openharmony-arm64@0.28.2': + optional: true + + '@esbuild/sunos-x64@0.28.2': + optional: true + + '@esbuild/win32-arm64@0.28.2': + optional: true + + '@esbuild/win32-ia32@0.28.2': + optional: true + + '@esbuild/win32-x64@0.28.2': + optional: true + '@eslint-community/eslint-utils@4.10.1(eslint@10.13.0(jiti@2.6.1))': dependencies: eslint: 10.13.0(jiti@2.6.1) @@ -15966,6 +16285,35 @@ snapshots: es6-iterator: 2.0.3 es6-symbol: 3.1.4 + esbuild@0.28.2: + optionalDependencies: + '@esbuild/aix-ppc64': 0.28.2 + '@esbuild/android-arm': 0.28.2 + '@esbuild/android-arm64': 0.28.2 + '@esbuild/android-x64': 0.28.2 + '@esbuild/darwin-arm64': 0.28.2 + '@esbuild/darwin-x64': 0.28.2 + '@esbuild/freebsd-arm64': 0.28.2 + '@esbuild/freebsd-x64': 0.28.2 + '@esbuild/linux-arm': 0.28.2 + '@esbuild/linux-arm64': 0.28.2 + '@esbuild/linux-ia32': 0.28.2 + '@esbuild/linux-loong64': 0.28.2 + '@esbuild/linux-mips64el': 0.28.2 + '@esbuild/linux-ppc64': 0.28.2 + '@esbuild/linux-riscv64': 0.28.2 + '@esbuild/linux-s390x': 0.28.2 + '@esbuild/linux-x64': 0.28.2 + '@esbuild/netbsd-arm64': 0.28.2 + '@esbuild/netbsd-x64': 0.28.2 + '@esbuild/openbsd-arm64': 0.28.2 + '@esbuild/openbsd-x64': 0.28.2 + '@esbuild/openharmony-arm64': 0.28.2 + '@esbuild/sunos-x64': 0.28.2 + '@esbuild/win32-arm64': 0.28.2 + '@esbuild/win32-ia32': 0.28.2 + '@esbuild/win32-x64': 0.28.2 + escalade@3.2.0: {} escape-html@1.0.3: {} @@ -20506,6 +20854,21 @@ snapshots: vary@1.1.2: {} + vite@7.3.7(@types/node@26.6.6)(jiti@2.6.1)(sass@1.102.0)(terser@5.49.0): + dependencies: + esbuild: 0.28.2 + fdir: 6.5.0(picomatch@4.0.5) + picomatch: 4.0.5 + postcss: 8.5.28 + rollup: 4.62.3 + tinyglobby: 0.2.17 + optionalDependencies: + '@types/node': 26.6.6 + fsevents: 2.3.3 + jiti: 2.6.1 + sass: 1.102.0 + terser: 5.49.0 + vlq@0.2.3: {} w3c-keyname@2.2.8: {}