@instructure/ui-file-drop 11.6.0 → 11.6.1-snapshot-129
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/CHANGELOG.md +41 -296
- package/es/FileDrop/{index.js → v1/index.js} +3 -3
- package/es/FileDrop/v2/index.js +371 -0
- package/es/FileDrop/v2/props.js +26 -0
- package/es/FileDrop/v2/styles.js +111 -0
- package/es/FileDrop/v2/utils/accepts.js +51 -0
- package/es/FileDrop/v2/utils/getEventFiles.js +41 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -3
- package/lib/FileDrop/v1/index.js +379 -0
- package/lib/FileDrop/{index.js → v2/index.js} +9 -9
- package/lib/FileDrop/v2/props.js +31 -0
- package/lib/FileDrop/v2/styles.js +117 -0
- package/lib/FileDrop/v2/utils/accepts.js +58 -0
- package/lib/FileDrop/v2/utils/getEventFiles.js +47 -0
- package/lib/{index.js → exports/a.js} +2 -2
- package/lib/exports/b.js +12 -0
- package/package.json +42 -20
- package/src/FileDrop/{index.tsx → v1/index.tsx} +4 -4
- package/src/FileDrop/{props.ts → v1/props.ts} +1 -1
- package/src/FileDrop/{styles.ts → v1/styles.ts} +2 -6
- package/src/FileDrop/v2/README.md +177 -0
- package/src/FileDrop/v2/index.tsx +419 -0
- package/src/FileDrop/v2/props.ts +211 -0
- package/src/FileDrop/v2/styles.ts +140 -0
- package/src/FileDrop/v2/utils/accepts.ts +54 -0
- package/src/FileDrop/v2/utils/getEventFiles.ts +47 -0
- package/src/exports/a.ts +26 -0
- package/src/exports/b.ts +26 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/FileDrop/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/FileDrop/v1/index.d.ts.map +1 -0
- package/types/FileDrop/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/FileDrop/v1/props.d.ts.map +1 -0
- package/types/FileDrop/v1/styles.d.ts.map +1 -0
- package/types/FileDrop/v1/theme.d.ts.map +1 -0
- package/types/FileDrop/v1/utils/accepts.d.ts.map +1 -0
- package/types/FileDrop/v1/utils/getEventFiles.d.ts.map +1 -0
- package/types/FileDrop/v2/index.d.ts +89 -0
- package/types/FileDrop/v2/index.d.ts.map +1 -0
- package/types/FileDrop/v2/props.d.ts +134 -0
- package/types/FileDrop/v2/props.d.ts.map +1 -0
- package/types/FileDrop/v2/styles.d.ts +17 -0
- package/types/FileDrop/v2/styles.d.ts.map +1 -0
- package/types/FileDrop/v2/utils/accepts.d.ts +5 -0
- package/types/FileDrop/v2/utils/accepts.d.ts.map +1 -0
- package/types/FileDrop/v2/utils/getEventFiles.d.ts +5 -0
- package/types/FileDrop/v2/utils/getEventFiles.d.ts.map +1 -0
- package/types/exports/a.d.ts +3 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +3 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/FileDrop/index.d.ts.map +0 -1
- package/types/FileDrop/props.d.ts.map +0 -1
- package/types/FileDrop/styles.d.ts.map +0 -1
- package/types/FileDrop/theme.d.ts.map +0 -1
- package/types/FileDrop/utils/accepts.d.ts.map +0 -1
- package/types/FileDrop/utils/getEventFiles.d.ts.map +0 -1
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/es/FileDrop/{props.js → v1/props.js} +0 -0
- /package/es/FileDrop/{styles.js → v1/styles.js} +0 -0
- /package/es/FileDrop/{theme.js → v1/theme.js} +0 -0
- /package/es/FileDrop/{utils → v1/utils}/accepts.js +0 -0
- /package/es/FileDrop/{utils → v1/utils}/getEventFiles.js +0 -0
- /package/lib/FileDrop/{props.js → v1/props.js} +0 -0
- /package/lib/FileDrop/{styles.js → v1/styles.js} +0 -0
- /package/lib/FileDrop/{theme.js → v1/theme.js} +0 -0
- /package/lib/FileDrop/{utils → v1/utils}/accepts.js +0 -0
- /package/lib/FileDrop/{utils → v1/utils}/getEventFiles.js +0 -0
- /package/src/FileDrop/{README.md → v1/README.md} +0 -0
- /package/src/FileDrop/{theme.ts → v1/theme.ts} +0 -0
- /package/src/FileDrop/{utils → v1/utils}/accepts.ts +0 -0
- /package/src/FileDrop/{utils → v1/utils}/getEventFiles.ts +0 -0
- /package/types/FileDrop/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/FileDrop/{theme.d.ts → v1/theme.d.ts} +0 -0
- /package/types/FileDrop/{utils → v1/utils}/accepts.d.ts +0 -0
- /package/types/FileDrop/{utils → v1/utils}/getEventFiles.d.ts +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type { FileDropProps, FileDropStyleProps, FileDropStyle } from './props'
|
|
26
|
+
import type { NewComponentTypes, SharedTokens } from '@instructure/ui-themes'
|
|
27
|
+
|
|
28
|
+
type StyleParams = FileDropProps & FileDropStyleProps
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* ---
|
|
32
|
+
* private: true
|
|
33
|
+
* ---
|
|
34
|
+
* Generates the style object from the theme and provided additional information
|
|
35
|
+
* @param {Object} componentTheme The theme variable object.
|
|
36
|
+
* @param {Object} params the props and state of the component, the style is applied to
|
|
37
|
+
* @param {Object} sharedTokens Shared tokens from the theme
|
|
38
|
+
* @return {Object} The final style object, which will be used in the component
|
|
39
|
+
*/
|
|
40
|
+
const generateStyle = (
|
|
41
|
+
componentTheme: NewComponentTypes['FileDrop'],
|
|
42
|
+
params: StyleParams,
|
|
43
|
+
_sharedTokens: SharedTokens
|
|
44
|
+
): FileDropStyle => {
|
|
45
|
+
const {
|
|
46
|
+
height,
|
|
47
|
+
functionallyDisabled,
|
|
48
|
+
visuallyDisabled,
|
|
49
|
+
dragRejected,
|
|
50
|
+
dragAccepted
|
|
51
|
+
} = params
|
|
52
|
+
|
|
53
|
+
const dragAcceptedStyle = dragAccepted
|
|
54
|
+
? {
|
|
55
|
+
borderColor: componentTheme.acceptedColor
|
|
56
|
+
}
|
|
57
|
+
: {}
|
|
58
|
+
|
|
59
|
+
const dragRejectedStyle = dragRejected
|
|
60
|
+
? {
|
|
61
|
+
borderColor: componentTheme.rejectedColor
|
|
62
|
+
}
|
|
63
|
+
: {}
|
|
64
|
+
|
|
65
|
+
const functionallyDisabledStyle = functionallyDisabled
|
|
66
|
+
? {
|
|
67
|
+
cursor: 'not-allowed',
|
|
68
|
+
pointerEvents: 'none'
|
|
69
|
+
}
|
|
70
|
+
: {}
|
|
71
|
+
|
|
72
|
+
const visuallyDisabledStyle = visuallyDisabled
|
|
73
|
+
? {
|
|
74
|
+
opacity: 0.5
|
|
75
|
+
}
|
|
76
|
+
: {}
|
|
77
|
+
|
|
78
|
+
// Force the content to fill the space set with the 'height' React prop
|
|
79
|
+
const heightStyle = height
|
|
80
|
+
? {
|
|
81
|
+
height: '100%'
|
|
82
|
+
}
|
|
83
|
+
: {}
|
|
84
|
+
|
|
85
|
+
// border color precedence: normal hover < dragRejected OR dragAccepted
|
|
86
|
+
const hoverBorderColor =
|
|
87
|
+
!dragAccepted && !dragRejected
|
|
88
|
+
? { borderColor: componentTheme.hoverBorderColor }
|
|
89
|
+
: {}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
fileDropLabel: {
|
|
93
|
+
label: 'fileDrop__label',
|
|
94
|
+
display: 'block',
|
|
95
|
+
boxSizing: 'border-box',
|
|
96
|
+
position: 'relative',
|
|
97
|
+
...heightStyle,
|
|
98
|
+
...functionallyDisabledStyle,
|
|
99
|
+
...visuallyDisabledStyle
|
|
100
|
+
},
|
|
101
|
+
fileDropInput: {
|
|
102
|
+
label: 'fileDrop__input',
|
|
103
|
+
width: '0.0625rem',
|
|
104
|
+
height: '0.0625rem',
|
|
105
|
+
margin: '-0.0625rem',
|
|
106
|
+
padding: 0,
|
|
107
|
+
position: 'absolute',
|
|
108
|
+
overflow: 'hidden',
|
|
109
|
+
clip: 'rect(0 0 0 0)',
|
|
110
|
+
border: 0
|
|
111
|
+
},
|
|
112
|
+
fileDropLabelContent: {
|
|
113
|
+
label: 'fileDrop__labelContent',
|
|
114
|
+
display: 'block',
|
|
115
|
+
backgroundColor: componentTheme.backgroundColor,
|
|
116
|
+
boxSizing: 'border-box',
|
|
117
|
+
zIndex: 1,
|
|
118
|
+
textAlign: 'center',
|
|
119
|
+
borderRadius: componentTheme.borderRadius,
|
|
120
|
+
border: `${componentTheme.borderWidth} ${componentTheme.borderStyle} ${componentTheme.borderColor}`,
|
|
121
|
+
cursor: 'pointer',
|
|
122
|
+
'&:hover': {
|
|
123
|
+
...hoverBorderColor
|
|
124
|
+
},
|
|
125
|
+
...heightStyle,
|
|
126
|
+
...dragAcceptedStyle,
|
|
127
|
+
...dragRejectedStyle
|
|
128
|
+
},
|
|
129
|
+
fileDropLayout: {
|
|
130
|
+
label: 'fileDrop__layout',
|
|
131
|
+
display: 'block',
|
|
132
|
+
overflow: 'hidden',
|
|
133
|
+
borderRadius: componentTheme.borderRadius,
|
|
134
|
+
...heightStyle
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export default generateStyle
|
|
140
|
+
export type { StyleParams }
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
function accepts(file: File, acceptProp: string | string[]) {
|
|
26
|
+
if (file && acceptProp && file.type !== 'application/x-moz-file') {
|
|
27
|
+
const acceptList = getAcceptList(acceptProp)
|
|
28
|
+
const mimeType = file.type || ''
|
|
29
|
+
const baseMimeType = mimeType.replace(/\/.*$/, '')
|
|
30
|
+
|
|
31
|
+
return acceptList.some((type) => {
|
|
32
|
+
if (type.charAt(0) === '.') {
|
|
33
|
+
// type is an extension like .pdf
|
|
34
|
+
if (!file.name) {
|
|
35
|
+
return mimeType.endsWith(type.slice(1))
|
|
36
|
+
}
|
|
37
|
+
return file.name.toLowerCase().endsWith(type.toLowerCase())
|
|
38
|
+
} else if (/\/\*$/.test(type)) {
|
|
39
|
+
// type is something like a image/* mime type
|
|
40
|
+
return baseMimeType === type.replace(/\/.*$/, '')
|
|
41
|
+
}
|
|
42
|
+
return mimeType === type
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
return true
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getAcceptList(accept: string | string[]) {
|
|
49
|
+
const list = Array.isArray(accept) ? accept : accept.split(',')
|
|
50
|
+
return list.map((a) => a.trim().replace(/^\w+$/, '.$&'))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export default accepts
|
|
54
|
+
export { accepts, getAcceptList }
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React from 'react'
|
|
26
|
+
|
|
27
|
+
function getEventFiles(
|
|
28
|
+
event: React.DragEvent | React.ChangeEvent,
|
|
29
|
+
inputEl?: HTMLInputElement
|
|
30
|
+
): ArrayLike<DataTransferItem | File | never> {
|
|
31
|
+
if ('dataTransfer' in event) {
|
|
32
|
+
const dt = event.dataTransfer
|
|
33
|
+
if (dt) {
|
|
34
|
+
if (dt.files && dt.files.length) {
|
|
35
|
+
return dt.files
|
|
36
|
+
} else if (dt.items && dt.items.length) {
|
|
37
|
+
return dt.items
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} else if (inputEl && inputEl.files) {
|
|
41
|
+
return inputEl.files
|
|
42
|
+
}
|
|
43
|
+
return []
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default getEventFiles
|
|
47
|
+
export { getEventFiles }
|
package/src/exports/a.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export { FileDrop } from '../FileDrop/v1'
|
|
26
|
+
export type { FileDropProps } from '../FileDrop/v1/props'
|
package/src/exports/b.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export { FileDrop } from '../FileDrop/v2'
|
|
26
|
+
export type { FileDropProps } from '../FileDrop/v2/props'
|