Skip to content

Commit ac2e362

Browse files
committed
Fix @beyonk/svelte-datepicker local issue
It's a hack to fix beyonk-group/svelte-datepicker#56 But it's not the end fix.
1 parent b7d71d6 commit ac2e362

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

src/lib/admin/components/PaginatedTable/Filter.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import ConfigFilter from '$lib/admin/ConfigFilter';
33
import FilterType from '$lib/admin/FilterType';
44
import DatePicker from '@beyonk/svelte-datepicker/src/components/DatePicker.svelte';
5-
import { dayjs } from '@beyonk/svelte-datepicker/src/components/lib/date-utils';
5+
import { dayjs } from '$lib/utils/date-utils';
66
77
export let filter: ConfigFilter;
88
export let change_callback: Function;

src/lib/utils/date-utils.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as baseDayJs from 'dayjs/esm/index.js';
2+
import localeData from 'dayjs/esm/plugin/localeData/index.js';
3+
import minMax from 'dayjs/esm/plugin/minMax/index.js';
4+
import isSameOrBefore from 'dayjs/esm/plugin/isSameOrBefore/index.js';
5+
import isSameOrAfter from 'dayjs/esm/plugin/isSameOrAfter/index.js';
6+
7+
let dayjs = baseDayJs;
8+
9+
if (baseDayJs.default) {
10+
dayjs = baseDayJs.default;
11+
}
12+
13+
if (dayjs && dayjs.extend) {
14+
dayjs.extend(localeData);
15+
dayjs.extend(minMax);
16+
dayjs.extend(isSameOrBefore);
17+
dayjs.extend(isSameOrAfter);
18+
} else if (!dayjs) {
19+
console.error('"dayjs" import is empty.');
20+
} else if (!dayjs.extend) {
21+
console.error('"dayjs" import does not implement "extend".');
22+
}
23+
24+
export {
25+
dayjs
26+
};

svelte.config.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import preprocess from 'svelte-preprocess';
33
import path from 'path';
44
import fs from 'fs';
55

6-
const copyPlugin = function (options) {
6+
const copyFile = function (options) {
77
return function () {
88
const targetDir = path.dirname(options.target);
99
if (!fs.existsSync(targetDir)){
@@ -29,14 +29,18 @@ const config = {
2929
vite: {
3030
prebundleSvelteLibraries: true,
3131
plugins: [
32-
copyPlugin({
32+
copyFile({
3333
source: './node_modules/bootstrap/dist/js/bootstrap.bundle.min.js',
3434
target: './static/bootstrap.min.js',
3535
}),
36-
copyPlugin({
36+
copyFile({
3737
source: './node_modules/bootstrap/dist/js/bootstrap.bundle.min.js.map',
3838
target: './static/bootstrap.min.js.map',
3939
}),
40+
copyFile({
41+
source: './src/lib/utils/date-utils.ts',
42+
target: './node_modules/@beyonk/svelte-datepicker/src/components/lib/date-utils.js',
43+
}),
4044
],
4145
ssr: {
4246
noExternal: [ 'dayjs' ]

0 commit comments

Comments
 (0)