Skip to content

Commit e610afe

Browse files
author
codewec
committed
feat: move raw switch to toolbar
1 parent daac69e commit e610afe

8 files changed

Lines changed: 62 additions & 25 deletions

File tree

app/components/editoro/MainContent.vue

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const props = defineProps<{
2525
}>()
2626
2727
const emit = defineEmits<{
28+
toggleMode: []
2829
updateEditorContent: [value: string]
2930
selectPath: [path: string]
3031
goParent: []
@@ -49,6 +50,18 @@ const {
4950
canUploadImage: () => props.canUploadImage,
5051
uploadImage: props.uploadImage
5152
})
53+
54+
const richEditorHandlers = computed(() => ({
55+
...editorHandlers,
56+
toggleRawMode: {
57+
canExecute: () => true,
58+
execute: () => {
59+
emit('toggleMode')
60+
return true
61+
},
62+
isActive: () => false
63+
}
64+
}))
5265
</script>
5366

5467
<template>
@@ -134,22 +147,40 @@ const {
134147
</div>
135148
</template>
136149

137-
<UTextarea
150+
<div
138151
v-if="props.editorViewMode === 'raw'"
139-
:model-value="props.editorContent"
140-
:rows="30"
141-
:autoresize="false"
142-
class="editoro-raw"
143-
:placeholder="t('main.rawPlaceholder')"
144-
@update:model-value="emit('updateEditorContent', String($event || ''))"
145-
/>
152+
class="editoro-raw-wrap"
153+
>
154+
<div class="editoro-raw-switch-wrap">
155+
<UButton
156+
size="xs"
157+
color="neutral"
158+
variant="soft"
159+
class="editoro-raw-switch"
160+
icon="i-lucide-square-pen"
161+
:aria-label="t('editorMode.toRich')"
162+
@click="emit('toggleMode')"
163+
>
164+
{{ t('editorMode.rich') }}
165+
</UButton>
166+
</div>
167+
168+
<UTextarea
169+
:model-value="props.editorContent"
170+
:rows="30"
171+
:autoresize="false"
172+
class="editoro-raw"
173+
:placeholder="t('main.rawPlaceholder')"
174+
@update:model-value="emit('updateEditorContent', String($event || ''))"
175+
/>
176+
</div>
146177

147178
<UEditor
148179
v-else
149180
:model-value="props.editorContent"
150181
class="editoro-editor"
151182
content-type="markdown"
152-
:handlers="editorHandlers"
183+
:handlers="richEditorHandlers"
153184
:placeholder="t('main.editorPlaceholder')"
154185
@update:model-value="emit('updateEditorContent', String($event || ''))"
155186
>
@@ -278,8 +309,23 @@ const {
278309
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
279310
}
280311
312+
.editoro-raw-wrap {
313+
position: relative;
314+
width: 100%;
315+
height: 100%;
316+
min-height: 0;
317+
}
318+
319+
.editoro-raw-switch-wrap {
320+
position: absolute;
321+
top: 0.75rem;
322+
right: 1rem;
323+
z-index: 10;
324+
}
325+
281326
.editoro-raw :deep(textarea) {
282327
height: 100%;
328+
padding-right: 6.25rem;
283329
}
284330
285331
.editoro-toolbar {

app/components/editoro/MainHeader.vue

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ const { t } = useI18n()
55
66
const props = defineProps<{
77
showExpandSidebarButton: boolean
8-
editorModeLabel: string
9-
editorModeIcon: string
10-
editorModeTooltip: string
118
headerBadges: EditorPinnedBadge[]
129
canRenameOrDelete: boolean
1310
isSaving: boolean
@@ -18,7 +15,6 @@ const props = defineProps<{
1815
1916
const emit = defineEmits<{
2017
expandSidebar: []
21-
toggleMode: []
2218
selectBadge: [path: string]
2319
togglePin: [path: string]
2420
rename: []
@@ -38,13 +34,6 @@ const emit = defineEmits<{
3834
@click="emit('expandSidebar')"
3935
/>
4036

41-
<EditoroHeaderModeToggle
42-
:label="props.editorModeLabel"
43-
:icon="props.editorModeIcon"
44-
:tooltip="props.editorModeTooltip"
45-
@toggle="emit('toggleMode')"
46-
/>
47-
4837
<EditoroHeaderPinnedBadges
4938
:badges="props.headerBadges"
5039
@select="(path) => emit('selectBadge', path)"

app/components/editoro/Workspace.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ const {
6363
v-bind="mainHeaderProps"
6464
:show-expand-sidebar-button="editoro.ui.isSidebarCollapsed.value"
6565
@expand-sidebar="mainHeaderHandlers.expandSidebar"
66-
@toggle-mode="mainHeaderHandlers.toggleMode"
6766
@select-badge="mainHeaderHandlers.selectBadge"
6867
@toggle-pin="mainHeaderHandlers.togglePin"
6968
@rename="mainHeaderHandlers.rename"
@@ -72,6 +71,7 @@ const {
7271

7372
<EditoroMainContent
7473
v-bind="mainContentProps"
74+
@toggle-mode="mainContentHandlers.toggleMode"
7575
@update-editor-content="mainContentHandlers.updateEditorContent"
7676
@select-path="mainContentHandlers.selectPath"
7777
@go-parent="mainContentHandlers.goParent"

app/composables/workspace/useEditoroMainContentBindings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export function useEditoroMainContentBindings(options: WorkspaceBindingOptions)
2727
}))
2828

2929
const mainContentHandlers = {
30+
toggleMode: state.editor.toggleMode,
3031
updateEditorContent: (value: string) => {
3132
state.editor.content.value = value
3233
},

app/composables/workspace/useEditoroMainHeaderBindings.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import type { EditoroState } from '~/composables/workspace/types'
88
export function useEditoroMainHeaderBindings(state: EditoroState) {
99
const mainHeaderProps = computed(() => ({
1010
showExpandSidebarButton: unref(state.ui.isSidebarCollapsed),
11-
editorModeLabel: state.editor.modeLabel.value,
12-
editorModeIcon: state.editor.modeIcon.value,
13-
editorModeTooltip: state.editor.modeTooltip.value,
1411
headerBadges: state.view.headerBadges.value,
1512
canRenameOrDelete: state.view.canRenameOrDelete.value,
1613
isSaving: state.editor.isSaving.value,
@@ -21,7 +18,6 @@ export function useEditoroMainHeaderBindings(state: EditoroState) {
2118

2219
const mainHeaderHandlers = {
2320
expandSidebar: state.ui.expandSidebar,
24-
toggleMode: state.editor.toggleMode,
2521
selectBadge: (path: string) => {
2622
if (!path) {
2723
return

app/constants/editoro.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export function createEditorToolbarItems(t: Translator) {
2525
{ kind: 'codeBlock', icon: 'i-lucide-square-code', tooltip: { text: t('toolbar.codeBlock') } },
2626
{ kind: 'horizontalRule', icon: 'i-lucide-minus', tooltip: { text: t('toolbar.divider') } }
2727
],
28+
[
29+
{ kind: 'toggleRawMode', icon: 'i-lucide-file-text', label: 'Raw', tooltip: { text: t('toolbar.raw') }, 'aria-label': t('toolbar.raw') }
30+
],
2831
[
2932
{ 'kind': 'uploadImage', 'icon': 'i-lucide-image-plus', 'tooltip': { text: t('toolbar.uploadImage') }, 'aria-label': t('toolbar.uploadImage') }
3033
]

i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"quote": "Quote",
8080
"codeBlock": "Code block",
8181
"divider": "Divider",
82+
"raw": "Open raw editor",
8283
"uploadImage": "Upload image"
8384
},
8485
"suggestion": {

i18n/locales/ru.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"quote": "Цитата",
8080
"codeBlock": "Блок кода",
8181
"divider": "Разделитель",
82+
"raw": "Открыть raw-редактор",
8283
"uploadImage": "Загрузить изображение"
8384
},
8485
"suggestion": {

0 commit comments

Comments
 (0)