@react-fabric/searchbar 1.0.0-beta.8 → 1.0.1

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.
Files changed (54) hide show
  1. package/dist/cjs/filterbar/Context.js +1 -1
  2. package/dist/cjs/filterbar/FilterBar.js +28 -23
  3. package/dist/cjs/filterbar/FilterEdit.js +7 -4
  4. package/dist/cjs/filterbar/FilterForm.js +176 -56
  5. package/dist/cjs/filterbar/FilterMenu.js +23 -12
  6. package/dist/cjs/filterbar/FilterTag.js +30 -20
  7. package/dist/cjs/filterbar/FilterView.js +11 -6
  8. package/dist/cjs/filterbar/QueryForm.js +47 -24
  9. package/dist/cjs/i18n/{ar.json.js → ar/searchbar.json.js} +43 -39
  10. package/dist/cjs/i18n/{en.json.js → en/searchbar.json.js} +43 -39
  11. package/dist/cjs/i18n/index.js +4 -4
  12. package/dist/cjs/index.js +28 -0
  13. package/dist/cjs/searchbar/SearchBar.js +58 -16
  14. package/dist/cjs/types/index.js +13 -4
  15. package/dist/esm/filterbar/Context.js +2 -2
  16. package/dist/esm/filterbar/FilterBar.js +30 -25
  17. package/dist/esm/filterbar/FilterEdit.js +7 -4
  18. package/dist/esm/filterbar/FilterForm.js +179 -59
  19. package/dist/esm/filterbar/FilterMenu.js +24 -13
  20. package/dist/esm/filterbar/FilterTag.js +32 -22
  21. package/dist/esm/filterbar/FilterView.js +11 -6
  22. package/dist/esm/filterbar/QueryForm.js +48 -25
  23. package/dist/esm/i18n/{ar.json.js → ar/searchbar.json.js} +43 -39
  24. package/dist/esm/i18n/{en.json.js → en/searchbar.json.js} +43 -39
  25. package/dist/esm/i18n/index.js +2 -2
  26. package/dist/esm/index.js +30 -0
  27. package/dist/esm/searchbar/SearchBar.js +59 -17
  28. package/dist/esm/types/index.js +13 -4
  29. package/dist/types/filterbar/Context.d.ts +2 -3
  30. package/dist/types/filterbar/FilterBar.d.ts +23 -1
  31. package/dist/types/filterbar/FilterEdit.d.ts +2 -2
  32. package/dist/types/filterbar/FilterForm.d.ts +3 -3
  33. package/dist/types/filterbar/FilterMenu.d.ts +3 -2
  34. package/dist/types/filterbar/FilterTag.d.ts +3 -2
  35. package/dist/types/filterbar/FilterView.d.ts +2 -2
  36. package/dist/types/filterbar/QueryForm.d.ts +2 -2
  37. package/dist/types/index.d.ts +27 -1
  38. package/dist/types/searchbar/SearchBar.d.ts +30 -1
  39. package/dist/types/types/index.d.ts +23 -14
  40. package/package.json +16 -19
  41. package/src/filterbar/Context.tsx +5 -5
  42. package/src/filterbar/FilterBar.tsx +58 -75
  43. package/src/filterbar/FilterEdit.tsx +9 -16
  44. package/src/filterbar/FilterForm.tsx +149 -85
  45. package/src/filterbar/FilterMenu.tsx +29 -16
  46. package/src/filterbar/FilterTag.tsx +30 -43
  47. package/src/filterbar/FilterView.tsx +13 -24
  48. package/src/filterbar/QueryForm.tsx +26 -43
  49. package/src/i18n/{ar.json → ar/searchbar.json} +43 -39
  50. package/src/i18n/{en.json → en/searchbar.json} +43 -39
  51. package/src/i18n/index.ts +2 -2
  52. package/src/index.ts +23 -18
  53. package/src/searchbar/SearchBar.tsx +67 -40
  54. package/src/types/index.ts +38 -70
@@ -3,9 +3,10 @@
3
3
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
4
4
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
5
  import { useFloatingTree } from '@floating-ui/react';
6
- import { Row, Col, Button } from '@react-fabric/core';
7
- import { Field, Controller, Switch, Select, Input, Number, Form } from '@react-fabric/form';
8
- import { yup, shortHash, isArray } from '@react-fabric/utilities';
6
+ import { yupResolver } from '@hookform/resolvers/yup';
7
+ import { Row, Col, DropdownDismiss, Button } from '@react-fabric/core';
8
+ import { Field, Controller, Switch, Select, Input, Textarea, Number, DateInput, Form } from '@react-fabric/form';
9
+ import { yup, isDefined, shortHash, isArray } from '@react-fabric/utilities';
9
10
  import { useRef, useState, useEffect, useMemo, useCallback } from 'react';
10
11
  import { useTranslation } from 'react-i18next';
11
12
  import { OPERATOR, TypeOperators, FIELD_TYPE } from '../types/index.js';
@@ -15,8 +16,9 @@ import { jsx, jsxs } from 'react/jsx-runtime';
15
16
  var FilterSchema = new yup.ObjectSchema({
16
17
  id: yup.string().required(),
17
18
  field: yup.string().required(),
19
+ // type: yup.string().oneOf(Object.values(FIELD_TYPE)),
18
20
  operator: yup.string().required().oneOf(Object.values(OPERATOR)),
19
- negate: yup["boolean"](),
21
+ negate: yup["boolean"]().optional(),
20
22
  label: yup.string(),
21
23
  value: yup.mixed().when("operator", {
22
24
  is: OPERATOR.EXISTS,
@@ -27,20 +29,56 @@ var FilterSchema = new yup.ObjectSchema({
27
29
  return schema.required();
28
30
  }
29
31
  }).when("operator", {
30
- is: OPERATOR.IN,
32
+ is: OPERATOR.ANY,
31
33
  then: function then(schema) {
32
34
  return schema.test({
33
35
  name: "array-check",
34
36
  message: "${path} is a required field",
35
37
  test: function test() {
36
38
  var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
37
- return (val === null || val === void 0 ? void 0 : val.length) > 0;
39
+ return val.length > 0;
40
+ }
41
+ });
42
+ }
43
+ }).when("operator", {
44
+ is: OPERATOR.ALL,
45
+ then: function then(schema) {
46
+ return schema.test({
47
+ name: "array-check",
48
+ message: "${path} is a required field",
49
+ test: function test() {
50
+ var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
51
+ return val.length > 0;
52
+ }
53
+ });
54
+ }
55
+ }).when("operator", {
56
+ is: OPERATOR.BETWEEN,
57
+ then: function then(schema) {
58
+ return schema.test({
59
+ name: "array-check",
60
+ message: "${path} is a required field",
61
+ test: function test() {
62
+ var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
63
+ return val.length > 0 && isDefined(val[0]) && isDefined(val[1]);
64
+ }
65
+ });
66
+ }
67
+ }).when("operator", {
68
+ is: OPERATOR.BETWEEN,
69
+ then: function then(schema) {
70
+ return schema.test({
71
+ name: "array-check",
72
+ message: "${path} min max",
73
+ test: function test() {
74
+ var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
75
+ return val.length > 0 && val[0] < val[1];
38
76
  }
39
77
  });
40
78
  }
41
79
  })
42
80
  });
43
- var FilterForm = function FilterForm(_ref) {
81
+ function FilterForm(_ref) {
44
82
  var filter = _ref.filter,
45
83
  onChange = _ref.onChange,
46
84
  onRemove = _ref.onRemove;
@@ -52,30 +90,41 @@ var FilterForm = function FilterForm(_ref) {
52
90
  fields = _useFilterContext$fie === void 0 ? [] : _useFilterContext$fie;
53
91
  var inputRef = useRef(null);
54
92
  var formRef = useRef(null);
55
- var _useState = useState(filter),
93
+ var _useState = useState(function () {
94
+ return filter;
95
+ }),
56
96
  _useState2 = _slicedToArray(_useState, 2),
57
97
  values = _useState2[0],
58
98
  setValues = _useState2[1];
99
+ console.log(values);
59
100
  useEffect(function () {
60
- var _formRef$current, _formRef$current2;
61
- if (filter && "field" in filter && filter.field) return (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.setValues(filter);
62
- (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || _formRef$current2.setValues({
63
- id: shortHash(),
64
- field: "",
65
- operator: OPERATOR.EXISTS
66
- });
101
+ if (filter && "field" in filter && filter.field) {
102
+ var _formRef$current;
103
+ (_formRef$current = formRef.current) === null || _formRef$current === void 0 || _formRef$current.setValues(filter);
104
+ } else {
105
+ var _formRef$current2;
106
+ (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || _formRef$current2.setValues({
107
+ id: shortHash(),
108
+ field: "",
109
+ operator: OPERATOR.EXISTS
110
+ });
111
+ }
67
112
  }, [filter]);
68
113
  useEffect(function () {
69
- setTimeout(function () {
114
+ var tmr = setTimeout(function () {
70
115
  var _inputRef$current;
71
116
  (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
72
117
  }, 100);
118
+ return function () {
119
+ clearTimeout(tmr);
120
+ };
73
121
  }, []);
74
122
  var field = useMemo(function () {
75
123
  if (!(values !== null && values !== void 0 && values.field)) return undefined;
76
124
  return fields.find(function (f) {
77
125
  return f.field === (values === null || values === void 0 ? void 0 : values.field);
78
126
  });
127
+ // eslint-disable-next-line @eslint-react/exhaustive-deps
79
128
  }, [values]);
80
129
  var operators = useMemo(function () {
81
130
  var _formRef$current3;
@@ -89,24 +138,24 @@ var FilterForm = function FilterForm(_ref) {
89
138
  (_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 || _formRef$current4.setValue("value", undefined);
90
139
  }
91
140
  if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.STRING) {
92
- if ((values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.IN) {
141
+ if (values !== null && values !== void 0 && values.operator && [OPERATOR.ALL, OPERATOR.ANY].includes(values.operator)) {
93
142
  var _formRef$current5;
94
- !isArray(values.value) && ((_formRef$current5 = formRef.current) === null || _formRef$current5 === void 0 ? void 0 : _formRef$current5.setValue("value", []));
143
+ if (!isArray(values === null || values === void 0 ? void 0 : values.value)) (_formRef$current5 = formRef.current) === null || _formRef$current5 === void 0 || _formRef$current5.setValue("value", []);
95
144
  } else {
96
145
  var _formRef$current6;
97
- isArray(values.value) && ((_formRef$current6 = formRef.current) === null || _formRef$current6 === void 0 ? void 0 : _formRef$current6.setValue("value", undefined));
146
+ if (isArray(values === null || values === void 0 ? void 0 : values.value)) (_formRef$current6 = formRef.current) === null || _formRef$current6 === void 0 || _formRef$current6.setValue("value", undefined);
98
147
  }
99
148
  }
100
- if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.NUMBER || (field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.DECIMAL) {
149
+ if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.DATE || (field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.DATETIME || (field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.NUMBER || (field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.DECIMAL) {
101
150
  if ((values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.BETWEEN) {
102
151
  var _formRef$current7;
103
- !isArray(values.value) && ((_formRef$current7 = formRef.current) === null || _formRef$current7 === void 0 ? void 0 : _formRef$current7.setValue("value", []));
152
+ if (!isArray(values.value)) (_formRef$current7 = formRef.current) === null || _formRef$current7 === void 0 || _formRef$current7.setValue("value", []);
104
153
  } else {
105
154
  var _formRef$current8;
106
- isArray(values.value) && ((_formRef$current8 = formRef.current) === null || _formRef$current8 === void 0 ? void 0 : _formRef$current8.setValue("value", undefined));
155
+ if (isArray(values === null || values === void 0 ? void 0 : values.value)) (_formRef$current8 = formRef.current) === null || _formRef$current8 === void 0 || _formRef$current8.setValue("value", undefined);
107
156
  }
108
157
  }
109
- if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.BOOLEAN && (values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.IS && (values === null || values === void 0 ? void 0 : values.value) === undefined) {
158
+ if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.BOOLEAN && values !== null && values !== void 0 && values.operator && [OPERATOR.IS, OPERATOR.EQ].includes(values.operator) && (values === null || values === void 0 ? void 0 : values.value) === undefined) {
110
159
  var _formRef$current9;
111
160
  (_formRef$current9 = formRef.current) === null || _formRef$current9 === void 0 || _formRef$current9.setValue("value", false);
112
161
  }
@@ -123,7 +172,8 @@ var FilterForm = function FilterForm(_ref) {
123
172
  });
124
173
  }
125
174
  if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.STRING || (field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.ID) {
126
- if ((values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.IN) {
175
+ var _field$values2;
176
+ if ([OPERATOR.ALL, OPERATOR.ANY].includes(values === null || values === void 0 ? void 0 : values.operator)) {
127
177
  var _field$values;
128
178
  return /*#__PURE__*/jsx(Controller, {
129
179
  name: "value",
@@ -137,6 +187,19 @@ var FilterForm = function FilterForm(_ref) {
137
187
  onQuery: field.onSearch
138
188
  })
139
189
  });
190
+ } else if (!!field.onSearch || (_field$values2 = field.values) !== null && _field$values2 !== void 0 && _field$values2.length) {
191
+ var _field$values3;
192
+ return /*#__PURE__*/jsx(Controller, {
193
+ name: "value",
194
+ children: /*#__PURE__*/jsx(Select, {
195
+ searchable: true,
196
+ allowCreate: true,
197
+ allowClear: true,
198
+ options: (_field$values3 = field.values) !== null && _field$values3 !== void 0 ? _field$values3 : [],
199
+ label: t("label.value"),
200
+ onQuery: field.onSearch
201
+ })
202
+ });
140
203
  } else {
141
204
  return /*#__PURE__*/jsx(Controller, {
142
205
  name: "value",
@@ -147,27 +210,40 @@ var FilterForm = function FilterForm(_ref) {
147
210
  });
148
211
  }
149
212
  }
213
+ if (field.type === FIELD_TYPE.TEXT) {
214
+ return /*#__PURE__*/jsx(Controller, {
215
+ name: "value",
216
+ children: /*#__PURE__*/jsx(Textarea, {
217
+ rows: 3,
218
+ label: t("label.value"),
219
+ allowClear: true
220
+ })
221
+ });
222
+ }
150
223
  if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.DECIMAL || (field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.NUMBER) {
151
224
  var step = field.type === FIELD_TYPE.DECIMAL ? 0.1 : 1;
152
225
  if ((values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.BETWEEN) {
153
- return /*#__PURE__*/jsxs(Field, {
154
- label: t("label.value"),
155
- children: [/*#__PURE__*/jsx(Controller, {
156
- name: "value[0]",
157
- children: /*#__PURE__*/jsx(Number, {
158
- step: step,
159
- allowClear: true
160
- })
161
- }), /*#__PURE__*/jsx("span", {
162
- className: "p-2 text-muted",
163
- children: "\u2277"
164
- }), /*#__PURE__*/jsx(Controller, {
165
- name: "value[1]",
166
- children: /*#__PURE__*/jsx(Number, {
167
- step: step,
168
- allowClear: true
169
- })
170
- })]
226
+ return /*#__PURE__*/jsx(Controller, {
227
+ name: "value",
228
+ children: /*#__PURE__*/jsxs(Field, {
229
+ label: t("label.value"),
230
+ children: [/*#__PURE__*/jsx(Controller, {
231
+ name: "value[0]",
232
+ children: /*#__PURE__*/jsx(Number, {
233
+ step: step,
234
+ allowClear: true
235
+ })
236
+ }), /*#__PURE__*/jsx("span", {
237
+ className: "p-2 text-muted",
238
+ children: "\u2277"
239
+ }), /*#__PURE__*/jsx(Controller, {
240
+ name: "value[1]",
241
+ children: /*#__PURE__*/jsx(Number, {
242
+ step: step,
243
+ allowClear: true
244
+ })
245
+ })]
246
+ })
171
247
  });
172
248
  } else {
173
249
  return /*#__PURE__*/jsx(Controller, {
@@ -180,7 +256,43 @@ var FilterForm = function FilterForm(_ref) {
180
256
  });
181
257
  }
182
258
  }
183
- }, [field, values === null || values === void 0 ? void 0 : values.operator]);
259
+ if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.DATE || (field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.DATETIME) {
260
+ var type = field.type === FIELD_TYPE.DATETIME ? "datetime" : "date";
261
+ if ((values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.BETWEEN) {
262
+ return /*#__PURE__*/jsx(Controller, {
263
+ name: "value",
264
+ children: /*#__PURE__*/jsxs(Field, {
265
+ label: t("label.value"),
266
+ children: [/*#__PURE__*/jsx(Controller, {
267
+ name: "value[0]",
268
+ children: /*#__PURE__*/jsx(DateInput, {
269
+ type: type,
270
+ allowClear: true
271
+ })
272
+ }), /*#__PURE__*/jsx("span", {
273
+ className: "p-2 text-muted",
274
+ children: "\u2277"
275
+ }), /*#__PURE__*/jsx(Controller, {
276
+ name: "value[1]",
277
+ children: /*#__PURE__*/jsx(DateInput, {
278
+ type: type,
279
+ allowClear: true
280
+ })
281
+ })]
282
+ })
283
+ });
284
+ } else {
285
+ return /*#__PURE__*/jsx(Controller, {
286
+ name: "value",
287
+ children: /*#__PURE__*/jsx(DateInput, {
288
+ type: type,
289
+ allowClear: true
290
+ })
291
+ });
292
+ }
293
+ }
294
+ // eslint-disable-next-line @eslint-react/exhaustive-deps
295
+ }, [field, values]);
184
296
  var handleSubmit = useCallback(function (model) {
185
297
  var filter = {
186
298
  id: model.id,
@@ -188,19 +300,22 @@ var FilterForm = function FilterForm(_ref) {
188
300
  negate: model.negate,
189
301
  operator: model.operator,
190
302
  value: model.value,
191
- label: model.label
303
+ label: model.label,
304
+ type: field === null || field === void 0 ? void 0 : field.type
192
305
  };
193
306
  onChange === null || onChange === void 0 || onChange(filter);
194
307
  tree === null || tree === void 0 || tree.events.emit("close");
195
- }, [onChange]);
308
+ },
309
+ // eslint-disable-next-line @eslint-react/exhaustive-deps
310
+ [field, onChange]);
196
311
  return /*#__PURE__*/jsx(Form, {
197
312
  formRef: formRef,
198
- schema: FilterSchema,
313
+ resolver: yupResolver(FilterSchema),
199
314
  defaultValues: values,
200
315
  onChange: setValues,
201
316
  onSubmit: handleSubmit,
202
317
  children: /*#__PURE__*/jsxs("div", {
203
- className: "w-[32rem]",
318
+ className: "w-lg",
204
319
  children: [/*#__PURE__*/jsxs(Row, {
205
320
  children: [/*#__PURE__*/jsx(Col, {
206
321
  flex: "fill",
@@ -208,6 +323,7 @@ var FilterForm = function FilterForm(_ref) {
208
323
  name: "field",
209
324
  children: /*#__PURE__*/jsx(Select, {
210
325
  required: true,
326
+ searchable: true,
211
327
  ref: inputRef,
212
328
  label: t("label.field"),
213
329
  options: fields,
@@ -217,7 +333,7 @@ var FilterForm = function FilterForm(_ref) {
217
333
  })
218
334
  })
219
335
  }), /*#__PURE__*/jsxs(Col, {
220
- flex: "auto",
336
+ flex: "content",
221
337
  className: "text-center",
222
338
  children: [/*#__PURE__*/jsx("label", {
223
339
  className: "block py-0.5 text-sm",
@@ -229,7 +345,7 @@ var FilterForm = function FilterForm(_ref) {
229
345
  })
230
346
  })]
231
347
  }), /*#__PURE__*/jsx(Col, {
232
- flex: "auto",
348
+ flex: "content",
233
349
  className: "basis-28",
234
350
  children: /*#__PURE__*/jsx(Controller, {
235
351
  name: "operator",
@@ -253,22 +369,26 @@ var FilterForm = function FilterForm(_ref) {
253
369
  })
254
370
  })
255
371
  }), /*#__PURE__*/jsxs("div", {
256
- className: "flex pt-4 justify-end gap-1",
372
+ className: "flex mt-4 justify-end gap-1 sticky bottom-1 bg-default",
257
373
  children: [onRemove && /*#__PURE__*/jsx("div", {
258
374
  className: "flex-1",
375
+ children: /*#__PURE__*/jsx(DropdownDismiss, {
376
+ children: /*#__PURE__*/jsx(Button, {
377
+ "data-dropdown-dismiss": "true",
378
+ variant: "link",
379
+ size: "sm",
380
+ color: "danger",
381
+ onClick: onRemove,
382
+ children: t("label.remove")
383
+ })
384
+ })
385
+ }), /*#__PURE__*/jsx(DropdownDismiss, {
259
386
  children: /*#__PURE__*/jsx(Button, {
260
387
  "data-dropdown-dismiss": "true",
261
388
  variant: "link",
262
389
  size: "sm",
263
- color: "danger",
264
- onClick: onRemove,
265
- children: t("label.remove")
390
+ children: t("label.cancel")
266
391
  })
267
- }), /*#__PURE__*/jsx(Button, {
268
- "data-dropdown-dismiss": "true",
269
- variant: "link",
270
- size: "sm",
271
- children: t("label.cancel")
272
392
  }), /*#__PURE__*/jsx(Button, {
273
393
  type: "submit",
274
394
  variant: "solid",
@@ -278,6 +398,6 @@ var FilterForm = function FilterForm(_ref) {
278
398
  })]
279
399
  })
280
400
  });
281
- };
401
+ }
282
402
 
283
403
  export { FilterForm };
@@ -2,19 +2,22 @@
2
2
 
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
- import { Menu, MenuItem, CoreIcons, Divider } from '@react-fabric/core';
5
+ import { Menu, MenuItem, Divider } from '@react-fabric/core';
6
6
  import { useState } from 'react';
7
7
  import { useTranslation } from 'react-i18next';
8
+ import { OPERATOR } from '../types/index.js';
8
9
  import { FilterEdit } from './FilterEdit.js';
9
10
  import { FilterView } from './FilterView.js';
10
11
  import { jsx, jsxs } from 'react/jsx-runtime';
11
12
 
12
13
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
- var FilterMenu = function FilterMenu(_ref) {
15
- var filter = _ref.filter;
16
- _ref.fields;
17
- var onChange = _ref.onChange,
14
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
+ var MATCH_ALL = "M9,5C10.04,5 11.06,5.24 12,5.68C12.94,5.24 13.96,5 15,5A7,7 0 0,1 22,12A7,7 0 0,1 15,19C13.96,19 12.94,18.76 12,18.32C11.06,18.76 10.04,19 9,19A7,7 0 0,1 2,12A7,7 0 0,1 9,5M8.5,12C8.5,13.87 9.29,15.56 10.56,16.75L11.56,16.29C10.31,15.29 9.5,13.74 9.5,12C9.5,10.26 10.31,8.71 11.56,7.71L10.56,7.25C9.29,8.44 8.5,10.13 8.5,12M15.5,12C15.5,10.13 14.71,8.44 13.44,7.25L12.44,7.71C13.69,8.71 14.5,10.26 14.5,12C14.5,13.74 13.69,15.29 12.44,16.29L13.44,16.75C14.71,15.56 15.5,13.87 15.5,12Z";
16
+ var MATCH_ANY = "M9,5A7,7 0 0,0 2,12A7,7 0 0,0 9,19C10.04,19 11.06,18.76 12,18.32C12.94,18.76 13.96,19 15,19A7,7 0 0,0 22,12A7,7 0 0,0 15,5C13.96,5 12.94,5.24 12,5.68C11.06,5.24 10.04,5 9,5M9,7C9.34,7 9.67,7.03 10,7.1C8.72,8.41 8,10.17 8,12C8,13.83 8.72,15.59 10,16.89C9.67,16.96 9.34,17 9,17A5,5 0 0,1 4,12A5,5 0 0,1 9,7M15,7A5,5 0 0,1 20,12A5,5 0 0,1 15,17C14.66,17 14.33,16.97 14,16.9C15.28,15.59 16,13.83 16,12C16,10.17 15.28,8.41 14,7.11C14.33,7.04 14.66,7 15,7Z";
17
+ function FilterMenu(_ref) {
18
+ var filter = _ref.filter,
19
+ editable = _ref.editable,
20
+ onChange = _ref.onChange,
18
21
  onRemove = _ref.onRemove;
19
22
  var _useTranslation = useTranslation("searchbar"),
20
23
  t = _useTranslation.t;
@@ -31,28 +34,36 @@ var FilterMenu = function FilterMenu(_ref) {
31
34
  onRemove: onRemove
32
35
  }) : /*#__PURE__*/jsxs(Menu, {
33
36
  className: "text-sm",
34
- children: [filter.canEdit !== false ? /*#__PURE__*/jsx(MenuItem, {
35
- icon: CoreIcons.edit,
37
+ children: [editable && filter.canEdit !== false ? /*#__PURE__*/jsx(MenuItem, {
38
+ icon: "icon-[mdi--lead-pencil]",
36
39
  label: t("label.edit"),
37
40
  "data-dropdown-dismiss": "false",
38
41
  onClick: function onClick() {
39
42
  setView("edit");
40
43
  }
41
44
  }) : /*#__PURE__*/jsx(MenuItem, {
42
- icon: CoreIcons.eye,
45
+ icon: "icon-[mdi--eye]",
43
46
  label: t("label.view"),
44
47
  "data-dropdown-dismiss": "false",
45
48
  onClick: function onClick() {
46
49
  setView("view");
47
50
  }
48
- }), /*#__PURE__*/jsx(Divider, {}), filter.canPin !== false && /*#__PURE__*/jsx(MenuItem, {
51
+ }), /*#__PURE__*/jsx(Divider, {}), filter.operator && [OPERATOR.ALL, OPERATOR.ANY].includes(filter.operator) && /*#__PURE__*/jsx(MenuItem, {
52
+ label: t(filter.operator === OPERATOR.ALL ? "label.matchAny" : "label.matchAll"),
53
+ icon: t(filter.operator === OPERATOR.ALL ? MATCH_ANY : MATCH_ALL),
54
+ onClick: function onClick() {
55
+ return onChange(_objectSpread(_objectSpread({}, filter), {}, {
56
+ operator: filter.operator === OPERATOR.ALL ? OPERATOR.ANY : OPERATOR.ALL
57
+ }));
58
+ }
59
+ }), filter.canPin !== false && /*#__PURE__*/jsx(MenuItem, {
49
60
  label: t(filter.pinned ? "label.unpin" : "label.pin"),
50
61
  onClick: function onClick() {
51
62
  return onChange(_objectSpread(_objectSpread({}, filter), {}, {
52
63
  pinned: !filter.pinned
53
64
  }));
54
65
  }
55
- }), filter.canInvert !== false && /*#__PURE__*/jsx(MenuItem, {
66
+ }), filter.canInvert !== false && filter.field && /*#__PURE__*/jsx(MenuItem, {
56
67
  label: t(filter.negate ? "label.include" : "label.exclude"),
57
68
  onClick: function onClick() {
58
69
  return onChange(_objectSpread(_objectSpread({}, filter), {}, {
@@ -68,13 +79,13 @@ var FilterMenu = function FilterMenu(_ref) {
68
79
  }
69
80
  }), !filter.required && /*#__PURE__*/jsx(Divider, {}), !filter.required && /*#__PURE__*/jsx(MenuItem, {
70
81
  color: "danger",
71
- icon: CoreIcons.remove,
82
+ icon: "icon-[mdi--minus-circle-outline]",
72
83
  label: t("label.remove"),
73
84
  onClick: function onClick() {
74
85
  return onRemove();
75
86
  }
76
87
  })]
77
88
  });
78
- };
89
+ }
79
90
 
80
91
  export { FilterMenu };
@@ -1,20 +1,20 @@
1
1
  'use client';
2
2
 
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
- import { CoreIcons, Dropdown, Chip, Icon } from '@react-fabric/core';
5
- import { isNil } from '@react-fabric/utilities';
6
- import classNames from 'classnames';
4
+ import { Dropdown, Chip, Icon } from '@react-fabric/core';
5
+ import { isNil, cn } from '@react-fabric/utilities';
7
6
  import { useMemo, Fragment } from 'react';
8
7
  import { useTranslation } from 'react-i18next';
9
8
  import { FilterMenu } from './FilterMenu.js';
10
9
  import { jsxs, jsx } from 'react/jsx-runtime';
11
10
 
12
11
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
- var FilterTag = function FilterTag(_ref) {
12
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
+ function FilterTag(_ref) {
15
14
  var _filter$icon;
16
15
  var filter = _ref.filter,
17
16
  fields = _ref.fields,
17
+ editable = _ref.editable,
18
18
  _ref$includedColor = _ref.includedColor,
19
19
  includedColor = _ref$includedColor === void 0 ? "primary-500" : _ref$includedColor,
20
20
  _ref$excludedColor = _ref.excludedColor,
@@ -26,7 +26,7 @@ var FilterTag = function FilterTag(_ref) {
26
26
  var label = useMemo(function () {
27
27
  var _filter$value;
28
28
  if (filter.label) return /*#__PURE__*/jsxs(Fragment, {
29
- children: [filter.negate && /*#__PURE__*/jsx("span", {
29
+ children: [filter.field && filter.negate && /*#__PURE__*/jsx("span", {
30
30
  className: "font-semibold",
31
31
  children: "NOT"
32
32
  }), /*#__PURE__*/jsx("span", {
@@ -34,7 +34,7 @@ var FilterTag = function FilterTag(_ref) {
34
34
  })]
35
35
  });
36
36
  return /*#__PURE__*/jsxs(Fragment, {
37
- children: [filter.negate && /*#__PURE__*/jsx("span", {
37
+ children: [filter.field && filter.negate && /*#__PURE__*/jsx("span", {
38
38
  className: "font-semibold",
39
39
  children: "NOT"
40
40
  }), /*#__PURE__*/jsx("span", {
@@ -49,49 +49,59 @@ var FilterTag = function FilterTag(_ref) {
49
49
  children: (_filter$value = filter.value) === null || _filter$value === void 0 ? void 0 : _filter$value.toString().substring(0, 24)
50
50
  })]
51
51
  });
52
+ // eslint-disable-next-line @eslint-react/exhaustive-deps
52
53
  }, [filter]);
53
54
  var color = useMemo(function () {
54
55
  var _filter$color;
55
- return (_filter$color = filter.color) !== null && _filter$color !== void 0 ? _filter$color : filter.negate ? excludedColor : includedColor;
56
+ return (_filter$color = filter.color) !== null && _filter$color !== void 0 ? _filter$color : filter.field && filter.negate ? excludedColor : includedColor;
56
57
  }, [filter, includedColor, excludedColor]);
57
58
  var icon = useMemo(function () {
58
59
  if (filter.canDisable === false) return undefined;
59
- return filter.disabled ? CoreIcons.checkboxOff : CoreIcons.checkboxOn;
60
+ return filter.disabled ? "icon-[mdi--checkbox-blank-outline]" : "icon-[mdi--checkbox-marked]";
60
61
  }, [filter]);
61
62
  return /*#__PURE__*/jsxs(Dropdown, {
62
63
  showArrow: true,
63
64
  children: [/*#__PURE__*/jsx(Chip, {
64
65
  size: "sm",
65
66
  color: color,
66
- className: "outline outline-1 max-w-60",
67
+ className: cn("outline max-w-60", filter.disabled && "opacity-65"),
67
68
  variant: filter.pinned ? "solid" : undefined,
68
- icon: icon,
69
- iconColor: color,
70
- onIconClick: function onIconClick(e) {
71
- return [onChange(_objectSpread(_objectSpread({}, filter), {}, {
72
- disabled: !filter.disabled
73
- })), e.stopPropagation()];
74
- },
75
- "data-testid": "filter-tag",
69
+ icon: icon && /*#__PURE__*/jsx("button", {
70
+ className: "size-fit cursor-pointer",
71
+ onClick: function onClick(e) {
72
+ return [onChange(_objectSpread(_objectSpread({}, filter), {}, {
73
+ disabled: !filter.disabled
74
+ })), e.stopPropagation()];
75
+ },
76
+ children: /*#__PURE__*/jsx(Icon, {
77
+ icon: icon,
78
+ color: color
79
+ })
80
+ }),
81
+ "data-ref": "filterTag",
76
82
  "data-test-value": filter.id,
77
83
  stopPropagation: true,
78
84
  onRemove: filter.required ? undefined : function () {
79
85
  return onRemove();
80
86
  },
81
87
  children: /*#__PURE__*/jsxs("div", {
82
- className: classNames("flex gap-1 items-center", filter.disabled && "line-through opacity-65"),
88
+ className: cn("flex gap-1 items-center", filter.disabled && "line-through opacity-65"),
83
89
  children: [filter.pinned && /*#__PURE__*/jsx(Icon, {
84
90
  className: "flex-content",
85
- icon: (_filter$icon = filter.icon) !== null && _filter$icon !== void 0 ? _filter$icon : CoreIcons.pin
86
- }), label]
91
+ icon: (_filter$icon = filter.icon) !== null && _filter$icon !== void 0 ? _filter$icon : "icon-[mdi--pin]"
92
+ }), /*#__PURE__*/jsx("div", {
93
+ className: "truncate flex gap-x-0.5 flex-nowrap",
94
+ children: label
95
+ })]
87
96
  })
88
97
  }), /*#__PURE__*/jsx(FilterMenu, {
89
98
  filter: filter,
90
99
  fields: fields,
100
+ editable: editable,
91
101
  onChange: onChange,
92
102
  onRemove: onRemove
93
103
  })]
94
104
  });
95
- };
105
+ }
96
106
 
97
107
  export { FilterTag };
@@ -30,7 +30,7 @@ import { jsxs, jsx } from 'react/jsx-runtime';
30
30
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
31
  */
32
32
 
33
- var FilterView = function FilterView(_ref) {
33
+ function FilterView(_ref) {
34
34
  var filter = _ref.filter,
35
35
  onRemove = _ref.onRemove;
36
36
  var _useTranslation = useTranslation("searchbar"),
@@ -45,10 +45,14 @@ var FilterView = function FilterView(_ref) {
45
45
  var _filter$value2;
46
46
  value = "[".concat((_filter$value2 = filter.value) === null || _filter$value2 === void 0 ? void 0 : _filter$value2.join(" - "), "]");
47
47
  }
48
- if (filter.operator === OPERATOR.IN && isArray(filter.value)) {
48
+ if (filter.operator === OPERATOR.ANY && isArray(filter.value)) {
49
49
  var _filter$value3;
50
50
  value = "[".concat((_filter$value3 = filter.value) === null || _filter$value3 === void 0 ? void 0 : _filter$value3.join(", "), "]");
51
51
  }
52
+ if (filter.operator === OPERATOR.ALL && isArray(filter.value)) {
53
+ var _filter$value4;
54
+ value = "(".concat((_filter$value4 = filter.value) === null || _filter$value4 === void 0 ? void 0 : _filter$value4.join(", "), ")");
55
+ }
52
56
  return /*#__PURE__*/jsxs(Fragment, {
53
57
  children: [filter.negate && /*#__PURE__*/jsx("b", {
54
58
  children: "NOT\xA0"
@@ -62,17 +66,18 @@ var FilterView = function FilterView(_ref) {
62
66
  });
63
67
  }
64
68
  return "";
69
+ // eslint-disable-next-line @eslint-react/exhaustive-deps
65
70
  }, [filter]);
66
71
  return /*#__PURE__*/jsxs("div", {
67
- className: "p-2 bg-base relative",
72
+ className: "p-2 bg-default relative rounded-capped",
68
73
  children: ["query" in filter && /*#__PURE__*/jsx("div", {
69
- className: "absolute top-2 end-2 z-10",
74
+ className: "absolute top-2 inset-e-2 z-10",
70
75
  children: /*#__PURE__*/jsx(Copy, {
71
76
  size: "sm",
72
77
  text: view
73
78
  })
74
79
  }), /*#__PURE__*/jsx("pre", {
75
- className: "overflow-auto bg-base outline text-sm p-2 max-h-[24rem] max-w-[48rem] min-w-[24rem]",
80
+ className: "overflow-auto bg-default outline text-sm p-2 max-h-96 max-w-3xl min-w-[24rem]",
76
81
  children: view
77
82
  }), !filter.required && /*#__PURE__*/jsx(Button, {
78
83
  size: "sm",
@@ -83,6 +88,6 @@ var FilterView = function FilterView(_ref) {
83
88
  children: t("label.remove")
84
89
  })]
85
90
  });
86
- };
91
+ }
87
92
 
88
93
  export { FilterView };