// HyperMD, copyright (c) by laobubu // Distributed under an MIT license: http://laobubu.net/HyperMD/LICENSE // // DESCRIPTION: Align Table Columns // (function (mod){ //[HyperMD] UMD patched! /*commonjs*/ ("object"==typeof exports&&"undefined"!=typeof module) ? mod(null, exports, require("codemirror"), require("../core")) : /*amd*/ ("function"==typeof define&&define.amd) ? define(["require","exports","codemirror","../core"], mod) : /*plain env*/ mod(null, (this.HyperMD.TableAlign = this.HyperMD.TableAlign || {}), CodeMirror, HyperMD); })(function (require, exports, CodeMirror, core_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultOption = { enabled: false, }; exports.suggestedOption = { enabled: true, }; core_1.suggestedEditorConfig.hmdTableAlign = exports.suggestedOption; core_1.normalVisualConfig.hmdTableAlign = false; CodeMirror.defineOption("hmdTableAlign", exports.defaultOption, function (cm, newVal) { var enabled = !!newVal; ///// convert newVal's type to `Partial`, if it is not. if (!enabled || typeof newVal === "boolean") { newVal = { enabled: enabled }; } ///// apply config and write new values into cm var inst = exports.getAddon(cm); for (var k in exports.defaultOption) { inst[k] = (k in newVal) ? newVal[k] : exports.defaultOption[k]; } }); //#endregion /********************************************************************************** */ //#region Addon Class var TableAlign = /** @class */ (function () { function TableAlign(cm) { // options will be initialized to defaultOption (if exists) // add your code here var _this = this; this.cm = cm; this.styleEl = document.createElement("style"); /** * Remeasure visible columns, update CSS style to make columns aligned * * (This is a debounced function) */ // PATCHED: Request-Animation-Frame-throttle instead of timed debounce. tableID is // line-number-based (hypermd.js: "T" + line), so any line shift // above a table changes the CSS string and the table line is // re-rendered with a new id. With a 100ms debounce the new column // DOM lived for ~100ms without matching CSS — visible flicker. // requestAnimationFrame batches bursty updates (many `update` // events collapse into one) AND runs before the browser paints, // so the new