@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
206 lines (181 loc) • 6.81 kB
JavaScript
;
const EVENT_ACTIONS_REPLACEMENTS = [
['k-event-actions', 'k-event-recurrence-icon'],
];
const TOOLTIP_TO_POPOVER_REPLACEMENTS = [
['k-tooltip-events-container', 'k-popover-events'],
['k-tooltip-events', 'k-popover-events'],
['k-tooltip-event', 'k-popover-event'],
['k-scheduler-tooltip', 'k-scheduler-popover'],
];
const ALL_CLASS_REPLACEMENTS = [...EVENT_ACTIONS_REPLACEMENTS, ...TOOLTIP_TO_POPOVER_REPLACEMENTS];
const COMPOUND_TOOLTIP_RE_CSS = /\.k-tooltip\.k-scheduler-tooltip\b/g;
const COMPOUND_TOOLTIP_RE_JS = /k-tooltip\s+k-scheduler-tooltip|k-tooltip\.k-scheduler-tooltip/g;
const SCHEDULER_TOOLTIP_TITLE_RE_CSS = /(\.k-scheduler-(?:tooltip|popover)\b[^{}]*?)\.k-tooltip-title\b/g;
const SCHEDULER_TOOLTIP_TITLE_RE_JS = /(k-scheduler-(?:tooltip|popover)[^'"]*?)k-tooltip-title/g;
const DEPRECATED_WINDOW_OPTIONS = new Set([
'draggable', 'resizable', 'pinned', 'appendTo',
'loadContentFrom', 'position', 'iframe', 'maxHeight',
'maxWidth', 'minHeight', 'minWidth', 'scrollable',
]);
function applyClassReplacementsCss(str) {
let result = str;
COMPOUND_TOOLTIP_RE_CSS.lastIndex = 0;
result = result.replace(COMPOUND_TOOLTIP_RE_CSS, '.k-popover.k-scheduler-popover');
COMPOUND_TOOLTIP_RE_CSS.lastIndex = 0;
for (const [from, to] of ALL_CLASS_REPLACEMENTS) {
result = result.replaceAll(from, to);
}
SCHEDULER_TOOLTIP_TITLE_RE_CSS.lastIndex = 0;
result = result.replace(SCHEDULER_TOOLTIP_TITLE_RE_CSS, (_, prefix) => prefix + '.k-popover-header');
SCHEDULER_TOOLTIP_TITLE_RE_CSS.lastIndex = 0;
return result;
}
function applyClassReplacementsJs(str) {
let result = str;
COMPOUND_TOOLTIP_RE_JS.lastIndex = 0;
result = result.replace(COMPOUND_TOOLTIP_RE_JS, match => {
if (match.includes(' ')) {
return 'k-popover k-scheduler-popover';
}
return 'k-popover.k-scheduler-popover';
});
COMPOUND_TOOLTIP_RE_JS.lastIndex = 0;
for (const [from, to] of ALL_CLASS_REPLACEMENTS) {
result = result.replaceAll(from, to);
}
SCHEDULER_TOOLTIP_TITLE_RE_JS.lastIndex = 0;
result = result.replace(SCHEDULER_TOOLTIP_TITLE_RE_JS, (_, prefix) => prefix + 'k-popover-header');
SCHEDULER_TOOLTIP_TITLE_RE_JS.lastIndex = 0;
return result;
}
function transformStringLiterals(root, j, fn) {
let changed = false;
const visit = path => {
if (typeof path.node.value !== 'string') {
return;
}
const updated = fn(path.node.value);
if (updated === path.node.value) {
return;
}
path.node.value = updated;
if (path.node.extra) {
path.node.extra.rawValue = updated;
if (path.node.extra.raw) {
path.node.extra.raw = fn(path.node.extra.raw);
}
}
changed = true;
};
root.find(j.StringLiteral).forEach(visit);
root.find(j.Literal, n => typeof n.value === 'string').forEach(visit);
return changed;
}
function transformTemplateLiterals(root, j, fn) {
let changed = false;
root.find(j.TemplateLiteral).forEach(path => {
path.node.quasis.forEach(quasi => {
const updatedRaw = fn(quasi.value.raw);
const updatedCooked = quasi.value.cooked != null ? fn(quasi.value.cooked) : null;
if (updatedRaw !== quasi.value.raw || updatedCooked !== quasi.value.cooked) {
quasi.value.raw = updatedRaw;
if (quasi.value.cooked != null) {
quasi.value.cooked = updatedCooked;
}
changed = true;
}
});
});
return changed;
}
function isSchedulerEditableWindowCall(path) {
const callee = path.node.callee;
if (callee.type !== 'MemberExpression') {
return false;
}
const prop = callee.property;
const name = prop.name || prop.value;
return name === 'kendoScheduler';
}
function removeDeprecatedWindowOptions(root, j) {
let changed = false;
root
.find(j.CallExpression)
.filter(isSchedulerEditableWindowCall)
.forEach(path => {
const args = path.node.arguments;
if (!args.length || args[0].type !== 'ObjectExpression') {
return;
}
const editableProp = args[0].properties.find(p => {
if (p.type !== 'Property' && p.type !== 'ObjectProperty') {
return false;
}
return (p.key.name || p.key.value) === 'editable';
});
if (!editableProp) {
return;
}
let editableObj = editableProp.value;
if (editableObj.type !== 'ObjectExpression') {
return;
}
const windowProp = editableObj.properties.find(p => {
if (p.type !== 'Property' && p.type !== 'ObjectProperty') {
return false;
}
return (p.key.name || p.key.value) === 'window';
});
if (!windowProp || windowProp.value.type !== 'ObjectExpression') {
return;
}
const windowObj = windowProp.value;
const before = windowObj.properties.length;
windowObj.properties = windowObj.properties.filter(p => {
if (p.type !== 'Property' && p.type !== 'ObjectProperty') {
return true;
}
const key = p.key.name || p.key.value;
return !DEPRECATED_WINDOW_OPTIONS.has(key);
});
if (windowObj.properties.length < before) {
changed = true;
}
});
return changed;
}
const SCHEDULER_WINDOW_RE_CSS = /(\.k-scheduler\b[^{}]*?)\.k-window\b(?!-)/g;
const SCHEDULER_WINDOW_TITLEBAR_RE_CSS = /(\.k-scheduler\b[^{}]*?)\.k-window-titlebar\b/g;
const SCHEDULER_WINDOW_CONTENT_RE_CSS = /(\.k-scheduler\b[^{}]*?)\.k-window-content\b/g;
const SCHEDULER_WINDOW_ACTIONS_RE_CSS = /(\.k-scheduler\b[^{}]*?)\.k-window-actions\b/g;
function applySchedulerWindowToDialogCss(str) {
let result = str;
SCHEDULER_WINDOW_RE_CSS.lastIndex = 0;
result = result.replace(SCHEDULER_WINDOW_RE_CSS, (_, prefix) => prefix + '.k-dialog');
SCHEDULER_WINDOW_RE_CSS.lastIndex = 0;
SCHEDULER_WINDOW_TITLEBAR_RE_CSS.lastIndex = 0;
result = result.replace(SCHEDULER_WINDOW_TITLEBAR_RE_CSS, (_, prefix) => prefix + '.k-dialog-titlebar');
SCHEDULER_WINDOW_TITLEBAR_RE_CSS.lastIndex = 0;
SCHEDULER_WINDOW_CONTENT_RE_CSS.lastIndex = 0;
result = result.replace(SCHEDULER_WINDOW_CONTENT_RE_CSS, (_, prefix) => prefix + '.k-dialog-content');
SCHEDULER_WINDOW_CONTENT_RE_CSS.lastIndex = 0;
SCHEDULER_WINDOW_ACTIONS_RE_CSS.lastIndex = 0;
result = result.replace(SCHEDULER_WINDOW_ACTIONS_RE_CSS, (_, prefix) => prefix + '.k-dialog-actions');
SCHEDULER_WINDOW_ACTIONS_RE_CSS.lastIndex = 0;
return result;
}
module.exports = {
EVENT_ACTIONS_REPLACEMENTS,
TOOLTIP_TO_POPOVER_REPLACEMENTS,
ALL_CLASS_REPLACEMENTS,
COMPOUND_TOOLTIP_RE_CSS,
COMPOUND_TOOLTIP_RE_JS,
DEPRECATED_WINDOW_OPTIONS,
applyClassReplacementsCss,
applyClassReplacementsJs,
applySchedulerWindowToDialogCss,
transformStringLiterals,
transformTemplateLiterals,
removeDeprecatedWindowOptions,
};