@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,447 @@
1
+ import EventDispatcher from '../dispatchers/event_dispatcher';
2
+ import DomEventActions from '../actions/dom_event_actions';
3
+ import DialogActions from '../actions/dialog_actions';
4
+ import dialogUtils from '../utils/dialog';
5
+ import IframeComponent from './iframe';
6
+ import Button from './button';
7
+ import ButtonActions from '../actions/button_actions';
8
+ import Util from '../util';
9
+ import $ from '../dollar';
10
+ import HostApi from '../host-api';
11
+
12
+ const DLGID_PREFIX = 'ap-dialog-';
13
+ const DIALOG_CLASS = 'ap-aui-dialog2';
14
+ const DLGID_REGEXP = new RegExp(`^${DLGID_PREFIX}[0-9A-Za-z]+$`);
15
+ const DIALOG_SIZES = ['small', 'medium', 'large', 'xlarge', 'fullscreen', 'maximum'];
16
+ const DIALOG_BUTTON_CLASS = 'ap-aui-dialog-button';
17
+ const DIALOG_BUTTON_CUSTOM_CLASS = 'ap-dialog-custom-button';
18
+ const DIALOG_FOOTER_CLASS = 'aui-dialog2-footer';
19
+ const DIALOG_FOOTER_ACTIONS_CLASS = 'aui-dialog2-footer-actions';
20
+ const DIALOG_HEADER_ACTIONS_CLASS = 'header-control-panel';
21
+ const DIALOG_ERROR_CLOSE_BTN_ID = 'dialog-error-close-btn';
22
+
23
+ function getActiveDialog() {
24
+ const $el = AJS.LayerManager.global.getTopLayer();
25
+ if ($el && DLGID_REGEXP.test($el.attr('id'))) {
26
+ const dialog = AJS.dialog2($el);
27
+ dialog._id = dialog.$el.attr('id').replace(DLGID_PREFIX, '');
28
+ return dialog;
29
+ }
30
+ }
31
+
32
+ function getActionBar($dialog) {
33
+ var $actionBar = $dialog.find('.' + DIALOG_HEADER_ACTIONS_CLASS);
34
+ if(!$actionBar.length) {
35
+ $actionBar = $dialog.find('.' + DIALOG_FOOTER_ACTIONS_CLASS);
36
+ }
37
+ return $actionBar;
38
+ }
39
+
40
+ function getButtonByIdentifier(id, $dialog) {
41
+ const $actionBar = getActionBar($dialog);
42
+ return $actionBar.find('.aui-button').filter(function () {
43
+ return Button.getIdentifier(this) === id;
44
+ });
45
+ }
46
+
47
+ class Dialog {
48
+ constructor () {
49
+ }
50
+
51
+ _renderHeaderCloseBtn() {
52
+ const $close = $('<a />').addClass('aui-dialog2-header-close');
53
+ const $closeBtn = $('<span />').addClass('aui-icon aui-icon-small aui-iconfont-close-dialog').text('Close');
54
+ $close.append($closeBtn);
55
+ return $close;
56
+ }
57
+ //v3 ask DT about this DOM.
58
+ _renderFullScreenHeader($header, options) {
59
+ var $titleContainer = $('<div />').addClass('header-title-container aui-item expanded');
60
+ var $title = $('<div />').append($('<span />').addClass('header-title').text(options.header || ''));
61
+ $titleContainer.append($title);
62
+ $header.append($titleContainer).append(this._renderHeaderActions(options.actions, options.extension));
63
+ return $header;
64
+ }
65
+
66
+ _renderHeader(options){
67
+ const $header = $('<header />').addClass('aui-dialog2-header');
68
+ if(options.size === 'fullscreen') {
69
+ return this._renderFullScreenHeader($header, options);
70
+ }
71
+ if(options.header) {
72
+ const $title = $('<h2 />').addClass('aui-dialog2-header-main').text(options.header);
73
+ $header.append($title);
74
+ }
75
+ $header.append(this._renderHeaderCloseBtn());
76
+ return $header;
77
+ }
78
+
79
+ _renderHeaderActions(actions, extension) {
80
+ const $headerControls = $('<div />').addClass('aui-item ' + DIALOG_HEADER_ACTIONS_CLASS);
81
+ actions[0].additionalClasses = ['aui-icon', 'aui-icon-small', 'aui-iconfont-success'];
82
+ actions[1].additionalClasses = ['aui-icon', 'aui-icon-small', 'aui-iconfont-close-dialog'];
83
+ const $actions = this._renderActionButtons(actions, extension);
84
+ $actions.forEach(($action) => {
85
+ $headerControls.append($action);
86
+ });
87
+ return $headerControls;
88
+ }
89
+
90
+ _renderContent($content){
91
+ const $el = $('<div />').addClass('aui-dialog2-content');
92
+ if($content) {
93
+ $el.append($content);
94
+ }
95
+ return $el;
96
+ }
97
+
98
+ _renderFooter(options) {
99
+ const $footer = $('<footer />').addClass(DIALOG_FOOTER_CLASS);
100
+ if(options.size !== 'fullscreen') {
101
+ const $actions = this._renderFooterActions(options.actions, options.extension);
102
+ $footer.append($actions);
103
+ }
104
+ if(options.hint) {
105
+ const $hint = $('<div />').addClass('aui-dialog2-footer-hint').text(options.hint);
106
+ $footer.append($hint);
107
+ }
108
+ return $footer;
109
+ }
110
+
111
+ _renderActionButtons(actions, extension) {
112
+ var actionButtons = [];
113
+ [...actions].forEach(action => {
114
+ actionButtons.push(
115
+ this._renderDialogButton({
116
+ text: action.text,
117
+ name: action.name,
118
+ type: action.type,
119
+ additionalClasses: action.additionalClasses,
120
+ custom: action.custom || false,
121
+ identifier: action.identifier,
122
+ immutable: action.immutable,
123
+ disabled: action.disabled || false
124
+ }, extension)
125
+ );
126
+ });
127
+ return actionButtons;
128
+ }
129
+
130
+ _renderFooterActions(actions, extension) {
131
+ const $actions = $('<div />').addClass(DIALOG_FOOTER_ACTIONS_CLASS);
132
+ const $buttons = this._renderActionButtons(actions, extension);
133
+ $buttons.forEach(($button) => {
134
+ $actions.append($button);
135
+ });
136
+ return $actions;
137
+ }
138
+
139
+ _renderDialogButton(options, extension) {
140
+ options.additionalClasses = options.additionalClasses || [];
141
+ options.additionalClasses.push(DIALOG_BUTTON_CLASS);
142
+ if(options.custom) {
143
+ options.additionalClasses.push(DIALOG_BUTTON_CUSTOM_CLASS);
144
+ }
145
+ const $button = Button.render(options);
146
+ $button.extension = extension;
147
+ return $button;
148
+ }
149
+
150
+ /**
151
+ {
152
+ id: 'some-dialog-id',
153
+ title: 'some header',
154
+ hint: 'some footer hint',
155
+ $content: $(<div />).text('my content'),
156
+ actions: []
157
+ }
158
+ **/
159
+ render(options){
160
+ var originalOptions = Util.extend({}, options);
161
+ var sanitizedOptions = dialogUtils.sanitizeOptions(options);
162
+ const $dialog = $('<section />').attr({
163
+ role: 'dialog',
164
+ id: DLGID_PREFIX + sanitizedOptions.id
165
+ });
166
+ $dialog.attr('data-aui-modal', 'true');
167
+ $dialog.data({
168
+ 'aui-remove-on-hide': true,
169
+ 'extension': sanitizedOptions.extension
170
+ });
171
+ $dialog.addClass('aui-layer aui-dialog2 ' + DIALOG_CLASS);
172
+
173
+ if (DIALOG_SIZES.indexOf(sanitizedOptions.size) >= 0) {
174
+ $dialog.addClass('aui-dialog2-' + sanitizedOptions.size);
175
+ }
176
+
177
+ if(sanitizedOptions.size === 'fullscreen' || sanitizedOptions.size === 'maximum') {
178
+ if(sanitizedOptions.chrome) {
179
+ $dialog.addClass('ap-header-controls');
180
+ }
181
+ $dialog.addClass('aui-dialog2-maximum');
182
+ }
183
+
184
+ $dialog.append(this._renderContent(sanitizedOptions.$content));
185
+
186
+ if (sanitizedOptions.chrome) {
187
+ $dialog.prepend(this._renderHeader({
188
+ header: sanitizedOptions.header,
189
+ actions: sanitizedOptions.actions,
190
+ size: sanitizedOptions.size
191
+ }));
192
+
193
+ $dialog.append(this._renderFooter({
194
+ extension: sanitizedOptions.extension,
195
+ actions: sanitizedOptions.actions,
196
+ hint: sanitizedOptions.hint,
197
+ size: sanitizedOptions.size
198
+ }));
199
+ } else {
200
+ $dialog.addClass('aui-dialog2-chromeless');
201
+ }
202
+
203
+ const dialog = AJS.dialog2($dialog);
204
+ dialog._id = sanitizedOptions.id;
205
+ if (sanitizedOptions.size === 'fullscreen') {
206
+ sanitizedOptions.height = sanitizedOptions.width = '100%';
207
+ }
208
+ if (!sanitizedOptions.size || sanitizedOptions.size === 'fullscreen') {
209
+ AJS.layer($dialog).changeSize(sanitizedOptions.width, sanitizedOptions.height);
210
+ }
211
+ if (sanitizedOptions.onHide) {
212
+ dialog.on('hide', sanitizedOptions.onHide);
213
+ }
214
+ dialog.show();
215
+ dialog.$el.data('extension', sanitizedOptions.extension);
216
+ dialog.$el.data('originalOptions', originalOptions);
217
+ return $dialog;
218
+ }
219
+
220
+ setIframeDimensions($iframe){
221
+ IframeComponent.resize('100%', '100%', $iframe);
222
+ }
223
+
224
+ getActive(){
225
+ return getActiveDialog();
226
+ }
227
+
228
+ buttonIsEnabled(identifier) {
229
+ const dialog = getActiveDialog();
230
+ if (dialog) {
231
+ const $button = getButtonByIdentifier(identifier, dialog.$el);
232
+ return Button.isEnabled($button);
233
+ }
234
+ }
235
+
236
+ buttonIsVisible(identifier) {
237
+ const dialog = getActiveDialog();
238
+ if (dialog) {
239
+ const $button = getButtonByIdentifier(identifier, dialog.$el);
240
+ return Button.isVisible($button);
241
+ }
242
+ }
243
+
244
+ /**
245
+ * takes either a target spec or a filter function
246
+ * returns all matching dialogs
247
+ */
248
+ getByExtension(extension) {
249
+ var filterFunction;
250
+ if(typeof extension === 'function') {
251
+ filterFunction = extension;
252
+ } else {
253
+ var keys = Object.getOwnPropertyNames(extension);
254
+ filterFunction = function(dialog) {
255
+ var dialogData = $(dialog).data('extension');
256
+ return keys.every((key) => {
257
+ return dialogData[key] === extension[key];
258
+ });
259
+ };
260
+ }
261
+
262
+ return $('.' + DIALOG_CLASS).toArray().filter(filterFunction).map(($el) => {
263
+ return AJS.dialog2($el);
264
+ });
265
+ }
266
+
267
+ // add user defined button to an existing dialog
268
+ addButton(extension, options) {
269
+ options.custom = true;
270
+ var $button = this._renderDialogButton(options, extension);
271
+ var $dialog = this.getByExtension({
272
+ addon_key: extension.addon_key,
273
+ key: extension.key
274
+ })[0].$el;
275
+ var $actionBar = getActionBar($dialog);
276
+ $actionBar.append($button);
277
+ return $dialog;
278
+ }
279
+
280
+ renderErrorState(extension) {
281
+ const $dialog = this.getByExtension({
282
+ addon_key: extension.addon_key,
283
+ key: extension.key,
284
+ })[0].$el;
285
+
286
+ // Fullscreen dialogs already render a close button in the header
287
+ if ($dialog.hasClass('aui-dialog2-fullscreen')) {
288
+ return;
289
+ }
290
+
291
+ // Replace maximum size with xlarge - for better UI experience + less code changes required
292
+ if ($dialog.hasClass('aui-dialog2-maximum')) {
293
+ $dialog.removeClass('aui-dialog2-maximum');
294
+ $dialog.addClass('aui-dialog2-xlarge');
295
+ }
296
+
297
+ $dialog.removeClass('aui-dialog2-chromeless');
298
+
299
+ const $footerActions = $dialog.find(`.${DIALOG_FOOTER_ACTIONS_CLASS}`);
300
+ const closeButtonExists = $dialog.find(`#${DIALOG_ERROR_CLOSE_BTN_ID}`).length > 0;
301
+
302
+ if (!closeButtonExists) {
303
+ const closeButtonOptions = {
304
+ name: 'close',
305
+ id: 'dialog-error-close-btn',
306
+ text: 'Close',
307
+ type: 'primary',
308
+ disabled: false,
309
+ };
310
+
311
+ if ($footerActions.length) {
312
+ const $closeButton = this._renderDialogButton(closeButtonOptions, extension);
313
+ $footerActions.append($closeButton);
314
+ } else {
315
+ $dialog.append(
316
+ this._renderFooter({
317
+ extension: extension,
318
+ actions: [closeButtonOptions],
319
+ })
320
+ );
321
+ }
322
+ }
323
+ }
324
+ }
325
+
326
+ const DialogComponent = new Dialog();
327
+
328
+ EventDispatcher.register('iframe-bridge-established', (data) => {
329
+ if(data.extension.options.isDialog){
330
+ let callback;
331
+ const frameworkAdaptor = HostApi.getFrameworkAdaptor();
332
+ const dialogProvider = frameworkAdaptor.getProviderByModuleName('dialog');
333
+ if (dialogProvider) {
334
+ callback = dialogProvider.close;
335
+ dialogProvider.setButtonDisabled('submit', false);
336
+ } else {
337
+ DialogActions.toggleButton({
338
+ identifier: 'submit',
339
+ enabled: true
340
+ });
341
+ callback = () => {
342
+ DialogActions.close({
343
+ dialog: getActiveDialog(),
344
+ extension: data.extension
345
+ });
346
+ }
347
+ }
348
+
349
+ if(!data.extension.options.preventDialogCloseOnEscape){
350
+ DomEventActions.registerKeyEvent({
351
+ extension_id: data.extension.id,
352
+ key: 27,
353
+ callback
354
+ });
355
+
356
+ EventDispatcher.registerOnce('dialog-close', (d) => {
357
+ DomEventActions.unregisterKeyEvent({
358
+ extension_id: data.extension.id,
359
+ key: 27
360
+ });
361
+ });
362
+ }
363
+ }
364
+ });
365
+
366
+ EventDispatcher.register('dialog-close-active', (data) => {
367
+ var activeDialog = getActiveDialog();
368
+ if(activeDialog){
369
+ DialogActions.close({
370
+ customData: data.customData,
371
+ dialog: activeDialog,
372
+ extension: data.extension
373
+ });
374
+ }
375
+ });
376
+
377
+ EventDispatcher.register('dialog-close', (data) => {
378
+ if (data.dialog) {
379
+ data.dialog.hide();
380
+ }
381
+ });
382
+
383
+ EventDispatcher.register('dialog-button-toggle', (data) => {
384
+ const dialog = getActiveDialog();
385
+ if (dialog) {
386
+ const $button = getButtonByIdentifier(data.identifier, dialog.$el);
387
+ ButtonActions.toggle($button, !data.enabled);
388
+ }
389
+ });
390
+
391
+ EventDispatcher.register('dialog-button-toggle-visibility', (data) => {
392
+ const dialog = getActiveDialog();
393
+ if (dialog) {
394
+ const $button = getButtonByIdentifier(data.identifier, dialog.$el);
395
+ ButtonActions.toggleVisibility($button, data.hidden);
396
+ }
397
+ });
398
+
399
+ EventDispatcher.register('button-clicked', (data) => {
400
+ var $button = data.$el;
401
+ if($button.hasClass(DIALOG_BUTTON_CLASS)) {
402
+ var $dialog = $button.parents('.' + DIALOG_CLASS);
403
+ var $iframe = $dialog.find('iframe');
404
+ if ($iframe.length && $iframe[0].bridgeEstablished) {
405
+ DialogActions.clickButton(Button.getIdentifier($button), $button, $dialog.data('extension'));
406
+ } else {
407
+ DialogActions.close({
408
+ dialog: getActiveDialog(),
409
+ extension: $button.extension
410
+ });
411
+ }
412
+ }
413
+ });
414
+
415
+ if($.fn) {
416
+ EventDispatcher.register('iframe-create', (data) => {
417
+ if(data.extension.options && data.extension.options.isDialog){
418
+ DialogComponent.setIframeDimensions(data.extension.$el);
419
+ }
420
+ });
421
+
422
+ EventDispatcher.register('dialog-button-add', (data) => {
423
+ DialogComponent.addButton(data.extension, data.button);
424
+ });
425
+
426
+ EventDispatcher.register('host-window-resize', Util.debounce(() => {
427
+ $('.' + DIALOG_CLASS).each((i, dialog) => {
428
+ var $dialog = $(dialog);
429
+ var sanitizedOptions = dialogUtils.sanitizeOptions($dialog.data('originalOptions'));
430
+ dialog.style.width = sanitizedOptions.width;
431
+ dialog.style.height = sanitizedOptions.height;
432
+ });
433
+ }, 100));
434
+ }
435
+
436
+
437
+ DomEventActions.registerWindowKeyEvent({
438
+ keyCode: 27,
439
+ callback: () => {
440
+ DialogActions.closeActive({
441
+ customData: {},
442
+ extension: null
443
+ });
444
+ }
445
+ });
446
+
447
+ export default DialogComponent;
@@ -0,0 +1,106 @@
1
+ import DialogComponent from './dialog';
2
+ import IframeContainerComponent from './iframe_container';
3
+ import EventDispatcher from '../dispatchers/event_dispatcher';
4
+ import HostApi from '../host-api';
5
+ import EventActions from '../actions/event_actions';
6
+ import dialogUtils from '../utils/dialog';
7
+ import getBooleanFeatureFlag from '../utils/feature-flag';
8
+ import { getAccessNarrowingSpaceContext } from '../utils/access-narrowing-context';
9
+
10
+ class DialogExtension {
11
+
12
+ render(extension, dialogOptions){
13
+ extension.options = extension.options || {};
14
+ dialogOptions = dialogOptions || {};
15
+ extension.options.isDialog = true;
16
+ extension.options.dialogId = dialogOptions.id;
17
+ extension.options.callbackExtensionId = extension.callback_extension_id;
18
+ extension.options.preventDialogCloseOnEscape = dialogOptions.closeOnEscape === false;
19
+ extension.options.hostFrameOffset = dialogOptions.hostFrameOffset;
20
+ extension.options.hideIframeUntilLoad = true;
21
+ var $iframeContainer = IframeContainerComponent.createExtension(extension);
22
+ var $dialog = DialogComponent.render({
23
+ extension: extension,
24
+ $content: $iframeContainer,
25
+ chrome: dialogOptions.chrome,
26
+ width: dialogOptions.width,
27
+ height: dialogOptions.height,
28
+ size: dialogOptions.size,
29
+ header: dialogOptions.header,
30
+ hint: dialogOptions.hint,
31
+ submitText: dialogOptions.submitText,
32
+ cancelText: dialogOptions.cancelText,
33
+ buttons: dialogOptions.buttons,
34
+ onHide: dialogOptions.onHide
35
+ });
36
+ return $dialog;
37
+ }
38
+
39
+
40
+ renderErrorState(extension) {
41
+ DialogComponent.renderErrorState(extension);
42
+ }
43
+
44
+ getActiveDialog(){
45
+ return DialogComponent.getActive();
46
+ }
47
+
48
+ buttonIsEnabled(identifier) {
49
+ return DialogComponent.buttonIsEnabled(identifier);
50
+ }
51
+
52
+ buttonIsVisible(identifier) {
53
+ return DialogComponent.buttonIsVisible(identifier);
54
+ }
55
+
56
+ getByExtension(extension) {
57
+ if(typeof extension === 'string'){
58
+ extension = {
59
+ id: extension
60
+ };
61
+ }
62
+ return DialogComponent.getByExtension(extension);
63
+ }
64
+
65
+ }
66
+
67
+ var DialogExtensionComponent = new DialogExtension();
68
+ EventDispatcher.register('dialog-extension-open', function(data){
69
+ const dialogExtension = getAccessNarrowingSpaceContext(data.extension);
70
+ let dialogOptions = dialogUtils.sanitizeOptions(data.options);
71
+
72
+ const frameworkAdaptor = HostApi.getFrameworkAdaptor();
73
+ const dialogProvider = frameworkAdaptor.getProviderByModuleName('dialog');
74
+ if (dialogProvider) {
75
+ // this function should move.
76
+ const getOnClickFunction = action => {
77
+ const key = dialogExtension.key;
78
+ const addon_key = dialogExtension.addon_key;
79
+ const eventData = {
80
+ button: {
81
+ identifier: action.identifier,
82
+ name: action.identifier,
83
+ text: action.text
84
+ }
85
+ };
86
+ if (['submit', 'cancel'].indexOf(action.identifier) >= 0) {
87
+ EventActions.broadcast(`dialog.${action.identifier}`, {addon_key, key}, eventData);
88
+ }
89
+ EventActions.broadcast('dialog.button.click', {addon_key, key}, eventData);
90
+ };
91
+
92
+
93
+ dialogExtension.options.preventDialogCloseOnEscape = dialogOptions.closeOnEscape === false;
94
+ dialogOptions.actions.map(action => action.onClick = getOnClickFunction.bind(null, action));
95
+ dialogProvider.create(dialogOptions, dialogExtension);
96
+
97
+ } else {
98
+ DialogExtensionComponent.render(dialogExtension, data.options);
99
+ }
100
+ });
101
+
102
+ EventDispatcher.register('notify-content-resolver-failed', function (extension) {
103
+ DialogExtensionComponent.renderErrorState(extension);
104
+ });
105
+
106
+ export default DialogExtensionComponent;
@@ -0,0 +1,69 @@
1
+ import WebItemActions from '../actions/webitem_actions';
2
+ import EventDispatcher from '../dispatchers/event_dispatcher';
3
+ import WebItemUtils from '../utils/webitem';
4
+ import DialogExtensionActions from '../actions/dialog_extension_actions';
5
+ import $ from '../dollar';
6
+ import Util from '../util';
7
+ import {Flags} from '../utils/feature-flag';
8
+
9
+ const ITEM_NAME = 'dialog';
10
+ const SELECTOR = '.ap-dialog';
11
+ const TRIGGERS = ['click'];
12
+ const WEBITEM_UID_KEY = 'dialog-target-uid';
13
+ const DEFAULT_WEBITEM_OPTIONS = {
14
+ chrome: true
15
+ };
16
+
17
+ class DialogWebItem {
18
+ constructor(){
19
+ this._dialogWebItem = {
20
+ name: ITEM_NAME,
21
+ selector: SELECTOR,
22
+ triggers: TRIGGERS
23
+ };
24
+ }
25
+
26
+ getWebItem(){
27
+ return this._dialogWebItem;
28
+ }
29
+
30
+ _dialogOptions(options){
31
+ return Util.extend({}, DEFAULT_WEBITEM_OPTIONS, options || {});
32
+ }
33
+
34
+ /**
35
+ * @param {WebItemInvokedEventData} data
36
+ */
37
+ triggered(data) {
38
+ const $target = data.$target;
39
+
40
+ var webitemId = $target.data(WEBITEM_UID_KEY);
41
+ var dialogOptions = this._dialogOptions(data.extension.options);
42
+ dialogOptions.id = webitemId;
43
+ DialogExtensionActions.open(data.extension, dialogOptions);
44
+ }
45
+
46
+ /**
47
+ * @param {WebItemInvokedEventData} data
48
+ */
49
+ createIfNotExists(data) {
50
+ const $target = data.$target;
51
+ var uid = $target.data(WEBITEM_UID_KEY);
52
+
53
+ if(!uid) {
54
+ uid = WebItemUtils.uniqueId();
55
+ $target.data(WEBITEM_UID_KEY, uid);
56
+ }
57
+ }
58
+
59
+ }
60
+
61
+ let dialogInstance = new DialogWebItem();
62
+ let webitem = dialogInstance.getWebItem();
63
+ EventDispatcher.register('webitem-invoked:' + webitem.name, function(data){
64
+ dialogInstance.triggered(data);
65
+ });
66
+ EventDispatcher.register('before:webitem-invoked:' + webitem.name, dialogInstance.createIfNotExists);
67
+
68
+ WebItemActions.addWebItem(webitem);
69
+ export default dialogInstance;