Skip to content

Commit

Permalink
Fix @beyonk/svelte-datepicker local issue
Browse files Browse the repository at this point in the history
It's a hack to fix beyonk-group/svelte-datepicker#56

But it's not the end fix.
  • Loading branch information
AI-prodev committed Apr 18, 2022
1 parent 36afe17 commit 6cc1bb0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/admin/components/PaginatedTable/Filter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import ConfigFilter from '$lib/admin/ConfigFilter';
import FilterType from '$lib/admin/FilterType';
import DatePicker from '@beyonk/svelte-datepicker/src/components/DatePicker.svelte';
import { dayjs } from '@beyonk/svelte-datepicker/src/components/lib/date-utils';
import { dayjs } from '$lib/utils/date-utils';
export let filter: ConfigFilter;
export let change_callback: Function;
Expand Down
26 changes: 26 additions & 0 deletions src/lib/utils/date-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as baseDayJs from 'dayjs/esm/index.js';
import localeData from 'dayjs/esm/plugin/localeData/index.js';
import minMax from 'dayjs/esm/plugin/minMax/index.js';
import isSameOrBefore from 'dayjs/esm/plugin/isSameOrBefore/index.js';
import isSameOrAfter from 'dayjs/esm/plugin/isSameOrAfter/index.js';

let dayjs = baseDayJs;

if (baseDayJs.default) {
dayjs = baseDayJs.default;
}

if (dayjs && dayjs.extend) {
dayjs.extend(localeData);
dayjs.extend(minMax);
dayjs.extend(isSameOrBefore);
dayjs.extend(isSameOrAfter);
} else if (!dayjs) {
console.error('"dayjs" import is empty.');
} else if (!dayjs.extend) {
console.error('"dayjs" import does not implement "extend".');
}

export {
dayjs
};
10 changes: 7 additions & 3 deletions svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import preprocess from 'svelte-preprocess';
import path from 'path';
import fs from 'fs';

const copyPlugin = function (options) {
const copyFile = function (options) {
return function () {
const targetDir = path.dirname(options.target);
if (!fs.existsSync(targetDir)){
Expand All @@ -29,14 +29,18 @@ const config = {
vite: {
prebundleSvelteLibraries: true,
plugins: [
copyPlugin({
copyFile({
source: './node_modules/bootstrap/dist/js/bootstrap.bundle.min.js',
target: './static/bootstrap.min.js',
}),
copyPlugin({
copyFile({
source: './node_modules/bootstrap/dist/js/bootstrap.bundle.min.js.map',
target: './static/bootstrap.min.js.map',
}),
copyFile({
source: './src/lib/utils/date-utils.ts',
target: './node_modules/@beyonk/svelte-datepicker/src/components/lib/date-utils.js',
}),
],
ssr: {
noExternal: [ 'dayjs' ]
Expand Down

0 comments on commit 6cc1bb0

Please sign in to comment.