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

Svelte widget #299

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ ignore =
D10,
extend-exclude =
node_modules,
.direnv
# Explicitly set this, so "python-client/pyproject.toml" is never used
black-config = pyproject.toml
8 changes: 8 additions & 0 deletions widget/.parcelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This file is JSON5](https://parceljs.org/features/plugins/#.parcelrc), so let's use the same 2-space indent as other files.

Go ahead and add this file name to .editorconfig too.

"extends": "@parcel/config-default",
"transformers": {
"*.svelte": [
"parcel-transformer-svelte3-plus"
]
}
}
504 changes: 458 additions & 46 deletions widget/package-lock.json

Large diffs are not rendered by default.

32 changes: 29 additions & 3 deletions widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"build": "npm-run-all build:clean build:compile"
},
"dependencies": {
"django-s3-file-field": "file:../javascript-client"
"django-s3-file-field": "file:../javascript-client",
"svelte": "^4.2.0",
"svelte-preprocess": "^5.0.4"
},
"devDependencies": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort the devDependencies list.

"@parcel/transformer-sass": "^2.10.0",
Expand All @@ -27,7 +29,11 @@
"npm-run-all": "^4.1.5",
"parcel": "^2.10.0",
"rimraf": "^5.0.5",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"@tsconfig/svelte": "^5.0.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove @tsconfig/recommended as a dependency, since it's no longer used.

"parcel-transformer-svelte3-plus": "^0.2.10",
"process": "^0.11.10",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove process, unless it's somehow needed.

"svelte-check": "^3.5.0"
},
"alias": {
"buffer": false
Expand All @@ -36,7 +42,13 @@
"last 1 chrome version",
"last 1 firefox version"
],
"@parcel/resolver-default": {
"packageExports": true
},
"eslintConfig": {
"env": {
"node": true
},
Comment on lines +49 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? We're compiling something for the browser, not Node.

"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": true
Expand All @@ -53,6 +65,20 @@
],
"rules": {
"no-restricted-syntax": 0
}
},
"settings": {
"import/resolver": {
"typescript": {}
}
},
"overrides": [
{
"files": [
"**/*.ts",
"**/*.js",
"**/*.svelte"
]
}
]
}
}
6 changes: 6 additions & 0 deletions widget/src/App.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script lang="ts">
export let name: string = "friend";
console.log(arguments);
</script>

<h1>Hello {name}!</h1>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parcel-transformer-svelte3-plus is going to automatically enable svelte-preprocess for us (if it's installed), so we can use the template tag feature: https://github.com/sveltejs/svelte-preprocess#template-tag

So, I'd suggest wrapping the HTML in .svelte in <template> tags.

16 changes: 16 additions & 0 deletions widget/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import App from './App.svelte';

const targetInput = document.querySelector('input[data-s3fileinput]') as Element;
const parent = targetInput.parentNode;
const wrapper = document.createElement('div');
parent?.replaceChild(wrapper, targetInput);
wrapper.appendChild(targetInput);

const app = new App({
target: document.querySelector('input[data-s3fileinput]')?.parentNode as Element,
props: {
name: 'world',
},
});

export default app;
25 changes: 25 additions & 0 deletions widget/src/svelte.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
declare module '*.svelte' {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is any of this file necessary? Did you follow a tutorial that suggested creating this, or was it necessary to create by hand?

interface ComponentOptions<Props> {
target: HTMLElement;
anchor?: HTMLElement;
props?: Props;
hydrate?: boolean;
intro?: boolean;
}

interface Component<Props> {
new (options: ComponentOptions<Props>): any;
$set: (props: object) => any;
$on: (event: string, callback: (event: CustomEvent) => any) => any;
$destroy: () => any;
render: (props?: object) => {
html: string;
css: { code: string; map?: string };
head?: string;
};
}

const component: Component<object>;

export default component;
}
5 changes: 5 additions & 0 deletions widget/svelte.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const sveltePreprocess = require('svelte-preprocess')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this file may not be necessary at all: https://github.com/HellButcher/parcel-transformer-svelte3-plus#configuration

If we do need it, I'd rather use .svelterc as a declarative JSON format, instead of svelte.config.js, if possible.


module.exports = {
preprocess: sveltePreprocess()
}
7 changes: 5 additions & 2 deletions widget/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"extends": "@tsconfig/recommended/tsconfig.json",
"extends": "@tsconfig/svelte/tsconfig.json",
"include": [
"src/**/*"
"src/**/*",
"src/**/*.ts",
"src/**/*.js",
"src/**/*.svelte"
Comment on lines +5 to +7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these necessary? Aren't they matched by *?

]
}