x-block-lib 0.11.9 → 0.11.11

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.
@@ -308,6 +308,7 @@ var en_default = {
308
308
  CATEGORY_RESOURCE: "resource",
309
309
  CATEGORY_TEXT: "text",
310
310
  CATEGORY_TIME: "time",
311
+ CATEGORY_TYPE: "type",
311
312
  CATEGORY_VARIABLE: "var",
312
313
  LABEL_ARGUMENT: "Argument",
313
314
  LABEL_BOOLEAN: "Boolean",
package/dist/index.d.ts CHANGED
@@ -71,7 +71,7 @@ type __VLS_Props = {
71
71
  declare function load(state: any): void;
72
72
  declare function save(): any;
73
73
  declare function appendBlock(state: any): void;
74
- declare function generateCode(): string | undefined;
74
+ declare function generateCode(): string;
75
75
  declare function generateReactivity(): import("x-runtime-lib").Reactivity;
76
76
  declare function fireStateChange(): void;
77
77
  type __VLS_ModelProps = {
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function(){try{document.getElementById(`x-block-lib`)?.remove();const e = document.createElement(`style`);e.setAttribute(`id`, `x-block-lib`);const t = document.createTextNode(`.ghost[data-v-x-block-lib-ca7316a0]{opacity:.4;pointer-events:none}.blocklyToolbox{width:56px;overflow-x:hidden}.blocklyMainBackground{stroke-width:0}.blocklyToolboxCategory{margin-bottom:12px!important}.blocklyToolboxCategoryIcon{display:none!important}.blocklyTreeRowContentContainer{place-items:center;height:28px;display:flex;overflow:hidden}.blocklyFlyout{z-index:21}pre code.hljs{padding:1em;display:block;overflow-x:auto}code.hljs{padding:3px 5px}.hljs{color:#444;background:#f3f3f3}.hljs-comment{color:#697070}.hljs-punctuation,.hljs-tag{color:#444a}.hljs-tag .hljs-attr,.hljs-tag .hljs-name{color:#444}.hljs-attribute,.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-name,.hljs-selector-tag{font-weight:700}.hljs-deletion,.hljs-number,.hljs-quote,.hljs-selector-class,.hljs-selector-id,.hljs-string,.hljs-template-tag,.hljs-type{color:#800}.hljs-section,.hljs-title{color:#800;font-weight:700}.hljs-link,.hljs-operator,.hljs-regexp,.hljs-selector-attr,.hljs-selector-pseudo,.hljs-symbol,.hljs-template-variable,.hljs-variable{color:#ab5656}.hljs-literal{color:#695}.hljs-addition,.hljs-built_in,.hljs-bullet,.hljs-code{color:#397300}.hljs-meta{color:#1f7199}.hljs-meta .hljs-string{color:#38a}.hljs-emphasis{font-style:italic}.hljs-strong{font-weight:700}`);e.appendChild(t);document.head.appendChild(e);}catch(e){console.error('rolldown-plugin-inject-css', e);}})()
2
- import { A as Names, B as defineBlocksWithJsonArray, C as FieldCheckbox, D as FieldNumber, E as FieldLabel, F as Themes, G as inject$1, H as getMainWorkspace, I as Variables, J as serialization, K as inputs, L as WorkspaceSvg, M as ShortcutItems, N as ShortcutRegistry, O as FieldTextInput, P as Theme, R as Xml, S as Extensions, T as FieldImage, U as getSelected, V as dialog, W as icons, X as svgResize, Y as setLocale$1, Z as utils, _ as javascriptGenerator, a as lo, b as ContextMenuRegistry, c as encodeString, d as snakeCase, f as parseInt$1, g as Order, h as cloneDeep, i as require_dist$2, j as Procedures, k as Msg, l as require_dist, m as debounce, n as o, o as useResizeObserver, p as isEqual, q as registry, r as core_default, s as require_dist$1, t as javascript, u as upperCase, v as Blocks, w as FieldDropdown, x as Events, y as ContextMenu, z as common } from "./vendor.eb5jfwqa.js";
2
+ import { A as Names, B as constants, C as FieldCheckbox, D as FieldNumber, E as FieldLabel, F as Themes, G as icons, H as dialog, I as Variables, J as registry, K as inject$1, L as WorkspaceSvg, M as ShortcutItems, N as ShortcutRegistry, O as FieldTextInput, P as Theme, Q as utils, R as Xml, S as Extensions, T as FieldImage, U as getMainWorkspace, V as defineBlocksWithJsonArray, W as getSelected, X as setLocale$1, Y as serialization, Z as svgResize, _ as javascriptGenerator, a as lo, b as ContextMenuRegistry, c as encodeString, d as snakeCase, f as parseInt$1, g as Order, h as cloneDeep, i as require_dist$2, j as Procedures, k as Msg, l as require_dist, m as debounce, n as o, o as useResizeObserver, p as isEqual, q as inputs, r as core_default, s as require_dist$1, t as javascript, u as upperCase, v as Blocks, w as FieldDropdown, x as Events, y as ContextMenu, z as common } from "./vendor.lqnzhjrj.js";
3
3
  import { eventBus, globalObjects, messageWarning, openConfirmDlg, openPromptDlg, useColor, useSystem, useViewStack } from "x-essential-lib";
4
4
  import { globalState } from "x-state-lib";
5
5
  import { addIndent, finalProperties, getElement, getImplementMethodName, getItems, getTag, getTypes, makeEventId, makeEventKeyOfCustomSlot, makeEventKeyOfElementSlot, makeMethodId, makeMethodKeyOfCustomSlot, makeMethodKeyOfElementSlot, makePropertyId, makePropertyKeyOfCustomSlot, makePropertyKeyOfElementSlot, makeTriggerId, parseNumberUnit, pkgs, themeColors, toEventName, toMethodName, toPropertyName, unwrapEventId, unwrapEventKeyOfCustomSlot, unwrapEventKeyOfElementSlot, unwrapMethodId, unwrapMethodKeyOfCustomSlot, unwrapMethodKeyOfElementSlot, unwrapPropertyId, unwrapPropertyKeyOfCustomSlot, unwrapPropertyKeyOfElementSlot, unwrapSlotId } from "x-runtime-lib";
@@ -9,8 +9,8 @@ import { useDisplay } from "vuetify";
9
9
 
10
10
  //#region src/core/locale/index.ts
11
11
  async function setLocale(locale) {
12
- if (locale === "en") setLocale$1((await import("./en.e929s12a.js")).default);
13
- else if (locale === "zhHans") setLocale$1((await import("./zhHans.c7mba28i.js")).default);
12
+ if (locale === "en") setLocale$1((await import("./en.non7wgtb.js")).default);
13
+ else if (locale === "zhHans") setLocale$1((await import("./zhHans.er5jfqth.js")).default);
14
14
  else throw new Error(`invalid locale=${locale}`);
15
15
  }
16
16
  function localeMsg(key) {
@@ -457,7 +457,7 @@ function inWhiteList(type) {
457
457
 
458
458
  //#endregion
459
459
  //#region src/core/blocks/common/parameter/v1/index.ts
460
- const xmlUtils$11 = utils.xml;
460
+ const xmlUtils$12 = utils.xml;
461
461
  const PARAMETER_V1 = {
462
462
  init: function() {
463
463
  this.key = "";
@@ -468,7 +468,7 @@ const PARAMETER_V1 = {
468
468
  this.setColour(220);
469
469
  },
470
470
  mutationToDom: function() {
471
- const container = xmlUtils$11.createElement("mutation");
471
+ const container = xmlUtils$12.createElement("mutation");
472
472
  container.setAttribute("key", this.key);
473
473
  container.setAttribute("name", this.name);
474
474
  container.setAttribute("locale", this.locale ? "TRUE" : "FALSE");
@@ -597,6 +597,9 @@ function ensureParameterBlockV1s(scope, params) {
597
597
 
598
598
  //#endregion
599
599
  //#region src/core/utils/common/shadow.ts
600
+ function shadowOfJsonNullV1() {
601
+ return utils.xml.textToDom(`<shadow type="json_null_v1"></shadow>`);
602
+ }
600
603
  function shadowOfTextV1(value) {
601
604
  const text = `<shadow type="text_v1"><field name="TEXT">${value}</field></shadow>`;
602
605
  return utils.xml.textToDom(text);
@@ -2769,7 +2772,7 @@ javascriptGenerator.forBlock["app_bind_entry_v1"] = function() {
2769
2772
 
2770
2773
  //#endregion
2771
2774
  //#region src/core/blocks/app/event/appBind/v1/index.ts
2772
- const xmlUtils$10 = utils.xml;
2775
+ const xmlUtils$11 = utils.xml;
2773
2776
  const APP_BIND_CONTAINER_V1 = { init: function() {
2774
2777
  this.appendDummyInput().appendField("%{BKY_APP_V1_APP_BIND_CONTAINER_TITLE}");
2775
2778
  this.appendStatementInput("STACK");
@@ -2797,7 +2800,7 @@ const APP_BIND_V1 = {
2797
2800
  this.setHelpUrl("%{BKY_APP_V1_APP_BIND_HELPURL}");
2798
2801
  },
2799
2802
  mutationToDom: function() {
2800
- const container = xmlUtils$10.createElement("mutation");
2803
+ const container = xmlUtils$11.createElement("mutation");
2801
2804
  container.setAttribute("items", String(this.itemCount_));
2802
2805
  return container;
2803
2806
  },
@@ -7880,7 +7883,7 @@ ${javascriptGenerator.statementToCode(block, "HANDLE")}}
7880
7883
 
7881
7884
  //#endregion
7882
7885
  //#region src/core/blocks/json/jsonArray/v1/index.ts
7883
- const xmlUtils$9 = utils.xml;
7886
+ const xmlUtils$10 = utils.xml;
7884
7887
  const JSON_ARRAY_V1 = {
7885
7888
  init: function() {
7886
7889
  this.length = 0;
@@ -7892,12 +7895,12 @@ const JSON_ARRAY_V1 = {
7892
7895
  this.appendDummyInput("CLOSE_BRACKET").appendField(" ] ");
7893
7896
  this.setInputsInline(false);
7894
7897
  this.setOutput(true, "JsonArray");
7895
- this.setColour(350);
7898
+ this.setStyle("list_blocks");
7896
7899
  this.setTooltip("");
7897
7900
  this.setHelpUrl("");
7898
7901
  },
7899
7902
  mutationToDom: function() {
7900
- const container = xmlUtils$9.createElement("mutation");
7903
+ const container = xmlUtils$10.createElement("mutation");
7901
7904
  container.setAttribute("items", String(this.length));
7902
7905
  return container;
7903
7906
  },
@@ -7913,6 +7916,7 @@ const JSON_ARRAY_V1 = {
7913
7916
  for (let i = 0; i < this.length; i++) {
7914
7917
  const name = "ENTRY" + i;
7915
7918
  const input = this.appendValueInput(name);
7919
+ input.setShadowDom(shadowOfJsonNullV1());
7916
7920
  input.appendField(new FieldImage(plusImage, 20, 20, void 0, () => {
7917
7921
  if (this.isInFlyout) return;
7918
7922
  this.addEntry_(input);
@@ -7934,6 +7938,7 @@ const JSON_ARRAY_V1 = {
7934
7938
  input.fieldRow[1].setValue(i + 1);
7935
7939
  }
7936
7940
  const input = this.appendValueInput("ENTRY" + idx);
7941
+ input.setShadowDom(shadowOfJsonNullV1());
7937
7942
  input.appendField(new FieldImage(plusImage, 20, 20, void 0, () => {
7938
7943
  if (this.isInFlyout) return;
7939
7944
  this.addEntry_(input);
@@ -7968,13 +7973,13 @@ Blocks.json_array_v1 = JSON_ARRAY_V1;
7968
7973
  const JSON_BOOLEAN_V1 = { init: function() {
7969
7974
  this.appendDummyInput().appendField(new FieldDropdown([["false", "false"], ["true", "true"]]), "VALUE");
7970
7975
  this.setOutput(true, "JsonBoolean");
7971
- this.setColour(210);
7976
+ this.setStyle("logic_blocks");
7972
7977
  } };
7973
7978
  Blocks.json_boolean_v1 = JSON_BOOLEAN_V1;
7974
7979
 
7975
7980
  //#endregion
7976
7981
  //#region src/core/blocks/json/jsonMap/v1/index.ts
7977
- const xmlUtils$8 = utils.xml;
7982
+ const xmlUtils$9 = utils.xml;
7978
7983
  const JSON_MAP_V1 = {
7979
7984
  init: function() {
7980
7985
  this.length = 0;
@@ -7986,14 +7991,14 @@ const JSON_MAP_V1 = {
7986
7991
  this.appendDummyInput("CLOSE_BRACHET").appendField(" } ");
7987
7992
  this.setInputsInline(false);
7988
7993
  this.setOutput(true, "JsonMap");
7989
- this.setColour(120);
7994
+ this.setStyle("object_blocks");
7990
7995
  this.setTooltip("");
7991
7996
  this.setHelpUrl("");
7992
7997
  },
7993
7998
  mutationToDom: function() {
7994
- const container = xmlUtils$8.createElement("mutation");
7999
+ const container = xmlUtils$9.createElement("mutation");
7995
8000
  for (let i = 0; i < this.length; i++) {
7996
- const item = xmlUtils$8.createElement("item");
8001
+ const item = xmlUtils$9.createElement("item");
7997
8002
  item.setAttribute("key", this.getFieldValue("KEY" + i));
7998
8003
  container.appendChild(item);
7999
8004
  }
@@ -8017,6 +8022,7 @@ const JSON_MAP_V1 = {
8017
8022
  const key = keys[i];
8018
8023
  const name = "ENTRY" + i;
8019
8024
  const input = this.appendValueInput(name);
8025
+ input.setShadowDom(shadowOfJsonNullV1());
8020
8026
  input.appendField(new FieldImage(plusImage, 20, 20, void 0, () => {
8021
8027
  if (this.isInFlyout) return;
8022
8028
  this.addEntry_(input);
@@ -8037,6 +8043,7 @@ const JSON_MAP_V1 = {
8037
8043
  this.getInput("ENTRY" + i).name = "ENTRY" + (i + 1);
8038
8044
  }
8039
8045
  const input = this.appendValueInput("ENTRY" + idx);
8046
+ input.setShadowDom(shadowOfJsonNullV1());
8040
8047
  input.appendField(new FieldImage(plusImage, 20, 20, void 0, () => {
8041
8048
  if (this.isInFlyout) return;
8042
8049
  this.addEntry_(input);
@@ -8065,12 +8072,20 @@ const JSON_MAP_V1 = {
8065
8072
  };
8066
8073
  Blocks.json_map_v1 = JSON_MAP_V1;
8067
8074
 
8075
+ //#endregion
8076
+ //#region src/core/blocks/json/jsonNull/v1/index.ts
8077
+ const JSON_NULL_V1 = { init: function() {
8078
+ this.appendDummyInput().appendField("null");
8079
+ this.setOutput(true, "JsonNull");
8080
+ } };
8081
+ Blocks.json_null_v1 = JSON_NULL_V1;
8082
+
8068
8083
  //#endregion
8069
8084
  //#region src/core/blocks/json/jsonNumber/v1/index.ts
8070
8085
  const JSON_NUMBER_V1 = { init: function() {
8071
8086
  this.appendDummyInput().appendField(new FieldNumber(0), "VALUE");
8072
8087
  this.setOutput(true, "JsonNumber");
8073
- this.setColour(230);
8088
+ this.setStyle("math_blocks");
8074
8089
  } };
8075
8090
  Blocks.json_number_v1 = JSON_NUMBER_V1;
8076
8091
 
@@ -8078,9 +8093,13 @@ Blocks.json_number_v1 = JSON_NUMBER_V1;
8078
8093
  //#region src/core/blocks/json/jsonRoot/v1/index.ts
8079
8094
  const JSON_ROOT_V1 = { init: function() {
8080
8095
  this.appendDummyInput().setAlign(inputs.Align.CENTRE).appendField("JSON");
8081
- this.appendValueInput("JSON").setCheck(["JsonMap", "JsonArray"]);
8096
+ this.appendValueInput("JSON").setCheck([
8097
+ "JsonMap",
8098
+ "JsonArray",
8099
+ "JsonNull"
8100
+ ]).setShadowDom(shadowOfJsonNullV1());
8082
8101
  this.setDeletable(false);
8083
- this.setColour(250);
8102
+ this.setStyle("variable_blocks");
8084
8103
  this.setTooltip("");
8085
8104
  this.setHelpUrl("");
8086
8105
  } };
@@ -8091,13 +8110,13 @@ Blocks.json_root_v1 = JSON_ROOT_V1;
8091
8110
  const JSON_STRING_V1 = { init: function() {
8092
8111
  this.appendDummyInput().appendField("\"").appendField(new FieldTextInput(""), "VALUE").appendField("\"");
8093
8112
  this.setOutput(true, "JsonString");
8094
- this.setColour(160);
8113
+ this.setStyle("text_blocks");
8095
8114
  } };
8096
8115
  Blocks.json_string_v1 = JSON_STRING_V1;
8097
8116
 
8098
8117
  //#endregion
8099
8118
  //#region src/core/blocks/list/listCreate/v1/index.ts
8100
- const xmlUtils$7 = utils.xml;
8119
+ const xmlUtils$8 = utils.xml;
8101
8120
  const LIST_CREATE_CONTAINER_V1 = { init: function() {
8102
8121
  this.appendDummyInput().appendField("%{BKY_LIST_V1_CREATE_CONTAINER_TITLE}");
8103
8122
  this.appendStatementInput("STACK");
@@ -8124,7 +8143,7 @@ const LIST_CREATE_V1 = {
8124
8143
  this.updateShape_();
8125
8144
  },
8126
8145
  mutationToDom: function() {
8127
- const container = xmlUtils$7.createElement("mutation");
8146
+ const container = xmlUtils$8.createElement("mutation");
8128
8147
  container.setAttribute("items", String(this.itemCount_));
8129
8148
  return container;
8130
8149
  },
@@ -9738,7 +9757,7 @@ javascriptGenerator.forBlock["math_trig_v1"] = function(block) {
9738
9757
 
9739
9758
  //#endregion
9740
9759
  //#region src/core/blocks/object/objectCreate/v1/index.ts
9741
- const xmlUtils$6 = utils.xml;
9760
+ const xmlUtils$7 = utils.xml;
9742
9761
  const OBJECT_CREATE_CONTAINER_V1 = { init: function() {
9743
9762
  this.appendDummyInput().appendField("%{BKY_OBJECT_V1_CREATE_CONTAINER_TITLE}");
9744
9763
  this.appendStatementInput("STACK");
@@ -9765,7 +9784,7 @@ const OBJECT_CREATE_V1 = {
9765
9784
  this.setHelpUrl("%{BKY_OBJECT_V1_CREATE_HELPURL}");
9766
9785
  },
9767
9786
  mutationToDom: function() {
9768
- const container = xmlUtils$6.createElement("mutation");
9787
+ const container = xmlUtils$7.createElement("mutation");
9769
9788
  container.setAttribute("items", String(this.itemCount_));
9770
9789
  return container;
9771
9790
  },
@@ -10071,7 +10090,7 @@ javascriptGenerator.forBlock["object_to_json_v1"] = function(block) {
10071
10090
 
10072
10091
  //#endregion
10073
10092
  //#region src/core/blocks/procedure/procedureDef/v1/index.ts
10074
- const xmlUtils$5 = utils.xml;
10093
+ const xmlUtils$6 = utils.xml;
10075
10094
  const PROCEDURE_DEF_CONTAINER_V1 = { init: function() {
10076
10095
  this.appendDummyInput().appendField("%{BKY_PROCEDURE_V1_DEF_CONTAINER_TITLE}").appendField(new FieldCheckbox(false), "WITHRETURN");
10077
10096
  this.appendStatementInput("STACK");
@@ -10122,10 +10141,10 @@ const PROCEDURE_DEF_V1 = {
10122
10141
  this.setHelpUrl("%{BKY_PROCEDURE_V1_DEF_HELPURL}");
10123
10142
  },
10124
10143
  mutationToDom: function() {
10125
- const container = xmlUtils$5.createElement("mutation");
10144
+ const container = xmlUtils$6.createElement("mutation");
10126
10145
  container.setAttribute("withreturn", this.withReturn ? "TRUE" : "FALSE");
10127
10146
  this.args.forEach((arg) => {
10128
- const child = xmlUtils$5.createElement("arg");
10147
+ const child = xmlUtils$6.createElement("arg");
10129
10148
  child.setAttribute("name", arg.name);
10130
10149
  child.setAttribute("id", arg.id);
10131
10150
  container.appendChild(child);
@@ -10241,6 +10260,137 @@ const PROCEDURE_DEF_V1 = {
10241
10260
  };
10242
10261
  Blocks.procedure_def_v1 = PROCEDURE_DEF_V1;
10243
10262
 
10263
+ //#endregion
10264
+ //#region src/core/blocks/procedure/procedureCall/v1/index.ts
10265
+ const xmlUtils$5 = utils.xml;
10266
+ const PROCEDURE_CALL_V1 = {
10267
+ init: function() {
10268
+ this.withReturn = false;
10269
+ this.args = [];
10270
+ this.quarkIds_ = [];
10271
+ this.quarkConnections_ = {};
10272
+ this.appendDummyInput().appendField("", "NAME");
10273
+ this.setStyle("procedure_blocks");
10274
+ this.setTooltip("%{BKY_PROCEDURE_V1_CALL_TOOLTIP}");
10275
+ this.setHelpUrl("%{BKY_PROCEDURE_V1_CALL_HELPURL}");
10276
+ },
10277
+ mutationToDom: function() {
10278
+ const container = xmlUtils$5.createElement("mutation");
10279
+ container.setAttribute("name", this.getProcedureName_());
10280
+ container.setAttribute("withreturn", this.withReturn ? "TRUE" : "FALSE");
10281
+ this.args.forEach((arg) => {
10282
+ const child = xmlUtils$5.createElement("arg");
10283
+ child.setAttribute("name", arg);
10284
+ container.appendChild(child);
10285
+ });
10286
+ return container;
10287
+ },
10288
+ domToMutation: function(xmlElement) {
10289
+ const name = xmlElement.getAttribute("name") ?? "";
10290
+ const withReturn = xmlElement.getAttribute("withreturn") === "TRUE" ? true : false;
10291
+ const args = [];
10292
+ for (let i = 0, childNode; childNode = xmlElement.childNodes[i]; i++) if (childNode.nodeName.toLowerCase() === "arg") args.push(childNode.getAttribute("name"));
10293
+ this.setProcedureName_(name);
10294
+ this.setProcedureReturnArgs_(withReturn, [], []);
10295
+ },
10296
+ saveExtraState: function() {},
10297
+ loadExtraState: function() {},
10298
+ getProcedureName_: function() {
10299
+ return this.getFieldValue("NAME");
10300
+ },
10301
+ setProcedureName_: function(name) {
10302
+ this.setFieldValue(name, "NAME");
10303
+ },
10304
+ setProcedureReturnArgs_: function(withReturn, argNames, argIds) {
10305
+ if (argNames.length !== argIds.length) throw RangeError("argNames and argIds must be same length");
10306
+ this.withReturn = withReturn;
10307
+ const defBlock = Procedures.getDefinition(this.getProcedureName_(), this.workspace);
10308
+ const mutatorIcon = defBlock && defBlock.getIcon(icons.MutatorIcon.TYPE);
10309
+ const mutatorOpen = mutatorIcon && mutatorIcon.bubbleIsVisible();
10310
+ if (mutatorOpen) this.setCollapsed(false);
10311
+ else {
10312
+ this.quarkIds_ = [];
10313
+ this.quarkConnections_ = {};
10314
+ }
10315
+ if (argNames.join("\n") === this.args.join("\n")) {
10316
+ this.quarkIds_ = argIds;
10317
+ this.updateShape_();
10318
+ return;
10319
+ }
10320
+ for (let i = 0; i < this.args.length; i++) {
10321
+ const input = this.getInput("ARG" + i);
10322
+ if (input) {
10323
+ const connection = input.connection.targetConnection;
10324
+ this.quarkConnections_[this.quarkIds_[i]] = connection;
10325
+ if (connection && mutatorOpen && !argIds.includes(this.quarkIds_[i])) {
10326
+ connection.disconnect();
10327
+ connection.getSourceBlock().bumpNeighbours();
10328
+ }
10329
+ }
10330
+ }
10331
+ this.args = [...argNames];
10332
+ this.updateShape_();
10333
+ this.quarkIds_ = argIds;
10334
+ for (let i = 0; i < this.args.length; i++) {
10335
+ const quarkId = this.quarkIds_[i];
10336
+ if (quarkId in this.quarkConnections_) {
10337
+ if (!this.quarkConnections_[quarkId]?.reconnect(this, "ARG" + i)) delete this.quarkConnections_[quarkId];
10338
+ }
10339
+ }
10340
+ },
10341
+ onchange: function(event) {
10342
+ if (!this.workspace || this.workspace.isFlyout) return;
10343
+ if (event.type === Events.BLOCK_DELETE) {
10344
+ if (!Procedures.getDefinition(this.getProcedureName_(), this.workspace)) this.dispose();
10345
+ } else if (event.type === Events.BLOCK_CHANGE) {
10346
+ const changeEvent = event;
10347
+ if (!changeEvent.blockId) return;
10348
+ const block = this.workspace.getBlockById(changeEvent.blockId);
10349
+ if (!block) return;
10350
+ if (changeEvent.element === "field" && changeEvent.name === "NAME") {
10351
+ if (changeEvent.oldValue === this.getProcedureName_()) this.setProcedureName_(changeEvent.newValue);
10352
+ }
10353
+ const [name, args, withReturn] = block.getProcedureDef();
10354
+ if (name !== this.getProcedureName_()) return;
10355
+ if (changeEvent.element === "disabled") {
10356
+ Events.setGroup(changeEvent.group);
10357
+ this.setDisabledReason(!!changeEvent.newValue, "");
10358
+ Events.setGroup(false);
10359
+ }
10360
+ if (this.withReturn !== withReturn) {
10361
+ if (this.getParent()) this.unplug();
10362
+ }
10363
+ this.setProcedureReturnArgs_(withReturn, args, []);
10364
+ }
10365
+ },
10366
+ updateShape_: function() {
10367
+ if (this.withReturn) {
10368
+ this.setOutput(true);
10369
+ this.setPreviousStatement(false);
10370
+ this.setNextStatement(false);
10371
+ } else {
10372
+ this.setOutput(false);
10373
+ this.setPreviousStatement(true);
10374
+ this.setNextStatement(true);
10375
+ }
10376
+ for (let i = 0; i < this.args.length; i++) {
10377
+ const arg = this.args[i];
10378
+ if (this.getInput("ARG" + i)) try {
10379
+ Events.disable();
10380
+ this.setFieldValue(arg, "ARGNAME");
10381
+ } finally {
10382
+ Events.enable();
10383
+ }
10384
+ else this.appendValueInput("ARG" + i).setAlign(inputs.Align.RIGHT).appendField(new FieldLabel(arg), "ARGNAME" + i);
10385
+ }
10386
+ for (let i = this.args.length; this.getInput("ARG" + i); i++) this.removeInput("ARG" + i);
10387
+ }
10388
+ };
10389
+ Blocks.procedure_call_v1 = PROCEDURE_CALL_V1;
10390
+ javascriptGenerator.forBlock["procedure_call_v1"] = function() {
10391
+ return "";
10392
+ };
10393
+
10244
10394
  //#endregion
10245
10395
  //#region src/core/blocks/procedure/procedureReturn/v1/index.ts
10246
10396
  const xmlUtils$4 = utils.xml;
@@ -11793,11 +11943,23 @@ var clean_default = index_vue_vue_type_script_setup_true_lang_default$7;
11793
11943
 
11794
11944
  //#endregion
11795
11945
  //#region src/components/blockly/jsonHelper.ts
11946
+ function getMeta(root, keys) {
11947
+ let target = root;
11948
+ for (const key of [...keys, "__meta__"]) {
11949
+ if (!target || !target[key]) return;
11950
+ target = target[key];
11951
+ }
11952
+ return target;
11953
+ }
11954
+ function applyMeta(block, meta) {
11955
+ if (!meta) return;
11956
+ if (meta["comment"]) block.setCommentText(meta["comment"]);
11957
+ if (meta["inline"]) block.setInputsInline(true);
11958
+ if (meta["collapsed"]) block.setCollapsed(true);
11959
+ if (meta["disabled"]) block.setDisabledReason(true, constants.MANUALLY_DISABLED);
11960
+ }
11796
11961
  function loadFromJson(json, workspace) {
11797
- const root = workspace.newBlock("json_root_v1");
11798
- root.initSvg();
11799
- root.render();
11800
- const execNode = (node, parent) => {
11962
+ const execNode = (node, keys, parent) => {
11801
11963
  if (node === null) return;
11802
11964
  let type;
11803
11965
  if (node instanceof Array) type = "json_array_v1";
@@ -11813,47 +11975,91 @@ function loadFromJson(json, workspace) {
11813
11975
  target.initSvg();
11814
11976
  target.render();
11815
11977
  parent.connect(target.outputConnection);
11978
+ const m = getMeta(meta, keys);
11979
+ if (m) applyMeta(target, m);
11816
11980
  if (type === "json_map_v1") {
11817
- const keys = [];
11818
- for (const key in node) keys.push(key);
11819
- target.initData(keys);
11820
- for (let i = 0; i < keys.length; i++) {
11821
- const key = keys[i];
11981
+ const fieldKeys = Object.keys(node);
11982
+ target.initData(fieldKeys);
11983
+ for (let i = 0; i < fieldKeys.length; i++) {
11984
+ const fieldKey = fieldKeys[i];
11822
11985
  const input = target.getInput("ENTRY" + i);
11823
- execNode(node[key], input.connection);
11986
+ execNode(node[fieldKey], [...keys, fieldKey], input.connection);
11824
11987
  }
11825
11988
  } else if (type === "json_array_v1") {
11826
11989
  target.initData(node.length);
11827
- for (let i = 0; i < node.length; i++) execNode(node[i], target.getInput("ENTRY" + i).connection);
11990
+ for (let i = 0; i < node.length; i++) execNode(node[i], [...keys, i], target.getInput("ENTRY" + i).connection);
11828
11991
  } else if (type === "json_string_v1") target.setFieldValue(node, "VALUE");
11829
11992
  else if (type === "json_number_v1") target.setFieldValue(node, "VALUE");
11830
11993
  else if (type === "json_boolean_v1") target.setFieldValue(node ? "true" : "false", "VALUE");
11831
11994
  };
11832
- execNode(json, root.getInput("JSON").connection);
11995
+ let data;
11996
+ let meta;
11997
+ if (json.__data__ || json.__meta__) {
11998
+ data = json.__data__;
11999
+ meta = json.__meta__;
12000
+ } else data = json;
12001
+ const root = workspace.newBlock("json_root_v1");
12002
+ root.initSvg();
12003
+ root.render();
12004
+ const m = getMeta(meta, []);
12005
+ if (m) applyMeta(root, m);
12006
+ execNode(data, ["data"], root.getInput("JSON").connection);
11833
12007
  Events.fire(new (Events.get(Events.FINISHED_LOADING))(workspace));
11834
12008
  }
12009
+ function toMeta(block) {
12010
+ const meta = {};
12011
+ const comment = block.getCommentText();
12012
+ if (comment) meta["comment"] = comment;
12013
+ if (block.getInputsInline()) meta["inline"] = true;
12014
+ if (block.isCollapsed()) meta["collapsed"] = true;
12015
+ if (!block.isEnabled()) meta["disabled"] = true;
12016
+ block.isEnabled();
12017
+ if (Object.keys(meta).length > 0) return meta;
12018
+ else return null;
12019
+ }
12020
+ function mergeMeta(root, keys, meta) {
12021
+ let target = root;
12022
+ for (const key of [...keys, "__meta__"]) {
12023
+ if (!target[key]) target[key] = {};
12024
+ target = target[key];
12025
+ }
12026
+ if (meta["comment"]) target["comment"] = meta["comment"];
12027
+ if (meta["inline"]) target["inline"] = true;
12028
+ if (meta["collapsed"]) target["collapsed"] = true;
12029
+ if (meta["disabled"]) target["disabled"] = true;
12030
+ }
11835
12031
  function saveToJson(workspace) {
11836
- const execNode = (block) => {
12032
+ const meta = {};
12033
+ const execNode = (block, keys) => {
11837
12034
  if (!block) return null;
11838
- if (block.type === "json_root_v1") return execNode(block.getInputTargetBlock("JSON"));
12035
+ const m = toMeta(block);
12036
+ if (m) mergeMeta(meta, keys, m);
12037
+ if (block.type === "json_root_v1") return execNode(block.getInputTargetBlock("JSON"), ["data"]);
11839
12038
  else if (block.type === "json_map_v1") {
11840
12039
  const values = {};
11841
12040
  for (let i = 0; i < block.length; i++) {
11842
12041
  const key = block.getFieldValue("KEY" + i);
11843
- values[key] = execNode(block.getInputTargetBlock("ENTRY" + i));
12042
+ values[key] = execNode(block.getInputTargetBlock("ENTRY" + i), [...keys, key]);
11844
12043
  }
11845
12044
  return values;
11846
12045
  } else if (block.type === "json_array_v1") {
11847
12046
  const values = [];
11848
- for (let i = 0; i < block.length; i++) values.push(execNode(block.getInputTargetBlock("ENTRY" + i)));
12047
+ for (let i = 0; i < block.length; i++) values.push(execNode(block.getInputTargetBlock("ENTRY" + i), [...keys, i]));
11849
12048
  return values;
11850
12049
  } else if (block.type === "json_string_v1") return block.getFieldValue("VALUE");
11851
12050
  else if (block.type === "json_number_v1") return block.getFieldValue("VALUE");
11852
12051
  else if (block.type === "json_boolean_v1") return block.getFieldValue("VALUE") === "true";
11853
- else console.assert(false);
12052
+ else return null;
11854
12053
  };
11855
12054
  const blocks = workspace.getTopBlocks();
11856
- for (const block of blocks) if (block.type === "json_root_v1") return execNode(block);
12055
+ for (const block of blocks) if (block.type === "json_root_v1") {
12056
+ const data = execNode(block, []);
12057
+ if (Object.keys(meta).length > 0) return {
12058
+ __data__: data,
12059
+ __meta__: meta
12060
+ };
12061
+ else return data;
12062
+ }
11857
12063
  }
11858
12064
 
11859
12065
  //#endregion
@@ -12160,24 +12366,23 @@ var index_vue_vue_type_script_setup_true_lang_default$4 = /*@__PURE__*/ defineCo
12160
12366
  setup(__props, { expose: __expose }) {
12161
12367
  const open = useModel(__props, "modelValue");
12162
12368
  const context = injectContext();
12163
- const update = () => {
12369
+ function update() {
12164
12370
  if (!context.workspace) {
12165
12371
  console.assert(false);
12166
12372
  return;
12167
12373
  }
12168
- };
12374
+ }
12169
12375
  __expose({ update });
12170
- const onItemClick = (id) => {
12171
- const workspace = getMainWorkspace();
12172
- if (!workspace) {
12376
+ function onItemClick(id) {
12377
+ if (!context.workspace) {
12173
12378
  console.assert(false);
12174
12379
  return;
12175
12380
  }
12176
- const block = workspace.getBlockById(id);
12381
+ const block = context.workspace.getBlockById(id);
12177
12382
  common.setSelected(block);
12178
12383
  jumpTopBlock(id);
12179
12384
  open.value = false;
12180
- };
12385
+ }
12181
12386
  return (_ctx, _cache) => {
12182
12387
  return openBlock(), createElementBlock("div", { onClick: _cache[0] || (_cache[0] = ($event) => onItemClick("")) }, "blockTree");
12183
12388
  };
@@ -13401,8 +13606,8 @@ const jsonToolboxV1 = {
13401
13606
  kind: "categoryToolbox",
13402
13607
  contents: [{
13403
13608
  kind: "category",
13404
- name: "%{BKY_CATEGORY_JSON}",
13405
- colour: "330",
13609
+ name: "%{BKY_CATEGORY_TYPE}",
13610
+ categorystyle: "misc_category",
13406
13611
  contents: [
13407
13612
  {
13408
13613
  kind: "block",
@@ -13774,7 +13979,7 @@ var index_vue_vue_type_script_setup_true_lang_default$2 = /*@__PURE__*/ defineCo
13774
13979
  serialization.blocks.append(state, context.workspace);
13775
13980
  }
13776
13981
  function generateCode() {
13777
- if (__props.type === "json") console.assert(false);
13982
+ if (__props.type === "json") throw new Error(`no code in json`);
13778
13983
  else return javascriptGenerator.workspaceToCode(context.workspace);
13779
13984
  }
13780
13985
  function generateReactivity() {
@@ -36959,4 +36959,4 @@ function javascript(hljs) {
36959
36959
  }
36960
36960
 
36961
36961
  //#endregion
36962
- export { Names as A, defineBlocksWithJsonArray as B, FieldCheckbox as C, FieldNumber as D, FieldLabel as E, Themes as F, inject$1 as G, getMainWorkspace as H, Variables as I, serialization as J, inputs as K, WorkspaceSvg as L, ShortcutItems as M, ShortcutRegistry as N, FieldTextInput as O, Theme as P, Xml as R, Extensions as S, FieldImage as T, getSelected as U, dialog as V, icons as W, svgResize as X, setLocale as Y, utils as Z, javascriptGenerator as _, lo as a, ContextMenuRegistry as b, encodeString as c, snakeCase as d, parseInt$1 as f, Order as g, cloneDeep as h, require_dist as i, Procedures as j, Msg as k, require_dist$2 as l, debounce as m, o as n, useResizeObserver as o, isEqual as p, registry as q, core_default as r, require_dist$1 as s, javascript as t, upperCase as u, Blocks as v, FieldDropdown as w, Events as x, ContextMenu as y, common as z };
36962
+ export { Names as A, constants as B, FieldCheckbox as C, FieldNumber as D, FieldLabel as E, Themes as F, icons as G, dialog as H, Variables as I, registry as J, inject$1 as K, WorkspaceSvg as L, ShortcutItems as M, ShortcutRegistry as N, FieldTextInput as O, Theme as P, utils as Q, Xml as R, Extensions as S, FieldImage as T, getMainWorkspace as U, defineBlocksWithJsonArray as V, getSelected as W, setLocale as X, serialization as Y, svgResize as Z, javascriptGenerator as _, lo as a, ContextMenuRegistry as b, encodeString as c, snakeCase as d, parseInt$1 as f, Order as g, cloneDeep as h, require_dist as i, Procedures as j, Msg as k, require_dist$2 as l, debounce as m, o as n, useResizeObserver as o, isEqual as p, inputs as q, core_default as r, require_dist$1 as s, javascript as t, upperCase as u, Blocks as v, FieldDropdown as w, Events as x, ContextMenu as y, common as z };
@@ -308,6 +308,7 @@ var zhHans_default = {
308
308
  CATEGORY_RESOURCE: "资源",
309
309
  CATEGORY_TEXT: "文本",
310
310
  CATEGORY_TIME: "时间",
311
+ CATEGORY_TYPE: "类型",
311
312
  CATEGORY_VARIABLE: "变量",
312
313
  LABEL_ARGUMENT: "参数",
313
314
  LABEL_BOOLEAN: "布尔",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-block-lib",
3
- "version": "0.11.9",
3
+ "version": "0.11.11",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -52,7 +52,7 @@
52
52
  "vuetify": "^4.2.1",
53
53
  "x-error-lib": "^0.6.5",
54
54
  "x-essential-lib": "^0.10.40",
55
- "x-runtime-lib": "^0.10.3",
55
+ "x-runtime-lib": "^0.10.5",
56
56
  "x-state-lib": "^0.4.5"
57
57
  }
58
58
  }