Skip to content

Commit e22f85f

Browse files
committed
wip
1 parent cd077ef commit e22f85f

File tree

8 files changed

+33
-17
lines changed

8 files changed

+33
-17
lines changed

ghcjs/miso-functora/js/main.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,8 @@ export async function insertStorage(key, value) {
2929
}
3030

3131
export async function selectClipboard() {
32-
const { type, value } = await Clipboard.read();
33-
if (type.startsWith("text")) {
34-
return value;
35-
} else {
36-
const { buffer: u8a, typeFull: mime } = dataUriToBuffer(value);
37-
const blob = new Blob([u8a, { type: mime }]);
38-
return URL.createObjectURL(blob);
39-
}
32+
const { value } = await Clipboard.read();
33+
return value;
4034
}
4135

4236
export async function openBrowserPage(url) {
@@ -103,4 +97,10 @@ export function isNativePlatform() {
10397
return Capacitor.isNativePlatform();
10498
}
10599

100+
export function newBlobUrl(value) {
101+
const { buffer: u8a, typeFull: mime } = dataUriToBuffer(value);
102+
const blob = new Blob([u8a, { type: mime }]);
103+
return URL.createObjectURL(blob);
104+
}
105+
106106
defineCustomElements(window);

ghcjs/miso-functora/js/main.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ghcjs/miso-functora/src/Functora/Miso/Jsm/Generic.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Functora.Miso.Jsm.Generic
1313
genericPromise,
1414
printCurrentPage,
1515
saveFile,
16+
newBlobUrl,
1617
)
1718
where
1819

@@ -213,3 +214,9 @@ saveFile name mime bs = do
213214
genericPromise @[JS.JSVal] @Unicode "saveFile" argv $ \case
214215
Nothing -> pure ()
215216
Just str -> popupText str
217+
218+
newBlobUrl :: Unicode -> JSM Unicode
219+
newBlobUrl blob = do
220+
pkg <- getPkg
221+
res <- pkg ^. JS.js1 ("newBlobUrl" :: Unicode) blob
222+
JS.fromJSVal res >>= maybe (throwString @String "Failure, bad result!") pure

ghcjs/miso-functora/src/Functora/Miso/Prelude.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Functora.Prelude as X hiding
1313
cons,
1414
field,
1515
)
16+
import Functora.Rfc2397 as X
1617
import Miso as X hiding
1718
( Key,
1819
Text,

ghcjs/miso-functora/test/Functora/Miso/TypesSpec.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import qualified Optics.Setter as Ops
88
import Test.Hspec
99
import Test.Hspec.QuickCheck
1010
import Test.QuickCheck.Instances ()
11-
import qualified Text.URI as URI
1211

1312
data Expr
1413
= Lit Int

pub/functora/src/functora-ghcjs.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ common pkg
123123
, uniplate
124124
, universum
125125
, unliftio
126+
, uri-encode
126127
, vector
127128
, witch-mini
128129
, with-utf8
@@ -184,6 +185,7 @@ library
184185
Functora.Qr
185186
Functora.QrOrphan
186187
Functora.Rates
188+
Functora.Rfc2397
187189
Functora.Tags
188190
Functora.Unicode
189191
Functora.Web
@@ -232,6 +234,7 @@ test-suite functora-ghcjs-test
232234
Functora.Tags.TestFgpt
233235
Functora.Tags.TestSing
234236
Functora.TagsSpec
237+
Functora.WebSpec
235238

236239
other-modules:
237240
Functora.Aes
@@ -246,6 +249,7 @@ test-suite functora-ghcjs-test
246249
Functora.Qr
247250
Functora.QrOrphan
248251
Functora.Rates
252+
Functora.Rfc2397
249253
Functora.Tags
250254
Functora.TagsFamily
251255
Functora.TagsOrphan

pub/functora/src/test/Functora/WebSpec.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ smaples =
1616
spec :: Spec
1717
spec = do
1818
it "encode/decode" . forM_ smaples $ \sample ->
19-
fmap Rfc2397.encode (Rfc2397.decode sample) `shouldBe` Just sample
19+
fmap Rfc2397.encodeRfc2397 (Rfc2397.decodeRfc2397 sample)
20+
`shouldBe` Just sample

pub/functora/src/web/Functora/Rfc2397.hs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module Functora.Rfc2397
22
( Media (..),
33
Encoding (..),
4-
encode,
5-
decode,
4+
encodeRfc2397,
5+
decodeRfc2397,
66
)
77
where
88

@@ -19,11 +19,15 @@ data Media = Media
1919
}
2020
deriving stock (Eq, Ord, Show, Data, Generic)
2121

22+
instance Binary Media
23+
2224
data Encoding = B64Encoding | UrlEncoding
2325
deriving stock (Eq, Ord, Show, Read, Data, Generic, Bounded, Enum)
2426

25-
encode :: Media -> String
26-
encode Media {mediaMime = mime, mediaBytes = bs, mediaEncoding = enc} =
27+
instance Binary Encoding
28+
29+
encodeRfc2397 :: Media -> String
30+
encodeRfc2397 Media {mediaMime = mime, mediaBytes = bs, mediaEncoding = enc} =
2731
"data:"
2832
<> mime
2933
<> ( case enc of
@@ -41,8 +45,8 @@ encode Media {mediaMime = mime, mediaBytes = bs, mediaEncoding = enc} =
4145
$ decodeUtf8Strict bs
4246
)
4347

44-
decode :: String -> Maybe Media
45-
decode url =
48+
decodeRfc2397 :: String -> Maybe Media
49+
decodeRfc2397 url =
4650
let (scheme, rest) = break (== ':') url
4751
in case rest of
4852
':' : contents | scheme == "data" -> decodeContents contents

0 commit comments

Comments
 (0)