@effect/platform-browser 0.3.1 → 0.3.2
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/Clipboard.d.ts +37 -0
- package/Clipboard.d.ts.map +1 -0
- package/Clipboard.js +34 -0
- package/Clipboard.js.map +1 -0
- package/internal/clipboard.d.ts +2 -0
- package/internal/clipboard.d.ts.map +1 -0
- package/internal/clipboard.js +67 -0
- package/internal/clipboard.js.map +1 -0
- package/mjs/Clipboard.mjs +22 -0
- package/mjs/Clipboard.mjs.map +1 -0
- package/mjs/internal/clipboard.mjs +56 -0
- package/mjs/internal/clipboard.mjs.map +1 -0
- package/package.json +2 -2
- package/src/Clipboard.ts +44 -0
- package/src/internal/clipboard.ts +71 -0
package/Clipboard.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import type { Tag } from "@effect/data/Context";
|
|
5
|
+
import type * as Effect from "@effect/io/Effect";
|
|
6
|
+
import type * as Layer from "@effect/io/Layer";
|
|
7
|
+
import type { PlatformError } from "@effect/platform/Error";
|
|
8
|
+
/**
|
|
9
|
+
* @since 1.0.0
|
|
10
|
+
* @category interface
|
|
11
|
+
*/
|
|
12
|
+
export interface Clipboard {
|
|
13
|
+
readonly read: Effect.Effect<never, PlatformError, ClipboardItems>;
|
|
14
|
+
readonly readString: Effect.Effect<never, PlatformError, string>;
|
|
15
|
+
readonly write: (items: ClipboardItems) => Effect.Effect<never, PlatformError, void>;
|
|
16
|
+
readonly writeString: (text: string) => Effect.Effect<never, PlatformError, void>;
|
|
17
|
+
readonly writeBlob: (blob: Blob) => Effect.Effect<never, PlatformError, void>;
|
|
18
|
+
readonly clear: Effect.Effect<never, PlatformError, void>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
* @category constructor
|
|
23
|
+
*/
|
|
24
|
+
export declare const make: (impl: Omit<Clipboard, "clear" | "writeBlob">) => Clipboard;
|
|
25
|
+
/**
|
|
26
|
+
* @since 1.0.0
|
|
27
|
+
* @category tag
|
|
28
|
+
*/
|
|
29
|
+
export declare const Clipboard: Tag<Clipboard, Clipboard>;
|
|
30
|
+
/**
|
|
31
|
+
* A layer that directly interfaces with the navigator.clipboard api
|
|
32
|
+
*
|
|
33
|
+
* @since 1.0.0
|
|
34
|
+
* @category layers
|
|
35
|
+
*/
|
|
36
|
+
export declare const layer: Layer.Layer<never, never, Clipboard>;
|
|
37
|
+
//# sourceMappingURL=Clipboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Clipboard.d.ts","sourceRoot":"","sources":["./src/Clipboard.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,KAAK,KAAK,MAAM,kBAAkB,CAAA;AAE9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAE3D;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,cAAc,CAAC,CAAA;IAClE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,CAAA;IAChE,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,CAAC,CAAA;IACpF,QAAQ,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,CAAC,CAAA;IACjF,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,CAAC,CAAA;IAC7E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,CAAC,CAAA;CAC1D;AAED;;;GAGG;AACH,eAAO,MAAM,IAAI,EAAE,CACjB,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,GAAG,WAAW,CAAC,KACzC,SAAyB,CAAA;AAE9B;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,SAAS,CAAgB,CAAA;AAEhE;;;;;GAKG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,CAAkB,CAAA"}
|
package/Clipboard.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.make = exports.layer = exports.Clipboard = void 0;
|
|
7
|
+
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform-browser/internal/clipboard"));
|
|
8
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
9
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
+
/**
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @since 1.0.0
|
|
16
|
+
* @category constructor
|
|
17
|
+
*/
|
|
18
|
+
const make = internal.make;
|
|
19
|
+
/**
|
|
20
|
+
* @since 1.0.0
|
|
21
|
+
* @category tag
|
|
22
|
+
*/
|
|
23
|
+
exports.make = make;
|
|
24
|
+
const Clipboard = internal.tag;
|
|
25
|
+
/**
|
|
26
|
+
* A layer that directly interfaces with the navigator.clipboard api
|
|
27
|
+
*
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
* @category layers
|
|
30
|
+
*/
|
|
31
|
+
exports.Clipboard = Clipboard;
|
|
32
|
+
const layer = internal.layer;
|
|
33
|
+
exports.layer = layer;
|
|
34
|
+
//# sourceMappingURL=Clipboard.js.map
|
package/Clipboard.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Clipboard.js","names":["internal","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","make","exports","Clipboard","tag","layer"],"sources":["./src/Clipboard.ts"],"sourcesContent":[null],"mappings":";;;;;;AAOA,IAAAA,QAAA,gBAAAC,uBAAA,eAAAC,OAAA;AAAuE,SAAAC,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA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AAAAH,OAAA,CAAAG,KAAA,GAAAA,KAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../src/internal/clipboard.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.tag = exports.make = exports.layer = void 0;
|
|
7
|
+
var _Context = /*#__PURE__*/require("@effect/data/Context");
|
|
8
|
+
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Effect"));
|
|
9
|
+
var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Layer"));
|
|
10
|
+
var PlatformError = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/Error"));
|
|
11
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
+
/** @internal */
|
|
14
|
+
const tag = /*#__PURE__*/(0, _Context.Tag)("@effect/platform-browser/Clipboard");
|
|
15
|
+
/** @internal */
|
|
16
|
+
exports.tag = tag;
|
|
17
|
+
const make = impl => tag.of({
|
|
18
|
+
...impl,
|
|
19
|
+
clear: impl.writeString(""),
|
|
20
|
+
writeBlob: blob => impl.write([new ClipboardItem({
|
|
21
|
+
[blob.type]: blob
|
|
22
|
+
})])
|
|
23
|
+
});
|
|
24
|
+
/** @internal */
|
|
25
|
+
exports.make = make;
|
|
26
|
+
const clipboardError = props => PlatformError.SystemError({
|
|
27
|
+
reason: "PermissionDenied",
|
|
28
|
+
module: "Clipboard",
|
|
29
|
+
...props
|
|
30
|
+
});
|
|
31
|
+
/** @internal */
|
|
32
|
+
const layer = /*#__PURE__*/Layer.succeed(tag, /*#__PURE__*/make({
|
|
33
|
+
read: /*#__PURE__*/Effect.tryPromise({
|
|
34
|
+
try: navigator.clipboard.read,
|
|
35
|
+
catch: () => clipboardError({
|
|
36
|
+
"message": "Unable to read from clipboard",
|
|
37
|
+
"method": "read",
|
|
38
|
+
"pathOrDescriptor": "layer"
|
|
39
|
+
})
|
|
40
|
+
}),
|
|
41
|
+
write: s => Effect.tryPromise({
|
|
42
|
+
try: () => navigator.clipboard.write(s),
|
|
43
|
+
catch: () => clipboardError({
|
|
44
|
+
"message": "Unable to write to clipboard",
|
|
45
|
+
"method": "write",
|
|
46
|
+
"pathOrDescriptor": "layer"
|
|
47
|
+
})
|
|
48
|
+
}),
|
|
49
|
+
readString: /*#__PURE__*/Effect.tryPromise({
|
|
50
|
+
try: navigator.clipboard.readText,
|
|
51
|
+
catch: () => clipboardError({
|
|
52
|
+
"message": "Unable to read a string from clipboard",
|
|
53
|
+
"method": "readString",
|
|
54
|
+
"pathOrDescriptor": "layer"
|
|
55
|
+
})
|
|
56
|
+
}),
|
|
57
|
+
writeString: text => Effect.tryPromise({
|
|
58
|
+
try: () => navigator.clipboard.writeText(text),
|
|
59
|
+
catch: () => clipboardError({
|
|
60
|
+
"message": "Unable to write a string to clipboard",
|
|
61
|
+
"method": "writeString",
|
|
62
|
+
"pathOrDescriptor": "layer"
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
}));
|
|
66
|
+
exports.layer = layer;
|
|
67
|
+
//# sourceMappingURL=clipboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipboard.js","names":["_Context","require","Effect","_interopRequireWildcard","Layer","PlatformError","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","tag","Tag","exports","make","impl","of","clear","writeString","writeBlob","blob","write","ClipboardItem","type","clipboardError","props","SystemError","reason","module","layer","succeed","read","tryPromise","try","navigator","clipboard","catch","s","readString","readText","text","writeText"],"sources":["../src/internal/clipboard.ts"],"sourcesContent":[null],"mappings":";;;;;;AAAA,IAAAA,QAAA,gBAAAC,OAAA;AACA,IAAAC,MAAA,gBAAAC,uBAAA,eAAAF,OAAA;AACA,IAAAG,KAAA,gBAAAD,uBAAA,eAAAF,OAAA;AAEA,IAAAI,aAAA,gBAAAF,uBAAA,eAAAF,OAAA;AAAuD,SAAAK,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,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+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as internal from "@effect/platform-browser/internal/clipboard";
|
|
5
|
+
/**
|
|
6
|
+
* @since 1.0.0
|
|
7
|
+
* @category constructor
|
|
8
|
+
*/
|
|
9
|
+
export const make = internal.make;
|
|
10
|
+
/**
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
* @category tag
|
|
13
|
+
*/
|
|
14
|
+
export const Clipboard = internal.tag;
|
|
15
|
+
/**
|
|
16
|
+
* A layer that directly interfaces with the navigator.clipboard api
|
|
17
|
+
*
|
|
18
|
+
* @since 1.0.0
|
|
19
|
+
* @category layers
|
|
20
|
+
*/
|
|
21
|
+
export const layer = internal.layer;
|
|
22
|
+
//# sourceMappingURL=Clipboard.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Clipboard.mjs","names":["internal","make","Clipboard","tag","layer"],"sources":["../src/Clipboard.ts"],"sourcesContent":[null],"mappings":"AAAA;;;AAOA,OAAO,KAAKA,QAAQ,MAAM,6CAA6C;AAgBvE;;;;AAIA,OAAO,MAAMC,IAAI,GAEAD,QAAQ,CAACC,IAAI;AAE9B;;;;AAIA,OAAO,MAAMC,SAAS,GAA8BF,QAAQ,CAACG,GAAG;AAEhE;;;;;;AAMA,OAAO,MAAMC,KAAK,GAAyCJ,QAAQ,CAACI,KAAK"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Tag } from "@effect/data/Context";
|
|
2
|
+
import * as Effect from "@effect/io/Effect";
|
|
3
|
+
import * as Layer from "@effect/io/Layer";
|
|
4
|
+
import * as PlatformError from "@effect/platform/Error";
|
|
5
|
+
/** @internal */
|
|
6
|
+
export const tag = /*#__PURE__*/Tag("@effect/platform-browser/Clipboard");
|
|
7
|
+
/** @internal */
|
|
8
|
+
export const make = impl => tag.of({
|
|
9
|
+
...impl,
|
|
10
|
+
clear: impl.writeString(""),
|
|
11
|
+
writeBlob: blob => impl.write([new ClipboardItem({
|
|
12
|
+
[blob.type]: blob
|
|
13
|
+
})])
|
|
14
|
+
});
|
|
15
|
+
/** @internal */
|
|
16
|
+
const clipboardError = props => PlatformError.SystemError({
|
|
17
|
+
reason: "PermissionDenied",
|
|
18
|
+
module: "Clipboard",
|
|
19
|
+
...props
|
|
20
|
+
});
|
|
21
|
+
/** @internal */
|
|
22
|
+
export const layer = /*#__PURE__*/Layer.succeed(tag, /*#__PURE__*/make({
|
|
23
|
+
read: /*#__PURE__*/Effect.tryPromise({
|
|
24
|
+
try: navigator.clipboard.read,
|
|
25
|
+
catch: () => clipboardError({
|
|
26
|
+
"message": "Unable to read from clipboard",
|
|
27
|
+
"method": "read",
|
|
28
|
+
"pathOrDescriptor": "layer"
|
|
29
|
+
})
|
|
30
|
+
}),
|
|
31
|
+
write: s => Effect.tryPromise({
|
|
32
|
+
try: () => navigator.clipboard.write(s),
|
|
33
|
+
catch: () => clipboardError({
|
|
34
|
+
"message": "Unable to write to clipboard",
|
|
35
|
+
"method": "write",
|
|
36
|
+
"pathOrDescriptor": "layer"
|
|
37
|
+
})
|
|
38
|
+
}),
|
|
39
|
+
readString: /*#__PURE__*/Effect.tryPromise({
|
|
40
|
+
try: navigator.clipboard.readText,
|
|
41
|
+
catch: () => clipboardError({
|
|
42
|
+
"message": "Unable to read a string from clipboard",
|
|
43
|
+
"method": "readString",
|
|
44
|
+
"pathOrDescriptor": "layer"
|
|
45
|
+
})
|
|
46
|
+
}),
|
|
47
|
+
writeString: text => Effect.tryPromise({
|
|
48
|
+
try: () => navigator.clipboard.writeText(text),
|
|
49
|
+
catch: () => clipboardError({
|
|
50
|
+
"message": "Unable to write a string to clipboard",
|
|
51
|
+
"method": "writeString",
|
|
52
|
+
"pathOrDescriptor": "layer"
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
}));
|
|
56
|
+
//# sourceMappingURL=clipboard.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clipboard.mjs","names":["Tag","Effect","Layer","PlatformError","tag","make","impl","of","clear","writeString","writeBlob","blob","write","ClipboardItem","type","clipboardError","props","SystemError","reason","module","layer","succeed","read","tryPromise","try","navigator","clipboard","catch","s","readString","readText","text","writeText"],"sources":["../../src/internal/clipboard.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,GAAG,QAAQ,sBAAsB;AAC1C,OAAO,KAAKC,MAAM,MAAM,mBAAmB;AAC3C,OAAO,KAAKC,KAAK,MAAM,kBAAkB;AAEzC,OAAO,KAAKC,aAAa,MAAM,wBAAwB;AAEvD;AACA,OAAO,MAAMC,GAAG,gBAAGJ,GAAG,CAAsB,oCAAoC,CAAC;AAEjF;AACA,OAAO,MAAMK,IAAI,GACfC,IAAsD,IAEtDF,GAAG,CAACG,EAAE,CAAC;EACL,GAAGD,IAAI;EACPE,KAAK,EAAEF,IAAI,CAACG,WAAW,CAAC,EAAE,CAAC;EAC3BC,SAAS,EAAGC,IAAU,IAAKL,IAAI,CAACM,KAAK,CAAC,CAAC,IAAIC,aAAa,CAAC;IAAE,CAACF,IAAI,CAACG,IAAI,GAAGH;EAAI,CAAE,CAAC,CAAC;CACjF,CAAC;AAEJ;AACA,MAAMI,cAAc,GAAIC,KAAiF,IACvGb,aAAa,CAACc,WAAW,CAAC;EACxBC,MAAM,EAAE,kBAAkB;EAC1BC,MAAM,EAAE,WAAW;EACnB,GAAGH;CACJ,CAAC;AAEJ;AACA,OAAO,MAAMI,KAAK,gBAAGlB,KAAK,CAACmB,OAAO,CAChCjB,GAAG,eACHC,IAAI,CAAC;EACHiB,IAAI,eAAErB,MAAM,CAACsB,UAAU,CAAC;IACtBC,GAAG,EAAEC,SAAS,CAACC,SAAS,CAACJ,IAAI;IAC7BK,KAAK,EAAEA,CAAA,KACLZ,cAAc,CAAC;MACb,SAAS,EAAE,+BAA+B;MAC1C,QAAQ,EAAE,MAAM;MAChB,kBAAkB,EAAE;KACrB;GACJ,CAAC;EACFH,KAAK,EAAGgB,CAAuB,IAC7B3B,MAAM,CAACsB,UAAU,CAAC;IAChBC,GAAG,EAAEA,CAAA,KAAMC,SAAS,CAACC,SAAS,CAACd,KAAK,CAACgB,CAAC,CAAC;IACvCD,KAAK,EAAEA,CAAA,KACLZ,cAAc,CAAC;MACb,SAAS,EAAE,8BAA8B;MACzC,QAAQ,EAAE,OAAO;MACjB,kBAAkB,EAAE;KACrB;GACJ,CAAC;EACJc,UAAU,eAAE5B,MAAM,CAACsB,UAAU,CAAC;IAC5BC,GAAG,EAAEC,SAAS,CAACC,SAAS,CAACI,QAAQ;IACjCH,KAAK,EAAEA,CAAA,KACLZ,cAAc,CAAC;MACb,SAAS,EAAE,wCAAwC;MACnD,QAAQ,EAAE,YAAY;MACtB,kBAAkB,EAAE;KACrB;GACJ,CAAC;EACFN,WAAW,EAAGsB,IAAY,IACxB9B,MAAM,CAACsB,UAAU,CAAC;IAChBC,GAAG,EAAEA,CAAA,KAAMC,SAAS,CAACC,SAAS,CAACM,SAAS,CAACD,IAAI,CAAC;IAC9CJ,KAAK,EAAEA,CAAA,KACLZ,cAAc,CAAC;MACb,SAAS,EAAE,uCAAuC;MAClD,QAAQ,EAAE,aAAa;MACvB,kBAAkB,EAAE;KACrB;GACJ;CACJ,CAAC,CACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/platform-browser",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Unified interfaces for common platform-specific services",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -27,6 +27,6 @@
|
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@effect/data": "^0.18.4",
|
|
29
29
|
"@effect/io": "^0.40.0",
|
|
30
|
-
"@effect/platform": "^0.15.
|
|
30
|
+
"@effect/platform": "^0.15.2"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/Clipboard.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 1.0.0
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Tag } from "@effect/data/Context"
|
|
6
|
+
import type * as Effect from "@effect/io/Effect"
|
|
7
|
+
import type * as Layer from "@effect/io/Layer"
|
|
8
|
+
import * as internal from "@effect/platform-browser/internal/clipboard"
|
|
9
|
+
import type { PlatformError } from "@effect/platform/Error"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @since 1.0.0
|
|
13
|
+
* @category interface
|
|
14
|
+
*/
|
|
15
|
+
export interface Clipboard {
|
|
16
|
+
readonly read: Effect.Effect<never, PlatformError, ClipboardItems>
|
|
17
|
+
readonly readString: Effect.Effect<never, PlatformError, string>
|
|
18
|
+
readonly write: (items: ClipboardItems) => Effect.Effect<never, PlatformError, void>
|
|
19
|
+
readonly writeString: (text: string) => Effect.Effect<never, PlatformError, void>
|
|
20
|
+
readonly writeBlob: (blob: Blob) => Effect.Effect<never, PlatformError, void>
|
|
21
|
+
readonly clear: Effect.Effect<never, PlatformError, void>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @since 1.0.0
|
|
26
|
+
* @category constructor
|
|
27
|
+
*/
|
|
28
|
+
export const make: (
|
|
29
|
+
impl: Omit<Clipboard, "clear" | "writeBlob">
|
|
30
|
+
) => Clipboard = internal.make
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @since 1.0.0
|
|
34
|
+
* @category tag
|
|
35
|
+
*/
|
|
36
|
+
export const Clipboard: Tag<Clipboard, Clipboard> = internal.tag
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A layer that directly interfaces with the navigator.clipboard api
|
|
40
|
+
*
|
|
41
|
+
* @since 1.0.0
|
|
42
|
+
* @category layers
|
|
43
|
+
*/
|
|
44
|
+
export const layer: Layer.Layer<never, never, Clipboard> = internal.layer
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Tag } from "@effect/data/Context"
|
|
2
|
+
import * as Effect from "@effect/io/Effect"
|
|
3
|
+
import * as Layer from "@effect/io/Layer"
|
|
4
|
+
import type * as Clipboard from "@effect/platform-browser/Clipboard"
|
|
5
|
+
import * as PlatformError from "@effect/platform/Error"
|
|
6
|
+
|
|
7
|
+
/** @internal */
|
|
8
|
+
export const tag = Tag<Clipboard.Clipboard>("@effect/platform-browser/Clipboard")
|
|
9
|
+
|
|
10
|
+
/** @internal */
|
|
11
|
+
export const make = (
|
|
12
|
+
impl: Omit<Clipboard.Clipboard, "clear" | "writeBlob">
|
|
13
|
+
): Clipboard.Clipboard =>
|
|
14
|
+
tag.of({
|
|
15
|
+
...impl,
|
|
16
|
+
clear: impl.writeString(""),
|
|
17
|
+
writeBlob: (blob: Blob) => impl.write([new ClipboardItem({ [blob.type]: blob })])
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
/** @internal */
|
|
21
|
+
const clipboardError = (props: Omit<Parameters<typeof PlatformError.SystemError>[0], "reason" | "module">) =>
|
|
22
|
+
PlatformError.SystemError({
|
|
23
|
+
reason: "PermissionDenied",
|
|
24
|
+
module: "Clipboard",
|
|
25
|
+
...props
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
/** @internal */
|
|
29
|
+
export const layer = Layer.succeed(
|
|
30
|
+
tag,
|
|
31
|
+
make({
|
|
32
|
+
read: Effect.tryPromise({
|
|
33
|
+
try: navigator.clipboard.read,
|
|
34
|
+
catch: () =>
|
|
35
|
+
clipboardError({
|
|
36
|
+
"message": "Unable to read from clipboard",
|
|
37
|
+
"method": "read",
|
|
38
|
+
"pathOrDescriptor": "layer"
|
|
39
|
+
})
|
|
40
|
+
}),
|
|
41
|
+
write: (s: Array<ClipboardItem>) =>
|
|
42
|
+
Effect.tryPromise({
|
|
43
|
+
try: () => navigator.clipboard.write(s),
|
|
44
|
+
catch: () =>
|
|
45
|
+
clipboardError({
|
|
46
|
+
"message": "Unable to write to clipboard",
|
|
47
|
+
"method": "write",
|
|
48
|
+
"pathOrDescriptor": "layer"
|
|
49
|
+
})
|
|
50
|
+
}),
|
|
51
|
+
readString: Effect.tryPromise({
|
|
52
|
+
try: navigator.clipboard.readText,
|
|
53
|
+
catch: () =>
|
|
54
|
+
clipboardError({
|
|
55
|
+
"message": "Unable to read a string from clipboard",
|
|
56
|
+
"method": "readString",
|
|
57
|
+
"pathOrDescriptor": "layer"
|
|
58
|
+
})
|
|
59
|
+
}),
|
|
60
|
+
writeString: (text: string) =>
|
|
61
|
+
Effect.tryPromise({
|
|
62
|
+
try: () => navigator.clipboard.writeText(text),
|
|
63
|
+
catch: () =>
|
|
64
|
+
clipboardError({
|
|
65
|
+
"message": "Unable to write a string to clipboard",
|
|
66
|
+
"method": "writeString",
|
|
67
|
+
"pathOrDescriptor": "layer"
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
)
|