@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/test/widgets.test.ts
CHANGED
|
@@ -11,7 +11,19 @@ import { ImageWidget } from '../src/widgets/image';
|
|
|
11
11
|
import { ColorWidget } from '../src/widgets/color';
|
|
12
12
|
import { RowWidget } from '../src/widgets/row';
|
|
13
13
|
import { WidgetBase } from '../src/widgets/widget';
|
|
14
|
-
import {
|
|
14
|
+
import { placeEditsDuring } from '../src/widgets/inplace';
|
|
15
|
+
import { CanvasRecord, center, StubElement, stubCtx, widgetScene, withDocument } from './support';
|
|
16
|
+
|
|
17
|
+
function cssOf(el: StubElement): Record<string, string> {
|
|
18
|
+
const style: Record<string, string> = {};
|
|
19
|
+
el.style.cssText.split(';').forEach((rule) => {
|
|
20
|
+
const at = rule.indexOf(':');
|
|
21
|
+
if (at > 0) {
|
|
22
|
+
style[rule.slice(0, at).trim()] = rule.slice(at + 1).trim();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return style;
|
|
26
|
+
}
|
|
15
27
|
|
|
16
28
|
describe('a number widget', () => {
|
|
17
29
|
it('follows a drag and reports one edit when let go', () => {
|
|
@@ -97,6 +109,47 @@ describe('a number widget', () => {
|
|
|
97
109
|
});
|
|
98
110
|
});
|
|
99
111
|
|
|
112
|
+
it('keeps its input over the widget as the camera moves and zooms', () => {
|
|
113
|
+
withDocument((body) => {
|
|
114
|
+
const { graph, camera, ctx, widgetBox, click } = widgetScene((n) => new NumberWidget(n, { value: 3 }));
|
|
115
|
+
click(center(widgetBox()));
|
|
116
|
+
const input = body.children[0];
|
|
117
|
+
|
|
118
|
+
camera.position.x += 137;
|
|
119
|
+
camera.position.y -= 41;
|
|
120
|
+
camera.zoom = 2;
|
|
121
|
+
graph.render(ctx, camera, undefined);
|
|
122
|
+
|
|
123
|
+
const box = widgetBox();
|
|
124
|
+
const style = cssOf(input);
|
|
125
|
+
assert.equal(style.left, `${10 + box.Position.x}px`);
|
|
126
|
+
assert.equal(style.top, `${20 + box.Position.y}px`);
|
|
127
|
+
assert.equal(style.width, `${box.Size.x}px`);
|
|
128
|
+
assert.equal(style.height, `${box.Size.y}px`);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('hides its input while the node is off the canvas', () => {
|
|
133
|
+
withDocument((body) => {
|
|
134
|
+
const { graph, camera, ctx, widgetBox, click } = widgetScene(
|
|
135
|
+
(n) => new NumberWidget(n, { value: 3 }),
|
|
136
|
+
{ inputs: [{ name: 'in', type: 'n' }] },
|
|
137
|
+
);
|
|
138
|
+
click(center(widgetBox()));
|
|
139
|
+
const input = body.children[0];
|
|
140
|
+
const frame =() => placeEditsDuring(ctx.canvas, () => graph.render(ctx, camera, undefined));
|
|
141
|
+
|
|
142
|
+
camera.position.x -= 5000;
|
|
143
|
+
frame();
|
|
144
|
+
assert.equal(input.style.opacity, '0');
|
|
145
|
+
|
|
146
|
+
camera.position.x += 5000;
|
|
147
|
+
frame();
|
|
148
|
+
assert.equal(input.style.opacity, undefined);
|
|
149
|
+
assert.ok(input.isConnected);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
100
153
|
it('does not open an input after a drag', () => {
|
|
101
154
|
withDocument((body) => {
|
|
102
155
|
const { widgetBox, press } = widgetScene((n) => new NumberWidget(n, { value: 0 }));
|