mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 07:16:39 +00:00
Add copy YAML (automation & script) fallback without navigator.clipboard
(#7900)
This commit is contained in:
parent
ac0871d0e8
commit
f9dece0743
@ -1,8 +1,12 @@
|
|||||||
export const copyToClipboard = (str) => {
|
export const copyToClipboard = (str) => {
|
||||||
const el = document.createElement("textarea");
|
if (navigator.clipboard) {
|
||||||
el.value = str;
|
navigator.clipboard.writeText(str);
|
||||||
document.body.appendChild(el);
|
} else {
|
||||||
el.select();
|
const el = document.createElement("textarea");
|
||||||
document.execCommand("copy");
|
el.value = str;
|
||||||
document.body.removeChild(el);
|
document.body.appendChild(el);
|
||||||
|
el.select();
|
||||||
|
document.execCommand("copy");
|
||||||
|
document.body.removeChild(el);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -32,6 +32,7 @@ import "../../../components/ha-svg-icon";
|
|||||||
import "../../../components/ha-yaml-editor";
|
import "../../../components/ha-yaml-editor";
|
||||||
import { showToast } from "../../../util/toast";
|
import { showToast } from "../../../util/toast";
|
||||||
import type { HaYamlEditor } from "../../../components/ha-yaml-editor";
|
import type { HaYamlEditor } from "../../../components/ha-yaml-editor";
|
||||||
|
import { copyToClipboard } from "../../../common/util/copy-clipboard";
|
||||||
import {
|
import {
|
||||||
AutomationConfig,
|
AutomationConfig,
|
||||||
AutomationEntity,
|
AutomationEntity,
|
||||||
@ -396,7 +397,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
|
|
||||||
private async _copyYaml() {
|
private async _copyYaml() {
|
||||||
if (this._editor?.yaml) {
|
if (this._editor?.yaml) {
|
||||||
navigator.clipboard.writeText(this._editor.yaml);
|
copyToClipboard(this._editor.yaml);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ import "../../../components/ha-icon-input";
|
|||||||
import "../../../components/ha-svg-icon";
|
import "../../../components/ha-svg-icon";
|
||||||
import "../../../components/ha-yaml-editor";
|
import "../../../components/ha-yaml-editor";
|
||||||
import type { HaYamlEditor } from "../../../components/ha-yaml-editor";
|
import type { HaYamlEditor } from "../../../components/ha-yaml-editor";
|
||||||
|
import { copyToClipboard } from "../../../common/util/copy-clipboard";
|
||||||
import {
|
import {
|
||||||
Action,
|
Action,
|
||||||
deleteScript,
|
deleteScript,
|
||||||
@ -545,7 +546,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
|
|
||||||
private async _copyYaml() {
|
private async _copyYaml() {
|
||||||
if (this._editor?.yaml) {
|
if (this._editor?.yaml) {
|
||||||
navigator.clipboard.writeText(this._editor.yaml);
|
copyToClipboard(this._editor.yaml);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user