Initial commit.
Less hacky than the backend stuff, but not by too much. Can request and display one-shot/real-time data. Can fetch current clusters/topics from the backend. Can (barely) configure a new cluster for the backend to use. A lot of boilerplate from sveltekit is still kicking around.
This commit is contained in:
commit
d926a9cd36
|
@ -0,0 +1,13 @@
|
|||
.DS_Store
|
||||
node_modules
|
||||
/build
|
||||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
# Ignore files for PNPM, NPM and YARN
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
yarn.lock
|
|
@ -0,0 +1,15 @@
|
|||
module.exports = {
|
||||
root: true,
|
||||
extends: ['eslint:recommended', 'prettier'],
|
||||
plugins: ['svelte3'],
|
||||
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
ecmaVersion: 2020
|
||||
},
|
||||
env: {
|
||||
browser: true,
|
||||
es2017: true,
|
||||
node: true
|
||||
}
|
||||
};
|
|
@ -0,0 +1,11 @@
|
|||
.DS_Store
|
||||
node_modules
|
||||
/build
|
||||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
.vercel
|
||||
.output
|
||||
.idea/
|
|
@ -0,0 +1,13 @@
|
|||
.DS_Store
|
||||
node_modules
|
||||
/build
|
||||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
|
||||
# Ignore files for PNPM, NPM and YARN
|
||||
pnpm-lock.yaml
|
||||
package-lock.json
|
||||
yarn.lock
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"useTabs": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"printWidth": 100
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
# create-svelte
|
||||
|
||||
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
|
||||
|
||||
## Creating a project
|
||||
|
||||
If you're seeing this, you've probably already done this step. Congrats!
|
||||
|
||||
```bash
|
||||
# create a new project in the current directory
|
||||
npm create svelte@latest
|
||||
|
||||
# create a new project in my-app
|
||||
npm create svelte@latest my-app
|
||||
```
|
||||
|
||||
## Developing
|
||||
|
||||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
|
||||
# or start the server and open the app in a new browser tab
|
||||
npm run dev -- --open
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
To create a production version of your app:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
You can preview the production build with `npm run preview`.
|
||||
|
||||
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"extends": "./.svelte-kit/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": true,
|
||||
"strict": true
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"name": "my-app",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"dev": "vite dev",
|
||||
"build": "vite build",
|
||||
"package": "svelte-kit package",
|
||||
"preview": "vite preview",
|
||||
"check": "svelte-check --tsconfig ./jsconfig.json",
|
||||
"check:watch": "svelte-check --tsconfig ./jsconfig.json --watch",
|
||||
"lint": "prettier --check --plugin-search-dir=. . && eslint .",
|
||||
"format": "prettier --write --plugin-search-dir=. ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-auto": "next",
|
||||
"@sveltejs/kit": "next",
|
||||
"@types/cookie": "^0.5.1",
|
||||
"eslint": "^8.16.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-svelte3": "^4.0.0",
|
||||
"prettier": "^2.6.2",
|
||||
"prettier-plugin-svelte": "^2.7.0",
|
||||
"svelte": "^3.46.0",
|
||||
"svelte-check": "^2.7.1",
|
||||
"typescript": "^4.7.4",
|
||||
"vite": "^3.0.0"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@zerodevx/svelte-json-view": "^0.2.1",
|
||||
"@fontsource/fira-mono": "^4.5.0",
|
||||
"cookie": "^0.4.1",
|
||||
"highlight.js": "^11.6.0",
|
||||
"svelte-highlight": "^6.2.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
@import '@fontsource/fira-mono';
|
||||
|
||||
:root {
|
||||
font-family: Arial, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
|
||||
Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
||||
--font-mono: 'Fira Mono', monospace;
|
||||
--pure-white: #ffffff;
|
||||
--primary-color: #e7f4ff;
|
||||
--secondary-color: #d0dde9;
|
||||
--tertiary-color: #edf0f8;
|
||||
--accent-color: #ff0df8;
|
||||
--heading-color: rgba(0, 0, 0, 0.7);
|
||||
--text-color: #444444;
|
||||
--background-without-opacity: rgba(255, 255, 255, 0.7);
|
||||
--column-width: 42rem;
|
||||
--column-margin-top: 4rem;
|
||||
}
|
||||
|
||||
body {
|
||||
min-height: 100vh;
|
||||
margin: 0;
|
||||
background-color: var(--primary-color);
|
||||
/*
|
||||
background: linear-gradient(
|
||||
180deg,
|
||||
var(--primary-color) 0%,
|
||||
var(--secondary-color) 10.45%,
|
||||
var(--tertiary-color) 41.35%
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
body::before {
|
||||
content: '';
|
||||
width: 80vw;
|
||||
height: 100vh;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 10vw;
|
||||
z-index: -1;
|
||||
/*
|
||||
background: radial-gradient(
|
||||
50% 50% at 50% 50%,
|
||||
var(--pure-white) 0%,
|
||||
rgba(255, 255, 255, 0) 100%
|
||||
);
|
||||
opacity: 0.05;
|
||||
*/
|
||||
}
|
||||
|
||||
#svelte {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
h1,
|
||||
h2,
|
||||
p {
|
||||
font-weight: 400;
|
||||
color: var(--heading-color);
|
||||
}
|
||||
|
||||
h3 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
p {
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--accent-color);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
pre {
|
||||
font-size: 16px;
|
||||
font-family: var(--font-mono);
|
||||
background-color: rgba(255, 255, 255, 0.45);
|
||||
border-radius: 3px;
|
||||
box-shadow: 2px 2px 6px rgb(255 255 255 / 25%);
|
||||
padding: 0.5em;
|
||||
overflow-x: auto;
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
.bracket {
|
||||
color: #d0dde9;
|
||||
}
|
||||
|
||||
input,
|
||||
button {
|
||||
font-size: inherit;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.settings-option {
|
||||
padding: 1em;
|
||||
margin-bottom: 1em;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-style: solid;
|
||||
border-color: #b3ddef;
|
||||
border-width: 1px;
|
||||
}
|
||||
|
||||
button:focus:not(:focus-visible) {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
@media (min-width: 720px) {
|
||||
h1 {
|
||||
font-size: 2.4rem;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
// See https://kit.svelte.dev/docs/types#app
|
||||
// for information about these interfaces
|
||||
// and what to do when importing types
|
||||
declare namespace App {
|
||||
interface Locals {
|
||||
userid: string;
|
||||
}
|
||||
|
||||
// interface Platform {}
|
||||
|
||||
// interface PrivateEnv {}
|
||||
|
||||
// interface PublicEnv {}
|
||||
|
||||
// interface Session {}
|
||||
|
||||
// interface Stuff {}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<body>
|
||||
<div>%sveltekit.body%</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,23 @@
|
|||
import * as cookie from 'cookie';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Handle} */
|
||||
export const handle = async ({ event, resolve }) => {
|
||||
const cookies = cookie.parse(event.request.headers.get('cookie') || '');
|
||||
event.locals.userid = cookies['userid'] || crypto.randomUUID();
|
||||
|
||||
const response = await resolve(event);
|
||||
|
||||
if (!cookies['userid']) {
|
||||
// if this is the first time the user has visited this app,
|
||||
// set a cookie so that we recognise them when they return
|
||||
response.headers.set(
|
||||
'set-cookie',
|
||||
cookie.serialize('userid', event.locals.userid, {
|
||||
path: '/',
|
||||
httpOnly: true
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return response;
|
||||
};
|
|
@ -0,0 +1,107 @@
|
|||
<script>
|
||||
import { spring } from 'svelte/motion';
|
||||
|
||||
let count = 0;
|
||||
|
||||
const displayed_count = spring();
|
||||
$: displayed_count.set(count);
|
||||
$: offset = modulo($displayed_count, 1);
|
||||
|
||||
/**
|
||||
* @param {number} n
|
||||
* @param {number} m
|
||||
*/
|
||||
function modulo(n, m) {
|
||||
// handle negative numbers
|
||||
return ((n % m) + m) % m;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="counter">
|
||||
<button on:click={() => (count -= 1)} aria-label="Decrease the counter by one">
|
||||
<svg aria-hidden="true" viewBox="0 0 1 1">
|
||||
<path d="M0,0.5 L1,0.5" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<div class="counter-viewport">
|
||||
<div class="counter-digits" style="transform: translate(0, {100 * offset}%)">
|
||||
<strong class="hidden" aria-hidden="true">{Math.floor($displayed_count + 1)}</strong>
|
||||
<strong>{Math.floor($displayed_count)}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button on:click={() => (count += 1)} aria-label="Increase the counter by one">
|
||||
<svg aria-hidden="true" viewBox="0 0 1 1">
|
||||
<path d="M0,0.5 L1,0.5 M0.5,0 L0.5,1" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.counter {
|
||||
display: flex;
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
|
||||
margin: 1rem 0;
|
||||
}
|
||||
|
||||
.counter button {
|
||||
width: 2em;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: 0;
|
||||
background-color: transparent;
|
||||
touch-action: manipulation;
|
||||
color: var(--text-color);
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.counter button:hover {
|
||||
background-color: var(--secondary-color);
|
||||
}
|
||||
|
||||
svg {
|
||||
width: 25%;
|
||||
height: 25%;
|
||||
}
|
||||
|
||||
path {
|
||||
vector-effect: non-scaling-stroke;
|
||||
stroke-width: 2px;
|
||||
stroke: var(--text-color);
|
||||
}
|
||||
|
||||
.counter-viewport {
|
||||
width: 8em;
|
||||
height: 4em;
|
||||
overflow: hidden;
|
||||
text-align: center;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.counter-viewport strong {
|
||||
position: absolute;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-weight: 400;
|
||||
color: var(--accent-color);
|
||||
font-size: 4rem;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.counter-digits {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
top: -100%;
|
||||
user-select: none;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,4 @@
|
|||
export const queryMode = {
|
||||
REAL_TIME: 'realTime',
|
||||
ONE_SHOT: 'oneShot'
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
import { invalidate } from '$app/navigation';
|
||||
|
||||
// this action (https://svelte.dev/tutorial/actions) allows us to
|
||||
// progressively enhance a <form> that already works without JS
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
* @param {{
|
||||
* pending?: ({ data, form }: { data: FormData; form: HTMLFormElement }) => void;
|
||||
* error?: ({
|
||||
* data,
|
||||
* form,
|
||||
* response,
|
||||
* error
|
||||
* }: {
|
||||
* data: FormData;
|
||||
* form: HTMLFormElement;
|
||||
* response: Response | null;
|
||||
* error: Error | null;
|
||||
* }) => void;
|
||||
* result?: ({
|
||||
* data,
|
||||
* form,
|
||||
* response
|
||||
* }: {
|
||||
* data: FormData;
|
||||
* response: Response;
|
||||
* form: HTMLFormElement;
|
||||
* }) => void;
|
||||
* }} [opts]
|
||||
*/
|
||||
export function enhance(form, { pending, error, result } = {}) {
|
||||
let current_token;
|
||||
|
||||
/** @param {SubmitEvent} e */
|
||||
async function handle_submit(e) {
|
||||
const token = (current_token = {});
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
const data = new FormData(form);
|
||||
|
||||
if (pending) pending({ data, form });
|
||||
|
||||
try {
|
||||
const response = await fetch(form.action, {
|
||||
method: form.method,
|
||||
headers: {
|
||||
accept: 'application/json'
|
||||
},
|
||||
body: data
|
||||
});
|
||||
|
||||
if (token !== current_token) return;
|
||||
|
||||
if (response.ok) {
|
||||
if (result) result({ data, form, response });
|
||||
|
||||
const url = new URL(form.action);
|
||||
url.search = url.hash = '';
|
||||
invalidate(url.href);
|
||||
} else if (error) {
|
||||
error({ data, form, error: null, response });
|
||||
} else {
|
||||
console.error(await response.text());
|
||||
}
|
||||
} catch (e) {
|
||||
if (error && e instanceof Error) {
|
||||
error({ data, form, error: e, response: null });
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
form.addEventListener('submit', handle_submit);
|
||||
|
||||
return {
|
||||
destroy() {
|
||||
form.removeEventListener('submit', handle_submit);
|
||||
}
|
||||
};
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
<script>
|
||||
import NavBar from "./NavBar.svelte";
|
||||
import logo from './kd-full-logo.png';
|
||||
</script>
|
||||
|
||||
<header>
|
||||
<div class="corner">
|
||||
<a href="/">
|
||||
<img src={logo} alt="Kafka Dance Logo" />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<NavBar />
|
||||
|
||||
<div class="corner">
|
||||
<!-- TODO put something else here? github link? -->
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<style>
|
||||
header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.corner {
|
||||
font-weight: bold;
|
||||
font-size: 18px;
|
||||
color: black;
|
||||
height: 3em;
|
||||
}
|
||||
|
||||
.corner a {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.corner span {
|
||||
margin-top: 0.45em;
|
||||
margin-left: 0.5em;
|
||||
}
|
||||
|
||||
.corner img {
|
||||
margin-left: 0.5em;
|
||||
height: 2em;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
nav {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
--background: rgba(255, 255, 255, 0.7);
|
||||
}
|
||||
|
||||
svg {
|
||||
width: 2em;
|
||||
height: 3em;
|
||||
display: block;
|
||||
}
|
||||
|
||||
path {
|
||||
fill: var(--background);
|
||||
}
|
||||
|
||||
ul {
|
||||
position: relative;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
height: 3em;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
list-style: none;
|
||||
background: var(--background);
|
||||
background-size: contain;
|
||||
}
|
||||
|
||||
li {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
li.active::before {
|
||||
--size: 6px;
|
||||
content: '';
|
||||
width: 0;
|
||||
height: 0;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: calc(50% - var(--size));
|
||||
border: var(--size) solid transparent;
|
||||
border-top: var(--size) solid var(--accent-color);
|
||||
}
|
||||
|
||||
nav a {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
align-items: center;
|
||||
padding: 0 1em;
|
||||
color: var(--heading-color);
|
||||
font-weight: 700;
|
||||
font-size: 0.8rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.1em;
|
||||
text-decoration: none;
|
||||
transition: color 0.2s linear;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: var(--accent-color);
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,126 @@
|
|||
<script>
|
||||
import { page } from '$app/stores';
|
||||
</script>
|
||||
|
||||
<nav>
|
||||
<svg viewBox="0 0 2 3" aria-hidden="true">
|
||||
<path d="M0,0 L1,2 C1.5,3 1.5,3 2,3 L2,0 Z" />
|
||||
</svg>
|
||||
<ul>
|
||||
<li class:active={$page.url.pathname === '/'}>
|
||||
<a sveltekit:prefetch href="/">Home</a>
|
||||
</li>
|
||||
<li class:active={$page.url.pathname === '/settings'}>
|
||||
<a sveltekit:prefetch href="/settings">Settings</a>
|
||||
</li>
|
||||
<!--
|
||||
<li class:active={$page.url.pathname === '/about'}>
|
||||
<a sveltekit:prefetch href="/about">About</a>
|
||||
</li>
|
||||
<li class:active={$page.url.pathname === '/todos'}>
|
||||
<a sveltekit:prefetch href="/todos">Todos</a>
|
||||
</li>
|
||||
-->
|
||||
</ul>
|
||||
<svg viewBox="0 0 2 3" aria-hidden="true">
|
||||
<path d="M0,0 L0,3 C0.5,3 0.5,3 1,2 L2,0 Z" />
|
||||
</svg>
|
||||
</nav>
|
||||
|
||||
<style>
|
||||
header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.corner {
|
||||
font-weight: bold;
|
||||
font-size: 18px;
|
||||
color: black;
|
||||
height: 3em;
|
||||
}
|
||||
|
||||
.corner a {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.corner span {
|
||||
margin-top: 0.45em;
|
||||
margin-left: 0.5em;
|
||||
}
|
||||
|
||||
.corner img {
|
||||
margin-left: 0.5em;
|
||||
height: 2em;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
nav {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
--background: rgba(255, 255, 255, 0.7);
|
||||
}
|
||||
|
||||
svg {
|
||||
width: 2em;
|
||||
height: 3em;
|
||||
display: block;
|
||||
}
|
||||
|
||||
path {
|
||||
fill: var(--background);
|
||||
}
|
||||
|
||||
ul {
|
||||
position: relative;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
height: 3em;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
list-style: none;
|
||||
background: var(--background);
|
||||
background-size: contain;
|
||||
}
|
||||
|
||||
li {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
li.active::before {
|
||||
--size: 6px;
|
||||
content: '';
|
||||
width: 0;
|
||||
height: 0;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: calc(50% - var(--size));
|
||||
border: var(--size) solid transparent;
|
||||
border-top: var(--size) solid var(--accent-color);
|
||||
}
|
||||
|
||||
nav a {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
align-items: center;
|
||||
padding: 0 1em;
|
||||
color: var(--heading-color);
|
||||
font-weight: 700;
|
||||
font-size: 0.8rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.1em;
|
||||
text-decoration: none;
|
||||
transition: color 0.2s linear;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: var(--accent-color);
|
||||
}
|
||||
|
||||
</style>
|
Binary file not shown.
After Width: | Height: | Size: 57 KiB |
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="107" height="128" viewBox="0 0 107 128"><title>svelte-logo</title><path d="M94.1566,22.8189c-10.4-14.8851-30.94-19.2971-45.7914-9.8348L22.2825,29.6078A29.9234,29.9234,0,0,0,8.7639,49.6506a31.5136,31.5136,0,0,0,3.1076,20.2318A30.0061,30.0061,0,0,0,7.3953,81.0653a31.8886,31.8886,0,0,0,5.4473,24.1157c10.4022,14.8865,30.9423,19.2966,45.7914,9.8348L84.7167,98.3921A29.9177,29.9177,0,0,0,98.2353,78.3493,31.5263,31.5263,0,0,0,95.13,58.117a30,30,0,0,0,4.4743-11.1824,31.88,31.88,0,0,0-5.4473-24.1157" style="fill:#ff3e00"/><path d="M45.8171,106.5815A20.7182,20.7182,0,0,1,23.58,98.3389a19.1739,19.1739,0,0,1-3.2766-14.5025,18.1886,18.1886,0,0,1,.6233-2.4357l.4912-1.4978,1.3363.9815a33.6443,33.6443,0,0,0,10.203,5.0978l.9694.2941-.0893.9675a5.8474,5.8474,0,0,0,1.052,3.8781,6.2389,6.2389,0,0,0,6.6952,2.485,5.7449,5.7449,0,0,0,1.6021-.7041L69.27,76.281a5.4306,5.4306,0,0,0,2.4506-3.631,5.7948,5.7948,0,0,0-.9875-4.3712,6.2436,6.2436,0,0,0-6.6978-2.4864,5.7427,5.7427,0,0,0-1.6.7036l-9.9532,6.3449a19.0329,19.0329,0,0,1-5.2965,2.3259,20.7181,20.7181,0,0,1-22.2368-8.2427,19.1725,19.1725,0,0,1-3.2766-14.5024,17.9885,17.9885,0,0,1,8.13-12.0513L55.8833,23.7472a19.0038,19.0038,0,0,1,5.3-2.3287A20.7182,20.7182,0,0,1,83.42,29.6611a19.1739,19.1739,0,0,1,3.2766,14.5025,18.4,18.4,0,0,1-.6233,2.4357l-.4912,1.4978-1.3356-.98a33.6175,33.6175,0,0,0-10.2037-5.1l-.9694-.2942.0893-.9675a5.8588,5.8588,0,0,0-1.052-3.878,6.2389,6.2389,0,0,0-6.6952-2.485,5.7449,5.7449,0,0,0-1.6021.7041L37.73,51.719a5.4218,5.4218,0,0,0-2.4487,3.63,5.7862,5.7862,0,0,0,.9856,4.3717,6.2437,6.2437,0,0,0,6.6978,2.4864,5.7652,5.7652,0,0,0,1.602-.7041l9.9519-6.3425a18.978,18.978,0,0,1,5.2959-2.3278,20.7181,20.7181,0,0,1,22.2368,8.2427,19.1725,19.1725,0,0,1,3.2766,14.5024,17.9977,17.9977,0,0,1-8.13,12.0532L51.1167,104.2528a19.0038,19.0038,0,0,1-5.3,2.3287" style="fill:#fff"/></svg>
|
After Width: | Height: | Size: 1.8 KiB |
|
@ -0,0 +1,93 @@
|
|||
<script context="module">export {};
|
||||
</script>
|
||||
|
||||
<script>export let language = {
|
||||
name: undefined,
|
||||
register: undefined,
|
||||
};
|
||||
export let code = undefined;
|
||||
export let langtag = false;
|
||||
import hljs from "highlight.js/lib/core";
|
||||
import { createEventDispatcher, afterUpdate } from "svelte";
|
||||
const dispatch = createEventDispatcher();
|
||||
let highlighted = undefined;
|
||||
afterUpdate(() => {
|
||||
if (highlighted) {
|
||||
dispatch("highlight", { highlighted });
|
||||
}
|
||||
});
|
||||
$: if (language.name && language.register) {
|
||||
hljs.registerLanguage(language.name, language.register);
|
||||
highlighted = hljs.highlight(code, { language: language.name }).value;
|
||||
}
|
||||
</script>
|
||||
|
||||
<slot {highlighted}>
|
||||
<!-- prettier-ignore -->
|
||||
<div class="highlight-editor">
|
||||
<pre
|
||||
class:langtag
|
||||
data-language={language.name || "plaintext"}
|
||||
{...$$restProps}><code class="hljs">{#if highlighted !== undefined}{@html highlighted}{:else}{code}{/if}</code></pre>
|
||||
<textarea spellcheck="false" bind:value={code}></textarea>
|
||||
</div>
|
||||
</slot>
|
||||
|
||||
<style>
|
||||
/*textarea {
|
||||
resize: none;
|
||||
overflow: hidden;
|
||||
z-index: 1;
|
||||
position: absolute;
|
||||
float: bottom;
|
||||
margin-top: -246px;
|
||||
margin-left: 0;
|
||||
min-height: 196px;
|
||||
max-height: 196px;
|
||||
|
||||
background: transparent;
|
||||
color: rgba(0,0,0,0);
|
||||
caret-color: #d0dde9;
|
||||
|
||||
background-color: #222222;
|
||||
color: #d0dde9;
|
||||
|
||||
border: none;
|
||||
font-size: 14px;
|
||||
font-family: var(--font-mono);
|
||||
padding: 1em;
|
||||
overflow-x: auto;
|
||||
width: 25vw;
|
||||
}
|
||||
*/
|
||||
pre {
|
||||
z-index: 0;
|
||||
padding: 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
code {
|
||||
z-index: 0;
|
||||
min-height: 200px;
|
||||
max-height: 200px;
|
||||
width: 25vw;
|
||||
}
|
||||
.langtag {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.langtag::after {
|
||||
content: attr(data-language);
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
padding: 1em;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: inherit;
|
||||
color: inherit;
|
||||
background: var(--hljs-background);
|
||||
color: var(--hljs-foreground);
|
||||
border-radius: var(--hljs-radius);
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,129 @@
|
|||
// noinspection JSCheckFunctionSignatures
|
||||
|
||||
import { writable } from 'svelte/store'
|
||||
import {queryMode} from "./constants.js";
|
||||
|
||||
const mockItems = [
|
||||
{
|
||||
"eventType": "Television",
|
||||
"broughtToYouBy": "AMC",
|
||||
"title": "Breaking Bad"
|
||||
},
|
||||
{
|
||||
"eventType": "Television",
|
||||
"broughtToYouBy": "CBS",
|
||||
"title": "Breaking Bad Bang Theory"
|
||||
},
|
||||
{
|
||||
"eventType": "Movie",
|
||||
"broughtToYouBy": "20th Century Fox",
|
||||
"title": "Star Wars 2"
|
||||
},
|
||||
].map(o => ({value: o, timestamp: new Date().getTime()}))
|
||||
|
||||
const testMode = true
|
||||
export const state = writable({
|
||||
items: [],
|
||||
itemCount: undefined,
|
||||
error: null,
|
||||
})
|
||||
const updateClearError = updater => state.update(s => {
|
||||
s.error = null
|
||||
return updater(s)
|
||||
})
|
||||
|
||||
let itemLimit = Infinity
|
||||
let ws;
|
||||
let disconnected = false
|
||||
|
||||
const getRandomFromArray = array => array[Math.floor(Math.random() * array.length)]
|
||||
|
||||
export const query = async ({ cluster, topic, mode, jsFilter, queryCode, maxItems, mutableObjects }) => {
|
||||
updateClearError(s => ({...s, items: [], itemCount: 0}))
|
||||
if (disconnected) {
|
||||
connect()
|
||||
disconnected = false
|
||||
}
|
||||
if (testMode) {
|
||||
try {
|
||||
const f = new Function('message', 'value', queryCode)
|
||||
if (mode === queryMode.REAL_TIME) {
|
||||
const addItem = () => {
|
||||
const item = getRandomFromArray(mockItems)
|
||||
if (!jsFilter || f(item, item.value)) {
|
||||
item.timestamp = new Date().getTime()
|
||||
updateClearError(s => ({...s, items: [item, ...s.items].slice(0, itemLimit), itemCount: 0}))
|
||||
}
|
||||
setTimeout(addItem, 2000)
|
||||
}
|
||||
setTimeout(addItem, 2000)
|
||||
} else {
|
||||
updateClearError(s => ({...s, items: mockItems.filter(item => !jsFilter || f(item, item.value)), itemCount: 0}))
|
||||
}
|
||||
} catch (e) {
|
||||
updateClearError(s => ({ ...s, error: e.toString() }))
|
||||
}
|
||||
} else {
|
||||
updateClearError(s => ({ ...s, items: [], itemCount: 0 }))
|
||||
}
|
||||
itemLimit = maxItems
|
||||
ws.send(JSON.stringify({
|
||||
cluster,
|
||||
mode,
|
||||
topic,
|
||||
maxItems,
|
||||
immutable: !mutableObjects,
|
||||
searchCode: jsFilter && queryCode
|
||||
}))
|
||||
}
|
||||
|
||||
export const connect = () => {
|
||||
ws = new WebSocket(`ws://localhost:3000`)
|
||||
if (!ws) {
|
||||
updateClearError(s => ({...s, error: 'Unable to connect to websocket.'}))
|
||||
return
|
||||
}
|
||||
|
||||
ws.addEventListener('close', () => { disconnected = true })
|
||||
|
||||
ws.addEventListener('open', () => {
|
||||
console.log('WebSocket opened')
|
||||
// ws.send(JSON.stringify({
|
||||
// searchCode: 'return message.value?.UserId === "MINTERCI"'
|
||||
// }))
|
||||
})
|
||||
|
||||
ws.addEventListener('message', message => {
|
||||
//console.log('WebSocket message received', message)
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(message.data)
|
||||
switch (data.type) {
|
||||
case 'complete':
|
||||
updateClearError(s => ({
|
||||
...s,
|
||||
items: data.message
|
||||
}))
|
||||
break;
|
||||
case 'item_count':
|
||||
updateClearError(s => ({
|
||||
...s,
|
||||
itemCount: console.log('state', s) || data.message
|
||||
}))
|
||||
break;
|
||||
case 'message':
|
||||
updateClearError(s => ({
|
||||
...s,
|
||||
items: [data.message, ...s.items].slice(0, itemLimit)
|
||||
}))
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
data = message.data
|
||||
}
|
||||
})
|
||||
|
||||
ws.addEventListener('close', () => {
|
||||
console.log('WebSocket closed')
|
||||
})
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<script>
|
||||
import Header from '$lib/header/Header.svelte';
|
||||
import '../app.css';
|
||||
</script>
|
||||
|
||||
<Header />
|
||||
|
||||
<main>
|
||||
<slot />
|
||||
</main>
|
||||
|
||||
<!--<footer></footer>-->
|
||||
|
||||
<style>
|
||||
main {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 1rem;
|
||||
width: 100%;
|
||||
/*
|
||||
max-width: 1024px;
|
||||
*/
|
||||
margin: 0 auto;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
footer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 40px;
|
||||
}
|
||||
|
||||
footer a {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
@media (min-width: 480px) {
|
||||
footer {
|
||||
padding: 40px 0;
|
||||
}
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1 @@
|
|||
export const prerender = true;
|
|
@ -0,0 +1,242 @@
|
|||
<script>
|
||||
import { onMount } from 'svelte'
|
||||
import { JsonView } from '@zerodevx/svelte-json-view'
|
||||
import { state, connect, query } from '$lib/state';
|
||||
import { queryMode } from "../lib/constants.js";
|
||||
|
||||
let expandAll = false
|
||||
let showMetadata = false
|
||||
|
||||
const querySettings = {
|
||||
topic: null,
|
||||
cluster: null,
|
||||
mode: queryMode.REAL_TIME,
|
||||
jsFilter: true,
|
||||
maxItems: 20,
|
||||
mutableObjects: false,
|
||||
queryCode:
|
||||
`// The message object contains all metadata
|
||||
// \`value\` is shorthand for message.value
|
||||
|
||||
return message.value.eventType === "Television";`
|
||||
}
|
||||
|
||||
const makeRequest = async () => query(querySettings)
|
||||
|
||||
let topics = []
|
||||
let clusters = []
|
||||
const updateTopics = async () => {
|
||||
topics = []
|
||||
const response = await fetch(`http://localhost:3000/topics/${querySettings.cluster}`)
|
||||
topics = await response.json()
|
||||
topics.sort()
|
||||
console.log('topics', topics)
|
||||
querySettings.topic = topics[0]
|
||||
}
|
||||
onMount(async () => {
|
||||
connect();
|
||||
const response = await fetch(`http://localhost:3000/clusters`)
|
||||
clusters = Object.keys(await response.json())
|
||||
querySettings.cluster = clusters[0]
|
||||
await updateTopics()
|
||||
})
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{querySettings.topic} - Kafka Dance</title>
|
||||
<meta name="description" content="Kafka Dance" />
|
||||
</svelte:head>
|
||||
|
||||
<section>
|
||||
<div class="query-settings">
|
||||
<!--
|
||||
<Header />
|
||||
<NavBar />
|
||||
-->
|
||||
<h1>Message Search</h1>
|
||||
{#if $state.error}
|
||||
<div class="state-error">{$state.error}</div>
|
||||
{/if}
|
||||
|
||||
<div class="settings-option">
|
||||
<h3>Cluster</h3>
|
||||
<select disabled={clusters.length === 0} bind:value={querySettings.cluster} name="cluster" id="cluster" on:change={updateTopics}>
|
||||
{#each clusters as cluster}
|
||||
<option value={cluster}>{cluster}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="settings-option">
|
||||
<h3>Topic</h3>
|
||||
<select disabled={topics.length === 0} bind:value={querySettings.topic} name="topic" id="topic">
|
||||
{#each topics as topic}
|
||||
<option value={topic}>{topic}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="settings-option">
|
||||
<label>
|
||||
Maximum Results
|
||||
<input type=number bind:value={querySettings.maxItems} min=0 max=10000>
|
||||
</label>
|
||||
</div>
|
||||
<br/>
|
||||
|
||||
<div class="settings-option">
|
||||
<div class="query-input-header">Use JavaScript to filter messages <input type=checkbox bind:checked={querySettings.jsFilter}></div>
|
||||
{#if querySettings.jsFilter}
|
||||
<div class="query-input-display">
|
||||
<div title="If enabled, mutations made by the below code will be displayed in the result data.">
|
||||
Allow JavaScript to mutate objects <input type=checkbox bind:checked={querySettings.mutableObjects}>
|
||||
</div>
|
||||
<textarea class="query-input" bind:value={querySettings.queryCode}></textarea>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="settings-option query-type">
|
||||
<span>Query Type:</span>
|
||||
<span>
|
||||
<label title="Consume and display new events as they are produced.">
|
||||
<input type=radio bind:group={querySettings.mode} name="mode" value={queryMode.REAL_TIME}>
|
||||
Real Time
|
||||
</label>
|
||||
|
||||
<label title="Query all messages that currently exist, then stop.">
|
||||
<input type=radio bind:group={querySettings.mode} name="mode" value={queryMode.ONE_SHOT}>
|
||||
One Shot
|
||||
</label>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="query-button">
|
||||
<button on:click={makeRequest}>Start Query</button>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<div class="live-settings">
|
||||
<div>Expand All Objects <input type=checkbox bind:checked={expandAll}></div>
|
||||
<div>Show Metadata <input type=checkbox bind:checked={showMetadata}></div>
|
||||
<!--{#if $state.itemCount >= 0}
|
||||
<h2>{$state.itemCount} Matches Found...</h2>
|
||||
{/if}-->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if $state.items?.length > 0}
|
||||
<div class="json-view">
|
||||
<JsonView json={showMetadata ? $state.items : $state.items.map(item => item.value)}
|
||||
depth={expandAll ? Infinity : 1}/>
|
||||
</div>
|
||||
{:else }
|
||||
<div class="json-view no-query-data">
|
||||
<h2>No query data</h2>
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<style>
|
||||
section {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex: 1;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
h1 {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
textarea {
|
||||
overflow: hidden;
|
||||
z-index: 1;
|
||||
margin-left: 0;
|
||||
|
||||
background-color: #222222;
|
||||
color: #d0dde9;
|
||||
|
||||
border: none;
|
||||
font-size: 14px;
|
||||
font-family: var(--font-mono);
|
||||
padding: 1em;
|
||||
overflow-x: auto;
|
||||
min-width: 20vw;
|
||||
}
|
||||
|
||||
.query-settings {
|
||||
margin-right: 1rem;
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.query-input-display {
|
||||
margin-top: 1em;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.query-input {
|
||||
min-height: 4vw;
|
||||
}
|
||||
|
||||
.query-type {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.query-type label {
|
||||
padding-left: 0.5em;
|
||||
}
|
||||
|
||||
.query-button {
|
||||
text-align: right;
|
||||
border-radius: 0;
|
||||
border-style: none;
|
||||
}
|
||||
|
||||
.state-error {
|
||||
color: #ff2222;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* JsonView config
|
||||
:root {
|
||||
--nodePaddingLeft: 1rem;
|
||||
--nodeBorderLeft: 1px dotted #9ca3af;
|
||||
--nodeColor: #6d81a4;
|
||||
--bracketHoverBackground: #d1d5db;
|
||||
--leafDefaultColor: #9ca3af;
|
||||
--leafStringColor: #14cb8f;
|
||||
--leafNumberColor: #d97706;
|
||||
--leafBooleanColor: #2563eb;
|
||||
}
|
||||
|
||||
.bracket {
|
||||
color: #d0dde9;
|
||||
}
|
||||
*/
|
||||
|
||||
.json-view {
|
||||
border-radius: 4px;
|
||||
flex-grow: 6;
|
||||
padding: 1em;
|
||||
background-color: #e2eaff;
|
||||
height: 86vh;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
.no-query-data {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.no-query-data h2 {
|
||||
font-size: 32px;
|
||||
color: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,13 @@
|
|||
import { browser, dev } from '$app/env';
|
||||
|
||||
// we don't need any JS on this page, though we'll load
|
||||
// it in dev so that we get hot module replacement...
|
||||
export const hydrate = dev;
|
||||
|
||||
// ...but if the client-side router is already loaded
|
||||
// (i.e. we came here from elsewhere in the app), use it
|
||||
export const router = browser;
|
||||
|
||||
// since there's no dynamic data here, we can prerender
|
||||
// it so that it gets served as a static asset in prod
|
||||
export const prerender = true;
|
|
@ -0,0 +1,52 @@
|
|||
<script context="module">
|
||||
throw new Error("@migration task: Check code was safely removed (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292722)");
|
||||
|
||||
// import { browser, dev } from '$app/env';
|
||||
|
||||
// // we don't need any JS on this page, though we'll load
|
||||
// // it in dev so that we get hot module replacement...
|
||||
// export const hydrate = dev;
|
||||
|
||||
// // ...but if the client-side router is already loaded
|
||||
// // (i.e. we came here from elsewhere in the app), use it
|
||||
// export const router = browser;
|
||||
|
||||
// // since there's no dynamic data here, we can prerender
|
||||
// // it so that it gets served as a static asset in prod
|
||||
// export const prerender = true;
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>About</title>
|
||||
<meta name="description" content="About this app" />
|
||||
</svelte:head>
|
||||
|
||||
<div class="content">
|
||||
<h1>About this app</h1>
|
||||
|
||||
<p>
|
||||
This is a <a href="https://kit.svelte.dev">SvelteKit</a> app. You can make your own by typing the
|
||||
following into your command line and following the prompts:
|
||||
</p>
|
||||
|
||||
<pre>npm create svelte@latest</pre>
|
||||
|
||||
<p>
|
||||
The page you're looking at is purely static HTML, with no client-side interactivity needed.
|
||||
Because of that, we don't need to load any JavaScript. Try viewing the page's source, or opening
|
||||
the devtools network panel and reloading.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The <a href="/todos">TODOs</a> page illustrates SvelteKit's data loading and form handling. Try using
|
||||
it with JavaScript disabled!
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.content {
|
||||
width: 100%;
|
||||
max-width: var(--column-width);
|
||||
margin: var(--column-margin-top) auto 0 auto;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,123 @@
|
|||
<script>
|
||||
import {onMount} from "svelte";
|
||||
|
||||
const jsonRequest = type => async (path, object) => fetch('http://localhost:3000' + path, {
|
||||
method: type,
|
||||
body: JSON.stringify(object),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
const post = jsonRequest('POST')
|
||||
const put = jsonRequest('PUT')
|
||||
|
||||
const addCluster = async cluster => post('/clusters', cluster)
|
||||
const updateCluster = async cluster => put('/clusters', cluster)
|
||||
|
||||
let clusters = []
|
||||
onMount(async () => {
|
||||
const response = await fetch(`http://localhost:3000/clusters`)
|
||||
clusters = await response.json()
|
||||
if (Object.keys(clusters).length > 0) {
|
||||
config = Object.entries(clusters).map(([key, value]) => ({...value, clusterName: key}))[0]
|
||||
}
|
||||
})
|
||||
|
||||
let config = {
|
||||
clusterName: '',
|
||||
clientId: '',
|
||||
brokers: [''],
|
||||
ssl: true,
|
||||
sasl: {
|
||||
mechanism: '',
|
||||
username: '',
|
||||
password: ''
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<meta name="description" content="Kafka Dance Settings" />
|
||||
</svelte:head>
|
||||
|
||||
<section>
|
||||
<div class="query-settings">
|
||||
<h1>Cluster Configuration</h1>
|
||||
|
||||
<div class="settings-option">
|
||||
Cluster Name: <input bind:value={config.clusterName}>
|
||||
</div>
|
||||
|
||||
<div class="settings-option">
|
||||
Client Id: <input bind:value={config.clientId}>
|
||||
</div>
|
||||
|
||||
<div class="settings-option">
|
||||
Brokers:
|
||||
{#each config.brokers as broker}
|
||||
<input bind:value={broker}>
|
||||
{/each}
|
||||
<button on:click={() => {config.brokers = [...config.brokers, '']}}>+</button>
|
||||
</div>
|
||||
|
||||
<div class="settings-option">
|
||||
<div>
|
||||
Use SSL: <input type=checkbox bind:checked={config.ssl}>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="settings-option">
|
||||
<div>SASL:</div>
|
||||
<div>
|
||||
Mechanism: <input bind:value={config.sasl.mechanism}>
|
||||
</div>
|
||||
<div>
|
||||
Username: <input bind:value={config.sasl.username}>
|
||||
</div>
|
||||
<div>
|
||||
Password: <input type="password" bind:value={config.sasl.password}>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button style="float: right;" on:click={() => updateCluster(config)}>Save</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<style>
|
||||
section {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex: 1;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
h1 {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
textarea {
|
||||
overflow: hidden;
|
||||
z-index: 1;
|
||||
margin-left: 0;
|
||||
|
||||
background-color: #222222;
|
||||
color: #d0dde9;
|
||||
|
||||
border: none;
|
||||
font-size: 14px;
|
||||
font-family: var(--font-mono);
|
||||
padding: 1em;
|
||||
overflow-x: auto;
|
||||
min-width: 20vw;
|
||||
}
|
||||
|
||||
.query-settings {
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
||||
.no-query-data h2 {
|
||||
font-size: 32px;
|
||||
color: rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,70 @@
|
|||
import { api } from './_api';
|
||||
|
||||
/** @type {import('./$types').PageServerLoad} */
|
||||
export const load = async ({ locals }) => {
|
||||
// locals.userid comes from src/hooks.js
|
||||
const response = await api('GET', `todos/${locals.userid}`);
|
||||
|
||||
if (response.status === 404) {
|
||||
// user hasn't created a todo list.
|
||||
// start with an empty array
|
||||
return {
|
||||
todos: []
|
||||
};
|
||||
}
|
||||
|
||||
if (response.status === 200) {
|
||||
return {
|
||||
todos: await response.json()
|
||||
};
|
||||
}
|
||||
|
||||
throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292699)");
|
||||
return {
|
||||
status: response.status
|
||||
};
|
||||
};
|
||||
|
||||
/** @type {import('./$types').Action} */
|
||||
export const POST = async ({ request, locals }) => {
|
||||
const form = await request.formData();
|
||||
|
||||
await api('POST', `todos/${locals.userid}`, {
|
||||
text: form.get('text')
|
||||
});
|
||||
|
||||
throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292699)");
|
||||
return {};
|
||||
};
|
||||
|
||||
// If the user has JavaScript disabled, the URL will change to
|
||||
// include the method override unless we redirect back to /todos
|
||||
const redirect = {
|
||||
status: 303,
|
||||
headers: {
|
||||
location: '/todos'
|
||||
}
|
||||
};
|
||||
|
||||
/** @type {import('./$types').Action} */
|
||||
export const PATCH = async ({ request, locals }) => {
|
||||
const form = await request.formData();
|
||||
|
||||
await api('PATCH', `todos/${locals.userid}/${form.get('uid')}`, {
|
||||
text: form.has('text') ? form.get('text') : undefined,
|
||||
done: form.has('done') ? !!form.get('done') : undefined
|
||||
});
|
||||
|
||||
throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292699)");
|
||||
return redirect;
|
||||
};
|
||||
|
||||
/** @type {import('./$types').Action} */
|
||||
export const DELETE = async ({ request, locals }) => {
|
||||
const form = await request.formData();
|
||||
|
||||
await api('DELETE', `todos/${locals.userid}/${form.get('uid')}`);
|
||||
|
||||
throw new Error("@migration task: Migrate this return statement (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292699)");
|
||||
return redirect;
|
||||
};
|
|
@ -0,0 +1,192 @@
|
|||
<script>
|
||||
throw new Error("@migration task: Add data prop (https://github.com/sveltejs/kit/discussions/5774#discussioncomment-3292707)");
|
||||
|
||||
import { enhance } from '$lib/form';
|
||||
import { scale } from 'svelte/transition';
|
||||
import { flip } from 'svelte/animate';
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* uid: string;
|
||||
* created_at: Date;
|
||||
* text: string;
|
||||
* done: boolean;
|
||||
* pending_delete: boolean;
|
||||
* }} Todo
|
||||
*/
|
||||
|
||||
/** @type {Todo[]} */
|
||||
export let todos;
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Todos</title>
|
||||
<meta name="description" content="A todo list app" />
|
||||
</svelte:head>
|
||||
|
||||
<div class="todos">
|
||||
<h1>Todos</h1>
|
||||
|
||||
<form
|
||||
class="new"
|
||||
action="/todos"
|
||||
method="post"
|
||||
use:enhance={{
|
||||
result: async ({ form }) => {
|
||||
form.reset();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<input name="text" aria-label="Add todo" placeholder="+ tap to add a todo" />
|
||||
</form>
|
||||
|
||||
{#each todos as todo (todo.uid)}
|
||||
<div
|
||||
class="todo"
|
||||
class:done={todo.done}
|
||||
transition:scale|local={{ start: 0.7 }}
|
||||
animate:flip={{ duration: 200 }}
|
||||
>
|
||||
<form
|
||||
action="/todos?_method=PATCH"
|
||||
method="post"
|
||||
use:enhance={{
|
||||
pending: ({ data }) => {
|
||||
todo.done = !!data.get('done');
|
||||
}
|
||||
}}
|
||||
>
|
||||
<input type="hidden" name="uid" value={todo.uid} />
|
||||
<input type="hidden" name="done" value={todo.done ? '' : 'true'} />
|
||||
<button class="toggle" aria-label="Mark todo as {todo.done ? 'not done' : 'done'}" />
|
||||
</form>
|
||||
|
||||
<form class="text" action="/todos?_method=PATCH" method="post" use:enhance>
|
||||
<input type="hidden" name="uid" value={todo.uid} />
|
||||
<input aria-label="Edit todo" type="text" name="text" value={todo.text} />
|
||||
<button class="save" aria-label="Save todo" />
|
||||
</form>
|
||||
|
||||
<form
|
||||
action="/todos?_method=DELETE"
|
||||
method="post"
|
||||
use:enhance={{
|
||||
pending: () => (todo.pending_delete = true)
|
||||
}}
|
||||
>
|
||||
<input type="hidden" name="uid" value={todo.uid} />
|
||||
<button class="delete" aria-label="Delete todo" disabled={todo.pending_delete} />
|
||||
</form>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.todos {
|
||||
width: 100%;
|
||||
max-width: var(--column-width);
|
||||
margin: var(--column-margin-top) auto 0 auto;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.new {
|
||||
margin: 0 0 0.5rem 0;
|
||||
}
|
||||
|
||||
input {
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
|
||||
input:focus-visible {
|
||||
box-shadow: inset 1px 1px 6px rgba(0, 0, 0, 0.1);
|
||||
border: 1px solid #ff3e00 !important;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.new input {
|
||||
font-size: 28px;
|
||||
width: 100%;
|
||||
padding: 0.5em 1em 0.3em 1em;
|
||||
box-sizing: border-box;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.todo {
|
||||
display: grid;
|
||||
grid-template-columns: 2rem 1fr 2rem;
|
||||
grid-gap: 0.5rem;
|
||||
align-items: center;
|
||||
margin: 0 0 0.5rem 0;
|
||||
padding: 0.5rem;
|
||||
background-color: white;
|
||||
border-radius: 8px;
|
||||
filter: drop-shadow(2px 4px 6px rgba(0, 0, 0, 0.1));
|
||||
transform: translate(-1px, -1px);
|
||||
transition: filter 0.2s, transform 0.2s;
|
||||
}
|
||||
|
||||
.done {
|
||||
transform: none;
|
||||
opacity: 0.4;
|
||||
filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.1));
|
||||
}
|
||||
|
||||
form.text {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.todo input {
|
||||
flex: 1;
|
||||
padding: 0.5em 2em 0.5em 0.8em;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.todo button {
|
||||
width: 2em;
|
||||
height: 2em;
|
||||
border: none;
|
||||
background-color: transparent;
|
||||
background-position: 50% 50%;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
button.toggle {
|
||||
border: 1px solid rgba(0, 0, 0, 0.2);
|
||||
border-radius: 50%;
|
||||
box-sizing: border-box;
|
||||
background-size: 1em auto;
|
||||
}
|
||||
|
||||
.done .toggle {
|
||||
background-image: url("data:image/svg+xml,%3Csvg width='22' height='16' viewBox='0 0 22 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20.5 1.5L7.4375 14.5L1.5 8.5909' stroke='%23676778' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
|
||||
}
|
||||
|
||||
.delete {
|
||||
background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4.5 5V22H19.5V5H4.5Z' fill='%23676778' stroke='%23676778' stroke-width='1.5' stroke-linejoin='round'/%3E%3Cpath d='M10 10V16.5' stroke='white' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M14 10V16.5' stroke='white' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M2 5H22' stroke='%23676778' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M8 5L9.6445 2H14.3885L16 5H8Z' fill='%23676778' stroke='%23676778' stroke-width='1.5' stroke-linejoin='round'/%3E%3C/svg%3E%0A");
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
.delete:hover,
|
||||
.delete:focus {
|
||||
transition: opacity 0.2s;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.save {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
opacity: 0;
|
||||
background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20.5 2H3.5C2.67158 2 2 2.67157 2 3.5V20.5C2 21.3284 2.67158 22 3.5 22H20.5C21.3284 22 22 21.3284 22 20.5V3.5C22 2.67157 21.3284 2 20.5 2Z' fill='%23676778' stroke='%23676778' stroke-width='1.5' stroke-linejoin='round'/%3E%3Cpath d='M17 2V11H7.5V2H17Z' fill='white' stroke='white' stroke-width='1.5' stroke-linejoin='round'/%3E%3Cpath d='M13.5 5.5V7.5' stroke='%23676778' stroke-width='1.5' stroke-linecap='round'/%3E%3Cpath d='M5.99844 2H18.4992' stroke='%23676778' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E%0A");
|
||||
}
|
||||
|
||||
.todo input:focus + .save,
|
||||
.save:focus {
|
||||
transition: opacity 0.2s;
|
||||
opacity: 1;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
This module is used by the /todos endpoint to
|
||||
make calls to api.svelte.dev, which stores todos
|
||||
for each user. The leading underscore indicates that this is
|
||||
a private module, _not_ an endpoint — visiting /todos/_api
|
||||
will net you a 404 response.
|
||||
|
||||
(The data on the todo app will expire periodically; no
|
||||
guarantees are made. Don't use it to organise your life.)
|
||||
*/
|
||||
|
||||
const base = 'https://api.svelte.dev';
|
||||
|
||||
/**
|
||||
* @param {string} method
|
||||
* @param {string} resource
|
||||
* @param {Record<string, unknown>} [data]
|
||||
*/
|
||||
export function api(method, resource, data) {
|
||||
return fetch(`${base}/${resource}`, {
|
||||
method,
|
||||
headers: {
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
body: data && JSON.stringify(data)
|
||||
});
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1,3 @@
|
|||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
Binary file not shown.
After Width: | Height: | Size: 352 KiB |
Binary file not shown.
After Width: | Height: | Size: 113 KiB |
|
@ -0,0 +1,15 @@
|
|||
// import adapter from '@sveltejs/adapter-auto';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
kit: {
|
||||
//adapter: adapter(),
|
||||
|
||||
// Override http methods in the Todo forms
|
||||
methodOverride: {
|
||||
allowed: ['PATCH', 'DELETE']
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
|
@ -0,0 +1,8 @@
|
|||
import { sveltekit } from '@sveltejs/kit/vite';
|
||||
|
||||
/** @type {import('vite').UserConfig} */
|
||||
const config = {
|
||||
plugins: [sveltekit()]
|
||||
};
|
||||
|
||||
export default config;
|
Loading…
Reference in New Issue