feat: added full indexeddb support

This commit is contained in:
Luke Hagar
2024-07-04 17:05:59 +00:00
parent 7f96b00b67
commit e23eae5f80
30 changed files with 979 additions and 796 deletions

View File

@@ -1,5 +1,4 @@
<script lang="ts">
import { openApiStore } from '$lib';
import {
apiKeyAuthTemplate,
basicAuthTemplate,
@@ -7,11 +6,12 @@
oauth2AuthTemplate,
openIdAuthTemplate
} from '$lib/authTemplates';
import { selectedSpec } from '$lib/db';
import AuthenticationItem from '../atoms/AuthenticationItem.svelte';
let selectedSchema: string;
const addSecuritySchema = () => {
let tempSchemaList = $openApiStore.security;
let tempSchemaList = $selectedSpec.spec.security || [];
let newSchema;
switch (selectedSchema) {
case 'basicAuth':
@@ -36,47 +36,61 @@
if (newSchema) {
tempSchemaList = [...tempSchemaList, newSchema];
$openApiStore.security = tempSchemaList;
$selectedSpec.spec.security = tempSchemaList;
}
};
const removeSecuritySchema = (index: number) => {
let tempSchemaList = $openApiStore.security;
let tempSchemaList = $selectedSpec.spec.security;
tempSchemaList.splice(index, 1);
$openApiStore.security = tempSchemaList;
$selectedSpec.spec.security = tempSchemaList;
};
</script>
<form
class="border-token rounded-container-token bg-surface-backdrop-token px-6 py-4 min-h-20 space-y-4"
>
{#each $openApiStore.security as schema, index}
<div class="card w-full p-4">
<div class="flex flex-row-reverse w-full">
<button
type="button"
class="btn btn-sm variant-ringed-error hover:variant-filled-error"
on:click={() => {
removeSecuritySchema(index);
}}
>
Remove schema
</button>
{#if $selectedSpec.spec.security}
<form
class="border-token rounded-container-token bg-surface-backdrop-token px-6 py-4 min-h-20 space-y-4"
>
{#each $selectedSpec.spec.security as schema, index}
<div class="card w-full p-4">
<div class="flex flex-row-reverse w-full">
<button
type="button"
class="btn btn-sm variant-ringed-error hover:variant-filled-error"
on:click={() => {
removeSecuritySchema(index);
}}
>
Remove schema
</button>
</div>
<AuthenticationItem bind:schema />
</div>
<AuthenticationItem bind:schema />
</div>
<hr />
{/each}
<hr />
{/each}
<span class="flex justify-center items-center gap-2 max-w-sm mx-auto">
<select name="security-schema" bind:value={selectedSchema} class="input w-fit text-sm">
<option value="basicAuth" selected>Basic Auth</option>
<option value="bearerAuth">Bearer Auth</option>
<option value="ApiKeyAuth">API Key Auth</option>
<option value="openId">OpenID</option>
<option value="oAuthSample">OAuth2</option>
</select>
<button type="button" class="btn text-sm variant-filled-primary" on:click={addSecuritySchema}>
Add Security Schema
<span class="flex justify-center items-center gap-2 max-w-sm mx-auto">
<select name="security-schema" bind:value={selectedSchema} class="input w-fit text-sm">
<option value="basicAuth" selected>Basic Auth</option>
<option value="bearerAuth">Bearer Auth</option>
<option value="ApiKeyAuth">API Key Auth</option>
<option value="openId">OpenID</option>
<option value="oAuthSample">OAuth2</option>
</select>
<button type="button" class="btn text-sm variant-filled-primary" on:click={addSecuritySchema}>
Add Security Schema
</button>
</span>
</form>
{:else}
<div class="grid place-content-center h-full">
<p class="p-4">No security schema defined</p>
<button
class="btn variant-ghost-success"
on:click={() => {
addSecuritySchema();
}}
>
Add security schema
</button>
</span>
</form>
</div>
{/if}