@lvce-editor/chat-view 1.2.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.
@@ -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);
@@ -1230,15 +1232,20 @@ const create = (uid, uri, x, y, width, height, platform, assetDir) => {
1230
1232
  set(uid, state, state);
1231
1233
  };
1232
1234
 
1235
+ const isEqual$1 = (oldState, newState) => {
1236
+ return oldState.initial === newState.initial;
1237
+ };
1238
+
1233
1239
  const isEqual = (oldState, newState) => {
1234
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;
1235
1241
  };
1236
1242
 
1237
1243
  const RenderItems = 4;
1244
+ const RenderCss = 10;
1238
1245
  const RenderIncremental = 11;
1239
1246
 
1240
- const modules = [isEqual];
1241
- const numbers = [RenderIncremental];
1247
+ const modules = [isEqual, isEqual$1];
1248
+ const numbers = [RenderIncremental, RenderCss];
1242
1249
 
1243
1250
  const diff = (oldState, newState) => {
1244
1251
  const diffResult = [];
@@ -1366,6 +1373,11 @@ const handleClick = async (state, name) => {
1366
1373
  return state;
1367
1374
  };
1368
1375
 
1376
+ const handleClickClose = async () => {
1377
+ // @ts-ignore
1378
+ await invoke('Chat.terminate');
1379
+ };
1380
+
1369
1381
  const handleInput = async (state, value) => {
1370
1382
  if (state.ignoreNextInput) {
1371
1383
  return {
@@ -1501,6 +1513,46 @@ const loadContent = async state => {
1501
1513
  };
1502
1514
  };
1503
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
+
1504
1556
  const text = data => {
1505
1557
  return {
1506
1558
  childCount: 0,
@@ -1797,67 +1849,81 @@ const diffTree = (oldNodes, newNodes) => {
1797
1849
  return removeTrailingNavigationPatches(patches);
1798
1850
  };
1799
1851
 
1800
- const Actions = 'Actions';
1801
- const TestActive = 'TestActive';
1802
- const SideBarLocation = 'SideBarLocation';
1852
+ const ChatActions = 'ChatActions';
1853
+ const ChatHeader = 'ChatHeader';
1803
1854
  const Button = 'Button';
1804
- const Editor = 'Editor';
1805
- const EditorContent = 'EditorContent';
1855
+ const ChatDetails = 'ChatDetails';
1856
+ const ChatDetailsContent = 'ChatDetailsContent';
1806
1857
  const IconButton = 'IconButton';
1807
1858
  const Label = 'Label';
1808
- const List = 'List';
1809
- const ListItems = 'ListItems';
1859
+ const ChatList = 'ChatList';
1810
1860
  const Markdown = 'Markdown';
1811
1861
  const Message = 'Message';
1812
1862
  const MultilineInputBox = 'MultilineInputBox';
1813
1863
  const Viewlet = 'Viewlet';
1814
- const WelcomeMessage = 'WelcomeMessage';
1864
+ const ChatWelcomeMessage = 'ChatWelcomeMessage';
1815
1865
 
1816
1866
  const HandleInput = 4;
1817
1867
  const HandleClick = 11;
1818
1868
  const HandleKeyDown = 12;
1819
1869
 
1820
- const getSessionDom = (session, selectedSessionId) => {
1821
- const selected = session.id === selectedSessionId;
1822
- const sessionClassName = selected ? `${List} ${TestActive}` : List;
1870
+ const getChatDetailsDom = (messagesNodes, composerValue) => {
1823
1871
  return [{
1824
1872
  childCount: 2,
1825
- className: sessionClassName,
1873
+ className: ChatDetails,
1826
1874
  type: Div
1827
1875
  }, {
1876
+ childCount: Math.max(messagesNodes.length, 0),
1877
+ className: ChatDetailsContent,
1878
+ type: Div
1879
+ }, ...messagesNodes, {
1828
1880
  childCount: 1,
1829
- className: Button,
1830
- name: `session:${session.id}`,
1831
- role: Button$2,
1832
- tabIndex: 0,
1833
- type: Button$1
1834
- }, text(session.title), {
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 [{
1896
+ childCount: 2,
1897
+ className: ChatHeader,
1898
+ type: Div
1899
+ }, {
1835
1900
  childCount: 2,
1836
- className: Actions,
1901
+ className: ChatActions,
1837
1902
  type: Div
1838
1903
  }, {
1839
1904
  childCount: 1,
1840
- className: IconButton,
1841
- name: `session-rename:${session.id}`,
1842
- role: Button$2,
1843
- tabIndex: 0,
1844
- title: 'Rename chat session',
1845
- type: Button$1
1846
- }, text('Rename'), {
1905
+ className: Label,
1906
+ type: Span
1907
+ }, text('Chats'), {
1847
1908
  childCount: 1,
1848
1909
  className: IconButton,
1849
- name: `session-delete:${session.id}`,
1910
+ name: 'create-session',
1850
1911
  role: Button$2,
1851
1912
  tabIndex: 0,
1852
- title: 'Delete chat session',
1913
+ title: 'New Chat',
1853
1914
  type: Button$1
1854
- }, text('Delete')];
1915
+ }, text('+'), {
1916
+ childCount: sessionsLength,
1917
+ className: ChatList,
1918
+ type: Div
1919
+ }];
1855
1920
  };
1921
+
1856
1922
  const getMessagesDom = messages => {
1857
1923
  if (messages.length === 0) {
1858
1924
  return [{
1859
1925
  childCount: 1,
1860
- className: WelcomeMessage,
1926
+ className: ChatWelcomeMessage,
1861
1927
  type: Div
1862
1928
  }, text('Start a conversation by typing below.')];
1863
1929
  }
@@ -1877,63 +1943,58 @@ const getMessagesDom = messages => {
1877
1943
  }, text(message.text)];
1878
1944
  });
1879
1945
  };
1880
- const getStatusBarVirtualDom = (sessions, selectedSessionId, composerValue) => {
1881
- const selectedSession = sessions.find(session => session.id === selectedSessionId);
1882
- const messages = selectedSession ? selectedSession.messages : [];
1883
- const sessionNodes = sessions.flatMap(session => getSessionDom(session, selectedSessionId));
1884
- const messagesNodes = getMessagesDom(messages);
1885
- const dom = [{
1886
- childCount: 3,
1887
- className: Viewlet,
1888
- onClick: HandleClick,
1889
- onInput: HandleInput,
1890
- onKeyDown: HandleKeyDown,
1891
- type: Div
1892
- }, {
1946
+
1947
+ const getSessionDom = (session, _selectedSessionId) => {
1948
+ const sessionClassName = ChatList;
1949
+ return [{
1893
1950
  childCount: 2,
1894
- className: SideBarLocation,
1951
+ className: sessionClassName,
1895
1952
  type: Div
1896
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), {
1897
1961
  childCount: 2,
1898
- className: Actions,
1962
+ className: ChatActions,
1899
1963
  type: Div
1900
1964
  }, {
1901
- childCount: 1,
1902
- className: Label,
1903
- type: Span
1904
- }, text('Chats'), {
1905
1965
  childCount: 1,
1906
1966
  className: IconButton,
1907
- name: 'create-session',
1967
+ name: `session-rename:${session.id}`,
1908
1968
  role: Button$2,
1909
1969
  tabIndex: 0,
1910
- title: 'New Chat',
1970
+ title: 'Rename chat session',
1911
1971
  type: Button$1
1912
- }, text('+'), {
1913
- childCount: sessions.length,
1914
- className: ListItems,
1915
- type: Div
1916
- }, ...sessionNodes, {
1917
- childCount: 2,
1918
- className: Editor,
1919
- type: Div
1920
- }, {
1921
- childCount: Math.max(messagesNodes.length, 0),
1922
- className: EditorContent,
1923
- type: Div
1924
- }, ...messagesNodes, {
1972
+ }, text('Rename'), {
1925
1973
  childCount: 1,
1926
- className: Actions,
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,
1927
1996
  type: Div
1928
- }, {
1929
- childCount: 0,
1930
- className: MultilineInputBox,
1931
- name: 'composer',
1932
- placeholder: 'Type your message. Enter to send, Shift+Enter for newline.',
1933
- rows: 4,
1934
- type: TextArea,
1935
- value: composerValue
1936
- }];
1997
+ }, ...chatHeaderDom, ...sessionNodes, ...chatDetailsDom];
1937
1998
  return dom;
1938
1999
  };
1939
2000
 
@@ -1948,7 +2009,7 @@ const renderItems = (oldState, newState) => {
1948
2009
  if (initial) {
1949
2010
  return [SetDom2, uid, []];
1950
2011
  }
1951
- const dom = getStatusBarVirtualDom(sessions, selectedSessionId, composerValue);
2012
+ const dom = getChatVirtualDom(sessions, selectedSessionId, composerValue);
1952
2013
  return [SetDom2, uid, dom];
1953
2014
  };
1954
2015
 
@@ -1961,6 +2022,8 @@ const renderIncremental = (oldState, newState) => {
1961
2022
 
1962
2023
  const getRenderer = diffType => {
1963
2024
  switch (diffType) {
2025
+ case RenderCss:
2026
+ return renderCss;
1964
2027
  case RenderIncremental:
1965
2028
  return renderIncremental;
1966
2029
  case RenderItems:
@@ -2037,6 +2100,7 @@ const commandMap = {
2037
2100
  'Chat.getCommandIds': getCommandIds,
2038
2101
  'Chat.getKeyBindings': getKeyBindings,
2039
2102
  'Chat.handleClick': wrapCommand(handleClick),
2103
+ 'Chat.handleClickClose': handleClickClose,
2040
2104
  'Chat.handleInput': wrapCommand(handleInput),
2041
2105
  'Chat.handleKeyDown': wrapCommand(handleKeyDown),
2042
2106
  'Chat.initialize': initialize,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/chat-view",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Chat View Worker",
5
5
  "repository": {
6
6
  "type": "git",