Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update default ui #39

Merged
merged 23 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9347459
feat: update default ui
TamaraBogantseva Aug 22, 2024
d3e9ed2
fix: move styles.css file
TamaraBogantseva Aug 23, 2024
290a097
feat: pass inputField from flottform, use anchor element
TamaraBogantseva Aug 23, 2024
e7bcbc1
chore: use div instead of link and add copyToClipboard button
TamaraBogantseva Aug 26, 2024
3acf53f
fix: add some css variables
TamaraBogantseva Sep 5, 2024
c140308
chore: change event listeners
TamaraBogantseva Sep 12, 2024
137b692
feat: update default theme and rename it to default component
TamaraBogantseva Sep 12, 2024
4caf803
chore: update forms to use new default component
TamaraBogantseva Sep 12, 2024
c574b2e
fix: changes after pr review
TamaraBogantseva Sep 12, 2024
d2470c1
chore: delete unused imports and add types
TamaraBogantseva Sep 12, 2024
b038de9
Merge branch 'main' into feat/make-default-ui-customizable
TamaraBogantseva Sep 12, 2024
8c77e59
fix: remove options
TamaraBogantseva Sep 12, 2024
83e2be2
chore: Clean up unnecessary test files
Narigo Sep 12, 2024
bebe72e
fix: Emit a done message when file sending is completed
Narigo Sep 12, 2024
370cdf1
fix: Use logger instead of console for debug messages
Narigo Sep 12, 2024
1ad86a7
chore: Remove roadmap as we moved it to gh project
Narigo Sep 12, 2024
efd60d7
feat: Allow themes to be created inside of flottform/forms and only i…
Narigo Sep 12, 2024
5e20e7a
chore: Remove server-standalone-old workspace
Narigo Sep 12, 2024
f74fddd
chore: Move files and structure a bit
Narigo Sep 12, 2024
8e5abdc
fix: Allow onErrorText to be overridden and as a function
Narigo Sep 12, 2024
9bbe8bf
Update flottform/forms/src/flottform-file-input-host.ts
nidhal-labidi Sep 24, 2024
376172e
Update flottform/forms/src/internal.ts
nidhal-labidi Sep 24, 2024
6b053b3
Update flottform/forms/src/flottform-text-input-host.ts
nidhal-labidi Sep 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flottform/demo/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { base } from '$app/paths';
import '../app.postcss';
import '@flottform/forms/style.css';
</script>

<slot />
Expand Down
33 changes: 30 additions & 3 deletions flottform/demo/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<script lang="ts">
import { base } from '$app/paths';
import { onMount } from 'svelte';
import { defaultThemeForFileInput, FlottformFileInputHost } from '@flottform/forms';
import { createDefaultFlottformComponent, FlottformFileInputHost } from '@flottform/forms';
import { writable } from 'svelte/store';
import FileInput from '$lib/components/FileInput.svelte';
import { createClientUrl, sdpExchangeServerBase } from '../api';
import { browser } from '$app/environment';

const createTextClientUrl = async ({ endpointId }: { endpointId: string }) => {
if (browser) {
return `${window.location.origin}${base}/flottform-text-client/${endpointId}`;
}
return `https://192.168.178.23:5175/flottform-text-client/${endpointId}`;
};
TamaraBogantseva marked this conversation as resolved.
Show resolved Hide resolved

let highlighted = false;

Expand Down Expand Up @@ -101,18 +109,32 @@
isFillingOut = false;
};

let flottformAnchor: HTMLElement;

//container should have saved all elements
TamaraBogantseva marked this conversation as resolved.
Show resolved Hide resolved

onMount(async () => {
const fileInputs = document.querySelectorAll(
'input[type=file]'
) as NodeListOf<HTMLInputElement>;
const flottformComponent = createDefaultFlottformComponent({
flottformAnchorElement: flottformAnchor
});
for (const file of fileInputs) {
const flottformFileInputHost = new FlottformFileInputHost({
flottformComponent.createFileItem({
flottformApi: sdpExchangeServerBase,
createClientUrl,
inputField: file,
theme: defaultThemeForFileInput()
options: { label: file.id }
});
}
flottformComponent.createTextItem({
flottformApi: sdpExchangeServerBase,
createClientUrl: createTextClientUrl,
options: { label: 'Text' }
});
TamaraBogantseva marked this conversation as resolved.
Show resolved Hide resolved

console.log(flottformComponent.getAllFlottformItems());
});
</script>

Expand Down Expand Up @@ -144,6 +166,7 @@
up every few hours.
</p>
<form action="{base}/upload" method="POST" enctype="multipart/form-data" class="grid gap-8">
<div id="flottform-anchor" bind:this={flottformAnchor} class="flottform-anchor"></div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-6">
<div class="flex flex-col">
<label for="name">Name</label>
Expand Down Expand Up @@ -292,6 +315,10 @@
</div>

<style lang="postcss">
.flottform-anchor {
--flottform-border-width: 2px;
--flottform-border-color: #343af0;
}
.drag {
@apply border-2 border-dotted border-primary-blue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<script lang="ts">
import { FlottformTextInputClient } from '@flottform/forms';
import { page } from '$app/stores';
import { onMount } from 'svelte';
import { sdpExchangeServerBase } from '../../../api';

let currentState = $state<
'init' | 'connected' | 'sending' | 'done' | 'error-user-denied' | 'error'
>('init');
let textInput: HTMLInputElement;
let sendTextToForm = $state<() => void>();
let textToSend = $state('');

onMount(async () => {
const flottformTextInputClient = new FlottformTextInputClient({
endpointId: $page.params.endpointId,
flottformApi: sdpExchangeServerBase
});
// Start the WebRTC connection process as soon as the page loads.
flottformTextInputClient.start();

// Listen to the events to update the UI appropriately
flottformTextInputClient.on('connected', () => {
currentState = 'connected';
});
flottformTextInputClient.on('sending', () => {
currentState = 'sending';
});
flottformTextInputClient.on('done', () => {
currentState = 'done';
});
flottformTextInputClient.on('error', () => {
currentState = 'error';
});

sendTextToForm = () => {
currentState = 'sending';
try {
flottformTextInputClient.sendText(textToSend);
console.log(textToSend);
} catch (err) {
currentState = 'error';
console.error('Error getting navigators current position', err);
}
};
});
</script>

<div class="max-w-screen-xl mx-auto p-8 box-border grid grid-cols-1 gap-8">
<h1>Flottform "Return and complaints" client</h1>
<p>Use this form to send a text from this device to the open form on the main device.</p>

<form action="" on:submit={sendTextToForm}>
<div class="flex flex-col gap-4">
<label for="flottform">Send your text</label>
<input
type="text"
name="flottform"
id="flottform"
bind:this={textInput}
bind:value={textToSend}
class=" rounded p-2 border-primary-blue border-2"
/>
{#if currentState === 'sending'}
<div class="h-24 items-center">
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" class="w-12 spinner-svg">
<circle cx="50" cy="50" r="45" class="spinner" />
</svg>
</div>
{:else if currentState === 'done'}
<div class="flex gap-6">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" version="1.1" class="w-12">
<path
d="M 28.28125 6.28125 L 11 23.5625 L 3.71875 16.28125 L 2.28125 17.71875 L 10.28125 25.71875 L 11 26.40625 L 11.71875 25.71875 L 29.71875 7.71875 Z "
class="checkmark"
stroke-linecap="round"
pathLength="1"
stroke-width="2"
stroke="#3ab53a"
fill="none"
/>
</svg>
<p>Your text is successfully sent</p>
</div>
{:else if currentState === 'connected'}
<button
type="submit"
class="group relative w-fit cursor-pointer overflow-hidden rounded-md border-2 bg-primary-blue text-white border-primary-blue px-12 py-3 font-semibold disabled:border-gray-300 disabled:bg-gray-200 disabled:text-gray-500 disabled:pointer-events-none"
>
<span
class="ease absolute top-1/2 h-0 w-64 origin-center -translate-x-20 rotate-45 bg-white transition-all duration-300 group-hover:h-64 group-hover:-translate-y-32"
/>
<span class="ease relative transition duration-300 group-hover:text-primary-blue"
>Send</span
>
</button>
{:else if currentState === 'error'}
<h2 class="animate-bounce">Ouch!</h2>
<p>There was an error connecting to flottform! 😬</p>
<p>Please try again with a new QR code by clicking the button again on the main form.</p>
{/if}
</div>
</form>

<div>Connection state: {currentState}</div>
</div>

<style lang="postcss">
.spinner-svg {
animation: 2s linear infinite svg-animation;
}

.spinner {
@apply block fill-transparent stroke-primary-blue;
stroke-linecap: round;
stroke-dasharray: 283;
stroke-dashoffset: 280;
stroke-width: 8px;
transform-origin: 50% 50%;
animation: spinner 1.4s ease-in-out infinite both;
}

.checkmark {
stroke-dasharray: 1;
stroke-dashoffset: 1;
animation: dash 1s linear 1 forwards;
}

@keyframes spinner {
0%,
25% {
stroke-dashoffset: 280;
transform: rotate(0);
}

50%,
75% {
stroke-dashoffset: 65;
transform: rotate(45deg);
}

100% {
stroke-dashoffset: 280;
transform: rotate(360deg);
}
}

@keyframes rotate {
0% {
transform: rotateZ(0deg);
}
100% {
transform: rotateZ(360deg);
}
}

@keyframes dash {
from {
stroke-dashoffset: 1;
}
to {
stroke-dashoffset: 0;
}
}
</style>
22 changes: 18 additions & 4 deletions flottform/demo/src/routes/multiple-input-form/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
<script lang="ts">
import { FlottformFileInputHost, defaultThemeForFileInput } from '@flottform/forms';
import { FlottformFileInputHost, createDefaultFlottformComponent } from '@flottform/forms';
import { onMount } from 'svelte';
import { createClientUrl, sdpExchangeServerBase } from '../../api';

let flottformAnchor: HTMLElement;

onMount(async () => {
const fileInputs = document.querySelectorAll(
'input[type=file]'
) as NodeListOf<HTMLInputElement>;
const flottformComponent = createDefaultFlottformComponent({
flottformAnchorElement: flottformAnchor
});
for (const file of fileInputs) {
const flottformFileInputHost = new FlottformFileInputHost({
flottformComponent.createFileItem({
flottformApi: sdpExchangeServerBase,
createClientUrl,
inputField: file,
theme: defaultThemeForFileInput()
options: { label: file.id || file.name || 'File' }
});
}

// flottformFileInputHost.on('new', () => {
TamaraBogantseva marked this conversation as resolved.
Show resolved Hide resolved
// // Optional: Custom UI
// });
Expand Down Expand Up @@ -58,12 +64,17 @@
<title>Flottform DEMO</title>
</svelte:head>

<div
id="flottform-anchor"
bind:this={flottformAnchor}
class="absolute top-0 right-0 w-64 flottform-anchor"
></div>
<div class="max-w-screen-xl mx-auto p-8 box-border grid grid-cols-1 gap-8">
<h1>Multiple Input Form</h1>
<form class="grid grid-cols-1 gap-8">
<label class="grid">
<span>Please upload the first file:</span>
<input type="file" name="fileA" multiple />
<input type="file" name="fileA" id="document-A" multiple />
</label>
<label class="grid">
<span>Please upload the second file:</span>
Expand All @@ -90,6 +101,9 @@
</div>

<style lang="postcss">
.flottform-anchor {
--flottform-root-border-radius: 0px 0px 10px 10px;
}
.flottform {
@apply absolute top-0 right-0;
}
Expand Down
4 changes: 4 additions & 0 deletions flottform/forms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
".": {
"import": "./dist/index.js",
"require": "./dist/index.umd.cjs"
},
"./style.css": {
"import": "./dist/style.css",
"require": "./dist/style.css"
}
},
"types": "./dist/src/index.d.ts",
Expand Down
26 changes: 10 additions & 16 deletions flottform/forms/src/flottform-file-input-host.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { FlottformChannelHost } from './flottform-channel-host';
import { Styles } from './flottform-styles';
import { DEFAULT_WEBRTC_CONFIG, EventEmitter, Logger, POLL_TIME_IN_MS } from './internal';

type Listeners = {
new: [];
disconnected: [];
error: [error: any];
connected: [];
import {
BaseInputHost,
BaseListeners,
DEFAULT_WEBRTC_CONFIG,
Logger,
POLL_TIME_IN_MS
} from './internal';

type Listeners = BaseListeners & {
receive: []; // Emitted to signal the start of receiving the file(s)
progress: {
fileIndex: number;
Expand All @@ -16,17 +17,11 @@ type Listeners = {
overallProgress: number;
}[]; // Emitted to signal the progress of receiving the file(s)
done: [];
nidhal-labidi marked this conversation as resolved.
Show resolved Hide resolved
'endpoint-created': [{ link: string; qrCode: string }];
'webrtc:waiting-for-client': [
event: { link: string; qrCode: string; channel: FlottformChannelHost }
];
'webrtc:waiting-for-ice': [];
'webrtc:waiting-for-file': [];
};

const noop = () => {};

export class FlottformFileInputHost extends EventEmitter<Listeners> {
export class FlottformFileInputHost extends BaseInputHost<Listeners> {
private channel: FlottformChannelHost | null = null;
private inputField: HTMLInputElement;
private logger: Logger;
Expand Down Expand Up @@ -57,7 +52,6 @@ export class FlottformFileInputHost extends EventEmitter<Listeners> {
pollTimeForIceInMs?: number;
theme?: (myself: FlottformFileInputHost) => void;
logger?: Logger;
styles?: Styles;
}) {
super();
this.channel = new FlottformChannelHost({
Expand Down
Loading