veo-sdk 0.5.4 → 0.5.5

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.
@@ -1,5 +1,5 @@
1
- export { VEO_BLOCK_MIME, attachBlockDropTarget, attachDesignManipulator, createBuilderSession, initBuilderMode, startElementPicker, stopElementPicker } from './chunk-SBNT464M.mjs';
1
+ export { VEO_BLOCK_MIME, attachBlockDropTarget, attachDesignManipulator, createBuilderSession, initBuilderMode, startElementPicker, stopElementPicker } from './chunk-XPB4DL2Y.mjs';
2
2
  import './chunk-JPA46JBS.mjs';
3
3
  import './chunk-PTG3BTJE.mjs';
4
- //# sourceMappingURL=builder-MFTOJV6F.mjs.map
5
- //# sourceMappingURL=builder-MFTOJV6F.mjs.map
4
+ //# sourceMappingURL=builder-O2QHV2DV.mjs.map
5
+ //# sourceMappingURL=builder-O2QHV2DV.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"builder-MFTOJV6F.mjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"builder-O2QHV2DV.mjs"}
package/dist/builder.cjs CHANGED
@@ -32,7 +32,8 @@ function attachBlockDropTarget(options) {
32
32
  const types = event.dataTransfer?.types;
33
33
  return !!types && Array.from(types).includes(VEO_BLOCK_MIME);
34
34
  };
35
- const locate = (event) => {
35
+ const NEAR_PX = 48;
36
+ const locate = (clientY) => {
36
37
  const container = contentEl();
37
38
  if (!container) return null;
38
39
  const rect = container.getBoundingClientRect();
@@ -41,7 +42,7 @@ function attachBlockDropTarget(options) {
41
42
  let y = kids.length === 0 ? rect.top + rect.height / 2 : 0;
42
43
  for (const kid of kids) {
43
44
  const r = kid.getBoundingClientRect();
44
- if (event.clientY < r.top + r.height / 2) {
45
+ if (clientY < r.top + r.height / 2) {
45
46
  const idx = Number(kid.dataset.veoIdx);
46
47
  beforeIndex = Number.isFinite(idx) ? idx : null;
47
48
  y = r.top;
@@ -51,9 +52,26 @@ function attachBlockDropTarget(options) {
51
52
  }
52
53
  return { beforeIndex, y, rect };
53
54
  };
55
+ const overContent = (x, y, rect) => x >= rect.left - NEAR_PX && x <= rect.right + NEAR_PX && y >= rect.top - NEAR_PX && y <= rect.bottom + NEAR_PX;
56
+ const hoverAt = (x, y) => {
57
+ const at = locate(y);
58
+ if (!at || !overContent(x, y, at.rect)) {
59
+ hideLine();
60
+ return false;
61
+ }
62
+ spot = at;
63
+ showLine(at);
64
+ return true;
65
+ };
66
+ const dropAt = (x, y) => {
67
+ const at = locate(y);
68
+ hideLine();
69
+ if (!at || !overContent(x, y, at.rect)) return null;
70
+ return { beforeIndex: at.beforeIndex };
71
+ };
54
72
  const onDragOver = (event) => {
55
73
  if (!isBlockDrag(event)) return;
56
- const at = locate(event);
74
+ const at = locate(event.clientY);
57
75
  if (!at) return;
58
76
  event.preventDefault();
59
77
  if (event.dataTransfer) event.dataTransfer.dropEffect = "copy";
@@ -64,7 +82,7 @@ function attachBlockDropTarget(options) {
64
82
  if (!isBlockDrag(event)) return;
65
83
  event.preventDefault();
66
84
  const blockType = event.dataTransfer?.getData(VEO_BLOCK_MIME) ?? "";
67
- const at = spot ?? locate(event);
85
+ const at = spot ?? locate(event.clientY);
68
86
  hideLine();
69
87
  if (!blockType || !at) return;
70
88
  onDrop({ stepIndex, blockType, beforeIndex: at.beforeIndex });
@@ -78,6 +96,9 @@ function attachBlockDropTarget(options) {
78
96
  host.addEventListener("drop", onDropEvent);
79
97
  host.addEventListener("dragleave", onDragLeave);
80
98
  return {
99
+ hoverAt,
100
+ dropAt,
101
+ cancelHover: hideLine,
81
102
  detach() {
82
103
  host.removeEventListener("dragover", onDragOver);
83
104
  host.removeEventListener("drop", onDropEvent);
@@ -2787,7 +2808,7 @@ var MIN_H = 320;
2787
2808
  var MARGIN = 16;
2788
2809
  function injectBuilderPanel(opts) {
2789
2810
  if (!hasWindow() || !hasDocument()) {
2790
- return { target: () => null, teardown: () => {
2811
+ return { target: () => null, frameRect: () => null, teardown: () => {
2791
2812
  } };
2792
2813
  }
2793
2814
  const panelUrl = buildPanelUrl(opts);
@@ -2904,6 +2925,7 @@ function injectBuilderPanel(opts) {
2904
2925
  });
2905
2926
  return {
2906
2927
  target: () => popped && !popped.closed ? popped : iframe.contentWindow,
2928
+ frameRect: () => popped && !popped.closed ? null : iframe.getBoundingClientRect(),
2907
2929
  teardown: () => {
2908
2930
  stopPoll();
2909
2931
  if (popped && !popped.closed) popped.close();
@@ -3488,6 +3510,8 @@ function initBuilderMode() {
3488
3510
  let staticTarget = null;
3489
3511
  let manipulator = null;
3490
3512
  let dropTarget = null;
3513
+ let dragGhost = null;
3514
+ let previewStepIndex = 0;
3491
3515
  let pendingPreview = null;
3492
3516
  const getTarget = () => panel ? panel.target() : staticTarget;
3493
3517
  const post = (event) => {
@@ -3498,6 +3522,7 @@ function initBuilderMode() {
3498
3522
  manipulator = null;
3499
3523
  dropTarget?.detach();
3500
3524
  dropTarget = null;
3525
+ previewStepIndex = cmd.guide.startStepIndex ?? 0;
3501
3526
  const handle = previewGuide(cmd.guide);
3502
3527
  if (!cmd.editable) return;
3503
3528
  void handle.ready.then((result) => {
@@ -3523,6 +3548,47 @@ function initBuilderMode() {
3523
3548
  });
3524
3549
  });
3525
3550
  };
3551
+ const hideDragGhost = () => {
3552
+ dragGhost?.remove();
3553
+ dragGhost = null;
3554
+ };
3555
+ const moveDragGhost = (x, y, label) => {
3556
+ if (!dragGhost) {
3557
+ dragGhost = document.createElement("div");
3558
+ dragGhost.style.cssText = "position:fixed;padding:4px 10px;border-radius:999px;background:#1c1917;color:#fff;font:12px/1.4 system-ui,sans-serif;box-shadow:0 4px 14px rgba(0,0,0,0.35);border:1px solid rgba(255,255,255,0.25);pointer-events:none;z-index:2147483647;";
3559
+ document.body.appendChild(dragGhost);
3560
+ }
3561
+ dragGhost.textContent = label;
3562
+ dragGhost.style.left = `${x + 14}px`;
3563
+ dragGhost.style.top = `${y + 12}px`;
3564
+ };
3565
+ const handleBlockDrag = (cmd) => {
3566
+ const rect = panel?.frameRect();
3567
+ if (!rect || !dropTarget) {
3568
+ if (cmd.phase !== "move") hideDragGhost();
3569
+ dropTarget?.cancelHover();
3570
+ return;
3571
+ }
3572
+ const x = rect.left + cmd.x;
3573
+ const y = rect.top + cmd.y;
3574
+ if (cmd.phase === "move") {
3575
+ moveDragGhost(x, y, cmd.label || cmd.blockType);
3576
+ dropTarget.hoverAt(x, y);
3577
+ return;
3578
+ }
3579
+ hideDragGhost();
3580
+ if (cmd.phase === "cancel") {
3581
+ dropTarget.cancelHover();
3582
+ return;
3583
+ }
3584
+ const spotAt = dropTarget.dropAt(x, y);
3585
+ if (spotAt) {
3586
+ post({
3587
+ type: "block-dropped",
3588
+ payload: { stepIndex: previewStepIndex, blockType: cmd.blockType, ...spotAt }
3589
+ });
3590
+ }
3591
+ };
3526
3592
  const handleCommand = (cmd) => {
3527
3593
  switch (cmd.type) {
3528
3594
  case "panel-ready":
@@ -3552,11 +3618,15 @@ function initBuilderMode() {
3552
3618
  if (manipulator?.isDragging()) pendingPreview = cmd;
3553
3619
  else applyPreview(cmd);
3554
3620
  break;
3621
+ case "block-drag":
3622
+ handleBlockDrag(cmd);
3623
+ break;
3555
3624
  case "close-preview":
3556
3625
  manipulator?.detach();
3557
3626
  manipulator = null;
3558
3627
  dropTarget?.detach();
3559
3628
  dropTarget = null;
3629
+ hideDragGhost();
3560
3630
  pendingPreview = null;
3561
3631
  closeGuidePreview();
3562
3632
  break;
@@ -3581,6 +3651,7 @@ function initBuilderMode() {
3581
3651
  manipulator = null;
3582
3652
  dropTarget?.detach();
3583
3653
  dropTarget = null;
3654
+ hideDragGhost();
3584
3655
  pendingPreview = null;
3585
3656
  closeGuidePreview();
3586
3657
  post({ type: "closed" });