* TODO 加强Custom

//TODO 改进 Ap Assemble->Custom:
TODO 改进 UserCenter->Custom:
1.加入input/action后，显示name而不是file str，并显示“修改”按钮
2.点击“修改”按钮后，显示TextArea with file str，并显示“提交修改”按钮
3.点击“提交修改”按钮后，更新file str，并且如果name change，需要对应更新uiControlInspectorData->input->inputName



* ReDesign Custom

Custom:
Ts Module(just as utils)
Action
Input



Action,Input can invoke Ts Module's export functions

custom action/input should be compile to action/input

# can publish custom action/input

can get custom action/input from selected action/input


all action/input should be write online!


custom data store in element store


import element can get its custom data

# element assemble's custom data = selected action/input + imported custom


* TODO 为custom data提供代码编辑器


![image](https://img2023.cnblogs.com/blog/419321/202311/419321-20231125153737959-249842872.png)

![image](https://img2023.cnblogs.com/blog/419321/202311/419321-20231125165344986-1891902166.png)



# 目的

1.可以更好地编辑custom data
//2.可以发布custom data到贡献市场

# 具体方案

对于目的1：

- 在代码编辑器中编辑custom data，**支持ts语法，提供代码提示**（包括获得editor whole协议、选择的action等贡献的协议  中定义的类型）、高亮、自动补全等功能 


- file str应该跟原生的input/action的Main.ts文件一样，这样可方便用户要发布时可直接将其拷贝到本地

/*
对于目的2：

- 增加对协议的编辑和发布
  - 优化协议的开发过程：只填一些模板的类型，以及package.json的必备信息（如name、version），即可直接发布（到npm?)

- 增加发布到贡献市场
*/



refer to:

https://juejin.cn/post/7121512390159499278#heading-10
https://juejin.cn/post/7146457023415058468
https://theia-ide.org/

https://cloud.tencent.com/document/product/1301/57912






# ** TODO update Js Module to Ts Module



* TODO update custom input

TODO custom action/input should be compile to action/input

TODO can publish custom action/input

TODO can get custom action/input from selected action/input
test js code



Input:
need type:
editor whole package
action state
    could read type of file by actionName?


** TODO basic monaco demo

TODO show


TODO can get compiled value


# TODO add Ts Module
# can as contribute?

# 多文件

# TODO can get compiled value






TODO local: can get compiled value in webpack

TODO local: handle import protocol's actionName

TODO local: handle import utils(Ts Module)
bundle


TODO write a gulp to compile ts and bundle!

remove imported "export"
nest import


implement by rescript!

TODO bdd test


TODO run test


```ts
export default function getModelsInOrder(currentModel, monaco) {
  const allModels = monaco.editor.getModels();
  //Parse import statements to perform DFS starting at selected model
  const graph = allModels.map((model) => {
    let importRegex = /(from|import)\s+["']([^"']*)["']/gm;
    let importIndices = (model.getValue().match(importRegex) ?? []) //Get import strings
      .map((s) => s.match(/["']([^"']*)["']/)![1]) //find name
      .map((s) =>
        allModels.findIndex(
          (findImportModel) =>
            s === findImportModel.uri.path.substring(1).replace(/\.[^.]*$/, "") //compare formatted import to formatted filename
        )
      )
      .filter((index) => index !== -1);
    return importIndices;
  });

```




** DONE monaco demo2 by give more type infer(e.g. action state type, editor whole package)







** DONE custom input write online

store in element

import by element

TODO fix ui:
manage custom in element assemble instead of in ap assemble
  add
  show
  monaco


TODO fix publish element


# TODO fix UIConinpsector

TODO fix importElement



TODO merge when custom input of the same name:
compare equal(first length, then all)?{
use local input
} :{
remain one custom input;
rename another custom input's name to add post fix:"_copy";
}



# TODO fix add generated custom:
# add when run




TODO fix publish app->generate app

TODO fix import app:
ShowPublishedApp
getDataOf app


TODO frontend: 
webpack for monaco
add static files(meta3d-type)



TODO pass compile


TODO bdd test





TODO run test


  TODO fix:
    # edit code error
    run visual too slow!
      GPU
      TODO publish all
      TODO update all package
    # with input1 too slow

  test:
    # import app
    run visual
    use custom input
    import elements custom
      TODO fix: ui control inspectorl not get real data?
    switch->shouldn't restore

    import two elements custom

    run app


TODO pass bdd test




** DONE refactor: merge assemble-space, frontend, frontend-utils to frontend

merge src

update store

pass compile

merge test

pass compile

pass bdd test


merge frontend-utils

pass compile

pass bdd test


pass run test

** TODO input write local

# same content as online, except import protocol types 

# TODO publish

TODO compiled to custom input when show them in element assemble

# when start app:
# when enter assemble space:
# compile -> add to custom inputs
# selectedContributes remove local ones

when publish input:
publish compiled one: fileStr
  diff: use source instead of path

# when select input in market:
# get fileStr, name and store to selectedLocalBundledInputs/ActionsFromMarket instead of selectedContributesFromMarket


# when enter assemble space:
# add them to customs

when enter assemble space:
get bundled source -> add to custom inputs
selectedContributes remove local ones


  # name, fileStr



# TODO handle UI Control Inspector
# selectedContributes remove local ones



# TODO handle debug
# remove action debug?



TODO handle custom input and local input of the same name(remove all post fix):
compare equal(first length, then all)?{
use local input;
rename custom input's name to local input's one;
} :{
  if their name(not remove post fix) not the same? return :{
    remain custom input;
    rename custom input's name to add post fix:"_copy";
  }
}



pass compile

pass bdd test


pass run test
  import error

  fix: change input name, select not update




update all local inputs





# same content as online, just store in local and copy to online


# * TODO add Ts Module(as utils)

# can as contribute


# TODO Action,Input can invoke Ts Module's export functions

# TODO publish Ts Module

# TODO can get Ts Module from selected Published


# TODO how to handle import utils(Ts Module) in Input?



# ** TODO add Ts Module for custom input


# ** TODO add Ts Module for local input(utils)








# * TODO add "only import custom" button







* DONE update custom input->inputName: now can be arbitraily name

custom input is add by UI Control->Input!

auto get its name for build input protocol name!



* DONE fix: assertion

* DONE perf: solve run slow!

# auto change width,height?

fix: canvas size error


* DONE update custom action

# TODO should simplify type to forward, ... funcs!


pass compile 

pass bdd test

pass run test:runstop button
  no local
    # fix: not trigger run action!
  has local



TODO remove local input/action from selectedContributesFromMarket after import


TODO compile should unify!


    fix(platform): AssembleSpace->convertLocalToCustom: now remove local instead of local + custom
    
    because only has local, so only need remove local
    

TODO fix:
  change action/input name not match format, shouldn't error


TODO compile error shouldn't crash


////TODO api.nullable.getExn should return any type


TODO format


* DONE refactor: duplicate

AssembleSpace


* DONE add dispose custom input,action


* DONE update all actions




* DONE update custom actions->actionName: now can be arbitraily name

protocol auto add "-action-"









# * TODO publish