blockly-fluid 1.2.17 → 1.3.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.
package/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ const escapeXml = require("./utils/escapeXml.js");
2
+
1
3
  module.exports = (Blockly, { generator: languageGeneratorFallback, generators: languageGenerators = {}, translate = (text) => text } = {}) => {
2
4
  const Blocks = new Proxy({}, {
3
5
  set(_, name, configuration = {}) {
@@ -59,10 +61,8 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
59
61
  if (typeof input.default === "function") (input.default = input.default());
60
62
  if (typeof input.options === "function") (input.options = input.options());
61
63
 
62
- const dropdownId = encodeURIComponent(JSON.stringify([color, 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])]));
63
-
64
- if (!Blocks[`shadow_dropdown_${dropdownId}`]) {
65
- Blocks[`shadow_dropdown_${dropdownId}`] = {
64
+ if (!Blocks[`shadow_dropdown_${token}`]) {
65
+ Blocks[`shadow_dropdown_${token}`] = {
66
66
  layout: "DROPDOWN",
67
67
  fields: {
68
68
  DROPDOWN: {
@@ -81,14 +81,14 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
81
81
  };
82
82
  };
83
83
 
84
- valueInput.connection.setShadowDom(new DOMParser().parseFromString(`<shadow type="shadow_dropdown_${dropdownId}"></shadow>`, "text/xml").firstChild);
84
+ valueInput.connection.setShadowDom(new DOMParser().parseFromString(`<shadow type="shadow_dropdown_${escapeXml(token)}}"></shadow>`, "text/xml").firstChild);
85
85
  };
86
86
 
87
87
  if (input.variable) {
88
88
  if (typeof input.variable === "function") (input.variable = input.variable());
89
89
 
90
- if (!Blocks[`shadow_variable_${encodeURIComponent(color)}`]) {
91
- Blocks[`shadow_variable_${encodeURIComponent(color)}`] = {
90
+ if (!Blocks[`shadow_variable_${token}`]) {
91
+ Blocks[`shadow_variable_${token}`] = {
92
92
  layout: "VARIABLE",
93
93
  fields: {
94
94
  VARIABLE: {
@@ -105,13 +105,13 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
105
105
  };
106
106
  };
107
107
 
108
- valueInput.connection.setShadowDom(new DOMParser().parseFromString(`<shadow type="shadow_variable_${encodeURIComponent(color)}"><field name="VARIABLE">${input.variable}</field></shadow>`, "text/xml").firstChild);
108
+ valueInput.connection.setShadowDom(new DOMParser().parseFromString(`<shadow type="shadow_variable_${escapeXml(token)}"><field name="VARIABLE">${input.variable}</field></shadow>`, "text/xml").firstChild);
109
109
  };
110
110
 
111
111
  if (input.shadow) {
112
112
  if (typeof input.shadow === "function") (input.shadow = input.shadow());
113
113
 
114
- valueInput.connection.setShadowDom(new DOMParser().parseFromString(`<shadow type="shadow_${((typeof input.shadow.type === "function") ? input.shadow.type() : (input.shadow.type || "text")).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;")}">${(typeof input.shadow.content === "function") ? input.shadow.content() : (input.shadow.content || "")}</shadow>`, "text/xml").firstChild);
114
+ valueInput.connection.setShadowDom(new DOMParser().parseFromString(`<shadow type="shadow_${escapeXml((typeof input.shadow.type === "function") ? input.shadow.type() : (input.shadow.type || "text"))}">${(typeof input.shadow.content === "function") ? input.shadow.content() : (input.shadow.content || "")}</shadow>`, "text/xml").firstChild);
115
115
  };
116
116
  } else if (field) {
117
117
  const dummy = this.appendDummyInput();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blockly-fluid",
3
- "version": "1.2.17",
3
+ "version": "1.3.0",
4
4
  "description": "A flexible proxy wrapper for Blockly blocks.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,8 @@
1
+ module.exports = (string) => {
2
+ return string
3
+ .replace(/&/g, "&amp;")
4
+ .replace(/</g, "&lt;")
5
+ .replace(/>/g, "&gt;")
6
+ .replace(/"/g, "&quot;")
7
+ .replace(/'/g, "&apos;");
8
+ };