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";
|
2024-04-27 18:01:58 +08:00
|
|
|
import { htmlSafe } from "@ember/template";
|
2024-03-28 22:05:48 +08:00
|
|
|
import BooleanField from "admin/components/schema-theme-setting/types/boolean";
|
|
|
|
import CategoriesField from "admin/components/schema-theme-setting/types/categories";
|
|
|
|
import EnumField from "admin/components/schema-theme-setting/types/enum";
|
|
|
|
import FloatField from "admin/components/schema-theme-setting/types/float";
|
|
|
|
import GroupsField from "admin/components/schema-theme-setting/types/groups";
|
|
|
|
import IntegerField from "admin/components/schema-theme-setting/types/integer";
|
|
|
|
import StringField from "admin/components/schema-theme-setting/types/string";
|
|
|
|
import TagsField from "admin/components/schema-theme-setting/types/tags";
|
2024-02-27 06:07:32 +08:00
|
|
|
|
|
|
|
export default class SchemaThemeSettingField extends Component {
|
|
|
|
get component() {
|
2024-03-22 15:32:00 +08:00
|
|
|
const type = this.args.spec.type;
|
|
|
|
|
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-27 10:54:30 +08:00
|
|
|
case "categories":
|
|
|
|
return CategoriesField;
|
2024-03-22 15:32:00 +08:00
|
|
|
case "tags":
|
|
|
|
return TagsField;
|
2024-03-28 22:05:48 +08:00
|
|
|
case "groups":
|
|
|
|
return GroupsField;
|
2024-02-29 16:11:32 +08:00
|
|
|
default:
|
2024-03-22 15:32:00 +08:00
|
|
|
throw new Error(`unknown type ${type}`);
|
2024-02-27 06:07:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-15 07:47:42 +08:00
|
|
|
@cached
|
|
|
|
get description() {
|
2024-03-21 12:39:25 +08:00
|
|
|
if (!this.args.description) {
|
|
|
|
return;
|
|
|
|
}
|
2024-03-15 07:47:42 +08:00
|
|
|
|
2024-03-21 12:39:25 +08:00
|
|
|
return htmlSafe(this.args.description.trim().replace(/\n/g, "<br>"));
|
2024-03-15 07:47:42 +08:00
|
|
|
}
|
|
|
|
|
2024-02-27 06:07:32 +08:00
|
|
|
<template>
|
2024-03-30 03:01:02 +08:00
|
|
|
<div class="schema-field" data-name={{@name}} data-type={{@spec.type}}>
|
2024-03-28 10:53:51 +08:00
|
|
|
<label class="schema-field__label">{{@label}}{{if
|
2024-03-21 12:39:25 +08:00
|
|
|
@spec.required
|
|
|
|
"*"
|
|
|
|
}}</label>
|
2024-03-15 07:47:42 +08:00
|
|
|
|
|
|
|
<div class="schema-field__input">
|
2024-02-29 16:11:32 +08:00
|
|
|
<this.component
|
|
|
|
@value={{@value}}
|
|
|
|
@spec={{@spec}}
|
|
|
|
@onChange={{@onValueChange}}
|
2024-03-21 12:39:25 +08:00
|
|
|
@description={{this.description}}
|
2024-03-27 10:54:30 +08:00
|
|
|
@setting={{@setting}}
|
2024-02-29 16:11:32 +08:00
|
|
|
/>
|
2024-02-27 06:07:32 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
}
|