mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +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) => {
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(str);
|
||||
} else {
|
||||
const el = document.createElement("textarea");
|
||||
el.value = str;
|
||||
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 { showToast } from "../../../util/toast";
|
||||
import type { HaYamlEditor } from "../../../components/ha-yaml-editor";
|
||||
import { copyToClipboard } from "../../../common/util/copy-clipboard";
|
||||
import {
|
||||
AutomationConfig,
|
||||
AutomationEntity,
|
||||
@ -396,7 +397,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
||||
|
||||
private async _copyYaml() {
|
||||
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-yaml-editor";
|
||||
import type { HaYamlEditor } from "../../../components/ha-yaml-editor";
|
||||
import { copyToClipboard } from "../../../common/util/copy-clipboard";
|
||||
import {
|
||||
Action,
|
||||
deleteScript,
|
||||
@ -545,7 +546,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
||||
|
||||
private async _copyYaml() {
|
||||
if (this._editor?.yaml) {
|
||||
navigator.clipboard.writeText(this._editor.yaml);
|
||||
copyToClipboard(this._editor.yaml);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user