@lvce-editor/chat-view 1.1.0 → 1.3.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.
- package/dist/chatViewWorkerMain.js +148 -132
- package/package.json +1 -1
|
@@ -983,6 +983,7 @@ const TargetValue = 'event.target.value';
|
|
|
983
983
|
const ExtensionHostWorker = 44;
|
|
984
984
|
const RendererWorker = 1;
|
|
985
985
|
|
|
986
|
+
const SetCss = 'Viewlet.setCss';
|
|
986
987
|
const SetDom2 = 'Viewlet.setDom2';
|
|
987
988
|
const SetPatches = 'Viewlet.setPatches';
|
|
988
989
|
|
|
@@ -1059,6 +1060,7 @@ const {
|
|
|
1059
1060
|
} = create$2(ExtensionHostWorker);
|
|
1060
1061
|
|
|
1061
1062
|
const {
|
|
1063
|
+
invoke,
|
|
1062
1064
|
invokeAndTransfer,
|
|
1063
1065
|
set: set$1
|
|
1064
1066
|
} = create$2(RendererWorker);
|
|
@@ -1206,8 +1208,6 @@ const createDefaultState = () => {
|
|
|
1206
1208
|
messages: [],
|
|
1207
1209
|
title: 'Chat 1'
|
|
1208
1210
|
}],
|
|
1209
|
-
statusBarItemsLeft: [],
|
|
1210
|
-
statusBarItemsRight: [],
|
|
1211
1211
|
uid: 0,
|
|
1212
1212
|
warningCount: 0
|
|
1213
1213
|
};
|
|
@@ -1232,15 +1232,20 @@ const create = (uid, uri, x, y, width, height, platform, assetDir) => {
|
|
|
1232
1232
|
set(uid, state, state);
|
|
1233
1233
|
};
|
|
1234
1234
|
|
|
1235
|
+
const isEqual$1 = (oldState, newState) => {
|
|
1236
|
+
return oldState.initial === newState.initial;
|
|
1237
|
+
};
|
|
1238
|
+
|
|
1235
1239
|
const isEqual = (oldState, newState) => {
|
|
1236
1240
|
return oldState.composerValue === newState.composerValue && oldState.ignoreNextInput === newState.ignoreNextInput && oldState.initial === newState.initial && oldState.renamingSessionId === newState.renamingSessionId && oldState.selectedSessionId === newState.selectedSessionId && oldState.sessions === newState.sessions;
|
|
1237
1241
|
};
|
|
1238
1242
|
|
|
1239
1243
|
const RenderItems = 4;
|
|
1244
|
+
const RenderCss = 10;
|
|
1240
1245
|
const RenderIncremental = 11;
|
|
1241
1246
|
|
|
1242
|
-
const modules = [isEqual];
|
|
1243
|
-
const numbers = [RenderIncremental];
|
|
1247
|
+
const modules = [isEqual, isEqual$1];
|
|
1248
|
+
const numbers = [RenderIncremental, RenderCss];
|
|
1244
1249
|
|
|
1245
1250
|
const diff = (oldState, newState) => {
|
|
1246
1251
|
const diffResult = [];
|
|
@@ -1262,6 +1267,10 @@ const diff2 = uid => {
|
|
|
1262
1267
|
return result;
|
|
1263
1268
|
};
|
|
1264
1269
|
|
|
1270
|
+
const getKeyBindings = () => {
|
|
1271
|
+
return [];
|
|
1272
|
+
};
|
|
1273
|
+
|
|
1265
1274
|
const CREATE_SESSION = 'create-session';
|
|
1266
1275
|
const SESSION_PREFIX = 'session:';
|
|
1267
1276
|
const RENAME_PREFIX = 'session-rename:';
|
|
@@ -1364,6 +1373,11 @@ const handleClick = async (state, name) => {
|
|
|
1364
1373
|
return state;
|
|
1365
1374
|
};
|
|
1366
1375
|
|
|
1376
|
+
const handleClickClose = async () => {
|
|
1377
|
+
// @ts-ignore
|
|
1378
|
+
await invoke('Chat.terminate');
|
|
1379
|
+
};
|
|
1380
|
+
|
|
1367
1381
|
const handleInput = async (state, value) => {
|
|
1368
1382
|
if (state.ignoreNextInput) {
|
|
1369
1383
|
return {
|
|
@@ -1476,51 +1490,6 @@ const initialize = async () => {
|
|
|
1476
1490
|
set$2(rpc);
|
|
1477
1491
|
};
|
|
1478
1492
|
|
|
1479
|
-
const getIndex = (items, item) => {
|
|
1480
|
-
for (let i = 0; i < items.length; i++) {
|
|
1481
|
-
if (items[i].name === item.name) {
|
|
1482
|
-
return i;
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
return -1;
|
|
1486
|
-
};
|
|
1487
|
-
|
|
1488
|
-
const updateArray = (items, newItem) => {
|
|
1489
|
-
const index = getIndex(items, newItem);
|
|
1490
|
-
const before = items.slice(0, index);
|
|
1491
|
-
const after = items.slice(index + 1);
|
|
1492
|
-
return [...before, newItem, ...after];
|
|
1493
|
-
};
|
|
1494
|
-
|
|
1495
|
-
const itemLeftUpdate = (state, newItem) => {
|
|
1496
|
-
return {
|
|
1497
|
-
...state,
|
|
1498
|
-
statusBarItemsLeft: updateArray([...state.statusBarItemsLeft], newItem)
|
|
1499
|
-
};
|
|
1500
|
-
};
|
|
1501
|
-
|
|
1502
|
-
const itemRightCreate = (state, newItem) => {
|
|
1503
|
-
const {
|
|
1504
|
-
statusBarItemsRight
|
|
1505
|
-
} = state;
|
|
1506
|
-
const newStatusBarItemsRight = [...statusBarItemsRight, newItem];
|
|
1507
|
-
return {
|
|
1508
|
-
...state,
|
|
1509
|
-
statusBarItemsRight: newStatusBarItemsRight
|
|
1510
|
-
};
|
|
1511
|
-
};
|
|
1512
|
-
|
|
1513
|
-
const itemRightUpdate = (state, newItem) => {
|
|
1514
|
-
const {
|
|
1515
|
-
statusBarItemsRight
|
|
1516
|
-
} = state;
|
|
1517
|
-
const newStatusBarItemsRight = updateArray([...statusBarItemsRight], newItem);
|
|
1518
|
-
return {
|
|
1519
|
-
...state,
|
|
1520
|
-
statusBarItemsRight: newStatusBarItemsRight
|
|
1521
|
-
};
|
|
1522
|
-
};
|
|
1523
|
-
|
|
1524
1493
|
const ensureSessions = state => {
|
|
1525
1494
|
if (state.sessions.length > 0) {
|
|
1526
1495
|
return state.sessions;
|
|
@@ -1544,6 +1513,46 @@ const loadContent = async state => {
|
|
|
1544
1513
|
};
|
|
1545
1514
|
};
|
|
1546
1515
|
|
|
1516
|
+
const css = `.Chat {
|
|
1517
|
+
display: grid;
|
|
1518
|
+
grid-template-columns: 220px 1fr;
|
|
1519
|
+
grid-template-rows: auto 1fr auto;
|
|
1520
|
+
height: 100%;
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
.ChatHeader {
|
|
1524
|
+
align-items: center;
|
|
1525
|
+
display: flex;
|
|
1526
|
+
gap: 8px;
|
|
1527
|
+
justify-content: space-between;
|
|
1528
|
+
padding: 8px;
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
.ChatList {
|
|
1532
|
+
border-right: 1px solid var(--Widget-border);
|
|
1533
|
+
overflow: auto;
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
.ChatDetails {
|
|
1537
|
+
display: flex;
|
|
1538
|
+
flex-direction: column;
|
|
1539
|
+
min-height: 0;
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
.ChatDetailsContent {
|
|
1543
|
+
flex: 1;
|
|
1544
|
+
overflow: auto;
|
|
1545
|
+
padding: 8px;
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
.MultilineInputBox {
|
|
1549
|
+
width: 100%;
|
|
1550
|
+
}
|
|
1551
|
+
`;
|
|
1552
|
+
const renderCss = (oldState, newState) => {
|
|
1553
|
+
return [SetCss, newState.uid, css];
|
|
1554
|
+
};
|
|
1555
|
+
|
|
1547
1556
|
const text = data => {
|
|
1548
1557
|
return {
|
|
1549
1558
|
childCount: 0,
|
|
@@ -1840,67 +1849,81 @@ const diffTree = (oldNodes, newNodes) => {
|
|
|
1840
1849
|
return removeTrailingNavigationPatches(patches);
|
|
1841
1850
|
};
|
|
1842
1851
|
|
|
1843
|
-
const
|
|
1844
|
-
const
|
|
1845
|
-
const SideBarLocation = 'SideBarLocation';
|
|
1852
|
+
const ChatActions = 'ChatActions';
|
|
1853
|
+
const ChatHeader = 'ChatHeader';
|
|
1846
1854
|
const Button = 'Button';
|
|
1847
|
-
const
|
|
1848
|
-
const
|
|
1855
|
+
const ChatDetails = 'ChatDetails';
|
|
1856
|
+
const ChatDetailsContent = 'ChatDetailsContent';
|
|
1849
1857
|
const IconButton = 'IconButton';
|
|
1850
1858
|
const Label = 'Label';
|
|
1851
|
-
const
|
|
1852
|
-
const ListItems = 'ListItems';
|
|
1859
|
+
const ChatList = 'ChatList';
|
|
1853
1860
|
const Markdown = 'Markdown';
|
|
1854
1861
|
const Message = 'Message';
|
|
1855
1862
|
const MultilineInputBox = 'MultilineInputBox';
|
|
1856
1863
|
const Viewlet = 'Viewlet';
|
|
1857
|
-
const
|
|
1864
|
+
const ChatWelcomeMessage = 'ChatWelcomeMessage';
|
|
1858
1865
|
|
|
1859
1866
|
const HandleInput = 4;
|
|
1860
1867
|
const HandleClick = 11;
|
|
1861
1868
|
const HandleKeyDown = 12;
|
|
1862
1869
|
|
|
1863
|
-
const
|
|
1864
|
-
const selected = session.id === selectedSessionId;
|
|
1865
|
-
const sessionClassName = selected ? `${List} ${TestActive}` : List;
|
|
1870
|
+
const getChatDetailsDom = (messagesNodes, composerValue) => {
|
|
1866
1871
|
return [{
|
|
1867
1872
|
childCount: 2,
|
|
1868
|
-
className:
|
|
1873
|
+
className: ChatDetails,
|
|
1869
1874
|
type: Div
|
|
1870
1875
|
}, {
|
|
1876
|
+
childCount: Math.max(messagesNodes.length, 0),
|
|
1877
|
+
className: ChatDetailsContent,
|
|
1878
|
+
type: Div
|
|
1879
|
+
}, ...messagesNodes, {
|
|
1871
1880
|
childCount: 1,
|
|
1872
|
-
className:
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1881
|
+
className: ChatActions,
|
|
1882
|
+
type: Div
|
|
1883
|
+
}, {
|
|
1884
|
+
childCount: 0,
|
|
1885
|
+
className: MultilineInputBox,
|
|
1886
|
+
name: 'composer',
|
|
1887
|
+
placeholder: 'Type your message. Enter to send, Shift+Enter for newline.',
|
|
1888
|
+
rows: 4,
|
|
1889
|
+
type: TextArea,
|
|
1890
|
+
value: composerValue
|
|
1891
|
+
}];
|
|
1892
|
+
};
|
|
1893
|
+
|
|
1894
|
+
const getChatHeaderDom = sessionsLength => {
|
|
1895
|
+
return [{
|
|
1878
1896
|
childCount: 2,
|
|
1879
|
-
className:
|
|
1897
|
+
className: ChatHeader,
|
|
1898
|
+
type: Div
|
|
1899
|
+
}, {
|
|
1900
|
+
childCount: 2,
|
|
1901
|
+
className: ChatActions,
|
|
1880
1902
|
type: Div
|
|
1881
1903
|
}, {
|
|
1882
1904
|
childCount: 1,
|
|
1883
|
-
className:
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
tabIndex: 0,
|
|
1887
|
-
title: 'Rename chat session',
|
|
1888
|
-
type: Button$1
|
|
1889
|
-
}, text('Rename'), {
|
|
1905
|
+
className: Label,
|
|
1906
|
+
type: Span
|
|
1907
|
+
}, text('Chats'), {
|
|
1890
1908
|
childCount: 1,
|
|
1891
1909
|
className: IconButton,
|
|
1892
|
-
name:
|
|
1910
|
+
name: 'create-session',
|
|
1893
1911
|
role: Button$2,
|
|
1894
1912
|
tabIndex: 0,
|
|
1895
|
-
title: '
|
|
1913
|
+
title: 'New Chat',
|
|
1896
1914
|
type: Button$1
|
|
1897
|
-
}, text('
|
|
1915
|
+
}, text('+'), {
|
|
1916
|
+
childCount: sessionsLength,
|
|
1917
|
+
className: ChatList,
|
|
1918
|
+
type: Div
|
|
1919
|
+
}];
|
|
1898
1920
|
};
|
|
1921
|
+
|
|
1899
1922
|
const getMessagesDom = messages => {
|
|
1900
1923
|
if (messages.length === 0) {
|
|
1901
1924
|
return [{
|
|
1902
1925
|
childCount: 1,
|
|
1903
|
-
className:
|
|
1926
|
+
className: ChatWelcomeMessage,
|
|
1904
1927
|
type: Div
|
|
1905
1928
|
}, text('Start a conversation by typing below.')];
|
|
1906
1929
|
}
|
|
@@ -1920,63 +1943,58 @@ const getMessagesDom = messages => {
|
|
|
1920
1943
|
}, text(message.text)];
|
|
1921
1944
|
});
|
|
1922
1945
|
};
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
const
|
|
1926
|
-
|
|
1927
|
-
const messagesNodes = getMessagesDom(messages);
|
|
1928
|
-
const dom = [{
|
|
1929
|
-
childCount: 3,
|
|
1930
|
-
className: Viewlet,
|
|
1931
|
-
onClick: HandleClick,
|
|
1932
|
-
onInput: HandleInput,
|
|
1933
|
-
onKeyDown: HandleKeyDown,
|
|
1934
|
-
type: Div
|
|
1935
|
-
}, {
|
|
1946
|
+
|
|
1947
|
+
const getSessionDom = (session, _selectedSessionId) => {
|
|
1948
|
+
const sessionClassName = ChatList;
|
|
1949
|
+
return [{
|
|
1936
1950
|
childCount: 2,
|
|
1937
|
-
className:
|
|
1951
|
+
className: sessionClassName,
|
|
1938
1952
|
type: Div
|
|
1939
1953
|
}, {
|
|
1954
|
+
childCount: 1,
|
|
1955
|
+
className: Button,
|
|
1956
|
+
name: `session:${session.id}`,
|
|
1957
|
+
role: Button$2,
|
|
1958
|
+
tabIndex: 0,
|
|
1959
|
+
type: Button$1
|
|
1960
|
+
}, text(session.title), {
|
|
1940
1961
|
childCount: 2,
|
|
1941
|
-
className:
|
|
1962
|
+
className: ChatActions,
|
|
1942
1963
|
type: Div
|
|
1943
1964
|
}, {
|
|
1944
|
-
childCount: 1,
|
|
1945
|
-
className: Label,
|
|
1946
|
-
type: Span
|
|
1947
|
-
}, text('Chats'), {
|
|
1948
1965
|
childCount: 1,
|
|
1949
1966
|
className: IconButton,
|
|
1950
|
-
name:
|
|
1967
|
+
name: `session-rename:${session.id}`,
|
|
1951
1968
|
role: Button$2,
|
|
1952
1969
|
tabIndex: 0,
|
|
1953
|
-
title: '
|
|
1970
|
+
title: 'Rename chat session',
|
|
1954
1971
|
type: Button$1
|
|
1955
|
-
}, text('
|
|
1956
|
-
childCount: sessions.length,
|
|
1957
|
-
className: ListItems,
|
|
1958
|
-
type: Div
|
|
1959
|
-
}, ...sessionNodes, {
|
|
1960
|
-
childCount: 2,
|
|
1961
|
-
className: Editor,
|
|
1962
|
-
type: Div
|
|
1963
|
-
}, {
|
|
1964
|
-
childCount: Math.max(messagesNodes.length, 0),
|
|
1965
|
-
className: EditorContent,
|
|
1966
|
-
type: Div
|
|
1967
|
-
}, ...messagesNodes, {
|
|
1972
|
+
}, text('Rename'), {
|
|
1968
1973
|
childCount: 1,
|
|
1969
|
-
className:
|
|
1974
|
+
className: IconButton,
|
|
1975
|
+
name: `session-delete:${session.id}`,
|
|
1976
|
+
role: Button$2,
|
|
1977
|
+
tabIndex: 0,
|
|
1978
|
+
title: 'Delete chat session',
|
|
1979
|
+
type: Button$1
|
|
1980
|
+
}, text('Delete')];
|
|
1981
|
+
};
|
|
1982
|
+
|
|
1983
|
+
const getChatVirtualDom = (sessions, selectedSessionId, composerValue) => {
|
|
1984
|
+
const selectedSession = sessions.find(session => session.id === selectedSessionId);
|
|
1985
|
+
const messages = selectedSession ? selectedSession.messages : [];
|
|
1986
|
+
const chatHeaderDom = getChatHeaderDom(sessions.length);
|
|
1987
|
+
const sessionNodes = sessions.flatMap(session => getSessionDom(session));
|
|
1988
|
+
const messagesNodes = getMessagesDom(messages);
|
|
1989
|
+
const chatDetailsDom = getChatDetailsDom(messagesNodes, composerValue);
|
|
1990
|
+
const dom = [{
|
|
1991
|
+
childCount: 3,
|
|
1992
|
+
className: Viewlet + ' Chat',
|
|
1993
|
+
onClick: HandleClick,
|
|
1994
|
+
onInput: HandleInput,
|
|
1995
|
+
onKeyDown: HandleKeyDown,
|
|
1970
1996
|
type: Div
|
|
1971
|
-
},
|
|
1972
|
-
childCount: 0,
|
|
1973
|
-
className: MultilineInputBox,
|
|
1974
|
-
name: 'composer',
|
|
1975
|
-
placeholder: 'Type your message. Enter to send, Shift+Enter for newline.',
|
|
1976
|
-
rows: 4,
|
|
1977
|
-
type: TextArea,
|
|
1978
|
-
value: composerValue
|
|
1979
|
-
}];
|
|
1997
|
+
}, ...chatHeaderDom, ...sessionNodes, ...chatDetailsDom];
|
|
1980
1998
|
return dom;
|
|
1981
1999
|
};
|
|
1982
2000
|
|
|
@@ -1991,7 +2009,7 @@ const renderItems = (oldState, newState) => {
|
|
|
1991
2009
|
if (initial) {
|
|
1992
2010
|
return [SetDom2, uid, []];
|
|
1993
2011
|
}
|
|
1994
|
-
const dom =
|
|
2012
|
+
const dom = getChatVirtualDom(sessions, selectedSessionId, composerValue);
|
|
1995
2013
|
return [SetDom2, uid, dom];
|
|
1996
2014
|
};
|
|
1997
2015
|
|
|
@@ -2004,6 +2022,8 @@ const renderIncremental = (oldState, newState) => {
|
|
|
2004
2022
|
|
|
2005
2023
|
const getRenderer = diffType => {
|
|
2006
2024
|
switch (diffType) {
|
|
2025
|
+
case RenderCss:
|
|
2026
|
+
return renderCss;
|
|
2007
2027
|
case RenderIncremental:
|
|
2008
2028
|
return renderIncremental;
|
|
2009
2029
|
case RenderItems:
|
|
@@ -2062,14 +2082,10 @@ const saveState = state => {
|
|
|
2062
2082
|
nextSessionId,
|
|
2063
2083
|
renamingSessionId,
|
|
2064
2084
|
selectedSessionId,
|
|
2065
|
-
sessions
|
|
2066
|
-
statusBarItemsLeft,
|
|
2067
|
-
statusBarItemsRight
|
|
2085
|
+
sessions
|
|
2068
2086
|
} = state;
|
|
2069
2087
|
return {
|
|
2070
2088
|
composerValue,
|
|
2071
|
-
itemsLeft: statusBarItemsLeft,
|
|
2072
|
-
itemsRight: statusBarItemsRight,
|
|
2073
2089
|
nextMessageId,
|
|
2074
2090
|
nextSessionId,
|
|
2075
2091
|
renamingSessionId,
|
|
@@ -2082,14 +2098,14 @@ const commandMap = {
|
|
|
2082
2098
|
'Chat.create': create,
|
|
2083
2099
|
'Chat.diff2': diff2,
|
|
2084
2100
|
'Chat.getCommandIds': getCommandIds,
|
|
2101
|
+
'Chat.getKeyBindings': getKeyBindings,
|
|
2085
2102
|
'Chat.handleClick': wrapCommand(handleClick),
|
|
2103
|
+
'Chat.handleClickClose': handleClickClose,
|
|
2086
2104
|
'Chat.handleInput': wrapCommand(handleInput),
|
|
2087
2105
|
'Chat.handleKeyDown': wrapCommand(handleKeyDown),
|
|
2088
2106
|
'Chat.initialize': initialize,
|
|
2089
|
-
'Chat.itemLeftUpdate': wrapCommand(itemLeftUpdate),
|
|
2090
|
-
'Chat.itemRightCreate': wrapCommand(itemRightCreate),
|
|
2091
|
-
'Chat.itemRightUpdate': wrapCommand(itemRightUpdate),
|
|
2092
2107
|
'Chat.loadContent': wrapCommand(loadContent),
|
|
2108
|
+
'Chat.loadContent2': wrapCommand(loadContent),
|
|
2093
2109
|
'Chat.render2': render2,
|
|
2094
2110
|
'Chat.renderEventListeners': renderEventListeners,
|
|
2095
2111
|
'Chat.resize': wrapCommand(resize),
|