@newlogic-digital/ui 3.5.0 → 3.7.5

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 (138) hide show
  1. package/README.md +11 -1
  2. package/package.json +29 -22
  3. package/src/data/main.json +23 -8
  4. package/src/emails/styles/main/+.css +3 -0
  5. package/src/emails/styles/main/Base/+.css +2 -0
  6. package/src/emails/styles/main/Base/config.css +22 -0
  7. package/src/emails/styles/main/Components/+.css +1 -0
  8. package/src/emails/styles/main/Components/Card.css +12 -0
  9. package/src/emails/styles/main/Ui/+.css +3 -0
  10. package/src/emails/styles/main/Ui/Btn.css +78 -0
  11. package/src/emails/styles/main/Ui/Heading.css +8 -0
  12. package/src/emails/styles/main/Ui/Text.css +12 -0
  13. package/src/emails/styles/main.css +92 -0
  14. package/src/emails/templates.test/Layout.latte +16 -4
  15. package/src/emails/templates.test/Sections/Footer.latte +22 -0
  16. package/src/emails/templates.test/Sections/Header.latte +37 -0
  17. package/src/emails/templates.test/Sections/Text.latte +24 -0
  18. package/src/icons.svg +28 -28
  19. package/src/scripts/Components/+.js +2 -1
  20. package/src/scripts/Components/Drawer.js +60 -0
  21. package/src/scripts/Components/Popover.js +65 -0
  22. package/src/scripts/Layout/+.js +0 -1
  23. package/src/scripts/Layout/Header.js +14 -26
  24. package/src/scripts/Libraries/+.js +3 -5
  25. package/src/scripts/Libraries/CookieConsent.js +65 -52
  26. package/src/scripts/Libraries/Dialog.js +19 -38
  27. package/src/scripts/Libraries/Form.js +6 -19
  28. package/src/scripts/Libraries/Naja.js +22 -18
  29. package/src/scripts/Libraries/ReCaptcha.js +9 -26
  30. package/src/scripts/Libraries/Reveal.js +32 -0
  31. package/src/scripts/Libraries/Ripple.js +3 -3
  32. package/src/scripts/Libraries/Stimulus.js +50 -5
  33. package/src/scripts/Libraries/Swup.js +44 -59
  34. package/src/scripts/Libraries/Toaster.js +55 -0
  35. package/src/scripts/Ui/Check.js +3 -3
  36. package/src/scripts/Ui/Control.js +42 -34
  37. package/src/scripts/Ui/ControlSelect.js +6 -5
  38. package/src/scripts/Ui/Text.js +6 -6
  39. package/src/scripts/Utils/+.js +3 -3
  40. package/src/scripts/Utils/cdn.js +0 -1
  41. package/src/scripts/Utils/initAfter.js +11 -0
  42. package/src/scripts/Utils/naja.js +41 -0
  43. package/src/scripts/Utils/utilities.js +8 -0
  44. package/src/scripts/main.js +2 -1
  45. package/src/styles/Components/+.css +3 -2
  46. package/src/styles/Components/Dialog/+.css +2 -0
  47. package/src/styles/Components/Dialog/Content.css +2 -0
  48. package/src/styles/Components/Dialog/CookieConsent.css +17 -0
  49. package/src/styles/Components/Dialog/Default.css +2 -26
  50. package/src/styles/Components/Drawer.css +18 -0
  51. package/src/styles/Components/Field.css +1 -1
  52. package/src/styles/Components/Popover.css +1 -0
  53. package/src/styles/Components/Toaster.css +2 -0
  54. package/src/styles/Layout/Header.css +7 -39
  55. package/src/styles/Layout/Main.css +9 -6
  56. package/src/styles/Layout/Nav.css +6 -30
  57. package/src/styles/Libraries/+.css +0 -5
  58. package/src/styles/Ui/+.css +0 -1
  59. package/src/styles/Ui/Badge.css +1 -0
  60. package/src/styles/Ui/Btn.css +6 -5
  61. package/src/styles/Ui/Check.css +1 -1
  62. package/src/styles/Ui/Control.css +14 -4
  63. package/src/styles/Ui/ControlSelect.css +10 -19
  64. package/src/styles/Ui/Group.css +1 -1
  65. package/src/styles/Ui/Heading.css +1 -0
  66. package/src/styles/Ui/Image.css +1 -1
  67. package/src/styles/Ui/Info.css +1 -1
  68. package/src/styles/Ui/Label.css +1 -1
  69. package/src/styles/Ui/Link.css +7 -1
  70. package/src/styles/Ui/Notice.css +9 -1
  71. package/src/styles/Ui/Progress.css +1 -1
  72. package/src/styles/Ui/Switch.css +1 -1
  73. package/src/styles/Ui/Text.css +1 -8
  74. package/src/styles/Ui/Title.css +1 -4
  75. package/src/styles/Utils/+.css +1 -3
  76. package/src/styles/Utils/config.css +14 -3
  77. package/src/styles/Utils/default.css +11 -4
  78. package/src/styles/Utils/theme/+.css +1 -1
  79. package/src/styles/Utils/theme/main.css +27 -13
  80. package/src/styles/Utils/utilities.css +42 -0
  81. package/src/styles/main.css +1 -4
  82. package/src/templates/Components/Dialog/Basic.latte +24 -0
  83. package/src/templates/Components/Dialog/CookieConsent.latte +27 -0
  84. package/src/templates/Components/Form/CookieConsent.latte +47 -0
  85. package/src/templates/Layout/Header.latte +31 -33
  86. package/src/templates/Layout/Main.latte +39 -28
  87. package/src/templates/Sections/CookieConsent.latte +69 -0
  88. package/src/templates/Sections/Site.latte +80 -8
  89. package/src/templates/Sections/Text.latte +64 -0
  90. package/src/templates/Sections/Ui/Docs/@intro.html +5 -5
  91. package/src/templates/Sections/Ui/Docs/@nav.html +50 -60
  92. package/src/templates/Sections/Ui/Docs/@styles.html +1 -1
  93. package/src/templates/Sections/Ui/Docs/Default.latte +86 -166
  94. package/src/templates/Sections/Ui/Icons.html +1 -1
  95. package/src/templates/Sections/Ui/Intro.html +33 -79
  96. package/src/templates/Ui/ControlDate.latte +1 -1
  97. package/src/templates/Ui/ControlTime.latte +1 -1
  98. package/src/views/dialog/basic.json.latte +1 -1
  99. package/src/views/email/email.latte +2 -2
  100. package/src/views/email/email.test.latte +2 -2
  101. package/src/views/gdpr.json +6 -4
  102. package/src/views/popover/info.json.latte +15 -0
  103. package/vite.config.js +17 -10
  104. package/src/emails/styles/email.css +0 -77
  105. package/src/emails/templates.test/Content.latte +0 -24
  106. package/src/emails/templates.test/Header.latte +0 -14
  107. package/src/scripts/Components/CookieConsent.js +0 -78
  108. package/src/scripts/Layout/Main.js +0 -50
  109. package/src/scripts/Libraries/Drawer.js +0 -42
  110. package/src/scripts/Libraries/Script.js +0 -18
  111. package/src/scripts/Libraries/Slider.js +0 -160
  112. package/src/scripts/Libraries/Tippy.js +0 -117
  113. package/src/scripts/Utils/Functions/+.js +0 -7
  114. package/src/scripts/Utils/Functions/importScript.js +0 -17
  115. package/src/scripts/Utils/Functions/importStyle.js +0 -18
  116. package/src/scripts/Utils/Functions/inputStep.js +0 -9
  117. package/src/scripts/Utils/Functions/inputValidity.js +0 -57
  118. package/src/scripts/Utils/Functions/loadStimulus.js +0 -42
  119. package/src/scripts/Utils/Functions/replaceScript.js +0 -4
  120. package/src/scripts/Utils/Functions/replaceTag.js +0 -8
  121. package/src/scripts/Utils/global.js +0 -15
  122. package/src/styles/Components/CookieConsent.css +0 -68
  123. package/src/styles/Components/Dropdown/+.css +0 -1
  124. package/src/styles/Components/Dropdown/Default.css +0 -8
  125. package/src/styles/Libraries/Dialog.css +0 -1
  126. package/src/styles/Libraries/Drawer.css +0 -64
  127. package/src/styles/Libraries/Hint.css +0 -186
  128. package/src/styles/Libraries/Ripple.css +0 -1
  129. package/src/styles/Libraries/Tippy.css +0 -73
  130. package/src/styles/Ui/Dot.css +0 -22
  131. package/src/styles/Utils/icons.css +0 -5
  132. package/src/styles/Utils/tailwind.css +0 -50
  133. package/src/templates/Components/CookieConsent.latte +0 -28
  134. package/src/templates/Components/Dialogs/Basic.latte +0 -22
  135. package/src/templates/Components/Items/.gitkeep +0 -0
  136. package/src/templates/Sections/Gdpr.latte +0 -127
  137. package/src/views/dropdown/tippy.json.latte +0 -19
  138. /package/src/{styles/Utils/print.css → emails/styles/main/Base/font.css} +0 -0
@@ -0,0 +1,60 @@
1
+ import { LibStimulus, Controller } from '../Libraries/Stimulus.js'
2
+ import { showDrawer, closeDrawer, scrollDrawer } from 'winduum/src/components/drawer/index.js'
3
+
4
+ LibStimulus.register('c-drawer', class extends Controller {
5
+ static values = {
6
+ inertMatch: {
7
+ type: String,
8
+ default: ':where(.c-drawer, .l-header)'
9
+ }
10
+ }
11
+
12
+ connect() {
13
+ this.scrollReset()
14
+ this.element.addEventListener('click', ({ target }) => {
15
+ if (target === this.element) this.close()
16
+ })
17
+ }
18
+
19
+ scrollReset() {
20
+ this.element.scroll({ left: this.element.scrollWidth, behavior: 'instant' })
21
+ }
22
+
23
+ scroll({ target }) {
24
+ scrollDrawer(target)
25
+ }
26
+
27
+ inert(inert) {
28
+ [...document.body.children].forEach((element) => {
29
+ if (!element.matches(this.inertMatchValue)) (element.inert = inert)
30
+ })
31
+ }
32
+
33
+ show() {
34
+ this.scrollReset()
35
+ this.element.classList.add('active')
36
+ showDrawer(this.element)
37
+ this.inert(true)
38
+ }
39
+
40
+ close() {
41
+ closeDrawer(this.element)
42
+ }
43
+
44
+ toggle({ currentTarget }) {
45
+ this.activeButton = currentTarget
46
+
47
+ if (!currentTarget.classList.contains('active')) {
48
+ currentTarget.classList.add('active')
49
+ this.show()
50
+ } else {
51
+ this.close()
52
+ }
53
+ }
54
+
55
+ dismiss() {
56
+ this.element.classList.remove('active')
57
+ this.activeButton?.classList?.remove('active')
58
+ this.inert(false)
59
+ }
60
+ })
@@ -0,0 +1,65 @@
1
+ import { Controller, LibStimulus } from '../Libraries/Stimulus.js'
2
+ import { dataset, fetchJson } from '@newlogic-digital/utils-js'
3
+ import initAfter from '../Utils/initAfter.js'
4
+
5
+ LibStimulus.register('c-popover', class extends Controller {
6
+ static values = {
7
+ url: String,
8
+ insertTo: String,
9
+ manual: Boolean
10
+ }
11
+
12
+ async toggle({ currentTarget, params }) {
13
+ const { togglePopover } = await import('winduum/src/components/popover/index.js')
14
+ const hasUrlValue = this.hasUrlValue && !this.popoverTarget
15
+
16
+ if (hasUrlValue) await this.fetch()
17
+
18
+ this.popoverTarget = document.getElementById(currentTarget.getAttribute('popovertarget'))
19
+
20
+ if (hasUrlValue) initAfter(this.popoverTarget)
21
+
22
+ await togglePopover(currentTarget, params)
23
+ }
24
+
25
+ async hide() {
26
+ if (this.popoverActionTarget.ariaExpanded !== 'true') return
27
+
28
+ const { hidePopover } = await import('winduum/src/components/popover/index.js')
29
+
30
+ await hidePopover(this.popoverActionTarget)
31
+ }
32
+
33
+ async dismiss({ target }) {
34
+ if (this.popoverActionTarget.ariaExpanded !== 'true') return
35
+
36
+ if (!this.popoverTarget.contains(target) && !this.popoverActionTarget.isEqualNode(target) && this.popoverActionTarget.ariaExpanded === 'true') {
37
+ await this.hide()
38
+ }
39
+ }
40
+
41
+ async fetch() {
42
+ this.popoverActionTarget.classList.add('loading', 'cursor-wait')
43
+
44
+ const { content } = await fetchJson(this.urlValue)
45
+
46
+ this.popoverActionTarget.classList.remove('loading', 'cursor-wait')
47
+
48
+ const insertElement = !this.hasInsertToValue ? this.popoverActionTarget : document.querySelector(this.insertToValue)
49
+ insertElement.insertAdjacentHTML(!this.hasInsertToValue ? 'afterend' : 'beforeend', content)
50
+
51
+ return content
52
+ }
53
+
54
+ connect() {
55
+ this.popoverActionTarget = this.element.querySelector('[popovertargetaction]')
56
+
57
+ if (!this.popoverActionTarget) return
58
+
59
+ ;(!this.hasManualValue || !this.manualValue) && dataset(this.popoverActionTarget, 'action').add(
60
+ `click->c-popover#${this.popoverActionTarget.getAttribute('popovertargetaction')}:prevent`,
61
+ 'keydown.esc@window->c-popover#hide',
62
+ 'click@window->c-popover#dismiss'
63
+ )
64
+ }
65
+ })
@@ -1,2 +1 @@
1
1
  import './Header.js'
2
- import './Main.js'
@@ -1,32 +1,20 @@
1
- import { LibStimulus, Controller, getController } from '../Libraries/Stimulus.js'
1
+ import { LibStimulus, Controller } from '../Libraries/Stimulus.js'
2
2
 
3
- LibStimulus.register('l-header',
4
- /** @property {LibDrawer} libDrawerOutlet */
5
- class extends Controller {
6
- connect () {
7
- if (document.querySelector('#l-nav') === null) {
8
- this.element.insertAdjacentHTML('afterend', `
9
- <div id="l-nav" class="lib-drawer" data-controller="lib-drawer" data-action="scroll->lib-drawer#scroll" inert>
10
- <div class="l_nav">
11
- <div class="l_nav_head"></div>
12
- <div class="l_nav_body"></div>
13
- </div>
14
- </div>
15
- `)
3
+ LibStimulus.register('l-header', class extends Controller {
4
+ static targets = ['logo', 'nav']
16
5
 
17
- const layoutNav = document.querySelector('#l-nav')
18
- const logo = this.element.querySelector('.l_header_logo').outerHTML
19
- const nav = this.element.querySelector('.l_header_nav').outerHTML
6
+ connect() {
7
+ if (!document.querySelector('.l-nav')) {
8
+ this.element.insertAdjacentHTML('afterend', `
9
+ <div class="l-nav c-drawer" data-controller="c-drawer" data-action="scroll->c-drawer#scroll c-drawer:close->c-drawer#dismiss" inert>
10
+ <div class="c-drawer-content"></div>
11
+ </div>
12
+ `)
20
13
 
21
- layoutNav.querySelector('.l_nav_head').insertAdjacentHTML('beforeend', logo)
22
- layoutNav.querySelector('.l_nav_body').insertAdjacentHTML('beforeend', nav)
23
- }
24
- }
14
+ const drawerContentElement = document.querySelector('.l-nav .c-drawer-content')
25
15
 
26
- showDrawer () {
27
- /** @type {LibDrawer} */
28
- const LibDrawer = getController(document.querySelector('[data-controller~="lib-drawer"]'), 'lib-drawer')
29
- LibDrawer.show()
16
+ drawerContentElement.insertAdjacentHTML('beforeend', this.logoTarget.outerHTML)
17
+ drawerContentElement.insertAdjacentHTML('beforeend', this.navTarget.outerHTML)
30
18
  }
31
19
  }
32
- )
20
+ })
@@ -1,12 +1,10 @@
1
- export { default as CookieConsent } from './CookieConsent.js'
1
+ import './CookieConsent.js'
2
2
  import './Dialog.js'
3
- import './Drawer.js'
4
3
  import './Form.js'
5
4
  import './Naja.js'
6
5
  import './ReCaptcha.js'
6
+ import './Reveal.js'
7
7
  import './Ripple.js'
8
- import './Script.js'
9
- import './Slider.js'
10
8
  import './Stimulus.js'
11
9
  export { default as Swup } from './Swup.js'
12
- export { default as Tippy } from './Tippy.js'
10
+ import './Toaster.js'
@@ -1,67 +1,80 @@
1
- const LibCookieConsent = {
2
- setItem: (key, value) => {
3
- localStorage.setItem(key, value)
4
- },
5
- getItem: (key) => {
6
- return localStorage.getItem(key)
7
- },
8
- init: () => {
9
- const type = LibCookieConsent.getItem('lib-cookieconsent')
1
+ import { LibStimulus, Controller } from './Stimulus.js'
2
+ import { appendCookieConsent, setCookieConsent } from '@newlogic-digital/cookieconsent-js'
3
+ import { showDialog, closeDialog } from 'winduum/src/components/dialog/index.js'
10
4
 
11
- if (type !== null) {
12
- JSON.parse(type).forEach(type => LibCookieConsent.append(type))
5
+ export const getCookieConsentItem = (key = 'cookieconsent-js') => localStorage.getItem(key)
6
+
7
+ export const initCookieConsent = (element = document, type = getCookieConsentItem() ?? []) => {
8
+ element.querySelectorAll('[data-lib-cookieconsent]').forEach((element) => {
9
+ if (type.includes(element.getAttribute('data-lib-cookieconsent'))) {
10
+ appendCookieConsent(element, {
11
+ ignoreAttributeName: /(type|data-lib-cookieconsent)/
12
+ })
13
+ }
14
+ })
15
+ }
16
+
17
+ LibStimulus.register('c-dialog-cookieconsent', class extends Controller {
18
+ async connect() {
19
+ initCookieConsent()
20
+
21
+ if (document.querySelector('.c-form-cookieconsent')) {
22
+ return
13
23
  }
14
- },
15
- set: (type) => {
16
- LibCookieConsent.setItem('lib-cookieconsent', JSON.stringify(type))
17
- LibCookieConsent.setItem('lib-cookieconsent-expire', (Date.now() + 31556926 * 1000).toString())
18
24
 
19
- if (type.length > 0) {
20
- type.forEach(type => LibCookieConsent.append(type))
25
+ if (!getCookieConsentItem() || parseInt(getCookieConsentItem('cookieconsent-js-expire')) < Date.now()) {
26
+ setTimeout(async () => {
27
+ await showDialog(this.element, { closable: false })
28
+ }, 1500)
21
29
  } else {
22
- LibCookieConsent.setItem('lib-cookieconsent', JSON.stringify([]))
23
- LibCookieConsent.remove()
30
+ this.element.remove()
24
31
  }
25
- },
26
- remove: () => {
27
- document.cookie.split(';').forEach(c => {
28
- document.cookie = c.replace(/^ +/, '').replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/')
29
- })
30
- },
31
- append: (type) => {
32
- document.querySelectorAll('[data-lib-cookieconsent]').forEach(elm => {
33
- if (type === 'all' || elm.getAttribute('data-lib-cookieconsent') === type) {
34
- const script = document.createElement('script')
35
- let delay = 0
32
+ }
36
33
 
37
- ;[...elm.attributes].forEach((attribute) => {
38
- if (attribute.specified) {
39
- if (attribute.name.indexOf('data-lib-cookieconsent') === -1 && attribute.name.indexOf('type') === -1) {
40
- script.setAttribute(attribute.name, attribute.value)
41
- }
42
- }
43
- })
34
+ async approve() {
35
+ await this.hide(['performance', 'marketing'])
36
+ }
44
37
 
45
- script.innerHTML = elm.innerHTML
38
+ async decline() {
39
+ await this.hide([])
40
+ }
46
41
 
47
- if (elm.getAttribute('data-lib-cookieconsent-delay')) {
48
- delay = parseInt(elm.getAttribute('data-lib-cookieconsent-delay'))
49
- }
42
+ async hide(type) {
43
+ await setCookieConsent(type)
44
+ initCookieConsent(document, type)
45
+ await closeDialog(this.element, { remove: true })
46
+ }
47
+ })
50
48
 
51
- setTimeout(() => {
52
- if (elm.closest('body') !== null) {
53
- document.body.appendChild(script)
54
- } else if (elm.closest('head') !== null) {
55
- document.head.appendChild(script)
56
- }
49
+ LibStimulus.register('c-form-cookieconsent', class extends Controller {
50
+ connect() {
51
+ document.querySelector('.c-dialog-cookieconsent')?.close()
57
52
 
58
- elm.remove()
59
- }, delay)
53
+ this.element.querySelectorAll('input:not([disabled])').forEach((input) => {
54
+ input.checked = false
55
+ })
56
+
57
+ JSON.parse(getCookieConsentItem())?.forEach((type) => {
58
+ if (this.element.querySelector(`input[value="${type}"]`) !== null) {
59
+ this.element.querySelector(`input[value="${type}"]`).checked = true
60
60
  }
61
61
  })
62
62
  }
63
- }
64
63
 
65
- LibCookieConsent.init()
64
+ async update() {
65
+ const type = []
66
+
67
+ this.element.querySelectorAll('input:not([disabled])').forEach((input) => {
68
+ input.checked && type.push(input.value)
69
+ })
66
70
 
67
- export default LibCookieConsent
71
+ await setCookieConsent(type)
72
+ location.reload()
73
+ }
74
+
75
+ disconnect() {
76
+ if ((!getCookieConsentItem() || parseInt(getCookieConsentItem('cookieconsent-js-expire')) < Date.now())) {
77
+ document.querySelector('.c-dialog-cookieconsent')?.showModal()
78
+ }
79
+ }
80
+ })
@@ -1,47 +1,28 @@
1
- import { Controller, LibStimulus, loadStimulus } from './Stimulus.js'
2
- import { insertDialog, closeDialog, fetchDialog, dialogSelector } from 'winduum/src/libraries/dialog.js'
3
- import { replaceScript } from '../Utils/Functions/+.js'
1
+ import { Controller, LibStimulus } from './../Libraries/Stimulus.js'
2
+ import { insertDialog, closeDialog, dialogSelector } from 'winduum/src/components/dialog/index.js'
3
+ import initAfter from '../Utils/initAfter.js'
4
+ import { fetchJson } from '@newlogic-digital/utils-js'
4
5
 
5
6
  LibStimulus.register('lib-dialog', class extends Controller {
6
- static values = {
7
- open: String,
8
- url: String
9
- }
7
+ async show({ currentTarget, params }) {
8
+ const loadingClasses = (params.loadingClass ?? 'loading cursor-wait').split(' ')
9
+
10
+ currentTarget.classList.add(...loadingClasses)
11
+
12
+ await this.fetch(params.url, params)
10
13
 
11
- async connect () {
12
- if (this.hasOpenValue) {
13
- if (this.hasUrlValue) {
14
- await fetchDialog({
15
- url: this.urlValue, insertOptions: { remove: true }
16
- })
17
- } else {
18
- await insertDialog(document.querySelector(this.openValue).innerHTML, {
19
- remove: true
20
- })
21
- }
22
-
23
- loadStimulus(dialogSelector('.lib-dialog'))
24
- }
14
+ currentTarget.classList.remove(...loadingClasses)
25
15
  }
26
16
 
27
- async show ({ currentTarget, params }) {
28
- currentTarget.classList.add('loading', 'cursor-wait')
29
-
30
- await fetchDialog({
31
- url: params.url,
32
- insertOptions: {
33
- remove: params.remove ?? true,
34
- append: params.append ?? false
35
- }
36
- }).then(() => {
37
- loadStimulus(dialogSelector('.lib-dialog'))
38
- replaceScript(dialogSelector('.lib-dialog'))
39
- })
40
-
41
- currentTarget.classList.remove('loading', 'cursor-wait')
17
+ async close({ currentTarget, params }) {
18
+ await closeDialog(currentTarget.closest('dialog'), { remove: params.remove ?? true })
42
19
  }
43
20
 
44
- async close ({ currentTarget, params }) {
45
- await closeDialog(currentTarget.closest('dialog'), { remove: params.remove ?? false })
21
+ async fetch(url, options) {
22
+ const { content } = await fetchJson(url)
23
+
24
+ await insertDialog(content, options)
25
+
26
+ initAfter(dialogSelector('.c-dialog'))
46
27
  }
47
28
  })
@@ -1,26 +1,13 @@
1
1
  import { LibStimulus, Controller } from './Stimulus.js'
2
- import { inputValidity } from '../Utils/Functions/+.js'
2
+ import { validateForm } from 'winduum/src/components/form/index.js'
3
3
 
4
4
  LibStimulus.register('lib-form', class extends Controller {
5
- connect () {
6
- this.element.setAttribute('novalidate', '')
7
- this.element.addEventListener('submit', e => this.validation(e))
5
+ connect() {
6
+ this.element.noValidate = true
7
+ this.element.addEventListener('submit', this.validate)
8
8
  }
9
9
 
10
- validation (e) {
11
- if (this.element.checkValidity() === false) {
12
- e.preventDefault()
13
- e.stopPropagation()
14
-
15
- this.element.querySelector(':invalid').scrollIntoView({ behavior: 'smooth', block: 'center' })
16
- this.element.querySelector(':invalid').focus()
17
- } else {
18
- this.element.querySelector('[type="submit"]').classList.add('loading')
19
- }
20
-
21
- this.element.querySelectorAll('.ui-control, .ui-check, .ui-switch').forEach(element => {
22
- console.log(element)
23
- inputValidity(element, { message: true })
24
- })
10
+ async validate(event) {
11
+ validateForm(event)
25
12
  }
26
13
  })
@@ -1,33 +1,37 @@
1
+ import { Controller, LibStimulus, initStimulus } from './Stimulus.js'
2
+ import { initCookieConsent } from './CookieConsent.js'
3
+ import {
4
+ initNaja,
5
+ NajaRecaptchaExtension,
6
+ NajaFormValidityExtension
7
+ } from '../Utils/naja.js'
1
8
  import naja from 'naja'
2
- import { Controller, LibStimulus, loadStimulus } from './Stimulus.js'
9
+ import LibSwup from './Swup.js'
3
10
 
4
11
  LibStimulus.register('lib-naja', class extends Controller {
5
- async connect () {
6
- naja.uiHandler.addEventListener('interaction', ({ detail }) => {
7
- const element = detail.element
12
+ async initialize() {
13
+ naja.uiHandler.selector = '[data-naja]'
8
14
 
9
- detail.options.target = element
15
+ await initNaja(this.element, false)
10
16
 
11
- element.dispatchEvent(new CustomEvent('naja:interaction', { bubbles: true, cancelable: true }))
17
+ if (naja.initialized) return
12
18
 
13
- if (element?.form && !element.form.reportValidity()) {
14
- arguments[0].preventDefault()
15
- }
19
+ naja.uiHandler.addEventListener('interaction', ({ detail }) => {
20
+ detail.element.dispatchEvent(new CustomEvent('naja:interaction', { bubbles: true, cancelable: true }))
16
21
  })
17
22
 
18
23
  naja.snippetHandler.addEventListener('afterUpdate', ({ detail }) => {
19
- detail?.options.target.dispatchEvent(new CustomEvent('naja:afterUpdate', { bubbles: true, cancelable: true }))
24
+ detail.snippet.dispatchEvent(new CustomEvent('naja:afterUpdate', { bubbles: true, cancelable: true }))
20
25
 
21
- loadStimulus(document.body, false)
22
- })
26
+ initStimulus(detail.snippet)
27
+ initNaja(detail.snippet)
28
+ initCookieConsent(detail.snippet)
23
29
 
24
- naja.uiHandler.selector = '[data-naja]'
25
- naja.initialize({
26
- history: false
30
+ LibSwup.cache.clear()
27
31
  })
28
- }
29
32
 
30
- async get ({ params }) {
31
- await naja.makeRequest('GET', params.url, params.data ? JSON.parse(params.data) : null, { history: params.history ?? false })
33
+ naja.registerExtension(NajaRecaptchaExtension)
34
+ naja.registerExtension(NajaFormValidityExtension)
35
+ naja.initialize()
32
36
  }
33
37
  })
@@ -1,6 +1,5 @@
1
1
  import { LibStimulus, Controller } from './Stimulus.js'
2
- import naja from 'naja'
3
- import importScript from '../Utils/Functions/importScript.js'
2
+ import { importScript } from '@newlogic-digital/utils-js'
4
3
  import cdn from '../Utils/cdn.js'
5
4
 
6
5
  LibStimulus.register('lib-recaptcha', class extends Controller {
@@ -9,34 +8,18 @@ LibStimulus.register('lib-recaptcha', class extends Controller {
9
8
  action: String
10
9
  }
11
10
 
12
- connect () {
11
+ connect() {
13
12
  importScript(cdn.recaptcha.replace('{apikey}', this.apiValue))
14
13
  }
15
14
 
16
- async execute () {
17
- return new Promise(resolve => {
18
- window.grecaptcha.enterprise.ready(() => {
19
- window.grecaptcha.enterprise.execute(this.apiValue, { action: this.actionValue ?? 'form' }).then(token => {
20
- this.element.querySelector('[name="gtoken"]').value = token
21
- resolve()
22
- })
15
+ execute(event) {
16
+ if (event?.detail?.recaptchaExecuted) return
17
+
18
+ window.grecaptcha.enterprise.ready(() => {
19
+ window.grecaptcha.enterprise.execute(this.apiValue, { action: this.actionValue ?? 'form' }).then((token) => {
20
+ this.element.gtoken.value = token
21
+ this.element.dispatchEvent(new CustomEvent('submit', { cancelable: true, detail: { recaptchaExecuted: true } }))
23
22
  })
24
23
  })
25
24
  }
26
-
27
- async submit ({ params }) {
28
- if (this.element.reportValidity() === false) {
29
- return false
30
- }
31
-
32
- arguments[0].preventDefault()
33
-
34
- await this.execute()
35
-
36
- if (!params.naja) {
37
- this.element.submit()
38
- } else {
39
- await naja.makeRequest(this.element.method, this.element.action, new FormData(this.element), { history: 'replace' })
40
- }
41
- }
42
25
  })
@@ -0,0 +1,32 @@
1
+ import { Controller, LibStimulus } from './Stimulus.js'
2
+ import { dataset } from '@newlogic-digital/utils-js'
3
+
4
+ LibStimulus.register('lib-reveal', class extends Controller {
5
+ static targets = ['item']
6
+
7
+ intersectionObserver() {
8
+ this.observer = new IntersectionObserver((entries, observer) => {
9
+ entries.forEach((entry) => {
10
+ if (entry.intersectionRatio > 0.1 && !entry.target.classList.contains('in')) {
11
+ entry.target.classList.add('in')
12
+
13
+ if (entry.target.dataset.controllerNameParam) {
14
+ dataset(entry.target, 'controller').add(entry.target.dataset.controllerNameParam)
15
+ }
16
+ }
17
+ })
18
+ }, {
19
+ threshold: 0.1
20
+ })
21
+ }
22
+
23
+ itemTargetConnected(element) {
24
+ if (!this.observer) this.intersectionObserver()
25
+
26
+ this.observer?.observe(element)
27
+ }
28
+
29
+ itemTargetDisconnected(element) {
30
+ this.observer?.unobserve(element)
31
+ }
32
+ })
@@ -1,8 +1,8 @@
1
1
  import { Controller, LibStimulus } from './Stimulus.js'
2
- import { showRipple } from 'winduum/src/libraries/ripple.js'
2
+ import { showRipple } from 'winduum/src/utilities/ripple/index.js'
3
3
 
4
4
  LibStimulus.register('lib-ripple', class extends Controller {
5
- async show (e) {
6
- showRipple(e)
5
+ async show(event) {
6
+ showRipple(event)
7
7
  }
8
8
  })
@@ -1,11 +1,56 @@
1
1
  import { Application, Controller } from '@hotwired/stimulus'
2
- import loadStimulus from '../Utils/Functions/loadStimulus.js'
2
+ import { dataset } from '@newlogic-digital/utils-js'
3
+
4
+ function initActions(parent, selectors) {
5
+ if (!parent) return
6
+
7
+ selectors.forEach(([selector, action]) => {
8
+ parent.querySelectorAll(selector).forEach((element) => {
9
+ dataset(element, 'action').add(action)
10
+ })
11
+ })
12
+ }
13
+
14
+ function initControllers(parent, selectors) {
15
+ if (!parent) return
16
+
17
+ selectors.forEach((selector) => {
18
+ [...parent.getElementsByClassName(selector)].forEach((element) => {
19
+ dataset(element, 'controller').add(selector)
20
+ })
21
+ })
22
+ }
23
+
24
+ function initStimulus(element, { controllers, actions } = {
25
+ controllers: ['ui-control', 'ui-text', 'ui-check'],
26
+ actions: [['.ui-btn', 'click->lib-ripple#show'], ['.ui-check', 'change->ui-check#validate']]
27
+ }) {
28
+ initControllers(element, controllers)
29
+ initActions(element, actions)
30
+ }
3
31
 
4
32
  const LibStimulus = new Application(document.documentElement)
5
- const getController = (element, identifier) => LibStimulus.getControllerForElementAndIdentifier(element, identifier)
6
33
 
7
- LibStimulus.start().then(() => loadStimulus(document.body))
34
+ const getController = (...arg) => LibStimulus.getControllerForElementAndIdentifier(...arg)
35
+
36
+ const delegateController = (name, method, event = {}, selector) => {
37
+ const controller = getController(document.querySelector(selector || `.${name}`), name)
38
+
39
+ if (controller) return method ? controller[method](event) : controller
40
+ }
41
+
42
+ LibStimulus.start().then(() => initStimulus(document.body))
43
+
44
+ LibStimulus.register('controller', class extends Controller {
45
+ delegate(event) {
46
+ delegateController(event.params.name, event.params.method, event, event.params.selector)
47
+ }
48
+
49
+ load({ currentTarget, params }) {
50
+ dataset(currentTarget, 'controller').add(params.name)
51
+ }
52
+ })
8
53
 
9
- window.LibStimulus = { default: LibStimulus, Controller, loadStimulus }
54
+ window.LibStimulus = { default: LibStimulus, Controller, initStimulus, delegateController }
10
55
 
11
- export { LibStimulus, Controller, loadStimulus, getController }
56
+ export { LibStimulus, Controller, initStimulus, getController, delegateController }