@adcops/autocore-react 3.0.34 → 3.0.36

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.
Files changed (173) hide show
  1. package/dist/assets/BlocklyLogo.js +1 -9
  2. package/dist/assets/Distance.js +1 -5
  3. package/dist/assets/JogLong.js +1 -3
  4. package/dist/assets/JogMedium.js +1 -3
  5. package/dist/assets/JogShort.js +1 -3
  6. package/dist/assets/PythonLogo.js +1 -21
  7. package/dist/assets/Rotation3D.js +1 -3
  8. package/dist/assets/RotationCcw.js +1 -10
  9. package/dist/assets/RotationCcwA.js +1 -16
  10. package/dist/assets/RotationCcwB.js +1 -16
  11. package/dist/assets/RotationCcwC.js +1 -16
  12. package/dist/assets/RotationCw.js +1 -10
  13. package/dist/assets/RotationCwA.js +1 -16
  14. package/dist/assets/RotationCwB.js +1 -16
  15. package/dist/assets/RotationCwC.js +1 -16
  16. package/dist/assets/Run.js +1 -3
  17. package/dist/assets/Speed.js +1 -5
  18. package/dist/assets/SpeedFast.js +1 -3
  19. package/dist/assets/SpeedMedium.js +1 -3
  20. package/dist/assets/SpeedNone.js +1 -3
  21. package/dist/assets/SpeedSlow.js +1 -3
  22. package/dist/assets/Walk.js +1 -3
  23. package/dist/assets/index.js +1 -22
  24. package/dist/components/BlocklyEditor.css +71 -2
  25. package/dist/components/BlocklyEditor.js +1 -508
  26. package/dist/components/CodeEditor.js +1 -108
  27. package/dist/components/FileList.js +1 -218
  28. package/dist/components/FileSelect.js +1 -63
  29. package/dist/components/FitText.js +1 -13
  30. package/dist/components/Indicator.js +1 -113
  31. package/dist/components/IndicatorButton.js +1 -187
  32. package/dist/components/IndicatorRect.js +1 -93
  33. package/dist/components/JogPanel.js +1 -295
  34. package/dist/components/Lamp.js +1 -161
  35. package/dist/components/Osk.js +1 -125
  36. package/dist/components/OskDialog.js +1 -128
  37. package/dist/components/ProgressBarWithValue.js +1 -18
  38. package/dist/components/TextInput.js +1 -139
  39. package/dist/components/ToggleGroup.js +1 -204
  40. package/dist/components/ValueDisplay.js +1 -160
  41. package/dist/components/ValueIndicator.js +1 -38
  42. package/dist/components/ValueInput.js +1 -158
  43. package/dist/core/ActionMode.js +1 -18
  44. package/dist/core/EventEmitterContext.js +1 -252
  45. package/dist/core/IndicatorButtonState.js +1 -9
  46. package/dist/core/IndicatorColor.js +1 -36
  47. package/dist/core/MaskPatterns.js +1 -80
  48. package/dist/core/NumerableTypes.js +1 -10
  49. package/dist/core/PositionContext.js +1 -24
  50. package/dist/core/UniqueId.js +1 -32
  51. package/dist/core/ValueSimulator.js +1 -233
  52. package/dist/core/hoc.js +1 -44
  53. package/dist/hooks/adsHooks.js +1 -253
  54. package/dist/hooks/commandHooks.js +1 -252
  55. package/dist/hooks/index.js +1 -10
  56. package/dist/hooks/useScaledValue.js +1 -86
  57. package/dist/hub/CommandMessage.js +1 -9
  58. package/dist/hub/HubBase.js +1 -310
  59. package/dist/hub/HubSimulate.js +1 -46
  60. package/dist/hub/HubTauri.js +1 -130
  61. package/dist/hub/HubWebSocket.js +1 -240
  62. package/dist/hub/index.js +1 -57
  63. package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleMono-Italic-VariableFont_wght.ttf +0 -0
  64. package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleMono-VariableFont_wght.ttf +0 -0
  65. package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-Italic-VariableFont_wght.ttf +0 -0
  66. package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-Regular.woff2 +0 -0
  67. package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-RegularItalic.woff2 +0 -0
  68. package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-VariableFont_wght.ttf +0 -0
  69. package/dist/themes/adc-dark/blue/theme.css +7097 -0
  70. package/dist/themes/adc-dark/blue/theme.css.map +1 -0
  71. package/package.json +8 -2
  72. package/src/components/BlocklyEditor.css +71 -2
  73. package/src/themes/adc-dark/_extensions.scss +166 -0
  74. package/src/themes/adc-dark/_variables.scss +913 -0
  75. package/src/themes/adc-dark/blue/_fonts.scss +24 -0
  76. package/src/themes/adc-dark/blue/adc_theme.scss +31 -0
  77. package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleMono-Italic-VariableFont_wght.ttf +0 -0
  78. package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleMono-VariableFont_wght.ttf +0 -0
  79. package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-Italic-VariableFont_wght.ttf +0 -0
  80. package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-Regular.woff2 +0 -0
  81. package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-RegularItalic.woff2 +0 -0
  82. package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-VariableFont_wght.ttf +0 -0
  83. package/src/themes/adc-dark/blue/theme.scss +14 -0
  84. package/src/themes/theme-base/_colors.scss +18 -0
  85. package/src/themes/theme-base/_common.scss +75 -0
  86. package/src/themes/theme-base/_components.scss +111 -0
  87. package/src/themes/theme-base/_mixins.scss +243 -0
  88. package/src/themes/theme-base/components/button/_button.scss +644 -0
  89. package/src/themes/theme-base/components/button/_speeddial.scss +91 -0
  90. package/src/themes/theme-base/components/button/_splitbutton.scss +359 -0
  91. package/src/themes/theme-base/components/data/_carousel.scss +39 -0
  92. package/src/themes/theme-base/components/data/_datascroller.scss +47 -0
  93. package/src/themes/theme-base/components/data/_datatable.scss +389 -0
  94. package/src/themes/theme-base/components/data/_dataview.scss +47 -0
  95. package/src/themes/theme-base/components/data/_filter.scss +138 -0
  96. package/src/themes/theme-base/components/data/_orderlist.scss +86 -0
  97. package/src/themes/theme-base/components/data/_organizationchart.scss +50 -0
  98. package/src/themes/theme-base/components/data/_paginator.scss +91 -0
  99. package/src/themes/theme-base/components/data/_picklist.scss +74 -0
  100. package/src/themes/theme-base/components/data/_timeline.scss +38 -0
  101. package/src/themes/theme-base/components/data/_tree.scss +184 -0
  102. package/src/themes/theme-base/components/data/_treetable.scss +431 -0
  103. package/src/themes/theme-base/components/file/_fileupload.scss +41 -0
  104. package/src/themes/theme-base/components/input/_autocomplete.scss +95 -0
  105. package/src/themes/theme-base/components/input/_calendar.scss +251 -0
  106. package/src/themes/theme-base/components/input/_cascadeselect.scss +107 -0
  107. package/src/themes/theme-base/components/input/_checkbox.scss +181 -0
  108. package/src/themes/theme-base/components/input/_chips.scss +102 -0
  109. package/src/themes/theme-base/components/input/_colorpicker.scss +18 -0
  110. package/src/themes/theme-base/components/input/_dropdown.scss +252 -0
  111. package/src/themes/theme-base/components/input/_editor.scss +122 -0
  112. package/src/themes/theme-base/components/input/_iconfield.scss +10 -0
  113. package/src/themes/theme-base/components/input/_inputgroup.scss +74 -0
  114. package/src/themes/theme-base/components/input/_inputicon.scss +15 -0
  115. package/src/themes/theme-base/components/input/_inputnumber.scss +5 -0
  116. package/src/themes/theme-base/components/input/_inputotp.scss +10 -0
  117. package/src/themes/theme-base/components/input/_inputswitch.scss +100 -0
  118. package/src/themes/theme-base/components/input/_inputtext.scss +101 -0
  119. package/src/themes/theme-base/components/input/_listbox.scss +139 -0
  120. package/src/themes/theme-base/components/input/_mention.scss +31 -0
  121. package/src/themes/theme-base/components/input/_multiselect.scss +278 -0
  122. package/src/themes/theme-base/components/input/_password.scss +33 -0
  123. package/src/themes/theme-base/components/input/_radiobutton.scss +170 -0
  124. package/src/themes/theme-base/components/input/_rating.scss +81 -0
  125. package/src/themes/theme-base/components/input/_selectbutton.scss +50 -0
  126. package/src/themes/theme-base/components/input/_slider.scss +49 -0
  127. package/src/themes/theme-base/components/input/_togglebutton.scss +99 -0
  128. package/src/themes/theme-base/components/input/_treeselect.scss +151 -0
  129. package/src/themes/theme-base/components/input/_tristatecheckbox.scss +46 -0
  130. package/src/themes/theme-base/components/menu/_breadcrumb.scss +42 -0
  131. package/src/themes/theme-base/components/menu/_contextmenu.scss +39 -0
  132. package/src/themes/theme-base/components/menu/_dock.scss +109 -0
  133. package/src/themes/theme-base/components/menu/_megamenu.scss +141 -0
  134. package/src/themes/theme-base/components/menu/_menu.scss +33 -0
  135. package/src/themes/theme-base/components/menu/_menubar.scss +216 -0
  136. package/src/themes/theme-base/components/menu/_panelmenu.scss +153 -0
  137. package/src/themes/theme-base/components/menu/_slidemenu.scss +60 -0
  138. package/src/themes/theme-base/components/menu/_steps.scss +57 -0
  139. package/src/themes/theme-base/components/menu/_tabmenu.scss +50 -0
  140. package/src/themes/theme-base/components/menu/_tieredmenu.scss +43 -0
  141. package/src/themes/theme-base/components/messages/_inlinemessage.scss +69 -0
  142. package/src/themes/theme-base/components/messages/_message.scss +107 -0
  143. package/src/themes/theme-base/components/messages/_toast.scss +100 -0
  144. package/src/themes/theme-base/components/misc/_avatar.scss +34 -0
  145. package/src/themes/theme-base/components/misc/_badge.scss +77 -0
  146. package/src/themes/theme-base/components/misc/_blockui.scss +0 -0
  147. package/src/themes/theme-base/components/misc/_chip.scss +39 -0
  148. package/src/themes/theme-base/components/misc/_inplace.scss +17 -0
  149. package/src/themes/theme-base/components/misc/_metergroup.scss +81 -0
  150. package/src/themes/theme-base/components/misc/_progressbar.scss +17 -0
  151. package/src/themes/theme-base/components/misc/_scrolltop.scss +25 -0
  152. package/src/themes/theme-base/components/misc/_skeleton.scss +8 -0
  153. package/src/themes/theme-base/components/misc/_tag.scss +40 -0
  154. package/src/themes/theme-base/components/misc/_terminal.scss +12 -0
  155. package/src/themes/theme-base/components/multimedia/_galleria.scss +153 -0
  156. package/src/themes/theme-base/components/multimedia/_image.scss +54 -0
  157. package/src/themes/theme-base/components/overlay/_confirmpopup.scss +72 -0
  158. package/src/themes/theme-base/components/overlay/_dialog.scss +78 -0
  159. package/src/themes/theme-base/components/overlay/_overlaypanel.scss +64 -0
  160. package/src/themes/theme-base/components/overlay/_sidebar.scss +23 -0
  161. package/src/themes/theme-base/components/overlay/_tooltip.scss +33 -0
  162. package/src/themes/theme-base/components/panel/_accordion.scss +118 -0
  163. package/src/themes/theme-base/components/panel/_card.scss +30 -0
  164. package/src/themes/theme-base/components/panel/_divider.scss +31 -0
  165. package/src/themes/theme-base/components/panel/_fieldset.scss +47 -0
  166. package/src/themes/theme-base/components/panel/_panel.scss +47 -0
  167. package/src/themes/theme-base/components/panel/_scrollpanel.scss +10 -0
  168. package/src/themes/theme-base/components/panel/_splitter.scss +23 -0
  169. package/src/themes/theme-base/components/panel/_stepper.scss +136 -0
  170. package/src/themes/theme-base/components/panel/_tabview.scss +147 -0
  171. package/src/themes/theme-base/components/panel/_toolbar.scss +11 -0
  172. package/tools/build-themes.cjs +66 -0
  173. package/tools/copy-distribution-files.cjs +20 -16
@@ -1,508 +1 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- /*
3
- * Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
4
- * Created Date: 2024-03-15 13:21:06
5
- * -----
6
- * Last Modified: 2024-05-20 08:38:24
7
- * -----
8
- *
9
- */
10
- import React, { forwardRef, useImperativeHandle, useCallback, useState } from 'react';
11
- import Blockly from "blockly";
12
- import { pythonGenerator } from 'blockly/python';
13
- import { BlocklyWorkspace } from 'react-blockly';
14
- import "./BlocklyEditor.css";
15
- /**
16
- * A view that contains the blockly editor, wrapping the react-blockly BlocklyWorkspace
17
- * component. The added value of this BlocklyEditor component is that it will automatically
18
- * size to the container, which can be a bit tricky when using blockly.
19
- *
20
- * The auto-sizing requires a parent component to have the className "blockly-container". This
21
- * should be a component that has a known size roughly the size that you want the BlocklyEditor
22
- * to appear. Otherwise, the BlocklyEditor will use the dimentions of the entire window, which usually is
23
- * more than you want.
24
- *
25
- * Right now, the editor only supports generating python code, but a feature to specify the
26
- * generator for different languages is planned.
27
- *
28
- * ## Usage Example
29
- *
30
- * ```tsx
31
- * import React, { useRef } from 'react';
32
- * import BlocklyEditor from './BlocklyEditor';
33
- * import { StandardToolbox } from './toolbox';
34
- *
35
- * const App: React.FC = () => {
36
- * const blocklyEditorRef = useRef<{ newBlockly: () => void; loadBlockly: (xmlString: string) => void }>(null);
37
- *
38
- * const handleNew = () => {
39
- * if (blocklyEditorRef.current) {
40
- * blocklyEditorRef.current.newBlockly();
41
- * }
42
- * };
43
- *
44
- * const handleLoad = (xmlString: string) => {
45
- * if (blocklyEditorRef.current) {
46
- * blocklyEditorRef.current.loadBlockly(xmlString);
47
- * }
48
- * };
49
- *
50
- * return (
51
- * <div className="blockly-container" style={{ height: '500px' }}>
52
- * <BlocklyEditor
53
- * ref={blocklyEditorRef}
54
- * initialXml="<xml xmlns='http://www.w3.org/1999/xhtml'></xml>"
55
- * toolbox={StandardToolbox}
56
- * widthAdjustment={0}
57
- * heightAdjustment={0}
58
- * onWorkspaceChanged={(workspace) => console.log('Workspace changed:', workspace)}
59
- * onXmlChanged={(xml) => console.log('XML changed:', xml)}
60
- * onCodeChanged={(code) => console.log('Code changed:', code)}
61
- * onError={(message) => console.error('Error:', message)}
62
- * />
63
- * <button onClick={handleNew}>New</button>
64
- * <button onClick={() => handleLoad('<xml xmlns="http://www.w3.org/1999/xhtml"><block type="controls_if" x="10" y="10"></block></xml>')}>Load</button>
65
- * </div>
66
- * );
67
- * };
68
- *
69
- * export default App;
70
- * ```
71
- */
72
- export const BlocklyEditor = forwardRef((props, ref) => {
73
- const [_xml, setXml] = useState("");
74
- const [_code, setCode] = useState("");
75
- const [parentWidth, setParentWidth] = useState(0);
76
- const [parentHeight, setParentHeight] = useState(0);
77
- const [editorWorkspace, setEditorWorkspace] = useState(undefined);
78
- const containerRef = React.createRef();
79
- useImperativeHandle(ref, () => ({
80
- /**
81
- * Clears the Blockly workspace, removing all blocks.
82
- */
83
- newBlockly() {
84
- if (editorWorkspace) {
85
- editorWorkspace.clear();
86
- }
87
- },
88
- /**
89
- * Loads the given XML string into the Blockly workspace.
90
- * @param xmlString - The XML string representing the Blockly workspace to be loaded.
91
- */
92
- loadBlockly(xmlString) {
93
- if (editorWorkspace) {
94
- try {
95
- editorWorkspace.clear();
96
- const xml = Blockly.utils.xml.textToDom(xmlString);
97
- Blockly.Xml.domToWorkspace(xml, editorWorkspace);
98
- }
99
- catch (err) {
100
- if (props.onError) {
101
- props.onError(`${err}`);
102
- }
103
- }
104
- }
105
- }
106
- }));
107
- React.useEffect(() => {
108
- updateParentSize();
109
- window.addEventListener('resize', updateParentSize);
110
- return () => {
111
- window.removeEventListener('resize', updateParentSize);
112
- };
113
- }, []);
114
- /**
115
- * Updates the size of the parent container to ensure the Blockly workspace fits within it.
116
- */
117
- const updateParentSize = useCallback(() => {
118
- if (containerRef.current) {
119
- let w = 0;
120
- let h = 0;
121
- let p = containerRef.current.parentElement;
122
- while (p !== null) {
123
- w = p.offsetWidth;
124
- h = p.offsetHeight;
125
- if (p.className.indexOf("blockly-container") >= 0) {
126
- break;
127
- }
128
- p = p.parentElement;
129
- }
130
- if (w < 300)
131
- w = 300;
132
- if (h < 300)
133
- h = 300;
134
- setParentWidth((w * 0.9) + props.widthAdjustment);
135
- setParentHeight((h * 0.9) + props.heightAdjustment);
136
- }
137
- }, [props.widthAdjustment, props.heightAdjustment]);
138
- /**
139
- * Callback function that is triggered when the Blockly workspace changes.
140
- * It updates the generated code and triggers the appropriate callback.
141
- * @param workspace - The Blockly workspace that has changed.
142
- */
143
- const onWorkspaceChanged = (workspace) => {
144
- const code = pythonGenerator.workspaceToCode(workspace);
145
- setCode(code);
146
- if (props.onWorkspaceChanged)
147
- props.onWorkspaceChanged(workspace);
148
- if (props.onCodeChanged)
149
- props.onCodeChanged(code);
150
- };
151
- /**
152
- * Callback function that is triggered when the XML representation of the workspace changes.
153
- * @param s - The updated XML string.
154
- */
155
- const onXmlChanged = (s) => {
156
- setXml(s);
157
- if (props.onXmlChanged !== undefined && props.onXmlChanged !== null) {
158
- props.onXmlChanged(s);
159
- }
160
- };
161
- /**
162
- * Callback function that is triggered when the Blockly workspace is injected.
163
- * It sets the workspace reference.
164
- * @param workspace - The Blockly workspace that has been injected.
165
- */
166
- const onInject = (workspace) => {
167
- setEditorWorkspace(workspace);
168
- };
169
- return (_jsx("div", { ref: containerRef, style: { width: parentWidth, height: parentHeight }, children: _jsx(BlocklyWorkspace, { className: "fill-height", toolboxConfiguration: props.toolbox, initialXml: props.initialXml, onWorkspaceChange: onWorkspaceChanged, onXmlChange: onXmlChanged, onInject: onInject, workspaceConfiguration: {
170
- grid: {
171
- spacing: 20,
172
- length: 3,
173
- colour: "#ccc",
174
- snap: true,
175
- },
176
- } }) }));
177
- });
178
- export default BlocklyEditor;
179
- /**
180
- * Creates a custom Blockly toolbox XML string by inserting additional XML before and after
181
- * the standard Blockly toolbox.
182
- *
183
- * @param {string | undefined} xmlBefore - The XML content to be inserted before the built-in Blockly blocks.
184
- * @param {string | undefined} xmlAfter - The XML content to be inserted after the built-in Blockly blocks.
185
- * @returns {string} The customized toolbox XML string.
186
- */
187
- export const createCustomToolbox = (xmlBefore, xmlAfter) => {
188
- // Define markers for the insertion points.
189
- const kStartMarker = "<!-- BEGIN: Built-in Blockly Blocks //-->";
190
- const kEndMarker = "<!-- END: Built-in Blockly Blocks //-->";
191
- const beginInsertPoint = StandardToolbox.indexOf(kStartMarker);
192
- const endInsertPoint = StandardToolbox.indexOf(kEndMarker);
193
- if (beginInsertPoint === -1 || endInsertPoint === -1) {
194
- throw new Error('Could not find markers in standard toolbox');
195
- }
196
- // Insert xmlBefore right before the begin comment and xmlAfter right after the end comment.
197
- const modifiedToolbox = StandardToolbox.slice(0, beginInsertPoint) +
198
- (xmlBefore ? xmlBefore : "") +
199
- StandardToolbox.slice(beginInsertPoint, endInsertPoint + kEndMarker.length) +
200
- (xmlAfter ? xmlAfter : "") +
201
- StandardToolbox.slice(endInsertPoint + kEndMarker.length + 1);
202
- return modifiedToolbox;
203
- };
204
- export const StandardToolbox = `
205
- <xml id="toolbox" style="display: none">
206
- <!-- BEGIN: Built-in Blockly Blocks //-->
207
- <category name="Logic" categorystyle="logic_category">
208
- <block type="controls_if"></block>
209
- <block type="logic_compare"></block>
210
- <block type="logic_operation"></block>
211
- <block type="logic_negate"></block>
212
- <block type="logic_boolean"></block>
213
- <block type="logic_null" disabled="true"></block>
214
- <block type="logic_ternary"></block>
215
- </category>
216
- <category name="Loops" categorystyle="loop_category">
217
- <block type="controls_repeat_ext">
218
- <value name="TIMES">
219
- <shadow type="math_number">
220
- <field name="NUM">10</field>
221
- </shadow>
222
- </value>
223
- </block>
224
- <block type="controls_repeat" disabled="true"></block>
225
- <block type="controls_whileUntil"></block>
226
- <block type="controls_for">
227
- <value name="FROM">
228
- <shadow type="math_number">
229
- <field name="NUM">1</field>
230
- </shadow>
231
- </value>
232
- <value name="TO">
233
- <shadow type="math_number">
234
- <field name="NUM">10</field>
235
- </shadow>
236
- </value>
237
- <value name="BY">
238
- <shadow type="math_number">
239
- <field name="NUM">1</field>
240
- </shadow>
241
- </value>
242
- </block>
243
- <block type="controls_forEach"></block>
244
- <block type="controls_flow_statements"></block>
245
- </category>
246
- <category name="Math" categorystyle="math_category">
247
- <block type="math_number" gap="32">
248
- <field name="NUM">123</field>
249
- </block>
250
- <block type="math_arithmetic">
251
- <value name="A">
252
- <shadow type="math_number">
253
- <field name="NUM">1</field>
254
- </shadow>
255
- </value>
256
- <value name="B">
257
- <shadow type="math_number">
258
- <field name="NUM">1</field>
259
- </shadow>
260
- </value>
261
- </block>
262
- <block type="math_single">
263
- <value name="NUM">
264
- <shadow type="math_number">
265
- <field name="NUM">9</field>
266
- </shadow>
267
- </value>
268
- </block>
269
- <block type="math_trig">
270
- <value name="NUM">
271
- <shadow type="math_number">
272
- <field name="NUM">45</field>
273
- </shadow>
274
- </value>
275
- </block>
276
- <block type="math_constant"></block>
277
- <block type="math_number_property">
278
- <value name="NUMBER_TO_CHECK">
279
- <shadow type="math_number">
280
- <field name="NUM">0</field>
281
- </shadow>
282
- </value>
283
- </block>
284
- <block type="math_round">
285
- <value name="NUM">
286
- <shadow type="math_number">
287
- <field name="NUM">3.1</field>
288
- </shadow>
289
- </value>
290
- </block>
291
- <block type="math_on_list"></block>
292
- <block type="math_modulo">
293
- <value name="DIVIDEND">
294
- <shadow type="math_number">
295
- <field name="NUM">64</field>
296
- </shadow>
297
- </value>
298
- <value name="DIVISOR">
299
- <shadow type="math_number">
300
- <field name="NUM">10</field>
301
- </shadow>
302
- </value>
303
- </block>
304
- <block type="math_constrain">
305
- <value name="VALUE">
306
- <shadow type="math_number">
307
- <field name="NUM">50</field>
308
- </shadow>
309
- </value>
310
- <value name="LOW">
311
- <shadow type="math_number">
312
- <field name="NUM">1</field>
313
- </shadow>
314
- </value>
315
- <value name="HIGH">
316
- <shadow type="math_number">
317
- <field name="NUM">100</field>
318
- </shadow>
319
- </value>
320
- </block>
321
- <block type="math_random_int">
322
- <value name="FROM">
323
- <shadow type="math_number">
324
- <field name="NUM">1</field>
325
- </shadow>
326
- </value>
327
- <value name="TO">
328
- <shadow type="math_number">
329
- <field name="NUM">100</field>
330
- </shadow>
331
- </value>
332
- </block>
333
- <block type="math_random_float"></block>
334
- <block type="math_atan2">
335
- <value name="X">
336
- <shadow type="math_number">
337
- <field name="NUM">1</field>
338
- </shadow>
339
- </value>
340
- <value name="Y">
341
- <shadow type="math_number">
342
- <field name="NUM">1</field>
343
- </shadow>
344
- </value>
345
- </block>
346
- </category>
347
- <category name="Text" categorystyle="text_category">
348
- <block type="text"></block>
349
- <block type="text_multiline"></block>
350
- <block type="text_join"></block>
351
- <block type="text_append">
352
- <value name="TEXT">
353
- <shadow type="text"></shadow>
354
- </value>
355
- </block>
356
- <block type="text_length">
357
- <value name="VALUE">
358
- <shadow type="text">
359
- <field name="TEXT">abc</field>
360
- </shadow>
361
- </value>
362
- </block>
363
- <block type="text_isEmpty">
364
- <value name="VALUE">
365
- <shadow type="text">
366
- <field name="TEXT"></field>
367
- </shadow>
368
- </value>
369
- </block>
370
- <block type="text_indexOf">
371
- <value name="VALUE">
372
- <block type="variables_get">
373
- <field name="VAR">text</field>
374
- </block>
375
- </value>
376
- <value name="FIND">
377
- <shadow type="text">
378
- <field name="TEXT">abc</field>
379
- </shadow>
380
- </value>
381
- </block>
382
- <block type="text_charAt">
383
- <value name="VALUE">
384
- <block type="variables_get">
385
- <field name="VAR">text</field>
386
- </block>
387
- </value>
388
- </block>
389
- <block type="text_getSubstring">
390
- <value name="STRING">
391
- <block type="variables_get">
392
- <field name="VAR">text</field>
393
- </block>
394
- </value>
395
- </block>
396
- <block type="text_changeCase">
397
- <value name="TEXT">
398
- <shadow type="text">
399
- <field name="TEXT">abc</field>
400
- </shadow>
401
- </value>
402
- </block>
403
- <block type="text_trim">
404
- <value name="TEXT">
405
- <shadow type="text">
406
- <field name="TEXT">abc</field>
407
- </shadow>
408
- </value>
409
- </block>
410
- <block type="text_count">
411
- <value name="SUB">
412
- <shadow type="text"></shadow>
413
- </value>
414
- <value name="TEXT">
415
- <shadow type="text"></shadow>
416
- </value>
417
- </block>
418
- <block type="text_replace">
419
- <value name="FROM">
420
- <shadow type="text"></shadow>
421
- </value>
422
- <value name="TO">
423
- <shadow type="text"></shadow>
424
- </value>
425
- <value name="TEXT">
426
- <shadow type="text"></shadow>
427
- </value>
428
- </block>
429
- <block type="text_reverse">
430
- <value name="TEXT">
431
- <shadow type="text"></shadow>
432
- </value>
433
- </block>
434
- <label text="Input/Output:" web-class="ioLabel"></label>
435
- <block type="text_print">
436
- <value name="TEXT">
437
- <shadow type="text">
438
- <field name="TEXT">abc</field>
439
- </shadow>
440
- </value>
441
- </block>
442
- <block type="text_prompt_ext">
443
- <value name="TEXT">
444
- <shadow type="text">
445
- <field name="TEXT">abc</field>
446
- </shadow>
447
- </value>
448
- </block>
449
- </category>
450
- <category name="Lists" categorystyle="list_category">
451
- <block type="lists_create_with">
452
- <mutation items="0"></mutation>
453
- </block>
454
- <block type="lists_create_with"></block>
455
- <block type="lists_repeat">
456
- <value name="NUM">
457
- <shadow type="math_number">
458
- <field name="NUM">5</field>
459
- </shadow>
460
- </value>
461
- </block>
462
- <block type="lists_length"></block>
463
- <block type="lists_isEmpty"></block>
464
- <block type="lists_indexOf">
465
- <value name="VALUE">
466
- <block type="variables_get">
467
- <field name="VAR">list</field>
468
- </block>
469
- </value>
470
- </block>
471
- <block type="lists_getIndex">
472
- <value name="VALUE">
473
- <block type="variables_get">
474
- <field name="VAR">list</field>
475
- </block>
476
- </value>
477
- </block>
478
- <block type="lists_setIndex">
479
- <value name="LIST">
480
- <block type="variables_get">
481
- <field name="VAR">list</field>
482
- </block>
483
- </value>
484
- </block>
485
- <block type="lists_getSublist">
486
- <value name="LIST">
487
- <block type="variables_get">
488
- <field name="VAR">list</field>
489
- </block>
490
- </value>
491
- </block>
492
- <block type="lists_split">
493
- <value name="DELIM">
494
- <shadow type="text">
495
- <field name="TEXT">,</field>
496
- </shadow>
497
- </value>
498
- </block>
499
- <block type="lists_sort"></block>
500
- <block type="lists_reverse"></block>
501
- </category>
502
- <category name="Variables" categorystyle="variable_category" custom="VARIABLE"></category>
503
- <category name="Functions" categorystyle="procedure_category" custom="PROCEDURE"></category>
504
-
505
- <!-- END: Built-in Blockly Blocks //-->
506
-
507
- </xml>
508
- `;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import React,{forwardRef,useImperativeHandle,useCallback,useState}from"react";import Blockly from"blockly";import{pythonGenerator}from"blockly/python";import{BlocklyWorkspace}from"react-blockly";import"./BlocklyEditor.css";export const BlocklyEditor=forwardRef(((e,n)=>{const[l,t]=useState(""),[a,o]=useState(""),[c,d]=useState(0),[s,i]=useState(0),[m,r]=useState(void 0),b=React.createRef();useImperativeHandle(n,(()=>({newBlockly(){m&&m.clear()},loadBlockly(n){if(m)try{m.clear();const e=Blockly.utils.xml.textToDom(n);Blockly.Xml.domToWorkspace(e,m)}catch(n){e.onError&&e.onError(`${n}`)}}}))),React.useEffect((()=>(y(),window.addEventListener("resize",y),()=>{window.removeEventListener("resize",y)})),[]);const y=useCallback((()=>{if(b.current){let n=0,l=0,t=b.current.parentElement;for(;null!==t&&(n=t.offsetWidth,l=t.offsetHeight,!(t.className.indexOf("blockly-container")>=0));)t=t.parentElement;n<300&&(n=300),l<300&&(l=300),d(.9*n+e.widthAdjustment),i(.9*l+e.heightAdjustment)}}),[e.widthAdjustment,e.heightAdjustment]);return _jsx("div",{ref:b,style:{width:c,height:s},children:_jsx(BlocklyWorkspace,{className:"fill-height",toolboxConfiguration:e.toolbox,initialXml:e.initialXml,onWorkspaceChange:n=>{const l=pythonGenerator.workspaceToCode(n);o(l),e.onWorkspaceChanged&&e.onWorkspaceChanged(n),e.onCodeChanged&&e.onCodeChanged(l)},onXmlChange:n=>{t(n),void 0!==e.onXmlChanged&&null!==e.onXmlChanged&&e.onXmlChanged(n)},onInject:e=>{r(e)},workspaceConfiguration:{grid:{spacing:20,length:3,colour:"#ccc",snap:!0}}})})}));export default BlocklyEditor;export const createCustomToolbox=(e,n)=>{const l="\x3c!-- END: Built-in Blockly Blocks //--\x3e",t=StandardToolbox.indexOf("\x3c!-- BEGIN: Built-in Blockly Blocks //--\x3e"),a=StandardToolbox.indexOf(l);if(-1===t||-1===a)throw new Error("Could not find markers in standard toolbox");return StandardToolbox.slice(0,t)+(e||"")+StandardToolbox.slice(t,a+39)+(n||"")+StandardToolbox.slice(a+39+1)};export const StandardToolbox='\n <xml id="toolbox" style="display: none">\n \x3c!-- BEGIN: Built-in Blockly Blocks //--\x3e\n <category name="Logic" categorystyle="logic_category">\n <block type="controls_if"></block>\n <block type="logic_compare"></block>\n <block type="logic_operation"></block>\n <block type="logic_negate"></block>\n <block type="logic_boolean"></block>\n <block type="logic_null" disabled="true"></block>\n <block type="logic_ternary"></block>\n </category>\n <category name="Loops" categorystyle="loop_category">\n <block type="controls_repeat_ext">\n <value name="TIMES">\n <shadow type="math_number">\n <field name="NUM">10</field>\n </shadow>\n </value>\n </block>\n <block type="controls_repeat" disabled="true"></block>\n <block type="controls_whileUntil"></block>\n <block type="controls_for">\n <value name="FROM">\n <shadow type="math_number">\n <field name="NUM">1</field>\n </shadow>\n </value>\n <value name="TO">\n <shadow type="math_number">\n <field name="NUM">10</field>\n </shadow>\n </value>\n <value name="BY">\n <shadow type="math_number">\n <field name="NUM">1</field>\n </shadow>\n </value>\n </block>\n <block type="controls_forEach"></block>\n <block type="controls_flow_statements"></block>\n </category>\n <category name="Math" categorystyle="math_category">\n <block type="math_number" gap="32">\n <field name="NUM">123</field>\n </block>\n <block type="math_arithmetic">\n <value name="A">\n <shadow type="math_number">\n <field name="NUM">1</field>\n </shadow>\n </value>\n <value name="B">\n <shadow type="math_number">\n <field name="NUM">1</field>\n </shadow>\n </value>\n </block>\n <block type="math_single">\n <value name="NUM">\n <shadow type="math_number">\n <field name="NUM">9</field>\n </shadow>\n </value>\n </block>\n <block type="math_trig">\n <value name="NUM">\n <shadow type="math_number">\n <field name="NUM">45</field>\n </shadow>\n </value>\n </block>\n <block type="math_constant"></block>\n <block type="math_number_property">\n <value name="NUMBER_TO_CHECK">\n <shadow type="math_number">\n <field name="NUM">0</field>\n </shadow>\n </value>\n </block>\n <block type="math_round">\n <value name="NUM">\n <shadow type="math_number">\n <field name="NUM">3.1</field>\n </shadow>\n </value>\n </block>\n <block type="math_on_list"></block>\n <block type="math_modulo">\n <value name="DIVIDEND">\n <shadow type="math_number">\n <field name="NUM">64</field>\n </shadow>\n </value>\n <value name="DIVISOR">\n <shadow type="math_number">\n <field name="NUM">10</field>\n </shadow>\n </value>\n </block>\n <block type="math_constrain">\n <value name="VALUE">\n <shadow type="math_number">\n <field name="NUM">50</field>\n </shadow>\n </value>\n <value name="LOW">\n <shadow type="math_number">\n <field name="NUM">1</field>\n </shadow>\n </value>\n <value name="HIGH">\n <shadow type="math_number">\n <field name="NUM">100</field>\n </shadow>\n </value>\n </block>\n <block type="math_random_int">\n <value name="FROM">\n <shadow type="math_number">\n <field name="NUM">1</field>\n </shadow>\n </value>\n <value name="TO">\n <shadow type="math_number">\n <field name="NUM">100</field>\n </shadow>\n </value>\n </block>\n <block type="math_random_float"></block>\n <block type="math_atan2">\n <value name="X">\n <shadow type="math_number">\n <field name="NUM">1</field>\n </shadow>\n </value>\n <value name="Y">\n <shadow type="math_number">\n <field name="NUM">1</field>\n </shadow>\n </value>\n </block>\n </category>\n <category name="Text" categorystyle="text_category">\n <block type="text"></block>\n <block type="text_multiline"></block>\n <block type="text_join"></block>\n <block type="text_append">\n <value name="TEXT">\n <shadow type="text"></shadow>\n </value>\n </block>\n <block type="text_length">\n <value name="VALUE">\n <shadow type="text">\n <field name="TEXT">abc</field>\n </shadow>\n </value>\n </block>\n <block type="text_isEmpty">\n <value name="VALUE">\n <shadow type="text">\n <field name="TEXT"></field>\n </shadow>\n </value>\n </block>\n <block type="text_indexOf">\n <value name="VALUE">\n <block type="variables_get">\n <field name="VAR">text</field>\n </block>\n </value>\n <value name="FIND">\n <shadow type="text">\n <field name="TEXT">abc</field>\n </shadow>\n </value>\n </block>\n <block type="text_charAt">\n <value name="VALUE">\n <block type="variables_get">\n <field name="VAR">text</field>\n </block>\n </value>\n </block>\n <block type="text_getSubstring">\n <value name="STRING">\n <block type="variables_get">\n <field name="VAR">text</field>\n </block>\n </value>\n </block>\n <block type="text_changeCase">\n <value name="TEXT">\n <shadow type="text">\n <field name="TEXT">abc</field>\n </shadow>\n </value>\n </block>\n <block type="text_trim">\n <value name="TEXT">\n <shadow type="text">\n <field name="TEXT">abc</field>\n </shadow>\n </value>\n </block>\n <block type="text_count">\n <value name="SUB">\n <shadow type="text"></shadow>\n </value>\n <value name="TEXT">\n <shadow type="text"></shadow>\n </value>\n </block>\n <block type="text_replace">\n <value name="FROM">\n <shadow type="text"></shadow>\n </value>\n <value name="TO">\n <shadow type="text"></shadow>\n </value>\n <value name="TEXT">\n <shadow type="text"></shadow>\n </value>\n </block>\n <block type="text_reverse">\n <value name="TEXT">\n <shadow type="text"></shadow>\n </value>\n </block>\n <label text="Input/Output:" web-class="ioLabel"></label>\n <block type="text_print">\n <value name="TEXT">\n <shadow type="text">\n <field name="TEXT">abc</field>\n </shadow>\n </value>\n </block>\n <block type="text_prompt_ext">\n <value name="TEXT">\n <shadow type="text">\n <field name="TEXT">abc</field>\n </shadow>\n </value>\n </block>\n </category>\n <category name="Lists" categorystyle="list_category">\n <block type="lists_create_with">\n <mutation items="0"></mutation>\n </block>\n <block type="lists_create_with"></block>\n <block type="lists_repeat">\n <value name="NUM">\n <shadow type="math_number">\n <field name="NUM">5</field>\n </shadow>\n </value>\n </block>\n <block type="lists_length"></block>\n <block type="lists_isEmpty"></block>\n <block type="lists_indexOf">\n <value name="VALUE">\n <block type="variables_get">\n <field name="VAR">list</field>\n </block>\n </value>\n </block>\n <block type="lists_getIndex">\n <value name="VALUE">\n <block type="variables_get">\n <field name="VAR">list</field>\n </block>\n </value>\n </block>\n <block type="lists_setIndex">\n <value name="LIST">\n <block type="variables_get">\n <field name="VAR">list</field>\n </block>\n </value>\n </block>\n <block type="lists_getSublist">\n <value name="LIST">\n <block type="variables_get">\n <field name="VAR">list</field>\n </block>\n </value>\n </block>\n <block type="lists_split">\n <value name="DELIM">\n <shadow type="text">\n <field name="TEXT">,</field>\n </shadow>\n </value>\n </block>\n <block type="lists_sort"></block>\n <block type="lists_reverse"></block>\n </category>\n <category name="Variables" categorystyle="variable_category" custom="VARIABLE"></category>\n <category name="Functions" categorystyle="procedure_category" custom="PROCEDURE"></category>\n\n \x3c!-- END: Built-in Blockly Blocks //--\x3e\n\n </xml>\n';
@@ -1,108 +1 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- /*
3
- * Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
4
- * Created Date: 2024-03-17 08:43:02
5
- * -----
6
- * Last Modified: 2024-03-18 11:29:08
7
- * -----
8
- *
9
- */
10
- import * as React from 'react';
11
- //import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
12
- import Editor from '@monaco-editor/react';
13
- /**
14
- * Wrapper for the Microsoft Monaco editor, configured for our most common defaults.
15
- */
16
- export class CodeEditor extends React.Component {
17
- /**
18
- * Constructor
19
- * @param props PythonEditorProps
20
- */
21
- constructor(props) {
22
- super(props);
23
- /**
24
- * The editor is initialized and displayed in the view.
25
- * @param editor
26
- * @param monaco
27
- */
28
- Object.defineProperty(this, "editorDidMount", {
29
- enumerable: true,
30
- configurable: true,
31
- writable: true,
32
- value: (editor, monaco) => {
33
- monaco;
34
- editor.focus();
35
- }
36
- });
37
- /**
38
- * The editor is about to mount into the view.
39
- * @param monaco Instance of the editor.
40
- */
41
- Object.defineProperty(this, "handleEditorWillMount", {
42
- enumerable: true,
43
- configurable: true,
44
- writable: true,
45
- value: (monaco) => {
46
- monaco;
47
- }
48
- });
49
- /**
50
- * Handle changes to the editor's contents.
51
- * @param newValue New value of editor content.
52
- * @param e
53
- */
54
- Object.defineProperty(this, "onChange", {
55
- enumerable: true,
56
- configurable: true,
57
- writable: true,
58
- value: (newValue, e) => {
59
- e;
60
- if (this.props.onCodeChanged !== undefined && this.props.onCodeChanged !== null)
61
- this.props.onCodeChanged(newValue);
62
- }
63
- });
64
- Object.defineProperty(this, "handleEditorValidation", {
65
- enumerable: true,
66
- configurable: true,
67
- writable: true,
68
- value: (markers) => {
69
- // model markers
70
- markers.forEach(marker => console.log('onValidate:', marker.message));
71
- }
72
- });
73
- }
74
- /**
75
- * Render the component into the view.
76
- * @returns
77
- */
78
- render() {
79
- const options = {
80
- selectOnLineNumbers: true,
81
- roundedSelection: false,
82
- readOnly: this.props.readOnly,
83
- cursorStyle: this.props.cursorStyle,
84
- automaticLayout: true,
85
- theme: this.props.theme,
86
- language: this.props.language,
87
- folding: false,
88
- };
89
- return (_jsx(Editor, { value: this.props.code, height: "100%", width: "100%", defaultLanguage: "python", defaultValue: "", onChange: this.onChange, onMount: this.editorDidMount, beforeMount: this.handleEditorWillMount, onValidate: this.handleEditorValidation, theme: 'vs-dark', options: options }));
90
- }
91
- }
92
- /**
93
- * Default properties for this component.
94
- */
95
- Object.defineProperty(CodeEditor, "defaultProps", {
96
- enumerable: true,
97
- configurable: true,
98
- writable: true,
99
- value: {
100
- code: undefined,
101
- language: 'python',
102
- theme: 'vs-dark',
103
- readOnly: false,
104
- cursorStyle: "line",
105
- onCodeChanged: undefined
106
- }
107
- });
108
- export default CodeEditor;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import*as React from"react";import Editor from"@monaco-editor/react";export class CodeEditor extends React.Component{constructor(e){super(e),Object.defineProperty(this,"editorDidMount",{enumerable:!0,configurable:!0,writable:!0,value:(e,o)=>{e.focus()}}),Object.defineProperty(this,"handleEditorWillMount",{enumerable:!0,configurable:!0,writable:!0,value:e=>{}}),Object.defineProperty(this,"onChange",{enumerable:!0,configurable:!0,writable:!0,value:(e,o)=>{void 0!==this.props.onCodeChanged&&null!==this.props.onCodeChanged&&this.props.onCodeChanged(e)}}),Object.defineProperty(this,"handleEditorValidation",{enumerable:!0,configurable:!0,writable:!0,value:e=>{e.forEach((e=>{}))}})}render(){const e={selectOnLineNumbers:!0,roundedSelection:!1,readOnly:this.props.readOnly,cursorStyle:this.props.cursorStyle,automaticLayout:!0,theme:this.props.theme,language:this.props.language,folding:!1};return _jsx(Editor,{value:this.props.code,height:"100%",width:"100%",defaultLanguage:"python",defaultValue:"",onChange:this.onChange,onMount:this.editorDidMount,beforeMount:this.handleEditorWillMount,onValidate:this.handleEditorValidation,theme:"vs-dark",options:e})}}Object.defineProperty(CodeEditor,"defaultProps",{enumerable:!0,configurable:!0,writable:!0,value:{code:void 0,language:"python",theme:"vs-dark",readOnly:!1,cursorStyle:"line",onCodeChanged:void 0}});export default CodeEditor;