ember-promise-modals 5.0.0 → 5.1.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/README.md CHANGED
@@ -11,8 +11,7 @@ The better way to handle modals in your Ember.js apps.
11
11
  ## Compatibility
12
12
 
13
13
  - Ember.js v3.28 or above
14
- - Ember CLI v3.28 or above
15
- - Node.js v16 or above
14
+ - Embroider or ember-auto-import v2
16
15
 
17
16
  ## Installation
18
17
 
@@ -31,7 +30,7 @@ To use EPM in your project, add the target for the modals to your `application.h
31
30
  Then you can inject the `modals` [service](https://guides.emberjs.com/release/services/#toc_accessing-services) wherever you need and call its `open` method with a component class to render it as a modal.
32
31
 
33
32
  ```js
34
- import { inject as service } from '@ember/service';
33
+ import { service } from '@ember/service';
35
34
  import ConfirmationModal from 'my-app/components/confirmation-modal';
36
35
 
37
36
  export default class extends Component {
@@ -1,14 +1,22 @@
1
- import Component, { setComponentTemplate } from '@ember/component';
2
- import { inject } from '@ember/service';
3
- import './epm-modal-container.css';
1
+ import "./epm-modal-container.css"
2
+ import * as emberService from '@ember/service';
3
+ import Component from '@glimmer/component';
4
4
  import { precompileTemplate } from '@ember/template-compilation';
5
+ import { g, i } from 'decorator-transforms/runtime';
6
+ import { setComponentTemplate } from '@ember/component';
7
+
8
+ ;
5
9
 
6
10
  var TEMPLATE = precompileTemplate("{{#each this.modals._stack as |modal index|}}\n <div\n class=\"epm-backdrop {{if modal.isClosing \"epm-out\"}}\"\n tabindex=\"-1\"\n role=\"presentation\"\n aria-hidden=\"true\"\n data-test-epm-backdrop=\"{{index}}\"\n />\n <div class=\"epm-modal-container\">\n <EpmModal @modal={{modal}} data-test-epm-modal=\"{{index}}\" />\n </div>\n{{/each}}");
7
11
 
8
- var epmModalContainer = setComponentTemplate(TEMPLATE, Component.extend({
9
- tagName: '',
10
- modals: inject()
11
- }));
12
+ const service = emberService.service ?? emberService.inject;
13
+ class EpmModalContainer extends Component {
14
+ static {
15
+ g(this.prototype, "modals", [service]);
16
+ }
17
+ #modals = (i(this, "modals"), void 0);
18
+ }
19
+ setComponentTemplate(TEMPLATE, EpmModalContainer);
12
20
 
13
- export { epmModalContainer as default };
21
+ export { EpmModalContainer as default };
14
22
  //# sourceMappingURL=epm-modal-container.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"epm-modal-container.js","sources":["../../src/components/epm-modal-container.hbs","../../src/components/epm-modal-container.js"],"sourcesContent":["import { precompileTemplate } from \"@ember/template-compilation\";\nexport default precompileTemplate(\"{{#each this.modals._stack as |modal index|}}\\n <div\\n class=\\\"epm-backdrop {{if modal.isClosing \\\"epm-out\\\"}}\\\"\\n tabindex=\\\"-1\\\"\\n role=\\\"presentation\\\"\\n aria-hidden=\\\"true\\\"\\n data-test-epm-backdrop=\\\"{{index}}\\\"\\n />\\n <div class=\\\"epm-modal-container\\\">\\n <EpmModal @modal={{modal}} data-test-epm-modal=\\\"{{index}}\\\" />\\n </div>\\n{{/each}}\")","import Component from '@ember/component';\nimport { inject as service } from '@ember/service';\n\nimport './epm-modal-container.css';\n\nexport default Component.extend({\n tagName: '',\n\n modals: service(),\n});\n"],"names":["setComponentTemplate","TEMPLATE","Component","extend","tagName","modals","service"],"mappings":";;;;;AACA,eAAe,kBAAkB,CAAC,iXAAiX;;ACInZ,wBAAAA,oBAAA,CAAAC,QAAA,EAAeC,SAAS,CAACC,MAAM,CAAC;AAC9BC,EAAAA,OAAO,EAAE,EAAE;EAEXC,MAAM,EAAEC,MAAO,EAAC;AAClB,CAAC,CAAC,CAAA;;;;"}
1
+ {"version":3,"file":"epm-modal-container.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1,59 +1,67 @@
1
- import Component, { setComponentTemplate } from '@ember/component';
2
- import { set } from '@ember/object';
3
- import { readOnly } from '@ember/object/computed';
4
- import { guidFor } from '@ember/object/internals';
5
- import { inject } from '@ember/service';
1
+ import { action } from '@ember/object';
2
+ import * as emberService from '@ember/service';
3
+ import Component from '@glimmer/component';
4
+ import { tracked } from '@glimmer/tracking';
5
+ import { modifier } from 'ember-modifier';
6
6
  import { createFocusTrap } from 'focus-trap';
7
7
  import { precompileTemplate } from '@ember/template-compilation';
8
+ import { g, i, n } from 'decorator-transforms/runtime';
9
+ import { setComponentTemplate } from '@ember/component';
8
10
 
9
- var TEMPLATE = precompileTemplate("{{!-- template-lint-disable no-action --}}\n<div id={{this.modalElementId}} class=\"epm-modal {{this.optionsClassName}} {{this.animatingClass}}\">\n {{#let (component (ensure-safe-component @modal._componentClass) data=@modal._data close=(action \"close\")) as |ModalComponent|}}\n <ModalComponent />\n {{/let}}\n</div>");
11
+ var TEMPLATE = precompileTemplate("<div {{this.setup}} class=\"epm-modal {{this.optionsClassName}} {{this.animatingClass}}\">\n {{#let (component (ensure-safe-component @modal._componentClass)) as |ModalComponent|}}\n <ModalComponent @data={{@modal._data}} @close={{this.close}} />\n {{/let}}\n</div>");
10
12
 
11
- var epmModal = setComponentTemplate(TEMPLATE, Component.extend({
12
- tagName: '',
13
- outAnimationClass: 'epm-out',
14
- animatingClass: '',
15
- modals: inject(),
16
- optionsClassName: readOnly('modal._options.className'),
17
- modalElementId: null,
18
- focusTrapOptions: null,
19
- _animationEnd: null,
20
- init() {
21
- this._super(...arguments);
22
- set(this, 'modalElementId', guidFor(this));
23
- this.modal._componentInstance = this;
13
+ const service = emberService.service ?? emberService.inject;
14
+ class EpmModal extends Component {
15
+ static {
16
+ g(this.prototype, "modals", [service]);
17
+ }
18
+ #modals = (i(this, "modals"), void 0);
19
+ element = null;
20
+ outAnimationClass = 'epm-out';
21
+ _animationEnd = null;
22
+ static {
23
+ g(this.prototype, "animatingClass", [tracked], function () {
24
+ return '';
25
+ });
26
+ }
27
+ #animatingClass = (i(this, "animatingClass"), void 0);
28
+ get optionsClassName() {
29
+ return this.args.modal._options.className;
30
+ }
31
+ get focusTrapOptions() {
24
32
  let {
25
33
  focusTrapOptions: globalFocusTrapOptions
26
34
  } = this.modals;
27
35
  let {
28
36
  focusTrapOptions: localFocusTrapOptions
29
- } = this.modal._options;
30
- if (localFocusTrapOptions !== null) {
31
- this.focusTrapOptions = localFocusTrapOptions || globalFocusTrapOptions;
37
+ } = this.args.modal._options;
38
+ if (localFocusTrapOptions !== undefined) {
39
+ return localFocusTrapOptions;
32
40
  }
33
- },
34
- didInsertElement() {
35
- this._super(...arguments);
41
+ return globalFocusTrapOptions;
42
+ }
43
+ setup = modifier(element => {
44
+ this.element = element;
36
45
  this._addFocusTrap();
37
46
  this._addAnimationListeners();
38
47
 
39
48
  // animating in starts when the element is added to the DOM. Inform the service about it.
40
49
  this.modals._onModalAnimationStart();
41
- },
42
- willDestroyElement() {
43
- this.destroyModal();
44
- this._super(...arguments);
45
- },
46
- _getElement() {
47
- return document.getElementById(this.modalElementId);
48
- },
50
+ return () => {
51
+ this.destroyModal();
52
+ };
53
+ });
54
+ constructor() {
55
+ super(...arguments);
56
+ this.args.modal._componentInstance = this;
57
+ }
49
58
  _addFocusTrap() {
50
- let element = this._getElement();
51
59
  if (!this.focusTrapOptions) {
52
60
  return;
53
61
  }
54
62
  let options = {
55
63
  ...this.focusTrapOptions,
56
- fallbackFocus: element,
64
+ fallbackFocus: this.element,
57
65
  onDeactivate: (...args) => {
58
66
  this.focusTrapOptions.onDeactivate?.(...args);
59
67
  if (this.isDestroyed || this.isDestroying) {
@@ -62,9 +70,9 @@ var epmModal = setComponentTemplate(TEMPLATE, Component.extend({
62
70
  this.closeModal();
63
71
  }
64
72
  };
65
- this.focusTrap = createFocusTrap(element, options);
73
+ this.focusTrap = createFocusTrap(this.element, options);
66
74
  this.focusTrap.activate();
67
- },
75
+ }
68
76
  _removeFocusTrap(onDeactivate = this.focusTrapOptions?.onDeactivate) {
69
77
  if (!this.focusTrap) {
70
78
  return;
@@ -72,14 +80,14 @@ var epmModal = setComponentTemplate(TEMPLATE, Component.extend({
72
80
  this.focusTrap.deactivate({
73
81
  onDeactivate
74
82
  });
75
- },
83
+ }
76
84
  _addAnimationListeners() {
77
85
  this._animationEnd = ({
78
86
  target,
79
87
  animationName
80
88
  }) => {
81
89
  // ignore animations bubbling up
82
- if (target !== this._getElement()) {
90
+ if (target !== this.element) {
83
91
  return;
84
92
  }
85
93
 
@@ -87,24 +95,22 @@ var epmModal = setComponentTemplate(TEMPLATE, Component.extend({
87
95
  this.modals._onModalAnimationEnd();
88
96
  let isOutAnimation = animationName.substring(animationName.length - 4) === '-out';
89
97
  if (isOutAnimation) {
90
- this.modal._remove();
98
+ this.args.modal._remove();
91
99
  }
92
100
  };
93
- let element = this._getElement();
94
- if (element) {
95
- element.addEventListener('animationend', this._animationEnd);
101
+ if (this.element) {
102
+ this.element.addEventListener('animationend', this._animationEnd);
96
103
  }
97
- },
104
+ }
98
105
  _removeAnimationListeners() {
99
106
  if (!this._animationEnd) {
100
107
  return;
101
108
  }
102
- let element = this._getElement();
103
- if (element) {
104
- element.removeEventListener('animationend', this._animationEnd);
109
+ if (this.element) {
110
+ this.element.removeEventListener('animationend', this._animationEnd);
105
111
  }
106
112
  this._animationEnd = null;
107
- },
113
+ }
108
114
  destroyModal() {
109
115
  // Remove the focus trap without triggering the optional onDeactivate() hook
110
116
  this._removeFocusTrap(null);
@@ -113,8 +119,8 @@ var epmModal = setComponentTemplate(TEMPLATE, Component.extend({
113
119
  this._removeAnimationListeners();
114
120
 
115
121
  // make sure that we remove the modal, also resolving the test waiter
116
- this.modal._remove();
117
- },
122
+ this.args.modal._remove();
123
+ }
118
124
  closeModal(result) {
119
125
  if (this.animatingClass !== '') {
120
126
  return;
@@ -122,18 +128,20 @@ var epmModal = setComponentTemplate(TEMPLATE, Component.extend({
122
128
  this.modals._onModalAnimationStart();
123
129
 
124
130
  // This triggers the out animation, which in turn will remove the modal after it completes
125
- set(this, 'animatingClass', this.outAnimationClass);
126
- this.modal._resolve(result);
127
- },
128
- actions: {
129
- close(result) {
130
- this.closeModal(result);
131
+ this.animatingClass = this.outAnimationClass;
132
+ this.args.modal._resolve(result);
133
+ }
134
+ close(result) {
135
+ this.closeModal(result);
131
136
 
132
- // Remove the focus trap, triggering the onDeactivate() hook
133
- this._removeFocusTrap();
134
- }
137
+ // Remove the focus trap, triggering the onDeactivate() hook
138
+ this._removeFocusTrap();
139
+ }
140
+ static {
141
+ n(this.prototype, "close", [action]);
135
142
  }
136
- }));
143
+ }
144
+ setComponentTemplate(TEMPLATE, EpmModal);
137
145
 
138
- export { epmModal as default };
146
+ export { EpmModal as default };
139
147
  //# sourceMappingURL=epm-modal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"epm-modal.js","sources":["../../src/components/epm-modal.hbs","../../src/components/epm-modal.js"],"sourcesContent":["import { precompileTemplate } from \"@ember/template-compilation\";\nexport default precompileTemplate(\"{{!-- template-lint-disable no-action --}}\\n<div id={{this.modalElementId}} class=\\\"epm-modal {{this.optionsClassName}} {{this.animatingClass}}\\\">\\n {{#let (component (ensure-safe-component @modal._componentClass) data=@modal._data close=(action \\\"close\\\")) as |ModalComponent|}}\\n <ModalComponent />\\n {{/let}}\\n</div>\")","import Component from '@ember/component';\nimport { set } from '@ember/object';\nimport { readOnly } from '@ember/object/computed';\nimport { guidFor } from '@ember/object/internals';\nimport { inject as service } from '@ember/service';\n\nimport { createFocusTrap } from 'focus-trap';\n\nexport default Component.extend({\n tagName: '',\n outAnimationClass: 'epm-out',\n animatingClass: '',\n\n modals: service(),\n\n optionsClassName: readOnly('modal._options.className'),\n\n modalElementId: null,\n focusTrapOptions: null,\n _animationEnd: null,\n\n init() {\n this._super(...arguments);\n\n set(this, 'modalElementId', guidFor(this));\n\n this.modal._componentInstance = this;\n\n let { focusTrapOptions: globalFocusTrapOptions } = this.modals;\n let { focusTrapOptions: localFocusTrapOptions } = this.modal._options;\n\n if (localFocusTrapOptions !== null) {\n this.focusTrapOptions = localFocusTrapOptions || globalFocusTrapOptions;\n }\n },\n\n didInsertElement() {\n this._super(...arguments);\n\n this._addFocusTrap();\n this._addAnimationListeners();\n\n // animating in starts when the element is added to the DOM. Inform the service about it.\n this.modals._onModalAnimationStart();\n },\n\n willDestroyElement() {\n this.destroyModal();\n\n this._super(...arguments);\n },\n\n _getElement() {\n return document.getElementById(this.modalElementId);\n },\n\n _addFocusTrap() {\n let element = this._getElement();\n\n if (!this.focusTrapOptions) {\n return;\n }\n\n let options = {\n ...this.focusTrapOptions,\n fallbackFocus: element,\n onDeactivate: (...args) => {\n this.focusTrapOptions.onDeactivate?.(...args);\n\n if (this.isDestroyed || this.isDestroying) {\n return;\n }\n\n this.closeModal();\n },\n };\n\n this.focusTrap = createFocusTrap(element, options);\n this.focusTrap.activate();\n },\n\n _removeFocusTrap(onDeactivate = this.focusTrapOptions?.onDeactivate) {\n if (!this.focusTrap) {\n return;\n }\n\n this.focusTrap.deactivate({ onDeactivate });\n },\n\n _addAnimationListeners() {\n this._animationEnd = ({ target, animationName }) => {\n // ignore animations bubbling up\n if (target !== this._getElement()) {\n return;\n }\n\n // An animation has ended, inform the modals service\n this.modals._onModalAnimationEnd();\n\n let isOutAnimation = animationName.substring(animationName.length - 4) === '-out';\n if (isOutAnimation) {\n this.modal._remove();\n }\n };\n\n let element = this._getElement();\n if (element) {\n element.addEventListener('animationend', this._animationEnd);\n }\n },\n\n _removeAnimationListeners() {\n if (!this._animationEnd) {\n return;\n }\n\n let element = this._getElement();\n if (element) {\n element.removeEventListener('animationend', this._animationEnd);\n }\n\n this._animationEnd = null;\n },\n\n destroyModal() {\n // Remove the focus trap without triggering the optional onDeactivate() hook\n this._removeFocusTrap(null);\n\n // Remove the animation listeners\n this._removeAnimationListeners();\n\n // make sure that we remove the modal, also resolving the test waiter\n this.modal._remove();\n },\n\n closeModal(result) {\n if (this.animatingClass !== '') {\n return;\n }\n\n this.modals._onModalAnimationStart();\n\n // This triggers the out animation, which in turn will remove the modal after it completes\n set(this, 'animatingClass', this.outAnimationClass);\n\n this.modal._resolve(result);\n },\n\n actions: {\n close(result) {\n this.closeModal(result);\n\n // Remove the focus trap, triggering the onDeactivate() hook\n this._removeFocusTrap();\n },\n },\n});\n"],"names":["setComponentTemplate","TEMPLATE","Component","extend","tagName","outAnimationClass","animatingClass","modals","service","optionsClassName","readOnly","modalElementId","focusTrapOptions","_animationEnd","init","_super","arguments","set","guidFor","modal","_componentInstance","globalFocusTrapOptions","localFocusTrapOptions","_options","didInsertElement","_addFocusTrap","_addAnimationListeners","_onModalAnimationStart","willDestroyElement","destroyModal","_getElement","document","getElementById","element","options","fallbackFocus","onDeactivate","args","isDestroyed","isDestroying","closeModal","focusTrap","createFocusTrap","activate","_removeFocusTrap","deactivate","target","animationName","_onModalAnimationEnd","isOutAnimation","substring","length","_remove","addEventListener","_removeAnimationListeners","removeEventListener","result","_resolve","actions","close"],"mappings":";;;;;;;;AACA,eAAe,kBAAkB,CAAC,sUAAsU;;ACOxW,eAAAA,oBAAA,CAAAC,QAAA,EAAeC,SAAS,CAACC,MAAM,CAAC;AAC9BC,EAAAA,OAAO,EAAE,EAAE;AACXC,EAAAA,iBAAiB,EAAE,SAAS;AAC5BC,EAAAA,cAAc,EAAE,EAAE;EAElBC,MAAM,EAAEC,MAAO,EAAE;AAEjBC,EAAAA,gBAAgB,EAAEC,QAAQ,CAAC,0BAA0B,CAAC;AAEtDC,EAAAA,cAAc,EAAE,IAAI;AACpBC,EAAAA,gBAAgB,EAAE,IAAI;AACtBC,EAAAA,aAAa,EAAE,IAAI;AAEnBC,EAAAA,IAAIA,GAAG;AACL,IAAA,IAAI,CAACC,MAAM,CAAC,GAAGC,SAAS,CAAC,CAAA;IAEzBC,GAAG,CAAC,IAAI,EAAE,gBAAgB,EAAEC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;AAE1C,IAAA,IAAI,CAACC,KAAK,CAACC,kBAAkB,GAAG,IAAI,CAAA;IAEpC,IAAI;AAAER,MAAAA,gBAAgB,EAAES,sBAAAA;KAAwB,GAAG,IAAI,CAACd,MAAM,CAAA;IAC9D,IAAI;AAAEK,MAAAA,gBAAgB,EAAEU,qBAAAA;AAAsB,KAAC,GAAG,IA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AA,IAAIG,OAAO,EAAE;MACXA,OAAO,CAACsB,mBAAmB,CAAC,cAAc,EAAE,IAAI,CAAC1C,aAAa,CAAC,CAAA;AACjE,KAAA;IAEA,IAAI,CAACA,aAAa,GAAG,IAAI,CAAA;GAC1B;AAEDgB,EAAAA,YAAYA,GAAG;AACb;AACA,IAAA,IAAI,CAACe,gBAAgB,CAAC,IAAI,CAAC,CAAA;;AAE3B;IACA,IAAI,CAACU,yBAAyB,EAAE,CAAA;;AAEhC;AACA,IAAA,IAAI,CAACnC,KAAK,CAACiC,OAAO,EAAE,CAAA;GACrB;EAEDZ,UAAUA,CAACgB,MAAM,EAAE;AACjB,IAAA,IAAI,IAAI,CAAClD,cAAc,KAAK,EAAE,EAAE;AAC9B,MAAA,OAAA;AACF,KAAA;AAEA,IAAA,IAAI,CAACC,MAAM,CAACoB,sBAAsB,EAAE,CAAA;;AAEpC;IACAV,GAAG,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,CAACZ,iBAAiB,CAAC,CAAA;AAEnD,IAAA,IAAI,CAACc,KAAK,CAACsC,QAAQ,CAACD,MAAM,CAAC,CAAA;GAC5B;AAEDE,EAAAA,OAAO,EAAE;IACPC,KAAKA,CAACH,MAAM,EAAE;AACZ,MAAA,IAAI,CAAChB,UAAU,CAACgB,MAAM,CAAC,CAAA;;AAEvB;MACA,IAAI,CAACZ,gBAAgB,EAAE,CAAA;AACzB,KAAA;AACF,GAAA;AACF,CAAC,CAAC,CAAA;;;;"}
1
+ {"version":3,"file":"epm-modal.js","sources":["../../src/components/epm-modal.js"],"sourcesContent":["import { action } from '@ember/object';\nimport * as emberService from '@ember/service';\n\nimport Component from '@glimmer/component';\nimport { tracked } from '@glimmer/tracking';\nimport { modifier } from 'ember-modifier';\nimport { createFocusTrap } from 'focus-trap';\n\nconst service = emberService.service ?? emberService.inject;\n\nexport default class EpmModal extends Component {\n @service modals;\n\n element = null;\n outAnimationClass = 'epm-out';\n _animationEnd = null;\n\n @tracked animatingClass = '';\n\n get optionsClassName() {\n return this.args.modal._options.className;\n }\n\n get focusTrapOptions() {\n let { focusTrapOptions: globalFocusTrapOptions } = this.modals;\n let { focusTrapOptions: localFocusTrapOptions } = this.args.modal._options;\n\n if (localFocusTrapOptions !== undefined) {\n return localFocusTrapOptions;\n }\n\n return globalFocusTrapOptions;\n }\n\n setup = modifier(element => {\n this.element = element;\n this._addFocusTrap();\n this._addAnimationListeners();\n\n // animating in starts when the element is added to the DOM. Inform the service about it.\n this.modals._onModalAnimationStart();\n\n return () => {\n this.destroyModal();\n };\n });\n\n constructor() {\n super(...arguments);\n\n this.args.modal._componentInstance = this;\n }\n\n _addFocusTrap() {\n if (!this.focusTrapOptions) {\n return;\n }\n\n let options = {\n ...this.focusTrapOptions,\n fallbackFocus: this.element,\n onDeactivate: (...args) => {\n this.focusTrapOptions.onDeactivate?.(...args);\n\n if (this.isDestroyed || this.isDestroying) {\n return;\n }\n\n this.closeModal();\n },\n };\n\n this.focusTrap = createFocusTrap(this.element, options);\n this.focusTrap.activate();\n }\n\n _removeFocusTrap(onDeactivate = this.focusTrapOptions?.onDeactivate) {\n if (!this.focusTrap) {\n return;\n }\n\n this.focusTrap.deactivate({ onDeactivate });\n }\n\n _addAnimationListeners() {\n this._animationEnd = ({ target, animationName }) => {\n // ignore animations bubbling up\n if (target !== this.element) {\n return;\n }\n\n // An animation has ended, inform the modals service\n this.modals._onModalAnimationEnd();\n\n let isOutAnimation = animationName.substring(animationName.length - 4) === '-out';\n if (isOutAnimation) {\n this.args.modal._remove();\n }\n };\n\n if (this.element) {\n this.element.addEventListener('animationend', this._animationEnd);\n }\n }\n\n _removeAnimationListeners() {\n if (!this._animationEnd) {\n return;\n }\n\n if (this.element) {\n this.element.removeEventListener('animationend', this._animationEnd);\n }\n\n this._animationEnd = null;\n }\n\n destroyModal() {\n // Remove the focus trap without triggering the optional onDeactivate() hook\n this._removeFocusTrap(null);\n\n // Remove the animation listeners\n this._removeAnimationListeners();\n\n // make sure that we remove the modal, also resolving the test waiter\n this.args.modal._remove();\n }\n\n closeModal(result) {\n if (this.animatingClass !== '') {\n return;\n }\n\n this.modals._onModalAnimationStart();\n\n // This triggers the out animation, which in turn will remove the modal after it completes\n this.animatingClass = this.outAnimationClass;\n\n this.args.modal._resolve(result);\n }\n\n @action\n close(result) {\n this.closeModal(result);\n\n // Remove the focus trap, triggering the onDeactivate() hook\n this._removeFocusTrap();\n }\n}\n"],"names":["service","emberService","inject","EpmModal","Component","g","prototype","i","void 0","element","outAnimationClass","_animationEnd","tracked","optionsClassName","args","modal","_options","className","focusTrapOptions","globalFocusTrapOptions","modals","localFocusTrapOptions","undefined","setup","modifier","_addFocusTrap","_addAnimationListeners","_onModalAnimationStart","destroyModal","constructor","arguments","_componentInstance","options","fallbackFocus","onDeactivate","isDestroyed","isDestroying","closeModal","focusTrap","createFocusTrap","activate","_removeFocusTrap","deactivate","target","animationName","_onModalAnimationEnd","isOutAnimation","substring","length","_remove","addEventListener","_removeAnimationListeners","removeEventListener","result","animatingClass","_resolve","close","n","action","setComponentTemplate","TEMPLATE"],"mappings":";;;;;;;;;;;;AAQA,MAAMA,OAAO,GAAGC,YAAY,CAACD,OAAO,IAAIC,YAAY,CAACC,MAAM;AAE5C,MAAMC,QAAQ,SAASC,SAAS,CAAC;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CAC7CN,OAAO,CAAA,CAAA;AAAA;AAAA,EAAA,OAAA,IAAAO,CAAA,CAAA,IAAA,EAAA,QAAA,CAAA,EAAAC,MAAA;AAERC,EAAAA,OAAO,GAAG,IAAI;AACdC,EAAAA,iBAAiB,GAAG,SAAS;AAC7BC,EAAAA,aAAa,GAAG,IAAI;AAAC,EAAA;IAAAN,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,gBAAA,EAAA,CAEpBM,OAAO,CAAA,EAAA,YAAA;AAAA,MAAA,OAAkB,EAAE;AAAA,IAAA,CAAA,CAAA;AAAA;AAAA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BA,GAAG;AAC1B,IAAA,IAAI,CAAC,IAAI,CAACxC,aAAa,EAAE;AACvB,MAAA;AACF,IAAA;IAEA,IAAI,IAAI,CAACF,OAAO,EAAE;MAChB,IAAI,CAACA,OAAO,CAAC2C,mBAAmB,CAAC,cAAc,EAAE,IAAI,CAACzC,aAAa,CAAC;AACtE,IAAA;IAEA,IAAI,CAACA,aAAa,GAAG,IAAI;AAC3B,EAAA;AAEAiB,EAAAA,YAAYA,GAAG;AACb;AACA,IAAA,IAAI,CAACa,gBAAgB,CAAC,IAAI,CAAC;;AAE3B;IACA,IAAI,CAACU,yBAAyB,EAAE;;AAEhC;AACA,IAAA,IAAI,CAACrC,IAAI,CAACC,KAAK,CAACkC,OAAO,EAAE;AAC3B,EAAA;EAEAZ,UAAUA,CAACgB,MAAM,EAAE;AACjB,IAAA,IAAI,IAAI,CAACC,cAAc,KAAK,EAAE,EAAE;AAC9B,MAAA;AACF,IAAA;AAEA,IAAA,IAAI,CAAClC,MAAM,CAACO,sBAAsB,EAAE;;AAEpC;AACA,IAAA,IAAI,CAAC2B,cAAc,GAAG,IAAI,CAAC5C,iBAAiB;IAE5C,IAAI,CAACI,IAAI,CAACC,KAAK,CAACwC,QAAQ,CAACF,MAAM,CAAC;AAClC,EAAA;EAGAG,KAAKA,CAACH,MAAM,EAAE;AACZ,IAAA,IAAI,CAAChB,UAAU,CAACgB,MAAM,CAAC;;AAEvB;IACA,IAAI,CAACZ,gBAAgB,EAAE;AACzB,EAAA;AAAC,EAAA;IAAAgB,CAAA,CAAA,IAAA,CAAAnD,SAAA,EAAA,OAAA,EAAA,CANAoD,MAAM,CAAA,CAAA;AAAA;AAOT;AAACC,oBAAA,CAAAC,QAAA,EA1IoBzD,QAAQ,CAAA;;;;"}
@@ -1,25 +1,29 @@
1
1
  import Helper from '@ember/component/helper';
2
- import { inject } from '@ember/service';
2
+ import * as emberService from '@ember/service';
3
3
  import { g, i } from 'decorator-transforms/runtime';
4
4
 
5
+ const service = emberService.service ?? emberService.inject;
5
6
  class OpenModalHelper extends Helper {
6
7
  static {
7
- g(this.prototype, "modals", [inject]);
8
+ g(this.prototype, "modals", [service]);
8
9
  }
9
10
  #modals = (i(this, "modals"), void 0);
10
11
  modal = null;
12
+ once = false;
11
13
  compute([modalComponent, data, options], {
12
14
  close
13
15
  }) {
16
+ if (this.modal || this.once) {
17
+ return;
18
+ }
19
+ this.once = true;
14
20
  this.showModal(modalComponent, data, options, close);
15
21
  }
16
22
  async showModal(modalComponent, data, options, close) {
17
23
  this.modal = this.modals.open(modalComponent, data, options);
18
24
  let success = await this.modal;
19
25
  this.modal = null;
20
- if (close) {
21
- close(success);
22
- }
26
+ close?.(success);
23
27
  }
24
28
  hideModal() {
25
29
  this.modal?.close();
@@ -1 +1 @@
1
- {"version":3,"file":"open-modal.js","sources":["../../src/helpers/open-modal.js"],"sourcesContent":["import Helper from '@ember/component/helper';\nimport { inject as service } from '@ember/service';\n\nexport default class OpenModalHelper extends Helper {\n @service modals;\n\n modal = null;\n\n compute([modalComponent, data, options], { close }) {\n this.showModal(modalComponent, data, options, close);\n }\n\n async showModal(modalComponent, data, options, close) {\n this.modal = this.modals.open(modalComponent, data, options);\n\n let success = await this.modal;\n\n this.modal = null;\n\n if (close) {\n close(success);\n }\n }\n\n hideModal() {\n this.modal?.close();\n }\n\n willDestroy() {\n this.hideModal();\n super.willDestroy(...arguments);\n }\n}\n"],"names":["OpenModalHelper","Helper","g","this","prototype","service","i","void 0","modal","compute","modalComponent","data","options","close","showModal","modals","open","success","hideModal","willDestroy","arguments"],"mappings":";;;;AAGe,MAAMA,eAAe,SAASC,MAAM,CAAC;AAAA,EAAA;AAAAC,IAAAA,CAAA,CAAAC,IAAA,CAAAC,SAAA,aACjDC,MAAO,CAAA,CAAA,CAAA;AAAA,GAAA;AAAA,EAAA,OAAA,IAAAC,CAAA,CAAAH,IAAA,aAAAI,KAAA,CAAA,EAAA;AAERC,EAAAA,KAAK,GAAG,IAAI,CAAA;EAEZC,OAAOA,CAAC,CAACC,cAAc,EAAEC,IAAI,EAAEC,OAAO,CAAC,EAAE;AAAEC,IAAAA,KAAAA;AAAM,GAAC,EAAE;IAClD,IAAI,CAACC,SAAS,CAACJ,cAAc,EAAEC,IAAI,EAAEC,OAAO,EAAEC,KAAK,CAAC,CAAA;AACtD,GAAA;EAEA,MAAMC,SAASA,CAACJ,cAAc,EAAEC,IAAI,EAAEC,OAAO,EAAEC,KAAK,EAAE;AACpD,IAAA,IAAI,CAACL,KAAK,GAAG,IAAI,CAACO,MAAM,CAACC,IAAI,CAACN,cAAc,EAAEC,IAAI,EAAEC,OAAO,CAAC,CAAA;AAE5D,IAAA,IAAIK,OAAO,GAAG,MAAM,IAAI,CAACT,KAAK,CAAA;IAE9B,IAAI,CAACA,KAAK,GAAG,IAAI,CAAA;AAEjB,IAAA,IAAIK,KAAK,EAAE;MACTA,KAAK,CAACI,OAAO,CAAC,CAAA;AAChB,KAAA;AACF,GAAA;AAEAC,EAAAA,SAASA,GAAG;AACV,IAAA,IAAI,CAACV,KAAK,EAAEK,KAAK,EAAE,CAAA;AACrB,GAAA;AAEAM,EAAAA,WAAWA,GAAG;IACZ,IAAI,CAACD,SAAS,EAAE,CAAA;AAChB,IAAA,KAAK,CAACC,WAAW,CAAC,GAAGC,SAAS,CAAC,CAAA;AACjC,GAAA;AACF;;;;"}
1
+ {"version":3,"file":"open-modal.js","sources":["../../src/helpers/open-modal.js"],"sourcesContent":["import Helper from '@ember/component/helper';\nimport * as emberService from '@ember/service';\nconst service = emberService.service ?? emberService.inject;\n\nexport default class OpenModalHelper extends Helper {\n @service modals;\n\n modal = null;\n once = false;\n\n compute([modalComponent, data, options], { close }) {\n if (this.modal || this.once) {\n return;\n }\n\n this.once = true;\n\n this.showModal(modalComponent, data, options, close);\n }\n\n async showModal(modalComponent, data, options, close) {\n this.modal = this.modals.open(modalComponent, data, options);\n\n let success = await this.modal;\n\n this.modal = null;\n\n close?.(success);\n }\n\n hideModal() {\n this.modal?.close();\n }\n\n willDestroy() {\n this.hideModal();\n super.willDestroy(...arguments);\n }\n}\n"],"names":["service","emberService","inject","OpenModalHelper","Helper","g","prototype","i","void 0","modal","once","compute","modalComponent","data","options","close","showModal","modals","open","success","hideModal","willDestroy","arguments"],"mappings":";;;;AAEA,MAAMA,OAAO,GAAGC,YAAY,CAACD,OAAO,IAAIC,YAAY,CAACC,MAAM;AAE5C,MAAMC,eAAe,SAASC,MAAM,CAAC;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CACjDN,OAAO,CAAA,CAAA;AAAA;AAAA,EAAA,OAAA,IAAAO,CAAA,CAAA,IAAA,EAAA,QAAA,CAAA,EAAAC,MAAA;AAERC,EAAAA,KAAK,GAAG,IAAI;AACZC,EAAAA,IAAI,GAAG,KAAK;EAEZC,OAAOA,CAAC,CAACC,cAAc,EAAEC,IAAI,EAAEC,OAAO,CAAC,EAAE;AAAEC,IAAAA;AAAM,GAAC,EAAE;AAClD,IAAA,IAAI,IAAI,CAACN,KAAK,IAAI,IAAI,CAACC,IAAI,EAAE;AAC3B,MAAA;AACF,IAAA;IAEA,IAAI,CAACA,IAAI,GAAG,IAAI;IAEhB,IAAI,CAACM,SAAS,CAACJ,cAAc,EAAEC,IAAI,EAAEC,OAAO,EAAEC,KAAK,CAAC;AACtD,EAAA;EAEA,MAAMC,SAASA,CAACJ,cAAc,EAAEC,IAAI,EAAEC,OAAO,EAAEC,KAAK,EAAE;AACpD,IAAA,IAAI,CAACN,KAAK,GAAG,IAAI,CAACQ,MAAM,CAACC,IAAI,CAACN,cAAc,EAAEC,IAAI,EAAEC,OAAO,CAAC;AAE5D,IAAA,IAAIK,OAAO,GAAG,MAAM,IAAI,CAACV,KAAK;IAE9B,IAAI,CAACA,KAAK,GAAG,IAAI;IAEjBM,KAAK,GAAGI,OAAO,CAAC;AAClB,EAAA;AAEAC,EAAAA,SAASA,GAAG;AACV,IAAA,IAAI,CAACX,KAAK,EAAEM,KAAK,EAAE;AACrB,EAAA;AAEAM,EAAAA,WAAWA,GAAG;IACZ,IAAI,CAACD,SAAS,EAAE;AAChB,IAAA,KAAK,CAACC,WAAW,CAAC,GAAGC,SAAS,CAAC;AACjC,EAAA;AACF;;;;"}
package/dist/modal.js CHANGED
@@ -1,10 +1,15 @@
1
- import { computed, set } from '@ember/object';
2
1
  import { waitForPromise } from '@ember/test-waiters';
2
+ import { tracked } from '@glimmer/tracking';
3
3
  import { defer } from 'rsvp';
4
- import { n } from 'decorator-transforms/runtime';
4
+ import { g, i } from 'decorator-transforms/runtime';
5
5
 
6
- // eslint-disable-next-line ember/no-computed-properties-in-native-classes
7
6
  class Modal {
7
+ static {
8
+ g(this.prototype, "_deferredOutAnimation", [tracked], function () {
9
+ return undefined;
10
+ });
11
+ }
12
+ #_deferredOutAnimation = (i(this, "_deferredOutAnimation"), void 0);
8
13
  constructor(service, componentClass, data, options = {}) {
9
14
  this._service = service;
10
15
  this._componentClass = componentClass;
@@ -16,7 +21,6 @@ class Modal {
16
21
  };
17
22
  this._result = undefined;
18
23
  this._deferred = defer();
19
- this._deferredOutAnimation = undefined;
20
24
  this._componentInstance = undefined;
21
25
  }
22
26
  get result() {
@@ -25,9 +29,6 @@ class Modal {
25
29
  get isClosing() {
26
30
  return Boolean(this._deferredOutAnimation);
27
31
  }
28
- static {
29
- n(this.prototype, "isClosing", [computed('_deferredOutAnimation')]);
30
- }
31
32
  close(result) {
32
33
  if (this._componentInstance) {
33
34
  this._componentInstance.closeModal(result);
@@ -46,7 +47,7 @@ class Modal {
46
47
  if (this._deferredOutAnimation) {
47
48
  return;
48
49
  }
49
- set(this, '_deferredOutAnimation', defer());
50
+ this._deferredOutAnimation = defer();
50
51
  if (this._options.onAnimationModalOutEnd) {
51
52
  this._deferredOutAnimation.promise.then(() => this._options.onAnimationModalOutEnd()).catch(() => {});
52
53
  }
@@ -55,7 +56,10 @@ class Modal {
55
56
  waitForPromise(this._deferredOutAnimation.promise);
56
57
  }
57
58
  _remove() {
58
- this._service._stack.removeObject(this);
59
+ const index = this._service._stack.indexOf(this);
60
+ if (index !== -1) {
61
+ this._service._stack.splice(index, 1);
62
+ }
59
63
  if (this._service._stack.length === 0) {
60
64
  this._service._onLastModalRemoved();
61
65
  }
package/dist/modal.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"modal.js","sources":["../src/modal.js"],"sourcesContent":["// eslint-disable-next-line ember/no-computed-properties-in-native-classes\nimport { computed, set } from '@ember/object';\nimport { waitForPromise } from '@ember/test-waiters';\n\nimport { defer } from 'rsvp';\n\n/**\n * @typedef {Object} ModalOptions\n * @property {Function} [onAnimationModalOutEnd]\n * @property {String} [className] - CSS class name passed to the modal element\n */\n\n/**\n * @class Modal\n * @param {Service} service\n * @param {String} componentClass\n * @param {any} data\n * @param {ModalOptions} options\n * @method close - closes the modal\n * @method then - resolves when the modal is closed\n */\nexport default class Modal {\n constructor(service, componentClass, data, options = {}) {\n this._service = service;\n this._componentClass = componentClass;\n this._data = data;\n this._options = {\n className: '',\n onAnimationModalOutEnd: undefined,\n ...options,\n };\n this._result = undefined;\n this._deferred = defer();\n this._deferredOutAnimation = undefined;\n this._componentInstance = undefined;\n }\n\n get result() {\n return this._result;\n }\n\n @computed('_deferredOutAnimation')\n get isClosing() {\n return Boolean(this._deferredOutAnimation);\n }\n\n close(result) {\n if (this._componentInstance) {\n this._componentInstance.closeModal(result);\n }\n }\n\n then(onFulfilled, onRejected) {\n return this._deferred.promise.then(onFulfilled, onRejected);\n }\n\n _destroy() {\n if (!this._componentInstance) {\n return;\n }\n\n this._componentInstance.destroyModal();\n }\n\n _resolve(result) {\n if (this._deferredOutAnimation) {\n return;\n }\n\n set(this, '_deferredOutAnimation', defer());\n if (this._options.onAnimationModalOutEnd) {\n this._deferredOutAnimation.promise.then(() => this._options.onAnimationModalOutEnd()).catch(() => {});\n }\n\n this._result = result;\n this._deferred.resolve(result);\n\n waitForPromise(this._deferredOutAnimation.promise);\n }\n\n _remove() {\n this._service._stack.removeObject(this);\n\n if (this._service._stack.length === 0) {\n this._service._onLastModalRemoved();\n }\n\n this._componentInstance = undefined;\n\n if (this._deferredOutAnimation) {\n this._deferredOutAnimation.resolve();\n }\n }\n}\n"],"names":["Modal","constructor","service","componentClass","data","options","_service","_componentClass","_data","_options","className","onAnimationModalOutEnd","undefined","_result","_deferred","defer","_deferredOutAnimation","_componentInstance","result","isClosing","Boolean","n","this","prototype","computed","close","closeModal","then","onFulfilled","onRejected","promise","_destroy","destroyModal","_resolve","set","catch","resolve","waitForPromise","_remove","_stack","removeObject","length","_onLastModalRemoved"],"mappings":";;;;;AAAA;AAqBe,MAAMA,KAAK,CAAC;EACzBC,WAAWA,CAACC,OAAO,EAAEC,cAAc,EAAEC,IAAI,EAAEC,OAAO,GAAG,EAAE,EAAE;IACvD,IAAI,CAACC,QAAQ,GAAGJ,OAAO,CAAA;IACvB,IAAI,CAACK,eAAe,GAAGJ,cAAc,CAAA;IACrC,IAAI,CAACK,KAAK,GAAGJ,IAAI,CAAA;IACjB,IAAI,CAACK,QAAQ,GAAG;AACdC,MAAAA,SAAS,EAAE,EAAE;AACbC,MAAAA,sBAAsB,EAAEC,SAAS;MACjC,GAAGP,OAAAA;KACJ,CAAA;IACD,IAAI,CAACQ,OAAO,GAAGD,SAAS,CAAA;AACxB,IAAA,IAAI,CAACE,SAAS,GAAGC,KAAK,EAAE,CAAA;IACxB,IAAI,CAACC,qBAAqB,GAAGJ,SAAS,CAAA;IACtC,IAAI,CAACK,kBAAkB,GAAGL,SAAS,CAAA;AACrC,GAAA;EAEA,IAAIM,MAAMA,GAAG;IACX,OAAO,IAAI,CAACL,OAAO,CAAA;AACrB,GAAA;EAEA,IACIM,SAASA,GAAG;AACd,IAAA,OAAOC,OAAO,CAAC,IAAI,CAACJ,qBAAqB,CAAC,CAAA;AAC5C,GAAA;AAAC,EAAA;IAAAK,CAAA,CAAAC,IAAA,CAAAC,SAAA,gBAHAC,QAAQ,CAAC,uBAAuB,CAAC,CA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AEvC,IAAI,IAAI,CAAClC,QAAQ,CAACiC,MAAM,CAACE,MAAM,KAAK,CAAC,EAAE;AACrC,MAAA,IAAI,CAACnC,QAAQ,CAACoC,mBAAmB,EAAE,CAAA;AACrC,KAAA;IAEA,IAAI,CAACzB,kBAAkB,GAAGL,SAAS,CAAA;IAEnC,IAAI,IAAI,CAACI,qBAAqB,EAAE;AAC9B,MAAA,IAAI,CAACA,qBAAqB,CAACoB,OAAO,EAAE,CAAA;AACtC,KAAA;AACF,GAAA;AACF;;;;"}
1
+ {"version":3,"file":"modal.js","sources":["../src/modal.js"],"sourcesContent":["import { waitForPromise } from '@ember/test-waiters';\n\nimport { tracked } from '@glimmer/tracking';\nimport { defer } from 'rsvp';\n\n/**\n * @typedef {Object} ModalOptions\n * @property {Function} [onAnimationModalOutEnd]\n * @property {String} [className] - CSS class name passed to the modal element\n */\n\n/**\n * @class Modal\n * @param {Service} service\n * @param {String} componentClass\n * @param {any} data\n * @param {ModalOptions} options\n * @method close - closes the modal\n * @method then - resolves when the modal is closed\n */\nexport default class Modal {\n @tracked _deferredOutAnimation = undefined;\n\n constructor(service, componentClass, data, options = {}) {\n this._service = service;\n this._componentClass = componentClass;\n this._data = data;\n this._options = {\n className: '',\n onAnimationModalOutEnd: undefined,\n ...options,\n };\n this._result = undefined;\n this._deferred = defer();\n this._componentInstance = undefined;\n }\n\n get result() {\n return this._result;\n }\n\n get isClosing() {\n return Boolean(this._deferredOutAnimation);\n }\n\n close(result) {\n if (this._componentInstance) {\n this._componentInstance.closeModal(result);\n }\n }\n\n then(onFulfilled, onRejected) {\n return this._deferred.promise.then(onFulfilled, onRejected);\n }\n\n _destroy() {\n if (!this._componentInstance) {\n return;\n }\n\n this._componentInstance.destroyModal();\n }\n\n _resolve(result) {\n if (this._deferredOutAnimation) {\n return;\n }\n\n this._deferredOutAnimation = defer();\n if (this._options.onAnimationModalOutEnd) {\n this._deferredOutAnimation.promise.then(() => this._options.onAnimationModalOutEnd()).catch(() => {});\n }\n\n this._result = result;\n this._deferred.resolve(result);\n\n waitForPromise(this._deferredOutAnimation.promise);\n }\n\n _remove() {\n const index = this._service._stack.indexOf(this);\n if (index !== -1) {\n this._service._stack.splice(index, 1);\n }\n\n if (this._service._stack.length === 0) {\n this._service._onLastModalRemoved();\n }\n\n this._componentInstance = undefined;\n\n if (this._deferredOutAnimation) {\n this._deferredOutAnimation.resolve();\n }\n }\n}\n"],"names":["Modal","g","prototype","tracked","undefined","i","void 0","constructor","service","componentClass","data","options","_service","_componentClass","_data","_options","className","onAnimationModalOutEnd","_result","_deferred","defer","_componentInstance","result","isClosing","Boolean","_deferredOutAnimation","close","closeModal","then","onFulfilled","onRejected","promise","_destroy","destroyModal","_resolve","catch","resolve","waitForPromise","_remove","index","_stack","indexOf","splice","length","_onLastModalRemoved"],"mappings":";;;;;AAoBe,MAAMA,KAAK,CAAC;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,uBAAA,EAAA,CACxBC,OAAO,CAAA,EAAA,YAAA;AAAA,MAAA,OAAyBC,SAAS;AAAA,IAAA,CAAA,CAAA;AAAA;AAAA,EAAA,sBAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,uBAAA,CAAA,EAAAC,MAAA;EAE1CC,WAAWA,CAACC,OAAO,EAAEC,cAAc,EAAEC,IAAI,EAAEC,OAAO,GAAG,EAAE,EAAE;IACvD,IAAI,CAACC,QAAQ,GAAGJ,OAAO;IACvB,IAAI,CAACK,eAAe,GAAGJ,cAAc;IACrC,IAAI,CAACK,KAAK,GAAGJ,IAAI;IACjB,IAAI,CAACK,QAAQ,GAAG;AACdC,MAAAA,SAAS,EAAE,EAAE;AACbC,MAAAA,sBAAsB,EAAEb,SAAS;MACjC,GAAGO;KACJ;IACD,IAAI,CAACO,OAAO,GAAGd,SAAS;AACxB,IAAA,IAAI,CAACe,SAAS,GAAGC,KAAK,EAAE;IACxB,IAAI,CAACC,kBAAkB,GAAGjB,SAAS;AACrC,EAAA;E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K,GAAG,IAAI,CAAC3B,QAAQ,CAAC4B,MAAM,CAACC,OAAO,CAAC,IAAI,CAAC;AAChD,IAAA,IAAIF,KAAK,KAAK,EAAE,EAAE;MAChB,IAAI,CAAC3B,QAAQ,CAAC4B,MAAM,CAACE,MAAM,CAACH,KAAK,EAAE,CAAC,CAAC;AACvC,IAAA;IAEA,IAAI,IAAI,CAAC3B,QAAQ,CAAC4B,MAAM,CAACG,MAAM,KAAK,CAAC,EAAE;AACrC,MAAA,IAAI,CAAC/B,QAAQ,CAACgC,mBAAmB,EAAE;AACrC,IAAA;IAEA,IAAI,CAACvB,kBAAkB,GAAGjB,SAAS;IAEnC,IAAI,IAAI,CAACqB,qBAAqB,EAAE;AAC9B,MAAA,IAAI,CAACA,qBAAqB,CAACW,OAAO,EAAE;AACtC,IAAA;AACF,EAAA;AACF;;;;"}
@@ -1,31 +1,32 @@
1
- import { A } from '@ember/array';
2
- import { computed } from '@ember/object';
3
- import { alias } from '@ember/object/computed';
4
- import Service from '@ember/service';
1
+ import emberService__default from '@ember/service';
2
+ import { TrackedArray } from 'tracked-built-ins';
5
3
  import Modal from '../modal.js';
6
4
 
7
- var modals = Service.extend({
8
- count: computed('_stack.@each.isClosing', function () {
5
+ class ModalsService extends emberService__default {
6
+ _stack = new TrackedArray([]);
7
+ focusTrapOptions = undefined;
8
+ get count() {
9
9
  return this._stack.filter(modal => !modal.isClosing).length;
10
- }),
11
- top: alias('_stack.lastObject'),
12
- focusTrapOptions: undefined,
13
- init() {
14
- this._super(...arguments);
15
- this._stack = A([]);
10
+ }
11
+ get top() {
12
+ return this._stack.at(-1);
13
+ }
14
+ constructor() {
15
+ super(...arguments);
16
16
  if (this.focusTrapOptions !== null) {
17
17
  this.focusTrapOptions = {
18
18
  ...(this.focusTrapOptions ?? {}),
19
19
  clickOutsideDeactivates: this.focusTrapOptions?.clickOutsideDeactivates ?? true
20
20
  };
21
21
  }
22
- },
22
+ }
23
23
  willDestroy() {
24
24
  this._onLastModalRemoved();
25
25
  this._onModalAnimationEnd();
26
26
  this._destroyModals();
27
- this._super(...arguments);
28
- },
27
+ super.willDestroy(...arguments);
28
+ }
29
+
29
30
  /**
30
31
  * @param {*} componentClass component class
31
32
  * @param {*} data passed to the component template
@@ -34,30 +35,30 @@ var modals = Service.extend({
34
35
  */
35
36
  open(componentClass, data, options) {
36
37
  let modal = new Modal(this, componentClass, data, options);
37
- this._stack.pushObject(modal);
38
+ this._stack.push(modal);
38
39
  if (this._stack.length === 1) {
39
40
  this._onFirstModalAdded();
40
41
  }
41
42
  return modal;
42
- },
43
+ }
43
44
  _destroyModals() {
44
- this._stack.forEach(modal => {
45
+ for (let modal of this._stack) {
45
46
  modal._destroy();
46
- });
47
- },
47
+ }
48
+ }
48
49
  _onFirstModalAdded() {
49
50
  document.body.classList.add('epm-scrolling-disabled');
50
- },
51
+ }
51
52
  _onLastModalRemoved() {
52
53
  document.body.classList.remove('epm-scrolling-disabled');
53
- },
54
+ }
54
55
  _onModalAnimationStart() {
55
56
  document.body.classList.add('epm-animating');
56
- },
57
+ }
57
58
  _onModalAnimationEnd() {
58
59
  document.body.classList.remove('epm-animating');
59
60
  }
60
- });
61
+ }
61
62
 
62
- export { modals as default };
63
+ export { ModalsService as default };
63
64
  //# sourceMappingURL=modals.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"modals.js","sources":["../../src/services/modals.js"],"sourcesContent":["import { A } from '@ember/array';\nimport { computed } from '@ember/object';\nimport { alias } from '@ember/object/computed';\nimport Service from '@ember/service';\n\nimport Modal from '../modal';\n\nexport default Service.extend({\n count: computed('_stack.@each.isClosing', function () {\n return this._stack.filter(modal => !modal.isClosing).length;\n }),\n top: alias('_stack.lastObject'),\n\n focusTrapOptions: undefined,\n\n init() {\n this._super(...arguments);\n this._stack = A([]);\n\n if (this.focusTrapOptions !== null) {\n this.focusTrapOptions = {\n ...(this.focusTrapOptions ?? {}),\n clickOutsideDeactivates: this.focusTrapOptions?.clickOutsideDeactivates ?? true,\n };\n }\n },\n\n willDestroy() {\n this._onLastModalRemoved();\n this._onModalAnimationEnd();\n this._destroyModals();\n\n this._super(...arguments);\n },\n\n /**\n * @param {*} componentClass component class\n * @param {*} data passed to the component template\n * @param {ModalOptions} options applied to the modal\n * @returns {Modal}\n */\n open(componentClass, data, options) {\n let modal = new Modal(this, componentClass, data, options);\n\n this._stack.pushObject(modal);\n\n if (this._stack.length === 1) {\n this._onFirstModalAdded();\n }\n\n return modal;\n },\n\n _destroyModals() {\n this._stack.forEach(modal => {\n modal._destroy();\n });\n },\n\n _onFirstModalAdded() {\n document.body.classList.add('epm-scrolling-disabled');\n },\n\n _onLastModalRemoved() {\n document.body.classList.remove('epm-scrolling-disabled');\n },\n\n _onModalAnimationStart() {\n document.body.classList.add('epm-animating');\n },\n\n _onModalAnimationEnd() {\n document.body.classList.remove('epm-animating');\n },\n});\n"],"names":["Service","extend","count","computed","_stack","filter","modal","isClosing","length","top","alias","focusTrapOptions","undefined","init","_super","arguments","A","clickOutsideDeactivates","willDestroy","_onLastModalRemoved","_onModalAnimationEnd","_destroyModals","open","componentClass","data","options","Modal","pushObject","_onFirstModalAdded","forEach","_destroy","document","body","classList","add","remove","_onModalAnimationStart"],"mappings":";;;;;;AAOA,aAAeA,OAAO,CAACC,MAAM,CAAC;AAC5BC,EAAAA,KAAK,EAAEC,QAAQ,CAAC,wBAAwB,EAAE,YAAY;AACpD,IAAA,OAAO,IAAI,CAACC,MAAM,CAACC,MAAM,CAACC,KAAK,IAAI,CAACA,KAAK,CAACC,SAAS,CAAC,CAACC,MAAM,CAAA;AAC7D,GAAC,CAAC;AACFC,EAAAA,GAAG,EAAEC,KAAK,CAAC,mBAAmB,CAAC;AAE/BC,EAAAA,gBAAgB,EAAEC,SAAS;AAE3BC,EAAAA,IAAIA,GAAG;AACL,IAAA,IAAI,CAACC,MAAM,CAAC,GAAGC,SAAS,CAAC,CAAA;AACzB,IAAA,IAAI,CAACX,MAAM,GAAGY,CAAC,CAAC,EAAE,CAAC,CAA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AAS,CAACE,MAAM,CAAC,wBAAwB,CAAC,CAAA;GACzD;AAEDC,EAAAA,sBAAsBA,GAAG;IACvBL,QAAQ,CAACC,IAAI,CAACC,SAAS,CAACC,GAAG,CAAC,eAAe,CAAC,CAAA;GAC7C;AAEDd,EAAAA,oBAAoBA,GAAG;IACrBW,QAAQ,CAACC,IAAI,CAACC,SAAS,CAACE,MAAM,CAAC,eAAe,CAAC,CAAA;AACjD,GAAA;AACF,CAAC,CAAC;;;;"}
1
+ {"version":3,"file":"modals.js","sources":["../../src/services/modals.js"],"sourcesContent":["import Service from '@ember/service';\n\nimport { TrackedArray } from 'tracked-built-ins';\n\nimport Modal from '../modal';\n\nexport default class ModalsService extends Service {\n _stack = new TrackedArray([]);\n\n focusTrapOptions = undefined;\n\n get count() {\n return this._stack.filter(modal => !modal.isClosing).length;\n }\n\n get top() {\n return this._stack.at(-1);\n }\n\n constructor() {\n super(...arguments);\n\n if (this.focusTrapOptions !== null) {\n this.focusTrapOptions = {\n ...(this.focusTrapOptions ?? {}),\n clickOutsideDeactivates: this.focusTrapOptions?.clickOutsideDeactivates ?? true,\n };\n }\n }\n\n willDestroy() {\n this._onLastModalRemoved();\n this._onModalAnimationEnd();\n this._destroyModals();\n\n super.willDestroy(...arguments);\n }\n\n /**\n * @param {*} componentClass component class\n * @param {*} data passed to the component template\n * @param {ModalOptions} options applied to the modal\n * @returns {Modal}\n */\n open(componentClass, data, options) {\n let modal = new Modal(this, componentClass, data, options);\n\n this._stack.push(modal);\n\n if (this._stack.length === 1) {\n this._onFirstModalAdded();\n }\n\n return modal;\n }\n\n _destroyModals() {\n for (let modal of this._stack) {\n modal._destroy();\n }\n }\n\n _onFirstModalAdded() {\n document.body.classList.add('epm-scrolling-disabled');\n }\n\n _onLastModalRemoved() {\n document.body.classList.remove('epm-scrolling-disabled');\n }\n\n _onModalAnimationStart() {\n document.body.classList.add('epm-animating');\n }\n\n _onModalAnimationEnd() {\n document.body.classList.remove('epm-animating');\n }\n}\n"],"names":["ModalsService","Service","_stack","TrackedArray","focusTrapOptions","undefined","count","filter","modal","isClosing","length","top","at","constructor","arguments","clickOutsideDeactivates","willDestroy","_onLastModalRemoved","_onModalAnimationEnd","_destroyModals","open","componentClass","data","options","Modal","push","_onFirstModalAdded","_destroy","document","body","classList","add","remove","_onModalAnimationStart"],"mappings":";;;;AAMe,MAAMA,aAAa,SAASC,qBAAO,CAAC;AACjDC,EAAAA,MAAM,GAAG,IAAIC,YAAY,CAAC,EAAE,CAAC;AAE7BC,EAAAA,gBAAgB,GAAGC,SAAS;EAE5B,IAAIC,KAAKA,GAAG;AACV,IAAA,OAAO,IAAI,CAACJ,MAAM,CAACK,MAAM,CAACC,KAAK,IAAI,CAACA,KAAK,CAACC,SAAS,CAAC,CAACC,MAAM;AAC7D,EAAA;EAEA,IAAIC,GAAGA,GAAG;IACR,OAAO,IAAI,CAACT,MAAM,CAACU,EAAE,CAAC,EAAE,CAAC;AAC3B,EAAA;AAEAC,EAAAA,WAAWA,GAAG;IACZ,KAAK,CAAC,GAAGC,SAAS,CAAC;AAEnB,IAAA,IAAI,IAAI,CAACV,gBAAgB,KAAK,IAAI,EAAE;MAClC,IAAI,CAACA,gBAAgB,GAAG;AACtB,QAAA,IAAI,IAAI,CAACA,gBAAgB,IAAI,EAAE,CAAC;AAChCW,QAAAA,uBAAuB,EAAE,IAAI,CAACX,gBAAgB,EAAEW,uBAAuB,IAAI;OAC5E;AACH,IAAA;AACF,EAAA;AAEAC,EAAAA,WAAWA,GAAG;IACZ,IAAI,CAACC,mBAAmB,EAAE;IAC1B,IAAI,CAACC,oBAAoB,EAAE;IAC3B,IAAI,CAACC,cAAc,EAAE;AAErB,IAAA,KAAK,CAACH,WAAW,CAAC,GAAGF,SAAS,CAAC;AACjC,EAAA;;AAEA;AACF;AACA;AACA;AACA;AACA;AACEM,EAAAA,IAAIA,CAACC,cAAc,EAAEC,IAAI,EAAEC,OAAO,EAAE;AAClC,IAAA,IAAIf,KAAK,GAAG,IAAIgB,KAAK,CAAC,IAAI,EAAEH,cAAc,EAAEC,IAAI,EAAEC,OAAO,CAAC;AAE1D,IAAA,IAAI,CAACrB,MAAM,CAACuB,IAAI,CAACjB,KAAK,CAAC;AAEvB,IAAA,IAAI,IAAI,CAACN,MAAM,CAACQ,MAAM,KAAK,CAAC,EAAE;MAC5B,IAAI,CAACgB,kBAAkB,EAAE;AAC3B,IAAA;AAEA,IAAA,OAAOlB,KAAK;AACd,EAAA;AAEAW,EAAAA,cAAcA,GAAG;AACf,IAAA,KAAK,IAAIX,KAAK,IAAI,IAAI,CAACN,MAAM,EAAE;MAC7BM,KAAK,CAACmB,QAAQ,EAAE;AAClB,IAAA;AACF,EAAA;AAEAD,EAAAA,kBAAkBA,GAAG;IACnBE,QAAQ,CAACC,IAAI,CAACC,SAAS,CAACC,GAAG,CAAC,wBAAwB,CAAC;AACvD,EAAA;AAEAd,EAAAA,mBAAmBA,GAAG;IACpBW,QAAQ,CAACC,IAAI,CAACC,SAAS,CAACE,MAAM,CAAC,wBAAwB,CAAC;AAC1D,EAAA;AAEAC,EAAAA,sBAAsBA,GAAG;IACvBL,QAAQ,CAACC,IAAI,CAACC,SAAS,CAACC,GAAG,CAAC,eAAe,CAAC;AAC9C,EAAA;AAEAb,EAAAA,oBAAoBA,GAAG;IACrBU,QAAQ,CAACC,IAAI,CAACC,SAAS,CAACE,MAAM,CAAC,eAAe,CAAC;AACjD,EAAA;AACF;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/test-support/index.js"],"sourcesContent":["import { settled } from '@ember/test-helpers';\n\nfunction setMinimum(propertyName) {\n document.documentElement.style.setProperty(propertyName, '0.001s');\n}\n\nfunction unsetMinimum(propertyName) {\n document.documentElement.style.removeProperty(propertyName);\n}\n\nexport function setupPromiseModals(hooks) {\n hooks.beforeEach(function () {\n setMinimum('--epm-animation-backdrop-in-duration');\n setMinimum('--epm-animation-backdrop-out-duration');\n setMinimum('--epm-animation-backdrop-in-delay');\n setMinimum('--epm-animation-backdrop-out-delay');\n setMinimum('--epm-animation-modal-in-duration');\n setMinimum('--epm-animation-modal-out-duration');\n setMinimum('--epm-animation-modal-in-delay');\n setMinimum('--epm-animation-modal-out-delay');\n\n this.modals = this.owner.lookup('service:modals');\n });\n\n hooks.afterEach(async function () {\n // be sure to close all modals after a test\n if (this.modals) {\n this.modals._destroyModals();\n }\n\n delete this.modals;\n\n unsetMinimum('--epm-animation-backdrop-in-duration');\n unsetMinimum('--epm-animation-backdrop-out-duration');\n unsetMinimum('--epm-animation-backdrop-in-delay');\n unsetMinimum('--epm-animation-backdrop-out-delay');\n unsetMinimum('--epm-animation-modal-in-duration');\n unsetMinimum('--epm-animation-modal-out-duration');\n unsetMinimum('--epm-animation-modal-in-delay');\n unsetMinimum('--epm-animation-modal-out-delay');\n\n // wait for any registered test waiters to settle\n await settled();\n });\n}\n"],"names":["setMinimum","propertyName","document","documentElement","style","setProperty","unsetMinimum","removeProperty","setupPromiseModals","hooks","beforeEach","modals","owner","lookup","afterEach","_destroyModals","settled"],"mappings":";;AAEA,SAASA,UAAUA,CAACC,YAAY,EAAE;EAChCC,QAAQ,CAACC,eAAe,CAACC,KAAK,CAACC,WAAW,CAACJ,YAAY,EAAE,QAAQ,CAAC,CAAA;AACpE,CAAA;AAEA,SAASK,YAAYA,CAACL,YAAY,EAAE;EAClCC,QAAQ,CAACC,eAAe,CAACC,KAAK,CAACG,cAAc,CAACN,YAAY,CAAC,CAAA;AAC7D,CAAA;AAEO,SAASO,kBAAkBA,CAACC,KAAK,EAAE;EACxCA,KAAK,CAACC,UAAU,CAAC,YAAY;IAC3BV,UAAU,CAAC,sCAAsC,CAAC,CAAA;IAClDA,UAAU,CAAC,uCAAuC,CAAC,CAAA;IACnDA,UAAU,CAAC,mCAAmC,CAAC,CAAA;IAC/CA,UAAU,CAAC,oCAAoC,CAAC,CAAA;IAChDA,UAAU,CAAC,mCAAmC,CAAC,CAAA;IAC/CA,UAAU,CAAC,oCAAoC,CAAC,CAAA;IAChDA,UAAU,CAAC,gCAAgC,CAAC,CAAA;IAC5CA,UAAU,CAAC,iCAAiC,CAAC,CAAA;IAE7C,IAAI,CAACW,MAAM,GAAG,IAAI,CAACC,KAAK,CAACC,MAAM,CAAC,gBAAgB,CAAC,CAAA;AACnD,GAAC,CAAC,CAAA;EAEFJ,KAAK,CAACK,SAAS,CAAC,kBAAkB;AAChC;IACA,IAAI,IAAI,CAACH,MAAM,EAAE;AACf,MAAA,IAAI,CAACA,MAAM,CAACI,cAAc,EAAE,CAAA;AAC9B,KAAA;IAEA,OAAO,IAAI,CAACJ,MAAM,CAAA;IAElBL,YAAY,CAAC,sCAAsC,CAAC,CAAA;IACpDA,YAAY,CAAC,uCAAuC,CAAC,CAAA;IACrDA,YAAY,CAAC,mCAAmC,CAAC,CAAA;IACjDA,YAAY,CAAC,oCAAoC,CAAC,CAAA;IAClDA,YAAY,CAAC,mCAAmC,CAAC,CAAA;IACjDA,YAAY,CAAC,oCAAoC,CAAC,CAAA;IAClDA,YAAY,CAAC,gCAAgC,CAAC,CAAA;IAC9CA,YAAY,CAAC,iCAAiC,CAAC,CAAA;;AAE/C;IACA,MAAMU,OAAO,EAAE,CAAA;AACjB,GAAC,CAAC,CAAA;AACJ;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/test-support/index.js"],"sourcesContent":["import { settled } from '@ember/test-helpers';\n\nfunction setMinimum(propertyName) {\n document.documentElement.style.setProperty(propertyName, '0.001s');\n}\n\nfunction unsetMinimum(propertyName) {\n document.documentElement.style.removeProperty(propertyName);\n}\n\nexport function setupPromiseModals(hooks) {\n hooks.beforeEach(function () {\n setMinimum('--epm-animation-backdrop-in-duration');\n setMinimum('--epm-animation-backdrop-out-duration');\n setMinimum('--epm-animation-backdrop-in-delay');\n setMinimum('--epm-animation-backdrop-out-delay');\n setMinimum('--epm-animation-modal-in-duration');\n setMinimum('--epm-animation-modal-out-duration');\n setMinimum('--epm-animation-modal-in-delay');\n setMinimum('--epm-animation-modal-out-delay');\n\n this.modals = this.owner.lookup('service:modals');\n });\n\n hooks.afterEach(async function () {\n // be sure to close all modals after a test\n if (this.modals) {\n this.modals._destroyModals();\n }\n\n delete this.modals;\n\n unsetMinimum('--epm-animation-backdrop-in-duration');\n unsetMinimum('--epm-animation-backdrop-out-duration');\n unsetMinimum('--epm-animation-backdrop-in-delay');\n unsetMinimum('--epm-animation-backdrop-out-delay');\n unsetMinimum('--epm-animation-modal-in-duration');\n unsetMinimum('--epm-animation-modal-out-duration');\n unsetMinimum('--epm-animation-modal-in-delay');\n unsetMinimum('--epm-animation-modal-out-delay');\n\n // wait for any registered test waiters to settle\n await settled();\n });\n}\n"],"names":["setMinimum","propertyName","document","documentElement","style","setProperty","unsetMinimum","removeProperty","setupPromiseModals","hooks","beforeEach","modals","owner","lookup","afterEach","_destroyModals","settled"],"mappings":";;AAEA,SAASA,UAAUA,CAACC,YAAY,EAAE;EAChCC,QAAQ,CAACC,eAAe,CAACC,KAAK,CAACC,WAAW,CAACJ,YAAY,EAAE,QAAQ,CAAC;AACpE;AAEA,SAASK,YAAYA,CAACL,YAAY,EAAE;EAClCC,QAAQ,CAACC,eAAe,CAACC,KAAK,CAACG,cAAc,CAACN,YAAY,CAAC;AAC7D;AAEO,SAASO,kBAAkBA,CAACC,KAAK,EAAE;EACxCA,KAAK,CAACC,UAAU,CAAC,YAAY;IAC3BV,UAAU,CAAC,sCAAsC,CAAC;IAClDA,UAAU,CAAC,uCAAuC,CAAC;IACnDA,UAAU,CAAC,mCAAmC,CAAC;IAC/CA,UAAU,CAAC,oCAAoC,CAAC;IAChDA,UAAU,CAAC,mCAAmC,CAAC;IAC/CA,UAAU,CAAC,oCAAoC,CAAC;IAChDA,UAAU,CAAC,gCAAgC,CAAC;IAC5CA,UAAU,CAAC,iCAAiC,CAAC;IAE7C,IAAI,CAACW,MAAM,GAAG,IAAI,CAACC,KAAK,CAACC,MAAM,CAAC,gBAAgB,CAAC;AACnD,EAAA,CAAC,CAAC;EAEFJ,KAAK,CAACK,SAAS,CAAC,kBAAkB;AAChC;IACA,IAAI,IAAI,CAACH,MAAM,EAAE;AACf,MAAA,IAAI,CAACA,MAAM,CAACI,cAAc,EAAE;AAC9B,IAAA;IAEA,OAAO,IAAI,CAACJ,MAAM;IAElBL,YAAY,CAAC,sCAAsC,CAAC;IACpDA,YAAY,CAAC,uCAAuC,CAAC;IACrDA,YAAY,CAAC,mCAAmC,CAAC;IACjDA,YAAY,CAAC,oCAAoC,CAAC;IAClDA,YAAY,CAAC,mCAAmC,CAAC;IACjDA,YAAY,CAAC,oCAAoC,CAAC;IAClDA,YAAY,CAAC,gCAAgC,CAAC;IAC9CA,YAAY,CAAC,iCAAiC,CAAC;;AAE/C;IACA,MAAMU,OAAO,EAAE;AACjB,EAAA,CAAC,CAAC;AACJ;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-promise-modals",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "The better way to handle modals in your Ember.js apps.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -36,37 +36,42 @@
36
36
  "dependencies": {
37
37
  "@ember/test-waiters": "^3.0.2",
38
38
  "@embroider/addon-shim": "^1.8.7",
39
- "@embroider/util": "^1.7.1",
40
- "decorator-transforms": "^1.0.1",
41
- "focus-trap": "^6.9.3"
39
+ "@embroider/util": "^1.13.3",
40
+ "@glimmer/tracking": "^1.1.2",
41
+ "decorator-transforms": "^2.0.0",
42
+ "ember-modifier": "^4.2.2",
43
+ "focus-trap": "^7.0.0",
44
+ "tracked-built-ins": "^4.0.0"
42
45
  },
43
46
  "devDependencies": {
44
- "@babel/core": "7.24.4",
45
- "@babel/eslint-parser": "7.24.1",
46
- "@babel/plugin-proposal-decorators": "7.24.1",
47
- "@babel/plugin-transform-class-properties": "7.24.1",
48
- "@embroider/addon-dev": "4.2.1",
47
+ "@babel/core": "7.28.5",
48
+ "@babel/eslint-parser": "7.28.5",
49
+ "@babel/plugin-proposal-decorators": "7.28.0",
50
+ "@babel/plugin-transform-class-properties": "7.27.1",
51
+ "@ember/test-helpers": "5.2.2",
52
+ "@embroider/addon-dev": "8.1.2",
53
+ "@glimmer/component": "1.1.2",
49
54
  "@rollup/plugin-babel": "6.0.4",
50
- "ember-template-lint": "5.13.0",
51
- "eslint": "8.57.0",
52
- "eslint-config-prettier": "8.10.0",
53
- "eslint-plugin-ember": "11.12.0",
54
- "eslint-plugin-import-helpers": "1.3.1",
55
- "eslint-plugin-n": "16.6.2",
56
- "eslint-plugin-prettier": "4.2.1",
57
- "eslint-plugin-promise": "6.1.1",
58
- "eslint-plugin-qunit": "7.3.4",
55
+ "ember-template-lint": "7.9.3",
56
+ "eslint": "8.57.1",
57
+ "eslint-config-prettier": "9.1.2",
58
+ "eslint-plugin-ember": "12.6.0",
59
+ "eslint-plugin-import-helpers": "2.0.1",
60
+ "eslint-plugin-n": "17.21.3",
61
+ "eslint-plugin-prettier": "5.5.4",
62
+ "eslint-plugin-promise": "6.6.0",
63
+ "eslint-plugin-qunit": "8.2.5",
59
64
  "npm-run-all": "4.1.5",
60
- "prettier": "2.8.8",
61
- "rollup": "4.14.0",
65
+ "prettier": "3.6.2",
66
+ "rollup": "4.45.3",
62
67
  "rollup-plugin-copy": "3.5.0",
63
- "webpack": "5.89.0"
68
+ "webpack": "5.100.2"
64
69
  },
65
70
  "peerDependencies": {
66
- "@ember/test-helpers": "^3.0.0"
71
+ "@ember/test-helpers": "^3.0.0 || ^5.0.0"
67
72
  },
68
73
  "engines": {
69
- "node": ">= 16.*"
74
+ "node": ">= 18.*"
70
75
  },
71
76
  "ember": {
72
77
  "edition": "octane"