polaris_view_components 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/polaris_view_components/autocomplete_controller.js +32 -15
  3. data/app/assets/javascripts/polaris_view_components/dropzone_controller.js +495 -0
  4. data/app/assets/javascripts/polaris_view_components/index.js +2 -0
  5. data/app/assets/javascripts/polaris_view_components/popover_controller.js +9 -2
  6. data/app/assets/javascripts/polaris_view_components/utils.js +23 -0
  7. data/app/assets/javascripts/polaris_view_components.js +533 -63
  8. data/app/assets/stylesheets/polaris_view_components/custom.css +38 -6
  9. data/app/assets/stylesheets/polaris_view_components.css +2102 -2021
  10. data/app/assets/stylesheets/polaris_view_components.postcss.css +1 -1
  11. data/app/components/polaris/action_list/item_component.rb +1 -1
  12. data/app/components/polaris/action_list/section_component.rb +1 -1
  13. data/app/components/polaris/action_list_component.rb +1 -1
  14. data/app/components/polaris/autocomplete/action_component.rb +1 -1
  15. data/app/components/polaris/autocomplete/option_component.rb +1 -1
  16. data/app/components/polaris/autocomplete/section_component.rb +1 -1
  17. data/app/components/polaris/autocomplete_component.rb +9 -2
  18. data/app/components/polaris/avatar_component.rb +1 -1
  19. data/app/components/polaris/badge_component.rb +1 -1
  20. data/app/components/polaris/banner_component.rb +2 -2
  21. data/app/components/polaris/base_button.rb +1 -1
  22. data/app/components/polaris/base_checkbox.rb +1 -1
  23. data/app/components/polaris/base_component.rb +1 -1
  24. data/app/components/polaris/base_radio_button.rb +1 -1
  25. data/app/components/polaris/button_group_component.rb +3 -3
  26. data/app/components/polaris/callout_card_component.rb +1 -1
  27. data/app/components/polaris/caption_component.rb +1 -1
  28. data/app/components/polaris/card/header_component.rb +1 -1
  29. data/app/components/polaris/card/section_component.rb +2 -2
  30. data/app/components/polaris/card_component.rb +1 -1
  31. data/app/components/polaris/checkbox_component.rb +1 -1
  32. data/app/components/polaris/choice_component.rb +1 -1
  33. data/app/components/polaris/choice_list_component.rb +1 -1
  34. data/app/components/polaris/component.rb +6 -1
  35. data/app/components/polaris/data_table/cell_component.rb +1 -1
  36. data/app/components/polaris/data_table/column_component.rb +1 -1
  37. data/app/components/polaris/data_table_component.rb +1 -1
  38. data/app/components/polaris/description_list_component.rb +2 -2
  39. data/app/components/polaris/display_text_component.rb +1 -1
  40. data/app/components/polaris/dropzone_component.html.erb +156 -0
  41. data/app/components/polaris/dropzone_component.rb +150 -0
  42. data/app/components/polaris/empty_state_component.rb +1 -1
  43. data/app/components/polaris/exception_list/item_component.rb +1 -1
  44. data/app/components/polaris/exception_list_component.rb +1 -1
  45. data/app/components/polaris/filters_component.rb +3 -3
  46. data/app/components/polaris/footer_help_component.rb +1 -1
  47. data/app/components/polaris/form_layout/group_component.rb +2 -2
  48. data/app/components/polaris/form_layout/item_component.rb +1 -1
  49. data/app/components/polaris/form_layout_component.rb +1 -1
  50. data/app/components/polaris/frame/save_bar_component.rb +1 -1
  51. data/app/components/polaris/frame/top_bar_component.rb +1 -1
  52. data/app/components/polaris/frame_component.rb +1 -1
  53. data/app/components/polaris/heading_component.rb +1 -1
  54. data/app/components/polaris/headless_button.rb +1 -1
  55. data/app/components/polaris/icon_component.rb +1 -1
  56. data/app/components/polaris/index_table/cell_component.rb +1 -1
  57. data/app/components/polaris/index_table/column_component.rb +1 -1
  58. data/app/components/polaris/index_table_component.rb +1 -1
  59. data/app/components/polaris/inline_error_component.rb +1 -1
  60. data/app/components/polaris/label_component.rb +1 -1
  61. data/app/components/polaris/labelled_component.rb +1 -1
  62. data/app/components/polaris/layout/annotated_section.rb +1 -1
  63. data/app/components/polaris/layout/section.rb +1 -1
  64. data/app/components/polaris/layout_component.rb +1 -1
  65. data/app/components/polaris/link_component.rb +1 -1
  66. data/app/components/polaris/list_component.rb +2 -2
  67. data/app/components/polaris/modal/section_component.rb +1 -1
  68. data/app/components/polaris/modal_component.rb +1 -1
  69. data/app/components/polaris/navigation/item_component.rb +2 -2
  70. data/app/components/polaris/navigation/section_component.rb +2 -2
  71. data/app/components/polaris/navigation_component.rb +1 -1
  72. data/app/components/polaris/option_list/checkbox_component.rb +1 -1
  73. data/app/components/polaris/option_list/option_component.rb +1 -1
  74. data/app/components/polaris/option_list/radio_button_component.rb +1 -1
  75. data/app/components/polaris/option_list/section_component.rb +1 -1
  76. data/app/components/polaris/option_list_component.rb +1 -1
  77. data/app/components/polaris/page_actions_component.rb +1 -1
  78. data/app/components/polaris/page_component.rb +1 -1
  79. data/app/components/polaris/pagination_component.rb +1 -1
  80. data/app/components/polaris/popover/pane_component.rb +1 -1
  81. data/app/components/polaris/popover/section_component.rb +1 -1
  82. data/app/components/polaris/popover_component.rb +10 -4
  83. data/app/components/polaris/progress_bar_component.rb +1 -1
  84. data/app/components/polaris/radio_button_component.rb +1 -1
  85. data/app/components/polaris/resource_item_component.rb +1 -1
  86. data/app/components/polaris/resource_list_component.rb +1 -1
  87. data/app/components/polaris/scrollable_component.rb +1 -1
  88. data/app/components/polaris/select_component.rb +1 -1
  89. data/app/components/polaris/setting_toggle_component.rb +1 -1
  90. data/app/components/polaris/shopify_navigation_component.rb +2 -2
  91. data/app/components/polaris/skeleton_body_text_component.rb +1 -1
  92. data/app/components/polaris/spacer_component.rb +1 -1
  93. data/app/components/polaris/spinner_component.rb +1 -1
  94. data/app/components/polaris/stack/item_component.rb +15 -0
  95. data/app/components/polaris/stack_component.rb +2 -18
  96. data/app/components/polaris/subheading_component.rb +1 -1
  97. data/app/components/polaris/tabs/tab_component.rb +1 -1
  98. data/app/components/polaris/tabs_component.rb +1 -1
  99. data/app/components/polaris/tag_component.rb +3 -2
  100. data/app/components/polaris/text_container_component.rb +1 -1
  101. data/app/components/polaris/text_field_component.rb +2 -2
  102. data/app/components/polaris/text_style_component.rb +1 -1
  103. data/app/components/polaris/thumbnail_component.rb +1 -1
  104. data/app/components/polaris/toast_component.rb +1 -1
  105. data/app/components/polaris/top_bar/user_menu_component.rb +1 -1
  106. data/app/components/polaris/visually_hidden_component.rb +1 -1
  107. data/app/helpers/polaris/form_builder.rb +14 -5
  108. data/app/helpers/polaris/view_helper.rb +2 -1
  109. data/lib/polaris/view_components/engine.rb +5 -1
  110. data/lib/polaris/view_components/version.rb +1 -1
  111. metadata +7 -9
  112. data/app/components/polaris/application_component.rb +0 -35
  113. data/app/components/polaris/dropzone/component.html.erb +0 -72
  114. data/app/components/polaris/dropzone/component.rb +0 -128
  115. data/app/components/polaris/dropzone/controller.js +0 -226
  116. data/app/components/polaris/dropzone/utils.js +0 -57
  117. data/app/components/polaris/new_component.rb +0 -10
  118. 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,388 @@ class Button extends Controller {
136
165
  }
137
166
  }
138
167
 
168
+ const dragEvents = [ "dragover", "dragenter", "drop" ];
169
+
170
+ const SIZES = {
171
+ SMALL: "small",
172
+ MEDIUM: "medium",
173
+ LARGE: "large",
174
+ EXTRA_LARGE: "extraLarge"
175
+ };
176
+
177
+ class Dropzone extends Controller {
178
+ static targets=[ "container", "fileUpload", "loader", "input", "preview", "previewTemplate", "itemTemplate", "overlay", "errorOverlay" ];
179
+ static classes=[ "disabled" ];
180
+ static values={
181
+ accept: String,
182
+ allowMultiple: Boolean,
183
+ disabled: Boolean,
184
+ dropOnPage: Boolean,
185
+ focused: Boolean,
186
+ renderPreview: Boolean,
187
+ size: String
188
+ };
189
+ files=[];
190
+ acceptedFiles=[];
191
+ rejectedFiles=[];
192
+ _dragging=false;
193
+ dragTargets=[];
194
+ previewRendered=false;
195
+ _size="large";
196
+ connect() {
197
+ document.body.addEventListener("click", this.onExternalTriggerClick);
198
+ addEventListener("resize", this.onWindowResize);
199
+ addEventListener("direct-uploads:start", this.onDirectUploadsStart);
200
+ addEventListener("direct-uploads:end", this.onDirectUploadsEnd);
201
+ addEventListener("direct-upload:initialize", this.onDirectUploadInitialize);
202
+ addEventListener("direct-upload:start", this.onDirectUploadStart);
203
+ addEventListener("direct-upload:progress", this.onDirectUploadProgress);
204
+ addEventListener("direct-upload:error", this.onDirectUploadError);
205
+ addEventListener("direct-upload:end", this.onDirectUploadEnd);
206
+ this.onWindowResize();
207
+ }
208
+ disconnect() {
209
+ document.body.removeEventListener("click", this.onExternalTriggerClick);
210
+ removeEventListener("resize", this.onWindowResize);
211
+ removeEventListener("direct-uploads:start", this.onDirectUploadsStart);
212
+ removeEventListener("direct-uploads:end", this.onDirectUploadsEnd);
213
+ removeEventListener("direct-upload:initialize", this.onDirectUploadInitialize);
214
+ removeEventListener("direct-upload:start", this.onDirectUploadStart);
215
+ removeEventListener("direct-upload:progress", this.onDirectUploadProgress);
216
+ removeEventListener("direct-upload:error", this.onDirectUploadError);
217
+ removeEventListener("direct-upload:end", this.onDirectUploadEnd);
218
+ }
219
+ onExternalTriggerClick=event => {
220
+ const trigger = event.target.closest(`[data-${this.identifier}-external-target="trigger"]`);
221
+ if (!trigger) return;
222
+ event.preventDefault();
223
+ this.onClick();
224
+ };
225
+ onWindowResize=debounce$1((() => {
226
+ const size = this.calculateSize();
227
+ if (size !== this.size) {
228
+ this.size = size;
229
+ }
230
+ }), 50);
231
+ onBlur() {
232
+ this.focusedValue = false;
233
+ }
234
+ onChange(e) {
235
+ this.stopEvent(e);
236
+ if (this.disabled) return;
237
+ this.clearFiles();
238
+ const fileList = getDataTransferFiles(e);
239
+ const {files: files, acceptedFiles: acceptedFiles, rejectedFiles: rejectedFiles} = this.getValidatedFiles(fileList);
240
+ this.dragTargets = [];
241
+ this.files = files;
242
+ this.acceptedFiles = acceptedFiles;
243
+ this.rejectedFiles = rejectedFiles;
244
+ this.render();
245
+ }
246
+ onDragOver(e) {
247
+ this.stopEvent(e);
248
+ if (this.disabled) return;
249
+ }
250
+ onDragEnter(e) {
251
+ this.stopEvent(e);
252
+ if (this.disabled) return;
253
+ if (e.target && !this.dragTargets.includes(e.target)) {
254
+ this.dragTargets.push(e.target);
255
+ }
256
+ if (this.dragging) return;
257
+ this.dragging = true;
258
+ }
259
+ onDragLeave(e) {
260
+ this.stopEvent(e);
261
+ if (this.disabled) return;
262
+ this.dragTargets = this.dragTargets.filter((el => {
263
+ const compareNode = this.element;
264
+ return el !== e.target && compareNode && compareNode.contains(el);
265
+ }));
266
+ if (this.dragTargets.length > 0) return;
267
+ this.dragging = false;
268
+ }
269
+ onDrop(e) {
270
+ this.stopEvent(e);
271
+ if (this.disabled) return;
272
+ this.dragging = false;
273
+ this.onChange(e);
274
+ }
275
+ onFocus() {
276
+ this.focusedValue = true;
277
+ }
278
+ onClick() {
279
+ if (this.disabledValue) return;
280
+ this.open();
281
+ }
282
+ onDirectUploadsStart=() => {
283
+ this.disable();
284
+ };
285
+ onDirectUploadsEnd=() => {
286
+ this.enable();
287
+ this.clearFiles();
288
+ this.loaderTarget.classList.remove("Polaris--hidden");
289
+ };
290
+ onDirectUploadInitialize=event => {
291
+ const {target: target, detail: detail} = event;
292
+ const {id: id, file: file} = detail;
293
+ const dropzone = target.closest(".Polaris-DropZone");
294
+ if (!dropzone) return;
295
+ const content = dropzone.querySelector(`[data-file-name="${file.name}"]`);
296
+ const progressBar = content.parentElement.querySelector('[data-target="progress-bar"]');
297
+ progressBar.id = `direct-upload-${id}`;
298
+ };
299
+ onDirectUploadStart=event => {
300
+ const {id: id} = event.detail;
301
+ const progressBar = document.getElementById(`direct-upload-${id}`);
302
+ if (!progressBar) return;
303
+ progressBar.classList.remove("Polaris--hidden");
304
+ };
305
+ onDirectUploadProgress=event => {
306
+ const {id: id, progress: progress} = event.detail;
307
+ const progressBar = document.getElementById(`direct-upload-${id}`);
308
+ if (!progressBar) return;
309
+ const progressElement = progressBar.querySelector(".Polaris-ProgressBar__Indicator");
310
+ progressElement.style.width = `${progress}%`;
311
+ };
312
+ onDirectUploadError=event => {
313
+ const {id: id, error: error} = event.detail;
314
+ const progressBar = document.getElementById(`direct-upload-${id}`);
315
+ if (!progressBar) return;
316
+ event.preventDefault();
317
+ progressBar.classList.add("Polaris--hidden");
318
+ const uploadError = progressBar.parentElement.querySelector('[data-target="upload-error"]');
319
+ const errorIcon = uploadError.querySelector(".Polaris-InlineError__Icon");
320
+ if (errorIcon) errorIcon.remove();
321
+ uploadError.classList.remove("Polaris--hidden");
322
+ };
323
+ onDirectUploadEnd=event => {
324
+ const {id: id} = event.detail;
325
+ const progressBar = document.getElementById(`direct-upload-${id}`);
326
+ if (!progressBar) return;
327
+ progressBar.classList.add("Polaris-ProgressBar--colorSuccess");
328
+ };
329
+ open() {
330
+ this.inputTarget.click();
331
+ }
332
+ focusedValueChanged() {
333
+ this.element.classList.toggle("Polaris-DropZone--focused", this.focusedValue);
334
+ }
335
+ stopEvent(e) {
336
+ e.preventDefault();
337
+ e.stopPropagation();
338
+ }
339
+ getValidatedFiles(files) {
340
+ const acceptedFiles = [];
341
+ const rejectedFiles = [];
342
+ Array.from(files).forEach((file => {
343
+ if (fileAccepted(file, this.acceptValue)) {
344
+ acceptedFiles.push(file);
345
+ } else {
346
+ rejectedFiles.push(file);
347
+ }
348
+ }));
349
+ if (!this.allowMultipleValue) {
350
+ acceptedFiles.splice(1, acceptedFiles.length);
351
+ rejectedFiles.push(...acceptedFiles.slice(1));
352
+ }
353
+ return {
354
+ files: files,
355
+ acceptedFiles: acceptedFiles,
356
+ rejectedFiles: rejectedFiles
357
+ };
358
+ }
359
+ render() {
360
+ if (this.files.length === 0) {
361
+ this.toggleFileUpload(true);
362
+ this.toggleErrorOverlay(false);
363
+ } else if (this.rejectedFiles.length > 0) {
364
+ this.toggleFileUpload(false);
365
+ this.toggleErrorOverlay(true);
366
+ const dropRejectedEvent = new CustomEvent("polaris-dropzone:drop-rejected", {
367
+ detail: {
368
+ rejectedFiles: this.rejectedFiles
369
+ }
370
+ });
371
+ this.element.dispatchEvent(dropRejectedEvent);
372
+ } else if (this.acceptedFiles.length > 0) {
373
+ if (this.renderPreviewValue) {
374
+ this.renderUploadedFiles();
375
+ this.toggleFileUpload(false);
376
+ }
377
+ this.toggleErrorOverlay(false);
378
+ const dropAcceptedEvent = new CustomEvent("polaris-dropzone:drop-accepted", {
379
+ detail: {
380
+ acceptedFiles: this.acceptedFiles
381
+ }
382
+ });
383
+ this.element.dispatchEvent(dropAcceptedEvent);
384
+ }
385
+ const dropEvent = new CustomEvent("polaris-dropzone:drop", {
386
+ detail: {
387
+ files: this.files,
388
+ acceptedFiles: this.acceptedFiles,
389
+ rejectedFiles: this.rejectedFiles
390
+ }
391
+ });
392
+ this.element.dispatchEvent(dropEvent);
393
+ }
394
+ renderUploadedFiles() {
395
+ if (this.acceptedFiles.length === 0) return;
396
+ const clone = this.previewTemplateTarget.content.cloneNode(true);
397
+ const filesTarget = clone.querySelector(".target");
398
+ let files = this.acceptedFiles;
399
+ if (this.sizeValue == "small") files = [ files[0] ];
400
+ files.map((file => this.renderFile(file))).forEach((fragment => filesTarget.parentNode.appendChild(fragment)));
401
+ filesTarget.remove();
402
+ this.containerTarget.prepend(clone);
403
+ this.previewRendered = true;
404
+ }
405
+ toggleFileUpload(show = false) {
406
+ this.fileUploadTarget.classList.toggle("Polaris-VisuallyHidden", !show);
407
+ }
408
+ toggleErrorOverlay(show = false) {
409
+ this.errorOverlayTarget.classList.toggle("Polaris-VisuallyHidden", !show);
410
+ this.element.classList.toggle("Polaris-DropZone--hasError", show);
411
+ }
412
+ renderFile(file) {
413
+ const validImageTypes = [ "image/gif", "image/jpeg", "image/png" ];
414
+ const clone = this.itemTemplateTarget.content.cloneNode(true);
415
+ 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"]') ];
416
+ if (validImageTypes.includes(file.type)) {
417
+ const img = thumbnail.querySelector("img");
418
+ img.alt = file.name;
419
+ img.src = window.URL.createObjectURL(file);
420
+ icon.remove();
421
+ } else {
422
+ thumbnail.remove();
423
+ }
424
+ if (this.sizeValue != "small") {
425
+ content.insertAdjacentText("afterbegin", file.name);
426
+ content.setAttribute("data-file-name", file.name);
427
+ fileSize.textContent = formatBytes(file.size);
428
+ }
429
+ return clone;
430
+ }
431
+ clearFiles() {
432
+ if (!this.previewRendered) return;
433
+ this.acceptedFiles = [];
434
+ this.files = [];
435
+ this.rejectedFiles = [];
436
+ if (!this.hasPreviewTarget) return;
437
+ this.previewTarget.remove();
438
+ this.previewRendered = false;
439
+ }
440
+ calculateSize() {
441
+ const width = this.element.getBoundingClientRect().width;
442
+ let size = SIZES.LARGE;
443
+ if (width < 100) {
444
+ size = SIZES.SMALL;
445
+ } else if (width < 160) {
446
+ size = SIZES.MEDIUM;
447
+ } else if (width > 300) {
448
+ size = SIZES.EXTRA_LARGE;
449
+ }
450
+ this.size = size;
451
+ return size;
452
+ }
453
+ getSizeClass(size = "large") {
454
+ return this.sizeClassesSchema[size] || this.sizeClassesSchema.large;
455
+ }
456
+ disable() {
457
+ this.disabled = true;
458
+ this.element.classList.add(this.disabledClass);
459
+ this.inputTarget.disabled = true;
460
+ }
461
+ enable() {
462
+ this.disabled = false;
463
+ this.element.classList.remove(this.disabledClass);
464
+ this.inputTarget.disabled = false;
465
+ }
466
+ get fileListRendered() {
467
+ return this.element.querySelector("[data-rendered]");
468
+ }
469
+ get dropNode() {
470
+ return this.dropOnPageValue ? document : this.element;
471
+ }
472
+ get disabled() {
473
+ return this.disabledValue;
474
+ }
475
+ set disabled(val) {
476
+ this.disabledValue = val;
477
+ }
478
+ get dragging() {
479
+ return this._dragging;
480
+ }
481
+ set dragging(val) {
482
+ this._dragging = val;
483
+ this.element.classList.toggle("Polaris-DropZone--isDragging", val);
484
+ this.overlayTarget.classList.toggle("Polaris-VisuallyHidden", !val);
485
+ }
486
+ get sizeClassesSchema() {
487
+ return {
488
+ [SIZES.SMALL]: "Polaris-DropZone--sizeSmall",
489
+ [SIZES.MEDIUM]: "Polaris-DropZone--sizeMedium",
490
+ [SIZES.LARGE]: "Polaris-DropZone--sizeLarge",
491
+ [SIZES.EXTRA_LARGE]: "Polaris-DropZone--sizeExtraLarge"
492
+ };
493
+ }
494
+ get size() {
495
+ return this._size;
496
+ }
497
+ set size(val) {
498
+ this._size = val;
499
+ const sizeClassesToRemove = Object.values(this.sizeClassesSchema);
500
+ sizeClassesToRemove.forEach((className => this.element.classList.remove(className)));
501
+ this.element.classList.add(this.getSizeClass(val));
502
+ }
503
+ }
504
+
505
+ function fileAccepted(file, accept) {
506
+ return file.type === "application/x-moz-file" || accepts(file, accept);
507
+ }
508
+
509
+ function getDataTransferFiles(event) {
510
+ if (isDragEvent(event) && event.dataTransfer) {
511
+ const dt = event.dataTransfer;
512
+ if (dt.files && dt.files.length) {
513
+ return Array.from(dt.files);
514
+ } else if (dt.items && dt.items.length) {
515
+ return Array.from(dt.items);
516
+ }
517
+ } else if (isChangeEvent(event) && event.target.files) {
518
+ return Array.from(event.target.files);
519
+ }
520
+ return [];
521
+ }
522
+
523
+ function accepts(file, acceptedFiles = [ "" ]) {
524
+ if (file && acceptedFiles) {
525
+ const fileName = file.name || "";
526
+ const mimeType = file.type || "";
527
+ const baseMimeType = mimeType.replace(/\/.*$/, "");
528
+ const acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(",");
529
+ return acceptedFilesArray.some((type => {
530
+ const validType = type.trim();
531
+ if (validType.startsWith(".")) {
532
+ return fileName.toLowerCase().endsWith(validType.toLowerCase());
533
+ } else if (validType.endsWith("/*")) {
534
+ return baseMimeType === validType.replace(/\/.*$/, "");
535
+ }
536
+ return mimeType === validType;
537
+ }));
538
+ }
539
+ return true;
540
+ }
541
+
542
+ function isDragEvent(event) {
543
+ return dragEvents.indexOf(event.type) > 0;
544
+ }
545
+
546
+ function isChangeEvent(event) {
547
+ return event.type === "change";
548
+ }
549
+
139
550
  const alpineNames = {
140
551
  enterFromClass: "enter",
141
552
  enterActiveClass: "enterStart",
@@ -558,10 +969,29 @@ function getBasePlacement(placement) {
558
969
  return placement.split("-")[0];
559
970
  }
560
971
 
972
+ var max = Math.max;
973
+
974
+ var min = Math.min;
975
+
976
+ var round = Math.round;
977
+
561
978
  function getBoundingClientRect(element, includeScale) {
979
+ if (includeScale === void 0) {
980
+ includeScale = false;
981
+ }
562
982
  var rect = element.getBoundingClientRect();
563
983
  var scaleX = 1;
564
984
  var scaleY = 1;
985
+ if (isHTMLElement(element) && includeScale) {
986
+ var offsetHeight = element.offsetHeight;
987
+ var offsetWidth = element.offsetWidth;
988
+ if (offsetWidth > 0) {
989
+ scaleX = round(rect.width) / offsetWidth || 1;
990
+ }
991
+ if (offsetHeight > 0) {
992
+ scaleY = round(rect.height) / offsetHeight || 1;
993
+ }
994
+ }
565
995
  return {
566
996
  width: rect.width / scaleX,
567
997
  height: rect.height / scaleY,
@@ -671,16 +1101,15 @@ function getMainAxisFromPlacement(placement) {
671
1101
  return [ "top", "bottom" ].indexOf(placement) >= 0 ? "x" : "y";
672
1102
  }
673
1103
 
674
- var max = Math.max;
675
-
676
- var min = Math.min;
677
-
678
- var round = Math.round;
679
-
680
1104
  function within(min$1, value, max$1) {
681
1105
  return max(min$1, min(value, max$1));
682
1106
  }
683
1107
 
1108
+ function withinMaxClamp(min, value, max) {
1109
+ var v = within(min, value, max);
1110
+ return v > max ? max : v;
1111
+ }
1112
+
684
1113
  function getFreshSideObject() {
685
1114
  return {
686
1115
  top: 0,
@@ -782,15 +1211,24 @@ function roundOffsetsByDPR(_ref) {
782
1211
  var win = window;
783
1212
  var dpr = win.devicePixelRatio || 1;
784
1213
  return {
785
- x: round(round(x * dpr) / dpr) || 0,
786
- y: round(round(y * dpr) / dpr) || 0
1214
+ x: round(x * dpr) / dpr || 0,
1215
+ y: round(y * dpr) / dpr || 0
787
1216
  };
788
1217
  }
789
1218
 
790
1219
  function mapToStyles(_ref2) {
791
1220
  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;
1221
+ 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;
1222
+ 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;
1223
+ var _ref3 = typeof roundOffsets === "function" ? roundOffsets({
1224
+ x: x,
1225
+ y: y
1226
+ }) : {
1227
+ x: x,
1228
+ y: y
1229
+ };
1230
+ x = _ref3.x;
1231
+ y = _ref3.y;
794
1232
  var hasX = offsets.hasOwnProperty("x");
795
1233
  var hasY = offsets.hasOwnProperty("y");
796
1234
  var sideX = left;
@@ -810,18 +1248,29 @@ function mapToStyles(_ref2) {
810
1248
  offsetParent = offsetParent;
811
1249
  if (placement === top || (placement === left || placement === right) && variation === end) {
812
1250
  sideY = bottom;
813
- y -= offsetParent[heightProp] - popperRect.height;
1251
+ var offsetY = isFixed && win.visualViewport ? win.visualViewport.height : offsetParent[heightProp];
1252
+ y -= offsetY - popperRect.height;
814
1253
  y *= gpuAcceleration ? 1 : -1;
815
1254
  }
816
1255
  if (placement === left || (placement === top || placement === bottom) && variation === end) {
817
1256
  sideX = right;
818
- x -= offsetParent[widthProp] - popperRect.width;
1257
+ var offsetX = isFixed && win.visualViewport ? win.visualViewport.width : offsetParent[widthProp];
1258
+ x -= offsetX - popperRect.width;
819
1259
  x *= gpuAcceleration ? 1 : -1;
820
1260
  }
821
1261
  }
822
1262
  var commonStyles = Object.assign({
823
1263
  position: position
824
1264
  }, adaptive && unsetSides);
1265
+ var _ref4 = roundOffsets === true ? roundOffsetsByDPR({
1266
+ x: x,
1267
+ y: y
1268
+ }) : {
1269
+ x: x,
1270
+ y: y
1271
+ };
1272
+ x = _ref4.x;
1273
+ y = _ref4.y;
825
1274
  if (gpuAcceleration) {
826
1275
  var _Object$assign;
827
1276
  return Object.assign({}, commonStyles, (_Object$assign = {}, _Object$assign[sideY] = hasY ? "0" : "",
@@ -832,15 +1281,16 @@ function mapToStyles(_ref2) {
832
1281
  _Object$assign2[sideX] = hasX ? x + "px" : "", _Object$assign2.transform = "", _Object$assign2));
833
1282
  }
834
1283
 
835
- function computeStyles(_ref4) {
836
- var state = _ref4.state, options = _ref4.options;
1284
+ function computeStyles(_ref5) {
1285
+ var state = _ref5.state, options = _ref5.options;
837
1286
  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
1287
  var commonStyles = {
839
1288
  placement: getBasePlacement(state.placement),
840
1289
  variation: getVariation(state.placement),
841
1290
  popper: state.elements.popper,
842
1291
  popperRect: state.rects.popper,
843
- gpuAcceleration: gpuAcceleration
1292
+ gpuAcceleration: gpuAcceleration,
1293
+ isFixed: state.options.strategy === "fixed"
844
1294
  };
845
1295
  if (state.modifiersData.popperOffsets != null) {
846
1296
  state.styles.popper = Object.assign({}, state.styles.popper, mapToStyles(Object.assign({}, commonStyles, {
@@ -1042,7 +1492,7 @@ function getInnerBoundingClientRect(element) {
1042
1492
  }
1043
1493
 
1044
1494
  function getClientRectFromMixedType(element, clippingParent) {
1045
- return clippingParent === viewport ? rectToClientRect(getViewportRect(element)) : isHTMLElement(clippingParent) ? getInnerBoundingClientRect(clippingParent) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
1495
+ return clippingParent === viewport ? rectToClientRect(getViewportRect(element)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
1046
1496
  }
1047
1497
 
1048
1498
  function getClippingParents(element) {
@@ -1444,6 +1894,14 @@ function preventOverflow(_ref) {
1444
1894
  var tetherOffsetValue = typeof tetherOffset === "function" ? tetherOffset(Object.assign({}, state.rects, {
1445
1895
  placement: state.placement
1446
1896
  })) : tetherOffset;
1897
+ var normalizedTetherOffsetValue = typeof tetherOffsetValue === "number" ? {
1898
+ mainAxis: tetherOffsetValue,
1899
+ altAxis: tetherOffsetValue
1900
+ } : Object.assign({
1901
+ mainAxis: 0,
1902
+ altAxis: 0
1903
+ }, tetherOffsetValue);
1904
+ var offsetModifierState = state.modifiersData.offset ? state.modifiersData.offset[state.placement] : null;
1447
1905
  var data = {
1448
1906
  x: 0,
1449
1907
  y: 0
@@ -1451,13 +1909,14 @@ function preventOverflow(_ref) {
1451
1909
  if (!popperOffsets) {
1452
1910
  return;
1453
1911
  }
1454
- if (checkMainAxis || checkAltAxis) {
1912
+ if (checkMainAxis) {
1913
+ var _offsetModifierState$;
1455
1914
  var mainSide = mainAxis === "y" ? top : left;
1456
1915
  var altSide = mainAxis === "y" ? bottom : right;
1457
1916
  var len = mainAxis === "y" ? "height" : "width";
1458
1917
  var offset = popperOffsets[mainAxis];
1459
- var min$1 = popperOffsets[mainAxis] + overflow[mainSide];
1460
- var max$1 = popperOffsets[mainAxis] - overflow[altSide];
1918
+ var min$1 = offset + overflow[mainSide];
1919
+ var max$1 = offset - overflow[altSide];
1461
1920
  var additive = tether ? -popperRect[len] / 2 : 0;
1462
1921
  var minLen = variation === start ? referenceRect[len] : popperRect[len];
1463
1922
  var maxLen = variation === start ? -popperRect[len] : -referenceRect[len];
@@ -1470,28 +1929,32 @@ function preventOverflow(_ref) {
1470
1929
  var arrowPaddingMin = arrowPaddingObject[mainSide];
1471
1930
  var arrowPaddingMax = arrowPaddingObject[altSide];
1472
1931
  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;
1932
+ var minOffset = isBasePlacement ? referenceRect[len] / 2 - additive - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis : minLen - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis;
1933
+ var maxOffset = isBasePlacement ? -referenceRect[len] / 2 + additive + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis : maxLen + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis;
1475
1934
  var arrowOffsetParent = state.elements.arrow && getOffsetParent(state.elements.arrow);
1476
1935
  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
- }
1936
+ var offsetModifierValue = (_offsetModifierState$ = offsetModifierState == null ? void 0 : offsetModifierState[mainAxis]) != null ? _offsetModifierState$ : 0;
1937
+ var tetherMin = offset + minOffset - offsetModifierValue - clientOffset;
1938
+ var tetherMax = offset + maxOffset - offsetModifierValue;
1939
+ var preventedOffset = within(tether ? min(min$1, tetherMin) : min$1, offset, tether ? max(max$1, tetherMax) : max$1);
1940
+ popperOffsets[mainAxis] = preventedOffset;
1941
+ data[mainAxis] = preventedOffset - offset;
1942
+ }
1943
+ if (checkAltAxis) {
1944
+ var _offsetModifierState$2;
1945
+ var _mainSide = mainAxis === "x" ? top : left;
1946
+ var _altSide = mainAxis === "x" ? bottom : right;
1947
+ var _offset = popperOffsets[altAxis];
1948
+ var _len = altAxis === "y" ? "height" : "width";
1949
+ var _min = _offset + overflow[_mainSide];
1950
+ var _max = _offset - overflow[_altSide];
1951
+ var isOriginSide = [ top, left ].indexOf(basePlacement) !== -1;
1952
+ var _offsetModifierValue = (_offsetModifierState$2 = offsetModifierState == null ? void 0 : offsetModifierState[altAxis]) != null ? _offsetModifierState$2 : 0;
1953
+ var _tetherMin = isOriginSide ? _min : _offset - referenceRect[_len] - popperRect[_len] - _offsetModifierValue + normalizedTetherOffsetValue.altAxis;
1954
+ var _tetherMax = isOriginSide ? _offset + referenceRect[_len] + popperRect[_len] - _offsetModifierValue - normalizedTetherOffsetValue.altAxis : _max;
1955
+ var _preventedOffset = tether && isOriginSide ? withinMaxClamp(_tetherMin, _offset, _tetherMax) : within(tether ? _tetherMin : _min, _offset, tether ? _tetherMax : _max);
1956
+ popperOffsets[altAxis] = _preventedOffset;
1957
+ data[altAxis] = _preventedOffset - _offset;
1495
1958
  }
1496
1959
  state.modifiersData[name] = data;
1497
1960
  }
@@ -1521,8 +1984,8 @@ function getNodeScroll(node) {
1521
1984
 
1522
1985
  function isElementScaled(element) {
1523
1986
  var rect = element.getBoundingClientRect();
1524
- var scaleX = rect.width / element.offsetWidth || 1;
1525
- var scaleY = rect.height / element.offsetHeight || 1;
1987
+ var scaleX = round(rect.width) / element.offsetWidth || 1;
1988
+ var scaleY = round(rect.height) / element.offsetHeight || 1;
1526
1989
  return scaleX !== 1 || scaleY !== 1;
1527
1990
  }
1528
1991
 
@@ -1531,9 +1994,9 @@ function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
1531
1994
  isFixed = false;
1532
1995
  }
1533
1996
  var isOffsetParentAnElement = isHTMLElement(offsetParent);
1534
- isHTMLElement(offsetParent) && isElementScaled(offsetParent);
1997
+ var offsetParentIsScaled = isHTMLElement(offsetParent) && isElementScaled(offsetParent);
1535
1998
  var documentElement = getDocumentElement(offsetParent);
1536
- var rect = getBoundingClientRect(elementOrVirtualElement);
1999
+ var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled);
1537
2000
  var scroll = {
1538
2001
  scrollLeft: 0,
1539
2002
  scrollTop: 0
@@ -1547,7 +2010,7 @@ function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
1547
2010
  scroll = getNodeScroll(offsetParent);
1548
2011
  }
1549
2012
  if (isHTMLElement(offsetParent)) {
1550
- offsets = getBoundingClientRect(offsetParent);
2013
+ offsets = getBoundingClientRect(offsetParent, true);
1551
2014
  offsets.x += offsetParent.clientLeft;
1552
2015
  offsets.y += offsetParent.clientTop;
1553
2016
  } else if (documentElement) {
@@ -1775,13 +2238,18 @@ class Popover extends Controller {
1775
2238
  active: Boolean
1776
2239
  };
1777
2240
  connect() {
1778
- createPopper(this.activatorTarget, this.popoverTarget, {
2241
+ this.popper = createPopper(this.activatorTarget, this.popoverTarget, {
1779
2242
  placement: this.placementValue,
1780
2243
  modifiers: [ {
1781
2244
  name: "offset",
1782
2245
  options: {
1783
2246
  offset: [ 0, 5 ]
1784
2247
  }
2248
+ }, {
2249
+ name: "flip",
2250
+ options: {
2251
+ allowedAutoPlacements: [ "top-start", "bottom-start", "top-end", "bottom-end" ]
2252
+ }
1785
2253
  } ]
1786
2254
  });
1787
2255
  if (this.activeValue) {
@@ -1792,9 +2260,10 @@ class Popover extends Controller {
1792
2260
  this.popoverTarget.classList.toggle(this.closedClass);
1793
2261
  this.popoverTarget.classList.toggle(this.openClass);
1794
2262
  }
1795
- show() {
2263
+ async show() {
1796
2264
  this.popoverTarget.classList.remove(this.closedClass);
1797
2265
  this.popoverTarget.classList.add(this.openClass);
2266
+ await this.popper.update();
1798
2267
  }
1799
2268
  hide(event) {
1800
2269
  if (!this.element.contains(event.target) && !this.popoverTarget.classList.contains(this.closedClass)) {
@@ -2023,6 +2492,7 @@ class Toast extends Controller {
2023
2492
  function registerPolarisControllers(application) {
2024
2493
  application.register("polaris-autocomplete", Autocomplete);
2025
2494
  application.register("polaris-button", Button);
2495
+ application.register("polaris-dropzone", Dropzone);
2026
2496
  application.register("polaris-frame", Frame);
2027
2497
  application.register("polaris-modal", Modal);
2028
2498
  application.register("polaris-option-list", OptionList);