Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c6af3e9

Browse files
committedApr 18, 2022
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 c6af3e9

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-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

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { dayjs as baseDayJs } from 'dayjs';
2+
import localeData from 'dayjs/plugin/localeData';
3+
import minMax from 'dayjs/plugin/minMax';
4+
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
5+
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
6+
7+
/**
8+
* This entire file is a copy/paste of the one from @beyonk/svelte-datepicker
9+
* @see ../../../node_modules/@beyonk/svelte-datepicker/src/components/lib/date-utils.js
10+
*/
11+
const dayjs = function() {
12+
if (baseDayJs && baseDayJs.extend) {
13+
baseDayJs.extend(localeData);
14+
baseDayJs.extend(minMax);
15+
baseDayJs.extend(isSameOrBefore);
16+
baseDayJs.extend(isSameOrAfter);
17+
} else if (!baseDayJs) {
18+
console.error('"dayjs" import is empty.');
19+
} else if (!baseDayJs.extend) {
20+
console.error('"dayjs" import does not implement "extend".');
21+
}
22+
23+
return baseDayJs(...arguments);
24+
}
25+
26+
export {
27+
dayjs
28+
};

‎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)
Please sign in to comment.