react-hook-core 0.1.3 → 0.1.6

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
@@ -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,11 +308,12 @@ 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
  };
329
315
  _this.resource = resourceService.resource();
316
+ _this.hideFilter = true;
330
317
  _this.getModelName = _this.getModelName.bind(_this);
331
318
  _this.showMessage = _this.showMessage.bind(_this);
332
319
  _this.toggleFilter = _this.toggleFilter.bind(_this);
@@ -357,10 +344,12 @@ var BaseSearchComponent = (function (_super) {
357
344
  return 'filter';
358
345
  };
359
346
  BaseSearchComponent.prototype.toggleFilter = function (event) {
360
- this.hideFilter = !this.hideFilter;
347
+ var x = !this.hideFilter;
348
+ core_1.handleToggle(event.target, !x);
349
+ this.hideFilter = x;
361
350
  };
362
351
  BaseSearchComponent.prototype.load = function (s, autoSearch) {
363
- var obj2 = search_core_1.initFilter(s, this);
352
+ var obj2 = search_1.initFilter(s, this);
364
353
  this.setFilter(obj2);
365
354
  var com = this;
366
355
  if (autoSearch) {
@@ -401,11 +390,11 @@ var BaseSearchComponent = (function (_super) {
401
390
  var l = this.getList();
402
391
  var f = this.getSearchForm();
403
392
  var dc = (this.ui ? this.ui.decodeFromForm : undefined);
404
- 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);
405
394
  return obj3;
406
395
  };
407
396
  BaseSearchComponent.prototype.getFields = function () {
408
- var fs = search_core_1.getFieldsFromForm(this.fields, this.initFields, this.form);
397
+ var fs = search_1.getFieldsFromForm(this.fields, this.initFields, this.form);
409
398
  this.initFields = true;
410
399
  return fs;
411
400
  };
@@ -439,7 +428,7 @@ var BaseSearchComponent = (function (_super) {
439
428
  this.triggerSearch = true;
440
429
  return;
441
430
  }
442
- search_core_1.reset(this);
431
+ search_1.reset(this);
443
432
  this.tmpPageIndex = 1;
444
433
  this.doSearch();
445
434
  };
@@ -458,7 +447,7 @@ var BaseSearchComponent = (function (_super) {
458
447
  com.running = true;
459
448
  core_1.showLoading(_this.loading);
460
449
  if (!_this.ignoreUrlParam) {
461
- search_core_1.addParametersIntoUrl(s, isFirstLoad);
450
+ search_1.addParametersIntoUrl(s, isFirstLoad);
462
451
  }
463
452
  com.call(s);
464
453
  });
@@ -468,14 +457,14 @@ var BaseSearchComponent = (function (_super) {
468
457
  BaseSearchComponent.prototype.validateSearch = function (se, callback) {
469
458
  var u = this.ui;
470
459
  var vl = (u ? u.validateForm : undefined);
471
- 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);
472
461
  };
473
462
  BaseSearchComponent.prototype.showResults = function (s, sr) {
474
463
  var com = this;
475
464
  var results = sr.list;
476
465
  if (results && results.length > 0) {
477
466
  var lc = state_1.localeOf(undefined, this.getLocale);
478
- 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);
479
468
  }
480
469
  var am = com.appendMode;
481
470
  com.pageIndex = (s.page && s.page >= 1 ? s.page : 1);
@@ -488,7 +477,7 @@ var BaseSearchComponent = (function (_super) {
488
477
  limit = s.firstLimit;
489
478
  }
490
479
  com.nextPageToken = sr.nextPageToken;
491
- search_core_1.handleAppend(com, sr.list, limit, sr.nextPageToken);
480
+ search_1.handleAppend(com, sr.list, limit, sr.nextPageToken);
492
481
  if (com.append && (s.page && s.page > 1)) {
493
482
  com.appendList(results);
494
483
  }
@@ -497,11 +486,11 @@ var BaseSearchComponent = (function (_super) {
497
486
  }
498
487
  }
499
488
  else {
500
- search_core_1.showPaging(com, sr.list, s.limit, sr.total);
489
+ search_1.showPaging(com, sr.list, s.limit, sr.total);
501
490
  com.setList(results);
502
491
  com.tmpPageIndex = s.page;
503
492
  if (s.limit) {
504
- 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));
505
494
  }
506
495
  }
507
496
  com.running = undefined;
@@ -514,7 +503,7 @@ var BaseSearchComponent = (function (_super) {
514
503
  BaseSearchComponent.prototype.appendList = function (results) {
515
504
  var _a;
516
505
  var list = this.state.list;
517
- var arr = search_core_1.append(list, results);
506
+ var arr = search_1.append(list, results);
518
507
  var listForm = this.getSearchForm();
519
508
  var props = this.props;
520
509
  var setGlobalState = props.props.setGlobalState;
@@ -543,7 +532,7 @@ var BaseSearchComponent = (function (_super) {
543
532
  };
544
533
  BaseSearchComponent.prototype.sort = function (event) {
545
534
  event.preventDefault();
546
- search_core_1.handleSortEvent(event, this);
535
+ search_1.handleSortEvent(event, this);
547
536
  if (!this.appendMode) {
548
537
  this.doSearch();
549
538
  }
@@ -554,12 +543,12 @@ var BaseSearchComponent = (function (_super) {
554
543
  BaseSearchComponent.prototype.showMore = function (event) {
555
544
  event.preventDefault();
556
545
  this.tmpPageIndex = this.pageIndex;
557
- search_core_1.more(this);
546
+ search_1.more(this);
558
547
  this.doSearch();
559
548
  };
560
549
  BaseSearchComponent.prototype.pageChanged = function (data) {
561
550
  var page = data.page, size = data.size;
562
- search_core_1.changePage(this, page, size);
551
+ search_1.changePage(this, page, size);
563
552
  this.doSearch();
564
553
  };
565
554
  return BaseSearchComponent;
@@ -569,11 +558,6 @@ var SearchComponent = (function (_super) {
569
558
  __extends(SearchComponent, _super);
570
559
  function SearchComponent(props, sv, param, showMessage, showError, getLocale, uis, loading, listFormId) {
571
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;
572
- _this.add = function (event) {
573
- event.preventDefault();
574
- var url = _this.url + '/add';
575
- _this.props.history.push(url);
576
- };
577
561
  _this.autoSearch = input_1.getAutoSearch(param);
578
562
  if (sv) {
579
563
  if (typeof sv === 'function') {
@@ -587,7 +571,6 @@ var SearchComponent = (function (_super) {
587
571
  }
588
572
  }
589
573
  }
590
- _this.add = _this.add.bind(_this);
591
574
  _this.call = _this.call.bind(_this);
592
575
  _this.showError = input_1.getErrorFunc(param, showError);
593
576
  _this.componentDidMount = _this.componentDidMount.bind(_this);
@@ -603,7 +586,7 @@ var SearchComponent = (function (_super) {
603
586
  this.load(s, this.autoSearch);
604
587
  };
605
588
  SearchComponent.prototype.mergeFilter = function (obj, b, arrs) {
606
- return search_core_1.mergeFilter(obj, b, this.pageSizes, arrs);
589
+ return search_1.mergeFilter(obj, b, this.pageSizes, arrs);
607
590
  };
608
591
  SearchComponent.prototype.createFilter = function () {
609
592
  var s = {};
@@ -611,7 +594,7 @@ var SearchComponent = (function (_super) {
611
594
  };
612
595
  SearchComponent.prototype.call = function (se) {
613
596
  this.running = true;
614
- var s = reflectx_1.clone(se);
597
+ var s = reflect_1.clone(se);
615
598
  var page = this.pageIndex;
616
599
  if (!page || page < 1) {
617
600
  page = 1;
@@ -723,7 +706,6 @@ var BaseEditComponent = (function (_super) {
723
706
  if (event) {
724
707
  event.preventDefault();
725
708
  }
726
- this.props.history.goBack();
727
709
  };
728
710
  BaseEditComponent.prototype.resetState = function (newMod, model, originalModel) {
729
711
  this.newMode = newMod;
@@ -797,7 +779,7 @@ var BaseEditComponent = (function (_super) {
797
779
  });
798
780
  }
799
781
  else {
800
- 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);
801
783
  var keys = Object.keys(diffObj_1);
802
784
  if (keys.length === 0) {
803
785
  this.showMessage(r.value('msg_no_change'));
@@ -831,7 +813,7 @@ var BaseEditComponent = (function (_super) {
831
813
  var model = result.value;
832
814
  this.newMode = false;
833
815
  if (model && this.setBack) {
834
- this.resetState(false, model, reflectx_1.clone(model));
816
+ this.resetState(false, model, reflect_1.clone(model));
835
817
  }
836
818
  else {
837
819
  edit_1.handleVersion(this.getModel(), this.version);
@@ -948,18 +930,9 @@ var EditComponent = (function (_super) {
948
930
  }
949
931
  _this.load = _this.load.bind(_this);
950
932
  _this.doSave = _this.doSave.bind(_this);
951
- _this.componentDidMount = _this.componentDidMount.bind(_this);
952
933
  _this.ref = React.createRef();
953
934
  return _this;
954
935
  }
955
- EditComponent.prototype.componentDidMount = function () {
956
- var k = (this.ui ? this.ui.registerEvents : undefined);
957
- this.form = core_2.initForm(this.ref.current, k);
958
- var id = core_2.buildId(this.props, this.keys);
959
- if (id) {
960
- this.load(id);
961
- }
962
- };
963
936
  EditComponent.prototype.load = function (_id, callback) {
964
937
  var _this = this;
965
938
  var id = _id;
@@ -973,7 +946,7 @@ var EditComponent = (function (_super) {
973
946
  }
974
947
  else {
975
948
  com_3.newMode = false;
976
- com_3.orginalModel = reflectx_1.clone(obj);
949
+ com_3.orginalModel = reflect_1.clone(obj);
977
950
  if (!callback) {
978
951
  com_3.showModel(obj);
979
952
  }
@@ -1055,7 +1028,6 @@ var BaseDiffApprComponent = (function (_super) {
1055
1028
  _this.resource = resourceService.resource();
1056
1029
  _this.showMessage = _this.showMessage.bind(_this);
1057
1030
  _this.showError = _this.showError.bind(_this);
1058
- _this.back = _this.back.bind(_this);
1059
1031
  _this.initModel = _this.initModel.bind(_this);
1060
1032
  _this.postApprove = _this.postApprove.bind(_this);
1061
1033
  _this.postReject = _this.postReject.bind(_this);
@@ -1067,12 +1039,6 @@ var BaseDiffApprComponent = (function (_super) {
1067
1039
  };
1068
1040
  return _this;
1069
1041
  }
1070
- BaseDiffApprComponent.prototype.back = function (event) {
1071
- if (event) {
1072
- event.preventDefault();
1073
- }
1074
- this.props.history.goBack();
1075
- };
1076
1042
  BaseDiffApprComponent.prototype.initModel = function () {
1077
1043
  var x = {};
1078
1044
  return x;
@@ -1117,7 +1083,7 @@ var BaseDiffApprComponent = (function (_super) {
1117
1083
  var p = this.props;
1118
1084
  var diffModel = p['diffModel'];
1119
1085
  if (diffModel) {
1120
- var differentKeys_1 = reflectx_1.diff(diffModel.origin, diffModel.value);
1086
+ var differentKeys_1 = reflect_1.diff(diffModel.origin, diffModel.value);
1121
1087
  var dataFields = diff_1.getDataFields(this.form);
1122
1088
  dataFields.forEach(function (e) {
1123
1089
  var x = e.getAttribute('data-field');
@@ -1136,7 +1102,7 @@ var BaseDiffApprComponent = (function (_super) {
1136
1102
  }
1137
1103
  else {
1138
1104
  var _a = this.state, origin_1 = _a.origin, value = _a.value;
1139
- var differentKeys_2 = reflectx_1.diff(origin_1, value);
1105
+ var differentKeys_2 = reflect_1.diff(origin_1, value);
1140
1106
  var dataFields = diff_1.getDataFields(this.form);
1141
1107
  dataFields.forEach(function (e) {
1142
1108
  var x = e.getAttribute('data-field');
@@ -1178,13 +1144,6 @@ var DiffApprComponent = (function (_super) {
1178
1144
  };
1179
1145
  return _this;
1180
1146
  }
1181
- DiffApprComponent.prototype.componentDidMount = function () {
1182
- this.form = this.ref.current;
1183
- var id = core_2.buildId(this.props, this.keys);
1184
- if (id) {
1185
- this.load(id);
1186
- }
1187
- };
1188
1147
  DiffApprComponent.prototype.formatFields = function (value) {
1189
1148
  return value;
1190
1149
  };
package/lib/core.js CHANGED
@@ -33,7 +33,7 @@ exports.createDiffStatus = createDiffStatus;
33
33
  var resource = (function () {
34
34
  function resource() {
35
35
  }
36
- resource.phone = / |\-|\.|\(|\)/g;
36
+ resource.phone = / |-|\.|\(|\)/g;
37
37
  resource._cache = {};
38
38
  resource.cache = true;
39
39
  return resource;
@@ -107,26 +107,21 @@ function buildKeys(attributes) {
107
107
  return ps;
108
108
  }
109
109
  exports.buildKeys = buildKeys;
110
- function buildId(props, keys) {
111
- if (!props) {
112
- return null;
113
- }
114
- var sp = (props.match ? props : props['props']);
110
+ function buildId(p, keys) {
115
111
  if (!keys || keys.length === 0 || keys.length === 1) {
116
112
  if (keys && keys.length === 1) {
117
- var x = sp.match.params[keys[0]];
118
- if (x && x !== '') {
119
- return x;
113
+ if (p[keys[0]]) {
114
+ return p[keys[0]];
120
115
  }
121
116
  }
122
- return sp.match.params['id'];
117
+ return p['id'];
123
118
  }
124
119
  var id = {};
125
120
  for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
126
121
  var key = keys_1[_i];
127
- var v = sp.match.params[key];
122
+ var v = p[key];
128
123
  if (!v) {
129
- v = sp[key];
124
+ v = p[key];
130
125
  if (!v) {
131
126
  return null;
132
127
  }
@@ -269,3 +264,16 @@ function getDecodeFromForm(u, d) {
269
264
  return (u && u.ui ? u.ui.decodeFromForm : undefined);
270
265
  }
271
266
  exports.getDecodeFromForm = getDecodeFromForm;
267
+ function handleToggle(target, on) {
268
+ if (target) {
269
+ if (on) {
270
+ if (!target.classList.contains('on')) {
271
+ target.classList.add('on');
272
+ }
273
+ }
274
+ else {
275
+ target.classList.remove('on');
276
+ }
277
+ }
278
+ }
279
+ exports.handleToggle = handleToggle;
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,20 +10,32 @@ __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"));
22
- exports.withDefaultProps = function (Component) {
23
- return function (props) {
24
- return React.createElement(Component, { props: props, history: props.history });
25
- };
26
- };
18
+ __export(require("./useEdit"));
19
+ __export(require("./components"));
20
+ __export(require("./search"));
21
+ __export(require("./reflect"));
22
+ var core_1 = require("./core");
23
+ function checked(s, v) {
24
+ if (s) {
25
+ if (Array.isArray(s)) {
26
+ return s.includes(v);
27
+ }
28
+ else {
29
+ return s === v;
30
+ }
31
+ }
32
+ return false;
33
+ }
34
+ exports.checked = checked;
35
+ function value(obj) {
36
+ return (obj ? obj : {});
37
+ }
38
+ exports.value = value;
27
39
  exports.Loading = function (props) {
28
40
  var loadingStyle = {
29
41
  top: '30%',
@@ -39,3 +51,10 @@ exports.Loading = function (props) {
39
51
  return (React.createElement('div', { className: 'loader-wrapper' }, React.createElement('div', { className: 'loader-sign', style: loadingStyle }, React.createElement('div', { className: 'loader' }))));
40
52
  }
41
53
  };
54
+ function PageSizeSelect(p) {
55
+ var g = p.sizes;
56
+ var s = (!g || g.length === 0 ? core_1.pageSizes : g);
57
+ var opts = s.map(function (pgSize) { return React.createElement('option', { key: pgSize, value: pgSize }, pgSize); });
58
+ return React.createElement('select', { id: p.id, name: p.name, defaultValue: p.size, onChange: p.onChange }, opts);
59
+ }
60
+ exports.PageSizeSelect = PageSizeSelect;