Skip to content

Commit

Permalink
chore: setup fiber-htmx package
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Sep 13, 2024
1 parent 0cffba1 commit 5709b22
Show file tree
Hide file tree
Showing 15 changed files with 1,509 additions and 209 deletions.
29 changes: 29 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: ['plugin:prettier/recommended'],
overrides: [
{
files: ['**/*.tsx'],
rules: {
'react/prop-types': 'off'
}
}
],
settings: {
react: {
version: 'detect' // Tells eslint-plugin-react to automatically detect the version of React to use
}
},
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
ecmaFeatures: {
jsx: true // Allows for the parsing of JSX
}
},
rules: {}
}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package.json
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
}
}
60 changes: 60 additions & 0 deletions dist/fiber-htmx.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __decorateClass = (decorators, target, key, kind) => {
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
for (var i = decorators.length - 1, decorator; i >= 0; i--)
if (decorator = decorators[i])
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
if (kind && result) __defProp(target, key, result);
return result;
};

// src/toasts.ts
import { html, css, LitElement } from "lit";
import { customElement, property } from "lit/decorators.js";
var Toasts = class extends LitElement {
constructor() {
super(...arguments);
this.notifications = new Array();
}
connectedCallback() {
super.connectedCallback();
window.addEventListener("htmx-toasts:notify", (e) => this._handleNotify(e));
}
disconnectedCallback() {
super.disconnectedCallback();
window.removeEventListener("htmx-toasts:notify", (e) => this._handleNotify(e));
}
_handleNotify(e) {
const notifcation = { id: e.timeStamp, ...e.detail };
this.notifications.push(notifcation);
setTimeout(() => this._remove(notifcation), 3e3);
this.requestUpdate();
}
_remove(n) {
this.notifications = this.notifications.filter((i) => i.id !== n.id);
}
render() {
return html`
<link href="https://cdn.jsdelivr.net/npm/daisyui/dist/full.css" rel="stylesheet" type="text/css">
<div class="toast" role="status" aria-live="polite">
${this.notifications.map((n) => html`
<div class="alert alert-${n.level}">
<span>${n.message}</span>
<button class="btn btn-sm btn-outline" @click=${() => this._remove(n)}>Close</button>
</div>
`)}
</div>
`;
}
};
Toasts.styles = css`.toast { z-index: 9999; }`;
__decorateClass([
property({ type: Array })
], Toasts.prototype, "notifications", 2);
Toasts = __decorateClass([
customElement("htmx-toasts")
], Toasts);
export {
Toasts
};
2 changes: 1 addition & 1 deletion dist/out.js → dist/fiber-htmx.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
3 changes: 3 additions & 0 deletions dist/main.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Toasts } from "./toasts";
export { Toasts };
//# sourceMappingURL=main.d.ts.map
1 change: 1 addition & 0 deletions dist/main.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions dist/toasts.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { LitElement } from 'lit';
type Level = 'info' | 'warn' | 'error';
type Code = number;
type Message = string;
type Notification = {
id: number;
message: Message;
level: Level;
code: Code;
};
export declare class Toasts extends LitElement {
static styles: import("lit").CSSResult;
notifications: Notification[];
connectedCallback(): void;
disconnectedCallback(): void;
private _handleNotify;
private _remove;
protected render(): import("lit-html").TemplateResult<1>;
}
export {};
//# sourceMappingURL=toasts.d.ts.map
1 change: 1 addition & 0 deletions dist/toasts.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

const (
BundleFolder = "dist"
DefaultBundleFile = "out.js"
DefaultBundleFile = "fiber-htmx.min.js"
)

//go:embed dist
Expand Down
3 changes: 2 additions & 1 deletion gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

package htmx

//go:generate npx esbuild --bundle --minify --sourcemap --outfile=dist/out.js src/main.ts
//go:generate npx esbuild --bundle --minify --sourcemap --outfile=dist/fiber-htmx.min.js src/main.ts
//go:generate npx esbuild --bundle --platform=neutral --packages=external --outfile=dist/fiber-htmx.esm.js src/main.ts
Loading

0 comments on commit 5709b22

Please sign in to comment.