@firstnoodle-ui/bui 0.0.26 → 0.0.28
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/LICENSE +21 -21
- package/dist/bui.css +1 -1
- package/dist/components/calendar-view/CalendarView.vue.d.ts +21 -0
- package/dist/components/calendar-view/components/DateButton.vue.d.ts +10 -0
- package/dist/components/calendar-view/components/DecadeView.vue.d.ts +12 -0
- package/dist/components/calendar-view/components/MonthView.vue.d.ts +17 -0
- package/dist/components/calendar-view/components/YearView.vue.d.ts +13 -0
- package/dist/components/calendar-view/composables/useCalendar.d.ts +44 -0
- package/dist/components/calendar-view/index.d.ts +1 -0
- package/dist/components/calendar-view/utils/enums.d.ts +29 -0
- package/dist/components/calendar-view/utils/index.d.ts +23 -0
- package/dist/components/calendar-view/utils/types.d.ts +12 -0
- package/dist/components/calendar-view/utils/utils/calendar.d.ts +22 -0
- package/dist/components/calendar-view/utils/utils/date.d.ts +15 -0
- package/dist/components/calendar-view/utils/utils/format.d.ts +18 -0
- package/dist/components/calendar-view/utils/utils/time.d.ts +35 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/notification-badge/NotificationBadge.vue.d.ts +5 -0
- package/dist/components/notification-badge/index.d.ts +1 -0
- package/dist/components/select-list/components/option-group/OptionGroup.vue.d.ts +1 -0
- package/dist/components/select-list/components/select-list-option/SelectListOption.vue.d.ts +1 -0
- package/dist/components/select-list/types.d.ts +1 -0
- package/dist/components/types.d.ts +1 -1
- package/dist/index.mjs +7056 -6465
- package/dist/utils/capitalizeFirstLetter.d.ts +1 -0
- package/package.json +4 -3
- package/src/components/application-wrapper/ApplicationWrapper.vue +8 -0
- package/src/components/application-wrapper/index.ts +1 -0
- package/src/components/aside-section-label/AsideSectionLabel.vue +16 -0
- package/src/components/aside-section-label/index.ts +1 -0
- package/src/components/button/Button.vue +246 -0
- package/src/components/button/NotificationBadge.vue +15 -0
- package/src/components/button/components/button-label/ButtonLabel.vue +9 -0
- package/src/components/button/components/button-label/index.ts +1 -0
- package/src/components/button/components/index.ts +3 -0
- package/src/components/button/components/left-group/LeftGroup.vue +5 -0
- package/src/components/button/components/left-group/index.ts +1 -0
- package/src/components/button/components/notification-badge/NotificationBadge.vue +17 -0
- package/src/components/button/components/notification-badge/index.ts +1 -0
- package/src/components/button/index.ts +1 -0
- package/src/components/button-group/ButtonGroup.vue +97 -0
- package/src/components/button-group/index.ts +1 -0
- package/src/components/calendar-view/CalendarView.vue +106 -0
- package/src/components/calendar-view/components/DateButton.vue +23 -0
- package/src/components/calendar-view/components/DecadeView.vue +50 -0
- package/src/components/calendar-view/components/MonthView.vue +72 -0
- package/src/components/calendar-view/components/NavButton.vue +16 -0
- package/src/components/calendar-view/components/YearView.vue +52 -0
- package/src/components/calendar-view/composables/useCalendar.ts +138 -0
- package/src/components/calendar-view/index.ts +1 -0
- package/src/components/calendar-view/utils/enums.ts +31 -0
- package/src/components/calendar-view/utils/index.ts +240 -0
- package/src/components/calendar-view/utils/types.ts +13 -0
- package/src/components/calendar-view/utils/utils/calendar.ts +70 -0
- package/src/components/calendar-view/utils/utils/date.ts +130 -0
- package/src/components/calendar-view/utils/utils/format.ts +61 -0
- package/src/components/calendar-view/utils/utils/time.ts +70 -0
- package/src/components/checkbox/Checkbox.vue +51 -0
- package/src/components/checkbox/CircleIndicator.vue +26 -0
- package/src/components/checkbox/DefaultIndicator.vue +19 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/collapse/Collapse.vue +114 -0
- package/src/components/collapse/index.ts +1 -0
- package/src/components/confirm-cancel/ConfirmCancel.vue +66 -0
- package/src/components/confirm-cancel/index.ts +1 -0
- package/src/components/confirm-cancel/types.ts +18 -0
- package/src/components/content-slider/ContentSlider.vue +79 -0
- package/src/components/content-slider/index.ts +1 -0
- package/src/components/data-point/DataPoint.vue +5 -0
- package/src/components/data-point/index.ts +1 -0
- package/src/components/delete-button/DeleteButton.vue +19 -0
- package/src/components/delete-button/index.ts +1 -0
- package/src/components/dialog/Dialog.vue +70 -0
- package/src/components/dialog/index.ts +1 -0
- package/src/components/fade-in-up/FadeInUp.vue +17 -0
- package/src/components/fade-in-up/index.ts +1 -0
- package/src/components/filter-chip/FilterChip.vue +28 -0
- package/src/components/filter-chip/index.ts +1 -0
- package/src/components/first-paint/FirstPaint.vue +21 -0
- package/src/components/first-paint/index.ts +1 -0
- package/src/components/first-paint/style.scss +23 -0
- package/src/components/flexbox/Flexbox.vue +51 -0
- package/src/components/flexbox/index.ts +1 -0
- package/src/components/horizontal-layout/Aside.vue +114 -0
- package/src/components/horizontal-layout/HorizontalLayout.vue +118 -0
- package/src/components/horizontal-layout/index.ts +2 -0
- package/src/components/icon/Icon.vue +1263 -0
- package/src/components/icon/index.ts +1 -0
- package/src/components/icon/utils/combine-svgs.cjs +55 -0
- package/src/components/icon/utils/combined-svgs.txt +1150 -0
- package/src/components/icon/utils/svgs/admin.svg +16 -0
- package/src/components/icon/utils/svgs/arrow-deviate.svg +3 -0
- package/src/components/icon/utils/svgs/arrow-down-plus.svg +4 -0
- package/src/components/icon/utils/svgs/arrow-down.svg +3 -0
- package/src/components/icon/utils/svgs/arrow-from.svg +3 -0
- package/src/components/icon/utils/svgs/arrow-left.svg +3 -0
- package/src/components/icon/utils/svgs/arrow-move.svg +15 -0
- package/src/components/icon/utils/svgs/arrow-right.svg +3 -0
- package/src/components/icon/utils/svgs/arrow-sub.svg +3 -0
- package/src/components/icon/utils/svgs/arrow-trend.svg +15 -0
- package/src/components/icon/utils/svgs/arrow-up-plus.svg +4 -0
- package/src/components/icon/utils/svgs/arrow-up.svg +3 -0
- package/src/components/icon/utils/svgs/authority.svg +5 -0
- package/src/components/icon/utils/svgs/beams.svg +5 -0
- package/src/components/icon/utils/svgs/bell.svg +15 -0
- package/src/components/icon/utils/svgs/bold.svg +3 -0
- package/src/components/icon/utils/svgs/box.svg +5 -0
- package/src/components/icon/utils/svgs/building.svg +15 -0
- package/src/components/icon/utils/svgs/bullet-list.svg +8 -0
- package/src/components/icon/utils/svgs/calendar.svg +21 -0
- package/src/components/icon/utils/svgs/camera.svg +5 -0
- package/src/components/icon/utils/svgs/categories.svg +3 -0
- package/src/components/icon/utils/svgs/check-circled.svg +16 -0
- package/src/components/icon/utils/svgs/check-outline.svg +15 -0
- package/src/components/icon/utils/svgs/check.svg +3 -0
- package/src/components/icon/utils/svgs/chevron-down.svg +3 -0
- package/src/components/icon/utils/svgs/chevron-left-double.svg +4 -0
- package/src/components/icon/utils/svgs/chevron-left.svg +3 -0
- package/src/components/icon/utils/svgs/chevron-right-double.svg +4 -0
- package/src/components/icon/utils/svgs/chevron-right.svg +3 -0
- package/src/components/icon/utils/svgs/chevron-up.svg +3 -0
- package/src/components/icon/utils/svgs/clock.svg +4 -0
- package/src/components/icon/utils/svgs/close-outline.svg +3 -0
- package/src/components/icon/utils/svgs/close.svg +3 -0
- package/src/components/icon/utils/svgs/columns.svg +3 -0
- package/src/components/icon/utils/svgs/conclusion.svg +17 -0
- package/src/components/icon/utils/svgs/copy.svg +16 -0
- package/src/components/icon/utils/svgs/crosshair.svg +15 -0
- package/src/components/icon/utils/svgs/dash.svg +3 -0
- package/src/components/icon/utils/svgs/dashboard.svg +3 -0
- package/src/components/icon/utils/svgs/delete.svg +4 -0
- package/src/components/icon/utils/svgs/delta.svg +3 -0
- package/src/components/icon/utils/svgs/download.svg +3 -0
- package/src/components/icon/utils/svgs/drag.svg +8 -0
- package/src/components/icon/utils/svgs/drilldown.svg +8 -0
- package/src/components/icon/utils/svgs/edit.svg +16 -0
- package/src/components/icon/utils/svgs/envelope.svg +3 -0
- package/src/components/icon/utils/svgs/error.svg +3 -0
- package/src/components/icon/utils/svgs/export-document.svg +16 -0
- package/src/components/icon/utils/svgs/filter.svg +6 -0
- package/src/components/icon/utils/svgs/filters.svg +4 -0
- package/src/components/icon/utils/svgs/flag.svg +3 -0
- package/src/components/icon/utils/svgs/folder.svg +15 -0
- package/src/components/icon/utils/svgs/frequency.svg +3 -0
- package/src/components/icon/utils/svgs/fullscreen-off.svg +3 -0
- package/src/components/icon/utils/svgs/fullscreen-on.svg +3 -0
- package/src/components/icon/utils/svgs/graduate.svg +3 -0
- package/src/components/icon/utils/svgs/hamburger.svg +5 -0
- package/src/components/icon/utils/svgs/handshake.svg +15 -0
- package/src/components/icon/utils/svgs/heading-1.svg +4 -0
- package/src/components/icon/utils/svgs/heading-2.svg +4 -0
- package/src/components/icon/utils/svgs/heading.svg +3 -0
- package/src/components/icon/utils/svgs/home.svg +3 -0
- package/src/components/icon/utils/svgs/id-card.svg +6 -0
- package/src/components/icon/utils/svgs/id.svg +4 -0
- package/src/components/icon/utils/svgs/indent-left.svg +7 -0
- package/src/components/icon/utils/svgs/indent-right.svg +7 -0
- package/src/components/icon/utils/svgs/information.svg +17 -0
- package/src/components/icon/utils/svgs/italics.svg +3 -0
- package/src/components/icon/utils/svgs/itenary.svg +11 -0
- package/src/components/icon/utils/svgs/keyboard.svg +11 -0
- package/src/components/icon/utils/svgs/lightning.svg +15 -0
- package/src/components/icon/utils/svgs/link.svg +4 -0
- package/src/components/icon/utils/svgs/list-collapse.svg +6 -0
- package/src/components/icon/utils/svgs/list-expand.svg +6 -0
- package/src/components/icon/utils/svgs/location.svg +4 -0
- package/src/components/icon/utils/svgs/lock-locked.svg +4 -0
- package/src/components/icon/utils/svgs/lock-unlocked.svg +4 -0
- package/src/components/icon/utils/svgs/magnifying-glass.svg +15 -0
- package/src/components/icon/utils/svgs/map.svg +3 -0
- package/src/components/icon/utils/svgs/megaphone.svg +3 -0
- package/src/components/icon/utils/svgs/message.svg +15 -0
- package/src/components/icon/utils/svgs/microscope.svg +3 -0
- package/src/components/icon/utils/svgs/moon.svg +3 -0
- package/src/components/icon/utils/svgs/new-document.svg +4 -0
- package/src/components/icon/utils/svgs/news.svg +15 -0
- package/src/components/icon/utils/svgs/numbered-list.svg +7 -0
- package/src/components/icon/utils/svgs/open-link.svg +16 -0
- package/src/components/icon/utils/svgs/options.svg +5 -0
- package/src/components/icon/utils/svgs/page.svg +7 -0
- package/src/components/icon/utils/svgs/paper-plane.svg +15 -0
- package/src/components/icon/utils/svgs/paper.svg +3 -0
- package/src/components/icon/utils/svgs/pen-and-paper.svg +4 -0
- package/src/components/icon/utils/svgs/phase.svg +15 -0
- package/src/components/icon/utils/svgs/photo.svg +4 -0
- package/src/components/icon/utils/svgs/pie-chart.svg +3 -0
- package/src/components/icon/utils/svgs/plus.svg +3 -0
- package/src/components/icon/utils/svgs/point-left.svg +3 -0
- package/src/components/icon/utils/svgs/point-up.svg +3 -0
- package/src/components/icon/utils/svgs/popup.svg +16 -0
- package/src/components/icon/utils/svgs/question.svg +17 -0
- package/src/components/icon/utils/svgs/radio-tower.svg +3 -0
- package/src/components/icon/utils/svgs/recycle.svg +3 -0
- package/src/components/icon/utils/svgs/redo.svg +3 -0
- package/src/components/icon/utils/svgs/refresh.svg +3 -0
- package/src/components/icon/utils/svgs/route.svg +3 -0
- package/src/components/icon/utils/svgs/rows.svg +3 -0
- package/src/components/icon/utils/svgs/scope.svg +7 -0
- package/src/components/icon/utils/svgs/settings.svg +16 -0
- package/src/components/icon/utils/svgs/share.svg +11 -0
- package/src/components/icon/utils/svgs/sign-in.svg +4 -0
- package/src/components/icon/utils/svgs/sign-up.svg +3 -0
- package/src/components/icon/utils/svgs/sort-down.svg +20 -0
- package/src/components/icon/utils/svgs/sort-up.svg +20 -0
- package/src/components/icon/utils/svgs/sort.svg +7 -0
- package/src/components/icon/utils/svgs/square-solid.svg +3 -0
- package/src/components/icon/utils/svgs/star-solid.svg +15 -0
- package/src/components/icon/utils/svgs/star.svg +15 -0
- package/src/components/icon/utils/svgs/stop-watch.svg +5 -0
- package/src/components/icon/utils/svgs/structure.svg +3 -0
- package/src/components/icon/utils/svgs/sun.svg +23 -0
- package/src/components/icon/utils/svgs/table.svg +3 -0
- package/src/components/icon/utils/svgs/tag.svg +15 -0
- package/src/components/icon/utils/svgs/team.svg +15 -0
- package/src/components/icon/utils/svgs/telescope.svg +15 -0
- package/src/components/icon/utils/svgs/trash.svg +6 -0
- package/src/components/icon/utils/svgs/triangle-angle.svg +3 -0
- package/src/components/icon/utils/svgs/triangle-side.svg +3 -0
- package/src/components/icon/utils/svgs/underline.svg +4 -0
- package/src/components/icon/utils/svgs/undo.svg +3 -0
- package/src/components/icon/utils/svgs/user.svg +16 -0
- package/src/components/icon/utils/svgs/venn.svg +3 -0
- package/src/components/icon/utils/svgs/video.svg +3 -0
- package/src/components/icon/utils/svgs/visibility-off-alt.svg +19 -0
- package/src/components/icon/utils/svgs/visibility-off.svg +3 -0
- package/src/components/icon/utils/svgs/visibility-on.svg +16 -0
- package/src/components/icon/utils/svgs/warning.svg +5 -0
- package/src/components/index.ts +45 -0
- package/src/components/input/Input.vue +118 -0
- package/src/components/input/index.ts +1 -0
- package/src/components/input-number/InputNumber.vue +112 -0
- package/src/components/input-number/StepButton.vue +23 -0
- package/src/components/input-number/index.ts +1 -0
- package/src/components/load-spinner/LoadSpinner.vue +13 -0
- package/src/components/load-spinner/index.ts +1 -0
- package/src/components/modal/Modal.vue +111 -0
- package/src/components/modal/index.ts +1 -0
- package/src/components/nav-item/NavItem.vue +62 -0
- package/src/components/nav-item/index.ts +1 -0
- package/src/components/notification/Notification.vue +53 -0
- package/src/components/notification/index.ts +1 -0
- package/src/components/notification-badge/NotificationBadge.vue +7 -0
- package/src/components/notification-badge/index.ts +1 -0
- package/src/components/pagination/Pagination.vue +65 -0
- package/src/components/pagination/index.ts +1 -0
- package/src/components/pop-confirm/PopConfirm.vue +90 -0
- package/src/components/pop-confirm/index.ts +1 -0
- package/src/components/pop-select/FooterButton.vue +5 -0
- package/src/components/pop-select/PopSelect.vue +346 -0
- package/src/components/pop-select/ResultFilters.vue +28 -0
- package/src/components/pop-select/enums.ts +7 -0
- package/src/components/pop-select/index.ts +2 -0
- package/src/components/pop-select/option.vue +51 -0
- package/src/components/popper/Popper.vue +239 -0
- package/src/components/popper/PopperContent.vue +5 -0
- package/src/components/popper/index.ts +2 -0
- package/src/components/popper/middleware.ts +19 -0
- package/src/components/screen-overlay/ScreenOverlay.vue +53 -0
- package/src/components/screen-overlay/index.ts +1 -0
- package/src/components/scrollbar/Bar.vue +106 -0
- package/src/components/scrollbar/ScrollBottomLoader.vue +25 -0
- package/src/components/scrollbar/Scrollbar.vue +219 -0
- package/src/components/scrollbar/enums.ts +23 -0
- package/src/components/scrollbar/index.ts +3 -0
- package/src/components/scrollbar/style.scss +77 -0
- package/src/components/scrollbar/types.ts +32 -0
- package/src/components/select-list/SelectList.vue +476 -0
- package/src/components/select-list/components/SelectListFilterChip.vue +34 -0
- package/src/components/select-list/components/index.ts +3 -0
- package/src/components/select-list/components/option-group/OptionGroup.vue +20 -0
- package/src/components/select-list/components/option-group/index.ts +1 -0
- package/src/components/select-list/components/select-list-option/SelectListOption.vue +83 -0
- package/src/components/select-list/components/select-list-option/index.ts +1 -0
- package/src/components/select-list/components/status-cards/error-card/ErrorCard.vue +17 -0
- package/src/components/select-list/components/status-cards/error-card/index.ts +1 -0
- package/src/components/select-list/components/status-cards/idle-card/IdleCard.vue +11 -0
- package/src/components/select-list/components/status-cards/idle-card/index.ts +1 -0
- package/src/components/select-list/components/status-cards/index.ts +4 -0
- package/src/components/select-list/components/status-cards/loading-card/LoadingCard.vue +10 -0
- package/src/components/select-list/components/status-cards/loading-card/index.ts +1 -0
- package/src/components/select-list/components/status-cards/no-match-card/NoMatchCard.vue +15 -0
- package/src/components/select-list/components/status-cards/no-match-card/index.ts +1 -0
- package/src/components/select-list/components/status-cards/status-card/StatusCard.vue +25 -0
- package/src/components/select-list/components/status-cards/status-card/index.ts +1 -0
- package/src/components/select-list/index.ts +5 -0
- package/src/components/select-list/types.ts +49 -0
- package/src/components/side-over/SideOver.vue +87 -0
- package/src/components/side-over/index.ts +1 -0
- package/src/components/status-select/StatusIndicator.vue +78 -0
- package/src/components/status-select/StatusSelect.vue +62 -0
- package/src/components/status-select/index.ts +1 -0
- package/src/components/switch/Switch.vue +52 -0
- package/src/components/switch/index.ts +1 -0
- package/src/components/tab/Tab.vue +65 -0
- package/src/components/tab/index.ts +1 -0
- package/src/components/tag/Tag.vue +34 -0
- package/src/components/tag/index.ts +1 -0
- package/src/components/text-editor/TextEditor.vue +399 -0
- package/src/components/text-editor/components/Dialog.vue +11 -0
- package/src/components/text-editor/components/FormattingButton.vue +46 -0
- package/src/components/text-editor/components/InsertLinkDialog.vue +81 -0
- package/src/components/text-editor/components/InsertTextDialog.vue +36 -0
- package/src/components/text-editor/components/index.ts +3 -0
- package/src/components/text-editor/index.ts +1 -0
- package/src/components/text-highlight/TextHighlight.vue +113 -0
- package/src/components/text-highlight/index.ts +1 -0
- package/src/components/text-viewer/TextViewer.vue +5 -0
- package/src/components/text-viewer/index.ts +1 -0
- package/src/components/toggle-button/ToggleButton.vue +105 -0
- package/src/components/toggle-button/index.ts +1 -0
- package/src/components/tooltip/Tooltip.vue +54 -0
- package/src/components/tooltip/index.ts +1 -0
- package/src/components/types.ts +232 -0
- package/src/components/vertical-layout/RunningSection.vue +54 -0
- package/src/components/vertical-layout/VerticalLayout.vue +37 -0
- package/src/components/vertical-layout/index.ts +3 -0
- package/src/components/vertical-layout/types.ts +2 -0
- package/src/components/window-frame/WindowFrame.vue +20 -0
- package/src/components/window-frame/index.ts +1 -0
- package/src/composables/index.ts +5 -0
- package/src/composables/useClickOutside.ts +48 -0
- package/src/composables/useEscapeKey.ts +12 -0
- package/src/composables/useMounted.ts +7 -0
- package/src/composables/useNextFrame.ts +10 -0
- package/src/composables/useTrapFocus.ts +61 -0
- package/src/index.ts +5 -0
- package/src/main.css +140 -0
- package/src/utils/array.ts +11 -0
- package/src/utils/capitalizeFirstLetter.ts +4 -0
- package/src/utils/clamp.ts +9 -0
- package/src/utils/debounce.ts +8 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/scrollIntoView.ts +25 -0
- package/src/utils/scrollbarWidth.ts +27 -0
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { TIcon } from "../types";
|
|
3
|
+
import bold from "@tiptap/extension-bold";
|
|
4
|
+
import bulletList from "@tiptap/extension-bullet-list";
|
|
5
|
+
import Document from "@tiptap/extension-document";
|
|
6
|
+
import heading from "@tiptap/extension-heading";
|
|
7
|
+
import highlight from "@tiptap/extension-highlight";
|
|
8
|
+
|
|
9
|
+
import history from "@tiptap/extension-history";
|
|
10
|
+
|
|
11
|
+
import italic from "@tiptap/extension-italic";
|
|
12
|
+
|
|
13
|
+
import link from "@tiptap/extension-link";
|
|
14
|
+
import listItem from "@tiptap/extension-list-item";
|
|
15
|
+
|
|
16
|
+
import orderedList from "@tiptap/extension-ordered-list";
|
|
17
|
+
import Paragraph from "@tiptap/extension-paragraph";
|
|
18
|
+
import Placeholder from "@tiptap/extension-placeholder";
|
|
19
|
+
import Text from "@tiptap/extension-text";
|
|
20
|
+
import underline from "@tiptap/extension-underline";
|
|
21
|
+
import { EditorContent, useEditor } from "@tiptap/vue-3";
|
|
22
|
+
|
|
23
|
+
import { computed, onBeforeUnmount, ref } from "vue";
|
|
24
|
+
import { BFlexbox, BIcon } from "../";
|
|
25
|
+
import { useClickOutside } from "../../";
|
|
26
|
+
import FormattingButton from "./components/FormattingButton.vue";
|
|
27
|
+
|
|
28
|
+
import InsertLinkDialog from "./components/InsertLinkDialog.vue";
|
|
29
|
+
import InsertTextDialog from "./components/InsertTextDialog.vue";
|
|
30
|
+
|
|
31
|
+
const props = withDefaults(
|
|
32
|
+
defineProps<{
|
|
33
|
+
autoHideMenu?: boolean;
|
|
34
|
+
embedded?: boolean;
|
|
35
|
+
content: string;
|
|
36
|
+
editorContentClasses?: string;
|
|
37
|
+
editorContentFocusClasses?: string;
|
|
38
|
+
emphasis?: boolean;
|
|
39
|
+
expandVertically?: boolean;
|
|
40
|
+
headerIcon?: TIcon;
|
|
41
|
+
headerLabel?: string;
|
|
42
|
+
heading?: boolean;
|
|
43
|
+
highlight?: boolean;
|
|
44
|
+
history?: boolean;
|
|
45
|
+
insert?: boolean;
|
|
46
|
+
insertIcon?: TIcon;
|
|
47
|
+
insertLabel?: string;
|
|
48
|
+
insertTooltip?: string;
|
|
49
|
+
link?: boolean;
|
|
50
|
+
listStyles?: boolean;
|
|
51
|
+
minimal?: boolean;
|
|
52
|
+
placeholder?: string;
|
|
53
|
+
showMenu?: boolean;
|
|
54
|
+
}>(),
|
|
55
|
+
{
|
|
56
|
+
autoHideMenu: false,
|
|
57
|
+
editorContentClasses: "p-2 bg-1",
|
|
58
|
+
editorContentFocusClasses: "p-2 bg-1",
|
|
59
|
+
embedded: false,
|
|
60
|
+
emphasis: false,
|
|
61
|
+
expandVertically: false,
|
|
62
|
+
heading: false,
|
|
63
|
+
highlight: false,
|
|
64
|
+
history: false,
|
|
65
|
+
insert: false,
|
|
66
|
+
insertIcon: "download",
|
|
67
|
+
insertLabel: "Insert text",
|
|
68
|
+
insertTooltip: "Insert text",
|
|
69
|
+
link: false,
|
|
70
|
+
listStyles: false,
|
|
71
|
+
minimal: false,
|
|
72
|
+
showMenu: undefined,
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const emit = defineEmits(["blur", "change", "focus"]);
|
|
77
|
+
|
|
78
|
+
const editorFocussed = ref(false);
|
|
79
|
+
const softFocus = ref(false);
|
|
80
|
+
const showInsertTextDialog = ref(false);
|
|
81
|
+
const showLinkDialog = ref(false);
|
|
82
|
+
const editorRef = ref<HTMLDivElement>();
|
|
83
|
+
|
|
84
|
+
const { disableClickOutside, enableClickOutside } = useClickOutside(() => (softFocus.value = false));
|
|
85
|
+
|
|
86
|
+
const editor = useEditor({
|
|
87
|
+
content: props.content,
|
|
88
|
+
extensions: [
|
|
89
|
+
bold,
|
|
90
|
+
bulletList,
|
|
91
|
+
heading,
|
|
92
|
+
highlight,
|
|
93
|
+
history,
|
|
94
|
+
italic,
|
|
95
|
+
link,
|
|
96
|
+
listItem,
|
|
97
|
+
orderedList,
|
|
98
|
+
underline,
|
|
99
|
+
Document,
|
|
100
|
+
Paragraph,
|
|
101
|
+
Text,
|
|
102
|
+
Placeholder.configure({
|
|
103
|
+
placeholder: props.placeholder || "",
|
|
104
|
+
}),
|
|
105
|
+
],
|
|
106
|
+
onCreate: () => {
|
|
107
|
+
if (editorRef.value) {
|
|
108
|
+
enableClickOutside([editorRef.value]);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
onUpdate: ({ editor }) => emit("change", editor.getHTML()),
|
|
112
|
+
onFocus: () => {
|
|
113
|
+
editorFocussed.value = softFocus.value = true;
|
|
114
|
+
emit("focus");
|
|
115
|
+
},
|
|
116
|
+
onBlur: () => {
|
|
117
|
+
editorFocussed.value = false;
|
|
118
|
+
emit("blur");
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
onBeforeUnmount(() => disableClickOutside());
|
|
123
|
+
|
|
124
|
+
const menuVisible = computed(() => {
|
|
125
|
+
if (props.showMenu !== undefined) return props.showMenu;
|
|
126
|
+
return softFocus.value || !props.autoHideMenu;
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const headerClass = computed(() => {
|
|
130
|
+
return softFocus.value ? "bg-1 border-b border-default opacity-100" : "bg-2 border-b border-subtle opacity-50";
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const menuClass = computed(() => {
|
|
134
|
+
return softFocus.value ? "bg-2 border-t border-default opacity-100" : "bg-2 border-t border-subtle opacity-50";
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const focusPositions = ["start", "end", "all"] as const;
|
|
138
|
+
type TFocusPosition = (typeof focusPositions)[number];
|
|
139
|
+
|
|
140
|
+
const focus = (position: TFocusPosition) => {
|
|
141
|
+
const validatedPosition = focusPositions.includes(position) ? position : "end";
|
|
142
|
+
editor.value?.commands.focus(validatedPosition);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const blur = () => {
|
|
146
|
+
editor.value?.commands.blur();
|
|
147
|
+
softFocus.value = false;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const onCancelInsertLink = () => (showLinkDialog.value = false);
|
|
151
|
+
const onEditorMenuClick = () => (softFocus.value = true);
|
|
152
|
+
const onLinkInserted = () => (showLinkDialog.value = false);
|
|
153
|
+
const insertContent = (value: string) => editor.value?.commands.insertContent(value);
|
|
154
|
+
const onInsertText = (value: string) => {
|
|
155
|
+
insertContent(value);
|
|
156
|
+
showInsertTextDialog.value = false;
|
|
157
|
+
};
|
|
158
|
+
const onAddLink = () => (showLinkDialog.value = true);
|
|
159
|
+
const onAddText = () => (showInsertTextDialog.value = true);
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* For parent component
|
|
163
|
+
*/
|
|
164
|
+
const closeInsert = () => (showInsertTextDialog.value = false);
|
|
165
|
+
const setContent = (value: string) => editor.value?.commands.setContent(value);
|
|
166
|
+
|
|
167
|
+
defineExpose({ blur, closeInsert, focus, setContent });
|
|
168
|
+
</script>
|
|
169
|
+
|
|
170
|
+
<template>
|
|
171
|
+
<section v-if="editor" ref="editorRef" class="relative w-full">
|
|
172
|
+
<BFlexbox
|
|
173
|
+
col
|
|
174
|
+
align="stretch"
|
|
175
|
+
class="relative rounded-lg font-normal focus-within:border-default"
|
|
176
|
+
:class="{
|
|
177
|
+
'border': !embedded,
|
|
178
|
+
'flex-1 min-h-0': expandVertically,
|
|
179
|
+
'shadow-sm-outline border-action': softFocus,
|
|
180
|
+
'border-transparent': !softFocus && embedded,
|
|
181
|
+
'border-subtle': !softFocus && !embedded,
|
|
182
|
+
}"
|
|
183
|
+
>
|
|
184
|
+
<BFlexbox
|
|
185
|
+
v-if="headerLabel || headerIcon"
|
|
186
|
+
tag="header"
|
|
187
|
+
class="flex-0 h-10 px-3 gap-2 text-sm text-primary rounded-t-lg overflow-hidden"
|
|
188
|
+
:class="headerClass"
|
|
189
|
+
>
|
|
190
|
+
<BIcon v-if="headerIcon" :name="headerIcon" />
|
|
191
|
+
<span v-if="headerLabel">{{ headerLabel }}</span>
|
|
192
|
+
</BFlexbox>
|
|
193
|
+
<BFlexbox tag="main" align="start" fullwidth>
|
|
194
|
+
<EditorContent
|
|
195
|
+
class="flex-1 overflow-y-auto rounded-t-lg focus:outline-hidden"
|
|
196
|
+
:class="{
|
|
197
|
+
[editorContentClasses]: !softFocus,
|
|
198
|
+
[editorContentFocusClasses]: softFocus,
|
|
199
|
+
}"
|
|
200
|
+
:editor="editor"
|
|
201
|
+
/>
|
|
202
|
+
</BFlexbox>
|
|
203
|
+
<nav v-if="menuVisible" class="flex-0 min-h-0 p-1 rounded-b-lg overflow-hidden" :class="menuClass">
|
|
204
|
+
<BFlexbox justify="between">
|
|
205
|
+
<BFlexbox class="gap-0.5">
|
|
206
|
+
<template v-if="history">
|
|
207
|
+
<FormattingButton
|
|
208
|
+
icon="undo"
|
|
209
|
+
tooltip="Undo"
|
|
210
|
+
@click="
|
|
211
|
+
editor!.chain().focus().undo().run();
|
|
212
|
+
onEditorMenuClick();
|
|
213
|
+
"
|
|
214
|
+
/>
|
|
215
|
+
<FormattingButton
|
|
216
|
+
icon="redo"
|
|
217
|
+
tooltip="Redo"
|
|
218
|
+
@click="
|
|
219
|
+
editor!.chain().focus().redo().run();
|
|
220
|
+
onEditorMenuClick();
|
|
221
|
+
"
|
|
222
|
+
/>
|
|
223
|
+
</template>
|
|
224
|
+
<template v-if="emphasis">
|
|
225
|
+
<FormattingButton
|
|
226
|
+
icon="bold"
|
|
227
|
+
tooltip="Bold"
|
|
228
|
+
:active="editor.isActive('bold')"
|
|
229
|
+
@click="
|
|
230
|
+
editor!.chain().focus().toggleBold().run();
|
|
231
|
+
onEditorMenuClick();
|
|
232
|
+
"
|
|
233
|
+
/>
|
|
234
|
+
<FormattingButton
|
|
235
|
+
icon="italics"
|
|
236
|
+
tooltip="Italic"
|
|
237
|
+
:active="editor.isActive('italic')"
|
|
238
|
+
@click="
|
|
239
|
+
editor!.chain().focus().toggleItalic().run();
|
|
240
|
+
onEditorMenuClick();
|
|
241
|
+
"
|
|
242
|
+
/>
|
|
243
|
+
<FormattingButton
|
|
244
|
+
icon="underline"
|
|
245
|
+
tooltip="Underline"
|
|
246
|
+
:active="editor.isActive('underline')"
|
|
247
|
+
@click="
|
|
248
|
+
editor!.chain().focus().toggleUnderline().run();
|
|
249
|
+
onEditorMenuClick();
|
|
250
|
+
"
|
|
251
|
+
/>
|
|
252
|
+
</template>
|
|
253
|
+
<FormattingButton
|
|
254
|
+
v-if="highlight"
|
|
255
|
+
icon="square-solid"
|
|
256
|
+
tooltip="Yellow highlight"
|
|
257
|
+
:active="editor.isActive('highlight')"
|
|
258
|
+
@click="
|
|
259
|
+
editor!.chain().focus().toggleHighlight().run();
|
|
260
|
+
onEditorMenuClick();
|
|
261
|
+
"
|
|
262
|
+
/>
|
|
263
|
+
<FormattingButton
|
|
264
|
+
v-if="heading"
|
|
265
|
+
icon="heading"
|
|
266
|
+
tooltip="Heading"
|
|
267
|
+
:active="editor.isActive('heading', { level: 1 })"
|
|
268
|
+
@click="
|
|
269
|
+
editor!.chain().focus().toggleHeading({ level: 1 }).run();
|
|
270
|
+
onEditorMenuClick();
|
|
271
|
+
"
|
|
272
|
+
/>
|
|
273
|
+
<FormattingButton
|
|
274
|
+
v-if="link"
|
|
275
|
+
icon="link"
|
|
276
|
+
tooltip="Add link"
|
|
277
|
+
:active="editor.isActive('link')"
|
|
278
|
+
@click="
|
|
279
|
+
onAddLink();
|
|
280
|
+
onEditorMenuClick();
|
|
281
|
+
"
|
|
282
|
+
/>
|
|
283
|
+
<template v-if="listStyles">
|
|
284
|
+
<FormattingButton
|
|
285
|
+
icon="bullet-list"
|
|
286
|
+
tooltip="Bullet list"
|
|
287
|
+
:active="editor.isActive('bulletList')"
|
|
288
|
+
@click="
|
|
289
|
+
editor!.chain().focus().toggleBulletList().run();
|
|
290
|
+
onEditorMenuClick();
|
|
291
|
+
"
|
|
292
|
+
/>
|
|
293
|
+
<FormattingButton
|
|
294
|
+
icon="numbered-list"
|
|
295
|
+
tooltip="Numbered list"
|
|
296
|
+
:active="editor.isActive('orderedList')"
|
|
297
|
+
@click="
|
|
298
|
+
editor!.chain().focus().toggleOrderedList().run();
|
|
299
|
+
onEditorMenuClick();
|
|
300
|
+
"
|
|
301
|
+
/>
|
|
302
|
+
<FormattingButton
|
|
303
|
+
icon="indent-right"
|
|
304
|
+
tooltip="Indent right"
|
|
305
|
+
:disabled="Boolean(!editor.can().sinkListItem('listItem'))"
|
|
306
|
+
@click="
|
|
307
|
+
editor!.chain().focus().sinkListItem('listItem').run();
|
|
308
|
+
onEditorMenuClick();
|
|
309
|
+
"
|
|
310
|
+
/>
|
|
311
|
+
<FormattingButton
|
|
312
|
+
icon="indent-left"
|
|
313
|
+
tooltip="Indent left"
|
|
314
|
+
:disabled="Boolean(!editor.can().liftListItem('listItem'))"
|
|
315
|
+
@click="
|
|
316
|
+
editor!.chain().focus().liftListItem('listItem').run();
|
|
317
|
+
onEditorMenuClick();
|
|
318
|
+
"
|
|
319
|
+
/>
|
|
320
|
+
</template>
|
|
321
|
+
<FormattingButton
|
|
322
|
+
v-if="insert"
|
|
323
|
+
highlight
|
|
324
|
+
:icon="insertIcon"
|
|
325
|
+
:tooltip="insertTooltip"
|
|
326
|
+
:active="editor.isActive('insert')"
|
|
327
|
+
@click="
|
|
328
|
+
onAddText();
|
|
329
|
+
onEditorMenuClick();
|
|
330
|
+
"
|
|
331
|
+
/>
|
|
332
|
+
</BFlexbox>
|
|
333
|
+
<div v-if="$slots.menuRight" class="pr-1">
|
|
334
|
+
<slot name="menuRight" />
|
|
335
|
+
</div>
|
|
336
|
+
</BFlexbox>
|
|
337
|
+
</nav>
|
|
338
|
+
|
|
339
|
+
<InsertLinkDialog v-if="showLinkDialog" :editor="editor" @inserted="onLinkInserted" @cancel="onCancelInsertLink" />
|
|
340
|
+
|
|
341
|
+
<template v-if="showInsertTextDialog">
|
|
342
|
+
<slot v-if="$slots.insert" name="insert" />
|
|
343
|
+
<InsertTextDialog v-else @insert="onInsertText" @cancel="showInsertTextDialog = false" />
|
|
344
|
+
</template>
|
|
345
|
+
</BFlexbox>
|
|
346
|
+
</section>
|
|
347
|
+
</template>
|
|
348
|
+
|
|
349
|
+
<style>
|
|
350
|
+
.ProseMirror {
|
|
351
|
+
height: 100%;
|
|
352
|
+
}
|
|
353
|
+
.ProseMirror:focus {
|
|
354
|
+
outline: none;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/* Render blank line */
|
|
358
|
+
.ProseMirror p:empty::after {
|
|
359
|
+
content: "\00A0";
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
.ProseMirror a {
|
|
363
|
+
color: blue;
|
|
364
|
+
text-decoration: underline;
|
|
365
|
+
cursor: pointer;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/* Unordered (bullet) lists */
|
|
369
|
+
.ProseMirror ul {
|
|
370
|
+
margin-left: 30px;
|
|
371
|
+
}
|
|
372
|
+
.ProseMirror ul li {
|
|
373
|
+
list-style: circle;
|
|
374
|
+
list-style-position: outside;
|
|
375
|
+
}
|
|
376
|
+
.ProseMirror ul li > p {
|
|
377
|
+
display: inline;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/* Ordered (numbered) lists */
|
|
381
|
+
.ProseMirror ol {
|
|
382
|
+
margin-left: 30px;
|
|
383
|
+
}
|
|
384
|
+
.ProseMirror ol li {
|
|
385
|
+
list-style: decimal;
|
|
386
|
+
list-style-position: outside;
|
|
387
|
+
}
|
|
388
|
+
.ProseMirror ol li > p {
|
|
389
|
+
display: inline;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
.tiptap p.is-editor-empty:first-child::before {
|
|
393
|
+
color: #adb5bd;
|
|
394
|
+
content: attr(data-placeholder);
|
|
395
|
+
float: left;
|
|
396
|
+
height: 0;
|
|
397
|
+
pointer-events: none;
|
|
398
|
+
}
|
|
399
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<script setup lang="ts"></script>
|
|
2
|
+
|
|
3
|
+
<template>
|
|
4
|
+
<Teleport to="#modals">
|
|
5
|
+
<div class="pointer-events-auto absolute top-0 left-0 w-full h-full flex items-center justify-center rounded-sm bg-black/15">
|
|
6
|
+
<div class="px-8 py-6 bg-1 rounded-lg shadow-sm-xl space-y-2">
|
|
7
|
+
<slot />
|
|
8
|
+
</div>
|
|
9
|
+
</div>
|
|
10
|
+
</Teleport>
|
|
11
|
+
</template>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { TIcon } from "../../types";
|
|
3
|
+
import { BFlexbox, BIcon, BTooltip } from "../../";
|
|
4
|
+
|
|
5
|
+
withDefaults(
|
|
6
|
+
defineProps<{
|
|
7
|
+
active?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
highlight?: boolean;
|
|
10
|
+
icon?: TIcon;
|
|
11
|
+
label?: string;
|
|
12
|
+
tooltip?: string;
|
|
13
|
+
}>(),
|
|
14
|
+
{
|
|
15
|
+
active: false,
|
|
16
|
+
disabled: false,
|
|
17
|
+
highlight: false,
|
|
18
|
+
},
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const emit = defineEmits(["click"]);
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<template>
|
|
25
|
+
<BTooltip :text="tooltip" :delay="200">
|
|
26
|
+
<BFlexbox
|
|
27
|
+
tag="button"
|
|
28
|
+
inline
|
|
29
|
+
justify="center"
|
|
30
|
+
class="h-8 gap-2 rounded-lg border border-transparent focus:outline-hidden focus:border-strong"
|
|
31
|
+
:class="{
|
|
32
|
+
'bg-4 text-primary font-bold': active && !highlight,
|
|
33
|
+
'bg-4 text-action border border-subtle': highlight,
|
|
34
|
+
'text-tertiary bg-transparent': !active && !disabled && !highlight,
|
|
35
|
+
'hover:bg-5': !disabled,
|
|
36
|
+
'text-muted': disabled && !highlight,
|
|
37
|
+
'w-8': icon && !label,
|
|
38
|
+
'px-2': label,
|
|
39
|
+
}"
|
|
40
|
+
@click.stop.prevent="!disabled && emit('click')"
|
|
41
|
+
>
|
|
42
|
+
<BIcon v-if="icon" :name="icon" />
|
|
43
|
+
<span v-if="label" class="text-xs leading-none">{{ label }}</span>
|
|
44
|
+
</BFlexbox>
|
|
45
|
+
</BTooltip>
|
|
46
|
+
</template>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onBeforeMount, onMounted, ref } from "vue";
|
|
3
|
+
import { BConfirmCancel, BInput } from "../../";
|
|
4
|
+
import TextEditorDialog from "./Dialog.vue";
|
|
5
|
+
|
|
6
|
+
const props = defineProps<{ editor: any }>();
|
|
7
|
+
const emit = defineEmits(["cancel", "inserted"]);
|
|
8
|
+
const linkAddress = ref<string | null>(null);
|
|
9
|
+
const linkDisplayName = ref<string | null>(null);
|
|
10
|
+
|
|
11
|
+
const inputRef = ref<typeof BInput>();
|
|
12
|
+
|
|
13
|
+
const onAddLink = () => {
|
|
14
|
+
// get the current link if any
|
|
15
|
+
linkAddress.value = props.editor.getAttributes("link").href;
|
|
16
|
+
|
|
17
|
+
const { view, state } = props.editor;
|
|
18
|
+
|
|
19
|
+
if (linkAddress.value) {
|
|
20
|
+
/**
|
|
21
|
+
* If there is a link address, there must be a display name.
|
|
22
|
+
* But there is no simple way to get the display name.
|
|
23
|
+
* This is solved by looking at the parent content of the cursor position
|
|
24
|
+
* and find the content where the link is added
|
|
25
|
+
*
|
|
26
|
+
* The parent content is the line where cursor is broken down into blocks
|
|
27
|
+
*/
|
|
28
|
+
const relevantTextNodes = view.state.selection.ranges[0].$from.parent.content.content.filter(
|
|
29
|
+
(c: any) => c.marks.length > 0 && c.marks[0].attrs.href === linkAddress.value,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
linkDisplayName.value = relevantTextNodes[0].text;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// get the selected text as the display name
|
|
36
|
+
const { from, to } = view.state.selection;
|
|
37
|
+
linkDisplayName.value = state.doc.textBetween(from, to, "");
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
onBeforeMount(() => onAddLink());
|
|
42
|
+
onMounted(() => inputRef.value!.focus());
|
|
43
|
+
|
|
44
|
+
// TODO use define model
|
|
45
|
+
const onAddressChange = (value: string) => (linkAddress.value = value);
|
|
46
|
+
const onDisplayNameChange = (value: string) => (linkDisplayName.value = value);
|
|
47
|
+
|
|
48
|
+
const onInsert = () => {
|
|
49
|
+
if (linkAddress.value && !linkAddress.value.includes("http")) {
|
|
50
|
+
linkAddress.value = `https://${linkAddress.value}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (linkAddress.value) {
|
|
54
|
+
props.editor.chain().focus().extendMarkRange("link").setLink({ href: linkAddress.value }).run();
|
|
55
|
+
|
|
56
|
+
const transaction = props.editor.state.tr.insertText(linkDisplayName.value);
|
|
57
|
+
props.editor.view.dispatch(transaction);
|
|
58
|
+
|
|
59
|
+
emit("inserted");
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<template>
|
|
65
|
+
<TextEditorDialog>
|
|
66
|
+
<header>Insert link</header>
|
|
67
|
+
<section class="space-y-1">
|
|
68
|
+
<div class="text-xs text-secondary">
|
|
69
|
+
Text to display
|
|
70
|
+
</div>
|
|
71
|
+
<BInput ref="inputRef" placeholder="Text to display" :value="linkDisplayName || ''" @change="onDisplayNameChange" />
|
|
72
|
+
</section>
|
|
73
|
+
<section class="space-y-1">
|
|
74
|
+
<div class="text-xs text-secondary">
|
|
75
|
+
Address
|
|
76
|
+
</div>
|
|
77
|
+
<BInput placeholder="Link to a web page" :value="linkAddress || ''" @change="onAddressChange" />
|
|
78
|
+
</section>
|
|
79
|
+
<BConfirmCancel confirm-label="Insert" @confirm="onInsert" @cancel="emit('cancel')" />
|
|
80
|
+
</TextEditorDialog>
|
|
81
|
+
</template>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onMounted, ref } from "vue";
|
|
3
|
+
import { BConfirmCancel, BInput } from "../../";
|
|
4
|
+
import TextEditorDialog from "./Dialog.vue";
|
|
5
|
+
|
|
6
|
+
const emit = defineEmits(["cancel", "insert"]);
|
|
7
|
+
const textToBeInserted = ref<string | null>(null);
|
|
8
|
+
const inputRef = ref<typeof BInput>();
|
|
9
|
+
|
|
10
|
+
onMounted(() => inputRef.value!.focus());
|
|
11
|
+
|
|
12
|
+
const onCancelInsert = () => {
|
|
13
|
+
emit("cancel");
|
|
14
|
+
textToBeInserted.value = null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// TODO use defineModel
|
|
18
|
+
const onInputChange = (value: string) => (textToBeInserted.value = value);
|
|
19
|
+
|
|
20
|
+
const onInsert = () => {
|
|
21
|
+
emit("insert", textToBeInserted.value);
|
|
22
|
+
textToBeInserted.value = null;
|
|
23
|
+
};
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<template>
|
|
27
|
+
<TextEditorDialog>
|
|
28
|
+
<header>Insert text</header>
|
|
29
|
+
<section class="space-y-1">
|
|
30
|
+
<BInput ref="inputRef" placeholder="Text to be inserted" :value="textToBeInserted || ''" @change="onInputChange" />
|
|
31
|
+
</section>
|
|
32
|
+
<div class="flex flex-1 justify-end">
|
|
33
|
+
<BConfirmCancel confirm-label="Insert" @confirm="onInsert" @cancel="onCancelInsert" />
|
|
34
|
+
</div>
|
|
35
|
+
</TextEditorDialog>
|
|
36
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as BTextEditor } from "./TextEditor.vue";
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onBeforeMount, ref, watch } from "vue";
|
|
3
|
+
|
|
4
|
+
const props = withDefaults(
|
|
5
|
+
defineProps<{
|
|
6
|
+
value: string;
|
|
7
|
+
highlight?: string | null;
|
|
8
|
+
bold?: boolean;
|
|
9
|
+
underline?: boolean;
|
|
10
|
+
textColorClass?: string;
|
|
11
|
+
backgroundColor?: "yellow" | "green" | "blue" | "red" | "pink" | "white" | null;
|
|
12
|
+
}>(),
|
|
13
|
+
{
|
|
14
|
+
highlight: null,
|
|
15
|
+
bold: false,
|
|
16
|
+
underline: false,
|
|
17
|
+
textColorClass: "text-primary dark:text-black",
|
|
18
|
+
backgroundColor: null,
|
|
19
|
+
},
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const segments = ref<string[]>([]);
|
|
23
|
+
|
|
24
|
+
const highlightColorClasses = computed(() => {
|
|
25
|
+
if (!props.backgroundColor) return "";
|
|
26
|
+
|
|
27
|
+
const base = "ring-2 shadow-sm ";
|
|
28
|
+
switch (props.backgroundColor) {
|
|
29
|
+
case "yellow":
|
|
30
|
+
return `${base}bg-yellow-500 ring-yellow-500`;
|
|
31
|
+
case "green":
|
|
32
|
+
return `${base}bg-green-500 ring-green-500`;
|
|
33
|
+
case "blue":
|
|
34
|
+
return `${base}bg-blue-500 ring-blue-500`;
|
|
35
|
+
case "red":
|
|
36
|
+
return `${base}bg-red-500 ring-red-500`;
|
|
37
|
+
case "pink":
|
|
38
|
+
return `${base}bg-pink-500 ring-pink-500`;
|
|
39
|
+
case "white":
|
|
40
|
+
return `${base}bg-white ring-white`;
|
|
41
|
+
default:
|
|
42
|
+
return `${base}bg-yellow-500 ring-yellow-500`;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const segmentiseString = (targetString: string, searchString: string) => {
|
|
47
|
+
if (!targetString || !searchString) return [];
|
|
48
|
+
if (typeof targetString !== "string" || typeof searchString !== "string") return [];
|
|
49
|
+
|
|
50
|
+
const lowerCasedTargetString = targetString.toLowerCase();
|
|
51
|
+
const lowerCasedSearchString = searchString.toLowerCase();
|
|
52
|
+
|
|
53
|
+
const segmentBreakPoints = [];
|
|
54
|
+
let resultIndex = -1;
|
|
55
|
+
|
|
56
|
+
do {
|
|
57
|
+
resultIndex = lowerCasedTargetString.indexOf(lowerCasedSearchString, resultIndex + 1);
|
|
58
|
+
if (resultIndex !== -1) {
|
|
59
|
+
segmentBreakPoints.push(resultIndex, resultIndex + lowerCasedSearchString.length);
|
|
60
|
+
}
|
|
61
|
+
} while (resultIndex > -1);
|
|
62
|
+
|
|
63
|
+
const segments = [];
|
|
64
|
+
let segmentIndex = 0;
|
|
65
|
+
|
|
66
|
+
for (const highlight of segmentBreakPoints) {
|
|
67
|
+
segments.push(targetString.substring(segmentIndex, highlight));
|
|
68
|
+
segmentIndex = highlight;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
segments.push(targetString.substring(segmentBreakPoints[segmentBreakPoints.length - 1], targetString.length));
|
|
72
|
+
|
|
73
|
+
return segments;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
onBeforeMount(() => {
|
|
77
|
+
segments.value = props.highlight ? segmentiseString(props.value, props.highlight) : [];
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
watch(
|
|
81
|
+
() => props.highlight,
|
|
82
|
+
(newValue: string | null) => {
|
|
83
|
+
segments.value = newValue ? segmentiseString(props.value, newValue) : [];
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
<template>
|
|
89
|
+
<span class="relative z-0">
|
|
90
|
+
<template v-if="segments.length === 0">
|
|
91
|
+
{{ value }}
|
|
92
|
+
</template>
|
|
93
|
+
<template v-for="segment in segments" v-else :key="segment">
|
|
94
|
+
<span
|
|
95
|
+
v-if="highlight && segment.toLowerCase() === highlight.toLowerCase()"
|
|
96
|
+
class="relative z-0 rounded"
|
|
97
|
+
:class="[
|
|
98
|
+
{
|
|
99
|
+
'font-bold': bold,
|
|
100
|
+
'underline': underline,
|
|
101
|
+
},
|
|
102
|
+
highlightColorClasses,
|
|
103
|
+
textColorClass,
|
|
104
|
+
]"
|
|
105
|
+
>
|
|
106
|
+
{{ segment }}
|
|
107
|
+
</span>
|
|
108
|
+
<span v-else class="relative z-10">
|
|
109
|
+
{{ segment }}
|
|
110
|
+
</span>
|
|
111
|
+
</template>
|
|
112
|
+
</span>
|
|
113
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as BTextHighlight } from "./TextHighlight.vue";
|