import { t } from "i18next"; import { useContext } from "preact/hooks"; import { Fragment } from "preact/jsx-runtime"; import FNote from "../../entities/fnote"; import { ViewTypeOptions } from "../collections/interface"; import Dropdown from "../react/Dropdown"; import { FormDropdownDivider, FormDropdownSubmenu, FormListItem, FormListToggleableItem } from "../react/FormList"; import FormTextBox from "../react/FormTextBox"; import { useNoteLabel, useNoteLabelBoolean, useNoteLabelWithDefault } from "../react/hooks"; import Icon from "../react/Icon"; import { ParentComponent } from "../react/react_utils"; import { bookPropertiesConfig, BookProperty, ButtonProperty, CheckBoxProperty, ComboBoxItem, ComboBoxProperty, NumberProperty, SplitButtonProperty } from "../ribbon/collection-properties-config"; import { useViewType, VIEW_TYPE_MAPPINGS } from "../ribbon/CollectionPropertiesTab"; import ActionButton from "../react/ActionButton"; import { getHelpUrlForNote } from "../../services/in_app_help"; import { openInAppHelpFromUrl } from "../../services/utils"; const ICON_MAPPINGS: Record = { 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" }; export default function CollectionProperties({ note }: { note: FNote }) { const [ viewType, setViewType ] = useViewType(note); return ( <>
); } function ViewTypeSwitcher({ viewType, setViewType }: { viewType: ViewTypeOptions, setViewType: (newValue: ViewTypeOptions) => void }) { return (   {VIEW_TYPE_MAPPINGS[viewType]} } > {Object.entries(VIEW_TYPE_MAPPINGS).map(([ key, label ]) => ( setViewType(key as ViewTypeOptions)} selected={viewType === key} disabled={viewType === key} icon={ICON_MAPPINGS[key as ViewTypeOptions]} >{label} ))} ); } function ViewOptions({ note, viewType }: { note: FNote, viewType: ViewTypeOptions }) { const properties = bookPropertiesConfig[viewType].properties; return ( {properties.map(property => ( ))} {properties.length > 0 && } ); } function ViewProperty({ note, property }: { note: FNote, property: BookProperty }) { switch (property.type) { case "button": return ; case "split-button": return ; case "checkbox": return ; case "number": return ; case "combobox": return ; } } function ButtonPropertyView({ note, property }: { note: FNote, property: ButtonProperty }) { const parentComponent = useContext(ParentComponent); return ( { if (!parentComponent) return; property.onClick({ note, triggerCommand: parentComponent.triggerCommand.bind(parentComponent) }); }} >{property.label} ); } function SplitButtonPropertyView({ note, property }: { note: FNote, property: SplitButtonProperty }) { const parentComponent = useContext(ParentComponent); const ItemsComponent = property.items; const clickContext = parentComponent && { note, triggerCommand: parentComponent.triggerCommand.bind(parentComponent) }; return (parentComponent && clickContext && property.onClick(clickContext)} > ); } 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 ( e.stopPropagation()} > {property.label} ); } function ComboBoxPropertyView({ note, property }: { note: FNote, property: ComboBoxProperty }) { const [ value, setValue ] = useNoteLabelWithDefault(note, property.bindToLabel, property.defaultValue ?? ""); function renderItem(option: ComboBoxItem) { return ( setValue(option.value)} > {option.label} ); } return ( {(property.options).map((option, index) => { if ("items" in option) { return ( {option.title} {option.items.map(renderItem)} {index < property.options.length - 1 && } ); } else { return renderItem(option); } })} ); } function CheckBoxPropertyView({ note, property }: { note: FNote, property: CheckBoxProperty }) { const [ value, setValue ] = useNoteLabelBoolean(note, property.bindToLabel); return ( ); } function HelpButton({ note }: { note: FNote }) { const helpUrl = getHelpUrlForNote(note); return (helpUrl && ( openInAppHelpFromUrl(helpUrl))} text={t("help-button.title")} /> )); }