@economic/taco 2.44.5-create.7 → 2.44.5-create.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. package/dist/components/Provider/Localization.d.ts +2 -0
  2. package/dist/components/Report/Report.d.ts +1 -1
  3. package/dist/components/Table3/Table3.d.ts +2 -14
  4. package/dist/components/Table3/components/Columns/Internal/EditingActionsMenu.d.ts +1 -2
  5. package/dist/components/Table3/components/Editing/DiscardChangesConfirmationDialog.d.ts +7 -0
  6. package/dist/components/Table3/components/Row/Editing/CreateNewRow.d.ts +13 -0
  7. package/dist/components/Table3/components/Row/Editing/TemporaryRow.d.ts +11 -0
  8. package/dist/components/Table3/features/useEditingState.d.ts +28 -0
  9. package/dist/components/Table3/features/useTableEditing.d.ts +25 -36
  10. package/dist/components/Table3/types.d.ts +23 -8
  11. package/dist/components/Table3/useTable3.d.ts +6 -0
  12. package/dist/components/Table3/util/editing.d.ts +2 -1
  13. package/dist/esm/index.css +16 -4
  14. package/dist/esm/packages/taco/src/components/ModeSwitch/ModeSwitch.js +2 -2
  15. package/dist/esm/packages/taco/src/components/ModeSwitch/ModeSwitch.js.map +1 -1
  16. package/dist/esm/packages/taco/src/components/Provider/Localization.js +5 -3
  17. package/dist/esm/packages/taco/src/components/Provider/Localization.js.map +1 -1
  18. package/dist/esm/packages/taco/src/components/Switch/Switch.js +1 -1
  19. package/dist/esm/packages/taco/src/components/Switch/Switch.js.map +1 -1
  20. package/dist/esm/packages/taco/src/components/Table3/Table3.js +19 -7
  21. package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
  22. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js +27 -23
  23. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js.map +1 -1
  24. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Internal/EditingActionsMenu.js +5 -37
  25. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Internal/EditingActionsMenu.js.map +1 -1
  26. package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js +17 -12
  27. package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js.map +1 -1
  28. package/dist/esm/packages/taco/src/components/Table3/components/Editing/DiscardChangesConfirmationDialog.js +34 -0
  29. package/dist/esm/packages/taco/src/components/Table3/components/Editing/DiscardChangesConfirmationDialog.js.map +1 -0
  30. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js +89 -0
  31. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js.map +1 -0
  32. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/SaveStatus.js +2 -14
  33. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/SaveStatus.js.map +1 -1
  34. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js +95 -0
  35. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js.map +1 -0
  36. package/dist/esm/packages/taco/src/components/Table3/components/Row/Row.js +39 -6
  37. package/dist/esm/packages/taco/src/components/Table3/components/Row/Row.js.map +1 -1
  38. package/dist/esm/packages/taco/src/components/Table3/components/Toolbar/Editing/Editing.js +7 -2
  39. package/dist/esm/packages/taco/src/components/Table3/components/Toolbar/Editing/Editing.js.map +1 -1
  40. package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js +512 -0
  41. package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js.map +1 -0
  42. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js +19 -406
  43. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js.map +1 -1
  44. package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js +37 -32
  45. package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js.map +1 -1
  46. package/dist/esm/packages/taco/src/components/Table3/useTable3.js +25 -8
  47. package/dist/esm/packages/taco/src/components/Table3/useTable3.js.map +1 -1
  48. package/dist/esm/packages/taco/src/components/Table3/util/editing.js +6 -23
  49. package/dist/esm/packages/taco/src/components/Table3/util/editing.js.map +1 -1
  50. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js +3 -4
  51. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js.map +1 -1
  52. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Cell/BuiltIns/GroupedCell.js +9 -3
  53. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Cell/BuiltIns/GroupedCell.js.map +1 -1
  54. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Actions.js +6 -3
  55. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Actions.js.map +1 -1
  56. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Footer.js +1 -1
  57. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Footer.js.map +1 -1
  58. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/DisplayRow.js +1 -1
  59. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/DisplayRow.js.map +1 -1
  60. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterValue.js +1 -8
  61. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterValue.js.map +1 -1
  62. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js +24 -6
  63. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js.map +1 -1
  64. package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js +2 -2
  65. package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js.map +1 -1
  66. package/dist/esm/packages/taco/src/primitives/Table/types.js.map +1 -1
  67. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js +1 -1
  68. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js.map +1 -1
  69. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js +11 -0
  70. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js.map +1 -1
  71. package/dist/esm/packages/taco/src/utils/dom.js +7 -4
  72. package/dist/esm/packages/taco/src/utils/dom.js.map +1 -1
  73. package/dist/index.css +16 -4
  74. package/dist/primitives/Table/Core/Table.d.ts +1 -0
  75. package/dist/primitives/Table/Core/components/Columns/Internal/Actions.d.ts +3 -1
  76. package/dist/primitives/Table/Core/components/Footer/Footer.d.ts +2 -2
  77. package/dist/primitives/Table/Core/features/useTableRenderer.d.ts +2 -2
  78. package/dist/primitives/Table/Core/features/useTableStyle.d.ts +1 -1
  79. package/dist/primitives/Table/Core/types.d.ts +3 -0
  80. package/dist/primitives/Table/Core/useTable.d.ts +2 -2
  81. package/dist/primitives/Table/types.d.ts +2 -2
  82. package/dist/primitives/Table/useTableManager/useTableManager.d.ts +1 -1
  83. package/dist/taco.cjs.development.js +914 -627
  84. package/dist/taco.cjs.development.js.map +1 -1
  85. package/dist/taco.cjs.production.min.js +1 -1
  86. package/dist/taco.cjs.production.min.js.map +1 -1
  87. package/dist/utils/dom.d.ts +1 -0
  88. package/package.json +1 -1
  89. package/dist/components/Table3/components/Row/Editing/CreateRowButton.d.ts +0 -11
  90. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateRowButton.js +0 -90
  91. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateRowButton.js.map +0 -1
@@ -0,0 +1,89 @@
1
+ import React__default from 'react';
2
+ import { Icon } from '../../../../Icon/Icon.js';
3
+ import { useLocalization } from '../../../../Provider/Localization.js';
4
+ import { Button } from '../../../../Button/Button.js';
5
+
6
+ function CreateNewRow(props) {
7
+ var _temporaryRows$0$tabl, _temporaryRows$, _table$getState$colum;
8
+ const {
9
+ buttonRef,
10
+ onEditingCreate: handleEditingCreate,
11
+ table,
12
+ tableMeta
13
+ } = props;
14
+ const {
15
+ texts
16
+ } = useLocalization();
17
+ const temporaryRows = tableMeta.editing.temporaryRows;
18
+ const temporaryRowId = (_temporaryRows$0$tabl = (_temporaryRows$ = temporaryRows[0]) === null || _temporaryRows$ === void 0 ? void 0 : _temporaryRows$[tableMeta.rowIdentityAccessor]) !== null && _temporaryRows$0$tabl !== void 0 ? _temporaryRows$0$tabl : '';
19
+ const isDisabled = !!table.getState().globalFilter || !!((_table$getState$colum = table.getState().columnFilters) !== null && _table$getState$colum !== void 0 && _table$getState$colum.length) || !!temporaryRowId && !!tableMeta.editing.hasRowErrors(temporaryRowId);
20
+ const isSaving = !!temporaryRowId && tableMeta.editing.getRowStatus(temporaryRowId) === 'saving';
21
+ const handleCreate = function (event) {
22
+ try {
23
+ // prevent save being triggered by click outside - TODO: investigate why the button triggers clickoutside
24
+ event === null || event === void 0 ? void 0 : event.stopPropagation();
25
+ if (!handleEditingCreate || isDisabled) {
26
+ return Promise.resolve();
27
+ }
28
+ return Promise.resolve(tableMeta.editing.saveChanges(table)).then(function (saved) {
29
+ if (!saved) {
30
+ return;
31
+ }
32
+ try {
33
+ const changeset = handleEditingCreate();
34
+ if (changeset) {
35
+ const nextRowIndex = temporaryRows.length ? tableMeta.length + 1 : tableMeta.length;
36
+ // change the row before reating because it triggers a save
37
+ // saving would trigger the validation flow and immediately make the row red
38
+ tableMeta.rowActive.setRowActiveIndex(nextRowIndex);
39
+ requestAnimationFrame(function () {
40
+ try {
41
+ tableMeta.editing.toggleEditing(true, table);
42
+ return Promise.resolve(tableMeta.editing.createRow(changeset)).then(function (rowId) {
43
+ tableMeta.editing.setLastFocusedCellIndex(0);
44
+ try {
45
+ const row = table.getRow(rowId);
46
+ row.pin('bottom');
47
+ } catch {
48
+ //
49
+ }
50
+ });
51
+ } catch (e) {
52
+ return Promise.reject(e);
53
+ }
54
+ });
55
+ }
56
+ } catch (error) {
57
+ console.error(error);
58
+ }
59
+ });
60
+ } catch (e) {
61
+ return Promise.reject(e);
62
+ }
63
+ };
64
+ let tooltip;
65
+ if (isSaving) {
66
+ tooltip = texts.table3.editing.buttons.create.saving;
67
+ } else if (isDisabled) {
68
+ tooltip = texts.table3.editing.buttons.create.disabled;
69
+ }
70
+ return /*#__PURE__*/React__default.createElement("tr", {
71
+ "data-row-create": true,
72
+ className: "border-grey-300 group/row",
73
+ tabIndex: -1
74
+ }, /*#__PURE__*/React__default.createElement("td", {
75
+ className: "!bg-grey-50 col-span-full !border-b-0 !px-1"
76
+ }, /*#__PURE__*/React__default.createElement(Button, {
77
+ appearance: "transparent",
78
+ className: "group-hover:bg-grey-200 sticky left-[4px]",
79
+ disabled: isDisabled,
80
+ onClick: handleCreate,
81
+ ref: buttonRef,
82
+ tooltip: tooltip
83
+ }, /*#__PURE__*/React__default.createElement(Icon, {
84
+ name: "circle-plus"
85
+ }), texts.table3.editing.buttons.create.label)));
86
+ }
87
+
88
+ export { CreateNewRow };
89
+ //# sourceMappingURL=CreateNewRow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CreateNewRow.js","sources":["../../../../../../../../../../src/components/Table3/components/Row/Editing/CreateNewRow.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { Button } from '../../../../Button/Button';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { Icon } from '../../../../Icon/Icon';\nimport { Table3EditingCreateHandler } from '../../../types';\nimport { TableRef } from '../../../../../primitives/Table/types';\n\ntype CreateNewRowProps<TType = unknown> = {\n buttonRef: React.Ref<HTMLButtonElement>;\n onEditingCreate?: Table3EditingCreateHandler<TType>;\n table: ReactTable<TType>;\n tableMeta: ReactTableMeta<TType>;\n tableRef: React.RefObject<TableRef>;\n};\n\nexport function CreateNewRow<TType = unknown>(props: CreateNewRowProps<TType>) {\n const { buttonRef, onEditingCreate: handleEditingCreate, table, tableMeta } = props;\n const { texts } = useLocalization();\n\n const temporaryRows = tableMeta.editing.temporaryRows as TType[];\n const temporaryRowId: string = temporaryRows[0]?.[tableMeta.rowIdentityAccessor as string] ?? '';\n\n const isDisabled =\n !!table.getState().globalFilter ||\n !!table.getState().columnFilters?.length ||\n (!!temporaryRowId && !!tableMeta.editing.hasRowErrors(temporaryRowId));\n const isSaving = !!temporaryRowId && tableMeta.editing.getRowStatus(temporaryRowId) === 'saving';\n\n const handleCreate = async event => {\n // prevent save being triggered by click outside - TODO: investigate why the button triggers clickoutside\n event?.stopPropagation();\n\n if (!handleEditingCreate || isDisabled) {\n return;\n }\n\n const saved = await tableMeta.editing.saveChanges(table);\n\n if (!saved) {\n return;\n }\n\n try {\n const changeset = handleEditingCreate();\n\n if (changeset) {\n const nextRowIndex = temporaryRows.length ? tableMeta.length + 1 : tableMeta.length;\n // change the row before reating because it triggers a save\n // saving would trigger the validation flow and immediately make the row red\n tableMeta.rowActive.setRowActiveIndex(nextRowIndex);\n\n requestAnimationFrame(async () => {\n tableMeta.editing.toggleEditing(true, table);\n const rowId = await tableMeta.editing.createRow(changeset);\n tableMeta.editing.setLastFocusedCellIndex(0);\n\n try {\n const row = table.getRow(rowId);\n row.pin('bottom');\n } catch {\n //\n }\n });\n }\n } catch (error) {\n console.error(error);\n }\n };\n\n let tooltip;\n\n if (isSaving) {\n tooltip = texts.table3.editing.buttons.create.saving;\n } else if (isDisabled) {\n tooltip = texts.table3.editing.buttons.create.disabled;\n }\n\n return (\n <tr data-row-create className=\"border-grey-300 group/row\" tabIndex={-1}>\n <td className=\"!bg-grey-50 col-span-full !border-b-0 !px-1\">\n <Button\n appearance=\"transparent\"\n className=\"group-hover:bg-grey-200 sticky left-[4px]\"\n disabled={isDisabled}\n onClick={handleCreate}\n ref={buttonRef}\n tooltip={tooltip}>\n <Icon name=\"circle-plus\" />\n {texts.table3.editing.buttons.create.label}\n </Button>\n </td>\n </tr>\n );\n}\n"],"names":["CreateNewRow","props","buttonRef","onEditingCreate","handleEditingCreate","table","tableMeta","texts","useLocalization","temporaryRows","editing","temporaryRowId","_temporaryRows$0$tabl","_temporaryRows$","rowIdentityAccessor","isDisabled","getState","globalFilter","_table$getState$colum","columnFilters","length","hasRowErrors","isSaving","getRowStatus","handleCreate","event","stopPropagation","Promise","resolve","saveChanges","then","saved","changeset","nextRowIndex","rowActive","setRowActiveIndex","requestAnimationFrame","toggleEditing","createRow","rowId","setLastFocusedCellIndex","row","getRow","pin","e","reject","error","console","tooltip","table3","buttons","create","saving","disabled","React","className","tabIndex","Button","appearance","onClick","ref","Icon","name","label"],"mappings":";;;;;SAgBgBA,YAAYA,CAAkBC,KAA+B;;EACzE,MAAM;IAAEC,SAAS;IAAEC,eAAe,EAAEC,mBAAmB;IAAEC,KAAK;IAAEC;GAAW,GAAGL,KAAK;EACnF,MAAM;IAAEM;GAAO,GAAGC,eAAe,EAAE;EAEnC,MAAMC,aAAa,GAAGH,SAAS,CAACI,OAAO,CAACD,aAAwB;EAChE,MAAME,cAAc,IAAAC,qBAAA,IAAAC,eAAA,GAAWJ,aAAa,CAAC,CAAC,CAAC,cAAAI,eAAA,uBAAhBA,eAAA,CAAmBP,SAAS,CAACQ,mBAA6B,CAAC,cAAAF,qBAAA,cAAAA,qBAAA,GAAI,EAAE;EAEhG,MAAMG,UAAU,GACZ,CAAC,CAACV,KAAK,CAACW,QAAQ,EAAE,CAACC,YAAY,IAC/B,CAAC,GAAAC,qBAAA,GAACb,KAAK,CAACW,QAAQ,EAAE,CAACG,aAAa,cAAAD,qBAAA,eAA9BA,qBAAA,CAAgCE,MAAM,KACvC,CAAC,CAACT,cAAc,IAAI,CAAC,CAACL,SAAS,CAACI,OAAO,CAACW,YAAY,CAACV,cAAc,CAAE;EAC1E,MAAMW,QAAQ,GAAG,CAAC,CAACX,cAAc,IAAIL,SAAS,CAACI,OAAO,CAACa,YAAY,CAACZ,cAAc,CAAC,KAAK,QAAQ;EAEhG,MAAMa,YAAY,aAASC,KAAK;IAAA;;MAE5BA,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEC,eAAe,EAAE;MAExB,IAAI,CAACtB,mBAAmB,IAAIW,UAAU,EAAE;QACpC,OAAAY,OAAA,CAAAC,OAAA;;MACH,OAAAD,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GAAGzC,KAAK,CAAC0C,MAAM,CAACvC,OAAO,CAACwC,OAAO,CAACC,MAAM,CAACE,QAAQ;;EAG1D,oBACIC;;IAAoBC,SAAS,EAAC,2BAA2B;IAACC,QAAQ,EAAE,CAAC;kBACjEF;IAAIC,SAAS,EAAC;kBACVD,6BAACG,MAAM;IACHC,UAAU,EAAC,aAAa;IACxBH,SAAS,EAAC,2CAA2C;IACrDF,QAAQ,EAAEtC,UAAU;IACpB4C,OAAO,EAAEnC,YAAY;IACrBoC,GAAG,EAAE1D,SAAS;IACd8C,OAAO,EAAEA;kBACTM,6BAACO,IAAI;IAACC,IAAI,EAAC;IAAgB,EAC1BvD,KAAK,CAAC0C,MAAM,CAACvC,OAAO,CAACwC,OAAO,CAACC,MAAM,CAACY,KAAK,CACrC,CACR,CACJ;AAEb;;;;"}
@@ -5,7 +5,6 @@ import { Tooltip } from '../../../../Tooltip/Tooltip.js';
5
5
  import { useLocalization } from '../../../../Provider/Localization.js';
6
6
  import { Spinner } from '../../../../Spinner/Spinner.js';
7
7
 
8
- const COMPLETE_INDICATOR_DELAY = 3000;
9
8
  function SaveStatus(props) {
10
9
  const {
11
10
  rowId,
@@ -15,18 +14,7 @@ function SaveStatus(props) {
15
14
  texts
16
15
  } = useLocalization();
17
16
  const tableMeta = table.options.meta;
18
- const status = tableMeta.editing.getRowSaveStatus(rowId);
19
- React__default.useEffect(() => {
20
- let timeout;
21
- if (status === 'complete') {
22
- timeout = setTimeout(() => {
23
- tableMeta.editing.setRowSaveStatus(rowId, undefined);
24
- }, COMPLETE_INDICATOR_DELAY);
25
- }
26
- return () => {
27
- clearTimeout(timeout);
28
- };
29
- }, [status]);
17
+ const status = tableMeta.editing.getRowStatus(rowId);
30
18
  const className = cn('col-span-full sticky ml-auto right-0 top-0 -mb-[100%] z-10 h-8 bg-[inherit] flex items-center px-1.5 shadow-[-6px_0px_6px_var(--table-row-actions-shadow)]', {
31
19
  'mt-0.5': tableMeta.rowHeight.height === 'short',
32
20
  'mt-1': tableMeta.rowHeight.height === 'medium',
@@ -37,7 +25,7 @@ function SaveStatus(props) {
37
25
  className: "!contents"
38
26
  }, /*#__PURE__*/React__default.createElement("span", {
39
27
  className: className
40
- }, status === 'pending' ? (/*#__PURE__*/React__default.createElement(Tooltip, {
28
+ }, status === 'saving' ? (/*#__PURE__*/React__default.createElement(Tooltip, {
41
29
  title: texts.table3.editing.saving.progress
42
30
  }, /*#__PURE__*/React__default.createElement(Spinner, {
43
31
  delay: 0,
@@ -1 +1 @@
1
- {"version":3,"file":"SaveStatus.js","sources":["../../../../../../../../../../src/components/Table3/components/Row/Editing/SaveStatus.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport clsx from 'clsx';\nimport { Tooltip } from '../../../../Tooltip/Tooltip';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { BadgeIcon } from '../../../../BadgeIcon/BadgeIcon';\nimport { Spinner } from '../../../../Spinner/Spinner';\n\nconst COMPLETE_INDICATOR_DELAY = 3000;\n\ntype SaveStatusProps<TType = unknown> = {\n rowId: string;\n table: ReactTable<TType>;\n};\n\nexport function SaveStatus<TType = unknown>(props: SaveStatusProps<TType>) {\n const { rowId, table } = props;\n const { texts } = useLocalization();\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const status = tableMeta.editing.getRowSaveStatus(rowId);\n\n React.useEffect(() => {\n let timeout;\n\n if (status === 'complete') {\n timeout = setTimeout(() => {\n tableMeta.editing.setRowSaveStatus(rowId, undefined);\n }, COMPLETE_INDICATOR_DELAY);\n }\n\n return () => {\n clearTimeout(timeout);\n };\n }, [status]);\n\n const className = clsx(\n 'col-span-full sticky ml-auto right-0 top-0 -mb-[100%] z-10 h-8 bg-[inherit] flex items-center px-1.5 shadow-[-6px_0px_6px_var(--table-row-actions-shadow)]',\n {\n 'mt-0.5': tableMeta.rowHeight.height === 'short',\n 'mt-1': tableMeta.rowHeight.height === 'medium',\n 'mt-1.5': tableMeta.rowHeight.height === 'tall',\n 'mt-2': tableMeta.rowHeight.height === 'extra-tall',\n }\n );\n\n return (\n <td className=\"!contents\">\n <span className={className}>\n {status === 'pending' ? (\n <Tooltip title={texts.table3.editing.saving.progress}>\n <Spinner delay={0} className=\"mr-1 !h-5 !w-5\" />\n </Tooltip>\n ) : (\n <Tooltip title={texts.table3.editing.saving.complete}>\n <BadgeIcon icon=\"tick\" color=\"green\" subtle className=\"mr-1\" />\n </Tooltip>\n )}\n </span>\n </td>\n );\n}\n"],"names":["COMPLETE_INDICATOR_DELAY","SaveStatus","props","rowId","table","texts","useLocalization","tableMeta","options","meta","status","editing","getRowSaveStatus","React","useEffect","timeout","setTimeout","setRowSaveStatus","undefined","clearTimeout","className","clsx","rowHeight","height","Tooltip","title","table3","saving","progress","Spinner","delay","complete","BadgeIcon","icon","color","subtle"],"mappings":";;;;;;;AAQA,MAAMA,wBAAwB,GAAG,IAAI;SAOrBC,UAAUA,CAAkBC,KAA6B;EACrE,MAAM;IAAEC,KAAK;IAAEC;GAAO,GAAGF,KAAK;EAC9B,MAAM;IAAEG;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAA6B;EAC7D,MAAMC,MAAM,GAAGH,SAAS,CAACI,OAAO,CAACC,gBAAgB,CAACT,KAAK,CAAC;EAExDU,cAAK,CAACC,SAAS,CAAC;IACZ,IAAIC,OAAO;IAEX,IAAIL,MAAM,KAAK,UAAU,EAAE;MACvBK,OAAO,GAAGC,UAAU,CAAC;QACjBT,SAAS,CAACI,OAAO,CAACM,gBAAgB,CAACd,KAAK,EAAEe,SAAS,CAAC;OACvD,EAAElB,wBAAwB,CAAC;;IAGhC,OAAO;MACHmB,YAAY,CAACJ,OAAO,CAAC;KACxB;GACJ,EAAE,CAACL,MAAM,CAAC,CAAC;EAEZ,MAAMU,SAAS,GAAGC,EAAI,CAClB,4JAA4J,EAC5J;IACI,QAAQ,EAAEd,SAAS,CAACe,SAAS,CAACC,MAAM,KAAK,OAAO;IAChD,MAAM,EAAEhB,SAAS,CAACe,SAAS,CAACC,MAAM,KAAK,QAAQ;IAC/C,QAAQ,EAAEhB,SAAS,CAACe,SAAS,CAACC,MAAM,KAAK,MAAM;IAC/C,MAAM,EAAEhB,SAAS,CAACe,SAAS,CAACC,MAAM,KAAK;GAC1C,CACJ;EAED,oBACIV;IAAIO,SAAS,EAAC;kBACVP;IAAMO,SAAS,EAAEA;KACZV,MAAM,KAAK,SAAS,iBACjBG,6BAACW,OAAO;IAACC,KAAK,EAAEpB,KAAK,CAACqB,MAAM,CAACf,OAAO,CAACgB,MAAM,CAACC;kBACxCf,6BAACgB,OAAO;IAACC,KAAK,EAAE,CAAC;IAAEV,SAAS,EAAC;IAAmB,CAC1C,kBAEVP,6BAACW,OAAO;IAACC,KAAK,EAAEpB,KAAK,CAACqB,MAAM,CAACf,OAAO,CAACgB,MAAM,CAACI;kBACxClB,6BAACmB,SAAS;IAACC,IAAI,EAAC,MAAM;IAACC,KAAK,EAAC,OAAO;IAACC,MAAM;IAACf,SAAS,EAAC;IAAS,CACzD,CACb,CACE,CACN;AAEb;;;;"}
1
+ {"version":3,"file":"SaveStatus.js","sources":["../../../../../../../../../../src/components/Table3/components/Row/Editing/SaveStatus.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport clsx from 'clsx';\nimport { Tooltip } from '../../../../Tooltip/Tooltip';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { BadgeIcon } from '../../../../BadgeIcon/BadgeIcon';\nimport { Spinner } from '../../../../Spinner/Spinner';\n\ntype SaveStatusProps<TType = unknown> = {\n rowId: string;\n table: ReactTable<TType>;\n};\n\nexport function SaveStatus<TType = unknown>(props: SaveStatusProps<TType>) {\n const { rowId, table } = props;\n const { texts } = useLocalization();\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const status = tableMeta.editing.getRowStatus(rowId);\n\n const className = clsx(\n 'col-span-full sticky ml-auto right-0 top-0 -mb-[100%] z-10 h-8 bg-[inherit] flex items-center px-1.5 shadow-[-6px_0px_6px_var(--table-row-actions-shadow)]',\n {\n 'mt-0.5': tableMeta.rowHeight.height === 'short',\n 'mt-1': tableMeta.rowHeight.height === 'medium',\n 'mt-1.5': tableMeta.rowHeight.height === 'tall',\n 'mt-2': tableMeta.rowHeight.height === 'extra-tall',\n }\n );\n\n return (\n <td className=\"!contents\">\n <span className={className}>\n {status === 'saving' ? (\n <Tooltip title={texts.table3.editing.saving.progress}>\n <Spinner delay={0} className=\"mr-1 !h-5 !w-5\" />\n </Tooltip>\n ) : (\n <Tooltip title={texts.table3.editing.saving.complete}>\n <BadgeIcon icon=\"tick\" color=\"green\" subtle className=\"mr-1\" />\n </Tooltip>\n )}\n </span>\n </td>\n );\n}\n"],"names":["SaveStatus","props","rowId","table","texts","useLocalization","tableMeta","options","meta","status","editing","getRowStatus","className","clsx","rowHeight","height","React","Tooltip","title","table3","saving","progress","Spinner","delay","complete","BadgeIcon","icon","color","subtle"],"mappings":";;;;;;;SAagBA,UAAUA,CAAkBC,KAA6B;EACrE,MAAM;IAAEC,KAAK;IAAEC;GAAO,GAAGF,KAAK;EAC9B,MAAM;IAAEG;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAA6B;EAC7D,MAAMC,MAAM,GAAGH,SAAS,CAACI,OAAO,CAACC,YAAY,CAACT,KAAK,CAAC;EAEpD,MAAMU,SAAS,GAAGC,EAAI,CAClB,4JAA4J,EAC5J;IACI,QAAQ,EAAEP,SAAS,CAACQ,SAAS,CAACC,MAAM,KAAK,OAAO;IAChD,MAAM,EAAET,SAAS,CAACQ,SAAS,CAACC,MAAM,KAAK,QAAQ;IAC/C,QAAQ,EAAET,SAAS,CAACQ,SAAS,CAACC,MAAM,KAAK,MAAM;IAC/C,MAAM,EAAET,SAAS,CAACQ,SAAS,CAACC,MAAM,KAAK;GAC1C,CACJ;EAED,oBACIC;IAAIJ,SAAS,EAAC;kBACVI;IAAMJ,SAAS,EAAEA;KACZH,MAAM,KAAK,QAAQ,iBAChBO,6BAACC,OAAO;IAACC,KAAK,EAAEd,KAAK,CAACe,MAAM,CAACT,OAAO,CAACU,MAAM,CAACC;kBACxCL,6BAACM,OAAO;IAACC,KAAK,EAAE,CAAC;IAAEX,SAAS,EAAC;IAAmB,CAC1C,kBAEVI,6BAACC,OAAO;IAACC,KAAK,EAAEd,KAAK,CAACe,MAAM,CAACT,OAAO,CAACU,MAAM,CAACI;kBACxCR,6BAACS,SAAS;IAACC,IAAI,EAAC,MAAM;IAACC,KAAK,EAAC,OAAO;IAACC,MAAM;IAAChB,SAAS,EAAC;IAAS,CACzD,CACb,CACE,CACN;AAEb;;;;"}
@@ -0,0 +1,95 @@
1
+ import React__default from 'react';
2
+ import cn from 'clsx';
3
+ import { isElementTriggeredFromContainer } from '../../../../../utils/dom.js';
4
+ import { Row } from '../../../../../primitives/Table/Core/components/Row/Row.js';
5
+ import { TEMPORARY_ROW_ID_PREFIX } from '../../../util/editing.js';
6
+ import { RENDERERS } from '../../../useTable3.js';
7
+
8
+ function TemporaryRow(props) {
9
+ var _tableRef$current, _tableRef$current2;
10
+ const {
11
+ createRowButtonRef,
12
+ table,
13
+ tableMeta,
14
+ tableRef
15
+ } = props;
16
+ const isScrolled = tableRef.current ? ((_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : _tableRef$current.scrollHeight) > ((_tableRef$current2 = tableRef.current) === null || _tableRef$current2 === void 0 ? void 0 : _tableRef$current2.clientHeight) : false;
17
+ const handleKeyDown = function (event) {
18
+ try {
19
+ const _temp2 = function () {
20
+ if (event.key === 'ArrowDown') {
21
+ event.preventDefault();
22
+ const _temp = function () {
23
+ if (!isElementTriggeredFromContainer(event.target, event.currentTarget)) {
24
+ return Promise.resolve(tableMeta.editing.saveChanges(table)).then(function (saved) {
25
+ if (saved) {
26
+ var _createRowButtonRef$c;
27
+ (_createRowButtonRef$c = createRowButtonRef.current) === null || _createRowButtonRef$c === void 0 ? void 0 : _createRowButtonRef$c.focus();
28
+ }
29
+ });
30
+ }
31
+ }();
32
+ if (_temp && _temp.then) return _temp.then(function () {});
33
+ } else if (event.key === 'ArrowUp') {
34
+ event.preventDefault();
35
+ event.stopPropagation();
36
+ if (tableRef.current) {
37
+ var _tableRef$current$que, _tableRef$current$que2, _tableRef$current$que3;
38
+ const availableRows = Array.from((_tableRef$current$que = tableRef.current.querySelectorAll(`tbody tr:not([data-row-id^='${TEMPORARY_ROW_ID_PREFIX}'])`)) !== null && _tableRef$current$que !== void 0 ? _tableRef$current$que : []);
39
+ const footerHeight = (_tableRef$current$que2 = (_tableRef$current$que3 = tableRef.current.querySelector('tfoot')) === null || _tableRef$current$que3 === void 0 ? void 0 : _tableRef$current$que3.getBoundingClientRect().height) !== null && _tableRef$current$que2 !== void 0 ? _tableRef$current$que2 : 0;
40
+ const newRowHeight = event.currentTarget.getBoundingClientRect().height;
41
+ const visibleHeight = tableRef.current.clientHeight - footerHeight - newRowHeight;
42
+ const tableTopOffset = tableRef.current.getBoundingClientRect().top;
43
+ let nextRowIndex;
44
+ // iterate available rows in reverse order, since we're working at the bottom
45
+ for (let index = availableRows.length - 1; index >= 0; index--) {
46
+ const rowRect = availableRows[index].getBoundingClientRect();
47
+ const topPlusHalfRow = rowRect.top + rowRect.height / 2;
48
+ if (topPlusHalfRow - tableTopOffset <= visibleHeight) {
49
+ nextRowIndex = index;
50
+ break;
51
+ }
52
+ }
53
+ if (nextRowIndex) {
54
+ tableMeta.rowActive.setRowActiveIndex(Number(availableRows[nextRowIndex < 0 ? 0 : nextRowIndex].getAttribute('data-row-index')));
55
+ }
56
+ }
57
+ }
58
+ }();
59
+ return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
60
+ } catch (e) {
61
+ return Promise.reject(e);
62
+ }
63
+ };
64
+ const handleKeyDownCapture = event => {
65
+ if (event.key === 'ArrowLeft' && tableMeta.editing.lastFocusedCellIndex === 0) {
66
+ event.preventDefault();
67
+ event.stopPropagation();
68
+ } else if (event.key === 'ArrowRight' && tableMeta.editing.lastFocusedCellIndex) {
69
+ if (tableMeta.editing.lastFocusedCellIndex === table.getVisibleFlatColumns().length - 1) {
70
+ event.preventDefault();
71
+ event.stopPropagation();
72
+ }
73
+ }
74
+ };
75
+ const className = cn('group/row border-grey-300 !sticky z-[21]', {
76
+ 'bottom-20': tableMeta.footer.isEnabled,
77
+ 'bottom-10': !tableMeta.footer.isEnabled,
78
+ 'border-b border-t shadow-[0px_-5px_20px_0px_rgba(0,0,0,0.1)] border-t-grey-500/[0.75]': isScrolled
79
+ });
80
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, table.getBottomRows().map(row => (/*#__PURE__*/React__default.createElement(Row, {
81
+ key: row.id,
82
+ cellRenderer: RENDERERS.cell,
83
+ index: tableMeta.length,
84
+ measureRow: () => null,
85
+ renderer: RENDERERS.row,
86
+ row: row,
87
+ table: table,
88
+ className: className,
89
+ onKeyDown: handleKeyDown,
90
+ onKeyDownCapture: handleKeyDownCapture
91
+ }))));
92
+ }
93
+
94
+ export { TemporaryRow };
95
+ //# sourceMappingURL=TemporaryRow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TemporaryRow.js","sources":["../../../../../../../../../../src/components/Table3/components/Row/Editing/TemporaryRow.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport clsx from 'clsx';\nimport { Row } from '../../../../../primitives/Table/Core/components/Row/Row';\nimport { RENDERERS } from '../../../useTable3';\nimport { isElementTriggeredFromContainer } from '../../../../../utils/dom';\nimport { TableRef } from '../../../../../primitives/Table/types';\nimport { TEMPORARY_ROW_ID_PREFIX } from '../../../util/editing';\n\ntype TemporaryRowProps<TType = unknown> = {\n createRowButtonRef: React.RefObject<HTMLButtonElement>;\n table: ReactTable<TType>;\n tableMeta: ReactTableMeta<TType>;\n tableRef: React.RefObject<TableRef>;\n};\n\nexport function TemporaryRow<TType = unknown>(props: TemporaryRowProps<TType>) {\n const { createRowButtonRef, table, tableMeta, tableRef } = props;\n\n const isScrolled = tableRef.current ? tableRef.current?.scrollHeight > tableRef.current?.clientHeight : false;\n\n const handleKeyDown = async (event: React.KeyboardEvent<HTMLTableRowElement>) => {\n if (event.key === 'ArrowDown') {\n event.preventDefault();\n\n if (!isElementTriggeredFromContainer(event.target as Element, event.currentTarget)) {\n const saved = await tableMeta.editing.saveChanges(table);\n\n if (saved) {\n createRowButtonRef.current?.focus();\n }\n }\n } else if (event.key === 'ArrowUp') {\n event.preventDefault();\n event.stopPropagation();\n\n if (tableRef.current) {\n const availableRows = Array.from(\n tableRef.current.querySelectorAll(`tbody tr:not([data-row-id^='${TEMPORARY_ROW_ID_PREFIX}'])`) ?? []\n );\n\n const footerHeight = tableRef.current.querySelector('tfoot')?.getBoundingClientRect().height ?? 0;\n const newRowHeight = event.currentTarget.getBoundingClientRect().height;\n const visibleHeight = tableRef.current.clientHeight - footerHeight - newRowHeight;\n const tableTopOffset = tableRef.current.getBoundingClientRect().top;\n\n let nextRowIndex;\n\n // iterate available rows in reverse order, since we're working at the bottom\n for (let index = availableRows.length - 1; index >= 0; index--) {\n const rowRect = availableRows[index].getBoundingClientRect();\n const topPlusHalfRow = rowRect.top + rowRect.height / 2;\n\n if (topPlusHalfRow - tableTopOffset <= visibleHeight) {\n nextRowIndex = index;\n break;\n }\n }\n\n if (nextRowIndex) {\n tableMeta.rowActive.setRowActiveIndex(\n Number(availableRows[nextRowIndex < 0 ? 0 : nextRowIndex].getAttribute('data-row-index'))\n );\n }\n }\n }\n };\n\n const handleKeyDownCapture = (event: React.KeyboardEvent<HTMLTableRowElement>) => {\n if (event.key === 'ArrowLeft' && tableMeta.editing.lastFocusedCellIndex === 0) {\n event.preventDefault();\n event.stopPropagation();\n } else if (event.key === 'ArrowRight' && tableMeta.editing.lastFocusedCellIndex) {\n if (tableMeta.editing.lastFocusedCellIndex === table.getVisibleFlatColumns().length - 1) {\n event.preventDefault();\n event.stopPropagation();\n }\n }\n };\n\n const className = clsx('group/row border-grey-300 !sticky z-[21]', {\n 'bottom-20': tableMeta.footer.isEnabled,\n 'bottom-10': !tableMeta.footer.isEnabled,\n 'border-b border-t shadow-[0px_-5px_20px_0px_rgba(0,0,0,0.1)] border-t-grey-500/[0.75]': isScrolled,\n });\n\n return (\n <>\n {table.getBottomRows().map(row => (\n <Row<TType>\n key={row.id}\n cellRenderer={RENDERERS.cell}\n index={tableMeta.length}\n measureRow={() => null}\n renderer={RENDERERS.row}\n row={row}\n table={table}\n className={className}\n onKeyDown={handleKeyDown}\n onKeyDownCapture={handleKeyDownCapture}\n />\n ))}\n </>\n );\n}\n"],"names":["TemporaryRow","props","createRowButtonRef","table","tableMeta","tableRef","isScrolled","current","_tableRef$current","scrollHeight","_tableRef$current2","clientHeight","handleKeyDown","event","key","preventDefault","_temp","isElementTriggeredFromContainer","target","currentTarget","Promise","resolve","editing","saveChanges","then","saved","_createRowButtonRef$c","focus","stopPropagation","_tableRef$current$que","_tableRef$current$que2","_tableRef$current$que3","availableRows","Array","from","querySelectorAll","TEMPORARY_ROW_ID_PREFIX","footerHeight","querySelector","getBoundingClientRect","height","newRowHeight","visibleHeight","tableTopOffset","top","nextRowIndex","index","length","rowRect","topPlusHalfRow","rowActive","setRowActiveIndex","Number","getAttribute","_temp2","e","reject","handleKeyDownCapture","lastFocusedCellIndex","getVisibleFlatColumns","className","clsx","footer","isEnabled","React","getBottomRows","map","row","Row","id","cellRenderer","RENDERERS","cell","measureRow","renderer","onKeyDown","onKeyDownCapture"],"mappings":";;;;;;;SAgBgBA,YAAYA,CAAkBC,KAA+B;;EACzE,MAAM;IAAEC,kBAAkB;IAAEC,KAAK;IAAEC,SAAS;IAAEC;GAAU,GAAGJ,KAAK;EAEhE,MAAMK,UAAU,GAAGD,QAAQ,CAACE,OAAO,GAAG,EA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,oBAAoB,KAAK,CAAC,EAAE;MAC3E7C,KAAK,CAACE,cAAc,EAAE;MACtBF,KAAK,CAACe,eAAe,EAAE;KAC1B,MAAM,IAAIf,KAAK,CAACC,GAAG,KAAK,YAAY,IAAIV,SAAS,CAACkB,OAAO,CAACoC,oBAAoB,EAAE;MAC7E,IAAItD,SAAS,CAACkB,OAAO,CAACoC,oBAAoB,KAAKvD,KAAK,CAACwD,qBAAqB,EAAE,CAACZ,MAAM,GAAG,CAAC,EAAE;QACrFlC,KAAK,CAACE,cAAc,EAAE;QACtBF,KAAK,CAACe,eAAe,EAAE;;;GAGlC;EAED,MAAMgC,SAAS,GAAGC,EAAI,CAAC,0CAA0C,EAAE;IAC/D,WAAW,EAAEzD,SAAS,CAAC0D,MAAM,CAACC,SAAS;IACvC,WAAW,EAAE,CAAC3D,SAAS,CAAC0D,MAAM,CAACC,SAAS;IACxC,uFAAuF,EAAEzD;GAC5F,CAAC;EAEF,oBACI0D,4DACK7D,KAAK,CAAC8D,aAAa,EAAE,CAACC,GAAG,CAACC,GAAG,kBAC1BH,6BAACI,GAAG;IACAtD,GAAG,EAAEqD,GAAG,CAACE,EAAE;IACXC,YAAY,EAAEC,SAAS,CAACC,IAAI;IAC5B1B,KAAK,EAAE1C,SAAS,CAAC2C,MAAM;IACvB0B,UAAU,EAAEA,MAAM,IAAI;IACtBC,QAAQ,EAAEH,SAAS,CAACJ,GAAG;IACvBA,GAAG,EAAEA,GAAG;IACRhE,KAAK,EAAEA,KAAK;IACZyD,SAAS,EAAEA,SAAS;IACpBe,SAAS,EAAE/D,aAAa;IACxBgE,gBAAgB,EAAEnB;IACpB,CACL,CAAC,CACH;AAEX;;;;"}
@@ -1,7 +1,9 @@
1
1
  import React__default from 'react';
2
- import { setDataFocusAttribute } from '../../../../utils/dom.js';
2
+ import { setDataFocusAttribute, isElementTriggeredFromContainer } from '../../../../utils/dom.js';
3
3
  import { DisplayRow } from '../../../../primitives/Table/Core/components/Row/BuiltIns/DisplayRow.js';
4
4
  import { useAugmentedFocusManager } from '../../../../primitives/Table/Core/components/Body/util.js';
5
+ import { isTemporaryRow } from '../../util/editing.js';
6
+ import { DiscardChangesConfirmationDialog } from '../Editing/DiscardChangesConfirmationDialog.js';
5
7
  import { SaveStatus } from './Editing/SaveStatus.js';
6
8
 
7
9
  function Row(props) {
@@ -27,15 +29,46 @@ function Row(props) {
27
29
  }
28
30
  }
29
31
  }, [tableMeta.editing.isEditing, isActiveRow]);
32
+ const rowStatus = tableMeta.editing.getRowStatus(row.id);
33
+ // discard new row
34
+ const [showDiscardDialog, setShowDiscardDialog] = React__default.useState(false);
35
+ function handleDiscard() {
36
+ tableMeta.editing.discardChanges(row.id, table);
37
+ requestAnimationFrame(() => {
38
+ if (isTemporaryRow(row.id)) {
39
+ var _tableMeta$editing$cr;
40
+ (_tableMeta$editing$cr = tableMeta.editing.createRowButtonRef.current) === null || _tableMeta$editing$cr === void 0 ? void 0 : _tableMeta$editing$cr.focus();
41
+ } else {
42
+ focusManager.focusFirst();
43
+ }
44
+ });
45
+ }
46
+ function handleKeyDown(event) {
47
+ if (props.onKeyDown) {
48
+ props.onKeyDown(event);
49
+ }
50
+ if (event.isDefaultPrevented() || event.isPropagationStopped()) {
51
+ return;
52
+ }
53
+ if (event.key === 'Escape' && tableMeta.editing.hasChanges(row.id) && !isElementTriggeredFromContainer(event.target, event.currentTarget)) {
54
+ event.preventDefault();
55
+ setShowDiscardDialog(true);
56
+ }
57
+ }
30
58
  const attributes = {
31
- 'data-row-editing-invalid': tableMeta.editing.isEnabled && tableMeta.editing.hasRowErrors(row.id) ? !tableMeta.editing.hasRowErrorsSeen(row.id) ? 'unseen' : true : undefined,
32
- 'data-row-editing-status': tableMeta.editing.isEnabled && tableMeta.editing.getRowSaveStatus(row.id) ? tableMeta.editing.getRowSaveStatus(row.id) : undefined,
33
- onFocus: handleFocus
59
+ 'data-row-editing-invalid': tableMeta.editing.hasRowErrors(row.id) ? !tableMeta.editing.hasRowErrorsShownInAlert(row.id) ? 'unseen' : true : undefined,
60
+ 'data-row-editing-status': rowStatus,
61
+ onFocus: handleFocus,
62
+ onKeyDown: handleKeyDown
34
63
  };
35
- return /*#__PURE__*/React__default.createElement(DisplayRow, Object.assign({}, props, attributes), tableMeta.editing.getRowSaveStatus(row.id) ? /*#__PURE__*/React__default.createElement(SaveStatus, {
64
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(DisplayRow, Object.assign({}, props, attributes), rowStatus === 'saving' || rowStatus === 'saved' ? /*#__PURE__*/React__default.createElement(SaveStatus, {
36
65
  rowId: row.id,
37
66
  table: table
38
- }) : null);
67
+ }) : null), /*#__PURE__*/React__default.createElement(DiscardChangesConfirmationDialog, {
68
+ open: showDiscardDialog,
69
+ onChange: setShowDiscardDialog,
70
+ onDiscard: handleDiscard
71
+ }));
39
72
  }
40
73
 
41
74
  export { Row };
@@ -1 +1 @@
1
- {"version":3,"file":"Row.js","sources":["../../../../../../../../../src/components/Table3/components/Row/Row.tsx"],"sourcesContent":["import React from 'react';\nimport { TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { DisplayRow, DisplayRowProps } from '../../../../primitives/Table/Core/components/Row/BuiltIns/DisplayRow';\nimport { SaveStatus } from './Editing/SaveStatus';\nimport { useAugmentedFocusManager } from '../../../../primitives/Table/Core/components/Body/util';\nimport { setDataFocusAttribute } from '../../../../utils/dom';\n\nexport function Row<TType = unknown>(props: DisplayRowProps<TType>) {\n const { row, index, table } = props;\n const focusManager = useAugmentedFocusManager();\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const isActiveRow = tableMeta.rowActive.rowActiveIndex === index;\n\n React.useEffect(() => {\n if (tableMeta.editing.isEditing && isActiveRow && tableMeta.editing.lastFocusedCellIndex === undefined) {\n setDataFocusAttribute(focusManager.focusFirst());\n }\n }, [tableMeta.editing.isEditing, tableMeta.rowActive.rowActiveIndex, tableMeta.editing.lastFocusedCellIndex]);\n\n const handleFocus = React.useCallback(\n (event: React.FocusEvent<HTMLTableRowElement>) => {\n if (tableMeta.editing.isEditing) {\n const cellIndex = Number(event.target.closest('td')?.getAttribute('data-cell-index') ?? undefined);\n\n if (!isNaN(cellIndex)) {\n tableMeta.editing.setLastFocusedCellIndex(Number(cellIndex));\n }\n }\n },\n [tableMeta.editing.isEditing, isActiveRow]\n );\n\n const attributes = {\n 'data-row-editing-invalid':\n tableMeta.editing.isEnabled && tableMeta.editing.hasRowErrors(row.id)\n ? !tableMeta.editing.hasRowErrorsSeen(row.id)\n ? 'unseen'\n : true\n : undefined,\n 'data-row-editing-status':\n tableMeta.editing.isEnabled && tableMeta.editing.getRowSaveStatus(row.id)\n ? tableMeta.editing.getRowSaveStatus(row.id)\n : undefined,\n onFocus: handleFocus,\n };\n\n return (\n <DisplayRow<TType> {...props} {...attributes}>\n {tableMeta.editing.getRowSaveStatus(row.id) ? <SaveStatus rowId={row.id} table={table} /> : null}\n </DisplayRow>\n );\n}\n"],"names":["Row","props","row","index","table","focusManager","useAugmentedFocusManager","tableMeta","options","meta","isActiveRow","rowActive","rowActiveIndex","React","useEffect","editing","isEditing","lastFocusedCellIndex","undefined","setDataFocusAttribute","focusFirst","handleFocus","useCallback","event","_event$target$closest","_event$target$closest2","cellIndex","Number","target","closest","getAttribute","isNaN","setLastFocusedCellIndex","attributes","isEnabled","hasRowErrors","id","hasRowErrorsSeen","getRowSaveStatus","onFocus","DisplayRow","SaveStatus","rowId"],"mappings":";;;;;;SAOgBA,GAAGA,CAAkBC,KAA6B;EAC9D,MAAM;IAAEC,GAAG;IAAEC,KAAK;IAAEC;GAAO,GAAGH,KAAK;EACnC,MAAMI,YAAY,GAAGC,wBAAwB,EAAE;EAC/C,MAAMC,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAA6B;EAC7D,MAAMC,WAAW,GAAGH,SAAS,CAACI,SAAS,CAACC,cAAc,KAAKT,KAAK;EAEhEU,cAAK,CAACC,SAAS,CAAC;IACZ,IAAIP,SAAS,C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CAACuB,gBAAgB,CAACpC,GAAG,CAACkC,EAAE,CAAC,GACnE7B,SAAS,CAACQ,OAAO,CAACuB,gBAAgB,CAACpC,GAAG,CAACkC,EAAE,CAAC,GAC1ClB,SAAS;IACnBqB,OAAO,EAAElB;GACZ;EAED,oBACIR,6BAAC2B,UAAU,oBAAYvC,KAAK,EAAMgC,UAAU,GACvC1B,SAAS,CAACQ,OAAO,CAACuB,gBAAgB,CAACpC,GAAG,CAACkC,EAAE,CAAC,gBAAGvB,6BAAC4B,UAAU;IAACC,KAAK,EAAExC,GAAG,CAACkC,EAAE;IAAEhC,KAAK,EAAEA;IAAS,GAAG,IAAI,CACvF;AAErB;;;;"}
1
+ {"version":3,"file":"Row.js","sources":["../../../../../../../../../src/components/Table3/components/Row/Row.tsx"],"sourcesContent":["import React from 'react';\nimport { TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { DisplayRow, DisplayRowProps } from '../../../../primitives/Table/Core/components/Row/BuiltIns/DisplayRow';\nimport { SaveStatus } from './Editing/SaveStatus';\nimport { useAugmentedFocusManager } from '../../../../primitives/Table/Core/components/Body/util';\nimport { isElementTriggeredFromContainer, setDataFocusAttribute } from '../../../../utils/dom';\nimport { DiscardChangesConfirmationDialog } from '../Editing/DiscardChangesConfirmationDialog';\nimport { isTemporaryRow } from '../../util/editing';\n\nexport function Row<TType = unknown>(props: DisplayRowProps<TType>) {\n const { row, index, table } = props;\n const focusManager = useAugmentedFocusManager();\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const isActiveRow = tableMeta.rowActive.rowActiveIndex === index;\n\n React.useEffect(() => {\n if (tableMeta.editing.isEditing && isActiveRow && tableMeta.editing.lastFocusedCellIndex === undefined) {\n setDataFocusAttribute(focusManager.focusFirst());\n }\n }, [tableMeta.editing.isEditing, tableMeta.rowActive.rowActiveIndex, tableMeta.editing.lastFocusedCellIndex]);\n\n const handleFocus = React.useCallback(\n (event: React.FocusEvent<HTMLTableRowElement>) => {\n if (tableMeta.editing.isEditing) {\n const cellIndex = Number(event.target.closest('td')?.getAttribute('data-cell-index') ?? undefined);\n\n if (!isNaN(cellIndex)) {\n tableMeta.editing.setLastFocusedCellIndex(Number(cellIndex));\n }\n }\n },\n [tableMeta.editing.isEditing, isActiveRow]\n );\n\n const rowStatus = tableMeta.editing.getRowStatus(row.id);\n\n // discard new row\n const [showDiscardDialog, setShowDiscardDialog] = React.useState(false);\n\n function handleDiscard() {\n tableMeta.editing.discardChanges(row.id, table);\n requestAnimationFrame(() => {\n if (isTemporaryRow(row.id)) {\n tableMeta.editing.createRowButtonRef.current?.focus();\n } else {\n focusManager.focusFirst();\n }\n });\n }\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLTableRowElement>) {\n if (props.onKeyDown) {\n props.onKeyDown(event);\n }\n\n if (event.isDefaultPrevented() || event.isPropagationStopped()) {\n return;\n }\n\n if (\n event.key === 'Escape' &&\n tableMeta.editing.hasChanges(row.id) &&\n !isElementTriggeredFromContainer(event.target as HTMLElement, event.currentTarget)\n ) {\n event.preventDefault();\n setShowDiscardDialog(true);\n }\n }\n\n const attributes = {\n 'data-row-editing-invalid': tableMeta.editing.hasRowErrors(row.id)\n ? !tableMeta.editing.hasRowErrorsShownInAlert(row.id)\n ? 'unseen'\n : true\n : undefined,\n 'data-row-editing-status': rowStatus,\n onFocus: handleFocus,\n onKeyDown: handleKeyDown,\n };\n\n return (\n <>\n <DisplayRow<TType> {...props} {...attributes}>\n {rowStatus === 'saving' || rowStatus === 'saved' ? <SaveStatus rowId={row.id} table={table} /> : null}\n </DisplayRow>\n <DiscardChangesConfirmationDialog\n open={showDiscardDialog}\n onChange={setShowDiscardDialog}\n onDiscard={handleDiscard}\n />\n </>\n );\n}\n"],"names":["Row","props","row","index","table","focusManager","useAugmentedFocusManager","tableMeta","options","meta","isActiveRow","rowActive","rowActiveIndex","React","useEffect","editing","isEditing","lastFocusedCellIndex","undefined","setDataFocusAttribute","focusFirst","handleFocus","useCallback","event","_event$target$closest","_event$target$closest2","cellIndex","Number","target","closest","getAttribute","isNaN","setLastFocusedCellIndex","rowStatus","getRowStatus","id","showDiscardDialog","setShowDiscardDialog","useState","handleDiscard","discardChanges","requestAnimationFrame","isTemporaryRow","_tableMeta$editing$cr","createRowButtonRef","current","focus","handleKeyDown","onKeyDown","isDefaultPrevented","isPropagationStopped","key","hasChanges","isElementTriggeredFromContainer","currentTarget","preventDefault","attributes","hasRowErrors","hasRowErrorsShownInAlert","onFocus","DisplayRow","SaveStatus","rowId","DiscardChangesConfirmationDialog","open","onChange","onDiscard"],"mappings":";;;;;;;;SASgBA,GAAGA,CAAkBC,KAA6B;EAC9D,MAAM;IAAEC,GAAG;IAAEC,KAAK;IAAEC;GAAO,GAAGH,KAAK;EACnC,MAAMI,YAAY,GAAGC,wBAAwB,EAAE;EAC/C,MAAMC,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAA6B;EAC7D,MAAMC,WAAW,GAAGH,SAAS,CAACI,SAAS,CAACC,cAAc,KAAKT,KAAK;EAEhEU,cAAK,CAACC,SAAS,CAAC;IACZ,IAAIP,SAAS,CAACQ,OAAO,CAACC,SAAS,IAAIN,WAAW,IAAIH,SAAS,CAACQ,OAAO,CAACE,oBAAoB,KAAKC,SAAS,EAAE;MACpGC,qBAAqB,CAACd,YAAY,CAACe,UAAU,EAAE,CAAC;;GAEvD,EAAE,CAACb,SAAS,CAACQ,OAAO,CAACC,SAAS,EAAET,SAAS,CAACI,SAAS,CAACC,cAAc,EAAEL,SAAS,CAACQ,OAAO,CAACE,oBAAoB,CAAC,CAAC;EAE7G,MAAMI,WAAW,GAAGR,cAAK,CAACS,WAAW,CAChCC,KAA4C;IACzC,IAAIhB,SAAS,CAACQ,OAAO,CAACC,SAAS,EAAE;MAAA,IAAAQ,qBAAA,EAAAC,sBAAA;MAC7B,MAAMC,SAAS,GAAGC,MAAM,EAAAH,qBAAA,IAAAC,sBAAA,GAACF,KAAK,CAACK,MAAM,CAACC,OAAO,CAAC,IAAI,CAAC,c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CAACiC,EAAE,CAAC,IACpC,CAACkB,+BAA+B,CAAC9B,KAAK,CAACK,MAAqB,EAAEL,KAAK,CAAC+B,aAAa,CAAC,EACpF;MACE/B,KAAK,CAACgC,cAAc,EAAE;MACtBlB,oBAAoB,CAAC,IAAI,CAAC;;;EAIlC,MAAMmB,UAAU,GAAG;IACf,0BAA0B,EAAEjD,SAAS,CAACQ,OAAO,CAAC0C,YAAY,CAACvD,GAAG,CAACiC,EAAE,CAAC,GAC5D,CAAC5B,SAAS,CAACQ,OAAO,CAAC2C,wBAAwB,CAACxD,GAAG,CAACiC,EAAE,CAAC,GAC/C,QAAQ,GACR,IAAI,GACRjB,SAAS;IACf,yBAAyB,EAAEe,SAAS;IACpC0B,OAAO,EAAEtC,WAAW;IACpB2B,SAAS,EAAED;GACd;EAED,oBACIlC,yEACIA,6BAAC+C,UAAU,oBAAY3D,KAAK,EAAMuD,UAAU,GACvCvB,SAAS,KAAK,QAAQ,IAAIA,SAAS,KAAK,OAAO,gBAAGpB,6BAACgD,UAAU;IAACC,KAAK,EAAE5D,GAAG,CAACiC,EAAE;IAAE/B,KAAK,EAAEA;IAAS,GAAG,IAAI,CAC5F,eACbS,6BAACkD,gCAAgC;IAC7BC,IAAI,EAAE5B,iBAAiB;IACvB6B,QAAQ,EAAE5B,oBAAoB;IAC9B6B,SAAS,EAAE3B;IACb,CACH;AAEX;;;;"}
@@ -30,15 +30,20 @@ function Editing(props) {
30
30
  (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.click();
31
31
  });
32
32
  const handleChange = enabled => {
33
- tableMeta.editing.toggleEditing(enabled);
33
+ if (enabled && tableMeta.rowActive.rowActiveIndex === undefined) {
34
+ tableMeta.rowActive.setRowActiveIndex(0);
35
+ }
34
36
  requestAnimationFrame(() => {
35
37
  var _tableMeta$rowActive$;
36
- return scrollToIndex((_tableMeta$rowActive$ = tableMeta.rowActive.rowActiveIndex) !== null && _tableMeta$rowActive$ !== void 0 ? _tableMeta$rowActive$ : 0);
38
+ // wait for an active row to be set so that we don't trigger save
39
+ tableMeta.editing.toggleEditing(enabled, table);
40
+ scrollToIndex((_tableMeta$rowActive$ = tableMeta.rowActive.rowActiveIndex) !== null && _tableMeta$rowActive$ !== void 0 ? _tableMeta$rowActive$ : 0);
37
41
  });
38
42
  };
39
43
  return /*#__PURE__*/React__default.createElement(Tooltip, {
40
44
  title: tooltip
41
45
  }, /*#__PURE__*/React__default.createElement(ModeSwitch, {
46
+ "data-table": "editing-toggle",
42
47
  checked: tableMeta.editing.isEditing,
43
48
  onChange: handleChange,
44
49
  ref: ref
@@ -1 +1 @@
1
- {"version":3,"file":"Editing.js","sources":["../../../../../../../../../../src/components/Table3/components/Toolbar/Editing/Editing.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { Tooltip } from '../../../../Tooltip/Tooltip';\nimport { ModeSwitch } from '../../../../ModeSwitch/ModeSwitch';\nimport { useGlobalKeyDown } from '../../../../../hooks/useGlobalKeyDown';\nimport { Shortcut } from '../../../../Shortcut/Shortcut';\n\ntype EditingProps<TType = unknown> = React.HTMLAttributes<HTMLButtonElement> & {\n scrollToIndex: any;\n table: ReactTable<TType>;\n};\n\nexport function Editing<TType = unknown>(props: EditingProps<TType>) {\n const { scrollToIndex, table } = props;\n const { texts } = useLocalization();\n const ref = React.useRef<HTMLButtonElement>(null);\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n\n const shortcut = { key: 'e', meta: true, shift: false };\n const tooltip = (\n <>\n {texts.table3.editing.buttons.edit.tooltip}\n <Shortcut className=\"ml-2\" keys={shortcut} />\n </>\n );\n\n useGlobalKeyDown(shortcut, (event: KeyboardEvent) => {\n event.preventDefault();\n ref.current?.click();\n });\n\n const handleChange = (enabled: boolean) => {\n tableMeta.editing.toggleEditing(enabled);\n requestAnimationFrame(() => scrollToIndex(tableMeta.rowActive.rowActiveIndex ?? 0));\n };\n\n return (\n <Tooltip title={tooltip}>\n <ModeSwitch checked={tableMeta.editing.isEditing} onChange={handleChange} ref={ref} />\n </Tooltip>\n );\n}\n"],"names":["Editing","props","scrollToIndex","table","texts","useLocalization","ref","React","useRef","tableMeta","options","meta","shortcut","key","shift","tooltip","table3","editing","buttons","edit","Shortcut","className","keys","useGlobalKeyDown","event","preventDefault","_ref$current","current","click","handleChange","enabled","toggleEditing","requestAnimationFrame","_tableMeta$rowActive$","rowActive","rowActiveIndex","Tooltip","title","ModeSwitch","checked","isEditing","onChange"],"mappings":";;;;;;;SAagBA,OAAOA,CAAkBC,KAA0B;EAC/D,MAAM;IAAEC,aAAa;IAAEC;GAAO,GAAGF,KAAK;EACtC,MAAM;IAAEG;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,GAAG,GAAGC,cAAK,CAACC,MAAM,CAAoB,IAAI,CAAC;EACjD,MAAMC,SAAS,GAAGN,KAAK,CAACO,OAAO,CAACC,IAA6B;EAE7D,MAAMC,QAAQ,GAAG;IAAEC,GAAG,EAAE,GAAG;IAAEF,IAAI,EAAE,IAAI;IAAEG,KAAK,EAAE;GAAO;EACvD,MAAMC,OAAO,gBACTR,4DACKH,KAAK,CAACY,MAAM,CAACC,OAAO,CAACC,OAAO,CAACC,IAAI,CAACJ,OAAO,eAC1CR,6BAACa,QAAQ;IAACC,SAAS,EAAC,MAAM;IAACC,IAAI,EAAEV;IAAY,CAEpD;EAEDW,gBAAgB,CAACX,QAAQ,EAAGY,KAAoB;;IAC5CA,KAAK,CAACC,cAAc,EAAE;IACtB,CAAAC,YAAA,GAAApB,GAAG,CAACqB,OAAO,cAAAD,YAAA,uBAAXA,YAAA,CAAaE,KAAK,EAAE;GACvB,CAAC;EAEF,MAAMC,YAAY,GAAIC,OAAgB;IAClCrB,SAAS,CAACQ,OAAO,CAACc,aAAa,CAACD,OAAO,CAAC;IACxCE,qBAAqB,CAAC;MAAA,IAAAC,qBAAA;MAAA,OAAM/B,aAAa,EAAA+B,qBAAA,GAACxB,SAAS,CAACyB,SAAS,CAACC,cAAc,cAAAF,qBAAA,cAAAA,qBAAA,GAAI,CAAC,CAAC;MAAC;GACtF;EAED,oBACI1B,6BAAC6B,OAAO;IAACC,KAAK,EAAEtB;kBACZR,6BAAC+B,UAAU;IAACC,OAAO,EAAE9B,SAAS,CAACQ,OAAO,CAACuB,SAAS;IAAEC,QAAQ,EAAEZ,YAAY;IAAEvB,GAAG,EAAEA;IAAO,CAChF;AAElB;;;;"}
1
+ {"version":3,"file":"Editing.js","sources":["../../../../../../../../../../src/components/Table3/components/Toolbar/Editing/Editing.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { Tooltip } from '../../../../Tooltip/Tooltip';\nimport { ModeSwitch } from '../../../../ModeSwitch/ModeSwitch';\nimport { useGlobalKeyDown } from '../../../../../hooks/useGlobalKeyDown';\nimport { Shortcut } from '../../../../Shortcut/Shortcut';\n\ntype EditingProps<TType = unknown> = React.HTMLAttributes<HTMLButtonElement> & {\n scrollToIndex: any;\n table: ReactTable<TType>;\n};\n\nexport function Editing<TType = unknown>(props: EditingProps<TType>) {\n const { scrollToIndex, table } = props;\n const { texts } = useLocalization();\n const ref = React.useRef<HTMLButtonElement>(null);\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n\n const shortcut = { key: 'e', meta: true, shift: false };\n const tooltip = (\n <>\n {texts.table3.editing.buttons.edit.tooltip}\n <Shortcut className=\"ml-2\" keys={shortcut} />\n </>\n );\n\n useGlobalKeyDown(shortcut, (event: KeyboardEvent) => {\n event.preventDefault();\n ref.current?.click();\n });\n\n const handleChange = (enabled: boolean) => {\n if (enabled && tableMeta.rowActive.rowActiveIndex === undefined) {\n tableMeta.rowActive.setRowActiveIndex(0);\n }\n\n requestAnimationFrame(() => {\n // wait for an active row to be set so that we don't trigger save\n tableMeta.editing.toggleEditing(enabled, table);\n scrollToIndex(tableMeta.rowActive.rowActiveIndex ?? 0);\n });\n };\n\n return (\n <Tooltip title={tooltip}>\n <ModeSwitch data-table=\"editing-toggle\" checked={tableMeta.editing.isEditing} onChange={handleChange} ref={ref} />\n </Tooltip>\n );\n}\n"],"names":["Editing","props","scrollToIndex","table","texts","useLocalization","ref","React","useRef","tableMeta","options","meta","shortcut","key","shift","tooltip","table3","editing","buttons","edit","Shortcut","className","keys","useGlobalKeyDown","event","preventDefault","_ref$current","current","click","handleChange","enabled","rowActive","rowActiveIndex","undefined","setRowActiveIndex","requestAnimationFrame","toggleEditing","_tableMeta$rowActive$","Tooltip","title","ModeSwitch","checked","isEditing","onChange"],"mappings":";;;;;;;SAagBA,OAAOA,CAAkBC,KAA0B;EAC/D,MAAM;IAAEC,aAAa;IAAEC;GAAO,GAAGF,KAAK;EACtC,MAAM;IAAEG;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,GAAG,GAAGC,cAAK,CAACC,MAAM,CAAoB,IAAI,CAAC;EACjD,MAAMC,SAAS,GAAGN,KAAK,CAACO,OAAO,CAACC,IAA6B;EAE7D,MAAMC,QAAQ,GAAG;IAAEC,GAAG,EAAE,GAAG;IAAEF,IAAI,EAAE,IAAI;IAAEG,KAAK,EAAE;GAAO;EACvD,MAAMC,OAAO,gBACTR,4DACKH,KAAK,CAACY,MAAM,CAACC,OAAO,CAACC,OAAO,CAACC,IAAI,CAACJ,OAAO,eAC1CR,6BAACa,QAAQ;IAACC,SAAS,EAAC,MAAM;IAACC,IAAI,EAAEV;IAAY,CAEpD;EAEDW,gBAAgB,CAACX,QAAQ,EAAGY,KAAoB;;IAC5CA,KAAK,CAACC,cAAc,EAAE;IACtB,CAAAC,YAAA,GAAApB,GAAG,CAACqB,OAAO,cAAAD,YAAA,uBAAXA,YAAA,CAAaE,KAAK,EAAE;GACvB,CAAC;EAEF,MAAMC,YAAY,GAAIC,OAAgB;IAClC,IAAIA,OAAO,IAAIrB,SAAS,CAACsB,SA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