blockly-fluid 1.3.11 → 1.3.13

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
@@ -264,16 +264,16 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
264
264
  };
265
265
 
266
266
  languageGenerator.forBlock[name] = (block) => (((code) => {
267
- if (!output) return code;
267
+ if (!output) return dedent(code);
268
268
 
269
269
  return (Array.isArray(code)) ? [
270
- (code[1]?.toLowerCase() !== "nugget") ? code[0] : `await (async () => {\n${code[0].split("\n").map((line) => " " + line).join("\n")}\n})()`,
270
+ (code[1]?.toLowerCase() !== "nugget") ? dedent(code[0]) : `await (async () => {\n${dedent(code[0]).split("\n").map((line) => " " + line).join("\n")}\n})()`,
271
271
  languageGenerator[`ORDER_${(code[1]?.toLowerCase().replaceAll("nugget", "") || "NONE").toUpperCase()}`]
272
272
  ] : [
273
- code,
273
+ dedent(code),
274
274
  languageGenerator.ORDER_NONE
275
275
  ];
276
- })(dedent((typeof blockGenerator === "function") ? blockGenerator(...[
276
+ })((typeof blockGenerator === "function") ? blockGenerator(...[
277
277
  ...((values) => {
278
278
  if (!Object.keys(values).length) return [];
279
279
 
@@ -297,7 +297,7 @@ module.exports = (Blockly, { generator: languageGeneratorFallback, generators: l
297
297
  } : {}
298
298
  }), {}),
299
299
  }), languageGenerator
300
- ]) : blockGenerator)));
300
+ ]) : blockGenerator));
301
301
  });
302
302
 
303
303
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blockly-fluid",
3
- "version": "1.3.11",
3
+ "version": "1.3.13",
4
4
  "description": "A flexible proxy wrapper for Blockly blocks.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils/dedent.js CHANGED
@@ -1,15 +1,24 @@
1
- module.exports = (strings, ...values) => {
2
- let text = String.raw({ raw: strings }, ...values);
1
+ module.exports = (text) => {
2
+ const lines = text.split("\n");
3
3
 
4
- text = text.replace(/^\n/, "").replace(/\n$/, "");
4
+ const firstLine = lines.find((line) => line.trim().length > 0);
5
5
 
6
- const indent = text.match(/^[ \t]*(?=\S)/gm);
6
+ if (!firstLine) return text;
7
7
 
8
- if (indent) {
9
- const minimumIndent = Math.min(...indent.map(i => i.length));
8
+ const indentMatch = firstLine.match(/^[ \t]*/);
9
+ const indentSize = (indentMatch) ? indentMatch[0].length : 0;
10
10
 
11
- text = text.replace(new RegExp(`^[ \\t]{${minimumIndent}}`, "gm"), "");
12
- };
11
+ if (indentSize === 0) return text;
13
12
 
14
- return text;
13
+ return (
14
+ lines
15
+ .map((line) => (
16
+ (line.startsWith(" ".repeat(indentSize)))
17
+ ? line.slice(indentSize)
18
+ : line
19
+ ))
20
+ .join("\n")
21
+ .replace(/^\n/, "")
22
+ .replace(/\n\s*$/, "")
23
+ );
15
24
  };