polaris_view_components 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c25ff3636898168d8b63d341155e80003d847ee4e3888150382c59275d9df5d0
4
- data.tar.gz: b865d3b96a3e46b09a76d16699935314403a5efe407ef5f1dd759457f057c4f0
3
+ metadata.gz: 910750f06bdf1ff3095625a911c884155cca167b4dba43fd9e7aa9d61cc0ba72
4
+ data.tar.gz: a0bc6e2afc097fc27148cc8fcb91282380fe6ec878dfcf8828703aed6edec433
5
5
  SHA512:
6
- metadata.gz: 459107009e35c2eef5ccfca95eb3708b90e9ea5f45eecb23e9e68b17566a16ba95341e646339515129e20ee5b18bfcb3cf3a3195afc18b5a6ce79946398226de
7
- data.tar.gz: 3992aad996e4a9f2c38f2d915bd11af2106e6ee54cb5421a9a463f18820c0877eadf9e4b7823a02cf1c6e2995ef09f1019730a3986b4136eb50615e67a1c0b41
6
+ metadata.gz: 1d22ebdc5b83c1b52157c8e9b1f59cc2477546b521955329fff0b012a4c0472db8adad6b3bef881d108ad2e9388d2b23f44adb0d9e67fb0bb793015e4d23500b
7
+ data.tar.gz: 4891914fde6deb943f74567a89334bee1a8ada3736d3547acbf47d834446974e42c83ddb9d0b7ae6cf6c3d5017ce70d9cbf74c8b4706097695a5b7bda0b0f3ea
@@ -164,6 +164,9 @@ export default class extends Controller {
164
164
  onDirectUploadsEnd = () => {
165
165
  this.enable()
166
166
  this.clearFiles()
167
+
168
+ if (this.acceptedFiles.length === 0) return
169
+
167
170
  this.loaderTarget.classList.remove("Polaris--hidden")
168
171
  }
169
172
 
@@ -172,10 +175,16 @@ export default class extends Controller {
172
175
  const { id, file } = detail
173
176
  const dropzone = target.closest('.Polaris-DropZone')
174
177
  if (!dropzone) return
178
+ if (this.acceptedFiles.length === 0) return
175
179
 
176
- const content = dropzone.querySelector(`[data-file-name="${file.name}"]`)
177
- const progressBar = content.parentElement.querySelector('[data-target="progress-bar"]')
178
- progressBar.id = `direct-upload-${id}`
180
+ if (this.sizeValue == 'small') {
181
+ this.clearFiles()
182
+ this.loaderTarget.classList.remove("Polaris--hidden")
183
+ } else {
184
+ const content = dropzone.querySelector(`[data-file-name="${file.name}"]`)
185
+ const progressBar = content.parentElement.querySelector('[data-target="progress-bar"]')
186
+ progressBar.id = `direct-upload-${id}`
187
+ }
179
188
  }
180
189
 
181
190
  onDirectUploadStart = (event) => {
@@ -258,6 +267,7 @@ export default class extends Controller {
258
267
  this.toggleErrorOverlay(true)
259
268
 
260
269
  const dropRejectedEvent = new CustomEvent('polaris-dropzone:drop-rejected', {
270
+ bubbles: true,
261
271
  detail: { rejectedFiles: this.rejectedFiles }
262
272
  })
263
273
  this.element.dispatchEvent(dropRejectedEvent)
@@ -270,12 +280,14 @@ export default class extends Controller {
270
280
  this.toggleErrorOverlay(false)
271
281
 
272
282
  const dropAcceptedEvent = new CustomEvent('polaris-dropzone:drop-accepted', {
283
+ bubbles: true,
273
284
  detail: {acceptedFiles: this.acceptedFiles }
274
285
  })
275
286
  this.element.dispatchEvent(dropAcceptedEvent)
276
287
  }
277
288
 
278
289
  const dropEvent = new CustomEvent('polaris-dropzone:drop', {
290
+ bubbles: true,
279
291
  detail: {
280
292
  files: this.files,
281
293
  acceptedFiles: this.acceptedFiles,
@@ -1,5 +1,5 @@
1
1
  import { Controller } from "@hotwired/stimulus"
2
- import { useTransition } from "stimulus-use"
2
+ import { useTransition } from "./utils"
3
3
 
4
4
  export default class extends Controller {
5
5
  static targets = ["navigationOverlay", "navigation", "saveBar"]
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * @return {Function}
6
6
  */
7
- export function debounce (fn, wait) {
7
+ export function debounce (fn, wait) {
8
8
  let timeoutId
9
9
 
10
10
  return (...args) => {
@@ -21,3 +21,5 @@ export function formatBytes (bytes, decimals) {
21
21
  i = Math.floor(Math.log(bytes) / Math.log(k))
22
22
  return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
23
23
  }
24
+
25
+ export { useTransition } from "./use-transition"
@@ -0,0 +1,162 @@
1
+ const alpineNames = {
2
+ enterFromClass: 'enter',
3
+ enterActiveClass: 'enterStart',
4
+ enterToClass: 'enterEnd',
5
+ leaveFromClass: 'leave',
6
+ leaveActiveClass: 'leaveStart',
7
+ leaveToClass: 'leaveEnd'
8
+ }
9
+ const defaultOptions = {
10
+ transitioned: false,
11
+ hiddenClass: 'hidden',
12
+ preserveOriginalClass: true,
13
+ removeToClasses: true
14
+ };
15
+ export const useTransition = (controller, options = {}) => {
16
+ var _a, _b, _c;
17
+ const targetName = controller.element.dataset.transitionTarget;
18
+ let targetFromAttribute;
19
+ if (targetName) {
20
+ targetFromAttribute = controller[`${targetName}Target`];
21
+ }
22
+ const targetElement = (options === null || options === void 0 ? void 0 : options.element) || targetFromAttribute || controller.element;
23
+ // data attributes are only available on HTMLElement and SVGElement
24
+ if (!(targetElement instanceof HTMLElement || targetElement instanceof SVGElement))
25
+ return;
26
+ const dataset = targetElement.dataset;
27
+ const leaveAfter = parseInt(dataset.leaveAfter || '') || options.leaveAfter || 0;
28
+ const { transitioned, hiddenClass, preserveOriginalClass, removeToClasses } = Object.assign(defaultOptions, options);
29
+ const controllerEnter = (_a = controller.enter) === null || _a === void 0 ? void 0 : _a.bind(controller);
30
+ const controllerLeave = (_b = controller.leave) === null || _b === void 0 ? void 0 : _b.bind(controller);
31
+ const controllerToggleTransition = (_c = controller.toggleTransition) === null || _c === void 0 ? void 0 : _c.bind(controller);
32
+ async function enter(event) {
33
+ if (controller.transitioned)
34
+ return;
35
+ controller.transitioned = true;
36
+ controllerEnter && controllerEnter(event);
37
+ const enterFromClasses = getAttribute('enterFrom', options, dataset);
38
+ const enterActiveClasses = getAttribute('enterActive', options, dataset);
39
+ const enterToClasses = getAttribute('enterTo', options, dataset);
40
+ const leaveToClasses = getAttribute('leaveTo', options, dataset);
41
+ if (!!hiddenClass) {
42
+ targetElement.classList.remove(hiddenClass);
43
+ }
44
+ if (!removeToClasses) {
45
+ removeClasses(targetElement, leaveToClasses);
46
+ }
47
+ await transition(targetElement, enterFromClasses, enterActiveClasses, enterToClasses, hiddenClass, preserveOriginalClass, removeToClasses);
48
+ if (leaveAfter > 0) {
49
+ setTimeout(() => {
50
+ leave(event);
51
+ }, leaveAfter);
52
+ }
53
+ }
54
+ async function leave(event) {
55
+ if (!controller.transitioned)
56
+ return;
57
+ controller.transitioned = false;
58
+ controllerLeave && controllerLeave(event);
59
+ const leaveFromClasses = getAttribute('leaveFrom', options, dataset);
60
+ const leaveActiveClasses = getAttribute('leaveActive', options, dataset);
61
+ const leaveToClasses = getAttribute('leaveTo', options, dataset);
62
+ const enterToClasses = getAttribute('enterTo', options, dataset);
63
+ if (!removeToClasses) {
64
+ removeClasses(targetElement, enterToClasses);
65
+ }
66
+ await transition(targetElement, leaveFromClasses, leaveActiveClasses, leaveToClasses, hiddenClass, preserveOriginalClass, removeToClasses);
67
+ if (!!hiddenClass) {
68
+ targetElement.classList.add(hiddenClass);
69
+ }
70
+ }
71
+ function toggleTransition(event) {
72
+ controllerToggleTransition && controllerToggleTransition(event);
73
+ if (controller.transitioned) {
74
+ leave();
75
+ }
76
+ else {
77
+ enter();
78
+ }
79
+ }
80
+ async function transition(element, initialClasses, activeClasses, endClasses, hiddenClass, preserveOriginalClass, removeEndClasses) {
81
+ // if there's any overlap between the current set of classes and initialClasses/activeClasses/endClasses,
82
+ // we should remove them before we start and add them back at the end
83
+ const stashedClasses = [];
84
+ if (preserveOriginalClass) {
85
+ initialClasses.forEach(cls => element.classList.contains(cls) && cls !== hiddenClass && stashedClasses.push(cls));
86
+ activeClasses.forEach(cls => element.classList.contains(cls) && cls !== hiddenClass && stashedClasses.push(cls));
87
+ endClasses.forEach(cls => element.classList.contains(cls) && cls !== hiddenClass && stashedClasses.push(cls));
88
+ }
89
+ // Add initial class before element start transition
90
+ addClasses(element, initialClasses);
91
+ // remove the overlapping classes
92
+ removeClasses(element, stashedClasses);
93
+ // Add active class before element start transition and maitain it during the entire transition.
94
+ addClasses(element, activeClasses);
95
+ await nextAnimationFrame();
96
+ // remove the initial class on frame after the beginning of the transition
97
+ removeClasses(element, initialClasses);
98
+ // add the endClass on frame after the beginning of the transition
99
+ addClasses(element, endClasses);
100
+ // dynamically comput the duration of the transition from the style of the element
101
+ await afterTransition(element);
102
+ // remove both activeClasses and endClasses
103
+ removeClasses(element, activeClasses);
104
+ if (removeEndClasses) {
105
+ removeClasses(element, endClasses);
106
+ }
107
+ // restore the overlaping classes
108
+ addClasses(element, stashedClasses);
109
+ }
110
+ function initialState() {
111
+ controller.transitioned = transitioned;
112
+ if (transitioned) {
113
+ if (!!hiddenClass) {
114
+ targetElement.classList.remove(hiddenClass);
115
+ }
116
+ enter();
117
+ }
118
+ else {
119
+ if (!!hiddenClass) {
120
+ targetElement.classList.add(hiddenClass);
121
+ }
122
+ leave();
123
+ }
124
+ }
125
+ function addClasses(element, classes) {
126
+ if (classes.length > 0) {
127
+ element.classList.add(...classes);
128
+ }
129
+ }
130
+ function removeClasses(element, classes) {
131
+ if (classes.length > 0) {
132
+ element.classList.remove(...classes);
133
+ }
134
+ }
135
+ initialState();
136
+ Object.assign(controller, { enter, leave, toggleTransition });
137
+ return [enter, leave, toggleTransition];
138
+ };
139
+ function getAttribute(name, options, dataset) {
140
+ const datasetName = `transition${name[0].toUpperCase()}${name.substr(1)}`;
141
+ const datasetAlpineName = alpineNames[name];
142
+ const classes = options[name] || dataset[datasetName] || dataset[datasetAlpineName] || ' ';
143
+ return isEmpty(classes) ? [] : classes.split(' ');
144
+ }
145
+ async function afterTransition(element) {
146
+ return new Promise(resolve => {
147
+ const duration = Number(getComputedStyle(element).transitionDuration.split(',')[0].replace('s', '')) * 1000;
148
+ setTimeout(() => {
149
+ resolve(duration);
150
+ }, duration);
151
+ });
152
+ }
153
+ async function nextAnimationFrame() {
154
+ return new Promise(resolve => {
155
+ requestAnimationFrame(() => {
156
+ requestAnimationFrame(resolve);
157
+ });
158
+ });
159
+ }
160
+ function isEmpty(str) {
161
+ return str.length === 0 || !str.trim();
162
+ }
@@ -2,6 +2,163 @@ import { Controller } from "@hotwired/stimulus";
2
2
 
3
3
  import { get } from "@rails/request.js";
4
4
 
5
+ const alpineNames = {
6
+ enterFromClass: "enter",
7
+ enterActiveClass: "enterStart",
8
+ enterToClass: "enterEnd",
9
+ leaveFromClass: "leave",
10
+ leaveActiveClass: "leaveStart",
11
+ leaveToClass: "leaveEnd"
12
+ };
13
+
14
+ const defaultOptions = {
15
+ transitioned: false,
16
+ hiddenClass: "hidden",
17
+ preserveOriginalClass: true,
18
+ removeToClasses: true
19
+ };
20
+
21
+ const useTransition = (controller, options = {}) => {
22
+ var _a, _b, _c;
23
+ const targetName = controller.element.dataset.transitionTarget;
24
+ let targetFromAttribute;
25
+ if (targetName) {
26
+ targetFromAttribute = controller[`${targetName}Target`];
27
+ }
28
+ const targetElement = (options === null || options === void 0 ? void 0 : options.element) || targetFromAttribute || controller.element;
29
+ if (!(targetElement instanceof HTMLElement || targetElement instanceof SVGElement)) return;
30
+ const dataset = targetElement.dataset;
31
+ const leaveAfter = parseInt(dataset.leaveAfter || "") || options.leaveAfter || 0;
32
+ const {transitioned: transitioned, hiddenClass: hiddenClass, preserveOriginalClass: preserveOriginalClass, removeToClasses: removeToClasses} = Object.assign(defaultOptions, options);
33
+ const controllerEnter = (_a = controller.enter) === null || _a === void 0 ? void 0 : _a.bind(controller);
34
+ const controllerLeave = (_b = controller.leave) === null || _b === void 0 ? void 0 : _b.bind(controller);
35
+ const controllerToggleTransition = (_c = controller.toggleTransition) === null || _c === void 0 ? void 0 : _c.bind(controller);
36
+ async function enter(event) {
37
+ if (controller.transitioned) return;
38
+ controller.transitioned = true;
39
+ controllerEnter && controllerEnter(event);
40
+ const enterFromClasses = getAttribute("enterFrom", options, dataset);
41
+ const enterActiveClasses = getAttribute("enterActive", options, dataset);
42
+ const enterToClasses = getAttribute("enterTo", options, dataset);
43
+ const leaveToClasses = getAttribute("leaveTo", options, dataset);
44
+ if (!!hiddenClass) {
45
+ targetElement.classList.remove(hiddenClass);
46
+ }
47
+ if (!removeToClasses) {
48
+ removeClasses(targetElement, leaveToClasses);
49
+ }
50
+ await transition(targetElement, enterFromClasses, enterActiveClasses, enterToClasses, hiddenClass, preserveOriginalClass, removeToClasses);
51
+ if (leaveAfter > 0) {
52
+ setTimeout((() => {
53
+ leave(event);
54
+ }), leaveAfter);
55
+ }
56
+ }
57
+ async function leave(event) {
58
+ if (!controller.transitioned) return;
59
+ controller.transitioned = false;
60
+ controllerLeave && controllerLeave(event);
61
+ const leaveFromClasses = getAttribute("leaveFrom", options, dataset);
62
+ const leaveActiveClasses = getAttribute("leaveActive", options, dataset);
63
+ const leaveToClasses = getAttribute("leaveTo", options, dataset);
64
+ const enterToClasses = getAttribute("enterTo", options, dataset);
65
+ if (!removeToClasses) {
66
+ removeClasses(targetElement, enterToClasses);
67
+ }
68
+ await transition(targetElement, leaveFromClasses, leaveActiveClasses, leaveToClasses, hiddenClass, preserveOriginalClass, removeToClasses);
69
+ if (!!hiddenClass) {
70
+ targetElement.classList.add(hiddenClass);
71
+ }
72
+ }
73
+ function toggleTransition(event) {
74
+ controllerToggleTransition && controllerToggleTransition(event);
75
+ if (controller.transitioned) {
76
+ leave();
77
+ } else {
78
+ enter();
79
+ }
80
+ }
81
+ async function transition(element, initialClasses, activeClasses, endClasses, hiddenClass, preserveOriginalClass, removeEndClasses) {
82
+ const stashedClasses = [];
83
+ if (preserveOriginalClass) {
84
+ initialClasses.forEach((cls => element.classList.contains(cls) && cls !== hiddenClass && stashedClasses.push(cls)));
85
+ activeClasses.forEach((cls => element.classList.contains(cls) && cls !== hiddenClass && stashedClasses.push(cls)));
86
+ endClasses.forEach((cls => element.classList.contains(cls) && cls !== hiddenClass && stashedClasses.push(cls)));
87
+ }
88
+ addClasses(element, initialClasses);
89
+ removeClasses(element, stashedClasses);
90
+ addClasses(element, activeClasses);
91
+ await nextAnimationFrame();
92
+ removeClasses(element, initialClasses);
93
+ addClasses(element, endClasses);
94
+ await afterTransition(element);
95
+ removeClasses(element, activeClasses);
96
+ if (removeEndClasses) {
97
+ removeClasses(element, endClasses);
98
+ }
99
+ addClasses(element, stashedClasses);
100
+ }
101
+ function initialState() {
102
+ controller.transitioned = transitioned;
103
+ if (transitioned) {
104
+ if (!!hiddenClass) {
105
+ targetElement.classList.remove(hiddenClass);
106
+ }
107
+ enter();
108
+ } else {
109
+ if (!!hiddenClass) {
110
+ targetElement.classList.add(hiddenClass);
111
+ }
112
+ leave();
113
+ }
114
+ }
115
+ function addClasses(element, classes) {
116
+ if (classes.length > 0) {
117
+ element.classList.add(...classes);
118
+ }
119
+ }
120
+ function removeClasses(element, classes) {
121
+ if (classes.length > 0) {
122
+ element.classList.remove(...classes);
123
+ }
124
+ }
125
+ initialState();
126
+ Object.assign(controller, {
127
+ enter: enter,
128
+ leave: leave,
129
+ toggleTransition: toggleTransition
130
+ });
131
+ return [ enter, leave, toggleTransition ];
132
+ };
133
+
134
+ function getAttribute(name, options, dataset) {
135
+ const datasetName = `transition${name[0].toUpperCase()}${name.substr(1)}`;
136
+ const datasetAlpineName = alpineNames[name];
137
+ const classes = options[name] || dataset[datasetName] || dataset[datasetAlpineName] || " ";
138
+ return isEmpty(classes) ? [] : classes.split(" ");
139
+ }
140
+
141
+ async function afterTransition(element) {
142
+ return new Promise((resolve => {
143
+ const duration = Number(getComputedStyle(element).transitionDuration.split(",")[0].replace("s", "")) * 1e3;
144
+ setTimeout((() => {
145
+ resolve(duration);
146
+ }), duration);
147
+ }));
148
+ }
149
+
150
+ async function nextAnimationFrame() {
151
+ return new Promise((resolve => {
152
+ requestAnimationFrame((() => {
153
+ requestAnimationFrame(resolve);
154
+ }));
155
+ }));
156
+ }
157
+
158
+ function isEmpty(str) {
159
+ return str.length === 0 || !str.trim();
160
+ }
161
+
5
162
  function debounce$1(fn, wait) {
6
163
  let timeoutId;
7
164
  return (...args) => {
@@ -302,6 +459,7 @@ class Dropzone extends Controller {
302
459
  onDirectUploadsEnd=() => {
303
460
  this.enable();
304
461
  this.clearFiles();
462
+ if (this.acceptedFiles.length === 0) return;
305
463
  this.loaderTarget.classList.remove("Polaris--hidden");
306
464
  };
307
465
  onDirectUploadInitialize=event => {
@@ -309,9 +467,15 @@ class Dropzone extends Controller {
309
467
  const {id: id, file: file} = detail;
310
468
  const dropzone = target.closest(".Polaris-DropZone");
311
469
  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}`;
470
+ if (this.acceptedFiles.length === 0) return;
471
+ if (this.sizeValue == "small") {
472
+ this.clearFiles();
473
+ this.loaderTarget.classList.remove("Polaris--hidden");
474
+ } else {
475
+ const content = dropzone.querySelector(`[data-file-name="${file.name}"]`);
476
+ const progressBar = content.parentElement.querySelector('[data-target="progress-bar"]');
477
+ progressBar.id = `direct-upload-${id}`;
478
+ }
315
479
  };
316
480
  onDirectUploadStart=event => {
317
481
  const {id: id} = event.detail;
@@ -564,163 +728,6 @@ function isChangeEvent(event) {
564
728
  return event.type === "change";
565
729
  }
566
730
 
567
- const alpineNames = {
568
- enterFromClass: "enter",
569
- enterActiveClass: "enterStart",
570
- enterToClass: "enterEnd",
571
- leaveFromClass: "leave",
572
- leaveActiveClass: "leaveStart",
573
- leaveToClass: "leaveEnd"
574
- };
575
-
576
- const defaultOptions = {
577
- transitioned: false,
578
- hiddenClass: "hidden",
579
- preserveOriginalClass: true,
580
- removeToClasses: true
581
- };
582
-
583
- const useTransition = (controller, options = {}) => {
584
- var _a, _b, _c;
585
- const targetName = controller.element.dataset.transitionTarget;
586
- let targetFromAttribute;
587
- if (targetName) {
588
- targetFromAttribute = controller[`${targetName}Target`];
589
- }
590
- const targetElement = (options === null || options === void 0 ? void 0 : options.element) || targetFromAttribute || controller.element;
591
- if (!(targetElement instanceof HTMLElement || targetElement instanceof SVGElement)) return;
592
- const dataset = targetElement.dataset;
593
- const leaveAfter = parseInt(dataset.leaveAfter || "") || options.leaveAfter || 0;
594
- const {transitioned: transitioned, hiddenClass: hiddenClass, preserveOriginalClass: preserveOriginalClass, removeToClasses: removeToClasses} = Object.assign(defaultOptions, options);
595
- const controllerEnter = (_a = controller.enter) === null || _a === void 0 ? void 0 : _a.bind(controller);
596
- const controllerLeave = (_b = controller.leave) === null || _b === void 0 ? void 0 : _b.bind(controller);
597
- const controllerToggleTransition = (_c = controller.toggleTransition) === null || _c === void 0 ? void 0 : _c.bind(controller);
598
- async function enter(event) {
599
- if (controller.transitioned) return;
600
- controller.transitioned = true;
601
- controllerEnter && controllerEnter(event);
602
- const enterFromClasses = getAttribute("enterFrom", options, dataset);
603
- const enterActiveClasses = getAttribute("enterActive", options, dataset);
604
- const enterToClasses = getAttribute("enterTo", options, dataset);
605
- const leaveToClasses = getAttribute("leaveTo", options, dataset);
606
- if (!!hiddenClass) {
607
- targetElement.classList.remove(hiddenClass);
608
- }
609
- if (!removeToClasses) {
610
- removeClasses(targetElement, leaveToClasses);
611
- }
612
- await transition(targetElement, enterFromClasses, enterActiveClasses, enterToClasses, hiddenClass, preserveOriginalClass, removeToClasses);
613
- if (leaveAfter > 0) {
614
- setTimeout((() => {
615
- leave(event);
616
- }), leaveAfter);
617
- }
618
- }
619
- async function leave(event) {
620
- if (!controller.transitioned) return;
621
- controller.transitioned = false;
622
- controllerLeave && controllerLeave(event);
623
- const leaveFromClasses = getAttribute("leaveFrom", options, dataset);
624
- const leaveActiveClasses = getAttribute("leaveActive", options, dataset);
625
- const leaveToClasses = getAttribute("leaveTo", options, dataset);
626
- const enterToClasses = getAttribute("enterTo", options, dataset);
627
- if (!removeToClasses) {
628
- removeClasses(targetElement, enterToClasses);
629
- }
630
- await transition(targetElement, leaveFromClasses, leaveActiveClasses, leaveToClasses, hiddenClass, preserveOriginalClass, removeToClasses);
631
- if (!!hiddenClass) {
632
- targetElement.classList.add(hiddenClass);
633
- }
634
- }
635
- function toggleTransition(event) {
636
- controllerToggleTransition && controllerToggleTransition(event);
637
- if (controller.transitioned) {
638
- leave();
639
- } else {
640
- enter();
641
- }
642
- }
643
- async function transition(element, initialClasses, activeClasses, endClasses, hiddenClass, preserveOriginalClass, removeEndClasses) {
644
- const stashedClasses = [];
645
- if (preserveOriginalClass) {
646
- initialClasses.forEach((cls => element.classList.contains(cls) && cls !== hiddenClass && stashedClasses.push(cls)));
647
- activeClasses.forEach((cls => element.classList.contains(cls) && cls !== hiddenClass && stashedClasses.push(cls)));
648
- endClasses.forEach((cls => element.classList.contains(cls) && cls !== hiddenClass && stashedClasses.push(cls)));
649
- }
650
- addClasses(element, initialClasses);
651
- removeClasses(element, stashedClasses);
652
- addClasses(element, activeClasses);
653
- await nextAnimationFrame();
654
- removeClasses(element, initialClasses);
655
- addClasses(element, endClasses);
656
- await afterTransition(element);
657
- removeClasses(element, activeClasses);
658
- if (removeEndClasses) {
659
- removeClasses(element, endClasses);
660
- }
661
- addClasses(element, stashedClasses);
662
- }
663
- function initialState() {
664
- controller.transitioned = transitioned;
665
- if (transitioned) {
666
- if (!!hiddenClass) {
667
- targetElement.classList.remove(hiddenClass);
668
- }
669
- enter();
670
- } else {
671
- if (!!hiddenClass) {
672
- targetElement.classList.add(hiddenClass);
673
- }
674
- leave();
675
- }
676
- }
677
- function addClasses(element, classes) {
678
- if (classes.length > 0) {
679
- element.classList.add(...classes);
680
- }
681
- }
682
- function removeClasses(element, classes) {
683
- if (classes.length > 0) {
684
- element.classList.remove(...classes);
685
- }
686
- }
687
- initialState();
688
- Object.assign(controller, {
689
- enter: enter,
690
- leave: leave,
691
- toggleTransition: toggleTransition
692
- });
693
- return [ enter, leave, toggleTransition ];
694
- };
695
-
696
- function getAttribute(name, options, dataset) {
697
- const datasetName = `transition${name[0].toUpperCase()}${name.substr(1)}`;
698
- const datasetAlpineName = alpineNames[name];
699
- const classes = options[name] || dataset[datasetName] || dataset[datasetAlpineName] || " ";
700
- return isEmpty(classes) ? [] : classes.split(" ");
701
- }
702
-
703
- async function afterTransition(element) {
704
- return new Promise((resolve => {
705
- const duration = Number(getComputedStyle(element).transitionDuration.split(",")[0].replace("s", "")) * 1e3;
706
- setTimeout((() => {
707
- resolve(duration);
708
- }), duration);
709
- }));
710
- }
711
-
712
- async function nextAnimationFrame() {
713
- return new Promise((resolve => {
714
- requestAnimationFrame((() => {
715
- requestAnimationFrame(resolve);
716
- }));
717
- }));
718
- }
719
-
720
- function isEmpty(str) {
721
- return str.length === 0 || !str.trim();
722
- }
723
-
724
731
  class Frame extends Controller {
725
732
  static targets=[ "navigationOverlay", "navigation", "saveBar" ];
726
733
  connect() {
@@ -137,5 +137,9 @@ a.Polaris-Tag__Button {
137
137
  align-items: center;
138
138
  text-align: center;
139
139
  justify-content: center;
140
+
141
+ .Polaris-Spinner--sizeSmall {
142
+ height: 20px;
143
+ }
140
144
  }
141
145
  }
@@ -2343,3 +2343,6 @@ a.Polaris-Tag__Button {
2343
2343
  text-align: center;
2344
2344
  justify-content: center;
2345
2345
  }
2346
+ .Polaris-DropZone__Loader .Polaris-Spinner--sizeSmall {
2347
+ height: 20px;
2348
+ }
@@ -68,7 +68,7 @@
68
68
  <% end %>
69
69
 
70
70
  <div class="Polaris-DropZone__Loader Polaris--hidden" data-polaris-dropzone-target="loader">
71
- <%= polaris_spinner %>
71
+ <%= polaris_spinner(size: (@size == :small) ? :small : :large) %>
72
72
  </div>
73
73
  </div>
74
74
 
@@ -1,5 +1,5 @@
1
1
  module Polaris
2
2
  module ViewComponents
3
- VERSION = "0.9.0"
3
+ VERSION = "0.9.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polaris_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Gamble
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-03-07 00:00:00.000000000 Z
12
+ date: 2022-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -469,7 +469,8 @@ files:
469
469
  - app/assets/javascripts/polaris_view_components/select_controller.js
470
470
  - app/assets/javascripts/polaris_view_components/text_field_controller.js
471
471
  - app/assets/javascripts/polaris_view_components/toast_controller.js
472
- - app/assets/javascripts/polaris_view_components/utils.js
472
+ - app/assets/javascripts/polaris_view_components/utils/index.js
473
+ - app/assets/javascripts/polaris_view_components/utils/use-transition.js
473
474
  - app/assets/stylesheets/polaris_view_components.css
474
475
  - app/assets/stylesheets/polaris_view_components.postcss.css
475
476
  - app/assets/stylesheets/polaris_view_components/custom.css