veo-sdk 0.5.2 → 0.5.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.
@@ -0,0 +1,5 @@
1
+ export { VEO_BLOCK_MIME, attachBlockDropTarget, attachDesignManipulator, createBuilderSession, initBuilderMode, startElementPicker, stopElementPicker } from './chunk-SBNT464M.mjs';
2
+ import './chunk-JPA46JBS.mjs';
3
+ import './chunk-PTG3BTJE.mjs';
4
+ //# sourceMappingURL=builder-MFTOJV6F.mjs.map
5
+ //# sourceMappingURL=builder-MFTOJV6F.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"builder-LSWVQYFZ.mjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"builder-MFTOJV6F.mjs"}
package/dist/builder.cjs CHANGED
@@ -2,6 +2,91 @@
2
2
 
3
3
  var dom = require('@floating-ui/dom');
4
4
 
5
+ // src/plugins/builder/block-drop-target.ts
6
+ var VEO_BLOCK_MIME = "application/x-veo-block";
7
+ function attachBlockDropTarget(options) {
8
+ const { host, stepIndex, onDrop } = options;
9
+ const doc = host.ownerDocument;
10
+ let line = null;
11
+ let spot = null;
12
+ const contentEl = () => host.shadowRoot?.querySelector(".veo-guide-content") ?? null;
13
+ const blockChildren = (container) => Array.from(container.children).filter(
14
+ (el) => el instanceof HTMLElement && el.dataset.veoIdx !== void 0
15
+ );
16
+ const hideLine = () => {
17
+ line?.remove();
18
+ line = null;
19
+ spot = null;
20
+ };
21
+ const showLine = (at) => {
22
+ if (!line) {
23
+ line = doc.createElement("div");
24
+ line.style.cssText = "position:fixed;height:3px;border-radius:2px;background:#FF5B35;box-shadow:0 0 0 1px rgba(255,255,255,0.65);pointer-events:none;z-index:2147483647;";
25
+ host.shadowRoot?.appendChild(line);
26
+ }
27
+ line.style.left = `${at.rect.left + 4}px`;
28
+ line.style.width = `${Math.max(0, at.rect.width - 8)}px`;
29
+ line.style.top = `${at.y - 1.5}px`;
30
+ };
31
+ const isBlockDrag = (event) => {
32
+ const types = event.dataTransfer?.types;
33
+ return !!types && Array.from(types).includes(VEO_BLOCK_MIME);
34
+ };
35
+ const locate = (event) => {
36
+ const container = contentEl();
37
+ if (!container) return null;
38
+ const rect = container.getBoundingClientRect();
39
+ const kids = blockChildren(container);
40
+ let beforeIndex = null;
41
+ let y = kids.length === 0 ? rect.top + rect.height / 2 : 0;
42
+ for (const kid of kids) {
43
+ const r = kid.getBoundingClientRect();
44
+ if (event.clientY < r.top + r.height / 2) {
45
+ const idx = Number(kid.dataset.veoIdx);
46
+ beforeIndex = Number.isFinite(idx) ? idx : null;
47
+ y = r.top;
48
+ break;
49
+ }
50
+ y = r.bottom;
51
+ }
52
+ return { beforeIndex, y, rect };
53
+ };
54
+ const onDragOver = (event) => {
55
+ if (!isBlockDrag(event)) return;
56
+ const at = locate(event);
57
+ if (!at) return;
58
+ event.preventDefault();
59
+ if (event.dataTransfer) event.dataTransfer.dropEffect = "copy";
60
+ spot = at;
61
+ showLine(at);
62
+ };
63
+ const onDropEvent = (event) => {
64
+ if (!isBlockDrag(event)) return;
65
+ event.preventDefault();
66
+ const blockType = event.dataTransfer?.getData(VEO_BLOCK_MIME) ?? "";
67
+ const at = spot ?? locate(event);
68
+ hideLine();
69
+ if (!blockType || !at) return;
70
+ onDrop({ stepIndex, blockType, beforeIndex: at.beforeIndex });
71
+ };
72
+ const onDragLeave = (event) => {
73
+ const to = event.relatedTarget;
74
+ if (to instanceof Node && (to === host || host.contains(to))) return;
75
+ hideLine();
76
+ };
77
+ host.addEventListener("dragover", onDragOver);
78
+ host.addEventListener("drop", onDropEvent);
79
+ host.addEventListener("dragleave", onDragLeave);
80
+ return {
81
+ detach() {
82
+ host.removeEventListener("dragover", onDragOver);
83
+ host.removeEventListener("drop", onDropEvent);
84
+ host.removeEventListener("dragleave", onDragLeave);
85
+ hideLine();
86
+ }
87
+ };
88
+ }
89
+
5
90
  // src/utils/safe-env.ts
6
91
  function hasWindow() {
7
92
  return typeof window !== "undefined";
@@ -268,7 +353,15 @@ function buildStepContent(step, doc, callbacks) {
268
353
  function buildContentNodes(step, doc) {
269
354
  const blocks = normalizeBlocks(step);
270
355
  if (blocks) {
271
- return blocks.filter((b) => b.type !== "button").map((b) => buildContentBlock(b, doc)).filter((n) => n !== null);
356
+ const nodes2 = [];
357
+ for (const { block, idx } of blocks) {
358
+ if (block.type === "button") continue;
359
+ const node = buildContentBlock(block, doc);
360
+ if (!node) continue;
361
+ node.dataset.veoIdx = String(idx);
362
+ nodes2.push(node);
363
+ }
364
+ return nodes2;
272
365
  }
273
366
  const nodes = [];
274
367
  if (typeof step.imageUrl === "string" && step.imageUrl && isSafeUrl(step.imageUrl)) {
@@ -330,7 +423,8 @@ function renderLegacyStep(container, step, doc, callbacks) {
330
423
  }
331
424
  function normalizeBlocks(step) {
332
425
  if (!Array.isArray(step.blocks) || step.blocks.length === 0) return null;
333
- const valid = step.blocks.filter((b) => {
426
+ const valid = step.blocks.map((block, idx) => ({ block, idx })).filter((entry) => {
427
+ const b = entry.block;
334
428
  if (!b || typeof b !== "object") return false;
335
429
  if (b.type === "image") return typeof b.url === "string" && isSafeUrl(b.url);
336
430
  return b.type === "title" || b.type === "text" || b.type === "button";
@@ -340,13 +434,14 @@ function normalizeBlocks(step) {
340
434
  function renderBlocks(container, blocks, doc, callbacks) {
341
435
  let i = 0;
342
436
  while (i < blocks.length) {
343
- const block = blocks[i];
344
- if (block?.type === "button") {
437
+ const entry = blocks[i];
438
+ if (entry?.block.type === "button") {
345
439
  const actions = doc.createElement("div");
346
440
  actions.className = "veo-guide-actions";
441
+ actions.dataset.veoIdx = String(entry.idx);
347
442
  let rowAlign;
348
- while (i < blocks.length && blocks[i]?.type === "button") {
349
- const btnBlock = blocks[i];
443
+ while (i < blocks.length && blocks[i]?.block.type === "button") {
444
+ const btnBlock = blocks[i].block;
350
445
  if (!rowAlign) {
351
446
  const a = btnBlock.style?.align;
352
447
  if (a === "left" || a === "center" || a === "right") rowAlign = a;
@@ -358,8 +453,11 @@ function renderBlocks(container, blocks, doc, callbacks) {
358
453
  container.appendChild(actions);
359
454
  continue;
360
455
  }
361
- const node = buildContentBlock(block, doc);
362
- if (node) container.appendChild(node);
456
+ const node = entry ? buildContentBlock(entry.block, doc) : null;
457
+ if (node && entry) {
458
+ node.dataset.veoIdx = String(entry.idx);
459
+ container.appendChild(node);
460
+ }
363
461
  i++;
364
462
  }
365
463
  }
@@ -1531,7 +1629,7 @@ var BannerRenderer = class extends BaseRenderer {
1531
1629
  const step = context.guide.guideSteps[idx];
1532
1630
  if (!step) return;
1533
1631
  const position = step.style?.position === "bottom" ? "bottom" : "top";
1534
- const selector = context.nav ? null : step.selector?.trim() ?? null;
1632
+ const selector = step.selector?.trim() || null;
1535
1633
  let anchor = null;
1536
1634
  if (selector) {
1537
1635
  anchor = await waitForElement(selector);
@@ -3389,6 +3487,7 @@ function initBuilderMode() {
3389
3487
  let panel = null;
3390
3488
  let staticTarget = null;
3391
3489
  let manipulator = null;
3490
+ let dropTarget = null;
3392
3491
  let pendingPreview = null;
3393
3492
  const getTarget = () => panel ? panel.target() : staticTarget;
3394
3493
  const post = (event) => {
@@ -3397,6 +3496,8 @@ function initBuilderMode() {
3397
3496
  const applyPreview = (cmd) => {
3398
3497
  manipulator?.detach();
3399
3498
  manipulator = null;
3499
+ dropTarget?.detach();
3500
+ dropTarget = null;
3400
3501
  const handle = previewGuide(cmd.guide);
3401
3502
  if (!cmd.editable) return;
3402
3503
  void handle.ready.then((result) => {
@@ -3415,6 +3516,11 @@ function initBuilderMode() {
3415
3516
  applyPreview(queued);
3416
3517
  }
3417
3518
  });
3519
+ dropTarget = attachBlockDropTarget({
3520
+ host,
3521
+ stepIndex: cmd.guide.startStepIndex ?? 0,
3522
+ onDrop: (payload) => post({ type: "block-dropped", payload })
3523
+ });
3418
3524
  });
3419
3525
  };
3420
3526
  const handleCommand = (cmd) => {
@@ -3449,6 +3555,8 @@ function initBuilderMode() {
3449
3555
  case "close-preview":
3450
3556
  manipulator?.detach();
3451
3557
  manipulator = null;
3558
+ dropTarget?.detach();
3559
+ dropTarget = null;
3452
3560
  pendingPreview = null;
3453
3561
  closeGuidePreview();
3454
3562
  break;
@@ -3471,6 +3579,8 @@ function initBuilderMode() {
3471
3579
  picker = null;
3472
3580
  manipulator?.detach();
3473
3581
  manipulator = null;
3582
+ dropTarget?.detach();
3583
+ dropTarget = null;
3474
3584
  pendingPreview = null;
3475
3585
  closeGuidePreview();
3476
3586
  post({ type: "closed" });