2024-02-27 06:07:32 +08:00
|
|
|
import Component from "@glimmer/component";
|
2024-03-15 07:47:42 +08:00
|
|
|
import { cached } from "@glimmer/tracking";
|
|
|
|
import htmlSafe from "discourse-common/helpers/html-safe";
|
2024-02-29 16:11:32 +08:00
|
|
|
import BooleanField from "./types/boolean";
|
2024-03-13 09:08:50 +08:00
|
|
|
import CategoryField from "./types/category";
|
2024-02-29 16:11:32 +08:00
|
|
|
import EnumField from "./types/enum";
|
2024-03-13 09:08:50 +08:00
|
|
|
import FloatField from "./types/float";
|
|
|
|
import GroupField from "./types/group";
|
2024-02-29 16:11:32 +08:00
|
|
|
import IntegerField from "./types/integer";
|
|
|
|
import StringField from "./types/string";
|
2024-03-13 09:08:50 +08:00
|
|
|
import TagField from "./types/tag";
|
2024-02-27 06:07:32 +08:00
|
|
|
|
|
|
|
export default class SchemaThemeSettingField extends Component {
|
|
|
|
get component() {
|
2024-02-29 16:11:32 +08:00
|
|
|
switch (this.args.spec.type) {
|
|
|
|
case "string":
|
|
|
|
return StringField;
|
|
|
|
case "integer":
|
|
|
|
return IntegerField;
|
2024-03-13 09:08:50 +08:00
|
|
|
case "float":
|
|
|
|
return FloatField;
|
2024-02-29 16:11:32 +08:00
|
|
|
case "boolean":
|
|
|
|
return BooleanField;
|
|
|
|
case "enum":
|
|
|
|
return EnumField;
|
2024-03-13 09:08:50 +08:00
|
|
|
case "category":
|
|
|
|
return CategoryField;
|
|
|
|
case "tag":
|
|
|
|
return TagField;
|
|
|
|
case "group":
|
|
|
|
return GroupField;
|
2024-02-29 16:11:32 +08:00
|
|
|
default:
|
|
|
|
throw new Error("unknown type");
|
2024-02-27 06:07:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-15 07:47:42 +08:00
|
|
|
@cached
|
|
|
|
get description() {
|
|
|
|
return this.args.description.trim().replace(/\n/g, "<br>");
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasDescription() {
|
|
|
|
return this.args.description?.length > 0;
|
|
|
|
}
|
|
|
|
|
2024-02-27 06:07:32 +08:00
|
|
|
<template>
|
|
|
|
<div class="schema-field" data-name={{@name}}>
|
2024-03-15 07:47:42 +08:00
|
|
|
<label class="schema-field__label">{{@name}}</label>
|
|
|
|
|
|
|
|
<div class="schema-field__input">
|
2024-02-29 16:11:32 +08:00
|
|
|
<this.component
|
|
|
|
@value={{@value}}
|
|
|
|
@spec={{@spec}}
|
|
|
|
@onChange={{@onValueChange}}
|
|
|
|
/>
|
2024-02-27 06:07:32 +08:00
|
|
|
</div>
|
2024-03-15 07:47:42 +08:00
|
|
|
|
|
|
|
{{#if this.hasDescription}}
|
|
|
|
<div class="schema-field__description">
|
|
|
|
{{htmlSafe this.description}}
|
|
|
|
</div>
|
|
|
|
{{/if}}
|
2024-02-27 06:07:32 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
}
|