@newlogic-digital/stimulus-components 1.3.0 → 1.4.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 +6 -6
- package/src/index.js +2 -2
- package/src/recaptcha/index.js +45 -0
- package/src/reveal/index.js +20 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newlogic-digital/stimulus-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"eslint": "eslint '**/*.js'",
|
|
@@ -10,17 +10,17 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@hotwired/stimulus": "^3.2.2",
|
|
12
12
|
"@newlogic-digital/utils-js": "^1.2.0",
|
|
13
|
-
"winduum-stimulus": "^2.0.
|
|
13
|
+
"winduum-stimulus": "^2.0.15"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@eslint/js": "^10.0.1",
|
|
17
17
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
18
|
-
"@googlemaps/js-api-loader": "^2.
|
|
18
|
+
"@googlemaps/js-api-loader": "^2.1.1",
|
|
19
19
|
"@newlogic-digital/cookieconsent-js": "^1.1.1",
|
|
20
20
|
"@types/grecaptcha": "^3.0.9",
|
|
21
|
-
"eslint": "^10.
|
|
22
|
-
"globals": "^17.
|
|
23
|
-
"winduum": "^2.
|
|
21
|
+
"eslint": "^10.11.0",
|
|
22
|
+
"globals": "^17.12.0",
|
|
23
|
+
"winduum": "^2.2.28"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
26
|
"src"
|
package/src/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ControlSelect } from './control-select/index.js'
|
|
|
2
2
|
import { CookieConsentDialog, CookieConsentForm } from './cookieconsent/index.js'
|
|
3
3
|
import { GoogleMaps } from './google-maps/index.js'
|
|
4
4
|
import { Popover } from './popover/index.js'
|
|
5
|
-
import { ReCaptcha } from './recaptcha/index.js'
|
|
5
|
+
import { ReCaptcha, ReCaptchaLazy } from './recaptcha/index.js'
|
|
6
6
|
import { Reveal } from './reveal/index.js'
|
|
7
7
|
|
|
8
|
-
export { ControlSelect, CookieConsentDialog, CookieConsentForm, GoogleMaps, Popover, ReCaptcha, Reveal }
|
|
8
|
+
export { ControlSelect, CookieConsentDialog, CookieConsentForm, GoogleMaps, Popover, ReCaptcha, ReCaptchaLazy, Reveal }
|
package/src/recaptcha/index.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus'
|
|
2
2
|
import { importScript } from '@newlogic-digital/utils-js'
|
|
3
3
|
|
|
4
|
+
export const defineIntersectionObserver = (controller, options = {}) => {
|
|
5
|
+
const observer = new IntersectionObserver((entries) => {
|
|
6
|
+
for (const entry of entries) controller.intersectCallback?.(entry)
|
|
7
|
+
}, options)
|
|
8
|
+
|
|
9
|
+
observer.observe(controller.element)
|
|
10
|
+
|
|
11
|
+
return observer
|
|
12
|
+
}
|
|
13
|
+
|
|
4
14
|
export class ReCaptcha extends Controller {
|
|
5
15
|
static values = {
|
|
6
16
|
api: String,
|
|
@@ -23,3 +33,38 @@ export class ReCaptcha extends Controller {
|
|
|
23
33
|
})
|
|
24
34
|
}
|
|
25
35
|
}
|
|
36
|
+
|
|
37
|
+
export class ReCaptchaLazy extends Controller {
|
|
38
|
+
static values = {
|
|
39
|
+
api: String,
|
|
40
|
+
action: String,
|
|
41
|
+
url: {
|
|
42
|
+
default: 'https://www.google.com/recaptcha/enterprise.js?render={apikey}',
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
connect() {
|
|
47
|
+
this.observer = defineIntersectionObserver(this, { threshold: 0.1 })
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
disconnect() {
|
|
51
|
+
this.observer.disconnect()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
intersectCallback(entry) {
|
|
55
|
+
if (!entry.isIntersecting) return
|
|
56
|
+
|
|
57
|
+
this.observer.disconnect()
|
|
58
|
+
|
|
59
|
+
importScript(this.urlValue.replace('{apikey}', this.apiValue))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
execute(event) {
|
|
63
|
+
if (event?.detail?.recaptchaExecuted) return
|
|
64
|
+
|
|
65
|
+
window.grecaptcha.enterprise.ready(async () => {
|
|
66
|
+
this.element.gtoken.value = await window.grecaptcha.enterprise.execute(this.apiValue, { action: this.actionValue ?? 'form' })
|
|
67
|
+
this.element.dispatchEvent(new CustomEvent('submit', { cancelable: true, detail: { recaptchaExecuted: true } }))
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
}
|
package/src/reveal/index.js
CHANGED
|
@@ -4,19 +4,37 @@ import { dataset } from '@newlogic-digital/utils-js'
|
|
|
4
4
|
export class Reveal extends Controller {
|
|
5
5
|
static targets = ['item']
|
|
6
6
|
|
|
7
|
+
static values = {
|
|
8
|
+
threshold: {
|
|
9
|
+
type: Number,
|
|
10
|
+
default: 0.1,
|
|
11
|
+
},
|
|
12
|
+
intersectionRatio: {
|
|
13
|
+
type: Number,
|
|
14
|
+
default: 0.1,
|
|
15
|
+
},
|
|
16
|
+
clear: {
|
|
17
|
+
type: Boolean,
|
|
18
|
+
default: false,
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
|
|
7
22
|
intersectionObserver() {
|
|
8
23
|
this.observer = new IntersectionObserver((entries) => {
|
|
9
24
|
entries.forEach((entry) => {
|
|
10
|
-
if (entry.intersectionRatio >
|
|
25
|
+
if (entry.intersectionRatio > this.intersectionRatio && !entry.target.hasAttribute('data-in')) {
|
|
11
26
|
entry.target.setAttribute('data-in', '')
|
|
12
27
|
|
|
13
28
|
if (entry.target.dataset.lazyController) {
|
|
14
29
|
dataset(entry.target, 'controller').add(entry.target.dataset.lazyController)
|
|
15
30
|
}
|
|
16
31
|
}
|
|
32
|
+
else if (this.clearValue) {
|
|
33
|
+
entry.target.removeAttribute('data-in')
|
|
34
|
+
}
|
|
17
35
|
})
|
|
18
36
|
}, {
|
|
19
|
-
threshold:
|
|
37
|
+
threshold: this.thresholdValue,
|
|
20
38
|
})
|
|
21
39
|
}
|
|
22
40
|
|