Skip to content

Commit feb4871

Browse files
committed
修正
1. 當設定插件參數時添加獲取插件參數的變數 2. 修正指令參數 `combo` 類型的插件註釋 3. 修正指令參數註釋標籤 4. 調整參數名稱、說明的順序 5. 修正選項摺疊與展開時高度不一致 6. 簡化部份程式碼
1 parent f3fe2b8 commit feb4871

File tree

2 files changed

+26
-40
lines changed

2 files changed

+26
-40
lines changed

index.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
}
4444

4545
.fold {
46-
height: 21px;
46+
height: 25px;
4747
overflow: hidden;
4848
}
4949

@@ -221,10 +221,7 @@
221221
align-items: center;
222222

223223
gap: 4px;
224-
}
225-
226-
.list_cell:last-child {
227-
margin-bottom: 5px;
224+
height: 25px;
228225
}
229226

230227
.group_list_cell {
@@ -732,7 +729,7 @@
732729
</div>
733730
</div>
734731

735-
<div class="list_cell">
732+
<div class="list_cell" style="height: auto;">
736733
<div id="id_0_command_editor" style="height: 200px; width: 100%;"></div>
737734
</div>
738735
</div>

src/index.js

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ class CommandControl {
485485
</div>
486486
</div>
487487
488-
<div class="list_cell">
488+
<div class="list_cell" style="height: auto;">
489489
<div id="id_${COMMAND_MAIN_LIST_COUNT}_command_editor" style="height: 200px; width: 100%;"></div>
490490
</div>
491491
</div>
@@ -816,32 +816,17 @@ class ParameterBuilder {
816816

817817
/** @return {[string, string | false][] | null} */
818818
static getSelectDetail(el) {
819-
const selectOptions = el.querySelectorAll(".group_list_cell.param_type_select > .list_cell")
820-
if (selectOptions.length === 0) return null
821-
822-
return [...selectOptions]
823-
.flatMap(list => {
824-
const opt = Fnc.getIsEmpty(list.getElementsByClassName("param_input_select_name")[0]?.value)
825-
const val = Fnc.getIsEmpty(list.getElementsByClassName("param_input_select_value")[0]?.value)
826-
if (!opt || !val) return []
827-
828-
return [
829-
["option", opt],
830-
["value", val],
831-
]
832-
})
819+
return [...el.querySelectorAll(".group_list_cell.param_type_select > .list_cell")]
820+
.flatMap(list => [
821+
["option", Fnc.getIfNotEmpty(list.querySelector(".param_input_select_name")?.value)],
822+
["value", Fnc.getIfNotEmpty(list.querySelector(".param_input_select_value")?.value)],
823+
])
833824
}
834825

835826
/** @return {[string, string | false][] | null} */
836827
static getComboDetail(el) {
837-
const comboOptions = el.querySelectorAll(".group_list_cell.param_type_combo > .list_cell")
838-
if (comboOptions.length === 0) return null
839-
840-
return [...comboOptions]
841-
.map(list => {
842-
const opt = list.getElementsByClassName("param_input_combo_option")[0]?.value
843-
return ["option", Fnc.getIfNotEmpty(opt)]
844-
})
828+
return [...el.querySelectorAll(".group_list_cell.param_type_combo > .list_cell > .param_input_combo_option")]
829+
.map(el => ["option", Fnc.getIfNotEmpty(el.value)])
845830
}
846831

847832
static getDetailByType(el, type) {
@@ -918,11 +903,11 @@ class ParameterBuilder {
918903
+ [
919904
["param", param],
920905
["parent", prepareGetValue("param_input_parent")],
906+
["text", prepareGetValue("param_input_display")],
907+
["desc", prepareGetValue("param_input_desc")],
921908
["type", ParameterBuilder.getTypeAttr(type, isArray)],
922909
["default", prepareGetValue("param_input_default")],
923910
["details", details],
924-
["text", prepareGetValue("param_input_display")],
925-
["desc", prepareGetValue("param_input_desc")],
926911
]
927912
.filter(([_, v]) => v)
928913
.map(([n, v]) => {
@@ -940,7 +925,7 @@ class ParameterBuilder {
940925
.map(ParameterBuilder.buildSingleParam)
941926
.join("")
942927

943-
return ls === "" ? false : ls
928+
return Fnc.getIfNotEmpty(ls)
944929
}
945930
}
946931

@@ -950,6 +935,7 @@ class CommandBuilder {
950935
static buildBlockParams(block) {
951936
return [...block.getElementsByClassName("command_parameter_group")]
952937
.map(ParameterBuilder.buildSingleParam)
938+
.map(res => res.replaceAll("@param ", "@arg "))
953939
.join("")
954940
}
955941

@@ -964,7 +950,7 @@ class CommandBuilder {
964950
const body = EDITOR_COMMANDS.get(`id_${id}_command_editor`)?.getValue() || ""
965951

966952
return `
967-
PluginManager.registerCommand(filename, "${name}", function ({ ${paramsName} }){
953+
PluginManager.registerCommand(FILENAME, "${name}", function ({ ${paramsName} }){
968954
${body.replaceAll("\r\n", "\r\n ")}
969955
})`
970956
}
@@ -1053,18 +1039,21 @@ class Builder {
10531039

10541040
static build() {
10551041
const [commandsNote, commandsCode] = CommandBuilder.build()
1056-
const code = commandsCode.length > 0
1057-
? `\n(()=>{
1058-
const filename = document.currentScript.src.split("/").pop().replace(".js", "")
1042+
const parameterNote = ParameterBuilder.build()
1043+
1044+
const isHadCode = commandsCode.length > 0
1045+
const isHadParam = parameterNote.length > 0
10591046

1060-
${commandsCode}
1061-
})()`
1062-
: ""
1047+
const code = `\n(()=>{`
1048+
+ (isHadCode || isHadParam ? `\n const FILENAME = document.currentScript.src.split("/").pop().replace(".js", "")` : "")
1049+
+ (isHadParam ? "\n const PARAMETERS = PluginManager.parameters(FILENAME)" : "")
1050+
+ (isHadCode ? `\n\n ${commandsCode}` : "")
1051+
+ "\n})()"
10631052

10641053
return "/**:"
10651054
+ [
10661055
BasicInfoBuilder.build(),
1067-
ParameterBuilder.build(),
1056+
parameterNote,
10681057
commandsNote,
10691058
]
10701059
.filter(Fnc.getIfNotEmpty)

0 commit comments

Comments
 (0)