nexus-shared 1.1.21 → 3.0.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/CHANGELOG.md +262 -0
- package/LICENSE +21 -0
- package/README.md +1000 -0
- package/dist/Client.Index.d.ts +55 -0
- package/dist/Client.Index.js +60 -0
- package/dist/Components/Chats/Chat.d.ts +28 -0
- package/dist/Components/Chats/Chat.js +19 -0
- package/dist/Components/Chats/ChatButton.d.ts +26 -0
- package/dist/Components/Chats/ChatButton.js +41 -0
- package/dist/Components/Chats/ChatComposer.d.ts +41 -0
- package/dist/Components/Chats/ChatComposer.js +177 -0
- package/dist/Components/Chats/ChatConversations.d.ts +35 -0
- package/dist/Components/Chats/ChatConversations.js +38 -0
- package/dist/Components/Chats/ChatPanel.d.ts +66 -0
- package/dist/Components/Chats/ChatPanel.js +94 -0
- package/dist/Components/Chats/ChatParts.d.ts +87 -0
- package/dist/Components/Chats/ChatParts.js +100 -0
- package/dist/Components/Chats/ChatThread.d.ts +22 -0
- package/dist/Components/Chats/ChatThread.js +96 -0
- package/dist/Components/Documents/Button.d.ts +29 -0
- package/dist/Components/Documents/Button.js +11 -0
- package/dist/Components/Documents/Menu.d.ts +102 -0
- package/dist/Components/Documents/Menu.js +242 -0
- package/dist/Components/Documents/SplitButton.d.ts +64 -0
- package/dist/Components/Documents/SplitButton.js +129 -0
- package/dist/Components/Documents/TabButtons.d.ts +80 -0
- package/dist/Components/Documents/TabButtons.js +38 -0
- package/dist/Components/Forms/ApiForm.d.ts +23 -0
- package/dist/Components/Forms/ApiForm.js +100 -0
- package/dist/Components/Forms/Crud.d.ts +17 -0
- package/dist/Components/Forms/Crud.js +708 -0
- package/dist/Components/Forms/CrudParts.d.ts +15 -0
- package/dist/Components/Forms/CrudParts.js +36 -0
- package/dist/Components/Forms/ExcelImport.d.ts +42 -0
- package/dist/Components/Forms/ExcelImport.js +190 -0
- package/dist/Components/Forms/Form.d.ts +52 -0
- package/dist/Components/Forms/Form.js +323 -0
- package/dist/Components/Forms/SubmitForm.d.ts +65 -0
- package/dist/Components/Forms/SubmitForm.js +198 -0
- package/dist/Components/Inputs/Calendar.d.ts +69 -0
- package/dist/Components/Inputs/Calendar.js +258 -0
- package/dist/Components/Inputs/CheckBox.d.ts +53 -0
- package/dist/Components/Inputs/CheckBox.js +87 -0
- package/dist/Components/Inputs/CheckBoxGroup.d.ts +20 -0
- package/dist/Components/Inputs/CheckBoxGroup.js +80 -0
- package/dist/Components/Inputs/ChoiceField.d.ts +122 -0
- package/dist/Components/Inputs/ChoiceField.js +169 -0
- package/dist/Components/Inputs/DatePicker.d.ts +54 -0
- package/dist/Components/Inputs/DatePicker.js +246 -0
- package/dist/Components/Inputs/DateRangePicker.d.ts +62 -0
- package/dist/Components/Inputs/DateRangePicker.js +283 -0
- package/dist/Components/Inputs/DateTimePicker.d.ts +75 -0
- package/dist/Components/Inputs/DateTimePicker.js +400 -0
- package/dist/Components/Inputs/Dropdown.d.ts +117 -0
- package/dist/Components/Inputs/Dropdown.js +839 -0
- package/dist/Components/Inputs/DropdownParts.d.ts +84 -0
- package/dist/Components/Inputs/DropdownParts.js +102 -0
- package/dist/Components/Inputs/EditorShell.d.ts +45 -0
- package/dist/Components/Inputs/EditorShell.js +214 -0
- package/dist/Components/Inputs/Field.d.ts +53 -0
- package/dist/Components/Inputs/Field.js +16 -0
- package/dist/Components/Inputs/GroupForm.d.ts +20 -0
- package/dist/Components/Inputs/GroupForm.js +172 -0
- package/dist/Components/Inputs/InputField.d.ts +59 -0
- package/dist/Components/Inputs/InputField.js +169 -0
- package/dist/Components/Inputs/InputRenderer.d.ts +37 -0
- package/dist/Components/Inputs/InputRenderer.js +99 -0
- package/dist/Components/Inputs/MarkdownEditor.d.ts +67 -0
- package/dist/Components/Inputs/MarkdownEditor.js +289 -0
- package/dist/Components/Inputs/NumberBox.d.ts +53 -0
- package/dist/Components/Inputs/NumberBox.js +228 -0
- package/dist/Components/Inputs/RadioGroup.d.ts +20 -0
- package/dist/Components/Inputs/RadioGroup.js +43 -0
- package/dist/Components/Inputs/ReadOnlyNotice.d.ts +36 -0
- package/dist/Components/Inputs/ReadOnlyNotice.js +117 -0
- package/dist/Components/Inputs/RichTextEditor.d.ts +103 -0
- package/dist/Components/Inputs/RichTextEditor.js +1170 -0
- package/dist/Components/Inputs/RichTextParts.d.ts +63 -0
- package/dist/Components/Inputs/RichTextParts.js +157 -0
- package/dist/Components/Inputs/RowsInput.d.ts +115 -0
- package/dist/Components/Inputs/RowsInput.js +308 -0
- package/dist/Components/Inputs/Slider.d.ts +87 -0
- package/dist/Components/Inputs/Slider.js +216 -0
- package/dist/Components/Inputs/TabularForm.d.ts +27 -0
- package/dist/Components/Inputs/TabularForm.js +348 -0
- package/dist/Components/Inputs/TextArea.d.ts +43 -0
- package/dist/Components/Inputs/TextArea.js +31 -0
- package/dist/Components/Inputs/TextBox.d.ts +52 -0
- package/dist/Components/Inputs/TextBox.js +58 -0
- package/dist/Components/Inputs/TextField.d.ts +31 -0
- package/dist/Components/Inputs/TextField.js +35 -0
- package/dist/Components/Inputs/TimePanel.d.ts +34 -0
- package/dist/Components/Inputs/TimePanel.js +288 -0
- package/dist/Components/Inputs/TimePicker.d.ts +54 -0
- package/dist/Components/Inputs/TimePicker.js +240 -0
- package/dist/Components/Inputs/TreeView.d.ts +160 -0
- package/dist/Components/Inputs/TreeView.js +947 -0
- package/dist/Components/Layouts/MessageBox.d.ts +71 -0
- package/dist/Components/Layouts/MessageBox.js +104 -0
- package/dist/Components/Layouts/Popup.d.ts +92 -0
- package/dist/Components/Layouts/Popup.js +376 -0
- package/dist/Components/Layouts/PopupContext.d.ts +2 -0
- package/dist/Components/Layouts/PopupContext.js +4 -0
- package/dist/Components/Layouts/PopupDock.d.ts +22 -0
- package/dist/Components/Layouts/PopupDock.js +121 -0
- package/dist/Components/Layouts/PopupHost.d.ts +56 -0
- package/dist/Components/Layouts/PopupHost.js +163 -0
- package/dist/Components/Layouts/PopupRules.d.ts +30 -0
- package/dist/Components/Layouts/PopupRules.js +63 -0
- package/dist/Components/Layouts/ThemePicker.d.ts +13 -0
- package/dist/Components/Layouts/ThemePicker.js +22 -0
- package/dist/Components/Layouts/ThemeScript.d.ts +14 -0
- package/dist/Components/Layouts/ThemeScript.js +13 -0
- package/dist/Components/Layouts/ThemeSwitcher.d.ts +13 -0
- package/dist/Components/Layouts/ThemeSwitcher.js +49 -0
- package/dist/Components/Layouts/Toaster.d.ts +76 -0
- package/dist/Components/Layouts/Toaster.js +172 -0
- package/dist/Components/Viewers/DataTable.d.ts +25 -0
- package/dist/Components/Viewers/DataTable.js +596 -0
- package/dist/Components/Viewers/DataTableColumns.d.ts +28 -0
- package/dist/Components/Viewers/DataTableColumns.js +243 -0
- package/dist/Components/Viewers/DataTableParts.d.ts +138 -0
- package/dist/Components/Viewers/DataTableParts.js +157 -0
- package/dist/Components/Viewers/MarkdownView.d.ts +26 -0
- package/dist/Components/Viewers/MarkdownView.js +79 -0
- package/dist/Components/Viewers/RichTextView.d.ts +18 -0
- package/dist/Components/Viewers/RichTextView.js +17 -0
- package/dist/Helpers/AnimationHelpers.d.ts +6 -0
- package/dist/Helpers/AnimationHelpers.js +35 -0
- package/dist/Helpers/ApiClient.d.ts +96 -0
- package/dist/Helpers/ApiClient.js +200 -0
- package/dist/Helpers/ApiFormHelpers.d.ts +49 -0
- package/dist/Helpers/ApiFormHelpers.js +120 -0
- package/dist/Helpers/ApiModules.d.ts +131 -0
- package/dist/Helpers/ApiModules.js +195 -0
- package/dist/Helpers/ApiResponses.d.ts +51 -0
- package/dist/Helpers/ApiResponses.js +250 -0
- package/dist/Helpers/ApiRoutes.d.ts +140 -0
- package/dist/Helpers/ApiRoutes.js +183 -0
- package/dist/Helpers/ApiToasts.d.ts +21 -0
- package/dist/Helpers/ApiToasts.js +22 -0
- package/dist/Helpers/ChatBackend.d.ts +134 -0
- package/dist/Helpers/ChatBackend.js +332 -0
- package/dist/Helpers/ChatHelpers.d.ts +189 -0
- package/dist/Helpers/ChatHelpers.js +486 -0
- package/dist/Helpers/ChatHooks.d.ts +81 -0
- package/dist/Helpers/ChatHooks.js +175 -0
- package/dist/Helpers/ChatStore.d.ts +132 -0
- package/dist/Helpers/ChatStore.js +394 -0
- package/dist/Helpers/ChatSummaries.d.ts +39 -0
- package/dist/Helpers/ChatSummaries.js +118 -0
- package/dist/Helpers/ClassHelpers.d.ts +3 -0
- package/dist/Helpers/ClassHelpers.js +4 -0
- package/dist/Helpers/CrudBackend.d.ts +98 -0
- package/dist/Helpers/CrudBackend.js +214 -0
- package/dist/Helpers/CrudHelpers.d.ts +111 -0
- package/dist/Helpers/CrudHelpers.js +267 -0
- package/dist/Helpers/DateHelpers.d.ts +88 -0
- package/dist/Helpers/DateHelpers.js +363 -0
- package/dist/Helpers/DatePreferences.d.ts +14 -0
- package/dist/Helpers/DatePreferences.js +94 -0
- package/dist/Helpers/DateTimeHelpers.d.ts +87 -0
- package/dist/Helpers/DateTimeHelpers.js +286 -0
- package/dist/Helpers/DragHelpers.d.ts +129 -0
- package/dist/Helpers/DragHelpers.js +281 -0
- package/dist/Helpers/DropdownHelpers.d.ts +56 -0
- package/dist/Helpers/DropdownHelpers.js +180 -0
- package/dist/Helpers/ExcelBackend.d.ts +106 -0
- package/dist/Helpers/ExcelBackend.js +290 -0
- package/dist/Helpers/ExcelHelpers.d.ts +98 -0
- package/dist/Helpers/ExcelHelpers.js +302 -0
- package/dist/Helpers/FormDrafts.d.ts +18 -0
- package/dist/Helpers/FormDrafts.js +76 -0
- package/dist/Helpers/FormStore.d.ts +233 -0
- package/dist/Helpers/FormStore.js +752 -0
- package/dist/Helpers/InputParamsHelpers.d.ts +79 -0
- package/dist/Helpers/InputParamsHelpers.js +388 -0
- package/dist/Helpers/MarkdownEditing.d.ts +27 -0
- package/dist/Helpers/MarkdownEditing.js +250 -0
- package/dist/Helpers/MarkdownHelpers.d.ts +82 -0
- package/dist/Helpers/MarkdownHelpers.js +775 -0
- package/dist/Helpers/MessageBuilder.d.ts +74 -0
- package/dist/Helpers/MessageBuilder.js +252 -0
- package/dist/Helpers/NepaliCalendar.d.ts +25 -0
- package/dist/Helpers/NepaliCalendar.js +107 -0
- package/dist/Helpers/NumberHelpers.d.ts +71 -0
- package/dist/Helpers/NumberHelpers.js +202 -0
- package/dist/Helpers/Permissions.d.ts +62 -0
- package/dist/Helpers/Permissions.js +133 -0
- package/dist/Helpers/PopoverHelpers.d.ts +68 -0
- package/dist/Helpers/PopoverHelpers.js +195 -0
- package/dist/Helpers/RichTextHelpers.d.ts +77 -0
- package/dist/Helpers/RichTextHelpers.js +1072 -0
- package/dist/Helpers/RowsStore.d.ts +166 -0
- package/dist/Helpers/RowsStore.js +606 -0
- package/dist/Helpers/TableColumns.d.ts +47 -0
- package/dist/Helpers/TableColumns.js +282 -0
- package/dist/Helpers/TableExport.d.ts +30 -0
- package/dist/Helpers/TableExport.js +97 -0
- package/dist/Helpers/TableHelpers.d.ts +110 -0
- package/dist/Helpers/TableHelpers.js +301 -0
- package/dist/Helpers/TableStore.d.ts +142 -0
- package/dist/Helpers/TableStore.js +530 -0
- package/dist/Helpers/ThemeHelpers.d.ts +15 -0
- package/dist/Helpers/ThemeHelpers.js +16 -0
- package/dist/Helpers/TimeHelpers.d.ts +73 -0
- package/dist/Helpers/TimeHelpers.js +253 -0
- package/dist/Helpers/TreeStore.d.ts +188 -0
- package/dist/Helpers/TreeStore.js +577 -0
- package/dist/Helpers/ValidationHelpers.d.ts +124 -0
- package/dist/Helpers/ValidationHelpers.js +301 -0
- package/dist/Interfaces/ApiInterfaces.d.ts +174 -0
- package/dist/Interfaces/ApiInterfaces.js +30 -0
- package/dist/Interfaces/ChatInterfaces.d.ts +240 -0
- package/{src/sso-client.tsx → dist/Interfaces/ChatInterfaces.js} +1 -1
- package/dist/Interfaces/CrudInterfaces.d.ts +232 -0
- package/dist/Interfaces/CrudInterfaces.js +1 -0
- package/dist/Interfaces/DateInterfaces.d.ts +154 -0
- package/dist/Interfaces/DateInterfaces.js +29 -0
- package/dist/Interfaces/ExcelInterfaces.d.ts +215 -0
- package/dist/Interfaces/ExcelInterfaces.js +45 -0
- package/dist/Interfaces/FormInterfaces.d.ts +402 -0
- package/dist/Interfaces/FormInterfaces.js +1 -0
- package/dist/Interfaces/InputInterfaces.d.ts +141 -0
- package/dist/Interfaces/InputInterfaces.js +1 -0
- package/dist/Interfaces/MessageInterfaces.d.ts +111 -0
- package/dist/Interfaces/MessageInterfaces.js +5 -0
- package/dist/Interfaces/TableInterfaces.d.ts +351 -0
- package/dist/Interfaces/TableInterfaces.js +1 -0
- package/dist/Interfaces/ThemeInterfaces.d.ts +17 -0
- package/dist/Interfaces/ThemeInterfaces.js +17 -0
- package/dist/Interfaces/TypeInterfaces.d.ts +4 -0
- package/dist/Interfaces/TypeInterfaces.js +1 -0
- package/dist/Server.Index.d.ts +2 -0
- package/dist/Server.Index.js +5 -0
- package/dist/Services/ApiProxy.d.ts +32 -0
- package/dist/Services/ApiProxy.js +111 -0
- package/dist/Services/BrowserApi.d.ts +95 -0
- package/dist/Services/BrowserApi.js +129 -0
- package/dist/Services/ChatApi.d.ts +37 -0
- package/dist/Services/ChatApi.js +98 -0
- package/dist/Services/ExcelApi.d.ts +46 -0
- package/dist/Services/ExcelApi.js +196 -0
- package/dist/Services/ServerApi.d.ts +54 -0
- package/dist/Services/ServerApi.js +78 -0
- package/dist/Services/ThemeService.d.ts +17 -0
- package/dist/Services/ThemeService.js +83 -0
- package/dist/Shared.Index.d.ts +51 -0
- package/dist/Shared.Index.js +55 -0
- package/package.json +85 -33
- package/src/Styles/Nexus.Base.css +70 -0
- package/src/Styles/Nexus.Button.css +153 -0
- package/src/Styles/Nexus.Calendar.css +275 -0
- package/src/Styles/Nexus.Chat.css +1489 -0
- package/src/Styles/Nexus.Choice.css +345 -0
- package/src/Styles/Nexus.Crud.css +161 -0
- package/src/Styles/Nexus.DateTime.css +81 -0
- package/src/Styles/Nexus.Dropdown.css +774 -0
- package/src/Styles/Nexus.Editor.css +297 -0
- package/src/Styles/Nexus.Excel.css +370 -0
- package/src/Styles/Nexus.Form.css +321 -0
- package/src/Styles/Nexus.Index.css +36 -0
- package/src/Styles/Nexus.Input.css +637 -0
- package/src/Styles/Nexus.Markdown.css +265 -0
- package/src/Styles/Nexus.Menu.css +259 -0
- package/src/Styles/Nexus.Popup.css +731 -0
- package/src/Styles/Nexus.RichText.css +463 -0
- package/src/Styles/Nexus.Rows.css +596 -0
- package/src/Styles/Nexus.Slider.css +278 -0
- package/src/Styles/Nexus.Tab.Buttons.css +419 -0
- package/src/Styles/Nexus.Table.css +1296 -0
- package/src/Styles/Nexus.Theme.Picker.css +232 -0
- package/src/Styles/Nexus.Themes.css +194 -0
- package/src/Styles/Nexus.Time.css +147 -0
- package/src/Styles/Nexus.Toast.css +265 -0
- package/src/Styles/Nexus.Tokens.css +72 -0
- package/src/Styles/Nexus.Tree.css +435 -0
- package/src/api-services/authentication-service.tsx +0 -23
- package/src/api-services/preference-service.tsx +0 -5
- package/src/api-services/system-service.tsx +0 -29
- package/src/client.ts +0 -31
- package/src/components/documents/button.tsx +0 -133
- package/src/components/documents/icon-box.tsx +0 -93
- package/src/components/documents/page-title.tsx +0 -7
- package/src/components/documents/tab-button.tsx +0 -172
- package/src/components/documents/tag.tsx +0 -30
- package/src/components/index.js +0 -0
- package/src/components/inputs/checkbox-input.tsx +0 -66
- package/src/components/inputs/input-box.tsx +0 -48
- package/src/components/inputs/input-element.tsx +0 -65
- package/src/components/inputs/input-form.tsx +0 -164
- package/src/components/inputs/input.tsx +0 -181
- package/src/components/inputs/number-input.tsx +0 -108
- package/src/components/inputs/radiobox-input.tsx +0 -53
- package/src/components/inputs/textarea-input.tsx +0 -47
- package/src/components/inputs/textbox-input.tsx +0 -45
- package/src/components/layouts/global-dialogbox.tsx +0 -431
- package/src/components/layouts/global-layout.tsx +0 -64
- package/src/components/layouts/layout-helpers.tsx +0 -20
- package/src/components/layouts/panels/user-panel.tsx +0 -112
- package/src/components/layouts/utility-menu.tsx +0 -49
- package/src/components/panels/theme-panel.tsx +0 -46
- package/src/helpers/bitwise-helpers.tsx +0 -11
- package/src/helpers/browser-helpers.tsx +0 -156
- package/src/helpers/datasource-helpers.tsx +0 -99
- package/src/helpers/element-helpers.tsx +0 -123
- package/src/helpers/input-helpers.tsx +0 -74
- package/src/helpers/string-helpers.tsx +0 -28
- package/src/helpers/utility-helpers.tsx +0 -45
- package/src/helpers/validation-helpers.tsx +0 -302
- package/src/index.ts +0 -26
- package/src/interface.ts +0 -19
- package/src/interfaces/auth-token-interfaces.tsx +0 -6
- package/src/interfaces/browser-interfaces.tsx +0 -36
- package/src/interfaces/button-interfaces.tsx +0 -63
- package/src/interfaces/datasource-interfaces.tsx +0 -22
- package/src/interfaces/datatable-interfaces.tsx +0 -25
- package/src/interfaces/dialogbox-interfaces.tsx +0 -5
- package/src/interfaces/exception-interfaces.tsx +0 -99
- package/src/interfaces/http-interfaces.tsx +0 -129
- package/src/interfaces/icon-interfaces.tsx +0 -129
- package/src/interfaces/input-interfaces.tsx +0 -410
- package/src/interfaces/layout-interfaces.tsx +0 -191
- package/src/interfaces/menu-interfaces.tsx +0 -53
- package/src/interfaces/message-interfaces.tsx +0 -32
- package/src/interfaces/permission-interfaces.tsx +0 -9
- package/src/interfaces/storage-interfaces.tsx +0 -5
- package/src/interfaces/system-interfaces.tsx +0 -22
- package/src/interfaces/theme-interfaces.tsx +0 -123
- package/src/interfaces/type-interfaces.tsx +0 -28
- package/src/interfaces/user-interfaces.tsx +0 -47
- package/src/nexus-client.tsx +0 -21
- package/src/nexus.environments.tsx +0 -66
- package/src/proxy-api/proxy-backend.tsx +0 -60
- package/src/proxy-api/proxy-constants.tsx +0 -28
- package/src/proxy-api/proxy-helpers.tsx +0 -91
- package/src/proxy-api-client.tsx +0 -1
- package/src/proxy-api-server.tsx +0 -2
- package/src/services/http-client-services.tsx +0 -75
- package/src/services/http-services.tsx +0 -158
- package/src/services/loader-service.tsx +0 -185
- package/src/services/localstorage-service.tsx +0 -119
- package/src/services/message-services.tsx +0 -383
- package/src/services/theme-service.tsx +0 -163
- package/src/services/user-services.tsx +0 -10
- package/src/sso-config/auth-token-validation.ts +0 -16
- package/src/sso-config/callback-route.tsx +0 -35
- package/src/sso-config/cookie-encryption.ts +0 -51
- package/src/sso-config/cookie-helpers.tsx +0 -102
- package/src/sso-config/forgot-password-route.tsx +0 -36
- package/src/sso-config/oauth-callback-state.ts +0 -61
- package/src/sso-config/pkce-helpers.ts +0 -9
- package/src/sso-config/provider-complete-route.tsx +0 -18
- package/src/sso-config/redirect-context-actions.tsx +0 -45
- package/src/sso-config/redirect-context-helpers.tsx +0 -159
- package/src/sso-config/redirect-context-persist.tsx +0 -18
- package/src/sso-config/redirect-context-route.tsx +0 -45
- package/src/sso-config/refresh-route.tsx +0 -23
- package/src/sso-config/sign-in-route.tsx +0 -74
- package/src/sso-config/sign-out-route.tsx +0 -57
- package/src/sso-config/sign-up-route.tsx +0 -57
- package/src/sso-config/sso-backend-flow.ts +0 -38
- package/src/sso-config/sso-complete-route.tsx +0 -50
- package/src/sso-config/sso-config.ts +0 -59
- package/src/sso-config/sso-interfaces.tsx +0 -99
- package/src/sso-config/sso-response-helpers.tsx +0 -20
- package/src/sso-server.tsx +0 -21
- package/src/styles/nexus.animation.css +0 -269
- package/src/styles/nexus.core.css +0 -119
- package/src/styles/nexus.dialog.css +0 -144
- package/src/styles/nexus.grid-view.css +0 -42
- package/src/styles/nexus.icon.css +0 -51
- package/src/styles/nexus.input.css +0 -207
- package/src/styles/nexus.loader.css +0 -11
- package/src/styles/nexus.logic.css +0 -47
- package/src/styles/nexus.utility.css +0 -347
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Editing commands for Markdown text: the toolbar buttons and shortcuts of MarkdownEditor, list continuation on Enter,
|
|
3
|
+
* ticking a task, and turning a pasted URL into a link. Each takes the text and the selection and returns a single
|
|
4
|
+
* replacement, with no DOM, so a custom editor or a test can use them as well.
|
|
5
|
+
*/
|
|
6
|
+
/** A starter table: three columns, a header, and one row. */
|
|
7
|
+
export const MARKDOWN_TABLE = "| Column | Column | Column |\n| --- | --- | --- |\n| Text | Text | Text |";
|
|
8
|
+
/**
|
|
9
|
+
* The edit for a toolbar button. Inline marks (bold, italic, strikethrough, code) wrap the selection or the word at the
|
|
10
|
+
* caret, or remove the marks when they are already there. Line marks (quote, lists) apply to every selected line and
|
|
11
|
+
* come off when every line has them. Blocks (table, horizontal line) go on their own lines after the selection.
|
|
12
|
+
*/
|
|
13
|
+
export function applyMarkdownTool(value, selectionStart, selectionEnd, tool) {
|
|
14
|
+
const start = Math.min(selectionStart, selectionEnd);
|
|
15
|
+
const end = Math.max(selectionStart, selectionEnd);
|
|
16
|
+
switch (tool) {
|
|
17
|
+
case "bold":
|
|
18
|
+
return toggleWrap(value, start, end, "**", "bold text");
|
|
19
|
+
case "italic":
|
|
20
|
+
return toggleWrap(value, start, end, "_", "italic text");
|
|
21
|
+
case "strikethrough":
|
|
22
|
+
return toggleWrap(value, start, end, "~~", "text");
|
|
23
|
+
case "code":
|
|
24
|
+
return value.slice(start, end).includes("\n") ? toggleCodeBlock(value, start, end) : toggleWrap(value, start, end, "`", "code");
|
|
25
|
+
case "link":
|
|
26
|
+
case "image":
|
|
27
|
+
return insertLink(value, start, end, tool === "image");
|
|
28
|
+
case "heading":
|
|
29
|
+
return cycleHeading(value, start, end);
|
|
30
|
+
case "quote":
|
|
31
|
+
case "bulletList":
|
|
32
|
+
case "numberedList":
|
|
33
|
+
case "taskList":
|
|
34
|
+
return toggleLinePrefix(value, start, end, tool);
|
|
35
|
+
case "codeBlock":
|
|
36
|
+
return toggleCodeBlock(value, start, end);
|
|
37
|
+
case "table":
|
|
38
|
+
// Selects the first header, ready to type over.
|
|
39
|
+
return insertBlock(value, start, end, MARKDOWN_TABLE, [2, 8]);
|
|
40
|
+
case "rule":
|
|
41
|
+
return insertBlock(value, start, end, "---");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The edit for Enter at the end of a list item: a new item with the same indent and marker, the next number, and an
|
|
46
|
+
* empty box for a task. Enter on an empty item ends the list instead. `null` when Enter should just break the line.
|
|
47
|
+
*/
|
|
48
|
+
export function continueMarkdownList(value, selectionStart, selectionEnd) {
|
|
49
|
+
if (selectionStart !== selectionEnd)
|
|
50
|
+
return null;
|
|
51
|
+
const from = lineStartAt(value, selectionStart);
|
|
52
|
+
const to = lineEndAt(value, selectionStart);
|
|
53
|
+
const line = value.slice(from, to);
|
|
54
|
+
const match = /^([ \t]*)(?:([-+*])|(\d{1,9})([.)]))([ \t]+)(\[[ xX]\](?:[ \t]+|$))?/.exec(line);
|
|
55
|
+
if (!match || RULE.test(line) || selectionStart - from < match[0].length)
|
|
56
|
+
return null;
|
|
57
|
+
if (!line.slice(match[0].length).trim()) {
|
|
58
|
+
return { start: from, end: to, text: "", selectionStart: from, selectionEnd: from };
|
|
59
|
+
}
|
|
60
|
+
const [, indent = "", bullet, number, delimiter = ".", space = " ", task] = match;
|
|
61
|
+
const text = `\n${indent}${bullet ?? `${Number(number) + 1}${delimiter}`}${space}${task ? "[ ] " : ""}`;
|
|
62
|
+
return { start: selectionStart, end: selectionStart, text, selectionStart: selectionStart + text.length, selectionEnd: selectionStart + text.length };
|
|
63
|
+
}
|
|
64
|
+
/** The edit that ticks or clears the task whose marker is on `line` (from 0), as `MarkdownListItem.line` gives it. */
|
|
65
|
+
export function toggleMarkdownTask(value, line, checked) {
|
|
66
|
+
let from = 0;
|
|
67
|
+
for (let n = 0; n < line; n++) {
|
|
68
|
+
const next = value.indexOf("\n", from);
|
|
69
|
+
if (next < 0)
|
|
70
|
+
return null;
|
|
71
|
+
from = next + 1;
|
|
72
|
+
}
|
|
73
|
+
const match = /^((?:[ \t]*>)*[ \t]*(?:[-+*]|\d{1,9}[.)])[ \t]+\[)[ xX]\]/.exec(value.slice(from, lineEndAt(value, from)));
|
|
74
|
+
if (!match)
|
|
75
|
+
return null;
|
|
76
|
+
const at = from + match[1].length;
|
|
77
|
+
return { start: at, end: at + 1, text: checked ? "x" : " " };
|
|
78
|
+
}
|
|
79
|
+
/** The edit that turns selected text into a link when a URL is pasted over it. `null` for any other paste. */
|
|
80
|
+
export function linkPastedUrl(value, selectionStart, selectionEnd, pasted) {
|
|
81
|
+
const url = pasted.trim();
|
|
82
|
+
const selected = value.slice(selectionStart, selectionEnd);
|
|
83
|
+
if (!selected.trim() || selected.includes("\n") || !/^https?:\/\/\S+$/.test(url) || /^\s*(?:https?:\/\/|www\.)/.test(selected))
|
|
84
|
+
return null;
|
|
85
|
+
const text = `[${selected}](${url})`;
|
|
86
|
+
return { start: selectionStart, end: selectionEnd, text, selectionStart: selectionStart + text.length, selectionEnd: selectionStart + text.length };
|
|
87
|
+
}
|
|
88
|
+
const RULE = /^ {0,3}(?:(?:\*[ \t]*){3,}|(?:-[ \t]*){3,}|(?:_[ \t]*){3,})$/;
|
|
89
|
+
const WORD = /[\p{L}\p{N}\p{M}]/u;
|
|
90
|
+
const LINE_PREFIX = {
|
|
91
|
+
quote: /^([ \t]*)> ?/,
|
|
92
|
+
bulletList: /^([ \t]*)[-+*][ \t]+(?!\[[ xX]\](?:[ \t]|$))/,
|
|
93
|
+
numberedList: /^([ \t]*)\d{1,9}[.)][ \t]+/,
|
|
94
|
+
taskList: /^([ \t]*)[-+*][ \t]+\[[ xX]\](?:[ \t]+|$)/,
|
|
95
|
+
};
|
|
96
|
+
const ANY_LIST_PREFIX = /^([ \t]*)(?:[-+*]|\d{1,9}[.)])[ \t]+(?:\[[ xX]\](?:[ \t]+|$))?/;
|
|
97
|
+
function toggleWrap(value, start, end, marker, placeholder) {
|
|
98
|
+
const size = marker.length;
|
|
99
|
+
const selected = value.slice(start, end);
|
|
100
|
+
// The marks sit just outside the selection, or the selection includes them: take them off.
|
|
101
|
+
if (start >= size && value.slice(start - size, start) === marker && value.slice(end, end + size) === marker) {
|
|
102
|
+
return { start: start - size, end: end + size, text: selected, selectionStart: start - size, selectionEnd: end - size };
|
|
103
|
+
}
|
|
104
|
+
if (selected.length >= 2 * size && selected.startsWith(marker) && selected.endsWith(marker)) {
|
|
105
|
+
const inner = selected.slice(size, -size);
|
|
106
|
+
return { start, end, text: inner, selectionStart: start, selectionEnd: start + inner.length };
|
|
107
|
+
}
|
|
108
|
+
if (!selected.trim()) {
|
|
109
|
+
// A caret inside a word marks the word; anywhere else, a placeholder to type over.
|
|
110
|
+
const word = start === end ? wordAround(value, start) : null;
|
|
111
|
+
if (word) {
|
|
112
|
+
const text = marker + value.slice(word.start, word.end) + marker;
|
|
113
|
+
return { start: word.start, end: word.end, text, selectionStart: start + size, selectionEnd: start + size };
|
|
114
|
+
}
|
|
115
|
+
return { start: end, end, text: marker + placeholder + marker, selectionStart: end + size, selectionEnd: end + size + placeholder.length };
|
|
116
|
+
}
|
|
117
|
+
// Marks cannot span lines, so each line gets its own. Spaces at the edges stay outside them.
|
|
118
|
+
const text = selected
|
|
119
|
+
.split("\n")
|
|
120
|
+
.map(line => {
|
|
121
|
+
const core = line.trim();
|
|
122
|
+
if (!core)
|
|
123
|
+
return line;
|
|
124
|
+
const lead = line.indexOf(core);
|
|
125
|
+
return line.slice(0, lead) + marker + core + marker + line.slice(lead + core.length);
|
|
126
|
+
})
|
|
127
|
+
.join("\n");
|
|
128
|
+
if (selected.includes("\n"))
|
|
129
|
+
return { start, end, text, selectionStart: start, selectionEnd: start + text.length };
|
|
130
|
+
const lead = selected.indexOf(selected.trim());
|
|
131
|
+
return { start, end, text, selectionStart: start + lead + size, selectionEnd: start + lead + size + selected.trim().length };
|
|
132
|
+
}
|
|
133
|
+
function toggleLinePrefix(value, start, end, tool) {
|
|
134
|
+
const { from, to, lines } = selectedLines(value, start, end);
|
|
135
|
+
const pattern = LINE_PREFIX[tool];
|
|
136
|
+
const filled = lines.filter(line => line.trim());
|
|
137
|
+
const remove = filled.length > 0 && filled.every(line => pattern.test(line));
|
|
138
|
+
let number = 0;
|
|
139
|
+
const prefixLengths = [];
|
|
140
|
+
const next = lines.map(line => {
|
|
141
|
+
if (!line.trim() && lines.length > 1) {
|
|
142
|
+
prefixLengths.push(0);
|
|
143
|
+
return line;
|
|
144
|
+
}
|
|
145
|
+
// A list replaces any other list marker on the line, so a bulleted list becomes a numbered one in one click.
|
|
146
|
+
const current = remove ? pattern.exec(line) : tool === "quote" ? null : ANY_LIST_PREFIX.exec(line);
|
|
147
|
+
const indent = current?.[1] ?? (tool === "quote" ? "" : /^[ \t]*/.exec(line)[0]);
|
|
148
|
+
number++;
|
|
149
|
+
const marker = remove ? "" : tool === "quote" ? "> " : tool === "numberedList" ? `${number}. ` : tool === "taskList" ? "- [ ] " : "- ";
|
|
150
|
+
prefixLengths.push(current?.[0].length ?? indent.length);
|
|
151
|
+
return indent + marker + line.slice(current?.[0].length ?? indent.length);
|
|
152
|
+
});
|
|
153
|
+
const text = next.join("\n");
|
|
154
|
+
if (start === end && lines.length === 1) {
|
|
155
|
+
// The caret keeps its place in the line's text.
|
|
156
|
+
const oldPrefix = prefixLengths[0];
|
|
157
|
+
const newPrefix = text.length - (lines[0].length - oldPrefix);
|
|
158
|
+
const caret = from + newPrefix + Math.max(0, start - from - oldPrefix);
|
|
159
|
+
return { start: from, end: to, text, selectionStart: caret, selectionEnd: caret };
|
|
160
|
+
}
|
|
161
|
+
return { start: from, end: to, text, selectionStart: from, selectionEnd: from + text.length };
|
|
162
|
+
}
|
|
163
|
+
/** No heading, then #, ##, ###, and back to none: one button for the three sizes a page usually needs. */
|
|
164
|
+
function cycleHeading(value, start, end) {
|
|
165
|
+
const from = lineStartAt(value, start);
|
|
166
|
+
const to = lineEndAt(value, start);
|
|
167
|
+
const line = value.slice(from, to);
|
|
168
|
+
const match = /^ {0,3}(#{1,6})(?:[ \t]+|$)/.exec(line);
|
|
169
|
+
const level = match ? match[1].length : 0;
|
|
170
|
+
const prefix = level >= 3 ? "" : `${"#".repeat(level + 1)} `;
|
|
171
|
+
const text = prefix + line.slice(match ? match[0].length : 0);
|
|
172
|
+
const shift = text.length - line.length;
|
|
173
|
+
const selectionStart = Math.max(from + prefix.length, start + shift);
|
|
174
|
+
return { start: from, end: to, text, selectionStart, selectionEnd: Math.max(selectionStart, end + shift) };
|
|
175
|
+
}
|
|
176
|
+
function toggleCodeBlock(value, start, end) {
|
|
177
|
+
const { from, to, lines } = selectedLines(value, start, end);
|
|
178
|
+
// Fences right above and below the lines: take them off.
|
|
179
|
+
if (from > 0 && to < value.length) {
|
|
180
|
+
const aboveFrom = lineStartAt(value, from - 1);
|
|
181
|
+
const belowTo = lineEndAt(value, to + 1);
|
|
182
|
+
if (/^ {0,3}(?:```|~~~)/.test(value.slice(aboveFrom, from - 1)) && /^ {0,3}(?:```|~~~)[ \t]*$/.test(value.slice(to + 1, belowTo))) {
|
|
183
|
+
const inner = value.slice(from, to);
|
|
184
|
+
return { start: aboveFrom, end: belowTo, text: inner, selectionStart: aboveFrom, selectionEnd: aboveFrom + inner.length };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const inner = lines.join("\n");
|
|
188
|
+
const text = `\`\`\`\n${inner}\n\`\`\``;
|
|
189
|
+
return { start: from, end: to, text, selectionStart: from + 4, selectionEnd: from + 4 + (inner.trim() ? inner.length : 0) };
|
|
190
|
+
}
|
|
191
|
+
function insertLink(value, start, end, image) {
|
|
192
|
+
const open = image ? "})`;
|
|
198
|
+
return { start, end, text, selectionStart: start + open.length, selectionEnd: start + open.length + placeholder.length };
|
|
199
|
+
}
|
|
200
|
+
// Selected text becomes the link's text; select the address to paste over.
|
|
201
|
+
if (selected.trim() && !selected.includes("\n")) {
|
|
202
|
+
const text = `${open}${selected}](https://)`;
|
|
203
|
+
const address = start + open.length + selected.length + 2;
|
|
204
|
+
return { start, end, text, selectionStart: address, selectionEnd: address + "https://".length };
|
|
205
|
+
}
|
|
206
|
+
const text = `${open}${placeholder}](https://)`;
|
|
207
|
+
return { start: end, end, text, selectionStart: end + open.length, selectionEnd: end + open.length + placeholder.length };
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Puts a block on its own lines: in place of an empty line, or after the selected lines. Blank lines keep it apart
|
|
211
|
+
* from the text around it; without one, a line of dashes under text would make that text a heading.
|
|
212
|
+
*/
|
|
213
|
+
function insertBlock(value, start, end, block, select) {
|
|
214
|
+
const from = lineStartAt(value, start);
|
|
215
|
+
const to = lineEndAt(value, Math.max(start, end));
|
|
216
|
+
const onEmptyLine = !value.slice(from, to).trim();
|
|
217
|
+
const at = onEmptyLine ? from : to;
|
|
218
|
+
const textBefore = value.slice(0, at);
|
|
219
|
+
const textAfter = value.slice(to);
|
|
220
|
+
const before = at === 0 || textBefore.endsWith("\n\n") ? "" : textBefore.endsWith("\n") ? "\n" : "\n\n";
|
|
221
|
+
const after = textAfter.startsWith("\n\n") ? "" : "\n";
|
|
222
|
+
const blockStart = at + before.length;
|
|
223
|
+
// Without a selection inside the block, the caret goes to the line after it.
|
|
224
|
+
const [selectFrom, selectTo] = select ?? [block.length + 1, block.length + 1];
|
|
225
|
+
return { start: at, end: to, text: before + block + after, selectionStart: blockStart + selectFrom, selectionEnd: blockStart + selectTo };
|
|
226
|
+
}
|
|
227
|
+
/** The full lines a selection touches. A selection that ends at the start of a line does not touch that line. */
|
|
228
|
+
function selectedLines(value, start, end) {
|
|
229
|
+
const from = lineStartAt(value, start);
|
|
230
|
+
const to = lineEndAt(value, end > start && value[end - 1] === "\n" ? end - 1 : end);
|
|
231
|
+
return { from, to, lines: value.slice(from, to).split("\n") };
|
|
232
|
+
}
|
|
233
|
+
function lineStartAt(value, at) {
|
|
234
|
+
return at <= 0 ? 0 : value.lastIndexOf("\n", at - 1) + 1;
|
|
235
|
+
}
|
|
236
|
+
function lineEndAt(value, at) {
|
|
237
|
+
const end = value.indexOf("\n", at);
|
|
238
|
+
return end < 0 ? value.length : end;
|
|
239
|
+
}
|
|
240
|
+
function wordAround(value, at) {
|
|
241
|
+
if (!WORD.test(value[at - 1] ?? "") || !WORD.test(value[at] ?? ""))
|
|
242
|
+
return null;
|
|
243
|
+
let start = at;
|
|
244
|
+
let end = at;
|
|
245
|
+
while (start > 0 && WORD.test(value[start - 1]))
|
|
246
|
+
start--;
|
|
247
|
+
while (end < value.length && WORD.test(value[end]))
|
|
248
|
+
end++;
|
|
249
|
+
return { start, end };
|
|
250
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export type MarkdownInline = {
|
|
2
|
+
type: "text";
|
|
3
|
+
text: string;
|
|
4
|
+
} | {
|
|
5
|
+
type: "strong" | "emphasis" | "strike";
|
|
6
|
+
children: MarkdownInline[];
|
|
7
|
+
} | {
|
|
8
|
+
type: "code";
|
|
9
|
+
text: string;
|
|
10
|
+
}
|
|
11
|
+
/** `href` is `null` when the address is not safe to open, such as `javascript:`. */
|
|
12
|
+
| {
|
|
13
|
+
type: "link";
|
|
14
|
+
href: string | null;
|
|
15
|
+
title?: string;
|
|
16
|
+
children: MarkdownInline[];
|
|
17
|
+
} | {
|
|
18
|
+
type: "image";
|
|
19
|
+
src: string | null;
|
|
20
|
+
alt: string;
|
|
21
|
+
title?: string;
|
|
22
|
+
} | {
|
|
23
|
+
type: "break";
|
|
24
|
+
};
|
|
25
|
+
export type MarkdownAlign = "left" | "center" | "right" | null;
|
|
26
|
+
export interface MarkdownTableCell {
|
|
27
|
+
children: MarkdownInline[];
|
|
28
|
+
}
|
|
29
|
+
export interface MarkdownListItem {
|
|
30
|
+
/** `true` or `false` for a task (`- [x]`, `- [ ]`), `null` for any other item. */
|
|
31
|
+
checked: boolean | null;
|
|
32
|
+
/** Line of the item's marker in the source, counted from 0, so a preview can tick a task in the text. */
|
|
33
|
+
line: number;
|
|
34
|
+
children: MarkdownBlock[];
|
|
35
|
+
}
|
|
36
|
+
export type MarkdownHeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
37
|
+
export type MarkdownBlock = {
|
|
38
|
+
type: "heading";
|
|
39
|
+
level: MarkdownHeadingLevel;
|
|
40
|
+
children: MarkdownInline[];
|
|
41
|
+
} | {
|
|
42
|
+
type: "paragraph";
|
|
43
|
+
children: MarkdownInline[];
|
|
44
|
+
} | {
|
|
45
|
+
type: "code";
|
|
46
|
+
language: string;
|
|
47
|
+
text: string;
|
|
48
|
+
} | {
|
|
49
|
+
type: "quote";
|
|
50
|
+
children: MarkdownBlock[];
|
|
51
|
+
}
|
|
52
|
+
/** `tight` lists have no blank lines between their items, and show their text without paragraph spacing. */
|
|
53
|
+
| {
|
|
54
|
+
type: "list";
|
|
55
|
+
ordered: boolean;
|
|
56
|
+
start: number;
|
|
57
|
+
tight: boolean;
|
|
58
|
+
items: MarkdownListItem[];
|
|
59
|
+
} | {
|
|
60
|
+
type: "table";
|
|
61
|
+
align: MarkdownAlign[];
|
|
62
|
+
head: MarkdownTableCell[];
|
|
63
|
+
rows: MarkdownTableCell[][];
|
|
64
|
+
} | {
|
|
65
|
+
type: "rule";
|
|
66
|
+
};
|
|
67
|
+
export interface MarkdownOptions {
|
|
68
|
+
/**
|
|
69
|
+
* Every line break inside a paragraph shows as a line break, as in GitHub comments. Default true.
|
|
70
|
+
* Off: lines join into one paragraph, and only a line ending in two spaces or a backslash breaks.
|
|
71
|
+
*/
|
|
72
|
+
breaks?: boolean;
|
|
73
|
+
}
|
|
74
|
+
/** Parses Markdown into blocks for rendering. Never throws, whatever the text. */
|
|
75
|
+
export declare function parseMarkdown(markdown: string, options?: MarkdownOptions): MarkdownBlock[];
|
|
76
|
+
/** The text of Markdown without its marks, for excerpts, search, and counts. Blocks are separated by a line break. */
|
|
77
|
+
export declare function markdownToPlainText(markdown: string): string;
|
|
78
|
+
/**
|
|
79
|
+
* The address when a link or image may use it, otherwise `null`. Links allow http, https, mailto, tel, and addresses
|
|
80
|
+
* without a scheme (relative paths and #anchors); images allow http, https, relative paths, and raster data URLs.
|
|
81
|
+
*/
|
|
82
|
+
export declare function safeUrl(url: string, kind?: "link" | "image"): string | null;
|