@zuilib/text-editor 0.7.0 → 0.7.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog — @zuilib/text-editor
2
2
 
3
+ ## 0.7.1
4
+
5
+ - Fix: free `text` shapes could not be typed into. The text tool's editor
6
+ opened on pointerdown and was blurred by the same click; it now opens on
7
+ pointerup like the card editors
8
+ - Fix: selecting a shape no longer shifts the drawing. The properties row
9
+ is always rendered (showing the defaults for the next shape when nothing
10
+ is selected) with a fixed minimum height, so click-to-edit lands where
11
+ the pointer is
12
+ - Fix: keyboard shortcuts keep working after committing text (the canvas
13
+ regains focus); `Home`/`End` work inside the inline text editor
14
+
3
15
  ## 0.7.0
4
16
 
5
17
  **Themed drawing canvas.** The canvas chrome now follows the host theme
package/dist/index.js CHANGED
@@ -2234,6 +2234,14 @@ function TextEditOverlay({
2234
2234
  el.select();
2235
2235
  const onKeyDown = (e) => {
2236
2236
  e.stopPropagation();
2237
+ if ((e.key === "Home" || e.key === "End") && !e.shiftKey && !e.metaKey && !e.ctrlKey) {
2238
+ e.preventDefault();
2239
+ const text = el.value;
2240
+ const caret = e.key === "Home" ? el.selectionStart : el.selectionEnd;
2241
+ const pos = e.key === "Home" ? text.lastIndexOf("\n", caret - 1) + 1 : (text.indexOf("\n", caret) + 1 || text.length + 1) - 1;
2242
+ el.setSelectionRange(pos, pos);
2243
+ return;
2244
+ }
2237
2245
  if (e.key === "Enter" && !e.shiftKey) {
2238
2246
  e.preventDefault();
2239
2247
  onCommit(shape.id, field, valueRef.current);
@@ -2265,7 +2273,9 @@ function TextEditOverlay({
2265
2273
  fontSize: FONT_SIZE,
2266
2274
  width: Math.max(80, size.w + 20),
2267
2275
  height: size.h + 2,
2268
- whiteSpace: "pre"
2276
+ // `pre` would keep the lines, but Chrome ignores Home/End in a
2277
+ // `white-space: pre` textarea; the width tracks the content anyway
2278
+ whiteSpace: "pre-wrap"
2269
2279
  });
2270
2280
  } else if (isConnectorType(shape.type)) {
2271
2281
  const lines = wrapText(value, CONNECTOR_LABEL_MAX_WIDTH, CONNECTOR_FONT_SIZE);
@@ -2537,6 +2547,7 @@ function DrawingCanvas({ nodeKey, data }) {
2537
2547
  const rootRef = useRef4(null);
2538
2548
  const svgRef = useRef4(null);
2539
2549
  const dragRef = useRef4(null);
2550
+ const pendingTextEditRef = useRef4(null);
2540
2551
  const pendingPointRef = useRef4(null);
2541
2552
  const frameRef = useRef4(null);
2542
2553
  const lastCommittedRef = useRef4(serializeDrawingData(data));
@@ -2663,7 +2674,8 @@ function DrawingCanvas({ nodeKey, data }) {
2663
2674
  }
2664
2675
  ]);
2665
2676
  setTool("select");
2666
- startTextEditing(id2, "text");
2677
+ setSelectedIds(/* @__PURE__ */ new Set([id2]));
2678
+ pendingTextEditRef.current = id2;
2667
2679
  return;
2668
2680
  }
2669
2681
  const id = createShapeId();
@@ -2767,6 +2779,12 @@ function DrawingCanvas({ nodeKey, data }) {
2767
2779
  }
2768
2780
  pendingPointRef.current = null;
2769
2781
  setHoverBoxId(null);
2782
+ if (pendingTextEditRef.current) {
2783
+ const id = pendingTextEditRef.current;
2784
+ pendingTextEditRef.current = null;
2785
+ startTextEditing(id, "text");
2786
+ return;
2787
+ }
2770
2788
  if (!drag) return;
2771
2789
  const point = getPoint(e);
2772
2790
  if (drag.mode === "marquee") {
@@ -2950,6 +2968,7 @@ function DrawingCanvas({ nodeKey, data }) {
2950
2968
  const commitText = useCallback(
2951
2969
  (id, field, value) => {
2952
2970
  setEditingText(null);
2971
+ rootRef.current?.focus({ preventScroll: true });
2953
2972
  updateShapes(
2954
2973
  (prev) => prev.flatMap((s) => {
2955
2974
  if (s.id !== id) return [s];
@@ -2974,7 +2993,6 @@ function DrawingCanvas({ nodeKey, data }) {
2974
2993
  }, []);
2975
2994
  const editingShape = shapes.find((s) => s.id === editingText?.id) ?? null;
2976
2995
  const hoverBox = hoverBoxId ? shapes.find((s) => s.id === hoverBoxId) : null;
2977
- const showProps = isEditable && !editingText && (selection.length > 0 || tool !== "select");
2978
2996
  const propStroke = single?.stroke ?? selection[0]?.stroke ?? stroke;
2979
2997
  const propFill = single?.fill ?? selection.find((s) => isBoxType(s.type))?.fill ?? fill;
2980
2998
  const canvasCursor = tool === "select" ? "default" : tool === "text" ? "text" : "crosshair";
@@ -3004,7 +3022,7 @@ function DrawingCanvas({ nodeKey, data }) {
3004
3022
  onCopyMermaid: copyMermaid
3005
3023
  }
3006
3024
  ),
3007
- /* @__PURE__ */ jsx9("div", { className: `zui-drawing-props-host ${showProps ? "is-visible" : ""}`, children: /* @__PURE__ */ jsx9(
3025
+ /* @__PURE__ */ jsx9("div", { className: "zui-drawing-props-host", children: /* @__PURE__ */ jsx9(
3008
3026
  PropertyBar,
3009
3027
  {
3010
3028
  selection,
package/dist/styles.css CHANGED
@@ -653,23 +653,15 @@
653
653
  background: color-mix(in srgb, var(--zui-drawing-accent) 14%, transparent);
654
654
  }
655
655
 
656
- /* Contextual properties: a second row that expands under the tools */
656
+ /*
657
+ * Properties row: colors for the selection (or for the next shape when
658
+ * nothing is selected) plus contextual connector options. Always rendered
659
+ * with a fixed minimum height so the drawing never shifts under the
660
+ * pointer when the selection changes.
661
+ */
657
662
  .zui-drawing-props-host {
658
663
  flex-basis: 100%;
659
664
  display: flex;
660
- max-height: 0;
661
- overflow: hidden;
662
- opacity: 0;
663
- pointer-events: none;
664
- transition:
665
- max-height 0.18s ease,
666
- opacity 0.18s ease;
667
- }
668
-
669
- .zui-drawing-props-host.is-visible {
670
- max-height: 6rem;
671
- opacity: 1;
672
- pointer-events: auto;
673
665
  }
674
666
 
675
667
  .zui-drawing-props {
@@ -677,7 +669,8 @@
677
669
  flex-wrap: wrap;
678
670
  align-items: center;
679
671
  gap: 0.25rem;
680
- padding: 0.25rem 0 0.125rem;
672
+ min-height: 1.75rem;
673
+ padding: 0.125rem 0 0;
681
674
  }
682
675
 
683
676
  .zui-drawing-props-group {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuilib/text-editor",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "ZUI — A markdown editor component wrapping Lexical",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",