diff --git a/frontend/src/app/plugins/api.cljs b/frontend/src/app/plugins/api.cljs index aec912d5e9..a9b1e4d323 100644 --- a/frontend/src/app/plugins/api.cljs +++ b/frontend/src/app/plugins/api.cljs @@ -379,9 +379,12 @@ :createText (fn [text] (cond - (or (not (string? text)) (empty? text)) + (not (string? text)) (u/not-valid plugin-id :createText text) + (empty? text) + nil + :else (let [page (dsh/lookup-page @st/state) shape (-> (cts/setup-shape {:type :text diff --git a/frontend/test/frontend_tests/plugins/context_shapes_test.cljs b/frontend/test/frontend_tests/plugins/context_shapes_test.cljs index d144e6e41f..4b0af4cbfe 100644 --- a/frontend/test/frontend_tests/plugins/context_shapes_test.cljs +++ b/frontend/test/frontend_tests/plugins/context_shapes_test.cljs @@ -339,6 +339,10 @@ (t/is (= (-> (. text -fills) (aget 0) (aget "fillColor")) "#123456")) (t/is (nil? (-> (. text -fills) (aget 0) (aget "fillColorGradient"))))))) + (t/testing "createText with empty string returns null" + (t/is (nil? (.createText context ""))) + (t/is (some? (.createText context "Hello")))) + (t/testing "Relative properties" (let [board (.createBoard context)] (set! (.-x board) 100) diff --git a/plugins/libs/plugin-types/index.d.ts b/plugins/libs/plugin-types/index.d.ts index 2f37332aab..8b41bec813 100644 --- a/plugins/libs/plugin-types/index.d.ts +++ b/plugins/libs/plugin-types/index.d.ts @@ -1165,8 +1165,8 @@ export interface Context { /** * Creates a Text shape with the specified text content. Requires `content:write` permission. - * @param text The text content for the Text shape. - * @return Returns the new created shape, if the shape wasn't created can return null. + * @param text The text content for the Text shape. Must be a non-empty string. + * @return Returns the new created shape. Returns null if an empty string is provided or the shape couldn't be created. * * @example * ```js