matestack-ui-core 1.1.0 → 1.4.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 +801 -13
- data/app/concepts/matestack/ui/core/cable/cable.haml +1 -1
- data/app/concepts/matestack/ui/core/collection/helper.rb +7 -1
- data/app/concepts/matestack/ui/core/component/base.rb +1 -1
- data/app/concepts/matestack/ui/core/form/checkbox/base.rb +120 -0
- data/app/concepts/matestack/ui/core/form/checkbox/checkbox.js +15 -0
- data/app/concepts/matestack/ui/core/form/checkbox/checkbox.rb +7 -70
- data/app/concepts/matestack/ui/core/form/checkbox/mixin.js +80 -0
- data/app/concepts/matestack/ui/core/form/form.js +15 -46
- data/app/concepts/matestack/ui/core/form/input/base.rb +75 -0
- data/app/concepts/matestack/ui/core/form/input/input.js +15 -0
- data/app/concepts/matestack/ui/core/form/input/input.rb +8 -52
- data/app/concepts/matestack/ui/core/form/input/mixin.js +55 -0
- data/app/concepts/matestack/ui/core/form/radio/base.rb +90 -0
- data/app/concepts/matestack/ui/core/form/radio/mixin.js +62 -0
- data/app/concepts/matestack/ui/core/form/radio/radio.js +15 -0
- data/app/concepts/matestack/ui/core/form/radio/radio.rb +7 -62
- data/app/concepts/matestack/ui/core/form/select/base.rb +98 -0
- data/app/concepts/matestack/ui/core/form/select/mixin.js +58 -0
- data/app/concepts/matestack/ui/core/form/select/select.js +15 -0
- data/app/concepts/matestack/ui/core/form/select/select.rb +11 -60
- data/app/concepts/matestack/ui/core/form/submit/base.rb +12 -0
- data/app/concepts/matestack/ui/core/form/submit/submit.js +19 -0
- data/app/concepts/matestack/ui/core/form/submit/submit.rb +9 -6
- data/app/concepts/matestack/ui/core/form/textarea/base.rb +49 -0
- data/app/concepts/matestack/ui/core/form/textarea/mixin.js +41 -0
- data/app/concepts/matestack/ui/core/form/textarea/textarea.js +15 -0
- data/app/concepts/matestack/ui/core/form/textarea/textarea.rb +10 -21
- data/app/concepts/matestack/ui/core/js/core.js +11 -0
- data/app/concepts/matestack/ui/core/{form/submit/submit.haml → select/select.haml} +1 -1
- data/app/concepts/matestack/ui/core/select/select.rb +7 -0
- data/app/concepts/matestack/ui/core/view/view.rb +2 -2
- data/app/helpers/matestack/ui/core/application_helper.rb +2 -2
- data/app/javascript/matestack-ui-core/index.js +12 -2
- data/app/lib/matestack/ui/core/has_view_context.rb +4 -2
- data/app/lib/matestack/ui/core/rendering/main_renderer.rb +4 -1
- data/lib/matestack/ui/core/components.rb +2 -0
- data/lib/matestack/ui/core/version.rb +1 -1
- data/vendor/assets/javascripts/dist/matestack-ui-core.js +611 -55
- data/vendor/assets/javascripts/dist/matestack-ui-core.js.map +1 -1
- data/vendor/assets/javascripts/dist/matestack-ui-core.min.js +1 -1
- data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.LICENSE.txt +5 -12
- data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.br +0 -0
- data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.gz +0 -0
- data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.map +1 -1
- data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.map.br +0 -0
- data/vendor/assets/javascripts/dist/matestack-ui-core.min.js.map.gz +0 -0
- metadata +31 -16
- data/app/concepts/matestack/ui/core/form/select/select.haml +0 -9
@@ -0,0 +1,15 @@
|
|
1
|
+
import Vue from "vue/dist/vue.esm";
|
2
|
+
|
3
|
+
import formInputMixin from "./mixin";
|
4
|
+
import componentMixin from "../../component/component";
|
5
|
+
|
6
|
+
const componentDef = {
|
7
|
+
mixins: [componentMixin, formInputMixin],
|
8
|
+
data() {
|
9
|
+
return {};
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
let component = Vue.component("matestack-ui-core-form-input", componentDef);
|
14
|
+
|
15
|
+
export default componentDef;
|
@@ -1,59 +1,15 @@
|
|
1
|
-
require_relative '
|
2
|
-
|
3
|
-
require_relative '../has_errors'
|
1
|
+
require_relative './base'
|
2
|
+
|
4
3
|
module Matestack::Ui::Core::Form::Input
|
5
|
-
class Input <
|
6
|
-
include Matestack::Ui::Core::Form::Utils
|
7
|
-
include Matestack::Ui::Core::Form::HasInputHtmlAttributes
|
8
|
-
include Matestack::Ui::Core::Form::HasErrors
|
4
|
+
class Input < Base
|
9
5
|
|
10
|
-
|
11
|
-
optional :multiple, :init, for: { as: :input_for }, label: { as: :input_label }
|
6
|
+
vue_js_component_name "matestack-ui-core-form-input"
|
12
7
|
|
13
8
|
def response
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def vue_attributes
|
20
|
-
(options[:attributes] || {}).merge({
|
21
|
-
"@change": change_event,
|
22
|
-
ref: "input.#{attr_key}",
|
23
|
-
'init-value': init_value,
|
24
|
-
'v-bind:class': "{ '#{input_error_class}': #{error_key} }"
|
25
|
-
}).merge(
|
26
|
-
type != :file ? { "#{v_model_type}": input_key } : {}
|
27
|
-
) # file inputs are readonly, no v-model possible
|
28
|
-
end
|
29
|
-
|
30
|
-
def v_model_type
|
31
|
-
if type == :number || init_value.is_a?(Integer)
|
32
|
-
'v-model.number'
|
33
|
-
else
|
34
|
-
'v-model'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def change_event
|
39
|
-
"inputChanged('#{attr_key}'); #{ "filesAdded('#{attr_key}');" if type == :file }".strip
|
40
|
-
end
|
41
|
-
|
42
|
-
def custom_options_validation
|
43
|
-
raise "included form config is missing, please add ':include' to parent form component" if @included_config.nil?
|
44
|
-
end
|
45
|
-
|
46
|
-
def attr_key
|
47
|
-
super + "#{'[]' if multiple && type == :file}"
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def parse_value(value)
|
53
|
-
if [true, false].include? value
|
54
|
-
value ? 1 : 0
|
55
|
-
else
|
56
|
-
return value
|
9
|
+
div class: "matestack-ui-core-form-input" do
|
10
|
+
label text: input_label if input_label
|
11
|
+
input input_attributes
|
12
|
+
render_errors
|
57
13
|
end
|
58
14
|
end
|
59
15
|
|
@@ -0,0 +1,55 @@
|
|
1
|
+
const formInputMixin = {
|
2
|
+
methods: {
|
3
|
+
initialize: function(){
|
4
|
+
const self = this
|
5
|
+
let data = {};
|
6
|
+
|
7
|
+
for (let key in this.$refs) {
|
8
|
+
let initValue = this.$refs[key]["attributes"]["init-value"];
|
9
|
+
|
10
|
+
if (initValue) {
|
11
|
+
data[key.replace("input.", "")] = initValue["value"];
|
12
|
+
Object.assign(self.$parent.data, data);
|
13
|
+
self.afterInitialize(initValue["value"])
|
14
|
+
} else {
|
15
|
+
data[key.replace("input.", "")] = null;
|
16
|
+
Object.assign(self.$parent.data, data);
|
17
|
+
self.afterInitialize(null)
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
//without the timeout it's somehow not working
|
22
|
+
setTimeout(function () {
|
23
|
+
self.$forceUpdate()
|
24
|
+
}, 1);
|
25
|
+
},
|
26
|
+
filesAdded: function (key) {
|
27
|
+
const dataTransfer = event.dataTransfer || event.target;
|
28
|
+
const files = dataTransfer.files;
|
29
|
+
if (event.target.attributes.multiple) {
|
30
|
+
this.$parent.data[key] = [];
|
31
|
+
for (let index in files) {
|
32
|
+
if (files[index] instanceof File) {
|
33
|
+
this.$parent.data[key].push(files[index]);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
} else {
|
37
|
+
this.$parent.data[key] = files[0];
|
38
|
+
}
|
39
|
+
},
|
40
|
+
inputChanged: function (key) {
|
41
|
+
this.$parent.resetErrors(key);
|
42
|
+
this.$forceUpdate();
|
43
|
+
},
|
44
|
+
afterInitialize: function(value){
|
45
|
+
// can be used in the main component for further initialization steps
|
46
|
+
},
|
47
|
+
setValue: function (value){
|
48
|
+
this.$parent.data[this.componentConfig["key"]] = value
|
49
|
+
this.$forceUpdate();
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
export default formInputMixin
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require_relative '../utils'
|
2
|
+
require_relative '../has_input_html_attributes'
|
3
|
+
require_relative '../has_errors'
|
4
|
+
module Matestack::Ui::Core::Form::Radio
|
5
|
+
class Base < Matestack::Ui::Core::Component::Dynamic
|
6
|
+
include Matestack::Ui::Core::Form::Utils
|
7
|
+
include Matestack::Ui::Core::Form::HasInputHtmlAttributes
|
8
|
+
include Matestack::Ui::Core::Form::HasErrors
|
9
|
+
|
10
|
+
requires :key
|
11
|
+
optional :multiple, :init, for: { as: :input_for }, label: { as: :input_label }, options: { as: :radio_options }
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@component_config[:init_value] = init_value
|
15
|
+
end
|
16
|
+
|
17
|
+
def component_id
|
18
|
+
"radio-component-for-#{attr_key}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def input_key
|
22
|
+
"$parent.data[\"#{key}\"]"
|
23
|
+
end
|
24
|
+
|
25
|
+
def error_key
|
26
|
+
"$parent.errors[\"#{key}\"]"
|
27
|
+
end
|
28
|
+
|
29
|
+
def change_event
|
30
|
+
"inputChanged('#{attr_key}')"
|
31
|
+
end
|
32
|
+
|
33
|
+
def render_options
|
34
|
+
radio_options.to_a.each do |item|
|
35
|
+
input radio_attributes(item)
|
36
|
+
label text: item_label(item), for: id_for_item(item_value(item))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def radio_attributes(item)
|
41
|
+
html_attributes.merge(
|
42
|
+
attributes: vue_attributes,
|
43
|
+
type: :radio,
|
44
|
+
id: "#{id_for_item(item_value(item))}",
|
45
|
+
name: item_name(item),
|
46
|
+
value: item_value(item),
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def vue_attributes
|
51
|
+
(options[:attributes] || {}).merge({
|
52
|
+
"@change": change_event,
|
53
|
+
ref: "select.#{attr_key}",
|
54
|
+
'init-value': init_value,
|
55
|
+
'v-bind:class': "{ '#{input_error_class}': #{error_key} }",
|
56
|
+
'value-type': value_type,
|
57
|
+
"#{v_model_type}": input_key,
|
58
|
+
})
|
59
|
+
end
|
60
|
+
|
61
|
+
def value_type
|
62
|
+
item_value(radio_options.first).is_a?(Integer) ? Integer : nil
|
63
|
+
end
|
64
|
+
|
65
|
+
def item_value(item)
|
66
|
+
item.is_a?(Array) ? item.last : item
|
67
|
+
end
|
68
|
+
|
69
|
+
def item_name(item)
|
70
|
+
"#{attr_key}_#{item.is_a?(Array) ? item.first : item}"
|
71
|
+
end
|
72
|
+
|
73
|
+
def item_label(item)
|
74
|
+
item.is_a?(Array) ? item.first : item
|
75
|
+
end
|
76
|
+
|
77
|
+
def v_model_type
|
78
|
+
if radio_options && item_value(radio_options.first).is_a?(Integer)
|
79
|
+
'v-model.number'
|
80
|
+
else
|
81
|
+
'v-model'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def id_for_item(value)
|
86
|
+
"#{html_attributes[:id] || attr_key}_#{value}"
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
const formRadioMixin = {
|
2
|
+
methods: {
|
3
|
+
initialize: function(){
|
4
|
+
const self = this
|
5
|
+
let data = {};
|
6
|
+
|
7
|
+
for (let key in self.$refs) {
|
8
|
+
let initValue = self.$refs[key]["attributes"]["init-value"];
|
9
|
+
let valueType = self.$refs[key]["attributes"]["value-type"];
|
10
|
+
|
11
|
+
if (key.startsWith("select.")) {
|
12
|
+
if (key.startsWith("select.multiple.")) {
|
13
|
+
if (initValue) {
|
14
|
+
data[key.replace("select.multiple.", "")] = JSON.parse(initValue["value"]);
|
15
|
+
Object.assign(self.$parent.data, data);
|
16
|
+
self.afterInitialize(JSON.parse(initValue["value"]))
|
17
|
+
} else {
|
18
|
+
data[key.replace("select.multiple.", "")] = [];
|
19
|
+
Object.assign(self.$parent.data, data);
|
20
|
+
self.afterInitialize([])
|
21
|
+
}
|
22
|
+
} else {
|
23
|
+
if (initValue) {
|
24
|
+
if (valueType && valueType["value"] == "Integer") {
|
25
|
+
data[key.replace("select.", "")] = parseInt(initValue["value"]);
|
26
|
+
Object.assign(self.$parent.data, data);
|
27
|
+
self.afterInitialize(parseInt(initValue["value"]))
|
28
|
+
} else {
|
29
|
+
data[key.replace("select.", "")] = initValue["value"];
|
30
|
+
Object.assign(self.$parent.data, data);
|
31
|
+
self.afterInitialize(initValue["value"])
|
32
|
+
}
|
33
|
+
} else {
|
34
|
+
data[key.replace("select.", "")] = null;
|
35
|
+
Object.assign(self.$parent.data, data);
|
36
|
+
self.afterInitialize(null)
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
//without the timeout it's somehow not working
|
43
|
+
setTimeout(function () {
|
44
|
+
self.$forceUpdate();
|
45
|
+
}, 1);
|
46
|
+
},
|
47
|
+
inputChanged: function (key) {
|
48
|
+
this.$parent.resetErrors(key);
|
49
|
+
this.$forceUpdate();
|
50
|
+
},
|
51
|
+
afterInitialize: function(value){
|
52
|
+
// can be used in the main component for further initialization steps
|
53
|
+
},
|
54
|
+
setValue: function (value){
|
55
|
+
this.$parent.data[this.componentConfig["key"]] = value
|
56
|
+
this.$forceUpdate();
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
}
|
61
|
+
|
62
|
+
export default formRadioMixin
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import Vue from "vue/dist/vue.esm";
|
2
|
+
|
3
|
+
import formRadioMixin from "./mixin";
|
4
|
+
import componentMixin from "../../component/component";
|
5
|
+
|
6
|
+
const componentDef = {
|
7
|
+
mixins: [componentMixin, formRadioMixin],
|
8
|
+
data() {
|
9
|
+
return {};
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
let component = Vue.component("matestack-ui-core-form-radio", componentDef);
|
14
|
+
|
15
|
+
export default componentDef;
|
@@ -1,71 +1,16 @@
|
|
1
|
-
require_relative '
|
2
|
-
|
3
|
-
require_relative '../has_errors'
|
1
|
+
require_relative './base'
|
2
|
+
|
4
3
|
module Matestack::Ui::Core::Form::Radio
|
5
|
-
class Radio <
|
6
|
-
include Matestack::Ui::Core::Form::Utils
|
7
|
-
include Matestack::Ui::Core::Form::HasInputHtmlAttributes
|
8
|
-
include Matestack::Ui::Core::Form::HasErrors
|
4
|
+
class Radio < Base
|
9
5
|
|
10
|
-
|
11
|
-
optional :multiple, :init, for: { as: :input_for }, label: { as: :input_label }, options: { as: :radio_options }
|
6
|
+
vue_js_component_name "matestack-ui-core-form-radio"
|
12
7
|
|
13
8
|
def response
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
type: :radio,
|
18
|
-
id: "#{id_for_item(item_value(item))}",
|
19
|
-
name: item_name(item),
|
20
|
-
value: item_value(item),
|
21
|
-
)
|
22
|
-
label text: item_label(item), for: id_for_item(item_value(item))
|
23
|
-
end
|
24
|
-
render_errors
|
25
|
-
end
|
26
|
-
|
27
|
-
def vue_attributes
|
28
|
-
(options[:attributes] || {}).merge({
|
29
|
-
"@change": change_event,
|
30
|
-
ref: "select.#{attr_key}",
|
31
|
-
'init-value': init_value,
|
32
|
-
'v-bind:class': "{ '#{input_error_class}': #{error_key} }",
|
33
|
-
'value-type': value_type,
|
34
|
-
"#{v_model_type}": input_key,
|
35
|
-
})
|
36
|
-
end
|
37
|
-
|
38
|
-
def value_type
|
39
|
-
item_value(radio_options.first).is_a?(Integer) ? Integer : nil
|
40
|
-
end
|
41
|
-
|
42
|
-
def item_value(item)
|
43
|
-
item.is_a?(Array) ? item.last : item
|
44
|
-
end
|
45
|
-
|
46
|
-
def item_name(item)
|
47
|
-
"#{attr_key}_#{item.is_a?(Array) ? item.first : item}"
|
48
|
-
end
|
49
|
-
|
50
|
-
def item_label(item)
|
51
|
-
item.is_a?(Array) ? item.first : item
|
52
|
-
end
|
53
|
-
|
54
|
-
def v_model_type
|
55
|
-
if radio_options && item_value(radio_options.first).is_a?(Integer)
|
56
|
-
'v-model.number'
|
57
|
-
else
|
58
|
-
'v-model'
|
9
|
+
div class: "matestack-ui-core-form-radio" do
|
10
|
+
render_options
|
11
|
+
render_errors
|
59
12
|
end
|
60
13
|
end
|
61
14
|
|
62
|
-
def change_event
|
63
|
-
"inputChanged('#{attr_key}')"
|
64
|
-
end
|
65
|
-
|
66
|
-
def id_for_item(value)
|
67
|
-
"#{html_attributes[:id] || attr_key}_#{value}"
|
68
|
-
end
|
69
|
-
|
70
15
|
end
|
71
16
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require_relative '../utils'
|
2
|
+
require_relative '../has_errors'
|
3
|
+
module Matestack::Ui::Core::Form::Select
|
4
|
+
class Base < Matestack::Ui::Core::Component::Dynamic
|
5
|
+
include Matestack::Ui::Core::Form::Utils
|
6
|
+
include Matestack::Ui::Core::Form::HasErrors
|
7
|
+
|
8
|
+
html_attributes :autofocus, :disabled, :form, :multiple, :name, :required, :size
|
9
|
+
|
10
|
+
requires :key
|
11
|
+
optional :multiple, :init, :placeholder, :disabled_values,
|
12
|
+
for: { as: :input_for },
|
13
|
+
label: { as: :input_label },
|
14
|
+
options: { as: :select_options }
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@component_config[:init_value] = init_value
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def component_id
|
22
|
+
"select-component-for-#{attr_key}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def select_attributes
|
26
|
+
html_attributes.merge(attributes: vue_attributes)
|
27
|
+
end
|
28
|
+
|
29
|
+
def render_options
|
30
|
+
if placeholder
|
31
|
+
option value: 'null', disabled: true, selected: init_value.nil?, text: placeholder
|
32
|
+
end
|
33
|
+
select_options.to_a.each do |item|
|
34
|
+
option value: item_value(item), disabled: item_disabled(item), text: item_label(item)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def input_key
|
39
|
+
"$parent.data[\"#{key}\"]"
|
40
|
+
end
|
41
|
+
|
42
|
+
def error_key
|
43
|
+
"$parent.errors[\"#{key}\"]"
|
44
|
+
end
|
45
|
+
|
46
|
+
def change_event
|
47
|
+
"inputChanged('#{attr_key}')"
|
48
|
+
end
|
49
|
+
|
50
|
+
def vue_attributes
|
51
|
+
(options[:attributes] || {}).merge({
|
52
|
+
"@change": change_event,
|
53
|
+
ref: vue_ref,
|
54
|
+
'init-value': init_value || [],
|
55
|
+
'v-bind:class': "{ '#{input_error_class}': #{error_key} }",
|
56
|
+
'value-type': value_type,
|
57
|
+
"#{v_model_type}": input_key,
|
58
|
+
})
|
59
|
+
end
|
60
|
+
|
61
|
+
def vue_ref
|
62
|
+
"select#{'.multiple' if multiple}.#{attr_key}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def value_type
|
66
|
+
item_value(select_options.first).is_a?(Integer) ? Integer : nil
|
67
|
+
end
|
68
|
+
|
69
|
+
def item_value(item)
|
70
|
+
item.is_a?(Array) ? item.last : item
|
71
|
+
end
|
72
|
+
|
73
|
+
def item_name(item)
|
74
|
+
"#{attr_key}_#{item.is_a?(Array) ? item.first : item}"
|
75
|
+
end
|
76
|
+
|
77
|
+
def item_disabled(item)
|
78
|
+
disabled_values.present? && disabled_values.include?(item_value(item))
|
79
|
+
end
|
80
|
+
|
81
|
+
def item_label(item)
|
82
|
+
item.is_a?(Array) ? item.first : item
|
83
|
+
end
|
84
|
+
|
85
|
+
def v_model_type
|
86
|
+
if select_options && item_value(select_options.first).is_a?(Integer) && !multiple
|
87
|
+
'v-model.number'
|
88
|
+
else
|
89
|
+
'v-model'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def id_for_item(value)
|
94
|
+
"#{html_attributes[:id]}_#{value}"
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|