ywana-core8 0.0.706 → 0.0.708

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.
@@ -9868,13 +9868,83 @@ function _catch$1(body, recover) {
9868
9868
 
9869
9869
  var CollectionContext = React.createContext();
9870
9870
  var CollectionContextProvider = function CollectionContextProvider(props) {
9871
+ var fetch = function fetch(id) {
9872
+ try {
9873
+ return Promise.resolve(_catch$1(function () {
9874
+ return Promise.resolve(API.find(id));
9875
+ }, function (error) {
9876
+ console.log(error);
9877
+ }));
9878
+ } catch (e) {
9879
+ return Promise.reject(e);
9880
+ }
9881
+ };
9882
+ /*
9883
+ async function reloadSelection() {
9884
+ const result = await this.fetch(this.selected.id)
9885
+ this.selected = result
9886
+ }
9887
+ function clear() {
9888
+ this.selected = null
9889
+ }
9890
+ async function create(form) {
9891
+ try {
9892
+ if (versioning) form.version = 1
9893
+ await API.create(form);
9894
+ await this.load();
9895
+ } catch (error) {
9896
+ console.log(error)
9897
+ }
9898
+ return
9899
+ }
9900
+ async function update(form) {
9901
+ try {
9902
+ if (versioning) form.version = form.version ? form.version + 1 : 1
9903
+ await API.update(form)
9904
+ await this.load()
9905
+ } catch (error) {
9906
+ console.log(error)
9907
+ }
9908
+ return
9909
+ }
9910
+ async function patch(id, form) {
9911
+ try {
9912
+ if (versioning) form.version = form.version ? form.version + 1 : 1
9913
+ await API.patch(id, form)
9914
+ await this.load()
9915
+ } catch (error) {
9916
+ console.log(error)
9917
+ }
9918
+ return
9919
+ }
9920
+ async function updateProperty(id, propertyName, form) {
9921
+ try {
9922
+ await API.updateProperty(id, propertyName, form)
9923
+ await this.load()
9924
+ } catch (error) {
9925
+ console.log(error)
9926
+ }
9927
+ return
9928
+ }
9929
+ async function remove(id) {
9930
+ try {
9931
+ await API.remove(id)
9932
+ await this.load()
9933
+ } catch (error) {
9934
+ console.log(error)
9935
+ }
9936
+ return
9937
+ }
9938
+ */
9939
+
9940
+
9871
9941
  var select = function select(id) {
9872
9942
  try {
9873
9943
  var _this2 = this;
9874
9944
 
9875
9945
  var _temp2 = function () {
9876
9946
  if (fetching) {
9877
- return Promise.resolve(_this2.fetch(id)).then(function (result) {
9947
+ return Promise.resolve(fetch(id)).then(function (result) {
9878
9948
  setSelected(result);
9879
9949
  });
9880
9950
  } else {
@@ -9963,80 +10033,6 @@ var CollectionContextProvider = function CollectionContextProvider(props) {
9963
10033
  delete next[id];
9964
10034
  setCustomFilters(next);
9965
10035
  }
9966
- /*
9967
- async function reloadSelection() {
9968
- const result = await this.fetch(this.selected.id)
9969
- this.selected = result
9970
- }
9971
-
9972
- async function fetch(id) {
9973
- try {
9974
- const result = await API.find(id)
9975
- return result
9976
- } catch (error) {
9977
- console.log(error)
9978
- }
9979
- }
9980
-
9981
- function clear() {
9982
- this.selected = null
9983
- }
9984
-
9985
- async function create(form) {
9986
- try {
9987
- if (versioning) form.version = 1
9988
- await API.create(form);
9989
- await this.load();
9990
- } catch (error) {
9991
- console.log(error)
9992
- }
9993
- return
9994
- }
9995
-
9996
- async function update(form) {
9997
- try {
9998
- if (versioning) form.version = form.version ? form.version + 1 : 1
9999
- await API.update(form)
10000
- await this.load()
10001
- } catch (error) {
10002
- console.log(error)
10003
- }
10004
- return
10005
- }
10006
-
10007
- async function patch(id, form) {
10008
- try {
10009
- if (versioning) form.version = form.version ? form.version + 1 : 1
10010
- await API.patch(id, form)
10011
- await this.load()
10012
- } catch (error) {
10013
- console.log(error)
10014
- }
10015
- return
10016
- }
10017
-
10018
- async function updateProperty(id, propertyName, form) {
10019
- try {
10020
- await API.updateProperty(id, propertyName, form)
10021
- await this.load()
10022
- } catch (error) {
10023
- console.log(error)
10024
- }
10025
- return
10026
- }
10027
-
10028
- async function remove(id) {
10029
- try {
10030
- await API.remove(id)
10031
- await this.load()
10032
- } catch (error) {
10033
- console.log(error)
10034
- }
10035
- return
10036
- }
10037
-
10038
- */
10039
-
10040
10036
 
10041
10037
  var value = {
10042
10038
  all: all,
@@ -10235,7 +10231,7 @@ var CollectionFilters = function CollectionFilters(props) {
10235
10231
  function change(id, value) {
10236
10232
  var _extends2;
10237
10233
 
10238
- context.setFilters(_extends({}, filters, (_extends2 = {}, _extends2[id] = value, _extends2)));
10234
+ if (filters) context.setFilters(_extends({}, filters, (_extends2 = {}, _extends2[id] = value, _extends2)));
10239
10235
  }
10240
10236
 
10241
10237
  function toggle() {
@@ -10297,16 +10293,42 @@ var CollectionFiltersResume = function CollectionFiltersResume(props) {
10297
10293
  */
10298
10294
 
10299
10295
  var CollectionList = function CollectionList(props) {
10296
+ var itemRenderer = props.itemRenderer,
10297
+ groupBy = props.groupBy,
10298
+ _props$searchBy = props.searchBy,
10299
+ searchBy = _props$searchBy === void 0 ? [] : _props$searchBy;
10300
10300
  var context = useContext(CollectionContext);
10301
10301
  var _context$all = context.all,
10302
10302
  all = _context$all === void 0 ? [] : _context$all,
10303
10303
  filters = context.filters,
10304
10304
  customFilters = context.customFilters;
10305
+
10306
+ var _useState = useState(''),
10307
+ search = _useState[0],
10308
+ setSearch = _useState[1];
10309
+
10305
10310
  useEffect(function () {
10306
10311
  context.load();
10307
10312
  }, [filters, customFilters]);
10308
- var items = all.map(function (item) {
10313
+
10314
+ function changeSearch(id, value) {
10315
+ setSearch(value);
10316
+ }
10317
+
10318
+ function select(id) {
10319
+ context.select(id);
10320
+ }
10321
+
10322
+ var searched = searchBy.length > 0 && search.length > 0 ? all.filter(function (item) {
10323
+ var text = searchBy.map(function (field) {
10324
+ return item[field];
10325
+ }).join(' ').toLowerCase();
10326
+ return text.includes(search.toLowerCase());
10327
+ }) : all;
10328
+ var items = searched.map(function (item) {
10329
+ if (itemRenderer) return itemRenderer(item);
10309
10330
  return {
10331
+ id: item.id,
10310
10332
  icon: "folder",
10311
10333
  line1: item.name,
10312
10334
  meta: item.state
@@ -10315,8 +10337,19 @@ var CollectionList = function CollectionList(props) {
10315
10337
  return /*#__PURE__*/React.createElement("div", {
10316
10338
  className: "collection-list"
10317
10339
  }, /*#__PURE__*/React.createElement(List, {
10318
- items: items
10319
- }));
10340
+ items: items,
10341
+ onSelect: select,
10342
+ groupBy: groupBy
10343
+ }), searchBy.length > 0 ? /*#__PURE__*/React.createElement("div", {
10344
+ className: "search-box"
10345
+ }, /*#__PURE__*/React.createElement(Icon, {
10346
+ icon: "search",
10347
+ size: "small"
10348
+ }), /*#__PURE__*/React.createElement(TextField, {
10349
+ placeholder: "Search",
10350
+ onChange: changeSearch,
10351
+ outlined: true
10352
+ })) : null);
10320
10353
  };
10321
10354
 
10322
10355
  /**
@@ -10324,10 +10357,10 @@ var CollectionList = function CollectionList(props) {
10324
10357
  */
10325
10358
 
10326
10359
  var CollectionEditor = function CollectionEditor(props) {
10327
- useContext(CollectionContext);
10360
+ var customEditor = props.customEditor;
10328
10361
  return /*#__PURE__*/React.createElement("div", {
10329
10362
  className: "collection-editor"
10330
- }, "editor");
10363
+ }, customEditor);
10331
10364
  };
10332
10365
 
10333
10366
  /**
@@ -10339,18 +10372,29 @@ var CollectionPage = function CollectionPage(props) {
10339
10372
  url = props.url,
10340
10373
  schema = props.schema,
10341
10374
  layout = props.layout,
10375
+ title = props.title,
10342
10376
  canFilter = props.canFilter,
10343
- customFilters = props.customFilters;
10377
+ customFilters = props.customFilters,
10378
+ listGroupBy = props.listGroupBy,
10379
+ listSearchBy = props.listSearchBy,
10380
+ listItemRenderer = props.listItemRenderer,
10381
+ customEditor = props.customEditor;
10344
10382
  return /*#__PURE__*/React.createElement("div", {
10345
10383
  className: "collection-page " + layout
10346
10384
  }, /*#__PURE__*/React.createElement(CollectionContextProvider, {
10347
10385
  host: host,
10348
10386
  url: url
10349
10387
  }, /*#__PURE__*/React.createElement(Header, {
10350
- title: "CollectionPage"
10388
+ title: title
10351
10389
  }), canFilter ? /*#__PURE__*/React.createElement(CollectionFilters, {
10352
10390
  schema: schema
10353
- }, customFilters) : null, /*#__PURE__*/React.createElement(CollectionList, null), /*#__PURE__*/React.createElement(CollectionEditor, null)));
10391
+ }, customFilters) : null, /*#__PURE__*/React.createElement(CollectionList, {
10392
+ itemRenderer: listItemRenderer,
10393
+ groupBy: listGroupBy,
10394
+ searchBy: listSearchBy
10395
+ }), /*#__PURE__*/React.createElement(CollectionEditor, {
10396
+ customEditor: customEditor
10397
+ })));
10354
10398
  };
10355
10399
 
10356
10400
  /**