@newlogic-digital/stimulus-components 1.3.0 → 1.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newlogic-digital/stimulus-components",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
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"
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.0.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.1.0",
22
- "globals": "^17.4.0",
23
- "winduum": "^2.1.0"
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
@@ -1,8 +1,9 @@
1
1
  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
+ import { Paginator } from './paginator/index.js'
4
5
  import { Popover } from './popover/index.js'
5
- import { ReCaptcha } from './recaptcha/index.js'
6
+ import { ReCaptcha, ReCaptchaLazy } from './recaptcha/index.js'
6
7
  import { Reveal } from './reveal/index.js'
7
8
 
8
- export { ControlSelect, CookieConsentDialog, CookieConsentForm, GoogleMaps, Popover, ReCaptcha, Reveal }
9
+ export { ControlSelect, CookieConsentDialog, CookieConsentForm, GoogleMaps, Paginator, Popover, ReCaptcha, ReCaptchaLazy, Reveal }
@@ -0,0 +1,17 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+
3
+ export class Paginator extends Controller {
4
+ static targets = ['append', 'scroll']
5
+
6
+ scroll() {
7
+ this.scrollTarget.scrollIntoView({ behavior: 'smooth', block: 'start' })
8
+ }
9
+
10
+ addSnippetAppend() {
11
+ this.appendTarget.setAttribute('data-naja-snippet-append', '')
12
+ }
13
+
14
+ removeSnippetAppend() {
15
+ this.appendTarget.removeAttribute('data-naja-snippet-append')
16
+ }
17
+ }
@@ -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
+ }
@@ -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 > 0.1 && !entry.target.hasAttribute('data-in')) {
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: 0.1,
37
+ threshold: this.thresholdValue,
20
38
  })
21
39
  }
22
40