testomatio-editor-blocks 0.4.15 → 0.4.16
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.
|
@@ -68,6 +68,14 @@ export const snippetBlock = createReactBlockSpec({
|
|
|
68
68
|
const snippetSuggestions = useSnippetAutocomplete();
|
|
69
69
|
const hasSnippets = snippetSuggestions.length > 0;
|
|
70
70
|
const isSnippetSelected = snippetId.length > 0;
|
|
71
|
+
const resolvedTitle = useMemo(() => {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
if (snippetTitle)
|
|
74
|
+
return snippetTitle;
|
|
75
|
+
if (!snippetId || snippetSuggestions.length === 0)
|
|
76
|
+
return "";
|
|
77
|
+
return (_b = (_a = snippetSuggestions.find((s) => s.id === snippetId)) === null || _a === void 0 ? void 0 : _a.title) !== null && _b !== void 0 ? _b : "";
|
|
78
|
+
}, [snippetTitle, snippetId, snippetSuggestions]);
|
|
71
79
|
const handleSnippetSelect = useCallback((suggestion) => {
|
|
72
80
|
var _a;
|
|
73
81
|
const rawBody = (_a = suggestion.body) !== null && _a !== void 0 ? _a : "";
|
|
@@ -102,6 +110,11 @@ export const snippetBlock = createReactBlockSpec({
|
|
|
102
110
|
if (!hasSnippets) {
|
|
103
111
|
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." }) }));
|
|
104
112
|
}
|
|
105
|
-
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:
|
|
113
|
+
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: resolvedTitle, placeholder: "Select Snippet", suggestions: snippetSuggestions, selectedId: snippetId, onSelect: handleSnippetSelect })] }), isSnippetSelected && snippetData && (_jsx("div", { className: "bn-snippet__content", dangerouslySetInnerHTML: {
|
|
114
|
+
__html: snippetData
|
|
115
|
+
.replace(/&/g, "&")
|
|
116
|
+
.replace(/</g, "<")
|
|
117
|
+
.replace(/>/g, ">"),
|
|
118
|
+
} }))] }));
|
|
106
119
|
},
|
|
107
120
|
});
|
package/package.json
CHANGED
|
@@ -141,6 +141,12 @@ export const snippetBlock = createReactBlockSpec(
|
|
|
141
141
|
const hasSnippets = snippetSuggestions.length > 0;
|
|
142
142
|
const isSnippetSelected = snippetId.length > 0;
|
|
143
143
|
|
|
144
|
+
const resolvedTitle = useMemo(() => {
|
|
145
|
+
if (snippetTitle) return snippetTitle;
|
|
146
|
+
if (!snippetId || snippetSuggestions.length === 0) return "";
|
|
147
|
+
return snippetSuggestions.find((s) => s.id === snippetId)?.title ?? "";
|
|
148
|
+
}, [snippetTitle, snippetId, snippetSuggestions]);
|
|
149
|
+
|
|
144
150
|
const handleSnippetSelect = useCallback(
|
|
145
151
|
(suggestion: SnippetSuggestion) => {
|
|
146
152
|
const rawBody = suggestion.body ?? "";
|
|
@@ -187,7 +193,7 @@ export const snippetBlock = createReactBlockSpec(
|
|
|
187
193
|
<div className="bn-snippet__header">
|
|
188
194
|
<span className="bn-snippet__label">Snippet</span>
|
|
189
195
|
<SnippetDropdown
|
|
190
|
-
value={
|
|
196
|
+
value={resolvedTitle}
|
|
191
197
|
placeholder="Select Snippet"
|
|
192
198
|
suggestions={snippetSuggestions}
|
|
193
199
|
selectedId={snippetId}
|
|
@@ -195,7 +201,15 @@ export const snippetBlock = createReactBlockSpec(
|
|
|
195
201
|
/>
|
|
196
202
|
</div>
|
|
197
203
|
{isSnippetSelected && snippetData && (
|
|
198
|
-
<div
|
|
204
|
+
<div
|
|
205
|
+
className="bn-snippet__content"
|
|
206
|
+
dangerouslySetInnerHTML={{
|
|
207
|
+
__html: snippetData
|
|
208
|
+
.replace(/&/g, "&")
|
|
209
|
+
.replace(/</g, "<")
|
|
210
|
+
.replace(/>/g, ">"),
|
|
211
|
+
}}
|
|
212
|
+
/>
|
|
199
213
|
)}
|
|
200
214
|
</div>
|
|
201
215
|
);
|