@atlassian/atlassian-connect-js 5.3.190

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 (190) hide show
  1. package/.depcheckrc.json +16 -0
  2. package/.editorconfig +9 -0
  3. package/.envrc +5 -0
  4. package/.eslintignore +12 -0
  5. package/.eslintrc +31 -0
  6. package/.husky/pre-commit +11 -0
  7. package/.lintstagedrc.js +6 -0
  8. package/.netrc +1 -0
  9. package/.npmrc-public +4 -0
  10. package/.nvmrc +1 -0
  11. package/LICENSE +3 -0
  12. package/README.md +281 -0
  13. package/bitbucket-pipelines.yml +33 -0
  14. package/build/bin/bin-helper.js +29 -0
  15. package/build/bin/npm-postinstall.js +9 -0
  16. package/build/configs/append-sourcemapping.js +13 -0
  17. package/build/configs/availabletasks.js +15 -0
  18. package/build/configs/clean.js +12 -0
  19. package/build/configs/concat.js +44 -0
  20. package/build/configs/copy.js +32 -0
  21. package/build/configs/index.js +19 -0
  22. package/build/configs/jshint.js +9 -0
  23. package/build/configs/karma.js +11 -0
  24. package/build/configs/replace.js +10 -0
  25. package/build/configs/requirejs.js +187 -0
  26. package/build/configs/saucelabs-launchers.js +30 -0
  27. package/build/configs/shell.js +24 -0
  28. package/build/configs/uglify.js +15 -0
  29. package/build/configs/watch.js +45 -0
  30. package/build/end.frag +13 -0
  31. package/build/start.frag +18 -0
  32. package/bundlesize.config.json +14 -0
  33. package/dist/connect-host.css +225 -0
  34. package/dist/connect-host.js +13908 -0
  35. package/dist/connect-host.min.css +1 -0
  36. package/dist/iframe-fedramp.js +13663 -0
  37. package/dist/iframe.js +13663 -0
  38. package/dist/legacy-text-colors.css +245 -0
  39. package/dist/surfaces.css +11 -0
  40. package/dist/themes/atlaskit-tokens_dark-future.css +6 -0
  41. package/dist/themes/atlaskit-tokens_dark.css +394 -0
  42. package/dist/themes/atlaskit-tokens_legacy-dark.css +394 -0
  43. package/dist/themes/atlaskit-tokens_legacy-light.css +394 -0
  44. package/dist/themes/atlaskit-tokens_light-future.css +6 -0
  45. package/dist/themes/atlaskit-tokens_light.css +394 -0
  46. package/dist/themes/atlaskit-tokens_shape.css +14 -0
  47. package/dist/themes/atlaskit-tokens_spacing.css +26 -0
  48. package/dist/themes/atlaskit-tokens_typography-adg3.css +25 -0
  49. package/dist/themes/atlaskit-tokens_typography-modernized.css +25 -0
  50. package/dist/themes/atlaskit-tokens_typography-refreshed.css +25 -0
  51. package/gulpfile.js +204 -0
  52. package/memleak-check/app.html +10 -0
  53. package/memleak-check/index.html +31 -0
  54. package/memleak-check/index.js +33 -0
  55. package/package.json +102 -0
  56. package/renovate.json +11 -0
  57. package/security-assistant.yml +2 -0
  58. package/spec/.eslintrc +10 -0
  59. package/spec/config/karma.base.conf.js +200 -0
  60. package/spec/config/karma.conf.js +20 -0
  61. package/spec/fixtures/base_dialog_component_tests.js +180 -0
  62. package/spec/mocks/mock_feature_flag.js +23 -0
  63. package/spec/tests/amd_spec.js +122 -0
  64. package/spec/tests/analytics_dispatcher_spec.js +429 -0
  65. package/spec/tests/analytics_performance_spec.js +41 -0
  66. package/spec/tests/button_spec.js +143 -0
  67. package/spec/tests/dialog_extension_spec.js +59 -0
  68. package/spec/tests/dialog_module_provider_spec.js +499 -0
  69. package/spec/tests/dialog_module_spec.js +395 -0
  70. package/spec/tests/dialog_spec.js +296 -0
  71. package/spec/tests/dialog_webitem_spec.js +183 -0
  72. package/spec/tests/dropdown_module_spec.js +77 -0
  73. package/spec/tests/env_module_spec.js +153 -0
  74. package/spec/tests/events_spec.js +77 -0
  75. package/spec/tests/extension_configuration_options_store_spec.js +25 -0
  76. package/spec/tests/flag_module_provider_spec.js +79 -0
  77. package/spec/tests/flag_module_spec.js +118 -0
  78. package/spec/tests/flag_spec.js +243 -0
  79. package/spec/tests/host-api_spec.js +220 -0
  80. package/spec/tests/iframe-create_spec.js +43 -0
  81. package/spec/tests/iframe_container_spec.js +19 -0
  82. package/spec/tests/iframe_spec.js +265 -0
  83. package/spec/tests/inline_dialog_spec.js +41 -0
  84. package/spec/tests/inline_dialog_webitem_spec.js +331 -0
  85. package/spec/tests/loading_indicator_spec.js +48 -0
  86. package/spec/tests/messages_module_spec.js +108 -0
  87. package/spec/tests/meta_spec.js +71 -0
  88. package/spec/tests/module_args_spec.js +52 -0
  89. package/spec/tests/observe_spec.js +73 -0
  90. package/spec/tests/public_events.spec.js +102 -0
  91. package/spec/tests/scroll_position_spec.js +109 -0
  92. package/spec/tests/theming_spec.js +594 -0
  93. package/spec/tests/util_spec.js +55 -0
  94. package/spec/tests/utils/base64_spec.js +20 -0
  95. package/spec/tests/utils/button_spec.js +11 -0
  96. package/spec/tests/utils/cookie_spec.js +19 -0
  97. package/spec/tests/utils/deprecate_spec.js +22 -0
  98. package/spec/tests/utils/dialog_spec.js +297 -0
  99. package/spec/tests/utils/host_util_spec.js +45 -0
  100. package/spec/tests/utils/iframe_spec.js +41 -0
  101. package/spec/tests/utils/jwt_spec.js +135 -0
  102. package/spec/tests/utils/url_spec.js +37 -0
  103. package/spec/tests/utils/waitUntilReadyNextTick.js +5 -0
  104. package/spec/tests/utils/webitem.js +219 -0
  105. package/spec/tests/webitem_spec.js +131 -0
  106. package/src/css/host/dialog.css +144 -0
  107. package/src/css/host/flags.css +5 -0
  108. package/src/css/host/host.css +64 -0
  109. package/src/css/host/messages.css +12 -0
  110. package/src/css/plugin/legacy-text-colors.less +55 -0
  111. package/src/css/plugin/surfaces.css +11 -0
  112. package/src/host/ACJSFrameworkAdaptor.js +44 -0
  113. package/src/host/actions/analytics_action.js +35 -0
  114. package/src/host/actions/button_actions.js +21 -0
  115. package/src/host/actions/dialog_actions.js +27 -0
  116. package/src/host/actions/dialog_extension_actions.js +25 -0
  117. package/src/host/actions/dom_event_actions.js +32 -0
  118. package/src/host/actions/dropdown_actions.js +12 -0
  119. package/src/host/actions/env_actions.js +57 -0
  120. package/src/host/actions/event_actions.js +33 -0
  121. package/src/host/actions/flag_actions.js +22 -0
  122. package/src/host/actions/iframe_actions.js +27 -0
  123. package/src/host/actions/inline_dialog_actions.js +26 -0
  124. package/src/host/actions/inline_dialog_webitem_actions.js +10 -0
  125. package/src/host/actions/jwt_actions.js +51 -0
  126. package/src/host/actions/loading_indicator_actions.js +10 -0
  127. package/src/host/actions/module_actions.js +14 -0
  128. package/src/host/actions/webitem_actions.js +29 -0
  129. package/src/host/components/button.js +112 -0
  130. package/src/host/components/dialog.js +447 -0
  131. package/src/host/components/dialog_extension.js +106 -0
  132. package/src/host/components/dialog_webitem.js +69 -0
  133. package/src/host/components/flag.js +102 -0
  134. package/src/host/components/iframe.js +130 -0
  135. package/src/host/components/iframe_container.js +38 -0
  136. package/src/host/components/inline_dialog.js +108 -0
  137. package/src/host/components/inline_dialog_webitem.js +157 -0
  138. package/src/host/components/loading_indicator.js +110 -0
  139. package/src/host/components/webitem.js +227 -0
  140. package/src/host/deprecate.js +20 -0
  141. package/src/host/dispatchers/analytics_dispatcher.js +512 -0
  142. package/src/host/dispatchers/event_dispatcher.js +46 -0
  143. package/src/host/dollar.js +8 -0
  144. package/src/host/host-api.js +325 -0
  145. package/src/host/iframe-create.js +7 -0
  146. package/src/host/index.js +108 -0
  147. package/src/host/module-providers.js +13 -0
  148. package/src/host/modules/_featureFlag.js +42 -0
  149. package/src/host/modules/_performance.js +54 -0
  150. package/src/host/modules/analytics.js +17 -0
  151. package/src/host/modules/dialog.js +496 -0
  152. package/src/host/modules/dropdown.js +255 -0
  153. package/src/host/modules/env.js +156 -0
  154. package/src/host/modules/events.js +28 -0
  155. package/src/host/modules/flag.js +170 -0
  156. package/src/host/modules/host.js +19 -0
  157. package/src/host/modules/inline-dialog.js +33 -0
  158. package/src/host/modules/messages.js +309 -0
  159. package/src/host/modules/page.js +29 -0
  160. package/src/host/modules/scroll-position.js +102 -0
  161. package/src/host/modules/theming.js +114 -0
  162. package/src/host/stores/extension_configuration_options_store.js +24 -0
  163. package/src/host/util.js +98 -0
  164. package/src/host/utils/access-narrowing-context.js +18 -0
  165. package/src/host/utils/base64.js +22 -0
  166. package/src/host/utils/button.js +10 -0
  167. package/src/host/utils/cookie.js +14 -0
  168. package/src/host/utils/dialog.js +239 -0
  169. package/src/host/utils/feature-flag.js +27 -0
  170. package/src/host/utils/iframe.js +23 -0
  171. package/src/host/utils/jwt.js +60 -0
  172. package/src/host/utils/observe.js +34 -0
  173. package/src/host/utils/removal-observer.js +30 -0
  174. package/src/host/utils/simplexdm.js +58 -0
  175. package/src/host/utils/url.js +23 -0
  176. package/src/host/utils/webitem.js +214 -0
  177. package/src/plugin/amd.js +115 -0
  178. package/src/plugin/analytics.js +84 -0
  179. package/src/plugin/deprecate.js +16 -0
  180. package/src/plugin/dialog.js +197 -0
  181. package/src/plugin/dollar.js +77 -0
  182. package/src/plugin/events-instance.js +2 -0
  183. package/src/plugin/events.js +246 -0
  184. package/src/plugin/extension_configuration_options_store.js +27 -0
  185. package/src/plugin/featureFlag.js +8 -0
  186. package/src/plugin/index.js +118 -0
  187. package/src/plugin/meta.js +14 -0
  188. package/src/plugin/public-events.js +73 -0
  189. package/src/plugin/theming.js +211 -0
  190. package/src/plugin/util.js +104 -0
@@ -0,0 +1,496 @@
1
+ import EventDispatcher from '../dispatchers/event_dispatcher';
2
+ import DialogExtensionActions from '../actions/dialog_extension_actions';
3
+ import DialogActions from '../actions/dialog_actions';
4
+ import EventActions from '../actions/event_actions';
5
+ import DialogExtensionComponent from '../components/dialog_extension';
6
+ import ButtonComponent from '../components/button';
7
+ import DialogUtils from '../utils/dialog';
8
+ import HostApi from '../host-api';
9
+ import Util from '../util';
10
+ import dialogUtils from '../utils/dialog';
11
+ import getBooleanFeatureFlag from '../utils/feature-flag';
12
+
13
+ const _dialogs = {};
14
+
15
+ EventDispatcher.register('dialog-close', function (data) {
16
+ const dialog = data.dialog;
17
+ if (dialog && data.extension) {
18
+ const targetSpec = { addon_key: data.extension.addon_key, id: data.extension.options.callbackExtensionId };
19
+ EventActions.broadcast('dialog.close', targetSpec, data.customData);
20
+ }
21
+ });
22
+
23
+ EventDispatcher.register('dialog-button-click', (data) => {
24
+ var eventData = {
25
+ button: {
26
+ name: ButtonComponent.getName(data.$el),
27
+ identifier: ButtonComponent.getIdentifier(data.$el),
28
+ text: ButtonComponent.getText(data.$el)
29
+ }
30
+ };
31
+ var eventName = 'dialog.button.click';
32
+
33
+ var buttonEventFilter = {
34
+ addon_key: data.extension.addon_key,
35
+ key: data.extension.key
36
+ };
37
+
38
+ buttonEventFilter.id = data.extension.id;
39
+
40
+ // Old buttons, (submit and cancel) use old events
41
+ if(!data.$el.hasClass('ap-dialog-custom-button')) {
42
+ EventActions.broadcast(`dialog.${eventData.button.name}`,
43
+ buttonEventFilter,
44
+ eventData
45
+ );
46
+ }
47
+
48
+ EventActions.broadcast(eventName,
49
+ buttonEventFilter,
50
+ eventData
51
+ );
52
+ });
53
+
54
+ /**
55
+ * @class Dialog~Dialog
56
+ * @description A dialog object that is returned when a dialog is created using the [dialog module](module-Dialog.html).
57
+ */
58
+ class Dialog {
59
+ constructor(options, callback) {
60
+ callback = Util.last(arguments);
61
+ const _id = callback._id;
62
+ const extension = callback._context.extension;
63
+ let dialogExtension = {
64
+ addon_key: extension.addon_key,
65
+ key: options.key,
66
+ options: Util.pick(extension.options, ['customData', 'productContext']),
67
+ callback_extension_id: extension.id
68
+ };
69
+
70
+ // ACJS-185: the following is a really bad idea but we need it
71
+ // for compat until AP.dialog.customData has been deprecated
72
+ dialogExtension.options.customData = options.customData;
73
+ // terrible idea! - we need to remove this from p2 ASAP!
74
+ var dialogModuleOptions = DialogUtils.moduleOptionsFromGlobal(dialogExtension.addon_key, dialogExtension.key);
75
+
76
+ // There is a hostFrameOffset configuration available
77
+ // for modals (window._AP.dialogOptions) and inline modals (window._AP.inlineDialogOptions)
78
+ // which is taken into account during the iframe insertion (inside the dialog).
79
+ // The change below injects hostFrameOffset value from the global module options (window._AP.dialogModules)
80
+ // which is required for establishing a contact with a correct host (solves spa iframe problem).
81
+ if (typeof (dialogModuleOptions || {}).hostFrameOffset === 'number') {
82
+ dialogExtension.options.hostFrameOffset = dialogModuleOptions.hostFrameOffset;
83
+ }
84
+
85
+ options = Util.extend({}, dialogModuleOptions || {}, options);
86
+ options.id = _id;
87
+ dialogUtils.trackMultipleDialogOpening(dialogExtension, options);
88
+ DialogExtensionActions.open(dialogExtension, options);
89
+
90
+ this.customData = options.customData;
91
+ _dialogs[_id] = this;
92
+ }
93
+
94
+ /**
95
+ * Registers a callback for a dialog event.
96
+ * @method on
97
+ * @memberOf Dialog~Dialog
98
+ * @param {String} event The dialog event to listen for. Valid options are "close".
99
+ * @param {Function} callback The function to be invoked.
100
+ * @noDemo
101
+ * @example
102
+ * AP.dialog.create({
103
+ * key: 'my-module-key'
104
+ * }).on("close", function() {
105
+ * console.log("Dialog was closed");
106
+ * });
107
+ */
108
+ }
109
+
110
+ /**
111
+ * @class Dialog~DialogButton
112
+ * @description A dialog button that can be controlled with JavaScript
113
+ */
114
+ class Button {
115
+ constructor(identifier, callback) {
116
+ callback = Util.last(arguments);
117
+ const frameworkAdaptor = HostApi.getFrameworkAdaptor();
118
+ const dialogProvider = frameworkAdaptor.getProviderByModuleName('dialog');
119
+ if (dialogProvider) {
120
+ dialogUtils.assertActiveDialogOrThrow(dialogProvider, callback._context.extension.addon_key);
121
+ this.name = identifier;
122
+ this.identifier = identifier;
123
+ } else {
124
+ if (!DialogExtensionComponent.getActiveDialog()) {
125
+ throw new Error('Failed to find an active dialog.');
126
+ }
127
+ this.name = identifier;
128
+ this.identifier = identifier;
129
+ this.enabled = DialogExtensionComponent.buttonIsEnabled(identifier);
130
+ this.hidden = !DialogExtensionComponent.buttonIsVisible(identifier);
131
+ }
132
+ }
133
+ /**
134
+ * Sets the button state to enabled
135
+ * @method enable
136
+ * @memberOf Dialog~DialogButton
137
+ * @noDemo
138
+ * @example
139
+ * AP.dialog.getButton('submit').enable();
140
+ */
141
+ enable() {
142
+ this.setState({
143
+ enabled: true
144
+ });
145
+ }
146
+ /**
147
+ * Sets the button state to disabled. A disabled button cannot be clicked and emits no events.
148
+ * @method disable
149
+ * @memberOf Dialog~DialogButton
150
+ * @noDemo
151
+ * @example
152
+ * AP.dialog.getButton('submit').disable();
153
+ */
154
+ disable() {
155
+ this.setState({
156
+ enabled: false
157
+ });
158
+ }
159
+ /**
160
+ * Query a button for its current state.
161
+ * @method isEnabled
162
+ * @memberOf Dialog~DialogButton
163
+ * @param {Function} callback function to receive the button state.
164
+ * @noDemo
165
+ * @example
166
+ * AP.dialog.getButton('submit').isEnabled(function(enabled){
167
+ * if(enabled){
168
+ * //button is enabled
169
+ * }
170
+ * });
171
+ */
172
+ isEnabled(callback) {
173
+ callback = Util.last(arguments);
174
+ const frameworkAdaptor = HostApi.getFrameworkAdaptor();
175
+ const dialogProvider = frameworkAdaptor.getProviderByModuleName('dialog');
176
+ if (dialogProvider) {
177
+ callback(!dialogProvider.isButtonDisabled(this.identifier));
178
+ } else {
179
+ callback(this.enabled);
180
+ }
181
+ }
182
+ /**
183
+ * Toggle the button state between enabled and disabled.
184
+ * @method toggle
185
+ * @memberOf Dialog~DialogButton
186
+ * @noDemo
187
+ * @example
188
+ * AP.dialog.getButton('submit').toggle();
189
+ */
190
+ toggle() {
191
+ const frameworkAdaptor = HostApi.getFrameworkAdaptor();
192
+ const dialogProvider = frameworkAdaptor.getProviderByModuleName('dialog');
193
+ if (dialogProvider) {
194
+ dialogProvider.toggleButton(this.identifier);
195
+ } else {
196
+ this.setState({
197
+ enabled: !this.enabled
198
+ });
199
+ }
200
+ }
201
+ setState(state) {
202
+ const frameworkAdaptor = HostApi.getFrameworkAdaptor();
203
+ const dialogProvider = frameworkAdaptor.getProviderByModuleName('dialog');
204
+ if (dialogProvider) {
205
+ dialogProvider.setButtonDisabled(this.identifier, !state.enabled);
206
+ } else {
207
+ this.enabled = state.enabled;
208
+ DialogActions.toggleButton({
209
+ identifier: this.identifier,
210
+ enabled: this.enabled
211
+ });
212
+ }
213
+ }
214
+ /**
215
+ * Trigger a callback bound to a button.
216
+ * @method trigger
217
+ * @memberOf Dialog~DialogButton
218
+ * @noDemo
219
+ * @example
220
+ * AP.dialog.getButton('submit').bind(function(){
221
+ * alert('clicked!');
222
+ * });
223
+ * AP.dialog.getButton('submit').trigger();
224
+ */
225
+ trigger(callback) {
226
+ callback = Util.last(arguments);
227
+ if (this.enabled) {
228
+ DialogActions.dialogMessage({
229
+ name: this.name,
230
+ extension: callback._context.extension
231
+ });
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Query a button for its current hidden/visible state.
237
+ * @method isHidden
238
+ * @memberOf Dialog~DialogButton
239
+ * @param {Function} callback function to receive the button state.
240
+ * @noDemo
241
+ * @example
242
+ * AP.dialog.getButton('submit').isHidden(function(hidden){
243
+ * if(hidden){
244
+ * //button is hidden
245
+ * }
246
+ * });
247
+ */
248
+ isHidden(callback) {
249
+ callback = Util.last(arguments);
250
+ const frameworkAdaptor = HostApi.getFrameworkAdaptor();
251
+ const dialogProvider = frameworkAdaptor.getProviderByModuleName('dialog');
252
+ if (dialogProvider) {
253
+ callback(dialogProvider.isButtonHidden(this.identifier));
254
+ } else {
255
+ callback(this.hidden);
256
+ }
257
+ }
258
+ /**
259
+ * Sets the button state to hidden
260
+ * @method hide
261
+ * @memberOf Dialog~DialogButton
262
+ * @noDemo
263
+ * @example
264
+ * AP.dialog.getButton('submit').hide();
265
+ */
266
+ hide() {
267
+ this.setHidden(true);
268
+ }
269
+ /**
270
+ * Sets the button state to visible
271
+ * @method show
272
+ * @memberOf Dialog~DialogButton
273
+ * @noDemo
274
+ * @example
275
+ * AP.dialog.getButton('submit').show();
276
+ */
277
+ show() {
278
+ this.setHidden(false);
279
+ }
280
+
281
+ setHidden(hidden) {
282
+ const frameworkAdaptor = HostApi.getFrameworkAdaptor();
283
+ const dialogProvider = frameworkAdaptor.getProviderByModuleName('dialog');
284
+ if (dialogProvider) {
285
+ dialogProvider.setButtonHidden(this.identifier, hidden);
286
+ } else {
287
+ this.hidden = hidden;
288
+ DialogActions.toggleButtonVisibility({
289
+ identifier: this.identifier,
290
+ hidden: this.hidden
291
+ });
292
+ }
293
+ }
294
+ }
295
+
296
+ function getDialogFromContext(context) {
297
+ return _dialogs[context.extension.options.dialogId];
298
+ }
299
+
300
+ class CreateButton {
301
+ constructor(options, callback) {
302
+ callback = Util.last(arguments);
303
+ const frameworkAdaptor = HostApi.getFrameworkAdaptor();
304
+ const dialogProvider = frameworkAdaptor.getProviderByModuleName('dialog');
305
+ if (dialogProvider) {
306
+ dialogUtils.assertActiveDialogOrThrow(dialogProvider, callback._context.extension.addon_key);
307
+ dialogProvider.createButton({
308
+ identifier: options.identifier,
309
+ text: options.text,
310
+ hidden: false,
311
+ disabled: options.disabled || false,
312
+ onClick: () => {
313
+ EventActions.broadcast('dialog.button.click', {
314
+ addon_key: callback._context.extension.addon_key,
315
+ key: callback._context.extension.key
316
+ }, {
317
+ button: {
318
+ identifier: options.identifier,
319
+ text: options.text
320
+ }
321
+ });
322
+ }
323
+ });
324
+ } else {
325
+ DialogExtensionActions.addUserButton({
326
+ identifier: options.identifier,
327
+ text: options.text
328
+ }, callback._context.extension);
329
+ }
330
+ }
331
+ }
332
+
333
+ /**
334
+ * The Dialog module provides a mechanism for launching an add-on's modules as modal dialogs from within an add-on's iframe.
335
+ *
336
+ * A modal dialog displays information without requiring the user to leave the current page.
337
+ *
338
+ * The dialog is opened over the entire window, rather than within the iframe itself.
339
+ *
340
+ * <h3>Styling your dialog to look like a standard Atlassian dialog</h3>
341
+ *
342
+ * By default the dialog iframe is undecorated. It's up to you to style the dialog.
343
+ * <img src="/cloud/connect/images/connectdialogchromelessexample.jpeg" width="100%" />
344
+ *
345
+ * In order to maintain a consistent look and feel between the host application and the add-on, we encourage you to style your dialogs to match Atlassian's Design Guidelines for modal dialogs.
346
+ *
347
+ * To do that, you'll need to add the AUI styles to your dialog.
348
+ *
349
+ * For more information, read about the Atlassian User Interface [dialog component](https://docs.atlassian.com/aui/latest/docs/dialog2.html).
350
+ * @exports Dialog
351
+ */
352
+ export default {
353
+ /**
354
+ * @class Dialog~DialogOptions
355
+ * @description The options supplied to a [dialog.create()](module-Dialog.html) call.
356
+ *
357
+ * @property {String} key The module key of a dialog, or the key of a page or web-item that you want to open as a dialog.
358
+ * @property {String} size Opens the dialog at a preset size: small, medium, large, x-large or fullscreen (with chrome).
359
+ * @property {Number|String} width if size is not set, define the width as a percentage (append a % to the number) or pixels.
360
+ * @property {Number|String} height if size is not set, define the height as a percentage (append a % to the number) or pixels.
361
+ * @property {Boolean} chrome (optional) opens the dialog with heading and buttons.
362
+ * @property {String} header (optional) text to display in the header if opening a dialog with chrome.
363
+ * @property {String} submitText (optional) text for the submit button if opening a dialog with chrome.
364
+ * @property {String} cancelText (optional) text for the cancel button if opening a dialog with chrome.
365
+ * @property {Object} customData (optional) custom data object that can be accessed from the actual dialog iFrame.
366
+ * @property {Boolean} closeOnEscape (optional) if true, pressing ESC inside the dialog will close the dialog (default is true).
367
+ * @property {Array} buttons (optional) an array of custom buttons to be added to the dialog if opening a dialog with chrome.
368
+ * @property {String} hint (optional) Suggested actions or helpful info that will be added to the dialog if opening with chrome.
369
+ */
370
+
371
+ /**
372
+ * Creates a dialog for a common dialog, page or web-item module key.
373
+ * @param {Dialog~DialogOptions} options configuration object of dialog options.
374
+ * @method create
375
+ * @noDemo
376
+ * @example
377
+ * AP.dialog.create({
378
+ * key: 'my-module-key',
379
+ * width: '500px',
380
+ * height: '200px',
381
+ * chrome: true,
382
+ * buttons: [
383
+ * {
384
+ * text: 'my button',
385
+ * identifier: 'my_unique_identifier'
386
+ * }
387
+ * ]
388
+ * }).on("close", callbackFunc);
389
+ *
390
+ * @return {Dialog~Dialog} Dialog object allowing for callback registrations
391
+ */
392
+ create: {
393
+ constructor: Dialog
394
+ },
395
+ /**
396
+ * Closes the currently open dialog. Optionally pass data to listeners of the `dialog.close` event.
397
+ * This will only close a dialog that has been opened by your add-on.
398
+ * You can register for close events using the `dialog.close` event and the [events module](../events/).
399
+ * @param {Object} data An object to be emitted on dialog close.
400
+ * @noDemo
401
+ * @example
402
+ * AP.dialog.close({foo: 'bar'});
403
+ */
404
+ close: function (data, callback) {
405
+ callback = Util.last(arguments);
406
+ const frameworkAdaptor = HostApi.getFrameworkAdaptor();
407
+ const dialogProvider = frameworkAdaptor.getProviderByModuleName('dialog');
408
+ if (dialogProvider) {
409
+ dialogUtils.assertActiveDialogOrThrow(dialogProvider, callback._context.extension.addon_key);
410
+ EventActions.broadcast('dialog.close', {
411
+ addon_key: callback._context.extension.addon_key
412
+ }, data);
413
+ dialogProvider.close();
414
+ } else {
415
+ var dialogToClose;
416
+ if(callback._context.extension.options.isDialog){
417
+ dialogToClose = DialogExtensionComponent.getByExtension(callback._context.extension.id)[0];
418
+ } else {
419
+ dialogToClose = DialogExtensionComponent.getActiveDialog();
420
+ }
421
+
422
+ DialogActions.close({
423
+ customData: data,
424
+ dialog: dialogToClose,
425
+ extension: callback._context.extension
426
+ });
427
+ }
428
+ },
429
+ /**
430
+ * Passes the custom data Object to the specified callback function.
431
+ * @noDemo
432
+ * @name getCustomData
433
+ * @method
434
+ * @param {Function} callback - Callback method to be executed with the custom data.
435
+ * @example
436
+ * AP.dialog.getCustomData(function (customData) {
437
+ * console.log(customData);
438
+ * });
439
+ *
440
+ */
441
+ getCustomData: function (callback) {
442
+ callback = Util.last(arguments);
443
+ const dialog = getDialogFromContext(callback._context);
444
+ if (dialog) {
445
+ callback(dialog.customData);
446
+ } else {
447
+ callback(undefined);
448
+ }
449
+ },
450
+ /**
451
+ * Stop the dialog from closing when the submit button is clicked
452
+ * @method disableCloseOnSubmit
453
+ * @noDemo
454
+ * @example
455
+ * AP.dialog.disableCloseOnSubmit();
456
+ * AP.events.on('dialog.button.click', function(data){
457
+ * if(data.button.name === 'submit') {
458
+ * console.log('submit button pressed');
459
+ * }
460
+ * }
461
+ */
462
+
463
+ /**
464
+ * Returns the button that was requested (either cancel or submit). If the requested button does not exist, an empty Object will be returned instead.
465
+ * @method getButton
466
+ * @returns {Dialog~DialogButton}
467
+ * @noDemo
468
+ * @example
469
+ * AP.dialog.getButton('submit');
470
+ */
471
+ getButton: {
472
+ constructor: Button,
473
+ enable: Button.prototype.enable,
474
+ disable: Button.prototype.disable,
475
+ toggle: Button.prototype.toggle,
476
+ isEnabled: Button.prototype.isEnabled,
477
+ trigger: Button.prototype.trigger,
478
+ hide: Button.prototype.hide,
479
+ show: Button.prototype.show,
480
+ isHidden: Button.prototype.isHidden
481
+ },
482
+ /**
483
+ * Creates a dialog button that can be controlled with javascript
484
+ * @method createButton
485
+ * @returns {Dialog~DialogButton}
486
+ * @noDemo
487
+ * @example
488
+ * AP.dialog.createButton({
489
+ * text: 'button text',
490
+ * identifier: 'button.1'
491
+ * }).bind(function mycallback(){});
492
+ */
493
+ createButton: {
494
+ constructor: CreateButton
495
+ }
496
+ };