mpizenberg / elm-file Goto Github PK
View Code? Open in Web Editor NEWAlternative to elm/file that can be encoded and passed through ports
License: BSD 3-Clause "New" or "Revised" License
Alternative to elm/file that can be encoded and passed through ports
License: BSD 3-Clause "New" or "Revised" License
While using FileValue.onDrop
function, a set of properties must be given as a parameter :
dropConfig = { onOver, onDrop, onLeave }
Each of those is a function taking as parameters a file and a list of file.
I have no trouble reading the content of the files for the onDrop
function, but while using the onOver
function and writing in my logs the content of the file being dragged over, I get the following result :
{ lastModified = Posix 0
, mime = "text/plain"
, name = "If you see this file, please report an error at https://github.com/mpizenberg/elm-files/issues"
, size = 0
, value = <internals> }
Here is the exact piece of code giving me this result :
ฬ```elm
let
extensionRegex : Regex.Regex
extensionRegex = Maybe.withDefault Regex.never <| Regex.fromString "*\\.csv"
extension : String -> Bool
extension fileName =
Regex.contains extensionRegex fileName
in
List.map Element.htmlAttribute
(File.onDrop
-- /!\ Cannot work with file.mime string for onOver,
-- as it seems to always be "text/plain"
{ onOver = \file otherFiles ->
if extension (Debug.log "name:" file).name then
DragDropLightsMsg DragOverLights
else
DragDropImagesMsg DragOverImages
-- (case Debug.log "mime:" file.mime of
-- "text/csv" ->
-- DragDropLightsMsg DragOverLights
-- "text/plain" ->
-- DragDropLightsMsg DragOverLights
-- "image/*" ->
-- DragDropImagesMsg DragOverImages
-- _ ->
-- ClearLogs
-- )
, onDrop = \file otherFiles ->
(case file.mime of
"text/csv" ->
DragDropLightsMsg (DropLights file)
_ ->
DragDropImagesMsg (DropImages file otherFiles)
)
, onLeave = Just { id = "FileDropArea", msg = DragDropImagesMsg DragLeaveImages }
}
)
## Reproductibility :
I have tried the following browsing tools :
[x] Firefox
[x] Chrome
[ ] Explorer
[ ] Opera
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.