ilha 0.14.2 → 0.14.4

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.
@@ -0,0 +1,89 @@
1
+ import * as AsyncResult from "effect/unstable/reactivity/AsyncResult";
2
+ import * as Option from "effect/Option";
3
+ import * as Result from "effect/Result";
4
+
5
+ //#region src/errors.ts
6
+ const asFailure = (e) => {
7
+ if (Result.isResult(e) && Result.isFailure(e)) {
8
+ const v = Option.getOrUndefined(Result.getFailure(e));
9
+ return Result.fail(v instanceof Error ? v : new Error(String(v)));
10
+ }
11
+ return Result.fail(e instanceof Error ? e : new Error(String(e)));
12
+ };
13
+ const failureMessage = (e) => asFailure(e).pipe(Result.match({
14
+ onFailure: (err) => err.message,
15
+ onSuccess: () => "error"
16
+ }));
17
+
18
+ //#endregion
19
+ //#region src/shared.ts
20
+ const KEY_ATTR = "data-ilha-key";
21
+ const SLOT_ATTR = "data-ilha-slot";
22
+ const ISLAND = Symbol.for("ilha.island");
23
+ const ISLAND_MOUNT_INTERNAL = Symbol.for("ilha.islandMountInternal");
24
+ const ISLAND_SLOT_TAG = Symbol.for("ilha.islandSlotTag");
25
+ const objectTag = (value) => Object.prototype.toString.call(value);
26
+ const isBoolean = (value) => value === true || value === false;
27
+ const isString = (value) => objectTag(value) === "[object String]";
28
+ const isNumber = (value) => objectTag(value) === "[object Number]";
29
+ const isBigInt = (value) => objectTag(value) === "[object BigInt]";
30
+ const isFunction = (value) => {
31
+ const tag = objectTag(value);
32
+ return tag === "[object Function]" || tag === "[object AsyncFunction]" || tag === "[object GeneratorFunction]";
33
+ };
34
+ const isObject = (value) => value !== null && objectTag(value) === "[object Object]";
35
+ const skip = (x) => x === null || x === void 0 || isBoolean(x);
36
+ const KEEP = Symbol("ilha.keep");
37
+ const unwrap = (value, keep) => {
38
+ if (AsyncResult.isAsyncResult(value)) {
39
+ if (AsyncResult.isWaiting(value) && keep !== void 0) return KEEP;
40
+ if (AsyncResult.isFailure(value) && !AsyncResult.isWaiting(value)) return String(AsyncResult.error(value) ?? "error");
41
+ const v = AsyncResult.value(value);
42
+ if (v._tag === "Some") return v.value;
43
+ return "";
44
+ }
45
+ return value;
46
+ };
47
+ const errorView = (e) => ({
48
+ $$ilha: 1,
49
+ children: [failureMessage(e)],
50
+ props: { "data-ilha-error": "" },
51
+ type: "pre"
52
+ });
53
+
54
+ //#endregion
55
+ //#region src/types.ts
56
+ const Fragment = Symbol("ilha.Fragment");
57
+
58
+ //#endregion
59
+ //#region src/vnode.ts
60
+ const flatten = (xs) => {
61
+ const out = [];
62
+ for (const x of xs) if (Array.isArray(x)) out.push(...flatten(x));
63
+ else out.push(x);
64
+ return out;
65
+ };
66
+ const h = (type, props, ...rest) => {
67
+ const p = { ...props };
68
+ const fromProps = p.children;
69
+ const { key: rawKey, ...restProps } = p;
70
+ return {
71
+ $$ilha: 1,
72
+ children: flatten([...fromProps === void 0 ? [] : [fromProps], ...rest]),
73
+ key: rawKey,
74
+ props: restProps,
75
+ type
76
+ };
77
+ };
78
+ const isVNode = (x) => {
79
+ if (!isObject(x)) return false;
80
+ return x.$$ilha === 1;
81
+ };
82
+ const isSetupFn = (x) => {
83
+ if (!isFunction(x)) return false;
84
+ const n = x.constructor?.name;
85
+ return n === "GeneratorFunction" || n === "AsyncFunction";
86
+ };
87
+
88
+ //#endregion
89
+ export { skip as _, ISLAND as a, failureMessage as b, KEEP as c, errorView as d, isBigInt as f, isString as g, isObject as h, Fragment as i, KEY_ATTR as l, isNumber as m, isSetupFn as n, ISLAND_MOUNT_INTERNAL as o, isFunction as p, isVNode as r, ISLAND_SLOT_TAG as s, h as t, SLOT_ATTR as u, unwrap as v, asFailure as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ilha",
3
- "version": "0.14.2",
3
+ "version": "0.14.4",
4
4
  "description": "Generator-first island UI on Effect",
5
5
  "keywords": [
6
6
  "effect",
@@ -60,7 +60,8 @@
60
60
  "scripts": {
61
61
  "build": "tsdown",
62
62
  "cleanup": "rimraf dist node_modules",
63
- "test": "bun test"
63
+ "test": "bun test",
64
+ "typecheck": "tsc -p tsconfig.types.json --noEmit"
64
65
  },
65
66
  "devDependencies": {
66
67
  "@happy-dom/global-registrator": "^20.11.2",