diff --git a/src/main.ts b/src/main.ts index 4c69dc4..faaf025 100644 --- a/src/main.ts +++ b/src/main.ts @@ -584,7 +584,9 @@ export default class MediaDbPlugin extends Plugin { newProperties.push(defaultProperty); } else { // newProperty is just an object and take locked status from default property - newProperties.push(new PropertyMapping(newProperty.property, newProperty.newProperty, newProperty.mapping, defaultProperty.locked)); + newProperties.push( + new PropertyMapping(newProperty.property, newProperty.newProperty, newProperty.mapping, defaultProperty.locked, newProperty.wikilink ?? false), + ); } } diff --git a/src/settings/PropertyMapper.ts b/src/settings/PropertyMapper.ts index 533399c..b2cabd7 100644 --- a/src/settings/PropertyMapper.ts +++ b/src/settings/PropertyMapper.ts @@ -35,14 +35,22 @@ export class PropertyMapper { for (const [key, value] of Object.entries(obj)) { for (const propertyMapping of propertyMappings) { if (propertyMapping.property === key) { + let finalValue = value; + if (propertyMapping.wikilink) { + if (typeof value === 'string') { + finalValue = `[[${value}]]`; + } else if (Array.isArray(value)) { + finalValue = value.map(v => (typeof v === 'string' ? `[[${v}]]` : v)); + } + } if (propertyMapping.mapping === PropertyMappingOption.Map) { // @ts-ignore - newObj[propertyMapping.newProperty] = value; + newObj[propertyMapping.newProperty] = finalValue; } else if (propertyMapping.mapping === PropertyMappingOption.Remove) { // do nothing } else if (propertyMapping.mapping === PropertyMappingOption.Default) { // @ts-ignore - newObj[key] = value; + newObj[key] = finalValue; } break; } diff --git a/src/settings/PropertyMapping.ts b/src/settings/PropertyMapping.ts index bad0369..730b579 100644 --- a/src/settings/PropertyMapping.ts +++ b/src/settings/PropertyMapping.ts @@ -75,7 +75,7 @@ export class PropertyMappingModel { copy(): PropertyMappingModel { const copy = new PropertyMappingModel(this.type); for (const property of this.properties) { - const propertyCopy = new PropertyMapping(property.property, property.newProperty, property.mapping, property.locked); + const propertyCopy = new PropertyMapping(property.property, property.newProperty, property.mapping, property.locked, property.wikilink); copy.properties.push(propertyCopy); } return copy; @@ -87,12 +87,14 @@ export class PropertyMapping { newProperty: string; locked: boolean; mapping: PropertyMappingOption; + wikilink: boolean; - constructor(property: string, newProperty: string, mapping: PropertyMappingOption, locked?: boolean) { + constructor(property: string, newProperty: string, mapping: PropertyMappingOption, locked?: boolean, wikilink?: boolean) { this.property = property; this.newProperty = newProperty; this.mapping = mapping; this.locked = locked ?? false; + this.wikilink = wikilink ?? false; } validate(): { res: boolean; err?: Error } { diff --git a/src/settings/PropertyMappingModelComponent.svelte b/src/settings/PropertyMappingModelComponent.svelte index 81b236c..7dca2d5 100644 --- a/src/settings/PropertyMappingModelComponent.svelte +++ b/src/settings/PropertyMappingModelComponent.svelte @@ -11,57 +11,145 @@ let { model, save }: Props = $props(); let validationResult: { res: boolean; err?: Error } | undefined = $derived(model.validate()); - - // Use $state as a variable declaration initializer - let propertyStates = $state(model.properties.map(p => ({ ...p })));
{property.property}
- | Property | +Mapping | +New name | +Wikilink | +|||
|---|---|---|---|---|---|---|
+ {property.property}
+ |
+
+ {#if property.locked}
+
+ property cannot be remapped
+ |
+ {:else}
+ + + | + +
+ {#if property.mapping === PropertyMappingOption.Map}
+
+
+ {:else}
+ —
+ {/if}
+ |
+
+ + + | {/if} - {/if} - - {/each} - +||