-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.svelte
199 lines (143 loc) · 5.11 KB
/
main.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<script>
export let OLSKCollectionItemAccessibilitySummaryFunction;
export let OLSKCollectionSortFunction;
export let OLSKCollectionChunkFunction = null;
export let OLSKCollectionChunkKeySortFunction = null;
export let _OLSKCollectionDispatchKey;
export let OLSKCollectionDispatchClick;
export let OLSKCollectionDispatchArrow = null;
export let OLSKCollectionDispatchStash = null;
export let OLSKCollectionItems = [];
export let OLSKCollectionItemsLocus = null;
export let OLSKCollectionItemClass = '';
export let OLSKCollectionEnableLooping = false;
export let OLSKCollectionIgnoreKeyboard = false;
import { OLSK_SPEC_UI } from 'OLSKSpec';
import OLSKCollectionLogic from './logic.js';
export const modPublic = Object.assign(OLSKCollectionLogic.OLSKCollectionAPI({
OLSKCollectionItems,
_OLSKCollectionKeyFunction: _OLSKCollectionDispatchKey,
OLSKCollectionSortFunction,
OLSKCollectionDispatchChange: (function () {
OLSKCollectionItems = OLSKCollectionItems;
_OLSKCollectionItemsDidChange(OLSKCollectionItems);
}),
}), {
_OLSKCollectionStashItems: [],
_OLSKCollectionStashEnabled: false,
OLSKCollectionStashEnabled (inputData) {
if (typeof inputData === 'undefined') {
return modPublic._OLSKCollectionStashEnabled;
}
modPublic._OLSKCollectionStashItems = [];
return modPublic._OLSKCollectionStashEnabled = inputData;
},
_OLSKCollectionStashToggle (inputData) {
modPublic._OLSKCollectionStashItems = modPublic._OLSKCollectionStashItems.includes(inputData) ? modPublic._OLSKCollectionStashItems.filter(function (e) {
return e !== inputData;
}) : modPublic._OLSKCollectionStashItems.concat(inputData);
OLSKCollectionDispatchStash && OLSKCollectionDispatchStash(modPublic._OLSKCollectionStashItems.slice());
},
});
const _OLSKCollectionItemsDidChange = function (inputData) {
modPublic._OLSKCollectionDebugReassign(inputData);
if (!OLSKCollectionChunkFunction) {
return;
}
const order = JSON.stringify(OLSKCollectionItems.map(_OLSKCollectionDispatchKey));
if (order === mod._ValueOrder) {
return;
}
mod._ValueOrder = order;
mod._ValueItemsChunked = OLSKCollectionChunkFunction(OLSKCollectionItems);
mod._ValueItemsChunks = (function (inputData) {
return OLSKCollectionChunkKeySortFunction ? inputData.sort(OLSKCollectionChunkKeySortFunction) : inputData;
})(Object.keys(mod._ValueItemsChunked));
};
$: {
_OLSKCollectionItemsDidChange(OLSKCollectionItems)
};
const mod = {
// VALUE
_ValueOrder: '',
// INTERFACE
InterfaceWindowDidKeydown(event) {
if (!OLSKCollectionDispatchArrow) {
return;
}
if (OLSKCollectionIgnoreKeyboard) {
return;
}
if (!OLSKCollectionItems.length) {
return;
}
const handlerFunctions = {
ArrowUp () {
(function() {
if (!OLSKCollectionEnableLooping && OLSKCollectionItems[0] === OLSKCollectionItemsLocus) {
return;
}
mod.ControlArrowIncrement(-1);
})();
return event.preventDefault();
},
ArrowDown () {
(function() {
if (!OLSKCollectionEnableLooping && (OLSKCollectionItems.slice(-1).pop() === OLSKCollectionItemsLocus)) {
return;
}
mod.ControlArrowIncrement(1);
})();
return event.preventDefault();
},
};
handlerFunctions[event.code] && handlerFunctions[event.code]();
},
// CONTROL
ControlArrowIncrement (inputData) {
OLSKCollectionDispatchArrow(OLSKCollectionItems[OLSKCollectionLogic.OLSKCollectionConstrainIndex(OLSKCollectionItems, OLSKCollectionItems.indexOf(OLSKCollectionItemsLocus) + inputData)]);
},
};
import OLSKUIAssets from 'OLSKUIAssets';
</script>
<svelte:window on:keydown={ mod.InterfaceWindowDidKeydown } />
<div class="OLSKCollection">
<slot></slot>
{#if !OLSKCollectionItems.length }
<div class="OLSKCollectionEmpty" aria-hidden="true">
<slot name="OLSKCollectionEmpty"></slot>
</div>
{/if}
{#each (mod._ValueItemsChunks || [undefined]) as key }
<div class="OLSKCollectionChunk">
{#if key }
<div class="OLSKCollectionChunkHeading OLSKStickyHeader">{ key }</div>
{/if}
<div class="OLSKCollectionChunkItems">
{#each (key ? mod._ValueItemsChunked[key] : OLSKCollectionItems) as item }
<div class="OLSKCollectionItem { OLSKCollectionItemClass }" class:OLSKCollectionItemStash={ modPublic._OLSKCollectionStashItems.includes(item) } class:OLSKCollectionItemLocus={ item === OLSKCollectionItemsLocus } aria-label={ OLSKCollectionItemAccessibilitySummaryFunction(item) } role="button" on:click={ () => modPublic._OLSKCollectionStashEnabled ? modPublic._OLSKCollectionStashToggle(item) : OLSKCollectionDispatchClick(item) }>
{#if modPublic._OLSKCollectionStashEnabled }
<div class="OLSKCollectionItemStashStatus">
<div class="OLSKCollectionItemStashStatusImage">{@html OLSKUIAssets._OLSKSharedStashSelected }</div>
</div>
{/if}
<slot name="OLSKCollectionItem" OLSKCollectionItem={ item }></slot>
</div>
{/each}
</div>
</div>
{/each}
</div>
<style>
.OLSKCollectionItem {
cursor: pointer;
display: flex;
align-items: center;
}
.OLSKCollectionItemStashStatus {
flex-shrink: 0;
}
.OLSKCollectionItemStashStatusImage:not(.OLSKCollectionItemStash .OLSKCollectionItemStashStatusImage) {
display: none;
}
</style>