@elicdavis/node-flow 0.2.0 → 0.2.1
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/index.d.mts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +82 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +82 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/graph.ts +7 -4
- package/src/index.ts +2 -2
- package/src/widgets/inplace.ts +75 -23
- package/src/widgets/number.ts +5 -12
- package/src/widgets/string.ts +1 -8
- package/src/widgets/widget.ts +201 -180
- package/test/support.ts +15 -2
- package/test/widgets.test.ts +54 -1
package/dist/index.mjs
CHANGED
|
@@ -2093,40 +2093,72 @@ function drawFieldText(ctx, box, scale, look) {
|
|
|
2093
2093
|
}
|
|
2094
2094
|
|
|
2095
2095
|
// src/widgets/inplace.ts
|
|
2096
|
+
var open = /* @__PURE__ */ new Set();
|
|
2097
|
+
function placeEditsDuring(canvas, draw) {
|
|
2098
|
+
open.forEach((edit) => {
|
|
2099
|
+
if (edit.canvas === canvas) {
|
|
2100
|
+
edit.placed = false;
|
|
2101
|
+
}
|
|
2102
|
+
});
|
|
2103
|
+
draw();
|
|
2104
|
+
open.forEach((edit) => {
|
|
2105
|
+
if (edit.canvas === canvas && !edit.placed) {
|
|
2106
|
+
edit.input.style.opacity = "0";
|
|
2107
|
+
edit.input.style.pointerEvents = "none";
|
|
2108
|
+
}
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2096
2111
|
function editInPlace(config) {
|
|
2097
2112
|
const canvas = config.canvas;
|
|
2098
2113
|
if (canvas === null) {
|
|
2099
2114
|
return null;
|
|
2100
2115
|
}
|
|
2101
|
-
const rect = canvas.getBoundingClientRect();
|
|
2102
|
-
const sx = canvas.width > 0 ? rect.width / canvas.width : 1;
|
|
2103
|
-
const sy = canvas.height > 0 ? rect.height / canvas.height : 1;
|
|
2104
2116
|
const input = document.createElement("input");
|
|
2105
2117
|
input.type = "text";
|
|
2106
2118
|
input.value = config.value;
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2119
|
+
const edit = { canvas, input, placed: true };
|
|
2120
|
+
const place = (box, scale) => {
|
|
2121
|
+
const rect = canvas.getBoundingClientRect();
|
|
2122
|
+
const sx = canvas.width > 0 ? rect.width / canvas.width : 1;
|
|
2123
|
+
const sy = canvas.height > 0 ? rect.height / canvas.height : 1;
|
|
2124
|
+
const left = rect.left + box.Position.x * sx;
|
|
2125
|
+
const top = rect.top + box.Position.y * sy;
|
|
2126
|
+
const width2 = box.Size.x * sx;
|
|
2127
|
+
const height2 = box.Size.y * sy;
|
|
2128
|
+
const clip = [
|
|
2129
|
+
Math.max(0, rect.top - top),
|
|
2130
|
+
Math.max(0, left + width2 - (rect.left + rect.width)),
|
|
2131
|
+
Math.max(0, top + height2 - (rect.top + rect.height)),
|
|
2132
|
+
Math.max(0, rect.left - left)
|
|
2133
|
+
];
|
|
2134
|
+
edit.placed = true;
|
|
2135
|
+
input.style.cssText = [
|
|
2136
|
+
"position: fixed",
|
|
2137
|
+
`left: ${left}px`,
|
|
2138
|
+
`top: ${top}px`,
|
|
2139
|
+
`width: ${width2}px`,
|
|
2140
|
+
`height: ${height2}px`,
|
|
2141
|
+
`clip-path: inset(${clip.map((c) => `${c}px`).join(" ")})`,
|
|
2142
|
+
"box-sizing: border-box",
|
|
2143
|
+
"margin: 0",
|
|
2144
|
+
`padding: 0 ${Theme.Widget.Padding * scale}px`,
|
|
2145
|
+
`font: ${Theme.Widget.FontSize * scale * sy}px ${Theme.FontFamily}`,
|
|
2146
|
+
`color: ${Theme.Widget.FontColor}`,
|
|
2147
|
+
`background: ${Theme.Widget.Hover.BackgroundColor}`,
|
|
2148
|
+
`border: ${Theme.Widget.Border.Size * scale}px solid ${Theme.Widget.Border.Color}`,
|
|
2149
|
+
`border-radius: ${Theme.Widget.Border.Radius * scale}px`,
|
|
2150
|
+
"outline: none",
|
|
2151
|
+
"z-index: 1000"
|
|
2152
|
+
].join(";");
|
|
2153
|
+
};
|
|
2154
|
+
place(config.box, config.scale);
|
|
2124
2155
|
let done = false;
|
|
2125
2156
|
const finish = (keep) => {
|
|
2126
2157
|
if (done) {
|
|
2127
2158
|
return;
|
|
2128
2159
|
}
|
|
2129
2160
|
done = true;
|
|
2161
|
+
open.delete(edit);
|
|
2130
2162
|
input.remove();
|
|
2131
2163
|
if (keep) {
|
|
2132
2164
|
config.onCommit(input.value);
|
|
@@ -2144,10 +2176,11 @@ function editInPlace(config) {
|
|
|
2144
2176
|
}
|
|
2145
2177
|
});
|
|
2146
2178
|
input.addEventListener("blur", () => finish(true));
|
|
2179
|
+
open.add(edit);
|
|
2147
2180
|
document.body.appendChild(input);
|
|
2148
2181
|
input.focus();
|
|
2149
2182
|
input.select();
|
|
2150
|
-
return input;
|
|
2183
|
+
return { input, place };
|
|
2151
2184
|
}
|
|
2152
2185
|
|
|
2153
2186
|
// src/widgets/widget.ts
|
|
@@ -2161,11 +2194,19 @@ var WidgetBase = class {
|
|
|
2161
2194
|
#box = { Position: { x: 0, y: 0 }, Size: { x: 0, y: 0 } };
|
|
2162
2195
|
#canvas = null;
|
|
2163
2196
|
#scale = 1;
|
|
2197
|
+
#editing = null;
|
|
2164
2198
|
Draw(ctx, box, scale, mousePosition) {
|
|
2165
2199
|
this.#box = { Position: { x: box.Position.x, y: box.Position.y }, Size: { x: box.Size.x, y: box.Size.y } };
|
|
2166
2200
|
this.#canvas = ctx.canvas ?? null;
|
|
2167
2201
|
this.#scale = scale;
|
|
2168
2202
|
this.#hovered = !this.#disabled && mousePosition !== void 0 && InBox(box, mousePosition);
|
|
2203
|
+
if (this.#editing !== null) {
|
|
2204
|
+
if (this.#editing.input.isConnected) {
|
|
2205
|
+
this.#editing.place(this.#box, scale);
|
|
2206
|
+
} else {
|
|
2207
|
+
this.#editing = null;
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2169
2210
|
ctx.save();
|
|
2170
2211
|
if (this.#disabled) {
|
|
2171
2212
|
ctx.globalAlpha *= 0.4;
|
|
@@ -2237,6 +2278,15 @@ var WidgetBase = class {
|
|
|
2237
2278
|
scale() {
|
|
2238
2279
|
return this.#scale;
|
|
2239
2280
|
}
|
|
2281
|
+
editText(value, onCommit) {
|
|
2282
|
+
this.#editing = editInPlace({
|
|
2283
|
+
canvas: this.#canvas,
|
|
2284
|
+
box: this.#box,
|
|
2285
|
+
scale: this.#scale,
|
|
2286
|
+
value,
|
|
2287
|
+
onCommit
|
|
2288
|
+
});
|
|
2289
|
+
}
|
|
2240
2290
|
onPointerDown(pointer) {
|
|
2241
2291
|
}
|
|
2242
2292
|
onPointerMove(pointer) {
|
|
@@ -2396,16 +2446,10 @@ var NumberWidget = class extends ValueWidget {
|
|
|
2396
2446
|
return;
|
|
2397
2447
|
}
|
|
2398
2448
|
const before = this.value();
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
value: String(before),
|
|
2404
|
-
onCommit: (text) => {
|
|
2405
|
-
const parsed = Number.parseFloat(text);
|
|
2406
|
-
if (Number.isFinite(parsed)) {
|
|
2407
|
-
this.commit(this.#clean(parsed), before);
|
|
2408
|
-
}
|
|
2449
|
+
this.editText(String(before), (text) => {
|
|
2450
|
+
const parsed = Number.parseFloat(text);
|
|
2451
|
+
if (Number.isFinite(parsed)) {
|
|
2452
|
+
this.commit(this.#clean(parsed), before);
|
|
2409
2453
|
}
|
|
2410
2454
|
});
|
|
2411
2455
|
}
|
|
@@ -2613,13 +2657,7 @@ var StringWidget = class extends ValueWidget {
|
|
|
2613
2657
|
}
|
|
2614
2658
|
onClick() {
|
|
2615
2659
|
const before = this.value();
|
|
2616
|
-
|
|
2617
|
-
canvas: this.canvas(),
|
|
2618
|
-
box: this.box(),
|
|
2619
|
-
scale: this.scale(),
|
|
2620
|
-
value: before,
|
|
2621
|
-
onCommit: (text) => this.commit(text, before)
|
|
2622
|
-
});
|
|
2660
|
+
this.editText(before, (text) => this.commit(text, before));
|
|
2623
2661
|
}
|
|
2624
2662
|
};
|
|
2625
2663
|
|
|
@@ -8016,10 +8054,12 @@ var NodeFlowGraph = class {
|
|
|
8016
8054
|
this.#cursor = "default" /* Default */;
|
|
8017
8055
|
TimeExecution("Render_Background", this.#renderBackground.bind(this));
|
|
8018
8056
|
TimeExecution("Render_View_" + this.#currentView, () => {
|
|
8019
|
-
|
|
8020
|
-
|
|
8021
|
-
|
|
8022
|
-
|
|
8057
|
+
placeEditsDuring(this.#canvas, () => {
|
|
8058
|
+
let results = this.currentView().render(this.#ctx, this.#camera, this.#mousePosition);
|
|
8059
|
+
if (results?.cursorStyle) {
|
|
8060
|
+
this.#cursor = results?.cursorStyle;
|
|
8061
|
+
}
|
|
8062
|
+
});
|
|
8023
8063
|
});
|
|
8024
8064
|
TimeExecution("Render_Minimap", () => {
|
|
8025
8065
|
this.#minimap.render(this.#ctx, this.#canvas, this.#camera, this.#mainNodeSubsystem.getNodes());
|