Skip to content

Commit

Permalink
feat: markdown editor for indicators description
Browse files Browse the repository at this point in the history
  • Loading branch information
Tucsky committed Oct 29, 2024
1 parent d4b4242 commit 5da0b43
Show file tree
Hide file tree
Showing 17 changed files with 456 additions and 109 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/assets/sass/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.editor {
height: 100%;
min-height: 50px;

.monaco-editor {
#app.-light & {
--vscode-editor-background: var(--theme-background-100);
--vscode-editorStickyScroll-background: var(--theme-background-100);
--vscode-editorStickyScrollHover-background: var(--theme-background-100);
--vscode-editorGutter-background: var(--theme-background-100);
}

.minimap-shadow-visible {
box-shadow: rgb(0 0 0 / 10%) -6px 0 6px -6px inset;
}

.scroll-decoration {
box-shadow: rgb(0 0 0 / 10%) 0 6px 6px -6px inset;
}

.view-overlays .current-line {
border-color: var(--theme-background-100);
}

.minimap {
left: auto !important;
right: 0 !important;
}
}
}
3 changes: 2 additions & 1 deletion src/components/chart/buildUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,8 @@ function parseReferences(
references.push({
indicatorId,
serieId,
plotIndex
plotIndex,
plotType: 'unknown'
})
}

Expand Down
1 change: 1 addition & 0 deletions src/components/chart/chart.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export interface IndicatorReference {
indicatorId: string
serieId?: string
plotIndex: number
plotType: string
}
export interface Renderer {
minLength: number
Expand Down
13 changes: 8 additions & 5 deletions src/components/chart/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1400,9 +1400,11 @@ export default class Chart {
this.incrementRendererBar(temporaryRenderer)

for (const id in computedSeries) {
computedSeries[id].push({
time: temporaryRenderer.localTimestamp
})
if (this.seriesIndicatorsMap[id].plotType !== 'broken-area') {
computedSeries[id].push({
time: temporaryRenderer.localTimestamp
})
}
}

barCount++
Expand Down Expand Up @@ -1475,7 +1477,7 @@ export default class Chart {
}
}

createIndicatorSeries(indicator) {
createIndicatorSeries(indicator: LoadedIndicator) {
if (!indicator.model) {
return
}
Expand All @@ -1501,7 +1503,8 @@ export default class Chart {

this.seriesIndicatorsMap[plot.id] = {
indicatorId: indicator.id,
plotIndex: i
plotIndex: i,
plotType: plot.type
}
series.push(plot.id)

Expand Down
12 changes: 9 additions & 3 deletions src/components/framework/Dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export default class Dialog extends Vue {
handleDrag(event) {
if (
this._handleTranslateRelease ||
this._handleTranslateRelease ||
event.button === 2 ||
event.target.classList.contains('-no-grab') ||
event.target.parentElement.classList.contains('-no-grab')
Expand Down Expand Up @@ -338,9 +338,15 @@ export default class Dialog extends Vue {
}
if (savePosition) {
this.savePosition(position)
if (
typeof position.w === 'number' &&
typeof position.h === 'number' &&
(position.w !== this.position?.w || position.h !== this.position?.h)
) {
this.$emit('resize')
}
this.$emit('resize')
this.savePosition(position)
}
if (this._persistTimeout) {
Expand Down
48 changes: 43 additions & 5 deletions src/components/framework/PromptDialog.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
<template>
<Dialog @clickOutside="close" size="small" :resizable="false">
<Dialog
@clickOutside="close"
size="small"
:resizable="tag === 'editor'"
@resize="resizeEditor"
>
<template v-slot:header>
<div class="dialog__title">{{ action }}</div>
</template>
<p class="mt0 mb8 -nl" v-if="question">{{ question }}</p>
<form ref="form" @submit.prevent="submit">
<div class="form-group">
<label v-if="label">{{ label }}</label>
<form
ref="form"
class="flex-grow-1 d-flex -column"
@submit.prevent="submit"
>
<div class="form-group flex-grow-1 d-flex -column">
<div class="d-flex mb8">
<label class="mr8 mt4 mb4">{{ label }}</label>

<label
v-if="tag === 'editor'"
class="checkbox-control -small mlauto mr0"
>
<input type="checkbox" class="form-control" v-model="showPreview" />
<div v-tippy title="Show preview"></div>
</label>
</div>
<input
v-if="tag === 'input'"
type="text"
Expand All @@ -16,6 +35,15 @@
v-autofocus
v-on:keyup.enter="submit"
/>
<MarkdownEditor
v-else-if="tag === 'editor'"
class="w-100 flex-grow-1"
ref="editor"
v-model="value"
:show-preview="showPreview"
minimal
autofocus
/>
<textarea
v-else
type="text"
Expand All @@ -42,6 +70,10 @@
import DialogMixin from '@/mixins/dialogMixin'
export default {
components: {
MarkdownEditor: () =>
import('@/components/framework/editor/MarkdownEditor.vue')
},
props: {
tag: {
type: String,
Expand Down Expand Up @@ -73,7 +105,8 @@ export default {
},
mixins: [DialogMixin],
data: () => ({
value: ''
value: '',
showPreview: false
}),
mounted() {
if (this.input && this.input.length) {
Expand All @@ -83,6 +116,11 @@ export default {
methods: {
submit() {
this.close(this.value)
},
resizeEditor() {
if (this.$refs.editor && this.$refs.editor.resize) {
this.$refs.editor.resize()
}
}
}
}
Expand Down
44 changes: 1 addition & 43 deletions src/components/framework/editor/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ export default class Editor extends Vue {
}
}
this.createTheme()
this.createEditor()
}
Expand Down Expand Up @@ -109,45 +107,6 @@ export default class Editor extends Vue {
window.addEventListener('beforeunload', this._beforeUnloadHandler)
}
createTheme() {
const lsLight = this.$store.state.settings.theme === 'light'
const style = getComputedStyle(document.documentElement)
const backgroundColor = splitColorCode(
style.getPropertyValue('--theme-background-base')
)
const backgroundColor100 = splitColorCode(
style.getPropertyValue('--theme-background-100')
)
const backgroundColor150 = splitColorCode(
style.getPropertyValue('--theme-background-150')
)
if (lsLight) {
monaco.defineTheme('my-light', {
base: 'vs',
inherit: true,
rules: [],
colors: {
'minimap.background': rgbToHex(backgroundColor150),
'editor.background': rgbToHex(backgroundColor100),
'editor.lineHighlightBackground': rgbToHex(backgroundColor),
'editor.lineHighlightBorder': rgbToHex(backgroundColor)
}
})
} else {
monaco.defineTheme('my-dark', {
base: 'vs-dark',
inherit: true,
rules: [],
colors: {
'editor.background': rgbToHex(backgroundColor100),
'editor.lineHighlightBackground': rgbToHex(backgroundColor),
'editor.lineHighlightBorder': rgbToHex(backgroundColor)
}
})
}
}
async createEditor() {
this.editorInstance = monaco.create(this.$el as HTMLElement, {
value: this.value,
Expand All @@ -162,8 +121,7 @@ export default class Editor extends Vue {
overviewRulerLanes: 0,
overviewRulerBorder: false,
contextmenu: false,
theme:
this.$store.state.settings.theme === 'light' ? 'my-light' : 'my-dark'
theme: 'aggr'
})
this.editorInstance.getDomNode().addEventListener('mousedown', () => {
Expand Down
Loading

0 comments on commit 5da0b43

Please sign in to comment.