x-block-lib 0.11.10 → 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.
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";
@@ -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);
@@ -7892,7 +7895,7 @@ 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
  },
@@ -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,7 +7973,7 @@ 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
 
@@ -7986,7 +7991,7 @@ 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
  },
@@ -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,7 +8110,7 @@ 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
 
@@ -11924,11 +11943,23 @@ var clean_default = index_vue_vue_type_script_setup_true_lang_default$7;
11924
11943
 
11925
11944
  //#endregion
11926
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
+ }
11927
11961
  function loadFromJson(json, workspace) {
11928
- const root = workspace.newBlock("json_root_v1");
11929
- root.initSvg();
11930
- root.render();
11931
- const execNode = (node, parent) => {
11962
+ const execNode = (node, keys, parent) => {
11932
11963
  if (node === null) return;
11933
11964
  let type;
11934
11965
  if (node instanceof Array) type = "json_array_v1";
@@ -11944,47 +11975,91 @@ function loadFromJson(json, workspace) {
11944
11975
  target.initSvg();
11945
11976
  target.render();
11946
11977
  parent.connect(target.outputConnection);
11978
+ const m = getMeta(meta, keys);
11979
+ if (m) applyMeta(target, m);
11947
11980
  if (type === "json_map_v1") {
11948
- const keys = [];
11949
- for (const key in node) keys.push(key);
11950
- target.initData(keys);
11951
- for (let i = 0; i < keys.length; i++) {
11952
- 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];
11953
11985
  const input = target.getInput("ENTRY" + i);
11954
- execNode(node[key], input.connection);
11986
+ execNode(node[fieldKey], [...keys, fieldKey], input.connection);
11955
11987
  }
11956
11988
  } else if (type === "json_array_v1") {
11957
11989
  target.initData(node.length);
11958
- 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);
11959
11991
  } else if (type === "json_string_v1") target.setFieldValue(node, "VALUE");
11960
11992
  else if (type === "json_number_v1") target.setFieldValue(node, "VALUE");
11961
11993
  else if (type === "json_boolean_v1") target.setFieldValue(node ? "true" : "false", "VALUE");
11962
11994
  };
11963
- 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);
11964
12007
  Events.fire(new (Events.get(Events.FINISHED_LOADING))(workspace));
11965
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
+ }
11966
12031
  function saveToJson(workspace) {
11967
- const execNode = (block) => {
12032
+ const meta = {};
12033
+ const execNode = (block, keys) => {
11968
12034
  if (!block) return null;
11969
- 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"]);
11970
12038
  else if (block.type === "json_map_v1") {
11971
12039
  const values = {};
11972
12040
  for (let i = 0; i < block.length; i++) {
11973
12041
  const key = block.getFieldValue("KEY" + i);
11974
- values[key] = execNode(block.getInputTargetBlock("ENTRY" + i));
12042
+ values[key] = execNode(block.getInputTargetBlock("ENTRY" + i), [...keys, key]);
11975
12043
  }
11976
12044
  return values;
11977
12045
  } else if (block.type === "json_array_v1") {
11978
12046
  const values = [];
11979
- 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]));
11980
12048
  return values;
11981
12049
  } else if (block.type === "json_string_v1") return block.getFieldValue("VALUE");
11982
12050
  else if (block.type === "json_number_v1") return block.getFieldValue("VALUE");
11983
12051
  else if (block.type === "json_boolean_v1") return block.getFieldValue("VALUE") === "true";
11984
- else console.assert(false);
12052
+ else return null;
11985
12053
  };
11986
12054
  const blocks = workspace.getTopBlocks();
11987
- 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
+ }
11988
12063
  }
11989
12064
 
11990
12065
  //#endregion
@@ -12291,24 +12366,23 @@ var index_vue_vue_type_script_setup_true_lang_default$4 = /*@__PURE__*/ defineCo
12291
12366
  setup(__props, { expose: __expose }) {
12292
12367
  const open = useModel(__props, "modelValue");
12293
12368
  const context = injectContext();
12294
- const update = () => {
12369
+ function update() {
12295
12370
  if (!context.workspace) {
12296
12371
  console.assert(false);
12297
12372
  return;
12298
12373
  }
12299
- };
12374
+ }
12300
12375
  __expose({ update });
12301
- const onItemClick = (id) => {
12302
- const workspace = getMainWorkspace();
12303
- if (!workspace) {
12376
+ function onItemClick(id) {
12377
+ if (!context.workspace) {
12304
12378
  console.assert(false);
12305
12379
  return;
12306
12380
  }
12307
- const block = workspace.getBlockById(id);
12381
+ const block = context.workspace.getBlockById(id);
12308
12382
  common.setSelected(block);
12309
12383
  jumpTopBlock(id);
12310
12384
  open.value = false;
12311
- };
12385
+ }
12312
12386
  return (_ctx, _cache) => {
12313
12387
  return openBlock(), createElementBlock("div", { onClick: _cache[0] || (_cache[0] = ($event) => onItemClick("")) }, "blockTree");
12314
12388
  };
@@ -13533,7 +13607,7 @@ const jsonToolboxV1 = {
13533
13607
  contents: [{
13534
13608
  kind: "category",
13535
13609
  name: "%{BKY_CATEGORY_TYPE}",
13536
- colour: "330",
13610
+ categorystyle: "misc_category",
13537
13611
  contents: [
13538
13612
  {
13539
13613
  kind: "block",
@@ -13905,7 +13979,7 @@ var index_vue_vue_type_script_setup_true_lang_default$2 = /*@__PURE__*/ defineCo
13905
13979
  serialization.blocks.append(state, context.workspace);
13906
13980
  }
13907
13981
  function generateCode() {
13908
- if (__props.type === "json") console.assert(false);
13982
+ if (__props.type === "json") throw new Error(`no code in json`);
13909
13983
  else return javascriptGenerator.workspaceToCode(context.workspace);
13910
13984
  }
13911
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-block-lib",
3
- "version": "0.11.10",
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.4",
55
+ "x-runtime-lib": "^0.10.5",
56
56
  "x-state-lib": "^0.4.5"
57
57
  }
58
58
  }