react-hook-core 0.1.0 → 0.1.4

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.
package/README.md CHANGED
@@ -1 +1 @@
1
- # react-xone
1
+ # react
package/lib/components.js CHANGED
@@ -305,23 +305,18 @@ var BaseSearchComponent = (function (_super) {
305
305
  _this.ui = ui;
306
306
  _this.loading = loading;
307
307
  _this.listFormId = listFormId;
308
- _this.initPageSize = 20;
309
- _this.pageSize = 20;
308
+ _this.initPageSize = 24;
309
+ _this.pageSize = 24;
310
310
  _this.pageIndex = 1;
311
- _this.itemTotal = 0;
312
- _this.pageTotal = 0;
311
+ _this.total = 0;
312
+ _this.pages = 0;
313
313
  _this.sequenceNo = 'sequenceNo';
314
314
  _this.tmpPageIndex = 1;
315
315
  _this.pageMaxSize = 7;
316
- _this.pageSizes = [10, 20, 40, 60, 100, 200, 400, 800];
316
+ _this.pageSizes = core_2.pageSizes;
317
317
  _this.viewable = true;
318
318
  _this.addable = true;
319
319
  _this.editable = true;
320
- _this.add = function (event) {
321
- event.preventDefault();
322
- var url = _this.props['props'].match.url + '/add';
323
- _this.props.history.push(url);
324
- };
325
320
  _this.pageSizeOnClick = function () {
326
321
  _this.setState(function (prevState) { return ({ isPageSizeOpenDropDown: !prevState.isPageSizeOpenDropDown }); });
327
322
  };
@@ -332,11 +327,11 @@ var BaseSearchComponent = (function (_super) {
332
327
  _this.doSearch();
333
328
  };
334
329
  _this.resource = resourceService.resource();
330
+ _this.hideFilter = true;
335
331
  _this.getModelName = _this.getModelName.bind(_this);
336
332
  _this.showMessage = _this.showMessage.bind(_this);
337
333
  _this.toggleFilter = _this.toggleFilter.bind(_this);
338
334
  _this.load = _this.load.bind(_this);
339
- _this.add = _this.add.bind(_this);
340
335
  _this.getSearchForm = _this.getSearchForm.bind(_this);
341
336
  _this.setSearchForm = _this.setSearchForm.bind(_this);
342
337
  _this.setFilter = _this.setFilter.bind(_this);
@@ -344,7 +339,7 @@ var BaseSearchComponent = (function (_super) {
344
339
  _this.getFields = _this.getFields.bind(_this);
345
340
  _this.pageSizeChanged = _this.pageSizeChanged.bind(_this);
346
341
  _this.clearQ = _this.clearQ.bind(_this);
347
- _this.searchOnClick = _this.searchOnClick.bind(_this);
342
+ _this.search = _this.search.bind(_this);
348
343
  _this.resetAndSearch = _this.resetAndSearch.bind(_this);
349
344
  _this.doSearch = _this.doSearch.bind(_this);
350
345
  _this.call = _this.call.bind(_this);
@@ -355,14 +350,17 @@ var BaseSearchComponent = (function (_super) {
355
350
  _this.sort = _this.sort.bind(_this);
356
351
  _this.showMore = _this.showMore.bind(_this);
357
352
  _this.pageChanged = _this.pageChanged.bind(_this);
358
- _this.url = (props.match ? props.match.url : props['props'].match.url);
353
+ var currentUrl = window.location.host + window.location.pathname;
354
+ _this.url = removeUrlParams(currentUrl);
359
355
  return _this;
360
356
  }
361
357
  BaseSearchComponent.prototype.getModelName = function () {
362
358
  return 'filter';
363
359
  };
364
360
  BaseSearchComponent.prototype.toggleFilter = function (event) {
365
- this.hideFilter = !this.hideFilter;
361
+ var x = !this.hideFilter;
362
+ core_1.handleToggle(event.target, !x);
363
+ this.hideFilter = x;
366
364
  };
367
365
  BaseSearchComponent.prototype.load = function (s, autoSearch) {
368
366
  var obj2 = search_core_1.initFilter(s, this);
@@ -384,7 +382,10 @@ var BaseSearchComponent = (function (_super) {
384
382
  return this.form;
385
383
  };
386
384
  BaseSearchComponent.prototype.setFilter = function (filter) {
387
- this.setState(filter);
385
+ var modelName = this.getModelName();
386
+ var objSet = {};
387
+ objSet[modelName] = filter;
388
+ this.setState(objSet);
388
389
  };
389
390
  BaseSearchComponent.prototype.getCurrencyCode = function () {
390
391
  return core_2.getCurrencyCode(this.form);
@@ -423,7 +424,7 @@ var BaseSearchComponent = (function (_super) {
423
424
  });
424
425
  }
425
426
  };
426
- BaseSearchComponent.prototype.searchOnClick = function (event) {
427
+ BaseSearchComponent.prototype.search = function (event) {
427
428
  if (event) {
428
429
  event.preventDefault();
429
430
  if (!this.getSearchForm()) {
@@ -477,12 +478,12 @@ var BaseSearchComponent = (function (_super) {
477
478
  var results = sr.list;
478
479
  if (results && results.length > 0) {
479
480
  var lc = state_1.localeOf(undefined, this.getLocale);
480
- search_core_1.formatResultsByComponent(results, com, lc);
481
+ search_core_1.formatResults(results, com.pageIndex, com.pageSize, com.pageSize, com.sequenceNo, com.format, lc);
481
482
  }
482
483
  var am = com.appendMode;
483
484
  com.pageIndex = (s.page && s.page >= 1 ? s.page : 1);
484
485
  if (sr.total) {
485
- com.itemTotal = sr.total;
486
+ com.total = sr.total;
486
487
  }
487
488
  if (am) {
488
489
  var limit = s.limit;
@@ -560,8 +561,8 @@ var BaseSearchComponent = (function (_super) {
560
561
  this.doSearch();
561
562
  };
562
563
  BaseSearchComponent.prototype.pageChanged = function (data) {
563
- var currentPage = data.currentPage, itemsPerPage = data.itemsPerPage;
564
- search_core_1.changePage(this, currentPage, itemsPerPage);
564
+ var page = data.page, size = data.size;
565
+ search_core_1.changePage(this, page, size);
565
566
  this.doSearch();
566
567
  };
567
568
  return BaseSearchComponent;
@@ -571,19 +572,25 @@ var SearchComponent = (function (_super) {
571
572
  __extends(SearchComponent, _super);
572
573
  function SearchComponent(props, sv, param, showMessage, showError, getLocale, uis, loading, listFormId) {
573
574
  var _this = _super.call(this, props, input_1.getResource(param), input_1.getMsgFunc(param, showMessage), input_1.getLocaleFunc(param, getLocale), input_1.getUIService(param, uis), input_1.getLoadingFunc(param, loading), listFormId) || this;
575
+ _this.add = function (event) {
576
+ event.preventDefault();
577
+ var url = _this.url + '/add';
578
+ _this.props.history.push(url);
579
+ };
574
580
  _this.autoSearch = input_1.getAutoSearch(param);
575
581
  if (sv) {
576
582
  if (typeof sv === 'function') {
577
583
  var x = sv;
578
- _this.search = x;
584
+ _this.service = x;
579
585
  }
580
586
  else {
581
- _this.search = sv.search;
587
+ _this.service = sv.search;
582
588
  if (sv.keys) {
583
589
  _this.keys = sv.keys();
584
590
  }
585
591
  }
586
592
  }
593
+ _this.add = _this.add.bind(_this);
587
594
  _this.call = _this.call.bind(_this);
588
595
  _this.showError = input_1.getErrorFunc(param, showError);
589
596
  _this.componentDidMount = _this.componentDidMount.bind(_this);
@@ -630,8 +637,8 @@ var SearchComponent = (function (_super) {
630
637
  delete se['firstLimit'];
631
638
  core_1.showLoading(this.loading);
632
639
  var com = this;
633
- if (this.search) {
634
- this.search(s, limit, next, fields).then(function (sr) {
640
+ if (this.service) {
641
+ this.service(s, limit, next, fields).then(function (sr) {
635
642
  com.showResults(s, sr);
636
643
  com.running = undefined;
637
644
  core_1.hideLoading(com.loading);
@@ -659,7 +666,7 @@ var BaseEditComponent = (function (_super) {
659
666
  _this.backOnSuccess = true;
660
667
  _this.patchable = true;
661
668
  _this.addable = true;
662
- _this.newOnClick = function (event) {
669
+ _this.create = function (event) {
663
670
  if (event) {
664
671
  event.preventDefault();
665
672
  }
@@ -676,7 +683,7 @@ var BaseEditComponent = (function (_super) {
676
683
  }, 100);
677
684
  }
678
685
  };
679
- _this.saveOnClick = function (event) {
686
+ _this.save = function (event) {
680
687
  event.preventDefault();
681
688
  event.persist();
682
689
  if (!_this.form && event && event.target) {
@@ -704,11 +711,11 @@ var BaseEditComponent = (function (_super) {
704
711
  _this.showModel = _this.showModel.bind(_this);
705
712
  _this.getModel = _this.getModel.bind(_this);
706
713
  _this.createModel = _this.createModel.bind(_this);
707
- _this.newOnClick = _this.newOnClick.bind(_this);
708
- _this.saveOnClick = _this.saveOnClick.bind(_this);
714
+ _this.create = _this.create.bind(_this);
715
+ _this.save = _this.save.bind(_this);
709
716
  _this.onSave = _this.onSave.bind(_this);
710
717
  _this.validate = _this.validate.bind(_this);
711
- _this.save = _this.save.bind(_this);
718
+ _this.doSave = _this.doSave.bind(_this);
712
719
  _this.succeed = _this.succeed.bind(_this);
713
720
  _this.fail = _this.fail.bind(_this);
714
721
  _this.postSave = _this.postSave.bind(_this);
@@ -788,7 +795,7 @@ var BaseEditComponent = (function (_super) {
788
795
  com_2.validate(obj_1, function () {
789
796
  var msg = core_2.message(r.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
790
797
  _this.confirm(msg.message, msg.title, function () {
791
- com_2.save(obj_1, obj_1, isBack);
798
+ com_2.doSave(obj_1, obj_1, isBack);
792
799
  }, msg.no, msg.yes);
793
800
  });
794
801
  }
@@ -802,7 +809,7 @@ var BaseEditComponent = (function (_super) {
802
809
  com_2.validate(obj_1, function () {
803
810
  var msg = core_2.message(r.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
804
811
  _this.confirm(msg.message, msg.title, function () {
805
- com_2.save(obj_1, diffObj_1, isBack);
812
+ com_2.doSave(obj_1, diffObj_1, isBack);
806
813
  }, msg.no, msg.yes);
807
814
  });
808
815
  }
@@ -820,7 +827,7 @@ var BaseEditComponent = (function (_super) {
820
827
  callback(obj);
821
828
  }
822
829
  };
823
- BaseEditComponent.prototype.save = function (obj, dif, isBack) {
830
+ BaseEditComponent.prototype.doSave = function (obj, dif, isBack) {
824
831
  };
825
832
  BaseEditComponent.prototype.succeed = function (msg, isBack, result) {
826
833
  if (result) {
@@ -943,7 +950,7 @@ var EditComponent = (function (_super) {
943
950
  _this.keys = [];
944
951
  }
945
952
  _this.load = _this.load.bind(_this);
946
- _this.save = _this.save.bind(_this);
953
+ _this.doSave = _this.doSave.bind(_this);
947
954
  _this.componentDidMount = _this.componentDidMount.bind(_this);
948
955
  _this.ref = React.createRef();
949
956
  return _this;
@@ -952,9 +959,7 @@ var EditComponent = (function (_super) {
952
959
  var k = (this.ui ? this.ui.registerEvents : undefined);
953
960
  this.form = core_2.initForm(this.ref.current, k);
954
961
  var id = core_2.buildId(this.props, this.keys);
955
- if (id) {
956
- this.load(id);
957
- }
962
+ this.load(id);
958
963
  };
959
964
  EditComponent.prototype.load = function (_id, callback) {
960
965
  var _this = this;
@@ -1013,7 +1018,7 @@ var EditComponent = (function (_super) {
1013
1018
  }
1014
1019
  }
1015
1020
  };
1016
- EditComponent.prototype.save = function (obj, body, isBack) {
1021
+ EditComponent.prototype.doSave = function (obj, body, isBack) {
1017
1022
  this.running = true;
1018
1023
  core_1.showLoading(this.loading);
1019
1024
  var isBackO = (isBack == null || isBack === undefined ? this.backOnSuccess : isBack);
@@ -1254,3 +1259,8 @@ var DiffApprComponent = (function (_super) {
1254
1259
  return DiffApprComponent;
1255
1260
  }(BaseDiffApprComponent));
1256
1261
  exports.DiffApprComponent = DiffApprComponent;
1262
+ function removeUrlParams(url) {
1263
+ var startParams = url.indexOf('?');
1264
+ return startParams !== -1 ? url.substring(0, startParams) : url;
1265
+ }
1266
+ exports.removeUrlParams = removeUrlParams;
package/lib/core.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var formutil_1 = require("./formutil");
4
+ exports.pageSizes = [12, 24, 60, 100, 120, 180, 300, 600];
4
5
  function createEditStatus(status) {
5
6
  if (status) {
6
7
  return status;
@@ -268,3 +269,16 @@ function getDecodeFromForm(u, d) {
268
269
  return (u && u.ui ? u.ui.decodeFromForm : undefined);
269
270
  }
270
271
  exports.getDecodeFromForm = getDecodeFromForm;
272
+ function handleToggle(target, on) {
273
+ if (target) {
274
+ if (on) {
275
+ if (!target.classList.contains('on')) {
276
+ target.classList.add('on');
277
+ }
278
+ }
279
+ else {
280
+ target.classList.remove('on');
281
+ }
282
+ }
283
+ }
284
+ exports.handleToggle = handleToggle;
package/lib/index.js CHANGED
@@ -19,8 +19,39 @@ __export(require("./useView"));
19
19
  __export(require("./useEdit"));
20
20
  __export(require("./useSearch"));
21
21
  __export(require("./useMessage"));
22
+ function checked(s, v) {
23
+ if (s) {
24
+ if (Array.isArray(s)) {
25
+ return s.includes(v);
26
+ }
27
+ else {
28
+ return s === v;
29
+ }
30
+ }
31
+ return false;
32
+ }
33
+ exports.checked = checked;
34
+ function value(obj) {
35
+ return (obj ? obj : {});
36
+ }
37
+ exports.value = value;
22
38
  exports.withDefaultProps = function (Component) {
23
39
  return function (props) {
24
40
  return React.createElement(Component, { props: props, history: props.history });
25
41
  };
26
42
  };
43
+ exports.Loading = function (props) {
44
+ var loadingStyle = {
45
+ top: '30%',
46
+ backgroundColor: 'white',
47
+ border: 'none',
48
+ 'WebkitBoxShadow': 'none',
49
+ 'boxShadow': 'none'
50
+ };
51
+ if (props.error) {
52
+ return React.createElement('div', null, 'Error Load Module!');
53
+ }
54
+ else {
55
+ return (React.createElement('div', { className: 'loader-wrapper' }, React.createElement('div', { className: 'loader-sign', style: loadingStyle }, React.createElement('div', { className: 'loader' }))));
56
+ }
57
+ };
package/lib/useEdit.js CHANGED
@@ -39,20 +39,20 @@ exports.useEditProps = function (props, refForm, initialState, service, p2, p) {
39
39
  var keys;
40
40
  if (p && !p.keys && service && service.metadata) {
41
41
  var metadata = (p.metadata ? p.metadata : service.metadata());
42
- var meta = edit_1.build(metadata);
43
- keys = (p.keys ? p.keys : (meta ? meta.keys : undefined));
44
- var version = (p.version ? p.version : (meta ? meta.version : undefined));
45
- p.keys = keys;
46
- p.version = version;
42
+ if (metadata) {
43
+ var meta = edit_1.build(metadata);
44
+ keys = (p.keys ? p.keys : (meta ? meta.keys : undefined));
45
+ var version = (p.version ? p.version : (meta ? meta.version : undefined));
46
+ p.keys = keys;
47
+ p.version = version;
48
+ }
47
49
  }
48
50
  var id = core_1.buildId(props, keys);
49
- if (id) {
50
- if (p && p.initialize) {
51
- p.initialize(id, baseProps.load, baseProps.setState, p.callback);
52
- }
53
- else {
54
- baseProps.load(id, p ? p.callback : undefined);
55
- }
51
+ if (p && p.initialize) {
52
+ p.initialize(id, baseProps.load, baseProps.setState, p.callback);
53
+ }
54
+ else {
55
+ baseProps.load(id, p ? p.callback : undefined);
56
56
  }
57
57
  }, []);
58
58
  return __assign({}, baseProps);
@@ -145,7 +145,7 @@ exports.useCoreEdit = function (props, refForm, initialState, service, p1, p) {
145
145
  }
146
146
  };
147
147
  var createModel = (p && p.createModel ? p.createModel : _createModel);
148
- var newOnClick = function (event) {
148
+ var create = function (event) {
149
149
  event.preventDefault();
150
150
  var obj = createModel();
151
151
  resetState(true, obj, undefined);
@@ -184,7 +184,7 @@ exports.useCoreEdit = function (props, refForm, initialState, service, p1, p) {
184
184
  validate(obj_1, function () {
185
185
  var msg = core_1.message(p1.resource.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
186
186
  p1.confirm(msg.message, msg.title, function () {
187
- save(obj_1, undefined, version_1, isBack);
187
+ doSave(obj_1, undefined, version_1, isBack);
188
188
  }, msg.no, msg.yes);
189
189
  });
190
190
  }
@@ -198,7 +198,7 @@ exports.useCoreEdit = function (props, refForm, initialState, service, p1, p) {
198
198
  validate(obj_1, function () {
199
199
  var msg = core_1.message(p1.resource.value, 'msg_confirm_save', 'confirm', 'yes', 'no');
200
200
  p1.confirm(msg.message, msg.title, function () {
201
- save(obj_1, diffObj_1, version_1, isBack);
201
+ doSave(obj_1, diffObj_1, version_1, isBack);
202
202
  }, msg.no, msg.yes);
203
203
  });
204
204
  }
@@ -206,7 +206,7 @@ exports.useCoreEdit = function (props, refForm, initialState, service, p1, p) {
206
206
  }
207
207
  };
208
208
  var onSave = (p && p.onSave ? p.onSave : _onSave);
209
- var saveOnClick = function (event) {
209
+ var save = function (event) {
210
210
  event.preventDefault();
211
211
  event.persist();
212
212
  onSave();
@@ -319,7 +319,7 @@ exports.useCoreEdit = function (props, refForm, initialState, service, p1, p) {
319
319
  p1.showError(msg.message, msg.title);
320
320
  };
321
321
  var handleDuplicateKey = (p && p.handleDuplicateKey ? p.handleDuplicateKey : _handleDuplicateKey);
322
- var _save = function (obj, body, version, isBack) {
322
+ var _doSave = function (obj, body, version, isBack) {
323
323
  setRunning(true);
324
324
  core_1.showLoading(p1.loading);
325
325
  var isBackO = (isBack == null || isBack === undefined ? true : isBack);
@@ -336,7 +336,7 @@ exports.useCoreEdit = function (props, refForm, initialState, service, p1, p) {
336
336
  service.insert(obj).then(function (result) { return postSave(obj, result, version, isBackO); });
337
337
  }
338
338
  };
339
- var save = (p && p.save ? p.save : _save);
339
+ var doSave = (p && p.doSave ? p.doSave : _doSave);
340
340
  var _load = function (_id, callback) {
341
341
  var id = _id;
342
342
  if (id != null && id !== '') {
@@ -400,8 +400,7 @@ exports.useCoreEdit = function (props, refForm, initialState, service, p1, p) {
400
400
  getModelName: getModelName,
401
401
  resetState: resetState,
402
402
  handleNotFound: handleNotFound,
403
- getModel: getModel, createNewModel: createModel, newOnClick: newOnClick,
404
- saveOnClick: saveOnClick,
403
+ getModel: getModel, createNewModel: createModel, newOnClick: create, save: save,
405
404
  onSave: onSave,
406
405
  confirm: confirm,
407
406
  validate: validate, showMessage: p1.showMessage, succeed: succeed,
@@ -409,6 +408,6 @@ exports.useCoreEdit = function (props, refForm, initialState, service, p1, p) {
409
408
  postSave: postSave,
410
409
  handleDuplicateKey: handleDuplicateKey,
411
410
  load: load,
412
- save: save
411
+ doSave: doSave
413
412
  });
414
413
  };