diff --git a/package-lock.json b/package-lock.json index d40726e..b0bb267 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,13 +14,13 @@ "awesome-qr": "^2.1.5-rc.0", "bulma-calendar": "^6.1.18", "bulma-o-steps": "^1.1.0", - "dayjs": "^1.11.9", + "dayjs": "^1.11.10", "jsonwebtoken-esm": "^2.0.1", "jsqr": "^1.4.0" }, "devDependencies": { "@sveltejs/adapter-static": "2.0.3", - "@sveltejs/kit": "1.27.2", + "@sveltejs/kit": "1.27.3", "@tabler/icons-svelte": "^2.40.0", "@web3-onboard/bitget": "^2.0.1", "@web3-onboard/blocto": "^2.0.0", @@ -31,7 +31,7 @@ "@web3-onboard/frontier": "^2.0.4", "@web3-onboard/gnosis": "2.2.0", "@web3-onboard/infinity-wallet": "^2.0.4", - "@web3-onboard/injected-wallets": "2.10.8", + "@web3-onboard/injected-wallets": "2.10.9", "@web3-onboard/taho": "^2.0.5", "@web3-onboard/torus": "^2.2.6", "@web3-onboard/walletconnect": "2.5.0", @@ -2367,9 +2367,9 @@ } }, "node_modules/@sveltejs/kit": { - "version": "1.27.2", - "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.27.2.tgz", - "integrity": "sha512-2w2VbPpK8DI3QCSVa2UNAv5sKNks1LT8GsEdpk41ffOyO2znGx2ZwcRWacsqlvh3d9lncZuDdANvCbTbuKvy3Q==", + "version": "1.27.3", + "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.27.3.tgz", + "integrity": "sha512-pd7qwX6ww5noA0/FLk45B0aKUeOXWR+pfZsGTrv3dRmj3lTmnki9UTmTdWzHJGrje+BBkGUZHfgGrsSOQQBQpQ==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -4584,9 +4584,9 @@ } }, "node_modules/@web3-onboard/injected-wallets": { - "version": "2.10.8", - "resolved": "https://registry.npmjs.org/@web3-onboard/injected-wallets/-/injected-wallets-2.10.8.tgz", - "integrity": "sha512-qjYwwXSqYApxSS0x5oR7mBggGzhta8LF0ShdBIPl6GG2KfGN233YnSmd3GNTGxYe5RU9p0lxMBaLn82AApxr8Q==", + "version": "2.10.9", + "resolved": "https://registry.npmjs.org/@web3-onboard/injected-wallets/-/injected-wallets-2.10.9.tgz", + "integrity": "sha512-Eo2BAHOaEnhufSCiqgVYT1FeNLKKmEfAEcHcxBVeANar7th8zUBhC5QyorQNwTvsFr9MOxgJe/CELcAFQJalVA==", "dev": true, "dependencies": { "@web3-onboard/common": "^2.3.3", @@ -5587,9 +5587,9 @@ } }, "node_modules/dayjs": { - "version": "1.11.9", - "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.9.tgz", - "integrity": "sha512-QvzAURSbQ0pKdIye2txOzNaHmxtUBXerpY0FJsFXUMKbIZeFm5ht1LS/jFsrncjnmtv8HsG0W2g6c0zUjZWmpA==" + "version": "1.11.10", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.10.tgz", + "integrity": "sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ==" }, "node_modules/debug": { "version": "4.3.4", @@ -11901,9 +11901,9 @@ "requires": {} }, "@sveltejs/kit": { - "version": "1.27.2", - "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.27.2.tgz", - "integrity": "sha512-2w2VbPpK8DI3QCSVa2UNAv5sKNks1LT8GsEdpk41ffOyO2znGx2ZwcRWacsqlvh3d9lncZuDdANvCbTbuKvy3Q==", + "version": "1.27.3", + "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.27.3.tgz", + "integrity": "sha512-pd7qwX6ww5noA0/FLk45B0aKUeOXWR+pfZsGTrv3dRmj3lTmnki9UTmTdWzHJGrje+BBkGUZHfgGrsSOQQBQpQ==", "dev": true, "requires": { "@sveltejs/vite-plugin-svelte": "^2.4.1", @@ -13548,9 +13548,9 @@ } }, "@web3-onboard/injected-wallets": { - "version": "2.10.8", - "resolved": "https://registry.npmjs.org/@web3-onboard/injected-wallets/-/injected-wallets-2.10.8.tgz", - "integrity": "sha512-qjYwwXSqYApxSS0x5oR7mBggGzhta8LF0ShdBIPl6GG2KfGN233YnSmd3GNTGxYe5RU9p0lxMBaLn82AApxr8Q==", + "version": "2.10.9", + "resolved": "https://registry.npmjs.org/@web3-onboard/injected-wallets/-/injected-wallets-2.10.9.tgz", + "integrity": "sha512-Eo2BAHOaEnhufSCiqgVYT1FeNLKKmEfAEcHcxBVeANar7th8zUBhC5QyorQNwTvsFr9MOxgJe/CELcAFQJalVA==", "dev": true, "requires": { "@web3-onboard/common": "^2.3.3", @@ -14314,9 +14314,9 @@ "integrity": "sha512-0VNbwmWJDS/G3ySwFSJA3ayhbURMTJLtwM2DTxf9CWondCnh6DTNlO9JgRSq6ibf4eD0lfMJNBxUdEAHHix+bA==" }, "dayjs": { - "version": "1.11.9", - "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.9.tgz", - "integrity": "sha512-QvzAURSbQ0pKdIye2txOzNaHmxtUBXerpY0FJsFXUMKbIZeFm5ht1LS/jFsrncjnmtv8HsG0W2g6c0zUjZWmpA==" + "version": "1.11.10", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.10.tgz", + "integrity": "sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ==" }, "debug": { "version": "4.3.4", diff --git a/package.json b/package.json index 8fc71cb..2571e2e 100644 --- a/package.json +++ b/package.json @@ -21,13 +21,13 @@ "awesome-qr": "^2.1.5-rc.0", "bulma-calendar": "^6.1.18", "bulma-o-steps": "^1.1.0", - "dayjs": "^1.11.9", + "dayjs": "^1.11.10", "jsonwebtoken-esm": "^2.0.1", "jsqr": "^1.4.0" }, "devDependencies": { "@sveltejs/adapter-static": "2.0.3", - "@sveltejs/kit": "1.27.2", + "@sveltejs/kit": "1.27.3", "@tabler/icons-svelte": "^2.40.0", "@web3-onboard/bitget": "^2.0.1", "@web3-onboard/blocto": "^2.0.0", @@ -39,7 +39,7 @@ "@web3-onboard/infinity-wallet": "^2.0.4", "@web3-onboard/taho": "^2.0.5", "@web3-onboard/gnosis": "2.2.0", - "@web3-onboard/injected-wallets": "2.10.8", + "@web3-onboard/injected-wallets": "2.10.9", "@web3-onboard/torus": "^2.2.6", "@web3-onboard/walletconnect": "2.5.0", "@web3-onboard/xdefi": "^2.0.5", diff --git a/src/lib/actions/utils.js b/src/lib/actions/utils.js new file mode 100644 index 0000000..b5a5276 --- /dev/null +++ b/src/lib/actions/utils.js @@ -0,0 +1,116 @@ +import { tick } from 'svelte' +import { writable } from 'svelte/store' + +export const portal = (el, target = 'body') => { + let targetEl + async function update(newTarget) { + target = newTarget + if (typeof target === 'string') { + targetEl = document.querySelector(target) + if (targetEl === null) { + await tick() + targetEl = document.querySelector(target) + } + if (targetEl === null) { + throw new Error(`No element found matching css selector: "${target}"`) + } + } else if (target instanceof HTMLElement) { + targetEl = target + } else { + throw new TypeError( + `Unknown portal target type: ${ + target === null ? 'null' : typeof target + }. Allowed types: string (CSS selector) or HTMLElement.` + ) + } + targetEl.appendChild(el) + el.hidden = false + } + + function destroy() { + if (el.parentNode) { + el.parentNode.removeChild(el) + } + } + + update(target) + return { + update, + destroy + } +} + +export const invertedScroll = (node, active) => { + const handleWheel = (event) => { + if (active && event.deltaY) { + event.preventDefault() + event.currentTarget.scrollTop -= + parseFloat( + getComputedStyle(event.currentTarget).getPropertyValue('font-size') + ) * + (event.deltaY < 0 ? -1 : 1) * + 2 + } + } + + node.addEventListener('wheel', handleWheel, true) + return { + update(newActive) { + active = newActive + }, + destroy() { + node.removeEventListener('wheel', handleWheel, true) + } + } +} + +export const clickOutside = (node) => { + const handleClick = (event) => { + if (node && !node.contains(event.target) && !event.defaultPrevented) { + node.dispatchEvent(new CustomEvent('click_outside', node)) + } + } + + document.addEventListener('click', handleClick, true) + return { + destroy() { + document.removeEventListener('click', handleClick, true) + } + } +} + +export const createSelector = (multiple = false) => { + let selectable = 0 + + const { subscribe, update } = writable({}) + + const addSelectable = (selected = false) => { + update(($selector) => ({ + ...$selector, + [++selectable]: selected + })) + return selectable + } + + const simpleSelect = (index) => { + update(($selector) => + Object.keys($selector).reduce((acc, key) => { + acc[key] = parseInt(key) === index + return acc + }, {}) + ) + } + + const mutipleSelect = (index) => { + update(($selector) => ({ + ...$selector, + [index]: !$selector[index] + })) + } + + return { + subscribe, + addSelectable, + select: multiple ? mutipleSelect : simpleSelect + } +}