@farm.js/react 0.1.0-beta.0 → 0.1.0-beta.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/README.md +277 -11
- package/dist/compiler-runtime.cjs +1290 -17
- package/dist/compiler-runtime.cjs.map +1 -1
- package/dist/compiler-runtime.d.mts +132 -5
- package/dist/compiler-runtime.d.ts +132 -5
- package/dist/compiler-runtime.mjs +1290 -17
- package/dist/compiler-runtime.mjs.map +1 -1
- package/dist/index.cjs +24 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.mjs +24 -2
- package/dist/index.mjs.map +1 -1
- package/dist/list.cjs +27 -0
- package/dist/list.cjs.map +1 -0
- package/dist/list.d.mts +20 -0
- package/dist/list.d.ts +20 -0
- package/dist/list.mjs +21 -0
- package/dist/list.mjs.map +1 -0
- package/dist/vite.cjs +2332 -140
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +2332 -140
- package/dist/vite.mjs.map +1 -1
- package/package.json +10 -4
package/dist/list.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
interface ListProps<Item> {
|
|
4
|
+
/** Items to render. Nullish collections are treated as empty. */
|
|
5
|
+
each: Iterable<Item> | null | undefined;
|
|
6
|
+
/** Returns the stable React key for one item. */
|
|
7
|
+
by(item: Item, index: number): React.Key;
|
|
8
|
+
/** Renders one keyed row. */
|
|
9
|
+
children(item: Item, index: number): React.ReactElement;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* An explicit keyed collection boundary for advanced list expressions.
|
|
13
|
+
*
|
|
14
|
+
* It behaves like ordinary React when the compiler is disabled. With the
|
|
15
|
+
* experimental compiler enabled, eligible usages are isolated so local list
|
|
16
|
+
* updates do not execute the surrounding user component.
|
|
17
|
+
*/
|
|
18
|
+
declare function List<Item>({ each, by, children }: ListProps<Item>): React.ReactElement;
|
|
19
|
+
|
|
20
|
+
export { List, type ListProps };
|
package/dist/list.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
// src/list.tsx
|
|
4
|
+
function List({ each, by, children }) {
|
|
5
|
+
const rows = each ? Array.from(each) : [];
|
|
6
|
+
return React.createElement(
|
|
7
|
+
React.Fragment,
|
|
8
|
+
null,
|
|
9
|
+
...rows.map((item, index) => {
|
|
10
|
+
const row = children(item, index);
|
|
11
|
+
if (!React.isValidElement(row)) {
|
|
12
|
+
throw new TypeError("@farm.js/react List children must return one React element.");
|
|
13
|
+
}
|
|
14
|
+
return React.cloneElement(row, { key: by(item, index) });
|
|
15
|
+
})
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { List };
|
|
20
|
+
//# sourceMappingURL=list.mjs.map
|
|
21
|
+
//# sourceMappingURL=list.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/list.tsx"],"names":[],"mappings":";;;AAkBO,SAAS,IAAA,CAAW,EAAE,IAAA,EAAM,EAAA,EAAI,UAAS,EAAwC;AACtF,EAAA,MAAM,OAAO,IAAA,GAAO,KAAA,CAAM,IAAA,CAAK,IAAI,IAAI,EAAC;AACxC,EAAA,OAAO,KAAA,CAAM,aAAA;AAAA,IACX,KAAA,CAAM,QAAA;AAAA,IACN,IAAA;AAAA,IACA,GAAG,IAAA,CAAK,GAAA,CAAI,CAAC,MAAM,KAAA,KAAU;AAC3B,MAAA,MAAM,GAAA,GAAM,QAAA,CAAS,IAAA,EAAM,KAAK,CAAA;AAChC,MAAA,IAAI,CAAC,KAAA,CAAM,cAAA,CAAe,GAAG,CAAA,EAAG;AAC9B,QAAA,MAAM,IAAI,UAAU,6DAA6D,CAAA;AAAA,MACnF;AACA,MAAA,OAAO,KAAA,CAAM,aAAa,GAAA,EAAK,EAAE,KAAK,EAAA,CAAG,IAAA,EAAM,KAAK,CAAA,EAAuB,CAAA;AAAA,IAC7E,CAAC;AAAA,GACH;AACF","file":"list.mjs","sourcesContent":["import React from \"react\";\n\nexport interface ListProps<Item> {\n /** Items to render. Nullish collections are treated as empty. */\n each: Iterable<Item> | null | undefined;\n /** Returns the stable React key for one item. */\n by(item: Item, index: number): React.Key;\n /** Renders one keyed row. */\n children(item: Item, index: number): React.ReactElement;\n}\n\n/**\n * An explicit keyed collection boundary for advanced list expressions.\n *\n * It behaves like ordinary React when the compiler is disabled. With the\n * experimental compiler enabled, eligible usages are isolated so local list\n * updates do not execute the surrounding user component.\n */\nexport function List<Item>({ each, by, children }: ListProps<Item>): React.ReactElement {\n const rows = each ? Array.from(each) : [];\n return React.createElement(\n React.Fragment,\n null,\n ...rows.map((item, index) => {\n const row = children(item, index);\n if (!React.isValidElement(row)) {\n throw new TypeError(\"@farm.js/react List children must return one React element.\");\n }\n return React.cloneElement(row, { key: by(item, index) } as React.Attributes);\n }),\n );\n}\n"]}
|