@kungal/editor-core 0.36.0 → 0.37.0
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 +23 -0
- package/dist/preset/index.cjs +4 -1
- package/dist/preset/index.cjs.map +1 -1
- package/dist/preset/index.d.cts +8 -5
- package/dist/preset/index.d.ts +8 -5
- package/dist/preset/index.js +4 -1
- package/dist/preset/index.js.map +1 -1
- package/package.json +1 -1
package/dist/preset/index.d.cts
CHANGED
|
@@ -21,7 +21,9 @@ declare const spoilerSchema: _milkdown_kit_utils.$NodeSchema<"kun-spoiler">;
|
|
|
21
21
|
* - a selection → its TEXT moves INSIDE the node. It has to be moved, not
|
|
22
22
|
* replaced: `replaceSelectionWith` on its own deletes what you selected. The
|
|
23
23
|
* schema is `marks: ''` (bold inside `||…||` cannot round-trip), so the
|
|
24
|
-
* formatting is what's dropped, never the words.
|
|
24
|
+
* formatting is what's dropped, never the words. Line breaks become spaces:
|
|
25
|
+
* `||…||` pairs within one line in every reader of the syntax, so a spoiler
|
|
26
|
+
* spanning lines would serialize to markdown that reads back as literal `||`.
|
|
25
27
|
* - an empty selection → an empty spoiler with the caret inside it: type, and
|
|
26
28
|
* what you type is hidden. "Empty" means holding a caret anchor — a caret
|
|
27
29
|
* cannot sit in an inline node with no text node in it — and a spoiler with
|
|
@@ -32,10 +34,11 @@ declare const spoilerSchema: _milkdown_kit_utils.$NodeSchema<"kun-spoiler">;
|
|
|
32
34
|
* all, so this button has to toggle.
|
|
33
35
|
*
|
|
34
36
|
* Returns false where there is nothing to hide or nowhere to put it — inside a
|
|
35
|
-
* code block,
|
|
36
|
-
* delete it) — so a host can grey the
|
|
37
|
-
*
|
|
38
|
-
* survive the move:
|
|
37
|
+
* code block, with a NODE selected, or over a selection holding no words at all
|
|
38
|
+
* (an image is not text; replacing it would delete it) — so a host can grey the
|
|
39
|
+
* button out. A spoiler holds text, so any other inline node caught in a text
|
|
40
|
+
* selection alongside words (an image, inline math) does not survive the move:
|
|
41
|
+
* `||…||` cannot carry one.
|
|
39
42
|
*/
|
|
40
43
|
declare const insertKunSpoilerCommand: _milkdown_kit_utils.$Command<unknown>;
|
|
41
44
|
/** Typing `||text||` in the editor turns it into a spoiler node in place. The
|
package/dist/preset/index.d.ts
CHANGED
|
@@ -21,7 +21,9 @@ declare const spoilerSchema: _milkdown_kit_utils.$NodeSchema<"kun-spoiler">;
|
|
|
21
21
|
* - a selection → its TEXT moves INSIDE the node. It has to be moved, not
|
|
22
22
|
* replaced: `replaceSelectionWith` on its own deletes what you selected. The
|
|
23
23
|
* schema is `marks: ''` (bold inside `||…||` cannot round-trip), so the
|
|
24
|
-
* formatting is what's dropped, never the words.
|
|
24
|
+
* formatting is what's dropped, never the words. Line breaks become spaces:
|
|
25
|
+
* `||…||` pairs within one line in every reader of the syntax, so a spoiler
|
|
26
|
+
* spanning lines would serialize to markdown that reads back as literal `||`.
|
|
25
27
|
* - an empty selection → an empty spoiler with the caret inside it: type, and
|
|
26
28
|
* what you type is hidden. "Empty" means holding a caret anchor — a caret
|
|
27
29
|
* cannot sit in an inline node with no text node in it — and a spoiler with
|
|
@@ -32,10 +34,11 @@ declare const spoilerSchema: _milkdown_kit_utils.$NodeSchema<"kun-spoiler">;
|
|
|
32
34
|
* all, so this button has to toggle.
|
|
33
35
|
*
|
|
34
36
|
* Returns false where there is nothing to hide or nowhere to put it — inside a
|
|
35
|
-
* code block,
|
|
36
|
-
* delete it) — so a host can grey the
|
|
37
|
-
*
|
|
38
|
-
* survive the move:
|
|
37
|
+
* code block, with a NODE selected, or over a selection holding no words at all
|
|
38
|
+
* (an image is not text; replacing it would delete it) — so a host can grey the
|
|
39
|
+
* button out. A spoiler holds text, so any other inline node caught in a text
|
|
40
|
+
* selection alongside words (an image, inline math) does not survive the move:
|
|
41
|
+
* `||…||` cannot carry one.
|
|
39
42
|
*/
|
|
40
43
|
declare const insertKunSpoilerCommand: _milkdown_kit_utils.$Command<unknown>;
|
|
41
44
|
/** Typing `||text||` in the editor turns it into a spoiler node in place. The
|
package/dist/preset/index.js
CHANGED
|
@@ -144,10 +144,13 @@ var insertKunSpoilerCommand = $command(
|
|
|
144
144
|
if ($from.parent.isTextblock && !$from.parent.canReplaceWith($from.index(), $from.index(), type)) {
|
|
145
145
|
return false;
|
|
146
146
|
}
|
|
147
|
+
const text = state.doc.textBetween(from, to, " ", " ").replaceAll(CARET_ANCHOR, "");
|
|
148
|
+
if (!empty && !text.trim()) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
147
151
|
if (!dispatch) {
|
|
148
152
|
return true;
|
|
149
153
|
}
|
|
150
|
-
const text = state.doc.textBetween(from, to, " ").replaceAll(CARET_ANCHOR, "");
|
|
151
154
|
const node = type.create(null, state.schema.text(text || CARET_ANCHOR));
|
|
152
155
|
const tr = state.tr.replaceSelectionWith(node, false);
|
|
153
156
|
const after = tr.selection.to;
|