import './table-input.css'; import React from 'dom-chef'; import select from 'select-dom'; import delegate from 'delegate-it'; import * as pageDetect from 'github-url-detection'; import * as textFieldEdit from 'text-field-edit'; import features from '.'; import smartBlockWrap from '../helpers/smart-block-wrap'; function addTable({delegateTarget: square}: delegate.Event): void { const field = square.form!.querySelector('textarea')!; const cursorPosition = field.selectionStart; field.focus(); const table = '\n' + ('\n' + '\t
\n'.repeat(Number(square.dataset.x)) ).repeat(Number(square.dataset.y)) + '
'; textFieldEdit.insert(field, smartBlockWrap(table, field)); // Move caret to first cell field.selectionEnd = field.value.indexOf('', cursorPosition) + ''.length; } function highlightSquares({delegateTarget: hover}: delegate.Event): void { for (const cell of hover.parentElement!.children as HTMLCollectionOf) { cell.classList.toggle('selected', cell.dataset.x! <= hover.dataset.x! && cell.dataset.y! <= hover.dataset.y!); } } function init(): void { delegate(document, '.rgh-table-input-cell', 'click', addTable); delegate(document, '.rgh-table-input-cell', 'mouseenter', highlightSquares, {capture: true}); for (const anchor of select.all('md-task-list')) { anchor.after(
{Array.from({length: 25}).map((_, index) => ( ))}
); } } void features.add(__filebasename, { include: [ pageDetect.hasRichTextEditor ], init });