Skip to content

Build your personal knowledge base with Trilium Notes

feat(labels): Add textarea label type with Table support

Mystler5b5222b84688
diff --git a/apps/client/src/services/promoted_attribute_definition_parser.ts b/apps/client/src/services/promoted_attribute_definition_parser.ts
index 0d93aae3c5..b589d45986 100644
--- a/apps/client/src/services/promoted_attribute_definition_parser.ts
+++ b/apps/client/src/services/promoted_attribute_definition_parser.ts
@@ -1,4 +1,4 @@
-export type LabelType = "text" | "number" | "boolean" | "date" | "datetime" | "time" | "url" | "color";
+export type LabelType = "text" | "textarea" | "number" | "boolean" | "date" | "datetime" | "time" | "url" | "color";
type Multiplicity = "single" | "multi";
export interface DefinitionObject {
@@ -17,7 +17,7 @@ function parse(value: string) {
for (const token of tokens) {
if (token === "promoted") {
defObj.isPromoted = true;
- } else if (["text", "number", "boolean", "date", "datetime", "time", "url", "color"].includes(token)) {
+ } else if (["text", "textarea", "number", "boolean", "date", "datetime", "time", "url", "color"].includes(token)) {
defObj.labelType = token as LabelType;
} else if (["single", "multi"].includes(token)) {
defObj.multiplicity = token as Multiplicity;
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 07f7b10de0..14595237af 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -343,6 +343,7 @@
"label_type_title": "Type of the label will help Trilium to choose suitable interface to enter the label value.",
"label_type": "Type",
"text": "Text",
+ "textarea": "Textarea",
"number": "Number",
"boolean": "Boolean",
"date": "Date",
diff --git a/apps/client/src/widgets/PromotedAttributes.tsx b/apps/client/src/widgets/PromotedAttributes.tsx
index 1e0bdeb474..47b6fa2432 100644
--- a/apps/client/src/widgets/PromotedAttributes.tsx
+++ b/apps/client/src/widgets/PromotedAttributes.tsx
@@ -2,7 +2,7 @@ import "./PromotedAttributes.css";
import { UpdateAttributeResponse } from "@triliumnext/commons";
import clsx from "clsx";
-import { ComponentChild, HTMLInputTypeAttribute, InputHTMLAttributes, MouseEventHandler, TargetedEvent, TargetedInputEvent } from "preact";
+import { ComponentChild, createElement, HTMLInputTypeAttribute, InputHTMLAttributes, MouseEventHandler, TargetedEvent, TargetedInputEvent } from "preact";
import { Dispatch, StateUpdater, useCallback, useEffect, useRef, useState } from "preact/hooks";
import NoteContext from "../components/note_context";
@@ -36,7 +36,7 @@ interface CellProps {
setCellToFocus(cell: Cell): void;
}
-type OnChangeEventData = TargetedEvent<HTMLInputElement, Event> | InputEvent | JQuery.TriggeredEvent<HTMLInputElement, undefined, HTMLInputElement, HTMLInputElement>;
+type OnChangeEventData = TargetedEvent<HTMLInputElement | HTMLTextAreaElement, Event> | InputEvent | JQuery.TriggeredEvent<HTMLInputElement, undefined, HTMLInputElement, HTMLInputElement>;
type OnChangeListener = (e: OnChangeEventData) => void | Promise<void>;
export default function PromotedAttributes() {
@@ -173,6 +173,7 @@ function PromotedAttributeCell(props: CellProps) {
const LABEL_MAPPINGS: Record<LabelType, HTMLInputTypeAttribute> = {
text: "text",
+ textarea: "text",
number: "number",
boolean: "checkbox",
date: "date",
@@ -226,20 +227,21 @@ function LabelInput(props: CellProps & { inputId: string }) {
}
}
- const inputNode = <input
- className="form-control promoted-attribute-input"
- tabIndex={200 + definitionAttr.position}
- id={inputId}
- type={LABEL_MAPPINGS[definition.labelType ?? "text"]}
- value={valueDraft}
- checked={definition.labelType === "boolean" ? valueAttr.value === "true" : undefined}
- placeholder={t("promoted_attributes.unset-field-placeholder")}
- data-attribute-id={valueAttr.attributeId}
- data-attribute-type={valueAttr.type}
- data-attribute-name={valueAttr.name}
- onBlur={onChangeListener}
- {...extraInputProps}
- />;
+
+ const inputNode = createElement(definition.labelType === "textarea" ? "textarea" : "input", {
+ className: "form-control promoted-attribute-input",
+ tabIndex: 200 + definitionAttr.position,
+ id: inputId,
+ type: LABEL_MAPPINGS[definition.labelType ?? "text"],
+ value: valueDraft,
+ checked: definition.labelType === "boolean" ? valueAttr.value === "true" : undefined,
+ placeholder: t("promoted_attributes.unset-field-placeholder"),
+ "data-attribute-id": valueAttr.attributeId,
+ "data-attribute-type": valueAttr.type,
+ "data-attribute-name": valueAttr.name,
+ onBlur: onChangeListener,
+ ...extraInputProps
+ });
if (definition.labelType === "boolean") {
return <>
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.ts b/apps/client/src/widgets/attribute_widgets/attribute_detail.ts
index 607af49952..452c6aecc3 100644
--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.ts
+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.ts
@@ -137,6 +137,7 @@ const TPL = /*html*/`
<td>
<select class="attr-input-label-type form-control">
<option value="text">${t("attribute_detail.text")}</option>
+ <option value="textarea">${t("attribute_detail.textarea")}</option>
<option value="number">${t("attribute_detail.number")}</option>
<option value="boolean">${t("attribute_detail.boolean")}</option>
<option value="date">${t("attribute_detail.date")}</option>
diff --git a/apps/client/src/widgets/collections/table/columns.tsx b/apps/client/src/widgets/collections/table/columns.tsx
index 74db6ddb71..bf2adf6761 100644
--- a/apps/client/src/widgets/collections/table/columns.tsx
+++ b/apps/client/src/widgets/collections/table/columns.tsx
@@ -19,6 +19,13 @@ const labelTypeMappings: Record<ColumnType, Partial<ColumnDefinition>> = {
text: {
editor: "input"
},
+ textarea: {
+ editor: "textarea",
+ formatter: "textarea",
+ editorParams: {
+ shiftEnterSubmit: true
+ }
+ },
boolean: {
formatter: "tickCross",
editor: "tickCross"
diff --git a/apps/server/src/services/promoted_attribute_definition_parser.ts b/apps/server/src/services/promoted_attribute_definition_parser.ts
index 630c57a729..9d94be5eda 100644
--- a/apps/server/src/services/promoted_attribute_definition_parser.ts
+++ b/apps/server/src/services/promoted_attribute_definition_parser.ts
@@ -7,7 +7,7 @@ function parse(value: string): DefinitionObject {
for (const token of tokens) {
if (token === "promoted") {
defObj.isPromoted = true;
- } else if (["text", "number", "boolean", "date", "datetime", "time", "url"].includes(token)) {
+ } else if (["text", "textarea", "number", "boolean", "date", "datetime", "time", "url"].includes(token)) {
defObj.labelType = token;
} else if (["single", "multi"].includes(token)) {
defObj.multiplicity = token;