@apia/api 4.0.19 → 4.0.20

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/dist/index.d.ts CHANGED
@@ -319,6 +319,7 @@ declare class Filter {
319
319
  }
320
320
 
321
321
  type TableControllerState = {
322
+ finishedLoading: boolean;
322
323
  columns: Map<string, TResponsiveTableColumn>;
323
324
  filters: Map<string | number, Filter>;
324
325
  pagination: {
@@ -381,9 +382,12 @@ declare class TableController {
381
382
  constructor(initialState?: Partial<TableControllerState>);
382
383
  clearFilters(): void;
383
384
  private parseFilters;
384
- Context: ({ children }: {
385
+ Context: (({ children }: {
385
386
  children: React.ReactNode;
386
- }) => react.JSX.Element;
387
+ }) => react.JSX.Element) & {
388
+ displayName: string;
389
+ };
390
+ private TableContext;
387
391
  getTableName(): string;
388
392
  Pagination: (() => react.JSX.Element) & {
389
393
  displayName: string;
@@ -486,5 +490,25 @@ declare class ApiaMonDocModal extends QueryModalController {
486
490
  }
487
491
  declare const ApiaMonDocModal2: ApiaMonDocModal;
488
492
 
489
- export { ApiaApi, ApiaApiHandler, ApiaMonDocModal2, ApiaPoolsModals2, ApiaUsersModal2, type IApiaApiRequestConfig, QueryController, type QueryControllerStructure, QueryModalController, type TApiaApiAxiosResponse, type TApiaApiMethod, type TApiaApiResult, type TFilter, getFunction, getModal, isHtmlResponse, isXmlResponse, makeApiaUrl, parseSuccessfulResponse };
493
+ declare class GenericListQuery extends QueryController {
494
+ ajaxUrl: string;
495
+ constructor(ajaxUrl: string);
496
+ getTableControllerDefaultProps(): {
497
+ isMultiple: boolean;
498
+ };
499
+ protected getLoadStructureParameters(): {
500
+ action: string;
501
+ };
502
+ protected getRefreshParameters(): Record<string, unknown>;
503
+ protected getSortParameters(): Record<string, unknown>;
504
+ protected getFilterParameters(): Record<string, unknown>;
505
+ protected getFiltersValuesMap(): Record<string, unknown>;
506
+ protected filter(): Promise<void>;
507
+ protected parseLoadStructureResponse(response: any): QueryControllerStructure;
508
+ initialLoad(): Promise<void>;
509
+ refresh(): Promise<void>;
510
+ sort(column: string): Promise<void>;
511
+ }
512
+
513
+ export { ApiaApi, ApiaApiHandler, ApiaMonDocModal2, ApiaPoolsModals2, ApiaUsersModal2, GenericListQuery, type IApiaApiRequestConfig, QueryController, type QueryControllerStructure, QueryModalController, type TApiaApiAxiosResponse, type TApiaApiMethod, type TApiaApiResult, type TFilter, getFunction, getModal, isHtmlResponse, isXmlResponse, makeApiaUrl, parseSuccessfulResponse };
490
514
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx, jsxs, Fragment } from '@apia/theme/jsx-runtime';
2
2
  import * as React from 'react';
3
- import React__default, { createContext, useState, useCallback, useEffect, useId } from 'react';
3
+ import React__default, { createContext, useState, useCallback, useEffect, useId, memo } from 'react';
4
4
  import { Box, Label, spacing, getVariant, Input as Input$1, Select as Select$1 } from '@apia/theme';
5
5
  import { debugDispatcher, parseXmlAsync, EventEmitter, arrayOrArray, useMount, encrypt, noNaN, getIndex, getLabel, StatefulEmitter, focus, focusSelector, useLatest } from '@apia/util';
6
6
  import { notify, getNotificationMessageObj, dispatchNotifications } from '@apia/notifications';
@@ -11,8 +11,8 @@ import merge from 'lodash-es/merge';
11
11
  import QueryString from 'qs';
12
12
  import { session } from '@apia/session';
13
13
  import uniqueId from 'lodash-es/uniqueId';
14
- import { ResponsiveTableContext, ResponsiveTable, Pagination, Sort, Responsive, Additional, responsiveTableStore, useResponsiveTableContext, getResponsiveTableContext, makeController2, responsiveTableActions, TableContextReproducer } from '@apia/table';
15
- import { makeObservable, observable, reaction, action, toJS } from 'mobx';
14
+ import { ResponsiveTableContext, ResponsiveTable, Pagination, Sort, Responsive, Additional, responsiveTableStore, useResponsiveTableContext, getResponsiveTableContext, TableLoadingContext, makeController2, responsiveTableActions, TableContextReproducer } from '@apia/table';
15
+ import { makeObservable, observable, reaction, toJS, action } from 'mobx';
16
16
  import { observer } from 'mobx-react-lite';
17
17
  import { throttle } from 'lodash-es';
18
18
  import { Icon } from '@apia/icons';
@@ -3025,7 +3025,7 @@ const ApiaApiHandlerNonMemoized = () => {
3025
3025
  "a,input,textarea,button"
3026
3026
  );
3027
3027
  if (elements?.length === 1)
3028
- void focus.on([...elements][0]);
3028
+ void focus?.on([...elements][0]);
3029
3029
  });
3030
3030
  const setError = React.useCallback(
3031
3031
  (notification) => {
@@ -3310,26 +3310,26 @@ const InputFilterRenderer = observer(
3310
3310
  }
3311
3311
  );
3312
3312
 
3313
- var __defProp$7 = Object.defineProperty;
3314
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3315
- var __publicField$7 = (obj, key, value) => {
3316
- __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
3313
+ var __defProp$6 = Object.defineProperty;
3314
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3315
+ var __publicField$6 = (obj, key, value) => {
3316
+ __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
3317
3317
  return value;
3318
3318
  };
3319
3319
  class Filter {
3320
3320
  constructor(properties) {
3321
- __publicField$7(this, "tableName");
3322
- __publicField$7(this, "filterState", {
3321
+ __publicField$6(this, "tableName");
3322
+ __publicField$6(this, "filterState", {
3323
3323
  runAutomatically: false,
3324
3324
  value: ""
3325
3325
  });
3326
- __publicField$7(this, "Component", observer(({ filter }) => {
3326
+ __publicField$6(this, "Component", observer(({ filter }) => {
3327
3327
  const { name } = useResponsiveTableContext();
3328
3328
  this.tableName = name;
3329
3329
  if (this.filterState.isRange) {
3330
3330
  return this.getRangeRenderer({ filter });
3331
3331
  }
3332
- if (this.filterState.options) {
3332
+ if (arrayOrArray(this.filterState.options).length > 0) {
3333
3333
  return this.getSelectRenderer({ filter });
3334
3334
  }
3335
3335
  return this.getInputRenderer({ filter });
@@ -3391,16 +3391,16 @@ const FilterTypesComponent = observer(
3391
3391
  }
3392
3392
  );
3393
3393
 
3394
- var __defProp$6 = Object.defineProperty;
3395
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3396
- var __publicField$6 = (obj, key, value) => {
3397
- __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
3394
+ var __defProp$5 = Object.defineProperty;
3395
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3396
+ var __publicField$5 = (obj, key, value) => {
3397
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
3398
3398
  return value;
3399
3399
  };
3400
3400
  class FilterTypes {
3401
3401
  constructor() {
3402
- __publicField$6(this, "conditions", []);
3403
- __publicField$6(this, "Component", () => /* @__PURE__ */ jsx(FilterTypesComponent, { filterTypes: this }));
3402
+ __publicField$5(this, "conditions", []);
3403
+ __publicField$5(this, "Component", () => /* @__PURE__ */ jsx(FilterTypesComponent, { filterTypes: this }));
3404
3404
  makeObservable(this, {
3405
3405
  conditions: observable
3406
3406
  });
@@ -3438,28 +3438,38 @@ class FilterTypes {
3438
3438
  }
3439
3439
  }
3440
3440
 
3441
- var __defProp$5 = Object.defineProperty;
3442
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3443
- var __publicField$5 = (obj, key, value) => {
3444
- __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
3441
+ var __defProp$4 = Object.defineProperty;
3442
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3443
+ var __publicField$4 = (obj, key, value) => {
3444
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
3445
3445
  return value;
3446
3446
  };
3447
3447
  let controllerCount = 0;
3448
3448
  class TableController {
3449
3449
  constructor(initialState) {
3450
- __publicField$5(this, "emitter", new EventEmitter());
3451
- __publicField$5(this, "tableName", `TableController${controllerCount++}`);
3452
- __publicField$5(this, "tableSelectionController");
3453
- __publicField$5(this, "controllerComponent", () => null);
3454
- __publicField$5(this, "filterTypes", new FilterTypes());
3455
- __publicField$5(this, "state", {
3450
+ __publicField$4(this, "emitter", new EventEmitter());
3451
+ __publicField$4(this, "tableName", `TableController${controllerCount++}`);
3452
+ __publicField$4(this, "tableSelectionController");
3453
+ __publicField$4(this, "controllerComponent", () => null);
3454
+ __publicField$4(this, "filterTypes", new FilterTypes());
3455
+ __publicField$4(this, "state", {
3456
+ finishedLoading: false,
3456
3457
  columns: /* @__PURE__ */ new Map(),
3457
3458
  filters: /* @__PURE__ */ new Map(),
3458
3459
  pagination: { currentPage: 0, totalPages: 0, totalRecords: 0 },
3459
3460
  props: {},
3460
3461
  rows: []
3461
3462
  });
3462
- __publicField$5(this, "Context", ({ children }) => {
3463
+ __publicField$4(this, "Context", observer(({ children }) => {
3464
+ return /* @__PURE__ */ jsx(
3465
+ TableLoadingContext.Provider,
3466
+ {
3467
+ value: { current: this.state.finishedLoading },
3468
+ children: /* @__PURE__ */ jsx(this.TableContext, { children })
3469
+ }
3470
+ );
3471
+ }));
3472
+ __publicField$4(this, "TableContext", memo(({ children }) => {
3463
3473
  const state = this.state;
3464
3474
  const props = toJS(state.props);
3465
3475
  return /* @__PURE__ */ jsx(
@@ -3491,8 +3501,8 @@ class TableController {
3491
3501
  children
3492
3502
  }
3493
3503
  );
3494
- });
3495
- __publicField$5(this, "Pagination", observer(() => {
3504
+ }));
3505
+ __publicField$4(this, "Pagination", observer(() => {
3496
3506
  return /* @__PURE__ */ jsx(
3497
3507
  Pagination,
3498
3508
  {
@@ -3504,7 +3514,7 @@ class TableController {
3504
3514
  }
3505
3515
  );
3506
3516
  }));
3507
- __publicField$5(this, "Table", ResponsiveTable);
3517
+ __publicField$4(this, "Table", ResponsiveTable);
3508
3518
  makeObservable(this, {
3509
3519
  state: observable,
3510
3520
  updateState: action
@@ -3579,23 +3589,28 @@ class TableController {
3579
3589
  }
3580
3590
  }
3581
3591
 
3582
- var __defProp$4 = Object.defineProperty;
3583
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3584
- var __publicField$4 = (obj, key, value) => {
3585
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
3592
+ var __defProp$3 = Object.defineProperty;
3593
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3594
+ var __publicField$3 = (obj, key, value) => {
3595
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
3586
3596
  return value;
3587
3597
  };
3598
+ function unescapeHtml(html) {
3599
+ const tmp = document.createElement("textarea");
3600
+ tmp.innerHTML = html;
3601
+ return tmp.value;
3602
+ }
3588
3603
  class QueryController {
3589
3604
  constructor(ajaxUrl) {
3590
3605
  this.ajaxUrl = ajaxUrl;
3591
- __publicField$4(this, "hasInited", false);
3592
- __publicField$4(this, "initializing", false);
3593
- __publicField$4(this, "structure", null);
3594
- __publicField$4(this, "tableController");
3606
+ __publicField$3(this, "hasInited", false);
3607
+ __publicField$3(this, "initializing", false);
3608
+ __publicField$3(this, "structure", null);
3609
+ __publicField$3(this, "tableController");
3595
3610
  /**
3596
3611
  * Allows to throttle calls to actual refresh method.
3597
3612
  */
3598
- __publicField$4(this, "executeRefresh", throttle(
3613
+ __publicField$3(this, "executeRefresh", throttle(
3599
3614
  async () => {
3600
3615
  await this.actualRefreshMethod();
3601
3616
  },
@@ -3760,7 +3775,9 @@ class QueryController {
3760
3775
  cells: [
3761
3776
  columns.find((c) => c.showAsAdditional) ? {} : void 0,
3762
3777
  ...columns.filter((c) => c.hidden).map(() => ({})),
3763
- ...arrayOrArray(r.cell).map((c) => ({ children: c }))
3778
+ ...arrayOrArray(r.cell).map((c) => ({
3779
+ children: typeof c === "string" ? unescapeHtml(c) : c
3780
+ }))
3764
3781
  ].filter(Boolean),
3765
3782
  className: r.classToAdd,
3766
3783
  id: r.id
@@ -3921,16 +3938,16 @@ const AdditionalFiltersComponent = ({
3921
3938
  ] }) });
3922
3939
  };
3923
3940
 
3924
- var __defProp$3 = Object.defineProperty;
3925
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3926
- var __publicField$3 = (obj, key, value) => {
3927
- __defNormalProp$3(obj, key + "" , value);
3941
+ var __defProp$2 = Object.defineProperty;
3942
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3943
+ var __publicField$2 = (obj, key, value) => {
3944
+ __defNormalProp$2(obj, key + "" , value);
3928
3945
  return value;
3929
3946
  };
3930
3947
  class AdditionalFiltersModal {
3931
3948
  constructor(queryController) {
3932
3949
  this.queryController = queryController;
3933
- __publicField$3(this, "modalHandler", null);
3950
+ __publicField$2(this, "modalHandler", null);
3934
3951
  }
3935
3952
  getModalDefinition() {
3936
3953
  return {
@@ -3985,19 +4002,19 @@ class AdditionalFiltersModal {
3985
4002
  }
3986
4003
  }
3987
4004
 
3988
- var __defProp$2 = Object.defineProperty;
3989
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3990
- var __publicField$2 = (obj, key, value) => {
3991
- __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
4005
+ var __defProp$1 = Object.defineProperty;
4006
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4007
+ var __publicField$1 = (obj, key, value) => {
4008
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
3992
4009
  return value;
3993
4010
  };
3994
4011
  class QueryModalController {
3995
4012
  constructor(queryController) {
3996
- __publicField$2(this, "emitter", new EventEmitter());
3997
- __publicField$2(this, "queryController");
3998
- __publicField$2(this, "modalHandler", null);
3999
- __publicField$2(this, "currentSelection", null);
4000
- __publicField$2(this, "additionalFiltersController");
4013
+ __publicField$1(this, "emitter", new EventEmitter());
4014
+ __publicField$1(this, "queryController");
4015
+ __publicField$1(this, "modalHandler", null);
4016
+ __publicField$1(this, "currentSelection", null);
4017
+ __publicField$1(this, "additionalFiltersController");
4001
4018
  if (!queryController) {
4002
4019
  throw new Error("QueryController instance is required");
4003
4020
  }
@@ -4078,11 +4095,11 @@ class QueryModalController {
4078
4095
  return this.emitter.on(ev, cb);
4079
4096
  }
4080
4097
  async openModal(properties) {
4081
- await this.queryController.initialLoad();
4082
4098
  this.modalHandler = ApiaUtil.instance.modals.open({
4083
4099
  ...this.getModalDefinition(),
4084
4100
  ...properties
4085
4101
  });
4102
+ await this.queryController.initialLoad();
4086
4103
  return this.onConfirmResolve();
4087
4104
  }
4088
4105
  getModalHandler() {
@@ -4110,19 +4127,16 @@ class QueryModalController {
4110
4127
  }
4111
4128
  }
4112
4129
 
4113
- var __defProp$1 = Object.defineProperty;
4114
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4115
- var __publicField$1 = (obj, key, value) => {
4116
- __defNormalProp$1(obj, key + "" , value);
4117
- return value;
4118
- };
4119
4130
  class GenericListQuery extends QueryController {
4120
4131
  constructor(ajaxUrl) {
4121
4132
  super(ajaxUrl);
4122
4133
  this.ajaxUrl = ajaxUrl;
4123
- __publicField$1(this, "tableController", new TableController({
4124
- props: { isMultiple: true }
4125
- }));
4134
+ }
4135
+ getTableControllerDefaultProps() {
4136
+ return {
4137
+ ...super.getTableControllerDefaultProps(),
4138
+ isMultiple: true
4139
+ };
4126
4140
  }
4127
4141
  getLoadStructureParameters() {
4128
4142
  return { ...super.getLoadStructureParameters(), action: "filter" };
@@ -4217,6 +4231,9 @@ class GenericListQuery extends QueryController {
4217
4231
  return returnObject;
4218
4232
  }
4219
4233
  async initialLoad() {
4234
+ this.tableController.updateState({
4235
+ props: this.getTableControllerDefaultProps()
4236
+ });
4220
4237
  await this.refresh();
4221
4238
  }
4222
4239
  async refresh() {
@@ -4436,5 +4453,5 @@ class ApiaMonDocModal extends QueryModalController {
4436
4453
  }
4437
4454
  const ApiaMonDocModal2 = new ApiaMonDocModal();
4438
4455
 
4439
- export { ApiaApi, ApiaApiHandler, ApiaMonDocModal2, ApiaPoolsModals2, ApiaUsersModal2, QueryController, QueryModalController, getFunction, getModal, isHtmlResponse, isXmlResponse, makeApiaUrl, parseSuccessfulResponse };
4456
+ export { ApiaApi, ApiaApiHandler, ApiaMonDocModal2, ApiaPoolsModals2, ApiaUsersModal2, GenericListQuery, QueryController, QueryModalController, getFunction, getModal, isHtmlResponse, isXmlResponse, makeApiaUrl, parseSuccessfulResponse };
4440
4457
  //# sourceMappingURL=index.js.map