diff --git a/build.gradle b/build.gradle --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { typescript { compilerOptions { lib = ["es5", "dom", "scripthost", "es2015.promise", "es2015.symbol", "es2015.iterable"] - listFiles = true + //listFiles = true declaration = true strict = true types = [] @@ -16,6 +16,11 @@ typescript { jsx = "react" jsxFactory = "createElement" moduleResolution = "node" + // traceResolution = true + // baseUrl = "./" + // paths = [ "*": [ "$projectDir/src/typings/*" ] ] + // baseUrl = "$projectDir/src/typings" + // typeRoots = ["$projectDir/src/typings"] } tscCmd = "$projectDir/node_modules/.bin/tsc" @@ -25,13 +30,28 @@ typescript { configureTsMain { compilerOptions { - types = ["requirejs", "dojo-typings"] + types = ["requirejs"] + } +} + +npmPackMeta { + meta { + name = "@$npmScope/$project.name" } } +task npmPackTypings(type: Copy) { + dependsOn sources.main.output + + npmPack.dependsOn it + + from sources.main.output.typingsDir + into npm.packageDir +} + task printVersion { doLast { - println "packageName: $packageName"; + println "packageName: ${npmPackMeta.metadata.get().name}"; println "version: $version"; println "target: $typescript.compilerOptions.target"; println "module: $typescript.compilerOptions.module"; diff --git a/package-lock.json b/package-lock.json --- a/package-lock.json +++ b/package-lock.json @@ -43,6 +43,25 @@ "integrity": "sha512-f5dXGzOJycyzSMdaXVhiBhauL4dYydXwVpavfQ1mVCaGjR56a9QfklXObUxlIY9bGTmCPHEEZ04I16BZ/8w5ww==", "dev": true }, + "@types/dijit": { + "version": "file:src/typings/dijit", + "dev": true, + "requires": { + "@types/dojo": "^1.0.0" + }, + "dependencies": { + "@types/dojo": { + "version": "1.9.42", + "resolved": "https://registry.npmjs.org/@types/dojo/-/dojo-1.9.42.tgz", + "integrity": "sha512-yFfw7uoOlCy6QgxTWIzii4/QOsIDXq9gX3/6iXQ2nz//Y23yWXFRaYpoQ7GW0fvPN3lKtYkXgv6GXtdtWlHFXg==", + "dev": true + } + } + }, + "@types/dojo": { + "version": "file:src/typings/dojo", + "dev": true + }, "@types/requirejs": { "version": "2.1.31", "resolved": "https://registry.npmjs.org/@types/requirejs/-/requirejs-2.1.31.tgz", @@ -297,15 +316,6 @@ "integrity": "sha512-DUiXyoLK6vMF5BPr/qiMLTxDMfiM9qlzN1jxfDsVfuvB/CwhYpNxA/M4mbqKN8PCVGLmccXBJbfmFJPP5+zmzw==", "dev": true }, - "dojo-typings": { - "version": "1.11.9", - "resolved": "https://registry.npmjs.org/dojo-typings/-/dojo-typings-1.11.9.tgz", - "integrity": "sha512-mh8w+Mau2Y1QfTEszEAdO7j6ycNhYxF/Ing6nAk1eUg6NxjeT0viVHjICMd9sU3U463vM2G+KfBBK5grk3/Mlw==", - "dev": true, - "requires": { - "@types/chai": "^4.0.4" - } - }, "emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", diff --git a/package.json b/package.json --- a/package.json +++ b/package.json @@ -2,7 +2,6 @@ "devDependencies": { "@types/requirejs": "2.1.31", "dojo": "1.16.0", - "dojo-typings": "1.11.9", "typescript": "~3.7.5", "eslint": "6.8.0", "tslint": "6.0.0", @@ -10,6 +9,8 @@ "yaml": "~1.7.2", "@types/yaml": "1.2.0", "chai": "4.2.0", - "@types/chai": "4.1.3" + "@types/chai": "4.1.3", + "@types/dojo": "./src/typings/dojo", + "@types/dijit": "./src/typings/dijit" } } diff --git a/settings.gradle b/settings.gradle --- a/settings.gradle +++ b/settings.gradle @@ -12,4 +12,4 @@ //include 'sub-project-name' -//rootProject.name = 'djx' \ No newline at end of file +rootProject.name = 'djx' \ No newline at end of file diff --git a/src/main/ts/declare.ts b/src/main/ts/declare.ts --- a/src/main/ts/declare.ts +++ b/src/main/ts/declare.ts @@ -1,6 +1,7 @@ import declare = require("dojo/_base/declare"); import { each } from "@implab/core-amd/safe"; import { Constructor } from "@implab/core-amd/interfaces"; +import { DeclareConstructor } from "dojo/_base/declare"; export interface AbstractConstructor { prototype: T; @@ -14,25 +15,25 @@ interface DjMockConstructor { export function djbase( b0: AbstractConstructor -): dojo._base.DeclareConstructor; +): DeclareConstructor; export function djbase( b0: AbstractConstructor, b1: AbstractConstructor -): dojo._base.DeclareConstructor; +): DeclareConstructor; export function djbase( b0: AbstractConstructor, b1: AbstractConstructor, b2: AbstractConstructor -): dojo._base.DeclareConstructor; +): DeclareConstructor; export function djbase( b0: AbstractConstructor, b1: AbstractConstructor, b2: AbstractConstructor, b3: AbstractConstructor -): dojo._base.DeclareConstructor; +): DeclareConstructor; export function djbase( b0: AbstractConstructor, @@ -40,7 +41,7 @@ export function djbase, b3: AbstractConstructor, b4: AbstractConstructor -): dojo._base.DeclareConstructor; +): DeclareConstructor; export function djbase( b0: AbstractConstructor, @@ -49,7 +50,7 @@ export function djbase, b4: AbstractConstructor, b5: AbstractConstructor -): dojo._base.DeclareConstructor; +): DeclareConstructor; export function djbase( b0: AbstractConstructor, @@ -59,7 +60,7 @@ export function djbase, b5: AbstractConstructor, b6: AbstractConstructor -): dojo._base.DeclareConstructor; +): DeclareConstructor; export function djbase( b0: AbstractConstructor, @@ -70,7 +71,7 @@ export function djbase, b6: AbstractConstructor, b7: AbstractConstructor -): dojo._base.DeclareConstructor; +): DeclareConstructor; /** Создает конструктор-заглушку из списка базовых классов, используется * для объявления классов при помощи `dojo/_base/declare`. diff --git a/src/main/ts/djx/DjxWidgetBase.ts b/src/main/ts/djx/DjxWidgetBase.ts --- a/src/main/ts/djx/DjxWidgetBase.ts +++ b/src/main/ts/djx/DjxWidgetBase.ts @@ -3,6 +3,7 @@ import _WidgetBase = require("dijit/_Wid import _AttachMixin = require("dijit/_AttachMixin"); import { BuildContext, isNode } from "./traits"; import registry = require("dijit/registry"); +import { Handle } from "dojo/interfaces"; @djclass export abstract class DjxWidgetBase extends djbase(_WidgetBase, _AttachMixin) { @@ -18,7 +19,7 @@ export abstract class DjxWidgetBase exte baseNode: T, getAttrFunc: (baseNode: T, attr: string) => string, // tslint:disable-next-line: ban-types - attachFunc: (node: T, type: string, func?: Function) => dojo.Handle + attachFunc: (node: T, type: string, func?: Function) => Handle ): boolean { if (isNode(baseNode)) { const w = registry.byNode(baseNode); diff --git a/src/main/ts/djx/WidgetContext.ts b/src/main/ts/djx/WidgetContext.ts --- a/src/main/ts/djx/WidgetContext.ts +++ b/src/main/ts/djx/WidgetContext.ts @@ -1,8 +1,8 @@ import dom = require("dojo/dom-construct"); -import { argumentNotNull, isNull, mixin } from "@implab/core-amd/safe"; +import { argumentNotNull } from "@implab/core-amd/safe"; import _WidgetBase = require("dijit/_WidgetBase"); -import { _WidgetBaseConstructor, isNode } from "./traits"; import { BuildContextBase } from "./BuildContextBase"; +import { _WidgetBaseConstructor } from "dijit/_WidgetBase"; export class WidgetContext extends BuildContextBase { widgetClass: _WidgetBaseConstructor; diff --git a/src/main/ts/djx/traits.ts b/src/main/ts/djx/traits.ts --- a/src/main/ts/djx/traits.ts +++ b/src/main/ts/djx/traits.ts @@ -1,4 +1,5 @@ import _WidgetBase = require("dijit/_WidgetBase"); +import { _WidgetBaseConstructor } from "dijit/_WidgetBase"; export interface BuildContext { getDomElement(): HTMLElement; @@ -24,8 +25,6 @@ export function isPlainObject(v: object) return !vp || vp === Object.prototype; } -export type _WidgetBaseConstructor = dijit._WidgetBaseConstructor<_WidgetBase>; - export function isWidgetConstructor(v: any): v is _WidgetBaseConstructor { return typeof v === "function" && v.prototype && "domNode" in v.prototype; } diff --git a/src/main/ts/i18n.ts b/src/main/ts/i18n.ts --- a/src/main/ts/i18n.ts +++ b/src/main/ts/i18n.ts @@ -6,7 +6,8 @@ export function bundle const nlsBundle = new NlsBundle(nls, locales); const fn = (locale?: string) => { - const result = nlsBundle.getLocale(locale); + const result = locale ? nlsBundle.getLocale(locale) : nlsBundle.default; + if (isPromise(result)) throw new Error(`The bundle '${locale}' isn't loaded`); else diff --git a/src/main/tsconfig.json b/src/main/tsconfig.json --- a/src/main/tsconfig.json +++ b/src/main/tsconfig.json @@ -2,6 +2,8 @@ "extends": "../tsconfig", "compilerOptions": { "rootDir": "ts", - "types": ["requirejs", "dojo-typings"] + "types": [ + "requirejs" + ] } } \ No newline at end of file diff --git a/src/main/typings/declarations.d.ts b/src/main/typings/declarations.d.ts deleted file mode 100644 diff --git a/src/test/ts/TestTraits.ts b/src/test/ts/TestTraits.ts --- a/src/test/ts/TestTraits.ts +++ b/src/test/ts/TestTraits.ts @@ -11,11 +11,11 @@ export class TapeWriter implements IDest private readonly _t: TapWriter; private readonly _subscriptions = new Array(); - private _destroyed; + private _destroyed = false; constructor(t: TapWriter) { argumentNotNull(t, "test"); - + this._t = t; } writeEvents(source: IObservable, ct: ICancellation = Cancellation.none) { @@ -41,15 +41,20 @@ export class TapeWriter implements IDest } destroy() { + if (this._destroyed) + return; + this._destroyed = true; this._subscriptions.forEach(destroy); } } -type TestCallback = (ok: (msg:string) => void, fail: (msg:string) => void, trace: TraceSource) => void; -type AsyncTestCallback = (trace: TraceSource) => PromiseLike | void; +type TestCallback = (ok: (msg: string) => void, fail: (msg: string) => void, trace: TraceSource) => void; +type AsyncTestCallback = (trace: TraceSource) => PromiseLike; +export function test(name: string, cb: TestCallback ): void; +export function test(name: string, cb: AsyncTestCallback): void; export function test(name: string, cb: TestCallback | AsyncTestCallback) { - + } export function run() { diff --git a/src/test/tsconfig.json b/src/test/tsconfig.json --- a/src/test/tsconfig.json +++ b/src/test/tsconfig.json @@ -6,6 +6,6 @@ "ts", "../main/ts" ], - "types": ["requirejs", "dojo-typings"] + "types": ["requirejs"] } } \ No newline at end of file diff --git a/src/typings/dijit/Calendar.d.ts b/src/typings/dijit/Calendar.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/Calendar.d.ts @@ -0,0 +1,107 @@ +import DropDownButton = require("./form/DropDownButton"); +import _Widget = require("./_Widget"); +import _TemplatedMixin = require("./_TemplatedMixin"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; +import { CSSStateNodes, _CssStateMixin } from "./_CssStateMixin"; +import { _MonthWidgetConstructor, CalendarLite } from "./CalendarLite"; + +interface _MonthDropDownButton extends DropDownButton<_MonthDropDown> { + onMonthSelect(): void; + postCreate(): void; + + set(name: 'month', value: number): this; + set(name: string, value: any): this; + set(values: Object): this; +} + +type _MonthDropDownButtonConstructor = _WidgetBaseConstructor<_MonthDropDownButton>; + +interface _MonthDropDown extends _Widget, _TemplatedMixin, _CssStateMixin { + months: string[]; + baseClass: string; + templateString: string; + + /** + * Callback when month is selected from drop down + */ + onChange(month: number): void; + + set(name: 'months', value: string[]): this; + set(name: string, value: any): this; + set(values: Object): this; +} + +type _MonthDropDownConstructor = _WidgetBaseConstructor<_MonthDropDown>; + +interface Calendar extends CalendarLite, _Widget, _CssStateMixin { + + baseClass: string; + + /** + * Set node classes for various mouse events, see dijit._CssStateMixin for more details + */ + cssStateNodes: CSSStateNodes; + + /** + * Creates the drop down button that displays the current month and lets user pick a new one + */ + _createMonthWidget(): _MonthDropDownButton; + + postCreate(): void; + + /** + * Handler for when user selects a month from the drop down list + */ + _onMonthSelect(newMonth: number): void; + + /** + * Handler for mouse over events on days, sets hovered style + */ + _onDayMouseOver(evt: MouseEvent): void; + + /** + * Handler for mouse out events on days, clears hovered style + */ + _onDayMouseOut(evt: MouseEvent): void; + _onDayMouseDown(evt: MouseEvent): void; + _onDayMouseUp(evt: MouseEvent): void; + + /** + * Provides keyboard navigation of calendar. + */ + handleKey(evt: KeyboardEvent): void; + + /** + * For handling keydown events on a stand alone calendar + */ + _onKeyDown(evt: KeyboardEvent): void; + + /** + * Deprecated. Notification that a date cell was selected. It may be the same as the previous value. + */ + onValueSelected(date: Date): void; + + onChange(date: Date): void; + + /** + * May be overridden to return CSS classes to associate with the date entry for the given dateObject + * for example to indicate a holiday in specified locale. + */ + getClassForDate(dateObject: Date, locale?: string): string; + + get(name: 'value'): Date; + get(name: string): any; + + set(name: 'value', value: number | Date): this; + set(name: string, value: any): this; + set(values: Object): this; +} + +interface CalendarConstructor extends _WidgetBaseConstructor { + _MonthWidget: _MonthWidgetConstructor; + _MonthDropDown: _MonthDropDownButtonConstructor; + _MonthDropDownButton: _MonthDropDownButtonConstructor; +} + +declare const Calendar: CalendarConstructor; +export = Calendar; diff --git a/src/typings/dijit/CalendarLite.d.ts b/src/typings/dijit/CalendarLite.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/CalendarLite.d.ts @@ -0,0 +1,181 @@ +import _WidgetBase = require("./_WidgetBase"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; +import _TemplatedMixin = require("./_TemplatedMixin"); + +declare namespace CalendarLite { + interface _MonthWidget extends _WidgetBase { + set(name: 'month', value: Date): this; + set(name: string, value: any): this; + set(values: Object): this; + } + + type _MonthWidgetConstructor = _WidgetBaseConstructor<_MonthWidget>; + + interface CalendarLite extends _WidgetBase, _TemplatedMixin { + /** + * Template for main calendar + */ + templateString: string; + + /** + * Template for cell for a day of the week (ex: M) + */ + dowTemplateString: string; + + dateTemplateString: string; + weekTemplateString: string; + + /** + * The currently selected Date, initially set to invalid date to indicate no selection. + */ + value: Date; + + /** + * JavaScript namespace to find calendar routines. If unspecified, uses Gregorian calendar routines + * at dojo/date and dojo/date/locale. + */ + datePackage: string; + + /** + * How to represent the days of the week in the calendar header. See locale + */ + dayWidth: string; + + /** + * Order fields are traversed when user hits the tab key + */ + tabIndex: string; + + /** + * (Optional) The first day of week override. By default the first day of week is determined + * for the current locale (extracted from the CLDR). + * Special value -1 (default value), means use locale dependent value. + */ + dayOffset: number; + + /** + * Date object containing the currently focused date, or the date which would be focused + * if the calendar itself was focused. Also indicates which year and month to display, + * i.e. the current "page" the calendar is on. + */ + currentFocus: Date; + + /** + * Put the summary to the node with role=grid + */ + _setSummaryAttr: string; + + baseClass: string; + + /** + * Runs various tests on the value, checking that it's a valid date, rather + * than blank or NaN. + */ + _isValidDate(value: Date): boolean; + + /** + * Convert Number into Date, or copy Date object. Then, round to nearest day, + * setting to 1am to avoid issues when DST shift occurs at midnight, see #8521, #9366) + */ + _patchDate(value: number | Date): Date; + + /** + * This just sets the content of node to the specified text. + * Can't do "node.innerHTML=text" because of an IE bug w/tables, see #3434. + */ + _setText(node: HTMLElement, text?: string): void; + + /** + * Fills in the calendar grid with each day (1-31). + * Call this on creation, when moving to a new month. + */ + _populateGrid(): void; + + /** + * Fill in localized month, and prev/current/next years + */ + _populateControls(): void; + + /** + * Sets calendar's value to today's date + */ + goToToday(): void; + + /** + * Creates the drop down button that displays the current month and lets user pick a new one + */ + _createMonthWidget(): void; + + buildRendering(): void; + postCreate(): void; + + /** + * Set up connects for increment/decrement of months/years + */ + _connectControls(): void; + + /** + * If the calendar currently has focus, then focuses specified date, + * changing the currently displayed month/year if necessary. + * If the calendar doesn't have focus, updates currently + * displayed month/year, and sets the cell that will get focus + * when Calendar is focused. + */ + _setCurrentFocusAttr(date: Date, forceFocus?: boolean): void; + + /** + * Focus the calendar by focusing one of the calendar cells + */ + focus(): void; + + /** + * Handler for day clicks, selects the date if appropriate + */ + _onDayClick(evt: MouseEvent): void; + + /** + * Returns the cell corresponding to the date, or null if the date is not within the currently + * displayed month. + */ + _getNodeByDate(value: Date): HTMLElement; + + /** + * Marks the specified cells as selected, and clears cells previously marked as selected. + * For CalendarLite at most one cell is selected at any point, but this allows an array + * for easy subclassing. + */ + _markSelectedDates(dates: Date[]): void; + + /** + * Called only when the selected date has changed + */ + onChange(date: Date): void; + + /** + * May be overridden to disable certain dates in the calendar e.g. `isDisabledDate=dojo.date.locale.isWeekend` + */ + isDisabledDate(dateObject: Date, locale?: string): boolean; + + /** + * May be overridden to return CSS classes to associate with the date entry for the given dateObject, + * for example to indicate a holiday in specified locale. + */ + getClassForDate(dateObject: Date, locale?: string): string; + + get(name: 'value'): Date; + get(name: string): any; + + set(name: 'value', value: number | Date): this; + set(name: string, value: any): this; + set(values: Object): this; + } + + interface CalendarLiteConstructor extends _WidgetBaseConstructor { + _MonthWidget: _MonthWidgetConstructor; + } + +} + +declare type CalendarLite = CalendarLite.CalendarLite; +declare const CalendarLite: CalendarLite.CalendarLiteConstructor; +export = CalendarLite; diff --git a/src/typings/dijit/ConfirmDialog.d.ts b/src/typings/dijit/ConfirmDialog.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/ConfirmDialog.d.ts @@ -0,0 +1,8 @@ +import { _ConfirmDialogMixin } from "./_ConfirmDialogMixin"; +import { DialogConstructor } from "./Dialog"; + +interface ConfirmDialog extends _ConfirmDialogMixin { } + +type ConfirmDialogConstructor = DialogConstructor; +declare const ConfirmDialog: ConfirmDialogConstructor; +export = ConfirmDialog; diff --git a/src/typings/dijit/Destroyable.d.ts b/src/typings/dijit/Destroyable.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/Destroyable.d.ts @@ -0,0 +1,24 @@ +import { DeclareConstructor } from "dojo/_base/declare"; + +interface Destroyable { + _destroyed?: true; + + /** + * Destroy this class, releasing any resources registered via own(). + */ + destroy(preserveDom?: boolean): void; + + /** + * Track specified handles and remove/destroy them when this instance is destroyed, unless they were + * already removed/destroyed manually. + */ + own(...args: any[]): any[]; +} + +/** + * Mixin to track handles and release them when instance is destroyed. + */ +interface DestroyableConstructor extends DeclareConstructor { } + +declare const Destroyable: DestroyableConstructor; +export = Destroyable; diff --git a/src/typings/dijit/Dialog.d.ts b/src/typings/dijit/Dialog.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/Dialog.d.ts @@ -0,0 +1,147 @@ +import _TemplatedMixin = require("./_TemplatedMixin"); +import _FormMixin = require("./form/_FormMixin"); +import _DialogMixin = require("./_DialogMixin"); +import _CssStateMixin = require("./_CssStateMixin"); +import { CSSStateNodes } from "./_CssStateMixin"; +import DojoPromise = require("dojo/promise/Promise"); +import { DomGeometryWidthHeight } from "dojo/dom-geometry"; +import { _WidgetBaseConstructor, _WidgetBase } from "./_WidgetBase"; +import ContentPane = require("./layout/ContentPane"); + +interface _DialogBase extends _TemplatedMixin, _FormMixin, _DialogMixin, _CssStateMixin { + templateString: string; + baseClass: string; + cssStateNodes: CSSStateNodes; + + /** + * True if Dialog is currently displayed on screen. + */ + open: boolean; + + /** + * The time in milliseconds it takes the dialog to fade in and out + */ + duration: number; + + /** + * A Toggle to modify the default focus behavior of a Dialog, which + * is to re-focus the element which had focus before being opened. + * False will disable refocusing. Default: true + */ + refocus: boolean; + + /** + * A Toggle to modify the default focus behavior of a Dialog, which + * is to focus on the first dialog element after opening the dialog. + * False will disable autofocusing. Default: true + */ + autofocus: boolean; + + /** + * Toggles the movable aspect of the Dialog. If true, Dialog + * can be dragged by it's title. If false it will remain centered + * in the viewport. + */ + draggable: boolean; + + /** + * Maximum size to allow the dialog to expand to, relative to viewport size + */ + maxRatio: number; + + /** + * Dialog show [x] icon to close itself, and ESC key will close the dialog. + */ + closable: boolean; + postMixInProperties(): void; + postCreate(): void; + + /** + * Called when data has been loaded from an href. + * Unlike most other callbacks, this function can be connected to (via `dojo.connect`) + * but should *not* be overridden. + */ + onLoad(data?: any): void; + + focus(): void; + + /* Not entirely sure of the resolution type of these promises */ + + /** + * Display the dialog + */ + show(): DojoPromise; + + /** + * Hide the dialog + */ + hide(): DojoPromise; + + /** + * Called with no argument when viewport scrolled or viewport size changed. Adjusts Dialog as + * necessary to keep it visible. + * + * Can also be called with an argument (by dojox/layout/ResizeHandle etc.) to explicitly set the + * size of the dialog. + */ + resize(dim?: DomGeometryWidthHeight): void; + + destroy(preserveDom?: boolean): void; +} + +type _DialogBaseConstructor = _WidgetBaseConstructor<_DialogBase>; + +interface Dialog extends ContentPane, _DialogBase { + /* overrides conflicting methods */ + resize(dim?: DomGeometryWidthHeight): void; +} + +interface DialogLevelManager { + _beginZIndex: number; + + /** + * Call right before fade-in animation for new dialog. + * + * Saves current focus, displays/adjusts underlay for new dialog, + * and sets the z-index of the dialog itself. + * + * New dialog will be displayed on top of all currently displayed dialogs. + * Caller is responsible for setting focus in new dialog after the fade-in + * animation completes. + */ + show(dialog: _WidgetBase, underlayAttrs: Object): void; + + /** + * Called when the specified dialog is hidden/destroyed, after the fade-out + * animation ends, in order to reset page focus, fix the underlay, etc. + * If the specified dialog isn't open then does nothing. + * + * Caller is responsible for either setting display:none on the dialog domNode, + * or calling dijit/popup.hide(), or removing it from the page DOM. + */ + hide(dialog: _WidgetBase): void; + + /** + * Returns true if specified Dialog is the top in the task + */ + isTop(dialog: _WidgetBase): boolean; +} + +declare namespace Dialog { + + interface DialogConstructor extends _WidgetBaseConstructor { + /** + * for monkey patching and dojox/widget/DialogSimple + */ + _DialogBase: _DialogBaseConstructor; + _DialogLevelManager: DialogLevelManager; + _dialogStack: { + dialog: _WidgetBase, + focus: any, + underlayAttrs: any + }[]; + } +} + +declare const Dialog: Dialog.DialogConstructor; +export = Dialog; diff --git a/src/typings/dijit/DropDownMenu.d.ts b/src/typings/dijit/DropDownMenu.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/DropDownMenu.d.ts @@ -0,0 +1,12 @@ +import _MenuBase = require("./_MenuBase"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; + +/** + * A menu, without features for context menu (Meaning, drop down menu) + */ +interface DropDownMenu extends _MenuBase { } + +type DropDownMenuConstructor = _WidgetBaseConstructor; + +declare const DropDownMenu: DropDownMenuConstructor; +export = DropDownMenu; diff --git a/src/typings/dijit/Fieldset.d.ts b/src/typings/dijit/Fieldset.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/Fieldset.d.ts @@ -0,0 +1,14 @@ +import { _WidgetBaseConstructor } from "./_WidgetBase"; +import TitlePane = require("./TitlePane"); + +/** + * An accessible fieldset that can be expanded or collapsed via + * its legend. Fieldset extends `dijit.TitlePane`. + */ +interface Fieldset extends TitlePane { + open: boolean; +} + +type FieldsetConstructor = _WidgetBaseConstructor
; +declare const Fieldset: FieldsetConstructor; +export = Fieldset; diff --git a/src/typings/dijit/Menu.d.ts b/src/typings/dijit/Menu.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/Menu.d.ts @@ -0,0 +1,54 @@ +import DropDownMenu = require("./DropDownMenu"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; + +/** + * A context menu you can assign to multiple elements + */ + interface Menu extends DropDownMenu { + /** + * Array of dom node ids of nodes to attach to. + * Fill this with nodeIds upon widget creation and it becomes context menu for those nodes. + */ + targetNodeIds: string[]; + + /** + * CSS expression to apply this Menu to descendants of targetNodeIds, rather than to + * the nodes specified by targetNodeIds themselves. Useful for applying a Menu to + * a range of rows in a table, tree, etc. + * + * The application must require() an appropriate level of dojo/query to handle the selector. + */ + selector: string; + + /** + * If true, right clicking anywhere on the window will cause this context menu to open. + * If false, must specify targetNodeIds. + */ + contextMenuForWindow: boolean; + + /** + * If true, menu will open on left click instead of right click, similar to a file menu. + */ + leftClickToOpen: boolean; + + /** + * When this menu closes, re-focus the element which had focus before it was opened. + */ + refocus: boolean; + + /** + * Attach menu to given node + */ + bindDomNode(node: string | Node): void; + + /** + * Detach menu from given node + */ + unBindDomNode(nodeName: string | Node): void; + } + + interface MenuConstructor extends _WidgetBaseConstructor { } + + declare const Menu: MenuConstructor; + export = Menu; + \ No newline at end of file diff --git a/src/typings/dijit/MenuBar.d.ts b/src/typings/dijit/MenuBar.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/MenuBar.d.ts @@ -0,0 +1,23 @@ +import _MenuBase = require("./_MenuBase"); +import _WidgetBase = require("./_WidgetBase"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; + +interface MenuBar extends _MenuBase { + baseClass: 'dijitMenuBar'; + popupDelay: number; + _isMenuBar: true; + _orient: string[]; + _moveToPopup(evt: Event): void; + focusChild(item: _WidgetBase): void; + _onChildDeselect(item: _WidgetBase): void; + _onLeftArrow(): void; + _onRightArrow(): void; + _onDownArrow(): void; + _onUpArrow(): void; + onItemClick(item: _WidgetBase, evt: Event): void; +} + +interface MenuBarConstructor extends _WidgetBaseConstructor { } + +declare const MenuBar: MenuBarConstructor; +export = MenuBar \ No newline at end of file diff --git a/src/typings/dijit/MenuBarItem.d.ts b/src/typings/dijit/MenuBarItem.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/MenuBarItem.d.ts @@ -0,0 +1,9 @@ +import MenuItem = require("./MenuItem"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; + +interface MenuBarItem extends MenuItem { } + +interface MenuBarItemConstructor extends _WidgetBaseConstructor { } + +declare const MenuBarItem: MenuBarItemConstructor; +export = MenuBarItem; diff --git a/src/typings/dijit/MenuItem.d.ts b/src/typings/dijit/MenuItem.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/MenuItem.d.ts @@ -0,0 +1,69 @@ +import _Widget = require("./_Widget"); +import _TemplatedMixin = require("./_TemplatedMixin"); +import _Contained = require("./_Contained"); +import _CssStateMixin = require("./_CssStateMixin"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; + +interface MenuItem extends _Widget, _TemplatedMixin, _Contained, _CssStateMixin { + /** + * Text for the accelerator (shortcut) key combination, a control, alt, etc. modified keystroke meant to execute the menu item regardless of where the focus is on the page. + * + * Note that although Menu can display accelerator keys, there is no infrastructure to actually catch and execute those accelerators. + */ + accelKey: string; + + /** + * If true, the menu item is disabled. + * If false, the menu item is enabled. + */ + disabled: boolean; + + /** Menu text as HTML */ + label: string; + + /** + * Class to apply to DOMNode to make it display an icon. + */ + iconClass: string; + + /** + * Hook for attr('accelKey', ...) to work. + * Set accelKey on this menu item. + */ + _setAccelKeyAttr(value: string): void; + + /** + * Hook for attr('disabled', ...) to work. + * Enable or disable this menu item. + */ + _setDisabledAttr(value: boolean): void; + + _setLabelAttr(val: string): void; + _setIconClassAttr(val: string): void; + + _fillContent(source: Element): void; + + /** + * Indicate that this node is the currently selected one + */ + _setSelected(selected: boolean): void; + + focus(): void; + + /** + * Deprecated. + * Use set('disabled', bool) instead. + */ + setDisabled(disabled: boolean): void; + + /** + * Deprecated. + * Use set('label', ...) instead. + */ + setLabel(content: string): void; +} + +interface MenuItemConstructor extends _WidgetBaseConstructor { } + +declare const MenuItem: MenuItemConstructor; +export = MenuItem; \ No newline at end of file diff --git a/src/typings/dijit/MenuSeparator.d.ts b/src/typings/dijit/MenuSeparator.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/MenuSeparator.d.ts @@ -0,0 +1,11 @@ +import _WidgetBase = require("./_WidgetBase"); +import _TemplatedMixin = require("./_TemplatedMixin"); +import _Contained = require("./_Contained"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; + +interface MenuSeparator extends _WidgetBase, _TemplatedMixin, _Contained { } + +interface MenuSeparatorConstructor extends _WidgetBaseConstructor { } + +declare const MenuSeparator: MenuSeparatorConstructor; +export = MenuSeparator; diff --git a/src/typings/dijit/PopupMenuBarItem.d.ts b/src/typings/dijit/PopupMenuBarItem.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/PopupMenuBarItem.d.ts @@ -0,0 +1,9 @@ +import { _WidgetBaseConstructor } from "./_WidgetBase"; +import PopupMenuItem = require("./PopupMenuItem"); + +interface PopupMenuBarItem extends PopupMenuItem { } + +interface PopupMenuBarItemConstructor extends _WidgetBaseConstructor { } + +declare const PopupMenuBarItem: PopupMenuBarItemConstructor; +export = PopupMenuBarItem; diff --git a/src/typings/dijit/PopupMenuItem.d.ts b/src/typings/dijit/PopupMenuItem.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/PopupMenuItem.d.ts @@ -0,0 +1,27 @@ +import MenuItem = require("./MenuItem"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; + +/** + * An item in a Menu that spawn a drop down (usually a drop down menu) + */ +interface PopupMenuItem extends MenuItem { + /** + * When Menu is declared in markup, this code gets the menu label and the popup widget from the srcNodeRef. + * + * srcNodeRef.innerHTML contains both the menu item text and a popup widget + * The first part holds the menu item text and the second part is the popup + */ + _fillContent(source: Element): void; + + /** + * Open the popup to the side of/underneath this MenuItem, and optionally focus first item + */ + _openPopup(params: { around?: Element; popup?: Function }, focus?: boolean): void; + + _closePopup(): void; +} + +interface PopupMenuItemConstructor extends _WidgetBaseConstructor { } + +declare const PopupMenuItem: PopupMenuItemConstructor; +export = PopupMenuItem; diff --git a/src/typings/dijit/TitlePane.d.ts b/src/typings/dijit/TitlePane.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/TitlePane.d.ts @@ -0,0 +1,58 @@ +import ContentPane = require("./layout/ContentPane"); +import _TemplatedMixin = require("./_TemplatedMixin"); +import _CssStateMixin = require("./_CssStateMixin"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; + +interface TitlePane extends ContentPane, _TemplatedMixin, _CssStateMixin { + /** + * Whether pane can be opened or closed by clicking the title bar. + */ + toggleable: boolean; + + /** + * Tabindex setting for the title (so users can tab to the title then use space/enter to open/close the title pane) + */ + tabIndex: string; + + /** + * Time in milliseconds to fade in/fade out + */ + duration: number; + + /** + * Don't change this parameter from the default value. + * + * This ContentPane parameter doesn't make sense for TitlePane, since TitlePane is never a child of a layout container, nor should TitlePane try to control the size of an inner widget. + */ + doLayout: boolean; + + /** + * Switches between opened and closed state + */ + toggle(): void; + + /** + * Set the open/close css state for the TitlePane + */ + _setCss(): void; + + /** + * Handler for when user hits a key + */ + _onTitleKey(e: Event): void; + + /** + * Handler when user clicks the title bar + */ + _onTitleClick(): void; + + /** + * Deprecated. Use set('title', ...) instead. + */ + setTitle(): void; +} + +interface TitlePaneConstructor extends _WidgetBaseConstructor { } + +declare const TitlePane: TitlePaneConstructor; +export = TitlePane; \ No newline at end of file diff --git a/src/typings/dijit/Toolbar.d.ts b/src/typings/dijit/Toolbar.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/Toolbar.d.ts @@ -0,0 +1,11 @@ +import _Widget = require("./_Widget"); +import _TemplatedMixin = require("./_TemplatedMixin"); +import _KeyNavContainer = require("./_KeyNavContainer"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; + +interface Toolbar extends _Widget, _TemplatedMixin, _KeyNavContainer { } + +interface ToolbarConstructor extends _WidgetBaseConstructor { } + +declare const Toolbar: ToolbarConstructor; +export = Toolbar; diff --git a/src/typings/dijit/ToolbarSeparator.d.ts b/src/typings/dijit/ToolbarSeparator.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/ToolbarSeparator.d.ts @@ -0,0 +1,10 @@ +import _Widget = require("./_Widget"); +import _TemplatedMixin = require("./_TemplatedMixin"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; + +interface ToolbarSeparator extends _Widget, _TemplatedMixin { } + +interface ToolbarSeparatorConstructor extends _WidgetBaseConstructor { } + +declare const ToolbarSeparator: ToolbarSeparatorConstructor; +export = ToolbarSeparatorConstructor; diff --git a/src/typings/dijit/Tooltip.d.ts b/src/typings/dijit/Tooltip.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/Tooltip.d.ts @@ -0,0 +1,121 @@ +import _Widget = require("./_Widget"); +import { NodeOrString } from "dojo/interfaces"; +import dojo = require("dojo/_base/html"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; +import { PlaceRectangle } from "./place"; + +interface Tooltip extends _Widget { + /** + * HTML to display in the tooltip. + * Specified as innerHTML when creating the widget from markup. + */ + label: string; + + /** + * Number of milliseconds to wait after hovering over/focusing on the object, before + * the tooltip is displayed. + */ + showDelay: number; + + /** + * Number of milliseconds to wait after unhovering the object, before + * the tooltip is hidden. Note that blurring an object hides the tooltip immediately. + */ + hideDelay: number; + + /** + * Id of domNode(s) to attach the tooltip to. + * When user hovers over specified dom node(s), the tooltip will appear. + */ + connectId: NodeOrString | NodeOrString[]; + + /** + * See description of `dijit/Tooltip.defaultPosition` for details on position parameter. + */ + position: string; + + /** + * CSS expression to apply this Tooltip to descendants of connectIds, rather than to + * the nodes specified by connectIds themselves. Useful for applying a Tooltip to + * a range of rows in a table, tree, etc. Use in conjunction with getContent() parameter. + * Ex: connectId: myTable, selector: "tr", getContent: function(node){ return ...; } + * + * The application must require() an appropriate level of dojo/query to handle the selector. + */ + selector: string; + + /** + * Attach tooltip to specified node if it's not already connected + */ + addTarget(node: NodeOrString): void; + + /** + * Detach tooltip from specified node + */ + removeTarget(node: NodeOrString): void; + + /** + * User overridable function that return the text to display in the tooltip. + */ + getContent(node: Node): Node; + + /** + * Display the tooltip; usually not called directly. + */ + open(target: Node): void; + + /** + * Hide the tooltip or cancel timer for show of tooltip + */ + close(): void; + + /** + * Called when the tooltip is shown + */ + onShow(): void; + + /** + * Called when the tooltip is hidden + */ + onHide(): void; +} + +interface TooltipConstructor extends _WidgetBaseConstructor { + /** + * This variable controls the position of tooltips, if the position is not specified to + * the Tooltip widget or *TextBox widget itself. It's an array of strings with the values + * possible for `dijit/place.around()`. The recommended values are: + * + * - before-centered: centers tooltip to the left of the anchor node/widget, or to the right + * in the case of RTL scripts like Hebrew and Arabic + * - after-centered: centers tooltip to the right of the anchor node/widget, or to the left + * in the case of RTL scripts like Hebrew and Arabic + * - above-centered: tooltip is centered above anchor node + * - below-centered: tooltip is centered above anchor node + * + * The list is positions is tried, in order, until a position is found where the tooltip fits + * within the viewport. + * + * Be careful setting this parameter. A value of "above-centered" may work fine until the user scrolls + * the screen so that there's no room above the target node. Nodes with drop downs, like + * DropDownButton or FilteringSelect, are especially problematic, in that you need to be sure + * that the drop down and tooltip don't overlap, even when the viewport is scrolled so that there + * is only room below (or above) the target node, but not both. + */ + defaultPosition: [string]; + + /** + * Static method to display tooltip w/specified contents in specified position. + * See description of dijit/Tooltip.defaultPosition for details on position parameter. + * If position is not specified then dijit/Tooltip.defaultPosition is used. + */ + show(innerHTML: string, aroundNode: PlaceRectangle, position?: [string], rtl?: boolean, textDir?: string, onMouseEnter?: Function, onMouseLeave?: Function): void; + + /** + * Hide the tooltip + */ + hide(aroundNode: PlaceRectangle): void; +} + +declare const Tooltip: TooltipConstructor; +export = Tooltip; diff --git a/src/typings/dijit/TooltipDialog.d.ts b/src/typings/dijit/TooltipDialog.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/TooltipDialog.d.ts @@ -0,0 +1,75 @@ +import ContentPane = require("./layout/ContentPane"); +import _TemplatedMixin = require("./_TemplatedMixin"); +import _FormMixin = require("./form/_FormMixin"); +import _DialogMixin = require("./_DialogMixin"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; +import { PlaceCorner, PlacePosition } from "./place"; + +interface TooltipDialog extends ContentPane, _TemplatedMixin, _FormMixin, _DialogMixin { + /** + * Description of tooltip dialog (required for a11y) + */ + title: string; + + /** + * Don't change this parameter from the default value. + * This ContentPane parameter doesn't make sense for TooltipDialog, since TooltipDialog + * is never a child of a layout container, nor can you specify the size of + * TooltipDialog in order to control the size of an inner widget. + */ + doLayout: boolean; + + /** + * A Toggle to modify the default focus behavior of a Dialog, which + * is to focus on the first dialog element after opening the dialog. + * False will disable autofocusing. Default: true. + */ + autofocus: boolean; + + /** + * The pointer to the first focusable node in the dialog. + */ + _firstFocusItem: any; + + /** + * The pointer to which node has focus prior to our dialog. + */ + _lastFocusItem: any; + + /** + * Configure widget to be displayed in given position relative to the button. + * + * This is called from the dijit.popup code, and should not be called directly. + */ + orient(node: Node | HTMLElement, aroundCorner: PlaceCorner, tooltipCorner: PlaceCorner): void; + + /** + * Focus on first field + */ + focus(): void; + + /** + * Called when dialog is displayed. + * + * This is called from the dijit.popup code, and should not be called directly. + */ + onOpen(pos: { + aroundCorner: PlaceCorner + aroundNodePos: PlacePosition + corner: PlaceCorner + x: number + y: number + }): void; + + /** + * Handler for keydown events + * + * Keep keyboard focus in dialog; close dialog on escape key + */ + _onKey(evt: KeyboardEvent): void; +} + +interface TooltipDialogConstructor extends _WidgetBaseConstructor { } + +declare const TooltipDialog: TooltipDialogConstructor; +export = TooltipDialog; diff --git a/src/typings/dijit/_AttachMixin.d.ts b/src/typings/dijit/_AttachMixin.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_AttachMixin.d.ts @@ -0,0 +1,87 @@ +import { DeclareConstructor } from "dojo/_base/declare"; +import { Handle } from "dojo/interfaces"; +import _WidgetBase = require("./_WidgetBase"); + +declare module "./_WidgetBase" { + interface _WidgetBase { + dojoAttachEvent: string; + dojoAttachPoint: string; + } +} + +declare module "dojo/_base/kernel" { + interface Dijit { + _AttachMixin: _AttachMixinConstructor; + } +} + +interface _AttachMixin { + /** + * List of widget attribute names associated with data-dojo-attach-point=... in the template, ex: ["containerNode", "labelNode"] + */ + _attachPoints: string[]; + + /** + * List of connections associated with data-dojo-attach-event=... in the template + */ + _attachEvents: Handle[]; + + /** + * Object to which attach points and events will be scoped. Defaults to 'this'. + */ + attachScope: any; + + /** + * Search descendants of this.containerNode for data-dojo-attach-point and data-dojo-attach-event. + * + * Should generally be left false (the default value) both for performance and to avoid failures when this.containerNode holds other _AttachMixin instances with their own attach points and events. + */ + searchContainerNode: boolean; + + /** + * Attach to DOM nodes marked with special attributes. + */ + buildRendering(): void; + + /** + * hook for _WidgetsInTemplateMixin + */ + _beforeFillContent(): void; + + /** + * Iterate through the dom nodes and attach functions and nodes accordingly. + * + * Map widget properties and functions to the handlers specified in the dom node and it's descendants. This function iterates over all nodes and looks for these properties: + * - dojoAttachPoint/data-dojo-attach-point + * - dojoAttachEvent/data-dojo-attach-event + */ + _attachTemplateNodes(rootNode: Element | Node): void; + + /** + * Process data-dojo-attach-point and data-dojo-attach-event for given node or widget. + * + * Returns true if caller should process baseNode's children too. + */ + _processTemplateNode( + baseNode: T, + getAttrFunc: (baseNode: T, attr: string) => string, + attachFunc: (node: T, type: string, func?: Function) => Handle + ): boolean; + + /** + * Roughly corresponding to dojo/on, this is the default function for processing a data-dojo-attach-event. Meant to attach to DOMNodes, not to widgets. + */ + _attach(node: Element | Node, type: string, func?: Function): Handle; + + /** + * Detach and clean up the attachments made in _attachtempalteNodes. + */ + _detachTemplateNodes(): void; + + destroyRendering(preserveDom?: boolean): void; +} + +interface _AttachMixinConstructor extends DeclareConstructor<_AttachMixin> { } + +declare const _AttachMixin: _AttachMixinConstructor; +export = _AttachMixin; diff --git a/src/typings/dijit/_BidiMixin.d.ts b/src/typings/dijit/_BidiMixin.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_BidiMixin.d.ts @@ -0,0 +1,27 @@ +import { DeclareConstructor } from "dojo/_base/declare"; + +interface _BidiMixin { + + /** + * Gets the right direction of text. + */ + getTextDir(text: string): string; + + /** + * Set element.dir according to this.textDir, assuming this.textDir has a value. + */ + applyTextDir(element: HTMLElement, text?: string): void; + + /** + * Wraps by UCC (Unicode control characters) option's text according to this.textDir + */ + enforceTextDirWithUcc(option: HTMLOptionElement, text: string): string; + + /** + * Restores the text of origObj, if needed, after enforceTextDirWithUcc, e.g. set("textDir", textDir). + */ + restoreOriginalText(origObj: HTMLOptionElement): HTMLOptionElement; +} + +declare const _BidiMixin: DeclareConstructor<_BidiMixin>; +export = _BidiMixin; diff --git a/src/typings/dijit/_BidiSupport.d.ts b/src/typings/dijit/_BidiSupport.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_BidiSupport.d.ts @@ -0,0 +1,28 @@ +import _WidgetBase = require("./_WidgetBase"); + +declare module "./_WidgetBase" { + interface _WidgetBase { + + /** + * Gets the right direction of text. + */ + getTextDir(text: string): string; + + /** + * Set element.dir according to this.textDir, assuming this.textDir has a value. + */ + applyTextDir(element: HTMLElement, text?: string): void; + + /** + * Wraps by UCC (Unicode control characters) option's text according to this.textDir + */ + enforceTextDirWithUcc(option: HTMLOptionElement, text: string): string; + + /** + * Restores the text of origObj, if needed, after enforceTextDirWithUcc, e.g. set("textDir", textDir). + */ + restoreOriginalText(origObj: HTMLOptionElement): HTMLOptionElement; + } +} + +export = _WidgetBase; diff --git a/src/typings/dijit/_ConfirmDialogMixin.d.ts b/src/typings/dijit/_ConfirmDialogMixin.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_ConfirmDialogMixin.d.ts @@ -0,0 +1,29 @@ +import { DeclareConstructor } from "dojo/_base/declare"; +import _WidgetsInTemplateMixin = require("./_WidgetsInTemplateMixin"); + +interface _ConfirmDialogMixin extends _WidgetsInTemplateMixin { + /** + * HTML snippet for action bar, overrides _DialogMixin.actionBarTemplate + */ + actionBarTemplate: string; + + /** + * Label of OK button. + */ + buttonOk: string; + + /** + * Label of cancel button. + */ + buttonCancel: string; +} + +type _ConfirmDialogMixinContructor = DeclareConstructor<_ConfirmDialogMixin>; + +declare const _ConfirmDialogMixin: _ConfirmDialogMixinContructor + +declare module "dojo/_base/kernel" { + interface Dijit { + _ConfirmDialogMixin: _ConfirmDialogMixinContructor; + } +} diff --git a/src/typings/dijit/_Contained.d.ts b/src/typings/dijit/_Contained.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_Contained.d.ts @@ -0,0 +1,33 @@ +import { DeclareConstructor } from "dojo/_base/declare"; +import _WidgetBase = require("./_WidgetBase"); + +interface _Contained { + /** + * Returns the previous child of the parent or null if this is the + * first child of the parent. + */ + getPreviousSibling(): T; + + /** + * Returns the next child of the parent or null if this is the last + * child of the parent. + */ + getNextSibling(): T; + + /** + * Returns the index of this widget within its container parent. + * It returns -1 if the parent does not exist or if the parent is + * not a dijit/_Container. + */ + getIndexInParent(): number; +} + +declare module "dojo/_base/kernel" { + interface Dijit { + _Contained: _ContainedConstructor; + } +} + +type _ContainedConstructor = DeclareConstructor<_Contained>; +declare const _Contained: _ContainedConstructor; +export = _Contained; diff --git a/src/typings/dijit/_Container.d.ts b/src/typings/dijit/_Container.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_Container.d.ts @@ -0,0 +1,39 @@ +import { DeclareConstructor } from "dojo/_base/declare"; +import _WidgetBase = require("./_WidgetBase"); + +interface _Container { + buildRendering(): void; + + /** + * Makes the given widget a child of this widget. + */ + addChild(widget: T, insertIndex?: number): void; + + /** + * Removes the passed widget instance from this widget but does + * not destroy it. You can also pass in an integer indicating + * the index within the container to remove (ie, removeChild(5) removes the sixth widget) + */ + removeChild(widget: T): void; + removeChild(widget: number): void; + + /** + * Returns true if widget has child widgets, i.e. if this.containerNode contains widgets. + */ + hasChildren(): boolean; + + /** + * Gets the index of the child in this container or -1 if not found + */ + getIndexOfChild(widget: T): number; +} + +declare module "dojo/_base/kernel" { + interface Dijit { + _Container: _ContainerConstructor + } +} + +type _ContainerConstructor = DeclareConstructor<_Container>; +declare const _Container: _ContainerConstructor; +export = _Container; diff --git a/src/typings/dijit/_CssStateMixin.d.ts b/src/typings/dijit/_CssStateMixin.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_CssStateMixin.d.ts @@ -0,0 +1,31 @@ +import { DeclareConstructor } from "dojo/_base/declare"; + +declare namespace _CssStateMixin { + interface CSSStateNodes { + [node: string]: string; + } + + + interface _CssStateMixin { + /** + * True if cursor is over this widget + */ + hovering: boolean; + + /** + * True if mouse was pressed while over this widget, and hasn't been released yet + */ + active: boolean; + } +} + +declare module "dojo/_base/kernel" { + interface Dijit { + _CssStateMixin: _CssStateMixinConstructor + } +} + +type _CssStateMixin = _CssStateMixin._CssStateMixin; +type _CssStateMixinConstructor = DeclareConstructor<_CssStateMixin>; +declare const _CssStateMixin: _CssStateMixinConstructor; +export = _CssStateMixin; diff --git a/src/typings/dijit/_DialogMixin.d.ts b/src/typings/dijit/_DialogMixin.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_DialogMixin.d.ts @@ -0,0 +1,35 @@ +import { DeclareConstructor } from "dojo/_base/declare"; + +interface _DialogMixin { + /** + * HTML snippet to show the action bar (gray bar with OK/cancel buttons). + * Blank by default, but used by ConfirmDialog/ConfirmTooltipDialog subclasses. + */ + actionBarTemplate: string; + + /** + * Callback when the user hits the submit button. + * Override this method to handle Dialog execution. + */ + execute(formContents?: any): void; + + /** + * Called when user has pressed the Dialog's cancel button, to notify container. + */ + onCancel(): void; + + /** + * Called when user has pressed the dialog's OK button, to notify container. + */ + onExecute(): void; +} + +declare module "dojo/_base/kernel" { + interface Dijit { + _DialogMixin: _DialogMixinConstructor + } +} + +type _DialogMixinConstructor = DeclareConstructor<_DialogMixin>; +declare const _DialogMixin: _DialogMixinConstructor; +export = _DialogMixin; diff --git a/src/typings/dijit/_FocusMixin.d.ts b/src/typings/dijit/_FocusMixin.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_FocusMixin.d.ts @@ -0,0 +1,42 @@ +import { DeclareConstructor } from "dojo/_base/declare"; +import { FocusManager } from "./focus"; + +declare module "./_WidgetBase" { + + interface _WidgetBase { + /** + * This widget or a widget it contains has focus, or is "active" because + * it was recently clicked. + */ + focused: boolean; + + /** + * Called when the widget becomes "active" because + * it or a widget inside of it either has focus, or has recently + * been clicked. + */ + onFocus(): void; + + /** + * Called when the widget stops being "active" because + * focus moved to something outside of it, or the user + * clicked somewhere outside of it, or the widget was + * hidden. + */ + onBlur(): void; + } +} + +interface _FocusMixin { + _focusManager: FocusManager; +} + +declare module "dojo/_base/kernel" { + interface Dijit { + _FocusMixin: _FocusMixinConstructor; + } +} + +type _FocusMixinConstructor = DeclareConstructor<_FocusMixin>; +declare const _FocusMixin: _FocusMixinConstructor; +export = _FocusMixin; diff --git a/src/typings/dijit/_HasDropDown.d.ts b/src/typings/dijit/_HasDropDown.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_HasDropDown.d.ts @@ -0,0 +1,140 @@ +import _FocusMixin = require("./_FocusMixin"); +import _WidgetBase = require("./_WidgetBase"); +import { Deferred } from "dojo/Deferred"; +import { PlaceLocation } from "./place"; + +interface _HasDropDown extends _FocusMixin { + /** + * The button/icon/node to click to display the drop down. + * Can be set via a data-dojo-attach-point assignment. + * If missing, then either focusNode or domNode (if focusNode is also missing) will be used. + */ + _buttonNode: HTMLElement; + + /** + * Will set CSS class dijitUpArrow, dijitDownArrow, dijitRightArrow etc. on this node depending + * on where the drop down is set to be positioned. + * Can be set via a data-dojo-attach-point assignment. + * If missing, then _buttonNode will be used. + */ + _arrowWrapperNode: HTMLElement; + + /** + * The node to set the aria-expanded class on. + * Also sets popupActive class but that will be removed in 2.0. + * Can be set via a data-dojo-attach-point assignment. + * If missing, then focusNode or _buttonNode (if focusNode is missing) will be used. + */ + _popupStateNode: HTMLElement; + + /** + * The node to display the popup around. + * Can be set via a data-dojo-attach-point assignment. + * If missing, then domNode will be used. + */ + _aroundNode: HTMLElement; + + /** + * The widget to display as a popup. This widget *must* be + * defined before the startup function is called. + */ + dropDown: T; + + /** + * Set to true to make the drop down at least as wide as this + * widget. Set to false if the drop down should just be its + * default width. + */ + autoWidth: boolean; + + /** + * Set to true to make the drop down exactly as wide as this + * widget. Overrides autoWidth. + */ + forceWidth: boolean; + + /** + * The max height for our dropdown. + * Any dropdown taller than this will have scrollbars. + * Set to 0 for no max height, or -1 to limit height to available space in viewport + */ + maxHeight: number; + + /** + * This variable controls the position of the drop down. + * It's an array of strings + */ + dropDownPosition: string[]; + /* TODO remove for TS 1.8 */ + /* dropDownPosition: ('before' | 'after' | 'above' | 'below')[]; */ + + /** + * When set to false, the click events will not be stopped, in + * case you want to use them in your subclass + */ + _stopClickEvents: boolean; + + /** + * Callback when the user mousedown/touchstart on the arrow icon. + */ + _onDropDownMouseDown(e: MouseEvent): void; + + /** + * Callback on mouseup/touchend after mousedown/touchstart on the arrow icon. + * Note that this function is called regardless of what node the event occurred on (but only after + * a mousedown/touchstart on the arrow). + */ + _onDropDownMouseUp(e?: MouseEvent): void; + + /** + * The drop down was already opened on mousedown/keydown; just need to stop the event + */ + _onDropDownClick(e: MouseEvent): void; + + buildRendering(): void; + postCreate(): void; + destroy(preserveDom?: boolean): void; + + /** + * Returns true if the dropdown exists and it's data is loaded. This can + * be overridden in order to force a call to loadDropDown(). + */ + isLoaded(): boolean; + + /** + * Creates the drop down if it doesn't exist, loads the data + * if there's an href and it hasn't been loaded yet, and then calls + * the given callback. + */ + loadDropDown(loadCallback: () => void): void; + + /** + * Creates the drop down if it doesn't exist, loads the data + * if there's an href and it hasn't been loaded yet, and + * then opens the drop down. This is basically a callback when the + * user presses the down arrow button to open the drop down. + */ + loadAndOpenDropDown(): Deferred; + + /** + * Callback when the user presses the down arrow button or presses + * the down arrow key to open/close the drop down. + * Toggle the drop-down widget; if it is up, close it, if not, open it + */ + toggleDropDown(): void; + + /** + * Opens the dropdown for this widget. To be called only when this.dropDown + * has been created and is ready to display (ie, it's data is loaded). + */ + openDropDown(): PlaceLocation; + + /** + * Closes the drop down on this widget + */ + closeDropDown(focus?: boolean): void; +} + +type _HasDropDownConstructor = _HasDropDown; +declare const _HasDropDown: _HasDropDownConstructor; +export = _HasDropDown; diff --git a/src/typings/dijit/_KeyNavContainer.d.ts b/src/typings/dijit/_KeyNavContainer.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_KeyNavContainer.d.ts @@ -0,0 +1,67 @@ +import _FocusMixin = require("./_FocusMixin"); +import _Container = require("./_Container"); +import _WidgetBase = require("./_WidgetBase"); +import { DeclareConstructor } from "dojo/_base/declare"; +import _KeyNavMixin = require("./_KeyNavMixin"); + +/** + * A _Container with keyboard navigation of its children. + * + * Provides normalized keyboard and focusing code for Container widgets. + * To use this mixin, call connectKeyNavHandlers() in postCreate(). + * Also, child widgets must implement a focus() method. + */ +interface _KeyNavContainer extends _FocusMixin, _KeyNavMixin, _Container { + /** + * Deprecated. You can call this in postCreate() to attach the keyboard handlers to the container, but the preferred method is to override _onLeftArrow() and _onRightArrow(), or _onUpArrow() and _onDownArrow(), to call focusPrev() and focusNext(). + * + * @param prevKeyCodes Key codes for navigating to the previous child. + * @param nextKeyCodes Key codes for navigating to the next child. + */ + connectKeyNavHandlers(prevKeyCodes: number[], nextKeyCodes: number[]): void; + + /** + * @deprecated + */ + startupKeyNavChildren(): void; + + /** + * Setup for each child widget. + * + * Sets tabIndex=-1 on each child, so that the tab key will leave the container rather than visiting each child. + * + * Note: if you add children by a different method than addChild(), then need to call this manually or at least make sure the child's tabIndex is -1. + * + * Note: see also _LayoutWidget.setupChild(), which is also called for each child widget. + */ + _startupChild(widget: _WidgetBase): void; + + /** + * Focus the next widget + */ + focusNext(): void; + + /** + * Focus the last focusable node in the previous widget + * + * (ex: go to the ComboButton icon section rather than button section) + */ + focusPrev(): void; + + /** + * Implement _KeyNavMixin.childSelector, to identify focusable child nodes. + * + * If we allowed a dojo/query dependency from this module this could more simply be a string "> *" instead of this function. + */ + childSelector(node: Element | Node): boolean | void | any; +} + +declare module "dojo/_base/kernel" { + interface Dijit { + _KeyNavContainer: _KeyNavContainerConstructor + } +} + +type _KeyNavContainerConstructor = DeclareConstructor<_KeyNavContainer>; +declare const _KeyNavContainer: _KeyNavContainerConstructor; +export = _KeyNavContainer; diff --git a/src/typings/dijit/_KeyNavMixin.d.ts b/src/typings/dijit/_KeyNavMixin.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_KeyNavMixin.d.ts @@ -0,0 +1,168 @@ +import _FocusMixin = require("./_FocusMixin"); +import _WidgetBase = require("./_WidgetBase"); +import { DeclareConstructor } from "dojo/_base/declare"; + +/** + * A mixin to allow arrow key and letter key navigation of child or descendant widgets. + * It can be used by dijit/_Container based widgets with a flat list of children, or more complex widgets like dijit/Tree. + * + * To use this mixin, the subclass must: + * + * - Implement _getNext(), _getFirst(), _getLast(), _onLeftArrow(), _onRightArrow() _onDownArrow(), _onUpArrow() methods to handle home/end/left/right/up/down keystrokes. Next and previous in this context refer to a linear ordering of the descendants used by letter key search. + * - Set all descendants' initial tabIndex to "-1"; both initial descendants and any descendants added later, by for example addChild() + * - Define childSelector to a function or string that identifies focusable descendant widgets + * + * Also, child widgets must implement a focus() method. + */ +interface _KeyNavMixin extends _FocusMixin { + /** + * Tab index of the container; same as HTML tabIndex attribute. + * Note then when user tabs into the container, focus is immediately moved to the first item in the container. + */ + tabIndex: string; + + /** + * Selector (passed to on.selector()) used to identify what to treat as a child widget. Used to monitor focus events and set this.focusedChild. Must be set by implementing class. If this is a string (ex: "> *") then the implementing class must require dojo/query. + */ + childSelector: string | Function | null; + + /** + * Called on left arrow key, or right arrow key if widget is in RTL mode. + * Should go back to the previous child in horizontal container widgets like Toolbar. + */ + _onLeftArrow(evt?: KeyboardEvent): void; + + /** + * Called on right arrow key, or left arrow key if widget is in RTL mode. + * Should go to the next child in horizontal container widgets like Toolbar. + */ + _onRightArrow(evt?: KeyboardEvent): void; + + /** + * Called on up arrow key. Should go to the previous child in vertical container widgets like Menu. + */ + _onUpArrow(evt?: KeyboardEvent): void; + + /** + * Called on down arrow key. Should go to the next child in vertical container widgets like Menu. + */ + _onDownArrow(evt?: KeyboardEvent): void; + + /** + * Default focus() implementation: focus the first child. + */ + focus(): void; + + /** + * Returns first child that can be focused. + */ + _getFirstFocusableChild(): _WidgetBase; + + /** + * Returns last child that can be focused. + */ + _getLastFocusableChild(): _WidgetBase; + + /** + * Focus the first focusable child in the container. + */ + focusFirstChild(): void; + + /** + * Focus the last focusable child in the container. + */ + focusLastChild(): void; + + /** + * Focus specified child widget. + * + * @param widget Reference to container's child widget + * @param last If true and if widget has multiple focusable nodes, focus the last one instead of the first one + */ + focusChild(widget: _WidgetBase, last?: boolean): void; + + /** + * Handler for when the container itself gets focus. + * + * Initially the container itself has a tabIndex, but when it gets focus, switch focus to first child. + */ + _onContainerFocus(evt: Event): void; + + /** + * Called when a child widget gets focus, either by user clicking it, or programatically by arrow key handling code. + * + * It marks that the current node is the selected one, and the previously selected node no longer is. + */ + _onChildFocus(child?: _WidgetBase): void; + + _searchString: string; + + multiCharSearchDuration: number; + + /** + * When a key is pressed that matches a child item, this method is called so that a widget can take appropriate action is necessary. + */ + onKeyboardSearch(tem: _WidgetBase, evt: Event, searchString: string, numMatches: number): void; + + /** + * Compares the searchString to the widget's text label, returning: + * + * * -1: a high priority match and stop searching + * * 0: not a match + * * 1: a match but keep looking for a higher priority match + */ + _keyboardSearchCompare(item: _WidgetBase, searchString: string): -1 | 0 | 1; + + /** + * When a key is pressed, if it's an arrow key etc. then it's handled here. + */ + _onContainerKeydown(evt: Event): void; + + /** + * When a printable key is pressed, it's handled here, searching by letter. + */ + _onContainerKeypress(evt: Event): void; + + /** + * Perform a search of the widget's options based on the user's keyboard activity + * + * Called on keypress (and sometimes keydown), searches through this widget's children looking for items that match the user's typed search string. Multiple characters typed within 1 sec of each other are combined for multicharacter searching. + */ + _keyboardSearch(evt: Event, keyChar: string): void; + + /** + * Called when focus leaves a child widget to go to a sibling widget. + */ + _onChildBlur(widget: _WidgetBase): void; + + /** + * Returns the next or previous focusable descendant, compared to "child". + * Implements and extends _KeyNavMixin._getNextFocusableChild() for a _Container. + */ + _getNextFocusableChild(child: _WidgetBase, dir: 1 | -1): _WidgetBase | null; + + /** + * Returns the first child. + */ + _getFirst(): _WidgetBase | null; + + /** + * Returns the last descendant. + */ + _getLast(): _WidgetBase | null; + + /** + * Returns the next descendant, compared to "child". + */ + _getNext(child: _WidgetBase, dir: 1 | -1): _WidgetBase | null; +} + +declare module "dojo/_base/kernel" { + interface Dijit { + _KeyNavMixin: _KeyNavMixinConstructor; + } +} + +type _KeyNavMixinConstructor = DeclareConstructor<_KeyNavMixin>; +declare const _KeyNavMixin: _KeyNavMixinConstructor; +export = _KeyNavMixin; \ No newline at end of file diff --git a/src/typings/dijit/_MenuBase.d.ts b/src/typings/dijit/_MenuBase.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_MenuBase.d.ts @@ -0,0 +1,158 @@ +import _KeyNavContainer = require("./_KeyNavContainer"); +import _CssStateMixin = require("./_CssStateMixin"); +import { _WidgetBaseConstructor, _WidgetBase } from "./_WidgetBase"; +import _TemplatedMixin = require("./_TemplatedMixin"); +import _Widget = require("./_Widget"); +import MenuItem = require("./MenuItem"); + +/** + * Abstract base class for Menu and MenuBar. + * Subclass should implement _onUpArrow(), _onDownArrow(), _onLeftArrow(), and _onRightArrow(). + */ +interface _MenuBase extends _Widget, _TemplatedMixin, _KeyNavContainer, _CssStateMixin { + selected: MenuItem | null; + + _setSelectedAttr(item?: MenuItem | null): void; + + /** + * This Menu has been clicked (mouse or via space/arrow key) or opened as a submenu, so mere mouseover will open submenus. Focusing a menu via TAB does NOT automatically make it active since TAB is a navigation operation and not a selection one. + * + * For Windows apps, pressing the ALT key focuses the menubar menus (similar to TAB navigation) but the menu is not active (ie no dropdown) until an item is clicked. + */ + activated: boolean; + + _setActivatedAttr(val: boolean): void; + + /** + * pointer to menu that displayed me + */ + parentMenu: _Widget | null; + + /** + * After a menu has been activated (by clicking on it etc.), number of milliseconds before hovering (without clicking) another MenuItem causes that MenuItem's popup to automatically open. + */ + popupDelay: number; + + /** + * For a passive (unclicked) Menu, number of milliseconds before hovering (without clicking) will cause the popup to open. Default is Infinity, meaning you need to click the menu to open it. + */ + passivePopupDelay: number; + + /** + * A toggle to control whether or not a Menu gets focused when opened as a drop down from a MenuBar or DropDownButton/ComboButton. Note though that it always get focused when opened via the keyboard. + */ + autoFocus: boolean; + + /** + * Selector (passed to on.selector()) used to identify MenuItem child widgets, but exclude inert children like MenuSeparator. If subclass overrides to a string (ex: "> *"), the subclass must require dojo/query. + */ + childSelector(node: Element | Node): boolean | void | Function; + + /** + * Attach point for notification about when a menu item has been executed. This is an internal mechanism used for Menus to signal to their parent to close them, because they are about to execute the onClick handler. In general developers should not attach to or override this method. + */ + onExecute(): void; + + /** + * Attach point for notification about when the user cancels the current menu + * This is an internal mechanism used for Menus to signal to their parent to close them. In general developers should not attach to or override this method. + */ + onCancel(): void; + + /** + * This handles the right arrow key (left arrow key on RTL systems), which will either open a submenu, or move to the next item in the ancestor MenuBar + */ + _moveToPopup(evt: Event): void; + + /** + * This handler is called when the mouse moves over the popup. + */ + _onPopupHover(evt?: MouseEvent): void; + + /** + * Called when cursor is over a MenuItem. + */ + onItemHover(item: MenuItem): void; + + /** + * Called when a child MenuItem becomes deselected. Setup timer to close its popup. + */ + _onChildDeselect(item: MenuItem): void; + + /** + * Callback fires when mouse exits a MenuItem + */ + onItemUnhover(item: MenuItem): void; + + /** + * Cancels the popup timer because the user has stop hovering on the MenuItem, etc. + */ + _stopPopupTimer(): void; + + /** + * Cancels the pending-close timer because the close has been preempted + */ + _stopPendingCloseTimer(): void; + + /** + * Returns the top menu in this chain of Menus + */ + _getTopMenu(): void; + + /** + * Handle clicks on an item. + */ + onItemClick(item: _WidgetBase, evt: Event): void; + + /** + * Open the popup to the side of/underneath the current menu item, and optionally focus first item + */ + _openItemPopup(fromItem: MenuItem, focus: boolean): void; + + /** + * Callback when this menu is opened. + * This is called by the popup manager as notification that the menu was opened. + */ + onOpen(evt?: Event): void; + + /** + * Callback when this menu is closed. + * This is called by the popup manager as notification that the menu was closed. + */ + onClose(): boolean; + + /** + * Called when submenu is clicked or focus is lost. Close hierarchy of menus. + */ + _closeChild(): void; + /** + * Called when child of this Menu gets focus from: + * + * 1. clicking it + * 2. tabbing into it + * 3. being opened by a parent menu. + * + * This is not called just from mouse hover. + */ + _onItemFocus(item: MenuItem): void; + + /** + * Called when focus is moved away from this Menu and it's submenus. + */ + _onBlur(): void; + + /** + * Called when the user is done with this menu. Closes hierarchy of menus. + */ + _cleanUp(clearSelectedItem?: boolean): void; +} + +declare module "dojo/_base/kernel" { + interface Dijit { + _MenuBase: _MenuBaseConstructor; + } +} + +type _MenuBaseConstructor = _WidgetBaseConstructor<_MenuBase>; +declare const _MenuBase: _MenuBaseConstructor; +export = _MenuBase; diff --git a/src/typings/dijit/_OnDijitClickMixin.d.ts b/src/typings/dijit/_OnDijitClickMixin.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_OnDijitClickMixin.d.ts @@ -0,0 +1,32 @@ +import { DeclareConstructor } from "dojo/_base/declare"; +import { ExtensionEvent } from "dojo/on"; +import { WatchHandle } from "dojo/interfaces"; +import { A11yClick } from "./a11yclick"; + +interface _OnDijitClickMixin { + /** + * override _WidgetBase.connect() to make this.connect(node, "ondijitclick", ...) work + */ + connect(obj: any, event: string | ExtensionEvent, method: string | EventListener): WatchHandle; +} + +/** + * Deprecated. New code should access the dijit/a11yclick event directly, ex: + * this.own(on(node, a11yclick, function(){ ... })); + * + * Mixing in this class will make _WidgetBase.connect(node, "ondijitclick", ...) work. + * It also used to be necessary to make templates with ondijitclick work, but now you can just require + * dijit/a11yclick. + */ +interface _OnDijitClickMixinConstructor extends DeclareConstructor<_OnDijitClickMixin>{ + a11yclick: A11yClick; +} + +declare module "dojo/_base/kernel" { + interface Dijit { + _OnDijitClickMixin: _OnDijitClickMixinConstructor; + } +} + +declare const _OnDijitClickMixin: _OnDijitClickMixinConstructor; +export = _OnDijitClickMixin; diff --git a/src/typings/dijit/_TemplatedMixin.d.ts b/src/typings/dijit/_TemplatedMixin.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_TemplatedMixin.d.ts @@ -0,0 +1,45 @@ +import _AttachMixin = require("./_AttachMixin"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; + +interface _TemplatedMixin extends _AttachMixin { + + /** + * A string that represents the widget template. + * Use in conjunction with dojo.cache() to load from a file. + */ + templateString: string; + + /** + * Path to template (HTML file) for this widget relative to dojo.baseUrl. + * Deprecated: use templateString with require([... "dojo/text!..."], ...) instead + */ + templatePath: string; + + /** + * Set _AttachMixin.searchContainerNode to true for back-compat for widgets that have data-dojo-attach-point's + * and events inside this.containerNode. Remove for 2.0. + */ + searchContainerNode: boolean; + + /** + * Construct the UI for this widget from a template, setting this.domNode. + */ + buildRendering(): void; +} + +interface _TemplatedMixinConstructor extends _WidgetBaseConstructor<_TemplatedMixin> { + /** + * Static method to get a template based on the templatePath or + * templateString key + */ + getCachedTemplate(templateString: string, alwaysUseString: string, doc?: Document): string | HTMLElement; +} + +declare module "dojo/_base/kernel" { + interface Dijit { + _TemplatedMixin: _TemplatedMixinConstructor; + } +} + +declare const _TemplatedMixin: _TemplatedMixinConstructor; +export = _TemplatedMixin; diff --git a/src/typings/dijit/_Widget.d.ts b/src/typings/dijit/_Widget.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_Widget.d.ts @@ -0,0 +1,115 @@ +import _WidgetBase = require("./_WidgetBase"); +import _OnDijitClickMixin = require("./_OnDijitClickMixin"); +import _FocusMixin = require("./_FocusMixin"); +import { _WidgetBaseConstructor } from "./_WidgetBase"; + +interface _Widget extends _WidgetBase, _OnDijitClickMixin, _FocusMixin { + /** + * Connect to this function to receive notifications of mouse click events. + */ + onClick(event: DocumentEvent): void; + + /** + * Connect to this function to receive notifications of mouse double click events. + */ + onDblClick(event: DocumentEvent): void; + + /** + * Connect to this function to receive notifications of keys being pressed down. + */ + onKeyDown(event: DocumentEvent): void; + + /** + * Connect to this function to receive notifications of printable keys being typed. + */ + onKeyPress(event: DocumentEvent): void; + + /** + * Connect to this function to receive notifications of keys being released. + */ + onKeyUp(event: DocumentEvent): void; + + /** + * Connect to this function to receive notifications of when the mouse button is pressed down. + */ + onMouseDown(event: DocumentEvent): void; + + /** + * Connect to this function to receive notifications of when the mouse moves over nodes contained within this widget. + */ + onMouseMove(event: DocumentEvent): void; + + /** + * Connect to this function to receive notifications of when the mouse moves off of nodes contained within this widget. + */ + onMouseOut(event: DocumentEvent): void; + + /** + * Connect to this function to receive notifications of when the mouse moves onto nodes contained within this widget. + */ + onMouseOver(event: DocumentEvent): void; + + /** + * Connect to this function to receive notifications of when the mouse moves off of this widget. + */ + onMouseLeave(event: DocumentEvent): void; + + /** + * Connect to this function to receive notifications of when the mouse moves onto this widget. + */ + onMouseEnter(event: DocumentEvent): void; + + /** + * Connect to this function to receive notifications of when the mouse button is released. + */ + onMouseUp(event: DocumentEvent): void; + + postCreate(): void; + + /** + * Deprecated. Use set() instead. + */ + setAttribute(attr: string, value: any): void; + + /** + * This method is deprecated, use get() or set() directly. + */ + attr(name: string | { [attr: string]: any }, value?: any): any; + + /** + * Returns all the widgets contained by this, i.e., all widgets underneath this.containerNode. + */ + getDescendants(): _Widget[]; + + /** + * Called when this widget becomes the selected pane in a + * `dijit/layout/TabContainer`, `dijit/layout/StackContainer`, + * `dijit/layout/AccordionContainer`, etc. + * + * Also called to indicate display of a `dijit.Dialog`, `dijit.TooltipDialog`, or `dijit.TitlePane`. + */ + onShow(): void; + + /** + * Called when another widget becomes the selected pane in a + * `dijit/layout/TabContainer`, `dijit/layout/StackContainer`, + * `dijit/layout/AccordionContainer`, etc. + * + * Also called to indicate hide of a `dijit.Dialog`, `dijit.TooltipDialog`, or `dijit.TitlePane`. + */ + onHide(): void; + + /** + * Called when this widget is being displayed as a popup (ex: a Calendar popped + * up from a DateTextBox), and it is hidden. + * This is called from the dijit.popup code, and should not be called directly. + * + * Also used as a parameter for children of `dijit/layout/StackContainer` or subclasses. + * Callback if a user tries to close the child. Child will be closed if this function returns true. + */ + onClose(): boolean; +} + +type _WidgetConstructor = _WidgetBaseConstructor<_Widget>; +declare const _Widget: _WidgetConstructor; +export = _Widget; diff --git a/src/typings/dijit/_WidgetBase.d.ts b/src/typings/dijit/_WidgetBase.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_WidgetBase.d.ts @@ -0,0 +1,241 @@ +import Stateful = require("dojo/Stateful"); +import Destroyable = require("./Destroyable"); +import { ExtensionEvent } from "dojo/on"; +import { NodeFragmentOrString, Handle, NodeOrString, WatchHandle } from "dojo/interfaces"; +import { DeclareConstructor } from "dojo/_base/declare"; + +declare namespace _WidgetBase { + + interface _WidgetBase extends Stateful, Destroyable { + + /** + * A unique, opaque ID string that can be assigned by users or by the + * system. If the developer passes an ID which is known not to be + * unique, the specified ID is ignored and the system-generated ID is + * used instead. + */ + id: string; + + /** + * Rarely used. Overrides the default Dojo locale used to render this widget, + * as defined by the [HTML LANG](http://www.w3.org/TR/html401/struct/dirlang.html#adef-lang) attribute. + * Value must be among the list of locales specified during by the Dojo bootstrap, + * formatted according to [RFC 3066](http://www.ietf.org/rfc/rfc3066.txt) (like en-us). + */ + lang: string; + + /** + * Bi-directional support, as defined by the [HTML DIR](http://www.w3.org/TR/html401/struct/dirlang.html#adef-dir) + * attribute. Either left-to-right "ltr" or right-to-left "rtl". If undefined, widgets renders in page's + * default direction. + */ + dir: string; + + /** + * HTML class attribute + */ + class: string; + + /** + * HTML style attributes as cssText string or name/value hash + */ + style: string; + + /** + * HTML title attribute. + * + * For form widgets this specifies a tooltip to display when hovering over + * the widget (just like the native HTML title attribute). + * + * For TitlePane or for when this widget is a child of a TabContainer, AccordionContainer, + * etc., it's used to specify the tab label, accordion pane title, etc. In this case it's + * interpreted as HTML. + */ + title: string; + + /** + * When this widget's title attribute is used to for a tab label, accordion pane title, etc., + * this specifies the tooltip to appear when the mouse is hovered over that text. + */ + tooltip: string; + + /** + * Root CSS class of the widget (ex: dijitTextBox), used to construct CSS classes to indicate + * widget state. + */ + baseClass: string; + + /** + * pointer to original DOM node + */ + srcNodeRef: HTMLElement; + + /** + * This is our visible representation of the widget! Other DOM + * Nodes may by assigned to other properties, usually through the + * template system's data-dojo-attach-point syntax, but the domNode + * property is the canonical "top level" node in widget UI. + */ + domNode: HTMLElement; + + /** + * Designates where children of the source DOM node will be placed. + * "Children" in this case refers to both DOM nodes and widgets. + */ + containerNode: HTMLElement; + + /** + * The document this widget belongs to. If not specified to constructor, will default to + * srcNodeRef.ownerDocument, or if no sourceRef specified, then to the document global + */ + ownerDocument: HTMLElement; + + /** + * Deprecated. Instead of attributeMap, widget should have a _setXXXAttr attribute + * for each XXX attribute to be mapped to the DOM. + */ + attributeMap: { [attribute: string]: any }; + + /** + * Bi-directional support, the main variable which is responsible for the direction of the text. + * The text direction can be different than the GUI direction by using this parameter in creation + * of a widget. + */ + textDir: string; + + /** + * Kicks off widget instantiation. See create() for details. + */ + postscript(params?: any, srcNodeRef?: HTMLElement): void; + + /** + * Kick off the life-cycle of a widget + */ + create(params?: any, srcNodeRef?: HTMLElement): void; + + /** + * Called after the parameters to the widget have been read-in, + * but before the widget template is instantiated. Especially + * useful to set properties that are referenced in the widget + * template. + */ + postMixInProperties(): void; + + /** + * Construct the UI for this widget, setting this.domNode. + * Most widgets will mixin `dijit._TemplatedMixin`, which implements this method. + */ + buildRendering(): void; + + /** + * Processing after the DOM fragment is created + */ + postCreate(): void; + + /** + * Processing after the DOM fragment is added to the document + */ + startup(): void; + + /** + * Destroy this widget and its descendants + */ + destroyRecursive(preserveDom?: boolean): void; + + /** + * Destroys the DOM nodes associated with this widget. + */ + destroyRendering(preserveDom?: boolean): void; + + /** + * Recursively destroy the children of this widget and their + * descendants. + */ + destroyDescendants(preserveDom?: boolean): void; + + /** + * Deprecated. Override destroy() instead to implement custom widget tear-down + * behavior. + */ + uninitialize(): boolean; + + /** + * Used by widgets to signal that a synthetic event occurred, ex: + * | myWidget.emit("attrmodified-selectedChildWidget", {}). + */ + emit(type: string, eventObj?: any, callbackArgs?: any[]): any; + + /** + * Call specified function when event occurs, ex: myWidget.on("click", function(){ ... }). + */ + on(type: string | ExtensionEvent, func: EventListener | Function): WatchHandle; + + /** + * Returns a string that represents the widget. + */ + toString(): string; + + /** + * Returns all direct children of this widget, i.e. all widgets underneath this.containerNode whose parent + * is this widget. Note that it does not return all descendants, but rather just direct children. + */ + getChildren(): T[]; + + /** + * Returns the parent widget of this widget. + */ + getParent(): T; + + /** + * Deprecated, will be removed in 2.0, use this.own(on(...)) or this.own(aspect.after(...)) instead. + */ + connect(obj: any, event: string | ExtensionEvent, method: string | EventListener): WatchHandle; + + /** + * Deprecated, will be removed in 2.0, use handle.remove() instead. + */ + disconnect(handle: WatchHandle): void; + + /** + * Deprecated, will be removed in 2.0, use this.own(topic.subscribe()) instead. + */ + subscribe(t: string, method: EventListener): WatchHandle; + + /** + * Deprecated, will be removed in 2.0, use handle.remove() instead. + */ + unsubscribe(handle: WatchHandle): void; + + /** + * Return this widget's explicit or implicit orientation (true for LTR, false for RTL) + */ + isLeftToRight(): boolean; + + /** + * Return true if this widget can currently be focused + * and false if not + */ + isFocusable(): boolean; + + /** + * Place this widget somewhere in the DOM based + * on standard domConstruct.place() conventions. + */ + placeAt(reference: NodeFragmentOrString | T, position?: string | number): this; + + /** + * Wrapper to setTimeout to avoid deferred functions executing + * after the originating widget has been destroyed. + * Returns an object handle with a remove method (that returns null) (replaces clearTimeout). + */ + defer(fcn: Function, delay?: number): Handle; + } + + interface _WidgetBaseConstructor extends DeclareConstructor { + new(params: Object, srcNodeRef: NodeOrString): W; + } +} + +type _WidgetBase = _WidgetBase._WidgetBase; +declare const _WidgetBase: _WidgetBase._WidgetBaseConstructor; +export = _WidgetBase; diff --git a/src/typings/dijit/_WidgetsInTemplateMixin.d.ts b/src/typings/dijit/_WidgetsInTemplateMixin.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_WidgetsInTemplateMixin.d.ts @@ -0,0 +1,21 @@ +import { _WidgetBaseConstructor } from "./_WidgetBase"; + +interface _WidgetsInTemplateMixin { + /** + * Used to provide a context require to dojo/parser in order to be + * able to use relative MIDs (e.g. `./Widget`) in the widget's template. + */ + contextRequire: Function; + + startup(): void; +} + +declare module "dojo/_base/kernel" { + interface Dijit { + _WidgetsInTemplateMixin: _WidgetsInTemplateMixinConstructor + } +} + +type _WidgetsInTemplateMixinConstructor = _WidgetBaseConstructor<_WidgetsInTemplateMixin>; +declare const _WidgetsInTemplateMixin: _WidgetsInTemplateMixinConstructor; +export = _WidgetsInTemplateMixin; diff --git a/src/typings/dijit/_base/focus.d.ts b/src/typings/dijit/_base/focus.d.ts new file mode 100644 --- /dev/null +++ b/src/typings/dijit/_base/focus.d.ts @@ -0,0 +1,84 @@ +import dijit = require("../main"); +import _WidgetBase = require("dijit/_WidgetBase"); + +type Bookmark = { isCollapsed: boolean, mark?: Range }; +type FocusNode = Element | null; +type RemoveHandle = { remove(): void }; + +/** + * Deprecated module to monitor currently focused node and stack of currently focused widgets. + * + * New code should access dijit/focus directly. + */ +declare module "dojo/_base/kernel" { + interface Dijit { + /** + * Currently focused item on screen + */ + _curFocus: FocusNode; + + /** + * Previously focused item on screen + */ + _prevFocus: FocusNode; + + /** + * Returns true if there is no text selected + */ + isCollapsed(): boolean; + + /** + * Retrieves a bookmark that can be used with moveToBookmark to return to the same range + */ + getBookmark(): Bookmark; + + /** + * Moves current selection to a bookmark + */ + moveToBookmark(bookmark: Bookmark): void; + + /** + * Called as getFocus(), this returns an Object showing the current focus and selected text. + * + * Called as getFocus(widget), where widget is a (widget representing) a button that was just pressed, it returns where focus was before that button was pressed. (Pressing the button may have either shifted focus to the button, or removed focus altogether.) In this case the selected text is not returned, since it can't be accurately determined. + */ + getFocus(menu: _WidgetBase, openedForWindow?: Window): { + node: FocusNode; + bookmark: any; + openedForWindow?: Window + }; + + /** + * List of currently active widgets (focused widget and it's ancestors) + */ + _activeStack: _WidgetBase[]; + + /** + * Registers listeners on the specified iframe so that any click or focus event on that iframe (or anything in it) is reported as a focus/click event on the `