UNPKG

@blockly/field-date

Version:

A Blockly date picker field that uses the browser's date picker.

121 lines 3.97 kB
/** * @license * Copyright 2023 Google LLC * SPDX-License-Identifier: Apache-2.0 */ /** * @fileoverview Plugin overview. */ import * as Blockly from 'blockly/core'; /** * Class for a date input field. */ export declare class FieldDate extends Blockly.FieldTextInput { /** * Serializable fields are saved by the XML renderer, non-serializable fields * are not. Editable fields should also be serializable. */ SERIALIZABLE: boolean; /** * Class for a date input field. Derived from the Closure library date * picker. * * @param value The initial value of the field. Should be in * 'YYYY-MM-DD' format. Defaults to the current date. * @param validator A function that is called to validate * changes to the field's value. Takes in a date string & returns a * validated date string ('YYYY-MM-DD' format), or null to abort the * change. * @param config A map of options used to configure the field. */ constructor(value?: string, validator?: FieldDateValidator, config?: FieldDateConfig); /** * Constructs a FieldDate from a JSON arg object. * * @param options A JSON object with options (date). * @returns The new field instance. * @package * @nocollapse */ static fromJson(options: FieldDateFromJsonConfig): FieldDate; /** * Ensures that the input value is a valid date. Additionally, if the date * string provided includes a time, the time will be removed and the date for * relative to the user's timezone will be used. * * @param newValue The input value. Ex: '2023-04-28' * @returns A valid date string, or null if invalid. * @override */ protected doClassValidation_(newValue?: string): string | null; /** * Get the text to display on the block when the input hasn't spawned in. * * @returns The text to display on the block. * @override */ protected getText_(): string | null; /** * Renders the field. If the picker is shown make sure it has the current * date selected. */ protected render_(): void; /** * Shows the inline free-text editor on top of the text along with the date * editor. * * @param e Optional mouse event that triggered the field to * open, or undefined if triggered programmatically. * @override */ protected showEditor_(e?: Event): void; /** * Updates the size of the field based on the text. * * @param margin margin to use when positioning the text element. * @override */ protected updateSize_(margin?: number): void; /** * Shows the datepicker. */ private showDropdown; /** * Create the html input and set it to type date. * * @returns The newly created date input editor. */ protected widgetCreate_(): HTMLInputElement; } /** * A config object for defining a field date. */ export interface FieldDateConfig extends Blockly.FieldTextInputConfig { spellcheck?: never; } /** * Options used to define a field date from JSON. */ export interface FieldDateFromJsonConfig extends FieldDateConfig { date?: string; } export type FieldDateValidator = Blockly.FieldTextInputValidator; /** * Validate a string value to see if it matches the format. * * @param value The value to validate the format for. * @returns true if the value is in 'yyyy-mm-dd' format. * @example * isISOFormat('2000-02-20T00:00:00Z') === false * isISOFormat('2000-02-20') === true */ export declare function isISOFormat(value: string): boolean; /** * Convert the date to ISO format for the current timezone. * * @param date The date to convert to an ISO string. * @returns The string in 'yyyy-mm-dd' format, though for the current timezone. * Ex: new Date('2000-02-20') */ export declare function toLocalISOString(date: Date): string; //# sourceMappingURL=field_date.d.ts.map