Skip to content
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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"lint:types": "tsc",
"precommit-badges": "node build-scripts/create-badges.js && git add public/badges",
"precommit-redirect": "node build-scripts/sort-redirects.js && prettier -w redirect.json legacy.json && git add redirect.json legacy.json",
"test": "node test/badges.js && node test/redirects.js && node --experimental-strip-types test/resolve.js"
"test": "node test/badges.js && node test/redirects.js && node --experimental-strip-types test/resolve.js && node --experimental-strip-types test/instances.js"
},
"pre-commit": [
"precommit-redirect",
Expand All @@ -23,6 +23,7 @@
"license": "Apache-2.0",
"devDependencies": {
"@11ty/eleventy": "^3.1.6",
"@types/sortablejs": "1.15.9",
"gulp": "^5.0.1",
"pre-commit": "^2.0.0",
"prettier": "^3.9.9",
Expand All @@ -40,7 +41,8 @@
"clipboard-copy": "^4.0.1",
"fuse.js": "7.5.0",
"html-minifier-terser": "^7.2.0",
"lit": "^3.3.3"
"lit": "^3.3.3",
"sortablejs": "1.15.7"
},
"packageManager": "pnpm@12.20.0"
}
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

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

4 changes: 4 additions & 0 deletions src-11ty/faq.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ <h1 class="card-header">Frequently Asked Questions</h1>
the documentation can link the user directly to the right page in their
instance.
</p>
<p>
If you manage more than one instance, you can store a URL for each of them.
When you open a link, My Home Assistant asks which instance to open it in.
</p>
<p>
All the data is stored in your browser. At no point will any data leave your
network. My Home Assistant only redirects you to pages that provide you with
Expand Down
6 changes: 6 additions & 0 deletions src-11ty/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
align-items: center;
line-break: anywhere;
}
.instance-url {
display: block;
}
.instance-info.multiple .instance-url {
margin-top: var(--ha-space-2);
}
.instance-header {
font-weight: 600;
letter-spacing: 0.05em;
Expand Down
47 changes: 47 additions & 0 deletions src-11ty/redirect-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,51 @@
.highlight {
display: none;
}
.instance-list {
list-style: none;
margin: 0;
padding: 0;
border-top: 1px solid var(--divider-color);
}
.instance-list li + li {
border-top: 1px solid var(--divider-color);
}
.instance-list[hidden] {
display: none;
}
.instance-list a {
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--ha-space-4);
box-sizing: border-box;
min-height: 48px;
padding: var(--ha-space-3) var(--ha-space-4);
color: var(--primary-text-color);
text-decoration: none;
line-break: anywhere;
}
.instance-list.card-end li:last-child a {
border-bottom-left-radius: var(--ha-card-border-radius);
border-bottom-right-radius: var(--ha-card-border-radius);
}
.instance-list a:focus-visible {
outline: var(--wa-focus-ring);
outline-offset: -2px;
}
@media (hover: hover) {
.instance-list a:hover {
background-color: var(--ha-color-fill-neutral-quiet-hover);
}
}
.instance-list svg {
flex-shrink: 0;
width: 24px;
height: 24px;
margin: 0;
color: var(--secondary-text-color);
fill: currentColor;
}

.warning {
position: relative;
Expand Down Expand Up @@ -108,6 +153,8 @@ <h1 class="card-header">Open page in your Home Assistant?</h1>
<a href="/faq#404">our troubleshooting steps</a>.
</div>

<ul class="instance-list" aria-label="Your instances" hidden></ul>

{% if redirect.redirect == "oauth" %}
<div class="card-actions">
<div class="fake-button decline-link">Decline</div>
Expand Down
147 changes: 147 additions & 0 deletions src/components/ha-sortable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// Adapted from frontend: https://github.com/home-assistant/frontend/blob/fdd66b5cecd7c15b772deb709bc51fe89b3910bf/src/components/ha-sortable.ts
import { html, LitElement, nothing, type PropertyValues } from "lit";
import { customElement, property } from "lit/decorators.js";
import Sortable, { type SortableEvent } from "sortablejs";
import { fireEvent } from "../util/fire_event";

@customElement("ha-sortable")
export class HaSortable extends LitElement {
private _sortable?: Sortable;

@property({ type: Boolean })
public disabled = false;

@property({ type: Boolean, attribute: "no-style" })
public noStyle = false;

@property({ type: String, attribute: "draggable-selector" })
public draggableSelector?: string;

@property({ type: String, attribute: "handle-selector" })
public handleSelector?: string;

@property({ type: Boolean })
public rollback = true;

protected updated(changedProperties: PropertyValues<this>) {
if (changedProperties.has("disabled")) {
if (this.disabled) {
this._destroySortable();
} else {
this._createSortable();
}
}
}

// Workaround for connectedCallback just after disconnectedCallback (when dragging sortable with sortable children)
private _shouldBeDestroy = false;

public disconnectedCallback() {
super.disconnectedCallback();
this._shouldBeDestroy = true;
setTimeout(() => {
if (this._shouldBeDestroy) {
this._destroySortable();
this._shouldBeDestroy = false;
}
}, 1);
}

public connectedCallback() {
super.connectedCallback();
this._shouldBeDestroy = false;
if (this.hasUpdated && !this.disabled) {
this._createSortable();
}
}

protected createRenderRoot() {
return this;
}

protected render() {
if (this.noStyle) return nothing;
return html`
<style>
.sortable-fallback {
display: none !important;
}

.sortable-ghost {
box-shadow: 0 0 0 2px var(--primary-color);
background: var(--ha-color-fill-primary-normal-resting);
border-radius: var(--ha-border-radius-sm);
opacity: 0.4;
}

.sortable-drag {
border-radius: var(--ha-border-radius-sm);
opacity: 1;
background: var(--card-background-color);
box-shadow: 0px 4px 8px 3px #00000026;
cursor: grabbing;
}
</style>
`;
}

private _createSortable() {
if (this._sortable) return;
const container = this.children[0] as HTMLElement | undefined;

if (!container) return;

const options: Sortable.Options = {
scroll: true,
// Force the autoscroll fallback because it works better than the native one
forceAutoScrollFallback: true,
scrollSpeed: 20,
animation: 150,
onChoose: this._handleChoose,
onEnd: this._handleEnd,
onUpdate: this._handleUpdate,
};

if (this.draggableSelector) {
options.draggable = this.draggableSelector;
}
if (this.handleSelector) {
options.handle = this.handleSelector;
}

this._sortable = new Sortable(container, options);
}

private _handleUpdate = (evt: SortableEvent) => {
fireEvent(this, "item-moved", {
newIndex: evt.newIndex!,
oldIndex: evt.oldIndex!,
});
};

private _handleEnd = (evt: SortableEvent) => {
// put back in original location
if (this.rollback && (evt.item as any).placeholder) {
(evt.item as any).placeholder.replaceWith(evt.item);
delete (evt.item as any).placeholder;
}
};

private _handleChoose = (evt: SortableEvent) => {
if (!this.rollback) return;
(evt.item as any).placeholder = document.createComment("sort-placeholder");
evt.item.after((evt.item as any).placeholder);
};

private _destroySortable() {
if (!this._sortable) return;
this._sortable.destroy();
this._sortable = undefined;
}
}

declare global {
interface HTMLElementTagNameMap {
"ha-sortable": HaSortable;
}
}
40 changes: 29 additions & 11 deletions src/components/my-instance-info.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,47 @@
import { unsafeSVG } from "lit/directives/unsafe-svg.js";
import { html, LitElement, TemplateResult } from "lit";
import { html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators.js";
import { svgPencil } from "./svg-pencil";

@customElement("my-instance-info")
class MyInstanceInfo extends LitElement {
@property({ attribute: false }) public instanceUrl!: string | null;
@property({ attribute: false }) public instanceUrls: string[] = [];

createRenderRoot() {
return this;
}

protected render(): TemplateResult {
if (!this.instanceUrl) {
return html``;
protected render() {
if (!this.instanceUrls.length) {
return nothing;
}
const multiple = this.instanceUrls.length > 1;
const editLabel = multiple ? "Edit instances" : "Edit instance";
return html`
<div class="instance-info">
<div class=${multiple ? "instance-info multiple" : "instance-info"}>
<div>
<div class="instance-header">HOME ASSISTANT INSTANCE</div>
<a href=${this.instanceUrl} rel="noreferrer noopener" target="_blank">
${this.instanceUrl}
</a>
<div class="instance-header">
${multiple ? "HOME ASSISTANT INSTANCES" : "HOME ASSISTANT INSTANCE"}
</div>
${this.instanceUrls.map(
(url) => html`
<a
class="instance-url"
href=${url}
rel="noreferrer noopener"
target="_blank"
>
${url}
</a>
`,
)}
</div>
<button class="empty" @click=${this._handleEdit}>
<button
class="empty"
aria-label=${editLabel}
title=${editLabel}
@click=${this._handleEdit}
>
${unsafeSVG(svgPencil)}
</button>
</div>
Expand Down
Loading