@chayns-components/core 5.5.14 → 5.5.20
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/lib/cjs/components/copyable-content/CopyableContent.js +18 -12
- package/lib/cjs/components/copyable-content/CopyableContent.js.map +1 -1
- package/lib/cjs/components/copyable-content/CopyableContent.styles.js +2 -1
- package/lib/cjs/components/copyable-content/CopyableContent.styles.js.map +1 -1
- package/lib/cjs/components/copyable-content/CopyableContent.test.js +26 -17
- package/lib/cjs/components/copyable-content/CopyableContent.test.js.map +1 -1
- package/lib/cjs/components/copyable-content/copyableContentClipboard.js +45 -28
- package/lib/cjs/components/copyable-content/copyableContentClipboard.js.map +1 -1
- package/lib/cjs/components/copyable-content/copyableContentClipboard.test.js +13 -11
- package/lib/cjs/components/copyable-content/copyableContentClipboard.test.js.map +1 -1
- package/lib/cjs/components/sharing-context-menu/SharingContextMenu.js +11 -12
- package/lib/cjs/components/sharing-context-menu/SharingContextMenu.js.map +1 -1
- package/lib/cjs/components/sharing-context-menu/SharingContextMenu.test.js +48 -0
- package/lib/cjs/components/sharing-context-menu/SharingContextMenu.test.js.map +1 -0
- package/lib/cjs/constants/textStrings.js +0 -4
- package/lib/cjs/constants/textStrings.js.map +1 -1
- package/lib/cjs/utils/sharingBar.js +14 -17
- package/lib/cjs/utils/sharingBar.js.map +1 -1
- package/lib/esm/components/copyable-content/CopyableContent.js +19 -13
- package/lib/esm/components/copyable-content/CopyableContent.js.map +1 -1
- package/lib/esm/components/copyable-content/CopyableContent.styles.js +2 -1
- package/lib/esm/components/copyable-content/CopyableContent.styles.js.map +1 -1
- package/lib/esm/components/copyable-content/CopyableContent.test.js +24 -16
- package/lib/esm/components/copyable-content/CopyableContent.test.js.map +1 -1
- package/lib/esm/components/copyable-content/copyableContentClipboard.js +41 -28
- package/lib/esm/components/copyable-content/copyableContentClipboard.js.map +1 -1
- package/lib/esm/components/copyable-content/copyableContentClipboard.test.js +13 -11
- package/lib/esm/components/copyable-content/copyableContentClipboard.test.js.map +1 -1
- package/lib/esm/components/sharing-context-menu/SharingContextMenu.js +11 -12
- package/lib/esm/components/sharing-context-menu/SharingContextMenu.js.map +1 -1
- package/lib/esm/components/sharing-context-menu/SharingContextMenu.test.js +45 -0
- package/lib/esm/components/sharing-context-menu/SharingContextMenu.test.js.map +1 -0
- package/lib/esm/constants/textStrings.js +0 -4
- package/lib/esm/constants/textStrings.js.map +1 -1
- package/lib/esm/utils/sharingBar.js +15 -18
- package/lib/esm/utils/sharingBar.js.map +1 -1
- package/lib/types/components/copyable-content/CopyableContent.d.ts +0 -1
- package/lib/types/components/sharing-context-menu/SharingContextMenu.d.ts +16 -0
- package/lib/types/constants/textStrings.d.ts +0 -4
- package/package.json +5 -7
- package/LICENSE +0 -21
|
@@ -1,17 +1,41 @@
|
|
|
1
1
|
import { formatStringToHtml } from '@chayns-components/format';
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
const getPlainTextFromHtml = html => {
|
|
3
|
+
const document = new DOMParser().parseFromString(html, 'text/html');
|
|
4
|
+
return Array.from(document.body.children).map(element => {
|
|
5
|
+
if (element.tagName === 'UL' || element.tagName === 'OL') {
|
|
6
|
+
return Array.from(element.children).map(item => `• ${item.textContent?.trim() ?? ''}`).join('\n');
|
|
7
|
+
}
|
|
8
|
+
return element.textContent?.trim() ?? '';
|
|
9
|
+
}).filter(Boolean).join('\n\n');
|
|
10
|
+
};
|
|
11
|
+
const createClipboardContent = source => {
|
|
12
|
+
const {
|
|
13
|
+
html
|
|
14
|
+
} = formatStringToHtml(source);
|
|
15
|
+
return {
|
|
16
|
+
html,
|
|
17
|
+
plainText: getPlainTextFromHtml(html)
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const copyWithClipboardItem = async ({
|
|
21
|
+
html,
|
|
22
|
+
plainText
|
|
23
|
+
}) => {
|
|
24
|
+
const clipboardData = new ClipboardItem({
|
|
25
|
+
'text/plain': new Blob([plainText], {
|
|
26
|
+
type: 'text/plain'
|
|
27
|
+
}),
|
|
28
|
+
'text/html': new Blob([html], {
|
|
29
|
+
type: 'text/html'
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
await navigator.clipboard.write([clipboardData]);
|
|
9
33
|
};
|
|
10
|
-
const copyPlainText = async
|
|
34
|
+
const copyPlainText = async plainText => {
|
|
11
35
|
if (typeof ClipboardItem !== 'undefined') {
|
|
12
36
|
try {
|
|
13
|
-
await navigator.clipboard.write([
|
|
14
|
-
'text/plain': new Blob([
|
|
37
|
+
await navigator.clipboard.write([new ClipboardItem({
|
|
38
|
+
'text/plain': new Blob([plainText], {
|
|
15
39
|
type: 'text/plain'
|
|
16
40
|
})
|
|
17
41
|
})]);
|
|
@@ -20,33 +44,22 @@ const copyPlainText = async source => {
|
|
|
20
44
|
// Use writeText as the final browser-compatible fallback.
|
|
21
45
|
}
|
|
22
46
|
}
|
|
23
|
-
await navigator.clipboard.writeText(
|
|
47
|
+
await navigator.clipboard.writeText(plainText);
|
|
24
48
|
};
|
|
25
49
|
export const copyableContentToClipboard = async source => {
|
|
50
|
+
const clipboardContent = createClipboardContent(source);
|
|
26
51
|
if (!navigator.clipboard) {
|
|
27
52
|
throw new Error('Clipboard API is not available.');
|
|
28
53
|
}
|
|
29
|
-
if (typeof ClipboardItem === 'undefined'
|
|
30
|
-
await copyPlainText(
|
|
54
|
+
if (typeof ClipboardItem === 'undefined') {
|
|
55
|
+
await copyPlainText(clipboardContent.plainText);
|
|
31
56
|
return;
|
|
32
57
|
}
|
|
33
|
-
const {
|
|
34
|
-
html
|
|
35
|
-
} = formatStringToHtml(source);
|
|
36
58
|
try {
|
|
37
|
-
await
|
|
38
|
-
'text/plain': new Blob([source], {
|
|
39
|
-
type: 'text/plain'
|
|
40
|
-
}),
|
|
41
|
-
'text/markdown': new Blob([source], {
|
|
42
|
-
type: 'text/markdown'
|
|
43
|
-
}),
|
|
44
|
-
'text/html': new Blob([html], {
|
|
45
|
-
type: 'text/html'
|
|
46
|
-
})
|
|
47
|
-
})]);
|
|
59
|
+
await copyWithClipboardItem(clipboardContent);
|
|
48
60
|
} catch {
|
|
49
|
-
|
|
61
|
+
// Use the plain-text fallback when the browser rejects rich MIME types.
|
|
62
|
+
await copyPlainText(clipboardContent.plainText);
|
|
50
63
|
}
|
|
51
64
|
};
|
|
52
65
|
//# sourceMappingURL=copyableContentClipboard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copyableContentClipboard.js","names":["formatStringToHtml","
|
|
1
|
+
{"version":3,"file":"copyableContentClipboard.js","names":["formatStringToHtml","getPlainTextFromHtml","html","document","DOMParser","parseFromString","Array","from","body","children","map","element","tagName","item","textContent","trim","join","filter","Boolean","createClipboardContent","source","plainText","copyWithClipboardItem","clipboardData","ClipboardItem","Blob","type","navigator","clipboard","write","copyPlainText","writeText","copyableContentToClipboard","clipboardContent","Error"],"sources":["../../../../src/components/copyable-content/copyableContentClipboard.ts"],"sourcesContent":["import { formatStringToHtml } from '@chayns-components/format';\n\ninterface ClipboardContent {\n html: string;\n plainText: string;\n}\n\nconst getPlainTextFromHtml = (html: string) => {\n const document = new DOMParser().parseFromString(html, 'text/html');\n\n return Array.from(document.body.children)\n .map((element) => {\n if (element.tagName === 'UL' || element.tagName === 'OL') {\n return Array.from(element.children)\n .map((item) => `• ${item.textContent?.trim() ?? ''}`)\n .join('\\n');\n }\n\n return element.textContent?.trim() ?? '';\n })\n .filter(Boolean)\n .join('\\n\\n');\n};\n\nconst createClipboardContent = (source: string): ClipboardContent => {\n const { html } = formatStringToHtml(source);\n return { html, plainText: getPlainTextFromHtml(html) };\n};\n\nconst copyWithClipboardItem = async ({ html, plainText }: ClipboardContent) => {\n const clipboardData = new ClipboardItem({\n 'text/plain': new Blob([plainText], { type: 'text/plain' }),\n 'text/html': new Blob([html], { type: 'text/html' }),\n });\n\n await navigator.clipboard.write([clipboardData]);\n};\n\nconst copyPlainText = async (plainText: string) => {\n if (typeof ClipboardItem !== 'undefined') {\n try {\n await navigator.clipboard.write([\n new ClipboardItem({\n 'text/plain': new Blob([plainText], { type: 'text/plain' }),\n }),\n ]);\n return;\n } catch {\n // Use writeText as the final browser-compatible fallback.\n }\n }\n\n await navigator.clipboard.writeText(plainText);\n};\n\nexport const copyableContentToClipboard = async (source: string) => {\n const clipboardContent = createClipboardContent(source);\n\n if (!navigator.clipboard) {\n throw new Error('Clipboard API is not available.');\n }\n\n if (typeof ClipboardItem === 'undefined') {\n await copyPlainText(clipboardContent.plainText);\n return;\n }\n\n try {\n await copyWithClipboardItem(clipboardContent);\n } catch {\n // Use the plain-text fallback when the browser rejects rich MIME types.\n await copyPlainText(clipboardContent.plainText);\n }\n};\n"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,2BAA2B;AAO9D,MAAMC,oBAAoB,GAAIC,IAAY,IAAK;EAC3C,MAAMC,QAAQ,GAAG,IAAIC,SAAS,CAAC,CAAC,CAACC,eAAe,CAACH,IAAI,EAAE,WAAW,CAAC;EAEnE,OAAOI,KAAK,CAACC,IAAI,CAACJ,QAAQ,CAACK,IAAI,CAACC,QAAQ,CAAC,CACpCC,GAAG,CAAEC,OAAO,IAAK;IACd,IAAIA,OAAO,CAACC,OAAO,KAAK,IAAI,IAAID,OAAO,CAACC,OAAO,KAAK,IAAI,EAAE;MACtD,OAAON,KAAK,CAACC,IAAI,CAACI,OAAO,CAACF,QAAQ,CAAC,CAC9BC,GAAG,CAAEG,IAAI,IAAK,KAAKA,IAAI,CAACC,WAAW,EAAEC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CACpDC,IAAI,CAAC,IAAI,CAAC;IACnB;IAEA,OAAOL,OAAO,CAACG,WAAW,EAAEC,IAAI,CAAC,CAAC,IAAI,EAAE;EAC5C,CAAC,CAAC,CACDE,MAAM,CAACC,OAAO,CAAC,CACfF,IAAI,CAAC,MAAM,CAAC;AACrB,C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,iCAAiC,CAAC;EACtD;EAEA,IAAI,OAAOV,aAAa,KAAK,WAAW,EAAE;IACtC,MAAMM,aAAa,CAACG,gBAAgB,CAACZ,SAAS,CAAC;IAC/C;EACJ;EAEA,IAAI;IACA,MAAMC,qBAAqB,CAACW,gBAAgB,CAAC;EACjD,CAAC,CAAC,MAAM;IACJ;IACA,MAAMH,aAAa,CAACG,gBAAgB,CAACZ,SAAS,CAAC;EACnD;AACJ,CAAC","ignoreList":[]}
|
|
@@ -12,27 +12,29 @@ describe('copyableContentToClipboard', () => {
|
|
|
12
12
|
afterEach(() => {
|
|
13
13
|
vi.restoreAllMocks();
|
|
14
14
|
});
|
|
15
|
-
it('writes
|
|
15
|
+
it('writes readable plain text first and safe HTML second', async () => {
|
|
16
16
|
const write = vi.spyOn(navigator.clipboard, 'write').mockResolvedValue();
|
|
17
17
|
await copyableContentToClipboard(source);
|
|
18
18
|
const item = write.mock.calls[0][0][0];
|
|
19
|
-
|
|
20
|
-
await expect(readBlob(await item.getType('text/
|
|
19
|
+
expect(Object.keys(item.items)).toEqual(['text/plain', 'text/html']);
|
|
20
|
+
await expect(readBlob(await item.getType('text/plain'))).resolves.toBe('Heading\n\nLink');
|
|
21
21
|
await expect(readBlob(await item.getType('text/html'))).resolves.toBe(formatStringToHtml(source).html);
|
|
22
22
|
});
|
|
23
|
-
it('uses a plain ClipboardItem
|
|
24
|
-
vi.
|
|
25
|
-
|
|
26
|
-
}));
|
|
27
|
-
const write = vi.spyOn(navigator.clipboard, 'write').mockResolvedValue();
|
|
23
|
+
it('uses a plain ClipboardItem after a rejected rich write', async () => {
|
|
24
|
+
const write = vi.spyOn(navigator.clipboard, 'write').mockRejectedValueOnce(new Error('denied')).mockResolvedValueOnce();
|
|
25
|
+
const writeText = vi.spyOn(navigator.clipboard, 'writeText').mockResolvedValue();
|
|
28
26
|
await copyableContentToClipboard(source);
|
|
29
|
-
expect(write).toHaveBeenCalledTimes(
|
|
27
|
+
expect(write).toHaveBeenCalledTimes(2);
|
|
28
|
+
expect(writeText).not.toHaveBeenCalled();
|
|
29
|
+
const item = write.mock.calls[1][0][0];
|
|
30
|
+
expect(Object.keys(item.items)).toEqual(['text/plain']);
|
|
31
|
+
await expect(readBlob(await item.getType('text/plain'))).resolves.toBe('Heading\n\nLink');
|
|
30
32
|
});
|
|
31
|
-
it('uses writeText after ClipboardItem writes fail', async () => {
|
|
33
|
+
it('uses writeText after all ClipboardItem writes fail', async () => {
|
|
32
34
|
vi.spyOn(navigator.clipboard, 'write').mockRejectedValue(new Error('denied'));
|
|
33
35
|
const writeText = vi.spyOn(navigator.clipboard, 'writeText').mockResolvedValue();
|
|
34
36
|
await copyableContentToClipboard(source);
|
|
35
|
-
expect(writeText).toHaveBeenCalledWith(
|
|
37
|
+
expect(writeText).toHaveBeenCalledWith('Heading\n\nLink');
|
|
36
38
|
});
|
|
37
39
|
});
|
|
38
40
|
//# sourceMappingURL=copyableContentClipboard.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copyableContentClipboard.test.js","names":["formatStringToHtml","afterEach","describe","expect","it","vi","copyableContentToClipboard","source","readBlob","blob","Promise","resolve","reject","reader","FileReader","onerror","error","onload","result","readAsText","restoreAllMocks","write","spyOn","navigator","clipboard","mockResolvedValue","item","mock","calls","getType","resolves","toBe","html","
|
|
1
|
+
{"version":3,"file":"copyableContentClipboard.test.js","names":["formatStringToHtml","afterEach","describe","expect","it","vi","copyableContentToClipboard","source","readBlob","blob","Promise","resolve","reject","reader","FileReader","onerror","error","onload","result","readAsText","restoreAllMocks","write","spyOn","navigator","clipboard","mockResolvedValue","item","mock","calls","Object","keys","items","toEqual","getType","resolves","toBe","html","mockRejectedValueOnce","Error","mockResolvedValueOnce","writeText","toHaveBeenCalledTimes","not","toHaveBeenCalled","mockRejectedValue","toHaveBeenCalledWith"],"sources":["../../../../src/components/copyable-content/copyableContentClipboard.test.ts"],"sourcesContent":["import { formatStringToHtml } from '@chayns-components/format';\nimport { afterEach, describe, expect, it, vi } from 'vitest';\nimport { copyableContentToClipboard } from './copyableContentClipboard';\n\nconst source = '# Heading\\n\\n[Link](https://example.com)';\n\nconst readBlob = (blob: Blob) =>\n new Promise<string>((resolve, reject) => {\n const reader = new FileReader();\n reader.onerror = () => reject(reader.error);\n reader.onload = () => resolve(reader.result as string);\n reader.readAsText(blob);\n });\n\ndescribe('copyableContentToClipboard', () => {\n afterEach(() => {\n vi.restoreAllMocks();\n });\n\n it('writes readable plain text first and safe HTML second', async () => {\n const write = vi.spyOn(navigator.clipboard, 'write').mockResolvedValue();\n\n await copyableContentToClipboard(source);\n\n const item = write.mock.calls[0][0][0] as unknown as ClipboardItem & {\n items: Record<string, Blob>;\n };\n expect(Object.keys(item.items)).toEqual(['text/plain', 'text/html']);\n await expect(readBlob(await item.getType('text/plain'))).resolves.toBe('Heading\\n\\nLink');\n await expect(readBlob(await item.getType('text/html'))).resolves.toBe(\n formatStringToHtml(source).html,\n );\n });\n\n it('uses a plain ClipboardItem after a rejected rich write', async () => {\n const write = vi\n .spyOn(navigator.clipboard, 'write')\n .mockRejectedValueOnce(new Error('denied'))\n .mockResolvedValueOnce();\n const writeText = vi.spyOn(navigator.clipboard, 'writeText').mockResolvedValue();\n\n await copyableContentToClipboard(source);\n\n expect(write).toHaveBeenCalledTimes(2);\n expect(writeText).not.toHaveBeenCalled();\n const item = write.mock.calls[1][0][0] as unknown as ClipboardItem & {\n items: Record<string, Blob>;\n };\n expect(Object.keys(item.items)).toEqual(['text/plain']);\n await expect(readBlob(await item.getType('text/plain'))).resolves.toBe('Heading\\n\\nLink');\n });\n\n it('uses writeText after all ClipboardItem writes fail', async () => {\n vi.spyOn(navigator.clipboard, 'write').mockRejectedValue(new Error('denied'));\n const writeText = vi.spyOn(navigator.clipboard, 'writeText').mockResolvedValue();\n\n await copyableContentToClipboard(source);\n\n expect(writeText).toHaveBeenCalledWith('Heading\\n\\nLink');\n });\n});\n"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,2B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,IAAIN,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7E,MAAME,SAAS,GAAGnC,EAAE,CAACiB,KAAK,CAACC,SAAS,CAACC,SAAS,EAAE,WAAW,CAAC,CAACC,iBAAiB,CAAC,CAAC;IAEhF,MAAMnB,0BAA0B,CAACC,MAAM,CAAC;IAExCJ,MAAM,CAACqC,SAAS,CAAC,CAACK,oBAAoB,CAAC,iBAAiB,CAAC;EAC7D,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
|
|
@@ -9,6 +9,8 @@ const SharingContextMenu = /*#__PURE__*/forwardRef(({
|
|
|
9
9
|
link,
|
|
10
10
|
children,
|
|
11
11
|
shouldEnableKeyboardHighlighting,
|
|
12
|
+
shouldShowCallingCodeAction = true,
|
|
13
|
+
shouldShowCopyAction = true,
|
|
12
14
|
...contextMenuProps
|
|
13
15
|
}, ref) => {
|
|
14
16
|
const isTouch = useIsTouch();
|
|
@@ -55,12 +57,12 @@ const SharingContextMenu = /*#__PURE__*/forwardRef(({
|
|
|
55
57
|
break;
|
|
56
58
|
}
|
|
57
59
|
}, [link, isTouch]);
|
|
58
|
-
const contextMenuItems = [{
|
|
60
|
+
const contextMenuItems = [...(shouldShowCopyAction ? [{
|
|
59
61
|
icons: ['fa fa-copy'],
|
|
60
62
|
key: 'copy',
|
|
61
63
|
onClick: () => handleShare('copy'),
|
|
62
64
|
text: 'Zwischenablage'
|
|
63
|
-
}, {
|
|
65
|
+
}] : []), {
|
|
64
66
|
icons: ['fa-solid fa-brands fa-whatsapp'],
|
|
65
67
|
key: 'whatsapp',
|
|
66
68
|
onClick: () => handleShare('whatsapp'),
|
|
@@ -80,21 +82,18 @@ const SharingContextMenu = /*#__PURE__*/forwardRef(({
|
|
|
80
82
|
key: 'mail',
|
|
81
83
|
onClick: () => handleShare('mail'),
|
|
82
84
|
text: 'Mail'
|
|
83
|
-
}, {
|
|
85
|
+
}, ...(shouldShowCallingCodeAction ? [{
|
|
84
86
|
icons: ['fa fa-qrcode'],
|
|
85
87
|
key: 'callingCode',
|
|
86
88
|
onClick: handleImageDownload,
|
|
87
89
|
text: 'Calling Code herunterladen'
|
|
88
|
-
}];
|
|
89
|
-
return (
|
|
90
|
-
|
|
90
|
+
}] : [])];
|
|
91
|
+
return /*#__PURE__*/React.createElement(ContextMenu, _extends({
|
|
92
|
+
items: contextMenuItems,
|
|
93
|
+
ref: ref,
|
|
94
|
+
shouldEnableKeyboardHighlighting: shouldEnableKeyboardHighlighting
|
|
91
95
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
92
|
-
|
|
93
|
-
items: contextMenuItems,
|
|
94
|
-
ref: ref,
|
|
95
|
-
shouldEnableKeyboardHighlighting: shouldEnableKeyboardHighlighting
|
|
96
|
-
}, contextMenuProps), children)
|
|
97
|
-
);
|
|
96
|
+
}, contextMenuProps), children);
|
|
98
97
|
});
|
|
99
98
|
SharingContextMenu.displayName = 'SharingContextMenu';
|
|
100
99
|
export default SharingContextMenu;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SharingContextMenu.js","names":["getSite","React","forwardRef","useCallback","SHAREPROVIDER","useIsTouch","copyToClipboard","shareWithApp","shareWithUrl","ContextMenu","SharingContextMenu","link","children","shouldEnableKeyboardHighlighting","contextMenuProps","ref","isTouch","handleImageDownload","url","replace","encodeURIComponent","color","handleShare","key","trim","contextMenuItems","icons","onClick","text","createElement","_extends","items","displayName"],"sources":["../../../../src/components/sharing-context-menu/SharingContextMenu.tsx"],"sourcesContent":["import { getSite } from 'chayns-api';\nimport React, { forwardRef, useCallback } from 'react';\nimport { SHAREPROVIDER } from '../../constants/sharingBar';\nimport { useIsTouch } from '../../utils/environment';\nimport { copyToClipboard, shareWithApp, shareWithUrl } from '../../utils/sharingBar';\nimport ContextMenu from '../context-menu/ContextMenu';\nimport { ContextMenuProps, ContextMenuRef } from '../context-menu/ContextMenu.types';\n\nexport type SharingContextMenuProps = {\n /**\n * The link that should be shared.\n */\n link: string;\n /**\n * Enables keyboard-only focus highlighting for the context menu trigger.\n */\n shouldEnableKeyboardHighlighting?: boolean;\n} & Omit<ContextMenuProps, 'items' | 'shouldEnableKeyboardHighlighting'>;\n\nconst SharingContextMenu = forwardRef<ContextMenuRef, SharingContextMenuProps>(\n ({
|
|
1
|
+
{"version":3,"file":"SharingContextMenu.js","names":["getSite","React","forwardRef","useCallback","SHAREPROVIDER","useIsTouch","copyToClipboard","shareWithApp","shareWithUrl","ContextMenu","SharingContextMenu","link","children","shouldEnableKeyboardHighlighting","shouldShowCallingCodeAction","shouldShowCopyAction","contextMenuProps","ref","isTouch","handleImageDownload","url","replace","encodeURIComponent","color","handleShare","key","trim","contextMenuItems","icons","onClick","text","createElement","_extends","items","displayName"],"sources":["../../../../src/components/sharing-context-menu/SharingContextMenu.tsx"],"sourcesContent":["import { getSite } from 'chayns-api';\nimport React, { forwardRef, useCallback } from 'react';\nimport { SHAREPROVIDER } from '../../constants/sharingBar';\nimport { useIsTouch } from '../../utils/environment';\nimport { copyToClipboard, shareWithApp, shareWithUrl } from '../../utils/sharingBar';\nimport ContextMenu from '../context-menu/ContextMenu';\nimport { ContextMenuProps, ContextMenuRef } from '../context-menu/ContextMenu.types';\n\nexport type SharingContextMenuProps = {\n /**\n * The link that should be shared.\n */\n link: string;\n /**\n * Shows the action that copies the shared link to the clipboard.\n */\n shouldShowCopyAction?: boolean;\n /**\n * Shows the action that downloads a calling-code image.\n */\n shouldShowCallingCodeAction?: boolean;\n /**\n * Enables keyboard-only focus highlighting for the context menu trigger.\n */\n shouldEnableKeyboardHighlighting?: boolean;\n} & Omit<ContextMenuProps, 'items' | 'shouldEnableKeyboardHighlighting'>;\n\nconst SharingContextMenu = forwardRef<ContextMenuRef, SharingContextMenuProps>(\n (\n {\n link,\n children,\n shouldEnableKeyboardHighlighting,\n shouldShowCallingCodeAction = true,\n shouldShowCopyAction = true,\n ...contextMenuProps\n },\n ref,\n ) => {\n const isTouch = useIsTouch();\n\n const handleImageDownload = useCallback(() => {\n shareWithUrl(\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n SHAREPROVIDER[5].url\n .replace('{url}', encodeURIComponent(link))\n .replace('{linkText}', 'Teilen')\n .replace('{color}', getSite().color.replace('#', '')),\n );\n }, [link]);\n\n const handleShare = useCallback(\n (key: string) => {\n switch (key) {\n case 'whatsapp':\n shareWithUrl(\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n SHAREPROVIDER[0].url.replace(\n '{url}',\n encodeURIComponent(`${link}`.trim()),\n ),\n );\n break;\n case 'facebook':\n shareWithUrl(\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n SHAREPROVIDER[3].url.replace('{url}', encodeURIComponent(link)),\n );\n break;\n case 'twitter':\n shareWithUrl(\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n SHAREPROVIDER[4].url\n .replace('{url}', encodeURIComponent(link))\n .replace('{linkText}', ''),\n );\n break;\n case 'mail':\n if (isTouch) {\n shareWithApp(`${link}`.trim());\n } else {\n shareWithUrl(\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n SHAREPROVIDER[2].url.replace(\n '{url}',\n encodeURIComponent(`${link}`.trim()),\n ),\n );\n }\n break;\n case 'copy':\n copyToClipboard(link);\n break;\n default:\n break;\n }\n },\n [link, isTouch],\n );\n\n const contextMenuItems = [\n ...(shouldShowCopyAction\n ? [\n {\n icons: ['fa fa-copy'],\n key: 'copy',\n onClick: () => handleShare('copy'),\n text: 'Zwischenablage',\n },\n ]\n : []),\n {\n icons: ['fa-solid fa-brands fa-whatsapp'],\n key: 'whatsapp',\n onClick: () => handleShare('whatsapp'),\n text: 'Whatsapp',\n },\n {\n icons: ['fa-solid fa-brands fa-facebook-f'],\n key: 'facebook',\n onClick: () => handleShare('facebook'),\n text: 'Facebook',\n },\n {\n icons: ['fa-solid fa-brands fa-x-twitter'],\n key: 'twitter',\n onClick: () => handleShare('twitter'),\n text: 'X',\n },\n {\n icons: ['fa fa-envelope'],\n key: 'mail',\n onClick: () => handleShare('mail'),\n text: 'Mail',\n },\n ...(shouldShowCallingCodeAction\n ? [\n {\n icons: ['fa fa-qrcode'],\n key: 'callingCode',\n onClick: handleImageDownload,\n text: 'Calling Code herunterladen',\n },\n ]\n : []),\n ];\n\n return (\n <ContextMenu\n items={contextMenuItems}\n ref={ref}\n shouldEnableKeyboardHighlighting={shouldEnableKeyboardHighlighting}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...contextMenuProps}\n >\n {children}\n </ContextMenu>\n );\n },\n);\n\nSharingContextMenu.displayName = 'SharingContextMenu';\n\nexport default SharingContextMenu;\n"],"mappings":";AAAA,SAASA,OAAO,QAAQ,YAAY;AACpC,OAAOC,KAAK,IAAIC,UAAU,EAAEC,WAAW,QAAQ,OAAO;AACtD,SAASC,aAAa,QAAQ,4BAA4B;AAC1D,SAASC,UAAU,QAAQ,yBAAyB;AACpD,SAASC,eAAe,EAAEC,YAAY,EAAEC,YAAY,QAAQ,wBAAwB;AACpF,OAAOC,WAAW,MAAM,6BAA6B;AAsBrD,MAAMC,kBAAkB,gBAAGR,UAAU,CACjC,CACI;EACIS,IAAI;EACJC,QAAQ;EACRC,gCAAgC;EAChCC,2BAA2B,GAAG,IAAI;EAClCC,oBAAoB,GAAG,IAAI;EAC3B,GAAGC;AACP,CAAC,EACDC,GAAG,KACF;EACD,MAAMC,OAAO,GAAGb,UAAU,CAAC,CAAC;EAE5B,MAAMc,mBAAmB,GAAGhB,WAAW,CAAC,MAAM;IAC1CK,YAAY;IACR;IACA;IACAJ,aAAa,CAAC,CAAC,CAAC,CAACgB,GAAG,CACfC,OAAO,CAAC,OAAO,EAAEC,kBAAkB,CAACX,IAAI,CAAC,CAAC,CAC1CU,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,CAC/BA,OAAO,CAAC,SAAS,EAAErB,OAAO,CAAC,CAAC,CAACuB,KAAK,CAACF,OAAO,CAAC,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@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import SharingContextMenu from './SharingContextMenu';
|
|
5
|
+
vi.mock('chayns-api', () => ({
|
|
6
|
+
getSite: () => ({
|
|
7
|
+
color: '#000000'
|
|
8
|
+
})
|
|
9
|
+
}));
|
|
10
|
+
vi.mock('../../utils/environment', () => ({
|
|
11
|
+
useIsTouch: () => false
|
|
12
|
+
}));
|
|
13
|
+
vi.mock('../context-menu/ContextMenu', () => ({
|
|
14
|
+
default: ({
|
|
15
|
+
children,
|
|
16
|
+
items
|
|
17
|
+
}) => /*#__PURE__*/React.createElement("div", {
|
|
18
|
+
"data-item-keys": items.map(item => item.key).join(',')
|
|
19
|
+
}, children)
|
|
20
|
+
}));
|
|
21
|
+
describe('SharingContextMenu', () => {
|
|
22
|
+
it('keeps copy and calling-code actions enabled by default', () => {
|
|
23
|
+
const {
|
|
24
|
+
container
|
|
25
|
+
} = render(/*#__PURE__*/React.createElement(SharingContextMenu, {
|
|
26
|
+
link: "https://example.com"
|
|
27
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
28
|
+
type: "button"
|
|
29
|
+
}, "Share")));
|
|
30
|
+
expect(container.firstChild.getAttribute('data-item-keys')).toBe('copy,whatsapp,facebook,twitter,mail,callingCode');
|
|
31
|
+
});
|
|
32
|
+
it('can hide copy and calling-code actions for dedicated content actions', () => {
|
|
33
|
+
const {
|
|
34
|
+
container
|
|
35
|
+
} = render(/*#__PURE__*/React.createElement(SharingContextMenu, {
|
|
36
|
+
link: "https://example.com",
|
|
37
|
+
shouldShowCallingCodeAction: false,
|
|
38
|
+
shouldShowCopyAction: false
|
|
39
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
40
|
+
type: "button"
|
|
41
|
+
}, "Share")));
|
|
42
|
+
expect(container.firstChild.getAttribute('data-item-keys')).toBe('whatsapp,facebook,twitter,mail');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=SharingContextMenu.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SharingContextMenu.test.js","names":["render","React","describe","expect","it","vi","SharingContextMenu","mock","getSite","color","useIsTouch","default","children","items","createElement","map","item","key","join","container","link","type","firstChild","getAttribute","toBe","shouldShowCallingCodeAction","shouldShowCopyAction"],"sources":["../../../../src/components/sharing-context-menu/SharingContextMenu.test.tsx"],"sourcesContent":["import { render } from '@testing-library/react';\nimport React, { ReactNode } from 'react';\nimport { describe, expect, it, vi } from 'vitest';\nimport SharingContextMenu from './SharingContextMenu';\n\nvi.mock('chayns-api', () => ({\n getSite: () => ({ color: '#000000' }),\n}));\n\nvi.mock('../../utils/environment', () => ({\n useIsTouch: () => false,\n}));\n\nvi.mock('../context-menu/ContextMenu', () => ({\n default: ({ children, items }: { children: ReactNode; items: Array<{ key: string }> }) => (\n <div data-item-keys={items.map((item) => item.key).join(',')}>{children}</div>\n ),\n}));\n\ndescribe('SharingContextMenu', () => {\n it('keeps copy and calling-code actions enabled by default', () => {\n const { container } = render(\n <SharingContextMenu link=\"https://example.com\">\n <button type=\"button\">Share</button>\n </SharingContextMenu>,\n );\n\n expect((container.firstChild as HTMLElement).getAttribute('data-item-keys')).toBe(\n 'copy,whatsapp,facebook,twitter,mail,callingCode',\n );\n });\n\n it('can hide copy and calling-code actions for dedicated content actions', () => {\n const { container } = render(\n <SharingContextMenu\n link=\"https://example.com\"\n shouldShowCallingCodeAction={false}\n shouldShowCopyAction={false}\n >\n <button type=\"button\">Share</button>\n </SharingContextMenu>,\n );\n\n expect((container.firstChild as HTMLElement).getAttribute('data-item-keys')).toBe(\n 'whatsapp,facebook,twitter,mail',\n );\n });\n});\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,wBAAwB;AAC/C,OAAOC,KAAK,MAAqB,OAAO;AACxC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,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,KAAA,CAAAa,aAAA;MAAQO,IAAI,EAAC;IAAQ,GAAC,OAAa,CACnB,CACxB,CAAC;IAEDlB,MAAM,CAAEgB,SAAS,CAACG,UAAU,CAAiBC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAACC,IAAI,CAC7E,gCACJ,CAAC;EACL,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
|
|
@@ -49,10 +49,6 @@ export default {
|
|
|
49
49
|
stringName: 'txt_chayns_components_core_components_copyableContent_share',
|
|
50
50
|
fallback: 'Teilen'
|
|
51
51
|
},
|
|
52
|
-
copied: {
|
|
53
|
-
stringName: 'txt_chayns_components_core_components_copyableContent_copied',
|
|
54
|
-
fallback: 'Kopiert'
|
|
55
|
-
},
|
|
56
52
|
copyFailed: {
|
|
57
53
|
stringName: 'txt_chayns_components_core_components_copyableContent_copyFailed',
|
|
58
54
|
fallback: 'Kopieren fehlgeschlagen'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textStrings.js","names":["components","filter","filterContent","input","placeholder","stringName","fallback","sort","filterButtons","all","truncation","less","more","fileItem","download","remove","copyableContent","copy","share","
|
|
1
|
+
{"version":3,"file":"textStrings.js","names":["components","filter","filterContent","input","placeholder","stringName","fallback","sort","filterButtons","all","truncation","less","more","fileItem","download","remove","copyableContent","copy","share","copyFailed"],"sources":["../../../src/constants/textStrings.ts"],"sourcesContent":["export default {\n components: {\n filter: {\n filterContent: {\n input: {\n placeholder: {\n stringName:\n 'txt_chayns_components_core_components_filter_filterContent_input_placeholder',\n fallback: 'Suche',\n },\n },\n sort: {\n stringName: 'txt_chayns_components_core_components_filter_filterContent_sort',\n fallback: 'Sortierung',\n },\n },\n },\n filterButtons: {\n all: {\n stringName: 'txt_chayns_components_core_components_filterButtons_all',\n fallback: 'Alle',\n },\n },\n truncation: {\n less: {\n stringName: 'txt_chayns_components_core_components_truncation_less',\n fallback: 'Weniger',\n },\n more: {\n stringName: 'txt_chayns_components_core_components_truncation_more',\n fallback: 'Mehr',\n },\n },\n fileItem: {\n download: {\n stringName: 'txt_chayns_components_core_components_fileItem_download',\n fallback: 'Download',\n },\n remove: {\n stringName: 'txt_chayns_components_core_components_fileItem_remove',\n fallback: 'Entfernen',\n },\n },\n copyableContent: {\n copy: {\n stringName: 'txt_chayns_components_core_components_copyableContent_copy',\n fallback: 'Kopieren',\n },\n share: {\n stringName: 'txt_chayns_components_core_components_copyableContent_share',\n fallback: 'Teilen',\n },\n copyFailed: {\n stringName: 'txt_chayns_components_core_components_copyableContent_copyFailed',\n fallback: 'Kopieren fehlgeschlagen',\n },\n },\n },\n} as const;\n"],"mappings":"AAAA,eAAe;EACXA,UAAU,EAAE;IACRC,MAAM,EAAE;MACJC,aAAa,EAAE;QACXC,KAAK,EAAE;UACHC,WAAW,EAAE;YACTC,UAAU,EACN,8EAA8E;YAClFC,QAAQ,EAAE;UACd;QACJ,CAAC;QACDC,IAAI,EAAE;UACFF,UAAU,EAAE,iEAAiE;UAC7EC,QAAQ,EAAE;QACd;MACJ;IACJ,CAAC;IACDE,aAAa,EAAE;MACXC,GAAG,EAAE;QACDJ,UAAU,EAAE,yDAAyD;QACrEC,QAAQ,EAAE;MACd;IACJ,CAAC;IACDI,UAAU,EAAE;MACRC,IAAI,EAAE;QACFN,UAAU,EAAE,uDAAuD;QACnEC,QAAQ,EAAE;MACd,CAAC;MACDM,IAAI,EAAE;QACFP,UAAU,EAAE,uDAAuD;QACnEC,QAAQ,EAAE;MACd;IACJ,CAAC;IACDO,QAAQ,EAAE;MACNC,QAAQ,EAAE;QACNT,UAAU,EAAE,yDAAyD;QACrEC,QAAQ,EAAE;MACd,CAAC;MACDS,MAAM,EAAE;QACJV,UAAU,EAAE,uDAAuD;QACnEC,QAAQ,EAAE;MACd;IACJ,CAAC;IACDU,eAAe,EAAE;MACbC,IAAI,EAAE;QACFZ,UAAU,EAAE,4DAA4D;QACxEC,QAAQ,EAAE;MACd,CAAC;MACDY,KAAK,EAAE;QACHb,UAAU,EAAE,6DAA6D;QACzEC,QAAQ,EAAE;MACd,CAAC;MACDa,UAAU,EAAE;QACRd,UAAU,EAAE,kEAAkE;QAC9EC,QAAQ,EAAE;MACd;IACJ;EACJ;AACJ,CAAC","ignoreList":[]}
|
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { openImage } from 'chayns-api';
|
|
2
2
|
export const copyToClipboard = link => {
|
|
3
3
|
const aux = document.createElement('input');
|
|
4
|
-
const range = document.createRange();
|
|
5
4
|
aux.setAttribute('value', link);
|
|
6
5
|
aux.setAttribute('contenteditable', 'true');
|
|
7
6
|
aux.setAttribute('readonly', 'true');
|
|
8
7
|
document.body.appendChild(aux);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
try {
|
|
9
|
+
const selection = window.getSelection();
|
|
10
|
+
if (!selection) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const range = document.createRange();
|
|
14
|
+
aux.select();
|
|
15
|
+
range.selectNodeContents(aux);
|
|
16
|
+
selection.removeAllRanges();
|
|
17
|
+
selection.addRange(range);
|
|
18
|
+
aux.setSelectionRange(0, 999999);
|
|
19
|
+
document.execCommand('copy');
|
|
20
|
+
} finally {
|
|
21
|
+
aux.remove();
|
|
14
22
|
}
|
|
15
|
-
s.removeAllRanges();
|
|
16
|
-
s.addRange(range);
|
|
17
|
-
aux.setSelectionRange(0, 999999);
|
|
18
|
-
document.execCommand('copy');
|
|
19
|
-
document.body.removeChild(aux);
|
|
20
|
-
void createDialog({
|
|
21
|
-
type: DialogType.TOAST,
|
|
22
|
-
showCloseIcon: true,
|
|
23
|
-
toastType: 1,
|
|
24
|
-
text: 'kopiert'
|
|
25
|
-
}).open();
|
|
26
23
|
};
|
|
27
24
|
export const shareWithApp = link => {
|
|
28
25
|
window.location.href = `mailto:?subject=&body=${encodeURIComponent(link)}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharingBar.js","names":["
|
|
1
|
+
{"version":3,"file":"sharingBar.js","names":["openImage","copyToClipboard","link","aux","document","createElement","setAttribute","body","appendChild","selection","window","getSelection","range","createRange","select","selectNodeContents","removeAllRanges","addRange","setSelectionRange","execCommand","remove","shareWithApp","location","href","encodeURIComponent","shareWithUrl","startsWith","open","indexOf","items","url"],"sources":["../../../src/utils/sharingBar.ts"],"sourcesContent":["import { openImage } from 'chayns-api';\n\nexport const copyToClipboard = (link: string) => {\n const aux = document.createElement('input');\n aux.setAttribute('value', link);\n aux.setAttribute('contenteditable', 'true');\n aux.setAttribute('readonly', 'true');\n\n document.body.appendChild(aux);\n\n try {\n const selection = window.getSelection();\n\n if (!selection) {\n return;\n }\n\n const range = document.createRange();\n aux.select();\n range.selectNodeContents(aux);\n selection.removeAllRanges();\n selection.addRange(range);\n aux.setSelectionRange(0, 999999);\n document.execCommand('copy');\n } finally {\n aux.remove();\n }\n};\n\nexport const shareWithApp = (link: string) => {\n window.location.href = `mailto:?subject=&body=${encodeURIComponent(link)}`;\n};\n\nexport const shareWithUrl = (link: string) => {\n if (link.startsWith('mailto')) {\n window.open(link);\n } else if (link.indexOf('chaynsqrcodegenerator') > 0) {\n void openImage({ items: [{ url: link }] });\n } else {\n window.open(link, '_blank');\n }\n};\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,YAAY;AAEtC,OAAO,MAAMC,eAAe,GAAIC,IAAY,IAAK;EAC7C,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,OAAO,CAAC;EAC3CF,GAAG,CAACG,YAAY,CAAC,OAAO,EAAEJ,IAAI,CAAC;EAC/BC,GAAG,CAACG,YAAY,CAAC,iBAAiB,EAAE,MAAM,CAAC;EAC3CH,GAAG,CAACG,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC;EAEpCF,QAAQ,CAACG,IAAI,CAACC,WAAW,CAACL,GAAG,CAAC;EAE9B,IAAI;IACA,MAAMM,SAAS,GAAGC,MAAM,CAACC,YAAY,CAAC,CAAC;IAEvC,IAAI,CAACF,SAAS,EAAE;MACZ;IACJ;IAEA,MAAMG,KAAK,GAAGR,QAAQ,CAACS,WAAW,CAAC,CAAC;IACpCV,GAAG,CAACW,MAAM,CAAC,CAAC;IACZF,KAAK,CAACG,kBAAkB,CAACZ,GAAG,CAAC;IAC7BM,SAAS,CAACO,eAAe,CAAC,CAAC;IAC3BP,SAAS,CAACQ,QAAQ,CAACL,KAAK,CAAC;IACzBT,GAAG,CAACe,iBAAiB,CAAC,CAAC,EAAE,MAAM,CAAC;IAChCd,QAAQ,CAACe,WAAW,CAAC,MAAM,CAAC;EAChC,CAAC,SAAS;IACNhB,GAAG,CAACiB,MAAM,CAAC,CAAC;EAChB;AACJ,CAAC;AAED,OAAO,MAAMC,YAAY,GAAInB,IAAY,IAAK;EAC1CQ,MAAM,CAACY,QAAQ,CAACC,IAAI,GAAG,yBAAyBC,kBAAkB,CAACtB,IAAI,CAAC,EAAE;AAC9E,CAAC;AAED,OAAO,MAAMuB,YAAY,GAAIvB,IAAY,IAAK;EAC1C,IAAIA,IAAI,CAACwB,UAAU,CAAC,QAAQ,CAAC,EAAE;IAC3BhB,MAAM,CAACiB,IAAI,CAACzB,IAAI,CAAC;EACrB,CAAC,MAAM,IAAIA,IAAI,CAAC0B,OAAO,CAAC,uBAAuB,CAAC,GAAG,CAAC,EAAE;IAClD,KAAK5B,SAAS,CAAC;MAAE6B,KAAK,EAAE,CAAC;QAAEC,GAAG,EAAE5B;MAAK,CAAC;IAAE,CAAC,CAAC;EAC9C,CAAC,MAAM;IACHQ,MAAM,CAACiB,IAAI,CAACzB,IAAI,EAAE,QAAQ,CAAC;EAC/B;AACJ,CAAC","ignoreList":[]}
|
|
@@ -5,6 +5,14 @@ export type SharingContextMenuProps = {
|
|
|
5
5
|
* The link that should be shared.
|
|
6
6
|
*/
|
|
7
7
|
link: string;
|
|
8
|
+
/**
|
|
9
|
+
* Shows the action that copies the shared link to the clipboard.
|
|
10
|
+
*/
|
|
11
|
+
shouldShowCopyAction?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Shows the action that downloads a calling-code image.
|
|
14
|
+
*/
|
|
15
|
+
shouldShowCallingCodeAction?: boolean;
|
|
8
16
|
/**
|
|
9
17
|
* Enables keyboard-only focus highlighting for the context menu trigger.
|
|
10
18
|
*/
|
|
@@ -15,6 +23,14 @@ declare const SharingContextMenu: React.ForwardRefExoticComponent<{
|
|
|
15
23
|
* The link that should be shared.
|
|
16
24
|
*/
|
|
17
25
|
link: string;
|
|
26
|
+
/**
|
|
27
|
+
* Shows the action that copies the shared link to the clipboard.
|
|
28
|
+
*/
|
|
29
|
+
shouldShowCopyAction?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Shows the action that downloads a calling-code image.
|
|
32
|
+
*/
|
|
33
|
+
shouldShowCallingCodeAction?: boolean;
|
|
18
34
|
/**
|
|
19
35
|
* Enables keyboard-only focus highlighting for the context menu trigger.
|
|
20
36
|
*/
|
|
@@ -49,10 +49,6 @@ declare const _default: {
|
|
|
49
49
|
readonly stringName: "txt_chayns_components_core_components_copyableContent_share";
|
|
50
50
|
readonly fallback: "Teilen";
|
|
51
51
|
};
|
|
52
|
-
readonly copied: {
|
|
53
|
-
readonly stringName: "txt_chayns_components_core_components_copyableContent_copied";
|
|
54
|
-
readonly fallback: "Kopiert";
|
|
55
|
-
};
|
|
56
52
|
readonly copyFailed: {
|
|
57
53
|
readonly stringName: "txt_chayns_components_core_components_copyableContent_copyFailed";
|
|
58
54
|
readonly fallback: "Kopieren fehlgeschlagen";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/core",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.20",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"browserslist": [
|
|
@@ -65,10 +65,9 @@
|
|
|
65
65
|
"@types/styled-components": "^5.1.36",
|
|
66
66
|
"@types/uuid": "^10.0.0",
|
|
67
67
|
"babel-loader": "^9.2.1",
|
|
68
|
-
"chayns-api": "^3.4.
|
|
68
|
+
"chayns-api": "^3.4.1",
|
|
69
69
|
"cross-env": "^7.0.3",
|
|
70
70
|
"jsdom": "^26.1.0",
|
|
71
|
-
"lerna": "^8.2.4",
|
|
72
71
|
"react": "^18.3.1",
|
|
73
72
|
"react-dom": "^18.3.1",
|
|
74
73
|
"styled-components": "^6.4.4",
|
|
@@ -76,8 +75,8 @@
|
|
|
76
75
|
"vitest": "^1.6.1"
|
|
77
76
|
},
|
|
78
77
|
"dependencies": {
|
|
79
|
-
"@chayns-components/format": "^5.5.
|
|
80
|
-
"@chayns-components/textstring": "^5.5.
|
|
78
|
+
"@chayns-components/format": "^5.5.20",
|
|
79
|
+
"@chayns-components/textstring": "^5.5.20",
|
|
81
80
|
"@chayns/colors": "^2.0.2",
|
|
82
81
|
"@chayns/uac-service": "~0.0.62",
|
|
83
82
|
"clsx": "^2.1.1",
|
|
@@ -93,6 +92,5 @@
|
|
|
93
92
|
},
|
|
94
93
|
"publishConfig": {
|
|
95
94
|
"access": "public"
|
|
96
|
-
}
|
|
97
|
-
"gitHead": "5933dcba58846a7507088aefcd35559b2635bd48"
|
|
95
|
+
}
|
|
98
96
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Tobit Laboratories AG
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|