@vonaffenfels/slate-editor 1.1.11 → 1.1.13

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.11",
3
+ "version": "1.1.13",
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": "840a8741f2c0e62c54c4039a68a0e103c3041322",
75
+ "gitHead": "7ac51bec76cbf6f02661849c5836c874c4a1a3a6",
76
76
  "publishConfig": {
77
77
  "access": "public"
78
78
  }
@@ -5,6 +5,8 @@ import {Transforms} from "slate";
5
5
  import {ReactEditor} from "slate-react";
6
6
  import classNames from "classnames";
7
7
  import {ToolMargin} from "../Tools/Margin";
8
+ import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
9
+ import {faStickyNote} from "@fortawesome/free-solid-svg-icons";
8
10
 
9
11
  export const LayoutSlotContext = createContext({isInSlot: false});
10
12
 
@@ -28,6 +30,25 @@ export const LayoutSlot = ({
28
30
  }, {at: path});
29
31
  };
30
32
 
33
+ const switchSticky = () => {
34
+ let node = ReactEditor.toSlateNode(editor, attributes.ref.current);
35
+ let path = ReactEditor.findPath(editor, node);
36
+ let stickyTop = element?.attributes?.stickyTop;
37
+
38
+ if (!element.attributes.sticky) {
39
+ stickyTop = prompt("Abstand nach oben, wenn sticky", element?.attributes?.stickyTop || 0);
40
+ }
41
+
42
+ Transforms.setNodes(editor, {
43
+ type: "layout-slot",
44
+ attributes: {
45
+ ...(element.attributes || {}),
46
+ sticky: !element.attributes.sticky,
47
+ stickyTop: stickyTop || 0,
48
+ },
49
+ }, {at: path});
50
+ };
51
+
31
52
  return <div
32
53
  className={classNames({
33
54
  ["layout-slot layout-slot-" + element.attributes.name]: true,
@@ -51,10 +72,19 @@ export const LayoutSlot = ({
51
72
  {element.attributes.name}
52
73
  </span>
53
74
 
54
- <ToolMargin margin={element?.attributes?.margin} onChange={onMarginChange}/>
75
+ <div className="flex items-center">
76
+ {!element?.attributes?.sticky ? (
77
+ <FontAwesomeIcon icon={faStickyNote} color="#000000" size="md" className="mr-2 cursor-pointer" onClick={switchSticky} />
78
+ ) : (
79
+ <FontAwesomeIcon icon={faStickyNote} color="#3490f3" size="md" className="mr-2 cursor-pointer" onClick={switchSticky} />
80
+ )}
81
+ <ToolMargin margin={element?.attributes?.margin} onChange={onMarginChange}/>
82
+ </div>
55
83
  </div>
56
84
  <div className="layout-slot-content">
57
- {children}
85
+ <div className={classNames({"sticky top-[80px]": element?.attributes?.sticky})}>
86
+ {children}
87
+ </div>
58
88
  </div>
59
89
  </LayoutSlotContext.Provider>
60
90
  </div>;
@@ -177,8 +177,10 @@ export function Serializer({
177
177
  "md:ml-4": props.attributes?.margin?.left,
178
178
  })}
179
179
  >
180
- {props.children.map((v, i) => <Fragment
181
- key={"layout-slot-" + i}>{serializeNode(v, i, props.attributes.name)}</Fragment>)}
180
+ {props.children.map((v, i) => <div
181
+ key={"layout-slot-" + i}
182
+ style={{top: props.attributes?.sticky && "80px"}}
183
+ className={classNames({"sticky": props.attributes?.sticky})}>{serializeNode(v, i, props.attributes.name)}</div>)}
182
184
  </div>
183
185
  </Wrapper>;
184
186
  default: {
@@ -2,9 +2,8 @@ import ReactDOM from "react-dom";
2
2
  import React, {
3
3
  useEffect, useRef, useState,
4
4
  } from "react";
5
- import {
6
- ReactEditor, useSlate,
7
- } from "slate-react";
5
+ import {ReactEditor} from "slate-react";
6
+ import {Node} from "slate";
8
7
  import classNames from "classnames";
9
8
  // eslint-disable-next-line import/no-unresolved
10
9
  import "scss/toolbar.scss";
@@ -106,7 +105,24 @@ export const Toolbar = ({
106
105
  },
107
106
  };
108
107
 
109
- Transforms.insertNodes(editor, [element], {at: [lastSelection?.anchor?.path?.[0]]});
108
+ if (lastSelection?.anchor?.path?.length) {
109
+ lastSelection.anchor.path.forEach((p, i) => {
110
+ let slicedPath = lastSelection.anchor.path.slice(0, i + 1);
111
+ let node = Node.get(editor, slicedPath);
112
+
113
+ // Wenn Paragraph, dann auf die Ebene des Paragraphen
114
+ if (node.type === "paragraph") {
115
+ Transforms.insertNodes(editor, [element], {at: slicedPath});
116
+
117
+ return;
118
+ }
119
+
120
+ // Wenn vorletzter Anchor, dann einfügen (letzter ist column, keine row)
121
+ if (i === lastSelection.anchor.path.length - 2) {
122
+ Transforms.insertNodes(editor, [element], {at: slicedPath});
123
+ }
124
+ });
125
+ }
110
126
  };
111
127
 
112
128
  function renderMenu() {