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,51 +0,0 @@
1
- import { Editor } from '@tiptap/core'
2
- import { MarkType } from '@tiptap/pm/model'
3
- import { Plugin, PluginKey } from '@tiptap/pm/state'
4
- import { isValidUrl } from '#utils/url-validation'
5
-
6
- type PasteHandlerOptions = {
7
- editor: Editor
8
- defaultProtocol: string
9
- type: MarkType
10
- }
11
-
12
- export function linkPasteHandler(options: PasteHandlerOptions): Plugin {
13
- return new Plugin({
14
- key: new PluginKey('handlePasteLink'),
15
- props: {
16
- handlePaste: (view, event, slice) => {
17
- const { state } = view
18
- const { selection } = state
19
- const { empty } = selection
20
-
21
- if (empty) {
22
- return false
23
- }
24
-
25
- let textContent = ''
26
- slice.content.forEach((node) => {
27
- textContent += node.textContent
28
- })
29
- if (!textContent) {
30
- return false
31
- }
32
-
33
- let link = isValidUrl(textContent) ? textContent : null
34
- if (!link) {
35
- return false
36
- }
37
-
38
- return options.editor
39
- .chain()
40
- .setTextSelection({ from: selection.from, to: selection.to })
41
- .setLink({ href: link })
42
- .setTextSelection(selection.to)
43
- .command(({ tr }) => {
44
- tr.setStoredMarks([])
45
- return true
46
- })
47
- .run()
48
- },
49
- },
50
- })
51
- }
@@ -1 +0,0 @@
1
- export { MentionExtension } from './mention-extension'
@@ -1,204 +0,0 @@
1
- // @ts-nocheck -- frozen v0 code, kept out of type-check (see tsconfig.app.json)
2
- import { MaybeRefOrGetter, toValue, type Component } from 'vue'
3
- import { Extension, Node, mergeAttributes } from '@tiptap/core'
4
- import { VueNodeViewRenderer } from '@tiptap/vue-3'
5
- import { PluginKey } from '@tiptap/pm/state'
6
- import {
7
- createSuggestionExtension,
8
- BaseSuggestionItem,
9
- } from '../suggestion/createSuggestionExtension'
10
- import SuggestionList from '../suggestion/SuggestionList.vue'
11
- import './style.css'
12
-
13
- export interface MentionSuggestionItem extends BaseSuggestionItem {
14
- id: string
15
- label: string
16
- value?: string
17
- email?: string
18
- full_name?: string
19
- }
20
-
21
- function createMentionNode(component?: Component) {
22
- const config: any = {
23
- name: 'mention',
24
- group: 'inline',
25
- inline: true,
26
- selectable: true,
27
- atom: true,
28
- addOptions() {
29
- return {
30
- component: undefined,
31
- }
32
- },
33
-
34
- addAttributes() {
35
- return {
36
- id: {
37
- default: null,
38
- parseHTML: (element: HTMLElement) => element.getAttribute('data-id'),
39
- renderHTML: (attributes: any) => {
40
- if (!attributes.id) {
41
- return {}
42
- }
43
- return { 'data-id': attributes.id }
44
- },
45
- },
46
- label: {
47
- default: null,
48
- parseHTML: (element: HTMLElement) =>
49
- element.getAttribute('data-label'),
50
- renderHTML: (attributes: any) => {
51
- if (!attributes.label) {
52
- return {}
53
- }
54
- return { 'data-label': attributes.label }
55
- },
56
- },
57
- }
58
- },
59
-
60
- parseHTML() {
61
- return [
62
- {
63
- tag: 'span.mention[data-type="mention"]',
64
- getAttrs: (dom: any) => {
65
- const element = dom as HTMLElement
66
- return {
67
- id: element.getAttribute('data-id'),
68
- label: element.getAttribute('data-label'),
69
- }
70
- },
71
- },
72
- ]
73
- },
74
-
75
- renderHTML({ HTMLAttributes }: any) {
76
- return [
77
- 'span',
78
- mergeAttributes(HTMLAttributes, {
79
- class: 'mention',
80
- 'data-type': 'mention',
81
- }),
82
- `@${HTMLAttributes['data-label'] || HTMLAttributes.id || ''}`,
83
- ]
84
- },
85
- renderText({ node }: any) {
86
- return `@${node.attrs.label || node.attrs.id || ''}`
87
- },
88
- }
89
-
90
- if (component) {
91
- config.addNodeView = () => {
92
- return VueNodeViewRenderer(component)
93
- }
94
- }
95
-
96
- return Node.create(config)
97
- }
98
-
99
- const MentionSuggestionExtension =
100
- createSuggestionExtension<MentionSuggestionItem>({
101
- name: 'mentionSuggestion',
102
- char: '@',
103
- pluginKey: new PluginKey('mentionSuggestion'),
104
- component: SuggestionList,
105
-
106
- addOptions() {
107
- return {
108
- mentions: [],
109
- }
110
- },
111
-
112
- items: ({ query, editor }) => {
113
- const { mentions: _mentions } = editor.extensionManager.extensions.find(
114
- (ext) => ext.name === 'mentionSuggestion',
115
- )!.options
116
- const mentions = toValue(_mentions)
117
-
118
- const filtered = mentions
119
- .filter((mention: MentionSuggestionItem) =>
120
- mention.label.toLowerCase().startsWith(query.toLowerCase()),
121
- )
122
- .slice(0, 10)
123
- .map((mention: MentionSuggestionItem) => ({
124
- ...mention,
125
- display: mention.label,
126
- }))
127
-
128
- return filtered
129
- },
130
-
131
- command: ({ editor, range, props }) => {
132
- const attributes = {
133
- id: props.id || props.value,
134
- label: props.label,
135
- }
136
-
137
- editor
138
- .chain()
139
- .focus()
140
- .insertContentAt(range, [
141
- {
142
- type: 'mention',
143
- attrs: attributes,
144
- },
145
- {
146
- type: 'text',
147
- text: ' ',
148
- },
149
- ])
150
- .run()
151
- },
152
-
153
- tippyOptions: {
154
- placement: 'bottom-start',
155
- offset: [0, 8],
156
- },
157
- allowSpaces: false,
158
- decorationTag: 'span',
159
- decorationClass: 'mention-suggestion-active',
160
- })
161
-
162
- export const MentionExtension = Extension.create<{
163
- mentions: MaybeRefOrGetter<MentionSuggestionItem[]>
164
- component?: Component
165
- }>({
166
- name: 'mentionExtension',
167
-
168
- addOptions() {
169
- return {
170
- mentions: [],
171
- component: undefined,
172
- }
173
- },
174
-
175
- addExtensions() {
176
- return [
177
- createMentionNode(this.options.component),
178
- MentionSuggestionExtension.configure({
179
- mentions: this.options.mentions,
180
- }),
181
- ]
182
- },
183
-
184
- addCommands() {
185
- return {
186
- getMentions:
187
- () =>
188
- ({ editor }) => {
189
- const mentions: MentionSuggestionItem[] = []
190
-
191
- editor.state.doc.descendants((node: Node) => {
192
- if (node.type.name === 'mention') {
193
- mentions.push({
194
- id: node.attrs.id,
195
- label: node.attrs.label,
196
- })
197
- }
198
- })
199
-
200
- return mentions
201
- },
202
- }
203
- },
204
- })
@@ -1,11 +0,0 @@
1
- .mention {
2
- font-weight: 600;
3
- box-decoration-break: clone;
4
- padding: 0 1px;
5
- border-radius: 4px;
6
- display: inline-block;
7
- }
8
-
9
- .mention.ProseMirror-selectednode, .mention:hover {
10
- background-color: var(--surface-gray-1, #f8f8f8);
11
- }
@@ -1,236 +0,0 @@
1
- /**
2
- * Shared utilities for color conversion and mapping across text editor extensions
3
- */
4
-
5
- // Foreground/text color mappings (tailwind scale 600)
6
- export const textColorHexMap: Record<string, string> = {
7
- black: '#000000',
8
- red: '#dc2626',
9
- blue: '#1579D0',
10
- green: '#16a34a',
11
- yellow: '#ca8a04',
12
- orange: '#ea580c',
13
- purple: '#9333ea',
14
- pink: '#db2777',
15
- gray: '#6b7280',
16
- indigo: '#4f46e5',
17
- teal: '#0d9488',
18
- cyan: '#06b6d4',
19
- }
20
-
21
- // Background/highlight color mappings (tailwind scale 100)
22
- export const highlightColorHexMap: Record<string, string> = {
23
- red: '#fecaca',
24
- blue: '#bfdbfe',
25
- green: '#bbf7d0',
26
- yellow: '#fef08a',
27
- orange: '#fed7aa',
28
- purple: '#e9d5ff',
29
- pink: '#fbcfe8',
30
- gray: '#e5e7eb',
31
- indigo: '#c7d2fe',
32
- teal: '#99f6e4',
33
- cyan: '#a5f3fc',
34
- }
35
-
36
- // Legacy color mappings for backward compatibility
37
- export const legacyTextColorMap: Record<string, string> = {
38
- '#1F272E': 'gray',
39
- '#ca8a04': 'yellow',
40
- '#ea580c': 'orange',
41
- '#dc2626': 'red',
42
- '#16a34a': 'green',
43
- '#1579D0': 'blue',
44
- '#9333ea': 'purple',
45
- '#db2777': 'pink',
46
- }
47
-
48
- export const legacyHighlightColorMap: Record<string, string> = {
49
- '#fef9c3': 'yellow',
50
- '#ffedd5': 'orange',
51
- '#fee2e2': 'red',
52
- '#dcfce7': 'green',
53
- '#D3E9FC': 'blue',
54
- '#f3e8ff': 'purple',
55
- '#fce7f3': 'pink',
56
- }
57
-
58
- /**
59
- * Converts a hex or RGB color to the closest named color from our allowed list
60
- * @param color - Color to convert (e.g. "#fee2e2" or "rgb(254, 226, 226)")
61
- * @param allowedColors - List of allowed color names
62
- * @param colorMap - Map of color names to hex values to compare against
63
- * @param legacyMap - Optional legacy color mapping for exact matches
64
- * @returns The closest named color
65
- */
66
- export function getClosestNamedColor(
67
- color: string,
68
- allowedColors: string[],
69
- colorMap: Record<string, string>,
70
- legacyMap?: Record<string, string>,
71
- ): string | null {
72
- // Check exact match first for quick returns
73
- if (legacyMap && color.startsWith('#') && legacyMap[color]) {
74
- return legacyMap[color]
75
- }
76
-
77
- // Parse the color to RGB values
78
- let r = 0,
79
- g = 0,
80
- b = 0
81
-
82
- // Handle hex format
83
- if (color.startsWith('#')) {
84
- const hex = color.substring(1)
85
- if (hex.length === 6) {
86
- r = parseInt(hex.substring(0, 2), 16)
87
- g = parseInt(hex.substring(2, 4), 16)
88
- b = parseInt(hex.substring(4, 6), 16)
89
- }
90
- }
91
- // Handle rgb format
92
- else if (color.startsWith('rgb')) {
93
- const rgbMatch = /rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i.exec(color)
94
- if (rgbMatch) {
95
- r = parseInt(rgbMatch[1], 10)
96
- g = parseInt(rgbMatch[2], 10)
97
- b = parseInt(rgbMatch[3], 10)
98
- }
99
- }
100
-
101
- // Invalid color format
102
- if (isNaN(r) || isNaN(g) || isNaN(b)) {
103
- return null
104
- }
105
-
106
- let closestColor = null
107
- let minDistance = Infinity
108
-
109
- // Find the closest color by calculating the Euclidean distance in RGB space
110
- for (const colorName of allowedColors) {
111
- const namedHex = colorMap[colorName]
112
- if (!namedHex) continue
113
-
114
- const namedHexClean = namedHex.startsWith('#')
115
- ? namedHex.substring(1)
116
- : namedHex
117
-
118
- if (namedHexClean.length !== 6) continue
119
-
120
- const nr = parseInt(namedHexClean.substring(0, 2), 16)
121
- const ng = parseInt(namedHexClean.substring(2, 4), 16)
122
- const nb = parseInt(namedHexClean.substring(4, 6), 16)
123
-
124
- // Calculate Euclidean distance
125
- const distance = Math.sqrt(
126
- Math.pow(r - nr, 2) + Math.pow(g - ng, 2) + Math.pow(b - nb, 2),
127
- )
128
-
129
- if (distance < minDistance) {
130
- minDistance = distance
131
- closestColor = colorName
132
- }
133
- }
134
-
135
- return closestColor
136
- }
137
-
138
- /**
139
- * Extracts color from a style attribute and converts it to the closest named color
140
- * @param style - CSS style string (e.g., "color: #ff0000; font-weight: bold;")
141
- * @param allowedColors - List of allowed color names
142
- * @param colorMap - Map of color names to hex values
143
- * @param legacyMap - Optional legacy color mapping
144
- * @param property - CSS property to extract ('color' or 'background-color')
145
- * @returns The closest named color or null
146
- */
147
- export function extractColorFromStyle(
148
- style: string,
149
- allowedColors: string[],
150
- colorMap: Record<string, string> = textColorHexMap,
151
- legacyMap: Record<string, string> = legacyTextColorMap,
152
- property: string = 'color',
153
- ): string | null {
154
- const allColorsInMap = Object.keys(colorMap)
155
-
156
- // Check for color in hex format
157
- const hexColorMatch = new RegExp(`${property}:\\s*(#[0-9a-f]{6})`, 'i').exec(
158
- style,
159
- )
160
- if (hexColorMatch && hexColorMatch[1]) {
161
- const closestOverallColor = getClosestNamedColor(
162
- hexColorMatch[1],
163
- allColorsInMap, // Search in all colors from the map
164
- colorMap,
165
- legacyMap,
166
- )
167
- if (closestOverallColor) {
168
- // Check if this color is in the originally passed 'allowedColors'
169
- if (allowedColors.includes(closestOverallColor)) {
170
- if (closestOverallColor === 'gray') {
171
- return null // Special handling for gray
172
- }
173
- return closestOverallColor // It's the closest, allowed, and not gray
174
- }
175
- // If not in allowedColors, this match is invalid for the current context
176
- }
177
- }
178
-
179
- // Check for color in rgb format
180
- const rgbColorMatch = new RegExp(
181
- `${property}:\\s*(rgb\\(\\s*\\d+\\s*,\\s*\\d+\\s*,\\s*\\d+\\s*\\))`,
182
- 'i',
183
- ).exec(style)
184
- if (rgbColorMatch && rgbColorMatch[1]) {
185
- const closestOverallColor = getClosestNamedColor(
186
- rgbColorMatch[1],
187
- allColorsInMap, // Search in all colors from the map
188
- colorMap,
189
- legacyMap,
190
- )
191
- if (closestOverallColor) {
192
- // Check if this color is in the originally passed 'allowedColors'
193
- if (allowedColors.includes(closestOverallColor)) {
194
- if (closestOverallColor === 'gray') {
195
- return null // Special handling for gray
196
- }
197
- return closestOverallColor // It's the closest, allowed, and not gray
198
- }
199
- // If not in allowedColors, this match is invalid for the current context
200
- }
201
- }
202
-
203
- return null
204
- }
205
-
206
- /**
207
- * Extracts text color from a style attribute
208
- */
209
- export function extractTextColorFromStyle(
210
- style: string,
211
- allowedColors: string[],
212
- ): string | null {
213
- return extractColorFromStyle(
214
- style,
215
- allowedColors,
216
- textColorHexMap,
217
- legacyTextColorMap,
218
- 'color',
219
- )
220
- }
221
-
222
- /**
223
- * Extracts background color from a style attribute for highlights
224
- */
225
- export function extractHighlightColorFromStyle(
226
- style: string,
227
- allowedColors: string[],
228
- ): string | null {
229
- return extractColorFromStyle(
230
- style,
231
- allowedColors,
232
- highlightColorHexMap,
233
- legacyHighlightColorMap,
234
- 'background-color',
235
- )
236
- }
@@ -1,59 +0,0 @@
1
- <template>
2
- <SuggestionList
3
- ref="suggestionList"
4
- :items="props.items"
5
- :command="(item) => onItemSelect(item as CommandItem)"
6
- container-class="min-w-48"
7
- item-class="h-7"
8
- :show-no-results="true"
9
- >
10
- <template #default="{ item }">
11
- <component :is="item.icon" v-if="item.icon" class="mr-2 h-4 w-4" />
12
- <div v-else class="mr-2 h-4 w-4"></div>
13
- <span>{{ item.title }}</span>
14
- </template>
15
- </SuggestionList>
16
- </template>
17
-
18
- <script setup lang="ts">
19
- import { ref, type PropType } from 'vue'
20
- import SuggestionList from '../suggestion/SuggestionList.vue'
21
- import type { Editor, Range } from '@tiptap/core'
22
- import type { CommandItem } from './slash-commands-extension'
23
-
24
- const props = defineProps({
25
- items: {
26
- type: Array as PropType<CommandItem[]>,
27
- required: true,
28
- },
29
- editor: {
30
- type: Object as PropType<Editor>,
31
- required: true,
32
- },
33
- range: {
34
- type: Object as PropType<Range>,
35
- required: true,
36
- },
37
- command: {
38
- type: Function as PropType<(item: CommandItem) => void>,
39
- required: true,
40
- },
41
- query: String,
42
- })
43
-
44
- const suggestionList = ref<InstanceType<typeof SuggestionList> | null>(null)
45
-
46
- const onItemSelect = (item: CommandItem) => {
47
- if (item) {
48
- props.command(item)
49
- }
50
- }
51
-
52
- const onKeyDown = ({ event }: { event: KeyboardEvent }) => {
53
- return suggestionList.value?.onKeyDown({ event }) ?? false
54
- }
55
-
56
- defineExpose({
57
- onKeyDown,
58
- })
59
- </script>