@knowark/componarkjs 1.13.4 → 1.14.1
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/README.md +57 -45
- package/lib/base/component/component.js +142 -20
- package/lib/base/component/component.test.js +753 -374
- package/lib/base/component/index.js +3 -0
- package/lib/base/styles/index.js +4 -1
- package/lib/base/utils/define.js +30 -7
- package/lib/base/utils/define.test.js +129 -42
- package/lib/base/utils/format.js +12 -6
- package/lib/base/utils/format.test.js +16 -16
- package/lib/base/utils/helpers.js +42 -9
- package/lib/base/utils/helpers.test.js +134 -115
- package/lib/base/utils/index.js +1 -0
- package/lib/base/utils/slots.js +3 -2
- package/lib/base/utils/slots.test.js +38 -38
- package/lib/base/utils/uuid.js +1 -1
- package/lib/base/utils/uuid.test.js +13 -13
- package/lib/components/audio/components/audio.js +36 -3
- package/lib/components/audio/components/audio.test.js +120 -90
- package/lib/components/audio/index.js +1 -0
- package/lib/components/audio/styles/index.js +5 -1
- package/lib/components/camera/components/camera.js +15 -0
- package/lib/components/camera/components/camera.test.js +96 -91
- package/lib/components/camera/index.js +1 -0
- package/lib/components/camera/styles/index.js +5 -1
- package/lib/components/capture/components/capture.js +48 -4
- package/lib/components/capture/components/capture.test.js +165 -97
- package/lib/components/capture/index.js +1 -0
- package/lib/components/droparea/components/droparea-preview.js +114 -19
- package/lib/components/droparea/components/droparea-preview.test.js +344 -80
- package/lib/components/droparea/components/droparea.js +82 -6
- package/lib/components/droparea/components/droparea.test.js +309 -299
- package/lib/components/droparea/index.js +1 -0
- package/lib/components/droparea/styles/index.js +5 -1
- package/lib/components/emit/components/emit.js +34 -4
- package/lib/components/emit/components/emit.test.js +192 -134
- package/lib/components/emit/index.js +1 -0
- package/lib/components/index.js +2 -1
- package/lib/components/list/components/item.js +6 -0
- package/lib/components/list/components/item.test.js +69 -68
- package/lib/components/list/components/list.js +51 -7
- package/lib/components/list/components/list.test.js +358 -227
- package/lib/components/list/index.js +1 -0
- package/lib/components/paginator/components/paginator.js +34 -8
- package/lib/components/paginator/components/paginator.test.js +146 -143
- package/lib/components/paginator/index.js +1 -0
- package/lib/components/paginator/styles/index.js +5 -1
- package/lib/components/spinner/components/spinner.js +10 -0
- package/lib/components/spinner/components/spinner.test.js +36 -41
- package/lib/components/spinner/index.js +1 -0
- package/lib/components/spinner/styles/index.js +5 -1
- package/lib/components/splitview/components/splitview.detail.js +10 -1
- package/lib/components/splitview/components/splitview.detail.test.js +75 -73
- package/lib/components/splitview/components/splitview.js +54 -11
- package/lib/components/splitview/components/splitview.master.js +37 -2
- package/lib/components/splitview/components/splitview.master.test.js +52 -52
- package/lib/components/splitview/components/splitview.test.js +135 -31
- package/lib/components/splitview/index.js +1 -0
- package/lib/components/translate/components/translate.js +65 -14
- package/lib/components/translate/components/translate.test.js +658 -131
- package/lib/components/translate/index.js +1 -0
- package/lib/index.js +3 -0
- package/package.json +4 -27
- package/scripts/node-test-setup.js +94 -0
- package/tsconfig.json +1 -1
- package/types/base/component/component.d.ts +43 -8
- package/types/base/component/component.d.ts.map +1 -1
- package/types/base/component/index.d.ts +4 -6
- package/types/base/component/index.d.ts.map +1 -1
- package/types/base/styles/index.d.ts +3 -2
- package/types/base/styles/index.d.ts.map +1 -1
- package/types/base/utils/define.d.ts +3 -2
- package/types/base/utils/define.d.ts.map +1 -1
- package/types/base/utils/format.d.ts +12 -6
- package/types/base/utils/format.d.ts.map +1 -1
- package/types/base/utils/helpers.d.ts +27 -7
- package/types/base/utils/helpers.d.ts.map +1 -1
- package/types/base/utils/slots.d.ts +8 -10
- package/types/base/utils/slots.d.ts.map +1 -1
- package/types/base/utils/uuid.d.ts +1 -1
- package/types/base/utils/uuid.d.ts.map +1 -1
- package/types/components/audio/components/audio.d.ts +23 -9
- package/types/components/audio/components/audio.d.ts.map +1 -1
- package/types/components/audio/styles/index.d.ts +3 -2
- package/types/components/audio/styles/index.d.ts.map +1 -1
- package/types/components/camera/components/camera.d.ts +11 -3
- package/types/components/camera/components/camera.d.ts.map +1 -1
- package/types/components/camera/styles/index.d.ts +3 -2
- package/types/components/camera/styles/index.d.ts.map +1 -1
- package/types/components/capture/components/capture.d.ts +23 -3
- package/types/components/capture/components/capture.d.ts.map +1 -1
- package/types/components/droparea/components/droparea-preview.d.ts +64 -11
- package/types/components/droparea/components/droparea-preview.d.ts.map +1 -1
- package/types/components/droparea/components/droparea.d.ts +58 -13
- package/types/components/droparea/components/droparea.d.ts.map +1 -1
- package/types/components/droparea/styles/index.d.ts +3 -2
- package/types/components/droparea/styles/index.d.ts.map +1 -1
- package/types/components/emit/components/emit.d.ts +15 -3
- package/types/components/emit/components/emit.d.ts.map +1 -1
- package/types/components/list/components/item.d.ts +8 -1
- package/types/components/list/components/item.d.ts.map +1 -1
- package/types/components/list/components/list.d.ts +23 -5
- package/types/components/list/components/list.d.ts.map +1 -1
- package/types/components/paginator/components/paginator.d.ts +32 -8
- package/types/components/paginator/components/paginator.d.ts.map +1 -1
- package/types/components/paginator/styles/index.d.ts +3 -2
- package/types/components/paginator/styles/index.d.ts.map +1 -1
- package/types/components/spinner/components/spinner.d.ts +14 -3
- package/types/components/spinner/components/spinner.d.ts.map +1 -1
- package/types/components/spinner/styles/index.d.ts +3 -2
- package/types/components/spinner/styles/index.d.ts.map +1 -1
- package/types/components/splitview/components/splitview.d.ts +22 -4
- package/types/components/splitview/components/splitview.d.ts.map +1 -1
- package/types/components/splitview/components/splitview.detail.d.ts +12 -2
- package/types/components/splitview/components/splitview.detail.d.ts.map +1 -1
- package/types/components/splitview/components/splitview.master.d.ts +12 -1
- package/types/components/splitview/components/splitview.master.d.ts.map +1 -1
- package/types/components/translate/components/translate.d.ts +44 -10
- package/types/components/translate/components/translate.d.ts.map +1 -1
|
@@ -1,112 +1,180 @@
|
|
|
1
|
+
import { it } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
1
3
|
import './capture.js'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
let container = null
|
|
5
|
+
let container = null
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const setup = () => {
|
|
8
|
+
document.body.innerHTML = ''
|
|
9
|
+
container = document.createElement('div')
|
|
10
|
+
document.body.appendChild(container)
|
|
11
|
+
}
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
it('can be instantiated', () => {
|
|
14
|
+
setup()
|
|
15
|
+
container.innerHTML = `
|
|
16
|
+
<ark-capture></ark-capture>
|
|
17
|
+
`
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
`
|
|
19
|
+
const capture = container.querySelector('ark-capture')
|
|
20
|
+
assert.deepStrictEqual(capture, capture.init())
|
|
21
|
+
})
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
it('renders the given data detail', () => {
|
|
24
|
+
setup()
|
|
25
|
+
container.innerHTML = `
|
|
26
|
+
<ark-capture>
|
|
27
|
+
<data>
|
|
28
|
+
{
|
|
29
|
+
"name": "John Doe",
|
|
30
|
+
"job": "Programmer"
|
|
31
|
+
}
|
|
32
|
+
</data>
|
|
33
|
+
<output></output>
|
|
34
|
+
</ark-capture>
|
|
35
|
+
`
|
|
36
|
+
|
|
37
|
+
const capture = container.querySelector('ark-capture')
|
|
38
|
+
capture.init().render()
|
|
39
|
+
const output = capture.querySelector('output')
|
|
40
|
+
|
|
41
|
+
assert.deepStrictEqual(capture.children.length, 1)
|
|
42
|
+
assert.ok(output.innerHTML.includes('John Doe'))
|
|
43
|
+
assert.ok(output.innerHTML.includes('Programmer'))
|
|
44
|
+
})
|
|
24
45
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
it('renders json data on the given template on the given output', () => {
|
|
47
|
+
setup()
|
|
48
|
+
container.innerHTML = `
|
|
49
|
+
<ark-capture>
|
|
50
|
+
<data>
|
|
51
|
+
{
|
|
52
|
+
"name": "John Doe",
|
|
53
|
+
"job": "Programmer"
|
|
54
|
+
}
|
|
55
|
+
</data>
|
|
56
|
+
<template>
|
|
57
|
+
<div id="output">
|
|
58
|
+
<strong>\${this.name}</strong>
|
|
59
|
+
<strong>\${this.job}</strong>
|
|
60
|
+
</div>
|
|
61
|
+
</template>
|
|
62
|
+
<output></output>
|
|
63
|
+
</ark-capture>
|
|
64
|
+
`
|
|
65
|
+
|
|
66
|
+
const capture = container.querySelector('ark-capture')
|
|
67
|
+
capture.init().render()
|
|
68
|
+
const output = capture.querySelector('output')
|
|
69
|
+
|
|
70
|
+
assert.deepStrictEqual(capture.children.length, 1)
|
|
71
|
+
assert.ok(output.children[0].innerHTML.includes('John Doe'))
|
|
72
|
+
assert.ok(output.children[0].innerHTML.includes('Programmer'))
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('captures specific custom events and renders its details', () => {
|
|
76
|
+
setup()
|
|
77
|
+
container.innerHTML = `
|
|
78
|
+
<ark-capture receive="custom">
|
|
79
|
+
<template>
|
|
80
|
+
<div id="output">
|
|
81
|
+
<strong>\${this.name}</strong>
|
|
82
|
+
<strong>\${this.job}</strong>
|
|
83
|
+
</div>
|
|
84
|
+
</template>
|
|
85
|
+
<output></output>
|
|
86
|
+
<p>Adjoint Element</p>
|
|
87
|
+
</ark-capture>
|
|
88
|
+
`
|
|
89
|
+
|
|
90
|
+
const capture = container.querySelector('ark-capture')
|
|
91
|
+
capture.init().render()
|
|
92
|
+
capture.addEventListener('custom', capture.handle.bind(capture))
|
|
93
|
+
const output = capture.querySelector('output')
|
|
94
|
+
|
|
95
|
+
capture.dispatchEvent(new CustomEvent('custom', {
|
|
96
|
+
bubbles: true,
|
|
97
|
+
detail: {
|
|
98
|
+
name: 'Richard Roe', job: 'Analyst'
|
|
99
|
+
}
|
|
100
|
+
}))
|
|
101
|
+
|
|
102
|
+
assert.deepStrictEqual(capture.children.length, 2)
|
|
103
|
+
assert.ok(output.children[0].innerHTML.includes('Richard Roe'))
|
|
104
|
+
assert.ok(output.children[0].innerHTML.includes('Analyst'))
|
|
105
|
+
|
|
106
|
+
capture.dispatchEvent(new CustomEvent('custom', {
|
|
107
|
+
bubbles: true,
|
|
108
|
+
detail: {
|
|
109
|
+
name: 'Megan More', job: 'Manager'
|
|
110
|
+
}
|
|
111
|
+
}))
|
|
112
|
+
|
|
113
|
+
assert.deepStrictEqual(capture.children.length, 2)
|
|
114
|
+
assert.ok(output.children[0].innerHTML.includes('Megan More'))
|
|
115
|
+
assert.ok(output.children[0].innerHTML.includes('Manager'))
|
|
116
|
+
})
|
|
45
117
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
</div>
|
|
60
|
-
</template>
|
|
61
|
-
<output></output>
|
|
62
|
-
</ark-capture>
|
|
63
|
-
`
|
|
64
|
-
|
|
65
|
-
const capture = container.querySelector('ark-capture')
|
|
66
|
-
const output = capture.querySelector('output')
|
|
67
|
-
|
|
68
|
-
expect(capture.children.length).toEqual(1)
|
|
69
|
-
expect(output.children[0].innerHTML).toContain('John Doe')
|
|
70
|
-
expect(output.children[0].innerHTML).toContain('Programmer')
|
|
118
|
+
it('emits error when data JSON is invalid', () => {
|
|
119
|
+
setup()
|
|
120
|
+
const holder = document.createElement('div')
|
|
121
|
+
holder.innerHTML = `
|
|
122
|
+
<ark-capture>
|
|
123
|
+
<data>{ invalid json }</data>
|
|
124
|
+
<output></output>
|
|
125
|
+
</ark-capture>
|
|
126
|
+
`
|
|
127
|
+
const capture = holder.querySelector('ark-capture')
|
|
128
|
+
let errorEvent = null
|
|
129
|
+
capture.addEventListener('error', (event) => {
|
|
130
|
+
errorEvent = event
|
|
71
131
|
})
|
|
72
132
|
|
|
73
|
-
|
|
74
|
-
container.innerHTML = `
|
|
75
|
-
<ark-capture receive="custom">
|
|
76
|
-
<template>
|
|
77
|
-
<div id="output">
|
|
78
|
-
<strong>\${this.name}</strong>
|
|
79
|
-
<strong>\${this.job}</strong>
|
|
80
|
-
</div>
|
|
81
|
-
</template>
|
|
82
|
-
<output></output>
|
|
83
|
-
<p>Adjoint Element</p>
|
|
84
|
-
</ark-capture>
|
|
85
|
-
`
|
|
86
|
-
|
|
87
|
-
const capture = container.querySelector('ark-capture')
|
|
88
|
-
const output = capture.querySelector('output')
|
|
89
|
-
|
|
90
|
-
capture.dispatchEvent(new CustomEvent('custom', {
|
|
91
|
-
bubbles: true,
|
|
92
|
-
detail: {
|
|
93
|
-
name: 'Richard Roe', job: 'Analyst'
|
|
94
|
-
}
|
|
95
|
-
}))
|
|
133
|
+
capture.init().render()
|
|
96
134
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
expect(output.children[0].innerHTML).toContain('Analyst')
|
|
135
|
+
assert.ok(errorEvent)
|
|
136
|
+
})
|
|
100
137
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
138
|
+
it('emits error when template cannot be compiled', () => {
|
|
139
|
+
setup()
|
|
140
|
+
const holder = document.createElement('div')
|
|
141
|
+
holder.innerHTML = `
|
|
142
|
+
<ark-capture>
|
|
143
|
+
<data>{"name":"John"}</data>
|
|
144
|
+
<template>\${this.name</template>
|
|
145
|
+
<output></output>
|
|
146
|
+
</ark-capture>
|
|
147
|
+
`
|
|
148
|
+
const capture = holder.querySelector('ark-capture')
|
|
149
|
+
let errorEvent = null
|
|
150
|
+
capture.addEventListener('error', (event) => {
|
|
151
|
+
errorEvent = event
|
|
152
|
+
})
|
|
107
153
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
154
|
+
capture.init().render()
|
|
155
|
+
|
|
156
|
+
assert.ok(errorEvent)
|
|
157
|
+
assert.deepStrictEqual(capture.querySelector('output').innerHTML, '')
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it('emits error when template evaluation fails at runtime', () => {
|
|
161
|
+
setup()
|
|
162
|
+
const holder = document.createElement('div')
|
|
163
|
+
holder.innerHTML = `
|
|
164
|
+
<ark-capture>
|
|
165
|
+
<data>{"name":"John"}</data>
|
|
166
|
+
<template>\${this.profile.name}</template>
|
|
167
|
+
<output></output>
|
|
168
|
+
</ark-capture>
|
|
169
|
+
`
|
|
170
|
+
const capture = holder.querySelector('ark-capture')
|
|
171
|
+
let errorEvent = null
|
|
172
|
+
capture.addEventListener('error', (event) => {
|
|
173
|
+
errorEvent = event
|
|
111
174
|
})
|
|
175
|
+
|
|
176
|
+
capture.init().render()
|
|
177
|
+
|
|
178
|
+
assert.ok(errorEvent)
|
|
179
|
+
assert.deepStrictEqual(capture.querySelector('output').innerHTML, '')
|
|
112
180
|
})
|
|
@@ -4,12 +4,30 @@ import './droparea.js'
|
|
|
4
4
|
/** @import {Droparea} from './droparea.js' */
|
|
5
5
|
|
|
6
6
|
const tag = 'ark-droparea-preview'
|
|
7
|
+
/**
|
|
8
|
+
* Renders file previews and drag-sort ordering.
|
|
9
|
+
*/
|
|
7
10
|
|
|
8
11
|
export class DropareaPreview extends Component {
|
|
9
|
-
|
|
12
|
+
constructor () {
|
|
13
|
+
super()
|
|
14
|
+
this._objectUrls = new Map()
|
|
15
|
+
this._onDragEnd = this.handleDrop.bind(this)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** @param {object} context
|
|
19
|
+
* @returns {this} */
|
|
20
|
+
init (context = {}) {
|
|
10
21
|
return super.init()
|
|
11
22
|
}
|
|
12
23
|
|
|
24
|
+
/** @returns {void} */
|
|
25
|
+
disconnectedCallback () {
|
|
26
|
+
this.revokeAllFiles()
|
|
27
|
+
super.disconnectedCallback()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @returns {this} */
|
|
13
31
|
render () {
|
|
14
32
|
this.content = /* html */ `
|
|
15
33
|
<ul data-preview-list class="ark-droparea-preview__list drag-sort-enable"></ul>
|
|
@@ -17,8 +35,12 @@ export class DropareaPreview extends Component {
|
|
|
17
35
|
return super.render()
|
|
18
36
|
}
|
|
19
37
|
|
|
38
|
+
/**
|
|
39
|
+
* @param {File} file
|
|
40
|
+
* @returns {void}
|
|
41
|
+
*/
|
|
20
42
|
previewFile (file) {
|
|
21
|
-
const blobUrl =
|
|
43
|
+
const blobUrl = this.getObjectURL(file)
|
|
22
44
|
const fileType = file.type.split('/')[0]
|
|
23
45
|
const previewZone = this.select('[data-preview-list]')
|
|
24
46
|
const picture = document.createElement('li')
|
|
@@ -28,7 +50,9 @@ export class DropareaPreview extends Component {
|
|
|
28
50
|
removeButton.className = 'ark-droparea__remove'
|
|
29
51
|
|
|
30
52
|
if (fileType != 'image') {
|
|
31
|
-
|
|
53
|
+
const text = document.createElement('p')
|
|
54
|
+
text.textContent = file.name
|
|
55
|
+
picture.appendChild(text)
|
|
32
56
|
picture.setAttribute('data', `${blobUrl}`)
|
|
33
57
|
} else {
|
|
34
58
|
picture.style.backgroundImage = `url('${blobUrl}')`
|
|
@@ -45,6 +69,7 @@ export class DropareaPreview extends Component {
|
|
|
45
69
|
}
|
|
46
70
|
}
|
|
47
71
|
|
|
72
|
+
/** @returns {void} */
|
|
48
73
|
toggleVisibility () {
|
|
49
74
|
const previewZone = this.select('[data-preview-list]')
|
|
50
75
|
this.files.length !== 0
|
|
@@ -54,6 +79,8 @@ export class DropareaPreview extends Component {
|
|
|
54
79
|
|
|
55
80
|
/* DragSort Functionality */
|
|
56
81
|
|
|
82
|
+
/** @param {string} listClass
|
|
83
|
+
* @returns {void} */
|
|
57
84
|
enableDragSort (listClass) {
|
|
58
85
|
const sortableLists = this.getElementsByClassName(listClass)
|
|
59
86
|
Array.prototype.map.call(sortableLists, (list) => {
|
|
@@ -61,51 +88,69 @@ export class DropareaPreview extends Component {
|
|
|
61
88
|
})
|
|
62
89
|
}
|
|
63
90
|
|
|
91
|
+
/** @param {HTMLUListElement} list
|
|
92
|
+
* @returns {void} */
|
|
64
93
|
enableDragList (list) {
|
|
65
94
|
Array.prototype.map.call(list.children, (item) => {
|
|
66
95
|
this.enableDragItem(item)
|
|
67
96
|
})
|
|
68
97
|
}
|
|
69
98
|
|
|
99
|
+
/** @param {HTMLElement} item
|
|
100
|
+
* @returns {void} */
|
|
70
101
|
enableDragItem (item) {
|
|
71
|
-
item.
|
|
102
|
+
if (item.hasAttribute('data-drag-enabled')) return
|
|
103
|
+
|
|
104
|
+
item.setAttribute('data-drag-enabled', '')
|
|
105
|
+
item.setAttribute('draggable', 'true')
|
|
72
106
|
item.addEventListener('drag', this.handleDrag.bind(this, item))
|
|
73
|
-
item.addEventListener('dragend', this.
|
|
107
|
+
item.addEventListener('dragend', this._onDragEnd, false)
|
|
74
108
|
}
|
|
75
109
|
|
|
76
110
|
/* istanbul ignore next */
|
|
111
|
+
/** @param {HTMLLIElement} item
|
|
112
|
+
* @param {DragEvent} event
|
|
113
|
+
* @returns {void} */
|
|
77
114
|
handleDrag (item, event) {
|
|
78
115
|
const selectedItem = item
|
|
79
|
-
const list = selectedItem.
|
|
116
|
+
const list = /** @type {HTMLElement} */ (selectedItem.parentElement)
|
|
80
117
|
const x = event.clientX
|
|
81
118
|
const y = event.clientY
|
|
82
119
|
|
|
83
120
|
selectedItem.classList.add('drag-sort-active')
|
|
84
|
-
let swapItem =
|
|
85
|
-
document.elementFromPoint(x, y)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (list === swapItem.parentNode) {
|
|
121
|
+
let swapItem = /** @type {ChildNode|null} */ (
|
|
122
|
+
document.elementFromPoint(x, y))
|
|
123
|
+
if (!swapItem) swapItem = selectedItem
|
|
124
|
+
|
|
125
|
+
if (list && swapItem && list === swapItem.parentNode) {
|
|
89
126
|
swapItem = (
|
|
90
127
|
swapItem !== selectedItem.nextSibling
|
|
91
128
|
? swapItem
|
|
92
129
|
: swapItem.nextSibling)
|
|
93
|
-
list.insertBefore(selectedItem, swapItem)
|
|
130
|
+
list.insertBefore(selectedItem, /** @type {ChildNode|null} */ (swapItem))
|
|
94
131
|
}
|
|
95
132
|
}
|
|
96
133
|
|
|
97
|
-
|
|
98
|
-
|
|
134
|
+
/** @param {DragEvent} event
|
|
135
|
+
* @returns {void} */
|
|
136
|
+
handleDrop (event) {
|
|
137
|
+
const target = /** @type {HTMLElement|null} */ (event.target)
|
|
138
|
+
if (!target) return
|
|
139
|
+
const droparea = /** @type {Droparea|null} */ (target.closest('ark-droparea'))
|
|
140
|
+
if (!droparea) return
|
|
141
|
+
|
|
99
142
|
droparea.preview.createNewFileList()
|
|
100
|
-
|
|
143
|
+
target.classList.remove('drag-sort-active')
|
|
101
144
|
droparea.preview.dispatchAlterEvent()
|
|
102
145
|
}
|
|
103
146
|
/* ---------------------------------------------------- */
|
|
104
147
|
|
|
148
|
+
/** @returns {void} */
|
|
105
149
|
dispatchAlterEvent () {
|
|
106
150
|
this.emit('alter', this.mediaList)
|
|
107
151
|
}
|
|
108
152
|
|
|
153
|
+
/** @returns {void} */
|
|
109
154
|
createNewFileList () {
|
|
110
155
|
const nodeList = this.querySelectorAll('li')
|
|
111
156
|
const newList = []
|
|
@@ -116,15 +161,61 @@ export class DropareaPreview extends Component {
|
|
|
116
161
|
this.droparea.fileList = newList
|
|
117
162
|
}
|
|
118
163
|
|
|
164
|
+
/**
|
|
165
|
+
* @param {File} file
|
|
166
|
+
* @returns {boolean}
|
|
167
|
+
*/
|
|
119
168
|
fileExists (file) {
|
|
120
169
|
return this.files.some((item) => item.name === file.name)
|
|
121
170
|
}
|
|
122
171
|
|
|
172
|
+
/** @param {File} file
|
|
173
|
+
* @returns {string} */
|
|
174
|
+
getObjectURL (file) {
|
|
175
|
+
if (this._objectUrls.has(file)) return this._objectUrls.get(file)
|
|
176
|
+
|
|
177
|
+
const url = URL.createObjectURL(file)
|
|
178
|
+
this._objectUrls.set(file, url)
|
|
179
|
+
return url
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** @param {File} file
|
|
183
|
+
* @returns {void} */
|
|
184
|
+
revokeFile (file) {
|
|
185
|
+
const url = this._objectUrls.get(file)
|
|
186
|
+
if (!url) return
|
|
187
|
+
|
|
188
|
+
this._objectUrls.delete(file)
|
|
189
|
+
URL.revokeObjectURL?.(url)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** @returns {void} */
|
|
193
|
+
revokeAllFiles () {
|
|
194
|
+
for (const url of this._objectUrls.values()) {
|
|
195
|
+
URL.revokeObjectURL?.(url)
|
|
196
|
+
}
|
|
197
|
+
this._objectUrls.clear()
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** @returns {void} */
|
|
201
|
+
clearPreview () {
|
|
202
|
+
const previewZone = this.select('[data-preview-list]')
|
|
203
|
+
previewZone && (previewZone.textContent = '')
|
|
204
|
+
this.toggleVisibility()
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** @param {File} file
|
|
208
|
+
* @param {MouseEvent} event
|
|
209
|
+
* @returns {void} */
|
|
123
210
|
removeFile (file, event) {
|
|
124
|
-
const element = event.target
|
|
211
|
+
const element = /** @type {HTMLElement|null} */ (event.target)
|
|
212
|
+
if (!element) return
|
|
125
213
|
const fileIndex = this.droparea.fileList.indexOf(file)
|
|
214
|
+
if (fileIndex < 0) return
|
|
215
|
+
|
|
216
|
+
this.revokeFile(file)
|
|
126
217
|
this.droparea.fileList.splice(fileIndex, 1)
|
|
127
|
-
element.
|
|
218
|
+
element.parentElement?.remove()
|
|
128
219
|
this.selectAll('li').forEach((item, index) =>
|
|
129
220
|
item.setAttribute('index', String(index))
|
|
130
221
|
)
|
|
@@ -132,14 +223,18 @@ export class DropareaPreview extends Component {
|
|
|
132
223
|
this.dispatchAlterEvent()
|
|
133
224
|
}
|
|
134
225
|
|
|
226
|
+
/** @param {File} file
|
|
227
|
+
* @returns {number} */
|
|
135
228
|
fileIndex (file) {
|
|
136
229
|
return this.droparea.fileList.indexOf(file)
|
|
137
230
|
}
|
|
138
231
|
|
|
232
|
+
/** @returns {Droparea} */
|
|
139
233
|
get droparea () {
|
|
140
|
-
return /** @type {Droparea} */ (this.closest('
|
|
234
|
+
return /** @type {Droparea} */ (this.closest('ark-droparea'))
|
|
141
235
|
}
|
|
142
236
|
|
|
237
|
+
/** @returns {Array<{name:string,type:string,size:number,url:string}>} */
|
|
143
238
|
get mediaList () {
|
|
144
239
|
const mediaList = []
|
|
145
240
|
this.droparea.fileList.map((file) => {
|
|
@@ -147,7 +242,7 @@ export class DropareaPreview extends Component {
|
|
|
147
242
|
name: file.name,
|
|
148
243
|
type: file.type,
|
|
149
244
|
size: file.size,
|
|
150
|
-
url:
|
|
245
|
+
url: this.getObjectURL(file)
|
|
151
246
|
})
|
|
152
247
|
})
|
|
153
248
|
return mediaList
|