Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(fluent-editor): add formula demo #2516

Merged
merged 1 commit into from
Nov 12, 2024
Merged

Conversation

kagol
Copy link
Member

@kagol kagol commented Nov 12, 2024

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Introduced new Vue components for editing mathematical content using a Tiny Fluent Editor.
    • Added a demo for editable formulas, enhancing user interaction with mathematical expressions.
  • Bug Fixes

    • Updated dependencies to ensure compatibility and improved functionality.
  • Documentation

    • Added descriptions for new demo entries, including translations for better accessibility.

@kagol kagol added the documentation Improvements or additions to documentation label Nov 12, 2024
Copy link

coderabbitai bot commented Nov 12, 2024

Walkthrough

This pull request introduces two new Vue components, options-formula-composition-api.vue and options-formula.vue, which integrate a Tiny Fluent Editor with support for mathematical content. The components utilize the Composition API and include functionality for editing mathematical expressions. Additionally, a new demo entry is added to fluent-editor.js to showcase the formula editing feature, and the package.json files are updated to include the mathlive library as a dependency and to update the version of the @opentiny/fluent-editor package.

Changes

File Path Change Summary
examples/sites/demos/pc/app/fluent-editor/options-formula-composition-api.vue New Vue component integrating Tiny Fluent Editor with math capabilities using Composition API.
examples/sites/demos/pc/app/fluent-editor/options-formula.vue New Vue component for editing mathematical content with Tiny Fluent Editor and two-way binding.
examples/sites/demos/pc/app/fluent-editor/webdoc/fluent-editor.js Added demo entry for editable formulas, referencing the new options-formula.vue file.
examples/sites/package.json Added mathlive dependency with version ^0.101.1.
packages/vue/src/fluent-editor/package.json Updated @opentiny/fluent-editor dependency version from ~3.20.0 to ~3.22.0.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • zzcr

🐇 In a world of math and flair,
A Tiny Editor's magic we share.
With formulas bright, we hop and play,
Editing joyfully, day by day.
So grab your numbers, don’t delay,
In our fluent garden, let’s create and sway! 🌼✏️


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Nov 12, 2024
Copy link

[e2e-test-warn]
The component to be tested is missing.

The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".

Please make sure you've read our contributing guide

@kagol kagol added the documentation Improvements or additions to documentation label Nov 12, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Nov 12, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (8)
packages/vue/src/fluent-editor/package.json (1)

MathLive dependency should be added to @opentiny/vue-fluent-editor

The verification shows that:

  • MathLive is actively used in the fluent-editor component for formula editing functionality
  • It's currently only listed as a dependency in the examples/sites/package.json
  • The @opentiny/fluent-editor package (3.22.0) doesn't include mathlive in its dependencies

The formula editing feature requires mathlive to work correctly, as evidenced by:

  • Direct imports of 'mathlive' and its CSS files in the formula editor component
  • Usage of mathlive module configuration in the editor options
  • Integration with mathlive for formula rendering and editing
🔗 Analysis chain

Line range hint 13-20: Query: MathLive dependency appears to be missing

The AI summary mentions MathLive library integration, but it's not listed as a dependency. Should mathlive be added as a dependency for the formula editing feature to work correctly?


Let me gather more information about the formula editing feature and its dependencies.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if mathlive is a dependency of @opentiny/fluent-editor
# or if it needs to be explicitly added

# Check if mathlive is already included in fluent-editor's dependencies
curl -s https://registry.npmjs.org/@opentiny/fluent-editor/3.22.0 | jq '.dependencies'

# Search for mathlive usage in the codebase
rg -l 'mathlive'

Length of output: 549


Script:

#!/bin/bash
# Check the content of formula-related files to understand the implementation
rg -A 5 "mathlive" examples/sites/demos/pc/app/fluent-editor/options-formula.vue
rg -A 5 "mathlive" examples/sites/demos/pc/app/fluent-editor/webdoc/fluent-editor.js

# Check if mathlive is listed in any package.json files
rg -l "mathlive" "**/package.json"

# Check the content of the example package.json that contains mathlive
cat examples/sites/package.json | jq '.dependencies'

Length of output: 2014

examples/sites/demos/pc/app/fluent-editor/options-formula-composition-api.vue (2)

1-7: Consider internationalizing the text and improving content display

  1. The hardcoded Chinese text "内容:" should be internationalized for better maintainability and accessibility.
  2. Consider formatting the displayed content for better readability in the demo.
 <template>
   <div>
     <tiny-fluent-editor v-model="content" :options="options" ref="editorRef"></tiny-fluent-editor>
-    内容:<br />
-    {{ content }}
+    {{ t('content') }}:<br />
+    <pre>{{ JSON.stringify(JSON.parse(content), null, 2) }}</pre>
   </div>
 </template>

18-29: Improve code organization and translate comments

  1. Move the initial content to a named constant for better maintainability.
  2. Translate Chinese comments to English.
+const INITIAL_FORMULA = {
+  ops: [
+    {
+      insert: {
+        mathlive: {
+          value: '\\sum_{i=1}^{n} i^2',
+          mode: 'dialog'
+        }
+      }
+    },
+    { insert: '\n' }
+  ]
+}

 const editorRef = ref()
-const content = ref('{"ops":[{"insert":{"mathlive":{"value":"\\sum_{i=1}^{n} i^2","mode":"dialog"}}},{"insert":"\n"}]}')
+const content = ref(JSON.stringify(INITIAL_FORMULA))

 const options = ref({
   modules: {
-    // 工具栏
+    // Toolbar configuration
     toolbar: ['formula'],
-    // 可编辑公式
+    // Enable formula editing
     mathlive: true
   }
 })
examples/sites/demos/pc/app/fluent-editor/options-formula.vue (3)

1-7: Consider implementing internationalization for the text labels.

The hardcoded Chinese text "内容:" should be internationalized to support multiple languages and maintain consistency with the project's documentation standards.

-    内容:<br />
+    {{ t('content') }}<br />

12-13: Translate Chinese comments to English for consistency.

Keep documentation and comments in English to maintain consistency across the codebase.

-// 引入 mathlive 模块和样式
+// Import mathlive module and styles

34-38: Consider using created() hook and component props for initialization.

Direct manipulation of the quill instance in mounted() could be fragile. Consider:

  1. Moving the initialization to created() hook
  2. Using component props for initial content
  3. Adding error handling for the quill instance access
 export default {
+  props: {
+    initialFormula: {
+      type: Object,
+      default: () => INITIAL_FORMULA
+    }
+  },
   mounted() {
-    this.$refs.editorRef.state.quill.setContents({
-      'ops': [{ 'insert': { 'mathlive': { 'value': '\\sum_{i=1}^{n} i^2', 'mode': 'dialog' } } }, { 'insert': '\n' }]
-    })
+    try {
+      this.$refs.editorRef?.state.quill?.setContents(this.initialFormula)
+    } catch (error) {
+      console.error('Failed to initialize editor content:', error)
+    }
   }
 }
examples/sites/demos/pc/app/fluent-editor/webdoc/fluent-editor.js (1)

54-65: Consider adding English description for consistency.

The demo entry is well-structured and provides clear documentation in Chinese. However, for consistency with other demos like 'basic-usage' that have English descriptions, consider adding an English description.

 desc: {
   'zh-CN': '通过设置 <code>options</code> 中的 <code>mathlive</code> 为 true 开启可编辑公式功能。',
-  'en-US': ''
+  'en-US': 'Enable editable formula functionality by setting <code>mathlive</code> to true in the <code>options</code> configuration.'
 },
examples/sites/package.json (1)

44-44: Document the dependency purpose.

Consider adding a comment in package.json to document that mathlive is required for the fluent editor's formula editing feature. This helps future maintainers understand why this dependency exists.

   "@vueuse/head": "0.7.13",
   "github-markdown-css": "^5.1.0",
   "highlight.js": "^11.5.1",
   "marked": "^4.3.0",
-  "mathlive": "^0.101.1",
+  // Required for fluent editor's formula editing feature
+  "mathlive": "^0.101.1",
   "prismjs": "^1.28.0",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a3e30c3 and 2c8891a.

📒 Files selected for processing (5)
  • examples/sites/demos/pc/app/fluent-editor/options-formula-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/fluent-editor/options-formula.vue (1 hunks)
  • examples/sites/demos/pc/app/fluent-editor/webdoc/fluent-editor.js (1 hunks)
  • examples/sites/package.json (1 hunks)
  • packages/vue/src/fluent-editor/package.json (1 hunks)
🔇 Additional comments (6)
examples/sites/demos/pc/app/fluent-editor/options-formula-composition-api.vue (2)

1-36: Verify formula feature demonstration completeness

As this is a demo component, we should ensure it adequately demonstrates the key features of the formula editing capability:

  1. Formula insertion
  2. Formula editing
  3. Different formula modes (if available)
  4. Error handling
#!/bin/bash
# Description: Check for comprehensive formula feature documentation

# Check if there are other formula-related demos or documentation
rg -g '*.{vue,md}' -l 'mathlive|formula' examples/sites/demos/pc/app/fluent-editor/

# Check for formula-related tests
rg -g '*test*.{js,ts,vue}' -l 'mathlive|formula'

9-17: Translate comments and verify mathlive compatibility

  1. The Chinese comment should be in English for consistency.
  2. We should verify the mathlive version compatibility with the project.
examples/sites/demos/pc/app/fluent-editor/options-formula.vue (2)

13-15: Verify mathlive dependency declaration.

The component imports mathlive and its CSS files, but we should ensure these dependencies are properly declared in package.json.

✅ Verification successful

Dependency mathlive is properly declared in package.json

The verification confirms that mathlive is correctly declared in examples/sites/package.json with version constraint ^0.101.1, which aligns with the imports used in the component.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if mathlive is declared in package.json
rg -l "mathlive" | grep -i "package.json"

# Check the version constraints
rg '"mathlive":\s*"[^"]*"' -g 'package.json'

Length of output: 168


21-33: 🛠️ Refactor suggestion

Extract duplicated formula content into a constant.

The formula content is duplicated between data() and mounted(). Consider extracting it into a constant to maintain DRY principles and improve maintainability.

+const INITIAL_FORMULA = {
+  ops: [
+    {
+      insert: {
+        mathlive: {
+          value: '\\sum_{i=1}^{n} i^2',
+          mode: 'dialog'
+        }
+      }
+    },
+    { insert: '\n' }
+  ]
+}

 export default {
   data() {
     return {
-      content: '{"ops":[{"insert":{"mathlive":{"value":"\\sum_{i=1}^{n} i^2","mode":"dialog"}}},{"insert":"\n"}]}',
+      content: JSON.stringify(INITIAL_FORMULA),
       options: {
         // ...
       }
     }
   }
 }

Likely invalid or redundant comment.

examples/sites/demos/pc/app/fluent-editor/webdoc/fluent-editor.js (1)

64-64: Verify the referenced Vue file exists.

The demo references 'options-formula.vue'. Let's verify this file exists in the correct location.

✅ Verification successful

File exists and contains the required component

The verification confirms that:

  • The file options-formula.vue exists at the correct location: examples/sites/demos/pc/app/fluent-editor/options-formula.vue
  • The file contains the TinyFluentEditor component as expected
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the referenced Vue file exists in the demos directory
# Expected: File should exist in the same directory as other demo files

# Find the demo file
fd --type f "options-formula.vue" examples/sites/demos/pc/app/fluent-editor

# If found, verify it contains TinyFluentEditor component
if fd --quiet "options-formula.vue" examples/sites/demos/pc/app/fluent-editor; then
  rg -l "TinyFluentEditor" $(fd --type f "options-formula.vue" examples/sites/demos/pc/app/fluent-editor)
fi

Length of output: 438

examples/sites/package.json (1)

44-44: Verify mathlive version and security.

The addition of mathlive is appropriate for the formula editing feature. However, let's verify the version choice.

✅ Verification successful

✓ The mathlive version is up-to-date and secure

The version 0.101.1 specified in package.json is currently the latest version available on npm, and no security vulnerabilities were found for this package.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check latest version and security advisories for mathlive

# Get latest version from npm
echo "Latest version from npm:"
curl -s https://registry.npmjs.org/mathlive/latest | jq '.version'

# Check for known vulnerabilities
echo "Checking for vulnerabilities:"
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: NPM, package: "mathlive") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

Length of output: 546

@@ -11,7 +11,7 @@
"//postversion": "pnpm build"
},
"dependencies": {
"@opentiny/fluent-editor": "~3.20.0",
"@opentiny/fluent-editor": "~3.22.0",
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Version bump is compatible but MathLive dependency is missing

The version bump to ~3.22.0 is compatible, but there's an implementation concern:

  • The formula feature requires MathLive (v0.101.1) as shown in the demo files, but it's not declared as a dependency in the component's package.json
  • The feature is actively used in the demo files with imports from 'mathlive'
  • This dependency should be explicitly declared in packages/vue/src/fluent-editor/package.json to ensure proper installation
🔗 Analysis chain

Verify compatibility with the new fluent-editor version

The version bump from ~3.20.0 to ~3.22.0 appears to be related to adding formula support. Let's verify this version contains the required features.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the changelog or release notes for version 3.22.0 to confirm formula support
# and verify no breaking changes were introduced

# Search for changelog files
fd -t f -e md -e txt -i "changelog|release|history" 

# Check package.json in fluent-editor dependency for peer dependencies
curl -s https://registry.npmjs.org/@opentiny/fluent-editor/3.22.0 | jq '.peerDependencies'

Length of output: 549


Script:

#!/bin/bash
# Let's check the actual usage of mathlive in the formula-related files
rg -A 5 "mathlive" examples/sites/demos/pc/app/fluent-editor/options-formula.vue
rg -A 5 "mathlive" examples/sites/demos/pc/app/fluent-editor/options-formula-composition-api.vue

# Check if there are any formula-related features in the fluent-editor component
rg -l "formula" packages/vue/src/fluent-editor/

# Check the package.json in examples to see how mathlive is declared
cat examples/sites/package.json | jq '.dependencies["mathlive"]'

Length of output: 1436

Comment on lines +31 to +35
onMounted(() => {
editorRef.value.state.quill.setContents({
'ops': [{ 'insert': { 'mathlive': { 'value': '\\sum_{i=1}^{n} i^2', 'mode': 'dialog' } } }, { 'insert': '\n' }]
})
})
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove redundant content initialization

The initial content is already set via v-model binding. The manual initialization in onMounted is redundant and could lead to race conditions.

-onMounted(() => {
-  editorRef.value.state.quill.setContents({
-    'ops': [{ 'insert': { 'mathlive': { 'value': '\\sum_{i=1}^{n} i^2', 'mode': 'dialog' } } }, { 'insert': '\n' }]
-  })
-})

Additionally, if you need to programmatically update the content, consider exposing a proper method through the TinyFluentEditor component instead of accessing the Quill instance directly.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onMounted(() => {
editorRef.value.state.quill.setContents({
'ops': [{ 'insert': { 'mathlive': { 'value': '\\sum_{i=1}^{n} i^2', 'mode': 'dialog' } } }, { 'insert': '\n' }]
})
})

@zzcr zzcr merged commit e2cebe2 into dev Nov 12, 2024
10 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants