mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
feat(book_properties): group map style into vector & raster
This commit is contained in:
parent
b5a57b3c66
commit
d17f5b8447
@ -1967,7 +1967,9 @@
|
|||||||
"hide-weekends": "Hide weekends",
|
"hide-weekends": "Hide weekends",
|
||||||
"display-week-numbers": "Display week numbers",
|
"display-week-numbers": "Display week numbers",
|
||||||
"map-style": "Map style:",
|
"map-style": "Map style:",
|
||||||
"max-nesting-depth": "Max nesting depth:"
|
"max-nesting-depth": "Max nesting depth:",
|
||||||
|
"raster": "Raster",
|
||||||
|
"vector": "Vector"
|
||||||
},
|
},
|
||||||
"table_context_menu": {
|
"table_context_menu": {
|
||||||
"delete_row": "Delete row"
|
"delete_row": "Delete row"
|
||||||
|
@ -59,7 +59,9 @@ const TPL = /*html*/`
|
|||||||
<span style="white-space: nowrap">${t("book_properties.view_type")}: </span>
|
<span style="white-space: nowrap">${t("book_properties.view_type")}: </span>
|
||||||
|
|
||||||
<select class="view-type-select form-select form-select-sm">
|
<select class="view-type-select form-select form-select-sm">
|
||||||
${Object.entries(VIEW_TYPE_MAPPINGS).map(([type, label]) => `
|
${Object.entries(VIEW_TYPE_MAPPINGS)
|
||||||
|
.filter(([type]) => type !== "raster")
|
||||||
|
.map(([type, label]) => `
|
||||||
<option value="${type}">${label}</option>
|
<option value="${type}">${label}</option>
|
||||||
`).join("")}
|
`).join("")}
|
||||||
</select>
|
</select>
|
||||||
@ -215,16 +217,17 @@ export default class BookPropertiesWidget extends NoteContextAwareWidget {
|
|||||||
const $select = $("<select>", {
|
const $select = $("<select>", {
|
||||||
class: "form-select form-select-sm"
|
class: "form-select form-select-sm"
|
||||||
});
|
});
|
||||||
const actualValue = note.getLabelValue(property.bindToLabel) ?? property.defaultValue;
|
const actualValue = note.getLabelValue(property.bindToLabel) ?? property.defaultValue ?? "";
|
||||||
for (const option of property.options) {
|
for (const option of property.options) {
|
||||||
const $option = $("<option>", {
|
if ("items" in option) {
|
||||||
value: option.value,
|
const $optGroup = $("<optgroup>", { label: option.name });
|
||||||
text: option.label
|
for (const item of option.items) {
|
||||||
});
|
buildComboBoxItem(item, actualValue).appendTo($optGroup);
|
||||||
if (actualValue === option.value) {
|
}
|
||||||
$option.prop("selected", true);
|
$optGroup.appendTo($select);
|
||||||
|
} else {
|
||||||
|
buildComboBoxItem(option, actualValue).appendTo($select);
|
||||||
}
|
}
|
||||||
$select.append($option);
|
|
||||||
}
|
}
|
||||||
$select.on("change", () => {
|
$select.on("change", () => {
|
||||||
const value = $select.val();
|
const value = $select.val();
|
||||||
@ -246,3 +249,14 @@ export default class BookPropertiesWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildComboBoxItem({ value, label }: { value: string, label: string }, actualValue: string) {
|
||||||
|
const $option = $("<option>", {
|
||||||
|
value,
|
||||||
|
text: label
|
||||||
|
});
|
||||||
|
if (actualValue === value) {
|
||||||
|
$option.prop("selected", true);
|
||||||
|
}
|
||||||
|
return $option;
|
||||||
|
}
|
||||||
|
@ -31,6 +31,16 @@ interface NumberProperty {
|
|||||||
min?: number;
|
min?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ComboBoxItem {
|
||||||
|
value: string;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ComboBoxGroup {
|
||||||
|
name: string;
|
||||||
|
items: ComboBoxItem[];
|
||||||
|
}
|
||||||
|
|
||||||
interface ComboBoxProperty {
|
interface ComboBoxProperty {
|
||||||
type: "combobox",
|
type: "combobox",
|
||||||
label: string;
|
label: string;
|
||||||
@ -39,7 +49,7 @@ interface ComboBoxProperty {
|
|||||||
* The default value is used when the label is not set.
|
* The default value is used when the label is not set.
|
||||||
*/
|
*/
|
||||||
defaultValue?: string;
|
defaultValue?: string;
|
||||||
options: { value: string; label: string }[];
|
options: (ComboBoxItem | ComboBoxGroup)[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type BookProperty = CheckBoxProperty | ButtonProperty | NumberProperty | ComboBoxProperty;
|
export type BookProperty = CheckBoxProperty | ButtonProperty | NumberProperty | ComboBoxProperty;
|
||||||
@ -108,10 +118,26 @@ export const bookPropertiesConfig: Record<ViewTypeOptions, BookConfig> = {
|
|||||||
type: "combobox",
|
type: "combobox",
|
||||||
bindToLabel: "mapStyle",
|
bindToLabel: "mapStyle",
|
||||||
defaultValue: DEFAULT_MAP_LAYER_NAME,
|
defaultValue: DEFAULT_MAP_LAYER_NAME,
|
||||||
options: Object.entries(MAP_LAYERS).map(([id, layer]) => ({
|
options: [
|
||||||
value: id,
|
{
|
||||||
label: layer.name
|
name: t("book_properties_config.raster"),
|
||||||
}))
|
items: Object.entries(MAP_LAYERS)
|
||||||
|
.filter(([_, layer]) => layer.type === "raster")
|
||||||
|
.map(([id, layer]) => ({
|
||||||
|
value: id,
|
||||||
|
label: layer.name
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: t("book_properties_config.vector"),
|
||||||
|
items: Object.entries(MAP_LAYERS)
|
||||||
|
.filter(([_, layer]) => layer.type === "vector")
|
||||||
|
.map(([id, layer]) => ({
|
||||||
|
value: id,
|
||||||
|
label: layer.name
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -22,28 +22,28 @@ export const MAP_LAYERS: Record<string, VectorLayer | RasterLayer> = {
|
|||||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||||
},
|
},
|
||||||
"versatiles-colorful": {
|
"versatiles-colorful": {
|
||||||
name: "VersaTiles Colorful (vector)",
|
name: "VersaTiles Colorful",
|
||||||
type: "vector",
|
type: "vector",
|
||||||
style: async () => (await import("./styles/colorful/en.json")).default
|
style: async () => (await import("./styles/colorful/en.json")).default
|
||||||
},
|
},
|
||||||
"versatiles-eclipse": {
|
"versatiles-eclipse": {
|
||||||
name: "VersaTiles Eclipse (vector)",
|
name: "VersaTiles Eclipse",
|
||||||
type: "vector",
|
type: "vector",
|
||||||
style: async () => (await import("./styles/eclipse/en.json")).default,
|
style: async () => (await import("./styles/eclipse/en.json")).default,
|
||||||
isDarkTheme: true
|
isDarkTheme: true
|
||||||
},
|
},
|
||||||
"versatiles-graybeard": {
|
"versatiles-graybeard": {
|
||||||
name: "VersaTiles Graybeard (vector)",
|
name: "VersaTiles Graybeard",
|
||||||
type: "vector",
|
type: "vector",
|
||||||
style: async () => (await import("./styles/graybeard/en.json")).default
|
style: async () => (await import("./styles/graybeard/en.json")).default
|
||||||
},
|
},
|
||||||
"versatiles-neutrino": {
|
"versatiles-neutrino": {
|
||||||
name: "VersaTiles Neutrino (vector)",
|
name: "VersaTiles Neutrino",
|
||||||
type: "vector",
|
type: "vector",
|
||||||
style: async () => (await import("./styles/neutrino/en.json")).default
|
style: async () => (await import("./styles/neutrino/en.json")).default
|
||||||
},
|
},
|
||||||
"versatiles-shadow": {
|
"versatiles-shadow": {
|
||||||
name: "VersaTiles Shadow (vector)",
|
name: "VersaTiles Shadow",
|
||||||
type: "vector",
|
type: "vector",
|
||||||
style: async () => (await import("./styles/shadow/en.json")).default,
|
style: async () => (await import("./styles/shadow/en.json")).default,
|
||||||
isDarkTheme: true
|
isDarkTheme: true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user