@fc3/mmcadi 0.1.57 → 0.1.59

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 +1 @@
1
- 1767736645
1
+ 1767915849
@@ -1 +1 @@
1
- 1767736776
1
+ 1767916022
package/dist/client.js CHANGED
@@ -2280,7 +2280,13 @@
2280
2280
  var InteractionHelper = class {
2281
2281
  constructor() {
2282
2282
  this.drag_start_coordinate = null;
2283
+ this.drag_current_coordinate = null;
2283
2284
  this.drag_delay_timer = null;
2285
+ this.scroll_timer = null;
2286
+ this.scroll_direction = null;
2287
+ this.last_scroll_time = null;
2288
+ this.current_scroll_y = null;
2289
+ this.swiping = false;
2284
2290
  }
2285
2291
  attach() {
2286
2292
  if (!this.isTouchDevice()) {
@@ -2350,7 +2356,8 @@
2350
2356
  if (coordinate === null) {
2351
2357
  return;
2352
2358
  }
2353
- this.drag_start_coordinate = coordinate;
2359
+ this.setDragStartCoordinate(coordinate);
2360
+ this.setDragCurrentCoordinate(coordinate);
2354
2361
  block.classList.add("drag-candidate");
2355
2362
  this.scheduleDelayedDrag();
2356
2363
  event.preventDefault();
@@ -2430,22 +2437,116 @@
2430
2437
  }
2431
2438
  handleTouchMove(event) {
2432
2439
  const current_coordinate = this.getEventCoordinate(event);
2440
+ this.setDragCurrentCoordinate(current_coordinate);
2441
+ this.cancelDelayedDrag();
2442
+ this.demoteAllDragCandidates();
2443
+ if (this.isSwiping()) {
2444
+ return this.handleSwipe();
2445
+ }
2446
+ if (this.shouldBeSwiping()) {
2447
+ return this.activateSwiping();
2448
+ }
2449
+ this.scheduleDelayedDrag();
2450
+ this.updateDragTargets();
2451
+ if (this.isDragging()) {
2452
+ event.preventDefault();
2453
+ }
2454
+ }
2455
+ getCurrentAndStartCoordinates() {
2456
+ const start_coordinate = this.getDragStartCoordinate();
2457
+ const current_coordinate = this.getDragCurrentCoordinate();
2458
+ if (start_coordinate === null) {
2459
+ throw new import_errors8.InvariantViolation(`
2460
+ Tried to read start coordinate during touch event,
2461
+ but it was not set
2462
+ `);
2463
+ }
2464
+ if (current_coordinate === null) {
2465
+ throw new import_errors8.InvariantViolation(`
2466
+ Tried to read current coordinate during touch event,
2467
+ but it was not set
2468
+ `);
2469
+ }
2470
+ return [current_coordinate, start_coordinate];
2471
+ }
2472
+ handleSwipe() {
2473
+ const [current_coordinate, start_coordinate] = this.getCurrentAndStartCoordinates();
2474
+ const x_delta = current_coordinate.x - start_coordinate.x;
2475
+ const raw_elements = document.querySelectorAll("section.swiping");
2476
+ const elements = Array.from(raw_elements);
2477
+ elements.forEach((element) => {
2478
+ const normalized_delta = Math.min(0, x_delta);
2479
+ element.style.transform = `translateX(${normalized_delta}px)`;
2480
+ });
2481
+ }
2482
+ activateSwiping() {
2483
+ this.swiping = true;
2484
+ const blocks = this.getCurrentTouchedBlocks();
2485
+ blocks.forEach((block) => {
2486
+ block.style.width = `${block.clientWidth}px`;
2487
+ block.classList.add("swiping");
2488
+ });
2489
+ }
2490
+ deactivateSwiping() {
2491
+ this.swiping = false;
2492
+ const [current_coordinate, start_coordinate] = this.getCurrentAndStartCoordinates();
2493
+ const delta = current_coordinate.x - start_coordinate.x;
2494
+ const raw_blocks = document.querySelectorAll("section.swiping");
2495
+ const blocks = Array.from(raw_blocks);
2496
+ blocks.forEach((block) => {
2497
+ block.style.transform = "";
2498
+ block.classList.remove("swiping");
2499
+ const swipe_open = delta < block.clientWidth / 2 * -1;
2500
+ if (swipe_open) {
2501
+ const raw_open_blocks = document.querySelectorAll(".swipe-open");
2502
+ const open_blocks = Array.from(raw_open_blocks);
2503
+ open_blocks.forEach((block2) => {
2504
+ block2.classList.remove("swipe-open");
2505
+ });
2506
+ }
2507
+ block.classList.toggle("swipe-open", swipe_open);
2508
+ });
2509
+ }
2510
+ getCurrentTouchedBlocks() {
2511
+ const [current_coordinate, _] = this.getCurrentAndStartCoordinates();
2512
+ const { x, y } = current_coordinate;
2513
+ const raw_blocks = document.querySelectorAll("section.block");
2514
+ const blocks = Array.from(raw_blocks);
2515
+ return blocks.filter((block) => {
2516
+ const rect = block.getBoundingClientRect();
2517
+ if (x > rect.left && x < rect.right && y > rect.top && y < rect.bottom) {
2518
+ return true;
2519
+ }
2520
+ return false;
2521
+ });
2522
+ }
2523
+ shouldBeSwiping() {
2524
+ const blocks = this.getCurrentTouchedBlocks();
2525
+ const open_block = blocks.find((block) => {
2526
+ return block.classList.contains("swipe-open");
2527
+ });
2528
+ if (open_block) {
2529
+ return true;
2530
+ }
2531
+ const current_coordinate = this.getDragCurrentCoordinate();
2433
2532
  const start_coordinate = this.getDragStartCoordinate();
2434
2533
  if (start_coordinate === null || current_coordinate === null) {
2435
- return;
2534
+ return false;
2436
2535
  }
2437
- this.demoteAllDragCandidates();
2438
- this.scheduleDelayedDrag();
2536
+ const x_delta = current_coordinate.x - start_coordinate.x;
2537
+ const y_delta = current_coordinate.y - start_coordinate.y;
2538
+ const x_threshold = -1 * 48;
2539
+ const y_threshold = 48;
2540
+ return x_delta < x_threshold && Math.abs(y_delta) < y_threshold;
2541
+ }
2542
+ updateDragTargets() {
2439
2543
  const raw_targets = document.querySelectorAll(".dragging");
2440
2544
  const drag_target_blocks = Array.from(raw_targets);
2441
2545
  drag_target_blocks.forEach((target_block) => {
2442
- this.translateDragTargetBlock(target_block, current_coordinate);
2546
+ this.updateDragTarget(target_block);
2443
2547
  });
2444
- if (drag_target_blocks.length > 0) {
2445
- event.preventDefault();
2446
- }
2447
2548
  }
2448
- translateDragTargetBlock(block, current_coordinate) {
2549
+ updateDragTarget(block) {
2449
2550
  const x_attribute = block.getAttribute("data-drag-start-x");
2450
2551
  const y_attribute = block.getAttribute("data-drag-start-y");
2451
2552
  if (x_attribute === null || y_attribute === null) {
@@ -2464,18 +2565,26 @@
2464
2565
  y: ${y_attribute}
2465
2566
  `);
2466
2567
  }
2467
- const start_coordinate = this.getDragStartCoordinate();
2468
- if (start_coordinate === null) {
2469
- throw new import_errors8.InvariantViolation(`
2470
- Tried to translate drag target, but drag start coordinate was null
2471
- `);
2472
- }
2568
+ const [current_coordinate, start_coordinate] = this.getCurrentAndStartCoordinates();
2473
2569
  const { x: start_x, y: start_y } = start_coordinate;
2474
2570
  const { x: current_x, y: current_y } = current_coordinate;
2475
2571
  const x_delta = current_x - start_x;
2476
2572
  const y_delta = current_y - start_y;
2573
+ const container = document.querySelector("main");
2574
+ if (container === null) {
2575
+ throw new import_errors8.InvariantViolation(`
2576
+ Unable to find <main> container element in the DOM
2577
+ `);
2578
+ }
2579
+ const container_rect = container.getBoundingClientRect();
2477
2580
  const new_x = parsed_x + x_delta;
2478
- const new_y = parsed_y + y_delta;
2581
+ const new_y = Math.max(
2582
+ container_rect.top,
2583
+ Math.min(
2584
+ parsed_y + y_delta,
2585
+ container_rect.bottom
2586
+ )
2587
+ );
2479
2588
  block.style.left = `${new_x}px`;
2480
2589
  block.style.top = `${new_y}px`;
2481
2590
  const block_rect = block.getBoundingClientRect();
@@ -2506,6 +2615,91 @@
2506
2615
  }
2507
2616
  }
2508
2617
  }
2618
+ if (block_rect.top < 0) {
2619
+ this.startScrollingUp();
2620
+ } else if (block_rect.bottom > window.innerHeight) {
2621
+ this.startScrollingDown();
2622
+ } else {
2623
+ this.stopScrolling();
2624
+ }
2625
+ }
2626
+ stopScrolling() {
2627
+ this.setScrollDirection(null);
2628
+ }
2629
+ startScrollingUp() {
2630
+ this.setScrollDirection("up" /* UP */);
2631
+ }
2632
+ startScrollingDown() {
2633
+ this.setScrollDirection("down" /* DOWN */);
2634
+ }
2635
+ setScrollDirection(scroll_direction) {
2636
+ if (this.scroll_direction === scroll_direction) {
2637
+ return;
2638
+ }
2639
+ this.scroll_direction = scroll_direction;
2640
+ if (scroll_direction === null) {
2641
+ this.last_scroll_time = null;
2642
+ this.current_scroll_y = null;
2643
+ } else {
2644
+ this.last_scroll_time = Date.now();
2645
+ this.current_scroll_y = window.scrollY;
2646
+ this.scheduleScroll();
2647
+ }
2648
+ }
2649
+ getScrollDirection() {
2650
+ return this.scroll_direction;
2651
+ }
2652
+ setLastScrollTime(time) {
2653
+ this.last_scroll_time = time;
2654
+ }
2655
+ getLastScrollTime() {
2656
+ if (this.last_scroll_time === null) {
2657
+ throw new import_errors8.InvariantViolation(`
2658
+ Tried to read last scroll time, but it was not set
2659
+ `);
2660
+ }
2661
+ return this.last_scroll_time;
2662
+ }
2663
+ scheduleScroll() {
2664
+ if (this.scroll_timer) {
2665
+ window.cancelAnimationFrame(this.scroll_timer);
2666
+ this.scroll_timer = null;
2667
+ }
2668
+ this.scroll_timer = window.requestAnimationFrame(() => {
2669
+ this.scroll();
2670
+ });
2671
+ }
2672
+ scroll() {
2673
+ if (!this.isDragging()) {
2674
+ return;
2675
+ }
2676
+ const scroll_direction = this.getScrollDirection();
2677
+ if (scroll_direction === null) {
2678
+ return;
2679
+ }
2680
+ const last_scroll_time = this.getLastScrollTime();
2681
+ const now = Date.now();
2682
+ const elapsed_time = now - last_scroll_time;
2683
+ const scroll_speed_per_second = window.innerHeight / 2;
2684
+ const time_ratio = elapsed_time / import_time.TimeInterval.ONE_SECOND;
2685
+ const scroll_amount = scroll_speed_per_second * time_ratio;
2686
+ const scroll_y = this.getCurrentScrollY();
2687
+ const sign = scroll_direction === "up" /* UP */ ? -1 : 1;
2688
+ const new_scroll_y = Math.max(
2689
+ 0,
2690
+ Math.min(
2691
+ document.documentElement.scrollHeight,
2692
+ scroll_y + scroll_amount * sign
2693
+ )
2694
+ );
2695
+ this.setCurrentScrollY(new_scroll_y);
2696
+ this.setLastScrollTime(now);
2697
+ const window_moved = new_scroll_y !== scroll_y;
2698
+ if (window_moved) {
2699
+ window.scrollTo(0, new_scroll_y);
2700
+ this.updateDragTargets();
2701
+ }
2702
+ this.scheduleScroll();
2509
2703
  }
2510
2704
  getGhostForBlock(block) {
2511
2705
  const index_path = get_index_path_for_element_default(block);
@@ -2549,12 +2743,16 @@
2549
2743
  if (index === -1) {
2550
2744
  throw new import_errors8.InvariantViolation("Unable to locate ghost within siblings");
2551
2745
  }
2746
+ index++;
2552
2747
  while (index < siblings.length) {
2553
- index++;
2554
- const sibling = siblings[index];
2748
+ const sibling = siblings[index++];
2555
2749
  if (sibling === block) {
2556
2750
  continue;
2557
2751
  }
2752
+ if (sibling === void 0) {
2753
+ console.log(sibling);
2754
+ console.log(siblings);
2755
+ }
2558
2756
  const { classList } = sibling;
2559
2757
  if (!classList.contains("block")) {
2560
2758
  continue;
@@ -2567,7 +2765,12 @@
2567
2765
  return null;
2568
2766
  }
2569
2767
  handleTouchEnd(event) {
2570
- this.stopDragging();
2768
+ if (this.isSwiping()) {
2769
+ this.deactivateSwiping();
2770
+ }
2771
+ if (this.isDragging()) {
2772
+ this.stopDragging();
2773
+ }
2571
2774
  }
2572
2775
  handleGenericClick(event) {
2573
2776
  const { target } = event;
@@ -2698,6 +2901,29 @@
2698
2901
  getDragStartCoordinate() {
2699
2902
  return this.drag_start_coordinate;
2700
2903
  }
2904
+ setDragStartCoordinate(coordinate) {
2905
+ this.drag_start_coordinate = coordinate;
2906
+ }
2907
+ getDragCurrentCoordinate() {
2908
+ return this.drag_current_coordinate;
2909
+ }
2910
+ setDragCurrentCoordinate(coordinate) {
2911
+ this.drag_current_coordinate = coordinate;
2912
+ }
2913
+ getCurrentScrollY() {
2914
+ if (this.current_scroll_y === null) {
2915
+ throw new import_errors8.InvariantViolation(`
2916
+ Tried to read current scroll y, but it was not set
2917
+ `);
2918
+ }
2919
+ return this.current_scroll_y;
2920
+ }
2921
+ setCurrentScrollY(scroll_y) {
2922
+ this.current_scroll_y = scroll_y;
2923
+ }
2924
+ isSwiping() {
2925
+ return this.swiping;
2926
+ }
2701
2927
  };
2702
2928
  var interaction_default = InteractionHelper;
2703
2929
 
@@ -1,6 +1,12 @@
1
1
  declare class InteractionHelper {
2
2
  private drag_start_coordinate;
3
+ private drag_current_coordinate;
3
4
  private drag_delay_timer;
5
+ private scroll_timer;
6
+ private scroll_direction;
7
+ private last_scroll_time;
8
+ private current_scroll_y;
9
+ private swiping;
4
10
  constructor();
5
11
  attach(): void;
6
12
  isDragging(): boolean;
@@ -15,7 +21,23 @@ declare class InteractionHelper {
15
21
  private beginDelayedDrag;
16
22
  private handleNativeDragStart;
17
23
  private handleTouchMove;
18
- private translateDragTargetBlock;
24
+ private getCurrentAndStartCoordinates;
25
+ private handleSwipe;
26
+ private activateSwiping;
27
+ private deactivateSwiping;
28
+ private getCurrentTouchedBlocks;
29
+ private shouldBeSwiping;
30
+ private updateDragTargets;
31
+ private updateDragTarget;
32
+ private stopScrolling;
33
+ private startScrollingUp;
34
+ private startScrollingDown;
35
+ private setScrollDirection;
36
+ private getScrollDirection;
37
+ private setLastScrollTime;
38
+ private getLastScrollTime;
39
+ private scheduleScroll;
40
+ private scroll;
19
41
  private getGhostForBlock;
20
42
  private getPreviousBlock;
21
43
  private getNextBlock;
@@ -28,5 +50,11 @@ declare class InteractionHelper {
28
50
  private submitReposition;
29
51
  private getEventCoordinate;
30
52
  private getDragStartCoordinate;
53
+ private setDragStartCoordinate;
54
+ private getDragCurrentCoordinate;
55
+ private setDragCurrentCoordinate;
56
+ private getCurrentScrollY;
57
+ private setCurrentScrollY;
58
+ private isSwiping;
31
59
  }
32
60
  export default InteractionHelper;