@dereekb/dbx-core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/README.md +7 -0
  2. package/dereekb-dbx-core.d.ts +5 -0
  3. package/esm2020/dereekb-dbx-core.mjs +5 -0
  4. package/esm2020/index.mjs +2 -0
  5. package/esm2020/lib/action/action.handler.mjs +140 -0
  6. package/esm2020/lib/action/action.holder.mjs +50 -0
  7. package/esm2020/lib/action/action.machine.mjs +37 -0
  8. package/esm2020/lib/action/action.mjs +51 -0
  9. package/esm2020/lib/action/action.module.mjs +38 -0
  10. package/esm2020/lib/action/action.store.mjs +188 -0
  11. package/esm2020/lib/action/action.store.source.mjs +149 -0
  12. package/esm2020/lib/action/directive/auto/action.automodify.directive.mjs +53 -0
  13. package/esm2020/lib/action/directive/auto/action.autotrigger.directive.mjs +131 -0
  14. package/esm2020/lib/action/directive/auto/action.autotrigger.value.directive.mjs +79 -0
  15. package/esm2020/lib/action/directive/auto/index.mjs +4 -0
  16. package/esm2020/lib/action/directive/context/action.component.mjs +18 -0
  17. package/esm2020/lib/action/directive/context/action.directive.mjs +33 -0
  18. package/esm2020/lib/action/directive/context/action.source.directive.mjs +40 -0
  19. package/esm2020/lib/action/directive/context/index.mjs +4 -0
  20. package/esm2020/lib/action/directive/debug/action.logger.directive.mjs +30 -0
  21. package/esm2020/lib/action/directive/debug/index.mjs +2 -0
  22. package/esm2020/lib/action/directive/index.mjs +6 -0
  23. package/esm2020/lib/action/directive/map/action.map.directive.mjs +74 -0
  24. package/esm2020/lib/action/directive/map/action.map.key.directive.mjs +40 -0
  25. package/esm2020/lib/action/directive/map/action.map.mjs +6 -0
  26. package/esm2020/lib/action/directive/map/action.map.source.directive.mjs +49 -0
  27. package/esm2020/lib/action/directive/map/action.map.working.disable.directive.mjs +41 -0
  28. package/esm2020/lib/action/directive/map/index.mjs +6 -0
  29. package/esm2020/lib/action/directive/state/action.disabled.directive.mjs +49 -0
  30. package/esm2020/lib/action/directive/state/action.disabled.modified.directive.mjs +35 -0
  31. package/esm2020/lib/action/directive/state/action.handler.directive.mjs +55 -0
  32. package/esm2020/lib/action/directive/state/action.success.component.mjs +50 -0
  33. package/esm2020/lib/action/directive/state/action.success.directive.mjs +48 -0
  34. package/esm2020/lib/action/directive/state/action.value.directive.mjs +52 -0
  35. package/esm2020/lib/action/directive/state/action.working.component.mjs +32 -0
  36. package/esm2020/lib/action/directive/state/index.mjs +8 -0
  37. package/esm2020/lib/action/index.mjs +10 -0
  38. package/esm2020/lib/action/snackbar/index.mjs +3 -0
  39. package/esm2020/lib/action/snackbar/snackbar.mjs +24 -0
  40. package/esm2020/lib/button/action/action.button.directive.mjs +46 -0
  41. package/esm2020/lib/button/action/action.button.trigger.directive.mjs +36 -0
  42. package/esm2020/lib/button/action/index.mjs +3 -0
  43. package/esm2020/lib/button/button.directive.mjs +109 -0
  44. package/esm2020/lib/button/button.loading.directive.mjs +43 -0
  45. package/esm2020/lib/button/button.mjs +9 -0
  46. package/esm2020/lib/button/button.module.mjs +40 -0
  47. package/esm2020/lib/button/index.mjs +7 -0
  48. package/esm2020/lib/button/router/button.segue.directive.mjs +43 -0
  49. package/esm2020/lib/button/router/index.mjs +2 -0
  50. package/esm2020/lib/index.mjs +9 -0
  51. package/esm2020/lib/injected/index.mjs +6 -0
  52. package/esm2020/lib/injected/injected.component.mjs +34 -0
  53. package/esm2020/lib/injected/injected.component.module.mjs +26 -0
  54. package/esm2020/lib/injected/injected.directive.mjs +32 -0
  55. package/esm2020/lib/injected/injected.instance.mjs +101 -0
  56. package/esm2020/lib/injected/injected.mjs +2 -0
  57. package/esm2020/lib/pipe/date/date.pipe.module.mjs +54 -0
  58. package/esm2020/lib/pipe/date/datedistance.pipe.mjs +42 -0
  59. package/esm2020/lib/pipe/date/dateformatdistance.pipe.mjs +37 -0
  60. package/esm2020/lib/pipe/date/datefromtoformat.pipe.mjs +35 -0
  61. package/esm2020/lib/pipe/date/index.mjs +9 -0
  62. package/esm2020/lib/pipe/date/minutesstring.pipe.mjs +32 -0
  63. package/esm2020/lib/pipe/date/timedistance.pipe.mjs +49 -0
  64. package/esm2020/lib/pipe/date/tojsdate.pipe.mjs +18 -0
  65. package/esm2020/lib/pipe/date/tominutes.pipe.mjs +17 -0
  66. package/esm2020/lib/pipe/index.mjs +2 -0
  67. package/esm2020/lib/router/anchor/anchor.directive.mjs +40 -0
  68. package/esm2020/lib/router/anchor/anchor.mjs +35 -0
  69. package/esm2020/lib/router/anchor/clickable.mjs +2 -0
  70. package/esm2020/lib/router/anchor/index.mjs +4 -0
  71. package/esm2020/lib/router/index.mjs +4 -0
  72. package/esm2020/lib/router/router/index.mjs +4 -0
  73. package/esm2020/lib/router/router/provider/angular/angular.router.service.mjs +51 -0
  74. package/esm2020/lib/router/router/provider/angular/angular.router.service.module.mjs +30 -0
  75. package/esm2020/lib/router/router/provider/angular/index.mjs +3 -0
  76. package/esm2020/lib/router/router/provider/index.mjs +3 -0
  77. package/esm2020/lib/router/router/provider/uirouter/index.mjs +3 -0
  78. package/esm2020/lib/router/router/provider/uirouter/uirouter.router.service.mjs +39 -0
  79. package/esm2020/lib/router/router/provider/uirouter/uirouter.router.service.module.mjs +31 -0
  80. package/esm2020/lib/router/router/service/index.mjs +3 -0
  81. package/esm2020/lib/router/router/service/router.service.mjs +6 -0
  82. package/esm2020/lib/router/router/service/router.transition.service.mjs +6 -0
  83. package/esm2020/lib/router/router/transition/index.mjs +3 -0
  84. package/esm2020/lib/router/router/transition/transition.mjs +12 -0
  85. package/esm2020/lib/router/router/transition/transition.watcher.directive.mjs +35 -0
  86. package/esm2020/lib/router/segue.mjs +8 -0
  87. package/esm2020/lib/storage/index.mjs +9 -0
  88. package/esm2020/lib/storage/storage.accessor.mjs +16 -0
  89. package/esm2020/lib/storage/storage.accessor.simple.factory.mjs +33 -0
  90. package/esm2020/lib/storage/storage.accessor.simple.mjs +161 -0
  91. package/esm2020/lib/storage/storage.accessor.string.mjs +50 -0
  92. package/esm2020/lib/storage/storage.di.mjs +4 -0
  93. package/esm2020/lib/storage/storage.module.mjs +37 -0
  94. package/esm2020/lib/storage/storage.object.localstorage.mjs +46 -0
  95. package/esm2020/lib/storage/storage.object.memory.mjs +17 -0
  96. package/esm2020/lib/subscription/index.mjs +2 -0
  97. package/esm2020/lib/subscription/subscription.directive.mjs +46 -0
  98. package/esm2020/lib/util/index.mjs +2 -0
  99. package/esm2020/lib/util/view.mjs +34 -0
  100. package/fesm2015/dereekb-dbx-core.mjs +2875 -0
  101. package/fesm2015/dereekb-dbx-core.mjs.map +1 -0
  102. package/fesm2020/dereekb-dbx-core.mjs +2856 -0
  103. package/fesm2020/dereekb-dbx-core.mjs.map +1 -0
  104. package/index.d.ts +1 -0
  105. package/lib/action/action.d.ts +43 -0
  106. package/lib/action/action.handler.d.ts +73 -0
  107. package/lib/action/action.holder.d.ts +28 -0
  108. package/lib/action/action.machine.d.ts +23 -0
  109. package/lib/action/action.module.d.ts +25 -0
  110. package/lib/action/action.store.d.ts +147 -0
  111. package/lib/action/action.store.source.d.ts +72 -0
  112. package/lib/action/directive/auto/action.automodify.directive.d.ts +15 -0
  113. package/lib/action/directive/auto/action.autotrigger.directive.d.ts +54 -0
  114. package/lib/action/directive/auto/action.autotrigger.value.directive.d.ts +25 -0
  115. package/lib/action/directive/auto/index.d.ts +3 -0
  116. package/lib/action/directive/context/action.component.d.ts +6 -0
  117. package/lib/action/directive/context/action.directive.d.ts +13 -0
  118. package/lib/action/directive/context/action.source.directive.d.ts +16 -0
  119. package/lib/action/directive/context/index.d.ts +3 -0
  120. package/lib/action/directive/debug/action.logger.directive.d.ts +14 -0
  121. package/lib/action/directive/debug/index.d.ts +1 -0
  122. package/lib/action/directive/index.d.ts +5 -0
  123. package/lib/action/directive/map/action.map.d.ts +13 -0
  124. package/lib/action/directive/map/action.map.directive.d.ts +35 -0
  125. package/lib/action/directive/map/action.map.key.directive.d.ts +20 -0
  126. package/lib/action/directive/map/action.map.source.directive.d.ts +20 -0
  127. package/lib/action/directive/map/action.map.working.disable.directive.d.ts +21 -0
  128. package/lib/action/directive/map/index.d.ts +5 -0
  129. package/lib/action/directive/state/action.disabled.directive.d.ts +20 -0
  130. package/lib/action/directive/state/action.disabled.modified.directive.d.ts +16 -0
  131. package/lib/action/directive/state/action.handler.directive.d.ts +22 -0
  132. package/lib/action/directive/state/action.success.component.d.ts +15 -0
  133. package/lib/action/directive/state/action.success.directive.d.ts +24 -0
  134. package/lib/action/directive/state/action.value.directive.d.ts +22 -0
  135. package/lib/action/directive/state/action.working.component.d.ts +12 -0
  136. package/lib/action/directive/state/index.d.ts +7 -0
  137. package/lib/action/index.d.ts +9 -0
  138. package/lib/action/snackbar/index.d.ts +1 -0
  139. package/lib/action/snackbar/snackbar.d.ts +50 -0
  140. package/lib/button/action/action.button.directive.d.ts +18 -0
  141. package/lib/button/action/action.button.trigger.directive.d.ts +17 -0
  142. package/lib/button/action/index.d.ts +2 -0
  143. package/lib/button/button.d.ts +26 -0
  144. package/lib/button/button.directive.d.ts +52 -0
  145. package/lib/button/button.loading.directive.d.ts +21 -0
  146. package/lib/button/button.module.d.ts +11 -0
  147. package/lib/button/index.d.ts +6 -0
  148. package/lib/button/router/button.segue.directive.d.ts +18 -0
  149. package/lib/button/router/index.d.ts +1 -0
  150. package/lib/index.d.ts +8 -0
  151. package/lib/injected/index.d.ts +5 -0
  152. package/lib/injected/injected.component.d.ts +15 -0
  153. package/lib/injected/injected.component.module.d.ts +8 -0
  154. package/lib/injected/injected.d.ts +26 -0
  155. package/lib/injected/injected.directive.d.ts +17 -0
  156. package/lib/injected/injected.instance.d.ts +29 -0
  157. package/lib/pipe/date/date.pipe.module.d.ts +13 -0
  158. package/lib/pipe/date/datedistance.pipe.d.ts +8 -0
  159. package/lib/pipe/date/dateformatdistance.pipe.d.ts +13 -0
  160. package/lib/pipe/date/datefromtoformat.pipe.d.ts +14 -0
  161. package/lib/pipe/date/index.d.ts +8 -0
  162. package/lib/pipe/date/minutesstring.pipe.d.ts +8 -0
  163. package/lib/pipe/date/timedistance.pipe.d.ts +13 -0
  164. package/lib/pipe/date/tojsdate.pipe.d.ts +9 -0
  165. package/lib/pipe/date/tominutes.pipe.d.ts +7 -0
  166. package/lib/pipe/index.d.ts +1 -0
  167. package/lib/router/anchor/anchor.d.ts +31 -0
  168. package/lib/router/anchor/anchor.directive.d.ts +20 -0
  169. package/lib/router/anchor/clickable.d.ts +17 -0
  170. package/lib/router/anchor/index.d.ts +3 -0
  171. package/lib/router/index.d.ts +3 -0
  172. package/lib/router/router/index.d.ts +3 -0
  173. package/lib/router/router/provider/angular/angular.router.service.d.ts +17 -0
  174. package/lib/router/router/provider/angular/angular.router.service.module.d.ts +8 -0
  175. package/lib/router/router/provider/angular/index.d.ts +2 -0
  176. package/lib/router/router/provider/index.d.ts +2 -0
  177. package/lib/router/router/provider/uirouter/index.d.ts +2 -0
  178. package/lib/router/router/provider/uirouter/uirouter.router.service.d.ts +19 -0
  179. package/lib/router/router/provider/uirouter/uirouter.router.service.module.d.ts +8 -0
  180. package/lib/router/router/service/index.d.ts +2 -0
  181. package/lib/router/router/service/router.service.d.ts +12 -0
  182. package/lib/router/router/service/router.transition.service.d.ts +11 -0
  183. package/lib/router/router/transition/index.d.ts +2 -0
  184. package/lib/router/router/transition/transition.d.ts +13 -0
  185. package/lib/router/router/transition/transition.watcher.directive.d.ts +18 -0
  186. package/lib/router/segue.d.ts +28 -0
  187. package/lib/storage/index.d.ts +8 -0
  188. package/lib/storage/storage.accessor.d.ts +35 -0
  189. package/lib/storage/storage.accessor.simple.d.ts +75 -0
  190. package/lib/storage/storage.accessor.simple.factory.d.ts +18 -0
  191. package/lib/storage/storage.accessor.string.d.ts +16 -0
  192. package/lib/storage/storage.di.d.ts +3 -0
  193. package/lib/storage/storage.module.d.ts +10 -0
  194. package/lib/storage/storage.object.localstorage.d.ts +16 -0
  195. package/lib/storage/storage.object.memory.d.ts +9 -0
  196. package/lib/subscription/index.d.ts +1 -0
  197. package/lib/subscription/subscription.directive.d.ts +25 -0
  198. package/lib/util/index.d.ts +1 -0
  199. package/lib/util/view.d.ts +22 -0
  200. package/package.json +52 -0
@@ -0,0 +1,2875 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Directive, forwardRef, Host, Input, Injectable, Optional, Component, NgModule, EventEmitter, Output, LOCALE_ID, Pipe, Inject, ViewContainerRef, ViewChild, InjectionToken } from '@angular/core';
3
+ import { SubscriptionObject, LockSet, filterMaybe, scanCount, combineLatestFromMapValuesObsFn, skipFirstMaybe } from '@dereekb/rxjs';
4
+ import * as i1 from 'rxjs';
5
+ import { BehaviorSubject, combineLatest, Subject, interval, EMPTY, of, isObservable, Observable } from 'rxjs';
6
+ import { switchMap, first, distinctUntilChanged, filter, debounce, throttle, exhaustMap, mergeMap, map, shareReplay, withLatestFrom, startWith, tap, delay } from 'rxjs/operators';
7
+ import * as i1$3 from '@dereekb/util';
8
+ import { hasValueOrNotEmpty, BooleanStringKeyArrayUtilityInstance, reduceBooleansWithOrFn, getValueFromObjectOrGetter, DataIsExpiredError, DataDoesNotExistError, filterMaybeValuesFn, StorageObjectUtility, SHARED_MEMORY_STORAGE } from '@dereekb/util';
9
+ import { ComponentStore } from '@ngrx/component-store';
10
+ import * as i2 from '@angular/common';
11
+ import { CommonModule, formatDate } from '@angular/common';
12
+ import ms from 'ms';
13
+ import * as i1$1 from '@angular/router';
14
+ import { NavigationStart, NavigationEnd } from '@angular/router';
15
+ import { isArray } from 'class-validator';
16
+ import * as i1$2 from '@uirouter/core';
17
+ import { addMinutes, isPast, formatDistance, isValid, formatDistanceToNow, startOfDay, isSameDay } from 'date-fns';
18
+ import { toJsDate, formatToTimeString, unixTimeNumberForNow, timeNumberHasExpired } from '@dereekb/date';
19
+
20
+ /**
21
+ * Abstract component that contains a SubscriptionObject and will clean it up automatically.
22
+ */
23
+ class AbstractSubscriptionDirective {
24
+ constructor(subscription) {
25
+ this._subscriptionObject = new SubscriptionObject();
26
+ this.sub = subscription;
27
+ }
28
+ ngOnDestroy() {
29
+ this._subscriptionObject.destroy();
30
+ }
31
+ set sub(subscription) {
32
+ this._subscriptionObject.subscription = subscription;
33
+ }
34
+ }
35
+ AbstractSubscriptionDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AbstractSubscriptionDirective, deps: [{ token: i1.Subscription }], target: i0.ɵɵFactoryTarget.Directive });
36
+ AbstractSubscriptionDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: AbstractSubscriptionDirective, ngImport: i0 });
37
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AbstractSubscriptionDirective, decorators: [{
38
+ type: Directive
39
+ }], ctorParameters: function () { return [{ type: i1.Subscription }]; } });
40
+ /**
41
+ * AbstractSubscriptionDirective extension that prevents the OnDestroy from occuring until the lockset is unlocked.
42
+ */
43
+ class AbstractLockSetSubscriptionDirective extends AbstractSubscriptionDirective {
44
+ constructor() {
45
+ super(...arguments);
46
+ this.lockSet = new LockSet();
47
+ }
48
+ ngOnDestroy() {
49
+ this.lockSet.onNextUnlock(() => this.onLockSetDestroy());
50
+ }
51
+ onLockSetDestroy() {
52
+ super.ngOnDestroy();
53
+ }
54
+ }
55
+ AbstractLockSetSubscriptionDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AbstractLockSetSubscriptionDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
56
+ AbstractLockSetSubscriptionDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: AbstractLockSetSubscriptionDirective, usesInheritance: true, ngImport: i0 });
57
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AbstractLockSetSubscriptionDirective, decorators: [{
58
+ type: Directive
59
+ }] });
60
+
61
+ /**
62
+ * Source that provides a ActionContextStore observable.
63
+ */
64
+ class ActionContextStoreSource {
65
+ }
66
+ /**
67
+ * Secondary source. Used by DbNgxActionContextComponent to find secondary sources.
68
+ */
69
+ class SecondaryActionContextStoreSource extends ActionContextStoreSource {
70
+ }
71
+ function actionContextStoreSourcePipe(obs) {
72
+ return obs.pipe(filterMaybe());
73
+ }
74
+ function pipeActionStore(source, pipeFn) {
75
+ return source.store$.pipe(switchMap(pipeFn));
76
+ }
77
+ /**
78
+ * Convenience function for subscribing to the input source once and using the provided store.
79
+ */
80
+ function useActionStore(source, useFn) {
81
+ return source.store$.pipe(first()).subscribe(useFn);
82
+ }
83
+ // tslint:disable-next-line: directive-class-suffix
84
+ class ActionContextStoreSourceInstance {
85
+ constructor(source) {
86
+ this.source = source;
87
+ this.lockSet = new LockSet();
88
+ if (!source) {
89
+ throw new Error('Source is required.');
90
+ }
91
+ }
92
+ ngOnDestroy() {
93
+ this.lockSet.destroyOnNextUnlock();
94
+ }
95
+ // MARK: Store
96
+ get store$() {
97
+ return this.source.store$;
98
+ }
99
+ pipeStore(pipeFn) {
100
+ return pipeActionStore(this.source, pipeFn);
101
+ }
102
+ useStore(useFn) {
103
+ return useActionStore(this.source, useFn);
104
+ }
105
+ get state$() {
106
+ return this.pipeStore(x => x.state$);
107
+ }
108
+ get triggered$() {
109
+ return this.pipeStore(x => x.triggered$);
110
+ }
111
+ get valueReady$() {
112
+ return this.pipeStore(x => x.valueReady$);
113
+ }
114
+ get success$() {
115
+ return this.pipeStore(x => x.success$);
116
+ }
117
+ get error$() {
118
+ return this.pipeStore(x => x.error$);
119
+ }
120
+ get rejected$() {
121
+ return this.pipeStore(x => x.rejected$);
122
+ }
123
+ get isModified$() {
124
+ return this.pipeStore(x => x.isModified$);
125
+ }
126
+ get isModifiedAndCanTriggerUpdates$() {
127
+ return this.pipeStore(x => x.isModifiedAndCanTriggerUpdates$);
128
+ }
129
+ get isModifiedAndCanTrigger$() {
130
+ return this.pipeStore(x => x.isModifiedAndCanTrigger$);
131
+ }
132
+ get actionState$() {
133
+ return this.pipeStore(x => x.actionState$);
134
+ }
135
+ get isWorking$() {
136
+ return this.pipeStore(x => x.isWorking$);
137
+ }
138
+ get isSuccess$() {
139
+ return this.pipeStore(x => x.isSuccess$);
140
+ }
141
+ get isDisabled$() {
142
+ return this.pipeStore(x => x.isDisabled$);
143
+ }
144
+ get errorCountSinceLastSuccess$() {
145
+ return this.pipeStore(x => x.errorCountSinceLastSuccess$);
146
+ }
147
+ enable(key, enable = true) {
148
+ this.disable(key, !enable);
149
+ }
150
+ disable(key, disable = true) {
151
+ this.useStore((x) => (disable) ? x.disable(key) : x.enable(key));
152
+ }
153
+ setIsModified(isModified) {
154
+ this.useStore((x) => x.setIsModified(isModified));
155
+ }
156
+ trigger() {
157
+ this.useStore((x) => x.trigger());
158
+ }
159
+ readyValue(value) {
160
+ this.useStore((x) => x.readyValue(value));
161
+ }
162
+ startWorking() {
163
+ this.useStore((x) => x.startWorking());
164
+ }
165
+ reject(error) {
166
+ this.useStore((x) => x.reject(error));
167
+ }
168
+ success(value) {
169
+ this.useStore((x) => x.success(value));
170
+ }
171
+ reset() {
172
+ this.useStore((x) => x.reset());
173
+ }
174
+ }
175
+ ActionContextStoreSourceInstance.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: ActionContextStoreSourceInstance, deps: [{ token: ActionContextStoreSource }], target: i0.ɵɵFactoryTarget.Directive });
176
+ ActionContextStoreSourceInstance.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: ActionContextStoreSourceInstance, ngImport: i0 });
177
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: ActionContextStoreSourceInstance, decorators: [{
178
+ type: Directive
179
+ }], ctorParameters: function () { return [{ type: ActionContextStoreSource }]; } });
180
+ const actionContextStoreSourceInstanceFactory = (source) => {
181
+ return new ActionContextStoreSourceInstance(source);
182
+ };
183
+ /**
184
+ * Provides an ActionContextStoreSource, as well as an ActionContextStoreSourceInstance.
185
+ */
186
+ function ProvideActionStoreSource(sourceType) {
187
+ return [{
188
+ provide: ActionContextStoreSource,
189
+ useExisting: forwardRef(() => sourceType)
190
+ },
191
+ {
192
+ provide: ActionContextStoreSourceInstance,
193
+ useFactory: actionContextStoreSourceInstanceFactory,
194
+ deps: [ActionContextStoreSource]
195
+ }];
196
+ }
197
+ function ProvideSecondaryActionStoreSource(sourceType) {
198
+ return [{
199
+ provide: SecondaryActionContextStoreSource,
200
+ useExisting: forwardRef(() => sourceType)
201
+ },
202
+ ...ProvideActionStoreSource(sourceType)
203
+ ];
204
+ }
205
+
206
+ class DbNgxActionAutoModifyDirective extends AbstractSubscriptionDirective {
207
+ constructor(source) {
208
+ super();
209
+ this.source = source;
210
+ this._autoModifyEnabled = new BehaviorSubject(true);
211
+ }
212
+ get autoModifyEnabled() {
213
+ return this._autoModifyEnabled.value;
214
+ }
215
+ set autoModifyEnabled(autoModifyEnabled) {
216
+ this._autoModifyEnabled.next(autoModifyEnabled !== 'false');
217
+ }
218
+ ngOnInit() {
219
+ const obs = combineLatest([
220
+ this._autoModifyEnabled.pipe(distinctUntilChanged()),
221
+ this.source.isModified$.pipe(filter(x => !x)) // Only when not modified send a value.
222
+ ]);
223
+ this.sub = obs.subscribe(([autoModifyEnabled, isModified]) => {
224
+ if (autoModifyEnabled && !isModified) {
225
+ this.source.setIsModified(true);
226
+ }
227
+ });
228
+ }
229
+ ngOnDestroy() {
230
+ this.source.lockSet.onNextUnlock(() => {
231
+ super.ngOnDestroy();
232
+ this._autoModifyEnabled.complete();
233
+ });
234
+ }
235
+ }
236
+ DbNgxActionAutoModifyDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionAutoModifyDirective, deps: [{ token: ActionContextStoreSourceInstance, host: true }], target: i0.ɵɵFactoryTarget.Directive });
237
+ DbNgxActionAutoModifyDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionAutoModifyDirective, selector: "[dbxActionAutoModify]", inputs: { autoModifyEnabled: ["dbxActionAutoModify", "autoModifyEnabled"] }, usesInheritance: true, ngImport: i0 });
238
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionAutoModifyDirective, decorators: [{
239
+ type: Directive,
240
+ args: [{
241
+ selector: '[dbxActionAutoModify]',
242
+ }]
243
+ }], ctorParameters: function () {
244
+ return [{ type: ActionContextStoreSourceInstance, decorators: [{
245
+ type: Host
246
+ }] }];
247
+ }, propDecorators: { autoModifyEnabled: [{
248
+ type: Input,
249
+ args: ['dbxActionAutoModify']
250
+ }] } });
251
+
252
+ const DEFAULT_DEBOUNCE_MS = 2 * 1000;
253
+ const DEFAULT_THROTTLE_MS = 10 * 1000;
254
+ const DEFAULT_ERROR_THROTTLE_MS = 3 * 1000;
255
+ const MAX_ERRORS_TO_THROTTLE_ON = 6;
256
+ /**
257
+ * Extension of DbNgxActionTransitionSafetyDirective that automatically triggers the action periodically when it is in a modified state.
258
+ */
259
+ class DbNgxActionAutoTriggerDirective extends AbstractSubscriptionDirective {
260
+ constructor(source) {
261
+ super();
262
+ this.source = source;
263
+ this._triggerEnabled = new BehaviorSubject(true);
264
+ this.triggerDebounce = DEFAULT_DEBOUNCE_MS;
265
+ this.triggerThrottle = DEFAULT_THROTTLE_MS;
266
+ this.triggerErrorThrottle = DEFAULT_ERROR_THROTTLE_MS;
267
+ this.maxErrorsForThrottle = MAX_ERRORS_TO_THROTTLE_ON;
268
+ this._triggerLimit = new BehaviorSubject(undefined);
269
+ this._trigger = new Subject();
270
+ this._triggerCount = 0;
271
+ this._errorCount$ = this.source.errorCountSinceLastSuccess$;
272
+ this._triggerCount$ = this.source.isModifiedAndCanTriggerUpdates$.pipe(filter(() => this.isEnabled), filter((x) => x), debounce(() => interval(this.triggerDebounce)), throttle(() => this._errorCount$.pipe(first(), exhaustMap((count) => interval(this.triggerThrottle + (Math.min(count, this.maxErrorsForThrottle) * this.triggerErrorThrottle)))), { leading: true, trailing: true }),
273
+ // Check again for the "trailing" piece.
274
+ filter(() => this.isEnabled), mergeMap(() => this.source.isModifiedAndCanTrigger$.pipe(first())), filter((x) => x), map(() => this._triggerCount += 1), shareReplay(1));
275
+ /**
276
+ * Observable for the trigger mechanism.
277
+ */
278
+ this.triggerCount$ = this._triggerEnabled.pipe(switchMap((enabled) => {
279
+ if (enabled) {
280
+ return this._triggerCount$;
281
+ }
282
+ else {
283
+ return EMPTY;
284
+ }
285
+ }));
286
+ this._isTriggerLimited$ = combineLatest([this.triggerCount$, this._triggerLimit]).pipe(map(([triggerCount, limit]) => [triggerCount, ((limit) ? (triggerCount > limit) : false)]), shareReplay(1));
287
+ this.isTriggerLimited$ = this._isTriggerLimited$.pipe(map(x => x[1]));
288
+ this.trigger$ = this._isTriggerLimited$.pipe(filter(x => !x[1]), distinctUntilChanged((a, b) => a[0] === b[0]), // Only trigger when the count changes.
289
+ map(() => undefined));
290
+ }
291
+ /**
292
+ * How much to throttle the auto-triggering.
293
+ */
294
+ get triggerEnabled() {
295
+ return this._triggerEnabled.value;
296
+ }
297
+ set triggerEnabled(triggerEnabled) {
298
+ triggerEnabled = triggerEnabled !== false; // Default to true
299
+ if (this.triggerEnabled !== triggerEnabled) {
300
+ this._triggerEnabled.next(triggerEnabled);
301
+ }
302
+ }
303
+ /**
304
+ * Optional input to override both triggerDebounce and triggerThrottle.
305
+ *
306
+ * Used in forms that are simple.
307
+ */
308
+ set fastTrigger(fastTrigger) {
309
+ if (fastTrigger) {
310
+ this.triggerDebounce = 200;
311
+ this.triggerThrottle = 500;
312
+ }
313
+ }
314
+ /**
315
+ * Optional input to override both triggerDebounce and triggerThrottle to be 0.
316
+ *
317
+ * Used in forms that generally return a single value.
318
+ */
319
+ set instantTrigger(instantTrigger) {
320
+ if (instantTrigger) {
321
+ this.triggerDebounce = 10;
322
+ this.triggerThrottle = 0;
323
+ }
324
+ }
325
+ get triggerLimit() {
326
+ return this._triggerLimit.value;
327
+ }
328
+ set triggerLimit(triggerLimit) {
329
+ triggerLimit = triggerLimit || 0;
330
+ this._triggerLimit.next(triggerLimit);
331
+ }
332
+ get isEnabled() {
333
+ return this.triggerEnabled !== false;
334
+ }
335
+ ngOnInit() {
336
+ this.sub = this.trigger$.subscribe(() => {
337
+ this.source.trigger();
338
+ });
339
+ }
340
+ ngOnDestroy() {
341
+ this.source.lockSet.onNextUnlock(() => {
342
+ super.ngOnDestroy();
343
+ this._trigger.complete();
344
+ this._triggerLimit.complete();
345
+ });
346
+ }
347
+ }
348
+ DbNgxActionAutoTriggerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionAutoTriggerDirective, deps: [{ token: ActionContextStoreSourceInstance, host: true }], target: i0.ɵɵFactoryTarget.Directive });
349
+ DbNgxActionAutoTriggerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionAutoTriggerDirective, selector: "[dbxActionAutoTrigger]", inputs: { triggerEnabled: ["dbxActionAutoTrigger", "triggerEnabled"], triggerDebounce: "triggerDebounce", triggerThrottle: "triggerThrottle", triggerErrorThrottle: "triggerErrorThrottle", fastTrigger: "fastTrigger", instantTrigger: "instantTrigger", triggerLimit: "triggerLimit" }, usesInheritance: true, ngImport: i0 });
350
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionAutoTriggerDirective, decorators: [{
351
+ type: Directive,
352
+ args: [{
353
+ selector: '[dbxActionAutoTrigger]',
354
+ }]
355
+ }], ctorParameters: function () {
356
+ return [{ type: ActionContextStoreSourceInstance, decorators: [{
357
+ type: Host
358
+ }] }];
359
+ }, propDecorators: { triggerEnabled: [{
360
+ type: Input,
361
+ args: ['dbxActionAutoTrigger']
362
+ }], triggerDebounce: [{
363
+ type: Input
364
+ }], triggerThrottle: [{
365
+ type: Input
366
+ }], triggerErrorThrottle: [{
367
+ type: Input
368
+ }], fastTrigger: [{
369
+ type: Input
370
+ }], instantTrigger: [{
371
+ type: Input
372
+ }], triggerLimit: [{
373
+ type: Input
374
+ }] } });
375
+
376
+ /**
377
+ * Directive that watches an observable for changes and sets the new value and modified states as necessary.
378
+ */
379
+ class DbNgxActionAutoTriggerValueDirective {
380
+ constructor(source) {
381
+ this.source = source;
382
+ this._valueObs = new BehaviorSubject(EMPTY);
383
+ this._isModifiedFn = new BehaviorSubject(undefined);
384
+ this._modifiedSub = new SubscriptionObject();
385
+ this._triggerSub = new SubscriptionObject();
386
+ this.modifiedValue$ = this._valueObs.pipe(switchMap((obs) => obs.pipe(withLatestFrom(this._isModifiedFn), mergeMap(([value, dbxActionAutoTriggerModified]) => {
387
+ let result;
388
+ if (dbxActionAutoTriggerModified) {
389
+ result = dbxActionAutoTriggerModified(value).pipe(map((isModified) => [isModified, value]));
390
+ }
391
+ else {
392
+ result = of([true, value]);
393
+ }
394
+ return result;
395
+ }), shareReplay(1))));
396
+ }
397
+ set dbxActionAutoTriggerValue(dbxActionAutoTriggerValue) {
398
+ this._valueObs.next(dbxActionAutoTriggerValue);
399
+ }
400
+ set dbxActionAutoTriggerModifiedNonEmptyValue(requireNonEmpty) {
401
+ if (requireNonEmpty) {
402
+ this.dbxActionAutoTriggerModified = (value) => {
403
+ return of(hasValueOrNotEmpty(value));
404
+ };
405
+ }
406
+ }
407
+ set dbxActionAutoTriggerModified(dbxActionAutoTriggerModified) {
408
+ this._isModifiedFn.next(dbxActionAutoTriggerModified);
409
+ }
410
+ ngOnInit() {
411
+ // Update Modified value.
412
+ this._modifiedSub.subscription = this.modifiedValue$.subscribe(([isModified, value]) => {
413
+ this.source.setIsModified(isModified);
414
+ });
415
+ // Set the value on triggers.
416
+ this._triggerSub.subscription = this.source.triggered$.pipe(mergeMap(x => this.modifiedValue$)).subscribe(([isModified, value]) => {
417
+ this.source.readyValue(value);
418
+ });
419
+ }
420
+ ngOnDestroy() {
421
+ this.source.lockSet.onNextUnlock(() => {
422
+ this._isModifiedFn.complete();
423
+ this._valueObs.complete();
424
+ this._modifiedSub.destroy();
425
+ this._triggerSub.destroy();
426
+ });
427
+ }
428
+ }
429
+ DbNgxActionAutoTriggerValueDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionAutoTriggerValueDirective, deps: [{ token: ActionContextStoreSourceInstance, host: true }], target: i0.ɵɵFactoryTarget.Directive });
430
+ DbNgxActionAutoTriggerValueDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionAutoTriggerValueDirective, selector: "[dbxActionAutoTriggerValue]", inputs: { dbxActionAutoTriggerValue: "dbxActionAutoTriggerValue", dbxActionAutoTriggerModifiedNonEmptyValue: "dbxActionAutoTriggerModifiedNonEmptyValue", dbxActionAutoTriggerModified: "dbxActionAutoTriggerModified" }, ngImport: i0 });
431
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionAutoTriggerValueDirective, decorators: [{
432
+ type: Directive,
433
+ args: [{
434
+ selector: '[dbxActionAutoTriggerValue]',
435
+ }]
436
+ }], ctorParameters: function () {
437
+ return [{ type: ActionContextStoreSourceInstance, decorators: [{
438
+ type: Host
439
+ }] }];
440
+ }, propDecorators: { dbxActionAutoTriggerValue: [{
441
+ type: Input,
442
+ args: ['dbxActionAutoTriggerValue']
443
+ }], dbxActionAutoTriggerModifiedNonEmptyValue: [{
444
+ type: Input
445
+ }], dbxActionAutoTriggerModified: [{
446
+ type: Input
447
+ }] } });
448
+
449
+ /**
450
+ * Used by ActionContextState to denote what state the action is in.
451
+ */
452
+ var ActionState;
453
+ (function (ActionState) {
454
+ /**
455
+ * No action in progress. Waiting for the trigger.
456
+ */
457
+ ActionState["Idle"] = "idle";
458
+ /**
459
+ * Idle state that can be set to show that the source is not yet ready.
460
+ */
461
+ ActionState["Disabled"] = "disabled";
462
+ /**
463
+ * The action was triggered. We wait (and allow) the value to be updated.
464
+ */
465
+ ActionState["Triggered"] = "triggered";
466
+ /**
467
+ * The trigger was accepted and the value is updated. It should begin working immediately.
468
+ *
469
+ * ValueReady cannot be set until triggered is set.
470
+ */
471
+ ActionState["ValueReady"] = "valueReady";
472
+ /**
473
+ * The action is in progress.
474
+ */
475
+ ActionState["Working"] = "working";
476
+ /**
477
+ * The trigger, action, or value was rejected due to an error or other issue.
478
+ *
479
+ * An error may be specified optionally.
480
+ */
481
+ ActionState["Rejected"] = "rejected";
482
+ /**
483
+ * The action was successful.
484
+ */
485
+ ActionState["Success"] = "success";
486
+ })(ActionState || (ActionState = {}));
487
+ const DEFAULT_ACTION_DISABLED_KEY = 'default';
488
+ function isIdleActionState(actionState) {
489
+ switch (actionState) {
490
+ case ActionState.Idle:
491
+ case ActionState.Disabled:
492
+ case ActionState.Rejected:
493
+ case ActionState.Success:
494
+ return true;
495
+ default:
496
+ return false;
497
+ }
498
+ }
499
+
500
+ function isActionContextEnabled(state) {
501
+ return BooleanStringKeyArrayUtilityInstance.isFalse(state.disabled);
502
+ }
503
+ function isActionContextDisabled(state) {
504
+ return BooleanStringKeyArrayUtilityInstance.isTrue(state.disabled);
505
+ }
506
+ function isDisabledActionContextState(state) {
507
+ return isIdleActionState(state.actionState) && isActionContextDisabled(state);
508
+ }
509
+ function isWorkingActionState(actionState) {
510
+ return !isIdleActionState(actionState);
511
+ }
512
+ function canTriggerActionState(actionState) {
513
+ return actionState !== ActionState.Disabled && isIdleActionState(actionState);
514
+ }
515
+ function canTriggerAction(state) {
516
+ return isActionContextEnabled(state) && isIdleActionState(state.actionState);
517
+ }
518
+ function canReadyValue(state) {
519
+ return state.actionState === ActionState.Triggered;
520
+ }
521
+ function actionContextIsModifiedAndCanTrigger(state) {
522
+ // console.log('check: ', state, state.isModified, canTriggerAction(state));
523
+ return state.isModified && canTriggerAction(state);
524
+ }
525
+ function actionContextHasNoErrorAndIsModifiedAndCanTrigger(state) {
526
+ return !state.error && actionContextIsModifiedAndCanTrigger(state);
527
+ }
528
+ const INITIAL_STATE = {
529
+ isModified: false,
530
+ actionState: ActionState.Idle
531
+ };
532
+ class ActionContextStore extends ComponentStore {
533
+ constructor() {
534
+ super(Object.assign({}, INITIAL_STATE));
535
+ this.lockSet = new LockSet();
536
+ // MARK: Accessors
537
+ this.actionState$ = this.state$.pipe(map(x => isDisabledActionContextState(x) ? ActionState.Disabled : x.actionState), shareReplay(1));
538
+ /**
539
+ * Returns the current disabled reasons.
540
+ */
541
+ this.disabled$ = this.state$.pipe(map(x => { var _a; return [...(_a = x.disabled) !== null && _a !== void 0 ? _a : []]; }), distinctUntilChanged(), shareReplay(1));
542
+ /**
543
+ * Maps the current state to true or not when the action state changes to/from disabled.
544
+ */
545
+ this.isDisabled$ = this.state$.pipe(map(isDisabledActionContextState), distinctUntilChanged(), shareReplay(1));
546
+ /**
547
+ * Pipes when idle but modified.
548
+ */
549
+ this.isModified$ = this.afterDistinctBoolean(x => x.isModified);
550
+ /**
551
+ * Pipes true when triggered.
552
+ */
553
+ this.triggered$ = this.afterDistinctActionState(ActionState.Triggered, () => true);
554
+ /**
555
+ * Pipes the readied value on ValueReady.
556
+ */
557
+ this.valueReady$ = this.afterDistinctActionState(ActionState.ValueReady, x => x.value);
558
+ /**
559
+ * Pipes the error on the rejection state.
560
+ */
561
+ this.rejected$ = this.afterDistinctActionState(ActionState.Rejected, x => x.error);
562
+ /**
563
+ * Pipes the result when the ActionState becomes working.
564
+ */
565
+ this.working$ = this.afterDistinctActionState(ActionState.Working, () => true);
566
+ /**
567
+ * Whether or not it is currently in a working state.
568
+ */
569
+ this.isWorking$ = this.afterDistinctBoolean(x => isWorkingActionState(x.actionState));
570
+ /**
571
+ * Pipes the current error.
572
+ */
573
+ this.error$ = this.state$.pipe(map(x => x.error), distinctUntilChanged(), shareReplay(1));
574
+ /**
575
+ * Pipes the result when the ActionState becomes success.
576
+ */
577
+ this.success$ = this.afterDistinctActionState(ActionState.Success, x => x.result);
578
+ /**
579
+ * Whether or not it is currently in a success state.
580
+ */
581
+ this.isSuccess$ = this.afterDistinctBoolean(x => x.actionState === ActionState.Success);
582
+ /**
583
+ * Number of errors since last success.
584
+ */
585
+ this.errorCountSinceLastSuccess$ = this.isSuccess$.pipe(startWith(false), distinctUntilChanged(), switchMap(() => this.error$.pipe(filterMaybe(), scanCount(), startWith(0))), shareReplay(1));
586
+ /**
587
+ * Whether or not the state can be triggered.
588
+ */
589
+ this.canTrigger$ = this.state$.pipe(map(canTriggerAction), distinctUntilChanged(), shareReplay(1));
590
+ /**
591
+ * Pipe that maps whether or not this is modified and can be triggered.
592
+ *
593
+ * Updates every state update instead of when the value changes.
594
+ */
595
+ this.isModifiedAndCanTriggerUpdates$ = this.state$.pipe(map((x) => actionContextIsModifiedAndCanTrigger(x), shareReplay(1)));
596
+ /**
597
+ * Whether or not it can be triggered and modified.
598
+ */
599
+ this.isModifiedAndCanTrigger$ = this.isModifiedAndCanTriggerUpdates$.pipe(distinctUntilChanged());
600
+ this.hasNoErrorAndIsModifiedAndCanTrigger$ = this.state$.pipe(map((x) => actionContextHasNoErrorAndIsModifiedAndCanTrigger(x)), distinctUntilChanged(), shareReplay(1));
601
+ // MARK: State Changes
602
+ /**
603
+ * Adds a disabled reason.
604
+ */
605
+ this.disable = this.updater((state, key) => (Object.assign(Object.assign({}, state), { disabled: BooleanStringKeyArrayUtilityInstance.insert(state.disabled, (key !== null && key !== void 0 ? key : DEFAULT_ACTION_DISABLED_KEY)) })));
606
+ /**
607
+ * Removes a disabled reason.
608
+ */
609
+ this.enable = this.updater((state, key) => (Object.assign(Object.assign({}, state), { disabled: BooleanStringKeyArrayUtilityInstance.remove(state.disabled, (key !== null && key !== void 0 ? key : DEFAULT_ACTION_DISABLED_KEY)) })));
610
+ /**
611
+ * Triggers the modified state, if not disabled.
612
+ */
613
+ this.setIsModified = this.updater((state, isModified) => (Object.assign(Object.assign({}, state), { actionState: (state.actionState === ActionState.Success) ? ActionState.Idle : state.actionState, isModified: isModified !== null && isModified !== void 0 ? isModified : true })));
614
+ /**
615
+ * Triggers the action if the state is currently not idle. The current state is cleared, but the error is retained (as we may need the error from the previous attempt).
616
+ *
617
+ * Will not fire if the action is disabled.
618
+ */
619
+ this.trigger = this.updater((state) => canTriggerAction(state)
620
+ ? ({ isModified: state.isModified, actionState: ActionState.Triggered, error: state.error, value: undefined })
621
+ : state);
622
+ /**
623
+ * Updates the value, setting value ready. The current result is cleared.
624
+ */
625
+ this.readyValue = this.updater((state, value) => canReadyValue(state)
626
+ ? (Object.assign(Object.assign({}, state), { actionState: ActionState.ValueReady, value, result: undefined }))
627
+ : state);
628
+ /**
629
+ * Notifys the context that the action is in progress.
630
+ */
631
+ this.startWorking = this.updater((state) => (Object.assign(Object.assign({}, state), { actionState: ActionState.Working })));
632
+ /**
633
+ * Triggers rejection of the action. The value is cleared.
634
+ */
635
+ this.reject = this.updater((state, error) => { var _a; return ({ isModified: state.isModified, actionState: ActionState.Rejected, error, errorCount: ((_a = state.errorCount) !== null && _a !== void 0 ? _a : 0) + 1 }); });
636
+ /**
637
+ * Updates the state to success, and optionally sets a result.
638
+ *
639
+ * Clears modified state, and any errors.
640
+ */
641
+ this.success = this.updater((state, result) => ({ isModified: false, actionState: ActionState.Success, value: state.value, result, error: undefined }));
642
+ /**
643
+ * Completely resets the store.
644
+ */
645
+ this.reset = this.updater((state) => (Object.assign({}, INITIAL_STATE)));
646
+ this.lockSet.addLock('working', this.isWorking$);
647
+ }
648
+ // MARK: Utility
649
+ afterDistinctBoolean(fromState) {
650
+ return this.state$.pipe(map(x => fromState(x)), distinctUntilChanged(), shareReplay(1));
651
+ }
652
+ afterDistinctActionState(actionState, fromState) {
653
+ return this.state$.pipe(map((x) => ([x, x.actionState])), distinctUntilChanged((a, b) => (a === null || a === void 0 ? void 0 : a[1]) === (b === null || b === void 0 ? void 0 : b[1])), // Filter out when the state remains the same.
654
+ filter(([x, y]) => y === actionState), // Only pipe when the action state matches.
655
+ map(x => fromState(x[0])), shareReplay(1));
656
+ }
657
+ // MARK: Cleanup
658
+ ngOnDestroy() {
659
+ // Wait for any actions to complete before destroying.
660
+ this.lockSet.onNextUnlock(() => {
661
+ super.ngOnDestroy();
662
+ }, 2000);
663
+ }
664
+ }
665
+ ActionContextStore.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: ActionContextStore, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
666
+ ActionContextStore.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: ActionContextStore });
667
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: ActionContextStore, decorators: [{
668
+ type: Injectable
669
+ }], ctorParameters: function () { return []; } });
670
+
671
+ /**
672
+ * Abstract class that can either use SecondaryActionContextStoreSource or create it's own.
673
+ */
674
+ class ActionContextBaseSource {
675
+ constructor(inputSource) {
676
+ this.inputSource = inputSource;
677
+ if (this.inputSource) {
678
+ this._store$ = this.inputSource.store$;
679
+ }
680
+ else {
681
+ this._store = new ActionContextStore();
682
+ this._store$ = of(this._store);
683
+ }
684
+ this._instance = new ActionContextStoreSourceInstance(this);
685
+ this.isModified$ = this._instance.isModified$;
686
+ this.triggered$ = this._instance.triggered$;
687
+ this.success$ = this._instance.success$;
688
+ }
689
+ destroy() {
690
+ if (this._store) {
691
+ this._store.ngOnDestroy();
692
+ this._instance.ngOnDestroy();
693
+ }
694
+ }
695
+ get lockSet() {
696
+ return this._instance.lockSet;
697
+ }
698
+ get sourceInstance() {
699
+ return this._instance;
700
+ }
701
+ get store$() {
702
+ return this._store$;
703
+ }
704
+ /**
705
+ * Use to trigger the action directly.
706
+ */
707
+ trigger() {
708
+ this._instance.trigger();
709
+ }
710
+ readyValue(value) {
711
+ this._instance.readyValue(value);
712
+ }
713
+ reset() {
714
+ this._instance.reset();
715
+ }
716
+ }
717
+
718
+ /**
719
+ * Provides an DbNgxActionContext.
720
+ */
721
+ class DbNgxActionContextDirective extends ActionContextBaseSource {
722
+ constructor(inputSource) {
723
+ super(inputSource);
724
+ }
725
+ ngOnDestroy() {
726
+ this.lockSet.destroyOnNextUnlock(() => {
727
+ this.destroy();
728
+ });
729
+ }
730
+ }
731
+ DbNgxActionContextDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionContextDirective, deps: [{ token: SecondaryActionContextStoreSource, host: true, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
732
+ DbNgxActionContextDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionContextDirective, selector: "[dbxActionContext]", providers: ProvideActionStoreSource(DbNgxActionContextDirective), exportAs: ["action"], usesInheritance: true, ngImport: i0 });
733
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionContextDirective, decorators: [{
734
+ type: Directive,
735
+ args: [{
736
+ selector: '[dbxActionContext]',
737
+ exportAs: 'action',
738
+ providers: ProvideActionStoreSource(DbNgxActionContextDirective)
739
+ }]
740
+ }], ctorParameters: function () {
741
+ return [{ type: SecondaryActionContextStoreSource, decorators: [{
742
+ type: Optional
743
+ }, {
744
+ type: Host
745
+ }] }];
746
+ } });
747
+
748
+ class DbNgxActionComponent extends DbNgxActionContextDirective {
749
+ }
750
+ DbNgxActionComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
751
+ DbNgxActionComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionComponent, selector: "dbx-action", providers: ProvideActionStoreSource(DbNgxActionComponent), exportAs: ["action"], usesInheritance: true, ngImport: i0, template: '<ng-content></ng-content>', isInline: true });
752
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionComponent, decorators: [{
753
+ type: Component,
754
+ args: [{
755
+ selector: 'dbx-action',
756
+ exportAs: 'action',
757
+ template: '<ng-content></ng-content>',
758
+ providers: ProvideActionStoreSource(DbNgxActionComponent)
759
+ }]
760
+ }] });
761
+
762
+ /**
763
+ * Directive that provides a DbNgxActionSourceDirective that is passed in.
764
+ */
765
+ class DbNgxActionSourceDirective {
766
+ constructor() {
767
+ this._source = new BehaviorSubject(undefined);
768
+ this.store$ = this._source.pipe(filterMaybe(), switchMap((x) => actionContextStoreSourcePipe(x.store$)));
769
+ }
770
+ ngOnDestroy() {
771
+ this._source.complete();
772
+ }
773
+ get source() {
774
+ return this._source.value;
775
+ }
776
+ set source(source) {
777
+ if (source && !source.store$) {
778
+ throw new Error('Invalid source passed to dbxActionSource.');
779
+ }
780
+ this._source.next(source);
781
+ }
782
+ }
783
+ DbNgxActionSourceDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionSourceDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
784
+ DbNgxActionSourceDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionSourceDirective, selector: "[dbxActionSource]", inputs: { source: ["dbxActionSource", "source"] }, providers: ProvideSecondaryActionStoreSource(DbNgxActionSourceDirective), ngImport: i0 });
785
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionSourceDirective, decorators: [{
786
+ type: Directive,
787
+ args: [{
788
+ selector: '[dbxActionSource]',
789
+ providers: ProvideSecondaryActionStoreSource(DbNgxActionSourceDirective)
790
+ }]
791
+ }], propDecorators: { source: [{
792
+ type: Input,
793
+ args: ['dbxActionSource']
794
+ }] } });
795
+
796
+ /**
797
+ * Prints out the current state to the console. Useful for debugging.
798
+ */
799
+ class DbNgxActionContextLoggerDirective extends AbstractSubscriptionDirective {
800
+ constructor(source) {
801
+ super();
802
+ this.source = source;
803
+ }
804
+ ngOnInit() {
805
+ this.sub = this.source.state$.subscribe((state) => {
806
+ console.log('State: ', state);
807
+ });
808
+ }
809
+ }
810
+ DbNgxActionContextLoggerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionContextLoggerDirective, deps: [{ token: ActionContextStoreSourceInstance, host: true }], target: i0.ɵɵFactoryTarget.Directive });
811
+ DbNgxActionContextLoggerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionContextLoggerDirective, selector: "[dbxActionContextLogger]", usesInheritance: true, ngImport: i0 });
812
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionContextLoggerDirective, decorators: [{
813
+ type: Directive,
814
+ args: [{
815
+ selector: '[dbxActionContextLogger]'
816
+ }]
817
+ }], ctorParameters: function () {
818
+ return [{ type: ActionContextStoreSourceInstance, decorators: [{
819
+ type: Host
820
+ }] }];
821
+ } });
822
+
823
+ /**
824
+ * Context used for providing actions based on the action key.
825
+ *
826
+ * This is useful for passing action contexts around via the providers instead of explicit injection.
827
+ */
828
+ class DbNgxActionContextMapDirective {
829
+ constructor() {
830
+ this._map = new BehaviorSubject(new Map());
831
+ this.map$ = this._map.asObservable();
832
+ this.areAnyWorking$ = this.checkAnyAre(x => x.isWorking$, false);
833
+ }
834
+ get map() {
835
+ return this._map.value;
836
+ }
837
+ sourceForKey(key) {
838
+ return new DbNgxActionContextMapDirectiveSourceInstance(this, key);
839
+ }
840
+ addStoreSource(key, source) {
841
+ if (this.map.has(key)) {
842
+ throw new Error(`Key already existed for "${key}" in map. Ensure the previous store is removed before setting another.`);
843
+ }
844
+ else if (!source) {
845
+ throw new Error('addStoreSource requires a source.');
846
+ }
847
+ this.map.set(key, source);
848
+ this._map.next(this.map);
849
+ }
850
+ removeStore(key) {
851
+ if (!this.map.delete(key)) {
852
+ console.warn('removeStore called and no value was found.');
853
+ }
854
+ this._map.next(this.map);
855
+ }
856
+ ngOnDestroy() {
857
+ this._map.complete();
858
+ }
859
+ // MARK: Utility
860
+ checkAnyAre(mapFn, emptyArrayValue = false) {
861
+ return this.reduceFromAllSources(mapFn, reduceBooleansWithOrFn(emptyArrayValue));
862
+ }
863
+ reduceFromAllSources(mapFn, reduceFn) {
864
+ return this.fromAllSources(mapFn).pipe(map(reduceFn));
865
+ }
866
+ fromAllSources(mapFn) {
867
+ return this.map$.pipe(switchMap(combineLatestFromMapValuesObsFn((x) => x.store$.pipe(switchMap(mapFn)))));
868
+ }
869
+ }
870
+ DbNgxActionContextMapDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionContextMapDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
871
+ DbNgxActionContextMapDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionContextMapDirective, selector: "[dbxActionContextMap]", providers: [], exportAs: ["actionMap"], ngImport: i0 });
872
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionContextMapDirective, decorators: [{
873
+ type: Directive,
874
+ args: [{
875
+ selector: '[dbxActionContextMap]',
876
+ exportAs: 'actionMap',
877
+ providers: [],
878
+ }]
879
+ }], ctorParameters: function () { return []; } });
880
+ class DbNgxActionContextMapDirectiveSourceInstance {
881
+ constructor(parent, key) {
882
+ this.parent = parent;
883
+ this.key = key;
884
+ this._source$ = this.parent.map$.pipe(map(x => x.get(this.key)), distinctUntilChanged());
885
+ this._store$ = this._source$.pipe(switchMap((x) => { var _a; return (_a = x === null || x === void 0 ? void 0 : x.store$) !== null && _a !== void 0 ? _a : of(undefined); }), shareReplay(1));
886
+ this.store$ = actionContextStoreSourcePipe(this._store$);
887
+ }
888
+ }
889
+
890
+ /**
891
+ * Directive that provides a ActionContextStoreSource using the input key and DbNgxActionContextMapDirective.
892
+ */
893
+ class DbNgxActionFromMapDirective {
894
+ constructor(_map) {
895
+ this._map = _map;
896
+ this._key = new BehaviorSubject(undefined);
897
+ this.store$ = this._key.pipe(filterMaybe(), switchMap((x) => this._map.sourceForKey(x).store$));
898
+ }
899
+ ngOnDestroy() {
900
+ this._key.complete();
901
+ }
902
+ get key() {
903
+ return this._key.value;
904
+ }
905
+ set key(key) {
906
+ this._key.next(key);
907
+ }
908
+ }
909
+ DbNgxActionFromMapDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionFromMapDirective, deps: [{ token: DbNgxActionContextMapDirective }], target: i0.ɵɵFactoryTarget.Directive });
910
+ DbNgxActionFromMapDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionFromMapDirective, selector: "[dbxActionFromMap]", inputs: { key: ["dbxActionFromMap", "key"] }, providers: ProvideSecondaryActionStoreSource(DbNgxActionFromMapDirective), ngImport: i0 });
911
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionFromMapDirective, decorators: [{
912
+ type: Directive,
913
+ args: [{
914
+ selector: '[dbxActionFromMap]',
915
+ providers: ProvideSecondaryActionStoreSource(DbNgxActionFromMapDirective)
916
+ }]
917
+ }], ctorParameters: function () { return [{ type: DbNgxActionContextMapDirective }]; }, propDecorators: { key: [{
918
+ type: Input,
919
+ args: ['dbxActionFromMap']
920
+ }] } });
921
+
922
+ /**
923
+ * Used to communicate with an dbxActionMap and set the ActionContextStore to the store based on the key.
924
+ */
925
+ class DbNgxActionMapSourceDirective {
926
+ constructor(source, _map) {
927
+ this.source = source;
928
+ this._map = _map;
929
+ }
930
+ ngOnDestroy() {
931
+ this._removeFromToStore();
932
+ }
933
+ set key(key) {
934
+ if (this._key !== key) {
935
+ this._removeFromToStore();
936
+ }
937
+ this._key = key;
938
+ this._addToStore();
939
+ }
940
+ _addToStore() {
941
+ if (this._key) {
942
+ this._map.addStoreSource(this._key, this.source);
943
+ }
944
+ }
945
+ _removeFromToStore() {
946
+ if (this._key) {
947
+ this._map.removeStore(this._key);
948
+ }
949
+ }
950
+ }
951
+ DbNgxActionMapSourceDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionMapSourceDirective, deps: [{ token: ActionContextStoreSource, host: true }, { token: DbNgxActionContextMapDirective }], target: i0.ɵɵFactoryTarget.Directive });
952
+ DbNgxActionMapSourceDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionMapSourceDirective, selector: "[dbxActionMapSource]", inputs: { key: ["dbxActionMapSource", "key"] }, ngImport: i0 });
953
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionMapSourceDirective, decorators: [{
954
+ type: Directive,
955
+ args: [{
956
+ selector: '[dbxActionMapSource]'
957
+ }]
958
+ }], ctorParameters: function () {
959
+ return [{ type: ActionContextStoreSource, decorators: [{
960
+ type: Host
961
+ }] }, { type: DbNgxActionContextMapDirective }];
962
+ }, propDecorators: { key: [{
963
+ type: Input,
964
+ args: ['dbxActionMapSource']
965
+ }] } });
966
+
967
+ /**
968
+ * Map that returns sources for ActionKey values.
969
+ */
970
+ class ActionContextStoreSourceMap {
971
+ }
972
+
973
+ const DEFAULT_ACTION_MAP_WORKING_DISABLED_KEY = '';
974
+ /**
975
+ * Used to communicate with an dbxActionMap and set the ActionContextStore to be disabled if any other element in the map is working.
976
+ */
977
+ class DbNgxActionMapWorkingDisableDirective extends AbstractSubscriptionDirective {
978
+ constructor(source, _map) {
979
+ super();
980
+ this.source = source;
981
+ this._map = _map;
982
+ }
983
+ ngOnInit() {
984
+ this.sub = this._map.areAnyWorking$.subscribe((x) => {
985
+ this.source.disable(this.disabledKey || DEFAULT_ACTION_MAP_WORKING_DISABLED_KEY, x);
986
+ });
987
+ }
988
+ ngOnDestroy() {
989
+ super.ngOnDestroy();
990
+ this.source.enable(this.disabledKey || DEFAULT_ACTION_MAP_WORKING_DISABLED_KEY);
991
+ }
992
+ }
993
+ DbNgxActionMapWorkingDisableDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionMapWorkingDisableDirective, deps: [{ token: ActionContextStoreSourceInstance, host: true }, { token: DbNgxActionContextMapDirective }], target: i0.ɵɵFactoryTarget.Directive });
994
+ DbNgxActionMapWorkingDisableDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionMapWorkingDisableDirective, selector: "[dbxActionMapWorkingDisable]", inputs: { disabledKey: ["dbxActionMapWorkingDisable", "disabledKey"] }, usesInheritance: true, ngImport: i0 });
995
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionMapWorkingDisableDirective, decorators: [{
996
+ type: Directive,
997
+ args: [{
998
+ selector: '[dbxActionMapWorkingDisable]'
999
+ }]
1000
+ }], ctorParameters: function () {
1001
+ return [{ type: ActionContextStoreSourceInstance, decorators: [{
1002
+ type: Host
1003
+ }] }, { type: DbNgxActionContextMapDirective }];
1004
+ }, propDecorators: { disabledKey: [{
1005
+ type: Input,
1006
+ args: ['dbxActionMapWorkingDisable']
1007
+ }] } });
1008
+
1009
+ const APP_ACTION_DISABLED_DIRECTIVE_KEY = 'dbx_action_disabled';
1010
+ /**
1011
+ * Directive that allows disabling an action using the inputs.
1012
+ */
1013
+ class DbNgxActionDisabledDirective extends AbstractSubscriptionDirective {
1014
+ constructor(source) {
1015
+ super();
1016
+ this.source = source;
1017
+ this._disabled = new BehaviorSubject(false);
1018
+ this.disabled$ = this._disabled.pipe(distinctUntilChanged());
1019
+ }
1020
+ ngOnInit() {
1021
+ this.sub = this.disabled$.subscribe((x) => {
1022
+ this.source.disable(APP_ACTION_DISABLED_DIRECTIVE_KEY, x);
1023
+ });
1024
+ }
1025
+ ngOnDestroy() {
1026
+ super.ngOnDestroy();
1027
+ this._disabled.complete();
1028
+ this.source.enable(APP_ACTION_DISABLED_DIRECTIVE_KEY);
1029
+ }
1030
+ get disabled() {
1031
+ return this._disabled.value;
1032
+ }
1033
+ set disabled(disabled) {
1034
+ this._disabled.next(disabled);
1035
+ }
1036
+ }
1037
+ DbNgxActionDisabledDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionDisabledDirective, deps: [{ token: ActionContextStoreSourceInstance, host: true }], target: i0.ɵɵFactoryTarget.Directive });
1038
+ DbNgxActionDisabledDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionDisabledDirective, selector: "[dbxActionDisabled]", inputs: { disabled: ["dbxActionDisabled", "disabled"] }, usesInheritance: true, ngImport: i0 });
1039
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionDisabledDirective, decorators: [{
1040
+ type: Directive,
1041
+ args: [{
1042
+ selector: '[dbxActionDisabled]'
1043
+ }]
1044
+ }], ctorParameters: function () {
1045
+ return [{ type: ActionContextStoreSourceInstance, decorators: [{
1046
+ type: Host
1047
+ }] }];
1048
+ }, propDecorators: { disabled: [{
1049
+ type: Input,
1050
+ args: ['dbxActionDisabled']
1051
+ }] } });
1052
+
1053
+ const APP_ACTION_DISABLED_UNTIL_MODIFIED_DIRECTIVE_KEY = 'dbx_action_is_not_modified';
1054
+ /**
1055
+ * Directive that sets the disabled state based on the current isModified state.
1056
+ */
1057
+ class DbNgxActionDisabledUntilModifiedDirective extends AbstractSubscriptionDirective {
1058
+ constructor(source) {
1059
+ super();
1060
+ this.source = source;
1061
+ }
1062
+ ngOnInit() {
1063
+ this.sub = this.source.isModified$.subscribe((x) => {
1064
+ this.source.disable(APP_ACTION_DISABLED_UNTIL_MODIFIED_DIRECTIVE_KEY, !x);
1065
+ });
1066
+ }
1067
+ ngOnDestroy() {
1068
+ super.ngOnDestroy();
1069
+ this.source.enable(APP_ACTION_DISABLED_UNTIL_MODIFIED_DIRECTIVE_KEY);
1070
+ }
1071
+ }
1072
+ DbNgxActionDisabledUntilModifiedDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionDisabledUntilModifiedDirective, deps: [{ token: ActionContextStoreSourceInstance, host: true }], target: i0.ɵɵFactoryTarget.Directive });
1073
+ DbNgxActionDisabledUntilModifiedDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionDisabledUntilModifiedDirective, selector: "[dbxActionDisabledUntilModified]", usesInheritance: true, ngImport: i0 });
1074
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionDisabledUntilModifiedDirective, decorators: [{
1075
+ type: Directive,
1076
+ args: [{
1077
+ selector: '[dbxActionDisabledUntilModified]'
1078
+ }]
1079
+ }], ctorParameters: function () {
1080
+ return [{ type: ActionContextStoreSourceInstance, decorators: [{
1081
+ type: Host
1082
+ }] }];
1083
+ } });
1084
+
1085
+ /**
1086
+ * WorkHandlerContextDelegate implementation using an ActionContextStoreSourceInstance.
1087
+ */
1088
+ class WorkHandlerContextSourceDelegate {
1089
+ constructor(source) {
1090
+ this.source = source;
1091
+ }
1092
+ startWorking() {
1093
+ this.source.startWorking();
1094
+ }
1095
+ success(result) {
1096
+ this.source.success(result);
1097
+ }
1098
+ reject(error) {
1099
+ this.source.reject(error);
1100
+ }
1101
+ }
1102
+ /**
1103
+ * Used by DbNgxActionHandlerDirective when handling a function.
1104
+ */
1105
+ class WorkHandlerContext {
1106
+ constructor(value, delegate) {
1107
+ this.value = value;
1108
+ this.delegate = delegate;
1109
+ this._done = false;
1110
+ this._doneActionBegan = false;
1111
+ this._actionBegan = new BehaviorSubject(false);
1112
+ this._isComplete = new BehaviorSubject(false);
1113
+ // Schedule to cleanup self once isComplete is true.
1114
+ this._isComplete.subscribe((done) => {
1115
+ if (done) {
1116
+ this.destroy();
1117
+ }
1118
+ });
1119
+ }
1120
+ get actionBegan() {
1121
+ var _a;
1122
+ return (_a = this._doneActionBegan) !== null && _a !== void 0 ? _a : this._actionBegan.value;
1123
+ }
1124
+ get actionBegan$() {
1125
+ return this._done ? of(this._doneActionBegan) : this._actionBegan.asObservable();
1126
+ }
1127
+ get isComplete() {
1128
+ return this._done || this._isComplete.value;
1129
+ }
1130
+ get isComplete$() {
1131
+ return this._done ? of(true) : this._isComplete.asObservable();
1132
+ }
1133
+ /**
1134
+ * Begins working using an observable.
1135
+ */
1136
+ startWorkingWithObservable(actionObs) {
1137
+ this.startWorking();
1138
+ actionObs.pipe(first()).subscribe((actionResult) => {
1139
+ this.success(actionResult);
1140
+ }, (error) => {
1141
+ var _a, _b;
1142
+ const message = (_b = (_a = error.message) !== null && _a !== void 0 ? _a : error.code) !== null && _b !== void 0 ? _b : undefined;
1143
+ this.reject((message) ? ({ message }) : undefined);
1144
+ });
1145
+ }
1146
+ /**
1147
+ * Notifies the system that the action has begun.
1148
+ */
1149
+ startWorking() {
1150
+ this._setWorking();
1151
+ this.delegate.startWorking();
1152
+ }
1153
+ /**
1154
+ * Sets success on the action.
1155
+ */
1156
+ success(result) {
1157
+ this._setComplete();
1158
+ this.delegate.success(result);
1159
+ }
1160
+ /**
1161
+ * Sets rejected on the action.
1162
+ */
1163
+ reject(error) {
1164
+ this._setComplete();
1165
+ this.delegate.reject(error);
1166
+ }
1167
+ destroy() {
1168
+ this._doneActionBegan = this.actionBegan;
1169
+ this._done = true;
1170
+ // Delay to prevent error.
1171
+ setTimeout(() => {
1172
+ this._actionBegan.complete();
1173
+ this._isComplete.complete();
1174
+ });
1175
+ }
1176
+ _setWorking() {
1177
+ if (this.actionBegan) {
1178
+ throw new Error('Action already has been triggered for this context.');
1179
+ }
1180
+ this._actionBegan.next(true);
1181
+ }
1182
+ _setComplete() {
1183
+ if (this.isComplete) {
1184
+ throw new Error('Action has already been marked as completed.');
1185
+ }
1186
+ this._isComplete.next(true);
1187
+ }
1188
+ }
1189
+ /**
1190
+ * Creates a function that uses a provider to always handle new values.
1191
+ */
1192
+ function handleWorkValueReadyWithConfigFn(providerFn) {
1193
+ return (value) => {
1194
+ const config = providerFn(value);
1195
+ return handleWorkValueReadyFn(config)(value);
1196
+ };
1197
+ }
1198
+ /**
1199
+ * Creates a function that handles the incoming value and creates a WorkHandlerContext.
1200
+ */
1201
+ function handleWorkValueReadyFn({ handlerFunction, delegate }) {
1202
+ return (value) => {
1203
+ const handler = new WorkHandlerContext(value, delegate);
1204
+ let fnResult;
1205
+ try {
1206
+ fnResult = handlerFunction(value, handler);
1207
+ }
1208
+ catch (e) {
1209
+ console.error('Action encountered an unexpected error.', e);
1210
+ handler.reject(e);
1211
+ return;
1212
+ }
1213
+ if (!handler.isComplete) {
1214
+ if (fnResult && isObservable(fnResult)) {
1215
+ if (handler.actionBegan) {
1216
+ throw new Error('Action already marked as begun from handlerFunction result. Either return an observable or use the handler directly.');
1217
+ }
1218
+ handler.startWorkingWithObservable(fnResult);
1219
+ }
1220
+ }
1221
+ return handler;
1222
+ };
1223
+ }
1224
+
1225
+ /**
1226
+ * Context used for defining a function that performs an action using the input function on ValueReady.
1227
+ */
1228
+ class DbNgxActionHandlerDirective extends AbstractSubscriptionDirective {
1229
+ constructor(source) {
1230
+ super();
1231
+ this.source = source;
1232
+ this._handlerFunction = new BehaviorSubject(undefined);
1233
+ this.handlerFunction$ = this._handlerFunction.pipe(filterMaybe(), shareReplay(1));
1234
+ this._delegate = new WorkHandlerContextSourceDelegate(this.source);
1235
+ }
1236
+ get handlerFunction() {
1237
+ return this._handlerFunction.value;
1238
+ }
1239
+ set handlerFunction(handlerFunction) {
1240
+ this._handlerFunction.next(handlerFunction);
1241
+ }
1242
+ ngOnInit() {
1243
+ this.sub = this.handlerFunction$.pipe(switchMap(handlerFunction => this.source.valueReady$.pipe(map((x) => [handlerFunction, x]), tap(([handlerFunction, value]) => {
1244
+ const context = handleWorkValueReadyFn({ handlerFunction, delegate: this._delegate })(value);
1245
+ if (context) {
1246
+ // Add the action to the lockSet for the source to prevent it from being destroyed until the action completes.
1247
+ this.source.lockSet.addLock('actionhandler', context.isComplete$.pipe(map(x => !x)));
1248
+ }
1249
+ })))).subscribe();
1250
+ }
1251
+ ngOnDestroy() {
1252
+ this.source.lockSet.onNextUnlock(() => {
1253
+ super.ngOnDestroy();
1254
+ });
1255
+ }
1256
+ }
1257
+ DbNgxActionHandlerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionHandlerDirective, deps: [{ token: ActionContextStoreSourceInstance, host: true }], target: i0.ɵɵFactoryTarget.Directive });
1258
+ DbNgxActionHandlerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionHandlerDirective, selector: "[dbxActionHandler]", inputs: { handlerFunction: ["dbxActionHandler", "handlerFunction"] }, usesInheritance: true, ngImport: i0 });
1259
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionHandlerDirective, decorators: [{
1260
+ type: Directive,
1261
+ args: [{
1262
+ selector: '[dbxActionHandler]',
1263
+ }]
1264
+ }], ctorParameters: function () {
1265
+ return [{ type: ActionContextStoreSourceInstance, decorators: [{
1266
+ type: Host
1267
+ }] }];
1268
+ }, propDecorators: { handlerFunction: [{
1269
+ type: Input,
1270
+ args: ['dbxActionHandler']
1271
+ }] } });
1272
+
1273
+ /**
1274
+ * Displays the input content when success is set.
1275
+ *
1276
+ * Can be configured to show for a limited time afterwards, etc.
1277
+ */
1278
+ class DbNgxActionSuccessComponent {
1279
+ constructor(source) {
1280
+ this.source = source;
1281
+ this.show$ = this.source.isSuccess$.pipe(exhaustMap((success) => {
1282
+ if (success) {
1283
+ if (this.hideAfter) {
1284
+ return of(false).pipe(delay(this.hideAfter), startWith(true));
1285
+ }
1286
+ else {
1287
+ return of(true);
1288
+ }
1289
+ }
1290
+ else {
1291
+ return of(false);
1292
+ }
1293
+ }), shareReplay(1));
1294
+ }
1295
+ }
1296
+ DbNgxActionSuccessComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionSuccessComponent, deps: [{ token: ActionContextStoreSourceInstance }], target: i0.ɵɵFactoryTarget.Component });
1297
+ DbNgxActionSuccessComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionSuccessComponent, selector: "dbx-action-success", inputs: { hideAfter: "hideAfter" }, ngImport: i0, template: `
1298
+ <ng-container *ngIf="show$ | async">
1299
+ <ng-content></ng-content>
1300
+ </ng-container>
1301
+ `, isInline: true, directives: [{ type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], pipes: { "async": i2.AsyncPipe } });
1302
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionSuccessComponent, decorators: [{
1303
+ type: Component,
1304
+ args: [{
1305
+ selector: 'dbx-action-success',
1306
+ template: `
1307
+ <ng-container *ngIf="show$ | async">
1308
+ <ng-content></ng-content>
1309
+ </ng-container>
1310
+ `
1311
+ }]
1312
+ }], ctorParameters: function () { return [{ type: ActionContextStoreSourceInstance }]; }, propDecorators: { hideAfter: [{
1313
+ type: Input
1314
+ }] } });
1315
+
1316
+ /**
1317
+ * Directive that executes a function on ActionContextStore Success.
1318
+ */
1319
+ class DbNgxActionSuccessDirective extends AbstractSubscriptionDirective {
1320
+ constructor(source) {
1321
+ super();
1322
+ this.source = source;
1323
+ this._successFunction = new BehaviorSubject(undefined);
1324
+ this.successFunction$ = this._successFunction.pipe(filterMaybe(), shareReplay(1));
1325
+ }
1326
+ get successFunction() {
1327
+ return this._successFunction.value;
1328
+ }
1329
+ set successFunction(successFunction) {
1330
+ this._successFunction.next(successFunction);
1331
+ }
1332
+ ngOnInit() {
1333
+ this.sub = this.successFunction$.pipe(switchMap(successFunction => this.source.success$.pipe(map(x => ([successFunction, x])), tap(([successFn, result]) => {
1334
+ successFn(result);
1335
+ })))).subscribe();
1336
+ }
1337
+ ngOnDestroy() {
1338
+ super.ngOnDestroy();
1339
+ this._successFunction.complete();
1340
+ }
1341
+ }
1342
+ DbNgxActionSuccessDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionSuccessDirective, deps: [{ token: ActionContextStoreSourceInstance, host: true }], target: i0.ɵɵFactoryTarget.Directive });
1343
+ DbNgxActionSuccessDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionSuccessDirective, selector: "[dbxActionSuccess]", inputs: { successFunction: ["dbxActionSuccess", "successFunction"] }, usesInheritance: true, ngImport: i0 });
1344
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionSuccessDirective, decorators: [{
1345
+ type: Directive,
1346
+ args: [{
1347
+ selector: '[dbxActionSuccess]',
1348
+ }]
1349
+ }], ctorParameters: function () {
1350
+ return [{ type: ActionContextStoreSourceInstance, decorators: [{
1351
+ type: Host
1352
+ }] }];
1353
+ }, propDecorators: { successFunction: [{
1354
+ type: Input,
1355
+ args: ['dbxActionSuccess']
1356
+ }] } });
1357
+
1358
+ /**
1359
+ * Directive that provides a default value when triggered.
1360
+ *
1361
+ * No value is required, allowing the directive to automatically call readyValue with undefined.
1362
+ */
1363
+ class DbNgxActionValueDirective extends AbstractSubscriptionDirective {
1364
+ constructor(source) {
1365
+ super();
1366
+ this.source = source;
1367
+ this._valueOrFunction = new BehaviorSubject(undefined);
1368
+ this.valueOrFunction$ = this._valueOrFunction.pipe(filterMaybe(), shareReplay(1));
1369
+ }
1370
+ get valueOrFunction() {
1371
+ return this._valueOrFunction.value;
1372
+ }
1373
+ set valueOrFunction(valueOrFunction) {
1374
+ this._valueOrFunction.next(valueOrFunction);
1375
+ }
1376
+ ngOnInit() {
1377
+ this.sub = this.valueOrFunction$.pipe(switchMap(valueOrFunction => this.source.triggered$.pipe(tap(() => {
1378
+ const value = getValueFromObjectOrGetter(valueOrFunction);
1379
+ this.source.readyValue(value);
1380
+ })))).subscribe();
1381
+ }
1382
+ ngOnDestroy() {
1383
+ super.ngOnDestroy();
1384
+ this._valueOrFunction.complete();
1385
+ }
1386
+ }
1387
+ DbNgxActionValueDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionValueDirective, deps: [{ token: ActionContextStoreSourceInstance, host: true }], target: i0.ɵɵFactoryTarget.Directive });
1388
+ DbNgxActionValueDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionValueDirective, selector: "[dbxActionValue]", inputs: { valueOrFunction: ["dbxActionValue", "valueOrFunction"] }, usesInheritance: true, ngImport: i0 });
1389
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionValueDirective, decorators: [{
1390
+ type: Directive,
1391
+ args: [{
1392
+ selector: '[dbxActionValue]',
1393
+ }]
1394
+ }], ctorParameters: function () {
1395
+ return [{ type: ActionContextStoreSourceInstance, decorators: [{
1396
+ type: Host
1397
+ }] }];
1398
+ }, propDecorators: { valueOrFunction: [{
1399
+ type: Input,
1400
+ args: ['dbxActionValue']
1401
+ }] } });
1402
+
1403
+ /**
1404
+ * Displays the input content when working is set.
1405
+ */
1406
+ class DbNgxActionWorkingComponent {
1407
+ constructor(source) {
1408
+ this.source = source;
1409
+ this.show$ = this.source.isWorking$;
1410
+ }
1411
+ }
1412
+ DbNgxActionWorkingComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionWorkingComponent, deps: [{ token: ActionContextStoreSourceInstance }], target: i0.ɵɵFactoryTarget.Component });
1413
+ DbNgxActionWorkingComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionWorkingComponent, selector: "dbx-action-working", ngImport: i0, template: `
1414
+ <ng-container *ngIf="show$ | async">
1415
+ <ng-content></ng-content>
1416
+ </ng-container>
1417
+ `, isInline: true, directives: [{ type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], pipes: { "async": i2.AsyncPipe } });
1418
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionWorkingComponent, decorators: [{
1419
+ type: Component,
1420
+ args: [{
1421
+ selector: 'dbx-action-working',
1422
+ template: `
1423
+ <ng-container *ngIf="show$ | async">
1424
+ <ng-content></ng-content>
1425
+ </ng-container>
1426
+ `
1427
+ }]
1428
+ }], ctorParameters: function () { return [{ type: ActionContextStoreSourceInstance }]; } });
1429
+
1430
+ const DEFAULT_SNACKBAR_DIRECTIVE_DURATION = ms('4s');
1431
+ const DEFAULT_SNACKBAR_UNDO_DIRECTIVE_DURATION = ms('30s');
1432
+ var ActionSnackbarDefaultType;
1433
+ (function (ActionSnackbarDefaultType) {
1434
+ ActionSnackbarDefaultType["NONE"] = "none";
1435
+ ActionSnackbarDefaultType["CREATE"] = "create";
1436
+ ActionSnackbarDefaultType["SAVE"] = "save";
1437
+ ActionSnackbarDefaultType["DELETE"] = "delete";
1438
+ ActionSnackbarDefaultType["MERGE"] = "merge";
1439
+ ActionSnackbarDefaultType["SEND"] = "send";
1440
+ ActionSnackbarDefaultType["CANCEL"] = "cancel";
1441
+ ActionSnackbarDefaultType["RESTORE"] = "restore";
1442
+ ActionSnackbarDefaultType["REFRESH"] = "refresh";
1443
+ ActionSnackbarDefaultType["MARK_READ"] = "read";
1444
+ ActionSnackbarDefaultType["MARK_UNREAD"] = "unread";
1445
+ })(ActionSnackbarDefaultType || (ActionSnackbarDefaultType = {}));
1446
+ var ActionSnackbarEventType;
1447
+ (function (ActionSnackbarEventType) {
1448
+ ActionSnackbarEventType[ActionSnackbarEventType["WORKING"] = 0] = "WORKING";
1449
+ ActionSnackbarEventType[ActionSnackbarEventType["SUCCESS"] = 1] = "SUCCESS";
1450
+ ActionSnackbarEventType[ActionSnackbarEventType["REJECTED"] = 2] = "REJECTED";
1451
+ })(ActionSnackbarEventType || (ActionSnackbarEventType = {}));
1452
+
1453
+ // export * from './snackbar.directive';
1454
+
1455
+ /**
1456
+ * Configurable machine that handles components of the ActionContextStore lifecycle.
1457
+ */
1458
+ class ActionContextMachine extends ActionContextBaseSource {
1459
+ constructor(config, source) {
1460
+ super(source);
1461
+ this.config = config;
1462
+ this._isShutdown = true;
1463
+ this._handleValueReadySub = new SubscriptionObject();
1464
+ // Handle Value Ready
1465
+ this._handleValueReadySub.subscription = this.sourceInstance.valueReady$.subscribe((value) => {
1466
+ handleWorkValueReadyFn({ handlerFunction: config.handleValueReady, delegate: new WorkHandlerContextSourceDelegate(this.sourceInstance) })(value);
1467
+ });
1468
+ // If this is a one-time use, then destroy it after the first success comes through.
1469
+ if (this.config.oneTimeUse) {
1470
+ this.sourceInstance.success$.pipe(first(), delay(1000)).subscribe(() => {
1471
+ this.destroy();
1472
+ });
1473
+ }
1474
+ if (this.config.onSuccess) {
1475
+ this.sourceInstance.success$.subscribe(this.config.onSuccess);
1476
+ }
1477
+ }
1478
+ destroy() {
1479
+ super.destroy();
1480
+ this._handleValueReadySub.destroy();
1481
+ this._isShutdown = true;
1482
+ }
1483
+ get isShutdown() {
1484
+ return this._isShutdown;
1485
+ }
1486
+ }
1487
+
1488
+ class DbNgxCoreActionModule {
1489
+ }
1490
+ DbNgxCoreActionModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreActionModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1491
+ DbNgxCoreActionModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreActionModule, declarations: [DbNgxActionComponent, DbNgxActionContextDirective, DbNgxActionContextMapDirective, DbNgxActionFromMapDirective, DbNgxActionMapSourceDirective,
1492
+ DbNgxActionMapWorkingDisableDirective, DbNgxActionSourceDirective, DbNgxActionHandlerDirective, DbNgxActionDisabledDirective, DbNgxActionDisabledUntilModifiedDirective,
1493
+ DbNgxActionAutoTriggerDirective, DbNgxActionAutoTriggerValueDirective, DbNgxActionAutoModifyDirective, DbNgxActionValueDirective, DbNgxActionContextLoggerDirective,
1494
+ DbNgxActionSuccessComponent, DbNgxActionSuccessDirective, DbNgxActionWorkingComponent], imports: [CommonModule], exports: [DbNgxActionComponent, DbNgxActionContextDirective, DbNgxActionContextMapDirective, DbNgxActionFromMapDirective, DbNgxActionMapSourceDirective,
1495
+ DbNgxActionMapWorkingDisableDirective, DbNgxActionSourceDirective, DbNgxActionHandlerDirective, DbNgxActionDisabledDirective, DbNgxActionDisabledUntilModifiedDirective,
1496
+ DbNgxActionAutoTriggerDirective, DbNgxActionAutoTriggerValueDirective, DbNgxActionAutoModifyDirective, DbNgxActionValueDirective, DbNgxActionContextLoggerDirective,
1497
+ DbNgxActionSuccessComponent, DbNgxActionSuccessDirective, DbNgxActionWorkingComponent] });
1498
+ DbNgxCoreActionModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreActionModule, imports: [[
1499
+ CommonModule
1500
+ ]] });
1501
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreActionModule, decorators: [{
1502
+ type: NgModule,
1503
+ args: [{
1504
+ imports: [
1505
+ CommonModule
1506
+ ],
1507
+ declarations: [
1508
+ DbNgxActionComponent, DbNgxActionContextDirective, DbNgxActionContextMapDirective, DbNgxActionFromMapDirective, DbNgxActionMapSourceDirective,
1509
+ DbNgxActionMapWorkingDisableDirective, DbNgxActionSourceDirective, DbNgxActionHandlerDirective, DbNgxActionDisabledDirective, DbNgxActionDisabledUntilModifiedDirective,
1510
+ DbNgxActionAutoTriggerDirective, DbNgxActionAutoTriggerValueDirective, DbNgxActionAutoModifyDirective, DbNgxActionValueDirective, DbNgxActionContextLoggerDirective,
1511
+ DbNgxActionSuccessComponent, DbNgxActionSuccessDirective, DbNgxActionWorkingComponent
1512
+ ],
1513
+ exports: [
1514
+ DbNgxActionComponent, DbNgxActionContextDirective, DbNgxActionContextMapDirective, DbNgxActionFromMapDirective, DbNgxActionMapSourceDirective,
1515
+ DbNgxActionMapWorkingDisableDirective, DbNgxActionSourceDirective, DbNgxActionHandlerDirective, DbNgxActionDisabledDirective, DbNgxActionDisabledUntilModifiedDirective,
1516
+ DbNgxActionAutoTriggerDirective, DbNgxActionAutoTriggerValueDirective, DbNgxActionAutoModifyDirective, DbNgxActionValueDirective, DbNgxActionContextLoggerDirective,
1517
+ DbNgxActionSuccessComponent, DbNgxActionSuccessDirective, DbNgxActionWorkingComponent
1518
+ ]
1519
+ }]
1520
+ }] });
1521
+
1522
+ class DbNgxButton {
1523
+ }
1524
+ function ProvideDbNgxButton(sourceType) {
1525
+ return [{
1526
+ provide: DbNgxButton,
1527
+ useExisting: sourceType
1528
+ }];
1529
+ }
1530
+
1531
+ /**
1532
+ * Context used for linking a button to an ActionContext and only look for triggers.
1533
+ */
1534
+ class DbNgxActionButtonTriggerDirective extends AbstractSubscriptionDirective {
1535
+ constructor(button, source) {
1536
+ super();
1537
+ this.button = button;
1538
+ this.source = source;
1539
+ }
1540
+ ngOnInit() {
1541
+ this.sub = this.button.clicked$.subscribe(() => {
1542
+ this._buttonClicked();
1543
+ });
1544
+ }
1545
+ _buttonClicked() {
1546
+ this.source.trigger();
1547
+ }
1548
+ }
1549
+ DbNgxActionButtonTriggerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionButtonTriggerDirective, deps: [{ token: DbNgxButton, host: true }, { token: ActionContextStoreSourceInstance }], target: i0.ɵɵFactoryTarget.Directive });
1550
+ DbNgxActionButtonTriggerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionButtonTriggerDirective, selector: "[dbxActionButtonTrigger]", usesInheritance: true, ngImport: i0 });
1551
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionButtonTriggerDirective, decorators: [{
1552
+ type: Directive,
1553
+ args: [{
1554
+ selector: '[dbxActionButtonTrigger]'
1555
+ }]
1556
+ }], ctorParameters: function () {
1557
+ return [{ type: DbNgxButton, decorators: [{
1558
+ type: Host
1559
+ }] }, { type: ActionContextStoreSourceInstance }];
1560
+ } });
1561
+
1562
+ /**
1563
+ * Context used for linking a button to an ActionContext.
1564
+ */
1565
+ class DbNgxActionButtonDirective extends DbNgxActionButtonTriggerDirective {
1566
+ constructor(button, source, ngZone) {
1567
+ super(button, source);
1568
+ this.ngZone = ngZone;
1569
+ this._workingSub = new SubscriptionObject();
1570
+ this._disabledSub = new SubscriptionObject();
1571
+ }
1572
+ ngOnInit() {
1573
+ super.ngOnInit();
1574
+ this._workingSub.subscription = this.source.isWorking$.subscribe((working) => {
1575
+ // console.log('Working: ', working);
1576
+ this.ngZone.run(() => this.button.working = working);
1577
+ });
1578
+ this._disabledSub.subscription = this.source.isDisabled$.subscribe((disabled) => {
1579
+ // console.log('Disabled: ', disabled);
1580
+ this.ngZone.run(() => this.button.disabled = disabled);
1581
+ });
1582
+ }
1583
+ ngOnDestroy() {
1584
+ super.ngOnDestroy();
1585
+ this._workingSub.destroy();
1586
+ this._disabledSub.destroy();
1587
+ }
1588
+ }
1589
+ DbNgxActionButtonDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionButtonDirective, deps: [{ token: DbNgxButton, host: true }, { token: ActionContextStoreSourceInstance }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
1590
+ DbNgxActionButtonDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxActionButtonDirective, selector: "[dbxActionButton]", usesInheritance: true, ngImport: i0 });
1591
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxActionButtonDirective, decorators: [{
1592
+ type: Directive,
1593
+ args: [{
1594
+ selector: '[dbxActionButton]'
1595
+ }]
1596
+ }], ctorParameters: function () {
1597
+ return [{ type: DbNgxButton, decorators: [{
1598
+ type: Host
1599
+ }] }, { type: ActionContextStoreSourceInstance }, { type: i0.NgZone }];
1600
+ } });
1601
+
1602
+ var AnchorType;
1603
+ (function (AnchorType) {
1604
+ AnchorType[AnchorType["None"] = 0] = "None";
1605
+ AnchorType[AnchorType["Clickable"] = 1] = "Clickable";
1606
+ AnchorType[AnchorType["Sref"] = 2] = "Sref";
1607
+ AnchorType[AnchorType["Href"] = 3] = "Href";
1608
+ AnchorType[AnchorType["Disabled"] = 4] = "Disabled";
1609
+ })(AnchorType || (AnchorType = {}));
1610
+ function anchorTypeForAnchor(anchor, disabled) {
1611
+ let type = AnchorType.Disabled;
1612
+ if (!disabled && anchor) {
1613
+ if (anchor.disabled) {
1614
+ type = AnchorType.Disabled;
1615
+ }
1616
+ else if (anchor.ref) {
1617
+ type = AnchorType.Sref;
1618
+ }
1619
+ else if (anchor.onClick) {
1620
+ type = AnchorType.Clickable;
1621
+ }
1622
+ else if (anchor.url) {
1623
+ type = AnchorType.Href;
1624
+ }
1625
+ }
1626
+ return type;
1627
+ }
1628
+ class DbNgxAnchor {
1629
+ }
1630
+ function ProvideDbNgxAnchor(sourceType) {
1631
+ return [{
1632
+ provide: DbNgxAnchor,
1633
+ useExisting: sourceType
1634
+ }];
1635
+ }
1636
+
1637
+ /**
1638
+ * Abstract anchor directive.
1639
+ */
1640
+ class AbstractDbNgxAnchorDirective {
1641
+ constructor() {
1642
+ this._disabled = new BehaviorSubject(false);
1643
+ this._anchor = new BehaviorSubject(undefined);
1644
+ this.disabled$ = this._disabled.asObservable();
1645
+ this.anchor$ = this._anchor.pipe(skipFirstMaybe(), distinctUntilChanged(), shareReplay(1));
1646
+ this.type$ = combineLatest([this.disabled$, this.anchor$]).pipe(map(([disabled, anchor]) => anchorTypeForAnchor(anchor, disabled)), distinctUntilChanged(), shareReplay(1));
1647
+ }
1648
+ get anchor() {
1649
+ return this._anchor.value;
1650
+ }
1651
+ set anchor(anchor) {
1652
+ this._anchor.next(anchor);
1653
+ }
1654
+ get disabled() {
1655
+ return this._disabled.value;
1656
+ }
1657
+ set disabled(disabled) {
1658
+ this._disabled.next(disabled);
1659
+ }
1660
+ }
1661
+ AbstractDbNgxAnchorDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AbstractDbNgxAnchorDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1662
+ AbstractDbNgxAnchorDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: AbstractDbNgxAnchorDirective, inputs: { anchor: "anchor", disabled: "disabled" }, ngImport: i0 });
1663
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AbstractDbNgxAnchorDirective, decorators: [{
1664
+ type: Directive
1665
+ }], propDecorators: { anchor: [{
1666
+ type: Input
1667
+ }], disabled: [{
1668
+ type: Input
1669
+ }] } });
1670
+
1671
+ var DbNgxRouterTransitionEventType;
1672
+ (function (DbNgxRouterTransitionEventType) {
1673
+ /**
1674
+ * A transition started.
1675
+ */
1676
+ DbNgxRouterTransitionEventType["START"] = "start";
1677
+ /**
1678
+ * A transition ended.
1679
+ */
1680
+ DbNgxRouterTransitionEventType["SUCCESS"] = "ended";
1681
+ })(DbNgxRouterTransitionEventType || (DbNgxRouterTransitionEventType = {}));
1682
+
1683
+ /**
1684
+ * AngularRouter implementation of DbNgxRouterService and DbNgxRouterTransitionService.
1685
+ */
1686
+ class DbNgxAngularRouterService {
1687
+ constructor(router, activatedRoute) {
1688
+ this.router = router;
1689
+ this.activatedRoute = activatedRoute;
1690
+ this.transitions$ = this.router.events.pipe(map((x) => {
1691
+ let event;
1692
+ if (x instanceof NavigationStart) {
1693
+ event = {
1694
+ type: DbNgxRouterTransitionEventType.START
1695
+ };
1696
+ }
1697
+ else if (x instanceof NavigationEnd) {
1698
+ event = {
1699
+ type: DbNgxRouterTransitionEventType.SUCCESS
1700
+ };
1701
+ }
1702
+ return event;
1703
+ }), filterMaybe());
1704
+ }
1705
+ go(segueRef) {
1706
+ let ref = segueRef.ref;
1707
+ if (isArray(ref)) {
1708
+ return this.router.navigate(ref, Object.assign(Object.assign({}, segueRef.refOptions), { queryParams: segueRef.refParams }));
1709
+ }
1710
+ else {
1711
+ return this.router.navigateByUrl(ref, Object.assign({}, segueRef.refOptions));
1712
+ }
1713
+ }
1714
+ }
1715
+ DbNgxAngularRouterService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxAngularRouterService, deps: [{ token: i1$1.Router }, { token: i1$1.ActivatedRoute }], target: i0.ɵɵFactoryTarget.Injectable });
1716
+ DbNgxAngularRouterService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxAngularRouterService });
1717
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxAngularRouterService, decorators: [{
1718
+ type: Injectable
1719
+ }], ctorParameters: function () { return [{ type: i1$1.Router }, { type: i1$1.ActivatedRoute }]; } });
1720
+
1721
+ /**
1722
+ * Router service definition that can route the app and provide routing details.
1723
+ */
1724
+ class DbNgxRouterService {
1725
+ }
1726
+
1727
+ /**
1728
+ * Router service definition that provides high level information about router transitions.
1729
+ */
1730
+ class DbNgxRouterTransitionService {
1731
+ }
1732
+
1733
+ class DbNgxCoreAngularRouterSegueModule {
1734
+ static forRoot() {
1735
+ return {
1736
+ ngModule: DbNgxCoreAngularRouterSegueModule,
1737
+ providers: [
1738
+ DbNgxAngularRouterService,
1739
+ {
1740
+ provide: DbNgxRouterService,
1741
+ useExisting: DbNgxAngularRouterService
1742
+ },
1743
+ {
1744
+ provide: DbNgxRouterTransitionService,
1745
+ useExisting: DbNgxAngularRouterService
1746
+ }
1747
+ ]
1748
+ };
1749
+ }
1750
+ }
1751
+ DbNgxCoreAngularRouterSegueModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreAngularRouterSegueModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1752
+ DbNgxCoreAngularRouterSegueModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreAngularRouterSegueModule });
1753
+ DbNgxCoreAngularRouterSegueModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreAngularRouterSegueModule });
1754
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreAngularRouterSegueModule, decorators: [{
1755
+ type: NgModule,
1756
+ args: [{}]
1757
+ }] });
1758
+
1759
+ /**
1760
+ * UIRouter implementation of DbNgxRouterService and DbNgxRouterTransitionService.
1761
+ */
1762
+ class DbNgxUIRouterService {
1763
+ constructor(state, transitionService, uiRouterGlobals) {
1764
+ this.state = state;
1765
+ this.transitionService = transitionService;
1766
+ this.uiRouterGlobals = uiRouterGlobals;
1767
+ this._transitions = new Subject();
1768
+ this.transitions$ = this._transitions.asObservable();
1769
+ const emitTransition = (type) => {
1770
+ this._transitions.next({
1771
+ type
1772
+ });
1773
+ };
1774
+ this.transitionService.onStart({}, () => {
1775
+ emitTransition(DbNgxRouterTransitionEventType.START);
1776
+ });
1777
+ this.transitionService.onSuccess({}, () => {
1778
+ emitTransition(DbNgxRouterTransitionEventType.SUCCESS);
1779
+ });
1780
+ }
1781
+ go(segueRef) {
1782
+ const params = Object.assign(Object.assign({}, this.uiRouterGlobals.current.params), segueRef.refParams);
1783
+ return this.state.go(segueRef.ref, params, segueRef.refOptions).then(_ => true).catch(_ => false);
1784
+ }
1785
+ }
1786
+ DbNgxUIRouterService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxUIRouterService, deps: [{ token: i1$2.StateService }, { token: i1$2.TransitionService }, { token: i1$2.UIRouterGlobals }], target: i0.ɵɵFactoryTarget.Injectable });
1787
+ DbNgxUIRouterService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxUIRouterService });
1788
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxUIRouterService, decorators: [{
1789
+ type: Injectable
1790
+ }], ctorParameters: function () { return [{ type: i1$2.StateService }, { type: i1$2.TransitionService }, { type: i1$2.UIRouterGlobals }]; } });
1791
+
1792
+ class DbNgxCoreUIRouterSegueModule {
1793
+ static forRoot() {
1794
+ return {
1795
+ ngModule: DbNgxCoreUIRouterSegueModule,
1796
+ providers: [
1797
+ DbNgxUIRouterService,
1798
+ {
1799
+ provide: DbNgxRouterService,
1800
+ useExisting: DbNgxUIRouterService
1801
+ },
1802
+ {
1803
+ provide: DbNgxRouterTransitionService,
1804
+ useExisting: DbNgxUIRouterService
1805
+ }
1806
+ ]
1807
+ };
1808
+ }
1809
+ }
1810
+ DbNgxCoreUIRouterSegueModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreUIRouterSegueModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1811
+ DbNgxCoreUIRouterSegueModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreUIRouterSegueModule });
1812
+ DbNgxCoreUIRouterSegueModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreUIRouterSegueModule });
1813
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreUIRouterSegueModule, decorators: [{
1814
+ type: NgModule,
1815
+ args: [{}]
1816
+ }] });
1817
+
1818
+ /**
1819
+ * Abstract directive that listens to onSuccess transition events and runs a function.
1820
+ */
1821
+ class AbstractTransitionWatcherDirective {
1822
+ constructor(dbNgxRouterTransitionService, ngZone) {
1823
+ this.dbNgxRouterTransitionService = dbNgxRouterTransitionService;
1824
+ this.ngZone = ngZone;
1825
+ this._transitionSub = new SubscriptionObject();
1826
+ }
1827
+ ngOnInit() {
1828
+ this._transitionSub.subscription = this.dbNgxRouterTransitionService.transitions$.pipe(filter(x => x.type === DbNgxRouterTransitionEventType.SUCCESS)).subscribe(() => {
1829
+ this.updateForSuccessfulTransition();
1830
+ });
1831
+ }
1832
+ ngOnDestroy() {
1833
+ this._transitionSub.destroy();
1834
+ }
1835
+ // MARK: Action
1836
+ zoneUpdateForSuccessfulTransition() {
1837
+ this.ngZone.run(() => this.updateForSuccessfulTransition());
1838
+ }
1839
+ }
1840
+ AbstractTransitionWatcherDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AbstractTransitionWatcherDirective, deps: [{ token: DbNgxRouterTransitionService }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
1841
+ AbstractTransitionWatcherDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: AbstractTransitionWatcherDirective, ngImport: i0 });
1842
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AbstractTransitionWatcherDirective, decorators: [{
1843
+ type: Directive
1844
+ }], ctorParameters: function () { return [{ type: DbNgxRouterTransitionService }, { type: i0.NgZone }]; } });
1845
+
1846
+ function refStringToSegueRef(ref, options) {
1847
+ return Object.assign(Object.assign({}, options), { ref });
1848
+ }
1849
+ function mapRefStringObsToSegueRefObs(obs, options) {
1850
+ return obs.pipe(map(x => refStringToSegueRef(x, options)));
1851
+ }
1852
+
1853
+ // MARK: Button Directives
1854
+ class DbNgxButtonSegueDirective extends AbstractSubscriptionDirective {
1855
+ constructor(dbxButton, dbxRouterService) {
1856
+ super();
1857
+ this.dbxButton = dbxButton;
1858
+ this.dbxRouterService = dbxRouterService;
1859
+ this._segueRef = new BehaviorSubject(undefined);
1860
+ this.segueRef$ = this._segueRef.pipe(filterMaybe(), distinctUntilChanged(), shareReplay(1));
1861
+ }
1862
+ get segueRef() {
1863
+ return this._segueRef.value;
1864
+ }
1865
+ set segueRef(segueRef) {
1866
+ this._segueRef.next(segueRef);
1867
+ }
1868
+ ngOnInit() {
1869
+ this.sub = this.segueRef$.pipe(switchMap(segueRef => this.dbxButton.clicked$.pipe(tap(() => {
1870
+ this.dbxRouterService.go(segueRef);
1871
+ })))).subscribe();
1872
+ }
1873
+ }
1874
+ DbNgxButtonSegueDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxButtonSegueDirective, deps: [{ token: DbNgxButton }, { token: DbNgxRouterService }], target: i0.ɵɵFactoryTarget.Directive });
1875
+ DbNgxButtonSegueDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxButtonSegueDirective, selector: "[dbxButtonSegue]", inputs: { segueRef: ["dbxButtonSegue", "segueRef"] }, usesInheritance: true, ngImport: i0 });
1876
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxButtonSegueDirective, decorators: [{
1877
+ type: Directive,
1878
+ args: [{
1879
+ selector: '[dbxButtonSegue]'
1880
+ }]
1881
+ }], ctorParameters: function () { return [{ type: DbNgxButton }, { type: DbNgxRouterService }]; }, propDecorators: { segueRef: [{
1882
+ type: Input,
1883
+ args: ['dbxButtonSegue']
1884
+ }] } });
1885
+
1886
+ /**
1887
+ * Abstract button component.
1888
+ */
1889
+ class AbstractDbNgxButtonDirective extends AbstractSubscriptionDirective {
1890
+ constructor() {
1891
+ super();
1892
+ this._disabled = new BehaviorSubject(false);
1893
+ this._working = new BehaviorSubject(false);
1894
+ this.disabled$ = this._disabled.asObservable();
1895
+ this.working$ = this._working.asObservable();
1896
+ this.buttonClick = new EventEmitter();
1897
+ this.clicked$ = this.buttonClick.asObservable();
1898
+ /**
1899
+ * Pre-interceptor button click.
1900
+ */
1901
+ this._buttonClick = new Subject();
1902
+ this._buttonInterceptor = new BehaviorSubject(undefined);
1903
+ }
1904
+ get disabled() {
1905
+ return this._disabled.value;
1906
+ }
1907
+ set disabled(disabled) {
1908
+ this._disabled.next(disabled);
1909
+ }
1910
+ get working() {
1911
+ return this._working.value;
1912
+ }
1913
+ set working(working) {
1914
+ this._working.next(working);
1915
+ }
1916
+ ngOnInit() {
1917
+ this.sub = this._buttonClick.pipe(switchMap(() => this._buttonInterceptor.pipe(switchMap((x) => {
1918
+ if (x) {
1919
+ return x.interceptButtonClick().pipe(first());
1920
+ }
1921
+ else {
1922
+ return of(true);
1923
+ }
1924
+ }), filter((x) => Boolean(x)) // Ignore false values.
1925
+ ))).subscribe(() => {
1926
+ this._forceButtonClicked();
1927
+ });
1928
+ }
1929
+ ngOnDestroy() {
1930
+ super.ngOnDestroy();
1931
+ this._disabled.complete();
1932
+ this._working.complete();
1933
+ this._buttonClick.complete();
1934
+ this._buttonInterceptor.complete();
1935
+ }
1936
+ /**
1937
+ * Sets the button interceptor. If any interceptor is already set, it is replaced.
1938
+ */
1939
+ setButtonInterceptor(interceptor) {
1940
+ this._buttonInterceptor.next(interceptor);
1941
+ }
1942
+ /**
1943
+ * Main function to use for handling clicks on the button.
1944
+ */
1945
+ clickButton() {
1946
+ if (!this.disabled) {
1947
+ this._buttonClick.next();
1948
+ }
1949
+ }
1950
+ /**
1951
+ * Forces a button click. Skips the interceptors if any are configured.
1952
+ */
1953
+ _forceButtonClicked() {
1954
+ this.buttonClick.emit();
1955
+ }
1956
+ }
1957
+ AbstractDbNgxButtonDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AbstractDbNgxButtonDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1958
+ AbstractDbNgxButtonDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: AbstractDbNgxButtonDirective, inputs: { disabled: "disabled", working: "working", icon: "icon", text: "text" }, outputs: { buttonClick: "buttonClick" }, usesInheritance: true, ngImport: i0 });
1959
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AbstractDbNgxButtonDirective, decorators: [{
1960
+ type: Directive
1961
+ }], ctorParameters: function () { return []; }, propDecorators: { disabled: [{
1962
+ type: Input
1963
+ }], working: [{
1964
+ type: Input
1965
+ }], icon: [{
1966
+ type: Input
1967
+ }], text: [{
1968
+ type: Input
1969
+ }], buttonClick: [{
1970
+ type: Output
1971
+ }] } });
1972
+ // MARK: Implementation
1973
+ /**
1974
+ * Provides an DbNgxButton directive.
1975
+ */
1976
+ class DbNgxButtonDirective extends AbstractDbNgxButtonDirective {
1977
+ }
1978
+ DbNgxButtonDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxButtonDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
1979
+ DbNgxButtonDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxButtonDirective, selector: "[dbxButton]", providers: ProvideDbNgxButton(DbNgxButtonDirective), exportAs: ["dbxButton"], usesInheritance: true, ngImport: i0 });
1980
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxButtonDirective, decorators: [{
1981
+ type: Directive,
1982
+ args: [{
1983
+ selector: '[dbxButton]',
1984
+ exportAs: 'dbxButton',
1985
+ providers: ProvideDbNgxButton(DbNgxButtonDirective)
1986
+ }]
1987
+ }] });
1988
+
1989
+ /**
1990
+ * Context used for linking a button to a LoadingContext.
1991
+ *
1992
+ * It will be set working when the context is set loading.
1993
+ */
1994
+ class DbNgxLoadingButtonDirective extends AbstractSubscriptionDirective {
1995
+ constructor(button, ngZone) {
1996
+ super();
1997
+ this.button = button;
1998
+ this.ngZone = ngZone;
1999
+ }
2000
+ /**
2001
+ * Sets a LoadingContext that is watched for the loading state.
2002
+ */
2003
+ set context(context) {
2004
+ let subscription;
2005
+ if (context) {
2006
+ subscription = context.stream$.subscribe((x) => {
2007
+ this.ngZone.run(() => this.button.working = x.loading);
2008
+ });
2009
+ }
2010
+ this.sub = subscription;
2011
+ }
2012
+ }
2013
+ DbNgxLoadingButtonDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxLoadingButtonDirective, deps: [{ token: DbNgxButton, host: true }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
2014
+ DbNgxLoadingButtonDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxLoadingButtonDirective, selector: "[dbxLoadingButton]", inputs: { context: ["dbxLoadingButton", "context"] }, usesInheritance: true, ngImport: i0 });
2015
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxLoadingButtonDirective, decorators: [{
2016
+ type: Directive,
2017
+ args: [{
2018
+ selector: '[dbxLoadingButton]'
2019
+ }]
2020
+ }], ctorParameters: function () {
2021
+ return [{ type: DbNgxButton, decorators: [{
2022
+ type: Host
2023
+ }] }, { type: i0.NgZone }];
2024
+ }, propDecorators: { context: [{
2025
+ type: Input,
2026
+ args: ['dbxLoadingButton']
2027
+ }] } });
2028
+
2029
+ class DbNgxCoreButtonModule {
2030
+ }
2031
+ DbNgxCoreButtonModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreButtonModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2032
+ DbNgxCoreButtonModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreButtonModule, declarations: [DbNgxButtonDirective,
2033
+ DbNgxLoadingButtonDirective,
2034
+ DbNgxActionButtonTriggerDirective,
2035
+ DbNgxActionButtonDirective,
2036
+ DbNgxButtonSegueDirective], exports: [DbNgxButtonDirective,
2037
+ DbNgxLoadingButtonDirective,
2038
+ DbNgxActionButtonTriggerDirective,
2039
+ DbNgxActionButtonDirective,
2040
+ DbNgxButtonSegueDirective] });
2041
+ DbNgxCoreButtonModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreButtonModule, imports: [[]] });
2042
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxCoreButtonModule, decorators: [{
2043
+ type: NgModule,
2044
+ args: [{
2045
+ imports: [],
2046
+ declarations: [
2047
+ DbNgxButtonDirective,
2048
+ DbNgxLoadingButtonDirective,
2049
+ DbNgxActionButtonTriggerDirective,
2050
+ DbNgxActionButtonDirective,
2051
+ DbNgxButtonSegueDirective
2052
+ ],
2053
+ exports: [
2054
+ DbNgxButtonDirective,
2055
+ DbNgxLoadingButtonDirective,
2056
+ DbNgxActionButtonTriggerDirective,
2057
+ DbNgxActionButtonDirective,
2058
+ DbNgxButtonSegueDirective
2059
+ ],
2060
+ }]
2061
+ }] });
2062
+
2063
+ /**
2064
+ * Pipe that takes in a date and number of minutes and outputs a formatted date.
2065
+ */
2066
+ class DateFromToTimePipe {
2067
+ constructor(locale) {
2068
+ this.locale = locale;
2069
+ }
2070
+ transform(input, format, minutes) {
2071
+ return DateFromToTimePipe.formatFromTo(input, format, minutes, this.locale);
2072
+ }
2073
+ static formatFromTo(input, format, minutes, locale) {
2074
+ if (input) {
2075
+ const date = toJsDate(input);
2076
+ const endDate = addMinutes(date, minutes);
2077
+ const dateString = formatDate(date, format, locale);
2078
+ return dateString + ' - ' + formatToTimeString(endDate);
2079
+ }
2080
+ return undefined;
2081
+ }
2082
+ }
2083
+ DateFromToTimePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DateFromToTimePipe, deps: [{ token: LOCALE_ID }], target: i0.ɵɵFactoryTarget.Pipe });
2084
+ DateFromToTimePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DateFromToTimePipe, name: "dateFromPlusTo" });
2085
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DateFromToTimePipe, decorators: [{
2086
+ type: Pipe,
2087
+ args: [{ name: 'dateFromPlusTo' }]
2088
+ }], ctorParameters: function () {
2089
+ return [{ type: undefined, decorators: [{
2090
+ type: Inject,
2091
+ args: [LOCALE_ID]
2092
+ }] }];
2093
+ } });
2094
+
2095
+ class MinutesStringPipe {
2096
+ transform(input) {
2097
+ const minutes = Number(input);
2098
+ if (input != null && !isNaN(minutes)) {
2099
+ if (minutes > 3600) {
2100
+ const unrounded = minutes / 3600;
2101
+ const days = Math.ceil(unrounded);
2102
+ return ((unrounded !== days) ? '~' : '') + days + ' days';
2103
+ }
2104
+ else if (minutes > 180) {
2105
+ const unrounded = minutes / 60;
2106
+ const hours = Math.ceil(unrounded);
2107
+ return ((unrounded !== hours) ? '~' : '') + hours + ' hours';
2108
+ }
2109
+ else {
2110
+ return minutes + ' minutes';
2111
+ }
2112
+ }
2113
+ else {
2114
+ return undefined;
2115
+ }
2116
+ }
2117
+ }
2118
+ MinutesStringPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: MinutesStringPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
2119
+ MinutesStringPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: MinutesStringPipe, name: "minutesString", pure: false });
2120
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: MinutesStringPipe, decorators: [{
2121
+ type: Pipe,
2122
+ args: [{ name: 'minutesString', pure: false }]
2123
+ }] });
2124
+
2125
+ class ToJsDatePipe {
2126
+ static toJsDate(input) {
2127
+ return (input) ? toJsDate(input) : undefined;
2128
+ }
2129
+ transform(input) {
2130
+ return ToJsDatePipe.toJsDate(input);
2131
+ }
2132
+ }
2133
+ ToJsDatePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: ToJsDatePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
2134
+ ToJsDatePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: ToJsDatePipe, name: "toJsDate" });
2135
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: ToJsDatePipe, decorators: [{
2136
+ type: Pipe,
2137
+ args: [{ name: 'toJsDate' }]
2138
+ }] });
2139
+
2140
+ class TimeDistanceCountdownPipe {
2141
+ transform(input, soonString = 'Soon', unavailable = 'Not Available') {
2142
+ if (input) {
2143
+ const from = ToJsDatePipe.toJsDate(input);
2144
+ if (isPast(from)) {
2145
+ return soonString;
2146
+ }
2147
+ else {
2148
+ const to = new Date();
2149
+ return formatDistance(from, to, {
2150
+ addSuffix: true
2151
+ });
2152
+ }
2153
+ }
2154
+ else {
2155
+ return unavailable;
2156
+ }
2157
+ }
2158
+ }
2159
+ TimeDistanceCountdownPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: TimeDistanceCountdownPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
2160
+ TimeDistanceCountdownPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: TimeDistanceCountdownPipe, name: "timeCountdownDistance", pure: false });
2161
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: TimeDistanceCountdownPipe, decorators: [{
2162
+ type: Pipe,
2163
+ args: [{ name: 'timeCountdownDistance', pure: false }]
2164
+ }] });
2165
+ class TimeDistancePipe {
2166
+ transform(input, to = new Date(), unavailable = 'Not Available') {
2167
+ if (input) {
2168
+ const from = ToJsDatePipe.toJsDate(input);
2169
+ return formatDistance(from, to, {
2170
+ addSuffix: true
2171
+ });
2172
+ }
2173
+ else {
2174
+ return unavailable;
2175
+ }
2176
+ }
2177
+ }
2178
+ TimeDistancePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: TimeDistancePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
2179
+ TimeDistancePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: TimeDistancePipe, name: "timeDistance", pure: false });
2180
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: TimeDistancePipe, decorators: [{
2181
+ type: Pipe,
2182
+ args: [{ name: 'timeDistance', pure: false }]
2183
+ }] });
2184
+
2185
+ class ToMinutesPipe {
2186
+ transform(milliseconds) {
2187
+ if (milliseconds) {
2188
+ return Math.floor(milliseconds / (60 * 1000));
2189
+ }
2190
+ return milliseconds;
2191
+ }
2192
+ }
2193
+ ToMinutesPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: ToMinutesPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
2194
+ ToMinutesPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: ToMinutesPipe, name: "toMinutes" });
2195
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: ToMinutesPipe, decorators: [{
2196
+ type: Pipe,
2197
+ args: [{ name: 'toMinutes' }]
2198
+ }] });
2199
+
2200
+ /**
2201
+ * Pipe that takes in a date and appends the distance to it in parenthesis.
2202
+ */
2203
+ class DateFormatDistancePipe {
2204
+ constructor(locale) {
2205
+ this.locale = locale;
2206
+ }
2207
+ transform(input, format, includeSeconds = false) {
2208
+ if (input) {
2209
+ const date = toJsDate(input);
2210
+ if (isValid(date)) {
2211
+ const dateString = formatDate(date, format, this.locale);
2212
+ const distance = formatDistanceToNow(date, {
2213
+ includeSeconds,
2214
+ addSuffix: true
2215
+ });
2216
+ return `${dateString} (${distance})`;
2217
+ }
2218
+ }
2219
+ return undefined;
2220
+ }
2221
+ }
2222
+ DateFormatDistancePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DateFormatDistancePipe, deps: [{ token: LOCALE_ID }], target: i0.ɵɵFactoryTarget.Pipe });
2223
+ DateFormatDistancePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DateFormatDistancePipe, name: "dateFormatDistance", pure: false });
2224
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DateFormatDistancePipe, decorators: [{
2225
+ type: Pipe,
2226
+ args: [{ name: 'dateFormatDistance', pure: false }]
2227
+ }], ctorParameters: function () {
2228
+ return [{ type: undefined, decorators: [{
2229
+ type: Inject,
2230
+ args: [LOCALE_ID]
2231
+ }] }];
2232
+ } });
2233
+
2234
+ class DateDistancePipe {
2235
+ transform(input, to, unavailable = 'Not Available') {
2236
+ if (input) {
2237
+ const defaultTo = !to;
2238
+ if (defaultTo) {
2239
+ to = new Date();
2240
+ }
2241
+ const from = ToJsDatePipe.toJsDate(input);
2242
+ const fromStart = startOfDay(from);
2243
+ const toStart = startOfDay(to);
2244
+ if (isSameDay(fromStart, toStart)) {
2245
+ let text;
2246
+ if (defaultTo || isSameDay(from, new Date())) {
2247
+ text = 'Today';
2248
+ }
2249
+ else {
2250
+ text = 'Same Day';
2251
+ }
2252
+ return text;
2253
+ }
2254
+ else {
2255
+ return formatDistance(fromStart, toStart, {
2256
+ addSuffix: true
2257
+ });
2258
+ }
2259
+ }
2260
+ else {
2261
+ return unavailable;
2262
+ }
2263
+ }
2264
+ }
2265
+ DateDistancePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DateDistancePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
2266
+ DateDistancePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DateDistancePipe, name: "dateDistance", pure: false });
2267
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DateDistancePipe, decorators: [{
2268
+ type: Pipe,
2269
+ args: [{ name: 'dateDistance', pure: false }]
2270
+ }] });
2271
+
2272
+ class DbNgxDatePipeModule {
2273
+ }
2274
+ DbNgxDatePipeModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxDatePipeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2275
+ DbNgxDatePipeModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxDatePipeModule, declarations: [DateFromToTimePipe,
2276
+ DateFormatDistancePipe,
2277
+ MinutesStringPipe,
2278
+ TimeDistanceCountdownPipe,
2279
+ TimeDistancePipe,
2280
+ DateDistancePipe,
2281
+ ToJsDatePipe,
2282
+ ToMinutesPipe], exports: [DateFromToTimePipe,
2283
+ DateFormatDistancePipe,
2284
+ MinutesStringPipe,
2285
+ TimeDistanceCountdownPipe,
2286
+ TimeDistancePipe,
2287
+ DateDistancePipe,
2288
+ ToJsDatePipe,
2289
+ ToMinutesPipe] });
2290
+ DbNgxDatePipeModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxDatePipeModule });
2291
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxDatePipeModule, decorators: [{
2292
+ type: NgModule,
2293
+ args: [{
2294
+ exports: [
2295
+ DateFromToTimePipe,
2296
+ DateFormatDistancePipe,
2297
+ MinutesStringPipe,
2298
+ TimeDistanceCountdownPipe,
2299
+ TimeDistancePipe,
2300
+ DateDistancePipe,
2301
+ ToJsDatePipe,
2302
+ ToMinutesPipe
2303
+ ],
2304
+ declarations: [
2305
+ DateFromToTimePipe,
2306
+ DateFormatDistancePipe,
2307
+ MinutesStringPipe,
2308
+ TimeDistanceCountdownPipe,
2309
+ TimeDistancePipe,
2310
+ DateDistancePipe,
2311
+ ToJsDatePipe,
2312
+ ToMinutesPipe
2313
+ ]
2314
+ }]
2315
+ }] });
2316
+
2317
+ /**
2318
+ * Instance used by components to inject content based on the configuration into the view.
2319
+ */
2320
+ class DbNgxInjectedComponentInstance {
2321
+ constructor() {
2322
+ this._subscriptionObject = new SubscriptionObject();
2323
+ this._config = new BehaviorSubject(undefined);
2324
+ this._template = new BehaviorSubject(undefined);
2325
+ this._content = new BehaviorSubject(undefined);
2326
+ this._componentRef = new BehaviorSubject(undefined);
2327
+ this.config$ = this._config.pipe(distinctUntilChanged());
2328
+ this.template$ = this._template.pipe(distinctUntilChanged());
2329
+ this.content$ = this._content.pipe(filterMaybe(), distinctUntilChanged(), shareReplay(1));
2330
+ }
2331
+ get config() {
2332
+ return this._config.value;
2333
+ }
2334
+ set config(config) {
2335
+ this._config.next(config);
2336
+ }
2337
+ get template() {
2338
+ return this._template.value;
2339
+ }
2340
+ set template(template) {
2341
+ this._template.next(template);
2342
+ }
2343
+ get content() {
2344
+ return this._content.value;
2345
+ }
2346
+ set content(content) {
2347
+ this._content.next(content);
2348
+ }
2349
+ get componentRef() {
2350
+ return this._componentRef.value;
2351
+ }
2352
+ set componentRef(componentRef) {
2353
+ this._componentRef.next(componentRef);
2354
+ }
2355
+ init() {
2356
+ // Wait until the first of either of the two inputs comes in as not defined, and then emit.
2357
+ // We filter the first maybe here between the two items.
2358
+ const configTemplateObs = combineLatest([this.config$, this.template$]).pipe(map(([config, template]) => {
2359
+ if (config || template) {
2360
+ return {
2361
+ config,
2362
+ template
2363
+ };
2364
+ }
2365
+ else {
2366
+ return undefined;
2367
+ }
2368
+ }), skipFirstMaybe());
2369
+ this._subscriptionObject.subscription = combineLatest([configTemplateObs, this.content$]).subscribe(([inputConfig, content]) => {
2370
+ const { config, template } = inputConfig !== null && inputConfig !== void 0 ? inputConfig : {};
2371
+ this._reset(content);
2372
+ if (config) {
2373
+ this._initComponent(config, content);
2374
+ }
2375
+ else if (template) {
2376
+ this._initTemplate(template, content);
2377
+ }
2378
+ });
2379
+ }
2380
+ destroy() {
2381
+ this._config.complete();
2382
+ this._template.complete();
2383
+ this._content.complete();
2384
+ this._componentRef.complete();
2385
+ }
2386
+ _initComponent(config, content) {
2387
+ content.clear();
2388
+ const { init, injector, componentClass } = config;
2389
+ const componentRef = content.createComponent(componentClass, { injector });
2390
+ const instance = componentRef.instance;
2391
+ if (init) {
2392
+ init(instance);
2393
+ }
2394
+ this.componentRef = componentRef;
2395
+ }
2396
+ _initTemplate(config, content) {
2397
+ content.clear();
2398
+ const { templateRef, viewRef } = config;
2399
+ if (templateRef) {
2400
+ content.createEmbeddedView(templateRef);
2401
+ // TODO: Figure out if these items need to be destroyed or not when this item is destroyed. If so, we need a reference to destroy.
2402
+ }
2403
+ else if (viewRef) {
2404
+ content.insert(viewRef);
2405
+ }
2406
+ }
2407
+ _reset(content) {
2408
+ if (this.componentRef) {
2409
+ content.clear();
2410
+ this.componentRef = undefined;
2411
+ }
2412
+ }
2413
+ }
2414
+
2415
+ /**
2416
+ * Abstract directive that injects content based on the configuration into the view.
2417
+ */
2418
+ class AbstractDbNgxInjectedDirective {
2419
+ constructor() {
2420
+ this._instance = new DbNgxInjectedComponentInstance();
2421
+ }
2422
+ ngOnInit() {
2423
+ this._instance.init();
2424
+ }
2425
+ ngOnDestroy() {
2426
+ this._instance.destroy();
2427
+ }
2428
+ setConfig(config) {
2429
+ this._instance.config = config;
2430
+ }
2431
+ setTemplate(template) {
2432
+ this._instance.template = template;
2433
+ }
2434
+ setContent(content) {
2435
+ this._instance.content = content;
2436
+ }
2437
+ }
2438
+ AbstractDbNgxInjectedDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AbstractDbNgxInjectedDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
2439
+ AbstractDbNgxInjectedDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.0", type: AbstractDbNgxInjectedDirective, ngImport: i0 });
2440
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AbstractDbNgxInjectedDirective, decorators: [{
2441
+ type: Directive
2442
+ }] });
2443
+
2444
+ /**
2445
+ * Component that injects content based on the configuration into the view.
2446
+ */
2447
+ class DbNgxInjectedComponent extends AbstractDbNgxInjectedDirective {
2448
+ set config(config) {
2449
+ this.setConfig(config);
2450
+ }
2451
+ set template(template) {
2452
+ this.setTemplate(template);
2453
+ }
2454
+ set content(content) {
2455
+ this.setContent(content);
2456
+ }
2457
+ }
2458
+ DbNgxInjectedComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxInjectedComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
2459
+ DbNgxInjectedComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.0", type: DbNgxInjectedComponent, selector: "dbx-injected-content, [dbx-injected-content]", inputs: { config: "config", template: "template" }, viewQueries: [{ propertyName: "content", first: true, predicate: ["content"], descendants: true, read: ViewContainerRef, static: true }], usesInheritance: true, ngImport: i0, template: `<ng-template #content></ng-template>`, isInline: true });
2460
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxInjectedComponent, decorators: [{
2461
+ type: Component,
2462
+ args: [{
2463
+ selector: 'dbx-injected-content, [dbx-injected-content]',
2464
+ template: `<ng-template #content></ng-template>`
2465
+ }]
2466
+ }], propDecorators: { config: [{
2467
+ type: Input
2468
+ }], template: [{
2469
+ type: Input
2470
+ }], content: [{
2471
+ type: ViewChild,
2472
+ args: ['content', { static: true, read: ViewContainerRef }]
2473
+ }] } });
2474
+
2475
+ class DbNgxInjectedComponentModule {
2476
+ }
2477
+ DbNgxInjectedComponentModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxInjectedComponentModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2478
+ DbNgxInjectedComponentModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxInjectedComponentModule, declarations: [DbNgxInjectedComponent], imports: [CommonModule], exports: [DbNgxInjectedComponent] });
2479
+ DbNgxInjectedComponentModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxInjectedComponentModule, imports: [[
2480
+ CommonModule
2481
+ ]] });
2482
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: DbNgxInjectedComponentModule, decorators: [{
2483
+ type: NgModule,
2484
+ args: [{
2485
+ imports: [
2486
+ CommonModule
2487
+ ],
2488
+ declarations: [
2489
+ DbNgxInjectedComponent
2490
+ ],
2491
+ exports: [
2492
+ DbNgxInjectedComponent
2493
+ ],
2494
+ }]
2495
+ }] });
2496
+
2497
+ class StringifySimpleStorageAccessorConverter {
2498
+ stringifyValue(value) {
2499
+ return JSON.stringify(value);
2500
+ }
2501
+ parseValue(data) {
2502
+ return JSON.parse(data);
2503
+ }
2504
+ }
2505
+ class WrapperSimpleStorageAccessorDelegate {
2506
+ constructor(_delegate, _converter) {
2507
+ this._delegate = _delegate;
2508
+ this._converter = _converter;
2509
+ }
2510
+ get(key) {
2511
+ return this._delegate.get(key);
2512
+ }
2513
+ set(key, value) {
2514
+ return this._delegate.set(key, value);
2515
+ }
2516
+ remove(key) {
2517
+ return this._delegate.remove(key);
2518
+ }
2519
+ clear() {
2520
+ return this._delegate.clear();
2521
+ }
2522
+ all(prefix) {
2523
+ return this._delegate.all(prefix);
2524
+ }
2525
+ allKeys(prefix) {
2526
+ return this._delegate.allKeys(prefix);
2527
+ }
2528
+ stringifyValue(value) {
2529
+ return this._converter.stringifyValue(value);
2530
+ }
2531
+ parseValue(data) {
2532
+ return this._converter.parseValue(data);
2533
+ }
2534
+ }
2535
+ /**
2536
+ * LimitedStorageAccessor implementation that uses a Delegate
2537
+ */
2538
+ class SimpleStorageAccessor {
2539
+ constructor(_delegate, config) {
2540
+ var _a;
2541
+ this._delegate = _delegate;
2542
+ const prefix = config.prefix;
2543
+ const prefixSplitter = (_a = config.prefixSplitter) !== null && _a !== void 0 ? _a : SimpleStorageAccessor.PREFIX_SPLITTER;
2544
+ this.assertValidStorageKeyPrefix(prefix, prefixSplitter);
2545
+ const fullPrefix = `${prefix}${prefixSplitter}`;
2546
+ this._config = Object.assign(Object.assign({}, config), { prefixSplitter,
2547
+ fullPrefix });
2548
+ }
2549
+ // MARK: LimitedStorageAccessor
2550
+ get(inputKey) {
2551
+ const storeKey = this.makeStorageKey(inputKey);
2552
+ return this._delegate.get(storeKey).pipe(map((storedData) => {
2553
+ if (storedData) {
2554
+ const readStoredData = this.readStoredData(storedData);
2555
+ if (!readStoredData.expired) {
2556
+ return readStoredData.convertedData;
2557
+ }
2558
+ else {
2559
+ throw new DataIsExpiredError(readStoredData);
2560
+ }
2561
+ }
2562
+ else {
2563
+ throw new DataDoesNotExistError();
2564
+ }
2565
+ }));
2566
+ }
2567
+ set(inputKey, inputValue) {
2568
+ const storeKey = this.makeStorageKey(inputKey);
2569
+ const storeData = this.buildStoredData(inputValue);
2570
+ const data = JSON.stringify(storeData);
2571
+ return this._delegate.set(storeKey, data);
2572
+ }
2573
+ remove(key) {
2574
+ const storeKey = this.makeStorageKey(key);
2575
+ return this._delegate.remove(storeKey);
2576
+ }
2577
+ all() {
2578
+ return this._delegate.all(this._config.fullPrefix).pipe(map((allStoredData) => {
2579
+ return allStoredData.map((storedData) => {
2580
+ const readStoredData = this.readStoredData(storedData);
2581
+ if (!readStoredData.expired) {
2582
+ return readStoredData.convertedData;
2583
+ }
2584
+ else {
2585
+ return null;
2586
+ }
2587
+ }).filter(filterMaybeValuesFn);
2588
+ }));
2589
+ }
2590
+ allKeys() {
2591
+ return this._delegate.allKeys(this._config.fullPrefix).pipe(map((keys) => keys.map(x => this.decodeStorageKey(x))));
2592
+ }
2593
+ clear() {
2594
+ return this._delegate.clear();
2595
+ }
2596
+ // MARK: Stored Values
2597
+ readStoredData(storedDataString) {
2598
+ const storedData = JSON.parse(storedDataString);
2599
+ const expired = this.isExpiredStoredData(storedData);
2600
+ const convertedData = this._delegate.parseValue(storedData.data);
2601
+ return Object.assign(Object.assign({}, storedData), { expired,
2602
+ convertedData });
2603
+ }
2604
+ buildStoredData(value) {
2605
+ return {
2606
+ storedAt: unixTimeNumberForNow(),
2607
+ data: this.stringifyValue(value)
2608
+ };
2609
+ }
2610
+ isExpiredStoredData(storeData) {
2611
+ const expiresIn = this._config.expiresIn;
2612
+ if (expiresIn) {
2613
+ if (storeData.storedAt) {
2614
+ return timeNumberHasExpired(storeData.storedAt, expiresIn);
2615
+ }
2616
+ return true;
2617
+ }
2618
+ else {
2619
+ return false;
2620
+ }
2621
+ }
2622
+ // MARK: Internal
2623
+ assertValidStorageKeyPrefix(prefix, prefixSplitter) {
2624
+ if (!prefixSplitter) {
2625
+ throw new Error('Invalid storage key prefix splitter. Must be defined and not empty.');
2626
+ }
2627
+ if (!this.isValidStorageKeyPrefix(prefix, prefixSplitter)) {
2628
+ throw new Error('Invalid storage key prefix.');
2629
+ }
2630
+ }
2631
+ isValidStorageKeyPrefix(prefix, prefixSpltter) {
2632
+ return Boolean(prefix && prefix.indexOf(prefixSpltter) === -1);
2633
+ }
2634
+ makeStorageKey(key) {
2635
+ return `${this._config.prefix}${this._config.prefixSplitter}${String(key)}`;
2636
+ }
2637
+ isKeyOfAccessor(storageKey) {
2638
+ return storageKey.startsWith(this._config.fullPrefix);
2639
+ }
2640
+ decodeStorageKey(storageKey) {
2641
+ const split = storageKey.split(this._config.prefixSplitter, 2);
2642
+ return split[1];
2643
+ }
2644
+ stringifyValue(value) {
2645
+ return this._delegate.stringifyValue(value);
2646
+ }
2647
+ }
2648
+ SimpleStorageAccessor.PREFIX_SPLITTER = '::';
2649
+
2650
+ /**
2651
+ * Simple StorageAccessor implementation that wraps a FullStorageObject.
2652
+ */
2653
+ class StringStorageAccessor {
2654
+ constructor(_storage) {
2655
+ this._storage = _storage;
2656
+ }
2657
+ get(key) {
2658
+ return new Observable((x) => {
2659
+ const value = this._storage.getItem(key);
2660
+ x.next(value);
2661
+ x.complete();
2662
+ });
2663
+ }
2664
+ set(key, value) {
2665
+ return new Observable((x) => {
2666
+ this._storage.setItem(key, value);
2667
+ x.next();
2668
+ x.complete();
2669
+ });
2670
+ }
2671
+ remove(key) {
2672
+ return new Observable((x) => {
2673
+ this._storage.removeItem(key);
2674
+ x.next();
2675
+ x.complete();
2676
+ });
2677
+ }
2678
+ clear() {
2679
+ const removed = this._storage.removeAll();
2680
+ return new Observable((x) => {
2681
+ x.next(removed);
2682
+ x.complete();
2683
+ });
2684
+ }
2685
+ all() {
2686
+ return this.allKeys().pipe(map(x => x.map(y => this._storage.getItem(y))), shareReplay(1));
2687
+ }
2688
+ allKeys() {
2689
+ return new Observable((x) => {
2690
+ const result = StorageObjectUtility.allKeysFromStorageObject(this._storage);
2691
+ x.next(result);
2692
+ x.complete();
2693
+ });
2694
+ }
2695
+ }
2696
+
2697
+ const DEFAULT_STORAGE_OBJECT_TOKEN = new InjectionToken('DEFAULT_STORAGE_OBJECT');
2698
+ const DEFAULT_STORAGE_ACCESSOR_FACTORY_TOKEN = new InjectionToken('DEFAULT_STORAGE_ACCESSOR_FACTORY');
2699
+
2700
+ /**
2701
+ * Used for building SimpleStorageAccessor instances from SimpleStorageAccessorConfig.
2702
+ */
2703
+ class SimpleStorageAccessorFactory {
2704
+ constructor(storageObject) {
2705
+ this.storageObject = storageObject;
2706
+ }
2707
+ createStorageAccessor(config) {
2708
+ var _a, _b;
2709
+ const storage = (_a = config.storage) !== null && _a !== void 0 ? _a : new StringStorageAccessor(this.storageObject);
2710
+ const converter = (_b = config.converter) !== null && _b !== void 0 ? _b : new StringifySimpleStorageAccessorConverter();
2711
+ const delegate = new WrapperSimpleStorageAccessorDelegate(storage, converter);
2712
+ const accessorConfig = {
2713
+ prefix: config.prefix
2714
+ };
2715
+ return new SimpleStorageAccessor(delegate, accessorConfig);
2716
+ }
2717
+ }
2718
+ SimpleStorageAccessorFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: SimpleStorageAccessorFactory, deps: [{ token: DEFAULT_STORAGE_OBJECT_TOKEN }], target: i0.ɵɵFactoryTarget.Injectable });
2719
+ SimpleStorageAccessorFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: SimpleStorageAccessorFactory });
2720
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: SimpleStorageAccessorFactory, decorators: [{
2721
+ type: Injectable
2722
+ }], ctorParameters: function () {
2723
+ return [{ type: i1$3.FullStorageObject, decorators: [{
2724
+ type: Inject,
2725
+ args: [DEFAULT_STORAGE_OBJECT_TOKEN]
2726
+ }] }];
2727
+ } });
2728
+
2729
+ /**
2730
+ * Stored object accessor that can get/set/remove via a key, or be cleared entirely.
2731
+ */
2732
+ class LimitedStorageAccessor {
2733
+ }
2734
+ /**
2735
+ * LimitedStorageAccessor extension that has knowledge of all stored keys.
2736
+ */
2737
+ class StorageAccessor extends LimitedStorageAccessor {
2738
+ }
2739
+ /**
2740
+ * StorageAccessor-like object that has immediate/synchronous functionality for get/set.
2741
+ */
2742
+ class InstantStorageAccessor {
2743
+ }
2744
+
2745
+ /**
2746
+ * StorageObject using LocalStorage.
2747
+ */
2748
+ class FullLocalStorageObject {
2749
+ constructor(_localStorage) {
2750
+ this._localStorage = _localStorage;
2751
+ }
2752
+ get isPersistant() {
2753
+ return true;
2754
+ }
2755
+ get isAvailable() {
2756
+ const test = '_T_E_S_T_';
2757
+ try {
2758
+ // Tests setting and removing an item. These will throw an
2759
+ // exception if the localstorage is not available
2760
+ this._localStorage.setItem(test, test);
2761
+ this._localStorage.removeItem(test);
2762
+ return true;
2763
+ }
2764
+ catch (e) {
2765
+ return false;
2766
+ }
2767
+ }
2768
+ get length() {
2769
+ return this._localStorage.length;
2770
+ }
2771
+ getItem(key) {
2772
+ return this._localStorage.getItem(key);
2773
+ }
2774
+ setItem(key, item) {
2775
+ this._localStorage.setItem(key, item);
2776
+ }
2777
+ removeItem(key) {
2778
+ this._localStorage.removeItem(key);
2779
+ }
2780
+ key(index) {
2781
+ return this._localStorage.key(index);
2782
+ }
2783
+ removeAll() {
2784
+ const keys = StorageObjectUtility.allKeysFromStorageObject(this);
2785
+ keys.forEach(x => this.removeItem(x));
2786
+ return keys;
2787
+ }
2788
+ }
2789
+
2790
+ /**
2791
+ * FullStorageObject implementation that uses a localstorage that entirely resides in memory.
2792
+ */
2793
+ class MemoryStorageObject extends FullLocalStorageObject {
2794
+ get isLastingStorage() {
2795
+ return false;
2796
+ }
2797
+ get isAvailable() {
2798
+ return true;
2799
+ }
2800
+ constructor() {
2801
+ super(SHARED_MEMORY_STORAGE);
2802
+ }
2803
+ }
2804
+
2805
+ function defaultStorageObjectFactory() {
2806
+ let storageObject = new FullLocalStorageObject(localStorage);
2807
+ if (!storageObject.isAvailable) {
2808
+ storageObject = new MemoryStorageObject();
2809
+ }
2810
+ return storageObject;
2811
+ }
2812
+ class AppStorageModule {
2813
+ static forRoot() {
2814
+ return {
2815
+ ngModule: AppStorageModule,
2816
+ providers: [{
2817
+ provide: DEFAULT_STORAGE_OBJECT_TOKEN,
2818
+ useFactory: defaultStorageObjectFactory
2819
+ }, {
2820
+ provide: DEFAULT_STORAGE_ACCESSOR_FACTORY_TOKEN,
2821
+ useClass: SimpleStorageAccessorFactory
2822
+ }, {
2823
+ provide: SimpleStorageAccessorFactory,
2824
+ useExisting: DEFAULT_STORAGE_ACCESSOR_FACTORY_TOKEN
2825
+ }]
2826
+ };
2827
+ }
2828
+ }
2829
+ AppStorageModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AppStorageModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2830
+ AppStorageModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AppStorageModule });
2831
+ AppStorageModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AppStorageModule });
2832
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.0", ngImport: i0, type: AppStorageModule, decorators: [{
2833
+ type: NgModule
2834
+ }] });
2835
+
2836
+ /**
2837
+ * Triggers a detection change on the input view as long as the view has not been destroyed.
2838
+ *
2839
+ * @param cdRef
2840
+ */
2841
+ function safeDetectChanges(cdRef) {
2842
+ if (!cdRef.destroyed) {
2843
+ cdRef.detectChanges();
2844
+ }
2845
+ }
2846
+ /**
2847
+ * Used to check an injected ElementRef that wraps an ng-content injection point whether or not any content was injected,
2848
+ * or more specifically if the parent component passed any target content to the child. This will still return true if
2849
+ * passed content is empty.
2850
+ *
2851
+ * TS:
2852
+ * @ViewChild('customLoading', { static: false }) customCustom: ElementRef;
2853
+ *
2854
+ * HTML:
2855
+ * <div #customContent>
2856
+ * <ng-content select="[content]"></ng-content>
2857
+ * </div>
2858
+ */
2859
+ function checkNgContentWrapperHasContent(ref) {
2860
+ // https://github.com/angular/angular/issues/26083
2861
+ let hasContent = false;
2862
+ if (ref != null) {
2863
+ const childNodes = ref.nativeElement.childNodes;
2864
+ const hasChildNodes = childNodes && childNodes.length > 0;
2865
+ hasContent = Boolean(hasChildNodes);
2866
+ }
2867
+ return hasContent;
2868
+ }
2869
+
2870
+ /**
2871
+ * Generated bundle index. Do not edit.
2872
+ */
2873
+
2874
+ export { APP_ACTION_DISABLED_DIRECTIVE_KEY, APP_ACTION_DISABLED_UNTIL_MODIFIED_DIRECTIVE_KEY, AbstractDbNgxAnchorDirective, AbstractDbNgxButtonDirective, AbstractDbNgxInjectedDirective, AbstractLockSetSubscriptionDirective, AbstractSubscriptionDirective, AbstractTransitionWatcherDirective, ActionContextBaseSource, ActionContextMachine, ActionContextStore, ActionContextStoreSource, ActionContextStoreSourceInstance, ActionContextStoreSourceMap, ActionSnackbarDefaultType, ActionSnackbarEventType, ActionState, AnchorType, AppStorageModule, DEFAULT_ACTION_DISABLED_KEY, DEFAULT_ACTION_MAP_WORKING_DISABLED_KEY, DEFAULT_SNACKBAR_DIRECTIVE_DURATION, DEFAULT_SNACKBAR_UNDO_DIRECTIVE_DURATION, DEFAULT_STORAGE_ACCESSOR_FACTORY_TOKEN, DEFAULT_STORAGE_OBJECT_TOKEN, DateDistancePipe, DateFormatDistancePipe, DateFromToTimePipe, DbNgxActionAutoModifyDirective, DbNgxActionAutoTriggerDirective, DbNgxActionAutoTriggerValueDirective, DbNgxActionButtonDirective, DbNgxActionButtonTriggerDirective, DbNgxActionComponent, DbNgxActionContextDirective, DbNgxActionContextLoggerDirective, DbNgxActionContextMapDirective, DbNgxActionContextMapDirectiveSourceInstance, DbNgxActionDisabledDirective, DbNgxActionDisabledUntilModifiedDirective, DbNgxActionFromMapDirective, DbNgxActionHandlerDirective, DbNgxActionMapSourceDirective, DbNgxActionMapWorkingDisableDirective, DbNgxActionSourceDirective, DbNgxActionSuccessComponent, DbNgxActionSuccessDirective, DbNgxActionValueDirective, DbNgxActionWorkingComponent, DbNgxAnchor, DbNgxAngularRouterService, DbNgxButton, DbNgxButtonDirective, DbNgxButtonSegueDirective, DbNgxCoreActionModule, DbNgxCoreAngularRouterSegueModule, DbNgxCoreButtonModule, DbNgxCoreUIRouterSegueModule, DbNgxDatePipeModule, DbNgxInjectedComponent, DbNgxInjectedComponentInstance, DbNgxInjectedComponentModule, DbNgxLoadingButtonDirective, DbNgxRouterService, DbNgxRouterTransitionEventType, DbNgxRouterTransitionService, DbNgxUIRouterService, FullLocalStorageObject, InstantStorageAccessor, LimitedStorageAccessor, MemoryStorageObject, MinutesStringPipe, ProvideActionStoreSource, ProvideDbNgxAnchor, ProvideDbNgxButton, ProvideSecondaryActionStoreSource, SecondaryActionContextStoreSource, SimpleStorageAccessor, SimpleStorageAccessorFactory, StorageAccessor, StringStorageAccessor, StringifySimpleStorageAccessorConverter, TimeDistanceCountdownPipe, TimeDistancePipe, ToJsDatePipe, ToMinutesPipe, WorkHandlerContext, WorkHandlerContextSourceDelegate, WrapperSimpleStorageAccessorDelegate, actionContextHasNoErrorAndIsModifiedAndCanTrigger, actionContextIsModifiedAndCanTrigger, actionContextStoreSourceInstanceFactory, actionContextStoreSourcePipe, anchorTypeForAnchor, canReadyValue, canTriggerAction, canTriggerActionState, checkNgContentWrapperHasContent, defaultStorageObjectFactory, handleWorkValueReadyFn, handleWorkValueReadyWithConfigFn, isActionContextDisabled, isActionContextEnabled, isDisabledActionContextState, isIdleActionState, isWorkingActionState, mapRefStringObsToSegueRefObs, pipeActionStore, refStringToSegueRef, safeDetectChanges, useActionStore };
2875
+ //# sourceMappingURL=dereekb-dbx-core.mjs.map