项目作者: matteobruni

项目描述 :
Object GUI - Javascript Object GUI Editor
高级语言: TypeScript
项目地址: git://github.com/matteobruni/object-gui.git
创建时间: 2020-08-04T10:07:34Z
项目社区:https://github.com/matteobruni/object-gui

开源协议:MIT License

下载


README in: Indonesian
README in: German
README in: Hebrew
README in: Spanish
README in: Portuguese

Object GUI - Javascript Object Editor

Object GUI is your fully customizable Javascript Object GUI Editor

Gitpod Ready-to-Code

Usage

You can see a working sample here: https://codepen.io/matteobruni/pen/oNxNvja

Installation

HTML / Vanilla JS

You need to include these files:

CSS

https://cdn.jsdelivr.net/npm/object-gui@2/dist/css/object-gui.css

Javascript

https://cdn.jsdelivr.net/npm/object-gui@2/dist/js/object-gui.min.js

ES 6 Imports

  1. import { Editor } from "object-gui";

CommonJS / Node.js

  1. const Editor = require("object-gui");

Usage

  1. const code = document.getElementById("code");
  2. const data = {
  3. prop1: "pluto",
  4. prop2: 3,
  5. group1: {
  6. prop1: "paperino",
  7. prop2: 0.3,
  8. },
  9. color1: "#ff0000",
  10. select1: "Item 2",
  11. alert: function () {
  12. alert(JSON.stringify(data, null, 4));
  13. },
  14. };
  15. const editor = new Editor("sample", "Sample", () => data);
  16. editor.top().right();
  17. editor.theme("light");
  18. const group1 = editor.root.addGroup("group1", "Group 1", true);
  19. group1.addProperty("prop1", "Property 1", "string").change(() => {
  20. console.log(data);
  21. });
  22. group1
  23. .addProperty("prop2", "Property 2", "number")
  24. .min(0)
  25. .max(1)
  26. .step(0.01)
  27. .change(() => {
  28. console.log(data);
  29. });
  30. editor.root.addProperty("prop1", "Property 1", "string").change(() => {
  31. console.log(data);
  32. });
  33. editor.root
  34. .addProperty("prop2", "Property 2", "number")
  35. .min(0)
  36. .max(10)
  37. .step(0.5)
  38. .change(() => {
  39. console.log(data);
  40. });
  41. editor.root.addProperty("color1", "Color 1", "color").change(() => {
  42. console.log(data);
  43. });
  44. const select1Input = editor.root.addProperty("select1", "Select 1", "select").change(() => {
  45. code.innerText = JSON.stringify(data, null, 4);
  46. console.log(data);
  47. });
  48. select1Input.addItem("Item 1");
  49. select1Input.addItem("Item 2");
  50. select1Input.addItem("Item 3");
  51. editor.root.addButton("alert", "Alert");
  52. code.innerText = JSON.stringify(data, null, 4);