ember-promise-modals 3.0.1 → 4.0.0

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.
package/.release-it.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-template-curly-in-string */
2
2
  module.exports = {
3
3
  plugins: {
4
- 'release-it-lerna-changelog': {
4
+ '@release-it-plugins/lerna-changelog': {
5
5
  infile: 'CHANGELOG.md',
6
6
  },
7
7
  },
package/CHANGELOG.md CHANGED
@@ -2,13 +2,46 @@
2
2
 
3
3
 
4
4
 
5
+
6
+ ## v4.0.0 (2023-06-01)
7
+
8
+ #### :boom: Breaking Change
9
+ * [#856](https://github.com/mainmatter/ember-promise-modals/pull/856) setupPromiseModals should wait for test waiters to settle ([@marcin-wicha](https://github.com/marcin-wicha))
10
+
11
+ #### :rocket: Enhancement
12
+ * [#550](https://github.com/mainmatter/ember-promise-modals/pull/550) Modal template helper ([@pichfl](https://github.com/pichfl))
13
+
14
+ #### :bug: Bug Fix
15
+ * [#826](https://github.com/mainmatter/ember-promise-modals/pull/826) Ensure animations are triggered when `prefer-reduced-animation` is used ([@pichfl](https://github.com/pichfl))
16
+ * [#682](https://github.com/mainmatter/ember-promise-modals/pull/682) Improve test helper ([@pichfl](https://github.com/pichfl))
17
+
18
+ #### :house: Internal
19
+ * [#819](https://github.com/mainmatter/ember-promise-modals/pull/819) Update ember-try configuration ([@pichfl](https://github.com/pichfl))
20
+ * [#688](https://github.com/mainmatter/ember-promise-modals/pull/688) Prefer "happy path" code style for `_resolve()` ([@pichfl](https://github.com/pichfl))
21
+ * [#687](https://github.com/mainmatter/ember-promise-modals/pull/687) Extract destruction of the modals effects into a method and apply them ([@pichfl](https://github.com/pichfl))
22
+ * [#686](https://github.com/mainmatter/ember-promise-modals/pull/686) Closing the modal should inform the modals service ([@pichfl](https://github.com/pichfl))
23
+ * [#766](https://github.com/mainmatter/ember-promise-modals/pull/766) Replace deprecated release-it-lerna-changelog ([@pichfl](https://github.com/pichfl))
24
+ * [#685](https://github.com/mainmatter/ember-promise-modals/pull/685) Move attaching/detaching `animationend` event handler into methods and generalize related names ([@pichfl](https://github.com/pichfl))
25
+ * [#763](https://github.com/mainmatter/ember-promise-modals/pull/763) Allow automatic installation of peer dependencies ([@pichfl](https://github.com/pichfl))
26
+ * [#684](https://github.com/mainmatter/ember-promise-modals/pull/684) Move focusTrap setup/teardown to methods ([@pichfl](https://github.com/pichfl))
27
+ * [#683](https://github.com/mainmatter/ember-promise-modals/pull/683) Replace retained element reference with a method ([@pichfl](https://github.com/pichfl))
28
+ * [#598](https://github.com/mainmatter/ember-promise-modals/pull/598) Refactor handling of `focusTrap.onDeactivate` method ([@pichfl](https://github.com/pichfl))
29
+ * [#681](https://github.com/mainmatter/ember-promise-modals/pull/681) remove dependabot configuration ([@nickschot](https://github.com/nickschot))
30
+
31
+ #### Committers: 5
32
+ - Florian Pichler ([@pichfl](https://github.com/pichfl))
33
+ - Gabor Babicz ([@zeppelin](https://github.com/zeppelin))
34
+ - Marcin Wicha ([@marcin-wicha](https://github.com/marcin-wicha))
35
+ - Nick Schot ([@nickschot](https://github.com/nickschot))
36
+ - Sebastian Helbig ([@sebastianhelbig](https://github.com/sebastianhelbig))
37
+
5
38
  ## v3.0.1 (2022-04-12)
6
39
 
7
40
  #### :bug: Bug Fix
8
- * [#596](https://github.com/simplabs/ember-promise-modals/pull/596) Ensure calls to @close run before the focus-out deactivation ([@pichfl](https://github.com/pichfl))
41
+ * [#596](https://github.com/mainmatter/ember-promise-modals/pull/596) Ensure calls to @close run before the focus-out deactivation ([@pichfl](https://github.com/pichfl))
9
42
 
10
43
  #### :house: Internal
11
- * [#597](https://github.com/simplabs/ember-promise-modals/pull/597) Remove deprecated `clickOutsideDeactivates` option ([@pichfl](https://github.com/pichfl))
44
+ * [#597](https://github.com/mainmatter/ember-promise-modals/pull/597) Remove deprecated `clickOutsideDeactivates` option ([@pichfl](https://github.com/pichfl))
12
45
 
13
46
  #### Committers: 1
14
47
  - Florian Pichler ([@pichfl](https://github.com/pichfl))
@@ -16,26 +49,26 @@
16
49
  ## v3.0.0 (2022-04-11)
17
50
 
18
51
  #### :boom: Breaking Change
19
- * [#588](https://github.com/simplabs/ember-promise-modals/pull/588) Use ember-auto-import@2 ([@pichfl](https://github.com/pichfl))
20
- * [#438](https://github.com/simplabs/ember-promise-modals/pull/438) bump @ember/test-waiters to 3.0.0 ([@nickschot](https://github.com/nickschot))
21
- * [#437](https://github.com/simplabs/ember-promise-modals/pull/437) Drop Node 10 support ([@nickschot](https://github.com/nickschot))
52
+ * [#588](https://github.com/mainmatter/ember-promise-modals/pull/588) Use ember-auto-import@2 ([@pichfl](https://github.com/pichfl))
53
+ * [#438](https://github.com/mainmatter/ember-promise-modals/pull/438) bump @ember/test-waiters to 3.0.0 ([@nickschot](https://github.com/nickschot))
54
+ * [#437](https://github.com/mainmatter/ember-promise-modals/pull/437) Drop Node 10 support ([@nickschot](https://github.com/nickschot))
22
55
 
23
56
  #### :rocket: Enhancement
24
- * [#549](https://github.com/simplabs/ember-promise-modals/pull/549) Enhance focus trap configuration ([@zeppelin](https://github.com/zeppelin))
25
- * [#533](https://github.com/simplabs/ember-promise-modals/pull/533) Legacy: Downgrade native class to Ember.Object ([@pichfl](https://github.com/pichfl))
26
- * [#436](https://github.com/simplabs/ember-promise-modals/pull/436) Embroider optimized compatibility ([@nickschot](https://github.com/nickschot))
27
- * [#517](https://github.com/simplabs/ember-promise-modals/pull/517) Add option to disable focus trap ([@zeppelin](https://github.com/zeppelin))
57
+ * [#549](https://github.com/mainmatter/ember-promise-modals/pull/549) Enhance focus trap configuration ([@zeppelin](https://github.com/zeppelin))
58
+ * [#533](https://github.com/mainmatter/ember-promise-modals/pull/533) Legacy: Downgrade native class to Ember.Object ([@pichfl](https://github.com/pichfl))
59
+ * [#436](https://github.com/mainmatter/ember-promise-modals/pull/436) Embroider optimized compatibility ([@nickschot](https://github.com/nickschot))
60
+ * [#517](https://github.com/mainmatter/ember-promise-modals/pull/517) Add option to disable focus trap ([@zeppelin](https://github.com/zeppelin))
28
61
 
29
62
  #### :memo: Documentation
30
- * [#502](https://github.com/simplabs/ember-promise-modals/pull/502) Provide additional documentation for the Modal class and ModalOptions ([@pichfl](https://github.com/pichfl))
63
+ * [#502](https://github.com/mainmatter/ember-promise-modals/pull/502) Provide additional documentation for the Modal class and ModalOptions ([@pichfl](https://github.com/pichfl))
31
64
 
32
65
  #### :house: Internal
33
- * [#594](https://github.com/simplabs/ember-promise-modals/pull/594) Configure release-it ([@pichfl](https://github.com/pichfl))
34
- * [#570](https://github.com/simplabs/ember-promise-modals/pull/570) Setup Renovatebot ([@nickschot](https://github.com/nickschot))
35
- * [#477](https://github.com/simplabs/ember-promise-modals/pull/477) Replace Yarn with pnpm ([@pichfl](https://github.com/pichfl))
36
- * [#530](https://github.com/simplabs/ember-promise-modals/pull/530) Internal: Extend and apply prettier configuration ([@pichfl](https://github.com/pichfl))
37
- * [#500](https://github.com/simplabs/ember-promise-modals/pull/500) Specify octane edition in package.json & add missing optional features ([@nickschot](https://github.com/nickschot))
38
- * [#499](https://github.com/simplabs/ember-promise-modals/pull/499) Update ember-release scenario to use auto-import v2 ([@nickschot](https://github.com/nickschot))
66
+ * [#594](https://github.com/mainmatter/ember-promise-modals/pull/594) Configure release-it ([@pichfl](https://github.com/pichfl))
67
+ * [#570](https://github.com/mainmatter/ember-promise-modals/pull/570) Setup Renovatebot ([@nickschot](https://github.com/nickschot))
68
+ * [#477](https://github.com/mainmatter/ember-promise-modals/pull/477) Replace Yarn with pnpm ([@pichfl](https://github.com/pichfl))
69
+ * [#530](https://github.com/mainmatter/ember-promise-modals/pull/530) Internal: Extend and apply prettier configuration ([@pichfl](https://github.com/pichfl))
70
+ * [#500](https://github.com/mainmatter/ember-promise-modals/pull/500) Specify octane edition in package.json & add missing optional features ([@nickschot](https://github.com/nickschot))
71
+ * [#499](https://github.com/mainmatter/ember-promise-modals/pull/499) Update ember-release scenario to use auto-import v2 ([@nickschot](https://github.com/nickschot))
39
72
 
40
73
  #### Committers: 3
41
74
  - Florian Pichler ([@pichfl](https://github.com/pichfl))
@@ -45,19 +78,19 @@
45
78
  ## v2.0.0 (2021-09-01)
46
79
 
47
80
  #### :boom: Breaking Change
48
- * [#427](https://github.com/simplabs/ember-promise-modals/pull/427) Generate one backdrop per modal ([@aoumiri](https://github.com/aoumiri))
81
+ * [#427](https://github.com/mainmatter/ember-promise-modals/pull/427) Generate one backdrop per modal ([@aoumiri](https://github.com/aoumiri))
49
82
 
50
83
  #### :rocket: Enhancement
51
- * [#427](https://github.com/simplabs/ember-promise-modals/pull/427) Generate one backdrop per modal ([@aoumiri](https://github.com/aoumiri))
84
+ * [#427](https://github.com/mainmatter/ember-promise-modals/pull/427) Generate one backdrop per modal ([@aoumiri](https://github.com/aoumiri))
52
85
 
53
86
  #### :memo: Documentation
54
- * [#432](https://github.com/simplabs/ember-promise-modals/pull/432) Fix responsiveness of dummy app ([@nickschot](https://github.com/nickschot))
55
- * [#414](https://github.com/simplabs/ember-promise-modals/pull/414) Improve README and dummy application ([@pichfl](https://github.com/pichfl))
87
+ * [#432](https://github.com/mainmatter/ember-promise-modals/pull/432) Fix responsiveness of dummy app ([@nickschot](https://github.com/nickschot))
88
+ * [#414](https://github.com/mainmatter/ember-promise-modals/pull/414) Improve README and dummy application ([@pichfl](https://github.com/pichfl))
56
89
 
57
90
  #### :house: Internal
58
- * [#431](https://github.com/simplabs/ember-promise-modals/pull/431) Use env=production when building the dummy application ([@pichfl](https://github.com/pichfl))
59
- * [#430](https://github.com/simplabs/ember-promise-modals/pull/430) Update production build path for GitHub pages ([@pichfl](https://github.com/pichfl))
60
- * [#415](https://github.com/simplabs/ember-promise-modals/pull/415) Deploy dummy application to Github pages ([@pichfl](https://github.com/pichfl))
91
+ * [#431](https://github.com/mainmatter/ember-promise-modals/pull/431) Use env=production when building the dummy application ([@pichfl](https://github.com/pichfl))
92
+ * [#430](https://github.com/mainmatter/ember-promise-modals/pull/430) Update production build path for GitHub pages ([@pichfl](https://github.com/pichfl))
93
+ * [#415](https://github.com/mainmatter/ember-promise-modals/pull/415) Deploy dummy application to Github pages ([@pichfl](https://github.com/pichfl))
61
94
 
62
95
  #### Committers: 4
63
96
  - Anass OUMIRI ([@aoumiri](https://github.com/aoumiri))
@@ -69,7 +102,7 @@
69
102
  ## v1.1.1 (2021-07-27)
70
103
 
71
104
  #### :bug: Bug Fix
72
- * [#422](https://github.com/simplabs/ember-promise-modals/pull/422) fix promsie-modals from breaking when used in another addon instead of an app ([@nickschot](https://github.com/nickschot))
105
+ * [#422](https://github.com/mainmatter/ember-promise-modals/pull/422) fix promsie-modals from breaking when used in another addon instead of an app ([@nickschot](https://github.com/nickschot))
73
106
 
74
107
  #### Committers: 1
75
108
  - Nick Schot ([@nickschot](https://github.com/nickschot))
@@ -78,10 +111,10 @@
78
111
  ## v1.1.0 (2021-07-27)
79
112
 
80
113
  #### :rocket: Enhancement
81
- * [#421](https://github.com/simplabs/ember-promise-modals/pull/421) add optional onAnimationModalOutEnd hook ([@nickschot](https://github.com/nickschot))
114
+ * [#421](https://github.com/mainmatter/ember-promise-modals/pull/421) add optional onAnimationModalOutEnd hook ([@nickschot](https://github.com/nickschot))
82
115
 
83
116
  #### :bug: Bug Fix
84
- * [#420](https://github.com/simplabs/ember-promise-modals/pull/420) explicitly specify animation delay and duration as separate to make sure they're properly used by the browser ([@nickschot](https://github.com/nickschot))
117
+ * [#420](https://github.com/mainmatter/ember-promise-modals/pull/420) explicitly specify animation delay and duration as separate to make sure they're properly used by the browser ([@nickschot](https://github.com/nickschot))
85
118
 
86
119
  #### Committers: 1
87
120
  - Nick Schot ([@nickschot](https://github.com/nickschot))
@@ -90,10 +123,10 @@
90
123
  ## v1.0.2 (2021-07-26)
91
124
 
92
125
  #### :bug: Bug Fix
93
- * [#419](https://github.com/simplabs/ember-promise-modals/pull/419) fix setting a delay on the backdrop or modal makes animation break ([@nickschot](https://github.com/nickschot))
126
+ * [#419](https://github.com/mainmatter/ember-promise-modals/pull/419) fix setting a delay on the backdrop or modal makes animation break ([@nickschot](https://github.com/nickschot))
94
127
 
95
128
  #### :house: Internal
96
- * [#417](https://github.com/simplabs/ember-promise-modals/pull/417) Delete unused modal service file from dummy app ([@nickschot](https://github.com/nickschot))
129
+ * [#417](https://github.com/mainmatter/ember-promise-modals/pull/417) Delete unused modal service file from dummy app ([@nickschot](https://github.com/nickschot))
97
130
 
98
131
  #### Committers: 1
99
132
  - Nick Schot ([@nickschot](https://github.com/nickschot))
@@ -102,10 +135,10 @@
102
135
  ## v1.0.1 (2021-07-16)
103
136
 
104
137
  #### :bug: Bug Fix
105
- * [#412](https://github.com/simplabs/ember-promise-modals/pull/412) fix backdrop not animating immediately after the last modal is closed ([@nickschot](https://github.com/nickschot))
138
+ * [#412](https://github.com/mainmatter/ember-promise-modals/pull/412) fix backdrop not animating immediately after the last modal is closed ([@nickschot](https://github.com/nickschot))
106
139
 
107
140
  #### :house: Internal
108
- * [#413](https://github.com/simplabs/ember-promise-modals/pull/413) use babel-eslint as eslint parser ([@nickschot](https://github.com/nickschot))
141
+ * [#413](https://github.com/mainmatter/ember-promise-modals/pull/413) use babel-eslint as eslint parser ([@nickschot](https://github.com/nickschot))
109
142
 
110
143
  #### Committers: 2
111
144
  - Nick Schot ([@nickschot](https://github.com/nickschot))
@@ -115,14 +148,14 @@
115
148
  ## v1.0.0 (2021-07-13)
116
149
 
117
150
  #### :boom: Breaking Change
118
- * [#148](https://github.com/simplabs/ember-promise-modals/pull/148) Replace ember-animated with CSS animations ([@pichfl](https://github.com/pichfl))
151
+ * [#148](https://github.com/mainmatter/ember-promise-modals/pull/148) Replace ember-animated with CSS animations ([@pichfl](https://github.com/pichfl))
119
152
 
120
153
  #### :rocket: Enhancement
121
- * [#148](https://github.com/simplabs/ember-promise-modals/pull/148) Replace ember-animated with CSS animations ([@pichfl](https://github.com/pichfl))
154
+ * [#148](https://github.com/mainmatter/ember-promise-modals/pull/148) Replace ember-animated with CSS animations ([@pichfl](https://github.com/pichfl))
122
155
 
123
156
  #### :house: Internal
124
- * [#407](https://github.com/simplabs/ember-promise-modals/pull/407) upgrade to ember-qunit v5 ([@nickschot](https://github.com/nickschot))
125
- * [#309](https://github.com/simplabs/ember-promise-modals/pull/309) Update addon layout according to latest ember addon blueprint ([@pichfl](https://github.com/pichfl))
157
+ * [#407](https://github.com/mainmatter/ember-promise-modals/pull/407) upgrade to ember-qunit v5 ([@nickschot](https://github.com/nickschot))
158
+ * [#309](https://github.com/mainmatter/ember-promise-modals/pull/309) Update addon layout according to latest ember addon blueprint ([@pichfl](https://github.com/pichfl))
126
159
 
127
160
  #### Committers: 3
128
161
  - Florian Pichler ([@pichfl](https://github.com/pichfl))
@@ -133,14 +166,14 @@
133
166
  ## v0.2.1 (2020-06-30)
134
167
 
135
168
  #### :rocket: Enhancement
136
- * [#178](https://github.com/simplabs/ember-promise-modals/pull/178) Expose `clickOutsideDeactivates` on the `modals` service ([@Turbo87](https://github.com/Turbo87))
169
+ * [#178](https://github.com/mainmatter/ember-promise-modals/pull/178) Expose `clickOutsideDeactivates` on the `modals` service ([@Turbo87](https://github.com/Turbo87))
137
170
 
138
171
  #### :bug: Bug Fix
139
- * [#181](https://github.com/simplabs/ember-promise-modals/pull/181) service/modals: Reset `.epm-scrolling-disabled` class in the destructor ([@Turbo87](https://github.com/Turbo87))
140
- * [#180](https://github.com/simplabs/ember-promise-modals/pull/180) components/modal: Fix broken destructor ([@Turbo87](https://github.com/Turbo87))
172
+ * [#181](https://github.com/mainmatter/ember-promise-modals/pull/181) service/modals: Reset `.epm-scrolling-disabled` class in the destructor ([@Turbo87](https://github.com/Turbo87))
173
+ * [#180](https://github.com/mainmatter/ember-promise-modals/pull/180) components/modal: Fix broken destructor ([@Turbo87](https://github.com/Turbo87))
141
174
 
142
175
  #### :house: Internal
143
- * [#179](https://github.com/simplabs/ember-promise-modals/pull/179) Add `qunit-console-grouper` dev dependency ([@Turbo87](https://github.com/Turbo87))
176
+ * [#179](https://github.com/mainmatter/ember-promise-modals/pull/179) Add `qunit-console-grouper` dev dependency ([@Turbo87](https://github.com/Turbo87))
144
177
 
145
178
  #### Committers: 1
146
179
  - Tobias Bieniek ([@Turbo87](https://github.com/Turbo87))
@@ -149,18 +182,18 @@
149
182
  ## v0.2.0 (2020-04-22)
150
183
 
151
184
  #### :boom: Breaking Change
152
- * [#142](https://github.com/simplabs/ember-promise-modals/pull/142) Convert `ember-animated` to a peer dependency ([@Turbo87](https://github.com/Turbo87))
153
- * [#139](https://github.com/simplabs/ember-promise-modals/pull/139) Drop Support for Node.js 8 ([@Turbo87](https://github.com/Turbo87))
185
+ * [#142](https://github.com/mainmatter/ember-promise-modals/pull/142) Convert `ember-animated` to a peer dependency ([@Turbo87](https://github.com/Turbo87))
186
+ * [#139](https://github.com/mainmatter/ember-promise-modals/pull/139) Drop Support for Node.js 8 ([@Turbo87](https://github.com/Turbo87))
154
187
 
155
188
  #### :rocket: Enhancement
156
- * [#137](https://github.com/simplabs/ember-promise-modals/pull/137) Add Support for `ember-animated` v0.9 and v0.10 ([@dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
189
+ * [#137](https://github.com/mainmatter/ember-promise-modals/pull/137) Add Support for `ember-animated` v0.9 and v0.10 ([@dependabot-preview[bot]](https://github.com/apps/dependabot-preview))
157
190
 
158
191
  #### :memo: Documentation
159
- * [#80](https://github.com/simplabs/ember-promise-modals/pull/80) Update README ([@ansmonjol](https://github.com/ansmonjol))
192
+ * [#80](https://github.com/mainmatter/ember-promise-modals/pull/80) Update README ([@ansmonjol](https://github.com/ansmonjol))
160
193
 
161
194
  #### :house: Internal
162
- * [#143](https://github.com/simplabs/ember-promise-modals/pull/143) CI: Add scenarios for Ember v3.12 and v3.16 ([@Turbo87](https://github.com/Turbo87))
163
- * [#141](https://github.com/simplabs/ember-promise-modals/pull/141) Use GitHub Actions for CI ([@Turbo87](https://github.com/Turbo87))
195
+ * [#143](https://github.com/mainmatter/ember-promise-modals/pull/143) CI: Add scenarios for Ember v3.12 and v3.16 ([@Turbo87](https://github.com/Turbo87))
196
+ * [#141](https://github.com/mainmatter/ember-promise-modals/pull/141) Use GitHub Actions for CI ([@Turbo87](https://github.com/Turbo87))
164
197
 
165
198
  #### Committers: 2
166
199
  - Alexandre Monjol ([@ansmonjol](https://github.com/ansmonjol))
package/README.md CHANGED
@@ -107,6 +107,24 @@ order to trigger the "close modal" action. It can be called like so:
107
107
  this.args.close(results); // or this.close() in classic components
108
108
  ```
109
109
 
110
+ ### Routable modals using the template helper
111
+
112
+ This addon comes with a `{{open-modal}}` template helper which can be used to trigger modals from any templates. It accepts the similar arguments as the `open` method. It can be used to open a modal in a route, closing it automatically when navigating elsewhere.
113
+
114
+ ```hbs
115
+ {{open-modal 'confirmation-modal' (hash fileUrl=this.fileUrl) close=(fn this.save results)}}
116
+ ```
117
+
118
+ Positional arguments mimick the `open()` method on the service:
119
+
120
+ - `name`: The name of the modal component to render
121
+ - `data`: Pass additional context to the modal,
122
+ - `options`: Pass additional options to the modal
123
+
124
+ Named arguments:
125
+
126
+ - `close` is called asynchronously with the data returned by the modals `@close` action when it is closed
127
+
110
128
  ## Animation
111
129
 
112
130
  This addon uses CSS animations. You can either replace the
@@ -13,6 +13,7 @@ export default Component.extend({
13
13
 
14
14
  tagName: '',
15
15
  outAnimationClass: 'epm-out',
16
+ animatingClass: '',
16
17
 
17
18
  modals: service(),
18
19
 
@@ -20,11 +21,13 @@ export default Component.extend({
20
21
 
21
22
  modalElementId: null,
22
23
  focusTrapOptions: null,
24
+ _animationEnd: null,
23
25
 
24
26
  init() {
25
27
  this._super(...arguments);
26
28
 
27
29
  set(this, 'modalElementId', guidFor(this));
30
+
28
31
  this.modal._componentInstance = this;
29
32
 
30
33
  let { focusTrapOptions: globalFocusTrapOptions } = this.modals;
@@ -38,79 +41,121 @@ export default Component.extend({
38
41
  didInsertElement() {
39
42
  this._super(...arguments);
40
43
 
41
- let element = document.getElementById(this.modalElementId);
44
+ this._addFocusTrap();
45
+ this._addAnimationListeners();
42
46
 
43
- if (this.focusTrapOptions) {
44
- let options = {
45
- ...this.focusTrapOptions,
46
- fallbackFocus: `#${this.modalElementId}`,
47
- onPostDeactivate: (...args) => {
48
- this.focusTrapOptions.onPostDeactivate?.(...args);
47
+ // animating in starts when the element is added to the DOM. Inform the service about it.
48
+ this.modals._onModalAnimationStart();
49
+ },
49
50
 
50
- if (this.isDestroyed || this.isDestroying) {
51
- return;
52
- }
51
+ willDestroyElement() {
52
+ this.destroyModal();
53
53
 
54
- this.closeModal();
55
- },
56
- };
54
+ this._super(...arguments);
55
+ },
57
56
 
58
- this.focusTrap = createFocusTrap(element, options);
59
- this.focusTrap.activate();
60
- }
57
+ _getElement() {
58
+ return document.getElementById(this.modalElementId);
59
+ },
61
60
 
62
- this.fadeOutEnd = ({ target, animationName }) => {
63
- this.modals._onModalAnimationEnd();
61
+ _addFocusTrap() {
62
+ let element = this._getElement();
64
63
 
65
- let isntTarget = target !== element;
66
- let animationEndsWrong = animationName.substring(animationName.length - 4) !== '-out';
64
+ if (!this.focusTrapOptions) {
65
+ return;
66
+ }
67
67
 
68
- if (isntTarget || animationEndsWrong) {
69
- return;
70
- }
68
+ let options = {
69
+ ...this.focusTrapOptions,
70
+ fallbackFocus: element,
71
+ onDeactivate: (...args) => {
72
+ this.focusTrapOptions.onDeactivate?.(...args);
73
+
74
+ if (this.isDestroyed || this.isDestroying) {
75
+ return;
76
+ }
71
77
 
72
- this.modal._remove();
78
+ this.closeModal();
79
+ },
73
80
  };
74
81
 
75
- this.modals._onModalAnimationStart();
76
- element.addEventListener('animationend', this.fadeOutEnd);
77
- set(this, 'animatingOutClass', '');
82
+ this.focusTrap = createFocusTrap(element, options);
83
+ this.focusTrap.activate();
78
84
  },
79
85
 
80
- willDestroyElement() {
81
- if (this.focusTrap) {
82
- this.focusTrap.deactivate({ onDeactivate: null });
86
+ _removeFocusTrap(onDeactivate = this.focusTrapOptions?.onDeactivate) {
87
+ if (!this.focusTrap) {
88
+ return;
83
89
  }
84
90
 
85
- if (this.fadeOutEnd) {
86
- let element = document.getElementById(this.modalElementId);
91
+ this.focusTrap.deactivate({ onDeactivate });
92
+ },
93
+
94
+ _addAnimationListeners() {
95
+ this._animationEnd = ({ target, animationName }) => {
96
+ // ignore animations bubbling up
97
+ if (target !== this._getElement()) {
98
+ return;
99
+ }
100
+
101
+ // An animation has ended, inform the modals service
102
+ this.modals._onModalAnimationEnd();
87
103
 
88
- if (element) {
89
- element.removeEventListener('animationend', this.fadeOutEnd);
90
- // make sure that we remove the modal, also resolving the test waiter
104
+ let isOutAnimation = animationName.substring(animationName.length - 4) === '-out';
105
+ if (isOutAnimation) {
91
106
  this.modal._remove();
92
107
  }
108
+ };
109
+
110
+ let element = this._getElement();
111
+ if (element) {
112
+ element.addEventListener('animationend', this._animationEnd);
113
+ }
114
+ },
115
+
116
+ _removeAnimationListeners() {
117
+ if (!this._animationEnd) {
118
+ return;
93
119
  }
94
120
 
95
- this._super(...arguments);
121
+ let element = this._getElement();
122
+ if (element) {
123
+ element.removeEventListener('animationend', this._animationEnd);
124
+ }
125
+
126
+ this._animationEnd = null;
96
127
  },
97
128
 
98
- closeModal(result) {
99
- // Trigger out animation
100
- set(this, 'animatingOutClass', this.outAnimationClass);
129
+ destroyModal() {
130
+ // Remove the focus trap without triggering the optional onDeactivate() hook
131
+ this._removeFocusTrap(null);
132
+
133
+ // Remove the animation listeners
134
+ this._removeAnimationListeners();
101
135
 
102
- if (this.focusTrap) {
103
- this.focusTrap.deactivate({
104
- onDeactivate: this.focusTrapOptions.onDeactivate,
105
- });
136
+ // make sure that we remove the modal, also resolving the test waiter
137
+ this.modal._remove();
138
+ },
139
+
140
+ closeModal(result) {
141
+ if (this.animatingClass !== '') {
142
+ return;
106
143
  }
107
144
 
145
+ this.modals._onModalAnimationStart();
146
+
147
+ // This triggers the out animation, which in turn will remove the modal after it completes
148
+ set(this, 'animatingClass', this.outAnimationClass);
149
+
108
150
  this.modal._resolve(result);
109
151
  },
110
152
 
111
153
  actions: {
112
154
  close(result) {
113
155
  this.closeModal(result);
156
+
157
+ // Remove the focus trap, triggering the onDeactivate() hook
158
+ this._removeFocusTrap();
114
159
  },
115
160
  },
116
161
  });
@@ -0,0 +1,33 @@
1
+ import Helper from '@ember/component/helper';
2
+ import { inject as service } from '@ember/service';
3
+
4
+ export default class OpenModalHelper extends Helper {
5
+ @service modals;
6
+
7
+ modal = null;
8
+
9
+ compute([modalComponent, data, options], { close }) {
10
+ this.showModal(modalComponent, data, options, close);
11
+ }
12
+
13
+ async showModal(modalComponent, data, options, close) {
14
+ this.modal = this.modals.open(modalComponent, data, options);
15
+
16
+ let success = await this.modal;
17
+
18
+ this.modal = null;
19
+
20
+ if (close) {
21
+ close(success);
22
+ }
23
+ }
24
+
25
+ hideModal() {
26
+ this.modal?.close();
27
+ }
28
+
29
+ willDestroy() {
30
+ this.hideModal();
31
+ super.willDestroy(...arguments);
32
+ }
33
+ }
package/addon/modal.js CHANGED
@@ -54,18 +54,28 @@ export default class Modal {
54
54
  return this._deferred.promise.then(onFulfilled, onRejected);
55
55
  }
56
56
 
57
- _resolve(result) {
58
- if (!this._deferredOutAnimation) {
59
- set(this, '_deferredOutAnimation', defer());
60
- if (this._options.onAnimationModalOutEnd) {
61
- this._deferredOutAnimation.promise.then(() => this._options.onAnimationModalOutEnd()).catch(() => {});
62
- }
57
+ _destroy() {
58
+ if (!this._componentInstance) {
59
+ return;
60
+ }
63
61
 
64
- this._result = result;
65
- this._deferred.resolve(result);
62
+ this._componentInstance.destroyModal();
63
+ }
66
64
 
67
- waitForPromise(this._deferredOutAnimation.promise);
65
+ _resolve(result) {
66
+ if (this._deferredOutAnimation) {
67
+ return;
68
68
  }
69
+
70
+ set(this, '_deferredOutAnimation', defer());
71
+ if (this._options.onAnimationModalOutEnd) {
72
+ this._deferredOutAnimation.promise.then(() => this._options.onAnimationModalOutEnd()).catch(() => {});
73
+ }
74
+
75
+ this._result = result;
76
+ this._deferred.resolve(result);
77
+
78
+ waitForPromise(this._deferredOutAnimation.promise);
69
79
  }
70
80
 
71
81
  _remove() {
@@ -20,13 +20,17 @@ export default Service.extend({
20
20
  if (this.focusTrapOptions !== null) {
21
21
  this.focusTrapOptions = {
22
22
  ...(this.focusTrapOptions ?? {}),
23
- clickOutsideDeactivates: this.focusTrapOptions?.clickOutsideDeactivate ?? true,
23
+ clickOutsideDeactivates: this.focusTrapOptions?.clickOutsideDeactivates ?? true,
24
24
  };
25
25
  }
26
26
  },
27
27
 
28
28
  willDestroy() {
29
29
  this._onLastModalRemoved();
30
+ this._onModalAnimationEnd();
31
+ this._destroyModals();
32
+
33
+ this._super(...arguments);
30
34
  },
31
35
 
32
36
  /**
@@ -47,6 +51,12 @@ export default Service.extend({
47
51
  return modal;
48
52
  },
49
53
 
54
+ _destroyModals() {
55
+ this._stack.forEach(modal => {
56
+ modal._destroy();
57
+ });
58
+ },
59
+
50
60
  _onFirstModalAdded() {
51
61
  document.body.classList.add('epm-scrolling-disabled');
52
62
  },
@@ -17,14 +17,14 @@
17
17
 
18
18
  @media (prefers-reduced-motion: reduce) {
19
19
  :root {
20
- --epm-animation-backdrop-in-duration: 0s;
21
- --epm-animation-backdrop-out-duration: 0s;
22
- --epm-animation-modal-in-duration: 0s;
23
- --epm-animation-modal-out-duration: 0s;
24
- --epm-animation-backdrop-in-delay: 0s;
25
- --epm-animation-backdrop-out-delay: 0s;
26
- --epm-animation-modal-in-delay: 0s;
27
- --epm-animation-modal-out-delay: 0s;
20
+ --epm-animation-backdrop-in-duration: 0.001s;
21
+ --epm-animation-backdrop-out-duration: 0.001s;
22
+ --epm-animation-modal-in-duration: 0.001s;
23
+ --epm-animation-modal-out-duration: 0.001s;
24
+ --epm-animation-backdrop-in-delay: 0.001s;
25
+ --epm-animation-backdrop-out-delay: 0.001s;
26
+ --epm-animation-modal-in-delay: 0.001s;
27
+ --epm-animation-modal-out-delay: 0.001s;
28
28
  }
29
29
  }
30
30
 
@@ -1,5 +1,5 @@
1
1
  {{!-- template-lint-disable no-action --}}
2
- <div id={{this.modalElementId}} class="epm-modal {{this.optionsClassName}} {{this.animatingOutClass}}">
2
+ <div id={{this.modalElementId}} class="epm-modal {{this.optionsClassName}} {{this.animatingClass}}">
3
3
  {{#let (component (ensure-safe-component @modal._name) data=@modal._data close=(action "close")) as |ModalComponent|}}
4
4
  <ModalComponent />
5
5
  {{/let}}