Skip to content

Commit f211a11

Browse files
committed
First Commit
0 parents  commit f211a11

25 files changed

+4683
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = false
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.eslintignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package
6+
.env
7+
.env.*
8+
!.env.example
9+
10+
# Ignore files for PNPM, NPM and YARN
11+
pnpm-lock.yaml
12+
package-lock.json
13+
yarn.lock

.eslintrc.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true
6+
},
7+
"extends": [
8+
"standard"
9+
],
10+
"parser": "@typescript-eslint/parser",
11+
"parserOptions": {
12+
"ecmaVersion": 2020,
13+
"sourceType": "module"
14+
},
15+
"plugins": [
16+
"svelte3",
17+
"@typescript-eslint"
18+
],
19+
"settings": {
20+
"svelte3/typescript": true
21+
},
22+
"overrides": [
23+
{
24+
"files": ["*.svelte"],
25+
"processor": "svelte3/svelte3",
26+
"rules": {
27+
"import/first": "off",
28+
"no-multiple-empty-lines": "off",
29+
"no-use-before-define": "off"
30+
}
31+
}
32+
],
33+
"rules": {
34+
"indent": ["warn", 4, { "ignoredNodes": ["VariableDeclaration[declarations.length=0]"] }],
35+
"brace-style": ["warn", "stroustrup"],
36+
"space-before-function-paren": "off",
37+
"no-explicit-any": "off"
38+
}
39+
}

.gitignore

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package
6+
.env
7+
.env.*
8+
!.env.example
9+
10+
.idea
11+
sample_code/data/**/
12+
sample_code/model
13+
.env
14+
.venv
15+
16+
/node_modules
17+
build
18+
**/__pycache__

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict=true

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SvelteKit BoilerPlate
2+
3+
This is a BoilerPlater with erverything I like to use in a SveltreKit application.
4+
5+
## It uses the following techonologies:
6+
7+
SvelteKit, PostCSS, Sass, Typescript, Vite, Jest and ESLint
8+
9+
### To install the dependencies use yarn.
10+
11+
```bash
12+
# Install it globally
13+
npm i -g yarn
14+
# Install the dependencies
15+
yarn
16+
17+
```
18+
19+
### To run the dev server, run
20+
21+
```bash
22+
23+
yarn dev
24+
25+
```

jest.config.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Config } from '@jest/types'
2+
3+
const config: Config.InitialOptions = {
4+
preset: 'ts-jest',
5+
verbose: true,
6+
collectCoverage: true,
7+
collectCoverageFrom: [
8+
'pages/*.{svelte}',
9+
'src/**/*.{ts,svelte}',
10+
'!src/**/*.d.ts'
11+
],
12+
transform: {
13+
'^.+\\.tsx?$': 'ts-jest'
14+
},
15+
moduleNameMapper: {
16+
'\\$/(.*)': '<rootDir>/src/$1'
17+
}
18+
}
19+
20+
export default config

package.json

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "sepyrate",
3+
"version": "0.0.1",
4+
"type": "module",
5+
"license": "MIT",
6+
"scripts": {
7+
"dev": "vite dev",
8+
"build": "vite build",
9+
"package": "svelte-kit package",
10+
"preview": "vite preview",
11+
"prepare": "svelte-kit sync",
12+
"check": "svelte-check --tsconfig ./tsconfig.json",
13+
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
14+
"lint": "eslint .",
15+
"test": "jest"
16+
},
17+
"devDependencies": {
18+
"@jest/types": "^28.1.1",
19+
"@poppanator/sveltekit-svg": "^0.3.4",
20+
"@sveltejs/adapter-static": "^1.0.0-next.35",
21+
"@sveltejs/kit": "next",
22+
"@testing-library/svelte": "^3.1.3",
23+
"@testing-library/user-event": "^14.2.1",
24+
"@types/jest": "^28.1.4",
25+
"@types/node": "^18.0.3",
26+
"@types/testing-library__jest-dom": "^5.14.5",
27+
"@typescript-eslint/eslint-plugin": "^5.27.0",
28+
"@typescript-eslint/parser": "^5.27.0",
29+
"autoprefixer": "^10.4.7",
30+
"eslint": "^8.16.0",
31+
"eslint-config-standard": "^17.0.0",
32+
"eslint-plugin-import": "^2.26.0",
33+
"eslint-plugin-n": "^15.2.4",
34+
"eslint-plugin-promise": "^6.0.0",
35+
"eslint-plugin-svelte3": "^4.0.0",
36+
"eslint-plugin-testing-library": "^5.5.1",
37+
"jest": "^28.1.2",
38+
"postcss": "^8.4.14",
39+
"postcss-custom-media": "^8.0.2",
40+
"postcss-custom-selectors": "^6.0.3",
41+
"postcss-extend-rule": "^4.0.0",
42+
"postcss-import": "^14.1.0",
43+
"postcss-media-minmax": "^5.0.0",
44+
"postcss-nested": "^5.0.6",
45+
"postcss-scss": "^4.0.4",
46+
"postcss-simple-vars": "^6.0.3",
47+
"sass": "^1.53.0",
48+
"svelte": "^3.44.0",
49+
"svelte-check": "^2.7.1",
50+
"svelte-preprocess": "^4.10.6",
51+
"testing-library": "^0.0.2",
52+
"ts-jest": "^28.0.5",
53+
"ts-node": "^10.8.2",
54+
"tslib": "^2.3.1",
55+
"typescript": "^4.7.4",
56+
"vite": "^2.9.13"
57+
}
58+
}

pages/__layout.svelte

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script lang="ts">
2+
import { onMount } from 'svelte'
3+
import { theme } from '$/stores/theme'
4+
5+
$: ready = !import.meta.env.DEV
6+
7+
onMount(() => {
8+
document.body.classList.add($theme)
9+
ready = true
10+
})
11+
</script>
12+
13+
<slot/>
14+
15+
<style lang="scss" global>
16+
@use "../styles/app.scss";
17+
</style>

pages/index.svelte

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script lang="ts">
2+
const name = 'Daniel'
3+
</script>
4+
5+
<header>
6+
<h1> SvelteKit Boilerplate</h1>
7+
<p>
8+
Project made by {name}.
9+
</p>
10+
</header>
11+
12+
<style lang="postcss">
13+
header {
14+
h1 {
15+
font-size: 1rem;
16+
}
17+
p {
18+
font-size: 0.6rem;
19+
}
20+
}
21+
</style>

public/favicon.png

1.53 KB
Loading

src/app.d.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference types="@sveltejs/kit" />
2+
3+
// See https://kit.svelte.dev/docs/types#app
4+
// for information about these interfaces
5+
// and what to do when importing types
6+
declare namespace App {
7+
// interface Locals {}
8+
// interface Platform {}
9+
// interface Session {}
10+
// interface Stuff {}
11+
}

src/app.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
8+
%sveltekit.head%
9+
</head>
10+
<body id="app">
11+
%sveltekit.body%
12+
</body>
13+
</html>

src/lib/clickToggle.ts

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
type Options = {
2+
item?: string
3+
outside?: boolean
4+
save?: boolean
5+
key?: string
6+
}
7+
8+
const CLASS_NAME = 'visible'
9+
10+
/**
11+
* Toggle visible and hidden an element.
12+
*
13+
* The element to toggle should be exactly after the one that uses the action.
14+
*
15+
* @param element The element that uses the action, should not be passed.
16+
* @param options.item The item that will be toggled.
17+
* Use `next` to use the one immediately after the `element`.
18+
*
19+
* @param options.save Specify if the element should be save to localStorage or not.
20+
* @param options.key The key to be saved to localStorage, only work if save is true.
21+
*
22+
* @returns Nothing, just remove Event Listenner.
23+
*/
24+
25+
export function clickInside(element: Element, options?: Options) {
26+
// This occurs when clickOutside is used in an element other than clickInside.
27+
28+
function onClick() {
29+
let item: Element = element
30+
31+
if ((options) && (options.item)) {
32+
if (options.item !== 'next') {
33+
item = document.querySelector(options.item) || item
34+
}
35+
else {
36+
item = element.nextElementSibling || item
37+
}
38+
}
39+
40+
item.dispatchEvent(new CustomEvent('clickInside'))
41+
item.classList.toggle(CLASS_NAME)
42+
43+
if (options) {
44+
if ((options.save) && (options.key)) {
45+
const hasClass = item.classList.contains(CLASS_NAME)
46+
localStorage.setItem(options.key, hasClass.toString())
47+
}
48+
49+
if (options.outside) {
50+
clickOutside(item, element)
51+
}
52+
}
53+
}
54+
55+
element.addEventListener('click', onClick, true)
56+
57+
return {
58+
destroy() {
59+
element.removeEventListener('click', onClick, true)
60+
}
61+
}
62+
}
63+
/**
64+
* Hides a visible element when click outside it.
65+
*
66+
* Use it together clickInside.
67+
*
68+
* @param element The element that uses the action, should not be passed.
69+
*
70+
* @param toggle The element that toggle the class.
71+
*
72+
* @returns Nothing, just remove Event Listenner.
73+
*/
74+
75+
export function clickOutside(element: Element, toggle?: Element) {
76+
function onClick(event: any) {
77+
if ((!element.contains(event.target)) && (!toggle?.contains(event.target))) {
78+
const item: Element = element
79+
80+
item.classList.remove(CLASS_NAME)
81+
}
82+
}
83+
84+
document.body.addEventListener('click', onClick, true)
85+
86+
return {
87+
destroy() {
88+
document.body.removeEventListener('click', onClick, true)
89+
}
90+
}
91+
}

src/lib/store.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { writable } from 'svelte/store'
2+
import { browser } from '$app/env'
3+
4+
export function savable<T>(key: string, initial: string | [] | {} | boolean, save: boolean = true) {
5+
let data: any = initial
6+
7+
if (save) {
8+
const persist = browser && localStorage.getItem(key)
9+
data = persist ? JSON.parse(persist) : initial
10+
}
11+
12+
const store = writable<T>(data, () => {
13+
const unsubscribe: any = store.subscribe((value) => {
14+
if (save) {
15+
browser && localStorage.setItem(key, JSON.stringify(value))
16+
}
17+
})
18+
19+
return unsubscribe
20+
})
21+
22+
return store
23+
}

src/stores/theme.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { get } from 'svelte/store'
2+
import { savable } from '$/lib/store'
3+
4+
export const themes = ['light', 'dark']
5+
export const theme = savable<string>('theme', themes[0], true)
6+
7+
export const handleTheme = (event: any) => {
8+
const newTheme = event.target.value
9+
10+
document.body.classList.replace(get(theme), newTheme)
11+
theme.set(newTheme)
12+
}

0 commit comments

Comments
 (0)