funda-ui 4.1.335 → 4.1.345
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/DynamicFields/index.js +38 -32
- package/lib/cjs/DynamicFields/index.js +38 -32
- package/lib/esm/DynamicFields/index.tsx +68 -57
- package/package.json +1 -1
package/DynamicFields/index.js
CHANGED
|
@@ -243,45 +243,51 @@ var DynamicFields = function DynamicFields(props) {
|
|
|
243
243
|
}
|
|
244
244
|
function handleClickRemove(e) {
|
|
245
245
|
if (e !== null && typeof e !== 'undefined') e.preventDefault();
|
|
246
|
-
var
|
|
246
|
+
var $target = e.currentTarget.closest('.dynamic-fields__data__wrapper');
|
|
247
|
+
if ($target === null) return;
|
|
248
|
+
var curKey = $target.dataset.key;
|
|
247
249
|
if (window.confirm(confirmText || '')) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
250
|
+
if (rootRef.current && addBtnRef.current) {
|
|
251
|
+
//button status
|
|
252
|
+
if (rootRef.current.querySelectorAll(PER_ROW_DOM_STRING).length <= parseFloat(maxFields)) {
|
|
253
|
+
addBtnRef.current.style.setProperty('display', 'inline', 'important');
|
|
254
|
+
}
|
|
255
|
+
var curItem = rootRef.current.querySelector(".dynamic-fields__append [data-key=\"".concat(curKey, "\"]"));
|
|
256
|
+
if (curItem !== null) {
|
|
257
|
+
var curIndex = curItem.dataset.index;
|
|
254
258
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
259
|
+
// Do not delete the parent node `innerAppendBodyClassName`, otherwise an error may be reported when
|
|
260
|
+
// using routing: DOMException: Failed to execute 'removeChild' on 'Node'
|
|
261
|
+
if (!DO_NOT_REMOVE_DOM) {
|
|
262
|
+
curItem.remove();
|
|
263
|
+
}
|
|
260
264
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
265
|
+
//
|
|
266
|
+
setTimeout(function () {
|
|
267
|
+
var perRow = [].slice.call(rootRef.current.querySelectorAll(PER_ROW_DOM_STRING));
|
|
264
268
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
+
// update index
|
|
270
|
+
perRow.forEach(function (el, i) {
|
|
271
|
+
el.dataset.index = i.toString();
|
|
272
|
+
});
|
|
269
273
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
274
|
+
// update last element
|
|
275
|
+
if (perRow.length === 1) {
|
|
276
|
+
updateLastItemCls(perRow[0], 'add');
|
|
277
|
+
} else {
|
|
278
|
+
updateLastItemCls(perRow[perRow.length - 1], 'add');
|
|
279
|
+
}
|
|
276
280
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
+
// update inner elements
|
|
282
|
+
if (perRow.length === 0) {
|
|
283
|
+
if (!emptyContentEnabled('remove')) updateHeadCls('add');
|
|
284
|
+
}
|
|
281
285
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
286
|
+
//
|
|
287
|
+
onRemove === null || onRemove === void 0 ? void 0 : onRemove(perRow, curKey, curIndex, rootRef.current, e.currentTarget, PER_ROW_DOM_STRING);
|
|
288
|
+
}, 0);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
285
291
|
}
|
|
286
292
|
}
|
|
287
293
|
function generateGroup(inputData) {
|
|
@@ -243,45 +243,51 @@ var DynamicFields = function DynamicFields(props) {
|
|
|
243
243
|
}
|
|
244
244
|
function handleClickRemove(e) {
|
|
245
245
|
if (e !== null && typeof e !== 'undefined') e.preventDefault();
|
|
246
|
-
var
|
|
246
|
+
var $target = e.currentTarget.closest('.dynamic-fields__data__wrapper');
|
|
247
|
+
if ($target === null) return;
|
|
248
|
+
var curKey = $target.dataset.key;
|
|
247
249
|
if (window.confirm(confirmText || '')) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
250
|
+
if (rootRef.current && addBtnRef.current) {
|
|
251
|
+
//button status
|
|
252
|
+
if (rootRef.current.querySelectorAll(PER_ROW_DOM_STRING).length <= parseFloat(maxFields)) {
|
|
253
|
+
addBtnRef.current.style.setProperty('display', 'inline', 'important');
|
|
254
|
+
}
|
|
255
|
+
var curItem = rootRef.current.querySelector(".dynamic-fields__append [data-key=\"".concat(curKey, "\"]"));
|
|
256
|
+
if (curItem !== null) {
|
|
257
|
+
var curIndex = curItem.dataset.index;
|
|
254
258
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
259
|
+
// Do not delete the parent node `innerAppendBodyClassName`, otherwise an error may be reported when
|
|
260
|
+
// using routing: DOMException: Failed to execute 'removeChild' on 'Node'
|
|
261
|
+
if (!DO_NOT_REMOVE_DOM) {
|
|
262
|
+
curItem.remove();
|
|
263
|
+
}
|
|
260
264
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
265
|
+
//
|
|
266
|
+
setTimeout(function () {
|
|
267
|
+
var perRow = [].slice.call(rootRef.current.querySelectorAll(PER_ROW_DOM_STRING));
|
|
264
268
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
+
// update index
|
|
270
|
+
perRow.forEach(function (el, i) {
|
|
271
|
+
el.dataset.index = i.toString();
|
|
272
|
+
});
|
|
269
273
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
274
|
+
// update last element
|
|
275
|
+
if (perRow.length === 1) {
|
|
276
|
+
updateLastItemCls(perRow[0], 'add');
|
|
277
|
+
} else {
|
|
278
|
+
updateLastItemCls(perRow[perRow.length - 1], 'add');
|
|
279
|
+
}
|
|
276
280
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
+
// update inner elements
|
|
282
|
+
if (perRow.length === 0) {
|
|
283
|
+
if (!emptyContentEnabled('remove')) updateHeadCls('add');
|
|
284
|
+
}
|
|
281
285
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
286
|
+
//
|
|
287
|
+
onRemove === null || onRemove === void 0 ? void 0 : onRemove(perRow, curKey, curIndex, rootRef.current, e.currentTarget, PER_ROW_DOM_STRING);
|
|
288
|
+
}, 0);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
285
291
|
}
|
|
286
292
|
}
|
|
287
293
|
function generateGroup(inputData) {
|
|
@@ -104,7 +104,7 @@ const DynamicFields = (props: DynamicFieldsProps) => {
|
|
|
104
104
|
el.classList.remove(ITEM_LAST_CLASSNAME);
|
|
105
105
|
(el.firstChild as HTMLDivElement)?.classList.remove(ITEM_LAST_CLASSNAME);
|
|
106
106
|
});
|
|
107
|
-
|
|
107
|
+
|
|
108
108
|
el.classList.add(ITEM_LAST_CLASSNAME);
|
|
109
109
|
el.parentElement?.classList.add(ITEM_LAST_CLASSNAME);
|
|
110
110
|
} else {
|
|
@@ -160,8 +160,8 @@ const DynamicFields = (props: DynamicFieldsProps) => {
|
|
|
160
160
|
//
|
|
161
161
|
setTimeout(() => {
|
|
162
162
|
const perRow = [].slice.call(rootRef.current.querySelectorAll(PER_ROW_DOM_STRING));
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
|
|
164
|
+
|
|
165
165
|
// update index
|
|
166
166
|
perRow.forEach((el: HTMLDivElement, i: number) => {
|
|
167
167
|
el.dataset.index = i.toString();
|
|
@@ -171,7 +171,7 @@ const DynamicFields = (props: DynamicFieldsProps) => {
|
|
|
171
171
|
// update last element
|
|
172
172
|
if (perRow.length > 1) {
|
|
173
173
|
updateLastItemCls(perRow[0], 'remove');
|
|
174
|
-
updateLastItemCls(perRow[perRow.length-1], 'add');
|
|
174
|
+
updateLastItemCls(perRow[perRow.length - 1], 'add');
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
// update inner elements
|
|
@@ -186,55 +186,66 @@ const DynamicFields = (props: DynamicFieldsProps) => {
|
|
|
186
186
|
|
|
187
187
|
|
|
188
188
|
function handleClickRemove(e: React.MouseEvent) {
|
|
189
|
-
if (e !== null && typeof e !== 'undefined')
|
|
189
|
+
if (e !== null && typeof e !== 'undefined') e.preventDefault();
|
|
190
|
+
|
|
191
|
+
const $target: any = e.currentTarget.closest('.dynamic-fields__data__wrapper');
|
|
192
|
+
if ($target === null) return;
|
|
193
|
+
|
|
194
|
+
const curKey = ($target as HTMLDivElement).dataset.key;
|
|
190
195
|
|
|
191
|
-
const curKey = (e.currentTarget.closest('.dynamic-fields__data__wrapper') as HTMLDivElement).dataset.key;
|
|
192
|
-
|
|
193
196
|
|
|
194
197
|
if (window.confirm(confirmText || '')) {
|
|
195
198
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
199
|
+
if (rootRef.current && addBtnRef.current) {
|
|
200
|
+
//button status
|
|
201
|
+
if (rootRef.current.querySelectorAll(PER_ROW_DOM_STRING).length <= parseFloat(maxFields)) {
|
|
202
|
+
addBtnRef.current.style.setProperty('display', 'inline', 'important');
|
|
203
|
+
}
|
|
200
204
|
|
|
201
|
-
|
|
202
|
-
const curItem = rootRef.current.querySelector(`.dynamic-fields__append [data-key="${curKey}"]`);
|
|
203
|
-
const curIndex = curItem.dataset.index;
|
|
204
205
|
|
|
206
|
+
const curItem = rootRef.current.querySelector(`.dynamic-fields__append [data-key="${curKey}"]`);
|
|
205
207
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (curItem !== null && !DO_NOT_REMOVE_DOM) {
|
|
209
|
-
curItem.remove();
|
|
210
|
-
}
|
|
208
|
+
if (curItem !== null) {
|
|
209
|
+
const curIndex = curItem.dataset.index;
|
|
211
210
|
|
|
212
|
-
|
|
213
|
-
//
|
|
214
|
-
setTimeout(() => {
|
|
215
|
-
const perRow = [].slice.call(rootRef.current.querySelectorAll(PER_ROW_DOM_STRING));
|
|
216
|
-
|
|
217
|
-
// update index
|
|
218
|
-
perRow.forEach((el: HTMLDivElement, i: number) => {
|
|
219
|
-
el.dataset.index = i.toString();
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
// update last element
|
|
223
|
-
if (perRow.length === 1) {
|
|
224
|
-
updateLastItemCls(perRow[0], 'add');
|
|
225
|
-
} else {
|
|
226
|
-
updateLastItemCls(perRow[perRow.length-1], 'add');
|
|
227
|
-
}
|
|
228
211
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (!
|
|
212
|
+
// Do not delete the parent node `innerAppendBodyClassName`, otherwise an error may be reported when
|
|
213
|
+
// using routing: DOMException: Failed to execute 'removeChild' on 'Node'
|
|
214
|
+
if (!DO_NOT_REMOVE_DOM) {
|
|
215
|
+
curItem.remove();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
//
|
|
220
|
+
setTimeout(() => {
|
|
221
|
+
const perRow = [].slice.call(rootRef.current.querySelectorAll(PER_ROW_DOM_STRING));
|
|
222
|
+
|
|
223
|
+
// update index
|
|
224
|
+
perRow.forEach((el: HTMLDivElement, i: number) => {
|
|
225
|
+
el.dataset.index = i.toString();
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// update last element
|
|
229
|
+
if (perRow.length === 1) {
|
|
230
|
+
updateLastItemCls(perRow[0], 'add');
|
|
231
|
+
} else {
|
|
232
|
+
updateLastItemCls(perRow[perRow.length - 1], 'add');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// update inner elements
|
|
236
|
+
if (perRow.length === 0) {
|
|
237
|
+
if (!emptyContentEnabled('remove')) updateHeadCls('add');
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
//
|
|
242
|
+
onRemove?.(perRow, curKey as never, curIndex as number, rootRef.current, e.currentTarget as HTMLAnchorElement, PER_ROW_DOM_STRING);
|
|
243
|
+
}, 0);
|
|
232
244
|
}
|
|
233
|
-
|
|
234
245
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
238
249
|
}
|
|
239
250
|
|
|
240
251
|
}
|
|
@@ -243,29 +254,29 @@ const DynamicFields = (props: DynamicFieldsProps) => {
|
|
|
243
254
|
const isNew = !Array.isArray(inputData);
|
|
244
255
|
const _data = Array.isArray(inputData) ? inputData : [inputData];
|
|
245
256
|
|
|
246
|
-
|
|
257
|
+
|
|
247
258
|
return (
|
|
248
259
|
_data.map((item: any, i: number) => {
|
|
249
|
-
const removeBtyn = <><a href="#" tabIndex={-1} className={`dynamic-fields__removebtn ${btnRemoveWrapperClassName || 'align-middle'
|
|
260
|
+
const removeBtyn = <><a href="#" tabIndex={-1} className={`dynamic-fields__removebtn ${btnRemoveWrapperClassName || 'align-middle'}`} onClick={handleClickRemove}>
|
|
250
261
|
{iconRemove ? <>{iconRemove}</> : <><svg width="20px" height="20px" viewBox="0 0 24 24" fill="none"><path fillRule="evenodd" clipRule="evenodd" d="M22 12c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2s10 4.477 10 10ZM8 11a1 1 0 1 0 0 2h8a1 1 0 1 0 0-2H8Z" fill="#000" /></svg></>}
|
|
251
262
|
</a></>;
|
|
252
263
|
|
|
253
264
|
return <React.Fragment key={'tmpl-' + i}>
|
|
254
265
|
{isNew ? <>
|
|
255
266
|
{item}
|
|
256
|
-
</> : <><div key={'tmpl-' + i} className={`dynamic-fields__inner__body ${innerAppendBodyClassName || ''} ${i === _data.length-1 ? ITEM_LAST_CLASSNAME : ''}`} data-body-index={i}>
|
|
257
|
-
<div
|
|
258
|
-
className={`dynamic-fields__data__wrapper position-relative ${innerAppendCellClassName || ''} ${i === _data.length-1 ? ITEM_LAST_CLASSNAME : ''}`}
|
|
259
|
-
data-key={i}
|
|
267
|
+
</> : <><div key={'tmpl-' + i} className={`dynamic-fields__inner__body ${innerAppendBodyClassName || ''} ${i === _data.length - 1 ? ITEM_LAST_CLASSNAME : ''}`} data-body-index={i}>
|
|
268
|
+
<div
|
|
269
|
+
className={`dynamic-fields__data__wrapper position-relative ${innerAppendCellClassName || ''} ${i === _data.length - 1 ? ITEM_LAST_CLASSNAME : ''}`}
|
|
270
|
+
data-key={i}
|
|
260
271
|
data-index={i}
|
|
261
272
|
{...attributes}
|
|
262
273
|
>
|
|
263
274
|
{item}
|
|
264
275
|
{removeBtyn}
|
|
265
276
|
</div>
|
|
266
|
-
|
|
277
|
+
</div>
|
|
267
278
|
</>}
|
|
268
|
-
|
|
279
|
+
|
|
269
280
|
</React.Fragment>
|
|
270
281
|
|
|
271
282
|
})
|
|
@@ -273,11 +284,11 @@ const DynamicFields = (props: DynamicFieldsProps) => {
|
|
|
273
284
|
)
|
|
274
285
|
|
|
275
286
|
}
|
|
276
|
-
|
|
287
|
+
|
|
277
288
|
function addButton() {
|
|
278
289
|
return <div className="dynamic-fields__btns dynamic-fields__btns--end">
|
|
279
290
|
{iconAddBefore ? iconAddBefore : null}
|
|
280
|
-
<a ref={addBtnRef} id={addBtnIdRef.current} href="#" tabIndex={-1} className={`dynamic-fields__addbtn ${btnAddWrapperClassName || 'align-middle'
|
|
291
|
+
<a ref={addBtnRef} id={addBtnIdRef.current} href="#" tabIndex={-1} className={`dynamic-fields__addbtn ${btnAddWrapperClassName || 'align-middle'}`} onClick={handleClickAdd}>
|
|
281
292
|
{iconAdd ? <>{iconAdd}</> : <><svg width="20px" height="20px" viewBox="0 0 24 24" fill="none"><path d="M12 2C6.49 2 2 6.49 2 12C2 17.51 6.49 22 12 22C17.51 22 22 17.51 22 12C22 6.49 17.51 2 12 2ZM16 12.75H12.75V16C12.75 16.41 12.41 16.75 12 16.75C11.59 16.75 11.25 16.41 11.25 16V12.75H8C7.59 12.75 7.25 12.41 7.25 12C7.25 11.59 7.59 11.25 8 11.25H11.25V8C11.25 7.59 11.59 7.25 12 7.25C12.41 7.25 12.75 7.59 12.75 8V11.25H16C16.41 11.25 16.75 11.59 16.75 12C16.75 12.41 16.41 12.75 16 12.75Z" fill="#000" /></svg></>}
|
|
282
293
|
</a>
|
|
283
294
|
{iconAddAfter ? iconAddAfter : null}
|
|
@@ -289,7 +300,7 @@ const DynamicFields = (props: DynamicFieldsProps) => {
|
|
|
289
300
|
|
|
290
301
|
setVal(data ? data.init : []);
|
|
291
302
|
setTmpl(data ? data.tmpl : null);
|
|
292
|
-
|
|
303
|
+
|
|
293
304
|
//
|
|
294
305
|
onLoad?.(addBtnIdRef.current, rootRef.current, PER_ROW_DOM_STRING);
|
|
295
306
|
}, [data]);
|
|
@@ -300,7 +311,7 @@ const DynamicFields = (props: DynamicFieldsProps) => {
|
|
|
300
311
|
|
|
301
312
|
|
|
302
313
|
<div className={wrapperClassName || wrapperClassName === '' ? wrapperClassName : "mb-3 position-relative"} ref={rootRef}>
|
|
303
|
-
{label ? <>{typeof label === 'string' ? <label className="form-label" dangerouslySetInnerHTML={{__html: `${label}`}}></label> : <label className="form-label">{label}</label>}</> : null}
|
|
314
|
+
{label ? <>{typeof label === 'string' ? <label className="form-label" dangerouslySetInnerHTML={{ __html: `${label}` }}></label> : <label className="form-label">{label}</label>}</> : null}
|
|
304
315
|
|
|
305
316
|
<div ref={fieldsRef} className="dynamic-fields-container" data-max-fields={maxFields || 10} id={idRes}>
|
|
306
317
|
|
|
@@ -310,12 +321,12 @@ const DynamicFields = (props: DynamicFieldsProps) => {
|
|
|
310
321
|
|
|
311
322
|
|
|
312
323
|
<div className={`dynamic-fields__append ${innerAppendClassName || ''}`}>
|
|
313
|
-
|
|
324
|
+
|
|
314
325
|
{/* //////////// head /////////// */}
|
|
315
326
|
{innerAppendHeadData && Array.isArray(innerAppendHeadData) && (val.length > 0 || innerAppendHeadRowShowFirst) ? <>
|
|
316
327
|
<div className={`dynamic-fields__inner__head ${innerAppendHeadRowClassName || ''}`}>
|
|
317
|
-
{innerAppendHeadData.map((item: any, i:number) => {
|
|
318
|
-
return <div key={'inner-header-row' + i} className={`${innerAppendHeadCellClassName || ''} ${i === innerAppendHeadData.length-1 ? ITEM_LAST_CLASSNAME : ''} ${Array.isArray(innerAppendHeadCellClassName) ? (typeof innerAppendHeadCellClassName[i] !== 'undefined' ? innerAppendHeadCellClassName[i] : '') : ''}`} style={innerAppendHeadCellStyles && typeof innerAppendHeadCellStyles[i] !== 'undefined' ? innerAppendHeadCellStyles[i] : {}}>{item}</div>;
|
|
328
|
+
{innerAppendHeadData.map((item: any, i: number) => {
|
|
329
|
+
return <div key={'inner-header-row' + i} className={`${innerAppendHeadCellClassName || ''} ${i === innerAppendHeadData.length - 1 ? ITEM_LAST_CLASSNAME : ''} ${Array.isArray(innerAppendHeadCellClassName) ? (typeof innerAppendHeadCellClassName[i] !== 'undefined' ? innerAppendHeadCellClassName[i] : '') : ''}`} style={innerAppendHeadCellStyles && typeof innerAppendHeadCellStyles[i] !== 'undefined' ? innerAppendHeadCellStyles[i] : {}}>{item}</div>;
|
|
319
330
|
})}
|
|
320
331
|
</div>
|
|
321
332
|
</> : null}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "UIUX Lab",
|
|
3
3
|
"email": "uiuxlab@gmail.com",
|
|
4
4
|
"name": "funda-ui",
|
|
5
|
-
"version": "4.1.
|
|
5
|
+
"version": "4.1.345",
|
|
6
6
|
"description": "React components using pure Bootstrap 5+ which does not contain any external style and script libraries.",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|