Skip to content

Commit efad5b5

Browse files
committed
Create 'hello world' svelte app
1 parent 011794c commit efad5b5

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

widget/src/App.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script lang="ts">
2+
export let name: string = "friend";
3+
console.log(arguments);
4+
</script>
5+
6+
<h1>Hello {name}!</h1>

widget/src/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
8+
<title>Svelte Example</title>
9+
</head>
10+
11+
<body>
12+
<input type="file" name="s3ff_mandatory_blob" data-s3fileinput="/api/s3ff" required="" id="id_s3ff_mandatory_blob">
13+
<!-- This script tag points to the source of the JS file we want to load and bundle -->
14+
<script type="module" defer src="main.ts"></script>
15+
</body>
16+
17+
</html>

widget/src/main.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import App from './App.svelte';
2+
3+
const targetInput = document.querySelector('input[data-s3fileinput]') as Element;
4+
const parent = targetInput.parentNode;
5+
const wrapper = document.createElement('div');
6+
parent?.replaceChild(wrapper, targetInput);
7+
wrapper.appendChild(targetInput);
8+
9+
const app = new App({
10+
target: document.querySelector('input[data-s3fileinput]')?.parentNode as Element,
11+
props: {
12+
name: 'world',
13+
},
14+
});
15+
16+
export default app;

widget/src/svelte.d.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
declare module '*.svelte' {
2+
interface ComponentOptions<Props> {
3+
target: HTMLElement;
4+
anchor?: HTMLElement;
5+
props?: Props;
6+
hydrate?: boolean;
7+
intro?: boolean;
8+
}
9+
10+
interface Component<Props> {
11+
new (options: ComponentOptions<Props>): any;
12+
$set: (props: object) => any;
13+
$on: (event: string, callback: (event: CustomEvent) => any) => any;
14+
$destroy: () => any;
15+
render: (props?: object) => {
16+
html: string;
17+
css: { code: string; map?: string };
18+
head?: string;
19+
};
20+
}
21+
22+
const component: Component<object>;
23+
24+
export default component;
25+
}

0 commit comments

Comments
 (0)