Skip to content

Commit 81718e1

Browse files
author
Sascha Goldhofer
committed
Merge branch 'release/9.1.0'
2 parents 77c1db4 + fcb416e commit 81718e1

19 files changed

+763
-216
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ _Editron_ can be loaded through script tags in HMTL or bundled with your applica
7878

7979

8080
## Working With Editron
81+
82+
For a general understanding of a json-schema and editron editors refer to the introduction [docs/json-schema-and-editron-editors](./docs/json-schema-and-editron-editors.md).
83+
8184
For details about _editron_ **configuration** and **interaction** refer to [docs/howto-work-with-editron](./docs/howto-work-with-editron.md). What follows is a quick overview:
8285

8386
Create an instance of editron, passing your json-schema
@@ -168,6 +171,9 @@ Besides [getting-started](./examples/getting-started.html), the following exampl
168171

169172
## Breaking Changes
170173

174+
`03/2021` with `v9` `Controller` has been renamed to `Editron` for consistency.
175+
176+
171177
`07/2020` with `v8` editron is written using typescript. Due to module-syntax, some exports have changed, mainly:
172178

173179
- accessing services has change to a method `editron.service(serviceName)`

dist/editron-modules.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/editron.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export default Editron;
2222
export { Editron, Options };
2323
export * as components from "./src/components";
2424
export * as utils from "./src/utils";
25-
export * as store from "./src/store/global";
25+
export { translate } from "./src/utils/i18n";
26+
export { default as render } from "./src/utils/render";
2627
export type { Editor, EditorPlugin, Options as EditorOptions } from "./src/editors/Editor";
2728
export type { EditorUpdateEvent } from "./src/editors/Editor";
2829
export type { ValidationError, EditronConfigAttrs, FormatValidator, KeywordValidator, JSONSchema, JSONPointer, JSONData } from "./src/types";

dist/manifest.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/module/editron.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import * as components_1 from "./src/components";
2424
export { components_1 as components };
2525
import * as utils_1 from "./src/utils";
2626
export { utils_1 as utils };
27-
import * as store_1 from "./src/store/global";
28-
export { store_1 as store };
27+
export { translate } from "./src/utils/i18n";
28+
export { default as render } from "./src/utils/render";
2929
// editors
3030
export { default as AbstractEditor, getTypeClass } from "./src/editors/AbstractEditor";
3131
export { default as AbstractValueEditor } from "./src/editors/AbstractValueEditor";

dist/module/src/Editron.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ export default class Editron {
394394
validateAll() {
395395
setTimeout(() => this.destroyed !== true && this.service("validation").validate(this.service("data").getDataByReference()));
396396
}
397+
getErrors() {
398+
return this.service("validation").getErrorsAndWarnings();
399+
}
397400
/** Destroy the editor, its widgets and services */
398401
destroy() {
399402
var _a;

dist/src/Editron.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ export default class Editron {
236236
getRootEditor(editor: Editor): Editor | undefined;
237237
/** start validation of current data */
238238
validateAll(): void;
239+
getErrors(): ValidationError[];
239240
/** Destroy the editor, its widgets and services */
240241
destroy(): void;
241242
}

dist/src/services/dataservice/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,31 @@ import Store from "../../store";
33
import { JSONData, JSONPointer } from "../../types";
44
import { UpdateDataEvent } from "../../editors/Editor";
55
import { Change, SimpleChange } from "./change";
6+
/** Called before a single change in value will be notified */
67
declare type BeforeUpdateEvent = {
78
type: "data:update:before";
89
value: {
910
pointer: JSONPointer;
1011
action: string;
1112
};
1213
};
14+
/** Called when a single change in value was notified */
1315
declare type AfterUpdateEvent = {
1416
type: "data:update:after";
1517
value: {
1618
pointer: JSONPointer;
1719
patch: Patch;
1820
};
1921
};
22+
/** Additional event called when for single array or object change */
2023
declare type ContainerUpdateEvent = {
2124
type: "data:update:container";
2225
value: {
2326
pointer: JSONPointer;
2427
changes: Array<Change>;
2528
};
2629
};
30+
/** Called when all updates have been notified */
2731
declare type UpdateDoneEvent = {
2832
type: "data:update:done";
2933
value: Array<SimpleChange>;

docs/doc-editron-editor.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,31 @@
2020

2121
## Editor
2222

23-
> A custom _editor_ is **completly responsible for rendering the display of a value to a _dom_-Element, receiving user-events and passing data-changes back to _editron_**. _Editron_ will manage and update values, perform validation, error-reporting and initialize editors, based on the _json-schema_ and available _editors_ .
23+
> A custom _editor_ is **completly responsible for rendering the display of a value to a _dom_-Element, receiving user-events and passing data-changes back to _editron_**. _Editron_ will manage and update values, perform validation, error-reporting and initialize editors, based on the _json-schema_ and available _editors_.
24+
25+
An _editor_ usally renders a single json-schema type, for example a json-schema like
26+
27+
```json
28+
{
29+
"type": "object",
30+
"properties": {
31+
"title": {
32+
"type": "string"
33+
}
34+
}
35+
}
36+
```
37+
38+
can be rendered to a tree of editors like
39+
40+
```jsx
41+
<ObjectEditor>
42+
<ValueEditor title>
43+
</ObjectEditor>
44+
```
45+
46+
You can read more details about this in [docs/json-schema-and-editron-editors.md].
47+
2448

2549
An custom _editron editor_ **needs** to be a class (or instantiatable function) with the following attributes
2650

docs/doc-editron-options.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# Editron Options
2+
3+
> You can customize most forms for the bundled _editron editors_ in your _json-schema_. For this, follow the [docs/doc-editor-options](./doc-editor-options.md). When you need to adjust the list of used [editors](./docs/doc-editron-editor.md), add [plugins](./doc-plugin.md) or modify [services](./howto-work-with-editron#services) you can add _options_ to the _editron_ constructor which is described here.
4+
5+
- [Options](#options)
6+
- [Option: i18n](#option-i18n)
7+
- [Option: services](#option-services)
8+
- [Option: proxy](#option-proxy)
9+
10+
11+
## Options
12+
13+
Creating a new _editron_ instance you may pass an optional _options_ object
14+
15+
```ts
16+
import { Editron } from "editron";
17+
18+
const options = {}
19+
const jsonSchema = { type: "object" };
20+
const editron = new Editron(jsonSchema, data || {}, options);
21+
```
22+
23+
With the options supporting the following settings
24+
25+
option | type | description
26+
----------|-----------------|----------------------
27+
editors | EditorPlugin[] | a list of additional _editors_ that may be used to display your json-schema
28+
addDefaultEditors | boolean | if set to false, _editron_ will not add the bundled _editors_ to the list of available _editors_.
29+
i18n | object | an object containing key-string translations
30+
proxy | object | an object with proxy handlers for custom requests
31+
locationService | object | a configuration object for the location-service
32+
33+
34+
For example, adding a custom editor:
35+
36+
```ts
37+
import { Editron } from "editron";
38+
import { MyImageEditor } from "./MyImageEditor";
39+
40+
const jsonSchema = { type: "object" };
41+
const editron = new Editron(jsonSchema, data || {}, {
42+
editors: [MyImageEditor]
43+
});
44+
```
45+
46+
47+
### Option i18n
48+
49+
_Editron_ uses a simple key to string translation helper, that is exposed as `translate`. This method will return a string for a unique key and performs placeholder replacement for a data-object. Example:
50+
51+
For a key
52+
53+
```ts
54+
{ "custom:title": "Title of {{id}}" }
55+
```
56+
57+
you can call translate with
58+
59+
```ts
60+
import { translate } from "editron";
61+
const string = translate("custom:title", { id: "Test" });
62+
console.log(string); // "title of Test"
63+
```
64+
65+
You can add your own key-string pairs and overwrite strings used by _editron_ using the i8n setting:
66+
67+
```ts
68+
import { Editron } from "editron";
69+
const editron = new Editron(jsonSchema, data || {}, {
70+
i18n: {
71+
strings: {
72+
"toolbar:undo:tooltip": "Undo. Letzte Änderung rückgängig machen",
73+
"toolbar:redo:tooltip": "Redo. Letzte Änderung wiederherstellen",
74+
}
75+
}
76+
});
77+
```
78+
79+
The _i18n_ object supports translation of generated errors. Each error has its own error-code, which may be referenced for string translation like in:
80+
81+
```ts
82+
import { Editron } from "editron";
83+
const editron = new Editron(jsonSchema, data || {}, {
84+
i18n: {
85+
errors: {
86+
"minimum-error": "Die Zahl muss größer oder gleich {{minimum}} sein"
87+
}
88+
}
89+
});
90+
```
91+
92+
When a simple string-translation is not sufficient you may also pass a function
93+
94+
```ts
95+
import { Editron, render } from "editron";
96+
const editron = new Editron(jsonSchema, data || {}, {
97+
i18n: {
98+
errors: {
99+
"min-length-error": (editron, error) => {
100+
if (error.data.minLength === 1) {
101+
return "Es wird eine Eingabe benötigt";
102+
}
103+
return render("Der Text muss eine Mindestlänge von {{minLength}} haben (aktuell {{length}}).", error.data);
104+
}
105+
}
106+
}
107+
});
108+
```
109+
110+
111+
### Option Services
112+
113+
Currently, only the [LocationService](./howto-work-with-editron#locationservice) has configuration settings exposed on `locationService`:
114+
115+
116+
```ts
117+
import { Editron } from "editron";
118+
const editron = new Editron(jsonSchema, data || {}, {
119+
locationService: {
120+
/** additional offset in px, to scroll into view. In case you want to adjust scroll-position on focus (e.g. skip a header). Defaults to 0 */
121+
scrollTopOffset: 50
122+
/** default root element, where any json-pointers (editron widgets) are searched for. Defaults to `document.body` */
123+
rootElement: $mainFormElement;
124+
/** regular expression to identify page-target within a json-pointer. The service will emit an event `location:page` when it was changed */
125+
pagePattern?: string;
126+
/** a scoll callback event is fired when the desired position has completed scrolling */
127+
scrollCallback?: boolean;
128+
}
129+
});
130+
```
131+
132+
133+
### Option Proxy
134+
135+
_Editron_ uses a frontend adapter [Foxy](https://github.com/sueddeutsche/foxy/) to configure requests outside of _editron_ to be used within _editron_ by custom _editors_. You may pass Foxy-Handlers to the _editron_ constructor, like:
136+
137+
```ts
138+
import { Editron } from "editron";
139+
const editron = new Editron(jsonSchema, data || {}, {
140+
proxy: {
141+
handlers: [
142+
{
143+
use: () => true,
144+
getImageData: ({ source }) => imageService.get(source)
145+
}
146+
]
147+
}
148+
});
149+
```
150+
151+
which can be accessed from any _editron_ instance by
152+
153+
```ts
154+
const imageData = await editron.proxy().get("getImageData", { source: 123 });
155+
```
156+
157+
For more details about the handlers and api, refer to the [Foxy Documentation](https://github.com/sueddeutsche/foxy/).
158+
159+
160+
161+
162+
You can read [docs/howto-work-with-editron](./howto-work-with-editron.md) next
163+
164+
[Back to README](../README.md)

0 commit comments

Comments
 (0)