import { useMemo } from "react"; import { Intent } from "@blueprintjs/core"; import { RowGroup, RowGroupOption, SingleInput, TextField, TextWithSelect, SettingsManager } from "Components/UserSettings"; const { Provider: NotesProvider, useSettings: useNotesSettings } = new SettingsManager<"notes">({ /* istanbul ignore next */ afterUpdate: (_prevState, update) => { window?.zoteroRoam?.updateSetting?.("notes", update); } }); const NEST_POSITION_OPTIONS = [ { label: "At the top", value: "top" }, { label: "At the bottom", value: "bottom" } ]; const NEST_PRESET_OPTIONS = [ { label: "Don't nest", value: false }, { label: "[[Notes]]", value: "[[Notes]]" } ]; const NEST_USE_OPTIONS = { "preset": "Preset", "custom": "Custom content" }; const SPLIT_PRESET_OPTIONS = [ { label: "Newline", value: "\n" }, { label: "Paragraph", value: "
" } ]; const SPLIT_USE_OPTIONS = { "preset": "Preset", "custom": "Custom separator" }; const USE_OPTIONS = { "default": "Default formatter", "function": "Custom function" }; const WITH_OPTIONS = [ { label: "Use raw metadata", value: "raw" }, { label: "Use HTML blocks", value: "text" } ]; function NotesWidget(){ const [ { func, nest_char, nest_position, nest_preset, nest_use, split_char, split_preset, split_use, use, __with }, setOpts ] = useNotesSettings(); const handlers = useMemo(() => { /* istanbul ignore next */ function updateSingleValue(op, val){ setOpts(prevState => ({ ...prevState, [op]: val })); } return { updateFuncName: (val) => updateSingleValue("func", val), updateNestChar: (val) => updateSingleValue("nest_char", val), updateNestPosition: (val) => updateSingleValue("nest_position", val), updateNestPreset: (val) => updateSingleValue("nest_preset", val), updateNestUse: (val) => updateSingleValue("nest_use", val), updateSplitChar: (val) => updateSingleValue("split_char", val), updateSplitPreset: (val) => updateSingleValue("split_preset", val), updateSplitUse: (val) => updateSingleValue("split_use", val), updateUseType: (val) => updateSingleValue("use", val), updateWithFormat: (val) => updateSingleValue("__with", val) }; }, [setOpts]); const customFuncButtonProps = useMemo(() => ({ intent: Intent.PRIMARY }), []); return <>