namirasoft-site-react 1.4.339 → 1.4.340

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.
Files changed (290) hide show
  1. package/.dockerignore +86 -86
  2. package/.env.template +10 -10
  3. package/Dockerfile +18 -18
  4. package/config-overrides.js +72 -72
  5. package/dist/App.css +34 -0
  6. package/dist/components/NSBanner.module.css +47 -47
  7. package/dist/components/NSBarAction.module.css +84 -84
  8. package/dist/components/NSBarAlert.module.css +79 -79
  9. package/dist/components/NSBarNotification.module.css +34 -34
  10. package/dist/components/NSBarTitle.module.css +9 -9
  11. package/dist/components/NSBox.module.css +50 -50
  12. package/dist/components/NSBoxBaseCombo.module.css +6 -6
  13. package/dist/components/NSBoxBoolean.module.css +67 -67
  14. package/dist/components/NSBoxDate.module.css +4 -4
  15. package/dist/components/NSBoxDateTime.module.css +4 -4
  16. package/dist/components/NSBoxDuration.module.css +4 -4
  17. package/dist/components/NSBoxFile.module.css +10 -10
  18. package/dist/components/NSBoxPhone.module.css +35 -35
  19. package/dist/components/NSBoxRadio.module.css +33 -33
  20. package/dist/components/NSBoxSchemaBase.module.css +17 -17
  21. package/dist/components/NSBoxSchemaVariable.module.css +16 -16
  22. package/dist/components/NSBoxTextArea.module.css +12 -12
  23. package/dist/components/NSBoxTime.module.css +4 -4
  24. package/dist/components/NSButton.module.css +57 -57
  25. package/dist/components/NSButtonBlue.module.css +4 -4
  26. package/dist/components/NSButtonGreen.module.css +4 -4
  27. package/dist/components/NSButtonRed.module.css +4 -4
  28. package/dist/components/NSCard.module.css +114 -114
  29. package/dist/components/NSCardScreenshot.module.css +41 -41
  30. package/dist/components/NSChartColumn.module.css +7 -7
  31. package/dist/components/NSChartTable.module.css +21 -21
  32. package/dist/components/NSColumn.module.css +16 -16
  33. package/dist/components/NSCopyBox.module.css +39 -39
  34. package/dist/components/NSDialog.module.css +112 -112
  35. package/dist/components/NSDialogPageSelection.module.css +103 -103
  36. package/dist/components/NSDownTimer.module.css +55 -55
  37. package/dist/components/NSDownload.module.css +46 -46
  38. package/dist/components/NSElectronicCard.module.css +60 -60
  39. package/dist/components/NSEntityCardBackground.module.css +27 -27
  40. package/dist/components/NSFilterBox.module.css +56 -56
  41. package/dist/components/NSFilterItem.module.css +24 -24
  42. package/dist/components/NSFooter.module.css +134 -134
  43. package/dist/components/NSHeader.module.css +291 -291
  44. package/dist/components/NSHeaderScreenshot.module.css +35 -35
  45. package/dist/components/NSID.js +2 -0
  46. package/dist/components/NSID.js.map +1 -1
  47. package/dist/components/NSLabel.module.css +25 -25
  48. package/dist/components/NSLabelErrorNotifier.module.css +2 -2
  49. package/dist/components/NSLayout.module.css +14 -14
  50. package/dist/components/NSLine.module.css +15 -15
  51. package/dist/components/NSLink.module.css +36 -36
  52. package/dist/components/NSListGrouped.module.css +69 -69
  53. package/dist/components/NSLoading.module.css +30 -30
  54. package/dist/components/NSMenuAction.js +2 -2
  55. package/dist/components/NSMenuAction.module.css +88 -88
  56. package/dist/components/NSMenuButton.module.css +44 -44
  57. package/dist/components/NSNoData.module.css +9 -9
  58. package/dist/components/NSPagination.module.css +85 -85
  59. package/dist/components/NSPanel.module.css +19 -19
  60. package/dist/components/NSPanelAccordion.module.css +4 -4
  61. package/dist/components/NSRange.module.css +66 -66
  62. package/dist/components/NSRow.module.css +17 -17
  63. package/dist/components/NSSection.module.css +4 -4
  64. package/dist/components/NSSectionCards.module.css +38 -38
  65. package/dist/components/NSSectionTiles.module.css +10 -10
  66. package/dist/components/NSTabPage.module.css +59 -59
  67. package/dist/components/NSTable.module.css +263 -263
  68. package/dist/components/NSTile.module.css +76 -76
  69. package/dist/components/NSTimelineMonthly.module.css +71 -71
  70. package/dist/components/NSTitle.module.css +15 -15
  71. package/dist/index.css +6 -0
  72. package/dist/pages/NSNotFoundPage.module.css +18 -18
  73. package/dist/pages/NSUpdating.module.css +35 -35
  74. package/package.json +80 -80
  75. package/public/index.html +38 -38
  76. package/src/App.css +33 -33
  77. package/src/App.tsx +131 -131
  78. package/src/Color.tsx +10 -10
  79. package/src/CopyToClipboard.ts +6 -6
  80. package/src/NSBoxBuilder.tsx +914 -914
  81. package/src/Validator.ts +163 -163
  82. package/src/components/INSBox.tsx +6 -6
  83. package/src/components/NSBanner.module.css +47 -47
  84. package/src/components/NSBanner.tsx +80 -80
  85. package/src/components/NSBarAction.module.css +84 -84
  86. package/src/components/NSBarAction.tsx +90 -90
  87. package/src/components/NSBarAlert.module.css +79 -79
  88. package/src/components/NSBarAlert.tsx +35 -35
  89. package/src/components/NSBarNotification.module.css +34 -34
  90. package/src/components/NSBarNotification.tsx +85 -85
  91. package/src/components/NSBarTitle.module.css +9 -9
  92. package/src/components/NSBarTitle.tsx +23 -23
  93. package/src/components/NSBox.module.css +50 -50
  94. package/src/components/NSBox.tsx +19 -19
  95. package/src/components/NSBoxBaseCombo.module.css +6 -6
  96. package/src/components/NSBoxBaseCombo.tsx +314 -314
  97. package/src/components/NSBoxBaseLayout.tsx +88 -88
  98. package/src/components/NSBoxBaseLayoutRecursive.tsx +54 -54
  99. package/src/components/NSBoxBoolean.module.css +67 -67
  100. package/src/components/NSBoxBoolean.tsx +119 -119
  101. package/src/components/NSBoxBooleans.tsx +161 -161
  102. package/src/components/NSBoxColor.tsx +95 -95
  103. package/src/components/NSBoxCombo.tsx +91 -91
  104. package/src/components/NSBoxDate.module.css +4 -4
  105. package/src/components/NSBoxDate.tsx +90 -90
  106. package/src/components/NSBoxDateTime.module.css +4 -4
  107. package/src/components/NSBoxDateTime.tsx +105 -105
  108. package/src/components/NSBoxDouble.tsx +94 -94
  109. package/src/components/NSBoxDuration.module.css +4 -4
  110. package/src/components/NSBoxDuration.tsx +95 -95
  111. package/src/components/NSBoxDynamic.tsx +67 -67
  112. package/src/components/NSBoxDynamics.tsx +68 -68
  113. package/src/components/NSBoxEmail.tsx +98 -98
  114. package/src/components/NSBoxEntity.tsx +101 -101
  115. package/src/components/NSBoxEnum.tsx +108 -108
  116. package/src/components/NSBoxFile.module.css +10 -10
  117. package/src/components/NSBoxFile.tsx +101 -101
  118. package/src/components/NSBoxFilePath.tsx +95 -95
  119. package/src/components/NSBoxFont.tsx +95 -95
  120. package/src/components/NSBoxIPV4.tsx +95 -95
  121. package/src/components/NSBoxIPV4Range.tsx +95 -95
  122. package/src/components/NSBoxIPV6.tsx +92 -92
  123. package/src/components/NSBoxIPV6Range.tsx +95 -95
  124. package/src/components/NSBoxInteger.tsx +91 -91
  125. package/src/components/NSBoxMoney.tsx +95 -95
  126. package/src/components/NSBoxPassword.tsx +106 -106
  127. package/src/components/NSBoxPhone.module.css +35 -35
  128. package/src/components/NSBoxPhone.tsx +107 -107
  129. package/src/components/NSBoxRadio.module.css +33 -33
  130. package/src/components/NSBoxRadio.tsx +91 -91
  131. package/src/components/NSBoxSchemaBase.module.css +17 -17
  132. package/src/components/NSBoxSchemaBase.tsx +540 -540
  133. package/src/components/NSBoxSchemaVariable.module.css +16 -16
  134. package/src/components/NSBoxSchemaVariable.tsx +250 -250
  135. package/src/components/NSBoxSearch.tsx +97 -97
  136. package/src/components/NSBoxString.tsx +91 -91
  137. package/src/components/NSBoxTextArea.module.css +12 -12
  138. package/src/components/NSBoxTextArea.tsx +98 -98
  139. package/src/components/NSBoxTime.module.css +4 -4
  140. package/src/components/NSBoxTime.tsx +93 -93
  141. package/src/components/NSBoxTimeZone.tsx +95 -95
  142. package/src/components/NSBoxURL.tsx +104 -104
  143. package/src/components/NSBoxVersion.tsx +95 -95
  144. package/src/components/NSButton.module.css +57 -57
  145. package/src/components/NSButton.tsx +25 -25
  146. package/src/components/NSButtonBlue.module.css +4 -4
  147. package/src/components/NSButtonBlue.tsx +19 -19
  148. package/src/components/NSButtonGreen.module.css +4 -4
  149. package/src/components/NSButtonGreen.tsx +19 -19
  150. package/src/components/NSButtonRed.module.css +4 -4
  151. package/src/components/NSButtonRed.tsx +19 -19
  152. package/src/components/NSCard.module.css +114 -114
  153. package/src/components/NSCard.tsx +63 -63
  154. package/src/components/NSCardScreenshot.module.css +41 -41
  155. package/src/components/NSCardScreenshot.tsx +31 -31
  156. package/src/components/NSChartColumn.module.css +7 -7
  157. package/src/components/NSChartColumn.tsx +106 -106
  158. package/src/components/NSChartDoughnut.tsx +112 -112
  159. package/src/components/NSChartPie.tsx +105 -105
  160. package/src/components/NSChartRange.tsx +14 -14
  161. package/src/components/NSChartTable.module.css +21 -21
  162. package/src/components/NSChartTable.tsx +94 -94
  163. package/src/components/NSColumn.module.css +16 -16
  164. package/src/components/NSColumn.tsx +24 -24
  165. package/src/components/NSCopy.tsx +58 -58
  166. package/src/components/NSCopyBox.module.css +39 -39
  167. package/src/components/NSCopyBox.tsx +53 -53
  168. package/src/components/NSDialog.module.css +112 -112
  169. package/src/components/NSDialog.tsx +61 -61
  170. package/src/components/NSDialogDelete.tsx +26 -26
  171. package/src/components/NSDialogInfo.tsx +32 -32
  172. package/src/components/NSDialogPageSelection.module.css +103 -103
  173. package/src/components/NSDialogPageSelection.tsx +227 -227
  174. package/src/components/NSDownTimer.module.css +55 -55
  175. package/src/components/NSDownTimer.tsx +91 -91
  176. package/src/components/NSDownload.module.css +46 -46
  177. package/src/components/NSDownload.tsx +66 -66
  178. package/src/components/NSElectronicCard.module.css +60 -60
  179. package/src/components/NSElectronicCard.tsx +46 -46
  180. package/src/components/NSEntityCardBackground.module.css +27 -27
  181. package/src/components/NSEntityCardBackground.tsx +36 -36
  182. package/src/components/NSFilterBox.module.css +56 -56
  183. package/src/components/NSFilterBox.tsx +506 -506
  184. package/src/components/NSFilterItem.module.css +24 -24
  185. package/src/components/NSFilterItem.tsx +27 -27
  186. package/src/components/NSFooter.module.css +134 -134
  187. package/src/components/NSFooter.tsx +321 -321
  188. package/src/components/NSHeader.module.css +291 -291
  189. package/src/components/NSHeader.tsx +261 -261
  190. package/src/components/NSHeaderScreenshot.module.css +35 -35
  191. package/src/components/NSHeaderScreenshot.tsx +39 -39
  192. package/src/components/NSID.tsx +133 -131
  193. package/src/components/NSLabel.module.css +25 -25
  194. package/src/components/NSLabel.tsx +46 -46
  195. package/src/components/NSLabelErrorNotifier.module.css +2 -2
  196. package/src/components/NSLabelErrorNotifier.tsx +35 -35
  197. package/src/components/NSLayout.module.css +14 -14
  198. package/src/components/NSLayout.tsx +126 -126
  199. package/src/components/NSLine.module.css +15 -15
  200. package/src/components/NSLine.tsx +13 -13
  201. package/src/components/NSLink.module.css +36 -36
  202. package/src/components/NSLink.tsx +25 -25
  203. package/src/components/NSLinkBlue.tsx +21 -21
  204. package/src/components/NSLinkGreen.tsx +12 -12
  205. package/src/components/NSLinkRed.tsx +12 -12
  206. package/src/components/NSListGrouped.module.css +69 -69
  207. package/src/components/NSListGrouped.tsx +106 -106
  208. package/src/components/NSListProduct.tsx +44 -44
  209. package/src/components/NSLoading.module.css +30 -30
  210. package/src/components/NSLoading.tsx +21 -21
  211. package/src/components/NSMenuAction.module.css +88 -88
  212. package/src/components/NSMenuAction.tsx +90 -90
  213. package/src/components/NSMenuButton.module.css +44 -44
  214. package/src/components/NSMenuButton.tsx +206 -206
  215. package/src/components/NSNoData.module.css +9 -9
  216. package/src/components/NSNoData.tsx +24 -24
  217. package/src/components/NSPagination.module.css +85 -85
  218. package/src/components/NSPagination.tsx +182 -182
  219. package/src/components/NSPanel.module.css +19 -19
  220. package/src/components/NSPanel.tsx +24 -24
  221. package/src/components/NSPanelAccordion.module.css +4 -4
  222. package/src/components/NSPanelAccordion.tsx +51 -51
  223. package/src/components/NSRange.module.css +66 -66
  224. package/src/components/NSRange.tsx +83 -83
  225. package/src/components/NSRepeater.tsx +256 -256
  226. package/src/components/NSRepeaterNSBoxSchemaVariable.tsx +90 -90
  227. package/src/components/NSRepeaterNSTag.tsx +81 -81
  228. package/src/components/NSRow.module.css +17 -17
  229. package/src/components/NSRow.tsx +24 -24
  230. package/src/components/NSSection.module.css +4 -4
  231. package/src/components/NSSection.tsx +26 -26
  232. package/src/components/NSSectionCards.module.css +38 -38
  233. package/src/components/NSSectionCards.tsx +51 -51
  234. package/src/components/NSSectionTiles.module.css +10 -10
  235. package/src/components/NSSectionTiles.tsx +25 -25
  236. package/src/components/NSSectionTitle.tsx +21 -21
  237. package/src/components/NSSpace.tsx +28 -28
  238. package/src/components/NSTabPage.module.css +59 -59
  239. package/src/components/NSTabPage.tsx +91 -91
  240. package/src/components/NSTable.module.css +263 -263
  241. package/src/components/NSTable.tsx +482 -482
  242. package/src/components/NSTag.tsx +74 -74
  243. package/src/components/NSTile.module.css +76 -76
  244. package/src/components/NSTile.tsx +27 -27
  245. package/src/components/NSTimelineMonthly.module.css +71 -71
  246. package/src/components/NSTimelineMonthly.tsx +44 -44
  247. package/src/components/NSTitle.module.css +15 -15
  248. package/src/components/NSTitle.tsx +19 -19
  249. package/src/formatter/BackColorFormatter.tsx +23 -23
  250. package/src/formatter/BaseColumnFormatter.ts +16 -16
  251. package/src/formatter/BaseURLImageFormatter.tsx +33 -33
  252. package/src/formatter/BooleanFormatter.ts +22 -22
  253. package/src/formatter/DateFormatter.ts +21 -21
  254. package/src/formatter/DateTimeFormatter.ts +21 -21
  255. package/src/formatter/DurationFormatter.ts +13 -13
  256. package/src/formatter/EmailFormatter.tsx +21 -21
  257. package/src/formatter/EnumFormatter.ts +13 -13
  258. package/src/formatter/FloatFormatter.ts +23 -23
  259. package/src/formatter/ForeColorFormatter.tsx +24 -24
  260. package/src/formatter/IDFormatter.tsx +30 -30
  261. package/src/formatter/IPFormatter.ts +13 -13
  262. package/src/formatter/IntegerFormatter.ts +23 -23
  263. package/src/formatter/JsonFormatter.ts +21 -21
  264. package/src/formatter/MoneyFormatter.ts +30 -30
  265. package/src/formatter/PhoneFormatter.tsx +21 -21
  266. package/src/formatter/StringFormatter.tsx +43 -43
  267. package/src/formatter/TimeFormatter.ts +21 -21
  268. package/src/formatter/URLFormatter.tsx +21 -21
  269. package/src/formatter/UnknowFormatter.ts +18 -18
  270. package/src/index.tsx +7 -7
  271. package/src/main.ts +222 -222
  272. package/src/pages/NSNotFoundPage.module.css +18 -18
  273. package/src/pages/NSNotFoundPage.tsx +11 -11
  274. package/src/pages/NSUpdating.module.css +35 -35
  275. package/src/pages/NSUpdating.tsx +32 -32
  276. package/src/props/IBackgroundPropps.ts +5 -5
  277. package/src/props/IBaseComponentProps.ts +8 -8
  278. package/src/props/IHeaderIconProps.ts +10 -10
  279. package/src/props/IHeaderProps.ts +7 -7
  280. package/src/props/IImageProps.ts +4 -4
  281. package/src/props/ILinkProps.ts +5 -5
  282. package/src/props/IValidationNumberProps.ts +4 -4
  283. package/src/props/IValidationPrecisionProps.ts +3 -3
  284. package/src/props/IValidationProps.ts +9 -9
  285. package/src/props/IValidationRegexProps.ts +4 -4
  286. package/src/props/IValidationStringProps.ts +4 -4
  287. package/src/routing/NSNotifier.ts +114 -114
  288. package/src/routing/NSRouterMaker.tsx +20 -20
  289. package/src/routing/NSRouterMakerComponent.ts +5 -5
  290. package/src/routing/NSRouterMakerProps.ts +5 -5
@@ -1,257 +1,257 @@
1
- import { Component, createRef, ReactNode } from 'react';
2
- import { INSBox } from './INSBox';
3
- import { IBaseComponentProps } from '../props/IBaseComponentProps';
4
- import { NSSpace, NSSpaceSizeType } from './NSSpace';
5
- import { NSLine } from './NSLine';
6
- import { INSBoxBaseLayoutProps, NSBoxBaseLayout } from './NSBoxBaseLayout';
7
- import { safeMenuMenuItem } from './NSMenuButton';
8
- import { Validator } from '../Validator';
9
-
10
- export interface NSRepeaterProps<ItemType, ValueType> extends IBaseComponentProps, INSBoxBaseLayoutProps<ItemType, ValueType>
11
- {
12
- createItem: (gIndex: number, lIndex: number, ref: React.RefObject<ItemType>, onChange: () => void, onDelete: undefined | ((lIndex: number) => void)) => ReactNode;
13
- getValue: (item: ItemType, checkError: boolean) => ValueType | null;
14
- setValue: (item: ItemType, index: number, value: ValueType | null, callback?: () => void) => void;
15
- isEmpty: (item: ItemType, value: ValueType | null) => boolean;
16
- onItemChanged?: (repeater: NSRepeater<ItemType, ValueType>) => void;
17
- onValuesChanged?: (repeater: NSRepeater<ItemType, ValueType>) => void;
18
- required: boolean;
19
- min?: number;
20
- max?: number;
21
- ignoreItemsHavingError?: boolean;
22
- }
23
-
24
- export interface NSRepeaterState
25
- {
26
- items: boolean[];
27
- }
28
-
29
- export class NSRepeater<ItemType, ValueType> extends Component<NSRepeaterProps<ItemType, ValueType>, NSRepeaterState> implements INSBox
30
- {
31
- NSBoxBaseLayout_Main = createRef<NSBoxBaseLayout>();
32
- private Item_Refs: React.RefObject<ItemType>[] = [];
33
- private last_value: ValueType[] = [];
34
- constructor(props: NSRepeaterProps<ItemType, ValueType>)
35
- {
36
- super(props);
37
- this.state = { items: [] };
38
- this.getCount = this.getCount.bind(this);
39
- this.canDelete = this.canDelete.bind(this);
40
- this.getGIndex = this.getGIndex.bind(this);
41
- this.getIndex = this.getIndex.bind(this);
42
- this.addItem = this.addItem.bind(this);
43
- this.delItem = this.delItem.bind(this);
44
- this.onChange = this.onChange.bind(this);
45
- this.checkForNew = this.checkForNew.bind(this);
46
-
47
- this.isEmpty = this.isEmpty.bind(this);
48
- this.getError = this.getError.bind(this);
49
- this.getValue = this.getValue.bind(this);
50
- this.setValue = this.setValue.bind(this);
51
- }
52
- private getCount(): number
53
- {
54
- return this.state.items.filter(x => x).length;
55
- }
56
- private canDelete(gIndex: number)
57
- {
58
- if (this.Item_Refs.length > 0)
59
- {
60
- let count = this.getCount();
61
- if (count <= (this.props.min ?? 1))
62
- return false;
63
- if (count === this.props.max)
64
- return true;
65
- if (gIndex === this.state.items.length - 1)
66
- return false;
67
- return true
68
- }
69
- return false;
70
- }
71
- private getGIndex(index: number): number
72
- {
73
- if (this.state.items.length === 0)
74
- return 0;
75
- for (let i = 0; i < this.state.items.length; i++)
76
- {
77
- if (this.state.items[i])
78
- {
79
- if (index === 0)
80
- return i;
81
- index--;
82
- }
83
- }
84
- return this.state.items.length - 1;
85
- }
86
- private getIndex(gindex: number): number
87
- {
88
- if (gindex >= this.state.items.length)
89
- throw new Error("GIndex out of bound: " + gindex);
90
- let ans = -1;
91
- for (let i = 0; i <= gindex; i++)
92
- if (this.state.items[i])
93
- ans++;
94
- return ans;
95
- }
96
- private addItem(state: boolean = true)
97
- {
98
- if (!this.props.max || this.getCount() < this.props.max)
99
- {
100
- this.Item_Refs.push(createRef<ItemType>());
101
- if (state)
102
- {
103
- let items = this.state.items;
104
- items.push(true);
105
- this.setState({ items }, () =>
106
- {
107
- this.props.onItemChanged?.(this);
108
- });
109
- }
110
- }
111
- }
112
- private delItem(lIndex: number)
113
- {
114
- let gindex = this.getGIndex(lIndex);
115
- if (this.canDelete(gindex))
116
- {
117
- let items = this.state.items;
118
- items[gindex] = false;
119
- this.setState({ items }, () =>
120
- {
121
- this.props.onItemChanged?.(this);
122
- this.onChange();
123
- });
124
- }
125
- }
126
- private onChange()
127
- {
128
- console.log({ items: this.state.items });
129
- this.props.onValuesChanged?.(this);
130
- this.checkForNew();
131
- }
132
- private checkForNew()
133
- {
134
- let length = this.state.items.filter(x => x).length;
135
- if (length === 0)
136
- this.addItem();
137
- else
138
- {
139
- let last = this.Item_Refs.length - 1;
140
- while (!this.state.items[last])
141
- last--;
142
- let item = this.Item_Refs[last].current;
143
- if (item)
144
- if (!this.props.isEmpty(item, this.props.getValue(item, false)))
145
- {
146
- debugger;
147
- this.addItem();
148
- }
149
- }
150
- }
151
- isEmpty(): boolean
152
- {
153
- return true;
154
- }
155
- getError(): string | null
156
- {
157
- return (
158
- Validator.getErrorArray(this.props.title, this.last_value, this.props.required, this.props.min, this.props.max)
159
- );
160
- }
161
- getValue(checkError: boolean = true): ValueType[]
162
- {
163
- this.last_value = this.state.items.map((exists, index) =>
164
- {
165
- if (exists)
166
- {
167
- let item = this.Item_Refs[index].current;
168
- if (item)
169
- {
170
- try
171
- {
172
- let empty_value = this.props.getValue(item, false);
173
- if (!this.props.isEmpty(item, empty_value))
174
- return this.props.getValue(item, checkError);
175
- } catch (error)
176
- {
177
- if (this.props.ignoreItemsHavingError !== true)
178
- throw error;
179
- }
180
- }
181
- }
182
- return null
183
- }).filter(x => x !== null) as ValueType[];
184
- return NSBoxBaseLayout.checkGetValue(this, checkError, () => this.last_value) ?? [];
185
- }
186
- setValue(value: ValueType[], callback?: () => void): void
187
- {
188
- this.Item_Refs = [];
189
- value.forEach(() =>
190
- {
191
- this.addItem(false);
192
- })
193
- let items = value.map(() => true);
194
- this.setState({ items }, () =>
195
- {
196
- this.props.onItemChanged?.(this);
197
- value.forEach((value, index) =>
198
- {
199
- let item = this.Item_Refs[index].current;
200
- if (item)
201
- this.props.setValue(item, index, value);
202
- });
203
- this.onChange();
204
- callback?.();
205
- });
206
- }
207
- override componentDidMount()
208
- {
209
- let min = this.props.min ?? 1;
210
- for (let i = 0; i < min; i++)
211
- this.addItem();
212
- }
213
- override render()
214
- {
215
- let menu = safeMenuMenuItem(this.props, () => { });
216
-
217
- let LIndex = -1;
218
-
219
- return (
220
- <NSBoxBaseLayout
221
- ref={this.NSBoxBaseLayout_Main}
222
- {...this.props}
223
- menu={menu}
224
- >
225
- {
226
- this.Item_Refs.map((ref, GIndex) =>
227
- {
228
- if (this.state.items[GIndex])
229
- LIndex++;
230
- let visible = this.state.items[GIndex];
231
- let props = { ...this.props };
232
- props.style = { ...props.style };
233
- if (!visible)
234
- props.style.display = "none";
235
-
236
- let onDelete = undefined;
237
- if (this.canDelete(GIndex))
238
- onDelete = this.delItem;
239
-
240
- let item = this.props.createItem(GIndex, LIndex, ref, this.onChange, onDelete);
241
-
242
- if (visible && LIndex !== 0)
243
- return <div style={{ width: "100%", ...props.style }}>
244
- <NSSpace size={NSSpaceSizeType.MICRO} />
245
- <NSLine />
246
- <NSSpace size={NSSpaceSizeType.MICRO} />
247
- {item}
248
- </div>
249
- return <div style={{ width: "100%", ...props.style }}>
250
- {item}
251
- </div>
252
- })
253
- }
254
- </NSBoxBaseLayout>
255
- );
256
- }
1
+ import { Component, createRef, ReactNode } from 'react';
2
+ import { INSBox } from './INSBox';
3
+ import { IBaseComponentProps } from '../props/IBaseComponentProps';
4
+ import { NSSpace, NSSpaceSizeType } from './NSSpace';
5
+ import { NSLine } from './NSLine';
6
+ import { INSBoxBaseLayoutProps, NSBoxBaseLayout } from './NSBoxBaseLayout';
7
+ import { safeMenuMenuItem } from './NSMenuButton';
8
+ import { Validator } from '../Validator';
9
+
10
+ export interface NSRepeaterProps<ItemType, ValueType> extends IBaseComponentProps, INSBoxBaseLayoutProps<ItemType, ValueType>
11
+ {
12
+ createItem: (gIndex: number, lIndex: number, ref: React.RefObject<ItemType>, onChange: () => void, onDelete: undefined | ((lIndex: number) => void)) => ReactNode;
13
+ getValue: (item: ItemType, checkError: boolean) => ValueType | null;
14
+ setValue: (item: ItemType, index: number, value: ValueType | null, callback?: () => void) => void;
15
+ isEmpty: (item: ItemType, value: ValueType | null) => boolean;
16
+ onItemChanged?: (repeater: NSRepeater<ItemType, ValueType>) => void;
17
+ onValuesChanged?: (repeater: NSRepeater<ItemType, ValueType>) => void;
18
+ required: boolean;
19
+ min?: number;
20
+ max?: number;
21
+ ignoreItemsHavingError?: boolean;
22
+ }
23
+
24
+ export interface NSRepeaterState
25
+ {
26
+ items: boolean[];
27
+ }
28
+
29
+ export class NSRepeater<ItemType, ValueType> extends Component<NSRepeaterProps<ItemType, ValueType>, NSRepeaterState> implements INSBox
30
+ {
31
+ NSBoxBaseLayout_Main = createRef<NSBoxBaseLayout>();
32
+ private Item_Refs: React.RefObject<ItemType>[] = [];
33
+ private last_value: ValueType[] = [];
34
+ constructor(props: NSRepeaterProps<ItemType, ValueType>)
35
+ {
36
+ super(props);
37
+ this.state = { items: [] };
38
+ this.getCount = this.getCount.bind(this);
39
+ this.canDelete = this.canDelete.bind(this);
40
+ this.getGIndex = this.getGIndex.bind(this);
41
+ this.getIndex = this.getIndex.bind(this);
42
+ this.addItem = this.addItem.bind(this);
43
+ this.delItem = this.delItem.bind(this);
44
+ this.onChange = this.onChange.bind(this);
45
+ this.checkForNew = this.checkForNew.bind(this);
46
+
47
+ this.isEmpty = this.isEmpty.bind(this);
48
+ this.getError = this.getError.bind(this);
49
+ this.getValue = this.getValue.bind(this);
50
+ this.setValue = this.setValue.bind(this);
51
+ }
52
+ private getCount(): number
53
+ {
54
+ return this.state.items.filter(x => x).length;
55
+ }
56
+ private canDelete(gIndex: number)
57
+ {
58
+ if (this.Item_Refs.length > 0)
59
+ {
60
+ let count = this.getCount();
61
+ if (count <= (this.props.min ?? 1))
62
+ return false;
63
+ if (count === this.props.max)
64
+ return true;
65
+ if (gIndex === this.state.items.length - 1)
66
+ return false;
67
+ return true
68
+ }
69
+ return false;
70
+ }
71
+ private getGIndex(index: number): number
72
+ {
73
+ if (this.state.items.length === 0)
74
+ return 0;
75
+ for (let i = 0; i < this.state.items.length; i++)
76
+ {
77
+ if (this.state.items[i])
78
+ {
79
+ if (index === 0)
80
+ return i;
81
+ index--;
82
+ }
83
+ }
84
+ return this.state.items.length - 1;
85
+ }
86
+ private getIndex(gindex: number): number
87
+ {
88
+ if (gindex >= this.state.items.length)
89
+ throw new Error("GIndex out of bound: " + gindex);
90
+ let ans = -1;
91
+ for (let i = 0; i <= gindex; i++)
92
+ if (this.state.items[i])
93
+ ans++;
94
+ return ans;
95
+ }
96
+ private addItem(state: boolean = true)
97
+ {
98
+ if (!this.props.max || this.getCount() < this.props.max)
99
+ {
100
+ this.Item_Refs.push(createRef<ItemType>());
101
+ if (state)
102
+ {
103
+ let items = this.state.items;
104
+ items.push(true);
105
+ this.setState({ items }, () =>
106
+ {
107
+ this.props.onItemChanged?.(this);
108
+ });
109
+ }
110
+ }
111
+ }
112
+ private delItem(lIndex: number)
113
+ {
114
+ let gindex = this.getGIndex(lIndex);
115
+ if (this.canDelete(gindex))
116
+ {
117
+ let items = this.state.items;
118
+ items[gindex] = false;
119
+ this.setState({ items }, () =>
120
+ {
121
+ this.props.onItemChanged?.(this);
122
+ this.onChange();
123
+ });
124
+ }
125
+ }
126
+ private onChange()
127
+ {
128
+ console.log({ items: this.state.items });
129
+ this.props.onValuesChanged?.(this);
130
+ this.checkForNew();
131
+ }
132
+ private checkForNew()
133
+ {
134
+ let length = this.state.items.filter(x => x).length;
135
+ if (length === 0)
136
+ this.addItem();
137
+ else
138
+ {
139
+ let last = this.Item_Refs.length - 1;
140
+ while (!this.state.items[last])
141
+ last--;
142
+ let item = this.Item_Refs[last].current;
143
+ if (item)
144
+ if (!this.props.isEmpty(item, this.props.getValue(item, false)))
145
+ {
146
+ debugger;
147
+ this.addItem();
148
+ }
149
+ }
150
+ }
151
+ isEmpty(): boolean
152
+ {
153
+ return true;
154
+ }
155
+ getError(): string | null
156
+ {
157
+ return (
158
+ Validator.getErrorArray(this.props.title, this.last_value, this.props.required, this.props.min, this.props.max)
159
+ );
160
+ }
161
+ getValue(checkError: boolean = true): ValueType[]
162
+ {
163
+ this.last_value = this.state.items.map((exists, index) =>
164
+ {
165
+ if (exists)
166
+ {
167
+ let item = this.Item_Refs[index].current;
168
+ if (item)
169
+ {
170
+ try
171
+ {
172
+ let empty_value = this.props.getValue(item, false);
173
+ if (!this.props.isEmpty(item, empty_value))
174
+ return this.props.getValue(item, checkError);
175
+ } catch (error)
176
+ {
177
+ if (this.props.ignoreItemsHavingError !== true)
178
+ throw error;
179
+ }
180
+ }
181
+ }
182
+ return null
183
+ }).filter(x => x !== null) as ValueType[];
184
+ return NSBoxBaseLayout.checkGetValue(this, checkError, () => this.last_value) ?? [];
185
+ }
186
+ setValue(value: ValueType[], callback?: () => void): void
187
+ {
188
+ this.Item_Refs = [];
189
+ value.forEach(() =>
190
+ {
191
+ this.addItem(false);
192
+ })
193
+ let items = value.map(() => true);
194
+ this.setState({ items }, () =>
195
+ {
196
+ this.props.onItemChanged?.(this);
197
+ value.forEach((value, index) =>
198
+ {
199
+ let item = this.Item_Refs[index].current;
200
+ if (item)
201
+ this.props.setValue(item, index, value);
202
+ });
203
+ this.onChange();
204
+ callback?.();
205
+ });
206
+ }
207
+ override componentDidMount()
208
+ {
209
+ let min = this.props.min ?? 1;
210
+ for (let i = 0; i < min; i++)
211
+ this.addItem();
212
+ }
213
+ override render()
214
+ {
215
+ let menu = safeMenuMenuItem(this.props, () => { });
216
+
217
+ let LIndex = -1;
218
+
219
+ return (
220
+ <NSBoxBaseLayout
221
+ ref={this.NSBoxBaseLayout_Main}
222
+ {...this.props}
223
+ menu={menu}
224
+ >
225
+ {
226
+ this.Item_Refs.map((ref, GIndex) =>
227
+ {
228
+ if (this.state.items[GIndex])
229
+ LIndex++;
230
+ let visible = this.state.items[GIndex];
231
+ let props = { ...this.props };
232
+ props.style = { ...props.style };
233
+ if (!visible)
234
+ props.style.display = "none";
235
+
236
+ let onDelete = undefined;
237
+ if (this.canDelete(GIndex))
238
+ onDelete = this.delItem;
239
+
240
+ let item = this.props.createItem(GIndex, LIndex, ref, this.onChange, onDelete);
241
+
242
+ if (visible && LIndex !== 0)
243
+ return <div style={{ width: "100%", ...props.style }}>
244
+ <NSSpace size={NSSpaceSizeType.MICRO} />
245
+ <NSLine />
246
+ <NSSpace size={NSSpaceSizeType.MICRO} />
247
+ {item}
248
+ </div>
249
+ return <div style={{ width: "100%", ...props.style }}>
250
+ {item}
251
+ </div>
252
+ })
253
+ }
254
+ </NSBoxBaseLayout>
255
+ );
256
+ }
257
257
  }