x-block-lib 0.2.0 → 0.2.2

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.js CHANGED
@@ -1,57 +1,472 @@
1
- import { getCurrentInstance as b, inject as m, defineComponent as h, ref as C, onMounted as k, nextTick as T, onBeforeUnmount as _, watch as d, openBlock as v, createElementBlock as R, withDirectives as K, createElementVNode as M } from "vue";
2
- import { openConfirmDlg as P, openPromptDlg as w, useViewStack as x } from "x-essential-lib";
1
+ (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".blocklyToolboxDiv{overflow-x:hidden;width:56px}")),document.head.appendChild(e)}}catch(d){console.error("vite-plugin-css-injected-by-js",d)}})();
2
+ import { getCurrentInstance as b, inject as d, defineComponent as m, ref as C, onMounted as k, nextTick as S, onBeforeUnmount as T, watch as y, openBlock as L, createElementBlock as E, withDirectives as I, createElementVNode as v } from "vue";
3
+ import { openConfirmDlg as B, openPromptDlg as R, useViewStack as x } from "x-essential-lib";
3
4
  import * as e from "blockly/core";
4
- function B(r, t) {
5
- const o = b();
6
- if (!o)
7
- throw new Error(`[Vuetify] ${r} must be called from inside a setup function`);
8
- return o;
5
+ import { javascriptGenerator as P, Order as w } from "blockly/javascript";
6
+ function F(o, t) {
7
+ const n = b();
8
+ if (!n)
9
+ throw new Error(`[Vuetify] ${o} must be called from inside a setup function`);
10
+ return n;
9
11
  }
10
- const O = Symbol.for("vuetify:locale");
11
- function z() {
12
- const r = m(O);
13
- if (!r)
12
+ const M = Symbol.for("vuetify:locale");
13
+ function K() {
14
+ const o = d(M);
15
+ if (!o)
14
16
  throw new Error("[Vuetify] Could not find injected locale instance");
15
- return r;
17
+ return o;
16
18
  }
17
- const E = Symbol.for("vuetify:theme");
18
- function I() {
19
- B("useTheme");
20
- const r = m(E, null);
21
- if (!r)
19
+ const A = Symbol.for("vuetify:theme");
20
+ function D() {
21
+ F("useTheme");
22
+ const o = d(A, null);
23
+ if (!o)
22
24
  throw new Error("Could not find Vuetify theme injection");
23
- return r;
25
+ return o;
24
26
  }
25
- e.dialog.setConfirm(async (r, t) => {
26
- const o = await P({
27
+ e.defineBlocksWithJsonArray([
28
+ {
29
+ type: "boolean_v1",
30
+ message0: "%1",
31
+ args0: [
32
+ {
33
+ type: "field_dropdown",
34
+ name: "BOOL",
35
+ options: [
36
+ ["%{BKY_LOGIC_BOOLEAN_FALSE}", "FALSE"],
37
+ ["%{BKY_LOGIC_BOOLEAN_TRUE}", "TRUE"]
38
+ ]
39
+ }
40
+ ],
41
+ output: "Boolean",
42
+ style: "logic_blocks",
43
+ tooltip: "%{BKY_LOGIC_V1_BOOLEAN_TOOLTIP}",
44
+ helpUrl: "%{BKY_LOGIC_V1_BOOLEAN_HELPURL}"
45
+ }
46
+ ]);
47
+ P.forBlock.boolean_v1 = function(o) {
48
+ return [o.getFieldValue("BOOL") === "TRUE" ? "true" : "false", w.ATOMIC];
49
+ };
50
+ const N = {
51
+ elseIfCount_: 0,
52
+ hasElse_: !1,
53
+ mutationToDom: function() {
54
+ if (this.elseIfCount_ <= 0 && !this.hasElse_)
55
+ return null;
56
+ const o = e.utils.xml.createElement("mutation");
57
+ return this.elseIfCount_ > 0 && o.setAttribute("elseIf", String(this.elseIfCount_)), this.hasElse_ && o.setAttribute("else", "TRUE"), o;
58
+ },
59
+ domToMutation: function(o) {
60
+ this.elseIfCount_ = parseInt(o.getAttribute("elseif"), 10) || 0, this.hasElse_ = o.getAttribute("else") === "TRUE", this.rebuildShape_();
61
+ },
62
+ saveExtraState: function() {
63
+ if (this.elseIfCount_ <= 0 && !this.hasElse_)
64
+ return null;
65
+ const o = /* @__PURE__ */ Object.create(null);
66
+ return this.elseIfCount_ > 0 && (o.elseIfCount = this.elseIfCount_), this.hasElse_ && (o.hasElse = !0), o;
67
+ },
68
+ loadExtraState: function(o) {
69
+ this.elseIfCount_ = o.elseIfCount || 0, this.hasElse_ = !!o.hasElse, this.updateShape_();
70
+ },
71
+ decompose: function(o) {
72
+ const t = o.newBlock("if_if_v1");
73
+ t.initSvg();
74
+ let n = t.nextConnection;
75
+ for (let r = 0; r < this.elseIfCount_; r++) {
76
+ const s = o.newBlock(
77
+ "if_else_if_v1"
78
+ );
79
+ s.initSvg(), n.connect(s.previousConnection), n = s.nextConnection;
80
+ }
81
+ if (this.hasElse_) {
82
+ const r = o.newBlock("if_else_v1");
83
+ r.initSvg(), n.connect(r.previousConnection);
84
+ }
85
+ return t;
86
+ },
87
+ compose: function(o) {
88
+ let t = o.nextConnection.targetBlock();
89
+ this.elseIfCount_ = 0, this.hasElse_ = !1;
90
+ const n = [null], r = [null];
91
+ let s = null;
92
+ for (; t; ) {
93
+ if (t.isInsertionMarker()) {
94
+ t = t.getNextBlock();
95
+ continue;
96
+ }
97
+ switch (t.type) {
98
+ case "if_else_if_v1":
99
+ this.elseIfCount_++, n.push(
100
+ t.valueConnection_
101
+ ), r.push(
102
+ t.statementConnection_
103
+ );
104
+ break;
105
+ case "if_else_v1":
106
+ this.hasElse_ = !0, s = t.statementConnection_;
107
+ break;
108
+ default:
109
+ throw TypeError("Unknown block type: " + t.type);
110
+ }
111
+ t = t.getNextBlock();
112
+ }
113
+ this.updateShape_(), this.reconnectChildBlocks_(
114
+ n,
115
+ r,
116
+ s
117
+ );
118
+ },
119
+ saveConnections: function(o) {
120
+ let t = o.nextConnection.targetBlock(), n = 1;
121
+ for (; t; ) {
122
+ if (t.isInsertionMarker()) {
123
+ t = t.getNextBlock();
124
+ continue;
125
+ }
126
+ switch (t.type) {
127
+ case "if_else_if_v1": {
128
+ const r = this.getInput("IF" + n), s = this.getInput("DO" + n);
129
+ t.valueConnection_ = r && r.connection.targetConnection, t.statementConnection_ = s && s.connection.targetConnection, n++;
130
+ break;
131
+ }
132
+ case "if_else_v1": {
133
+ const r = this.getInput("ELSE");
134
+ t.statementConnection_ = r && r.connection.targetConnection;
135
+ break;
136
+ }
137
+ default:
138
+ throw TypeError("Unknown block type: " + t.type);
139
+ }
140
+ t = t.getNextBlock();
141
+ }
142
+ },
143
+ rebuildShape_: function() {
144
+ const o = [null], t = [null];
145
+ let n = null;
146
+ this.getInput("ELSE") && (n = this.getInput("ELSE").connection.targetConnection);
147
+ for (let r = 1; this.getInput("IF" + r); r++) {
148
+ const s = this.getInput("IF" + r), i = this.getInput("DO" + r);
149
+ o.push(s.connection.targetConnection), t.push(i.connection.targetConnection);
150
+ }
151
+ this.updateShape_(), this.reconnectChildBlocks_(
152
+ o,
153
+ t,
154
+ n
155
+ );
156
+ },
157
+ updateShape_: function() {
158
+ this.getInput("ELSE") && this.removeInput("ELSE");
159
+ for (let o = 1; this.getInput("IF" + o); o++)
160
+ this.removeInput("IF" + o), this.removeInput("DO" + o);
161
+ for (let o = 1; o <= this.elseIfCount_; o++)
162
+ this.appendValueInput("IF" + o).setCheck("Boolean").appendField(e.Msg.LOGIC_ELSE_IF), this.appendStatementInput("DO" + o).appendField(e.Msg.LOGIC_DO);
163
+ this.hasElse_ && this.appendStatementInput("ELSE").appendField(e.Msg.LOGIC_ELSE);
164
+ },
165
+ reconnectChildBlocks_: function(o, t, n) {
166
+ var r, s;
167
+ for (let i = 1; i <= this.elseIfCount_; i++)
168
+ (r = o[i]) == null || r.reconnect(this, "IF" + i), (s = t[i]) == null || s.reconnect(this, "DO" + i);
169
+ n == null || n.reconnect(this, "ELSE");
170
+ }
171
+ };
172
+ e.Extensions.registerMutator(
173
+ "if_v1_mutator",
174
+ N,
175
+ void 0,
176
+ ["if_else_if_v1", "if_else_v1"]
177
+ );
178
+ e.defineBlocksWithJsonArray([
179
+ {
180
+ type: "if_v1",
181
+ message0: "%{BKY_LOGIC_IF} %1",
182
+ args0: [
183
+ {
184
+ type: "input_value",
185
+ name: "IF0",
186
+ check: "Boolean"
187
+ }
188
+ ],
189
+ message1: "%{BKY_LOGIC_DO} %1",
190
+ args1: [
191
+ {
192
+ type: "input_statement",
193
+ name: "DO0"
194
+ }
195
+ ],
196
+ previousStatement: null,
197
+ nextStatement: null,
198
+ style: "logic_blocks",
199
+ helpUrl: "%{BKY_LOGIC_V1_IF_HELPURL",
200
+ suppressPrefixSuffix: !0,
201
+ mutator: "if_v1_mutator"
202
+ },
203
+ {
204
+ type: "if_if_v1",
205
+ message0: "%{BKY_LOGIC_IF}",
206
+ nextStatement: null,
207
+ enableContextMenu: !1,
208
+ style: "logic_blocks"
209
+ },
210
+ {
211
+ type: "if_else_if_v1",
212
+ message0: "%{BKY_LOGIC_ELSE_IF}",
213
+ previousStatement: null,
214
+ nextStatement: null,
215
+ enableContextMenu: !1,
216
+ style: "logic_blocks"
217
+ },
218
+ {
219
+ type: "if_else_v1",
220
+ message0: "%{BKY_LOGIC_ELSE}",
221
+ previousStatement: null,
222
+ enableContextMenu: !1,
223
+ style: "logic_blocks"
224
+ }
225
+ ]);
226
+ const V = {
227
+ customContextMenu: function(o) {
228
+ if (this.isInFlyout)
229
+ return;
230
+ const t = this.getField("VAR"), n = t.getVariable(), r = n == null ? void 0 : n.name;
231
+ if (!this.isCollapsed() && r) {
232
+ const s = {
233
+ type: "variables_get",
234
+ fields: {
235
+ VAR: t.saveState(!0)
236
+ }
237
+ };
238
+ o.push({
239
+ enabled: !0,
240
+ text: e.Msg.VARIABLES_SET_CREATE_GET.replace("%1", r),
241
+ callback: e.ContextMenu.callbackFactory(this, s)
242
+ });
243
+ }
244
+ }
245
+ };
246
+ e.Extensions.registerMixin(
247
+ "contextMenu_newGetVariableBlock_v1",
248
+ V
249
+ );
250
+ e.Extensions.register(
251
+ "flow_control_tooltip_v1",
252
+ e.Extensions.buildTooltipForDropdown("MODE", {
253
+ BREAK: "%{BKY_LOOP_V1_FLOW_CONTROL_TOOLTIP_BREAK}",
254
+ CONTINUE: "%{BKY_LOOP_V1_FLOW_CONTROL_TOOLTIP_CONTINUE}"
255
+ })
256
+ );
257
+ const U = /* @__PURE__ */ new Set([
258
+ "repeat_v1",
259
+ "for_each_v1",
260
+ "for_v1",
261
+ "while_until_v1"
262
+ ]), Y = {
263
+ getSurroundLoop: function() {
264
+ let o = this;
265
+ do {
266
+ if (U.has(o.type))
267
+ return !0;
268
+ o = o == null ? void 0 : o.getSurroundParent();
269
+ } while (o);
270
+ return !1;
271
+ },
272
+ onchange: function(o) {
273
+ const t = this.workspace;
274
+ if (!t.isDragging || t.isDragging() || o.type !== e.Events.BLOCK_MOVE && o.type !== e.Events.BLOCK_CREATE)
275
+ return;
276
+ const n = this.getSurroundLoop();
277
+ if (console.log(o.type, n), this.setWarningText(
278
+ n ? null : e.Msg.LOOP_FLOW_CONTROL_WARNING
279
+ ), !this.isInFlyout)
280
+ try {
281
+ e.Events.setRecordUndo(!1), this.setDisabledReason(!n, "FLOW_CONTROL_NOT_IN_LOOP");
282
+ } finally {
283
+ e.Events.setRecordUndo(!0);
284
+ }
285
+ }
286
+ };
287
+ e.Extensions.registerMixin(
288
+ "flow_control_in_loop_check_v1",
289
+ Y
290
+ );
291
+ e.defineBlocksWithJsonArray([
292
+ {
293
+ type: "flow_control_v1",
294
+ message0: "%1",
295
+ args0: [
296
+ {
297
+ type: "field_dropdown",
298
+ name: "MODE",
299
+ options: [
300
+ ["%{BKY_LOOP_V1_FLOW_CONTROL_OPERATOR_BREAK}", "BREAK"],
301
+ ["%{BKY_LOOP_V1_FLOW_CONTROL_OPERATOR_CONTINUE}", "CONTINUE"]
302
+ ]
303
+ }
304
+ ],
305
+ previousStatement: null,
306
+ style: "loop_blocks",
307
+ helpurl: "%{BKY_LOOP_V1_FLOW_CONTROL_HELPURL}",
308
+ suppressPrefixSuffix: !0,
309
+ extensions: ["flow_control_tooltip_v1", "flow_control_in_loop_check_v1"]
310
+ }
311
+ ]);
312
+ e.Extensions.register(
313
+ "for_tooltip_v1",
314
+ e.Extensions.buildTooltipWithFieldText(
315
+ "%{BKY_LOOP_V1_FOR_TOOLTIP}",
316
+ "VAR"
317
+ )
318
+ );
319
+ e.defineBlocksWithJsonArray([
320
+ {
321
+ type: "for_v1",
322
+ message0: "%{BKY_LOOP_V1_FOR_TITLE}",
323
+ args0: [
324
+ {
325
+ type: "field_variable",
326
+ name: "VAR",
327
+ variable: null
328
+ },
329
+ {
330
+ type: "input_value",
331
+ name: "FROM",
332
+ check: "Number",
333
+ align: "RIGHT"
334
+ },
335
+ {
336
+ type: "input_value",
337
+ name: "TO",
338
+ check: "Number",
339
+ align: "RIGHT"
340
+ },
341
+ {
342
+ type: "input_value",
343
+ name: "BY",
344
+ check: "Number",
345
+ align: "RIGHT"
346
+ }
347
+ ],
348
+ message1: "%{BKY_LOOP_DO} %1",
349
+ args1: [
350
+ {
351
+ type: "input_statement",
352
+ name: "DO"
353
+ }
354
+ ],
355
+ inputsInline: !0,
356
+ previousStatement: null,
357
+ nextStatement: null,
358
+ style: "loop_blocks",
359
+ helpUrl: "%{BKY_LOOP_V1_FOR_HELPURL}",
360
+ extensions: ["contextMenu_newGetVariableBlock_v1", "for_tooltip_v1"]
361
+ }
362
+ ]);
363
+ e.Extensions.register(
364
+ "for_each_tooltip_v1",
365
+ e.Extensions.buildTooltipWithFieldText(
366
+ "%{BKY_LOOP_V1_FOR_EACH_TOOLTIP}",
367
+ "VAR"
368
+ )
369
+ );
370
+ e.defineBlocksWithJsonArray([
371
+ {
372
+ type: "for_each_v1",
373
+ message0: "%{BKY_LOOP_V1_FOR_EACH_TITLE}",
374
+ args0: [
375
+ {
376
+ type: "field_variable",
377
+ name: "VAR",
378
+ variable: null
379
+ },
380
+ {
381
+ type: "input_value",
382
+ name: "LIST",
383
+ check: "Array"
384
+ }
385
+ ],
386
+ message1: "%{BKY_LOOP_DO} %1",
387
+ args1: [
388
+ {
389
+ type: "input_statement",
390
+ name: "DO"
391
+ }
392
+ ],
393
+ previousStatement: null,
394
+ nextStatement: null,
395
+ style: "loop_blocks",
396
+ helpUrl: "%{BKY_LOOP_V1_FOR_EACH_HELPURL}",
397
+ extensions: ["contextMenu_newGetVariableBlock_v1", "for_each_tooltip_v1"]
398
+ }
399
+ ]);
400
+ e.Extensions.register(
401
+ "while_until_tooltip_v1",
402
+ e.Extensions.buildTooltipForDropdown("MODE", {
403
+ WHILE: "%{BKY_LOOP_V1_WHILE_UNTIL_TOOLTIP_WHILE}",
404
+ UNTIL: "%{BKY_LOOP_V1_WHILE_UNTIL_TOOLTIP_UNTIL}"
405
+ })
406
+ );
407
+ e.defineBlocksWithJsonArray([
408
+ {
409
+ type: "while_until_v1",
410
+ message0: "%1 %2",
411
+ args0: [
412
+ {
413
+ type: "field_dropdown",
414
+ name: "MODE",
415
+ options: [
416
+ ["%{BKY_LOOP_V1_WHILE_UNTIL_OPERATOR_WHILE}", "WHILE"],
417
+ ["%{BKY_LOOP_V1_WHILE_UNTIL_OPERATOR_UNTIL}", "UNTIL"]
418
+ ]
419
+ },
420
+ {
421
+ type: "input_value",
422
+ name: "BOOL",
423
+ check: "Boolean"
424
+ }
425
+ ],
426
+ message1: "%{BKY_LOOP_DO} %1",
427
+ args1: [
428
+ {
429
+ type: "input_statement",
430
+ name: "DO"
431
+ }
432
+ ],
433
+ previousStatement: null,
434
+ nextStatement: null,
435
+ style: "loop_blocks",
436
+ helpUrl: "%{BKY_LOOP_V1_WHILE_UNTIL_HELPURL}",
437
+ extensions: ["while_until_tooltip_v1"]
438
+ }
439
+ ]);
440
+ e.dialog.setConfirm(async (o, t) => {
441
+ const n = await B({
27
442
  title: "",
28
- text: r
443
+ text: o
29
444
  });
30
- t(!!o);
445
+ t(!!n);
31
446
  });
32
- e.dialog.setPrompt(async (r, t, o) => {
33
- const a = await w({
447
+ e.dialog.setPrompt(async (o, t, n) => {
448
+ const r = await R({
34
449
  title: "",
35
450
  value: t
36
451
  });
37
- o(a);
452
+ n(r);
38
453
  });
39
- const D = (r, t) => {
40
- const o = r[t];
41
- return o ? typeof o == "function" ? o() : Promise.resolve(o) : new Promise((a, c) => {
42
- (typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(c.bind(null, new Error("Unknown variable dynamic import: " + t)));
454
+ const W = (o, t) => {
455
+ const n = o[t];
456
+ return n ? typeof n == "function" ? n() : Promise.resolve(n) : new Promise((r, s) => {
457
+ (typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(s.bind(null, new Error("Unknown variable dynamic import: " + t)));
43
458
  });
44
459
  };
45
- async function f(r) {
46
- const t = await D(/* @__PURE__ */ Object.assign({ "./msg/en.ts": () => import("./en-DYxpcVy9.js"), "./msg/zhHans.ts": () => import("./zhHans-DjWw6Iqb.js") }), `./msg/${r}.ts`);
47
- e.setLocale(t);
460
+ async function f(o) {
461
+ const t = await W(/* @__PURE__ */ Object.assign({ "./msg/en.ts": () => import("./en-Djut8W3R.js"), "./msg/zhHans.ts": () => import("./zhHans-D_qcn_1f.js") }), `./msg/${o}.ts`);
462
+ e.setLocale(t.default);
48
463
  }
49
- class F {
50
- init({ contextMenu: t = !0, shortcut: o = !0 } = {
464
+ class G {
465
+ init({ contextMenu: t = !0, shortcut: n = !0 } = {
51
466
  contextMenu: !0,
52
467
  shortcut: !0
53
468
  }) {
54
- t && (this.blockCopyToStorageContextMenu(), this.blockPasteFromStorageContextMenu()), o && (e.ShortcutRegistry.registry.unregister(
469
+ t && (this.blockCopyToStorageContextMenu(), this.blockPasteFromStorageContextMenu()), n && (e.ShortcutRegistry.registry.unregister(
55
470
  e.ShortcutItems.names.COPY
56
471
  ), e.ShortcutRegistry.registry.unregister(
57
472
  e.ShortcutItems.names.CUT
@@ -64,21 +479,15 @@ class F {
64
479
  displayText: function() {
65
480
  return e.Msg.CROSS_TAB_COPY ? e.Msg.CROSS_TAB_COPY : "Copy";
66
481
  },
67
- preconditionFn: function(o) {
68
- var s;
69
- const a = e.getSelected();
70
- if (!a)
71
- return "disabled";
72
- const c = (s = o.workspace) == null ? void 0 : s.getBlockById(
73
- a.id
74
- );
75
- return !c || !c.isDeletable() || !c.isMovable() ? "disabled" : "enabled";
482
+ preconditionFn: function() {
483
+ const n = e.getSelected();
484
+ return !n || !e.isDeletable(n) || !n.isDeletable() || !e.isDraggable(n) || !n.isMovable() || !e.isCopyable(n) ? "disabled" : "enabled";
76
485
  },
77
- callback: function(o) {
78
- var a;
486
+ callback: function(n) {
487
+ var r;
79
488
  localStorage.setItem(
80
489
  "blocklyStash",
81
- JSON.stringify((a = o.block) == null ? void 0 : a.toCopyData())
490
+ JSON.stringify((r = n.block) == null ? void 0 : r.toCopyData())
82
491
  );
83
492
  },
84
493
  scopeType: e.ContextMenuRegistry.ScopeType.BLOCK,
@@ -92,20 +501,20 @@ class F {
92
501
  displayText: function() {
93
502
  return e.Msg.CROSS_TAB_PASTE ? e.Msg.CROSS_TAB_PASTE : "Paste";
94
503
  },
95
- preconditionFn: function(o) {
96
- var s;
97
- const a = localStorage.getItem("blocklyStash");
98
- if (!a)
504
+ preconditionFn: function(n) {
505
+ var i;
506
+ const r = localStorage.getItem("blocklyStash");
507
+ if (!r)
99
508
  return "disabled";
100
- const c = JSON.parse(a);
101
- return !c || !((s = o.workspace) != null && s.isCapacityAvailable(c.typeCounts)) ? "disabled" : "enabled";
509
+ const s = JSON.parse(r);
510
+ return !s || !((i = n.workspace) != null && i.isCapacityAvailable(s.typeCounts)) ? "disabled" : "enabled";
102
511
  },
103
- callback: function(o) {
104
- const a = localStorage.getItem("blocklyStash");
105
- if (!a)
512
+ callback: function(n) {
513
+ const r = localStorage.getItem("blocklyStash");
514
+ if (!r)
106
515
  return;
107
- const c = JSON.parse(a);
108
- c && o.workspace && e.clipboard.paste(c, o.workspace);
516
+ const s = JSON.parse(r);
517
+ s && n.workspace && e.clipboard.paste(s, n.workspace);
109
518
  },
110
519
  scopeType: e.ContextMenuRegistry.ScopeType.WORKSPACE,
111
520
  id: "blockPasteFromStorage",
@@ -114,136 +523,166 @@ class F {
114
523
  e.ContextMenuRegistry.registry.register(t);
115
524
  }
116
525
  blockCopyToStorageShortcut() {
117
- const t = {
118
- name: "copy",
119
- preconditionFn: function(s) {
120
- if (s.options.readOnly || e.Gesture.inProgress())
121
- return !1;
122
- const n = e.getSelected();
123
- if (!n)
124
- return !1;
125
- const i = s.getBlockById(
126
- n.id
127
- );
128
- return !(!i || !i.isDeletable() || !i.isMovable() || i.isInMutator);
129
- },
130
- callback: function(s, n) {
131
- n.preventDefault();
132
- const i = e.getSelected();
133
- if (!i)
134
- return !1;
135
- const l = s.getBlockById(
136
- i.id
137
- );
138
- return l ? (s.hideChaff(), localStorage.setItem(
139
- "blocklyStash",
140
- JSON.stringify(l.toCopyData())
141
- ), !0) : !1;
142
- }
143
- };
144
- e.ShortcutRegistry.registry.register(t);
145
- const o = e.ShortcutRegistry.registry.createSerializedKey(
526
+ const t = e.ShortcutRegistry.registry.createSerializedKey(
146
527
  e.utils.KeyCodes.C,
147
528
  [e.utils.KeyCodes.CTRL]
148
- );
149
- e.ShortcutRegistry.registry.addKeyMapping(o, t.name);
150
- const a = e.ShortcutRegistry.registry.createSerializedKey(
529
+ ), n = e.ShortcutRegistry.registry.createSerializedKey(
151
530
  e.utils.KeyCodes.C,
152
531
  [e.utils.KeyCodes.ALT]
153
- );
154
- e.ShortcutRegistry.registry.addKeyMapping(a, t.name);
155
- const c = e.ShortcutRegistry.registry.createSerializedKey(
532
+ ), r = e.ShortcutRegistry.registry.createSerializedKey(
156
533
  e.utils.KeyCodes.C,
157
534
  [e.utils.KeyCodes.META]
158
- );
159
- e.ShortcutRegistry.registry.addKeyMapping(c, t.name);
160
- }
161
- blockCutToStorageShortcut() {
162
- const t = {
163
- name: "cut",
164
- preconditionFn: function(s) {
165
- if (s.options.readOnly || e.Gesture.inProgress())
166
- return !1;
167
- const n = e.getSelected();
168
- if (!n)
535
+ ), s = {
536
+ name: "copy",
537
+ preconditionFn: function(i) {
538
+ if (i.options.readOnly || e.Gesture.inProgress())
169
539
  return !1;
170
- const i = s.getBlockById(
171
- n.id
172
- );
173
- return !(!i || !i.isDeletable() || !i.isMovable() || s.isFlyout);
540
+ const a = e.getSelected();
541
+ return !(!a || !e.isDeletable(a) || !a.isDeletable() || !e.isDraggable(a) || !a.isMovable() || !e.isCopyable(a));
174
542
  },
175
- callback: function(s, n) {
176
- n.preventDefault();
177
- const i = e.getSelected();
178
- if (!i)
543
+ callback: function(i, a) {
544
+ a.preventDefault();
545
+ const l = e.getSelected();
546
+ if (!l || !e.isCopyable(l))
179
547
  return !1;
180
- const l = s.getBlockById(
181
- i.id
182
- );
183
- return l ? (localStorage.setItem(
184
- "blocklyStash",
185
- JSON.stringify(l.toCopyData())
186
- ), e.Events.setGroup(!0), l.dispose(!0), e.Events.setGroup(!1), !0) : !1;
187
- }
548
+ const c = l.toCopyData();
549
+ return c ? (i.hideChaff(), localStorage.setItem("blocklyStash", JSON.stringify(c)), !0) : !1;
550
+ },
551
+ keyCodes: [t, n, r]
188
552
  };
189
- e.ShortcutRegistry.registry.register(t);
190
- const o = e.ShortcutRegistry.registry.createSerializedKey(
553
+ e.ShortcutRegistry.registry.register(s);
554
+ }
555
+ blockCutToStorageShortcut() {
556
+ const t = e.ShortcutRegistry.registry.createSerializedKey(
191
557
  e.utils.KeyCodes.X,
192
558
  [e.utils.KeyCodes.CTRL]
193
- );
194
- e.ShortcutRegistry.registry.addKeyMapping(o, t.name);
195
- const a = e.ShortcutRegistry.registry.createSerializedKey(
559
+ ), n = e.ShortcutRegistry.registry.createSerializedKey(
196
560
  e.utils.KeyCodes.X,
197
561
  [e.utils.KeyCodes.ALT]
198
- );
199
- e.ShortcutRegistry.registry.addKeyMapping(a, t.name);
200
- const c = e.ShortcutRegistry.registry.createSerializedKey(
562
+ ), r = e.ShortcutRegistry.registry.createSerializedKey(
201
563
  e.utils.KeyCodes.X,
202
564
  [e.utils.KeyCodes.META]
203
- );
204
- e.ShortcutRegistry.registry.addKeyMapping(c, t.name);
205
- }
206
- blockPasteFromStorageShortcut() {
207
- const t = {
208
- name: "paste",
209
- preconditionFn: function(s) {
210
- if (s.options.readOnly || e.Gesture.inProgress())
211
- return !1;
212
- const n = localStorage.getItem("blocklyStash");
213
- if (!n)
565
+ ), s = {
566
+ name: "cut",
567
+ preconditionFn: function(i) {
568
+ if (i.options.readOnly || e.Gesture.inProgress())
214
569
  return !1;
215
- const i = JSON.parse(n);
216
- return !(!i || !s.isCapacityAvailable(i.typeCounts));
570
+ const a = e.getSelected();
571
+ return !(!a || !e.isDeletable(a) || !a.isDeletable() || !e.isDraggable(a) || !a.isMovable() || !e.isCopyable(a) || a.workspace.isFlyout);
217
572
  },
218
- callback: function(s, n) {
219
- n.preventDefault();
220
- const i = localStorage.getItem("blocklyStash");
221
- if (!i)
573
+ callback: function(i, a) {
574
+ a.preventDefault();
575
+ const l = e.getSelected();
576
+ if (!l || !e.isDeletable(l) || !l.isDeletable() || !e.isCopyable(l))
222
577
  return !1;
223
- const l = JSON.parse(i);
224
- return l ? (e.clipboard.paste(l, s), !0) : !1;
225
- }
578
+ const c = l.toCopyData();
579
+ return c ? (localStorage.setItem("blocklyStash", JSON.stringify(c)), l instanceof e.BlockSvg ? l.checkAndDelete() : l.dispose(), !0) : !1;
580
+ },
581
+ keyCodes: [t, n, r]
226
582
  };
227
- e.ShortcutRegistry.registry.register(t);
228
- const o = e.ShortcutRegistry.registry.createSerializedKey(
583
+ e.ShortcutRegistry.registry.register(s);
584
+ }
585
+ blockPasteFromStorageShortcut() {
586
+ const t = e.ShortcutRegistry.registry.createSerializedKey(
229
587
  e.utils.KeyCodes.V,
230
588
  [e.utils.KeyCodes.CTRL]
231
- );
232
- e.ShortcutRegistry.registry.addKeyMapping(o, t.name);
233
- const a = e.ShortcutRegistry.registry.createSerializedKey(
589
+ ), n = e.ShortcutRegistry.registry.createSerializedKey(
234
590
  e.utils.KeyCodes.V,
235
591
  [e.utils.KeyCodes.ALT]
236
- );
237
- e.ShortcutRegistry.registry.addKeyMapping(a, t.name);
238
- const c = e.ShortcutRegistry.registry.createSerializedKey(
592
+ ), r = e.ShortcutRegistry.registry.createSerializedKey(
239
593
  e.utils.KeyCodes.V,
240
594
  [e.utils.KeyCodes.META]
241
- );
242
- e.ShortcutRegistry.registry.addKeyMapping(c, t.name);
595
+ ), s = {
596
+ name: "paste",
597
+ preconditionFn: function(i) {
598
+ if (i.options.readOnly || e.Gesture.inProgress())
599
+ return !1;
600
+ const a = localStorage.getItem("blocklyStash");
601
+ if (!a)
602
+ return !1;
603
+ const l = JSON.parse(a);
604
+ return !(!l || !i.isCapacityAvailable(l.typeCounts));
605
+ },
606
+ callback: function(i, a) {
607
+ a.preventDefault();
608
+ const l = localStorage.getItem("blocklyStash");
609
+ if (!l)
610
+ return !1;
611
+ const c = JSON.parse(l);
612
+ return c ? (e.clipboard.paste(c, i), !0) : !1;
613
+ },
614
+ keyCodes: [t, n, r]
615
+ };
616
+ e.ShortcutRegistry.registry.register(s);
243
617
  }
244
618
  }
245
- const A = new F();
246
- A.init({ contextMenu: !0, shortcut: !0 });
619
+ class H {
620
+ init() {
621
+ const t = e.ContextMenuRegistry.registry.getItem("cleanWorkspace");
622
+ t && (t.callback = function(n) {
623
+ const r = n.workspace;
624
+ if (!r)
625
+ return;
626
+ r.setResizesEnabled(!1), e.Events.setGroup(!0);
627
+ const s = r.getTopBlocks(!0);
628
+ let i = 0;
629
+ for (let a = 0, l; l = s[a]; a++) {
630
+ if (!l.isMovable())
631
+ continue;
632
+ const c = l.getRelativeToSurfaceXY();
633
+ l.moveBy(-c.x, i - c.y, ["cleanup"]), l.snapToGrid(), i = l.getRelativeToSurfaceXY().y + l.getHeightWidth().height + 100;
634
+ }
635
+ e.Events.setGroup(!1), r.setResizesEnabled(!0);
636
+ });
637
+ }
638
+ }
639
+ function g(o) {
640
+ const t = o.getParent();
641
+ return t && g(t) ? !0 : !t && !!(o.outputConnection || o.previousConnection);
642
+ }
643
+ class z {
644
+ init() {
645
+ const t = e.ContextMenuRegistry.registry.getItem("blockDisable");
646
+ t && (t.preconditionFn = function(n) {
647
+ const r = n.block;
648
+ return r && !r.isInFlyout && r.workspace.options.disable && r.isEditable() ? r.getInheritedDisabled() || g(r) ? "disabled" : "enabled" : "hidden";
649
+ });
650
+ }
651
+ }
652
+ class X extends e.HorizontalFlyout {
653
+ addBlockListeners_(t, n, r) {
654
+ e.getMainWorkspace().options.readOnly || super.addBlockListeners_(t, n, r);
655
+ }
656
+ isBlockCreatable(t) {
657
+ return e.getMainWorkspace().options.readOnly ? !1 : super.isBlockCreatable(t);
658
+ }
659
+ }
660
+ class J extends e.VerticalFlyout {
661
+ addBlockListeners_(t, n, r) {
662
+ e.getMainWorkspace().options.readOnly || super.addBlockListeners_(t, n, r);
663
+ }
664
+ isBlockCreatable(t) {
665
+ return e.getMainWorkspace().options.readOnly ? !1 : super.isBlockCreatable(t);
666
+ }
667
+ }
668
+ const j = new G();
669
+ j.init({ contextMenu: !0, shortcut: !0 });
670
+ const $ = new H();
671
+ $.init();
672
+ const q = new z();
673
+ q.init();
674
+ e.registry.register(
675
+ e.registry.Type.FLYOUTS_HORIZONTAL_TOOLBOX,
676
+ e.registry.DEFAULT,
677
+ X,
678
+ !0
679
+ );
680
+ e.registry.register(
681
+ e.registry.Type.FLYOUTS_VERTICAL_TOOLBOX,
682
+ e.registry.DEFAULT,
683
+ J,
684
+ !0
685
+ );
247
686
  e.Themes.Classic.blockStyles = {
248
687
  color_blocks: {
249
688
  colourPrimary: "#a5745b",
@@ -368,7 +807,7 @@ e.Themes.Classic.categoryStyles = {
368
807
  colour: "#a55b80"
369
808
  }
370
809
  };
371
- const L = e.Theme.defineTheme("light", {
810
+ const Z = e.Theme.defineTheme("light", {
372
811
  name: "light",
373
812
  base: e.Themes.Classic,
374
813
  componentStyles: {
@@ -384,7 +823,7 @@ const L = e.Theme.defineTheme("light", {
384
823
  scrollbarOpacity: 0.4,
385
824
  cursorColour: ""
386
825
  }
387
- }), V = e.Theme.defineTheme("dark", {
826
+ }), Q = e.Theme.defineTheme("dark", {
388
827
  name: "dark",
389
828
  base: e.Themes.Classic,
390
829
  componentStyles: {
@@ -401,55 +840,95 @@ const L = e.Theme.defineTheme("light", {
401
840
  cursorColour: ""
402
841
  }
403
842
  });
404
- function $(r) {
843
+ function ee(o) {
405
844
  const t = e.getMainWorkspace();
406
- switch (console.log(t), r) {
845
+ switch (console.log(t), o) {
407
846
  case "light":
408
- t.setTheme(L);
847
+ t.setTheme(Z);
409
848
  break;
410
849
  case "dark":
411
- t.setTheme(V);
850
+ t.setTheme(Q);
412
851
  break;
413
852
  }
414
853
  }
415
- const j = {
854
+ const te = {
855
+ kind: "category",
856
+ name: "%{BKY_CATEGORY_LOGIC}",
857
+ categorystyle: "logic_category",
858
+ contents: [
859
+ {
860
+ kind: "label",
861
+ text: "%{BKY_LABEL_BOOLEAN}"
862
+ },
863
+ {
864
+ kind: "block",
865
+ type: "boolean_v1"
866
+ },
867
+ {
868
+ kind: "block",
869
+ type: "if_v1"
870
+ }
871
+ ]
872
+ }, oe = {
873
+ kind: "category",
874
+ name: "%{BKY_CATEGORY_LOOP}",
875
+ categorystyle: "loop_category",
876
+ contents: [
877
+ {
878
+ kind: "block",
879
+ type: "while_until_v1"
880
+ },
881
+ {
882
+ kind: "block",
883
+ type: "flow_control_v1"
884
+ },
885
+ {
886
+ kind: "block",
887
+ type: "for_v1"
888
+ },
889
+ {
890
+ kind: "block",
891
+ type: "for_each_v1"
892
+ }
893
+ ]
894
+ }, ne = {
416
895
  kind: "categoryToolbox",
417
- contents: []
896
+ contents: [te, oe]
418
897
  };
419
- function N(r, t) {
420
- var c, s;
421
- const o = t.value, a = {
422
- passive: !((c = t.modifiers) != null && c.active)
898
+ function re(o, t) {
899
+ var s, i;
900
+ const n = t.value, r = {
901
+ passive: !((s = t.modifiers) != null && s.active)
423
902
  };
424
- window.addEventListener("resize", o, a), r._onResize = Object(r._onResize), r._onResize[t.instance.$.uid] = {
425
- handler: o,
426
- options: a
427
- }, (s = t.modifiers) != null && s.quiet || o();
903
+ window.addEventListener("resize", n, r), o._onResize = Object(o._onResize), o._onResize[t.instance.$.uid] = {
904
+ handler: n,
905
+ options: r
906
+ }, (i = t.modifiers) != null && i.quiet || n();
428
907
  }
429
- function J(r, t) {
430
- var c;
431
- if (!((c = r._onResize) != null && c[t.instance.$.uid]))
908
+ function se(o, t) {
909
+ var s;
910
+ if (!((s = o._onResize) != null && s[t.instance.$.uid]))
432
911
  return;
433
912
  const {
434
- handler: o,
435
- options: a
436
- } = r._onResize[t.instance.$.uid];
437
- window.removeEventListener("resize", o, a), delete r._onResize[t.instance.$.uid];
913
+ handler: n,
914
+ options: r
915
+ } = o._onResize[t.instance.$.uid];
916
+ window.removeEventListener("resize", n, r), delete o._onResize[t.instance.$.uid];
438
917
  }
439
- const X = {
440
- mounted: N,
441
- unmounted: J
442
- }, G = { class: "position-relative w-100 h-100" }, q = /* @__PURE__ */ h({
918
+ const ie = {
919
+ mounted: re,
920
+ unmounted: se
921
+ }, le = { class: "position-relative w-100 h-100" }, ae = /* @__PURE__ */ m({
443
922
  __name: "index",
444
923
  props: {
445
924
  type: {},
446
925
  version: {}
447
926
  },
448
927
  emits: ["ready", "change"],
449
- setup(r, { emit: t }) {
450
- const o = z(), a = I(), { open: c } = x("blocklyEditorFlyout"), s = r, n = t, i = C(null);
451
- let l;
452
- const g = {
928
+ setup(o, { emit: t }) {
929
+ const n = K(), r = D(), { open: s } = x("blocklyEditorFlyout"), i = o, a = t, l = C(null);
930
+ let c;
931
+ const p = {
453
932
  grid: {
454
933
  length: 2,
455
934
  snap: !0,
@@ -461,7 +940,8 @@ const X = {
461
940
  scrollbars: !0,
462
941
  wheel: !0
463
942
  },
464
- theme: a.current.value.dark ? "dark" : "light",
943
+ readOnly: !1,
944
+ theme: r.current.value.dark ? "dark" : "light",
465
945
  trashcan: !1,
466
946
  zoom: {
467
947
  maxScale: 1,
@@ -472,47 +952,47 @@ const X = {
472
952
  }
473
953
  };
474
954
  k(async () => {
475
- if (!i.value)
955
+ if (!l.value)
476
956
  return;
477
- await f(o.current.value);
957
+ await f(n.current.value);
478
958
  let u;
479
- s.type === "app" && s.version === "v1" && (u = j), g.toolbox = u, l = e.inject(i.value, g), l.addChangeListener(e.Events.disableOrphans), l.addChangeListener(S), await T(), n("ready", l);
959
+ i.type === "app" && i.version === "v1" && (u = ne), p.toolbox = u, c = e.inject(l.value, p), c.addChangeListener(e.Events.disableOrphans), c.addChangeListener(O), await S(), a("ready", c);
480
960
  });
481
- function p() {
482
- l && e.svgResize(l);
961
+ function h() {
962
+ c && e.svgResize(c);
483
963
  }
484
- function S(u) {
485
- n("change", u);
964
+ function O(u) {
965
+ a("change", u);
486
966
  }
487
- return _(() => {
488
- c.value = !1;
489
- }), d(c, (u) => {
490
- var y;
491
- u || (y = l.getToolbox()) == null || y.clearSelection();
492
- }), d(
493
- () => o.current.value,
967
+ return T(() => {
968
+ s.value = !1;
969
+ }), y(s, (u) => {
970
+ var _;
971
+ u || (_ = c.getToolbox()) == null || _.clearSelection();
972
+ }), y(
973
+ () => n.current.value,
494
974
  (u) => {
495
975
  f(u);
496
976
  }
497
- ), d(
498
- () => a.current.value.dark,
977
+ ), y(
978
+ () => r.current.value.dark,
499
979
  (u) => {
500
- $(u ? "dark" : "light");
980
+ ee(u ? "dark" : "light");
501
981
  }
502
- ), (u, y) => (v(), R("div", G, [
503
- K(M("div", {
982
+ ), (u, _) => (L(), E("div", le, [
983
+ I(v("div", {
504
984
  class: "w-100 h-100",
505
985
  ref_key: "blocklyDiv",
506
- ref: i,
986
+ ref: l,
507
987
  id: "blocklyEditor"
508
988
  }, null, 512), [
509
- [X, p]
989
+ [ie, h]
510
990
  ])
511
991
  ]));
512
992
  }
513
- }), U = (r) => {
514
- r.component("x-blockly", q);
515
- }, W = { install: U };
993
+ }), ce = (o) => {
994
+ o.component("x-blockly", ae);
995
+ }, pe = { install: ce };
516
996
  export {
517
- W as default
997
+ pe as default
518
998
  };