foldkit 0.9.0-canary.0 → 0.10.0-canary.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/README.md +12 -8
- package/dist/runtime/addNavigationEventListeners.js +15 -33
- package/dist/runtime/urlRequest.d.ts +3 -3
- package/dist/runtime/urlRequest.d.ts.map +1 -1
- package/dist/schema.d.ts +0 -17
- package/dist/schema.d.ts.map +1 -1
- package/dist/url.d.ts +1 -1
- package/dist/url.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,22 +8,26 @@
|
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
+
The best way to get started with Foldkit is to use `create-foldkit-app`. This
|
|
12
|
+
will guide you through creating a new Foldkit project with your preferred
|
|
13
|
+
package manager and example template.
|
|
14
|
+
|
|
11
15
|
```bash
|
|
12
|
-
|
|
16
|
+
npx create-foldkit-app@latest --wizard
|
|
13
17
|
```
|
|
14
18
|
|
|
15
19
|
## Counter Example
|
|
16
20
|
|
|
17
|
-
```
|
|
21
|
+
```ts
|
|
18
22
|
import { Match as M, Schema } from 'effect'
|
|
19
23
|
import { Runtime } from 'foldkit'
|
|
20
24
|
import { Class, Html, OnClick, button, div } from 'foldkit/html'
|
|
21
|
-
import {
|
|
25
|
+
import { ts } from 'foldkit/schema'
|
|
22
26
|
|
|
23
27
|
// MODEL
|
|
24
28
|
|
|
25
29
|
const Model = Schema.Number
|
|
26
|
-
type Model =
|
|
30
|
+
type Model = typeof Model.Type
|
|
27
31
|
|
|
28
32
|
// MESSAGE
|
|
29
33
|
|
|
@@ -33,11 +37,11 @@ const Reset = ts('Reset')
|
|
|
33
37
|
|
|
34
38
|
const Message = Schema.Union(Decrement, Increment, Reset)
|
|
35
39
|
|
|
36
|
-
type Decrement =
|
|
37
|
-
type Increment =
|
|
38
|
-
type Reset =
|
|
40
|
+
type Decrement = typeof Decrement.Type
|
|
41
|
+
type Increment = typeof Increment.Type
|
|
42
|
+
type Reset = typeof Reset.Type
|
|
39
43
|
|
|
40
|
-
type Message =
|
|
44
|
+
type Message = typeof Message.Type
|
|
41
45
|
|
|
42
46
|
// UPDATE
|
|
43
47
|
|
|
@@ -8,17 +8,7 @@ export const addNavigationEventListeners = (messageQueue, browserConfig) => {
|
|
|
8
8
|
};
|
|
9
9
|
const addPopStateListener = (messageQueue, browserConfig) => {
|
|
10
10
|
const onPopState = () => {
|
|
11
|
-
|
|
12
|
-
const hash = StringExt.stripPrefixNonEmpty('#')(window.location.hash);
|
|
13
|
-
const newUrl = {
|
|
14
|
-
protocol: window.location.protocol,
|
|
15
|
-
host: window.location.host,
|
|
16
|
-
port: OptionExt.fromString(window.location.port),
|
|
17
|
-
pathname: window.location.pathname,
|
|
18
|
-
search,
|
|
19
|
-
hash,
|
|
20
|
-
};
|
|
21
|
-
Queue.unsafeOffer(messageQueue, browserConfig.onUrlChange(newUrl));
|
|
11
|
+
Queue.unsafeOffer(messageQueue, browserConfig.onUrlChange(locationToUrl()));
|
|
22
12
|
};
|
|
23
13
|
window.addEventListener('popstate', onPopState);
|
|
24
14
|
};
|
|
@@ -44,33 +34,25 @@ const addLinkClickListener = (messageQueue, browserConfig) => {
|
|
|
44
34
|
Queue.unsafeOffer(messageQueue, browserConfig.onUrlRequest(External.make({ href })));
|
|
45
35
|
return;
|
|
46
36
|
}
|
|
47
|
-
|
|
48
|
-
const url = {
|
|
49
|
-
protocol,
|
|
50
|
-
host,
|
|
51
|
-
port: OptionExt.fromString(port),
|
|
52
|
-
pathname,
|
|
53
|
-
search: StringExt.stripPrefixNonEmpty('?')(search),
|
|
54
|
-
hash: StringExt.stripPrefixNonEmpty('#')(hash),
|
|
55
|
-
};
|
|
56
|
-
Queue.unsafeOffer(messageQueue, browserConfig.onUrlRequest(Internal.make({ url })));
|
|
37
|
+
Queue.unsafeOffer(messageQueue, browserConfig.onUrlRequest(Internal.make({ url: urlToFoldkitUrl(linkUrl) })));
|
|
57
38
|
};
|
|
58
39
|
document.addEventListener('click', onLinkClick);
|
|
59
40
|
};
|
|
60
41
|
const addProgrammaticNavigationListener = (messageQueue, browserConfig) => {
|
|
61
42
|
const onProgrammaticNavigation = () => {
|
|
62
|
-
|
|
63
|
-
const hash = StringExt.stripPrefixNonEmpty('#')(window.location.hash);
|
|
64
|
-
const { location: { protocol, host, port, pathname }, } = window;
|
|
65
|
-
const newUrl = {
|
|
66
|
-
protocol,
|
|
67
|
-
host,
|
|
68
|
-
port: OptionExt.fromString(port),
|
|
69
|
-
pathname,
|
|
70
|
-
search,
|
|
71
|
-
hash,
|
|
72
|
-
};
|
|
73
|
-
Queue.unsafeOffer(messageQueue, browserConfig.onUrlChange(newUrl));
|
|
43
|
+
Queue.unsafeOffer(messageQueue, browserConfig.onUrlChange(locationToUrl()));
|
|
74
44
|
};
|
|
75
45
|
window.addEventListener('foldkit:urlchange', onProgrammaticNavigation);
|
|
76
46
|
};
|
|
47
|
+
const urlToFoldkitUrl = (url) => {
|
|
48
|
+
const { protocol, hostname, port, pathname, search, hash } = url;
|
|
49
|
+
return {
|
|
50
|
+
protocol,
|
|
51
|
+
host: hostname,
|
|
52
|
+
port: OptionExt.fromString(port),
|
|
53
|
+
pathname,
|
|
54
|
+
search: StringExt.stripPrefixNonEmpty('?')(search),
|
|
55
|
+
hash: StringExt.stripPrefixNonEmpty('#')(hash),
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const locationToUrl = () => urlToFoldkitUrl(new URL(window.location.href));
|
|
@@ -9,11 +9,11 @@ export declare const Internal: S.TaggedStruct<"Internal", {
|
|
|
9
9
|
hash: S.OptionFromSelf<typeof S.String>;
|
|
10
10
|
}>;
|
|
11
11
|
}>;
|
|
12
|
-
export type Internal =
|
|
12
|
+
export type Internal = typeof Internal.Type;
|
|
13
13
|
export declare const External: S.TaggedStruct<"External", {
|
|
14
14
|
href: typeof S.String;
|
|
15
15
|
}>;
|
|
16
|
-
export type External =
|
|
16
|
+
export type External = typeof External.Type;
|
|
17
17
|
export declare const UrlRequest: S.Union<[S.TaggedStruct<"Internal", {
|
|
18
18
|
url: S.Struct<{
|
|
19
19
|
protocol: typeof S.String;
|
|
@@ -26,5 +26,5 @@ export declare const UrlRequest: S.Union<[S.TaggedStruct<"Internal", {
|
|
|
26
26
|
}>, S.TaggedStruct<"External", {
|
|
27
27
|
href: typeof S.String;
|
|
28
28
|
}>]>;
|
|
29
|
-
export type UrlRequest =
|
|
29
|
+
export type UrlRequest = typeof UrlRequest.Type;
|
|
30
30
|
//# sourceMappingURL=urlRequest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlRequest.d.ts","sourceRoot":"","sources":["../../src/runtime/urlRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAA;AAIpC,eAAO,MAAM,QAAQ;;;;;;;;;EAEnB,CAAA;AACF,MAAM,MAAM,QAAQ,GAAG,
|
|
1
|
+
{"version":3,"file":"urlRequest.d.ts","sourceRoot":"","sources":["../../src/runtime/urlRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAA;AAIpC,eAAO,MAAM,QAAQ;;;;;;;;;EAEnB,CAAA;AACF,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAA;AAE3C,eAAO,MAAM,QAAQ;;EAEnB,CAAA;AACF,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAA;AAE3C,eAAO,MAAM,UAAU;;;;;;;;;;;IAA8B,CAAA;AACrD,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,IAAI,CAAA"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -17,21 +17,4 @@ export declare const ts: {
|
|
|
17
17
|
<Tag extends string>(tag: Tag): S.TaggedStruct<Tag, {}>;
|
|
18
18
|
<Tag extends string, Fields extends S.Struct.Fields>(tag: Tag, fields: Fields): S.TaggedStruct<Tag, Fields>;
|
|
19
19
|
};
|
|
20
|
-
/**
|
|
21
|
-
* Extracts the TypeScript type from an Effect Schema.
|
|
22
|
-
*
|
|
23
|
-
* Abbreviated as `ST` (Schema Type) because it's used frequently throughout Foldkit applications.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* const Model = S.Struct({ count: S.Number })
|
|
28
|
-
* type Model = ST<typeof Model> // { count: number }
|
|
29
|
-
*
|
|
30
|
-
* const Reset = ts('Reset')
|
|
31
|
-
* type Reset = ST<typeof Reset> // { _tag: "Reset" }
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @template T - The Schema to extract the type from
|
|
35
|
-
*/
|
|
36
|
-
export type ST<T> = S.Schema.Type<T>;
|
|
37
20
|
//# sourceMappingURL=schema.d.ts.map
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAA;AAEpC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,EAAE,EAAE;IACf,CAAC,GAAG,SAAS,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,YAAY,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IACvD,CAAC,GAAG,SAAS,MAAM,EAAE,MAAM,SAAS,CAAC,CAAC,MAAM,CAAC,MAAM,EACjD,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,GACb,CAAC,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;CAEG,CAAA
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAA;AAEpC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,EAAE,EAAE;IACf,CAAC,GAAG,SAAS,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,YAAY,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;IACvD,CAAC,GAAG,SAAS,MAAM,EAAE,MAAM,SAAS,CAAC,CAAC,MAAM,CAAC,MAAM,EACjD,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,GACb,CAAC,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;CAEG,CAAA"}
|
package/dist/url.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare const Url: S.Struct<{
|
|
|
7
7
|
search: S.OptionFromSelf<typeof S.String>;
|
|
8
8
|
hash: S.OptionFromSelf<typeof S.String>;
|
|
9
9
|
}>;
|
|
10
|
-
export type Url =
|
|
10
|
+
export type Url = typeof Url.Type;
|
|
11
11
|
export declare const fromString: (str: string) => Option.Option<{
|
|
12
12
|
readonly search: Option.Option<string>;
|
|
13
13
|
readonly protocol: string;
|
package/dist/url.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAe,MAAM,IAAI,CAAC,EAAU,MAAM,QAAQ,CAAA;AAIzE,eAAO,MAAM,GAAG;;;;;;;EAOd,CAAA;AACF,MAAM,MAAM,GAAG,GAAG,
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../src/url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAe,MAAM,IAAI,CAAC,EAAU,MAAM,QAAQ,CAAA;AAIzE,eAAO,MAAM,GAAG;;;;;;;EAOd,CAAA;AACF,MAAM,MAAM,GAAG,GAAG,OAAO,GAAG,CAAC,IAAI,CAAA;AAyEjC,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM;;;;;;;EAAuC,CAAA;AAC7E,eAAO,MAAM,QAAQ,GAAI,KAAK,GAAG,WAAqC,CAAA"}
|