@adcops/autocore-react 3.0.1 → 3.0.3
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/assets/BlocklyLogo.d.ts +3 -0
- package/dist/assets/BlocklyLogo.js +1 -0
- package/dist/assets/Distance.d.ts +3 -0
- package/dist/assets/Distance.js +1 -0
- package/dist/assets/JogLong.d.ts +3 -0
- package/dist/assets/JogLong.js +1 -0
- package/dist/assets/JogMedium.d.ts +3 -0
- package/dist/assets/JogMedium.js +1 -0
- package/dist/assets/JogShort.d.ts +3 -0
- package/dist/assets/JogShort.js +1 -0
- package/dist/assets/PythonLogo.d.ts +3 -0
- package/dist/assets/PythonLogo.js +1 -0
- package/dist/assets/Rotation3D.d.ts +3 -0
- package/dist/assets/Rotation3D.js +1 -0
- package/dist/assets/RotationCcw.d.ts +3 -0
- package/dist/assets/RotationCcw.js +1 -0
- package/dist/assets/RotationCcwA.d.ts +3 -0
- package/dist/assets/RotationCcwA.js +1 -0
- package/dist/assets/RotationCcwB.d.ts +3 -0
- package/dist/assets/RotationCcwB.js +1 -0
- package/dist/assets/RotationCcwC.d.ts +3 -0
- package/dist/assets/RotationCcwC.js +1 -0
- package/dist/assets/RotationCw.d.ts +3 -0
- package/dist/assets/RotationCw.js +1 -0
- package/dist/assets/RotationCwA.d.ts +3 -0
- package/dist/assets/RotationCwA.js +1 -0
- package/dist/assets/RotationCwB.d.ts +3 -0
- package/dist/assets/RotationCwB.js +1 -0
- package/dist/assets/RotationCwC.d.ts +3 -0
- package/dist/assets/RotationCwC.js +1 -0
- package/dist/assets/Run.d.ts +3 -0
- package/dist/assets/Run.js +1 -0
- package/dist/assets/Speed.d.ts +3 -0
- package/dist/assets/Speed.js +1 -0
- package/dist/assets/SpeedFast.d.ts +3 -0
- package/dist/assets/SpeedFast.js +1 -0
- package/dist/assets/SpeedMedium.d.ts +3 -0
- package/dist/assets/SpeedMedium.js +1 -0
- package/dist/assets/SpeedNone.d.ts +3 -0
- package/dist/assets/SpeedNone.js +1 -0
- package/dist/assets/SpeedSlow.d.ts +3 -0
- package/dist/assets/SpeedSlow.js +1 -0
- package/dist/assets/Walk.d.ts +3 -0
- package/dist/assets/Walk.js +1 -0
- package/dist/assets/index.d.ts +22 -0
- package/dist/assets/index.js +1 -0
- package/dist/assets/svg/blockly_logo.svg +82 -0
- package/dist/assets/svg/distance.svg +40 -0
- package/dist/assets/svg/jog_long.svg +1 -0
- package/dist/assets/svg/jog_medium.svg +1 -0
- package/dist/assets/svg/jog_short.svg +1 -0
- package/dist/assets/svg/python_logo.svg +246 -0
- package/dist/assets/svg/rotation_3d.svg +1 -0
- package/dist/assets/svg/rotation_ccw.svg +50 -0
- package/dist/assets/svg/rotation_ccw_a.svg +57 -0
- package/dist/assets/svg/rotation_ccw_b.svg +57 -0
- package/dist/assets/svg/rotation_ccw_c.svg +57 -0
- package/dist/assets/svg/rotation_cw.svg +49 -0
- package/dist/assets/svg/rotation_cw_a.svg +30 -0
- package/dist/assets/svg/rotation_cw_b.svg +30 -0
- package/dist/assets/svg/rotation_cw_c.svg +30 -0
- package/dist/assets/svg/run.svg +1 -0
- package/dist/assets/svg/speed.svg +39 -0
- package/dist/assets/svg/speed_fast.svg +1 -0
- package/dist/assets/svg/speed_medium.svg +1 -0
- package/dist/assets/svg/speed_none.svg +1 -0
- package/dist/assets/svg/speed_slow.svg +1 -0
- package/dist/assets/svg/walk.svg +1 -0
- package/dist/components/BlocklyEditor.css +25 -0
- package/dist/components/BlocklyEditor.d.ts +120 -0
- package/dist/components/BlocklyEditor.js +1 -0
- package/dist/components/CodeEditor.d.ts +76 -0
- package/dist/components/CodeEditor.js +1 -0
- package/dist/components/Indicator.d.ts +12 -27
- package/dist/components/Indicator.js +1 -1
- package/dist/components/IndicatorButton.d.ts +56 -37
- package/dist/components/IndicatorButton.js +1 -1
- package/dist/components/JogPanel.css +41 -0
- package/dist/components/JogPanel.d.ts +115 -0
- package/dist/components/JogPanel.js +1 -0
- package/dist/components/Lamp.d.ts +81 -0
- package/dist/components/Lamp.js +1 -0
- package/dist/components/ToggleGroup.d.ts +103 -0
- package/dist/components/ToggleGroup.js +1 -0
- package/dist/core/ActionMode.d.ts +9 -0
- package/dist/core/ActionMode.js +1 -0
- package/dist/core/IndicatorButtonState.d.ts +21 -0
- package/dist/core/IndicatorButtonState.js +1 -0
- package/docs/assets/highlight.css +25 -18
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/components_BlocklyEditor.BlocklyEditor.html +124 -0
- package/docs/classes/components_CodeEditor.CodeEditor.html +128 -0
- package/docs/classes/components_Indicator.Indicator.html +8 -8
- package/docs/classes/components_IndicatorButton.IndicatorButton.html +17 -17
- package/docs/classes/components_JogPanel.JogPanel.html +138 -0
- package/docs/classes/components_Lamp.Lamp.html +105 -0
- package/docs/classes/components_OskDialog.OskDialog.html +5 -5
- package/docs/classes/components_ToggleGroup.ToggleGroup.html +118 -0
- package/docs/classes/components_ValueDisplay.ValueDisplay.html +4 -4
- package/docs/classes/core_ValueSimulator.ValueSimulator.html +2 -2
- package/docs/classes/hub_HubBase.HubBase.html +4 -4
- package/docs/classes/hub_HubSimulate.HubSimulate.html +2 -2
- package/docs/classes/hub_HubSocketIo.HubSocketIo.html +5 -5
- package/docs/classes/hub_HubTauri.HubTauri.html +5 -5
- package/docs/enums/components_JogPanel.JogDistanceAction.html +5 -0
- package/docs/enums/components_JogPanel.JogPanelAction.html +18 -0
- package/docs/enums/components_JogPanel.JogSpeedAction.html +5 -0
- package/docs/enums/core_ActionMode.ActionMode.html +6 -0
- package/docs/enums/core_IndicatorColor.IndicatorColor.html +23 -0
- package/docs/functions/assets_BlocklyLogo.default.html +1 -0
- package/docs/functions/assets_Distance.default.html +1 -0
- package/docs/functions/assets_JogLong.default.html +1 -0
- package/docs/functions/assets_JogMedium.default.html +1 -0
- package/docs/functions/assets_JogShort.default.html +1 -0
- package/docs/functions/assets_PythonLogo.default.html +1 -0
- package/docs/functions/assets_Rotation3D.default.html +1 -0
- package/docs/functions/assets_RotationCcw.default.html +1 -0
- package/docs/functions/assets_RotationCcwA.default.html +1 -0
- package/docs/functions/assets_RotationCcwB.default.html +1 -0
- package/docs/functions/assets_RotationCcwC.default.html +1 -0
- package/docs/functions/assets_RotationCw.default.html +1 -0
- package/docs/functions/assets_RotationCwA.default.html +1 -0
- package/docs/functions/assets_RotationCwB.default.html +1 -0
- package/docs/functions/assets_RotationCwC.default.html +1 -0
- package/docs/functions/assets_Run.default.html +1 -0
- package/docs/functions/assets_Speed.default.html +1 -0
- package/docs/functions/assets_SpeedFast.default.html +1 -0
- package/docs/functions/assets_SpeedMedium.default.html +1 -0
- package/docs/functions/assets_SpeedNone.default.html +1 -0
- package/docs/functions/assets_SpeedSlow.default.html +1 -0
- package/docs/functions/assets_Walk.default.html +1 -0
- package/docs/functions/components_BlocklyEditor.createCustomToolbox.html +6 -0
- package/docs/functions/components_Osk.Osk.html +2 -2
- package/docs/functions/core_EventEmitterContext.EventEmitterProvider.html +2 -2
- package/docs/functions/core_UniqueId.UniqueId.html +2 -2
- package/docs/functions/core_hoc.hocAddSubscription.html +2 -2
- package/docs/functions/hub.createHub.html +2 -2
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +18 -2
- package/docs/interfaces/components_IndicatorButton.IndicatorButtonProps.html +160 -132
- package/docs/interfaces/components_JogPanel.JogPanelButtonDefinition.html +5 -0
- package/docs/interfaces/components_ToggleGroup.ToggleGroupProps.html +636 -0
- package/docs/interfaces/core_EventEmitterContext.Action.html +2 -2
- package/docs/interfaces/core_EventEmitterContext.EventEmitterContextType.html +2 -2
- package/docs/interfaces/core_EventEmitterContext.State.html +2 -2
- package/docs/interfaces/core_EventEmitterContext.Subscription.html +2 -2
- package/docs/interfaces/core_IndicatorButtonState.IndicatorButtonState.html +10 -0
- package/docs/interfaces/core_PositionContext.IPositionContext.html +2 -2
- package/docs/modules/assets.html +23 -0
- package/docs/modules/assets_BlocklyLogo.html +2 -0
- package/docs/modules/assets_Distance.html +2 -0
- package/docs/modules/assets_JogLong.html +2 -0
- package/docs/modules/assets_JogMedium.html +2 -0
- package/docs/modules/assets_JogShort.html +2 -0
- package/docs/modules/assets_PythonLogo.html +2 -0
- package/docs/modules/assets_Rotation3D.html +2 -0
- package/docs/modules/assets_RotationCcw.html +2 -0
- package/docs/modules/assets_RotationCcwA.html +2 -0
- package/docs/modules/assets_RotationCcwB.html +2 -0
- package/docs/modules/assets_RotationCcwC.html +2 -0
- package/docs/modules/assets_RotationCw.html +2 -0
- package/docs/modules/assets_RotationCwA.html +2 -0
- package/docs/modules/assets_RotationCwB.html +2 -0
- package/docs/modules/assets_RotationCwC.html +2 -0
- package/docs/modules/assets_Run.html +2 -0
- package/docs/modules/assets_Speed.html +2 -0
- package/docs/modules/assets_SpeedFast.html +2 -0
- package/docs/modules/assets_SpeedMedium.html +2 -0
- package/docs/modules/assets_SpeedNone.html +2 -0
- package/docs/modules/assets_SpeedSlow.html +2 -0
- package/docs/modules/assets_Walk.html +2 -0
- package/docs/modules/components_BlocklyEditor.html +5 -0
- package/docs/modules/components_CodeEditor.html +3 -0
- package/docs/modules/components_Indicator.html +2 -2
- package/docs/modules/components_IndicatorButton.html +4 -4
- package/docs/modules/components_JogPanel.html +9 -0
- package/docs/modules/components_Lamp.html +4 -0
- package/docs/modules/components_Osk.html +2 -2
- package/docs/modules/components_OskDialog.html +2 -2
- package/docs/modules/components_ToggleGroup.html +5 -0
- package/docs/modules/components_ValueDisplay.html +2 -2
- package/docs/modules/core_ActionMode.html +2 -0
- package/docs/modules/core_EventEmitterContext.html +2 -2
- package/docs/modules/{components_IndicatorColor.html → core_IndicatorButtonState.html} +2 -2
- package/docs/modules/core_IndicatorColor.html +2 -0
- package/docs/modules/core_MaskPatterns.html +2 -2
- package/docs/modules/core_NumerableTypes.html +2 -2
- package/docs/modules/core_PositionContext.html +2 -2
- package/docs/modules/core_UniqueId.html +2 -2
- package/docs/modules/core_ValueSimulator.html +2 -2
- package/docs/modules/core_hoc.html +2 -2
- package/docs/modules/hub.html +2 -2
- package/docs/modules/hub_HubBase.html +2 -2
- package/docs/modules/hub_HubSimulate.html +2 -2
- package/docs/modules/hub_HubSocketIo.html +2 -2
- package/docs/modules/hub_HubTauri.html +2 -2
- package/docs/types/components_IndicatorButton.IndicatorButtonOptionsType.html +1 -0
- package/docs/types/core_EventEmitterContext.EmitterDispatchFunction.html +2 -2
- package/docs/types/core_EventEmitterContext.EmitterSubscribeFunction.html +2 -2
- package/docs/types/core_EventEmitterContext.EmitterUnsubscribeFunction.html +2 -2
- package/docs/types/core_NumerableTypes.NumerableFormatOptions.html +2 -2
- package/docs/types/core_hoc.HocAddSubscriptionProps.html +2 -2
- package/docs/variables/components_BlocklyEditor.StandardToolbox.html +1 -0
- package/docs/variables/components_JogPanel.kDefaultButtonDefinitions.html +2 -0
- package/docs/variables/components_JogPanel.kRotationButtonDefinitions.html +1 -0
- package/docs/variables/core_EventEmitterContext.EventEmitterContext.html +6 -6
- package/docs/variables/core_MaskPatterns.PrimeReactMaskPatterns.html +2 -2
- package/docs/variables/core_MaskPatterns.RegExMaskPatterns.html +2 -2
- package/docs/variables/core_PositionContext.DimensionsContext.html +2 -2
- package/package.json +7 -3
- package/readme.md +33 -0
- package/src/assets/BlocklyLogo.tsx +27 -0
- package/src/assets/Distance.tsx +18 -0
- package/src/assets/JogLong.tsx +13 -0
- package/src/assets/JogMedium.tsx +13 -0
- package/src/assets/JogShort.tsx +13 -0
- package/src/assets/PythonLogo.tsx +83 -0
- package/src/assets/Rotation3D.tsx +13 -0
- package/src/assets/RotationCcw.tsx +33 -0
- package/src/assets/RotationCcwA.tsx +45 -0
- package/src/assets/RotationCcwB.tsx +45 -0
- package/src/assets/RotationCcwC.tsx +45 -0
- package/src/assets/RotationCw.tsx +31 -0
- package/src/assets/RotationCwA.tsx +42 -0
- package/src/assets/RotationCwB.tsx +42 -0
- package/src/assets/RotationCwC.tsx +42 -0
- package/src/assets/Run.tsx +13 -0
- package/src/assets/Speed.tsx +18 -0
- package/src/assets/SpeedFast.tsx +13 -0
- package/src/assets/SpeedMedium.tsx +13 -0
- package/src/assets/SpeedNone.tsx +13 -0
- package/src/assets/SpeedSlow.tsx +13 -0
- package/src/assets/Walk.tsx +13 -0
- package/src/assets/index.ts +22 -0
- package/src/assets/svg/blockly_logo.svg +82 -0
- package/src/assets/svg/distance.svg +40 -0
- package/src/assets/svg/jog_long.svg +1 -0
- package/src/assets/svg/jog_medium.svg +1 -0
- package/src/assets/svg/jog_short.svg +1 -0
- package/src/assets/svg/python_logo.svg +246 -0
- package/src/assets/svg/rotation_3d.svg +1 -0
- package/src/assets/svg/rotation_ccw.svg +50 -0
- package/src/assets/svg/rotation_ccw_a.svg +57 -0
- package/src/assets/svg/rotation_ccw_b.svg +57 -0
- package/src/assets/svg/rotation_ccw_c.svg +57 -0
- package/src/assets/svg/rotation_cw.svg +49 -0
- package/src/assets/svg/rotation_cw_a.svg +30 -0
- package/src/assets/svg/rotation_cw_b.svg +30 -0
- package/src/assets/svg/rotation_cw_c.svg +30 -0
- package/src/assets/svg/run.svg +1 -0
- package/src/assets/svg/speed.svg +39 -0
- package/src/assets/svg/speed_fast.svg +1 -0
- package/src/assets/svg/speed_medium.svg +1 -0
- package/src/assets/svg/speed_none.svg +1 -0
- package/src/assets/svg/speed_slow.svg +1 -0
- package/src/assets/svg/walk.svg +1 -0
- package/src/components/BlocklyEditor.css +25 -0
- package/src/components/BlocklyEditor.tsx +598 -0
- package/src/components/CodeEditor.tsx +156 -0
- package/src/components/Indicator.tsx +63 -118
- package/src/components/IndicatorButton.tsx +104 -50
- package/src/components/JogPanel.css +41 -0
- package/src/components/JogPanel.tsx +458 -0
- package/src/components/Lamp.tsx +243 -0
- package/src/components/ToggleGroup.tsx +429 -0
- package/src/core/ActionMode.ts +20 -0
- package/src/core/IndicatorButtonState.ts +34 -0
- package/tools/copy-distribution-files.cjs +3 -2
- package/dist/components/DPad.css +0 -522
- package/dist/components/DPad.d.ts +0 -34
- package/dist/components/DPad.js +0 -1
- package/docs/enums/components_DPad.VcJoyPadAction.html +0 -10
- package/docs/enums/components_DPad.VcJoyPadButtonId.html +0 -7
- package/docs/enums/components_IndicatorButton.ActionMode.html +0 -6
- package/docs/enums/components_IndicatorColor.IndicatorColor.html +0 -23
- package/docs/functions/components_DPad.VcDPad.html +0 -5
- package/docs/interfaces/components_IndicatorButton.IndicatorButtonState.html +0 -10
- package/docs/modules/components_DPad.html +0 -5
- package/src/components/DPad.css +0 -522
- package/src/components/DPad.tsx +0 -94
- /package/dist/{components → core}/IndicatorColor.d.ts +0 -0
- /package/dist/{components → core}/IndicatorColor.js +0 -0
- /package/src/{components → core}/IndicatorColor.ts +0 -0
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
|
|
3
|
+
* Created Date: 2024-03-15 13:21:06
|
|
4
|
+
* -----
|
|
5
|
+
* Last Modified: 2024-03-18 11:31:36
|
|
6
|
+
* -----
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import Blockly from "blockly";
|
|
11
|
+
import { pythonGenerator } from 'blockly/python';
|
|
12
|
+
|
|
13
|
+
import { BlocklyWorkspace } from 'react-blockly';
|
|
14
|
+
|
|
15
|
+
import React from 'react';
|
|
16
|
+
|
|
17
|
+
import "./BlocklyEditor.css";
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Properties for the Blockly Editor.
|
|
22
|
+
*/
|
|
23
|
+
interface BlocklyEditorProps {
|
|
24
|
+
/**
|
|
25
|
+
* The initial XML representation of the Blockly workspace. Can be undefined
|
|
26
|
+
* if the workspace should start empty.
|
|
27
|
+
*/
|
|
28
|
+
initialXml: string | undefined;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The configuration definition for the Blockly Toolbox.
|
|
32
|
+
*/
|
|
33
|
+
toolbox: Blockly.utils.toolbox.ToolboxDefinition;
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Allows the parent component to add/subtract from the calculated
|
|
38
|
+
* width of the BlocklyEditor to account for other components (like a menu, toolbar, switch)
|
|
39
|
+
* in the view.
|
|
40
|
+
*/
|
|
41
|
+
widthAdjustment: number;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Allows the parent component to add/subtract from the calculated
|
|
46
|
+
* height of the BlocklyEditor to account for other components (like a menu, toolbar, switch)
|
|
47
|
+
* in the view.
|
|
48
|
+
*/
|
|
49
|
+
heightAdjustment: number;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Callback fired when the Blockly workspace content changes.
|
|
53
|
+
* Note: This does not directly reflect changes to the XML or the code.
|
|
54
|
+
*/
|
|
55
|
+
onWorkspaceChanged?: () => void;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Callback fired when the XML representation of the workspace changes.
|
|
59
|
+
* @param xml The updated XML representation of the workspace.
|
|
60
|
+
*/
|
|
61
|
+
onXmlChanged?: (xml: string) => void;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Callback fired when the generated code (e.g., Python) changes.
|
|
65
|
+
* @param code The updated generated code.
|
|
66
|
+
*/
|
|
67
|
+
onCodeChanged?: (code: string) => void;
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* State of the BlocklyEditor
|
|
74
|
+
*/
|
|
75
|
+
interface BlocklyEditorState {
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A name for the Blockly editor, potentially used for identification.
|
|
79
|
+
*/
|
|
80
|
+
name: string;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The current XML representation of the workspace.
|
|
84
|
+
*/
|
|
85
|
+
xml: string;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The current generated code (e.g., Python).
|
|
89
|
+
*/
|
|
90
|
+
code: string;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The height of the first parent container with
|
|
94
|
+
* classname "blockly-container". It is important to set
|
|
95
|
+
* a parent container with this class name for auto-sizing to work!
|
|
96
|
+
*/
|
|
97
|
+
parentHeight: number;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The width of the first parent container with
|
|
101
|
+
* classname "blockly-container". It is important to set
|
|
102
|
+
* a parent container with this class name for auto-sizing to work!
|
|
103
|
+
*/
|
|
104
|
+
parentWidth: number;
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* A view that contains the blockly editor, wrapping the react-blockly BlocklyWorkspace
|
|
111
|
+
* component. The added value of this BlocklyEditor component is that it will automatically
|
|
112
|
+
* size to the container, which can be a bit tricky when using blockly.
|
|
113
|
+
*
|
|
114
|
+
* The auto-sizing requires a parent component to have the className "blockly-container". This
|
|
115
|
+
* should be a component that has a known size roughly the size that you want the BlocklyEditor
|
|
116
|
+
* to appear. Otherwise, the BlocklyEditor will use the dimentions of the entire window, which usually is
|
|
117
|
+
* more than you want.
|
|
118
|
+
*
|
|
119
|
+
* Right now, the editor only supports generating python code, but a feature to specify the
|
|
120
|
+
* generator for different languages is planned.
|
|
121
|
+
*/
|
|
122
|
+
export class BlocklyEditor extends React.Component<BlocklyEditorProps, BlocklyEditorState> {
|
|
123
|
+
|
|
124
|
+
static defaultProps = {
|
|
125
|
+
initialXml: undefined,
|
|
126
|
+
widthAdjustment: 0,
|
|
127
|
+
heightAdjustment: 0,
|
|
128
|
+
onWorkspaceChanged: undefined,
|
|
129
|
+
onXmlChanged : undefined,
|
|
130
|
+
onCodeChanged : undefined
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// Explicitly type the ref as a reference to a HTMLDivElement
|
|
134
|
+
private ref = React.createRef<HTMLDivElement>();
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Constructor
|
|
138
|
+
*/
|
|
139
|
+
constructor(props: BlocklyEditorProps) {
|
|
140
|
+
super(props);
|
|
141
|
+
this.state = {
|
|
142
|
+
name: '',
|
|
143
|
+
xml: '',
|
|
144
|
+
code: '',
|
|
145
|
+
parentWidth: 0,
|
|
146
|
+
parentHeight: 0
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
componentDidMount() {
|
|
152
|
+
this.updateParentSize();
|
|
153
|
+
window.addEventListener('resize', this.updateParentSize);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
componentDidUpdate(prevProps: BlocklyEditorProps) {
|
|
157
|
+
prevProps;
|
|
158
|
+
// Logic to handle updates in props, if necessary
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
componentWillUnmount() {
|
|
162
|
+
window.removeEventListener('resize', this.updateParentSize);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
updateParentSize = () => {
|
|
167
|
+
|
|
168
|
+
if (this.ref.current) {
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
const parent = this.ref.current.parentElement;
|
|
172
|
+
let w = 0;
|
|
173
|
+
let h = 0;
|
|
174
|
+
let p = parent;
|
|
175
|
+
|
|
176
|
+
while (p !== undefined && p !== null) {
|
|
177
|
+
w = p.offsetWidth;
|
|
178
|
+
h = p.offsetHeight;
|
|
179
|
+
|
|
180
|
+
if (p.className.indexOf("blockly-container") >= 0) {
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
p = p.parentElement;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (w < 300) {
|
|
188
|
+
w = 300;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (h < 300)
|
|
192
|
+
h = 300;
|
|
193
|
+
|
|
194
|
+
this.setState({
|
|
195
|
+
parentWidth: (w * 0.9) + this.props.widthAdjustment,
|
|
196
|
+
parentHeight: (h * 0.9) + this.props.heightAdjustment,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
private onWorkspaceChanged = (workspace: Blockly.WorkspaceSvg | undefined) => {
|
|
205
|
+
const code = pythonGenerator.workspaceToCode(workspace);
|
|
206
|
+
this.setState({ code: code });
|
|
207
|
+
if (this.props.onWorkspaceChanged !== undefined && this.props.onWorkspaceChanged !== null)
|
|
208
|
+
this.props.onWorkspaceChanged();
|
|
209
|
+
|
|
210
|
+
if (this.props.onCodeChanged !== undefined && this.props.onCodeChanged !== null)
|
|
211
|
+
this.props.onCodeChanged(code);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private setXml = (xml: string) => {
|
|
215
|
+
this.setState({ xml: xml });
|
|
216
|
+
|
|
217
|
+
if (this.props.onXmlChanged !== undefined && this.props.onXmlChanged !== null)
|
|
218
|
+
this.props.onXmlChanged(xml);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private onInject = (workspace: Blockly.WorkspaceSvg) => {
|
|
222
|
+
workspace;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
render() {
|
|
227
|
+
return (
|
|
228
|
+
<>
|
|
229
|
+
<BlocklyWorkspace
|
|
230
|
+
className="fill-height" // you can use whatever classes are appropriate for your app's CSS
|
|
231
|
+
toolboxConfiguration={this.props.toolbox} // this must be a JSON toolbox definition
|
|
232
|
+
initialXml={this.props.initialXml}
|
|
233
|
+
onWorkspaceChange={this.onWorkspaceChanged}
|
|
234
|
+
onXmlChange={this.setXml}
|
|
235
|
+
onInject={this.onInject}
|
|
236
|
+
workspaceConfiguration={{
|
|
237
|
+
grid: {
|
|
238
|
+
spacing: 20,
|
|
239
|
+
length: 3,
|
|
240
|
+
colour: "#ccc",
|
|
241
|
+
snap: true,
|
|
242
|
+
},
|
|
243
|
+
}}
|
|
244
|
+
/>
|
|
245
|
+
|
|
246
|
+
</>
|
|
247
|
+
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export default BlocklyEditor;
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Creates a custom Blockly toolbox XML string by inserting additional XML before and after
|
|
259
|
+
* the standard Blockly toolbox.
|
|
260
|
+
*
|
|
261
|
+
* @param {string | undefined} xmlBefore - The XML content to be inserted before the built-in Blockly blocks.
|
|
262
|
+
* @param {string | undefined} xmlAfter - The XML content to be inserted after the built-in Blockly blocks.
|
|
263
|
+
* @returns {string} The customized toolbox XML string.
|
|
264
|
+
*/
|
|
265
|
+
export const createCustomToolbox = (xmlBefore: string | undefined, xmlAfter: string | undefined): string => {
|
|
266
|
+
|
|
267
|
+
// Define markers for the insertion points.
|
|
268
|
+
const kStartMarker = "<!-- BEGIN: Built-in Blockly Blocks //-->";
|
|
269
|
+
const kEndMarker = "<!-- END: Built-in Blockly Blocks //-->";
|
|
270
|
+
|
|
271
|
+
const beginInsertPoint = StandardToolbox.indexOf(kStartMarker);
|
|
272
|
+
const endInsertPoint = StandardToolbox.indexOf(kEndMarker);
|
|
273
|
+
|
|
274
|
+
if (beginInsertPoint === -1 || endInsertPoint === -1) {
|
|
275
|
+
throw new Error('Could not find markers in standard toolbox');
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Insert xmlBefore right before the begin comment and xmlAfter right after the end comment.
|
|
279
|
+
const modifiedToolbox =
|
|
280
|
+
StandardToolbox.slice(0, beginInsertPoint) +
|
|
281
|
+
(xmlBefore ? xmlBefore : "") +
|
|
282
|
+
StandardToolbox.slice(beginInsertPoint, endInsertPoint + kEndMarker.length) +
|
|
283
|
+
(xmlAfter ? xmlAfter : "") +
|
|
284
|
+
StandardToolbox.slice(endInsertPoint + kEndMarker.length + 1);
|
|
285
|
+
|
|
286
|
+
return modifiedToolbox;
|
|
287
|
+
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
export const StandardToolbox = `
|
|
294
|
+
<xml id="toolbox" style="display: none">
|
|
295
|
+
<!-- BEGIN: Built-in Blockly Blocks //-->
|
|
296
|
+
<category name="Logic" categorystyle="logic_category">
|
|
297
|
+
<block type="controls_if"></block>
|
|
298
|
+
<block type="logic_compare"></block>
|
|
299
|
+
<block type="logic_operation"></block>
|
|
300
|
+
<block type="logic_negate"></block>
|
|
301
|
+
<block type="logic_boolean"></block>
|
|
302
|
+
<block type="logic_null" disabled="true"></block>
|
|
303
|
+
<block type="logic_ternary"></block>
|
|
304
|
+
</category>
|
|
305
|
+
<category name="Loops" categorystyle="loop_category">
|
|
306
|
+
<block type="controls_repeat_ext">
|
|
307
|
+
<value name="TIMES">
|
|
308
|
+
<shadow type="math_number">
|
|
309
|
+
<field name="NUM">10</field>
|
|
310
|
+
</shadow>
|
|
311
|
+
</value>
|
|
312
|
+
</block>
|
|
313
|
+
<block type="controls_repeat" disabled="true"></block>
|
|
314
|
+
<block type="controls_whileUntil"></block>
|
|
315
|
+
<block type="controls_for">
|
|
316
|
+
<value name="FROM">
|
|
317
|
+
<shadow type="math_number">
|
|
318
|
+
<field name="NUM">1</field>
|
|
319
|
+
</shadow>
|
|
320
|
+
</value>
|
|
321
|
+
<value name="TO">
|
|
322
|
+
<shadow type="math_number">
|
|
323
|
+
<field name="NUM">10</field>
|
|
324
|
+
</shadow>
|
|
325
|
+
</value>
|
|
326
|
+
<value name="BY">
|
|
327
|
+
<shadow type="math_number">
|
|
328
|
+
<field name="NUM">1</field>
|
|
329
|
+
</shadow>
|
|
330
|
+
</value>
|
|
331
|
+
</block>
|
|
332
|
+
<block type="controls_forEach"></block>
|
|
333
|
+
<block type="controls_flow_statements"></block>
|
|
334
|
+
</category>
|
|
335
|
+
<category name="Math" categorystyle="math_category">
|
|
336
|
+
<block type="math_number" gap="32">
|
|
337
|
+
<field name="NUM">123</field>
|
|
338
|
+
</block>
|
|
339
|
+
<block type="math_arithmetic">
|
|
340
|
+
<value name="A">
|
|
341
|
+
<shadow type="math_number">
|
|
342
|
+
<field name="NUM">1</field>
|
|
343
|
+
</shadow>
|
|
344
|
+
</value>
|
|
345
|
+
<value name="B">
|
|
346
|
+
<shadow type="math_number">
|
|
347
|
+
<field name="NUM">1</field>
|
|
348
|
+
</shadow>
|
|
349
|
+
</value>
|
|
350
|
+
</block>
|
|
351
|
+
<block type="math_single">
|
|
352
|
+
<value name="NUM">
|
|
353
|
+
<shadow type="math_number">
|
|
354
|
+
<field name="NUM">9</field>
|
|
355
|
+
</shadow>
|
|
356
|
+
</value>
|
|
357
|
+
</block>
|
|
358
|
+
<block type="math_trig">
|
|
359
|
+
<value name="NUM">
|
|
360
|
+
<shadow type="math_number">
|
|
361
|
+
<field name="NUM">45</field>
|
|
362
|
+
</shadow>
|
|
363
|
+
</value>
|
|
364
|
+
</block>
|
|
365
|
+
<block type="math_constant"></block>
|
|
366
|
+
<block type="math_number_property">
|
|
367
|
+
<value name="NUMBER_TO_CHECK">
|
|
368
|
+
<shadow type="math_number">
|
|
369
|
+
<field name="NUM">0</field>
|
|
370
|
+
</shadow>
|
|
371
|
+
</value>
|
|
372
|
+
</block>
|
|
373
|
+
<block type="math_round">
|
|
374
|
+
<value name="NUM">
|
|
375
|
+
<shadow type="math_number">
|
|
376
|
+
<field name="NUM">3.1</field>
|
|
377
|
+
</shadow>
|
|
378
|
+
</value>
|
|
379
|
+
</block>
|
|
380
|
+
<block type="math_on_list"></block>
|
|
381
|
+
<block type="math_modulo">
|
|
382
|
+
<value name="DIVIDEND">
|
|
383
|
+
<shadow type="math_number">
|
|
384
|
+
<field name="NUM">64</field>
|
|
385
|
+
</shadow>
|
|
386
|
+
</value>
|
|
387
|
+
<value name="DIVISOR">
|
|
388
|
+
<shadow type="math_number">
|
|
389
|
+
<field name="NUM">10</field>
|
|
390
|
+
</shadow>
|
|
391
|
+
</value>
|
|
392
|
+
</block>
|
|
393
|
+
<block type="math_constrain">
|
|
394
|
+
<value name="VALUE">
|
|
395
|
+
<shadow type="math_number">
|
|
396
|
+
<field name="NUM">50</field>
|
|
397
|
+
</shadow>
|
|
398
|
+
</value>
|
|
399
|
+
<value name="LOW">
|
|
400
|
+
<shadow type="math_number">
|
|
401
|
+
<field name="NUM">1</field>
|
|
402
|
+
</shadow>
|
|
403
|
+
</value>
|
|
404
|
+
<value name="HIGH">
|
|
405
|
+
<shadow type="math_number">
|
|
406
|
+
<field name="NUM">100</field>
|
|
407
|
+
</shadow>
|
|
408
|
+
</value>
|
|
409
|
+
</block>
|
|
410
|
+
<block type="math_random_int">
|
|
411
|
+
<value name="FROM">
|
|
412
|
+
<shadow type="math_number">
|
|
413
|
+
<field name="NUM">1</field>
|
|
414
|
+
</shadow>
|
|
415
|
+
</value>
|
|
416
|
+
<value name="TO">
|
|
417
|
+
<shadow type="math_number">
|
|
418
|
+
<field name="NUM">100</field>
|
|
419
|
+
</shadow>
|
|
420
|
+
</value>
|
|
421
|
+
</block>
|
|
422
|
+
<block type="math_random_float"></block>
|
|
423
|
+
<block type="math_atan2">
|
|
424
|
+
<value name="X">
|
|
425
|
+
<shadow type="math_number">
|
|
426
|
+
<field name="NUM">1</field>
|
|
427
|
+
</shadow>
|
|
428
|
+
</value>
|
|
429
|
+
<value name="Y">
|
|
430
|
+
<shadow type="math_number">
|
|
431
|
+
<field name="NUM">1</field>
|
|
432
|
+
</shadow>
|
|
433
|
+
</value>
|
|
434
|
+
</block>
|
|
435
|
+
</category>
|
|
436
|
+
<category name="Text" categorystyle="text_category">
|
|
437
|
+
<block type="text"></block>
|
|
438
|
+
<block type="text_multiline"></block>
|
|
439
|
+
<block type="text_join"></block>
|
|
440
|
+
<block type="text_append">
|
|
441
|
+
<value name="TEXT">
|
|
442
|
+
<shadow type="text"></shadow>
|
|
443
|
+
</value>
|
|
444
|
+
</block>
|
|
445
|
+
<block type="text_length">
|
|
446
|
+
<value name="VALUE">
|
|
447
|
+
<shadow type="text">
|
|
448
|
+
<field name="TEXT">abc</field>
|
|
449
|
+
</shadow>
|
|
450
|
+
</value>
|
|
451
|
+
</block>
|
|
452
|
+
<block type="text_isEmpty">
|
|
453
|
+
<value name="VALUE">
|
|
454
|
+
<shadow type="text">
|
|
455
|
+
<field name="TEXT"></field>
|
|
456
|
+
</shadow>
|
|
457
|
+
</value>
|
|
458
|
+
</block>
|
|
459
|
+
<block type="text_indexOf">
|
|
460
|
+
<value name="VALUE">
|
|
461
|
+
<block type="variables_get">
|
|
462
|
+
<field name="VAR">text</field>
|
|
463
|
+
</block>
|
|
464
|
+
</value>
|
|
465
|
+
<value name="FIND">
|
|
466
|
+
<shadow type="text">
|
|
467
|
+
<field name="TEXT">abc</field>
|
|
468
|
+
</shadow>
|
|
469
|
+
</value>
|
|
470
|
+
</block>
|
|
471
|
+
<block type="text_charAt">
|
|
472
|
+
<value name="VALUE">
|
|
473
|
+
<block type="variables_get">
|
|
474
|
+
<field name="VAR">text</field>
|
|
475
|
+
</block>
|
|
476
|
+
</value>
|
|
477
|
+
</block>
|
|
478
|
+
<block type="text_getSubstring">
|
|
479
|
+
<value name="STRING">
|
|
480
|
+
<block type="variables_get">
|
|
481
|
+
<field name="VAR">text</field>
|
|
482
|
+
</block>
|
|
483
|
+
</value>
|
|
484
|
+
</block>
|
|
485
|
+
<block type="text_changeCase">
|
|
486
|
+
<value name="TEXT">
|
|
487
|
+
<shadow type="text">
|
|
488
|
+
<field name="TEXT">abc</field>
|
|
489
|
+
</shadow>
|
|
490
|
+
</value>
|
|
491
|
+
</block>
|
|
492
|
+
<block type="text_trim">
|
|
493
|
+
<value name="TEXT">
|
|
494
|
+
<shadow type="text">
|
|
495
|
+
<field name="TEXT">abc</field>
|
|
496
|
+
</shadow>
|
|
497
|
+
</value>
|
|
498
|
+
</block>
|
|
499
|
+
<block type="text_count">
|
|
500
|
+
<value name="SUB">
|
|
501
|
+
<shadow type="text"></shadow>
|
|
502
|
+
</value>
|
|
503
|
+
<value name="TEXT">
|
|
504
|
+
<shadow type="text"></shadow>
|
|
505
|
+
</value>
|
|
506
|
+
</block>
|
|
507
|
+
<block type="text_replace">
|
|
508
|
+
<value name="FROM">
|
|
509
|
+
<shadow type="text"></shadow>
|
|
510
|
+
</value>
|
|
511
|
+
<value name="TO">
|
|
512
|
+
<shadow type="text"></shadow>
|
|
513
|
+
</value>
|
|
514
|
+
<value name="TEXT">
|
|
515
|
+
<shadow type="text"></shadow>
|
|
516
|
+
</value>
|
|
517
|
+
</block>
|
|
518
|
+
<block type="text_reverse">
|
|
519
|
+
<value name="TEXT">
|
|
520
|
+
<shadow type="text"></shadow>
|
|
521
|
+
</value>
|
|
522
|
+
</block>
|
|
523
|
+
<label text="Input/Output:" web-class="ioLabel"></label>
|
|
524
|
+
<block type="text_print">
|
|
525
|
+
<value name="TEXT">
|
|
526
|
+
<shadow type="text">
|
|
527
|
+
<field name="TEXT">abc</field>
|
|
528
|
+
</shadow>
|
|
529
|
+
</value>
|
|
530
|
+
</block>
|
|
531
|
+
<block type="text_prompt_ext">
|
|
532
|
+
<value name="TEXT">
|
|
533
|
+
<shadow type="text">
|
|
534
|
+
<field name="TEXT">abc</field>
|
|
535
|
+
</shadow>
|
|
536
|
+
</value>
|
|
537
|
+
</block>
|
|
538
|
+
</category>
|
|
539
|
+
<category name="Lists" categorystyle="list_category">
|
|
540
|
+
<block type="lists_create_with">
|
|
541
|
+
<mutation items="0"></mutation>
|
|
542
|
+
</block>
|
|
543
|
+
<block type="lists_create_with"></block>
|
|
544
|
+
<block type="lists_repeat">
|
|
545
|
+
<value name="NUM">
|
|
546
|
+
<shadow type="math_number">
|
|
547
|
+
<field name="NUM">5</field>
|
|
548
|
+
</shadow>
|
|
549
|
+
</value>
|
|
550
|
+
</block>
|
|
551
|
+
<block type="lists_length"></block>
|
|
552
|
+
<block type="lists_isEmpty"></block>
|
|
553
|
+
<block type="lists_indexOf">
|
|
554
|
+
<value name="VALUE">
|
|
555
|
+
<block type="variables_get">
|
|
556
|
+
<field name="VAR">list</field>
|
|
557
|
+
</block>
|
|
558
|
+
</value>
|
|
559
|
+
</block>
|
|
560
|
+
<block type="lists_getIndex">
|
|
561
|
+
<value name="VALUE">
|
|
562
|
+
<block type="variables_get">
|
|
563
|
+
<field name="VAR">list</field>
|
|
564
|
+
</block>
|
|
565
|
+
</value>
|
|
566
|
+
</block>
|
|
567
|
+
<block type="lists_setIndex">
|
|
568
|
+
<value name="LIST">
|
|
569
|
+
<block type="variables_get">
|
|
570
|
+
<field name="VAR">list</field>
|
|
571
|
+
</block>
|
|
572
|
+
</value>
|
|
573
|
+
</block>
|
|
574
|
+
<block type="lists_getSublist">
|
|
575
|
+
<value name="LIST">
|
|
576
|
+
<block type="variables_get">
|
|
577
|
+
<field name="VAR">list</field>
|
|
578
|
+
</block>
|
|
579
|
+
</value>
|
|
580
|
+
</block>
|
|
581
|
+
<block type="lists_split">
|
|
582
|
+
<value name="DELIM">
|
|
583
|
+
<shadow type="text">
|
|
584
|
+
<field name="TEXT">,</field>
|
|
585
|
+
</shadow>
|
|
586
|
+
</value>
|
|
587
|
+
</block>
|
|
588
|
+
<block type="lists_sort"></block>
|
|
589
|
+
<block type="lists_reverse"></block>
|
|
590
|
+
</category>
|
|
591
|
+
<category name="Variables" categorystyle="variable_category" custom="VARIABLE"></category>
|
|
592
|
+
<category name="Functions" categorystyle="procedure_category" custom="PROCEDURE"></category>
|
|
593
|
+
|
|
594
|
+
<!-- END: Built-in Blockly Blocks //-->
|
|
595
|
+
|
|
596
|
+
</xml>
|
|
597
|
+
`;
|
|
598
|
+
|