-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtext.js
60 lines (49 loc) · 1.65 KB
/
text.js
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
import { app } from "../../../scripts/app.js"
app.registerExtension({
name: "ZuellniText",
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.category != "zuellni/text")
return
const onNodeCreated = nodeType.prototype.onNodeCreated
const onExecuted = nodeType.prototype.onExecuted
if (nodeData.name == "ZuellniTextPreview") {
nodeType.prototype.onNodeCreated = function () {
const output = this.widgets.find(w => w.name == "output")
if (output) {
output.inputEl.placeholder = ""
output.inputEl.readOnly = true
output.inputEl.style.cursor = "default"
output.inputEl.style.opacity = 0.7
}
this.setSize(this.computeSize())
return onNodeCreated?.apply(this, arguments)
}
nodeType.prototype.onExecuted = function (message) {
const output = this.widgets.find(w => w.name == "output")
output && (output.value = message.text)
return onExecuted?.apply(this, arguments)
}
} else if (nodeData.name == "ZuellniTextReplace") {
nodeType.prototype.onNodeCreated = function () {
const count = this.widgets.find(w => w.name == "count")
if (count) {
count.callback = () => this.onChanged(count.value)
this.onChanged(count.value)
}
return onNodeCreated?.apply(this, arguments)
}
nodeType.prototype.onChanged = function (count) {
!this.inputs && (this.inputs = [])
const current = this.inputs.length
if (current == count)
return
if (current < count)
for (let i = current; i < count; i++)
this.addInput(String.fromCharCode(i + 97), "STRING")
else
for (let i = current - 1; i >= count; i--)
this.removeInput(i)
}
}
}
})