@vonaffenfels/contentful-slate-editor 1.1.26 → 1.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vonaffenfels/contentful-slate-editor",
3
- "version": "1.1.26",
3
+ "version": "1.1.28",
4
4
  "scripts": {
5
5
  "prepublish": "yarn run build",
6
6
  "dev": "yarn run start",
@@ -56,6 +56,8 @@
56
56
  "@babel/preset-env": "^7.13.15",
57
57
  "@babel/preset-react": "^7.13.13",
58
58
  "@contentful/app-sdk": "^3.33.0",
59
+ "@contentful/f36-components": "^4.56.2",
60
+ "@contentful/f36-multiselect": "^4.21.0",
59
61
  "@contentful/field-editor-single-line": "^0.14.1",
60
62
  "@contentful/field-editor-test-utils": "^0.11.1",
61
63
  "@contentful/forma-36-fcss": "^0.3.1",
@@ -91,10 +93,10 @@
91
93
  "webpack-watch-files-plugin": "^1.2.1"
92
94
  },
93
95
  "dependencies": {
94
- "@vonaffenfels/slate-editor": "^1.1.26",
96
+ "@vonaffenfels/slate-editor": "^1.1.28",
95
97
  "webpack": "5.88.2"
96
98
  },
97
- "gitHead": "5f0d00b0e64e0c1e25ade668bbabdebf85eafe02",
99
+ "gitHead": "a600552bfcbd6e605f8ababe0f4ef6f3222ac58a",
98
100
  "publishConfig": {
99
101
  "access": "public"
100
102
  }
@@ -1,83 +1,112 @@
1
- import React, {Component} from 'react';
1
+ import React, {
2
+ useEffect, useState,
3
+ } from 'react';
2
4
  import {
3
- Heading, Form, TextField, Workbench, Paragraph,
5
+ Heading, Form, TextField, Workbench,
4
6
  } from '@contentful/forma-36-react-components';
7
+ import {FormControl} from '@contentful/f36-components';
8
+ import {Multiselect} from '@contentful/f36-multiselect';
5
9
  import {css} from 'emotion';
6
10
 
7
- export default class Config extends Component {
11
+ const Config = ({sdk}) => {
12
+ const [params, setParams] = useState({
13
+ translationService: "",
14
+ usersWithTranslation: [],
15
+ });
16
+ const [spaceUsers, setSpaceUsers] = useState([]);
8
17
 
9
- constructor(props) {
10
- super(props);
11
- this.state = {parameters: {}};
18
+ const onConfigure = async () => {
19
+ const currentState = await sdk.app.getCurrentState();
12
20
 
13
- // `onConfigure` allows to configure a callback to be
14
- // invoked when a user attempts to install the app or update
15
- // its configuration.
16
- props.sdk.app.onConfigure(() => this.onConfigure());
17
- }
18
-
19
- async componentDidMount() {
20
- // Get current parameters of the app.
21
- // If the app is not installed yet, `parameters` will be `null`.
22
- const parameters = await this.props.sdk.app.getParameters();
21
+ return {
22
+ parameters: params,
23
+ targetState: currentState,
24
+ };
25
+ };
23
26
 
24
- this.setState(parameters ? {parameters} : this.state, () => {
25
- // Once preparation has finished, call `setReady` to hide
26
- // the loading screen and present the app to a user.
27
- this.props.sdk.app.setReady();
27
+ const onFieldChanged = (value, field) => {
28
+ setParams({
29
+ ...params,
30
+ [field]: value,
28
31
  });
29
- }
32
+ };
30
33
 
31
- async onConfigure() {
32
- // This method will be called when a user clicks on "Install"
33
- // or "Save" in the configuration screen.
34
- // for more details see https://www.contentful.com/developers/docs/extensibility/ui-extensions/sdk-reference/#register-an-app-configuration-hook
34
+ useEffect(() => {
35
+ if (sdk) {
36
+ sdk.app.getParameters().then(params => {
37
+ setParams(params);
38
+ sdk.app.setReady();
39
+ });
40
+ sdk.space.getUsers().then(users => {
41
+ setSpaceUsers(users.items.map(v => v.email));
42
+ });
43
+ }
44
+ }, [sdk]);
35
45
 
36
- // Get current the state of EditorInterface and other entities
37
- // related to this app installation
38
- const currentState = await this.props.sdk.app.getCurrentState();
46
+ useEffect(() => {
47
+ if (sdk) {
48
+ sdk.app.onConfigure(() => onConfigure());
49
+ }
50
+ }, [sdk, params]);
39
51
 
40
- return {
41
- // Parameters to be persisted as the app configuration.
42
- parameters: this.state.parameters,
43
- // In case you don't want to submit any update to app
44
- // locations, you can just pass the currentState as is
45
- targetState: currentState,
46
- };
47
- }
52
+ const handleSelectItem = (event) => {
53
+ const {
54
+ checked,
55
+ value,
56
+ } = event.target;
57
+
58
+ let newValue = params?.usersWithTranslation || [];
59
+ if (checked) {
60
+ newValue = [...newValue, value];
61
+ } else {
62
+ newValue = newValue.filter((email) => email !== value);
63
+ }
48
64
 
49
- onFieldChanged(value, field) {
50
- this.setState({
51
- parameters: {
52
- ...this.state.parameters,
53
- [field]: value,
54
- },
65
+ setParams({
66
+ ...params,
67
+ usersWithTranslation: newValue,
55
68
  });
56
- }
69
+ };
70
+
71
+
72
+ return (
73
+ <Workbench className={css({
74
+ padding: '80px',
75
+ backgroundColor: "#FFF",
76
+ })}>
77
+ <Form>
78
+ <Heading>Configuration</Heading>
57
79
 
58
- render() {
59
- return (
60
- <Workbench className={css({
61
- padding: '80px',
62
- backgroundColor: "#FFF",
63
- })}>
64
- <Form>
65
- <Heading>Configuration</Heading>
66
- <TextField
67
- value={this.state.parameters.cloudinaryApiKey}
68
- onChange={e => this.onFieldChanged(e.target.value, "cloudinaryApiKey")}
69
- labelText="Cloudinary API Key"
70
- required
71
- />
72
- <TextField
73
- value={this.state.parameters.cloudinaryCloudName}
74
- onChange={e => this.onFieldChanged(e.target.value, "cloudinaryCloudName")}
75
- labelText="Cloudinary Cloud Name"
76
- required
77
- />
78
- </Form>
79
- </Workbench>
80
- );
81
- }
80
+ <FormControl>
81
+ <FormControl.Label>Benutzer mit Übersetzung im Editor</FormControl.Label>
82
+ <Multiselect
83
+ currentSelection={params.usersWithTranslation}
84
+ popoverProps={{isFullWidth: true}}
85
+ >
86
+ {spaceUsers.map((userEmail) => {
87
+ const val = userEmail.toLowerCase().replace(/\s/g, '-');
88
+ return (
89
+ <Multiselect.Option
90
+ key={`user-${val}}`}
91
+ itemId={val}
92
+ value={userEmail}
93
+ label={userEmail}
94
+ onSelectItem={handleSelectItem}
95
+ isChecked={params.usersWithTranslation?.includes(userEmail)}
96
+ />
97
+ );
98
+ })}
99
+ </Multiselect>
100
+ </FormControl>
101
+ <TextField
102
+ value={params.translationService}
103
+ onChange={e => onFieldChanged(e.target.value, "translationService")}
104
+ labelText="Translation Service URL"
105
+ required
106
+ />
107
+ </Form>
108
+ </Workbench>
109
+ );
110
+ };
82
111
 
83
- }
112
+ export default Config;
@@ -22,6 +22,7 @@ const EditorField = ({
22
22
  sdk,
23
23
  portal,
24
24
  locale,
25
+ setLocale,
25
26
  onStorybookElementClick,
26
27
  elementPropsMap,
27
28
  activeConfig,
@@ -151,6 +152,8 @@ const EditorField = ({
151
152
  <BlockEditor
152
153
  onChange={onChange}
153
154
  value={validateValue(value)}
155
+ locale={locale}
156
+ setLocale={setLocale}
154
157
  contentfulSdk={sdk}
155
158
  config={JSON.parse("{}")}
156
159
  elementPropsMap={elementPropsMap}
@@ -37,6 +37,7 @@ const Entry = ({
37
37
  fieldSdk={fieldSdk}
38
38
  editorSdk={sdk.editor}
39
39
  locale={locale}
40
+ setLocale={setLocale}
40
41
  elementPropsMap={elementPropsMap}
41
42
  entrySdk={sdk.entry}
42
43
  appSdk={sdk.app}