Extract logic for enum providers

6b61abc8edc033c3e5e88e69ec398e70df8305ea

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +10 -8Ignore whitespace
public/scripts/extensions/stable-diffusion/index.js+10 -8
@@ -3823,6 +3823,8 @@ function applyCommandArguments(args) {
3823jQuery(async () => {3823jQuery(async () => {
3824 await addSDGenButtons();3824 await addSDGenButtons();
38253825
3826 const getSelectEnumProvider = (id, text) => () => Array.from(document.querySelectorAll(`#${id} > [value]`)).map(x => new SlashCommandEnumValue(x.getAttribute('value'), text ? x.textContent : null));
3827
3826 SlashCommandParser.addCommandObject(SlashCommand.fromProps({3828 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
3827 name: 'imagine',3829 name: 'imagine',
3828 returns: 'URL of the generated image, or an empty string if the generation failed',3830 returns: 'URL of the generated image, or an empty string if the generation failed',
@@ -3934,7 +3936,7 @@ jQuery(async () => {
3934 typeList: [ARGUMENT_TYPE.STRING],3936 typeList: [ARGUMENT_TYPE.STRING],
3935 acceptsMultiple: false,3937 acceptsMultiple: false,
3936 forceEnum: true,3938 forceEnum: true,
3937 enumProvider: () => Array.from(document.querySelectorAll('#sd_model > [value]')).map(o => new SlashCommandEnumValue(o.getAttribute('value'), o.textContent)),3939 enumProvider: getSelectEnumProvider('sd_model', true),
3938 }),3940 }),
3939 SlashCommandNamedArgument.fromProps({3941 SlashCommandNamedArgument.fromProps({
3940 name: 'sampler',3942 name: 'sampler',
@@ -3943,7 +3945,7 @@ jQuery(async () => {
3943 typeList: [ARGUMENT_TYPE.STRING],3945 typeList: [ARGUMENT_TYPE.STRING],
3944 acceptsMultiple: false,3946 acceptsMultiple: false,
3945 forceEnum: true,3947 forceEnum: true,
3946 enumProvider: () => Array.from(document.querySelectorAll('#sd_sampler > [value]')).map(o => new SlashCommandEnumValue(o.getAttribute('value'), o.textContent)),3948 enumProvider: getSelectEnumProvider('sd_sampler', false),
3947 }),3949 }),
3948 SlashCommandNamedArgument.fromProps({3950 SlashCommandNamedArgument.fromProps({
3949 name: 'scheduler',3951 name: 'scheduler',
@@ -3952,7 +3954,7 @@ jQuery(async () => {
3952 typeList: [ARGUMENT_TYPE.STRING],3954 typeList: [ARGUMENT_TYPE.STRING],
3953 acceptsMultiple: false,3955 acceptsMultiple: false,
3954 forceEnum: true,3956 forceEnum: true,
3955 enumProvider: () => Array.from(document.querySelectorAll('#sd_scheduler > [value]')).map(o => new SlashCommandEnumValue(o.getAttribute('value'), o.textContent)),3957 enumProvider: getSelectEnumProvider('sd_scheduler', false),
3956 }),3958 }),
3957 SlashCommandNamedArgument.fromProps({3959 SlashCommandNamedArgument.fromProps({
3958 name: 'vae',3960 name: 'vae',
@@ -3961,7 +3963,7 @@ jQuery(async () => {
3961 typeList: [ARGUMENT_TYPE.STRING],3963 typeList: [ARGUMENT_TYPE.STRING],
3962 acceptsMultiple: false,3964 acceptsMultiple: false,
3963 forceEnum: true,3965 forceEnum: true,
3964 enumProvider: () => Array.from(document.querySelectorAll('#sd_vae > [value]')).map(o => new SlashCommandEnumValue(o.getAttribute('value'), o.textContent)),3966 enumProvider: getSelectEnumProvider('sd_vae', false),
3965 }),3967 }),
3966 SlashCommandNamedArgument.fromProps({3968 SlashCommandNamedArgument.fromProps({
3967 name: 'upscaler',3969 name: 'upscaler',
@@ -3970,7 +3972,7 @@ jQuery(async () => {
3970 typeList: [ARGUMENT_TYPE.STRING],3972 typeList: [ARGUMENT_TYPE.STRING],
3971 acceptsMultiple: false,3973 acceptsMultiple: false,
3972 forceEnum: true,3974 forceEnum: true,
3973 enumProvider: () => Array.from(document.querySelectorAll('#sd_hr_upscaler > [value]')).map(o => new SlashCommandEnumValue(o.getAttribute('value'), o.textContent)),3975 enumProvider: getSelectEnumProvider('sd_hr_upscaler', false),
3974 }),3976 }),
3975 SlashCommandNamedArgument.fromProps({3977 SlashCommandNamedArgument.fromProps({
3976 name: 'hires',3978 name: 'hires',
@@ -4038,7 +4040,7 @@ jQuery(async () => {
4038 typeList: [ARGUMENT_TYPE.STRING],4040 typeList: [ARGUMENT_TYPE.STRING],
4039 isRequired: false,4041 isRequired: false,
4040 forceEnum: true,4042 forceEnum: true,
4041 enumProvider: () => Array.from(document.querySelectorAll('#sd_source > [value]')).map(x => new SlashCommandEnumValue(x.getAttribute('value'), x.textContent)),4043 enumProvider: getSelectEnumProvider('sd_source', true),
4042 }),4044 }),
4043 ],4045 ],
4044 helpString: 'If an argument is provided, change the source of the image generation, e.g. <code>/imagine-source comfy</code>. Returns the current source.',4046 helpString: 'If an argument is provided, change the source of the image generation, e.g. <code>/imagine-source comfy</code>. Returns the current source.',
@@ -4070,7 +4072,7 @@ jQuery(async () => {
4070 typeList: [ARGUMENT_TYPE.STRING],4072 typeList: [ARGUMENT_TYPE.STRING],
4071 isRequired: false,4073 isRequired: false,
4072 forceEnum: true,4074 forceEnum: true,
4073 enumProvider: () => Array.from(document.querySelectorAll('#sd_style > [value]')).map(x => new SlashCommandEnumValue(x.getAttribute('value'), x.textContent)),4075 enumProvider: getSelectEnumProvider('sd_style', false),
4074 }),4076 }),
4075 ],4077 ],
4076 helpString: 'If an argument is provided, change the style of the image generation, e.g. <code>/imagine-style MyStyle</code>. Returns the current style.',4078 helpString: 'If an argument is provided, change the style of the image generation, e.g. <code>/imagine-style MyStyle</code>. Returns the current style.',
@@ -4097,7 +4099,7 @@ jQuery(async () => {
4097 description: 'workflow name',4099 description: 'workflow name',
4098 typeList: [ARGUMENT_TYPE.STRING],4100 typeList: [ARGUMENT_TYPE.STRING],
4099 isRequired: true,4101 isRequired: true,
4100 enumProvider: () => Array.from(document.querySelectorAll('#sd_comfy_workflow > [value]')).map(x => x.getAttribute('value')).map(workflow => new SlashCommandEnumValue(workflow)),4102 enumProvider: getSelectEnumProvider('sd_comfy_workflow', false),
4101 }),4103 }),
4102 ],4104 ],
4103 helpString: '(workflowName) - change the workflow to be used for image generation with ComfyUI, e.g. <pre><code>/imagine-comfy-workflow MyWorkflow</code></pre>',4105 helpString: '(workflowName) - change the workflow to be used for image generation with ComfyUI, e.g. <pre><code>/imagine-comfy-workflow MyWorkflow</code></pre>',