frappe-ui 1.0.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/experimental/Calendar/CalendarEventRow.vue +0 -4
- package/experimental/Calendar/calendarUtils.ts +33 -21
- package/experimental/CommandPalette/CommandPaletteItem.vue +9 -1
- package/experimental/MultiEmailInput/MultiEmailInput.vue +64 -12
- package/experimental/MultiEmailInput/types.ts +12 -3
- package/experimental/SpriteIcons/IconPicker.vue +2 -1
- package/experimental/Stepper/StepIndicator.vue +129 -0
- package/experimental/Stepper/Stepper.api.md +117 -0
- package/experimental/Stepper/Stepper.md +95 -0
- package/experimental/Stepper/Stepper.vue +82 -0
- package/experimental/Stepper/StepperHorizontal.vue +93 -0
- package/experimental/Stepper/StepperVertical.vue +291 -0
- package/experimental/Stepper/index.ts +11 -0
- package/experimental/Stepper/resolve.ts +87 -0
- package/experimental/Stepper/types.ts +89 -0
- package/experimental.ts +2 -21
- package/package.json +1 -3
- package/src/charts/CalendarHeatmapChart.vue +353 -0
- package/src/charts/DonutChart.vue +34 -58
- package/src/charts/HeatmapChart.vue +26 -64
- package/src/charts/NumberCard.vue +62 -7
- package/src/charts/PercentageBarChart.vue +243 -0
- package/src/charts/SankeyChart.vue +14 -11
- package/src/charts/ScatterChart.vue +24 -20
- package/src/charts/axisChartCommon.ts +182 -18
- package/src/charts/axisFormat.ts +8 -3
- package/src/charts/calendarHeatmapOptions.ts +604 -0
- package/src/charts/colorMath.ts +26 -0
- package/src/charts/components/ChartContainer.vue +63 -53
- package/src/charts/components/ChartLegend.vue +216 -24
- package/src/charts/components/ChartScale.vue +85 -0
- package/src/charts/core/dataLabelFit.ts +45 -6
- package/src/charts/core/useAxisChart.ts +36 -19
- package/src/charts/core/useChart.ts +6 -1
- package/src/charts/core/usePlotKeyboard.ts +13 -2
- package/src/charts/docs/BarChart.md +11 -3
- package/src/charts/docs/CalendarHeatmapChart.api.md +165 -0
- package/src/charts/docs/CalendarHeatmapChart.md +33 -0
- package/src/charts/docs/ChartContainer.api.md +6 -0
- package/src/charts/docs/ChartLegend.api.md +1 -1
- package/src/charts/docs/ChartLegend.md +25 -3
- package/src/charts/docs/DonutChart.api.md +12 -0
- package/src/charts/docs/DonutChart.md +17 -0
- package/src/charts/docs/HeatmapChart.api.md +1 -1
- package/src/charts/docs/LineChart.md +5 -3
- package/src/charts/docs/NumberCard.api.md +6 -0
- package/src/charts/docs/NumberCard.md +6 -0
- package/src/charts/docs/Overview.md +13 -6
- package/src/charts/docs/PercentageBarChart.api.md +148 -0
- package/src/charts/docs/PercentageBarChart.md +42 -0
- package/src/charts/docs/ScatterChart.md +2 -3
- package/src/charts/donutChartOptions.ts +22 -130
- package/src/charts/format.ts +4 -1
- package/src/charts/heatmapOptions.ts +17 -12
- package/src/charts/hiddenSeries.ts +8 -3
- package/src/charts/index.ts +12 -0
- package/src/charts/legendOverflow.ts +40 -0
- package/src/charts/numberCardFormat.ts +19 -13
- package/src/charts/referenceLines.ts +2 -1
- package/src/charts/scatterOptions.ts +16 -3
- package/src/charts/seriesData.ts +8 -3
- package/src/charts/slices.ts +228 -0
- package/src/charts/tokens.ts +99 -0
- package/src/charts/types.ts +318 -9
- package/src/components/Avatar/Avatar.md +27 -2
- package/src/components/Avatar/Avatar.vue +29 -12
- package/src/components/Breadcrumbs/Breadcrumbs.vue +2 -1
- package/src/components/Combobox/Combobox.vue +9 -2
- package/src/components/Combobox/ComboboxResults.vue +6 -1
- package/src/components/Combobox/utils.ts +2 -1
- package/src/components/DatePicker/DatePicker.md +7 -0
- package/src/components/DatePicker/DatePicker.vue +6 -0
- package/src/components/DatePicker/DateTimePicker.vue +6 -0
- package/src/components/DatePicker/composables.ts +18 -1
- package/src/components/DatePicker/utils.ts +53 -0
- package/src/components/Dialog/Dialog.md +3 -1
- package/src/components/Duration/Duration.api.md +16 -3
- package/src/components/Duration/Duration.md +21 -0
- package/src/components/Duration/Duration.vue +29 -8
- package/src/components/Duration/duration.ts +105 -44
- package/src/components/Duration/index.ts +1 -0
- package/src/components/Duration/types.ts +30 -1
- package/src/components/HoverCard/HoverCard.vue +21 -5
- package/src/components/Menu/utils.ts +3 -2
- package/src/components/MobileNav/MobileNavItem.vue +3 -22
- package/src/components/MultiSelect/MultiSelect.api.md +5 -0
- package/src/components/MultiSelect/MultiSelect.vue +34 -0
- package/src/components/MultiSelect/MultiSelectResults.vue +3 -4
- package/src/components/MultiSelect/types.ts +6 -0
- package/src/components/Select/Select.vue +4 -4
- package/src/components/Select/utils.ts +1 -0
- package/src/components/SettingsDialog/SettingsDialog.api.md +7 -2
- package/src/components/SettingsDialog/SettingsDialog.md +2 -1
- package/src/components/SettingsDialog/SettingsRow.vue +12 -2
- package/src/components/Sidebar/SidebarItem.vue +3 -33
- package/src/components/SidebarRail/SidebarRailItem.vue +4 -17
- package/src/components/Switch/Switch.vue +3 -3
- package/src/components/Tooltip/Tooltip.vue +8 -0
- package/src/components/shared/deferredTrigger.ts +174 -0
- package/src/components/shared/navLink.ts +45 -0
- package/src/components/shared/selection/utils.ts +8 -1
- package/src/data-fetching/useCall/useCall.ts +25 -26
- package/src/data-fetching/useFrappeFetch.ts +48 -2
- package/src/data-fetching/useList/useList.ts +11 -3
- package/src/data-fetching/utils.ts +15 -1
- package/src/molecules/editor/components/MediaNodeView.vue +10 -1
- package/src/molecules/editor/components/MediaResizeGuide.vue +71 -0
- package/src/molecules/editor/components/media-node-view-utils.ts +7 -0
- package/src/molecules/editor/composables/useNodeViewResize.ts +142 -10
- package/src/molecules/editor/extensions/attachment/attachment-engine.ts +1 -1
- package/src/molecules/editor/extensions/content-paste/paste-html-utils.ts +16 -6
- package/src/molecules/editor/extensions/iframe/IframeNodeView.vue +29 -10
- package/src/molecules/editor/extensions/iframe/iframe-allowlist.ts +35 -16
- package/src/molecules/editor/extensions/iframe/iframe-embed-utils.ts +1 -1
- package/src/molecules/editor/extensions/iframe/iframe-extension.ts +30 -30
- package/src/molecules/editor/extensions/link/LinkEditorPopup.vue +1 -1
- package/src/molecules/editor/extensions/link/link-paste-plugin.ts +1 -1
- package/src/molecules/editor/extensions/shared/media-upload-engine.ts +1 -1
- package/src/molecules/editor/useEditor.ts +12 -6
- package/src/molecules/list/ListRow.vue +8 -1
- package/src/utils/dialog.ts +57 -16
- package/src/{molecules/editor/extensions/shared → utils}/url-safety.ts +28 -16
- package/tailwind/content.js +1 -1
- package/tailwind/plugin.js +22 -0
- package/vite/README.md +5 -3
- package/vite/codeLanguages.js +41 -17
- package/vite/doctypeInterfaceGenerator.js +52 -39
- package/vitepress/index.node.ts +0 -2
- package/experimental/TextEditor/TextEditor.api.md +0 -161
- package/experimental/TextEditor/TextEditor.vue +0 -298
- package/experimental/TextEditor/classIcon.ts +0 -21
- package/experimental/TextEditor/commands.js +0 -344
- package/experimental/TextEditor/components/CodeBlockComponent.vue +0 -103
- package/experimental/TextEditor/components/FontColor.vue +0 -153
- package/experimental/TextEditor/components/ImageViewerModal.vue +0 -463
- package/experimental/TextEditor/components/InsertImage.vue +0 -54
- package/experimental/TextEditor/components/InsertLink.vue +0 -13
- package/experimental/TextEditor/components/InsertVideo.vue +0 -14
- package/experimental/TextEditor/components/LinkPopup.vue +0 -99
- package/experimental/TextEditor/components/MediaNodeView.vue +0 -398
- package/experimental/TextEditor/components/MentionList.vue +0 -95
- package/experimental/TextEditor/components/TextEditorBubbleMenu.vue +0 -78
- package/experimental/TextEditor/components/TextEditorFixedMenu.vue +0 -78
- package/experimental/TextEditor/components/TextEditorFloatingMenu.vue +0 -61
- package/experimental/TextEditor/components/TextEditorMenu.vue +0 -218
- package/experimental/TextEditor/components/index.js +0 -0
- package/experimental/TextEditor/extensions/code-block.ts +0 -119
- package/experimental/TextEditor/extensions/color/color-extension.ts +0 -140
- package/experimental/TextEditor/extensions/color/color-styles.css +0 -25
- package/experimental/TextEditor/extensions/color/index.ts +0 -2
- package/experimental/TextEditor/extensions/content-paste-extension.ts +0 -160
- package/experimental/TextEditor/extensions/copy-styles.ts +0 -160
- package/experimental/TextEditor/extensions/emoji/EmojiList.vue +0 -55
- package/experimental/TextEditor/extensions/emoji/emoji-extension.ts +0 -55
- package/experimental/TextEditor/extensions/emoji/emojis.json +0 -7422
- package/experimental/TextEditor/extensions/heading/heading.ts +0 -20
- package/experimental/TextEditor/extensions/highlight/highlight-extension.ts +0 -241
- package/experimental/TextEditor/extensions/highlight/highlight-styles.css +0 -31
- package/experimental/TextEditor/extensions/highlight/index.ts +0 -2
- package/experimental/TextEditor/extensions/iframe/IframeNodeView.vue +0 -308
- package/experimental/TextEditor/extensions/iframe/InsertIframe.vue +0 -209
- package/experimental/TextEditor/extensions/iframe/iframe-extension.ts +0 -404
- package/experimental/TextEditor/extensions/iframe/index.ts +0 -11
- package/experimental/TextEditor/extensions/iframe/utils.ts +0 -283
- package/experimental/TextEditor/extensions/image/image-extension.ts +0 -661
- package/experimental/TextEditor/extensions/image/index.ts +0 -5
- package/experimental/TextEditor/extensions/image-group/ImageGroupNodeView.vue +0 -182
- package/experimental/TextEditor/extensions/image-group/ImageGroupUploadDialog.vue +0 -740
- package/experimental/TextEditor/extensions/image-group/image-group-extension.ts +0 -187
- package/experimental/TextEditor/extensions/image-viewer-extension.ts +0 -162
- package/experimental/TextEditor/extensions/link/index.ts +0 -1
- package/experimental/TextEditor/extensions/link/link-extension.ts +0 -323
- package/experimental/TextEditor/extensions/link/linkPasteHandler.ts +0 -51
- package/experimental/TextEditor/extensions/mention/index.ts +0 -1
- package/experimental/TextEditor/extensions/mention/mention-extension.ts +0 -204
- package/experimental/TextEditor/extensions/mention/style.css +0 -11
- package/experimental/TextEditor/extensions/shared/color-utils.ts +0 -236
- package/experimental/TextEditor/extensions/slash-commands/SlashCommandsList.vue +0 -59
- package/experimental/TextEditor/extensions/slash-commands/slash-commands-extension.ts +0 -184
- package/experimental/TextEditor/extensions/suggestion/SuggestionList.vue +0 -130
- package/experimental/TextEditor/extensions/suggestion/createSuggestionExtension.ts +0 -151
- package/experimental/TextEditor/extensions/suggestion/index.ts +0 -5
- package/experimental/TextEditor/extensions/tag/index.ts +0 -1
- package/experimental/TextEditor/extensions/tag/tag-extension.ts +0 -170
- package/experimental/TextEditor/extensions/toc-node/TocNodeView.vue +0 -439
- package/experimental/TextEditor/extensions/toc-node/index.ts +0 -3
- package/experimental/TextEditor/extensions/toc-node/toc-node-extension.ts +0 -167
- package/experimental/TextEditor/extensions/video-extension.ts +0 -653
- package/experimental/TextEditor/hljs-github.css +0 -197
- package/experimental/TextEditor/index.ts +0 -21
- package/experimental/TextEditor/style.css +0 -190
- package/experimental/TextEditor/types.ts +0 -72
- package/experimental/TextEditor/utils.js +0 -11
- package/src/utils/url-validation.ts +0 -39
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { Editor, Range } from '@tiptap/core'
|
|
2
|
-
import { PluginKey } from '@tiptap/pm/state'
|
|
3
|
-
import {
|
|
4
|
-
createSuggestionExtension,
|
|
5
|
-
type BaseSuggestionItem,
|
|
6
|
-
} from '../suggestion/createSuggestionExtension'
|
|
7
|
-
import SlashCommandsList from './SlashCommandsList.vue'
|
|
8
|
-
import { Component as VueComponent } from 'vue'
|
|
9
|
-
|
|
10
|
-
import { classIcon } from '../../classIcon'
|
|
11
|
-
const Heading2 = classIcon('lucide-heading-2')
|
|
12
|
-
const Heading3 = classIcon('lucide-heading-3')
|
|
13
|
-
const List = classIcon('lucide-list')
|
|
14
|
-
const ListOrdered = classIcon('lucide-list-ordered')
|
|
15
|
-
const ListTask = classIcon('lucide-list-checks')
|
|
16
|
-
const Code = classIcon('lucide-code')
|
|
17
|
-
const Quote = classIcon('lucide-quote')
|
|
18
|
-
const Image = classIcon('lucide-image')
|
|
19
|
-
const Video = classIcon('lucide-video')
|
|
20
|
-
const GalleryVertical = classIcon('lucide-gallery-vertical')
|
|
21
|
-
const Link = classIcon('lucide-link')
|
|
22
|
-
const Minus = classIcon('lucide-minus')
|
|
23
|
-
const Table = classIcon('lucide-table-2')
|
|
24
|
-
const TableOfContents = classIcon('lucide-table-of-contents')
|
|
25
|
-
export const SlashCommandSuggestionKey = new PluginKey<any>(
|
|
26
|
-
'slashCommandSuggestion',
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
export interface CommandItem extends BaseSuggestionItem {
|
|
30
|
-
title: string
|
|
31
|
-
icon: VueComponent
|
|
32
|
-
command: (props: CommandExecutionProps) => void
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
type CommandExecutionProps = {
|
|
36
|
-
editor: Editor
|
|
37
|
-
range: Range
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const getCommands = (): CommandItem[] => [
|
|
41
|
-
{
|
|
42
|
-
title: 'Heading 2',
|
|
43
|
-
icon: Heading2,
|
|
44
|
-
command: ({ editor, range }: CommandExecutionProps) => {
|
|
45
|
-
editor
|
|
46
|
-
.chain()
|
|
47
|
-
.focus()
|
|
48
|
-
.deleteRange(range)
|
|
49
|
-
.setNode('heading', { level: 2 })
|
|
50
|
-
.run()
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
title: 'Heading 3',
|
|
55
|
-
icon: Heading3,
|
|
56
|
-
command: ({ editor, range }: CommandExecutionProps) => {
|
|
57
|
-
editor
|
|
58
|
-
.chain()
|
|
59
|
-
.focus()
|
|
60
|
-
.deleteRange(range)
|
|
61
|
-
.setNode('heading', { level: 3 })
|
|
62
|
-
.run()
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
title: 'Bullet List',
|
|
67
|
-
icon: List,
|
|
68
|
-
command: ({ editor, range }: CommandExecutionProps) => {
|
|
69
|
-
editor.chain().focus().deleteRange(range).toggleBulletList().run()
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
title: 'Numbered List',
|
|
74
|
-
icon: ListOrdered,
|
|
75
|
-
command: ({ editor, range }: CommandExecutionProps) => {
|
|
76
|
-
editor.chain().focus().deleteRange(range).toggleOrderedList().run()
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
title: 'Task List',
|
|
81
|
-
icon: ListTask,
|
|
82
|
-
command: ({ editor, range }: CommandExecutionProps) => {
|
|
83
|
-
editor.chain().focus().deleteRange(range).toggleTaskList().run()
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
title: 'Code Block',
|
|
88
|
-
icon: Code,
|
|
89
|
-
command: ({ editor, range }: CommandExecutionProps) => {
|
|
90
|
-
editor.chain().focus().deleteRange(range).toggleCodeBlock().run()
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
title: 'Blockquote',
|
|
95
|
-
icon: Quote,
|
|
96
|
-
command: ({ editor, range }: CommandExecutionProps) => {
|
|
97
|
-
editor.chain().focus().deleteRange(range).toggleBlockquote().run()
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
title: 'Image',
|
|
102
|
-
icon: Image,
|
|
103
|
-
command: ({ editor, range }: CommandExecutionProps) => {
|
|
104
|
-
editor.chain().focus().deleteRange(range).selectAndUploadImage().run()
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
title: 'Video',
|
|
109
|
-
icon: Video,
|
|
110
|
-
command: ({ editor, range }: CommandExecutionProps) => {
|
|
111
|
-
editor.chain().focus().deleteRange(range).selectAndUploadVideo().run()
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
title: 'Embed',
|
|
116
|
-
icon: GalleryVertical,
|
|
117
|
-
command: ({ editor, range }: CommandExecutionProps) => {
|
|
118
|
-
editor.chain().focus().deleteRange(range).openIframeDialog().run()
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
title: 'Link',
|
|
123
|
-
icon: Link,
|
|
124
|
-
command: ({ editor, range }: CommandExecutionProps) => {
|
|
125
|
-
editor.chain().focus().deleteRange(range).setLink({ href: '' }).run()
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
title: 'Horizontal Rule',
|
|
130
|
-
icon: Minus,
|
|
131
|
-
command: ({ editor, range }: CommandExecutionProps) => {
|
|
132
|
-
editor.chain().focus().deleteRange(range).setHorizontalRule().run()
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
title: 'Table',
|
|
137
|
-
icon: Table,
|
|
138
|
-
command: ({ editor, range }: CommandExecutionProps) => {
|
|
139
|
-
editor
|
|
140
|
-
.chain()
|
|
141
|
-
.focus()
|
|
142
|
-
.deleteRange(range)
|
|
143
|
-
.insertTable({ rows: 3, cols: 3, withHeaderRow: true })
|
|
144
|
-
.run()
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
title: 'Table of Contents',
|
|
149
|
-
icon: TableOfContents,
|
|
150
|
-
command: ({ editor, range }: CommandExecutionProps) => {
|
|
151
|
-
editor
|
|
152
|
-
.chain()
|
|
153
|
-
.focus()
|
|
154
|
-
.deleteRange(range)
|
|
155
|
-
.insertTableOfContentsNode()
|
|
156
|
-
.run()
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
]
|
|
160
|
-
|
|
161
|
-
export const SlashCommands = createSuggestionExtension<CommandItem>({
|
|
162
|
-
name: 'slashCommands',
|
|
163
|
-
char: '/',
|
|
164
|
-
pluginKey: SlashCommandSuggestionKey,
|
|
165
|
-
items: ({ query }) => {
|
|
166
|
-
const commands = getCommands()
|
|
167
|
-
return commands.filter((item) =>
|
|
168
|
-
item.title.toLowerCase().startsWith(query.toLowerCase()),
|
|
169
|
-
)
|
|
170
|
-
},
|
|
171
|
-
command: ({ editor, range, props: item }) => {
|
|
172
|
-
if (item && typeof item.command === 'function') {
|
|
173
|
-
item.command({ editor, range })
|
|
174
|
-
} else {
|
|
175
|
-
console.error(
|
|
176
|
-
'Slash command execution error: command function not found on selected item or item is invalid.',
|
|
177
|
-
item,
|
|
178
|
-
)
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
component: SlashCommandsList,
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
export default SlashCommands
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<div
|
|
4
|
-
v-if="items.length || showNoResults"
|
|
5
|
-
ref="container"
|
|
6
|
-
class="relative max-h-[300px] min-w-40 overflow-y-auto rounded-6 bg-surface-base p-1 text-base shadow-lg"
|
|
7
|
-
:class="containerClass"
|
|
8
|
-
>
|
|
9
|
-
<button
|
|
10
|
-
v-for="(item, index) in items"
|
|
11
|
-
:key="index"
|
|
12
|
-
:ref="
|
|
13
|
-
(el) => {
|
|
14
|
-
if (el) itemRefs[index] = el as HTMLButtonElement
|
|
15
|
-
}
|
|
16
|
-
"
|
|
17
|
-
:class="[
|
|
18
|
-
'flex w-full items-center whitespace-nowrap rounded-5 px-2 py-1.5 text-sm text-ink-gray-9',
|
|
19
|
-
index === selectedIndex ? 'bg-surface-gray-2' : '',
|
|
20
|
-
itemClass,
|
|
21
|
-
]"
|
|
22
|
-
@click="selectItem(index)"
|
|
23
|
-
@mouseover="selectedIndex = index"
|
|
24
|
-
>
|
|
25
|
-
<slot :item="item" :index="index">
|
|
26
|
-
<span>{{ item.display || item.title || item.name }}</span>
|
|
27
|
-
</slot>
|
|
28
|
-
</button>
|
|
29
|
-
<div v-if="!items.length" class="px-3 py-1.5 text-sm text-ink-gray-5">
|
|
30
|
-
No results
|
|
31
|
-
</div>
|
|
32
|
-
</div>
|
|
33
|
-
</div>
|
|
34
|
-
</template>
|
|
35
|
-
|
|
36
|
-
<script setup lang="ts">
|
|
37
|
-
import { ref, watch, type PropType, nextTick, onBeforeUpdate } from 'vue'
|
|
38
|
-
import type { BaseSuggestionItem } from './createSuggestionExtension'
|
|
39
|
-
|
|
40
|
-
const props = defineProps({
|
|
41
|
-
items: {
|
|
42
|
-
type: Array as PropType<BaseSuggestionItem[]>,
|
|
43
|
-
required: true,
|
|
44
|
-
},
|
|
45
|
-
command: {
|
|
46
|
-
type: Function as PropType<(item: BaseSuggestionItem) => void>,
|
|
47
|
-
required: true,
|
|
48
|
-
},
|
|
49
|
-
containerClass: {
|
|
50
|
-
type: String,
|
|
51
|
-
default: '',
|
|
52
|
-
},
|
|
53
|
-
itemClass: {
|
|
54
|
-
type: String,
|
|
55
|
-
default: '',
|
|
56
|
-
},
|
|
57
|
-
showNoResults: {
|
|
58
|
-
type: Boolean,
|
|
59
|
-
default: false,
|
|
60
|
-
},
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
const selectedIndex = ref(0)
|
|
64
|
-
const container = ref<HTMLDivElement | null>(null)
|
|
65
|
-
const itemRefs = ref<HTMLButtonElement[]>([])
|
|
66
|
-
|
|
67
|
-
onBeforeUpdate(() => {
|
|
68
|
-
itemRefs.value = []
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
const scrollIntoView = () => {
|
|
72
|
-
nextTick(() => {
|
|
73
|
-
const selectedElement = itemRefs.value[selectedIndex.value]
|
|
74
|
-
if (selectedElement) {
|
|
75
|
-
selectedElement.scrollIntoView({ block: 'nearest' })
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const selectItem = (index: number) => {
|
|
81
|
-
const item = props.items[index]
|
|
82
|
-
if (item) {
|
|
83
|
-
props.command(item)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const onKeyDown = ({ event }: { event: KeyboardEvent }) => {
|
|
88
|
-
if (!props.items.length) return false
|
|
89
|
-
|
|
90
|
-
if (event.key === 'ArrowUp') {
|
|
91
|
-
upHandler()
|
|
92
|
-
return true
|
|
93
|
-
}
|
|
94
|
-
if (event.key === 'ArrowDown') {
|
|
95
|
-
downHandler()
|
|
96
|
-
return true
|
|
97
|
-
}
|
|
98
|
-
if (event.key === 'Enter') {
|
|
99
|
-
enterHandler()
|
|
100
|
-
return true
|
|
101
|
-
}
|
|
102
|
-
return false
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const upHandler = () => {
|
|
106
|
-
selectedIndex.value =
|
|
107
|
-
(selectedIndex.value + props.items.length - 1) % props.items.length
|
|
108
|
-
scrollIntoView()
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const downHandler = () => {
|
|
112
|
-
selectedIndex.value = (selectedIndex.value + 1) % props.items.length
|
|
113
|
-
scrollIntoView()
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const enterHandler = () => {
|
|
117
|
-
selectItem(selectedIndex.value)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
watch(
|
|
121
|
-
() => props.items,
|
|
122
|
-
() => {
|
|
123
|
-
selectedIndex.value = 0
|
|
124
|
-
},
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
defineExpose({
|
|
128
|
-
onKeyDown,
|
|
129
|
-
})
|
|
130
|
-
</script>
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { Extension, Editor, Range } from '@tiptap/core'
|
|
2
|
-
import { VueRenderer } from '@tiptap/vue-3'
|
|
3
|
-
import Suggestion, {
|
|
4
|
-
SuggestionOptions,
|
|
5
|
-
SuggestionProps,
|
|
6
|
-
} from '@tiptap/suggestion'
|
|
7
|
-
import { PluginKey } from '@tiptap/pm/state'
|
|
8
|
-
import tippy, { Instance as TippyInstance, Props as TippyProps } from 'tippy.js'
|
|
9
|
-
import { Component as VueComponent } from 'vue'
|
|
10
|
-
|
|
11
|
-
export interface BaseSuggestionItem {
|
|
12
|
-
title?: string
|
|
13
|
-
name?: string
|
|
14
|
-
[key: string]: any
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface CreateSuggestionExtensionOptions<
|
|
18
|
-
TItem extends BaseSuggestionItem,
|
|
19
|
-
> {
|
|
20
|
-
name: string
|
|
21
|
-
char: string
|
|
22
|
-
pluginKey: PluginKey
|
|
23
|
-
items: (props: {
|
|
24
|
-
query: string
|
|
25
|
-
editor: Editor
|
|
26
|
-
}) => TItem[] | Promise<TItem[]>
|
|
27
|
-
command: (props: { editor: Editor; range: Range; props: TItem }) => void
|
|
28
|
-
component: VueComponent
|
|
29
|
-
tippyOptions?: Partial<TippyProps>
|
|
30
|
-
allowSpaces?: boolean
|
|
31
|
-
startOfLine?: boolean
|
|
32
|
-
decorationTag?: string
|
|
33
|
-
decorationClass?: string
|
|
34
|
-
addOptions?: () => Record<string, any>
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function createSuggestionExtension<TItem extends BaseSuggestionItem>(
|
|
38
|
-
options: CreateSuggestionExtensionOptions<TItem>,
|
|
39
|
-
) {
|
|
40
|
-
type ExtensionFullOptions = Record<string, any> & {
|
|
41
|
-
suggestion: Omit<SuggestionOptions<TItem>, 'editor'>
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return Extension.create<ExtensionFullOptions>({
|
|
45
|
-
name: options.name,
|
|
46
|
-
|
|
47
|
-
addOptions() {
|
|
48
|
-
const customOptions = options.addOptions
|
|
49
|
-
? options.addOptions.call(this)
|
|
50
|
-
: {}
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
...customOptions,
|
|
54
|
-
suggestion: {
|
|
55
|
-
char: options.char,
|
|
56
|
-
pluginKey: options.pluginKey,
|
|
57
|
-
items: options.items,
|
|
58
|
-
command: options.command,
|
|
59
|
-
allowSpaces: options.allowSpaces,
|
|
60
|
-
startOfLine: options.startOfLine,
|
|
61
|
-
decorationTag: options.decorationTag || 'span',
|
|
62
|
-
decorationClass: options.decorationClass || 'suggestion',
|
|
63
|
-
render: () => {
|
|
64
|
-
let component: VueRenderer | null
|
|
65
|
-
let popup: TippyInstance[] | null
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
onStart: (props: SuggestionProps<TItem>) => {
|
|
69
|
-
component = new VueRenderer(options.component, {
|
|
70
|
-
editor: props.editor,
|
|
71
|
-
props: props,
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
if (!props.clientRect || !component.element) {
|
|
75
|
-
return
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const defaultTippyOptions: Partial<TippyProps> = {
|
|
79
|
-
getReferenceClientRect: props.clientRect as () => DOMRect,
|
|
80
|
-
appendTo: () => document.body,
|
|
81
|
-
content: component.element,
|
|
82
|
-
showOnCreate: true,
|
|
83
|
-
interactive: true,
|
|
84
|
-
trigger: 'manual',
|
|
85
|
-
placement: 'bottom-start',
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
popup = tippy('body', {
|
|
89
|
-
...defaultTippyOptions,
|
|
90
|
-
...options.tippyOptions,
|
|
91
|
-
})
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
onUpdate(props: SuggestionProps<TItem>) {
|
|
95
|
-
component?.updateProps(props)
|
|
96
|
-
|
|
97
|
-
if (!props.clientRect) {
|
|
98
|
-
return
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (popup && popup[0]) {
|
|
102
|
-
popup[0].setProps({
|
|
103
|
-
getReferenceClientRect: props.clientRect as () => DOMRect,
|
|
104
|
-
})
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
onKeyDown(props: { event: KeyboardEvent }): boolean {
|
|
109
|
-
if (props.event.key === 'Escape') {
|
|
110
|
-
if (popup && popup[0]) {
|
|
111
|
-
popup[0].hide()
|
|
112
|
-
}
|
|
113
|
-
return true
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
component &&
|
|
118
|
-
component.ref &&
|
|
119
|
-
typeof (component.ref as any).onKeyDown === 'function'
|
|
120
|
-
) {
|
|
121
|
-
return (component.ref as any).onKeyDown(props)
|
|
122
|
-
}
|
|
123
|
-
return false
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
onExit() {
|
|
127
|
-
if (popup && popup[0]) {
|
|
128
|
-
popup[0].destroy()
|
|
129
|
-
}
|
|
130
|
-
if (component) {
|
|
131
|
-
component.destroy()
|
|
132
|
-
}
|
|
133
|
-
popup = null
|
|
134
|
-
component = null
|
|
135
|
-
},
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
} as Omit<SuggestionOptions<TItem>, 'editor'>,
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
addProseMirrorPlugins() {
|
|
143
|
-
return [
|
|
144
|
-
Suggestion<TItem>({
|
|
145
|
-
editor: this.editor,
|
|
146
|
-
...this.options.suggestion,
|
|
147
|
-
}),
|
|
148
|
-
]
|
|
149
|
-
},
|
|
150
|
-
})
|
|
151
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { TagExtension, TagNode, getTagExtensions } from './tag-extension'
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck -- frozen v0 code, kept out of type-check (see tsconfig.app.json)
|
|
2
|
-
import { Node, mergeAttributes, Range, Editor } from '@tiptap/core'
|
|
3
|
-
import { PluginKey } from '@tiptap/pm/state'
|
|
4
|
-
import {
|
|
5
|
-
createSuggestionExtension,
|
|
6
|
-
BaseSuggestionItem,
|
|
7
|
-
} from '../suggestion/createSuggestionExtension'
|
|
8
|
-
import SuggestionList from '../suggestion/SuggestionList.vue'
|
|
9
|
-
import { toValue } from 'vue'
|
|
10
|
-
import { TextEditorProps } from '../../types'
|
|
11
|
-
|
|
12
|
-
export const TagNode = Node.create({
|
|
13
|
-
name: 'tagItem',
|
|
14
|
-
group: 'inline',
|
|
15
|
-
inline: true,
|
|
16
|
-
selectable: true,
|
|
17
|
-
atom: true,
|
|
18
|
-
|
|
19
|
-
addAttributes() {
|
|
20
|
-
return {
|
|
21
|
-
tagId: {
|
|
22
|
-
default: null,
|
|
23
|
-
parseHTML: (element) => element.getAttribute('data-tag-id'),
|
|
24
|
-
renderHTML: (attributes) => {
|
|
25
|
-
if (!attributes.tagId) {
|
|
26
|
-
return {}
|
|
27
|
-
}
|
|
28
|
-
return { 'data-tag-id': attributes.tagId }
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
tagLabel: {
|
|
32
|
-
default: 'tag',
|
|
33
|
-
parseHTML: (element) => element.getAttribute('data-tag-label'),
|
|
34
|
-
renderHTML: (attributes) => ({ 'data-tag-label': attributes.tagLabel }),
|
|
35
|
-
},
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
parseHTML() {
|
|
40
|
-
return [
|
|
41
|
-
{
|
|
42
|
-
tag: 'span.tag-item',
|
|
43
|
-
getAttrs: (dom) => {
|
|
44
|
-
const element = dom as HTMLElement
|
|
45
|
-
return {
|
|
46
|
-
tagId: element.getAttribute('data-tag-id'),
|
|
47
|
-
tagLabel:
|
|
48
|
-
element.getAttribute('data-tag-label') ||
|
|
49
|
-
element.innerText.replace(/^#/, ''),
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
]
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
renderHTML({ HTMLAttributes }) {
|
|
57
|
-
// HTMLAttributes will include data-tag-id and data-tag-label
|
|
58
|
-
return [
|
|
59
|
-
'span',
|
|
60
|
-
mergeAttributes(HTMLAttributes, { class: 'tag-item' }),
|
|
61
|
-
`#${HTMLAttributes['data-tag-label']}`,
|
|
62
|
-
]
|
|
63
|
-
},
|
|
64
|
-
renderText({ node }: any) {
|
|
65
|
-
return `#${node.attrs.tagLabel || ''}`
|
|
66
|
-
},
|
|
67
|
-
addCommands() {
|
|
68
|
-
return {
|
|
69
|
-
setTag:
|
|
70
|
-
(attributes: { tagLabel: string; tagId?: string }) =>
|
|
71
|
-
({ commands }) => {
|
|
72
|
-
return commands.insertContent({
|
|
73
|
-
type: this.name,
|
|
74
|
-
attrs: attributes,
|
|
75
|
-
})
|
|
76
|
-
},
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
interface TagSuggestionItem extends BaseSuggestionItem {
|
|
82
|
-
name?: string
|
|
83
|
-
label: string
|
|
84
|
-
isNew?: boolean
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export const TagExtension = createSuggestionExtension<TagSuggestionItem>({
|
|
88
|
-
name: 'tagSuggestion',
|
|
89
|
-
char: '#',
|
|
90
|
-
pluginKey: new PluginKey('tagSuggestion'),
|
|
91
|
-
component: SuggestionList,
|
|
92
|
-
|
|
93
|
-
addOptions() {
|
|
94
|
-
return {
|
|
95
|
-
tags: [],
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
items: ({ query, editor }) => {
|
|
100
|
-
const { tags: _tags } = editor.extensionManager.extensions.find(
|
|
101
|
-
(ext) => ext.name === 'tagSuggestion',
|
|
102
|
-
)!.options
|
|
103
|
-
let tags = toValue(_tags)
|
|
104
|
-
|
|
105
|
-
// Filter existing tags based on the query
|
|
106
|
-
let filteredTags = tags
|
|
107
|
-
.filter((tag: TagSuggestionItem) =>
|
|
108
|
-
tag.label.toLowerCase().startsWith(query.toLowerCase()),
|
|
109
|
-
)
|
|
110
|
-
.map((tag: TagSuggestionItem) => ({ ...tag, display: tag.label }))
|
|
111
|
-
|
|
112
|
-
if (
|
|
113
|
-
query.length > 0 &&
|
|
114
|
-
!tags.some(
|
|
115
|
-
(tag: TagSuggestionItem) =>
|
|
116
|
-
tag.label.toLowerCase() === query.toLowerCase(),
|
|
117
|
-
)
|
|
118
|
-
) {
|
|
119
|
-
filteredTags.push({
|
|
120
|
-
display: `New tag: "${query}"`,
|
|
121
|
-
label: query,
|
|
122
|
-
isNew: true,
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
return filteredTags
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
command: ({ editor, range, props }) => {
|
|
129
|
-
const attributes = {
|
|
130
|
-
tagLabel: props.label,
|
|
131
|
-
...(props.id && !props.isNew && { tagId: props.id }),
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
editor
|
|
135
|
-
.chain()
|
|
136
|
-
.focus()
|
|
137
|
-
.insertContentAt(range, [
|
|
138
|
-
{
|
|
139
|
-
type: TagNode.name,
|
|
140
|
-
attrs: attributes,
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
type: 'text',
|
|
144
|
-
text: ' ',
|
|
145
|
-
},
|
|
146
|
-
])
|
|
147
|
-
.run()
|
|
148
|
-
},
|
|
149
|
-
|
|
150
|
-
tippyOptions: {
|
|
151
|
-
placement: 'bottom-start',
|
|
152
|
-
offset: [0, 8],
|
|
153
|
-
},
|
|
154
|
-
allowSpaces: false,
|
|
155
|
-
decorationTag: 'span',
|
|
156
|
-
decorationClass: 'tag-suggestion-active',
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
export function getTagExtensions(getTags: () => TextEditorProps['tags']) {
|
|
160
|
-
if (getTags() === null) {
|
|
161
|
-
return []
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return [
|
|
165
|
-
TagNode,
|
|
166
|
-
TagExtension.configure({
|
|
167
|
-
tags: getTags,
|
|
168
|
-
}),
|
|
169
|
-
]
|
|
170
|
-
}
|