@vonaffenfels/contentful-slate-editor 1.2.38 → 1.2.41

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.
@@ -1,51 +1,51 @@
1
- import React, {
2
- useEffect, useState,
3
- } from 'react';
4
- import EditorField from "./EditorField";
5
-
6
- const Entry = ({
7
- sdk,
8
- onStorybookElementClick,
9
- elementPropsMap,
10
- activeConfig,
11
- }) => {
12
- const field = sdk.parameters.instance.contentField;
13
- const fieldSdk = sdk.entry.fields[field];
14
-
15
- const [locale, setLocale] = useState(sdk.locales.default);
16
- const [portal, setPortal] = useState();
17
- const portalField = sdk?.entry?.fields?.portal;
18
-
19
- portalField?.onValueChanged(() => {
20
- if (portalField.getValue() !== portal) {
21
- setPortal(portalField.getValue());
22
- }
23
- });
24
-
25
- useEffect(() => {
26
- const detachHandler = sdk.editor.onLocaleSettingsChanged((loc) => {
27
- setLocale(loc?.focused || sdk.locales.default);
28
- });
29
-
30
- return () => {
31
- detachHandler();
32
- };
33
- }, []);
34
-
35
- return <EditorField
36
- preview={false}
37
- fieldSdk={fieldSdk}
38
- editorSdk={sdk.editor}
39
- locale={locale}
40
- setLocale={setLocale}
41
- elementPropsMap={elementPropsMap}
42
- entrySdk={sdk.entry}
43
- appSdk={sdk.app}
44
- sdk={sdk}
45
- portal={portal}
46
- onStorybookElementClick={onStorybookElementClick}
47
- activeConfig={activeConfig}
48
- />;
49
- };
50
-
1
+ import React, {
2
+ useEffect, useState,
3
+ } from 'react';
4
+ import EditorField from "./EditorField";
5
+
6
+ const Entry = ({
7
+ sdk,
8
+ onStorybookElementClick,
9
+ elementPropsMap,
10
+ activeConfig,
11
+ }) => {
12
+ const field = sdk.parameters.instance.contentField;
13
+ const fieldSdk = sdk.entry.fields[field];
14
+
15
+ const [locale, setLocale] = useState(sdk.locales.default);
16
+ const [portal, setPortal] = useState();
17
+ const portalField = sdk?.entry?.fields?.portal;
18
+
19
+ portalField?.onValueChanged(() => {
20
+ if (portalField.getValue() !== portal) {
21
+ setPortal(portalField.getValue());
22
+ }
23
+ });
24
+
25
+ useEffect(() => {
26
+ const detachHandler = sdk.editor.onLocaleSettingsChanged((loc) => {
27
+ setLocale(loc?.focused || sdk.locales.default);
28
+ });
29
+
30
+ return () => {
31
+ detachHandler();
32
+ };
33
+ }, []);
34
+
35
+ return <EditorField
36
+ preview={false}
37
+ fieldSdk={fieldSdk}
38
+ editorSdk={sdk.editor}
39
+ locale={locale}
40
+ setLocale={setLocale}
41
+ elementPropsMap={elementPropsMap}
42
+ entrySdk={sdk.entry}
43
+ appSdk={sdk.app}
44
+ sdk={sdk}
45
+ portal={portal}
46
+ onStorybookElementClick={onStorybookElementClick}
47
+ activeConfig={activeConfig}
48
+ />;
49
+ };
50
+
51
51
  export default Entry;
@@ -1,72 +1,72 @@
1
- import React, {
2
- useEffect, useRef, useState,
3
- } from 'react';
4
- import Renderer from "@vonaffenfels/slate-editor/dist/Renderer";
5
- import componentLoader from "@vonaffenfels/slate-editor/componentLoader.js";
6
-
7
- const FIELD_HEIGHT = 300;
8
- let _interval;
9
-
10
- const Field = ({
11
- sdk,
12
- elementPropsMap,
13
- }) => {
14
- const [value, setValue] = useState(sdk.field.getValue());
15
- const wrapperRef = useRef();
16
-
17
- const openDialog = () => {
18
- sdk.dialogs.openCurrentApp({
19
- title: 'Inhalt bearbeiten',
20
- width: 'fullWidth',
21
- position: "center",
22
- allowHeightOverflow: true,
23
- shouldCloseOnOverlayClick: false,
24
- shouldCloseOnEscapePress: false,
25
- minHeight: 500,
26
- parameters: {
27
- value: sdk.field.getValue(),
28
- portal: sdk.entry.fields.portal.getValue(),
29
- contentType: sdk.entry.getSys().contentType.sys.id,
30
- },
31
- }).then((data) => {
32
- if (data) {
33
- sdk.field.setValue(data);
34
- }
35
- });
36
- };
37
-
38
- useEffect(() => {
39
- sdk.window.updateHeight(FIELD_HEIGHT);
40
- sdk.field.onValueChanged(handleValueChanged);
41
- }, []);
42
-
43
- const handleValueChanged = value => {
44
- setValue(value);
45
-
46
- clearInterval(_interval);
47
- _interval = setInterval(() => {
48
- if (wrapperRef.current) {
49
- sdk.window.updateHeight(wrapperRef.current.clientHeight);
50
- }
51
- }, 500);
52
- };
53
-
54
- return <div
55
- ref={wrapperRef}
56
- >
57
- <button onClick={openDialog} className="button mb-2 w-full">Inhalt bearbeiten</button>
58
- <div style={{
59
- overflowY: "auto",
60
- maxHeight: "500px",
61
- }}>
62
- <Renderer
63
- value={value}
64
- elementPropsMap={elementPropsMap}
65
- storybookComponentLoader={(block) => {
66
- return componentLoader(block);
67
- }}/>
68
- </div>
69
- </div>;
70
- };
71
-
1
+ import React, {
2
+ useEffect, useRef, useState,
3
+ } from 'react';
4
+ import Renderer from "@vonaffenfels/slate-editor/dist/Renderer";
5
+ import componentLoader from "@vonaffenfels/slate-editor/componentLoader.js";
6
+
7
+ const FIELD_HEIGHT = 300;
8
+ let _interval;
9
+
10
+ const Field = ({
11
+ sdk,
12
+ elementPropsMap,
13
+ }) => {
14
+ const [value, setValue] = useState(sdk.field.getValue());
15
+ const wrapperRef = useRef();
16
+
17
+ const openDialog = () => {
18
+ sdk.dialogs.openCurrentApp({
19
+ title: 'Inhalt bearbeiten',
20
+ width: 'fullWidth',
21
+ position: "center",
22
+ allowHeightOverflow: true,
23
+ shouldCloseOnOverlayClick: false,
24
+ shouldCloseOnEscapePress: false,
25
+ minHeight: 500,
26
+ parameters: {
27
+ value: sdk.field.getValue(),
28
+ portal: sdk.entry.fields.portal.getValue(),
29
+ contentType: sdk.entry.getSys().contentType.sys.id,
30
+ },
31
+ }).then((data) => {
32
+ if (data) {
33
+ sdk.field.setValue(data);
34
+ }
35
+ });
36
+ };
37
+
38
+ useEffect(() => {
39
+ sdk.window.updateHeight(FIELD_HEIGHT);
40
+ sdk.field.onValueChanged(handleValueChanged);
41
+ }, []);
42
+
43
+ const handleValueChanged = value => {
44
+ setValue(value);
45
+
46
+ clearInterval(_interval);
47
+ _interval = setInterval(() => {
48
+ if (wrapperRef.current) {
49
+ sdk.window.updateHeight(wrapperRef.current.clientHeight);
50
+ }
51
+ }, 500);
52
+ };
53
+
54
+ return <div
55
+ ref={wrapperRef}
56
+ >
57
+ <button onClick={openDialog} className="button mb-2 w-full">Inhalt bearbeiten</button>
58
+ <div style={{
59
+ overflowY: "auto",
60
+ maxHeight: "500px",
61
+ }}>
62
+ <Renderer
63
+ value={value}
64
+ elementPropsMap={elementPropsMap}
65
+ storybookComponentLoader={(block) => {
66
+ return componentLoader(block);
67
+ }}/>
68
+ </div>
69
+ </div>;
70
+ };
71
+
72
72
  export default Field;
@@ -1,93 +1,93 @@
1
- import {Button} from "@contentful/f36-components";
2
- import React, {
3
- useEffect, useState,
4
- } from "react";
5
-
6
- export const Sidebar = ({
7
- sdk,
8
- activeConfig,
9
- }) => {
10
- return <div className="flex w-full flex-col gap-2">
11
- <div className="w-full">
12
- <OpenProdPageLink sdk={sdk} activeConfig={activeConfig}/>
13
- </div>
14
- <div className="w-full">
15
- <SidebarTranslations sdk={sdk}/>
16
- </div>
17
- </div>;
18
- };
19
-
20
- const OpenProdPageLink = ({
21
- activeConfig,
22
- sdk,
23
- }) => {
24
- const [slug, setSlug] = useState(sdk?.entry?.fields?.slug?.getValue());
25
- const [locale, setLocale] = useState(sdk.locales.default);
26
-
27
- useEffect(() => {
28
- const detachHandler = sdk.editor.onLocaleSettingsChanged((loc) => {
29
- setLocale(loc?.focused || sdk.locales.default);
30
- });
31
-
32
- return () => {
33
- detachHandler();
34
- };
35
- }, [sdk]);
36
-
37
- useEffect(() => {
38
- if (locale) {
39
- setSlug(sdk?.entry?.fields?.slug?.getForLocale(locale).getValue());
40
- }
41
- }, [locale]);
42
-
43
- useEffect(() => {
44
- if (sdk?.entry?.fields?.slug) {
45
- return sdk.entry.fields.slug.onValueChanged(setSlug);
46
- }
47
- }, [sdk]);
48
-
49
- const disabled = !activeConfig?.domain || !slug;
50
- let link = `${activeConfig.domain}/${slug}`;
51
-
52
- if (sdk?.locales?.default !== locale) {
53
- link = `${activeConfig.domain}/${locale}/${slug}`;
54
- }
55
-
56
- const onClick = () => {
57
- if (disabled) {
58
- return;
59
- }
60
-
61
- window.open(link, "_blank");
62
- };
63
-
64
- return <Button isDisabled={disabled} isFullWidth={true} variant="secondary" onClick={onClick}>Live-Seite öffnen</Button>;
65
- };
66
-
67
- const SidebarTranslations = ({sdk}) => {
68
- const enabled = sdk?.parameters?.installation?.usersWithTranslation?.includes(sdk?.user?.email) && sdk?.parameters?.installation?.translationService;
69
-
70
- if (!enabled) {
71
- return null;
72
- }
73
-
74
- const onClick = () => {
75
- sdk.dialogs.openCurrentApp({
76
- title: 'Übersetzen',
77
- width: 'fullWidth',
78
- position: "center",
79
- allowHeightOverflow: true,
80
- shouldCloseOnOverlayClick: false,
81
- shouldCloseOnEscapePress: false,
82
- minHeight: 500,
83
- parameters: {
84
- type: "translation",
85
- entryId: sdk.entry.getSys().id,
86
- },
87
- });
88
- };
89
-
90
- return <>
91
- <Button isFullWidth={true} onClick={onClick}>Übersetzen</Button>
92
- </>;
1
+ import {Button} from "@contentful/f36-components";
2
+ import React, {
3
+ useEffect, useState,
4
+ } from "react";
5
+
6
+ export const Sidebar = ({
7
+ sdk,
8
+ activeConfig,
9
+ }) => {
10
+ return <div className="flex w-full flex-col gap-2">
11
+ <div className="w-full">
12
+ <OpenProdPageLink sdk={sdk} activeConfig={activeConfig}/>
13
+ </div>
14
+ <div className="w-full">
15
+ <SidebarTranslations sdk={sdk}/>
16
+ </div>
17
+ </div>;
18
+ };
19
+
20
+ const OpenProdPageLink = ({
21
+ activeConfig,
22
+ sdk,
23
+ }) => {
24
+ const [slug, setSlug] = useState(sdk?.entry?.fields?.slug?.getValue());
25
+ const [locale, setLocale] = useState(sdk.locales.default);
26
+
27
+ useEffect(() => {
28
+ const detachHandler = sdk.editor.onLocaleSettingsChanged((loc) => {
29
+ setLocale(loc?.focused || sdk.locales.default);
30
+ });
31
+
32
+ return () => {
33
+ detachHandler();
34
+ };
35
+ }, [sdk]);
36
+
37
+ useEffect(() => {
38
+ if (locale) {
39
+ setSlug(sdk?.entry?.fields?.slug?.getForLocale(locale).getValue());
40
+ }
41
+ }, [locale]);
42
+
43
+ useEffect(() => {
44
+ if (sdk?.entry?.fields?.slug) {
45
+ return sdk.entry.fields.slug.onValueChanged(setSlug);
46
+ }
47
+ }, [sdk]);
48
+
49
+ const disabled = !activeConfig?.domain || !slug;
50
+ let link = `${activeConfig.domain}/${slug}`;
51
+
52
+ if (sdk?.locales?.default !== locale) {
53
+ link = `${activeConfig.domain}/${locale}/${slug}`;
54
+ }
55
+
56
+ const onClick = () => {
57
+ if (disabled) {
58
+ return;
59
+ }
60
+
61
+ window.open(link, "_blank");
62
+ };
63
+
64
+ return <Button isDisabled={disabled} isFullWidth={true} variant="secondary" onClick={onClick}>Live-Seite öffnen</Button>;
65
+ };
66
+
67
+ const SidebarTranslations = ({sdk}) => {
68
+ const enabled = sdk?.parameters?.installation?.usersWithTranslation?.includes(sdk?.user?.email) && sdk?.parameters?.installation?.translationService;
69
+
70
+ if (!enabled) {
71
+ return null;
72
+ }
73
+
74
+ const onClick = () => {
75
+ sdk.dialogs.openCurrentApp({
76
+ title: 'Übersetzen',
77
+ width: 'fullWidth',
78
+ position: "center",
79
+ allowHeightOverflow: true,
80
+ shouldCloseOnOverlayClick: false,
81
+ shouldCloseOnEscapePress: false,
82
+ minHeight: 500,
83
+ parameters: {
84
+ type: "translation",
85
+ entryId: sdk.entry.getSys().id,
86
+ },
87
+ });
88
+ };
89
+
90
+ return <>
91
+ <Button isFullWidth={true} onClick={onClick}>Übersetzen</Button>
92
+ </>;
93
93
  };
package/src/dev.js CHANGED
@@ -1,5 +1,5 @@
1
- import './scss/index.scss';
2
- import './scss/dev.scss';
3
- import {BaseContentfulApp} from "./index"
4
-
1
+ import './scss/index.scss';
2
+ import './scss/dev.scss';
3
+ import {BaseContentfulApp} from "./index"
4
+
5
5
  BaseContentfulApp();
@@ -1,24 +1,24 @@
1
- import React, {
2
- useState, useEffect, useRef,
3
- } from "react";
4
-
5
- export default function useOnScreen(ref) {
6
- const [isIntersecting, setIntersecting] = useState(false);
7
- const observerRef = useRef();
8
-
9
- useEffect(() => {
10
- if (!observerRef.current && ref.current) {
11
- observerRef.current = new IntersectionObserver(([entry]) => setIntersecting(entry.isIntersecting));
12
-
13
- observerRef.current.observe(ref.current);
14
-
15
- return () => {
16
- if (observerRef.current) {
17
- observerRef.current.disconnect();
18
- }
19
- };
20
- }
21
- }, []);
22
-
23
- return isIntersecting;
1
+ import React, {
2
+ useState, useEffect, useRef,
3
+ } from "react";
4
+
5
+ export default function useOnScreen(ref) {
6
+ const [isIntersecting, setIntersecting] = useState(false);
7
+ const observerRef = useRef();
8
+
9
+ useEffect(() => {
10
+ if (!observerRef.current && ref.current) {
11
+ observerRef.current = new IntersectionObserver(([entry]) => setIntersecting(entry.isIntersecting));
12
+
13
+ observerRef.current.observe(ref.current);
14
+
15
+ return () => {
16
+ if (observerRef.current) {
17
+ observerRef.current.disconnect();
18
+ }
19
+ };
20
+ }
21
+ }, []);
22
+
23
+ return isIntersecting;
24
24
  }
package/src/index.html CHANGED
@@ -1,12 +1,12 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8"/>
5
- <title>Slate Block Editor Contentful App</title>
6
- <script src="https://media-library.cloudinary.com/global/all.js"></script>
7
- </head>
8
- <body>
9
- <div id="root">
10
- </div>
11
- </body>
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <title>Slate Block Editor Contentful App</title>
6
+ <script src="https://media-library.cloudinary.com/global/all.js"></script>
7
+ </head>
8
+ <body>
9
+ <div id="root">
10
+ </div>
11
+ </body>
12
12
  </html>