ywana-core8 0.0.535 → 0.0.538

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.
@@ -4044,7 +4044,7 @@ var TabbedContentEditor = function TabbedContentEditor(_ref2) {
4044
4044
  fields = section.fields;
4045
4045
  return /*#__PURE__*/React.createElement("section", {
4046
4046
  key: title
4047
- }, /*#__PURE__*/React.createElement("nav", null, "\xA0"), /*#__PURE__*/React.createElement("main", null, grouped ? group(section).map(function (group) {
4047
+ }, grouped ? group(section).map(function (group) {
4048
4048
  return /*#__PURE__*/React.createElement(Fragment, null, group.name.length > 0 ? /*#__PURE__*/React.createElement("div", {
4049
4049
  className: "group-caption"
4050
4050
  }, group.name) : null, group.fields.filter(function (field) {
@@ -4070,7 +4070,7 @@ var TabbedContentEditor = function TabbedContentEditor(_ref2) {
4070
4070
  onChange: change,
4071
4071
  content: content
4072
4072
  });
4073
- })));
4073
+ }));
4074
4074
  })));
4075
4075
  };
4076
4076
  /**
@@ -4533,9 +4533,7 @@ var CollectionEditor$1 = function CollectionEditor(_ref10) {
4533
4533
  Feeder = field.Feeder,
4534
4534
  Renderer = field.Renderer,
4535
4535
  _field$Adder = field.Adder,
4536
- Adder = _field$Adder === void 0 ? true : _field$Adder,
4537
- _field$editable3 = field.editable,
4538
- editable = _field$editable3 === void 0 ? true : _field$editable3;
4536
+ Adder = _field$Adder === void 0 ? true : _field$Adder;
4539
4537
 
4540
4538
  function add(rows) {
4541
4539
  if (onChange) {
@@ -4561,7 +4559,9 @@ var CollectionEditor$1 = function CollectionEditor(_ref10) {
4561
4559
  }
4562
4560
  }
4563
4561
 
4564
- var columns = Object.values(item).map(function (item) {
4562
+ var columns = Object.values(item).filter(function (field) {
4563
+ return field.column === true;
4564
+ }).map(function (item) {
4565
4565
  return _extends({}, item, {
4566
4566
  onChange: change
4567
4567
  });
@@ -4570,7 +4570,7 @@ var CollectionEditor$1 = function CollectionEditor(_ref10) {
4570
4570
  id: 'actions',
4571
4571
  label: 'Actions'
4572
4572
  });
4573
- var rows = value.map(function (item, index) {
4573
+ value.map(function (item, index) {
4574
4574
  return _extends({}, item, {
4575
4575
  id: index,
4576
4576
  actions: [/*#__PURE__*/React.createElement(Icon, {
@@ -4583,26 +4583,23 @@ var CollectionEditor$1 = function CollectionEditor(_ref10) {
4583
4583
  })]
4584
4584
  });
4585
4585
  });
4586
- var table = {
4587
- columns: columns,
4588
- rows: rows
4589
- };
4590
4586
  return /*#__PURE__*/React.createElement("div", {
4591
4587
  className: "collection-editor"
4592
- }, /*#__PURE__*/React.createElement("header", null, /*#__PURE__*/React.createElement(Text, {
4593
- use: "caption"
4594
- }, label), /*#__PURE__*/React.createElement("div", {
4595
- className: "actions"
4596
- }, Feeder ? /*#__PURE__*/React.createElement(Feeder, {
4597
- onAdd: add
4598
- }) : null)), Renderer ? /*#__PURE__*/React.createElement(Renderer, {
4588
+ }, Renderer ? /*#__PURE__*/React.createElement(Renderer, {
4599
4589
  field: field,
4600
4590
  value: value,
4601
4591
  onRemove: remove,
4602
4592
  onChange: onChange
4603
- }) : /*#__PURE__*/React.createElement(DataTable, _extends({}, table, {
4604
- editable: editable
4605
- })), /*#__PURE__*/React.createElement("footer", null, Adder ? /*#__PURE__*/React.createElement(CollectionAdder, {
4593
+ }) // : <DataTable {...table} editable={editable} />
4594
+ : /*#__PURE__*/React.createElement(TableEditor$2, {
4595
+ icon: "info",
4596
+ title: label,
4597
+ data: value,
4598
+ schema: item,
4599
+ groupBy: "field1"
4600
+ }), /*#__PURE__*/React.createElement("footer", null, Feeder ? /*#__PURE__*/React.createElement(Feeder, {
4601
+ onAdd: add
4602
+ }) : null, Adder ? /*#__PURE__*/React.createElement(CollectionAdder, {
4606
4603
  item: item,
4607
4604
  onAdd: add
4608
4605
  }) : null));
@@ -4677,6 +4674,166 @@ var CollectionAdder = function CollectionAdder(_ref11) {
4677
4674
  action: toggle
4678
4675
  }));
4679
4676
  };
4677
+ /**
4678
+ * Table Editor
4679
+ */
4680
+
4681
+
4682
+ var TableEditor$2 = function TableEditor(props) {
4683
+ var select = function select(row) {
4684
+ try {
4685
+ if (onSelect) onSelect(row.id);
4686
+ return Promise.resolve();
4687
+ } catch (e) {
4688
+ return Promise.reject(e);
4689
+ }
4690
+ };
4691
+
4692
+ var _props$data = props.data,
4693
+ data = _props$data === void 0 ? [] : _props$data,
4694
+ icon = props.icon,
4695
+ title = props.title,
4696
+ schema = props.schema,
4697
+ editable = props.editable,
4698
+ canDelete = props.canDelete,
4699
+ filter = props.filter,
4700
+ actions = props.actions,
4701
+ className = props.className;
4702
+
4703
+ var _useState5 = useState(props.groupBy),
4704
+ groupBy = _useState5[0],
4705
+ setGroupBy = _useState5[1];
4706
+
4707
+ function changeGroup(id, value) {
4708
+ setGroupBy(value);
4709
+ }
4710
+
4711
+ function renderGroupLabel(groupName) {
4712
+ var grouper = schema[groupBy];
4713
+ if (!groupName || !grouper) return "";
4714
+
4715
+ if (grouper.options) {
4716
+ var options = CHECK['isFunction'](grouper.options) ? grouper.options() : grouper.options;
4717
+ var option = options.find(function (option) {
4718
+ return option.value === groupName;
4719
+ });
4720
+ return option ? option.label : groupName;
4721
+ } else {
4722
+ return groupName;
4723
+ }
4724
+ }
4725
+
4726
+ function renderGroups() {
4727
+ var items = filter ? filter(data) : data;
4728
+ if (items.length === 0) return /*#__PURE__*/React.createElement("div", {
4729
+ className: "empty-message"
4730
+ }, /*#__PURE__*/React.createElement(Icon, {
4731
+ icon: "search_off"
4732
+ }), /*#__PURE__*/React.createElement(Text, null, "No Result Found"));
4733
+ var groups = items.reduce(function (groups, item) {
4734
+ var groupName = item[groupBy];
4735
+ var group = groups[groupName];
4736
+ if (!group) groups[groupName] = [];
4737
+ groups[groupName].push(item);
4738
+ return groups;
4739
+ }, {});
4740
+ return Object.keys(groups).map(function (groupName) {
4741
+ var table = {
4742
+ columns: Object.values(schema).filter(function (field) {
4743
+ return field.column === true;
4744
+ }).map(function (field) {
4745
+ var options = field.options;
4746
+
4747
+ if (options && typeof options == 'function') {
4748
+ options = options();
4749
+ }
4750
+
4751
+ return {
4752
+ id: field.id,
4753
+ label: field.label,
4754
+ type: field.type,
4755
+ format: field.format,
4756
+ item: field.item ? field.item : [],
4757
+ onChange: field.id === "checked" ? checkOne : field.editable ? change : null,
4758
+
4759
+ /* checked has it´s own handler */
4760
+ options: options
4761
+ };
4762
+ }),
4763
+ rows: groups[groupName].map(function (item) {
4764
+ item.actions = actions ? actions.map(function (_action) {
4765
+ return _action.filter ? _action.filter(item) ? /*#__PURE__*/React.createElement(Icon, {
4766
+ icon: _action.icon,
4767
+ clickable: true,
4768
+ size: "small",
4769
+ action: function action() {
4770
+ return run(_action, item);
4771
+ }
4772
+ }) : null : /*#__PURE__*/React.createElement(Icon, {
4773
+ icon: _action.icon,
4774
+ clickable: true,
4775
+ size: "small",
4776
+ action: function action() {
4777
+ return run(_action, item);
4778
+ }
4779
+ });
4780
+ }) : [];
4781
+ if (canDelete) item.actions.push( /*#__PURE__*/React.createElement(Icon, {
4782
+ icon: "delete",
4783
+ size: "small",
4784
+ clickable: true,
4785
+ action: function action() {
4786
+ return remove(item.id);
4787
+ }
4788
+ }));
4789
+ return item;
4790
+ })
4791
+ };
4792
+ table.columns.push({
4793
+ id: "actions"
4794
+ });
4795
+ var groupSize = groups[groupName].length;
4796
+ var title = /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("span", {
4797
+ className: "size"
4798
+ }, groupSize), renderGroupLabel(groupName));
4799
+ return /*#__PURE__*/React.createElement(Fragment, {
4800
+ key: groupName
4801
+ }, /*#__PURE__*/React.createElement(Header, {
4802
+ title: title
4803
+ }, /*#__PURE__*/React.createElement("span", {
4804
+ className: "size"
4805
+ }, groupSize)), /*#__PURE__*/React.createElement(DataTable, _extends({}, table, {
4806
+ onRowSelection: select,
4807
+ editable: editable,
4808
+ className: className
4809
+ })));
4810
+ });
4811
+ }
4812
+
4813
+ function buildGroupOptions(schema) {
4814
+ return Object.values(schema).filter(function (field) {
4815
+ return field.grouper === true;
4816
+ }).map(function (field) {
4817
+ return {
4818
+ label: field.label,
4819
+ value: field.id
4820
+ };
4821
+ });
4822
+ }
4823
+
4824
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Header, {
4825
+ icon: icon,
4826
+ title: /*#__PURE__*/React.createElement(Text, null, title)
4827
+ }, /*#__PURE__*/React.createElement(DropDown, {
4828
+ id: "groupBy",
4829
+ label: "Agrupar Por",
4830
+ value: groupBy,
4831
+ options: buildGroupOptions(schema),
4832
+ onChange: changeGroup
4833
+ })), /*#__PURE__*/React.createElement("main", {
4834
+ className: "table-editor"
4835
+ }, renderGroups()));
4836
+ };
4680
4837
 
4681
4838
  /**
4682
4839
  * Create Content Dialog
@@ -4916,6 +5073,7 @@ var CollectionPage = function CollectionPage(props) {
4916
5073
  canFilter = _props$canFilter === void 0 ? false : _props$canFilter,
4917
5074
  _props$canAdd = props.canAdd,
4918
5075
  canAdd = _props$canAdd === void 0 ? false : _props$canAdd,
5076
+ searchBy = props.searchBy,
4919
5077
  _props$autosave = props.autosave,
4920
5078
  autosave = _props$autosave === void 0 ? false : _props$autosave,
4921
5079
  _props$delay = props.delay,
@@ -4993,10 +5151,12 @@ var CollectionPage = function CollectionPage(props) {
4993
5151
  icon: icon,
4994
5152
  levels: levels,
4995
5153
  onSelect: onSelect,
4996
- sorter: sorter
5154
+ sorter: sorter,
5155
+ searchBy: searchBy
4997
5156
  }) : /*#__PURE__*/React.createElement(CollectionList, {
4998
5157
  groupBy: groupBy,
4999
- onSelect: onSelect
5158
+ onSelect: onSelect,
5159
+ searchBy: searchBy
5000
5160
  })), /*#__PURE__*/React.createElement("main", {
5001
5161
  key: id,
5002
5162
  className: "collection-page " + className
@@ -5086,7 +5246,9 @@ var CollectionList = function CollectionList(props) {
5086
5246
  };
5087
5247
 
5088
5248
  var groupBy = props.groupBy,
5089
- onSelect = props.onSelect;
5249
+ onSelect = props.onSelect,
5250
+ _props$searchBy = props.searchBy,
5251
+ searchBy = _props$searchBy === void 0 ? [] : _props$searchBy;
5090
5252
 
5091
5253
  var _useContext2 = useContext(PageContext),
5092
5254
  pageContext = _useContext2[0],
@@ -5095,12 +5257,32 @@ var CollectionList = function CollectionList(props) {
5095
5257
  var _pageContext$all = pageContext.all,
5096
5258
  all = _pageContext$all === void 0 ? [] : _pageContext$all;
5097
5259
 
5260
+ var _useState2 = useState(),
5261
+ filter = _useState2[0],
5262
+ setFilter = _useState2[1];
5263
+
5098
5264
  function clear() {
5099
5265
  pageContext.clear();
5100
5266
  setPageContext(Object.assign({}, pageContext));
5101
5267
  }
5102
5268
 
5103
- var items = all ? all.map(function (content) {
5269
+ function changeSearch(id, value) {
5270
+ setFilter(value);
5271
+ }
5272
+
5273
+ function search() {
5274
+ var items = filter ? all.filter(function (item) {
5275
+ var result = searchBy.some(function (fieldName) {
5276
+ var value = item[fieldName];
5277
+ return value ? value.indexOf(filter.toUpperCase()) >= 0 : false;
5278
+ });
5279
+ return result;
5280
+ }) : all;
5281
+ return items;
5282
+ }
5283
+
5284
+ var items = search();
5285
+ var items2 = items.map(function (content) {
5104
5286
  return {
5105
5287
  id: content.id,
5106
5288
  line1: content.name || content.centre || content.tag,
@@ -5108,12 +5290,20 @@ var CollectionList = function CollectionList(props) {
5108
5290
  line2: content.description,
5109
5291
  content: content
5110
5292
  };
5111
- }) : [];
5112
- return /*#__PURE__*/React.createElement(List, {
5113
- items: items,
5293
+ });
5294
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("main", null, /*#__PURE__*/React.createElement(List, {
5295
+ items: items2,
5114
5296
  onSelect: select,
5115
5297
  groupBy: groupBy
5116
- });
5298
+ })), /*#__PURE__*/React.createElement("footer", null, /*#__PURE__*/React.createElement("div", {
5299
+ className: "search-box"
5300
+ }, /*#__PURE__*/React.createElement(TextField, {
5301
+ icon: "search",
5302
+ label: "Search",
5303
+ onChange: changeSearch,
5304
+ outlined: true,
5305
+ className: "search-box"
5306
+ }))));
5117
5307
  };
5118
5308
  /**
5119
5309
  * Collection Tree
@@ -5137,7 +5327,9 @@ var CollectionTree = function CollectionTree(props) {
5137
5327
  icon = _props$icon === void 0 ? "description" : _props$icon,
5138
5328
  levels = props.levels,
5139
5329
  onSelect = props.onSelect,
5140
- sorter = props.sorter;
5330
+ sorter = props.sorter,
5331
+ _props$searchBy2 = props.searchBy,
5332
+ searchBy = _props$searchBy2 === void 0 ? [] : _props$searchBy2;
5141
5333
 
5142
5334
  var _useContext3 = useContext(PageContext),
5143
5335
  pageContext = _useContext3[0],
@@ -5146,16 +5338,16 @@ var CollectionTree = function CollectionTree(props) {
5146
5338
  var _pageContext$all2 = pageContext.all,
5147
5339
  all = _pageContext$all2 === void 0 ? [] : _pageContext$all2;
5148
5340
 
5149
- var _useState2 = useState(),
5150
- filter = _useState2[0],
5151
- setFilter = _useState2[1];
5341
+ var _useState3 = useState(),
5342
+ filter = _useState3[0],
5343
+ setFilter = _useState3[1];
5152
5344
 
5153
5345
  function clear() {
5154
5346
  pageContext.clear();
5155
5347
  setPageContext(Object.assign({}, pageContext));
5156
5348
  }
5157
5349
 
5158
- function search(id, value) {
5350
+ function changeSearch(id, value) {
5159
5351
  setFilter(value);
5160
5352
  }
5161
5353
 
@@ -5209,17 +5401,26 @@ var CollectionTree = function CollectionTree(props) {
5209
5401
  });
5210
5402
  }
5211
5403
 
5212
- var items = sorter ? sorter(all) : all;
5213
- var items2 = filter ? items.filter(function (item) {
5214
- return item.name.toUpperCase().indexOf(filter.toUpperCase()) >= 0;
5215
- }) : items;
5404
+ function search() {
5405
+ var items = filter ? all.filter(function (item) {
5406
+ var result = searchBy.some(function (fieldName) {
5407
+ var value = item[fieldName];
5408
+ return value ? value.indexOf(filter.toUpperCase()) >= 0 : false;
5409
+ });
5410
+ return result;
5411
+ }) : all;
5412
+ return items;
5413
+ }
5414
+
5415
+ var items = search();
5416
+ var items2 = sorter ? sorter(items) : items;
5216
5417
  var nodes = generateNodes(levels, items2);
5217
5418
  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("main", null, /*#__PURE__*/React.createElement(Tree, null, renderNodes(nodes))), /*#__PURE__*/React.createElement("footer", null, /*#__PURE__*/React.createElement("div", {
5218
5419
  className: "search-box"
5219
5420
  }, /*#__PURE__*/React.createElement(TextField, {
5220
5421
  icon: "search",
5221
5422
  label: "Search",
5222
- onChange: search,
5423
+ onChange: changeSearch,
5223
5424
  outlined: true,
5224
5425
  className: "search-box"
5225
5426
  }))));
@@ -5265,9 +5466,9 @@ var CollectionEditor = function CollectionEditor(props) {
5265
5466
  delay = _props$delay2 === void 0 ? 1000 : _props$delay2;
5266
5467
  var timer = useRef(null);
5267
5468
 
5268
- var _useState3 = useState(selected),
5269
- form = _useState3[0],
5270
- setForm = _useState3[1];
5469
+ var _useState4 = useState(selected),
5470
+ form = _useState4[0],
5471
+ setForm = _useState4[1];
5271
5472
 
5272
5473
  useEffect(function () {
5273
5474
  setForm(selected);