@ai-matrx/design-system 0.35.0 → 0.36.0

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.
@@ -138,6 +138,11 @@ interface SpreadsheetCellProps {
138
138
  preventDefault: () => void;
139
139
  /** The cell element, used to give the grid keyboard focus. */
140
140
  currentTarget?: unknown;
141
+ /**
142
+ * What was actually pressed. A press inside an overlay this cell portalled out
143
+ * of the table is NOT a press on the cell — see `camePastAPortal`.
144
+ */
145
+ target?: unknown;
141
146
  }) => void;
142
147
  onMouseEnter: () => void;
143
148
  }
@@ -138,6 +138,11 @@ interface SpreadsheetCellProps {
138
138
  preventDefault: () => void;
139
139
  /** The cell element, used to give the grid keyboard focus. */
140
140
  currentTarget?: unknown;
141
+ /**
142
+ * What was actually pressed. A press inside an overlay this cell portalled out
143
+ * of the table is NOT a press on the cell — see `camePastAPortal`.
144
+ */
145
+ target?: unknown;
141
146
  }) => void;
142
147
  onMouseEnter: () => void;
143
148
  }
@@ -610,6 +610,19 @@ function targetsAnEditor(target) {
610
610
  if (!element) return false;
611
611
  return element.closest("input, textarea, select, [contenteditable='true']") !== null;
612
612
  }
613
+ function camePastAPortal(target, host) {
614
+ if (typeof Element === "undefined") return false;
615
+ const element = target instanceof Element ? target : null;
616
+ const owner = host instanceof Element ? host : null;
617
+ if (!element || !owner) return false;
618
+ return !owner.contains(element);
619
+ }
620
+ function camePastAPortalIntoTheContainer(target) {
621
+ if (typeof Element === "undefined") return false;
622
+ const element = target instanceof Element ? target : null;
623
+ if (!element) return false;
624
+ return element.closest('[data-matrx-table-spreadsheet="true"]') === null;
625
+ }
613
626
  var NOTHING = [];
614
627
  function useSpreadsheetGrid(options) {
615
628
  const [range, setRange] = useState(null);
@@ -782,6 +795,7 @@ function useSpreadsheetGrid(options) {
782
795
  const current = optionsRef.current;
783
796
  if (!current) return;
784
797
  if (targetsAnEditor(event.target)) return;
798
+ if (camePastAPortalIntoTheContainer(event.target)) return;
785
799
  const accel = event.metaKey || event.ctrlKey;
786
800
  if (accel && (event.key === "z" || event.key === "Z")) {
787
801
  event.preventDefault();
@@ -868,6 +882,7 @@ function useSpreadsheetGrid(options) {
868
882
  const onCopy = useCallback(
869
883
  (event) => {
870
884
  if (!optionsRef.current || !range || targetsAnEditor(event.target)) return;
885
+ if (camePastAPortalIntoTheContainer(event.target)) return;
871
886
  const text = selectionAsTsv();
872
887
  if (!text) return;
873
888
  event.preventDefault();
@@ -878,6 +893,7 @@ function useSpreadsheetGrid(options) {
878
893
  const onCut = useCallback(
879
894
  (event) => {
880
895
  if (!optionsRef.current || !range || targetsAnEditor(event.target)) return;
896
+ if (camePastAPortalIntoTheContainer(event.target)) return;
881
897
  const text = selectionAsTsv();
882
898
  if (!text) return;
883
899
  event.preventDefault();
@@ -890,6 +906,7 @@ function useSpreadsheetGrid(options) {
890
906
  (event) => {
891
907
  const current = optionsRef.current;
892
908
  if (!current || current.paste === false || !range || targetsAnEditor(event.target)) return;
909
+ if (camePastAPortalIntoTheContainer(event.target)) return;
893
910
  const text = event.clipboardData?.getData("text/plain") ?? "";
894
911
  if (!text) return;
895
912
  event.preventDefault();
@@ -973,6 +990,7 @@ function useSpreadsheetGrid(options) {
973
990
  ...inFillPreview ? { "data-matrx-cell-fill-preview": "true" } : {},
974
991
  onMouseDown: (event) => {
975
992
  if (event.button !== 0) return;
993
+ if (camePastAPortal(event.target ?? null, event.currentTarget)) return;
976
994
  event.preventDefault();
977
995
  const origin = event.currentTarget;
978
996
  if (typeof HTMLElement !== "undefined" && origin instanceof HTMLElement) {