frappe-ui 1.1.0 → 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/CommandPalette/CommandPaletteItem.vue +9 -1
- package/experimental/SpriteIcons/IconPicker.vue +2 -1
- package/experimental.ts +0 -21
- package/package.json +1 -3
- package/src/components/Breadcrumbs/Breadcrumbs.vue +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/HoverCard/HoverCard.vue +21 -5
- package/src/components/MobileNav/MobileNavItem.vue +3 -22
- 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/Tooltip/Tooltip.vue +8 -0
- package/src/components/shared/deferredTrigger.ts +174 -0
- package/src/components/shared/navLink.ts +45 -0
- 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 +26 -9
- 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/list/ListRow.vue +8 -1
- package/src/utils/dialog.ts +20 -2
- package/src/{molecules/editor/extensions/shared → utils}/url-safety.ts +28 -16
- package/tailwind/content.js +0 -1
- package/tailwind/plugin.js +22 -0
- 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,61 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<FloatingMenu
|
|
3
|
-
v-if="floatingMenuButtons"
|
|
4
|
-
:options="{ duration: 100 }"
|
|
5
|
-
:editor="editor"
|
|
6
|
-
class="flex"
|
|
7
|
-
>
|
|
8
|
-
<button
|
|
9
|
-
v-for="button in floatingMenuButtons"
|
|
10
|
-
:key="button.label"
|
|
11
|
-
class="flex rounded-4 p-1 text-ink-gray-8 transition-colors"
|
|
12
|
-
:class="
|
|
13
|
-
button.isActive(editor)
|
|
14
|
-
? 'bg-surface-gray-2'
|
|
15
|
-
: 'hover:bg-surface-gray-2'
|
|
16
|
-
"
|
|
17
|
-
@click="() => button.action(editor)"
|
|
18
|
-
:title="button.label"
|
|
19
|
-
>
|
|
20
|
-
<component v-if="button.icon" :is="button.icon" class="h-4 w-4" />
|
|
21
|
-
<span class="inline-block h-4 min-w-[1rem] text-sm leading-4" v-else>
|
|
22
|
-
{{ button.text }}
|
|
23
|
-
</span>
|
|
24
|
-
</button>
|
|
25
|
-
</FloatingMenu>
|
|
26
|
-
</template>
|
|
27
|
-
<script>
|
|
28
|
-
import { FloatingMenu } from '@tiptap/vue-3/menus'
|
|
29
|
-
import { createEditorButton } from '../utils'
|
|
30
|
-
|
|
31
|
-
export default {
|
|
32
|
-
name: 'TextEditorFloatingMenu',
|
|
33
|
-
props: ['buttons'],
|
|
34
|
-
components: { FloatingMenu },
|
|
35
|
-
inject: ['editor'],
|
|
36
|
-
computed: {
|
|
37
|
-
floatingMenuButtons() {
|
|
38
|
-
if (!this.buttons) return false
|
|
39
|
-
|
|
40
|
-
let buttons
|
|
41
|
-
if (Array.isArray(this.buttons)) {
|
|
42
|
-
buttons = this.buttons
|
|
43
|
-
} else {
|
|
44
|
-
buttons = [
|
|
45
|
-
'Paragraph',
|
|
46
|
-
'Heading 2',
|
|
47
|
-
'Heading 3',
|
|
48
|
-
'Bullet List',
|
|
49
|
-
'Numbered List',
|
|
50
|
-
'Task List',
|
|
51
|
-
'Blockquote',
|
|
52
|
-
'Code',
|
|
53
|
-
'Horizontal Rule',
|
|
54
|
-
'TableOfContents',
|
|
55
|
-
]
|
|
56
|
-
}
|
|
57
|
-
return buttons.map(createEditorButton)
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
}
|
|
61
|
-
</script>
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="inline-flex bg-surface-base p-1">
|
|
3
|
-
<div class="inline-flex items-center gap-1.5">
|
|
4
|
-
<template
|
|
5
|
-
v-for="(button, index) in buttons"
|
|
6
|
-
:key="button?.label || button?.type || `btn-${index}`"
|
|
7
|
-
>
|
|
8
|
-
<template
|
|
9
|
-
v-if="button && (!button.condition || button.condition(editor))"
|
|
10
|
-
>
|
|
11
|
-
<div
|
|
12
|
-
class="h-4 w-[2px] border-l"
|
|
13
|
-
v-if="button && button.type === 'separator'"
|
|
14
|
-
></div>
|
|
15
|
-
<div class="shrink-0" v-else-if="button && button.map">
|
|
16
|
-
<Popover>
|
|
17
|
-
<template #trigger>
|
|
18
|
-
<button
|
|
19
|
-
class="rounded-4 p-1 text-base-medium text-ink-gray-8 transition-colors"
|
|
20
|
-
:class="
|
|
21
|
-
getActiveButton(button)
|
|
22
|
-
? 'bg-surface-gray-3'
|
|
23
|
-
: 'hover:bg-surface-gray-2'
|
|
24
|
-
"
|
|
25
|
-
>
|
|
26
|
-
<component
|
|
27
|
-
v-if="(getActiveButton(button) || button[0]).icon"
|
|
28
|
-
:is="(getActiveButton(button) || button[0]).icon"
|
|
29
|
-
class="h-4 w-4"
|
|
30
|
-
/>
|
|
31
|
-
<span v-else>
|
|
32
|
-
{{ (getActiveButton(button) || button[0]).label }}
|
|
33
|
-
</span>
|
|
34
|
-
</button>
|
|
35
|
-
</template>
|
|
36
|
-
<template #default="{ close }">
|
|
37
|
-
<ul class="p-1.5 focus:outline-none">
|
|
38
|
-
<li
|
|
39
|
-
v-for="option in button"
|
|
40
|
-
v-show="option.condition ? option.condition(editor) : true"
|
|
41
|
-
>
|
|
42
|
-
<component
|
|
43
|
-
v-if="option.component"
|
|
44
|
-
:is="option.component || 'div'"
|
|
45
|
-
v-bind="{ editor }"
|
|
46
|
-
>
|
|
47
|
-
<template v-slot="componentSlotProps">
|
|
48
|
-
<button
|
|
49
|
-
class="w-full h-7 rounded-4 px-2 text-base flex items-center gap-2 hover:bg-surface-gray-3"
|
|
50
|
-
:class="
|
|
51
|
-
option.isDisabled?.(editor) &&
|
|
52
|
-
'opacity-50 pointer-events-none'
|
|
53
|
-
"
|
|
54
|
-
@click="
|
|
55
|
-
() => {
|
|
56
|
-
if (componentSlotProps?.onClick)
|
|
57
|
-
componentSlotProps.onClick(option)
|
|
58
|
-
else if (option.action) onButtonClick(option)
|
|
59
|
-
|
|
60
|
-
close()
|
|
61
|
-
}
|
|
62
|
-
"
|
|
63
|
-
:title="option.label"
|
|
64
|
-
>
|
|
65
|
-
<component
|
|
66
|
-
v-if="option.icon"
|
|
67
|
-
:is="option.icon"
|
|
68
|
-
class="h-4 w-4"
|
|
69
|
-
/>
|
|
70
|
-
<span
|
|
71
|
-
class="whitespace-nowrap text-ink-gray-7"
|
|
72
|
-
v-if="option.label"
|
|
73
|
-
>
|
|
74
|
-
{{ option.label }}
|
|
75
|
-
</span>
|
|
76
|
-
</button>
|
|
77
|
-
</template>
|
|
78
|
-
</component>
|
|
79
|
-
<button
|
|
80
|
-
v-else
|
|
81
|
-
class="w-full h-7 rounded-4 px-2 text-base flex items-center gap-2 hover:bg-surface-gray-3"
|
|
82
|
-
:class="
|
|
83
|
-
option.isDisabled?.(editor) &&
|
|
84
|
-
'opacity-50 pointer-events-none'
|
|
85
|
-
"
|
|
86
|
-
@click="
|
|
87
|
-
() => {
|
|
88
|
-
if (!option.action) return
|
|
89
|
-
onButtonClick(option)
|
|
90
|
-
close()
|
|
91
|
-
}
|
|
92
|
-
"
|
|
93
|
-
>
|
|
94
|
-
<component
|
|
95
|
-
v-if="option.icon"
|
|
96
|
-
:is="option.icon"
|
|
97
|
-
class="size-4 flex-shrink-0 text-ink-gray-6"
|
|
98
|
-
/>
|
|
99
|
-
<span
|
|
100
|
-
v-if="option.label"
|
|
101
|
-
class="whitespace-nowrap text-ink-gray-7"
|
|
102
|
-
>{{ option.label }}</span
|
|
103
|
-
>
|
|
104
|
-
</button>
|
|
105
|
-
</li>
|
|
106
|
-
</ul>
|
|
107
|
-
</template>
|
|
108
|
-
</Popover>
|
|
109
|
-
</div>
|
|
110
|
-
<button
|
|
111
|
-
v-else-if="!button.component"
|
|
112
|
-
class="flex rounded-4 text-ink-gray-8 transition-colors focus-within:ring-0"
|
|
113
|
-
:class="[
|
|
114
|
-
buttons.length > 1 ? 'p-1' : 'p-1.5 border',
|
|
115
|
-
button.isDisabled?.(editor) && 'opacity-50 pointer-events-none',
|
|
116
|
-
button.isActive?.(editor)
|
|
117
|
-
? 'bg-surface-gray-3'
|
|
118
|
-
: 'hover:bg-surface-gray-2',
|
|
119
|
-
button.class,
|
|
120
|
-
]"
|
|
121
|
-
@click="onButtonClick(button)"
|
|
122
|
-
:title="button.label || button.text"
|
|
123
|
-
>
|
|
124
|
-
<component v-if="button.icon" :is="button.icon" class="h-4 w-4" />
|
|
125
|
-
<span
|
|
126
|
-
class="inline-block h-4 min-w-[1rem] text-sm leading-4"
|
|
127
|
-
v-else-if="button.text"
|
|
128
|
-
>
|
|
129
|
-
{{ button.text }}
|
|
130
|
-
</span>
|
|
131
|
-
<span
|
|
132
|
-
class="inline-block h-4 min-w-[1rem] text-sm leading-4"
|
|
133
|
-
v-else-if="button.label"
|
|
134
|
-
>
|
|
135
|
-
{{ button.label }}
|
|
136
|
-
</span>
|
|
137
|
-
</button>
|
|
138
|
-
<Suspense v-else-if="button.component">
|
|
139
|
-
<component :is="button.component || 'div'" v-bind="{ editor }">
|
|
140
|
-
<template v-slot="componentSlotProps">
|
|
141
|
-
<button
|
|
142
|
-
class="flex rounded-4 p-1 text-ink-gray-8 transition-colors"
|
|
143
|
-
:class="[
|
|
144
|
-
button.isDisabled?.(editor) &&
|
|
145
|
-
'opacity-50 pointer-events-none',
|
|
146
|
-
button.isActive?.(editor) || componentSlotProps?.isActive
|
|
147
|
-
? 'bg-surface-gray-3'
|
|
148
|
-
: 'hover:bg-surface-gray-2',
|
|
149
|
-
button.class,
|
|
150
|
-
]"
|
|
151
|
-
@click="
|
|
152
|
-
componentSlotProps?.onClick
|
|
153
|
-
? componentSlotProps.onClick(button)
|
|
154
|
-
: onButtonClick(button)
|
|
155
|
-
"
|
|
156
|
-
:title="button.label"
|
|
157
|
-
>
|
|
158
|
-
<component
|
|
159
|
-
v-if="button.icon"
|
|
160
|
-
:is="button.icon"
|
|
161
|
-
class="h-4 w-4"
|
|
162
|
-
/>
|
|
163
|
-
<span
|
|
164
|
-
class="inline-block h-4 min-w-[1rem] text-sm leading-4"
|
|
165
|
-
v-else
|
|
166
|
-
>
|
|
167
|
-
{{ button.text }}
|
|
168
|
-
</span>
|
|
169
|
-
</button>
|
|
170
|
-
</template>
|
|
171
|
-
</component>
|
|
172
|
-
<template #fallback>
|
|
173
|
-
<button
|
|
174
|
-
class="flex rounded-4 p-1 text-ink-gray-8 transition-colors"
|
|
175
|
-
:class="[
|
|
176
|
-
button.isDisabled?.(editor) &&
|
|
177
|
-
'opacity-50 pointer-events-none',
|
|
178
|
-
'hover:bg-surface-gray-2',
|
|
179
|
-
button.class,
|
|
180
|
-
]"
|
|
181
|
-
@click="onButtonClick(button)"
|
|
182
|
-
:title="button.label"
|
|
183
|
-
>
|
|
184
|
-
<component
|
|
185
|
-
v-if="button.icon"
|
|
186
|
-
:is="button.icon"
|
|
187
|
-
class="h-4 w-4"
|
|
188
|
-
/>
|
|
189
|
-
<span
|
|
190
|
-
class="inline-block h-4 min-w-[1rem] text-sm leading-4"
|
|
191
|
-
v-else
|
|
192
|
-
>
|
|
193
|
-
{{ button.text }}
|
|
194
|
-
</span>
|
|
195
|
-
</button></template
|
|
196
|
-
>
|
|
197
|
-
</Suspense>
|
|
198
|
-
</template>
|
|
199
|
-
</template>
|
|
200
|
-
</div>
|
|
201
|
-
</div>
|
|
202
|
-
</template>
|
|
203
|
-
<script setup>
|
|
204
|
-
import Popover from '#components/Popover/Popover.vue'
|
|
205
|
-
import { inject } from 'vue'
|
|
206
|
-
|
|
207
|
-
const props = defineProps({
|
|
208
|
-
buttons: Array,
|
|
209
|
-
})
|
|
210
|
-
const editor = inject('editor')
|
|
211
|
-
|
|
212
|
-
const onButtonClick = (button) => {
|
|
213
|
-
button.action(editor.value)
|
|
214
|
-
}
|
|
215
|
-
const getActiveButton = (group) => {
|
|
216
|
-
return group.find((b) => b.isActive?.(editor.value))
|
|
217
|
-
}
|
|
218
|
-
</script>
|
|
File without changes
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck -- frozen v0 code, kept out of type-check (see tsconfig.app.json)
|
|
2
|
-
import { common, createLowlight } from 'lowlight'
|
|
3
|
-
import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight'
|
|
4
|
-
import Code from '@tiptap/extension-code'
|
|
5
|
-
import CodeBlockComponent from '../components/CodeBlockComponent.vue'
|
|
6
|
-
import { VueNodeViewRenderer } from '@tiptap/vue-3'
|
|
7
|
-
import { markInputRule } from '@tiptap/core'
|
|
8
|
-
|
|
9
|
-
const INDENT = ' '.repeat(4)
|
|
10
|
-
export const inputRegex = /(?<=^|[^`])`([^`]+)`(?!`)$/
|
|
11
|
-
|
|
12
|
-
function getCodeBlockCtx(state: any) {
|
|
13
|
-
const { $from, from, to } = state.selection
|
|
14
|
-
let d = $from.depth
|
|
15
|
-
while (d > 0 && $from.node(d).type.name !== 'codeBlock') d--
|
|
16
|
-
if (d === 0) return null
|
|
17
|
-
|
|
18
|
-
const node = $from.node(d)
|
|
19
|
-
const start = $from.start(d)
|
|
20
|
-
const text: string = node.textContent
|
|
21
|
-
const fromOffset = from - start
|
|
22
|
-
const toOffset = to - start
|
|
23
|
-
return { start, text, fromOffset, toOffset }
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function lineStartsBetween(text: string, fromOffset: number, toOffset: number) {
|
|
27
|
-
let startOff = text.lastIndexOf('\n', Math.max(0, fromOffset - 1)) + 1
|
|
28
|
-
let endOff = toOffset
|
|
29
|
-
if (endOff > 0 && text[endOff - 1] === '\n') endOff--
|
|
30
|
-
|
|
31
|
-
const starts: number[] = [startOff]
|
|
32
|
-
let i = startOff
|
|
33
|
-
while (true) {
|
|
34
|
-
const nl = text.indexOf('\n', i)
|
|
35
|
-
if (nl === -1 || nl >= endOff) break
|
|
36
|
-
starts.push(nl + 1)
|
|
37
|
-
i = nl + 1
|
|
38
|
-
}
|
|
39
|
-
return starts
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const lowlight = createLowlight(common)
|
|
43
|
-
|
|
44
|
-
export const ExtendedCodeBlock = CodeBlockLowlight.extend({
|
|
45
|
-
addNodeView() {
|
|
46
|
-
return VueNodeViewRenderer(CodeBlockComponent)
|
|
47
|
-
},
|
|
48
|
-
addKeyboardShortcuts() {
|
|
49
|
-
return {
|
|
50
|
-
Tab: () => {
|
|
51
|
-
const { state, dispatch } = this.editor.view
|
|
52
|
-
const ctx = getCodeBlockCtx(state)
|
|
53
|
-
if (!ctx) return false
|
|
54
|
-
|
|
55
|
-
const { start, text, fromOffset, toOffset } = ctx
|
|
56
|
-
const multiline = text.slice(fromOffset, toOffset).includes('\n')
|
|
57
|
-
const tr = state.tr
|
|
58
|
-
if (multiline) {
|
|
59
|
-
for (const off of lineStartsBetween(text, fromOffset, toOffset)) {
|
|
60
|
-
const pos = tr.mapping.map(start + off)
|
|
61
|
-
tr.insertText(INDENT, pos)
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
tr.insertText(INDENT, state.selection.from)
|
|
65
|
-
}
|
|
66
|
-
dispatch(tr)
|
|
67
|
-
return true
|
|
68
|
-
},
|
|
69
|
-
'Shift-Tab': () => {
|
|
70
|
-
const { state, dispatch } = this.editor.view
|
|
71
|
-
const ctx = getCodeBlockCtx(state)
|
|
72
|
-
if (!ctx) return false
|
|
73
|
-
|
|
74
|
-
const { start, text, fromOffset, toOffset } = ctx
|
|
75
|
-
const tr = state.tr
|
|
76
|
-
for (const off of lineStartsBetween(text, fromOffset, toOffset)) {
|
|
77
|
-
let len = 0
|
|
78
|
-
if (text.substr(off, 4) === INDENT) len = 4
|
|
79
|
-
else if (text[off] === '\t') len = 1
|
|
80
|
-
|
|
81
|
-
if (len > 0) {
|
|
82
|
-
const s = tr.mapping.map(start + off)
|
|
83
|
-
const e = tr.mapping.map(start + off + len)
|
|
84
|
-
tr.delete(s, e)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
dispatch(tr)
|
|
89
|
-
return true
|
|
90
|
-
},
|
|
91
|
-
'`': () => {
|
|
92
|
-
const { from, to } = this.editor.state.selection
|
|
93
|
-
if (from === to) return false
|
|
94
|
-
return this.editor.commands.toggleCode()
|
|
95
|
-
},
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
}).configure({ lowlight })
|
|
99
|
-
|
|
100
|
-
export const ExtendedCode = Code.extend({
|
|
101
|
-
addKeyboardShortcuts() {
|
|
102
|
-
return {
|
|
103
|
-
'`': () => {
|
|
104
|
-
const { from, to } = this.editor.state.selection
|
|
105
|
-
if (from === to) return false
|
|
106
|
-
return this.editor.commands.toggleCode()
|
|
107
|
-
},
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
addInputRules() {
|
|
112
|
-
return [
|
|
113
|
-
markInputRule({
|
|
114
|
-
find: inputRegex,
|
|
115
|
-
type: this.type,
|
|
116
|
-
}),
|
|
117
|
-
]
|
|
118
|
-
},
|
|
119
|
-
})
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import '@tiptap/extension-text-style'
|
|
2
|
-
|
|
3
|
-
import { Extension } from '@tiptap/core'
|
|
4
|
-
import { extractTextColorFromStyle } from '../shared/color-utils'
|
|
5
|
-
|
|
6
|
-
export type ColorOptions = {
|
|
7
|
-
/**
|
|
8
|
-
* The types where the color can be applied
|
|
9
|
-
* @default ['textStyle']
|
|
10
|
-
*/
|
|
11
|
-
types: string[]
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Available color names that can be used
|
|
15
|
-
* @default ['red', 'blue', 'green', 'yellow', 'orange', 'purple', 'pink', 'gray']
|
|
16
|
-
*/
|
|
17
|
-
colors: string[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
declare module '@tiptap/core' {
|
|
21
|
-
interface Commands<ReturnType> {
|
|
22
|
-
namedColor: {
|
|
23
|
-
/**
|
|
24
|
-
* Set the text color by name
|
|
25
|
-
* @param colorName The named color to set (e.g., 'blue', 'red')
|
|
26
|
-
* @example editor.commands.setColorByName('blue')
|
|
27
|
-
*/
|
|
28
|
-
setColorByName: (colorName: string) => ReturnType
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Unset the text color
|
|
32
|
-
* @example editor.commands.unsetColor()
|
|
33
|
-
*/
|
|
34
|
-
unsetColor: () => ReturnType
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* This extension allows you to color your text using named colors instead of hex/rgb values.
|
|
41
|
-
* Colors are applied as data attributes that can be styled with CSS for light/dark mode support.
|
|
42
|
-
*/
|
|
43
|
-
export const NamedColorExtension = Extension.create<ColorOptions>({
|
|
44
|
-
name: 'namedColor',
|
|
45
|
-
|
|
46
|
-
addOptions() {
|
|
47
|
-
return {
|
|
48
|
-
types: ['textStyle'],
|
|
49
|
-
colors: [
|
|
50
|
-
'red',
|
|
51
|
-
'blue',
|
|
52
|
-
'green',
|
|
53
|
-
'yellow',
|
|
54
|
-
'orange',
|
|
55
|
-
'purple',
|
|
56
|
-
'pink',
|
|
57
|
-
'gray',
|
|
58
|
-
'teal',
|
|
59
|
-
'cyan',
|
|
60
|
-
],
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
addGlobalAttributes() {
|
|
65
|
-
return [
|
|
66
|
-
{
|
|
67
|
-
types: this.options.types,
|
|
68
|
-
attributes: {
|
|
69
|
-
color: {
|
|
70
|
-
default: null,
|
|
71
|
-
parseHTML: (element) => {
|
|
72
|
-
// Check for CSS custom property format in style attribute
|
|
73
|
-
const style = element.getAttribute('style')
|
|
74
|
-
if (style) {
|
|
75
|
-
const colorMatch = style.match(
|
|
76
|
-
/color:\s*var\(--prose-color-(\w+)\)/,
|
|
77
|
-
)
|
|
78
|
-
if (colorMatch && this.options.colors.includes(colorMatch[1])) {
|
|
79
|
-
return colorMatch[1]
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Fallback: try extracting from legacy formats
|
|
83
|
-
const extractedColor = extractTextColorFromStyle(
|
|
84
|
-
style,
|
|
85
|
-
this.options.colors,
|
|
86
|
-
)
|
|
87
|
-
if (extractedColor) {
|
|
88
|
-
return extractedColor
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return null
|
|
93
|
-
},
|
|
94
|
-
renderHTML: (attributes) => {
|
|
95
|
-
if (
|
|
96
|
-
!attributes.color ||
|
|
97
|
-
!this.options.colors.includes(attributes.color)
|
|
98
|
-
) {
|
|
99
|
-
return {}
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
style: `color: var(--prose-color-${attributes.color})`,
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
]
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
addCommands() {
|
|
112
|
-
return {
|
|
113
|
-
setColorByName:
|
|
114
|
-
(colorName: string) =>
|
|
115
|
-
({ chain }) => {
|
|
116
|
-
// Validate that the color name is allowed
|
|
117
|
-
if (!this.options.colors.includes(colorName)) {
|
|
118
|
-
console.warn(
|
|
119
|
-
`Color "${colorName}" is not in the allowed colors list`,
|
|
120
|
-
)
|
|
121
|
-
return false
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
let commandChain = chain().setMark('textStyle', { color: colorName })
|
|
125
|
-
|
|
126
|
-
return commandChain.focus().run()
|
|
127
|
-
},
|
|
128
|
-
unsetColor:
|
|
129
|
-
() =>
|
|
130
|
-
({ chain }) => {
|
|
131
|
-
return chain()
|
|
132
|
-
.setMark('textStyle', { color: null })
|
|
133
|
-
.removeEmptyTextStyle()
|
|
134
|
-
.run()
|
|
135
|
-
},
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
export { NamedColorExtension as default }
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
.ProseMirror {
|
|
2
|
-
--prose-color-red: var(--red-600);
|
|
3
|
-
--prose-color-blue: var(--blue-600);
|
|
4
|
-
--prose-color-green: var(--green-600);
|
|
5
|
-
--prose-color-yellow: var(--yellow-600);
|
|
6
|
-
--prose-color-orange: var(--orange-600);
|
|
7
|
-
--prose-color-purple: var(--purple-600);
|
|
8
|
-
--prose-color-pink: var(--pink-600);
|
|
9
|
-
--prose-color-gray: var(--gray-600);
|
|
10
|
-
--prose-color-teal: var(--teal-600);
|
|
11
|
-
--prose-color-cyan: var(--cyan-600);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
[data-theme='dark'] .ProseMirror {
|
|
15
|
-
--prose-color-red: var(--dark-red-400);
|
|
16
|
-
--prose-color-blue: var(--dark-blue-400);
|
|
17
|
-
--prose-color-green: var(--dark-green-400);
|
|
18
|
-
--prose-color-yellow: var(--dark-yellow-400);
|
|
19
|
-
--prose-color-orange: var(--dark-orange-400);
|
|
20
|
-
--prose-color-purple: var(--dark-purple-400);
|
|
21
|
-
--prose-color-pink: var(--dark-pink-400);
|
|
22
|
-
--prose-color-gray: var(--dark-gray-400);
|
|
23
|
-
--prose-color-teal: var(--dark-teal-400);
|
|
24
|
-
--prose-color-cyan: var(--dark-cyan-400);
|
|
25
|
-
}
|