@kronor/dtv 13.0.0 → 13.0.2

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.
@@ -53,6 +53,21 @@ function compareFilters(from, to, change) {
53
53
  from.children.forEach((child, index) => compareFilters(child, to.children[index], change));
54
54
  }
55
55
  }
56
+ const takesOneValue = (control) => control.type === 'dropdown' || (control.type === 'autocomplete' && !control.multiple);
57
+ const takesList = (control) => control.type === 'multiselect' || (control.type === 'autocomplete' && control.multiple);
58
+ /** The comparison of a filter taking one value, by the comparison of the same filter taking a list of them. */
59
+ const LIST_COMPARISONS = new Map([['equals', 'in'], ['notEquals', 'notIn']]);
60
+ /**
61
+ * Whether `to` takes a list of the values `from` took one of, on the same field (a dropdown
62
+ * became a multiselect): what is stored for it carries over as a list of one value. As the
63
+ * DSL's `WrapsInList`.
64
+ */
65
+ function wrapsInList(from, to) {
66
+ return from.kind === 'leaf' && to.kind === 'leaf'
67
+ && takesOneValue(from.control) && takesList(to.control)
68
+ && deepEqual(from.field, to.field)
69
+ && (from.cmp === to.cmp || LIST_COMPARISONS.get(from.cmp) === to.cmp);
70
+ }
56
71
  function operatorsOf(filter) {
57
72
  switch (filter.kind) {
58
73
  case 'leaf':
@@ -134,6 +149,13 @@ export function generateOps(from, to) {
134
149
  continue;
135
150
  const change = { structure: null, operatorsChanged: false, meaning: [] };
136
151
  compareFilters(from.filters[filterId], toFilter, change);
152
+ if (change.structure !== null && wrapsInList(from.filters[filterId], toFilter)) {
153
+ ops.push(op(`m.wrapInList(${quote(filterId)})`, [
154
+ `"${filterId}" takes several values now: a value stored for it becomes a list of that value.`,
155
+ `To start it over instead: m.reset(${quote(filterId)})`
156
+ ]));
157
+ continue;
158
+ }
137
159
  if (change.structure !== null) {
138
160
  reset.add(filterId);
139
161
  ops.push(op(`m.reset(${quote(filterId)})`, [