persian-data-grid 0.5.0 → 0.6.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 (282) hide show
  1. package/OFL.txt +93 -0
  2. package/README.md +179 -22
  3. package/dist/ERPTableGroupRow-J5Z2LRC5.cjs +131 -0
  4. package/dist/ERPTableGroupRow-J5Z2LRC5.cjs.map +1 -0
  5. package/dist/ERPTableGroupRow-PSAPAHGL.js +125 -0
  6. package/dist/ERPTableGroupRow-PSAPAHGL.js.map +1 -0
  7. package/dist/GridPlugin-CJCaYnlw.d.ts +57 -0
  8. package/dist/GridPlugin-oxhq8AsM.d.cts +57 -0
  9. package/dist/GridPresenceService-GEH6535Q.js +3 -0
  10. package/dist/GridPresenceService-GEH6535Q.js.map +1 -0
  11. package/dist/GridPresenceService-RDN5FXHQ.cjs +12 -0
  12. package/dist/GridPresenceService-RDN5FXHQ.cjs.map +1 -0
  13. package/dist/GridSession-B-9lLcoB.d.cts +2492 -0
  14. package/dist/GridSession-Bc7UIawO.d.ts +2492 -0
  15. package/dist/GridSyncService-KTLB4KP3.js +3 -0
  16. package/dist/GridSyncService-KTLB4KP3.js.map +1 -0
  17. package/dist/GridSyncService-TAPAHABV.cjs +12 -0
  18. package/dist/GridSyncService-TAPAHABV.cjs.map +1 -0
  19. package/dist/PdfRenderer-1HFh6UeR.d.ts +22 -0
  20. package/dist/PdfRenderer-CBg7hWNS.d.cts +22 -0
  21. package/dist/RemoteApi-CCQxiSf1.d.cts +28 -0
  22. package/dist/RemoteApi-CCQxiSf1.d.ts +28 -0
  23. package/dist/SelectImpl-NM4O4IGW.js +447 -0
  24. package/dist/SelectImpl-NM4O4IGW.js.map +1 -0
  25. package/dist/SelectImpl-W2EI4T7O.cjs +453 -0
  26. package/dist/SelectImpl-W2EI4T7O.cjs.map +1 -0
  27. package/dist/UITableController-Cuwq481K.d.cts +632 -0
  28. package/dist/UITableController-DU8RopUM.d.ts +632 -0
  29. package/dist/VazirmatnPdfRenderer-BCMpC1zy.d.cts +96 -0
  30. package/dist/VazirmatnPdfRenderer-Dz_G-m3c.d.ts +96 -0
  31. package/dist/adapters/arian-erp.cjs +77 -0
  32. package/dist/adapters/arian-erp.cjs.map +1 -0
  33. package/dist/adapters/arian-erp.d.cts +60 -0
  34. package/dist/adapters/arian-erp.d.ts +60 -0
  35. package/dist/adapters/arian-erp.js +71 -0
  36. package/dist/adapters/arian-erp.js.map +1 -0
  37. package/dist/appendAtEnd-RHIQRG2W.cjs +35 -0
  38. package/dist/appendAtEnd-RHIQRG2W.cjs.map +1 -0
  39. package/dist/appendAtEnd-TJEABLGD.js +33 -0
  40. package/dist/appendAtEnd-TJEABLGD.js.map +1 -0
  41. package/dist/applyImportedRows-BO6yxoAN.d.cts +135 -0
  42. package/dist/applyImportedRows-D4zVY8uD.d.ts +135 -0
  43. package/dist/applyRowVisibilityHandler-KS6TMCBN.js +83 -0
  44. package/dist/applyRowVisibilityHandler-KS6TMCBN.js.map +1 -0
  45. package/dist/applyRowVisibilityHandler-LXCOGESZ.cjs +85 -0
  46. package/dist/applyRowVisibilityHandler-LXCOGESZ.cjs.map +1 -0
  47. package/dist/broadcastChannelTransport-FHUMV76O.cjs +12 -0
  48. package/dist/broadcastChannelTransport-FHUMV76O.cjs.map +1 -0
  49. package/dist/broadcastChannelTransport-MIH53VNZ.js +3 -0
  50. package/dist/broadcastChannelTransport-MIH53VNZ.js.map +1 -0
  51. package/dist/callbackRemoteApi-BlXO5NJz.d.ts +30 -0
  52. package/dist/callbackRemoteApi-DgnXH-i0.d.cts +30 -0
  53. package/dist/cellRenderContext-DB7V_mlu.d.ts +42 -0
  54. package/dist/cellRenderContext-DG5BOlxK.d.cts +42 -0
  55. package/dist/chunk-2BJCRYOS.cjs +936 -0
  56. package/dist/chunk-2BJCRYOS.cjs.map +1 -0
  57. package/dist/chunk-3Y3KKGEC.js +3 -0
  58. package/dist/chunk-3Y3KKGEC.js.map +1 -0
  59. package/dist/chunk-5ALMNLUR.cjs +1408 -0
  60. package/dist/chunk-5ALMNLUR.cjs.map +1 -0
  61. package/dist/chunk-5HKVMPBD.js +937 -0
  62. package/dist/chunk-5HKVMPBD.js.map +1 -0
  63. package/dist/chunk-633KP74Z.js +189 -0
  64. package/dist/chunk-633KP74Z.js.map +1 -0
  65. package/dist/chunk-6XBXZPBW.js +298 -0
  66. package/dist/chunk-6XBXZPBW.js.map +1 -0
  67. package/dist/chunk-77UXAJII.js +112 -0
  68. package/dist/chunk-77UXAJII.js.map +1 -0
  69. package/dist/chunk-ASPTRYRD.cjs +21 -0
  70. package/dist/chunk-ASPTRYRD.cjs.map +1 -0
  71. package/dist/chunk-AU3RDJYQ.js +243 -0
  72. package/dist/chunk-AU3RDJYQ.js.map +1 -0
  73. package/dist/chunk-BHDRUZH5.cjs +33 -0
  74. package/dist/chunk-BHDRUZH5.cjs.map +1 -0
  75. package/dist/chunk-BLYVOV3G.cjs +191 -0
  76. package/dist/chunk-BLYVOV3G.cjs.map +1 -0
  77. package/dist/chunk-CILNIWYW.cjs +100 -0
  78. package/dist/chunk-CILNIWYW.cjs.map +1 -0
  79. package/dist/chunk-DFFP7SJ6.cjs +257 -0
  80. package/dist/chunk-DFFP7SJ6.cjs.map +1 -0
  81. package/dist/chunk-DXRCYW42.cjs +568 -0
  82. package/dist/chunk-DXRCYW42.cjs.map +1 -0
  83. package/dist/chunk-EBV6HGZB.cjs +33 -0
  84. package/dist/chunk-EBV6HGZB.cjs.map +1 -0
  85. package/dist/chunk-EHHHC5JV.js +832 -0
  86. package/dist/chunk-EHHHC5JV.js.map +1 -0
  87. package/dist/chunk-F4PYOYHR.js +112 -0
  88. package/dist/chunk-F4PYOYHR.js.map +1 -0
  89. package/dist/chunk-GQEDLUMB.js +168 -0
  90. package/dist/chunk-GQEDLUMB.js.map +1 -0
  91. package/dist/chunk-H2LESGMX.cjs +319 -0
  92. package/dist/chunk-H2LESGMX.cjs.map +1 -0
  93. package/dist/chunk-HTNJT2QU.js +11674 -0
  94. package/dist/chunk-HTNJT2QU.js.map +1 -0
  95. package/dist/chunk-IIISFUW4.cjs +11786 -0
  96. package/dist/chunk-IIISFUW4.cjs.map +1 -0
  97. package/dist/chunk-IMPCRWYP.cjs +251 -0
  98. package/dist/chunk-IMPCRWYP.cjs.map +1 -0
  99. package/dist/chunk-IPPIXOVQ.js +317 -0
  100. package/dist/chunk-IPPIXOVQ.js.map +1 -0
  101. package/dist/chunk-J4XJ4UBC.js +1404 -0
  102. package/dist/chunk-J4XJ4UBC.js.map +1 -0
  103. package/dist/chunk-J7CPPFXT.cjs +89 -0
  104. package/dist/chunk-J7CPPFXT.cjs.map +1 -0
  105. package/dist/chunk-JOICD47Q.cjs +41 -0
  106. package/dist/chunk-JOICD47Q.cjs.map +1 -0
  107. package/dist/chunk-KHMG6EI2.js +13 -0
  108. package/dist/chunk-KHMG6EI2.js.map +1 -0
  109. package/dist/chunk-KMRURD5J.cjs +15 -0
  110. package/dist/chunk-KMRURD5J.cjs.map +1 -0
  111. package/dist/chunk-KRJG3KMP.cjs +174 -0
  112. package/dist/chunk-KRJG3KMP.cjs.map +1 -0
  113. package/dist/chunk-KUBVDIF7.cjs +653 -0
  114. package/dist/chunk-KUBVDIF7.cjs.map +1 -0
  115. package/dist/chunk-KYAOSBQN.js +31 -0
  116. package/dist/chunk-KYAOSBQN.js.map +1 -0
  117. package/dist/chunk-LJ7LMEXO.js +36 -0
  118. package/dist/chunk-LJ7LMEXO.js.map +1 -0
  119. package/dist/chunk-MT3KLB2Q.cjs +944 -0
  120. package/dist/chunk-MT3KLB2Q.cjs.map +1 -0
  121. package/dist/chunk-MU3RY46O.js +932 -0
  122. package/dist/chunk-MU3RY46O.js.map +1 -0
  123. package/dist/chunk-MUQQKPWR.js +84 -0
  124. package/dist/chunk-MUQQKPWR.js.map +1 -0
  125. package/dist/chunk-N7SJTINL.cjs +4 -0
  126. package/dist/chunk-N7SJTINL.cjs.map +1 -0
  127. package/dist/chunk-NTV2UUAJ.cjs +149 -0
  128. package/dist/chunk-NTV2UUAJ.cjs.map +1 -0
  129. package/dist/chunk-PJQWHF6T.js +31 -0
  130. package/dist/chunk-PJQWHF6T.js.map +1 -0
  131. package/dist/chunk-PQY54EL5.js +248 -0
  132. package/dist/chunk-PQY54EL5.js.map +1 -0
  133. package/dist/chunk-PXCHPZTP.cjs +839 -0
  134. package/dist/chunk-PXCHPZTP.cjs.map +1 -0
  135. package/dist/chunk-Q7TBBUTX.cjs +110 -0
  136. package/dist/chunk-Q7TBBUTX.cjs.map +1 -0
  137. package/dist/chunk-QQMU44KJ.js +612 -0
  138. package/dist/chunk-QQMU44KJ.js.map +1 -0
  139. package/dist/chunk-QZN7R2WP.cjs +114 -0
  140. package/dist/chunk-QZN7R2WP.cjs.map +1 -0
  141. package/dist/chunk-RKVSJU46.js +35 -0
  142. package/dist/chunk-RKVSJU46.js.map +1 -0
  143. package/dist/chunk-RM6ZWNT3.js +561 -0
  144. package/dist/chunk-RM6ZWNT3.js.map +1 -0
  145. package/dist/chunk-SX4VQXAA.cjs +114 -0
  146. package/dist/chunk-SX4VQXAA.cjs.map +1 -0
  147. package/dist/chunk-SZ7BLAY3.js +92 -0
  148. package/dist/chunk-SZ7BLAY3.js.map +1 -0
  149. package/dist/chunk-TN4MG6FY.js +112 -0
  150. package/dist/chunk-TN4MG6FY.js.map +1 -0
  151. package/dist/chunk-UC7PHDM6.cjs +331 -0
  152. package/dist/chunk-UC7PHDM6.cjs.map +1 -0
  153. package/dist/chunk-UXVLYUUW.js +108 -0
  154. package/dist/chunk-UXVLYUUW.js.map +1 -0
  155. package/dist/chunk-VVGYRZ7S.cjs +38 -0
  156. package/dist/chunk-VVGYRZ7S.cjs.map +1 -0
  157. package/dist/chunk-W5256BJ4.js +56 -0
  158. package/dist/chunk-W5256BJ4.js.map +1 -0
  159. package/dist/chunk-WUMOSOEK.cjs +62 -0
  160. package/dist/chunk-WUMOSOEK.cjs.map +1 -0
  161. package/dist/chunk-XLRE2J25.js +140 -0
  162. package/dist/chunk-XLRE2J25.js.map +1 -0
  163. package/dist/chunk-Y6W5V2CI.js +19 -0
  164. package/dist/chunk-Y6W5V2CI.js.map +1 -0
  165. package/dist/chunk-Z4QPZ3Z3.cjs +114 -0
  166. package/dist/chunk-Z4QPZ3Z3.cjs.map +1 -0
  167. package/dist/createEngineGridQuery-Dmq3i5v3.d.cts +884 -0
  168. package/dist/createEngineGridQuery-Mt1hc33m.d.ts +884 -0
  169. package/dist/date-picker-jalali.cjs +263 -0
  170. package/dist/date-picker-jalali.cjs.map +1 -0
  171. package/dist/date-picker-jalali.d.cts +62 -0
  172. package/dist/date-picker-jalali.d.ts +62 -0
  173. package/dist/date-picker-jalali.js +256 -0
  174. package/dist/date-picker-jalali.js.map +1 -0
  175. package/dist/finance.cjs +205 -0
  176. package/dist/finance.cjs.map +1 -0
  177. package/dist/finance.d.cts +90 -0
  178. package/dist/finance.d.ts +90 -0
  179. package/dist/finance.js +157 -0
  180. package/dist/finance.js.map +1 -0
  181. package/dist/foldedColumn-IHDT4ARZ.cjs +66 -0
  182. package/dist/foldedColumn-IHDT4ARZ.cjs.map +1 -0
  183. package/dist/foldedColumn-TFURUKFG.js +64 -0
  184. package/dist/foldedColumn-TFURUKFG.js.map +1 -0
  185. package/dist/headless.cjs +729 -0
  186. package/dist/headless.cjs.map +1 -0
  187. package/dist/headless.d.cts +504 -0
  188. package/dist/headless.d.ts +504 -0
  189. package/dist/headless.js +226 -0
  190. package/dist/headless.js.map +1 -0
  191. package/dist/index-DN8M8Jkq.d.cts +14 -0
  192. package/dist/index-DmzL-F_o.d.ts +14 -0
  193. package/dist/index.cjs +8002 -11409
  194. package/dist/index.cjs.map +1 -1
  195. package/dist/index.d.cts +437 -2305
  196. package/dist/index.d.ts +437 -2305
  197. package/dist/index.js +7244 -11083
  198. package/dist/index.js.map +1 -1
  199. package/dist/locales/ar.cjs +12 -0
  200. package/dist/locales/ar.cjs.map +1 -0
  201. package/dist/locales/ar.d.cts +6 -0
  202. package/dist/locales/ar.d.ts +6 -0
  203. package/dist/locales/ar.js +3 -0
  204. package/dist/locales/ar.js.map +1 -0
  205. package/dist/locales/en.cjs +12 -0
  206. package/dist/locales/en.cjs.map +1 -0
  207. package/dist/locales/en.d.cts +6 -0
  208. package/dist/locales/en.d.ts +6 -0
  209. package/dist/locales/en.js +3 -0
  210. package/dist/locales/en.js.map +1 -0
  211. package/dist/locales/fa.cjs +12 -0
  212. package/dist/locales/fa.cjs.map +1 -0
  213. package/dist/locales/fa.d.cts +6 -0
  214. package/dist/locales/fa.d.ts +6 -0
  215. package/dist/locales/fa.js +3 -0
  216. package/dist/locales/fa.js.map +1 -0
  217. package/dist/locales/index.cjs +51 -0
  218. package/dist/locales/index.cjs.map +1 -0
  219. package/dist/locales/index.d.cts +5 -0
  220. package/dist/locales/index.d.ts +5 -0
  221. package/dist/locales/index.js +6 -0
  222. package/dist/locales/index.js.map +1 -0
  223. package/dist/memoryRecords-AWDKUJ2F.cjs +50 -0
  224. package/dist/memoryRecords-AWDKUJ2F.cjs.map +1 -0
  225. package/dist/memoryRecords-OJTGXLRH.js +47 -0
  226. package/dist/memoryRecords-OJTGXLRH.js.map +1 -0
  227. package/dist/pagedFooterTotals-DXCGDO6F.cjs +27 -0
  228. package/dist/pagedFooterTotals-DXCGDO6F.cjs.map +1 -0
  229. package/dist/pagedFooterTotals-ORWKUNE7.js +25 -0
  230. package/dist/pagedFooterTotals-ORWKUNE7.js.map +1 -0
  231. package/dist/pagedKit-MFGAJFSK.cjs +134 -0
  232. package/dist/pagedKit-MFGAJFSK.cjs.map +1 -0
  233. package/dist/pagedKit-WYWY4LRV.js +127 -0
  234. package/dist/pagedKit-WYWY4LRV.js.map +1 -0
  235. package/dist/pagedSearch-HCPJW7VM.js +38 -0
  236. package/dist/pagedSearch-HCPJW7VM.js.map +1 -0
  237. package/dist/pagedSearch-U3WCG4GN.cjs +42 -0
  238. package/dist/pagedSearch-U3WCG4GN.cjs.map +1 -0
  239. package/dist/plugins/csv.cjs +124 -0
  240. package/dist/plugins/csv.cjs.map +1 -0
  241. package/dist/plugins/csv.d.cts +44 -0
  242. package/dist/plugins/csv.d.ts +44 -0
  243. package/dist/plugins/csv.js +120 -0
  244. package/dist/plugins/csv.js.map +1 -0
  245. package/dist/plugins/excel.cjs +52 -0
  246. package/dist/plugins/excel.cjs.map +1 -0
  247. package/dist/plugins/excel.d.cts +14 -0
  248. package/dist/plugins/excel.d.ts +14 -0
  249. package/dist/plugins/excel.js +7 -0
  250. package/dist/plugins/excel.js.map +1 -0
  251. package/dist/plugins/pdf/fonts/vazirmatn.cjs +50 -0
  252. package/dist/plugins/pdf/fonts/vazirmatn.cjs.map +1 -0
  253. package/dist/plugins/pdf/fonts/vazirmatn.d.cts +24 -0
  254. package/dist/plugins/pdf/fonts/vazirmatn.d.ts +24 -0
  255. package/dist/plugins/pdf/fonts/vazirmatn.js +39 -0
  256. package/dist/plugins/pdf/fonts/vazirmatn.js.map +1 -0
  257. package/dist/plugins/pdf.cjs +24 -0
  258. package/dist/plugins/pdf.cjs.map +1 -0
  259. package/dist/plugins/pdf.d.cts +21 -0
  260. package/dist/plugins/pdf.d.ts +21 -0
  261. package/dist/plugins/pdf.js +7 -0
  262. package/dist/plugins/pdf.js.map +1 -0
  263. package/dist/presence.cjs +56 -0
  264. package/dist/presence.cjs.map +1 -0
  265. package/dist/presence.d.cts +17 -0
  266. package/dist/presence.d.ts +17 -0
  267. package/dist/presence.js +54 -0
  268. package/dist/presence.js.map +1 -0
  269. package/dist/rebuildRowVisibility-66EAZ356.cjs +21 -0
  270. package/dist/rebuildRowVisibility-66EAZ356.cjs.map +1 -0
  271. package/dist/rebuildRowVisibility-6TYM5BP2.js +19 -0
  272. package/dist/rebuildRowVisibility-6TYM5BP2.js.map +1 -0
  273. package/dist/styles.css +1440 -0
  274. package/dist/sync.cjs +148 -0
  275. package/dist/sync.cjs.map +1 -0
  276. package/dist/sync.d.cts +17 -0
  277. package/dist/sync.d.ts +17 -0
  278. package/dist/sync.js +146 -0
  279. package/dist/sync.js.map +1 -0
  280. package/dist/types-D__47BKv.d.cts +23 -0
  281. package/dist/types-D__47BKv.d.ts +23 -0
  282. package/package.json +184 -28
@@ -0,0 +1,561 @@
1
+ import { DomainError } from './chunk-KHMG6EI2.js';
2
+ import { ColumnId, RowId } from './chunk-XLRE2J25.js';
3
+
4
+ // application/handlers/cellCommandsHandler.ts
5
+ function logError(audit, error, context) {
6
+ if (error instanceof DomainError) {
7
+ audit.log({
8
+ type: error.code,
9
+ message: error.message,
10
+ payload: { details: error.details, context }
11
+ });
12
+ } else if (error instanceof Error) {
13
+ audit.log({
14
+ type: "INVARIANT_VIOLATION",
15
+ message: error.message,
16
+ payload: { stack: error.stack, context }
17
+ });
18
+ } else {
19
+ audit.log({
20
+ type: "INVARIANT_VIOLATION",
21
+ message: "Unexpected error",
22
+ payload: { error, context }
23
+ });
24
+ }
25
+ }
26
+ async function applyRemoteVisibilityRules(dynamic, input) {
27
+ const {
28
+ table,
29
+ rowId,
30
+ changedColumnId,
31
+ newValue,
32
+ clearDependents = true
33
+ } = input;
34
+ const meta = dynamic?.columnMeta;
35
+ if (!meta) return;
36
+ const colKey = `${table.getActiveCollectionName() ?? "default"}_${changedColumnId.value}`;
37
+ const changedMeta = meta.get(colKey) ?? meta.get(changedColumnId.value);
38
+ const resolveOn = changedMeta?.resolveOn;
39
+ if (!resolveOn) return;
40
+ if (resolveOn.fieldName !== changedColumnId.value) return;
41
+ const row = table.getRows().find((r) => r.id.value === rowId.value);
42
+ if (!row) return;
43
+ const rowValues = {};
44
+ for (const [colId, cell] of row.getCells().entries()) {
45
+ rowValues[colId] = cell.getValue();
46
+ }
47
+ if (newValue == null || newValue === "") return;
48
+ const params = typeof resolveOn.buildParams === "function" ? resolveOn.buildParams(rowValues) : { value: newValue };
49
+ const response = await dynamic.remoteApi.request({
50
+ endpoint: resolveOn.endpoint,
51
+ params,
52
+ method: "POST"
53
+ });
54
+ resolveOn.getResponse?.(response, row);
55
+ const flags = resolveOn.mapFlags?.(response) ?? {};
56
+ const toShow = [];
57
+ const visibilityCondition = {};
58
+ const activeCollection = table.getActiveCollectionName() ?? "default";
59
+ meta.forEach((colCfg) => {
60
+ if ((colCfg.fieldCollection ?? "default") !== activeCollection) return;
61
+ const v = colCfg.visibility;
62
+ if (v?.kind === "whenRemoteFlag" && v.sourceFieldName === changedColumnId.value) {
63
+ const colId = new ColumnId(colCfg.fieldName);
64
+ const schema = table.getColumnSchema(colId);
65
+ const flagValue = flags[v.flag] ?? false;
66
+ visibilityCondition[colCfg.fieldName] = flagValue;
67
+ if (flagValue && schema) {
68
+ toShow.push({ ...schema, hidden: false });
69
+ }
70
+ }
71
+ const dependency = colCfg.dynamicSource?.dependsOn;
72
+ if (clearDependents && dependency && dependency.includes(changedColumnId.value) && !Object.hasOwn(visibilityCondition, colCfg.fieldName) && colCfg.visibility?.kind !== "whenTableType" && colCfg.visibility?.kind !== "whenCollection") {
73
+ const cell = row.getCell(colCfg.fieldName);
74
+ cell?.changeValue(null);
75
+ cell?.changeDisplay(null);
76
+ }
77
+ });
78
+ if (toShow.length > 0) {
79
+ table.addColumns(toShow);
80
+ }
81
+ row.setVisibilityCondition(visibilityCondition);
82
+ }
83
+ var ChangeCellValueHandler = class {
84
+ constructor(repo, audit, permissionPolicy, dynamic) {
85
+ this.repo = repo;
86
+ this.audit = audit;
87
+ this.permissionPolicy = permissionPolicy;
88
+ this.dynamic = dynamic;
89
+ }
90
+ async execute(command, actor) {
91
+ const table = await this.repo.getById(command.store, command.tableKey);
92
+ try {
93
+ const rowId = new RowId(command.rowId);
94
+ const columnId = new ColumnId(command.columnId);
95
+ const schema = table.getColumnSchema(columnId);
96
+ if (!schema) {
97
+ throw new DomainError("COLUMN_NOT_FOUND", "Column does not exist", {
98
+ columnId: columnId.value
99
+ });
100
+ }
101
+ if (schema.editable === false) {
102
+ throw new DomainError("NOT_EDITABLE", "Cell is not editable", {
103
+ rowId: rowId.value,
104
+ columnId: columnId.value
105
+ });
106
+ }
107
+ if (!this.permissionPolicy.canChangeCell({
108
+ actor,
109
+ rowId: command.rowId,
110
+ columnId: command.columnId
111
+ })) {
112
+ throw new DomainError(
113
+ "FORBIDDEN",
114
+ "Actor is not allowed to change this cell",
115
+ { actor, rowId: rowId.value, columnId: columnId.value }
116
+ );
117
+ }
118
+ const validated = this.validateCellValue(schema.fieldType, command.newValue);
119
+ const domainEvent = table.changeCell(rowId, columnId, validated.value);
120
+ if (!domainEvent) {
121
+ throw new DomainError(
122
+ "CELL_NOT_FOUND",
123
+ "Cell not found or value not changed",
124
+ { rowId: rowId.value, columnId: columnId.value }
125
+ );
126
+ }
127
+ if (this.dynamic) {
128
+ await this.applyComputedColumns({
129
+ table,
130
+ rowId,
131
+ changedColumnId: columnId,
132
+ remoteApi: this.dynamic.remoteApi
133
+ });
134
+ await this.applyRemoteVisibilityRules({
135
+ table,
136
+ rowId,
137
+ changedColumnId: columnId,
138
+ newValue: command.newValue
139
+ });
140
+ this.applyDynamicProjection({
141
+ table,
142
+ rowId,
143
+ changedColumnId: columnId,
144
+ validatedValue: command.newValue
145
+ });
146
+ }
147
+ const state = table.getRows().find((r) => r.id.value === rowId.value)?.getCells().get("RowState")?.getValue();
148
+ if (state === "None" /* Unchanged */) {
149
+ table.changeCell(rowId, new ColumnId("RowState"), "Update" /* Modified */);
150
+ table.changeDisplay(rowId, new ColumnId("RowState"), "Update" /* Modified */);
151
+ }
152
+ await this.repo.save(command.store, table);
153
+ const out = {
154
+ type: "CELL_CHANGED",
155
+ tableId: command.tableKey,
156
+ rowId: domainEvent.rowId.value,
157
+ columnId: domainEvent.columnId.value,
158
+ newValue: domainEvent.newValue,
159
+ previousValue: domainEvent.previousValue
160
+ };
161
+ this.audit.log({ type: "CELL_CHANGED", message: out.type, payload: out });
162
+ return [out];
163
+ } catch (e) {
164
+ logError(this.audit, e, `ChangeCellValueHandler[${command.tableKey}:${command.rowId}:${command.columnId}]`);
165
+ return [];
166
+ }
167
+ }
168
+ /* ── helpers ─────────────────────────────────────────────────────── */
169
+ applyRemoteVisibilityRules(input) {
170
+ return applyRemoteVisibilityRules(this.dynamic, input);
171
+ }
172
+ async applyComputedColumns(input) {
173
+ const { table, rowId, changedColumnId, remoteApi } = input;
174
+ const meta = this.dynamic.columnMeta;
175
+ const computedColumns = Array.from(meta.values()).filter(
176
+ (c) => c.computed != null
177
+ );
178
+ if (computedColumns.length === 0) return;
179
+ const row = table.getRows().find((r) => r.id.value === rowId.value);
180
+ if (!row) return;
181
+ const rowValues = {};
182
+ for (const [colId, cell] of row.getCells().entries()) {
183
+ rowValues[colId] = cell.getValue();
184
+ }
185
+ const dependents = /* @__PURE__ */ new Map();
186
+ for (const col of computedColumns) {
187
+ for (const dep of col.computed.dependsOn ?? []) {
188
+ if (!dependents.has(dep)) dependents.set(dep, []);
189
+ dependents.get(dep).push(col);
190
+ }
191
+ }
192
+ const queue = [changedColumnId.value];
193
+ const visited = /* @__PURE__ */ new Set();
194
+ let safetyCounter = 0;
195
+ const MAX = computedColumns.length + 1;
196
+ while (queue.length > 0) {
197
+ if (safetyCounter++ > MAX) {
198
+ throw new Error("Computed cycle detected");
199
+ }
200
+ const source = queue.shift();
201
+ const targets = dependents.get(source) ?? [];
202
+ for (const colCfg of targets) {
203
+ const targetField = colCfg.fieldName;
204
+ const targetColId = new ColumnId(targetField);
205
+ const schema = table.getColumnSchema(targetColId);
206
+ if (!schema || !colCfg.computed) continue;
207
+ const rawValue = colCfg.computed.compute(rowValues, remoteApi);
208
+ const newValue = rawValue instanceof Promise ? await rawValue : rawValue;
209
+ const validated = this.validateCellValue(schema.fieldType, newValue);
210
+ if (validated.value instanceof Promise) {
211
+ throw new Error(
212
+ `Computed column "${targetField}" returned a Promise after validation`
213
+ );
214
+ }
215
+ const prev = rowValues[targetField];
216
+ if (Object.is(prev, validated.value)) continue;
217
+ table.changeCell(rowId, targetColId, validated.value);
218
+ if (schema.displayFormat) {
219
+ const validatedDisplay = this.validateCellValue(
220
+ schema.fieldType,
221
+ schema.displayFormat(newValue)
222
+ );
223
+ table.changeDisplay(rowId, targetColId, validatedDisplay.value);
224
+ } else {
225
+ table.changeDisplay(rowId, targetColId, validated.value);
226
+ }
227
+ rowValues[targetField] = validated.value;
228
+ queue.push(targetField);
229
+ visited.add(targetField);
230
+ }
231
+ }
232
+ }
233
+ validateCellValue(type, value) {
234
+ switch (type) {
235
+ case "text":
236
+ case "textArea":
237
+ case "description":
238
+ case "date":
239
+ return typeof value === "string" ? { ok: true, value } : { ok: false, error: { message: "Expected string", details: { value } }, value };
240
+ case "static":
241
+ return { ok: true, value };
242
+ case "checkbox":
243
+ return typeof value === "boolean" ? { ok: true, value } : { ok: false, error: { message: "Expected boolean", details: { value } }, value };
244
+ case "number":
245
+ case "price":
246
+ case "select":
247
+ case "selectOption": {
248
+ if (value === "" || value === void 0) {
249
+ return { ok: true, value };
250
+ }
251
+ const n = typeof value === "number" ? value : Number(value);
252
+ return Number.isFinite(n) ? { ok: true, value: n } : { ok: false, error: { message: "Expected number", details: { value } }, value };
253
+ }
254
+ default:
255
+ return { ok: false, error: { message: "Unsupported type", details: { type, value } }, value };
256
+ }
257
+ }
258
+ applyDynamicProjection(input) {
259
+ const { table, changedColumnId, validatedValue } = input;
260
+ const activeCollection = table.getActiveCollectionName() ?? "default";
261
+ this.dynamic.columnMeta.forEach((colMeta, key) => {
262
+ if ((colMeta.fieldCollection ?? "default") !== activeCollection) return;
263
+ const col = table.getColumnSchema(new ColumnId(colMeta.fieldName));
264
+ const depends = colMeta.dynamicSource?.dependsOn;
265
+ if (depends?.includes(changedColumnId.value)) {
266
+ const { dynamicSource } = colMeta;
267
+ const { endpoint, dependsOn, ...restDynamic } = dynamicSource ?? {};
268
+ const base = col ?? colMeta;
269
+ table.setColumnSchema(new ColumnId(base.fieldName), {
270
+ ...base,
271
+ dynamicSelectFilterOption: base.dynamicSelectFilterOption ?? (() => true),
272
+ dynamicSource: {
273
+ endpoint: endpoint ?? "",
274
+ ...restDynamic,
275
+ dependOn: {
276
+ fieldName: changedColumnId.value,
277
+ value: validatedValue
278
+ }
279
+ }
280
+ });
281
+ }
282
+ if (colMeta.visibility?.kind === "whenFieldTruthy" && colMeta.visibility.fieldName === changedColumnId.value && col) {
283
+ table.setColumnSchema(new ColumnId(colMeta.fieldName), col);
284
+ }
285
+ });
286
+ }
287
+ };
288
+ var ChangeCellDisplayValueHandler = class {
289
+ constructor(repo, audit, permissionPolicy) {
290
+ this.repo = repo;
291
+ this.audit = audit;
292
+ this.permissionPolicy = permissionPolicy;
293
+ }
294
+ async execute(command, actor) {
295
+ const table = await this.repo.getById(command.store, command.tableKey);
296
+ try {
297
+ const rowId = new RowId(command.rowId);
298
+ const columnId = new ColumnId(command.columnId);
299
+ const schema = table.getColumnSchema(columnId);
300
+ if (!schema) {
301
+ throw new DomainError("COLUMN_NOT_FOUND", "Column does not exist", {
302
+ columnId: columnId.value
303
+ });
304
+ }
305
+ if (schema.editable === false) {
306
+ throw new DomainError("NOT_EDITABLE", "Cell is not editable", {
307
+ rowId: rowId.value,
308
+ columnId: columnId.value
309
+ });
310
+ }
311
+ if (!this.permissionPolicy.canChangeCell({
312
+ actor,
313
+ rowId: command.rowId,
314
+ columnId: command.columnId
315
+ })) {
316
+ throw new DomainError(
317
+ "FORBIDDEN",
318
+ "Actor is not allowed to change this cell",
319
+ { actor, rowId: rowId.value, columnId: columnId.value }
320
+ );
321
+ }
322
+ const domainEvent = table.changeDisplay(rowId, columnId, command.newValue);
323
+ if (!domainEvent) {
324
+ throw new DomainError(
325
+ "CELL_NOT_FOUND",
326
+ "Cell not found or value not changed",
327
+ { rowId: rowId.value, columnId: columnId.value }
328
+ );
329
+ }
330
+ await this.repo.save(command.store, table);
331
+ const out = {
332
+ type: "CELL_DISPLAY_CHANGED",
333
+ tableId: command.tableKey,
334
+ rowId: domainEvent.rowId.value,
335
+ columnId: domainEvent.columnId.value,
336
+ newValue: domainEvent.newValue
337
+ };
338
+ this.audit.log({ type: "CELL_DISPLAY_CHANGED", message: out.type, payload: out });
339
+ return [out];
340
+ } catch (e) {
341
+ logError(this.audit, e, `ChangeCellDisplayValueHandler[${command.tableKey}:${command.rowId}:${command.columnId}]`);
342
+ return [];
343
+ }
344
+ }
345
+ };
346
+ var SaveDescriptionHandler = class {
347
+ constructor(repo, audit, permissionPolicy) {
348
+ this.repo = repo;
349
+ this.audit = audit;
350
+ this.permissionPolicy = permissionPolicy;
351
+ }
352
+ async execute(command, actor) {
353
+ const table = await this.repo.getById(command.store, command.tableKey);
354
+ try {
355
+ const rowId = new RowId(command.rowId);
356
+ const domainEvent = table.saveDescription(rowId, command.flag);
357
+ if (!domainEvent) {
358
+ throw new DomainError(
359
+ "CELL_NOT_FOUND",
360
+ "Cell not found or value not changed",
361
+ { rowId: rowId.value, flag: command.flag }
362
+ );
363
+ }
364
+ await this.repo.save(command.store, table);
365
+ const out = {
366
+ type: "ROW_DESCRIPTION_SAVED",
367
+ tableId: command.tableKey,
368
+ rowId: domainEvent.rowId.value,
369
+ description: command.flag
370
+ };
371
+ this.audit.log({ type: "INFORMATION", message: out.type, payload: out });
372
+ return [out];
373
+ } catch (e) {
374
+ logError(this.audit, e, `SaveDescriptionHandler[${command.tableKey}:${command.rowId}]`);
375
+ return [];
376
+ }
377
+ }
378
+ };
379
+ var ApplyDynamicProjectionHandler = class {
380
+ constructor(repo, audit, permissionPolicy, dynamic) {
381
+ this.repo = repo;
382
+ this.audit = audit;
383
+ this.permissionPolicy = permissionPolicy;
384
+ this.dynamic = dynamic;
385
+ }
386
+ async execute(command, actor) {
387
+ const { store, tableKey, rowId, columnId } = command;
388
+ const table = await this.repo.getById(store, tableKey);
389
+ try {
390
+ const row = table.getRow(rowId);
391
+ if (!row) {
392
+ throw new DomainError("ROW_NOT_FOUND", `Row ${rowId} not found`, { rowId });
393
+ }
394
+ const cell = row.getCell(columnId);
395
+ if (!cell) {
396
+ throw new DomainError("CELL_NOT_FOUND", `Cell ${columnId} not found`, { columnId });
397
+ }
398
+ const colValue = cell.getValue();
399
+ const previousValue = colValue;
400
+ const newRowId = new RowId(rowId);
401
+ const newColumnId = new ColumnId(columnId);
402
+ if (this.dynamic) {
403
+ await this.applyComputedColumns({
404
+ table,
405
+ rowId: newRowId,
406
+ changedColumnId: newColumnId,
407
+ remoteApi: this.dynamic.remoteApi
408
+ });
409
+ await this.applyRemoteVisibilityRules({
410
+ table,
411
+ rowId: newRowId,
412
+ changedColumnId: newColumnId,
413
+ newValue: colValue,
414
+ clearDependents: false
415
+ });
416
+ this.applyDynamicProjection({
417
+ table,
418
+ rowId: newRowId,
419
+ changedColumnId: newColumnId,
420
+ validatedValue: colValue
421
+ });
422
+ }
423
+ const state = table.getRows().find((r) => r.id.value === newRowId.value)?.getCells().get("RowState")?.getValue();
424
+ if (state === "None" /* Unchanged */) {
425
+ table.changeCell(newRowId, new ColumnId("RowState"), "Update" /* Modified */);
426
+ table.changeDisplay(newRowId, new ColumnId("RowState"), "Update" /* Modified */);
427
+ }
428
+ await this.repo.save(store, table);
429
+ const out = {
430
+ type: "CELL_CHANGED",
431
+ tableId: tableKey,
432
+ rowId: newRowId.value,
433
+ columnId: newColumnId.value,
434
+ newValue: colValue,
435
+ previousValue
436
+ };
437
+ this.audit.log({ type: "CELL_CHANGED", message: out.type, payload: out });
438
+ return [out];
439
+ } catch (e) {
440
+ logError(this.audit, e, `ApplyDynamicProjectionHandler[${tableKey}:${rowId}:${columnId}]`);
441
+ return [];
442
+ }
443
+ }
444
+ /* ── helpers (identical to ChangeCellValueHandler) ───────────────── */
445
+ applyRemoteVisibilityRules(input) {
446
+ return applyRemoteVisibilityRules(this.dynamic, input);
447
+ }
448
+ async applyComputedColumns(input) {
449
+ const { table, rowId, changedColumnId, remoteApi } = input;
450
+ const meta = this.dynamic.columnMeta;
451
+ const computedColumns = Array.from(meta.values()).filter(
452
+ (c) => c.computed != null
453
+ );
454
+ if (computedColumns.length === 0) return;
455
+ const row = table.getRows().find((r) => r.id.value === rowId.value);
456
+ if (!row) return;
457
+ const rowValues = {};
458
+ for (const [colId, cell] of row.getCells().entries()) {
459
+ rowValues[colId] = cell.getValue();
460
+ }
461
+ const dependents = /* @__PURE__ */ new Map();
462
+ for (const col of computedColumns) {
463
+ for (const dep of col.computed.dependsOn ?? []) {
464
+ if (!dependents.has(dep)) dependents.set(dep, []);
465
+ dependents.get(dep).push(col);
466
+ }
467
+ }
468
+ const queue = [changedColumnId.value];
469
+ const visited = /* @__PURE__ */ new Set();
470
+ let safetyCounter = 0;
471
+ const MAX = computedColumns.length + 1;
472
+ while (queue.length > 0) {
473
+ if (safetyCounter++ > MAX) throw new Error("Computed cycle detected");
474
+ const source = queue.shift();
475
+ const targets = dependents.get(source) ?? [];
476
+ for (const colCfg of targets) {
477
+ const targetField = colCfg.fieldName;
478
+ const targetColId = new ColumnId(targetField);
479
+ const schema = table.getColumnSchema(targetColId);
480
+ if (!schema || !colCfg.computed) continue;
481
+ const rawValue = colCfg.computed.compute(rowValues, remoteApi);
482
+ const newValue = rawValue instanceof Promise ? await rawValue : rawValue;
483
+ const validated = this.validateCellValue(schema.fieldType, newValue);
484
+ if (validated.value instanceof Promise) {
485
+ throw new Error(`Computed column "${targetField}" returned a Promise after validation`);
486
+ }
487
+ const prev = rowValues[targetField];
488
+ if (Object.is(prev, validated.value)) continue;
489
+ table.changeCell(rowId, targetColId, validated.value);
490
+ if (schema.displayFormat) {
491
+ const validatedDisplay = this.validateCellValue(
492
+ schema.fieldType,
493
+ schema.displayFormat(newValue)
494
+ );
495
+ table.changeDisplay(rowId, targetColId, validatedDisplay.value);
496
+ } else {
497
+ table.changeDisplay(rowId, targetColId, validated.value);
498
+ }
499
+ rowValues[targetField] = validated.value;
500
+ queue.push(targetField);
501
+ visited.add(targetField);
502
+ }
503
+ }
504
+ }
505
+ validateCellValue(type, value) {
506
+ switch (type) {
507
+ case "text":
508
+ case "textArea":
509
+ case "description":
510
+ case "date":
511
+ return typeof value === "string" ? { ok: true, value } : { ok: false, error: { message: "Expected string", details: { value } }, value };
512
+ case "static":
513
+ return { ok: true, value };
514
+ case "checkbox":
515
+ return typeof value === "boolean" ? { ok: true, value } : { ok: false, error: { message: "Expected boolean", details: { value } }, value };
516
+ case "number":
517
+ case "price":
518
+ case "select":
519
+ case "selectOption": {
520
+ if (value === "" || value === void 0) return { ok: true, value };
521
+ const n = typeof value === "number" ? value : Number(value);
522
+ return Number.isFinite(n) ? { ok: true, value: n } : { ok: false, error: { message: "Expected number", details: { value } }, value };
523
+ }
524
+ default:
525
+ return { ok: false, error: { message: "Unsupported type", details: { type, value } }, value };
526
+ }
527
+ }
528
+ applyDynamicProjection(input) {
529
+ const { table, changedColumnId, validatedValue } = input;
530
+ const activeCollection = table.getActiveCollectionName() ?? "default";
531
+ this.dynamic.columnMeta.forEach((colMeta, key) => {
532
+ if ((colMeta.fieldCollection ?? "default") !== activeCollection) return;
533
+ const col = table.getColumnSchema(new ColumnId(colMeta.fieldName));
534
+ const depends = colMeta.dynamicSource?.dependsOn;
535
+ if (depends?.includes(changedColumnId.value)) {
536
+ const { dynamicSource } = colMeta;
537
+ const { endpoint, dependsOn, ...restDynamic } = dynamicSource ?? {};
538
+ const base = col ?? colMeta;
539
+ table.setColumnSchema(new ColumnId(base.fieldName), {
540
+ ...base,
541
+ dynamicSelectFilterOption: base.dynamicSelectFilterOption ?? (() => true),
542
+ dynamicSource: {
543
+ endpoint: endpoint ?? "",
544
+ ...restDynamic,
545
+ dependOn: {
546
+ fieldName: changedColumnId.value,
547
+ value: validatedValue
548
+ }
549
+ }
550
+ });
551
+ }
552
+ if (colMeta.visibility?.kind === "whenFieldTruthy" && colMeta.visibility.fieldName === changedColumnId.value && col) {
553
+ table.setColumnSchema(new ColumnId(colMeta.fieldName), col);
554
+ }
555
+ });
556
+ }
557
+ };
558
+
559
+ export { ApplyDynamicProjectionHandler, ChangeCellDisplayValueHandler, ChangeCellValueHandler, SaveDescriptionHandler, applyRemoteVisibilityRules, logError };
560
+ //# sourceMappingURL=chunk-RM6ZWNT3.js.map
561
+ //# sourceMappingURL=chunk-RM6ZWNT3.js.map