switch.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return function (d, b) {
  7. extendStatics(d, b);
  8. function __() { this.constructor = d; }
  9. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10. };
  11. })();
  12. /*!
  13. * devextreme-angular
  14. * Version: 19.1.16
  15. * Build date: Tue Oct 18 2022
  16. *
  17. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  18. *
  19. * This software may be modified and distributed under the terms
  20. * of the MIT license. See the LICENSE file in the root of the project for details.
  21. *
  22. * https://github.com/DevExpress/devextreme-angular
  23. */
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. var platform_browser_1 = require("@angular/platform-browser");
  26. var platform_browser_2 = require("@angular/platform-browser");
  27. var core_1 = require("@angular/core");
  28. var switch_1 = require("devextreme/ui/switch");
  29. var forms_1 = require("@angular/forms");
  30. var component_1 = require("../core/component");
  31. var template_host_1 = require("../core/template-host");
  32. var integration_1 = require("../core/integration");
  33. var template_1 = require("../core/template");
  34. var nested_option_1 = require("../core/nested-option");
  35. var watcher_helper_1 = require("../core/watcher-helper");
  36. var CUSTOM_VALUE_ACCESSOR_PROVIDER = {
  37. provide: forms_1.NG_VALUE_ACCESSOR,
  38. useExisting: core_1.forwardRef(function () { return DxSwitchComponent; }),
  39. multi: true
  40. };
  41. /**
  42. * The Switch is a widget that can be in two states: "On" and "Off".
  43. */
  44. var DxSwitchComponent = (function (_super) {
  45. __extends(DxSwitchComponent, _super);
  46. function DxSwitchComponent(elementRef, ngZone, templateHost, _watcherHelper, optionHost, transferState, platformId) {
  47. var _this = _super.call(this, elementRef, ngZone, templateHost, _watcherHelper, transferState, platformId) || this;
  48. _this.touched = function (_) { };
  49. _this._createEventEmitters([
  50. { subscribe: 'contentReady', emit: 'onContentReady' },
  51. { subscribe: 'disposing', emit: 'onDisposing' },
  52. { subscribe: 'initialized', emit: 'onInitialized' },
  53. { subscribe: 'optionChanged', emit: 'onOptionChanged' },
  54. { subscribe: 'valueChanged', emit: 'onValueChanged' },
  55. { emit: 'accessKeyChange' },
  56. { emit: 'activeStateEnabledChange' },
  57. { emit: 'disabledChange' },
  58. { emit: 'elementAttrChange' },
  59. { emit: 'focusStateEnabledChange' },
  60. { emit: 'heightChange' },
  61. { emit: 'hintChange' },
  62. { emit: 'hoverStateEnabledChange' },
  63. { emit: 'isValidChange' },
  64. { emit: 'nameChange' },
  65. { emit: 'offTextChange' },
  66. { emit: 'onTextChange' },
  67. { emit: 'readOnlyChange' },
  68. { emit: 'rtlEnabledChange' },
  69. { emit: 'switchedOffTextChange' },
  70. { emit: 'switchedOnTextChange' },
  71. { emit: 'tabIndexChange' },
  72. { emit: 'validationErrorChange' },
  73. { emit: 'validationMessageModeChange' },
  74. { emit: 'valueChange' },
  75. { emit: 'visibleChange' },
  76. { emit: 'widthChange' },
  77. { emit: 'onBlur' }
  78. ]);
  79. optionHost.setHost(_this);
  80. return _this;
  81. }
  82. Object.defineProperty(DxSwitchComponent.prototype, "accessKey", {
  83. get: /**
  84. * Specifies the shortcut key that sets focus on the widget.
  85. */
  86. function () {
  87. return this._getOption('accessKey');
  88. },
  89. set: function (value) {
  90. this._setOption('accessKey', value);
  91. },
  92. enumerable: true,
  93. configurable: true
  94. });
  95. Object.defineProperty(DxSwitchComponent.prototype, "activeStateEnabled", {
  96. get: /**
  97. * Specifies whether or not the widget changes its state when interacting with a user.
  98. */
  99. function () {
  100. return this._getOption('activeStateEnabled');
  101. },
  102. set: function (value) {
  103. this._setOption('activeStateEnabled', value);
  104. },
  105. enumerable: true,
  106. configurable: true
  107. });
  108. Object.defineProperty(DxSwitchComponent.prototype, "disabled", {
  109. get: /**
  110. * Specifies whether the widget responds to user interaction.
  111. */
  112. function () {
  113. return this._getOption('disabled');
  114. },
  115. set: function (value) {
  116. this._setOption('disabled', value);
  117. },
  118. enumerable: true,
  119. configurable: true
  120. });
  121. Object.defineProperty(DxSwitchComponent.prototype, "elementAttr", {
  122. get: /**
  123. * Specifies the attributes to be attached to the widget's root element.
  124. */
  125. function () {
  126. return this._getOption('elementAttr');
  127. },
  128. set: function (value) {
  129. this._setOption('elementAttr', value);
  130. },
  131. enumerable: true,
  132. configurable: true
  133. });
  134. Object.defineProperty(DxSwitchComponent.prototype, "focusStateEnabled", {
  135. get: /**
  136. * Specifies whether the widget can be focused using keyboard navigation.
  137. */
  138. function () {
  139. return this._getOption('focusStateEnabled');
  140. },
  141. set: function (value) {
  142. this._setOption('focusStateEnabled', value);
  143. },
  144. enumerable: true,
  145. configurable: true
  146. });
  147. Object.defineProperty(DxSwitchComponent.prototype, "height", {
  148. get: /**
  149. * Specifies the widget's height.
  150. */
  151. function () {
  152. return this._getOption('height');
  153. },
  154. set: function (value) {
  155. this._setOption('height', value);
  156. },
  157. enumerable: true,
  158. configurable: true
  159. });
  160. Object.defineProperty(DxSwitchComponent.prototype, "hint", {
  161. get: /**
  162. * Specifies text for a hint that appears when a user pauses on the widget.
  163. */
  164. function () {
  165. return this._getOption('hint');
  166. },
  167. set: function (value) {
  168. this._setOption('hint', value);
  169. },
  170. enumerable: true,
  171. configurable: true
  172. });
  173. Object.defineProperty(DxSwitchComponent.prototype, "hoverStateEnabled", {
  174. get: /**
  175. * Specifies whether the widget changes its state when a user pauses on it.
  176. */
  177. function () {
  178. return this._getOption('hoverStateEnabled');
  179. },
  180. set: function (value) {
  181. this._setOption('hoverStateEnabled', value);
  182. },
  183. enumerable: true,
  184. configurable: true
  185. });
  186. Object.defineProperty(DxSwitchComponent.prototype, "isValid", {
  187. get: /**
  188. * Specifies whether the editor's value is valid.
  189. */
  190. function () {
  191. return this._getOption('isValid');
  192. },
  193. set: function (value) {
  194. this._setOption('isValid', value);
  195. },
  196. enumerable: true,
  197. configurable: true
  198. });
  199. Object.defineProperty(DxSwitchComponent.prototype, "name", {
  200. get: /**
  201. * The value to be assigned to the `name` attribute of the underlying HTML element.
  202. */
  203. function () {
  204. return this._getOption('name');
  205. },
  206. set: function (value) {
  207. this._setOption('name', value);
  208. },
  209. enumerable: true,
  210. configurable: true
  211. });
  212. Object.defineProperty(DxSwitchComponent.prototype, "offText", {
  213. get: /**
  214. * Use the switchedOffText option instead.
  215. */
  216. function () {
  217. return this._getOption('offText');
  218. },
  219. set: function (value) {
  220. this._setOption('offText', value);
  221. },
  222. enumerable: true,
  223. configurable: true
  224. });
  225. Object.defineProperty(DxSwitchComponent.prototype, "onText", {
  226. get: /**
  227. * Use the switchedOnText option instead.
  228. */
  229. function () {
  230. return this._getOption('onText');
  231. },
  232. set: function (value) {
  233. this._setOption('onText', value);
  234. },
  235. enumerable: true,
  236. configurable: true
  237. });
  238. Object.defineProperty(DxSwitchComponent.prototype, "readOnly", {
  239. get: /**
  240. * Specifies whether the editor is read-only.
  241. */
  242. function () {
  243. return this._getOption('readOnly');
  244. },
  245. set: function (value) {
  246. this._setOption('readOnly', value);
  247. },
  248. enumerable: true,
  249. configurable: true
  250. });
  251. Object.defineProperty(DxSwitchComponent.prototype, "rtlEnabled", {
  252. get: /**
  253. * Switches the widget to a right-to-left representation.
  254. */
  255. function () {
  256. return this._getOption('rtlEnabled');
  257. },
  258. set: function (value) {
  259. this._setOption('rtlEnabled', value);
  260. },
  261. enumerable: true,
  262. configurable: true
  263. });
  264. Object.defineProperty(DxSwitchComponent.prototype, "switchedOffText", {
  265. get: /**
  266. * Specifies the text displayed when the widget is switched off.
  267. */
  268. function () {
  269. return this._getOption('switchedOffText');
  270. },
  271. set: function (value) {
  272. this._setOption('switchedOffText', value);
  273. },
  274. enumerable: true,
  275. configurable: true
  276. });
  277. Object.defineProperty(DxSwitchComponent.prototype, "switchedOnText", {
  278. get: /**
  279. * Specifies the text displayed when the widget is switched on.
  280. */
  281. function () {
  282. return this._getOption('switchedOnText');
  283. },
  284. set: function (value) {
  285. this._setOption('switchedOnText', value);
  286. },
  287. enumerable: true,
  288. configurable: true
  289. });
  290. Object.defineProperty(DxSwitchComponent.prototype, "tabIndex", {
  291. get: /**
  292. * Specifies the number of the element when the Tab key is used for navigating.
  293. */
  294. function () {
  295. return this._getOption('tabIndex');
  296. },
  297. set: function (value) {
  298. this._setOption('tabIndex', value);
  299. },
  300. enumerable: true,
  301. configurable: true
  302. });
  303. Object.defineProperty(DxSwitchComponent.prototype, "validationError", {
  304. get: /**
  305. * Specifies information on the validation error when using a custom validation engine. Should be changed at runtime along with the isValid option.
  306. */
  307. function () {
  308. return this._getOption('validationError');
  309. },
  310. set: function (value) {
  311. this._setOption('validationError', value);
  312. },
  313. enumerable: true,
  314. configurable: true
  315. });
  316. Object.defineProperty(DxSwitchComponent.prototype, "validationMessageMode", {
  317. get: /**
  318. * Specifies how the message about the validation rules that are not satisfied by this editor's value is displayed.
  319. */
  320. function () {
  321. return this._getOption('validationMessageMode');
  322. },
  323. set: function (value) {
  324. this._setOption('validationMessageMode', value);
  325. },
  326. enumerable: true,
  327. configurable: true
  328. });
  329. Object.defineProperty(DxSwitchComponent.prototype, "value", {
  330. get: /**
  331. * A Boolean value specifying whether the current switch state is "On" or "Off".
  332. */
  333. function () {
  334. return this._getOption('value');
  335. },
  336. set: function (value) {
  337. this._setOption('value', value);
  338. },
  339. enumerable: true,
  340. configurable: true
  341. });
  342. Object.defineProperty(DxSwitchComponent.prototype, "visible", {
  343. get: /**
  344. * Specifies whether the widget is visible.
  345. */
  346. function () {
  347. return this._getOption('visible');
  348. },
  349. set: function (value) {
  350. this._setOption('visible', value);
  351. },
  352. enumerable: true,
  353. configurable: true
  354. });
  355. Object.defineProperty(DxSwitchComponent.prototype, "width", {
  356. get: /**
  357. * Specifies the widget's width.
  358. */
  359. function () {
  360. return this._getOption('width');
  361. },
  362. set: function (value) {
  363. this._setOption('width', value);
  364. },
  365. enumerable: true,
  366. configurable: true
  367. });
  368. DxSwitchComponent.prototype.change = function (_) { };
  369. DxSwitchComponent.prototype._createInstance = function (element, options) {
  370. return new switch_1.default(element, options);
  371. };
  372. DxSwitchComponent.prototype.writeValue = function (value) {
  373. this.eventHelper.lockedValueChangeEvent = true;
  374. this.value = value;
  375. this.eventHelper.lockedValueChangeEvent = false;
  376. };
  377. DxSwitchComponent.prototype.setDisabledState = function (isDisabled) {
  378. this.disabled = isDisabled;
  379. };
  380. DxSwitchComponent.prototype.registerOnChange = function (fn) { this.change = fn; };
  381. DxSwitchComponent.prototype.registerOnTouched = function (fn) { this.touched = fn; };
  382. DxSwitchComponent.prototype._createWidget = function (element) {
  383. var _this = this;
  384. _super.prototype._createWidget.call(this, element);
  385. this.instance.on('focusOut', function (e) {
  386. _this.eventHelper.fireNgEvent('onBlur', [e]);
  387. });
  388. };
  389. DxSwitchComponent.prototype.ngOnDestroy = function () {
  390. this._destroyWidget();
  391. };
  392. DxSwitchComponent.decorators = [
  393. { type: core_1.Component, args: [{
  394. selector: 'dx-switch',
  395. template: '',
  396. providers: [
  397. template_host_1.DxTemplateHost,
  398. watcher_helper_1.WatcherHelper,
  399. CUSTOM_VALUE_ACCESSOR_PROVIDER,
  400. nested_option_1.NestedOptionHost
  401. ]
  402. },] },
  403. ];
  404. /** @nocollapse */
  405. DxSwitchComponent.ctorParameters = function () { return [
  406. { type: core_1.ElementRef, },
  407. { type: core_1.NgZone, },
  408. { type: template_host_1.DxTemplateHost, },
  409. { type: watcher_helper_1.WatcherHelper, },
  410. { type: nested_option_1.NestedOptionHost, },
  411. { type: platform_browser_2.TransferState, },
  412. { type: undefined, decorators: [{ type: core_1.Inject, args: [core_1.PLATFORM_ID,] },] },
  413. ]; };
  414. DxSwitchComponent.propDecorators = {
  415. "accessKey": [{ type: core_1.Input },],
  416. "activeStateEnabled": [{ type: core_1.Input },],
  417. "disabled": [{ type: core_1.Input },],
  418. "elementAttr": [{ type: core_1.Input },],
  419. "focusStateEnabled": [{ type: core_1.Input },],
  420. "height": [{ type: core_1.Input },],
  421. "hint": [{ type: core_1.Input },],
  422. "hoverStateEnabled": [{ type: core_1.Input },],
  423. "isValid": [{ type: core_1.Input },],
  424. "name": [{ type: core_1.Input },],
  425. "offText": [{ type: core_1.Input },],
  426. "onText": [{ type: core_1.Input },],
  427. "readOnly": [{ type: core_1.Input },],
  428. "rtlEnabled": [{ type: core_1.Input },],
  429. "switchedOffText": [{ type: core_1.Input },],
  430. "switchedOnText": [{ type: core_1.Input },],
  431. "tabIndex": [{ type: core_1.Input },],
  432. "validationError": [{ type: core_1.Input },],
  433. "validationMessageMode": [{ type: core_1.Input },],
  434. "value": [{ type: core_1.Input },],
  435. "visible": [{ type: core_1.Input },],
  436. "width": [{ type: core_1.Input },],
  437. "onContentReady": [{ type: core_1.Output },],
  438. "onDisposing": [{ type: core_1.Output },],
  439. "onInitialized": [{ type: core_1.Output },],
  440. "onOptionChanged": [{ type: core_1.Output },],
  441. "onValueChanged": [{ type: core_1.Output },],
  442. "accessKeyChange": [{ type: core_1.Output },],
  443. "activeStateEnabledChange": [{ type: core_1.Output },],
  444. "disabledChange": [{ type: core_1.Output },],
  445. "elementAttrChange": [{ type: core_1.Output },],
  446. "focusStateEnabledChange": [{ type: core_1.Output },],
  447. "heightChange": [{ type: core_1.Output },],
  448. "hintChange": [{ type: core_1.Output },],
  449. "hoverStateEnabledChange": [{ type: core_1.Output },],
  450. "isValidChange": [{ type: core_1.Output },],
  451. "nameChange": [{ type: core_1.Output },],
  452. "offTextChange": [{ type: core_1.Output },],
  453. "onTextChange": [{ type: core_1.Output },],
  454. "readOnlyChange": [{ type: core_1.Output },],
  455. "rtlEnabledChange": [{ type: core_1.Output },],
  456. "switchedOffTextChange": [{ type: core_1.Output },],
  457. "switchedOnTextChange": [{ type: core_1.Output },],
  458. "tabIndexChange": [{ type: core_1.Output },],
  459. "validationErrorChange": [{ type: core_1.Output },],
  460. "validationMessageModeChange": [{ type: core_1.Output },],
  461. "valueChange": [{ type: core_1.Output },],
  462. "visibleChange": [{ type: core_1.Output },],
  463. "widthChange": [{ type: core_1.Output },],
  464. "onBlur": [{ type: core_1.Output },],
  465. "change": [{ type: core_1.HostListener, args: ['valueChange', ['$event'],] },],
  466. "touched": [{ type: core_1.HostListener, args: ['onBlur', ['$event'],] },],
  467. };
  468. return DxSwitchComponent;
  469. }(component_1.DxComponent));
  470. exports.DxSwitchComponent = DxSwitchComponent;
  471. var DxSwitchModule = (function () {
  472. function DxSwitchModule() {
  473. }
  474. DxSwitchModule.decorators = [
  475. { type: core_1.NgModule, args: [{
  476. imports: [
  477. integration_1.DxIntegrationModule,
  478. template_1.DxTemplateModule,
  479. platform_browser_1.BrowserTransferStateModule
  480. ],
  481. declarations: [
  482. DxSwitchComponent
  483. ],
  484. exports: [
  485. DxSwitchComponent,
  486. template_1.DxTemplateModule
  487. ]
  488. },] },
  489. ];
  490. return DxSwitchModule;
  491. }());
  492. exports.DxSwitchModule = DxSwitchModule;
  493. //# sourceMappingURL=switch.js.map