@kabel-project/kabel 1.0.7 → 1.0.9

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 (273) hide show
  1. package/dist/comment-renderer/renderer.d.ts +32 -0
  2. package/dist/comment-renderer/renderer.d.ts.map +1 -0
  3. package/dist/controllers/base.d.ts +39 -0
  4. package/dist/controllers/base.d.ts.map +1 -0
  5. package/dist/controllers/wasd.d.ts +33 -0
  6. package/dist/controllers/wasd.d.ts.map +1 -0
  7. package/dist/events/comment-drag-handle.d.ts +2 -0
  8. package/dist/events/comment-drag-handle.d.ts.map +1 -0
  9. package/dist/events/comment-input.d.ts +4 -0
  10. package/dist/events/comment-input.d.ts.map +1 -0
  11. package/dist/events/connection-line.d.ts +2 -0
  12. package/dist/events/connection-line.d.ts.map +1 -0
  13. package/dist/events/connector.d.ts +2 -0
  14. package/dist/events/connector.d.ts.map +1 -0
  15. package/dist/events/draggable.d.ts +2 -0
  16. package/dist/events/draggable.d.ts.map +1 -0
  17. package/{events/events.ts → dist/events/events.d.ts} +8 -7
  18. package/dist/events/events.d.ts.map +1 -0
  19. package/dist/events/input-box.d.ts +2 -0
  20. package/dist/events/input-box.d.ts.map +1 -0
  21. package/dist/events/node-x-btn.d.ts +2 -0
  22. package/dist/events/node-x-btn.d.ts.map +1 -0
  23. package/dist/kabel.js +2 -0
  24. package/dist/kabel.js.map +1 -0
  25. package/dist/renderers/apollo/apollo.d.ts +12 -0
  26. package/dist/renderers/apollo/apollo.d.ts.map +1 -0
  27. package/dist/renderers/apollo/constants.d.ts +21 -0
  28. package/dist/renderers/apollo/constants.d.ts.map +1 -0
  29. package/dist/renderers/apollo/renderer.d.ts +97 -0
  30. package/dist/renderers/apollo/renderer.d.ts.map +1 -0
  31. package/{renderers/atlas/atlas.ts → dist/renderers/atlas/atlas.d.ts} +6 -15
  32. package/dist/renderers/atlas/atlas.d.ts.map +1 -0
  33. package/dist/renderers/constants.d.ts +51 -0
  34. package/dist/renderers/constants.d.ts.map +1 -0
  35. package/dist/renderers/renderer.d.ts +470 -0
  36. package/dist/renderers/renderer.d.ts.map +1 -0
  37. package/dist/renderers/representer-node.d.ts +27 -0
  38. package/dist/renderers/representer-node.d.ts.map +1 -0
  39. package/dist/renderers/representer.d.ts +13 -0
  40. package/dist/renderers/representer.d.ts.map +1 -0
  41. package/dist/src/category.d.ts +48 -0
  42. package/dist/src/category.d.ts.map +1 -0
  43. package/{src/colors.ts → dist/src/colors.d.ts} +21 -20
  44. package/dist/src/colors.d.ts.map +1 -0
  45. package/dist/src/comment.d.ts +88 -0
  46. package/dist/src/comment.d.ts.map +1 -0
  47. package/dist/src/connection.d.ts +52 -0
  48. package/dist/src/connection.d.ts.map +1 -0
  49. package/dist/src/context-menu.d.ts +76 -0
  50. package/dist/src/context-menu.d.ts.map +1 -0
  51. package/dist/src/coordinates.d.ts +52 -0
  52. package/dist/src/coordinates.d.ts.map +1 -0
  53. package/dist/src/core.d.ts +153 -0
  54. package/dist/src/core.d.ts.map +1 -0
  55. package/dist/src/ctx-menu-registry.d.ts +22 -0
  56. package/dist/src/ctx-menu-registry.d.ts.map +1 -0
  57. package/dist/src/dropdown-menu.d.ts +87 -0
  58. package/dist/src/dropdown-menu.d.ts.map +1 -0
  59. package/dist/src/field.d.ts +305 -0
  60. package/dist/src/field.d.ts.map +1 -0
  61. package/dist/src/flyout.d.ts +41 -0
  62. package/dist/src/flyout.d.ts.map +1 -0
  63. package/dist/src/fonts-manager.d.ts +6 -0
  64. package/dist/src/fonts-manager.d.ts.map +1 -0
  65. package/dist/src/grid.d.ts +60 -0
  66. package/dist/src/grid.d.ts.map +1 -0
  67. package/dist/src/headless-node.d.ts +11 -0
  68. package/dist/src/headless-node.d.ts.map +1 -0
  69. package/dist/src/index.d.ts +38 -0
  70. package/dist/src/index.d.ts.map +1 -0
  71. package/dist/src/inject-headless.d.ts +4 -0
  72. package/dist/src/inject-headless.d.ts.map +1 -0
  73. package/{src/inject.ts → dist/src/inject.d.ts} +142 -213
  74. package/dist/src/inject.d.ts.map +1 -0
  75. package/{src/main-workspace.ts → dist/src/main-workspace.d.ts} +31 -51
  76. package/dist/src/main-workspace.d.ts.map +1 -0
  77. package/dist/src/mutator.d.ts +2 -0
  78. package/dist/src/mutator.d.ts.map +1 -0
  79. package/{src/node-types.ts → dist/src/node-types.d.ts} +26 -27
  80. package/dist/src/node-types.d.ts.map +1 -0
  81. package/dist/src/nodesvg.d.ts +266 -0
  82. package/dist/src/nodesvg.d.ts.map +1 -0
  83. package/{src/prototypes.ts → dist/src/prototypes.d.ts} +10 -9
  84. package/dist/src/prototypes.d.ts.map +1 -0
  85. package/{src/renderer-map.ts → dist/src/renderer-map.d.ts} +51 -86
  86. package/dist/src/renderer-map.d.ts.map +1 -0
  87. package/dist/src/toolbox.d.ts +51 -0
  88. package/dist/src/toolbox.d.ts.map +1 -0
  89. package/{src/types.ts → dist/src/types.d.ts} +159 -205
  90. package/dist/src/types.d.ts.map +1 -0
  91. package/dist/src/undo-redo.d.ts +15 -0
  92. package/dist/src/undo-redo.d.ts.map +1 -0
  93. package/{src/visual-types.ts → dist/src/visual-types.d.ts} +34 -29
  94. package/dist/src/visual-types.d.ts.map +1 -0
  95. package/dist/src/widget-prototypes.d.ts +10 -0
  96. package/dist/src/widget-prototypes.d.ts.map +1 -0
  97. package/dist/src/widget.d.ts +62 -0
  98. package/dist/src/widget.d.ts.map +1 -0
  99. package/{src/workspace-coords.ts → dist/src/workspace-coords.d.ts} +10 -14
  100. package/dist/src/workspace-coords.d.ts.map +1 -0
  101. package/dist/src/workspace-svg.d.ts +371 -0
  102. package/dist/src/workspace-svg.d.ts.map +1 -0
  103. package/dist/src/workspace.d.ts +50 -0
  104. package/dist/src/workspace.d.ts.map +1 -0
  105. package/dist/themes/dark.d.ts +4 -0
  106. package/dist/themes/dark.d.ts.map +1 -0
  107. package/dist/themes/default.d.ts +4 -0
  108. package/dist/themes/default.d.ts.map +1 -0
  109. package/dist/themes/themes.d.ts +6 -0
  110. package/dist/themes/themes.d.ts.map +1 -0
  111. package/dist/util/emitter.d.ts +10 -0
  112. package/dist/util/emitter.d.ts.map +1 -0
  113. package/dist/util/env.d.ts +7 -0
  114. package/dist/util/env.d.ts.map +1 -0
  115. package/{util/escape-html.ts → dist/util/escape-html.d.ts} +16 -22
  116. package/dist/util/escape-html.d.ts.map +1 -0
  117. package/dist/util/eventer.d.ts +29 -0
  118. package/dist/util/eventer.d.ts.map +1 -0
  119. package/dist/util/has-prop.d.ts +2 -0
  120. package/dist/util/has-prop.d.ts.map +1 -0
  121. package/dist/util/parse-color.d.ts +6 -0
  122. package/dist/util/parse-color.d.ts.map +1 -0
  123. package/dist/util/path.d.ts +25 -0
  124. package/dist/util/path.d.ts.map +1 -0
  125. package/dist/util/styler.d.ts +12 -0
  126. package/dist/util/styler.d.ts.map +1 -0
  127. package/dist/util/uid.d.ts +42 -0
  128. package/dist/util/uid.d.ts.map +1 -0
  129. package/{util/unescape-html.ts → dist/util/unescape-html.d.ts} +16 -22
  130. package/dist/util/unescape-html.d.ts.map +1 -0
  131. package/dist/util/user-state.d.ts +37 -0
  132. package/dist/util/user-state.d.ts.map +1 -0
  133. package/{util/wait-anim-frames.ts → dist/util/wait-anim-frames.d.ts} +11 -24
  134. package/dist/util/wait-anim-frames.d.ts.map +1 -0
  135. package/dist/util/window-listeners.d.ts +8 -0
  136. package/dist/util/window-listeners.d.ts.map +1 -0
  137. package/package.json +5 -2
  138. package/(1.0.7)kabel.md +0 -18
  139. package/_READ_ME_MEDIA_/documentation/docs.md +0 -293
  140. package/_READ_ME_MEDIA_/workspace.png +0 -0
  141. package/comment-renderer/renderer.ts +0 -228
  142. package/controllers/base.ts +0 -186
  143. package/controllers/wasd.ts +0 -132
  144. package/docs/README.md +0 -98
  145. package/docs/_media/docs.md +0 -289
  146. package/docs/_media/workspace.png +0 -0
  147. package/docs/classes/CommentModel.md +0 -271
  148. package/docs/classes/CommentRenderer.md +0 -457
  149. package/docs/classes/ConnectableField.md +0 -597
  150. package/docs/classes/Connection.md +0 -191
  151. package/docs/classes/ContextMenuHTML.md +0 -163
  152. package/docs/classes/Coordinates.md +0 -187
  153. package/docs/classes/DropdownContainer.md +0 -300
  154. package/docs/classes/DummyField.md +0 -393
  155. package/docs/classes/Eventer.md +0 -185
  156. package/docs/classes/Field.md +0 -461
  157. package/docs/classes/InjectMsg.md +0 -85
  158. package/docs/classes/NodeSvg.md +0 -1011
  159. package/docs/classes/NumberField.md +0 -559
  160. package/docs/classes/OptConnectField.md +0 -624
  161. package/docs/classes/Renderer.md +0 -1636
  162. package/docs/classes/RendererConstants.md +0 -343
  163. package/docs/classes/Representer.md +0 -95
  164. package/docs/classes/RepresenterNode.md +0 -175
  165. package/docs/classes/TextField.md +0 -559
  166. package/docs/classes/Toolbox.md +0 -172
  167. package/docs/classes/WASDController.md +0 -616
  168. package/docs/classes/Widget.md +0 -195
  169. package/docs/classes/WorkspaceController.md +0 -385
  170. package/docs/classes/WorkspaceCoords.md +0 -218
  171. package/docs/classes/WorkspaceSvg.md +0 -1380
  172. package/docs/functions/clearMainWorkspace.md +0 -20
  173. package/docs/functions/getMainWorkspace.md +0 -19
  174. package/docs/functions/inject.md +0 -35
  175. package/docs/functions/setMainWorkspace.md +0 -28
  176. package/docs/globals.md +0 -95
  177. package/docs/interfaces/ColorStyle.md +0 -43
  178. package/docs/interfaces/ConnectorToFrom.md +0 -57
  179. package/docs/interfaces/DrawState.md +0 -81
  180. package/docs/interfaces/FieldConnectionData.md +0 -25
  181. package/docs/interfaces/FieldOptions.md +0 -63
  182. package/docs/interfaces/FieldRawBoxData.md +0 -25
  183. package/docs/interfaces/FieldVisualInfo.md +0 -65
  184. package/docs/interfaces/GridOptions.md +0 -61
  185. package/docs/interfaces/InjectOptions.md +0 -133
  186. package/docs/interfaces/InputFieldJson.md +0 -50
  187. package/docs/interfaces/KabelCommentRendering.md +0 -31
  188. package/docs/interfaces/KabelInterface.md +0 -469
  189. package/docs/interfaces/KabelNodeRendering.md +0 -77
  190. package/docs/interfaces/KabelUIX.md +0 -105
  191. package/docs/interfaces/KabelUtils.md +0 -215
  192. package/docs/interfaces/NodeEvents.md +0 -42
  193. package/docs/interfaces/NodeJson.md +0 -104
  194. package/docs/interfaces/NodePrototype.md +0 -82
  195. package/docs/interfaces/RegisteredEl.md +0 -53
  196. package/docs/interfaces/SerializedNode.md +0 -128
  197. package/docs/interfaces/TblxCategoryStruct.md +0 -41
  198. package/docs/interfaces/TblxFieldStruct.md +0 -28
  199. package/docs/interfaces/TblxNodeStruct.md +0 -35
  200. package/docs/interfaces/WidgetOptions.md +0 -115
  201. package/docs/interfaces/WidgetPrototypeList.md +0 -15
  202. package/docs/type-aliases/AnyField.md +0 -13
  203. package/docs/type-aliases/AnyFieldCls.md +0 -13
  204. package/docs/type-aliases/Color.md +0 -13
  205. package/docs/type-aliases/Connectable.md +0 -13
  206. package/docs/type-aliases/EventArgs.md +0 -11
  207. package/docs/type-aliases/EventSetupFn.md +0 -25
  208. package/docs/type-aliases/Hex.md +0 -13
  209. package/docs/type-aliases/RGBObject.md +0 -37
  210. package/docs/type-aliases/RGBString.md +0 -13
  211. package/docs/type-aliases/RGBTuple.md +0 -13
  212. package/docs/type-aliases/TblxObjStruct.md +0 -52
  213. package/docs/variables/CategoryColors.md +0 -29
  214. package/docs/variables/FieldMap.md +0 -41
  215. package/docs/variables/NodePrototypes.md +0 -18
  216. package/docs/variables/default.md +0 -11
  217. package/events/comment-drag-handle.ts +0 -61
  218. package/events/comment-input.ts +0 -291
  219. package/events/connection-line.ts +0 -68
  220. package/events/connector.ts +0 -116
  221. package/events/draggable.ts +0 -119
  222. package/events/input-box.ts +0 -213
  223. package/events/node-x-btn.ts +0 -25
  224. package/index.d.ts +0 -4
  225. package/renderers/apollo/apollo.ts +0 -21
  226. package/renderers/apollo/constants.ts +0 -40
  227. package/renderers/apollo/renderer.ts +0 -331
  228. package/renderers/constants.ts +0 -87
  229. package/renderers/renderer.ts +0 -1288
  230. package/renderers/representer-node.ts +0 -52
  231. package/renderers/representer.ts +0 -25
  232. package/src/category.ts +0 -107
  233. package/src/comment.ts +0 -142
  234. package/src/connection.ts +0 -114
  235. package/src/context-menu.ts +0 -194
  236. package/src/coordinates.ts +0 -74
  237. package/src/core.ts +0 -202
  238. package/src/ctx-menu-registry.ts +0 -143
  239. package/src/dropdown-menu.ts +0 -215
  240. package/src/field.ts +0 -595
  241. package/src/flyout.ts +0 -165
  242. package/src/fonts-manager.ts +0 -38
  243. package/src/grid.ts +0 -162
  244. package/src/headless-node.ts +0 -27
  245. package/src/index.ts +0 -115
  246. package/src/inject-headless.ts +0 -18
  247. package/src/mutator.ts +0 -40
  248. package/src/nodesvg.ts +0 -756
  249. package/src/styles.css +0 -224
  250. package/src/toolbox.ts +0 -125
  251. package/src/undo-redo.ts +0 -87
  252. package/src/widget-prototypes.ts +0 -11
  253. package/src/widget.ts +0 -139
  254. package/src/workspace-svg.ts +0 -736
  255. package/src/workspace.ts +0 -155
  256. package/test-server.js +0 -61
  257. package/themes/dark.ts +0 -32
  258. package/themes/default.ts +0 -28
  259. package/themes/themes.ts +0 -9
  260. package/tsconfig.json +0 -25
  261. package/typedoc.json +0 -10
  262. package/util/emitter.ts +0 -33
  263. package/util/env.ts +0 -11
  264. package/util/eventer.ts +0 -108
  265. package/util/has-prop.ts +0 -4
  266. package/util/parse-color.ts +0 -42
  267. package/util/path.ts +0 -99
  268. package/util/styler.ts +0 -41
  269. package/util/uid.ts +0 -184
  270. package/util/user-state.ts +0 -68
  271. package/util/window-listeners.ts +0 -62
  272. package/webpack.config.js +0 -80
  273. /package/{docs/_media → dist}/index.html +0 -0
package/src/styles.css DELETED
@@ -1,224 +0,0 @@
1
- /* Workspace wrapper: horizontal layout */
2
- .KabelWorkspaceWrapper {
3
- display: flex;
4
- flex-direction: row;
5
- width: 100%;
6
- height: 100%;
7
- background: #f0f0f0;
8
- /* light gray background */
9
- overflow: hidden;
10
- position: relative;
11
- }
12
-
13
- /* Toolbox panel (left) */
14
- .KabelToolbox {
15
- width: 12%;
16
- min-width: 150px;
17
- height: 100%;
18
- background: rgba(240, 240, 240, 0.95);
19
- border-right: 1px solid #ccc;
20
- box-sizing: border-box;
21
- display: flex;
22
- flex-direction: column;
23
- padding: 8px;
24
- overflow-y: auto;
25
- }
26
-
27
- /* Context menu container */
28
- .KabelContextMenu {
29
- position: absolute;
30
- background: #1e1e2f;
31
- color: #000000;
32
- border-radius: 6px;
33
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
34
- padding: 4px 0;
35
- font-family: 'Segoe UI', sans-serif;
36
- font-size: 14px;
37
- min-width: 160px;
38
- z-index: 9999;
39
- user-select: none;
40
- overflow: visible;
41
- height: auto;
42
- transition: opacity 0.15s ease, transform 0.15s ease;
43
- opacity: 0;
44
- transform: scale(0.95);
45
- display: flex;
46
- flex-direction: column;
47
- }
48
-
49
- /* Show state */
50
- .KabelContextMenu.show {
51
- opacity: 1;
52
- transform: scale(1);
53
- }
54
-
55
- /* Individual option */
56
- .KabelContextOption {
57
- padding: 8px 16px;
58
- cursor: pointer;
59
- transition: background 0.15s ease, color 0.15s ease;
60
- }
61
- .KabelContextOption:hover {
62
- background: #b0adb0;
63
- color: #fff;
64
- }
65
- .KabelContextOption.disabled {
66
- opacity: 0.35;
67
- cursor: not-allowed;
68
- color: #777; /* dim it so it's obviously off */
69
- background: transparent;
70
- pointer-events: none;
71
- }
72
-
73
- /* make sure hover never triggers visually */
74
- .KabelContextOption.disabled:hover {
75
- background: transparent;
76
- color: #777;
77
- }
78
-
79
- /* Optional: active click effect */
80
- .KabelContextOption:active {
81
- background: #fff;
82
- color: #000;
83
- }
84
-
85
- /* Scrollbar if too many options */
86
- .KabelContextMenu::-webkit-scrollbar {
87
- width: 6px;
88
- }
89
-
90
- .KabelContextMenu::-webkit-scrollbar-thumb {
91
- background: rgba(255, 255, 255, 0.2);
92
- border-radius: 3px;
93
- }
94
-
95
- /* Category buttons */
96
-
97
- .KabelCategoryRow {
98
- background: #fff;
99
- border: 1px solid #ccc;
100
- padding: 4px 8px;
101
- margin-bottom: 4px;
102
- border-radius: 4px;
103
- height: 5%;
104
- padding: 6px;
105
- cursor: pointer;
106
- text-align: left;
107
- transition: background 0.2s, color 0.2s;
108
- }
109
-
110
- .KabelToolbox button:hover {
111
- background: #e6e6e6;
112
- color: #333;
113
- }
114
-
115
- .KabelConnectionBubbleHighlight {
116
- stroke: yellow !important;
117
- stroke-width: 6px !important;
118
- stroke-linejoin: round;
119
- stroke-linecap: round;
120
- filter: drop-shadow(0 0 6px rgba(255, 255, 0, 0.9));
121
- }
122
-
123
- .KabelConnectionBubbleHighlightWrong {
124
- stroke: rgb(255, 0, 0) !important;
125
- stroke-width: 6px !important;
126
- stroke-linejoin: round;
127
- stroke-linecap: round;
128
- filter: drop-shadow(0 0 6px rgba(255, 0, 0, 0.9));
129
- }
130
-
131
- /* Container */
132
- .KabelDropdownMenu {
133
- position: absolute;
134
- display: none;
135
- background: #1e1e1e;
136
- color: #f0f0f0;
137
- font-family: sans-serif;
138
- font-size: 14px;
139
- border: 1px solid #333;
140
- border-radius: 6px;
141
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
142
- padding: 4px 0;
143
- z-index: 9999;
144
- user-select: none;
145
- animation: fadeIn 0.15s ease-out;
146
- }
147
-
148
- /* Dropdown items */
149
- .KabelDropdownItem {
150
- padding: 6px 12px;
151
- cursor: pointer;
152
- transition: background 0.15s;
153
- }
154
-
155
- /* Hover + focus states */
156
- .KabelDropdownItem:hover,
157
- .KabelDropdownItem:focus {
158
- background: #2d2d2d;
159
- }
160
-
161
- /* Active (clicked) state */
162
- .KabelDropdownItem:active {
163
- background: #3a3a3a;
164
- }
165
-
166
- /* Optional: highlight selected value */
167
- .KabelDropdownItem.selected {
168
- background: #444;
169
- font-weight: 600;
170
- }
171
-
172
- /* Smooth open effect */
173
- @keyframes fadeIn {
174
- from {
175
- opacity: 0;
176
- transform: translateY(-3px);
177
- }
178
-
179
- to {
180
- opacity: 1;
181
- transform: translateY(0);
182
- }
183
- }
184
-
185
-
186
-
187
- /* Flyout panel (right) */
188
- .KabelFlyout {
189
- width: 20%;
190
- height: 100%;
191
- background: rgba(255, 255, 255, 0.95);
192
- border-left: 1px solid #ccc;
193
- box-sizing: border-box;
194
- overflow-y: auto;
195
- position: relative;
196
- /* for absolute positioning of nodes inside */
197
- display: none;
198
- /* hidden by default */
199
- padding: 8px;
200
- }
201
-
202
- /* Flyout nodes */
203
- .KabelFlyoutNode {
204
- padding: 6px 10px;
205
- margin-bottom: 4px;
206
- border-radius: 4px;
207
- cursor: pointer;
208
- user-select: none;
209
- transition: background 0.2s;
210
- }
211
-
212
- .KabelFlyoutNode:hover {
213
- background: #e0e0e0;
214
- }
215
-
216
- /* SVG workspace area */
217
- .KabelWorkspaceWrapper svg {
218
- flex: 1;
219
- width: 100%;
220
- height: 100%;
221
- background: #fff;
222
- /* white canvas background */
223
- display: block;
224
- }
package/src/toolbox.ts DELETED
@@ -1,125 +0,0 @@
1
- import Flyout from "./flyout";
2
- import { InjectOptions, TblxCategoryStruct, TblxNodeStruct } from "./inject";
3
- import WorkspaceSvg, { WSTheme } from "./workspace-svg";
4
- import Category from "./category";
5
-
6
- /**
7
- * Represents the toolbox in a Kabel workspace.
8
- * The toolbox can be either a flyout or a category-based toolbox.
9
- */
10
- class Toolbox {
11
- /** Toolbox type: 1 = category toolbox, 2 = flyout toolbox */
12
- type: 1 | 2;
13
-
14
- /** Reference to the workspace this toolbox belongs to */
15
- workspace: WorkspaceSvg;
16
-
17
- /** Workspace options for initialization */
18
- wsOptions: InjectOptions;
19
-
20
- /** Flyout instance for node display */
21
- _flyout: Flyout;
22
-
23
- /** Contents of the toolbox (nodes or categories) */
24
- _contents: TblxNodeStruct[] | TblxCategoryStruct[];
25
-
26
- /** DOM container element for the toolbox */
27
- container: HTMLDivElement;
28
-
29
- /** List of categories (if using a category toolbox) */
30
- _categories: Category[] = [];
31
-
32
- /**
33
- * Creates a new Toolbox instance attached to a workspace.
34
- * @param workspace The workspace instance to attach this toolbox to
35
- */
36
- constructor(workspace: WorkspaceSvg) {
37
- this.workspace = workspace;
38
- this.wsOptions = this.getOptions();
39
- this.type = this.wsOptions.toolbox?.type == "flyout" ? 2 : 1;
40
- this._contents = this.wsOptions.toolbox?.contents ?? [];
41
-
42
- // Pass toolbox reference to flyout
43
- this._flyout = new Flyout(this);
44
-
45
- // Create container element
46
- this.container = document.createElement("div");
47
- this.container.className = "KabelToolbox";
48
- this.container.style.position = "absolute";
49
- this.container.style.left = "0";
50
- this.container.style.top = "0";
51
- this.container.style.width = "20%";
52
- this.container.style.height = "100%";
53
- this.container.style.background = "rgba(240,240,240,0.9)";
54
- this.container.style.overflowY = "auto";
55
-
56
- // Append to workspace top layer
57
- workspace._wsTop.appendChild(this.container);
58
-
59
- // Initialize toolbox depending on type
60
- if (this.type === 1) this.initCategoryToolbox();
61
- if (this.type === 2) this.initFlyoutToolbox();
62
- }
63
- /**
64
- * Applies a WSTheme to the toolbox and flyout elements.
65
- * @param theme The workspace theme to apply
66
- */
67
- updateStyles(theme: WSTheme) {
68
- if (!theme?.UIStyles) return;
69
-
70
- const { toolboxCategoriesBG, toolboxFlyoutBG } = theme.UIStyles;
71
-
72
- const applyStyles = (el: HTMLElement, styles?: Partial<CSSStyleDeclaration>) => {
73
- if (!styles) return;
74
-
75
- for (const key in styles) {
76
- const k = key as keyof CSSStyleDeclaration;
77
- const v = styles[k];
78
- // Only assign if value exists
79
- if (v !== undefined) {
80
- // cast to any to avoid TS errors
81
- (el.style as any)[k] = v;
82
- }
83
- }
84
- };
85
-
86
- if (this.type === 1) applyStyles(this.container, toolboxCategoriesBG);
87
- if (this._flyout?.container) applyStyles(this._flyout.container, toolboxFlyoutBG);
88
- }
89
-
90
-
91
- /**
92
- * Retrieves the workspace options.
93
- * @returns The workspace's InjectOptions
94
- */
95
- getOptions() {
96
- return this.workspace.options;
97
- }
98
-
99
- /**
100
- * Initializes a category-based toolbox.
101
- * Converts the toolbox contents into Category instances and attaches them.
102
- */
103
- initCategoryToolbox() {
104
- const categories = this._contents as TblxCategoryStruct[];
105
- categories.forEach(cData => {
106
- const category = new Category(this, cData);
107
- this._categories.push(category);
108
- });
109
-
110
- // Hide flyout when workspace is clicked
111
- this.workspace.svg.on("click", () => this._flyout.hide());
112
- }
113
-
114
- /**
115
- * Initializes a flyout toolbox.
116
- * Fills the flyout with the node definitions from the toolbox contents.
117
- */
118
- initFlyoutToolbox() {
119
- this.container.style.display = "none";
120
- const nodes = this._contents as TblxNodeStruct[];
121
- this._flyout.fill(nodes);
122
- }
123
- }
124
-
125
- export default Toolbox;
package/src/undo-redo.ts DELETED
@@ -1,87 +0,0 @@
1
- import WorkspaceSvg from "./workspace-svg";
2
-
3
- interface HistoryEntry {
4
- state: any; // serialized workspace or diff
5
- }
6
-
7
- export default class UndoRedoHistory {
8
- private ws: WorkspaceSvg;
9
- private undoStack: HistoryEntry[] = [];
10
- private redoStack: HistoryEntry[] = [];
11
- private isRecording: boolean = true;
12
-
13
- constructor(ws: WorkspaceSvg) {
14
- this.ws = ws;
15
- }
16
-
17
- emitChange() {
18
- if (!this.isRecording) return;
19
- if (!this.ws.recordHistory) return;
20
-
21
- const state = this.ws.toJson ? this.ws.toJson(true) : {};
22
- this.undoStack.push({ state });
23
- this.redoStack.length = 0;
24
-
25
- //console.log("[emitChange] pushed state. undoStack size:", this.undoStack.length, "redoStack cleared");
26
- }
27
-
28
- undo() {
29
- //console.log("[undo] called. undoStack size:", this.undoStack.length, "redoStack size:", this.redoStack.length);
30
-
31
- if (this.undoStack.length <= 1) {
32
- //console.log("[undo] nothing to undo.");
33
- return;
34
- }
35
-
36
- const current = this.undoStack.pop();
37
- //console.log("[undo] popped current state:", current);
38
-
39
- const prev = this.undoStack[this.undoStack.length - 1];
40
- //console.log("[undo] previous state to restore:", prev);
41
-
42
- if (!prev) {
43
- //console.log("[undo] no previous state found.");
44
- return;
45
- }
46
-
47
- this.isRecording = false;
48
- this.ws.fromJson?.(prev.state);
49
- this.isRecording = true;
50
-
51
- this.redoStack.push(current as HistoryEntry);
52
- //console.log("[undo] state restored. undoStack size now:", this.undoStack.length, "redoStack size now:", this.redoStack.length);
53
- }
54
-
55
- redo() {
56
- //console.log("[redo] called. undoStack size:", this.undoStack.length, "redoStack size:", this.redoStack.length);
57
-
58
- const entry = this.redoStack.pop();
59
- if (!entry) {
60
- //console.log("[redo] nothing to redo.");
61
- return;
62
- }
63
-
64
- //console.log("[redo] popping state from redoStack:", entry);
65
-
66
- this.isRecording = false;
67
- this.ws.fromJson?.(entry.state);
68
- this.isRecording = true;
69
-
70
- this.undoStack.push(entry);
71
- //console.log("[redo] state restored. undoStack size now:", this.undoStack.length, "redoStack size now:", this.redoStack.length);
72
- }
73
-
74
- clear() {
75
- this.undoStack = [];
76
- this.redoStack = [];
77
- //console.log("[clear] undo and redo stacks cleared");
78
- }
79
-
80
- canUndo() {
81
- return this.undoStack.length > 1;
82
- }
83
-
84
- canRedo() {
85
- return this.redoStack.length > 0;
86
- }
87
- }
@@ -1,11 +0,0 @@
1
- import { WidgetOptions } from "./widget";
2
-
3
- /**
4
- * A list of prototypes for widgets.
5
- */
6
- export interface WidgetPrototypeList {
7
- [key: string]: WidgetOptions
8
- }
9
-
10
- const WidgetPrototypes: WidgetPrototypeList = {};
11
- export default WidgetPrototypes;
package/src/widget.ts DELETED
@@ -1,139 +0,0 @@
1
- import WorkspaceSvg from "./workspace-svg";
2
- import Coordinates from "./coordinates";
3
- import { generateUID } from "../util/uid";
4
- import Workspace from "./workspace";
5
-
6
- export interface WidgetOptions {
7
- /**
8
- * Widget class to instantiate for the widget, by default it uses Kabel's
9
- */
10
- cls?: typeof Widget;
11
- /**
12
- * Coordinates to spawn the widget at.
13
- */
14
- coords?: Coordinates; // where to position the widget
15
- /**
16
- * Width of the widget
17
- */
18
- width?: number; // optional width
19
- /**
20
- * Height of the widget.
21
- */
22
- height?: number; // optional height
23
- /**
24
- * Class to give the widget's html container.
25
- */
26
- className?: string; // optional CSS class
27
- /**
28
- * Widget inner HTML default content.
29
- */
30
- html?: string; // inner HTML
31
- /**
32
- * Widget name
33
- */
34
- name: string;
35
- /**
36
- * Sets up a new widget of this type
37
- * @param this - This context of the function points to widget.
38
- * @param widget - The widget this function is called on.
39
- * @param html - The html container of the widget.
40
- * @returns - Void.
41
- */
42
- init?: (this: WidgetOptions, widget: Widget, html: HTMLElement) => void;
43
- }
44
- class Widget {
45
- workspace: WorkspaceSvg|Workspace;
46
- container: HTMLDivElement;
47
- coords: Coordinates;
48
- width: number;
49
- height: number;
50
- visible: boolean;
51
- name: string;
52
- id: string;
53
- options: WidgetOptions;
54
- static WIDGET_GLOBAL_ID = 0;
55
- constructor(workspace: WorkspaceSvg|Workspace, options: WidgetOptions = { name: `Untitled(${Widget.WIDGET_GLOBAL_ID++})` }) {
56
- this.workspace = workspace;
57
- this.coords = options.coords ?? new Coordinates(0, 0);
58
- this.width = options.width ?? 200;
59
- this.height = options.height ?? 100;
60
- this.visible = false;
61
- this.name = options.name;
62
- this.id = generateUID('nanoid', { alphabet: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0129384756!)@(#*$&%^' });
63
- this.options = options;
64
- this.container = document.createElement("div");
65
- this.container.className = options.className ?? "KabelWidget";
66
- this.container.style.position = "absolute";
67
- this.container.style.left = `${this.coords.x}px`;
68
- this.container.style.top = `${this.coords.y}px`;
69
- this.container.style.width = `${this.width}px`;
70
- this.container.style.height = `${this.height}px`;
71
- this.container.style.background = "rgba(255,255,255,0.9)";
72
- this.container.style.border = "1px solid #aaa";
73
- this.container.style.borderRadius = "4px";
74
- this.container.style.boxShadow = "0 2px 6px rgba(0,0,0,0.2)";
75
- this.container.style.pointerEvents = "auto";
76
- this.container.style.zIndex = "1000"; // overlays nodes
77
-
78
- if (options.html) this.container.innerHTML = options.html;
79
-
80
- if (!this.workspace.isHeadless) (this.workspace as WorkspaceSvg)._wsTop.appendChild(this.container);
81
- this.hide();
82
- if (typeof options.init !== 'undefined' && options.init) {
83
- options.init(this, this.container);
84
- }
85
- }
86
-
87
- // Show the widget
88
- show() {
89
- this.container.style.display = "block";
90
- this.visible = true;
91
- }
92
-
93
- // Hide the widget
94
- hide() {
95
- this.container.style.display = "none";
96
- this.visible = false;
97
- }
98
-
99
- // Move the widget to new coords
100
- setCoords(coords: Coordinates) {
101
- this.coords = coords;
102
- this.container.style.left = `${coords.x}px`;
103
- this.container.style.top = `${coords.y}px`;
104
- }
105
-
106
- // Update the HTML content
107
- setHTML(html: string) {
108
- this.container.innerHTML = html;
109
- }
110
- // Bring widget back from the dead after a .destroy call
111
- reanimate() {
112
- this.container = document.createElement("div");
113
- this.container.className = this.options.className ?? "KabelWidget";
114
- this.container.style.position = "absolute";
115
- this.container.style.left = `${this.coords.x}px`;
116
- this.container.style.top = `${this.coords.y}px`;
117
- this.container.style.width = `${this.width}px`;
118
- this.container.style.height = `${this.height}px`;
119
- this.container.style.background = "rgba(255,255,255,0.9)";
120
- this.container.style.border = "1px solid #aaa";
121
- this.container.style.borderRadius = "4px";
122
- this.container.style.boxShadow = "0 2px 6px rgba(0,0,0,0.2)";
123
- this.container.style.pointerEvents = "auto";
124
- this.container.style.zIndex = "1000"; // overlays nodes
125
-
126
- if (this.options.html) this.container.innerHTML = this.options.html;
127
- if (this.workspace.isHeadless) return;
128
-
129
- (this.workspace as WorkspaceSvg)._wsTop.appendChild(this.container);
130
- this.workspace._addWidgetToDB(this);
131
- }
132
- // Destroy widget & cleanup.
133
- destroy() {
134
- this.container.remove();
135
- this.workspace._delWidgetFromDB(this);
136
- }
137
- }
138
-
139
- export default Widget;