polaris_view_components 0.7.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/icons/polaris/AnalyticsMinor.svg +1 -0
  3. data/app/assets/icons/polaris/AppsMinor.svg +1 -0
  4. data/app/assets/icons/polaris/BlockMinor.svg +1 -0
  5. data/app/assets/icons/polaris/ButtonMinor.svg +1 -0
  6. data/app/assets/icons/polaris/CaretDownMinor.svg +1 -1
  7. data/app/assets/icons/polaris/CaretUpMinor.svg +1 -1
  8. data/app/assets/icons/polaris/CircleTickMinor.svg +1 -0
  9. data/app/assets/icons/polaris/Columns3Minor.svg +1 -0
  10. data/app/assets/icons/polaris/CustomersMinor.svg +1 -1
  11. data/app/assets/icons/polaris/DiscountsMinor.svg +1 -0
  12. data/app/assets/icons/polaris/DropdownMinor.svg +1 -1
  13. data/app/assets/icons/polaris/FinancesMajor.svg +1 -0
  14. data/app/assets/icons/polaris/FinancesMinor.svg +1 -0
  15. data/app/assets/icons/polaris/HomeMinor.svg +1 -0
  16. data/app/assets/icons/polaris/MarketingMinor.svg +1 -0
  17. data/app/assets/icons/polaris/OnlineStoreMinor.svg +1 -0
  18. data/app/assets/icons/polaris/OrdersMinor.svg +1 -0
  19. data/app/assets/icons/polaris/ProductsMinor.svg +1 -0
  20. data/app/assets/icons/polaris/QuestionMarkInverseMajor.svg +1 -0
  21. data/app/assets/icons/polaris/QuestionMarkInverseMinor.svg +1 -0
  22. data/app/assets/icons/polaris/SelectMinor.svg +1 -1
  23. data/app/assets/icons/polaris/TitleMinor.svg +1 -0
  24. data/app/assets/icons/polaris/WandMinor.svg +1 -0
  25. data/app/assets/javascripts/polaris_view_components/autocomplete_controller.js +32 -15
  26. data/app/assets/javascripts/polaris_view_components/collapsible_controller.js +19 -0
  27. data/app/assets/javascripts/polaris_view_components/dropzone_controller.js +495 -0
  28. data/app/assets/javascripts/polaris_view_components/index.js +4 -0
  29. data/app/assets/javascripts/polaris_view_components/polaris_controller.js +4 -0
  30. data/app/assets/javascripts/polaris_view_components/popover_controller.js +9 -2
  31. data/app/assets/javascripts/polaris_view_components/toast_controller.js +13 -2
  32. data/app/assets/javascripts/polaris_view_components/utils.js +23 -0
  33. data/app/assets/javascripts/polaris_view_components.js +560 -65
  34. data/app/assets/stylesheets/polaris_view_components/custom.css +38 -6
  35. data/app/assets/stylesheets/polaris_view_components.css +2107 -2021
  36. data/app/assets/stylesheets/polaris_view_components.postcss.css +1 -1
  37. data/app/components/polaris/action_list/item_component.rb +1 -1
  38. data/app/components/polaris/action_list/section_component.rb +1 -1
  39. data/app/components/polaris/action_list_component.rb +1 -1
  40. data/app/components/polaris/autocomplete/action_component.rb +1 -1
  41. data/app/components/polaris/autocomplete/option_component.rb +1 -1
  42. data/app/components/polaris/autocomplete/section_component.rb +1 -1
  43. data/app/components/polaris/autocomplete_component.rb +9 -2
  44. data/app/components/polaris/avatar_component.rb +1 -1
  45. data/app/components/polaris/badge_component.rb +1 -1
  46. data/app/components/polaris/banner_component.rb +2 -2
  47. data/app/components/polaris/base_button.rb +1 -1
  48. data/app/components/polaris/base_checkbox.rb +1 -1
  49. data/app/components/polaris/base_component.rb +1 -1
  50. data/app/components/polaris/base_radio_button.rb +1 -1
  51. data/app/components/polaris/button_group_component.rb +3 -3
  52. data/app/components/polaris/callout_card_component.rb +1 -1
  53. data/app/components/polaris/caption_component.rb +1 -1
  54. data/app/components/polaris/card/header_component.rb +1 -1
  55. data/app/components/polaris/card/section_component.rb +2 -2
  56. data/app/components/polaris/card_component.rb +1 -1
  57. data/app/components/polaris/checkbox_component.rb +1 -1
  58. data/app/components/polaris/choice_component.rb +1 -1
  59. data/app/components/polaris/choice_list_component.rb +1 -1
  60. data/app/components/polaris/collapsible_component.rb +37 -0
  61. data/app/components/polaris/component.rb +6 -1
  62. data/app/components/polaris/data_table/cell_component.rb +1 -1
  63. data/app/components/polaris/data_table/column_component.rb +1 -1
  64. data/app/components/polaris/data_table_component.rb +1 -1
  65. data/app/components/polaris/description_list_component.rb +2 -2
  66. data/app/components/polaris/display_text_component.rb +1 -1
  67. data/app/components/polaris/dropzone_component.html.erb +156 -0
  68. data/app/components/polaris/dropzone_component.rb +150 -0
  69. data/app/components/polaris/empty_state_component.rb +1 -1
  70. data/app/components/polaris/exception_list/item_component.rb +1 -1
  71. data/app/components/polaris/exception_list_component.rb +1 -1
  72. data/app/components/polaris/filters_component.rb +3 -3
  73. data/app/components/polaris/footer_help_component.rb +1 -1
  74. data/app/components/polaris/form_layout/group_component.rb +2 -2
  75. data/app/components/polaris/form_layout/item_component.rb +1 -1
  76. data/app/components/polaris/form_layout_component.rb +1 -1
  77. data/app/components/polaris/frame/save_bar_component.rb +1 -1
  78. data/app/components/polaris/frame/top_bar_component.rb +1 -1
  79. data/app/components/polaris/frame_component.rb +1 -1
  80. data/app/components/polaris/heading_component.rb +1 -1
  81. data/app/components/polaris/headless_button.rb +1 -1
  82. data/app/components/polaris/icon_component.rb +1 -1
  83. data/app/components/polaris/index_table/cell_component.rb +1 -1
  84. data/app/components/polaris/index_table/column_component.rb +1 -1
  85. data/app/components/polaris/index_table_component.rb +1 -1
  86. data/app/components/polaris/inline_error_component.rb +1 -1
  87. data/app/components/polaris/keyboard_key_component.rb +20 -0
  88. data/app/components/polaris/label_component.rb +1 -1
  89. data/app/components/polaris/labelled_component.rb +1 -1
  90. data/app/components/polaris/layout/annotated_section.rb +1 -1
  91. data/app/components/polaris/layout/section.rb +1 -1
  92. data/app/components/polaris/layout_component.rb +1 -1
  93. data/app/components/polaris/link_component.rb +1 -1
  94. data/app/components/polaris/list_component.rb +2 -2
  95. data/app/components/polaris/modal/section_component.rb +1 -1
  96. data/app/components/polaris/modal_component.rb +1 -1
  97. data/app/components/polaris/navigation/item_component.rb +2 -2
  98. data/app/components/polaris/navigation/section_component.rb +2 -2
  99. data/app/components/polaris/navigation_component.rb +1 -1
  100. data/app/components/polaris/option_list/checkbox_component.rb +1 -1
  101. data/app/components/polaris/option_list/option_component.rb +1 -1
  102. data/app/components/polaris/option_list/radio_button_component.rb +1 -1
  103. data/app/components/polaris/option_list/section_component.rb +1 -1
  104. data/app/components/polaris/option_list_component.rb +1 -1
  105. data/app/components/polaris/page_actions_component.rb +1 -1
  106. data/app/components/polaris/page_component.rb +1 -1
  107. data/app/components/polaris/pagination_component.rb +1 -1
  108. data/app/components/polaris/popover/pane_component.rb +1 -1
  109. data/app/components/polaris/popover/section_component.rb +1 -1
  110. data/app/components/polaris/popover_component.rb +10 -4
  111. data/app/components/polaris/progress_bar_component.rb +1 -1
  112. data/app/components/polaris/radio_button_component.rb +1 -1
  113. data/app/components/polaris/resource_item_component.rb +4 -2
  114. data/app/components/polaris/resource_list_component.rb +1 -1
  115. data/app/components/polaris/scrollable_component.rb +1 -1
  116. data/app/components/polaris/select_component.rb +1 -1
  117. data/app/components/polaris/setting_toggle_component.rb +1 -1
  118. data/app/components/polaris/shopify_navigation_component.rb +2 -2
  119. data/app/components/polaris/skeleton_body_text_component.rb +1 -1
  120. data/app/components/polaris/skeleton_display_text_component.rb +32 -0
  121. data/app/components/polaris/skeleton_thumbnail_component.rb +31 -0
  122. data/app/components/polaris/spacer_component.rb +1 -1
  123. data/app/components/polaris/spinner_component.rb +1 -1
  124. data/app/components/polaris/stack/item_component.rb +15 -0
  125. data/app/components/polaris/stack_component.rb +2 -18
  126. data/app/components/polaris/subheading_component.rb +1 -1
  127. data/app/components/polaris/tabs/tab_component.rb +1 -1
  128. data/app/components/polaris/tabs_component.rb +1 -1
  129. data/app/components/polaris/tag_component.rb +3 -2
  130. data/app/components/polaris/text_container_component.rb +1 -1
  131. data/app/components/polaris/text_field_component.rb +2 -2
  132. data/app/components/polaris/text_style_component.rb +1 -1
  133. data/app/components/polaris/thumbnail_component.rb +1 -1
  134. data/app/components/polaris/toast_component.rb +1 -1
  135. data/app/components/polaris/top_bar/user_menu_component.rb +1 -1
  136. data/app/components/polaris/visually_hidden_component.rb +1 -1
  137. data/app/helpers/polaris/form_builder.rb +14 -5
  138. data/app/helpers/polaris/view_helper.rb +6 -1
  139. data/config/locales/en.yml +6 -0
  140. data/lib/polaris/view_components/engine.rb +5 -1
  141. data/lib/polaris/view_components/version.rb +1 -1
  142. metadata +31 -21
  143. data/app/components/polaris/application_component.rb +0 -35
  144. data/app/components/polaris/dropzone/component.html.erb +0 -72
  145. data/app/components/polaris/dropzone/component.rb +0 -128
  146. data/app/components/polaris/dropzone/controller.js +0 -226
  147. data/app/components/polaris/dropzone/utils.js +0 -57
  148. data/app/components/polaris/new_component.rb +0 -10
  149. data/app/helpers/polaris/conditional_helper.rb +0 -11
@@ -2,10 +2,25 @@ import { Controller } from "@hotwired/stimulus";
2
2
 
3
3
  import { get } from "@rails/request.js";
4
4
 
5
+ function debounce$1(fn, wait) {
6
+ let timeoutId;
7
+ return (...args) => {
8
+ clearTimeout(timeoutId);
9
+ timeoutId = setTimeout((() => fn.apply(this, args)), wait);
10
+ };
11
+ }
12
+
13
+ function formatBytes(bytes, decimals) {
14
+ if (bytes == 0) return "0 Bytes";
15
+ const k = 1024, dm = decimals || 2, sizes = [ "Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" ], i = Math.floor(Math.log(bytes) / Math.log(k));
16
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
17
+ }
18
+
5
19
  class Autocomplete extends Controller {
6
20
  static targets=[ "popover", "input", "results", "option", "emptyState" ];
7
21
  static values={
8
- url: String
22
+ url: String,
23
+ selected: Array
9
24
  };
10
25
  connect() {
11
26
  this.inputTarget.addEventListener("input", this.onInputChange);
@@ -14,13 +29,10 @@ class Autocomplete extends Controller {
14
29
  this.inputTarget.removeEventListener("input", this.onInputChange);
15
30
  }
16
31
  toggle() {
17
- if (this.visibleOptions.length > 0) {
18
- this.hideEmptyState();
19
- this.popoverController.show();
20
- } else if (this.value.length > 0 && this.hasEmptyStateTarget) {
21
- this.showEmptyState();
32
+ if (this.isRemote && this.visibleOptions.length == 0 && this.value.length == 0) {
33
+ this.fetchResults();
22
34
  } else {
23
- this.popoverController.forceHide();
35
+ this.handleResults();
24
36
  }
25
37
  }
26
38
  select(event) {
@@ -42,6 +54,13 @@ class Autocomplete extends Controller {
42
54
  this.filterOptions();
43
55
  }
44
56
  }), 200);
57
+ reset() {
58
+ this.inputTarget.value = "";
59
+ this.optionTargets.forEach((option => {
60
+ option.classList.add("Polaris--hidden");
61
+ }));
62
+ this.handleResults();
63
+ }
45
64
  get isRemote() {
46
65
  return this.urlValue.length > 0;
47
66
  }
@@ -54,6 +73,17 @@ class Autocomplete extends Controller {
54
73
  get visibleOptions() {
55
74
  return this.optionTargets.filter((option => !option.classList.contains("Polaris--hidden")));
56
75
  }
76
+ handleResults() {
77
+ if (this.visibleOptions.length > 0) {
78
+ this.hideEmptyState();
79
+ this.popoverController.show();
80
+ this.checkSelected();
81
+ } else if (this.value.length > 0 && this.hasEmptyStateTarget) {
82
+ this.showEmptyState();
83
+ } else {
84
+ this.popoverController.forceHide();
85
+ }
86
+ }
57
87
  filterOptions() {
58
88
  if (this.value === "") {
59
89
  this.optionTargets.forEach((option => {
@@ -69,7 +99,7 @@ class Autocomplete extends Controller {
69
99
  }
70
100
  }));
71
101
  }
72
- this.toggle();
102
+ this.handleResults();
73
103
  }
74
104
  async fetchResults() {
75
105
  const response = await get(this.urlValue, {
@@ -80,7 +110,7 @@ class Autocomplete extends Controller {
80
110
  if (response.ok) {
81
111
  const results = await response.html;
82
112
  this.resultsTarget.innerHTML = results;
83
- this.toggle();
113
+ this.handleResults();
84
114
  }
85
115
  }
86
116
  showEmptyState() {
@@ -95,16 +125,15 @@ class Autocomplete extends Controller {
95
125
  this.resultsTarget.classList.remove("Polaris--hidden");
96
126
  }
97
127
  }
128
+ checkSelected() {
129
+ this.visibleOptions.forEach((option => {
130
+ const input = option.querySelector("input");
131
+ if (!input) return;
132
+ input.checked = this.selectedValue.includes(input.value);
133
+ }));
134
+ }
98
135
  }
99
136
 
100
- const debounce$1 = (fn, delay = 10) => {
101
- let timeoutId = null;
102
- return (...args) => {
103
- clearTimeout(timeoutId);
104
- timeoutId = setTimeout(fn, delay);
105
- };
106
- };
107
-
108
137
  class Button extends Controller {
109
138
  disable(event) {
110
139
  if (this.button.disabled) {
@@ -136,6 +165,405 @@ class Button extends Controller {
136
165
  }
137
166
  }
138
167
 
168
+ class Collapsible extends Controller {
169
+ toggle() {
170
+ if (this.isClosed) {
171
+ this.element.style.maxHeight = "none";
172
+ this.element.style.overflow = "visible";
173
+ this.element.classList.remove("Polaris-Collapsible--isFullyClosed");
174
+ } else {
175
+ this.element.style.maxHeight = "0px";
176
+ this.element.style.overflow = "hidden";
177
+ this.element.classList.add("Polaris-Collapsible--isFullyClosed");
178
+ }
179
+ }
180
+ get isClosed() {
181
+ return this.element.classList.contains("Polaris-Collapsible--isFullyClosed");
182
+ }
183
+ }
184
+
185
+ const dragEvents = [ "dragover", "dragenter", "drop" ];
186
+
187
+ const SIZES = {
188
+ SMALL: "small",
189
+ MEDIUM: "medium",
190
+ LARGE: "large",
191
+ EXTRA_LARGE: "extraLarge"
192
+ };
193
+
194
+ class Dropzone extends Controller {
195
+ static targets=[ "container", "fileUpload", "loader", "input", "preview", "previewTemplate", "itemTemplate", "overlay", "errorOverlay" ];
196
+ static classes=[ "disabled" ];
197
+ static values={
198
+ accept: String,
199
+ allowMultiple: Boolean,
200
+ disabled: Boolean,
201
+ dropOnPage: Boolean,
202
+ focused: Boolean,
203
+ renderPreview: Boolean,
204
+ size: String
205
+ };
206
+ files=[];
207
+ acceptedFiles=[];
208
+ rejectedFiles=[];
209
+ _dragging=false;
210
+ dragTargets=[];
211
+ previewRendered=false;
212
+ _size="large";
213
+ connect() {
214
+ document.body.addEventListener("click", this.onExternalTriggerClick);
215
+ addEventListener("resize", this.onWindowResize);
216
+ addEventListener("direct-uploads:start", this.onDirectUploadsStart);
217
+ addEventListener("direct-uploads:end", this.onDirectUploadsEnd);
218
+ addEventListener("direct-upload:initialize", this.onDirectUploadInitialize);
219
+ addEventListener("direct-upload:start", this.onDirectUploadStart);
220
+ addEventListener("direct-upload:progress", this.onDirectUploadProgress);
221
+ addEventListener("direct-upload:error", this.onDirectUploadError);
222
+ addEventListener("direct-upload:end", this.onDirectUploadEnd);
223
+ this.onWindowResize();
224
+ }
225
+ disconnect() {
226
+ document.body.removeEventListener("click", this.onExternalTriggerClick);
227
+ removeEventListener("resize", this.onWindowResize);
228
+ removeEventListener("direct-uploads:start", this.onDirectUploadsStart);
229
+ removeEventListener("direct-uploads:end", this.onDirectUploadsEnd);
230
+ removeEventListener("direct-upload:initialize", this.onDirectUploadInitialize);
231
+ removeEventListener("direct-upload:start", this.onDirectUploadStart);
232
+ removeEventListener("direct-upload:progress", this.onDirectUploadProgress);
233
+ removeEventListener("direct-upload:error", this.onDirectUploadError);
234
+ removeEventListener("direct-upload:end", this.onDirectUploadEnd);
235
+ }
236
+ onExternalTriggerClick=event => {
237
+ const trigger = event.target.closest(`[data-${this.identifier}-external-target="trigger"]`);
238
+ if (!trigger) return;
239
+ event.preventDefault();
240
+ this.onClick();
241
+ };
242
+ onWindowResize=debounce$1((() => {
243
+ const size = this.calculateSize();
244
+ if (size !== this.size) {
245
+ this.size = size;
246
+ }
247
+ }), 50);
248
+ onBlur() {
249
+ this.focusedValue = false;
250
+ }
251
+ onChange(e) {
252
+ this.stopEvent(e);
253
+ if (this.disabled) return;
254
+ this.clearFiles();
255
+ const fileList = getDataTransferFiles(e);
256
+ const {files: files, acceptedFiles: acceptedFiles, rejectedFiles: rejectedFiles} = this.getValidatedFiles(fileList);
257
+ this.dragTargets = [];
258
+ this.files = files;
259
+ this.acceptedFiles = acceptedFiles;
260
+ this.rejectedFiles = rejectedFiles;
261
+ this.render();
262
+ }
263
+ onDragOver(e) {
264
+ this.stopEvent(e);
265
+ if (this.disabled) return;
266
+ }
267
+ onDragEnter(e) {
268
+ this.stopEvent(e);
269
+ if (this.disabled) return;
270
+ if (e.target && !this.dragTargets.includes(e.target)) {
271
+ this.dragTargets.push(e.target);
272
+ }
273
+ if (this.dragging) return;
274
+ this.dragging = true;
275
+ }
276
+ onDragLeave(e) {
277
+ this.stopEvent(e);
278
+ if (this.disabled) return;
279
+ this.dragTargets = this.dragTargets.filter((el => {
280
+ const compareNode = this.element;
281
+ return el !== e.target && compareNode && compareNode.contains(el);
282
+ }));
283
+ if (this.dragTargets.length > 0) return;
284
+ this.dragging = false;
285
+ }
286
+ onDrop(e) {
287
+ this.stopEvent(e);
288
+ if (this.disabled) return;
289
+ this.dragging = false;
290
+ this.onChange(e);
291
+ }
292
+ onFocus() {
293
+ this.focusedValue = true;
294
+ }
295
+ onClick() {
296
+ if (this.disabledValue) return;
297
+ this.open();
298
+ }
299
+ onDirectUploadsStart=() => {
300
+ this.disable();
301
+ };
302
+ onDirectUploadsEnd=() => {
303
+ this.enable();
304
+ this.clearFiles();
305
+ this.loaderTarget.classList.remove("Polaris--hidden");
306
+ };
307
+ onDirectUploadInitialize=event => {
308
+ const {target: target, detail: detail} = event;
309
+ const {id: id, file: file} = detail;
310
+ const dropzone = target.closest(".Polaris-DropZone");
311
+ if (!dropzone) return;
312
+ const content = dropzone.querySelector(`[data-file-name="${file.name}"]`);
313
+ const progressBar = content.parentElement.querySelector('[data-target="progress-bar"]');
314
+ progressBar.id = `direct-upload-${id}`;
315
+ };
316
+ onDirectUploadStart=event => {
317
+ const {id: id} = event.detail;
318
+ const progressBar = document.getElementById(`direct-upload-${id}`);
319
+ if (!progressBar) return;
320
+ progressBar.classList.remove("Polaris--hidden");
321
+ };
322
+ onDirectUploadProgress=event => {
323
+ const {id: id, progress: progress} = event.detail;
324
+ const progressBar = document.getElementById(`direct-upload-${id}`);
325
+ if (!progressBar) return;
326
+ const progressElement = progressBar.querySelector(".Polaris-ProgressBar__Indicator");
327
+ progressElement.style.width = `${progress}%`;
328
+ };
329
+ onDirectUploadError=event => {
330
+ const {id: id, error: error} = event.detail;
331
+ const progressBar = document.getElementById(`direct-upload-${id}`);
332
+ if (!progressBar) return;
333
+ event.preventDefault();
334
+ progressBar.classList.add("Polaris--hidden");
335
+ const uploadError = progressBar.parentElement.querySelector('[data-target="upload-error"]');
336
+ const errorIcon = uploadError.querySelector(".Polaris-InlineError__Icon");
337
+ if (errorIcon) errorIcon.remove();
338
+ uploadError.classList.remove("Polaris--hidden");
339
+ };
340
+ onDirectUploadEnd=event => {
341
+ const {id: id} = event.detail;
342
+ const progressBar = document.getElementById(`direct-upload-${id}`);
343
+ if (!progressBar) return;
344
+ progressBar.classList.add("Polaris-ProgressBar--colorSuccess");
345
+ };
346
+ open() {
347
+ this.inputTarget.click();
348
+ }
349
+ focusedValueChanged() {
350
+ this.element.classList.toggle("Polaris-DropZone--focused", this.focusedValue);
351
+ }
352
+ stopEvent(e) {
353
+ e.preventDefault();
354
+ e.stopPropagation();
355
+ }
356
+ getValidatedFiles(files) {
357
+ const acceptedFiles = [];
358
+ const rejectedFiles = [];
359
+ Array.from(files).forEach((file => {
360
+ if (fileAccepted(file, this.acceptValue)) {
361
+ acceptedFiles.push(file);
362
+ } else {
363
+ rejectedFiles.push(file);
364
+ }
365
+ }));
366
+ if (!this.allowMultipleValue) {
367
+ acceptedFiles.splice(1, acceptedFiles.length);
368
+ rejectedFiles.push(...acceptedFiles.slice(1));
369
+ }
370
+ return {
371
+ files: files,
372
+ acceptedFiles: acceptedFiles,
373
+ rejectedFiles: rejectedFiles
374
+ };
375
+ }
376
+ render() {
377
+ if (this.files.length === 0) {
378
+ this.toggleFileUpload(true);
379
+ this.toggleErrorOverlay(false);
380
+ } else if (this.rejectedFiles.length > 0) {
381
+ this.toggleFileUpload(false);
382
+ this.toggleErrorOverlay(true);
383
+ const dropRejectedEvent = new CustomEvent("polaris-dropzone:drop-rejected", {
384
+ detail: {
385
+ rejectedFiles: this.rejectedFiles
386
+ }
387
+ });
388
+ this.element.dispatchEvent(dropRejectedEvent);
389
+ } else if (this.acceptedFiles.length > 0) {
390
+ if (this.renderPreviewValue) {
391
+ this.renderUploadedFiles();
392
+ this.toggleFileUpload(false);
393
+ }
394
+ this.toggleErrorOverlay(false);
395
+ const dropAcceptedEvent = new CustomEvent("polaris-dropzone:drop-accepted", {
396
+ detail: {
397
+ acceptedFiles: this.acceptedFiles
398
+ }
399
+ });
400
+ this.element.dispatchEvent(dropAcceptedEvent);
401
+ }
402
+ const dropEvent = new CustomEvent("polaris-dropzone:drop", {
403
+ detail: {
404
+ files: this.files,
405
+ acceptedFiles: this.acceptedFiles,
406
+ rejectedFiles: this.rejectedFiles
407
+ }
408
+ });
409
+ this.element.dispatchEvent(dropEvent);
410
+ }
411
+ renderUploadedFiles() {
412
+ if (this.acceptedFiles.length === 0) return;
413
+ const clone = this.previewTemplateTarget.content.cloneNode(true);
414
+ const filesTarget = clone.querySelector(".target");
415
+ let files = this.acceptedFiles;
416
+ if (this.sizeValue == "small") files = [ files[0] ];
417
+ files.map((file => this.renderFile(file))).forEach((fragment => filesTarget.parentNode.appendChild(fragment)));
418
+ filesTarget.remove();
419
+ this.containerTarget.prepend(clone);
420
+ this.previewRendered = true;
421
+ }
422
+ toggleFileUpload(show = false) {
423
+ this.fileUploadTarget.classList.toggle("Polaris-VisuallyHidden", !show);
424
+ }
425
+ toggleErrorOverlay(show = false) {
426
+ this.errorOverlayTarget.classList.toggle("Polaris-VisuallyHidden", !show);
427
+ this.element.classList.toggle("Polaris-DropZone--hasError", show);
428
+ }
429
+ renderFile(file) {
430
+ const validImageTypes = [ "image/gif", "image/jpeg", "image/png" ];
431
+ const clone = this.itemTemplateTarget.content.cloneNode(true);
432
+ const [icon, thumbnail, content, fileSize] = [ clone.querySelector('[data-target="icon"]'), clone.querySelector('[data-target="thumbnail"]'), clone.querySelector('[data-target="content"]'), clone.querySelector('[data-target="file-size"]') ];
433
+ if (validImageTypes.includes(file.type)) {
434
+ const img = thumbnail.querySelector("img");
435
+ img.alt = file.name;
436
+ img.src = window.URL.createObjectURL(file);
437
+ icon.remove();
438
+ } else {
439
+ thumbnail.remove();
440
+ }
441
+ if (this.sizeValue != "small") {
442
+ content.insertAdjacentText("afterbegin", file.name);
443
+ content.setAttribute("data-file-name", file.name);
444
+ fileSize.textContent = formatBytes(file.size);
445
+ }
446
+ return clone;
447
+ }
448
+ clearFiles() {
449
+ if (!this.previewRendered) return;
450
+ this.acceptedFiles = [];
451
+ this.files = [];
452
+ this.rejectedFiles = [];
453
+ if (!this.hasPreviewTarget) return;
454
+ this.previewTarget.remove();
455
+ this.previewRendered = false;
456
+ }
457
+ calculateSize() {
458
+ const width = this.element.getBoundingClientRect().width;
459
+ let size = SIZES.LARGE;
460
+ if (width < 100) {
461
+ size = SIZES.SMALL;
462
+ } else if (width < 160) {
463
+ size = SIZES.MEDIUM;
464
+ } else if (width > 300) {
465
+ size = SIZES.EXTRA_LARGE;
466
+ }
467
+ this.size = size;
468
+ return size;
469
+ }
470
+ getSizeClass(size = "large") {
471
+ return this.sizeClassesSchema[size] || this.sizeClassesSchema.large;
472
+ }
473
+ disable() {
474
+ this.disabled = true;
475
+ this.element.classList.add(this.disabledClass);
476
+ this.inputTarget.disabled = true;
477
+ }
478
+ enable() {
479
+ this.disabled = false;
480
+ this.element.classList.remove(this.disabledClass);
481
+ this.inputTarget.disabled = false;
482
+ }
483
+ get fileListRendered() {
484
+ return this.element.querySelector("[data-rendered]");
485
+ }
486
+ get dropNode() {
487
+ return this.dropOnPageValue ? document : this.element;
488
+ }
489
+ get disabled() {
490
+ return this.disabledValue;
491
+ }
492
+ set disabled(val) {
493
+ this.disabledValue = val;
494
+ }
495
+ get dragging() {
496
+ return this._dragging;
497
+ }
498
+ set dragging(val) {
499
+ this._dragging = val;
500
+ this.element.classList.toggle("Polaris-DropZone--isDragging", val);
501
+ this.overlayTarget.classList.toggle("Polaris-VisuallyHidden", !val);
502
+ }
503
+ get sizeClassesSchema() {
504
+ return {
505
+ [SIZES.SMALL]: "Polaris-DropZone--sizeSmall",
506
+ [SIZES.MEDIUM]: "Polaris-DropZone--sizeMedium",
507
+ [SIZES.LARGE]: "Polaris-DropZone--sizeLarge",
508
+ [SIZES.EXTRA_LARGE]: "Polaris-DropZone--sizeExtraLarge"
509
+ };
510
+ }
511
+ get size() {
512
+ return this._size;
513
+ }
514
+ set size(val) {
515
+ this._size = val;
516
+ const sizeClassesToRemove = Object.values(this.sizeClassesSchema);
517
+ sizeClassesToRemove.forEach((className => this.element.classList.remove(className)));
518
+ this.element.classList.add(this.getSizeClass(val));
519
+ }
520
+ }
521
+
522
+ function fileAccepted(file, accept) {
523
+ return file.type === "application/x-moz-file" || accepts(file, accept);
524
+ }
525
+
526
+ function getDataTransferFiles(event) {
527
+ if (isDragEvent(event) && event.dataTransfer) {
528
+ const dt = event.dataTransfer;
529
+ if (dt.files && dt.files.length) {
530
+ return Array.from(dt.files);
531
+ } else if (dt.items && dt.items.length) {
532
+ return Array.from(dt.items);
533
+ }
534
+ } else if (isChangeEvent(event) && event.target.files) {
535
+ return Array.from(event.target.files);
536
+ }
537
+ return [];
538
+ }
539
+
540
+ function accepts(file, acceptedFiles = [ "" ]) {
541
+ if (file && acceptedFiles) {
542
+ const fileName = file.name || "";
543
+ const mimeType = file.type || "";
544
+ const baseMimeType = mimeType.replace(/\/.*$/, "");
545
+ const acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(",");
546
+ return acceptedFilesArray.some((type => {
547
+ const validType = type.trim();
548
+ if (validType.startsWith(".")) {
549
+ return fileName.toLowerCase().endsWith(validType.toLowerCase());
550
+ } else if (validType.endsWith("/*")) {
551
+ return baseMimeType === validType.replace(/\/.*$/, "");
552
+ }
553
+ return mimeType === validType;
554
+ }));
555
+ }
556
+ return true;
557
+ }
558
+
559
+ function isDragEvent(event) {
560
+ return dragEvents.indexOf(event.type) > 0;
561
+ }
562
+
563
+ function isChangeEvent(event) {
564
+ return event.type === "change";
565
+ }
566
+
139
567
  const alpineNames = {
140
568
  enterFromClass: "enter",
141
569
  enterActiveClass: "enterStart",
@@ -392,6 +820,9 @@ class Polaris extends Controller {
392
820
  showToast() {
393
821
  this.findElement("toast").show();
394
822
  }
823
+ toggleCollapsible() {
824
+ this.findElement("collapsible").toggle();
825
+ }
395
826
  findElement(type) {
396
827
  const targetId = this.element.dataset.target.replace("#", "");
397
828
  const target = document.getElementById(targetId);
@@ -558,10 +989,29 @@ function getBasePlacement(placement) {
558
989
  return placement.split("-")[0];
559
990
  }
560
991
 
992
+ var max = Math.max;
993
+
994
+ var min = Math.min;
995
+
996
+ var round = Math.round;
997
+
561
998
  function getBoundingClientRect(element, includeScale) {
999
+ if (includeScale === void 0) {
1000
+ includeScale = false;
1001
+ }
562
1002
  var rect = element.getBoundingClientRect();
563
1003
  var scaleX = 1;
564
1004
  var scaleY = 1;
1005
+ if (isHTMLElement(element) && includeScale) {
1006
+ var offsetHeight = element.offsetHeight;
1007
+ var offsetWidth = element.offsetWidth;
1008
+ if (offsetWidth > 0) {
1009
+ scaleX = round(rect.width) / offsetWidth || 1;
1010
+ }
1011
+ if (offsetHeight > 0) {
1012
+ scaleY = round(rect.height) / offsetHeight || 1;
1013
+ }
1014
+ }
565
1015
  return {
566
1016
  width: rect.width / scaleX,
567
1017
  height: rect.height / scaleY,
@@ -671,16 +1121,15 @@ function getMainAxisFromPlacement(placement) {
671
1121
  return [ "top", "bottom" ].indexOf(placement) >= 0 ? "x" : "y";
672
1122
  }
673
1123
 
674
- var max = Math.max;
675
-
676
- var min = Math.min;
677
-
678
- var round = Math.round;
679
-
680
1124
  function within(min$1, value, max$1) {
681
1125
  return max(min$1, min(value, max$1));
682
1126
  }
683
1127
 
1128
+ function withinMaxClamp(min, value, max) {
1129
+ var v = within(min, value, max);
1130
+ return v > max ? max : v;
1131
+ }
1132
+
684
1133
  function getFreshSideObject() {
685
1134
  return {
686
1135
  top: 0,
@@ -782,15 +1231,24 @@ function roundOffsetsByDPR(_ref) {
782
1231
  var win = window;
783
1232
  var dpr = win.devicePixelRatio || 1;
784
1233
  return {
785
- x: round(round(x * dpr) / dpr) || 0,
786
- y: round(round(y * dpr) / dpr) || 0
1234
+ x: round(x * dpr) / dpr || 0,
1235
+ y: round(y * dpr) / dpr || 0
787
1236
  };
788
1237
  }
789
1238
 
790
1239
  function mapToStyles(_ref2) {
791
1240
  var _Object$assign2;
792
- var popper = _ref2.popper, popperRect = _ref2.popperRect, placement = _ref2.placement, variation = _ref2.variation, offsets = _ref2.offsets, position = _ref2.position, gpuAcceleration = _ref2.gpuAcceleration, adaptive = _ref2.adaptive, roundOffsets = _ref2.roundOffsets;
793
- var _ref3 = roundOffsets === true ? roundOffsetsByDPR(offsets) : typeof roundOffsets === "function" ? roundOffsets(offsets) : offsets, _ref3$x = _ref3.x, x = _ref3$x === void 0 ? 0 : _ref3$x, _ref3$y = _ref3.y, y = _ref3$y === void 0 ? 0 : _ref3$y;
1241
+ var popper = _ref2.popper, popperRect = _ref2.popperRect, placement = _ref2.placement, variation = _ref2.variation, offsets = _ref2.offsets, position = _ref2.position, gpuAcceleration = _ref2.gpuAcceleration, adaptive = _ref2.adaptive, roundOffsets = _ref2.roundOffsets, isFixed = _ref2.isFixed;
1242
+ var _offsets$x = offsets.x, x = _offsets$x === void 0 ? 0 : _offsets$x, _offsets$y = offsets.y, y = _offsets$y === void 0 ? 0 : _offsets$y;
1243
+ var _ref3 = typeof roundOffsets === "function" ? roundOffsets({
1244
+ x: x,
1245
+ y: y
1246
+ }) : {
1247
+ x: x,
1248
+ y: y
1249
+ };
1250
+ x = _ref3.x;
1251
+ y = _ref3.y;
794
1252
  var hasX = offsets.hasOwnProperty("x");
795
1253
  var hasY = offsets.hasOwnProperty("y");
796
1254
  var sideX = left;
@@ -810,18 +1268,29 @@ function mapToStyles(_ref2) {
810
1268
  offsetParent = offsetParent;
811
1269
  if (placement === top || (placement === left || placement === right) && variation === end) {
812
1270
  sideY = bottom;
813
- y -= offsetParent[heightProp] - popperRect.height;
1271
+ var offsetY = isFixed && win.visualViewport ? win.visualViewport.height : offsetParent[heightProp];
1272
+ y -= offsetY - popperRect.height;
814
1273
  y *= gpuAcceleration ? 1 : -1;
815
1274
  }
816
1275
  if (placement === left || (placement === top || placement === bottom) && variation === end) {
817
1276
  sideX = right;
818
- x -= offsetParent[widthProp] - popperRect.width;
1277
+ var offsetX = isFixed && win.visualViewport ? win.visualViewport.width : offsetParent[widthProp];
1278
+ x -= offsetX - popperRect.width;
819
1279
  x *= gpuAcceleration ? 1 : -1;
820
1280
  }
821
1281
  }
822
1282
  var commonStyles = Object.assign({
823
1283
  position: position
824
1284
  }, adaptive && unsetSides);
1285
+ var _ref4 = roundOffsets === true ? roundOffsetsByDPR({
1286
+ x: x,
1287
+ y: y
1288
+ }) : {
1289
+ x: x,
1290
+ y: y
1291
+ };
1292
+ x = _ref4.x;
1293
+ y = _ref4.y;
825
1294
  if (gpuAcceleration) {
826
1295
  var _Object$assign;
827
1296
  return Object.assign({}, commonStyles, (_Object$assign = {}, _Object$assign[sideY] = hasY ? "0" : "",
@@ -832,15 +1301,16 @@ function mapToStyles(_ref2) {
832
1301
  _Object$assign2[sideX] = hasX ? x + "px" : "", _Object$assign2.transform = "", _Object$assign2));
833
1302
  }
834
1303
 
835
- function computeStyles(_ref4) {
836
- var state = _ref4.state, options = _ref4.options;
1304
+ function computeStyles(_ref5) {
1305
+ var state = _ref5.state, options = _ref5.options;
837
1306
  var _options$gpuAccelerat = options.gpuAcceleration, gpuAcceleration = _options$gpuAccelerat === void 0 ? true : _options$gpuAccelerat, _options$adaptive = options.adaptive, adaptive = _options$adaptive === void 0 ? true : _options$adaptive, _options$roundOffsets = options.roundOffsets, roundOffsets = _options$roundOffsets === void 0 ? true : _options$roundOffsets;
838
1307
  var commonStyles = {
839
1308
  placement: getBasePlacement(state.placement),
840
1309
  variation: getVariation(state.placement),
841
1310
  popper: state.elements.popper,
842
1311
  popperRect: state.rects.popper,
843
- gpuAcceleration: gpuAcceleration
1312
+ gpuAcceleration: gpuAcceleration,
1313
+ isFixed: state.options.strategy === "fixed"
844
1314
  };
845
1315
  if (state.modifiersData.popperOffsets != null) {
846
1316
  state.styles.popper = Object.assign({}, state.styles.popper, mapToStyles(Object.assign({}, commonStyles, {
@@ -1042,7 +1512,7 @@ function getInnerBoundingClientRect(element) {
1042
1512
  }
1043
1513
 
1044
1514
  function getClientRectFromMixedType(element, clippingParent) {
1045
- return clippingParent === viewport ? rectToClientRect(getViewportRect(element)) : isHTMLElement(clippingParent) ? getInnerBoundingClientRect(clippingParent) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
1515
+ return clippingParent === viewport ? rectToClientRect(getViewportRect(element)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
1046
1516
  }
1047
1517
 
1048
1518
  function getClippingParents(element) {
@@ -1444,6 +1914,14 @@ function preventOverflow(_ref) {
1444
1914
  var tetherOffsetValue = typeof tetherOffset === "function" ? tetherOffset(Object.assign({}, state.rects, {
1445
1915
  placement: state.placement
1446
1916
  })) : tetherOffset;
1917
+ var normalizedTetherOffsetValue = typeof tetherOffsetValue === "number" ? {
1918
+ mainAxis: tetherOffsetValue,
1919
+ altAxis: tetherOffsetValue
1920
+ } : Object.assign({
1921
+ mainAxis: 0,
1922
+ altAxis: 0
1923
+ }, tetherOffsetValue);
1924
+ var offsetModifierState = state.modifiersData.offset ? state.modifiersData.offset[state.placement] : null;
1447
1925
  var data = {
1448
1926
  x: 0,
1449
1927
  y: 0
@@ -1451,13 +1929,14 @@ function preventOverflow(_ref) {
1451
1929
  if (!popperOffsets) {
1452
1930
  return;
1453
1931
  }
1454
- if (checkMainAxis || checkAltAxis) {
1932
+ if (checkMainAxis) {
1933
+ var _offsetModifierState$;
1455
1934
  var mainSide = mainAxis === "y" ? top : left;
1456
1935
  var altSide = mainAxis === "y" ? bottom : right;
1457
1936
  var len = mainAxis === "y" ? "height" : "width";
1458
1937
  var offset = popperOffsets[mainAxis];
1459
- var min$1 = popperOffsets[mainAxis] + overflow[mainSide];
1460
- var max$1 = popperOffsets[mainAxis] - overflow[altSide];
1938
+ var min$1 = offset + overflow[mainSide];
1939
+ var max$1 = offset - overflow[altSide];
1461
1940
  var additive = tether ? -popperRect[len] / 2 : 0;
1462
1941
  var minLen = variation === start ? referenceRect[len] : popperRect[len];
1463
1942
  var maxLen = variation === start ? -popperRect[len] : -referenceRect[len];
@@ -1470,28 +1949,32 @@ function preventOverflow(_ref) {
1470
1949
  var arrowPaddingMin = arrowPaddingObject[mainSide];
1471
1950
  var arrowPaddingMax = arrowPaddingObject[altSide];
1472
1951
  var arrowLen = within(0, referenceRect[len], arrowRect[len]);
1473
- var minOffset = isBasePlacement ? referenceRect[len] / 2 - additive - arrowLen - arrowPaddingMin - tetherOffsetValue : minLen - arrowLen - arrowPaddingMin - tetherOffsetValue;
1474
- var maxOffset = isBasePlacement ? -referenceRect[len] / 2 + additive + arrowLen + arrowPaddingMax + tetherOffsetValue : maxLen + arrowLen + arrowPaddingMax + tetherOffsetValue;
1952
+ var minOffset = isBasePlacement ? referenceRect[len] / 2 - additive - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis : minLen - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis;
1953
+ var maxOffset = isBasePlacement ? -referenceRect[len] / 2 + additive + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis : maxLen + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis;
1475
1954
  var arrowOffsetParent = state.elements.arrow && getOffsetParent(state.elements.arrow);
1476
1955
  var clientOffset = arrowOffsetParent ? mainAxis === "y" ? arrowOffsetParent.clientTop || 0 : arrowOffsetParent.clientLeft || 0 : 0;
1477
- var offsetModifierValue = state.modifiersData.offset ? state.modifiersData.offset[state.placement][mainAxis] : 0;
1478
- var tetherMin = popperOffsets[mainAxis] + minOffset - offsetModifierValue - clientOffset;
1479
- var tetherMax = popperOffsets[mainAxis] + maxOffset - offsetModifierValue;
1480
- if (checkMainAxis) {
1481
- var preventedOffset = within(tether ? min(min$1, tetherMin) : min$1, offset, tether ? max(max$1, tetherMax) : max$1);
1482
- popperOffsets[mainAxis] = preventedOffset;
1483
- data[mainAxis] = preventedOffset - offset;
1484
- }
1485
- if (checkAltAxis) {
1486
- var _mainSide = mainAxis === "x" ? top : left;
1487
- var _altSide = mainAxis === "x" ? bottom : right;
1488
- var _offset = popperOffsets[altAxis];
1489
- var _min = _offset + overflow[_mainSide];
1490
- var _max = _offset - overflow[_altSide];
1491
- var _preventedOffset = within(tether ? min(_min, tetherMin) : _min, _offset, tether ? max(_max, tetherMax) : _max);
1492
- popperOffsets[altAxis] = _preventedOffset;
1493
- data[altAxis] = _preventedOffset - _offset;
1494
- }
1956
+ var offsetModifierValue = (_offsetModifierState$ = offsetModifierState == null ? void 0 : offsetModifierState[mainAxis]) != null ? _offsetModifierState$ : 0;
1957
+ var tetherMin = offset + minOffset - offsetModifierValue - clientOffset;
1958
+ var tetherMax = offset + maxOffset - offsetModifierValue;
1959
+ var preventedOffset = within(tether ? min(min$1, tetherMin) : min$1, offset, tether ? max(max$1, tetherMax) : max$1);
1960
+ popperOffsets[mainAxis] = preventedOffset;
1961
+ data[mainAxis] = preventedOffset - offset;
1962
+ }
1963
+ if (checkAltAxis) {
1964
+ var _offsetModifierState$2;
1965
+ var _mainSide = mainAxis === "x" ? top : left;
1966
+ var _altSide = mainAxis === "x" ? bottom : right;
1967
+ var _offset = popperOffsets[altAxis];
1968
+ var _len = altAxis === "y" ? "height" : "width";
1969
+ var _min = _offset + overflow[_mainSide];
1970
+ var _max = _offset - overflow[_altSide];
1971
+ var isOriginSide = [ top, left ].indexOf(basePlacement) !== -1;
1972
+ var _offsetModifierValue = (_offsetModifierState$2 = offsetModifierState == null ? void 0 : offsetModifierState[altAxis]) != null ? _offsetModifierState$2 : 0;
1973
+ var _tetherMin = isOriginSide ? _min : _offset - referenceRect[_len] - popperRect[_len] - _offsetModifierValue + normalizedTetherOffsetValue.altAxis;
1974
+ var _tetherMax = isOriginSide ? _offset + referenceRect[_len] + popperRect[_len] - _offsetModifierValue - normalizedTetherOffsetValue.altAxis : _max;
1975
+ var _preventedOffset = tether && isOriginSide ? withinMaxClamp(_tetherMin, _offset, _tetherMax) : within(tether ? _tetherMin : _min, _offset, tether ? _tetherMax : _max);
1976
+ popperOffsets[altAxis] = _preventedOffset;
1977
+ data[altAxis] = _preventedOffset - _offset;
1495
1978
  }
1496
1979
  state.modifiersData[name] = data;
1497
1980
  }
@@ -1521,8 +2004,8 @@ function getNodeScroll(node) {
1521
2004
 
1522
2005
  function isElementScaled(element) {
1523
2006
  var rect = element.getBoundingClientRect();
1524
- var scaleX = rect.width / element.offsetWidth || 1;
1525
- var scaleY = rect.height / element.offsetHeight || 1;
2007
+ var scaleX = round(rect.width) / element.offsetWidth || 1;
2008
+ var scaleY = round(rect.height) / element.offsetHeight || 1;
1526
2009
  return scaleX !== 1 || scaleY !== 1;
1527
2010
  }
1528
2011
 
@@ -1531,9 +2014,9 @@ function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
1531
2014
  isFixed = false;
1532
2015
  }
1533
2016
  var isOffsetParentAnElement = isHTMLElement(offsetParent);
1534
- isHTMLElement(offsetParent) && isElementScaled(offsetParent);
2017
+ var offsetParentIsScaled = isHTMLElement(offsetParent) && isElementScaled(offsetParent);
1535
2018
  var documentElement = getDocumentElement(offsetParent);
1536
- var rect = getBoundingClientRect(elementOrVirtualElement);
2019
+ var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled);
1537
2020
  var scroll = {
1538
2021
  scrollLeft: 0,
1539
2022
  scrollTop: 0
@@ -1547,7 +2030,7 @@ function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
1547
2030
  scroll = getNodeScroll(offsetParent);
1548
2031
  }
1549
2032
  if (isHTMLElement(offsetParent)) {
1550
- offsets = getBoundingClientRect(offsetParent);
2033
+ offsets = getBoundingClientRect(offsetParent, true);
1551
2034
  offsets.x += offsetParent.clientLeft;
1552
2035
  offsets.y += offsetParent.clientTop;
1553
2036
  } else if (documentElement) {
@@ -1775,13 +2258,18 @@ class Popover extends Controller {
1775
2258
  active: Boolean
1776
2259
  };
1777
2260
  connect() {
1778
- createPopper(this.activatorTarget, this.popoverTarget, {
2261
+ this.popper = createPopper(this.activatorTarget, this.popoverTarget, {
1779
2262
  placement: this.placementValue,
1780
2263
  modifiers: [ {
1781
2264
  name: "offset",
1782
2265
  options: {
1783
2266
  offset: [ 0, 5 ]
1784
2267
  }
2268
+ }, {
2269
+ name: "flip",
2270
+ options: {
2271
+ allowedAutoPlacements: [ "top-start", "bottom-start", "top-end", "bottom-end" ]
2272
+ }
1785
2273
  } ]
1786
2274
  });
1787
2275
  if (this.activeValue) {
@@ -1792,9 +2280,10 @@ class Popover extends Controller {
1792
2280
  this.popoverTarget.classList.toggle(this.closedClass);
1793
2281
  this.popoverTarget.classList.toggle(this.openClass);
1794
2282
  }
1795
- show() {
2283
+ async show() {
1796
2284
  this.popoverTarget.classList.remove(this.closedClass);
1797
2285
  this.popoverTarget.classList.add(this.openClass);
2286
+ await this.popper.update();
1798
2287
  }
1799
2288
  hide(event) {
1800
2289
  if (!this.element.contains(event.target) && !this.popoverTarget.classList.contains(this.closedClass)) {
@@ -1996,8 +2485,9 @@ class Toast extends Controller {
1996
2485
  this.element.removeEventListener("transitionend", this.updatePositions, false);
1997
2486
  };
1998
2487
  getStyle(position) {
1999
- const translateIn = -80 * position;
2000
- const translateOut = 150 - 80 * position;
2488
+ const height = this.element.offsetHeight + this.heightOffset;
2489
+ const translateIn = height * -1;
2490
+ const translateOut = 150 - height;
2001
2491
  return `--toast-translate-y-in: ${translateIn}px; --toast-translate-y-out: ${translateOut}px;`;
2002
2492
  }
2003
2493
  get timeoutDuration() {
@@ -2018,11 +2508,16 @@ class Toast extends Controller {
2018
2508
  get position() {
2019
2509
  return this.visibleToasts.filter((el => !this.element.isEqualNode(el))).length + 1;
2020
2510
  }
2511
+ get heightOffset() {
2512
+ return this.visibleToasts.filter((el => !this.element.isEqualNode(el) && this.element.dataset.position > el.dataset.position)).map((el => el.offsetHeight)).reduce(((a, b) => a + b), 0);
2513
+ }
2021
2514
  }
2022
2515
 
2023
2516
  function registerPolarisControllers(application) {
2024
2517
  application.register("polaris-autocomplete", Autocomplete);
2025
2518
  application.register("polaris-button", Button);
2519
+ application.register("polaris-collapsible", Collapsible);
2520
+ application.register("polaris-dropzone", Dropzone);
2026
2521
  application.register("polaris-frame", Frame);
2027
2522
  application.register("polaris-modal", Modal);
2028
2523
  application.register("polaris-option-list", OptionList);