coveragebook_components 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/build/coco/app.css +7 -5
- data/app/assets/build/coco/app.js +95 -48
- data/app/assets/build/coco/book.css +3 -0
- data/app/assets/build/coco/book.js +2 -2
- data/app/assets/js/helpers/path.js +9 -1
- data/app/components/coco/app/blocks/slide_editor/slide_editor.css +4 -0
- data/app/components/coco/app/blocks/slide_editor/slide_editor.html.erb +145 -190
- data/app/components/coco/app/blocks/slide_editor/slide_editor.js +70 -17
- data/app/components/coco/app/blocks/slide_editor/slide_editor.rb +37 -86
- data/app/components/coco/app/elements/alert/alert.css +1 -1
- data/app/components/coco/app/elements/color_picker_button/color_picker_button.html.erb +17 -16
- data/app/components/coco/app/elements/color_picker_button/color_picker_button.js +0 -8
- data/app/components/coco/app/elements/color_picker_button/color_picker_button.rb +2 -15
- data/app/components/coco/app/elements/image_picker/image_picker.html.erb +4 -4
- data/app/components/coco/app/elements/image_picker/image_picker.js +18 -6
- data/app/components/coco/app/elements/image_picker/image_picker.rb +2 -11
- data/app/components/coco/app/elements/image_picker_button/image_picker_button.html.erb +9 -8
- data/app/components/coco/app/elements/image_picker_button/image_picker_button.js +10 -23
- data/app/components/coco/app/elements/image_picker_button/image_picker_button.rb +19 -35
- data/app/components/coco/app/elements/seamless_textarea/seamless_textarea.html.erb +7 -4
- data/app/components/coco/app/elements/seamless_textarea/seamless_textarea.js +9 -3
- data/app/components/coco/app/elements/seamless_textarea/seamless_textarea.rb +5 -20
- data/app/components/coco/base/image_uploader/image_uploader.html.erb +3 -2
- data/app/components/coco/base/image_uploader/image_uploader.rb +2 -12
- data/app/components/coco/book/blocks/slides/media_slide/media_slide.css +1 -1
- data/lib/coco.rb +1 -1
- metadata +2 -6
- data/app/assets/build/coco/app.dev.css +0 -3427
- data/app/assets/build/coco/app.dev.js +0 -24891
- data/app/assets/build/coco/book.dev.css +0 -992
- data/app/assets/build/coco/book.dev.js +0 -19840
@@ -6,119 +6,70 @@ module Coco
|
|
6
6
|
include Coco::BookHelper
|
7
7
|
include Coco::FormatHelper
|
8
8
|
|
9
|
-
renders_one :
|
10
|
-
add_field(:bg_color, name, input_options)
|
11
|
-
end
|
12
|
-
|
13
|
-
renders_one :text_color, ->(name: :text_color_hex, **input_options) do
|
14
|
-
add_field(:text_color, name, input_options)
|
15
|
-
end
|
16
|
-
|
17
|
-
renders_one :bg_image, ->(name: :bg_image, **input_options) do
|
18
|
-
add_field(:bg_image, name, input_options)
|
19
|
-
end
|
9
|
+
renders_one :form
|
20
10
|
|
21
|
-
renders_one :
|
22
|
-
|
11
|
+
renders_one :title, ->(value = nil, **textarea_options) do
|
12
|
+
Coco::App::Elements::SeamlessTextarea.new(**textarea_options,
|
13
|
+
value: value,
|
14
|
+
multiline: false,
|
15
|
+
focus: true,
|
16
|
+
data: {role: "title-editor"},
|
17
|
+
x: {modelable: "value", model: "title"})
|
23
18
|
end
|
24
19
|
|
25
|
-
renders_one :
|
26
|
-
|
20
|
+
renders_one :text_1, ->(value = nil, **textarea_options) do
|
21
|
+
Coco::App::Elements::SeamlessTextarea.new(**textarea_options,
|
22
|
+
value: value,
|
23
|
+
multiline: false,
|
24
|
+
data: {role: "text-1-editor"},
|
25
|
+
x: {modelable: "value", model: "text1"})
|
27
26
|
end
|
28
27
|
|
29
|
-
renders_one :
|
30
|
-
|
28
|
+
renders_one :bg_color, ->(value = nil, **input_options) do
|
29
|
+
@bg_color_options = {selected: value, **input_options}
|
31
30
|
end
|
32
31
|
|
33
|
-
renders_one :
|
34
|
-
|
32
|
+
renders_one :text_color, ->(value = nil, **input_options) do
|
33
|
+
@text_color_options = {selected: value, **input_options}
|
35
34
|
end
|
36
35
|
|
37
|
-
|
38
|
-
|
36
|
+
renders_one :bg_image, ->(src = nil, **input_options) do
|
37
|
+
@bg_image_options = {src: src, **input_options}
|
39
38
|
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
@form_args = form.to_h
|
45
|
-
@model = @form_args[:model]
|
46
|
-
@fields = {}
|
47
|
-
end
|
48
|
-
|
49
|
-
def form_args(attrs = {})
|
50
|
-
html_args = @form_args.fetch(:html, {})
|
51
|
-
attrs[:class] = class_names(html_args[:class], attrs[:class])
|
52
|
-
html_args.merge!(attrs)
|
53
|
-
@form_args.merge({html: html_args})
|
54
|
-
end
|
40
|
+
# renders_one :thumbnail, ->(name: :thumbnail_image, **input_options) do
|
41
|
+
# add_field(:thumbnail, name, input_options)
|
42
|
+
# end
|
55
43
|
|
56
44
|
def slide_args
|
57
45
|
{
|
58
|
-
bg_image:
|
59
|
-
bg_color_hex:
|
60
|
-
text_color_hex:
|
61
|
-
layout: layout_value,
|
46
|
+
bg_image: bg_image_src,
|
47
|
+
bg_color_hex: bg_color_css,
|
48
|
+
text_color_hex: text_color_css,
|
62
49
|
render_empty: true
|
63
50
|
}
|
64
51
|
end
|
65
52
|
|
66
53
|
def alpine_props
|
67
54
|
{
|
68
|
-
bg_color:
|
69
|
-
text_color:
|
70
|
-
title:
|
71
|
-
text_1:
|
72
|
-
|
73
|
-
bg_image: {
|
74
|
-
name: ((field?(:bg_image) && bg_image_value.present?) && File.basename(bg_image_value)),
|
75
|
-
data: (bg_image_value if field?(:bg_image))
|
76
|
-
}
|
55
|
+
bg_color: bg_color_css,
|
56
|
+
text_color: text_color_css,
|
57
|
+
title: title&.value,
|
58
|
+
text_1: text_1&.value,
|
59
|
+
bg_image: bg_image_src
|
77
60
|
}
|
78
61
|
end
|
79
62
|
|
80
|
-
def
|
81
|
-
|
82
|
-
field_name = name.to_s.gsub(matches[0], "").to_sym
|
83
|
-
method = matches[1].to_sym
|
84
|
-
if field?(field_name)
|
85
|
-
fields[field_name].public_send(method)
|
86
|
-
end
|
87
|
-
end
|
63
|
+
def bg_color_css
|
64
|
+
@bg_color_options[:selected] if @bg_color_options
|
88
65
|
end
|
89
66
|
|
90
|
-
def
|
91
|
-
|
92
|
-
field?(field_name.to_sym)
|
67
|
+
def text_color_css
|
68
|
+
@text_color_options[:selected] if @text_color_options
|
93
69
|
end
|
94
70
|
|
95
|
-
def
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
private
|
100
|
-
|
101
|
-
def add_field(field_name, name, options = {})
|
102
|
-
model_value = @model&.public_send(name) if @model&.respond_to?(name)
|
103
|
-
fields[field_name] = SlideInput.new(name, model_value, options)
|
104
|
-
end
|
105
|
-
|
106
|
-
SlideInput = Data.define(:name, :model_value, :input_options) do
|
107
|
-
def value
|
108
|
-
input_options.fetch(:value, model_value)
|
109
|
-
end
|
110
|
-
|
111
|
-
def options
|
112
|
-
input_options.tap do |options|
|
113
|
-
options[:value] = value
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def to_json
|
118
|
-
"\"#{value}\"" if value.present?
|
119
|
-
end
|
120
|
-
|
121
|
-
alias_method :to_s, :value
|
71
|
+
def bg_image_src
|
72
|
+
@bg_image_options[:src] if @bg_image_options
|
122
73
|
end
|
123
74
|
end
|
124
75
|
end
|
@@ -1,23 +1,24 @@
|
|
1
1
|
<%= render component_tag(x: {
|
2
2
|
data: x_data("appColorPickerButton", {selected: selected}),
|
3
|
-
"@dropdown:mount": "onDropdownMount
|
3
|
+
"@dropdown:mount": "onDropdownMount"
|
4
4
|
}) do %>
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
<div x-effect="$dispatch('color-picker:change', {color: selectedColor})">
|
6
|
+
<%= render button do |btn| %>
|
7
|
+
<% btn.with_icon do %>
|
8
|
+
<%= icon %>
|
9
|
+
<% end %>
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
<% btn.with_dropdown do %>
|
12
|
+
<div
|
13
|
+
@color-picker:select="selectedColor = $event.detail.selectedColor;"
|
14
|
+
x-cloak>
|
15
|
+
<div data-role="color-picker">
|
16
|
+
<%= picker %>
|
17
|
+
</div>
|
17
18
|
</div>
|
18
|
-
|
19
|
-
<% end %>
|
19
|
+
<% end %>
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
<%= button_text %>
|
22
|
+
<% end %>
|
23
|
+
</div>
|
23
24
|
<% end %>
|
@@ -12,14 +12,6 @@ export default CocoComponent("appColorPickerButton", ({ selected }) => {
|
|
12
12
|
);
|
13
13
|
},
|
14
14
|
|
15
|
-
get selectedColorHex() {
|
16
|
-
return this.selectedColor && this.selectedColor.replace("#", "");
|
17
|
-
},
|
18
|
-
|
19
|
-
set selectedColorHex(value) {
|
20
|
-
this.selectedColor == "#" + value.replace("#", "");
|
21
|
-
},
|
22
|
-
|
23
15
|
onDropdownMount() {
|
24
16
|
this.getPicker().setSelectedColor(this.selectedColor);
|
25
17
|
},
|
@@ -26,7 +26,7 @@ module Coco
|
|
26
26
|
end
|
27
27
|
|
28
28
|
renders_one :icon, ->(&block) do
|
29
|
-
tag.span class: "picker-icon", ":style": "{color: selectedColor}", &block
|
29
|
+
tag.span class: "picker-icon", style: "color: #{@selected}", ":style": "{color: selectedColor}", &block
|
30
30
|
end
|
31
31
|
|
32
32
|
before_render do
|
@@ -40,26 +40,13 @@ module Coco
|
|
40
40
|
|
41
41
|
attr_reader :selected
|
42
42
|
|
43
|
-
def initialize(selected: nil,
|
43
|
+
def initialize(selected: nil, **kwargs)
|
44
44
|
@selected = selected
|
45
45
|
|
46
46
|
@size = kwargs.fetch(:size, :default)&.to_sym
|
47
47
|
if @size.in?(Coco::App::Elements::Button::SIZE_ALIASES.keys) && !kwargs.key?(:resize)
|
48
48
|
@size, @resize = Coco::App::Elements::Button::SIZE_ALIASES.fetch(@size)
|
49
49
|
end
|
50
|
-
|
51
|
-
@form_builder = form_builder
|
52
|
-
@input_name = input_name
|
53
|
-
end
|
54
|
-
|
55
|
-
def input
|
56
|
-
if @input_name
|
57
|
-
if @form_builder
|
58
|
-
@form_builder.hidden_field(@input_name, value: @selected, "x-model": "selectedColorHex")
|
59
|
-
else
|
60
|
-
hidden_field_tag(@input_name, @selected, "x-model": "selectedColorHex")
|
61
|
-
end
|
62
|
-
end
|
63
50
|
end
|
64
51
|
|
65
52
|
def button_text
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= render component_tag(x: {data: x_data("appImagePicker",
|
1
|
+
<%= render component_tag(x: {data: x_data("appImagePicker", {src: src}), ":class": "hasImage && 'has-image'"}) do %>
|
2
2
|
<div class="picker-file-name" x-show="hasImage">
|
3
3
|
<label x-text="name"></label>
|
4
4
|
</div>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<%= render Coco::ImageUploader.new(
|
7
7
|
**uploader_args,
|
8
8
|
click: false) do %>
|
9
|
-
<div class="picker-blank-state" x-show="
|
9
|
+
<div class="picker-blank-state" x-show="!$parent.src">
|
10
10
|
<% if blank_state_text? %>
|
11
11
|
<div class="picker-placeholder-text">
|
12
12
|
<%= blank_state_text %>
|
@@ -18,8 +18,8 @@
|
|
18
18
|
<% end %>
|
19
19
|
</div>
|
20
20
|
</div>
|
21
|
-
<div x-show="
|
22
|
-
<img :src="
|
21
|
+
<div x-show="$parent.src" x-cloak>
|
22
|
+
<img :src="$parent.src" class="picker-thumbnail">
|
23
23
|
</div>
|
24
24
|
<% end %>
|
25
25
|
</div>
|
@@ -1,17 +1,23 @@
|
|
1
1
|
import { CocoComponent } from "@js/coco";
|
2
2
|
import { getComponent } from "@helpers/alpine";
|
3
|
+
import { basename } from "@helpers/path";
|
3
4
|
|
4
|
-
export default CocoComponent("appImagePicker", ({
|
5
|
+
export default CocoComponent("appImagePicker", ({ src }) => {
|
5
6
|
return {
|
6
7
|
use: [],
|
7
|
-
|
8
|
+
|
9
|
+
image: {
|
10
|
+
name: basename(src),
|
11
|
+
file: null,
|
12
|
+
data: src,
|
13
|
+
},
|
8
14
|
|
9
15
|
get name() {
|
10
|
-
return this.image
|
16
|
+
return this.image.name;
|
11
17
|
},
|
12
18
|
|
13
19
|
get src() {
|
14
|
-
return this.image
|
20
|
+
return this.image.data;
|
15
21
|
},
|
16
22
|
|
17
23
|
get hasImage() {
|
@@ -23,8 +29,14 @@ export default CocoComponent("appImagePicker", ({ image }) => {
|
|
23
29
|
},
|
24
30
|
|
25
31
|
setImage(file, silent = false) {
|
26
|
-
this.image =
|
32
|
+
this.image = {
|
33
|
+
file: file.file,
|
34
|
+
name: file.name,
|
35
|
+
data: file.data,
|
36
|
+
};
|
37
|
+
|
27
38
|
this.uploader.setFile(file);
|
39
|
+
|
28
40
|
if (silent === false) {
|
29
41
|
this.$dispatch("image-picker:select", { image: this.image });
|
30
42
|
}
|
@@ -32,7 +44,7 @@ export default CocoComponent("appImagePicker", ({ image }) => {
|
|
32
44
|
|
33
45
|
clearImage(silent = false) {
|
34
46
|
this.uploader.clear();
|
35
|
-
this.image = null;
|
47
|
+
this.image = { name: null, data: null, file: null };
|
36
48
|
if (silent === false) {
|
37
49
|
this.$dispatch("image-picker:clear");
|
38
50
|
}
|
@@ -15,18 +15,9 @@ module Coco
|
|
15
15
|
|
16
16
|
attr_reader :uploader_args, :src
|
17
17
|
|
18
|
-
def initialize(
|
18
|
+
def initialize(src: nil, accept: "image/*", **kwargs)
|
19
19
|
@src = src
|
20
|
-
@uploader_args = {
|
21
|
-
end
|
22
|
-
|
23
|
-
def alpine_props
|
24
|
-
{
|
25
|
-
image: {
|
26
|
-
name: (src.present? && File.basename(src)),
|
27
|
-
data: src
|
28
|
-
}
|
29
|
-
}
|
20
|
+
@uploader_args = {accept: accept}
|
30
21
|
end
|
31
22
|
end
|
32
23
|
end
|
@@ -1,20 +1,21 @@
|
|
1
1
|
<%= render component_tag(x: {
|
2
|
-
data: x_data("appImagePickerButton",
|
3
|
-
"@dropdown:mount": "onDropdownMount"
|
4
|
-
|
5
|
-
|
2
|
+
data: x_data("appImagePickerButton", {src: src}),
|
3
|
+
"@dropdown:mount": "onDropdownMount",
|
4
|
+
effect: "$dispatch('image-picker:change', {image: selectedImage})"
|
5
|
+
}) do %>
|
6
6
|
<%= render button do |btn| %>
|
7
|
-
|
7
|
+
|
8
|
+
<% btn.with_dropdown do %>
|
8
9
|
<div
|
9
|
-
@image-picker:select="setSelectedImage($event.detail.image)"
|
10
|
-
@image-picker:clear="clearSelectedImage"
|
10
|
+
@image-picker:select="$parent.setSelectedImage($event.detail.image)"
|
11
|
+
@image-picker:clear="$parent.clearSelectedImage"
|
11
12
|
x-cloak>
|
12
13
|
<div data-role="image-picker">
|
13
14
|
<%= picker %>
|
14
15
|
</div>
|
15
16
|
</div>
|
16
17
|
<% end %>
|
17
|
-
|
18
|
+
|
18
19
|
<%= button_text %>
|
19
20
|
<% end %>
|
20
21
|
<% end %>
|
@@ -1,24 +1,13 @@
|
|
1
1
|
import { CocoComponent } from "@js/coco";
|
2
2
|
import { getData } from "@helpers/alpine";
|
3
|
+
import { basename } from "@helpers/path";
|
3
4
|
|
4
|
-
export default CocoComponent("appImagePickerButton", ({
|
5
|
+
export default CocoComponent("appImagePickerButton", ({ src }) => {
|
5
6
|
return {
|
6
|
-
selectedImage:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
init() {
|
11
|
-
this.$watch("selectedImage", (file) => {
|
12
|
-
const dataTransfer = new DataTransfer();
|
13
|
-
if (file && file.file instanceof File) {
|
14
|
-
dataTransfer.items.add(file.file);
|
15
|
-
}
|
16
|
-
this.$refs.fileInput.files = dataTransfer.files;
|
17
|
-
|
18
|
-
if (this.dropdown) {
|
19
|
-
this.dropdown.hide();
|
20
|
-
}
|
21
|
-
});
|
7
|
+
selectedImage: {
|
8
|
+
name: basename(src),
|
9
|
+
file: null,
|
10
|
+
data: src,
|
22
11
|
},
|
23
12
|
|
24
13
|
getPicker() {
|
@@ -37,21 +26,19 @@ export default CocoComponent("appImagePickerButton", ({ image }) => {
|
|
37
26
|
reader.addEventListener("load", () => {
|
38
27
|
this.selectedImage = {
|
39
28
|
name: file.name,
|
40
|
-
file
|
29
|
+
file,
|
41
30
|
data: reader.result,
|
42
31
|
};
|
43
|
-
});
|
44
32
|
|
45
|
-
|
46
|
-
|
47
|
-
// });
|
33
|
+
this.dropdown.hide();
|
34
|
+
});
|
48
35
|
|
49
36
|
reader.readAsDataURL(file);
|
50
37
|
},
|
51
38
|
|
52
39
|
clearSelectedImage() {
|
53
40
|
this.dropdown.hide();
|
54
|
-
this.selectedImage = null;
|
41
|
+
this.selectedImage = { name: null, data: null, file: null };
|
55
42
|
},
|
56
43
|
|
57
44
|
setSelectedImage(image) {
|
@@ -29,13 +29,10 @@ module Coco
|
|
29
29
|
with_picker(src: @src) unless picker?
|
30
30
|
end
|
31
31
|
|
32
|
-
attr_reader :src
|
32
|
+
attr_reader :src
|
33
33
|
|
34
|
-
def initialize(src: nil,
|
34
|
+
def initialize(src: nil, **kwargs)
|
35
35
|
@src = src
|
36
|
-
@form_builder = form_builder
|
37
|
-
@input_name = input_name
|
38
|
-
@direct_upload = direct_upload
|
39
36
|
|
40
37
|
@size = kwargs.fetch(:size, :default)&.to_sym
|
41
38
|
if @size.in?(Coco::App::Elements::Button::SIZE_ALIASES.keys) && !kwargs.key?(:resize)
|
@@ -43,38 +40,25 @@ module Coco
|
|
43
40
|
end
|
44
41
|
end
|
45
42
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
name: (src.present? && File.basename(src)),
|
54
|
-
data: src
|
55
|
-
}
|
56
|
-
}
|
57
|
-
end
|
43
|
+
# def input
|
44
|
+
# if input_name
|
45
|
+
# kwargs = {
|
46
|
+
# class: "picker-file-input",
|
47
|
+
# "x-ref": "fileInput",
|
48
|
+
# direct_upload: @direct_upload
|
49
|
+
# }
|
58
50
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
class: "picker-file-input",
|
63
|
-
"x-ref": "fileInput",
|
64
|
-
direct_upload: @direct_upload
|
65
|
-
}
|
51
|
+
# if direct_upload? && !helpers.respond_to?(:rails_direct_uploads_url)
|
52
|
+
# kwargs[:data] = {direct_upload_url: @direct_upload}
|
53
|
+
# end
|
66
54
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
file_field_tag(input_name, **kwargs)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
55
|
+
# if @form_builder
|
56
|
+
# @form_builder.file_field(input_name, **kwargs)
|
57
|
+
# else
|
58
|
+
# file_field_tag(input_name, **kwargs)
|
59
|
+
# end
|
60
|
+
# end
|
61
|
+
# end
|
78
62
|
|
79
63
|
def button_text
|
80
64
|
text || content
|
@@ -1,12 +1,15 @@
|
|
1
|
-
<%= render component_tag(x: {data: "appSeamlessTextarea"}) do %>
|
2
|
-
<%=
|
1
|
+
<%= render component_tag(x: {data: "appSeamlessTextarea", options: "options"}) do %>
|
2
|
+
<%= text_area_tag(nil, value,
|
3
|
+
id: nil,
|
4
|
+
placeholder: placeholder,
|
3
5
|
spellcheck: false,
|
4
6
|
rows: 1,
|
5
7
|
**x_attrs({
|
6
8
|
"@keydown.enter.prevent": (true unless multiline?),
|
7
9
|
"@input": "onResize",
|
8
10
|
ref: "textarea",
|
9
|
-
"model.debounce": "value"
|
10
|
-
})
|
11
|
+
"model.fill.debounce": "value"
|
12
|
+
}),
|
13
|
+
**@textarea_args
|
11
14
|
) %>
|
12
15
|
<% end %>
|
@@ -9,12 +9,18 @@ export default CocoComponent("appSeamlessTextarea", () => {
|
|
9
9
|
observer: null,
|
10
10
|
value: null,
|
11
11
|
|
12
|
-
|
13
|
-
return this.assertData("multiline", "false");
|
14
|
-
},
|
12
|
+
options: ["multiline", "focus"],
|
15
13
|
|
16
14
|
init() {
|
17
15
|
this.value = this.$refs.textarea.value;
|
16
|
+
this.$nextTick(() => {
|
17
|
+
this.onResize();
|
18
|
+
|
19
|
+
if (this.$options.focus) {
|
20
|
+
this.$refs.textarea.focus();
|
21
|
+
this.$refs.textarea.selectionStart = this.$refs.textarea.value.length;
|
22
|
+
}
|
23
|
+
});
|
18
24
|
},
|
19
25
|
|
20
26
|
onResize() {
|
@@ -3,22 +3,17 @@ module Coco
|
|
3
3
|
module Elements
|
4
4
|
class SeamlessTextarea < Coco::Component
|
5
5
|
include TagHelper
|
6
|
-
include Concerns::WrapsComponent
|
7
6
|
include Concerns::AcceptsOptions
|
8
7
|
|
9
|
-
wraps_component :textarea
|
10
|
-
|
11
8
|
accepts_option :multiline, from: [true, false]
|
9
|
+
accepts_option :focus, from: [true, false]
|
12
10
|
|
13
|
-
attr_reader :
|
11
|
+
attr_reader :placeholder
|
14
12
|
|
15
|
-
def initialize(
|
16
|
-
@name = name
|
17
|
-
@value = value
|
18
|
-
@form_builder = form_builder
|
13
|
+
def initialize(textarea: nil, value: nil, placeholder: nil, **kwargs)
|
19
14
|
@textarea_args = textarea.to_h
|
20
|
-
@
|
21
|
-
@
|
15
|
+
@value = value
|
16
|
+
@placeholder = placeholder
|
22
17
|
end
|
23
18
|
|
24
19
|
def multiline?
|
@@ -28,16 +23,6 @@ module Coco
|
|
28
23
|
def value
|
29
24
|
(@value.presence || content.presence || "").strip_heredoc.strip
|
30
25
|
end
|
31
|
-
|
32
|
-
def text_area(**html_args)
|
33
|
-
args = @textarea_args.merge(html_args.compact)
|
34
|
-
|
35
|
-
if @form_builder
|
36
|
-
@form_builder.text_area(name, value: value, **args)
|
37
|
-
else
|
38
|
-
text_area_tag(name, value, **args)
|
39
|
-
end
|
40
|
-
end
|
41
26
|
end
|
42
27
|
end
|
43
28
|
end
|
@@ -7,11 +7,12 @@
|
|
7
7
|
"@drop.stop.prevent": "active = false; handleDrop($event)",
|
8
8
|
":data-active": "active && droppable"
|
9
9
|
}) do %>
|
10
|
-
<%=
|
10
|
+
<%= file_field_tag(nil,
|
11
|
+
accept: accept,
|
11
12
|
class: "uploader-input",
|
12
13
|
"x-ref": "input",
|
13
14
|
"@click.stop": "",
|
14
|
-
"@change": "handleFiles($el.files)" %>
|
15
|
+
"@change": "handleFiles($el.files)") %>
|
15
16
|
<%= content %>
|
16
17
|
<% end %>
|
17
18
|
|
@@ -5,20 +5,10 @@ module Coco
|
|
5
5
|
accepts_option :click, from: [true, false], default: true
|
6
6
|
accepts_option :drop, from: [true, false], default: true
|
7
7
|
|
8
|
-
attr_reader :name, :accept
|
8
|
+
attr_reader :name, :accept
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
@name = name || random_id
|
10
|
+
def initialize(accept: "image/*", **kwargs)
|
12
11
|
@accept = accept
|
13
|
-
@form_builder = form_builder
|
14
|
-
end
|
15
|
-
|
16
|
-
def file_field(**kwargs)
|
17
|
-
if form_builder
|
18
|
-
form_builder.file_field(@name, **kwargs)
|
19
|
-
else
|
20
|
-
file_field_tag(@name, **kwargs)
|
21
|
-
end
|
22
12
|
end
|
23
13
|
|
24
14
|
def clickable?
|
data/lib/coco.rb
CHANGED