Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ui/src/components/codemirror-editor/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:style="codemirrorStyle"
:tab-size="4"
:autofocus="true"
v-bind="$attrs"
v-bind="editorAttrs"
/>

<div class="codemirror-editor__footer">
Expand Down Expand Up @@ -39,14 +39,15 @@
</template>

<script setup lang="ts">
import { ref, computed, watch } from 'vue'
import { ref, computed, watch, useAttrs } from 'vue'
import { Codemirror } from 'vue-codemirror'
import { python } from '@codemirror/lang-python'
import { oneDark } from '@codemirror/theme-one-dark'
import { linter, type Diagnostic } from '@codemirror/lint'
import FunctionApi from '@/api/function-lib'

defineOptions({ name: 'CodemirrorEditor' })
const editorAttrs = useAttrs() as any
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useAttrs() is cast to any, which drops type checking for forwarded attrs. Prefer keeping the inferred type (or casting to Record<string, unknown>/a more specific type) rather than as any so vue-tsc can catch invalid bindings.

Suggested change
const editorAttrs = useAttrs() as any
const editorAttrs = useAttrs()

Copilot uses AI. Check for mistakes.

const props = defineProps<{
title: String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no apparent issue with the given Vue code snippet. It appears to be setting up a CodeMirror component on a Vue template, using various plugins such as Python language support, One Dark theme, linting tools, and an API call function for functions. The code bindings are correctly defined within the template and script sections.

Here's a concise overview of what this code snippet does:

  1. Imports ref, computed, watch, and useAttrs from Vue,
  2. Import Codemirror and its Python syntax (lang-python) and one-dark theme.
    3 Defines a setup for the Codemirror editor which uses these components,
  3. Sets some basic props like title,
  4. Uses v-bind="$attrs" and assigns it to a new variable editorAttrs.

If you have additional requirements or need further optimizations, let me know!

Expand Down
6 changes: 4 additions & 2 deletions ui/src/components/dynamics-form/items/JsonInput.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div style="width: 100%" class="function-CodemirrorEditor">
<Codemirror
v-bind="$attrs"
v-bind="editorAttrs"
ref="cmRef"
v-model="model_value"
:extensions="extensions"
Expand Down Expand Up @@ -51,7 +51,7 @@ import { json, jsonParseLinter } from '@codemirror/lang-json'
import { oneDark } from '@codemirror/theme-one-dark'
import { Codemirror } from 'vue-codemirror'
import { linter } from '@codemirror/lint'
import { computed, ref } from 'vue'
import { computed, ref, useAttrs } from 'vue'
import { t } from '@/locales'
const props = withDefaults(defineProps<{ modelValue?: any }>(), { modelValue: () => {} })
const emit = defineEmits(['update:modelValue'])
Expand Down Expand Up @@ -124,6 +124,8 @@ const validate_rules = (rule: any, value: any, callback: any) => {
return true
}

const editorAttrs = useAttrs() as any
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting useAttrs() to any removes type-safety for forwarded attributes and may mask invalid props/listeners being passed through. Prefer keeping the inferred Readonly<Record<string, unknown>> (or casting to a safer record type) instead of as any.

Suggested change
const editorAttrs = useAttrs() as any
const editorAttrs = useAttrs()

Copilot uses AI. Check for mistakes.

defineExpose({ validate_rules: validate_rules })
</script>
<style lang="scss">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code seems to be for a Vue component with a CodeMirror editor using the 'vue-codemirror' library. Here are some minor adjustments and suggestions:

  1. Attribute Binding: The v-bind="$attrs" has been replaced with v-bind="editor_attrs". This is fine, but it might be useful to include @keydown.enter.prevent if you want to handle Enter key press events separately.

  2. Component Name Spaces: Ensure that all components like linter, oneDark, $attrs, etc., are properly namespace qualified (e.g., @codemirror/lint) as these could depend on environment-specific module resolution.

  3. Use of Composition API: Instead of importing individual functions (computed, ref) directly from 'vue', consider using useComputed, useRef functions when necessary. However, all dependencies are imported at the top which is good practice.

Overall, the structure and functionality appear correct for managing a CodeMirror instance within Vue.js.

Expand Down
5 changes: 3 additions & 2 deletions ui/src/components/markdown/MdEditor.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<template>
<MdEditor :language="language" noIconfont noPrettier v-bind="$attrs">
<MdEditor :language="language" noIconfont noPrettier v-bind="editorAttrs">
<template #defFooters>
<slot name="defFooters"> </slot>
</template>
</MdEditor>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { computed, useAttrs } from 'vue'
import { MdEditor, config } from 'md-editor-v3'
import { getBrowserLang } from '@/locales/index'
import './assets/markdown-iconfont.js'
// 引入公共库中的语言配置
import ZH_TW from '@vavt/cm-extension/dist/locale/zh-TW'

defineOptions({ name: 'MdEditor' })
const editorAttrs = useAttrs() as any
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useAttrs() is being cast to any, which removes type-safety for forwarded attributes. Prefer keeping the inferred Readonly<Record<string, unknown>> (or a more specific record type) instead of as any.

Suggested change
const editorAttrs = useAttrs() as any
const editorAttrs = useAttrs()

Copilot uses AI. Check for mistakes.
const language = computed(() => localStorage.getItem('MaxKB-locale') || getBrowserLang() || '')
config({
editorConfig: {
Expand Down
11 changes: 9 additions & 2 deletions ui/src/components/markdown/MdPreview.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<template>
<MdPreview :language="language" noIconfont noPrettier :codeFoldable="false" v-bind="$attrs" />
<MdPreview
:language="language"
noIconfont
noPrettier
:codeFoldable="false"
v-bind="previewAttrs"
/>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { computed, useAttrs } from 'vue'
import { MdPreview, config } from 'md-editor-v3'
import { getBrowserLang } from '@/locales/index'
import useStore from '@/stores'
// 引入公共库中的语言配置
import ZH_TW from '@vavt/cm-extension/dist/locale/zh-TW'

defineOptions({ name: 'MdPreview' })
const previewAttrs = useAttrs() as any
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useAttrs() already has a useful type (Readonly<Record<string, unknown>>), so casting to any unnecessarily drops type-safety and can hide mistakes when forwarding attrs. Prefer keeping the inferred type (or casting to a narrower record type if needed) instead of as any.

Suggested change
const previewAttrs = useAttrs() as any
const previewAttrs = useAttrs()

Copilot uses AI. Check for mistakes.
const { user } = useStore()
const language = computed(() => user.getLanguage() || getBrowserLang() || '')
config({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code is mostly correct and well-documented. However, there are a few suggestions for improvement:

  1. Attribute Binding: Instead of binding v-bind="$attrs" directly to a component that doesn't have built-in support (<MdPreview>), it might be beneficial to apply these attributes manually if needed.

  2. Consistency with Attribute Syntax: The v-on: syntax should be used consistently. In this case, you can remove the unnecessary : before @.

  3. Variable Naming: Use descriptive variable names where appropriate to improve readability.

  4. Comments: Ensure comments are clear and concise. If additional documentation is required, consider updating it.

Here's an optimized version of the code considering these points:

<!-- Correcting attribute binding -->
<template>
  <MdPreview
    :language="computedLanguage"
    noIconfont
    noPrettier
    :codeFoldable="false"
    v-on="$attrs" <!-- Consistent attribute binding using @ instead of : -->
  />
</template>

<script setup lang="ts">
import { computed, useAttrs } from 'vue'
import { MdPreview, config } from 'md-editor-v3'
import { getBrowserLang } from '@/locales/index'
import useStore from '@/stores'

// Using useAttrs to access any extra props passed to the component
const previewAttrs = useAttrs() as Record<string, any>

// Importing Chinese Traditional Locale configuration for Vue Tiptap extension
import ZH_TW from '@vavt/cm-extension/dist/locale/zh-TW'

defineOptions({ name: 'MdPreview' })

// Setting up global editor configuration
config({
    locale: {
        ...ZH_TW,
        // Additional configuration settings if needed
    },
})

// Computed property to determine the active language or default to browser language
const computedLanguage = computed(() => [
    user.getLanguage(),
    browserLang(), // Assuming browserLang is defined somewhere else in your application
].find(lang => !!lang) || '')

/**
 * Fetches the current browser language based on navigator.locale.
 */
function browserLang(): string | null {
    return navigator.language.split('-')[0]; // Example function definition
}
</script>

Key Changes:

  • Used '@' prefix for event bindings to adhere to modern JavaScript practices.
  • Ensured consistent variable naming for better readability (computedLanguage, browserLang).
  • Provided a commented-out example showing how to fetch and set the browser language.
  • Removed unused imports and variables.

These changes make the code more readable and maintainable while leveraging existing Vue features effectively.

Expand Down