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

Add nonce to codex-tooltip #2520

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/components/modules/api/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ export default class TooltipAPI extends Module {
* @param {TooltipOptions} options - tooltip options
*/
public show(element: HTMLElement, content: TooltipContent, options?: TooltipOptions): void {
tooltip.show(element, content, options);
tooltip.show(element, content, options, this.config);
}

/**
* Method hides tooltip on HTML page
*/
public hide(): void {
tooltip.hide();
tooltip.hide(false, this.config);
}

/**
Expand All @@ -64,6 +64,6 @@ export default class TooltipAPI extends Module {
* @param {TooltipOptions} options - tooltip options
*/
public onHover(element: HTMLElement, content: TooltipContent, options?: TooltipOptions): void {
tooltip.onHover(element, content, options);
tooltip.onHover(element, content, options, this.config);
}
}
5 changes: 3 additions & 2 deletions src/components/modules/toolbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export default class Toolbar extends Module<ToolbarNodes> {

tooltip.onHover(this.nodes.plusButton, tooltipContent, {
hidingDelay: 400,
});
}, this.config);

/**
* Fill Actions Zone:
Expand All @@ -416,7 +416,8 @@ export default class Toolbar extends Module<ToolbarNodes> {
I18n.ui(I18nInternalNS.ui.blockTunes.toggler, 'Click to tune'),
{
hidingDelay: 400,
}
},
this.config
);

/**
Expand Down
4 changes: 2 additions & 2 deletions src/components/modules/toolbar/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
tooltip.onHover(this.nodes.conversionToggler, I18n.ui(I18nInternalNS.ui.inlineToolbar.converter, 'Convert to'), {
placement: 'top',
hidingDelay: 100,
});
}, this.config);
}
}

Expand Down Expand Up @@ -606,7 +606,7 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
tooltip.onHover(button, tooltipContent, {
placement: 'top',
hidingDelay: 100,
});
}, this.config);
}

instance.checkState(SelectionUtils.get());
Expand Down
22 changes: 14 additions & 8 deletions src/components/utils/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
import CodeXTooltips from 'codex-tooltip';
import type { TooltipOptions, TooltipContent } from 'codex-tooltip/types';
import { EditorConfig } from '../../../types';

/**
* Tooltips lib: CodeX Tooltips
Expand All @@ -16,13 +17,15 @@ let lib: null | CodeXTooltips = null;
* If library is needed, but it is not initialized yet, this function will initialize it
*
* For example, if editor was destroyed and then initialized again
*
* @param {string} nonce - The nonce to apply to the injected styles.
*/
function prepare(): void {
export function prepare(nonce?: string): void {
if (lib) {
return;
}

lib = new CodeXTooltips();
lib = new CodeXTooltips(nonce);
}

/**
Expand All @@ -31,9 +34,10 @@ function prepare(): void {
* @param {HTMLElement} element - any HTML element in DOM
* @param content - tooltip's content
* @param options - showing settings
* @param {EditorConfig} config - The EditorJS config
*/
export function show(element: HTMLElement, content: TooltipContent, options?: TooltipOptions): void {
prepare();
export function show(element: HTMLElement, content: TooltipContent, options?: TooltipOptions, config?: EditorConfig): void {
prepare(config?.style.nonce);

lib?.show(element, content, options);
}
Expand All @@ -42,9 +46,10 @@ export function show(element: HTMLElement, content: TooltipContent, options?: To
* Hides tooltip
*
* @param skipHidingDelay — pass true to immediately hide the tooltip
* @param {EditorConfig} config - The EditorJS config
*/
export function hide(skipHidingDelay = false): void {
prepare();
export function hide(skipHidingDelay = false, config?: EditorConfig): void {
prepare(config?.style.nonce);

lib?.hide(skipHidingDelay);
}
Expand All @@ -55,9 +60,10 @@ export function hide(skipHidingDelay = false): void {
* @param {HTMLElement} element - any HTML element in DOM
* @param content - tooltip's content
* @param options - showing settings
* @param {EditorConfig} config - The EditorJS config
*/
export function onHover(element: HTMLElement, content: TooltipContent, options?: TooltipOptions): void {
prepare();
export function onHover(element: HTMLElement, content: TooltipContent, options?: TooltipOptions, config?: EditorConfig): void {
prepare(config?.style.nonce);

lib?.onHover(element, content, options);
}
Expand Down