mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-09 00:00:26 +00:00
refactor: prepare vue components for vapor mode (#38798)
Removes what would block a later switch to Vue's vapor mode: `vue-chartjs` and the `SvgIcon` render function are virtual DOM components, and `v-memo` has no vapor equivalent. This does not adopt vapor mode, which will be stable in upcoming Vue 3.6. `vue-chartjs` was a thin wrapper over chart.js, so a local `ChartCanvas.vue` replaces it. Chart data and options move into computed values to keep their object identity, which is what `v-memo` was compensating for. `chartjs-adapter-dayjs-4` is moved first-party, just ~40 lines that are easy to maintain.
This commit is contained in:
+1
-35
@@ -1,6 +1,5 @@
|
||||
import {defineComponent, h, type PropType} from 'vue';
|
||||
import {parseDom, serializeXml} from './utils.ts';
|
||||
import {html, htmlRaw} from './utils/html.ts';
|
||||
import {htmlRaw} from './utils/html.ts';
|
||||
import giteaDoubleChevronLeft from '../../public/assets/img/svg/gitea-double-chevron-left.svg';
|
||||
import giteaDoubleChevronRight from '../../public/assets/img/svg/gitea-double-chevron-right.svg';
|
||||
import giteaEmptyCheckbox from '../../public/assets/img/svg/gitea-empty-checkbox.svg';
|
||||
@@ -222,36 +221,3 @@ export function svgParseOuterInner(name: SvgName) {
|
||||
const svgOuter = svgDoc.firstChild as SVGElement;
|
||||
return {svgOuter, svgInnerHtml};
|
||||
}
|
||||
|
||||
export const SvgIcon = defineComponent({
|
||||
name: 'SvgIcon',
|
||||
props: {
|
||||
name: {type: String as PropType<SvgName>, required: true},
|
||||
size: {type: Number, default: 16},
|
||||
symbolId: {type: String},
|
||||
},
|
||||
render() {
|
||||
let {svgOuter, svgInnerHtml} = svgParseOuterInner(this.name);
|
||||
// https://vuejs.org/guide/extras/render-function.html#creating-vnodes
|
||||
// the `^` is used for attr, set SVG attributes like 'width', `aria-hidden`, `viewBox`, etc
|
||||
const attrs: Record<string, any> = {};
|
||||
for (const attr of svgOuter.attributes) {
|
||||
if (attr.name === 'class') continue;
|
||||
attrs[`^${attr.name}`] = attr.value;
|
||||
}
|
||||
attrs[`^width`] = this.size;
|
||||
attrs[`^height`] = this.size;
|
||||
|
||||
const classes = Array.from(svgOuter.classList);
|
||||
if (this.symbolId) {
|
||||
classes.push('tw-hidden', 'svg-symbol-container');
|
||||
svgInnerHtml = html`<symbol id="${this.symbolId}" viewBox="${attrs['^viewBox']}">${htmlRaw(svgInnerHtml)}</symbol>`;
|
||||
}
|
||||
// create VNode
|
||||
return h('svg', {
|
||||
...attrs,
|
||||
class: classes,
|
||||
innerHTML: svgInnerHtml,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user