gctGenerator/site/.vuepress/components/CodeList.vue

284 lines
6.4 KiB
Vue
Raw Normal View History

2020-06-28 06:33:20 +09:00
<template>
<div>
<div class="preset-select">
<SelectComponent
:options="getPresetOptions()"
:onChange="(v) => loadPreset(v)"
:placeholder="getPresetPlaceholder()"
:key="generation"
/>
</div>
<div v-for="category in codeCategories" v-bind:key="category.identifier" class="code-group">
<div class="category-title">{{ getCategoryTitle(category) }}</div>
<ul>
<li
v-for="(code, idx) in availableCodes.filter((c) => c.category === category.identifier)"
v-bind:key="idx"
:class="code.selected ? 'checked' : code.disabled ? 'disabled' : ''"
@click="toggle(code)"
@mouseover="inspect(code)"
>
{{ getCodeTitle(code) }}
</li>
<li
v-if="category.identifier === 'loader'"
:class="stageLoaderSelected ? 'checked' : ''"
@click="toggleStageLoader()"
@mouseover="showStageLoaderHelp()"
>
{{ getStageLoaderLabel() }}
</li>
</ul>
</div>
</div>
2020-06-28 06:33:20 +09:00
</template>
<script>
import { translateCode, translate } from '../i18n/localeHelper';
import codeCategories from '../data/codeCategories.json';
import presetCategories from '../data/presetCategories.json';
2020-07-03 10:42:43 +09:00
2020-06-28 06:33:20 +09:00
export default {
props: {
codes: { type: Array },
onSelectionChanged: { type: Function },
onInspect: { type: Function },
onStageLoaderToggle: { type: Function },
onInspectStageLoader: { type: Function },
2020-06-28 06:33:20 +09:00
},
mounted() {
this.populate();
},
watch: {
2020-07-01 14:26:48 +09:00
codes: function () {
2020-06-28 06:33:20 +09:00
this.populate();
this.unselectStageLoader();
2020-06-28 06:33:20 +09:00
},
},
data() {
return {
availableCodes: [],
codeCategories,
presetCategories,
stageLoaderSelected: false,
generation: 0,
2020-06-28 06:33:20 +09:00
};
},
methods: {
getPresetOptions() {
return presetCategories.map((c) => ({
label: c.i18nKey,
value: c.identifier,
}));
},
2022-02-22 09:25:49 +09:00
emitChangeEvent() {
const selectedCodes = this.availableCodes.filter((c) => c.selected);
this.onSelectionChanged(selectedCodes);
},
loadPreset(identifier) {
if (
(this.stageLoaderSelected || this.availableCodes.find((c) => c.selected)) &&
!confirm(translate('common.selectionreset', this.$lang))
) {
this.generation++;
return;
}
for (const code of this.availableCodes) {
code.selected = code.presets.includes(identifier);
}
this.unselectStageLoader();
this.refreshDisabledCodes();
2022-02-22 09:25:49 +09:00
this.emitChangeEvent();
this.generation++;
},
getPresetPlaceholder() {
return translate('common.loadpresetplaceholder', this.$lang);
},
unselectStageLoader() {
if (this.stageLoaderSelected) {
this.stageLoaderSelected = false;
this.onStageLoaderToggle(false);
}
},
2020-07-03 10:42:43 +09:00
getCodeTitle(code) {
return translateCode(code, this.$lang).title;
},
getCategoryTitle(category) {
return translate(category.i18nKey, this.$lang);
},
getStageLoaderLabel() {
return translate('headers.stageloader', this.$lang);
},
toggleStageLoader() {
for (const c of this.availableCodes.filter((c) => c.category === 'loader' && c.selected)) {
c.selected = false;
}
const newState = !this.stageLoaderSelected;
this.stageLoaderSelected = newState;
this.onStageLoaderToggle(newState);
this.refreshDisabledCodes();
2022-02-22 09:25:49 +09:00
this.emitChangeEvent();
},
refreshDisabledCodes() {
for (const code of this.availableCodes) {
if (code.dependsOn) {
if (code.dependsOn === 'loader' && this.stageLoaderSelected) {
code.disabled = false;
} else if (
!this.availableCodes.some((c) => c.selected && c.category === code.dependsOn)
) {
code.disabled = true;
code.selected = false;
} else {
code.disabled = false;
}
}
}
},
2020-06-28 06:33:20 +09:00
toggle(code) {
if (!code.selected && codeCategories.find((c) => c.identifier === code.category).exclusive) {
for (const availableCode of this.availableCodes.filter(
(c) => c.category === code.category && c.selected,
)) {
availableCode.selected = false;
}
}
if (!code.selected && code.category === 'loader' && this.stageLoaderSelected) {
this.stageLoaderSelected = false;
this.onStageLoaderToggle(false);
}
code.selected = code.disabled ? false : !code.selected;
this.refreshDisabledCodes();
2022-02-22 09:25:49 +09:00
this.emitChangeEvent();
2020-06-28 06:33:20 +09:00
},
populate() {
2020-07-01 14:26:48 +09:00
this.availableCodes = this.codes.map((c) => ({ ...c, selected: false }));
this.refreshDisabledCodes();
2020-06-28 06:33:20 +09:00
},
inspect(code) {
this.onInspect(code);
},
showStageLoaderHelp() {
this.onInspectStageLoader();
},
2020-06-28 06:33:20 +09:00
},
};
</script>
<style scoped>
.category-title {
color: white;
font-weight: 500;
text-align: center;
background: #383838b5;
padding-top: 2px;
padding-bottom: 2px;
margin-bottom: 0;
}
.category-title ~ ul {
margin-top: 0;
}
.preset-select {
margin-bottom: 20px;
}
.code-group {
border: 1px solid #d7d7d7;
margin-bottom: 20px;
}
.code-group ul {
margin-bottom: 0;
}
2020-06-28 06:33:20 +09:00
ul {
list-style-type: none;
padding-left: 0;
}
ul li {
cursor: pointer;
color: #262626;
transition: 0.1s;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
outline: none;
display: block;
min-width: 280px;
2020-09-24 21:57:59 +09:00
white-space: nowrap;
2020-06-28 06:33:20 +09:00
padding-right: 15px;
2020-06-29 00:35:18 +09:00
text-align: left;
2020-06-28 06:33:20 +09:00
}
ul li:nth-child(odd) {
2021-11-05 10:39:04 +09:00
background: #f3f3f3;
2020-06-28 06:33:20 +09:00
}
ul li:not(.disabled):hover {
2020-06-28 06:33:20 +09:00
background: #3eaf7c;
color: #fff;
}
ul li.checked:hover {
background: #3eaf7c;
color: #fff;
}
ul li.checked {
background: #434343;
color: #fff;
}
ul li.disabled {
background: #c7c7c7;
color: #767676;
}
ul li.disabled:hover {
cursor: not-allowed;
}
2020-06-28 06:33:20 +09:00
li {
position: relative;
padding-left: 26px;
}
li::before {
2020-06-29 00:35:18 +09:00
content: '';
2020-06-28 06:33:20 +09:00
position: absolute;
2021-11-05 10:39:04 +09:00
border-color: #e7e7e7;
2020-06-28 06:33:20 +09:00
border-style: solid;
border-width: 2px;
border-radius: 50%;
left: 6px;
top: 6px;
height: 10px;
width: 10px;
}
li:not(.disabled):not(.checked):hover::before {
2020-06-28 06:33:20 +09:00
border-color: #fff;
2020-06-29 00:35:18 +09:00
background-color: #1fa76e;
2020-06-28 06:33:20 +09:00
}
li.checked::before {
border-color: #fff;
background-color: #d85e55;
}
2020-06-29 00:35:18 +09:00
@media screen and (max-width: 400px) {
ul li {
min-width: 180px;
}
}
2020-06-28 06:33:20 +09:00
</style>