Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F1374952
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/inputs/component-input.ts b/src/inputs/component-input.ts
index 0e0b22f..12c727c 100644
--- a/src/inputs/component-input.ts
+++ b/src/inputs/component-input.ts
@@ -1,157 +1,162 @@
import { printArgPath } from "./print-arg-path.js";
import type { Context } from "koa";
import type { ComponentArgument, JDDContext, TableData } from "@sealcode/jdd";
import { SingleReference } from "@sealcode/jdd";
import {
ComponentArguments,
Enum,
Image,
List,
Structured,
Table,
} from "@sealcode/jdd";
import { ComponentInputStructured } from "./component-input-structured.js";
import type { StatefulPage } from "@sealcode/sealgen";
import type { ComponentPreviewActions } from "../component-preview-actions.js";
import { ComponentInputList } from "./component-input-list.js";
import type { JDDPageState } from "../jdd-page.js";
import { ComponentInputEnum } from "./component-input-enum.js";
import { ComponentInputImage } from "./component-input-image.js";
import { ComponentInputTable } from "./component-input-table.js";
import type { FilePointer } from "@sealcode/file-manager";
import { ComponentInputSingleReference } from "./component-input-single-reference.js";
import { is, predicates } from "@sealcode/ts-predicates";
export const actionName = "Components";
const absoluteUrlPattern = "http(s?)(://)((www.)?)(([^.]+).)?([a-zA-z0-9-_]+)";
export async function ComponentInput<State extends JDDPageState, T>({
ctx,
state,
arg_path,
arg,
value,
page,
makeJDDContext,
makeAssetURL,
}: {
state: State;
ctx: Context;
arg_path: string[];
arg: ComponentArgument<T>;
value: T;
page: StatefulPage<JDDPageState, typeof ComponentPreviewActions>;
makeJDDContext: (ctx: Context) => JDDContext;
makeAssetURL: (asset: string) => string;
}): Promise<string> {
if (value === undefined) {
value = await arg.getEmptyValue(makeJDDContext(ctx));
}
if (arg instanceof List) {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
return ComponentInputList({
ctx,
state,
arg_path,
arg,
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
value: value as T[],
page,
makeJDDContext,
makeAssetURL,
});
}
const argType = arg.getTypeName();
const isUrlAbsolute =
arg instanceof ComponentArguments.URL && arg.urlType === "absolute";
const inputType = isUrlAbsolute ? "url" : "text";
if (arg instanceof Structured) {
return ComponentInputStructured({
ctx,
state,
arg_path,
arg,
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
value: value as Record<string, unknown>,
page,
makeJDDContext,
makeAssetURL,
});
}
if (arg instanceof SingleReference) {
return ComponentInputSingleReference({
ctx,
state,
arg_path,
arg,
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
value: value as string,
onchange: page.rerender(),
makeJDDContext,
});
}
if (arg instanceof Enum) {
return ComponentInputEnum({
state,
arg_path,
arg,
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
value: value as string,
onchange: page.rerender(),
});
}
if (arg instanceof Image) {
return ComponentInputImage({
ctx,
state,
arg_path,
arg,
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
value: value as FilePointer,
page,
makeJDDContext,
});
}
if (arg instanceof Table) {
return ComponentInputTable({
ctx,
state,
arg_path,
arg,
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
value: value as TableData<unknown, unknown>,
page,
makeJDDContext,
makeAssetURL,
});
}
return /* HTML */ `<div>
<label>
${arg_path.at(-1) || ""}
${argType == "markdown"
? /* HTML */ `<div class="grow-wrap">
<textarea
name="${`$${printArgPath(arg_path)}`}"
onblur="${page.rerender()}"
cols="40"
data-controller="markdown-textarea submit-on-input"
data-action="autogrow-textarea#autogrow blur->autogrow-textarea#autogrow resize->autogrow-textarea#autogrow submit-on-input#sendValues focus->submit-on-input#makePermanent blur->submit-on-input#makeNotPermanent"
autocomplete="off"
>
${is(value, predicates.string) ? value : ""}</textarea
>
</div>`
- : /* HTML */ `<input type="${inputType}"
- name="${`$${printArgPath(arg_path)}`}"
- value="${is(value, predicates.string) ? value : ""}" size="40"
- ${isUrlAbsolute ? `pattern="${absoluteUrlPattern}"` : ""}" />`}
+ : /* HTML */ `<input
+ type="${inputType}"
+ name="${`$${printArgPath(arg_path)}`}"
+ value="${is(value, predicates.string) ? value : ""}"
+ size="40"
+ ${isUrlAbsolute
+ ? `pattern="${absoluteUrlPattern}"`
+ : ""}
+ />`}
</label>
</div>`;
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Wed, Feb 26, 01:46 (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
610626
Default Alt Text
(4 KB)
Attached To
Mode
rJDDE jdd-editor
Attached
Detach File
Event Timeline
Log In to Comment