@fluid-topics/ft-copy-block 1.1.18

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/README.md ADDED
@@ -0,0 +1,19 @@
1
+ Copy block
2
+
3
+ ## Install
4
+
5
+ ```shell
6
+ npm install @fluid-topics/ft-copy-block
7
+ yarn add @fluid-topics/ft-copy-block
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ ```typescript
13
+ import { html } from "lit"
14
+ import "@fluid-topics/ft-copy-block"
15
+
16
+ function render() {
17
+ return html` <ft-copy-block><pre>window.alert("toto")</pre></ft-copy-block> `
18
+ }
19
+ ```
@@ -0,0 +1,7 @@
1
+ import { DefaultI18nMessages, I18nMessageContext, I18nMessages } from "@fluid-topics/ft-i18n";
2
+ export interface CopyBlockComponentMessages extends I18nMessages {
3
+ tooltipMessage(): string;
4
+ copySuccessMessage(): string;
5
+ }
6
+ export declare const copyBlock: I18nMessageContext<CopyBlockComponentMessages>;
7
+ export declare const defaultCopyBlockMessages: DefaultI18nMessages<CopyBlockComponentMessages>;
@@ -0,0 +1,6 @@
1
+ import { I18nMessageContext } from "@fluid-topics/ft-i18n";
2
+ export const copyBlock = I18nMessageContext.build("copyBlockComponent");
3
+ export const defaultCopyBlockMessages = {
4
+ tooltipMessage: "Copy to clipboard",
5
+ copySuccessMessage: "Copied!",
6
+ };
@@ -0,0 +1,10 @@
1
+ export declare const FtCopyBlockCssVariables: {
2
+ spacing: import("@fluid-topics/ft-wc-utils").FtCssVariable;
3
+ borderRadius: import("@fluid-topics/ft-wc-utils").FtCssVariable;
4
+ borderStyle: import("@fluid-topics/ft-wc-utils").FtCssVariable;
5
+ borderColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
6
+ borderWidth: import("@fluid-topics/ft-wc-utils").FtCssVariable;
7
+ backgroundColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
8
+ buttonHeight: import("@fluid-topics/ft-wc-utils").FtCssVariable;
9
+ };
10
+ export declare const styles: import("lit").CSSResult;
@@ -0,0 +1,56 @@
1
+ import { css } from "lit";
2
+ import { designSystemVariables, FtCssVariableFactory } from "@fluid-topics/ft-wc-utils";
3
+ export const FtCopyBlockCssVariables = {
4
+ spacing: FtCssVariableFactory.create("--ft-copy-block-spacing", "", "SIZE", "12px 48px 12px 12px"),
5
+ borderRadius: FtCssVariableFactory.extend("--ft-copy-block-border-radius", "", designSystemVariables.borderRadiusS),
6
+ borderStyle: FtCssVariableFactory.create("--ft-copy-block-border-style", "", "BORDER-STYLE", "solid"),
7
+ borderColor: FtCssVariableFactory.extend("--ft-copy-block-border-color", "", designSystemVariables.colorOutline),
8
+ borderWidth: FtCssVariableFactory.create("--ft-copy-block-border-width", "", "SIZE", "1px"),
9
+ backgroundColor: FtCssVariableFactory.extend("--ft-copy-block-background-color", "", designSystemVariables.colorSurface),
10
+ buttonHeight: FtCssVariableFactory.create("--ft-copy-block-button-height", "", "SIZE", "unset"),
11
+ };
12
+ // language=CSS
13
+ export const styles = css `
14
+ :host {
15
+ display: block;
16
+ }
17
+
18
+ [part="container"] {
19
+ position: relative;
20
+ border-radius: ${FtCopyBlockCssVariables.borderRadius};
21
+ border-style: ${FtCopyBlockCssVariables.borderStyle};
22
+ border-color: ${FtCopyBlockCssVariables.borderColor};
23
+ border-width: ${FtCopyBlockCssVariables.borderWidth};
24
+ background-color: ${FtCopyBlockCssVariables.backgroundColor};
25
+ }
26
+
27
+ [part="button-container"] {
28
+ position: absolute;
29
+ right: 0;
30
+ top: 0;
31
+ height: ${FtCopyBlockCssVariables.buttonHeight}
32
+ }
33
+
34
+ [part="content"] {
35
+ overflow-x: auto;
36
+ margin: ${FtCopyBlockCssVariables.spacing};
37
+ }
38
+
39
+ [part="tooltip"] {
40
+ display: block;
41
+ height: ${FtCopyBlockCssVariables.buttonHeight}
42
+ }
43
+
44
+ [part="tooltip"]::part(container) {
45
+ height: ${FtCopyBlockCssVariables.buttonHeight}
46
+ }
47
+
48
+ [part="button"] {
49
+ height: ${FtCopyBlockCssVariables.buttonHeight}
50
+ }
51
+
52
+ [part="button"]::part(button) {
53
+ height: ${FtCopyBlockCssVariables.buttonHeight}
54
+ }
55
+
56
+ `;
@@ -0,0 +1,11 @@
1
+ import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
2
+ import { FtCopyBlockProperties } from "./ft-copy-block.properties";
3
+ import { FtLitElementWithI18n } from "@fluid-topics/ft-i18n";
4
+ export declare class FtCopyBlock extends FtLitElementWithI18n implements FtCopyBlockProperties {
5
+ static elementDefinitions: ElementDefinitionsMap;
6
+ static styles: import("lit").CSSResult;
7
+ private tooltip?;
8
+ constructor();
9
+ protected render(): import("lit").TemplateResult<1>;
10
+ private copyContents;
11
+ }
@@ -0,0 +1,58 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { html, nothing } from "lit";
8
+ import { query } from "lit/decorators.js";
9
+ import { FtButton } from "@fluid-topics/ft-button";
10
+ import { FtTooltip } from "@fluid-topics/ft-tooltip";
11
+ import { styles } from "./ft-copy-block.css";
12
+ import { copyBlock, defaultCopyBlockMessages } from "./CopyBlockComponentMessages";
13
+ import { FtLitElementWithI18n } from "@fluid-topics/ft-i18n";
14
+ class FtCopyBlock extends FtLitElementWithI18n {
15
+ constructor() {
16
+ super();
17
+ this.addI18nContext(copyBlock, defaultCopyBlockMessages);
18
+ }
19
+ render() {
20
+ return html `
21
+ <div part="container">
22
+ ${navigator.clipboard ? html `
23
+ <div part="button-container">
24
+ <ft-tooltip part="tooltip" text=${copyBlock.messages.tooltipMessage()} position="bottom" exportpartsPrefix="tooltip">
25
+ <ft-button icon="CLONE" part="button" exportpartsPrefix="button" @click=${this.copyContents}></ft-button>
26
+ </ft-tooltip>
27
+ </div>
28
+ ` : nothing}
29
+
30
+ <div part="content">
31
+ <slot></slot>
32
+ </div>
33
+ </div>
34
+ `;
35
+ }
36
+ async copyContents() {
37
+ try {
38
+ await navigator.clipboard.writeText(this.shadowRoot.host.innerText);
39
+ this.tooltip.manual = true;
40
+ this.tooltip.text = copyBlock.messages.copySuccessMessage();
41
+ await this.tooltip.show(1000);
42
+ this.tooltip.text = copyBlock.messages.tooltipMessage();
43
+ this.tooltip.manual = false;
44
+ }
45
+ catch {
46
+ console.log("Failed to copy to clipboard");
47
+ }
48
+ }
49
+ }
50
+ FtCopyBlock.elementDefinitions = {
51
+ "ft-button": FtButton,
52
+ "ft-tooltip": FtTooltip,
53
+ };
54
+ FtCopyBlock.styles = styles;
55
+ __decorate([
56
+ query("[part='tooltip']")
57
+ ], FtCopyBlock.prototype, "tooltip", void 0);
58
+ export { FtCopyBlock };