react-matchings 0.0.8 → 0.1.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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- const __REACT_MATCHINGS_AUTO_CSS__ = "/*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */\n@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-space-y-reverse:0;--tw-border-style:solid;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace;--color-slate-300:oklch(86.9% .022 252.894);--color-slate-700:oklch(37.2% .044 257.287);--color-slate-900:oklch(20.8% .042 265.755);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-500:oklch(55.1% .027 264.364);--color-gray-700:oklch(37.3% .034 259.733);--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-3xl:48rem;--font-weight-medium:500;--radius-md:.375rem;--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab, red, red)){::placeholder{color:color-mix(in oklab, currentcolor 50%, transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.pointer-events-none{pointer-events:none}.absolute{position:absolute}.relative{position:relative}.z-10{z-index:10}.z-20{z-index:20}.contents{display:contents}.grid{display:grid}.h-full{height:100%}.w-full{width:100%}.max-w-3xl{max-width:var(--container-3xl)}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.gap-10{gap:calc(var(--spacing) * 10)}:where(.space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 3) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 3) * calc(1 - var(--tw-space-y-reverse)))}.rounded{border-radius:.25rem}.rounded-md{border-radius:var(--radius-md)}.border{border-style:var(--tw-border-style);border-width:1px}.border-gray-200{border-color:var(--color-gray-200)}.border-slate-300{border-color:var(--color-slate-300)}.bg-black{background-color:var(--color-black)}.bg-gray-700{background-color:var(--color-gray-700)}.bg-slate-900{background-color:var(--color-slate-900)}.bg-white{background-color:var(--color-white)}.p-4{padding:calc(var(--spacing) * 4)}.p-6{padding:calc(var(--spacing) * 6)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.text-slate-900{color:var(--color-slate-900)}.text-white{color:var(--color-white)}.select-none{-webkit-user-select:none;user-select:none}@media (hover:hover){.hover\\:bg-slate-700:hover{background-color:var(--color-slate-700)}}.focus\\:ring-2:focus{--tw-ring-shadow:var(--tw-ring-inset,) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.focus\\:ring-gray-500:focus{--tw-ring-color:var(--color-gray-500)}.focus\\:outline-none:focus{--tw-outline-style:none;outline-style:none}}@property --tw-space-y-reverse{syntax:\"*\";inherits:false;initial-value:0}@property --tw-border-style{syntax:\"*\";inherits:false;initial-value:solid}@property --tw-font-weight{syntax:\"*\";inherits:false}@property --tw-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:\"*\";inherits:false}@property --tw-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:\"*\";inherits:false}@property --tw-inset-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:\"*\";inherits:false}@property --tw-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:\"*\";inherits:false}@property --tw-inset-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:\"*\";inherits:false}@property --tw-ring-offset-width{syntax:\"<length>\";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:\"*\";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}";
1
+ const __REACT_MATCHINGS_AUTO_CSS__ = "/*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */\n@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-space-y-reverse:0;--tw-border-style:solid;--tw-font-weight:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000}}}@layer theme{:root,:host{--font-sans:ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";--font-mono:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace;--color-red-500:oklch(63.7% .237 25.331);--color-slate-300:oklch(86.9% .022 252.894);--color-slate-700:oklch(37.2% .044 257.287);--color-slate-900:oklch(20.8% .042 265.755);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-500:oklch(55.1% .027 264.364);--color-gray-700:oklch(37.3% .034 259.733);--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-3xl:48rem;--font-weight-medium:500;--radius-md:.375rem;--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab, red, red)){::placeholder{color:color-mix(in oklab, currentcolor 50%, transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){appearance:button}::file-selector-button{appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}}@layer components;@layer utilities{.pointer-events-none{pointer-events:none}.absolute{position:absolute}.relative{position:relative}.z-10{z-index:10}.z-20{z-index:20}.container{width:100%}@media (min-width:40rem){.container{max-width:40rem}}@media (min-width:48rem){.container{max-width:48rem}}@media (min-width:64rem){.container{max-width:64rem}}@media (min-width:80rem){.container{max-width:80rem}}@media (min-width:96rem){.container{max-width:96rem}}.contents{display:contents}.grid{display:grid}.h-full{height:100%}.w-full{width:100%}.max-w-3xl{max-width:var(--container-3xl)}.touch-none{touch-action:none}.resize{resize:both}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.gap-10{gap:calc(var(--spacing) * 10)}:where(.space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing) * 3) * var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing) * 3) * calc(1 - var(--tw-space-y-reverse)))}.rounded{border-radius:.25rem}.rounded-md{border-radius:var(--radius-md)}.border{border-style:var(--tw-border-style);border-width:1px}.border-gray-200{border-color:var(--color-gray-200)}.border-slate-300{border-color:var(--color-slate-300)}.bg-black{background-color:var(--color-black)}.bg-gray-700{background-color:var(--color-gray-700)}.bg-red-500{background-color:var(--color-red-500)}.bg-slate-900{background-color:var(--color-slate-900)}.bg-white{background-color:var(--color-white)}.p-4{padding:calc(var(--spacing) * 4)}.p-6{padding:calc(var(--spacing) * 6)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.text-slate-900{color:var(--color-slate-900)}.text-white{color:var(--color-white)}.select-none{-webkit-user-select:none;user-select:none}@media (hover:hover){.hover\\:bg-slate-700:hover{background-color:var(--color-slate-700)}}.focus\\:ring-2:focus{--tw-ring-shadow:var(--tw-ring-inset,) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow)}.focus\\:ring-gray-500:focus{--tw-ring-color:var(--color-gray-500)}.focus\\:outline-none:focus{--tw-outline-style:none;outline-style:none}}@property --tw-space-y-reverse{syntax:\"*\";inherits:false;initial-value:0}@property --tw-border-style{syntax:\"*\";inherits:false;initial-value:solid}@property --tw-font-weight{syntax:\"*\";inherits:false}@property --tw-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:\"*\";inherits:false}@property --tw-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:\"*\";inherits:false}@property --tw-inset-shadow-alpha{syntax:\"<percentage>\";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:\"*\";inherits:false}@property --tw-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:\"*\";inherits:false}@property --tw-inset-ring-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:\"*\";inherits:false}@property --tw-ring-offset-width{syntax:\"<length>\";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:\"*\";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:\"*\";inherits:false;initial-value:0 0 #0000}";
2
2
  function __injectReactMatchingsCss() {
3
3
  if (typeof document === "undefined" || document.getElementById("__REACT_MATCHINGS_AUTO_CSS__")) return;
4
4
  const style = document.createElement("style");
@@ -8,7 +8,7 @@ function __injectReactMatchingsCss() {
8
8
  }
9
9
  __injectReactMatchingsCss();
10
10
  // src/matching.tsx
11
- import { useCallback, useEffect, useRef, useState } from "react";
11
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
12
12
 
13
13
  // src/lib/utils.ts
14
14
  import { clsx } from "clsx";
@@ -19,9 +19,36 @@ function cn(...inputs) {
19
19
 
20
20
  // src/matching.tsx
21
21
  import { jsx, jsxs } from "react/jsx-runtime";
22
+ var DEFAULT_EDGE_THRESHOLD = 64;
23
+ var DEFAULT_MAX_SCROLL_SPEED = 16;
24
+ function toMatches(matches) {
25
+ return Object.entries(matches).map(([questionId, answerId]) => ({
26
+ questionId: Number(questionId),
27
+ answerId
28
+ }));
29
+ }
30
+ function toMatchRecord(matches) {
31
+ return (matches ?? []).reduce((record, match) => {
32
+ record[match.questionId] = match.answerId;
33
+ return record;
34
+ }, {});
35
+ }
36
+ function findScrollableAncestor(element) {
37
+ let current = element.parentElement;
38
+ while (current) {
39
+ const { overflowY } = window.getComputedStyle(current);
40
+ if (/(auto|scroll|overlay)/.test(overflowY) && current.scrollHeight > current.clientHeight) {
41
+ return current;
42
+ }
43
+ current = current.parentElement;
44
+ }
45
+ return document.scrollingElement ?? document.documentElement;
46
+ }
22
47
  function Matching({
23
48
  questions,
24
49
  answers,
50
+ matches: controlledMatches,
51
+ defaultMatches,
25
52
  className,
26
53
  questionClassName,
27
54
  answerClassName,
@@ -30,19 +57,41 @@ function Matching({
30
57
  circleRadius = 8,
31
58
  offset = 10,
32
59
  disabled,
60
+ allowAnswerReuse = false,
61
+ autoScroll = true,
62
+ getMatchStyles,
33
63
  onChange
34
64
  }) {
35
- const [matches, setMatches] = useState({});
65
+ const [uncontrolledMatches, setUncontrolledMatches] = useState(
66
+ () => toMatchRecord(defaultMatches)
67
+ );
36
68
  const [lines, setLines] = useState([]);
37
69
  const [dragging, setDragging] = useState(null);
38
70
  const [dragLine, setDragLine] = useState(null);
39
71
  const containerRef = useRef(null);
40
72
  const questionRefs = useRef({});
41
73
  const answerRefs = useRef({});
74
+ const pointerRef = useRef(null);
75
+ const scrollElementRef = useRef(null);
76
+ const scrollFrameRef = useRef(null);
77
+ const isControlled = controlledMatches !== void 0;
78
+ const matches = useMemo(
79
+ () => isControlled ? toMatchRecord(controlledMatches) : uncontrolledMatches,
80
+ [controlledMatches, isControlled, uncontrolledMatches]
81
+ );
82
+ const setMatches = useCallback(
83
+ (next) => {
84
+ if (!isControlled) {
85
+ setUncontrolledMatches(next);
86
+ }
87
+ queueMicrotask(() => onChange?.(toMatches(next)));
88
+ },
89
+ [isControlled, onChange]
90
+ );
42
91
  const getElementCenter = useCallback(
43
- (el, isAnswer = false) => {
44
- if (!el || !containerRef.current) return null;
45
- const rect = el.getBoundingClientRect();
92
+ (element, isAnswer = false) => {
93
+ if (!element || !containerRef.current) return null;
94
+ const rect = element.getBoundingClientRect();
46
95
  const containerRect = containerRef.current.getBoundingClientRect();
47
96
  return {
48
97
  x: isAnswer ? rect.left - containerRect.left + circleRadius + offset : rect.right - containerRect.left - circleRadius - offset,
@@ -51,90 +100,131 @@ function Matching({
51
100
  },
52
101
  [circleRadius, offset]
53
102
  );
54
- const handleMouseDown = (qId) => {
55
- if (disabled) return;
56
- setDragging(qId);
57
- requestAnimationFrame(() => {
58
- const start = getElementCenter(questionRefs.current[qId]);
59
- if (start) setDragLine({ start, end: start, questionId: qId });
103
+ const refreshLines = useCallback(() => {
104
+ const nextLines = toMatches(matches).map(({ questionId, answerId }) => {
105
+ const start = getElementCenter(questionRefs.current[questionId]);
106
+ const end = getElementCenter(answerRefs.current[answerId], true);
107
+ return start && end ? { questionId, answerId, start, end } : null;
108
+ }).filter((line) => line !== null);
109
+ setLines(nextLines);
110
+ }, [getElementCenter, matches]);
111
+ const refreshDragLine = useCallback(() => {
112
+ if (dragging == null || !containerRef.current || !pointerRef.current) return;
113
+ const start = getElementCenter(questionRefs.current[dragging]);
114
+ if (!start) return;
115
+ const rect = containerRef.current.getBoundingClientRect();
116
+ setDragLine({
117
+ start,
118
+ end: {
119
+ x: pointerRef.current.clientX - rect.left,
120
+ y: pointerRef.current.clientY - rect.top
121
+ }
60
122
  });
123
+ }, [dragging, getElementCenter]);
124
+ const stopAutoScroll = useCallback(() => {
125
+ if (scrollFrameRef.current !== null) cancelAnimationFrame(scrollFrameRef.current);
126
+ scrollFrameRef.current = null;
127
+ scrollElementRef.current = null;
128
+ }, []);
129
+ const runAutoScroll = useCallback(() => {
130
+ scrollFrameRef.current = null;
131
+ if (autoScroll === false || dragging == null || !pointerRef.current) return;
132
+ const scrollElement = scrollElementRef.current;
133
+ if (!scrollElement) return;
134
+ const isDocument = scrollElement === document.scrollingElement;
135
+ const rect = isDocument ? { top: 0, bottom: window.innerHeight } : scrollElement.getBoundingClientRect();
136
+ const edgeThreshold = typeof autoScroll === "object" ? autoScroll.edgeThreshold ?? DEFAULT_EDGE_THRESHOLD : DEFAULT_EDGE_THRESHOLD;
137
+ const maxSpeed = typeof autoScroll === "object" ? autoScroll.maxSpeed ?? DEFAULT_MAX_SCROLL_SPEED : DEFAULT_MAX_SCROLL_SPEED;
138
+ const { clientY } = pointerRef.current;
139
+ let speed = 0;
140
+ if (clientY < rect.top + edgeThreshold) {
141
+ speed = -maxSpeed * (1 - Math.max(0, clientY - rect.top) / edgeThreshold);
142
+ } else if (clientY > rect.bottom - edgeThreshold) {
143
+ speed = maxSpeed * (1 - Math.max(0, rect.bottom - clientY) / edgeThreshold);
144
+ }
145
+ if (speed !== 0) {
146
+ const previousScrollTop = scrollElement.scrollTop;
147
+ scrollElement.scrollTop += speed;
148
+ if (scrollElement.scrollTop !== previousScrollTop) {
149
+ refreshLines();
150
+ refreshDragLine();
151
+ }
152
+ }
153
+ scrollFrameRef.current = requestAnimationFrame(runAutoScroll);
154
+ }, [autoScroll, dragging, refreshDragLine, refreshLines]);
155
+ const cancelDragging = useCallback(() => {
156
+ setDragging(null);
157
+ setDragLine(null);
158
+ pointerRef.current = null;
159
+ stopAutoScroll();
160
+ }, [stopAutoScroll]);
161
+ const handlePointerDown = (event, questionId) => {
162
+ if (disabled || !containerRef.current) return;
163
+ event.preventDefault();
164
+ pointerRef.current = { id: event.pointerId, clientX: event.clientX, clientY: event.clientY };
165
+ scrollElementRef.current = findScrollableAncestor(containerRef.current);
166
+ setDragging(questionId);
61
167
  };
62
- const handleMouseMove = useCallback(
63
- (e) => {
64
- if (dragging == null || !containerRef.current) return;
65
- const rect = containerRef.current.getBoundingClientRect();
66
- setDragLine(
67
- (prev) => prev ? {
68
- ...prev,
69
- end: { x: e.clientX - rect.left, y: e.clientY - rect.top }
70
- } : null
71
- );
168
+ const handlePointerMove = useCallback(
169
+ (event) => {
170
+ if (dragging == null || pointerRef.current?.id !== event.pointerId) return;
171
+ pointerRef.current = { id: event.pointerId, clientX: event.clientX, clientY: event.clientY };
172
+ refreshDragLine();
72
173
  },
73
- [dragging]
174
+ [dragging, refreshDragLine]
74
175
  );
75
- const handleMouseUp = (aId) => {
76
- if (dragging != null) {
77
- setMatches((prev) => {
78
- const newMatches = { ...prev, [dragging]: aId };
79
- if (onChange) {
80
- queueMicrotask(
81
- () => onChange(
82
- Object.entries(newMatches).map(([qId, aId2]) => ({
83
- questionId: Number(qId),
84
- answerId: aId2
85
- }))
86
- )
87
- );
176
+ const handlePointerUp = (event, answerId) => {
177
+ if (dragging != null && pointerRef.current?.id === event.pointerId) {
178
+ const next = { ...matches };
179
+ if (!allowAnswerReuse) {
180
+ for (const [questionId, matchedAnswerId] of Object.entries(next)) {
181
+ if (matchedAnswerId === answerId) delete next[Number(questionId)];
88
182
  }
89
- return newMatches;
90
- });
183
+ }
184
+ next[dragging] = answerId;
185
+ setMatches(next);
91
186
  }
92
- setDragging(null);
93
- setDragLine(null);
187
+ cancelDragging();
94
188
  };
95
- const removeMatch = (qId) => {
96
- setMatches((prev) => {
97
- const newMatches = { ...prev };
98
- delete newMatches[qId];
99
- if (onChange) {
100
- queueMicrotask(
101
- () => onChange(
102
- Object.entries(newMatches).map(([qId2, aId]) => ({
103
- questionId: Number(qId2),
104
- answerId: aId
105
- }))
106
- )
107
- );
108
- }
109
- return newMatches;
110
- });
189
+ const removeMatch = (questionId) => {
190
+ const next = { ...matches };
191
+ delete next[questionId];
192
+ setMatches(next);
111
193
  };
112
194
  useEffect(() => {
113
195
  if (dragging == null) return;
114
- const handleUp = () => {
115
- setDragging(null);
116
- setDragLine(null);
196
+ refreshDragLine();
197
+ if (autoScroll !== false && scrollFrameRef.current === null) {
198
+ scrollFrameRef.current = requestAnimationFrame(runAutoScroll);
199
+ }
200
+ const handleUp = (event) => {
201
+ if (pointerRef.current?.id === event.pointerId) cancelDragging();
117
202
  };
118
- document.addEventListener("mousemove", handleMouseMove);
119
- document.addEventListener("mouseup", handleUp);
203
+ document.addEventListener("pointermove", handlePointerMove);
204
+ document.addEventListener("pointerup", handleUp);
205
+ document.addEventListener("pointercancel", handleUp);
120
206
  return () => {
121
- document.removeEventListener("mousemove", handleMouseMove);
122
- document.removeEventListener("mouseup", handleUp);
207
+ document.removeEventListener("pointermove", handlePointerMove);
208
+ document.removeEventListener("pointerup", handleUp);
209
+ document.removeEventListener("pointercancel", handleUp);
210
+ stopAutoScroll();
123
211
  };
124
- }, [dragging, handleMouseMove]);
212
+ }, [
213
+ autoScroll,
214
+ cancelDragging,
215
+ dragging,
216
+ handlePointerMove,
217
+ refreshDragLine,
218
+ runAutoScroll,
219
+ stopAutoScroll
220
+ ]);
125
221
  useEffect(() => {
126
- if (!containerRef.current) return;
127
- const newLines = Object.entries(matches).map(([qId, aId]) => {
128
- const startEl = questionRefs.current[Number(qId)];
129
- const endEl = answerRefs.current[Number(aId)];
130
- if (!startEl || !endEl) return null;
131
- const start = getElementCenter(startEl, false);
132
- const end = getElementCenter(endEl, true);
133
- if (!start || !end) return null;
134
- return { qId, aId: aId.toString(), start, end };
135
- }).filter(Boolean);
136
- setLines(newLines);
137
- }, [matches, getElementCenter]);
222
+ refreshLines();
223
+ }, [refreshLines]);
224
+ useEffect(() => {
225
+ window.addEventListener("resize", refreshLines);
226
+ return () => window.removeEventListener("resize", refreshLines);
227
+ }, [refreshLines]);
138
228
  return /* @__PURE__ */ jsxs(
139
229
  "div",
140
230
  {
@@ -142,30 +232,41 @@ function Matching({
142
232
  ref: containerRef,
143
233
  children: [
144
234
  /* @__PURE__ */ jsxs("svg", { className: "absolute z-20 w-full h-full pointer-events-none", children: [
145
- lines.map(({ qId, aId, start, end }) => /* @__PURE__ */ jsxs("g", { children: [
146
- /* @__PURE__ */ jsx(
147
- "line",
148
- {
149
- x1: start.x,
150
- y1: start.y,
151
- x2: end.x,
152
- y2: end.y,
153
- stroke: lineColor,
154
- strokeWidth: 3,
155
- strokeLinecap: "round"
156
- }
157
- ),
158
- /* @__PURE__ */ jsx(
159
- "circle",
160
- {
161
- cx: start.x,
162
- cy: start.y,
163
- r: circleRadius,
164
- fill: circleColor
165
- }
166
- ),
167
- /* @__PURE__ */ jsx("circle", { cx: end.x, cy: end.y, r: circleRadius, fill: circleColor })
168
- ] }, `${qId}-${aId}`)),
235
+ lines.map((line) => {
236
+ const styles = getMatchStyles?.(line);
237
+ return /* @__PURE__ */ jsxs("g", { children: [
238
+ /* @__PURE__ */ jsx(
239
+ "line",
240
+ {
241
+ x1: line.start.x,
242
+ y1: line.start.y,
243
+ x2: line.end.x,
244
+ y2: line.end.y,
245
+ stroke: styles?.lineColor ?? lineColor,
246
+ strokeWidth: 3,
247
+ strokeLinecap: "round"
248
+ }
249
+ ),
250
+ /* @__PURE__ */ jsx(
251
+ "circle",
252
+ {
253
+ cx: line.start.x,
254
+ cy: line.start.y,
255
+ r: circleRadius,
256
+ fill: styles?.circleColor ?? circleColor
257
+ }
258
+ ),
259
+ /* @__PURE__ */ jsx(
260
+ "circle",
261
+ {
262
+ cx: line.end.x,
263
+ cy: line.end.y,
264
+ r: circleRadius,
265
+ fill: styles?.circleColor ?? circleColor
266
+ }
267
+ )
268
+ ] }, `${line.questionId}-${line.answerId}`);
269
+ }),
169
270
  dragLine && /* @__PURE__ */ jsxs("g", { children: [
170
271
  /* @__PURE__ */ jsx(
171
272
  "line",
@@ -180,63 +281,50 @@ function Matching({
180
281
  strokeLinecap: "round"
181
282
  }
182
283
  ),
183
- /* @__PURE__ */ jsx(
184
- "circle",
185
- {
186
- cx: dragLine.start.x,
187
- cy: dragLine.start.y,
188
- r: circleRadius,
189
- fill: circleColor
190
- }
191
- ),
192
- /* @__PURE__ */ jsx(
193
- "circle",
194
- {
195
- cx: dragLine.end.x,
196
- cy: dragLine.end.y,
197
- r: circleRadius,
198
- fill: circleColor
199
- }
200
- )
284
+ /* @__PURE__ */ jsx("circle", { cx: dragLine.start.x, cy: dragLine.start.y, r: circleRadius, fill: circleColor }),
285
+ /* @__PURE__ */ jsx("circle", { cx: dragLine.end.x, cy: dragLine.end.y, r: circleRadius, fill: circleColor })
201
286
  ] })
202
287
  ] }),
203
- /* @__PURE__ */ jsx("div", { className: "relative z-10 space-y-3", children: questions.map((q) => {
204
- const isMatched = matches[q.id] !== void 0;
288
+ /* @__PURE__ */ jsx("div", { className: "relative z-10 space-y-3", children: questions.map((question) => {
289
+ const answerId = matches[question.id];
290
+ const styles = answerId === void 0 ? void 0 : getMatchStyles?.({ questionId: question.id, answerId });
205
291
  return /* @__PURE__ */ jsx(
206
292
  "button",
207
293
  {
208
- ref: (el) => void (questionRefs.current[q.id] = el),
294
+ ref: (element) => void (questionRefs.current[question.id] = element),
209
295
  type: "button",
210
296
  disabled,
211
- onMouseDown: () => handleMouseDown(q.id),
212
- onClick: () => isMatched && removeMatch(q.id),
297
+ onPointerDown: (event) => handlePointerDown(event, question.id),
298
+ onClick: () => answerId !== void 0 && removeMatch(question.id),
213
299
  className: cn(
214
- "p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500",
215
- isMatched && "bg-gray-700",
216
- questionClassName
300
+ "p-4 rounded bg-black text-white w-full touch-none font-medium focus:outline-none focus:ring-2 focus:ring-gray-500",
301
+ answerId !== void 0 && "bg-gray-700",
302
+ questionClassName,
303
+ styles?.questionClassName
217
304
  ),
218
- children: q.text
305
+ children: question.text
219
306
  },
220
- q.id
307
+ question.id
221
308
  );
222
309
  }) }),
223
- /* @__PURE__ */ jsx("div", { className: "relative z-10 space-y-3", children: answers.map((a) => {
224
- const isMatched = Object.values(matches).includes(a.id);
310
+ /* @__PURE__ */ jsx("div", { className: "relative z-10 space-y-3", children: answers.map((answer) => {
311
+ const answerMatches = toMatches(matches).filter((match) => match.answerId === answer.id);
225
312
  return /* @__PURE__ */ jsx(
226
313
  "button",
227
314
  {
228
- ref: (el) => void (answerRefs.current[a.id] = el),
315
+ ref: (element) => void (answerRefs.current[answer.id] = element),
229
316
  type: "button",
230
317
  disabled,
231
- onMouseUp: () => handleMouseUp(a.id),
318
+ onPointerUp: (event) => handlePointerUp(event, answer.id),
232
319
  className: cn(
233
- "p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500",
234
- isMatched && "bg-gray-700",
235
- answerClassName
320
+ "p-4 rounded bg-black text-white w-full touch-none font-medium focus:outline-none focus:ring-2 focus:ring-gray-500",
321
+ answerMatches.length > 0 && "bg-gray-700",
322
+ answerClassName,
323
+ answerMatches.map((match) => getMatchStyles?.(match)?.answerClassName)
236
324
  ),
237
- children: a.text
325
+ children: answer.text
238
326
  },
239
- a.id
327
+ answer.id
240
328
  );
241
329
  }) })
242
330
  ]
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/matching.tsx","../src/lib/utils.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from \"react\";\nimport { cn } from \"./lib/utils\";\n\nexport type TMatch = {\n questionId: number;\n answerId: number;\n};\n\ntype Props = {\n questions: { id: number; text: string }[];\n answers: { id: number; text: string }[];\n className?: string;\n questionClassName?: string;\n answerClassName?: string;\n lineColor?: string;\n circleColor?: string;\n circleRadius?: number;\n offset?: number;\n disabled?: boolean;\n onChange?: (matches: TMatch[]) => void;\n};\n\ntype Line = {\n qId: string;\n aId: string;\n start: { x: number; y: number };\n end: { x: number; y: number };\n};\n\nexport function Matching({\n questions,\n answers,\n className,\n questionClassName,\n answerClassName,\n lineColor = \"black\",\n circleColor = \"white\",\n circleRadius = 8,\n offset = 10,\n disabled,\n onChange,\n}: Props) {\n const [matches, setMatches] = useState<Record<number, number>>({});\n const [lines, setLines] = useState<Line[]>([]);\n const [dragging, setDragging] = useState<number | null>(null);\n const [dragLine, setDragLine] = useState<{\n start: { x: number; y: number };\n end: { x: number; y: number };\n questionId: number;\n } | null>(null);\n\n const containerRef = useRef<HTMLDivElement | null>(null);\n const questionRefs = useRef<Record<number, HTMLButtonElement | null>>({});\n const answerRefs = useRef<Record<number, HTMLButtonElement | null>>({});\n\n const getElementCenter = useCallback(\n (el: HTMLElement | null, isAnswer = false) => {\n if (!el || !containerRef.current) return null;\n const rect = el.getBoundingClientRect();\n const containerRect = containerRef.current.getBoundingClientRect();\n return {\n x: isAnswer\n ? rect.left - containerRect.left + circleRadius + offset\n : rect.right - containerRect.left - circleRadius - offset,\n y: rect.top + rect.height / 2 - containerRect.top,\n };\n },\n [circleRadius, offset]\n );\n\n const handleMouseDown = (qId: number) => {\n if (disabled) return;\n setDragging(qId);\n requestAnimationFrame(() => {\n const start = getElementCenter(questionRefs.current[qId]);\n if (start) setDragLine({ start, end: start, questionId: qId });\n });\n };\n\n const handleMouseMove = useCallback(\n (e: MouseEvent) => {\n if (dragging == null || !containerRef.current) return;\n const rect = containerRef.current.getBoundingClientRect();\n setDragLine((prev) =>\n prev\n ? {\n ...prev,\n end: { x: e.clientX - rect.left, y: e.clientY - rect.top },\n }\n : null\n );\n },\n [dragging]\n );\n\n const handleMouseUp = (aId: number) => {\n if (dragging != null) {\n setMatches((prev) => {\n const newMatches = { ...prev, [dragging]: aId };\n if (onChange) {\n // notify parent immediately on every change\n queueMicrotask(() =>\n onChange(\n Object.entries(newMatches).map(([qId, aId]) => ({\n questionId: Number(qId),\n answerId: aId,\n }))\n )\n );\n }\n return newMatches;\n });\n }\n setDragging(null);\n setDragLine(null);\n };\n\n const removeMatch = (qId: number) => {\n setMatches((prev) => {\n const newMatches = { ...prev };\n delete newMatches[qId];\n if (onChange) {\n queueMicrotask(() =>\n onChange(\n Object.entries(newMatches).map(([qId, aId]) => ({\n questionId: Number(qId),\n answerId: aId,\n }))\n )\n );\n }\n return newMatches;\n });\n };\n\n useEffect(() => {\n if (dragging == null) return;\n const handleUp = () => {\n setDragging(null);\n setDragLine(null);\n };\n document.addEventListener(\"mousemove\", handleMouseMove);\n document.addEventListener(\"mouseup\", handleUp);\n return () => {\n document.removeEventListener(\"mousemove\", handleMouseMove);\n document.removeEventListener(\"mouseup\", handleUp);\n };\n }, [dragging, handleMouseMove]);\n\n useEffect(() => {\n if (!containerRef.current) return;\n\n const newLines: Line[] = Object.entries(matches)\n .map(([qId, aId]) => {\n const startEl = questionRefs.current[Number(qId)];\n const endEl = answerRefs.current[Number(aId)];\n if (!startEl || !endEl) return null;\n const start = getElementCenter(startEl, false);\n const end = getElementCenter(endEl, true);\n if (!start || !end) return null;\n return { qId, aId: aId.toString(), start, end };\n })\n .filter(Boolean) as Line[];\n\n setLines(newLines);\n }, [matches, getElementCenter]);\n\n return (\n <div\n className={cn(\"grid relative grid-cols-2 gap-10 select-none\", className)}\n ref={containerRef}\n >\n <svg className=\"absolute z-20 w-full h-full pointer-events-none\">\n {lines.map(({ qId, aId, start, end }) => (\n <g key={`${qId}-${aId}`}>\n <line\n x1={start.x}\n y1={start.y}\n x2={end.x}\n y2={end.y}\n stroke={lineColor}\n strokeWidth={3}\n strokeLinecap=\"round\"\n />\n <circle\n cx={start.x}\n cy={start.y}\n r={circleRadius}\n fill={circleColor}\n />\n <circle cx={end.x} cy={end.y} r={circleRadius} fill={circleColor} />\n </g>\n ))}\n {dragLine && (\n <g>\n <line\n x1={dragLine.start.x}\n y1={dragLine.start.y}\n x2={dragLine.end.x}\n y2={dragLine.end.y}\n stroke={lineColor}\n strokeWidth={3}\n strokeDasharray=\"5,5\"\n strokeLinecap=\"round\"\n />\n <circle\n cx={dragLine.start.x}\n cy={dragLine.start.y}\n r={circleRadius}\n fill={circleColor}\n />\n <circle\n cx={dragLine.end.x}\n cy={dragLine.end.y}\n r={circleRadius}\n fill={circleColor}\n />\n </g>\n )}\n </svg>\n\n <div className=\"relative z-10 space-y-3\">\n {questions.map((q) => {\n const isMatched = matches[q.id] !== undefined;\n return (\n <button\n key={q.id}\n ref={(el) => void (questionRefs.current[q.id] = el)}\n type=\"button\"\n disabled={disabled}\n onMouseDown={() => handleMouseDown(q.id)}\n onClick={() => isMatched && removeMatch(q.id)}\n className={cn(\n \"p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500\",\n isMatched && \"bg-gray-700\",\n questionClassName\n )}\n >\n {q.text}\n </button>\n );\n })}\n </div>\n\n <div className=\"relative z-10 space-y-3\">\n {answers.map((a) => {\n const isMatched = Object.values(matches).includes(a.id);\n return (\n <button\n key={a.id}\n ref={(el) => void (answerRefs.current[a.id] = el)}\n type=\"button\"\n disabled={disabled}\n onMouseUp={() => handleMouseUp(a.id)}\n className={cn(\n \"p-4 rounded bg-black text-white w-full font-medium focus:outline-none focus:ring-2 focus:ring-gray-500\",\n isMatched && \"bg-gray-700\",\n answerClassName\n )}\n >\n {a.text}\n </button>\n );\n })}\n </div>\n </div>\n );\n}\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;;;ACAzD,SAAS,YAA6B;AACtC,SAAS,eAAe;AAEjB,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,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,CAAC,GACH;AAAA,QAEA,oBAAC,SAAI,WAAU,2BACZ,kBAAQ,IAAI,CAAC,MAAM;AAClB,gBAAM,YAAY,OAAO,OAAO,OAAO,EAAE,SAAS,EAAE,EAAE;AACtD,iBACE;AAAA,YAAC;AAAA;AAAA,cAEC,KAAK,CAAC,OAAO,MAAM,WAAW,QAAQ,EAAE,EAAE,IAAI;AAAA,cAC9C,MAAK;AAAA,cACL;AAAA,cACA,WAAW,MAAM,cAAc,EAAE,EAAE;AAAA,cACnC,WAAW;AAAA,gBACT;AAAA,gBACA,aAAa;AAAA,gBACb;AAAA,cACF;AAAA,cAEC,YAAE;AAAA;AAAA,YAXE,EAAE;AAAA,UAYT;AAAA,QAEJ,CAAC,GACH;AAAA;AAAA;AAAA,EACF;AAEJ;","names":["aId","qId"]}
1
+ {"version":3,"sources":["../src/matching.tsx","../src/lib/utils.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { cn } from \"./lib/utils\";\n\nexport type TMatch = {\n questionId: number;\n answerId: number;\n};\n\nexport type TMatchStyles = {\n lineColor?: string;\n circleColor?: string;\n questionClassName?: string;\n answerClassName?: string;\n};\n\nexport type TAutoScrollOptions = {\n edgeThreshold?: number;\n maxSpeed?: number;\n};\n\nexport type MatchingProps = {\n questions: { id: number; text: string }[];\n answers: { id: number; text: string }[];\n matches?: TMatch[];\n defaultMatches?: TMatch[];\n className?: string;\n questionClassName?: string;\n answerClassName?: string;\n lineColor?: string;\n circleColor?: string;\n circleRadius?: number;\n offset?: number;\n disabled?: boolean;\n allowAnswerReuse?: boolean;\n autoScroll?: boolean | TAutoScrollOptions;\n getMatchStyles?: (match: TMatch) => TMatchStyles | undefined;\n onChange?: (matches: TMatch[]) => void;\n};\n\ntype Point = { x: number; y: number };\n\ntype Line = TMatch & {\n start: Point;\n end: Point;\n};\n\nconst DEFAULT_EDGE_THRESHOLD = 64;\nconst DEFAULT_MAX_SCROLL_SPEED = 16;\n\nfunction toMatches(matches: Record<number, number>): TMatch[] {\n return Object.entries(matches).map(([questionId, answerId]) => ({\n questionId: Number(questionId),\n answerId,\n }));\n}\n\nfunction toMatchRecord(matches: TMatch[] | undefined): Record<number, number> {\n return (matches ?? []).reduce<Record<number, number>>((record, match) => {\n record[match.questionId] = match.answerId;\n return record;\n }, {});\n}\n\nfunction findScrollableAncestor(element: HTMLElement): HTMLElement {\n let current = element.parentElement;\n\n while (current) {\n const { overflowY } = window.getComputedStyle(current);\n if (/(auto|scroll|overlay)/.test(overflowY) && current.scrollHeight > current.clientHeight) {\n return current;\n }\n current = current.parentElement;\n }\n\n return (document.scrollingElement as HTMLElement | null) ?? document.documentElement;\n}\n\nexport function Matching({\n questions,\n answers,\n matches: controlledMatches,\n defaultMatches,\n className,\n questionClassName,\n answerClassName,\n lineColor = \"black\",\n circleColor = \"white\",\n circleRadius = 8,\n offset = 10,\n disabled,\n allowAnswerReuse = false,\n autoScroll = true,\n getMatchStyles,\n onChange,\n}: MatchingProps) {\n const [uncontrolledMatches, setUncontrolledMatches] = useState<Record<number, number>>(() =>\n toMatchRecord(defaultMatches)\n );\n const [lines, setLines] = useState<Line[]>([]);\n const [dragging, setDragging] = useState<number | null>(null);\n const [dragLine, setDragLine] = useState<{ start: Point; end: Point } | null>(null);\n\n const containerRef = useRef<HTMLDivElement | null>(null);\n const questionRefs = useRef<Record<number, HTMLButtonElement | null>>({});\n const answerRefs = useRef<Record<number, HTMLButtonElement | null>>({});\n const pointerRef = useRef<{ id: number; clientX: number; clientY: number } | null>(null);\n const scrollElementRef = useRef<HTMLElement | null>(null);\n const scrollFrameRef = useRef<number | null>(null);\n const isControlled = controlledMatches !== undefined;\n const matches = useMemo(\n () => (isControlled ? toMatchRecord(controlledMatches) : uncontrolledMatches),\n [controlledMatches, isControlled, uncontrolledMatches]\n );\n\n const setMatches = useCallback(\n (next: Record<number, number>) => {\n if (!isControlled) {\n setUncontrolledMatches(next);\n }\n queueMicrotask(() => onChange?.(toMatches(next)));\n },\n [isControlled, onChange]\n );\n\n const getElementCenter = useCallback(\n (element: HTMLElement | null, isAnswer = false) => {\n if (!element || !containerRef.current) return null;\n const rect = element.getBoundingClientRect();\n const containerRect = containerRef.current.getBoundingClientRect();\n return {\n x: isAnswer\n ? rect.left - containerRect.left + circleRadius + offset\n : rect.right - containerRect.left - circleRadius - offset,\n y: rect.top + rect.height / 2 - containerRect.top,\n };\n },\n [circleRadius, offset]\n );\n\n const refreshLines = useCallback(() => {\n const nextLines = toMatches(matches)\n .map(({ questionId, answerId }) => {\n const start = getElementCenter(questionRefs.current[questionId]);\n const end = getElementCenter(answerRefs.current[answerId], true);\n return start && end ? { questionId, answerId, start, end } : null;\n })\n .filter((line): line is Line => line !== null);\n\n setLines(nextLines);\n }, [getElementCenter, matches]);\n\n const refreshDragLine = useCallback(() => {\n if (dragging == null || !containerRef.current || !pointerRef.current) return;\n const start = getElementCenter(questionRefs.current[dragging]);\n if (!start) return;\n const rect = containerRef.current.getBoundingClientRect();\n setDragLine({\n start,\n end: {\n x: pointerRef.current.clientX - rect.left,\n y: pointerRef.current.clientY - rect.top,\n },\n });\n }, [dragging, getElementCenter]);\n\n const stopAutoScroll = useCallback(() => {\n if (scrollFrameRef.current !== null) cancelAnimationFrame(scrollFrameRef.current);\n scrollFrameRef.current = null;\n scrollElementRef.current = null;\n }, []);\n\n const runAutoScroll = useCallback(() => {\n scrollFrameRef.current = null;\n if (autoScroll === false || dragging == null || !pointerRef.current) return;\n\n const scrollElement = scrollElementRef.current;\n if (!scrollElement) return;\n\n const isDocument = scrollElement === document.scrollingElement;\n const rect = isDocument\n ? { top: 0, bottom: window.innerHeight }\n : scrollElement.getBoundingClientRect();\n const edgeThreshold =\n typeof autoScroll === \"object\"\n ? (autoScroll.edgeThreshold ?? DEFAULT_EDGE_THRESHOLD)\n : DEFAULT_EDGE_THRESHOLD;\n const maxSpeed =\n typeof autoScroll === \"object\"\n ? (autoScroll.maxSpeed ?? DEFAULT_MAX_SCROLL_SPEED)\n : DEFAULT_MAX_SCROLL_SPEED;\n const { clientY } = pointerRef.current;\n let speed = 0;\n\n if (clientY < rect.top + edgeThreshold) {\n speed = -maxSpeed * (1 - Math.max(0, clientY - rect.top) / edgeThreshold);\n } else if (clientY > rect.bottom - edgeThreshold) {\n speed = maxSpeed * (1 - Math.max(0, rect.bottom - clientY) / edgeThreshold);\n }\n\n if (speed !== 0) {\n const previousScrollTop = scrollElement.scrollTop;\n scrollElement.scrollTop += speed;\n if (scrollElement.scrollTop !== previousScrollTop) {\n refreshLines();\n refreshDragLine();\n }\n }\n\n scrollFrameRef.current = requestAnimationFrame(runAutoScroll);\n }, [autoScroll, dragging, refreshDragLine, refreshLines]);\n\n const cancelDragging = useCallback(() => {\n setDragging(null);\n setDragLine(null);\n pointerRef.current = null;\n stopAutoScroll();\n }, [stopAutoScroll]);\n\n const handlePointerDown = (event: React.PointerEvent, questionId: number) => {\n if (disabled || !containerRef.current) return;\n event.preventDefault();\n pointerRef.current = { id: event.pointerId, clientX: event.clientX, clientY: event.clientY };\n scrollElementRef.current = findScrollableAncestor(containerRef.current);\n setDragging(questionId);\n };\n\n const handlePointerMove = useCallback(\n (event: PointerEvent) => {\n if (dragging == null || pointerRef.current?.id !== event.pointerId) return;\n pointerRef.current = { id: event.pointerId, clientX: event.clientX, clientY: event.clientY };\n refreshDragLine();\n },\n [dragging, refreshDragLine]\n );\n\n const handlePointerUp = (event: React.PointerEvent, answerId: number) => {\n if (dragging != null && pointerRef.current?.id === event.pointerId) {\n const next = { ...matches };\n if (!allowAnswerReuse) {\n for (const [questionId, matchedAnswerId] of Object.entries(next)) {\n if (matchedAnswerId === answerId) delete next[Number(questionId)];\n }\n }\n next[dragging] = answerId;\n setMatches(next);\n }\n cancelDragging();\n };\n\n const removeMatch = (questionId: number) => {\n const next = { ...matches };\n delete next[questionId];\n setMatches(next);\n };\n\n useEffect(() => {\n if (dragging == null) return;\n refreshDragLine();\n if (autoScroll !== false && scrollFrameRef.current === null) {\n scrollFrameRef.current = requestAnimationFrame(runAutoScroll);\n }\n\n const handleUp = (event: PointerEvent) => {\n if (pointerRef.current?.id === event.pointerId) cancelDragging();\n };\n document.addEventListener(\"pointermove\", handlePointerMove);\n document.addEventListener(\"pointerup\", handleUp);\n document.addEventListener(\"pointercancel\", handleUp);\n return () => {\n document.removeEventListener(\"pointermove\", handlePointerMove);\n document.removeEventListener(\"pointerup\", handleUp);\n document.removeEventListener(\"pointercancel\", handleUp);\n stopAutoScroll();\n };\n }, [\n autoScroll,\n cancelDragging,\n dragging,\n handlePointerMove,\n refreshDragLine,\n runAutoScroll,\n stopAutoScroll,\n ]);\n\n useEffect(() => {\n refreshLines();\n }, [refreshLines]);\n\n useEffect(() => {\n window.addEventListener(\"resize\", refreshLines);\n return () => window.removeEventListener(\"resize\", refreshLines);\n }, [refreshLines]);\n\n return (\n <div\n className={cn(\"grid relative grid-cols-2 gap-10 select-none\", className)}\n ref={containerRef}\n >\n <svg className=\"absolute z-20 w-full h-full pointer-events-none\">\n {lines.map((line) => {\n const styles = getMatchStyles?.(line);\n return (\n <g key={`${line.questionId}-${line.answerId}`}>\n <line\n x1={line.start.x}\n y1={line.start.y}\n x2={line.end.x}\n y2={line.end.y}\n stroke={styles?.lineColor ?? lineColor}\n strokeWidth={3}\n strokeLinecap=\"round\"\n />\n <circle\n cx={line.start.x}\n cy={line.start.y}\n r={circleRadius}\n fill={styles?.circleColor ?? circleColor}\n />\n <circle\n cx={line.end.x}\n cy={line.end.y}\n r={circleRadius}\n fill={styles?.circleColor ?? circleColor}\n />\n </g>\n );\n })}\n {dragLine && (\n <g>\n <line\n x1={dragLine.start.x}\n y1={dragLine.start.y}\n x2={dragLine.end.x}\n y2={dragLine.end.y}\n stroke={lineColor}\n strokeWidth={3}\n strokeDasharray=\"5,5\"\n strokeLinecap=\"round\"\n />\n <circle cx={dragLine.start.x} cy={dragLine.start.y} r={circleRadius} fill={circleColor} />\n <circle cx={dragLine.end.x} cy={dragLine.end.y} r={circleRadius} fill={circleColor} />\n </g>\n )}\n </svg>\n\n <div className=\"relative z-10 space-y-3\">\n {questions.map((question) => {\n const answerId = matches[question.id];\n const styles =\n answerId === undefined\n ? undefined\n : getMatchStyles?.({ questionId: question.id, answerId });\n return (\n <button\n key={question.id}\n ref={(element) => void (questionRefs.current[question.id] = element)}\n type=\"button\"\n disabled={disabled}\n onPointerDown={(event) => handlePointerDown(event, question.id)}\n onClick={() => answerId !== undefined && removeMatch(question.id)}\n className={cn(\n \"p-4 rounded bg-black text-white w-full touch-none font-medium focus:outline-none focus:ring-2 focus:ring-gray-500\",\n answerId !== undefined && \"bg-gray-700\",\n questionClassName,\n styles?.questionClassName\n )}\n >\n {question.text}\n </button>\n );\n })}\n </div>\n\n <div className=\"relative z-10 space-y-3\">\n {answers.map((answer) => {\n const answerMatches = toMatches(matches).filter((match) => match.answerId === answer.id);\n return (\n <button\n key={answer.id}\n ref={(element) => void (answerRefs.current[answer.id] = element)}\n type=\"button\"\n disabled={disabled}\n onPointerUp={(event) => handlePointerUp(event, answer.id)}\n className={cn(\n \"p-4 rounded bg-black text-white w-full touch-none font-medium focus:outline-none focus:ring-2 focus:ring-gray-500\",\n answerMatches.length > 0 && \"bg-gray-700\",\n answerClassName,\n answerMatches.map((match) => getMatchStyles?.(match)?.answerClassName)\n )}\n >\n {answer.text}\n </button>\n );\n })}\n </div>\n </div>\n );\n}\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n"],"mappings":";AAAA,SAAS,aAAa,WAAW,SAAS,QAAQ,gBAAgB;;;ACAlE,SAAS,YAA6B;AACtC,SAAS,eAAe;AAEjB,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;;;ADySY,SACE,KADF;AAhQZ,IAAM,yBAAyB;AAC/B,IAAM,2BAA2B;AAEjC,SAAS,UAAU,SAA2C;AAC5D,SAAO,OAAO,Q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AAC;AAAA;AAAA,cAEC,KAAK,CAAC,YAAY,MAAM,aAAa,QAAQ,SAAS,EAAE,IAAI;AAAA,cAC5D,MAAK;AAAA,cACL;AAAA,cACA,eAAe,CAAC,UAAU,kBAAkB,OAAO,SAAS,EAAE;AAAA,cAC9D,SAAS,MAAM,aAAa,UAAa,YAAY,SAAS,EAAE;AAAA,cAChE,WAAW;AAAA,gBACT;AAAA,gBACA,aAAa,UAAa;AAAA,gBAC1B;AAAA,gBACA,QAAQ;AAAA,cACV;AAAA,cAEC,mBAAS;AAAA;AAAA,YAbL,SAAS;AAAA,UAchB;AAAA,QAEJ,CAAC,GACH;AAAA,QAEA,oBAAC,SAAI,WAAU,2BACZ,kBAAQ,IAAI,CAAC,WAAW;AACvB,gBAAM,gBAAgB,UAAU,OAAO,EAAE,OAAO,CAAC,UAAU,MAAM,aAAa,OAAO,EAAE;AACvF,iBACE;AAAA,YAAC;AAAA;AAAA,cAEC,KAAK,CAAC,YAAY,MAAM,WAAW,QAAQ,OAAO,EAAE,IAAI;AAAA,cACxD,MAAK;AAAA,cACL;AAAA,cACA,aAAa,CAAC,UAAU,gBAAgB,OAAO,OAAO,EAAE;AAAA,cACxD,WAAW;AAAA,gBACT;AAAA,gBACA,cAAc,SAAS,KAAK;AAAA,gBAC5B;AAAA,gBACA,cAAc,IAAI,CAAC,UAAU,iBAAiB,KAAK,GAAG,eAAe;AAAA,cACvE;AAAA,cAEC,iBAAO;AAAA;AAAA,YAZH,OAAO;AAAA,UAad;AAAA,QAEJ,CAAC,GACH;AAAA;AAAA;AAAA,EACF;AAEJ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-matchings",
3
- "version": "0.0.8",
3
+ "version": "0.1.1",
4
4
  "description": "A React component for matching questions and answers",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",