2019-04-05 15:39:09 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
|
|
*/
|
|
|
|
|
2020-06-24 23:18:28 +02:00
|
|
|
import { IInterpreterRenderHandlers } from 'src/plugins/expressions';
|
2019-04-05 15:39:09 +02:00
|
|
|
|
2020-06-24 23:18:28 +02:00
|
|
|
type GenericRendererCallback = (callback: () => void) => void;
|
|
|
|
|
|
|
|
export interface RendererHandlers extends IInterpreterRenderHandlers {
|
|
|
|
/** Handler to invoke when an element should be destroyed. */
|
|
|
|
destroy: () => void;
|
2020-02-04 22:41:02 +01:00
|
|
|
/** Get the id of the element being rendered. Can be used as a unique ID in a render function */
|
|
|
|
getElementId: () => string;
|
2019-08-06 23:47:45 +02:00
|
|
|
/** Retrieves the value of the filter property on the element object persisted on the workpad */
|
|
|
|
getFilter: () => string;
|
2020-06-24 23:18:28 +02:00
|
|
|
/** Handler to invoke when a renderer is considered complete */
|
|
|
|
onComplete: (fn: () => void) => void;
|
2020-01-13 21:40:05 +01:00
|
|
|
/** Handler to invoke when a rendered embeddable is destroyed */
|
|
|
|
onEmbeddableDestroyed: () => void;
|
2020-06-24 23:18:28 +02:00
|
|
|
/** Handler to invoke when the input to a function has changed internally */
|
|
|
|
onEmbeddableInputChange: (expression: string) => void;
|
|
|
|
/** Handler to invoke when an element's dimensions have changed*/
|
|
|
|
onResize: GenericRendererCallback;
|
|
|
|
/** Handler to invoke when an element should be resized. */
|
|
|
|
resize: (size: { height: number; width: number }) => void;
|
|
|
|
/** Sets the value of the filter property on the element object persisted on the workpad */
|
|
|
|
setFilter: (filter: string) => void;
|
2019-04-05 15:39:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface RendererSpec<RendererConfig = {}> {
|
2019-08-06 23:47:45 +02:00
|
|
|
/** The render type */
|
2019-04-05 15:39:09 +02:00
|
|
|
name: string;
|
2019-08-06 23:47:45 +02:00
|
|
|
/** The name to display */
|
2019-04-05 15:39:09 +02:00
|
|
|
displayName: string;
|
2019-08-06 23:47:45 +02:00
|
|
|
/** A description of what is rendered */
|
2019-04-05 15:39:09 +02:00
|
|
|
help: string;
|
2019-08-06 23:47:45 +02:00
|
|
|
/** Indicate whether the element should reuse the existing DOM element when re-rendering */
|
2019-04-05 15:39:09 +02:00
|
|
|
reuseDomNode: boolean;
|
2019-08-06 23:47:45 +02:00
|
|
|
/** The default width of the element in pixels */
|
|
|
|
width?: number;
|
|
|
|
/** The default height of the element in pixels */
|
|
|
|
height?: number;
|
|
|
|
/** A function that renders an element into the specified DOM element */
|
2019-04-05 15:39:09 +02:00
|
|
|
render: (domNode: HTMLElement, config: RendererConfig, handlers: RendererHandlers) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type RendererFactory<RendererConfig = {}> = () => RendererSpec<RendererConfig>;
|
2020-08-11 17:36:08 +02:00
|
|
|
|
|
|
|
export type AnyRendererFactory = RendererFactory<any>;
|
|
|
|
export type AnyRendererSpec = RendererSpec<any>;
|