polaris_view_components 0.5.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -2
- data/app/assets/javascripts/polaris_view_components/autocomplete_controller.js +136 -0
- data/app/assets/javascripts/polaris_view_components/button_controller.js +47 -0
- data/app/assets/javascripts/polaris_view_components/dropzone_controller.js +495 -0
- data/app/assets/javascripts/polaris_view_components/frame_controller.js +41 -0
- data/app/assets/javascripts/polaris_view_components/index.js +21 -1
- data/app/assets/javascripts/polaris_view_components/modal_controller.js +25 -0
- data/app/assets/javascripts/polaris_view_components/option_list_controller.js +41 -0
- data/app/assets/javascripts/polaris_view_components/polaris_controller.js +28 -0
- data/app/assets/javascripts/polaris_view_components/popover_controller.js +56 -0
- data/app/assets/javascripts/polaris_view_components/scrollable_controller.js +60 -0
- data/app/assets/javascripts/polaris_view_components/text_field_controller.js +4 -0
- data/app/assets/javascripts/polaris_view_components/toast_controller.js +68 -0
- data/app/assets/javascripts/polaris_view_components/utils.js +23 -0
- data/app/assets/javascripts/polaris_view_components.js +2400 -1
- data/app/assets/stylesheets/polaris_view_components/custom.css +104 -6
- data/app/assets/stylesheets/polaris_view_components.css +2147 -2021
- data/app/assets/stylesheets/polaris_view_components.postcss.css +1 -1
- data/app/components/polaris/action.rb +3 -3
- data/app/components/polaris/action_list/item_component.html.erb +35 -0
- data/app/components/polaris/action_list/item_component.rb +41 -0
- data/app/components/polaris/action_list/section_component.html.erb +16 -0
- data/app/components/polaris/action_list/section_component.rb +26 -0
- data/app/components/polaris/action_list_component.html.erb +13 -0
- data/app/components/polaris/action_list_component.rb +25 -0
- data/app/components/polaris/autocomplete/action_component.rb +7 -0
- data/app/components/polaris/autocomplete/option_component.rb +35 -0
- data/app/components/polaris/autocomplete/section_component.html.erb +9 -0
- data/app/components/polaris/autocomplete/section_component.rb +12 -0
- data/app/components/polaris/autocomplete_component.html.erb +30 -0
- data/app/components/polaris/autocomplete_component.rb +65 -0
- data/app/components/polaris/avatar_component.rb +2 -2
- data/app/components/polaris/badge_component.rb +2 -2
- data/app/components/polaris/banner_component.rb +8 -8
- data/app/components/polaris/base_button.rb +2 -2
- data/app/components/polaris/base_checkbox.rb +48 -0
- data/app/components/polaris/base_component.rb +1 -1
- data/app/components/polaris/base_radio_button.rb +38 -0
- data/app/components/polaris/button_component.html.erb +13 -0
- data/app/components/polaris/button_group_component.rb +8 -8
- data/app/components/polaris/callout_card_component.rb +6 -6
- data/app/components/polaris/caption_component.rb +3 -3
- data/app/components/polaris/card/header_component.rb +2 -2
- data/app/components/polaris/card/section_component.rb +4 -4
- data/app/components/polaris/card_component.html.erb +4 -0
- data/app/components/polaris/card_component.rb +6 -5
- data/app/components/polaris/character_count.rb +10 -10
- data/app/components/polaris/checkbox_component.html.erb +1 -5
- data/app/components/polaris/checkbox_component.rb +20 -13
- data/app/components/polaris/choice_component.rb +2 -2
- data/app/components/polaris/choice_list_component.rb +6 -6
- data/app/components/polaris/component.rb +6 -1
- data/app/components/polaris/data_table/cell_component.rb +4 -4
- data/app/components/polaris/data_table/column_component.rb +1 -1
- data/app/components/polaris/data_table_component.rb +4 -4
- data/app/components/polaris/description_list_component.rb +5 -5
- data/app/components/polaris/display_text_component.rb +3 -3
- data/app/components/polaris/dropzone_component.html.erb +156 -0
- data/app/components/polaris/dropzone_component.rb +150 -0
- data/app/components/polaris/empty_state_component.rb +4 -4
- data/app/components/polaris/exception_list/item_component.rb +3 -3
- data/app/components/polaris/exception_list_component.rb +2 -2
- data/app/components/polaris/filters_component.html.erb +22 -0
- data/app/components/polaris/filters_component.rb +61 -8
- data/app/components/polaris/footer_help_component.rb +2 -2
- data/app/components/polaris/form_layout/group_component.rb +5 -5
- data/app/components/polaris/form_layout/item_component.rb +2 -2
- data/app/components/polaris/form_layout_component.rb +4 -4
- data/app/components/polaris/frame/save_bar_component.html.erb +23 -0
- data/app/components/polaris/frame/save_bar_component.rb +31 -0
- data/app/components/polaris/frame/top_bar_component.html.erb +30 -0
- data/app/components/polaris/frame/top_bar_component.rb +18 -0
- data/app/components/polaris/frame_component.html.erb +44 -0
- data/app/components/polaris/frame_component.rb +33 -0
- data/app/components/polaris/heading_component.rb +2 -2
- data/app/components/polaris/headless_button.html.erb +13 -0
- data/app/components/polaris/headless_button.rb +18 -6
- data/app/components/polaris/icon_component.rb +3 -3
- data/app/components/polaris/index_table/cell_component.rb +3 -3
- data/app/components/polaris/index_table/column_component.rb +1 -1
- data/app/components/polaris/index_table_component.rb +4 -4
- data/app/components/polaris/inline_error_component.rb +2 -2
- data/app/components/polaris/label_component.rb +3 -3
- data/app/components/polaris/labelled_component.rb +3 -3
- data/app/components/polaris/layout/annotated_section.rb +2 -2
- data/app/components/polaris/layout/section.rb +2 -2
- data/app/components/polaris/layout_component.rb +4 -4
- data/app/components/polaris/link_component.rb +4 -4
- data/app/components/polaris/list_component.rb +5 -5
- data/app/components/polaris/logo.rb +13 -0
- data/app/components/polaris/modal/section_component.rb +19 -0
- data/app/components/polaris/modal_component.html.erb +79 -0
- data/app/components/polaris/modal_component.rb +98 -0
- data/app/components/polaris/navigation/item_component.html.erb +31 -0
- data/app/components/polaris/navigation/item_component.rb +85 -0
- data/app/components/polaris/navigation/section_component.html.erb +17 -0
- data/app/components/polaris/navigation/section_component.rb +64 -0
- data/app/components/polaris/navigation_component.html.erb +29 -0
- data/app/components/polaris/navigation_component.rb +15 -0
- data/app/components/polaris/option_list/checkbox_component.html.erb +14 -0
- data/app/components/polaris/option_list/checkbox_component.rb +37 -0
- data/app/components/polaris/option_list/option_component.rb +24 -0
- data/app/components/polaris/option_list/radio_button_component.rb +54 -0
- data/app/components/polaris/option_list/section_component.html.erb +14 -0
- data/app/components/polaris/option_list/section_component.rb +53 -0
- data/app/components/polaris/option_list_component.html.erb +15 -0
- data/app/components/polaris/option_list_component.rb +67 -0
- data/app/components/polaris/page_actions_component.rb +9 -8
- data/app/components/polaris/page_component.rb +5 -5
- data/app/components/polaris/pagination_component.rb +2 -6
- data/app/components/polaris/popover/pane_component.html.erb +25 -0
- data/app/components/polaris/popover/pane_component.rb +20 -0
- data/app/components/polaris/popover/section_component.rb +19 -0
- data/app/components/polaris/popover_component.html.erb +31 -0
- data/app/components/polaris/popover_component.rb +113 -0
- data/app/components/polaris/progress_bar_component.rb +6 -6
- data/app/components/polaris/radio_button_component.html.erb +1 -6
- data/app/components/polaris/radio_button_component.rb +18 -8
- data/app/components/polaris/resource_item_component.html.erb +16 -6
- data/app/components/polaris/resource_item_component.rb +43 -10
- data/app/components/polaris/resource_list_component.rb +3 -3
- data/app/components/polaris/scrollable_component.html.erb +5 -0
- data/app/components/polaris/scrollable_component.rb +48 -0
- data/app/components/polaris/select_component.rb +4 -4
- data/app/components/polaris/setting_toggle_component.html.erb +10 -0
- data/app/components/polaris/setting_toggle_component.rb +24 -0
- data/app/components/polaris/shopify_navigation_component.rb +8 -8
- data/app/components/polaris/skeleton_body_text_component.rb +2 -2
- data/app/components/polaris/spacer_component.rb +4 -4
- data/app/components/polaris/spinner_component.rb +3 -3
- data/app/components/polaris/stack/item_component.rb +15 -0
- data/app/components/polaris/stack_component.rb +6 -22
- data/app/components/polaris/subheading_component.rb +2 -2
- data/app/components/polaris/tabs/tab_component.html.erb +10 -0
- data/app/components/polaris/tabs/tab_component.rb +34 -0
- data/app/components/polaris/tabs_component.html.erb +7 -0
- data/app/components/polaris/tabs_component.rb +37 -0
- data/app/components/polaris/tag_component.rb +3 -2
- data/app/components/polaris/text_container_component.rb +3 -3
- data/app/components/polaris/text_field_component.rb +25 -11
- data/app/components/polaris/text_style_component.rb +5 -5
- data/app/components/polaris/thumbnail_component.rb +3 -3
- data/app/components/polaris/toast_component.html.erb +21 -0
- data/app/components/polaris/toast_component.rb +40 -0
- data/app/components/polaris/top_bar/user_menu_component.html.erb +19 -0
- data/app/components/polaris/top_bar/user_menu_component.rb +9 -0
- data/app/components/polaris/visually_hidden_component.rb +1 -1
- data/app/helpers/polaris/form_builder.rb +19 -8
- data/app/helpers/polaris/url_helper.rb +3 -3
- data/app/helpers/polaris/view_helper.rb +24 -4
- data/app/validators/type_validator.rb +2 -2
- data/config/locales/en.yml +6 -0
- data/lib/generators/polaris_view_components/install_generator.rb +5 -5
- data/lib/polaris/view_components/engine.rb +16 -2
- data/lib/polaris/view_components/version.rb +1 -1
- data/lib/polaris_view_components.rb +1 -1
- metadata +79 -16
- data/app/components/polaris/application_component.rb +0 -35
- data/app/components/polaris/dropzone/component.html.erb +0 -72
- data/app/components/polaris/dropzone/component.rb +0 -128
- data/app/components/polaris/dropzone/controller.js +0 -226
- data/app/components/polaris/dropzone/utils.js +0 -57
- data/app/components/polaris/new_component.rb +0 -10
- data/app/helpers/polaris/conditional_helper.rb +0 -11
@@ -1,128 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Polaris
|
4
|
-
module Dropzone
|
5
|
-
class Component < Polaris::Component
|
6
|
-
ALLOWED_TYPES = %w[file image]
|
7
|
-
|
8
|
-
validates :type, inclusion: { in: ALLOWED_TYPES, message: "%{value} is not a valid type" }
|
9
|
-
validates :label_action, type: Action, allow_nil: true
|
10
|
-
|
11
|
-
# TODO
|
12
|
-
# Options missing:
|
13
|
-
# - open_file_dialog
|
14
|
-
# - overlay
|
15
|
-
# - overlay_text
|
16
|
-
# - Size CSS Class
|
17
|
-
# - Doesn't take into account an initial load with files
|
18
|
-
|
19
|
-
attr_reader :label_action, :type
|
20
|
-
|
21
|
-
def initialize(
|
22
|
-
form:,
|
23
|
-
attribute:,
|
24
|
-
accept: "",
|
25
|
-
active: false,
|
26
|
-
allow_multiple: true,
|
27
|
-
disabled: false,
|
28
|
-
drop_on_page: false,
|
29
|
-
error: false,
|
30
|
-
error_overlay_text: "",
|
31
|
-
id: "",
|
32
|
-
label: "",
|
33
|
-
label_action: nil,
|
34
|
-
label_hidden: false,
|
35
|
-
overlay_text: "Drop file to upload",
|
36
|
-
outline: true,
|
37
|
-
type: "file",
|
38
|
-
**args
|
39
|
-
)
|
40
|
-
super
|
41
|
-
|
42
|
-
@form = form
|
43
|
-
@attribute = attribute
|
44
|
-
@accept = accept
|
45
|
-
@active = active
|
46
|
-
@allow_multiple = allow_multiple
|
47
|
-
@disabled = disabled
|
48
|
-
@drop_on_page = drop_on_page
|
49
|
-
@error = error
|
50
|
-
@error_overlay_text = error_overlay_text
|
51
|
-
@id = id
|
52
|
-
@label = label
|
53
|
-
@label_action = label_action
|
54
|
-
@label_hidden = label_hidden
|
55
|
-
@overlay_text = overlay_text
|
56
|
-
@outline = outline
|
57
|
-
@type = type
|
58
|
-
end
|
59
|
-
|
60
|
-
def labelled_attrs
|
61
|
-
{
|
62
|
-
form: @form,
|
63
|
-
attribute: @attribute,
|
64
|
-
error: @error,
|
65
|
-
label: @label,
|
66
|
-
label_hidden: @label_hidden,
|
67
|
-
index: @index,
|
68
|
-
action: @label_action
|
69
|
-
}
|
70
|
-
end
|
71
|
-
|
72
|
-
def input_attrs
|
73
|
-
{
|
74
|
-
accept: @accept,
|
75
|
-
disabled: @disabled,
|
76
|
-
type: "file",
|
77
|
-
multiple: @allow_multiple,
|
78
|
-
data: {
|
79
|
-
action: "focus->polaris--dropzone#onFocus blur->polaris--dropzone#onBlur change->polaris--dropzone#onChange",
|
80
|
-
'polaris--dropzone-target': 'input',
|
81
|
-
}
|
82
|
-
}
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
|
87
|
-
def additional_aria
|
88
|
-
{
|
89
|
-
disabled: @disabled.to_s,
|
90
|
-
}
|
91
|
-
end
|
92
|
-
|
93
|
-
def additional_data
|
94
|
-
{
|
95
|
-
controller: "polaris--dropzone",
|
96
|
-
action: "click->polaris--dropzone#onClick #{drop_actions}",
|
97
|
-
'polaris--dropzone-accept-value': @accept,
|
98
|
-
'polaris--dropzone-allowMultiple-value': @allow_multiple.to_s,
|
99
|
-
'polaris--dropzone-disabled-value': @disabled.to_s,
|
100
|
-
'polaris--dropzone-focused-value': 'false',
|
101
|
-
'polaris--dropzone-drop-on-page-value': 'false',
|
102
|
-
}
|
103
|
-
end
|
104
|
-
|
105
|
-
def drop_actions
|
106
|
-
event_scope = @drop_on_page ? "@document" : ""
|
107
|
-
|
108
|
-
[
|
109
|
-
"drop#{event_scope}->polaris--dropzone#onDrop",
|
110
|
-
"dragover#{event_scope}->polaris--dropzone#onDragOver",
|
111
|
-
"dragenter#{event_scope}->polaris--dropzone#onDragEnter",
|
112
|
-
"dragleave#{event_scope}->polaris--dropzone#onDragLeave"
|
113
|
-
].join(" ")
|
114
|
-
end
|
115
|
-
|
116
|
-
def classes
|
117
|
-
classes = %w[Polaris-DropZone Polaris-DropZone--sizeExtraLarge]
|
118
|
-
|
119
|
-
classes << "Polaris-DropZone--isDisabled" if @disabled
|
120
|
-
classes << "Polaris-DropZone--isDisabled" if @disabled
|
121
|
-
classes << "Polaris-DropZone--hasError" if @error.present?
|
122
|
-
classes << "Polaris-DropZone--hasOutline" if @outline
|
123
|
-
|
124
|
-
classes
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
@@ -1,226 +0,0 @@
|
|
1
|
-
import { Controller } from "@hotwired/stimulus"
|
2
|
-
|
3
|
-
import { fileAccepted, getDataTransferFiles } from './utils'
|
4
|
-
|
5
|
-
// eslint-disable-next-line import/no-default-export
|
6
|
-
export default class extends Controller {
|
7
|
-
static targets = ['container', 'fileUpload', 'input', 'itemTemplate', 'itemsTemplate', 'overlay']
|
8
|
-
static values = {
|
9
|
-
accept: String,
|
10
|
-
allowMultiple: Boolean,
|
11
|
-
disabled: Boolean,
|
12
|
-
dropOnPage: Boolean,
|
13
|
-
focused: Boolean,
|
14
|
-
}
|
15
|
-
|
16
|
-
_files = []
|
17
|
-
_acceptedFiles = []
|
18
|
-
_rejectedFiles = []
|
19
|
-
_dragging = false
|
20
|
-
dragTargets = []
|
21
|
-
filesRendered = false
|
22
|
-
|
23
|
-
onBlur () {
|
24
|
-
this.focusedValue = false
|
25
|
-
}
|
26
|
-
|
27
|
-
onChange (e) {
|
28
|
-
this.stopEvent(e)
|
29
|
-
if (this.disabled) return
|
30
|
-
|
31
|
-
this.clearFiles()
|
32
|
-
|
33
|
-
const fileList = getDataTransferFiles(e)
|
34
|
-
const { files, acceptedFiles, rejectedFiles } = this.getValidatedFiles(fileList)
|
35
|
-
this.dragTargets = []
|
36
|
-
|
37
|
-
this.files = files
|
38
|
-
this.acceptedFiles = acceptedFiles
|
39
|
-
this.rejectedFiles = rejectedFiles
|
40
|
-
}
|
41
|
-
|
42
|
-
onDragOver (e) {
|
43
|
-
this.stopEvent(e)
|
44
|
-
if (this.disabled) return
|
45
|
-
}
|
46
|
-
|
47
|
-
onDragEnter (e) {
|
48
|
-
this.stopEvent(e)
|
49
|
-
if (this.disabled) return
|
50
|
-
|
51
|
-
if (e.target && !this.dragTargets.includes(e.target)) {
|
52
|
-
this.dragTargets.push(e.target)
|
53
|
-
}
|
54
|
-
|
55
|
-
if (this.dragging) return
|
56
|
-
|
57
|
-
this.dragging = true
|
58
|
-
}
|
59
|
-
|
60
|
-
onDragLeave (e) {
|
61
|
-
this.stopEvent(e)
|
62
|
-
if (this.disabled) return
|
63
|
-
|
64
|
-
this.dragTargets = this.dragTargets.filter(el => {
|
65
|
-
const compareNode = this.element
|
66
|
-
|
67
|
-
return el !== e.target && compareNode && compareNode.contains(el)
|
68
|
-
})
|
69
|
-
|
70
|
-
if (this.dragTargets.length > 0) return
|
71
|
-
|
72
|
-
this.dragging = false
|
73
|
-
}
|
74
|
-
|
75
|
-
onDrop (e) {
|
76
|
-
this.stopEvent(e)
|
77
|
-
if (this.disabled) return
|
78
|
-
|
79
|
-
this.dragging = false
|
80
|
-
|
81
|
-
this.onChange(e)
|
82
|
-
}
|
83
|
-
|
84
|
-
onFocus () {
|
85
|
-
this.focusedValue = true
|
86
|
-
}
|
87
|
-
|
88
|
-
onClick () {
|
89
|
-
if (this.disabledValue) return
|
90
|
-
|
91
|
-
this.open()
|
92
|
-
}
|
93
|
-
|
94
|
-
open () {
|
95
|
-
this.inputTarget.click()
|
96
|
-
}
|
97
|
-
|
98
|
-
focusedValueChanged () {
|
99
|
-
this.element.classList.toggle('Polaris-DropZone--focused', this.focusedValue)
|
100
|
-
}
|
101
|
-
|
102
|
-
stopEvent (e) {
|
103
|
-
e.preventDefault()
|
104
|
-
e.stopPropagation()
|
105
|
-
}
|
106
|
-
|
107
|
-
getValidatedFiles (files) {
|
108
|
-
const acceptedFiles = []
|
109
|
-
const rejectedFiles = []
|
110
|
-
|
111
|
-
Array.from(files).forEach(file => {
|
112
|
-
if (!fileAccepted(file, this.acceptValue)) {
|
113
|
-
return rejectedFiles.push(file)
|
114
|
-
}
|
115
|
-
|
116
|
-
acceptedFiles.push(file)
|
117
|
-
})
|
118
|
-
|
119
|
-
if (!this.allowMultipleValue) {
|
120
|
-
acceptedFiles.splice(1, acceptedFiles.length)
|
121
|
-
rejectedFiles.push(...acceptedFiles.slice(1))
|
122
|
-
}
|
123
|
-
|
124
|
-
return { files, acceptedFiles, rejectedFiles }
|
125
|
-
}
|
126
|
-
|
127
|
-
renderUploadedFiles () {
|
128
|
-
if (this.files.length === 0) return
|
129
|
-
|
130
|
-
const clone = this.itemsTemplateTarget.content.cloneNode(true)
|
131
|
-
const filesTarget = clone.querySelector('.target')
|
132
|
-
|
133
|
-
this.files
|
134
|
-
.map(file => this.renderFile(file))
|
135
|
-
.forEach(fragment => filesTarget.parentNode.appendChild(fragment))
|
136
|
-
filesTarget.remove()
|
137
|
-
|
138
|
-
this.containerTarget.prepend(clone)
|
139
|
-
|
140
|
-
this.filesRendered = true
|
141
|
-
}
|
142
|
-
|
143
|
-
renderFile (file) {
|
144
|
-
const clone = this.itemTemplateTarget.content.cloneNode(true)
|
145
|
-
const [image, content, caption] = [
|
146
|
-
clone.querySelector('img'),
|
147
|
-
clone.querySelector('.content'),
|
148
|
-
clone.querySelector('.Polaris-Caption'),
|
149
|
-
]
|
150
|
-
image.alt = file.name
|
151
|
-
image.src = window.URL.createObjectURL(file)
|
152
|
-
content.insertAdjacentText('afterbegin', file.name)
|
153
|
-
caption.textContent = `${file.size} bytes`
|
154
|
-
|
155
|
-
return clone
|
156
|
-
}
|
157
|
-
|
158
|
-
clearFiles () {
|
159
|
-
if (!this.filesRendered) return
|
160
|
-
|
161
|
-
this.acceptedFiles = []
|
162
|
-
this.files = []
|
163
|
-
this.rejectedFiles = []
|
164
|
-
|
165
|
-
const rendered = this.element.querySelector('[data-rendered]')
|
166
|
-
if (!rendered) return
|
167
|
-
|
168
|
-
rendered.remove()
|
169
|
-
this.filesRendered = false
|
170
|
-
}
|
171
|
-
|
172
|
-
get dropNode () {
|
173
|
-
return this.dropOnPageValue ? document : this.element
|
174
|
-
}
|
175
|
-
|
176
|
-
get disabled () {
|
177
|
-
return this.disabledValue
|
178
|
-
}
|
179
|
-
|
180
|
-
set disabled (val) {
|
181
|
-
this.disabledValue = val
|
182
|
-
}
|
183
|
-
|
184
|
-
get dragging () {
|
185
|
-
return this._dragging
|
186
|
-
}
|
187
|
-
|
188
|
-
set dragging (val) {
|
189
|
-
this._dragging = val
|
190
|
-
|
191
|
-
this.element.classList.toggle('Polaris-DropZone--isDragging', val)
|
192
|
-
this.overlayTarget.classList.toggle('Polaris-VisuallyHidden', !val)
|
193
|
-
}
|
194
|
-
|
195
|
-
get files () {
|
196
|
-
return this._files
|
197
|
-
}
|
198
|
-
|
199
|
-
set files (val) {
|
200
|
-
this._files = val
|
201
|
-
|
202
|
-
const hasFiles = val.length > 0
|
203
|
-
|
204
|
-
this.fileUploadTarget.classList.toggle('Polaris-VisuallyHidden', hasFiles)
|
205
|
-
|
206
|
-
if (hasFiles && !this.filesRendered) {
|
207
|
-
this.renderUploadedFiles()
|
208
|
-
}
|
209
|
-
}
|
210
|
-
|
211
|
-
get acceptedFiles () {
|
212
|
-
return this._acceptedFiles
|
213
|
-
}
|
214
|
-
|
215
|
-
set acceptedFiles (val) {
|
216
|
-
this._acceptedFiles = val
|
217
|
-
}
|
218
|
-
|
219
|
-
get rejectedFiles () {
|
220
|
-
return this._rejectedFiles
|
221
|
-
}
|
222
|
-
|
223
|
-
set rejectedFiles (val) {
|
224
|
-
this._rejectedFiles = val
|
225
|
-
}
|
226
|
-
}
|
@@ -1,57 +0,0 @@
|
|
1
|
-
const dragEvents = ['dragover', 'dragenter', 'drop']
|
2
|
-
|
3
|
-
export function fileAccepted (file, accept) {
|
4
|
-
return file.type === 'application/x-moz-file' || accepts(file, accept)
|
5
|
-
}
|
6
|
-
|
7
|
-
export function getDataTransferFiles (event) {
|
8
|
-
if (isDragEvent(event) && event.dataTransfer) {
|
9
|
-
const dt = event.dataTransfer
|
10
|
-
|
11
|
-
if (dt.files && dt.files.length) {
|
12
|
-
return Array.from(dt.files)
|
13
|
-
} else if (dt.items && dt.items.length) {
|
14
|
-
// Chrome is the only browser that allows to read the file list on drag
|
15
|
-
// events and uses `items` instead of `files` in this case.
|
16
|
-
return Array.from(dt.items)
|
17
|
-
}
|
18
|
-
} else if (isChangeEvent(event) && event.target.files) {
|
19
|
-
// Return files from even when a file was selected from an upload dialog
|
20
|
-
return Array.from(event.target.files)
|
21
|
-
}
|
22
|
-
|
23
|
-
return []
|
24
|
-
}
|
25
|
-
|
26
|
-
function accepts (file, acceptedFiles = ['']) {
|
27
|
-
if (file && acceptedFiles) {
|
28
|
-
const fileName = file.name || ''
|
29
|
-
const mimeType = file.type || ''
|
30
|
-
const baseMimeType = mimeType.replace(/\/.*$/, '')
|
31
|
-
const acceptedFilesArray = Array.isArray(acceptedFiles)
|
32
|
-
? acceptedFiles
|
33
|
-
: acceptedFiles.split(',')
|
34
|
-
|
35
|
-
return acceptedFilesArray.some((type) => {
|
36
|
-
const validType = type.trim()
|
37
|
-
if (validType.startsWith('.')) {
|
38
|
-
return fileName.toLowerCase().endsWith(validType.toLowerCase())
|
39
|
-
} else if (validType.endsWith('/*')) {
|
40
|
-
// This is something like a image/* mime type
|
41
|
-
return baseMimeType === validType.replace(/\/.*$/, '')
|
42
|
-
}
|
43
|
-
|
44
|
-
return mimeType === validType
|
45
|
-
})
|
46
|
-
}
|
47
|
-
|
48
|
-
return true
|
49
|
-
}
|
50
|
-
|
51
|
-
function isDragEvent (event) {
|
52
|
-
return dragEvents.indexOf(event.type) > 0
|
53
|
-
}
|
54
|
-
|
55
|
-
function isChangeEvent (event) {
|
56
|
-
return event.type === 'change'
|
57
|
-
}
|