/*! * Jodit Editor (https://xdsoft.net/jodit/) * Released under MIT see LICENSE.txt in the project root for license information. * Copyright (c) 2013-2025 Valeriy Chupurnov. All rights reserved. https://xdsoft.net */ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { KEY_TAB } from "../../core/constants.js"; import { autobind, watch } from "../../core/decorators/index.js"; import { Dom } from "../../core/dom/dom.js"; import { pluginSystem } from "../../core/global.js"; import { $$, alignElement, position } from "../../core/helpers/index.js"; import { Plugin } from "../../core/plugin/index.js"; import { Table } from "../../modules/table/table.js"; import "./config.js"; const key = 'table_processor_observer'; const MOUSE_MOVE_LABEL = 'onMoveTableSelectCell'; export class selectCells extends Plugin { constructor() { super(...arguments); /** * First selected cell */ this.__selectedCell = null; /** * User is selecting cells now */ this.__isSelectionMode = false; } /** * Shortcut for Jodit.modules.Table */ get __tableModule() { return this.j.getInstance(Table, this.j.o); } afterInit(jodit) { if (!jodit.o.tableAllowCellSelection) { return; } jodit.e .on('keydown.select-cells', (event) => { if (event.key === KEY_TAB) { this.unselectCells(); } }) .on('beforeCommand.select-cells', this.onExecCommand) .on('afterCommand.select-cells', this.onAfterCommand) // see `plugins/select.ts` .on([ 'clickEditor', 'mousedownTd', 'mousedownTh', 'touchstartTd', 'touchstartTh' ] .map(e => e + '.select-cells') .join(' '), this.onStartSelection) // For `clickEditor` correct working. Because `mousedown` on first cell // and mouseup on another cell call `click` only for `TR` element. .on('clickTr clickTbody', () => { var _a; const cellsCount = this.__tableModule.getAllSelectedCells().length; if (cellsCount) { if (cellsCount > 1) { (_a = this.j.s.sel) === null || _a === void 0 ? void 0 : _a.removeAllRanges(); } return false; } }); } /** * Mouse click inside the table */ onStartSelection(cell) { if (this.j.o.readonly) { return; } this.unselectCells(); if (cell === this.j.editor) { return; } const table = Dom.closest(cell, 'table', this.j.editor); if (!cell || !table) { return; } if (!cell.firstChild) { cell.appendChild(this.j.createInside.element('br')); } this.__isSelectionMode = true; this.__selectedCell = cell; this.__tableModule.addSelection(cell); this.j.e .on(table, 'mousemove.select-cells touchmove.select-cells', // Don't use decorator because need clear label on mouseup this.j.async.throttle(this.__onMove.bind(this, table), { label: MOUSE_MOVE_LABEL, timeout: this.j.defaultTimeout / 2 })) .on(table, 'mouseup.select-cells touchend.select-cells', this.__onStopSelection.bind(this, table)); return false; } onOutsideClick() { this.__selectedCell = null; this.__onRemoveSelection(); } onChange() { if (!this.j.isLocked && !this.__isSelectionMode) { this.__onRemoveSelection(); } } /** * Mouse move inside the table */ __onMove(table, e) { var _a; if (this.j.o.readonly && !this.j.isLocked) { return; } if (this.j.isLockedNotBy(key)) { return; } const node = this.j.ed.elementFromPoint(e.clientX, e.clientY); if (!node) { return; } const cell = Dom.closest(node, ['td', 'th'], table); if (!cell || !this.__selectedCell) { return; } if (cell !== this.__selectedCell) { this.j.lock(key); } this.unselectCells(); const bound = this.__tableModule.getSelectedBound(table, [ cell, this.__selectedCell ]), box = this.__tableModule.formalMatrix(table); for (let i = bound[0][0]; i <= bound[1][0]; i += 1) { for (let j = bound[0][1]; j <= bound[1][1]; j += 1) { this.__tableModule.addSelection(box[i][j]); } } const cellsCount = this.__tableModule.getAllSelectedCells().length; if (cellsCount > 1) { (_a = this.j.s.sel) === null || _a === void 0 ? void 0 : _a.removeAllRanges(); } this.j.e.fire('hidePopup'); e.stopPropagation(); // Hack for FireFox for force redraw selection (() => { const n = this.j.createInside.fromHTML('