persian-data-grid 0.5.0 → 0.7.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-E5Q6FYDS.js +125 -0
  4. package/dist/ERPTableGroupRow-E5Q6FYDS.js.map +1 -0
  5. package/dist/ERPTableGroupRow-F2IPDYL5.cjs +131 -0
  6. package/dist/ERPTableGroupRow-F2IPDYL5.cjs.map +1 -0
  7. package/dist/GridPlugin-Bewn0X51.d.ts +57 -0
  8. package/dist/GridPlugin-DewWufGZ.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-CeIfVFck.d.ts +2625 -0
  14. package/dist/GridSession-CmQn2RnL.d.cts +2625 -0
  15. package/dist/GridSyncService-3JQLEY65.cjs +12 -0
  16. package/dist/GridSyncService-3JQLEY65.cjs.map +1 -0
  17. package/dist/GridSyncService-GECXGEKL.js +3 -0
  18. package/dist/GridSyncService-GECXGEKL.js.map +1 -0
  19. package/dist/PdfRenderer-B9FJaCo_.d.cts +22 -0
  20. package/dist/PdfRenderer-bN7ca_Aj.d.ts +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-C71LXBiX.d.ts +678 -0
  28. package/dist/UITableController-CIwnHIw8.d.cts +678 -0
  29. package/dist/VazirmatnPdfRenderer-CpCqA-Wh.d.cts +96 -0
  30. package/dist/VazirmatnPdfRenderer-D46smncn.d.ts +96 -0
  31. package/dist/adapters/arian-erp.cjs +89 -0
  32. package/dist/adapters/arian-erp.cjs.map +1 -0
  33. package/dist/adapters/arian-erp.d.cts +62 -0
  34. package/dist/adapters/arian-erp.d.ts +62 -0
  35. package/dist/adapters/arian-erp.js +79 -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-C2fWYoPy.d.cts +135 -0
  42. package/dist/applyImportedRows-Cqh_N_0k.d.ts +135 -0
  43. package/dist/applyRowVisibilityHandler-Q64ZFC7A.cjs +86 -0
  44. package/dist/applyRowVisibilityHandler-Q64ZFC7A.cjs.map +1 -0
  45. package/dist/applyRowVisibilityHandler-ZLZXQEGY.js +84 -0
  46. package/dist/applyRowVisibilityHandler-ZLZXQEGY.js.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-BYLjmSI6.d.ts +51 -0
  52. package/dist/callbackRemoteApi-Cv26MmSD.d.cts +51 -0
  53. package/dist/cellRenderContext-BaNh4qn_.d.ts +42 -0
  54. package/dist/cellRenderContext-DvngkptV.d.cts +42 -0
  55. package/dist/chunk-27ALJSZP.js +12187 -0
  56. package/dist/chunk-27ALJSZP.js.map +1 -0
  57. package/dist/chunk-3HP3HQCW.cjs +688 -0
  58. package/dist/chunk-3HP3HQCW.cjs.map +1 -0
  59. package/dist/chunk-3Y3KKGEC.js +3 -0
  60. package/dist/chunk-3Y3KKGEC.js.map +1 -0
  61. package/dist/chunk-52LFOPXD.cjs +588 -0
  62. package/dist/chunk-52LFOPXD.cjs.map +1 -0
  63. package/dist/chunk-5ALMNLUR.cjs +1408 -0
  64. package/dist/chunk-5ALMNLUR.cjs.map +1 -0
  65. package/dist/chunk-5HKVMPBD.js +937 -0
  66. package/dist/chunk-5HKVMPBD.js.map +1 -0
  67. package/dist/chunk-72IVAOTK.cjs +38 -0
  68. package/dist/chunk-72IVAOTK.cjs.map +1 -0
  69. package/dist/chunk-77UXAJII.js +112 -0
  70. package/dist/chunk-77UXAJII.js.map +1 -0
  71. package/dist/chunk-7GWV5HGO.js +36 -0
  72. package/dist/chunk-7GWV5HGO.js.map +1 -0
  73. package/dist/chunk-7T6AWRPU.js +581 -0
  74. package/dist/chunk-7T6AWRPU.js.map +1 -0
  75. package/dist/chunk-AU3RDJYQ.js +243 -0
  76. package/dist/chunk-AU3RDJYQ.js.map +1 -0
  77. package/dist/chunk-CILNIWYW.cjs +100 -0
  78. package/dist/chunk-CILNIWYW.cjs.map +1 -0
  79. package/dist/chunk-CMQ4VLCW.cjs +840 -0
  80. package/dist/chunk-CMQ4VLCW.cjs.map +1 -0
  81. package/dist/chunk-DFFP7SJ6.cjs +257 -0
  82. package/dist/chunk-DFFP7SJ6.cjs.map +1 -0
  83. package/dist/chunk-E2J533UH.cjs +53 -0
  84. package/dist/chunk-E2J533UH.cjs.map +1 -0
  85. package/dist/chunk-EBV6HGZB.cjs +33 -0
  86. package/dist/chunk-EBV6HGZB.cjs.map +1 -0
  87. package/dist/chunk-F4PYOYHR.js +112 -0
  88. package/dist/chunk-F4PYOYHR.js.map +1 -0
  89. package/dist/chunk-F6EMC75A.cjs +34 -0
  90. package/dist/chunk-F6EMC75A.cjs.map +1 -0
  91. package/dist/chunk-GKE33FOJ.js +32 -0
  92. package/dist/chunk-GKE33FOJ.js.map +1 -0
  93. package/dist/chunk-GQEDLUMB.js +168 -0
  94. package/dist/chunk-GQEDLUMB.js.map +1 -0
  95. package/dist/chunk-HLOHWFOA.js +645 -0
  96. package/dist/chunk-HLOHWFOA.js.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-KCNTKYUY.js +206 -0
  108. package/dist/chunk-KCNTKYUY.js.map +1 -0
  109. package/dist/chunk-KHMG6EI2.js +13 -0
  110. package/dist/chunk-KHMG6EI2.js.map +1 -0
  111. package/dist/chunk-KMRURD5J.cjs +15 -0
  112. package/dist/chunk-KMRURD5J.cjs.map +1 -0
  113. package/dist/chunk-KRJG3KMP.cjs +174 -0
  114. package/dist/chunk-KRJG3KMP.cjs.map +1 -0
  115. package/dist/chunk-LY27YAXE.cjs +208 -0
  116. package/dist/chunk-LY27YAXE.cjs.map +1 -0
  117. package/dist/chunk-MT3KLB2Q.cjs +944 -0
  118. package/dist/chunk-MT3KLB2Q.cjs.map +1 -0
  119. package/dist/chunk-MUQQKPWR.js +84 -0
  120. package/dist/chunk-MUQQKPWR.js.map +1 -0
  121. package/dist/chunk-N7SJTINL.cjs +4 -0
  122. package/dist/chunk-N7SJTINL.cjs.map +1 -0
  123. package/dist/chunk-NB5GCGHL.js +833 -0
  124. package/dist/chunk-NB5GCGHL.js.map +1 -0
  125. package/dist/chunk-NQUVAJQA.js +298 -0
  126. package/dist/chunk-NQUVAJQA.js.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-Q7TBBUTX.cjs +110 -0
  134. package/dist/chunk-Q7TBBUTX.cjs.map +1 -0
  135. package/dist/chunk-QZN7R2WP.cjs +114 -0
  136. package/dist/chunk-QZN7R2WP.cjs.map +1 -0
  137. package/dist/chunk-RKVSJU46.js +35 -0
  138. package/dist/chunk-RKVSJU46.js.map +1 -0
  139. package/dist/chunk-SVO62ZV2.js +50 -0
  140. package/dist/chunk-SVO62ZV2.js.map +1 -0
  141. package/dist/chunk-SX4VQXAA.cjs +114 -0
  142. package/dist/chunk-SX4VQXAA.cjs.map +1 -0
  143. package/dist/chunk-SZ7BLAY3.js +92 -0
  144. package/dist/chunk-SZ7BLAY3.js.map +1 -0
  145. package/dist/chunk-TN4MG6FY.js +112 -0
  146. package/dist/chunk-TN4MG6FY.js.map +1 -0
  147. package/dist/chunk-UC7PHDM6.cjs +331 -0
  148. package/dist/chunk-UC7PHDM6.cjs.map +1 -0
  149. package/dist/chunk-UXVLYUUW.js +108 -0
  150. package/dist/chunk-UXVLYUUW.js.map +1 -0
  151. package/dist/chunk-VBAZ77Q4.js +932 -0
  152. package/dist/chunk-VBAZ77Q4.js.map +1 -0
  153. package/dist/chunk-VSAFQTW5.cjs +319 -0
  154. package/dist/chunk-VSAFQTW5.cjs.map +1 -0
  155. package/dist/chunk-VYJQ2HTA.cjs +936 -0
  156. package/dist/chunk-VYJQ2HTA.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-WTHTVKVI.cjs +12299 -0
  160. package/dist/chunk-WTHTVKVI.cjs.map +1 -0
  161. package/dist/chunk-WUMOSOEK.cjs +62 -0
  162. package/dist/chunk-WUMOSOEK.cjs.map +1 -0
  163. package/dist/chunk-XLRE2J25.js +140 -0
  164. package/dist/chunk-XLRE2J25.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-BBkud5oE.d.ts +939 -0
  168. package/dist/createEngineGridQuery-D-fgO_jg.d.cts +939 -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 +508 -0
  188. package/dist/headless.d.ts +508 -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 +8060 -11409
  194. package/dist/index.cjs.map +1 -1
  195. package/dist/index.d.cts +457 -2305
  196. package/dist/index.d.ts +457 -2305
  197. package/dist/index.js +7302 -11084
  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 +185 -29
@@ -0,0 +1,581 @@
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, audit) {
27
+ const {
28
+ table,
29
+ rowId,
30
+ changedColumnId,
31
+ newValue,
32
+ clearDependents = true
33
+ } = input;
34
+ const meta = dynamic?.columnMeta;
35
+ if (!meta) return true;
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 true;
40
+ if (resolveOn.fieldName !== changedColumnId.value) return true;
41
+ const row = table.getRows().find((r) => r.id.value === rowId.value);
42
+ if (!row) return true;
43
+ const rowValues = {};
44
+ for (const [colId, cell] of row.getCells().entries()) {
45
+ rowValues[colId] = cell.getValue();
46
+ }
47
+ if (newValue == null || newValue === "") return true;
48
+ const params = typeof resolveOn.buildParams === "function" ? resolveOn.buildParams(rowValues) : { value: newValue };
49
+ let response;
50
+ let failed = false;
51
+ try {
52
+ response = await dynamic.remoteApi.request({
53
+ endpoint: resolveOn.endpoint,
54
+ params,
55
+ method: "POST"
56
+ });
57
+ } catch (error) {
58
+ failed = true;
59
+ if (audit) logError(audit, error, `resolveOn[${resolveOn.endpoint}]`);
60
+ }
61
+ if (!failed) resolveOn.getResponse?.(response, row);
62
+ const flags = failed ? {} : resolveOn.mapFlags?.(response) ?? {};
63
+ const toShow = [];
64
+ const visibilityCondition = {};
65
+ const activeCollection = table.getActiveCollectionName() ?? "default";
66
+ meta.forEach((colCfg) => {
67
+ if ((colCfg.fieldCollection ?? "default") !== activeCollection) return;
68
+ const v = colCfg.visibility;
69
+ if (!failed && v?.kind === "whenRemoteFlag" && v.sourceFieldName === changedColumnId.value) {
70
+ const colId = new ColumnId(colCfg.fieldName);
71
+ const schema = table.getColumnSchema(colId);
72
+ const flagValue = flags[v.flag] ?? false;
73
+ visibilityCondition[colCfg.fieldName] = flagValue;
74
+ if (flagValue && schema) {
75
+ toShow.push({ ...schema, hidden: false });
76
+ }
77
+ }
78
+ const dependency = colCfg.dynamicSource?.dependsOn;
79
+ if (clearDependents && dependency && dependency.includes(changedColumnId.value) && !Object.hasOwn(visibilityCondition, colCfg.fieldName) && colCfg.visibility?.kind !== "whenTableType" && colCfg.visibility?.kind !== "whenCollection") {
80
+ const cell = row.getCell(colCfg.fieldName);
81
+ cell?.changeValue(null);
82
+ cell?.changeDisplay(null);
83
+ }
84
+ });
85
+ if (toShow.length > 0) {
86
+ table.addColumns(toShow);
87
+ }
88
+ if (!failed) row.setVisibilityCondition(visibilityCondition);
89
+ return !failed;
90
+ }
91
+ var ChangeCellValueHandler = class {
92
+ constructor(repo, audit, permissionPolicy, dynamic) {
93
+ this.repo = repo;
94
+ this.audit = audit;
95
+ this.permissionPolicy = permissionPolicy;
96
+ this.dynamic = dynamic;
97
+ }
98
+ async execute(command, actor) {
99
+ const table = await this.repo.getById(command.store, command.tableKey);
100
+ try {
101
+ const rowId = new RowId(command.rowId);
102
+ const columnId = new ColumnId(command.columnId);
103
+ const schema = table.getColumnSchema(columnId);
104
+ if (!schema) {
105
+ throw new DomainError("COLUMN_NOT_FOUND", "Column does not exist", {
106
+ columnId: columnId.value
107
+ });
108
+ }
109
+ if (schema.editable === false) {
110
+ throw new DomainError("NOT_EDITABLE", "Cell is not editable", {
111
+ rowId: rowId.value,
112
+ columnId: columnId.value
113
+ });
114
+ }
115
+ if (!this.permissionPolicy.canChangeCell({
116
+ actor,
117
+ rowId: command.rowId,
118
+ columnId: command.columnId
119
+ })) {
120
+ throw new DomainError(
121
+ "FORBIDDEN",
122
+ "Actor is not allowed to change this cell",
123
+ { actor, rowId: rowId.value, columnId: columnId.value }
124
+ );
125
+ }
126
+ const validated = this.validateCellValue(schema.fieldType, command.newValue);
127
+ const domainEvent = table.changeCell(rowId, columnId, validated.value);
128
+ if (!domainEvent) {
129
+ throw new DomainError(
130
+ "CELL_NOT_FOUND",
131
+ "Cell not found or value not changed",
132
+ { rowId: rowId.value, columnId: columnId.value }
133
+ );
134
+ }
135
+ if (this.dynamic) {
136
+ await this.applyComputedColumns({
137
+ table,
138
+ rowId,
139
+ changedColumnId: columnId,
140
+ remoteApi: this.dynamic.remoteApi
141
+ });
142
+ await this.applyRemoteVisibilityRules({
143
+ table,
144
+ rowId,
145
+ changedColumnId: columnId,
146
+ newValue: command.newValue
147
+ });
148
+ this.applyDynamicProjection({
149
+ table,
150
+ rowId,
151
+ changedColumnId: columnId,
152
+ validatedValue: command.newValue
153
+ });
154
+ }
155
+ const state = table.getRows().find((r) => r.id.value === rowId.value)?.getCells().get("RowState")?.getValue();
156
+ if (state === "None" /* Unchanged */) {
157
+ table.changeCell(rowId, new ColumnId("RowState"), "Update" /* Modified */);
158
+ table.changeDisplay(rowId, new ColumnId("RowState"), "Update" /* Modified */);
159
+ }
160
+ await this.repo.save(command.store, table);
161
+ const out = {
162
+ type: "CELL_CHANGED",
163
+ tableId: command.tableKey,
164
+ rowId: domainEvent.rowId.value,
165
+ columnId: domainEvent.columnId.value,
166
+ newValue: domainEvent.newValue,
167
+ previousValue: domainEvent.previousValue
168
+ };
169
+ this.audit.log({ type: "CELL_CHANGED", message: out.type, payload: out });
170
+ return [out];
171
+ } catch (e) {
172
+ logError(this.audit, e, `ChangeCellValueHandler[${command.tableKey}:${command.rowId}:${command.columnId}]`);
173
+ return [];
174
+ }
175
+ }
176
+ /* ── helpers ─────────────────────────────────────────────────────── */
177
+ applyRemoteVisibilityRules(input) {
178
+ return applyRemoteVisibilityRules(this.dynamic, input, this.audit);
179
+ }
180
+ async applyComputedColumns(input) {
181
+ const { table, rowId, changedColumnId, remoteApi } = input;
182
+ const meta = this.dynamic.columnMeta;
183
+ const computedColumns = Array.from(meta.values()).filter(
184
+ (c) => c.computed != null
185
+ );
186
+ if (computedColumns.length === 0) return;
187
+ const row = table.getRows().find((r) => r.id.value === rowId.value);
188
+ if (!row) return;
189
+ const rowValues = {};
190
+ for (const [colId, cell] of row.getCells().entries()) {
191
+ rowValues[colId] = cell.getValue();
192
+ }
193
+ const dependents = /* @__PURE__ */ new Map();
194
+ for (const col of computedColumns) {
195
+ for (const dep of col.computed.dependsOn ?? []) {
196
+ if (!dependents.has(dep)) dependents.set(dep, []);
197
+ dependents.get(dep).push(col);
198
+ }
199
+ }
200
+ const queue = [changedColumnId.value];
201
+ const visited = /* @__PURE__ */ new Set();
202
+ let safetyCounter = 0;
203
+ const MAX = computedColumns.length + 1;
204
+ while (queue.length > 0) {
205
+ if (safetyCounter++ > MAX) {
206
+ throw new Error("Computed cycle detected");
207
+ }
208
+ const source = queue.shift();
209
+ const targets = dependents.get(source) ?? [];
210
+ for (const colCfg of targets) {
211
+ const targetField = colCfg.fieldName;
212
+ const targetColId = new ColumnId(targetField);
213
+ const schema = table.getColumnSchema(targetColId);
214
+ if (!schema || !colCfg.computed) continue;
215
+ let newValue;
216
+ try {
217
+ const rawValue = colCfg.computed.compute(rowValues, remoteApi);
218
+ newValue = rawValue instanceof Promise ? await rawValue : rawValue;
219
+ } catch (error) {
220
+ logError(this.audit, error, `computed[${targetField}]`);
221
+ continue;
222
+ }
223
+ const validated = this.validateCellValue(schema.fieldType, newValue);
224
+ if (validated.value instanceof Promise) {
225
+ throw new Error(
226
+ `Computed column "${targetField}" returned a Promise after validation`
227
+ );
228
+ }
229
+ const prev = rowValues[targetField];
230
+ if (Object.is(prev, validated.value)) continue;
231
+ table.changeCell(rowId, targetColId, validated.value);
232
+ if (schema.displayFormat) {
233
+ const validatedDisplay = this.validateCellValue(
234
+ schema.fieldType,
235
+ schema.displayFormat(newValue)
236
+ );
237
+ table.changeDisplay(rowId, targetColId, validatedDisplay.value);
238
+ } else {
239
+ table.changeDisplay(rowId, targetColId, validated.value);
240
+ }
241
+ rowValues[targetField] = validated.value;
242
+ queue.push(targetField);
243
+ visited.add(targetField);
244
+ }
245
+ }
246
+ }
247
+ validateCellValue(type, value) {
248
+ switch (type) {
249
+ case "text":
250
+ case "textArea":
251
+ case "description":
252
+ case "date":
253
+ return typeof value === "string" ? { ok: true, value } : { ok: false, error: { message: "Expected string", details: { value } }, value };
254
+ case "static":
255
+ return { ok: true, value };
256
+ case "checkbox":
257
+ return typeof value === "boolean" ? { ok: true, value } : { ok: false, error: { message: "Expected boolean", details: { value } }, value };
258
+ case "number":
259
+ case "price":
260
+ case "select":
261
+ case "selectOption": {
262
+ if (value === "" || value === void 0) {
263
+ return { ok: true, value };
264
+ }
265
+ const n = typeof value === "number" ? value : Number(value);
266
+ return Number.isFinite(n) ? { ok: true, value: n } : { ok: false, error: { message: "Expected number", details: { value } }, value };
267
+ }
268
+ default:
269
+ return { ok: false, error: { message: "Unsupported type", details: { type, value } }, value };
270
+ }
271
+ }
272
+ applyDynamicProjection(input) {
273
+ const { table, changedColumnId, validatedValue } = input;
274
+ const activeCollection = table.getActiveCollectionName() ?? "default";
275
+ this.dynamic.columnMeta.forEach((colMeta, key) => {
276
+ if ((colMeta.fieldCollection ?? "default") !== activeCollection) return;
277
+ const col = table.getColumnSchema(new ColumnId(colMeta.fieldName));
278
+ const depends = colMeta.dynamicSource?.dependsOn;
279
+ if (depends?.includes(changedColumnId.value)) {
280
+ const { dynamicSource } = colMeta;
281
+ const { endpoint, dependsOn, ...restDynamic } = dynamicSource ?? {};
282
+ const base = col ?? colMeta;
283
+ table.setColumnSchema(new ColumnId(base.fieldName), {
284
+ ...base,
285
+ dynamicSelectFilterOption: base.dynamicSelectFilterOption ?? (() => true),
286
+ dynamicSource: {
287
+ endpoint: endpoint ?? "",
288
+ ...restDynamic,
289
+ dependOn: {
290
+ fieldName: changedColumnId.value,
291
+ value: validatedValue
292
+ }
293
+ }
294
+ });
295
+ }
296
+ if (colMeta.visibility?.kind === "whenFieldTruthy" && colMeta.visibility.fieldName === changedColumnId.value && col) {
297
+ table.setColumnSchema(new ColumnId(colMeta.fieldName), col);
298
+ }
299
+ });
300
+ }
301
+ };
302
+ var ChangeCellDisplayValueHandler = class {
303
+ constructor(repo, audit, permissionPolicy) {
304
+ this.repo = repo;
305
+ this.audit = audit;
306
+ this.permissionPolicy = permissionPolicy;
307
+ }
308
+ async execute(command, actor) {
309
+ const table = await this.repo.getById(command.store, command.tableKey);
310
+ try {
311
+ const rowId = new RowId(command.rowId);
312
+ const columnId = new ColumnId(command.columnId);
313
+ const schema = table.getColumnSchema(columnId);
314
+ if (!schema) {
315
+ throw new DomainError("COLUMN_NOT_FOUND", "Column does not exist", {
316
+ columnId: columnId.value
317
+ });
318
+ }
319
+ if (schema.editable === false) {
320
+ throw new DomainError("NOT_EDITABLE", "Cell is not editable", {
321
+ rowId: rowId.value,
322
+ columnId: columnId.value
323
+ });
324
+ }
325
+ if (!this.permissionPolicy.canChangeCell({
326
+ actor,
327
+ rowId: command.rowId,
328
+ columnId: command.columnId
329
+ })) {
330
+ throw new DomainError(
331
+ "FORBIDDEN",
332
+ "Actor is not allowed to change this cell",
333
+ { actor, rowId: rowId.value, columnId: columnId.value }
334
+ );
335
+ }
336
+ const domainEvent = table.changeDisplay(rowId, columnId, command.newValue);
337
+ if (!domainEvent) {
338
+ throw new DomainError(
339
+ "CELL_NOT_FOUND",
340
+ "Cell not found or value not changed",
341
+ { rowId: rowId.value, columnId: columnId.value }
342
+ );
343
+ }
344
+ await this.repo.save(command.store, table);
345
+ const out = {
346
+ type: "CELL_DISPLAY_CHANGED",
347
+ tableId: command.tableKey,
348
+ rowId: domainEvent.rowId.value,
349
+ columnId: domainEvent.columnId.value,
350
+ newValue: domainEvent.newValue
351
+ };
352
+ this.audit.log({ type: "CELL_DISPLAY_CHANGED", message: out.type, payload: out });
353
+ return [out];
354
+ } catch (e) {
355
+ logError(this.audit, e, `ChangeCellDisplayValueHandler[${command.tableKey}:${command.rowId}:${command.columnId}]`);
356
+ return [];
357
+ }
358
+ }
359
+ };
360
+ var SaveDescriptionHandler = class {
361
+ constructor(repo, audit, permissionPolicy) {
362
+ this.repo = repo;
363
+ this.audit = audit;
364
+ this.permissionPolicy = permissionPolicy;
365
+ }
366
+ async execute(command, actor) {
367
+ const table = await this.repo.getById(command.store, command.tableKey);
368
+ try {
369
+ const rowId = new RowId(command.rowId);
370
+ const domainEvent = table.saveDescription(rowId, command.flag);
371
+ if (!domainEvent) {
372
+ throw new DomainError(
373
+ "CELL_NOT_FOUND",
374
+ "Cell not found or value not changed",
375
+ { rowId: rowId.value, flag: command.flag }
376
+ );
377
+ }
378
+ await this.repo.save(command.store, table);
379
+ const out = {
380
+ type: "ROW_DESCRIPTION_SAVED",
381
+ tableId: command.tableKey,
382
+ rowId: domainEvent.rowId.value,
383
+ description: command.flag
384
+ };
385
+ this.audit.log({ type: "INFORMATION", message: out.type, payload: out });
386
+ return [out];
387
+ } catch (e) {
388
+ logError(this.audit, e, `SaveDescriptionHandler[${command.tableKey}:${command.rowId}]`);
389
+ return [];
390
+ }
391
+ }
392
+ };
393
+ var ApplyDynamicProjectionHandler = class {
394
+ constructor(repo, audit, permissionPolicy, dynamic) {
395
+ this.repo = repo;
396
+ this.audit = audit;
397
+ this.permissionPolicy = permissionPolicy;
398
+ this.dynamic = dynamic;
399
+ }
400
+ async execute(command, actor) {
401
+ const { store, tableKey, rowId, columnId } = command;
402
+ const table = await this.repo.getById(store, tableKey);
403
+ try {
404
+ const row = table.getRow(rowId);
405
+ if (!row) {
406
+ throw new DomainError("ROW_NOT_FOUND", `Row ${rowId} not found`, { rowId });
407
+ }
408
+ const cell = row.getCell(columnId);
409
+ if (!cell) {
410
+ throw new DomainError("CELL_NOT_FOUND", `Cell ${columnId} not found`, { columnId });
411
+ }
412
+ const colValue = cell.getValue();
413
+ const previousValue = colValue;
414
+ const newRowId = new RowId(rowId);
415
+ const newColumnId = new ColumnId(columnId);
416
+ if (this.dynamic) {
417
+ await this.applyComputedColumns({
418
+ table,
419
+ rowId: newRowId,
420
+ changedColumnId: newColumnId,
421
+ remoteApi: this.dynamic.remoteApi
422
+ });
423
+ await this.applyRemoteVisibilityRules({
424
+ table,
425
+ rowId: newRowId,
426
+ changedColumnId: newColumnId,
427
+ newValue: colValue,
428
+ clearDependents: false
429
+ });
430
+ this.applyDynamicProjection({
431
+ table,
432
+ rowId: newRowId,
433
+ changedColumnId: newColumnId,
434
+ validatedValue: colValue
435
+ });
436
+ }
437
+ const state = table.getRows().find((r) => r.id.value === newRowId.value)?.getCells().get("RowState")?.getValue();
438
+ if (state === "None" /* Unchanged */) {
439
+ table.changeCell(newRowId, new ColumnId("RowState"), "Update" /* Modified */);
440
+ table.changeDisplay(newRowId, new ColumnId("RowState"), "Update" /* Modified */);
441
+ }
442
+ await this.repo.save(store, table);
443
+ const out = {
444
+ type: "CELL_CHANGED",
445
+ tableId: tableKey,
446
+ rowId: newRowId.value,
447
+ columnId: newColumnId.value,
448
+ newValue: colValue,
449
+ previousValue
450
+ };
451
+ this.audit.log({ type: "CELL_CHANGED", message: out.type, payload: out });
452
+ return [out];
453
+ } catch (e) {
454
+ logError(this.audit, e, `ApplyDynamicProjectionHandler[${tableKey}:${rowId}:${columnId}]`);
455
+ return [];
456
+ }
457
+ }
458
+ /* ── helpers (identical to ChangeCellValueHandler) ───────────────── */
459
+ applyRemoteVisibilityRules(input) {
460
+ return applyRemoteVisibilityRules(this.dynamic, input, this.audit);
461
+ }
462
+ async applyComputedColumns(input) {
463
+ const { table, rowId, changedColumnId, remoteApi } = input;
464
+ const meta = this.dynamic.columnMeta;
465
+ const computedColumns = Array.from(meta.values()).filter(
466
+ (c) => c.computed != null
467
+ );
468
+ if (computedColumns.length === 0) return;
469
+ const row = table.getRows().find((r) => r.id.value === rowId.value);
470
+ if (!row) return;
471
+ const rowValues = {};
472
+ for (const [colId, cell] of row.getCells().entries()) {
473
+ rowValues[colId] = cell.getValue();
474
+ }
475
+ const dependents = /* @__PURE__ */ new Map();
476
+ for (const col of computedColumns) {
477
+ for (const dep of col.computed.dependsOn ?? []) {
478
+ if (!dependents.has(dep)) dependents.set(dep, []);
479
+ dependents.get(dep).push(col);
480
+ }
481
+ }
482
+ const queue = [changedColumnId.value];
483
+ const visited = /* @__PURE__ */ new Set();
484
+ let safetyCounter = 0;
485
+ const MAX = computedColumns.length + 1;
486
+ while (queue.length > 0) {
487
+ if (safetyCounter++ > MAX) throw new Error("Computed cycle detected");
488
+ const source = queue.shift();
489
+ const targets = dependents.get(source) ?? [];
490
+ for (const colCfg of targets) {
491
+ const targetField = colCfg.fieldName;
492
+ const targetColId = new ColumnId(targetField);
493
+ const schema = table.getColumnSchema(targetColId);
494
+ if (!schema || !colCfg.computed) continue;
495
+ let newValue;
496
+ try {
497
+ const rawValue = colCfg.computed.compute(rowValues, remoteApi);
498
+ newValue = rawValue instanceof Promise ? await rawValue : rawValue;
499
+ } catch (error) {
500
+ logError(this.audit, error, `computed[${targetField}]`);
501
+ continue;
502
+ }
503
+ const validated = this.validateCellValue(schema.fieldType, newValue);
504
+ if (validated.value instanceof Promise) {
505
+ throw new Error(`Computed column "${targetField}" returned a Promise after validation`);
506
+ }
507
+ const prev = rowValues[targetField];
508
+ if (Object.is(prev, validated.value)) continue;
509
+ table.changeCell(rowId, targetColId, validated.value);
510
+ if (schema.displayFormat) {
511
+ const validatedDisplay = this.validateCellValue(
512
+ schema.fieldType,
513
+ schema.displayFormat(newValue)
514
+ );
515
+ table.changeDisplay(rowId, targetColId, validatedDisplay.value);
516
+ } else {
517
+ table.changeDisplay(rowId, targetColId, validated.value);
518
+ }
519
+ rowValues[targetField] = validated.value;
520
+ queue.push(targetField);
521
+ visited.add(targetField);
522
+ }
523
+ }
524
+ }
525
+ validateCellValue(type, value) {
526
+ switch (type) {
527
+ case "text":
528
+ case "textArea":
529
+ case "description":
530
+ case "date":
531
+ return typeof value === "string" ? { ok: true, value } : { ok: false, error: { message: "Expected string", details: { value } }, value };
532
+ case "static":
533
+ return { ok: true, value };
534
+ case "checkbox":
535
+ return typeof value === "boolean" ? { ok: true, value } : { ok: false, error: { message: "Expected boolean", details: { value } }, value };
536
+ case "number":
537
+ case "price":
538
+ case "select":
539
+ case "selectOption": {
540
+ if (value === "" || value === void 0) return { ok: true, value };
541
+ const n = typeof value === "number" ? value : Number(value);
542
+ return Number.isFinite(n) ? { ok: true, value: n } : { ok: false, error: { message: "Expected number", details: { value } }, value };
543
+ }
544
+ default:
545
+ return { ok: false, error: { message: "Unsupported type", details: { type, value } }, value };
546
+ }
547
+ }
548
+ applyDynamicProjection(input) {
549
+ const { table, changedColumnId, validatedValue } = input;
550
+ const activeCollection = table.getActiveCollectionName() ?? "default";
551
+ this.dynamic.columnMeta.forEach((colMeta, key) => {
552
+ if ((colMeta.fieldCollection ?? "default") !== activeCollection) return;
553
+ const col = table.getColumnSchema(new ColumnId(colMeta.fieldName));
554
+ const depends = colMeta.dynamicSource?.dependsOn;
555
+ if (depends?.includes(changedColumnId.value)) {
556
+ const { dynamicSource } = colMeta;
557
+ const { endpoint, dependsOn, ...restDynamic } = dynamicSource ?? {};
558
+ const base = col ?? colMeta;
559
+ table.setColumnSchema(new ColumnId(base.fieldName), {
560
+ ...base,
561
+ dynamicSelectFilterOption: base.dynamicSelectFilterOption ?? (() => true),
562
+ dynamicSource: {
563
+ endpoint: endpoint ?? "",
564
+ ...restDynamic,
565
+ dependOn: {
566
+ fieldName: changedColumnId.value,
567
+ value: validatedValue
568
+ }
569
+ }
570
+ });
571
+ }
572
+ if (colMeta.visibility?.kind === "whenFieldTruthy" && colMeta.visibility.fieldName === changedColumnId.value && col) {
573
+ table.setColumnSchema(new ColumnId(colMeta.fieldName), col);
574
+ }
575
+ });
576
+ }
577
+ };
578
+
579
+ export { ApplyDynamicProjectionHandler, ChangeCellDisplayValueHandler, ChangeCellValueHandler, SaveDescriptionHandler, applyRemoteVisibilityRules, logError };
580
+ //# sourceMappingURL=chunk-7T6AWRPU.js.map
581
+ //# sourceMappingURL=chunk-7T6AWRPU.js.map