Coder Social home page Coder Social logo

Comments (18)

ascoders avatar ascoders commented on July 22, 2024 2

json 解析一下就成 jsx 了,未来我可能会加上这个功能。

from gaea-editor.

yunsii avatar yunsii commented on July 22, 2024 1

看了看 gaea-render 的源码,重写了一个渲染组件 gaea-injection-render ,解决了不能刷新的问题

终于跑完整个流程了 _(:3J∠)_

from gaea-editor.

eddyzhang1986 avatar eddyzhang1986 commented on July 22, 2024

@ascoders
niubility,i am so worship you
崇拜中,顺便多问一句大神,
这个解析过程是不是非常类似于编译原理的 遍历抽象语法树 生成最终代码的过程
用visit模式就可以解决这个问题,是这个样子的嘛?
如果大神原意带我的话,我也想参与一下帮你打个杂解学习下这种问题的解决的说

from gaea-editor.

ascoders avatar ascoders commented on July 22, 2024

@eddyzhang1986 谈不上打杂,你可以把这个功能抽象出来,不一定要与编辑器耦合。

可以把编辑器生成的 json 当做语法树,可以通过给编辑器新增插件,或者自己写一个【通用语法树->jsx解析器】,我觉得做后者更有意义。

用什么模式都可以,总之做好了以后,通过 decode 拿到结构化数据,就可以解析了:

import {decode} from 'gaea-editor'
const dataJson = decode(editorSaveData)
const jsxStr = yourParser(dataJson)

from gaea-editor.

ascoders avatar ascoders commented on July 22, 2024

继续 mark,这个功能蛮多人推荐的。

from gaea-editor.

nick121212 avatar nick121212 commented on July 22, 2024

@ascoders 你这个功能,我正好也在做,有没有联系方式沟通下

from gaea-editor.

nick121212 avatar nick121212 commented on July 22, 2024

这个是测试地址:https://nick121212.github.io/fx-schema-form-react-demo/dist/index.html#/panel/create

from gaea-editor.

yunsii avatar yunsii commented on July 22, 2024

json 解析一下就成 jsx 了,未来我可能会加上这个功能。

现在有下文了吗,如果纯用 json 渲染的话,UI 和数据的联动没法搞吧?

from gaea-editor.

ascoders avatar ascoders commented on July 22, 2024

@theprimone json 语法有描述 UI 与数据联动 - 事件机制。

生成 jsx 还没做,因为我觉得可以根据 json 生成,大家生成的场景也不同,还是留给业务方自己做吧。

from gaea-editor.

yunsii avatar yunsii commented on July 22, 2024

@ascoders 现在我的难点是

  1. 外部数据如何注入。当前的技术栈是 umi + dva + antd-mobile,也看了 #12 中的回复,听你这么一说,是通过在渲染的时候将数据注入 json 配置中?
  2. 事件机制没弄懂。看了 #26 中的回复,现在能达到控制弹窗的效果了吗?

from gaea-editor.

ascoders avatar ascoders commented on July 22, 2024
  1. 无论是通过插件把 json -> jsx 做成内置功能,还是外部 onChange 拿到 json 后手动转成 jsx 都可以,与技术方案没关系,只要是 react 体系即可。
  2. 事件分为 trigger 和 action,trigger 可以是组件的回调比如 onClick,trigger 可以修改组件状态比如修改值为 visible,我看你做的比较深入,可以考虑 fork 一下看看源代码,发一个自己修改过源码的包使用。

from gaea-editor.

yunsii avatar yunsii commented on July 22, 2024
  1. 我的想法是在组件中添加一个数据源的 string 字段,比如: dataSource 。渲染的时候遍历 json 根据 dataSourceprops 注入组件渲染需要的数据。这样做的话就不用关心转换的问题了,纯展示型的页面应该没问题。
  2. 添加事件没问题,但是触发另一个组件显示隐藏不行,选择触发事件,也没有可下拉的事件可供选择,不知道需要注意些什么。另,事件对象打印的是 Proxy 对象,序列化的话有问题,事件应该怎么序列化呢?以及如果让事件调用外部定义的方法呢?比如打开模态框的时候调用接口和点击确定调用查询接口。如果都能通过 json 解决就完美了

这就看看源码。

from gaea-editor.

yunsii avatar yunsii commented on July 22, 2024

之前的解决方案可行。给特定组件添加像 dataSourcehandleClick 的字段,再在渲染时,根据对应的字段注入数据和方法即可。参考 feat: injectConfig to renderJson and save gaea-draft 。不知道这样的解决方案如何?

另,很尴尬,源码 npm i 后启动报错

Analyse project×  fatal     Unexpected file or directory: D:\workspaces\github\gaea-editor\node_modules\.bin

这是在我删了之前报错的两次文件之后,真是疑惑。

from gaea-editor.

ascoders avatar ascoders commented on July 22, 2024

目前不支持 windows 系统调试源码,能试试 linux 环境吗

from gaea-editor.

yunsii avatar yunsii commented on July 22, 2024

有点硬核了,用 gitpod 打开了 😆

from gaea-editor.

yunsii avatar yunsii commented on July 22, 2024

搞了个可配置的属性,大佬看看可以合并不? 单独发布好像没太大必要。

feat: config layout of editor

from gaea-editor.

ascoders avatar ascoders commented on July 22, 2024

功能截图有吗

from gaea-editor.

yunsii avatar yunsii commented on July 22, 2024

src/gaea-editor.type.tsx 加了配置

/**
 * Editor layout
 */
public layout?: {
  showDragMenu: boolean;
  defaultViewMode: ViewMode;
} = { showDragMenu: false, defaultViewMode: 'PC' };

当我这样初始化配置的时候

<Editor layout={{ showDragMenu: true, defaultViewMode: 'Iphone6/7/8' } { ...rest } />

就达到初始化布局的目的了,后续可扩展配置。

==================================

另,我试了异步为 gaea-render 赋值,发现渲染器不会刷新 UI ,这该怎么办呢?试了试用 refforceUpdate() 也不行,最后一步了,我太难了 _(:3J∠)_

from gaea-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.