Skip to content

Commit

Permalink
Merge branch 'bugfix/draggable-select-highlight' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
lancewilhelm committed Jun 4, 2024
2 parents dcccad8 + c14f0d9 commit 3f08f1f
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 31 deletions.
5 changes: 3 additions & 2 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ input::placeholder textarea::placeholder{
}

input:focus, textarea:focus {
outline: none;
box-shadow: 0 0 0 2px var(--main-color);
outline: 3px solid var(--main-color);
outline-offset: 3px;
}

button {
Expand Down Expand Up @@ -73,6 +73,7 @@ button:active {

button:focus {
outline: 3px solid var(--main-color);
outline-offset: 3px;
}

a {
Expand Down
1 change: 1 addition & 0 deletions components/codebook/codes/CodebookCodesPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ function handleDrop({ items, target }) {
:item="c"
:children="c.children ? c.children : []"
:depth="0"
:selected-style="() => 'border'"
@onDrop="handleDrop"
@selected="handleSelected"
@onContextMenu="openContextMenu"
Expand Down
24 changes: 19 additions & 5 deletions components/codebook/codes/CodebookCodesPanelItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ function getAllChildren(code) {
}
return children
}
function handleCodeTextColor() {
if (configStore.config.dynamic_code_text_color) {
if (props.code.group) {
return 'var(--text-color)'
}
return tinycolor.mostReadable(props.code.color, ['black', 'white'], {
includeFallbackColors: false,
})
} else {
if (configStore.config.code_text_color) {
return configStore.config.code_text_color
} else {
return 'var(--text-color)'
}
}
}
</script>

<template>
Expand All @@ -33,14 +50,11 @@ function getAllChildren(code) {
:class="['flex flex-row grow p-1.5']"
:style="{
'background-color': code.color,
color: configStore.config.dynamic_code_text_color ? tinycolor.mostReadable(code.color, ['black', 'white'], {
includeFallbackColors: false,
}) : configStore.config.code_text_color ? configStore.config.code_text_color : 'var(--text-color)',
color: handleCodeTextColor()
}"
>
<div class="mr-1.5">
<div v-if="code.group" class="mr-1.5">
<Icon
v-if="code.group"
name="fa6-solid:angle-right"
:style="{
transform: isOpen ? 'rotate(90deg)' : 'rotate(0deg)',
Expand Down
22 changes: 9 additions & 13 deletions components/draggable/DraggableContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ provide('dropTarget', dropTarget)
const isDragOver = computed(() => dropTarget.value === 'root')
watch(dropTarget, (value) => {
if (value !== null) {
}
})
useEventListener(window, 'drop', (e) => e.preventDefault())
useEventListener(window, 'dragover', (e) => e.preventDefault())
function onDropRoot(event) {
if (draggedItems.value.length > 0) {
emit('onDrop', { items: draggedItems.value, target: 'root' })
Expand All @@ -19,19 +27,6 @@ function onDropRoot(event) {
}
}
watch(dropTarget, (value) => {
if (value !== null) {
}
})
window.addEventListener('drop', (e) => e.preventDefault())
window.addEventListener('dragover', (e) => e.preventDefault())
onBeforeUnmount(() => {
window.removeEventListener('drop', (e) => e.preventDefault())
window.removeEventListener('dragover', (e) => e.preventDefault())
})
function handleContextMenu(event) {
emit('onContextMenu', { event, target: 'root' })
}
Expand Down Expand Up @@ -59,6 +54,7 @@ function onDragLeave(event) {
<slot></slot>
<div
:class="['grow', { 'bg-sub-alt': isDragOver }]"
@click="selectedItems = []"
@dragenter="onDragEnter"
@dragleave="onDragLeave"
/>
Expand Down
20 changes: 12 additions & 8 deletions components/draggable/DraggableItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ const props = defineProps({
type: Number,
default: 0,
},
selectedStyle: {
type: Function,
}
})
const selectedItems = inject('selectedItems')
const draggedItems = inject('draggedItems')
const dropTarget = inject('dropTarget')
const configStore = useConfigStore()
const isSelected = computed(() => selectedItems.value.includes(props.item))
const isDragOver = computed(() => dropTarget.value?.id === props.item.id && draggedItems.value?.length > 0)
const isOpen = ref(false)
Expand All @@ -34,10 +36,11 @@ function onSelect(event) {
selectedItems.value.push(props.item)
}
} else {
selectedItems.value = [props.item]
emit('selected', props.item)
if (props.item.children?.length > 0) {
isOpen.value = !isOpen.value
} else {
selectedItems.value = [props.item]
emit('selected', props.item)
}
}
}
Expand Down Expand Up @@ -112,7 +115,7 @@ function handleContextMenu(event) {
<template>
<div>
<div
:class="['cursor-pointer', { 'bg-main text-bg': isSelected, 'bg-sub-alt': isDragOver}]"
:class="['cursor-pointer', { 'bg-main': isSelected && selectedStyle(item) === 'bg', 'border-l-8 border-main': isSelected && selectedStyle(item) === 'border', 'bg-sub-alt': isDragOver}]"
@click="onSelect"
@dragstart="onDragStart"
@dragenter="onDragEnter"
Expand All @@ -131,11 +134,12 @@ function handleContextMenu(event) {
>
<span class="absolute z-10 top-0 bottom-0 w-px bg-text" />
<DraggableItem
v-for="child in children"
:key="child.id"
:item="child"
:children="child.children"
v-for="c in children"
:key="c.id"
:item="c"
:children="c.children"
:depth="depth + 1"
:selected-style="selectedStyle"
@onDrop="emit('onDrop', $event)"
@selected="emit('selected', $event)"
@onContextMenu="emit('onContextMenu', $event)"
Expand Down
1 change: 1 addition & 0 deletions components/file/FilePanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ function handleSelected(item) {
:item="file"
:children="file.children ? file.children : []"
:depth="0"
:selected-style="() => 'border'"
@onDrop="handleDrop"
@selected="handleSelected"
@onContextMenu="openContextMenu"
Expand Down
4 changes: 2 additions & 2 deletions components/file/FileViewerPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,10 @@ function handleCodeClick(event, segment) {
segment.codes.length > 2 ? 'italic' : 'normal',
'font-weight':
segment.codes.length > 3 ? 'bold' : 'normal',
'box-shadow':
'box-shadow': configStore.config.code_box_shadow ?
segment.codes.length !== 0
? '2px 3px 0px #000'
: 'none',
: 'none' : 'none',
}"
@click="
segment.codes.length > 0
Expand Down
10 changes: 9 additions & 1 deletion pages/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ definePageMeta({
middleware: 'auth',
})
import BaseColorPicker from '~/components/base/BaseColorPicker.vue';
import BaseColorPicker from '~/components/base/BaseColorPicker.vue'
import themesList from '/assets/themes.json'
const displayName = defineModel('displayName')
Expand Down Expand Up @@ -237,6 +237,14 @@ function setRandomTheme(random) {
<SettingsColorPicker configParameter="code_text_color" />
</SettingsGroupSection>

<SettingsGroupSection
title="code highlight box shadow"
icon="fa6-solid:square"
description="Enable box shadow on the code highlight in the file viewer"
>
<SettingsBooleanButtons configParameter="code_box_shadow" />
</SettingsGroupSection>

<!-- <div class="text-3xl font-black font-mono text-main">login</div>
<div class="settings-group">TBD</div> -->

Expand Down
3 changes: 3 additions & 0 deletions supabase/migrations/20240604012152_code_box_shadow.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
alter table "public"."configs" add column "code_box_shadow" boolean default true;


0 comments on commit 3f08f1f

Please sign in to comment.