MenuHandler.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. var __assign = (this && this.__assign) || function () {
  18. __assign = Object.assign || function(t) {
  19. for (var s, i = 1, n = arguments.length; i < n; i++) {
  20. s = arguments[i];
  21. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  22. t[p] = s[p];
  23. }
  24. return t;
  25. };
  26. return __assign.apply(this, arguments);
  27. };
  28. var __read = (this && this.__read) || function (o, n) {
  29. var m = typeof Symbol === "function" && o[Symbol.iterator];
  30. if (!m) return o;
  31. var i = m.call(o), r, ar = [], e;
  32. try {
  33. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  34. }
  35. catch (error) { e = { error: error }; }
  36. finally {
  37. try {
  38. if (r && !r.done && (m = i["return"])) m.call(i);
  39. }
  40. finally { if (e) throw e.error; }
  41. }
  42. return ar;
  43. };
  44. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  45. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  46. if (ar || !(i in from)) {
  47. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  48. ar[i] = from[i];
  49. }
  50. }
  51. return to.concat(ar || Array.prototype.slice.call(from));
  52. };
  53. var __values = (this && this.__values) || function(o) {
  54. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  55. if (m) return m.call(o);
  56. if (o && typeof o.length === "number") return {
  57. next: function () {
  58. if (o && i >= o.length) o = void 0;
  59. return { value: o && o[i++], done: !o };
  60. }
  61. };
  62. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  63. };
  64. Object.defineProperty(exports, "__esModule", { value: true });
  65. exports.MenuHandler = exports.MenuMathDocumentMixin = exports.MenuMathItemMixin = void 0;
  66. var mathjax_js_1 = require("../../mathjax.js");
  67. var MathItem_js_1 = require("../../core/MathItem.js");
  68. var Options_js_1 = require("../../util/Options.js");
  69. var Menu_js_1 = require("./Menu.js");
  70. (0, MathItem_js_1.newState)('CONTEXT_MENU', 170);
  71. function MenuMathItemMixin(BaseMathItem) {
  72. return (function (_super) {
  73. __extends(class_1, _super);
  74. function class_1() {
  75. return _super !== null && _super.apply(this, arguments) || this;
  76. }
  77. class_1.prototype.addMenu = function (document, force) {
  78. if (force === void 0) { force = false; }
  79. if (this.state() >= MathItem_js_1.STATE.CONTEXT_MENU)
  80. return;
  81. if (!this.isEscaped && (document.options.enableMenu || force)) {
  82. document.menu.addMenu(this);
  83. }
  84. this.state(MathItem_js_1.STATE.CONTEXT_MENU);
  85. };
  86. class_1.prototype.checkLoading = function (document) {
  87. document.checkLoading();
  88. };
  89. return class_1;
  90. }(BaseMathItem));
  91. }
  92. exports.MenuMathItemMixin = MenuMathItemMixin;
  93. function MenuMathDocumentMixin(BaseDocument) {
  94. var _a;
  95. return _a = (function (_super) {
  96. __extends(class_2, _super);
  97. function class_2() {
  98. var args = [];
  99. for (var _i = 0; _i < arguments.length; _i++) {
  100. args[_i] = arguments[_i];
  101. }
  102. var _this = _super.apply(this, __spreadArray([], __read(args), false)) || this;
  103. _this.menu = new _this.options.MenuClass(_this, _this.options.menuOptions);
  104. var ProcessBits = _this.constructor.ProcessBits;
  105. if (!ProcessBits.has('context-menu')) {
  106. ProcessBits.allocate('context-menu');
  107. }
  108. _this.options.MathItem = MenuMathItemMixin(_this.options.MathItem);
  109. return _this;
  110. }
  111. class_2.prototype.addMenu = function () {
  112. var e_1, _a;
  113. if (!this.processed.isSet('context-menu')) {
  114. try {
  115. for (var _b = __values(this.math), _c = _b.next(); !_c.done; _c = _b.next()) {
  116. var math = _c.value;
  117. math.addMenu(this);
  118. }
  119. }
  120. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  121. finally {
  122. try {
  123. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  124. }
  125. finally { if (e_1) throw e_1.error; }
  126. }
  127. this.processed.set('context-menu');
  128. }
  129. return this;
  130. };
  131. class_2.prototype.checkLoading = function () {
  132. if (this.menu.isLoading) {
  133. mathjax_js_1.mathjax.retryAfter(this.menu.loadingPromise.catch(function (err) { return console.log(err); }));
  134. }
  135. var settings = this.menu.settings;
  136. if (settings.collapsible) {
  137. this.options.enableComplexity = true;
  138. this.menu.checkComponent('a11y/complexity');
  139. }
  140. if (settings.explorer) {
  141. this.options.enableEnrichment = true;
  142. this.options.enableExplorer = true;
  143. this.menu.checkComponent('a11y/explorer');
  144. }
  145. return this;
  146. };
  147. class_2.prototype.state = function (state, restore) {
  148. if (restore === void 0) { restore = false; }
  149. _super.prototype.state.call(this, state, restore);
  150. if (state < MathItem_js_1.STATE.CONTEXT_MENU) {
  151. this.processed.clear('context-menu');
  152. }
  153. return this;
  154. };
  155. class_2.prototype.updateDocument = function () {
  156. _super.prototype.updateDocument.call(this);
  157. this.menu.menu.store.sort();
  158. return this;
  159. };
  160. return class_2;
  161. }(BaseDocument)),
  162. _a.OPTIONS = __assign(__assign({ enableEnrichment: true, enableComplexity: true, enableExplorer: true, enrichSpeech: 'none', enrichError: function (_doc, _math, err) {
  163. return console.warn('Enrichment Error:', err);
  164. } }, BaseDocument.OPTIONS), { MenuClass: Menu_js_1.Menu, menuOptions: Menu_js_1.Menu.OPTIONS, enableMenu: true, sre: (BaseDocument.OPTIONS.sre || (0, Options_js_1.expandable)({})), a11y: (BaseDocument.OPTIONS.a11y || (0, Options_js_1.expandable)({})), renderActions: (0, Options_js_1.expandable)(__assign(__assign({}, BaseDocument.OPTIONS.renderActions), { addMenu: [MathItem_js_1.STATE.CONTEXT_MENU], checkLoading: [MathItem_js_1.STATE.UNPROCESSED + 1] })) }),
  165. _a;
  166. }
  167. exports.MenuMathDocumentMixin = MenuMathDocumentMixin;
  168. function MenuHandler(handler) {
  169. handler.documentClass = MenuMathDocumentMixin(handler.documentClass);
  170. return handler;
  171. }
  172. exports.MenuHandler = MenuHandler;
  173. //# sourceMappingURL=MenuHandler.js.map