@flighthq/clipboard 0.1.0 → 0.2.0
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/package.json +8 -3
- package/src/clipboard.test.ts +34 -27
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/clipboard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/flighthq/flight.git",
|
|
7
|
+
"directory": "packages/clipboard"
|
|
8
|
+
},
|
|
4
9
|
"type": "module",
|
|
5
10
|
"main": "dist/index.js",
|
|
6
11
|
"types": "dist/index.d.ts",
|
|
@@ -27,8 +32,8 @@
|
|
|
27
32
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
28
33
|
},
|
|
29
34
|
"dependencies": {
|
|
30
|
-
"@flighthq/signals": "0.
|
|
31
|
-
"@flighthq/types": "0.
|
|
35
|
+
"@flighthq/signals": "0.2.0",
|
|
36
|
+
"@flighthq/types": "0.2.0"
|
|
32
37
|
},
|
|
33
38
|
"devDependencies": {
|
|
34
39
|
"typescript": "^5.3.0"
|
package/src/clipboard.test.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { ClipboardBackend, ClipboardBookmark } from '@flighthq/types';
|
|
2
|
+
import {
|
|
3
|
+
ClipboardFormatBookmark,
|
|
4
|
+
ClipboardFormatHtml,
|
|
5
|
+
ClipboardFormatImage,
|
|
6
|
+
ClipboardFormatRtf,
|
|
7
|
+
ClipboardFormatText,
|
|
8
|
+
} from '@flighthq/types';
|
|
2
9
|
|
|
3
10
|
import {
|
|
4
11
|
attachClipboardWatch,
|
|
@@ -55,15 +62,15 @@ function fakeBackend(): ClipboardBackend & {
|
|
|
55
62
|
formats: {},
|
|
56
63
|
changeCount: 0,
|
|
57
64
|
async readFormat(format) {
|
|
58
|
-
if (format ===
|
|
59
|
-
if (format ===
|
|
60
|
-
if (format ===
|
|
65
|
+
if (format === ClipboardFormatText) return this.text;
|
|
66
|
+
if (format === ClipboardFormatHtml) return this.html;
|
|
67
|
+
if (format === ClipboardFormatRtf) return this.rtf;
|
|
61
68
|
return this.formats[format] ?? '';
|
|
62
69
|
},
|
|
63
70
|
async writeFormat(format, data) {
|
|
64
|
-
if (format ===
|
|
65
|
-
else if (format ===
|
|
66
|
-
else if (format ===
|
|
71
|
+
if (format === ClipboardFormatText) this.text = data;
|
|
72
|
+
else if (format === ClipboardFormatHtml) this.html = data;
|
|
73
|
+
else if (format === ClipboardFormatRtf) this.rtf = data;
|
|
67
74
|
else this.formats[format] = data;
|
|
68
75
|
this.changeCount++;
|
|
69
76
|
return true;
|
|
@@ -74,11 +81,11 @@ function fakeBackend(): ClipboardBackend & {
|
|
|
74
81
|
},
|
|
75
82
|
async getFormats() {
|
|
76
83
|
const out: string[] = [];
|
|
77
|
-
if (this.text.length > 0) out.push(
|
|
78
|
-
if (this.html.length > 0) out.push(
|
|
79
|
-
if (this.rtf.length > 0) out.push(
|
|
80
|
-
if (this.image.length > 0) out.push(
|
|
81
|
-
if (this.bookmark !== null) out.push(
|
|
84
|
+
if (this.text.length > 0) out.push(ClipboardFormatText);
|
|
85
|
+
if (this.html.length > 0) out.push(ClipboardFormatHtml);
|
|
86
|
+
if (this.rtf.length > 0) out.push(ClipboardFormatRtf);
|
|
87
|
+
if (this.image.length > 0) out.push(ClipboardFormatImage);
|
|
88
|
+
if (this.bookmark !== null) out.push(ClipboardFormatBookmark);
|
|
82
89
|
for (const k of Object.keys(this.formats)) out.push(k);
|
|
83
90
|
return out;
|
|
84
91
|
},
|
|
@@ -228,7 +235,7 @@ describe('createWebClipboardBackend', () => {
|
|
|
228
235
|
const backend = createWebClipboardBackend();
|
|
229
236
|
expect(typeof (await backend.readText())).toBe('string');
|
|
230
237
|
expect(typeof (await backend.readHtml())).toBe('string');
|
|
231
|
-
expect(typeof (await backend.readFormat(
|
|
238
|
+
expect(typeof (await backend.readFormat(ClipboardFormatText))).toBe('string');
|
|
232
239
|
});
|
|
233
240
|
|
|
234
241
|
it('getFormats returns an array without throwing', async () => {
|
|
@@ -317,7 +324,7 @@ describe('getClipboardFormats', () => {
|
|
|
317
324
|
expect(await getClipboardFormats()).toEqual([]);
|
|
318
325
|
await writeClipboardText('hi');
|
|
319
326
|
const formats = await getClipboardFormats();
|
|
320
|
-
expect(formats).toContain(
|
|
327
|
+
expect(formats).toContain(ClipboardFormatText);
|
|
321
328
|
});
|
|
322
329
|
|
|
323
330
|
it('returns [] from the web backend without throwing', async () => {
|
|
@@ -335,8 +342,8 @@ describe('hasClipboardBookmark', () => {
|
|
|
335
342
|
|
|
336
343
|
it('returns true after a bookmark is written by the backend', async () => {
|
|
337
344
|
const backend = fakeBackend();
|
|
338
|
-
// Simulate a backend that puts
|
|
339
|
-
backend.formats[
|
|
345
|
+
// Simulate a backend that puts ClipboardFormatBookmark in formats when a bookmark is written
|
|
346
|
+
backend.formats[ClipboardFormatBookmark] = 'https://example.com\nFlight';
|
|
340
347
|
setClipboardBackend(backend);
|
|
341
348
|
expect(await hasClipboardBookmark()).toBe(true);
|
|
342
349
|
});
|
|
@@ -346,9 +353,9 @@ describe('hasClipboardFormat', () => {
|
|
|
346
353
|
it('reflects whether a format is present', async () => {
|
|
347
354
|
const backend = fakeBackend();
|
|
348
355
|
setClipboardBackend(backend);
|
|
349
|
-
expect(await hasClipboardFormat(
|
|
356
|
+
expect(await hasClipboardFormat(ClipboardFormatText)).toBe(false);
|
|
350
357
|
await writeClipboardText('x');
|
|
351
|
-
expect(await hasClipboardFormat(
|
|
358
|
+
expect(await hasClipboardFormat(ClipboardFormatText)).toBe(true);
|
|
352
359
|
});
|
|
353
360
|
});
|
|
354
361
|
|
|
@@ -402,22 +409,22 @@ describe('readClipboard', () => {
|
|
|
402
409
|
setClipboardBackend(backend);
|
|
403
410
|
await writeClipboardText('hello');
|
|
404
411
|
await writeClipboardHtml('<b>hello</b>');
|
|
405
|
-
const result = await readClipboard([
|
|
406
|
-
expect(result[
|
|
407
|
-
expect(result[
|
|
412
|
+
const result = await readClipboard([ClipboardFormatText, ClipboardFormatHtml]);
|
|
413
|
+
expect(result[ClipboardFormatText]).toBe('hello');
|
|
414
|
+
expect(result[ClipboardFormatHtml]).toBe('<b>hello</b>');
|
|
408
415
|
});
|
|
409
416
|
|
|
410
417
|
it('omits formats that are not present', async () => {
|
|
411
418
|
const backend = fakeBackend();
|
|
412
419
|
setClipboardBackend(backend);
|
|
413
420
|
await writeClipboardText('hi');
|
|
414
|
-
const result = await readClipboard([
|
|
415
|
-
expect(result[
|
|
416
|
-
expect(result[
|
|
421
|
+
const result = await readClipboard([ClipboardFormatText, ClipboardFormatRtf]);
|
|
422
|
+
expect(result[ClipboardFormatText]).toBe('hi');
|
|
423
|
+
expect(result[ClipboardFormatRtf]).toBeUndefined();
|
|
417
424
|
});
|
|
418
425
|
|
|
419
426
|
it('returns {} from the web backend without throwing', async () => {
|
|
420
|
-
const result = await createWebClipboardBackend().readItems([
|
|
427
|
+
const result = await createWebClipboardBackend().readItems([ClipboardFormatText]);
|
|
421
428
|
expect(typeof result).toBe('object');
|
|
422
429
|
});
|
|
423
430
|
});
|
|
@@ -516,8 +523,8 @@ describe('writeClipboard', () => {
|
|
|
516
523
|
setClipboardBackend(backend);
|
|
517
524
|
expect(
|
|
518
525
|
await writeClipboard([
|
|
519
|
-
{ format:
|
|
520
|
-
{ format:
|
|
526
|
+
{ format: ClipboardFormatText, data: 'hello' },
|
|
527
|
+
{ format: ClipboardFormatHtml, data: '<b>hello</b>' },
|
|
521
528
|
]),
|
|
522
529
|
).toBe(true);
|
|
523
530
|
expect(backend.text).toBe('hello');
|
|
@@ -525,7 +532,7 @@ describe('writeClipboard', () => {
|
|
|
525
532
|
});
|
|
526
533
|
|
|
527
534
|
it('returns false from the web backend without throwing', async () => {
|
|
528
|
-
expect(await createWebClipboardBackend().writeItems([{ format:
|
|
535
|
+
expect(await createWebClipboardBackend().writeItems([{ format: ClipboardFormatText, data: 'x' }])).toBe(false);
|
|
529
536
|
});
|
|
530
537
|
});
|
|
531
538
|
|