diff --git a/packages/ts-interface-generator/src/test/interfaceGenerationHelper.test.ts b/packages/ts-interface-generator/src/test/interfaceGenerationHelper.test.ts index ecb3c47..39d122d 100644 --- a/packages/ts-interface-generator/src/test/interfaceGenerationHelper.test.ts +++ b/packages/ts-interface-generator/src/test/interfaceGenerationHelper.test.ts @@ -86,6 +86,11 @@ declare module "./SampleControl" { */ alsoLabelledBy?: Control | string | (Control | string)[]; + /** + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + */ + singlePress?: (event: SampleControl$SinglePressEvent) => void; + /** * Fired when double-clicked. */ @@ -338,6 +343,62 @@ declare module "./SampleControl" { */ removeAllAlsoLabelledBy(): string[]; + // event: singlePress + + /** + * Attaches event handler "fn" to the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachSinglePress(fn: (event: SampleControl$SinglePressEvent) => void, listener?: object): this; + + /** + * Attaches event handler "fn" to the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param data An application-specific payload object that will be passed to the event handler along with the event object when firing the event + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachSinglePress(data: CustomDataType, fn: (event: SampleControl$SinglePressEvent, data: CustomDataType) => void, listener?: object): this; + + /** + * Detaches event handler "fn" from the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * The passed function and listener object must match the ones used for event registration. + * + * @param fn The function to be called, when the event occurs + * @param listener Context object on which the given function had to be called + * @returns Reference to "this" in order to allow method chaining + */ + detachSinglePress(fn: (event: SampleControl$SinglePressEvent) => void, listener?: object): this; + + /** + * Fires event "singlePress" to attached listeners. + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * @param parameters Parameters to pass along with the event + * @returns Reference to "this" in order to allow method chaining + */ + fireSinglePress(parameters?: SampleControl$SinglePressEventParameters): this; + // event: doublePress /** @@ -393,19 +454,35 @@ declare module "./SampleControl" { * The return value of this method indicates whether the default action should be executed. * * @param parameters Parameters to pass along with the event + * @param [mParameters.delay] Fired when double-clicked. + * * @returns Whether or not to prevent the default action */ fireDoublePress(parameters?: SampleControl$DoublePressEventParameters): boolean; } + /** + * Interface describing the parameters of SampleControl's 'singlePress' event. + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + */ + // eslint-disable-next-line + export interface SampleControl$SinglePressEventParameters { + } + /** * Interface describing the parameters of SampleControl's 'doublePress' event. * Fired when double-clicked. */ - // eslint-disable-next-line export interface SampleControl$DoublePressEventParameters { + delay?: number; } + /** + * Type describing the SampleControl's 'singlePress' event. + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + */ + export type SampleControl$SinglePressEvent = Event; + /** * Type describing the SampleControl's 'doublePress' event. * Fired when double-clicked. @@ -661,6 +738,62 @@ declare module "./SampleControl" { */ removeAllAlsoLabelledBy(): string[]; + // event: singlePress + + /** + * Attaches event handler "fn" to the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachSinglePress(fn: (event: SampleControl$SinglePressEvent) => void, listener?: object): this; + + /** + * Attaches event handler "fn" to the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param data An application-specific payload object that will be passed to the event handler along with the event object when firing the event + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachSinglePress(data: CustomDataType, fn: (event: SampleControl$SinglePressEvent, data: CustomDataType) => void, listener?: object): this; + + /** + * Detaches event handler "fn" from the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * The passed function and listener object must match the ones used for event registration. + * + * @param fn The function to be called, when the event occurs + * @param listener Context object on which the given function had to be called + * @returns Reference to "this" in order to allow method chaining + */ + detachSinglePress(fn: (event: SampleControl$SinglePressEvent) => void, listener?: object): this; + + /** + * Fires event "singlePress" to attached listeners. + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * @param parameters Parameters to pass along with the event + * @returns Reference to "this" in order to allow method chaining + */ + fireSinglePress(parameters?: SampleControl$SinglePressEventParameters): this; + // event: doublePress /** @@ -716,6 +849,8 @@ declare module "./SampleControl" { * The return value of this method indicates whether the default action should be executed. * * @param parameters Parameters to pass along with the event + * @param [mParameters.delay] Fired when double-clicked. + * * @returns Whether or not to prevent the default action */ fireDoublePress(parameters?: SampleControl$DoublePressEventParameters): boolean; diff --git a/packages/ts-interface-generator/src/test/samples/sampleControl/SampleControl.gen.d.ts b/packages/ts-interface-generator/src/test/samples/sampleControl/SampleControl.gen.d.ts index 1185e1a..3139b4d 100644 --- a/packages/ts-interface-generator/src/test/samples/sampleControl/SampleControl.gen.d.ts +++ b/packages/ts-interface-generator/src/test/samples/sampleControl/SampleControl.gen.d.ts @@ -40,6 +40,11 @@ declare module "./SampleControl" { */ alsoLabelledBy?: Control | string | (Control | string)[]; + /** + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + */ + singlePress?: (event: SampleControl$SinglePressEvent) => void; + /** * Fired when double-clicked. */ @@ -292,6 +297,62 @@ declare module "./SampleControl" { */ removeAllAlsoLabelledBy(): string[]; + // event: singlePress + + /** + * Attaches event handler "fn" to the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachSinglePress(fn: (event: SampleControl$SinglePressEvent) => void, listener?: object): this; + + /** + * Attaches event handler "fn" to the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param data An application-specific payload object that will be passed to the event handler along with the event object when firing the event + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachSinglePress(data: CustomDataType, fn: (event: SampleControl$SinglePressEvent, data: CustomDataType) => void, listener?: object): this; + + /** + * Detaches event handler "fn" from the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * The passed function and listener object must match the ones used for event registration. + * + * @param fn The function to be called, when the event occurs + * @param listener Context object on which the given function had to be called + * @returns Reference to "this" in order to allow method chaining + */ + detachSinglePress(fn: (event: SampleControl$SinglePressEvent) => void, listener?: object): this; + + /** + * Fires event "singlePress" to attached listeners. + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * @param parameters Parameters to pass along with the event + * @returns Reference to "this" in order to allow method chaining + */ + fireSinglePress(parameters?: SampleControl$SinglePressEventParameters): this; + // event: doublePress /** @@ -347,19 +408,35 @@ declare module "./SampleControl" { * The return value of this method indicates whether the default action should be executed. * * @param parameters Parameters to pass along with the event + * @param [mParameters.delay] Fired when double-clicked. + * * @returns Whether or not to prevent the default action */ fireDoublePress(parameters?: SampleControl$DoublePressEventParameters): boolean; } + /** + * Interface describing the parameters of SampleControl's 'singlePress' event. + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + */ + // eslint-disable-next-line + export interface SampleControl$SinglePressEventParameters { + } + /** * Interface describing the parameters of SampleControl's 'doublePress' event. * Fired when double-clicked. */ - // eslint-disable-next-line export interface SampleControl$DoublePressEventParameters { + delay?: number; } + /** + * Type describing the SampleControl's 'singlePress' event. + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + */ + export type SampleControl$SinglePressEvent = Event; + /** * Type describing the SampleControl's 'doublePress' event. * Fired when double-clicked. @@ -615,6 +692,62 @@ declare module "./SampleControl" { */ removeAllAlsoLabelledBy(): string[]; + // event: singlePress + + /** + * Attaches event handler "fn" to the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachSinglePress(fn: (event: SampleControl$SinglePressEvent) => void, listener?: object): this; + + /** + * Attaches event handler "fn" to the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param data An application-specific payload object that will be passed to the event handler along with the event object when firing the event + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachSinglePress(data: CustomDataType, fn: (event: SampleControl$SinglePressEvent, data: CustomDataType) => void, listener?: object): this; + + /** + * Detaches event handler "fn" from the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * The passed function and listener object must match the ones used for event registration. + * + * @param fn The function to be called, when the event occurs + * @param listener Context object on which the given function had to be called + * @returns Reference to "this" in order to allow method chaining + */ + detachSinglePress(fn: (event: SampleControl$SinglePressEvent) => void, listener?: object): this; + + /** + * Fires event "singlePress" to attached listeners. + * + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + * + * @param parameters Parameters to pass along with the event + * @returns Reference to "this" in order to allow method chaining + */ + fireSinglePress(parameters?: SampleControl$SinglePressEventParameters): this; + // event: doublePress /** @@ -670,6 +803,8 @@ declare module "./SampleControl" { * The return value of this method indicates whether the default action should be executed. * * @param parameters Parameters to pass along with the event + * @param [mParameters.delay] Fired when double-clicked. + * * @returns Whether or not to prevent the default action */ fireDoublePress(parameters?: SampleControl$DoublePressEventParameters): boolean; diff --git a/packages/ts-interface-generator/src/test/samples/sampleControl/SampleControl.ts b/packages/ts-interface-generator/src/test/samples/sampleControl/SampleControl.ts index 1af77fa..d0b830d 100644 --- a/packages/ts-interface-generator/src/test/samples/sampleControl/SampleControl.ts +++ b/packages/ts-interface-generator/src/test/samples/sampleControl/SampleControl.ts @@ -46,10 +46,22 @@ export default class SampleControl extends Button { alsoLabelledBy: { type: "sap.ui.core.Control", multiple: true }, }, events: { + /** + * Fired when single-clicked. This event has no parameters, which requires an eslint-disable in the generated code. + */ + singlePress: {}, /** * Fired when double-clicked. */ - doublePress: { allowPreventDefault: true }, + doublePress: { + allowPreventDefault: true, + parameters: { + /** + * The amount of milliseconds between the first and second press + */ + delay: { type: "int" } + } + } }, }; @@ -72,6 +84,8 @@ export default class SampleControl extends Button { }; doit() { + this.fireSinglePress(); + this.fireDoublePress({ delay: 100 }); alert("Hello"); } } diff --git a/packages/ts-interface-generator/src/test/samples/sampleWebComponent/SampleWebComponent.gen.d.ts b/packages/ts-interface-generator/src/test/samples/sampleWebComponent/SampleWebComponent.gen.d.ts index ed4bf70..5686867 100644 --- a/packages/ts-interface-generator/src/test/samples/sampleWebComponent/SampleWebComponent.gen.d.ts +++ b/packages/ts-interface-generator/src/test/samples/sampleWebComponent/SampleWebComponent.gen.d.ts @@ -12,7 +12,7 @@ declare module "./SampleWebComponent" { /** * Interface defining the settings object used in constructor calls */ - interface $SampleWebComponentSettings extends $WebComponentSettings { + interface $SampleWebComp onentSettings extends $WebComponentSettings { /** * The text that appears below the main text. diff --git a/packages/ts-interface-generator/src/test/testcases/instance-exported/MyControl.gen.d.ts b/packages/ts-interface-generator/src/test/testcases/instance-exported/MyControl.gen.d.ts index 39835b1..3b505d6 100644 --- a/packages/ts-interface-generator/src/test/testcases/instance-exported/MyControl.gen.d.ts +++ b/packages/ts-interface-generator/src/test/testcases/instance-exported/MyControl.gen.d.ts @@ -7,12 +7,6 @@ declare module "./MyControl" { * Interface defining the settings object used in constructor calls */ interface $MyControlSettings extends $ControlSettings { - - /** - * The text. - * - * @since 1.0 - */ text?: string | PropertyBindingInfo; } @@ -23,10 +17,6 @@ declare module "./MyControl" { /** * Gets current value of property "text". * - * The text. - * - * @since 1.0 - * * @returns Value of property "text" */ getText(): string; @@ -34,9 +24,6 @@ declare module "./MyControl" { /** * Sets a new value for property "text". * - * The text. - * - * @since 1.0 * When called with a value of "null" or "undefined", the default value of the property will be restored. * * @param text New value for property "text" diff --git a/packages/ts-interface-generator/src/test/testcases/instance-exported/MyControl.ts b/packages/ts-interface-generator/src/test/testcases/instance-exported/MyControl.ts index 80b0ed8..7672219 100644 --- a/packages/ts-interface-generator/src/test/testcases/instance-exported/MyControl.ts +++ b/packages/ts-interface-generator/src/test/testcases/instance-exported/MyControl.ts @@ -3,17 +3,11 @@ import { MetadataOptions } from "sap/ui/core/Element"; import RenderManager from "sap/ui/core/RenderManager"; /** - * This is my control. - * * @namespace my */ export class MyControl extends Control { static readonly metadata: MetadataOptions = { properties: { - /** - * The text. - * @since 1.0 - */ text: "string", }, }; diff --git a/packages/ts-interface-generator/src/test/testcases/separate-export/MyControl.gen.d.ts b/packages/ts-interface-generator/src/test/testcases/separate-export/MyControl.gen.d.ts new file mode 100644 index 0000000..d3b6a45 --- /dev/null +++ b/packages/ts-interface-generator/src/test/testcases/separate-export/MyControl.gen.d.ts @@ -0,0 +1,34 @@ +import { PropertyBindingInfo } from "sap/ui/base/ManagedObject"; +import { $ControlSettings } from "sap/ui/core/Control"; + +declare module "./MyControl" { + + /** + * Interface defining the settings object used in constructor calls + */ + interface $MyControlSettings extends $ControlSettings { + text?: string | PropertyBindingInfo; + } + + export default interface MyControl { + + // property: text + + /** + * Gets current value of property "text". + * + * @returns Value of property "text" + */ + getText(): string; + + /** + * Sets a new value for property "text". + * + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * @param text New value for property "text" + * @returns Reference to "this" in order to allow method chaining + */ + setText(text: string): this; + } +} diff --git a/packages/ts-interface-generator/src/test/testcases/separate-export/MyControl.ts b/packages/ts-interface-generator/src/test/testcases/separate-export/MyControl.ts new file mode 100644 index 0000000..92455b9 --- /dev/null +++ b/packages/ts-interface-generator/src/test/testcases/separate-export/MyControl.ts @@ -0,0 +1,27 @@ +import Control from "sap/ui/core/Control"; +import { MetadataOptions } from "sap/ui/core/Element"; +import RenderManager from "sap/ui/core/RenderManager"; + +/** + * @namespace my + */ +class MyControl extends Control { + static readonly metadata: MetadataOptions = { + properties: { + text: "string", + }, + }; + + static renderer = { + apiVersion: 2, + render: function (rm: RenderManager, control: MyControl) { + rm.openStart("div", control); + rm.openEnd(); + // @ts-ignore this only works with the generated interface + rm.text(control.getText()); + rm.close("div"); + }, + }; +} + +export default MyControl; \ No newline at end of file diff --git a/packages/ts-interface-generator/src/test/testcases/simple-control/MyControl.gen.d.ts b/packages/ts-interface-generator/src/test/testcases/simple-control/MyControl.gen.d.ts index 0b468e2..d3b6a45 100644 --- a/packages/ts-interface-generator/src/test/testcases/simple-control/MyControl.gen.d.ts +++ b/packages/ts-interface-generator/src/test/testcases/simple-control/MyControl.gen.d.ts @@ -7,12 +7,6 @@ declare module "./MyControl" { * Interface defining the settings object used in constructor calls */ interface $MyControlSettings extends $ControlSettings { - - /** - * The text. - * - * @since 1.0 - */ text?: string | PropertyBindingInfo; } @@ -23,10 +17,6 @@ declare module "./MyControl" { /** * Gets current value of property "text". * - * The text. - * - * @since 1.0 - * * @returns Value of property "text" */ getText(): string; @@ -34,9 +24,6 @@ declare module "./MyControl" { /** * Sets a new value for property "text". * - * The text. - * - * @since 1.0 * When called with a value of "null" or "undefined", the default value of the property will be restored. * * @param text New value for property "text" diff --git a/packages/ts-interface-generator/src/test/testcases/simple-control/MyControl.ts b/packages/ts-interface-generator/src/test/testcases/simple-control/MyControl.ts index 4222d0d..ae2e29e 100644 --- a/packages/ts-interface-generator/src/test/testcases/simple-control/MyControl.ts +++ b/packages/ts-interface-generator/src/test/testcases/simple-control/MyControl.ts @@ -3,17 +3,11 @@ import { MetadataOptions } from "sap/ui/core/Element"; import RenderManager from "sap/ui/core/RenderManager"; /** - * This is my control. - * * @namespace my */ export default class MyControl extends Control { static readonly metadata: MetadataOptions = { properties: { - /** - * The text. - * @since 1.0 - */ text: "string", }, }; diff --git a/packages/ts-interface-generator/src/test/testcases/web-component/SampleWebComponent.gen.d.ts b/packages/ts-interface-generator/src/test/testcases/web-component/SampleWebComponent.gen.d.ts new file mode 100644 index 0000000..ed4bf70 --- /dev/null +++ b/packages/ts-interface-generator/src/test/testcases/web-component/SampleWebComponent.gen.d.ts @@ -0,0 +1,729 @@ +import Event from "sap/ui/base/Event"; +import { CSSColor } from "sap/ui/core/library"; +import Control from "sap/ui/core/Control"; +import { AggregationBindingInfo } from "sap/ui/base/ManagedObject"; +import WebComponent from "sap/ui/core/webc/WebComponent"; +import TooltipBase from "sap/ui/core/TooltipBase"; +import { PropertyBindingInfo } from "sap/ui/base/ManagedObject"; +import { $WebComponentSettings } from "sap/ui/core/webc/WebComponent"; + +declare module "./SampleWebComponent" { + + /** + * Interface defining the settings object used in constructor calls + */ + interface $SampleWebComponentSettings extends $WebComponentSettings { + + /** + * The text that appears below the main text. + * + * @since 1.0 + */ + subtext?: string | PropertyBindingInfo; + + /** + * Determines the text color of the SampleWebComponent. + * + * @experimental + */ + textColor?: CSSColor | PropertyBindingInfo | `{${string}}`; + + /** + * Usage of mapping + */ + text?: string | PropertyBindingInfo; + + /** + * Determines the content of the SampleWebComponent. + */ + content?: Control[] | Control | AggregationBindingInfo | `{${string}}`; + header?: WebComponent; + tooltip?: TooltipBase | string | PropertyBindingInfo; + partnerControl?: SampleWebComponent | string; + + /** + * This is an association. + */ + alsoLabelledBy?: Control | string | (Control | string)[]; + + /** + * Fired when double-clicked. + */ + doublePress?: (event: SampleWebComponent$DoublePressEvent) => void; + } + + export default interface SampleWebComponent { + + // property: subtext + + /** + * Gets current value of property "subtext". + * + * The text that appears below the main text. + * + * @since 1.0 + * + * @returns Value of property "subtext" + */ + getSubtext(): string; + + /** + * Sets a new value for property "subtext". + * + * The text that appears below the main text. + * + * @since 1.0 + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * @param subtext New value for property "subtext" + * @returns Reference to "this" in order to allow method chaining + */ + setSubtext(subtext: string): this; + + // property: textColor + + /** + * Gets current value of property "textColor". + * + * Determines the text color of the SampleWebComponent. + * + * @experimental + * Default value is: "" + * @returns Value of property "textColor" + */ + getTextColor(): CSSColor; + + /** + * Sets a new value for property "textColor". + * + * Determines the text color of the SampleWebComponent. + * + * @experimental + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * Default value is: "" + * @param [textColor=""] New value for property "textColor" + * @returns Reference to "this" in order to allow method chaining + */ + setTextColor(textColor: CSSColor): this; + + // property: text + + /** + * Gets current value of property "text". + * + * Usage of mapping + * + * @returns Value of property "text" + */ + getText(): string; + + /** + * Sets a new value for property "text". + * + * Usage of mapping + * + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * @param text New value for property "text" + * @returns Reference to "this" in order to allow method chaining + */ + setText(text: string): this; + + // aggregation: content + + /** + * Gets content of aggregation "content". + * + * Determines the content of the SampleWebComponent. + */ + getContent(): Control[]; + + /** + * Adds some content to the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @param content The content to add; if empty, nothing is inserted + * @returns Reference to "this" in order to allow method chaining + */ + addContent(content: Control): this; + + /** + * Inserts a content into the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @param content The content to insert; if empty, nothing is inserted + * @param index The "0"-based index the content should be inserted at; for + * a negative value of "iIndex", the content is inserted at position 0; for a value + * greater than the current size of the aggregation, the content is inserted at + * the last position + * @returns Reference to "this" in order to allow method chaining + */ + insertContent(content: Control, index: number): this; + + /** + * Removes a content from the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @param content The content to remove or its index or id + * @returns The removed content or "null" + */ + removeContent(content: number | string | Control): Control | null; + + /** + * Removes all the controls from the aggregation "content". + * Additionally, it unregisters them from the hosting UIArea. + * + * Determines the content of the SampleWebComponent. + * + * @returns An array of the removed elements (might be empty) + */ + removeAllContent(): Control[]; + + /** + * Checks for the provided "sap.ui.core.Control" in the aggregation "content". + * and returns its index if found or -1 otherwise. + * + * Determines the content of the SampleWebComponent. + * + * @param content The content whose index is looked for + * @returns The index of the provided control in the aggregation if found, or -1 otherwise + */ + indexOfContent(content: Control): number; + + /** + * Destroys all the content in the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyContent(): this; + + /** + * Binds aggregation "content" to model data. + * + * Determines the content of the SampleWebComponent. + * + * See {@link sap.ui.base.ManagedObject#bindAggregation ManagedObject.bindAggregation} for a + * detailed description of the possible properties of "oBindingInfo". + * @param oBindingInfo The binding information + * @returns Reference to "this" in order to allow method chaining + */ + bindContent(bindingInfo: AggregationBindingInfo): this; + + /** + * Unbinds aggregation "content" from model data. + * + * Determines the content of the SampleWebComponent. + * + * @returns Reference to "this" in order to allow method chaining + */ + unbindContent(): this; + + // aggregation: header + + /** + * Gets content of aggregation "header". + */ + getHeader(): WebComponent; + + /** + * Sets the aggregated header. + * + * @param header The header to set + * @returns Reference to "this" in order to allow method chaining + */ + setHeader(header: WebComponent): this; + + /** + * Destroys the header in the aggregation "header". + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyHeader(): this; + + // aggregation: tooltip + + /** + * Gets content of aggregation "tooltip". + */ + getTooltip(): TooltipBase; + + /** + * Sets the aggregated tooltip. + * + * @param tooltip The tooltip to set + * @returns Reference to "this" in order to allow method chaining + */ + setTooltip(tooltip: TooltipBase): this; + + /** + * Destroys the tooltip in the aggregation "tooltip". + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyTooltip(): this; + + // association: partnerControl + + /** + * ID of the element which is the current target of the association "partnerControl", or "null". + */ + getPartnerControl(): string; + + /** + * Sets the associated partnerControl. + * + * @param partnerControl ID of an element which becomes the new target of this "partnerControl" association; alternatively, an element instance may be given + * @returns Reference to "this" in order to allow method chaining + */ + setPartnerControl(partnerControl?: string | SampleWebComponent): this; + + // association: alsoLabelledBy + + /** + * Returns array of IDs of the elements which are the current targets of the association "alsoLabelledBy". + * + * This is an association. + */ + getAlsoLabelledBy(): string[]; + + /** + * Adds some alsoLabelledBy into the association "alsoLabelledBy". + * + * This is an association. + * + * @param alsoLabelledBy The alsoLabelledBy to add; if empty, nothing is inserted + * @returns Reference to "this" in order to allow method chaining + */ + addAlsoLabelledBy(alsoLabelledBy: string | Control): this; + + /** + * Removes an alsoLabelledBy from the association named alsoLabelledBy. + * + * This is an association. + * + * @param alsoLabelledBy The alsoLabelledBy to be removed or its index or ID + * @returns The removed alsoLabelledBy or "null" + */ + removeAlsoLabelledBy(alsoLabelledBy: number | string | Control): string; + + /** + * Removes all the controls in the association named alsoLabelledBy. + * + * This is an association. + * + * @returns An array of the removed elements (might be empty) + */ + removeAllAlsoLabelledBy(): string[]; + + // event: doublePress + + /** + * Attaches event handler "fn" to the "doublePress" event of this "SampleWebComponent". + * + * Fired when double-clicked. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleWebComponent" itself. + * + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleWebComponent" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachDoublePress(fn: (event: SampleWebComponent$DoublePressEvent) => void, listener?: object): this; + + /** + * Attaches event handler "fn" to the "doublePress" event of this "SampleWebComponent". + * + * Fired when double-clicked. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleWebComponent" itself. + * + * @param data An application-specific payload object that will be passed to the event handler along with the event object when firing the event + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleWebComponent" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachDoublePress(data: CustomDataType, fn: (event: SampleWebComponent$DoublePressEvent, data: CustomDataType) => void, listener?: object): this; + + /** + * Detaches event handler "fn" from the "doublePress" event of this "SampleWebComponent". + * + * Fired when double-clicked. + * + * The passed function and listener object must match the ones used for event registration. + * + * @param fn The function to be called, when the event occurs + * @param listener Context object on which the given function had to be called + * @returns Reference to "this" in order to allow method chaining + */ + detachDoublePress(fn: (event: SampleWebComponent$DoublePressEvent) => void, listener?: object): this; + + /** + * Fires event "doublePress" to attached listeners. + * + * Fired when double-clicked. + * + * Listeners may prevent the default action of this event by calling the "preventDefault" method on the event object. + * The return value of this method indicates whether the default action should be executed. + * + * @param parameters Parameters to pass along with the event + * @returns Whether or not to prevent the default action + */ + fireDoublePress(parameters?: SampleWebComponent$DoublePressEventParameters): boolean; + } + + /** + * Interface describing the parameters of SampleWebComponent's 'doublePress' event. + * Fired when double-clicked. + */ + // eslint-disable-next-line + export interface SampleWebComponent$DoublePressEventParameters { + } + + /** + * Type describing the SampleWebComponent's 'doublePress' event. + * Fired when double-clicked. + */ + export type SampleWebComponent$DoublePressEvent = Event; +} + +// this duplicate interface without export is needed to avoid "Cannot find name 'SampleWebComponent'" TypeScript errors above +declare module "./SampleWebComponent" { + interface SampleWebComponent { + + // property: subtext + + /** + * Gets current value of property "subtext". + * + * The text that appears below the main text. + * + * @since 1.0 + * + * @returns Value of property "subtext" + */ + getSubtext(): string; + + /** + * Sets a new value for property "subtext". + * + * The text that appears below the main text. + * + * @since 1.0 + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * @param subtext New value for property "subtext" + * @returns Reference to "this" in order to allow method chaining + */ + setSubtext(subtext: string): this; + + // property: textColor + + /** + * Gets current value of property "textColor". + * + * Determines the text color of the SampleWebComponent. + * + * @experimental + * Default value is: "" + * @returns Value of property "textColor" + */ + getTextColor(): CSSColor; + + /** + * Sets a new value for property "textColor". + * + * Determines the text color of the SampleWebComponent. + * + * @experimental + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * Default value is: "" + * @param [textColor=""] New value for property "textColor" + * @returns Reference to "this" in order to allow method chaining + */ + setTextColor(textColor: CSSColor): this; + + // property: text + + /** + * Gets current value of property "text". + * + * Usage of mapping + * + * @returns Value of property "text" + */ + getText(): string; + + /** + * Sets a new value for property "text". + * + * Usage of mapping + * + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * @param text New value for property "text" + * @returns Reference to "this" in order to allow method chaining + */ + setText(text: string): this; + + // aggregation: content + + /** + * Gets content of aggregation "content". + * + * Determines the content of the SampleWebComponent. + */ + getContent(): Control[]; + + /** + * Adds some content to the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @param content The content to add; if empty, nothing is inserted + * @returns Reference to "this" in order to allow method chaining + */ + addContent(content: Control): this; + + /** + * Inserts a content into the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @param content The content to insert; if empty, nothing is inserted + * @param index The "0"-based index the content should be inserted at; for + * a negative value of "iIndex", the content is inserted at position 0; for a value + * greater than the current size of the aggregation, the content is inserted at + * the last position + * @returns Reference to "this" in order to allow method chaining + */ + insertContent(content: Control, index: number): this; + + /** + * Removes a content from the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @param content The content to remove or its index or id + * @returns The removed content or "null" + */ + removeContent(content: number | string | Control): Control | null; + + /** + * Removes all the controls from the aggregation "content". + * Additionally, it unregisters them from the hosting UIArea. + * + * Determines the content of the SampleWebComponent. + * + * @returns An array of the removed elements (might be empty) + */ + removeAllContent(): Control[]; + + /** + * Checks for the provided "sap.ui.core.Control" in the aggregation "content". + * and returns its index if found or -1 otherwise. + * + * Determines the content of the SampleWebComponent. + * + * @param content The content whose index is looked for + * @returns The index of the provided control in the aggregation if found, or -1 otherwise + */ + indexOfContent(content: Control): number; + + /** + * Destroys all the content in the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyContent(): this; + + /** + * Binds aggregation "content" to model data. + * + * Determines the content of the SampleWebComponent. + * + * See {@link sap.ui.base.ManagedObject#bindAggregation ManagedObject.bindAggregation} for a + * detailed description of the possible properties of "oBindingInfo". + * @param oBindingInfo The binding information + * @returns Reference to "this" in order to allow method chaining + */ + bindContent(bindingInfo: AggregationBindingInfo): this; + + /** + * Unbinds aggregation "content" from model data. + * + * Determines the content of the SampleWebComponent. + * + * @returns Reference to "this" in order to allow method chaining + */ + unbindContent(): this; + + // aggregation: header + + /** + * Gets content of aggregation "header". + */ + getHeader(): WebComponent; + + /** + * Sets the aggregated header. + * + * @param header The header to set + * @returns Reference to "this" in order to allow method chaining + */ + setHeader(header: WebComponent): this; + + /** + * Destroys the header in the aggregation "header". + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyHeader(): this; + + // aggregation: tooltip + + /** + * Gets content of aggregation "tooltip". + */ + getTooltip(): TooltipBase; + + /** + * Sets the aggregated tooltip. + * + * @param tooltip The tooltip to set + * @returns Reference to "this" in order to allow method chaining + */ + setTooltip(tooltip: TooltipBase): this; + + /** + * Destroys the tooltip in the aggregation "tooltip". + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyTooltip(): this; + + // association: partnerControl + + /** + * ID of the element which is the current target of the association "partnerControl", or "null". + */ + getPartnerControl(): string; + + /** + * Sets the associated partnerControl. + * + * @param partnerControl ID of an element which becomes the new target of this "partnerControl" association; alternatively, an element instance may be given + * @returns Reference to "this" in order to allow method chaining + */ + setPartnerControl(partnerControl?: string | SampleWebComponent): this; + + // association: alsoLabelledBy + + /** + * Returns array of IDs of the elements which are the current targets of the association "alsoLabelledBy". + * + * This is an association. + */ + getAlsoLabelledBy(): string[]; + + /** + * Adds some alsoLabelledBy into the association "alsoLabelledBy". + * + * This is an association. + * + * @param alsoLabelledBy The alsoLabelledBy to add; if empty, nothing is inserted + * @returns Reference to "this" in order to allow method chaining + */ + addAlsoLabelledBy(alsoLabelledBy: string | Control): this; + + /** + * Removes an alsoLabelledBy from the association named alsoLabelledBy. + * + * This is an association. + * + * @param alsoLabelledBy The alsoLabelledBy to be removed or its index or ID + * @returns The removed alsoLabelledBy or "null" + */ + removeAlsoLabelledBy(alsoLabelledBy: number | string | Control): string; + + /** + * Removes all the controls in the association named alsoLabelledBy. + * + * This is an association. + * + * @returns An array of the removed elements (might be empty) + */ + removeAllAlsoLabelledBy(): string[]; + + // event: doublePress + + /** + * Attaches event handler "fn" to the "doublePress" event of this "SampleWebComponent". + * + * Fired when double-clicked. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleWebComponent" itself. + * + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleWebComponent" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachDoublePress(fn: (event: SampleWebComponent$DoublePressEvent) => void, listener?: object): this; + + /** + * Attaches event handler "fn" to the "doublePress" event of this "SampleWebComponent". + * + * Fired when double-clicked. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleWebComponent" itself. + * + * @param data An application-specific payload object that will be passed to the event handler along with the event object when firing the event + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleWebComponent" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachDoublePress(data: CustomDataType, fn: (event: SampleWebComponent$DoublePressEvent, data: CustomDataType) => void, listener?: object): this; + + /** + * Detaches event handler "fn" from the "doublePress" event of this "SampleWebComponent". + * + * Fired when double-clicked. + * + * The passed function and listener object must match the ones used for event registration. + * + * @param fn The function to be called, when the event occurs + * @param listener Context object on which the given function had to be called + * @returns Reference to "this" in order to allow method chaining + */ + detachDoublePress(fn: (event: SampleWebComponent$DoublePressEvent) => void, listener?: object): this; + + /** + * Fires event "doublePress" to attached listeners. + * + * Fired when double-clicked. + * + * Listeners may prevent the default action of this event by calling the "preventDefault" method on the event object. + * The return value of this method indicates whether the default action should be executed. + * + * @param parameters Parameters to pass along with the event + * @returns Whether or not to prevent the default action + */ + fireDoublePress(parameters?: SampleWebComponent$DoublePressEventParameters): boolean; + } +} diff --git a/packages/ts-interface-generator/src/test/testcases/web-component/SampleWebComponent.ts b/packages/ts-interface-generator/src/test/testcases/web-component/SampleWebComponent.ts new file mode 100644 index 0000000..a085e56 --- /dev/null +++ b/packages/ts-interface-generator/src/test/testcases/web-component/SampleWebComponent.ts @@ -0,0 +1,92 @@ +import WebComponent, { MetadataOptions } from "sap/ui/core/webc/WebComponent"; + +/** + * A SampleWebComponent is a control wrapper for a Web Component and this is its documentation. + * + * @namespace ui5tssampleapp.control + */ +export default class SampleWebComponent extends WebComponent { + // The following three lines were generated and should remain as-is to make TypeScript aware of the constructor signatures + constructor(idOrSettings?: string | $SampleWebComponentSettings); + constructor(id?: string, settings?: $SampleWebComponentSettings); + constructor(id?: string, settings?: $SampleWebComponentSettings) { + super(id, settings); + } + + static readonly metadata: MetadataOptions = { + tag: "sample-webcomponent", + properties: { + /** + * The text that appears below the main text. + * @since 1.0 + */ + subtext: "string", + + /** + * Determines the text color of the SampleWebComponent. + * + * @experimental + */ + textColor: { type: "sap.ui.core.CSSColor", defaultValue: "" }, + + /** + * Usage of mapping + */ + text: { + type: "string", + mapping: { + type: "textContent", + }, + }, + }, + aggregations: { + /** + * Determines the content of the SampleWebComponent. + */ + content: { multiple: true, type: "sap.ui.core.Control", bindable: true }, + header: { multiple: false, type: "sap.ui.core.webc.WebComponent" }, + tooltip: { + multiple: false, + type: "sap.ui.core.TooltipBase", + altTypes: ["string"], + }, + }, + defaultAggregation: "content", + associations: { + partnerControl: "SampleWebComponent", + /** + * This is an association. + */ + alsoLabelledBy: { type: "sap.ui.core.Control", multiple: true }, + }, + events: { + /** + * Fired when double-clicked. + */ + doublePress: { allowPreventDefault: true }, + }, + methods: ["somePublicMethod"], + getters: ["somePublicGetter"], + }; +} + +/** + * implement the methods and getters + */ +declare module "./SampleWebComponent" { + export default interface SampleWebComponent { + /** + * Some public method returning a "string" + * + * @since 1.0 + * + * @returns Value of property "subtext" + */ + somePublicMethod(): string; + + /** + * Some public getter being a "string" + */ + somePublicGetter: string; + } +} diff --git a/packages/ts-interface-generator/src/test/testcases/xl-control-with-all-features/SampleControl.gen.d.ts b/packages/ts-interface-generator/src/test/testcases/xl-control-with-all-features/SampleControl.gen.d.ts new file mode 100644 index 0000000..fbc4b91 --- /dev/null +++ b/packages/ts-interface-generator/src/test/testcases/xl-control-with-all-features/SampleControl.gen.d.ts @@ -0,0 +1,856 @@ +import Event from "sap/ui/base/Event"; +import { CSSColor } from "sap/ui/core/library"; +import Control from "sap/ui/core/Control"; +import { AggregationBindingInfo } from "sap/ui/base/ManagedObject"; +import TooltipBase from "sap/ui/core/TooltipBase"; +import { PropertyBindingInfo } from "sap/ui/base/ManagedObject"; +import { $ButtonSettings } from "sap/m/Button"; + +declare module "./SampleControl" { + + /** + * Interface defining the settings object used in constructor calls + */ + interface $SampleControlSettings extends $ButtonSettings { + + /** + * The text that appears below the main text. + * + * @since 1.0 + */ + subtext?: string | PropertyBindingInfo; + + /** + * Determines the text color of the SampleControl. + * + * @experimental + */ + textColor?: CSSColor | PropertyBindingInfo | `{${string}}`; + + /** + * Determines the content of the SampleControl. + */ + content?: Control[] | Control | AggregationBindingInfo | `{${string}}`; + + /** + * The header - there can be only one + */ + header?: Control; + + /** + * The tooltip - either a string or a TooltipBase + */ + tooltip?: TooltipBase | string | PropertyBindingInfo; + + /** + * Another control belonging to this one + */ + partnerControl?: SampleControl | string; + + /** + * This is an association. + */ + alsoLabelledBy?: Control | string | (Control | string)[]; + + /** + * Fired when single-clicked. This event has no parameters. + */ + singlePress?: (event: SampleControl$SinglePressEvent) => void; + + /** + * Fired when double-clicked. + */ + doublePress?: (event: SampleControl$DoublePressEvent) => void; + } + + export default interface SampleControl { + + // property: subtext + + /** + * Gets current value of property "subtext". + * + * The text that appears below the main text. + * + * @since 1.0 + * + * @returns Value of property "subtext" + */ + getSubtext(): string; + + /** + * Sets a new value for property "subtext". + * + * The text that appears below the main text. + * + * @since 1.0 + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * @param subtext New value for property "subtext" + * @returns Reference to "this" in order to allow method chaining + */ + setSubtext(subtext: string): this; + + // property: textColor + + /** + * Gets current value of property "textColor". + * + * Determines the text color of the SampleControl. + * + * @experimental + * Default value is: "" + * @returns Value of property "textColor" + */ + getTextColor(): CSSColor; + + /** + * Sets a new value for property "textColor". + * + * Determines the text color of the SampleControl. + * + * @experimental + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * Default value is: "" + * @param [textColor=""] New value for property "textColor" + * @returns Reference to "this" in order to allow method chaining + */ + setTextColor(textColor: CSSColor): this; + + // aggregation: content + + /** + * Gets content of aggregation "content". + * + * Determines the content of the SampleControl. + */ + getContent(): Control[]; + + /** + * Adds some content to the aggregation "content". + * + * Determines the content of the SampleControl. + * + * @param content The content to add; if empty, nothing is inserted + * @returns Reference to "this" in order to allow method chaining + */ + addContent(content: Control): this; + + /** + * Inserts a content into the aggregation "content". + * + * Determines the content of the SampleControl. + * + * @param content The content to insert; if empty, nothing is inserted + * @param index The "0"-based index the content should be inserted at; for + * a negative value of "iIndex", the content is inserted at position 0; for a value + * greater than the current size of the aggregation, the content is inserted at + * the last position + * @returns Reference to "this" in order to allow method chaining + */ + insertContent(content: Control, index: number): this; + + /** + * Removes a content from the aggregation "content". + * + * Determines the content of the SampleControl. + * + * @param content The content to remove or its index or id + * @returns The removed content or "null" + */ + removeContent(content: number | string | Control): Control | null; + + /** + * Removes all the controls from the aggregation "content". + * Additionally, it unregisters them from the hosting UIArea. + * + * Determines the content of the SampleControl. + * + * @returns An array of the removed elements (might be empty) + */ + removeAllContent(): Control[]; + + /** + * Checks for the provided "sap.ui.core.Control" in the aggregation "content". + * and returns its index if found or -1 otherwise. + * + * Determines the content of the SampleControl. + * + * @param content The content whose index is looked for + * @returns The index of the provided control in the aggregation if found, or -1 otherwise + */ + indexOfContent(content: Control): number; + + /** + * Destroys all the content in the aggregation "content". + * + * Determines the content of the SampleControl. + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyContent(): this; + + /** + * Binds aggregation "content" to model data. + * + * Determines the content of the SampleControl. + * + * See {@link sap.ui.base.ManagedObject#bindAggregation ManagedObject.bindAggregation} for a + * detailed description of the possible properties of "oBindingInfo". + * @param oBindingInfo The binding information + * @returns Reference to "this" in order to allow method chaining + */ + bindContent(bindingInfo: AggregationBindingInfo): this; + + /** + * Unbinds aggregation "content" from model data. + * + * Determines the content of the SampleControl. + * + * @returns Reference to "this" in order to allow method chaining + */ + unbindContent(): this; + + // aggregation: header + + /** + * Gets content of aggregation "header". + * + * The header - there can be only one + */ + getHeader(): Control; + + /** + * Sets the aggregated header. + * + * The header - there can be only one + * + * @param header The header to set + * @returns Reference to "this" in order to allow method chaining + */ + setHeader(header: Control): this; + + /** + * Destroys the header in the aggregation "header". + * + * The header - there can be only one + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyHeader(): this; + + // aggregation: tooltip + + /** + * Gets content of aggregation "tooltip". + * + * The tooltip - either a string or a TooltipBase + */ + getTooltip(): TooltipBase; + + /** + * Sets the aggregated tooltip. + * + * The tooltip - either a string or a TooltipBase + * + * @param tooltip The tooltip to set + * @returns Reference to "this" in order to allow method chaining + */ + setTooltip(tooltip: TooltipBase): this; + + /** + * Destroys the tooltip in the aggregation "tooltip". + * + * The tooltip - either a string or a TooltipBase + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyTooltip(): this; + + // association: partnerControl + + /** + * ID of the element which is the current target of the association "partnerControl", or "null". + * + * Another control belonging to this one + */ + getPartnerControl(): string; + + /** + * Sets the associated partnerControl. + * + * Another control belonging to this one + * + * @param partnerControl ID of an element which becomes the new target of this "partnerControl" association; alternatively, an element instance may be given + * @returns Reference to "this" in order to allow method chaining + */ + setPartnerControl(partnerControl?: string | SampleControl): this; + + // association: alsoLabelledBy + + /** + * Returns array of IDs of the elements which are the current targets of the association "alsoLabelledBy". + * + * This is an association. + */ + getAlsoLabelledBy(): string[]; + + /** + * Adds some alsoLabelledBy into the association "alsoLabelledBy". + * + * This is an association. + * + * @param alsoLabelledBy The alsoLabelledBy to add; if empty, nothing is inserted + * @returns Reference to "this" in order to allow method chaining + */ + addAlsoLabelledBy(alsoLabelledBy: string | Control): this; + + /** + * Removes an alsoLabelledBy from the association named alsoLabelledBy. + * + * This is an association. + * + * @param alsoLabelledBy The alsoLabelledBy to be removed or its index or ID + * @returns The removed alsoLabelledBy or "null" + */ + removeAlsoLabelledBy(alsoLabelledBy: number | string | Control): string; + + /** + * Removes all the controls in the association named alsoLabelledBy. + * + * This is an association. + * + * @returns An array of the removed elements (might be empty) + */ + removeAllAlsoLabelledBy(): string[]; + + // event: singlePress + + /** + * Attaches event handler "fn" to the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachSinglePress(fn: (event: SampleControl$SinglePressEvent) => void, listener?: object): this; + + /** + * Attaches event handler "fn" to the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param data An application-specific payload object that will be passed to the event handler along with the event object when firing the event + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachSinglePress(data: CustomDataType, fn: (event: SampleControl$SinglePressEvent, data: CustomDataType) => void, listener?: object): this; + + /** + * Detaches event handler "fn" from the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters. + * + * The passed function and listener object must match the ones used for event registration. + * + * @param fn The function to be called, when the event occurs + * @param listener Context object on which the given function had to be called + * @returns Reference to "this" in order to allow method chaining + */ + detachSinglePress(fn: (event: SampleControl$SinglePressEvent) => void, listener?: object): this; + + /** + * Fires event "singlePress" to attached listeners. + * + * Fired when single-clicked. This event has no parameters. + * + * @param parameters Parameters to pass along with the event + * @returns Reference to "this" in order to allow method chaining + */ + fireSinglePress(parameters?: SampleControl$SinglePressEventParameters): this; + + // event: doublePress + + /** + * Attaches event handler "fn" to the "doublePress" event of this "SampleControl". + * + * Fired when double-clicked. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachDoublePress(fn: (event: SampleControl$DoublePressEvent) => void, listener?: object): this; + + /** + * Attaches event handler "fn" to the "doublePress" event of this "SampleControl". + * + * Fired when double-clicked. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param data An application-specific payload object that will be passed to the event handler along with the event object when firing the event + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachDoublePress(data: CustomDataType, fn: (event: SampleControl$DoublePressEvent, data: CustomDataType) => void, listener?: object): this; + + /** + * Detaches event handler "fn" from the "doublePress" event of this "SampleControl". + * + * Fired when double-clicked. + * + * The passed function and listener object must match the ones used for event registration. + * + * @param fn The function to be called, when the event occurs + * @param listener Context object on which the given function had to be called + * @returns Reference to "this" in order to allow method chaining + */ + detachDoublePress(fn: (event: SampleControl$DoublePressEvent) => void, listener?: object): this; + + /** + * Fires event "doublePress" to attached listeners. + * + * Fired when double-clicked. + * + * Listeners may prevent the default action of this event by calling the "preventDefault" method on the event object. + * The return value of this method indicates whether the default action should be executed. + * + * @param parameters Parameters to pass along with the event + * @param [mParameters.delay] Fired when double-clicked. + * + * @returns Whether or not to prevent the default action + */ + fireDoublePress(parameters?: SampleControl$DoublePressEventParameters): boolean; + } + + /** + * Interface describing the parameters of SampleControl's 'singlePress' event. + * Fired when single-clicked. This event has no parameters. + */ + // eslint-disable-next-line + export interface SampleControl$SinglePressEventParameters { + } + + /** + * Interface describing the parameters of SampleControl's 'doublePress' event. + * Fired when double-clicked. + */ + export interface SampleControl$DoublePressEventParameters { + delay?: number; + } + + /** + * Type describing the SampleControl's 'singlePress' event. + * Fired when single-clicked. This event has no parameters. + */ + export type SampleControl$SinglePressEvent = Event; + + /** + * Type describing the SampleControl's 'doublePress' event. + * Fired when double-clicked. + */ + export type SampleControl$DoublePressEvent = Event; +} + +// this duplicate interface without export is needed to avoid "Cannot find name 'SampleControl'" TypeScript errors above +declare module "./SampleControl" { + interface SampleControl { + + // property: subtext + + /** + * Gets current value of property "subtext". + * + * The text that appears below the main text. + * + * @since 1.0 + * + * @returns Value of property "subtext" + */ + getSubtext(): string; + + /** + * Sets a new value for property "subtext". + * + * The text that appears below the main text. + * + * @since 1.0 + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * @param subtext New value for property "subtext" + * @returns Reference to "this" in order to allow method chaining + */ + setSubtext(subtext: string): this; + + // property: textColor + + /** + * Gets current value of property "textColor". + * + * Determines the text color of the SampleControl. + * + * @experimental + * Default value is: "" + * @returns Value of property "textColor" + */ + getTextColor(): CSSColor; + + /** + * Sets a new value for property "textColor". + * + * Determines the text color of the SampleControl. + * + * @experimental + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * Default value is: "" + * @param [textColor=""] New value for property "textColor" + * @returns Reference to "this" in order to allow method chaining + */ + setTextColor(textColor: CSSColor): this; + + // aggregation: content + + /** + * Gets content of aggregation "content". + * + * Determines the content of the SampleControl. + */ + getContent(): Control[]; + + /** + * Adds some content to the aggregation "content". + * + * Determines the content of the SampleControl. + * + * @param content The content to add; if empty, nothing is inserted + * @returns Reference to "this" in order to allow method chaining + */ + addContent(content: Control): this; + + /** + * Inserts a content into the aggregation "content". + * + * Determines the content of the SampleControl. + * + * @param content The content to insert; if empty, nothing is inserted + * @param index The "0"-based index the content should be inserted at; for + * a negative value of "iIndex", the content is inserted at position 0; for a value + * greater than the current size of the aggregation, the content is inserted at + * the last position + * @returns Reference to "this" in order to allow method chaining + */ + insertContent(content: Control, index: number): this; + + /** + * Removes a content from the aggregation "content". + * + * Determines the content of the SampleControl. + * + * @param content The content to remove or its index or id + * @returns The removed content or "null" + */ + removeContent(content: number | string | Control): Control | null; + + /** + * Removes all the controls from the aggregation "content". + * Additionally, it unregisters them from the hosting UIArea. + * + * Determines the content of the SampleControl. + * + * @returns An array of the removed elements (might be empty) + */ + removeAllContent(): Control[]; + + /** + * Checks for the provided "sap.ui.core.Control" in the aggregation "content". + * and returns its index if found or -1 otherwise. + * + * Determines the content of the SampleControl. + * + * @param content The content whose index is looked for + * @returns The index of the provided control in the aggregation if found, or -1 otherwise + */ + indexOfContent(content: Control): number; + + /** + * Destroys all the content in the aggregation "content". + * + * Determines the content of the SampleControl. + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyContent(): this; + + /** + * Binds aggregation "content" to model data. + * + * Determines the content of the SampleControl. + * + * See {@link sap.ui.base.ManagedObject#bindAggregation ManagedObject.bindAggregation} for a + * detailed description of the possible properties of "oBindingInfo". + * @param oBindingInfo The binding information + * @returns Reference to "this" in order to allow method chaining + */ + bindContent(bindingInfo: AggregationBindingInfo): this; + + /** + * Unbinds aggregation "content" from model data. + * + * Determines the content of the SampleControl. + * + * @returns Reference to "this" in order to allow method chaining + */ + unbindContent(): this; + + // aggregation: header + + /** + * Gets content of aggregation "header". + * + * The header - there can be only one + */ + getHeader(): Control; + + /** + * Sets the aggregated header. + * + * The header - there can be only one + * + * @param header The header to set + * @returns Reference to "this" in order to allow method chaining + */ + setHeader(header: Control): this; + + /** + * Destroys the header in the aggregation "header". + * + * The header - there can be only one + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyHeader(): this; + + // aggregation: tooltip + + /** + * Gets content of aggregation "tooltip". + * + * The tooltip - either a string or a TooltipBase + */ + getTooltip(): TooltipBase; + + /** + * Sets the aggregated tooltip. + * + * The tooltip - either a string or a TooltipBase + * + * @param tooltip The tooltip to set + * @returns Reference to "this" in order to allow method chaining + */ + setTooltip(tooltip: TooltipBase): this; + + /** + * Destroys the tooltip in the aggregation "tooltip". + * + * The tooltip - either a string or a TooltipBase + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyTooltip(): this; + + // association: partnerControl + + /** + * ID of the element which is the current target of the association "partnerControl", or "null". + * + * Another control belonging to this one + */ + getPartnerControl(): string; + + /** + * Sets the associated partnerControl. + * + * Another control belonging to this one + * + * @param partnerControl ID of an element which becomes the new target of this "partnerControl" association; alternatively, an element instance may be given + * @returns Reference to "this" in order to allow method chaining + */ + setPartnerControl(partnerControl?: string | SampleControl): this; + + // association: alsoLabelledBy + + /** + * Returns array of IDs of the elements which are the current targets of the association "alsoLabelledBy". + * + * This is an association. + */ + getAlsoLabelledBy(): string[]; + + /** + * Adds some alsoLabelledBy into the association "alsoLabelledBy". + * + * This is an association. + * + * @param alsoLabelledBy The alsoLabelledBy to add; if empty, nothing is inserted + * @returns Reference to "this" in order to allow method chaining + */ + addAlsoLabelledBy(alsoLabelledBy: string | Control): this; + + /** + * Removes an alsoLabelledBy from the association named alsoLabelledBy. + * + * This is an association. + * + * @param alsoLabelledBy The alsoLabelledBy to be removed or its index or ID + * @returns The removed alsoLabelledBy or "null" + */ + removeAlsoLabelledBy(alsoLabelledBy: number | string | Control): string; + + /** + * Removes all the controls in the association named alsoLabelledBy. + * + * This is an association. + * + * @returns An array of the removed elements (might be empty) + */ + removeAllAlsoLabelledBy(): string[]; + + // event: singlePress + + /** + * Attaches event handler "fn" to the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachSinglePress(fn: (event: SampleControl$SinglePressEvent) => void, listener?: object): this; + + /** + * Attaches event handler "fn" to the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param data An application-specific payload object that will be passed to the event handler along with the event object when firing the event + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachSinglePress(data: CustomDataType, fn: (event: SampleControl$SinglePressEvent, data: CustomDataType) => void, listener?: object): this; + + /** + * Detaches event handler "fn" from the "singlePress" event of this "SampleControl". + * + * Fired when single-clicked. This event has no parameters. + * + * The passed function and listener object must match the ones used for event registration. + * + * @param fn The function to be called, when the event occurs + * @param listener Context object on which the given function had to be called + * @returns Reference to "this" in order to allow method chaining + */ + detachSinglePress(fn: (event: SampleControl$SinglePressEvent) => void, listener?: object): this; + + /** + * Fires event "singlePress" to attached listeners. + * + * Fired when single-clicked. This event has no parameters. + * + * @param parameters Parameters to pass along with the event + * @returns Reference to "this" in order to allow method chaining + */ + fireSinglePress(parameters?: SampleControl$SinglePressEventParameters): this; + + // event: doublePress + + /** + * Attaches event handler "fn" to the "doublePress" event of this "SampleControl". + * + * Fired when double-clicked. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachDoublePress(fn: (event: SampleControl$DoublePressEvent) => void, listener?: object): this; + + /** + * Attaches event handler "fn" to the "doublePress" event of this "SampleControl". + * + * Fired when double-clicked. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleControl" itself. + * + * @param data An application-specific payload object that will be passed to the event handler along with the event object when firing the event + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleControl" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachDoublePress(data: CustomDataType, fn: (event: SampleControl$DoublePressEvent, data: CustomDataType) => void, listener?: object): this; + + /** + * Detaches event handler "fn" from the "doublePress" event of this "SampleControl". + * + * Fired when double-clicked. + * + * The passed function and listener object must match the ones used for event registration. + * + * @param fn The function to be called, when the event occurs + * @param listener Context object on which the given function had to be called + * @returns Reference to "this" in order to allow method chaining + */ + detachDoublePress(fn: (event: SampleControl$DoublePressEvent) => void, listener?: object): this; + + /** + * Fires event "doublePress" to attached listeners. + * + * Fired when double-clicked. + * + * Listeners may prevent the default action of this event by calling the "preventDefault" method on the event object. + * The return value of this method indicates whether the default action should be executed. + * + * @param parameters Parameters to pass along with the event + * @param [mParameters.delay] Fired when double-clicked. + * + * @returns Whether or not to prevent the default action + */ + fireDoublePress(parameters?: SampleControl$DoublePressEventParameters): boolean; + } +} diff --git a/packages/ts-interface-generator/src/test/testcases/xl-control-with-all-features/SampleControl.ts b/packages/ts-interface-generator/src/test/testcases/xl-control-with-all-features/SampleControl.ts new file mode 100644 index 0000000..f9b9905 --- /dev/null +++ b/packages/ts-interface-generator/src/test/testcases/xl-control-with-all-features/SampleControl.ts @@ -0,0 +1,102 @@ +import Button from "sap/m/Button"; +import { MetadataOptions } from "sap/ui/core/Element"; +import RenderManager from "sap/ui/core/RenderManager"; + +/** + * A SampleControl is a control and this is its documentation. + * + * @namespace ui5tssampleapp.control + */ +export default class SampleControl extends Button { + + // The following three lines were generated and should remain as-is to make TypeScript aware of the constructor signatures + constructor(idOrSettings?: string | $SampleControlSettings); + constructor(id?: string, settings?: $SampleControlSettings); + constructor(id?: string, settings?: $SampleControlSettings) { super(id, settings); } + + static readonly metadata: MetadataOptions = { + properties: { + /** + * The text that appears below the main text. + * @since 1.0 + */ + subtext: "string", + + /** + * Determines the text color of the SampleControl. + * + * @experimental + */ + textColor: { type: "sap.ui.core.CSSColor", defaultValue: "" }, + }, + aggregations: { + /** + * Determines the content of the SampleControl. + */ + content: { multiple: true, type: "sap.ui.core.Control", bindable: true }, + /** + * The header - there can be only one + */ + header: { multiple: false, type: "sap.ui.core.Control" }, + /** + * The tooltip - either a string or a TooltipBase + */ + tooltip: { multiple: false, type: "sap.ui.core.TooltipBase", altTypes : ["string"]} + }, + defaultAggregation: "content", + associations: { + /** + * Another control belonging to this one + */ + partnerControl: "SampleControl", + /** + * This is an association. + */ + alsoLabelledBy: { type: "sap.ui.core.Control", multiple: true }, + }, + events: { + /** + * Fired when single-clicked. This event has no parameters. + */ + singlePress: {}, + /** + * Fired when double-clicked. + */ + doublePress: { + allowPreventDefault: true, + parameters: { + /** + * The amount of milliseconds between the first and second press + */ + delay: { type: "int" } + } + } + }, + }; + + static renderer = { + apiVersion: 2, + render: function (rm: RenderManager, control: SampleControl) { + rm.openStart("div", control); + rm.openEnd(); + + rm.text(control.getText()); + // @ts-ignore this only works with the generated interface + rm.text(control.getSubtext()); + // @ts-ignore this only works with the generated interface + const content = control.getContent(); + for (let i = 0; i < content.length; i++) { + rm.renderControl(content[i]); + } + rm.close("div"); + } + }; + + doit() { + this.fireDoublePress({ + delay: 100 + }); + this.fireSinglePress(); + alert("Hello"); + } +}