jsl-ui 10.2.3 → 10.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,3 +13,24 @@ const teams = new SelectComponent({
13
13
  - `value` / `getValue()` use keys from `keyColumn` (default `"value"`); `getSelected()` returns the matching data objects. Multiple selection uses arrays; single selection uses a scalar.
14
14
  - Omit `multiple` and use `value: "design"` for single selection with the same data.
15
15
  - `setValue()` takes keys and updates the binding without raising change callbacks. The component owns its dropdown; do not create `SelectDDAreaComponent` separately.
16
+
17
+ ## Search on the server
18
+
19
+ For option sets too large to load, let the server search. The dropdown's own search box stays the only search field.
20
+
21
+ ```ts
22
+ let generation = 0;
23
+ const customers = new SelectComponent({
24
+ ariaLabel: "Customer", data: [],
25
+ onOpen: () => search(""), // optional: load the first batch lazily
26
+ onSearch: term => search(term), // after 300 ms without typing; "" when the list reopens
27
+ onLoadMore: () => loadMore() // list scrolled near its end
28
+ });
29
+ ```
30
+
31
+ - With `onSearch`, typed text is not matched against `data` and `matchSearch` is ignored. `searchDelay` (default 300) debounces typing.
32
+ - Answer with `setData(items, hasMore)` and `setLoading(false)`; call `setLoading(true)` when a request starts. `setData` replaces all options, so for `onLoadMore` pass the items so far plus the new batch. The scroll position is kept.
33
+ - `onLoadMore` only fires while the last `setData` reported `hasMore` and the select is not loading, once per batch. Always finish with `setLoading(false)`, also after an error, or no further batch is requested.
34
+ - The chosen item stays selected and shown even if later results do not list it; `getSelected()` and `setValue()` still find it. Preselect by passing it in `data` with `value`, or by calling `setData` before `setValue`.
35
+ - Discard answers of outdated requests yourself, for example with a counter that grows with every search.
36
+ - `loadingText` replaces the "Loading…" hint.
@@ -0,0 +1,93 @@
1
+ Copyright 2022 The Bricolage Grotesque Project Authors (https://github.com/ateliertriay/bricolage)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ https://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,93 @@
1
+ Copyright 2022 The Figtree Project Authors (https://github.com/erikdkennedy/figtree)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -65,6 +65,30 @@ const large = new SelectComponent({
65
65
  value: 5000, ariaLabel: "Large list", dropdownHeight: "18rem", placeholder: "Choose an item",
66
66
  onChange: (value, item) => { largeStatus.content = item ? "Selected " + item.text + ", key " + value : "Selection cleared."; }
67
67
  });
68
+ // A pretend server: 500 customers, searched and paged with a delay.
69
+ const customerNames = Array.from({ length: 500 }, (_, i) => ({ value: i + 1, text: "Customer " + ("000" + (i + 1)).slice(-4) + " " + ["Alpine", "Danube", "Linz", "Graz", "Tyrol"][i % 5] }));
70
+ const remoteStatus = status("Open the list, type a name or scroll for more.");
71
+ let remoteGeneration = 0;
72
+ let remoteFound: typeof customerNames = [];
73
+ let remoteTerm = "";
74
+ function remoteLoad(append: boolean) {
75
+ const generation = ++remoteGeneration;
76
+ remote.setLoading(true);
77
+ setTimeout(() => {
78
+ if (generation !== remoteGeneration) { return; }
79
+ const matches = customerNames.filter(item => item.text.toLowerCase().includes(remoteTerm.toLowerCase()));
80
+ remoteFound = matches.slice(0, append ? remoteFound.length + 25 : 25);
81
+ remote.setData(remoteFound, remoteFound.length < matches.length);
82
+ remote.setLoading(false);
83
+ remoteStatus.content = remoteFound.length + " of " + matches.length + " matches loaded.";
84
+ }, 400);
85
+ }
86
+ const remote: SelectComponent = new SelectComponent({
87
+ id: "select-remote", data: [], ariaLabel: "Customer", placeholder: "Choose a customer", searchPlaceholder: "Search customers…",
88
+ onOpen: () => { if (!remoteFound.length) { remoteLoad(false); } },
89
+ onSearch: term => { remoteTerm = term; remoteLoad(false); },
90
+ onLoadMore: () => remoteLoad(true)
91
+ });
68
92
  function card(id: string, number: string, title: string, description: string, children: Content[]): IJSLVNode {
69
93
  return { tag: "article", attr: { id, class: "sample-card" }, children: [
70
94
  group([text("span", number, "sample-number"), text("h3", title)], "card-heading"),
@@ -142,6 +166,10 @@ export const selectShowcase: IJSLVNode = {
142
166
  card("select-scale", "06", "Room for a long list", "Ten thousand options, with only the visible rows rendered. Selection stays in view when you open the list.", [
143
167
  field("select-large", "Item", large), largeStatus,
144
168
  text("p", "Type to search. Arrow keys move through results; Ctrl+Home and Ctrl+End jump to either end.", "inline-note")
169
+ ]),
170
+ card("select-server", "07", "Search on the server", "For lists too long to load. The one search box asks the server, and scrolling to the end loads more.", [
171
+ field("select-remote", "Customer", remote), remoteStatus,
172
+ text("pre", '{ onSearch: term => load(term), onLoadMore: () => loadMore() } // answer with select.setData(items, hasMore)', "sample-code")
145
173
  ])
146
174
  ], "sample-grid select-sample-grid"),
147
175
  { tag: "details", attr: { class: "usage" }, children: [
@@ -34,6 +34,7 @@ export const showcaseSources: Record<string, string> = {
34
34
  "select-custom": "import \"../../ui/base.css\";\nimport \"./showcase.css\";\nimport { IJSLComponent, IJSLVNode } from \"jsl-render\";\nimport { SelectComponent } from \"../../components/select/SelectComponent\";\nimport { JSLRender as ExampleRenderer } from \"jsl-render\";\n\ntype Content = IJSLVNode | IJSLComponent;\n\nconst text = (tag: string, content: string, className?: string): IJSLVNode => ({ tag, content, attr: { class: className } });\n\nconst group = (children: Content[], className?: string): IJSLVNode => ({ tag: \"div\", attr: { class: className }, children });\n\nconst status = (content: string): IJSLVNode => ({ tag: \"p\", content, attr: { class: \"sample-status\", role: \"status\" } });\n\nconst field = (id: string, label: string, control: Content) => group([\n { tag: \"label\", content: label, attr: { for: id } }, control\n], \"select-showcase-field\");\n\nconst people = [\n { value: \"maya\", text: \"Maya Chen\", initials: \"MC\", role: \"Product designer\" },\n { value: \"alex\", text: \"Alex Morgan\", initials: \"AM\", role: \"Frontend engineer\" },\n { value: \"sam\", text: \"Sam Rivera\", initials: \"SR\", role: \"Accessibility specialist\" },\n { value: \"jules\", text: \"Jules Martin\", initials: \"JM\", role: \"Product manager\" }\n];\n\nconst memberStatus = status(\"Selected Maya Chen.\");\n\nconst member = new SelectComponent({\n id: \"select-owner\", data: people, value: \"maya\",\n ariaLabel: \"Project owner\", placeholder: \"Assign an owner\", rowHeight: 56,\n matchSearch: (item, term) => (item.text + \" \" + item.role).toLowerCase().includes(term.toLowerCase()),\n onRender: args => args.isCurrent ? text(\"span\", args.data.text) : group([\n { tag: \"span\", content: args.data.initials, attr: { class: \"select-person-avatar\", \"aria-hidden\": \"true\" } },\n group([text(\"strong\", args.data.text), text(\"span\", args.data.role)], \"select-person-copy\")\n ], \"select-person\"),\n onChange: (_value, item) => { memberStatus.content = item ? \"Selected \" + item.text + \".\" : \"No owner selected.\"; }\n});\n\nfunction card(id: string, number: string, title: string, description: string, children: Content[]): IJSLVNode {\n return { tag: \"article\", attr: { id, class: \"sample-card\" }, children: [\n group([text(\"span\", number, \"sample-number\"), text(\"h3\", title)], \"card-heading\"),\n text(\"p\", description, \"card-description\"), ...children\n ] };\n}\n\n// Add <div id=\"example\"></div> to the page.\nnew ExampleRenderer(document.getElementById(\"example\"), true).render(\n card(\"select-custom\", \"04\", \"More than a label\", \"Custom rows add useful details about each person.\", [\n field(\"select-owner\", \"Project owner\", member), memberStatus,\n text(\"p\", \"Search also matches each person's role.\", \"inline-note\")\n ])\n);",
35
35
  "select-states": "import \"../../ui/base.css\";\nimport \"./showcase.css\";\nimport { IJSLComponent, IJSLVNode } from \"jsl-render\";\nimport { SelectComponent } from \"../../components/select/SelectComponent\";\nimport { JSLRender as ExampleRenderer } from \"jsl-render\";\n\ntype Content = IJSLVNode | IJSLComponent;\n\nconst text = (tag: string, content: string, className?: string): IJSLVNode => ({ tag, content, attr: { class: className } });\n\nconst group = (children: Content[], className?: string): IJSLVNode => ({ tag: \"div\", attr: { class: className }, children });\n\nconst field = (id: string, label: string, control: Content) => group([\n { tag: \"label\", content: label, attr: { for: id } }, control\n], \"select-showcase-field\");\n\nconst projects = [\n { value: \"website\", text: \"Website refresh\" }, { value: \"library\", text: \"Component library\" },\n { value: \"workspace\", text: \"Team workspace\" }, { value: \"mobile\", text: \"Mobile experience\" },\n { value: \"research\", text: \"Customer research\" }, { value: \"release\", text: \"Autumn release\" }\n];\n\nconst skills = [\n { value: \"design\", text: \"Design\" }, { value: \"typescript\", text: \"TypeScript\" },\n { value: \"accessibility\", text: \"Accessibility\" }, { value: \"testing\", text: \"Testing\" },\n { value: \"research\", text: \"Research\" }, { value: \"documentation\", text: \"Documentation\" }\n];\n\nfunction card(id: string, number: string, title: string, description: string, children: Content[]): IJSLVNode {\n return { tag: \"article\", attr: { id, class: \"sample-card\" }, children: [\n group([text(\"span\", number, \"sample-number\"), text(\"h3\", title)], \"card-heading\"),\n text(\"p\", description, \"card-description\"), ...children\n ] };\n}\n\n// Add <div id=\"example\"></div> to the page.\nnew ExampleRenderer(document.getElementById(\"example\"), true).render(\n card(\"select-states\", \"05\", \"The right level of choice\", \"Search can be omitted for short lists. Required selections and disabled controls share the same design.\", [\n field(\"select-required\", \"Default project\", new SelectComponent({\n id: \"select-required\", data: projects.slice(0, 3), value: \"library\", ariaLabel: \"Default project\",\n enableSearch: false, allowEmpty: false\n })),\n field(\"select-disabled\", \"Unavailable project\", new SelectComponent({\n id: \"select-disabled\", data: projects, value: \"website\", enabled: false, ariaLabel: \"Unavailable project\"\n })),\n field(\"select-disabled-multi\", \"Unavailable skills\", new SelectComponent({\n id: \"select-disabled-multi\", data: skills, multiple: true, value: [\"design\", \"testing\"], enabled: false, ariaLabel: \"Unavailable skills\"\n }))\n ])\n);",
36
36
  "select-scale": "import \"../../ui/base.css\";\nimport \"./showcase.css\";\nimport { IJSLComponent, IJSLVNode } from \"jsl-render\";\nimport { SelectComponent } from \"../../components/select/SelectComponent\";\nimport { JSLRender as ExampleRenderer } from \"jsl-render\";\n\ntype Content = IJSLVNode | IJSLComponent;\n\nconst text = (tag: string, content: string, className?: string): IJSLVNode => ({ tag, content, attr: { class: className } });\n\nconst group = (children: Content[], className?: string): IJSLVNode => ({ tag: \"div\", attr: { class: className }, children });\n\nconst status = (content: string): IJSLVNode => ({ tag: \"p\", content, attr: { class: \"sample-status\", role: \"status\" } });\n\nconst field = (id: string, label: string, control: Content) => group([\n { tag: \"label\", content: label, attr: { for: id } }, control\n], \"select-showcase-field\");\n\nconst largeStatus = status(\"Search by name or jump through the list with your keyboard.\");\n\nconst large = new SelectComponent({\n id: \"select-large\", data: Array.from({ length: 10000 }, (_, i) => ({ value: i + 1, text: \"Item \" + (\"00000\" + (i + 1)).slice(-5) })),\n value: 5000, ariaLabel: \"Large list\", dropdownHeight: \"18rem\", placeholder: \"Choose an item\",\n onChange: (value, item) => { largeStatus.content = item ? \"Selected \" + item.text + \", key \" + value : \"Selection cleared.\"; }\n});\n\nfunction card(id: string, number: string, title: string, description: string, children: Content[]): IJSLVNode {\n return { tag: \"article\", attr: { id, class: \"sample-card\" }, children: [\n group([text(\"span\", number, \"sample-number\"), text(\"h3\", title)], \"card-heading\"),\n text(\"p\", description, \"card-description\"), ...children\n ] };\n}\n\n// Add <div id=\"example\"></div> to the page.\nnew ExampleRenderer(document.getElementById(\"example\"), true).render(\n card(\"select-scale\", \"06\", \"Room for a long list\", \"Ten thousand options, with only the visible rows rendered. Selection stays in view when you open the list.\", [\n field(\"select-large\", \"Item\", large), largeStatus,\n text(\"p\", \"Type to search. Arrow keys move through results; Ctrl+Home and Ctrl+End jump to either end.\", \"inline-note\")\n ])\n);",
37
+ "select-server": "import \"../../ui/base.css\";\nimport \"./showcase.css\";\nimport { IJSLComponent, IJSLVNode } from \"jsl-render\";\nimport { SelectComponent } from \"../../components/select/SelectComponent\";\nimport { JSLRender as ExampleRenderer } from \"jsl-render\";\n\ntype Content = IJSLVNode | IJSLComponent;\n\nconst text = (tag: string, content: string, className?: string): IJSLVNode => ({ tag, content, attr: { class: className } });\n\nconst group = (children: Content[], className?: string): IJSLVNode => ({ tag: \"div\", attr: { class: className }, children });\n\nconst status = (content: string): IJSLVNode => ({ tag: \"p\", content, attr: { class: \"sample-status\", role: \"status\" } });\n\nconst field = (id: string, label: string, control: Content) => group([\n { tag: \"label\", content: label, attr: { for: id } }, control\n], \"select-showcase-field\");\n\nconst customerNames = Array.from({ length: 500 }, (_, i) => ({ value: i + 1, text: \"Customer \" + (\"000\" + (i + 1)).slice(-4) + \" \" + [\"Alpine\", \"Danube\", \"Linz\", \"Graz\", \"Tyrol\"][i % 5] }));\n\nconst remoteStatus = status(\"Open the list, type a name or scroll for more.\");\n\nlet remoteGeneration = 0;\n\nlet remoteFound: typeof customerNames = [];\n\nlet remoteTerm = \"\";\n\nfunction remoteLoad(append: boolean) {\n const generation = ++remoteGeneration;\n remote.setLoading(true);\n setTimeout(() => {\n if (generation !== remoteGeneration) { return; }\n const matches = customerNames.filter(item => item.text.toLowerCase().includes(remoteTerm.toLowerCase()));\n remoteFound = matches.slice(0, append ? remoteFound.length + 25 : 25);\n remote.setData(remoteFound, remoteFound.length < matches.length);\n remote.setLoading(false);\n remoteStatus.content = remoteFound.length + \" of \" + matches.length + \" matches loaded.\";\n }, 400);\n}\n\nconst remote: SelectComponent = new SelectComponent({\n id: \"select-remote\", data: [], ariaLabel: \"Customer\", placeholder: \"Choose a customer\", searchPlaceholder: \"Search customers…\",\n onOpen: () => { if (!remoteFound.length) { remoteLoad(false); } },\n onSearch: term => { remoteTerm = term; remoteLoad(false); },\n onLoadMore: () => remoteLoad(true)\n});\n\nfunction card(id: string, number: string, title: string, description: string, children: Content[]): IJSLVNode {\n return { tag: \"article\", attr: { id, class: \"sample-card\" }, children: [\n group([text(\"span\", number, \"sample-number\"), text(\"h3\", title)], \"card-heading\"),\n text(\"p\", description, \"card-description\"), ...children\n ] };\n}\n\n// Add <div id=\"example\"></div> to the page.\nnew ExampleRenderer(document.getElementById(\"example\"), true).render(\n card(\"select-server\", \"07\", \"Search on the server\", \"For lists too long to load. The one search box asks the server, and scrolling to the end loads more.\", [\n field(\"select-remote\", \"Customer\", remote), remoteStatus,\n text(\"pre\", '{ onSearch: term => load(term), onLoadMore: () => loadMore() } // answer with select.setData(items, hasMore)', \"sample-code\")\n ])\n);",
37
38
  "checkbox-basic": "import \"../../ui/base.css\";\nimport \"./showcase.css\";\nimport { IJSLComponent, IJSLVNode } from \"jsl-render\";\nimport { CheckBoxComponent } from \"../../components/checkbox/CheckBoxComponent\";\nimport { JSLRender as ExampleRenderer } from \"jsl-render\";\n\ntype Content = IJSLVNode | IJSLComponent;\n\nconst text = (tag: string, content: string, className?: string): IJSLVNode => ({ tag, content, attr: { class: className } });\n\nconst group = (children: Content[], className?: string): IJSLVNode => ({ tag: \"div\", attr: { class: className }, children });\n\nconst status = (content: string): IJSLVNode => ({ tag: \"p\", content, attr: { class: \"sample-status\", role: \"status\" } });\n\nfunction card(id: string, number: string, title: string, description: string, children: Content[]): IJSLVNode {\n return { tag: \"article\", attr: { id, class: \"sample-card\" }, children: [\n group([text(\"span\", number, \"sample-number\"), text(\"h3\", title)], \"card-heading\"),\n text(\"p\", description, \"card-description\"), ...children\n ] };\n}\n\nconst basicStatus = status(\"Email updates are off.\");\n\n// Add <div id=\"example\"></div> to the page.\nnew ExampleRenderer(document.getElementById(\"example\"), true).render(\n card(\"checkbox-basic\", \"01\", \"One clear choice\", \"Click the box or its label. Tab focuses the input; Space changes its state.\", [\n new CheckBoxComponent({ id: \"checkbox-basic-input\", label: \"Email me product updates\", onChange: checked => {\n basicStatus.content = checked ? \"Email updates are on.\" : \"Email updates are off.\";\n } }), basicStatus,\n text(\"pre\", '{ label: \"Email me product updates\", onChange: checked => { ... } }', \"sample-code\")\n ])\n);",
38
39
  "checkbox-states": "import \"../../ui/base.css\";\nimport \"./showcase.css\";\nimport { IJSLComponent, IJSLVNode } from \"jsl-render\";\nimport { CheckBoxComponent } from \"../../components/checkbox/CheckBoxComponent\";\nimport { JSLRender as ExampleRenderer } from \"jsl-render\";\n\ntype Content = IJSLVNode | IJSLComponent;\n\nconst text = (tag: string, content: string, className?: string): IJSLVNode => ({ tag, content, attr: { class: className } });\n\nconst group = (children: Content[], className?: string): IJSLVNode => ({ tag: \"div\", attr: { class: className }, children });\n\nfunction card(id: string, number: string, title: string, description: string, children: Content[]): IJSLVNode {\n return { tag: \"article\", attr: { id, class: \"sample-card\" }, children: [\n group([text(\"span\", number, \"sample-number\"), text(\"h3\", title)], \"card-heading\"),\n text(\"p\", description, \"card-description\"), ...children\n ] };\n}\n\n// Add <div id=\"example\"></div> to the page.\nnew ExampleRenderer(document.getElementById(\"example\"), true).render(\n card(\"checkbox-states\", \"02\", \"A little more context\", \"Supporting text explains a choice. Disabled controls keep their labels and current state.\", [\n group([\n new CheckBoxComponent({ id: \"checkbox-description\", label: \"Remember this workspace\", description: \"Open this workspace automatically the next time you sign in.\", value: true }),\n new CheckBoxComponent({ id: \"checkbox-disabled\", label: \"Managed by your administrator\", enabled: false }),\n new CheckBoxComponent({ id: \"checkbox-disabled-checked\", label: \"Security notifications\", value: true, enabled: false })\n ], \"checkbox-stack\")\n ])\n);",
39
40
  "checkbox-partial": "import \"../../ui/base.css\";\nimport \"./showcase.css\";\nimport { IJSLComponent, IJSLVNode } from \"jsl-render\";\nimport { CheckBoxComponent } from \"../../components/checkbox/CheckBoxComponent\";\nimport { JSLRender as ExampleRenderer } from \"jsl-render\";\n\ntype Content = IJSLVNode | IJSLComponent;\n\nconst text = (tag: string, content: string, className?: string): IJSLVNode => ({ tag, content, attr: { class: className } });\n\nconst group = (children: Content[], className?: string): IJSLVNode => ({ tag: \"div\", attr: { class: className }, children });\n\nconst status = (content: string): IJSLVNode => ({ tag: \"p\", content, attr: { class: \"sample-status\", role: \"status\" } });\n\nfunction card(id: string, number: string, title: string, description: string, children: Content[]): IJSLVNode {\n return { tag: \"article\", attr: { id, class: \"sample-card\" }, children: [\n group([text(\"span\", number, \"sample-number\"), text(\"h3\", title)], \"card-heading\"),\n text(\"p\", description, \"card-description\"), ...children\n ] };\n}\n\nconst partialStatus = status(\"1 of 3 channels selected.\");\n\nconst channels = [\"Product news\", \"Release notes\", \"Community events\"].map((label, index) => new CheckBoxComponent({\n id: \"checkbox-channel-\" + index, label, value: index === 0,\n onChange: () => syncChannels()\n}));\n\nconst allChannels = new CheckBoxComponent({\n id: \"checkbox-all\", label: \"All updates\", indeterminate: true,\n onChange: checked => { channels.forEach(channel => channel.setValue(checked)); syncChannels(); }\n});\n\nfunction syncChannels() {\n const count = channels.filter(channel => channel.getValue()).length;\n allChannels.setValue(count === channels.length);\n allChannels.indeterminate = count > 0 && count < channels.length;\n partialStatus.content = count + \" of \" + channels.length + \" channels selected.\";\n}\n\n// Add <div id=\"example\"></div> to the page.\nnew ExampleRenderer(document.getElementById(\"example\"), true).render(\n card(\"checkbox-partial\", \"03\", \"Some, all, or none\", \"A mixed parent summarizes its children. Activating it selects or clears the whole group.\", [\n group([allChannels, group(channels, \"checkbox-child-list\")], \"checkbox-stack\"), partialStatus,\n text(\"pre\", \"checkbox.indeterminate = true;\\ncheckbox.setValue(true); // Silent checked update\", \"sample-code\")\n ])\n);",
@@ -1,9 +1,11 @@
1
1
  import "./themes.css";
2
2
  import "./nivona.css";
3
+ import "./wirtshans.css";
3
4
 
4
5
  export const showcaseThemes = [
5
6
  { id: "default", label: "Default (neutral)" },
6
7
  { id: "nivona", label: "Nivona" },
8
+ { id: "wirtshans", label: "Wirtshans" },
7
9
  { id: "ocean", label: "Ocean" },
8
10
  { id: "forest", label: "Forest" },
9
11
  { id: "plum", label: "Plum" },
@@ -0,0 +1,65 @@
1
+ /* Wirtshans website palette and typography; interaction shades are UI derivatives. */
2
+ @font-face {
3
+ font-family: "Figtree";
4
+ src: url("./fonts/Figtree-Variable.ttf") format("truetype");
5
+ font-style: normal;
6
+ font-weight: 300 900;
7
+ font-display: swap;
8
+ }
9
+
10
+ @font-face {
11
+ font-family: "Bricolage Grotesque";
12
+ src: url("./fonts/BricolageGrotesque-Variable.ttf") format("truetype");
13
+ font-style: normal;
14
+ font-weight: 200 800;
15
+ font-display: swap;
16
+ }
17
+
18
+ :root[data-showcase-theme="wirtshans"] {
19
+ color-scheme: light;
20
+ font-family: "Figtree", Arial, sans-serif;
21
+
22
+ --jsl-color-canvas: #f7f5f0;
23
+ --jsl-color-surface: #ffffff;
24
+ --jsl-color-surface-subtle: #f7f5f0;
25
+ --jsl-color-surface-hover: #efebe3;
26
+ --jsl-color-surface-selected: #fbf1dc;
27
+ --jsl-color-border: #b9b2a5;
28
+ --jsl-color-border-subtle: #e2ded5;
29
+ --jsl-color-text: #141312;
30
+ --jsl-color-text-secondary: #5c5a55;
31
+ --jsl-color-text-muted: #68645c;
32
+ --jsl-color-accent: #e3a72f;
33
+ --jsl-color-accent-hover: #cf9220;
34
+ --jsl-color-accent-active: #b47b16;
35
+ --jsl-color-on-accent: #141312;
36
+ --jsl-color-focus: #8a5a00;
37
+ --jsl-color-disabled-surface: #efebe3;
38
+ --jsl-color-disabled-text: #777168;
39
+ --jsl-color-overlay: rgba(20, 19, 18, 0.55);
40
+ --jsl-shadow-dialog: 0 18px 44px rgba(20, 19, 18, 0.18);
41
+ --jsl-button-radius: 999px;
42
+ --jsl-dialog-radius: 22px;
43
+ }
44
+
45
+ :root[data-showcase-theme="wirtshans"] :is(h1, h2, h3, h4) {
46
+ font-family: "Bricolage Grotesque", "Figtree", Arial, sans-serif;
47
+ color: var(--jsl-color-text);
48
+ font-weight: 700;
49
+ }
50
+
51
+ :root[data-showcase-theme="wirtshans"] :is(.sample-card, .usage, .context-panel, .hero-preview) {
52
+ border-radius: 16px;
53
+ }
54
+
55
+ :root[data-showcase-theme="wirtshans"] .nav-item[aria-current] {
56
+ box-shadow: inset 3px 0 #e3a72f;
57
+ }
58
+
59
+ :root[data-showcase-theme="wirtshans"] .eyebrow {
60
+ color: #8a5a00;
61
+ }
62
+
63
+ :root[data-showcase-theme="wirtshans"] .status-dot {
64
+ background: #8a5a00;
65
+ }
@@ -39,6 +39,23 @@ export interface ISelectComponentOptions<T = any, TValue = any, TBinding = any>
39
39
  onRender?: (args: ISelectRenderArg<T>) => void | IJSLVNode;
40
40
  onRenderGroup?: (args: ISelectRenderGroupArg) => void | IJSLVNode;
41
41
  matchSearch?: (data: T, term: string) => boolean;
42
+ /**
43
+ * Switches to server-side search: the typed text is no longer matched against `data`. After `searchDelay` ms of
44
+ * typing (and with "" when the list opens with a stale search) this is called with the term; the owner answers
45
+ * with setData() and setLoading(). `matchSearch` is ignored.
46
+ */
47
+ onSearch?: (term: string) => void;
48
+ /** Milliseconds to wait after the last keystroke before onSearch runs. Default 300. */
49
+ searchDelay?: number;
50
+ /** Called whenever the list opens, for example to load the first batch lazily. */
51
+ onOpen?: () => void;
52
+ /**
53
+ * Called when the list is scrolled near its end while setData() reported more items. Start loading and call
54
+ * setLoading(true) at once; finish with setData(all items so far, hasMore) and setLoading(false).
55
+ */
56
+ onLoadMore?: () => void;
57
+ /** Shown at the end of the list while setLoading(true) is active. */
58
+ loadingText?: string;
42
59
  onAppend?: (dom: HTMLDivElement) => void;
43
60
  enableKeyboard?: boolean;
44
61
  multiple?: boolean;
@@ -72,6 +89,11 @@ export declare class SelectComponent<T = any, TValue = any, TBinding = any> impl
72
89
  private dropdownLimit;
73
90
  private disposed;
74
91
  private expandedBeforePress;
92
+ private loading;
93
+ private hasMore;
94
+ private moreRequested;
95
+ private searchedTerm;
96
+ private searchTimer;
75
97
  constructor(o: ISelectComponentOptions<T, TValue, TBinding>);
76
98
  render(): IJSLVNode;
77
99
  onCreate(node: IJSLVNode): void;
@@ -92,6 +114,19 @@ export declare class SelectComponent<T = any, TValue = any, TBinding = any> impl
92
114
  setValue(value: any): void;
93
115
  getSelected(): T | T[];
94
116
  setSelected(item: T | T[]): void;
117
+ /**
118
+ * Replaces the options, for example with the answer to onSearch or with more items for onLoadMore. The current
119
+ * selection is kept even when it is not part of the new data. `hasMore` tells whether onLoadMore may be called.
120
+ */
121
+ setData(data: T[], hasMore?: boolean): void;
122
+ /** Shows or hides the loading hint at the end of the list. Call with false when a search or load has finished. */
123
+ setLoading(loading: boolean): void;
124
+ /** @internal Used by the dropdown. */
125
+ isLoading(): boolean;
126
+ /** @internal Used by the dropdown: the typed text changed. Runs onSearch after searchDelay unless `immediate`. */
127
+ requestSearch(term: string, immediate?: boolean): void;
128
+ /** @internal Used by the dropdown: the end of the list is near. */
129
+ requestMore(): void;
95
130
  focus(): void;
96
131
  hasSelection(): boolean;
97
132
  protected renderSelection(): IJSLVNode;
@@ -13,6 +13,11 @@ export class SelectComponent {
13
13
  this.dropdownLimit = 0;
14
14
  this.disposed = false;
15
15
  this.expandedBeforePress = false;
16
+ // Server-side search state. searchedTerm is the term onSearch last ran with.
17
+ this.loading = false;
18
+ this.hasMore = false;
19
+ this.moreRequested = false;
20
+ this.searchedTerm = "";
16
21
  this.onOutsidePress = (event) => {
17
22
  var _a, _b;
18
23
  if (!((_a = this.dom) === null || _a === void 0 ? void 0 : _a.contains(event.target)) && !((_b = this.dropdownArea) === null || _b === void 0 ? void 0 : _b.contains(event.target))) {
@@ -63,7 +68,7 @@ export class SelectComponent {
63
68
  enableKeyboard: true, rowHeight: 36, allowEmpty: true, enabled: true,
64
69
  openOnEnter: true, focusFirstItem: true, autoShrink: true, bindMode: "toModel",
65
70
  searchPlaceholder: "Search options…", emptyText: "No matching options",
66
- clearButtonLabel: "Clear selection",
71
+ clearButtonLabel: "Clear selection", searchDelay: 300, loadingText: "Loading…",
67
72
  onRenderGroup: args => { var _a; args.node.content = String((_a = args.groupValue) !== null && _a !== void 0 ? _a : ""); },
68
73
  matchSearch: (data, term) => { var _a; return String((_a = data[this.options.textColumn]) !== null && _a !== void 0 ? _a : "").toLowerCase().includes(term.toLowerCase()); },
69
74
  ...o, data: (_a = o.data) !== null && _a !== void 0 ? _a : []
@@ -147,7 +152,7 @@ export class SelectComponent {
147
152
  isExpanded() { return this.expanded; }
148
153
  getListId() { return this.listId; }
149
154
  show(searchTxt) {
150
- var _a, _b, _c;
155
+ var _a, _b, _c, _d, _e;
151
156
  if (!this.options.enabled || this.disposed || !this.dom || this.expanded) {
152
157
  return;
153
158
  }
@@ -174,7 +179,7 @@ export class SelectComponent {
174
179
  }
175
180
  if (this.options.autoShrink) {
176
181
  const contentHeight = (data.length ? data.length * this.options.rowHeight : 64) +
177
- (this.options.enableSearch ? 48 : 0) + 8;
182
+ (this.options.enableSearch ? 48 : 0) + 8 + (this.loading ? 28 : 0);
178
183
  this.dropdownArea.style.height = Math.min(contentHeight, this.dropdownLimit) + "px";
179
184
  }
180
185
  this.positionDropdown();
@@ -184,12 +189,17 @@ export class SelectComponent {
184
189
  this.dropdownRenderer.render(this.dropdownComponent);
185
190
  JSLRender.lastCreatedRenderer = previousRenderer;
186
191
  this.positionDropdown();
192
+ // A fresh list starts with an empty search; make the owner drop results of an earlier search.
193
+ if (this.options.onSearch && !searchTxt) {
194
+ this.requestSearch("", true);
195
+ }
196
+ (_d = (_c = this.options).onOpen) === null || _d === void 0 ? void 0 : _d.call(_c);
187
197
  document.addEventListener("mousedown", this.onOutsidePress, true);
188
198
  document.addEventListener("touchstart", this.onOutsidePress, true);
189
199
  document.addEventListener("focusin", this.onDocumentFocus);
190
200
  window.addEventListener("resize", this.positionDropdown);
191
201
  window.addEventListener("scroll", this.onWindowScroll, true);
192
- (_c = this.renderer) === null || _c === void 0 ? void 0 : _c.refresh();
202
+ (_e = this.renderer) === null || _e === void 0 ? void 0 : _e.refresh();
193
203
  this.updateTriggerAria();
194
204
  this.focusFrame = requestAnimationFrame(() => {
195
205
  var _a;
@@ -212,6 +222,7 @@ export class SelectComponent {
212
222
  cancelAnimationFrame(this.focusFrame);
213
223
  this.focusFrame = undefined;
214
224
  }
225
+ clearTimeout(this.searchTimer);
215
226
  const wasExpanded = this.expanded;
216
227
  this.expanded = false;
217
228
  this.focused = null;
@@ -264,6 +275,60 @@ export class SelectComponent {
264
275
  this.options.onChange.notify(value, this.selected);
265
276
  this.refresh();
266
277
  }
278
+ /**
279
+ * Replaces the options, for example with the answer to onSearch or with more items for onLoadMore. The current
280
+ * selection is kept even when it is not part of the new data. `hasMore` tells whether onLoadMore may be called.
281
+ */
282
+ setData(data, hasMore = false) {
283
+ var _a;
284
+ const key = this.options.keyColumn;
285
+ this.options.data = data !== null && data !== void 0 ? data : [];
286
+ this.hasMore = hasMore;
287
+ this.moreRequested = false;
288
+ // Selection and focus compare by identity: point them at the new objects.
289
+ const current = (item) => { var _a; return (_a = this.options.data.find(candidate => candidate[key] === item[key])) !== null && _a !== void 0 ? _a : item; };
290
+ if (this.selected != null) {
291
+ this.selected = this.options.multiple ? this.selected.map(current) : current(this.selected);
292
+ }
293
+ (_a = this.dropdownComponent) === null || _a === void 0 ? void 0 : _a.dataChanged();
294
+ this.refresh();
295
+ }
296
+ /** Shows or hides the loading hint at the end of the list. Call with false when a search or load has finished. */
297
+ setLoading(loading) {
298
+ this.loading = loading;
299
+ if (!loading) {
300
+ this.moreRequested = false;
301
+ }
302
+ this.refresh();
303
+ }
304
+ /** @internal Used by the dropdown. */
305
+ isLoading() { return this.loading; }
306
+ /** @internal Used by the dropdown: the typed text changed. Runs onSearch after searchDelay unless `immediate`. */
307
+ requestSearch(term, immediate = false) {
308
+ clearTimeout(this.searchTimer);
309
+ if (term === this.searchedTerm) {
310
+ return;
311
+ }
312
+ const run = () => {
313
+ this.searchedTerm = term;
314
+ this.moreRequested = false;
315
+ this.options.onSearch(term);
316
+ };
317
+ if (immediate) {
318
+ run();
319
+ }
320
+ else {
321
+ this.searchTimer = setTimeout(run, this.options.searchDelay);
322
+ }
323
+ }
324
+ /** @internal Used by the dropdown: the end of the list is near. */
325
+ requestMore() {
326
+ if (!this.options.onLoadMore || !this.hasMore || this.loading || this.moreRequested) {
327
+ return;
328
+ }
329
+ this.moreRequested = true;
330
+ this.options.onLoadMore();
331
+ }
267
332
  focus() {
268
333
  var _a;
269
334
  if (this.dom) {
@@ -315,14 +380,23 @@ export class SelectComponent {
315
380
  return node;
316
381
  }
317
382
  selectValue(value) {
318
- var _a;
383
+ var _a, _b;
319
384
  if (value == null) {
320
385
  this.selected = this.options.multiple ? [] : null;
321
386
  return;
322
387
  }
323
- this.selected = this.options.multiple ?
324
- this.options.data.filter(item => Array.isArray(value) && value.indexOf(item[this.options.keyColumn]) >= 0) :
325
- (_a = this.options.data.find(item => item[this.options.keyColumn] === value)) !== null && _a !== void 0 ? _a : null;
388
+ const key = this.options.keyColumn;
389
+ // Items the current data no longer lists (after setData) stay selectable by their key.
390
+ const previous = this.selected == null ? [] : Array.isArray(this.selected) ? this.selected : [this.selected];
391
+ if (this.options.multiple) {
392
+ const keys = Array.isArray(value) ? value : [];
393
+ const listed = this.options.data.filter(item => keys.indexOf(item[key]) >= 0);
394
+ this.selected = [...listed, ...previous.filter(item => keys.indexOf(item[key]) >= 0 &&
395
+ !listed.some(other => other[key] === item[key]))];
396
+ }
397
+ else {
398
+ this.selected = (_b = (_a = this.options.data.find(item => item[key] === value)) !== null && _a !== void 0 ? _a : previous.find(item => item[key] === value)) !== null && _b !== void 0 ? _b : null;
399
+ }
326
400
  }
327
401
  refresh() { var _a, _b; (_a = this.renderer) === null || _a === void 0 ? void 0 : _a.refresh(); (_b = this.dropdownRenderer) === null || _b === void 0 ? void 0 : _b.refresh(); }
328
402
  focusWithoutOpening() {
@@ -19,14 +19,20 @@ export declare class SelectDDAreaComponent implements IJSLComponent {
19
19
  private searchText;
20
20
  private optionPositions;
21
21
  private optionCount;
22
+ private removed;
22
23
  constructor(options: ISelectComponentOptions<any>, component: SelectComponent, args: IDDArguments);
23
24
  onInit(renderer: JSLRender): void;
24
25
  onCreate(node: IJSLVNode): void;
26
+ onRemove(): void;
25
27
  render(): IJSLVNode;
26
28
  navigateDown(): void;
27
29
  navigateUp(): void;
28
30
  search(term: string): void;
31
+ /** The owner replaced the data: keep the focused item if it is still listed, otherwise focus the first. */
32
+ dataChanged(): void;
29
33
  clearSearch(): void;
34
+ private checkLoadMore;
35
+ private checkLoadMoreSoon;
30
36
  private isGroup;
31
37
  private renderRow;
32
38
  private focusFirst;