@shoper/phoenix_design_system 1.18.10-0 → 1.18.10-1

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 (38) hide show
  1. package/build/cjs/packages/phoenix/src/components/accordion/accordion.js +28 -6
  2. package/build/cjs/packages/phoenix/src/components/accordion/accordion.js.map +1 -1
  3. package/build/cjs/packages/phoenix/src/components/accordion/accordion_constants.js +5 -0
  4. package/build/cjs/packages/phoenix/src/components/accordion/accordion_constants.js.map +1 -1
  5. package/build/cjs/packages/phoenix/src/components/accordion/accordion_content.js +143 -2
  6. package/build/cjs/packages/phoenix/src/components/accordion/accordion_content.js.map +1 -1
  7. package/build/cjs/packages/phoenix/src/components/accordion/accordion_group.js +171 -47
  8. package/build/cjs/packages/phoenix/src/components/accordion/accordion_group.js.map +1 -1
  9. package/build/cjs/packages/phoenix/src/components/accordion/accordion_toggler.js +50 -1
  10. package/build/cjs/packages/phoenix/src/components/accordion/accordion_toggler.js.map +1 -1
  11. package/build/cjs/packages/phoenix/src/index.js +6 -5
  12. package/build/cjs/packages/phoenix/src/index.js.map +1 -1
  13. package/build/cjs/packages/utilities/build/esm/packages/utilities/src/feature_flag_utils.js +26 -0
  14. package/build/cjs/packages/utilities/build/esm/packages/utilities/src/feature_flag_utils.js.map +1 -0
  15. package/build/cjs/packages/utilities/build/esm/packages/utilities/src/json_utils.js +25 -0
  16. package/build/cjs/packages/utilities/build/esm/packages/utilities/src/json_utils.js.map +1 -0
  17. package/build/esm/packages/phoenix/src/components/accordion/accordion.d.ts +6 -1
  18. package/build/esm/packages/phoenix/src/components/accordion/accordion.js +29 -7
  19. package/build/esm/packages/phoenix/src/components/accordion/accordion.js.map +1 -1
  20. package/build/esm/packages/phoenix/src/components/accordion/accordion_constants.d.ts +4 -0
  21. package/build/esm/packages/phoenix/src/components/accordion/accordion_constants.js +5 -1
  22. package/build/esm/packages/phoenix/src/components/accordion/accordion_constants.js.map +1 -1
  23. package/build/esm/packages/phoenix/src/components/accordion/accordion_content.d.ts +24 -0
  24. package/build/esm/packages/phoenix/src/components/accordion/accordion_content.js +143 -2
  25. package/build/esm/packages/phoenix/src/components/accordion/accordion_content.js.map +1 -1
  26. package/build/esm/packages/phoenix/src/components/accordion/accordion_group.d.ts +17 -3
  27. package/build/esm/packages/phoenix/src/components/accordion/accordion_group.js +172 -48
  28. package/build/esm/packages/phoenix/src/components/accordion/accordion_group.js.map +1 -1
  29. package/build/esm/packages/phoenix/src/components/accordion/accordion_toggler.d.ts +9 -0
  30. package/build/esm/packages/phoenix/src/components/accordion/accordion_toggler.js +50 -1
  31. package/build/esm/packages/phoenix/src/components/accordion/accordion_toggler.js.map +1 -1
  32. package/build/esm/packages/phoenix/src/components/accordion/accordion_types.d.ts +10 -0
  33. package/build/esm/packages/phoenix/src/index.js +2 -2
  34. package/build/esm/packages/utilities/build/esm/packages/utilities/src/feature_flag_utils.js +22 -0
  35. package/build/esm/packages/utilities/build/esm/packages/utilities/src/feature_flag_utils.js.map +1 -0
  36. package/build/esm/packages/utilities/build/esm/packages/utilities/src/json_utils.js +21 -0
  37. package/build/esm/packages/utilities/build/esm/packages/utilities/src/json_utils.js.map +1 -0
  38. package/package.json +2 -2
@@ -6,16 +6,23 @@ var tslib_es6 = require('../../../../../external/tslib/tslib.es6.js');
6
6
  var decorators = require('lit/decorators');
7
7
  var phoenix_light_lit_element = require('../../core/phoenix_light_lit_element/phoenix_light_lit_element.js');
8
8
  var phoenix_custom_element = require('../../core/decorators/phoenix_custom_element.js');
9
+ var behavior_subject = require('../../core/classes/behavior_subject/behavior_subject.js');
10
+ var context_provider_controller = require('../../core/context/context_provider_controller.js');
9
11
  var accordion_constants = require('./accordion_constants.js');
12
+ var feature_flag_utils = require('../../../../utilities/build/esm/packages/utilities/src/feature_flag_utils.js');
10
13
 
11
14
  exports.HAccordion = class HAccordion extends phoenix_light_lit_element.PhoenixLightLitElement {
12
15
  constructor() {
13
- super(...arguments);
16
+ super();
14
17
  this.disabled = false;
15
18
  this.mode = accordion_constants.ACCORDION_MODE.multi;
16
- }
17
- updated() {
18
- this.notify();
19
+ this._isDevAccordionOptimizationFlagEnabled = feature_flag_utils.FeatureFlagUtils.isEnabled('dev_accordion_optimization');
20
+ if (!this._isDevAccordionOptimizationFlagEnabled) {
21
+ this._accordionSubject = new behavior_subject.BehaviorSubject(this._getProps());
22
+ this._accordionContext = new context_provider_controller.ContextProviderController(this);
23
+ this._accordionContext.provide(accordion_constants.ACCORDION_CONTEXTS.accordionProps, this._accordionSubject);
24
+ this.setAttribute('role', 'none');
25
+ }
19
26
  }
20
27
  enable() {
21
28
  this.disabled = false;
@@ -23,8 +30,22 @@ exports.HAccordion = class HAccordion extends phoenix_light_lit_element.PhoenixL
23
30
  disable() {
24
31
  this.disabled = true;
25
32
  }
33
+ updated() {
34
+ this.notify();
35
+ }
26
36
  notify() {
27
- this.dispatchEvent(new Event(accordion_constants.ACCORDION_EVENTS.update));
37
+ if (this._isDevAccordionOptimizationFlagEnabled) {
38
+ this.dispatchEvent(new Event(accordion_constants.ACCORDION_EVENTS.update));
39
+ }
40
+ else {
41
+ this._accordionSubject.notify(this._getProps());
42
+ }
43
+ }
44
+ _getProps() {
45
+ return {
46
+ disabled: this.disabled,
47
+ mode: this.mode
48
+ };
28
49
  }
29
50
  };
30
51
  tslib_es6.__decorate([
@@ -36,6 +57,7 @@ tslib_es6.__decorate([
36
57
  tslib_es6.__metadata("design:type", String)
37
58
  ], exports.HAccordion.prototype, "mode", void 0);
38
59
  exports.HAccordion = tslib_es6.__decorate([
39
- phoenix_custom_element.phoenixCustomElement('h-accordion')
60
+ phoenix_custom_element.phoenixCustomElement('h-accordion'),
61
+ tslib_es6.__metadata("design:paramtypes", [])
40
62
  ], exports.HAccordion);
41
63
  //# sourceMappingURL=accordion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA,wBAAwB,4CAAgD;AACxE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
1
+ {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA,wBAAwB,4CAAgD;AACxE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
@@ -6,6 +6,10 @@ const ACCORDION_EVENTS = {
6
6
  toggle: 'toggle',
7
7
  update: 'updateAccordion'
8
8
  };
9
+ const ACCORDION_CONTEXTS = {
10
+ accordionProps: 'accordionPropsSubject',
11
+ accordionGroupProps: 'accordionGroupPropsSubject'
12
+ };
9
13
  const ACCORDION_CSS_CLASSES = {
10
14
  open: 'accordion__details_open'
11
15
  };
@@ -16,6 +20,7 @@ const ACCORDION_MODE = {
16
20
  const ACCORDION_ANIMATION_DURATION = 400;
17
21
 
18
22
  exports.ACCORDION_ANIMATION_DURATION = ACCORDION_ANIMATION_DURATION;
23
+ exports.ACCORDION_CONTEXTS = ACCORDION_CONTEXTS;
19
24
  exports.ACCORDION_CSS_CLASSES = ACCORDION_CSS_CLASSES;
20
25
  exports.ACCORDION_EVENTS = ACCORDION_EVENTS;
21
26
  exports.ACCORDION_MODE = ACCORDION_MODE;
@@ -1 +1 @@
1
- {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
1
+ {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
@@ -3,19 +3,160 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var tslib_es6 = require('../../../../../external/tslib/tslib.es6.js');
6
+ require('lit');
7
+ var decorators = require('lit/decorators');
6
8
  var phoenix_light_lit_element = require('../../core/phoenix_light_lit_element/phoenix_light_lit_element.js');
7
9
  var phoenix_custom_element = require('../../core/decorators/phoenix_custom_element.js');
10
+ var observer = require('../../core/classes/observer/observer.js');
11
+ var context_consumer_controller = require('../../core/context/context_consumer_controller.js');
12
+ var accordion_constants = require('./accordion_constants.js');
13
+ var feature_flag_utils = require('../../../../utilities/build/esm/packages/utilities/src/feature_flag_utils.js');
14
+ var transition_controller = require('../../controllers/transition_controller/transition_controller.js');
8
15
 
16
+ const RESIZE_DEBOUNCE_MS = 150;
17
+ const MUTATION_DEBOUNCE_MS = 100;
9
18
  exports.HAccordionContent = class HAccordionContent extends phoenix_light_lit_element.PhoenixLightLitElement {
10
19
  constructor() {
11
20
  super();
12
- this.slot = this.hasAttribute('slot') ? this.slot : 'content';
21
+ this.transitionName = 'accordion-toggle';
22
+ this._resizeDebounceTimer = null;
23
+ this._mutationDebounceTimer = null;
24
+ this._mutationObserver = null;
25
+ this._handleResize = () => {
26
+ if (this._resizeDebounceTimer !== null) {
27
+ window.cancelAnimationFrame(this._resizeDebounceTimer);
28
+ }
29
+ this._resizeDebounceTimer = window.requestAnimationFrame(() => {
30
+ setTimeout(() => {
31
+ this._setStylingOptions();
32
+ }, RESIZE_DEBOUNCE_MS);
33
+ });
34
+ };
35
+ this._setStylingOptions = () => {
36
+ requestAnimationFrame(() => {
37
+ const previousDisplay = this.style.display;
38
+ this.style.setProperty('display', 'block', 'important');
39
+ this.style.height = 'auto';
40
+ requestAnimationFrame(() => {
41
+ this._setOriginalHeightValue();
42
+ this.style.display = previousDisplay;
43
+ this.style.height = this.hidden ? '0px' : this._originalHeight;
44
+ });
45
+ });
46
+ };
47
+ this._handleMutation = () => {
48
+ if (this._mutationDebounceTimer !== null) {
49
+ window.clearTimeout(this._mutationDebounceTimer);
50
+ }
51
+ this._mutationDebounceTimer = window.setTimeout(() => {
52
+ requestAnimationFrame(() => {
53
+ this.style.height = 'auto';
54
+ requestAnimationFrame(() => {
55
+ this._setOriginalHeightValue();
56
+ if (this.hidden) {
57
+ this.style.height = '0px';
58
+ }
59
+ else {
60
+ this.style.height = this._originalHeight;
61
+ }
62
+ });
63
+ });
64
+ }, MUTATION_DEBOUNCE_MS);
65
+ };
66
+ this._setOriginalHeightValue = () => {
67
+ const newHeight = this.getBoundingClientRect().height;
68
+ if (newHeight !== 0 || this.children.length === 0) {
69
+ this._originalHeight = `${newHeight}px`;
70
+ }
71
+ };
72
+ this._expand = () => {
73
+ this._setHeight(this._originalHeight);
74
+ };
75
+ this._handleTransitionEnd = (e) => {
76
+ if (this._isDevAccordionOptimizationFlagEnabled)
77
+ return;
78
+ if (e.propertyName !== 'height' || e.target !== this) {
79
+ return;
80
+ }
81
+ if (!this.hidden && this.style.height !== '0px') {
82
+ this.style.height = 'auto';
83
+ }
84
+ };
85
+ this._collapse = () => {
86
+ const currentHeight = this.getBoundingClientRect().height;
87
+ this._setHeight(`${currentHeight}px`);
88
+ requestAnimationFrame(() => {
89
+ requestAnimationFrame(() => {
90
+ this._setHeight('0px');
91
+ });
92
+ });
93
+ };
94
+ this._isDevAccordionOptimizationFlagEnabled = feature_flag_utils.FeatureFlagUtils.isEnabled('dev_accordion_optimization');
95
+ if (this._isDevAccordionOptimizationFlagEnabled) {
96
+ this.slot = this.hasAttribute('slot') ? this.slot : 'content';
97
+ }
98
+ else {
99
+ this.setAttribute('role', 'region');
100
+ this._boundHandleTransitionEnd = this._handleTransitionEnd.bind(this);
101
+ }
13
102
  }
14
103
  connectedCallback() {
15
104
  super.connectedCallback();
16
- this.classList.add('accordion-content');
105
+ if (!this._isDevAccordionOptimizationFlagEnabled) {
106
+ this._contextConsumer = new context_consumer_controller.ContextConsumerController(this);
107
+ this._transitionController = new transition_controller.TransitionController(this, this.transitionName);
108
+ this._subscribeObserver();
109
+ window.addEventListener('resize', this._handleResize, { passive: true });
110
+ this.addEventListener('transitionend', this._boundHandleTransitionEnd);
111
+ }
112
+ if (this._isDevAccordionOptimizationFlagEnabled) {
113
+ this.classList.add('accordion-content');
114
+ }
115
+ }
116
+ firstUpdated(props) {
117
+ super.firstUpdated(props);
118
+ if (!this._isDevAccordionOptimizationFlagEnabled) {
119
+ this._setStylingOptions();
120
+ }
121
+ }
122
+ async _subscribeObserver() {
123
+ this._accordionGroupProps = await this._contextConsumer.consumeAsync(accordion_constants.ACCORDION_CONTEXTS.accordionGroupProps);
124
+ this._accordionGroupPropsObserver = new observer.Observer((accordionProps) => {
125
+ this._setAttributes(accordionProps);
126
+ accordionProps.opened ? this._transitionController.show(this._expand) : this._transitionController.hide(this._collapse);
127
+ });
128
+ this._accordionGroupProps.subscribe(this._accordionGroupPropsObserver);
129
+ this._mutationObserver = new MutationObserver(this._handleMutation);
130
+ this._mutationObserver.observe(this, { childList: true, subtree: true });
131
+ }
132
+ _setHeight(height) {
133
+ this.style.height = height;
134
+ }
135
+ _setAttributes({ regionId, controlsId }) {
136
+ this.setAttribute('id', controlsId);
137
+ this.setAttribute('labelledby', regionId);
138
+ }
139
+ disconnectedCallback() {
140
+ var _a, _b;
141
+ super.disconnectedCallback();
142
+ if (!this._isDevAccordionOptimizationFlagEnabled) {
143
+ (_a = this._accordionGroupProps) === null || _a === void 0 ? void 0 : _a.unsubscribe(this._accordionGroupPropsObserver);
144
+ (_b = this._mutationObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
145
+ window.removeEventListener('resize', this._handleResize);
146
+ this.removeEventListener('transitionend', this._boundHandleTransitionEnd);
147
+ if (this._resizeDebounceTimer !== null) {
148
+ window.cancelAnimationFrame(this._resizeDebounceTimer);
149
+ }
150
+ if (this._mutationDebounceTimer !== null) {
151
+ window.clearTimeout(this._mutationDebounceTimer);
152
+ }
153
+ }
17
154
  }
18
155
  };
156
+ tslib_es6.__decorate([
157
+ decorators.property(),
158
+ tslib_es6.__metadata("design:type", Object)
159
+ ], exports.HAccordionContent.prototype, "transitionName", void 0);
19
160
  exports.HAccordionContent = tslib_es6.__decorate([
20
161
  phoenix_custom_element.phoenixCustomElement('h-accordion-content'),
21
162
  tslib_es6.__metadata("design:paramtypes", [])
@@ -1 +1 @@
1
- {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA,wBAAwB,4CAAgD;AACxE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
1
+ {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA,wBAAwB,4CAAgD;AACxE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
@@ -7,15 +7,23 @@ var lit = require('lit');
7
7
  var decorators = require('lit/decorators');
8
8
  var phoenix_light_lit_element = require('../../core/phoenix_light_lit_element/phoenix_light_lit_element.js');
9
9
  var phoenix_custom_element = require('../../core/decorators/phoenix_custom_element.js');
10
+ var observer = require('../../core/classes/observer/observer.js');
11
+ var context_consumer_controller = require('../../core/context/context_consumer_controller.js');
12
+ var behavior_subject = require('../../core/classes/behavior_subject/behavior_subject.js');
13
+ var context_provider_controller = require('../../core/context/context_provider_controller.js');
10
14
  var v4 = require('../../../../../external/uuid/dist/esm-browser/v4.js');
11
15
  var accordion_constants = require('./accordion_constants.js');
16
+ var feature_flag_utils = require('../../../../utilities/build/esm/packages/utilities/src/feature_flag_utils.js');
12
17
  var ref = require('lit/directives/ref');
18
+ var when = require('lit/directives/when');
13
19
 
14
20
  exports.HAccordionGroup = class HAccordionGroup extends phoenix_light_lit_element.PhoenixLightLitElement {
15
21
  constructor() {
16
- super(...arguments);
22
+ super();
17
23
  this.opened = false;
18
24
  this._isDisabled = false;
25
+ this._regionId = typeof self.crypto.randomUUID === 'function' ? self.crypto.randomUUID() : (Math.random() + 1).toString(36).substring(3);
26
+ this._controlsId = typeof self.crypto.randomUUID === 'function' ? self.crypto.randomUUID() : (Math.random() + 1).toString(36).substring(3);
19
27
  this._mode = accordion_constants.ACCORDION_MODE.multi;
20
28
  this._$parentAccordion = null;
21
29
  this._detailsRef = ref.createRef();
@@ -40,83 +48,190 @@ exports.HAccordionGroup = class HAccordionGroup extends phoenix_light_lit_elemen
40
48
  $accordionGroup.hide();
41
49
  });
42
50
  };
51
+ this._accordionToggle = () => {
52
+ this.toggle();
53
+ };
43
54
  this._summaryClickHandler = (ev) => {
44
55
  ev.preventDefault();
45
56
  if (!this._isDisabled)
46
57
  this.toggle();
47
58
  };
59
+ this._isDevAccordionOptimizationFlagEnabled = feature_flag_utils.FeatureFlagUtils.isEnabled('dev_accordion_optimization');
60
+ if (!this._isDevAccordionOptimizationFlagEnabled) {
61
+ this._accordionGroupPropsSubject = new behavior_subject.BehaviorSubject(this._getProps());
62
+ this._accordionGroupContext = new context_provider_controller.ContextProviderController(this);
63
+ this._accordionGroupContext.provide(accordion_constants.ACCORDION_CONTEXTS.accordionGroupProps, this._accordionGroupPropsSubject);
64
+ this.setAttribute('role', 'none');
65
+ }
48
66
  }
49
67
  connectedCallback() {
50
68
  var _a;
51
69
  super.connectedCallback();
52
- this._$parentAccordion = this.closest('h-accordion');
53
- (_a = this._$parentAccordion) === null || _a === void 0 ? void 0 : _a.addEventListener(accordion_constants.ACCORDION_EVENTS.update, this._syncWithParentAccordion);
54
- this._syncWithParentAccordion();
70
+ if (this._isDevAccordionOptimizationFlagEnabled) {
71
+ this._$parentAccordion = this.closest('h-accordion');
72
+ (_a = this._$parentAccordion) === null || _a === void 0 ? void 0 : _a.addEventListener(accordion_constants.ACCORDION_EVENTS.update, this._syncWithParentAccordion);
73
+ this._syncWithParentAccordion();
74
+ }
75
+ else {
76
+ this._accordionContextConsumer = new context_consumer_controller.ContextConsumerController(this);
77
+ this._subscribeObserver();
78
+ this.addEventListener(accordion_constants.ACCORDION_EVENTS.toggle, this._accordionToggle);
79
+ }
55
80
  }
56
81
  firstUpdated(props) {
57
82
  super.firstUpdated(props);
58
- if (this.opened)
83
+ if (this.opened && this._isDevAccordionOptimizationFlagEnabled)
59
84
  this.show();
60
85
  }
86
+ async _subscribeObserver() {
87
+ this._accordionProps = await this._accordionContextConsumer.consumeAsync(accordion_constants.ACCORDION_CONTEXTS.accordionProps);
88
+ this._accordionPropsObserver = new observer.Observer((accordionProps) => {
89
+ this._mode = accordionProps.mode;
90
+ const hasAccordionBeenDisabled = accordionProps.disabled;
91
+ if (hasAccordionBeenDisabled) {
92
+ this.disable();
93
+ return;
94
+ }
95
+ const hasAccordionBeenEnabled = accordionProps.disabled === false;
96
+ if (hasAccordionBeenEnabled) {
97
+ this.enable();
98
+ return;
99
+ }
100
+ });
101
+ this._accordionProps.subscribe(this._accordionPropsObserver);
102
+ }
61
103
  disconnectedCallback() {
62
104
  var _a;
63
105
  super.disconnectedCallback();
64
- (_a = this._$parentAccordion) === null || _a === void 0 ? void 0 : _a.removeEventListener(accordion_constants.ACCORDION_EVENTS.update, this._syncWithParentAccordion);
65
- }
66
- _handleSingleModeConstraint() {
67
- if (this._mode === accordion_constants.ACCORDION_MODE.single) {
68
- this._hideOtherDetailsGroups();
106
+ if (this._isDevAccordionOptimizationFlagEnabled) {
107
+ (_a = this._$parentAccordion) === null || _a === void 0 ? void 0 : _a.removeEventListener(accordion_constants.ACCORDION_EVENTS.update, this._syncWithParentAccordion);
108
+ }
109
+ else {
110
+ this._accordionProps.unsubscribe(this._accordionPropsObserver);
111
+ this.removeEventListener(accordion_constants.ACCORDION_EVENTS.toggle, this._accordionToggle);
69
112
  }
70
- }
71
- toggle() {
72
- this._handleSingleModeConstraint();
73
- const $details = this._detailsRef.value;
74
- if (!$details)
75
- return;
76
- const isOpen = $details.hasAttribute('open');
77
- isOpen ? this.hide() : this.show();
78
113
  }
79
114
  show() {
80
- this._handleSingleModeConstraint();
81
- const $details = this._detailsRef.value;
82
- if (!$details)
83
- return;
84
- $details.setAttribute('open', '');
85
- requestAnimationFrame(() => {
86
- $details.classList.add(accordion_constants.ACCORDION_CSS_CLASSES.open);
87
- });
88
- this._dispatchToggleEvent($details, true);
115
+ if (this._isDevAccordionOptimizationFlagEnabled) {
116
+ this._handleSingleModeConstraint();
117
+ const $details = this._detailsRef.value;
118
+ if (!$details)
119
+ return;
120
+ $details.setAttribute('open', '');
121
+ requestAnimationFrame(() => {
122
+ $details.classList.add(accordion_constants.ACCORDION_CSS_CLASSES.open);
123
+ });
124
+ this._dispatchToggleEvent($details, true);
125
+ }
126
+ else {
127
+ if (this._mode === accordion_constants.ACCORDION_MODE.single)
128
+ this._closeOtherAccordionGroups();
129
+ this.opened = true;
130
+ }
89
131
  }
90
132
  hide() {
91
- const $details = this._detailsRef.value;
92
- if (!$details)
93
- return;
94
- $details.classList.remove(accordion_constants.ACCORDION_CSS_CLASSES.open);
95
- setTimeout(() => {
96
- $details.removeAttribute('open');
97
- }, accordion_constants.ACCORDION_ANIMATION_DURATION);
98
- this._dispatchToggleEvent($details, false);
133
+ if (this._isDevAccordionOptimizationFlagEnabled) {
134
+ const $details = this._detailsRef.value;
135
+ if (!$details)
136
+ return;
137
+ $details.classList.remove(accordion_constants.ACCORDION_CSS_CLASSES.open);
138
+ setTimeout(() => {
139
+ $details.removeAttribute('open');
140
+ }, accordion_constants.ACCORDION_ANIMATION_DURATION);
141
+ this._dispatchToggleEvent($details, false);
142
+ }
143
+ else {
144
+ this.opened = false;
145
+ }
99
146
  }
100
147
  _dispatchToggleEvent($details, open) {
101
148
  this.emitCustomEvent(accordion_constants.ACCORDION_EVENTS.toggle, {
102
149
  detail: { open, target: $details }
103
150
  });
104
151
  }
152
+ toggle() {
153
+ if (this._isDevAccordionOptimizationFlagEnabled) {
154
+ this._handleSingleModeConstraint();
155
+ const $details = this._detailsRef.value;
156
+ if (!$details)
157
+ return;
158
+ const isOpen = $details.hasAttribute('open');
159
+ isOpen ? this.hide() : this.show();
160
+ }
161
+ else {
162
+ if (this._mode === accordion_constants.ACCORDION_MODE.single)
163
+ this._closeOtherAccordionGroups();
164
+ this.opened = !this.opened;
165
+ }
166
+ }
167
+ _handleSingleModeConstraint() {
168
+ if (this._mode === accordion_constants.ACCORDION_MODE.single) {
169
+ this._hideOtherDetailsGroups();
170
+ }
171
+ }
105
172
  enable() {
106
- if (!this._isDisabled)
107
- return;
108
- this._isDisabled = false;
109
- this.hide();
173
+ if (this._isDevAccordionOptimizationFlagEnabled) {
174
+ if (!this._isDisabled)
175
+ return;
176
+ this._isDisabled = false;
177
+ this.hide();
178
+ }
179
+ else {
180
+ if (this._isDisabled) {
181
+ this.addEventListener(accordion_constants.ACCORDION_EVENTS.toggle, this._accordionToggle);
182
+ this.hide();
183
+ this._isDisabled = false;
184
+ }
185
+ }
110
186
  }
111
187
  disable() {
112
- if (this._isDisabled)
113
- return;
114
- this._isDisabled = true;
115
- this.show();
188
+ if (this._isDevAccordionOptimizationFlagEnabled) {
189
+ if (this._isDisabled)
190
+ return;
191
+ this._isDisabled = true;
192
+ this.show();
193
+ }
194
+ else {
195
+ if (!this._isDisabled) {
196
+ this.removeEventListener(accordion_constants.ACCORDION_EVENTS.toggle, this._accordionToggle);
197
+ this.show();
198
+ this._isDisabled = true;
199
+ }
200
+ }
201
+ }
202
+ _closeOtherAccordionGroups() {
203
+ if (!this._isDisabled) {
204
+ const $accordion = this.closest('h-accordion');
205
+ const $accordionGroups = [...$accordion.querySelectorAll('h-accordion-group')];
206
+ const $otherAccordionGroupsWithinAccordion = $accordionGroups.filter(($accordionGroup) => $accordionGroup !== this);
207
+ $otherAccordionGroupsWithinAccordion.forEach(($accordionGroup) => $accordionGroup.hide());
208
+ }
209
+ }
210
+ notify() {
211
+ if (!this._isDevAccordionOptimizationFlagEnabled) {
212
+ this._accordionGroupPropsSubject.notify(this._getProps());
213
+ }
214
+ }
215
+ updated(_changedProperties) {
216
+ if (!this._isDevAccordionOptimizationFlagEnabled) {
217
+ if (_changedProperties.has('opened') ||
218
+ _changedProperties.has('_isDisabled') ||
219
+ _changedProperties.has('_regionId') ||
220
+ _changedProperties.has('_controlsId')) {
221
+ this.notify();
222
+ }
223
+ }
224
+ }
225
+ _getProps() {
226
+ return {
227
+ opened: this.opened,
228
+ disabled: this._isDisabled,
229
+ regionId: this._regionId,
230
+ controlsId: this._controlsId
231
+ };
116
232
  }
117
- notify() { }
118
233
  render() {
119
- return lit.html `
234
+ return when.when(this._isDevAccordionOptimizationFlagEnabled, () => lit.html `
120
235
  <details
121
236
  ${ref.ref(this._detailsRef)}
122
237
  class="accordion__details ${this._isDisabled ? 'accordion__details_disabled' : ''}"
@@ -133,7 +248,7 @@ exports.HAccordionGroup = class HAccordionGroup extends phoenix_light_lit_elemen
133
248
 
134
249
  ${this.getSlot('content')}
135
250
  </details>
136
- `;
251
+ `);
137
252
  }
138
253
  };
139
254
  tslib_es6.__decorate([
@@ -144,11 +259,20 @@ tslib_es6.__decorate([
144
259
  decorators.state(),
145
260
  tslib_es6.__metadata("design:type", Object)
146
261
  ], exports.HAccordionGroup.prototype, "_isDisabled", void 0);
262
+ tslib_es6.__decorate([
263
+ decorators.state(),
264
+ tslib_es6.__metadata("design:type", Object)
265
+ ], exports.HAccordionGroup.prototype, "_regionId", void 0);
266
+ tslib_es6.__decorate([
267
+ decorators.state(),
268
+ tslib_es6.__metadata("design:type", Object)
269
+ ], exports.HAccordionGroup.prototype, "_controlsId", void 0);
147
270
  tslib_es6.__decorate([
148
271
  decorators.state(),
149
272
  tslib_es6.__metadata("design:type", String)
150
273
  ], exports.HAccordionGroup.prototype, "_mode", void 0);
151
274
  exports.HAccordionGroup = tslib_es6.__decorate([
152
- phoenix_custom_element.phoenixCustomElement('h-accordion-group')
275
+ phoenix_custom_element.phoenixCustomElement('h-accordion-group'),
276
+ tslib_es6.__metadata("design:paramtypes", [])
153
277
  ], exports.HAccordionGroup);
154
278
  //# sourceMappingURL=accordion_group.js.map
@@ -1 +1 @@
1
- {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA,wBAAwB,4CAAgD;AACxE;AACA;AACA;AACA;AACA,iBAAiB,qDAAyD;AAC1E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
1
+ {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA,wBAAwB,4CAAgD;AACxE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB,qDAAyD;AAC1E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
@@ -3,13 +3,62 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var tslib_es6 = require('../../../../../external/tslib/tslib.es6.js');
6
+ var utilities = require('@dreamcommerce/utilities');
6
7
  var phoenix_light_lit_element = require('../../core/phoenix_light_lit_element/phoenix_light_lit_element.js');
7
8
  var phoenix_custom_element = require('../../core/decorators/phoenix_custom_element.js');
9
+ var observer = require('../../core/classes/observer/observer.js');
10
+ var context_consumer_controller = require('../../core/context/context_consumer_controller.js');
11
+ var accordion_constants = require('./accordion_constants.js');
8
12
 
9
13
  exports.HAccordionToggler = class HAccordionToggler extends phoenix_light_lit_element.PhoenixLightLitElement {
10
14
  constructor() {
11
15
  super();
12
- this.slot = this.hasAttribute('slot') ? this.slot : 'toggler';
16
+ this._emitTogglerClickedWithKeyboard = (ev) => {
17
+ if (ev.key !== ' ' && ev.key !== 'Enter')
18
+ return;
19
+ if (this.getAttribute('aria-disabled') === 'true')
20
+ return;
21
+ this._emitTogglerClicked();
22
+ };
23
+ this._emitTogglerClicked = () => {
24
+ this.emitCustomEvent(accordion_constants.ACCORDION_EVENTS.toggle);
25
+ };
26
+ this._isDevAccordionOptimizationFlagEnabled = utilities.FeatureFlagUtils.isEnabled('dev_accordion_optimization');
27
+ if (this._isDevAccordionOptimizationFlagEnabled) {
28
+ this.slot = this.hasAttribute('slot') ? this.slot : 'toggler';
29
+ }
30
+ else {
31
+ this._contextConsumer = new context_consumer_controller.ContextConsumerController(this);
32
+ }
33
+ }
34
+ async connectedCallback() {
35
+ super.connectedCallback();
36
+ if (!this._isDevAccordionOptimizationFlagEnabled) {
37
+ this._accordionGroupProps = await this._contextConsumer.consumeAsync(accordion_constants.ACCORDION_CONTEXTS.accordionGroupProps);
38
+ this._accordionGroupPropsObserver = new observer.Observer((accordionProps) => this._setAttributes(accordionProps));
39
+ this._accordionGroupProps.subscribe(this._accordionGroupPropsObserver);
40
+ this.addEventListener('click', this._emitTogglerClicked);
41
+ this.addEventListener('keydown', this._emitTogglerClickedWithKeyboard);
42
+ }
43
+ }
44
+ _setAttributes({ regionId, opened, controlsId, disabled }) {
45
+ this.setAttribute('id', regionId);
46
+ this.setAttribute('aria-expanded', opened ? 'true' : 'false');
47
+ this.setAttribute('aria-controls', controlsId);
48
+ this.setAttribute('aria-disabled', disabled ? 'true' : 'false');
49
+ if (disabled) {
50
+ this.removeAttribute('role');
51
+ this.setAttribute('tabindex', '-1');
52
+ }
53
+ else {
54
+ this.setAttribute('role', 'button');
55
+ this.setAttribute('tabindex', '0');
56
+ }
57
+ }
58
+ disconnectedCallback() {
59
+ if (this._accordionGroupProps && !this._isDevAccordionOptimizationFlagEnabled) {
60
+ this._accordionGroupProps.unsubscribe(this._accordionGroupPropsObserver);
61
+ }
13
62
  }
14
63
  };
15
64
  exports.HAccordionToggler = tslib_es6.__decorate([
@@ -1 +1 @@
1
- {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA,wBAAwB,4CAAgD;AACxE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}
1
+ {"version":3,"file":null,"sources":[null],"sourcesContent":[null],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA,wBAAwB,4CAAgD;AACxE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;"}