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.
Files changed (194) hide show
  1. package/experimental/Calendar/CalendarEventRow.vue +0 -4
  2. package/experimental/Calendar/calendarUtils.ts +33 -21
  3. package/experimental/CommandPalette/CommandPaletteItem.vue +9 -1
  4. package/experimental/MultiEmailInput/MultiEmailInput.vue +64 -12
  5. package/experimental/MultiEmailInput/types.ts +12 -3
  6. package/experimental/SpriteIcons/IconPicker.vue +2 -1
  7. package/experimental/Stepper/StepIndicator.vue +129 -0
  8. package/experimental/Stepper/Stepper.api.md +117 -0
  9. package/experimental/Stepper/Stepper.md +95 -0
  10. package/experimental/Stepper/Stepper.vue +82 -0
  11. package/experimental/Stepper/StepperHorizontal.vue +93 -0
  12. package/experimental/Stepper/StepperVertical.vue +291 -0
  13. package/experimental/Stepper/index.ts +11 -0
  14. package/experimental/Stepper/resolve.ts +87 -0
  15. package/experimental/Stepper/types.ts +89 -0
  16. package/experimental.ts +2 -21
  17. package/package.json +1 -3
  18. package/src/charts/CalendarHeatmapChart.vue +353 -0
  19. package/src/charts/DonutChart.vue +34 -58
  20. package/src/charts/HeatmapChart.vue +26 -64
  21. package/src/charts/NumberCard.vue +62 -7
  22. package/src/charts/PercentageBarChart.vue +243 -0
  23. package/src/charts/SankeyChart.vue +14 -11
  24. package/src/charts/ScatterChart.vue +24 -20
  25. package/src/charts/axisChartCommon.ts +182 -18
  26. package/src/charts/axisFormat.ts +8 -3
  27. package/src/charts/calendarHeatmapOptions.ts +604 -0
  28. package/src/charts/colorMath.ts +26 -0
  29. package/src/charts/components/ChartContainer.vue +63 -53
  30. package/src/charts/components/ChartLegend.vue +216 -24
  31. package/src/charts/components/ChartScale.vue +85 -0
  32. package/src/charts/core/dataLabelFit.ts +45 -6
  33. package/src/charts/core/useAxisChart.ts +36 -19
  34. package/src/charts/core/useChart.ts +6 -1
  35. package/src/charts/core/usePlotKeyboard.ts +13 -2
  36. package/src/charts/docs/BarChart.md +11 -3
  37. package/src/charts/docs/CalendarHeatmapChart.api.md +165 -0
  38. package/src/charts/docs/CalendarHeatmapChart.md +33 -0
  39. package/src/charts/docs/ChartContainer.api.md +6 -0
  40. package/src/charts/docs/ChartLegend.api.md +1 -1
  41. package/src/charts/docs/ChartLegend.md +25 -3
  42. package/src/charts/docs/DonutChart.api.md +12 -0
  43. package/src/charts/docs/DonutChart.md +17 -0
  44. package/src/charts/docs/HeatmapChart.api.md +1 -1
  45. package/src/charts/docs/LineChart.md +5 -3
  46. package/src/charts/docs/NumberCard.api.md +6 -0
  47. package/src/charts/docs/NumberCard.md +6 -0
  48. package/src/charts/docs/Overview.md +13 -6
  49. package/src/charts/docs/PercentageBarChart.api.md +148 -0
  50. package/src/charts/docs/PercentageBarChart.md +42 -0
  51. package/src/charts/docs/ScatterChart.md +2 -3
  52. package/src/charts/donutChartOptions.ts +22 -130
  53. package/src/charts/format.ts +4 -1
  54. package/src/charts/heatmapOptions.ts +17 -12
  55. package/src/charts/hiddenSeries.ts +8 -3
  56. package/src/charts/index.ts +12 -0
  57. package/src/charts/legendOverflow.ts +40 -0
  58. package/src/charts/numberCardFormat.ts +19 -13
  59. package/src/charts/referenceLines.ts +2 -1
  60. package/src/charts/scatterOptions.ts +16 -3
  61. package/src/charts/seriesData.ts +8 -3
  62. package/src/charts/slices.ts +228 -0
  63. package/src/charts/tokens.ts +99 -0
  64. package/src/charts/types.ts +318 -9
  65. package/src/components/Avatar/Avatar.md +27 -2
  66. package/src/components/Avatar/Avatar.vue +29 -12
  67. package/src/components/Breadcrumbs/Breadcrumbs.vue +2 -1
  68. package/src/components/Combobox/Combobox.vue +9 -2
  69. package/src/components/Combobox/ComboboxResults.vue +6 -1
  70. package/src/components/Combobox/utils.ts +2 -1
  71. package/src/components/DatePicker/DatePicker.md +7 -0
  72. package/src/components/DatePicker/DatePicker.vue +6 -0
  73. package/src/components/DatePicker/DateTimePicker.vue +6 -0
  74. package/src/components/DatePicker/composables.ts +18 -1
  75. package/src/components/DatePicker/utils.ts +53 -0
  76. package/src/components/Dialog/Dialog.md +3 -1
  77. package/src/components/Duration/Duration.api.md +16 -3
  78. package/src/components/Duration/Duration.md +21 -0
  79. package/src/components/Duration/Duration.vue +29 -8
  80. package/src/components/Duration/duration.ts +105 -44
  81. package/src/components/Duration/index.ts +1 -0
  82. package/src/components/Duration/types.ts +30 -1
  83. package/src/components/HoverCard/HoverCard.vue +21 -5
  84. package/src/components/Menu/utils.ts +3 -2
  85. package/src/components/MobileNav/MobileNavItem.vue +3 -22
  86. package/src/components/MultiSelect/MultiSelect.api.md +5 -0
  87. package/src/components/MultiSelect/MultiSelect.vue +34 -0
  88. package/src/components/MultiSelect/MultiSelectResults.vue +3 -4
  89. package/src/components/MultiSelect/types.ts +6 -0
  90. package/src/components/Select/Select.vue +4 -4
  91. package/src/components/Select/utils.ts +1 -0
  92. package/src/components/SettingsDialog/SettingsDialog.api.md +7 -2
  93. package/src/components/SettingsDialog/SettingsDialog.md +2 -1
  94. package/src/components/SettingsDialog/SettingsRow.vue +12 -2
  95. package/src/components/Sidebar/SidebarItem.vue +3 -33
  96. package/src/components/SidebarRail/SidebarRailItem.vue +4 -17
  97. package/src/components/Switch/Switch.vue +3 -3
  98. package/src/components/Tooltip/Tooltip.vue +8 -0
  99. package/src/components/shared/deferredTrigger.ts +174 -0
  100. package/src/components/shared/navLink.ts +45 -0
  101. package/src/components/shared/selection/utils.ts +8 -1
  102. package/src/data-fetching/useCall/useCall.ts +25 -26
  103. package/src/data-fetching/useFrappeFetch.ts +48 -2
  104. package/src/data-fetching/useList/useList.ts +11 -3
  105. package/src/data-fetching/utils.ts +15 -1
  106. package/src/molecules/editor/components/MediaNodeView.vue +10 -1
  107. package/src/molecules/editor/components/MediaResizeGuide.vue +71 -0
  108. package/src/molecules/editor/components/media-node-view-utils.ts +7 -0
  109. package/src/molecules/editor/composables/useNodeViewResize.ts +142 -10
  110. package/src/molecules/editor/extensions/attachment/attachment-engine.ts +1 -1
  111. package/src/molecules/editor/extensions/content-paste/paste-html-utils.ts +16 -6
  112. package/src/molecules/editor/extensions/iframe/IframeNodeView.vue +29 -10
  113. package/src/molecules/editor/extensions/iframe/iframe-allowlist.ts +35 -16
  114. package/src/molecules/editor/extensions/iframe/iframe-embed-utils.ts +1 -1
  115. package/src/molecules/editor/extensions/iframe/iframe-extension.ts +30 -30
  116. package/src/molecules/editor/extensions/link/LinkEditorPopup.vue +1 -1
  117. package/src/molecules/editor/extensions/link/link-paste-plugin.ts +1 -1
  118. package/src/molecules/editor/extensions/shared/media-upload-engine.ts +1 -1
  119. package/src/molecules/editor/useEditor.ts +12 -6
  120. package/src/molecules/list/ListRow.vue +8 -1
  121. package/src/utils/dialog.ts +57 -16
  122. package/src/{molecules/editor/extensions/shared → utils}/url-safety.ts +28 -16
  123. package/tailwind/content.js +1 -1
  124. package/tailwind/plugin.js +22 -0
  125. package/vite/README.md +5 -3
  126. package/vite/codeLanguages.js +41 -17
  127. package/vite/doctypeInterfaceGenerator.js +52 -39
  128. package/vitepress/index.node.ts +0 -2
  129. package/experimental/TextEditor/TextEditor.api.md +0 -161
  130. package/experimental/TextEditor/TextEditor.vue +0 -298
  131. package/experimental/TextEditor/classIcon.ts +0 -21
  132. package/experimental/TextEditor/commands.js +0 -344
  133. package/experimental/TextEditor/components/CodeBlockComponent.vue +0 -103
  134. package/experimental/TextEditor/components/FontColor.vue +0 -153
  135. package/experimental/TextEditor/components/ImageViewerModal.vue +0 -463
  136. package/experimental/TextEditor/components/InsertImage.vue +0 -54
  137. package/experimental/TextEditor/components/InsertLink.vue +0 -13
  138. package/experimental/TextEditor/components/InsertVideo.vue +0 -14
  139. package/experimental/TextEditor/components/LinkPopup.vue +0 -99
  140. package/experimental/TextEditor/components/MediaNodeView.vue +0 -398
  141. package/experimental/TextEditor/components/MentionList.vue +0 -95
  142. package/experimental/TextEditor/components/TextEditorBubbleMenu.vue +0 -78
  143. package/experimental/TextEditor/components/TextEditorFixedMenu.vue +0 -78
  144. package/experimental/TextEditor/components/TextEditorFloatingMenu.vue +0 -61
  145. package/experimental/TextEditor/components/TextEditorMenu.vue +0 -218
  146. package/experimental/TextEditor/components/index.js +0 -0
  147. package/experimental/TextEditor/extensions/code-block.ts +0 -119
  148. package/experimental/TextEditor/extensions/color/color-extension.ts +0 -140
  149. package/experimental/TextEditor/extensions/color/color-styles.css +0 -25
  150. package/experimental/TextEditor/extensions/color/index.ts +0 -2
  151. package/experimental/TextEditor/extensions/content-paste-extension.ts +0 -160
  152. package/experimental/TextEditor/extensions/copy-styles.ts +0 -160
  153. package/experimental/TextEditor/extensions/emoji/EmojiList.vue +0 -55
  154. package/experimental/TextEditor/extensions/emoji/emoji-extension.ts +0 -55
  155. package/experimental/TextEditor/extensions/emoji/emojis.json +0 -7422
  156. package/experimental/TextEditor/extensions/heading/heading.ts +0 -20
  157. package/experimental/TextEditor/extensions/highlight/highlight-extension.ts +0 -241
  158. package/experimental/TextEditor/extensions/highlight/highlight-styles.css +0 -31
  159. package/experimental/TextEditor/extensions/highlight/index.ts +0 -2
  160. package/experimental/TextEditor/extensions/iframe/IframeNodeView.vue +0 -308
  161. package/experimental/TextEditor/extensions/iframe/InsertIframe.vue +0 -209
  162. package/experimental/TextEditor/extensions/iframe/iframe-extension.ts +0 -404
  163. package/experimental/TextEditor/extensions/iframe/index.ts +0 -11
  164. package/experimental/TextEditor/extensions/iframe/utils.ts +0 -283
  165. package/experimental/TextEditor/extensions/image/image-extension.ts +0 -661
  166. package/experimental/TextEditor/extensions/image/index.ts +0 -5
  167. package/experimental/TextEditor/extensions/image-group/ImageGroupNodeView.vue +0 -182
  168. package/experimental/TextEditor/extensions/image-group/ImageGroupUploadDialog.vue +0 -740
  169. package/experimental/TextEditor/extensions/image-group/image-group-extension.ts +0 -187
  170. package/experimental/TextEditor/extensions/image-viewer-extension.ts +0 -162
  171. package/experimental/TextEditor/extensions/link/index.ts +0 -1
  172. package/experimental/TextEditor/extensions/link/link-extension.ts +0 -323
  173. package/experimental/TextEditor/extensions/link/linkPasteHandler.ts +0 -51
  174. package/experimental/TextEditor/extensions/mention/index.ts +0 -1
  175. package/experimental/TextEditor/extensions/mention/mention-extension.ts +0 -204
  176. package/experimental/TextEditor/extensions/mention/style.css +0 -11
  177. package/experimental/TextEditor/extensions/shared/color-utils.ts +0 -236
  178. package/experimental/TextEditor/extensions/slash-commands/SlashCommandsList.vue +0 -59
  179. package/experimental/TextEditor/extensions/slash-commands/slash-commands-extension.ts +0 -184
  180. package/experimental/TextEditor/extensions/suggestion/SuggestionList.vue +0 -130
  181. package/experimental/TextEditor/extensions/suggestion/createSuggestionExtension.ts +0 -151
  182. package/experimental/TextEditor/extensions/suggestion/index.ts +0 -5
  183. package/experimental/TextEditor/extensions/tag/index.ts +0 -1
  184. package/experimental/TextEditor/extensions/tag/tag-extension.ts +0 -170
  185. package/experimental/TextEditor/extensions/toc-node/TocNodeView.vue +0 -439
  186. package/experimental/TextEditor/extensions/toc-node/index.ts +0 -3
  187. package/experimental/TextEditor/extensions/toc-node/toc-node-extension.ts +0 -167
  188. package/experimental/TextEditor/extensions/video-extension.ts +0 -653
  189. package/experimental/TextEditor/hljs-github.css +0 -197
  190. package/experimental/TextEditor/index.ts +0 -21
  191. package/experimental/TextEditor/style.css +0 -190
  192. package/experimental/TextEditor/types.ts +0 -72
  193. package/experimental/TextEditor/utils.js +0 -11
  194. 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
- }
@@ -1,2 +0,0 @@
1
- export { NamedColorExtension, default } from './color-extension'
2
- export type { ColorOptions } from './color-extension'