Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7423071
ve.ui.DSVFileTransferHandler.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
ve.ui.DSVFileTransferHandler.js
View Options
/*!
* VisualEditor UserInterface delimiter-separated values file transfer handler class.
*
* @copyright See AUTHORS.txt
*/
/**
* Delimiter-separated values file transfer handler.
*
* @class
* @extends ve.ui.FileTransferHandler
*
* @constructor
* @param {ve.ui.Surface} surface
* @param {ve.ui.DataTransferItem} item
*/
ve
.
ui
.
DSVFileTransferHandler
=
function
VeUiDSVFileTransferHandler
()
{
// Parent constructor
ve
.
ui
.
DSVFileTransferHandler
.
super
.
apply
(
this
,
arguments
);
};
/* Inheritance */
OO
.
inheritClass
(
ve
.
ui
.
DSVFileTransferHandler
,
ve
.
ui
.
FileTransferHandler
);
/* Static properties */
ve
.
ui
.
DSVFileTransferHandler
.
static
.
name
=
'dsv'
;
ve
.
ui
.
DSVFileTransferHandler
.
static
.
types
=
[
'text/csv'
,
'text/tab-separated-values'
];
ve
.
ui
.
DSVFileTransferHandler
.
static
.
extensions
=
[
'csv'
,
'tsv'
];
/* Methods */
/**
* @inheritdoc
*/
ve
.
ui
.
DSVFileTransferHandler
.
prototype
.
onFileLoad
=
function
()
{
const
data
=
[];
const
input
=
Papa
.
parse
(
this
.
reader
.
result
);
if
(
input
.
meta
.
aborted
||
(
input
.
data
.
length
<=
0
)
)
{
this
.
abort
();
}
else
{
// Lookup the type for table elements
const
tableNodeName
=
ve
.
dm
.
modelRegistry
.
matchElement
(
document
.
createElement
(
'table'
)
);
const
tableNodeClass
=
ve
.
dm
.
modelRegistry
.
lookup
(
tableNodeName
);
const
tableElement
=
{
type
:
tableNodeName
};
// Sanitize, as this can add default attributes for the table type
tableNodeClass
.
static
.
sanitize
(
tableElement
);
data
.
push
(
tableElement
,
{
type
:
'tableSection'
,
attributes
:
{
style
:
'body'
}
}
);
input
.
data
.
forEach
(
(
line
,
i
)
=>
{
// Skip 'empty' row if at the end of the file
if
(
i
===
input
.
data
.
length
-
1
&&
line
.
length
===
1
&&
line
[
0
]
===
''
)
{
return
;
}
data
.
push
(
{
type
:
'tableRow'
}
);
line
.
forEach
(
(
cell
)
=>
{
data
.
push
(
{
type
:
'tableCell'
,
attributes
:
{
style
:
(
i
===
0
?
'header'
:
'data'
)
}
},
{
type
:
'paragraph'
,
internal
:
{
generated
:
'wrapper'
}
}
);
ve
.
batchPush
(
data
,
cell
.
split
(
''
)
);
data
.
push
(
{
type
:
'/paragraph'
},
{
type
:
'/tableCell'
}
);
}
);
data
.
push
(
{
type
:
'/tableRow'
}
);
}
);
data
.
push
(
{
type
:
'/tableSection'
},
{
type
:
'/'
+
tableElement
.
type
}
);
this
.
resolve
(
data
);
}
// Parent method
ve
.
ui
.
DSVFileTransferHandler
.
super
.
prototype
.
onFileLoad
.
apply
(
this
,
arguments
);
};
/* Registration */
ve
.
ui
.
dataTransferHandlerFactory
.
register
(
ve
.
ui
.
DSVFileTransferHandler
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 22, 06:20 (23 h, 42 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
b0/bd/b93f4a9c8c57b29a9729b7e73156
Default Alt Text
ve.ui.DSVFileTransferHandler.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment