blockly-fluid 1.3.31 → 1.4.0

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.
@@ -1,4 +1,4 @@
1
- module.exports = (Blockly) => {
1
+ module.exports = (Blockly) => (
2
2
  class FieldMultilineInput extends Blockly.Field {
3
3
  constructor(text) {
4
4
  super(text);
@@ -30,7 +30,5 @@ module.exports = (Blockly) => {
30
30
 
31
31
  Blockly.DropDownDiv.showPositionedByField(this, this.sourceBlock_);
32
32
  };
33
- };
34
-
35
- Blockly.fieldRegistry.register("field_multiline_input", FieldMultilineInput);
36
- };
33
+ }
34
+ );
@@ -0,0 +1,34 @@
1
+ MediaSourceHandle.exports = (Blockly) => (
2
+ class FieldSearchDropdown extends Blockly.FieldDropdown {
3
+ constructor(options, validator) {
4
+ super(options, validator);
5
+ };
6
+
7
+ showEditor_() {
8
+ super.showEditor_();
9
+
10
+ const menu = Blockly.DropDownDiv.getContentDiv();
11
+
12
+ const search = document.createElement("input");
13
+ search.style.width = "100%";
14
+ search.style.boxSizing = "border-box";
15
+ search.style.marginBottom = "6px";
16
+
17
+ menu.prepend(search);
18
+
19
+ const items = Array.from(menu.querySelectorAll(".blocklyMenuItem"));
20
+
21
+ search.addEventListener("input", () => {
22
+ const value = search.value.toLowerCase();
23
+
24
+ items.forEach((item) => {
25
+ const text = item.textContent.toLowerCase();
26
+
27
+ item.style.display = text.includes(value) ? "" : "none";
28
+ });
29
+ });
30
+
31
+ search.focus();
32
+ };
33
+ }
34
+ );
package/index.js CHANGED
@@ -63,6 +63,7 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
63
63
  };
64
64
 
65
65
  if (input.options) {
66
+ if (typeof input.search === "function") (input.search = input.search());
66
67
  if (typeof input.default === "function") (input.default = input.default());
67
68
  if (typeof input.options === "function") (input.options = input.options());
68
69
 
@@ -74,6 +75,7 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
74
75
  fields: {
75
76
  DROPDOWN: {
76
77
  type: "dropdown",
78
+ search: input.search,
77
79
  default: input.default,
78
80
  options: input.options
79
81
  }
@@ -153,9 +155,10 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
153
155
 
154
156
  break;
155
157
  case "dropdown":
158
+ if (typeof field.search === "function") (field.search = field.search());
156
159
  if (typeof field.options === "function") (field.options = field.options());
157
160
 
158
- dummy.appendField(new Blockly.FieldDropdown(...[
161
+ dummy.appendField(new ((field.search) ? require("./fields/FieldSearchDropdown.js")(Blockly) : Blockly.FieldDropdown)(...[
159
162
  ((Array.isArray(field.options)) ? field.options.map((option) => [option, option]) : Object.entries(field.options)).map(([name, text]) => (
160
163
  ((name.toLowerCase().startsWith("separator")) && [true, name].includes(text))
161
164
  ? "separator"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blockly-fluid",
3
- "version": "1.3.31",
3
+ "version": "1.4.0",
4
4
  "description": "A flexible proxy wrapper for Blockly blocks.",
5
5
  "main": "index.js",
6
6
  "scripts": {