onekijs-ui 0.19.13 → 0.19.15

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.
@@ -5,15 +5,15 @@ declare class SelectService<T = any, I extends SelectItem<T> = SelectItem<T>, S
5
5
  protected lastCheckQuery: Query | undefined;
6
6
  get defaultValue(): T | T[] | null | undefined;
7
7
  get defaultValueLoading(): boolean | undefined;
8
- check(): Generator<void | import("redux-saga/effects").AllEffect<import("redux-saga/effects").CallEffect<Generator<I[] | Generator<void | import("redux-saga/effects").ForkEffect<Generator<void | import("redux-saga/effects").CallEffect<true>, void, unknown>> | import("redux-saga/effects").CancelEffect | CollectionFetcherResult<T> | Promise<CollectionFetcherResult<T> | undefined>, CollectionFetcherResult<T>, (import("redux-saga").Task<any> | null) & CollectionFetcherResult<T> & (CollectionFetcherResult<T> | undefined)>, I | undefined, I[] & CollectionFetcherResult<T>>>> | import("redux-saga/effects").AllEffect<Generator<I[] | Generator<void | import("redux-saga/effects").ForkEffect<Generator<void | import("redux-saga/effects").CallEffect<true>, void, unknown>> | import("redux-saga/effects").CancelEffect | CollectionFetcherResult<T> | Promise<CollectionFetcherResult<T> | undefined>, CollectionFetcherResult<T>, (import("redux-saga").Task<any> | null) & CollectionFetcherResult<T> & (CollectionFetcherResult<T> | undefined)>, I | undefined, I[] & CollectionFetcherResult<T>>> | import("redux-saga/effects").CallEffect<void>, void, (I | undefined)[]>;
8
+ check(): Generator<void | import("redux-saga/effects").AllEffect<import("redux-saga/effects").CallEffect<Generator<I[] | Generator<void | import("redux-saga/effects").CancelEffect | import("redux-saga/effects").ForkEffect<Generator<void | import("redux-saga/effects").CallEffect<true>, void, unknown>> | CollectionFetcherResult<T> | Promise<CollectionFetcherResult<T> | undefined>, CollectionFetcherResult<T>, (import("redux-saga").Task<any> | null) & CollectionFetcherResult<T> & (CollectionFetcherResult<T> | undefined)>, I | undefined, I[] & CollectionFetcherResult<T>>>> | import("redux-saga/effects").AllEffect<Generator<I[] | Generator<void | import("redux-saga/effects").CancelEffect | import("redux-saga/effects").ForkEffect<Generator<void | import("redux-saga/effects").CallEffect<true>, void, unknown>> | CollectionFetcherResult<T> | Promise<CollectionFetcherResult<T> | undefined>, CollectionFetcherResult<T>, (import("redux-saga").Task<any> | null) & CollectionFetcherResult<T> & (CollectionFetcherResult<T> | undefined)>, I | undefined, I[] & CollectionFetcherResult<T>>> | import("redux-saga/effects").CallEffect<void>, void, (I | undefined)[]>;
9
9
  setData(data: T[], query?: Query): void;
10
- setDefaultValue(value: T | T[] | null | undefined): Generator<void | Generator<void | import("redux-saga/effects").AllEffect<import("redux-saga/effects").CallEffect<Generator<I[] | Generator<void | import("redux-saga/effects").ForkEffect<Generator<void | import("redux-saga/effects").CallEffect<true>, void, unknown>> | import("redux-saga/effects").CancelEffect | CollectionFetcherResult<T> | Promise<CollectionFetcherResult<T> | undefined>, CollectionFetcherResult<T>, (import("redux-saga").Task<any> | null) & CollectionFetcherResult<T> & (CollectionFetcherResult<T> | undefined)>, I | undefined, I[] & CollectionFetcherResult<T>>>> | import("redux-saga/effects").AllEffect<Generator<I[] | Generator<void | import("redux-saga/effects").ForkEffect<Generator<void | import("redux-saga/effects").CallEffect<true>, void, unknown>> | import("redux-saga/effects").CancelEffect | CollectionFetcherResult<T> | Promise<CollectionFetcherResult<T> | undefined>, CollectionFetcherResult<T>, (import("redux-saga").Task<any> | null) & CollectionFetcherResult<T> & (CollectionFetcherResult<T> | undefined)>, I | undefined, I[] & CollectionFetcherResult<T>>> | import("redux-saga/effects").CallEffect<void>, void, (I | undefined)[]>, void, unknown>;
10
+ setDefaultValue(value: T | T[] | null | undefined): Generator<void | Generator<void | import("redux-saga/effects").AllEffect<import("redux-saga/effects").CallEffect<Generator<I[] | Generator<void | import("redux-saga/effects").CancelEffect | import("redux-saga/effects").ForkEffect<Generator<void | import("redux-saga/effects").CallEffect<true>, void, unknown>> | CollectionFetcherResult<T> | Promise<CollectionFetcherResult<T> | undefined>, CollectionFetcherResult<T>, (import("redux-saga").Task<any> | null) & CollectionFetcherResult<T> & (CollectionFetcherResult<T> | undefined)>, I | undefined, I[] & CollectionFetcherResult<T>>>> | import("redux-saga/effects").AllEffect<Generator<I[] | Generator<void | import("redux-saga/effects").CancelEffect | import("redux-saga/effects").ForkEffect<Generator<void | import("redux-saga/effects").CallEffect<true>, void, unknown>> | CollectionFetcherResult<T> | Promise<CollectionFetcherResult<T> | undefined>, CollectionFetcherResult<T>, (import("redux-saga").Task<any> | null) & CollectionFetcherResult<T> & (CollectionFetcherResult<T> | undefined)>, I | undefined, I[] & CollectionFetcherResult<T>>> | import("redux-saga/effects").CallEffect<void>, void, (I | undefined)[]>, void, unknown>;
11
11
  setDefaultValueLoading(loading: boolean): void;
12
12
  setItemWidth(_item: I, value: number): void;
13
13
  setValue(value: null | T | T[]): void;
14
14
  setUrl(url: string, query?: Query): void;
15
15
  _buildItem(data: T | null | undefined, adaptee: unknown, context?: AnonymousObject): I;
16
- _filterItem(item: I | undefined, query: Query, valid: boolean): Generator<I[] | Generator<void | import("redux-saga/effects").ForkEffect<Generator<void | import("redux-saga/effects").CallEffect<true>, void, unknown>> | import("redux-saga/effects").CancelEffect | CollectionFetcherResult<T> | Promise<CollectionFetcherResult<T> | undefined>, CollectionFetcherResult<T>, (import("redux-saga").Task<any> | null) & CollectionFetcherResult<T> & (CollectionFetcherResult<T> | undefined)>, I | undefined, I[] & CollectionFetcherResult<T>>;
16
+ _filterItem(item: I | undefined, query: Query, valid: boolean): Generator<I[] | Generator<void | import("redux-saga/effects").CancelEffect | import("redux-saga/effects").ForkEffect<Generator<void | import("redux-saga/effects").CallEffect<true>, void, unknown>> | CollectionFetcherResult<T> | Promise<CollectionFetcherResult<T> | undefined>, CollectionFetcherResult<T>, (import("redux-saga").Task<any> | null) & CollectionFetcherResult<T> & (CollectionFetcherResult<T> | undefined)>, I | undefined, I[] & CollectionFetcherResult<T>>;
17
17
  _compareItem(a: I | undefined, b: I | undefined): boolean;
18
18
  _setDefaultValue(value: T | T[] | null | undefined): void;
19
19
  _setValidDefaultValue(value: T | T[] | null): void;
@@ -40,10 +40,12 @@ export type FormTableProps<T = any, I extends TableItem<T> = TableItem<T>, S ext
40
40
  export type FormTableContext<T = any> = {
41
41
  tableName: string;
42
42
  onSelect: (item: TableItem<T>, selected: boolean) => void;
43
+ onAdd: (initialValue: Partial<T> | undefined) => void;
43
44
  addLabel: string;
44
45
  required?: boolean;
45
46
  maxLength?: number;
46
47
  minLength?: number;
48
+ editable?: boolean;
47
49
  };
48
50
  export type FormTableItemDisplayerProps<T = any> = {
49
51
  value: T;
package/dist/index.js CHANGED
@@ -10245,11 +10245,11 @@ const SelectRowComponent = ({ item }) => {
10245
10245
  };
10246
10246
  const FooterComponent = () => {
10247
10247
  const form = onekijsFramework.useForm();
10248
- const { tableName, addLabel, maxLength } = useFormTableContext();
10248
+ const { tableName, addLabel, maxLength, onAdd } = useFormTableContext();
10249
10249
  const isSingleColumnTable = useTableColumns().find((c) => c.id === '');
10250
10250
  const addRow = (e) => {
10251
- form.add(tableName, isSingleColumnTable ? undefined : {});
10252
10251
  e.preventDefault();
10252
+ onAdd(isSingleColumnTable ? undefined : {});
10253
10253
  };
10254
10254
  const currentSize = (form.getValue(tableName) || []).length;
10255
10255
  if (maxLength !== undefined && currentSize >= maxLength)
@@ -10295,7 +10295,11 @@ const FormTableComponent = React.memo(({ addLabel = 'add', controller, value, on
10295
10295
  onChange && onChange(currentValues.filter((v) => getId(v) !== getId(value)));
10296
10296
  }
10297
10297
  };
10298
- return { tableName: name, onSelect, addLabel, required, minLength, maxLength };
10298
+ const onAdd = (initialValue) => {
10299
+ formTableContext.current.editable = true;
10300
+ form.add(name, initialValue);
10301
+ };
10302
+ return { tableName: name, onSelect, onAdd, addLabel, required, minLength, maxLength };
10299
10303
  });
10300
10304
  // listen on value change from the form
10301
10305
  // for the initial value in the table controller
@@ -10416,12 +10420,12 @@ FormTable.displayName = 'FormTable';
10416
10420
 
10417
10421
  const CheckboxCellComponent = (options) => {
10418
10422
  const CheckboxCellComponent = ({ item, column, rowIndex }) => {
10419
- const { tableName } = useFormTableContext();
10423
+ const { tableName, editable } = useFormTableContext();
10420
10424
  const { size, ...checkboxOptions } = options;
10421
10425
  // if the id is empty, it's a single table column and the value is the row itself
10422
10426
  const name = column.id ? `${tableName}.${rowIndex}.${column.id}` : `${tableName}.${rowIndex}`;
10423
10427
  const className = typeof options.className === 'function' ? options.className(item, column, rowIndex) : options.className;
10424
- return (React.createElement(FormCheckbox, { layout: "table", ...checkboxOptions, name: name, className: addClassname('o-table-checkbox', className) }));
10428
+ return (React.createElement(FormCheckbox, { layout: "table", ...checkboxOptions, name: name, className: addClassname('o-table-checkbox', className), editable: editable ?? options.editable }));
10425
10429
  };
10426
10430
  CheckboxCellComponent.displayName = 'CheckboxCellComponent';
10427
10431
  return CheckboxCellComponent;
@@ -10520,11 +10524,11 @@ const enumColumn = (id, options) => {
10520
10524
 
10521
10525
  const InputCellComponent = (options) => {
10522
10526
  const InputCellComponent = ({ item, column, rowIndex }) => {
10523
- const { tableName } = useFormTableContext();
10527
+ const { tableName, editable } = useFormTableContext();
10524
10528
  const className = typeof options.className === 'function' ? options.className(item, column, rowIndex) : options.className;
10525
10529
  // if the id is empty, it's a single table column and the value is the row itself
10526
10530
  const name = column.id ? `${tableName}.${rowIndex}.${column.id}` : `${tableName}.${rowIndex}`;
10527
- return (React.createElement(FormInput, { size: "small", layout: "table", ...options, name: name, className: addClassname('o-table-input', className) }));
10531
+ return (React.createElement(FormInput, { size: "small", layout: "table", ...options, name: name, className: addClassname('o-table-input', className), editable: editable ?? options.editable }));
10528
10532
  };
10529
10533
  InputCellComponent.displayName = 'InputCellComponent';
10530
10534
  return InputCellComponent;
@@ -10597,7 +10601,7 @@ const numberColumn = (id, options) => {
10597
10601
 
10598
10602
  const SelectCellComponent = (options, broker) => {
10599
10603
  const SelectCellComponent = ({ item, column, rowIndex }) => {
10600
- const { tableName } = useFormTableContext();
10604
+ const { tableName, editable } = useFormTableContext();
10601
10605
  const controller = useSelectController(options.dataSource, options);
10602
10606
  const service = controller.asService();
10603
10607
  // if the id is empty, it's a single table column and the value is the row itself
@@ -10610,7 +10614,7 @@ const SelectCellComponent = (options, broker) => {
10610
10614
  broker.removeSubscriber(name);
10611
10615
  };
10612
10616
  }, [name, service]);
10613
- return (React.createElement(Component, { size: "small", layout: "table", ...options, name: name, className: addClassname('o-table-select', className), controller: controller }));
10617
+ return (React.createElement(Component, { size: "small", layout: "table", ...options, name: name, className: addClassname('o-table-select', className), controller: controller, editable: editable ?? options.editable }));
10614
10618
  };
10615
10619
  SelectCellComponent.displayName = 'SelectCellComponent';
10616
10620
  return SelectCellComponent;
@@ -10643,7 +10647,7 @@ const selectColumn = (id, options) => {
10643
10647
  };
10644
10648
 
10645
10649
  const TextareaComponent = (props) => {
10646
- const { className, size = 'medium', status, onFocus: forwardFocus, onBlur: forwardBlur, ...textareaProps } = props;
10650
+ const { className, size = 'medium', status, onFocus: forwardFocus, onBlur: forwardBlur, onChange: forwardChange, value, ...textareaProps } = props;
10647
10651
  const [focus, setFocus] = React.useState(false);
10648
10652
  const classNames = addClassname(`o-textarea o-textarea-size-${size}${focus ? ' o-textarea-focus' : ''}${status ? ' o-textarea-status-' + status.toLowerCase() : ''}`, className);
10649
10653
  const onFocus = (e) => {
@@ -10654,8 +10658,20 @@ const TextareaComponent = (props) => {
10654
10658
  setFocus(false);
10655
10659
  forwardBlur && forwardBlur(e);
10656
10660
  };
10661
+ const ref = React.useRef(null);
10662
+ const selectorRef = React.useRef();
10663
+ const onChange = (e) => {
10664
+ selectorRef.current = e.target.selectionStart;
10665
+ forwardChange && forwardChange(e);
10666
+ };
10667
+ React.useEffect(() => {
10668
+ if (selectorRef.current !== undefined && selectorRef.current !== null && ref.current) {
10669
+ ref.current.setSelectionRange(selectorRef.current, selectorRef.current);
10670
+ selectorRef.current = undefined;
10671
+ }
10672
+ }, [value]);
10657
10673
  return (React.createElement("div", { className: classNames },
10658
- React.createElement("textarea", { className: "o-textarea-field", ...textareaProps, onFocus: onFocus, onBlur: onBlur })));
10674
+ React.createElement("textarea", { className: "o-textarea-field", ...textareaProps, ref: ref, onFocus: onFocus, onBlur: onBlur, onChange: value === undefined ? undefined : onChange, value: value })));
10659
10675
  };
10660
10676
  TextareaComponent.displayName = 'TextareaComponent';
10661
10677
 
@@ -10758,11 +10774,11 @@ FormTextarea.displayName = 'FormTextarea';
10758
10774
 
10759
10775
  const TextareaCellComponent = (options) => {
10760
10776
  const TextareaCellComponent = ({ item, column, rowIndex }) => {
10761
- const { tableName } = useFormTableContext();
10777
+ const { tableName, editable } = useFormTableContext();
10762
10778
  // if the id is empty, it's a single table column and the value is the row itself
10763
10779
  const name = column.id ? `${tableName}.${rowIndex}.${column.id}` : `${tableName}.${rowIndex}`;
10764
10780
  const className = typeof options.className === 'function' ? options.className(item, column, rowIndex) : options.className;
10765
- return (React.createElement(FormTextarea, { size: "small", layout: "table", ...options, name: name, className: addClassname('o-table-textarea', className) }));
10781
+ return (React.createElement(FormTextarea, { size: "small", layout: "table", ...options, name: name, className: addClassname('o-table-textarea', className), editable: editable ?? options.editable }));
10766
10782
  };
10767
10783
  TextareaCellComponent.displayName = 'TextareaCellComponent';
10768
10784
  return TextareaCellComponent;