@peektravel/app-utilities 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ui/index.cjs CHANGED
@@ -2151,16 +2151,47 @@ var OdyCopyButton = class extends OdyElement {
2151
2151
  }
2152
2152
  #onClick = () => {
2153
2153
  const value = this.attr("value");
2154
- const clipboard = typeof navigator !== "undefined" ? navigator.clipboard : void 0;
2155
- if (!clipboard || typeof clipboard.writeText !== "function") {
2156
- this.#feedback("error", value);
2157
- return;
2154
+ const ok = this.#execCopy(value);
2155
+ if (!ok) {
2156
+ const clipboard = typeof navigator !== "undefined" ? navigator.clipboard : void 0;
2157
+ if (clipboard && typeof clipboard.writeText === "function") {
2158
+ void clipboard.writeText(value).then(
2159
+ () => void 0,
2160
+ () => void 0
2161
+ );
2162
+ }
2158
2163
  }
2159
- void clipboard.writeText(value).then(
2160
- () => this.#feedback("success", value),
2161
- () => this.#feedback("error", value)
2162
- );
2164
+ this.#feedback(ok ? "success" : "error", value);
2163
2165
  };
2166
+ /**
2167
+ * Synchronous clipboard write. Must be called within the user-gesture window
2168
+ * (i.e. directly from the click handler, not from an async continuation).
2169
+ * Works in cross-origin iframes and legacy contexts where the async Clipboard
2170
+ * API is unavailable or blocked.
2171
+ */
2172
+ #execCopy(value) {
2173
+ if (!value || typeof document === "undefined") return false;
2174
+ const el = document.createElement("textarea");
2175
+ el.value = value;
2176
+ el.setAttribute("readonly", "");
2177
+ el.style.position = "fixed";
2178
+ el.style.top = "0";
2179
+ el.style.left = "0";
2180
+ el.style.opacity = "0";
2181
+ document.body.appendChild(el);
2182
+ el.select();
2183
+ try {
2184
+ el.setSelectionRange(0, value.length);
2185
+ } catch {
2186
+ }
2187
+ let ok = false;
2188
+ try {
2189
+ ok = document.execCommand("copy");
2190
+ } catch {
2191
+ }
2192
+ document.body.removeChild(el);
2193
+ return ok;
2194
+ }
2164
2195
  #feedback(state, value) {
2165
2196
  this.#state = state;
2166
2197
  this.render();