@bagelink/vue 0.0.986 → 0.0.988
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/dist/components/Btn.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/CodeEditor/CodeTypes.d.ts +197 -0
- package/dist/components/form/inputs/CodeEditor/CodeTypes.d.ts.map +1 -0
- package/dist/components/form/inputs/CodeEditor/Index.vue.d.ts +60 -0
- package/dist/components/form/inputs/CodeEditor/Index.vue.d.ts.map +1 -0
- package/dist/components/form/inputs/CodeEditor/format.d.ts +2 -0
- package/dist/components/form/inputs/CodeEditor/format.d.ts.map +1 -0
- package/dist/components/form/inputs/RichText/Toolbar.vue.d.ts +5 -3
- package/dist/components/form/inputs/RichText/Toolbar.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/components/Toolbar.vue.d.ts +14 -0
- package/dist/components/form/inputs/RichText/components/Toolbar.vue.d.ts.map +1 -0
- package/dist/components/form/inputs/RichText/components/gridBox.vue.d.ts +11 -0
- package/dist/components/form/inputs/RichText/components/gridBox.vue.d.ts.map +1 -0
- package/dist/components/form/inputs/RichText/composables/useEditor.d.ts +86 -0
- package/dist/components/form/inputs/RichText/composables/useEditor.d.ts.map +1 -0
- package/dist/components/form/inputs/RichText/composables/useEditorKeyboard.d.ts +2 -0
- package/dist/components/form/inputs/RichText/composables/useEditorKeyboard.d.ts.map +1 -0
- package/dist/components/form/inputs/RichText/config.d.ts +5 -0
- package/dist/components/form/inputs/RichText/config.d.ts.map +1 -0
- package/dist/components/form/inputs/RichText/index.vue.d.ts +1 -1
- package/dist/components/form/inputs/RichText/index.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/utils/formatting.d.ts +7 -0
- package/dist/components/form/inputs/RichText/utils/formatting.d.ts.map +1 -0
- package/dist/components/form/inputs/RichText/utils/media.d.ts +4 -0
- package/dist/components/form/inputs/RichText/utils/media.d.ts.map +1 -0
- package/dist/components/form/inputs/RichText/utils/selection.d.ts +4 -0
- package/dist/components/form/inputs/RichText/utils/selection.d.ts.map +1 -0
- package/dist/components/form/inputs/RichText/utils/table.d.ts +6 -0
- package/dist/components/form/inputs/RichText/utils/table.d.ts.map +1 -0
- package/dist/components/form/inputs/index.d.ts +1 -0
- package/dist/components/form/inputs/index.d.ts.map +1 -1
- package/dist/editor-CUDRLdmS.js +4 -0
- package/dist/editor-Cu374vEW.cjs +4 -0
- package/dist/index.cjs +53541 -763
- package/dist/index.mjs +53542 -764
- package/dist/style.css +19779 -97
- package/package.json +2 -1
- package/src/components/Btn.vue +3 -0
- package/src/components/form/inputs/CodeEditor/CodeTypes.ts +446 -0
- package/src/components/form/inputs/CodeEditor/Index.vue +440 -0
- package/src/components/form/inputs/CodeEditor/format.ts +98 -0
- package/src/components/form/inputs/CodeEditor/themes/brown-papersq.png +0 -0
- package/src/components/form/inputs/CodeEditor/themes/pojoaque.jpg +0 -0
- package/src/components/form/inputs/CodeEditor/themes/themes-base16.css +12809 -0
- package/src/components/form/inputs/CodeEditor/themes/themes.css +6740 -0
- package/src/components/form/inputs/RichText/components/Toolbar.vue +51 -0
- package/src/components/form/inputs/RichText/components/gridBox.vue +22 -0
- package/src/components/form/inputs/RichText/composables/useEditor.ts +208 -0
- package/src/components/form/inputs/RichText/composables/useEditorKeyboard.ts +21 -0
- package/src/components/form/inputs/RichText/config.ts +73 -0
- package/src/components/form/inputs/RichText/editor.css +25 -0
- package/src/components/form/inputs/RichText/index.vue +81 -193
- package/src/components/form/inputs/RichText/richTextTypes.d.ts +77 -0
- package/src/components/form/inputs/RichText/utils/formatting.ts +98 -0
- package/src/components/form/inputs/RichText/utils/media.ts +42 -0
- package/src/components/form/inputs/RichText/utils/selection.ts +48 -0
- package/src/components/form/inputs/RichText/utils/table.ts +79 -0
- package/src/components/form/inputs/index.ts +1 -0
- package/src/components/form/inputs/RichText/Toolbar.vue +0 -87
- package/src/components/form/inputs/RichText/formatting.ts +0 -246
- package/src/components/form/inputs/RichText/richtext-types.ts +0 -29
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import type { ToolbarConfig, ToolbarConfigOption } from './richtext-types'
|
|
3
|
-
import { Btn, type MaterialIcons } from '@bagelink/vue'
|
|
4
|
-
|
|
5
|
-
defineProps<{ config: ToolbarConfig }>()
|
|
6
|
-
const emit = defineEmits(['action'])
|
|
7
|
-
|
|
8
|
-
// const colorPicker = $ref<HTMLInputElement | undefined>()
|
|
9
|
-
// const fontSizeInput = $ref<HTMLInputElement | undefined>()
|
|
10
|
-
|
|
11
|
-
interface toolbarOption {
|
|
12
|
-
name: ToolbarConfigOption | 'separator'
|
|
13
|
-
label?: string
|
|
14
|
-
icon?: MaterialIcons
|
|
15
|
-
class?: string
|
|
16
|
-
}
|
|
17
|
-
const toolbarOptions: toolbarOption[] = [
|
|
18
|
-
{ name: 'formatBlock', label: 'h2', icon: 'format_h2' },
|
|
19
|
-
{ name: 'formatBlock', label: 'h3', icon: 'format_h3' },
|
|
20
|
-
{ name: 'formatBlock', label: 'h4', icon: 'format_h4' },
|
|
21
|
-
{ name: 'formatBlock', label: 'h5', icon: 'format_h5' },
|
|
22
|
-
{ name: 'formatBlock', label: 'h6', icon: 'format_h6' },
|
|
23
|
-
{ name: 'separator' },
|
|
24
|
-
{ name: 'bold', label: 'Bold', icon: 'format_bold' },
|
|
25
|
-
{ name: 'italic', label: 'Italic', icon: 'format_italic' },
|
|
26
|
-
{ name: 'underline', label: 'Underline', icon: 'format_underlined' },
|
|
27
|
-
{ name: 'separator' },
|
|
28
|
-
{ name: 'orderedList', label: 'Ordered List', icon: 'format_list_numbered' },
|
|
29
|
-
{ name: 'unorderedList', label: 'Unordered List', icon: 'format_list_bulleted' },
|
|
30
|
-
{ name: 'separator' },
|
|
31
|
-
{ name: 'link', label: 'Link', icon: 'add_link' },
|
|
32
|
-
{ name: 'image', label: 'Image', icon: 'add_photo_alternate' },
|
|
33
|
-
{ name: 'youtube', label: 'YouTube', icon: 'youtube_activity' },
|
|
34
|
-
{ name: 'separator' },
|
|
35
|
-
{ name: 'splitView', label: 'Split View', icon: 'code' },
|
|
36
|
-
{ name: 'clear', label: 'Clear Formatting', icon: 'format_clear' },
|
|
37
|
-
{ name: 'fullScreen', label: 'Full Screen', icon: 'fullscreen', class: 'ms-auto' },
|
|
38
|
-
]
|
|
39
|
-
|
|
40
|
-
// function handleColorPick(type: 'textColor' | 'backgroundColor') {
|
|
41
|
-
// const color = colorPicker?.value
|
|
42
|
-
// if (color) {
|
|
43
|
-
// emit('action', type, color)
|
|
44
|
-
// }
|
|
45
|
-
// }
|
|
46
|
-
|
|
47
|
-
// function handleFontSizeChange() {
|
|
48
|
-
// const size = fontSizeInput?.value
|
|
49
|
-
// if (size) {
|
|
50
|
-
// emit('action', 'fontSize', size)
|
|
51
|
-
// }
|
|
52
|
-
// }
|
|
53
|
-
</script>
|
|
54
|
-
|
|
55
|
-
<template>
|
|
56
|
-
<div class="toolbar flex gap-025 pb-05 flex-wrap" role="toolbar">
|
|
57
|
-
<template v-for="(action, index) in toolbarOptions" :key="index">
|
|
58
|
-
<Btn
|
|
59
|
-
v-if="action.name !== 'separator' && config.includes(action.name)"
|
|
60
|
-
v-tooltip="action.label"
|
|
61
|
-
:icon="action.icon"
|
|
62
|
-
thin
|
|
63
|
-
flat
|
|
64
|
-
:aria-label="action.name"
|
|
65
|
-
:class="[action.class, { active: selectedStyles?.has(action.name) }]"
|
|
66
|
-
class="radius-05"
|
|
67
|
-
@click="emit('action', action.name, action.label)"
|
|
68
|
-
/>
|
|
69
|
-
<span
|
|
70
|
-
v-else-if="action.name === 'separator'"
|
|
71
|
-
:key="`separator-${index}`"
|
|
72
|
-
class="opacity-2 mb-025"
|
|
73
|
-
>|</span>
|
|
74
|
-
</template>
|
|
75
|
-
</div>
|
|
76
|
-
</template>
|
|
77
|
-
|
|
78
|
-
<style scoped>
|
|
79
|
-
.toolbar :deep(.active) {
|
|
80
|
-
background: var(--primary-color);
|
|
81
|
-
color: white;
|
|
82
|
-
}
|
|
83
|
-
</style>
|
|
84
|
-
|
|
85
|
-
<style scoped>
|
|
86
|
-
|
|
87
|
-
</style>
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
let modal: any
|
|
2
|
-
|
|
3
|
-
export function applyFormatting(command: string, value: string = '') {
|
|
4
|
-
const selection = window.getSelection()
|
|
5
|
-
if (selection && selection.rangeCount > 0) {
|
|
6
|
-
const range = selection.getRangeAt(0)
|
|
7
|
-
const span = document.createElement('span')
|
|
8
|
-
|
|
9
|
-
switch (command) {
|
|
10
|
-
case 'formatBlock':
|
|
11
|
-
formatBlock(value)
|
|
12
|
-
break
|
|
13
|
-
case 'bold':
|
|
14
|
-
span.style.fontWeight = 'bold'
|
|
15
|
-
break
|
|
16
|
-
case 'italic':
|
|
17
|
-
span.style.fontStyle = 'italic'
|
|
18
|
-
break
|
|
19
|
-
case 'underline':
|
|
20
|
-
span.style.textDecoration = 'underline'
|
|
21
|
-
break
|
|
22
|
-
case 'strikeThrough':
|
|
23
|
-
span.style.textDecoration = 'line-through'
|
|
24
|
-
break
|
|
25
|
-
case 'fontSize':
|
|
26
|
-
span.style.fontSize = value
|
|
27
|
-
break
|
|
28
|
-
case 'foreColor':
|
|
29
|
-
span.style.color = value
|
|
30
|
-
break
|
|
31
|
-
case 'backColor':
|
|
32
|
-
span.style.backgroundColor = value
|
|
33
|
-
break
|
|
34
|
-
case 'justifyLeft':
|
|
35
|
-
span.style.textAlign = 'left'
|
|
36
|
-
break
|
|
37
|
-
case 'justifyCenter':
|
|
38
|
-
span.style.textAlign = 'center'
|
|
39
|
-
break
|
|
40
|
-
case 'justifyRight':
|
|
41
|
-
span.style.textAlign = 'right'
|
|
42
|
-
break
|
|
43
|
-
case 'justifyFull':
|
|
44
|
-
span.style.textAlign = 'justify'
|
|
45
|
-
break
|
|
46
|
-
case 'insertOrderedList':
|
|
47
|
-
insertList('ol')
|
|
48
|
-
return
|
|
49
|
-
case 'insertUnorderedList':
|
|
50
|
-
insertList('ul')
|
|
51
|
-
return
|
|
52
|
-
case 'indent':
|
|
53
|
-
span.style.marginLeft = '40px'
|
|
54
|
-
break
|
|
55
|
-
case 'outdent':
|
|
56
|
-
span.style.marginLeft = '-40px'
|
|
57
|
-
break
|
|
58
|
-
case 'removeFormatting':
|
|
59
|
-
removeFormatting()
|
|
60
|
-
break
|
|
61
|
-
case 'insertHorizontalRule':
|
|
62
|
-
insertHorizontalRule()
|
|
63
|
-
break
|
|
64
|
-
case 'subscript':
|
|
65
|
-
span.style.verticalAlign = 'sub'
|
|
66
|
-
break
|
|
67
|
-
case 'superscript':
|
|
68
|
-
span.style.verticalAlign = 'super'
|
|
69
|
-
break
|
|
70
|
-
case 'fontName':
|
|
71
|
-
span.style.fontFamily = value
|
|
72
|
-
break
|
|
73
|
-
case 'increaseFontSize':
|
|
74
|
-
increaseFontSize()
|
|
75
|
-
break
|
|
76
|
-
case 'decreaseFontSize':
|
|
77
|
-
decreaseFontSize()
|
|
78
|
-
break
|
|
79
|
-
case 'link':
|
|
80
|
-
insertLink()
|
|
81
|
-
break
|
|
82
|
-
case 'image':
|
|
83
|
-
insertImage()
|
|
84
|
-
break
|
|
85
|
-
case 'createTable':
|
|
86
|
-
createTable()
|
|
87
|
-
break
|
|
88
|
-
default:
|
|
89
|
-
console.warn(`Command ${command} is not supported`)
|
|
90
|
-
return
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
range.surroundContents(span)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function formatBlock(value: string) {
|
|
98
|
-
if (!value) return
|
|
99
|
-
const selection = window.getSelection()
|
|
100
|
-
const range = selection?.getRangeAt(0)
|
|
101
|
-
if (!range) return
|
|
102
|
-
range.selectNodeContents(range.startContainer)
|
|
103
|
-
const el = document.createElement(value)
|
|
104
|
-
range.surroundContents(el)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function increaseFontSize() {
|
|
108
|
-
const selection = window.getSelection()
|
|
109
|
-
if (selection && selection.rangeCount > 0) {
|
|
110
|
-
const range = selection.getRangeAt(0)
|
|
111
|
-
const span = document.createElement('span')
|
|
112
|
-
const currentFontSize = Number.parseInt((range.startContainer.parentNode as HTMLElement).style.fontSize || '16', 10)
|
|
113
|
-
const newFontSize = currentFontSize + 2
|
|
114
|
-
span.style.fontSize = `${newFontSize}px`
|
|
115
|
-
range.surroundContents(span)
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function decreaseFontSize() {
|
|
120
|
-
const selection = window.getSelection()
|
|
121
|
-
if (selection && selection.rangeCount > 0) {
|
|
122
|
-
const range = selection.getRangeAt(0)
|
|
123
|
-
const span = document.createElement('span')
|
|
124
|
-
const currentFontSize = Number.parseInt((range.startContainer.parentNode as HTMLElement).style.fontSize || '16', 10)
|
|
125
|
-
const newFontSize = currentFontSize - 2
|
|
126
|
-
span.style.fontSize = `${newFontSize}px`
|
|
127
|
-
range.surroundContents(span)
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function removeFormatting() {
|
|
132
|
-
const selection = window.getSelection()
|
|
133
|
-
if (selection && selection.rangeCount > 0) {
|
|
134
|
-
const range = selection.getRangeAt(0)
|
|
135
|
-
const span = document.createElement('span')
|
|
136
|
-
span.textContent = range.toString()
|
|
137
|
-
range.deleteContents()
|
|
138
|
-
range.insertNode(span)
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function insertHorizontalRule() {
|
|
143
|
-
const selection = window.getSelection()
|
|
144
|
-
if (selection && selection.rangeCount > 0) {
|
|
145
|
-
const range = selection.getRangeAt(0)
|
|
146
|
-
const hr = document.createElement('hr')
|
|
147
|
-
range.deleteContents()
|
|
148
|
-
range.insertNode(hr)
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function insertList(type: string) {
|
|
153
|
-
const selection = window.getSelection()
|
|
154
|
-
if (selection && selection.rangeCount > 0) {
|
|
155
|
-
const range = selection.getRangeAt(0)
|
|
156
|
-
const list = document.createElement(type)
|
|
157
|
-
const listItem = document.createElement('li')
|
|
158
|
-
listItem.textContent = range.toString()
|
|
159
|
-
list.append(listItem)
|
|
160
|
-
range.deleteContents()
|
|
161
|
-
range.insertNode(list)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export function insertLink() {
|
|
166
|
-
const selection = window.getSelection()
|
|
167
|
-
if (!selection || selection.rangeCount < 1) return
|
|
168
|
-
const range = selection.getRangeAt(0)
|
|
169
|
-
modal.showModalForm({ title: 'Insert Link', schema: [
|
|
170
|
-
{ id: 'url', $el: 'text', label: 'URL' },
|
|
171
|
-
{ id: 'openInNewTab', $el: 'check', label: 'Open in new tab' },
|
|
172
|
-
], onSubmit: (data: any) => {
|
|
173
|
-
const { url, openInNewTab } = data
|
|
174
|
-
if (url) {
|
|
175
|
-
const anchor = document.createElement('a')
|
|
176
|
-
anchor.href = url
|
|
177
|
-
range.surroundContents(anchor)
|
|
178
|
-
if (openInNewTab) anchor.target = '_blank'
|
|
179
|
-
}
|
|
180
|
-
} })
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export function insertImage() {
|
|
184
|
-
const selection = window.getSelection()
|
|
185
|
-
if (!selection || selection.rangeCount < 1) return
|
|
186
|
-
const range = selection.getRangeAt(0)
|
|
187
|
-
modal.showModalForm({ title: 'Upload Image', schema: [
|
|
188
|
-
{ id: 'src', $el: 'file', attrs: { bindkey: 'url' } },
|
|
189
|
-
{ id: 'alt', $el: 'text', label: 'Alt Text' },
|
|
190
|
-
], onSubmit: (_data: any) => {
|
|
191
|
-
const { src } = _data
|
|
192
|
-
if (src) {
|
|
193
|
-
const img = document.createElement('img')
|
|
194
|
-
img.src = src
|
|
195
|
-
img.alt = _data.alt
|
|
196
|
-
range.deleteContents()
|
|
197
|
-
range.insertNode(img)
|
|
198
|
-
}
|
|
199
|
-
} })
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export function createTable() {
|
|
203
|
-
const rows = prompt('Enter the number of rows:')
|
|
204
|
-
const cols = prompt('Enter the number of columns:')
|
|
205
|
-
if (rows && cols) {
|
|
206
|
-
const table = document.createElement('table')
|
|
207
|
-
table.style.border = '1px solid black'
|
|
208
|
-
table.style.borderCollapse = 'collapse'
|
|
209
|
-
|
|
210
|
-
for (let i = 0; i < Number.parseInt(rows); i++) {
|
|
211
|
-
const row = table.insertRow()
|
|
212
|
-
for (let j = 0; j < Number.parseInt(cols); j++) {
|
|
213
|
-
const cell = row.insertCell()
|
|
214
|
-
cell.style.border = '1px solid black'
|
|
215
|
-
cell.style.padding = '5px'
|
|
216
|
-
cell.textContent = `Cell ${i + 1},${j + 1}`
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const selection = window.getSelection()
|
|
221
|
-
if (selection && selection.rangeCount > 0) {
|
|
222
|
-
const range = selection.getRangeAt(0)
|
|
223
|
-
range.deleteContents()
|
|
224
|
-
range.insertNode(table)
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function clearFormatting() {
|
|
230
|
-
const selection = window.getSelection()
|
|
231
|
-
const range = selection?.getRangeAt(0)
|
|
232
|
-
if (!range) return
|
|
233
|
-
range.selectNodeContents(range.startContainer)
|
|
234
|
-
const contents = range.extractContents()
|
|
235
|
-
const text = contents.textContent
|
|
236
|
-
if (text !== null && text !== '') {
|
|
237
|
-
range.deleteContents()
|
|
238
|
-
const textNode = document.createTextNode(`${text}`)
|
|
239
|
-
setTimeout(() => { range.insertNode(textNode) }, 1)
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export function useFormatting(modalInstance?: any) {
|
|
244
|
-
modal = modalInstance
|
|
245
|
-
return { applyFormatting, clearFormatting }
|
|
246
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export type ToolbarConfigOption = 'bold'
|
|
2
|
-
| 'italic'
|
|
3
|
-
| 'underline'
|
|
4
|
-
| 'strikethrough'
|
|
5
|
-
| 'fontSize'
|
|
6
|
-
| 'fontFamily'
|
|
7
|
-
| 'textColor'
|
|
8
|
-
| 'backgroundColor'
|
|
9
|
-
| 'alignLeft'
|
|
10
|
-
| 'alignCenter'
|
|
11
|
-
| 'alignRight'
|
|
12
|
-
| 'alignJustify'
|
|
13
|
-
| 'orderedList'
|
|
14
|
-
| 'unorderedList'
|
|
15
|
-
| 'indent'
|
|
16
|
-
| 'outdent'
|
|
17
|
-
| 'link'
|
|
18
|
-
| 'image'
|
|
19
|
-
| 'table'
|
|
20
|
-
| 'blockquote'
|
|
21
|
-
| 'codeBlock'
|
|
22
|
-
| 'splitView'
|
|
23
|
-
| 'codeView'
|
|
24
|
-
| 'youtube'
|
|
25
|
-
| 'clear'
|
|
26
|
-
| 'fullScreen'
|
|
27
|
-
| 'formatBlock'
|
|
28
|
-
|
|
29
|
-
export type ToolbarConfig = ToolbarConfigOption[]
|