testomatio-editor-blocks 0.4.37 → 0.4.40

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.
@@ -22,7 +22,7 @@ const headingPrefixes = {
22
22
  5: "#####",
23
23
  6: "######",
24
24
  };
25
- const SPECIAL_CHAR_REGEX = /([*_`~\[\]()<>\\])/g;
25
+ const SPECIAL_CHAR_REGEX = /([*_`~\[\]()<\\])/g;
26
26
  const HTML_SPAN_REGEX = /<\/?span[^>]*>/g;
27
27
  const HTML_UNDERLINE_REGEX = /<\/?u>/g;
28
28
  const EXPECTED_LABEL_REGEX = /^(?:[*_`]*\s*)?(expected(?:\s+result)?)\s*(?:[*_`]*\s*)?\s*[:\-–—]\s*/i;
@@ -77,7 +77,7 @@ function stripLeadingFormatting(text) {
77
77
  return result;
78
78
  }
79
79
  function unescapeMarkdown(text) {
80
- return stripHtmlWrappers(text).replace(/\\([*_`~\[\]()<>\\])/g, "$1");
80
+ return stripHtmlWrappers(text).replace(/\\([*_`~\[\]()<>\\])/g, "$1").replace(/\\>/g, ">");
81
81
  }
82
82
  function applyTextStyles(text, styles) {
83
83
  if (!styles) {
@@ -652,7 +652,7 @@ function parseList(lines, startIndex, listType, indentLevel, allowEmptySteps = f
652
652
  // Check if this line should be parsed as nested content
653
653
  // Only go deeper if indent is at least 2 more than the next level's expected indent
654
654
  const nextLevelExpectedIndent = (indentLevel + 1) * 2;
655
- if (indent >= nextLevelExpectedIndent) {
655
+ if (indent >= nextLevelExpectedIndent && items.length > 0) {
656
656
  const lastItem = items.at(-1);
657
657
  if (!lastItem) {
658
658
  break;
@@ -1016,7 +1016,7 @@ function parseQuote(lines, index) {
1016
1016
  if (!trimmed.startsWith(">")) {
1017
1017
  break;
1018
1018
  }
1019
- collected.push(trimmed.replace(/^>\s?/, ""));
1019
+ collected.push(trimmed.replace(/^(?:>\s?)+/, ""));
1020
1020
  next += 1;
1021
1021
  }
1022
1022
  return {
@@ -13,14 +13,14 @@ export function useSnippetAutocomplete() {
13
13
  return cachedSuggestions;
14
14
  if (!globalFetcher)
15
15
  return [];
16
+ if (inflightPromise)
17
+ return [];
16
18
  const result = globalFetcher();
17
19
  if (result && typeof result.then === "function") {
18
- if (!inflightPromise) {
19
- inflightPromise = result
20
- .then((r) => normalizeSnippetSuggestions(r))
21
- .then((items) => { cachedSuggestions = items; inflightPromise = null; return items; })
22
- .catch((error) => { inflightPromise = null; console.error("Failed to fetch snippet suggestions", error); return []; });
23
- }
20
+ inflightPromise = result
21
+ .then((r) => normalizeSnippetSuggestions(r))
22
+ .then((items) => { cachedSuggestions = items; inflightPromise = null; return items; })
23
+ .catch((error) => { inflightPromise = null; console.error("Failed to fetch snippet suggestions", error); return []; });
24
24
  return [];
25
25
  }
26
26
  const normalized = normalizeSnippetSuggestions(result);
@@ -13,14 +13,14 @@ export function useStepAutocomplete() {
13
13
  return cachedSuggestions;
14
14
  if (!globalFetcher)
15
15
  return [];
16
+ if (inflightPromise)
17
+ return [];
16
18
  const result = globalFetcher();
17
19
  if (result && typeof result.then === "function") {
18
- if (!inflightPromise) {
19
- inflightPromise = result
20
- .then((r) => normalizeStepSuggestions(r))
21
- .then((items) => { cachedSuggestions = items; inflightPromise = null; return items; })
22
- .catch((error) => { inflightPromise = null; console.error("Failed to fetch step suggestions", error); return []; });
23
- }
20
+ inflightPromise = result
21
+ .then((r) => normalizeStepSuggestions(r))
22
+ .then((items) => { cachedSuggestions = items; inflightPromise = null; return items; })
23
+ .catch((error) => { inflightPromise = null; console.error("Failed to fetch step suggestions", error); return []; });
24
24
  return [];
25
25
  }
26
26
  const normalized = normalizeStepSuggestions(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testomatio-editor-blocks",
3
- "version": "0.4.37",
3
+ "version": "0.4.40",
4
4
  "description": "Custom BlockNote schema, markdown conversion helpers, and UI for Testomatio-style test cases and steps.",
5
5
  "type": "module",
6
6
  "main": "./package/index.js",
@@ -389,6 +389,26 @@ describe("blocksToMarkdown", () => {
389
389
  );
390
390
  });
391
391
 
392
+ it("serializes a blockquote", () => {
393
+ const blocks: CustomEditorBlock[] = [
394
+ {
395
+ id: "q1",
396
+ type: "quote",
397
+ props: { textColor: "default", backgroundColor: "default", textAlignment: "left" },
398
+ content: [{ type: "text", text: "Hello world", styles: {} }],
399
+ children: [],
400
+ },
401
+ ];
402
+
403
+ expect(blocksToMarkdown(blocks)).toBe("> Hello world");
404
+ });
405
+
406
+ it("round-trips a blockquote without escaping > in content", () => {
407
+ const markdown = "> Some quoted text";
408
+ const blocks = markdownToBlocks(markdown);
409
+ expect(blocksToMarkdown(blocks as any)).toBe("> Some quoted text");
410
+ });
411
+
392
412
  it("serializes table cells containing newlines as <br/>", () => {
393
413
  const blocks: CustomEditorBlock[] = [
394
414
  {
@@ -573,6 +593,48 @@ describe("blocksToMarkdown", () => {
573
593
  });
574
594
 
575
595
  describe("markdownToBlocks", () => {
596
+ it("parses nested blockquote by flattening to single-level quote", () => {
597
+ const markdown = ">> The Witch bade her clean the pots.";
598
+ const blocks = markdownToBlocks(markdown);
599
+ expect(blocks).toEqual([
600
+ {
601
+ type: "quote",
602
+ props: { textColor: "default", backgroundColor: "default", textAlignment: "left" },
603
+ content: [{ type: "text", text: "The Witch bade her clean the pots.", styles: {} }],
604
+ children: [],
605
+ },
606
+ ]);
607
+ });
608
+
609
+ it("parses spaced nested blockquote > > text", () => {
610
+ const markdown = "> > The Witch bade her clean the pots.";
611
+ const blocks = markdownToBlocks(markdown);
612
+ expect(blocks).toEqual([
613
+ {
614
+ type: "quote",
615
+ props: { textColor: "default", backgroundColor: "default", textAlignment: "left" },
616
+ content: [{ type: "text", text: "The Witch bade her clean the pots.", styles: {} }],
617
+ children: [],
618
+ },
619
+ ]);
620
+ });
621
+
622
+ it("round-trips nested blockquote without \\> escaping", () => {
623
+ const markdown = [
624
+ "> Dorothy followed her through many of the beautiful rooms in her castle.",
625
+ ">> The Witch bade her clean the pots.",
626
+ ].join("\n");
627
+
628
+ const blocks = markdownToBlocks(markdown);
629
+ const result = blocksToMarkdown(blocks as any);
630
+ expect(result).toBe(
631
+ [
632
+ "> Dorothy followed her through many of the beautiful rooms in her castle.",
633
+ "> The Witch bade her clean the pots.",
634
+ ].join("\n"),
635
+ );
636
+ });
637
+
576
638
  it("parses test steps and test cases", () => {
577
639
  const markdown = [
578
640
  "* Open the Login page.",
@@ -946,6 +1008,24 @@ describe("markdownToBlocks", () => {
946
1008
  expect(nestedChildren.some((child) => child.type === "bulletListItem")).toBe(true);
947
1009
  });
948
1010
 
1011
+ it("does not freeze on indented list items without a parent", () => {
1012
+ const markdown = [
1013
+ "### Requirements",
1014
+ "",
1015
+ " * The system should log in the user {{username}} with password ${password} successfully.",
1016
+ "",
1017
+ " ### Steps",
1018
+ "",
1019
+ " * Open login page",
1020
+ " *Expected*: The main page is opened",
1021
+ ].join("\n");
1022
+
1023
+ const blocks = markdownToBlocks(markdown);
1024
+ expect(blocks.length).toBeGreaterThan(0);
1025
+ const bullets = blocks.filter((b) => b.type === "bulletListItem");
1026
+ expect(bullets.length).toBeGreaterThanOrEqual(1);
1027
+ });
1028
+
949
1029
  it("parses expected result prefixes with emphasis", () => {
950
1030
  const markdown = [
951
1031
  "* Open the form.",
@@ -60,7 +60,7 @@ const headingPrefixes: Record<number, string> = {
60
60
  6: "######",
61
61
  };
62
62
 
63
- const SPECIAL_CHAR_REGEX = /([*_`~\[\]()<>\\])/g;
63
+ const SPECIAL_CHAR_REGEX = /([*_`~\[\]()<\\])/g;
64
64
  const HTML_SPAN_REGEX = /<\/?span[^>]*>/g;
65
65
  const HTML_UNDERLINE_REGEX = /<\/?u>/g;
66
66
  const EXPECTED_LABEL_REGEX = /^(?:[*_`]*\s*)?(expected(?:\s+result)?)\s*(?:[*_`]*\s*)?\s*[:\-–—]\s*/i;
@@ -125,7 +125,7 @@ function stripLeadingFormatting(text: string): string {
125
125
  }
126
126
 
127
127
  function unescapeMarkdown(text: string): string {
128
- return stripHtmlWrappers(text).replace(/\\([*_`~\[\]()<>\\])/g, "$1");
128
+ return stripHtmlWrappers(text).replace(/\\([*_`~\[\]()<>\\])/g, "$1").replace(/\\>/g, ">");
129
129
  }
130
130
 
131
131
  function applyTextStyles(text: string, styles: EditorStyles | undefined): string {
@@ -796,7 +796,7 @@ function parseList(
796
796
  // Check if this line should be parsed as nested content
797
797
  // Only go deeper if indent is at least 2 more than the next level's expected indent
798
798
  const nextLevelExpectedIndent = (indentLevel + 1) * 2;
799
- if (indent >= nextLevelExpectedIndent) {
799
+ if (indent >= nextLevelExpectedIndent && items.length > 0) {
800
800
  const lastItem = items.at(-1);
801
801
  if (!lastItem) {
802
802
  break;
@@ -1214,7 +1214,7 @@ function parseQuote(lines: string[], index: number): { block: CustomPartialBlock
1214
1214
  if (!trimmed.startsWith(">")) {
1215
1215
  break;
1216
1216
  }
1217
- collected.push(trimmed.replace(/^>\s?/, ""));
1217
+ collected.push(trimmed.replace(/^(?:>\s?)+/, ""));
1218
1218
  next += 1;
1219
1219
  }
1220
1220
 
@@ -45,14 +45,13 @@ export function useSnippetAutocomplete(): SnippetSuggestion[] {
45
45
  const [suggestions, setSuggestions] = useState<SnippetSuggestion[]>(() => {
46
46
  if (cachedSuggestions.length > 0) return cachedSuggestions;
47
47
  if (!globalFetcher) return [];
48
+ if (inflightPromise) return [];
48
49
  const result = globalFetcher();
49
50
  if (result && typeof (result as Promise<unknown>).then === "function") {
50
- if (!inflightPromise) {
51
- inflightPromise = (result as Promise<SnippetInput>)
52
- .then((r) => normalizeSnippetSuggestions(r))
53
- .then((items) => { cachedSuggestions = items; inflightPromise = null; return items; })
54
- .catch((error) => { inflightPromise = null; console.error("Failed to fetch snippet suggestions", error); return [] as SnippetSuggestion[]; });
55
- }
51
+ inflightPromise = (result as Promise<SnippetInput>)
52
+ .then((r) => normalizeSnippetSuggestions(r))
53
+ .then((items) => { cachedSuggestions = items; inflightPromise = null; return items; })
54
+ .catch((error) => { inflightPromise = null; console.error("Failed to fetch snippet suggestions", error); return [] as SnippetSuggestion[]; });
56
55
  return [];
57
56
  }
58
57
  const normalized = normalizeSnippetSuggestions(result as SnippetInput);
@@ -51,14 +51,13 @@ export function useStepAutocomplete(): StepSuggestion[] {
51
51
  const [suggestions, setSuggestions] = useState<StepSuggestion[]>(() => {
52
52
  if (cachedSuggestions.length > 0) return cachedSuggestions;
53
53
  if (!globalFetcher) return [];
54
+ if (inflightPromise) return [];
54
55
  const result = globalFetcher();
55
56
  if (result && typeof (result as Promise<unknown>).then === "function") {
56
- if (!inflightPromise) {
57
- inflightPromise = (result as Promise<StepInput>)
58
- .then((r) => normalizeStepSuggestions(r))
59
- .then((items) => { cachedSuggestions = items; inflightPromise = null; return items; })
60
- .catch((error) => { inflightPromise = null; console.error("Failed to fetch step suggestions", error); return [] as StepSuggestion[]; });
61
- }
57
+ inflightPromise = (result as Promise<StepInput>)
58
+ .then((r) => normalizeStepSuggestions(r))
59
+ .then((items) => { cachedSuggestions = items; inflightPromise = null; return items; })
60
+ .catch((error) => { inflightPromise = null; console.error("Failed to fetch step suggestions", error); return [] as StepSuggestion[]; });
62
61
  return [];
63
62
  }
64
63
  const normalized = normalizeStepSuggestions(result as StepInput);