katalyst-govuk-formbuilder 1.30.0 → 2.0.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.
- checksums.yaml +4 -4
- data/README.md +141 -15
- data/app/assets/builds/katalyst/govuk/formbuilder.css +77 -0
- data/app/assets/builds/katalyst/govuk/formbuilder.js +573 -10
- data/app/assets/builds/katalyst/govuk/formbuilder.min.js +8 -8
- data/app/assets/builds/katalyst/govuk/formbuilder.min.js.map +1 -1
- data/app/assets/stylesheets/katalyst/govuk/components/_index.scss +1 -0
- data/app/assets/stylesheets/katalyst/govuk/components/attachment/_index.scss +3 -0
- data/app/assets/stylesheets/katalyst/govuk/components/attachment/_mixin.scss +89 -0
- data/app/helpers/katalyst/govuk/form_builder/builder.rb +504 -0
- data/app/helpers/katalyst/govuk/form_builder/containers/fieldset_context.rb +19 -0
- data/app/helpers/katalyst/govuk/form_builder/elements/attachment.rb +80 -0
- data/app/helpers/katalyst/govuk/form_builder/elements/combobox.rb +85 -0
- data/app/helpers/katalyst/govuk/form_builder/elements/document.rb +68 -0
- data/app/helpers/katalyst/govuk/form_builder/elements/image.rb +65 -0
- data/app/helpers/katalyst/govuk/form_builder/elements/label.rb +38 -0
- data/app/helpers/katalyst/govuk/form_builder/elements/legend.rb +32 -0
- data/app/helpers/katalyst/govuk/form_builder/elements/rich_textarea.rb +70 -0
- data/app/helpers/katalyst/govuk/form_builder/frontend.rb +34 -0
- data/app/helpers/katalyst/govuk/form_builder/traits/attachment.rb +215 -0
- data/app/helpers/katalyst/govuk/form_builder/traits/file.rb +104 -0
- data/app/helpers/katalyst/govuk/form_builder/traits/label.rb +33 -0
- data/config/importmap.rb +1 -0
- data/config/locales/en.yml +16 -0
- data/lib/katalyst/govuk/form_builder/config.rb +20 -0
- data/lib/katalyst/govuk/form_builder/engine.rb +1 -1
- metadata +31 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "govuk_design_system_formbuilder"
|
|
4
|
+
|
|
5
|
+
module Katalyst
|
|
6
|
+
module GOVUK
|
|
7
|
+
module FormBuilder
|
|
8
|
+
module Traits
|
|
9
|
+
module File
|
|
10
|
+
extend ActiveSupport::Concern
|
|
11
|
+
|
|
12
|
+
protected
|
|
13
|
+
|
|
14
|
+
def stimulus_controller_actions
|
|
15
|
+
<<~ACTIONS.gsub(/\s+/, " ").freeze
|
|
16
|
+
dragover->#{stimulus_controller}#dragover
|
|
17
|
+
dragenter->#{stimulus_controller}#dragenter
|
|
18
|
+
dragleave->#{stimulus_controller}#dragleave
|
|
19
|
+
drop->#{stimulus_controller}#drop
|
|
20
|
+
ACTIONS
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def file
|
|
24
|
+
previous_input = @builder.hidden_field(@attribute_name, id: nil, value: value.signed_id) if attached?
|
|
25
|
+
file_input = @builder.file_field(@attribute_name, attributes(@html_attributes))
|
|
26
|
+
|
|
27
|
+
safe_join([previous_input, file_input])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def destroy_element
|
|
31
|
+
return if @html_attributes[:optional].blank?
|
|
32
|
+
|
|
33
|
+
@builder.fields_for(:"#{@attribute_name}_attachment") do |form|
|
|
34
|
+
form.hidden_field :_destroy, value: false, data: { "#{stimulus_controller}_target" => "destroy" }
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def destroy_element_trigger
|
|
39
|
+
return if @html_attributes[:optional].blank?
|
|
40
|
+
|
|
41
|
+
content_tag(:button, "", class: "file-destroy", data: { action: "#{stimulus_controller}#setDestroy" })
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def preview_url
|
|
45
|
+
preview? ? main_app.polymorphic_path(value, only_path: true) : ""
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def preview?
|
|
49
|
+
attached?
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def attached?
|
|
53
|
+
value&.attached? && value.blob.persisted?
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def value
|
|
57
|
+
@builder.object.send(@attribute_name)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def file_input_options
|
|
61
|
+
default_file_input_options = options
|
|
62
|
+
|
|
63
|
+
add_option(default_file_input_options, :accept, @mime_types.join(","))
|
|
64
|
+
add_option(default_file_input_options, :data, :action, "change->#{stimulus_controller}#onUpload")
|
|
65
|
+
|
|
66
|
+
default_file_input_options
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def options
|
|
70
|
+
{
|
|
71
|
+
id: field_id(link_errors: true),
|
|
72
|
+
class: classes,
|
|
73
|
+
aria: { describedby: combine_references(hint_id, error_id) },
|
|
74
|
+
}
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
using GOVUKDesignSystemFormBuilder::PrefixableArray
|
|
78
|
+
|
|
79
|
+
def classes
|
|
80
|
+
build_classes(%(file-upload), %(file-upload--error) => has_errors?).prefix(brand)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def default_form_group_options(**form_group_options)
|
|
84
|
+
add_option(form_group_options, :class, "govuk-form-group #{form_group_class}")
|
|
85
|
+
add_option(form_group_options, :data, :controller, stimulus_controller)
|
|
86
|
+
add_option(form_group_options, :data, :action, stimulus_controller_actions)
|
|
87
|
+
add_option(form_group_options, :data, :"#{stimulus_controller}_mime_types_value",
|
|
88
|
+
@mime_types.to_json)
|
|
89
|
+
|
|
90
|
+
form_group_options
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def add_option(options, key, *path)
|
|
94
|
+
if path.length > 1
|
|
95
|
+
add_option(options[key] ||= {}, *path)
|
|
96
|
+
else
|
|
97
|
+
options[key] = [options[key], *path].compact.join(" ")
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "govuk_design_system_formbuilder"
|
|
4
|
+
|
|
5
|
+
module Katalyst
|
|
6
|
+
module GOVUK
|
|
7
|
+
module FormBuilder
|
|
8
|
+
module Traits
|
|
9
|
+
# Extend GovukDesignSystemFormBuilder::Traits::Label set the default size to small for non-nested labels.
|
|
10
|
+
module Label
|
|
11
|
+
extend ActiveSupport::Concern
|
|
12
|
+
|
|
13
|
+
included do
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def label_content
|
|
17
|
+
default = @builder.fieldset_context.any? ? {} : { size: "s" }
|
|
18
|
+
|
|
19
|
+
case @label
|
|
20
|
+
when Hash
|
|
21
|
+
default.merge(@label)
|
|
22
|
+
when Proc
|
|
23
|
+
default.merge(content: @label)
|
|
24
|
+
else
|
|
25
|
+
fail(ArgumentError, %(label must be a Proc or Hash))
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/config/importmap.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
pin "@katalyst/govuk-formbuilder", to: "katalyst/govuk/formbuilder.js"
|
|
4
|
+
pin "@rails/activestorage", to: "activestorage.esm.js"
|
|
4
5
|
|
|
5
6
|
pin_all_from Katalyst::GOVUK::FormBuilder::Engine.root.join("app/assets/javascripts"),
|
|
6
7
|
# preload in tests so that we don't start clicking before controllers load
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# The attachment field's string defaults — the canonical vocabulary.
|
|
2
|
+
# The JS bundle carries a mirror of this table as its offline defaults
|
|
3
|
+
# (app/javascript/katalyst/govuk/config.js); keep the two in step.
|
|
4
|
+
# Strings that differ from these defaults — a translation, or a host
|
|
5
|
+
# app's override in any locale, en included — render onto the field's
|
|
6
|
+
# data-i18n.* attributes, where the JS enhancement reads them.
|
|
7
|
+
en:
|
|
8
|
+
katalyst:
|
|
9
|
+
govuk:
|
|
10
|
+
attachment:
|
|
11
|
+
upload_succeeded: "Uploaded successfully"
|
|
12
|
+
upload_failed: "Upload failed — try again"
|
|
13
|
+
retry_button: "Try again"
|
|
14
|
+
file_removed: "%{filename} removed"
|
|
15
|
+
remove_button: "Remove %{filename}"
|
|
16
|
+
remove_button_content: "Remove"
|
|
@@ -26,6 +26,26 @@ module Katalyst
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
config.image_mime_types = %w[image/png image/gif image/jpeg image/webp].freeze
|
|
29
|
+
|
|
30
|
+
def attachment_preview_representation
|
|
31
|
+
config.attachment_preview_representation
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def attachment_preview_representation=(value)
|
|
35
|
+
config.attachment_preview_representation = value
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
config.attachment_preview_representation = { resize_to_fill: [256, 256] }.freeze
|
|
39
|
+
|
|
40
|
+
def use_legacy_file_fields?
|
|
41
|
+
config.use_legacy_file_fields
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def use_legacy_file_fields=(value)
|
|
45
|
+
config.use_legacy_file_fields = value
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
config.use_legacy_file_fields = false
|
|
29
49
|
end
|
|
30
50
|
end
|
|
31
51
|
end
|
|
@@ -43,7 +43,7 @@ module Katalyst
|
|
|
43
43
|
initializer "katalyst-govuk-formbuilder.importmap", before: "importmap" do |app|
|
|
44
44
|
if app.config.respond_to?(:importmap)
|
|
45
45
|
app.config.importmap.paths << root.join("config/importmap.rb")
|
|
46
|
-
app.config.importmap.cache_sweepers << root.join("app/assets/
|
|
46
|
+
app.config.importmap.cache_sweepers << root.join("app/assets/builds")
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: katalyst-govuk-formbuilder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Katalyst Interactive
|
|
@@ -9,6 +9,20 @@ bindir: bin
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: activestorage
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 8.0.0
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 8.0.0
|
|
12
26
|
- !ruby/object:Gem::Dependency
|
|
13
27
|
name: govuk_design_system_formbuilder
|
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -38,13 +52,29 @@ files:
|
|
|
38
52
|
- app/assets/builds/katalyst/govuk/formbuilder.min.js.map
|
|
39
53
|
- app/assets/config/katalyst-govuk-formbuilder.js
|
|
40
54
|
- app/assets/stylesheets/katalyst/govuk/components/_index.scss
|
|
55
|
+
- app/assets/stylesheets/katalyst/govuk/components/attachment/_index.scss
|
|
56
|
+
- app/assets/stylesheets/katalyst/govuk/components/attachment/_mixin.scss
|
|
41
57
|
- app/assets/stylesheets/katalyst/govuk/components/combobox/_index.scss
|
|
42
58
|
- app/assets/stylesheets/katalyst/govuk/components/combobox/_mixin.scss
|
|
43
59
|
- app/assets/stylesheets/katalyst/govuk/components/richtextarea/_index.scss
|
|
44
60
|
- app/assets/stylesheets/katalyst/govuk/components/richtextarea/_mixin.scss
|
|
45
61
|
- app/assets/stylesheets/katalyst/govuk/formbuilder.scss
|
|
62
|
+
- app/helpers/katalyst/govuk/form_builder/builder.rb
|
|
63
|
+
- app/helpers/katalyst/govuk/form_builder/containers/fieldset_context.rb
|
|
64
|
+
- app/helpers/katalyst/govuk/form_builder/elements/attachment.rb
|
|
65
|
+
- app/helpers/katalyst/govuk/form_builder/elements/combobox.rb
|
|
66
|
+
- app/helpers/katalyst/govuk/form_builder/elements/document.rb
|
|
67
|
+
- app/helpers/katalyst/govuk/form_builder/elements/image.rb
|
|
68
|
+
- app/helpers/katalyst/govuk/form_builder/elements/label.rb
|
|
69
|
+
- app/helpers/katalyst/govuk/form_builder/elements/legend.rb
|
|
70
|
+
- app/helpers/katalyst/govuk/form_builder/elements/rich_textarea.rb
|
|
71
|
+
- app/helpers/katalyst/govuk/form_builder/frontend.rb
|
|
72
|
+
- app/helpers/katalyst/govuk/form_builder/traits/attachment.rb
|
|
73
|
+
- app/helpers/katalyst/govuk/form_builder/traits/file.rb
|
|
74
|
+
- app/helpers/katalyst/govuk/form_builder/traits/label.rb
|
|
46
75
|
- config/ci.rb
|
|
47
76
|
- config/importmap.rb
|
|
77
|
+
- config/locales/en.yml
|
|
48
78
|
- lib/katalyst-govuk-formbuilder.rb
|
|
49
79
|
- lib/katalyst/govuk/form_builder.rb
|
|
50
80
|
- lib/katalyst/govuk/form_builder/config.rb
|