Skip to content

Commit

Permalink
group demo routes
Browse files Browse the repository at this point in the history
update deps
  • Loading branch information
janosh committed Jan 14, 2023
1 parent a82b467 commit e813e48
Show file tree
Hide file tree
Showing 21 changed files with 107 additions and 113 deletions.
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
"devDependencies": {
"@iconify/svelte": "^3.0.1",
"@playwright/test": "^1.29.2",
"@sveltejs/adapter-static": "1.0.1",
"@sveltejs/kit": "1.0.7",
"@sveltejs/adapter-static": "^1.0.2",
"@sveltejs/kit": "^1.1.0",
"@sveltejs/package": "1.0.2",
"@sveltejs/vite-plugin-svelte": "^2.0.2",
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
"@vitest/coverage-c8": "^0.26.3",
"@typescript-eslint/eslint-plugin": "^5.48.1",
"@typescript-eslint/parser": "^5.48.1",
"@vitest/coverage-c8": "^0.27.1",
"eslint": "^8.31.0",
"eslint-plugin-svelte3": "^4.0.0",
"hastscript": "^7.2.0",
Expand All @@ -43,17 +43,16 @@
"prettier-plugin-svelte": "^2.9.0",
"rehype-autolink-headings": "^6.1.1",
"rehype-slug": "^5.1.0",
"svelte": "^3.55.0",
"svelte-check": "^3.0.1",
"svelte-github-corner": "^0.2.0",
"svelte": "^3.55.1",
"svelte-check": "^3.0.2",
"svelte-preprocess": "^5.0.0",
"svelte-toc": "^0.5.1",
"svelte-zoo": "^0.1.4",
"svelte-toc": "^0.5.2",
"svelte-zoo": "^0.2.0",
"svelte2tsx": "^0.6.0",
"tslib": "^2.4.1",
"typescript": "^4.9.4",
"vite": "^4.0.4",
"vitest": "^0.26.3"
"vitest": "^0.27.1"
},
"keywords": [
"svelte",
Expand Down
23 changes: 23 additions & 0 deletions src/routes/(demos)/+layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script lang="ts">
import { name } from '$root/package.json'
import { DemoNav } from '$site'
</script>

<h1>
<img src="favicon.svg" alt={name} height="50" width="50" />&ensp;Svelte MultiSelect
</h1>

<main>
<DemoNav style="place-content: center;" />

<slot />
</main>

<style>
h1 {
text-align: center;
display: flex;
place-content: center;
place-items: center;
}
</style>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import MultiSelect from '$lib'
import { foods, languages } from '$src/options'
import LanguageSlot from '$src/site/LanguageSlot.svelte'
import { LanguageSlot } from '$site'

let selected_empty = []
</script>
Expand Down Expand Up @@ -35,7 +35,7 @@
<script>
import MultiSelect from '$lib'
import { languages } from '$src/options'
import LanguageSlot from '$src/site/LanguageSlot.svelte'
import { LanguageSlot } from '$site'

let selected_append = ['Haskell', 'TypeScript']
</script>
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This example shows the JavaScript way of handling MultiSelect fields in form sub
```svelte example stackblitz
<script lang="ts">
import MultiSelect from '$lib'
import ColorSlot from '$src/site/ColorSlot.svelte'
import { ColorSlot } from '$site'
import { colors } from '$src/options'

async function handle_submit(event: SubmitEvent) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ HTML.
```svelte example stackblitz
<script lang="ts">
import MultiSelect from '$lib'
import ColorSlot from '$src/site/ColorSlot.svelte'
import { ColorSlot } from '$site'
import { colors } from '$src/options'
import { repository } from '$root/package.json'
import type { ActionData, PageServerData } from './$types'
Expand Down Expand Up @@ -92,7 +92,7 @@ HTML.

### +page.server.ts

The above codes needs to be in a `+page.svelte` file with the following `+page.server.ts` file in the same directory next to it.
The above code needs to be in a `+page.svelte` file with the following `+page.server.ts` file in the same directory next to it.

```ts
import { invalid } from '@sveltejs/kit'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<script lang="ts">
import MultiSelect from '$lib'
import { languages } from '$src/options'
import LanguageSlot from '$src/site/LanguageSlot.svelte'
import { LanguageSlot } from '$site'
</script>

<MultiSelect
Expand Down Expand Up @@ -46,7 +46,7 @@ When setting an integer value for `maxSelect` Multiselect will

<br />

Of course you can combine `maxSelect={n}` and `required={m}` where `n>=m`.
Of course, you can combine `maxSelect={n}` and `required={m}` where `n>=m`.

```svelte example stackblitz
<script lang="ts">
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<script>
import MultiSelect from '$lib'
import { languages } from '$src/options'
import LanguageSlot from '$src/site/LanguageSlot.svelte'
import { LanguageSlot } from '$site'
import { language_store } from '$src/stores'
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
<script>
import MultiSelect from '$lib'
import { languages } from '$src/options'
import LanguageSlot from '$src/site/LanguageSlot.svelte'
import { LanguageSlot, MinusIcon } from '$site'
import { Icon } from 'svelte-zoo'
import MinusIcon from '$src/site/MinusIcon.svelte'
</script>

<MultiSelect
Expand All @@ -30,7 +29,7 @@
<script>
import MultiSelect from '$lib'
import { languages } from '$src/options'
import LanguageSlot from '$src/site/LanguageSlot.svelte'
import { LanguageSlot } from '$site'
import { Icon } from 'svelte-zoo'

// local variable used in CollapseIcon on:click callback to close dropdown
Expand Down
File renamed without changes.
File renamed without changes.
52 changes: 2 additions & 50 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,67 +1,19 @@
<script lang="ts">
import { page } from '$app/stores'
import { repository } from '$root/package.json'
import GitHubCorner from 'svelte-github-corner'
import { GitHubCorner } from 'svelte-zoo'
import '../app.css'
import { _demo_routes } from './+layout'
$: is_current = (path: string) => {
if (path === $page.url.pathname) return `page`
if (path !== `/` && $page.url.pathname.includes(path)) return `page`
return undefined
}
</script>

<GitHubCorner href={repository} />

{#if !$page.error && $page.url.pathname !== `/`}
<a href="." aria-label="Back to index page">&laquo; home</a>
{/if}
{#if _demo_routes.some((route) => $page.url.pathname.endsWith(route))}
<h1>
<img src="favicon.svg" alt="Svelte MultiSelect" height="50" width="50" />&ensp;Svelte
MultiSelect Examples
</h1>

<nav>
{#each _demo_routes as route, idx}
{#if idx > 0}<strong>&bull;</strong>{/if}
<a href={route} aria-current={is_current(route)}>{route}</a>
{/each}
</nav>

<main>
<slot />
</main>
{:else}
<!-- handles non-svx routes index.svelte and +error.svelte -->
<slot />
{/if}
<slot />

<style>
h1 {
text-align: center;
display: flex;
place-content: center;
place-items: center;
}
nav {
display: flex;
gap: 1em 1ex;
place-content: center;
margin: 1em auto 3em;
max-width: 45em;
flex-wrap: wrap;
}
nav > a {
padding: 0 4pt;
background-color: rgba(255, 255, 255, 0.1);
border-radius: 3pt;
transition: 0.2s;
}
nav > a[aria-current='page'] {
color: mediumseagreen;
}
a[href='.'] {
font-size: 15pt;
position: absolute;
Expand Down
10 changes: 0 additions & 10 deletions src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ import type { LayoutLoad } from './$types'

export const prerender = true

export const _demo_routes = Object.keys(
import.meta.glob(`./*/+page.{svx,md,svelte}`)
)
.map((filename) => filename.split(`/`)[1])
.filter((name) => ![`contributing`, `changelog`].includes(name))

if (_demo_routes.length < 5) {
throw new Error(`Too few demo routes found: ${_demo_routes.length}`)
}

export const load: LayoutLoad = ({ url }) => {
if (url.pathname.endsWith(`.md`)) {
throw redirect(307, url.pathname.replace(/\.md$/, ``))
Expand Down
20 changes: 2 additions & 18 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script lang="ts">
import Readme from '$root/readme.md'
import { DemoNav, Examples } from '$site'
import Toc from 'svelte-toc'
import Examples from '../site/Examples.svx'
import { _demo_routes } from './+layout'
</script>

<main>
Expand All @@ -14,29 +13,14 @@
Some more in-depth examples for specific features of
<code>svelte-multiselect</code>:
</p>
<nav>
{#each _demo_routes as route, idx}
{#if idx > 0}<strong>&bull;</strong>{/if}
<a href={route}>{route}</a>
{/each}
</nav>
<DemoNav />
</svelte:fragment>
</Readme>
</main>

<Toc headingSelector="main > :where(h2, h3)" breakpoint={1250} />

<style>
nav {
display: flex;
gap: 2ex 1ex;
flex-wrap: wrap;
}
nav a {
padding: 1pt 4pt;
background-color: rgba(255, 255, 255, 0.1);
border-radius: 3pt;
}
@media (max-width: 600px) {
:global(h1[align='center']) {
display: flex;
Expand Down
43 changes: 43 additions & 0 deletions src/site/DemoNav.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<script lang="ts">
import { page } from '$app/stores'
export let style: string | null = null
const routes = Object.keys(
// eslint-disable-next-line @typescript-eslint/quotes
import.meta.glob('/src/routes/\\(demos\\)/*/+page*.{svx,md,svelte}')
).map((filename) => filename.split(`/`)[4])
if (routes.length < 3) {
throw new Error(`Too few demo routes found: ${routes.length}`)
}
$: is_current = (path: string) => {
if (path === $page.url.pathname) return `page`
if (path !== `/` && $page.url.pathname.includes(path)) return `page`
return undefined
}
</script>

<nav {style}>
{#each routes as href, idx}
{#if idx > 0}<strong>&bull;</strong>{/if}
<a {href} aria-current={is_current(href)}>{href}</a>
{/each}
</nav>

<style>
nav {
display: flex;
gap: 1em 1ex;
flex-wrap: wrap;
}
nav > a {
padding: 0 4pt;
background-color: rgba(255, 255, 255, 0.1);
border-radius: 3pt;
transition: 0.2s;
}
nav > a[aria-current='page'] {
color: mediumseagreen;
}
</style>
7 changes: 7 additions & 0 deletions src/site/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export { default as ColorSlot } from './ColorSlot.svelte'
export { default as DemoNav } from './DemoNav.svelte'
export { default as Examples } from './Examples.svx'
export { default as IconifySlot } from './IconifySlot.svelte'
export { default as LanguageSlot } from './LanguageSlot.svelte'
export { default as MinusIcon } from './MinusIcon.svelte'
export { default as RepoSlot } from './RepoSlot.svelte'
15 changes: 10 additions & 5 deletions svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import adapter from '@sveltejs/adapter-static'
import { s } from 'hastscript'
import { mdsvex } from 'mdsvex'
import examples from 'mdsvexamples'
import linkHeadings from 'rehype-autolink-headings'
import headingSlugs from 'rehype-slug'
import link_headings from 'rehype-autolink-headings'
import heading_slugs from 'rehype-slug'
import preprocess from 'svelte-preprocess'

const rehypePlugins = [
headingSlugs,
heading_slugs,
[
linkHeadings,
link_headings,
{
behavior: `append`,
test: [`h2`, `h3`, `h4`, `h5`, `h6`], // don't auto-link <h1>
Expand All @@ -30,7 +30,6 @@ const defaults = {
pkg: pkg.name,
repo: pkg.repository,
}

const remarkPlugins = [[examples, { defaults }]]

/** @type {import('@sveltejs/kit').Config} */
Expand All @@ -44,6 +43,12 @@ export default {

kit: {
adapter: adapter(),

alias: {
$root: `.`,
$src: `./src`,
$site: `./src/site`,
},
},

package: {
Expand Down
8 changes: 0 additions & 8 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { sveltekit } from '@sveltejs/kit/vite'
import examples from 'mdsvexamples/vite'
import { resolve } from 'path'
import type { UserConfig } from 'vite'
import type { UserConfig as VitestConfig } from 'vitest'

Expand All @@ -15,13 +14,6 @@ const vite_config: UserConfig & { test: VitestConfig } = {
},
},

resolve: {
alias: {
$src: resolve(`./src`),
$root: resolve(`.`),
},
},

server: {
fs: { allow: [`..`] }, // needed to import from $root
port: 3000,
Expand Down

0 comments on commit e813e48

Please sign in to comment.