ngx-contextmenu.umd.js 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/cdk/overlay'), require('@angular/common'), require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('@angular/cdk/portal'), require('@angular/cdk/a11y')) :
  3. typeof define === 'function' && define.amd ? define('ngx-contextmenu', ['exports', '@angular/cdk/overlay', '@angular/common', '@angular/core', 'rxjs', 'rxjs/operators', '@angular/cdk/portal', '@angular/cdk/a11y'], factory) :
  4. (global = global || self, factory(global['ngx-contextmenu'] = {}, global.ng.cdk.overlay, global.ng.common, global.ng.core, global.rxjs, global.rxjs.operators, global.ng.cdk.portal, global.ng.cdk.a11y));
  5. }(this, (function (exports, overlay, common, core, rxjs, operators, portal, a11y) { 'use strict';
  6. /*! *****************************************************************************
  7. Copyright (c) Microsoft Corporation. All rights reserved.
  8. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  9. this file except in compliance with the License. You may obtain a copy of the
  10. License at http://www.apache.org/licenses/LICENSE-2.0
  11. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  13. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  14. MERCHANTABLITY OR NON-INFRINGEMENT.
  15. See the Apache Version 2.0 License for specific language governing permissions
  16. and limitations under the License.
  17. ***************************************************************************** */
  18. /* global Reflect, Promise */
  19. var extendStatics = function(d, b) {
  20. extendStatics = Object.setPrototypeOf ||
  21. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  22. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  23. return extendStatics(d, b);
  24. };
  25. function __extends(d, b) {
  26. extendStatics(d, b);
  27. function __() { this.constructor = d; }
  28. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  29. }
  30. var __assign = function() {
  31. __assign = Object.assign || function __assign(t) {
  32. for (var s, i = 1, n = arguments.length; i < n; i++) {
  33. s = arguments[i];
  34. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  35. }
  36. return t;
  37. };
  38. return __assign.apply(this, arguments);
  39. };
  40. function __rest(s, e) {
  41. var t = {};
  42. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  43. t[p] = s[p];
  44. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  45. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  46. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  47. t[p[i]] = s[p[i]];
  48. }
  49. return t;
  50. }
  51. function __decorate(decorators, target, key, desc) {
  52. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  53. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  54. 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;
  55. return c > 3 && r && Object.defineProperty(target, key, r), r;
  56. }
  57. function __param(paramIndex, decorator) {
  58. return function (target, key) { decorator(target, key, paramIndex); }
  59. }
  60. function __metadata(metadataKey, metadataValue) {
  61. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
  62. }
  63. function __awaiter(thisArg, _arguments, P, generator) {
  64. return new (P || (P = Promise))(function (resolve, reject) {
  65. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  66. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  67. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  68. step((generator = generator.apply(thisArg, _arguments || [])).next());
  69. });
  70. }
  71. function __generator(thisArg, body) {
  72. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  73. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  74. function verb(n) { return function (v) { return step([n, v]); }; }
  75. function step(op) {
  76. if (f) throw new TypeError("Generator is already executing.");
  77. while (_) try {
  78. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  79. if (y = 0, t) op = [op[0] & 2, t.value];
  80. switch (op[0]) {
  81. case 0: case 1: t = op; break;
  82. case 4: _.label++; return { value: op[1], done: false };
  83. case 5: _.label++; y = op[1]; op = [0]; continue;
  84. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  85. default:
  86. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  87. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  88. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  89. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  90. if (t[2]) _.ops.pop();
  91. _.trys.pop(); continue;
  92. }
  93. op = body.call(thisArg, _);
  94. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  95. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  96. }
  97. }
  98. function __exportStar(m, exports) {
  99. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  100. }
  101. function __values(o) {
  102. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  103. if (m) return m.call(o);
  104. return {
  105. next: function () {
  106. if (o && i >= o.length) o = void 0;
  107. return { value: o && o[i++], done: !o };
  108. }
  109. };
  110. }
  111. function __read(o, n) {
  112. var m = typeof Symbol === "function" && o[Symbol.iterator];
  113. if (!m) return o;
  114. var i = m.call(o), r, ar = [], e;
  115. try {
  116. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  117. }
  118. catch (error) { e = { error: error }; }
  119. finally {
  120. try {
  121. if (r && !r.done && (m = i["return"])) m.call(i);
  122. }
  123. finally { if (e) throw e.error; }
  124. }
  125. return ar;
  126. }
  127. function __spread() {
  128. for (var ar = [], i = 0; i < arguments.length; i++)
  129. ar = ar.concat(__read(arguments[i]));
  130. return ar;
  131. }
  132. function __spreadArrays() {
  133. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  134. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  135. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  136. r[k] = a[j];
  137. return r;
  138. };
  139. function __await(v) {
  140. return this instanceof __await ? (this.v = v, this) : new __await(v);
  141. }
  142. function __asyncGenerator(thisArg, _arguments, generator) {
  143. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  144. var g = generator.apply(thisArg, _arguments || []), i, q = [];
  145. return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
  146. function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
  147. function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
  148. function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
  149. function fulfill(value) { resume("next", value); }
  150. function reject(value) { resume("throw", value); }
  151. function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
  152. }
  153. function __asyncDelegator(o) {
  154. var i, p;
  155. return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
  156. function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
  157. }
  158. function __asyncValues(o) {
  159. if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
  160. var m = o[Symbol.asyncIterator], i;
  161. return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
  162. function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
  163. function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
  164. }
  165. function __makeTemplateObject(cooked, raw) {
  166. if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
  167. return cooked;
  168. };
  169. function __importStar(mod) {
  170. if (mod && mod.__esModule) return mod;
  171. var result = {};
  172. if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
  173. result.default = mod;
  174. return result;
  175. }
  176. function __importDefault(mod) {
  177. return (mod && mod.__esModule) ? mod : { default: mod };
  178. }
  179. /**
  180. * @fileoverview added by tsickle
  181. * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  182. */
  183. var ContextMenuItemDirective = /** @class */ (function () {
  184. function ContextMenuItemDirective(template, elementRef) {
  185. this.template = template;
  186. this.elementRef = elementRef;
  187. this.divider = false;
  188. this.enabled = true;
  189. this.passive = false;
  190. this.visible = true;
  191. this.execute = new core.EventEmitter();
  192. this.isActive = false;
  193. }
  194. Object.defineProperty(ContextMenuItemDirective.prototype, "disabled", {
  195. get: /**
  196. * @return {?}
  197. */
  198. function () {
  199. return this.passive ||
  200. this.divider ||
  201. !this.evaluateIfFunction(this.enabled, this.currentItem);
  202. },
  203. enumerable: true,
  204. configurable: true
  205. });
  206. /**
  207. * @param {?} value
  208. * @param {?} item
  209. * @return {?}
  210. */
  211. ContextMenuItemDirective.prototype.evaluateIfFunction = /**
  212. * @param {?} value
  213. * @param {?} item
  214. * @return {?}
  215. */
  216. function (value, item) {
  217. if (value instanceof Function) {
  218. return value(item);
  219. }
  220. return value;
  221. };
  222. /**
  223. * @return {?}
  224. */
  225. ContextMenuItemDirective.prototype.setActiveStyles = /**
  226. * @return {?}
  227. */
  228. function () {
  229. this.isActive = true;
  230. };
  231. /**
  232. * @return {?}
  233. */
  234. ContextMenuItemDirective.prototype.setInactiveStyles = /**
  235. * @return {?}
  236. */
  237. function () {
  238. this.isActive = false;
  239. };
  240. /**
  241. * @param {?} item
  242. * @param {?=} $event
  243. * @return {?}
  244. */
  245. ContextMenuItemDirective.prototype.triggerExecute = /**
  246. * @param {?} item
  247. * @param {?=} $event
  248. * @return {?}
  249. */
  250. function (item, $event) {
  251. if (!this.evaluateIfFunction(this.enabled, item)) {
  252. return;
  253. }
  254. this.execute.emit({ event: $event, item: item });
  255. };
  256. ContextMenuItemDirective.decorators = [
  257. { type: core.Directive, args: [{
  258. /* tslint:disable:directive-selector-type */
  259. selector: '[contextMenuItem]',
  260. },] }
  261. ];
  262. /** @nocollapse */
  263. ContextMenuItemDirective.ctorParameters = function () { return [
  264. { type: core.TemplateRef },
  265. { type: core.ElementRef }
  266. ]; };
  267. ContextMenuItemDirective.propDecorators = {
  268. subMenu: [{ type: core.Input }],
  269. divider: [{ type: core.Input }],
  270. enabled: [{ type: core.Input }],
  271. passive: [{ type: core.Input }],
  272. visible: [{ type: core.Input }],
  273. execute: [{ type: core.Output }]
  274. };
  275. return ContextMenuItemDirective;
  276. }());
  277. if (false) {
  278. /** @type {?} */
  279. ContextMenuItemDirective.prototype.subMenu;
  280. /** @type {?} */
  281. ContextMenuItemDirective.prototype.divider;
  282. /** @type {?} */
  283. ContextMenuItemDirective.prototype.enabled;
  284. /** @type {?} */
  285. ContextMenuItemDirective.prototype.passive;
  286. /** @type {?} */
  287. ContextMenuItemDirective.prototype.visible;
  288. /** @type {?} */
  289. ContextMenuItemDirective.prototype.execute;
  290. /** @type {?} */
  291. ContextMenuItemDirective.prototype.currentItem;
  292. /** @type {?} */
  293. ContextMenuItemDirective.prototype.isActive;
  294. /** @type {?} */
  295. ContextMenuItemDirective.prototype.template;
  296. /** @type {?} */
  297. ContextMenuItemDirective.prototype.elementRef;
  298. }
  299. /**
  300. * @fileoverview added by tsickle
  301. * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  302. */
  303. /** @type {?} */
  304. var CONTEXT_MENU_OPTIONS = new core.InjectionToken('CONTEXT_MENU_OPTIONS');
  305. /**
  306. * @fileoverview added by tsickle
  307. * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  308. */
  309. /**
  310. * @record
  311. */
  312. function ILinkConfig() { }
  313. if (false) {
  314. /** @type {?} */
  315. ILinkConfig.prototype.click;
  316. /** @type {?|undefined} */
  317. ILinkConfig.prototype.enabled;
  318. /** @type {?} */
  319. ILinkConfig.prototype.html;
  320. }
  321. /** @type {?} */
  322. var ARROW_LEFT_KEYCODE = 37;
  323. var ContextMenuContentComponent = /** @class */ (function () {
  324. function ContextMenuContentComponent(changeDetector, elementRef, options) {
  325. this.changeDetector = changeDetector;
  326. this.elementRef = elementRef;
  327. this.options = options;
  328. this.menuItems = [];
  329. this.isLeaf = false;
  330. this.execute = new core.EventEmitter();
  331. this.openSubMenu = new core.EventEmitter();
  332. this.closeLeafMenu = new core.EventEmitter();
  333. this.closeAllMenus = new core.EventEmitter();
  334. this.autoFocus = false;
  335. this.useBootstrap4 = false;
  336. this.subscription = new rxjs.Subscription();
  337. if (options) {
  338. this.autoFocus = options.autoFocus;
  339. this.useBootstrap4 = options.useBootstrap4;
  340. }
  341. }
  342. /**
  343. * @return {?}
  344. */
  345. ContextMenuContentComponent.prototype.ngOnInit = /**
  346. * @return {?}
  347. */
  348. function () {
  349. var _this = this;
  350. this.menuItems.forEach((/**
  351. * @param {?} menuItem
  352. * @return {?}
  353. */
  354. function (menuItem) {
  355. menuItem.currentItem = _this.item;
  356. _this.subscription.add(menuItem.execute.subscribe((/**
  357. * @param {?} event
  358. * @return {?}
  359. */
  360. function (event) {
  361. return _this.execute.emit(__assign({}, event, { menuItem: menuItem }));
  362. })));
  363. }));
  364. /** @type {?} */
  365. var queryList = new core.QueryList();
  366. queryList.reset(this.menuItems);
  367. this._keyManager = new a11y.ActiveDescendantKeyManager(queryList).withWrap();
  368. };
  369. /**
  370. * @return {?}
  371. */
  372. ContextMenuContentComponent.prototype.ngAfterViewInit = /**
  373. * @return {?}
  374. */
  375. function () {
  376. var _this = this;
  377. if (this.autoFocus) {
  378. setTimeout((/**
  379. * @return {?}
  380. */
  381. function () { return _this.focus(); }));
  382. }
  383. this.overlay.updatePosition();
  384. };
  385. /**
  386. * @return {?}
  387. */
  388. ContextMenuContentComponent.prototype.ngOnDestroy = /**
  389. * @return {?}
  390. */
  391. function () {
  392. this.subscription.unsubscribe();
  393. };
  394. /**
  395. * @return {?}
  396. */
  397. ContextMenuContentComponent.prototype.focus = /**
  398. * @return {?}
  399. */
  400. function () {
  401. if (this.autoFocus) {
  402. this.menuElement.nativeElement.focus();
  403. }
  404. };
  405. /**
  406. * @param {?} $event
  407. * @return {?}
  408. */
  409. ContextMenuContentComponent.prototype.stopEvent = /**
  410. * @param {?} $event
  411. * @return {?}
  412. */
  413. function ($event) {
  414. $event.stopPropagation();
  415. };
  416. /**
  417. * @param {?} menuItem
  418. * @return {?}
  419. */
  420. ContextMenuContentComponent.prototype.isMenuItemEnabled = /**
  421. * @param {?} menuItem
  422. * @return {?}
  423. */
  424. function (menuItem) {
  425. return this.evaluateIfFunction(menuItem && menuItem.enabled);
  426. };
  427. /**
  428. * @param {?} menuItem
  429. * @return {?}
  430. */
  431. ContextMenuContentComponent.prototype.isMenuItemVisible = /**
  432. * @param {?} menuItem
  433. * @return {?}
  434. */
  435. function (menuItem) {
  436. return this.evaluateIfFunction(menuItem && menuItem.visible);
  437. };
  438. /**
  439. * @param {?} value
  440. * @return {?}
  441. */
  442. ContextMenuContentComponent.prototype.evaluateIfFunction = /**
  443. * @param {?} value
  444. * @return {?}
  445. */
  446. function (value) {
  447. if (value instanceof Function) {
  448. return value(this.item);
  449. }
  450. return value;
  451. };
  452. /**
  453. * @param {?} link
  454. * @return {?}
  455. */
  456. ContextMenuContentComponent.prototype.isDisabled = /**
  457. * @param {?} link
  458. * @return {?}
  459. */
  460. function (link) {
  461. return link.enabled && !link.enabled(this.item);
  462. };
  463. /**
  464. * @param {?} event
  465. * @return {?}
  466. */
  467. ContextMenuContentComponent.prototype.onKeyEvent = /**
  468. * @param {?} event
  469. * @return {?}
  470. */
  471. function (event) {
  472. if (!this.isLeaf) {
  473. return;
  474. }
  475. this._keyManager.onKeydown(event);
  476. };
  477. /**
  478. * @param {?=} event
  479. * @return {?}
  480. */
  481. ContextMenuContentComponent.prototype.keyboardOpenSubMenu = /**
  482. * @param {?=} event
  483. * @return {?}
  484. */
  485. function (event) {
  486. if (!this.isLeaf) {
  487. return;
  488. }
  489. this.cancelEvent(event);
  490. /** @type {?} */
  491. var menuItem = this.menuItems[this._keyManager.activeItemIndex];
  492. if (menuItem) {
  493. this.onOpenSubMenu(menuItem);
  494. }
  495. };
  496. /**
  497. * @param {?=} event
  498. * @return {?}
  499. */
  500. ContextMenuContentComponent.prototype.keyboardMenuItemSelect = /**
  501. * @param {?=} event
  502. * @return {?}
  503. */
  504. function (event) {
  505. if (!this.isLeaf) {
  506. return;
  507. }
  508. this.cancelEvent(event);
  509. /** @type {?} */
  510. var menuItem = this.menuItems[this._keyManager.activeItemIndex];
  511. if (menuItem) {
  512. this.onMenuItemSelect(menuItem, event);
  513. }
  514. };
  515. /**
  516. * @param {?} event
  517. * @return {?}
  518. */
  519. ContextMenuContentComponent.prototype.onCloseLeafMenu = /**
  520. * @param {?} event
  521. * @return {?}
  522. */
  523. function (event) {
  524. if (!this.isLeaf) {
  525. return;
  526. }
  527. this.cancelEvent(event);
  528. this.closeLeafMenu.emit({
  529. exceptRootMenu: event.keyCode === ARROW_LEFT_KEYCODE,
  530. event: event
  531. });
  532. };
  533. /**
  534. * @param {?} event
  535. * @return {?}
  536. */
  537. ContextMenuContentComponent.prototype.closeMenu = /**
  538. * @param {?} event
  539. * @return {?}
  540. */
  541. function (event) {
  542. if (event.type === 'click' && event.button === 2) {
  543. return;
  544. }
  545. this.closeAllMenus.emit({ event: event });
  546. };
  547. /**
  548. * @param {?} menuItem
  549. * @param {?=} event
  550. * @return {?}
  551. */
  552. ContextMenuContentComponent.prototype.onOpenSubMenu = /**
  553. * @param {?} menuItem
  554. * @param {?=} event
  555. * @return {?}
  556. */
  557. function (menuItem, event) {
  558. /** @type {?} */
  559. var anchorElementRef = this.menuItemElements.toArray()[this._keyManager.activeItemIndex];
  560. /** @type {?} */
  561. var anchorElement = anchorElementRef && anchorElementRef.nativeElement;
  562. this.openSubMenu.emit({
  563. anchorElement: anchorElement,
  564. contextMenu: menuItem.subMenu,
  565. event: event,
  566. item: this.item,
  567. parentContextMenu: this
  568. });
  569. };
  570. /**
  571. * @param {?} menuItem
  572. * @param {?} event
  573. * @return {?}
  574. */
  575. ContextMenuContentComponent.prototype.onMenuItemSelect = /**
  576. * @param {?} menuItem
  577. * @param {?} event
  578. * @return {?}
  579. */
  580. function (menuItem, event) {
  581. event.preventDefault();
  582. event.stopPropagation();
  583. this.onOpenSubMenu(menuItem, event);
  584. if (!menuItem.subMenu) {
  585. menuItem.triggerExecute(this.item, event);
  586. }
  587. };
  588. /**
  589. * @private
  590. * @param {?} event
  591. * @return {?}
  592. */
  593. ContextMenuContentComponent.prototype.cancelEvent = /**
  594. * @private
  595. * @param {?} event
  596. * @return {?}
  597. */
  598. function (event) {
  599. if (!event) {
  600. return;
  601. }
  602. /** @type {?} */
  603. var target = event.target;
  604. if (['INPUT', 'TEXTAREA', 'SELECT'].indexOf(target.tagName) > -1 ||
  605. target.isContentEditable) {
  606. return;
  607. }
  608. event.preventDefault();
  609. event.stopPropagation();
  610. };
  611. ContextMenuContentComponent.decorators = [
  612. { type: core.Component, args: [{
  613. selector: 'context-menu-content',
  614. template: "\n <div\n class=\"dropdown open show ngx-contextmenu\"\n [ngClass]=\"menuClass\"\n tabindex=\"0\"\n >\n <ul\n #menu\n class=\"dropdown-menu show\"\n style=\"position: static; float: none;\"\n tabindex=\"0\"\n >\n <li\n #li\n *ngFor=\"let menuItem of menuItems; let i = index\"\n [class.disabled]=\"!isMenuItemEnabled(menuItem)\"\n [class.divider]=\"menuItem.divider\"\n [class.dropdown-divider]=\"useBootstrap4 && menuItem.divider\"\n [class.active]=\"menuItem.isActive && isMenuItemEnabled(menuItem)\"\n [attr.role]=\"menuItem.divider ? 'separator' : undefined\"\n >\n <a\n *ngIf=\"!menuItem.divider && !menuItem.passive\"\n href\n [class.dropdown-item]=\"useBootstrap4\"\n [class.active]=\"menuItem.isActive && isMenuItemEnabled(menuItem)\"\n [class.disabled]=\"useBootstrap4 && !isMenuItemEnabled(menuItem)\"\n [class.hasSubMenu]=\"!!menuItem.subMenu\"\n (click)=\"onMenuItemSelect(menuItem, $event)\"\n (mouseenter)=\"onOpenSubMenu(menuItem, $event)\"\n >\n <ng-template\n [ngTemplateOutlet]=\"menuItem.template\"\n [ngTemplateOutletContext]=\"{ $implicit: item }\"\n ></ng-template>\n </a>\n\n <span\n (click)=\"stopEvent($event)\"\n (contextmenu)=\"stopEvent($event)\"\n class=\"passive\"\n *ngIf=\"!menuItem.divider && menuItem.passive\"\n [class.dropdown-item]=\"useBootstrap4\"\n [class.disabled]=\"useBootstrap4 && !isMenuItemEnabled(menuItem)\"\n >\n <ng-template\n [ngTemplateOutlet]=\"menuItem.template\"\n [ngTemplateOutletContext]=\"{ $implicit: item }\"\n ></ng-template>\n </span>\n </li>\n </ul>\n </div>\n ",
  615. styles: ["\n .passive {\n display: block;\n padding: 3px 20px;\n clear: both;\n font-weight: normal;\n line-height: @line-height-base;\n white-space: nowrap;\n }\n .hasSubMenu:before {\n content: '\u25B6';\n float: right;\n }\n "]
  616. }] }
  617. ];
  618. /** @nocollapse */
  619. ContextMenuContentComponent.ctorParameters = function () { return [
  620. { type: core.ChangeDetectorRef },
  621. { type: core.ElementRef },
  622. { type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [CONTEXT_MENU_OPTIONS,] }] }
  623. ]; };
  624. ContextMenuContentComponent.propDecorators = {
  625. menuItems: [{ type: core.Input }],
  626. item: [{ type: core.Input }],
  627. event: [{ type: core.Input }],
  628. parentContextMenu: [{ type: core.Input }],
  629. menuClass: [{ type: core.Input }],
  630. overlay: [{ type: core.Input }],
  631. isLeaf: [{ type: core.Input }],
  632. execute: [{ type: core.Output }],
  633. openSubMenu: [{ type: core.Output }],
  634. closeLeafMenu: [{ type: core.Output }],
  635. closeAllMenus: [{ type: core.Output }],
  636. menuElement: [{ type: core.ViewChild, args: ['menu', { static: true },] }],
  637. menuItemElements: [{ type: core.ViewChildren, args: ['li',] }],
  638. onKeyEvent: [{ type: core.HostListener, args: ['window:keydown.ArrowDown', ['$event'],] }, { type: core.HostListener, args: ['window:keydown.ArrowUp', ['$event'],] }],
  639. keyboardOpenSubMenu: [{ type: core.HostListener, args: ['window:keydown.ArrowRight', ['$event'],] }],
  640. keyboardMenuItemSelect: [{ type: core.HostListener, args: ['window:keydown.Enter', ['$event'],] }, { type: core.HostListener, args: ['window:keydown.Space', ['$event'],] }],
  641. onCloseLeafMenu: [{ type: core.HostListener, args: ['window:keydown.Escape', ['$event'],] }, { type: core.HostListener, args: ['window:keydown.ArrowLeft', ['$event'],] }],
  642. closeMenu: [{ type: core.HostListener, args: ['document:click', ['$event'],] }, { type: core.HostListener, args: ['document:contextmenu', ['$event'],] }]
  643. };
  644. return ContextMenuContentComponent;
  645. }());
  646. if (false) {
  647. /** @type {?} */
  648. ContextMenuContentComponent.prototype.menuItems;
  649. /** @type {?} */
  650. ContextMenuContentComponent.prototype.item;
  651. /** @type {?} */
  652. ContextMenuContentComponent.prototype.event;
  653. /** @type {?} */
  654. ContextMenuContentComponent.prototype.parentContextMenu;
  655. /** @type {?} */
  656. ContextMenuContentComponent.prototype.menuClass;
  657. /** @type {?} */
  658. ContextMenuContentComponent.prototype.overlay;
  659. /** @type {?} */
  660. ContextMenuContentComponent.prototype.isLeaf;
  661. /** @type {?} */
  662. ContextMenuContentComponent.prototype.execute;
  663. /** @type {?} */
  664. ContextMenuContentComponent.prototype.openSubMenu;
  665. /** @type {?} */
  666. ContextMenuContentComponent.prototype.closeLeafMenu;
  667. /** @type {?} */
  668. ContextMenuContentComponent.prototype.closeAllMenus;
  669. /** @type {?} */
  670. ContextMenuContentComponent.prototype.menuElement;
  671. /** @type {?} */
  672. ContextMenuContentComponent.prototype.menuItemElements;
  673. /** @type {?} */
  674. ContextMenuContentComponent.prototype.autoFocus;
  675. /** @type {?} */
  676. ContextMenuContentComponent.prototype.useBootstrap4;
  677. /**
  678. * @type {?}
  679. * @private
  680. */
  681. ContextMenuContentComponent.prototype._keyManager;
  682. /**
  683. * @type {?}
  684. * @private
  685. */
  686. ContextMenuContentComponent.prototype.subscription;
  687. /**
  688. * @type {?}
  689. * @private
  690. */
  691. ContextMenuContentComponent.prototype.changeDetector;
  692. /**
  693. * @type {?}
  694. * @private
  695. */
  696. ContextMenuContentComponent.prototype.elementRef;
  697. /**
  698. * @type {?}
  699. * @private
  700. */
  701. ContextMenuContentComponent.prototype.options;
  702. }
  703. /**
  704. * @fileoverview added by tsickle
  705. * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  706. */
  707. /**
  708. * @record
  709. */
  710. function IContextMenuClickEvent() { }
  711. if (false) {
  712. /** @type {?|undefined} */
  713. IContextMenuClickEvent.prototype.anchorElement;
  714. /** @type {?|undefined} */
  715. IContextMenuClickEvent.prototype.contextMenu;
  716. /** @type {?|undefined} */
  717. IContextMenuClickEvent.prototype.event;
  718. /** @type {?|undefined} */
  719. IContextMenuClickEvent.prototype.parentContextMenu;
  720. /** @type {?} */
  721. IContextMenuClickEvent.prototype.item;
  722. /** @type {?|undefined} */
  723. IContextMenuClickEvent.prototype.activeMenuItemIndex;
  724. }
  725. /**
  726. * @record
  727. */
  728. function IContextMenuContext() { }
  729. if (false) {
  730. /** @type {?} */
  731. IContextMenuContext.prototype.menuItems;
  732. /** @type {?} */
  733. IContextMenuContext.prototype.menuClass;
  734. }
  735. /**
  736. * @record
  737. */
  738. function CloseLeafMenuEvent() { }
  739. if (false) {
  740. /** @type {?|undefined} */
  741. CloseLeafMenuEvent.prototype.exceptRootMenu;
  742. /** @type {?|undefined} */
  743. CloseLeafMenuEvent.prototype.event;
  744. }
  745. /**
  746. * @record
  747. */
  748. function OverlayRefWithContextMenu() { }
  749. if (false) {
  750. /** @type {?|undefined} */
  751. OverlayRefWithContextMenu.prototype.contextMenu;
  752. }
  753. /**
  754. * @record
  755. */
  756. function CancelContextMenuEvent() { }
  757. if (false) {
  758. /** @type {?} */
  759. CancelContextMenuEvent.prototype.eventType;
  760. /** @type {?|undefined} */
  761. CancelContextMenuEvent.prototype.event;
  762. }
  763. /**
  764. * @record
  765. */
  766. function ExecuteContextMenuEvent() { }
  767. if (false) {
  768. /** @type {?} */
  769. ExecuteContextMenuEvent.prototype.eventType;
  770. /** @type {?|undefined} */
  771. ExecuteContextMenuEvent.prototype.event;
  772. /** @type {?} */
  773. ExecuteContextMenuEvent.prototype.item;
  774. /** @type {?} */
  775. ExecuteContextMenuEvent.prototype.menuItem;
  776. }
  777. var ContextMenuService = /** @class */ (function () {
  778. function ContextMenuService(overlay, scrollStrategy) {
  779. this.overlay = overlay;
  780. this.scrollStrategy = scrollStrategy;
  781. this.isDestroyingLeafMenu = false;
  782. this.show = new rxjs.Subject();
  783. this.triggerClose = new rxjs.Subject();
  784. this.close = new rxjs.Subject();
  785. this.overlays = [];
  786. this.fakeElement = {
  787. getBoundingClientRect: (/**
  788. * @return {?}
  789. */
  790. function () { return ({
  791. bottom: 0,
  792. height: 0,
  793. left: 0,
  794. right: 0,
  795. top: 0,
  796. width: 0,
  797. }); })
  798. };
  799. }
  800. /**
  801. * @param {?} context
  802. * @return {?}
  803. */
  804. ContextMenuService.prototype.openContextMenu = /**
  805. * @param {?} context
  806. * @return {?}
  807. */
  808. function (context) {
  809. var anchorElement = context.anchorElement, event = context.event, parentContextMenu = context.parentContextMenu;
  810. if (!parentContextMenu) {
  811. /** @type {?} */
  812. var mouseEvent_1 = (/** @type {?} */ (event));
  813. this.fakeElement.getBoundingClientRect = (/**
  814. * @return {?}
  815. */
  816. function () { return ({
  817. bottom: mouseEvent_1.clientY,
  818. height: 0,
  819. left: mouseEvent_1.clientX,
  820. right: mouseEvent_1.clientX,
  821. top: mouseEvent_1.clientY,
  822. width: 0,
  823. }); });
  824. this.closeAllContextMenus({ eventType: 'cancel', event: event });
  825. /** @type {?} */
  826. var positionStrategy = this.overlay.position().connectedTo(new core.ElementRef(anchorElement || this.fakeElement), { originX: 'start', originY: 'bottom' }, { overlayX: 'start', overlayY: 'top' })
  827. .withFallbackPosition({ originX: 'start', originY: 'top' }, { overlayX: 'start', overlayY: 'bottom' })
  828. .withFallbackPosition({ originX: 'end', originY: 'top' }, { overlayX: 'start', overlayY: 'top' })
  829. .withFallbackPosition({ originX: 'start', originY: 'top' }, { overlayX: 'end', overlayY: 'top' })
  830. .withFallbackPosition({ originX: 'end', originY: 'center' }, { overlayX: 'start', overlayY: 'center' })
  831. .withFallbackPosition({ originX: 'start', originY: 'center' }, { overlayX: 'end', overlayY: 'center' });
  832. this.overlays = [this.overlay.create({
  833. positionStrategy: positionStrategy,
  834. panelClass: 'ngx-contextmenu',
  835. scrollStrategy: this.scrollStrategy.close(),
  836. })];
  837. this.attachContextMenu(this.overlays[0], context);
  838. }
  839. else {
  840. /** @type {?} */
  841. var positionStrategy = this.overlay.position().connectedTo(new core.ElementRef(event ? event.target : anchorElement), { originX: 'end', originY: 'top' }, { overlayX: 'start', overlayY: 'top' })
  842. .withFallbackPosition({ originX: 'start', originY: 'top' }, { overlayX: 'end', overlayY: 'top' })
  843. .withFallbackPosition({ originX: 'end', originY: 'bottom' }, { overlayX: 'start', overlayY: 'bottom' })
  844. .withFallbackPosition({ originX: 'start', originY: 'bottom' }, { overlayX: 'end', overlayY: 'bottom' });
  845. /** @type {?} */
  846. var newOverlay = this.overlay.create({
  847. positionStrategy: positionStrategy,
  848. panelClass: 'ngx-contextmenu',
  849. scrollStrategy: this.scrollStrategy.close(),
  850. });
  851. this.destroySubMenus(parentContextMenu);
  852. this.overlays = this.overlays.concat(newOverlay);
  853. this.attachContextMenu(newOverlay, context);
  854. }
  855. };
  856. /**
  857. * @param {?} overlay
  858. * @param {?} context
  859. * @return {?}
  860. */
  861. ContextMenuService.prototype.attachContextMenu = /**
  862. * @param {?} overlay
  863. * @param {?} context
  864. * @return {?}
  865. */
  866. function (overlay, context) {
  867. var _this = this;
  868. var event = context.event, item = context.item, menuItems = context.menuItems, menuClass = context.menuClass;
  869. /** @type {?} */
  870. var contextMenuContent = overlay.attach(new portal.ComponentPortal(ContextMenuContentComponent));
  871. contextMenuContent.instance.event = event;
  872. contextMenuContent.instance.item = item;
  873. contextMenuContent.instance.menuItems = menuItems;
  874. contextMenuContent.instance.overlay = overlay;
  875. contextMenuContent.instance.isLeaf = true;
  876. contextMenuContent.instance.menuClass = menuClass;
  877. ((/** @type {?} */ (overlay))).contextMenu = contextMenuContent.instance;
  878. /** @type {?} */
  879. var subscriptions = new rxjs.Subscription();
  880. subscriptions.add(contextMenuContent.instance.execute.asObservable()
  881. .subscribe((/**
  882. * @param {?} executeEvent
  883. * @return {?}
  884. */
  885. function (executeEvent) { return _this.closeAllContextMenus(__assign({ eventType: 'execute' }, executeEvent)); })));
  886. subscriptions.add(contextMenuContent.instance.closeAllMenus.asObservable()
  887. .subscribe((/**
  888. * @param {?} closeAllEvent
  889. * @return {?}
  890. */
  891. function (closeAllEvent) { return _this.closeAllContextMenus(__assign({ eventType: 'cancel' }, closeAllEvent)); })));
  892. subscriptions.add(contextMenuContent.instance.closeLeafMenu.asObservable()
  893. .subscribe((/**
  894. * @param {?} closeLeafMenuEvent
  895. * @return {?}
  896. */
  897. function (closeLeafMenuEvent) { return _this.destroyLeafMenu(closeLeafMenuEvent); })));
  898. subscriptions.add(contextMenuContent.instance.openSubMenu.asObservable()
  899. .subscribe((/**
  900. * @param {?} subMenuEvent
  901. * @return {?}
  902. */
  903. function (subMenuEvent) {
  904. _this.destroySubMenus(contextMenuContent.instance);
  905. if (!subMenuEvent.contextMenu) {
  906. contextMenuContent.instance.isLeaf = true;
  907. return;
  908. }
  909. contextMenuContent.instance.isLeaf = false;
  910. _this.show.next(subMenuEvent);
  911. })));
  912. contextMenuContent.onDestroy((/**
  913. * @return {?}
  914. */
  915. function () {
  916. menuItems.forEach((/**
  917. * @param {?} menuItem
  918. * @return {?}
  919. */
  920. function (menuItem) { return menuItem.isActive = false; }));
  921. subscriptions.unsubscribe();
  922. }));
  923. contextMenuContent.changeDetectorRef.detectChanges();
  924. };
  925. /**
  926. * @param {?} closeEvent
  927. * @return {?}
  928. */
  929. ContextMenuService.prototype.closeAllContextMenus = /**
  930. * @param {?} closeEvent
  931. * @return {?}
  932. */
  933. function (closeEvent) {
  934. if (this.overlays) {
  935. this.close.next(closeEvent);
  936. this.overlays.forEach((/**
  937. * @param {?} overlay
  938. * @param {?} index
  939. * @return {?}
  940. */
  941. function (overlay, index) {
  942. overlay.detach();
  943. overlay.dispose();
  944. }));
  945. }
  946. this.overlays = [];
  947. };
  948. /**
  949. * @return {?}
  950. */
  951. ContextMenuService.prototype.getLastAttachedOverlay = /**
  952. * @return {?}
  953. */
  954. function () {
  955. /** @type {?} */
  956. var overlay = this.overlays[this.overlays.length - 1];
  957. while (this.overlays.length > 1 && overlay && !overlay.hasAttached()) {
  958. overlay.detach();
  959. overlay.dispose();
  960. this.overlays = this.overlays.slice(0, -1);
  961. overlay = this.overlays[this.overlays.length - 1];
  962. }
  963. return overlay;
  964. };
  965. /**
  966. * @param {?=} __0
  967. * @return {?}
  968. */
  969. ContextMenuService.prototype.destroyLeafMenu = /**
  970. * @param {?=} __0
  971. * @return {?}
  972. */
  973. function (_a) {
  974. var _this = this;
  975. var _b = _a === void 0 ? {} : _a, exceptRootMenu = _b.exceptRootMenu, event = _b.event;
  976. if (this.isDestroyingLeafMenu) {
  977. return;
  978. }
  979. this.isDestroyingLeafMenu = true;
  980. setTimeout((/**
  981. * @return {?}
  982. */
  983. function () {
  984. /** @type {?} */
  985. var overlay = _this.getLastAttachedOverlay();
  986. if (_this.overlays.length > 1 && overlay) {
  987. overlay.detach();
  988. overlay.dispose();
  989. }
  990. if (!exceptRootMenu && _this.overlays.length > 0 && overlay) {
  991. _this.close.next({ eventType: 'cancel', event: event });
  992. overlay.detach();
  993. overlay.dispose();
  994. }
  995. /** @type {?} */
  996. var newLeaf = _this.getLastAttachedOverlay();
  997. if (newLeaf) {
  998. newLeaf.contextMenu.isLeaf = true;
  999. }
  1000. _this.isDestroyingLeafMenu = false;
  1001. }));
  1002. };
  1003. /**
  1004. * @param {?} contextMenu
  1005. * @return {?}
  1006. */
  1007. ContextMenuService.prototype.destroySubMenus = /**
  1008. * @param {?} contextMenu
  1009. * @return {?}
  1010. */
  1011. function (contextMenu) {
  1012. /** @type {?} */
  1013. var overlay = contextMenu.overlay;
  1014. /** @type {?} */
  1015. var index = this.overlays.indexOf(overlay);
  1016. this.overlays.slice(index + 1).forEach((/**
  1017. * @param {?} subMenuOverlay
  1018. * @return {?}
  1019. */
  1020. function (subMenuOverlay) {
  1021. subMenuOverlay.detach();
  1022. subMenuOverlay.dispose();
  1023. }));
  1024. };
  1025. /**
  1026. * @param {?} contextMenuContent
  1027. * @return {?}
  1028. */
  1029. ContextMenuService.prototype.isLeafMenu = /**
  1030. * @param {?} contextMenuContent
  1031. * @return {?}
  1032. */
  1033. function (contextMenuContent) {
  1034. /** @type {?} */
  1035. var overlay = this.getLastAttachedOverlay();
  1036. return contextMenuContent.overlay === overlay;
  1037. };
  1038. ContextMenuService.decorators = [
  1039. { type: core.Injectable }
  1040. ];
  1041. /** @nocollapse */
  1042. ContextMenuService.ctorParameters = function () { return [
  1043. { type: overlay.Overlay },
  1044. { type: overlay.ScrollStrategyOptions }
  1045. ]; };
  1046. return ContextMenuService;
  1047. }());
  1048. if (false) {
  1049. /** @type {?} */
  1050. ContextMenuService.prototype.isDestroyingLeafMenu;
  1051. /** @type {?} */
  1052. ContextMenuService.prototype.show;
  1053. /** @type {?} */
  1054. ContextMenuService.prototype.triggerClose;
  1055. /** @type {?} */
  1056. ContextMenuService.prototype.close;
  1057. /**
  1058. * @type {?}
  1059. * @private
  1060. */
  1061. ContextMenuService.prototype.contextMenuContent;
  1062. /**
  1063. * @type {?}
  1064. * @private
  1065. */
  1066. ContextMenuService.prototype.overlays;
  1067. /**
  1068. * @type {?}
  1069. * @private
  1070. */
  1071. ContextMenuService.prototype.fakeElement;
  1072. /**
  1073. * @type {?}
  1074. * @private
  1075. */
  1076. ContextMenuService.prototype.overlay;
  1077. /**
  1078. * @type {?}
  1079. * @private
  1080. */
  1081. ContextMenuService.prototype.scrollStrategy;
  1082. }
  1083. /**
  1084. * @fileoverview added by tsickle
  1085. * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1086. */
  1087. /**
  1088. * @record
  1089. */
  1090. function ILinkConfig$1() { }
  1091. if (false) {
  1092. /** @type {?} */
  1093. ILinkConfig$1.prototype.click;
  1094. /** @type {?|undefined} */
  1095. ILinkConfig$1.prototype.enabled;
  1096. /** @type {?} */
  1097. ILinkConfig$1.prototype.html;
  1098. }
  1099. /**
  1100. * @record
  1101. */
  1102. function MouseLocation() { }
  1103. if (false) {
  1104. /** @type {?|undefined} */
  1105. MouseLocation.prototype.left;
  1106. /** @type {?|undefined} */
  1107. MouseLocation.prototype.marginLeft;
  1108. /** @type {?|undefined} */
  1109. MouseLocation.prototype.marginTop;
  1110. /** @type {?|undefined} */
  1111. MouseLocation.prototype.top;
  1112. }
  1113. var ContextMenuComponent = /** @class */ (function () {
  1114. function ContextMenuComponent(_contextMenuService, changeDetector, elementRef, options) {
  1115. var _this = this;
  1116. this._contextMenuService = _contextMenuService;
  1117. this.changeDetector = changeDetector;
  1118. this.elementRef = elementRef;
  1119. this.options = options;
  1120. this.menuClass = "";
  1121. this.autoFocus = false;
  1122. this.useBootstrap4 = false;
  1123. this.disabled = false;
  1124. this.close = new core.EventEmitter();
  1125. this.open = new core.EventEmitter();
  1126. this.visibleMenuItems = [];
  1127. this.links = [];
  1128. this.subscription = new rxjs.Subscription();
  1129. if (options) {
  1130. this.autoFocus = options.autoFocus;
  1131. this.useBootstrap4 = options.useBootstrap4;
  1132. }
  1133. this.subscription.add(_contextMenuService.show.subscribe((/**
  1134. * @param {?} menuEvent
  1135. * @return {?}
  1136. */
  1137. function (menuEvent) {
  1138. _this.onMenuEvent(menuEvent);
  1139. })));
  1140. }
  1141. /**
  1142. * @return {?}
  1143. */
  1144. ContextMenuComponent.prototype.ngOnDestroy = /**
  1145. * @return {?}
  1146. */
  1147. function () {
  1148. this.subscription.unsubscribe();
  1149. };
  1150. /**
  1151. * @param {?} menuEvent
  1152. * @return {?}
  1153. */
  1154. ContextMenuComponent.prototype.onMenuEvent = /**
  1155. * @param {?} menuEvent
  1156. * @return {?}
  1157. */
  1158. function (menuEvent) {
  1159. var _this = this;
  1160. if (this.disabled) {
  1161. return;
  1162. }
  1163. var contextMenu = menuEvent.contextMenu, event = menuEvent.event, item = menuEvent.item;
  1164. if (contextMenu && contextMenu !== this) {
  1165. return;
  1166. }
  1167. this.event = event;
  1168. this.item = item;
  1169. this.setVisibleMenuItems();
  1170. this._contextMenuService.openContextMenu(__assign({}, menuEvent, { menuItems: this.visibleMenuItems, menuClass: this.menuClass }));
  1171. this._contextMenuService.close.asObservable().pipe(operators.first()).subscribe((/**
  1172. * @param {?} closeEvent
  1173. * @return {?}
  1174. */
  1175. function (closeEvent) { return _this.close.emit(closeEvent); }));
  1176. this.open.next(menuEvent);
  1177. };
  1178. /**
  1179. * @param {?} menuItem
  1180. * @return {?}
  1181. */
  1182. ContextMenuComponent.prototype.isMenuItemVisible = /**
  1183. * @param {?} menuItem
  1184. * @return {?}
  1185. */
  1186. function (menuItem) {
  1187. return this.evaluateIfFunction(menuItem.visible);
  1188. };
  1189. /**
  1190. * @return {?}
  1191. */
  1192. ContextMenuComponent.prototype.setVisibleMenuItems = /**
  1193. * @return {?}
  1194. */
  1195. function () {
  1196. var _this = this;
  1197. this.visibleMenuItems = this.menuItems.filter((/**
  1198. * @param {?} menuItem
  1199. * @return {?}
  1200. */
  1201. function (menuItem) { return _this.isMenuItemVisible(menuItem); }));
  1202. };
  1203. /**
  1204. * @param {?} value
  1205. * @return {?}
  1206. */
  1207. ContextMenuComponent.prototype.evaluateIfFunction = /**
  1208. * @param {?} value
  1209. * @return {?}
  1210. */
  1211. function (value) {
  1212. if (value instanceof Function) {
  1213. return value(this.item);
  1214. }
  1215. return value;
  1216. };
  1217. ContextMenuComponent.decorators = [
  1218. { type: core.Component, args: [{
  1219. encapsulation: core.ViewEncapsulation.None,
  1220. selector: 'context-menu',
  1221. template: " ",
  1222. styles: ["\n .cdk-overlay-container {\n position: fixed;\n z-index: 1000;\n pointer-events: none;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n }\n .ngx-contextmenu.cdk-overlay-pane {\n position: absolute;\n pointer-events: auto;\n box-sizing: border-box;\n }\n "]
  1223. }] }
  1224. ];
  1225. /** @nocollapse */
  1226. ContextMenuComponent.ctorParameters = function () { return [
  1227. { type: ContextMenuService },
  1228. { type: core.ChangeDetectorRef },
  1229. { type: core.ElementRef },
  1230. { type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [CONTEXT_MENU_OPTIONS,] }] }
  1231. ]; };
  1232. ContextMenuComponent.propDecorators = {
  1233. menuClass: [{ type: core.Input }],
  1234. autoFocus: [{ type: core.Input }],
  1235. useBootstrap4: [{ type: core.Input }],
  1236. disabled: [{ type: core.Input }],
  1237. close: [{ type: core.Output }],
  1238. open: [{ type: core.Output }],
  1239. menuItems: [{ type: core.ContentChildren, args: [ContextMenuItemDirective,] }],
  1240. menuElement: [{ type: core.ViewChild, args: ['menu', { static: false },] }]
  1241. };
  1242. return ContextMenuComponent;
  1243. }());
  1244. if (false) {
  1245. /** @type {?} */
  1246. ContextMenuComponent.prototype.menuClass;
  1247. /** @type {?} */
  1248. ContextMenuComponent.prototype.autoFocus;
  1249. /** @type {?} */
  1250. ContextMenuComponent.prototype.useBootstrap4;
  1251. /** @type {?} */
  1252. ContextMenuComponent.prototype.disabled;
  1253. /** @type {?} */
  1254. ContextMenuComponent.prototype.close;
  1255. /** @type {?} */
  1256. ContextMenuComponent.prototype.open;
  1257. /** @type {?} */
  1258. ContextMenuComponent.prototype.menuItems;
  1259. /** @type {?} */
  1260. ContextMenuComponent.prototype.menuElement;
  1261. /** @type {?} */
  1262. ContextMenuComponent.prototype.visibleMenuItems;
  1263. /** @type {?} */
  1264. ContextMenuComponent.prototype.links;
  1265. /** @type {?} */
  1266. ContextMenuComponent.prototype.item;
  1267. /** @type {?} */
  1268. ContextMenuComponent.prototype.event;
  1269. /**
  1270. * @type {?}
  1271. * @private
  1272. */
  1273. ContextMenuComponent.prototype.subscription;
  1274. /**
  1275. * @type {?}
  1276. * @private
  1277. */
  1278. ContextMenuComponent.prototype._contextMenuService;
  1279. /**
  1280. * @type {?}
  1281. * @private
  1282. */
  1283. ContextMenuComponent.prototype.changeDetector;
  1284. /**
  1285. * @type {?}
  1286. * @private
  1287. */
  1288. ContextMenuComponent.prototype.elementRef;
  1289. /**
  1290. * @type {?}
  1291. * @private
  1292. */
  1293. ContextMenuComponent.prototype.options;
  1294. }
  1295. /**
  1296. * @fileoverview added by tsickle
  1297. * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1298. */
  1299. var ContextMenuAttachDirective = /** @class */ (function () {
  1300. function ContextMenuAttachDirective(contextMenuService) {
  1301. this.contextMenuService = contextMenuService;
  1302. }
  1303. /**
  1304. * @param {?} event
  1305. * @return {?}
  1306. */
  1307. ContextMenuAttachDirective.prototype.onContextMenu = /**
  1308. * @param {?} event
  1309. * @return {?}
  1310. */
  1311. function (event) {
  1312. if (!this.contextMenu.disabled) {
  1313. this.contextMenuService.show.next({
  1314. contextMenu: this.contextMenu,
  1315. event: event,
  1316. item: this.contextMenuSubject,
  1317. });
  1318. event.preventDefault();
  1319. event.stopPropagation();
  1320. }
  1321. };
  1322. ContextMenuAttachDirective.decorators = [
  1323. { type: core.Directive, args: [{
  1324. selector: '[contextMenu]',
  1325. },] }
  1326. ];
  1327. /** @nocollapse */
  1328. ContextMenuAttachDirective.ctorParameters = function () { return [
  1329. { type: ContextMenuService }
  1330. ]; };
  1331. ContextMenuAttachDirective.propDecorators = {
  1332. contextMenuSubject: [{ type: core.Input }],
  1333. contextMenu: [{ type: core.Input }],
  1334. onContextMenu: [{ type: core.HostListener, args: ['contextmenu', ['$event'],] }]
  1335. };
  1336. return ContextMenuAttachDirective;
  1337. }());
  1338. if (false) {
  1339. /** @type {?} */
  1340. ContextMenuAttachDirective.prototype.contextMenuSubject;
  1341. /** @type {?} */
  1342. ContextMenuAttachDirective.prototype.contextMenu;
  1343. /**
  1344. * @type {?}
  1345. * @private
  1346. */
  1347. ContextMenuAttachDirective.prototype.contextMenuService;
  1348. }
  1349. /**
  1350. * @fileoverview added by tsickle
  1351. * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1352. */
  1353. var ContextMenuModule = /** @class */ (function () {
  1354. function ContextMenuModule() {
  1355. }
  1356. /**
  1357. * @param {?=} options
  1358. * @return {?}
  1359. */
  1360. ContextMenuModule.forRoot = /**
  1361. * @param {?=} options
  1362. * @return {?}
  1363. */
  1364. function (options) {
  1365. return {
  1366. ngModule: ContextMenuModule,
  1367. providers: [
  1368. ContextMenuService,
  1369. {
  1370. provide: CONTEXT_MENU_OPTIONS,
  1371. useValue: options,
  1372. },
  1373. ],
  1374. };
  1375. };
  1376. ContextMenuModule.decorators = [
  1377. { type: core.NgModule, args: [{
  1378. declarations: [
  1379. ContextMenuAttachDirective,
  1380. ContextMenuComponent,
  1381. ContextMenuContentComponent,
  1382. ContextMenuItemDirective,
  1383. ],
  1384. entryComponents: [
  1385. ContextMenuContentComponent,
  1386. ],
  1387. exports: [
  1388. ContextMenuAttachDirective,
  1389. ContextMenuComponent,
  1390. ContextMenuItemDirective,
  1391. ],
  1392. imports: [
  1393. common.CommonModule,
  1394. overlay.OverlayModule,
  1395. ],
  1396. },] }
  1397. ];
  1398. return ContextMenuModule;
  1399. }());
  1400. /**
  1401. * @fileoverview added by tsickle
  1402. * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1403. */
  1404. /**
  1405. * @record
  1406. */
  1407. function IContextMenuOptions() { }
  1408. if (false) {
  1409. /** @type {?|undefined} */
  1410. IContextMenuOptions.prototype.useBootstrap4;
  1411. /** @type {?|undefined} */
  1412. IContextMenuOptions.prototype.autoFocus;
  1413. }
  1414. exports.ContextMenuComponent = ContextMenuComponent;
  1415. exports.ContextMenuModule = ContextMenuModule;
  1416. exports.ContextMenuService = ContextMenuService;
  1417. exports.ɵa = ContextMenuAttachDirective;
  1418. exports.ɵb = ContextMenuItemDirective;
  1419. exports.ɵc = CONTEXT_MENU_OPTIONS;
  1420. exports.ɵd = ContextMenuContentComponent;
  1421. Object.defineProperty(exports, '__esModule', { value: true });
  1422. })));
  1423. //# sourceMappingURL=ngx-contextmenu.umd.js.map