-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24c14d7
commit 107bacd
Showing
14 changed files
with
135 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
{ | ||
"name": "astro-flow-demo", | ||
"type": "module", | ||
"version": "0.3.5", | ||
"version": "0.3.6", | ||
"private": true, | ||
"scripts": { | ||
"start": "astro dev", | ||
"build": "astro build", | ||
"serve": "astro preview" | ||
}, | ||
"devDependencies": { | ||
"@astropub/flow": "0.3.5", | ||
"@astropub/flow": "0.3.6", | ||
"astro": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,11 @@ | ||
export { HTMLString } from './lib/HTMLString.d' | ||
export { iterate } from './lib/iterate.d' | ||
export { Iterate } from './lib/iterate-component.d' | ||
export { Iterate as For } from './lib/iterate-component.d' | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
export function Case<T>(props: CaseProps<T>): any | ||
export function Switch(props: SwitchProps): any | ||
|
||
export interface SwitchProps { | ||
of: any | ||
export { default as Iterate, Props as IterateProps } from './lib/AstroIterate.astro.d' | ||
export { default as For, Props as ForProps } from './lib/AstroIterate.astro.d' | ||
export { default as Switch, Props as SwitchProps } from './lib/AstroSwitch.d' | ||
export { default as Case, Props as CaseProps } from './lib/AstroCase.d' | ||
export { default as When, Props as WhenProps } from './lib/AstroWhen.d' | ||
|
||
declare module '@astropub/flow/Iterate' { | ||
export * from './lib/AstroIterate.astro.d' | ||
} | ||
|
||
export type CaseProps<T> = ( | ||
'of' extends keyof T | ||
? T['of'] extends (string | number | bigint | boolean | symbol | null | undefined) | ||
? { | ||
of: T | ||
} | ||
: T['of'] extends ((value: unknown) => boolean) | ||
? { | ||
of: T | ||
} | ||
: T['of'] extends object | ||
? { | ||
of: T | ||
} | ||
: never | ||
: 'default' extends keyof T | ||
? { | ||
default: "" | true | ||
} | ||
: any | ||
) | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
||
export function When(props: WhenProps): any | ||
|
||
type WhenProps = Record<any, any> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export { HTMLString } from './lib/HTMLString.js' | ||
export { iterate } from './lib/iterate.js' | ||
export { Iterate } from './lib/iterate-component.js' | ||
export { Iterate as For } from './lib/iterate-component.js' | ||
|
||
export { default as Iterate } from './lib/AstroIterate.astro' | ||
export { default as For } from './lib/AstroIterate.astro' | ||
export { default as Case } from './lib/AstroCase.astro' | ||
export { default as Switch } from './lib/AstroSwitch.astro' | ||
export { default as When } from './lib/AstroWhen.astro' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export type Props<T> = 'of' extends keyof T | ||
? T['of'] extends (string | number | bigint | boolean | symbol | null | undefined) | ||
? { | ||
of: T | ||
} | ||
: T['of'] extends ((value: unknown) => boolean) | ||
? { | ||
of: T | ||
} | ||
: T['of'] extends object | ||
? { | ||
of: T | ||
} | ||
: never | ||
: 'default' extends keyof T | ||
? { | ||
default: "" | true | ||
} | ||
: any | ||
|
||
export default function Case<T>(props: Props<T>): any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export default function For<T>(props: Props<T>): any | ||
|
||
export type Props<T> = { | ||
[K in keyof T]: K extends 'children' ? unknown : T[K] | ||
} & { | ||
children?: { | ||
(item: IterableValue<T[Exclude<keyof T, 'children'>]>): any | ||
} | ||
} | ||
|
||
type IterableValue<T> = T extends Array<infer P> | ||
? P | ||
: T extends AsyncGenerator<infer P, unknown, unknown> | ||
? P | ||
: T extends Generator<infer P, unknown, unknown> | ||
? P | ||
: never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { getNormalizedGenerator, isIterable } from './shared.js' | ||
|
||
export default Object.assign( | ||
function Iterate(_result, attributes, slots) { | ||
const promiseOfGenerator = Promise.resolve( | ||
typeof slots.default === 'function' | ||
? slots.default() | ||
: slots.default | ||
).then( | ||
(result) => result.expressions.at(0) | ||
).then( | ||
(result) => getNormalizedGenerator(result), | ||
() => null | ||
) | ||
|
||
const iterables = Object.values(attributes) | ||
|
||
return { | ||
[Symbol.toStringTag]: 'AstroComponent', | ||
|
||
async *[Symbol.asyncIterator]() { | ||
const generator = await promiseOfGenerator | ||
|
||
for (const iterable of iterables) { | ||
if (isIterable(iterable)) { | ||
for await (const element of iterable) { | ||
yield * generator(element) | ||
} | ||
} | ||
} | ||
}, | ||
} | ||
}, | ||
{ | ||
isAstroComponentFactory: true | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface Props { | ||
of: any | ||
} | ||
|
||
export default function Switch(props: Props): any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type Props = Record<any, any> | ||
|
||
export default function When(props: Props): any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class HTMLString extends String { | ||
get [Symbol.toStringTag](): string | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters