x-block-lib 0.6.23 → 0.6.25

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.
@@ -0,0 +1,7 @@
1
+ import * as Blockly from 'blockly/core';
2
+ export declare function spawnTextBlockV1(workspace: Blockly.Workspace, value: string): Blockly.Block;
3
+ export declare function spawnMathNumberBlockV1(workspace: Blockly.Workspace, value: number): Blockly.Block;
4
+ export declare function spawnLogicBooleanBlockV1(workspace: Blockly.Workspace, value: boolean): Blockly.Block;
5
+ export declare function spawnItemsBlockV1(workspace: Blockly.Workspace, items: string): Blockly.Block;
6
+ export declare function spawnTypesBlockV1(workspace: Blockly.Workspace, types: string): Blockly.Block;
7
+ export declare function spawnSelectCompBlockV1(workspace: Blockly.Workspace): Blockly.Block;
@@ -1,16 +1,3 @@
1
- import * as Blockly from 'blockly/core';
2
- export declare function toBlockType(key: string): string;
3
- export declare function toCheck(key: string): string;
4
- export declare function ensureOpts(options: Blockly.MenuOption[]): Blockly.MenuOption[];
5
- export declare function genParamShadowV1(param: {
6
- type: 'string' | 'number' | 'boolean' | 'comp';
7
- default: unknown;
8
- }): Element;
9
- export declare function spawnParameterBlockV1(workspace: Blockly.Workspace, key: string, name: string, locale: boolean): Blockly.Block;
10
- export declare function ensureParameterBlockV1s(scope: Blockly.Block, params: [string, string, string, boolean][]): void;
11
- export declare function spawnTextBlockV1(workspace: Blockly.Workspace, value: string): Blockly.Block;
12
- export declare function spawnMathNumberBlockV1(workspace: Blockly.Workspace, value: number): Blockly.Block;
13
- export declare function spawnLogicBooleanBlockV1(workspace: Blockly.Workspace, value: boolean): Blockly.Block;
14
- export declare function spawnItemsBlockV1(workspace: Blockly.Workspace, items: string): Blockly.Block;
15
- export declare function spawnTypesBlockV1(workspace: Blockly.Workspace, types: string): Blockly.Block;
16
- export declare function spawnSelectCompBlockV1(workspace: Blockly.Workspace): Blockly.Block;
1
+ export * from './block';
2
+ export * from './misc';
3
+ export * from './parameter';
@@ -0,0 +1,8 @@
1
+ import * as Blockly from 'blockly/core';
2
+ export declare function toBlockType(key: string): string;
3
+ export declare function toCheck(key: string): string;
4
+ export declare function ensureOpts(options: Blockly.MenuOption[]): Blockly.MenuOption[];
5
+ export declare function genParamShadowV1(param: {
6
+ type: 'string' | 'number' | 'boolean' | 'comp';
7
+ default: unknown;
8
+ }): Element;
@@ -0,0 +1,3 @@
1
+ import * as Blockly from 'blockly/core';
2
+ export declare function spawnParameterBlockV1(workspace: Blockly.Workspace, key: string, name: string, locale: boolean): Blockly.Block;
3
+ export declare function ensureParameterBlockV1s(scope: Blockly.Block, params: [string, string, string, boolean][]): void;
package/dist/index.js CHANGED
@@ -1135,19 +1135,95 @@ function Te(e) {
1135
1135
  let t = "";
1136
1136
  if (e.type === "string") {
1137
1137
  let n = "";
1138
- typeof e.default == "string" && (n = e.default), t = `<shadow type="text_v1"><field name="TEXT">${n}</field></shadow>`;
1138
+ typeof e.default == "string" && (n = e.default), t = `
1139
+ <shadow type="text_v1">
1140
+ <field name="TEXT">
1141
+ ${n}
1142
+ </field>
1143
+ </shadow>
1144
+ `;
1139
1145
  } else if (e.type === "number") {
1140
1146
  let n = 0;
1141
- typeof e.default == "number" && (n = e.default), t = `<shadow type="math_number_v1"><field name="NUM">${n}</field></shadow>`;
1147
+ typeof e.default == "number" && (n = e.default), t = `
1148
+ <shadow type="math_number_v1">
1149
+ <field name="NUM">
1150
+ ${n}
1151
+ </field>
1152
+ </shadow>
1153
+ `;
1142
1154
  } else if (e.type === "boolean") {
1143
1155
  let n = "FALSE";
1144
- typeof e.default == "boolean" && (n = e.default ? "TRUE" : "FALSE"), t = `<shadow type="logic_boolean_v1"><field name="BOOL">${n}</field></shadow>`;
1145
- } else e.type === "comp" ? t = '<shadow type="select_comp_v1"></shadow>' : console.assert(!1, "invalid param type", e.type);
1156
+ typeof e.default == "boolean" && (n = e.default ? "TRUE" : "FALSE"), t = `
1157
+ <shadow type="logic_boolean_v1">
1158
+ <field name="BOOL">
1159
+ ${n}
1160
+ </field>
1161
+ </shadow>
1162
+ `;
1163
+ } else e.type === "comp" ? t = `
1164
+ <shadow type="select_comp_v1">
1165
+ </shadow>
1166
+ ` : console.assert(!1, "invalid param type", e.type);
1146
1167
  return W.xml.textToDom(t);
1147
1168
  }
1169
+ function kr(e, t) {
1170
+ const n = `
1171
+ <block type="text_v1">
1172
+ <field name="TEXT">
1173
+ ${t}
1174
+ </field>
1175
+ </block>
1176
+ `, o = W.xml.textToDom(n);
1177
+ return zt.domToBlock(o, e);
1178
+ }
1179
+ function Nr(e, t) {
1180
+ const n = `
1181
+ <block type="math_number_v1">
1182
+ <field name="NUM">
1183
+ ${t}
1184
+ </field>
1185
+ </block>
1186
+ `, o = W.xml.textToDom(n);
1187
+ return zt.domToBlock(o, e);
1188
+ }
1189
+ function Sr(e, t) {
1190
+ const o = `
1191
+ <block type="logic_boolean_v1">
1192
+ <field name="BOOL">
1193
+ ${t ? "TRUE" : "FALSE"}
1194
+ </field>
1195
+ </block>
1196
+ `, i = W.xml.textToDom(o);
1197
+ return zt.domToBlock(i, e);
1198
+ }
1199
+ function Lr(e, t) {
1200
+ const o = `
1201
+ <block type="${jo(t)}">
1202
+ </block>
1203
+ `, i = W.xml.textToDom(o);
1204
+ return zt.domToBlock(i, e);
1205
+ }
1206
+ function Br(e, t) {
1207
+ const o = `
1208
+ <block type="${jo(t)}">
1209
+ </block>
1210
+ `, i = W.xml.textToDom(o);
1211
+ return zt.domToBlock(i, e);
1212
+ }
1213
+ function Rr(e) {
1214
+ const n = W.xml.textToDom(`
1215
+ <block type="select_comp_v1">
1216
+ </block>
1217
+ `);
1218
+ return zt.domToBlock(n, e);
1219
+ }
1148
1220
  function rs(e, t, n, o) {
1149
- const i = `<xml><block type="parameter_v1"><mutation key="${t}" name="${n}" locale="${o ? "TRUE" : "FALSE"}"/></block></xml>`, s = W.xml.textToDom(i), a = zt.domToWorkspace(s, e);
1150
- return e.getBlockById(a[0]);
1221
+ const i = `
1222
+ <block type="parameter_v1">
1223
+ <mutation key="${t}" name="${n}" locale="${o ? "TRUE" : "FALSE"}"/>
1224
+ </block>
1225
+ `, s = W.xml.textToDom(i);
1226
+ return zt.domToBlock(s, e);
1151
1227
  }
1152
1228
  function je(e, t) {
1153
1229
  try {
@@ -1174,30 +1250,6 @@ function je(e, t) {
1174
1250
  x.enable();
1175
1251
  }
1176
1252
  }
1177
- function kr(e, t) {
1178
- const n = `<block type="text_v1"><field name="TEXT">${t}</field></block>`, o = W.xml.textToDom(n);
1179
- return zt.domToBlock(o, e);
1180
- }
1181
- function Nr(e, t) {
1182
- const n = `<block type="math_number_v1"><field name="NUM">${t}</field></block>`, o = W.xml.textToDom(n);
1183
- return zt.domToBlock(o, e);
1184
- }
1185
- function Sr(e, t) {
1186
- const o = `<block type="logic_boolean_v1"><field name="BOOL">${t ? "TRUE" : "FALSE"}</field></block>`, i = W.xml.textToDom(o);
1187
- return zt.domToBlock(i, e);
1188
- }
1189
- function Lr(e, t) {
1190
- const o = `<block type="${jo(t)}"></block>`, i = W.xml.textToDom(o);
1191
- return zt.domToBlock(i, e);
1192
- }
1193
- function Br(e, t) {
1194
- const o = `<block type="${jo(t)}"></block>`, i = W.xml.textToDom(o);
1195
- return zt.domToBlock(i, e);
1196
- }
1197
- function Rr(e) {
1198
- const n = W.xml.textToDom('<block type="select_comp_v1"></block>');
1199
- return zt.domToBlock(n, e);
1200
- }
1201
1253
  function Xn(e) {
1202
1254
  const { version: t } = L.app.activeObject;
1203
1255
  if (!Fn[t])
@@ -1954,38 +2006,41 @@ const zh = (e, t) => {
1954
2006
  const i = this.getInput("DUMMY");
1955
2007
  if (!i)
1956
2008
  return;
1957
- const s = t.find((l) => l.validator(this.value));
1958
- if (!s)
2009
+ let s = this.value;
2010
+ s || (s = void 0);
2011
+ const a = t.find((d) => d.validator(s));
2012
+ if (!a)
1959
2013
  return;
1960
2014
  i.removeField("VALUE", !0), i.removeField("SUFFIX", !0);
1961
- let a, c;
1962
- if (s.ui === "pixelInput") {
1963
- const l = Bc(this.value) ?? 0;
1964
- a = new Rs(
1965
- l,
1966
- s.min,
1967
- s.max,
1968
- 1 / Math.pow(10, s.precision ?? 15),
1969
- (d) => {
1970
- this.value = d + "px";
2015
+ let c, l;
2016
+ if (a.ui === "pixelInput") {
2017
+ const d = Bc(this.value) ?? 0;
2018
+ c = new Rs(
2019
+ d,
2020
+ a.min,
2021
+ a.max,
2022
+ a.precision ? 1 / Math.pow(10, a.precision) : null,
2023
+ (_) => {
2024
+ this.value = _ + "px";
1971
2025
  }
1972
- ), c = "px";
1973
- } else if (s.ui === "percentInput") {
1974
- const l = Rc(this.value) ?? 0;
1975
- a = new Rs(
1976
- l,
1977
- s.min,
1978
- s.max,
1979
- s.precision ? 1 / Math.pow(10, s.precision) : null,
1980
- (d) => {
1981
- this.value = d + "%";
2026
+ ), l = "px";
2027
+ } else if (a.ui === "percentInput") {
2028
+ const d = Rc(this.value) ?? 0;
2029
+ c = new Rs(
2030
+ d,
2031
+ a.min,
2032
+ a.max,
2033
+ a.precision ? 1 / Math.pow(10, a.precision) : null,
2034
+ (_) => {
2035
+ this.value = _ + "%";
1982
2036
  }
1983
- ), c = "%";
2037
+ ), l = "%";
1984
2038
  }
1985
- a && i.appendField(a, "VALUE"), c && i.appendField(c, "SUFFIX");
2039
+ c && i.appendField(c, "VALUE"), l && i.appendField(l, "SUFFIX");
1986
2040
  },
1987
2041
  checkWarning_: function() {
1988
- if (!t.find((s) => s.validator(this.value))) {
2042
+ let i = this.value;
2043
+ if (i || (i = void 0), !t.find((a) => a.validator(i))) {
1989
2044
  this.setWarningText(m.WARN_TYPE_NOT_AVAILABLE);
1990
2045
  return;
1991
2046
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "x-block-lib",
3
3
  "private": false,
4
- "version": "0.6.23",
4
+ "version": "0.6.25",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",