@newlogic-digital/stimulus-components 1.2.0 → 1.3.0
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.
- package/package.json +9 -6
- package/src/control-select/index.js +18 -18
- package/src/cookieconsent/index.js +64 -63
- package/src/google-maps/index.js +49 -0
- package/src/index.js +2 -1
- package/src/popover/index.js +16 -15
- package/src/recaptcha/index.js +17 -17
- package/src/reveal/index.js +22 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newlogic-digital/stimulus-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"eslint": "eslint '**/*.js'",
|
|
@@ -9,14 +9,17 @@
|
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@hotwired/stimulus": "^3.2.2",
|
|
12
|
-
"@newlogic-digital/utils-js": "^1.
|
|
13
|
-
"winduum-stimulus": "^2.0.
|
|
12
|
+
"@newlogic-digital/utils-js": "^1.2.0",
|
|
13
|
+
"winduum-stimulus": "^2.0.13"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@
|
|
16
|
+
"@eslint/js": "^10.0.1",
|
|
17
|
+
"@stylistic/eslint-plugin": "^5.10.0",
|
|
18
|
+
"@googlemaps/js-api-loader": "^2.0.2",
|
|
19
|
+
"@newlogic-digital/cookieconsent-js": "^1.1.1",
|
|
17
20
|
"@types/grecaptcha": "^3.0.9",
|
|
18
|
-
"eslint": "^
|
|
19
|
-
"
|
|
21
|
+
"eslint": "^10.1.0",
|
|
22
|
+
"globals": "^17.4.0",
|
|
20
23
|
"winduum": "^2.1.0"
|
|
21
24
|
},
|
|
22
25
|
"files": [
|
|
@@ -2,27 +2,27 @@ import { Controller } from '@hotwired/stimulus'
|
|
|
2
2
|
import { dataset, dispatchCustomEvent } from '@newlogic-digital/utils-js'
|
|
3
3
|
|
|
4
4
|
export class ControlSelect extends Controller {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
connect() {
|
|
6
|
+
this.select = this.element.querySelector('select')
|
|
7
|
+
this.options = this.element.querySelectorAll('[data-option]')
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
dataset(this.select, 'action').add('change->x-control-select#active')
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
this.options.forEach((option) => {
|
|
12
|
+
if (option.dataset.disabled) return
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
dataset(option, 'action').add('click->x-control-select#choose')
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
choose({ currentTarget }) {
|
|
19
|
+
this.select.value = currentTarget.dataset.option
|
|
20
|
+
dispatchCustomEvent(this.select)
|
|
21
|
+
document.activeElement.blur()
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
active() {
|
|
25
|
+
this.options.forEach(option => option.removeAttribute('data-active'))
|
|
26
|
+
this.element.querySelector(`[data-option="${this.select.value}"]`).setAttribute('data-active', '')
|
|
27
|
+
}
|
|
28
28
|
}
|
|
@@ -2,83 +2,84 @@ import { Controller } from '@hotwired/stimulus'
|
|
|
2
2
|
import { setCookieConsent, initCookieConsent } from '@newlogic-digital/cookieconsent-js'
|
|
3
3
|
|
|
4
4
|
export class CookieConsentCommon extends Controller {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
cookieConsentItemKey = 'cookieconsent-js'
|
|
6
|
+
cookieConsentExpireItemKey = 'cookieconsent-js-expire'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
getCookieConsentItem() {
|
|
9
|
+
return localStorage.getItem(this.cookieConsentItemKey)
|
|
10
|
+
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
getCookieConsentExpireItem() {
|
|
13
|
+
return localStorage.getItem(this.cookieConsentExpireItemKey)
|
|
14
|
+
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export class CookieConsentDialog extends CookieConsentCommon {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (document.querySelector('.x-cookieconsent-form')) {
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (!this.getCookieConsentItem() || parseInt(this.getCookieConsentExpireItem()) < Date.now()) {
|
|
26
|
-
setTimeout(async () => {
|
|
27
|
-
const { showDialog } = await import('winduum/src/components/dialog/index.js')
|
|
28
|
-
|
|
29
|
-
await showDialog(this.element, { closable: false })
|
|
30
|
-
}, 1500)
|
|
31
|
-
} else {
|
|
32
|
-
this.element.remove()
|
|
33
|
-
}
|
|
34
|
-
}
|
|
18
|
+
async connect() {
|
|
19
|
+
initCookieConsent(document, this.getCookieConsentItem() ?? [])
|
|
35
20
|
|
|
36
|
-
|
|
37
|
-
|
|
21
|
+
if (document.querySelector('.x-cookieconsent-form')) {
|
|
22
|
+
return
|
|
38
23
|
}
|
|
39
24
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
async hide(type) {
|
|
45
|
-
const { closeDialog } = await import('winduum/src/components/dialog/index.js')
|
|
25
|
+
if (!this.getCookieConsentItem() || parseInt(this.getCookieConsentExpireItem()) < Date.now()) {
|
|
26
|
+
setTimeout(async () => {
|
|
27
|
+
const { showDialog } = await import('winduum/src/components/dialog/index.js')
|
|
46
28
|
|
|
47
|
-
await
|
|
48
|
-
|
|
49
|
-
await closeDialog(this.element, { remove: true })
|
|
29
|
+
await showDialog(this.element, { closable: false })
|
|
30
|
+
}, 1500)
|
|
50
31
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
export class CookieConsentForm extends CookieConsentCommon {
|
|
54
|
-
connect() {
|
|
55
|
-
document.querySelector('.x-cookieconsent-dialog')?.close()
|
|
56
|
-
|
|
57
|
-
this.element.querySelectorAll('input:not([disabled])').forEach((input) => {
|
|
58
|
-
input.checked = false
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
JSON.parse(this.getCookieConsentItem())?.forEach((type) => {
|
|
62
|
-
if (this.element.querySelector(`input[value="${type}"]`) !== null) {
|
|
63
|
-
this.element.querySelector(`input[value="${type}"]`).checked = true
|
|
64
|
-
}
|
|
65
|
-
})
|
|
32
|
+
else {
|
|
33
|
+
this.element.remove()
|
|
66
34
|
}
|
|
35
|
+
}
|
|
67
36
|
|
|
68
|
-
|
|
69
|
-
|
|
37
|
+
async approve() {
|
|
38
|
+
await this.hide(['performance', 'marketing'])
|
|
39
|
+
}
|
|
70
40
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
41
|
+
async decline() {
|
|
42
|
+
await this.hide([])
|
|
43
|
+
}
|
|
74
44
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
45
|
+
async hide(type) {
|
|
46
|
+
const { closeDialog } = await import('winduum/src/components/dialog/index.js')
|
|
78
47
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
48
|
+
await setCookieConsent(type)
|
|
49
|
+
initCookieConsent(document, type)
|
|
50
|
+
await closeDialog(this.element, { remove: true })
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class CookieConsentForm extends CookieConsentCommon {
|
|
55
|
+
connect() {
|
|
56
|
+
document.querySelector('.x-cookieconsent-dialog')?.close()
|
|
57
|
+
|
|
58
|
+
this.element.querySelectorAll('input:not([disabled])').forEach((input) => {
|
|
59
|
+
input.checked = false
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
JSON.parse(this.getCookieConsentItem())?.forEach((type) => {
|
|
63
|
+
if (this.element.querySelector(`input[value="${type}"]`) !== null) {
|
|
64
|
+
this.element.querySelector(`input[value="${type}"]`).checked = true
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async update() {
|
|
70
|
+
const type = []
|
|
71
|
+
|
|
72
|
+
this.element.querySelectorAll('input:not([disabled])').forEach((input) => {
|
|
73
|
+
input.checked && type.push(input.value)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
await setCookieConsent(type)
|
|
77
|
+
location.reload()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
disconnect() {
|
|
81
|
+
if ((!this.getCookieConsentItem() || parseInt(this.getCookieConsentExpireItem()) < Date.now())) {
|
|
82
|
+
document.querySelector('.x-cookieconsent-dialog')?.showModal()
|
|
83
83
|
}
|
|
84
|
+
}
|
|
84
85
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus'
|
|
2
|
+
import { getId } from '@newlogic-digital/utils-js'
|
|
3
|
+
|
|
4
|
+
export class GoogleMaps extends Controller {
|
|
5
|
+
static targets = ['map']
|
|
6
|
+
|
|
7
|
+
static values = {
|
|
8
|
+
options: Object,
|
|
9
|
+
key: String,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
markerContent = `<svg class="size-16 text-accent"><use href="#heroicons-solid/map-pin"></use></svg>`
|
|
13
|
+
|
|
14
|
+
async connect() {
|
|
15
|
+
const { setOptions, importLibrary } = await import('@googlemaps/js-api-loader')
|
|
16
|
+
|
|
17
|
+
setOptions({
|
|
18
|
+
key: this.keyValue,
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const { Map } = await importLibrary('maps')
|
|
22
|
+
|
|
23
|
+
this.map = new Map(this.mapTarget, {
|
|
24
|
+
zoom: 13,
|
|
25
|
+
mapId: getId(),
|
|
26
|
+
mapTypeControl: false,
|
|
27
|
+
streetViewControl: false,
|
|
28
|
+
...this.optionsValue,
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
this.dispatch('connect')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async renderMarker() {
|
|
35
|
+
if (this.optionsValue.center?.lat == null || this.optionsValue.center?.lng == null) {
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const { importLibrary } = await import('@googlemaps/js-api-loader')
|
|
40
|
+
const { AdvancedMarkerElement } = await importLibrary('marker')
|
|
41
|
+
const content = new DOMParser().parseFromString(this.markerContent, 'text/html').body.firstChild
|
|
42
|
+
|
|
43
|
+
this.marker = new AdvancedMarkerElement({
|
|
44
|
+
map: this.map,
|
|
45
|
+
position: this.optionsValue.center,
|
|
46
|
+
content,
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ControlSelect } from './control-select/index.js'
|
|
2
2
|
import { CookieConsentDialog, CookieConsentForm } from './cookieconsent/index.js'
|
|
3
|
+
import { GoogleMaps } from './google-maps/index.js'
|
|
3
4
|
import { Popover } from './popover/index.js'
|
|
4
5
|
import { ReCaptcha } from './recaptcha/index.js'
|
|
5
6
|
import { Reveal } from './reveal/index.js'
|
|
6
7
|
|
|
7
|
-
export { ControlSelect, CookieConsentDialog, CookieConsentForm, Popover, ReCaptcha, Reveal }
|
|
8
|
+
export { ControlSelect, CookieConsentDialog, CookieConsentForm, GoogleMaps, Popover, ReCaptcha, Reveal }
|
package/src/popover/index.js
CHANGED
|
@@ -2,23 +2,24 @@ import { Popover as PopoverController } from 'winduum-stimulus/components/popove
|
|
|
2
2
|
import { animationsFinished } from 'winduum/src/common.js'
|
|
3
3
|
|
|
4
4
|
export class Popover extends PopoverController {
|
|
5
|
-
|
|
5
|
+
static targets = ['content', 'autocomplete']
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
minAutocompleteLength = 2
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} else {
|
|
15
|
-
currentTarget.ariaExpanded = 'true'
|
|
16
|
-
}
|
|
9
|
+
async autocomplete({ currentTarget }) {
|
|
10
|
+
if (currentTarget.value.length < this.minAutocompleteLength) {
|
|
11
|
+
currentTarget.ariaExpanded = 'false'
|
|
12
|
+
await animationsFinished(this.contentTarget)
|
|
13
|
+
this.contentTarget.replaceChildren()
|
|
17
14
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.autocompleteTarget.setAttribute('aria-activedescendant', currentTarget.id)
|
|
21
|
-
this.autocompleteTarget.value = currentTarget.textContent.trim()
|
|
22
|
-
currentTarget.blur()
|
|
15
|
+
else {
|
|
16
|
+
currentTarget.ariaExpanded = 'true'
|
|
23
17
|
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
selectDescendant({ currentTarget }) {
|
|
21
|
+
this.autocompleteTarget.setAttribute('aria-activedescendant', currentTarget.id)
|
|
22
|
+
this.autocompleteTarget.value = currentTarget.textContent.trim()
|
|
23
|
+
currentTarget.blur()
|
|
24
|
+
}
|
|
24
25
|
}
|
package/src/recaptcha/index.js
CHANGED
|
@@ -2,24 +2,24 @@ import { Controller } from '@hotwired/stimulus'
|
|
|
2
2
|
import { importScript } from '@newlogic-digital/utils-js'
|
|
3
3
|
|
|
4
4
|
export class ReCaptcha extends Controller {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
static values = {
|
|
6
|
+
api: String,
|
|
7
|
+
action: String,
|
|
8
|
+
url: {
|
|
9
|
+
default: 'https://www.google.com/recaptcha/enterprise.js?render={apikey}',
|
|
10
|
+
},
|
|
11
|
+
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
connect() {
|
|
14
|
+
importScript(this.urlValue.replace('{apikey}', this.apiValue))
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
execute(event) {
|
|
18
|
+
if (event?.detail?.recaptchaExecuted) return
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
window.grecaptcha.enterprise.ready(async () => {
|
|
21
|
+
this.element.gtoken.value = await window.grecaptcha.enterprise.execute(this.apiValue, { action: this.actionValue ?? 'form' })
|
|
22
|
+
this.element.dispatchEvent(new CustomEvent('submit', { cancelable: true, detail: { recaptchaExecuted: true } }))
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
25
|
}
|
package/src/reveal/index.js
CHANGED
|
@@ -2,31 +2,31 @@ import { Controller } from '@hotwired/stimulus'
|
|
|
2
2
|
import { dataset } from '@newlogic-digital/utils-js'
|
|
3
3
|
|
|
4
4
|
export class Reveal extends Controller {
|
|
5
|
-
|
|
5
|
+
static targets = ['item']
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
intersectionObserver() {
|
|
8
|
+
this.observer = new IntersectionObserver((entries) => {
|
|
9
|
+
entries.forEach((entry) => {
|
|
10
|
+
if (entry.intersectionRatio > 0.1 && !entry.target.hasAttribute('data-in')) {
|
|
11
|
+
entry.target.setAttribute('data-in', '')
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
if (entry.target.dataset.lazyController) {
|
|
14
|
+
dataset(entry.target, 'controller').add(entry.target.dataset.lazyController)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
}, {
|
|
19
|
+
threshold: 0.1,
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
itemTargetConnected(element) {
|
|
24
|
+
if (!this.observer) this.intersectionObserver()
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
this.observer?.observe(element)
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
itemTargetDisconnected(element) {
|
|
30
|
+
this.observer?.unobserve(element)
|
|
31
|
+
}
|
|
32
32
|
}
|