@knowark/componarkjs 1.7.3 → 1.7.5
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/Makefile +6 -3
- package/jsconfig.json +23 -0
- package/lib/base/component/component.js +27 -26
- package/lib/base/component/component.test.js +76 -32
- package/lib/base/styles/styles.js +34 -5
- package/lib/base/utils/define.js +6 -7
- package/lib/base/utils/define.test.js +5 -5
- package/lib/base/utils/helpers.js +14 -10
- package/lib/base/utils/helpers.test.js +13 -13
- package/lib/base/utils/uuid.js +4 -4
- package/lib/components/audio/components/audio.js +6 -6
- package/lib/components/audio/components/audio.test.js +11 -10
- package/lib/components/audio/styles/ark.css.js +1 -1
- package/lib/components/camera/components/camera.test.js +6 -6
- package/lib/components/camera/styles/ark.css.js +1 -1
- package/lib/components/camera/styles/index.js +1 -1
- package/lib/components/capture/components/capture.js +2 -2
- package/lib/components/capture/components/capture.test.js +1 -1
- package/lib/components/droparea/components/droparea-preview.js +27 -26
- package/lib/components/droparea/components/droparea-preview.test.js +9 -9
- package/lib/components/droparea/components/droparea.js +19 -19
- package/lib/components/droparea/components/droparea.test.js +42 -42
- package/lib/components/droparea/styles/ark.css.js +1 -1
- package/lib/components/emit/components/emit.js +4 -4
- package/lib/components/emit/components/emit.test.js +5 -5
- package/lib/components/list/components/item.test.js +12 -14
- package/lib/components/list/components/list.js +25 -25
- package/lib/components/list/components/list.test.js +27 -29
- package/lib/components/paginator/components/paginator.js +2 -2
- package/lib/components/paginator/components/paginator.test.js +15 -18
- package/lib/components/paginator/styles/ark.css.js +1 -1
- package/lib/components/spinner/components/spinner.js +17 -17
- package/lib/components/spinner/styles/index.js +1 -1
- package/lib/components/splitview/components/splitview.detail.js +3 -3
- package/lib/components/splitview/components/splitview.detail.test.js +23 -23
- package/lib/components/splitview/components/splitview.js +3 -3
- package/lib/components/splitview/components/splitview.master.js +3 -3
- package/lib/components/splitview/components/splitview.master.test.js +2 -2
- package/lib/components/splitview/components/splitview.test.js +5 -7
- package/lib/components/translate/components/translate.js +17 -19
- package/lib/components/translate/components/translate.test.js +13 -14
- package/package.json +1 -1
- package/showcase/assets/knowark.svg +1 -0
- package/showcase/{design/screens/base/audio/audioDemo.js → components/demos/audio.js} +6 -10
- package/showcase/{design/screens/base/camera/cameraDemo.js → components/demos/camera.js} +6 -7
- package/showcase/{design/screens/base/droparea/dropareaDemo.js → components/demos/droparea.js} +7 -7
- package/showcase/{design/screens/base/list/listDemo.js → components/demos/list.js} +2 -3
- package/showcase/{design/screens/base/paginator/paginatorDemo.js → components/demos/paginator.js} +9 -9
- package/showcase/{design/screens/base/splitview/splitViewDemo.js → components/demos/splitview.js} +42 -9
- package/showcase/{design/screens/base/translate/translateDemo.js → components/demos/translate.js} +4 -5
- package/showcase/components/index.html +81 -0
- package/showcase/index.html +40 -82
- package/showcase/index.js +0 -1
- package/webpack.config.cjs +50 -50
- package/showcase/design/core/factories/development/development.factory.js +0 -5
- package/showcase/design/core/factories/development/index.js +0 -1
- package/showcase/design/core/factories/index.js +0 -11
- package/showcase/design/core/factories/standard.factory.js +0 -19
- package/showcase/design/index.html +0 -22
- package/showcase/design/index.js +0 -7
- package/showcase/design/screens/base/audio/index.js +0 -25
- package/showcase/design/screens/base/camera/index.js +0 -25
- package/showcase/design/screens/base/droparea/index.js +0 -25
- package/showcase/design/screens/base/index.js +0 -42
- package/showcase/design/screens/base/list/index.js +0 -25
- package/showcase/design/screens/base/paginator/index.js +0 -25
- package/showcase/design/screens/base/root.component.js +0 -294
- package/showcase/design/screens/base/root.routes.js +0 -28
- package/showcase/design/screens/base/spinner/index.js +0 -25
- package/showcase/design/screens/base/spinner/spinnerDemo.js +0 -55
- package/showcase/design/screens/base/splitview/detailDemo.js +0 -40
- package/showcase/design/screens/base/splitview/index.js +0 -25
- package/showcase/design/screens/base/translate/index.js +0 -20
- package/showcase/design/screens/main.js +0 -12
- package/showcase/design/screens/screens.routes.js +0 -23
- package/tsconfig.json +0 -23
- /package/showcase/{design/.htaccess → .htaccess} +0 -0
|
@@ -17,8 +17,8 @@ describe('Helpers', () => {
|
|
|
17
17
|
it('does not allow invalid attribute', () => {
|
|
18
18
|
const element = document.createElement('div')
|
|
19
19
|
element.innerHTML = /* html */`
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
<button listen ark-on-click="myMethod"></button>
|
|
21
|
+
`
|
|
22
22
|
|
|
23
23
|
listen(element)
|
|
24
24
|
|
|
@@ -41,8 +41,8 @@ describe('Helpers', () => {
|
|
|
41
41
|
it('It does not allow to execute undeclared methods.', () => {
|
|
42
42
|
const element = document.createElement('div')
|
|
43
43
|
element.innerHTML = /* html */`
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
<button listen on-click="myMethod"></button>
|
|
45
|
+
`
|
|
46
46
|
|
|
47
47
|
listen(element)
|
|
48
48
|
|
|
@@ -52,10 +52,10 @@ describe('Helpers', () => {
|
|
|
52
52
|
|
|
53
53
|
it('can listen events', () => {
|
|
54
54
|
const element = document.createElement('div')
|
|
55
|
-
element
|
|
55
|
+
element.binding = 'listen'
|
|
56
56
|
element.innerHTML = /* html */`
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
<button listen on-click="myMethod"></button>
|
|
58
|
+
`
|
|
59
59
|
// @ts-ignore
|
|
60
60
|
element.myMethod = function () {
|
|
61
61
|
element.setAttribute('clicked-element', '')
|
|
@@ -69,10 +69,10 @@ describe('Helpers', () => {
|
|
|
69
69
|
|
|
70
70
|
it('ignores missing methods when listening', () => {
|
|
71
71
|
const element = document.createElement('div')
|
|
72
|
-
element
|
|
72
|
+
element.binding = 'listen'
|
|
73
73
|
element.innerHTML = /* html */`
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
<button listen on-click="missing"></button>
|
|
75
|
+
`
|
|
76
76
|
// @ts-ignore
|
|
77
77
|
element.myMethod = function () {
|
|
78
78
|
element.setAttribute('clicked-element', '')
|
|
@@ -121,7 +121,7 @@ describe('Helpers', () => {
|
|
|
121
121
|
})
|
|
122
122
|
|
|
123
123
|
it('gets an object properties by a given path', () => {
|
|
124
|
-
const object = {state: {data: {value: 25}}, data: 13}
|
|
124
|
+
const object = { state: { data: { value: 25 } }, data: 13 }
|
|
125
125
|
|
|
126
126
|
let value = get(object, 'data')
|
|
127
127
|
|
|
@@ -144,10 +144,10 @@ describe('Helpers', () => {
|
|
|
144
144
|
const classes = {
|
|
145
145
|
[`background-${background}`]: background,
|
|
146
146
|
[`color-${color}`]: color,
|
|
147
|
-
[`shadow-${shadow}`]: shadow
|
|
147
|
+
[`shadow-${shadow}`]: shadow
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
const result = keys(classes)
|
|
151
151
|
|
|
152
152
|
expect(result).toEqual('background-primary shadow-small')
|
|
153
153
|
})
|
package/lib/base/utils/uuid.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
export function uuid () {
|
|
3
3
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
|
|
4
4
|
/[xy]/g, function (c) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const r = (Math.random() * 16) | 0
|
|
6
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8
|
|
7
|
+
return v.toString(16)
|
|
8
|
+
})
|
|
9
9
|
}
|
|
@@ -13,7 +13,7 @@ export class Audio extends Component {
|
|
|
13
13
|
return super.init()
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
reflectedProperties() {
|
|
16
|
+
reflectedProperties () {
|
|
17
17
|
return ['status']
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -49,13 +49,13 @@ export class Audio extends Component {
|
|
|
49
49
|
event.stopPropagation()
|
|
50
50
|
this.status = 'recording'
|
|
51
51
|
this.render()
|
|
52
|
-
const options = {audio: true}
|
|
52
|
+
const options = { audio: true }
|
|
53
53
|
const navigator = this.global.navigator
|
|
54
54
|
const stream = await navigator.mediaDevices.getUserMedia(options)
|
|
55
55
|
|
|
56
56
|
this.recorder = new this.global.MediaRecorder(stream)
|
|
57
57
|
this.recorder.addEventListener('dataavailable', this._onData.bind(this))
|
|
58
|
-
this.timerId = this._time()
|
|
58
|
+
this.timerId = this._time()
|
|
59
59
|
this.recorder.start()
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -79,7 +79,7 @@ export class Audio extends Component {
|
|
|
79
79
|
|
|
80
80
|
_time () {
|
|
81
81
|
let count = 0
|
|
82
|
-
return
|
|
82
|
+
return setInterval(() => {
|
|
83
83
|
count += 1
|
|
84
84
|
const seconds = count % 60
|
|
85
85
|
const minutes = Math.trunc(count / 60)
|
|
@@ -92,9 +92,9 @@ export class Audio extends Component {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/** @param {any} event */
|
|
95
|
-
_onData(event) {
|
|
95
|
+
_onData (event) {
|
|
96
96
|
const audio = this.select('.ark-audio__audio')
|
|
97
|
-
audio
|
|
97
|
+
audio.src = this.global.URL.createObjectURL(event.data)
|
|
98
98
|
const reader = new this.global.FileReader()
|
|
99
99
|
reader.readAsDataURL(event.data)
|
|
100
100
|
reader.onloadend = () => { this.dataURL = reader.result }
|
|
@@ -14,16 +14,15 @@ const mockGlobal = {
|
|
|
14
14
|
this.start = () => {}
|
|
15
15
|
this.addEventListener = (type, callback) => {}
|
|
16
16
|
this.stop = () => {}
|
|
17
|
-
this.stream = {getTracks: () => [{stop: () => null}]}
|
|
17
|
+
this.stream = { getTracks: () => [{ stop: () => null }] }
|
|
18
18
|
},
|
|
19
19
|
FileReader: function () {
|
|
20
20
|
const self = this
|
|
21
21
|
this.readAsDataURL = (data) => setTimeout(
|
|
22
|
-
() => self
|
|
22
|
+
() => self.onloadend(), 1000)
|
|
23
23
|
this.result = 'base64::data::result'
|
|
24
|
-
|
|
25
24
|
},
|
|
26
|
-
URL: {createObjectURL: (data) => 'mock://data/url'}
|
|
25
|
+
URL: { createObjectURL: (data) => 'mock://data/url' }
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
describe('Audio', () => {
|
|
@@ -52,7 +51,7 @@ describe('Audio', () => {
|
|
|
52
51
|
<ark-audio></ark-audio>
|
|
53
52
|
`
|
|
54
53
|
const audio = container.querySelector('ark-audio')
|
|
55
|
-
audio.init({global: mockGlobal})
|
|
54
|
+
audio.init({ global: mockGlobal })
|
|
56
55
|
|
|
57
56
|
expect(audio.status).toEqual('idle')
|
|
58
57
|
await audio.start(new Event('click'))
|
|
@@ -65,7 +64,7 @@ describe('Audio', () => {
|
|
|
65
64
|
<ark-audio></ark-audio>
|
|
66
65
|
`
|
|
67
66
|
const audio = container.querySelector('ark-audio')
|
|
68
|
-
audio.init({global: mockGlobal})
|
|
67
|
+
audio.init({ global: mockGlobal })
|
|
69
68
|
|
|
70
69
|
expect(audio.status).toEqual('idle')
|
|
71
70
|
await audio.start(new Event('click'))
|
|
@@ -79,7 +78,7 @@ describe('Audio', () => {
|
|
|
79
78
|
<ark-audio></ark-audio>
|
|
80
79
|
`
|
|
81
80
|
const audio = container.querySelector('ark-audio')
|
|
82
|
-
audio.init({global: mockGlobal})
|
|
81
|
+
audio.init({ global: mockGlobal })
|
|
83
82
|
|
|
84
83
|
expect(audio.status).toEqual('idle')
|
|
85
84
|
await audio.start(new Event('click'))
|
|
@@ -96,7 +95,7 @@ describe('Audio', () => {
|
|
|
96
95
|
<ark-audio></ark-audio>
|
|
97
96
|
`
|
|
98
97
|
const audio = container.querySelector('ark-audio')
|
|
99
|
-
audio.init({global: mockGlobal})
|
|
98
|
+
audio.init({ global: mockGlobal })
|
|
100
99
|
|
|
101
100
|
await audio.start(new Event('click'))
|
|
102
101
|
jest.runOnlyPendingTimers()
|
|
@@ -112,12 +111,14 @@ describe('Audio', () => {
|
|
|
112
111
|
<ark-audio></ark-audio>
|
|
113
112
|
`
|
|
114
113
|
const audio = container.querySelector('ark-audio')
|
|
115
|
-
audio.init({global: mockGlobal})
|
|
114
|
+
audio.init({ global: mockGlobal })
|
|
116
115
|
|
|
117
116
|
await audio.start(new Event('click'))
|
|
118
117
|
audio.stop(new Event('click'))
|
|
119
118
|
|
|
120
|
-
audio._onData({
|
|
119
|
+
audio._onData({
|
|
120
|
+
data: new globalThis.Blob(['Hello'], { type: 'text/plain' })
|
|
121
|
+
})
|
|
121
122
|
jest.runOnlyPendingTimers()
|
|
122
123
|
|
|
123
124
|
expect(audio.dataURL).toEqual('base64::data::result')
|
|
@@ -4,8 +4,8 @@ const mockGlobal = () => ({
|
|
|
4
4
|
navigator: {
|
|
5
5
|
mediaDevices: {
|
|
6
6
|
__stops: 0,
|
|
7
|
-
async getUserMedia(_options) {
|
|
8
|
-
return { getTracks: () => [{stop: () => {this.__stops += 1}}] }
|
|
7
|
+
async getUserMedia (_options) {
|
|
8
|
+
return { getTracks: () => [{ stop: () => { this.__stops += 1 } }] }
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -55,7 +55,7 @@ describe('Camera', () => {
|
|
|
55
55
|
<ark-camera></ark-camera>
|
|
56
56
|
`
|
|
57
57
|
const camera = container.querySelector('ark-camera')
|
|
58
|
-
camera.init({global: mockGlobal()})
|
|
58
|
+
camera.init({ global: mockGlobal() })
|
|
59
59
|
|
|
60
60
|
await camera.start()
|
|
61
61
|
|
|
@@ -68,7 +68,7 @@ describe('Camera', () => {
|
|
|
68
68
|
`
|
|
69
69
|
const camera = container.querySelector('ark-camera')
|
|
70
70
|
const global = mockGlobal()
|
|
71
|
-
camera.init({global
|
|
71
|
+
camera.init({ global })
|
|
72
72
|
|
|
73
73
|
await camera.start()
|
|
74
74
|
|
|
@@ -83,7 +83,7 @@ describe('Camera', () => {
|
|
|
83
83
|
`
|
|
84
84
|
const camera = container.querySelector('ark-camera')
|
|
85
85
|
const global = mockGlobal()
|
|
86
|
-
camera.init({global
|
|
86
|
+
camera.init({ global })
|
|
87
87
|
|
|
88
88
|
await camera.setCameraOrientation('environment')
|
|
89
89
|
|
|
@@ -95,7 +95,7 @@ describe('Camera', () => {
|
|
|
95
95
|
<ark-camera></ark-camera>
|
|
96
96
|
`
|
|
97
97
|
const camera = container.querySelector('ark-camera')
|
|
98
|
-
camera.init({global: mockGlobal()})
|
|
98
|
+
camera.init({ global: mockGlobal() })
|
|
99
99
|
|
|
100
100
|
const data = camera.dataURL()
|
|
101
101
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import styles from './ark.css.js'
|
|
2
|
-
export default styles
|
|
2
|
+
export default styles
|
|
@@ -4,7 +4,7 @@ const tag = 'ark-capture'
|
|
|
4
4
|
export class Capture extends Component {
|
|
5
5
|
constructor () {
|
|
6
6
|
super()
|
|
7
|
-
const type = this
|
|
7
|
+
const type = this.receive || 'emit'
|
|
8
8
|
this.addEventListener(type, this.handle.bind(this))
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -24,7 +24,7 @@ export class Capture extends Component {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
render () {
|
|
27
|
-
const outputTemplate
|
|
27
|
+
const outputTemplate = this._pop(':scope > template')?.innerHTML
|
|
28
28
|
this.template = (
|
|
29
29
|
outputTemplate ? this._format(outputTemplate) : this.template)
|
|
30
30
|
|
|
@@ -4,18 +4,18 @@ import './droparea.js'
|
|
|
4
4
|
const tag = 'ark-droparea-preview'
|
|
5
5
|
|
|
6
6
|
export class DropareaPreview extends Component {
|
|
7
|
-
init(_context = {}) {
|
|
7
|
+
init (_context = {}) {
|
|
8
8
|
return super.init()
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
render() {
|
|
11
|
+
render () {
|
|
12
12
|
this.content = /* html */ `
|
|
13
13
|
<ul data-preview-list class="ark-droparea-preview__list drag-sort-enable"></ul>
|
|
14
14
|
`
|
|
15
15
|
return super.render()
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
previewFile(file) {
|
|
18
|
+
previewFile (file) {
|
|
19
19
|
const blobUrl = URL.createObjectURL(file)
|
|
20
20
|
const fileType = file.type.split('/')[0]
|
|
21
21
|
const previewZone = this.select('[data-preview-list]')
|
|
@@ -43,7 +43,7 @@ export class DropareaPreview extends Component {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
toggleVisibility() {
|
|
46
|
+
toggleVisibility () {
|
|
47
47
|
const previewZone = this.select('[data-preview-list]')
|
|
48
48
|
this.files.length !== 0
|
|
49
49
|
? (previewZone.style.display = 'grid')
|
|
@@ -52,31 +52,31 @@ export class DropareaPreview extends Component {
|
|
|
52
52
|
|
|
53
53
|
/* DragSort Functionality */
|
|
54
54
|
|
|
55
|
-
enableDragSort(listClass) {
|
|
55
|
+
enableDragSort (listClass) {
|
|
56
56
|
const sortableLists = this.getElementsByClassName(listClass)
|
|
57
57
|
Array.prototype.map.call(sortableLists, (list) => {
|
|
58
58
|
this.enableDragList(list)
|
|
59
59
|
})
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
enableDragList(list) {
|
|
62
|
+
enableDragList (list) {
|
|
63
63
|
Array.prototype.map.call(list.children, (item) => {
|
|
64
64
|
this.enableDragItem(item)
|
|
65
65
|
})
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
enableDragItem(item) {
|
|
68
|
+
enableDragItem (item) {
|
|
69
69
|
item.setAttribute('draggable', true)
|
|
70
70
|
item.addEventListener('drag', this.handleDrag.bind(this, item))
|
|
71
71
|
item.addEventListener('dragend', this.handleDrop, false)
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/* istanbul ignore next */
|
|
75
|
-
handleDrag(item, event) {
|
|
76
|
-
const selectedItem = item
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
handleDrag (item, event) {
|
|
76
|
+
const selectedItem = item
|
|
77
|
+
const list = selectedItem.parentNode
|
|
78
|
+
const x = event.clientX
|
|
79
|
+
const y = event.clientY
|
|
80
80
|
|
|
81
81
|
selectedItem.classList.add('drag-sort-active')
|
|
82
82
|
let swapItem =
|
|
@@ -85,25 +85,26 @@ export class DropareaPreview extends Component {
|
|
|
85
85
|
: document.elementFromPoint(x, y)
|
|
86
86
|
if (list === swapItem.parentNode) {
|
|
87
87
|
swapItem = (
|
|
88
|
-
swapItem !== selectedItem.nextSibling
|
|
89
|
-
|
|
88
|
+
swapItem !== selectedItem.nextSibling
|
|
89
|
+
? swapItem
|
|
90
|
+
: swapItem.nextSibling)
|
|
90
91
|
list.insertBefore(selectedItem, swapItem)
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
handleDrop(item) {
|
|
95
|
+
handleDrop (item) {
|
|
95
96
|
const droparea = item.target.closest('ark-droparea')
|
|
96
97
|
droparea.preview.createNewFileList()
|
|
97
98
|
item.target.classList.remove('drag-sort-active')
|
|
98
99
|
droparea.preview.dispatchAlterEvent()
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
+
/* ---------------------------------------------------- */
|
|
101
102
|
|
|
102
|
-
dispatchAlterEvent() {
|
|
103
|
+
dispatchAlterEvent () {
|
|
103
104
|
this.emit('alter', this.mediaList)
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
createNewFileList() {
|
|
107
|
+
createNewFileList () {
|
|
107
108
|
const nodeList = this.querySelectorAll('li')
|
|
108
109
|
const newList = []
|
|
109
110
|
nodeList.forEach((item, index) => {
|
|
@@ -113,13 +114,13 @@ export class DropareaPreview extends Component {
|
|
|
113
114
|
this.droparea.fileList = newList
|
|
114
115
|
}
|
|
115
116
|
|
|
116
|
-
fileExists(file) {
|
|
117
|
+
fileExists (file) {
|
|
117
118
|
const present = this.files.some((item) => item.name === file.name)
|
|
118
119
|
return present
|
|
119
120
|
}
|
|
120
121
|
|
|
121
|
-
removeFile(file, event) {
|
|
122
|
-
|
|
122
|
+
removeFile (file, event) {
|
|
123
|
+
const element = event.target
|
|
123
124
|
const fileIndex = this.droparea.fileList.indexOf(file)
|
|
124
125
|
this.droparea.fileList.splice(fileIndex, 1)
|
|
125
126
|
element.parentNode.remove()
|
|
@@ -130,28 +131,28 @@ export class DropareaPreview extends Component {
|
|
|
130
131
|
this.dispatchAlterEvent()
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
fileIndex(file) {
|
|
134
|
+
fileIndex (file) {
|
|
134
135
|
return this.droparea.fileList.indexOf(file)
|
|
135
136
|
}
|
|
136
137
|
|
|
137
|
-
get droparea() {
|
|
138
|
+
get droparea () {
|
|
138
139
|
return this.closest('.ark-droparea')
|
|
139
140
|
}
|
|
140
141
|
|
|
141
|
-
get mediaList() {
|
|
142
|
+
get mediaList () {
|
|
142
143
|
const mediaList = []
|
|
143
144
|
this.droparea.fileList.map((file) => {
|
|
144
145
|
mediaList.push({
|
|
145
146
|
name: file.name,
|
|
146
147
|
type: file.type,
|
|
147
148
|
size: file.size,
|
|
148
|
-
url: URL.createObjectURL(file)
|
|
149
|
+
url: URL.createObjectURL(file)
|
|
149
150
|
})
|
|
150
151
|
})
|
|
151
152
|
return mediaList
|
|
152
153
|
}
|
|
153
154
|
|
|
154
|
-
get files() {
|
|
155
|
+
get files () {
|
|
155
156
|
return this.droparea.fileList
|
|
156
157
|
}
|
|
157
158
|
}
|
|
@@ -4,7 +4,7 @@ import './droparea-preview.js'
|
|
|
4
4
|
describe('Droparea', () => {
|
|
5
5
|
const createBubbledEvent = (type, props = {}) => {
|
|
6
6
|
const event = new Event(type, {
|
|
7
|
-
bubbles: true
|
|
7
|
+
bubbles: true
|
|
8
8
|
})
|
|
9
9
|
Object.assign(event, props)
|
|
10
10
|
return event
|
|
@@ -43,17 +43,17 @@ describe('Droparea', () => {
|
|
|
43
43
|
const preview = droparea.querySelector('[data-preview-list]')
|
|
44
44
|
const dropZone = droparea.querySelector('.ark-droparea__form')
|
|
45
45
|
const myFile = new File(['image'], 'Doggy.png', {
|
|
46
|
-
type: 'image/png'
|
|
46
|
+
type: 'image/png'
|
|
47
47
|
})
|
|
48
48
|
const myFile2 = new File(['image'], 'Scooby.png', {
|
|
49
|
-
type: 'image/png'
|
|
49
|
+
type: 'image/png'
|
|
50
50
|
})
|
|
51
51
|
const dropEvent = createBubbledEvent('drop', {
|
|
52
52
|
clientX: 0,
|
|
53
53
|
clientY: 1,
|
|
54
54
|
dataTransfer: {
|
|
55
|
-
files: [myFile, myFile2]
|
|
56
|
-
}
|
|
55
|
+
files: [myFile, myFile2]
|
|
56
|
+
}
|
|
57
57
|
})
|
|
58
58
|
|
|
59
59
|
dropZone.dispatchEvent(dropEvent)
|
|
@@ -70,17 +70,17 @@ describe('Droparea', () => {
|
|
|
70
70
|
const preview = droparea.querySelector('[data-preview-list]')
|
|
71
71
|
const dropZone = droparea.querySelector('.ark-droparea__form')
|
|
72
72
|
const myFile = new File(['image'], 'Doggy.png', {
|
|
73
|
-
type: 'image/png'
|
|
73
|
+
type: 'image/png'
|
|
74
74
|
})
|
|
75
75
|
const myFile2 = new File(['image'], 'Scooby.png', {
|
|
76
|
-
type: 'image/png'
|
|
76
|
+
type: 'image/png'
|
|
77
77
|
})
|
|
78
78
|
const dropEvent = createBubbledEvent('drop', {
|
|
79
79
|
clientX: 0,
|
|
80
80
|
clientY: 1,
|
|
81
81
|
dataTransfer: {
|
|
82
|
-
files: [myFile, myFile2]
|
|
83
|
-
}
|
|
82
|
+
files: [myFile, myFile2]
|
|
83
|
+
}
|
|
84
84
|
})
|
|
85
85
|
|
|
86
86
|
dropZone.dispatchEvent(dropEvent)
|
|
@@ -5,7 +5,7 @@ import styles from '../styles/index.js'
|
|
|
5
5
|
const tag = 'ark-droparea'
|
|
6
6
|
|
|
7
7
|
export class Droparea extends Component {
|
|
8
|
-
init(context = {}) {
|
|
8
|
+
init (context = {}) {
|
|
9
9
|
this.fileList = []
|
|
10
10
|
this.contextFiles = context.contextFiles || this.contextFiles || []
|
|
11
11
|
this.accept = context.accept || this.accept
|
|
@@ -14,7 +14,7 @@ export class Droparea extends Component {
|
|
|
14
14
|
return super.init()
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
render() {
|
|
17
|
+
render () {
|
|
18
18
|
this.content = /* html */ `
|
|
19
19
|
<form class="${tag}__form">
|
|
20
20
|
<div class="${tag}__header">
|
|
@@ -34,11 +34,11 @@ export class Droparea extends Component {
|
|
|
34
34
|
return super.render()
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
reflectedProperties() {
|
|
37
|
+
reflectedProperties () {
|
|
38
38
|
return ['size', 'accept', 'maxSize', 'title']
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
async load() {
|
|
41
|
+
async load () {
|
|
42
42
|
this.dragDropEvents.forEach((eventName) => {
|
|
43
43
|
this.addEventListener(eventName, this.preventDefaults, false)
|
|
44
44
|
})
|
|
@@ -61,40 +61,40 @@ export class Droparea extends Component {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
openInput(event) {
|
|
64
|
+
openInput (event) {
|
|
65
65
|
event.stopPropagation()
|
|
66
66
|
const input = this.select('[data-input]')
|
|
67
67
|
input.click()
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
preventDefaults(event) {
|
|
70
|
+
preventDefaults (event) {
|
|
71
71
|
event.preventDefault()
|
|
72
72
|
event.stopPropagation()
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
highlight(event) {
|
|
75
|
+
highlight (event) {
|
|
76
76
|
this.dropZone.classList.add('highlight')
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
unhighlight(event) {
|
|
79
|
+
unhighlight (event) {
|
|
80
80
|
this.dropZone.classList.remove('highlight')
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
handleDrop(event) {
|
|
83
|
+
handleDrop (event) {
|
|
84
84
|
event.stopPropagation()
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
const data = event.dataTransfer
|
|
86
|
+
const files = data.files
|
|
87
87
|
this.handleFiles(files)
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
onChange(event) {
|
|
90
|
+
onChange (event) {
|
|
91
91
|
event.stopPropagation()
|
|
92
92
|
const input = event.target
|
|
93
93
|
const files = input.files
|
|
94
94
|
this.handleFiles(files)
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
handleFiles(files) {
|
|
97
|
+
handleFiles (files) {
|
|
98
98
|
if (this.single) {
|
|
99
99
|
files = [files[0]]
|
|
100
100
|
if (
|
|
@@ -111,7 +111,7 @@ export class Droparea extends Component {
|
|
|
111
111
|
files = [...files]
|
|
112
112
|
if (!files.includes(undefined) && this.validate(files)) {
|
|
113
113
|
files.forEach((file) => {
|
|
114
|
-
/*istanbul ignore else*/
|
|
114
|
+
/* istanbul ignore else */
|
|
115
115
|
if (!this.preview.fileExists(file) && this.maxSizeValidate(file)) {
|
|
116
116
|
this.fileList.push(file)
|
|
117
117
|
this.preview.previewFile(file)
|
|
@@ -122,7 +122,7 @@ export class Droparea extends Component {
|
|
|
122
122
|
this.preview.dispatchAlterEvent()
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
validate(fileList) {
|
|
125
|
+
validate (fileList) {
|
|
126
126
|
if (!this.accept || this.accept.length === 0) return true
|
|
127
127
|
const acceptList = this.accept.split(',').map(
|
|
128
128
|
(s) => s.trim().toLowerCase())
|
|
@@ -132,7 +132,7 @@ export class Droparea extends Component {
|
|
|
132
132
|
const hasText = acceptList.indexOf('text') >= 0
|
|
133
133
|
|
|
134
134
|
for (let i = 0, len = fileList.length; i < len; ++i) {
|
|
135
|
-
|
|
135
|
+
const ext = '' + fileList[i].name.split('.').pop().toLowerCase()
|
|
136
136
|
if (acceptList.indexOf(ext) >= 0) continue
|
|
137
137
|
if (hasAudio && fileList[i].type.split('/')[0] === 'audio') continue
|
|
138
138
|
if (hasVideo && fileList[i].type.split('/')[0] === 'video') continue
|
|
@@ -149,15 +149,15 @@ export class Droparea extends Component {
|
|
|
149
149
|
return true
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
get dropZone() {
|
|
152
|
+
get dropZone () {
|
|
153
153
|
return this.select('.ark-droparea__form')
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
get preview() {
|
|
156
|
+
get preview () {
|
|
157
157
|
return this.select('ark-droparea-preview')
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
get mediaList() {
|
|
160
|
+
get mediaList () {
|
|
161
161
|
return this.preview.mediaList
|
|
162
162
|
}
|
|
163
163
|
}
|