@yoobic/yobi 8.3.0-45 → 8.3.0-48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/cjs/design-system.cjs.js +1 -1
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/yoo-card-feed.cjs.entry.js +2 -2
  4. package/dist/cjs/yoo-detail-bar.cjs.entry.js +1 -1
  5. package/dist/cjs/yoo-form-dynamic.cjs.entry.js +11 -10
  6. package/dist/cjs/yoo-form-input-container.cjs.entry.js +1 -1
  7. package/dist/cjs/yoo-form-swipe-cards.cjs.entry.js +199 -135
  8. package/dist/cjs/yoo-form-todo-task-list.cjs.entry.js +1 -2
  9. package/dist/cjs/yoo-login.cjs.entry.js +54 -63
  10. package/dist/collection/components/form/form-dynamic/form-dynamic.js +11 -10
  11. package/dist/collection/components/form/form-input-container/form-input-container.css +7 -0
  12. package/dist/collection/components/form/form-swipe-cards/form-swipe-cards.css +169 -179
  13. package/dist/collection/components/form/form-swipe-cards/form-swipe-cards.js +233 -169
  14. package/dist/collection/components/form/form-todo-task-list/form-todo-task-list.js +1 -2
  15. package/dist/collection/feature-communicate/feed/card-feed/components/sub-cards.js +2 -2
  16. package/dist/collection/feature-operate/campaign/detail-bar/detail-bar.js +3 -3
  17. package/dist/collection/feature-platform/login/login/login.css +119 -46
  18. package/dist/collection/feature-platform/login/login/login.js +25 -30
  19. package/dist/collection/feature-platform/login/login/parts/Header.js +15 -16
  20. package/dist/collection/feature-platform/login/login/parts/LoginForm.js +15 -18
  21. package/dist/collection/feature-platform/login/login/parts/LoginOptions.js +2 -2
  22. package/dist/design-system/design-system.esm.js +1 -1
  23. package/dist/design-system/yoo-card-feed.entry.js +3 -3
  24. package/dist/design-system/yoo-detail-bar.entry.js +1 -1
  25. package/dist/design-system/yoo-form-dynamic.entry.js +11 -10
  26. package/dist/design-system/yoo-form-input-container.entry.js +1 -1
  27. package/dist/design-system/yoo-form-swipe-cards.entry.js +201 -137
  28. package/dist/design-system/yoo-form-todo-task-list.entry.js +1 -2
  29. package/dist/design-system/yoo-login.entry.js +55 -64
  30. package/dist/esm/design-system.js +1 -1
  31. package/dist/esm/loader.js +1 -1
  32. package/dist/esm/yoo-card-feed.entry.js +3 -3
  33. package/dist/esm/yoo-detail-bar.entry.js +1 -1
  34. package/dist/esm/yoo-form-dynamic.entry.js +11 -10
  35. package/dist/esm/yoo-form-input-container.entry.js +1 -1
  36. package/dist/esm/yoo-form-swipe-cards.entry.js +201 -137
  37. package/dist/esm/yoo-form-todo-task-list.entry.js +1 -2
  38. package/dist/esm/yoo-login.entry.js +55 -64
  39. package/dist/types/components/form/form-swipe-cards/form-swipe-cards.d.ts +20 -13
  40. package/dist/types/feature-platform/login/login/parts/LoginForm.d.ts +0 -1
  41. package/dist/types/feature-platform/login/login/parts/LoginOptions.d.ts +0 -1
  42. package/dist/types/home/runner/work/yoobic-ng-6/yoobic-ng-6/design-system/stencil/.stencil/shared/interfaces/src/entities/form-field/form-field.interface.d.ts +1 -0
  43. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import { SwipeCardsDirection, SwipeCardsMode } from '@shared/interfaces';
2
- import { Draggable, findParent, getMedia, getUUID, gsapTimeline, gsapTo, isCloudinaryLink, isWeb, Power1, translate, translateMulti } from '@shared/utils';
3
- import { Component, Element, Event, forceUpdate, h, Host, Prop, Watch } from '@stencil/core';
2
+ import { Draggable, findParent, getMedia, getUUID, gsapSet, gsapTimeline, gsapTo, isCloudinaryLink, isWeb, Power1, translate, translateMulti } from '@shared/utils';
3
+ import { Component, Element, Event, forceUpdate, h, Host, Prop, State, Watch } from '@stencil/core';
4
4
  import { clamp, inRange, isEqual, shuffle } from 'lodash-es';
5
5
  import { getAppContext } from '../../../utils/helpers/common-helpers';
6
6
  import { hasDuplicates, showWarningAlert } from '../../../utils/helpers/draggable-tags-helpers';
@@ -14,36 +14,36 @@ export class YooFormSwipeCardsComponent {
14
14
  this.shuffled = true;
15
15
  this.values = [];
16
16
  this.swipeCards = [];
17
- this.cardsElements = [];
18
17
  this.swipeButtons = [];
19
18
  }
19
+ onIsVisibleChanged() {
20
+ // Timeout here to wait for the yoo-form-footer to be mounted after a slide has
21
+ // been changed, this will be removed after the refactor of the slides component
22
+ setTimeout(() => this.displayFooterElement(), 150);
23
+ }
20
24
  onCategoriesChanged(nv, ov) {
21
25
  this.hasDataChanged = !isEqual(nv, ov);
22
- if (this.hasDataChanged) {
23
- this.spyOnValuesChanged();
24
- }
26
+ this.showWarnings();
25
27
  }
26
28
  onValuesChanged(nv, ov) {
27
29
  this.hasDataChanged = !isEqual(nv, ov);
30
+ this.hasDataChanged && this.prepareGame();
31
+ this.resetCards();
28
32
  if (!this.isMode.image) {
29
- this.spyOnValuesChanged();
33
+ this.showWarnings();
30
34
  }
31
35
  }
32
36
  onImagesChanged(nv, ov) {
33
37
  this.hasDataChanged = !isEqual(nv, ov);
38
+ this.hasDataChanged && this.prepareGame();
39
+ this.resetCards();
34
40
  if (!this.isMode.text) {
35
- this.spyOnValuesChanged();
41
+ this.showWarnings();
36
42
  }
37
43
  }
38
44
  onRequireChanged() {
39
45
  this.validate();
40
46
  }
41
- // eslint-disable-next-line @stencil/decorators-style
42
- onIsVisibleChanged() {
43
- // Timeout here to wait for the yoo-form-footer to be mounted after a slide has
44
- // been changed, this will be removed after the refactor of the slides component
45
- setTimeout(() => this.displayFooterElement(!this.showInstructionView), 150);
46
- }
47
47
  get isMode() {
48
48
  const { image, text, textimage } = SwipeCardsMode;
49
49
  return {
@@ -52,14 +52,26 @@ export class YooFormSwipeCardsComponent {
52
52
  text: this.mode === text
53
53
  };
54
54
  }
55
- get numberEmptyItems() {
56
- var _a;
57
- const checkEmptyValues = (v) => { var _a; return ((_a = v === null || v === void 0 ? void 0 : v.filter((v) => !v)) === null || _a === void 0 ? void 0 : _a.length) || 0; };
55
+ get cardData() {
56
+ var _a, _b;
58
57
  return {
59
- image: checkEmptyValues((_a = this.images) === null || _a === void 0 ? void 0 : _a.map(img => img._downloadURL)),
60
- text: checkEmptyValues(this.values)
58
+ imagesUrls: ((_a = this.images) === null || _a === void 0 ? void 0 : _a.filter(({ _downloadURL }) => _downloadURL)) || [],
59
+ texts: ((_b = this.values) === null || _b === void 0 ? void 0 : _b.filter((v) => v)) || [],
60
+ getLength(type) {
61
+ return type === 'images' ? this.imagesUrls.length : this.texts.length;
62
+ },
63
+ hasMinimum(type) {
64
+ return (type === 'images' ? this.imagesUrls.length : this.texts.length) >= 2;
65
+ },
66
+ hasEmpty(type) {
67
+ var _a, _b;
68
+ return !!(type === 'images' ? (_a = this.image) === null || _a === void 0 ? void 0 : _a.filter(({ _downloadURL }) => !_downloadURL).length : (_b = this.image) === null || _b === void 0 ? void 0 : _b.filter((v) => !v).length);
69
+ }
61
70
  };
62
71
  }
72
+ get cardsElements() {
73
+ return Array.from(this.host.shadowRoot.querySelectorAll('.card')) || [];
74
+ }
63
75
  get hasImage() {
64
76
  return this.isMode.image || this.isMode.textimage;
65
77
  }
@@ -67,8 +79,34 @@ export class YooFormSwipeCardsComponent {
67
79
  return this.isMode.text || this.isMode.textimage;
68
80
  }
69
81
  get hasTwoCategories() {
70
- var _a, _b;
71
- return !!(((_a = this.categories) === null || _a === void 0 ? void 0 : _a.length) && ((_b = this.categories) === null || _b === void 0 ? void 0 : _b.filter((v) => v).length) === 2);
82
+ var _a;
83
+ return ((_a = this.categories) === null || _a === void 0 ? void 0 : _a.filter((v) => v).length) === 2;
84
+ }
85
+ get hasDuplicateValues() {
86
+ return this.hasText && hasDuplicates(this.cardData.texts);
87
+ }
88
+ get hasEmptyValues() {
89
+ const hasEmptyImagesValues = this.cardData.hasEmpty('images');
90
+ const hasEmptyTextsValues = this.cardData.hasEmpty('texts');
91
+ return (this.hasMinimumRequiredData &&
92
+ (this.isMode.image
93
+ ? hasEmptyImagesValues
94
+ : this.isMode.text
95
+ ? hasEmptyTextsValues
96
+ : hasEmptyImagesValues || hasEmptyTextsValues || this.cardData.getLength('images') !== this.cardData.getLength('texts')));
97
+ }
98
+ get hasMinimumRequiredData() {
99
+ const hasMinimumImagesValues = this.cardData.hasMinimum('images');
100
+ const hasMinimumTextsValues = this.cardData.hasMinimum('texts');
101
+ return this.isMode.image ? hasMinimumImagesValues : this.isMode.text ? hasMinimumTextsValues : hasMinimumImagesValues && hasMinimumTextsValues;
102
+ }
103
+ get hasData() {
104
+ const hasImagesValues = !!this.cardData.getLength('images');
105
+ const hasTextsValues = !!this.cardData.getLength('texts');
106
+ return this.isMode.image ? hasImagesValues : this.isMode.text ? hasTextsValues : hasImagesValues && hasTextsValues;
107
+ }
108
+ get isDataValid() {
109
+ return this.hasTwoCategories && this.hasMinimumRequiredData && !this.hasDuplicateValues && !this.hasEmptyValues;
72
110
  }
73
111
  get hasAllCardBeenSwiped() {
74
112
  var _a;
@@ -76,7 +114,7 @@ export class YooFormSwipeCardsComponent {
76
114
  }
77
115
  get buttons() {
78
116
  const { left, right, undo } = SwipeCardsDirection;
79
- const getButton = (direction) => { var _a, _b; return (_b = (_a = this.swipeButtons) === null || _a === void 0 ? void 0 : _a.filter(({ id }) => id === `swipe-${direction}`)) === null || _b === void 0 ? void 0 : _b[0]; };
117
+ const getButton = (direction) => { var _a, _b, _c; return (_c = (_b = (_a = this.swipeButtons) === null || _a === void 0 ? void 0 : _a.filter((button) => button)) === null || _b === void 0 ? void 0 : _b.filter(({ id }) => id === `swipe-${direction}`)) === null || _c === void 0 ? void 0 : _c[0]; };
80
118
  return {
81
119
  left: getButton(left),
82
120
  undo: getButton(undo),
@@ -103,20 +141,20 @@ export class YooFormSwipeCardsComponent {
103
141
  this.updateGame();
104
142
  }
105
143
  validate() {
106
- var _a;
107
- const numberSwipedCards = (_a = this.swipeCards.filter(card => card.swipedDirection)) === null || _a === void 0 ? void 0 : _a.length;
108
- this.validity = numberSwipedCards === (this.hasImage ? this.images.length : this.values.length);
144
+ var _a, _b;
145
+ const numberSwipedCards = (_a = this.swipeCards.filter((card) => card.swipedDirection)) === null || _a === void 0 ? void 0 : _a.length;
146
+ this.validity = !this.required || numberSwipedCards === ((_b = this.cardData[this.hasImage ? 'imagesUrls' : 'texts']) === null || _b === void 0 ? void 0 : _b.length);
109
147
  this.validityChanged.emit(this.validity);
110
148
  return this.validity;
111
149
  }
112
150
  prepareGame() {
113
151
  this.shuffleCardValues();
114
- this.animationDelay = this.animated ? .25 : 0;
152
+ this.animationDelay = this.animated ? 0.25 : 0;
115
153
  this.revealCards = !this.showInstructionView;
116
154
  this.swipeCards = this.initCards();
117
155
  }
118
156
  initGame() {
119
- this.displayFooterElement(false);
157
+ this.displayFooterElement();
120
158
  !this.showInstructionView && this.initDraggable();
121
159
  }
122
160
  updateCardsData() {
@@ -130,34 +168,32 @@ export class YooFormSwipeCardsComponent {
130
168
  updateGame() {
131
169
  if (this.revealCards) {
132
170
  this.hasDataChanged = false;
133
- this.revealCards = false;
134
171
  this.initDraggable();
172
+ setTimeout(() => {
173
+ if (this.host.scrollHeight > this.host.clientHeight) {
174
+ this.host.scrollTo({
175
+ top: this.host.scrollHeight,
176
+ behavior: 'smooth'
177
+ });
178
+ }
179
+ }, 1000);
135
180
  }
136
- setTimeout(() => this.lockSwipeButtons(false), 750);
181
+ setTimeout(() => this.lockSwipeActions(false), 750);
182
+ this.displayFooterElement();
137
183
  }
138
184
  shuffleCardValues() {
139
- const cardData = this.hasImage ? this.images.filter((f) => (this.isMode.textimage ? f === null || f === void 0 ? void 0 : f._filename : f)) : this.values.filter((v) => v);
185
+ const cardData = this.hasImage ? this.cardData.imagesUrls : this.cardData.texts;
140
186
  this.cardValues = this.shuffled ? shuffle(cardData) : cardData;
141
187
  }
142
- getCardElement(id) {
188
+ getCardElement(cardId) {
143
189
  var _a;
144
- return (_a = this.cardsElements) === null || _a === void 0 ? void 0 : _a.find((cardElement) => (cardElement === null || cardElement === void 0 ? void 0 : cardElement.id) === id);
145
- }
146
- spyOnValuesChanged() {
147
- this.hasDataChanged && this.showWarnings();
190
+ return (_a = this.cardsElements) === null || _a === void 0 ? void 0 : _a.find(({ id }) => cardId === id);
148
191
  }
149
192
  showWarnings() {
150
- var _a;
151
- if (((_a = this.values) === null || _a === void 0 ? void 0 : _a.length) && this.livePreview && !this.hasTwoCategories) {
152
- showWarningAlert(this.host, true, 'NOTFULFILLEDCATEGORIES');
153
- }
154
- else if (this.hasTwoCategories && this.livePreview) {
155
- this.hasEmptyValues = !!this.numberEmptyItems.text || !!this.numberEmptyItems.image;
156
- this.hasDuplicatesValues = this.hasText && hasDuplicates(this.values);
157
- let showAlert = this.hasEmptyValues || this.hasDuplicatesValues;
158
- this.isMode.textimage && this.hasEmptyValues && (showAlert = showAlert && this.numberEmptyItems.text !== this.numberEmptyItems.image);
159
- const bannerMessage = this.hasDuplicatesValues ? 'NODUPLICATEVALUES' : this.hasEmptyValues ? 'NOEMPTYVALUES' : '';
160
- const bannerColor = this.hasDuplicatesValues ? 'danger' : this.hasEmptyValues ? 'warning' : null;
193
+ if (this.livePreview && this.hasDataChanged && this.hasData) {
194
+ const bannerMessage = this.hasDuplicateValues ? 'NODUPLICATEVALUES' : this.hasEmptyValues ? 'NOEMPTYVALUES' : !this.hasTwoCategories ? 'NOTFULFILLEDCATEGORIES' : '';
195
+ const bannerColor = this.hasDuplicateValues || !this.hasTwoCategories ? 'danger' : this.hasEmptyValues ? 'warning' : null;
196
+ const showAlert = !!bannerMessage;
161
197
  showWarningAlert(this.host, showAlert, bannerMessage, bannerColor);
162
198
  this.hasDataChanged = !showAlert;
163
199
  if (showAlert)
@@ -168,48 +204,49 @@ export class YooFormSwipeCardsComponent {
168
204
  const formatCardValue = (value) => {
169
205
  var _a, _b;
170
206
  if (this.isMode.image) {
171
- return isCloudinaryLink((_b = (_a = this.answer) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b[0]) ? value._downloadURL :
172
- value._downloadURL.split('/').pop();
207
+ return isCloudinaryLink((_b = (_a = this.answer) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b[0]) ? value._downloadURL : value._downloadURL.split('/').pop();
173
208
  }
174
209
  if (this.isMode.textimage) {
175
210
  return value._filename;
176
211
  }
177
212
  return value;
178
213
  };
179
- const getValuesFromDirection = (direction) => this.swipeCards.filter(c => c.swipedDirection === direction).map(c => formatCardValue(c.value));
180
- this.livePreview ? forceUpdate(this) : setValueAndValidateInput([
181
- getValuesFromDirection(SwipeCardsDirection.left),
182
- getValuesFromDirection(SwipeCardsDirection.right)
183
- ], this);
214
+ const getValuesFromDirection = (direction) => this.swipeCards.filter((c) => c.swipedDirection === direction).map((c) => formatCardValue(c.value));
215
+ this.livePreview ? forceUpdate(this) : setValueAndValidateInput([getValuesFromDirection(SwipeCardsDirection.left), getValuesFromDirection(SwipeCardsDirection.right)], this);
184
216
  }
185
- displayFooterElement(show = true) {
217
+ displayFooterElement() {
186
218
  var _a, _b;
187
219
  const yooIonSlideEl = findParent(this.host, 'yoo-ion-slide');
188
- if (yooIonSlideEl) {
189
- const footerElement = yooIonSlideEl.querySelector('yoo-form-footer');
190
- if (footerElement) {
191
- this.nextButtonText = ((_b = (_a = footerElement === null || footerElement === void 0 ? void 0 : footerElement.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('yoo-button:last-of-type')) === null || _b === void 0 ? void 0 : _b.textContent) || '';
192
- footerElement.style.display = show ? 'block' : 'none';
193
- }
220
+ const footerElement = yooIonSlideEl === null || yooIonSlideEl === void 0 ? void 0 : yooIonSlideEl.querySelector('yoo-form-footer');
221
+ if (footerElement) {
222
+ this.nextButtonText = ((_b = (_a = footerElement === null || footerElement === void 0 ? void 0 : footerElement.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('yoo-button:last-of-type')) === null || _b === void 0 ? void 0 : _b.textContent) || '';
223
+ footerElement.style.display = !this.showInstructionView ? 'block' : 'none';
194
224
  }
195
225
  }
196
226
  initDraggable() {
197
- this.cardsElements
198
- .filter(e => !Draggable.get(e))
199
- .forEach(e => this.getDraggableInstance(e));
200
- this.cardsElements.forEach(e => e === null || e === void 0 ? void 0 : e.classList.remove('revealing'));
227
+ this.cardsElements.filter((e) => !Draggable.get(e)).forEach((e) => this.getDraggableInstance(e));
228
+ this.cardsElements.forEach((e) => e === null || e === void 0 ? void 0 : e.classList.remove('revealing'));
201
229
  }
202
230
  initCards() {
203
231
  var _a;
204
- return ((_a = this.cardValues) === null || _a === void 0 ? void 0 : _a.map(v => ({ id: getUUID(), value: this.hasImage ? v : v }))) || [];
232
+ return ((_a = this.cardValues) === null || _a === void 0 ? void 0 : _a.map((value) => ({ id: getUUID(), value }))) || [];
205
233
  }
206
- lockSwipeButtons(lockState = true) {
234
+ lockSwipeActions(lockState = true) {
207
235
  var _a;
208
- (_a = this.swipeButtons) === null || _a === void 0 ? void 0 : _a.forEach(b => b && (b.disabled = lockState));
236
+ (_a = this.swipeButtons) === null || _a === void 0 ? void 0 : _a.forEach((b) => b && (b.disabled = this.animated ? lockState : false));
237
+ }
238
+ async resetCards() {
239
+ var _a, _b;
240
+ this.showInstructionView = true;
241
+ await Promise.all((_a = this.swipeCards) === null || _a === void 0 ? void 0 : _a.map((card) => this.undoCard(card, false)));
242
+ (_b = this.cardsElements) === null || _b === void 0 ? void 0 : _b.forEach((cardElement) => {
243
+ cardElement.removeAttribute('swiped');
244
+ gsapSet(cardElement, { clearProps: 'all' });
245
+ });
209
246
  }
210
247
  swipeCard(direction) {
211
248
  if (this.currentCard) {
212
- this.lockSwipeButtons();
249
+ this.lockSwipeActions();
213
250
  this.buttons[direction].style.removeProperty('transform');
214
251
  this.gameContainerElement.removeAttribute('direction');
215
252
  this.currentCardElement.setAttribute('swiped', direction);
@@ -220,11 +257,7 @@ export class YooFormSwipeCardsComponent {
220
257
  getSwipedState(swipeProgress) {
221
258
  const swipeThresholds = [0.35, 0.65];
222
259
  return {
223
- swipedDirection: swipeProgress < swipeThresholds[0]
224
- ? SwipeCardsDirection.left
225
- : swipeProgress > swipeThresholds[1]
226
- ? SwipeCardsDirection.right
227
- : null,
260
+ swipedDirection: swipeProgress < swipeThresholds[0] ? SwipeCardsDirection.left : swipeProgress > swipeThresholds[1] ? SwipeCardsDirection.right : null,
228
261
  isCardThrowable: !inRange(swipeProgress, swipeThresholds[0], swipeThresholds[1])
229
262
  };
230
263
  }
@@ -232,12 +265,16 @@ export class YooFormSwipeCardsComponent {
232
265
  if (this.currentCardElement) {
233
266
  const { left, right } = SwipeCardsDirection;
234
267
  const [categoryLeft, categoryRight] = this.categories;
235
- const categoryContainer = this.currentCardElement.querySelector('.content-category');
236
268
  const isThrowable = [left, right].includes(swipingDirection);
237
- categoryContainer.textContent = translateMulti(swipingDirection === left ? categoryLeft : swipingDirection === right ? categoryRight : '');
238
- [this.gameContainerElement, this.currentCardElement].forEach(e => {
239
- isThrowable ? e.setAttribute('direction', swipingDirection) : e.removeAttribute('direction');
240
- });
269
+ const contentContainer = this.currentCardElement.querySelector(`.content-${this.isMode.image ? 'image' : 'text'}`);
270
+ if (isThrowable) {
271
+ this.gameContainerElement.setAttribute('direction', swipingDirection);
272
+ contentContainer.dataset.category = translateMulti(swipingDirection === left ? categoryLeft : swipingDirection === right ? categoryRight : '');
273
+ }
274
+ else {
275
+ this.gameContainerElement.removeAttribute('direction');
276
+ contentContainer.removeAttribute('data-category');
277
+ }
241
278
  }
242
279
  }
243
280
  async getDraggableInstance(cardElement) {
@@ -245,16 +282,12 @@ export class YooFormSwipeCardsComponent {
245
282
  if (!timeline || !cardElement) {
246
283
  return;
247
284
  }
248
- this.revealCards = false;
249
285
  const maxRange = this.host.clientWidth / 2;
250
286
  const returnedAnimation = timeline();
251
287
  // building swiping animation
252
288
  const swipeAnimation = timeline({ paused: true });
253
- const isSwipeable = el => el.classList.contains('current');
254
- swipeAnimation
255
- .fromTo(this.buttons.left, 1, { scale: 1.5 }, { scale: 1 }, 0)
256
- .fromTo(this.buttons.right, 1, { scale: 1 }, { scale: 1.5 }, 1)
257
- .progress(.5);
289
+ const isSwipeable = (el) => el.classList.contains('current');
290
+ swipeAnimation.fromTo(this.buttons.left, 1, { scale: 1.5 }, { scale: 1 }, 0).fromTo(this.buttons.right, 1, { scale: 1 }, { scale: 1.5 }, 1).progress(0.5);
258
291
  const onStartSwiping = () => {
259
292
  if (isSwipeable(cardElement)) {
260
293
  this.blockMoves.emit(true);
@@ -272,26 +305,26 @@ export class YooFormSwipeCardsComponent {
272
305
  const baseProps = { left: 0, top: 0 };
273
306
  if (isSwipeable(cardElement)) {
274
307
  const { isCardThrowable, swipedDirection } = this.getSwipedState(swipeAnimation.progress());
275
- !isCardThrowable ?
276
- returnedAnimation
277
- .to(cardElement, this.animationDelay, baseProps)
278
- .to([this.buttons.left, this.buttons.right], { scale: 1, ease: Power1.easeInOut }, 0) :
279
- this.swipeCard(swipedDirection);
308
+ !isCardThrowable
309
+ ? returnedAnimation.to(cardElement, this.animationDelay, baseProps).to([this.buttons.left, this.buttons.right], { scale: 1, ease: Power1.easeInOut }, 0)
310
+ : this.swipeCard(swipedDirection);
280
311
  }
281
312
  else {
282
313
  gsapTo(cardElement, this.animationDelay, baseProps);
283
314
  }
284
315
  this.blockMoves.emit(false);
285
316
  };
286
- return (new Draggable(cardElement, {
317
+ return new Draggable(cardElement, {
287
318
  bound: this.host,
288
319
  type: 'left, top',
289
320
  cursor: 'grab',
290
321
  zIndexBoost: false,
291
322
  onDragStart: () => onStartSwiping(),
292
- onDrag() { onSwiping(this); },
323
+ onDrag() {
324
+ onSwiping(this);
325
+ },
293
326
  onDragEnd: () => onThrowing()
294
- }));
327
+ });
295
328
  }
296
329
  clickToSwipe(clickedDirection) {
297
330
  if (!this.buttons[clickedDirection].disabled) {
@@ -299,41 +332,55 @@ export class YooFormSwipeCardsComponent {
299
332
  this.swipeCard(clickedDirection);
300
333
  }
301
334
  }
302
- async undoSwipe() {
303
- const lastThrownCard = this.swipeCards[this.swipeCards.reduce((acc, card, index) => (card.swipedDirection ? index : acc), 0)];
304
- if (!this.buttons.undo.disabled && (lastThrownCard === null || lastThrownCard === void 0 ? void 0 : lastThrownCard.swipedDirection)) {
305
- this.lockSwipeButtons();
306
- const lastThrownCardElement = this.getCardElement(lastThrownCard === null || lastThrownCard === void 0 ? void 0 : lastThrownCard.id);
335
+ async undoCard(card, shouldLockActions = true) {
336
+ var _a, _b;
337
+ card = card || this.swipeCards[this.swipeCards.reduce((acc, card, index) => (card.swipedDirection ? index : acc), 0)];
338
+ if (!((_b = (_a = this.buttons) === null || _a === void 0 ? void 0 : _a.undo) === null || _b === void 0 ? void 0 : _b.disabled) && (card === null || card === void 0 ? void 0 : card.swipedDirection)) {
339
+ shouldLockActions && this.lockSwipeActions();
340
+ const lastThrownCardElement = this.getCardElement(card === null || card === void 0 ? void 0 : card.id);
307
341
  if (lastThrownCardElement) {
342
+ lastThrownCardElement.style.zIndex = '4';
308
343
  lastThrownCardElement.style.removeProperty('top');
309
344
  lastThrownCardElement.style.removeProperty('left');
310
345
  lastThrownCardElement.removeAttribute('swiped');
311
- lastThrownCard === null || lastThrownCard === void 0 ? true : delete lastThrownCard.swipedDirection;
312
- setTimeout(() => {
313
- this.getUserAnswer();
314
- }, 225);
346
+ card === null || card === void 0 ? true : delete card.swipedDirection;
347
+ await new Promise((resolve) => {
348
+ setTimeout(() => {
349
+ this.getUserAnswer();
350
+ resolve();
351
+ }, 225);
352
+ });
315
353
  }
316
354
  }
317
355
  }
318
356
  renderCards() {
319
- return h("section", { id: "cards" }, this.swipeCards.map(({ swipedDirection, value, id }, i, s) => {
357
+ let nbrCardRevealed = 0;
358
+ return (h("section", { id: "cards" }, this.swipeCards.map(({ swipedDirection, value, id }, i, s) => {
320
359
  const currentCardIndex = s.indexOf(this.currentCard);
321
360
  const hasCurrentCard = currentCardIndex !== -1;
322
- return h("div", { id: id, class: {
361
+ const isCurrentCard = i === currentCardIndex;
362
+ return (h("div", { id: id, class: {
323
363
  card: true,
324
- current: i === currentCardIndex,
364
+ current: isCurrentCard,
325
365
  second: hasCurrentCard && i === currentCardIndex + 1,
326
366
  third: hasCurrentCard && i === currentCardIndex + 2,
327
367
  revealing: this.revealCards
328
- }, ref: el => this.cardsElements[i] = el, ...{
368
+ }, onTransitionEnd: () => {
369
+ nbrCardRevealed += 1;
370
+ if (this.revealCards && nbrCardRevealed === Math.min(s.length + 1, 3)) {
371
+ this.enableButtonActions = true;
372
+ }
373
+ if (isCurrentCard) {
374
+ this.currentCardElement.style.removeProperty('z-index');
375
+ }
376
+ }, ...{
329
377
  type: this.mode,
330
378
  ...(swipedDirection && { direction: swipedDirection })
331
379
  } },
332
380
  this.hasImage && (h("div", { class: "content-image" },
333
381
  h("yoo-img", { instant: true, src: getMedia(value['_downloadURL']) }))),
334
- this.hasText && (h("div", { class: "content-text" }, translateMulti((value === null || value === void 0 ? void 0 : value['_filename']) || value))),
335
- h("div", { class: "content-category" }));
336
- }));
382
+ this.hasText && h("div", { class: "content-text" }, translateMulti((value === null || value === void 0 ? void 0 : value['_filename']) || value))));
383
+ })));
337
384
  }
338
385
  renderInstructionCategory(side) {
339
386
  const isLeftCategory = side === SwipeCardsDirection.left;
@@ -341,18 +388,18 @@ export class YooFormSwipeCardsComponent {
341
388
  const iconColor = isWeb(this.host) ? categoryColor : 'light';
342
389
  const iconSize = isWeb(this.host) ? 'large' : 'medium';
343
390
  const category = this.categories && translateMulti(isLeftCategory ? this.categories[0] : this.categories[1]);
344
- return h("div", { class: { category: true, [side]: true } },
391
+ return (h("div", { class: { category: true, [side]: true } },
345
392
  h("yoo-tag", { noBackground: isWeb(this.host), color: categoryColor, size: "large", icon: `big-arrow-${side}`, iconOnlyColor: iconColor, iconOnlySize: iconSize }),
346
393
  h("p", { class: `${categoryColor}` }, category),
347
- h("span", { class: "stable" }, translate(`SWIPE${side.toUpperCase()}`)));
394
+ h("span", { class: "stable" }, translate(`SWIPE${side.toUpperCase()}`))));
348
395
  }
349
396
  renderTopDescription() {
350
- return h("div", { id: "header" },
397
+ return (h("div", { id: "header" },
351
398
  h("span", { id: "title", innerHTML: translateMulti(this.label) }),
352
- h("span", { class: "stable" }, translate(this.description || 'CARDSWIPEDEFAULTINSTRUCTIONS')));
399
+ h("span", { class: "stable" }, translate(this.description || 'CARDSWIPEDEFAULTINSTRUCTIONS'))));
353
400
  }
354
- renderInstructions() {
355
- return (h("section", { id: "instructions" },
401
+ renderHeaderInstructions() {
402
+ return [
356
403
  this.renderTopDescription(),
357
404
  h("section", { id: "categories" },
358
405
  this.renderInstructionCategory(SwipeCardsDirection.left),
@@ -360,14 +407,10 @@ export class YooFormSwipeCardsComponent {
360
407
  this.renderInstructionCategory(SwipeCardsDirection.right)),
361
408
  this.instructionsDocument && (h("section", { id: "document" },
362
409
  h("div", { class: "document-title" }, translate('ATTACHMENTS')),
363
- h("yoo-form-document", { document: this.instructionsDocument, readonly: true, onInputChanged: (ev) => ev.stopPropagation() }))),
364
- h("yoo-button", { disabled: !(this.hasTwoCategories && !this.hasDuplicatesValues), size: (isWeb(this.host) && !this.livePreview) ? 'medium' : 'large', color: "app-color", onClick: () => {
365
- this.revealCards = true;
366
- this.showInstructionView = false;
367
- this.displayFooterElement();
368
- } }, translate('START'))));
369
- }
370
- renderSwipeButtons() {
410
+ h("yoo-form-document", { document: this.instructionsDocument, readonly: true, onInputChanged: (ev) => ev.stopPropagation() })))
411
+ ];
412
+ }
413
+ renderActions() {
371
414
  const { left, undo, right } = SwipeCardsDirection;
372
415
  return h("section", { id: "actions" }, [left, undo, right].map((d, i) => this.renderSwipeAction(d, i)));
373
416
  }
@@ -376,57 +419,75 @@ export class YooFormSwipeCardsComponent {
376
419
  const isUndo = direction === SwipeCardsDirection.undo;
377
420
  const isLeft = direction === SwipeCardsDirection.left;
378
421
  const isMobile = !isWeb(this.host) || this.livePreview;
379
- const actionColor = isUndo ? isWeb(this.host) ? 'light' : 'stable-alt' : isLeft ? 'app-color' : 'warning';
422
+ const actionColor = isUndo ? (isWeb(this.host) ? 'light' : 'stable-alt') : isLeft ? 'app-color' : 'warning';
380
423
  const swipeIcon = isUndo ? 'undo' : `big-arrow-${direction}`;
381
424
  const categoryIndex = isLeft ? 0 : 1;
382
425
  return (h("div", { class: { action: true, hide: this.hasAllCardBeenSwiped && !isUndo } },
383
- h("yoo-button", { shape: "circular", rippleType: "unbounded", id: `swipe-${direction}`, size: (isUndo && !isMobile) ? 'medium' : 'large', fill: (isMobile || isUndo) ? 'solid' : 'transparent', color: isUndo ? isMobile ? 'stable-light' : 'text-color' : actionColor.concat('-20'), ref: (element) => (this.swipeButtons[index] = element), onClick: () => isUndo ? this.undoSwipe() : this.clickToSwipe(direction) },
426
+ h("yoo-button", { shape: "circular", rippleType: "unbounded", id: `swipe-${direction}`, disabled: !this.enableButtonActions, size: isUndo && !isMobile ? 'medium' : 'large', fill: isMobile || isUndo ? 'solid' : 'transparent', color: isUndo ? (isMobile ? 'stable-light' : 'text-color') : actionColor.concat('-20'), ref: (element) => (this.swipeButtons[index] = element), onClick: () => (isUndo ? this.undoCard() : this.clickToSwipe(direction)) },
384
427
  h("yoo-icon", { name: swipeIcon, color: actionColor, size: isMobile ? 'medium' : isUndo ? 'small' : 'large' })),
385
428
  !isUndo && ((_a = this.categories) === null || _a === void 0 ? void 0 : _a.length) && h("span", { class: actionColor }, translateMulti(this.categories[categoryIndex]))));
386
429
  }
387
- renderEndGameMessage() {
388
- return h("section", { id: "end-message", class: { active: this.hasAllCardBeenSwiped } },
389
- h("yoo-lottie", { autoplay: this.hasAllCardBeenSwiped, type: "check" }),
390
- h("div", { innerHTML: translate('ENDSWIPINGCARDSMESSAGE') }),
391
- h("span", null, translate('CLICKTOCONTINUE', { buttonName: this.nextButtonText })));
430
+ renderBackground() {
431
+ return (h("section", { id: "background" },
432
+ h("div", { id: "end-message", class: { active: this.hasAllCardBeenSwiped } },
433
+ h("yoo-lottie", { autoplay: this.hasAllCardBeenSwiped, type: "check" }),
434
+ h("div", { innerHTML: translate('ENDSWIPINGCARDSMESSAGE') }),
435
+ h("span", null, translate('CLICKTOCONTINUE', { buttonName: this.nextButtonText }))),
436
+ this.renderActions()));
392
437
  }
393
438
  renderGame() {
394
439
  return [
395
440
  isWeb(this.host) && !this.livePreview && this.renderTopDescription(),
396
441
  h("section", { id: "game", ref: (element) => (this.gameContainerElement = element) },
397
- this.renderEndGameMessage(),
398
- this.renderCards()),
399
- this.renderSwipeButtons()
442
+ this.renderBackground(),
443
+ this.renderCards())
400
444
  ];
401
445
  }
446
+ renderStartButton() {
447
+ return (!this.readonly &&
448
+ this.showInstructionView && (h("yoo-button", { disabled: !this.hasData || !this.isDataValid, size: isWeb(this.host) && !this.livePreview ? 'medium' : 'large', color: "app-color", onClick: () => {
449
+ this.revealCards = true;
450
+ this.showInstructionView = false;
451
+ this.displayFooterElement();
452
+ } }, translate('START'))));
453
+ }
454
+ renderInstructions() {
455
+ return [h("section", { id: "instructions" }, this.renderHeaderInstructions()), this.renderStartButton()];
456
+ }
402
457
  renderSummary() {
403
- const getAnswerCounter = (category) => { var _a, _b; return ((_a = this.value) === null || _a === void 0 ? void 0 : _a.length) && ((_b = this.answer) === null || _b === void 0 ? void 0 : _b.length) ? translateMulti(category) : ''; };
458
+ const getAnswerCounter = (category) => { var _a, _b; return (((_a = this.value) === null || _a === void 0 ? void 0 : _a.length) && ((_b = this.answer) === null || _b === void 0 ? void 0 : _b.length) ? translateMulti(category) : ''); };
404
459
  const getAnswerImage = (answerValue) => {
405
460
  var _a, _b;
406
461
  const getImageValue = (image) => image[`${this.isMode.image ? '_downloadURL' : '_filename'}`];
407
- return (((_a = this.images.find(image => getImageValue(image) === answerValue)) === null || _a === void 0 ? void 0 : _a._downloadURL) ||
408
- ((_b = this.images.find(image => { var _a; return (_a = getImageValue(image)) === null || _a === void 0 ? void 0 : _a.includes(answerValue); })) === null || _b === void 0 ? void 0 : _b._downloadURL) || '');
462
+ return (((_a = this.images.find((image) => getImageValue(image) === answerValue)) === null || _a === void 0 ? void 0 : _a._downloadURL) ||
463
+ ((_b = this.images.find((image) => { var _a; return (_a = getImageValue(image)) === null || _a === void 0 ? void 0 : _a.includes(answerValue); })) === null || _b === void 0 ? void 0 : _b._downloadURL) ||
464
+ '');
409
465
  };
410
466
  const getValidationClass = (categoryIndex, answerValue) => this.answer[categoryIndex].find((answer) => answerValue.includes(answer)) ? 'valid' : 'invalid';
411
- return this.categories.map((categoryValue, catIndex) => [
412
- h("div", { class: "category-title" }, getAnswerCounter(categoryValue)),
413
- h("ul", null, Array.from(new Set(this.value[catIndex])).map((userAnswer) => {
414
- var _a;
415
- return (h("li", { class: getValidationClass(catIndex, userAnswer) },
416
- !!((_a = this.images) === null || _a === void 0 ? void 0 : _a.length) && h("yoo-img", { src: getAnswerImage(userAnswer) }),
417
- !this.isMode.image && h("yoo-truncate", null, translateMulti(userAnswer))));
418
- }))
419
- ]);
467
+ return (this.readonly &&
468
+ this.categories.map((categoryValue, catIndex) => [
469
+ h("div", { class: "category-title" }, getAnswerCounter(categoryValue)),
470
+ h("ul", null, Array.from(new Set(this.value[catIndex])).map((userAnswer) => {
471
+ var _a;
472
+ return (h("li", { class: getValidationClass(catIndex, userAnswer) },
473
+ !!((_a = this.images) === null || _a === void 0 ? void 0 : _a.length) && h("yoo-img", { src: getAnswerImage(userAnswer) }),
474
+ !this.isMode.image && h("yoo-truncate", null, translateMulti(userAnswer))));
475
+ }))
476
+ ]));
420
477
  }
421
478
  renderBanner() {
422
- return this.livePreview && h("yoo-banner", null,
423
- h("p", { slot: "content" }));
479
+ return (this.livePreview &&
480
+ !this.readonly && (h("yoo-banner", null,
481
+ h("p", { slot: "content" }))));
482
+ }
483
+ renderMain() {
484
+ return h("main", null, !this.readonly && (this.showInstructionView ? this.renderInstructions() : this.renderGame()));
424
485
  }
425
486
  render() {
426
- return (h(Host, { class: { ...getAppContext(this.host), 'swiper-no-swiping': !this.readonly, instructions: this.showInstructionView } },
487
+ return (h(Host, { class: { ...getAppContext(this.host), 'swiper-no-swiping': !this.readonly }, ...{ view: this.showInstructionView ? 'instructions' : 'game' } },
427
488
  this.renderBanner(),
428
- !this.readonly && (this.showInstructionView ? this.renderInstructions() : this.renderGame()),
429
- this.readonly && this.renderSummary()));
489
+ this.renderMain(),
490
+ this.renderSummary()));
430
491
  }
431
492
  static get is() { return "yoo-form-swipe-cards"; }
432
493
  static get encapsulation() { return "shadow"; }
@@ -600,23 +661,6 @@ export class YooFormSwipeCardsComponent {
600
661
  "attribute": "number-steps",
601
662
  "reflect": false
602
663
  },
603
- "isVisible": {
604
- "type": "boolean",
605
- "mutable": false,
606
- "complexType": {
607
- "original": "boolean",
608
- "resolved": "boolean",
609
- "references": {}
610
- },
611
- "required": false,
612
- "optional": false,
613
- "docs": {
614
- "tags": [],
615
- "text": ""
616
- },
617
- "attribute": "is-visible",
618
- "reflect": false
619
- },
620
664
  "readonly": {
621
665
  "type": "boolean",
622
666
  "mutable": false,
@@ -728,6 +772,23 @@ export class YooFormSwipeCardsComponent {
728
772
  "reflect": false,
729
773
  "defaultValue": "true"
730
774
  },
775
+ "isVisible": {
776
+ "type": "boolean",
777
+ "mutable": false,
778
+ "complexType": {
779
+ "original": "boolean",
780
+ "resolved": "boolean",
781
+ "references": {}
782
+ },
783
+ "required": false,
784
+ "optional": false,
785
+ "docs": {
786
+ "tags": [],
787
+ "text": ""
788
+ },
789
+ "attribute": "is-visible",
790
+ "reflect": false
791
+ },
731
792
  "categories": {
732
793
  "type": "unknown",
733
794
  "mutable": false,
@@ -797,6 +858,9 @@ export class YooFormSwipeCardsComponent {
797
858
  "reflect": false
798
859
  }
799
860
  }; }
861
+ static get states() { return {
862
+ "enableButtonActions": {}
863
+ }; }
800
864
  static get events() { return [{
801
865
  "method": "validityChanged",
802
866
  "name": "validityChanged",
@@ -845,6 +909,9 @@ export class YooFormSwipeCardsComponent {
845
909
  }]; }
846
910
  static get elementRef() { return "host"; }
847
911
  static get watchers() { return [{
912
+ "propName": "isVisible",
913
+ "methodName": "onIsVisibleChanged"
914
+ }, {
848
915
  "propName": "categories",
849
916
  "methodName": "onCategoriesChanged"
850
917
  }, {
@@ -856,8 +923,5 @@ export class YooFormSwipeCardsComponent {
856
923
  }, {
857
924
  "propName": "required",
858
925
  "methodName": "onRequireChanged"
859
- }, {
860
- "propName": "isVisible",
861
- "methodName": "onIsVisibleChanged"
862
926
  }]; }
863
927
  }