wysimark-lite 0.16.1 → 0.16.3

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/dist/index.mjs CHANGED
@@ -1422,7 +1422,6 @@ function serializeElement(element, orders) {
1422
1422
  case "unordered-list-item": {
1423
1423
  const indent2 = " ".repeat(element.depth * LIST_INDENT_SIZE);
1424
1424
  return `${indent2}- ${serializeLine(element.children)}
1425
-
1426
1425
  `;
1427
1426
  }
1428
1427
  case "ordered-list-item": {
@@ -1430,7 +1429,6 @@ function serializeElement(element, orders) {
1430
1429
  return `${indent2}${orders[element.depth]}. ${serializeLine(
1431
1430
  element.children
1432
1431
  )}
1433
-
1434
1432
  `;
1435
1433
  }
1436
1434
  case "task-list-item": {
@@ -1440,15 +1438,10 @@ function serializeElement(element, orders) {
1440
1438
  line = " ";
1441
1439
  }
1442
1440
  return `${indent2}- [${element.checked ? "x" : " "}] ${line}
1443
-
1444
1441
  `;
1445
1442
  }
1446
1443
  case "image-block":
1447
1444
  return serializeImageBlock(element);
1448
- case "image-inline":
1449
- throw new Error(
1450
- `This shouldn't happen because inlines are handled in serializeSegment`
1451
- );
1452
1445
  }
1453
1446
  assertUnreachable(element);
1454
1447
  }
@@ -1457,7 +1450,9 @@ function serializeElement(element, orders) {
1457
1450
  function serializeElements(elements) {
1458
1451
  const segments = [];
1459
1452
  let orders = [];
1460
- for (const element of elements) {
1453
+ for (let i = 0; i < elements.length; i++) {
1454
+ const element = elements[i];
1455
+ const nextElement = i < elements.length - 1 ? elements[i + 1] : null;
1461
1456
  if (element.type === "ordered-list-item") {
1462
1457
  orders[element.depth] = (orders[element.depth] || 0) + 1;
1463
1458
  orders = orders.slice(0, element.depth + 1);
@@ -1466,7 +1461,11 @@ function serializeElements(elements) {
1466
1461
  } else {
1467
1462
  orders = [];
1468
1463
  }
1469
- segments.push(serializeElement(element, orders));
1464
+ let serialized = serializeElement(element, orders);
1465
+ if ((element.type === "ordered-list-item" || element.type === "unordered-list-item" || element.type === "task-list-item") && (!nextElement || nextElement.type !== "ordered-list-item" && nextElement.type !== "unordered-list-item" && nextElement.type !== "task-list-item")) {
1466
+ serialized = serialized.replace(/\n$/, "\n\n");
1467
+ }
1468
+ segments.push(serialized);
1470
1469
  }
1471
1470
  const joined = segments.join("");
1472
1471
  if (joined.trim() === "")
@@ -2294,7 +2293,7 @@ function normalizeNode(editor, entry) {
2294
2293
  // src/anchor-plugin/render-element/anchor.tsx
2295
2294
  import { clsx } from "clsx";
2296
2295
  import { useEffect as useEffect3, useRef as useRef4 } from "react";
2297
- import { useSelected } from "slate-react";
2296
+ import { useSelected, useSlate } from "slate-react";
2298
2297
 
2299
2298
  // src/use-layer/layers.tsx
2300
2299
  import { createContext, useState } from "react";
@@ -3354,7 +3353,8 @@ function AnchorDialog({
3354
3353
  const editTooltip = useTooltip({ title: "\u30EA\u30F3\u30AF\u3092\u7DE8\u96C6" });
3355
3354
  const removeLink2 = useCallback4(() => {
3356
3355
  editor.anchor.removeLink({ at: element });
3357
- }, [editor]);
3356
+ dialog.close();
3357
+ }, [editor, dialog]);
3358
3358
  const openEditDialog = useCallback4(() => {
3359
3359
  editTooltip.onMouseLeave();
3360
3360
  dialog.open(() => {
@@ -3421,13 +3421,15 @@ function Anchor({
3421
3421
  const startEdgeRef = useRef4(null);
3422
3422
  const anchorRef = useRef4(null);
3423
3423
  const selected = useSelected();
3424
+ const editor = useSlate();
3424
3425
  const dialog = useLayer("dialog");
3425
3426
  useEffect3(() => {
3426
3427
  const anchor = anchorRef.current;
3427
3428
  const startEdge = startEdgeRef.current;
3428
3429
  if (!anchor || !startEdge)
3429
3430
  return;
3430
- if (selected) {
3431
+ const hasSelection = editor.selection && editor.selection.anchor.offset !== editor.selection.focus.offset;
3432
+ if (selected && !hasSelection) {
3431
3433
  setTimeout(() => {
3432
3434
  dialog.open(() => /* @__PURE__ */ jsx14(
3433
3435
  AnchorDialog,
@@ -7628,13 +7630,13 @@ var itemSets = [largeItems, mediumItems, smallItems];
7628
7630
  // src/toolbar-plugin/components/toolbar/toolbar-button.tsx
7629
7631
  import { clsx as clsx9 } from "clsx";
7630
7632
  import { useCallback as useCallback13, useRef as useRef9 } from "react";
7631
- import { ReactEditor as ReactEditor14, useSlate, useSlateStatic as useSlateStatic19 } from "slate-react";
7633
+ import { ReactEditor as ReactEditor14, useSlate as useSlate2, useSlateStatic as useSlateStatic19 } from "slate-react";
7632
7634
  import { jsx as jsx55, jsxs as jsxs29 } from "react/jsx-runtime";
7633
7635
  function ToolbarButton({
7634
7636
  item
7635
7637
  }) {
7636
7638
  const staticEditor = useSlateStatic19();
7637
- const editor = useSlate();
7639
+ const editor = useSlate2();
7638
7640
  const isActive = item.active ? item.active(editor) : false;
7639
7641
  const ref = useRef9(null);
7640
7642
  const tooltip = useTooltip({