formatic 0.2.3 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/app/assets/javascript/declarations/date.d.ts +9 -0
- data/app/assets/javascript/declarations/file.d.ts +16 -0
- data/app/assets/javascript/declarations/select.d.ts +15 -0
- data/app/assets/javascript/declarations/setup.d.ts +1 -0
- data/app/assets/javascript/declarations/stepper.d.ts +12 -0
- data/app/assets/javascript/declarations/string.d.ts +14 -0
- data/app/assets/javascript/declarations/textarea.d.ts +15 -0
- data/app/assets/javascript/declarations/toggle.d.ts +8 -0
- data/app/assets/javascript/formatic/date.js +30 -0
- data/app/assets/javascript/formatic/date.js.map +1 -0
- data/app/assets/javascript/formatic/file.js +100 -0
- data/app/assets/javascript/formatic/file.js.map +1 -0
- data/app/assets/javascript/formatic/select.js +81 -0
- data/app/assets/javascript/formatic/select.js.map +1 -0
- data/app/assets/javascript/formatic/setup.js +44 -0
- data/app/assets/javascript/formatic/stepper.js +67 -0
- data/app/assets/javascript/formatic/stepper.js.map +1 -0
- data/app/assets/javascript/formatic/string.js +71 -0
- data/app/assets/javascript/formatic/string.js.map +1 -0
- data/app/assets/javascript/formatic/textarea.js +81 -0
- data/app/assets/javascript/formatic/textarea.js.map +1 -0
- data/app/assets/javascript/formatic/toggle.js +63 -0
- data/app/assets/javascript/formatic/toggle.js.map +1 -0
- data/app/assets/javascript/src/date.ts +41 -0
- data/app/assets/javascript/src/file.ts +122 -0
- data/app/assets/javascript/src/select.ts +101 -0
- data/app/assets/javascript/src/stepper.ts +80 -0
- data/app/assets/javascript/src/string.ts +89 -0
- data/app/assets/javascript/src/textarea.ts +101 -0
- data/app/assets/javascript/src/toggle.ts +76 -0
- data/app/assets/stylesheets/formatic/components/date.sass +2 -2
- data/app/assets/stylesheets/formatic/formatic.css +450 -0
- data/app/assets/stylesheets/formatic/vendor.css +1107 -0
- data/app/assets/stylesheets/formatic.sass +17 -0
- data/app/assets/stylesheets/vendor.sass +1 -0
- data/app/components/formatic/base.rb +10 -1
- data/app/components/formatic/checklist.rb +6 -2
- data/app/components/formatic/date.rb +1 -1
- data/app/components/formatic/file.rb +27 -0
- data/app/components/formatic/files.rb +8 -0
- data/app/components/formatic/select.rb +1 -1
- data/app/components/formatic/textarea.rb +7 -3
- data/app/components/formatic/time.rb +3 -3
- data/config/importmap.rb +11 -0
- data/lib/formatic/choices/options.rb +1 -1
- data/lib/formatic/choices/records.rb +1 -1
- data/lib/formatic/engine.rb +24 -0
- data/lib/formatic/version.rb +1 -1
- data/lib/formatic/wrappers/required.rb +1 -1
- data/lib/formatic.rb +2 -1
- data/vscode/formatic.code-snippets +58 -0
- metadata +56 -17
- data/app/assets/javascript/formatic/components/date.ts +0 -54
- data/app/assets/javascript/formatic/components/select.ts +0 -113
- data/app/assets/javascript/formatic/components/stepper.ts +0 -89
- data/app/assets/javascript/formatic/components/string.ts +0 -103
- data/app/assets/javascript/formatic/components/textarea.ts +0 -112
- data/app/assets/javascript/formatic/components/toggle.ts +0 -89
- data/app/assets/javascript/formatic.js +0 -446
- data/app/assets/javascript/formatic.js.map +0 -1
- data/app/assets/stylesheets/formatic/index.sass +0 -17
- data/app/assets/stylesheets/formatic/package.json +0 -5
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// ITCSS
|
|
2
|
+
|
|
3
|
+
@use "formatic/generics/flip.sass"
|
|
4
|
+
|
|
5
|
+
@use "formatic/components/wrapper.sass" // Wrapper comes first, rest alphabetically
|
|
6
|
+
@use "formatic/components/checklist.sass"
|
|
7
|
+
@use "formatic/components/date.sass"
|
|
8
|
+
@use "formatic/components/select.sass"
|
|
9
|
+
@use "formatic/components/stepper.sass"
|
|
10
|
+
@use "formatic/components/string.sass"
|
|
11
|
+
@use "formatic/components/textarea.sass"
|
|
12
|
+
@use "formatic/components/time.sass"
|
|
13
|
+
@use "formatic/components/toggle.sass"
|
|
14
|
+
|
|
15
|
+
@use "formatic/utilities/container"
|
|
16
|
+
|
|
17
|
+
@use "formatic/scopes/form"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@use "filepond"
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
module Formatic
|
|
4
4
|
# All inputs inherit from this class.
|
|
5
5
|
class Base < ApplicationComponent
|
|
6
|
+
# You can render something within the wrapper, after the input.
|
|
7
|
+
renders_one :footer
|
|
8
|
+
|
|
6
9
|
# Rails form builder. Usually with a model as `f.object`.
|
|
7
10
|
option :f
|
|
8
11
|
|
|
@@ -17,6 +20,9 @@ module Formatic
|
|
|
17
20
|
# If not passed in, it is derived from the form object.
|
|
18
21
|
option :value, as: :manual_value, default: -> { :_fetch_from_record }
|
|
19
22
|
|
|
23
|
+
# Custom Data-attributes for the <input>
|
|
24
|
+
option :data, as: :manual_data, default: -> { {} }
|
|
25
|
+
|
|
20
26
|
# CSS class(es) applied to the <input> element
|
|
21
27
|
# and the wrapper <div> respectively.
|
|
22
28
|
option :class, as: :manual_class, optional: true
|
|
@@ -25,6 +31,9 @@ module Formatic
|
|
|
25
31
|
# For inputs that support `<input autofocus=...>`
|
|
26
32
|
option :autofocus, default: -> { false }
|
|
27
33
|
|
|
34
|
+
# Multiple records are submitted via one input.
|
|
35
|
+
option :multiple, default: -> { false }
|
|
36
|
+
|
|
28
37
|
# Some inputs (such as checkboxes and textfields)
|
|
29
38
|
# can be submitted continously by submitting their <form>
|
|
30
39
|
# via javascript.
|
|
@@ -68,7 +77,7 @@ module Formatic
|
|
|
68
77
|
|
|
69
78
|
# # Name of the URL param for this input.
|
|
70
79
|
def input_name
|
|
71
|
-
"#{param_key}[#{attribute_name}]"
|
|
80
|
+
"#{param_key}[#{attribute_name}]#{'[]' if multiple}"
|
|
72
81
|
end
|
|
73
82
|
end
|
|
74
83
|
end
|
|
@@ -27,10 +27,10 @@ module Formatic
|
|
|
27
27
|
<% wrap.with_input do %>
|
|
28
28
|
<div class="c-formatic-checklist s-formatic">
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
<%= f.collection_check_boxes(attribute_name, choices, :last, :first) do |builder| %>
|
|
31
31
|
|
|
32
32
|
<%= content_tag :div,
|
|
33
|
-
builder.label { builder.check_box(class: manual_class) + content_tag(:i) + content_tag(:span, split_and_wrap(builder.object.first)) },
|
|
33
|
+
builder.label { builder.check_box(class: manual_class, data:) + content_tag(:i) + content_tag(:span, split_and_wrap(builder.object.first)) },
|
|
34
34
|
class: 'c-formatic-toggle' %>
|
|
35
35
|
|
|
36
36
|
<% end %>
|
|
@@ -52,6 +52,10 @@ module Formatic
|
|
|
52
52
|
)
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
+
def data
|
|
56
|
+
manual_data
|
|
57
|
+
end
|
|
58
|
+
|
|
55
59
|
def split_and_wrap(string)
|
|
56
60
|
parts = string.split(' ')
|
|
57
61
|
return parts.first if parts.size == 1
|
|
@@ -104,7 +104,7 @@ module Formatic
|
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
def collection_for_month
|
|
107
|
-
result = (1..12).map { [l(::Date.new(1,
|
|
107
|
+
result = (1..12).map { [l(::Date.new(1, it), format: '%B %-m'), it] }
|
|
108
108
|
result.prepend([nil, nil]) if wrapper.optional?
|
|
109
109
|
result
|
|
110
110
|
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Formatic
|
|
4
|
+
# File upload
|
|
5
|
+
class File < ::Formatic::Base
|
|
6
|
+
option :direct_upload, default: -> { true }
|
|
7
|
+
option :multiple, default: -> { false }
|
|
8
|
+
option :accept, default: -> {}
|
|
9
|
+
|
|
10
|
+
# TODO: Make the hidden_field (form validations) work with multiple: true
|
|
11
|
+
erb_template <<~ERB
|
|
12
|
+
<%= render wrapper do |wrap| %>
|
|
13
|
+
|
|
14
|
+
<% wrap.with_input do %>
|
|
15
|
+
|
|
16
|
+
<div class="c-formatic-file js-formatic-file">
|
|
17
|
+
<%- if value.present? && value.attached? -%>
|
|
18
|
+
<%= f.hidden_field attribute_name, value: value.signed_id %>
|
|
19
|
+
<%- end -%>
|
|
20
|
+
|
|
21
|
+
<%= f.file_field attribute_name, class: "js-formatic-file__input", direct_upload:, multiple:, accept: %>
|
|
22
|
+
</div>
|
|
23
|
+
<% end %>
|
|
24
|
+
<% end %>
|
|
25
|
+
ERB
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
module Formatic
|
|
4
4
|
# Text input for multi-line text.
|
|
5
5
|
class Textarea < ::Formatic::Base
|
|
6
|
-
renders_one :footer
|
|
7
|
-
|
|
8
6
|
erb_template <<~ERB
|
|
9
7
|
<%= render wrapper do |wrap| -%>
|
|
10
8
|
|
|
@@ -21,6 +19,8 @@ module Formatic
|
|
|
21
19
|
<%= f.text_area(attribute_name, **input_options) -%>
|
|
22
20
|
<% end -%>
|
|
23
21
|
|
|
22
|
+
<%= footer -%>
|
|
23
|
+
|
|
24
24
|
</div>
|
|
25
25
|
<% end -%>
|
|
26
26
|
<% end -%>
|
|
@@ -29,7 +29,7 @@ module Formatic
|
|
|
29
29
|
def input_options
|
|
30
30
|
result = {
|
|
31
31
|
placeholder: wrapper.placeholder,
|
|
32
|
-
data
|
|
32
|
+
data:,
|
|
33
33
|
autofocus:,
|
|
34
34
|
class: css_classes
|
|
35
35
|
}
|
|
@@ -39,6 +39,10 @@ module Formatic
|
|
|
39
39
|
result
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
def data
|
|
43
|
+
{ '1p-ignore' => true }.merge(manual_data)
|
|
44
|
+
end
|
|
45
|
+
|
|
42
46
|
def css_classes
|
|
43
47
|
classes = %i[c-formatic-textarea__input js-formatic-textarea]
|
|
44
48
|
classes.push(:'is-autosubmit') if async_submit
|
|
@@ -40,7 +40,7 @@ module Formatic
|
|
|
40
40
|
|
|
41
41
|
# Usually the time component is used below the date component (for a DateTime attribute).
|
|
42
42
|
# So, normally we don't want the label to be shown twice.
|
|
43
|
-
def label
|
|
43
|
+
def label # rubocop:disable Naming/PredicateMethod
|
|
44
44
|
false
|
|
45
45
|
end
|
|
46
46
|
|
|
@@ -76,7 +76,7 @@ module Formatic
|
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
def collection_for_hour
|
|
79
|
-
result = (0..23).map { [
|
|
79
|
+
result = (0..23).map { [it, it] }
|
|
80
80
|
result.prepend([nil, nil]) if wrapper.optional?
|
|
81
81
|
result
|
|
82
82
|
end
|
|
@@ -91,7 +91,7 @@ module Formatic
|
|
|
91
91
|
steps.sort!
|
|
92
92
|
end
|
|
93
93
|
|
|
94
|
-
result = steps.map { [
|
|
94
|
+
result = steps.map { [it.to_s.rjust(2, '0'), it] }
|
|
95
95
|
result.prepend([nil, nil]) if wrapper.optional?
|
|
96
96
|
result
|
|
97
97
|
end
|
data/config/importmap.rb
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
pin 'formatic', to: 'formatic/setup.js'
|
|
4
|
+
|
|
5
|
+
pin 'formatic/date', to: 'formatic/date.js'
|
|
6
|
+
pin 'formatic/file', to: 'formatic/file.js'
|
|
7
|
+
pin 'formatic/select', to: 'formatic/select.js'
|
|
8
|
+
pin 'formatic/stepper', to: 'formatic/stepper.js'
|
|
9
|
+
pin 'formatic/string', to: 'formatic/string.js'
|
|
10
|
+
pin 'formatic/textarea', to: 'formatic/textarea.js'
|
|
11
|
+
pin 'formatic/toggle', to: 'formatic/toggle.js'
|
|
@@ -32,7 +32,7 @@ module Formatic
|
|
|
32
32
|
return false unless model_klass.respond_to?(:reflect_on_all_associations)
|
|
33
33
|
|
|
34
34
|
model_klass.reflect_on_all_associations(:belongs_to)
|
|
35
|
-
.detect {
|
|
35
|
+
.detect { it.foreign_key == attribute_name.to_s }
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
end
|
|
@@ -40,7 +40,7 @@ module Formatic
|
|
|
40
40
|
return false unless model_klass.respond_to?(:reflect_on_all_associations)
|
|
41
41
|
|
|
42
42
|
model_klass.reflect_on_all_associations(:belongs_to)
|
|
43
|
-
.detect {
|
|
43
|
+
.detect { it.foreign_key == attribute_name.to_s }
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
end
|
data/lib/formatic/engine.rb
CHANGED
|
@@ -7,6 +7,30 @@ module Formatic
|
|
|
7
7
|
# :nodoc:
|
|
8
8
|
class Engine < ::Rails::Engine
|
|
9
9
|
isolate_namespace Formatic
|
|
10
|
+
config.autoload_paths << root.join('lib')
|
|
11
|
+
|
|
12
|
+
initializer 'formatic.importmap', before: 'importmap' do |app|
|
|
13
|
+
app.config.importmap.paths << Engine.root.join('config/importmap.rb')
|
|
14
|
+
# Watch JS changes in development
|
|
15
|
+
app.config.importmap.cache_sweepers << Engine.root.join('app/assets/javascript')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
initializer 'formatic.assets' do |app|
|
|
19
|
+
app.config.assets.paths << Engine.root.join('app/javascript')
|
|
20
|
+
app.config.assets.paths << Engine.root.join('app/stylesheets')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
initializer 'formatic.vscode_snippets', group: :all do |app|
|
|
24
|
+
app.config.after_initialize do
|
|
25
|
+
vscode_dir = Rails.root.join('.vscode')
|
|
26
|
+
next unless vscode_dir.directory?
|
|
27
|
+
|
|
28
|
+
target = vscode_dir.join('formatic.code-snippets')
|
|
29
|
+
source = Engine.root.join('vscode/formatic.code-snippets')
|
|
30
|
+
|
|
31
|
+
FileUtils.ln_s(source, target, force: true)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
10
34
|
|
|
11
35
|
config.to_prepare do
|
|
12
36
|
# Our Formatic components are subclasses of `ViewComponent::Base`.
|
data/lib/formatic/version.rb
CHANGED
data/lib/formatic.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require 'calls'
|
|
4
4
|
require 'countries'
|
|
5
5
|
require 'holidays'
|
|
6
|
+
require 'importmap-rails'
|
|
6
7
|
require 'dry/initializer'
|
|
7
8
|
|
|
8
9
|
require 'formatic/version'
|
|
@@ -20,7 +21,7 @@ require 'formatic/wrappers/required'
|
|
|
20
21
|
require 'formatic/wrappers/translate'
|
|
21
22
|
require 'formatic/wrappers/validators'
|
|
22
23
|
|
|
23
|
-
require 'formatic/engine'
|
|
24
|
+
require 'formatic/engine'
|
|
24
25
|
|
|
25
26
|
module Formatic
|
|
26
27
|
class Error < ::StandardError; end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"render Formatic::Checklist": {
|
|
3
|
+
"prefix": [
|
|
4
|
+
"fchecklist"
|
|
5
|
+
],
|
|
6
|
+
"body": [
|
|
7
|
+
"= render Formatic::Checklist.new(f:, attribute_name: $0)",
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
"render Formatic::String": {
|
|
11
|
+
"prefix": [
|
|
12
|
+
"fstring"
|
|
13
|
+
],
|
|
14
|
+
"body": [
|
|
15
|
+
"= render Formatic::String.new(f:, attribute_name: $0)",
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"render Formatic::Stepper": {
|
|
19
|
+
"prefix": [
|
|
20
|
+
"fstepper"
|
|
21
|
+
],
|
|
22
|
+
"body": [
|
|
23
|
+
"= render Formatic::Stepper.new(f:, attribute_name: $0)",
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
"render Formatic::Textarea": {
|
|
27
|
+
"prefix": [
|
|
28
|
+
"ftextarea"
|
|
29
|
+
],
|
|
30
|
+
"body": [
|
|
31
|
+
"= render Formatic::Textarea.new(f:, attribute_name: $0)",
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
"render Formatic::Toggle": {
|
|
35
|
+
"prefix": [
|
|
36
|
+
"ftoggle"
|
|
37
|
+
],
|
|
38
|
+
"body": [
|
|
39
|
+
"= render Formatic::Toggle.new(f:, attribute_name: $0)",
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
"render Formatic::Select": {
|
|
43
|
+
"prefix": [
|
|
44
|
+
"fselect"
|
|
45
|
+
],
|
|
46
|
+
"body": [
|
|
47
|
+
"= render Formatic::Select.new(f:, attribute_name: $0, records:)",
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
"render Formatic::Date": {
|
|
51
|
+
"prefix": [
|
|
52
|
+
"fdate"
|
|
53
|
+
],
|
|
54
|
+
"body": [
|
|
55
|
+
"= render Formatic::Date.new(f:, attribute_name: $0)",
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
}
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: formatic
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- halo
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: actionview
|
|
@@ -80,6 +79,20 @@ dependencies:
|
|
|
80
79
|
- - ">="
|
|
81
80
|
- !ruby/object:Gem::Version
|
|
82
81
|
version: '0'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: importmap-rails
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
type: :runtime
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
83
96
|
- !ruby/object:Gem::Dependency
|
|
84
97
|
name: view_component
|
|
85
98
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -104,14 +117,37 @@ files:
|
|
|
104
117
|
- CHANGELOG.md
|
|
105
118
|
- LICENSE.txt
|
|
106
119
|
- README.md
|
|
107
|
-
- app/assets/javascript/
|
|
108
|
-
- app/assets/javascript/
|
|
109
|
-
- app/assets/javascript/
|
|
110
|
-
- app/assets/javascript/
|
|
111
|
-
- app/assets/javascript/
|
|
112
|
-
- app/assets/javascript/
|
|
113
|
-
- app/assets/javascript/
|
|
114
|
-
- app/assets/javascript/
|
|
120
|
+
- app/assets/javascript/declarations/date.d.ts
|
|
121
|
+
- app/assets/javascript/declarations/file.d.ts
|
|
122
|
+
- app/assets/javascript/declarations/select.d.ts
|
|
123
|
+
- app/assets/javascript/declarations/setup.d.ts
|
|
124
|
+
- app/assets/javascript/declarations/stepper.d.ts
|
|
125
|
+
- app/assets/javascript/declarations/string.d.ts
|
|
126
|
+
- app/assets/javascript/declarations/textarea.d.ts
|
|
127
|
+
- app/assets/javascript/declarations/toggle.d.ts
|
|
128
|
+
- app/assets/javascript/formatic/date.js
|
|
129
|
+
- app/assets/javascript/formatic/date.js.map
|
|
130
|
+
- app/assets/javascript/formatic/file.js
|
|
131
|
+
- app/assets/javascript/formatic/file.js.map
|
|
132
|
+
- app/assets/javascript/formatic/select.js
|
|
133
|
+
- app/assets/javascript/formatic/select.js.map
|
|
134
|
+
- app/assets/javascript/formatic/setup.js
|
|
135
|
+
- app/assets/javascript/formatic/stepper.js
|
|
136
|
+
- app/assets/javascript/formatic/stepper.js.map
|
|
137
|
+
- app/assets/javascript/formatic/string.js
|
|
138
|
+
- app/assets/javascript/formatic/string.js.map
|
|
139
|
+
- app/assets/javascript/formatic/textarea.js
|
|
140
|
+
- app/assets/javascript/formatic/textarea.js.map
|
|
141
|
+
- app/assets/javascript/formatic/toggle.js
|
|
142
|
+
- app/assets/javascript/formatic/toggle.js.map
|
|
143
|
+
- app/assets/javascript/src/date.ts
|
|
144
|
+
- app/assets/javascript/src/file.ts
|
|
145
|
+
- app/assets/javascript/src/select.ts
|
|
146
|
+
- app/assets/javascript/src/stepper.ts
|
|
147
|
+
- app/assets/javascript/src/string.ts
|
|
148
|
+
- app/assets/javascript/src/textarea.ts
|
|
149
|
+
- app/assets/javascript/src/toggle.ts
|
|
150
|
+
- app/assets/stylesheets/formatic.sass
|
|
115
151
|
- app/assets/stylesheets/formatic/components/checklist.sass
|
|
116
152
|
- app/assets/stylesheets/formatic/components/date.sass
|
|
117
153
|
- app/assets/stylesheets/formatic/components/select.sass
|
|
@@ -121,9 +157,8 @@ files:
|
|
|
121
157
|
- app/assets/stylesheets/formatic/components/time.sass
|
|
122
158
|
- app/assets/stylesheets/formatic/components/toggle.sass
|
|
123
159
|
- app/assets/stylesheets/formatic/components/wrapper.sass
|
|
160
|
+
- app/assets/stylesheets/formatic/formatic.css
|
|
124
161
|
- app/assets/stylesheets/formatic/generics/flip.sass
|
|
125
|
-
- app/assets/stylesheets/formatic/index.sass
|
|
126
|
-
- app/assets/stylesheets/formatic/package.json
|
|
127
162
|
- app/assets/stylesheets/formatic/scopes/form.sass
|
|
128
163
|
- app/assets/stylesheets/formatic/settings/_colors.sass
|
|
129
164
|
- app/assets/stylesheets/formatic/tools/_cloud.sass
|
|
@@ -131,10 +166,14 @@ files:
|
|
|
131
166
|
- app/assets/stylesheets/formatic/tools/_terminal.sass
|
|
132
167
|
- app/assets/stylesheets/formatic/tools/_theme.sass
|
|
133
168
|
- app/assets/stylesheets/formatic/utilities/container.sass
|
|
169
|
+
- app/assets/stylesheets/formatic/vendor.css
|
|
170
|
+
- app/assets/stylesheets/vendor.sass
|
|
134
171
|
- app/components/formatic/application_component.rb
|
|
135
172
|
- app/components/formatic/base.rb
|
|
136
173
|
- app/components/formatic/checklist.rb
|
|
137
174
|
- app/components/formatic/date.rb
|
|
175
|
+
- app/components/formatic/file.rb
|
|
176
|
+
- app/components/formatic/files.rb
|
|
138
177
|
- app/components/formatic/select.rb
|
|
139
178
|
- app/components/formatic/stepper.rb
|
|
140
179
|
- app/components/formatic/string.rb
|
|
@@ -142,6 +181,7 @@ files:
|
|
|
142
181
|
- app/components/formatic/time.rb
|
|
143
182
|
- app/components/formatic/toggle.rb
|
|
144
183
|
- app/components/formatic/wrapper.rb
|
|
184
|
+
- config/importmap.rb
|
|
145
185
|
- config/locales/formatic.de.yml
|
|
146
186
|
- config/locales/formatic.en.yml
|
|
147
187
|
- lib/formatic.rb
|
|
@@ -162,6 +202,7 @@ files:
|
|
|
162
202
|
- lib/formatic/wrappers/required.rb
|
|
163
203
|
- lib/formatic/wrappers/translate.rb
|
|
164
204
|
- lib/formatic/wrappers/validators.rb
|
|
205
|
+
- vscode/formatic.code-snippets
|
|
165
206
|
homepage: https://github.com/halo/formatic
|
|
166
207
|
licenses:
|
|
167
208
|
- MIT
|
|
@@ -170,7 +211,6 @@ metadata:
|
|
|
170
211
|
source_code_uri: https://github.com/halo/formatic
|
|
171
212
|
changelog_uri: https://github.com/halo/halo/blob/main/CHANGELOG.md
|
|
172
213
|
rubygems_mfa_required: 'true'
|
|
173
|
-
post_install_message:
|
|
174
214
|
rdoc_options: []
|
|
175
215
|
require_paths:
|
|
176
216
|
- lib
|
|
@@ -178,15 +218,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
178
218
|
requirements:
|
|
179
219
|
- - ">="
|
|
180
220
|
- !ruby/object:Gem::Version
|
|
181
|
-
version: 3.
|
|
221
|
+
version: 3.4.0
|
|
182
222
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
223
|
requirements:
|
|
184
224
|
- - ">="
|
|
185
225
|
- !ruby/object:Gem::Version
|
|
186
226
|
version: '0'
|
|
187
227
|
requirements: []
|
|
188
|
-
rubygems_version:
|
|
189
|
-
signing_key:
|
|
228
|
+
rubygems_version: 4.0.1
|
|
190
229
|
specification_version: 4
|
|
191
230
|
summary: A set of ViewComponents for form elements
|
|
192
231
|
test_files: []
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
namespace Formatic {
|
|
2
|
-
export class Date {
|
|
3
|
-
private el: HTMLElement
|
|
4
|
-
|
|
5
|
-
constructor(el: HTMLElement) {
|
|
6
|
-
this.el = el
|
|
7
|
-
this.setupBindings()
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
private setupBindings() {
|
|
11
|
-
this.shortcutButtons.forEach((el) => {
|
|
12
|
-
el.addEventListener('click', (event) => {
|
|
13
|
-
event.preventDefault()
|
|
14
|
-
const shortcut = <HTMLInputElement>event.currentTarget
|
|
15
|
-
|
|
16
|
-
this.dayInput.value = shortcut.dataset.day
|
|
17
|
-
this.monthInput.value = shortcut.dataset.month
|
|
18
|
-
this.yearInput.value = shortcut.dataset.year
|
|
19
|
-
})
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// ------------
|
|
24
|
-
// DOM Elements
|
|
25
|
-
// ------------
|
|
26
|
-
|
|
27
|
-
private get dayInput() {
|
|
28
|
-
return this.el.querySelector<HTMLSelectElement>('.js-formatic-date__day')
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
private get monthInput() {
|
|
32
|
-
return this.el.querySelector<HTMLSelectElement>('.js-formatic-date__month')
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
private get yearInput() {
|
|
36
|
-
return this.el.querySelector<HTMLSelectElement>('.js-formatic-date__year')
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
private get shortcutButtons() {
|
|
40
|
-
return this.el.querySelectorAll<HTMLElement>('.js-formatic-date__shortcut')
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// --------------
|
|
46
|
-
// Initialization
|
|
47
|
-
// --------------
|
|
48
|
-
|
|
49
|
-
document.addEventListener('DOMContentLoaded', () => {
|
|
50
|
-
document.querySelectorAll<HTMLElement>('.js-formatic-date').forEach((el) => {
|
|
51
|
-
console.debug('Instantiating Formatic.Date...')
|
|
52
|
-
new Formatic.Date(el)
|
|
53
|
-
})
|
|
54
|
-
})
|
|
@@ -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
|
-
|