testomatio-editor-blocks 0.3.0 → 0.4.1
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.
- package/package/editor/blocks/snippet.js +42 -23
- package/package/editor/blocks/step.js +166 -35
- package/package/editor/blocks/stepField.d.ts +9 -1
- package/package/editor/blocks/stepField.js +664 -34
- package/package/editor/blocks/stepHorizontalView.d.ts +14 -0
- package/package/editor/blocks/stepHorizontalView.js +7 -0
- package/package/editor/blocks/useAutoResize.d.ts +8 -0
- package/package/editor/blocks/useAutoResize.js +31 -0
- package/package/editor/customMarkdownConverter.d.ts +1 -0
- package/package/editor/customMarkdownConverter.js +260 -31
- package/package/styles.css +706 -130
- package/package.json +9 -2
- package/src/App.tsx +1 -1
- package/src/editor/blocks/markdown.ts +27 -7
- package/src/editor/blocks/snippet.tsx +117 -61
- package/src/editor/blocks/step.tsx +325 -87
- package/src/editor/blocks/stepField.tsx +1396 -299
- package/src/editor/blocks/stepHorizontalView.tsx +90 -0
- package/src/editor/blocks/useAutoResize.ts +44 -0
- package/src/editor/customMarkdownConverter.test.ts +542 -3
- package/src/editor/customMarkdownConverter.ts +310 -36
- package/src/editor/customSchema.test.ts +35 -0
- package/src/editor/markdownToBlocks.test.ts +119 -0
- package/src/editor/styles.css +827 -128
|
@@ -1,8 +1,45 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { createReactBlockSpec } from "@blocknote/react";
|
|
3
|
-
import { useCallback } from "react";
|
|
4
|
-
import { StepField } from "./stepField";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
4
|
import { useSnippetAutocomplete } from "../snippetAutocomplete";
|
|
5
|
+
function SnippetDropdown({ value, placeholder, suggestions, onSelect }) {
|
|
6
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
7
|
+
const [search, setSearch] = useState("");
|
|
8
|
+
const containerRef = useRef(null);
|
|
9
|
+
const searchRef = useRef(null);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!isOpen)
|
|
12
|
+
return;
|
|
13
|
+
const handleMouseDown = (event) => {
|
|
14
|
+
if (containerRef.current && !containerRef.current.contains(event.target)) {
|
|
15
|
+
setIsOpen(false);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
document.addEventListener("mousedown", handleMouseDown);
|
|
19
|
+
return () => document.removeEventListener("mousedown", handleMouseDown);
|
|
20
|
+
}, [isOpen]);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (isOpen) {
|
|
23
|
+
setSearch("");
|
|
24
|
+
requestAnimationFrame(() => { var _a; return (_a = searchRef.current) === null || _a === void 0 ? void 0 : _a.focus(); });
|
|
25
|
+
}
|
|
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" }))] })] }))] }));
|
|
42
|
+
}
|
|
6
43
|
export const snippetBlock = createReactBlockSpec({
|
|
7
44
|
type: "snippet",
|
|
8
45
|
content: "none",
|
|
@@ -24,28 +61,10 @@ export const snippetBlock = createReactBlockSpec({
|
|
|
24
61
|
render: ({ block, editor }) => {
|
|
25
62
|
const snippetTitle = block.props.snippetTitle || "";
|
|
26
63
|
const snippetData = block.props.snippetData || "";
|
|
64
|
+
const snippetId = block.props.snippetId || "";
|
|
27
65
|
const snippetSuggestions = useSnippetAutocomplete();
|
|
28
66
|
const hasSnippets = snippetSuggestions.length > 0;
|
|
29
|
-
const
|
|
30
|
-
if (nextTitle === snippetTitle) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
editor.updateBlock(block.id, {
|
|
34
|
-
props: {
|
|
35
|
-
snippetTitle: nextTitle,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
}, [block.id, editor, snippetTitle]);
|
|
39
|
-
const handleSnippetDataChange = useCallback((next) => {
|
|
40
|
-
if (next === snippetData) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
editor.updateBlock(block.id, {
|
|
44
|
-
props: {
|
|
45
|
-
snippetData: next,
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
}, [editor, block.id, snippetData]);
|
|
67
|
+
const isSnippetSelected = snippetId.length > 0;
|
|
49
68
|
const handleSnippetSelect = useCallback((suggestion) => {
|
|
50
69
|
var _a;
|
|
51
70
|
const rawBody = (_a = suggestion.body) !== null && _a !== void 0 ? _a : "";
|
|
@@ -67,6 +86,6 @@ export const snippetBlock = createReactBlockSpec({
|
|
|
67
86
|
if (!hasSnippets) {
|
|
68
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." }) }));
|
|
69
88
|
}
|
|
70
|
-
return (_jsxs("div", { className: "bn-teststep bn-snippet", "data-block-id": block.id, children: [
|
|
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 }))] }));
|
|
71
90
|
},
|
|
72
91
|
});
|
|
@@ -1,8 +1,48 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { createReactBlockSpec } from "@blocknote/react";
|
|
3
|
-
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { createReactBlockSpec, useEditorChange } from "@blocknote/react";
|
|
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";
|
|
7
|
+
const EXPECTED_COLLAPSED_KEY = "bn-expected-collapsed";
|
|
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) => {
|
|
14
|
+
if (typeof window === "undefined") {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
window.localStorage.setItem(EXPECTED_COLLAPSED_KEY, collapsed ? "true" : "false");
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
//
|
|
22
|
+
}
|
|
23
|
+
};
|
|
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) => {
|
|
36
|
+
if (typeof window === "undefined") {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
window.localStorage.setItem(VIEW_MODE_KEY, mode);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
//
|
|
44
|
+
}
|
|
45
|
+
};
|
|
6
46
|
export const stepBlock = createReactBlockSpec({
|
|
7
47
|
type: "testStep",
|
|
8
48
|
content: "none",
|
|
@@ -22,22 +62,68 @@ export const stepBlock = createReactBlockSpec({
|
|
|
22
62
|
const stepTitle = block.props.stepTitle || "";
|
|
23
63
|
const stepData = block.props.stepData || "";
|
|
24
64
|
const expectedResult = block.props.expectedResult || "";
|
|
25
|
-
const
|
|
26
|
-
|
|
65
|
+
const expectedHasContent = expectedResult.trim().length > 0;
|
|
66
|
+
/* storedExpectedCollapsed removed — currently unused */
|
|
67
|
+
const dataHasContent = stepData.trim().length > 0;
|
|
68
|
+
const [isExpectedVisible, setIsExpectedVisible] = useState(expectedHasContent);
|
|
69
|
+
const [isDataVisible, setIsDataVisible] = useState(dataHasContent);
|
|
27
70
|
const [shouldFocusDataField, setShouldFocusDataField] = useState(false);
|
|
71
|
+
const [documentVersion, setDocumentVersion] = useState(0);
|
|
28
72
|
const uploadImage = useStepImageUpload();
|
|
73
|
+
const [viewMode, setViewMode] = useState(() => readStepViewMode());
|
|
74
|
+
// Calculate step number based on position in document
|
|
75
|
+
const stepNumber = useMemo(() => {
|
|
76
|
+
const allBlocks = editor.document;
|
|
77
|
+
const stepBlocks = allBlocks.filter((b) => b.type === "testStep");
|
|
78
|
+
const index = stepBlocks.findIndex((b) => b.id === block.id);
|
|
79
|
+
return index >= 0 ? index + 1 : 1;
|
|
80
|
+
}, [block.id, documentVersion, editor.document]);
|
|
81
|
+
useEditorChange(() => {
|
|
82
|
+
setDocumentVersion((version) => version + 1);
|
|
83
|
+
}, editor);
|
|
29
84
|
useEffect(() => {
|
|
30
|
-
if (
|
|
31
|
-
|
|
85
|
+
if (typeof window === "undefined") {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const handleStorage = (event) => {
|
|
89
|
+
if (event.key === VIEW_MODE_KEY) {
|
|
90
|
+
setViewMode(readStepViewMode());
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const handleLocal = () => {
|
|
94
|
+
setViewMode(readStepViewMode());
|
|
95
|
+
};
|
|
96
|
+
window.addEventListener("storage", handleStorage);
|
|
97
|
+
window.addEventListener("bn-step-view-mode", handleLocal);
|
|
98
|
+
return () => {
|
|
99
|
+
window.removeEventListener("storage", handleStorage);
|
|
100
|
+
window.removeEventListener("bn-step-view-mode", handleLocal);
|
|
101
|
+
};
|
|
102
|
+
}, []);
|
|
103
|
+
const combinedStepValue = useMemo(() => {
|
|
104
|
+
if (!stepData) {
|
|
105
|
+
return stepTitle;
|
|
106
|
+
}
|
|
107
|
+
return stepTitle ? `${stepTitle}\n${stepData}` : stepData;
|
|
108
|
+
}, [stepData, stepTitle]);
|
|
109
|
+
const handleCombinedStepChange = useCallback((next) => {
|
|
110
|
+
if (next === combinedStepValue) {
|
|
111
|
+
return;
|
|
32
112
|
}
|
|
33
|
-
|
|
113
|
+
const [nextTitle = "", ...rest] = next.split("\n");
|
|
114
|
+
const nextData = rest.join("\n");
|
|
115
|
+
editor.updateBlock(block.id, {
|
|
116
|
+
props: {
|
|
117
|
+
stepTitle: nextTitle,
|
|
118
|
+
stepData: nextData,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}, [block.id, combinedStepValue, editor]);
|
|
34
122
|
useEffect(() => {
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
return () => clearTimeout(timer);
|
|
123
|
+
if (dataHasContent && !isDataVisible) {
|
|
124
|
+
setIsDataVisible(true);
|
|
38
125
|
}
|
|
39
|
-
|
|
40
|
-
}, [isDataVisible, shouldFocusDataField]);
|
|
126
|
+
}, [dataHasContent, isDataVisible]);
|
|
41
127
|
const handleStepTitleChange = useCallback((next) => {
|
|
42
128
|
if (next === stepTitle) {
|
|
43
129
|
return;
|
|
@@ -58,10 +144,13 @@ export const stepBlock = createReactBlockSpec({
|
|
|
58
144
|
},
|
|
59
145
|
});
|
|
60
146
|
}, [editor, block.id, stepData]);
|
|
61
|
-
const
|
|
147
|
+
const handleShowData = useCallback(() => {
|
|
62
148
|
setIsDataVisible(true);
|
|
63
149
|
setShouldFocusDataField(true);
|
|
64
150
|
}, []);
|
|
151
|
+
const handleHideData = useCallback(() => {
|
|
152
|
+
setIsDataVisible(false);
|
|
153
|
+
}, []);
|
|
65
154
|
const handleExpectedChange = useCallback((next) => {
|
|
66
155
|
if (next === expectedResult) {
|
|
67
156
|
return;
|
|
@@ -86,28 +175,70 @@ export const stepBlock = createReactBlockSpec({
|
|
|
86
175
|
], block.id, "after");
|
|
87
176
|
}, [editor, block.id]);
|
|
88
177
|
const handleFieldFocus = useCallback(() => {
|
|
89
|
-
|
|
178
|
+
var _a, _b, _c;
|
|
179
|
+
const selection = editor.getSelection();
|
|
180
|
+
const blocks = (_a = selection === null || selection === void 0 ? void 0 : selection.blocks) !== null && _a !== void 0 ? _a : [];
|
|
181
|
+
const firstId = (_b = blocks[0]) === null || _b === void 0 ? void 0 : _b.id;
|
|
182
|
+
const lastId = (_c = blocks[blocks.length - 1]) === null || _c === void 0 ? void 0 : _c.id;
|
|
183
|
+
if (firstId === block.id && lastId === block.id) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
editor.setSelection(block.id, block.id);
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
//
|
|
191
|
+
}
|
|
90
192
|
}, [editor, block.id]);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
193
|
+
const handleToggleView = useCallback(() => {
|
|
194
|
+
const next = viewMode === "horizontal" ? "vertical" : "horizontal";
|
|
195
|
+
writeStepViewMode(next);
|
|
196
|
+
setViewMode(next);
|
|
197
|
+
if (typeof window !== "undefined") {
|
|
198
|
+
window.dispatchEvent(new Event("bn-step-view-mode"));
|
|
199
|
+
}
|
|
200
|
+
}, [viewMode]);
|
|
201
|
+
const [dataFocusSignal] = useState(0);
|
|
202
|
+
const [expectedFocusSignal, setExpectedFocusSignal] = useState(0);
|
|
203
|
+
const handleShowExpected = useCallback(() => {
|
|
204
|
+
setIsExpectedVisible(true);
|
|
205
|
+
setExpectedFocusSignal((value) => value + 1);
|
|
206
|
+
writeExpectedCollapsedPreference(false);
|
|
207
|
+
}, []);
|
|
208
|
+
const handleHideExpected = useCallback(() => {
|
|
209
|
+
setIsExpectedVisible(false);
|
|
210
|
+
writeExpectedCollapsedPreference(true);
|
|
211
|
+
}, []);
|
|
212
|
+
useEffect(() => {
|
|
213
|
+
if (expectedHasContent && !isExpectedVisible) {
|
|
214
|
+
setIsExpectedVisible(true);
|
|
215
|
+
}
|
|
216
|
+
}, [expectedHasContent, isExpectedVisible]);
|
|
217
|
+
const canToggleData = !dataHasContent;
|
|
218
|
+
const canToggleExpected = !expectedHasContent;
|
|
219
|
+
if (viewMode === "horizontal") {
|
|
220
|
+
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" }) })] }) }) }));
|
|
221
|
+
}
|
|
222
|
+
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) => {
|
|
223
|
+
if (!uploadImage) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
setIsDataVisible(true);
|
|
227
|
+
setShouldFocusDataField(true);
|
|
228
|
+
try {
|
|
229
|
+
const result = await uploadImage(file);
|
|
230
|
+
if (result === null || result === void 0 ? void 0 : result.url) {
|
|
231
|
+
const nextValue = stepData.trim().length > 0 ? `${stepData}\n` : ``;
|
|
232
|
+
editor.updateBlock(block.id, {
|
|
233
|
+
props: {
|
|
234
|
+
stepData: nextValue,
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
console.error("Failed to upload image to Step Data", error);
|
|
241
|
+
}
|
|
242
|
+
} }), 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"] }))] })] })] }));
|
|
112
243
|
},
|
|
113
244
|
});
|
|
@@ -4,9 +4,17 @@ import { type SnippetSuggestion } from "../snippetAutocomplete";
|
|
|
4
4
|
type Suggestion = StepSuggestion | SnippetSuggestion;
|
|
5
5
|
type StepFieldProps = {
|
|
6
6
|
label: string;
|
|
7
|
+
showLabel?: boolean;
|
|
8
|
+
labelToggle?: {
|
|
9
|
+
onClick: () => void;
|
|
10
|
+
expanded: boolean;
|
|
11
|
+
};
|
|
12
|
+
labelAction?: ReactNode;
|
|
13
|
+
placeholder?: string;
|
|
7
14
|
value: string;
|
|
8
15
|
onChange: (nextValue: string) => void;
|
|
9
16
|
autoFocus?: boolean;
|
|
17
|
+
focusSignal?: number;
|
|
10
18
|
multiline?: boolean;
|
|
11
19
|
enableAutocomplete?: boolean;
|
|
12
20
|
fieldName?: string;
|
|
@@ -22,5 +30,5 @@ type StepFieldProps = {
|
|
|
22
30
|
showImageButton?: boolean;
|
|
23
31
|
onFieldFocus?: () => void;
|
|
24
32
|
};
|
|
25
|
-
export declare function StepField({ label, value, onChange, autoFocus, 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;
|
|
26
34
|
export {};
|