@vonaffenfels/slate-editor 1.0.52 → 1.0.53

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.0.52",
3
+ "version": "1.0.53",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -71,7 +71,7 @@
71
71
  "cssnano": "^5.0.1",
72
72
  "escape-html": "^1.0.3"
73
73
  },
74
- "gitHead": "41eb9767f8c80645382c0d77eae03bcefaac6fe4",
74
+ "gitHead": "2dc913432ea48a4eaf107ff9c5f15b572eeda4d6",
75
75
  "publishConfig": {
76
76
  "access": "public"
77
77
  }
package/scss/editor.scss CHANGED
@@ -11,6 +11,12 @@
11
11
  max-width: 100%;
12
12
  width: 100%;
13
13
 
14
+ .slate-editor-element-selected {
15
+ .storybook-element-component {
16
+ outline: 2px dashed #61a2e9;
17
+ }
18
+ }
19
+
14
20
  &.storybook-active {
15
21
  .slate-editor {
16
22
  display: none;
@@ -416,18 +422,20 @@
416
422
  .resizable-left {
417
423
  position: relative;
418
424
  }
425
+
419
426
  .resizable-right {
420
427
  position: relative;
421
428
  }
429
+
422
430
  .resizable-x-handle {
423
- cursor: ew-resize;
424
- content: "";
425
- position: absolute;
426
- height: 100%;
427
- width: 10px;
428
- text-align: center;
429
- top: 0;
430
- left: -2px;
431
- background-color: transparent;
431
+ cursor: ew-resize;
432
+ content: "";
433
+ position: absolute;
434
+ height: 100%;
435
+ width: 10px;
436
+ text-align: center;
437
+ top: 0;
438
+ left: -2px;
439
+ background-color: transparent;
432
440
  }
433
441
  }
@@ -9,7 +9,7 @@
9
9
  z-index: 10;
10
10
  background-color: rgba(255, 255, 255, 0.7);
11
11
  color: black;
12
- font-size: 2em;
12
+ font-size: 1em;
13
13
  align-items: center;
14
14
  justify-content: center;
15
15
  content-visibility: auto;
@@ -131,4 +131,10 @@
131
131
  min-height: 100px;
132
132
  min-width: 100px;
133
133
  }
134
+ }
135
+
136
+ @container (min-width: 100px) {
137
+ .storybook-element-component-overlay {
138
+ font-size: 2em;
139
+ }
134
140
  }
@@ -45,6 +45,15 @@ export default function BlockEditor({
45
45
  let node = ReactEditor.toSlateNode(editor, attributes.ref.current);
46
46
  let path = ReactEditor.findPath(editor, node);
47
47
 
48
+ document.querySelectorAll(".slate-editor-element-selected").forEach(el => {
49
+ el.classList.remove("slate-editor-element-selected");
50
+ });
51
+
52
+ if (attributes.ref.current) {
53
+ attributes.ref.current.classList.add("slate-editor-element-selected");
54
+ }
55
+
56
+
48
57
  setSelectedStorybookElement({
49
58
  ...element,
50
59
  editorAttributes: attributes,
@@ -170,10 +179,14 @@ export default function BlockEditor({
170
179
  block: newStorybookElement.block,
171
180
  isEmpty: false,
172
181
  isInline: selectedStorybookElement.isInline,
173
- attributes: newStorybookElement.attributes || {},
182
+ attributes: {...(newStorybookElement.attributes || {})},
174
183
  type: "storybook",
175
184
  };
176
185
 
186
+ if (!newNodeProps.attributes.teasermanagerSlotId) {
187
+ newNodeProps.attributes.teasermanagerSlotId = ObjectId();
188
+ }
189
+
177
190
  Transforms.setNodes(editor, newNodeProps, {at: selectedStorybookElement.path});
178
191
 
179
192
  onSlateChange(editor.children);
@@ -183,10 +196,6 @@ export default function BlockEditor({
183
196
  ...newNodeProps,
184
197
  };
185
198
 
186
- if (!mergedValue.attributes.teasermanagerSlotId) {
187
- mergedValue.attributes.teasermanagerSlotId = ObjectId();
188
- }
189
-
190
199
  setSelectedStorybookElement(mergedValue);
191
200
  };
192
201
 
@@ -29,17 +29,19 @@ export const Resizable = ({left, right}) => {
29
29
  }
30
30
 
31
31
  const onMouseDown = (e) => {
32
+ if (!rightRef.current) {
33
+ return;
34
+ }
32
35
  rightRef.current.resizingStartWidth = rightRef.current.getBoundingClientRect().width;
33
36
  rightRef.current.resizingStartMouseX = e.pageX;
34
37
  rightRef.current.resizing = true;
35
38
  };
36
39
  const onMouseMove = (e) => {
37
- if (!rightRef.current.resizing) {
40
+ if (!rightRef?.current?.resizing) {
38
41
  return;
39
42
  }
40
43
 
41
44
  let newWidth = rightRef.current.resizingStartWidth - (e.pageX - rightRef.current.resizingStartMouseX)
42
-
43
45
  newWidth = checkWidth(newWidth);
44
46
 
45
47
  localStorage.setItem("slate-editor-resizable-width", newWidth);
@@ -47,7 +49,9 @@ export const Resizable = ({left, right}) => {
47
49
  rightRef.current.style.width = newWidth + 'px';
48
50
  }
49
51
  const onMouseUp = (e) => {
50
- rightRef.current.resizing = false;
52
+ if (rightRef.current) {
53
+ rightRef.current.resizing = false;
54
+ }
51
55
  }
52
56
 
53
57
  rightRef.current.addEventListener("mousedown", onMouseDown);
@@ -55,7 +59,9 @@ export const Resizable = ({left, right}) => {
55
59
  document.addEventListener("mouseup", onMouseUp);
56
60
 
57
61
  return () => {
58
- rightRef.current.removeEventListener("mousedown", onMouseDown);
62
+ if (rightRef.current) {
63
+ rightRef.current.removeEventListener("mousedown", onMouseDown);
64
+ }
59
65
  document.removeEventListener("mousemove", onMouseMove);
60
66
  document.removeEventListener("mouseup", onMouseUp);
61
67
  }