@lensui/lens-table 0.1.95 → 0.1.96

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.cjs CHANGED
@@ -968,6 +968,8 @@ function TextAreaEditor({
968
968
  const [open, setOpen] = (0, import_react6.useState)(false);
969
969
  const inputRef = (0, import_react6.useRef)(null);
970
970
  const textareaRef = (0, import_react6.useRef)(null);
971
+ const lastLineStart = inline ? Math.max(value.lastIndexOf("\n"), value.lastIndexOf("\r")) + 1 : 0;
972
+ const collapsedValue = inline ? value.slice(lastLineStart) : value;
971
973
  const selectionRef = (0, import_react6.useRef)(null);
972
974
  const inlineHeaderHeight = typeof style.height === "number" ? style.height : 34;
973
975
  const editorStyle = inline && open ? {
@@ -980,12 +982,12 @@ function TextAreaEditor({
980
982
  if (event.key === "Enter") onCommit(value);
981
983
  if (event.key === "Escape") onCancel();
982
984
  };
983
- const rememberSelection = (control) => {
985
+ const rememberSelection = (control, offset = 0) => {
984
986
  if (!control || control.selectionStart === null || control.selectionEnd === null)
985
987
  return;
986
988
  selectionRef.current = {
987
- start: control.selectionStart,
988
- end: control.selectionEnd,
989
+ start: control.selectionStart + offset,
990
+ end: control.selectionEnd + offset,
989
991
  direction: control.selectionDirection ?? "none"
990
992
  };
991
993
  };
@@ -995,27 +997,31 @@ function TextAreaEditor({
995
997
  if (!control) return;
996
998
  const selection = selectionRef.current;
997
999
  const length = control.value.length;
1000
+ const offset = open ? 0 : lastLineStart;
998
1001
  control.focus();
999
1002
  control.setSelectionRange(
1000
- Math.min(selection.start, length),
1001
- Math.min(selection.end, length),
1003
+ Math.max(0, Math.min(selection.start - offset, length)),
1004
+ Math.max(0, Math.min(selection.end - offset, length)),
1002
1005
  selection.direction
1003
1006
  );
1004
- }, [inline, open]);
1007
+ }, [inline, lastLineStart, open]);
1005
1008
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1006
1009
  "div",
1007
1010
  {
1008
1011
  className: `rvg-native-editor rvg-textarea-editor${inline && open ? " is-inline-expanded" : ""}`,
1009
1012
  style: editorStyle,
1010
1013
  children: [
1014
+ inline && !open && lastLineStart > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "rvg-textarea-collapsed-prefix", "aria-hidden": "true", children: "\u21B5" }),
1011
1015
  !(inline && open) && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1012
1016
  "input",
1013
1017
  {
1014
1018
  ref: inputRef,
1015
- value,
1019
+ value: collapsedValue,
1016
1020
  autoFocus: true,
1017
1021
  maxLength,
1018
- onChange: (event) => onChange(event.target.value),
1022
+ onChange: (event) => onChange(
1023
+ inline ? `${value.slice(0, lastLineStart)}${event.target.value}` : event.target.value
1024
+ ),
1019
1025
  onKeyDown: handleKeyDown
1020
1026
  }
1021
1027
  ),
@@ -1039,7 +1045,7 @@ function TextAreaEditor({
1039
1045
  textareaRef.current?.focus();
1040
1046
  return;
1041
1047
  }
1042
- rememberSelection(inputRef.current);
1048
+ rememberSelection(inputRef.current, lastLineStart);
1043
1049
  setOpen(true);
1044
1050
  },
1045
1051
  children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MultilineEditorIcon, {})
package/dist/index.js CHANGED
@@ -942,6 +942,8 @@ function TextAreaEditor({
942
942
  const [open, setOpen] = useState4(false);
943
943
  const inputRef = useRef4(null);
944
944
  const textareaRef = useRef4(null);
945
+ const lastLineStart = inline ? Math.max(value.lastIndexOf("\n"), value.lastIndexOf("\r")) + 1 : 0;
946
+ const collapsedValue = inline ? value.slice(lastLineStart) : value;
945
947
  const selectionRef = useRef4(null);
946
948
  const inlineHeaderHeight = typeof style.height === "number" ? style.height : 34;
947
949
  const editorStyle = inline && open ? {
@@ -954,12 +956,12 @@ function TextAreaEditor({
954
956
  if (event.key === "Enter") onCommit(value);
955
957
  if (event.key === "Escape") onCancel();
956
958
  };
957
- const rememberSelection = (control) => {
959
+ const rememberSelection = (control, offset = 0) => {
958
960
  if (!control || control.selectionStart === null || control.selectionEnd === null)
959
961
  return;
960
962
  selectionRef.current = {
961
- start: control.selectionStart,
962
- end: control.selectionEnd,
963
+ start: control.selectionStart + offset,
964
+ end: control.selectionEnd + offset,
963
965
  direction: control.selectionDirection ?? "none"
964
966
  };
965
967
  };
@@ -969,27 +971,31 @@ function TextAreaEditor({
969
971
  if (!control) return;
970
972
  const selection = selectionRef.current;
971
973
  const length = control.value.length;
974
+ const offset = open ? 0 : lastLineStart;
972
975
  control.focus();
973
976
  control.setSelectionRange(
974
- Math.min(selection.start, length),
975
- Math.min(selection.end, length),
977
+ Math.max(0, Math.min(selection.start - offset, length)),
978
+ Math.max(0, Math.min(selection.end - offset, length)),
976
979
  selection.direction
977
980
  );
978
- }, [inline, open]);
981
+ }, [inline, lastLineStart, open]);
979
982
  return /* @__PURE__ */ jsxs7(
980
983
  "div",
981
984
  {
982
985
  className: `rvg-native-editor rvg-textarea-editor${inline && open ? " is-inline-expanded" : ""}`,
983
986
  style: editorStyle,
984
987
  children: [
988
+ inline && !open && lastLineStart > 0 && /* @__PURE__ */ jsx7("span", { className: "rvg-textarea-collapsed-prefix", "aria-hidden": "true", children: "\u21B5" }),
985
989
  !(inline && open) && /* @__PURE__ */ jsx7(
986
990
  "input",
987
991
  {
988
992
  ref: inputRef,
989
- value,
993
+ value: collapsedValue,
990
994
  autoFocus: true,
991
995
  maxLength,
992
- onChange: (event) => onChange(event.target.value),
996
+ onChange: (event) => onChange(
997
+ inline ? `${value.slice(0, lastLineStart)}${event.target.value}` : event.target.value
998
+ ),
993
999
  onKeyDown: handleKeyDown
994
1000
  }
995
1001
  ),
@@ -1013,7 +1019,7 @@ function TextAreaEditor({
1013
1019
  textareaRef.current?.focus();
1014
1020
  return;
1015
1021
  }
1016
- rememberSelection(inputRef.current);
1022
+ rememberSelection(inputRef.current, lastLineStart);
1017
1023
  setOpen(true);
1018
1024
  },
1019
1025
  children: /* @__PURE__ */ jsx7(MultilineEditorIcon, {})
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lensui/lens-table",
3
- "version": "0.1.95",
3
+ "version": "0.1.96",
4
4
  "description": "A lightweight, canvas-rendered React table component for LensUI.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",