@kabel-project/kabel 1.0.7

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 (152) hide show
  1. package/(1.0.7)kabel.md +18 -0
  2. package/README.md +96 -0
  3. package/_READ_ME_MEDIA_/documentation/docs.md +293 -0
  4. package/_READ_ME_MEDIA_/workspace.png +0 -0
  5. package/comment-renderer/renderer.ts +228 -0
  6. package/controllers/base.ts +186 -0
  7. package/controllers/wasd.ts +132 -0
  8. package/docs/README.md +98 -0
  9. package/docs/_media/docs.md +289 -0
  10. package/docs/_media/index.html +168 -0
  11. package/docs/_media/workspace.png +0 -0
  12. package/docs/classes/CommentModel.md +271 -0
  13. package/docs/classes/CommentRenderer.md +457 -0
  14. package/docs/classes/ConnectableField.md +597 -0
  15. package/docs/classes/Connection.md +191 -0
  16. package/docs/classes/ContextMenuHTML.md +163 -0
  17. package/docs/classes/Coordinates.md +187 -0
  18. package/docs/classes/DropdownContainer.md +300 -0
  19. package/docs/classes/DummyField.md +393 -0
  20. package/docs/classes/Eventer.md +185 -0
  21. package/docs/classes/Field.md +461 -0
  22. package/docs/classes/InjectMsg.md +85 -0
  23. package/docs/classes/NodeSvg.md +1011 -0
  24. package/docs/classes/NumberField.md +559 -0
  25. package/docs/classes/OptConnectField.md +624 -0
  26. package/docs/classes/Renderer.md +1636 -0
  27. package/docs/classes/RendererConstants.md +343 -0
  28. package/docs/classes/Representer.md +95 -0
  29. package/docs/classes/RepresenterNode.md +175 -0
  30. package/docs/classes/TextField.md +559 -0
  31. package/docs/classes/Toolbox.md +172 -0
  32. package/docs/classes/WASDController.md +616 -0
  33. package/docs/classes/Widget.md +195 -0
  34. package/docs/classes/WorkspaceController.md +385 -0
  35. package/docs/classes/WorkspaceCoords.md +218 -0
  36. package/docs/classes/WorkspaceSvg.md +1380 -0
  37. package/docs/functions/clearMainWorkspace.md +20 -0
  38. package/docs/functions/getMainWorkspace.md +19 -0
  39. package/docs/functions/inject.md +35 -0
  40. package/docs/functions/setMainWorkspace.md +28 -0
  41. package/docs/globals.md +95 -0
  42. package/docs/interfaces/ColorStyle.md +43 -0
  43. package/docs/interfaces/ConnectorToFrom.md +57 -0
  44. package/docs/interfaces/DrawState.md +81 -0
  45. package/docs/interfaces/FieldConnectionData.md +25 -0
  46. package/docs/interfaces/FieldOptions.md +63 -0
  47. package/docs/interfaces/FieldRawBoxData.md +25 -0
  48. package/docs/interfaces/FieldVisualInfo.md +65 -0
  49. package/docs/interfaces/GridOptions.md +61 -0
  50. package/docs/interfaces/InjectOptions.md +133 -0
  51. package/docs/interfaces/InputFieldJson.md +50 -0
  52. package/docs/interfaces/KabelCommentRendering.md +31 -0
  53. package/docs/interfaces/KabelInterface.md +469 -0
  54. package/docs/interfaces/KabelNodeRendering.md +77 -0
  55. package/docs/interfaces/KabelUIX.md +105 -0
  56. package/docs/interfaces/KabelUtils.md +215 -0
  57. package/docs/interfaces/NodeEvents.md +42 -0
  58. package/docs/interfaces/NodeJson.md +104 -0
  59. package/docs/interfaces/NodePrototype.md +82 -0
  60. package/docs/interfaces/RegisteredEl.md +53 -0
  61. package/docs/interfaces/SerializedNode.md +128 -0
  62. package/docs/interfaces/TblxCategoryStruct.md +41 -0
  63. package/docs/interfaces/TblxFieldStruct.md +28 -0
  64. package/docs/interfaces/TblxNodeStruct.md +35 -0
  65. package/docs/interfaces/WidgetOptions.md +115 -0
  66. package/docs/interfaces/WidgetPrototypeList.md +15 -0
  67. package/docs/type-aliases/AnyField.md +13 -0
  68. package/docs/type-aliases/AnyFieldCls.md +13 -0
  69. package/docs/type-aliases/Color.md +13 -0
  70. package/docs/type-aliases/Connectable.md +13 -0
  71. package/docs/type-aliases/EventArgs.md +11 -0
  72. package/docs/type-aliases/EventSetupFn.md +25 -0
  73. package/docs/type-aliases/Hex.md +13 -0
  74. package/docs/type-aliases/RGBObject.md +37 -0
  75. package/docs/type-aliases/RGBString.md +13 -0
  76. package/docs/type-aliases/RGBTuple.md +13 -0
  77. package/docs/type-aliases/TblxObjStruct.md +52 -0
  78. package/docs/variables/CategoryColors.md +29 -0
  79. package/docs/variables/FieldMap.md +41 -0
  80. package/docs/variables/NodePrototypes.md +18 -0
  81. package/docs/variables/default.md +11 -0
  82. package/events/comment-drag-handle.ts +61 -0
  83. package/events/comment-input.ts +291 -0
  84. package/events/connection-line.ts +68 -0
  85. package/events/connector.ts +116 -0
  86. package/events/draggable.ts +119 -0
  87. package/events/events.ts +7 -0
  88. package/events/input-box.ts +213 -0
  89. package/events/node-x-btn.ts +25 -0
  90. package/index.d.ts +4 -0
  91. package/package.json +49 -0
  92. package/renderers/apollo/apollo.ts +21 -0
  93. package/renderers/apollo/constants.ts +40 -0
  94. package/renderers/apollo/renderer.ts +331 -0
  95. package/renderers/atlas/atlas.ts +15 -0
  96. package/renderers/constants.ts +87 -0
  97. package/renderers/renderer.ts +1288 -0
  98. package/renderers/representer-node.ts +52 -0
  99. package/renderers/representer.ts +25 -0
  100. package/src/category.ts +107 -0
  101. package/src/colors.ts +20 -0
  102. package/src/comment.ts +142 -0
  103. package/src/connection.ts +114 -0
  104. package/src/context-menu.ts +194 -0
  105. package/src/coordinates.ts +74 -0
  106. package/src/core.ts +202 -0
  107. package/src/ctx-menu-registry.ts +143 -0
  108. package/src/dropdown-menu.ts +215 -0
  109. package/src/field.ts +595 -0
  110. package/src/flyout.ts +165 -0
  111. package/src/fonts-manager.ts +38 -0
  112. package/src/grid.ts +162 -0
  113. package/src/headless-node.ts +27 -0
  114. package/src/index.ts +115 -0
  115. package/src/inject-headless.ts +18 -0
  116. package/src/inject.ts +213 -0
  117. package/src/main-workspace.ts +51 -0
  118. package/src/mutator.ts +40 -0
  119. package/src/node-types.ts +27 -0
  120. package/src/nodesvg.ts +756 -0
  121. package/src/prototypes.ts +9 -0
  122. package/src/renderer-map.ts +86 -0
  123. package/src/styles.css +224 -0
  124. package/src/toolbox.ts +125 -0
  125. package/src/types.ts +205 -0
  126. package/src/undo-redo.ts +87 -0
  127. package/src/visual-types.ts +29 -0
  128. package/src/widget-prototypes.ts +11 -0
  129. package/src/widget.ts +139 -0
  130. package/src/workspace-coords.ts +14 -0
  131. package/src/workspace-svg.ts +736 -0
  132. package/src/workspace.ts +155 -0
  133. package/test-server.js +61 -0
  134. package/themes/dark.ts +32 -0
  135. package/themes/default.ts +28 -0
  136. package/themes/themes.ts +9 -0
  137. package/tsconfig.json +25 -0
  138. package/typedoc.json +10 -0
  139. package/util/emitter.ts +33 -0
  140. package/util/env.ts +11 -0
  141. package/util/escape-html.ts +22 -0
  142. package/util/eventer.ts +108 -0
  143. package/util/has-prop.ts +4 -0
  144. package/util/parse-color.ts +42 -0
  145. package/util/path.ts +99 -0
  146. package/util/styler.ts +41 -0
  147. package/util/uid.ts +184 -0
  148. package/util/unescape-html.ts +22 -0
  149. package/util/user-state.ts +68 -0
  150. package/util/wait-anim-frames.ts +24 -0
  151. package/util/window-listeners.ts +62 -0
  152. package/webpack.config.js +80 -0
@@ -0,0 +1,87 @@
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
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * A RGB array (ex: {r: 255, g: 255, b: 255})
3
+ */
4
+ export type RGBObject = { r: number; g: number; b: number };
5
+ /**
6
+ * A RGB tuple (ex: [255, 255, 255])
7
+ */
8
+ export type RGBTuple = [number, number, number];
9
+ /**
10
+ * A RGB string (ex: '255, 255, 255')
11
+ */
12
+ export type RGBString = `${number}, ${number}, ${number}`;
13
+ /**
14
+ * A hex color
15
+ */
16
+ export type Hex = `#${string}`;
17
+ /**
18
+ * A color, whether it be #ffffff, {r, g, b}, 'r, g, b', or [r, g, b]
19
+ */
20
+ export type Color = RGBObject | RGBString | RGBTuple | Hex;
21
+ /**
22
+ * Stores color data for a visual element on screen.
23
+ */
24
+ export interface ColorStyle {
25
+ primary: Color;
26
+ secondary: Color;
27
+ tertiary: Color;
28
+ category?: string;
29
+ }
@@ -0,0 +1,11 @@
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 ADDED
@@ -0,0 +1,139 @@
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;
@@ -0,0 +1,14 @@
1
+ import Coordinates from "./coordinates";
2
+
3
+
4
+
5
+ /**
6
+ * A class that represents Workspace Camera Coords.
7
+ * May be used in the future, right now its a no-op Coords wrapper.
8
+ */
9
+ class WorkspaceCoords extends Coordinates {
10
+ constructor(x = 0, y = 0) {
11
+ super(x, y);
12
+ }
13
+ }
14
+ export default WorkspaceCoords;