core icon indicating copy to clipboard operation
core copied to clipboard

[FEATURE] 更好的 Dialog 方案

Open hacke2 opened this issue 3 years ago • 5 comments

如果你的需求与问题相关,请在下面描述一下(Is your feature request related to a problem? Please describe.)

描述你预期的功能表现(Describe the solution you'd like)

目前插件新增一个 Dialog,在没有插件视图(左侧、右侧、编辑器内部)是没法将这个组件给注册到视图上去的。目前临时方案是使用 toolBar 这个插槽

package.json:


{
  "kaitianContributes": {
    "toolBar": {
        "component": [....]
    }
  }
}

希望有更好的方式来注册,目前不符和语义,不一定所有场景下都有 toolbar

描述你考虑过的替代方案(Describe alternatives you've considered)

  1. 增加 overlay 或者 dialog 的注册点,更加有语义,可以由框架层注册,可以防止没有 toolbar 的情况
  • 好处:和其他模型设计统一
  • 坏处:Dialog 显隐通过 Node/Worker command 进行管理,成本较高
kaitianContributes: {
  "dialogs": [
    {
      "id": "custom-dialog",
      "title": "Custom Dialog",
      "component": Dialog
    }
  ]
}
  1. 针对 Dialog 场景单独设计 API
  • 好处:抽象 Dialog 需求,开发者只用关心 Dialog 实际内容,显隐由 API 完成
  • 坏处:新增 kaitian API,有一定工作量 from @Aaaaash

// component
export const Dialog = (props: CustomDialogProps) => {
  const { message, description } = props;
  return (
    <div>
      <div>{message}</div>
      <div>{description}</div>
    </div>
  );
};

// contributes
kaitianContributes: {
  "dialogs": [
    {
      "id": "custom-dialog",
      "title": "Custom Dialog",
      "component": Dialog
    }
  ]
}

// openDialog
sumi.window.openDialog(
  'custom-dialog',
  {
    title: 'Custom Dialog',
    width: 800,
    height: 600,
    data: {
      message: 'Hello World!',
      description: 'This is a custom dialog',
    },
    actions: [
      { title: "确认", id: "confirm" },
      { title: "取消", id: "cancel" }
    ]
)

补充信息(Additional context)

hacke2 avatar Feb 28 '22 09:02 hacke2

感觉方案 2 对开发者更友好一些,同时减少了用户使用方案 1 可能带来的样式不统一、不适配主题等问题。

erha19 avatar Feb 28 '22 09:02 erha19

1 方案里的视图和 2 其实是一样的,所以样式和主题如果使用 IDE token 是没问题的,主要区别是 show/hide 如何来管理

hacke2 avatar Feb 28 '22 09:02 hacke2

方案 2 主要是考虑两种显示方式,一般来说两种需求都可能会有

  1. 在 Node 环境通过调用 API 来打开 dialog
  2. 在 Browser 环境执行 command 来打开 dialog

Aaaaash avatar Feb 28 '22 09:02 Aaaaash

@hacke2 这个还有计划搞吗?

erha19 avatar Jul 06 '22 02:07 erha19

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 12 '22 18:10 stale[bot]