testomatio-editor-blocks 0.4.20 → 0.4.22

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.
@@ -1,3 +1,4 @@
1
+ export declare const isEmptyParagraph: (b: any) => boolean;
1
2
  export declare const stepBlock: {
2
3
  config: {
3
4
  readonly type: "testStep";
@@ -43,6 +43,10 @@ const writeStepViewMode = (mode) => {
43
43
  //
44
44
  }
45
45
  };
46
+ export const isEmptyParagraph = (b) => b.type === "paragraph" &&
47
+ (!Array.isArray(b.content) ||
48
+ b.content.length === 0 ||
49
+ b.content.every((n) => { var _a; return n.type === "text" && !((_a = n.text) === null || _a === void 0 ? void 0 : _a.trim()); }));
46
50
  export const stepBlock = createReactBlockSpec({
47
51
  type: "testStep",
48
52
  content: "none",
@@ -82,9 +86,13 @@ export const stepBlock = createReactBlockSpec({
82
86
  return 1;
83
87
  let count = 1;
84
88
  for (let i = blockIndex - 1; i >= 0; i--) {
85
- if (allBlocks[i].type === "testStep") {
89
+ const b = allBlocks[i];
90
+ if (b.type === "testStep") {
86
91
  count++;
87
92
  }
93
+ else if (isEmptyParagraph(b)) {
94
+ continue;
95
+ }
88
96
  else {
89
97
  break;
90
98
  }
@@ -99,7 +107,7 @@ export const stepBlock = createReactBlockSpec({
99
107
  return false;
100
108
  for (let i = blockIndex - 1; i >= 0; i--) {
101
109
  const b = allBlocks[i];
102
- if (b.type === "testStep" || b.type === "snippet") {
110
+ if (b.type === "testStep" || b.type === "snippet" || isEmptyParagraph(b)) {
103
111
  continue;
104
112
  }
105
113
  if (b.type === "heading") {
@@ -3,5 +3,5 @@ import { StepField } from "./stepField";
3
3
  const STEP_PLACEHOLDER = "Enter step name";
4
4
  const EXPECTED_RESULT_PLACEHOLDER = "Enter expected result";
5
5
  export function StepHorizontalView({ blockId, stepNumber, stepValue, expectedResult, onStepChange, onExpectedChange, onInsertNextStep, onFieldFocus, viewToggle, }) {
6
- return (_jsxs("div", { className: "bn-teststep bn-teststep--horizontal", "data-block-id": blockId, children: [_jsxs("div", { className: "bn-teststep__timeline", children: [_jsx("span", { className: "bn-teststep__number", children: stepNumber }), _jsx("div", { className: "bn-teststep__line" })] }), _jsxs("div", { className: "bn-teststep__content", children: [_jsxs("div", { className: "bn-teststep__horizontal-fields", children: [_jsxs("div", { className: "bn-teststep__horizontal-col", children: [_jsx("div", { className: "bn-teststep__header", children: _jsx("span", { className: "bn-teststep__title", children: "Step" }) }), _jsx(StepField, { label: "Step", showLabel: false, value: stepValue, onChange: onStepChange, placeholder: STEP_PLACEHOLDER, enableAutocomplete: true, fieldName: "title", suggestionFilter: (suggestion) => suggestion.isSnippet !== true, onFieldFocus: onFieldFocus, multiline: true, enableImageUpload: true, showFormattingButtons: true, showImageButton: true })] }), _jsxs("div", { className: "bn-teststep__horizontal-col", children: [_jsxs("div", { className: "bn-teststep__header", children: [_jsx("span", { className: "bn-teststep__title", children: "Expected result" }), viewToggle] }), _jsx(StepField, { label: "Expected result", showLabel: false, value: expectedResult, onChange: onExpectedChange, placeholder: EXPECTED_RESULT_PLACEHOLDER, multiline: true, enableAutocomplete: true, enableImageUpload: true, showFormattingButtons: true, showImageButton: true, onFieldFocus: onFieldFocus })] })] }), _jsx("div", { className: "bn-step-actions", children: _jsxs("button", { type: "button", className: "bn-step-action-btn", onClick: onInsertNextStep, children: [_jsx("svg", { className: "bn-step-action-btn__icon", width: "16", height: "16", viewBox: "0 0 13.334 13.334", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M6.667 0a6.667 6.667 0 1 1 0 13.334A6.667 6.667 0 0 1 6.667 0Zm0 1.334a5.333 5.333 0 1 0 0 10.666 5.333 5.333 0 0 0 0-10.666ZM7.334 3.334V6H10v1.334H7.334V10H6V7.334H3.334V6H6V3.334h1.334Z", fill: "currentColor" }) }), "Add new step"] }) })] })] }));
6
+ return (_jsxs("div", { className: "bn-teststep bn-teststep--horizontal", "data-block-id": blockId, children: [_jsxs("div", { className: "bn-teststep__timeline", children: [_jsx("span", { className: "bn-teststep__number", children: stepNumber }), _jsx("div", { className: "bn-teststep__line" })] }), _jsxs("div", { className: "bn-teststep__content", children: [_jsxs("div", { className: "bn-teststep__header", children: [_jsx("span", { className: "bn-teststep__title", children: "Step" }), viewToggle] }), _jsxs("div", { className: "bn-teststep__horizontal-fields", children: [_jsxs("div", { className: "bn-teststep__horizontal-col", children: [_jsx("div", { className: "bn-teststep__header", children: _jsx("span", { className: "bn-teststep__title", children: "Step" }) }), _jsx(StepField, { label: "Step", showLabel: false, value: stepValue, onChange: onStepChange, placeholder: STEP_PLACEHOLDER, enableAutocomplete: true, fieldName: "title", suggestionFilter: (suggestion) => suggestion.isSnippet !== true, onFieldFocus: onFieldFocus, multiline: true, enableImageUpload: true, showFormattingButtons: true, showImageButton: true })] }), _jsxs("div", { className: "bn-teststep__horizontal-col", children: [_jsx("div", { className: "bn-teststep__header", children: _jsx("span", { className: "bn-teststep__title", children: "Expected result" }) }), _jsx(StepField, { label: "Expected result", showLabel: false, value: expectedResult, onChange: onExpectedChange, placeholder: EXPECTED_RESULT_PLACEHOLDER, multiline: true, enableAutocomplete: true, enableImageUpload: true, showFormattingButtons: true, showImageButton: true, onFieldFocus: onFieldFocus })] })] }), _jsx("div", { className: "bn-step-actions", children: _jsxs("button", { type: "button", className: "bn-step-action-btn", onClick: onInsertNextStep, children: [_jsx("svg", { className: "bn-step-action-btn__icon", width: "16", height: "16", viewBox: "0 0 13.334 13.334", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M6.667 0a6.667 6.667 0 1 1 0 13.334A6.667 6.667 0 0 1 6.667 0Zm0 1.334a5.333 5.333 0 1 0 0 10.666 5.333 5.333 0 0 0 0-10.666ZM7.334 3.334V6H10v1.334H7.334V10H6V7.334H3.334V6H6V3.334h1.334Z", fill: "currentColor" }) }), "Add new step"] }) })] })] }));
7
7
  }
@@ -10,7 +10,9 @@ export function useAutoResize({ textarea, multiline = false, minRows = 2, maxRow
10
10
  const lineHeight = parseFloat(getComputedStyle(textarea).lineHeight || "16");
11
11
  const minHeight = lineHeight * minRows;
12
12
  const maxHeight = lineHeight * maxRows;
13
- textarea.style.height = `${Math.min(Math.max(textarea.scrollHeight, minHeight), maxHeight)}px`;
13
+ const clampedHeight = Math.min(Math.max(textarea.scrollHeight, minHeight), maxHeight);
14
+ textarea.style.height = `${clampedHeight}px`;
15
+ textarea.style.overflowY = textarea.scrollHeight > maxHeight ? "auto" : "hidden";
14
16
  };
15
17
  const observer = new MutationObserver(resize);
16
18
  observer.observe(textarea, { childList: true, characterData: true, subtree: true });
@@ -500,22 +500,10 @@ html.dark .bn-step-image-preview__content {
500
500
  color: #0a0a0a;
501
501
  }
502
502
 
503
- .bn-teststep__view-toggle--horizontal {
503
+ .bn-teststep__view-toggle--horizontal svg {
504
504
  transform: rotate(90deg);
505
505
  }
506
506
 
507
- .bn-teststep__view-toggle[data-tooltip]::after {
508
- top: calc(100% + 6px);
509
- left: 50%;
510
- transform: translateX(-50%);
511
- }
512
-
513
- .bn-teststep__view-toggle--horizontal[data-tooltip]::after {
514
- top: calc(100% + 6px);
515
- left: 50%;
516
- transform: translateX(-50%);
517
- }
518
-
519
507
  .bn-teststep__horizontal-fields {
520
508
  display: flex;
521
509
  gap: 16px;
@@ -997,7 +985,21 @@ html.dark .bn-step-image-preview__content {
997
985
  font-weight: 400;
998
986
  line-height: 20px;
999
987
  color: #262626;
1000
- overflow: visible;
988
+ overflow: hidden;
989
+ }
990
+
991
+ .bn-step-editor .overtype-wrapper .overtype-input {
992
+ scrollbar-width: thin;
993
+ scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
994
+ }
995
+
996
+ .bn-step-editor .overtype-wrapper .overtype-input::-webkit-scrollbar {
997
+ width: 6px;
998
+ }
999
+
1000
+ .bn-step-editor .overtype-wrapper .overtype-input::-webkit-scrollbar-thumb {
1001
+ background: rgba(0, 0, 0, 0.2);
1002
+ border-radius: 3px;
1001
1003
  }
1002
1004
 
1003
1005
  .bn-step-editor--multiline {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testomatio-editor-blocks",
3
- "version": "0.4.20",
3
+ "version": "0.4.22",
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",
@@ -1,5 +1,41 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { customSchema } from "../customSchema";
3
+ import { isEmptyParagraph } from "./step";
4
+
5
+ describe("isEmptyParagraph", () => {
6
+ it("returns true for paragraph with no content", () => {
7
+ expect(isEmptyParagraph({ type: "paragraph", content: [], children: [] })).toBe(true);
8
+ });
9
+
10
+ it("returns true for paragraph with undefined content", () => {
11
+ expect(isEmptyParagraph({ type: "paragraph", children: [] })).toBe(true);
12
+ });
13
+
14
+ it("returns true for paragraph with only whitespace text", () => {
15
+ expect(
16
+ isEmptyParagraph({
17
+ type: "paragraph",
18
+ content: [{ type: "text", text: " " }],
19
+ children: [],
20
+ }),
21
+ ).toBe(true);
22
+ });
23
+
24
+ it("returns false for paragraph with text content", () => {
25
+ expect(
26
+ isEmptyParagraph({
27
+ type: "paragraph",
28
+ content: [{ type: "text", text: "hello" }],
29
+ children: [],
30
+ }),
31
+ ).toBe(false);
32
+ });
33
+
34
+ it("returns false for non-paragraph blocks", () => {
35
+ expect(isEmptyParagraph({ type: "heading", content: [], children: [] })).toBe(false);
36
+ expect(isEmptyParagraph({ type: "testStep", content: [], children: [] })).toBe(false);
37
+ });
38
+ });
3
39
 
4
40
  describe("custom block specs", () => {
5
41
  it("registers the step block", () => {
@@ -47,6 +47,12 @@ const writeStepViewMode = (mode: StepViewMode) => {
47
47
  }
48
48
  };
49
49
 
50
+ export const isEmptyParagraph = (b: any): boolean =>
51
+ b.type === "paragraph" &&
52
+ (!Array.isArray(b.content) ||
53
+ b.content.length === 0 ||
54
+ b.content.every((n: any) => n.type === "text" && !n.text?.trim()));
55
+
50
56
  export const stepBlock = createReactBlockSpec(
51
57
  {
52
58
  type: "testStep",
@@ -91,8 +97,11 @@ export const stepBlock = createReactBlockSpec(
91
97
 
92
98
  let count = 1;
93
99
  for (let i = blockIndex - 1; i >= 0; i--) {
94
- if (allBlocks[i].type === "testStep") {
100
+ const b = allBlocks[i];
101
+ if (b.type === "testStep") {
95
102
  count++;
103
+ } else if (isEmptyParagraph(b)) {
104
+ continue;
96
105
  } else {
97
106
  break;
98
107
  }
@@ -108,7 +117,7 @@ export const stepBlock = createReactBlockSpec(
108
117
 
109
118
  for (let i = blockIndex - 1; i >= 0; i--) {
110
119
  const b = allBlocks[i];
111
- if (b.type === "testStep" || b.type === "snippet") {
120
+ if (b.type === "testStep" || b.type === "snippet" || isEmptyParagraph(b)) {
112
121
  continue;
113
122
  }
114
123
  if (b.type === "heading") {
@@ -35,6 +35,10 @@ export function StepHorizontalView({
35
35
  <div className="bn-teststep__line" />
36
36
  </div>
37
37
  <div className="bn-teststep__content">
38
+ <div className="bn-teststep__header">
39
+ <span className="bn-teststep__title">Step</span>
40
+ {viewToggle}
41
+ </div>
38
42
  <div className="bn-teststep__horizontal-fields">
39
43
  <div className="bn-teststep__horizontal-col">
40
44
  <div className="bn-teststep__header">
@@ -59,7 +63,6 @@ export function StepHorizontalView({
59
63
  <div className="bn-teststep__horizontal-col">
60
64
  <div className="bn-teststep__header">
61
65
  <span className="bn-teststep__title">Expected result</span>
62
- {viewToggle}
63
66
  </div>
64
67
  <StepField
65
68
  label="Expected result"
@@ -21,7 +21,9 @@ export function useAutoResize({ textarea, multiline = false, minRows = 2, maxRow
21
21
  const minHeight = lineHeight * minRows;
22
22
  const maxHeight = lineHeight * maxRows;
23
23
 
24
- textarea.style.height = `${Math.min(Math.max(textarea.scrollHeight, minHeight), maxHeight)}px`;
24
+ const clampedHeight = Math.min(Math.max(textarea.scrollHeight, minHeight), maxHeight);
25
+ textarea.style.height = `${clampedHeight}px`;
26
+ textarea.style.overflowY = textarea.scrollHeight > maxHeight ? "auto" : "hidden";
25
27
  };
26
28
 
27
29
  const observer = new MutationObserver(resize);
@@ -920,6 +920,46 @@ describe("markdownToBlocks", () => {
920
920
  );
921
921
  });
922
922
 
923
+ it("parses multiple steps separated by blank lines", () => {
924
+ const markdown = [
925
+ "## Steps",
926
+ "* asjkldnkasndkj",
927
+ " *Expected*: slkednfkjsdnfkjsdnf",
928
+ "",
929
+ "* sdfnsikdfnsikdn",
930
+ " *Expected*: sedfnskdijfns",
931
+ "",
932
+ "* sdfnksdjfnsdknf",
933
+ " *Expected*: sdjfnskdjfnskdfn",
934
+ ].join("\n");
935
+
936
+ const blocks = markdownToBlocks(markdown);
937
+ const stepBlocks = blocks.filter((block) => block.type === "testStep");
938
+
939
+ expect(stepBlocks).toHaveLength(3);
940
+
941
+ expect(stepBlocks[0].props).toEqual({
942
+ stepTitle: "asjkldnkasndkj",
943
+ stepData: "",
944
+ expectedResult: "slkednfkjsdnfkjsdnf\n",
945
+ listStyle: "bullet",
946
+ });
947
+
948
+ expect(stepBlocks[1].props).toEqual({
949
+ stepTitle: "sdfnsikdfnsikdn",
950
+ stepData: "",
951
+ expectedResult: "sedfnskdijfns\n",
952
+ listStyle: "bullet",
953
+ });
954
+
955
+ expect(stepBlocks[2].props).toEqual({
956
+ stepTitle: "sdfnksdjfnsdknf",
957
+ stepData: "",
958
+ expectedResult: "sdjfnskdjfnskdfn",
959
+ listStyle: "bullet",
960
+ });
961
+ });
962
+
923
963
  it("round-trips simple blocks", () => {
924
964
  const blocks: CustomEditorBlock[] = [
925
965
  {
@@ -500,22 +500,10 @@ html.dark .bn-step-image-preview__content {
500
500
  color: #0a0a0a;
501
501
  }
502
502
 
503
- .bn-teststep__view-toggle--horizontal {
503
+ .bn-teststep__view-toggle--horizontal svg {
504
504
  transform: rotate(90deg);
505
505
  }
506
506
 
507
- .bn-teststep__view-toggle[data-tooltip]::after {
508
- top: calc(100% + 6px);
509
- left: 50%;
510
- transform: translateX(-50%);
511
- }
512
-
513
- .bn-teststep__view-toggle--horizontal[data-tooltip]::after {
514
- top: calc(100% + 6px);
515
- left: 50%;
516
- transform: translateX(-50%);
517
- }
518
-
519
507
  .bn-teststep__horizontal-fields {
520
508
  display: flex;
521
509
  gap: 16px;
@@ -997,7 +985,21 @@ html.dark .bn-step-image-preview__content {
997
985
  font-weight: 400;
998
986
  line-height: 20px;
999
987
  color: #262626;
1000
- overflow: visible;
988
+ overflow: hidden;
989
+ }
990
+
991
+ .bn-step-editor .overtype-wrapper .overtype-input {
992
+ scrollbar-width: thin;
993
+ scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
994
+ }
995
+
996
+ .bn-step-editor .overtype-wrapper .overtype-input::-webkit-scrollbar {
997
+ width: 6px;
998
+ }
999
+
1000
+ .bn-step-editor .overtype-wrapper .overtype-input::-webkit-scrollbar-thumb {
1001
+ background: rgba(0, 0, 0, 0.2);
1002
+ border-radius: 3px;
1001
1003
  }
1002
1004
 
1003
1005
  .bn-step-editor--multiline {