@vonaffenfels/slate-editor 1.1.34 → 1.1.37

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.34",
3
+ "version": "1.1.37",
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": "1e3ea5ff0c721c70b372b3507f1c2ee1f4ff270c",
75
+ "gitHead": "23bd1926bceee0ce73a5d25f021c544ead009f77",
76
76
  "publishConfig": {
77
77
  "access": "public"
78
78
  }
@@ -28,6 +28,7 @@
28
28
 
29
29
  input[type="text"],
30
30
  input[type="time"],
31
+ input[type="date"],
31
32
  input[type="number"],
32
33
  input[type="color"],
33
34
  input[type="datetime-local"],
@@ -144,6 +144,9 @@ const StorybookNodeComponent = ({
144
144
  title="Klicken, um das Element zu konfigurieren"
145
145
  onClick={onEditClick}>
146
146
  <div className="absolute right-0 top-0 m-2">
147
+ <span className="mr-2">
148
+ {[element?.attributes?.visibleFromDate, element?.attributes?.visibleToDate].filter(Boolean).map((date) => new Date(date).toLocaleString?.()).join(" - ")}
149
+ </span>
147
150
  <FontAwesomeIcon
148
151
  icon={faDesktop}
149
152
  color={element?.attributes?.hideOnDesktop ? "lightgray" : "black"}
@@ -36,6 +36,16 @@ export const StorybookDisplay = (props) => {
36
36
  };
37
37
  }, [elRef.current]);
38
38
 
39
+ let currentDate = new Date();
40
+
41
+ if (!isEditor && element?.attributes?.visibleFromDate && new Date(element?.attributes?.visibleFromDate) > currentDate) {
42
+ return;
43
+ }
44
+
45
+ if (!isEditor && element?.attributes?.visibleToDate && new Date(element?.attributes?.visibleToDate) < currentDate) {
46
+ return;
47
+ }
48
+
39
49
  if (element.isEmpty || !element.block) {
40
50
  return <EmptyBlock {...element.attributes} />;
41
51
  }
@@ -0,0 +1,55 @@
1
+ import classNames from "classnames";
2
+
3
+ export const DateTime = ({
4
+ value,
5
+ onChange,
6
+ className,
7
+ inline,
8
+ ...props
9
+ }) => {
10
+ // Separate date and time values
11
+ const dateValue = value ? value.split("T")[0] : "";
12
+ const timeValue = value ? value.split("T")[1] : "";
13
+
14
+ // Handle changes for date and time inputs
15
+ const handleDateChange = (e) => {
16
+ const newDate = e.target.value;
17
+ const newDateTime = `${newDate}T${timeValue || "00:00"}`;
18
+ onChange(newDateTime);
19
+ };
20
+
21
+ const handleTimeChange = (e) => {
22
+ const newTime = e.target.value;
23
+ const newDateTime = `${dateValue || "1970-01-01"}T${newTime}`;
24
+ onChange(newDateTime);
25
+ };
26
+
27
+ return (
28
+ <div className={classNames(className, "grid gap-2", {
29
+ "grid-cols-2": inline,
30
+ "grid-cols-1": !inline,
31
+ })}>
32
+ {/* Date input */}
33
+ <input
34
+ type="date"
35
+ className="w-full"
36
+ value={dateValue}
37
+ onChange={handleDateChange}
38
+ {...props}
39
+ />
40
+
41
+ {/* Time input */}
42
+ <input
43
+ type="time"
44
+ className="w-full"
45
+ value={timeValue}
46
+ onChange={handleTimeChange}
47
+ {...props}
48
+ />
49
+
50
+ {!!value && (
51
+ <button className="button button--tertiary" onClick={() => onChange(undefined)}>Zurücksetzen</button>
52
+ )}
53
+ </div>
54
+ );
55
+ };
@@ -9,6 +9,7 @@ import {
9
9
  CollapsableMenu, CollapsableMenuItem,
10
10
  } from "./CollapsableMenu/CollapsableMenu";
11
11
  import {Switch} from "./SidebarEditor/Fields/Switch";
12
+ import {DateTime} from "./SidebarEditor/Fields/DateTime";
12
13
 
13
14
  const SidebarEditor = ({
14
15
  sdk,
@@ -270,6 +271,56 @@ const SidebarEditor = ({
270
271
  );
271
272
  };
272
273
 
274
+ const handleInfoClick = () => {
275
+ let message = "";
276
+
277
+ if (!story?.argTypes || !storybookElement) {
278
+ return;
279
+ }
280
+
281
+ Object.keys(story.argTypes).forEach((key, index) => {
282
+ const argType = story.argTypes[key];
283
+ const attribute = storybookElement.attributes?.[key];
284
+
285
+ if (!argType || attribute === undefined || attribute === "") {
286
+ return;
287
+ }
288
+
289
+ if (index !== 0) {
290
+ message += " | ";
291
+ }
292
+
293
+ if (Array.isArray(attribute)) {
294
+ message += `${argType.name}: ${attribute.length} Elemente`;
295
+ return;
296
+ }
297
+
298
+ switch (typeof attribute) {
299
+ case "boolean":
300
+ message += `${argType.name}: ${attribute ? "Ja" : "Nein"}`;
301
+ break;
302
+ case "number":
303
+ message += `${argType.name}: ${attribute}`;
304
+ break;
305
+ case "object":
306
+ message += `${argType.name}: ${JSON.stringify(attribute, null, 2)}`;
307
+ break;
308
+ default:
309
+ message += `${argType.name}: "${attribute}"`;
310
+ }
311
+ });
312
+
313
+ sdk.dialogs
314
+ .openAlert({
315
+ title: 'Info',
316
+ message: message || 'Keine Informationen verfügbar',
317
+ confirmLabel: "Schließen",
318
+ })
319
+ .then((result) => {
320
+ // `result` is always `true`, can be skipped
321
+ });
322
+ };
323
+
273
324
  return (
274
325
  <div id="sidebar-editor-wrapper">
275
326
  <div id="sidebar-editor">
@@ -327,8 +378,9 @@ const SidebarEditor = ({
327
378
  hinzufügen</CollapsableMenuItem>
328
379
  <CollapsableMenuItem onClick={() => onInsert("below")}>Danach
329
380
  hinzufügen</CollapsableMenuItem>
381
+ <CollapsableMenuItem onClick={handleInfoClick}>Info</CollapsableMenuItem>
330
382
  <div className="px-4 pb-2 pt-1">
331
- <b className="mb-1 block text-sm">Sichtbar auf:</b>
383
+ <b className="mb-1 block text-sm">Sichtbarkeit</b>
332
384
  <Switch
333
385
  value={!storybookElement.attributes.hideOnDesktop}
334
386
  label="Desktop"
@@ -344,6 +396,10 @@ const SidebarEditor = ({
344
396
  label="Smartphone"
345
397
  className="mb-2"
346
398
  onClick={() => handleFieldValueChange("hideOnSmartphone", !storybookElement.attributes.hideOnSmartphone)}/>
399
+ <label className="mb-1 block">Sichtbar von</label>
400
+ <DateTime className="mb-2" value={storybookElement.attributes.visibleFromDate} onChange={v => handleFieldValueChange("visibleFromDate", v)} />
401
+ <label className="mb-1 block">Sichtbar bis</label>
402
+ <DateTime className="mb-2" value={storybookElement.attributes.visibleToDate} onChange={v => handleFieldValueChange("visibleToDate", v)} />
347
403
  </div>
348
404
  </CollapsableMenu>
349
405
  </div>