diff --git a/packages/pluggable-widgets-tools/CHANGELOG.md b/packages/pluggable-widgets-tools/CHANGELOG.md index 16d89cdd..0dc92601 100644 --- a/packages/pluggable-widgets-tools/CHANGELOG.md +++ b/packages/pluggable-widgets-tools/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Added + +- We added support for [System texts](https://docs.mendix.com/refguide/system-texts/), introduced to Pluggable Widgets in Mendix 11.13. Texts [defined in the Widget's XML file](https://docs.mendix.com/apidocs-mxsdk/apidocs/pluggable-widgets-property-types/#text) are included in Studio Pro's System text editor. Texts can be defined with parameters and default translations or can be a reference to an external System text. + ## [11.12.0] - 2026-06-30 ### Changed diff --git a/packages/pluggable-widgets-tools/package.json b/packages/pluggable-widgets-tools/package.json index 8d83977c..1ac2098a 100644 --- a/packages/pluggable-widgets-tools/package.json +++ b/packages/pluggable-widgets-tools/package.json @@ -1,6 +1,6 @@ { "name": "@mendix/pluggable-widgets-tools", - "version": "11.12.0", + "version": "11.13.0", "description": "Mendix Pluggable Widgets Tools", "engines": { "node": ">=20" diff --git a/packages/pluggable-widgets-tools/src/common.ts b/packages/pluggable-widgets-tools/src/common.ts index 83bae0ef..450fbc59 100644 --- a/packages/pluggable-widgets-tools/src/common.ts +++ b/packages/pluggable-widgets-tools/src/common.ts @@ -1,4 +1,4 @@ -export function ensure(arg?: T, label: string = "argument"): T { +export function ensure(arg: T | undefined | null, label: string = "argument"): T { if (arg === null || arg === undefined) { throw new Error(`Did not expect ${label} to be ${arg}`); } diff --git a/packages/pluggable-widgets-tools/src/typings-generator/WidgetXml.ts b/packages/pluggable-widgets-tools/src/typings-generator/WidgetXml.ts index f6220ef6..5b4ebb6b 100644 --- a/packages/pluggable-widgets-tools/src/typings-generator/WidgetXml.ts +++ b/packages/pluggable-widgets-tools/src/typings-generator/WidgetXml.ts @@ -106,6 +106,56 @@ export interface SystemProperty { }; } +export interface TextSystemProperty { + $: { + key: "Text"; + }; + text: SystemText[]; + externalTexts: ExternalSystemTextNamespace[]; +} + +export interface SystemText { + $: { + key: string; + }; + caption: string; + translations: SystemTextTranslationCollection[]; + parameters: SystemTextParameterCollection[]; +} + +export interface SystemTextParameterCollection { + parameter: SystemTextParameter[]; +} + +export interface SystemTextTranslationCollection { + translation: SystemTextTranslation[]; +} + +export interface SystemTextTranslation { + $: { + lang: string; + }; +} + +export interface SystemTextParameter { + $: { + caption: string; + }; +} + +export interface ExternalSystemTextNamespace { + $: { + widgetId: string; + }; + text: ExternalSystemText[]; +} + +export interface ExternalSystemText { + $: { + key: string; + }; +} + export interface Enumeration { enumerationValue: EnumerationValue[]; } diff --git a/packages/pluggable-widgets-tools/src/typings-generator/__tests__/index.spec.ts b/packages/pluggable-widgets-tools/src/typings-generator/__tests__/index.spec.ts index f624b586..ea7bdb1b 100644 --- a/packages/pluggable-widgets-tools/src/typings-generator/__tests__/index.spec.ts +++ b/packages/pluggable-widgets-tools/src/typings-generator/__tests__/index.spec.ts @@ -55,6 +55,8 @@ import { singleObjectDatasourceNativeOutput, singleObjectDatasourceWebOutput } from "./outputs/single-object-datasource"; +import { systemTextsInput, systemTextsInputNative } from "./inputs/systemtexts"; +import { systemTextsNativeOutput, systemTextsOutput } from "./outputs/systemtexts"; describe("Generating tests", () => { it("Generates a parsed typing from XML for native", () => { @@ -266,6 +268,16 @@ describe("Generating tests", () => { const newContent = generateNativeTypesFor(singleObjectDatasourceInputNative); expect(newContent).toBe(singleObjectDatasourceNativeOutput); }); + + it("Generates a parsed typing from XML for web using system texts", () => { + const newContent = generateFullTypesFor(systemTextsInput); + expect(newContent).toBe(systemTextsOutput); + }); + + it("Generates a parsed typing from XML for native using system texts", () => { + const newContent = generateNativeTypesFor(systemTextsInputNative); + expect(newContent).toBe(systemTextsNativeOutput); + }); }); function generateFullTypesFor(xml: string) { diff --git a/packages/pluggable-widgets-tools/src/typings-generator/__tests__/inputs/systemtexts.ts b/packages/pluggable-widgets-tools/src/typings-generator/__tests__/inputs/systemtexts.ts new file mode 100644 index 00000000..42fb6b79 --- /dev/null +++ b/packages/pluggable-widgets-tools/src/typings-generator/__tests__/inputs/systemtexts.ts @@ -0,0 +1,46 @@ +const systemProperty = ` + + Photo + + Photo + Foto + + + + Photo Count + + {1} Photos + {1} Foto's + + + + + + + + + + +`; + +export const systemTextsInput = ` + + + + ${systemProperty} + + +`; + +export const systemTextsInputNative = ` + + + + ${systemProperty} + + +`; diff --git a/packages/pluggable-widgets-tools/src/typings-generator/__tests__/outputs/systemtexts.ts b/packages/pluggable-widgets-tools/src/typings-generator/__tests__/outputs/systemtexts.ts new file mode 100644 index 00000000..334142ec --- /dev/null +++ b/packages/pluggable-widgets-tools/src/typings-generator/__tests__/outputs/systemtexts.ts @@ -0,0 +1,45 @@ +export const systemTextsOutput = `/** + * This file was generated from MyWidget.xml + * WARNING: All changes made to this file will be overwritten + * @author Mendix Widgets Framework Team + */ +import { CSSProperties } from "react"; + +export interface Translations { + "photo": []; + "photo_count": [params: [count: string]]; + "mendix.textbox.TextBox": [key: "label" | "placeholder", params?: string[]] + "mendix.datagrid.DataGrid": [key: string, params?: string[]] +} + +export interface MyWidgetContainerProps { + name: string; + class: string; + style?: CSSProperties; + tabIndex?: number; + texts: { + translate: (key: K, ...params: Translations[K]) => string + } +} + +export interface MyWidgetPreviewProps { + /** + * @deprecated Deprecated since version 9.18.0. Please use class property instead. + */ + className: string; + class: string; + style: string; + styleObject?: CSSProperties; + readOnly: boolean; + renderMode: "design" | "xray" | "structure"; + translate: (text: string) => string; +} +`; + +export const systemTextsNativeOutput = `export interface MyWidgetProps