You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.6 KiB
1.6 KiB
clipboard
arts/clipboard contains ActiveClipboard, a small service for writing text to
the clipboard without components reading navigator.clipboard directly.
Ownership
ActiveAppcan declare it withdefineActiveClipboard(...).- Standalone
ActiveUixcreates it by default and lets you disable it withclipboard:false. - Attached
ActiveUixcreates no substitutes: if a layer asks foruix.clipboardandapp.clipboarddoes not exist, it fails with an explicit error. ActiveDomdoes not own this capability. The clipboard is an environment capability, not a visual mutation of DOM nodes.
Direct use
import { createActiveClipboard } from '$clipboard';
const clipboard = createActiveClipboard();
await clipboard.writeText('Copied text');
clipboard.dispose();
Injection
Tests, SSR shells and apps with their own permissions can inject a writer:
const clipboard = createActiveClipboard({
writer: {
async writeText(text) {
await customClipboardApi.write(text);
}
}
});
With no writer and no navigator.clipboard.writeText, writeText(...) throws
ActiveClipboardUnavailableError.
ActiveApp
import { createActiveApp } from '$active-app';
import { defineActiveClipboard } from '$active-app/service-factories';
const App = createActiveApp({
services: {
clipboard: defineActiveClipboard()
}
});
await App.clipboard.writeText('Copied text');
UIX / Soma
Soma components that need to write to the clipboard consume uix.clipboard
through their layer scope. They do not import $clipboard or read navigator
directly.