@data_wise/hyper-markdown 1.1.5 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -77,6 +77,39 @@ export default {
77
77
  | `defaultShowEditor` | Boolean | `true` | 编辑器初始显示状态(仅在 editable 为 true 时有效) |
78
78
  | `datasource` | Object | - | 数据源配置对象(可选) |
79
79
 
80
+ ### 组件事件
81
+
82
+ | 事件名 | 参数 | 说明 |
83
+ |--------|------|------|
84
+ | `update:content` | `(content: string)` | 内容更新时触发 |
85
+ | `errors` | `(errors: Array)` | 渲染错误时触发,返回错误数组 |
86
+
87
+ #### 错误对象格式
88
+
89
+ ```javascript
90
+ {
91
+ line: 10, // 错误所在行号
92
+ type: 'ECharts', // 错误类型:ECharts, Dataset, Mermaid, Container
93
+ message: '配置错误', // 错误描述
94
+ code: '```echarts...', // 相关代码片段
95
+ severity: 'error' // 错误级别
96
+ }
97
+ ```
98
+
99
+ #### 错误收集说明
100
+
101
+ 组件会自动收集以下类型的渲染错误:
102
+
103
+ - **ECharts 错误**:图表配置错误、数据格式错误等
104
+ - **Mermaid 错误**:流程图语法错误
105
+ - **Dataset 错误**:数据集格式错误、数据源查询失败等
106
+ - **Container 错误**:容器配置错误(如 cell 宽度超出范围)
107
+
108
+ 错误会在渲染完成后自动收集,并通过 `@errors` 事件传递给外部。你可以:
109
+
110
+ 1. **监听事件**:`@errors="handleErrors"` 实时获取错误
111
+ 2. **主动获取**:`this.$refs.editor.getErrors()` 获取当前错误列表
112
+
80
113
  ### 基础用法
81
114
 
82
115
  ```vue
@@ -85,6 +118,7 @@ export default {
85
118
  <MarkdownEditor
86
119
  :content="markdownContent"
87
120
  :editable="true"
121
+ @errors="handleErrors"
88
122
  />
89
123
  </div>
90
124
  </template>
@@ -101,6 +135,17 @@ export default {
101
135
  return {
102
136
  markdownContent: '# 欢迎使用 Hyper Markdown'
103
137
  }
138
+ },
139
+ methods: {
140
+ handleErrors(errors) {
141
+ // 处理渲染错误
142
+ if (errors.length > 0) {
143
+ console.log('发现渲染错误:', errors)
144
+ errors.forEach(error => {
145
+ console.error(`第 ${error.line} 行 [${error.type}]: ${error.message}`)
146
+ })
147
+ }
148
+ }
104
149
  }
105
150
  }
106
151
  </script>
@@ -316,6 +361,29 @@ graph TD
316
361
  ```
317
362
  ````
318
363
 
364
+ #### ⚠️ 使用 dataset + encode 时的注意事项
365
+
366
+ 使用 `dataset` + `encode` 时,formatter 必须用**函数形式**,字符串模板会显示 `[object Object]`:
367
+
368
+ ````markdown
369
+ ```echarts
370
+ {
371
+ dataset: dataset['sales_data'],
372
+ series: [{
373
+ type: "pie",
374
+ encode: { itemName: "产品", value: "销量" },
375
+ label: {
376
+ // ❌ 错误:formatter: "{b}: {c}次 ({d}%)"
377
+ // ✅ 正确:使用函数
378
+ formatter: function(params) {
379
+ return params.data['产品'] + ': ' + params.data['销量'] + '次 (' + params.percent + '%)';
380
+ }
381
+ }
382
+ }]
383
+ }
384
+ ```
385
+ ````
386
+
319
387
  ### 4. SQL 数据源查询
320
388
 
321
389
  支持从数据源查询数据,需要先注入 `datasource` 属性: