@inlay/core 0.0.1 → 0.0.3

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/dist/index.d.ts CHANGED
@@ -1,12 +1,21 @@
1
1
  import type { l } from "@atproto/lex";
2
- type Node = {
3
- type: l.NsidString;
4
- props?: l.UnknownObject;
5
- };
6
- type LexiconModule = {
7
- readonly $nsid: l.NsidString;
2
+ import { type Node, type LexiconComponent } from "./node.ts";
3
+ export { type Node, isValidNode } from "./node.ts";
4
+ type LexiconModule = LexiconComponent & {
8
5
  readonly main: l.Procedure;
9
6
  };
10
- export declare function $<M extends LexiconModule>(mod: M, props?: Omit<l.InferMethodInputBody<M["main"]>, "children">, children?: (Node | string | number | false | null | undefined)[]): Node;
11
- export {};
7
+ type Child = Node | string | number | boolean | null | undefined | Child[];
8
+ type Props<M extends LexiconModule> = Omit<l.InferMethodInputBody<M["main"]>, "children"> & {
9
+ children?: Child;
10
+ };
11
+ export type Component<M extends LexiconModule> = M & ((props: Props<M>) => Node);
12
+ export declare function jslex<T>(namespace: T): {
13
+ [K in keyof T]: T[K] extends LexiconModule ? Component<T[K]> : T[K];
14
+ };
15
+ type Config<M extends LexiconModule> = Omit<l.InferMethodInputBody<M["main"]>, "children"> & {
16
+ key?: string;
17
+ };
18
+ export declare function $<M extends LexiconModule>(mod: M, config?: Config<M>, ...children: Child[]): Node;
19
+ export declare function stringifyNode(node: Node, indent?: number): string;
20
+ export declare function parseNode<T = Node>(json: string): T;
12
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAGtC,KAAK,IAAI,GAAG;IACV,IAAI,EAAE,CAAC,CAAC,UAAU,CAAC;IACnB,KAAK,CAAC,EAAE,CAAC,CAAC,aAAa,CAAC;CACzB,CAAC;AAEF,K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,CAAC,KAAK,IAAI,CAAC,CAAC;AAE9B,wBAAgB,KAAK,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,GAAG;KACrC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,aAAa,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACpE,CAEA;AAID,KAAK,MAAM,CAAC,CAAC,SAAS,aAAa,IAAI,IAAI,CACzC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EACjC,UAAU,CACX,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAErB,wBAAgB,CAAC,CAAC,CAAC,SAAS,aAAa,EACvC,GAAG,EAAE,CAAC,EACN,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAClB,GAAG,QAAQ,EAAE,KAAK,EAAE,GACnB,IAAI,CAON;AA0BD,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,wBAAgB,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAEnD"}
package/dist/index.js CHANGED
@@ -3,17 +3,55 @@
3
3
  // Usage:
4
4
  // import { Stack } from "@/generated/org/design";
5
5
  // import { Post } from "@/generated/com/example";
6
- // import { $ } from "@inlay/core";
6
+ // import { $, parseNode } from "@inlay/core";
7
7
  //
8
- // $(Stack, { gap: "medium" }, [
8
+ // $(Stack, { gap: "medium" },
9
+ // $(Post, { uri: 'at://...' }),
9
10
  // $(Post, { uri: 'at://...' })
10
- // ])
11
+ // )
12
+ //
13
+ // Serialization:
14
+ // stringifyNode(node) // serializes with brand encoding
15
+ // parseNode(json) // restores branded nodes
11
16
  //
12
17
  // Node types are NSIDs (e.g., "com.example.Post")
13
- export function $(mod, props, children) {
14
- const finalProps = children != null ? { ...props, children } : props;
15
- return {
16
- type: mod.$nsid,
17
- props: finalProps,
18
- };
18
+ import { BRAND, createNode, keyStaticChildren, } from "./node.js";
19
+ export { isValidNode } from "./node.js";
20
+ export function jslex(namespace) {
21
+ return namespace;
22
+ }
23
+ export function $(mod, config, ...children) {
24
+ const { key, ...rest } = config ?? {};
25
+ const props = children.length > 0
26
+ ? { ...rest, children: keyStaticChildren(children) }
27
+ : rest;
28
+ return createNode(mod.$nsid, key, props);
29
+ }
30
+ function replacer(key, value) {
31
+ if (key === "$") {
32
+ if (value === BRAND) {
33
+ return "$";
34
+ }
35
+ if (typeof value === "string" && value.startsWith("$")) {
36
+ return "$" + value;
37
+ }
38
+ }
39
+ return value;
40
+ }
41
+ function reviver(key, value) {
42
+ if (key === "$") {
43
+ if (value === "$") {
44
+ return BRAND;
45
+ }
46
+ if (typeof value === "string" && value.startsWith("$$")) {
47
+ return value.slice(1);
48
+ }
49
+ }
50
+ return value;
51
+ }
52
+ export function stringifyNode(node, indent) {
53
+ return JSON.stringify(node, replacer, indent);
54
+ }
55
+ export function parseNode(json) {
56
+ return JSON.parse(json, reviver);
19
57
  }
@@ -0,0 +1,6 @@
1
+ import type { l } from "@atproto/lex";
2
+ import type { Node, LexiconComponent } from "./node.ts";
3
+ import { Fragment } from "./jsx-runtime.ts";
4
+ export { Fragment };
5
+ export declare function jsxDEV(type: LexiconComponent, props: l.UnknownObject | null, key?: string, isStaticChildren?: boolean): Node;
6
+ //# sourceMappingURL=jsx-dev-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-dev-runtime.d.ts","sourceRoot":"","sources":["../src/jsx-dev-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAa,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,QAAQ,EAAE,CAAC;AAEpB,wBAAgB,MAAM,CACpB,IAAI,EAAE,gBAAgB,EACtB,KAAK,EAAE,CAAC,CAAC,aAAa,GAAG,IAAI,EAC7B,GAAG,CAAC,EAAE,MAAM,EACZ,gBAAgB,CAAC,EAAE,OAAO,GACzB,IAAI,CAEN"}
@@ -0,0 +1,5 @@
1
+ import { jsx, jsxs, Fragment } from "./jsx-runtime.js";
2
+ export { Fragment };
3
+ export function jsxDEV(type, props, key, isStaticChildren) {
4
+ return isStaticChildren ? jsxs(type, props, key) : jsx(type, props, key);
5
+ }
@@ -0,0 +1,8 @@
1
+ import type { l } from "@atproto/lex";
2
+ import { type Node, type LexiconComponent } from "./node.ts";
3
+ export declare function jsx(type: LexiconComponent, props: l.UnknownObject | null, key?: string): Node;
4
+ export declare function jsxs(type: LexiconComponent, props: l.UnknownObject | null, key?: string): Node;
5
+ export declare function Fragment(_props: {
6
+ children?: unknown;
7
+ }): never;
8
+ //# sourceMappingURL=jsx-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx-runtime.d.ts","sourceRoot":"","sources":["../src/jsx-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACL,KAAK,IAAI,EACT,KAAK,gBAAgB,EAGtB,MAAM,WAAW,CAAC;AAEnB,wBAAgB,GAAG,CACjB,IAAI,EAAE,gBAAgB,EACtB,KAAK,EAAE,CAAC,CAAC,aAAa,GAAG,IAAI,EAC7B,GAAG,CAAC,EAAE,MAAM,GACX,IAAI,CAEN;AAED,wBAAgB,IAAI,CAClB,IAAI,EAAE,gBAAgB,EACtB,KAAK,EAAE,CAAC,CAAC,aAAa,GAAG,IAAI,EAC7B,GAAG,CAAC,EAAE,MAAM,GACX,IAAI,CAQN;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,KAAK,CAE9D"}
@@ -0,0 +1,16 @@
1
+ import { createNode, keyStaticChildren, } from "./node.js";
2
+ export function jsx(type, props, key) {
3
+ return createNode(type.$nsid, key, props);
4
+ }
5
+ export function jsxs(type, props, key) {
6
+ if (props?.children === undefined) {
7
+ return createNode(type.$nsid, key, props);
8
+ }
9
+ return createNode(type.$nsid, key, {
10
+ ...props,
11
+ children: keyStaticChildren(props.children),
12
+ });
13
+ }
14
+ export function Fragment(_props) {
15
+ throw new Error("Fragment is not supported");
16
+ }
package/dist/node.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { l } from "@atproto/lex";
2
+ export declare const BRAND: unique symbol;
3
+ export type Node = {
4
+ type: l.NsidString;
5
+ key?: string;
6
+ props?: l.UnknownObject;
7
+ };
8
+ export type LexiconComponent = {
9
+ readonly $nsid: l.NsidString;
10
+ };
11
+ export declare function createNode(type: l.NsidString, key?: string, props?: l.UnknownObject | null): Node;
12
+ export declare function isValidNode(value: unknown): value is Node;
13
+ export declare function keyStaticChildren<T>(children: T): T;
14
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAEtC,eAAO,MAAM,KAAK,eAAkB,CAAC;AAErC,MAAM,MAAM,IAAI,GAAG;IACjB,IAAI,EAAE,CAAC,CAAC,UAAU,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,CAAC,CAAC,aAAa,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,UAAU,CAAC;CAC9B,CAAC;AAEF,wBAAgB,UAAU,CACxB,IAAI,EAAE,CAAC,CAAC,UAAU,EAClB,GAAG,CAAC,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,CAAC,CAAC,aAAa,GAAG,IAAI,GAC7B,IAAI,CAEN;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAMzD;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAYnD"}
package/dist/node.js ADDED
@@ -0,0 +1,20 @@
1
+ export const BRAND = Symbol.for("$");
2
+ export function createNode(type, key, props) {
3
+ return { $: BRAND, type, key, props: props ?? undefined };
4
+ }
5
+ export function isValidNode(value) {
6
+ return (typeof value === "object" &&
7
+ value !== null &&
8
+ value.$ === BRAND);
9
+ }
10
+ export function keyStaticChildren(children) {
11
+ if (Array.isArray(children)) {
12
+ return children.map((child, i) => isValidNode(child) && child.key == null
13
+ ? { ...child, key: String(i) }
14
+ : child);
15
+ }
16
+ if (isValidNode(children) && children.key == null) {
17
+ return { ...children, key: "0" };
18
+ }
19
+ return children;
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inlay/core",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "author": "Dan Abramov <dan.abramov@gmail.com>",
6
6
  "license": "MIT",
@@ -10,6 +10,14 @@
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
12
  "import": "./dist/index.js"
13
+ },
14
+ "./jsx-runtime": {
15
+ "types": "./dist/jsx-runtime.d.ts",
16
+ "import": "./dist/jsx-runtime.js"
17
+ },
18
+ "./jsx-dev-runtime": {
19
+ "types": "./dist/jsx-dev-runtime.d.ts",
20
+ "import": "./dist/jsx-dev-runtime.js"
13
21
  }
14
22
  },
15
23
  "files": [