@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.
- package/dist/comment-renderer/renderer.d.ts +32 -0
- package/dist/comment-renderer/renderer.d.ts.map +1 -0
- package/dist/controllers/base.d.ts +39 -0
- package/dist/controllers/base.d.ts.map +1 -0
- package/dist/controllers/wasd.d.ts +33 -0
- package/dist/controllers/wasd.d.ts.map +1 -0
- package/dist/events/comment-drag-handle.d.ts +2 -0
- package/dist/events/comment-drag-handle.d.ts.map +1 -0
- package/dist/events/comment-input.d.ts +4 -0
- package/dist/events/comment-input.d.ts.map +1 -0
- package/dist/events/connection-line.d.ts +2 -0
- package/dist/events/connection-line.d.ts.map +1 -0
- package/dist/events/connector.d.ts +2 -0
- package/dist/events/connector.d.ts.map +1 -0
- package/dist/events/draggable.d.ts +2 -0
- package/dist/events/draggable.d.ts.map +1 -0
- package/{events/events.ts → dist/events/events.d.ts} +8 -7
- package/dist/events/events.d.ts.map +1 -0
- package/dist/events/input-box.d.ts +2 -0
- package/dist/events/input-box.d.ts.map +1 -0
- package/dist/events/node-x-btn.d.ts +2 -0
- package/dist/events/node-x-btn.d.ts.map +1 -0
- package/dist/kabel.js +2 -0
- package/dist/kabel.js.map +1 -0
- package/dist/renderers/apollo/apollo.d.ts +12 -0
- package/dist/renderers/apollo/apollo.d.ts.map +1 -0
- package/dist/renderers/apollo/constants.d.ts +21 -0
- package/dist/renderers/apollo/constants.d.ts.map +1 -0
- package/dist/renderers/apollo/renderer.d.ts +97 -0
- package/dist/renderers/apollo/renderer.d.ts.map +1 -0
- package/{renderers/atlas/atlas.ts → dist/renderers/atlas/atlas.d.ts} +6 -15
- package/dist/renderers/atlas/atlas.d.ts.map +1 -0
- package/dist/renderers/constants.d.ts +51 -0
- package/dist/renderers/constants.d.ts.map +1 -0
- package/dist/renderers/renderer.d.ts +470 -0
- package/dist/renderers/renderer.d.ts.map +1 -0
- package/dist/renderers/representer-node.d.ts +27 -0
- package/dist/renderers/representer-node.d.ts.map +1 -0
- package/dist/renderers/representer.d.ts +13 -0
- package/dist/renderers/representer.d.ts.map +1 -0
- package/dist/src/category.d.ts +48 -0
- package/dist/src/category.d.ts.map +1 -0
- package/{src/colors.ts → dist/src/colors.d.ts} +21 -20
- package/dist/src/colors.d.ts.map +1 -0
- package/dist/src/comment.d.ts +88 -0
- package/dist/src/comment.d.ts.map +1 -0
- package/dist/src/connection.d.ts +52 -0
- package/dist/src/connection.d.ts.map +1 -0
- package/dist/src/context-menu.d.ts +76 -0
- package/dist/src/context-menu.d.ts.map +1 -0
- package/dist/src/coordinates.d.ts +52 -0
- package/dist/src/coordinates.d.ts.map +1 -0
- package/dist/src/core.d.ts +153 -0
- package/dist/src/core.d.ts.map +1 -0
- package/dist/src/ctx-menu-registry.d.ts +22 -0
- package/dist/src/ctx-menu-registry.d.ts.map +1 -0
- package/dist/src/dropdown-menu.d.ts +87 -0
- package/dist/src/dropdown-menu.d.ts.map +1 -0
- package/dist/src/field.d.ts +305 -0
- package/dist/src/field.d.ts.map +1 -0
- package/dist/src/flyout.d.ts +41 -0
- package/dist/src/flyout.d.ts.map +1 -0
- package/dist/src/fonts-manager.d.ts +6 -0
- package/dist/src/fonts-manager.d.ts.map +1 -0
- package/dist/src/grid.d.ts +60 -0
- package/dist/src/grid.d.ts.map +1 -0
- package/dist/src/headless-node.d.ts +11 -0
- package/dist/src/headless-node.d.ts.map +1 -0
- package/dist/src/index.d.ts +38 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/inject-headless.d.ts +4 -0
- package/dist/src/inject-headless.d.ts.map +1 -0
- package/{src/inject.ts → dist/src/inject.d.ts} +142 -213
- package/dist/src/inject.d.ts.map +1 -0
- package/{src/main-workspace.ts → dist/src/main-workspace.d.ts} +31 -51
- package/dist/src/main-workspace.d.ts.map +1 -0
- package/dist/src/mutator.d.ts +2 -0
- package/dist/src/mutator.d.ts.map +1 -0
- package/{src/node-types.ts → dist/src/node-types.d.ts} +26 -27
- package/dist/src/node-types.d.ts.map +1 -0
- package/dist/src/nodesvg.d.ts +266 -0
- package/dist/src/nodesvg.d.ts.map +1 -0
- package/{src/prototypes.ts → dist/src/prototypes.d.ts} +10 -9
- package/dist/src/prototypes.d.ts.map +1 -0
- package/{src/renderer-map.ts → dist/src/renderer-map.d.ts} +51 -86
- package/dist/src/renderer-map.d.ts.map +1 -0
- package/dist/src/toolbox.d.ts +51 -0
- package/dist/src/toolbox.d.ts.map +1 -0
- package/{src/types.ts → dist/src/types.d.ts} +159 -205
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/undo-redo.d.ts +15 -0
- package/dist/src/undo-redo.d.ts.map +1 -0
- package/{src/visual-types.ts → dist/src/visual-types.d.ts} +34 -29
- package/dist/src/visual-types.d.ts.map +1 -0
- package/dist/src/widget-prototypes.d.ts +10 -0
- package/dist/src/widget-prototypes.d.ts.map +1 -0
- package/dist/src/widget.d.ts +62 -0
- package/dist/src/widget.d.ts.map +1 -0
- package/{src/workspace-coords.ts → dist/src/workspace-coords.d.ts} +10 -14
- package/dist/src/workspace-coords.d.ts.map +1 -0
- package/dist/src/workspace-svg.d.ts +371 -0
- package/dist/src/workspace-svg.d.ts.map +1 -0
- package/dist/src/workspace.d.ts +50 -0
- package/dist/src/workspace.d.ts.map +1 -0
- package/dist/themes/dark.d.ts +4 -0
- package/dist/themes/dark.d.ts.map +1 -0
- package/dist/themes/default.d.ts +4 -0
- package/dist/themes/default.d.ts.map +1 -0
- package/dist/themes/themes.d.ts +6 -0
- package/dist/themes/themes.d.ts.map +1 -0
- package/dist/util/emitter.d.ts +10 -0
- package/dist/util/emitter.d.ts.map +1 -0
- package/dist/util/env.d.ts +7 -0
- package/dist/util/env.d.ts.map +1 -0
- package/{util/escape-html.ts → dist/util/escape-html.d.ts} +16 -22
- package/dist/util/escape-html.d.ts.map +1 -0
- package/dist/util/eventer.d.ts +29 -0
- package/dist/util/eventer.d.ts.map +1 -0
- package/dist/util/has-prop.d.ts +2 -0
- package/dist/util/has-prop.d.ts.map +1 -0
- package/dist/util/parse-color.d.ts +6 -0
- package/dist/util/parse-color.d.ts.map +1 -0
- package/dist/util/path.d.ts +25 -0
- package/dist/util/path.d.ts.map +1 -0
- package/dist/util/styler.d.ts +12 -0
- package/dist/util/styler.d.ts.map +1 -0
- package/dist/util/uid.d.ts +42 -0
- package/dist/util/uid.d.ts.map +1 -0
- package/{util/unescape-html.ts → dist/util/unescape-html.d.ts} +16 -22
- package/dist/util/unescape-html.d.ts.map +1 -0
- package/dist/util/user-state.d.ts +37 -0
- package/dist/util/user-state.d.ts.map +1 -0
- package/{util/wait-anim-frames.ts → dist/util/wait-anim-frames.d.ts} +11 -24
- package/dist/util/wait-anim-frames.d.ts.map +1 -0
- package/dist/util/window-listeners.d.ts +8 -0
- package/dist/util/window-listeners.d.ts.map +1 -0
- package/package.json +5 -2
- package/(1.0.7)kabel.md +0 -18
- package/_READ_ME_MEDIA_/documentation/docs.md +0 -293
- package/_READ_ME_MEDIA_/workspace.png +0 -0
- package/comment-renderer/renderer.ts +0 -228
- package/controllers/base.ts +0 -186
- package/controllers/wasd.ts +0 -132
- package/docs/README.md +0 -98
- package/docs/_media/docs.md +0 -289
- package/docs/_media/workspace.png +0 -0
- package/docs/classes/CommentModel.md +0 -271
- package/docs/classes/CommentRenderer.md +0 -457
- package/docs/classes/ConnectableField.md +0 -597
- package/docs/classes/Connection.md +0 -191
- package/docs/classes/ContextMenuHTML.md +0 -163
- package/docs/classes/Coordinates.md +0 -187
- package/docs/classes/DropdownContainer.md +0 -300
- package/docs/classes/DummyField.md +0 -393
- package/docs/classes/Eventer.md +0 -185
- package/docs/classes/Field.md +0 -461
- package/docs/classes/InjectMsg.md +0 -85
- package/docs/classes/NodeSvg.md +0 -1011
- package/docs/classes/NumberField.md +0 -559
- package/docs/classes/OptConnectField.md +0 -624
- package/docs/classes/Renderer.md +0 -1636
- package/docs/classes/RendererConstants.md +0 -343
- package/docs/classes/Representer.md +0 -95
- package/docs/classes/RepresenterNode.md +0 -175
- package/docs/classes/TextField.md +0 -559
- package/docs/classes/Toolbox.md +0 -172
- package/docs/classes/WASDController.md +0 -616
- package/docs/classes/Widget.md +0 -195
- package/docs/classes/WorkspaceController.md +0 -385
- package/docs/classes/WorkspaceCoords.md +0 -218
- package/docs/classes/WorkspaceSvg.md +0 -1380
- package/docs/functions/clearMainWorkspace.md +0 -20
- package/docs/functions/getMainWorkspace.md +0 -19
- package/docs/functions/inject.md +0 -35
- package/docs/functions/setMainWorkspace.md +0 -28
- package/docs/globals.md +0 -95
- package/docs/interfaces/ColorStyle.md +0 -43
- package/docs/interfaces/ConnectorToFrom.md +0 -57
- package/docs/interfaces/DrawState.md +0 -81
- package/docs/interfaces/FieldConnectionData.md +0 -25
- package/docs/interfaces/FieldOptions.md +0 -63
- package/docs/interfaces/FieldRawBoxData.md +0 -25
- package/docs/interfaces/FieldVisualInfo.md +0 -65
- package/docs/interfaces/GridOptions.md +0 -61
- package/docs/interfaces/InjectOptions.md +0 -133
- package/docs/interfaces/InputFieldJson.md +0 -50
- package/docs/interfaces/KabelCommentRendering.md +0 -31
- package/docs/interfaces/KabelInterface.md +0 -469
- package/docs/interfaces/KabelNodeRendering.md +0 -77
- package/docs/interfaces/KabelUIX.md +0 -105
- package/docs/interfaces/KabelUtils.md +0 -215
- package/docs/interfaces/NodeEvents.md +0 -42
- package/docs/interfaces/NodeJson.md +0 -104
- package/docs/interfaces/NodePrototype.md +0 -82
- package/docs/interfaces/RegisteredEl.md +0 -53
- package/docs/interfaces/SerializedNode.md +0 -128
- package/docs/interfaces/TblxCategoryStruct.md +0 -41
- package/docs/interfaces/TblxFieldStruct.md +0 -28
- package/docs/interfaces/TblxNodeStruct.md +0 -35
- package/docs/interfaces/WidgetOptions.md +0 -115
- package/docs/interfaces/WidgetPrototypeList.md +0 -15
- package/docs/type-aliases/AnyField.md +0 -13
- package/docs/type-aliases/AnyFieldCls.md +0 -13
- package/docs/type-aliases/Color.md +0 -13
- package/docs/type-aliases/Connectable.md +0 -13
- package/docs/type-aliases/EventArgs.md +0 -11
- package/docs/type-aliases/EventSetupFn.md +0 -25
- package/docs/type-aliases/Hex.md +0 -13
- package/docs/type-aliases/RGBObject.md +0 -37
- package/docs/type-aliases/RGBString.md +0 -13
- package/docs/type-aliases/RGBTuple.md +0 -13
- package/docs/type-aliases/TblxObjStruct.md +0 -52
- package/docs/variables/CategoryColors.md +0 -29
- package/docs/variables/FieldMap.md +0 -41
- package/docs/variables/NodePrototypes.md +0 -18
- package/docs/variables/default.md +0 -11
- package/events/comment-drag-handle.ts +0 -61
- package/events/comment-input.ts +0 -291
- package/events/connection-line.ts +0 -68
- package/events/connector.ts +0 -116
- package/events/draggable.ts +0 -119
- package/events/input-box.ts +0 -213
- package/events/node-x-btn.ts +0 -25
- package/index.d.ts +0 -4
- package/renderers/apollo/apollo.ts +0 -21
- package/renderers/apollo/constants.ts +0 -40
- package/renderers/apollo/renderer.ts +0 -331
- package/renderers/constants.ts +0 -87
- package/renderers/renderer.ts +0 -1288
- package/renderers/representer-node.ts +0 -52
- package/renderers/representer.ts +0 -25
- package/src/category.ts +0 -107
- package/src/comment.ts +0 -142
- package/src/connection.ts +0 -114
- package/src/context-menu.ts +0 -194
- package/src/coordinates.ts +0 -74
- package/src/core.ts +0 -202
- package/src/ctx-menu-registry.ts +0 -143
- package/src/dropdown-menu.ts +0 -215
- package/src/field.ts +0 -595
- package/src/flyout.ts +0 -165
- package/src/fonts-manager.ts +0 -38
- package/src/grid.ts +0 -162
- package/src/headless-node.ts +0 -27
- package/src/index.ts +0 -115
- package/src/inject-headless.ts +0 -18
- package/src/mutator.ts +0 -40
- package/src/nodesvg.ts +0 -756
- package/src/styles.css +0 -224
- package/src/toolbox.ts +0 -125
- package/src/undo-redo.ts +0 -87
- package/src/widget-prototypes.ts +0 -11
- package/src/widget.ts +0 -139
- package/src/workspace-svg.ts +0 -736
- package/src/workspace.ts +0 -155
- package/test-server.js +0 -61
- package/themes/dark.ts +0 -32
- package/themes/default.ts +0 -28
- package/themes/themes.ts +0 -9
- package/tsconfig.json +0 -25
- package/typedoc.json +0 -10
- package/util/emitter.ts +0 -33
- package/util/env.ts +0 -11
- package/util/eventer.ts +0 -108
- package/util/has-prop.ts +0 -4
- package/util/parse-color.ts +0 -42
- package/util/path.ts +0 -99
- package/util/styler.ts +0 -41
- package/util/uid.ts +0 -184
- package/util/user-state.ts +0 -68
- package/util/window-listeners.ts +0 -62
- package/webpack.config.js +0 -80
- /package/{docs/_media → dist}/index.html +0 -0
package/src/field.ts
DELETED
|
@@ -1,595 +0,0 @@
|
|
|
1
|
-
import Connection, { Connectable } from "./connection";
|
|
2
|
-
import { G, Path, Rect, Svg, SVG, Text } from '@svgdotjs/svg.js';
|
|
3
|
-
import NodeSvg from "./nodesvg";
|
|
4
|
-
import { ConnectorToFrom } from "../renderers/renderer";
|
|
5
|
-
import dropdownContainer, { DropdownOptions } from "./dropdown-menu";
|
|
6
|
-
import WorkspaceSvg from "./workspace-svg";
|
|
7
|
-
/**
|
|
8
|
-
* Options used to initialize a Field.
|
|
9
|
-
*/
|
|
10
|
-
export interface FieldOptions { /** Name of the field */
|
|
11
|
-
name: string;
|
|
12
|
-
/** Human-readable label for the field */
|
|
13
|
-
label: string;
|
|
14
|
-
/** Key used to identify the field type in FieldTypesMap */
|
|
15
|
-
type: string;
|
|
16
|
-
/** Field value (optional) */
|
|
17
|
-
value?: any;
|
|
18
|
-
/** Only used by OptConnectField to determine internal value type */
|
|
19
|
-
fld_type?: "number" | "string";
|
|
20
|
-
[key: string]: any;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export interface FieldVisualInfo {
|
|
24
|
-
measuredWidth: number; // The width approximated by the field itself.
|
|
25
|
-
measuredHeight: number; // The height approximated by the field itself.
|
|
26
|
-
background: Rect; // The node's background element.
|
|
27
|
-
svg: Svg; // The workspace's SVG.js svg
|
|
28
|
-
nodeGroup: G; // Group for the node
|
|
29
|
-
fieldGroup: G; // A group containing the label & input.
|
|
30
|
-
xUsed: number; // The amount of x space used up by the label.
|
|
31
|
-
}
|
|
32
|
-
export interface FieldRawBoxData {
|
|
33
|
-
box: Rect;
|
|
34
|
-
txt: Text;
|
|
35
|
-
}
|
|
36
|
-
export interface FieldConnectionData {
|
|
37
|
-
connector: Path;
|
|
38
|
-
connState: ConnectorToFrom
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Base class for all fields.
|
|
42
|
-
* @template T The type of the value stored in the field
|
|
43
|
-
*/
|
|
44
|
-
class Field<T = any> {
|
|
45
|
-
label: string;
|
|
46
|
-
name: string;
|
|
47
|
-
type: string;
|
|
48
|
-
node?: NodeSvg;
|
|
49
|
-
editable: boolean;
|
|
50
|
-
svgGroup?: G;
|
|
51
|
-
protected value: T | null;
|
|
52
|
-
static register(name: string, cls: Function) { };
|
|
53
|
-
static unregister(name: string) { };
|
|
54
|
-
constructor() {
|
|
55
|
-
this.label = '';
|
|
56
|
-
this.name = '';
|
|
57
|
-
this.type = '';
|
|
58
|
-
this.value = null;
|
|
59
|
-
this.editable = true;
|
|
60
|
-
}
|
|
61
|
-
onDraw(rawBox?: FieldRawBoxData, connectionBubble?: FieldConnectionData) {
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
canEditConnector() {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Set whether or not you can edit this field.
|
|
69
|
-
* @param val - The value to set to.
|
|
70
|
-
*/
|
|
71
|
-
setEditable(val: boolean) {
|
|
72
|
-
this.editable = val;
|
|
73
|
-
if (this.node) {
|
|
74
|
-
this.node?.workspace?.renderer?.rerenderNode?.(this.node)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Ask whether or not we can edit this field.
|
|
79
|
-
*/
|
|
80
|
-
canEdit() {
|
|
81
|
-
return this.editable;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Set field name to something else.
|
|
85
|
-
* @param name string
|
|
86
|
-
* @returns the new name.
|
|
87
|
-
*/
|
|
88
|
-
setName(name: string) {
|
|
89
|
-
return this.name = name;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Initialize the field from JSON options.
|
|
93
|
-
* @param json FieldOptions object
|
|
94
|
-
*/
|
|
95
|
-
fromJson(json: FieldOptions, workspace?: WorkspaceSvg) {
|
|
96
|
-
if (json.name !== undefined) this.name = json.name;
|
|
97
|
-
if (json.label !== undefined) this.label = json.label;
|
|
98
|
-
if (json.type !== undefined) this.type = json.type;
|
|
99
|
-
if (json.value !== undefined) this.value = json.value;
|
|
100
|
-
if (json.editable) this.setEditable(Boolean(json.editable));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** @returns The field's name/key */
|
|
104
|
-
getName(): string {
|
|
105
|
-
return this.name;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** @returns The human-readable label */
|
|
109
|
-
getLabel(): string {
|
|
110
|
-
return this.label;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Set the human-readable label
|
|
115
|
-
* @param label New label
|
|
116
|
-
* @returns The updated label
|
|
117
|
-
*/
|
|
118
|
-
setLabel(label: string): string {
|
|
119
|
-
return this.label = label;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/** @returns Whether this field is a raw value field (text/number) */
|
|
123
|
-
hasRaw(): boolean {
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** @returns Whether this field supports connections */
|
|
128
|
-
hasConnectable(): boolean {
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
/** @returns Whether we have a custom editor/input look */
|
|
132
|
-
isCustomEditor(): boolean {
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Make the input's custom look.
|
|
137
|
-
* @param fieldVisualInfo - The visual info of the field, mutate this if needed.
|
|
138
|
-
*/
|
|
139
|
-
drawMyself(fieldVisualInfo: FieldVisualInfo) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
/** Return width & height of your field's custom editor */
|
|
143
|
-
measureMyself() {
|
|
144
|
-
return { width: null, height: null }; // if either is null then the renderer measures for us (meaning we have a connection or other type of raw field.)
|
|
145
|
-
}
|
|
146
|
-
/** @returns The stored value */
|
|
147
|
-
getValue(): T | null {
|
|
148
|
-
return this.value;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Set the stored value
|
|
153
|
-
* @param val New value
|
|
154
|
-
*/
|
|
155
|
-
setValue(val: T) {
|
|
156
|
-
this.value = val;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/** @returns The value as it should be displayed (can differ from internal value) */
|
|
160
|
-
getDisplayValue(): T | null {
|
|
161
|
-
return this.getValue();
|
|
162
|
-
}
|
|
163
|
-
toJson(deep: boolean, alreadyProcessed: { [key: string]: any }): FieldOptions {
|
|
164
|
-
return {
|
|
165
|
-
name: this.name,
|
|
166
|
-
label: this.label,
|
|
167
|
-
type: this.type,
|
|
168
|
-
value: this.getValue()
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Used when you want just a label with no actual value. Any value related methods are no-op.
|
|
174
|
-
*/
|
|
175
|
-
export class DummyField {
|
|
176
|
-
label: string;
|
|
177
|
-
name: string;
|
|
178
|
-
type: string;
|
|
179
|
-
node?: NodeSvg;
|
|
180
|
-
editable: boolean;
|
|
181
|
-
svgGroup?: G;
|
|
182
|
-
|
|
183
|
-
constructor() {
|
|
184
|
-
this.label = '';
|
|
185
|
-
this.name = '';
|
|
186
|
-
this.type = '';
|
|
187
|
-
this.editable = false;
|
|
188
|
-
}
|
|
189
|
-
onDraw(rawBox?: FieldRawBoxData, connectionBubble?: FieldConnectionData) {
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
canEditConnector() {
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Set whether or not you can edit this field.
|
|
197
|
-
* @param val - The value to set to.
|
|
198
|
-
*/
|
|
199
|
-
setEditable(val: boolean) {
|
|
200
|
-
this.editable = val;
|
|
201
|
-
if (this.node) {
|
|
202
|
-
this.node?.workspace?.renderer?.rerenderNode?.(this.node)
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Ask whether or not we can edit this field.
|
|
207
|
-
*/
|
|
208
|
-
canEdit() {
|
|
209
|
-
return this.editable;
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Set field name to something else.
|
|
213
|
-
* @param name string
|
|
214
|
-
* @returns the new name.
|
|
215
|
-
*/
|
|
216
|
-
setName(name: string) {
|
|
217
|
-
return this.name = name;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Initialize the field from JSON options.
|
|
221
|
-
* @param json FieldOptions object
|
|
222
|
-
*/
|
|
223
|
-
fromJson(json: FieldOptions) {
|
|
224
|
-
if (json.name !== undefined) this.name = json.name;
|
|
225
|
-
if (json.label !== undefined) this.label = json.label;
|
|
226
|
-
if (json.type !== undefined) this.type = json.type;
|
|
227
|
-
}
|
|
228
|
-
/** @returns Whether this field is a raw value field (text/number) */
|
|
229
|
-
hasRaw(): boolean {
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/** @returns Whether this field supports connections */
|
|
234
|
-
hasConnectable(): boolean {
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
/** @returns The field's name/key */
|
|
238
|
-
getName(): string {
|
|
239
|
-
return this.name;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/** @returns The human-readable label */
|
|
243
|
-
getLabel(): string {
|
|
244
|
-
return this.label;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Set the human-readable label
|
|
248
|
-
* @param label New label
|
|
249
|
-
* @returns The updated label
|
|
250
|
-
*/
|
|
251
|
-
setLabel(label: string): string {
|
|
252
|
-
return this.label = label;
|
|
253
|
-
}
|
|
254
|
-
/** @returns Whether we have a custom editor/input look */
|
|
255
|
-
isCustomEditor(): boolean {
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Make the input's custom look.
|
|
260
|
-
* @param fieldVisualInfo - The visual info of the field, mutate this if needed.
|
|
261
|
-
*/
|
|
262
|
-
drawMyself(fieldVisualInfo: FieldVisualInfo) {
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
/** Return width & height of your field's custom editor */
|
|
266
|
-
measureMyself() {
|
|
267
|
-
return { width: 0, height: 0 }; // if either is null then the renderer measures for us (meaning we have a connection or other type of raw field.)
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Dummy fields have no value.
|
|
271
|
-
* @returns {null}
|
|
272
|
-
*/
|
|
273
|
-
getValue() {
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* No-op for dummy fields
|
|
278
|
-
*/
|
|
279
|
-
setValue(_: any) { }
|
|
280
|
-
/** @returns The value as it should be displayed (can differ from internal value) */
|
|
281
|
-
getDisplayValue() {
|
|
282
|
-
return this.getValue();
|
|
283
|
-
}
|
|
284
|
-
toJson(deep: boolean, alreadyProcessed: { [key: string]: any }): FieldOptions {
|
|
285
|
-
return {
|
|
286
|
-
name: this.name,
|
|
287
|
-
label: this.label,
|
|
288
|
-
type: this.type,
|
|
289
|
-
value: this.getValue()
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Base class for fields that can be connected to other fields.
|
|
295
|
-
* @template T The type of the value stored in the field
|
|
296
|
-
*/
|
|
297
|
-
export class ConnectableField<T = any> extends Field<T> {
|
|
298
|
-
connection: Connection;
|
|
299
|
-
|
|
300
|
-
constructor() {
|
|
301
|
-
super();
|
|
302
|
-
this.connection = new Connection(this, null);
|
|
303
|
-
this.value = null as T;
|
|
304
|
-
}
|
|
305
|
-
hasConnectable(): boolean {
|
|
306
|
-
return true;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
hasRaw(): boolean {
|
|
310
|
-
return false;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/** Disconnect this field from any connected Connectable */
|
|
314
|
-
disconnect() {
|
|
315
|
-
const to = this.connection.to;
|
|
316
|
-
if (to instanceof NodeSvg && to?.previousConnection?.from) {
|
|
317
|
-
to.previousConnection.from = null;
|
|
318
|
-
this.connection.to = null;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
fromJson(json: FieldOptions, workspace?: WorkspaceSvg) {
|
|
322
|
-
super.fromJson(json);
|
|
323
|
-
|
|
324
|
-
// If the value is a serialized node, rebuild it
|
|
325
|
-
if (json.value && typeof json.value === "object" && json.value.id) {
|
|
326
|
-
this.value = NodeSvg._deserialize(json.value, {}, workspace) as any;
|
|
327
|
-
this.connection.setTo(this.value as Connectable);
|
|
328
|
-
} else if (json.value instanceof NodeSvg) {
|
|
329
|
-
this.value = json.value as any;
|
|
330
|
-
this.connection.setTo(this.value as Connectable);
|
|
331
|
-
} else {
|
|
332
|
-
this.value = json.value;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return this;
|
|
336
|
-
}
|
|
337
|
-
toJson(deep: boolean, alreadyProcessed: { [key: string]: any }): FieldOptions {
|
|
338
|
-
let val: any = this.getValue();
|
|
339
|
-
// If it's connected to a node, store it's serialized form.
|
|
340
|
-
if (val instanceof NodeSvg) val = { node: alreadyProcessed[val.id] ? (deep ? alreadyProcessed[val.id] : val.id) : val.serialize(alreadyProcessed) };
|
|
341
|
-
|
|
342
|
-
return {
|
|
343
|
-
...super.toJson(true, alreadyProcessed),
|
|
344
|
-
value: val
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/** Field storing a numeric value */
|
|
350
|
-
export class NumberField extends Field<number> {
|
|
351
|
-
constructor() {
|
|
352
|
-
super();
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
fromJson(json: FieldOptions) {
|
|
356
|
-
super.fromJson(json);
|
|
357
|
-
if (json.value !== undefined) this.setValue(Number(json.value));
|
|
358
|
-
}
|
|
359
|
-
setValue(val: number) {
|
|
360
|
-
this.value = Number(val);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/** Field storing a string value */
|
|
365
|
-
export class TextField extends Field<string> {
|
|
366
|
-
constructor() {
|
|
367
|
-
super();
|
|
368
|
-
}
|
|
369
|
-
fromJson(json: FieldOptions) {
|
|
370
|
-
super.fromJson(json);
|
|
371
|
-
if (json.value !== undefined) this.setValue(String(json.value));
|
|
372
|
-
}
|
|
373
|
-
setValue(val: string) {
|
|
374
|
-
this.value = String(val);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Optional connectable field.
|
|
380
|
-
* Can store either a number or string depending on fld_type.
|
|
381
|
-
*/
|
|
382
|
-
export class OptConnectField extends ConnectableField<number | string | NodeSvg> {
|
|
383
|
-
fldType: "number" | "string";
|
|
384
|
-
|
|
385
|
-
constructor() {
|
|
386
|
-
super();
|
|
387
|
-
this.fldType = "string";
|
|
388
|
-
}
|
|
389
|
-
canEditConnector(): boolean {
|
|
390
|
-
return true;
|
|
391
|
-
}
|
|
392
|
-
canEdit() {
|
|
393
|
-
if (this.getValue() instanceof NodeSvg) {
|
|
394
|
-
return false;
|
|
395
|
-
}
|
|
396
|
-
return this.editable;
|
|
397
|
-
}
|
|
398
|
-
getValue(): string | number | NodeSvg | null {
|
|
399
|
-
if (this.connection && this.connection.getTo()) {
|
|
400
|
-
return this.connection.getTo() as NodeSvg;
|
|
401
|
-
} else {
|
|
402
|
-
return this.value;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
hasRaw() {
|
|
406
|
-
return true;
|
|
407
|
-
}
|
|
408
|
-
hasConnectable() {
|
|
409
|
-
return true;
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Set field type.
|
|
413
|
-
* @param type "number"|"string"
|
|
414
|
-
*/
|
|
415
|
-
setFieldType(type: "number" | "string") {
|
|
416
|
-
this.fldType = type;
|
|
417
|
-
}
|
|
418
|
-
/**
|
|
419
|
-
* Initialize from JSON, respecting fld_type
|
|
420
|
-
* @param json FieldOptions
|
|
421
|
-
*/
|
|
422
|
-
fromJson(json: FieldOptions, workspace?: WorkspaceSvg) {
|
|
423
|
-
super.fromJson(json, workspace);
|
|
424
|
-
this.fldType = json.fld_type || "string";
|
|
425
|
-
if (this.value != null && typeof this.value === this.fldType) {
|
|
426
|
-
this.setValue(this.value as number | string);
|
|
427
|
-
}
|
|
428
|
-
return this;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* Set the value, converting to number or string depending on fld_type
|
|
433
|
-
* @param val The new value
|
|
434
|
-
*/
|
|
435
|
-
setValue(val: number | string) {
|
|
436
|
-
if (this.fldType === "number") this.value = Number(val);
|
|
437
|
-
else this.value = String(val);
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* @returns Display value for UI purposes (never null)
|
|
442
|
-
*/
|
|
443
|
-
getDisplayValue(): string {
|
|
444
|
-
if (this.value == null) return this.fldType === "number" ? "0" : "";
|
|
445
|
-
if (this.getValue() instanceof NodeSvg) return '[NODE]'; // If theres a connection
|
|
446
|
-
return String(this.value);
|
|
447
|
-
}
|
|
448
|
-
toJson(deep: boolean, alreadyProcessed: { [key: string]: any }): FieldOptions {
|
|
449
|
-
let val: any = this.getValue();
|
|
450
|
-
// If it's connected to a node, store it's serialized form.
|
|
451
|
-
if (val instanceof NodeSvg) val = { node: deep ? val.serialize(alreadyProcessed) : val.id };
|
|
452
|
-
|
|
453
|
-
return {
|
|
454
|
-
...super.toJson(true, alreadyProcessed),
|
|
455
|
-
fld_type: this.fldType,
|
|
456
|
-
value: val
|
|
457
|
-
};
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
export type DropdownItem = { text: string, value: string } | string
|
|
461
|
-
export class DropdownField extends Field<string> {
|
|
462
|
-
options: DropdownItem[] | null;
|
|
463
|
-
_selected: DropdownItem | null;
|
|
464
|
-
_isOpen: boolean;
|
|
465
|
-
|
|
466
|
-
constructor() {
|
|
467
|
-
super();
|
|
468
|
-
this.options = null;
|
|
469
|
-
this._selected = null;
|
|
470
|
-
this._isOpen = false;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
onDraw(rawBox?: FieldRawBoxData) {
|
|
474
|
-
if (!rawBox || !this.options) return;
|
|
475
|
-
|
|
476
|
-
const { box, txt } = rawBox;
|
|
477
|
-
const toggle = () => this.toggleDropdown(rawBox);
|
|
478
|
-
box.click(toggle);
|
|
479
|
-
txt.click(toggle);
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
private toggleDropdown(rawBox: FieldRawBoxData) {
|
|
483
|
-
if (dropdownContainer.getOwner() === this) {
|
|
484
|
-
this.closeDropdown();
|
|
485
|
-
} else {
|
|
486
|
-
this.openDropdown(rawBox);
|
|
487
|
-
}
|
|
488
|
-
rawBox.txt.text(this.getDisplayValue());
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
private openDropdown(rawBox: FieldRawBoxData) {
|
|
492
|
-
if (!this.options) return;
|
|
493
|
-
|
|
494
|
-
const items = this.options.map(option => ({
|
|
495
|
-
label: typeof option === 'string' ? option : option.text,
|
|
496
|
-
value: typeof option === 'string' ? option : option.value
|
|
497
|
-
}));
|
|
498
|
-
|
|
499
|
-
dropdownContainer.show(this, {
|
|
500
|
-
items,
|
|
501
|
-
width: rawBox.box.bbox().width * 2,
|
|
502
|
-
onSelect: (value: string) => {
|
|
503
|
-
if (!this.options) return;
|
|
504
|
-
const original = this.options.find(
|
|
505
|
-
e => e === value || (typeof e !== 'string' && e.value === value)
|
|
506
|
-
);
|
|
507
|
-
if (original) {
|
|
508
|
-
this._selected = original;
|
|
509
|
-
this.setValue(value);
|
|
510
|
-
this.closeDropdown();
|
|
511
|
-
this?.node?.workspace?.emitChange?.();
|
|
512
|
-
this?.node?.workspace?.renderer?.rerenderNode?.(this.node);
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
} as DropdownOptions);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
private closeDropdown() {
|
|
519
|
-
dropdownContainer.hideIfOwner(this);
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
canEdit() {
|
|
523
|
-
return false;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
getSelected() {
|
|
527
|
-
return this._selected;
|
|
528
|
-
}
|
|
529
|
-
fromJson(json: FieldOptions) {
|
|
530
|
-
super.fromJson(json);
|
|
531
|
-
this.options = json.options as DropdownItem[] || null;
|
|
532
|
-
this._selected = this.options?.[0] ?? null;
|
|
533
|
-
if (this._selected) this.setValue(typeof this._selected === 'string' ? this._selected : this._selected.value);
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
/**
|
|
537
|
-
* Display value of dropdowns.
|
|
538
|
-
* @returns - Display value
|
|
539
|
-
*/
|
|
540
|
-
getDisplayValue(): string {
|
|
541
|
-
const text = typeof this._selected === 'string' ? this._selected : this._selected?.text || '';
|
|
542
|
-
const arrow = dropdownContainer.getOwner() == this ? '▲' : '▼'; // toggles open/closed
|
|
543
|
-
return text + ' ' + arrow;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* Set options on this dropdown
|
|
548
|
-
* @param options - List of options
|
|
549
|
-
*/
|
|
550
|
-
setOptions(options: DropdownItem[]) {
|
|
551
|
-
this.options = options;
|
|
552
|
-
this._selected = this.options?.[0] ?? null;
|
|
553
|
-
if (this._selected) this.setValue(
|
|
554
|
-
typeof this._selected === 'string' ? this._selected : this._selected.value
|
|
555
|
-
);
|
|
556
|
-
}
|
|
557
|
-
/**
|
|
558
|
-
*
|
|
559
|
-
* @param deep - Whether to recursive it.
|
|
560
|
-
* @param alreadyProcessed - Map of already serialized nodes.
|
|
561
|
-
* @returns - Json of this field.
|
|
562
|
-
*/
|
|
563
|
-
toJson(deep: boolean, alreadyProcessed: { [key: string]: any }): FieldOptions {
|
|
564
|
-
return { ...super.toJson(deep, alreadyProcessed), options: this.options };
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
/**
|
|
569
|
-
* Any field instance type
|
|
570
|
-
*/
|
|
571
|
-
export type AnyField = Field | OptConnectField | NumberField | TextField | DummyField | ConnectableField;
|
|
572
|
-
/**
|
|
573
|
-
* Any field class type
|
|
574
|
-
*/
|
|
575
|
-
export type AnyFieldCls = typeof Field | typeof OptConnectField | typeof ConnectableField | typeof NumberField | typeof TextField | typeof DummyField;
|
|
576
|
-
export const FieldMap: {
|
|
577
|
-
field_both: typeof OptConnectField;
|
|
578
|
-
field_string: typeof TextField;
|
|
579
|
-
field_num: typeof NumberField;
|
|
580
|
-
field_dummy: typeof DummyField;
|
|
581
|
-
field_str: typeof TextField;
|
|
582
|
-
connection: typeof ConnectableField;
|
|
583
|
-
[key: string]: AnyFieldCls;
|
|
584
|
-
} = {
|
|
585
|
-
'field_both': OptConnectField,
|
|
586
|
-
'field_string': TextField,
|
|
587
|
-
'field_num': NumberField,
|
|
588
|
-
'field_dummy': DummyField,
|
|
589
|
-
'field_str': TextField,
|
|
590
|
-
'connection': ConnectableField,
|
|
591
|
-
'dropdown': DropdownField
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
export default Field;
|