kempo-ui 0.4.20 → 0.4.21
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 +18 -0
- package/dist/components/Chat.js +10 -10
- package/dist/components/CodeEditor.js +23 -24
- package/dist/components/ControlGroup.js +17 -0
- package/dist/components/HtmlEditor.js +105 -106
- package/dist/components/MarkdownEditor.js +49 -49
- package/dist/components/Pagination.js +11 -11
- package/dist/components/Table.js +1 -1
- package/dist/components/controls/AlignCenter.js +1 -0
- package/dist/components/controls/AlignJustify.js +1 -0
- package/dist/components/controls/AlignLeft.js +1 -0
- package/dist/components/controls/AlignRight.js +1 -0
- package/dist/components/controls/Bold.js +1 -0
- package/dist/components/controls/BulletList.js +1 -0
- package/dist/components/controls/ButtonControl.js +33 -0
- package/dist/components/controls/CharacterCount.js +4 -0
- package/dist/components/controls/ClearFormatting.js +1 -0
- package/dist/components/controls/CodeBlock.js +1 -0
- package/dist/components/controls/Control.js +12 -0
- package/dist/components/controls/CopyCode.js +1 -0
- package/dist/components/controls/CreateLink.js +1 -0
- package/dist/components/controls/EditorTheme.js +30 -0
- package/dist/components/controls/FindReplace.js +1 -0
- package/dist/components/controls/FoldAll.js +1 -0
- package/dist/components/controls/FontSize.js +8 -0
- package/dist/components/controls/FontSizeDecrease.js +1 -0
- package/dist/components/controls/FontSizeIncrease.js +1 -0
- package/dist/components/controls/FormatBlock.js +8 -0
- package/dist/components/controls/FormatCode.js +1 -0
- package/dist/components/controls/Fullscreen.js +1 -0
- package/dist/components/controls/InlineCode.js +1 -0
- package/dist/components/controls/InsertTable.js +1 -0
- package/dist/components/controls/Italic.js +1 -0
- package/dist/components/controls/Language.js +21 -0
- package/dist/components/controls/MdImage.js +23 -0
- package/dist/components/controls/MdLink.js +1 -0
- package/dist/components/controls/MdSpeechToText.js +10 -0
- package/dist/components/controls/MdTable.js +19 -0
- package/dist/components/controls/Menu.js +51 -0
- package/dist/components/controls/Minimap.js +1 -0
- package/dist/components/controls/Mode.js +1 -0
- package/dist/components/controls/NumberList.js +1 -0
- package/dist/components/controls/PgCount.js +1 -0
- package/dist/components/controls/PgFirst.js +1 -0
- package/dist/components/controls/PgGotoPage.js +15 -0
- package/dist/components/controls/PgItemsPerPage.js +12 -0
- package/dist/components/controls/PgLast.js +1 -0
- package/dist/components/controls/PgNext.js +1 -0
- package/dist/components/controls/PgPageInfo.js +3 -0
- package/dist/components/controls/PgPrev.js +1 -0
- package/dist/components/controls/Quote.js +1 -0
- package/dist/components/controls/Redo.js +1 -0
- package/dist/components/{htmlEditorControls/ControlSpacer.js → controls/Spacer.js} +5 -5
- package/dist/components/controls/Strikethrough.js +1 -0
- package/dist/components/controls/TcDeleteRecord.js +1 -0
- package/dist/components/controls/TcDeleteSelected.js +1 -0
- package/dist/components/controls/TcEdit.js +12 -0
- package/dist/components/controls/TcExportCsv.js +3 -0
- package/dist/components/controls/TcExportJson.js +3 -0
- package/dist/components/controls/TcFieldSortHide.js +21 -0
- package/dist/components/controls/TcFilters.js +34 -0
- package/dist/components/controls/TcFirstPage.js +1 -0
- package/dist/components/controls/TcHiddenCount.js +1 -0
- package/dist/components/controls/TcHide.js +1 -0
- package/dist/components/controls/TcLastPage.js +1 -0
- package/dist/components/controls/TcNextPage.js +1 -0
- package/dist/components/controls/TcPageSelect.js +9 -0
- package/dist/components/controls/TcPageSize.js +5 -0
- package/dist/components/controls/TcPrevPage.js +1 -0
- package/dist/components/controls/TcSearch.js +1 -0
- package/dist/components/controls/TcShowAll.js +1 -0
- package/dist/components/controls/TextBackgroundColor.js +26 -0
- package/dist/components/controls/TextColor.js +26 -0
- package/dist/components/controls/Underline.js +1 -0
- package/dist/components/controls/Undo.js +1 -0
- package/dist/components/controls/WordCount.js +4 -0
- package/dist/components/controls/WordWrap.js +1 -0
- package/docs/components/code-editor.html +69 -48
- package/docs/components/html-editor.html +70 -69
- package/docs/components/markdown-editor.html +59 -78
- package/docs/components/pagination.html +51 -51
- package/docs/components/tableControls.html +5 -5
- package/docs/components/tableCustomFields.html +3 -3
- package/docs/components/tableFetchRecords.html +13 -13
- package/docs/components/tableFieldSortHide.html +4 -4
- package/docs/components/tablePagination.html +13 -13
- package/docs/components/tablePlaceholder.html +3 -3
- package/docs/components/tableRecordEditing.html +4 -4
- package/docs/components/tableRecordFiltering.html +5 -5
- package/docs/components/tableRecordHiding.html +7 -7
- package/docs/components/tableRecordSearching.html +3 -3
- package/docs/components/tableRowControls.html +6 -6
- package/docs/components/tableServerSync.html +7 -7
- package/docs/src/components/Chat.js +10 -10
- package/docs/src/components/CodeEditor.js +23 -24
- package/docs/src/components/ControlGroup.js +17 -0
- package/docs/src/components/HtmlEditor.js +105 -106
- package/docs/src/components/MarkdownEditor.js +49 -49
- package/docs/src/components/Pagination.js +11 -11
- package/docs/src/components/Table.js +1 -1
- package/docs/src/components/controls/AlignCenter.js +1 -0
- package/docs/src/components/controls/AlignJustify.js +1 -0
- package/docs/src/components/controls/AlignLeft.js +1 -0
- package/docs/src/components/controls/AlignRight.js +1 -0
- package/docs/src/components/controls/Bold.js +1 -0
- package/docs/src/components/controls/BulletList.js +1 -0
- package/docs/src/components/controls/ButtonControl.js +33 -0
- package/docs/src/components/controls/CharacterCount.js +4 -0
- package/docs/src/components/controls/ClearFormatting.js +1 -0
- package/docs/src/components/controls/CodeBlock.js +1 -0
- package/docs/src/components/controls/Control.js +12 -0
- package/docs/src/components/controls/CopyCode.js +1 -0
- package/docs/src/components/controls/CreateLink.js +1 -0
- package/docs/src/components/controls/EditorTheme.js +30 -0
- package/docs/src/components/controls/FindReplace.js +1 -0
- package/docs/src/components/controls/FoldAll.js +1 -0
- package/docs/src/components/controls/FontSize.js +8 -0
- package/docs/src/components/controls/FontSizeDecrease.js +1 -0
- package/docs/src/components/controls/FontSizeIncrease.js +1 -0
- package/docs/src/components/controls/FormatBlock.js +8 -0
- package/docs/src/components/controls/FormatCode.js +1 -0
- package/docs/src/components/controls/Fullscreen.js +1 -0
- package/docs/src/components/controls/InlineCode.js +1 -0
- package/docs/src/components/controls/InsertTable.js +1 -0
- package/docs/src/components/controls/Italic.js +1 -0
- package/docs/src/components/controls/Language.js +21 -0
- package/docs/src/components/controls/MdImage.js +23 -0
- package/docs/src/components/controls/MdLink.js +1 -0
- package/docs/src/components/controls/MdSpeechToText.js +10 -0
- package/docs/src/components/controls/MdTable.js +19 -0
- package/docs/src/components/controls/Menu.js +51 -0
- package/docs/src/components/controls/Minimap.js +1 -0
- package/docs/src/components/controls/Mode.js +1 -0
- package/docs/src/components/controls/NumberList.js +1 -0
- package/docs/src/components/controls/PgCount.js +1 -0
- package/docs/src/components/controls/PgFirst.js +1 -0
- package/docs/src/components/controls/PgGotoPage.js +15 -0
- package/docs/src/components/controls/PgItemsPerPage.js +12 -0
- package/docs/src/components/controls/PgLast.js +1 -0
- package/docs/src/components/controls/PgNext.js +1 -0
- package/docs/src/components/controls/PgPageInfo.js +3 -0
- package/docs/src/components/controls/PgPrev.js +1 -0
- package/docs/src/components/controls/Quote.js +1 -0
- package/docs/src/components/controls/Redo.js +1 -0
- package/docs/src/components/{codeEditorControls/ControlSpacer.js → controls/Spacer.js} +5 -5
- package/docs/src/components/controls/Strikethrough.js +1 -0
- package/docs/src/components/controls/TcDeleteRecord.js +1 -0
- package/docs/src/components/controls/TcDeleteSelected.js +1 -0
- package/docs/src/components/controls/TcEdit.js +12 -0
- package/docs/src/components/controls/TcExportCsv.js +3 -0
- package/docs/src/components/controls/TcExportJson.js +3 -0
- package/docs/src/components/controls/TcFieldSortHide.js +21 -0
- package/docs/src/components/controls/TcFilters.js +34 -0
- package/docs/src/components/controls/TcFirstPage.js +1 -0
- package/docs/src/components/controls/TcHiddenCount.js +1 -0
- package/docs/src/components/controls/TcHide.js +1 -0
- package/docs/src/components/controls/TcLastPage.js +1 -0
- package/docs/src/components/controls/TcNextPage.js +1 -0
- package/docs/src/components/controls/TcPageSelect.js +9 -0
- package/docs/src/components/controls/TcPageSize.js +5 -0
- package/docs/src/components/controls/TcPrevPage.js +1 -0
- package/docs/src/components/controls/TcSearch.js +1 -0
- package/docs/src/components/controls/TcShowAll.js +1 -0
- package/docs/src/components/controls/TextBackgroundColor.js +26 -0
- package/docs/src/components/controls/TextColor.js +26 -0
- package/docs/src/components/controls/Underline.js +1 -0
- package/docs/src/components/controls/Undo.js +1 -0
- package/docs/src/components/controls/WordCount.js +4 -0
- package/docs/src/components/controls/WordWrap.js +1 -0
- package/docs-src/components/code-editor.page.html +69 -48
- package/docs-src/components/html-editor.page.html +70 -69
- package/docs-src/components/markdown-editor.page.html +59 -78
- package/docs-src/components/pagination.page.html +51 -51
- package/docs-src/components/tableControls.page.html +5 -5
- package/docs-src/components/tableCustomFields.page.html +3 -3
- package/docs-src/components/tableFetchRecords.page.html +13 -13
- package/docs-src/components/tableFieldSortHide.page.html +4 -4
- package/docs-src/components/tablePagination.page.html +13 -13
- package/docs-src/components/tablePlaceholder.page.html +3 -3
- package/docs-src/components/tableRecordEditing.page.html +4 -4
- package/docs-src/components/tableRecordFiltering.page.html +5 -5
- package/docs-src/components/tableRecordHiding.page.html +7 -7
- package/docs-src/components/tableRecordSearching.page.html +3 -3
- package/docs-src/components/tableRowControls.page.html +6 -6
- package/docs-src/components/tableServerSync.page.html +7 -7
- package/llms.txt +37 -3
- package/package.json +1 -1
- package/src/components/Chat.js +14 -14
- package/src/components/CodeEditor.js +26 -32
- package/src/components/{codeEditorControls/ControlGroup.js → ControlGroup.js} +10 -6
- package/src/components/HtmlEditor.js +107 -125
- package/src/components/MarkdownEditor.js +117 -59
- package/src/components/Pagination.js +18 -23
- package/src/components/Table.js +5 -0
- package/src/components/controls/AlignCenter.js +19 -0
- package/src/components/controls/AlignJustify.js +19 -0
- package/src/components/controls/AlignLeft.js +19 -0
- package/src/components/controls/AlignRight.js +19 -0
- package/src/components/controls/Bold.js +19 -0
- package/src/components/controls/BulletList.js +19 -0
- package/src/components/controls/ButtonControl.js +114 -0
- package/src/components/controls/CharacterCount.js +48 -0
- package/src/components/controls/ClearFormatting.js +19 -0
- package/src/components/controls/CodeBlock.js +27 -0
- package/src/components/controls/Control.js +176 -0
- package/src/components/controls/CopyCode.js +19 -0
- package/src/components/controls/CreateLink.js +63 -0
- package/src/components/controls/EditorTheme.js +71 -0
- package/src/components/controls/FindReplace.js +19 -0
- package/src/components/controls/FoldAll.js +35 -0
- package/src/components/controls/FontSize.js +31 -0
- package/src/components/controls/FontSizeDecrease.js +19 -0
- package/src/components/controls/FontSizeIncrease.js +19 -0
- package/src/components/controls/FormatBlock.js +64 -0
- package/src/components/controls/FormatCode.js +19 -0
- package/src/components/controls/Fullscreen.js +42 -0
- package/src/components/controls/InlineCode.js +19 -0
- package/src/components/controls/InsertTable.js +67 -0
- package/src/components/controls/Italic.js +19 -0
- package/src/components/controls/Language.js +69 -0
- package/src/components/controls/MdImage.js +72 -0
- package/src/components/controls/MdLink.js +60 -0
- package/src/components/controls/MdSpeechToText.js +46 -0
- package/src/components/controls/MdTable.js +79 -0
- package/src/components/controls/Menu.js +98 -0
- package/src/components/controls/Minimap.js +36 -0
- package/src/components/controls/Mode.js +30 -0
- package/src/components/controls/NumberList.js +19 -0
- package/src/components/controls/PgCount.js +12 -0
- package/src/components/controls/PgFirst.js +28 -0
- package/src/components/controls/PgGotoPage.js +48 -0
- package/src/components/controls/PgItemsPerPage.js +36 -0
- package/src/components/controls/PgLast.js +28 -0
- package/src/components/controls/PgNext.js +25 -0
- package/src/components/controls/PgPageInfo.js +22 -0
- package/src/components/controls/PgPrev.js +25 -0
- package/src/components/controls/Quote.js +19 -0
- package/src/components/controls/Redo.js +18 -0
- package/src/components/controls/Spacer.js +15 -0
- package/src/components/controls/Strikethrough.js +19 -0
- package/src/components/controls/TcDeleteRecord.js +30 -0
- package/src/components/controls/TcDeleteSelected.js +16 -0
- package/src/components/controls/TcEdit.js +73 -0
- package/src/components/controls/TcExportCsv.js +60 -0
- package/src/components/controls/TcExportJson.js +46 -0
- package/src/components/controls/TcFieldSortHide.js +56 -0
- package/src/components/controls/TcFilters.js +86 -0
- package/src/components/controls/TcFirstPage.js +24 -0
- package/src/components/controls/TcHiddenCount.js +39 -0
- package/src/components/controls/TcHide.js +30 -0
- package/src/components/controls/TcLastPage.js +24 -0
- package/src/components/controls/TcNextPage.js +24 -0
- package/src/components/controls/TcPageSelect.js +36 -0
- package/src/components/controls/TcPageSize.js +23 -0
- package/src/components/controls/TcPrevPage.js +24 -0
- package/src/components/controls/TcSearch.js +34 -0
- package/src/components/controls/TcShowAll.js +18 -0
- package/src/components/controls/TextBackgroundColor.js +84 -0
- package/src/components/controls/TextColor.js +84 -0
- package/src/components/controls/Underline.js +19 -0
- package/src/components/controls/Undo.js +18 -0
- package/src/components/controls/WordCount.js +48 -0
- package/src/components/controls/WordWrap.js +36 -0
- package/tasks/released/0007-code-editor-updates/branch-custom-controls.png +0 -0
- package/tasks/released/0007-code-editor-updates/branch-toolbar.png +0 -0
- package/tasks/released/0007-code-editor-updates/docs-overview.png +0 -0
- package/tasks/released/0007-code-editor-updates/form-integration.png +0 -0
- package/tasks/released/0007-code-editor-updates/live-builtin-controls.png +0 -0
- package/tasks/released/0007-code-editor-updates/live-custom-controls.png +0 -0
- package/tasks/released/0007-code-editor-updates/live-toolbar.png +0 -0
- package/tasks/released/0007-code-editor-updates/local-builtin-controls.png +0 -0
- package/tasks/released/0007-code-editor-updates/local-fixed-builtin.png +0 -0
- package/tasks/released/0007-code-editor-updates/theme-selector.png +0 -0
- package/tasks/released/0007-code-editor-updates.md +96 -0
- package/tests/components/CodeEditor.browser-test.js +0 -42
- package/tests/components/HtmlEditor.browser-test.js +0 -88
- package/tests/components/MarkdownEditor.browser-test.js +0 -72
- package/tests/components/Pagination.browser-test.js +12 -90
- package/tests/components/{htmlEditorControls → controls}/Align.browser-test.js +16 -16
- package/tests/components/{htmlEditorControls → controls}/Bold.browser-test.js +7 -7
- package/tests/components/{htmlEditorControls → controls}/BulletList.browser-test.js +7 -7
- package/tests/components/{htmlEditorControls → controls}/CharacterCount.browser-test.js +5 -5
- package/tests/components/{htmlEditorControls → controls}/ClearFormatting.browser-test.js +7 -7
- package/tests/components/{htmlEditorControls → controls}/CodeBlock.browser-test.js +8 -8
- package/tests/components/controls/Control.browser-test.js +147 -0
- package/tests/components/{htmlEditorControls → controls}/ControlGroup.browser-test.js +9 -9
- package/tests/components/{htmlEditorControls → controls}/ControlSpacer.browser-test.js +4 -4
- package/tests/components/{codeEditorControls → controls}/CopyCode.browser-test.js +8 -8
- package/tests/components/{htmlEditorControls → controls}/CreateLink.browser-test.js +7 -7
- package/tests/components/{htmlEditorControls → controls}/DropdownControl.browser-test.js +8 -8
- package/tests/components/{codeEditorControls → controls}/EditorTheme.browser-test.js +4 -4
- package/tests/components/{tableControls → controls}/ExportControls.browser-test.js +22 -46
- package/tests/components/{tableControls → controls}/FieldSortHide.browser-test.js +14 -26
- package/tests/components/{tableControls → controls}/Filters.browser-test.js +15 -27
- package/tests/components/{codeEditorControls → controls}/FindReplace.browser-test.js +8 -8
- package/tests/components/{codeEditorControls → controls}/FoldAll.browser-test.js +10 -10
- package/tests/components/{codeEditorControls → controls}/FontSize.browser-test.js +19 -14
- package/tests/components/{htmlEditorControls → controls}/FormatBlock.browser-test.js +9 -9
- package/tests/components/{htmlEditorControls → controls}/FormatCode.browser-test.js +17 -18
- package/tests/components/{codeEditorControls → controls}/Fullscreen.browser-test.js +11 -32
- package/tests/components/{tableControls → controls}/HiddenCount.browser-test.js +4 -4
- package/tests/components/{htmlEditorControls → controls}/InlineCode.browser-test.js +7 -7
- package/tests/components/{htmlEditorControls → controls}/InsertTable.browser-test.js +7 -7
- package/tests/components/{htmlEditorControls → controls}/Italic.browser-test.js +7 -7
- package/tests/components/{codeEditorControls → controls}/LanguageSelect.browser-test.js +4 -4
- package/tests/components/{codeEditorControls → controls}/Minimap.browser-test.js +8 -8
- package/tests/components/{htmlEditorControls → controls}/Mode.browser-test.js +7 -7
- package/tests/components/{codeEditorControls → controls}/ModeVisibility.browser-test.js +7 -7
- package/tests/components/{htmlEditorControls → controls}/NumberList.browser-test.js +7 -7
- package/tests/components/{tableControls → controls}/PaginationControls.browser-test.js +45 -45
- package/tests/components/{tableControls → controls}/RecordControls.browser-test.js +24 -60
- package/tests/components/{tableControls → controls}/Search.browser-test.js +4 -16
- package/tests/components/{htmlEditorControls → controls}/Strikethrough.browser-test.js +7 -7
- package/tests/components/{htmlEditorControls → controls}/TextBackgroundColor.browser-test.js +5 -5
- package/tests/components/{htmlEditorControls → controls}/TextColor.browser-test.js +5 -5
- package/tests/components/{htmlEditorControls → controls}/Underline.browser-test.js +7 -7
- package/tests/components/{codeEditorControls → controls}/UndoRedo.browser-test.js +15 -15
- package/tests/components/{htmlEditorControls → controls}/WordCount.browser-test.js +5 -5
- package/tests/components/{codeEditorControls → controls}/WordWrap.browser-test.js +8 -8
- package/dist/components/codeEditorControls/CodeEditorControl.js +0 -17
- package/dist/components/codeEditorControls/ControlGroup.js +0 -12
- package/dist/components/codeEditorControls/ControlSpacer.js +0 -6
- package/dist/components/codeEditorControls/CopyCode.js +0 -9
- package/dist/components/codeEditorControls/EditorTheme.js +0 -26
- package/dist/components/codeEditorControls/FindReplace.js +0 -7
- package/dist/components/codeEditorControls/FoldAll.js +0 -7
- package/dist/components/codeEditorControls/FontSize.js +0 -13
- package/dist/components/codeEditorControls/FormatCode.js +0 -9
- package/dist/components/codeEditorControls/Fullscreen.js +0 -12
- package/dist/components/codeEditorControls/LanguageSelect.js +0 -15
- package/dist/components/codeEditorControls/Minimap.js +0 -8
- package/dist/components/codeEditorControls/Redo.js +0 -7
- package/dist/components/codeEditorControls/Undo.js +0 -7
- package/dist/components/codeEditorControls/WordWrap.js +0 -8
- package/dist/components/htmlEditorControls/AlignCenter.js +0 -12
- package/dist/components/htmlEditorControls/AlignJustify.js +0 -12
- package/dist/components/htmlEditorControls/AlignLeft.js +0 -12
- package/dist/components/htmlEditorControls/AlignRight.js +0 -12
- package/dist/components/htmlEditorControls/Bold.js +0 -12
- package/dist/components/htmlEditorControls/BulletList.js +0 -12
- package/dist/components/htmlEditorControls/CharacterCount.js +0 -18
- package/dist/components/htmlEditorControls/ClearFormatting.js +0 -12
- package/dist/components/htmlEditorControls/CodeBlock.js +0 -12
- package/dist/components/htmlEditorControls/ControlGroup.js +0 -12
- package/dist/components/htmlEditorControls/CreateLink.js +0 -15
- package/dist/components/htmlEditorControls/DropdownControl.js +0 -57
- package/dist/components/htmlEditorControls/FormatBlock.js +0 -12
- package/dist/components/htmlEditorControls/FormatCode.js +0 -1
- package/dist/components/htmlEditorControls/HtmlEditorControl.js +0 -44
- package/dist/components/htmlEditorControls/InlineCode.js +0 -12
- package/dist/components/htmlEditorControls/InsertTable.js +0 -15
- package/dist/components/htmlEditorControls/Italic.js +0 -12
- package/dist/components/htmlEditorControls/Mode.js +0 -9
- package/dist/components/htmlEditorControls/NumberList.js +0 -12
- package/dist/components/htmlEditorControls/Strikethrough.js +0 -12
- package/dist/components/htmlEditorControls/TextBackgroundColor.js +0 -97
- package/dist/components/htmlEditorControls/TextColor.js +0 -97
- package/dist/components/htmlEditorControls/Underline.js +0 -12
- package/dist/components/htmlEditorControls/WordCount.js +0 -18
- package/dist/components/markdownEditorControls/Bold.js +0 -11
- package/dist/components/markdownEditorControls/BulletList.js +0 -11
- package/dist/components/markdownEditorControls/Code.js +0 -11
- package/dist/components/markdownEditorControls/FormatBlock.js +0 -30
- package/dist/components/markdownEditorControls/Heading.js +0 -11
- package/dist/components/markdownEditorControls/Image.js +0 -93
- package/dist/components/markdownEditorControls/Italic.js +0 -11
- package/dist/components/markdownEditorControls/Link.js +0 -11
- package/dist/components/markdownEditorControls/MarkdownEditorControl.js +0 -39
- package/dist/components/markdownEditorControls/Menu.js +0 -30
- package/dist/components/markdownEditorControls/NumberedList.js +0 -11
- package/dist/components/markdownEditorControls/Quote.js +0 -11
- package/dist/components/markdownEditorControls/SpeechToText.js +0 -16
- package/dist/components/markdownEditorControls/Strikethrough.js +0 -11
- package/dist/components/markdownEditorControls/Table.js +0 -80
- package/dist/components/paginationControls/FirstPage.js +0 -1
- package/dist/components/paginationControls/GotoPage.js +0 -17
- package/dist/components/paginationControls/ItemsPerPage.js +0 -15
- package/dist/components/paginationControls/LastPage.js +0 -1
- package/dist/components/paginationControls/NextPage.js +0 -1
- package/dist/components/paginationControls/PageCount.js +0 -1
- package/dist/components/paginationControls/PageInfo.js +0 -6
- package/dist/components/paginationControls/PaginationButtonControl.js +0 -20
- package/dist/components/paginationControls/PaginationControl.js +0 -5
- package/dist/components/paginationControls/PrevPage.js +0 -1
- package/dist/components/tableControls/DeleteRecord.js +0 -7
- package/dist/components/tableControls/DeleteSelected.js +0 -7
- package/dist/components/tableControls/Edit.js +0 -18
- package/dist/components/tableControls/ExportCSV.js +0 -8
- package/dist/components/tableControls/ExportJson.js +0 -8
- package/dist/components/tableControls/FieldSortHide.js +0 -25
- package/dist/components/tableControls/Filters.js +0 -46
- package/dist/components/tableControls/FirstPage.js +0 -9
- package/dist/components/tableControls/HiddenCount.js +0 -3
- package/dist/components/tableControls/Hide.js +0 -5
- package/dist/components/tableControls/LastPage.js +0 -9
- package/dist/components/tableControls/NextPage.js +0 -9
- package/dist/components/tableControls/PageSelect.js +0 -22
- package/dist/components/tableControls/PageSize.js +0 -5
- package/dist/components/tableControls/PrevPage.js +0 -9
- package/dist/components/tableControls/Search.js +0 -9
- package/dist/components/tableControls/ShowAll.js +0 -5
- package/dist/components/tableControls/TableControl.js +0 -16
- package/docs/src/components/codeEditorControls/CodeEditorControl.js +0 -17
- package/docs/src/components/codeEditorControls/ControlGroup.js +0 -12
- package/docs/src/components/codeEditorControls/CopyCode.js +0 -9
- package/docs/src/components/codeEditorControls/EditorTheme.js +0 -26
- package/docs/src/components/codeEditorControls/FindReplace.js +0 -7
- package/docs/src/components/codeEditorControls/FoldAll.js +0 -7
- package/docs/src/components/codeEditorControls/FontSize.js +0 -13
- package/docs/src/components/codeEditorControls/FormatCode.js +0 -9
- package/docs/src/components/codeEditorControls/Fullscreen.js +0 -12
- package/docs/src/components/codeEditorControls/LanguageSelect.js +0 -15
- package/docs/src/components/codeEditorControls/Minimap.js +0 -8
- package/docs/src/components/codeEditorControls/Redo.js +0 -7
- package/docs/src/components/codeEditorControls/Undo.js +0 -7
- package/docs/src/components/codeEditorControls/WordWrap.js +0 -8
- package/docs/src/components/htmlEditorControls/AlignCenter.js +0 -12
- package/docs/src/components/htmlEditorControls/AlignJustify.js +0 -12
- package/docs/src/components/htmlEditorControls/AlignLeft.js +0 -12
- package/docs/src/components/htmlEditorControls/AlignRight.js +0 -12
- package/docs/src/components/htmlEditorControls/Bold.js +0 -12
- package/docs/src/components/htmlEditorControls/BulletList.js +0 -12
- package/docs/src/components/htmlEditorControls/CharacterCount.js +0 -18
- package/docs/src/components/htmlEditorControls/ClearFormatting.js +0 -12
- package/docs/src/components/htmlEditorControls/CodeBlock.js +0 -12
- package/docs/src/components/htmlEditorControls/ControlGroup.js +0 -12
- package/docs/src/components/htmlEditorControls/ControlSpacer.js +0 -6
- package/docs/src/components/htmlEditorControls/CreateLink.js +0 -15
- package/docs/src/components/htmlEditorControls/DropdownControl.js +0 -57
- package/docs/src/components/htmlEditorControls/FormatBlock.js +0 -12
- package/docs/src/components/htmlEditorControls/FormatCode.js +0 -1
- package/docs/src/components/htmlEditorControls/HtmlEditorControl.js +0 -44
- package/docs/src/components/htmlEditorControls/InlineCode.js +0 -12
- package/docs/src/components/htmlEditorControls/InsertTable.js +0 -15
- package/docs/src/components/htmlEditorControls/Italic.js +0 -12
- package/docs/src/components/htmlEditorControls/Mode.js +0 -9
- package/docs/src/components/htmlEditorControls/NumberList.js +0 -12
- package/docs/src/components/htmlEditorControls/Strikethrough.js +0 -12
- package/docs/src/components/htmlEditorControls/TextBackgroundColor.js +0 -97
- package/docs/src/components/htmlEditorControls/TextColor.js +0 -97
- package/docs/src/components/htmlEditorControls/Underline.js +0 -12
- package/docs/src/components/htmlEditorControls/WordCount.js +0 -18
- package/docs/src/components/markdownEditorControls/Bold.js +0 -11
- package/docs/src/components/markdownEditorControls/BulletList.js +0 -11
- package/docs/src/components/markdownEditorControls/Code.js +0 -11
- package/docs/src/components/markdownEditorControls/FormatBlock.js +0 -30
- package/docs/src/components/markdownEditorControls/Heading.js +0 -11
- package/docs/src/components/markdownEditorControls/Image.js +0 -93
- package/docs/src/components/markdownEditorControls/Italic.js +0 -11
- package/docs/src/components/markdownEditorControls/Link.js +0 -11
- package/docs/src/components/markdownEditorControls/MarkdownEditorControl.js +0 -39
- package/docs/src/components/markdownEditorControls/Menu.js +0 -30
- package/docs/src/components/markdownEditorControls/NumberedList.js +0 -11
- package/docs/src/components/markdownEditorControls/Quote.js +0 -11
- package/docs/src/components/markdownEditorControls/SpeechToText.js +0 -16
- package/docs/src/components/markdownEditorControls/Strikethrough.js +0 -11
- package/docs/src/components/markdownEditorControls/Table.js +0 -80
- package/docs/src/components/paginationControls/FirstPage.js +0 -1
- package/docs/src/components/paginationControls/GotoPage.js +0 -17
- package/docs/src/components/paginationControls/ItemsPerPage.js +0 -15
- package/docs/src/components/paginationControls/LastPage.js +0 -1
- package/docs/src/components/paginationControls/NextPage.js +0 -1
- package/docs/src/components/paginationControls/PageCount.js +0 -1
- package/docs/src/components/paginationControls/PageInfo.js +0 -6
- package/docs/src/components/paginationControls/PaginationButtonControl.js +0 -20
- package/docs/src/components/paginationControls/PaginationControl.js +0 -5
- package/docs/src/components/paginationControls/PrevPage.js +0 -1
- package/docs/src/components/tableControls/DeleteRecord.js +0 -7
- package/docs/src/components/tableControls/DeleteSelected.js +0 -7
- package/docs/src/components/tableControls/Edit.js +0 -18
- package/docs/src/components/tableControls/ExportCSV.js +0 -8
- package/docs/src/components/tableControls/ExportJson.js +0 -8
- package/docs/src/components/tableControls/FieldSortHide.js +0 -25
- package/docs/src/components/tableControls/Filters.js +0 -46
- package/docs/src/components/tableControls/FirstPage.js +0 -9
- package/docs/src/components/tableControls/HiddenCount.js +0 -3
- package/docs/src/components/tableControls/Hide.js +0 -5
- package/docs/src/components/tableControls/LastPage.js +0 -9
- package/docs/src/components/tableControls/NextPage.js +0 -9
- package/docs/src/components/tableControls/PageSelect.js +0 -22
- package/docs/src/components/tableControls/PageSize.js +0 -5
- package/docs/src/components/tableControls/PrevPage.js +0 -9
- package/docs/src/components/tableControls/Search.js +0 -9
- package/docs/src/components/tableControls/ShowAll.js +0 -5
- package/docs/src/components/tableControls/TableControl.js +0 -16
- package/src/components/codeEditorControls/CodeEditorControl.js +0 -134
- package/src/components/codeEditorControls/ControlSpacer.js +0 -23
- package/src/components/codeEditorControls/CopyCode.js +0 -37
- package/src/components/codeEditorControls/EditorTheme.js +0 -81
- package/src/components/codeEditorControls/FindReplace.js +0 -35
- package/src/components/codeEditorControls/FoldAll.js +0 -49
- package/src/components/codeEditorControls/FontSize.js +0 -45
- package/src/components/codeEditorControls/FormatCode.js +0 -37
- package/src/components/codeEditorControls/Fullscreen.js +0 -72
- package/src/components/codeEditorControls/LanguageSelect.js +0 -74
- package/src/components/codeEditorControls/Minimap.js +0 -60
- package/src/components/codeEditorControls/Redo.js +0 -35
- package/src/components/codeEditorControls/Undo.js +0 -35
- package/src/components/codeEditorControls/WordWrap.js +0 -60
- package/src/components/htmlEditorControls/AlignCenter.js +0 -63
- package/src/components/htmlEditorControls/AlignJustify.js +0 -63
- package/src/components/htmlEditorControls/AlignLeft.js +0 -63
- package/src/components/htmlEditorControls/AlignRight.js +0 -63
- package/src/components/htmlEditorControls/Bold.js +0 -63
- package/src/components/htmlEditorControls/BulletList.js +0 -63
- package/src/components/htmlEditorControls/CharacterCount.js +0 -75
- package/src/components/htmlEditorControls/ClearFormatting.js +0 -63
- package/src/components/htmlEditorControls/CodeBlock.js +0 -64
- package/src/components/htmlEditorControls/ControlGroup.js +0 -70
- package/src/components/htmlEditorControls/ControlSpacer.js +0 -23
- package/src/components/htmlEditorControls/CreateLink.js +0 -115
- package/src/components/htmlEditorControls/DropdownControl.js +0 -149
- package/src/components/htmlEditorControls/FormatBlock.js +0 -106
- package/src/components/htmlEditorControls/FormatCode.js +0 -7
- package/src/components/htmlEditorControls/HtmlEditorControl.js +0 -164
- package/src/components/htmlEditorControls/InlineCode.js +0 -63
- package/src/components/htmlEditorControls/InsertTable.js +0 -126
- package/src/components/htmlEditorControls/Italic.js +0 -63
- package/src/components/htmlEditorControls/Mode.js +0 -68
- package/src/components/htmlEditorControls/NumberList.js +0 -63
- package/src/components/htmlEditorControls/Strikethrough.js +0 -63
- package/src/components/htmlEditorControls/TextBackgroundColor.js +0 -189
- package/src/components/htmlEditorControls/TextColor.js +0 -189
- package/src/components/htmlEditorControls/Underline.js +0 -63
- package/src/components/htmlEditorControls/WordCount.js +0 -76
- package/src/components/markdownEditorControls/Bold.js +0 -30
- package/src/components/markdownEditorControls/BulletList.js +0 -30
- package/src/components/markdownEditorControls/Code.js +0 -39
- package/src/components/markdownEditorControls/FormatBlock.js +0 -102
- package/src/components/markdownEditorControls/Heading.js +0 -46
- package/src/components/markdownEditorControls/Image.js +0 -250
- package/src/components/markdownEditorControls/Italic.js +0 -30
- package/src/components/markdownEditorControls/Link.js +0 -74
- package/src/components/markdownEditorControls/MarkdownEditorControl.js +0 -158
- package/src/components/markdownEditorControls/Menu.js +0 -86
- package/src/components/markdownEditorControls/NumberedList.js +0 -69
- package/src/components/markdownEditorControls/Quote.js +0 -30
- package/src/components/markdownEditorControls/SpeechToText.js +0 -65
- package/src/components/markdownEditorControls/Strikethrough.js +0 -35
- package/src/components/markdownEditorControls/Table.js +0 -165
- package/src/components/paginationControls/FirstPage.js +0 -26
- package/src/components/paginationControls/GotoPage.js +0 -56
- package/src/components/paginationControls/ItemsPerPage.js +0 -44
- package/src/components/paginationControls/LastPage.js +0 -26
- package/src/components/paginationControls/NextPage.js +0 -26
- package/src/components/paginationControls/PageCount.js +0 -10
- package/src/components/paginationControls/PageInfo.js +0 -23
- package/src/components/paginationControls/PaginationButtonControl.js +0 -76
- package/src/components/paginationControls/PaginationControl.js +0 -43
- package/src/components/paginationControls/PrevPage.js +0 -26
- package/src/components/tableControls/DeleteRecord.js +0 -29
- package/src/components/tableControls/DeleteSelected.js +0 -27
- package/src/components/tableControls/Edit.js +0 -86
- package/src/components/tableControls/ExportCSV.js +0 -71
- package/src/components/tableControls/ExportJson.js +0 -55
- package/src/components/tableControls/FieldSortHide.js +0 -76
- package/src/components/tableControls/Filters.js +0 -113
- package/src/components/tableControls/FirstPage.js +0 -65
- package/src/components/tableControls/HiddenCount.js +0 -43
- package/src/components/tableControls/Hide.js +0 -34
- package/src/components/tableControls/LastPage.js +0 -65
- package/src/components/tableControls/NextPage.js +0 -65
- package/src/components/tableControls/PageSelect.js +0 -101
- package/src/components/tableControls/PageSize.js +0 -68
- package/src/components/tableControls/PrevPage.js +0 -65
- package/src/components/tableControls/Search.js +0 -56
- package/src/components/tableControls/ShowAll.js +0 -34
- package/src/components/tableControls/TableControl.js +0 -103
- package/tests/components/tableControls/TableControl.browser-test.js +0 -300
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{html as e,css as t}from"../lit-all.min.js";import i from"./ShadowComponent.js";import o from"../utils/formatCode.js";import l from"../utils/debounce.js";import{getCalculatedTheme as r,subscribeToTheme as s}from"../utils/theme.js";import a from"./Dialog.js";export default class c extends i{static formAssociated=!0;static properties={name:{type:String,reflect:!0},value:{type:String,reflect:!0},selection:{type:Object,state:!0},mode:{type:String,reflect:!0},controls:{type:String,reflect:!0},lexicalSrc:{type:String,attribute:"lexical-src"},monacoSrc:{type:String,attribute:"monaco-src"},nodes:{type:String},hasTopToolbar:{type:Boolean,state:!0},hasBottomToolbar:{type:Boolean,state:!0},fullscreen:{type:Boolean,reflect:!0},disabled:{type:Boolean,reflect:!0},readonly:{type:Boolean,reflect:!0},required:{type:Boolean,reflect:!0}};constructor(){super(),this.internals=this.attachInternals(),this.name="",this.value="",this.selection=null,this.cursor=null,this.mode="visual",this.controls="",this.lexicalSrc="",this.monacoSrc="",this.nodes="",this.hasTopToolbar=!1,this.hasBottomToolbar=!1,this.skipValueSync=!1,this.lexicalValueSync=!1,this.savedSelection=null,this.lexicalEditor=null,this.monacoEditor=null,this.editorTheme="auto",this.wordWrap=!0,this.minimapEnabled=!1,this.fontSize=14,this.fullscreen=!1,this.disabled=!1,this.readonly=!1,this.required=!1,this.lx={},this.debouncedSyncValue=l(()=>this.syncValueFromLexical(),300)}connectedCallback(){super.connectedCallback(),this.hasAttribute("value")&&(this.value=this.getAttribute("value")),this.slotObserver=new MutationObserver(()=>this.updateToolbarVisibility()),this.slotObserver.observe(this,{childList:!0,subtree:!0}),this.updateToolbarVisibility()}disconnectedCallback(){super.disconnectedCallback(),this.slotObserver?.disconnect(),this.cleanupFns?.forEach(e=>e?.()),this.monacoEditor?.dispose(),this.unsubscribeTheme?.(),this.fullscreen&&this.exitFullscreen()}updateToolbarVisibility(){const e=new Set(Array.from(this.children).map(e=>e.getAttribute("slot"))),t=this.constructor.controlSets[this.controls]??null;this.hasTopToolbar=!(!t?.topLeft&&!t?.topRight)||["toolbar-top","toolbar-top-left","toolbar-top-right"].some(t=>e.has(t)),this.hasBottomToolbar=!(!t?.bottomLeft&&!t?.bottomRight)||["toolbar-bottom","toolbar-bottom-left","toolbar-bottom-right"].some(t=>e.has(t))}updated(e){if(super.updated(e),e.has("controls")&&(this.updateToolbarVisibility(),this.controls&&"none"!==this.controls&&this.loadControls()),e.has("value")&&!this.skipValueSync&&(this.lexicalValueSync?this.lexicalValueSync=!1:this.lexicalEditor&&"visual"===this.mode&&!this.isVisualCompatible(this.value)?(this.skipLexicalExport=!0,this.mode="code"):this.syncContentToEditors(),this.updateFormValue(),this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0}))),e.has("mode")){const t=window.scrollY;this.handleModeSwitch(e.get("mode")),this.dispatchEvent(new CustomEvent("mode-changed",{detail:{mode:this.mode},bubbles:!0})),requestAnimationFrame(()=>window.scrollTo(0,t))}if(e.has("fullscreen")&&requestAnimationFrame(()=>this.monacoEditor?.layout()),e.has("disabled")||e.has("readonly")){const e=this.disabled||this.readonly;this.lexicalEditor?.setEditable(!e),this.monacoEditor?.updateOptions({readOnly:e})}(e.has("value")||e.has("required")||e.has("disabled"))&&this.#e()}#e=()=>{if(this.disabled)return void this.internals.setValidity({});const e=!(this.value||"").replace(/<[^>]+>/g,"").trim();this.required&&e?this.internals.setValidity({valueMissing:!0},"Please fill out this field.",this.lexicalContainer||this):this.internals.setValidity({})};async firstUpdated(){this.lexicalContainer=this.shadowRoot.querySelector(".lexical-editor"),this.monacoContainer=this.shadowRoot.querySelector(".monaco-editor-container"),await this.initLexical(),this.dispatchEvent(new CustomEvent("ready",{detail:{value:this.value},bubbles:!0}))}loadControls(){const e=this.constructor.controlModules[this.controls];if(!e?.length)return;const t=this.constructor.loadedModules,i=new URL("./htmlEditorControls/",import.meta.url).href,o=new URL("./codeEditorControls/",import.meta.url).href;e.filter(e=>!t.has(e)).forEach(e=>{t.add(e);const[l,r]=e.split("/");import(`${"cec"===l?o:i}${r}.js`)})}async loadNodeModules(){if(!this.nodes?.trim())return[];const e=new URL("./htmlEditorNodes/",import.meta.url).href;return(await Promise.all(this.nodes.split(",").map(e=>e.trim()).filter(Boolean).map(t=>import(`${e}${t}.js`)))).map(e=>e.default?.lexicalNode).filter(Boolean)}async loadLexicalModules(){const e=this.lexicalSrc||window.kempo?.lexicalUrl||"https://esm.sh",t=t=>((e,t)=>`${e}/${t}@0.43.0`)(e,t),[i,o,l,r,s,a,c,n,h]=await Promise.all([import(t("lexical")),import(t("@lexical/rich-text")),import(t("@lexical/html")),import(t("@lexical/history")),import(t("@lexical/list")),import(t("@lexical/link")),import(t("@lexical/selection")),import(t("@lexical/table")),import(t("@lexical/code"))]);this.lx={lexical:i,richText:o,lexicalHtml:l,history:r,list:s,link:a,selection:c,table:n,code:h},this.StyledTextNode=class extends i.TextNode{static getType(){return"styled-text"}static clone(e){return new this(e.__text,e.__key)}static importDOM(){return{span:()=>({conversion:e=>{const t=e.getAttribute("style");if(!t)return null;const o=i.$createTextNode(e.textContent);return o.setStyle(t),{node:o}},priority:1})}}static importJSON(e){return i.$createTextNode(e.text)}exportJSON(){return{...super.exportJSON(),type:"styled-text"}}}}async initLexical(){await this.loadLexicalModules(),this.customNodes=await this.loadNodeModules(),this.nodeCompatCheckers=this.customNodes.filter(e=>"function"==typeof e.isVisualCompatible).map(e=>e.isVisualCompatible),this.nodePreprocessors=this.customNodes.filter(e=>"function"==typeof e.preprocessHtml).map(e=>e.preprocessHtml);const{lexical:e,richText:t,history:i,list:o,link:l,table:r,code:s}=this.lx,a={namespace:"KempoHtmlEditor",theme:{paragraph:"k-editor-p",heading:{h1:"k-editor-h1",h2:"k-editor-h2",h3:"k-editor-h3",h4:"k-editor-h4",h5:"k-editor-h5",h6:"k-editor-h6"},text:{underline:"td-u",strikethrough:"td-lt"},list:{ul:"k-editor-ul",ol:"k-editor-ol",listitem:"k-editor-li"},link:"k-editor-link",quote:"k-editor-quote",code:"k-editor-code-block",codeHighlight:{},table:"k-editor-table",tableCell:"k-editor-table-cell",tableCellHeader:"k-editor-table-cell-header"},nodes:[t.HeadingNode,t.QuoteNode,o.ListNode,o.ListItemNode,l.LinkNode,r.TableNode,r.TableCellNode,r.TableRowNode,s.CodeNode,s.CodeHighlightNode,this.StyledTextNode,...this.customNodes],onError:console.error,editorState:null};this.lexicalEditor=e.createEditor(a),this.lexicalEditor.setRootElement(this.lexicalContainer),(this.disabled||this.readonly)&&this.lexicalEditor.setEditable(!1),this.lexicalEditor._window=new Proxy(window,{get:(e,t)=>{if("getSelection"===t)return()=>this.shadowRoot.getSelection();const i=Reflect.get(e,t);return"function"==typeof i?i.bind(e):i}}),this.cleanupFns=[t.registerRichText(this.lexicalEditor),i.registerHistory(this.lexicalEditor,i.createEmptyHistoryState(),300)],o.registerList&&this.cleanupFns.push(o.registerList(this.lexicalEditor)),r.registerTable&&this.cleanupFns.push(r.registerTable(this.lexicalEditor)),s.registerCodeHighlighting&&this.cleanupFns.push(s.registerCodeHighlighting(this.lexicalEditor)),l.registerLink&&this.cleanupFns.push(l.registerLink(this.lexicalEditor,{validateUrl:e=>{try{return new URL(e),!0}catch{return!1}}})),this.value&&(this.isVisualCompatible(this.value)?this.importHtmlToLexical(this.value):(this.skipLexicalExport=!0,this.mode="code")),this.lexicalEditor.registerUpdateListener(({dirtyElements:e,dirtyLeaves:t})=>{0===e.size&&0===t.size||(this.debouncedSyncValue(),this.dispatchEvent(new CustomEvent("input",{detail:{value:this.exportHtmlFromLexical()},bubbles:!0})))}),this.lexicalEditor.registerCommand(e.SELECTION_CHANGE_COMMAND,()=>(this.updateSelection(),!1),e.COMMAND_PRIORITY_LOW)}async initMonaco(){if(!this.monacoEditor){if(this.monacoInitPromise)return this.monacoInitPromise;this.monacoInitPromise=this._initMonaco(),await this.monacoInitPromise,this.monacoInitPromise=null}}async _initMonaco(){const e=this.monacoSrc||window.kempo?.monacoUrl||"https://cdn.jsdelivr.net/npm/monaco-editor@0.52.2/min";await new Promise((t,i)=>{if(window.monaco)return void t();if(window.require?.defined?.("vs/editor/editor.main"))return void t();const o=document.querySelector(`script[src="${e}/vs/loader.js"]`);if(o)return void o.addEventListener("load",()=>{window.require.config({paths:{vs:`${e}/vs`}}),window.require(["vs/editor/editor.main"],()=>t(),i)});const l=document.createElement("script");l.src=`${e}/vs/loader.js`,l.onload=()=>{window.require.config({paths:{vs:`${e}/vs`}}),window.require(["vs/editor/editor.main"],()=>t(),i)},l.onerror=i,document.head.appendChild(l)}),this.monacoEditor=window.monaco.editor.create(this.monacoContainer,{value:o(this.value),language:"html",theme:this.resolveMonacoTheme(),minimap:{enabled:this.minimapEnabled},wordWrap:this.wordWrap?"on":"off",fontSize:this.fontSize,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,padding:{top:8},readOnly:this.disabled||this.readonly});const t=document.querySelector('link[href*="monaco"][href*="editor.main.css"]');if(t){const e=document.createElement("link");e.rel="stylesheet",e.href=t.href,this.shadowRoot.appendChild(e)}this.unsubscribeTheme=s(()=>{this.monacoEditor&&"auto"===this.editorTheme&&window.monaco.editor.setTheme(this.resolveMonacoTheme())}),this.monacoEditor.onDidChangeModelContent(()=>{this.skipValueSync=!0,this.value=this.monacoEditor.getValue(),this.skipValueSync=!1,this.updateFormValue(),this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0})),this.dispatchEvent(new CustomEvent("input",{detail:{value:this.value},bubbles:!0}))})}importHtmlToLexical(e){if(!this.lexicalEditor||!this.lx.lexicalHtml)return;const{lexical:t,lexicalHtml:i}=this.lx,o=(this.nodePreprocessors||[]).reduce((e,t)=>t(e),e);this.lexicalEditor.update(()=>{if(t.$getRoot().clear(),!o?.trim())return;const e=(new DOMParser).parseFromString(o,"text/html"),l=i.$generateNodesFromDOM(this.lexicalEditor,e);l.length>0&&t.$insertNodes(l)},{discrete:!0})}exportHtmlFromLexical(){if(!this.lexicalEditor||!this.lx.lexicalHtml)return this.value;let e="";return this.lexicalEditor.getEditorState().read(()=>{e=this.lx.lexicalHtml.$generateHtmlFromNodes(this.lexicalEditor,null)}),this.cleanExportedHtml(e)}isVisualCompatible(e){if(!e?.trim())return!0;const t=new Set(["script","style","meta","link","head","iframe","object","embed","canvas","video","audio","form","input","button","select","textarea","fieldset","label","noscript","template","slot","svg","math"]),i=this.nodeCompatCheckers||[],o=(new DOMParser).parseFromString(e,"text/html"),l=document.createTreeWalker(o.body,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT);let r;for(;r=l.nextNode();)if(!i.some(e=>e(r))){if(r.nodeType===Node.COMMENT_NODE)return!1;if(t.has(r.tagName?.toLowerCase()))return!1}return!0}cleanExportedHtml(e){const t=(new DOMParser).parseFromString(e,"text/html");return t.body.querySelectorAll("[class]").forEach(e=>{const t=Array.from(e.classList).filter(e=>!e.startsWith("k-editor-")&&"td-u"!==e&&"td-lt"!==e);0===t.length?e.removeAttribute("class"):e.className=t.join(" ")}),t.body.querySelectorAll("[style]").forEach(e=>{const t=e.style.cssText.replace(/white-space:\s*pre-wrap;?\s*/g,"").trim();t?e.style.cssText=t:e.removeAttribute("style")}),t.body.querySelectorAll("span:not([class]):not([style]):not([id])").forEach(e=>{e.attributes.length||e.replaceWith(...e.childNodes)}),t.body.querySelectorAll("b > strong, i > em, b > b, strong > strong, i > i, em > em").forEach(e=>{e.replaceWith(...e.childNodes)}),t.body.querySelectorAll("pre[data-highlight-language], code[data-highlight-language]").forEach(e=>{e.removeAttribute("data-highlight-language"),e.removeAttribute("data-language")}),t.body.innerHTML}syncValueFromLexical(){this.lexicalEditor&&(this.lexicalValueSync=!0,this.value=this.exportHtmlFromLexical(),this.updateFormValue())}syncContentToEditors(){"visual"===this.mode&&this.lexicalEditor&&this.importHtmlToLexical(this.value)}async handleModeSwitch(e){"code"===this.mode?(this.lexicalEditor&&!this.skipLexicalExport&&(this.value=this.exportHtmlFromLexical()),this.skipLexicalExport=!1,await this.initMonaco(),this.monacoEditor&&(this.monacoEditor.setValue(o(this.value)),this.monacoEditor.layout())):"visual"===this.mode&&(this.monacoEditor&&(this.value=this.monacoEditor.getValue()),this.lexicalEditor&&this.importHtmlToLexical(this.value)),this.requestUpdate()}updateFormValue(){this.internals.setFormValue(this.getValue())}formResetCallback(){this.value=""}formStateRestoreCallback(e){this.value=e}formDisabledCallback(e){this.disabled=e}updateSelection=()=>{if("visual"!==this.mode||!this.lexicalEditor)return void(this.selection=null);const{lexical:e}=this.lx;this.lexicalEditor.getEditorState().read(()=>{const t=e.$getSelection();e.$isRangeSelection(t)&&!t.isCollapsed()?this.selection={text:t.getTextContent(),collapsed:!1}:(this.selection=null,this.cursor=t?{anchor:t.anchor,focus:t.focus}:null)})};setMode(e){return["visual","code"].includes(e)?"visual"!==e||this.isVisualCompatible(this.getValue())?(this.mode=e,this):(a.confirm("This html contains code that is not compatible with the visual editor, the incompatible code will be lost",t=>{t&&(this.mode=e)},{title:"Warning",confirmText:"Change Anyways"}),this):this}toggleMode(){return this.setMode("visual"===this.mode?"code":"visual")}getValue(){if("visual"===this.mode&&this.lexicalEditor)this.skipValueSync=!0,this.value=this.exportHtmlFromLexical(),this.skipValueSync=!1;else if("code"===this.mode&&this.monacoEditor)return this.monacoEditor.getValue();return this.value}setValue(e){return this.lexicalEditor&&"visual"===this.mode&&!this.isVisualCompatible(e)?(this.value=e,this.skipLexicalExport=!0,this.mode="code",this.updateFormValue(),this):(this.skipValueSync=!0,this.value=e,"visual"===this.mode?this.syncContentToEditors():"code"===this.mode&&this.monacoEditor&&this.monacoEditor.setValue(o(e)),this.updateFormValue(),this.skipValueSync=!1,this)}clear(){return this.setValue("")}bold(){return this.lexicalFormat("bold"),this}italic(){return this.lexicalFormat("italic"),this}underline(){return this.lexicalFormat("underline"),this}strikethrough(){return this.lexicalFormat("strikethrough"),this}inlineCode(){return this.lexicalFormat("code"),this}orderedList(){return"visual"===this.mode&&this.lexicalEditor?(this.lexicalEditor.update(()=>{this.lx.list.$insertList("number")},{discrete:!0}),this):this}unorderedList(){return"visual"===this.mode&&this.lexicalEditor?(this.lexicalEditor.update(()=>{this.lx.list.$insertList("bullet")},{discrete:!0}),this):this}alignLeft(){return this.lexicalFormatElement("left"),this}alignCenter(){return this.lexicalFormatElement("center"),this}alignRight(){return this.lexicalFormatElement("right"),this}alignJustify(){return this.lexicalFormatElement("justify"),this}setTextColor(e){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:t,selection:i}=this.lx;return this.lexicalEditor.update(()=>{const o=t.$getSelection();t.$isRangeSelection(o)&&i.$patchStyleText(o,{color:e})},{discrete:!0}),this}removeTextColor(){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:e,selection:t}=this.lx;return this.lexicalEditor.update(()=>{const i=e.$getSelection();e.$isRangeSelection(i)&&t.$patchStyleText(i,{color:null})},{discrete:!0}),this}setTextBackgroundColor(e){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:t,selection:i}=this.lx;return this.lexicalEditor.update(()=>{const o=t.$getSelection();t.$isRangeSelection(o)&&i.$patchStyleText(o,{"background-color":e})},{discrete:!0}),this}removeTextBackgroundColor(){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:e,selection:t}=this.lx;return this.lexicalEditor.update(()=>{const i=e.$getSelection();e.$isRangeSelection(i)&&t.$patchStyleText(i,{"background-color":null})},{discrete:!0}),this}removeFormat(){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:e,selection:t}=this.lx;return this.lexicalEditor.update(()=>{const i=e.$getSelection();e.$isRangeSelection(i)&&(i.getNodes().forEach(t=>{e.$isTextNode(t)&&t.setFormat(0)}),t.$patchStyleText(i,{color:null,"background-color":null}))},{discrete:!0}),this}formatBlock(e){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:t,richText:i,code:o}=this.lx;return this.lexicalEditor.update(()=>{const l=t.$getSelection();if(!t.$isRangeSelection(l))return;const r=l.anchor.getNode().getTopLevelElementOrThrow(),s=o.$isCodeNode(r);let a;if("p"===e)a=t.$createParagraphNode();else if(e.match(/^h[1-6]$/))a=i.$createHeadingNode(e);else if("blockquote"===e)a=i.$createQuoteNode();else{if("pre"!==e)return;a=o.$createCodeNode()}if(s&&"pre"!==e){const e=r.getTextContent();r.replace(a),a.append(t.$createTextNode(e))}else{const e=r.getChildren();r.replace(a),e.forEach(e=>a.append(e))}a.selectEnd()},{discrete:!0}),this}isSelectionInCodeBlock(){if("visual"!==this.mode||!this.lexicalEditor)return!1;let e=!1;const{lexical:t,code:i}=this.lx;return this.lexicalEditor.getEditorState().read(()=>{const o=t.$getSelection();t.$isRangeSelection(o)&&(e=i.$isCodeNode(o.anchor.getNode().getTopLevelElementOrThrow()))}),e}getTableAtSelection(){if("visual"!==this.mode||!this.lexicalEditor)return null;let e=null;const{lexical:t,table:i}=this.lx;return this.lexicalEditor.getEditorState().read(()=>{const o=t.$getSelection();if(!t.$isRangeSelection(o))return;let l=o.anchor.getNode();for(;l;){if(i.$isTableNode(l)){const t=l.getChildren(),o=[];let r=!1,s=0;t.forEach((e,t)=>{const l=[];e.getChildren().forEach(e=>{0===t&&i.$isTableCellNode(e)&&e.getHeaderStyles()===i.TableCellHeaderStates.ROW&&(r=!0),l.push(e.getTextContent())}),l.length>s&&(s=l.length),o.push(l)}),e={key:l.getKey(),rows:r?t.length-1:t.length,cols:s,hasHeaders:r,cellData:o};break}l=l.getParent()}}),e}removeTableByKey(e){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:t}=this.lx;return this.lexicalEditor.update(()=>{const i=t.$getNodeByKey(e);i&&i.remove()},{discrete:!0}),this}insertHTML(e){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:t,lexicalHtml:i}=this.lx;return this.lexicalEditor.update(()=>{const o=(new DOMParser).parseFromString(e,"text/html"),l=i.$generateNodesFromDOM(this.lexicalEditor,o);t.$insertNodes(l)},{discrete:!0}),this}insertAtCursor(e){return this.insertHTML(e)}insertTable(e,t,i=!1,o=null){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:l,table:r}=this.lx;return this.lexicalEditor.update(()=>{const s=e+(i?1:0),a=[];for(let e=0;e<s;e++){const s=[];for(let a=0;a<t;a++){const t=i&&0===e,c=t?r.TableCellHeaderStates.ROW:r.TableCellHeaderStates.NO_STATUS,n=r.$createTableCellNode(c),h=o?.[e]?.[a]??(t?`Header ${a+1}`:""),d=l.$createParagraphNode();d.append(l.$createTextNode(h||" ")),n.append(d),s.push(n)}a.push(r.$createTableRowNode().append(...s))}const c=r.$createTableNode().append(...a),n=l.$getSelection();if(l.$isRangeSelection(n)){n.anchor.getNode().getTopLevelElementOrThrow().insertAfter(c);const e=l.$createParagraphNode();c.insertAfter(e),e.selectEnd()}else{const e=l.$getRoot();e.append(c),e.append(l.$createParagraphNode())}},{discrete:!0}),this}insertElementAtCursor(e){return this.insertHTML(e.outerHTML)}replaceSelectionWithElement(e){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:t,lexicalHtml:i}=this.lx;return this.lexicalEditor.update(()=>{const o=t.$getSelection();if(!t.$isRangeSelection(o))return;o.removeText();const l=(new DOMParser).parseFromString(e.outerHTML,"text/html"),r=i.$generateNodesFromDOM(this.lexicalEditor,l);t.$insertNodes(r)},{discrete:!0}),this}wrapSelection(e,t,i=null){if("visual"!==this.mode||!this.lexicalEditor)return this;const o=i||this.getSelectedText();return o?this.insertHTML(e+o+t):this}getSelection(){if("visual"!==this.mode||!this.lexicalEditor)return null;let e=null;const{lexical:t}=this.lx;return this.lexicalEditor.getEditorState().read(()=>{const i=t.$getSelection();t.$isRangeSelection(i)&&!i.isCollapsed()&&(e={text:i.getTextContent(),html:i.getTextContent(),selection:i})}),e}getSelectedText(){let e="";if("visual"!==this.mode||!this.lexicalEditor)return e;const{lexical:t}=this.lx;return this.lexicalEditor.getEditorState().read(()=>{const i=t.$getSelection();t.$isRangeSelection(i)&&(e=i.getTextContent())}),e}getSelectedHTML(){return this.getSelectedText()}selectAll(){if("visual"===this.mode&&this.lexicalEditor){const{lexical:e}=this.lx;this.lexicalEditor.update(()=>{e.$selectAll()},{discrete:!0})}else if(this.monacoEditor){const e=this.monacoEditor.getModel();e&&this.monacoEditor.setSelection(e.getFullModelRange())}return this}replaceSelection(e){return this.insertHTML(e)}deleteSelection(){return"visual"===this.mode?this.lexicalCmd("DELETE_CHARACTER_COMMAND",!1):this.monacoEditor&&this.monacoEditor.trigger("keyboard","deleteAllLeft",null),this}getValueWithSelectionMarkers(){if("visual"!==this.mode||!this.lexicalEditor)return{html:this.value,hasCursor:!1,hasSelection:!1,selectedText:""};let e={html:this.exportHtmlFromLexical(),hasCursor:!1,hasSelection:!1,selectedText:""};const{lexical:t}=this.lx;return this.lexicalEditor.getEditorState().read(()=>{const i=t.$getSelection();t.$isRangeSelection(i)&&(i.isCollapsed()?e.hasCursor=!0:(e.hasSelection=!0,e.selectedText=i.getTextContent()))}),e}setValueFromSelectionMarkers(e){return this.setValue(e)}captureSelection(){return this.selection}restoreSavedSelection(){return!1}clearSavedSelection(){this.savedSelection=null}createLink(e){if("visual"!==this.mode||!this.lexicalEditor)return this;const{link:t}=this.lx;return this.lexicalEditor.update(()=>{t.$toggleLink(e)},{discrete:!0}),this}createLinkWithText(e,t){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:i,link:o}=this.lx;return this.lexicalEditor.update(()=>{const l=i.$getSelection();i.$isRangeSelection(l)&&!l.isCollapsed()&&l.removeText();const r=o.$createLinkNode(e);r.append(i.$createTextNode(t)),i.$insertNodes([r])},{discrete:!0}),this}unlink(){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:e,link:t}=this.lx;return this.lexicalEditor.update(()=>{const i=e.$getSelection();e.$isRangeSelection(i)&&i.getNodes().forEach(e=>{const i=e.getParent();i&&t.$isLinkNode?.(i)&&(i.getChildren().forEach(e=>i.insertBefore(e)),i.remove())})},{discrete:!0}),this}insertImage(e){return this.insertHTML(`<img src="${encodeURI(e)}" />`)}undo(){return"code"===this.mode?this.monacoEditor?.trigger("toolbar","undo"):this.lexicalCmd("UNDO_COMMAND",void 0),this}redo(){return"code"===this.mode?this.monacoEditor?.trigger("toolbar","redo"):this.lexicalCmd("REDO_COMMAND",void 0),this}copyToClipboard(){return navigator.clipboard.writeText(this.getValue()),this}setEditorTheme(e){return["auto","light","dark"].includes(e)&&(this.editorTheme=e),this.monacoEditor&&window.monaco.editor.setTheme(this.resolveMonacoTheme()),this}openFind(){return this.monacoEditor?.getAction("actions.find")?.run(),this}foldAll(){return this.monacoEditor?.getAction("editor.foldAll")?.run(),this}unfoldAll(){return this.monacoEditor?.getAction("editor.unfoldAll")?.run(),this}enterFullscreen(){return this.fullscreen=!0,document.body.classList.add("no-scroll"),this.dispatchEvent(new CustomEvent("fullscreen-changed",{detail:{fullscreen:!0},bubbles:!0})),this}exitFullscreen(){return this.fullscreen=!1,document.body.classList.remove("no-scroll"),this.dispatchEvent(new CustomEvent("fullscreen-changed",{detail:{fullscreen:!1},bubbles:!0})),this}toggleFullscreen(){return this.fullscreen?this.exitFullscreen():this.enterFullscreen()}increaseFontSize(){return this.fontSize=Math.min(this.fontSize+2,40),this.monacoEditor?.updateOptions({fontSize:this.fontSize}),this}decreaseFontSize(){return this.fontSize=Math.max(this.fontSize-2,8),this.monacoEditor?.updateOptions({fontSize:this.fontSize}),this}setWordWrap(e){return this.wordWrap=e,this.monacoEditor?.updateOptions({wordWrap:e?"on":"off"}),this}setMinimap(e){return this.minimapEnabled=e,this.monacoEditor?.updateOptions({minimap:{enabled:e}}),this}resolveMonacoTheme(){return"dark"===this.editorTheme?"vs-dark":"light"===this.editorTheme?"vs":"dark"===r()?"vs-dark":"vs"}lexicalCmd(e,t){if("visual"!==this.mode||!this.lexicalEditor)return;const i=this.lx.lexical?.[e];i&&this.lexicalEditor.dispatchCommand(i,t)}lexicalFormat(e){if("visual"!==this.mode||!this.lexicalEditor)return;const{lexical:t}=this.lx;this.lexicalEditor.update(()=>{const i=t.$getSelection();t.$isRangeSelection(i)&&i.formatText(e)},{discrete:!0})}lexicalFormatElement(e){"visual"===this.mode&&this.lexicalEditor&&this.lexicalEditor.dispatchCommand(this.lx.lexical.FORMAT_ELEMENT_COMMAND,e)}render(){const t=this.constructor.controlSets[this.controls]??{};return e`
|
|
2
|
-
${this.hasTopToolbar?
|
|
1
|
+
import{html as t,css as e}from"../lit-all.min.js";import i from"./ShadowComponent.js";import o from"../utils/formatCode.js";import l from"../utils/debounce.js";import{getCalculatedTheme as r,subscribeToTheme as s}from"../utils/theme.js";import a from"./Dialog.js";import n from"./controls/Control.js";export default class c extends i{static formAssociated=!0;static properties={name:{type:String,reflect:!0},value:{type:String,reflect:!0},selection:{type:Object,state:!0},mode:{type:String,reflect:!0},controls:{type:String,reflect:!0},lexicalSrc:{type:String,attribute:"lexical-src"},monacoSrc:{type:String,attribute:"monaco-src"},nodes:{type:String},hasTopToolbar:{type:Boolean,state:!0},hasBottomToolbar:{type:Boolean,state:!0},fullscreen:{type:Boolean,reflect:!0},disabled:{type:Boolean,reflect:!0},readonly:{type:Boolean,reflect:!0},required:{type:Boolean,reflect:!0}};constructor(){super(),this.internals=this.attachInternals(),this.name="",this.value="",this.selection=null,this.cursor=null,this.mode="visual",this.controls="",this.lexicalSrc="",this.monacoSrc="",this.nodes="",this.hasTopToolbar=!1,this.hasBottomToolbar=!1,this.skipValueSync=!1,this.lexicalValueSync=!1,this.savedSelection=null,this.lexicalEditor=null,this.monacoEditor=null,this.editorTheme="auto",this.wordWrap=!0,this.minimapEnabled=!1,this.fontSize=14,this.fullscreen=!1,this.disabled=!1,this.readonly=!1,this.required=!1,this.lx={},this.debouncedSyncValue=l(()=>this.syncValueFromLexical(),300)}connectedCallback(){super.connectedCallback(),this.hasAttribute("controlled")||this.setAttribute("controlled",""),this.hasAttribute("value")&&(this.value=this.getAttribute("value")),this.slotObserver=new MutationObserver(()=>this.updateToolbarVisibility()),this.slotObserver.observe(this,{childList:!0,subtree:!0}),this.updateToolbarVisibility()}disconnectedCallback(){super.disconnectedCallback(),this.slotObserver?.disconnect(),this.cleanupFns?.forEach(t=>t?.()),this.monacoEditor?.dispose(),this.unsubscribeTheme?.(),this.fullscreen&&this.exitFullscreen()}updateToolbarVisibility(){const t=new Set(Array.from(this.children).map(t=>t.getAttribute("slot"))),e=this.constructor.controlSets[this.controls]??null;this.hasTopToolbar=!(!e?.topLeft&&!e?.topRight)||["toolbar-top","toolbar-top-left","toolbar-top-right"].some(e=>t.has(e)),this.hasBottomToolbar=!(!e?.bottomLeft&&!e?.bottomRight)||["toolbar-bottom","toolbar-bottom-left","toolbar-bottom-right"].some(e=>t.has(e))}updated(t){if(super.updated(t),t.has("controls")&&(this.updateToolbarVisibility(),this.controls&&"none"!==this.controls&&this.loadControls()),t.has("value")&&!this.skipValueSync&&(this.lexicalValueSync?this.lexicalValueSync=!1:this.lexicalEditor&&"visual"===this.mode&&!this.isVisualCompatible(this.value)?(this.skipLexicalExport=!0,this.mode="code"):this.syncContentToEditors(),this.updateFormValue(),this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0}))),t.has("mode")){const e=window.scrollY;this.handleModeSwitch(t.get("mode")),this.dispatchEvent(new CustomEvent("mode-changed",{detail:{mode:this.mode},bubbles:!0})),requestAnimationFrame(()=>window.scrollTo(0,e))}if(t.has("fullscreen")&&requestAnimationFrame(()=>this.monacoEditor?.layout()),t.has("disabled")||t.has("readonly")){const t=this.disabled||this.readonly;this.lexicalEditor?.setEditable(!t),this.monacoEditor?.updateOptions({readOnly:t})}(t.has("value")||t.has("required")||t.has("disabled"))&&this.#t()}#t=()=>{if(this.disabled)return void this.internals.setValidity({});const t=!(this.value||"").replace(/<[^>]+>/g,"").trim();this.required&&t?this.internals.setValidity({valueMissing:!0},"Please fill out this field.",this.lexicalContainer||this):this.internals.setValidity({})};async firstUpdated(){this.lexicalContainer=this.shadowRoot.querySelector(".lexical-editor"),this.monacoContainer=this.shadowRoot.querySelector(".monaco-editor-container"),await this.initLexical(),this.dispatchEvent(new CustomEvent("ready",{detail:{value:this.value},bubbles:!0}))}loadControls(){const t=this.constructor.controlSets[this.controls];t&&n.load(Object.values(t))}async loadNodeModules(){if(!this.nodes?.trim())return[];const t=new URL("./htmlEditorNodes/",import.meta.url).href;return(await Promise.all(this.nodes.split(",").map(t=>t.trim()).filter(Boolean).map(e=>import(`${t}${e}.js`)))).map(t=>t.default?.lexicalNode).filter(Boolean)}async loadLexicalModules(){const t=this.lexicalSrc||window.kempo?.lexicalUrl||"https://esm.sh",e=e=>((t,e)=>`${t}/${e}@0.43.0`)(t,e),[i,o,l,r,s,a,n,c,d]=await Promise.all([import(e("lexical")),import(e("@lexical/rich-text")),import(e("@lexical/html")),import(e("@lexical/history")),import(e("@lexical/list")),import(e("@lexical/link")),import(e("@lexical/selection")),import(e("@lexical/table")),import(e("@lexical/code"))]);this.lx={lexical:i,richText:o,lexicalHtml:l,history:r,list:s,link:a,selection:n,table:c,code:d},this.StyledTextNode=class extends i.TextNode{static getType(){return"styled-text"}static clone(t){return new this(t.__text,t.__key)}static importDOM(){return{span:()=>({conversion:t=>{const e=t.getAttribute("style");if(!e)return null;const o=i.$createTextNode(t.textContent);return o.setStyle(e),{node:o}},priority:1})}}static importJSON(t){return i.$createTextNode(t.text)}exportJSON(){return{...super.exportJSON(),type:"styled-text"}}}}async initLexical(){await this.loadLexicalModules(),this.customNodes=await this.loadNodeModules(),this.nodeCompatCheckers=this.customNodes.filter(t=>"function"==typeof t.isVisualCompatible).map(t=>t.isVisualCompatible),this.nodePreprocessors=this.customNodes.filter(t=>"function"==typeof t.preprocessHtml).map(t=>t.preprocessHtml);const{lexical:t,richText:e,history:i,list:o,link:l,table:r,code:s}=this.lx,a={namespace:"KempoHtmlEditor",theme:{paragraph:"k-editor-p",heading:{h1:"k-editor-h1",h2:"k-editor-h2",h3:"k-editor-h3",h4:"k-editor-h4",h5:"k-editor-h5",h6:"k-editor-h6"},text:{underline:"td-u",strikethrough:"td-lt"},list:{ul:"k-editor-ul",ol:"k-editor-ol",listitem:"k-editor-li"},link:"k-editor-link",quote:"k-editor-quote",code:"k-editor-code-block",codeHighlight:{},table:"k-editor-table",tableCell:"k-editor-table-cell",tableCellHeader:"k-editor-table-cell-header"},nodes:[e.HeadingNode,e.QuoteNode,o.ListNode,o.ListItemNode,l.LinkNode,r.TableNode,r.TableCellNode,r.TableRowNode,s.CodeNode,s.CodeHighlightNode,this.StyledTextNode,...this.customNodes],onError:console.error,editorState:null};this.lexicalEditor=t.createEditor(a),this.lexicalEditor.setRootElement(this.lexicalContainer),(this.disabled||this.readonly)&&this.lexicalEditor.setEditable(!1),this.lexicalEditor._window=new Proxy(window,{get:(t,e)=>{if("getSelection"===e)return()=>this.shadowRoot.getSelection();const i=Reflect.get(t,e);return"function"==typeof i?i.bind(t):i}}),this.cleanupFns=[e.registerRichText(this.lexicalEditor),i.registerHistory(this.lexicalEditor,i.createEmptyHistoryState(),300)],o.registerList&&this.cleanupFns.push(o.registerList(this.lexicalEditor)),r.registerTable&&this.cleanupFns.push(r.registerTable(this.lexicalEditor)),s.registerCodeHighlighting&&this.cleanupFns.push(s.registerCodeHighlighting(this.lexicalEditor)),l.registerLink&&this.cleanupFns.push(l.registerLink(this.lexicalEditor,{validateUrl:t=>{try{return new URL(t),!0}catch{return!1}}})),this.value&&(this.isVisualCompatible(this.value)?this.importHtmlToLexical(this.value):(this.skipLexicalExport=!0,this.mode="code")),this.lexicalEditor.registerUpdateListener(({dirtyElements:t,dirtyLeaves:e})=>{0===t.size&&0===e.size||(this.debouncedSyncValue(),this.dispatchEvent(new CustomEvent("input",{detail:{value:this.exportHtmlFromLexical()},bubbles:!0})))}),this.lexicalEditor.registerCommand(t.SELECTION_CHANGE_COMMAND,()=>(this.updateSelection(),!1),t.COMMAND_PRIORITY_LOW)}async initMonaco(){if(!this.monacoEditor){if(this.monacoInitPromise)return this.monacoInitPromise;this.monacoInitPromise=this._initMonaco(),await this.monacoInitPromise,this.monacoInitPromise=null}}async _initMonaco(){const t=this.monacoSrc||window.kempo?.monacoUrl||"https://cdn.jsdelivr.net/npm/monaco-editor@0.52.2/min";await new Promise((e,i)=>{if(window.monaco)return void e();if(window.require?.defined?.("vs/editor/editor.main"))return void e();const o=document.querySelector(`script[src="${t}/vs/loader.js"]`);if(o)return void o.addEventListener("load",()=>{window.require.config({paths:{vs:`${t}/vs`}}),window.require(["vs/editor/editor.main"],()=>e(),i)});const l=document.createElement("script");l.src=`${t}/vs/loader.js`,l.onload=()=>{window.require.config({paths:{vs:`${t}/vs`}}),window.require(["vs/editor/editor.main"],()=>e(),i)},l.onerror=i,document.head.appendChild(l)}),this.monacoEditor=window.monaco.editor.create(this.monacoContainer,{value:o(this.value),language:"html",theme:this.resolveMonacoTheme(),minimap:{enabled:this.minimapEnabled},wordWrap:this.wordWrap?"on":"off",fontSize:this.fontSize,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,padding:{top:8},readOnly:this.disabled||this.readonly});const e=document.querySelector('link[href*="monaco"][href*="editor.main.css"]');if(e){const t=document.createElement("link");t.rel="stylesheet",t.href=e.href,this.shadowRoot.appendChild(t)}this.unsubscribeTheme=s(()=>{this.monacoEditor&&"auto"===this.editorTheme&&window.monaco.editor.setTheme(this.resolveMonacoTheme())}),this.monacoEditor.onDidChangeModelContent(()=>{this.skipValueSync=!0,this.value=this.monacoEditor.getValue(),this.skipValueSync=!1,this.updateFormValue(),this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0})),this.dispatchEvent(new CustomEvent("input",{detail:{value:this.value},bubbles:!0}))})}importHtmlToLexical(t){if(!this.lexicalEditor||!this.lx.lexicalHtml)return;const{lexical:e,lexicalHtml:i}=this.lx,o=(this.nodePreprocessors||[]).reduce((t,e)=>e(t),t);this.lexicalEditor.update(()=>{if(e.$getRoot().clear(),!o?.trim())return;const t=(new DOMParser).parseFromString(o,"text/html"),l=i.$generateNodesFromDOM(this.lexicalEditor,t);l.length>0&&e.$insertNodes(l)},{discrete:!0})}exportHtmlFromLexical(){if(!this.lexicalEditor||!this.lx.lexicalHtml)return this.value;let t="";return this.lexicalEditor.getEditorState().read(()=>{t=this.lx.lexicalHtml.$generateHtmlFromNodes(this.lexicalEditor,null)}),this.cleanExportedHtml(t)}isVisualCompatible(t){if(!t?.trim())return!0;const e=new Set(["script","style","meta","link","head","iframe","object","embed","canvas","video","audio","form","input","button","select","textarea","fieldset","label","noscript","template","slot","svg","math"]),i=this.nodeCompatCheckers||[],o=(new DOMParser).parseFromString(t,"text/html"),l=document.createTreeWalker(o.body,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT);let r;for(;r=l.nextNode();)if(!i.some(t=>t(r))){if(r.nodeType===Node.COMMENT_NODE)return!1;if(e.has(r.tagName?.toLowerCase()))return!1}return!0}cleanExportedHtml(t){const e=(new DOMParser).parseFromString(t,"text/html");return e.body.querySelectorAll("[class]").forEach(t=>{const e=Array.from(t.classList).filter(t=>!t.startsWith("k-editor-")&&"td-u"!==t&&"td-lt"!==t);0===e.length?t.removeAttribute("class"):t.className=e.join(" ")}),e.body.querySelectorAll("[style]").forEach(t=>{const e=t.style.cssText.replace(/white-space:\s*pre-wrap;?\s*/g,"").trim();e?t.style.cssText=e:t.removeAttribute("style")}),e.body.querySelectorAll("span:not([class]):not([style]):not([id])").forEach(t=>{t.attributes.length||t.replaceWith(...t.childNodes)}),e.body.querySelectorAll("b > strong, i > em, b > b, strong > strong, i > i, em > em").forEach(t=>{t.replaceWith(...t.childNodes)}),e.body.querySelectorAll("pre[data-highlight-language], code[data-highlight-language]").forEach(t=>{t.removeAttribute("data-highlight-language"),t.removeAttribute("data-language")}),e.body.innerHTML}syncValueFromLexical(){this.lexicalEditor&&(this.lexicalValueSync=!0,this.value=this.exportHtmlFromLexical(),this.updateFormValue())}syncContentToEditors(){"visual"===this.mode&&this.lexicalEditor&&this.importHtmlToLexical(this.value)}async handleModeSwitch(t){"code"===this.mode?(this.lexicalEditor&&!this.skipLexicalExport&&(this.value=this.exportHtmlFromLexical()),this.skipLexicalExport=!1,await this.initMonaco(),this.monacoEditor&&(this.monacoEditor.setValue(o(this.value)),this.monacoEditor.layout())):"visual"===this.mode&&(this.monacoEditor&&(this.value=this.monacoEditor.getValue()),this.lexicalEditor&&this.importHtmlToLexical(this.value)),this.requestUpdate()}updateFormValue(){this.internals.setFormValue(this.getValue())}formResetCallback(){this.value=""}formStateRestoreCallback(t){this.value=t}formDisabledCallback(t){this.disabled=t}updateSelection=()=>{if("visual"!==this.mode||!this.lexicalEditor)return void(this.selection=null);const{lexical:t}=this.lx;this.lexicalEditor.getEditorState().read(()=>{const e=t.$getSelection();t.$isRangeSelection(e)&&!e.isCollapsed()?this.selection={text:e.getTextContent(),collapsed:!1}:(this.selection=null,this.cursor=e?{anchor:e.anchor,focus:e.focus}:null)})};setMode(t){return["visual","code"].includes(t)?"visual"!==t||this.isVisualCompatible(this.getValue())?(this.mode=t,this):(a.confirm("This html contains code that is not compatible with the visual editor, the incompatible code will be lost",e=>{e&&(this.mode=t)},{title:"Warning",confirmText:"Change Anyways"}),this):this}toggleMode(){return this.setMode("visual"===this.mode?"code":"visual")}getValue(){if("visual"===this.mode&&this.lexicalEditor)this.skipValueSync=!0,this.value=this.exportHtmlFromLexical(),this.skipValueSync=!1;else if("code"===this.mode&&this.monacoEditor)return this.monacoEditor.getValue();return this.value}setValue(t){return this.lexicalEditor&&"visual"===this.mode&&!this.isVisualCompatible(t)?(this.value=t,this.skipLexicalExport=!0,this.mode="code",this.updateFormValue(),this):(this.skipValueSync=!0,this.value=t,"visual"===this.mode?this.syncContentToEditors():"code"===this.mode&&this.monacoEditor&&this.monacoEditor.setValue(o(t)),this.updateFormValue(),this.skipValueSync=!1,this)}clear(){return this.setValue("")}bold(){return this.lexicalFormat("bold"),this}italic(){return this.lexicalFormat("italic"),this}underline(){return this.lexicalFormat("underline"),this}strikethrough(){return this.lexicalFormat("strikethrough"),this}inlineCode(){return this.lexicalFormat("code"),this}orderedList(){return"visual"===this.mode&&this.lexicalEditor?(this.lexicalEditor.update(()=>{this.lx.list.$insertList("number")},{discrete:!0}),this):this}unorderedList(){return"visual"===this.mode&&this.lexicalEditor?(this.lexicalEditor.update(()=>{this.lx.list.$insertList("bullet")},{discrete:!0}),this):this}bulletList(){return this.unorderedList()}numberList(){return this.orderedList()}toggleWordWrap(){return this.setWordWrap(!this.wordWrap)}toggleMinimap(){return this.setMinimap(!this.minimapEnabled)}formatCode(){return this.monacoEditor?.getAction("editor.action.formatDocument")?.run(),this}alignLeft(){return this.lexicalFormatElement("left"),this}alignCenter(){return this.lexicalFormatElement("center"),this}alignRight(){return this.lexicalFormatElement("right"),this}alignJustify(){return this.lexicalFormatElement("justify"),this}setTextColor(t){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:e,selection:i}=this.lx;return this.lexicalEditor.update(()=>{const o=e.$getSelection();e.$isRangeSelection(o)&&i.$patchStyleText(o,{color:t})},{discrete:!0}),this}removeTextColor(){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:t,selection:e}=this.lx;return this.lexicalEditor.update(()=>{const i=t.$getSelection();t.$isRangeSelection(i)&&e.$patchStyleText(i,{color:null})},{discrete:!0}),this}setTextBackgroundColor(t){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:e,selection:i}=this.lx;return this.lexicalEditor.update(()=>{const o=e.$getSelection();e.$isRangeSelection(o)&&i.$patchStyleText(o,{"background-color":t})},{discrete:!0}),this}removeTextBackgroundColor(){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:t,selection:e}=this.lx;return this.lexicalEditor.update(()=>{const i=t.$getSelection();t.$isRangeSelection(i)&&e.$patchStyleText(i,{"background-color":null})},{discrete:!0}),this}removeFormat(){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:t,selection:e}=this.lx;return this.lexicalEditor.update(()=>{const i=t.$getSelection();t.$isRangeSelection(i)&&(i.getNodes().forEach(e=>{t.$isTextNode(e)&&e.setFormat(0)}),e.$patchStyleText(i,{color:null,"background-color":null}))},{discrete:!0}),this}formatBlock(t){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:e,richText:i,code:o}=this.lx;return this.lexicalEditor.update(()=>{const l=e.$getSelection();if(!e.$isRangeSelection(l))return;const r=l.anchor.getNode().getTopLevelElementOrThrow(),s=o.$isCodeNode(r);let a;if("p"===t)a=e.$createParagraphNode();else if(t.match(/^h[1-6]$/))a=i.$createHeadingNode(t);else if("blockquote"===t)a=i.$createQuoteNode();else{if("pre"!==t)return;a=o.$createCodeNode()}if(s&&"pre"!==t){const t=r.getTextContent();r.replace(a),a.append(e.$createTextNode(t))}else{const t=r.getChildren();r.replace(a),t.forEach(t=>a.append(t))}a.selectEnd()},{discrete:!0}),this}isSelectionInCodeBlock(){if("visual"!==this.mode||!this.lexicalEditor)return!1;let t=!1;const{lexical:e,code:i}=this.lx;return this.lexicalEditor.getEditorState().read(()=>{const o=e.$getSelection();e.$isRangeSelection(o)&&(t=i.$isCodeNode(o.anchor.getNode().getTopLevelElementOrThrow()))}),t}getTableAtSelection(){if("visual"!==this.mode||!this.lexicalEditor)return null;let t=null;const{lexical:e,table:i}=this.lx;return this.lexicalEditor.getEditorState().read(()=>{const o=e.$getSelection();if(!e.$isRangeSelection(o))return;let l=o.anchor.getNode();for(;l;){if(i.$isTableNode(l)){const e=l.getChildren(),o=[];let r=!1,s=0;e.forEach((t,e)=>{const l=[];t.getChildren().forEach(t=>{0===e&&i.$isTableCellNode(t)&&t.getHeaderStyles()===i.TableCellHeaderStates.ROW&&(r=!0),l.push(t.getTextContent())}),l.length>s&&(s=l.length),o.push(l)}),t={key:l.getKey(),rows:r?e.length-1:e.length,cols:s,hasHeaders:r,cellData:o};break}l=l.getParent()}}),t}removeTableByKey(t){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:e}=this.lx;return this.lexicalEditor.update(()=>{const i=e.$getNodeByKey(t);i&&i.remove()},{discrete:!0}),this}insertHTML(t){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:e,lexicalHtml:i}=this.lx;return this.lexicalEditor.update(()=>{const o=(new DOMParser).parseFromString(t,"text/html"),l=i.$generateNodesFromDOM(this.lexicalEditor,o);e.$insertNodes(l)},{discrete:!0}),this}insertAtCursor(t){return this.insertHTML(t)}insertTable(t,e,i=!1,o=null){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:l,table:r}=this.lx;return this.lexicalEditor.update(()=>{const s=t+(i?1:0),a=[];for(let t=0;t<s;t++){const s=[];for(let a=0;a<e;a++){const e=i&&0===t,n=e?r.TableCellHeaderStates.ROW:r.TableCellHeaderStates.NO_STATUS,c=r.$createTableCellNode(n),d=o?.[t]?.[a]??(e?`Header ${a+1}`:""),h=l.$createParagraphNode();h.append(l.$createTextNode(d||" ")),c.append(h),s.push(c)}a.push(r.$createTableRowNode().append(...s))}const n=r.$createTableNode().append(...a),c=l.$getSelection();if(l.$isRangeSelection(c)){c.anchor.getNode().getTopLevelElementOrThrow().insertAfter(n);const t=l.$createParagraphNode();n.insertAfter(t),t.selectEnd()}else{const t=l.$getRoot();t.append(n),t.append(l.$createParagraphNode())}},{discrete:!0}),this}insertElementAtCursor(t){return this.insertHTML(t.outerHTML)}replaceSelectionWithElement(t){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:e,lexicalHtml:i}=this.lx;return this.lexicalEditor.update(()=>{const o=e.$getSelection();if(!e.$isRangeSelection(o))return;o.removeText();const l=(new DOMParser).parseFromString(t.outerHTML,"text/html"),r=i.$generateNodesFromDOM(this.lexicalEditor,l);e.$insertNodes(r)},{discrete:!0}),this}wrapSelection(t,e,i=null){if("visual"!==this.mode||!this.lexicalEditor)return this;const o=i||this.getSelectedText();return o?this.insertHTML(t+o+e):this}getSelection(){if("visual"!==this.mode||!this.lexicalEditor)return null;let t=null;const{lexical:e}=this.lx;return this.lexicalEditor.getEditorState().read(()=>{const i=e.$getSelection();e.$isRangeSelection(i)&&!i.isCollapsed()&&(t={text:i.getTextContent(),html:i.getTextContent(),selection:i})}),t}getSelectedText(){let t="";if("visual"!==this.mode||!this.lexicalEditor)return t;const{lexical:e}=this.lx;return this.lexicalEditor.getEditorState().read(()=>{const i=e.$getSelection();e.$isRangeSelection(i)&&(t=i.getTextContent())}),t}getSelectedHTML(){return this.getSelectedText()}selectAll(){if("visual"===this.mode&&this.lexicalEditor){const{lexical:t}=this.lx;this.lexicalEditor.update(()=>{t.$selectAll()},{discrete:!0})}else if(this.monacoEditor){const t=this.monacoEditor.getModel();t&&this.monacoEditor.setSelection(t.getFullModelRange())}return this}replaceSelection(t){return this.insertHTML(t)}deleteSelection(){return"visual"===this.mode?this.lexicalCmd("DELETE_CHARACTER_COMMAND",!1):this.monacoEditor&&this.monacoEditor.trigger("keyboard","deleteAllLeft",null),this}getValueWithSelectionMarkers(){if("visual"!==this.mode||!this.lexicalEditor)return{html:this.value,hasCursor:!1,hasSelection:!1,selectedText:""};let t={html:this.exportHtmlFromLexical(),hasCursor:!1,hasSelection:!1,selectedText:""};const{lexical:e}=this.lx;return this.lexicalEditor.getEditorState().read(()=>{const i=e.$getSelection();e.$isRangeSelection(i)&&(i.isCollapsed()?t.hasCursor=!0:(t.hasSelection=!0,t.selectedText=i.getTextContent()))}),t}setValueFromSelectionMarkers(t){return this.setValue(t)}captureSelection(){return this.selection}restoreSavedSelection(){return!1}clearSavedSelection(){this.savedSelection=null}createLink(t){if("visual"!==this.mode||!this.lexicalEditor)return this;const{link:e}=this.lx;return this.lexicalEditor.update(()=>{e.$toggleLink(t)},{discrete:!0}),this}createLinkWithText(t,e){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:i,link:o}=this.lx;return this.lexicalEditor.update(()=>{const l=i.$getSelection();i.$isRangeSelection(l)&&!l.isCollapsed()&&l.removeText();const r=o.$createLinkNode(t);r.append(i.$createTextNode(e)),i.$insertNodes([r])},{discrete:!0}),this}unlink(){if("visual"!==this.mode||!this.lexicalEditor)return this;const{lexical:t,link:e}=this.lx;return this.lexicalEditor.update(()=>{const i=t.$getSelection();t.$isRangeSelection(i)&&i.getNodes().forEach(t=>{const i=t.getParent();i&&e.$isLinkNode?.(i)&&(i.getChildren().forEach(t=>i.insertBefore(t)),i.remove())})},{discrete:!0}),this}insertImage(t){return this.insertHTML(`<img src="${encodeURI(t)}" />`)}undo(){return"code"===this.mode?this.monacoEditor?.trigger("toolbar","undo"):this.lexicalCmd("UNDO_COMMAND",void 0),this}redo(){return"code"===this.mode?this.monacoEditor?.trigger("toolbar","redo"):this.lexicalCmd("REDO_COMMAND",void 0),this}copyToClipboard(){return navigator.clipboard.writeText(this.getValue()),this}setEditorTheme(t){return["auto","light","dark"].includes(t)&&(this.editorTheme=t),this.monacoEditor&&window.monaco.editor.setTheme(this.resolveMonacoTheme()),this}openFind(){return this.monacoEditor?.getAction("actions.find")?.run(),this}foldAll(){return this.monacoEditor?.getAction("editor.foldAll")?.run(),this}unfoldAll(){return this.monacoEditor?.getAction("editor.unfoldAll")?.run(),this}enterFullscreen(){return this.fullscreen=!0,document.body.classList.add("no-scroll"),this.dispatchEvent(new CustomEvent("fullscreen-changed",{detail:{fullscreen:!0},bubbles:!0})),this}exitFullscreen(){return this.fullscreen=!1,document.body.classList.remove("no-scroll"),this.dispatchEvent(new CustomEvent("fullscreen-changed",{detail:{fullscreen:!1},bubbles:!0})),this}toggleFullscreen(){return this.fullscreen?this.exitFullscreen():this.enterFullscreen()}increaseFontSize(){return this.fontSize=Math.min(this.fontSize+2,40),this.monacoEditor?.updateOptions({fontSize:this.fontSize}),this}decreaseFontSize(){return this.fontSize=Math.max(this.fontSize-2,8),this.monacoEditor?.updateOptions({fontSize:this.fontSize}),this}setWordWrap(t){return this.wordWrap=t,this.monacoEditor?.updateOptions({wordWrap:t?"on":"off"}),this}setMinimap(t){return this.minimapEnabled=t,this.monacoEditor?.updateOptions({minimap:{enabled:t}}),this}resolveMonacoTheme(){return"dark"===this.editorTheme?"vs-dark":"light"===this.editorTheme?"vs":"dark"===r()?"vs-dark":"vs"}lexicalCmd(t,e){if("visual"!==this.mode||!this.lexicalEditor)return;const i=this.lx.lexical?.[t];i&&this.lexicalEditor.dispatchCommand(i,e)}lexicalFormat(t){if("visual"!==this.mode||!this.lexicalEditor)return;const{lexical:e}=this.lx;this.lexicalEditor.update(()=>{const i=e.$getSelection();e.$isRangeSelection(i)&&i.formatText(t)},{discrete:!0})}lexicalFormatElement(t){"visual"===this.mode&&this.lexicalEditor&&this.lexicalEditor.dispatchCommand(this.lx.lexical.FORMAT_ELEMENT_COMMAND,t)}render(){const e=this.constructor.controlSets[this.controls]??{};return t`
|
|
2
|
+
${this.hasTopToolbar?t`
|
|
3
3
|
<div class="toolbar-top bb">
|
|
4
4
|
<div class="toolbar-start">
|
|
5
|
-
<slot name="toolbar-top-left">${
|
|
5
|
+
<slot name="toolbar-top-left">${e.topLeft??""}</slot>
|
|
6
6
|
</div>
|
|
7
7
|
<div class="toolbar-end">
|
|
8
|
-
<slot name="toolbar-top-right">${
|
|
8
|
+
<slot name="toolbar-top-right">${e.topRight??""}</slot>
|
|
9
9
|
</div>
|
|
10
10
|
</div>
|
|
11
11
|
`:""}
|
|
@@ -20,17 +20,17 @@ import{html as e,css as t}from"../lit-all.min.js";import i from"./ShadowComponen
|
|
|
20
20
|
?hidden=${"code"!==this.mode}
|
|
21
21
|
></div>
|
|
22
22
|
</div>
|
|
23
|
-
${this.hasBottomToolbar?
|
|
23
|
+
${this.hasBottomToolbar?t`
|
|
24
24
|
<div class="toolbar-bottom bt">
|
|
25
25
|
<div class="toolbar-start">
|
|
26
|
-
<slot name="toolbar-bottom-left">${
|
|
26
|
+
<slot name="toolbar-bottom-left">${e.bottomLeft??""}</slot>
|
|
27
27
|
</div>
|
|
28
28
|
<div class="toolbar-end">
|
|
29
|
-
<slot name="toolbar-bottom-right">${
|
|
29
|
+
<slot name="toolbar-bottom-right">${e.bottomRight??""}</slot>
|
|
30
30
|
</div>
|
|
31
31
|
</div>
|
|
32
32
|
`:""}
|
|
33
|
-
`}static styles=
|
|
33
|
+
`}static styles=e`
|
|
34
34
|
:host {
|
|
35
35
|
display: flex;
|
|
36
36
|
flex-direction: column;
|
|
@@ -40,10 +40,9 @@ import{html as e,css as t}from"../lit-all.min.js";import i from"./ShadowComponen
|
|
|
40
40
|
}
|
|
41
41
|
:host([fullscreen]) {
|
|
42
42
|
position: fixed;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
height: 100vh !important;
|
|
43
|
+
inset: 0;
|
|
44
|
+
width: auto;
|
|
45
|
+
height: auto;
|
|
47
46
|
z-index: 10000;
|
|
48
47
|
}
|
|
49
48
|
:host([disabled]) {
|
|
@@ -177,102 +176,102 @@ import{html as e,css as t}from"../lit-all.min.js";import i from"./ShadowComponen
|
|
|
177
176
|
.monaco-editor-container {
|
|
178
177
|
border: 1px solid var(--border-color);
|
|
179
178
|
}
|
|
180
|
-
`;static
|
|
181
|
-
<k-
|
|
182
|
-
<
|
|
183
|
-
<
|
|
184
|
-
<
|
|
185
|
-
</k-
|
|
186
|
-
<k-
|
|
187
|
-
<
|
|
188
|
-
<
|
|
189
|
-
</k-
|
|
190
|
-
`,topRight:null,bottomLeft:null,bottomRight:null},normal:{topLeft:
|
|
191
|
-
<k-
|
|
192
|
-
<
|
|
193
|
-
<
|
|
194
|
-
<
|
|
195
|
-
<
|
|
196
|
-
</k-
|
|
197
|
-
<
|
|
198
|
-
<
|
|
179
|
+
`;static controlSets={minimal:{topLeft:t`
|
|
180
|
+
<k-control-group>
|
|
181
|
+
<kc-bold></kc-bold>
|
|
182
|
+
<kc-italic></kc-italic>
|
|
183
|
+
<kc-underline></kc-underline>
|
|
184
|
+
</k-control-group>
|
|
185
|
+
<k-control-group>
|
|
186
|
+
<kc-bullet-list></kc-bullet-list>
|
|
187
|
+
<kc-number-list></kc-number-list>
|
|
188
|
+
</k-control-group>
|
|
189
|
+
`,topRight:null,bottomLeft:null,bottomRight:null},normal:{topLeft:t`
|
|
190
|
+
<k-control-group>
|
|
191
|
+
<kc-bold></kc-bold>
|
|
192
|
+
<kc-italic></kc-italic>
|
|
193
|
+
<kc-underline></kc-underline>
|
|
194
|
+
<kc-strikethrough></kc-strikethrough>
|
|
195
|
+
</k-control-group>
|
|
196
|
+
<kc-inline-code></kc-inline-code>
|
|
197
|
+
<kc-menu>
|
|
199
198
|
<k-icon slot="icon" name="format_paragraph"></k-icon>
|
|
200
199
|
<span slot="label">Text Style</span>
|
|
201
|
-
<
|
|
202
|
-
<
|
|
203
|
-
<
|
|
204
|
-
<
|
|
205
|
-
<
|
|
206
|
-
<
|
|
207
|
-
</
|
|
208
|
-
<k-
|
|
209
|
-
<
|
|
210
|
-
<
|
|
211
|
-
</k-
|
|
212
|
-
`,topRight:
|
|
213
|
-
<k-
|
|
214
|
-
<
|
|
215
|
-
<
|
|
216
|
-
<
|
|
217
|
-
</k-
|
|
218
|
-
<
|
|
219
|
-
<
|
|
220
|
-
<
|
|
221
|
-
`,bottomLeft:
|
|
222
|
-
<k-
|
|
223
|
-
<
|
|
224
|
-
<
|
|
225
|
-
<
|
|
226
|
-
<
|
|
227
|
-
</k-
|
|
228
|
-
<
|
|
229
|
-
<
|
|
200
|
+
<kc-format-block tag="p">Paragraph</kc-format-block>
|
|
201
|
+
<kc-format-block tag="h1">Heading 1</kc-format-block>
|
|
202
|
+
<kc-format-block tag="h2">Heading 2</kc-format-block>
|
|
203
|
+
<kc-format-block tag="h3">Heading 3</kc-format-block>
|
|
204
|
+
<kc-format-block tag="blockquote">Blockquote</kc-format-block>
|
|
205
|
+
<kc-code-block></kc-code-block>
|
|
206
|
+
</kc-menu>
|
|
207
|
+
<k-control-group>
|
|
208
|
+
<kc-bullet-list></kc-bullet-list>
|
|
209
|
+
<kc-number-list></kc-number-list>
|
|
210
|
+
</k-control-group>
|
|
211
|
+
`,topRight:t`
|
|
212
|
+
<k-control-group>
|
|
213
|
+
<kc-align-left></kc-align-left>
|
|
214
|
+
<kc-align-center></kc-align-center>
|
|
215
|
+
<kc-align-right></kc-align-right>
|
|
216
|
+
</k-control-group>
|
|
217
|
+
<kc-create-link></kc-create-link>
|
|
218
|
+
<kc-format-code></kc-format-code>
|
|
219
|
+
<kc-mode></kc-mode>
|
|
220
|
+
`,bottomLeft:t`<kc-word-count></kc-word-count>`,bottomRight:null},full:{topLeft:t`
|
|
221
|
+
<k-control-group>
|
|
222
|
+
<kc-bold></kc-bold>
|
|
223
|
+
<kc-italic></kc-italic>
|
|
224
|
+
<kc-underline></kc-underline>
|
|
225
|
+
<kc-strikethrough></kc-strikethrough>
|
|
226
|
+
</k-control-group>
|
|
227
|
+
<kc-inline-code></kc-inline-code>
|
|
228
|
+
<kc-menu>
|
|
230
229
|
<k-icon slot="icon" name="format_paragraph"></k-icon>
|
|
231
230
|
<span slot="label">Text Style</span>
|
|
232
|
-
<
|
|
233
|
-
<
|
|
234
|
-
<
|
|
235
|
-
<
|
|
236
|
-
<
|
|
237
|
-
<
|
|
238
|
-
</
|
|
239
|
-
<k-
|
|
240
|
-
<
|
|
241
|
-
<
|
|
242
|
-
</k-
|
|
243
|
-
<k-
|
|
244
|
-
<
|
|
245
|
-
<
|
|
246
|
-
</k-
|
|
247
|
-
<k-
|
|
248
|
-
<
|
|
249
|
-
<
|
|
250
|
-
<
|
|
251
|
-
</k-
|
|
252
|
-
<k-
|
|
253
|
-
<
|
|
254
|
-
<
|
|
255
|
-
<
|
|
256
|
-
</k-
|
|
257
|
-
<
|
|
258
|
-
`,topRight:
|
|
259
|
-
<k-
|
|
260
|
-
<
|
|
261
|
-
<
|
|
262
|
-
<
|
|
263
|
-
<
|
|
264
|
-
</k-
|
|
265
|
-
<
|
|
266
|
-
<k-
|
|
267
|
-
<
|
|
268
|
-
<
|
|
269
|
-
</k-
|
|
270
|
-
<
|
|
271
|
-
<
|
|
272
|
-
<
|
|
273
|
-
<
|
|
274
|
-
<
|
|
275
|
-
`,bottomLeft:
|
|
276
|
-
<
|
|
277
|
-
<
|
|
231
|
+
<kc-format-block tag="p">Paragraph</kc-format-block>
|
|
232
|
+
<kc-format-block tag="h1">Heading 1</kc-format-block>
|
|
233
|
+
<kc-format-block tag="h2">Heading 2</kc-format-block>
|
|
234
|
+
<kc-format-block tag="h3">Heading 3</kc-format-block>
|
|
235
|
+
<kc-format-block tag="blockquote">Blockquote</kc-format-block>
|
|
236
|
+
<kc-code-block></kc-code-block>
|
|
237
|
+
</kc-menu>
|
|
238
|
+
<k-control-group>
|
|
239
|
+
<kc-bullet-list></kc-bullet-list>
|
|
240
|
+
<kc-number-list></kc-number-list>
|
|
241
|
+
</k-control-group>
|
|
242
|
+
<k-control-group>
|
|
243
|
+
<kc-undo></kc-undo>
|
|
244
|
+
<kc-redo></kc-redo>
|
|
245
|
+
</k-control-group>
|
|
246
|
+
<k-control-group>
|
|
247
|
+
<kc-format-code></kc-format-code>
|
|
248
|
+
<kc-copy-code></kc-copy-code>
|
|
249
|
+
<kc-find-replace></kc-find-replace>
|
|
250
|
+
</k-control-group>
|
|
251
|
+
<k-control-group>
|
|
252
|
+
<kc-word-wrap></kc-word-wrap>
|
|
253
|
+
<kc-minimap></kc-minimap>
|
|
254
|
+
<kc-fold-all></kc-fold-all>
|
|
255
|
+
</k-control-group>
|
|
256
|
+
<kc-font-size></kc-font-size>
|
|
257
|
+
`,topRight:t`
|
|
258
|
+
<k-control-group>
|
|
259
|
+
<kc-align-left></kc-align-left>
|
|
260
|
+
<kc-align-center></kc-align-center>
|
|
261
|
+
<kc-align-right></kc-align-right>
|
|
262
|
+
<kc-align-justify></kc-align-justify>
|
|
263
|
+
</k-control-group>
|
|
264
|
+
<kc-create-link></kc-create-link>
|
|
265
|
+
<k-control-group>
|
|
266
|
+
<kc-text-color></kc-text-color>
|
|
267
|
+
<kc-text-background-color></kc-text-background-color>
|
|
268
|
+
</k-control-group>
|
|
269
|
+
<kc-clear-formatting></kc-clear-formatting>
|
|
270
|
+
<kc-insert-table></kc-insert-table>
|
|
271
|
+
<kc-editor-theme></kc-editor-theme>
|
|
272
|
+
<kc-mode></kc-mode>
|
|
273
|
+
<kc-fullscreen></kc-fullscreen>
|
|
274
|
+
`,bottomLeft:t`
|
|
275
|
+
<kc-word-count></kc-word-count>
|
|
276
|
+
<kc-character-count></kc-character-count>
|
|
278
277
|
`,bottomRight:null},"":{topLeft:null,topRight:null,bottomLeft:null,bottomRight:null}}}customElements.define("k-html-editor",c);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{html as t,css as e,nothing as i}from"../lit-all.min.js";import
|
|
1
|
+
import{html as t,css as e,nothing as i}from"../lit-all.min.js";import s from"./ShadowComponent.js";import l from"../utils/renderMarkdown.js";import o,{STRIP_COMPLETELY as n}from"../utils/sanitizeHtml.js";import a from"../utils/debounce.js";import r from"./controls/Control.js";import"./Resize.js";import"./Tabs.js";const c=Symbol(),h=Symbol(),d=Symbol(),u=Symbol();export default class b extends s{static formAssociated=!0;static properties={value:{type:String},name:{type:String,reflect:!0},placeholder:{type:String,reflect:!0},disabled:{type:Boolean,reflect:!0},required:{type:Boolean,reflect:!0},readonly:{type:Boolean,reflect:!0},mode:{type:String,reflect:!0},allowedTags:{type:String,reflect:!0,attribute:"allowed-tags"},disallowedTags:{type:String,reflect:!0,attribute:"disallowed-tags"},scriptsEnabled:{type:Boolean,reflect:!0,attribute:"scripts-enabled"},controls:{type:String,reflect:!0}};constructor(){super(),this.internals=this.attachInternals(),this.value="",this.name="",this.placeholder="",this.disabled=!1,this.required=!1,this.readonly=!1,this.mode="write",this.allowedTags="",this.disallowedTags="",this.scriptsEnabled=!1,this.controls="",this[c]="",this[h]=a(()=>this.handleChange(),300)}loadControls(){const t=this.constructor.controlSets[this.controls];t&&r.load(Object.values(t))}connectedCallback(){super.connectedCallback(),this.hasAttribute("controlled")||this.setAttribute("controlled",""),this.hasAttribute("value")&&(this[c]=this.getAttribute("value")),!this.value&&this[c]&&(this.value=this[c])}updated(t){super.updated(t),t.has("value")&&this.internals.setFormValue(this.value),t.has("controls")&&this.controls&&"none"!==this.controls&&this.loadControls(),this[u]()}formResetCallback(){this.value=this[c],this.mode="write"}formStateRestoreCallback(t){"string"==typeof t&&(this.value=t)}formDisabledCallback(t){this.disabled=t}focus(){"write"!==this.mode&&(this.mode="write"),this.updateComplete.then(()=>{this.shadowRoot?.querySelector("textarea")?.focus()})}blur(){this.shadowRoot?.querySelector("textarea")?.blur()}clear(){this.value=""}setMode(t){"write"!==t&&"preview"!==t||(this.mode=t)}togglePreview(){this.mode="write"===this.mode?"preview":"write"}get textarea(){return this.shadowRoot?.querySelector("textarea")||null}getSelection(){const t=this.textarea;return t?{start:t.selectionStart,end:t.selectionEnd,text:t.value.substring(t.selectionStart,t.selectionEnd)}:{start:0,end:0,text:""}}replaceSelection(t,{selectInserted:e=!0}={}){const i=this.textarea;i&&("write"!==this.mode&&(this.mode="write"),this.updateComplete.then(()=>{i.focus();const{selectionStart:s,selectionEnd:l}=i,o=i.value.substring(0,s),n=i.value.substring(l),a=o+t+n;i.value=a;const r=s+t.length;i.selectionStart=e?s:r,i.selectionEnd=r,this.value=a,i.dispatchEvent(new Event("input",{bubbles:!0}))}))}wrapSelection(t,e=t,i=""){const s=this.textarea;s?("write"!==this.mode&&(this.mode="write"),this.updateComplete.then(()=>{s.focus();const{selectionStart:l,selectionEnd:o,value:n}=s,a=n.substring(l,o);if(a.length>=t.length+e.length&&a.startsWith(t)&&a.endsWith(e)){const i=a.slice(t.length,a.length-e.length),r=n.substring(0,l)+i+n.substring(o);return s.value=r,s.selectionStart=l,s.selectionEnd=l+i.length,this.value=r,void s.dispatchEvent(new Event("input",{bubbles:!0}))}const r=n.substring(Math.max(0,l-t.length),l),c=n.substring(o,Math.min(n.length,o+e.length));if(r===t&&c===e){const i=n.substring(0,l-t.length)+a+n.substring(o+e.length);return s.value=i,s.selectionStart=l-t.length,s.selectionEnd=s.selectionStart+a.length,this.value=i,void s.dispatchEvent(new Event("input",{bubbles:!0}))}const h=a||i,d=n.substring(0,l)+t+h+e+n.substring(o);s.value=d;const u=l+t.length;s.selectionStart=u,s.selectionEnd=u+h.length,this.value=d,s.dispatchEvent(new Event("input",{bubbles:!0}))})):this.replaceSelection(t+i+e)}insertAtCursor(t){this.replaceSelection(t,{selectInserted:!1})}replaceInSelectedLines(t,e=""){const i=this.textarea;i&&("write"!==this.mode&&(this.mode="write"),this.updateComplete.then(()=>{i.focus();const{selectionStart:s,selectionEnd:l,value:o}=i,n=o.lastIndexOf("\n",s-1)+1,a=o.indexOf("\n",l),r=-1===a?o.length:a,c=o.substring(n,r),h=c.split("\n").map(i=>i.replace(t,e)).join("\n");if(h===c)return;const d=o.substring(0,n)+h+o.substring(r);i.value=d,i.selectionStart=n,i.selectionEnd=n+h.length,this.value=d,i.dispatchEvent(new Event("input",{bubbles:!0}))}))}insertLinePrefix(t,e=null){const i=this.textarea;i&&("write"!==this.mode&&(this.mode="write"),this.updateComplete.then(()=>{i.focus();const{selectionStart:s,selectionEnd:l,value:o}=i,n=o.lastIndexOf("\n",s-1)+1,a=o.indexOf("\n",l),r=-1===a?o.length:a,c=o.substring(n,r).split("\n"),h=c.filter(t=>t.length>0),d=h.length>0&&h.every(e=>e.startsWith(t)),u=c.map(i=>0===i.length?i:d?i.startsWith(t)?i.slice(t.length):i:i.startsWith(t)?i:e&&e.test(i)?i.replace(e,t):t+i).join("\n"),b=o.substring(0,n)+u+o.substring(r);i.value=b,i.selectionStart=n,i.selectionEnd=n+u.length,this.value=b,i.dispatchEvent(new Event("input",{bubbles:!0}))}))}bold(){return this.wrapSelection("**","**","bold text"),this}italic(){return this.wrapSelection("_","_","italic text"),this}strikethrough(){return this.wrapSelection("~~","~~","strikethrough"),this}inlineCode(){return this.getSelection().text.includes("\n")?this.wrapSelection("```\n","\n```","code"):this.wrapSelection("`","`","code"),this}quote(){return this.insertLinePrefix("> "),this}bulletList(){return this.insertLinePrefix("- "),this}numberList(){const t=this.textarea;return t?("write"!==this.mode&&(this.mode="write"),this.updateComplete.then(()=>{t.focus();const{selectionStart:e,selectionEnd:i,value:s}=t,l=s.lastIndexOf("\n",e-1)+1,o=s.indexOf("\n",i),n=-1===o?s.length:o,a=s.substring(l,n).split("\n"),r=/^\d+\. /,c=a.filter(t=>t.length>0);let h;if(c.length>0&&c.every(t=>r.test(t)))h=a.map(t=>t.replace(r,""));else{let t=1;h=a.map(e=>{if(!e)return e;const i=e.replace(r,"");return`${t++}. ${i}`})}const d=h.join("\n"),u=s.substring(0,l)+d+s.substring(n);t.value=u,t.selectionStart=l,t.selectionEnd=l+d.length,this.value=u,t.dispatchEvent(new Event("input",{bubbles:!0}))}),this):this}formatBlock(t){const e=(t||"").toLowerCase();if(/^h[1-6]$/.test(e)){const t=parseInt(e.slice(1),10);this.insertLinePrefix("#".repeat(t)+" ",/^#{1,6} /)}else"blockquote"===e?this.quote():"pre"===e&&this.wrapSelection("```\n","\n```","code");return this}get isEmpty(){return!(this.value||"").trim()}get renderedHtml(){const t={},e=this[d];if(e&&(t.allowedTags=e),this.scriptsEnabled){const e=new Set(n);e.delete("SCRIPT"),t.stripCompletely=e}return o(l(this.value||""),t)}get[d](){const t=(this.allowedTags||"").trim(),e=(this.disallowedTags||"").trim();if(t&&e&&console.warn("[k-markdown-editor] `allowed-tags` and `disallowed-tags` are mutually exclusive; using `allowed-tags`."),t)return"*"===t?{has:()=>!0}:new Set(t.split(",").map(t=>t.trim().toUpperCase()).filter(Boolean));if(e){const t=new Set(e.split(",").map(t=>t.trim().toUpperCase()).filter(Boolean));return{has:e=>!t.has(e)}}return null}[u]=()=>{const t=this.shadowRoot?.querySelector("textarea");this.required&&this.isEmpty?this.internals.setValidity({valueMissing:!0},"Please fill out this field.",t):this.internals.setValidity({})};handleInput=t=>{this.value=t.target.value,this.dispatchEvent(new CustomEvent("input",{detail:{value:this.value},bubbles:!0})),this[h]()};handleChange=()=>{this.dispatchEvent(new CustomEvent("change",{detail:{value:this.value},bubbles:!0}))};handleTabChange=t=>{const e=t.detail?.tab;e&&e!==this.mode&&(this.mode=e,this.dispatchEvent(new CustomEvent("mode-changed",{detail:{mode:e},bubbles:!0})))};render(){const e=this.constructor.controlSets[this.controls]??this.constructor.controlSets[""];return t`
|
|
2
2
|
<k-resize dimension="height" ?disabled=${this.disabled}>
|
|
3
3
|
<div class="frame">
|
|
4
4
|
<k-tabs fixed-height active=${this.mode} @tab=${this.handleTabChange}>
|
|
@@ -120,53 +120,53 @@ import{html as t,css as e,nothing as i}from"../lit-all.min.js";import l from"./S
|
|
|
120
120
|
.footer:not(:has(::slotted(*))) {
|
|
121
121
|
display: none;
|
|
122
122
|
}
|
|
123
|
-
`;static
|
|
124
|
-
<
|
|
125
|
-
<k-icon slot="
|
|
126
|
-
<
|
|
127
|
-
<
|
|
128
|
-
<
|
|
129
|
-
</
|
|
130
|
-
<
|
|
131
|
-
<
|
|
132
|
-
<
|
|
133
|
-
<
|
|
123
|
+
`;static controlSets={"":{top:null,bottom:null},none:{top:null,bottom:null},minimal:{top:t`
|
|
124
|
+
<kc-menu>
|
|
125
|
+
<k-icon slot="icon" name="text_fields"></k-icon>
|
|
126
|
+
<kc-format-block tag="h1"></kc-format-block>
|
|
127
|
+
<kc-format-block tag="h3"></kc-format-block>
|
|
128
|
+
<kc-format-block tag="h5"></kc-format-block>
|
|
129
|
+
</kc-menu>
|
|
130
|
+
<kc-bold></kc-bold>
|
|
131
|
+
<kc-italic></kc-italic>
|
|
132
|
+
<kc-bullet-list></kc-bullet-list>
|
|
133
|
+
<kc-number-list></kc-number-list>
|
|
134
134
|
`,bottom:null},normal:{top:t`
|
|
135
|
-
<
|
|
136
|
-
<k-icon slot="
|
|
137
|
-
<
|
|
138
|
-
<
|
|
139
|
-
<
|
|
140
|
-
<
|
|
141
|
-
<
|
|
142
|
-
<
|
|
143
|
-
</
|
|
144
|
-
<
|
|
145
|
-
<
|
|
146
|
-
<
|
|
147
|
-
<
|
|
148
|
-
<
|
|
149
|
-
<
|
|
150
|
-
<
|
|
135
|
+
<kc-menu>
|
|
136
|
+
<k-icon slot="icon" name="text_fields"></k-icon>
|
|
137
|
+
<kc-format-block tag="h1"></kc-format-block>
|
|
138
|
+
<kc-format-block tag="h2"></kc-format-block>
|
|
139
|
+
<kc-format-block tag="h3"></kc-format-block>
|
|
140
|
+
<kc-format-block tag="h4"></kc-format-block>
|
|
141
|
+
<kc-format-block tag="h5"></kc-format-block>
|
|
142
|
+
<kc-format-block tag="h6"></kc-format-block>
|
|
143
|
+
</kc-menu>
|
|
144
|
+
<kc-bold></kc-bold>
|
|
145
|
+
<kc-italic></kc-italic>
|
|
146
|
+
<kc-quote></kc-quote>
|
|
147
|
+
<kc-inline-code></kc-inline-code>
|
|
148
|
+
<kc-md-link></kc-md-link>
|
|
149
|
+
<kc-bullet-list></kc-bullet-list>
|
|
150
|
+
<kc-number-list></kc-number-list>
|
|
151
151
|
`,bottom:null},full:{top:t`
|
|
152
|
-
<
|
|
153
|
-
<k-icon slot="
|
|
154
|
-
<
|
|
155
|
-
<
|
|
156
|
-
<
|
|
157
|
-
<
|
|
158
|
-
<
|
|
159
|
-
<
|
|
160
|
-
</
|
|
161
|
-
<
|
|
162
|
-
<
|
|
163
|
-
<
|
|
164
|
-
<
|
|
165
|
-
<
|
|
166
|
-
<
|
|
167
|
-
<
|
|
168
|
-
<
|
|
169
|
-
<
|
|
170
|
-
<
|
|
171
|
-
<
|
|
172
|
-
`,bottom:null}}}customElements.define("k-markdown-editor",
|
|
152
|
+
<kc-menu>
|
|
153
|
+
<k-icon slot="icon" name="text_fields"></k-icon>
|
|
154
|
+
<kc-format-block tag="h1"></kc-format-block>
|
|
155
|
+
<kc-format-block tag="h2"></kc-format-block>
|
|
156
|
+
<kc-format-block tag="h3"></kc-format-block>
|
|
157
|
+
<kc-format-block tag="h4"></kc-format-block>
|
|
158
|
+
<kc-format-block tag="h5"></kc-format-block>
|
|
159
|
+
<kc-format-block tag="h6"></kc-format-block>
|
|
160
|
+
</kc-menu>
|
|
161
|
+
<kc-bold></kc-bold>
|
|
162
|
+
<kc-italic></kc-italic>
|
|
163
|
+
<kc-strikethrough></kc-strikethrough>
|
|
164
|
+
<kc-quote></kc-quote>
|
|
165
|
+
<kc-inline-code></kc-inline-code>
|
|
166
|
+
<kc-md-link></kc-md-link>
|
|
167
|
+
<kc-md-image></kc-md-image>
|
|
168
|
+
<kc-md-table></kc-md-table>
|
|
169
|
+
<kc-bullet-list></kc-bullet-list>
|
|
170
|
+
<kc-number-list></kc-number-list>
|
|
171
|
+
<kc-md-speech-to-text></kc-md-speech-to-text>
|
|
172
|
+
`,bottom:null}}}customElements.define("k-markdown-editor",b);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{html as t,css as e,nothing as s}from"../lit-all.min.js";import a from"./ShadowComponent.js";import{bound as i,closest as r}from"../utils/number.js";import{commaSeparatedArray as o}from"../utils/propConverters.js";export default class
|
|
1
|
+
import{html as t,css as e,nothing as s}from"../lit-all.min.js";import a from"./ShadowComponent.js";import{bound as i,closest as r}from"../utils/number.js";import{commaSeparatedArray as o}from"../utils/propConverters.js";import l from"./controls/Control.js";export default class g extends a{static properties={page:{type:Number,reflect:!0,attribute:"page"},totalItems:{type:Number,reflect:!0,attribute:"total-items"},itemsPerPage:{type:Number,reflect:!0,attribute:"items-per-page"},controls:{type:String,reflect:!0},pageSizes:{converter:o(t=>{const e=parseInt(t);return isNaN(e)?null:e},[5,10,25,50,100]),reflect:!0,attribute:"page-sizes"}};constructor(){super(),this.page=1,this.totalItems=0,this.itemsPerPage=10,this.pageSizes=[5,10,25,50,100],this.controls=""}connectedCallback(){super.connectedCallback(),this.hasAttribute("controlled")||this.setAttribute("controlled","")}loadControls(){const t=this.constructor.controlSets[this.controls];t&&l.load(Object.values(t))}willUpdate(t){t.forEach((t,e)=>{const s=this[e];switch(e){case"pageSizes":void 0===s?this.pageSizes=[5,10,25,50,100]:this.itemsPerPage=r(this.itemsPerPage,this.pageSizes);break;case"itemsPerPage":void 0===s?this.itemsPerPage=this.pageSizes?.[0]||10:(this.itemsPerPage=r(this.itemsPerPage,this.pageSizes),void 0!==t&&(this.page=Math.ceil(((this.page-1)*t+1)/this.itemsPerPage)));break;case"totalItems":if(void 0===s)this.totalItems=0;else{const t=Math.max(1,Math.ceil(this.totalItems/this.itemsPerPage));this.page>t&&(this.page=t)}break;case"page":if(void 0===s)this.page=1;else{const t=i(this.page,1,this.totalPages);t!==this.page&&(this.page=t)}break;case"controls":void 0===s&&(this.controls="")}})}updated(t){super.updated(t);(t.has("page")&&void 0!==t.get("page")||t.has("itemsPerPage")&&void 0!==t.get("itemsPerPage"))&&this.dispatchEvent(new CustomEvent("page-change",{detail:{currentPage:this.page,totalPages:this.totalPages,itemsPerPage:this.itemsPerPage,totalItems:this.totalItems},bubbles:!0})),t.has("controls")&&this.controls&&"none"!==this.controls&&this.loadControls()}get totalPages(){return this.totalItems&&this.itemsPerPage?Math.ceil(this.totalItems/this.itemsPerPage):1}nextPage(){this.page=i(this.page+1,1,this.totalPages)}previousPage(){this.page=i(this.page-1,1,this.totalPages)}render(){const e=this.constructor.controlSets[this.controls];return t`
|
|
2
2
|
<div id="controls" aria-label="Pagination">
|
|
3
3
|
<div class="left">
|
|
4
4
|
<slot>${e?.left??s}</slot>
|
|
@@ -30,14 +30,14 @@ import{html as t,css as e,nothing as s}from"../lit-all.min.js";import a from"./S
|
|
|
30
30
|
flex-wrap: wrap;
|
|
31
31
|
margin-left: auto;
|
|
32
32
|
}
|
|
33
|
-
`;static
|
|
34
|
-
<
|
|
35
|
-
<
|
|
36
|
-
<
|
|
33
|
+
`;static controlSets={"":{left:null,right:null},none:{left:null,right:null},simple:{left:t`
|
|
34
|
+
<kc-pg-prev></kc-pg-prev>
|
|
35
|
+
<kc-pg-page-info></kc-pg-page-info>
|
|
36
|
+
<kc-pg-next></kc-pg-next>
|
|
37
37
|
`,right:null},full:{left:t`
|
|
38
|
-
<
|
|
39
|
-
<
|
|
40
|
-
<
|
|
41
|
-
<
|
|
42
|
-
<
|
|
43
|
-
`,right:t`<
|
|
38
|
+
<kc-pg-first></kc-pg-first>
|
|
39
|
+
<kc-pg-prev></kc-pg-prev>
|
|
40
|
+
<kc-pg-goto-page></kc-pg-goto-page>
|
|
41
|
+
<kc-pg-next></kc-pg-next>
|
|
42
|
+
<kc-pg-last></kc-pg-last>
|
|
43
|
+
`,right:t`<kc-pg-items-per-page></kc-pg-items-per-page>`}}}window.customElements.define("k-pagination",g);
|