@pie-players/pie-tool-graph 0.3.3 → 0.3.4
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/tool-graph.js +2057 -3448
- package/package.json +9 -13
- package/tool-graph.svelte +6 -143
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-players/pie-tool-graph",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Interactive coordinate grid graphing tool for PIE assessment player",
|
|
6
6
|
"repository": {
|
|
@@ -35,17 +35,13 @@
|
|
|
35
35
|
"index.ts",
|
|
36
36
|
"package.json"
|
|
37
37
|
],
|
|
38
|
-
"peerDependencies": {
|
|
39
|
-
"svelte": "^5.51.0"
|
|
40
|
-
},
|
|
41
38
|
"license": "MIT",
|
|
42
39
|
"unpkg": "./dist/tool-graph.js",
|
|
43
40
|
"jsdelivr": "./dist/tool-graph.js",
|
|
44
41
|
"dependencies": {
|
|
45
|
-
"@pie-players/pie-assessment-toolkit": "0.3.
|
|
46
|
-
"@pie-players/pie-context": "0.3.
|
|
47
|
-
"@pie-players/pie-players-shared": "0.3.
|
|
48
|
-
"daisyui": "^5.5.18"
|
|
42
|
+
"@pie-players/pie-assessment-toolkit": "0.3.4",
|
|
43
|
+
"@pie-players/pie-context": "0.3.4",
|
|
44
|
+
"@pie-players/pie-players-shared": "0.3.4"
|
|
49
45
|
},
|
|
50
46
|
"types": "./dist/index.d.ts",
|
|
51
47
|
"scripts": {
|
|
@@ -56,11 +52,11 @@
|
|
|
56
52
|
},
|
|
57
53
|
"devDependencies": {
|
|
58
54
|
"@biomejs/biome": "^2.3.10",
|
|
59
|
-
"@sveltejs/vite-plugin-svelte": "^6.
|
|
60
|
-
"svelte": "^5.
|
|
61
|
-
"typescript": "^5.
|
|
62
|
-
"vite": "^7.
|
|
63
|
-
"vite-plugin-dts": "^4.5.
|
|
55
|
+
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
|
56
|
+
"svelte": "^5.53.7",
|
|
57
|
+
"typescript": "^5.9.3",
|
|
58
|
+
"vite": "^7.3.1",
|
|
59
|
+
"vite-plugin-dts": "^4.5.4"
|
|
64
60
|
},
|
|
65
61
|
"homepage": "https://github.com/pie-framework/pie-players/tree/master/packages/tool-graph#readme",
|
|
66
62
|
"bugs": {
|
package/tool-graph.svelte
CHANGED
|
@@ -10,16 +10,7 @@
|
|
|
10
10
|
/>
|
|
11
11
|
|
|
12
12
|
<script lang="ts">
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
connectToolRuntimeContext,
|
|
16
|
-
ZIndexLayer,
|
|
17
|
-
} from '@pie-players/pie-assessment-toolkit';
|
|
18
|
-
import type {
|
|
19
|
-
AssessmentToolkitRuntimeContext,
|
|
20
|
-
IToolCoordinator,
|
|
21
|
-
} from '@pie-players/pie-assessment-toolkit';
|
|
22
|
-
import { onMount } from 'svelte';
|
|
13
|
+
|
|
23
14
|
|
|
24
15
|
// Props
|
|
25
16
|
let {
|
|
@@ -30,9 +21,6 @@ import { onMount } from 'svelte';
|
|
|
30
21
|
toolId?: string;
|
|
31
22
|
} = $props();
|
|
32
23
|
|
|
33
|
-
// Check if running in browser
|
|
34
|
-
const isBrowser = typeof window !== 'undefined';
|
|
35
|
-
|
|
36
24
|
// Tool types (matching production implementation)
|
|
37
25
|
type Tool = 'selector' | 'point' | 'line' | 'delete';
|
|
38
26
|
|
|
@@ -55,20 +43,9 @@ import { onMount } from 'svelte';
|
|
|
55
43
|
}
|
|
56
44
|
|
|
57
45
|
// State
|
|
58
|
-
let containerEl = $state<HTMLDivElement | undefined>();
|
|
59
|
-
let runtimeContext = $state<AssessmentToolkitRuntimeContext | null>(null);
|
|
60
|
-
const coordinator = $derived(
|
|
61
|
-
runtimeContext?.toolCoordinator as IToolCoordinator | undefined,
|
|
62
|
-
);
|
|
63
46
|
let canvasWrapperEl = $state<HTMLDivElement | undefined>();
|
|
64
47
|
let svgCanvasEl = $state<SVGSVGElement | undefined>();
|
|
65
48
|
|
|
66
|
-
// Position and size (matching production implementation defaults)
|
|
67
|
-
let x = $state(isBrowser ? window.innerWidth / 2 : 400);
|
|
68
|
-
let y = $state(isBrowser ? window.innerHeight / 2 : 300);
|
|
69
|
-
let width = $state(700);
|
|
70
|
-
let height = $state(550); // Production implementation uses 550px height
|
|
71
|
-
|
|
72
49
|
// Tool state
|
|
73
50
|
let currentTool = $state<Tool>('selector');
|
|
74
51
|
let points = $state<Point[]>([]);
|
|
@@ -79,9 +56,6 @@ import { onMount } from 'svelte';
|
|
|
79
56
|
let draggingPointId = $state<number | null>(null);
|
|
80
57
|
let currentPointerPos = $state<Coordinates | null>(null);
|
|
81
58
|
|
|
82
|
-
// Track registration state
|
|
83
|
-
let registered = $state(false);
|
|
84
|
-
|
|
85
59
|
// Grid configuration (matching production implementation)
|
|
86
60
|
const MAJOR_VERTICAL_DIVISIONS = 5; // Fixed number of rows
|
|
87
61
|
const SUBGRID_DIVISIONS = 5; // 5x5 minor grid
|
|
@@ -92,13 +66,6 @@ import { onMount } from 'svelte';
|
|
|
92
66
|
let containerPixelWidth = $state(0);
|
|
93
67
|
let containerPixelHeight = $state(0);
|
|
94
68
|
|
|
95
|
-
$effect(() => {
|
|
96
|
-
if (!containerEl) return;
|
|
97
|
-
return connectToolRuntimeContext(containerEl, (value: AssessmentToolkitRuntimeContext) => {
|
|
98
|
-
runtimeContext = value;
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
69
|
// Dynamic viewBox width (matching production implementation)
|
|
103
70
|
let viewBoxWidth = $derived.by(() => {
|
|
104
71
|
if (containerPixelHeight <= 0 || containerPixelWidth <= 0) {
|
|
@@ -372,48 +339,6 @@ import { onMount } from 'svelte';
|
|
|
372
339
|
}
|
|
373
340
|
}
|
|
374
341
|
|
|
375
|
-
function handleClose() {
|
|
376
|
-
coordinator?.hideTool(toolId);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function handlePointerDown(e: PointerEvent) {
|
|
380
|
-
const target = e.target as HTMLElement;
|
|
381
|
-
|
|
382
|
-
// Only start drag if clicking the header
|
|
383
|
-
if (!target.closest('.pie-tool-graph__header')) return;
|
|
384
|
-
|
|
385
|
-
// Start dragging (we'll handle position updates)
|
|
386
|
-
if (containerEl) {
|
|
387
|
-
containerEl.setPointerCapture(e.pointerId);
|
|
388
|
-
const startX = e.clientX - x;
|
|
389
|
-
const startY = e.clientY - y;
|
|
390
|
-
|
|
391
|
-
function onMove(e: PointerEvent) {
|
|
392
|
-
let newX = e.clientX - startX;
|
|
393
|
-
let newY = e.clientY - startY;
|
|
394
|
-
|
|
395
|
-
// Keep calculator on screen
|
|
396
|
-
const halfWidth = (containerEl?.offsetWidth || width) / 2;
|
|
397
|
-
const halfHeight = (containerEl?.offsetHeight || height) / 2;
|
|
398
|
-
|
|
399
|
-
x = Math.max(halfWidth, Math.min(newX, window.innerWidth - halfWidth));
|
|
400
|
-
y = Math.max(halfHeight, Math.min(newY, window.innerHeight - halfHeight));
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
function onUp() {
|
|
404
|
-
if (containerEl) {
|
|
405
|
-
containerEl.releasePointerCapture(e.pointerId);
|
|
406
|
-
}
|
|
407
|
-
containerEl?.removeEventListener('pointermove', onMove);
|
|
408
|
-
containerEl?.removeEventListener('pointerup', onUp);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
containerEl.addEventListener('pointermove', onMove);
|
|
412
|
-
containerEl.addEventListener('pointerup', onUp);
|
|
413
|
-
coordinator?.bringToFront(containerEl);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
342
|
// ResizeObserver for dynamic viewBox width (matching production implementation)
|
|
418
343
|
let resizeObserver: ResizeObserver | null = null;
|
|
419
344
|
$effect(() => {
|
|
@@ -443,54 +368,16 @@ import { onMount } from 'svelte';
|
|
|
443
368
|
}
|
|
444
369
|
});
|
|
445
370
|
|
|
446
|
-
// Register with coordinator when it becomes available
|
|
447
|
-
$effect(() => {
|
|
448
|
-
if (coordinator && toolId && !registered) {
|
|
449
|
-
if (containerEl) {
|
|
450
|
-
coordinator.registerTool(toolId, 'Graph Tool', containerEl, ZIndexLayer.MODAL);
|
|
451
|
-
} else {
|
|
452
|
-
coordinator.registerTool(toolId, 'Graph Tool', undefined, ZIndexLayer.MODAL);
|
|
453
|
-
}
|
|
454
|
-
registered = true;
|
|
455
|
-
}
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
// Update element reference when container becomes available
|
|
459
|
-
$effect(() => {
|
|
460
|
-
if (coordinator && containerEl && toolId) {
|
|
461
|
-
coordinator.updateToolElement(toolId, containerEl);
|
|
462
|
-
coordinator.bringToFront(containerEl);
|
|
463
|
-
}
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
onMount(() => {
|
|
467
|
-
return () => {
|
|
468
|
-
if (resizeObserver) {
|
|
469
|
-
resizeObserver.disconnect();
|
|
470
|
-
resizeObserver = null;
|
|
471
|
-
}
|
|
472
|
-
if (coordinator && toolId) {
|
|
473
|
-
coordinator.unregisterTool(toolId);
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
});
|
|
477
371
|
</script>
|
|
478
372
|
|
|
479
373
|
{#if visible}
|
|
480
374
|
<div
|
|
481
|
-
bind:this={containerEl}
|
|
482
375
|
class="pie-tool-graph"
|
|
483
376
|
role="dialog"
|
|
484
377
|
tabindex="-1"
|
|
485
378
|
aria-label="Graph Tool - Draw points and lines on a coordinate grid"
|
|
486
|
-
|
|
487
|
-
onpointerdown={handlePointerDown}
|
|
379
|
+
data-tool-id={toolId}
|
|
488
380
|
>
|
|
489
|
-
<!-- Header (matching production implementation: dark teal) -->
|
|
490
|
-
<div class="pie-tool-graph__header">
|
|
491
|
-
<h3 id="graph-tool-title" class="pie-tool-graph__title">Graph Tool</h3>
|
|
492
|
-
</div>
|
|
493
|
-
|
|
494
381
|
<!-- Toolbar (matching production implementation: lighter teal) -->
|
|
495
382
|
<div class="pie-tool-graph__toolbar">
|
|
496
383
|
<!-- Tool buttons -->
|
|
@@ -691,41 +578,17 @@ import { onMount } from 'svelte';
|
|
|
691
578
|
|
|
692
579
|
<style>
|
|
693
580
|
.pie-tool-graph {
|
|
694
|
-
position:
|
|
581
|
+
position: relative;
|
|
695
582
|
background: var(--pie-background, #fff);
|
|
696
583
|
color: var(--pie-text, #111827);
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
touch-action: none;
|
|
701
|
-
border-radius: 12px;
|
|
584
|
+
width: 100%;
|
|
585
|
+
height: 100%;
|
|
586
|
+
min-height: 0;
|
|
702
587
|
overflow: hidden;
|
|
703
|
-
z-index: 2000; /* ZIndexLayer.MODAL */
|
|
704
|
-
min-width: 500px;
|
|
705
588
|
display: flex;
|
|
706
589
|
flex-direction: column;
|
|
707
590
|
}
|
|
708
591
|
|
|
709
|
-
/* Header (matching production implementation: dark teal) */
|
|
710
|
-
.pie-tool-graph__header {
|
|
711
|
-
padding: 12px 16px;
|
|
712
|
-
background: var(--pie-primary-dark, #2c3e50); /* Dark teal-like color */
|
|
713
|
-
color: var(--pie-white, #fff);
|
|
714
|
-
display: flex;
|
|
715
|
-
justify-content: space-between;
|
|
716
|
-
align-items: center;
|
|
717
|
-
cursor: move;
|
|
718
|
-
user-select: none;
|
|
719
|
-
border-radius: 12px 12px 0 0;
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
.pie-tool-graph__title {
|
|
723
|
-
font-weight: 600;
|
|
724
|
-
font-size: 16px;
|
|
725
|
-
color: var(--pie-white, #fff);
|
|
726
|
-
margin: 0;
|
|
727
|
-
}
|
|
728
|
-
|
|
729
592
|
/* Toolbar (matching production implementation: lighter teal) */
|
|
730
593
|
.pie-tool-graph__toolbar {
|
|
731
594
|
padding: 8px;
|