Skip to content

Commit

Permalink
upd: add list component
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX committed Nov 12, 2023
1 parent 4bf3e9d commit 4543da8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/block-data/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ export default {
],
),

list: component(
"List",
"ListModel",
content("inner", "as-socket", Direction.BOTTOM),
input("data", "iterable"),
output("current", "unknown", "as-socket", Direction.RIGHT),
[],
[],
[],
[textProp("class"), textProp("key", "$index")],
),

forEach: component(
"For each",
"ForEachModel",
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ export * from "./div.r";
export * from "./forEach.r";
export * from "./ifElse.r";
export * from "./input.r";
export * from "./list.r";
export * from "./paragraph.r";
export * from "./span.r";
export * from "./textNode.r";

import QuasiRuntime from "./plugin";
export default QuasiRuntime;

import * as refina from "refina";
export { refina };
export * as refina from "refina";
31 changes: 31 additions & 0 deletions packages/runtime/src/list.r.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ComponentContext, Content, OutputComponent, byIndex, byProp, bySelf } from "refina";
import QuasiRuntime from "./plugin";

export interface ListProps {
inner: Content;
class: string;
data: Iterable<any>;
key: string;
}

export class ListModel {
current: any;
}

@QuasiRuntime.outputComponent("list")
export class QList extends OutputComponent {
main(_: ComponentContext<this>, model: ListModel, props: ListProps): void {
_.$cls(props.class);
_.mdList(props.data, props.key === "$index" ? byIndex : props.key === "$self" ? bySelf : byProp(props.key), v => {
model.current = v;
_.embed(props.inner);
});
model.current = null;
}
}

declare module "refina" {
interface OutputComponents {
list: QList;
}
}

0 comments on commit 4543da8

Please sign in to comment.