Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/feat(api/QEditor): Fix and improve definitions prop type (fix #14141) #14227

Conversation

yusufkandemir
Copy link
Member

@yusufkandemir yusufkandemir commented Aug 19, 2022

What kind of change does this PR introduce?

  • Bugfix
  • Feature

Does this PR introduce a breaking change?

  • No

The PR fulfills these requirements:

  • It's submitted to the dev branch (or v[X] branch)
  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix: #xxx[,#xxx], where "xxx" is the issue number)

Other information:
Fixes #14141.

We will also start generating and exporting QEditorCommand, which may be used like this:

import { QEditorProps, QEditorCommand } from 'quasar';

// A common command that can be reused in different places
const save: QEditorCommand = {
  tip: 'Save your work',
  icon: 'save',
  label: 'Save',
  handler: () => { /* ... */ },
};

// <q-editor :definitions="definitions" ... />
const definitions: QEditorProps['definitions'] = {
  foo: { /* ... */ },
  save,
};

Diff:

@@ -3358,60 +3358,11 @@
    */
   definitions?:
     | {
         /**
-         * Label of the button
+         * Command definition
          */
-        label?: string;
-        /**
-         * Text to be displayed as a tooltip on hover
-         */
-        tip?: string;
-        /**
-         * HTML formatted text to be displayed within a tooltip on hover
-         */
-        htmlTip?: string;
-        /**
-         * Icon of the button
-         */
-        icon?: string;
-        /**
-         * Keycode of a key to be used together with the <ctrl> key for use as a shortcut to trigger this element
-         */
-        key?: number;
-        /**
-         * Either this or "cmd" is required. Function for when button gets clicked/tapped.
-         */
-        handler?: () => void;
-        /**
-         * Either this or "handler" is required. This must be a valid execCommand method according to the designMode API.
-         */
-        cmd?: string;
-        /**
-         * Only set a param if using a "cmd". This is commonly text or HTML to inject, but is highly dependent upon the specific cmd being called.
-         */
-        param?: string;
-        /**
-         * Is button disabled?
-         * @returns If true, the button will be disabled
-         */
-        disable?: boolean | (() => boolean);
-        /**
-         * Pass the value "no-state" if the button should not have an "active" state
-         */
-        type?: "no-state";
-        /**
-         * Lock the button label, so it doesn't change based on the child option selected.
-         */
-        fixedLabel?: boolean;
-        /**
-         * Lock the button icon, so it doesn't change based on the child option selected.
-         */
-        fixedIcon?: boolean;
-        /**
-         * Highlight the toolbar button, when a child option has been selected.
-         */
-        highlight?: boolean;
+        [commandName: string]: QEditorCommand;
       }
     | undefined;
   /**
    * Object with definitions of fonts
@@ -13472,8 +13423,64 @@
 }
 
 import { QNotifyUpdateOptions } from "./api";
 import { QNotifyOptions } from "./api";
+export interface QEditorCommand {
+  /**
+   * Label of the button
+   */
+  label?: string;
+  /**
+   * Text to be displayed as a tooltip on hover
+   */
+  tip?: string;
+  /**
+   * HTML formatted text to be displayed within a tooltip on hover
+   */
+  htmlTip?: string;
+  /**
+   * Icon of the button
+   */
+  icon?: string;
+  /**
+   * Keycode of a key to be used together with the <ctrl> key for use as a shortcut to trigger this element
+   */
+  key?: number;
+  /**
+   * Either this or "cmd" is required. Function for when button gets clicked/tapped.
+   */
+  handler?: () => void;
+  /**
+   * Either this or "handler" is required. This must be a valid execCommand method according to the designMode API.
+   */
+  cmd?: string;
+  /**
+   * Only set a param if using a "cmd". This is commonly text or HTML to inject, but is highly dependent upon the specific cmd being called.
+   */
+  param?: string;
+  /**
+   * Is button disabled?
+   * @returns If true, the button will be disabled
+   */
+  disable?: boolean | (() => boolean);
+  /**
+   * Pass the value "no-state" if the button should not have an "active" state
+   */
+  type?: "no-state";
+  /**
+   * Lock the button label, so it doesn't change based on the child option selected.
+   */
+  fixedLabel?: boolean;
+  /**
+   * Lock the button icon, so it doesn't change based on the child option selected.
+   */
+  fixedIcon?: boolean;
+  /**
+   * Highlight the toolbar button, when a child option has been selected.
+   */
+  highlight?: boolean;
+}
+

@yusufkandemir yusufkandemir changed the title fix(api/QEditor): Fix definitions prop type (fix #14141) fix/feat(api/QEditor): Fix and improve definitions prop type (fix #14141) Aug 19, 2022
@rstoenescu rstoenescu merged commit 1e16e53 into quasarframework:dev Aug 20, 2022
@rstoenescu
Copy link
Member

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QEditor definitions prop type
2 participants