ariadne_view_components 0.0.52-arm64-darwin → 0.0.54-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,6 +39,9 @@ export default class SyncedBooleanAttributesController<T> extends OutletManagerC
39
39
  getElementsToSync(): Array<Element> | null | undefined;
40
40
  connect(): void;
41
41
  updateAttributesForElement(element: Element, value: boolean): void;
42
+ getSyncedAttrsForElement(element: Element): string[] | null;
43
+ getAntiAttrsForElement(element: Element): string[] | null;
44
+ getParsedAttributeForElement<T>(element: Element, attribute: string): T | null;
42
45
  syncElementAttributes(): void;
43
46
  validateAttrChange(dispatchEvent: TStimulusDispatchEvent<TSyncAttrDetail>): void;
44
47
  doesElementHaveOnAttrs(element: Element): boolean;
@@ -32,12 +32,14 @@ class OptionsController extends SyncedBooleanAttributesController {
32
32
  }
33
33
  optionTargetConnected(element) {
34
34
  const key = __classPrivateFieldGet(this, _OptionsController_instances, "m", _OptionsController_getElementKey).call(this, element);
35
- if (this.doesElementHaveOnAttrs(element)) {
35
+ const isActive = this.activeOptionsValue[key] || this.doesElementHaveOnAttrs(element);
36
+ if (isActive) {
36
37
  __classPrivateFieldGet(this, _OptionsController_instances, "m", _OptionsController_activateKey).call(this, key);
37
38
  }
38
39
  else {
39
40
  __classPrivateFieldGet(this, _OptionsController_instances, "m", _OptionsController_deactivateKey).call(this, key);
40
41
  }
42
+ this.updateAttributesForElement(element, isActive);
41
43
  }
42
44
  getValueForElement(element) {
43
45
  var _a;
@@ -53,11 +53,14 @@ export default class OptionsController
53
53
 
54
54
  optionTargetConnected(element: Element) {
55
55
  const key = this.#getElementKey(element)
56
- if (this.doesElementHaveOnAttrs(element)) {
56
+ const isActive = this.activeOptionsValue[key] || this.doesElementHaveOnAttrs(element)
57
+ if (isActive) {
57
58
  this.#activateKey(key)
58
59
  } else {
59
60
  this.#deactivateKey(key)
60
61
  }
62
+
63
+ this.updateAttributesForElement(element, isActive)
61
64
  }
62
65
 
63
66
  #shouldChangeState(isCurrentlyActive: boolean, wasSelected: boolean) {
@@ -39,6 +39,9 @@ export default class SyncedBooleanAttributesController<T> extends OutletManagerC
39
39
  getElementsToSync(): Array<Element> | null | undefined;
40
40
  connect(): void;
41
41
  updateAttributesForElement(element: Element, value: boolean): void;
42
+ getSyncedAttrsForElement(element: Element): string[] | null;
43
+ getAntiAttrsForElement(element: Element): string[] | null;
44
+ getParsedAttributeForElement<T>(element: Element, attribute: string): T | null;
42
45
  syncElementAttributes(): void;
43
46
  validateAttrChange(dispatchEvent: TStimulusDispatchEvent<TSyncAttrDetail>): void;
44
47
  doesElementHaveOnAttrs(element: Element): boolean;
@@ -61,11 +61,45 @@ class SyncedBooleanAttributesController extends OutletManagerController {
61
61
  updateAttributesForElement(element, value) {
62
62
  // This is how you should update any synced or anti-synced attrs on your elements
63
63
  // Do not do it manually unless you are very sure of what you're doing
64
+ const syncedAttrs = this.getSyncedAttrsForElement(element);
65
+ if (syncedAttrs === null || syncedAttrs === void 0 ? void 0 : syncedAttrs.length) {
66
+ __classPrivateFieldGet(this, _SyncedBooleanAttributesController_instances, "m", _SyncedBooleanAttributesController_setAttrs).call(this, element, syncedAttrs, value);
67
+ }
68
+ const antiAttrs = this.getAntiAttrsForElement(element);
69
+ if (antiAttrs === null || antiAttrs === void 0 ? void 0 : antiAttrs.length) {
70
+ __classPrivateFieldGet(this, _SyncedBooleanAttributesController_instances, "m", _SyncedBooleanAttributesController_setAttrs).call(this, element, antiAttrs, !value);
71
+ }
72
+ }
73
+ getSyncedAttrsForElement(element) {
74
+ const parsedAttrs = this.getParsedAttributeForElement(element, 'data-options-synced-attrs-value');
75
+ if (parsedAttrs) {
76
+ return parsedAttrs;
77
+ }
64
78
  if (this.hasSyncedAttrsValue) {
65
- __classPrivateFieldGet(this, _SyncedBooleanAttributesController_instances, "m", _SyncedBooleanAttributesController_setAttrs).call(this, element, this.syncedAttrsValue, value);
79
+ return this.syncedAttrsValue;
80
+ }
81
+ return null;
82
+ }
83
+ getAntiAttrsForElement(element) {
84
+ const parsedAttrs = this.getParsedAttributeForElement(element, 'data-options-anti-attrs-value');
85
+ if (parsedAttrs) {
86
+ return parsedAttrs;
66
87
  }
67
88
  if (this.hasAntiAttrsValue) {
68
- __classPrivateFieldGet(this, _SyncedBooleanAttributesController_instances, "m", _SyncedBooleanAttributesController_setAttrs).call(this, element, this.antiAttrsValue, !value);
89
+ return this.antiAttrsValue;
90
+ }
91
+ return null;
92
+ }
93
+ getParsedAttributeForElement(element, attribute) {
94
+ const attr = element.getAttribute(attribute);
95
+ try {
96
+ if (attr === null) {
97
+ throw new Error('Bad attr');
98
+ }
99
+ return JSON.parse(attr);
100
+ }
101
+ catch (err) {
102
+ return null;
69
103
  }
70
104
  }
71
105
  syncElementAttributes() {
@@ -93,12 +93,53 @@ export default class SyncedBooleanAttributesController<T> extends OutletManagerC
93
93
  updateAttributesForElement(element: Element, value: boolean) {
94
94
  // This is how you should update any synced or anti-synced attrs on your elements
95
95
  // Do not do it manually unless you are very sure of what you're doing
96
+ const syncedAttrs = this.getSyncedAttrsForElement(element)
97
+ if (syncedAttrs?.length) {
98
+ this.#setAttrs(element, syncedAttrs, value)
99
+ }
100
+
101
+ const antiAttrs = this.getAntiAttrsForElement(element)
102
+ if (antiAttrs?.length) {
103
+ this.#setAttrs(element, antiAttrs, !value)
104
+ }
105
+ }
106
+
107
+ getSyncedAttrsForElement(element: Element) {
108
+ const parsedAttrs = this.getParsedAttributeForElement<Array<string>>(element, 'data-options-synced-attrs-value')
109
+ if (parsedAttrs) {
110
+ return parsedAttrs
111
+ }
112
+
96
113
  if (this.hasSyncedAttrsValue) {
97
- this.#setAttrs(element, this.syncedAttrsValue, value)
114
+ return this.syncedAttrsValue
115
+ }
116
+
117
+ return null
118
+ }
119
+
120
+ getAntiAttrsForElement(element: Element) {
121
+ const parsedAttrs = this.getParsedAttributeForElement<Array<string>>(element, 'data-options-anti-attrs-value')
122
+ if (parsedAttrs) {
123
+ return parsedAttrs
98
124
  }
99
125
 
100
126
  if (this.hasAntiAttrsValue) {
101
- this.#setAttrs(element, this.antiAttrsValue, !value)
127
+ return this.antiAttrsValue
128
+ }
129
+
130
+ return null
131
+ }
132
+
133
+ getParsedAttributeForElement<T>(element: Element, attribute: string) {
134
+ const attr = element.getAttribute(attribute)
135
+ try {
136
+ if (attr === null) {
137
+ throw new Error('Bad attr')
138
+ }
139
+
140
+ return JSON.parse(attr) as T
141
+ } catch (err) {
142
+ return null
102
143
  }
103
144
  }
104
145
 
@@ -3,6 +3,6 @@
3
3
  # :nocov:
4
4
  module Ariadne
5
5
  module ViewComponents
6
- VERSION = "0.0.52"
6
+ VERSION = "0.0.54"
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ariadne_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.52
4
+ version: 0.0.54
5
5
  platform: arm64-darwin
6
6
  authors:
7
7
  - Garen J. Torikian
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-07 00:00:00.000000000 Z
11
+ date: 2023-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tailwind_merge
@@ -342,7 +342,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
342
342
  - !ruby/object:Gem::Version
343
343
  version: '0'
344
344
  requirements: []
345
- rubygems_version: 3.4.15
345
+ rubygems_version: 3.4.16
346
346
  signing_key:
347
347
  specification_version: 4
348
348
  summary: ViewComponents for the Ariadne Design System