testomatio-editor-blocks 0.4.62 → 0.4.63

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.
@@ -93,13 +93,8 @@ export function canInsertStepOrSnippet(editor, referenceBlockId) {
93
93
  * Returns the inserted step's block ID (for focusing), or null.
94
94
  */
95
95
  export function addStepsBlock(editor) {
96
- var _a, _b, _c, _d;
96
+ var _a, _b, _c, _d, _e, _f;
97
97
  const allBlocks = editor.document;
98
- const emptyStep = {
99
- type: "testStep",
100
- props: { stepTitle: "", stepData: "", expectedResult: "" },
101
- children: [],
102
- };
103
98
  let stepsHeadingIndex = -1;
104
99
  for (let i = 0; i < allBlocks.length; i++) {
105
100
  const b = allBlocks[i];
@@ -129,8 +124,17 @@ export function addStepsBlock(editor) {
129
124
  continue;
130
125
  break;
131
126
  }
132
- const inserted = editor.insertBlocks([emptyStep], allBlocks[lastIndex].id, "after");
133
- return (_b = (_a = inserted === null || inserted === void 0 ? void 0 : inserted[0]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : null;
127
+ const previousStep = allBlocks[lastIndex];
128
+ const inheritedListStyle = (previousStep === null || previousStep === void 0 ? void 0 : previousStep.type) === "testStep"
129
+ ? ((_b = (_a = previousStep.props) === null || _a === void 0 ? void 0 : _a.listStyle) !== null && _b !== void 0 ? _b : "bullet")
130
+ : "bullet";
131
+ const emptyStep = {
132
+ type: "testStep",
133
+ props: { stepTitle: "", stepData: "", expectedResult: "", listStyle: inheritedListStyle },
134
+ children: [],
135
+ };
136
+ const inserted = editor.insertBlocks([emptyStep], previousStep.id, "after");
137
+ return (_d = (_c = inserted === null || inserted === void 0 ? void 0 : inserted[0]) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : null;
134
138
  }
135
139
  const lastBlock = allBlocks[allBlocks.length - 1];
136
140
  const stepsHeading = {
@@ -139,8 +143,13 @@ export function addStepsBlock(editor) {
139
143
  content: [{ type: "text", text: "Steps" }],
140
144
  children: [],
141
145
  };
146
+ const emptyStep = {
147
+ type: "testStep",
148
+ props: { stepTitle: "", stepData: "", expectedResult: "" },
149
+ children: [],
150
+ };
142
151
  const inserted = editor.insertBlocks([stepsHeading, emptyStep], lastBlock.id, "after");
143
- return (_d = (_c = inserted === null || inserted === void 0 ? void 0 : inserted[1]) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : null;
152
+ return (_f = (_e = inserted === null || inserted === void 0 ? void 0 : inserted[1]) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : null;
144
153
  }
145
154
  /**
146
155
  * Programmatically add an empty snippet block to the editor.
@@ -346,12 +355,14 @@ export const stepBlock = createReactBlockSpec({
346
355
  });
347
356
  }, [editor, block.id, expectedResult]);
348
357
  const handleInsertNextStep = useCallback(() => {
358
+ var _a;
349
359
  const allBlocks = editor.document;
350
360
  const idx = allBlocks.findIndex((b) => b.id === block.id);
351
361
  const next = idx >= 0 ? allBlocks[idx + 1] : null;
352
362
  if (next && isEmptyParagraph(next)) {
353
363
  editor.removeBlocks([next.id]);
354
364
  }
365
+ const currentListStyle = (_a = block.props.listStyle) !== null && _a !== void 0 ? _a : "bullet";
355
366
  editor.insertBlocks([
356
367
  {
357
368
  type: "testStep",
@@ -359,11 +370,12 @@ export const stepBlock = createReactBlockSpec({
359
370
  stepTitle: "",
360
371
  stepData: "",
361
372
  expectedResult: "",
373
+ listStyle: currentListStyle,
362
374
  },
363
375
  children: [],
364
376
  },
365
377
  ], block.id, "after");
366
- }, [editor, block.id]);
378
+ }, [editor, block.id, block.props]);
367
379
  const handleFieldFocus = useCallback(() => {
368
380
  var _a, _b, _c;
369
381
  const selection = editor.getSelection();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testomatio-editor-blocks",
3
- "version": "0.4.62",
3
+ "version": "0.4.63",
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",
@@ -108,11 +108,6 @@ export function addStepsBlock(editor: {
108
108
  insertBlocks: (blocks: any[], referenceId: string, placement: "before" | "after") => any[];
109
109
  }): string | null {
110
110
  const allBlocks = editor.document;
111
- const emptyStep = {
112
- type: "testStep" as const,
113
- props: { stepTitle: "", stepData: "", expectedResult: "" },
114
- children: [],
115
- };
116
111
 
117
112
  let stepsHeadingIndex = -1;
118
113
  for (let i = 0; i < allBlocks.length; i++) {
@@ -142,7 +137,17 @@ export function addStepsBlock(editor: {
142
137
  if (isEmptyParagraph(b)) continue;
143
138
  break;
144
139
  }
145
- const inserted = editor.insertBlocks([emptyStep], allBlocks[lastIndex].id, "after");
140
+ const previousStep = allBlocks[lastIndex];
141
+ const inheritedListStyle =
142
+ previousStep?.type === "testStep"
143
+ ? ((previousStep.props as any)?.listStyle ?? "bullet")
144
+ : "bullet";
145
+ const emptyStep = {
146
+ type: "testStep" as const,
147
+ props: { stepTitle: "", stepData: "", expectedResult: "", listStyle: inheritedListStyle },
148
+ children: [],
149
+ };
150
+ const inserted = editor.insertBlocks([emptyStep], previousStep.id, "after");
146
151
  return inserted?.[0]?.id ?? null;
147
152
  }
148
153
 
@@ -153,6 +158,11 @@ export function addStepsBlock(editor: {
153
158
  content: [{ type: "text" as const, text: "Steps" }],
154
159
  children: [],
155
160
  };
161
+ const emptyStep = {
162
+ type: "testStep" as const,
163
+ props: { stepTitle: "", stepData: "", expectedResult: "" },
164
+ children: [],
165
+ };
156
166
  const inserted = editor.insertBlocks([stepsHeading, emptyStep], lastBlock.id, "after");
157
167
  return inserted?.[1]?.id ?? null;
158
168
  }
@@ -399,6 +409,7 @@ export const stepBlock = createReactBlockSpec(
399
409
  if (next && isEmptyParagraph(next)) {
400
410
  editor.removeBlocks([next.id]);
401
411
  }
412
+ const currentListStyle = (block.props as any).listStyle ?? "bullet";
402
413
  editor.insertBlocks(
403
414
  [
404
415
  {
@@ -407,6 +418,7 @@ export const stepBlock = createReactBlockSpec(
407
418
  stepTitle: "",
408
419
  stepData: "",
409
420
  expectedResult: "",
421
+ listStyle: currentListStyle,
410
422
  },
411
423
  children: [],
412
424
  },
@@ -414,7 +426,7 @@ export const stepBlock = createReactBlockSpec(
414
426
  block.id,
415
427
  "after",
416
428
  );
417
- }, [editor, block.id]);
429
+ }, [editor, block.id, block.props]);
418
430
 
419
431
  const handleFieldFocus = useCallback(() => {
420
432
  const selection = editor.getSelection();
@@ -1696,6 +1696,36 @@ describe("markdownToBlocks", () => {
1696
1696
  expect(stepBlocks[1].props).toMatchObject({ stepTitle: "Second step", listStyle: "ordered" });
1697
1697
  });
1698
1698
 
1699
+ it("serializes a new ordered step appended to a numbered list as N.", () => {
1700
+ const orderedSteps: CustomEditorBlock[] = [
1701
+ {
1702
+ id: "s1",
1703
+ type: "testStep",
1704
+ props: { stepTitle: "First step", stepData: "", expectedResult: "", listStyle: "ordered" },
1705
+ content: undefined as any,
1706
+ children: [],
1707
+ } as any,
1708
+ {
1709
+ id: "s2",
1710
+ type: "testStep",
1711
+ props: { stepTitle: "Second step", stepData: "", expectedResult: "", listStyle: "ordered" },
1712
+ content: undefined as any,
1713
+ children: [],
1714
+ } as any,
1715
+ {
1716
+ id: "s3",
1717
+ type: "testStep",
1718
+ props: { stepTitle: "Newly added step", stepData: "", expectedResult: "", listStyle: "ordered" },
1719
+ content: undefined as any,
1720
+ children: [],
1721
+ } as any,
1722
+ ];
1723
+
1724
+ expect(blocksToMarkdown(orderedSteps)).toBe(
1725
+ ["1. First step", "2. Second step", "3. Newly added step"].join("\n"),
1726
+ );
1727
+ });
1728
+
1699
1729
  it("parses steps under an h4 'step' heading (lowercase)", () => {
1700
1730
  const markdown = ["#### step", "", "* Do something"].join("\n");
1701
1731
  const blocks = markdownToBlocks(markdown);