UNPKG

wed

Version:

Wed is a schema-aware editor for XML documents.

137 lines 4.87 kB
define(["require", "exports", "wed"], function (require, exports, wed_1) { /** * The base types for modes. * * @author Louis-Dominique Dubeau * @license MPL 2.0 * @copyright Mangalam Research Center for Buddhist Languages */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * A mode for wed should be implemented as a module which exports a * class derived from this class. */ class BaseMode { /** * @param editor The editor for which this mode is created. * * @param options The options for the mode. Each mode defines * what fields this object contains. */ constructor(editor, options) { this.editor = editor; this.options = options; this.wedOptions = { metadata: { name: "Base Mode (you should not be using this)", description: "The base mode. You should not be using it directly.", authors: ["Louis-Dominique Dubeau"], license: "MPL 2.0", copyright: "Mangalam Research Center for Buddhist Languages", }, label_levels: { max: 1, initial: 1, }, }; } /** * Gets the mode options. The returned object should be considered frozen. You * may inspect it, not modify it. */ getModeOptions() { return this.options; } /** * Gets the options that the mode wants wed to use with this mode. * * @returns The options. Callers are not allowed to modify the value returned. */ getWedOptions() { return this.wedOptions; } /** * @returns The base implementation returns an empty array. */ getStylesheets() { return []; } nodesAroundEditableContents(element) { let start = null; let startIx; let end = null; let endIx; let child = element.firstChild; let childIx = 0; while (child !== null) { if (wed_1.domtypeguards.isElement(child)) { if (child.classList.contains("_start_wrapper")) { startIx = childIx; start = child; } if (child.classList.contains("_end_wrapper")) { endIx = childIx; end = child; // We want the first end_wrapper we hit. There is no need to continue. break; } } child = child.nextSibling; childIx++; } if (startIx !== undefined && endIx !== undefined && endIx <= startIx) { throw new Error("end wrapper element unexpectedly appears before " + "start wrapper element, or is also a start wrapper " + "element"); } return [start, end]; } makePlaceholderFor(_element) { return wed_1.domutil.makePlaceholder(); } /** * While this API provides for the case where descriptions have not been * loaded yet or cannot be loaded, this class does not allow such eventuality * to occur. Derived classes could allow it. * * @returns This default implementation always returns ``undefined``. */ shortDescriptionFor(_name) { return undefined; } /** * While this API provides for the case such URL have not been loaded * yet or cannot be loaded, this class does not allow such eventuality * to occur. Derived classes could allow it. * * @returns The default implementation always returns ``undefined``. */ documentationLinkFor(_name) { return undefined; } /** * @returns ``undefined``. The default implementation has no mode-specific * checks and thus not return a validator. */ getValidator() { return undefined; } /** * The default implementation returns an empty array. */ getAttributeCompletions(_attribute) { return []; } /** * The default implementaiton returns an empty array. */ getToolbarButtons() { return []; } } exports.BaseMode = BaseMode; }); // LocalWords: autoinsertion domutil Dubeau Mangalam MPL html overriden // LocalWords: stylesheets //# sourceMappingURL=mode.js.map