Skip to content

Commit eff4d8d

Browse files
committed
feat(app): finalize block-chart
1 parent e8dabd3 commit eff4d8d

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

packages/app/modules/block-editor/components/Block.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const icon = defineProp<string>('icon', {
6363
<template>
6464
<div
6565
ref="root"
66-
class="flex min-h-[48px] items-center group hover:bg-b-secondary/50"
66+
class="flex min-h-[48px] items-center group hover:bg-b-secondary/50 pr-10"
6767
:class="isSelectedInEditor ? 'bg-b-secondary/50' : ''"
6868
@click="onClick"
6969
>

packages/app/modules/block-editor/components/BlockChart.vue

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ANSICard from '@modules/evaluation/components/ANSICard.vue'
88
import ToolbarBtn from './ToolbarBtn.vue'
99
import Block from './Block.vue'
1010
import ToolbarAlignment from './ToolbarAlignment.vue'
11+
import { useCss } from '@composables/css'
1112
1213
const MonacoEditor = defineAsyncComponent(() => import('@modules/monaco/components/MEditor.vue'))
1314
@@ -64,7 +65,7 @@ async function setChart() {
6465
setTimeout(() => (chartLoading.value = false), 300)
6566
}
6667
67-
watch(() => model.value.body, setChart, { immediate: true })
68+
watch([() => model.value.body, () => model.value.attrs], setChart, { immediate: true, deep: true })
6869
6970
// edit
7071
@@ -76,15 +77,19 @@ const parser = new MarkdownParser()
7677
async function update() {
7778
const node = new MarkdownNodeComponent()
7879
79-
node.name = 'script'
80+
node.name = 'chart'
8081
node.body = code.value
8182
node.attrs = config.value
8283
83-
const attrsAsString = Object.entries(node.attrs)
84+
let attrsAsString = Object.entries(node.attrs)
8485
.map(([key, value]) => `${key}="${value}"`)
8586
.join(' ')
8687
87-
const markdown = `:: script ${attrsAsString}\n ${node.body}\n::\n`
88+
if (attrsAsString) {
89+
attrsAsString = ` { ${attrsAsString} }`
90+
}
91+
92+
const markdown = `:: chart${attrsAsString}\n\n${node.body}\n::\n`
8893
8994
node.tokens = parser.toTokens(markdown, {
9095
includeEndOfFileToken: false,
@@ -117,6 +122,7 @@ const mode = ref<'chart' | 'debug' | 'dataset'>('chart')
117122
118123
// attrs
119124
125+
const css = useCss()
120126
const loadingAttrs = ref(false)
121127
122128
const config = ref({
@@ -125,6 +131,15 @@ const config = ref({
125131
align: 'left',
126132
})
127133
134+
const style = computed(() => {
135+
return {
136+
height: css.toMeasurement(config.value.height),
137+
width: css.toMeasurement(config.value.width),
138+
marginLeft: ['right', 'center'].includes(config.value.align) ? 'auto' : undefined,
139+
marginRight: ['left', 'center'].includes(config.value.align) ? 'auto' : undefined,
140+
}
141+
})
142+
128143
watch(
129144
() => model.value.attrs,
130145
() => {
@@ -219,7 +234,7 @@ watch(
219234

220235
<div class="w-28 flex items-center">
221236
<v-input
222-
v-model.lazy.number="config.height"
237+
v-model.lazy="config.height"
223238
flat
224239
size="sm"
225240
data-test-id="toolbar-input-height"
@@ -231,7 +246,7 @@ watch(
231246
</div>
232247
<div class="w-28 flex items-center">
233248
<v-input
234-
v-model.lazy.number="config.width"
249+
v-model.lazy="config.width"
235250
flat
236251
size="sm"
237252
data-test-id="toolbar-input-width"
@@ -247,16 +262,16 @@ watch(
247262
<v-icon name="chart-pie" class="text-[10rem] text-t-secondary" />
248263
</div>
249264

250-
<v-chart v-else-if="mode === 'chart'" :options="chartOptions" />
265+
<v-chart v-else-if="mode === 'chart'" :style="style" :options="chartOptions" />
251266

252-
<ANSICard
253-
v-else-if="mode === 'debug'"
254-
:model-value="evaluationOutput"
255-
:empty-message="$t('noEntity', [$t('log', 2)])"
256-
data-test-id="debug-view"
257-
>
258-
<template #empty>
259-
<div class="h-full w-full flex items-center justify-center text-t-secondary">
267+
<template v-else-if="mode === 'debug'">
268+
<div :style="style" class="bg-b-03 p-4">
269+
<ANSICard :model-value="evaluationOutput" data-test-id="debug-view" />
270+
271+
<div
272+
v-if="!evaluationOutput.length"
273+
class="h-full w-full flex items-center justify-center text-t-secondary"
274+
>
260275
<div class="flex flex-col items-center space-y-2">
261276
<v-icon name="bug" class="text-4xl" />
262277

@@ -265,8 +280,8 @@ watch(
265280
</div>
266281
</div>
267282
</div>
268-
</template>
269-
</ANSICard>
283+
</div>
284+
</template>
270285

271286
<MonacoEditor
272287
v-else-if="mode === 'dataset'"

packages/app/modules/block-editor/components/Editor.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Block from './Block.vue'
88
import BlockParagraph from './BlockParagraph.vue'
99
import BlockHeading from './BlockHeading.vue'
1010
import BlockScript from './BlockScript.vue'
11+
import BlockChart from './BlockChart.vue'
1112
1213
const root = ref<HTMLElement | null>(null)
1314
const editor = useEditorOrCreate()
@@ -53,6 +54,12 @@ function onNodeUpdate(node: MarkdownNode) {
5354
@update:model-value="onNodeUpdate"
5455
/>
5556

57+
<BlockChart
58+
v-else-if="n.is('Component') && n.name === 'chart'"
59+
:model-value="n"
60+
@update:model-value="onNodeUpdate"
61+
/>
62+
5663
<Block
5764
v-else
5865
:model-value="n"

0 commit comments

Comments
 (0)