react-hook-core 0.1.25 → 0.2.1

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/src/formutil.ts CHANGED
@@ -1,4 +1,4 @@
1
- export function readOnly(form?: HTMLFormElement|null): void {
1
+ export function setReadOnly(form?: HTMLFormElement|null, ...args: string[]): void {
2
2
  if (!form) {
3
3
  return;
4
4
  }
@@ -6,28 +6,39 @@ export function readOnly(form?: HTMLFormElement|null): void {
6
6
  for (let i = 0; i < len; i++) {
7
7
  const ctrl = form[i] as HTMLInputElement;
8
8
  const name = ctrl.getAttribute('name');
9
+ let skip = false;
9
10
  if (name != null && name.length > 0 && name !== 'btnBack') {
10
- let nodeName = ctrl.nodeName;
11
- const type = ctrl.getAttribute('type');
12
- if (nodeName === 'INPUT' && type !== null) {
13
- nodeName = type.toUpperCase();
11
+ if (arguments.length > 1) {
12
+ for (let j = 1; j < arguments.length; j++) {
13
+ if (arguments[j] === name) {
14
+ skip = true;
15
+ // continue; has bugs => why?
16
+ }
17
+ }
14
18
  }
15
- if (nodeName !== 'BUTTON'
16
- && nodeName !== 'RESET'
17
- && nodeName !== 'SUBMIT'
18
- && nodeName !== 'SELECT') {
19
- switch (type) {
20
- case 'checkbox':
21
- ctrl.disabled = true;
22
- break;
23
- case 'radio':
24
- ctrl.disabled = true;
25
- break;
26
- default:
27
- ctrl.readOnly = true;
19
+ if (skip === false) {
20
+ let nodeName = ctrl.nodeName;
21
+ const type = ctrl.getAttribute('type');
22
+ if (nodeName === 'INPUT' && type !== null) {
23
+ nodeName = type.toUpperCase();
24
+ }
25
+ if (nodeName !== 'BUTTON'
26
+ && nodeName !== 'RESET'
27
+ && nodeName !== 'SUBMIT'
28
+ && nodeName !== 'SELECT') {
29
+ switch (type) {
30
+ case 'checkbox':
31
+ ctrl.disabled = true;
32
+ break;
33
+ case 'radio':
34
+ ctrl.disabled = true;
35
+ break;
36
+ default:
37
+ ctrl.readOnly = true;
38
+ }
39
+ } else {
40
+ ctrl.disabled = true;
28
41
  }
29
- } else {
30
- ctrl.disabled = true;
31
42
  }
32
43
  }
33
44
  }
package/src/index.ts CHANGED
@@ -137,6 +137,13 @@ export const CurrencyInput = (props: InputProps) => {
137
137
  return React.createElement("input", { className: props.className, onBlur: onBlur, type: props.type, name: props.name, onChange: props.onChange ? props.onChange : onChange , disabled: props.disabled, "data-field": props['data-field'], min: props.min, max: props.max, value: state });
138
138
  };
139
139
  export type OnClick = React.MouseEvent<HTMLElement, MouseEvent>;
140
+ export function getParam(url: string, i?: number): string {
141
+ const ps = url.split('/');
142
+ if (!i || i < 0) {
143
+ i = 0;
144
+ }
145
+ return ps[ps.length - 1 - i];
146
+ }
140
147
  export function formatDate(date: Date | null | undefined, format: string): string {
141
148
  if (!date) {
142
149
  return '';
package/src/input.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {DiffStatusConfig, EditStatusConfig, LoadingService, Locale, ResourceService, UIService} from './core';
1
+ import {LoadingService, Locale, ResourceService, UIService} from './core';
2
2
 
3
3
  interface ResourceInput {
4
4
  resource: ResourceService;
@@ -75,6 +75,7 @@ export function getErrorFunc(p: ResourceService|ShowErrorInput, showErr?: (m: st
75
75
  }
76
76
  return (p as any).showError;
77
77
  }
78
+ /*
78
79
  export interface EditStatusParameter {
79
80
  status?: EditStatusConfig;
80
81
  }
@@ -93,3 +94,4 @@ export function getDiffStatusFunc(p: ResourceService|DiffStatusParameter, status
93
94
  }
94
95
  return (p as any).status;
95
96
  }
97
+ */
package/src/useEdit.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  import {useEffect, useState} from 'react';
2
2
  import {useNavigate, useParams} from 'react-router';
3
- import {Attributes, buildId, createEditStatus, EditStatusConfig, ErrorMessage, getModelName as getModelName2, hideLoading, initForm, LoadingService, Locale, message, messageByHttpStatus, ResourceService, showLoading, UIService} from './core';
4
- import {build, createModel as createModel2, EditParameter, GenericService, handleStatus, handleVersion, initPropertyNullInModel} from './edit';
5
- import {focusFirstError, readOnly as setReadOnly} from './formutil';
3
+ import {Attributes, buildId, ErrorMessage, getModelName as getModelName2, hideLoading, initForm, LoadingService, Locale, message, messageByHttpStatus, ResourceService, showLoading, UIService} from './core';
4
+ import {build, createModel as createModel2, EditParameter, GenericService, handleVersion, initPropertyNullInModel} from './edit';
5
+ import {focusFirstError, setReadOnly} from './formutil';
6
6
  import {DispatchWithCallback, useMergeState} from './merge';
7
7
  import {clone, makeDiff} from './reflect';
8
8
  import {localeOf} from './state';
9
9
  import {useUpdate} from './update';
10
10
 
11
11
  export interface BaseEditComponentParam<T, ID> {
12
- status?: EditStatusConfig;
12
+ // status?: EditStatusConfig;
13
13
  backOnSuccess?: boolean;
14
14
  name?: string;
15
15
  metadata?: Attributes;
@@ -18,9 +18,9 @@ export interface BaseEditComponentParam<T, ID> {
18
18
  setBack?: boolean;
19
19
  patchable?: boolean;
20
20
 
21
- addable?: boolean;
21
+ // addable?: boolean;
22
22
  readOnly?: boolean;
23
- deletable?: boolean;
23
+ // deletable?: boolean;
24
24
 
25
25
  insertSuccessMsg?: string;
26
26
  updateSuccessMsg?: string;
@@ -171,7 +171,7 @@ export const useCoreEdit = <T, ID, S, P>(
171
171
  addable = true
172
172
  } = p; */
173
173
  const navigate = useNavigate();
174
- const addable = (p && p.patchable !== false ? true : undefined);
174
+ // const addable = (p && p.patchable !== false ? true : undefined);
175
175
  const back = (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
176
176
  if (event) {
177
177
  event.preventDefault();
@@ -193,7 +193,7 @@ export const useCoreEdit = <T, ID, S, P>(
193
193
  const [flag, setFlag] = useMergeState({
194
194
  newMode: false,
195
195
  setBack: false,
196
- addable,
196
+ // addable,
197
197
  readOnly: p ? p.readOnly : undefined,
198
198
  originalModel: undefined
199
199
  });
@@ -258,7 +258,7 @@ export const useCoreEdit = <T, ID, S, P>(
258
258
  };
259
259
 
260
260
  const _onSave = (isBack?: boolean) => {
261
- if (flag.newMode === true && flag.addable === false) {
261
+ if (flag.newMode === true) {
262
262
  const m = message(p1.resource.value, 'error_permission_add', 'error_permission');
263
263
  p1.showError(m.message, m.title);
264
264
  return;
@@ -388,23 +388,21 @@ export const useCoreEdit = <T, ID, S, P>(
388
388
  const x: any = r;
389
389
  const successMsg = p1.resource.value('msg_save_success');
390
390
  const newMod = flag.newMode;
391
- const st = createEditStatus(p ? p.status : undefined);
391
+ // const st = createEditStatus(p ? p.status : undefined);
392
392
  if (Array.isArray(x)) {
393
393
  fail(x);
394
394
  } else if (!isNaN(x)) {
395
- if (x === st.success) {
395
+ if (x > 0) {
396
396
  succeed(successMsg, origin, version, backOnSave);
397
397
  } else {
398
- if (newMod && x === st.duplicate_key) {
398
+ if (newMod && x <= 0) {
399
399
  handleDuplicateKey();
400
- } else if (!newMod && x === st.not_found) {
400
+ } else if (!newMod && x === 0) {
401
401
  handleNotFound();
402
- } else if (!newMod && x === st.version_error) {
402
+ } else {
403
403
  const title = p1.resource.value('error');
404
404
  const err = p1.resource.value('error_version');
405
405
  p1.showError(err, title);
406
- } else {
407
- handleStatus(x as number, st, p1.resource.value, p1.showError);
408
406
  }
409
407
  }
410
408
  } else {
package/src/useSearch.ts CHANGED
@@ -61,10 +61,10 @@ export interface HookPropsSearchParameter<T, S extends Filter, ST extends Search
61
61
  initialize?: (ld: (s: S, auto?: boolean) => void, setState2: DispatchWithCallback<Partial<ST>>, com?: SearchComponentState<T, S>) => void;
62
62
  }
63
63
  export interface SearchComponentParam<T, M extends Filter> {
64
- addable?: boolean;
65
- editable?: boolean;
66
- approvable?: boolean;
67
- deletable?: boolean;
64
+ // addable?: boolean;
65
+ // editable?: boolean;
66
+ // approvable?: boolean;
67
+ // deletable?: boolean;
68
68
 
69
69
  keys?: string[];
70
70
  sequenceNo?: string;
@@ -134,11 +134,11 @@ export interface SearchComponentState<T, S> extends Pagination, Sortable {
134
134
  hideFilter?: boolean;
135
135
 
136
136
  ignoreUrlParam?: boolean;
137
- viewable?: boolean;
138
- addable?: boolean;
139
- editable?: boolean;
140
- approvable?: boolean;
141
- deletable?: boolean;
137
+ // viewable?: boolean;
138
+ // addable?: boolean;
139
+ // editable?: boolean;
140
+ // approvable?: boolean;
141
+ // deletable?: boolean;
142
142
  }
143
143
 
144
144
  export function mergeParam<T, S extends Filter>(p?: SearchComponentParam<T, S>): SearchComponentParam<T, S> {
@@ -158,6 +158,7 @@ export function mergeParam<T, S extends Filter>(p?: SearchComponentParam<T, S>):
158
158
  if (p.hideFilter === undefined) {
159
159
  p.hideFilter = true;
160
160
  }
161
+ /*
161
162
  if (p.addable === undefined) {
162
163
  p.addable = true;
163
164
  }
@@ -170,6 +171,7 @@ export function mergeParam<T, S extends Filter>(p?: SearchComponentParam<T, S>):
170
171
  if (p.deletable === undefined) {
171
172
  p.deletable = true;
172
173
  }
174
+ */
173
175
  return p;
174
176
  } else {
175
177
  return {
@@ -178,10 +180,10 @@ export function mergeParam<T, S extends Filter>(p?: SearchComponentParam<T, S>):
178
180
  pageSizes,
179
181
  pageMaxSize: 7,
180
182
  hideFilter: true,
181
- addable: true,
182
- editable: true,
183
- approvable: true,
184
- deletable: true
183
+ // addable: true,
184
+ // editable: true,
185
+ // approvable: true,
186
+ // deletable: true
185
187
  };
186
188
  }
187
189
  }
package/src/useView.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import {useEffect, useState} from 'react';
2
2
  import {useNavigate, useParams} from 'react-router';
3
3
  import {buildId, getModelName as getModelName2, hideLoading, initForm, LoadingService, Locale, message, messageByHttpStatus, ResourceService, showLoading, ViewParameter, ViewService} from './core';
4
- import {readOnly} from './formutil';
4
+ import {setReadOnly} from './formutil';
5
5
  import {DispatchWithCallback, useMergeState} from './merge';
6
6
 
7
7
  export interface BaseViewComponentParam<T, ID> {
@@ -97,7 +97,7 @@ export const useCoreView = <T, ID, S>(
97
97
  const _handleNotFound = (form?: any): void => {
98
98
  const msg = message(p1.resource.value, 'error_not_found', 'error');
99
99
  if (form) {
100
- readOnly(form);
100
+ setReadOnly(form);
101
101
  }
102
102
  p1.showError(msg.message, msg.title);
103
103
  };
@@ -132,7 +132,7 @@ export const useCoreView = <T, ID, S>(
132
132
  if (data && data.status) {
133
133
  msg = messageByHttpStatus(data.status, r.value);
134
134
  }
135
- readOnly(refForm.current);
135
+ setReadOnly(refForm.current);
136
136
  p1.showError(msg, title);
137
137
  }
138
138
  setRunning(false);