blockly-fluid 1.2.10 → 1.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fields/FieldMultilineInput.js +36 -0
- package/index.js +74 -44
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module.exports = (Blockly) => {
|
|
2
|
+
class FieldMultilineInput extends Blockly.Field {
|
|
3
|
+
constructor(text) {
|
|
4
|
+
super(text);
|
|
5
|
+
this.multiline = true;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
static fromJson(options) {
|
|
9
|
+
return new FieldMultilineInput(options["text"]);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
showEditor_() {
|
|
13
|
+
const div = Blockly.DropDownDiv.getContentDiv();
|
|
14
|
+
|
|
15
|
+
Blockly.utils.dom.clear(div);
|
|
16
|
+
|
|
17
|
+
const textarea = document.createElement("textarea");
|
|
18
|
+
|
|
19
|
+
textarea.value = this.getValue();
|
|
20
|
+
textarea.rows = 5;
|
|
21
|
+
textarea.style.resize = "both";
|
|
22
|
+
|
|
23
|
+
div.appendChild(textarea);
|
|
24
|
+
|
|
25
|
+
textarea.focus();
|
|
26
|
+
|
|
27
|
+
textarea.addEventListener("input", () => {
|
|
28
|
+
this.setValue(textarea.value);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
Blockly.DropDownDiv.showPositionedByField(this, this.sourceBlock_);
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
Blockly.fieldRegistry.register("field_multiline_input", FieldMultilineInput);
|
|
36
|
+
};
|
package/index.js
CHANGED
|
@@ -63,27 +63,33 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
|
|
|
63
63
|
|
|
64
64
|
const dropdownId = encodeURIComponent(JSON.stringify([input.default, ...((Array.isArray(input.options)) ? input.options.map((option) => [option, option]) : Object.entries(input.options)).map(([name, text]) => [translate((typeof text === "function") ? text() : text), (typeof name === "function") ? name() : name])]));
|
|
65
65
|
|
|
66
|
-
Blocks[`shadow_dropdown_${dropdownId}`]
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
if (!Blocks[`shadow_dropdown_${dropdownId}`]) {
|
|
67
|
+
Blocks[`shadow_dropdown_${dropdownId}`] = {
|
|
68
|
+
layout: "DROPDOWN",
|
|
69
|
+
fields: {
|
|
70
|
+
DROPDOWN: {
|
|
71
|
+
type: "dropdown",
|
|
72
|
+
default: input.default,
|
|
73
|
+
options: input.options
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
color,
|
|
77
|
+
output: true,
|
|
78
|
+
|
|
79
|
+
generator: ({ DROPDOWN }) => [
|
|
80
|
+
`"${DROPDOWN}"`,
|
|
81
|
+
"atomic"
|
|
82
|
+
]
|
|
83
|
+
};
|
|
82
84
|
};
|
|
83
85
|
|
|
84
86
|
valueInput.connection.setShadowDom(new DOMParser().parseFromString(`<shadow type="shadow_dropdown_${dropdownId}"></shadow>`, "text/xml").firstChild);
|
|
85
87
|
};
|
|
86
88
|
|
|
89
|
+
if (input.variable) {
|
|
90
|
+
valueInput.connection.setShadowDom(new DOMParser().parseFromString(`<shadow type="shadow_variable"><field name="VARIABLE">${input.variable}</field></shadow>`, "text/xml").firstChild);
|
|
91
|
+
};
|
|
92
|
+
|
|
87
93
|
if (input.shadow) {
|
|
88
94
|
if (typeof input.shadow === "function") (input.shadow = input.shadow());
|
|
89
95
|
|
|
@@ -98,12 +104,16 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
|
|
|
98
104
|
translate((typeof field.default === "function") ? field.default() : (field.default || "")),
|
|
99
105
|
...(field.validator) ? [field.validator] : []
|
|
100
106
|
]), token);
|
|
107
|
+
|
|
101
108
|
break;
|
|
102
109
|
case "multiline":
|
|
110
|
+
if (!Blockly.FieldMultilineInput) require("./fields/FieldMultilineInput.js")(Blockly);
|
|
111
|
+
|
|
103
112
|
dummy.appendField(new Blockly.FieldMultilineInput(...[
|
|
104
113
|
translate((typeof field.default === "function") ? field.default() : (field.default || "")),
|
|
105
114
|
...(field.validator) ? [field.validator] : []
|
|
106
115
|
]), token);
|
|
116
|
+
|
|
107
117
|
break;
|
|
108
118
|
case "dropdown":
|
|
109
119
|
if (typeof field.options === "function") (field.options = field.options());
|
|
@@ -112,12 +122,14 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
|
|
|
112
122
|
((Array.isArray(field.options)) ? field.options.map((option) => [option, option]) : Object.entries(field.options)).map(([name, text]) => [translate((typeof text === "function") ? text() : text), (typeof name === "function") ? name() : name]),
|
|
113
123
|
...(field.validator) ? [field.validator] : []
|
|
114
124
|
]), token);
|
|
125
|
+
|
|
115
126
|
break;
|
|
116
127
|
case "variable":
|
|
117
128
|
dummy.appendField(new Blockly.FieldVariable(...[
|
|
118
129
|
translate((typeof field.default === "function") ? field.default() : (field.default || "")),
|
|
119
130
|
...(field.validator) ? [field.validator] : []
|
|
120
131
|
]), token);
|
|
132
|
+
|
|
121
133
|
break;
|
|
122
134
|
default:
|
|
123
135
|
dummy.appendField(translate(token));
|
|
@@ -255,39 +267,57 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
|
|
|
255
267
|
}
|
|
256
268
|
});
|
|
257
269
|
|
|
258
|
-
Blocks["shadow_string"]
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
270
|
+
if (!Blocks["shadow_string"]) {
|
|
271
|
+
Blocks["shadow_string"] = {
|
|
272
|
+
layout: "TEXT",
|
|
273
|
+
fields: {
|
|
274
|
+
TEXT: {
|
|
275
|
+
type: "text"
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
output: true,
|
|
279
|
+
|
|
280
|
+
generator: ({ TEXT }) => [
|
|
281
|
+
`"${TEXT}"`,
|
|
282
|
+
"atomic"
|
|
283
|
+
]
|
|
284
|
+
};
|
|
285
|
+
};
|
|
266
286
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
"
|
|
270
|
-
|
|
287
|
+
if (!Blocks["shadow_number"]) {
|
|
288
|
+
Blocks["shadow_number"] = {
|
|
289
|
+
layout: "NUMBER",
|
|
290
|
+
fields: {
|
|
291
|
+
NUMBER: {
|
|
292
|
+
type: "text",
|
|
293
|
+
default: "0",
|
|
294
|
+
validator: (value) => {
|
|
295
|
+
if (!value) return "0";
|
|
296
|
+
if (/^-?\d*\.?\d*$/.test(value)) return value;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
output: Number,
|
|
301
|
+
|
|
302
|
+
generator: ({ NUMBER }) => [
|
|
303
|
+
NUMBER,
|
|
304
|
+
"atomic"
|
|
305
|
+
]
|
|
306
|
+
};
|
|
271
307
|
};
|
|
272
308
|
|
|
273
|
-
Blocks["
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
validator: (value) => {
|
|
280
|
-
if (!value) return "0";
|
|
281
|
-
if (/^-?\d*\.?\d*$/.test(value)) return value;
|
|
309
|
+
if (!Blocks["shadow_variable"]) {
|
|
310
|
+
Blocks["shadow_variable"] = {
|
|
311
|
+
layout: "VARIABLE",
|
|
312
|
+
fields: {
|
|
313
|
+
VARIABLE: {
|
|
314
|
+
type: "variable"
|
|
282
315
|
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
output: Number,
|
|
316
|
+
},
|
|
317
|
+
output: true,
|
|
286
318
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
"atomic"
|
|
290
|
-
]
|
|
319
|
+
generator: ({ VARIABLE }) => VARIABLE
|
|
320
|
+
};
|
|
291
321
|
};
|
|
292
322
|
|
|
293
323
|
return Blocks;
|