@vonaffenfels/slate-editor 1.1.29 → 1.1.31

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/slate-editor",
3
- "version": "1.1.29",
3
+ "version": "1.1.31",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -72,7 +72,7 @@
72
72
  "cssnano": "^5.0.1",
73
73
  "escape-html": "^1.0.3"
74
74
  },
75
- "gitHead": "6f766a57107e33b358372874a69e2199dc14d8f6",
75
+ "gitHead": "29092565a5ae7277e00d388bf0daabb0b51cda3d",
76
76
  "publishConfig": {
77
77
  "access": "public"
78
78
  }
@@ -0,0 +1,90 @@
1
+ import {Asset} from "@contentful/forma-36-react-components";
2
+ import {AssetList} from "../AssetList";
3
+
4
+ export const CloudinaryContentSelect = ({
5
+ value,
6
+ onChange,
7
+ multiple,
8
+ sdk,
9
+ }) => {
10
+ if (multiple) {
11
+ return (
12
+ <>
13
+ {value && value.length > 0 && (
14
+ <details className="mb-2">
15
+ <summary>{value.length || 0} {value.length === 1 ? "Element" : "Elemente"}</summary>
16
+ <div className="mt-4">
17
+ <AssetList
18
+ cloudinary
19
+ assets={value}
20
+ sdk={sdk}
21
+ onChange={onChange}
22
+ onAddClick={() => {
23
+ sdk.dialogs.openCurrentApp({
24
+ width: "fullWidth",
25
+ title: "Select Images",
26
+ shouldCloseOnOverlayClick: true,
27
+ shouldCloseOnEscapePress: true,
28
+ parameters: {
29
+ type: "cloudinary",
30
+ multiple: true,
31
+ portal: sdk?.entry?.fields?.portal?.getValue(),
32
+ },
33
+ }).then((data) => {
34
+ onChange([...value, ...(data?.assets || [])]);
35
+ });
36
+ }}/>
37
+ </div>
38
+ </details>
39
+ )}
40
+ <button
41
+ className="button"
42
+ onClick={() => {
43
+ sdk.dialogs.openCurrentApp({
44
+ width: "fullWidth",
45
+ title: "Select Images",
46
+ shouldCloseOnOverlayClick: true,
47
+ shouldCloseOnEscapePress: true,
48
+ parameters: {
49
+ type: "cloudinary",
50
+ multiple: true,
51
+ portal: sdk?.entry?.fields?.portal?.getValue(),
52
+ },
53
+ }).then((data) => {
54
+ onChange(data?.assets);
55
+ });
56
+ }}
57
+ >Auswählen
58
+ </button>
59
+ </>
60
+ );
61
+ }
62
+
63
+ return (
64
+ <>
65
+ {!!value && <div className="mb-2"><Asset
66
+ cloudinary
67
+ sdk={sdk}
68
+ asset={value}
69
+ onDeleteClick={() => onChange(null)}/></div>}
70
+ <button
71
+ className="button"
72
+ onClick={() => {
73
+ sdk.dialogs.openCurrentApp({
74
+ width: "fullWidth",
75
+ title: "Select Image",
76
+ shouldCloseOnOverlayClick: true,
77
+ shouldCloseOnEscapePress: true,
78
+ parameters: {
79
+ type: "cloudinary",
80
+ portal: sdk?.entry?.fields?.portal?.getValue(),
81
+ },
82
+ }).then((data) => {
83
+ onChange(data?.assets?.[0]);
84
+ });
85
+ }}
86
+ >Auswählen
87
+ </button>
88
+ </>
89
+ );
90
+ };
@@ -0,0 +1,90 @@
1
+ import {
2
+ useEffect, useState,
3
+ } from "react";
4
+
5
+ export const ColorPicker = ({
6
+ value,
7
+ onChange,
8
+ }) => {
9
+ const [opacity, setOpacity] = useState(1);
10
+ const [color, setColor] = useState(null);
11
+
12
+ const handleChange = (e) => {
13
+ setColor(e.target.value);
14
+
15
+ let c = e.target.value;
16
+
17
+ var rgbaCol = 'rgba(' + parseInt(c.slice(-6, -4), 16) + ',' + parseInt(c.slice(-4, -2), 16) + ',' + parseInt(c.slice(-2), 16) + ',' + opacity + ')';
18
+
19
+ onChange(rgbaCol);
20
+ };
21
+
22
+ useEffect(() => {
23
+ if (!color) {
24
+ return;
25
+ }
26
+
27
+ var rgbaCol = 'rgba(' + parseInt(color.slice(-6, -4), 16) + ',' + parseInt(color.slice(-4, -2), 16) + ',' + parseInt(color.slice(-2), 16) + ',' + opacity + ')';
28
+
29
+ onChange(rgbaCol);
30
+ }, [opacity]);
31
+
32
+ useEffect(() => {
33
+ if (!value) {
34
+ setColor("#000000");
35
+ setOpacity(1);
36
+
37
+ return;
38
+ }
39
+
40
+ if (value?.startsWith("rgba")) {
41
+ const color = parseColor(value);
42
+
43
+ setColor(convertColorToHex(value));
44
+ setOpacity(color.a);
45
+ } else {
46
+ setColor(value);
47
+ }
48
+ }, [value]);
49
+
50
+ return (
51
+ <div className="flex flex-col">
52
+ <input
53
+ type="color"
54
+ value={color || ""}
55
+ className="mb-1"
56
+ onChange={handleChange}/>
57
+ <input type="range" min="0" max="1" step="0.1" value={opacity} onChange={e => setOpacity(e.target.value)} />
58
+ {!!value && (
59
+ <button className="button button--tertiary mt-1" onClick={() => onChange(undefined)}>Zurücksetzen</button>
60
+ )}
61
+ </div>
62
+ );
63
+ };
64
+
65
+ function convertColorToHex(inputColor) {
66
+ function rgbToHex(r, g, b) {
67
+ return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
68
+ }
69
+
70
+ // Parse the input color value
71
+ let color;
72
+ if (inputColor.startsWith("#")) {
73
+ color = inputColor; // Already in HEX format
74
+ } else if (inputColor.startsWith("rgb")) {
75
+ color = parseColor(inputColor); // Convert to HEX format
76
+ }
77
+
78
+ return rgbToHex(color.r, color.g, color.b);
79
+ }
80
+
81
+ const parseColor = (inputColor) => {
82
+ let values = inputColor.match(/[\d.]+/g);
83
+
84
+ return {
85
+ r: parseInt(values[0]),
86
+ g: parseInt(values[1]),
87
+ b: parseInt(values[2]),
88
+ a: values[3] ? parseFloat(values[3]) : undefined,
89
+ };
90
+ };
@@ -0,0 +1,62 @@
1
+ import {Asset} from "@contentful/forma-36-react-components";
2
+ import {AssetList} from "../AssetList";
3
+ import {reduceContentfulResponse} from "../../util/reduceContentfulResponse";
4
+
5
+ export const ContentfulContentSelect = ({
6
+ value,
7
+ onChange,
8
+ sdk,
9
+ multiple,
10
+ field,
11
+ }) => {
12
+ if (multiple) {
13
+ return (
14
+ <>
15
+ {value && value.length > 0 && (
16
+ <details className="mb-2">
17
+ <summary>{value.length || 0} {value.length === 1 ? "Element" : "Elemente"}</summary>
18
+ <div className="mt-4">
19
+ <AssetList
20
+ assets={value}
21
+ sdk={sdk}
22
+ onChange={onChange}
23
+ onAddClick={() => {
24
+ sdk.dialogs.selectMultipleEntries({contentTypes: field.control.contentTypes}).then(contents => {
25
+ onChange(reduceContentfulResponse([...value, ...contents], field.control.paths));
26
+ });
27
+ }}/>
28
+ </div>
29
+ </details>
30
+ )}
31
+ <button
32
+ className="button"
33
+ onClick={() => {
34
+ sdk.dialogs.selectMultipleEntries({contentTypes: field.control.contentTypes}).then(contents => {
35
+ onChange(reduceContentfulResponse(contents, field.control.paths));
36
+ });
37
+ }}
38
+ >Auswählen
39
+ </button>
40
+ </>
41
+ );
42
+ }
43
+
44
+ return (
45
+ <>
46
+ {!!value && <div className="mb-2"><Asset
47
+ sdk={sdk}
48
+ asset={value}
49
+ onDeleteClick={() => onChange(null)}
50
+ onChange={onChange}/></div>}
51
+ <button
52
+ className="button"
53
+ onClick={() => {
54
+ sdk.dialogs.selectSingleEntry({contentTypes: field.control.contentTypes}).then(content => {
55
+ onChange(reduceContentfulResponse(content, field.control.paths));
56
+ });
57
+ }}
58
+ >Auswählen
59
+ </button>
60
+ </>
61
+ );
62
+ };
@@ -0,0 +1,68 @@
1
+ import {IconButton} from "../../SidebarEditor";
2
+ import {SidebarEditorField} from "../SidebarEditorField";
3
+
4
+ export const MVP = ({
5
+ value,
6
+ onChange,
7
+ onMove,
8
+ onDelete,
9
+ field,
10
+ fieldKey,
11
+ storybookElement,
12
+ sdk,
13
+ }) => {
14
+ return (
15
+ <details>
16
+ <summary>{value?.length || 0} {value?.length === 1 ? "Element" : "Elemente"}</summary>
17
+ <div className="mt-4">
18
+ {value?.map((f, index) => {
19
+ return (
20
+ <div className="mb-4" key={`mvp-${index}`}>
21
+ <div className="mb-2 flex items-center">
22
+ <b className="grow">{field.name} [{index.toString()}]</b>
23
+ <div className="icon-button-group mr-1">
24
+ <IconButton
25
+ size="small"
26
+ onClick={() => onMove("up", index)}
27
+ disabled={index === 0}>↑</IconButton>
28
+ <IconButton
29
+ size="small"
30
+ onClick={() => onMove("down", index)}
31
+ disabled={index === value?.length - 1}>↓</IconButton>
32
+ </div>
33
+ <IconButton
34
+ size="small"
35
+ onClick={() => onDelete(index)}>🗑</IconButton>
36
+ </div>
37
+ {Object.keys(field.control.fields).map((key) => {
38
+ let mvpField = field.control.fields[key];
39
+
40
+ value = value?.[index]?.[key];
41
+
42
+ return (
43
+ <div key={`mvp-field-${key}`}>
44
+ <SidebarEditorField
45
+ field={mvpField}
46
+ fieldKey={fieldKey}
47
+ value={value}
48
+ storybookElement={storybookElement}
49
+ sdk={sdk}
50
+ onChange={(fK, value) => onChange(
51
+ fK, value, key, index,
52
+ )}/>
53
+ </div>
54
+ );
55
+ })}
56
+ <hr className="my-4" style={{borderColor: "rgb(174, 193, 204)"}}/>
57
+ </div>
58
+ );
59
+ })}
60
+ <button
61
+ className="button button--secondary"
62
+ onClick={() => onChange(fieldKey, [...(value || []), {}])}>Neue
63
+ Zeile
64
+ </button>
65
+ </div>
66
+ </details>
67
+ );
68
+ };
@@ -0,0 +1,16 @@
1
+ export const StreamSelect = ({
2
+ value,
3
+ onChange,
4
+ field,
5
+ }) => {
6
+ return (
7
+ <select
8
+ value={value || ""}
9
+ onChange={onChange}>
10
+ <option value="">Auswählen</option>
11
+ {(field?.control?.streams || []).map(stream => (
12
+ <option key={`select-option-${stream.value}`} value={`$$_STREAM__${stream.value}__`}>{stream.label}</option>
13
+ ))}
14
+ </select>
15
+ );
16
+ };
@@ -0,0 +1,22 @@
1
+ export const Textarea = ({
2
+ value,
3
+ onChange,
4
+ }) => {
5
+ return (
6
+ <textarea
7
+ value={typeof value === "object" ? JSON.stringify(value, null, 2) || "" : value}
8
+ onChange={e => {
9
+ onChange(e);
10
+
11
+ e.target.style.height = "5px";
12
+ e.target.style.height = e.target.scrollHeight + 2 + "px";
13
+ }}
14
+ onBlur={(e) => {
15
+ e.target.style.height = "42px";
16
+ }}
17
+ onFocus={e => {
18
+ e.target.style.height = "5px";
19
+ e.target.style.height = e.target.scrollHeight + 2 + "px";
20
+ }}/>
21
+ );
22
+ };