mirror of
https://github.com/home-assistant/frontend.git
synced 2026-12-01 09:09:11 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac1aa4db75 |
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
import { consumeLocalize } from "../../../common/decorators/consume-context-entry";
|
||||
import type { LocalizeFunc } from "../../../common/translations/localize";
|
||||
import "../../../components/ha-code-editor";
|
||||
import "../../../components/ha-dialog";
|
||||
import { DialogMixin } from "../../../dialogs/dialog-mixin";
|
||||
import type { BlueprintContentDialogParams } from "./show-dialog-blueprint-content";
|
||||
|
||||
@customElement("dialog-blueprint-content")
|
||||
class DialogBlueprintContent extends DialogMixin<BlueprintContentDialogParams>(
|
||||
LitElement
|
||||
) {
|
||||
@state()
|
||||
@consumeLocalize()
|
||||
private _localize!: LocalizeFunc;
|
||||
|
||||
protected render() {
|
||||
if (!this.params) {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
return html`
|
||||
<ha-dialog
|
||||
open
|
||||
width="full"
|
||||
flexcontent
|
||||
header-title=${this._localize(
|
||||
"ui.panel.config.blueprint.add.raw_blueprint"
|
||||
)}
|
||||
header-subtitle=${this.params.name}
|
||||
>
|
||||
<ha-code-editor
|
||||
mode="yaml"
|
||||
.value=${this.params.content}
|
||||
read-only
|
||||
in-dialog
|
||||
dir="ltr"
|
||||
></ha-code-editor>
|
||||
</ha-dialog>
|
||||
`;
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
ha-dialog {
|
||||
--dialog-content-padding: 0;
|
||||
}
|
||||
/* A grid, so that the editor fills the height and scrolls inside */
|
||||
ha-code-editor {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: grid;
|
||||
grid-template-rows: minmax(0, 1fr);
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"dialog-blueprint-content": DialogBlueprintContent;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,14 @@
|
||||
import { mdiClose, mdiOpenInNew } from "@mdi/js";
|
||||
import "@home-assistant/components/card";
|
||||
import { mdiClose, mdiCodeBraces, mdiOpenInNew } from "@mdi/js";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import type { HASSDomTargetEvent } from "../../../common/dom/fire_event";
|
||||
import { withViewTransition } from "../../../common/util/view-transition";
|
||||
import "../../../components/ha-alert";
|
||||
import "../../../components/ha-button";
|
||||
import "../../../components/ha-code-editor";
|
||||
import "../../../components/ha-dialog";
|
||||
import "../../../components/ha-dialog-footer";
|
||||
import "../../../components/ha-dialog-header";
|
||||
import "../../../components/ha-expansion-panel";
|
||||
import "../../../components/ha-markdown";
|
||||
import "../../../components/ha-spinner";
|
||||
import "../../../components/input/ha-input";
|
||||
@@ -21,6 +19,7 @@ import { DirtyStateProviderMixin } from "../../../mixins/dirty-state-provider-mi
|
||||
import { haStyleDialog } from "../../../resources/styles";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { documentationUrl } from "../../../util/documentation-url";
|
||||
import { showBlueprintContentDialog } from "./show-dialog-blueprint-content";
|
||||
|
||||
interface BlueprintImportState {
|
||||
value: string;
|
||||
@@ -33,8 +32,6 @@ class DialogImportBlueprint extends DirtyStateProviderMixin<BlueprintImportState
|
||||
) {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property({ type: Boolean, reflect: true }) public large = false;
|
||||
|
||||
@state() private _params?;
|
||||
|
||||
@state() private _open = false;
|
||||
@@ -58,7 +55,6 @@ class DialogImportBlueprint extends DirtyStateProviderMixin<BlueprintImportState
|
||||
this._error = undefined;
|
||||
this._url = this._params.url;
|
||||
this._sourceUrlWarning = !this._isTrustedBlueprintUrl(this._url);
|
||||
this.large = false;
|
||||
this._open = true;
|
||||
this._initDirtyTracking(
|
||||
{ type: "shallow" },
|
||||
@@ -88,7 +84,6 @@ class DialogImportBlueprint extends DirtyStateProviderMixin<BlueprintImportState
|
||||
<ha-dialog
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${heading}
|
||||
width=${this.large ? "full" : "medium"}
|
||||
.preventScrimClose=${this.isDirtyState}
|
||||
@closed=${this._dialogClosed}
|
||||
>
|
||||
@@ -99,9 +94,7 @@ class DialogImportBlueprint extends DirtyStateProviderMixin<BlueprintImportState
|
||||
.label=${this.hass.localize("ui.common.close")}
|
||||
.path=${mdiClose}
|
||||
></ha-icon-button>
|
||||
<span slot="title" class="title-enlargeable" @click=${this._enlarge}>
|
||||
${heading}
|
||||
</span>
|
||||
<span slot="title">${heading}</span>
|
||||
</ha-dialog-header>
|
||||
<div>
|
||||
${
|
||||
@@ -164,18 +157,37 @@ class DialogImportBlueprint extends DirtyStateProviderMixin<BlueprintImportState
|
||||
></ha-input>
|
||||
`
|
||||
}
|
||||
<ha-expansion-panel
|
||||
.header=${this.hass.localize(
|
||||
"ui.panel.config.blueprint.add.raw_blueprint"
|
||||
)}
|
||||
>
|
||||
<ha-code-editor
|
||||
mode="yaml"
|
||||
.value=${this._result.raw_data}
|
||||
read-only
|
||||
dir="ltr"
|
||||
></ha-code-editor>
|
||||
</ha-expansion-panel>
|
||||
<hac-card class="content-card">
|
||||
<div class="content-row">
|
||||
<div class="content-text">
|
||||
<span>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.blueprint.add.raw_blueprint"
|
||||
)}
|
||||
</span>
|
||||
<span class="content-description">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.blueprint.add.raw_blueprint_description"
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
<ha-button
|
||||
appearance="filled"
|
||||
.accessibleLabel=${this.hass.localize(
|
||||
"ui.panel.config.blueprint.add.view_raw_blueprint_label"
|
||||
)}
|
||||
@click=${this._showContent}
|
||||
>
|
||||
<ha-svg-icon
|
||||
slot="start"
|
||||
.path=${mdiCodeBraces}
|
||||
></ha-svg-icon>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.blueprint.add.view_raw_blueprint"
|
||||
)}
|
||||
</ha-button>
|
||||
</div>
|
||||
</hac-card>
|
||||
${
|
||||
this._result?.exists
|
||||
? html`
|
||||
@@ -275,9 +287,10 @@ class DialogImportBlueprint extends DirtyStateProviderMixin<BlueprintImportState
|
||||
`;
|
||||
}
|
||||
|
||||
private _enlarge() {
|
||||
withViewTransition(() => {
|
||||
this.large = !this.large;
|
||||
private _showContent() {
|
||||
showBlueprintContentDialog(this, {
|
||||
name: this._result!.blueprint.metadata.name,
|
||||
content: this._result!.raw_data,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -384,11 +397,23 @@ class DialogImportBlueprint extends DirtyStateProviderMixin<BlueprintImportState
|
||||
a ha-svg-icon {
|
||||
--mdc-icon-size: 16px;
|
||||
}
|
||||
ha-expansion-panel {
|
||||
--expansion-panel-content-padding: 0px;
|
||||
.content-card {
|
||||
margin: var(--ha-space-6) 0 var(--ha-space-2);
|
||||
}
|
||||
.title-enlargeable {
|
||||
display: block;
|
||||
.content-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--ha-space-4);
|
||||
}
|
||||
.content-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.content-description {
|
||||
font-size: var(--ha-font-size-s);
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
`,
|
||||
];
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
|
||||
export interface BlueprintContentDialogParams {
|
||||
name: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
export const loadBlueprintContentDialog = () =>
|
||||
import("./dialog-blueprint-content");
|
||||
|
||||
export const showBlueprintContentDialog = (
|
||||
element: HTMLElement,
|
||||
dialogParams: BlueprintContentDialogParams
|
||||
): void => {
|
||||
fireEvent(element, "show-dialog", {
|
||||
dialogTag: "dialog-blueprint-content",
|
||||
dialogImport: loadBlueprintContentDialog,
|
||||
dialogParams,
|
||||
});
|
||||
};
|
||||
@@ -7136,6 +7136,9 @@
|
||||
"community_forums": "View blueprints on the community forums",
|
||||
"url": "Blueprint address",
|
||||
"raw_blueprint": "Blueprint content",
|
||||
"raw_blueprint_description": "Check the code before you import it.",
|
||||
"view_raw_blueprint": "View",
|
||||
"view_raw_blueprint_label": "View blueprint content",
|
||||
"importing": "Loading blueprint…",
|
||||
"import_btn": "Preview",
|
||||
"saving": "Importing blueprint…",
|
||||
|
||||
Reference in new issue
Block a user