import { BasePlugin } from '../base'; import type { BorderSettings, BorderObject, CustomBorderConfig } from './utils'; import type CellRange from '../../3rdparty/walkontable/src/cell/range'; export declare const PLUGIN_KEY = "customBorders"; export declare const PLUGIN_PRIORITY = 90; export type { BorderSettings, BorderObject }; /** * @plugin CustomBorders * @class CustomBorders * * @description * This plugin enables an option to apply custom borders through the context menu (configurable with context menu key * `borders`). * * To initialize Handsontable with predefined custom borders, provide cell coordinates and border styles in a form * of an array. * * When a border property is set to an empty object `{}` or an empty string `''`, the default style is applied: * **1px solid black**. * * The plugin also integrates with the [[ContextMenu]] plugin. Adding `'borders'` to the * [`contextMenu`](@/api/options.md#contextmenu) items enables users to apply or remove borders on selected cells * directly from the right-click menu. * * See [`customBorders` configuration option](@/api/options.md#customBorders) or go to * [Custom cell borders demo](@/guides/cell-features/formatting-cells/formatting-cells.md#custom-cell-borders) for more examples. * * @example * ```js * // Enable custom borders with context menu integration. * // When a border property is an empty object, the default style (1px solid black) is applied. * new Handsontable(container, { * customBorders: [ * { * range: { * from: { row: 1, col: 1 }, * to: { row: 3, col: 4 }, * }, * top: {}, // default: 1px solid black * bottom: {}, // default: 1px solid black * start: {}, // default: 1px solid black * end: {}, // default: 1px solid black * }, * { * row: 2, * col: 2, * start: { width: 2, color: 'red', style: 'dotted' }, * end: { width: 1, color: 'green', style: 'dashed' }, * top: '', // default: 1px solid black * bottom: '', // default: 1px solid black * }, * ], * // Enable the 'borders' item in the context menu so users can * // apply or remove borders from the right-click menu. * contextMenu: ['borders'], * }); * ``` */ export declare class CustomBorders extends BasePlugin { #private; /** * Returns the plugin key used to identify this plugin in Handsontable settings. */ static get PLUGIN_KEY(): string; /** * Returns the priority order used to determine the order in which plugins are initialized. */ static get PLUGIN_PRIORITY(): number; /** * Saved borders. * * @private * @type {Array} */ savedBorders: BorderObject[]; /** * Checks if the plugin is enabled in the handsontable settings. This method is executed in {@link Hooks#beforeInit} * hook and if it returns `true` then the {@link CustomBorders#enablePlugin} method is called. * * @returns {boolean} */ isEnabled(): boolean; /** * Enables the plugin functionality for this Handsontable instance. */ enablePlugin(): void; /** * Disables the plugin functionality for this Handsontable instance. */ disablePlugin(): void; /** * Updates the plugin's state. * * This method is executed when [`updateSettings()`](@/api/core.md#updatesettings) is invoked with any of the following configuration options: * - [`customBorders`](@/api/options.md#customborders) */ updatePlugin(): void; /** * Set custom borders. * * @example * ```js * const customBordersPlugin = hot.getPlugin('customBorders'); * * // Using an array of arrays (produced by `.getSelected()` method). * customBordersPlugin.setBorders([[1, 1, 2, 2], [6, 2, 0, 2]], {start: {width: 2, color: 'blue'}}); * * // Using an array of CellRange objects (produced by `.getSelectedRange()` method). * // Selecting a cell range. * hot.selectCell(0, 0, 2, 2); * // Returning selected cells' range with the getSelectedRange method. * customBordersPlugin.setBorders(hot.getSelectedRange(), {start: {hide: false, width: 2, color: 'blue'}}); * ``` * * @param {Array[]|CellRange[]} selectionRanges Array of selection ranges. * @param {object} borderObject Object with `top`, `right`, `bottom` and `start` properties. */ setBorders(selectionRanges: unknown[], borderObject?: Record): void; /** * Get custom borders. * * @example * ```js * const customBordersPlugin = hot.getPlugin('customBorders'); * * // Using an array of arrays (produced by `.getSelected()` method). * customBordersPlugin.getBorders([[1, 1, 2, 2], [6, 2, 0, 2]]); * // Using an array of CellRange objects (produced by `.getSelectedRange()` method). * customBordersPlugin.getBorders(hot.getSelectedRange()); * // Using without param - return all customBorders. * customBordersPlugin.getBorders(); * ``` * * @param {Array[]|CellRange[]} selectionRanges Array of selection ranges. * @returns {object[]} Returns array of border objects. */ getBorders(selectionRanges?: unknown[]): Record[]; /** * Clear custom borders. * * @example * ```js * const customBordersPlugin = hot.getPlugin('customBorders'); * * // Using an array of arrays (produced by `.getSelected()` method). * customBordersPlugin.clearBorders([[1, 1, 2, 2], [6, 2, 0, 2]]); * // Using an array of CellRange objects (produced by `.getSelectedRange()` method). * customBordersPlugin.clearBorders(hot.getSelectedRange()); * // Using without param - clear all customBorders. * customBordersPlugin.clearBorders(); * ``` * * @param {Array[]|CellRange[]} selectionRanges Array of selection ranges. */ clearBorders(selectionRanges?: unknown[]): void; /** * Insert WalkontableSelection instance into Walkontable settings. * * @private * @param {object} border Object with `row` and `col`, `start`, `end`, `top` and `bottom`, `id` and `border` ({Object} with `color`, `width` and `cornerVisible` property) properties. * @param {string} [place] Coordinate where add/remove border - `top`, `bottom`, `start`, `end`. */ insertBorderIntoSettings(border: BorderObject, place: string | undefined): void; /** * Prepare borders from setting (single cell). * * @private * @param {number} row Visual row index. * @param {number} column Visual column index. * @param {object} borderDescriptor Object with `row` and `col`, `start`, `end`, `top` and `bottom` properties. * @param {string} [place] Coordinate where add/remove border - `top`, `bottom`, `start`, `end`. */ prepareBorderFromCustomAdded(row: number, column: number, borderDescriptor: CustomBorderConfig | null, place: string | undefined): void; /** * Prepare borders from setting (object). * * @private * @param {object} range {CellRange} The CellRange object. * @param {object} customBorder Object with `start`, `end`, `top` and `bottom` properties. */ prepareBorderFromCustomAddedRange(range: { from: { row: number; col: number; }; to: { row: number; col: number; }; }, customBorder: CustomBorderConfig): void; /** * Remove border (triggered from context menu). * * @private * @param {number} row Visual row index. * @param {number} column Visual column index. */ removeAllBorders(row: number, column: number): void; /** * Set borders for each cell re. To border position. * * @private * @param {number} row Visual row index. * @param {number} column Visual column index. * @param {string} place Coordinate where add/remove border - `top`, `bottom`, `start`, `end` and `noBorders`. * @param {boolean} remove True when remove borders, and false when add borders. */ setBorder(row: number, column: number, place: string, remove: boolean | undefined): void; /** * Prepare borders based on cell and border position. * * @private * @param {CellRange[]} selected An array of CellRange objects. * @param {string} place Coordinate where add/remove border - `top`, `bottom`, `left`, `right` and `noBorders`. * @param {boolean} remove True when remove borders, and false when add borders. */ prepareBorder(selected: Record[], place: string, remove: boolean | undefined): void; /** * Create borders from settings. * * @private * @param {Array} customBorders Object with `row` and `col`, `start`, `end`, `top` and `bottom` properties. */ createCustomBorders(customBorders: CustomBorderConfig[]): void; /** * Count hide property in border object. * * @private * @param {object} border Object with `row` and `col`, `start`, `end`, `top` and `bottom`, `id` and * `border` ({Object} with `color`, `width` and `cornerVisible` property) properties. * @returns {number} */ countHide(border: BorderObject): number; /** * Clear borders settings from custom selections. * * @private * @param {string} borderId Border id name as string. */ clearBordersFromSelectionSettings(borderId: string): void; /** * Clear cellRange with null value. * * @private */ clearNullCellRange(): void; /** * Hide custom borders. * * @private */ hideBorders(): void; /** * Splice border from savedBorders. * * @private * @param {string} borderId Border id name as string. */ spliceBorder(borderId: string): void; /** * Check if an border already exists in the savedBorders array, and if true update border in savedBorders. * * @private * @param {object} border Object with `row` and `col`, `start`, `end`, `top` and `bottom`, `id` and * `border` ({Object} with `color`, `width` and `cornerVisible` property) properties. * * @returns {boolean} */ checkSavedBorders(border: BorderObject): boolean; /** * Check if an border already exists in the customSelections, and if true call toggleHiddenClass method. * * @private * @param {object} border Object with `row` and `col`, `start`, `end`, `top` and `bottom`, `id` and * `border` ({Object} with `color`, `width` and `cornerVisible` property) properties. * @param {string} place Coordinate where add/remove border - `top`, `bottom`, `start`, `end` and `noBorders`. * @param {boolean} remove True when remove borders, and false when add borders. * * @returns {boolean} */ checkCustomSelectionsFromContextMenu(border: Record, place: string, remove: boolean | undefined): boolean; /** * Check if an border already exists in the customSelections, and if true reset cellRange. * * @private * @param {object} border Object with `row` and `col`, `start`, `end`, `top` and `bottom`, `id` and * `border` ({Object} with `color`, `width` and `cornerVisible` property) properties. * @param {CellRange} cellRange The selection range to check. * @param {string} [place] Coordinate where add/remove border - `top`, `bottom`, `start`, `end`. * @returns {boolean} */ checkCustomSelections(border: BorderObject, cellRange: CellRange, place: string | undefined): boolean; /** * Change borders from settings. * * @private */ changeBorderSettings(): void; /** * Checks the settings cohesion. The properties such like "left"/"right" are supported only * in the LTR mode and the "left"/"right" options can not be used together with "start"/"end" properties. * * @private * @param {object[]} customBorders The user defined custom border objects array. */ checkSettingsCohesion(customBorders: CustomBorderConfig[]): void; /** * Destroys the plugin instance. */ destroy(): void; }