@react-fabric/searchbar 1.0.0-beta.9 → 1.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.
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 +177 -64
  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 +181 -68
  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 -91
  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,21 +3,22 @@
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
- import { FIELD_TYPE, OPERATOR, TypeOperators } from '../types/index.js';
12
+ import { OPERATOR, TypeOperators, FIELD_TYPE } from '../types/index.js';
12
13
  import { useFilterContext } from './Context.js';
13
14
  import { jsx, jsxs } from 'react/jsx-runtime';
14
15
 
15
16
  var FilterSchema = new yup.ObjectSchema({
16
17
  id: yup.string().required(),
17
18
  field: yup.string().required(),
18
- type: yup.string().required().oneOf(Object.values(FIELD_TYPE)),
19
+ // type: yup.string().oneOf(Object.values(FIELD_TYPE)),
19
20
  operator: yup.string().required().oneOf(Object.values(OPERATOR)),
20
- negate: yup["boolean"](),
21
+ negate: yup["boolean"]().optional(),
21
22
  label: yup.string(),
22
23
  value: yup.mixed().when("operator", {
23
24
  is: OPERATOR.EXISTS,
@@ -28,20 +29,56 @@ var FilterSchema = new yup.ObjectSchema({
28
29
  return schema.required();
29
30
  }
30
31
  }).when("operator", {
31
- is: OPERATOR.IN,
32
+ is: OPERATOR.ANY,
32
33
  then: function then(schema) {
33
34
  return schema.test({
34
35
  name: "array-check",
35
36
  message: "${path} is a required field",
36
37
  test: function test() {
37
38
  var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
38
- 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];
39
76
  }
40
77
  });
41
78
  }
42
79
  })
43
80
  });
44
- var FilterForm = function FilterForm(_ref) {
81
+ function FilterForm(_ref) {
45
82
  var filter = _ref.filter,
46
83
  onChange = _ref.onChange,
47
84
  onRemove = _ref.onRemove;
@@ -53,31 +90,41 @@ var FilterForm = function FilterForm(_ref) {
53
90
  fields = _useFilterContext$fie === void 0 ? [] : _useFilterContext$fie;
54
91
  var inputRef = useRef(null);
55
92
  var formRef = useRef(null);
56
- var _useState = useState(filter),
93
+ var _useState = useState(function () {
94
+ return filter;
95
+ }),
57
96
  _useState2 = _slicedToArray(_useState, 2),
58
97
  values = _useState2[0],
59
98
  setValues = _useState2[1];
99
+ console.log(values);
60
100
  useEffect(function () {
61
- var _formRef$current, _formRef$current2;
62
- if (filter && "field" in filter && filter.field) return (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.setValues(filter);
63
- (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || _formRef$current2.setValues({
64
- id: shortHash(),
65
- field: "",
66
- type: FIELD_TYPE.NONE,
67
- operator: OPERATOR.EXISTS
68
- });
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
+ }
69
112
  }, [filter]);
70
113
  useEffect(function () {
71
- setTimeout(function () {
114
+ var tmr = setTimeout(function () {
72
115
  var _inputRef$current;
73
116
  (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
74
117
  }, 100);
118
+ return function () {
119
+ clearTimeout(tmr);
120
+ };
75
121
  }, []);
76
122
  var field = useMemo(function () {
77
123
  if (!(values !== null && values !== void 0 && values.field)) return undefined;
78
124
  return fields.find(function (f) {
79
125
  return f.field === (values === null || values === void 0 ? void 0 : values.field);
80
126
  });
127
+ // eslint-disable-next-line @eslint-react/exhaustive-deps
81
128
  }, [values]);
82
129
  var operators = useMemo(function () {
83
130
  var _formRef$current3;
@@ -91,24 +138,24 @@ var FilterForm = function FilterForm(_ref) {
91
138
  (_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 || _formRef$current4.setValue("value", undefined);
92
139
  }
93
140
  if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.STRING) {
94
- 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)) {
95
142
  var _formRef$current5;
96
- !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", []);
97
144
  } else {
98
145
  var _formRef$current6;
99
- 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);
100
147
  }
101
148
  }
102
- 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) {
103
150
  if ((values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.BETWEEN) {
104
151
  var _formRef$current7;
105
- !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", []);
106
153
  } else {
107
154
  var _formRef$current8;
108
- 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);
109
156
  }
110
157
  }
111
- 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) {
112
159
  var _formRef$current9;
113
160
  (_formRef$current9 = formRef.current) === null || _formRef$current9 === void 0 || _formRef$current9.setValue("value", false);
114
161
  }
@@ -125,7 +172,8 @@ var FilterForm = function FilterForm(_ref) {
125
172
  });
126
173
  }
127
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) {
128
- 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)) {
129
177
  var _field$values;
130
178
  return /*#__PURE__*/jsx(Controller, {
131
179
  name: "value",
@@ -139,6 +187,19 @@ var FilterForm = function FilterForm(_ref) {
139
187
  onQuery: field.onSearch
140
188
  })
141
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
+ });
142
203
  } else {
143
204
  return /*#__PURE__*/jsx(Controller, {
144
205
  name: "value",
@@ -149,27 +210,40 @@ var FilterForm = function FilterForm(_ref) {
149
210
  });
150
211
  }
151
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
+ }
152
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) {
153
224
  var step = field.type === FIELD_TYPE.DECIMAL ? 0.1 : 1;
154
225
  if ((values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.BETWEEN) {
155
- return /*#__PURE__*/jsxs(Field, {
156
- label: t("label.value"),
157
- children: [/*#__PURE__*/jsx(Controller, {
158
- name: "value[0]",
159
- children: /*#__PURE__*/jsx(Number, {
160
- step: step,
161
- allowClear: true
162
- })
163
- }), /*#__PURE__*/jsx("span", {
164
- className: "p-2 text-muted",
165
- children: "\u2277"
166
- }), /*#__PURE__*/jsx(Controller, {
167
- name: "value[1]",
168
- children: /*#__PURE__*/jsx(Number, {
169
- step: step,
170
- allowClear: true
171
- })
172
- })]
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
+ })
173
247
  });
174
248
  } else {
175
249
  return /*#__PURE__*/jsx(Controller, {
@@ -182,28 +256,66 @@ var FilterForm = function FilterForm(_ref) {
182
256
  });
183
257
  }
184
258
  }
185
- }, [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]);
186
296
  var handleSubmit = useCallback(function (model) {
187
297
  var filter = {
188
298
  id: model.id,
189
299
  field: model.field,
190
- type: model.type,
191
300
  negate: model.negate,
192
301
  operator: model.operator,
193
302
  value: model.value,
194
- label: model.label
303
+ label: model.label,
304
+ type: field === null || field === void 0 ? void 0 : field.type
195
305
  };
196
306
  onChange === null || onChange === void 0 || onChange(filter);
197
307
  tree === null || tree === void 0 || tree.events.emit("close");
198
- }, [onChange]);
308
+ },
309
+ // eslint-disable-next-line @eslint-react/exhaustive-deps
310
+ [field, onChange]);
199
311
  return /*#__PURE__*/jsx(Form, {
200
312
  formRef: formRef,
201
- schema: FilterSchema,
313
+ resolver: yupResolver(FilterSchema),
202
314
  defaultValues: values,
203
315
  onChange: setValues,
204
316
  onSubmit: handleSubmit,
205
317
  children: /*#__PURE__*/jsxs("div", {
206
- className: "w-[32rem]",
318
+ className: "w-lg",
207
319
  children: [/*#__PURE__*/jsxs(Row, {
208
320
  children: [/*#__PURE__*/jsx(Col, {
209
321
  flex: "fill",
@@ -211,20 +323,17 @@ var FilterForm = function FilterForm(_ref) {
211
323
  name: "field",
212
324
  children: /*#__PURE__*/jsx(Select, {
213
325
  required: true,
326
+ searchable: true,
214
327
  ref: inputRef,
215
328
  label: t("label.field"),
216
329
  options: fields,
217
330
  labelProperty: "label",
218
331
  valueProperty: "field",
219
- groupProperty: "type",
220
- onSelect: function onSelect(field) {
221
- var _formRef$current10;
222
- return (_formRef$current10 = formRef.current) === null || _formRef$current10 === void 0 ? void 0 : _formRef$current10.setValue("type", field.type);
223
- }
332
+ groupProperty: "type"
224
333
  })
225
334
  })
226
335
  }), /*#__PURE__*/jsxs(Col, {
227
- flex: "auto",
336
+ flex: "content",
228
337
  className: "text-center",
229
338
  children: [/*#__PURE__*/jsx("label", {
230
339
  className: "block py-0.5 text-sm",
@@ -236,7 +345,7 @@ var FilterForm = function FilterForm(_ref) {
236
345
  })
237
346
  })]
238
347
  }), /*#__PURE__*/jsx(Col, {
239
- flex: "auto",
348
+ flex: "content",
240
349
  className: "basis-28",
241
350
  children: /*#__PURE__*/jsx(Controller, {
242
351
  name: "operator",
@@ -260,22 +369,26 @@ var FilterForm = function FilterForm(_ref) {
260
369
  })
261
370
  })
262
371
  }), /*#__PURE__*/jsxs("div", {
263
- className: "flex pt-4 justify-end gap-1",
372
+ className: "flex mt-4 justify-end gap-1 sticky bottom-1 bg-default",
264
373
  children: [onRemove && /*#__PURE__*/jsx("div", {
265
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, {
266
386
  children: /*#__PURE__*/jsx(Button, {
267
387
  "data-dropdown-dismiss": "true",
268
388
  variant: "link",
269
389
  size: "sm",
270
- color: "danger",
271
- onClick: onRemove,
272
- children: t("label.remove")
390
+ children: t("label.cancel")
273
391
  })
274
- }), /*#__PURE__*/jsx(Button, {
275
- "data-dropdown-dismiss": "true",
276
- variant: "link",
277
- size: "sm",
278
- children: t("label.cancel")
279
392
  }), /*#__PURE__*/jsx(Button, {
280
393
  type: "submit",
281
394
  variant: "solid",
@@ -285,6 +398,6 @@ var FilterForm = function FilterForm(_ref) {
285
398
  })]
286
399
  })
287
400
  });
288
- };
401
+ }
289
402
 
290
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 };