formatic 0.2.3 → 0.2.4

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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascript/declarations/date.d.ts +9 -0
  3. data/app/assets/javascript/declarations/file.d.ts +14 -0
  4. data/app/assets/javascript/declarations/select.d.ts +15 -0
  5. data/app/assets/javascript/declarations/setup.d.ts +3 -0
  6. data/app/assets/javascript/declarations/stepper.d.ts +12 -0
  7. data/app/assets/javascript/declarations/string.d.ts +14 -0
  8. data/app/assets/javascript/declarations/textarea.d.ts +15 -0
  9. data/app/assets/javascript/declarations/toggle.d.ts +8 -0
  10. data/app/assets/javascript/formatic/date.js +30 -0
  11. data/app/assets/javascript/formatic/date.js.map +1 -0
  12. data/app/assets/javascript/formatic/file.js +83 -0
  13. data/app/assets/javascript/formatic/file.js.map +1 -0
  14. data/app/assets/javascript/formatic/select.js +81 -0
  15. data/app/assets/javascript/formatic/select.js.map +1 -0
  16. data/app/assets/javascript/formatic/setup.js +42 -0
  17. data/app/assets/javascript/formatic/setup.js.map +1 -0
  18. data/app/assets/javascript/formatic/stepper.js +67 -0
  19. data/app/assets/javascript/formatic/stepper.js.map +1 -0
  20. data/app/assets/javascript/formatic/string.js +71 -0
  21. data/app/assets/javascript/formatic/string.js.map +1 -0
  22. data/app/assets/javascript/formatic/textarea.js +81 -0
  23. data/app/assets/javascript/formatic/textarea.js.map +1 -0
  24. data/app/assets/javascript/formatic/toggle.js +63 -0
  25. data/app/assets/javascript/formatic/toggle.js.map +1 -0
  26. data/app/assets/javascript/src/date.ts +41 -0
  27. data/app/assets/javascript/src/file.ts +101 -0
  28. data/app/assets/javascript/src/select.ts +101 -0
  29. data/app/assets/javascript/src/setup.js +44 -0
  30. data/app/assets/javascript/src/stepper.ts +80 -0
  31. data/app/assets/javascript/src/string.ts +89 -0
  32. data/app/assets/javascript/src/textarea.ts +101 -0
  33. data/app/assets/javascript/src/toggle.ts +76 -0
  34. data/app/assets/stylesheets/formatic/components/checklist.css +1 -0
  35. data/app/assets/stylesheets/formatic/components/checklist.css.map +1 -0
  36. data/app/assets/stylesheets/formatic/components/date.css +17 -0
  37. data/app/assets/stylesheets/formatic/components/date.sass +2 -2
  38. data/app/assets/stylesheets/formatic/components/select.css +17 -0
  39. data/app/assets/stylesheets/formatic/components/stepper.css +17 -0
  40. data/app/assets/stylesheets/formatic/components/string.css +17 -0
  41. data/app/assets/stylesheets/formatic/components/textarea.css +17 -0
  42. data/app/assets/stylesheets/formatic/components/time.css +17 -0
  43. data/app/assets/stylesheets/formatic/components/toggle.css +17 -0
  44. data/app/assets/stylesheets/formatic/components/wrapper.css +17 -0
  45. data/app/assets/stylesheets/formatic/formatic.css +450 -0
  46. data/app/assets/stylesheets/formatic/formatic.css.map +1 -0
  47. data/app/assets/stylesheets/formatic/generics/flip.css +1 -0
  48. data/app/assets/stylesheets/formatic/generics/flip.css.map +1 -0
  49. data/app/assets/stylesheets/formatic/scopes/form.css +17 -0
  50. data/app/assets/stylesheets/formatic/utilities/container.css +1 -0
  51. data/app/assets/stylesheets/formatic/utilities/container.css.map +1 -0
  52. data/app/assets/stylesheets/formatic/vendor.css +1107 -0
  53. data/app/assets/stylesheets/formatic/vendor.css.map +1 -0
  54. data/app/assets/stylesheets/formatic.css +18 -0
  55. data/app/assets/stylesheets/formatic.sass +17 -0
  56. data/app/assets/stylesheets/vendor.css +5 -0
  57. data/app/assets/stylesheets/vendor.css.map +1 -0
  58. data/app/assets/stylesheets/vendor.sass +1 -0
  59. data/app/components/formatic/base.rb +4 -1
  60. data/app/components/formatic/date.rb +1 -1
  61. data/app/components/formatic/file.rb +21 -0
  62. data/app/components/formatic/files.rb +8 -0
  63. data/app/components/formatic/select.rb +1 -1
  64. data/app/components/formatic/time.rb +3 -3
  65. data/config/importmap.rb +11 -0
  66. data/lib/formatic/choices/options.rb +1 -1
  67. data/lib/formatic/choices/records.rb +1 -1
  68. data/lib/formatic/engine.rb +12 -0
  69. data/lib/formatic/version.rb +1 -1
  70. data/lib/formatic/wrappers/required.rb +1 -1
  71. data/lib/formatic.rb +2 -1
  72. metadata +77 -17
  73. data/app/assets/javascript/formatic/components/date.ts +0 -54
  74. data/app/assets/javascript/formatic/components/select.ts +0 -113
  75. data/app/assets/javascript/formatic/components/stepper.ts +0 -89
  76. data/app/assets/javascript/formatic/components/string.ts +0 -103
  77. data/app/assets/javascript/formatic/components/textarea.ts +0 -112
  78. data/app/assets/javascript/formatic/components/toggle.ts +0 -89
  79. data/app/assets/javascript/formatic.js +0 -446
  80. data/app/assets/javascript/formatic.js.map +0 -1
  81. data/app/assets/stylesheets/formatic/index.sass +0 -17
  82. data/app/assets/stylesheets/formatic/package.json +0 -5
@@ -1,113 +0,0 @@
1
- namespace Formatic {
2
- export class Select {
3
- private el: HTMLElement
4
- private timeoutId: ReturnType<typeof setTimeout>
5
-
6
- constructor(el: HTMLElement) {
7
- this.el = el
8
- this.setupBindings()
9
- }
10
-
11
- private setupBindings() {
12
- this.autosize()
13
-
14
- this.el.addEventListener('input', (event) => {
15
- event.preventDefault()
16
- if (this.autoSubmit) this.actionSave()
17
- })
18
- }
19
-
20
- // ACTIONS
21
-
22
- private actionSave() {
23
- this.guiWaitingForSave()
24
- this.debounce(this.actionSaveNow.bind(this))()
25
- }
26
-
27
- private actionSaveNow() {
28
- console.debug("Saving select...")
29
- this.el.classList.remove('is-loading')
30
- this.el.classList.add('is-saved')
31
- this.save()
32
- }
33
-
34
- // GUI
35
-
36
- private guiWaitingForSave() {
37
- this.el.classList.add('is-loading')
38
- this.el.classList.remove('is-saved')
39
- this.el.classList.remove('is-failed')
40
- }
41
-
42
- private guiSaved() {
43
- this.el.classList.remove('is-loading')
44
- this.el.classList.add('is-saved')
45
- this.el.classList.remove('is-failed')
46
- }
47
-
48
- private guiFailed() {
49
- this.el.classList.remove('is-loading')
50
- this.el.classList.remove('is-saved')
51
- this.el.classList.add('is-failed')
52
- }
53
-
54
- // Attributes
55
-
56
- private get autoSubmit() {
57
- return this.el.classList.contains('is-autosubmit')
58
- }
59
-
60
- // Helpers
61
-
62
- private save() {
63
- const form = this.el.closest<HTMLFormElement>('form')
64
- const data = new FormData(form)
65
- data.set('_method', 'patch')
66
-
67
- fetch(form.action, {
68
- method: 'POST',
69
- headers: { 'Accept': 'text/javascript' },
70
- body: data
71
- })
72
- .then(response => {
73
- if (response.status == 201) {
74
- console.debug('Select content saved')
75
- this.guiSaved()
76
- } else {
77
- console.debug('Select content not saved')
78
- this.guiFailed()
79
- }
80
- }).catch(err => {
81
- console.warn(err)
82
- console.debug('Failed badly to save')
83
- })
84
- }
85
-
86
- private debounce(fn: Function) {
87
- return () => {
88
- clearTimeout(this.timeoutId)
89
- this.timeoutId = setTimeout(() => fn(), 1000)
90
- }
91
- }
92
-
93
- private autosize() {
94
- try {
95
- autosize(this.el) // External library.
96
- } catch (error) {
97
- console.warn(`Formatic is missing the autosize library`)
98
- }
99
- }
100
- }
101
- }
102
-
103
- // --------------
104
- // Initialization
105
- // --------------
106
-
107
- document.addEventListener('DOMContentLoaded', () => {
108
- document.querySelectorAll<HTMLElement>('.js-formatic-select').forEach((el) => {
109
- console.debug('Instantiating Formatic.Select...')
110
- new Formatic.Select(el)
111
- })
112
- })
113
-
@@ -1,89 +0,0 @@
1
- namespace Formatic {
2
- export class Stepper {
3
- private el: HTMLElement
4
-
5
- constructor(el: HTMLElement) {
6
- this.el = el
7
- this.setupBindings()
8
- }
9
-
10
- private setupBindings() {
11
- this.incrementButtons.forEach((el) => {
12
- el.addEventListener('click', (event) => {
13
- event.preventDefault()
14
- this.increment()
15
- })
16
- })
17
-
18
- this.decrementButtons.forEach((el) => {
19
- el.addEventListener('click', (event) => {
20
- event.preventDefault()
21
- this.decrement()
22
- })
23
- })
24
-
25
- this.numberInput.addEventListener('click', (event) => {
26
- this.numberInput.select()
27
- })
28
- }
29
-
30
- private increment() {
31
- if (!this.number && this.number != 0) {
32
- // Incrementing leads to `0` (it's common to quickly want to achieve the number zero).
33
- // But if the minimum is e.g. `1` then it should be that instead.
34
- this.numberInput.value = Math.max(...[0, this.minimum]).toString()
35
- } else if (isNaN(this.number)) {
36
- // Do nothing on weird stuff.
37
- return
38
- } else if (this.number < this.minimum) {
39
- this.numberInput.value = this.minimum.toString()
40
- } else {
41
- this.numberInput.value = (this.number + 1).toString()
42
- }
43
- }
44
-
45
- private decrement() {
46
- if (!this.number && this.number != 0) {
47
- // Decementing empty leads to `-1`.
48
- // But if the minimum is e.g. `0` then it should be that instead.
49
- this.numberInput.value = Math.max(...[-1, this.minimum]).toString()
50
- } else if (isNaN(this.number)) {
51
- // Do nothing on weird stuff.
52
- return
53
- } else if (this.number <= this.minimum) {
54
- // Do nothing if at the minimum already
55
- return
56
- } else {
57
- // Normal decrement.
58
- this.numberInput.value = (this.number - 1).toString()
59
- }
60
- }
61
-
62
- private get minimum() {
63
- return parseInt(this.numberInput.min)
64
- }
65
-
66
- private get number() {
67
- return parseInt(this.numberInput.value)
68
- }
69
-
70
- private get incrementButtons() {
71
- return this.el.querySelectorAll<HTMLLinkElement>('.js-formatic-stepper__increment')
72
- }
73
-
74
- private get decrementButtons() {
75
- return this.el.querySelectorAll<HTMLLinkElement>('.js-formatic-stepper__decrement')
76
- }
77
-
78
- private get numberInput() {
79
- return this.el.querySelector<HTMLInputElement>('.js-formatic-stepper__number')
80
- }
81
- }
82
- }
83
-
84
- document.addEventListener('DOMContentLoaded', () => {
85
- document.querySelectorAll<HTMLElement>('.js-formatic-stepper').forEach((el) => {
86
- console.debug('Instantiating Formatic.Stepper...')
87
- new Formatic.Stepper(el)
88
- })
89
- })
@@ -1,103 +0,0 @@
1
- namespace Formatic {
2
- export class String {
3
- private el: HTMLElement
4
- private timeoutId: ReturnType<typeof setTimeout>
5
-
6
- constructor(el: HTMLElement) {
7
- this.el = el
8
- this.setupBindings()
9
- }
10
-
11
- private setupBindings() {
12
- this.el.addEventListener('input', (event) => {
13
- event.preventDefault()
14
- if (this.autoSubmit) this.actionSave()
15
- })
16
- }
17
-
18
- // ACTIONS
19
-
20
- private actionSave() {
21
- this.guiWaitingForSave()
22
- this.debounce(this.actionSaveNow.bind(this))()
23
- }
24
-
25
- private actionSaveNow() {
26
- console.debug("Saving text input...")
27
- this.el.classList.remove('is-loading')
28
- this.el.classList.add('is-saved')
29
- this.save()
30
- }
31
-
32
- // GUI
33
-
34
- private guiWaitingForSave() {
35
- this.el.classList.add('is-loading')
36
- this.el.classList.remove('is-saved')
37
- this.el.classList.remove('is-failed')
38
- }
39
-
40
- private guiSaved() {
41
- this.el.classList.remove('is-loading')
42
- this.el.classList.add('is-saved')
43
- this.el.classList.remove('is-failed')
44
- }
45
-
46
- private guiFailed() {
47
- this.el.classList.remove('is-loading')
48
- this.el.classList.remove('is-saved')
49
- this.el.classList.add('is-failed')
50
- }
51
-
52
- // Attributes
53
-
54
- private get autoSubmit() {
55
- return this.el.classList.contains('is-autosubmit')
56
- }
57
-
58
- // Helpers
59
-
60
- private save() {
61
- const form = this.el.closest<HTMLFormElement>('form')
62
- const data = new FormData(form)
63
- data.set('_method', 'patch')
64
-
65
- fetch(form.action, {
66
- method: 'POST',
67
- headers: { 'Accept': 'text/javascript' },
68
- body: data
69
- })
70
- .then(response => {
71
- if (response.status == 201) {
72
- console.debug('String content saved')
73
- this.guiSaved()
74
- } else {
75
- console.debug('String content not saved')
76
- this.guiFailed()
77
- }
78
- }).catch(err => {
79
- console.warn(err)
80
- console.debug('Failed badly to save')
81
- })
82
- }
83
-
84
- private debounce(fn: Function) {
85
- return () => {
86
- clearTimeout(this.timeoutId)
87
- this.timeoutId = setTimeout(() => fn(), 1000)
88
- }
89
- }
90
-
91
- }
92
-
93
- // --------------
94
- // Initialization
95
- // --------------
96
-
97
- document.addEventListener('DOMContentLoaded', () => {
98
- document.querySelectorAll<HTMLElement>('.js-formatic-string').forEach((el) => {
99
- console.debug('Instantiating Formatic.String...')
100
- new Formatic.String(el)
101
- })
102
- })
103
- }
@@ -1,112 +0,0 @@
1
- namespace Formatic {
2
- export class Textarea {
3
- private el: HTMLElement
4
- private timeoutId: ReturnType<typeof setTimeout>
5
-
6
- constructor(el: HTMLElement) {
7
- this.el = el
8
- this.setupBindings()
9
- }
10
-
11
- private setupBindings() {
12
- this.autosize()
13
-
14
- this.el.addEventListener('input', (event) => {
15
- event.preventDefault()
16
- if (this.autoSubmit) this.actionSave()
17
- })
18
- }
19
-
20
- // ACTIONS
21
-
22
- private actionSave() {
23
- this.guiWaitingForSave()
24
- this.debounce(this.actionSaveNow.bind(this))()
25
- }
26
-
27
- private actionSaveNow() {
28
- console.debug("Saving textarea...")
29
- this.el.classList.remove('is-loading')
30
- this.el.classList.add('is-saved')
31
- this.save()
32
- }
33
-
34
- // GUI
35
-
36
- private guiWaitingForSave() {
37
- this.el.classList.add('is-loading')
38
- this.el.classList.remove('is-saved')
39
- this.el.classList.remove('is-failed')
40
- }
41
-
42
- private guiSaved() {
43
- this.el.classList.remove('is-loading')
44
- this.el.classList.add('is-saved')
45
- this.el.classList.remove('is-failed')
46
- }
47
-
48
- private guiFailed() {
49
- this.el.classList.remove('is-loading')
50
- this.el.classList.remove('is-saved')
51
- this.el.classList.add('is-failed')
52
- }
53
-
54
- // Attributes
55
-
56
- private get autoSubmit() {
57
- return this.el.classList.contains('is-autosubmit')
58
- }
59
-
60
- // Helpers
61
-
62
- private save() {
63
- const form = this.el.closest<HTMLFormElement>('form')
64
- const data = new FormData(form)
65
- data.set('_method', 'patch')
66
-
67
- fetch(form.action, {
68
- method: 'POST',
69
- headers: { 'Accept': 'text/javascript' },
70
- body: data
71
- })
72
- .then(response => {
73
- if (response.status == 201) {
74
- console.debug('Textarea content saved')
75
- this.guiSaved()
76
- } else {
77
- console.debug('Textarea content not saved')
78
- this.guiFailed()
79
- }
80
- }).catch(err => {
81
- console.warn(err)
82
- console.debug('Failed badly to save')
83
- })
84
- }
85
-
86
- private debounce(fn: Function) {
87
- return () => {
88
- clearTimeout(this.timeoutId)
89
- this.timeoutId = setTimeout(() => fn(), 1000)
90
- }
91
- }
92
-
93
- private autosize() {
94
- try {
95
- autosize(this.el) // External library.
96
- } catch (error) {
97
- console.warn(`Formatic is missing the autosize library`)
98
- }
99
- }
100
- }
101
-
102
- // --------------
103
- // Initialization
104
- // --------------
105
-
106
- document.addEventListener('DOMContentLoaded', () => {
107
- document.querySelectorAll<HTMLElement>('.js-formatic-textarea').forEach((el) => {
108
- console.debug('Instantiating Formatic.Textarea...')
109
- new Formatic.Textarea(el)
110
- })
111
- })
112
- }
@@ -1,89 +0,0 @@
1
- namespace Formatic {
2
- export class Toggle {
3
-
4
- private el: HTMLElement
5
-
6
- constructor(el: HTMLElement) {
7
- this.el = el
8
- this.setupBindings()
9
- }
10
-
11
- private setupBindings() {
12
- this.checkbox.addEventListener('click', (event) => {
13
- event.preventDefault()
14
- const box = <HTMLInputElement>event.target
15
- box.checked ? this.activate(box) : this.deactivate(box)
16
- })
17
- }
18
-
19
- private activate(box: HTMLInputElement) {
20
- const form = box.closest<HTMLFormElement>('form')
21
- const data = new FormData(form)
22
- data.set('_method', 'patch')
23
-
24
- fetch(form.action, {
25
- method: 'POST',
26
- headers: { 'Accept': 'text/javascript' },
27
- body: data
28
- })
29
- .then(response => {
30
- // For accurate user feedback, we make sure this is not an accidental 200.
31
- // Your controller needs to respond with 201 on create/update.
32
- if (response.status == 201) {
33
- console.debug('Activation confirmed')
34
- box.checked = true
35
- } else {
36
- console.debug('Activation not confirmed')
37
- console.log("Activation denied")
38
- }
39
- }).catch(err => {
40
- console.warn(err)
41
- console.debug('Failed badly to activate')
42
- })
43
- }
44
-
45
- private deactivate(box: HTMLInputElement) {
46
- const form = box.closest<HTMLFormElement>('form')
47
- const data = new FormData(form)
48
- data.set('_method', 'delete')
49
-
50
- fetch(form.action, {
51
- method: 'POST',
52
- headers: { 'Accept': 'text/javascript' },
53
- body: data
54
- })
55
- .then(response => {
56
- // Your controller needs to respond with 204 on destroy.
57
- if (response.status == 204) {
58
- console.debug('Deactivation confirmed')
59
- box.checked = false
60
- } else {
61
- console.debug('Deactivation not confirmed')
62
- console.log("Deactivation denied")
63
- }
64
- }).catch(err => {
65
- console.warn(err)
66
- console.debug('Failed badly to deactivate')
67
- })
68
- }
69
-
70
- // ------------
71
- // DOM Elements
72
- // ------------
73
-
74
- private get checkbox() {
75
- return this.el.querySelector<HTMLInputElement>('input[type="checkbox"]')
76
- }
77
- }
78
- }
79
-
80
- // --------------
81
- // Initialization
82
- // --------------
83
-
84
- document.addEventListener('DOMContentLoaded', () => {
85
- document.querySelectorAll<HTMLElement>('.js-formatic-toggle').forEach((el) => {
86
- console.debug('Instantiating Formatic::Toggle...')
87
- new Formatic.Toggle(el)
88
- })
89
- })