react-hook-core 0.1.4 → 0.1.7

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/lib/com.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var React = require("react");
4
+ var core_1 = require("./core");
5
+ function PageSizeSelect(p) {
6
+ var g = p.sizes;
7
+ var s = (!g || g.length === 0 ? core_1.pageSizes : g);
8
+ var opts = s.map(function (pgSize) { return React.createElement('option', { key: pgSize, value: pgSize }, pgSize); });
9
+ return React.createElement('select', { id: p.id, name: p.name, defaultValue: p.size, onChange: p.onChange }, opts);
10
+ }
11
+ exports.PageSizeSelect = PageSizeSelect;
12
+ function Search(p) {
13
+ return (React.createElement(React.Fragment, null, React.createElement("label", { className: p.className }, p.pageSizeChanged && React.createElement(PageSizeSelect, { size: p.size, sizes: p.sizes, onChange: p.pageSizeChanged, name: p.name, id: p.id }), React.createElement("input", { type: 'text', id: 'q', name: 'q', value: p.value || '', onChange: p.onChange, maxLength: p.maxLength, placeholder: p.placeholder }), p.clear && React.createElement("button", { type: 'button', hidden: !p.value, className: 'btn-remove-text', onClick: p.clear }), p.toggle && React.createElement("button", { type: 'button', className: 'btn-filter', onClick: p.toggle }), p.search && React.createElement("button", { type: 'submit', className: 'btn-search', onClick: p.search }))));
14
+ }
15
+ exports.Search = Search;
package/lib/components.js CHANGED
@@ -25,15 +25,15 @@ var __assign = (this && this.__assign) || function () {
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  var React = require("react");
28
- var reflectx_1 = require("reflectx");
29
- var search_core_1 = require("search-core");
30
28
  var core_1 = require("./core");
31
29
  var core_2 = require("./core");
32
30
  var diff_1 = require("./diff");
33
31
  var edit_1 = require("./edit");
34
32
  var formutil_1 = require("./formutil");
35
33
  var input_1 = require("./input");
34
+ var reflect_1 = require("./reflect");
36
35
  var route_1 = require("./route");
36
+ var search_1 = require("./search");
37
37
  var state_1 = require("./state");
38
38
  var ViewComponent = (function (_super) {
39
39
  __extends(ViewComponent, _super);
@@ -62,7 +62,6 @@ var ViewComponent = (function (_super) {
62
62
  }
63
63
  }
64
64
  }
65
- _this.back = _this.back.bind(_this);
66
65
  _this.getModelName = _this.getModelName.bind(_this);
67
66
  _this.load = _this.load.bind(_this);
68
67
  _this.getModel = _this.getModel.bind(_this);
@@ -70,12 +69,6 @@ var ViewComponent = (function (_super) {
70
69
  _this.ref = React.createRef();
71
70
  return _this;
72
71
  }
73
- ViewComponent.prototype.back = function (event) {
74
- if (event) {
75
- event.preventDefault();
76
- }
77
- this.props.history.goBack();
78
- };
79
72
  ViewComponent.prototype.getModelName = function () {
80
73
  if (this.name && this.name.length > 0) {
81
74
  return this.name;
@@ -88,13 +81,6 @@ var ViewComponent = (function (_super) {
88
81
  return n;
89
82
  }
90
83
  };
91
- ViewComponent.prototype.componentDidMount = function () {
92
- this.form = this.ref.current;
93
- var id = core_2.buildId(this.props, this.keys);
94
- if (id) {
95
- this.load(id);
96
- }
97
- };
98
84
  ViewComponent.prototype.load = function (_id, callback) {
99
85
  var id = _id;
100
86
  if (id != null && id !== '' && this.loadData) {
@@ -322,7 +308,7 @@ var BaseSearchComponent = (function (_super) {
322
308
  };
323
309
  _this.pageSizeChanged = function (event) {
324
310
  var size = parseInt(event.currentTarget.value, 10);
325
- search_core_1.changePageSize(_this, size);
311
+ search_1.changePageSize(_this, size);
326
312
  _this.tmpPageIndex = 1;
327
313
  _this.doSearch();
328
314
  };
@@ -363,7 +349,7 @@ var BaseSearchComponent = (function (_super) {
363
349
  this.hideFilter = x;
364
350
  };
365
351
  BaseSearchComponent.prototype.load = function (s, autoSearch) {
366
- var obj2 = search_core_1.initFilter(s, this);
352
+ var obj2 = search_1.initFilter(s, this);
367
353
  this.setFilter(obj2);
368
354
  var com = this;
369
355
  if (autoSearch) {
@@ -404,11 +390,11 @@ var BaseSearchComponent = (function (_super) {
404
390
  var l = this.getList();
405
391
  var f = this.getSearchForm();
406
392
  var dc = (this.ui ? this.ui.decodeFromForm : undefined);
407
- var obj3 = search_core_1.getModel(this.state, name, this, fields, this.excluding, this.keys, l, f, dc, lc, cc);
393
+ var obj3 = search_1.getModel(this.state, name, this, fields, this.excluding, this.keys, l, f, dc, lc, cc);
408
394
  return obj3;
409
395
  };
410
396
  BaseSearchComponent.prototype.getFields = function () {
411
- var fs = search_core_1.getFieldsFromForm(this.fields, this.initFields, this.form);
397
+ var fs = search_1.getFieldsFromForm(this.fields, this.initFields, this.form);
412
398
  this.initFields = true;
413
399
  return fs;
414
400
  };
@@ -442,7 +428,7 @@ var BaseSearchComponent = (function (_super) {
442
428
  this.triggerSearch = true;
443
429
  return;
444
430
  }
445
- search_core_1.reset(this);
431
+ search_1.reset(this);
446
432
  this.tmpPageIndex = 1;
447
433
  this.doSearch();
448
434
  };
@@ -461,7 +447,7 @@ var BaseSearchComponent = (function (_super) {
461
447
  com.running = true;
462
448
  core_1.showLoading(_this.loading);
463
449
  if (!_this.ignoreUrlParam) {
464
- search_core_1.addParametersIntoUrl(s, isFirstLoad);
450
+ search_1.addParametersIntoUrl(s, isFirstLoad);
465
451
  }
466
452
  com.call(s);
467
453
  });
@@ -471,14 +457,14 @@ var BaseSearchComponent = (function (_super) {
471
457
  BaseSearchComponent.prototype.validateSearch = function (se, callback) {
472
458
  var u = this.ui;
473
459
  var vl = (u ? u.validateForm : undefined);
474
- search_core_1.validate(se, callback, this.getSearchForm(), state_1.localeOf(undefined, this.getLocale), vl);
460
+ search_1.validate(se, callback, this.getSearchForm(), state_1.localeOf(undefined, this.getLocale), vl);
475
461
  };
476
462
  BaseSearchComponent.prototype.showResults = function (s, sr) {
477
463
  var com = this;
478
464
  var results = sr.list;
479
465
  if (results && results.length > 0) {
480
466
  var lc = state_1.localeOf(undefined, this.getLocale);
481
- search_core_1.formatResults(results, com.pageIndex, com.pageSize, com.pageSize, com.sequenceNo, com.format, lc);
467
+ search_1.formatResults(results, com.pageIndex, com.pageSize, com.pageSize, com.sequenceNo, com.format, lc);
482
468
  }
483
469
  var am = com.appendMode;
484
470
  com.pageIndex = (s.page && s.page >= 1 ? s.page : 1);
@@ -491,7 +477,7 @@ var BaseSearchComponent = (function (_super) {
491
477
  limit = s.firstLimit;
492
478
  }
493
479
  com.nextPageToken = sr.nextPageToken;
494
- search_core_1.handleAppend(com, sr.list, limit, sr.nextPageToken);
480
+ search_1.handleAppend(com, sr.list, limit, sr.nextPageToken);
495
481
  if (com.append && (s.page && s.page > 1)) {
496
482
  com.appendList(results);
497
483
  }
@@ -500,11 +486,11 @@ var BaseSearchComponent = (function (_super) {
500
486
  }
501
487
  }
502
488
  else {
503
- search_core_1.showPaging(com, sr.list, s.limit, sr.total);
489
+ search_1.showPaging(com, sr.list, s.limit, sr.total);
504
490
  com.setList(results);
505
491
  com.tmpPageIndex = s.page;
506
492
  if (s.limit) {
507
- this.showMessage(search_core_1.buildMessage(this.resourceService, s.page, s.limit, sr.list, sr.total));
493
+ this.showMessage(search_1.buildMessage(this.resourceService, s.page, s.limit, sr.list, sr.total));
508
494
  }
509
495
  }
510
496
  com.running = undefined;
@@ -517,7 +503,7 @@ var BaseSearchComponent = (function (_super) {
517
503
  BaseSearchComponent.prototype.appendList = function (results) {
518
504
  var _a;
519
505
  var list = this.state.list;
520
- var arr = search_core_1.append(list, results);
506
+ var arr = search_1.append(list, results);
521
507
  var listForm = this.getSearchForm();
522
508
  var props = this.props;
523
509
  var setGlobalState = props.props.setGlobalState;
@@ -546,7 +532,7 @@ var BaseSearchComponent = (function (_super) {
546
532
  };
547
533
  BaseSearchComponent.prototype.sort = function (event) {
548
534
  event.preventDefault();
549
- search_core_1.handleSortEvent(event, this);
535
+ search_1.handleSortEvent(event, this);
550
536
  if (!this.appendMode) {
551
537
  this.doSearch();
552
538
  }
@@ -557,12 +543,12 @@ var BaseSearchComponent = (function (_super) {
557
543
  BaseSearchComponent.prototype.showMore = function (event) {
558
544
  event.preventDefault();
559
545
  this.tmpPageIndex = this.pageIndex;
560
- search_core_1.more(this);
546
+ search_1.more(this);
561
547
  this.doSearch();
562
548
  };
563
549
  BaseSearchComponent.prototype.pageChanged = function (data) {
564
550
  var page = data.page, size = data.size;
565
- search_core_1.changePage(this, page, size);
551
+ search_1.changePage(this, page, size);
566
552
  this.doSearch();
567
553
  };
568
554
  return BaseSearchComponent;
@@ -572,11 +558,6 @@ var SearchComponent = (function (_super) {
572
558
  __extends(SearchComponent, _super);
573
559
  function SearchComponent(props, sv, param, showMessage, showError, getLocale, uis, loading, listFormId) {
574
560
  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
- };
580
561
  _this.autoSearch = input_1.getAutoSearch(param);
581
562
  if (sv) {
582
563
  if (typeof sv === 'function') {
@@ -590,7 +571,6 @@ var SearchComponent = (function (_super) {
590
571
  }
591
572
  }
592
573
  }
593
- _this.add = _this.add.bind(_this);
594
574
  _this.call = _this.call.bind(_this);
595
575
  _this.showError = input_1.getErrorFunc(param, showError);
596
576
  _this.componentDidMount = _this.componentDidMount.bind(_this);
@@ -606,7 +586,7 @@ var SearchComponent = (function (_super) {
606
586
  this.load(s, this.autoSearch);
607
587
  };
608
588
  SearchComponent.prototype.mergeFilter = function (obj, b, arrs) {
609
- return search_core_1.mergeFilter(obj, b, this.pageSizes, arrs);
589
+ return search_1.mergeFilter(obj, b, this.pageSizes, arrs);
610
590
  };
611
591
  SearchComponent.prototype.createFilter = function () {
612
592
  var s = {};
@@ -614,7 +594,7 @@ var SearchComponent = (function (_super) {
614
594
  };
615
595
  SearchComponent.prototype.call = function (se) {
616
596
  this.running = true;
617
- var s = reflectx_1.clone(se);
597
+ var s = reflect_1.clone(se);
618
598
  var page = this.pageIndex;
619
599
  if (!page || page < 1) {
620
600
  page = 1;
@@ -726,7 +706,6 @@ var BaseEditComponent = (function (_super) {
726
706
  if (event) {
727
707
  event.preventDefault();
728
708
  }
729
- this.props.history.goBack();
730
709
  };
731
710
  BaseEditComponent.prototype.resetState = function (newMod, model, originalModel) {
732
711
  this.newMode = newMod;
@@ -800,7 +779,7 @@ var BaseEditComponent = (function (_super) {
800
779
  });
801
780
  }
802
781
  else {
803
- var diffObj_1 = reflectx_1.makeDiff(edit_1.initPropertyNullInModel(this.orginalModel, this.metadata), obj_1, this.keys, this.version);
782
+ var diffObj_1 = reflect_1.makeDiff(edit_1.initPropertyNullInModel(this.orginalModel, this.metadata), obj_1, this.keys, this.version);
804
783
  var keys = Object.keys(diffObj_1);
805
784
  if (keys.length === 0) {
806
785
  this.showMessage(r.value('msg_no_change'));
@@ -834,7 +813,7 @@ var BaseEditComponent = (function (_super) {
834
813
  var model = result.value;
835
814
  this.newMode = false;
836
815
  if (model && this.setBack) {
837
- this.resetState(false, model, reflectx_1.clone(model));
816
+ this.resetState(false, model, reflect_1.clone(model));
838
817
  }
839
818
  else {
840
819
  edit_1.handleVersion(this.getModel(), this.version);
@@ -951,16 +930,9 @@ var EditComponent = (function (_super) {
951
930
  }
952
931
  _this.load = _this.load.bind(_this);
953
932
  _this.doSave = _this.doSave.bind(_this);
954
- _this.componentDidMount = _this.componentDidMount.bind(_this);
955
933
  _this.ref = React.createRef();
956
934
  return _this;
957
935
  }
958
- EditComponent.prototype.componentDidMount = function () {
959
- var k = (this.ui ? this.ui.registerEvents : undefined);
960
- this.form = core_2.initForm(this.ref.current, k);
961
- var id = core_2.buildId(this.props, this.keys);
962
- this.load(id);
963
- };
964
936
  EditComponent.prototype.load = function (_id, callback) {
965
937
  var _this = this;
966
938
  var id = _id;
@@ -974,7 +946,7 @@ var EditComponent = (function (_super) {
974
946
  }
975
947
  else {
976
948
  com_3.newMode = false;
977
- com_3.orginalModel = reflectx_1.clone(obj);
949
+ com_3.orginalModel = reflect_1.clone(obj);
978
950
  if (!callback) {
979
951
  com_3.showModel(obj);
980
952
  }
@@ -1056,7 +1028,6 @@ var BaseDiffApprComponent = (function (_super) {
1056
1028
  _this.resource = resourceService.resource();
1057
1029
  _this.showMessage = _this.showMessage.bind(_this);
1058
1030
  _this.showError = _this.showError.bind(_this);
1059
- _this.back = _this.back.bind(_this);
1060
1031
  _this.initModel = _this.initModel.bind(_this);
1061
1032
  _this.postApprove = _this.postApprove.bind(_this);
1062
1033
  _this.postReject = _this.postReject.bind(_this);
@@ -1068,12 +1039,6 @@ var BaseDiffApprComponent = (function (_super) {
1068
1039
  };
1069
1040
  return _this;
1070
1041
  }
1071
- BaseDiffApprComponent.prototype.back = function (event) {
1072
- if (event) {
1073
- event.preventDefault();
1074
- }
1075
- this.props.history.goBack();
1076
- };
1077
1042
  BaseDiffApprComponent.prototype.initModel = function () {
1078
1043
  var x = {};
1079
1044
  return x;
@@ -1118,7 +1083,7 @@ var BaseDiffApprComponent = (function (_super) {
1118
1083
  var p = this.props;
1119
1084
  var diffModel = p['diffModel'];
1120
1085
  if (diffModel) {
1121
- var differentKeys_1 = reflectx_1.diff(diffModel.origin, diffModel.value);
1086
+ var differentKeys_1 = reflect_1.diff(diffModel.origin, diffModel.value);
1122
1087
  var dataFields = diff_1.getDataFields(this.form);
1123
1088
  dataFields.forEach(function (e) {
1124
1089
  var x = e.getAttribute('data-field');
@@ -1137,7 +1102,7 @@ var BaseDiffApprComponent = (function (_super) {
1137
1102
  }
1138
1103
  else {
1139
1104
  var _a = this.state, origin_1 = _a.origin, value = _a.value;
1140
- var differentKeys_2 = reflectx_1.diff(origin_1, value);
1105
+ var differentKeys_2 = reflect_1.diff(origin_1, value);
1141
1106
  var dataFields = diff_1.getDataFields(this.form);
1142
1107
  dataFields.forEach(function (e) {
1143
1108
  var x = e.getAttribute('data-field');
@@ -1179,13 +1144,6 @@ var DiffApprComponent = (function (_super) {
1179
1144
  };
1180
1145
  return _this;
1181
1146
  }
1182
- DiffApprComponent.prototype.componentDidMount = function () {
1183
- this.form = this.ref.current;
1184
- var id = core_2.buildId(this.props, this.keys);
1185
- if (id) {
1186
- this.load(id);
1187
- }
1188
- };
1189
1147
  DiffApprComponent.prototype.formatFields = function (value) {
1190
1148
  return value;
1191
1149
  };
package/lib/core.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var formutil_1 = require("./formutil");
4
4
  exports.pageSizes = [12, 24, 60, 100, 120, 180, 300, 600];
5
+ exports.size = exports.pageSizes;
5
6
  function createEditStatus(status) {
6
7
  if (status) {
7
8
  return status;
@@ -33,7 +34,7 @@ exports.createDiffStatus = createDiffStatus;
33
34
  var resource = (function () {
34
35
  function resource() {
35
36
  }
36
- resource.phone = / |\-|\.|\(|\)/g;
37
+ resource.phone = / |-|\.|\(|\)/g;
37
38
  resource._cache = {};
38
39
  resource.cache = true;
39
40
  return resource;
@@ -107,26 +108,21 @@ function buildKeys(attributes) {
107
108
  return ps;
108
109
  }
109
110
  exports.buildKeys = buildKeys;
110
- function buildId(props, keys) {
111
- if (!props) {
112
- return null;
113
- }
114
- var sp = (props.match ? props : props['props']);
111
+ function buildId(p, keys) {
115
112
  if (!keys || keys.length === 0 || keys.length === 1) {
116
113
  if (keys && keys.length === 1) {
117
- var x = sp.match.params[keys[0]];
118
- if (x && x !== '') {
119
- return x;
114
+ if (p[keys[0]]) {
115
+ return p[keys[0]];
120
116
  }
121
117
  }
122
- return sp.match.params['id'];
118
+ return p['id'];
123
119
  }
124
120
  var id = {};
125
121
  for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
126
122
  var key = keys_1[_i];
127
- var v = sp.match.params[key];
123
+ var v = p[key];
128
124
  if (!v) {
129
- v = sp[key];
125
+ v = p[key];
130
126
  if (!v) {
131
127
  return null;
132
128
  }
package/lib/diff.js CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var reflectx_1 = require("reflectx");
3
+ var reflect_1 = require("./reflect");
4
4
  function formatDiffModel(obj, formatFields) {
5
5
  if (!obj) {
6
6
  return obj;
7
7
  }
8
- var obj2 = reflectx_1.clone(obj);
8
+ var obj2 = reflect_1.clone(obj);
9
9
  if (!obj2.origin) {
10
10
  obj2.origin = {};
11
11
  }
package/lib/formutil.js CHANGED
@@ -80,7 +80,7 @@ function focusFirstError(form, className) {
80
80
  var ctrl = form[i];
81
81
  var parent_1 = ctrl.parentElement;
82
82
  if (ctrl.classList.contains(className)
83
- || parent_1 && parent_1.classList.contains(className)) {
83
+ || (parent_1 && parent_1.classList.contains(className))) {
84
84
  ctrl.focus();
85
85
  ctrl.scrollIntoView();
86
86
  return;
@@ -93,7 +93,7 @@ function focusFirstError(form, className) {
93
93
  var parent_2 = ctrl.parentElement;
94
94
  if (ctrl.classList.contains('invalid')
95
95
  || ctrl.classList.contains('.ng-invalid')
96
- || parent_2 && parent_2.classList.contains('invalid')) {
96
+ || (parent_2 && parent_2.classList.contains('invalid'))) {
97
97
  ctrl.focus();
98
98
  ctrl.scrollIntoView();
99
99
  return;
package/lib/index.js CHANGED
@@ -10,15 +10,16 @@ __export(require("./core"));
10
10
  __export(require("./state"));
11
11
  __export(require("./edit"));
12
12
  __export(require("./route"));
13
- __export(require("./components"));
14
13
  __export(require("./diff"));
15
- __export(require("./router"));
16
14
  __export(require("./merge"));
17
15
  __export(require("./update"));
18
- __export(require("./useView"));
19
- __export(require("./useEdit"));
20
16
  __export(require("./useSearch"));
21
17
  __export(require("./useMessage"));
18
+ __export(require("./useEdit"));
19
+ __export(require("./components"));
20
+ __export(require("./search"));
21
+ __export(require("./reflect"));
22
+ __export(require("./com"));
22
23
  function checked(s, v) {
23
24
  if (s) {
24
25
  if (Array.isArray(s)) {
@@ -35,11 +36,6 @@ function value(obj) {
35
36
  return (obj ? obj : {});
36
37
  }
37
38
  exports.value = value;
38
- exports.withDefaultProps = function (Component) {
39
- return function (props) {
40
- return React.createElement(Component, { props: props, history: props.history });
41
- };
42
- };
43
39
  exports.Loading = function (props) {
44
40
  var loadingStyle = {
45
41
  top: '30%',