@protobase/ui 0.12.11 → 0.12.12

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.
@@ -1,25 +1,40 @@
1
1
  //#region src/live/view-fields.ts
2
- /** The widgets of a view in the shape `filter-string` talks to; options and counts are filled in later. */
2
+ const numberTypes = [
3
+ "integer",
4
+ "bigint",
5
+ "decimal"
6
+ ];
7
+ const isNumber = (model, field) => {
8
+ const type = model?.fields[field]?.type;
9
+ return type !== void 0 && numberTypes.includes(type);
10
+ };
11
+ /** A filter on a number field is a range slider, whichever widget the view asked for. */
12
+ const rangeOf = (widget, model) => widget.kind === "range" || widget.kind === "facets" && isNumber(model, widget.field);
13
+ const emptyRange = (field) => ({
14
+ id: field,
15
+ label: field,
16
+ min: 0,
17
+ max: 0,
18
+ step: 1,
19
+ histogram: [],
20
+ format: String
21
+ });
22
+ /**
23
+ * The widgets of a view in the shape `filter-string` talks to; options and counts are filled in later. Facets on a
24
+ * reference to another resource's records are a combobox, which searches those records.
25
+ */
3
26
  const widgetFields = (view, model) => {
4
27
  const widgets = view?.filters ?? [];
5
- const range = widgets.find((widget) => widget.kind === "range");
6
28
  const date = widgets.find((widget) => widget.kind === "dateRange");
7
29
  return {
8
- facets: widgets.flatMap((widget) => widget.kind === "facets" ? [{
30
+ facets: widgets.flatMap((widget) => widget.kind === "facets" && !rangeOf(widget, model) ? [{
9
31
  id: widget.field,
10
32
  label: widget.field,
11
33
  options: [],
12
- searchable: widget.search
34
+ searchable: widget.search,
35
+ ...model?.fields[widget.field]?.type === "relation" && { combobox: true }
13
36
  }] : []),
14
- ...range && { range: {
15
- id: range.field,
16
- label: range.field,
17
- min: 0,
18
- max: 0,
19
- step: 1,
20
- histogram: [],
21
- format: String
22
- } },
37
+ ranges: widgets.flatMap((widget) => rangeOf(widget, model) ? [emptyRange(widget.field)] : []),
23
38
  ...date && {
24
39
  dateField: date.field,
25
40
  dateKind: model?.fields[date.field]?.type === "date" ? "date" : "timestamp",
@@ -31,5 +46,7 @@ const widgetFields = (view, model) => {
31
46
  }] : [])
32
47
  };
33
48
  };
49
+ /** Whether a range draws its histogram: only a `range` widget that asks for one. */
50
+ const rangeHistogram = (view, field) => (view?.filters ?? []).some((widget) => widget.kind === "range" && widget.field === field && widget.histogram);
34
51
  //#endregion
35
- export { widgetFields };
52
+ export { rangeHistogram, widgetFields };
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.12.11";
2
+ var version = "0.12.12";
3
3
  var protobase = { "pluginApi": 1 };
4
4
  //#endregion
5
5
  export { protobase, version };