-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from mishankov/docs
Docs
- Loading branch information
Showing
18 changed files
with
394 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
# String manipulator | ||
|
||
Application that applies sequence of manipulations to string | ||
|
||
Interactive doc available at https://mishankov.github.io/string-manipulator/docs | ||
|
||
Available manipulations: | ||
- Replace | ||
- Prepend | ||
- Append | ||
- Split, get from index | ||
- Compose | ||
- Slice | ||
- Split-compose | ||
- Split-join |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,12 @@ | ||
<script lang="ts"> | ||
import { type TManipulation, applyManipulations } from "./manipulations"; | ||
import ManipulationsPanel from "./ManipulationsPanel.svelte"; | ||
import TextArea from "./components/TextArea.svelte"; | ||
import Heading from "./components/Heading.svelte"; | ||
let source = "Try me!\nResult will update automatically" | ||
let result = "" | ||
let manipulations: TManipulation[] = [{ | ||
type: "replace", | ||
from: "\\n", to: " -- ", id: "initial" | ||
}] | ||
document.addEventListener("keydown", (event) => { | ||
if (event.ctrlKey && event.key === "Enter") { | ||
result = applyManipulations(source, manipulations) | ||
} | ||
}) | ||
$: result = applyManipulations(source, manipulations) | ||
import Router, { type Route, routes } from "./components/Router.svelte"; | ||
import App from "./pages/App"; | ||
import Docs from "./pages/Docs"; | ||
routes.set([ | ||
{ location: "/", component: App }, | ||
{ location: "/docs", component: Docs } | ||
]) | ||
</script> | ||
|
||
<div class="panels"> | ||
<div class="panel"> | ||
<Heading text="Source" /> | ||
<TextArea id="source" bind:value={source} /> | ||
</div> | ||
|
||
<div class="panel"> | ||
<Heading text="Manipulations" /> | ||
<ManipulationsPanel bind:manipulations /> | ||
</div> | ||
|
||
<div class="panel"> | ||
<Heading text="Result" /> | ||
<TextArea id="result" bind:value={result} /> | ||
</div> | ||
</div> | ||
|
||
|
||
<style> | ||
.panels { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr 1fr; | ||
gap: 10px; | ||
padding: 10px; | ||
} | ||
.panel { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10px; | ||
} | ||
</style> | ||
<Router /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script lang="ts"> | ||
import { navigate } from "./Router.svelte"; | ||
export let link: string; | ||
export let isNavigation = false | ||
</script> | ||
|
||
{#if isNavigation} | ||
<a href="{link}" on:click={navigate}><slot/></a> | ||
{:else} | ||
<a href="{link}"><slot/></a> | ||
{/if} | ||
|
||
|
||
<style> | ||
a { | ||
font-family: monospace; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<script lang="ts" context="module"> | ||
import { onMount, type ComponentType } from "svelte"; | ||
import { get, writable } from "svelte/store"; | ||
import urlStore from "./url-store"; | ||
export interface Route { | ||
location: string | ||
component: ComponentType | ||
} | ||
export const routes = writable<Route[]>(); | ||
export const currentRoute = writable<Route>(); | ||
function pathWithBase(path: string): string { | ||
if (import.meta.env.BASE_URL === "/") return path | ||
return import.meta.env.BASE_URL + path | ||
} | ||
function currentLocation(pathname: string) { | ||
if (pathname === pathWithBase("/")) return pathname; | ||
if (pathname.endsWith("/")) return pathname.slice(0, pathname.length - 1); | ||
return pathname; | ||
}; | ||
function getRoute(href: string, routes: Route[]): Route { | ||
const url = new URL(href); | ||
const route = routes.find(route => pathWithBase(route.location) === currentLocation(url.pathname)) || routes[0] | ||
return route | ||
} | ||
export function navigate(event: MouseEvent) { | ||
event.preventDefault(); | ||
const target = event.target as HTMLAnchorElement | ||
window.history.pushState('', '', target["href"]); | ||
const route = getRoute(target["href"], get(routes)); | ||
currentRoute.set(route); | ||
}; | ||
</script> | ||
|
||
<script lang="ts"> | ||
onMount(() => { | ||
currentRoute.set(getRoute($urlStore.href, $routes)); | ||
}); | ||
$: currentRoute.set(getRoute($urlStore.href, $routes)) | ||
</script> | ||
|
||
{#if $currentRoute} | ||
<svelte:component this={$currentRoute.component}/> | ||
{/if} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Original source: github.com/bluwy/svelte-url/blob/master/src/url.js | ||
|
||
import { derived, writable } from "svelte/store"; | ||
|
||
export function createUrlStore() { | ||
const href = writable(window.location.href); | ||
|
||
const originalPushState = history.pushState; | ||
const originalReplaceState = history.replaceState; | ||
|
||
const updateHref = () => href.set(window.location.href); | ||
|
||
history.pushState = function (data, unused, url) { | ||
originalPushState.apply(this, [data, unused, url]); | ||
updateHref(); | ||
}; | ||
|
||
history.replaceState = function (data, unused, url) { | ||
originalReplaceState.apply(this, [data, unused, url]); | ||
updateHref(); | ||
}; | ||
|
||
window.addEventListener("popstate", updateHref); | ||
window.addEventListener("hashchange", updateHref); | ||
|
||
return { | ||
subscribe: derived(href, ($href) => new URL($href)).subscribe, | ||
}; | ||
} | ||
|
||
export default createUrlStore(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<script lang="ts"> | ||
import { type TManipulation, applyManipulations } from "../../manipulations"; | ||
import ManipulationsPanel from "./ManipulationsPanel.svelte"; | ||
import TextArea from "../../components/TextArea.svelte"; | ||
import Heading from "../../components/Heading.svelte"; | ||
import Link from "../../components/Link.svelte"; | ||
let source = "Try me!\nResult will be updated automatically" | ||
let result = "" | ||
let manipulations: TManipulation[] = [{ | ||
type: "replace", | ||
from: "\\n", to: " -- ", id: "initial" | ||
}] | ||
document.addEventListener("keydown", (event) => { | ||
if (event.ctrlKey && event.key === "Enter") { | ||
result = applyManipulations(source, manipulations) | ||
} | ||
}) | ||
$: result = applyManipulations(source, manipulations) | ||
</script> | ||
|
||
<div class="panels"> | ||
<div class="panel"> | ||
<Heading text="Source" /> | ||
<TextArea id="source" bind:value={source} /> | ||
</div> | ||
|
||
<div class="panel"> | ||
<div class="header-with-link"> | ||
<Heading text="Manipulations" /> <Link link="/docs" isNavigation>Docs</Link> | ||
</div> | ||
<ManipulationsPanel bind:manipulations /> | ||
</div> | ||
|
||
<div class="panel"> | ||
<Heading text="Result" /> | ||
<TextArea id="result" bind:value={result} /> | ||
</div> | ||
</div> | ||
|
||
|
||
<style> | ||
.panels { | ||
display: grid; | ||
grid-template-columns: 1fr auto 1fr; | ||
gap: 10px; | ||
padding: 10px; | ||
} | ||
.panel { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10px; | ||
} | ||
.header-with-link { | ||
display: flex; | ||
flex-direction: row; | ||
gap: 10px; | ||
align-items: end; | ||
} | ||
</style> |
4 changes: 2 additions & 2 deletions
4
src/ManipulationsPanel.svelte → src/pages/App/ManipulationsPanel.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import App from "./App.svelte"; | ||
|
||
export default App; |
Oops, something went wrong.