blockly-fluid 1.1.1 → 1.2.1
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/index.js +27 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
module.exports = (Blockly, { generator: languageGeneratorFallback, generators: languageGenerators = {}, translate = (text) => text } = {}) => {
|
|
2
|
+
let shadowDropdownOptions = [];
|
|
3
|
+
|
|
2
4
|
const Blocks = new Proxy({}, {
|
|
3
5
|
set(_, name, {
|
|
4
6
|
hat,
|
|
@@ -46,7 +48,15 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
|
|
|
46
48
|
|
|
47
49
|
valueInput.setCheck(input.check || null);
|
|
48
50
|
} else {
|
|
49
|
-
valueInput.connection.setShadowDom(new DOMParser().parseFromString(`<shadow type="
|
|
51
|
+
valueInput.connection.setShadowDom(new DOMParser().parseFromString(`<shadow type="shadow_string"><field name="TEXT"></field></shadow>`, "text/xml").firstChild);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
if (input.options) {
|
|
55
|
+
if (typeof input.options === "function") (input.options = input.options());
|
|
56
|
+
|
|
57
|
+
valueInput.connection.setShadowDom(new DOMParser().parseFromString(`<shadow type="shadow_dropdown"><field name="DROPDOWN">${(typeof input.default === "function") ? input.default() : (input.default || "")}</field></shadow>`, "text/xml").firstChild);
|
|
58
|
+
|
|
59
|
+
shadowDropdownOptions = Object.entries(input.options).map(([name, text]) => [translate((typeof text === "function") ? text() : text), (typeof name === "function") ? name() : name]);
|
|
50
60
|
};
|
|
51
61
|
|
|
52
62
|
if (input.shadow) {
|
|
@@ -71,8 +81,10 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
|
|
|
71
81
|
]), token);
|
|
72
82
|
break;
|
|
73
83
|
case "dropdown":
|
|
84
|
+
if (typeof field.options === "function") (field.options = field.options());
|
|
85
|
+
|
|
74
86
|
dummy.appendField(new Blockly.FieldDropdown(...[
|
|
75
|
-
Object.entries(field.options).map(([name, text]) => [translate((typeof text === "function") ? text() : text), (typeof name === "function") ? name() : name]),
|
|
87
|
+
((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]),
|
|
76
88
|
...(field.validator) ? [field.validator] : []
|
|
77
89
|
]), token);
|
|
78
90
|
break;
|
|
@@ -116,7 +128,7 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
|
|
|
116
128
|
this.inputList.forEach((input) => {
|
|
117
129
|
if (input.connection?.shadowDom || !Array.isArray(input.connection?.check) || input.connection.check.every((check) => !["String", "Number"].includes(check))) return;
|
|
118
130
|
|
|
119
|
-
input.connection.setShadowDom(new DOMParser().parseFromString(`<shadow type="${((input.connection.check?.length === 1) && (input.connection.check[0] === "Number")) ? "number" : "string"}"><field name="${((input.connection.check?.length === 1) && (input.connection.check[0] === "Number")) ? "NUMBER" : "TEXT"}"></field></shadow>`, "text/xml").firstChild);
|
|
131
|
+
input.connection.setShadowDom(new DOMParser().parseFromString(`<shadow type="shadow_${((input.connection.check?.length === 1) && (input.connection.check[0] === "Number")) ? "number" : "string"}"><field name="${((input.connection.check?.length === 1) && (input.connection.check[0] === "Number")) ? "NUMBER" : "TEXT"}"></field></shadow>`, "text/xml").firstChild);
|
|
120
132
|
});
|
|
121
133
|
}
|
|
122
134
|
};
|
|
@@ -218,7 +230,7 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
|
|
|
218
230
|
}
|
|
219
231
|
});
|
|
220
232
|
|
|
221
|
-
Blocks["
|
|
233
|
+
Blocks["shadow_string"] = {
|
|
222
234
|
layout: "TEXT",
|
|
223
235
|
fields: {
|
|
224
236
|
TEXT: {
|
|
@@ -233,7 +245,7 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
|
|
|
233
245
|
]
|
|
234
246
|
};
|
|
235
247
|
|
|
236
|
-
Blocks["
|
|
248
|
+
Blocks["shadow_number"] = {
|
|
237
249
|
layout: "NUMBER",
|
|
238
250
|
fields: {
|
|
239
251
|
NUMBER: {
|
|
@@ -253,5 +265,15 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
|
|
|
253
265
|
]
|
|
254
266
|
};
|
|
255
267
|
|
|
268
|
+
Blocks["shadow_dropdown"] = {
|
|
269
|
+
layout: "DROPDOWN",
|
|
270
|
+
fields: {
|
|
271
|
+
DROPDOWN: {
|
|
272
|
+
type: "dropdown",
|
|
273
|
+
options: () => shadowDropdownOptions
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
256
278
|
return Blocks;
|
|
257
279
|
};
|