mirror of
https://github.com/Physton/sd-webui-prompt-all-in-one.git
synced 2026-05-01 03:31:41 +00:00
Optimize the Tag input box
Optimize the Tag input box Former-commit-id: 0bb23f0fe2395d25773809cdbfbf3c153cfbe229
This commit is contained in:
@@ -1 +1 @@
|
||||
a0b7cb269fbf832a41a24aca46027515a3d492c3
|
||||
d7c7d23683e3ca9e351463e206a3c9b2e5399646
|
||||
@@ -1 +1 @@
|
||||
9d048e74cdcf8cd85072a83b193e2e4d19d7fd5d
|
||||
24ec055fc7e04c6b8625d0bc0eefe1664cceafef
|
||||
@@ -417,6 +417,17 @@ export default {
|
||||
genPrompt() {
|
||||
let prompts = []
|
||||
this.tags.forEach(tag => {
|
||||
let value = common.replaceTag(tag.value)
|
||||
console.log(value)
|
||||
if (value !== tag.value) {
|
||||
tag.value = value
|
||||
this._setTag(tag)
|
||||
}
|
||||
let localValue = common.replaceTag(tag.localValue)
|
||||
if (localValue !== tag.localValue) {
|
||||
tag.localValue = localValue
|
||||
}
|
||||
|
||||
if (tag.weightNum > 0) {
|
||||
tag.weightNum = parseFloat(tag.weightNum).toFixed(1)
|
||||
tag.value = tag.value.replace(common.weightNumRegex, ':' + tag.weightNum)
|
||||
@@ -459,14 +470,23 @@ export default {
|
||||
}
|
||||
return value
|
||||
},
|
||||
_setTag(tag) {
|
||||
tag.weightNum = common.getTagWeightNum(tag.value)
|
||||
tag.incWeight = common.getTagIncWeight(tag.value)
|
||||
tag.decWeight = common.getTagDecWeight(tag.value)
|
||||
},
|
||||
_appendTag(value, localValue = '', disabled = false) {
|
||||
const id = this.lastId++
|
||||
const weightNum = common.getTagWeightNum(value)
|
||||
const incWeight = common.getTagIncWeight(value)
|
||||
const decWeight = common.getTagDecWeight(value)
|
||||
let tag = {
|
||||
id,
|
||||
value,
|
||||
localValue,
|
||||
disabled,
|
||||
}
|
||||
this._setTag(tag)
|
||||
// value = common.setLayers(value, 0, '(', ')')
|
||||
// value = common.setLayers(value, 0, '[', ']')
|
||||
const index = this.tags.push({id, value, localValue, disabled, weightNum, incWeight, decWeight})
|
||||
const index = this.tags.push(tag)
|
||||
this.$nextTick(() => {
|
||||
autoSizeInput(this.$refs['promptTagEdit-' + id][0])
|
||||
})
|
||||
@@ -540,22 +560,16 @@ export default {
|
||||
if (e.keyCode === 13) {
|
||||
this.editing[this.tags[index].id] = false
|
||||
if (this.tags[index].value !== e.target.value) {
|
||||
const value = e.target.value
|
||||
this.tags[index].weightNum = common.getTagWeightNum(value)
|
||||
this.tags[index].incWeight = common.getTagIncWeight(value)
|
||||
this.tags[index].decWeight = common.getTagDecWeight(value)
|
||||
this.tags[index].value = e.target.value
|
||||
this._setTag(this.tags[index])
|
||||
// this.updateTags()
|
||||
}
|
||||
}
|
||||
},
|
||||
onTagInputChange(index, e) {
|
||||
if (this.tags[index].value === e.target.value) return
|
||||
const value = e.target.value
|
||||
this.tags[index].weightNum = common.getTagWeightNum(value)
|
||||
this.tags[index].incWeight = common.getTagIncWeight(value)
|
||||
this.tags[index].decWeight = common.getTagDecWeight(value)
|
||||
this.tags[index].value = value
|
||||
this.tags[index].value = e.target.value
|
||||
this._updateTag(this.tags[index])
|
||||
this.updateTags()
|
||||
},
|
||||
onTagWeightNumChange(index, e) {
|
||||
|
||||
@@ -1,5 +1,50 @@
|
||||
export default {
|
||||
weightNumRegex: /:([0-9\.]+)/,
|
||||
weightNumRegexEN: /:\s*([0-9\.]+)/,
|
||||
weightNumRegexCN: /:\s*([0-9\.]+)/,
|
||||
|
||||
replaceTag(text) {
|
||||
if (typeof text !== "string") return text
|
||||
if (text === "") return text
|
||||
text = this.replaceBrackets(text)
|
||||
if (this.weightNumRegexEN.test(text)) text = text.replace(this.weightNumRegexEN, ':$1')
|
||||
if (this.weightNumRegexCN.test(text)) text = text.replace(this.weightNumRegexCN, ':$1')
|
||||
return text
|
||||
},
|
||||
|
||||
replaceBrackets(text) {
|
||||
const length = text.length
|
||||
if (length === 0) return text
|
||||
const replaces = {
|
||||
"(": "(",
|
||||
")": ")",
|
||||
"【": "[",
|
||||
"】": "]",
|
||||
"《": "<",
|
||||
"》": ">",
|
||||
"「": "{",
|
||||
"」": "}",
|
||||
"『": "{",
|
||||
"』": "}",
|
||||
"〈": "<",
|
||||
"〉": ">",
|
||||
"﹝": "(",
|
||||
"﹞": ")",
|
||||
"﹛": "{",
|
||||
"﹜": "}",
|
||||
"﹙": "(",
|
||||
"﹚": ")",
|
||||
}
|
||||
let start = text[0]
|
||||
let end = text[length - 1]
|
||||
if (typeof replaces[start] !== "undefined") {
|
||||
text[0] = replaces[start]
|
||||
}
|
||||
if (typeof replaces[end] !== "undefined") {
|
||||
text[length - 1] = replaces[end]
|
||||
}
|
||||
return text
|
||||
},
|
||||
|
||||
/**
|
||||
* 分割标签
|
||||
|
||||
Reference in New Issue
Block a user