testomatio-editor-blocks 0.4.0 → 0.4.6

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,130 +1,44 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { createReactBlockSpec } from "@blocknote/react";
3
- import OverType from "overtype";
4
3
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
5
- import { StepField } from "./stepField";
6
4
  import { useSnippetAutocomplete } from "../snippetAutocomplete";
7
- import { useStepImageUpload } from "../stepImageUpload";
8
- function SnippetDataField({ label, value, placeholder, onChange, onFieldFocus, fieldName, enableImageUpload = false, }) {
5
+ function SnippetDropdown({ value, placeholder, suggestions, onSelect }) {
6
+ const [isOpen, setIsOpen] = useState(false);
7
+ const [search, setSearch] = useState("");
9
8
  const containerRef = useRef(null);
10
- const instanceRef = useRef(null);
11
- const uploadImage = useStepImageUpload();
12
- const [isFocused, setIsFocused] = useState(false);
13
- const onChangeRef = useRef(onChange);
14
- const initialValueRef = useRef(value);
9
+ const searchRef = useRef(null);
15
10
  useEffect(() => {
16
- onChangeRef.current = onChange;
17
- }, [onChange]);
18
- const insertImageMarkdown = useCallback((url) => {
19
- var _a, _b, _c;
20
- const instance = instanceRef.current;
21
- const textarea = instance === null || instance === void 0 ? void 0 : instance.textarea;
22
- if (!instance || !textarea) {
11
+ if (!isOpen)
23
12
  return;
24
- }
25
- const currentValue = instance.getValue();
26
- const selectionStart = (_a = textarea.selectionStart) !== null && _a !== void 0 ? _a : currentValue.length;
27
- const selectionEnd = (_b = textarea.selectionEnd) !== null && _b !== void 0 ? _b : currentValue.length;
28
- const before = currentValue.slice(0, selectionStart);
29
- const after = currentValue.slice(selectionEnd);
30
- const needsNewlineBefore = before.length > 0 && !before.endsWith("\n");
31
- const needsNewlineAfter = after.length > 0 && !after.startsWith("\n");
32
- const markdown = `${needsNewlineBefore ? "\n" : ""}![](${url})${needsNewlineAfter ? "\n" : ""}`;
33
- const nextValue = `${before}${markdown}${after}`;
34
- instance.setValue(nextValue);
35
- (_c = onChangeRef.current) === null || _c === void 0 ? void 0 : _c.call(onChangeRef, nextValue);
36
- requestAnimationFrame(() => {
37
- const cursor = selectionStart + markdown.length;
38
- textarea.selectionStart = cursor;
39
- textarea.selectionEnd = cursor;
40
- textarea.focus();
41
- });
42
- }, []);
43
- useEffect(() => {
44
- const container = containerRef.current;
45
- if (!container) {
46
- return;
47
- }
48
- const [instance] = OverType.init(container, {
49
- value: initialValueRef.current,
50
- placeholder,
51
- autoResize: true,
52
- minHeight: "5rem",
53
- toolbar: false,
54
- onChange: (nextValue) => {
55
- var _a;
56
- (_a = onChangeRef.current) === null || _a === void 0 ? void 0 : _a.call(onChangeRef, nextValue);
57
- },
58
- });
59
- instanceRef.current = instance;
60
- const textarea = instance.textarea;
61
- if (fieldName) {
62
- textarea.dataset.stepField = fieldName;
63
- }
64
- const handleFocus = () => {
65
- setIsFocused(true);
66
- onFieldFocus === null || onFieldFocus === void 0 ? void 0 : onFieldFocus();
67
- };
68
- const handleBlur = () => setIsFocused(false);
69
- textarea.addEventListener("focus", handleFocus);
70
- textarea.addEventListener("blur", handleBlur);
71
- return () => {
72
- textarea.removeEventListener("focus", handleFocus);
73
- textarea.removeEventListener("blur", handleBlur);
74
- instance.destroy();
75
- instanceRef.current = null;
13
+ const handleMouseDown = (event) => {
14
+ if (containerRef.current && !containerRef.current.contains(event.target)) {
15
+ setIsOpen(false);
16
+ }
76
17
  };
77
- }, [fieldName, onFieldFocus, placeholder]);
18
+ document.addEventListener("mousedown", handleMouseDown);
19
+ return () => document.removeEventListener("mousedown", handleMouseDown);
20
+ }, [isOpen]);
78
21
  useEffect(() => {
79
- const instance = instanceRef.current;
80
- if (!instance) {
81
- return;
82
- }
83
- if (instance.getValue() !== value) {
84
- instance.setValue(value);
85
- }
86
- }, [value]);
87
- useEffect(() => {
88
- var _a;
89
- if (!enableImageUpload || !uploadImage) {
90
- return;
91
- }
92
- const textarea = (_a = instanceRef.current) === null || _a === void 0 ? void 0 : _a.textarea;
93
- if (!textarea) {
94
- return;
22
+ if (isOpen) {
23
+ setSearch("");
24
+ requestAnimationFrame(() => { var _a; return (_a = searchRef.current) === null || _a === void 0 ? void 0 : _a.focus(); });
95
25
  }
96
- const handlePaste = async (event) => {
97
- var _a, _b;
98
- const items = Array.from((_b = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.items) !== null && _b !== void 0 ? _b : []);
99
- const imageItem = items.find((item) => item.kind === "file" && item.type.startsWith("image/"));
100
- const file = imageItem === null || imageItem === void 0 ? void 0 : imageItem.getAsFile();
101
- if (!file) {
102
- return;
103
- }
104
- event.preventDefault();
105
- try {
106
- const response = await uploadImage(file);
107
- if (response === null || response === void 0 ? void 0 : response.url) {
108
- insertImageMarkdown(response.url);
109
- }
110
- }
111
- catch (error) {
112
- console.error("Failed to upload pasted image", error);
113
- }
114
- };
115
- textarea.addEventListener("paste", handlePaste);
116
- return () => {
117
- textarea.removeEventListener("paste", handlePaste);
118
- };
119
- }, [enableImageUpload, insertImageMarkdown, uploadImage]);
120
- const editorClassName = useMemo(() => [
121
- "bn-step-editor",
122
- "bn-step-editor--multiline",
123
- isFocused ? "bn-step-editor--focused" : "",
124
- ]
125
- .filter(Boolean)
126
- .join(" "), [isFocused]);
127
- return (_jsxs("div", { className: "bn-step-field", children: [_jsx("div", { className: "bn-step-field__top", children: _jsx("span", { className: "bn-step-field__label", children: label }) }), _jsx("div", { ref: containerRef, className: editorClassName, "data-step-field": fieldName })] }));
26
+ }, [isOpen]);
27
+ const filtered = useMemo(() => {
28
+ const snippets = suggestions.filter((s) => s.isSnippet === true);
29
+ if (!search)
30
+ return snippets;
31
+ const lower = search.toLowerCase();
32
+ return snippets.filter((s) => s.title.toLowerCase().includes(lower));
33
+ }, [suggestions, search]);
34
+ const handleSearchChange = useCallback((event) => {
35
+ setSearch(event.target.value);
36
+ }, []);
37
+ return (_jsxs("div", { className: "bn-snippet-dropdown", ref: containerRef, children: [_jsxs("button", { type: "button", className: "bn-snippet-dropdown__trigger", onClick: () => setIsOpen((prev) => !prev), children: [_jsx("span", { className: "bn-snippet-dropdown__text", children: value || placeholder }), _jsx("svg", { className: "bn-snippet-dropdown__chevron", width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { d: "M4 6L8 10L12 6", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) })] }), isOpen && (_jsxs("div", { className: "bn-snippet-dropdown__panel", role: "listbox", children: [_jsxs("div", { className: "bn-snippet-dropdown__search", children: [_jsx("svg", { className: "bn-snippet-dropdown__search-icon", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { d: "M15.5 14H14.71L14.43 13.73C15.41 12.59 16 11.11 16 9.5C16 5.91 13.09 3 9.5 3C5.91 3 3 5.91 3 9.5C3 13.09 5.91 16 9.5 16C11.11 16 12.59 15.41 13.73 14.43L14 14.71V15.5L19 20.49L20.49 19L15.5 14ZM9.5 14C7.01 14 5 11.99 5 9.5C5 7.01 7.01 5 9.5 5C11.99 5 14 7.01 14 9.5C14 11.99 11.99 14 9.5 14Z", fill: "currentColor" }) }), _jsx("input", { ref: searchRef, type: "text", className: "bn-snippet-dropdown__search-input", placeholder: "Search", value: search, onChange: handleSearchChange })] }), _jsxs("div", { className: "bn-snippet-dropdown__list", children: [filtered.map((suggestion) => (_jsx("button", { type: "button", role: "option", className: "bn-snippet-dropdown__item", onMouseDown: (event) => {
38
+ event.preventDefault();
39
+ onSelect(suggestion);
40
+ setIsOpen(false);
41
+ }, tabIndex: -1, children: suggestion.title }, suggestion.id))), filtered.length === 0 && (_jsx("div", { className: "bn-snippet-dropdown__empty", children: "No snippets found" }))] })] }))] }));
128
42
  }
129
43
  export const snippetBlock = createReactBlockSpec({
130
44
  type: "snippet",
@@ -151,26 +65,6 @@ export const snippetBlock = createReactBlockSpec({
151
65
  const snippetSuggestions = useSnippetAutocomplete();
152
66
  const hasSnippets = snippetSuggestions.length > 0;
153
67
  const isSnippetSelected = snippetId.length > 0;
154
- const handleSnippetChange = useCallback((nextTitle) => {
155
- if (nextTitle === snippetTitle) {
156
- return;
157
- }
158
- editor.updateBlock(block.id, {
159
- props: {
160
- snippetTitle: nextTitle,
161
- },
162
- });
163
- }, [block.id, editor, snippetTitle]);
164
- const handleSnippetDataChange = useCallback((next) => {
165
- if (next === snippetData) {
166
- return;
167
- }
168
- editor.updateBlock(block.id, {
169
- props: {
170
- snippetData: next,
171
- },
172
- });
173
- }, [editor, block.id, snippetData]);
174
68
  const handleSnippetSelect = useCallback((suggestion) => {
175
69
  var _a;
176
70
  const rawBody = (_a = suggestion.body) !== null && _a !== void 0 ? _a : "";
@@ -192,6 +86,6 @@ export const snippetBlock = createReactBlockSpec({
192
86
  if (!hasSnippets) {
193
87
  return (_jsx("div", { className: "bn-teststep bn-snippet", "data-block-id": block.id, children: _jsx("p", { className: "bn-snippet__empty", children: "No snippets in this project." }) }));
194
88
  }
195
- return (_jsx("div", { className: "bn-teststep bn-snippet", "data-block-id": block.id, children: !isSnippetSelected ? (_jsx(StepField, { label: "Snippet Title", value: snippetTitle, onChange: handleSnippetChange, autoFocus: snippetTitle.length === 0, enableAutocomplete: true, suggestionFilter: (suggestion) => suggestion.isSnippet === true, suggestionsOverride: snippetSuggestions, onSuggestionSelect: handleSnippetSelect, fieldName: "snippet-title", showSuggestionsOnFocus: true, enableImageUpload: false, onFieldFocus: handleFieldFocus, readOnly: false })) : (_jsx(SnippetDataField, { label: `Snippet: ${snippetTitle}`, value: snippetData, onChange: handleSnippetDataChange, fieldName: "snippet-data", enableImageUpload: true, onFieldFocus: handleFieldFocus, placeholder: "Snippet data will appear here..." })) }));
89
+ return (_jsxs("div", { className: "bn-teststep bn-snippet", "data-block-id": block.id, onFocus: handleFieldFocus, children: [_jsxs("div", { className: "bn-snippet__header", children: [_jsx("span", { className: "bn-snippet__label", children: "Snippet" }), _jsx(SnippetDropdown, { value: snippetTitle, placeholder: "Select Snippet", suggestions: snippetSuggestions, onSelect: handleSnippetSelect })] }), isSnippetSelected && (_jsx("div", { className: "bn-snippet__content", children: snippetData }))] }));
196
90
  },
197
91
  });
@@ -12,6 +12,9 @@ export declare const stepBlock: {
12
12
  readonly expectedResult: {
13
13
  readonly default: "";
14
14
  };
15
+ readonly listStyle: {
16
+ readonly default: "bullet";
17
+ };
15
18
  };
16
19
  };
17
20
  implementation: import("@blocknote/core").TiptapBlockImplementation<{
@@ -27,6 +30,9 @@ export declare const stepBlock: {
27
30
  readonly expectedResult: {
28
31
  readonly default: "";
29
32
  };
33
+ readonly listStyle: {
34
+ readonly default: "bullet";
35
+ };
30
36
  };
31
37
  }, any, import("@blocknote/core").InlineContentSchema, import("@blocknote/core").StyleSchema>;
32
38
  };
@@ -1,26 +1,43 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { createReactBlockSpec } from "@blocknote/react";
2
+ import { createReactBlockSpec, useEditorChange } from "@blocknote/react";
3
3
  import { useCallback, useEffect, useMemo, useState } from "react";
4
4
  import { StepField } from "./stepField";
5
+ import { StepHorizontalView } from "./stepHorizontalView";
5
6
  import { useStepImageUpload } from "../stepImageUpload";
6
7
  const EXPECTED_COLLAPSED_KEY = "bn-expected-collapsed";
7
- const readExpectedCollapsedPreference = () => {
8
+ const VIEW_MODE_KEY = "bn-step-view-mode";
9
+ const STEP_TITLE_PLACEHOLDER = "Enter step title...";
10
+ const STEP_DATA_PLACEHOLDER = "Enter step data...";
11
+ const EXPECTED_RESULT_PLACEHOLDER = "Enter expected result...";
12
+ /* readExpectedCollapsedPreference removed — currently unused */
13
+ const writeExpectedCollapsedPreference = (collapsed) => {
8
14
  if (typeof window === "undefined") {
9
- return false;
15
+ return;
10
16
  }
11
17
  try {
12
- return window.localStorage.getItem(EXPECTED_COLLAPSED_KEY) === "true";
18
+ window.localStorage.setItem(EXPECTED_COLLAPSED_KEY, collapsed ? "true" : "false");
13
19
  }
14
20
  catch {
15
- return false;
21
+ //
16
22
  }
17
23
  };
18
- const writeExpectedCollapsedPreference = (collapsed) => {
24
+ const readStepViewMode = () => {
25
+ if (typeof window === "undefined") {
26
+ return "vertical";
27
+ }
28
+ try {
29
+ return window.localStorage.getItem(VIEW_MODE_KEY) === "horizontal" ? "horizontal" : "vertical";
30
+ }
31
+ catch {
32
+ return "vertical";
33
+ }
34
+ };
35
+ const writeStepViewMode = (mode) => {
19
36
  if (typeof window === "undefined") {
20
37
  return;
21
38
  }
22
39
  try {
23
- window.localStorage.setItem(EXPECTED_COLLAPSED_KEY, collapsed ? "true" : "false");
40
+ window.localStorage.setItem(VIEW_MODE_KEY, mode);
24
41
  }
25
42
  catch {
26
43
  //
@@ -39,6 +56,9 @@ export const stepBlock = createReactBlockSpec({
39
56
  expectedResult: {
40
57
  default: "",
41
58
  },
59
+ listStyle: {
60
+ default: "bullet",
61
+ },
42
62
  },
43
63
  }, {
44
64
  render: ({ block, editor }) => {
@@ -46,19 +66,62 @@ export const stepBlock = createReactBlockSpec({
46
66
  const stepData = block.props.stepData || "";
47
67
  const expectedResult = block.props.expectedResult || "";
48
68
  const expectedHasContent = expectedResult.trim().length > 0;
49
- const storedExpectedCollapsed = useMemo(() => readExpectedCollapsedPreference(), []);
69
+ /* storedExpectedCollapsed removed currently unused */
50
70
  const dataHasContent = stepData.trim().length > 0;
51
- const [isExpectedVisible, setIsExpectedVisible] = useState(expectedHasContent ? true : !storedExpectedCollapsed);
71
+ const [isExpectedVisible, setIsExpectedVisible] = useState(expectedHasContent);
52
72
  const [isDataVisible, setIsDataVisible] = useState(dataHasContent);
53
73
  const [shouldFocusDataField, setShouldFocusDataField] = useState(false);
74
+ const [documentVersion, setDocumentVersion] = useState(0);
54
75
  const uploadImage = useStepImageUpload();
76
+ const [viewMode, setViewMode] = useState(() => readStepViewMode());
55
77
  // Calculate step number based on position in document
56
78
  const stepNumber = useMemo(() => {
57
79
  const allBlocks = editor.document;
58
80
  const stepBlocks = allBlocks.filter((b) => b.type === "testStep");
59
81
  const index = stepBlocks.findIndex((b) => b.id === block.id);
60
82
  return index >= 0 ? index + 1 : 1;
61
- }, [editor.document, block.id]);
83
+ }, [block.id, documentVersion, editor.document]);
84
+ useEditorChange(() => {
85
+ setDocumentVersion((version) => version + 1);
86
+ }, editor);
87
+ useEffect(() => {
88
+ if (typeof window === "undefined") {
89
+ return;
90
+ }
91
+ const handleStorage = (event) => {
92
+ if (event.key === VIEW_MODE_KEY) {
93
+ setViewMode(readStepViewMode());
94
+ }
95
+ };
96
+ const handleLocal = () => {
97
+ setViewMode(readStepViewMode());
98
+ };
99
+ window.addEventListener("storage", handleStorage);
100
+ window.addEventListener("bn-step-view-mode", handleLocal);
101
+ return () => {
102
+ window.removeEventListener("storage", handleStorage);
103
+ window.removeEventListener("bn-step-view-mode", handleLocal);
104
+ };
105
+ }, []);
106
+ const combinedStepValue = useMemo(() => {
107
+ if (!stepData) {
108
+ return stepTitle;
109
+ }
110
+ return stepTitle ? `${stepTitle}\n${stepData}` : stepData;
111
+ }, [stepData, stepTitle]);
112
+ const handleCombinedStepChange = useCallback((next) => {
113
+ if (next === combinedStepValue) {
114
+ return;
115
+ }
116
+ const [nextTitle = "", ...rest] = next.split("\n");
117
+ const nextData = rest.join("\n");
118
+ editor.updateBlock(block.id, {
119
+ props: {
120
+ stepTitle: nextTitle,
121
+ stepData: nextData,
122
+ },
123
+ });
124
+ }, [block.id, combinedStepValue, editor]);
62
125
  useEffect(() => {
63
126
  if (dataHasContent && !isDataVisible) {
64
127
  setIsDataVisible(true);
@@ -115,8 +178,29 @@ export const stepBlock = createReactBlockSpec({
115
178
  ], block.id, "after");
116
179
  }, [editor, block.id]);
117
180
  const handleFieldFocus = useCallback(() => {
118
- editor.setSelection(block.id, block.id);
181
+ var _a, _b, _c;
182
+ const selection = editor.getSelection();
183
+ const blocks = (_a = selection === null || selection === void 0 ? void 0 : selection.blocks) !== null && _a !== void 0 ? _a : [];
184
+ const firstId = (_b = blocks[0]) === null || _b === void 0 ? void 0 : _b.id;
185
+ const lastId = (_c = blocks[blocks.length - 1]) === null || _c === void 0 ? void 0 : _c.id;
186
+ if (firstId === block.id && lastId === block.id) {
187
+ return;
188
+ }
189
+ try {
190
+ editor.setSelection(block.id, block.id);
191
+ }
192
+ catch {
193
+ //
194
+ }
119
195
  }, [editor, block.id]);
196
+ const handleToggleView = useCallback(() => {
197
+ const next = viewMode === "horizontal" ? "vertical" : "horizontal";
198
+ writeStepViewMode(next);
199
+ setViewMode(next);
200
+ if (typeof window !== "undefined") {
201
+ window.dispatchEvent(new Event("bn-step-view-mode"));
202
+ }
203
+ }, [viewMode]);
120
204
  const [dataFocusSignal] = useState(0);
121
205
  const [expectedFocusSignal, setExpectedFocusSignal] = useState(0);
122
206
  const handleShowExpected = useCallback(() => {
@@ -135,46 +219,29 @@ export const stepBlock = createReactBlockSpec({
135
219
  }, [expectedHasContent, isExpectedVisible]);
136
220
  const canToggleData = !dataHasContent;
137
221
  const canToggleExpected = !expectedHasContent;
138
- return (_jsxs("div", { className: "bn-teststep", "data-block-id": block.id, children: [_jsx(StepField, { label: `Step ${stepNumber}`, value: stepTitle, onChange: handleStepTitleChange, autoFocus: stepTitle.length === 0, enableAutocomplete: true, fieldName: "title", suggestionFilter: (suggestion) => suggestion.isSnippet !== true, onFieldFocus: handleFieldFocus, enableImageUpload: false, showFormattingButtons: true, onImageFile: async (file) => {
139
- if (!uploadImage) {
140
- return;
141
- }
142
- setIsDataVisible(true);
143
- setShouldFocusDataField(true);
144
- try {
145
- const result = await uploadImage(file);
146
- if (result === null || result === void 0 ? void 0 : result.url) {
147
- const nextValue = stepData.trim().length > 0 ? `${stepData}\n![](${result.url})` : `![](${result.url})`;
148
- editor.updateBlock(block.id, {
149
- props: {
150
- stepData: nextValue,
151
- },
152
- });
153
- }
154
- }
155
- catch (error) {
156
- console.error("Failed to upload image to Step Data", error);
157
- }
158
- } }), isDataVisible ? (_jsx(StepField, { label: "Step Data", labelToggle: canToggleData
159
- ? {
160
- onClick: handleHideData,
161
- expanded: true,
162
- }
163
- : undefined, value: stepData, onChange: handleStepDataChange, autoFocus: shouldFocusDataField, focusSignal: dataFocusSignal, multiline: true, enableImageUpload: true, showFormattingButtons: true, showImageButton: true, onFieldFocus: handleFieldFocus })) : (_jsx("div", { className: "bn-step-field bn-step-field--collapsed", children: _jsx("span", { className: "bn-step-field__label bn-step-field__label--toggle", role: "button", tabIndex: -1, onClick: handleShowData, onKeyDown: (event) => {
164
- if (event.key === "Enter" || event.key === " ") {
165
- event.preventDefault();
166
- handleShowData();
167
- }
168
- }, "aria-expanded": "false", children: "Step Data" }) })), isExpectedVisible ? (_jsx(StepField, { label: "Expected Result", labelToggle: canToggleExpected
169
- ? {
170
- onClick: handleHideExpected,
171
- expanded: true,
172
- }
173
- : undefined, value: expectedResult, onChange: handleExpectedChange, multiline: true, focusSignal: expectedFocusSignal, enableImageUpload: true, showFormattingButtons: true, showImageButton: true, onFieldFocus: handleFieldFocus })) : (_jsx("div", { className: "bn-step-field bn-step-field--collapsed", children: _jsx("span", { className: "bn-step-field__label bn-step-field__label--toggle", role: "button", tabIndex: -1, onClick: handleShowExpected, onKeyDown: (event) => {
174
- if (event.key === "Enter" || event.key === " ") {
175
- event.preventDefault();
176
- handleShowExpected();
177
- }
178
- }, "aria-expanded": "false", children: "Expected Result" }) })), _jsx("button", { type: "button", className: "bn-step-add", onClick: handleInsertNextStep, children: "+ Step" })] }));
222
+ if (viewMode === "horizontal") {
223
+ return (_jsx(StepHorizontalView, { blockId: block.id, stepNumber: stepNumber, stepValue: combinedStepValue, expectedResult: expectedResult, onStepChange: handleCombinedStepChange, onExpectedChange: handleExpectedChange, onInsertNextStep: handleInsertNextStep, onFieldFocus: handleFieldFocus, viewToggle: _jsx("button", { type: "button", className: "bn-teststep__view-toggle bn-teststep__view-toggle--horizontal", "aria-label": "Switch step view", onClick: handleToggleView, children: _jsxs("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: [_jsx("mask", { id: "mask-toggle", style: { maskType: "alpha" }, maskUnits: "userSpaceOnUse", x: "0", y: "0", width: "16", height: "16", children: _jsx("rect", { width: "16", height: "16", fill: "#D9D9D9" }) }), _jsx("g", { mask: "url(#mask-toggle)", children: _jsx("path", { d: "M12.6667 2C13.0333 2 13.3472 2.13056 13.6083 2.39167C13.8694 2.65278 14 2.96667 14 3.33333L14 12.6667C14 13.0333 13.8694 13.3472 13.6083 13.6083C13.3472 13.8694 13.0333 14 12.6667 14L10 14C9.63333 14 9.31944 13.8694 9.05833 13.6083C8.79722 13.3472 8.66667 13.0333 8.66667 12.6667L8.66667 3.33333C8.66667 2.96667 8.79722 2.65278 9.05833 2.39167C9.31945 2.13055 9.63333 2 10 2L12.6667 2ZM6 2C6.36667 2 6.68056 2.13055 6.94167 2.39167C7.20278 2.65278 7.33333 2.96667 7.33333 3.33333L7.33333 12.6667C7.33333 13.0333 7.20278 13.3472 6.94167 13.6083C6.68055 13.8694 6.36667 14 6 14L3.33333 14C2.96667 14 2.65278 13.8694 2.39167 13.6083C2.13056 13.3472 2 13.0333 2 12.6667L2 3.33333C2 2.96667 2.13056 2.65278 2.39167 2.39167C2.65278 2.13055 2.96667 2 3.33333 2L6 2ZM3.33333 12.6667L6 12.6667L6 3.33333L3.33333 3.33333L3.33333 12.6667Z", fill: "currentColor" }) })] }) }) }));
224
+ }
225
+ return (_jsxs("div", { className: "bn-teststep", "data-block-id": block.id, 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" }), _jsx("button", { type: "button", className: "bn-teststep__view-toggle", "aria-label": "Switch step view", onClick: handleToggleView, children: _jsxs("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: [_jsx("mask", { id: "mask-toggle", style: { maskType: "alpha" }, maskUnits: "userSpaceOnUse", x: "0", y: "0", width: "16", height: "16", children: _jsx("rect", { width: "16", height: "16", fill: "#D9D9D9" }) }), _jsx("g", { mask: "url(#mask-toggle)", children: _jsx("path", { d: "M12.6667 2C13.0333 2 13.3472 2.13056 13.6083 2.39167C13.8694 2.65278 14 2.96667 14 3.33333L14 12.6667C14 13.0333 13.8694 13.3472 13.6083 13.6083C13.3472 13.8694 13.0333 14 12.6667 14L10 14C9.63333 14 9.31944 13.8694 9.05833 13.6083C8.79722 13.3472 8.66667 13.0333 8.66667 12.6667L8.66667 3.33333C8.66667 2.96667 8.79722 2.65278 9.05833 2.39167C9.31945 2.13055 9.63333 2 10 2L12.6667 2ZM6 2C6.36667 2 6.68056 2.13055 6.94167 2.39167C7.20278 2.65278 7.33333 2.96667 7.33333 3.33333L7.33333 12.6667C7.33333 13.0333 7.20278 13.3472 6.94167 13.6083C6.68055 13.8694 6.36667 14 6 14L3.33333 14C2.96667 14 2.65278 13.8694 2.39167 13.6083C2.13056 13.3472 2 13.0333 2 12.6667L2 3.33333C2 2.96667 2.13056 2.65278 2.39167 2.39167C2.65278 2.13055 2.96667 2 3.33333 2L6 2ZM3.33333 12.6667L6 12.6667L6 3.33333L3.33333 3.33333L3.33333 12.6667Z", fill: "currentColor" }) })] }) })] }), _jsx(StepField, { label: "Step", showLabel: false, value: stepTitle, placeholder: STEP_TITLE_PLACEHOLDER, onChange: handleStepTitleChange, autoFocus: stepTitle.length === 0, enableAutocomplete: true, fieldName: "title", suggestionFilter: (suggestion) => suggestion.isSnippet !== true, onFieldFocus: handleFieldFocus, enableImageUpload: false, showFormattingButtons: true, onImageFile: async (file) => {
226
+ if (!uploadImage) {
227
+ return;
228
+ }
229
+ setIsDataVisible(true);
230
+ setShouldFocusDataField(true);
231
+ try {
232
+ const result = await uploadImage(file);
233
+ if (result === null || result === void 0 ? void 0 : result.url) {
234
+ const nextValue = stepData.trim().length > 0 ? `${stepData}\n![](${result.url})` : `![](${result.url})`;
235
+ editor.updateBlock(block.id, {
236
+ props: {
237
+ stepData: nextValue,
238
+ },
239
+ });
240
+ }
241
+ }
242
+ catch (error) {
243
+ console.error("Failed to upload image to Step Data", error);
244
+ }
245
+ } }), isDataVisible ? (_jsx(StepField, { label: "Step data", placeholder: STEP_DATA_PLACEHOLDER, labelAction: canToggleData ? (_jsx("button", { type: "button", className: "bn-step-field__dismiss", onClick: handleHideData, "aria-label": "Hide step data", children: "\u00D7" })) : undefined, value: stepData, onChange: handleStepDataChange, autoFocus: shouldFocusDataField, focusSignal: dataFocusSignal, multiline: true, enableAutocomplete: true, enableImageUpload: true, showFormattingButtons: true, showImageButton: true, onFieldFocus: handleFieldFocus })) : null, isExpectedVisible ? (_jsx(StepField, { label: "Expected result", placeholder: EXPECTED_RESULT_PLACEHOLDER, labelAction: canToggleExpected ? (_jsx("button", { type: "button", className: "bn-step-field__dismiss", onClick: handleHideExpected, tabIndex: -1, "aria-label": "Hide expected result", children: "\u00D7" })) : undefined, value: expectedResult, onChange: handleExpectedChange, multiline: true, focusSignal: expectedFocusSignal, enableAutocomplete: true, enableImageUpload: true, showFormattingButtons: true, showImageButton: true, onFieldFocus: handleFieldFocus })) : null, _jsxs("div", { className: "bn-step-actions", children: [_jsxs("button", { type: "button", className: "bn-step-action-btn", onClick: handleInsertNextStep, 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"] }), !isDataVisible && (_jsxs("button", { type: "button", className: "bn-step-action-btn", onClick: handleShowData, children: [_jsx("svg", { className: "bn-step-action-btn__icon", width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: _jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M8.666 7.333H12.666V8.667H8.666V12.667H7.332V8.667H3.332V7.333H7.332V3.333H8.666V7.333Z", fill: "currentColor" }) }), "Step data"] })), !isExpectedVisible && (_jsxs("button", { type: "button", className: "bn-step-action-btn", onClick: handleShowExpected, children: [_jsx("svg", { className: "bn-step-action-btn__icon", width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: _jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M8.666 7.333H12.666V8.667H8.666V12.667H7.332V8.667H3.332V7.333H7.332V3.333H8.666V7.333Z", fill: "currentColor" }) }), "Expected result"] }))] })] })] }));
179
246
  },
180
247
  });
@@ -4,10 +4,13 @@ import { type SnippetSuggestion } from "../snippetAutocomplete";
4
4
  type Suggestion = StepSuggestion | SnippetSuggestion;
5
5
  type StepFieldProps = {
6
6
  label: string;
7
+ showLabel?: boolean;
7
8
  labelToggle?: {
8
9
  onClick: () => void;
9
10
  expanded: boolean;
10
11
  };
12
+ labelAction?: ReactNode;
13
+ placeholder?: string;
11
14
  value: string;
12
15
  onChange: (nextValue: string) => void;
13
16
  autoFocus?: boolean;
@@ -27,5 +30,5 @@ type StepFieldProps = {
27
30
  showImageButton?: boolean;
28
31
  onFieldFocus?: () => void;
29
32
  };
30
- export declare function StepField({ label, labelToggle, value, onChange, autoFocus, focusSignal, multiline, enableAutocomplete, fieldName, suggestionFilter, suggestionsOverride, onSuggestionSelect, readOnly, showSuggestionsOnFocus, enableImageUpload, onImageFile, rightAction, showFormattingButtons, showImageButton, onFieldFocus, }: StepFieldProps): import("react/jsx-runtime").JSX.Element;
33
+ export declare function StepField({ label, showLabel, labelToggle, labelAction, placeholder, value, onChange, autoFocus, focusSignal, multiline, enableAutocomplete, fieldName, suggestionFilter, suggestionsOverride, onSuggestionSelect, readOnly, showSuggestionsOnFocus, enableImageUpload, onImageFile, rightAction, showFormattingButtons, showImageButton, onFieldFocus, }: StepFieldProps): import("react/jsx-runtime").JSX.Element;
31
34
  export {};