@usecsv/react 0.0.2 → 0.1.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.
- package/.babelrc.jest.js +14 -0
- package/.editorconfig +15 -0
- package/.env +0 -0
- package/.env.example +1 -0
- package/.eslintignore +1 -0
- package/.eslintrc.airbnbts.js +73 -0
- package/.eslintrc.json +91 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +7 -0
- package/.github/dependabot.yml +7 -0
- package/.github/workflows/main.yml +44 -0
- package/.github/workflows/publish.yml +19 -0
- package/.github/workflows/sementic_release.yml +27 -0
- package/.gitignore +8 -0
- package/.nvmrc +1 -0
- package/.nyc_output/0196dd80-12a9-4176-bd5b-4a8bc6e984f9.json +1 -0
- package/.nyc_output/0d5259bc-f1f3-4ca2-9d4f-1f77daccebf4.json +1 -0
- package/.nyc_output/92c6bc34-84c6-46f7-9e14-0d1bd2068352.json +1 -0
- package/.nyc_output/a0942cca-db9b-40d2-833e-8fcf7011171f.json +1 -0
- package/.nyc_output/b3fc15a1-349d-4d4c-a8dd-2142cc988ac3.json +1 -0
- package/.nyc_output/processinfo/0196dd80-12a9-4176-bd5b-4a8bc6e984f9.json +1 -0
- package/.nyc_output/processinfo/0d5259bc-f1f3-4ca2-9d4f-1f77daccebf4.json +1 -0
- package/.nyc_output/processinfo/92c6bc34-84c6-46f7-9e14-0d1bd2068352.json +1 -0
- package/.nyc_output/processinfo/a0942cca-db9b-40d2-833e-8fcf7011171f.json +1 -0
- package/.nyc_output/processinfo/b3fc15a1-349d-4d4c-a8dd-2142cc988ac3.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/.nycrc +8 -0
- package/.prettierignore +2 -0
- package/.prettierrc.js +6 -0
- package/.releaserc.json +39 -0
- package/.vscode/extensions.json +8 -0
- package/.vscode/launch.json +29 -0
- package/.vscode/settings.json +21 -0
- package/CHANGELOG.md +7 -0
- package/build/index.cjs +4 -4
- package/build/index.cjs.map +1 -1
- package/build/index.esm.js +4 -4
- package/build/index.esm.js.map +1 -1
- package/build/index.js +4 -4
- package/build/index.js.map +1 -1
- package/build/index.mjs +4 -4
- package/build/index.mjs.map +1 -1
- package/build/index.umd.js +4 -4
- package/build/index.umd.js.map +1 -1
- package/build/index.umd.min.js +3 -3
- package/build/index.umd.min.js.map +1 -1
- package/build/types/lib/useCsvReactPlugin.d.ts +1 -1
- package/build/types/lib/useCsvReactPlugin.d.ts.map +1 -1
- package/commitlint.config.js +1 -0
- package/config/rollup.config.js +78 -0
- package/config/webpack.dev.js +59 -0
- package/package.json +9 -9
- package/reports/coverage/base.css +224 -0
- package/reports/coverage/block-navigation.js +79 -0
- package/reports/coverage/favicon.png +0 -0
- package/reports/coverage/index.html +96 -0
- package/reports/coverage/prettify.css +1 -0
- package/reports/coverage/prettify.js +2 -0
- package/reports/coverage/sort-arrow-sprite.png +0 -0
- package/reports/coverage/sorter.js +170 -0
- package/src/dev/index.html +14 -0
- package/src/dev/index.tsx +22 -0
- package/src/index.tsx +3 -0
- package/src/lib/useCsvReactPlugin.tsx +42 -0
- package/src/test/jest-setup.ts +7 -0
- package/tsconfig.json +35 -0
- package/tsconfig.module.json +23 -0
- package/yarn.lock +11867 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
var addSorting = (function() {
|
|
3
|
+
'use strict';
|
|
4
|
+
var cols,
|
|
5
|
+
currentSort = {
|
|
6
|
+
index: 0,
|
|
7
|
+
desc: false
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// returns the summary table element
|
|
11
|
+
function getTable() {
|
|
12
|
+
return document.querySelector('.coverage-summary');
|
|
13
|
+
}
|
|
14
|
+
// returns the thead element of the summary table
|
|
15
|
+
function getTableHeader() {
|
|
16
|
+
return getTable().querySelector('thead tr');
|
|
17
|
+
}
|
|
18
|
+
// returns the tbody element of the summary table
|
|
19
|
+
function getTableBody() {
|
|
20
|
+
return getTable().querySelector('tbody');
|
|
21
|
+
}
|
|
22
|
+
// returns the th element for nth column
|
|
23
|
+
function getNthColumn(n) {
|
|
24
|
+
return getTableHeader().querySelectorAll('th')[n];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// loads all columns
|
|
28
|
+
function loadColumns() {
|
|
29
|
+
var colNodes = getTableHeader().querySelectorAll('th'),
|
|
30
|
+
colNode,
|
|
31
|
+
cols = [],
|
|
32
|
+
col,
|
|
33
|
+
i;
|
|
34
|
+
|
|
35
|
+
for (i = 0; i < colNodes.length; i += 1) {
|
|
36
|
+
colNode = colNodes[i];
|
|
37
|
+
col = {
|
|
38
|
+
key: colNode.getAttribute('data-col'),
|
|
39
|
+
sortable: !colNode.getAttribute('data-nosort'),
|
|
40
|
+
type: colNode.getAttribute('data-type') || 'string'
|
|
41
|
+
};
|
|
42
|
+
cols.push(col);
|
|
43
|
+
if (col.sortable) {
|
|
44
|
+
col.defaultDescSort = col.type === 'number';
|
|
45
|
+
colNode.innerHTML =
|
|
46
|
+
colNode.innerHTML + '<span class="sorter"></span>';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return cols;
|
|
50
|
+
}
|
|
51
|
+
// attaches a data attribute to every tr element with an object
|
|
52
|
+
// of data values keyed by column name
|
|
53
|
+
function loadRowData(tableRow) {
|
|
54
|
+
var tableCols = tableRow.querySelectorAll('td'),
|
|
55
|
+
colNode,
|
|
56
|
+
col,
|
|
57
|
+
data = {},
|
|
58
|
+
i,
|
|
59
|
+
val;
|
|
60
|
+
for (i = 0; i < tableCols.length; i += 1) {
|
|
61
|
+
colNode = tableCols[i];
|
|
62
|
+
col = cols[i];
|
|
63
|
+
val = colNode.getAttribute('data-value');
|
|
64
|
+
if (col.type === 'number') {
|
|
65
|
+
val = Number(val);
|
|
66
|
+
}
|
|
67
|
+
data[col.key] = val;
|
|
68
|
+
}
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
// loads all row data
|
|
72
|
+
function loadData() {
|
|
73
|
+
var rows = getTableBody().querySelectorAll('tr'),
|
|
74
|
+
i;
|
|
75
|
+
|
|
76
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
77
|
+
rows[i].data = loadRowData(rows[i]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// sorts the table using the data for the ith column
|
|
81
|
+
function sortByIndex(index, desc) {
|
|
82
|
+
var key = cols[index].key,
|
|
83
|
+
sorter = function(a, b) {
|
|
84
|
+
a = a.data[key];
|
|
85
|
+
b = b.data[key];
|
|
86
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
87
|
+
},
|
|
88
|
+
finalSorter = sorter,
|
|
89
|
+
tableBody = document.querySelector('.coverage-summary tbody'),
|
|
90
|
+
rowNodes = tableBody.querySelectorAll('tr'),
|
|
91
|
+
rows = [],
|
|
92
|
+
i;
|
|
93
|
+
|
|
94
|
+
if (desc) {
|
|
95
|
+
finalSorter = function(a, b) {
|
|
96
|
+
return -1 * sorter(a, b);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
for (i = 0; i < rowNodes.length; i += 1) {
|
|
101
|
+
rows.push(rowNodes[i]);
|
|
102
|
+
tableBody.removeChild(rowNodes[i]);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
rows.sort(finalSorter);
|
|
106
|
+
|
|
107
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
108
|
+
tableBody.appendChild(rows[i]);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// removes sort indicators for current column being sorted
|
|
112
|
+
function removeSortIndicators() {
|
|
113
|
+
var col = getNthColumn(currentSort.index),
|
|
114
|
+
cls = col.className;
|
|
115
|
+
|
|
116
|
+
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
|
117
|
+
col.className = cls;
|
|
118
|
+
}
|
|
119
|
+
// adds sort indicators for current column being sorted
|
|
120
|
+
function addSortIndicators() {
|
|
121
|
+
getNthColumn(currentSort.index).className += currentSort.desc
|
|
122
|
+
? ' sorted-desc'
|
|
123
|
+
: ' sorted';
|
|
124
|
+
}
|
|
125
|
+
// adds event listeners for all sorter widgets
|
|
126
|
+
function enableUI() {
|
|
127
|
+
var i,
|
|
128
|
+
el,
|
|
129
|
+
ithSorter = function ithSorter(i) {
|
|
130
|
+
var col = cols[i];
|
|
131
|
+
|
|
132
|
+
return function() {
|
|
133
|
+
var desc = col.defaultDescSort;
|
|
134
|
+
|
|
135
|
+
if (currentSort.index === i) {
|
|
136
|
+
desc = !currentSort.desc;
|
|
137
|
+
}
|
|
138
|
+
sortByIndex(i, desc);
|
|
139
|
+
removeSortIndicators();
|
|
140
|
+
currentSort.index = i;
|
|
141
|
+
currentSort.desc = desc;
|
|
142
|
+
addSortIndicators();
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
for (i = 0; i < cols.length; i += 1) {
|
|
146
|
+
if (cols[i].sortable) {
|
|
147
|
+
// add the click event handler on the th so users
|
|
148
|
+
// dont have to click on those tiny arrows
|
|
149
|
+
el = getNthColumn(i).querySelector('.sorter').parentElement;
|
|
150
|
+
if (el.addEventListener) {
|
|
151
|
+
el.addEventListener('click', ithSorter(i));
|
|
152
|
+
} else {
|
|
153
|
+
el.attachEvent('onclick', ithSorter(i));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// adds sorting functionality to the UI
|
|
159
|
+
return function() {
|
|
160
|
+
if (!getTable()) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
cols = loadColumns();
|
|
164
|
+
loadData();
|
|
165
|
+
addSortIndicators();
|
|
166
|
+
enableUI();
|
|
167
|
+
};
|
|
168
|
+
})();
|
|
169
|
+
|
|
170
|
+
window.addEventListener('load', addSorting);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import ReactDOM from "react-dom";
|
|
3
|
+
|
|
4
|
+
import UseCsvButton from "../index";
|
|
5
|
+
|
|
6
|
+
ReactDOM.render(
|
|
7
|
+
<React.StrictMode>
|
|
8
|
+
<div
|
|
9
|
+
style={{
|
|
10
|
+
position: "absolute",
|
|
11
|
+
top: "50%",
|
|
12
|
+
left: "50%",
|
|
13
|
+
transform: "translateX(-50%) translateY(-50%)",
|
|
14
|
+
}}
|
|
15
|
+
>
|
|
16
|
+
<UseCsvButton importerKey="your-importer-key" user={{ userId: "12345" }} metadata={{ anotherId: "12345" }}>
|
|
17
|
+
Import Data
|
|
18
|
+
</UseCsvButton>
|
|
19
|
+
</div>
|
|
20
|
+
</React.StrictMode>,
|
|
21
|
+
document.getElementById("root"),
|
|
22
|
+
);
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import useCsvPlugin from "@usecsv/js";
|
|
2
|
+
import React, { FC, ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
type UserObject = {
|
|
5
|
+
readonly userId: string;
|
|
6
|
+
};
|
|
7
|
+
type UseCsvButtonTypes = {
|
|
8
|
+
readonly importerKey: string;
|
|
9
|
+
readonly user?: UserObject;
|
|
10
|
+
readonly metadata: Record<string, string | number> | undefined;
|
|
11
|
+
readonly render?: ((onClick: () => Promise<any>) => ReactNode) | undefined | null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const UseCsvButton: FC<UseCsvButtonTypes> = ({ children, importerKey, user, metadata, render }) => {
|
|
15
|
+
return (
|
|
16
|
+
<>
|
|
17
|
+
{render ? (
|
|
18
|
+
<>{render(() => useCsvPlugin({ importerKey, user, metadata }))}</>
|
|
19
|
+
) : (
|
|
20
|
+
<button
|
|
21
|
+
type="button"
|
|
22
|
+
id="usecsv-button"
|
|
23
|
+
style={{
|
|
24
|
+
backgroundColor: "#FFF",
|
|
25
|
+
color: "#000",
|
|
26
|
+
border: "2px solid #000",
|
|
27
|
+
borderRadius: "6px",
|
|
28
|
+
padding: "10px 15px",
|
|
29
|
+
textAlign: "center",
|
|
30
|
+
fontSize: "16px",
|
|
31
|
+
cursor: "pointer",
|
|
32
|
+
}}
|
|
33
|
+
onClick={() => useCsvPlugin({ importerKey, user, metadata })}
|
|
34
|
+
>
|
|
35
|
+
{children}
|
|
36
|
+
</button>
|
|
37
|
+
)}
|
|
38
|
+
</>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default UseCsvButton;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Module settings.
|
|
4
|
+
"allowSyntheticDefaultImports": true,
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"isolatedModules": true,
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
"resolveJsonModule": true,
|
|
9
|
+
// Strictness and quality settings.
|
|
10
|
+
"alwaysStrict": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"importsNotUsedAsValues": "error",
|
|
13
|
+
"noFallthroughCasesInSwitch": true,
|
|
14
|
+
"noImplicitOverride": true,
|
|
15
|
+
"noImplicitReturns": true,
|
|
16
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
17
|
+
"noUncheckedIndexedAccess": true,
|
|
18
|
+
"noUnusedLocals": true,
|
|
19
|
+
"noUnusedParameters": true,
|
|
20
|
+
"strict": true,
|
|
21
|
+
"pretty": true /* Stylize errors and messages using color and context. */,
|
|
22
|
+
// Type-checking settings.
|
|
23
|
+
"lib": [
|
|
24
|
+
"ES2020",
|
|
25
|
+
"DOM"
|
|
26
|
+
],
|
|
27
|
+
"skipDefaultLibCheck": true,
|
|
28
|
+
"skipLibCheck": true,
|
|
29
|
+
"jsx": "react"
|
|
30
|
+
},
|
|
31
|
+
"include": [
|
|
32
|
+
"./src/**/*.ts",
|
|
33
|
+
"src/index.tsx", "./src/**/*.tsx",
|
|
34
|
+
],
|
|
35
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// Transpilation settings.
|
|
5
|
+
"module": "ES2020",
|
|
6
|
+
"target": "ES5",
|
|
7
|
+
// Output settings.
|
|
8
|
+
"charset": "utf-8",
|
|
9
|
+
"newLine": "LF",
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
// Type declaration settings.
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationDir": "build/types/",
|
|
14
|
+
// "emitDeclarationOnly": true,
|
|
15
|
+
"declarationMap": true,
|
|
16
|
+
"jsx": "react"
|
|
17
|
+
},
|
|
18
|
+
"exclude": [
|
|
19
|
+
"src/lib/**/*.spec.ts",
|
|
20
|
+
"src/**/dev",
|
|
21
|
+
"./**/test"
|
|
22
|
+
]
|
|
23
|
+
}
|