2025-12-11 19:17:23 +02:00
|
|
|
import { t } from "i18next";
|
2025-12-11 18:53:48 +02:00
|
|
|
import FNote from "../../entities/fnote";
|
|
|
|
|
import { ViewTypeOptions } from "../collections/interface";
|
|
|
|
|
import Dropdown from "../react/Dropdown";
|
2025-12-11 19:34:22 +02:00
|
|
|
import { FormDropdownDivider, FormDropdownSubmenu, FormListItem, FormListToggleableItem } from "../react/FormList";
|
2025-12-11 18:59:28 +02:00
|
|
|
import Icon from "../react/Icon";
|
2025-12-11 18:53:48 +02:00
|
|
|
import { useViewType, VIEW_TYPE_MAPPINGS } from "../ribbon/CollectionPropertiesTab";
|
2025-12-11 19:51:40 +02:00
|
|
|
import { bookPropertiesConfig, BookProperty, ButtonProperty, CheckBoxProperty, NumberProperty, SplitButtonProperty } from "../ribbon/collection-properties-config";
|
|
|
|
|
import { useNoteLabel, useNoteLabelBoolean } from "../react/hooks";
|
2025-12-11 19:29:27 +02:00
|
|
|
import { useContext } from "preact/hooks";
|
|
|
|
|
import { ParentComponent } from "../react/react_utils";
|
2025-12-11 19:51:40 +02:00
|
|
|
import FormTextBox from "../react/FormTextBox";
|
2025-12-11 18:53:48 +02:00
|
|
|
|
2025-12-11 18:59:28 +02:00
|
|
|
const ICON_MAPPINGS: Record<ViewTypeOptions, string> = {
|
|
|
|
|
grid: "bx bxs-grid",
|
|
|
|
|
list: "bx bx-list-ul",
|
|
|
|
|
calendar: "bx bx-calendar",
|
|
|
|
|
table: "bx bx-table",
|
|
|
|
|
geoMap: "bx bx-map-alt",
|
|
|
|
|
board: "bx bx-columns",
|
|
|
|
|
presentation: "bx bx-rectangle"
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-11 18:53:48 +02:00
|
|
|
export default function CollectionProperties({ note }: { note: FNote }) {
|
2025-12-11 19:29:27 +02:00
|
|
|
const [ viewType, setViewType ] = useViewType(note);
|
|
|
|
|
|
2025-12-11 18:53:48 +02:00
|
|
|
return (
|
2025-12-11 19:17:23 +02:00
|
|
|
<>
|
2025-12-11 19:29:27 +02:00
|
|
|
<ViewTypeSwitcher note={note} viewType={viewType} setViewType={setViewType} />
|
|
|
|
|
<ViewOptions note={note} viewType={viewType} />
|
2025-12-11 19:17:23 +02:00
|
|
|
</>
|
2025-12-11 18:53:48 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-11 19:29:27 +02:00
|
|
|
function ViewTypeSwitcher({ note, viewType, setViewType }: { note: FNote, viewType: ViewTypeOptions, setViewType: (newValue: ViewTypeOptions) => void }) {
|
2025-12-11 18:53:48 +02:00
|
|
|
return (
|
|
|
|
|
<Dropdown
|
2025-12-11 18:59:28 +02:00
|
|
|
text={<>
|
|
|
|
|
<Icon icon={ICON_MAPPINGS[viewType]} />
|
|
|
|
|
{VIEW_TYPE_MAPPINGS[viewType]}
|
|
|
|
|
</>}
|
2025-12-11 18:53:48 +02:00
|
|
|
>
|
|
|
|
|
{Object.entries(VIEW_TYPE_MAPPINGS).map(([ key, label ]) => (
|
|
|
|
|
<FormListItem
|
|
|
|
|
key={key}
|
2025-12-11 19:29:27 +02:00
|
|
|
onClick={() => setViewType(key as ViewTypeOptions)}
|
2025-12-11 18:59:28 +02:00
|
|
|
selected={viewType === key}
|
|
|
|
|
disabled={viewType === key}
|
|
|
|
|
icon={ICON_MAPPINGS[key as ViewTypeOptions]}
|
2025-12-11 18:53:48 +02:00
|
|
|
>{label}</FormListItem>
|
|
|
|
|
))}
|
|
|
|
|
</Dropdown>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-12-11 19:17:23 +02:00
|
|
|
|
2025-12-11 19:29:27 +02:00
|
|
|
function ViewOptions({ note, viewType }: { note: FNote, viewType: ViewTypeOptions }) {
|
|
|
|
|
const properties = bookPropertiesConfig[viewType].properties;
|
|
|
|
|
|
2025-12-11 19:17:23 +02:00
|
|
|
return (
|
|
|
|
|
<Dropdown
|
|
|
|
|
buttonClassName="bx bx-cog icon-action"
|
|
|
|
|
hideToggleArrow
|
|
|
|
|
>
|
2025-12-11 19:39:07 +02:00
|
|
|
{properties.map(property => (
|
|
|
|
|
<ViewProperty key={property} note={note} property={property} />
|
|
|
|
|
))}
|
|
|
|
|
{properties.length > 0 && <FormDropdownDivider />}
|
|
|
|
|
|
2025-12-11 19:17:23 +02:00
|
|
|
<ViewProperty note={note} property={{
|
|
|
|
|
type: "checkbox",
|
2025-12-11 19:44:22 +02:00
|
|
|
icon: "bx bx-archive",
|
2025-12-11 19:17:23 +02:00
|
|
|
label: t("book_properties.include_archived_notes"),
|
|
|
|
|
bindToLabel: "includeArchived"
|
|
|
|
|
} as CheckBoxProperty} />
|
|
|
|
|
</Dropdown>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ViewProperty({ note, property }: { note: FNote, property: BookProperty }) {
|
|
|
|
|
switch (property.type) {
|
2025-12-11 19:29:27 +02:00
|
|
|
case "button":
|
|
|
|
|
return <ButtonPropertyView note={note} property={property} />;
|
2025-12-11 19:34:22 +02:00
|
|
|
case "split-button":
|
|
|
|
|
return <SplitButtonPropertyView note={note} property={property} />;
|
2025-12-11 19:17:23 +02:00
|
|
|
case "checkbox":
|
|
|
|
|
return <CheckBoxPropertyView note={note} property={property} />;
|
2025-12-11 19:51:40 +02:00
|
|
|
case "number":
|
|
|
|
|
return <NumberPropertyView note={note} property={property} />;
|
2025-12-11 19:17:23 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-11 19:29:27 +02:00
|
|
|
function ButtonPropertyView({ note, property }: { note: FNote, property: ButtonProperty }) {
|
|
|
|
|
const parentComponent = useContext(ParentComponent);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<FormListItem
|
|
|
|
|
icon={property.icon}
|
|
|
|
|
title={property.title}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
if (!parentComponent) return;
|
|
|
|
|
property.onClick({
|
|
|
|
|
note,
|
|
|
|
|
triggerCommand: parentComponent.triggerCommand.bind(parentComponent)
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>{property.label}</FormListItem>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-11 19:34:22 +02:00
|
|
|
function SplitButtonPropertyView({ note, property }: { note: FNote, property: SplitButtonProperty }) {
|
|
|
|
|
const parentComponent = useContext(ParentComponent);
|
|
|
|
|
const ItemsComponent = property.items;
|
2025-12-11 19:37:04 +02:00
|
|
|
const clickContext = parentComponent && {
|
|
|
|
|
note,
|
|
|
|
|
triggerCommand: parentComponent.triggerCommand.bind(parentComponent)
|
|
|
|
|
};
|
2025-12-11 19:34:22 +02:00
|
|
|
|
|
|
|
|
return (parentComponent &&
|
2025-12-11 19:37:04 +02:00
|
|
|
<FormDropdownSubmenu
|
|
|
|
|
icon={property.icon ?? "bx bx-empty"}
|
|
|
|
|
title={property.label}
|
|
|
|
|
onDropdownToggleClicked={() => clickContext && property.onClick(clickContext)}
|
|
|
|
|
>
|
2025-12-11 19:34:22 +02:00
|
|
|
<ItemsComponent note={note} parentComponent={parentComponent} />
|
|
|
|
|
</FormDropdownSubmenu>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-11 19:51:40 +02:00
|
|
|
function NumberPropertyView({ note, property }: { note: FNote, property: NumberProperty }) {
|
|
|
|
|
//@ts-expect-error Interop with text box which takes in string values even for numbers.
|
|
|
|
|
const [ value, setValue ] = useNoteLabel(note, property.bindToLabel);
|
|
|
|
|
const disabled = property.disabled?.(note);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<FormListItem
|
|
|
|
|
icon={property.icon}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
|
>
|
|
|
|
|
{property.label}
|
|
|
|
|
<FormTextBox
|
|
|
|
|
type="number"
|
|
|
|
|
currentValue={value ?? ""} onChange={setValue}
|
|
|
|
|
style={{ width: (property.width ?? 100) }}
|
|
|
|
|
min={property.min ?? 0}
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
/>
|
|
|
|
|
</FormListItem>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-11 19:17:23 +02:00
|
|
|
function CheckBoxPropertyView({ note, property }: { note: FNote, property: CheckBoxProperty }) {
|
|
|
|
|
const [ value, setValue ] = useNoteLabelBoolean(note, property.bindToLabel);
|
|
|
|
|
return (
|
|
|
|
|
<FormListToggleableItem
|
2025-12-11 19:44:22 +02:00
|
|
|
icon={property.icon}
|
2025-12-11 19:17:23 +02:00
|
|
|
title={property.label}
|
|
|
|
|
currentValue={value}
|
|
|
|
|
onChange={setValue}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-12-11 19:29:27 +02:00
|
|
|
|