Skip to content

Commit 10300ed

Browse files
committed
Final docs on list types.
1 parent b0697fe commit 10300ed

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ You specify the editable options of your extension in a JSON document. This docu
9494
["value314159", "pi"] // Third dropdown, Displays "pi" to user, but the stored value is "value314159"
9595
],
9696

97+
// For "list"
98+
99+
"style" : "csv" // comma-separated list (optional, default)
100+
"style" : "textblock" // mutli-line text, one item per line.
101+
97102
// For "file" (a file picker)
98103

99104
"accept" : "image/*,video/*,.webp", // The extensions or mime types to filter by
@@ -151,7 +156,7 @@ Example JSON:
151156
"name" : "sampleSelect",
152157
"type" : "select",
153158
"label" : "Sample Selection",
154-
"description" : "A list of simple values, or values and their labels",
159+
"description" : "A selector among simple values, or values with custom labels",
155160
"values" : [
156161
"Value1", "Value2", ["Value3", "Value3's Label"]
157162
],
@@ -170,14 +175,31 @@ Example JSON:
170175
"label" : "Sample Block",
171176
"description" : "A multiline text block"
172177
},
178+
{
179+
"name" : "sampleCSVList",
180+
"type" : "list",
181+
"style" : "csv",
182+
"label" : "Sample CSV List",
183+
"description" : "A list of simple strings, separated by commas",
184+
"default" : ["one", "two", "three"]
185+
},
186+
{
187+
"name" : "sampleBlockList",
188+
"type" : "list",
189+
"style" : "textblock",
190+
"shape" : "list",
191+
"label" : "Sample Multiline List",
192+
"description" : "A list of simple strings, one per line",
193+
"default" : ["one", "two", "three"]
194+
},
173195
{
174196
"name" : "sampleFile",
175197
"type" : "file",
176198
"label" : "Sample File",
177199
"description" : "A chooser for file paths, with optional type filter",
178200
"accept" : "image/*"
179201
},
180-
202+
181203
{
182204
"name" : "sampleBooleanDependency",
183205
"type" : "boolean",
@@ -247,6 +269,12 @@ The expression can have the usual simple operators:
247269

248270
The simplest, and probably most useful expression, is simply the name of another simple boolean option: When it is checked, the option shows, and is hidden when the option is unchecked.
249271

272+
### Lists
273+
274+
Lists/Arrays of strings are currently supported with the "**list**" option type. It comes in two flavors:
275+
* `style: "csv"` : List items separated by commas (with any surrounding spaces removed)
276+
* `style: "textblock"` : List items are one per line.
277+
250278
### Option Groups
251279

252280
You can create a group of options with an option of `"type" : "group"`. The `"name"` is optional.

config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,15 +808,15 @@ class ListOption extends OptionUI
808808
constructor(name, options) {
809809
super(name, options);
810810

811-
const style = options.style ?? "csv";
811+
const style = (options.style ?? "csv").toLowerCase();
812812

813813
// Delegate the actual UI to a text widget, and we'll
814814
// wrap it to convert the string to/from a list.
815815
if (style === "csv") {
816816
this.#uiWidget = new TextOption(name, options);
817817
this.#separator = ", ";
818818
this.#splitter = (str) => str.split(/\s*,\s*/);
819-
} else if (style === "block") {
819+
} else if (style === "textblock") {
820820
this.#uiWidget = new TextBlockOption(name, options);
821821
// Splits at line breaks, but ignores final blank lines.
822822
this.#splitter = (str) => str.split(/\r?\n/).filter((line, i, arr) => !(i === arr.length - 1 && line === ''));

sample.json

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,12 @@
7171
{
7272
"name" : "sampleBlockList",
7373
"type" : "list",
74-
"style" : "block",
74+
"style" : "textblock",
7575
"shape" : "list",
7676
"label" : "Sample Multiline List",
7777
"description" : "A list of simple strings, one per line",
7878
"default" : ["one", "two", "three"]
7979
},
80-
{
81-
"name" : "sampleVarList",
82-
"type" : "list",
83-
"style" : "block",
84-
"shape" : "indexedvars",
85-
"label" : "Sample Multiline List",
86-
"description" : "A list of simple strings, one per line, and stored in separate variables",
87-
"default" : ["one", "two", "three"]
88-
},
8980
{
9081
"name" : "sampleFile",
9182
"type" : "file",

0 commit comments

Comments
 (0)