ngx-bootstrap-timepicker.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. import { Injectable, forwardRef, Component, ChangeDetectionStrategy, ViewEncapsulation, ChangeDetectorRef, Input, Output, EventEmitter, NgModule } from '@angular/core';
  2. import { NG_VALUE_ACCESSOR } from '@angular/forms';
  3. import { __extends } from 'tslib';
  4. import { BehaviorSubject } from 'rxjs';
  5. import { MiniState, MiniStore } from 'ngx-bootstrap/mini-ngrx';
  6. import { CommonModule } from '@angular/common';
  7. /**
  8. * @fileoverview added by tsickle
  9. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  10. */
  11. var TimepickerActions = /** @class */ (function () {
  12. function TimepickerActions() {
  13. }
  14. /**
  15. * @param {?} value
  16. * @return {?}
  17. */
  18. TimepickerActions.prototype.writeValue = /**
  19. * @param {?} value
  20. * @return {?}
  21. */
  22. function (value) {
  23. return {
  24. type: TimepickerActions.WRITE_VALUE,
  25. payload: value
  26. };
  27. };
  28. /**
  29. * @param {?} event
  30. * @return {?}
  31. */
  32. TimepickerActions.prototype.changeHours = /**
  33. * @param {?} event
  34. * @return {?}
  35. */
  36. function (event) {
  37. return {
  38. type: TimepickerActions.CHANGE_HOURS,
  39. payload: event
  40. };
  41. };
  42. /**
  43. * @param {?} event
  44. * @return {?}
  45. */
  46. TimepickerActions.prototype.changeMinutes = /**
  47. * @param {?} event
  48. * @return {?}
  49. */
  50. function (event) {
  51. return {
  52. type: TimepickerActions.CHANGE_MINUTES,
  53. payload: event
  54. };
  55. };
  56. /**
  57. * @param {?} event
  58. * @return {?}
  59. */
  60. TimepickerActions.prototype.changeSeconds = /**
  61. * @param {?} event
  62. * @return {?}
  63. */
  64. function (event) {
  65. return {
  66. type: TimepickerActions.CHANGE_SECONDS,
  67. payload: event
  68. };
  69. };
  70. /**
  71. * @param {?} value
  72. * @return {?}
  73. */
  74. TimepickerActions.prototype.setTime = /**
  75. * @param {?} value
  76. * @return {?}
  77. */
  78. function (value) {
  79. return {
  80. type: TimepickerActions.SET_TIME_UNIT,
  81. payload: value
  82. };
  83. };
  84. /**
  85. * @param {?} value
  86. * @return {?}
  87. */
  88. TimepickerActions.prototype.updateControls = /**
  89. * @param {?} value
  90. * @return {?}
  91. */
  92. function (value) {
  93. return {
  94. type: TimepickerActions.UPDATE_CONTROLS,
  95. payload: value
  96. };
  97. };
  98. TimepickerActions.WRITE_VALUE = '[timepicker] write value from ng model';
  99. TimepickerActions.CHANGE_HOURS = '[timepicker] change hours';
  100. TimepickerActions.CHANGE_MINUTES = '[timepicker] change minutes';
  101. TimepickerActions.CHANGE_SECONDS = '[timepicker] change seconds';
  102. TimepickerActions.SET_TIME_UNIT = '[timepicker] set time unit';
  103. TimepickerActions.UPDATE_CONTROLS = '[timepicker] update controls';
  104. TimepickerActions.decorators = [
  105. { type: Injectable }
  106. ];
  107. return TimepickerActions;
  108. }());
  109. /**
  110. * @fileoverview added by tsickle
  111. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  112. */
  113. /** @type {?} */
  114. var dex = 10;
  115. /** @type {?} */
  116. var hoursPerDay = 24;
  117. /** @type {?} */
  118. var hoursPerDayHalf = 12;
  119. /** @type {?} */
  120. var minutesPerHour = 60;
  121. /** @type {?} */
  122. var secondsPerMinute = 60;
  123. /**
  124. * @param {?=} value
  125. * @return {?}
  126. */
  127. function isValidDate(value) {
  128. if (!value) {
  129. return false;
  130. }
  131. if (value instanceof Date && isNaN(value.getHours())) {
  132. return false;
  133. }
  134. if (typeof value === 'string') {
  135. return isValidDate(new Date(value));
  136. }
  137. return true;
  138. }
  139. /**
  140. * @param {?} controls
  141. * @param {?} newDate
  142. * @return {?}
  143. */
  144. function isValidLimit(controls, newDate) {
  145. if (controls.min && newDate < controls.min) {
  146. return false;
  147. }
  148. if (controls.max && newDate > controls.max) {
  149. return false;
  150. }
  151. return true;
  152. }
  153. /**
  154. * @param {?} value
  155. * @return {?}
  156. */
  157. function toNumber(value) {
  158. if (typeof value === 'number') {
  159. return value;
  160. }
  161. return parseInt(value, dex);
  162. }
  163. /**
  164. * @param {?} value
  165. * @param {?=} isPM
  166. * @return {?}
  167. */
  168. function parseHours(value, isPM) {
  169. if (isPM === void 0) { isPM = false; }
  170. /** @type {?} */
  171. var hour = toNumber(value);
  172. if (isNaN(hour) ||
  173. hour < 0 ||
  174. hour > (isPM ? hoursPerDayHalf : hoursPerDay)) {
  175. return NaN;
  176. }
  177. return hour;
  178. }
  179. /**
  180. * @param {?} value
  181. * @return {?}
  182. */
  183. function parseMinutes(value) {
  184. /** @type {?} */
  185. var minute = toNumber(value);
  186. if (isNaN(minute) || minute < 0 || minute > minutesPerHour) {
  187. return NaN;
  188. }
  189. return minute;
  190. }
  191. /**
  192. * @param {?} value
  193. * @return {?}
  194. */
  195. function parseSeconds(value) {
  196. /** @type {?} */
  197. var seconds = toNumber(value);
  198. if (isNaN(seconds) || seconds < 0 || seconds > secondsPerMinute) {
  199. return NaN;
  200. }
  201. return seconds;
  202. }
  203. /**
  204. * @param {?} value
  205. * @return {?}
  206. */
  207. function parseTime(value) {
  208. if (typeof value === 'string') {
  209. return new Date(value);
  210. }
  211. return value;
  212. }
  213. /**
  214. * @param {?} value
  215. * @param {?} diff
  216. * @return {?}
  217. */
  218. function changeTime(value, diff) {
  219. if (!value) {
  220. return changeTime(createDate(new Date(), 0, 0, 0), diff);
  221. }
  222. /** @type {?} */
  223. var hour = value.getHours();
  224. /** @type {?} */
  225. var minutes = value.getMinutes();
  226. /** @type {?} */
  227. var seconds = value.getSeconds();
  228. if (diff.hour) {
  229. hour = (hour + toNumber(diff.hour)) % hoursPerDay;
  230. if (hour < 0) {
  231. hour += hoursPerDay;
  232. }
  233. }
  234. if (diff.minute) {
  235. minutes = minutes + toNumber(diff.minute);
  236. }
  237. if (diff.seconds) {
  238. seconds = seconds + toNumber(diff.seconds);
  239. }
  240. return createDate(value, hour, minutes, seconds);
  241. }
  242. /**
  243. * @param {?} value
  244. * @param {?} opts
  245. * @return {?}
  246. */
  247. function setTime(value, opts) {
  248. /** @type {?} */
  249. var hour = parseHours(opts.hour);
  250. /** @type {?} */
  251. var minute = parseMinutes(opts.minute);
  252. /** @type {?} */
  253. var seconds = parseSeconds(opts.seconds) || 0;
  254. if (opts.isPM && hour !== 12) {
  255. hour += hoursPerDayHalf;
  256. }
  257. if (!value) {
  258. if (!isNaN(hour) && !isNaN(minute)) {
  259. return createDate(new Date(), hour, minute, seconds);
  260. }
  261. return value;
  262. }
  263. if (isNaN(hour) || isNaN(minute)) {
  264. return value;
  265. }
  266. return createDate(value, hour, minute, seconds);
  267. }
  268. /**
  269. * @param {?} value
  270. * @param {?} hours
  271. * @param {?} minutes
  272. * @param {?} seconds
  273. * @return {?}
  274. */
  275. function createDate(value, hours, minutes, seconds) {
  276. return new Date(value.getFullYear(), value.getMonth(), value.getDate(), hours, minutes, seconds, value.getMilliseconds());
  277. }
  278. /**
  279. * @param {?} value
  280. * @return {?}
  281. */
  282. function padNumber(value) {
  283. /** @type {?} */
  284. var _value = value.toString();
  285. if (_value.length > 1) {
  286. return _value;
  287. }
  288. return "0" + _value;
  289. }
  290. /**
  291. * @param {?} hours
  292. * @param {?} isPM
  293. * @return {?}
  294. */
  295. function isHourInputValid(hours, isPM) {
  296. return !isNaN(parseHours(hours, isPM));
  297. }
  298. /**
  299. * @param {?} minutes
  300. * @return {?}
  301. */
  302. function isMinuteInputValid(minutes) {
  303. return !isNaN(parseMinutes(minutes));
  304. }
  305. /**
  306. * @param {?} seconds
  307. * @return {?}
  308. */
  309. function isSecondInputValid(seconds) {
  310. return !isNaN(parseSeconds(seconds));
  311. }
  312. /**
  313. * @param {?} diff
  314. * @param {?} max
  315. * @param {?} min
  316. * @return {?}
  317. */
  318. function isInputLimitValid(diff, max, min) {
  319. /** @type {?} */
  320. var newDate = setTime(new Date(), diff);
  321. if (max && newDate > max) {
  322. return false;
  323. }
  324. if (min && newDate < min) {
  325. return false;
  326. }
  327. return true;
  328. }
  329. /**
  330. * @param {?} hours
  331. * @param {?=} minutes
  332. * @param {?=} seconds
  333. * @param {?=} isPM
  334. * @return {?}
  335. */
  336. function isInputValid(hours, minutes, seconds, isPM) {
  337. if (minutes === void 0) { minutes = '0'; }
  338. if (seconds === void 0) { seconds = '0'; }
  339. return isHourInputValid(hours, isPM)
  340. && isMinuteInputValid(minutes)
  341. && isSecondInputValid(seconds);
  342. }
  343. /**
  344. * @fileoverview added by tsickle
  345. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  346. */
  347. /**
  348. * @param {?} state
  349. * @param {?=} event
  350. * @return {?}
  351. */
  352. function canChangeValue(state, event) {
  353. if (state.readonlyInput || state.disabled) {
  354. return false;
  355. }
  356. if (event) {
  357. if (event.source === 'wheel' && !state.mousewheel) {
  358. return false;
  359. }
  360. if (event.source === 'key' && !state.arrowkeys) {
  361. return false;
  362. }
  363. }
  364. return true;
  365. }
  366. /**
  367. * @param {?} event
  368. * @param {?} controls
  369. * @return {?}
  370. */
  371. function canChangeHours(event, controls) {
  372. if (!event.step) {
  373. return false;
  374. }
  375. if (event.step > 0 && !controls.canIncrementHours) {
  376. return false;
  377. }
  378. if (event.step < 0 && !controls.canDecrementHours) {
  379. return false;
  380. }
  381. return true;
  382. }
  383. /**
  384. * @param {?} event
  385. * @param {?} controls
  386. * @return {?}
  387. */
  388. function canChangeMinutes(event, controls) {
  389. if (!event.step) {
  390. return false;
  391. }
  392. if (event.step > 0 && !controls.canIncrementMinutes) {
  393. return false;
  394. }
  395. if (event.step < 0 && !controls.canDecrementMinutes) {
  396. return false;
  397. }
  398. return true;
  399. }
  400. /**
  401. * @param {?} event
  402. * @param {?} controls
  403. * @return {?}
  404. */
  405. function canChangeSeconds(event, controls) {
  406. if (!event.step) {
  407. return false;
  408. }
  409. if (event.step > 0 && !controls.canIncrementSeconds) {
  410. return false;
  411. }
  412. if (event.step < 0 && !controls.canDecrementSeconds) {
  413. return false;
  414. }
  415. return true;
  416. }
  417. /**
  418. * @param {?} state
  419. * @return {?}
  420. */
  421. function getControlsValue(state) {
  422. var hourStep = state.hourStep, minuteStep = state.minuteStep, secondsStep = state.secondsStep, readonlyInput = state.readonlyInput, disabled = state.disabled, mousewheel = state.mousewheel, arrowkeys = state.arrowkeys, showSpinners = state.showSpinners, showMeridian = state.showMeridian, showSeconds = state.showSeconds, meridians = state.meridians, min = state.min, max = state.max;
  423. return {
  424. hourStep: hourStep,
  425. minuteStep: minuteStep,
  426. secondsStep: secondsStep,
  427. readonlyInput: readonlyInput,
  428. disabled: disabled,
  429. mousewheel: mousewheel,
  430. arrowkeys: arrowkeys,
  431. showSpinners: showSpinners,
  432. showMeridian: showMeridian,
  433. showSeconds: showSeconds,
  434. meridians: meridians,
  435. min: min,
  436. max: max
  437. };
  438. }
  439. /**
  440. * @param {?} value
  441. * @param {?} state
  442. * @return {?}
  443. */
  444. function timepickerControls(value, state) {
  445. /** @type {?} */
  446. var hoursPerDayHalf = 12;
  447. var min = state.min, max = state.max, hourStep = state.hourStep, minuteStep = state.minuteStep, secondsStep = state.secondsStep, showSeconds = state.showSeconds;
  448. /** @type {?} */
  449. var res = {
  450. canIncrementHours: true,
  451. canIncrementMinutes: true,
  452. canIncrementSeconds: true,
  453. canDecrementHours: true,
  454. canDecrementMinutes: true,
  455. canDecrementSeconds: true,
  456. canToggleMeridian: true
  457. };
  458. if (!value) {
  459. return res;
  460. }
  461. // compare dates
  462. if (max) {
  463. /** @type {?} */
  464. var _newHour = changeTime(value, { hour: hourStep });
  465. res.canIncrementHours = max > _newHour;
  466. if (!res.canIncrementHours) {
  467. /** @type {?} */
  468. var _newMinutes = changeTime(value, { minute: minuteStep });
  469. res.canIncrementMinutes = showSeconds
  470. ? max > _newMinutes
  471. : max >= _newMinutes;
  472. }
  473. if (!res.canIncrementMinutes) {
  474. /** @type {?} */
  475. var _newSeconds = changeTime(value, { seconds: secondsStep });
  476. res.canIncrementSeconds = max >= _newSeconds;
  477. }
  478. if (value.getHours() < hoursPerDayHalf) {
  479. res.canToggleMeridian = changeTime(value, { hour: hoursPerDayHalf }) < max;
  480. }
  481. }
  482. if (min) {
  483. /** @type {?} */
  484. var _newHour = changeTime(value, { hour: -hourStep });
  485. res.canDecrementHours = min < _newHour;
  486. if (!res.canDecrementHours) {
  487. /** @type {?} */
  488. var _newMinutes = changeTime(value, { minute: -minuteStep });
  489. res.canDecrementMinutes = showSeconds
  490. ? min < _newMinutes
  491. : min <= _newMinutes;
  492. }
  493. if (!res.canDecrementMinutes) {
  494. /** @type {?} */
  495. var _newSeconds = changeTime(value, { seconds: -secondsStep });
  496. res.canDecrementSeconds = min <= _newSeconds;
  497. }
  498. if (value.getHours() >= hoursPerDayHalf) {
  499. res.canToggleMeridian = changeTime(value, { hour: -hoursPerDayHalf }) > min;
  500. }
  501. }
  502. return res;
  503. }
  504. /**
  505. * @fileoverview added by tsickle
  506. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  507. */
  508. /**
  509. * Provides default configuration values for timepicker
  510. */
  511. var TimepickerConfig = /** @class */ (function () {
  512. function TimepickerConfig() {
  513. /**
  514. * hours change step
  515. */
  516. this.hourStep = 1;
  517. /**
  518. * hours change step
  519. */
  520. this.minuteStep = 5;
  521. /**
  522. * seconds changes step
  523. */
  524. this.secondsStep = 10;
  525. /**
  526. * if true works in 12H mode and displays AM/PM. If false works in 24H mode and hides AM/PM
  527. */
  528. this.showMeridian = true;
  529. /**
  530. * meridian labels based on locale
  531. */
  532. this.meridians = ['AM', 'PM'];
  533. /**
  534. * if true hours and minutes fields will be readonly
  535. */
  536. this.readonlyInput = false;
  537. /**
  538. * if true hours and minutes fields will be disabled
  539. */
  540. this.disabled = false;
  541. /**
  542. * if true scroll inside hours and minutes inputs will change time
  543. */
  544. this.mousewheel = true;
  545. /**
  546. * if true the values of hours and minutes can be changed using the up/down arrow keys on the keyboard
  547. */
  548. this.arrowkeys = true;
  549. /**
  550. * if true spinner arrows above and below the inputs will be shown
  551. */
  552. this.showSpinners = true;
  553. /**
  554. * show seconds in timepicker
  555. */
  556. this.showSeconds = false;
  557. /**
  558. * show minutes in timepicker
  559. */
  560. this.showMinutes = true;
  561. /**
  562. * placeholder for hours field in timepicker
  563. */
  564. this.hoursPlaceholder = 'HH';
  565. /**
  566. * placeholder for minutes field in timepicker
  567. */
  568. this.minutesPlaceholder = 'MM';
  569. /**
  570. * placeholder for seconds field in timepicker
  571. */
  572. this.secondsPlaceholder = 'SS';
  573. }
  574. TimepickerConfig.decorators = [
  575. { type: Injectable }
  576. ];
  577. return TimepickerConfig;
  578. }());
  579. /**
  580. * @fileoverview added by tsickle
  581. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  582. */
  583. /** @type {?} */
  584. var initialState = {
  585. value: null,
  586. config: new TimepickerConfig(),
  587. controls: {
  588. canIncrementHours: true,
  589. canIncrementMinutes: true,
  590. canIncrementSeconds: true,
  591. canDecrementHours: true,
  592. canDecrementMinutes: true,
  593. canDecrementSeconds: true,
  594. canToggleMeridian: true
  595. }
  596. };
  597. // tslint:disable-next-line:cyclomatic-complexity
  598. /**
  599. * @param {?=} state
  600. * @param {?=} action
  601. * @return {?}
  602. */
  603. function timepickerReducer(state, action) {
  604. if (state === void 0) { state = initialState; }
  605. switch (action.type) {
  606. case TimepickerActions.WRITE_VALUE: {
  607. return Object.assign({}, state, { value: action.payload });
  608. }
  609. case TimepickerActions.CHANGE_HOURS: {
  610. if (!canChangeValue(state.config, action.payload) ||
  611. !canChangeHours(action.payload, state.controls)) {
  612. return state;
  613. }
  614. /** @type {?} */
  615. var _newTime = changeTime(state.value, { hour: action.payload.step });
  616. if ((state.config.max || state.config.min) && !isValidLimit(state.config, _newTime)) {
  617. return state;
  618. }
  619. return Object.assign({}, state, { value: _newTime });
  620. }
  621. case TimepickerActions.CHANGE_MINUTES: {
  622. if (!canChangeValue(state.config, action.payload) ||
  623. !canChangeMinutes(action.payload, state.controls)) {
  624. return state;
  625. }
  626. /** @type {?} */
  627. var _newTime = changeTime(state.value, { minute: action.payload.step });
  628. if ((state.config.max || state.config.min) && !isValidLimit(state.config, _newTime)) {
  629. return state;
  630. }
  631. return Object.assign({}, state, { value: _newTime });
  632. }
  633. case TimepickerActions.CHANGE_SECONDS: {
  634. if (!canChangeValue(state.config, action.payload) ||
  635. !canChangeSeconds(action.payload, state.controls)) {
  636. return state;
  637. }
  638. /** @type {?} */
  639. var _newTime = changeTime(state.value, {
  640. seconds: action.payload.step
  641. });
  642. if ((state.config.max || state.config.min) && !isValidLimit(state.config, _newTime)) {
  643. return state;
  644. }
  645. return Object.assign({}, state, { value: _newTime });
  646. }
  647. case TimepickerActions.SET_TIME_UNIT: {
  648. if (!canChangeValue(state.config)) {
  649. return state;
  650. }
  651. /** @type {?} */
  652. var _newTime = setTime(state.value, action.payload);
  653. return Object.assign({}, state, { value: _newTime });
  654. }
  655. case TimepickerActions.UPDATE_CONTROLS: {
  656. /** @type {?} */
  657. var _newControlsState = timepickerControls(state.value, action.payload);
  658. /** @type {?} */
  659. var _newState = {
  660. value: state.value,
  661. config: action.payload,
  662. controls: _newControlsState
  663. };
  664. if (state.config.showMeridian !== _newState.config.showMeridian) {
  665. if (state.value) {
  666. _newState.value = new Date(state.value);
  667. }
  668. }
  669. return Object.assign({}, state, _newState);
  670. }
  671. default:
  672. return state;
  673. }
  674. }
  675. /**
  676. * @fileoverview added by tsickle
  677. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  678. */
  679. var TimepickerStore = /** @class */ (function (_super) {
  680. __extends(TimepickerStore, _super);
  681. function TimepickerStore() {
  682. var _this = this;
  683. /** @type {?} */
  684. var _dispatcher = new BehaviorSubject({
  685. type: '[mini-ngrx] dispatcher init'
  686. });
  687. /** @type {?} */
  688. var state = new MiniState(initialState, _dispatcher, timepickerReducer);
  689. _this = _super.call(this, _dispatcher, timepickerReducer, state) || this;
  690. return _this;
  691. }
  692. TimepickerStore.decorators = [
  693. { type: Injectable }
  694. ];
  695. /** @nocollapse */
  696. TimepickerStore.ctorParameters = function () { return []; };
  697. return TimepickerStore;
  698. }(MiniStore));
  699. /**
  700. * @fileoverview added by tsickle
  701. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  702. */
  703. /** @type {?} */
  704. var TIMEPICKER_CONTROL_VALUE_ACCESSOR = {
  705. provide: NG_VALUE_ACCESSOR,
  706. /* tslint:disable-next-line: no-use-before-declare */
  707. useExisting: forwardRef((/**
  708. * @return {?}
  709. */
  710. function () { return TimepickerComponent; })),
  711. multi: true
  712. };
  713. var TimepickerComponent = /** @class */ (function () {
  714. function TimepickerComponent(_config, _cd, _store, _timepickerActions) {
  715. var _this = this;
  716. this._cd = _cd;
  717. this._store = _store;
  718. this._timepickerActions = _timepickerActions;
  719. /**
  720. * emits true if value is a valid date
  721. */
  722. this.isValid = new EventEmitter();
  723. // min\max validation for input fields
  724. this.invalidHours = false;
  725. this.invalidMinutes = false;
  726. this.invalidSeconds = false;
  727. // control value accessor methods
  728. // tslint:disable-next-line:no-any
  729. this.onChange = Function.prototype;
  730. // tslint:disable-next-line:no-any
  731. this.onTouched = Function.prototype;
  732. Object.assign(this, _config);
  733. this.timepickerSub = _store
  734. .select((/**
  735. * @param {?} state
  736. * @return {?}
  737. */
  738. function (state) { return state.value; }))
  739. .subscribe((/**
  740. * @param {?} value
  741. * @return {?}
  742. */
  743. function (value) {
  744. // update UI values if date changed
  745. _this._renderTime(value);
  746. _this.onChange(value);
  747. _this._store.dispatch(_this._timepickerActions.updateControls(getControlsValue(_this)));
  748. }));
  749. _store
  750. .select((/**
  751. * @param {?} state
  752. * @return {?}
  753. */
  754. function (state) { return state.controls; }))
  755. .subscribe((/**
  756. * @param {?} controlsState
  757. * @return {?}
  758. */
  759. function (controlsState) {
  760. _this.isValid.emit(isInputValid(_this.hours, _this.minutes, _this.seconds, _this.isPM()));
  761. Object.assign(_this, controlsState);
  762. _cd.markForCheck();
  763. }));
  764. }
  765. Object.defineProperty(TimepickerComponent.prototype, "isSpinnersVisible", {
  766. /** @deprecated - please use `isEditable` instead */
  767. get: /**
  768. * @deprecated - please use `isEditable` instead
  769. * @return {?}
  770. */
  771. function () {
  772. return this.showSpinners && !this.readonlyInput;
  773. },
  774. enumerable: true,
  775. configurable: true
  776. });
  777. Object.defineProperty(TimepickerComponent.prototype, "isEditable", {
  778. get: /**
  779. * @return {?}
  780. */
  781. function () {
  782. return !(this.readonlyInput || this.disabled);
  783. },
  784. enumerable: true,
  785. configurable: true
  786. });
  787. /**
  788. * @return {?}
  789. */
  790. TimepickerComponent.prototype.resetValidation = /**
  791. * @return {?}
  792. */
  793. function () {
  794. this.invalidHours = false;
  795. this.invalidMinutes = false;
  796. this.invalidSeconds = false;
  797. };
  798. /**
  799. * @return {?}
  800. */
  801. TimepickerComponent.prototype.isPM = /**
  802. * @return {?}
  803. */
  804. function () {
  805. return this.showMeridian && this.meridian === this.meridians[1];
  806. };
  807. /**
  808. * @param {?} $event
  809. * @return {?}
  810. */
  811. TimepickerComponent.prototype.prevDef = /**
  812. * @param {?} $event
  813. * @return {?}
  814. */
  815. function ($event) {
  816. $event.preventDefault();
  817. };
  818. /**
  819. * @param {?} $event
  820. * @return {?}
  821. */
  822. TimepickerComponent.prototype.wheelSign = /**
  823. * @param {?} $event
  824. * @return {?}
  825. */
  826. function ($event) {
  827. return Math.sign($event.deltaY) * -1;
  828. };
  829. /**
  830. * @param {?} changes
  831. * @return {?}
  832. */
  833. TimepickerComponent.prototype.ngOnChanges = /**
  834. * @param {?} changes
  835. * @return {?}
  836. */
  837. function (changes) {
  838. this._store.dispatch(this._timepickerActions.updateControls(getControlsValue(this)));
  839. };
  840. /**
  841. * @param {?} step
  842. * @param {?=} source
  843. * @return {?}
  844. */
  845. TimepickerComponent.prototype.changeHours = /**
  846. * @param {?} step
  847. * @param {?=} source
  848. * @return {?}
  849. */
  850. function (step, source) {
  851. if (source === void 0) { source = ''; }
  852. this.resetValidation();
  853. this._store.dispatch(this._timepickerActions.changeHours({ step: step, source: source }));
  854. };
  855. /**
  856. * @param {?} step
  857. * @param {?=} source
  858. * @return {?}
  859. */
  860. TimepickerComponent.prototype.changeMinutes = /**
  861. * @param {?} step
  862. * @param {?=} source
  863. * @return {?}
  864. */
  865. function (step, source) {
  866. if (source === void 0) { source = ''; }
  867. this.resetValidation();
  868. this._store.dispatch(this._timepickerActions.changeMinutes({ step: step, source: source }));
  869. };
  870. /**
  871. * @param {?} step
  872. * @param {?=} source
  873. * @return {?}
  874. */
  875. TimepickerComponent.prototype.changeSeconds = /**
  876. * @param {?} step
  877. * @param {?=} source
  878. * @return {?}
  879. */
  880. function (step, source) {
  881. if (source === void 0) { source = ''; }
  882. this.resetValidation();
  883. this._store.dispatch(this._timepickerActions.changeSeconds({ step: step, source: source }));
  884. };
  885. /**
  886. * @param {?} hours
  887. * @return {?}
  888. */
  889. TimepickerComponent.prototype.updateHours = /**
  890. * @param {?} hours
  891. * @return {?}
  892. */
  893. function (hours) {
  894. this.resetValidation();
  895. this.hours = hours;
  896. /** @type {?} */
  897. var isValid = isHourInputValid(this.hours, this.isPM()) && this.isValidLimit();
  898. if (!isValid) {
  899. this.invalidHours = true;
  900. this.isValid.emit(false);
  901. this.onChange(null);
  902. return;
  903. }
  904. this._updateTime();
  905. };
  906. /**
  907. * @param {?} minutes
  908. * @return {?}
  909. */
  910. TimepickerComponent.prototype.updateMinutes = /**
  911. * @param {?} minutes
  912. * @return {?}
  913. */
  914. function (minutes) {
  915. this.resetValidation();
  916. this.minutes = minutes;
  917. /** @type {?} */
  918. var isValid = isMinuteInputValid(this.minutes) && this.isValidLimit();
  919. if (!isValid) {
  920. this.invalidMinutes = true;
  921. this.isValid.emit(false);
  922. this.onChange(null);
  923. return;
  924. }
  925. this._updateTime();
  926. };
  927. /**
  928. * @param {?} seconds
  929. * @return {?}
  930. */
  931. TimepickerComponent.prototype.updateSeconds = /**
  932. * @param {?} seconds
  933. * @return {?}
  934. */
  935. function (seconds) {
  936. this.resetValidation();
  937. this.seconds = seconds;
  938. /** @type {?} */
  939. var isValid = isSecondInputValid(this.seconds) && this.isValidLimit();
  940. if (!isValid) {
  941. this.invalidSeconds = true;
  942. this.isValid.emit(false);
  943. this.onChange(null);
  944. return;
  945. }
  946. this._updateTime();
  947. };
  948. /**
  949. * @return {?}
  950. */
  951. TimepickerComponent.prototype.isValidLimit = /**
  952. * @return {?}
  953. */
  954. function () {
  955. return isInputLimitValid({
  956. hour: this.hours,
  957. minute: this.minutes,
  958. seconds: this.seconds,
  959. isPM: this.isPM()
  960. }, this.max, this.min);
  961. };
  962. /**
  963. * @return {?}
  964. */
  965. TimepickerComponent.prototype._updateTime = /**
  966. * @return {?}
  967. */
  968. function () {
  969. /** @type {?} */
  970. var _seconds = this.showSeconds ? this.seconds : void 0;
  971. /** @type {?} */
  972. var _minutes = this.showMinutes ? this.minutes : void 0;
  973. if (!isInputValid(this.hours, _minutes, _seconds, this.isPM())) {
  974. this.isValid.emit(false);
  975. this.onChange(null);
  976. return;
  977. }
  978. this._store.dispatch(this._timepickerActions.setTime({
  979. hour: this.hours,
  980. minute: this.minutes,
  981. seconds: this.seconds,
  982. isPM: this.isPM()
  983. }));
  984. };
  985. /**
  986. * @return {?}
  987. */
  988. TimepickerComponent.prototype.toggleMeridian = /**
  989. * @return {?}
  990. */
  991. function () {
  992. if (!this.showMeridian || !this.isEditable) {
  993. return;
  994. }
  995. /** @type {?} */
  996. var _hoursPerDayHalf = 12;
  997. this._store.dispatch(this._timepickerActions.changeHours({
  998. step: _hoursPerDayHalf,
  999. source: ''
  1000. }));
  1001. };
  1002. /**
  1003. * Write a new value to the element.
  1004. */
  1005. /**
  1006. * Write a new value to the element.
  1007. * @param {?} obj
  1008. * @return {?}
  1009. */
  1010. TimepickerComponent.prototype.writeValue = /**
  1011. * Write a new value to the element.
  1012. * @param {?} obj
  1013. * @return {?}
  1014. */
  1015. function (obj) {
  1016. if (isValidDate(obj)) {
  1017. this._store.dispatch(this._timepickerActions.writeValue(parseTime(obj)));
  1018. }
  1019. else if (obj == null) {
  1020. this._store.dispatch(this._timepickerActions.writeValue(null));
  1021. }
  1022. };
  1023. /**
  1024. * Set the function to be called when the control receives a change event.
  1025. */
  1026. // tslint:disable-next-line:no-any
  1027. /**
  1028. * Set the function to be called when the control receives a change event.
  1029. * @param {?} fn
  1030. * @return {?}
  1031. */
  1032. // tslint:disable-next-line:no-any
  1033. TimepickerComponent.prototype.registerOnChange = /**
  1034. * Set the function to be called when the control receives a change event.
  1035. * @param {?} fn
  1036. * @return {?}
  1037. */
  1038. // tslint:disable-next-line:no-any
  1039. function (fn) {
  1040. this.onChange = fn;
  1041. };
  1042. /**
  1043. * Set the function to be called when the control receives a touch event.
  1044. */
  1045. /**
  1046. * Set the function to be called when the control receives a touch event.
  1047. * @param {?} fn
  1048. * @return {?}
  1049. */
  1050. TimepickerComponent.prototype.registerOnTouched = /**
  1051. * Set the function to be called when the control receives a touch event.
  1052. * @param {?} fn
  1053. * @return {?}
  1054. */
  1055. function (fn) {
  1056. this.onTouched = fn;
  1057. };
  1058. /**
  1059. * This function is called when the control status changes to or from "disabled".
  1060. * Depending on the value, it will enable or disable the appropriate DOM element.
  1061. *
  1062. * @param isDisabled
  1063. */
  1064. /**
  1065. * This function is called when the control status changes to or from "disabled".
  1066. * Depending on the value, it will enable or disable the appropriate DOM element.
  1067. *
  1068. * @param {?} isDisabled
  1069. * @return {?}
  1070. */
  1071. TimepickerComponent.prototype.setDisabledState = /**
  1072. * This function is called when the control status changes to or from "disabled".
  1073. * Depending on the value, it will enable or disable the appropriate DOM element.
  1074. *
  1075. * @param {?} isDisabled
  1076. * @return {?}
  1077. */
  1078. function (isDisabled) {
  1079. this.disabled = isDisabled;
  1080. this._cd.markForCheck();
  1081. };
  1082. /**
  1083. * @return {?}
  1084. */
  1085. TimepickerComponent.prototype.ngOnDestroy = /**
  1086. * @return {?}
  1087. */
  1088. function () {
  1089. this.timepickerSub.unsubscribe();
  1090. };
  1091. /**
  1092. * @private
  1093. * @param {?} value
  1094. * @return {?}
  1095. */
  1096. TimepickerComponent.prototype._renderTime = /**
  1097. * @private
  1098. * @param {?} value
  1099. * @return {?}
  1100. */
  1101. function (value) {
  1102. if (!isValidDate(value)) {
  1103. this.hours = '';
  1104. this.minutes = '';
  1105. this.seconds = '';
  1106. this.meridian = this.meridians[0];
  1107. return;
  1108. }
  1109. /** @type {?} */
  1110. var _value = parseTime(value);
  1111. /** @type {?} */
  1112. var _hoursPerDayHalf = 12;
  1113. /** @type {?} */
  1114. var _hours = _value.getHours();
  1115. if (this.showMeridian) {
  1116. this.meridian = this.meridians[_hours >= _hoursPerDayHalf ? 1 : 0];
  1117. _hours = _hours % _hoursPerDayHalf;
  1118. // should be 12 PM, not 00 PM
  1119. if (_hours === 0) {
  1120. _hours = _hoursPerDayHalf;
  1121. }
  1122. }
  1123. this.hours = padNumber(_hours);
  1124. this.minutes = padNumber(_value.getMinutes());
  1125. this.seconds = padNumber(_value.getUTCSeconds());
  1126. };
  1127. TimepickerComponent.decorators = [
  1128. { type: Component, args: [{
  1129. selector: 'timepicker',
  1130. changeDetection: ChangeDetectionStrategy.OnPush,
  1131. providers: [TIMEPICKER_CONTROL_VALUE_ACCESSOR, TimepickerStore],
  1132. template: "<table>\n <tbody>\n <tr class=\"text-center\" [hidden]=\"!showSpinners\">\n <!-- increment hours button-->\n <td>\n <a class=\"btn btn-link\" [class.disabled]=\"!canIncrementHours || !isEditable\"\n (click)=\"changeHours(hourStep)\"\n ><span class=\"bs-chevron bs-chevron-up\"></span></a>\n </td>\n <!-- divider -->\n <td *ngIf=\"showMinutes\">&nbsp;&nbsp;&nbsp;</td>\n <!-- increment minutes button -->\n <td *ngIf=\"showMinutes\">\n <a class=\"btn btn-link\" [class.disabled]=\"!canIncrementMinutes || !isEditable\"\n (click)=\"changeMinutes(minuteStep)\"\n ><span class=\"bs-chevron bs-chevron-up\"></span></a>\n </td>\n <!-- divider -->\n <td *ngIf=\"showSeconds\">&nbsp;</td>\n <!-- increment seconds button -->\n <td *ngIf=\"showSeconds\">\n <a class=\"btn btn-link\" [class.disabled]=\"!canIncrementSeconds || !isEditable\"\n (click)=\"changeSeconds(secondsStep)\">\n <span class=\"bs-chevron bs-chevron-up\"></span>\n </a>\n </td>\n <!-- space between -->\n <td *ngIf=\"showMeridian\">&nbsp;&nbsp;&nbsp;</td>\n <!-- meridian placeholder-->\n <td *ngIf=\"showMeridian\"></td>\n </tr>\n <tr>\n <!-- hours -->\n <td class=\"form-group\" [class.has-error]=\"invalidHours\">\n <input type=\"text\" [class.is-invalid]=\"invalidHours\"\n class=\"form-control text-center bs-timepicker-field\"\n [placeholder]=\"hoursPlaceholder\"\n maxlength=\"2\"\n [readonly]=\"readonlyInput\"\n [disabled]=\"disabled\"\n [value]=\"hours\"\n (wheel)=\"prevDef($event);changeHours(hourStep * wheelSign($event), 'wheel')\"\n (keydown.ArrowUp)=\"changeHours(hourStep, 'key')\"\n (keydown.ArrowDown)=\"changeHours(-hourStep, 'key')\"\n (change)=\"updateHours($event.target.value)\"></td>\n <!-- divider -->\n <td *ngIf=\"showMinutes\">&nbsp;:&nbsp;</td>\n <!-- minutes -->\n <td class=\"form-group\" *ngIf=\"showMinutes\" [class.has-error]=\"invalidMinutes\">\n <input type=\"text\" [class.is-invalid]=\"invalidMinutes\"\n class=\"form-control text-center bs-timepicker-field\"\n [placeholder]=\"minutesPlaceholder\"\n maxlength=\"2\"\n [readonly]=\"readonlyInput\"\n [disabled]=\"disabled\"\n [value]=\"minutes\"\n (wheel)=\"prevDef($event);changeMinutes(minuteStep * wheelSign($event), 'wheel')\"\n (keydown.ArrowUp)=\"changeMinutes(minuteStep, 'key')\"\n (keydown.ArrowDown)=\"changeMinutes(-minuteStep, 'key')\"\n (change)=\"updateMinutes($event.target.value)\">\n </td>\n <!-- divider -->\n <td *ngIf=\"showSeconds\">&nbsp;:&nbsp;</td>\n <!-- seconds -->\n <td class=\"form-group\" *ngIf=\"showSeconds\" [class.has-error]=\"invalidSeconds\">\n <input type=\"text\" [class.is-invalid]=\"invalidSeconds\"\n class=\"form-control text-center bs-timepicker-field\"\n [placeholder]=\"secondsPlaceholder\"\n maxlength=\"2\"\n [readonly]=\"readonlyInput\"\n [disabled]=\"disabled\"\n [value]=\"seconds\"\n (wheel)=\"prevDef($event);changeSeconds(secondsStep * wheelSign($event), 'wheel')\"\n (keydown.ArrowUp)=\"changeSeconds(secondsStep, 'key')\"\n (keydown.ArrowDown)=\"changeSeconds(-secondsStep, 'key')\"\n (change)=\"updateSeconds($event.target.value)\">\n </td>\n <!-- space between -->\n <td *ngIf=\"showMeridian\">&nbsp;&nbsp;&nbsp;</td>\n <!-- meridian -->\n <td *ngIf=\"showMeridian\">\n <button type=\"button\" class=\"btn btn-default text-center\"\n [disabled]=\"!isEditable || !canToggleMeridian\"\n [class.disabled]=\"!isEditable || !canToggleMeridian\"\n (click)=\"toggleMeridian()\"\n >{{ meridian }}\n </button>\n </td>\n </tr>\n <tr class=\"text-center\" [hidden]=\"!showSpinners\">\n <!-- decrement hours button-->\n <td>\n <a class=\"btn btn-link\" [class.disabled]=\"!canDecrementHours || !isEditable\"\n (click)=\"changeHours(-hourStep)\">\n <span class=\"bs-chevron bs-chevron-down\"></span>\n </a>\n </td>\n <!-- divider -->\n <td *ngIf=\"showMinutes\">&nbsp;&nbsp;&nbsp;</td>\n <!-- decrement minutes button-->\n <td *ngIf=\"showMinutes\">\n <a class=\"btn btn-link\" [class.disabled]=\"!canDecrementMinutes || !isEditable\"\n (click)=\"changeMinutes(-minuteStep)\">\n <span class=\"bs-chevron bs-chevron-down\"></span>\n </a>\n </td>\n <!-- divider -->\n <td *ngIf=\"showSeconds\">&nbsp;</td>\n <!-- decrement seconds button-->\n <td *ngIf=\"showSeconds\">\n <a class=\"btn btn-link\" [class.disabled]=\"!canDecrementSeconds || !isEditable\"\n (click)=\"changeSeconds(-secondsStep)\">\n <span class=\"bs-chevron bs-chevron-down\"></span>\n </a>\n </td>\n <!-- space between -->\n <td *ngIf=\"showMeridian\">&nbsp;&nbsp;&nbsp;</td>\n <!-- meridian placeholder-->\n <td *ngIf=\"showMeridian\"></td>\n </tr>\n </tbody>\n</table>\n",
  1133. encapsulation: ViewEncapsulation.None,
  1134. styles: ["\n .bs-chevron {\n border-style: solid;\n display: block;\n width: 9px;\n height: 9px;\n position: relative;\n border-width: 3px 0px 0 3px;\n }\n\n .bs-chevron-up {\n -webkit-transform: rotate(45deg);\n transform: rotate(45deg);\n top: 2px;\n }\n\n .bs-chevron-down {\n -webkit-transform: rotate(-135deg);\n transform: rotate(-135deg);\n top: -2px;\n }\n\n .bs-timepicker-field {\n width: 50px;\n padding: .375rem .55rem;\n }\n "]
  1135. }] }
  1136. ];
  1137. /** @nocollapse */
  1138. TimepickerComponent.ctorParameters = function () { return [
  1139. { type: TimepickerConfig },
  1140. { type: ChangeDetectorRef },
  1141. { type: TimepickerStore },
  1142. { type: TimepickerActions }
  1143. ]; };
  1144. TimepickerComponent.propDecorators = {
  1145. hourStep: [{ type: Input }],
  1146. minuteStep: [{ type: Input }],
  1147. secondsStep: [{ type: Input }],
  1148. readonlyInput: [{ type: Input }],
  1149. disabled: [{ type: Input }],
  1150. mousewheel: [{ type: Input }],
  1151. arrowkeys: [{ type: Input }],
  1152. showSpinners: [{ type: Input }],
  1153. showMeridian: [{ type: Input }],
  1154. showMinutes: [{ type: Input }],
  1155. showSeconds: [{ type: Input }],
  1156. meridians: [{ type: Input }],
  1157. min: [{ type: Input }],
  1158. max: [{ type: Input }],
  1159. hoursPlaceholder: [{ type: Input }],
  1160. minutesPlaceholder: [{ type: Input }],
  1161. secondsPlaceholder: [{ type: Input }],
  1162. isValid: [{ type: Output }]
  1163. };
  1164. return TimepickerComponent;
  1165. }());
  1166. /**
  1167. * @fileoverview added by tsickle
  1168. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1169. */
  1170. var TimepickerModule = /** @class */ (function () {
  1171. function TimepickerModule() {
  1172. }
  1173. /**
  1174. * @return {?}
  1175. */
  1176. TimepickerModule.forRoot = /**
  1177. * @return {?}
  1178. */
  1179. function () {
  1180. return {
  1181. ngModule: TimepickerModule,
  1182. providers: [TimepickerConfig, TimepickerActions, TimepickerStore]
  1183. };
  1184. };
  1185. TimepickerModule.decorators = [
  1186. { type: NgModule, args: [{
  1187. imports: [CommonModule],
  1188. declarations: [TimepickerComponent],
  1189. exports: [TimepickerComponent]
  1190. },] }
  1191. ];
  1192. return TimepickerModule;
  1193. }());
  1194. export { TimepickerActions, TimepickerComponent, TimepickerConfig, TimepickerModule, TimepickerStore, TIMEPICKER_CONTROL_VALUE_ACCESSOR as ɵa };
  1195. //# sourceMappingURL=ngx-bootstrap-timepicker.js.map