@knowark/componarkjs 1.13.4 → 1.14.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/lib/base/component/component.js +17 -1
- package/lib/base/component/component.test.js +475 -389
- package/lib/base/utils/define.js +28 -6
- package/lib/base/utils/define.test.js +129 -42
- package/lib/base/utils/format.test.js +16 -16
- package/lib/base/utils/helpers.js +11 -4
- package/lib/base/utils/helpers.test.js +134 -115
- package/lib/base/utils/slots.test.js +38 -38
- package/lib/base/utils/uuid.test.js +13 -13
- package/lib/components/audio/components/audio.js +19 -1
- package/lib/components/audio/components/audio.test.js +120 -90
- package/lib/components/camera/components/camera.js +5 -0
- package/lib/components/camera/components/camera.test.js +96 -91
- package/lib/components/capture/components/capture.js +30 -2
- package/lib/components/capture/components/capture.test.js +165 -97
- package/lib/components/droparea/components/droparea-preview.js +58 -8
- package/lib/components/droparea/components/droparea-preview.test.js +262 -80
- package/lib/components/droparea/components/droparea.js +41 -4
- package/lib/components/droparea/components/droparea.test.js +309 -299
- package/lib/components/emit/components/emit.js +23 -3
- package/lib/components/emit/components/emit.test.js +192 -134
- package/lib/components/list/components/item.test.js +69 -68
- package/lib/components/list/components/list.js +33 -3
- package/lib/components/list/components/list.test.js +358 -227
- package/lib/components/paginator/components/paginator.test.js +146 -143
- package/lib/components/spinner/components/spinner.test.js +36 -41
- package/lib/components/splitview/components/splitview.detail.test.js +75 -73
- package/lib/components/splitview/components/splitview.js +36 -8
- package/lib/components/splitview/components/splitview.master.js +27 -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/translate/components/translate.js +28 -8
- package/lib/components/translate/components/translate.test.js +492 -133
- package/package.json +3 -27
- package/scripts/node-test-setup.js +94 -0
|
@@ -1,152 +1,155 @@
|
|
|
1
|
+
import { it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
1
3
|
import './paginator.js'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
let container = null
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
container = document.createElement('div')
|
|
8
|
-
document.body.appendChild(container)
|
|
9
|
-
})
|
|
5
|
+
let container = null
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
const setup = () => {
|
|
8
|
+
document.body.innerHTML = '';
|
|
9
|
+
container = document.createElement('div')
|
|
10
|
+
document.body.appendChild(container)
|
|
11
|
+
};
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
it('can be instantiated', () => {
|
|
14
|
+
setup();
|
|
15
|
+
container.innerHTML = /* html */ `
|
|
16
|
+
<ark-paginator></ark-paginator>
|
|
17
|
+
`
|
|
18
|
+
const paginator = container.querySelector('ark-paginator')
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
assert.strictEqual(paginator, paginator.init())
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('can be instantiated with parameters', () => {
|
|
24
|
+
setup();
|
|
25
|
+
container.innerHTML = /* html */ `
|
|
26
|
+
<ark-paginator page-size="12" displayed-pages="5"></ark-paginator>
|
|
27
|
+
`
|
|
28
|
+
const paginator = container.querySelector('ark-paginator')
|
|
29
|
+
paginator.init({ collectionSize: 120, currentPage: 4 })
|
|
30
|
+
|
|
31
|
+
assert.strictEqual(paginator.pageSize, '12')
|
|
32
|
+
assert.strictEqual(paginator.collectionSize, '120')
|
|
33
|
+
assert.strictEqual(paginator.currentPage, '4')
|
|
34
|
+
assert.strictEqual(paginator.displayedPages, '5')
|
|
35
|
+
assert.strictEqual(paginator.totalPages, 10)
|
|
36
|
+
|
|
37
|
+
paginator.init({ collectionSize: 120, pageSize: 10 })
|
|
38
|
+
assert.strictEqual(paginator.totalPages, 12)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('computes the current shown pages', () => {
|
|
42
|
+
setup();
|
|
43
|
+
container.innerHTML = /* html */ `
|
|
44
|
+
<ark-paginator collection-size="120" page-size="12"
|
|
45
|
+
displayed-pages="5" current-page="1"></ark-paginator>
|
|
46
|
+
`
|
|
47
|
+
const paginator = container.querySelector('ark-paginator')
|
|
48
|
+
|
|
49
|
+
assert.deepStrictEqual(paginator.currentPages, [1, 2, 3, 4, 5])
|
|
50
|
+
assert.deepStrictEqual(paginator.totalPages, 10)
|
|
51
|
+
|
|
52
|
+
paginator.init({ currentPage: 3 })
|
|
53
|
+
assert.deepStrictEqual(paginator.currentPages, [1, 2, 3, 4, 5])
|
|
54
|
+
|
|
55
|
+
paginator.init({ currentPage: 4 })
|
|
56
|
+
assert.deepStrictEqual(paginator.currentPages, [2, 3, 4, 5, 6])
|
|
57
|
+
|
|
58
|
+
paginator.init({ currentPage: 5 })
|
|
59
|
+
assert.deepStrictEqual(paginator.currentPages, [3, 4, 5, 6, 7])
|
|
60
|
+
|
|
61
|
+
paginator.init({ currentPage: 7 })
|
|
62
|
+
assert.deepStrictEqual(paginator.currentPages, [5, 6, 7, 8, 9])
|
|
63
|
+
|
|
64
|
+
paginator.init({ currentPage: 8 })
|
|
65
|
+
assert.deepStrictEqual(paginator.currentPages, [6, 7, 8, 9, 10])
|
|
66
|
+
|
|
67
|
+
paginator.init({ currentPage: 9 })
|
|
68
|
+
assert.deepStrictEqual(paginator.currentPages, [6, 7, 8, 9, 10])
|
|
69
|
+
|
|
70
|
+
paginator.init({ currentPage: 10 })
|
|
71
|
+
assert.deepStrictEqual(paginator.currentPages, [6, 7, 8, 9, 10])
|
|
72
|
+
|
|
73
|
+
paginator.init({ displayedPages: 6, currentPage: 5 })
|
|
74
|
+
assert.deepStrictEqual(paginator.currentPages, [2, 3, 4, 5, 6, 7])
|
|
75
|
+
|
|
76
|
+
paginator.init({ displayedPages: 6, currentPage: 7 })
|
|
77
|
+
assert.deepStrictEqual(paginator.currentPages, [4, 5, 6, 7, 8, 9])
|
|
24
78
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
79
|
+
paginator.init({ displayedPages: 6, currentPage: 9 })
|
|
80
|
+
assert.deepStrictEqual(paginator.currentPages, [5, 6, 7, 8, 9, 10])
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('enables and notifies page changes', () => {
|
|
84
|
+
setup();
|
|
85
|
+
container.innerHTML = /* html */ `
|
|
86
|
+
<ark-paginator collection-size="100" page-size="10"
|
|
87
|
+
displayed-pages="5" current-page="1"></ark-paginator>
|
|
88
|
+
`
|
|
89
|
+
const paginator = container.querySelector('ark-paginator')
|
|
90
|
+
|
|
91
|
+
let pageChangedEvent = null
|
|
92
|
+
paginator.addEventListener(
|
|
93
|
+
'page-changed', (event) => pageChangedEvent = event)
|
|
94
|
+
|
|
95
|
+
paginator._setCurrentPage(4)
|
|
96
|
+
|
|
97
|
+
assert.deepStrictEqual(paginator.currentPage, '4')
|
|
98
|
+
assert.ok(pageChangedEvent)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('moves to the different pages', () => {
|
|
102
|
+
setup();
|
|
103
|
+
container.innerHTML = /* html */ `
|
|
104
|
+
<ark-paginator collection-size="100" page-size="10"
|
|
105
|
+
displayed-pages="5" current-page="1"></ark-paginator>
|
|
106
|
+
`
|
|
107
|
+
const paginator = container.querySelector('ark-paginator')
|
|
31
108
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
expect(paginator.currentPages).toEqual([1, 2, 3, 4, 5])
|
|
54
|
-
|
|
55
|
-
paginator.init({ currentPage: 4 })
|
|
56
|
-
expect(paginator.currentPages).toEqual([2, 3, 4, 5, 6])
|
|
57
|
-
|
|
58
|
-
paginator.init({ currentPage: 5 })
|
|
59
|
-
expect(paginator.currentPages).toEqual([3, 4, 5, 6, 7])
|
|
60
|
-
|
|
61
|
-
paginator.init({ currentPage: 7 })
|
|
62
|
-
expect(paginator.currentPages).toEqual([5, 6, 7, 8, 9])
|
|
63
|
-
|
|
64
|
-
paginator.init({ currentPage: 8 })
|
|
65
|
-
expect(paginator.currentPages).toEqual([6, 7, 8, 9, 10])
|
|
66
|
-
|
|
67
|
-
paginator.init({ currentPage: 9 })
|
|
68
|
-
expect(paginator.currentPages).toEqual([6, 7, 8, 9, 10])
|
|
69
|
-
|
|
70
|
-
paginator.init({ currentPage: 10 })
|
|
71
|
-
expect(paginator.currentPages).toEqual([6, 7, 8, 9, 10])
|
|
72
|
-
|
|
73
|
-
paginator.init({ displayedPages: 6, currentPage: 5 })
|
|
74
|
-
expect(paginator.currentPages).toEqual([2, 3, 4, 5, 6, 7])
|
|
75
|
-
|
|
76
|
-
paginator.init({ displayedPages: 6, currentPage: 7 })
|
|
77
|
-
expect(paginator.currentPages).toEqual([4, 5, 6, 7, 8, 9])
|
|
78
|
-
|
|
79
|
-
paginator.init({ displayedPages: 6, currentPage: 9 })
|
|
80
|
-
expect(paginator.currentPages).toEqual([5, 6, 7, 8, 9, 10])
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it('enables and notifies page changes', () => {
|
|
84
|
-
container.innerHTML = /* html */ `
|
|
85
|
-
<ark-paginator collection-size="100" page-size="10"
|
|
86
|
-
displayed-pages="5" current-page="1"></ark-paginator>
|
|
87
|
-
`
|
|
88
|
-
const paginator = container.querySelector('ark-paginator')
|
|
89
|
-
|
|
90
|
-
let pageChangedEvent = null
|
|
91
|
-
paginator.addEventListener(
|
|
92
|
-
'page-changed', (event) => pageChangedEvent = event)
|
|
93
|
-
|
|
94
|
-
paginator._setCurrentPage(4)
|
|
95
|
-
|
|
96
|
-
expect(paginator.currentPage).toEqual('4')
|
|
97
|
-
expect(pageChangedEvent).toBeTruthy()
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
it('moves to the different pages', () => {
|
|
101
|
-
container.innerHTML = /* html */ `
|
|
102
|
-
<ark-paginator collection-size="100" page-size="10"
|
|
103
|
-
displayed-pages="5" current-page="1"></ark-paginator>
|
|
104
|
-
`
|
|
105
|
-
const paginator = container.querySelector('ark-paginator')
|
|
106
|
-
|
|
107
|
-
paginator.select('[data-page="4"]').click()
|
|
108
|
-
expect(paginator.currentPage).toEqual('4')
|
|
109
|
-
|
|
110
|
-
paginator.select('[data-page="6"]').click()
|
|
111
|
-
expect(paginator.currentPage).toEqual('6')
|
|
112
|
-
|
|
113
|
-
paginator.select('[on-click="_prev"]').click()
|
|
114
|
-
expect(paginator.currentPage).toEqual('5')
|
|
115
|
-
|
|
116
|
-
paginator.select('[on-click="_next"]').click()
|
|
117
|
-
expect(paginator.currentPage).toEqual('6')
|
|
118
|
-
|
|
119
|
-
paginator.select('[on-click="_first"]').click()
|
|
120
|
-
expect(paginator.currentPage).toEqual('1')
|
|
121
|
-
|
|
122
|
-
paginator.select('[on-click="_last"]').click()
|
|
123
|
-
expect(paginator.currentPage).toEqual('10')
|
|
124
|
-
|
|
125
|
-
paginator.select('[on-click="_next"]').click()
|
|
126
|
-
expect(paginator.currentPage).toEqual('10')
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
it('can be provided with custom styleable elements', () => {
|
|
130
|
-
container.innerHTML = /* html */ `
|
|
131
|
-
<ark-paginator page-size="12" displayed-pages="5">
|
|
132
|
-
<button data-first slot="first">
|
|
133
|
-
<span style="pointer-events: none">FIRST</span>
|
|
134
|
-
</button>
|
|
135
|
-
<button data-previous slot="previous">BACK</button>
|
|
136
|
-
<button data-page-general slot="page"></button>
|
|
137
|
-
<button data-next slot="next"></button>
|
|
138
|
-
<button data-last slot="last"></button>
|
|
139
|
-
</ark-paginator>
|
|
140
|
-
`
|
|
109
|
+
paginator.select('[data-page="4"]').click()
|
|
110
|
+
assert.deepStrictEqual(paginator.currentPage, '4')
|
|
111
|
+
|
|
112
|
+
paginator.select('[data-page="6"]').click()
|
|
113
|
+
assert.deepStrictEqual(paginator.currentPage, '6')
|
|
114
|
+
|
|
115
|
+
paginator.select('[on-click="_prev"]').click()
|
|
116
|
+
assert.deepStrictEqual(paginator.currentPage, '5')
|
|
117
|
+
|
|
118
|
+
paginator.select('[on-click="_next"]').click()
|
|
119
|
+
assert.deepStrictEqual(paginator.currentPage, '6')
|
|
120
|
+
|
|
121
|
+
paginator.select('[on-click="_first"]').click()
|
|
122
|
+
assert.deepStrictEqual(paginator.currentPage, '1')
|
|
123
|
+
|
|
124
|
+
paginator.select('[on-click="_last"]').click()
|
|
125
|
+
assert.deepStrictEqual(paginator.currentPage, '10')
|
|
126
|
+
|
|
127
|
+
paginator.select('[on-click="_next"]').click()
|
|
128
|
+
assert.deepStrictEqual(paginator.currentPage, '10')
|
|
129
|
+
})
|
|
141
130
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
131
|
+
it('can be provided with custom styleable elements', () => {
|
|
132
|
+
setup();
|
|
133
|
+
container.innerHTML = /* html */ `
|
|
134
|
+
<ark-paginator page-size="12" displayed-pages="5">
|
|
135
|
+
<button data-first slot="first">
|
|
136
|
+
<span style="pointer-events: none">FIRST</span>
|
|
137
|
+
</button>
|
|
138
|
+
<button data-previous slot="previous">BACK</button>
|
|
139
|
+
<button data-page-general slot="page"></button>
|
|
140
|
+
<button data-next slot="next"></button>
|
|
141
|
+
<button data-last slot="last"></button>
|
|
142
|
+
</ark-paginator>
|
|
143
|
+
`
|
|
144
|
+
|
|
145
|
+
const paginator = container.querySelector('ark-paginator')
|
|
146
|
+
|
|
147
|
+
assert.deepStrictEqual(
|
|
148
|
+
paginator.querySelector('[data-first]').innerHTML.trim(),
|
|
149
|
+
'<span style="pointer-events: none">FIRST</span>'
|
|
150
|
+
)
|
|
151
|
+
assert.deepStrictEqual(paginator.querySelector('[data-previous]').innerHTML.trim(), 'BACK')
|
|
152
|
+
assert.ok(paginator.querySelector('[data-page-general]'))
|
|
153
|
+
assert.ok(paginator.querySelector('[data-next]'))
|
|
154
|
+
assert.ok(paginator.querySelector('[data-last]'))
|
|
152
155
|
})
|
|
@@ -1,50 +1,45 @@
|
|
|
1
|
+
import { it } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
1
3
|
import './spinner.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 = /* html */ `
|
|
16
|
+
<ark-spinner></ark-spinner>
|
|
17
|
+
`
|
|
18
|
+
const spinner = container.querySelector('ark-spinner')
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
`
|
|
20
|
-
const spinner = container.querySelector('ark-spinner')
|
|
21
|
-
|
|
22
|
-
expect(spinner).toBeTruthy
|
|
23
|
-
expect(spinner).toBe(spinner.init())
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('Different types of spinner can be used', () => {
|
|
27
|
-
container.innerHTML = /* html */ `
|
|
28
|
-
<ark-spinner type="chase"></ark-spinner>
|
|
29
|
-
<ark-spinner type="rect"></ark-spinner>
|
|
30
|
-
<ark-spinner type="loader"></ark-spinner>
|
|
31
|
-
<ark-spinner type="bounce"></ark-spinner>
|
|
32
|
-
`
|
|
33
|
-
const spinner = container.querySelector('ark-spinner')
|
|
34
|
-
const loader = spinner.loader
|
|
20
|
+
assert.ok(spinner)
|
|
21
|
+
assert.strictEqual(spinner, spinner.init())
|
|
22
|
+
})
|
|
35
23
|
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
it('Different types of spinner can be used', () => {
|
|
25
|
+
setup()
|
|
26
|
+
container.innerHTML = /* html */ `
|
|
27
|
+
<ark-spinner type="chase"></ark-spinner>
|
|
28
|
+
<ark-spinner type="rect"></ark-spinner>
|
|
29
|
+
<ark-spinner type="loader"></ark-spinner>
|
|
30
|
+
<ark-spinner type="bounce"></ark-spinner>
|
|
31
|
+
`
|
|
32
|
+
const spinner = container.querySelector('ark-spinner')
|
|
33
|
+
assert.ok(spinner.loader)
|
|
34
|
+
})
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
it('Can set the scale of the spinner', () => {
|
|
37
|
+
setup()
|
|
38
|
+
container.innerHTML = /* html */ `
|
|
39
|
+
<ark-spinner scale="2.5" type="chase"></ark-spinner>
|
|
40
|
+
`
|
|
41
|
+
const spinner = container.querySelector('ark-spinner')
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
spinner.scale
|
|
48
|
-
)
|
|
49
|
-
})
|
|
43
|
+
assert.ok(spinner.loader)
|
|
44
|
+
assert.strictEqual(spinner.style.transform.split(')')[0].split('(')[1], spinner.scale)
|
|
50
45
|
})
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
1
3
|
import { Component } from '#base/index.js'
|
|
2
4
|
import './splitview.detail.js'
|
|
3
5
|
|
|
@@ -18,77 +20,77 @@ class MockMain extends Component {
|
|
|
18
20
|
}
|
|
19
21
|
Component.define('mock-main', MockMain)
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
<
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
23
|
+
let container = null
|
|
24
|
+
|
|
25
|
+
const setup = () => {
|
|
26
|
+
document.body.innerHTML = '';
|
|
27
|
+
container = document.createElement('div')
|
|
28
|
+
document.body.appendChild(container)
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
it('can be instantiated', () => {
|
|
32
|
+
setup();
|
|
33
|
+
container.innerHTML = `
|
|
34
|
+
<ark-splitview-detail>
|
|
35
|
+
</ark-splitview-detail>
|
|
36
|
+
`
|
|
37
|
+
const detail = container.querySelector('ark-splitview-detail')
|
|
38
|
+
assert.ok(detail)
|
|
39
|
+
|
|
40
|
+
assert.strictEqual(detail, detail.init())
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('can be instantiated with an inner main Component', () => {
|
|
44
|
+
setup();
|
|
45
|
+
container.innerHTML = /* html */`
|
|
46
|
+
<ark-splitview-detail>
|
|
47
|
+
<mock-main>MAIN CONTENT</mock-main>
|
|
48
|
+
</ark-splitview-detail>
|
|
49
|
+
`
|
|
50
|
+
const detail = container.querySelector('ark-splitview-detail')
|
|
51
|
+
|
|
52
|
+
assert.deepStrictEqual(detail.firstElementChild.textContent, 'MAIN CONTENT')
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('can initialize its main Component', () => {
|
|
56
|
+
setup();
|
|
57
|
+
container.innerHTML = /* html */`
|
|
58
|
+
<ark-splitview-detail>
|
|
59
|
+
<mock-main></mock-main>
|
|
60
|
+
</ark-splitview-detail>
|
|
61
|
+
`
|
|
62
|
+
const detail = container.querySelector('ark-splitview-detail')
|
|
63
|
+
|
|
64
|
+
detail.init({ name: 'Servagro' }).render()
|
|
65
|
+
|
|
66
|
+
assert.deepStrictEqual(detail.firstElementChild.textContent, 'Servagro')
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('can manipulate its hidden attribute', () => {
|
|
70
|
+
setup();
|
|
71
|
+
container.innerHTML = /* html */`
|
|
72
|
+
<ark-splitview-detail>
|
|
73
|
+
<mock-main></mock-main>
|
|
74
|
+
</ark-splitview-detail>
|
|
75
|
+
`
|
|
76
|
+
const detail = container.querySelector('ark-splitview-detail')
|
|
77
|
+
|
|
78
|
+
detail.show()
|
|
79
|
+
assert.ok(!detail.hasAttribute('hidden'))
|
|
80
|
+
|
|
81
|
+
detail.hide()
|
|
82
|
+
assert.ok(detail.hasAttribute('hidden'))
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('listens to close events to hide itself', () => {
|
|
86
|
+
setup();
|
|
87
|
+
container.innerHTML = /* html */`
|
|
88
|
+
<ark-splitview-detail>
|
|
89
|
+
<mock-main></mock-main>
|
|
90
|
+
</ark-splitview-detail>
|
|
91
|
+
`
|
|
92
|
+
const detail = container.querySelector('ark-splitview-detail')
|
|
93
|
+
detail.dispatchEvent(new Event('close'))
|
|
94
|
+
|
|
95
|
+
assert.ok(detail.hasAttribute('hidden'))
|
|
94
96
|
})
|
|
@@ -7,13 +7,44 @@ export class SplitView extends Component {
|
|
|
7
7
|
constructor () {
|
|
8
8
|
super()
|
|
9
9
|
this.binding = 'splitview-listen'
|
|
10
|
-
this.setDimensions()
|
|
11
|
-
|
|
10
|
+
this._onResize = this.setDimensions.bind(this)
|
|
11
|
+
this._onMasterChange = this.onMasterChange.bind(this)
|
|
12
|
+
this._master = null
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
setDimensions () {
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
if (typeof globalThis.innerHeight !== 'number') return
|
|
17
|
+
if (typeof globalThis.innerWidth !== 'number') return
|
|
18
|
+
|
|
19
|
+
this.style.setProperty('--inner-height', `${globalThis.innerHeight}px`)
|
|
20
|
+
this.style.setProperty('--inner-width', `${globalThis.innerWidth}px`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
connectedCallback () {
|
|
24
|
+
this.setDimensions()
|
|
25
|
+
globalThis.addEventListener('resize', this._onResize)
|
|
26
|
+
super.connectedCallback()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
disconnectedCallback () {
|
|
30
|
+
globalThis.removeEventListener('resize', this._onResize)
|
|
31
|
+
this._removeMasterListener()
|
|
32
|
+
super.disconnectedCallback()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_setMasterListener () {
|
|
36
|
+
const master = this.master
|
|
37
|
+
if (master === this._master) return
|
|
38
|
+
|
|
39
|
+
this._removeMasterListener()
|
|
40
|
+
this._master = master
|
|
41
|
+
this._master?.addEventListener('master-change', this._onMasterChange)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_removeMasterListener () {
|
|
45
|
+
if (!this._master) return
|
|
46
|
+
this._master.removeEventListener('master-change', this._onMasterChange)
|
|
47
|
+
this._master = null
|
|
17
48
|
}
|
|
18
49
|
|
|
19
50
|
get master () {
|
|
@@ -26,10 +57,7 @@ export class SplitView extends Component {
|
|
|
26
57
|
|
|
27
58
|
render () {
|
|
28
59
|
this.renderDetail()
|
|
29
|
-
|
|
30
|
-
this.master.addEventListener(
|
|
31
|
-
'master-change', this.onMasterChange.bind(this))
|
|
32
|
-
}
|
|
60
|
+
this._setMasterListener()
|
|
33
61
|
return super.render()
|
|
34
62
|
}
|
|
35
63
|
|
|
@@ -4,9 +4,9 @@ const tag = 'ark-splitview-master'
|
|
|
4
4
|
export class SplitViewMaster extends Component {
|
|
5
5
|
constructor () {
|
|
6
6
|
super()
|
|
7
|
+
this._onMasterEvent = this.onMasterEvent.bind(this)
|
|
8
|
+
this._boundMasterEvent = null
|
|
7
9
|
this.masterEvent = this.masterEvent
|
|
8
|
-
this.addEventListener(
|
|
9
|
-
this.masterEvent, this.onMasterEvent.bind(this))
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
init (context = {}) {
|
|
@@ -18,6 +18,31 @@ export class SplitViewMaster extends Component {
|
|
|
18
18
|
return ['masterEvent']
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
connectedCallback () {
|
|
22
|
+
this._syncMasterEventListener()
|
|
23
|
+
super.connectedCallback()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
disconnectedCallback () {
|
|
27
|
+
this._removeMasterEventListener()
|
|
28
|
+
super.disconnectedCallback()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
_syncMasterEventListener () {
|
|
32
|
+
const masterEvent = (this.masterEvent || '').trim()
|
|
33
|
+
if (!masterEvent || masterEvent === this._boundMasterEvent) return
|
|
34
|
+
|
|
35
|
+
this._removeMasterEventListener()
|
|
36
|
+
this.addEventListener(masterEvent, this._onMasterEvent)
|
|
37
|
+
this._boundMasterEvent = masterEvent
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
_removeMasterEventListener () {
|
|
41
|
+
if (!this._boundMasterEvent) return
|
|
42
|
+
this.removeEventListener(this._boundMasterEvent, this._onMasterEvent)
|
|
43
|
+
this._boundMasterEvent = null
|
|
44
|
+
}
|
|
45
|
+
|
|
21
46
|
/** @param {CustomEvent} event */
|
|
22
47
|
onMasterEvent (event) {
|
|
23
48
|
event.stopPropagation()
|