Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Remove access to the svelte/internal API which is deprecated #330

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 35 additions & 34 deletions package-lock.json

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

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "event-calendar",
"version": "3.4.0",
"version": "4.0.0",
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
Expand All @@ -13,14 +13,14 @@
"@babel/plugin-transform-runtime": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"@babel/runtime-corejs3": "^7.24.7",
"@event-calendar/build": "~3.4.0",
"@event-calendar/core": "~3.4.0",
"@event-calendar/day-grid": "~3.4.0",
"@event-calendar/interaction": "~3.4.0",
"@event-calendar/list": "~3.4.0",
"@event-calendar/resource-time-grid": "~3.4.0",
"@event-calendar/resource-timeline": "~3.4.0",
"@event-calendar/time-grid": "~3.4.0",
"@event-calendar/build": "~4.0.0",
"@event-calendar/core": "~4.0.0",
"@event-calendar/day-grid": "~4.0.0",
"@event-calendar/interaction": "~4.0.0",
"@event-calendar/list": "~4.0.0",
"@event-calendar/resource-time-grid": "~4.0.0",
"@event-calendar/resource-timeline": "~4.0.0",
"@event-calendar/time-grid": "~4.0.0",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
Expand All @@ -33,7 +33,7 @@
"rollup-plugin-scss": "^4.0.0",
"rollup-plugin-svelte": "^7.2.2",
"sass": "^1.77.6",
"svelte": "^4.2.18"
"svelte": "^4.2.19 || ^5.0.0-next.249"
},
"dependencies": {
"sirv-cli": "^2.0.2"
Expand Down
14 changes: 7 additions & 7 deletions packages/build/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@event-calendar/build",
"version": "3.4.0",
"version": "4.0.0",
"title": "Event Calendar",
"description": "Full-sized drag & drop event calendar with resource & timeline views",
"keywords": [
Expand All @@ -20,11 +20,11 @@
"jsdelivr": "event-calendar.min.js",
"style": "event-calendar.min.css",
"devDependencies": {
"@event-calendar/day-grid": "~3.4.0",
"@event-calendar/interaction": "~3.4.0",
"@event-calendar/list": "~3.4.0",
"@event-calendar/time-grid": "~3.4.0",
"@event-calendar/resource-time-grid": "~3.4.0",
"@event-calendar/resource-timeline": "~3.4.0"
"@event-calendar/day-grid": "~4.0.0",
"@event-calendar/interaction": "~4.0.0",
"@event-calendar/list": "~4.0.0",
"@event-calendar/time-grid": "~4.0.0",
"@event-calendar/resource-time-grid": "~4.0.0",
"@event-calendar/resource-timeline": "~4.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@event-calendar/core",
"version": "3.4.0",
"version": "4.0.0",
"title": "Event Calendar Core package",
"description": "Full-sized drag & drop event calendar with resource & timeline views",
"keywords": [
Expand Down
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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using Svelte's on method from svelte/events for this instead. Handles a few edge cases around event delegation which may or may not be relevant in this repo (I haven't checked)

}

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
Loading