@nextclaw/agent-chat-ui 0.3.8 → 0.3.9

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.
Files changed (2) hide show
  1. package/dist/index.js +18 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1216,8 +1216,8 @@ function readChatComposerSnapshotFromEditorState(editorState) {
1216
1216
  return {
1217
1217
  nodes,
1218
1218
  selection: {
1219
- start: getOffsetFromPoint(selection.anchor),
1220
- end: getOffsetFromPoint(selection.focus)
1219
+ start: Math.min(getOffsetFromPoint(selection.anchor), getOffsetFromPoint(selection.focus)),
1220
+ end: Math.max(getOffsetFromPoint(selection.anchor), getOffsetFromPoint(selection.focus))
1221
1221
  }
1222
1222
  };
1223
1223
  });
@@ -1275,9 +1275,10 @@ function getDocumentLength(nodes) {
1275
1275
  function insertToken(params) {
1276
1276
  const { label, nodes, selection, tokenKey, tokenKind, trigger } = params;
1277
1277
  const documentLength = getDocumentLength(nodes);
1278
- const replaceStart = trigger?.start ?? selection?.start ?? documentLength;
1278
+ const [selectionStart, selectionEnd] = selection ? [Math.min(selection.start, selection.end), Math.max(selection.start, selection.end)] : [documentLength, documentLength];
1279
+ const replaceStart = trigger?.start ?? selectionStart;
1279
1280
  return {
1280
- nodes: replaceChatComposerRange(nodes, replaceStart, trigger?.end ?? selection?.end ?? replaceStart, [createChatComposerTokenNode({
1281
+ nodes: replaceChatComposerRange(nodes, replaceStart, trigger?.end ?? selectionEnd, [createChatComposerTokenNode({
1281
1282
  label,
1282
1283
  tokenKey,
1283
1284
  tokenKind
@@ -1293,13 +1294,11 @@ function getChatComposerNodesSignature(nodes) {
1293
1294
  }
1294
1295
  function replaceChatComposerSelectionWithText(params) {
1295
1296
  const { nodes, selection, text } = params;
1296
- const currentSelection = selection ?? {
1297
- start: getDocumentLength(nodes),
1298
- end: getDocumentLength(nodes)
1299
- };
1300
- const nextOffset = currentSelection.start + text.length;
1297
+ const documentLength = getDocumentLength(nodes);
1298
+ const [selectionStart, selectionEnd] = selection ? [Math.min(selection.start, selection.end), Math.max(selection.start, selection.end)] : [documentLength, documentLength];
1299
+ const nextOffset = selectionStart + text.length;
1301
1300
  return {
1302
- nodes: replaceChatComposerRange(nodes, currentSelection.start, currentSelection.end, [createChatComposerTextNode(text)]),
1301
+ nodes: replaceChatComposerRange(nodes, selectionStart, selectionEnd, [createChatComposerTextNode(text)]),
1303
1302
  selection: {
1304
1303
  start: nextOffset,
1305
1304
  end: nextOffset
@@ -1355,17 +1354,17 @@ function syncSelectedSkillsIntoChatComposer(params) {
1355
1354
  function deleteChatComposerContent(params) {
1356
1355
  const { direction, nodes, selection: currentSelection } = params;
1357
1356
  const documentLength = getDocumentLength(nodes);
1358
- const selection = currentSelection ?? {
1359
- start: documentLength,
1360
- end: documentLength
1361
- };
1362
- let rangeStart = selection.start;
1363
- let rangeEnd = selection.end;
1364
- if (selection.start === selection.end) if (direction === "backward" && selection.start > 0) rangeStart = selection.start - 1;
1365
- else if (direction === "forward" && selection.end < documentLength) rangeEnd = selection.end + 1;
1357
+ const [selectionStart, selectionEnd] = currentSelection ? [Math.min(currentSelection.start, currentSelection.end), Math.max(currentSelection.start, currentSelection.end)] : [documentLength, documentLength];
1358
+ let rangeStart = selectionStart;
1359
+ let rangeEnd = selectionEnd;
1360
+ if (rangeStart === rangeEnd) if (direction === "backward" && rangeStart > 0) rangeStart -= 1;
1361
+ else if (direction === "forward" && rangeEnd < documentLength) rangeEnd += 1;
1366
1362
  else return {
1367
1363
  nodes: normalizeChatComposerNodes(nodes),
1368
- selection
1364
+ selection: {
1365
+ start: rangeStart,
1366
+ end: rangeEnd
1367
+ }
1369
1368
  };
1370
1369
  return {
1371
1370
  nodes: replaceChatComposerRange(nodes, rangeStart, rangeEnd, []),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/agent-chat-ui",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "private": false,
5
5
  "description": "Reusable Nextclaw agent chat UI primitives and default skin.",
6
6
  "type": "module",