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

feat: customized canvas entry #850

Merged
merged 12 commits into from
Oct 10, 2024

Conversation

yy-wow
Copy link
Collaborator

@yy-wow yy-wow commented Oct 10, 2024

English | 简体中文

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)
  • Built its own designer, fully self-validated

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:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

  1. 工具栏-保存增加beforeSave、saveMethod、saved钩子;
  2. 工具栏-预览增加beforePreview、previewMethod、afterPreview钩子;
  3. 画布iframe支持配置src替换默认的srcdoc,支持自定义的画布页面构建入口;
  4. 导出获取组件condition值的方法;
  5. 修复一些eslint报错问题

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced iframe rendering logic in the Canvas components to support conditional sources.
    • Introduced new props for better handling of canvas sources and visibility states in various components.
    • Added new methods for managing conditions and improved state management capabilities.
    • Added a new createRender function to facilitate rendering operations.
    • Expanded library entry points to include a new render entry.
  • Improvements

    • Asynchronous handling added to several functions, improving the flow of operations during save and preview actions.
    • Added pre-save and post-save hooks for greater flexibility in handling method execution.
    • Streamlined control flow for save operations, enhancing user experience during loading states.
    • Improved interactivity and maintainability of components through method restructuring.
  • Bug Fixes

    • Resolved issues related to method execution and state management within the components.
  • Configuration Changes

    • Updated project to use ECMAScript modules, enhancing module import and export syntax.
    • Added "type": "module" property in package.json for modern JavaScript standards.
    • Enhanced module export structure with new entries in package.json.

Copy link
Contributor

coderabbitai bot commented Oct 10, 2024

Walkthrough

The changes in this pull request introduce several enhancements across multiple files in the canvas package. Key updates include the addition of a new alias mapping for the @opentiny/tiny-engine-canvas/render module, new exports for the createRender function, and modifications to Vue components to improve canvas source management. Several new functions for condition management are added in the rendering context, and the package's package.json is updated to define export entries for better module resolution.

Changes

File Path Change Summary
.../vite-plugins/devAliasPlugin.js Added alias mapping for @opentiny/tiny-engine-canvas/render to resolve to packages/canvas/render/index.js.
.../index.js Added export for createRender function from ./render.
.../DesignCanvas.vue Renamed canvasUrl to canvasSrc, added canvasSrcDoc, and updated initialization logic for canvas properties.
.../CanvasContainer.vue Wrapped <iframe> in a conditional <template>, added canvasSrcDoc prop, and created srcAttrName computed property.
.../RenderMain.js Added getCondition, getConditions, and setCondition functions to the API object.
.../context.js Added getCondition and getConditions functions for condition management.
.../runner.js Changed argument passed to beforeAppCreate, updated event dispatching for canvasReady.
.../vite.config.js Added new entry point render in build.lib.entry configuration pointing to ./render/index.js.
.../canvas.js Updated export for createRender to come from @opentiny/tiny-engine-canvas/render.
.../package.json Added exports field to specify module exports for better compatibility.

Possibly related PRs

Suggested reviewers

  • hexqi

Poem

🐰 In the canvas where dreams take flight,
New sources emerge, oh what a sight!
With hooks and props, we dance and play,
Enhancing our tools, come join the fray!
From save to preview, all in sync,
A vibrant canvas, let’s pause and think! 🎨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4b9c0be and d97f14a.

📒 Files selected for processing (1)
  • packages/canvas/vite.config.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/canvas/vite.config.js

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 added enhancement New feature or request refactor-main refactor/develop branch feature labels Oct 10, 2024
Copy link
Contributor

@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: 8

🧹 Outside diff range and nitpick comments (13)
packages/canvas/render/src/context.js (1)

55-55: LGTM with a minor suggestion for robustness.

The getCondition function is a good addition that complements the existing setCondition function. It provides a way to retrieve the visibility state of a condition, which aligns well with the module's purpose.

Consider modifying the implementation to explicitly check for false to avoid potential issues with other falsy values:

-export const getCondition = (id) => conditions[id] !== false
+export const getCondition = (id) => conditions[id] !== false && conditions[id] !== undefined

This change ensures that only explicitly set false values or undefined conditions (which haven't been set) return false, providing more predictable behavior.

packages/canvas/render/src/runner.js (4)

52-52: LGTM! Consider adding a comment for clarity.

The changes to the create function look good. Passing the renderer object to beforeAppCreate instead of a Vue object with h property simplifies the API and provides a more consistent interface.

Consider adding a brief comment explaining the purpose of the renderer object for better code readability:

- await beforeAppCreate({ api: renderer })
+ // Pass renderer object containing API and app state to beforeAppCreate hook
+ await beforeAppCreate({ api: renderer })

Line range hint 72-72: Consider improving error handling

The current error handler suppresses all errors, which might hide important issues:

App.config.errorHandler = () => {}

Consider implementing a more robust error handling strategy. For example:

App.config.errorHandler = (err, instance, info) => {
  console.error('Vue Error:', err, instance, info)
  // Optionally, you can dispatch an event to notify the parent about the error
  dispatch('canvasError', { detail: { error: err, info } })
}

Line range hint 68-68: Consider alternatives to global properties

Setting lowcodeConfig as a global property might make it harder to track state changes:

App.config.globalProperties.lowcodeConfig = window.parent.TinyGlobalConfig

Consider using Vue's provide/inject API or a state management solution like Pinia for better maintainability.

Example using provide/inject:

// In your main component
import { provide } from 'vue'

provide('lowcodeConfig', window.parent.TinyGlobalConfig)

// In child components
import { inject } from 'vue'

const lowcodeConfig = inject('lowcodeConfig')

Line range hint 74-76: Potential memory leak in ResizeObserver

The ResizeObserver is created but never disconnected, which could lead to memory leaks if the component is frequently unmounted and remounted.

Consider storing the observer instance and disconnecting it when appropriate:

let resizeObserver

const create = async (config) => {
  // ... existing code ...

  resizeObserver = new ResizeObserver(() => {
    dispatch('canvasResize')
  })
  resizeObserver.observe(document.body)

  // Add a cleanup function
  const cleanup = () => {
    if (resizeObserver) {
      resizeObserver.disconnect()
      resizeObserver = null
    }
  }

  // Call cleanup when appropriate, e.g., when unmounting the app
  App.unmount = () => {
    cleanup()
    createApp(App).unmount()
  }

  // ... rest of the function ...
}
packages/canvas/DesignCanvas/src/DesignCanvas.vue (1)

58-64: LGTM: New canvas source handling logic implemented

The new logic for handling canvas sources is well-implemented. It allows for a custom canvas source (canvasSrc) or falls back to generating one (canvasSrcDoc), which aligns with the PR objectives. The use of getOptions(meta.id) provides component-specific configuration, and the fallback mechanism ensures backwards compatibility.

Consider adding a brief comment explaining the purpose of this logic for better code readability.

 const { canvasSrc = '' } = getOptions(meta.id) || {}
 let canvasSrcDoc = ''

+// Use custom canvas source if provided, otherwise generate one
 if (!canvasSrc) {
   const { importMap, importStyles } = getImportMapData(getMergeMeta('engine.config')?.importMapVersion)
   canvasSrcDoc = initCanvas(importMap, importStyles)
 }
packages/canvas/container/src/CanvasContainer.vue (2)

14-21: LGTM! Improved iframe rendering and source handling.

The changes enhance the flexibility of the iframe's source handling while maintaining the existing loading state display logic. The use of a computed property for determining the attribute name is a clean approach.

Consider adding an aria-label to the iframe for better accessibility:

 <iframe
   id="canvas"
   ref="iframe"
   :[srcAttrName]="canvasSrc || canvasSrcDoc"
   style="border: none; width: 100%; height: 100%"
+  aria-label="Canvas content"
 ></iframe>

67-67: LGTM! New prop added for alternative iframe source.

The addition of the canvasSrcDoc prop aligns well with the template changes, providing more flexibility in specifying the iframe's content.

Consider adding a brief comment to document the purpose of this prop:

 props: {
   controller: Object,
   canvasSrc: String,
+  // Alternative source for iframe content when canvasSrc is not provided
   canvasSrcDoc: String,
   materialsPanel: Object
 },
packages/canvas/render/src/RenderMain.js (2)

446-447: LGTM: New methods added to API object.

The getCondition and getConditions methods have been correctly added to the api object, expanding its functionality. This change aligns with the new imports and enhances the API surface for managing canvas conditions.

Consider adding JSDoc comments for these new methods to improve API documentation. For example:

/**
 * Retrieves a specific condition from the canvas state.
 * @returns {any} The requested condition value.
 */
getCondition,

/**
 * Retrieves all conditions from the canvas state.
 * @returns {Object} An object containing all condition key-value pairs.
 */
getConditions,

27-28: Overall impact: Enhanced condition management capabilities.

The changes introduce new methods for managing conditions in the canvas rendering system. These additions are non-breaking and enhance the API's functionality without modifying existing code.

Consider the following suggestions to further improve the implementation:

  1. Ensure that proper error handling and type checking are implemented in the getCondition and getConditions methods (in the './context' module) to maintain robustness.
  2. If these methods are part of a public API, consider adding them to the API documentation or README file to inform users of the new capabilities.
  3. Consider adding unit tests for these new methods to ensure their correct functionality and integration with the existing system.

Also applies to: 446-447

packages/toolbars/preview/src/Main.vue (1)

Line range hint 34-89: Consider Extracting Repetitive Logic into a Helper Function

The code pattern for checking if a function exists, calling it, and handling errors is repeated for beforePreview, previewMethod, and afterPreview. Consider extracting this pattern into a helper function to reduce duplication and improve readability.

Example of extracting the logic:

function executeHook(hookFunction, errorMessage) {
  if (typeof hookFunction === 'function') {
    return hookFunction().catch(error => {
      console.log(errorMessage, error)
      useNotify({
        type: 'error',
        message: errorMessage
      })
    })
  }
}

const preview = async () => {
  const { beforePreview, previewMethod, afterPreview } = getOptions(meta.id)

  await executeHook(beforePreview, 'Error in beforePreview:')
  
  if (await executeHook(previewMethod, 'Error in previewMethod:')) {
    return
  }

  // existing preview logic...

  await executeHook(afterPreview, 'Error in afterPreview:')
}

This refactoring reduces code repetition and centralizes error handling for hook functions.

packages/toolbars/save/src/Main.vue (1)

Line range hint 105-121: Refactor auto-save functionality using setInterval

The current implementation uses a recursive setTimeout in saveSetTimeout, which can lead to potential issues like stack overflows or unintended multiple timeouts. Using setInterval simplifies the code and ensures consistent execution at specified intervals.

Apply this diff to refactor the auto-save functionality:

-const saveSetTimeout = () => {
-  clearTimeout(state.preservationTime)
-  state.preservationTime = setTimeout(() => {
-    openApi()
-    saveSetTimeout()
-  }, state.timeValue * 60 * 1000)
-}
-
-const autoSave = () => {
-  if (state.checked) {
-    saveSetTimeout()
-  } else {
-    clearTimeout(state.preservationTime)
-  }
-  state.saveVisible = false
-}
+let autoSaveInterval = null
+
+const startAutoSave = () => {
+  stopAutoSave()
+  autoSaveInterval = setInterval(() => {
+    openApi()
+  }, state.timeValue * 60 * 1000)
+}
+
+const stopAutoSave = () => {
+  clearInterval(autoSaveInterval)
+  autoSaveInterval = null
+}
+
+const autoSave = () => {
+  if (state.checked) {
+    startAutoSave()
+  } else {
+    stopAutoSave()
+  }
+  state.saveVisible = false
+}
+
+onUnmounted(() => {
+  stopAutoSave()
+})
packages/settings/events/src/components/BindEventsDialog.vue (1)

Line range hint 175-210: Add error handling for beforeSaveMethod to prevent unhandled rejections.

Since confirm is now an async function that awaits beforeSaveMethod, any errors thrown by beforeSaveMethod could result in unhandled promise rejections. To enhance stability and user experience, consider adding error handling around this call.

You can wrap the call in a try-catch block:

if (typeof beforeSaveMethod === 'function') {
+  try {
     await beforeSaveMethod(method, state.bindMethodInfo)
+  } catch (error) {
+    // Handle the error appropriately
+    console.error('Error in beforeSaveMethod:', error)
+    // Optionally notify the user about the error
+  }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6f9ab48 and c8bc905.

📒 Files selected for processing (10)
  • packages/canvas/DesignCanvas/src/DesignCanvas.vue (4 hunks)
  • packages/canvas/container/src/CanvasContainer.vue (4 hunks)
  • packages/canvas/index.js (1 hunks)
  • packages/canvas/render/src/RenderMain.js (2 hunks)
  • packages/canvas/render/src/context.js (1 hunks)
  • packages/canvas/render/src/runner.js (2 hunks)
  • packages/settings/events/src/components/BindEventsDialog.vue (4 hunks)
  • packages/toolbars/preview/src/Main.vue (3 hunks)
  • packages/toolbars/save/src/Main.vue (1 hunks)
  • packages/toolbars/save/src/js/index.js (3 hunks)
🧰 Additional context used
🔇 Additional comments (16)
packages/canvas/render/src/context.js (2)

54-57: Overall, good additions to enhance condition management.

The new functions getCondition and getConditions complement the existing setCondition function and provide useful ways to access condition states. They align well with the module's purpose of managing context and conditions for canvas rendering.

A few minor improvements were suggested to enhance robustness and data protection. Additionally, more context about the use case for getConditions would be helpful in determining the best implementation approach.


57-57: Approved, but consider enhancing data protection and providing more context.

The getConditions function provides a way to access all condition states, which can be useful for debugging or bulk operations.

Consider the following suggestions:

  1. Return a copy of the conditions object to prevent unintended modifications:

    -export const getConditions = () => conditions
    +export const getConditions = () => ({ ...conditions })
  2. Add a comment explaining the intended use case for this function.

  3. If bulk access is not necessary, consider removing this function to maintain better encapsulation.

To help determine the best course of action, let's check if this function is used elsewhere in the codebase:

Could you provide more context on why direct access to all conditions is necessary? This information would help in determining whether to keep this function or if there's a more specific approach we could implement.

packages/canvas/render/src/runner.js (1)

Line range hint 1-91: Overall assessment: Good changes with room for improvement

The modifications to this file, particularly the changes to the create function, are generally positive. The main improvement is passing the renderer object to beforeAppCreate, which simplifies the API and provides a more consistent interface.

However, there are a few areas where the code could be further improved:

  1. Error handling could be more robust.
  2. Consider alternatives to using global properties for better state management.
  3. Address the potential memory leak with the ResizeObserver.

Addressing these points would further enhance the code's quality and maintainability.

packages/canvas/DesignCanvas/src/DesignCanvas.vue (5)

8-9: LGTM: New props align with PR objectives

The addition of canvas-src and canvas-src-doc props to the CanvasContainer component aligns well with the PR objective of allowing configuration of the src attribute. This change provides more flexibility in handling canvas sources.


30-31: LGTM: New imports support enhanced functionality

The addition of getMergeMeta and getOptions imports is consistent with the new functionality introduced in the component. These utilities likely support the new canvas source handling mechanism.


38-38: LGTM: Meta import added

The addition of the meta import is appropriate, as it's used later in the code to retrieve options specific to this component.


173-174: LGTM: New canvas source variables exposed to template

The addition of canvasSrc and canvasSrcDoc to the returned object correctly exposes these new variables to the template. This change is consistent with the earlier modifications in the template and setup function.


Line range hint 1-194: Summary: Successfully implemented custom canvas source support

The changes in this file successfully implement support for custom canvas sources, aligning well with the PR objectives. The new canvasSrc and canvasSrcDoc properties provide flexibility in handling canvas sources while maintaining backwards compatibility. The code quality is good, with only a minor suggestion for improved readability.

Overall, these changes enhance the functionality of the DesignCanvas component without introducing breaking changes.

packages/canvas/container/src/CanvasContainer.vue (2)

78-78: LGTM! Computed property for dynamic attribute selection.

The srcAttrName computed property is a clean and efficient way to determine the correct attribute for the iframe based on the available source. This approach enhances the component's flexibility and maintainability.


247-248: LGTM! Exposing new properties to the template.

The addition of loading and srcAttrName to the returned object in the setup function correctly makes these properties available for use in the template. This change is consistent with the Vue 3 Composition API best practices.

packages/canvas/render/src/RenderMain.js (1)

27-28: LGTM: New imports added correctly.

The new imports for getCondition and getConditions are appropriately placed with other related imports from the './context' module. This change aligns with the newly added methods in the api object.

packages/toolbars/preview/src/Main.vue (1)

39-49: Check for Early Return Condition in previewMethod

When previewMethod returns a truthy stop value, the function exits early. Ensure that this behavior is intentional and properly documented, so other developers understand the control flow.

Please confirm that returning stop from previewMethod is the desired behavior for halting the preview process.

packages/toolbars/save/src/js/index.js (1)

163-169: Review error handling in the saved hook

When invoking the saved hook, any errors are caught and logged, but no further action is taken. If the saved hook performs critical operations, consider implementing additional error handling, such as notifying the user or retrying the operation, to ensure the application responds appropriately to failures.

packages/settings/events/src/components/BindEventsDialog.vue (3)

35-35: Importing getOptions is appropriate and necessary.

The addition of getOptions import is necessary for retrieving options like beforeSaveMethod. This enhances the flexibility and configurability of the component.


197-203: Ensure consistent inclusion of eventArgs in function parameters.

Currently, eventArgs is included in the function parameters only when state.enableExtraParams is true. Verify whether eventArgs should always be included to ensure that event data is consistently available within the method. Inconsistencies might lead to unexpected behaviors or bugs.

Run the following script to analyze how eventArgs is used in function definitions:

#!/bin/bash
# Description: Find function definitions that include 'eventArgs' in their parameters.

# Search for functions where 'eventArgs' is a parameter
rg --type js --pcre2 'function\s+\w+\s*\(\s*eventArgs' -A 2

Expected Result: The script will list all function definitions that use eventArgs as a parameter, helping determine if it should be included consistently.


16-16: Verify necessity of passing dialogVisible prop to BindEventsDialogSidebar.

Please check if the dialogVisible prop is utilized within the BindEventsDialogSidebar component. If it's not used, consider removing it to simplify the component interface and avoid passing unnecessary props.

Run the following script to verify if dialogVisible is used within BindEventsDialogSidebar:

Expected Result: The script will output lines from BindEventsDialogSidebar.vue where dialogVisible is defined in props. If no output is returned, it indicates that dialogVisible is not used in the component.

packages/canvas/index.js Outdated Show resolved Hide resolved
packages/toolbars/preview/src/Main.vue Show resolved Hide resolved
packages/toolbars/preview/src/Main.vue Outdated Show resolved Hide resolved
packages/toolbars/preview/src/Main.vue Outdated Show resolved Hide resolved
packages/toolbars/preview/src/Main.vue Outdated Show resolved Hide resolved
packages/toolbars/save/src/js/index.js Outdated Show resolved Hide resolved
packages/toolbars/save/src/js/index.js Outdated Show resolved Hide resolved
packages/toolbars/save/src/Main.vue Show resolved Hide resolved
Copy link
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (2)
packages/toolbars/save/src/js/index.js (2)

100-119: LGTM: New hooks implemented with improved error handling

The implementation of beforeSave, saveMethod, and saved hooks aligns well with the PR objectives. The addition of error handling is a good practice.

Consider adding more specific error messages for different types of errors to provide better context to the user.

You could enhance the error handling by providing more specific error messages:

} catch (error) {
  let errorMessage = 'An unexpected error occurred during saving.';
  if (error instanceof TypeError) {
    errorMessage = 'Invalid data type encountered during saving.';
  } else if (error instanceof NetworkError) {
    errorMessage = 'Network error occurred while saving. Please check your connection.';
  }
  useNotify({
    type: 'error',
    message: `Error in saving: ${errorMessage}`
  });
}

164-174: LGTM: Improved error handling and hook implementation

The use of a finally block to reset state.disabled and the implementation of the saved hook with error handling are good practices.

Consider adding a more descriptive error message and potentially logging the error for debugging purposes.

You could enhance the error handling for the saved hook:

} catch (error) {
  console.error('Error in saved hook:', error);
  useNotify({
    type: 'error',
    message: `An error occurred after saving. Some post-save operations may not have completed successfully. Error: ${error.message}`
  });
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c8bc905 and ab76de4.

📒 Files selected for processing (3)
  • packages/canvas/index.js (1 hunks)
  • packages/toolbars/preview/src/Main.vue (3 hunks)
  • packages/toolbars/save/src/js/index.js (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/canvas/index.js
  • packages/toolbars/preview/src/Main.vue
🧰 Additional context used
🔇 Additional comments (2)
packages/toolbars/save/src/js/index.js (2)

20-20: LGTM: Import statement updated correctly

The addition of getOptions to the import statement is in line with the PR objectives to introduce new hooks for the save functionality.


Line range hint 1-174: LGTM: Overall implementation aligns with PR objectives

The changes in this file successfully implement the new hooks for the save functionality as described in the PR objectives. The error handling has been improved, and the overall structure of the code remains clean and maintainable.

Great job on enhancing the save feature with these new hooks and improved error handling!

Copy link
Contributor

@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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ab76de4 and 69667b5.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • packages/toolbars/preview/src/Main.vue (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/toolbars/preview/src/Main.vue
🧰 Additional context used

package.json Outdated Show resolved Hide resolved
chilingling
chilingling previously approved these changes Oct 10, 2024
Copy link
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (2)
packages/canvas/package.json (1)

17-24: LGTM! Consider adding a CommonJS export condition.

The addition of the exports field is a great improvement. It provides explicit control over how the package can be imported, which enhances compatibility with various module resolution systems.

To further improve compatibility, consider adding a CommonJS export condition. This would allow the package to be used in both ES Module and CommonJS environments. Here's a suggested modification:

 "exports": {
   ".": {
-    "import": "./dist/index.js"
+    "import": "./dist/index.js",
+    "require": "./dist/index.cjs"
   },
   "./render": {
-    "import": "./dist/render.js"
+    "import": "./dist/render.js",
+    "require": "./dist/render.cjs"
   }
 },

Note: This suggestion assumes that CommonJS versions of the files (with .cjs extension) are or will be available in the dist directory. If not, you'll need to adjust your build process to generate these files.

packages/canvas/vite.config.js (1)

37-38: LGTM! Consider updating documentation.

The addition of the render entry point is a good improvement, allowing for more granular imports and potentially smaller bundle sizes. This change aligns well with the PR objectives of introducing new canvas functionality.

Consider updating the package documentation to reflect this new entry point, explaining its purpose and how it relates to the new hooks for save and preview functionalities.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 69667b5 and 4b9c0be.

📒 Files selected for processing (5)
  • packages/build/vite-config/src/vite-plugins/devAliasPlugin.js (1 hunks)
  • packages/canvas/package.json (1 hunks)
  • packages/canvas/render/src/context.js (1 hunks)
  • packages/canvas/vite.config.js (1 hunks)
  • packages/design-core/src/canvas/canvas.js (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/design-core/src/canvas/canvas.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/canvas/render/src/context.js
🧰 Additional context used
🔇 Additional comments (2)
packages/build/vite-config/src/vite-plugins/devAliasPlugin.js (2)

Line range hint 1-118: Overall assessment of changes in devAliasPlugin.js

The changes made to this file are minimal and focused. The addition of the new alias mapping for @opentiny/tiny-engine-canvas/render is consistent with the existing pattern and doesn't introduce any apparent issues. The rest of the file, including the getDevAlias function structure and the devAliasPlugin function, remains unchanged.

To ensure the change is fully integrated:

  1. Verify that the new alias is being used correctly in other parts of the codebase (as suggested in the previous comment).
  2. Consider updating any relevant documentation to reflect this new alias, if necessary.
  3. Ensure that the build process correctly resolves this new alias in both development and production environments.

58-58: New alias mapping added for @opentiny/tiny-engine-canvas/render

The new alias mapping has been correctly added to the getDevAlias function. This addition allows for easier imports of the render module from the canvas package during development.

To ensure consistency and proper usage, let's verify if this new alias is being used correctly in other parts of the codebase:

This will help us identify any places where the new alias is being used and ensure it's implemented correctly across the project.

chilingling
chilingling previously approved these changes Oct 10, 2024
hexqi
hexqi previously approved these changes Oct 10, 2024
Copy link
Collaborator

@rhlin rhlin left a comment

Choose a reason for hiding this comment

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

LGTM

@hexqi hexqi merged commit 6c4227e into opentiny:refactor/develop Oct 10, 2024
1 check passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 12, 2024
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor-main refactor/develop branch feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants