Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions types/ckeditor__ckeditor5-ui/ckeditor__ckeditor5-ui-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ import {
ToolbarView,
TooltipView,
View,
ViewCollection,
ViewCollection
} from '@ckeditor/ckeditor5-ui';
import preventDefault from '@ckeditor/ckeditor5-ui/src/bindings/preventdefault';
import DropdownPanelView from '@ckeditor/ckeditor5-ui/src/dropdown/dropdownpanelview';
import DropdownView from '@ckeditor/ckeditor5-ui/src/dropdown/dropdownview';
import IframeView from '@ckeditor/ckeditor5-ui/src/iframe/iframeview';
import LabeledInputView from '@ckeditor/ckeditor5-ui/src/labeledinput/labeledinputview';
import ListSeparatorView from '@ckeditor/ckeditor5-ui/src/list/listseparatorview';
import ToolbarLineBreakView from '@ckeditor/ckeditor5-ui/src/toolbar/toolbarlinebreakview';
import { DomEmitterMixin, EmitterMixin, FocusTracker, KeystrokeHandler, Locale } from '@ckeditor/ckeditor5-utils';
import InputView from '@ckeditor/ckeditor5-ui/src/input/inputview';
import InputNumberView from '@ckeditor/ckeditor5-ui/src/inputnumber/inputnumberview';
import { createLabeledInputNumber } from '@ckeditor/ckeditor5-ui/src/labeledfield/utils';
import LabeledInputView from '@ckeditor/ckeditor5-ui/src/labeledinput/labeledinputview';
import ListSeparatorView from '@ckeditor/ckeditor5-ui/src/list/listseparatorview';
import ToolbarLineBreakView from '@ckeditor/ckeditor5-ui/src/toolbar/toolbarlinebreakview';
import { DomEmitterMixin, FocusTracker, KeystrokeHandler, Locale } from '@ckeditor/ckeditor5-utils';

let num = 0;
let str = '';
Expand Down Expand Up @@ -117,6 +117,11 @@ view.destroy();
htmlelement = view.element!;
view.element === null;

// $ExpectType void | undefined
view.disableCssTransitions?.();
// $ExpectType void | undefined
view.enableCssTransitions?.();

/**
* ViewCollection
*/
Expand Down Expand Up @@ -233,7 +238,7 @@ str = tooltip.text;
* clickOutsideHandler
*/
clickOutsideHandler({
emitter: Object.create(EmitterMixin),
emitter: new View(),
activator: () => false,
contextElements: [document.createElement('div')],
callback: () => {},
Expand Down
13 changes: 10 additions & 3 deletions types/ckeditor__ckeditor5-ui/src/bindings/clickoutsidehandler.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Emitter } from "@ckeditor/ckeditor5-utils/src/emittermixin";
import { Emitter } from '@ckeditor/ckeditor5-utils/src/dom/emittermixin';

export default function clickOutsideHandler(options?: {
/**
* Handles clicking **outside** of a specified set of elements, then fires an action.
*
* **Note**: Actually, the action is executed upon `mousedown`, not `click`. It prevents
* certain issues when the user keeps holding the mouse button and the UI cannot react
* properly.
*/
export default function clickOutsideHandler(options: {
emitter: Emitter;
activator: () => boolean;
contextElements: HTMLElement[];
callback: () => void;
contextElements: HTMLElement[];
}): void;
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
import View from "../view";
import View from '../view';

/**
* A decorator that brings the possibility to temporarily disable CSS transitions using
* {@link module:ui/view~View} methods. It is helpful when, for instance, the transitions should not happen
* when the view is first displayed but they should work normal in other cases.
*
* The methods to control the CSS transitions are:
* * `disableCssTransitions()` – Adds the `.ck-transitions-disabled` class to the
* {@link module:ui/view~View#element view element}.
* * `enableCssTransitions()` – Removes the `.ck-transitions-disabled` class from the
* {@link module:ui/view~View#element view element}.
*
* **Note**: This helper extends the {@link module:ui/view~View#template template} and must be used **after**
* {@link module:ui/view~View#setTemplate} is called:
*
* import injectCssTransitionDisabler from '@ckeditor/ckeditor5-ui/src/bindings/injectcsstransitiondisabler';
*
* class MyView extends View {
* constructor() {
* super();
*
* // ...
*
* this.setTemplate( { ... } );
*
* // ...
*
* injectCssTransitionDisabler( this );
*
* // ...
* }
* }
*
* The usage comes down to:
*
* const view = new MyView();
*
* // ...
*
* view.disableCssTransitions();
* view.show();
* view.enableCssTransitions();
*/
export default function injectCssTransitionDisabler(view: View): void;
23 changes: 21 additions & 2 deletions types/ckeditor__ckeditor5-ui/src/bindings/preventdefault.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
import { TemplateToBinding } from "../template";
import View from "../view";
import { TemplateToBinding } from '../template';
import View from '../view';

/**
* A helper which executes a native `Event.preventDefault()` if the target of an event equals the
* {@link module:ui/view~View#element element of the view}. It shortens the definition of a
* {@link module:ui/view~View#template template}.
*
* // In a class extending View.
* import preventDefault from '@ckeditor/ckeditor5-ui/src/bindings/preventdefault';
*
* // ...
*
* this.setTemplate( {
* tag: 'div',
*
* on: {
* // Prevent the default mousedown action on this view.
* mousedown: preventDefault( this )
* }
* } );
*/
export default function preventDefault(view: View): TemplateToBinding;
34 changes: 33 additions & 1 deletion types/ckeditor__ckeditor5-ui/src/bindings/submithandler.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
import View from "../view";
import View from '../view';

/**
* A handler useful for {@link module:ui/view~View views} working as HTML forms. It intercepts a native DOM
* `submit` event, prevents the default web browser behavior (navigation and page reload) and
* fires the `submit` event on a view instead. Such a custom event can be then used by any
* {@link module:utils/dom/emittermixin~Emitter emitter}, e.g. to serialize the form data.
*
* import submitHandler from '@ckeditor/ckeditor5-ui/src/bindings/submithandler';
*
* // ...
*
* class AnyFormView extends View {
* constructor() {
* super();
*
* // ...
*
* submitHandler( {
* view: this
* } );
* }
* }
*
* // ...
*
* const view = new AnyFormView();
*
* // A sample listener attached by an emitter working with the view.
* this.listenTo( view, 'submit', () => {
* saveTheFormData();
* hideTheForm();
* } );
*/
export default function submitHandler(options: { view: View }): void;
3 changes: 3 additions & 0 deletions types/ckeditor__ckeditor5-ui/src/view.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ export default class View implements DomEmitter, Observable {
*/
destroy(): void;

enableCssTransitions?(): void;
disableCssTransitions?(): void;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It would be great if I could do

declare module "../view" {
  class View {
    enableCssTransitions(): void;
    disableCssTransitions(): void;
  }
}

from injectcsstransitiondisabler.d.ts since these methods are only added if this latter is imported.

set(option: Record<string, unknown>): void;
set(name: string, value: unknown): void;
bind(...bindProperties: string[]): BindChain;
Expand Down