@vectara/vectara-ui 0.0.2

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 (333) hide show
  1. package/.github/workflows/deploy-pages-site.yml +26 -0
  2. package/.github/workflows/deploy-pr-preview.yml +25 -0
  3. package/CHANGELOG.md +13 -0
  4. package/NO_LICENSE +3 -0
  5. package/lib/components/accordion/Accordion.d.ts +8 -0
  6. package/lib/components/accordion/Accordion.js +27 -0
  7. package/lib/components/accordion/_index.scss +23 -0
  8. package/lib/components/accountMenu/AccountMenu.d.ts +13 -0
  9. package/lib/components/accountMenu/AccountMenu.js +7 -0
  10. package/lib/components/accountMenu/_index.scss +20 -0
  11. package/lib/components/app/AppContent.d.ts +9 -0
  12. package/lib/components/app/AppContent.js +28 -0
  13. package/lib/components/app/AppHeader.d.ts +7 -0
  14. package/lib/components/app/AppHeader.js +18 -0
  15. package/lib/components/app/AppLayout.d.ts +9 -0
  16. package/lib/components/app/AppLayout.js +10 -0
  17. package/lib/components/app/_index.scss +4 -0
  18. package/lib/components/app/appContent.scss +26 -0
  19. package/lib/components/app/appHeader.scss +15 -0
  20. package/lib/components/app/appLayout.scss +23 -0
  21. package/lib/components/app/appSideNav/AppSideNav.d.ts +7 -0
  22. package/lib/components/app/appSideNav/AppSideNav.js +46 -0
  23. package/lib/components/app/appSideNav/AppSideNavLink.d.ts +4 -0
  24. package/lib/components/app/appSideNav/AppSideNavLink.js +26 -0
  25. package/lib/components/app/appSideNav/AppSideNavSections.d.ts +2 -0
  26. package/lib/components/app/appSideNav/AppSideNavSections.js +11 -0
  27. package/lib/components/app/appSideNav/AppSideNavTree.d.ts +2 -0
  28. package/lib/components/app/appSideNav/AppSideNavTree.js +38 -0
  29. package/lib/components/app/appSideNav/_index.scss +17 -0
  30. package/lib/components/app/appSideNav/appSideNav.scss +75 -0
  31. package/lib/components/app/appSideNav/appSideNavSections.scss +33 -0
  32. package/lib/components/app/appSideNav/appSideNavTree.scss +25 -0
  33. package/lib/components/app/types.d.ts +21 -0
  34. package/lib/components/app/types.js +1 -0
  35. package/lib/components/badge/Badge.d.ts +14 -0
  36. package/lib/components/badge/Badge.js +33 -0
  37. package/lib/components/badge/_index.scss +64 -0
  38. package/lib/components/button/BaseButton.d.ts +28 -0
  39. package/lib/components/button/BaseButton.js +65 -0
  40. package/lib/components/button/ButtonPrimary.d.ts +8 -0
  41. package/lib/components/button/ButtonPrimary.js +42 -0
  42. package/lib/components/button/ButtonSecondary.d.ts +10 -0
  43. package/lib/components/button/ButtonSecondary.js +43 -0
  44. package/lib/components/button/ButtonTertiary.d.ts +10 -0
  45. package/lib/components/button/ButtonTertiary.js +43 -0
  46. package/lib/components/button/IconButton.d.ts +16 -0
  47. package/lib/components/button/IconButton.js +29 -0
  48. package/lib/components/button/_index.scss +5 -0
  49. package/lib/components/button/baseButton.scss +94 -0
  50. package/lib/components/button/buttonPrimary.scss +51 -0
  51. package/lib/components/button/buttonSecondary.scss +54 -0
  52. package/lib/components/button/buttonTertiary.scss +56 -0
  53. package/lib/components/button/createButtonIcon.d.ts +3 -0
  54. package/lib/components/button/createButtonIcon.js +24 -0
  55. package/lib/components/button/iconButton.scss +44 -0
  56. package/lib/components/button/types.d.ts +3 -0
  57. package/lib/components/button/types.js +2 -0
  58. package/lib/components/callout/Callout.d.ts +13 -0
  59. package/lib/components/callout/Callout.js +40 -0
  60. package/lib/components/callout/_index.scss +49 -0
  61. package/lib/components/callout/types.d.ts +3 -0
  62. package/lib/components/callout/types.js +2 -0
  63. package/lib/components/card/Card.d.ts +14 -0
  64. package/lib/components/card/Card.js +29 -0
  65. package/lib/components/card/_index.scss +114 -0
  66. package/lib/components/chat/Chat.d.ts +17 -0
  67. package/lib/components/chat/Chat.js +130 -0
  68. package/lib/components/chat/ChatInspector.d.ts +7 -0
  69. package/lib/components/chat/ChatInspector.js +12 -0
  70. package/lib/components/chat/ChatPanel.d.ts +7 -0
  71. package/lib/components/chat/ChatPanel.js +11 -0
  72. package/lib/components/chat/ChatSearchResult.d.ts +16 -0
  73. package/lib/components/chat/ChatSearchResult.js +26 -0
  74. package/lib/components/chat/ChatTurn.d.ts +9 -0
  75. package/lib/components/chat/ChatTurn.js +19 -0
  76. package/lib/components/chat/_index.scss +150 -0
  77. package/lib/components/chat/chatTurn.scss +38 -0
  78. package/lib/components/chat/types.d.ts +17 -0
  79. package/lib/components/chat/types.js +19 -0
  80. package/lib/components/code/Code.d.ts +17 -0
  81. package/lib/components/code/Code.js +44 -0
  82. package/lib/components/code/_index.scss +33 -0
  83. package/lib/components/code/types.d.ts +1 -0
  84. package/lib/components/code/types.js +1 -0
  85. package/lib/components/context/Context.d.ts +18 -0
  86. package/lib/components/context/Context.js +34 -0
  87. package/lib/components/context/Context.test.util.d.ts +2 -0
  88. package/lib/components/context/Context.test.util.js +22 -0
  89. package/lib/components/copyButton/CopyButton.d.ts +10 -0
  90. package/lib/components/copyButton/CopyButton.js +50 -0
  91. package/lib/components/drawer/Drawer.d.ts +13 -0
  92. package/lib/components/drawer/Drawer.js +53 -0
  93. package/lib/components/drawer/_index.scss +73 -0
  94. package/lib/components/flex/FlexContainer.d.ts +36 -0
  95. package/lib/components/flex/FlexContainer.js +53 -0
  96. package/lib/components/flex/FlexItem.d.ts +22 -0
  97. package/lib/components/flex/FlexItem.js +36 -0
  98. package/lib/components/flex/_flexContainer.scss +79 -0
  99. package/lib/components/flex/_flexItem.scss +64 -0
  100. package/lib/components/flex/_index.scss +2 -0
  101. package/lib/components/flex/types.d.ts +2 -0
  102. package/lib/components/flex/types.js +1 -0
  103. package/lib/components/form/_index.scss +7 -0
  104. package/lib/components/form/checkbox/Checkbox.d.ts +8 -0
  105. package/lib/components/form/checkbox/Checkbox.js +24 -0
  106. package/lib/components/form/checkbox/_index.scss +3 -0
  107. package/lib/components/form/index.d.ts +10 -0
  108. package/lib/components/form/index.js +9 -0
  109. package/lib/components/form/input/BasicInput.d.ts +15 -0
  110. package/lib/components/form/input/BasicInput.js +30 -0
  111. package/lib/components/form/input/NumberInput.d.ts +8 -0
  112. package/lib/components/form/input/NumberInput.js +61 -0
  113. package/lib/components/form/input/PasswordInput.d.ts +7 -0
  114. package/lib/components/form/input/PasswordInput.js +21 -0
  115. package/lib/components/form/input/TextInput.d.ts +6 -0
  116. package/lib/components/form/input/TextInput.js +21 -0
  117. package/lib/components/form/input/_index.scss +24 -0
  118. package/lib/components/form/label/Label.d.ts +7 -0
  119. package/lib/components/form/label/Label.js +18 -0
  120. package/lib/components/form/label/_index.scss +5 -0
  121. package/lib/components/form/radioButton/RadioButton.d.ts +9 -0
  122. package/lib/components/form/radioButton/RadioButton.js +24 -0
  123. package/lib/components/form/radioButton/_index.scss +3 -0
  124. package/lib/components/form/select/Select.d.ts +17 -0
  125. package/lib/components/form/select/Select.js +34 -0
  126. package/lib/components/form/select/_index.scss +56 -0
  127. package/lib/components/form/superRadioGroup/SuperRadioButton.d.ts +7 -0
  128. package/lib/components/form/superRadioGroup/SuperRadioButton.js +22 -0
  129. package/lib/components/form/superRadioGroup/SuperRadioGroup.d.ts +8 -0
  130. package/lib/components/form/superRadioGroup/SuperRadioGroup.js +6 -0
  131. package/lib/components/form/superRadioGroup/_index.scss +31 -0
  132. package/lib/components/form/superRadioGroup/types.d.ts +8 -0
  133. package/lib/components/form/superRadioGroup/types.js +1 -0
  134. package/lib/components/form/textArea/TextArea.d.ts +12 -0
  135. package/lib/components/form/textArea/TextArea.js +21 -0
  136. package/lib/components/form/textArea/_index.scss +14 -0
  137. package/lib/components/formGroup/FormGroup.d.ts +10 -0
  138. package/lib/components/formGroup/FormGroup.js +27 -0
  139. package/lib/components/grid/Grid.d.ts +12 -0
  140. package/lib/components/grid/Grid.js +20 -0
  141. package/lib/components/grid/_index.scss +51 -0
  142. package/lib/components/horizontalRule/HorizontalRule.d.ts +6 -0
  143. package/lib/components/horizontalRule/HorizontalRule.js +4 -0
  144. package/lib/components/horizontalRule/_index.scss +40 -0
  145. package/lib/components/icon/Icon.d.ts +11 -0
  146. package/lib/components/icon/Icon.js +37 -0
  147. package/lib/components/icon/_index.scss +25 -0
  148. package/lib/components/icon/types.d.ts +2 -0
  149. package/lib/components/icon/types.js +12 -0
  150. package/lib/components/index.d.ts +75 -0
  151. package/lib/components/index.js +67 -0
  152. package/lib/components/infoTable/InfoTable.d.ts +24 -0
  153. package/lib/components/infoTable/InfoTable.js +24 -0
  154. package/lib/components/infoTable/_index.scss +53 -0
  155. package/lib/components/link/Link.d.ts +3 -0
  156. package/lib/components/link/Link.js +36 -0
  157. package/lib/components/link/Link.test.d.ts +1 -0
  158. package/lib/components/link/Link.test.js +40 -0
  159. package/lib/components/link/_index.scss +17 -0
  160. package/lib/components/link/types.d.ts +15 -0
  161. package/lib/components/link/types.js +1 -0
  162. package/lib/components/list/List.d.ts +12 -0
  163. package/lib/components/list/List.js +15 -0
  164. package/lib/components/list/_index.scss +29 -0
  165. package/lib/components/menu/Menu.d.ts +7 -0
  166. package/lib/components/menu/Menu.js +6 -0
  167. package/lib/components/menu/MenuItem.d.ts +10 -0
  168. package/lib/components/menu/MenuItem.js +31 -0
  169. package/lib/components/menu/_index.scss +75 -0
  170. package/lib/components/modal/Modal.d.ts +13 -0
  171. package/lib/components/modal/Modal.js +53 -0
  172. package/lib/components/modal/_index.scss +85 -0
  173. package/lib/components/notification/Notification.d.ts +12 -0
  174. package/lib/components/notification/Notification.js +23 -0
  175. package/lib/components/notification/Notifications.d.ts +10 -0
  176. package/lib/components/notification/Notifications.js +35 -0
  177. package/lib/components/notification/_index.scss +99 -0
  178. package/lib/components/optionsButton/OptionsButton.d.ts +7 -0
  179. package/lib/components/optionsButton/OptionsButton.js +25 -0
  180. package/lib/components/optionsButton/_index.scss +42 -0
  181. package/lib/components/optionsList/OptionsList.d.ts +13 -0
  182. package/lib/components/optionsList/OptionsList.js +31 -0
  183. package/lib/components/optionsList/OptionsListItem.d.ts +10 -0
  184. package/lib/components/optionsList/OptionsListItem.js +41 -0
  185. package/lib/components/optionsList/_index.scss +84 -0
  186. package/lib/components/optionsList/types.d.ts +13 -0
  187. package/lib/components/optionsList/types.js +1 -0
  188. package/lib/components/popover/Popover.d.ts +11 -0
  189. package/lib/components/popover/Popover.js +91 -0
  190. package/lib/components/popover/_index.scss +29 -0
  191. package/lib/components/portal/Portal.d.ts +6 -0
  192. package/lib/components/portal/Portal.js +16 -0
  193. package/lib/components/progressBar/ProgressBar.d.ts +9 -0
  194. package/lib/components/progressBar/ProgressBar.js +26 -0
  195. package/lib/components/progressBar/_index.scss +63 -0
  196. package/lib/components/prompt/Prompt.d.ts +20 -0
  197. package/lib/components/prompt/Prompt.js +19 -0
  198. package/lib/components/prompt/_index.scss +70 -0
  199. package/lib/components/screenBlock/ScreenBlock.d.ts +6 -0
  200. package/lib/components/screenBlock/ScreenBlock.js +4 -0
  201. package/lib/components/screenBlock/_index.scss +17 -0
  202. package/lib/components/searchInput/SearchInput.d.ts +13 -0
  203. package/lib/components/searchInput/SearchInput.js +19 -0
  204. package/lib/components/searchInput/_index.scss +49 -0
  205. package/lib/components/searchResult/SearchResult.d.ts +21 -0
  206. package/lib/components/searchResult/SearchResult.js +33 -0
  207. package/lib/components/searchResult/SearchResult.test.d.ts +1 -0
  208. package/lib/components/searchResult/SearchResult.test.js +280 -0
  209. package/lib/components/searchResult/_index.scss +29 -0
  210. package/lib/components/searchSelect/SearchSelect.d.ts +11 -0
  211. package/lib/components/searchSelect/SearchSelect.js +78 -0
  212. package/lib/components/searchSelect/_index.scss +13 -0
  213. package/lib/components/setting/Setting.d.ts +12 -0
  214. package/lib/components/setting/Setting.js +24 -0
  215. package/lib/components/spacer/Spacer.d.ts +6 -0
  216. package/lib/components/spacer/Spacer.js +6 -0
  217. package/lib/components/spacer/_index.scss +20 -0
  218. package/lib/components/spacer/types.d.ts +1 -0
  219. package/lib/components/spacer/types.js +1 -0
  220. package/lib/components/spinner/Spinner.d.ts +7 -0
  221. package/lib/components/spinner/Spinner.js +15 -0
  222. package/lib/components/spinner/_index.scss +52 -0
  223. package/lib/components/spinner/types.d.ts +3 -0
  224. package/lib/components/spinner/types.js +2 -0
  225. package/lib/components/statList/StatList.d.ts +9 -0
  226. package/lib/components/statList/StatList.js +15 -0
  227. package/lib/components/statList/_index.scss +3 -0
  228. package/lib/components/status/Status.d.ts +6 -0
  229. package/lib/components/status/Status.js +24 -0
  230. package/lib/components/summary/Summary.d.ts +7 -0
  231. package/lib/components/summary/Summary.js +43 -0
  232. package/lib/components/summary/Summary.test.d.ts +1 -0
  233. package/lib/components/summary/Summary.test.js +544 -0
  234. package/lib/components/summary/SummaryCitation.d.ts +8 -0
  235. package/lib/components/summary/SummaryCitation.js +20 -0
  236. package/lib/components/summary/_index.scss +29 -0
  237. package/lib/components/table/Table.d.ts +44 -0
  238. package/lib/components/table/Table.js +117 -0
  239. package/lib/components/table/TableBulkActions.d.ts +7 -0
  240. package/lib/components/table/TableBulkActions.js +34 -0
  241. package/lib/components/table/TableCell.d.ts +5 -0
  242. package/lib/components/table/TableCell.js +4 -0
  243. package/lib/components/table/TableContent.d.ts +6 -0
  244. package/lib/components/table/TableContent.js +6 -0
  245. package/lib/components/table/TableHeaderCell.d.ts +9 -0
  246. package/lib/components/table/TableHeaderCell.js +8 -0
  247. package/lib/components/table/TablePager.d.ts +9 -0
  248. package/lib/components/table/TablePager.js +9 -0
  249. package/lib/components/table/TablePagination.d.ts +10 -0
  250. package/lib/components/table/TablePagination.js +18 -0
  251. package/lib/components/table/TableRowActions.d.ts +15 -0
  252. package/lib/components/table/TableRowActions.js +29 -0
  253. package/lib/components/table/_index.scss +70 -0
  254. package/lib/components/table/createPagination.d.ts +4 -0
  255. package/lib/components/table/createPagination.js +44 -0
  256. package/lib/components/table/createPagination.test.d.ts +1 -0
  257. package/lib/components/table/createPagination.test.js +32 -0
  258. package/lib/components/table/types.d.ts +1 -0
  259. package/lib/components/table/types.js +1 -0
  260. package/lib/components/tabs/Tab.d.ts +9 -0
  261. package/lib/components/tabs/Tab.js +27 -0
  262. package/lib/components/tabs/TabbedRoutes.d.ts +15 -0
  263. package/lib/components/tabs/TabbedRoutes.js +15 -0
  264. package/lib/components/tabs/Tabs.d.ts +10 -0
  265. package/lib/components/tabs/Tabs.js +8 -0
  266. package/lib/components/tabs/_index.scss +103 -0
  267. package/lib/components/tabs/types.d.ts +2 -0
  268. package/lib/components/tabs/types.js +1 -0
  269. package/lib/components/toggle/Toggle.d.ts +8 -0
  270. package/lib/components/toggle/Toggle.js +25 -0
  271. package/lib/components/toggle/_index.scss +55 -0
  272. package/lib/components/topicButton/TopicButton.d.ts +10 -0
  273. package/lib/components/topicButton/TopicButton.js +30 -0
  274. package/lib/components/topicButton/_index.scss +21 -0
  275. package/lib/components/typography/Text.d.ts +13 -0
  276. package/lib/components/typography/Text.js +24 -0
  277. package/lib/components/typography/TextColor.d.ts +9 -0
  278. package/lib/components/typography/TextColor.js +6 -0
  279. package/lib/components/typography/Title.d.ts +11 -0
  280. package/lib/components/typography/Title.js +20 -0
  281. package/lib/components/typography/_index.scss +3 -0
  282. package/lib/components/typography/_text.scss +150 -0
  283. package/lib/components/typography/_textColor.scss +15 -0
  284. package/lib/components/typography/_title.scss +68 -0
  285. package/lib/components/typography/types.d.ts +4 -0
  286. package/lib/components/typography/types.js +3 -0
  287. package/lib/index.d.ts +1 -0
  288. package/lib/index.js +1 -0
  289. package/lib/sassUtils/_animation.scss +1 -0
  290. package/lib/sassUtils/_app.scss +1 -0
  291. package/lib/sassUtils/_borders.scss +2 -0
  292. package/lib/sassUtils/_colors.scss +24 -0
  293. package/lib/sassUtils/_depth.scss +8 -0
  294. package/lib/sassUtils/_mixins.scss +11 -0
  295. package/lib/sassUtils/_shadows.scss +5 -0
  296. package/lib/sassUtils/_sizes.scss +10 -0
  297. package/lib/sassUtils/_typography.scss +20 -0
  298. package/lib/sassUtils/index.scss +10 -0
  299. package/lib/styles/index.css +3229 -0
  300. package/lib/utils/citations/applyCitationOrder.d.ts +1 -0
  301. package/lib/utils/citations/applyCitationOrder.js +19 -0
  302. package/lib/utils/citations/applyCitationOrder.test.d.ts +1 -0
  303. package/lib/utils/citations/applyCitationOrder.test.js +65 -0
  304. package/lib/utils/citations/extractCitations.d.ts +4 -0
  305. package/lib/utils/citations/extractCitations.js +26 -0
  306. package/lib/utils/citations/extractCitations.test.d.ts +1 -0
  307. package/lib/utils/citations/extractCitations.test.js +40 -0
  308. package/lib/utils/citations/index.d.ts +5 -0
  309. package/lib/utils/citations/index.js +5 -0
  310. package/lib/utils/citations/removeCitations.d.ts +1 -0
  311. package/lib/utils/citations/removeCitations.js +2 -0
  312. package/lib/utils/citations/removeCitations.test.d.ts +1 -0
  313. package/lib/utils/citations/removeCitations.test.js +11 -0
  314. package/lib/utils/citations/reorderCitations.d.ts +1 -0
  315. package/lib/utils/citations/reorderCitations.js +9 -0
  316. package/lib/utils/citations/reorderCitations.test.d.ts +1 -0
  317. package/lib/utils/citations/reorderCitations.test.js +6 -0
  318. package/lib/utils/citations/sanitizeCitations.d.ts +1 -0
  319. package/lib/utils/citations/sanitizeCitations.js +30 -0
  320. package/lib/utils/citations/sanitizeCitations.test.d.ts +1 -0
  321. package/lib/utils/citations/sanitizeCitations.test.js +11 -0
  322. package/lib/utils/createId.d.ts +1 -0
  323. package/lib/utils/createId.js +10 -0
  324. package/lib/utils/getTrackingProps.d.ts +7 -0
  325. package/lib/utils/getTrackingProps.js +18 -0
  326. package/lib/utils/index.d.ts +1 -0
  327. package/lib/utils/index.js +1 -0
  328. package/lib/utils/truncateString.d.ts +2 -0
  329. package/lib/utils/truncateString.js +20 -0
  330. package/lib/utils/truncateString.test.d.ts +1 -0
  331. package/lib/utils/truncateString.test.js +59 -0
  332. package/licenses.txt +9035 -0
  333. package/package.json +100 -0
@@ -0,0 +1 @@
1
+ export declare const applyCitationOrder: (searchResults: any[], unorderedSummary: string) => any[];
@@ -0,0 +1,19 @@
1
+ export const applyCitationOrder = (searchResults, unorderedSummary) => {
2
+ const orderedSearchResults = [];
3
+ const citations = unorderedSummary.match(/\[\d+\]/g) || [];
4
+ const addedCitations = new Set();
5
+ for (let i = 0; i < citations.length; i++) {
6
+ const citation = citations[i];
7
+ // Ignore citations that have already been added.
8
+ if (addedCitations.has(citation))
9
+ continue;
10
+ // Extract index from [INDEX] format.
11
+ const citationIndex = Number(citation.slice(1, citation.length - 1)) - 1;
12
+ // Ignore citations that are out of range of the search results.
13
+ if (citationIndex < 0 || citationIndex >= searchResults.length)
14
+ continue;
15
+ orderedSearchResults.push(searchResults[citationIndex]);
16
+ addedCitations.add(citation);
17
+ }
18
+ return orderedSearchResults;
19
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,65 @@
1
+ import { applyCitationOrder } from "./applyCitationOrder";
2
+ const searchResult1 = {
3
+ id: "id1",
4
+ snippet: {
5
+ pre: "pre",
6
+ text: "text",
7
+ post: "post"
8
+ },
9
+ source: "source1",
10
+ url: "url1",
11
+ title: "title1",
12
+ metadata: {
13
+ key: "value"
14
+ }
15
+ };
16
+ const searchResult2 = {
17
+ id: "id2",
18
+ snippet: {
19
+ pre: "pre",
20
+ text: "text",
21
+ post: "post"
22
+ },
23
+ source: "source2",
24
+ url: "url2",
25
+ title: "title2",
26
+ metadata: {
27
+ key: "value"
28
+ }
29
+ };
30
+ const searchResult3 = {
31
+ id: "id3",
32
+ snippet: {
33
+ pre: "pre",
34
+ text: "text",
35
+ post: "post"
36
+ },
37
+ source: "source3",
38
+ url: "url3",
39
+ title: "title3",
40
+ metadata: {
41
+ key: "value"
42
+ }
43
+ };
44
+ const searchResult4 = {
45
+ id: "id4",
46
+ snippet: {
47
+ pre: "pre",
48
+ text: "text",
49
+ post: "post"
50
+ },
51
+ source: "source4",
52
+ url: "url4",
53
+ title: "title4",
54
+ metadata: {
55
+ key: "value"
56
+ }
57
+ };
58
+ describe("applyCitationOrder", () => {
59
+ test("reorders search results to match the order of the citations in the summary", () => {
60
+ expect(applyCitationOrder([searchResult1, searchResult2, searchResult3, searchResult4], "summary [4] some words [1][3] and stuff at the end")).toEqual([searchResult4, searchResult1, searchResult3]);
61
+ });
62
+ test("ignores citations that are out of range of search results", () => {
63
+ expect(applyCitationOrder([searchResult1, searchResult2, searchResult3, searchResult4], "summary [5] some words [1][3] and stuff at the end")).toEqual([searchResult1, searchResult3]);
64
+ });
65
+ });
@@ -0,0 +1,4 @@
1
+ export declare const extractCitations: (summary: string) => {
2
+ text: string;
3
+ references?: string[] | undefined;
4
+ }[];
@@ -0,0 +1,26 @@
1
+ export const extractCitations = (summary) => {
2
+ // Match citations.
3
+ const regex = /\[(\d+(,*\s*\d*)*)\]/g;
4
+ const citations = [];
5
+ let match;
6
+ let lastIndex = 0;
7
+ // Parse all cited content.
8
+ while ((match = regex.exec(summary)) !== null) {
9
+ const index = match.index;
10
+ const reference = match[1];
11
+ const text = summary.slice(lastIndex, index);
12
+ // Handle citations that are in the form of [1, 2, 3] or [1,2,3]
13
+ // so normalize to the latter.
14
+ citations.push({
15
+ text,
16
+ references: reference.replace(/\s/g, "").split(",")
17
+ });
18
+ lastIndex = index + match[0].length;
19
+ }
20
+ // Add the remaining content after the last citation.
21
+ const text = summary.slice(lastIndex);
22
+ if (text.length > 0) {
23
+ citations.push({ text });
24
+ }
25
+ return citations;
26
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ import { extractCitations } from "./extractCitations";
2
+ describe("extractCitations", () => {
3
+ test("extracts single citations", () => {
4
+ const summary = "[1] Beginning of summary. [2][3] Multiple at beginning of sentence, and before comma [4], single at middle [5] of sentence. At end of sentence [6].";
5
+ expect(extractCitations(summary)).toEqual([
6
+ { text: "", references: ["1"] },
7
+ { text: " Beginning of summary. ", references: ["2"] },
8
+ { text: "", references: ["3"] },
9
+ {
10
+ text: " Multiple at beginning of sentence, and before comma ",
11
+ references: ["4"]
12
+ },
13
+ { text: ", single at middle ", references: ["5"] },
14
+ {
15
+ text: " of sentence. At end of sentence ",
16
+ references: ["6"]
17
+ },
18
+ { text: "." }
19
+ ]);
20
+ });
21
+ test("extracts citation at the end of the summary", () => {
22
+ const summary = "End of summary. [1]";
23
+ expect(extractCitations(summary)).toEqual([{ text: "End of summary. ", references: ["1"] }]);
24
+ });
25
+ test("extracts multiple comma-delimited citations", () => {
26
+ const summary = "Two citations [1, 2] and seven citations [1, 2, 3, 4, 5, 6, 7] and without spaces [1,2,3].";
27
+ expect(extractCitations(summary)).toEqual([
28
+ { text: "Two citations ", references: ["1", "2"] },
29
+ {
30
+ text: " and seven citations ",
31
+ references: ["1", "2", "3", "4", "5", "6", "7"]
32
+ },
33
+ {
34
+ text: " and without spaces ",
35
+ references: ["1", "2", "3"]
36
+ },
37
+ { text: "." }
38
+ ]);
39
+ });
40
+ });
@@ -0,0 +1,5 @@
1
+ export { applyCitationOrder } from "./applyCitationOrder";
2
+ export { extractCitations } from "./extractCitations";
3
+ export { reorderCitations } from "./reorderCitations";
4
+ export { sanitizeCitations } from "./sanitizeCitations";
5
+ export { removeCitations } from "./removeCitations";
@@ -0,0 +1,5 @@
1
+ export { applyCitationOrder } from "./applyCitationOrder";
2
+ export { extractCitations } from "./extractCitations";
3
+ export { reorderCitations } from "./reorderCitations";
4
+ export { sanitizeCitations } from "./sanitizeCitations";
5
+ export { removeCitations } from "./removeCitations";
@@ -0,0 +1 @@
1
+ export declare const removeCitations: (text: string) => string;
@@ -0,0 +1,2 @@
1
+ const regex = /(^\[(\d+(,*\s*\d*)*)\] ?)|( ?\[(\d+(,*\s*\d*)*)\])/g;
2
+ export const removeCitations = (text) => text.replace(regex, "");
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import { removeCitations } from "./removeCitations";
2
+ describe("removeCitations", () => {
3
+ test("removes single citations", () => {
4
+ const summary = "[1] Beginning of summary. [2][3] Multiple at beginning[2] of sentence, and before comma [4], single at middle [5] of sentence. At end of sentence [6].";
5
+ expect(removeCitations(summary)).toEqual("Beginning of summary. Multiple at beginning of sentence, and before comma, single at middle of sentence. At end of sentence.");
6
+ });
7
+ test("removes multiple comma-delimited citations", () => {
8
+ const summary = "Two citations [1, 2] and seven citations[1, 2, 3, 4, 5, 6, 7] and without spaces [1,2,3].";
9
+ expect(removeCitations(summary)).toEqual("Two citations and seven citations and without spaces.");
10
+ });
11
+ });
@@ -0,0 +1 @@
1
+ export declare const reorderCitations: (unorderedSummary: string) => string;
@@ -0,0 +1,9 @@
1
+ export const reorderCitations = (unorderedSummary) => {
2
+ const allCitations = unorderedSummary.match(/\[\d+\]/g) || [];
3
+ const uniqueCitations = [...new Set(allCitations)];
4
+ const citationToReplacement = {};
5
+ uniqueCitations.forEach((citation, index) => {
6
+ citationToReplacement[citation] = `[${index + 1}]`;
7
+ });
8
+ return unorderedSummary.replace(/\[\d+\]/g, (match) => citationToReplacement[match]);
9
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { reorderCitations } from "./reorderCitations";
2
+ describe("reorderCitations", () => {
3
+ test("reorders citations in a summary", () => {
4
+ expect(reorderCitations("summary [4] some words [1][3] and stuff at the end")).toEqual("summary [1] some words [2][3] and stuff at the end");
5
+ });
6
+ });
@@ -0,0 +1 @@
1
+ export declare const sanitizeCitations: (summary?: string) => string | undefined;
@@ -0,0 +1,30 @@
1
+ export const sanitizeCitations = (summary) => {
2
+ if (!summary)
3
+ return summary;
4
+ // Match citations.
5
+ const regex = /\[(\d+(,*\s*\d*)*)\]/g;
6
+ const parts = [];
7
+ let match;
8
+ let lastIndex = 0;
9
+ // Parse all cited content.
10
+ while ((match = regex.exec(summary)) !== null) {
11
+ const index = match.index;
12
+ const reference = match[1];
13
+ const text = summary.slice(lastIndex, index);
14
+ // Handle citations that are in the form of [1, 2, 3] or [1,2,3]
15
+ // so normalize to the latter.
16
+ parts.push(text);
17
+ parts.push(reference
18
+ .replace(/\s/g, "")
19
+ .split(",")
20
+ .map((citation) => `[${citation}]`)
21
+ .join(""));
22
+ lastIndex = index + match[0].length;
23
+ }
24
+ // Add the remaining content after the last citation.
25
+ const text = summary.slice(lastIndex);
26
+ if (text.length > 0) {
27
+ parts.push(text);
28
+ }
29
+ return parts.join("");
30
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import { sanitizeCitations } from "./sanitizeCitations";
2
+ describe("sanitizeCitations", () => {
3
+ test("ignores single citations", () => {
4
+ const summary = "[1] Beginning of summary. [2][3] Multiple at beginning of sentence, and before comma [4], single at middle [5] of sentence. At end of sentence [6].";
5
+ expect(sanitizeCitations(summary)).toEqual(summary);
6
+ });
7
+ test("sanitize multiple comma-delimited citations", () => {
8
+ const summary = "Two citations [1, 2] and seven citations [1, 2, 3, 4, 5, 6, 7] and without spaces [1,2,3].";
9
+ expect(sanitizeCitations(summary)).toEqual("Two citations [1][2] and seven citations [1][2][3][4][5][6][7] and without spaces [1][2][3].");
10
+ });
11
+ });
@@ -0,0 +1 @@
1
+ export declare const createId: () => string;
@@ -0,0 +1,10 @@
1
+ let id = 0;
2
+ export const createId = () => {
3
+ if (id === Number.MAX_SAFE_INTEGER) {
4
+ id = 0;
5
+ }
6
+ else {
7
+ id++;
8
+ }
9
+ return id.toString();
10
+ };
@@ -0,0 +1,7 @@
1
+ export declare const getTrackingProps: (track?: boolean) => {
2
+ rel: string;
3
+ referrerPolicy: string;
4
+ } | {
5
+ rel: string;
6
+ referrerPolicy?: undefined;
7
+ };
@@ -0,0 +1,18 @@
1
+ export const getTrackingProps = (track) => {
2
+ if (track) {
3
+ return {
4
+ // Protect against tabnabbing.
5
+ rel: "noopener",
6
+ // Provide information for tracking, e.g. to docs. Technically this should be
7
+ // 'referrerpolicy' but React wants it in camel case. This clashes with
8
+ // react-router Link's HTMLAttributeReferrerPolicy type definition so we
9
+ // have to use @ts-expect-error at callsites that consume this helper.
10
+ referrerPolicy: "no-referrer-when-downgrade"
11
+ };
12
+ }
13
+ // Protect against tabnabbing and strip information from the referrer header.
14
+ return {
15
+ rel: "noopener"
16
+ // Default referrer policy is set by a meta tag in index.html.
17
+ };
18
+ };
@@ -0,0 +1 @@
1
+ export { truncateStart, truncateEnd } from "./truncateString";
@@ -0,0 +1 @@
1
+ export { truncateStart, truncateEnd } from "./truncateString";
@@ -0,0 +1,2 @@
1
+ export declare const truncateStart: (source: string, maxLength: number) => string;
2
+ export declare const truncateEnd: (source: string, maxLength: number) => string;
@@ -0,0 +1,20 @@
1
+ export const truncateStart = (source, maxLength) => {
2
+ if (source.length < maxLength || maxLength <= 0)
3
+ return source;
4
+ const truncatedSource = source.substring(source.length - maxLength, source.length).trim();
5
+ if (truncatedSource.length)
6
+ return `…${truncatedSource}`;
7
+ return truncatedSource;
8
+ };
9
+ export const truncateEnd = (source, maxLength) => {
10
+ if (source.length < maxLength || maxLength <= 0)
11
+ return source;
12
+ const truncatedSource = source.substring(0, maxLength).trim();
13
+ if (truncatedSource.length) {
14
+ if ([".", "?", "!"].includes(truncatedSource[truncatedSource.length - 1])) {
15
+ return `${truncatedSource} …`;
16
+ }
17
+ return `${truncatedSource}…`;
18
+ }
19
+ return truncatedSource;
20
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
1
+ import { truncateStart, truncateEnd } from "./truncateString";
2
+ describe("truncateStart", () => {
3
+ it("returns a truncated source up to the maxLength", () => {
4
+ const source = "12345678";
5
+ expect(truncateStart(source, 5)).toBe("…45678");
6
+ });
7
+ it("preserves the original source if maxLength exceeds its length", () => {
8
+ const source = "12345678";
9
+ expect(truncateStart(source, 10)).toBe(source);
10
+ });
11
+ it("trims whitespace", () => {
12
+ const source = "1234 5678";
13
+ expect(truncateStart(source, 5)).toBe("…5678");
14
+ });
15
+ it("ignores zero maxLength", () => {
16
+ const source = "12345678";
17
+ expect(truncateStart(source, 0)).toBe(source);
18
+ });
19
+ it("ignores negative maxLength", () => {
20
+ const source = "12345678";
21
+ expect(truncateStart(source, -1)).toBe(source);
22
+ });
23
+ });
24
+ describe("truncateEnd", () => {
25
+ it("trims the maxLength number of characters from the start of the source", () => {
26
+ const source = "12345678";
27
+ expect(truncateEnd(source, 5)).toBe("12345…");
28
+ });
29
+ it("returns a truncated source up to the maxLength", () => {
30
+ const source = "12345678";
31
+ expect(truncateEnd(source, 10)).toBe(source);
32
+ });
33
+ it("trims whitespace", () => {
34
+ const source = "1234 5678";
35
+ expect(truncateEnd(source, 5)).toBe("1234…");
36
+ });
37
+ it("ignores zero maxLength", () => {
38
+ const source = "12345678";
39
+ expect(truncateEnd(source, 0)).toBe(source);
40
+ });
41
+ it("ignores negative maxLength", () => {
42
+ const source = "12345678";
43
+ expect(truncateEnd(source, -1)).toBe(source);
44
+ });
45
+ describe("inserts a space between the ellipsis and the truncated source when it ends", () => {
46
+ it("with a period", () => {
47
+ const source = "the. word";
48
+ expect(truncateEnd(source, 4)).toBe("the. …");
49
+ });
50
+ it("with a question mark", () => {
51
+ const source = "the? word";
52
+ expect(truncateEnd(source, 4)).toBe("the? …");
53
+ });
54
+ it("with an exclamation point", () => {
55
+ const source = "the! word";
56
+ expect(truncateEnd(source, 4)).toBe("the! …");
57
+ });
58
+ });
59
+ });