Skip to content

Commit 160e917

Browse files
committed
fix: resolve warnings in console
1 parent b431096 commit 160e917

8 files changed

Lines changed: 107 additions & 86 deletions

File tree

adminforth/spa/package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adminforth/spa/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"async-mutex": "^0.5.0",
2424
"dayjs": "^1.11.11",
2525
"debounce": "^2.1.0",
26+
"dompurify": "^3.4.1",
2627
"flowbite-datepicker": "^1.2.6",
2728
"javascript-time-ago": "^2.5.11",
2829
"lodash.debounce": "^4.0.8",

adminforth/spa/pnpm-lock.yaml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adminforth/spa/src/afcl/Modal.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ async function close() {
104104
isModalOpen.value = false;
105105
}
106106
107+
defineOptions({
108+
inheritAttrs: false,
109+
})
110+
107111
defineExpose({
108112
open: open,
109113
close: close,

adminforth/spa/src/components/CustomRangePicker.vue

Lines changed: 51 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
v-model="end"
1919
>
2020

21-
<div v-if="min && max" class="w-full px-2.5">
21+
<div v-if="min !== undefined && max !== undefined" class="w-full px-2.5">
2222
<RangePicker
2323
:dot-size="20"
2424
height="7.99px"
@@ -36,91 +36,79 @@ import debounce from 'debounce'
3636
import RangePicker from './RangePicker.vue';
3737
3838
const props = defineProps<{
39-
valueStart: number | null,
40-
valueEnd: number | null,
41-
min: number,
42-
max: number,
39+
valueStart: number | null | string,
40+
valueEnd: number | null | string,
41+
min: number | string | undefined,
42+
max: number | string | undefined,
4343
}>()
4444
4545
const emit = defineEmits(['update:valueStart', 'update:valueEnd']);
4646
47-
const minFormatted = computed(() => Math.floor(<number>props.min));
48-
const maxFormatted = computed(() => Math.ceil(<number>props.max));
47+
const minFormatted = computed(() => {
48+
const v = Number(props.min);
49+
return isNaN(v) ? 0 : Math.floor(v);
50+
});
4951
52+
const maxFormatted = computed(() => {
53+
const v = Number(props.max);
54+
return isNaN(v) ? 100 : Math.ceil(v);
55+
});
5056
51-
const start = ref<number | null>(props.valueStart);
52-
const end = ref<number | null>(props.valueEnd);
57+
const start = ref<number | null>(
58+
props.valueStart === "" || props.valueStart === null ? null : Number(props.valueStart)
59+
);
60+
const end = ref<number | null>(
61+
props.valueEnd === "" || props.valueEnd === null ? null : Number(props.valueEnd)
62+
);
5363
5464
const sliderValue = ref<[number, number]>([minFormatted.value, maxFormatted.value]);
5565
56-
watch([start, end], () => {
57-
if ( !start.value && end.value ) {
58-
setSliderValues(minFormatted.value, end.value);
59-
} else if ( start.value && !end.value ) {
60-
setSliderValues(start.value, maxFormatted.value);
61-
} else if ( !start.value && !end.value ) {
62-
setSliderValues(minFormatted.value, maxFormatted.value);
63-
} else {
64-
setSliderValues(start.value, end.value);
65-
}
66-
})
67-
68-
const updateFromSlider =
69-
debounce((value: [number, number]) => {
70-
start.value = value[0] === minFormatted.value ? null : value[0];
71-
end.value = value[1] === maxFormatted.value ? null : value[1];
72-
}, 500);
66+
function setSliderValues(s: number | null, e: number | null) {
67+
sliderValue.value = [s ?? minFormatted.value, e ?? maxFormatted.value];
68+
}
7369
74-
onMounted(() => {
75-
updateStartFromProps();
76-
updateEndFromProps();
70+
watch([start, end], () => {
71+
setSliderValues(start.value, end.value);
72+
});
7773
78-
watch(() => props.valueStart, (value) => {
79-
updateStartFromProps();
80-
});
81-
82-
watch(() => props.valueEnd, (value) => {
83-
updateEndFromProps();
84-
});
85-
})
74+
const updateFromSlider = debounce((value: [number, number]) => {
75+
start.value = value[0] === minFormatted.value ? null : value[0];
76+
end.value = value[1] === maxFormatted.value ? null : value[1];
77+
}, 500);
8678
8779
function updateStartFromProps() {
88-
if (props.valueStart == start.value) {
89-
return;
80+
const normalized = (props.valueStart === "" || props.valueStart === null || props.valueStart === undefined)
81+
? null : Number(props.valueStart);
82+
if (normalized !== start.value) {
83+
start.value = normalized;
9084
}
91-
start.value = props.valueStart;
92-
setSliderValues(start.value, end.value)
9385
}
9486
9587
function updateEndFromProps() {
96-
if (props.valueEnd == end.value) {
97-
return;
88+
const normalized = (props.valueEnd === "" || props.valueEnd === null || props.valueEnd === undefined)
89+
? null : Number(props.valueEnd);
90+
if (normalized !== end.value) {
91+
end.value = normalized;
9892
}
99-
end.value = props.valueEnd;
100-
setSliderValues(start.value, end.value)
10193
}
10294
103-
watch(start, () => {
104-
emit('update:valueStart', start.value)
105-
})
95+
onMounted(() => {
96+
updateStartFromProps();
97+
updateEndFromProps();
10698
107-
watch(end, () => {
108-
emit('update:valueEnd', end.value);
99+
watch(() => props.valueStart, updateStartFromProps);
100+
watch(() => props.valueEnd, updateEndFromProps);
101+
});
102+
103+
watch(start, (newVal) => {
104+
emit('update:valueStart', newVal);
109105
})
110106
111-
watch([minFormatted,maxFormatted], () => {
112-
if ( !start.value && end.value ) {
113-
setSliderValues(minFormatted.value, end.value);
114-
} else if ( start.value && !end.value ) {
115-
setSliderValues(start.value, maxFormatted.value);
116-
} else if ( !start.value && !end.value ) {
117-
setSliderValues(minFormatted.value, maxFormatted.value);
118-
} else {
119-
setSliderValues(start.value, end.value);
120-
}
107+
watch(end, (newVal) => {
108+
emit('update:valueEnd', newVal);
121109
})
122110
123-
function setSliderValues(start: any, end: any) {
124-
sliderValue.value = [start || minFormatted.value, end || maxFormatted.value];
125-
}
111+
watch([minFormatted, maxFormatted], () => {
112+
setSliderValues(start.value, end.value);
113+
})
126114
</script>

adminforth/spa/src/components/ResourceListTable.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ import CallActionWrapper from '@/components/CallActionWrapper.vue'
372372
const coreStore = useCoreStore();
373373
const { t } = useI18n();
374374
const { alert, confirm } = useAdminforth();
375-
const props = defineProps<{
375+
const props = withDefaults(defineProps<{
376376
page: number,
377377
resource: AdminForthResourceFrontend | null,
378378
rows: any[] | null,
@@ -389,7 +389,9 @@ const props = defineProps<{
389389
customActionIconsThreeDotsMenuItems?: AdminForthComponentDeclaration[]
390390
tableRowReplaceInjection?: AdminForthComponentDeclaration,
391391
isVirtualScrollEnabled: boolean
392-
}>();
392+
}>(), {
393+
sort: () => []
394+
});
393395
394396
//select between all rows or rows, that should be rendered in virtual scroll
395397
const rowsToRender = computed(() => {

adminforth/spa/src/utils/utils.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useCoreStore } from '../stores/core';
66
import { useUserStore } from '../stores/user';
77
import { Dropdown } from 'flowbite';
88
import adminforth, { useAdminforth } from '../adminforth';
9-
import sanitizeHtml from 'sanitize-html'
9+
import DOMPurify from 'dompurify'
1010
import debounce from 'debounce';
1111
import type { AdminForthActionFront, AdminForthResourceColumnInputCommon, AdminForthResourceFrontend, Predicate } from '@/types/Common';
1212
import { i18nInstance } from '../i18n'
@@ -337,26 +337,24 @@ export function humanifySize(size: number) {
337337
}
338338

339339
export function protectAgainstXSS(value: string) {
340-
return sanitizeHtml(value, {
341-
allowedTags: [
342-
"address", "article", "aside", "footer", "header", "h1", "h2", "h3", "h4",
343-
"h5", "h6", "hgroup", "main", "nav", "section", "blockquote", "dd", "div",
344-
"dl", "dt", "figcaption", "figure", "hr", "li", "main", "ol", "p", "pre",
345-
"ul", "a", "abbr", "b", "bdi", "bdo", "br", "cite", "code", "data", "dfn",
346-
"em", "i", "kbd", "mark", "q", "rb", "rp", "rt", "rtc", "ruby", "s", "samp",
347-
"small", "span", "strong", "sub", "sup", "time", "u", "var", "wbr", "caption",
348-
"col", "colgroup", "table", "tbody", "td", "tfoot", "th", "thead", "tr", 'img', 'video', 'source'
340+
return DOMPurify.sanitize(value, {
341+
ALLOWED_TAGS: [
342+
"address","article","aside","footer","header","h1","h2","h3","h4",
343+
"h5","h6","hgroup","main","nav","section","blockquote","dd","div",
344+
"dl","dt","figcaption","figure","hr","li","ol","p","pre",
345+
"ul","a","abbr","b","bdi","bdo","br","cite","code","data","dfn",
346+
"em","i","kbd","mark","q","rb","rp","rt","rtc","ruby","s","samp",
347+
"small","span","strong","sub","sup","time","u","var","wbr","caption",
348+
"col","colgroup","table","tbody","td","tfoot","th","thead","tr",
349+
"img","video","source"
349350
],
350-
allowedAttributes: {
351-
'li': [ 'data-list' ],
352-
'img': [ 'src', 'srcset', 'alt', 'title', 'width', 'height', 'loading' ],
353-
'video': [ 'src', 'controls', 'autoplay', 'loop', 'muted', 'poster', 'width', 'height', 'autoplay', 'playsinline' ],
354-
'source': [ 'src', 'type' ],
355-
// Allow markup on spans (classes & styles), and
356-
// generic data/aria/style attributes on any element. (e.g. for KaTeX-related previews)
357-
'span': [ 'class', 'style' ],
358-
'*': [ 'data-*', 'aria-*', 'style' ]
359-
},
351+
ALLOWED_ATTR: [
352+
"data-list",
353+
"src","srcset","alt","title","width","height","loading",
354+
"controls","autoplay","loop","muted","poster","playsinline",
355+
"class","style",
356+
"data-*","aria-*"
357+
]
360358
});
361359
}
362360

adminforth/spa/src/views/ListView.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ import { getCustomComponent, initThreeDotsDropdown, getList, startBulkAction } f
224224
import ThreeDotsMenu from '@/components/ThreeDotsMenu.vue';
225225
import { Tooltip, Spinner } from '@/afcl'
226226
import type { AdminForthComponentDeclaration, AdminForthComponentDeclarationFull, AdminForthFilterOperators, AdminForthResourceColumnCommon } from '@/types/Common';
227-
227+
import { useI18n } from 'vue-i18n';
228228
229229
import {
230230
IconBanOutline,
@@ -235,6 +235,8 @@ import {
235235
import Filters from '@/components/Filters.vue';
236236
import { useAdminforth } from '@/adminforth';
237237
238+
const { t } = useI18n();
239+
238240
const filtersShow = ref(false);
239241
const { list, alert } = useAdminforth();
240242
const coreStore = useCoreStore();

0 commit comments

Comments
 (0)