Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(ai-assistant): make "Try again" an icon above the preview
Elian Doran588e16d01ddb
diff --git a/apps/client/src/stylesheets/theme-next/forms.css b/apps/client/src/stylesheets/theme-next/forms.cssindex 011c49a66f..7639e3958e 100644--- a/apps/client/src/stylesheets/theme-next/forms.css+++ b/apps/client/src/stylesheets/theme-next/forms.css@@ -7,7 +7,8 @@ button.btn.btn-secondary,button.btn.btn-sm:not(.select-button),button.btn.btn-success,button.ck.ck-button:is(.ck-button-action, .ck-button-save, .ck-button-cancel, .ck-button-replaceall, .ck-button-replace).ck-button_with-text,-.ck-ai-assistant-form__actions > button.ck.ck-button.ck-button_with-text {+.ck-ai-assistant-form__actions > button.ck.ck-button.ck-button_with-text,+button.ck.ck-button.ck-ai-assistant-form__try-again {display: inline-flex;align-items: center;justify-content: center;@@ -29,7 +30,8 @@ button.btn.btn-secondary:hover,button.btn.btn-sm:not(.select-button):hover,button.btn.btn-success:hover,button.ck.ck-button:is(.ck-button-action, .ck-button-save, .ck-button-cancel, .ck-button-replaceall, .ck-button-replace).ck-button_with-text:not(.ck-disabled):hover,-.ck-ai-assistant-form__actions > button.ck.ck-button.ck-button_with-text:not(.ck-disabled):hover {+.ck-ai-assistant-form__actions > button.ck.ck-button.ck-button_with-text:not(.ck-disabled):hover,+button.ck.ck-button.ck-ai-assistant-form__try-again:not(.ck-disabled):hover {background: var(--cmd-button-hover-background-color);color: var(--cmd-button-hover-text-color);}@@ -39,7 +41,8 @@ button.btn.btn-secondary:active,button.btn.btn-sm:not(.select-button):active,button.btn.btn-success:active,button.ck.ck-button:is(.ck-button-action, .ck-button-save, .ck-button-cancel, .ck-button-replaceall, .ck-button-replace).ck-button_with-text:not(.ck-disabled):active,-.ck-ai-assistant-form__actions > button.ck.ck-button.ck-button_with-text:not(.ck-disabled):active {+.ck-ai-assistant-form__actions > button.ck.ck-button.ck-button_with-text:not(.ck-disabled):active,+button.ck.ck-button.ck-ai-assistant-form__try-again:not(.ck-disabled):active {opacity: 0.85;box-shadow: unset;background: var(--cmd-button-background-color) !important;@@ -52,7 +55,8 @@ button.btn.btn-secondary:disabled,button.btn.btn-sm:not(.select-button):disabled,button.btn.btn-success:disabled,button.ck.ck-button:is(.ck-button-action, .ck-button-save, .ck-button-cancel, .ck-button-replaceall, .ck-button-replace).ck-button_with-text.ck-disabled,-.ck-ai-assistant-form__actions > button.ck.ck-button.ck-button_with-text.ck-disabled {+.ck-ai-assistant-form__actions > button.ck.ck-button.ck-button_with-text.ck-disabled,+button.ck.ck-button.ck-ai-assistant-form__try-again.ck-disabled {opacity: var(--cmd-button-disabled-opacity);}@@ -62,10 +66,16 @@ button.btn.btn-sm:not(.select-button):focus-visible,button.btn.btn-success:focus-visible,button.ck.ck-button:is(.ck-button-action, .ck-button-save, .ck-button-cancel, .ck-button-replaceall, .ck-button-replace).ck-button_with-text:not(.ck-disabled):focus-visible,.ck-ai-assistant-form__actions > button.ck.ck-button.ck-button_with-text:not(.ck-disabled):focus-visible,+button.ck.ck-button.ck-ai-assistant-form__try-again:not(.ck-disabled):focus-visible,.tn-focusable-button:focus-visible {outline: 2px solid var(--input-focus-outline-color);}+button.ck.ck-button.ck-ai-assistant-form__try-again {+ min-width: unset;+ padding: 4px;+}+/* Button's icon. The text spacing is a margin rather than padding on purpose: transforms rotate thepadding-box, so with one-sided padding a spinning icon (`bx-spin`, e.g. a refresh button whileloading) orbits an off-center axis instead of rotating in place. Margin stays outside thediff --git a/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.spec.ts b/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.spec.tsindex fbfe0901d5..de7637bc01 100644--- a/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.spec.ts+++ b/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.spec.ts@@ -72,6 +72,29 @@ describe("AiAssistantFormView", () => {expect(form.viewMode).toBe("result");expect(previewHtml()).toBe("<p>generated</p>");expect(form.changesToggleView.isVisible).toBe(false);++ // "Try again" is the one thing left in the preview's strip, so the strip still shows.+ expect(form.tryAgainButtonView.isVisible).toBe(true);+ });++ it("offers 'Try again' as an icon in the preview's strip rather than among the commit actions", () => {+ const form = makeForm();+ const button = form.tryAgainButtonView;++ expect(button.isVisible).toBe(false);+ expect(button.withText).toBe(false);+ expect(button.icon).toContain("<svg");+ // Icon-only: the label has to survive as the tooltip and the accessible name.+ expect(button.label).toBe("Try again");+ expect(button.tooltip).toBe(true);++ expect(button.element?.closest(".ck-ai-assistant-form__preview-toolbar")).not.toBeNull();+ expect(button.element?.closest(".ck-ai-assistant-form__actions")).toBeNull();++ form.beginStreaming();+ form.setPreview("<p>new</p>");+ form.enterReview(true, null, "");+ expect(button.isVisible).toBe(true);});it("shows the usage line only for a review that has one, and clears it on the next run", () => {diff --git a/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.ts b/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.tsindex 3db389cbf4..0f8bfee8b8 100644--- a/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.ts+++ b/packages/ckeditor5/src/plugins/ai_assistant/ai_assistant_form.ts@@ -1,3 +1,4 @@+import { IconRefresh } from "@ckeditor/ckeditor5-icons";import {ButtonView,createLabeledInputText,@@ -91,7 +92,11 @@ export default class AiAssistantFormView extends View {this.replaceButtonView = this._createActionButton(locale, t("Replace"), "review", "replace");this.replaceButtonView.class = "ck-button-action";this.insertBelowButtonView = this._createActionButton(locale, t("Insert below"), "review", "insertBelow");+ // Icon-only, and sitting over the preview rather than among the commit actions: re-running+ // is about the response on screen, not about what to do with it.this.tryAgainButtonView = this._createActionButton(locale, t("Try again"), "review", "tryAgain");+ this.tryAgainButtonView.set({ icon: IconRefresh, withText: false, tooltip: true });+ this.tryAgainButtonView.class = "ck-ai-assistant-form__try-again";const bind = this.bindTemplate;@@ -103,11 +108,11 @@ export default class AiAssistantFormView extends View {},children: [{- // The feature's title belongs to the dialog's own header; all this row carries- // is the Result/Changes toggle, and only when a review has a diff to offer.+ // The preview's own strip: the Result/Changes toggle on the left, "Try again"+ // pushed to the right. The feature's title belongs to the dialog's header.tag: "div",- attributes: { class: ["ck", "ck-ai-assistant-form__viewmodes"] },- children: [this.resultToggleView, this.changesToggleView]+ attributes: { class: ["ck", "ck-ai-assistant-form__preview-toolbar"] },+ children: [this.resultToggleView, this.changesToggleView, this.tryAgainButtonView]},this.previewView,{@@ -133,7 +138,6 @@ export default class AiAssistantFormView extends View {this.stopButtonView,this.replaceButtonView,this.insertBelowButtonView,- this.tryAgainButtonView,{tag: "span",attributes: {@@ -167,15 +171,16 @@ export default class AiAssistantFormView extends View {// Turns a native form submit (the Enter key included) into the view's own `submit` event.submitHandler({ view: this });+ // In DOM order, so Tab walks the form the way it reads.const focusables = [this.resultToggleView,this.changesToggleView,+ this.tryAgainButtonView,this.promptInputView,this.sendButtonView,this.stopButtonView,this.replaceButtonView,- this.insertBelowButtonView,- this.tryAgainButtonView+ this.insertBelowButtonView];for (const view of focusables) {this._focusables.add(view);diff --git a/packages/ckeditor5/src/plugins/ai_assistant/theme/ai_assistant.css b/packages/ckeditor5/src/plugins/ai_assistant/theme/ai_assistant.cssindex 6aa8ace880..07d6147e82 100644--- a/packages/ckeditor5/src/plugins/ai_assistant/theme/ai_assistant.css+++ b/packages/ckeditor5/src/plugins/ai_assistant/theme/ai_assistant.css@@ -6,17 +6,21 @@width: min(560px, 90vw);}-.ck.ck-ai-assistant-form .ck-ai-assistant-form__viewmodes {+.ck.ck-ai-assistant-form .ck-ai-assistant-form__preview-toolbar {display: flex;align-items: center;gap: var(--ck-spacing-small);}-/* Outside a review with a diff both toggles are hidden; an empty row should not reserve a gap. */-.ck.ck-ai-assistant-form .ck-ai-assistant-form__viewmodes:not(:has(.ck-button:not(.ck-hidden))) {+/* Outside a review every button in the strip is hidden; it should not reserve a gap of its own. */+.ck.ck-ai-assistant-form .ck-ai-assistant-form__preview-toolbar:not(:has(.ck-button:not(.ck-hidden))) {display: none;}+.ck.ck-ai-assistant-form .ck-button.ck-ai-assistant-form__try-again {+ margin-inline-start: auto;+}+.ck.ck-ai-assistant-form .ck-ai-assistant-form__prompt-row {display: flex;align-items: flex-end;