Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
felixebert committed Oct 6, 2021
2 parents 0c7004a + 7414ef0 commit 8409f5b
Show file tree
Hide file tree
Showing 9 changed files with 518 additions and 278 deletions.
2 changes: 1 addition & 1 deletion dist/editron-modules.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/manifest.json

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions dist/module/src/Editron.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export default class Editron {
this.plugins = [];
/** editron proxy instance */
_proxy.set(this, void 0);
schema = UISchema.extendSchema(schema);
this.options = {
editors: [],
addDefaultEditors: true,
Expand Down Expand Up @@ -357,7 +356,6 @@ export default class Editron {
* @param schema - a valid json-schema
*/
setSchema(schema) {
schema = UISchema.extendSchema(schema);
this.service("validation").set(schema);
this.service("schema").setSchema(schema);
}
Expand Down
27 changes: 1 addition & 26 deletions dist/module/src/utils/UISchema.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import gp from "gson-pointer";
import populated from "./populated";
import { eachSchema } from "json-schema-library";
const UI_PROPERTY = "editron:ui";
/** property on a schema-definition, containing editron-options */
export const EDITRON_OPTION_PROPERTY = "editron:ui";
Expand Down Expand Up @@ -83,29 +82,6 @@ function copyOptions(pointer, editron) {
});
return settings;
}
/**
* Ensures each schema contains a valid schema[UI_PROPERTY] object
* @param rootSchema
* @return extended clone of json-schema
*/
function extendSchema(rootSchema) {
rootSchema = JSON.parse(JSON.stringify(rootSchema));
eachSchema(rootSchema, childSchema => {
if (childSchema.$ref && childSchema[UI_PROPERTY] == null) {
// do not add default options for references - json-schema-library
// merges on root elements only (which is acceptable)
return;
}
childSchema[UI_PROPERTY] = {
hidden: false,
title: childSchema.title || "",
description: childSchema.description || "",
...childSchema.options,
...childSchema[UI_PROPERTY]
};
});
return rootSchema;
}
/**
* Resolves a list of pointers, where the first found value is returned. Supports simple strings as fallback.
* e.g. `["/data/local/title", "/data/local/subtitle", "Title"]`
Expand Down Expand Up @@ -142,7 +118,7 @@ function getOption(pointer, editron, ...options) {
throw new Error("Expected at least one options property to be given in getOption");
}
const schema = editron.service("schema").get(pointer);
const editronOptions = schema[UI_PROPERTY] || {};
const editronOptions = schema[UI_PROPERTY] || schema.options || {};
for (let i = 0; i < options.length; i += 1) {
const option = editronOptions[options[i]];
const resolver = isPointer(option) ? resolveReference : resolveOption;
Expand All @@ -167,7 +143,6 @@ function getDefaultOption(schema, option) {
export default {
copyOptions,
enumOptions,
extendSchema,
getBreadcrumps,
getDefaultOption,
getEditronOptions,
Expand Down
7 changes: 0 additions & 7 deletions dist/src/utils/UISchema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ export declare type EditorSettings = {
* @return a resolved copy of the editron:ui settings
*/
declare function copyOptions(pointer: JSONPointer, editron: Editron): EditorSettings;
/**
* Ensures each schema contains a valid schema[UI_PROPERTY] object
* @param rootSchema
* @return extended clone of json-schema
*/
declare function extendSchema<T extends JSONSchema>(rootSchema: T): T;
/**
* Returns the first defined option set in schema. Supports relative and absolute pointers in data
*
Expand All @@ -39,7 +33,6 @@ declare function getDefaultOption(schema: JSONSchema, option: string): "" | any;
declare const _default: {
copyOptions: typeof copyOptions;
enumOptions: typeof enumOptions;
extendSchema: typeof extendSchema;
getBreadcrumps: typeof getBreadcrumps;
getDefaultOption: typeof getDefaultOption;
getEditronOptions: typeof getEditronOptions;
Expand Down
3 changes: 0 additions & 3 deletions src/Editron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ export default class Editron {
* @param [options.plugins] - list of editron-plugins to use
*/
constructor(schema: JSONSchema = { type: "object" }, data: JSONData = {}, options: Options = {}) {
schema = UISchema.extendSchema(schema);

this.options = {
editors: [],
addDefaultEditors: true,
Expand Down Expand Up @@ -431,7 +429,6 @@ export default class Editron {
* @param schema - a valid json-schema
*/
setSchema(schema: JSONSchema): void {
schema = UISchema.extendSchema(schema);
this.service("validation").set(schema);
this.service("schema").setSchema(schema);
}
Expand Down
32 changes: 1 addition & 31 deletions src/utils/UISchema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import gp from "gson-pointer";
import populated from "./populated";
import { eachSchema } from "json-schema-library";
const UI_PROPERTY = "editron:ui";
import { JSONPointer, JSONSchema } from "../types";
import Editron from "../Editron";
Expand Down Expand Up @@ -111,34 +110,6 @@ function copyOptions(pointer: JSONPointer, editron: Editron): EditorSettings {
}


/**
* Ensures each schema contains a valid schema[UI_PROPERTY] object
* @param rootSchema
* @return extended clone of json-schema
*/
function extendSchema<T extends JSONSchema>(rootSchema: T): T {
rootSchema = JSON.parse(JSON.stringify(rootSchema));

eachSchema(rootSchema, childSchema => {
if (childSchema.$ref && childSchema[UI_PROPERTY] == null) {
// do not add default options for references - json-schema-library
// merges on root elements only (which is acceptable)
return;
}

childSchema[UI_PROPERTY] = {
hidden: false,
title: childSchema.title || "",
description: childSchema.description || "",
...childSchema.options, // @legacy options
...childSchema[UI_PROPERTY]
};
});

return rootSchema;
}


/**
* Resolves a list of pointers, where the first found value is returned. Supports simple strings as fallback.
* e.g. `["/data/local/title", "/data/local/subtitle", "Title"]`
Expand Down Expand Up @@ -177,7 +148,7 @@ function getOption(pointer: JSONPointer, editron: Editron, ...options: Array<str
}

const schema = editron.service("schema").get(pointer);
const editronOptions = schema[UI_PROPERTY] || {};
const editronOptions = schema[UI_PROPERTY] || schema.options || {};

for (let i = 0; i < options.length; i += 1) {
const option = editronOptions[options[i]];
Expand Down Expand Up @@ -210,7 +181,6 @@ function getDefaultOption(schema: JSONSchema, option: string): ""|any {
export default {
copyOptions,
enumOptions,
extendSchema,
getBreadcrumps,
getDefaultOption,
getEditronOptions,
Expand Down
6 changes: 0 additions & 6 deletions test/utils/uischema/getOption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ describe("UISchema.getOption", () => {
assert.ok(result === null);
});

it("should have option 'hidden' defined per default", () => {
const result = UISchema.getOption("#", controller, "hidden");

assert.ok(result === false);
});

it("should return value of option", () => {
schema["editron:ui"].title = "title in options";
controller.setSchema(schema);
Expand Down
Loading

0 comments on commit 8409f5b

Please sign in to comment.