json_editor.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { JSONEditor } from "standalone";
  2. export default {
  3. template: "<div></div>",
  4. mounted() {
  5. this.properties.onChange = (updatedContent, previousContent, { contentErrors, patchResult }) => {
  6. this.$emit("change", { content: updatedContent, errors: contentErrors });
  7. };
  8. this.properties.onSelect = (selection) => {
  9. this.$emit("select", { selection: selection });
  10. };
  11. this.editor = new JSONEditor({
  12. target: this.$el,
  13. props: this.properties,
  14. });
  15. },
  16. beforeDestroy() {
  17. this.destroyEditor();
  18. },
  19. beforeUnmount() {
  20. this.destroyEditor();
  21. },
  22. methods: {
  23. update_editor() {
  24. if (this.editor) {
  25. this.editor.updateProps(this.properties);
  26. }
  27. },
  28. destroyEditor() {
  29. if (this.editor) {
  30. this.editor.destroy();
  31. }
  32. },
  33. run_editor_method(name, ...args) {
  34. if (this.editor) {
  35. if (name.startsWith(":")) {
  36. name = name.slice(1);
  37. args = args.map((arg) => new Function(`return (${arg})`)());
  38. }
  39. return runMethod(this.editor, name, args);
  40. }
  41. },
  42. },
  43. props: {
  44. properties: Object,
  45. },
  46. };