Page MenuHomeSealhub

No OneTemporary

Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
diff --git a/src/component-arguments.ts b/src/component-arguments.ts
index dd2b723..b1db7cc 100644
--- a/src/component-arguments.ts
+++ b/src/component-arguments.ts
@@ -1,151 +1,151 @@
export type ExtractComponentArgumentValue<C> = C extends ComponentArgument<
infer T
>
? T
: never;
export type ExtractStructuredComponentArgumentsValues<C> = {
[property in keyof C]: ExtractComponentArgumentValue<C[property]>;
};
export type T = ExtractComponentArgumentValue<Structured<any>>;
export abstract class ComponentArgument<ARG extends any> {
ARG!: ARG; // this is for some reason necessary to make the ExtractComponentArgumentValue work. It seems like this argument has to appear somewhere in the structure of the class to make it work. Possibly it can be made into some function argument or smth
abstract getTypeName(): string;
abstract getEmptyValue(): ARG;
abstract getExampleValue(): ARG;
}
export class ShortText extends ComponentArgument<string> {
getTypeName() {
return "short-text";
}
getEmptyValue() {
return "";
}
getExampleValue() {
return "Lorem ipsum set deloris";
}
}
export class MarkdownArgument extends ComponentArgument<string> {
getTypeName() {
return "markdown";
}
getEmptyValue() {
return "";
}
getExampleValue() {
- return `*Lorem ipsum* dolor sit amet, **consectetur adipiscing elit**, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Posuere lorem ipsum dolor sit amet consectetur adipiscing elit. Porttitor massa id neque aliquam vestibulum. Turpis egestas pretium aenean pharetra.
+ return `*Lorem ipsum* dolor sit amet, **consectetur adipiscing elit**, sed [do eiusmod](#) tempor incididunt ut labore et dolore magna aliqua. Posuere lorem ipsum dolor sit amet consectetur adipiscing elit. Porttitor massa id neque aliquam vestibulum. Turpis egestas pretium aenean pharetra.
Ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue. Tellus cras adipiscing enim eu turpis egestas. Sagittis id consectetur purus ut faucibus pulvinar elementum. Pulvinar etiam non quam lacus suspendisse. Viverra adipiscing at in tellus integer feugiat scelerisque. Ultricies leo integer malesuada nunc vel risus commodo. Morbi leo urna molestie at elementum. Justo laoreet sit amet cursus sit amet. `;
}
}
export class List<
T extends ComponentArgument<unknown>
> extends ComponentArgument<Array<ExtractComponentArgumentValue<T>>> {
constructor(public item_type: T) {
super();
}
getTypeName() {
return "list";
}
getEmptyValue() {
return [];
}
getExampleValue() {
return [this.item_type.getExampleValue() as any];
}
}
export class Structured<
T extends Record<string, ComponentArgument<unknown>>
> extends ComponentArgument<{
[property in keyof T]: ExtractComponentArgumentValue<T[property]>;
}> {
constructor(public structure: T) {
super();
}
getTypeName() {
return "structured";
}
getEmptyValue() {
return Object.fromEntries(
Object.entries(this.structure).map(([name, arg]) => [
name,
arg.getEmptyValue(),
])
) as {
[property in keyof T]: ExtractComponentArgumentValue<T[property]>;
};
}
getExampleValue() {
return Object.fromEntries(
Object.entries(this.structure).map(([name, arg]) => [
name,
arg.getExampleValue(),
])
) as {
[property in keyof T]: ExtractComponentArgumentValue<T[property]>;
};
}
}
export class Enum<T extends string> extends ComponentArgument<T> {
public readonly values: Readonly<T[]>;
constructor(values: Readonly<T[]>) {
super();
this.values = values;
}
getTypeName() {
return "enum";
}
getEmptyValue() {
return this.values[0];
}
getExampleValue() {
return this.values[Math.floor(Math.random() * this.values.length)];
}
}
export class Image extends ComponentArgument<string> {
constructor(public path_to_image_on_fs: string) {
super();
}
getTypeName() {
return "image";
}
getEmptyValue() {
return "";
}
getExampleValue() {
return "";
}
}
export const ComponentArguments = {
Image,
Structured,
List,
Markdown: MarkdownArgument,
ShortText,
Enum,
};

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 28, 03:15 (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1230145
Default Alt Text
(4 KB)

Event Timeline