@cratis/components 4.31.0 → 4.32.0

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 (42) hide show
  1. package/compat-manifest.json +11 -11
  2. package/dist/esm/Common/CratisComponentsProvider.d.ts +4 -0
  3. package/dist/esm/Common/CratisComponentsProvider.d.ts.map +1 -1
  4. package/dist/esm/Common/CratisComponentsProvider.js.map +1 -1
  5. package/dist/esm/DataPage/DataPage.d.ts +8 -0
  6. package/dist/esm/DataPage/DataPage.d.ts.map +1 -1
  7. package/dist/esm/DataPage/DataPage.js.map +1 -1
  8. package/dist/esm/DataTables/DataTableBody.d.ts +3 -1
  9. package/dist/esm/DataTables/DataTableBody.d.ts.map +1 -1
  10. package/dist/esm/DataTables/DataTableBody.js +2 -2
  11. package/dist/esm/DataTables/DataTableBody.js.map +1 -1
  12. package/dist/esm/DataTables/DataTableCore.d.ts +7 -1
  13. package/dist/esm/DataTables/DataTableCore.d.ts.map +1 -1
  14. package/dist/esm/DataTables/DataTableCore.js +8 -3
  15. package/dist/esm/DataTables/DataTableCore.js.map +1 -1
  16. package/dist/esm/DataTables/DataTableForObservableQuery.d.ts +8 -0
  17. package/dist/esm/DataTables/DataTableForObservableQuery.d.ts.map +1 -1
  18. package/dist/esm/DataTables/DataTableForObservableQuery.js +2 -2
  19. package/dist/esm/DataTables/DataTableForObservableQuery.js.map +1 -1
  20. package/dist/esm/DataTables/DataTableForQuery.d.ts +8 -0
  21. package/dist/esm/DataTables/DataTableForQuery.d.ts.map +1 -1
  22. package/dist/esm/DataTables/DataTableForQuery.js +2 -2
  23. package/dist/esm/DataTables/DataTableForQuery.js.map +1 -1
  24. package/dist/esm/DataTables/DataTableMessageOverrides.d.ts +1 -0
  25. package/dist/esm/DataTables/DataTableMessageOverrides.d.ts.map +1 -1
  26. package/dist/esm/DataTables/DataTableMessageOverrides.js.map +1 -1
  27. package/dist/esm/DataTables/DataTableMessages.d.ts +2 -0
  28. package/dist/esm/DataTables/DataTableMessages.d.ts.map +1 -1
  29. package/dist/esm/DataTables/DataTableMessages.js.map +1 -1
  30. package/dist/esm/DataTables/matchesFilterEntry.d.ts +7 -0
  31. package/dist/esm/DataTables/matchesFilterEntry.d.ts.map +1 -1
  32. package/dist/esm/DataTables/matchesFilterEntry.js +3 -1
  33. package/dist/esm/DataTables/matchesFilterEntry.js.map +1 -1
  34. package/dist/esm/DataTables/useDataTableMessages.d.ts +2 -1
  35. package/dist/esm/DataTables/useDataTableMessages.d.ts.map +1 -1
  36. package/dist/esm/DataTables/useDataTableMessages.js +6 -1
  37. package/dist/esm/DataTables/useDataTableMessages.js.map +1 -1
  38. package/dist/esm/DataTables/useServerQuery.d.ts +2 -1
  39. package/dist/esm/DataTables/useServerQuery.d.ts.map +1 -1
  40. package/dist/esm/DataTables/useServerQuery.js +2 -1
  41. package/dist/esm/DataTables/useServerQuery.js.map +1 -1
  42. package/package.json +1 -1
@@ -10,7 +10,7 @@ const toSorting = (sort, sortFields) => sort
10
10
  ? SortDirection.descending
11
11
  : SortDirection.ascending)
12
12
  : Sorting.none;
13
- const useServerQuery = (serverQuery, queryArguments, defaultFilters) => {
13
+ const useServerQuery = (serverQuery, queryArguments, defaultFilters, onGlobalFilterChange) => {
14
14
  const [sort, setSort] = useState(null);
15
15
  const [filters, setFilters] = useState(defaultFilters ?? {});
16
16
  const [searchText, setSearchText] = useState('');
@@ -43,6 +43,7 @@ const useServerQuery = (serverQuery, queryArguments, defaultFilters) => {
43
43
  },
44
44
  globalFilter: searchText,
45
45
  onGlobalFilterChange: (next) => {
46
+ onGlobalFilterChange?.(next);
46
47
  setSearchText(next);
47
48
  clearTimeout(searchTimerRef.current);
48
49
  const apply = () => {
@@ -1 +1 @@
1
- {"version":3,"file":"useServerQuery.js","sources":["../../../DataTables/useServerQuery.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useEffect, useRef, useState } from 'react';\nimport { SortDirection, Sorting } from '@cratis/arc/queries';\nimport type { DataTableCoreProps } from './DataTableCore';\nimport type { DataTableFilterMeta } from './DataTableFilterMeta';\nimport { DataTableRowProcessing } from './DataTableRowProcessing';\nimport {\n defaultServerQuerySearchDebounceMilliseconds,\n type DataTableServerQuery,\n} from './DataTableServerQuery';\nimport type { DataTableSort } from './DataTableSort';\nimport { DataTableSortDirection } from './DataTableSortDirection';\n\n/** The sorting and paging delegates of an Arc paging hook. */\nexport interface ServerQueryControls {\n setSorting: (sorting: Sorting) => unknown;\n setPage: (page: number) => unknown;\n}\n\n/** The table props that hand a table's sort, filter and search state to the server. */\nexport type ServerQueryTableProps = Pick<\n DataTableCoreProps<object>,\n | 'rowProcessing'\n | 'sort'\n | 'onSortChange'\n | 'filters'\n | 'onFilter'\n | 'globalFilter'\n | 'onGlobalFilterChange'\n>;\n\n/** What a bound table needs to run in server mode, or to run unchanged without it. */\nexport interface ServerQueryBinding<TArguments extends object> {\n /** The arguments to perform the query with. */\n queryArguments: TArguments | undefined;\n /**\n * Builds the table props that drive the query through the paging hook's delegates.\n * @param controls - The paging hook's sorting and paging delegates.\n * @returns No props without a server query, so the table keeps its loaded-page behavior.\n */\n tableProps(controls: ServerQueryControls): ServerQueryTableProps;\n}\n\nconst firstPage = 0;\n\nconst toSorting = (\n sort: DataTableSort | null,\n sortFields: Readonly<Record<string, string>> | undefined,\n): Sorting =>\n sort\n ? new Sorting(\n sortFields?.[sort.field] ?? sort.field,\n sort.direction === DataTableSortDirection.Descending\n ? SortDirection.descending\n : SortDirection.ascending,\n )\n : Sorting.none;\n\n/**\n * Keeps a bound table's sort, filter and search state for server mode and turns it into Arc sorting\n * and query arguments. Without a server query it passes the arguments through and adds no table props.\n * @param serverQuery - The server mode options, or undefined for loaded-page mode.\n * @param queryArguments - The arguments the table was given.\n * @param defaultFilters - The initial column filters.\n * @returns The arguments to query with and the table props for server mode.\n */\nexport const useServerQuery = <TArguments extends object>(\n serverQuery: DataTableServerQuery<TArguments> | undefined,\n queryArguments: TArguments | undefined,\n defaultFilters: DataTableFilterMeta | undefined,\n): ServerQueryBinding<TArguments> => {\n const [sort, setSort] = useState<DataTableSort | null>(null);\n const [filters, setFilters] = useState<DataTableFilterMeta>(defaultFilters ?? {});\n const [searchText, setSearchText] = useState('');\n const [appliedSearch, setAppliedSearch] = useState('');\n const appliedSearchRef = useRef('');\n const searchTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n useEffect(() => () => clearTimeout(searchTimerRef.current), []);\n\n if (!serverQuery) {\n return { queryArguments, tableProps: () => ({}) };\n }\n\n const debounceMilliseconds =\n serverQuery.searchDebounceMilliseconds ?? defaultServerQuerySearchDebounceMilliseconds;\n const serverArguments = {\n ...queryArguments,\n ...serverQuery.toArguments({ filters, globalFilter: appliedSearch }),\n } as TArguments;\n\n return {\n queryArguments: serverArguments,\n tableProps: ({ setSorting, setPage }) => ({\n rowProcessing: DataTableRowProcessing.None,\n sort,\n onSortChange: (next) => {\n setSort(next);\n setSorting(toSorting(next, serverQuery.sortFields));\n setPage(firstPage);\n },\n filters,\n onFilter: (next) => {\n setFilters(next);\n setPage(firstPage);\n },\n globalFilter: searchText,\n onGlobalFilterChange: (next) => {\n setSearchText(next);\n clearTimeout(searchTimerRef.current);\n const apply = () => {\n if (next === appliedSearchRef.current) return;\n appliedSearchRef.current = next;\n setAppliedSearch(next);\n setPage(firstPage);\n };\n if (debounceMilliseconds > 0) {\n searchTimerRef.current = setTimeout(apply, debounceMilliseconds);\n } else {\n apply();\n }\n },\n }),\n };\n};\n"],"names":[],"mappings":";;;;;;AA6CA,MAAM,SAAS,GAAG,CAAC;AAEnB,MAAM,SAAS,GAAG,CACd,IAA0B,EAC1B,UAAwD,KAExD;MACM,IAAI,OAAO,CACT,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,EACtC,IAAI,CAAC,SAAS,KAAK,sBAAsB,CAAC;UACpC,aAAa,CAAC;AACh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,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;gBACnD,OAAO,CAAC,SAAS,CAAC;YACtB,CAAC;YACD,OAAO;AACP,YAAA,QAAQ,EAAE,CAAC,IAAI,KAAI;gBACf,UAAU,CAAC,IAAI,CAAC;gBAChB,OAAO,CAAC,SAAS,CAAC;YACtB,CAAC;AACD,YAAA,YAAY,EAAE,UAAU;AACxB,YAAA,oBAAoB,EAAE,CAAC,IAAI,KAAI;gBAC3B,aAAa,CAAC,IAAI,CAAC;AACnB,gBAAA,YAAY,CAAC,cAAc,CAAC,OAAO,CAAC;gBACpC,MAAM,KAAK,GAAG,MAAK;AACf,oBAAA,IAAI,IAAI,KAAK,gBAAgB,CAAC,OAAO;wBAAE;AACvC,oBAAA,gBAAgB,CAAC,OAAO,GAAG,IAAI;oBAC/B,gBAAgB,CAAC,IAAI,CAAC;oBACtB,OAAO,CAAC,SAAS,CAAC;AACtB,gBAAA,CAAC;AACD,gBAAA,IAAI,oBAAoB,GAAG,CAAC,EAAE;oBAC1B,cAAc,CAAC,OAAO,GAAG,UAAU,CAAC,KAAK,EAAE,oBAAoB,CAAC;gBACpE;qBAAO;AACH,oBAAA,KAAK,EAAE;gBACX;YACJ,CAAC;SACJ,CAAC;KACL;AACL;;"}
1
+ {"version":3,"file":"useServerQuery.js","sources":["../../../DataTables/useServerQuery.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useEffect, useRef, useState } from 'react';\nimport { SortDirection, Sorting } from '@cratis/arc/queries';\nimport type { DataTableCoreProps } from './DataTableCore';\nimport type { DataTableFilterMeta } from './DataTableFilterMeta';\nimport { DataTableRowProcessing } from './DataTableRowProcessing';\nimport {\n defaultServerQuerySearchDebounceMilliseconds,\n type DataTableServerQuery,\n} from './DataTableServerQuery';\nimport type { DataTableSort } from './DataTableSort';\nimport { DataTableSortDirection } from './DataTableSortDirection';\n\n/** The sorting and paging delegates of an Arc paging hook. */\nexport interface ServerQueryControls {\n setSorting: (sorting: Sorting) => unknown;\n setPage: (page: number) => unknown;\n}\n\n/** The table props that hand a table's sort, filter and search state to the server. */\nexport type ServerQueryTableProps = Pick<\n DataTableCoreProps<object>,\n | 'rowProcessing'\n | 'sort'\n | 'onSortChange'\n | 'filters'\n | 'onFilter'\n | 'globalFilter'\n | 'onGlobalFilterChange'\n>;\n\n/** What a bound table needs to run in server mode, or to run unchanged without it. */\nexport interface ServerQueryBinding<TArguments extends object> {\n /** The arguments to perform the query with. */\n queryArguments: TArguments | undefined;\n /**\n * Builds the table props that drive the query through the paging hook's delegates.\n * @param controls - The paging hook's sorting and paging delegates.\n * @returns No props without a server query, so the table keeps its loaded-page behavior.\n */\n tableProps(controls: ServerQueryControls): ServerQueryTableProps;\n}\n\nconst firstPage = 0;\n\nconst toSorting = (\n sort: DataTableSort | null,\n sortFields: Readonly<Record<string, string>> | undefined,\n): Sorting =>\n sort\n ? new Sorting(\n sortFields?.[sort.field] ?? sort.field,\n sort.direction === DataTableSortDirection.Descending\n ? SortDirection.descending\n : SortDirection.ascending,\n )\n : Sorting.none;\n\n/**\n * Keeps a bound table's sort, filter and search state for server mode and turns it into Arc sorting\n * and query arguments. Without a server query it passes the arguments through and adds no table props.\n * @param serverQuery - The server mode options, or undefined for loaded-page mode.\n * @param queryArguments - The arguments the table was given.\n * @param defaultFilters - The initial column filters.\n * @param onGlobalFilterChange - Notified of every search text change, as typed.\n * @returns The arguments to query with and the table props for server mode.\n */\nexport const useServerQuery = <TArguments extends object>(\n serverQuery: DataTableServerQuery<TArguments> | undefined,\n queryArguments: TArguments | undefined,\n defaultFilters: DataTableFilterMeta | undefined,\n onGlobalFilterChange?: (globalFilter: string) => void,\n): ServerQueryBinding<TArguments> => {\n const [sort, setSort] = useState<DataTableSort | null>(null);\n const [filters, setFilters] = useState<DataTableFilterMeta>(defaultFilters ?? {});\n const [searchText, setSearchText] = useState('');\n const [appliedSearch, setAppliedSearch] = useState('');\n const appliedSearchRef = useRef('');\n const searchTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n useEffect(() => () => clearTimeout(searchTimerRef.current), []);\n\n if (!serverQuery) {\n return { queryArguments, tableProps: () => ({}) };\n }\n\n const debounceMilliseconds =\n serverQuery.searchDebounceMilliseconds ?? defaultServerQuerySearchDebounceMilliseconds;\n const serverArguments = {\n ...queryArguments,\n ...serverQuery.toArguments({ filters, globalFilter: appliedSearch }),\n } as TArguments;\n\n return {\n queryArguments: serverArguments,\n tableProps: ({ setSorting, setPage }) => ({\n rowProcessing: DataTableRowProcessing.None,\n sort,\n onSortChange: (next) => {\n setSort(next);\n setSorting(toSorting(next, serverQuery.sortFields));\n setPage(firstPage);\n },\n filters,\n onFilter: (next) => {\n setFilters(next);\n setPage(firstPage);\n },\n globalFilter: searchText,\n onGlobalFilterChange: (next) => {\n onGlobalFilterChange?.(next);\n setSearchText(next);\n clearTimeout(searchTimerRef.current);\n const apply = () => {\n if (next === appliedSearchRef.current) return;\n appliedSearchRef.current = next;\n setAppliedSearch(next);\n setPage(firstPage);\n };\n if (debounceMilliseconds > 0) {\n searchTimerRef.current = setTimeout(apply, debounceMilliseconds);\n } else {\n apply();\n }\n },\n }),\n };\n};\n"],"names":[],"mappings":";;;;;;AA6CA,MAAM,SAAS,GAAG,CAAC;AAEnB,MAAM,SAAS,GAAG,CACd,IAA0B,EAC1B,UAAwD,KAExD;MACM,IAAI,OAAO,CACT,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,EACtC,IAAI,CAAC,SAAS,KAAK,sBAAsB,CAAC;UACpC,aAAa,CAAC;AAChB,UAAE,aAAa,CAAC,SAAS;AAEjC,MAAE,OAAO,CAAC,IAAI;AAWf,MAAM,cAAc,GAAG,CAC1B,WAAyD,EACzD,cAAsC,EACtC,cAA+C,EAC/C,oBAAqD,KACrB;IAChC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAuB,IAA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;YACtB,CAAC;AACD,YAAA,YAAY,EAAE,UAAU;AACxB,YAAA,oBAAoB,EAAE,CAAC,IAAI,KAAI;AAC3B,gBAAA,oBAAoB,GAAG,IAAI,CAAC;gBAC5B,aAAa,CAAC,IAAI,CAAC;AACnB,gBAAA,YAAY,CAAC,cAAc,CAAC,OAAO,CAAC;gBACpC,MAAM,KAAK,GAAG,MAAK;AACf,oBAAA,IAAI,IAAI,KAAK,gBAAgB,CAAC,OAAO;wBAAE;AACvC,oBAAA,gBAAgB,CAAC,OAAO,GAAG,IAAI;oBAC/B,gBAAgB,CAAC,IAAI,CAAC;oBACtB,OAAO,CAAC,SAAS,CAAC;AACtB,gBAAA,CAAC;AACD,gBAAA,IAAI,oBAAoB,GAAG,CAAC,EAAE;oBAC1B,cAAc,CAAC,OAAO,GAAG,UAAU,CAAC,KAAK,EAAE,oBAAoB,CAAC;gBACpE;qBAAO;AACH,oBAAA,KAAK,EAAE;gBACX;YACJ,CAAC;SACJ,CAAC;KACL;AACL;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/components",
3
- "version": "4.31.0",
3
+ "version": "4.32.0",
4
4
  "description": "React components for CQRS and event-sourced apps — command dialogs, typed forms, and query-backed data tables for Cratis Arc",
5
5
  "keywords": [
6
6
  "react",