testomatio-editor-blocks 0.4.17 → 0.4.18

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.
@@ -77,9 +77,19 @@ export const stepBlock = createReactBlockSpec({
77
77
  // Calculate step number based on position in document
78
78
  const stepNumber = useMemo(() => {
79
79
  const allBlocks = editor.document;
80
- const stepBlocks = allBlocks.filter((b) => b.type === "testStep");
81
- const index = stepBlocks.findIndex((b) => b.id === block.id);
82
- return index >= 0 ? index + 1 : 1;
80
+ const blockIndex = allBlocks.findIndex((b) => b.id === block.id);
81
+ if (blockIndex < 0)
82
+ return 1;
83
+ let count = 1;
84
+ for (let i = blockIndex - 1; i >= 0; i--) {
85
+ if (allBlocks[i].type === "testStep") {
86
+ count++;
87
+ }
88
+ else {
89
+ break;
90
+ }
91
+ }
92
+ return count;
83
93
  }, [block.id, documentVersion, editor.document]);
84
94
  useEditorChange(() => {
85
95
  setDocumentVersion((version) => version + 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testomatio-editor-blocks",
3
- "version": "0.4.17",
3
+ "version": "0.4.18",
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",
@@ -86,9 +86,18 @@ export const stepBlock = createReactBlockSpec(
86
86
  // Calculate step number based on position in document
87
87
  const stepNumber = useMemo(() => {
88
88
  const allBlocks = editor.document;
89
- const stepBlocks = allBlocks.filter((b) => b.type === "testStep");
90
- const index = stepBlocks.findIndex((b) => b.id === block.id);
91
- return index >= 0 ? index + 1 : 1;
89
+ const blockIndex = allBlocks.findIndex((b) => b.id === block.id);
90
+ if (blockIndex < 0) return 1;
91
+
92
+ let count = 1;
93
+ for (let i = blockIndex - 1; i >= 0; i--) {
94
+ if (allBlocks[i].type === "testStep") {
95
+ count++;
96
+ } else {
97
+ break;
98
+ }
99
+ }
100
+ return count;
92
101
  }, [block.id, documentVersion, editor.document]);
93
102
 
94
103
  useEditorChange(() => {