-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from Joery-M/37-sharedsl-ui-settings
37 sharedsl UI settings
- Loading branch information
Showing
28 changed files
with
1,235 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/safelight/src/components/Menu/Settings/NamespaceSettings.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<template> | ||
<div v-if="currentSettings" ref="scrollContainer" class="h-full flex-1 overflow-y-auto"> | ||
<h1 class="mt-0"> | ||
{{ currentSettings.title }} | ||
</h1> | ||
<vue-markdown | ||
v-if="currentSettings.description" | ||
:source="currentSettings.description" | ||
:html="false" | ||
/> | ||
<div v-if="currentSettings.settings" role="list"> | ||
<SettingsGroup | ||
:settings="currentSettings.settings" | ||
:namespace="currentSettings.pathArray" | ||
:is-first="true" | ||
/> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { SettingsManager } from '@safelight/shared/Settings/SettingsManager'; | ||
import { computed, ref, watch } from 'vue'; | ||
import VueMarkdown from 'vue-markdown-render'; | ||
import SettingsGroup from './SettingsProperties/SettingsGroup.vue'; | ||
const props = withDefaults(defineProps<{ path: string }>(), { | ||
path: () => 'general' | ||
}); | ||
const scrollContainer = ref<HTMLDivElement>(); | ||
const currentSettings = computed(() => SettingsManager.getNamespace(props.path)); | ||
watch(currentSettings, () => { | ||
if (scrollContainer.value) { | ||
scrollContainer.value.scrollTo(0, 0); | ||
} | ||
}); | ||
</script> |
126 changes: 126 additions & 0 deletions
126
packages/safelight/src/components/Menu/Settings/Settings.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<template> | ||
<div class="flex h-full"> | ||
<div class="tree"> | ||
<Tree | ||
v-model:expandedKeys="expandedKeys" | ||
class="min-w-64" | ||
:selection-keys="{ [selectedPath]: true }" | ||
:value="tree" | ||
selection-mode="single" | ||
@node-select="onNodeSelect" | ||
> | ||
<template #nodeicon="{ node }"> | ||
<template v-if="node.data?.icon"> | ||
<component :is="node.data.icon" class="mr-2" /> | ||
</template> | ||
</template> | ||
</Tree> | ||
<Button severity="secondary" @click="SettingsManager.downloadSettings()"> | ||
<PhDownload /> | ||
Download JSON | ||
</Button> | ||
</div> | ||
<div | ||
class="mr-4 border-solid" | ||
style=" | ||
border-width: 0; | ||
border-right-width: 1px; | ||
border-right-color: var(--color-border); | ||
" | ||
/> | ||
<NamespaceSettings class="namespace" :path="selectedPath" /> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { PhDownload } from '@phosphor-icons/vue'; | ||
import { SettingsManager, SettingsNamespace } from '@safelight/shared/Settings/SettingsManager'; | ||
import Button from 'primevue/button'; | ||
import type { DynamicDialogInstance } from 'primevue/dynamicdialogoptions'; | ||
import Tree from 'primevue/tree'; | ||
import type { TreeNode } from 'primevue/treenode'; | ||
import { computed, inject, onMounted, ref, type Ref } from 'vue'; | ||
import NamespaceSettings from './NamespaceSettings.vue'; | ||
const selectedPath = ref<string>('general'); | ||
const expandedKeys = ref({}); | ||
const dialogRef = inject<Ref<DynamicDialogInstance>>('dialogRef'); | ||
onMounted(() => { | ||
if (dialogRef?.value?.data && dialogRef.value.data.namespace) { | ||
selectedPath.value = dialogRef.value.data.namespace; | ||
const namespaces = selectedPath.value.split('.'); | ||
expandedKeys.value = {}; | ||
namespaces.forEach((ns) => { | ||
expandedKeys.value = { ...expandedKeys.value, [ns]: true }; | ||
}); | ||
} | ||
}); | ||
const tree = computed(() => { | ||
return (Array.from(SettingsManager.settingsDefinition.values()) as SettingsNamespace[]).map( | ||
(ns) => mapSettingsNs(ns) | ||
); | ||
}); | ||
function onNodeSelect(data: TreeNode) { | ||
if (data.key) { | ||
if ((SettingsManager.getNamespace(data.key)?.settings?.length ?? 0) > 0) { | ||
selectedPath.value = data.key; | ||
} | ||
if (data.children && data.children.length > 0) { | ||
expandedKeys.value = { [data.key]: true }; | ||
} | ||
} | ||
} | ||
function mapSettingsNs(ns: SettingsNamespace): TreeNode { | ||
return { | ||
key: ns.path, | ||
label: ns.title, | ||
selectable: ns.settings?.length > 0 || ns.childNamespaces?.length > 0, | ||
children: ns.childNamespaces?.map(mapSettingsNs), | ||
data: { | ||
icon: ns.icon | ||
} | ||
} as TreeNode; | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.tree { | ||
@apply mr-4 flex flex-col; | ||
> .p-tree { | ||
@apply flex-1 overflow-y-auto; | ||
} | ||
> .p-button { | ||
@apply flex w-full justify-center gap-2; | ||
} | ||
} | ||
.namespace :deep(div[role='listitem']) { | ||
@apply mb-4 pl-4; | ||
h3 { | ||
@apply -ml-2 mb-3 mt-0; | ||
} | ||
p { | ||
@apply m-0; | ||
} | ||
.description { | ||
line-height: normal; | ||
} | ||
a.default { | ||
@apply invisible cursor-pointer align-middle text-sm font-extralight italic opacity-0 transition-all; | ||
&.show { | ||
@apply visible opacity-100; | ||
} | ||
> svg { | ||
@apply align-middle; | ||
} | ||
} | ||
} | ||
</style> |
11 changes: 11 additions & 0 deletions
11
packages/safelight/src/components/Menu/Settings/SettingsProperties/ArraySetting.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<template> | ||
<h3 v-if="setting?.title">{{ setting.title }}</h3> | ||
<vue-markdown v-if="setting?.description" :source="setting.description" /> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import type { SettingsArrayProperty } from '@safelight/shared/Settings/SettingsManager'; | ||
import VueMarkdown from 'vue-markdown-render'; | ||
defineProps<{ namespace: string[]; setting: SettingsArrayProperty }>(); | ||
</script> |
Oops, something went wrong.