Skip to content

Commit

Permalink
fix!: Remove access to the svelte/internal API which is deprecated (#330
Browse files Browse the repository at this point in the history
)

* fix!: Remove access to the svelte/internal API which was never intended to be public.
Allows Svelte 5 compatibility.

BREAKING: remove support for the destroy() method on <Calendar />. Alternative: wrap the calendar in an {#if notDestroyed}<Calendar />{/if} block.

* chore: bump version to 4.0.0

---------

Co-authored-by: Gonzalo Ruiz <rgon@rgon.es>
Co-authored-by: Vladimir <mr.vladimir.alexeev@gmail.com>
  • Loading branch information
3 people authored Sep 23, 2024
1 parent b22047a commit 9758b8f
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 51 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/core/src/Auxiliary.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script>
import {getContext} from 'svelte';
import {is_function} from 'svelte/internal';
import {debounce, toISOString, toLocalDate, toViewWithLocalDates} from './lib.js';
import {debounce, toISOString, toLocalDate, toViewWithLocalDates, is_function} from './lib.js';
let {datesSet, _auxiliary, _activeRange, _queue, _view} = getContext('state');
Expand Down
7 changes: 0 additions & 7 deletions packages/core/src/Calendar.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script>
import './styles/index.scss';
import {setContext, beforeUpdate, afterUpdate} from 'svelte';
import {destroy_component, get_current_component} from 'svelte/internal';
import {get} from 'svelte/store';
import {diff} from './storage/options';
import State from './storage/state';
Expand All @@ -24,8 +23,6 @@
export let plugins = [];
export let options = {};
let component = get_current_component();
let state = new State(plugins, options);
setContext('state', state);
Expand Down Expand Up @@ -114,10 +111,6 @@
return null;
}
export function destroy() {
destroy_component(component, true);
}
export function next() {
$date = nextDate($date, $duration);
return this;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/debounce.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {run_all} from 'svelte/internal';
import {run_all} from './utils.js';

export function debounce(fn, handle, queueStore) {
queueStore.update(queue => queue.set(handle, fn));
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/lib/events.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {addDay, datesEqual, createDate, cloneDate, setMidnight, toLocalDate, toISOString, noTimePart, copyTime} from './date';
import {createElement} from './dom';
import {assign, isArray} from './utils';
import {assign, isArray, is_function} from './utils';
import {toViewWithLocalDates} from './view';
import {is_function} from 'svelte/internal';

let eventId = 1;
export function createEvents(input) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/stores.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {derived} from 'svelte/store';
import {is_function} from 'svelte/internal';
import {is_function} from './utils.js';
import {toLocalDate} from './date';
import {createResources} from './resources.js';

Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/lib/times.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {is_function} from 'svelte/internal';
import {addDuration, cloneDate, createDuration, DAY_IN_SECONDS, toISOString, toSeconds} from './date.js';
import {max as maxFn, min as minFn} from './utils.js';
import {max as maxFn, min as minFn, is_function} from './utils.js';
import {bgEvent} from './events.js';

export function createTimes(date, $slotDuration, $_slotTimeLimits, $_intlSlotLabel) {
Expand Down
43 changes: 43 additions & 0 deletions packages/core/src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,46 @@ export function symbol() {
export function isArray(value) {
return Array.isArray(value);
}

/** @param {Array<() => void>} arr */
export function run_all(arr) {
for (var i = 0; i < arr.length; i++) {
arr[i]();
}
}

/**
* @param {any} thing
* @returns {thing is Function}
*/
export function is_function(thing) {
return typeof thing === 'function';
}

export const noop = () => {};


/**
* Fires the handler once immediately (unless corresponding arg is set to `false`),
* then listens to the given events until the render effect context is destroyed
* @param {EventTarget} target
* @param {Array<string>} events
* @param {(event?: Event) => void} handler
* @param {any} call_handler_immediately
*/
export function listen(target, events, handler, call_handler_immediately = true) {
if (call_handler_immediately) {
handler();
}

for (var name of events) {
target.addEventListener(name, handler);
}

teardown(() => {
for (var name of events) {
target.removeEventListener(name, handler);
}
});
}

6 changes: 3 additions & 3 deletions packages/core/src/storage/state.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {get, writable} from 'svelte/store';
import {is_function, tick, noop, identity} from 'svelte/internal';
import {tick} from 'svelte';
import {createOptions, createParsers} from './options';
import {
activeRange,
Expand All @@ -12,7 +12,7 @@ import {
viewTitle,
view as view2 // hack to avoid a runtime error in SvelteKit dev mode (ReferenceError: view is not defined)
} from './stores';
import {keys, intl, intlRange} from '../lib.js';
import {keys, intl, intlRange, is_function} from '../lib.js';

export default class {
constructor(plugins, input) {
Expand Down Expand Up @@ -57,7 +57,7 @@ export default class {
// Interaction
this._interaction = writable({});
this._iEvents = writable([null, null]); // interaction events: [drag/resize, pointer]
this._iClasses = writable(identity); // interaction event css classes
this._iClasses = writable([]); // interaction event css classes
this._iClass = writable(undefined); // interaction css class for entire calendar

// Set & Get
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/storage/stores.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {derived, writable, readable, get} from 'svelte/store';
import {is_function} from 'svelte/internal';
import {is_function} from '../lib/utils.js';
import {
DAY_IN_SECONDS,
assign,
Expand Down
3 changes: 1 addition & 2 deletions packages/day-grid/src/Day.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script>
import {getContext, tick} from 'svelte';
import {is_function} from 'svelte/internal';
import {datesEqual, setContent, createEventChunk, addDay, cloneDate, assign, setPayload, toISOString,
keyEnter, runReposition} from '@event-calendar/core';
keyEnter, runReposition, is_function} from '@event-calendar/core';
import Event from './Event.svelte';
import Popup from './Popup.svelte';
Expand Down
4 changes: 2 additions & 2 deletions packages/day-grid/src/Event.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import {afterUpdate, getContext, onMount} from 'svelte';
import {is_function} from 'svelte/internal';
import {
ancestor,
createEventClasses,
Expand All @@ -17,7 +16,8 @@
keyEnter,
task,
rect,
bgEvent
bgEvent,
is_function
} from '@event-calendar/core';
export let chunk;
Expand Down
4 changes: 2 additions & 2 deletions packages/interaction/src/Action.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import {getContext} from 'svelte';
import {is_function, listen, run_all} from 'svelte/internal';
import {
addDay,
addDuration,
Expand All @@ -18,7 +17,8 @@
toISOString,
toLocalDate,
toViewWithLocalDates,
listView, timelineView
listView, timelineView,
is_function, listen, run_all
} from '@event-calendar/core';
import {animate, limit} from './utils';
Expand Down
3 changes: 1 addition & 2 deletions packages/interaction/src/Auxiliary.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script>
import {getContext} from 'svelte';
import {listen} from 'svelte/internal';
import {bgEvent, helperEvent} from '@event-calendar/core';
import {bgEvent, helperEvent, listen} from '@event-calendar/core';
import Action from './Action.svelte';
import Pointer from './Pointer.svelte';
import Resizer from './Resizer.svelte';
Expand Down
2 changes: 1 addition & 1 deletion packages/interaction/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {writable} from 'svelte/store';
import {noop} from 'svelte/internal';
import {noop} from '@event-calendar/core';
import Auxiliary from './Auxiliary.svelte';

export default {
Expand Down
3 changes: 1 addition & 2 deletions packages/list/src/Body.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script>
import {getContext} from 'svelte';
import {is_function} from 'svelte/internal';
import {addDay, cloneDate, toViewWithLocalDates, setContent, bgEvent} from '@event-calendar/core';
import {addDay, cloneDate, toViewWithLocalDates, setContent, bgEvent, is_function} from '@event-calendar/core';
import Day from './Day.svelte';
let {_bodyEl, _events, _view, _viewDates, noEventsClick, noEventsContent, theme} = getContext('state');
Expand Down
4 changes: 2 additions & 2 deletions packages/list/src/Event.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import {afterUpdate, getContext, onMount} from 'svelte';
import {is_function} from 'svelte/internal';
import {
createEventContent,
toEventWithLocalDates,
Expand All @@ -10,7 +9,8 @@
keyEnter,
resourceBackgroundColor,
resourceTextColor,
task
task,
is_function
} from '@event-calendar/core';
export let chunk;
Expand Down
3 changes: 1 addition & 2 deletions packages/resource-time-grid/src/Label.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script>
import {getContext, onMount, afterUpdate, createEventDispatcher} from 'svelte';
import {is_function} from 'svelte/internal';
import {setContent, toLocalDate} from '@event-calendar/core';
import {setContent, toLocalDate, is_function} from '@event-calendar/core';
export let resource;
export let date = undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/resource-timeline/src/Event.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import {afterUpdate, getContext, onMount} from 'svelte';
import {is_function} from 'svelte/internal';
import {
createEventContent,
createEventClasses,
Expand All @@ -12,7 +11,8 @@
keyEnter,
resourceBackgroundColor,
resourceTextColor,
task, height, DAY_IN_SECONDS, toSeconds
task, height, DAY_IN_SECONDS, toSeconds,
is_function
} from '@event-calendar/core';
import {repositionEvent, getSlotTimeLimits} from './lib.js';
Expand Down
3 changes: 1 addition & 2 deletions packages/resource-timeline/src/Label.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script>
import {getContext, onMount} from 'svelte';
import {is_function} from 'svelte/internal';
import {setContent, toLocalDate} from '@event-calendar/core';
import {setContent, toLocalDate, is_function} from '@event-calendar/core';
export let resource;
export let date = undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/time-grid/src/Event.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import {afterUpdate, getContext, onMount} from 'svelte';
import {is_function} from 'svelte/internal';
import {
createEventContent,
createEventClasses,
Expand All @@ -13,7 +12,8 @@
keyEnter,
resourceBackgroundColor,
resourceTextColor,
task
task,
is_function
} from '@event-calendar/core';
export let date;
Expand Down
4 changes: 2 additions & 2 deletions packages/time-grid/src/all-day/Event.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import {afterUpdate, getContext, onMount} from 'svelte';
import {is_function} from 'svelte/internal';
import {
createEventClasses,
createEventContent,
Expand All @@ -13,7 +12,8 @@
resourceTextColor,
helperEvent,
keyEnter,
task, rect, ancestor, bgEvent
task, rect, ancestor, bgEvent,
is_function
} from '@event-calendar/core';
export let chunk;
Expand Down
2 changes: 1 addition & 1 deletion packages/time-grid/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {is_function} from 'svelte/internal';
import {is_function} from '@event-calendar/core';
import {sortEventChunks} from '@event-calendar/core';

export function groupEventChunks(chunks) {
Expand Down
14 changes: 7 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default [
format: 'es',
file: 'packages/core/index.js'
},
external: ['svelte', 'svelte/internal', 'svelte/store'],
external: ['svelte', 'svelte/store'],
plugins: [
svelte({
compilerOptions: {
Expand All @@ -47,7 +47,7 @@ export default [
format: 'es',
file: 'packages/interaction/index.js'
},
external: ['@event-calendar/core', 'svelte', 'svelte/internal', 'svelte/store'],
external: ['@event-calendar/core', 'svelte', 'svelte/store'],
plugins: [
svelte({
compilerOptions: {
Expand All @@ -64,7 +64,7 @@ export default [
format: 'es',
file: 'packages/day-grid/index.js'
},
external: ['@event-calendar/core', 'svelte', 'svelte/internal', 'svelte/store'],
external: ['@event-calendar/core', 'svelte', 'svelte/store'],
plugins: [
svelte({
compilerOptions: {
Expand All @@ -81,7 +81,7 @@ export default [
format: 'es',
file: 'packages/list/index.js'
},
external: ['@event-calendar/core', 'svelte', 'svelte/internal', 'svelte/store'],
external: ['@event-calendar/core', 'svelte', 'svelte/store'],
plugins: [
svelte({
compilerOptions: {
Expand All @@ -98,7 +98,7 @@ export default [
format: 'es',
file: 'packages/time-grid/index.js'
},
external: ['@event-calendar/core', 'svelte', 'svelte/internal', 'svelte/store'],
external: ['@event-calendar/core', 'svelte', 'svelte/store'],
plugins: [
svelte({
compilerOptions: {
Expand All @@ -115,7 +115,7 @@ export default [
format: 'es',
file: 'packages/resource-time-grid/index.js'
},
external: ['@event-calendar/core', '@event-calendar/time-grid', 'svelte', 'svelte/internal', 'svelte/store'],
external: ['@event-calendar/core', '@event-calendar/time-grid', 'svelte', 'svelte/store'],
plugins: [
svelte({
compilerOptions: {
Expand All @@ -132,7 +132,7 @@ export default [
format: 'es',
file: 'packages/resource-timeline/index.js'
},
external: ['@event-calendar/core', 'svelte', 'svelte/internal', 'svelte/store'],
external: ['@event-calendar/core', 'svelte', 'svelte/store'],
plugins: [
svelte({
compilerOptions: {
Expand Down

0 comments on commit 9758b8f

Please sign in to comment.