mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Render chart headings and report table headers and cells through the shared security-aware viewer. Use rendered text and emoji for canvas labels and dataset titles, capturing them before afterFlush so policy changes remain reactive. Extend title adapter, chart context and cumulative-flow browser policy coverage. Thanks to xet7 !
33 lines
1.3 KiB
JavaScript
33 lines
1.3 KiB
JavaScript
import { Blaze } from 'meteor/blaze';
|
|
import { Template } from 'meteor/templating';
|
|
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import './titleViewer.jade';
|
|
|
|
// Third-party charts do not mount Blaze fields. Render their HTML through
|
|
// the same viewer so Markdown, emoji and Admin Panel policies stay shared.
|
|
// toHTMLWithData disposes its temporary view after producing the markup.
|
|
export function titleViewerHtml(value) {
|
|
// Read in the chart's outer computation: temporary Blaze rendering owns
|
|
// its own computation, so it cannot keep the chart reactive by itself.
|
|
ReactiveCache.getCurrentSetting();
|
|
return Blaze.toHTMLWithData(Template.chartTitleViewer, { value: value || '' });
|
|
}
|
|
|
|
export function escapeTitleText(value) {
|
|
return String(value).replace(/[&<>"']/g, character => ({
|
|
'&': '&', '<': '<', '>': '>', '"': '"', "'": ''',
|
|
}[character]));
|
|
}
|
|
|
|
// SVG text labels cannot contain HTML blocks. Keep the viewer's rendered
|
|
// text/emoji, escaping it because Frappe inserts the label via innerHTML.
|
|
export function titleViewerText(value) {
|
|
const container = document.createElement('div');
|
|
container.innerHTML = titleViewerHtml(value);
|
|
return container.textContent;
|
|
}
|
|
|
|
export function titleViewerSvgText(value) {
|
|
return escapeTitleText(titleViewerText(value));
|
|
}
|