@poadio/app-vue 0.2.0 → 0.3.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 (334) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/app-vue.css +16 -8
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/items.d.ts +1 -0
  8. package/dist/items.d.ts.map +1 -1
  9. package/dist/items.js +79 -0
  10. package/dist/items.js.map +1 -1
  11. package/dist/messages.d.ts +0 -1
  12. package/dist/messages.d.ts.map +1 -1
  13. package/dist/messages.js +0 -2
  14. package/dist/messages.js.map +1 -1
  15. package/dist/sections/grid.d.ts.map +1 -1
  16. package/dist/sections/grid.js +2 -1
  17. package/dist/sections/grid.js.map +1 -1
  18. package/package.json +11 -2
  19. package/runtime-dist/app.css +16 -8
  20. package/runtime-dist/app.js +2 -2
  21. package/runtime-dist/c-00cvgnxc.js +2 -0
  22. package/runtime-dist/c-09vj399g.js +1 -0
  23. package/runtime-dist/c-0arc0hg5.js +1 -0
  24. package/runtime-dist/{c-1h49vkah.js → c-0x2e39ve.js} +2 -2
  25. package/runtime-dist/{c-fn3059s1.js → c-0x2jfka0.js} +2 -2
  26. package/runtime-dist/c-170fz4v2.js +2 -0
  27. package/runtime-dist/c-1aa5pzps.js +1 -0
  28. package/runtime-dist/c-1h3k0kb8.js +1 -0
  29. package/runtime-dist/c-1j1xssd8.js +2 -0
  30. package/runtime-dist/c-1n6fcyf0.js +1 -0
  31. package/runtime-dist/{c-gs1k0twe.js → c-22qerref.js} +2 -2
  32. package/runtime-dist/c-272dwppe.js +1 -0
  33. package/runtime-dist/c-2z768p0x.js +2 -0
  34. package/runtime-dist/c-38nmw75x.js +1 -0
  35. package/runtime-dist/c-3gqmyt95.js +1 -0
  36. package/runtime-dist/c-3yaegh2k.js +1 -0
  37. package/runtime-dist/{c-xqf3j4w7.js → c-4mqnegk0.js} +1 -1
  38. package/runtime-dist/c-4s1xdsjj.js +2 -0
  39. package/runtime-dist/{c-cvsx6n6e.js → c-4w8c01x6.js} +2 -2
  40. package/runtime-dist/c-5ap867xf.js +39 -0
  41. package/runtime-dist/{c-98tbntdq.js → c-5bxybf9g.js} +2 -2
  42. package/runtime-dist/c-5crndmh8.js +1 -0
  43. package/runtime-dist/c-632d3gvm.js +1 -0
  44. package/runtime-dist/c-6nx9xkc1.js +1 -0
  45. package/runtime-dist/c-6pfxp4ca.js +2 -0
  46. package/runtime-dist/c-76450e09.js +1 -0
  47. package/runtime-dist/c-770ysy0b.js +1 -0
  48. package/runtime-dist/c-7eh8g4bg.js +1 -0
  49. package/runtime-dist/c-81nspfex.js +1 -0
  50. package/runtime-dist/c-8cydj5g6.js +3 -0
  51. package/runtime-dist/c-8g74gqn9.js +2 -0
  52. package/runtime-dist/c-8v7c8j85.js +2 -0
  53. package/runtime-dist/c-8xc3fha3.js +2 -0
  54. package/runtime-dist/c-93kndqea.js +2 -0
  55. package/runtime-dist/c-96a9b7ys.js +1 -0
  56. package/runtime-dist/c-9hk02377.js +2 -0
  57. package/runtime-dist/c-9pzq231t.js +1 -0
  58. package/runtime-dist/c-a3jhm7jm.js +1 -0
  59. package/runtime-dist/c-aebecc6a.js +1 -0
  60. package/runtime-dist/c-aenj05yt.js +2 -0
  61. package/runtime-dist/c-aetcxxs5.js +2 -0
  62. package/runtime-dist/c-afjwwspe.js +1 -0
  63. package/runtime-dist/c-ah4kckw8.js +5 -0
  64. package/runtime-dist/c-an1sk7z5.js +2 -0
  65. package/runtime-dist/{c-qe1kevqk.js → c-b9npcc8v.js} +1 -1
  66. package/runtime-dist/{c-7cjj18ea.js → c-bbgsrr8m.js} +1 -1
  67. package/runtime-dist/{c-gznx0sj4.js → c-bbqq1fmz.js} +2 -2
  68. package/runtime-dist/c-bemne227.js +1 -0
  69. package/runtime-dist/c-bxfxd3hv.js +1 -0
  70. package/runtime-dist/c-bypwvtv5.js +1 -0
  71. package/runtime-dist/c-bz3efpds.js +1 -0
  72. package/runtime-dist/c-ckkpv1ab.js +1 -0
  73. package/runtime-dist/c-cyvq3zhq.js +1 -0
  74. package/runtime-dist/c-d3jg3nhc.js +1 -0
  75. package/runtime-dist/c-d68hg40s.js +1 -0
  76. package/runtime-dist/c-d8ba6h4e.js +1 -0
  77. package/runtime-dist/{c-m49q9r7s.js → c-d9eczdnp.js} +1 -1
  78. package/runtime-dist/c-dzp10g67.js +3 -0
  79. package/runtime-dist/c-e312a464.js +2 -0
  80. package/runtime-dist/c-e5eq2szv.js +2 -0
  81. package/runtime-dist/c-e7rb0mk1.js +1 -0
  82. package/runtime-dist/c-ejgrzqe3.js +1 -0
  83. package/runtime-dist/{c-gesjk5ph.js → c-ezj4yg2q.js} +1 -1
  84. package/runtime-dist/c-f23v2025.js +2 -0
  85. package/runtime-dist/c-f4fpjjsk.js +1 -0
  86. package/runtime-dist/c-fps4599a.js +1 -0
  87. package/runtime-dist/c-fq9wga43.js +1 -0
  88. package/runtime-dist/c-g06g8vzv.js +1 -0
  89. package/runtime-dist/c-g0ncg08s.js +7 -0
  90. package/runtime-dist/{c-ahcj5yr5.js → c-g0s6z8fh.js} +1 -1
  91. package/runtime-dist/c-gqaaq5xd.js +2 -0
  92. package/runtime-dist/c-gty08djr.js +2 -0
  93. package/runtime-dist/{c-wjadf68q.js → c-hcd75fdn.js} +1 -1
  94. package/runtime-dist/c-hddfmemr.js +2 -0
  95. package/runtime-dist/c-hqtxax0h.js +1 -0
  96. package/runtime-dist/{c-cc3m3rs1.js → c-hwgt6amh.js} +2 -2
  97. package/runtime-dist/c-jhscxp68.js +1 -0
  98. package/runtime-dist/c-jpgfd99h.js +1 -0
  99. package/runtime-dist/c-kt8hnx3r.js +1 -0
  100. package/runtime-dist/{c-sdf15np5.js → c-m4wr50z4.js} +1 -1
  101. package/runtime-dist/{c-rktc0ksd.js → c-mb798tvv.js} +2 -2
  102. package/runtime-dist/c-mpvzhygt.js +1 -0
  103. package/runtime-dist/c-mqwew5y8.js +1 -0
  104. package/runtime-dist/{c-sd570jk7.js → c-n5896ck3.js} +2 -2
  105. package/runtime-dist/{c-pbn2syef.js → c-nacvp4ca.js} +1 -1
  106. package/runtime-dist/c-ncw09fhf.js +1 -0
  107. package/runtime-dist/c-nm6tjep8.js +1 -0
  108. package/runtime-dist/c-p1cbp7e1.js +1 -0
  109. package/runtime-dist/c-pager3te.js +1 -0
  110. package/runtime-dist/c-pca88tas.js +1 -0
  111. package/runtime-dist/c-pp0qxmbz.js +2 -0
  112. package/runtime-dist/{c-mdj990nz.js → c-ppc1a1as.js} +2 -2
  113. package/runtime-dist/c-pttdwpdd.js +1 -0
  114. package/runtime-dist/c-q9h7pf4v.js +2 -0
  115. package/runtime-dist/c-qcz7q5fj.js +2 -0
  116. package/runtime-dist/c-qhv2qby2.js +2 -0
  117. package/runtime-dist/c-r539tr5f.js +1 -0
  118. package/runtime-dist/c-r7qgrz3b.js +2 -0
  119. package/runtime-dist/c-ra7b526a.js +1 -0
  120. package/runtime-dist/c-rm3pkjj7.js +1 -0
  121. package/runtime-dist/c-sgr6dj0y.js +3 -0
  122. package/runtime-dist/c-spzfyqjp.js +2 -0
  123. package/runtime-dist/c-srccgg45.js +2 -0
  124. package/runtime-dist/c-stez1fhk.js +2 -0
  125. package/runtime-dist/{c-fnzeden9.js → c-t31wwv0j.js} +1 -1
  126. package/runtime-dist/{c-p8wyhrwm.js → c-t8hew4h2.js} +2 -2
  127. package/runtime-dist/c-tc2bxsyc.js +1 -0
  128. package/runtime-dist/c-tjk566f2.js +2 -0
  129. package/runtime-dist/c-tjqjxwfa.js +1 -0
  130. package/runtime-dist/c-tpa4vh9k.js +1 -0
  131. package/runtime-dist/c-v43kzdgm.js +350 -0
  132. package/runtime-dist/c-v73qt5av.js +800 -0
  133. package/runtime-dist/c-w1cb3r8h.js +1 -0
  134. package/runtime-dist/c-wcha6k7x.js +1 -0
  135. package/runtime-dist/c-wrja8cc7.js +2 -0
  136. package/runtime-dist/c-x0evjwqg.js +2 -0
  137. package/runtime-dist/c-x2jj49ts.js +1 -0
  138. package/runtime-dist/c-x4aywmb9.js +2 -0
  139. package/runtime-dist/c-xhyafw4q.js +1 -0
  140. package/runtime-dist/c-xyqqhx8j.js +14 -0
  141. package/runtime-dist/c-y7f2tjg6.js +7 -0
  142. package/runtime-dist/c-yf86vgtz.js +2 -0
  143. package/runtime-dist/c-yhzkcpdp.js +1 -0
  144. package/runtime-dist/{c-m6yf7zaj.js → c-ytpw5gj2.js} +1 -1
  145. package/runtime-dist/c-z00nq4vy.js +2 -0
  146. package/runtime-dist/c-z6dbvc3p.js +2 -0
  147. package/runtime-dist/c-zbts8rvw.js +2 -0
  148. package/runtime-dist/{c-xeqwqt9z.js → c-zhvsa0wq.js} +2 -2
  149. package/runtime-dist/c-zhwr1x02.js +1 -0
  150. package/runtime-dist/c-znyeph7c.js +1 -0
  151. package/runtime-dist/maplibre-gl-csp-worker.js +6 -0
  152. package/runtime-dist/monaco/vs/base/browser/ui/codicons/codicon/codicon.ttf +0 -0
  153. package/runtime-dist/monaco/vs/base/worker/workerMain.js +31 -0
  154. package/runtime-dist/monaco/vs/basic-languages/abap/abap.js +10 -0
  155. package/runtime-dist/monaco/vs/basic-languages/apex/apex.js +10 -0
  156. package/runtime-dist/monaco/vs/basic-languages/azcli/azcli.js +10 -0
  157. package/runtime-dist/monaco/vs/basic-languages/bat/bat.js +10 -0
  158. package/runtime-dist/monaco/vs/basic-languages/bicep/bicep.js +11 -0
  159. package/runtime-dist/monaco/vs/basic-languages/cameligo/cameligo.js +10 -0
  160. package/runtime-dist/monaco/vs/basic-languages/clojure/clojure.js +10 -0
  161. package/runtime-dist/monaco/vs/basic-languages/coffee/coffee.js +10 -0
  162. package/runtime-dist/monaco/vs/basic-languages/cpp/cpp.js +10 -0
  163. package/runtime-dist/monaco/vs/basic-languages/csharp/csharp.js +10 -0
  164. package/runtime-dist/monaco/vs/basic-languages/csp/csp.js +10 -0
  165. package/runtime-dist/monaco/vs/basic-languages/css/css.js +12 -0
  166. package/runtime-dist/monaco/vs/basic-languages/cypher/cypher.js +10 -0
  167. package/runtime-dist/monaco/vs/basic-languages/dart/dart.js +10 -0
  168. package/runtime-dist/monaco/vs/basic-languages/dockerfile/dockerfile.js +10 -0
  169. package/runtime-dist/monaco/vs/basic-languages/ecl/ecl.js +10 -0
  170. package/runtime-dist/monaco/vs/basic-languages/elixir/elixir.js +10 -0
  171. package/runtime-dist/monaco/vs/basic-languages/flow9/flow9.js +10 -0
  172. package/runtime-dist/monaco/vs/basic-languages/freemarker2/freemarker2.js +12 -0
  173. package/runtime-dist/monaco/vs/basic-languages/fsharp/fsharp.js +10 -0
  174. package/runtime-dist/monaco/vs/basic-languages/go/go.js +10 -0
  175. package/runtime-dist/monaco/vs/basic-languages/graphql/graphql.js +10 -0
  176. package/runtime-dist/monaco/vs/basic-languages/handlebars/handlebars.js +10 -0
  177. package/runtime-dist/monaco/vs/basic-languages/hcl/hcl.js +10 -0
  178. package/runtime-dist/monaco/vs/basic-languages/html/html.js +10 -0
  179. package/runtime-dist/monaco/vs/basic-languages/ini/ini.js +10 -0
  180. package/runtime-dist/monaco/vs/basic-languages/java/java.js +10 -0
  181. package/runtime-dist/monaco/vs/basic-languages/javascript/javascript.js +10 -0
  182. package/runtime-dist/monaco/vs/basic-languages/julia/julia.js +10 -0
  183. package/runtime-dist/monaco/vs/basic-languages/kotlin/kotlin.js +10 -0
  184. package/runtime-dist/monaco/vs/basic-languages/less/less.js +11 -0
  185. package/runtime-dist/monaco/vs/basic-languages/lexon/lexon.js +10 -0
  186. package/runtime-dist/monaco/vs/basic-languages/liquid/liquid.js +10 -0
  187. package/runtime-dist/monaco/vs/basic-languages/lua/lua.js +10 -0
  188. package/runtime-dist/monaco/vs/basic-languages/m3/m3.js +10 -0
  189. package/runtime-dist/monaco/vs/basic-languages/markdown/markdown.js +10 -0
  190. package/runtime-dist/monaco/vs/basic-languages/mdx/mdx.js +10 -0
  191. package/runtime-dist/monaco/vs/basic-languages/mips/mips.js +10 -0
  192. package/runtime-dist/monaco/vs/basic-languages/msdax/msdax.js +10 -0
  193. package/runtime-dist/monaco/vs/basic-languages/mysql/mysql.js +10 -0
  194. package/runtime-dist/monaco/vs/basic-languages/objective-c/objective-c.js +10 -0
  195. package/runtime-dist/monaco/vs/basic-languages/pascal/pascal.js +10 -0
  196. package/runtime-dist/monaco/vs/basic-languages/pascaligo/pascaligo.js +10 -0
  197. package/runtime-dist/monaco/vs/basic-languages/perl/perl.js +10 -0
  198. package/runtime-dist/monaco/vs/basic-languages/pgsql/pgsql.js +10 -0
  199. package/runtime-dist/monaco/vs/basic-languages/php/php.js +10 -0
  200. package/runtime-dist/monaco/vs/basic-languages/pla/pla.js +10 -0
  201. package/runtime-dist/monaco/vs/basic-languages/postiats/postiats.js +10 -0
  202. package/runtime-dist/monaco/vs/basic-languages/powerquery/powerquery.js +10 -0
  203. package/runtime-dist/monaco/vs/basic-languages/powershell/powershell.js +10 -0
  204. package/runtime-dist/monaco/vs/basic-languages/protobuf/protobuf.js +11 -0
  205. package/runtime-dist/monaco/vs/basic-languages/pug/pug.js +10 -0
  206. package/runtime-dist/monaco/vs/basic-languages/python/python.js +10 -0
  207. package/runtime-dist/monaco/vs/basic-languages/qsharp/qsharp.js +10 -0
  208. package/runtime-dist/monaco/vs/basic-languages/r/r.js +10 -0
  209. package/runtime-dist/monaco/vs/basic-languages/razor/razor.js +10 -0
  210. package/runtime-dist/monaco/vs/basic-languages/redis/redis.js +10 -0
  211. package/runtime-dist/monaco/vs/basic-languages/redshift/redshift.js +10 -0
  212. package/runtime-dist/monaco/vs/basic-languages/restructuredtext/restructuredtext.js +10 -0
  213. package/runtime-dist/monaco/vs/basic-languages/ruby/ruby.js +10 -0
  214. package/runtime-dist/monaco/vs/basic-languages/rust/rust.js +10 -0
  215. package/runtime-dist/monaco/vs/basic-languages/sb/sb.js +10 -0
  216. package/runtime-dist/monaco/vs/basic-languages/scala/scala.js +10 -0
  217. package/runtime-dist/monaco/vs/basic-languages/scheme/scheme.js +10 -0
  218. package/runtime-dist/monaco/vs/basic-languages/scss/scss.js +12 -0
  219. package/runtime-dist/monaco/vs/basic-languages/shell/shell.js +10 -0
  220. package/runtime-dist/monaco/vs/basic-languages/solidity/solidity.js +10 -0
  221. package/runtime-dist/monaco/vs/basic-languages/sophia/sophia.js +10 -0
  222. package/runtime-dist/monaco/vs/basic-languages/sparql/sparql.js +10 -0
  223. package/runtime-dist/monaco/vs/basic-languages/sql/sql.js +10 -0
  224. package/runtime-dist/monaco/vs/basic-languages/st/st.js +10 -0
  225. package/runtime-dist/monaco/vs/basic-languages/swift/swift.js +13 -0
  226. package/runtime-dist/monaco/vs/basic-languages/systemverilog/systemverilog.js +10 -0
  227. package/runtime-dist/monaco/vs/basic-languages/tcl/tcl.js +10 -0
  228. package/runtime-dist/monaco/vs/basic-languages/twig/twig.js +10 -0
  229. package/runtime-dist/monaco/vs/basic-languages/typescript/typescript.js +10 -0
  230. package/runtime-dist/monaco/vs/basic-languages/typespec/typespec.js +10 -0
  231. package/runtime-dist/monaco/vs/basic-languages/vb/vb.js +10 -0
  232. package/runtime-dist/monaco/vs/basic-languages/wgsl/wgsl.js +307 -0
  233. package/runtime-dist/monaco/vs/basic-languages/xml/xml.js +10 -0
  234. package/runtime-dist/monaco/vs/basic-languages/yaml/yaml.js +10 -0
  235. package/runtime-dist/monaco/vs/editor/editor.main.css +8 -0
  236. package/runtime-dist/monaco/vs/editor/editor.main.js +798 -0
  237. package/runtime-dist/monaco/vs/language/css/cssMode.js +13 -0
  238. package/runtime-dist/monaco/vs/language/css/cssWorker.js +77 -0
  239. package/runtime-dist/monaco/vs/language/html/htmlMode.js +13 -0
  240. package/runtime-dist/monaco/vs/language/html/htmlWorker.js +454 -0
  241. package/runtime-dist/monaco/vs/language/json/jsonMode.js +19 -0
  242. package/runtime-dist/monaco/vs/language/json/jsonWorker.js +42 -0
  243. package/runtime-dist/monaco/vs/language/typescript/tsMode.js +20 -0
  244. package/runtime-dist/monaco/vs/language/typescript/tsWorker.js +51328 -0
  245. package/runtime-dist/monaco/vs/loader.js +11 -0
  246. package/runtime-dist/monaco/vs/nls.messages.de.js +21 -0
  247. package/runtime-dist/monaco/vs/nls.messages.es.js +21 -0
  248. package/runtime-dist/monaco/vs/nls.messages.fr.js +19 -0
  249. package/runtime-dist/monaco/vs/nls.messages.it.js +19 -0
  250. package/runtime-dist/monaco/vs/nls.messages.ja.js +21 -0
  251. package/runtime-dist/monaco/vs/nls.messages.ko.js +19 -0
  252. package/runtime-dist/monaco/vs/nls.messages.ru.js +21 -0
  253. package/runtime-dist/monaco/vs/nls.messages.zh-cn.js +21 -0
  254. package/runtime-dist/monaco/vs/nls.messages.zh-tw.js +19 -0
  255. package/runtime-dist/monaco-worker.js +4 -0
  256. package/runtime-dist/ui-maplibre-gl.css +1 -0
  257. package/runtime-dist/version.json +1 -1
  258. package/src/index.ts +1 -1
  259. package/src/items.ts +96 -0
  260. package/src/messages.ts +0 -2
  261. package/src/sections/grid.ts +2 -1
  262. package/runtime-dist/c-0rxdxcn3.js +0 -2
  263. package/runtime-dist/c-0zqjsnm5.js +0 -2
  264. package/runtime-dist/c-13nx24wa.js +0 -1
  265. package/runtime-dist/c-16cdkp27.js +0 -1
  266. package/runtime-dist/c-16cm3n82.js +0 -1
  267. package/runtime-dist/c-1xpa1fqz.js +0 -1
  268. package/runtime-dist/c-29v2e09p.js +0 -1
  269. package/runtime-dist/c-2ag31260.js +0 -2
  270. package/runtime-dist/c-2s6r37jb.js +0 -1
  271. package/runtime-dist/c-2v244yc0.js +0 -1
  272. package/runtime-dist/c-3be398px.js +0 -1
  273. package/runtime-dist/c-3jm96b1p.js +0 -2
  274. package/runtime-dist/c-3pe5hprv.js +0 -2
  275. package/runtime-dist/c-3zbf5g3p.js +0 -1
  276. package/runtime-dist/c-4h51m4qq.js +0 -1
  277. package/runtime-dist/c-523qwqen.js +0 -2
  278. package/runtime-dist/c-572jz6y4.js +0 -1
  279. package/runtime-dist/c-64j9mv7a.js +0 -1
  280. package/runtime-dist/c-6f446pxt.js +0 -1
  281. package/runtime-dist/c-6pd33f4a.js +0 -1
  282. package/runtime-dist/c-6qa26wds.js +0 -1
  283. package/runtime-dist/c-6w0f1kqm.js +0 -1
  284. package/runtime-dist/c-72hj12cs.js +0 -2
  285. package/runtime-dist/c-823yyjat.js +0 -1
  286. package/runtime-dist/c-8gpbevx2.js +0 -1
  287. package/runtime-dist/c-9sm6aybf.js +0 -2
  288. package/runtime-dist/c-a63rkaa9.js +0 -1
  289. package/runtime-dist/c-azvw5879.js +0 -2
  290. package/runtime-dist/c-b6g9ey7e.js +0 -2
  291. package/runtime-dist/c-bssc8kwn.js +0 -1
  292. package/runtime-dist/c-bvp9zbmr.js +0 -1
  293. package/runtime-dist/c-cp1ehb23.js +0 -1
  294. package/runtime-dist/c-d5y90g8f.js +0 -1
  295. package/runtime-dist/c-d8hfdner.js +0 -2
  296. package/runtime-dist/c-dqtdk937.js +0 -1
  297. package/runtime-dist/c-eczfywaq.js +0 -1
  298. package/runtime-dist/c-epemgj1a.js +0 -2
  299. package/runtime-dist/c-et83hbhc.js +0 -1
  300. package/runtime-dist/c-ffkh15py.js +0 -1
  301. package/runtime-dist/c-gen0a4bn.js +0 -1
  302. package/runtime-dist/c-gkyekesy.js +0 -15
  303. package/runtime-dist/c-h5m94fwp.js +0 -1
  304. package/runtime-dist/c-hdstjg33.js +0 -2
  305. package/runtime-dist/c-hsy77frc.js +0 -3
  306. package/runtime-dist/c-j02ymtyd.js +0 -2
  307. package/runtime-dist/c-j63hz554.js +0 -2
  308. package/runtime-dist/c-jvrr9zb8.js +0 -1
  309. package/runtime-dist/c-jymrpj5m.js +0 -1
  310. package/runtime-dist/c-k624qrhh.js +0 -2
  311. package/runtime-dist/c-kbg0cafy.js +0 -2
  312. package/runtime-dist/c-kmx0mv0c.js +0 -2
  313. package/runtime-dist/c-krt6rpg1.js +0 -1
  314. package/runtime-dist/c-kyajr8zz.js +0 -2
  315. package/runtime-dist/c-m30q0jrb.js +0 -1
  316. package/runtime-dist/c-m70tbfc5.js +0 -2
  317. package/runtime-dist/c-mvdn43tv.js +0 -2
  318. package/runtime-dist/c-mw3zx9yk.js +0 -1
  319. package/runtime-dist/c-n8mqnvjg.js +0 -1
  320. package/runtime-dist/c-nkrm4n9a.js +0 -1
  321. package/runtime-dist/c-nn49946s.js +0 -1
  322. package/runtime-dist/c-ny0mdx7k.js +0 -2
  323. package/runtime-dist/c-prt5qv2x.js +0 -1
  324. package/runtime-dist/c-rasvf2z2.js +0 -2
  325. package/runtime-dist/c-sjajadt4.js +0 -2
  326. package/runtime-dist/c-sv15z0aa.js +0 -1
  327. package/runtime-dist/c-tv3ksk7j.js +0 -2
  328. package/runtime-dist/c-vrmw0gka.js +0 -1
  329. package/runtime-dist/c-wnynh7zm.js +0 -1
  330. package/runtime-dist/c-xk9fqzsc.js +0 -1
  331. package/runtime-dist/c-xx4986kx.js +0 -1
  332. package/runtime-dist/c-y9120d6h.js +0 -1
  333. package/runtime-dist/c-ywzh0r63.js +0 -1
  334. package/runtime-dist/c-zyfkspym.js +0 -2
@@ -0,0 +1,2 @@
1
+ class a extends Error{code;messageKey;status;sourceCode;path;params;field;rule;cause;constructor(e,t,r={}){super(t);if(this.name="DataStoreError",this.code=e,this.messageKey=r.messageKey??(e==="validation"&&r.rule?`data.${r.rule}`:`data.${e}`),r.status!==void 0)this.status=r.status;if(r.sourceCode!==void 0)this.sourceCode=r.sourceCode;if(r.path!==void 0)this.path=r.path;if(r.params!==void 0)this.params=r.params;if(r.field!==void 0)this.field=r.field;if(r.rule!==void 0)this.rule=r.rule;if(r.cause!==void 0)this.cause=r.cause}}function E(e){if(e instanceof a)return e;let t=typeof e==="object"&&e!==null?e:{},r=typeof t.status==="number"?t.status:void 0,s=typeof t.code==="string"?t.code:void 0,n=typeof t.message==="string"&&t.message?t.message:String(e),i=s==="55000"||s==="0A000"?"read_only":Dr(t.kind)??Nr(r,s),o=typeof t.column==="string"?t.column:i==="constraint"?Lr(n):void 0;return new a(i,n,{...r!==void 0?{status:r}:{},...s!==void 0?{sourceCode:s}:{},...o?{field:o}:{},cause:e})}function Dr(e){switch(e){case"network":case"aborted":return"network";case"unauthorized":case"forbidden":case"not_found":case"conflict":case"constraint":case"server":return e;case"invalid":return"invalid_query";case"timeout":return"server";default:return}}function Nr(e,t){if(t==="network_error"||t==="aborted"||e===0)return"network";if(t==="42501"||t==="forbidden"||e===403)return"forbidden";if(t==="unauthorized"||t==="PGRST301"||e===401)return"unauthorized";if(t==="not_found"||e===404)return"not_found";if(t&&/^23/.test(t))return"constraint";if(t==="40001"||e===409||e===412)return"conflict";if(t&&/^(22|42)/.test(t))return"invalid_query";if(t==="invalid_request"||e===400)return"invalid_query";if(e!==void 0&&e>=500)return"server";if(zr(t))return"network";return"unknown"}var zr=(e)=>e==="ECONNREFUSED"||e==="ECONNRESET"||e==="ETIMEDOUT";function Lr(e){return(/column "([A-Za-z_][A-Za-z0-9_]*)"/.exec(e)??/Key \(([A-Za-z_][A-Za-z0-9_]*)\)=/.exec(e))?.[1]}var Ot=/^[A-Za-z_][A-Za-z0-9_]{0,62}$/,Ir=/^(0|[1-9][0-9]{0,8})$/,xt=16,Ue=new Set(["__proto__","prototype","constructor"]);function A(e,t="field"){if(e===void 0||e==="")return[];if(Array.isArray(e)){if(e.length>xt)throw re(t,"path too deep");return e.map((s,n)=>{if(typeof s==="number"?Number.isInteger(s)&&s>=0:typeof s==="string"&&Ot.test(s)&&!Ue.has(s))return s;throw re(`${t}[${n}]`,"expected a field name or an array index")})}if(typeof e!=="string")throw re(t,'expected a path such as "adresse.ville" or "lignes.0.qte"');let r=e.split(".");if(r.length>xt)throw re(t,"path too deep");return r.map((s)=>{if(Ir.test(s))return Number(s);if(Ot.test(s)&&!Ue.has(s))return s;throw re(t,`invalid segment "${s}" (expected a field name or an array index)`)})}var J=(e)=>e.join(".");function j(e,t){let r=e;for(let s of t){if(r===null||typeof r!=="object")return;if(typeof s==="number"){if(!Array.isArray(r))return;r=r[s]}else{if(Array.isArray(r)||!Object.prototype.hasOwnProperty.call(r,s))return;r=r[s]}}return r}function Z(e,t,r){if(t.length===0)return r;let[s,...n]=t;if(typeof s==="number"){let o=Array.isArray(e)?[...e]:[];return o[s]=Z(o[s],n,r),o}if(Ue.has(s))throw re("field",`invalid segment "${s}"`);let i=e!==null&&typeof e==="object"&&!Array.isArray(e)?{...e}:{};return i[s]=Z(Object.prototype.hasOwnProperty.call(i,s)?i[s]:void 0,n,r),i}function R(e,t,r=0){if(Object.is(e,t))return!0;if(r>64||typeof e!=="object"||typeof t!=="object"||e===null||t===null)return!1;if(Array.isArray(e)!==Array.isArray(t))return!1;if(Array.isArray(e)){let i=t;return e.length===i.length&&e.every((o,l)=>R(o,i[l],r+1))}let s=Object.keys(e),n=Object.keys(t);if(s.length!==n.length)return!1;return s.every((i)=>Object.prototype.hasOwnProperty.call(t,i)&&R(e[i],t[i],r+1))}var re=(e,t)=>new a("invalid_binding",`invalid field path at ${e}: ${t}`,{path:e});class V{hooks;value;listeners=new Set;constructor(e,t={}){this.hooks=t,this.value=e}get(){return this.value}get observed(){return this.listeners.size>0}set(e){if(Object.is(e,this.value))return;this.value=e;for(let t of[...this.listeners])if(this.listeners.has(t))t(e)}replace(e){this.value=e}subscribe(e){let t=(s)=>e(s);if(this.listeners.add(t),this.listeners.size===1)this.hooks.start?.();let r=!0;return()=>{if(!r)return;if(r=!1,this.listeners.delete(t),this.listeners.size===0)this.hooks.stop?.()}}}var At=["add","sub","mul","div","round","min","max","concat","coalesce","if","eq","ne","gt","gte","lt","lte","and","or","not"],Mr=new Set(At),Fr={sub:[2,2],div:[2,2],round:[1,2],if:[3,3],eq:[2,2],ne:[2,2],gt:[2,2],gte:[2,2],lt:[2,2],lte:[2,2],not:[1,1]},Y=(e,t)=>{throw new a("invalid_description",`invalid compute at ${e}: ${t}`,{path:e})};function He(e,t="compute",r=0){if(r>16)Y(t,"expression nested too deeply");if(e===null||typeof e==="boolean")return e;if(typeof e==="number")return Number.isFinite(e)?e:Y(t,"expected a finite number");if(typeof e==="string")return A(e),e;if(typeof e!=="object"||Array.isArray(e))return Y(t,'expected a field name, a number, { "text": … } or { "<op>": [ … ] }');let s=Object.keys(e);if(s.length!==1)return Y(t,"expected exactly one operator");let n=s[0],i=e[n];if(n==="text")return typeof i==="string"?e:Y(`${t}.text`,"expected a string");if(!Mr.has(n))throw new a("unknown_operator",`unknown compute operator "${n}" at ${t}: expected one of ${At.join(", ")}`,{path:t,params:{operator:n}});if(!Array.isArray(i)||i.length===0)return Y(`${t}.${n}`,"expected a non-empty array of operands");let[o,l]=Fr[n]??[1,64];if(i.length<o||i.length>l)Y(`${t}.${n}`,o===l?`expected ${o} operands`:`expected ${o} to ${l} operands`);return i.forEach((u,c)=>He(u,`${t}.${n}[${c}]`,r+1)),e}var Ge=(e)=>{if(typeof e==="number"&&Number.isFinite(e))return e;if(typeof e==="string"&&e.trim()!==""&&Number.isFinite(Number(e)))return Number(e);return null};function Xe(e,t){if(e===null||typeof e==="boolean"||typeof e==="number")return e;if(typeof e==="string")return j(t,A(e));let r=Object.keys(e)[0];if(r==="text")return e.text;let s=e[r],n=(u)=>Xe(s[u],t),i=()=>s.map((u)=>Xe(u,t)),o=()=>{let u=[];for(let c of i()){let f=Ge(c);if(f===null)return null;u.push(f)}return u},l=(u)=>{let c=n(0),f=n(1);if(c===null||c===void 0||f===null||f===void 0)return null;let d=Ge(c),h=Ge(f);return d!==null&&h!==null?u(d,h):u(String(c),String(f))};switch(r){case"add":{let u=o();return u&&u.reduce((c,f)=>c+f,0)}case"mul":{let u=o();return u&&u.reduce((c,f)=>c*f,1)}case"sub":{let u=o();return u&&u[0]-u[1]}case"div":{let u=o();return u&&u[1]!==0?u[0]/u[1]:null}case"round":{let u=o();if(!u)return null;let c=10**Math.max(0,Math.min(10,Math.trunc(u[1]??0)));return Math.round(u[0]*c)/c}case"min":{let u=o();return u&&Math.min(...u)}case"max":{let u=o();return u&&Math.max(...u)}case"concat":return i().map((u)=>u===null||u===void 0?"":String(u)).join("");case"coalesce":return i().find((u)=>u!==null&&u!==void 0)??null;case"if":return n(0)?n(1):n(2);case"eq":return JSON.stringify(n(0)??null)===JSON.stringify(n(1)??null);case"ne":return JSON.stringify(n(0)??null)!==JSON.stringify(n(1)??null);case"gt":return l((u,c)=>u>c);case"gte":return l((u,c)=>u>=c);case"lt":return l((u,c)=>u<c);case"lte":return l((u,c)=>u<=c);case"and":return i().every(Boolean);case"or":return i().some(Boolean);case"not":return!n(0);default:return null}}function _t(e,t){if(typeof e==="function")try{let r=e(t);return typeof r==="number"&&!Number.isFinite(r)?null:r}catch{return null}return Xe(e,t)}var jt=["key","label","description","search","start","end","duration","resource","geometry","latitude","longitude","parent","order","group","status","progress","color","image","value","version"],Et=new Set(jt),Kr=["required","min","max","minLength","maxLength","pattern"],Br=new Set(["field","key","header","type","roles","width","minWidth","align","sortable","filterable","editable","hidden","format","options","compute",...Kr]),Wr=/^\d{4}-\d{2}-\d{2}([T ][0-9:.]+(Z|[+-]\d{2}:?\d{2})?)?$/,Zr=new Set(["decimals","currency","percent","date"]),Qe=new Set(["text","number","date","datetime","boolean","enum","json","geometry"]),Jr=new Set(["left","right","center"]),Vr=/^[A-Za-z_][A-Za-z0-9_.-]{0,127}$/,Yr=/^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/,Ur=/^(\d+(\.\d+)?)(px|rem|em|ch|%|vw)$/,Gr=/^[A-Z]{3}$/,$t=200,Te=200,w=(e,t)=>{throw new a("invalid_binding",`invalid field at ${e}: ${t}`,{path:e})},de=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e)&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null);function Ct(e,t){if(typeof e==="string"){if(e.length===0||e.length>Te)w(t,`expected 1 to ${Te} characters`);return e}if(!de(e)||Object.keys(e).length===0)return w(t,'expected a text or an object of texts by language ({ "fr": "…", "en": "…" })');for(let[r,s]of Object.entries(e)){if(!Yr.test(r))w(`${t}.${r}`,"expected a language tag (fr, en, fr-CA)");if(typeof s!=="string"||s.length===0||s.length>Te)w(`${t}.${r}`,`expected 1 to ${Te} characters`)}return e}function Rt(e,t){if(typeof e==="number"){if(!Number.isInteger(e)||e<1||e>4000)w(t,"expected a width in px between 1 and 4000");return`${e}px`}if(typeof e!=="string"||!Ur.test(e))return w(t,"expected a number (px) or a CSS length (12rem, 20%)");return e}function se(e,t){if(typeof e!=="boolean")w(t,"expected true or false");return e}function Xr(e,t){if(!de(e))return w(t,"expected an object");for(let[r,s]of Object.entries(e)){let n=`${t}.${r}`;if(!Zr.has(r))w(n,"unknown key");if(r==="decimals"&&(typeof s!=="number"||!Number.isInteger(s)||s<0||s>20))w(n,"expected an integer between 0 and 20");if(r==="currency"&&(typeof s!=="string"||!Gr.test(s)))w(n,"expected an ISO 4217 code (EUR)");if(r==="percent")se(s,n);if(r==="date"&&s!=="short"&&s!=="medium"&&s!=="long")w(n,'expected "short", "medium" or "long"')}return e}var Hr=/^[A-Za-z_][A-Za-z0-9_-]{0,63}$/;function Qr(e,t,r){for(let s of Object.keys(e))if(s!=="store"&&s!=="fields")w(`${t}.${s}`,'unknown key (a reference has "store" and "fields")');if(typeof e.store!=="string"||!Hr.test(e.store))w(`${t}.store`,"expected a store name");if(r>0&&e.fields!==void 0)w(`${t}.fields`,"a reference inside a reference cannot declare fields");return{store:e.store,...e.fields!==void 0?{fields:he(e.fields,{at:`${t}.fields`,depth:r+1})}:{}}}function qr(e,t){if(!Array.isArray(e)||e.length===0||e.length>1000)return w(t,"expected a non-empty array of { value, label }");return e.map((r,s)=>{let n=`${t}[${s}]`;if(!de(r))return w(n,"expected { value, label }");for(let o of Object.keys(r))if(o!=="value"&&o!=="label")w(`${n}.${o}`,"unknown key");let i=r.value;if(!(i===null||typeof i==="string"||typeof i==="boolean"||typeof i==="number"&&Number.isFinite(i)))w(`${n}.value`,"expected a scalar");return{value:i,label:Ct(r.label,`${n}.label`)}})}function es(e,t,r){let s={};if(e.required!==void 0)s.required=se(e.required,`${t}.required`);for(let n of["min","max"]){let i=e[n];if(i===void 0)continue;if(r==="date"||r==="datetime"){if(typeof i!=="string"||!Wr.test(i))w(`${t}.${n}`,"expected an ISO date (2026-01-01)")}else if(typeof i!=="number"||!Number.isFinite(i))w(`${t}.${n}`,"expected a number");s[n]=i}for(let n of["minLength","maxLength"]){let i=e[n];if(i===void 0)continue;if(typeof i!=="number"||!Number.isInteger(i)||i<0||i>1e6)w(`${t}.${n}`,"expected a non-negative integer");s[n]=i}if(e.pattern!==void 0){let n=e.pattern;if(typeof n!=="string"||n.length===0||n.length>500)w(`${t}.pattern`,"expected a regular expression (1 to 500 characters)");try{new RegExp(n,"u")}catch{w(`${t}.pattern`,"not a valid regular expression")}s.pattern=n}if(s.min!==void 0&&s.max!==void 0&&ts(s.min,s.max)>0)w(`${t}.min`,"min is greater than max");if(s.minLength!==void 0&&s.maxLength!==void 0&&s.minLength>s.maxLength)w(`${t}.minLength`,"minLength is greater than maxLength");return Object.keys(s).length?s:void 0}var ts=(e,t)=>typeof e==="number"&&typeof t==="number"?e-t:Date.parse(String(e))-Date.parse(String(t));function qe(e){let t=e.toLowerCase().replace(/^pg_catalog\./,"");if(Qe.has(t))return t;if(/^(int[248]?|smallint|integer|bigint|numeric|decimal|real|float[48]?|double precision|money|serial|bigserial)(\(.*\))?$/.test(t))return"number";if(t==="date")return"date";if(/^timestamp/.test(t))return"datetime";if(t==="bool"||t==="boolean")return"boolean";if(/^(geometry|geography)(\(.*\))?$/.test(t))return"geometry";if(t==="json"||t==="jsonb"||t.endsWith("[]"))return"json";if(/^(text|varchar|character varying|char|character|bpchar|uuid|citext|name|time|timetz|interval|inet)/.test(t))return"text";return}function rs(e,t){if(!Array.isArray(e))return w(t,"expected an array of roles");let r=new Set;return e.map((s,n)=>{if(typeof s!=="string"||!Et.has(s))w(`${t}[${n}]`,`unknown role (known: ${jt.join(", ")})`);if(r.has(s))w(`${t}[${n}]`,"duplicate role");return r.add(s),s})}function he(e,t={}){let r=t.at??"fields";if(!Array.isArray(e)||e.length===0||e.length>$t)return w(r,`expected 1 to ${$t} fields`);let s=new Set;return e.map((n,i)=>{let o=`${r}[${i}]`,l=typeof n==="string"?{field:n}:de(n)?n:w(o,"expected a field path or a field object");for(let m of Object.keys(l))if(!Br.has(m))w(`${o}.${m}`,"unknown key");if(typeof l.field!=="string"||l.field==="")w(`${o}.field`,"expected a field path");let u=J(A(l.field,`${o}.field`)),c=l.key===void 0?u:typeof l.key==="string"&&Vr.test(l.key)?l.key:w(`${o}.key`,"expected an identifier");if(s.has(c))w(`${o}.key`,`duplicate field "${c}" (give a distinct "key")`);s.add(c);let f=de(l.options)?Qr(l.options,`${o}.options`,t.depth??0):void 0,d,h;if(f&&l.type===void 0)d="enum",h="declared";else if(l.type!==void 0){if(!Qe.has(l.type))w(`${o}.type`,`expected one of ${[...Qe].join(", ")}`);d=l.type,h="declared"}else{let m=!u.includes(".")?t.meta?.columns[u]:void 0,k=m?qe(m):void 0;d=k??"text",h=k?"meta":"default"}let g=l.options!==void 0&&!f?qr(l.options,`${o}.options`):void 0;if(d==="enum"&&!g&&!f)w(`${o}.options`,'an enum field needs its options (a list, or a reference store { "store": "…" })');if((g||f)&&d!=="enum")w(`${o}.options`,"options are only for an enum field");if(l.align!==void 0&&!Jr.has(l.align))w(`${o}.align`,'expected "left", "right" or "center"');let y=es(l,o,d),b;if(l.compute!==void 0){if(typeof l.compute==="function")b=l.compute;else try{b=He(l.compute,`${o}.compute`)}catch(m){if(m.code==="unknown_operator")throw m;w(m.path??`${o}.compute`,m.message.replace(/^invalid compute at [^:]+: /,""))}if(l.editable===!0)w(`${o}.editable`,"a computed field cannot be edited")}return{key:c,field:u,header:l.header!==void 0?Ct(l.header,`${o}.header`):u,type:d,typeSource:h,roles:l.roles!==void 0?rs(l.roles,`${o}.roles`):[],...l.width!==void 0?{width:Rt(l.width,`${o}.width`)}:{},...l.minWidth!==void 0?{minWidth:Rt(l.minWidth,`${o}.minWidth`)}:{},align:l.align??(d==="number"?"right":d==="boolean"?"center":"left"),sortable:l.sortable!==void 0?se(l.sortable,`${o}.sortable`):d!=="json"&&d!=="geometry"&&!u.includes("."),filterable:l.filterable!==void 0?se(l.filterable,`${o}.filterable`):!1,editable:l.editable!==void 0?se(l.editable,`${o}.editable`):!1,hidden:l.hidden!==void 0?se(l.hidden,`${o}.hidden`):!1,...l.format!==void 0?{format:Xr(l.format,`${o}.format`)}:{},...g?{options:g}:{},...f?{reference:f}:{},...y?{rules:y}:{},...b!==void 0?{compute:b}:{}}})}function ce(e,t){if(typeof e==="string")return e;let r=t.split("-")[0]??t;return e[t]??e[r]??e.en??Object.values(e)[0]??""}var ss={text:"text",number:"number",date:"date",datetime:void 0,boolean:"boolean",enum:"text",json:"text",geometry:"text"},ns={text:"text",number:"number",date:"date",datetime:"date",boolean:"boolean",enum:"select",json:"text",geometry:"text"},is={text:"text",number:"number",date:"date",datetime:"text",boolean:"checkbox",enum:"select",json:"textarea",geometry:"textarea"};function sa(e,t){return e.map((r)=>{let s=r.options?.map((i)=>({label:ce(i.label,t.locale),value:i.value})),n=ss[r.type];return{key:r.key,field:r.field,header:ce(r.header,t.locale),sortable:r.sortable,...n?{dataType:n}:{},align:r.align,filterable:r.filterable,filterType:ns[r.type],...s?{filterOptions:s,editorOptions:s}:{},...r.width?{width:r.width}:{},...r.minWidth?{minWidth:r.minWidth}:{},hidden:r.hidden,editable:r.editable,editor:is[r.type],...r.format?{format:r.format}:{},fieldType:r.type,roles:r.roles}})}function Pe(e,t){let r=(i,o)=>new a("validation",`invalid value for "${e.field}": ${i}`,{rule:i,field:e.field,...o?{params:o}:{}}),s=e.rules??{};if(t===null||t===void 0||t===""||Array.isArray(t)&&t.length===0)return s.required?r("required"):null;switch(e.type){case"number":if(typeof t!=="number"||!Number.isFinite(t))return r("type");if(s.min!==void 0&&typeof s.min==="number"&&t<s.min)return r("min",{min:s.min});if(s.max!==void 0&&typeof s.max==="number"&&t>s.max)return r("max",{max:s.max});break;case"date":case"datetime":{let i=t instanceof Date?t.getTime():typeof t==="string"?Date.parse(t):NaN;if(Number.isNaN(i))return r("type");if(s.min!==void 0&&i<Date.parse(String(s.min)))return r("min",{min:String(s.min)});if(s.max!==void 0&&i>Date.parse(String(s.max)))return r("max",{max:String(s.max)});break}case"boolean":if(typeof t!=="boolean")return r("type");break;case"enum":if(e.options&&!(Array.isArray(t)?t:[t]).every((i)=>e.options.some((o)=>o.value===i)))return r("enum");break;default:break}if(typeof t==="string"){if(s.minLength!==void 0&&t.length<s.minLength)return r("minLength",{min:s.minLength});if(s.maxLength!==void 0&&t.length>s.maxLength)return r("maxLength",{max:s.maxLength});if(s.pattern!==void 0&&!new RegExp(`^(?:${s.pattern})$`,"u").test(t))return r("pattern")}return null}function N(e,t){if(!Et.has(t))w("role",`unknown role "${String(t)}"`);return(Array.isArray(e)?e:e.fields??[]).filter((s)=>s.roles.includes(t))}var X=globalThis;var De="*",te=Object.freeze({kind:"update",dirty:!1,saving:!1,changes:{},errors:{},conflicts:{},error:null});function ge(e,t,r){if(!t)return!0;if(r){let s=Number(e[r]),n=Number(t[r]);if(Number.isFinite(s)&&Number.isFinite(n))return s>n}return!R(e,t)}var me=(e)=>JSON.stringify(e??null),os=3,ze=()=>({signal:new X.AbortController().signal});class ye{host;entries=new Map;seq=0;constructor(e){this.host=e}state(e){return this.entries.get(e)?.view??te}allView=Object.freeze({});all(){return this.allView}inserted(){return[...this.entries.entries()].filter(([,e])=>e.kind==="insert"&&e.keyValue===null).map(([e,t])=>({id:e,row:{...t.changes}}))}get dirty(){for(let e of this.entries.values())if(e.view.dirty)return!0;return!1}get saving(){for(let e of this.entries.values())if(e.saving)return!0;return!1}merge(e,t){let r=this.entries.get(e);if(!r||Object.keys(r.changes).length===0)return t;return{...t,...r.changes}}isDeleted(e){return this.entries.get(e)?.kind==="delete"}get versionColumn(){return this.host.version}base(e){return this.entries.get(e)?.base??null}incoming(e,t){let r=this.entries.get(e);if(!r||r.kind==="insert"&&r.keyValue===null)return"none";if(r.saving)return this.held.set(e,t),"deferred";if(t===null){if(r.kind==="delete")return this.entries.delete(e),this.publishAll(),"none";return r.conflicts={},r.error=new a("not_found","the row was deleted meanwhile",{messageKey:"data.save_not_found"}),this.publish(e,r),"handled"}if(!ge(t,r.base,this.host.version))return"stale";if(r.kind==="delete")return r.conflicts={[De]:{mine:null,theirs:t,base:r.base}},r.base={...t},r.error=new a("conflict","the row was changed before its deletion",{messageKey:"data.conflict"}),this.publish(e,r),"handled";if(this.compare(r,t),Object.keys(r.conflicts).length>0)r.error=Tt(r);return this.publish(e,r),"handled"}held=new Map;compare(e,t){let r=e.base??{};for(let s of Object.keys(e.changes)){let n=t[s],i=r[s],o=e.changes[s];if(R(n,i))continue;if(R(n,o)){delete e.changes[s],delete e.conflicts[s];continue}e.conflicts[s]={mine:o,theirs:n,base:e.conflicts[s]?.base??i}}e.base={...t}}set(e,t,r,s){let n=this.entry(e,t);if(n.kind==="delete")throw new a("read_only","this row is being deleted",{field:r});let i=n.base?n.base[r]:void 0;if(n.kind==="update"&&R(s,i))delete n.changes[r];else n.changes[r]=s;delete n.conflicts[r];let o=this.host.rule(r),l=o?Pe(o,s):null;if(l)n.errors[r]=l;else delete n.errors[r];if(Object.keys(n.conflicts).length===0)n.error=null;if(this.publish(e,n),this.host.mode()==="immediate")this.schedule(e)}insert(e){return this.insertAs(`new:${++this.seq}`,e)}insertAs(e,t){let r=this.fresh(null,null);r.kind="insert",r.changes={...t};for(let[s,n]of Object.entries(t)){let i=this.host.rule(s),o=i?Pe(i,n):null;if(o)r.errors[s]=o}if(this.entries.set(e,r),this.publish(e,r),this.host.mode()==="immediate")this.schedule(e);return e}remove(e,t){let r=this.entries.get(e);if(r?.kind==="insert"&&r.keyValue===null){this.entries.delete(e),this.publishAll();return}let s=this.entry(e,t);if(s.kind="delete",s.changes={},s.errors={},s.conflicts={},s.error=null,this.publish(e,s),this.host.mode()==="immediate")this.schedule(e)}revert(e,t){let r=e===void 0?[...this.entries.keys()]:[e];for(let s of r){let n=this.entries.get(s);if(!n)continue;if(t!==void 0){if(delete n.changes[t],delete n.errors[t],delete n.conflicts[t],Object.keys(n.conflicts).length===0)n.error=null;this.publish(s,n);continue}if(n.saving){n.again=!1;continue}if(n.kind==="insert"&&n.keyValue===null)this.entries.delete(s);else this.entries.delete(s)}this.publishAll()}dismiss(e){let t=this.entries.get(e);if(!t||t.saving)return;t.error=null,this.publish(e,t)}resolve(e,t,r){let s=this.entries.get(e);if(!s)return;let n=t===null?Object.keys(s.conflicts):[t];for(let i of n){if(!(i in s.conflicts))continue;if(i===De){if(r==="theirs"){this.entries.delete(e),this.publishAll();return}}else if(r==="theirs")delete s.changes[i],delete s.errors[i];delete s.conflicts[i]}if(Object.keys(s.conflicts).length===0)s.error=null;if(s.kind==="update"&&Object.keys(s.changes).length===0&&!s.error&&Object.keys(s.errors).length===0){this.entries.delete(e),this.publishAll();return}if(this.publish(e,s),this.host.mode()==="immediate"&&Object.keys(s.conflicts).length===0)this.schedule(e)}validate(e,t,r){let s=this.entries.get(e);if(!s||s.kind==="delete")return!0;let n={...t??s.base??{},...s.changes},i=r||s.kind==="insert"?new Set([...this.host.ruled(),...Object.keys(s.changes)]):new Set(Object.keys(s.changes));for(let o of i){let l=this.host.rule(o),u=l?Pe(l,n[o]):null;if(u)s.errors[o]=u;else delete s.errors[o]}return this.publish(e,s),Object.keys(s.errors).length===0}validateAll(e){let t=!0;for(let r of[...this.entries.keys()])if(!this.validate(r,e?.(r)??null,!1))t=!1;return t}async save(e,t,r=!1){let s=e===void 0?[...this.entries.keys()]:[e];return(await Promise.all(s.map((i)=>this.saveOne(i,t?.(i)??null,r,0)))).every(Boolean)}fresh(e,t){return{keyValue:e,base:t,kind:"update",changes:{},errors:{},conflicts:{},error:null,saving:!1,again:!1,view:te}}entry(e,t){let r=this.entries.get(e);if(!r)r=this.fresh(t?t[this.host.keyColumn]:null,t?{...t}:null),this.entries.set(e,r);return r}publish(e,t){let r=t.kind!=="update"||Object.keys(t.changes).length>0;if(t.kind==="update"&&!r&&!t.saving&&!t.error&&Object.keys(t.errors).length===0&&Object.keys(t.conflicts).length===0&&this.entries.get(e)===t)this.entries.delete(e);else t.view=Object.freeze({kind:t.kind,dirty:r,saving:t.saving,changes:Object.freeze({...t.changes}),errors:Object.freeze({...t.errors}),conflicts:Object.freeze({...t.conflicts}),error:t.error});this.publishAll()}publishAll(){let e={};for(let[t,r]of this.entries)e[t]=r.view;this.allView=Object.freeze(e),this.host.changed()}scheduled=new Set;schedule(e){if(this.scheduled.has(e))return;this.scheduled.add(e),Promise.resolve().then(()=>{this.scheduled.delete(e);let t=this.entries.get(e);if(!t)return;if(t.saving){t.again=!0;return}this.saveOne(e,null,!1,0)})}where(e){let{keyColumn:t,version:r}=this.host,s={[t]:e.keyValue};if(r&&e.base&&e.base[r]!==void 0&&e.base[r]!==null)s[r]=e.base[r];return s}async saveOne(e,t,r,s){let n=this.entries.get(e);if(!n)return!0;if(n.saving)return n.again=!0,!1;let i=this.host.mode()==="immediate";if(Object.keys(n.conflicts).length>0)return!1;if(!this.validate(e,t,r)){if(i&&n.kind==="update")this.rollback(e,n,n.errors[Object.keys(n.errors)[0]]??null);return!1}if(n.kind==="update"&&Object.keys(n.changes).length===0)return this.publish(e,n),!0;let{transport:o,table:l}=this.host;if(!o||!l){if(n.kind==="update"){let c={...n.base??{},...n.changes};this.entries.delete(e),this.host.commitLocal?.(e,c),this.publishAll()}return!0}let u={...n.changes};n.saving=!0,n.error=null,n.again=!1,this.publish(e,n);try{if(n.kind==="insert")return await this.sendInsert(e,n,u,o,l);if(n.kind==="delete")return await this.sendDelete(e,n,o,l,s);return await this.sendUpdate(e,n,u,o,l,s)}finally{let c=this.entries.get(e);if(c&&c.saving)c.saving=!1,this.publish(e,c);if(c&&c.again&&!c.saving&&this.entries.get(e)===c){if(c.again=!1,Object.keys(c.conflicts).length===0)this.saveOne(e,null,!1,0)}if(this.held.has(e)&&!this.entries.get(e)?.saving){let f=this.held.get(e)??null;this.held.delete(e),this.host.incoming?.(e,f)}}}fail(e,t,r,s){let n=E(r);if(t.saving=!1,n.code==="constraint"&&!n.field&&this.host.table){let i=as(n.message,this.host.table,Object.keys(s));if(i)n=new a("constraint",n.message,{...st(n),field:i})}if(n.field&&n.field in s)t.errors[n.field]=n;else t.error=n.code==="forbidden"?new a("forbidden",n.message,{...st(n),messageKey:"data.save_forbidden"}):n;if(this.host.mode()==="immediate"&&t.kind==="update")this.rollback(e,t,t.error??n);else this.publish(e,t);return!1}rollback(e,t,r){t.changes={},t.errors={},t.error=r,t.again=!1,this.publish(e,t)}async sendInsert(e,t,r,s,n){if(typeof s.insert!=="function")return this.fail(e,t,et(s,"insert"),r);let i;try{i=await s.insert({table:n,values:r},ze())}catch(o){return this.fail(e,t,o,r)}return this.inserted_(e,t,r,i)}inserted_(e,t,r,s){t.saving=!1;let n=s?.[this.host.keyColumn],i=this.host.insertedId?.(e)??me(n);this.entries.delete(e);let o={};for(let[l,u]of Object.entries(t.changes))if(!R(u,r[l]))o[l]=u;if(Object.keys(o).length){let l=this.fresh(n,s);l.changes=o,this.entries.set(i,l)}return this.host.stored(i,s,e),this.publishAll(),!0}async sendDelete(e,t,r,s,n){if(typeof r.remove!=="function")return this.fail(e,t,et(r,"remove"),{});let i;try{i=await r.remove({table:s,where:this.where(t)},ze())}catch(u){return this.fail(e,t,u,{})}if(i.length>0)return this.entries.delete(e),this.host.removed(e),this.publishAll(),!0;let o=await this.readBack(t);if(o===void 0)return this.fail(e,t,new a("unknown","cannot read the row back"),{});if(o===null)return this.entries.delete(e),this.host.removed(e),this.publishAll(),!0;let l=this.host.version;if(l&&!R(o[l],t.base?.[l]))return t.conflicts={[De]:{mine:null,theirs:o,base:t.base}},t.base=o,t.saving=!1,t.error=new a("conflict","the row was changed before its deletion",{messageKey:"data.conflict"}),this.host.stored(e,o,e),this.publish(e,t),!1;return this.fail(e,t,new a("forbidden","nothing deleted: refused by the row security",{messageKey:"data.save_forbidden"}),{})}async sendUpdate(e,t,r,s,n,i){if(typeof s.update!=="function")return this.fail(e,t,et(s,"update"),r);let o;try{o=await s.update({table:n,where:this.where(t),set:r},ze())}catch(l){return this.fail(e,t,l,r)}if(o.length>0)return this.updated_(e,t,r,o[0]);if(!await this.explainUnmatched(e,t,r))return!1;if(Object.keys(t.changes).length===0)return!0;if(i+1>=os)return this.fail(e,t,new a("conflict","the row keeps changing"),r);return this.saveOne(e,null,!1,i+1)}updated_(e,t,r,s){for(let[n,i]of Object.entries(r))if(R(t.changes[n],i))delete t.changes[n];return t.base={...s},t.saving=!1,t.error=null,this.host.stored(e,s,e),this.publish(e,t),!0}async explainUnmatched(e,t,r){let s=await this.readBack(t);if(s===void 0)return this.fail(e,t,new a("unknown","nothing written and the row cannot be read back"),r);if(s===null)return this.fail(e,t,new a("not_found","nothing written: the row no longer exists or is not visible",{messageKey:"data.save_not_found"}),{});let n=this.host.version;if(!n||R(s[n],t.base?.[n]))return this.fail(e,t,new a("forbidden","nothing written: refused by the row security",{messageKey:"data.save_forbidden"}),{});if(this.compare(t,s),t.saving=!1,this.host.stored(e,s,e),Object.keys(t.conflicts).length>0)return t.error=Tt(t),this.publish(e,t),!1;return this.publish(e,t),!0}batchSent=new Map;batchPrepare(e){let t=this.host.table,r=[],s=[],n=!0;for(let[i,o]of[...this.entries]){if(!o.view.dirty||o.saving)continue;if(Object.keys(o.conflicts).length>0||!this.validate(i,e(i),!1)){n=!1;continue}if(!t)continue;if(o.kind==="insert")r.push({op:"create",table:t,values:{...o.changes}});else if(o.kind==="delete")r.push({op:"destroy",table:t,where:this.where(o),expect:"one"});else if(Object.keys(o.changes).length>0)r.push({op:"update",table:t,where:this.where(o),set:{...o.changes},expect:"one"});else continue;s.push(i)}return n?{operations:r,ids:s}:null}batchStart(e){for(let t of e){let r=this.entries.get(t);if(!r)continue;this.batchSent.set(t,{...r.changes}),r.saving=!0,r.error=null,r.again=!1,this.publish(t,r)}}batchDone(e,t){let r=this.entries.get(e),s=this.batchSent.get(e)??{};if(this.batchSent.delete(e),!r)return;if(r.kind==="insert"){if(t[0])this.inserted_(e,r,s,t[0]);return}if(r.kind==="delete"){r.saving=!1,this.entries.delete(e),this.host.removed(e),this.publishAll();return}if(t[0])this.updated_(e,r,s,t[0])}async batchFailed(e,t,r){let s=this.entries.get(e),n=this.batchSent.get(e)??{};if(this.batchSent.delete(e),!s)return;if(s.saving=!1,!r){this.publish(e,s);return}if(t.code==="conflict"&&s.kind!=="insert")if(s.kind==="delete"){let i=await this.readBack(s);if(i&&this.host.version&&!R(i[this.host.version],s.base?.[this.host.version])){s.conflicts={[De]:{mine:null,theirs:i,base:s.base}},s.base=i,s.error=new a("conflict","the row was changed before its deletion",{messageKey:"data.conflict"}),this.host.stored(e,i,e),this.publish(e,s);return}}else if(await this.explainUnmatched(e,s,n)){s.error=new a("conflict","the row was changed meanwhile: send again",{messageKey:"data.conflict"}),this.publish(e,s);return}else return;if(s.error=t.code==="forbidden"?new a("forbidden",t.message,{...st(t),messageKey:"data.save_forbidden"}):t,t.field&&t.field in n)s.errors[t.field]=t,s.error=null;this.publish(e,s)}async readBack(e){let{transport:t,table:r,keyColumn:s}=this.host;if(!t?.findOne||!r)return;try{return await t.findOne({table:r,where:{[s]:e.keyValue}},ze())??null}catch{return}}}var Tt=(e)=>new a("conflict","the row was changed meanwhile",{params:{count:Object.keys(e.conflicts).length}});function as(e,t,r){let s=/constraint "([^"]+)"/.exec(e)?.[1];if(!s)return;let n=t.split(".").pop();return r.find((i)=>s===`${n}_${i}_check`||s===`${n}_${i}_key`||s===`${n}_${i}_fkey`)}var et=(e,t)=>new a("read_only",`transport "${e.name}" cannot ${t}`),st=(e)=>({...e.status!==void 0?{status:e.status}:{},...e.sourceCode!==void 0?{sourceCode:e.sourceCode}:{},cause:e.cause??e});var ls=(e)=>e.type==="list"?e.get().rows:e.get().value,be=(e,t)=>e.type==="list"&&t.length>0&&typeof t[0]==="string",cs=Object.freeze({writable:!1,dirty:!1,saving:!1,error:null,conflict:null});class Pt{store;path;cell;statusCell;stopStore=null;stopStatus=null;status;constructor(e,t){this.store=e,this.path=t,this.cell=new V(this.compute(),{start:()=>{if(be(e,t)&&e.type==="list")e.useCursor();this.sync(),this.stopStore=e.subscribe(()=>this.sync())},stop:()=>{this.stopStore?.(),this.stopStore=null}}),this.statusCell=new V(this.computeStatus(),{start:()=>{this.syncStatus(),this.stopStatus=e.subscribe(()=>this.syncStatus())},stop:()=>{this.stopStatus?.(),this.stopStatus=null}});let r=this.statusCell;this.status={get:()=>{if(!r.observed)this.syncStatus();return r.get()},subscribe:(s)=>r.subscribe(s)}}get writable(){let e=this.path;if(this.store.type==="record")return e.length>=1;if(be(this.store,e))return!0;return e.length>=2&&typeof e[0]==="number"&&typeof e[1]==="string"}compute(){if(be(this.store,this.path)&&this.store.type==="list"){let e=this.store.get().current.row;return e===null?void 0:j(e,this.path)}return j(ls(this.store),this.path)}sync(){let e=this.compute();if(!R(e,this.cell.get()))this.cell.set(e)}target(){let e=this.path;if(this.store.type==="record"){if(e.length===0)return null;let n=this.store.get();return{edit:n.edit,column:String(e[0]),id:null,original:j(n.original,e)}}if(be(this.store,e)){let n=this.store.get(),i=n.current.row;if(i===null)return null;let o=this.store.keyOf(i);return{edit:n.edits[o]??te,column:String(e[0]),id:o,original:void 0}}if(e.length<2||typeof e[0]!=="number")return null;let t=this.store.get(),r=t.rows[e[0]];if(r===void 0)return null;let s=this.store.keyOf(r);return{edit:t.edits[s]??te,column:String(e[1]),id:s,original:void 0}}computeStatus(){let e=this.target();if(!e)return cs;let{edit:t,column:r}=e,s=r in t.changes||t.kind==="insert";if(s&&this.store.type==="record"&&this.path.length>1)s=!R(this.compute(),e.original);return{writable:this.writable,dirty:s,saving:t.saving,error:t.errors[r]??(s?t.error:null),conflict:t.conflicts[r]??null}}syncStatus(){let e=this.computeStatus(),t=this.statusCell.get();if(t.writable===e.writable&&t.dirty===e.dirty&&t.saving===e.saving&&t.error===e.error&&t.conflict===e.conflict)return;this.statusCell.set(e)}get(){if(!this.cell.observed)this.sync();return this.cell.get()}subscribe(e){return this.cell.subscribe(e)}set(e){if(!this.writable)throw new a("read_only",`field "${J(this.path)||"*"}" cannot be changed (give a field of a record, or "rows.<index>.<column>")`,{path:"field"});if(this.store.type==="record"){this.store.set(this.path,e);return}let t=this.target();if(be(this.store,this.path)){if(!t?.id)throw new a("read_only","no current record: move the cursor first (first(), next()…)",{path:"field"});this.store.set(t.id,this.path,e);return}if(!t?.id)throw new a("read_only",`no row at index ${String(this.path[0])}`,{path:"field"});this.store.set(t.id,this.path.slice(1),e)}resolve(e){let t=this.target();if(!t)return;if(this.store.type==="record")this.store.resolve([this.path[0]],e);else if(t.id)this.store.resolve(t.id,t.column,e)}revert(){let e=this.target();if(!e)return;if(this.store.type==="record")this.store.revert([this.path[0]]);else if(e.id)this.store.revert(e.id,e.column)}toString(){return`field(${J(this.path)||"*"})`}}function kt(e,t){return new Pt(e,A(t))}var Dt=["eq","ne","gt","gte","lt","lte","in","notIn","like","ilike","notLike","notIlike","is","not","between","notBetween","contains","containedBy","overlap","match"],us=new Set(Dt),fs=/^:([A-Za-z_][A-Za-z0-9_]{0,62})$/,ds=/^[A-Za-z_][A-Za-z0-9_]{0,62}$/,it=(e)=>typeof e==="string"?fs.exec(e)?.[1]??null:null;function hs(e,t){if(typeof e!=="string"||!us.has(e))throw new a("unknown_operator",`unknown operator "${String(e)}" at ${t}: expected one of ${Dt.join(", ")}`,{path:t,params:{operator:String(e)}});return e}function at(e,t,r){let s=hs(t,e),n={[e]:{[s]:r}};return I(n,"where"),n}function Nt(e,t){if(!e)return e;let r=(s)=>{if(Array.isArray(s))return s.map(r);if(s&&typeof s==="object")return Object.fromEntries(Object.entries(s).map(([n,i])=>[n,r(i)]));if(typeof s==="string"){let n=it(s);if(n){if(!(n in t)||t[n]===void 0)throw new a("missing_param",`the parameter ":${n}" has no value: load({ ${n}: … })`,{path:n,params:{name:n}});return t[n]}if(s.startsWith("::"))return s.slice(1)}return s};return r(e)}function ne(e,t){if(!e||Object.keys(e).length===0)return t;let r=(l,u)=>JSON.stringify(l)===JSON.stringify(u),s=(l)=>("and"in l)||("or"in l)||("not"in l),n=t,i=e.and&&Object.keys(e).length===1?[...e.and]:[e],o=(l)=>r(l,t)||!s(l)&&!s(n)&&Object.keys(n).every((u)=>(u in l)&&r(l[u],n[u]));if(i.some(o))return e;if(!s(n)){if(i.findIndex((u)=>!s(u)&&Object.keys(n).every((c)=>!(c in u)))===0){let u={...i[0],...n};return i.length===1?u:{and:[u,...i.slice(1)]}}}return{and:[...i,t]}}function U(e){let t=[],r={where(s,n,i){return t.push(at(s,n,i)),r},and(s){return t.push(G("and",U(s))),r},or(s){return t.push(G("or",U(s))),r},not(s){return t.push({not:G("and",U(s))}),r}};if(e(r),t.length===0)throw new a("invalid_description","an empty group: write at least one .where(…) inside",{path:"where"});return t}function G(e,t){if(t.length===1)return t[0];return e==="and"?{and:t}:{or:t}}function Lt(e){if(typeof e!=="string")throw new a("invalid_description",'select expects a text: "a, b, relation(c, d)"',{path:"select"});let t=0,r=(l)=>{throw new a("invalid_description",`invalid select at ${t}: ${l}`,{path:"select"})},s=()=>{while(t<e.length&&/\s/.test(e[t]))t++},n=()=>{if(s(),e[t]==="*")return t++,"*";let l=/^[A-Za-z_][A-Za-z0-9_]{0,62}/.exec(e.slice(t));if(!l)return r("expected a column name");return t+=l[0].length,l[0]},i=(l)=>{if(l>8)r("relations nested too deeply");let u=[],c=!1,f={};for(;;){let d=n();if(s(),e[t]==="("){if(d==="*")r('"*" has no columns');t++;let h=i(l+1);if(s(),e[t]!==")")r('expected ")"');t++,f[d]={select:h.select,...Object.keys(h.include).length?{include:h.include}:{}}}else if(d==="*")c=!0;else if(!u.includes(d))u.push(d);if(s(),e[t]===","){t++;continue}break}return{select:c?"*":u,include:f}},o=i(0);if(s(),t<e.length)r(`unexpected "${e[t]}"`);if(o.select!=="*"&&o.select.length===0)return{select:"*",include:o.include};return{select:o.select,...Object.keys(o.include).length?{include:o.include}:{}}}function It(e,t="asc"){if(typeof e!=="string"||!ds.test(e))throw new a("invalid_description",`invalid order column "${String(e)}"`,{path:"order"});if(t!=="asc"&&t!=="desc")throw new a("invalid_description",'order direction: "asc" or "desc"',{path:"order"});return t==="asc"?e:[e,t]}function Mt(e,t){let r=typeof t==="string"?t:t[0];return[...(e??[]).filter((n)=>(typeof n==="string"?n:n[0])!==r),t]}var Vt=20,Re=1000,Yt=["save","version","fields","realtime"],ps=new Set(["type","table","select","where","order","pageSize","include","search","keyColumn","reference","parent","cursor","params","dependsOn","autoLoad","aggregate",...Yt]),gs=new Set(["group","count","sum","avg","min","max"]),Ut=/^[A-Za-z_][A-Za-z0-9_]{0,62}$/,Gt=/^[A-Za-z_][A-Za-z0-9_-]{0,63}$/,ms=new Set(["select","where","order","limit","required","count","include"]),Ft=new Set(["eq","ne","gt","gte","lt","lte"]),Kt=new Set(["in","notIn"]),Bt=new Set(["like","ilike","notLike","notIlike","match"]),Wt=new Set(["between","notBetween"]),Zt=new Set(["is","not"]),Jt=new Set(["contains","containedBy","overlap"]),Xt=/^[A-Za-z_][A-Za-z0-9_]{0,62}$/,ys=/^([A-Za-z_][A-Za-z0-9_]{0,62}\.)?[A-Za-z_][A-Za-z0-9_]{0,62}$/,bs=/^[A-Za-z_][A-Za-z0-9_]{0,62}(\.[A-Za-z0-9_]{1,63})+$/,p=(e,t)=>{throw new a("invalid_description",`invalid list description at ${e}: ${t}`,{path:e})},C=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e)&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null),H=(e)=>e===null||typeof e==="string"||typeof e==="boolean"||typeof e==="number"&&Number.isFinite(e);function Le(e,t,r=0){if(r>32)p(t,"value nested too deeply");if(H(e))return;if(Array.isArray(e))return e.forEach((s,n)=>Le(s,`${t}[${n}]`,r+1));if(C(e))return Object.entries(e).forEach(([s,n])=>Le(n,`${t}.${s}`,r+1));p(t,"not a JSON value")}function D(e,t){if(typeof e!=="string"||!Xt.test(e))p(t,"expected a column name");return e}function ct(e,t){if(e==="*")return"*";if(!Array.isArray(e)||e.length===0)return p(t,'expected "*" or a non-empty array of column names');return e.map((r,s)=>D(r,`${t}[${s}]`))}function Ht(e,t){if(!Array.isArray(e))return p(t,'expected an array of "column" or ["column", "asc" | "desc"]');return e.map((r,s)=>{let n=`${t}[${s}]`;if(typeof r==="string")return D(r,n);if(!Array.isArray(r)||r.length!==2)return p(n,'expected "column" or ["column", "asc" | "desc"]');let[i,o]=r;if(o!=="asc"&&o!=="desc")p(`${n}[1]`,'expected "asc" or "desc"');return[D(i,`${n}[0]`),o]})}function ws(e,t){if(H(e))return;if(Array.isArray(e))return e.forEach((s,n)=>H(s)?void 0:p(`${t}[${n}]`,"expected a scalar"));if(!C(e))return p(t,"expected a value, an array or an object of operators");let r=Object.entries(e);if(r.length===0)p(t,"empty condition");for(let[s,n]of r){let i=`${t}.${s}`;if(it(n)&&(Ft.has(s)||Kt.has(s)||Bt.has(s)||Wt.has(s)||Zt.has(s)||Jt.has(s)))continue;if(Ft.has(s)){if(!H(n))p(i,"expected a scalar")}else if(Kt.has(s)){if(!Array.isArray(n)||!n.every(H))p(i,"expected an array of scalars")}else if(Bt.has(s)){if(typeof n!=="string")p(i,"expected a string")}else if(Wt.has(s)){if(!Array.isArray(n)||n.length!==2||!n.every(H))p(i,"expected [low, high]")}else if(Zt.has(s)){if(n!==null&&typeof n!=="boolean")p(i,"expected null, true or false")}else if(Jt.has(s)){if(s==="overlap"&&!Array.isArray(n))p(i,"expected an array");Le(n,i)}else throw new a("unknown_operator",`invalid list description at ${i}: unknown operator`,{path:i,params:{operator:s}})}}function I(e,t="where",r=0){if(r>16)p(t,"filter nested too deeply");if(!C(e))return p(t,"expected an object");for(let[s,n]of Object.entries(e)){let i=`${t}.${s}`;if(s==="and"||s==="or"){if(!Array.isArray(n)||n.length===0)p(i,"expected a non-empty array of filters");n.forEach((o,l)=>I(o,`${i}[${l}]`,r+1))}else if(s==="not")I(n,i,r+1);else if(Xt.test(s)||bs.test(s))ws(n,i);else p(i,"expected a column name, a JSON path or and / or / not")}return e}function ut(e,t,r=0){if(r>8)p(t,"relations nested too deeply");if(Array.isArray(e)){if(e.length===0)p(t,"empty array");return e.map((s,n)=>D(s,`${t}[${n}]`))}if(!C(e))return p(t,"expected an array of relations or an object");for(let[s,n]of Object.entries(e)){let i=`${t}.${s}`;if(D(s,i),typeof n==="boolean")continue;if(!C(n))p(i,"expected true, false or an object");for(let[o,l]of Object.entries(n)){let u=`${i}.${o}`;if(!ms.has(o))p(u,"unknown key");if(o==="select")ct(l,u);else if(o==="where")I(l,u);else if(o==="order")Ht(l,u);else if(o==="limit")Qt(l,u,Re);else if(o==="required"||o==="count"){if(typeof l!=="boolean")p(u,"expected true or false")}else ut(l,u,r+1)}}return e}function Qt(e,t,r){if(typeof e!=="number"||!Number.isInteger(e)||e<1||e>r)p(t,`expected an integer between 1 and ${r}`);return e}function F(e){if(!C(e))return p("$","expected an object");if("kind"in e)p("kind",'a description has no "kind" (a store object has kind "store")');for(let s of Object.keys(e))if(!ps.has(s))p(s,"unknown key");if(e.type!==void 0&&e.type!=="list")p("type",'expected "list"');let t=er(e.table),r=e.type==="list"?{type:"list",table:t}:{table:t};if(e.select!==void 0)r.select=ct(e.select,"select");if(e.where!==void 0)r.where=I(e.where);if(e.order!==void 0)r.order=Ht(e.order,"order");if(e.pageSize!==void 0)r.pageSize=Qt(e.pageSize,"pageSize",Re);if(e.include!==void 0)r.include=ut(e.include,"include");if(e.search!==void 0){let s=e.search;if(!Array.isArray(s)||s.length===0)p("search","expected a non-empty array of column names");r.search=s.map((n,i)=>D(n,`search[${i}]`))}if(e.keyColumn!==void 0)r.keyColumn=D(e.keyColumn,"keyColumn");if(e.reference!==void 0){if(typeof e.reference!=="boolean")p("reference","expected true or false");r.reference=e.reference}if(e.parent!==void 0){let s=e.parent;if(!C(s))p("parent",'expected { "store": "…", "column": "…" }');let n=s;for(let i of Object.keys(n))if(i!=="store"&&i!=="column")p(`parent.${i}`,"unknown key");if(typeof n.store!=="string"||!Gt.test(n.store))p("parent.store","expected a store name");if(r.parent={store:n.store,column:D(n.column,"parent.column")},r.reference)p("parent","a reference store has no parent")}if(e.cursor!==void 0){if(e.cursor!=="first"&&e.cursor!=="last"&&e.cursor!=="none")p("cursor",'expected "first", "last" or "none"');r.cursor=e.cursor}if(e.params!==void 0)r.params=ks(e.params);if(e.dependsOn!==void 0)r.dependsOn=qt(e.dependsOn);if(e.autoLoad!==void 0){if(typeof e.autoLoad!=="boolean")p("autoLoad","expected true or false");r.autoLoad=e.autoLoad}if(e.aggregate!==void 0)r.aggregate=Ss(e.aggregate);return lt(e,r),r}function ks(e){if(!C(e))return p("params",'expected { "name": value }');for(let[t,r]of Object.entries(e)){if(!Ut.test(t))p(`params.${t}`,"expected a parameter name");if(!H(r))p(`params.${t}`,"expected a scalar")}return e}function qt(e,t="dependsOn"){let r=(s,n)=>{if(!C(s))return p(n,'expected { "store": "…", "field": "…", "param": "…" }');for(let i of Object.keys(s))if(i!=="store"&&i!=="field"&&i!=="param")p(`${n}.${i}`,"unknown key");if(typeof s.store!=="string"||!Gt.test(s.store))p(`${n}.store`,"expected a store name");if(typeof s.field!=="string"||!/^[A-Za-z_][A-Za-z0-9_]{0,62}(\.[A-Za-z0-9_]{1,63})*$/.test(s.field))p(`${n}.field`,"expected a field path");if(typeof s.param!=="string"||!Ut.test(s.param))p(`${n}.param`,"expected a parameter name");return s};if(Array.isArray(e)){if(e.length===0)p(t,"expected a non-empty array");return e.map((s,n)=>r(s,`${t}[${n}]`))}return r(e,t)}function Ss(e){if(!C(e))return p("aggregate",'expected { "group"?: [...], "count"?: true, "sum"?: [...], … }');for(let[r,s]of Object.entries(e)){let n=`aggregate.${r}`;if(!gs.has(r))throw new a("unknown_operator",`invalid list description at ${n}: unknown aggregate`,{path:n,params:{operator:r}});if(r==="count"){if(typeof s!=="boolean")p(n,"expected true or false")}else if(!Array.isArray(s)||s.length===0)p(n,"expected a non-empty array of column names");else s.forEach((i,o)=>D(i,`${n}[${o}]`))}let t=e;if(!t.count&&!t.sum&&!t.avg&&!t.min&&!t.max)p("aggregate","expected at least one of count, sum, avg, min, max");return t}function lt(e,t){if(e.save!==void 0){if(e.save!=="batch"&&e.save!=="immediate")p("save",'expected "batch" or "immediate"');t.save=e.save}if(e.version!==void 0)t.version=D(e.version,"version");if(e.realtime!==void 0){if(typeof e.realtime!=="boolean")p("realtime","expected true or false");t.realtime=e.realtime}if(e.fields!==void 0){try{he(e.fields,{at:"fields"})}catch(r){let s=r.path??"fields";p(s,r.message.replace(/^invalid field at [^:]+: /,""))}t.fields=e.fields}}function er(e){if(typeof e!=="string"||!ys.test(e))p("table",'expected a table name ("clients" or "schema.clients")');return e}var vs=new Set(["type","table","key","keyColumn","select","include","dependsOn","autoLoad",...Yt]);function we(e){if(!C(e))return p("$","expected an object");if("kind"in e)p("kind",'a description has no "kind" (a store object has kind "store")');if(e.type!=="record")p("type",'expected "record"');if("value"in e){for(let i of Object.keys(e))if(i!=="type"&&i!=="value"&&i!=="fields"&&i!=="save")p(i,'unknown key (a local record has only "value", "fields" and "save")');let s=e.value;if(!C(s)&&!Array.isArray(s))p("value","expected a JSON object or array");Le(s,"value");let n={type:"record",value:s};return lt(e,n),n}for(let s of Object.keys(e))if(!vs.has(s))p(s,"unknown key");let t={type:"record",table:er(e.table)},r=e.key;if(r!==void 0){if(!(typeof r==="string"&&r.length>0)&&!(typeof r==="number"&&Number.isFinite(r)))p("key","expected a non-empty string or a number");t.key=r}if(e.keyColumn!==void 0)t.keyColumn=D(e.keyColumn,"keyColumn");if(e.select!==void 0)t.select=ct(e.select,"select");if(e.include!==void 0)t.include=ut(e.include,"include");if(e.dependsOn!==void 0){t.dependsOn=qt(e.dependsOn);for(let s of[t.dependsOn].flat())if(s.param!=="key")p("dependsOn.param",'a record follows its key: "param": "key"')}if(e.autoLoad!==void 0){if(typeof e.autoLoad!=="boolean")p("autoLoad","expected true or false");t.autoLoad=e.autoLoad}return lt(e,t),t}function ft(e){if(C(e)&&e.type==="record")return we(e);return F(e)}var Ie=(e)=>(e??[]).map((t)=>typeof t==="string"?{column:t,direction:"asc"}:{column:t[0],direction:t[1]});var tr=(e)=>!!e.rules||e.type==="enum";class ke{own;sources=[];constructor(e){this.own=e?he(e):[]}all(){return[...this.own,...this.sources.flat()].filter((e)=>!e.field.includes("."))}rule(e){let t=this.all().filter((r)=>r.field===e);return t.find(tr)??t[0]}ruled(){return[...new Set(this.all().filter(tr).map((e)=>e.field))]}use(e){this.sources.push(e);let t=!1;return()=>{if(t)return;t=!0;let r=this.sources.indexOf(e);if(r>=0)this.sources.splice(r,1)}}versionColumn(){return this.all().find((e)=>e.roles.includes("version"))?.field}path(e){return A(e)}declared(){return this.own}}var Fe=(e,t)=>!t||t==="*"?e:Object.fromEntries(t.map((r)=>[r,e[r]])),sr=(e,t)=>{if(e===t)return 0;if(e===null||e===void 0)return 1;if(t===null||t===void 0)return-1;return e<t?-1:1};function Os(e,t){if(t.length===0)return e;return[...e].sort((r,s)=>{for(let n of t){let i=sr(r[n.column],s[n.column]);if(i!==0)return n.direction==="asc"?i:-i}return 0})}function Me(e,t){let r="";for(let s=0;s<e.length;s++){let n=e[s];if(n==="\\"&&s+1<e.length)r+=e[++s].replace(/[.*+?^${}()|[\]\\]/g,"\\$&");else if(n==="%")r+=".*";else if(n==="_")r+=".";else r+=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}return new RegExp("^"+r+"$",t+"s")}function xs(e,t){let r=t.term.toLowerCase();return t.columns.some((s)=>String(e[s]??"").toLowerCase().includes(r))}function K(e,t){return Object.entries(t).every(([r,s])=>{if(s===void 0)return!0;if(r==="and")return s.every((n)=>K(e,n));if(r==="or")return s.some((n)=>K(e,n));if(r==="not")return!K(e,s);return As(e[r],s)})}var rr=/^\d{4}-\d{2}-\d{2}T/,ie=(e,t)=>{if(typeof e==="string"&&typeof t==="string"&&rr.test(e)&&rr.test(t))return Date.parse(e)-Date.parse(t);return sr(e,t)},O=(e)=>e===null||e===void 0;function As(e,t){if(t===null)return O(e);if(Array.isArray(t))return t.includes(e);if(typeof t!=="object")return e===t;return Object.entries(t).every(([r,s])=>{switch(r){case"eq":return s===null?O(e):!O(e)&&e===s;case"ne":return!O(e)&&e!==s;case"gt":return!O(e)&&ie(e,s)>0;case"gte":return!O(e)&&ie(e,s)>=0;case"lt":return!O(e)&&ie(e,s)<0;case"lte":return!O(e)&&ie(e,s)<=0;case"between":return!O(e)&&ie(e,s[0])>=0&&ie(e,s[1])<=0;case"in":return!O(e)&&s.includes(e);case"notIn":return!O(e)&&!s.includes(e);case"like":return!O(e)&&Me(s,"").test(String(e));case"ilike":return!O(e)&&Me(s,"i").test(String(e));case"notLike":return!O(e)&&!Me(s,"").test(String(e));case"notIlike":return!O(e)&&!Me(s,"i").test(String(e));case"is":return s===null?O(e):e===s;case"not":return s===null?!O(e):e!==s;default:throw Error(`fake transport: operator "${r}" is not supported`)}})}function _s(e,t){let r=new Map;for(let i of e){let o=JSON.stringify((t.group??[]).map((l)=>i[l]??null));r.set(o,[...r.get(o)??[],i])}if(!t.group&&r.size===0)r.set("[]",[]);let s=(i,o)=>i.map((l)=>l[o]).filter((l)=>typeof l==="number"),n=[...r.entries()].map(([i,o])=>{let l={};if((t.group??[]).forEach((c,f)=>l[c]=JSON.parse(i)[f]),t.count)l.count=o.length;let u=(c,f,d)=>{if(f)l[c]=Object.fromEntries(f.map((h)=>[h,d(s(o,h))]))};return u("sum",t.sum,(c)=>c.length?c.reduce((f,d)=>f+d,0):null),u("avg",t.avg,(c)=>c.length?c.reduce((f,d)=>f+d,0)/c.length:null),u("min",t.min,(c)=>c.length?Math.min(...c):null),u("max",t.max,(c)=>c.length?Math.max(...c):null),l});if(t.order?.length){let i=(o,l)=>l.includes(".")?o[l.split(".")[0]]?.[l.split(".")[1]]:o[l];n=[...n].sort((o,l)=>{for(let u of t.order){let c=i(o,u.column),f=i(l,u.column);if(c===f)continue;let d=c<f?-1:1;return u.direction==="asc"?d:-d}return 0})}return t.limit?n.slice(0,t.limit):n}function Se(e,t){return e.filter((r)=>(!t.where||K(r,t.where))&&(!t.search||xs(r,t.search)))}function dt(e,t){return Os([...Se(e,t)],t.order).slice(t.offset,t.offset+t.limit).map((r)=>Fe(r,t.select))}function nr(e,t={}){let r=e.map((i)=>({...i})),s=t.keyColumn??"id",n=()=>r.reduce((i,o)=>Math.max(i,typeof o[s]==="number"?o[s]:0),0)+1;return{name:t.name??"memory",rows:()=>r,async find(i,o){return dt(r,i)},async count(i,o){return Se(r,i).length},async findOne(i,o){let l=r.find((u)=>K(u,i.where));return l?Fe(l,i.select):null},async insert(i,o){let l={[s]:n(),...i.values};return r=[...r,l],l},async update(i,o){let l=[];return r=r.map((u)=>{if(!K(u,i.where))return u;let c={...u,...i.set};return l.push(c),c}),l},async remove(i,o){let l=r.filter((u)=>K(u,i.where));return r=r.filter((u)=>!l.includes(u)),l},async aggregate(i,o){return _s(Se(r,i),i)}}}var pe=(e)=>typeof e==="object"&&e!==null&&typeof e.setArgs==="function"&&typeof e.fn==="string",Ke=(e)=>Array.isArray(e)?e:e&&typeof e==="object"&&Array.isArray(e.rows)?e.rows:e&&typeof e==="object"?[e]:[];function ir(e,t,r,s={}){let n=s.args,i=null,o=null,l=(c,f)=>{if(typeof e.call!=="function")return Promise.reject(new a("read_only",`transport "${e.name}" cannot call functions (no call())`));let d=c?{...n??{},...c}:n,h=JSON.stringify(d??null);if(i&&i.key===h)return i.promise;let g=e.call({kind:t,name:r,...d!==void 0?{args:d}:{}},f),y={key:h,promise:g};i=y;let b=()=>{if(i===y)i=null};return g.then(b,b),g},u=(c)=>({...c.limit!==void 0?{limit:c.limit,offset:c.offset??0}:{},...c.order&&c.order.length?{order:c.order.map((f)=>[f.column,f.direction])}:{},...c.where?{where:c.where}:{},...c.search?{search:c.search}:{}});return{name:`${e.name}:${t}`,kind:t,fn:r,args:()=>n,setArgs(c){n=c,i=null},async find(c,f){if(s.server)return o=u(c),Ke(await l(o,f)).map((d)=>Fe(d,c.select));return dt(Ke(await l(null,f)),c)},async count(c,f){if(s.server){let d=await l(o??u(c),f),h=d&&typeof d==="object"&&!Array.isArray(d)?d.total:void 0;return typeof h==="number"?h:Ke(d).length}return Se(Ke(await l(null,f)),c).length},async findOne(c,f){let d=await l(null,f);if(d===null||d===void 0)return null;if(!Array.isArray(d))return d;return(Object.keys(c.where).length?d.find((g)=>K(g,c.where)):void 0)??d[0]??null}}}var or=["beforeload","load","beforesave","saved","change","error","current"],lr=(e,t)=>globalThis.console?.error(`@poadio/data: a "${e}" listener failed`,t);class ve{listeners=new Map;on(e,t){if(!or.includes(e))throw TypeError(`unknown store event "${String(e)}": ${or.join(", ")}`);if(typeof t!=="function")throw TypeError("a store event listener is a function");let r=this.listeners.get(e);if(!r)this.listeners.set(e,r=new Set);let s=t;return r.add(s),()=>void r.delete(s)}has(e){return(this.listeners.get(e)?.size??0)>0}emit(e,t){let r=this.listeners.get(e);if(!r)return;for(let s of[...r])try{s(t)}catch(n){lr(e,n)}}before(e,t){let r=this.listeners.get(e),s={};if(!r)return s;for(let n of[...r]){let i;try{i=n(t)}catch(o){lr(e,o);continue}if(i===!1)return!1;if(i&&typeof i==="object"&&!Array.isArray(i))Object.assign(s,i)}return s}}var $s={setTimeout:(e,t)=>X.setTimeout(e,t),clearTimeout:(e)=>X.clearTimeout(e)},Oe=(e,t)=>e===null?1:Math.max(1,Math.ceil(e/t)),oe=(e,t)=>JSON.stringify(e)===JSON.stringify(t);class ur{transport;kind="store";type="list";description;state;events=new ve;debounceMs;scheduler;seq=0;controller=null;timer=null;stale=!0;countKey=null;waiters=[];mode;keyColumn;fields;baseRows=[];writer;constructor(e,t){this.transport=e;let{debounceMs:r,scheduler:s,realtimeDebounceMs:n,parentStore:i,...o}=t;if(this.realtimeDebounceMs=n??250,this.description=F(o),r!==void 0&&(!Number.isFinite(r)||r<0))throw new a("invalid_description","debounceMs must be a non-negative number",{path:"debounceMs"});if(this.debounceMs=r??300,this.scheduler=s??$s,this.mode=this.description.save??(this.description.parent?"batch":"immediate"),i)this.linkParent(()=>i);this.keyColumn=this.description.keyColumn??"id",this.fields=new ke(this.description.fields);let l=this;this.writer=new ye({table:this.description.table,keyColumn:this.keyColumn,get version(){return l.description.version??l.fields.versionColumn()??null},transport:e,mode:()=>this.mode,rule:(c)=>this.fields.rule(c),ruled:()=>this.fields.ruled(),changed:()=>this.publishRows(),stored:(c,f,d)=>{this.stored(c,f,d),this.emitWrite({event:d!==c?"insert":"update",table:this.description.table,record:f})},removed:(c)=>{let f=this.baseRows.find((d)=>this.keyOf(d)===c)?.[this.keyColumn];this.removed(c),this.emitWrite({event:"delete",table:this.description.table,old:{[this.keyColumn]:f??JSON.parse(c)}})},incoming:(c,f)=>this.receiveRow(c,f)});let u=this.description.pageSize??(this.description.reference?Re:Vt);if(this.state=new V({rows:[],total:null,page:1,pageSize:u,pageCount:1,order:Ie(this.description.order),filters:{},search:"",searchColumns:this.description.search??[],status:"idle",error:null,edits:this.writer.all(),dirty:!1,saving:!1,realtime:"off",current:Rs,filtered:!1,params:{...this.description.params??{}},totals:null},{start:()=>this.start(),stop:()=>this.stop()}),this.cursorActive=this.description.cursor!==void 0,this.description.autoLoad)Promise.resolve().then(()=>this.keepAlive())}get(){return this.state.get()}subscribe(e){return this.state.subscribe(e)}toJSON(){throw new a("not_serializable","a data store cannot be serialised: pass its JSON description instead")}setPage(e){let t=Math.max(1,Math.floor(Number.isFinite(e)?e:1));if(t===this.get().page)return;this.change({page:t})}setPageSize(e){if(!Number.isInteger(e)||e<1||e>Re)throw new a("invalid_description",`pageSize must be an integer between 1 and ${Re}`,{path:"pageSize"});if(e===this.get().pageSize)return;this.change({pageSize:e,page:1})}setOrder(e){let t=this.toSorts(e);if(oe(t,this.get().order))return;this.change({order:t,page:1})}toSorts(e){let t=e.map((r)=>typeof r==="string"||Array.isArray(r)?Ie([r])[0]:r);return F({table:this.description.table,order:t.map((r)=>[r.column,r.direction])}),t}checkColumns(e){return F({table:this.description.table,search:[...e]}),[...e]}setSearchColumns(e){let t=e===null?this.description.search??[]:e.length?this.checkColumns(e):[];if(oe(t,this.get().searchColumns))return;if(!this.get().search.trim()){this.put({...this.get(),searchColumns:t});return}this.change({searchColumns:t,page:1})}update(e){let t=this.get(),r={},s=!1;if(e.pageSize!==void 0&&e.pageSize!==t.pageSize){if(!Number.isInteger(e.pageSize)||e.pageSize<1||e.pageSize>Re)throw new a("invalid_description",`pageSize must be an integer between 1 and ${Re}`,{path:"pageSize"});r.pageSize=e.pageSize,s=!0}if(e.order!==void 0){let i=this.toSorts(e.order);if(!oe(i,t.order))r.order=i,s=!0}if(e.filters!==void 0){if(I(e.filters,"filters"),!oe(e.filters,t.filters))r.filters={...e.filters},s=!0}if(e.searchColumns!==void 0){let i=e.searchColumns===null?this.description.search??[]:e.searchColumns.length?this.checkColumns(e.searchColumns):[];if(!oe(i,t.searchColumns)){if(r.searchColumns=i,t.search.trim()||(e.search??"").trim())s=!0}}if(e.search!==void 0&&e.search!==t.search){if(r.search=e.search,e.search.trim()!==t.search.trim())s=!0}if(e.page!==void 0){let i=Math.max(1,Math.floor(Number.isFinite(e.page)?e.page:1));if(i!==t.page)r.page=i}else if(s&&t.page!==1)r.page=1;if(Object.keys(r).length===0)return;if(!(Object.keys(r).some((i)=>i!=="search")||(r.search??t.search).trim()!==t.search.trim())){this.put({...t,...r});return}this.change(r)}toggleSort(e){let t=this.get().order[0];if(t?.column!==e)this.setOrder([{column:e,direction:"asc"}]);else if(t.direction==="asc")this.setOrder([{column:e,direction:"desc"}]);else this.setOrder([])}setFilter(e,t){let{[e]:r,...s}=this.get().filters;this.setFilters(t===void 0?s:{...s,[e]:t})}setFilters(e){if(I(e,"filters"),oe(e,this.get().filters))return;this.change({filters:{...e},page:1})}setSearch(e){if(e===this.get().search)return;if(this.put({...this.get(),search:e,page:1}),this.stale=!0,!this.state.observed)return;this.clearTimer(),this.timer=this.scheduler.setTimeout(()=>{this.timer=null,this.read()},this.debounceMs)}refresh(){if(!this.state.observed)return this.stale=!0,Promise.resolve();return this.countKey=null,this.read()}load(e){if(e!==void 0)this.applyParams(e);return this.loadReady()}sync(e){return this.load(e)}applyParams(e){if(pe(this.transport)){if(this.transport.setArgs(e),this.countKey=null,this.stale=!0,this.state.observed)this.read();return}let t=e??{},r={...t.params&&typeof t.params==="object"?t.params:{}};for(let[s,n]of Object.entries(t))if(!js.has(s))r[s]=n;if(Object.keys(r).length>0)this.setParams(r);this.update({...t.where!==void 0?{filters:t.where}:{},...t.order!==void 0?{order:t.order}:{},...t.search!==void 0?{search:t.search}:{},...t.page!==void 0?{page:t.page}:{},...t.pageSize!==void 0?{pageSize:t.pageSize}:{}})}described=null;describeAs(e){this.described=e}toDescription(){if(this.described)return cr(this.described);let{table:e,...t}=this.description;return cr({name:"",source:"table",table:e,...t})}async loadReady(){let e=!1;for(let r=0;r<8;r++){let s=this.get();if(this.controller)await new Promise((n)=>this.waiters.push(n));else if(!e&&(this.stale||s.status==="idle"||s.status==="error"))e=!0,await this.read();else break}let t=this.get();if(t.status==="error"&&t.error)throw t.error;return t}writeListeners=new Set;onWrite(e){return this.writeListeners.add(e),()=>void this.writeListeners.delete(e)}emitWrite(e){for(let t of[...this.writeListeners])t(e)}realtimeDebounceMs;stopRealtime=null;realtimeTimer=null;loadedOnce=!1;lastRead=0;gone=new Set;receive(e){if(!gt(e.table,this.description.table))return;let r=(e.event==="delete"?e.old:e.record)?.[this.keyColumn];if(r===void 0){this.scheduleRefetch();return}let s=this.description.parent;if(s&&e.record&&!Q(e.record[s.column],this.lastParentKey)&&!this.baseRows.some((n)=>this.keyOf(n)===me(r)))return;this.receiveRow(me(r),e.event==="delete"?null:e.record,e.event)}receiveRow(e,t,r){let s=this.baseRows.findIndex((c)=>this.keyOf(c)===e),n=s>=0?this.baseRows[s]:null,i=this.writer.versionColumn,o=this.writer.incoming(e,t);if(o==="deferred"||o==="stale")return;if(t===null){if(o==="handled"){this.gone.add(e),this.adjustTotal(-1);return}if(n)this.baseRows=this.baseRows.filter((c,f)=>f!==s),this.adjustTotal(-1),this.put({...this.get(),rows:this.mergedRows()});this.scheduleRefetch();return}if(!n){this.scheduleRefetch();return}if(o==="none"&&!ge(t,n,i))return;let l=xe(t,n,this.description.include),u=Object.keys({...n,...l}).filter((c)=>!Q(n[c],l[c]));if(this.baseRows=this.baseRows.map((c,f)=>f===s?l:c),this.put({...this.get(),rows:this.mergedRows()}),r==="insert"||u.some((c)=>this.movingColumns().has(c))||this.description.include&&u.length>0)this.scheduleRefetch()}movingColumns(){let e=this.get(),t=new Set(e.order.map((r)=>r.column));if(e.search.trim())for(let r of e.searchColumns)t.add(r);for(let r of[this.description.where,e.filters])if(r)pt(r,t);if(this.description.parent)t.add(this.description.parent.column);return t}adjustTotal(e){let t=this.get();if(t.total===null)return;let r=Math.max(0,t.total+e);this.put({...t,total:r,pageCount:Oe(r,t.pageSize)})}scheduleRefetch(){if(!this.state.observed){this.stale=!0;return}if(this.realtimeTimer!==null)this.scheduler.clearTimeout(this.realtimeTimer);this.realtimeTimer=this.scheduler.setTimeout(()=>{if(this.realtimeTimer=null,this.writer.saving)return this.scheduleRefetch();this.countKey=null,this.read(!0)},this.realtimeDebounceMs)}startRealtime(e){if(this.stopRealtime||this.description.realtime===!1||typeof this.transport.subscribe!=="function")return;let t=e;this.setRealtime("connecting",t),this.stopRealtime=this.transport.subscribe({table:this.description.table},{change:(r)=>this.receive(r),status:(r)=>{let s=this.get().realtime;if(this.setRealtime(r,t),r==="live"&&s!=="live"&&this.loadedOnce&&!(this.description.reference&&Date.now()-this.lastRead<2000))this.scheduleRefetch()}}),t=!1}setRealtime(e,t=!1){if(this.get().realtime===e)return;if(t)this.put({...this.get(),realtime:e},!0);else this.put({...this.get(),realtime:e})}draftIds=new WeakMap;keyOf(e){let t=e!==null&&typeof e==="object"?this.draftIds.get(e):void 0;if(t)return t;return me(e!==null&&typeof e==="object"?e[this.keyColumn]:void 0)}shown(e){let t=this.baseRows.find((r)=>this.keyOf(r)===e);if(t)return t;return this.writer.inserted().find((r)=>r.id===e)?.row??null}set(e,t,r){let s=A(t);if(s.length===0||typeof s[0]!=="string")throw new a("read_only","a row is changed column by column: give a column",{path:"field"});let n=s[0];if(this.computed().has(n))throw new a("read_only",`"${n}" is a computed field: it is never written`,{field:n});if(n===this.keyColumn&&!e.startsWith("new:"))throw new a("read_only",`the key column "${n}" cannot be changed`,{field:n});let i=this.baseRows.find((u)=>this.keyOf(u)===e),o=this.writer.merge(e,i??this.shown(e)??{}),l=s.length===1?r:j(Z(o,s,r),[n]);this.writer.set(e,i??null,n,l)}insert(e){let t=this.description.parent,r=t?this.parentKey():null;return this.writer.insert(t&&r!==null&&e[t.column]===void 0?{...e,[t.column]:r}:{...e})}remove(e){let t=this.baseRows.find((r)=>this.keyOf(r)===e);this.writer.remove(e,t??null)}async save(e){if(this.events.has("beforesave")){let s=this.pendingChanges(e);if(s.length>0){let n=this.events.before("beforesave",{changes:s});if(n===!1)return!1;for(let i of s)if(i.kind!=="delete")for(let[o,l]of Object.entries(n))this.set(i.id,o,l)}}let t=this.pendingChanges(e).map((s)=>s.id),r=await this.saveRows(e);if(r&&t.length)this.events.emit("saved",{ids:t});if(!r){let s=Object.values(this.writer.all()).map((n)=>n.error??Object.values(n.errors)[0]??null).find(Boolean);if(s)this.events.emit("error",{error:s,during:"save"})}return r}pendingChanges(e){let t=this.writer.all();return Object.entries(t).filter(([r,s])=>s.dirty&&(e===void 0||r===e)).map(([r,s])=>({id:r,kind:s.kind,values:s.changes}))}saveRows(e){let t=this.description.parent;if(t){let r=this.parentKey();if(r===null&&this.writer.inserted().length>0)return Promise.resolve(!1);for(let s of this.writer.inserted())if(s.row[t.column]===void 0||s.row[t.column]===null)this.writer.set(s.id,null,t.column,r)}return this.writer.save(e,(r)=>this.baseRows.find((s)=>this.keyOf(s)===r)??null)}revert(e,t){this.writer.revert(e,t)}resolveParent=null;parentStore=null;stopParent=null;unlinkParent=null;lastParentKey=void 0;linkParent(e){this.resolveParent=e}parent(){if(this.parentStore||!this.description.parent||!this.resolveParent)return this.parentStore;let e=null;try{e=this.resolveParent()}catch{e=null}if(!e)return null;if(e.type!=="record")throw new a("invalid_description",`the parent of a child store must be a record store ("${this.description.parent.store}")`,{path:"parent.store"});return this.parentStore=e,this.unlinkParent=e.linkChild({dirty:()=>this.writer.dirty,saving:()=>this.writer.saving,save:()=>this.save(),revert:()=>this.writer.revert(),valid:()=>this.writer.validateAll((t)=>this.baseRows.find((r)=>this.keyOf(r)===t)??null),adopt:(t)=>{this.lastParentKey=t;let r=this.description.parent;for(let s of this.writer.inserted())if(s.row[r.column]===void 0||s.row[r.column]===null)this.writer.set(s.id,null,r.column,t)}}),e}parentKey(){let e=this.parent();return e?e.key():null}parentChanged(){let e=this.parentKey();if(e===this.lastParentKey)return;let t=this.lastParentKey===void 0;if(this.lastParentKey=e,t)return;this.writer.revert(),this.change({page:1})}notifyParent(){this.parentStore?.childChanged()}resolve(e,t,r){this.writer.resolve(e,t,r)}dismiss(e){this.writer.dismiss(e)}mergedRows(){return this.pipeline(this.rawRows())}rawRows(){let e=this.writer.all();if(this.gone.size)for(let s of[...this.gone]){if(e[s])continue;this.gone.delete(s),this.baseRows=this.baseRows.filter((n)=>this.keyOf(n)!==s)}if(Object.keys(e).length===0)return this.baseRows;let t=this.writer.inserted().map((s)=>(this.draftIds.set(s.row,s.id),s.row)),r=this.baseRows.filter((s)=>!this.writer.isDeleted(this.keyOf(s))).map((s)=>this.writer.merge(this.keyOf(s),s));return[...t,...r]}publishRows(){let e=this.get(),t=this.writer.all();if(e.edits===t)return;this.put({...e,rows:this.mergedRows(),edits:t,dirty:this.writer.dirty,saving:this.writer.saving}),this.notifyParent()}stored(e,t,r){let s=this.get(),n=this.baseRows.findIndex((o)=>this.keyOf(o)===e||this.keyOf(o)===r),i=n>=0?xe(t,this.baseRows[n],this.description.include):t;if(this.description.include)this.scheduleRefetch();if(n>=0)this.baseRows=this.baseRows.map((o,l)=>l===n?i:o);else if(this.baseRows=[i,...this.baseRows],s.total!==null&&r!==e)this.put({...s,total:s.total+1,pageCount:Oe(s.total+1,s.pageSize)});this.publishRows(),this.put({...this.get(),rows:this.mergedRows()})}removed(e){let t=this.get(),r=this.baseRows.length;if(this.baseRows=this.baseRows.filter((s)=>this.keyOf(s)!==e),this.baseRows.length!==r&&t.total!==null)this.put({...t,total:Math.max(0,t.total-1),pageCount:Oe(Math.max(0,t.total-1),t.pageSize)});this.put({...this.get(),rows:this.mergedRows()})}change(e){if(["filters","search","searchColumns","order","params","pageSize"].some((r)=>(r in e))&&!this.cursorTarget)this.cursorKey=null,this.cursorMoved=!1;let t={...this.get(),...e};if(this.put({...t,pageCount:Oe(t.total,t.pageSize)}),this.stale=!0,this.state.observed)this.read()}start(){if(this.startDepends(),this.description.parent){let r=this.parent();if(r){this.lastParentKey=r.key();let s=!0;this.stopParent=r.subscribe(()=>{if(s)return;this.parentChanged()}),s=!1}}let e=this.description.reference&&this.get().status==="ready"&&this.loadedOnce,t=!e&&(this.stale||this.get().status==="idle");if(this.startRealtime(t),t)this.read();else if(e&&this.stale)this.read(!0)}stop(){this.stopDepending(),this.stopParent?.(),this.stopParent=null,this.clearTimer(),this.cancel();let e=this.description.reference&&this.get().status==="ready"&&this.loadedOnce;if(this.stale=!e,this.realtimeTimer!==null)this.scheduler.clearTimeout(this.realtimeTimer);if(this.realtimeTimer=null,this.stopRealtime?.(),this.stopRealtime=null,!e)this.loadedOnce=!1;if(this.setRealtime("off"),this.get().status==="loading")this.put({...this.get(),status:this.get().total===null?"idle":"ready"})}clearTimer(){if(this.timer!==null)this.scheduler.clearTimeout(this.timer);this.timer=null}cancel(){this.seq++,this.controller?.abort(),this.controller=null,this.settleWaiters()}settleWaiters(){let e=this.waiters;this.waiters=[];for(let t of e)t()}combinedWhere(e){let t=[this.description.where,e,this.get().filters].filter((r)=>!!r&&Object.keys(r).length>0);if(t.length===0)return;return t.length===1?t[0]:{and:t}}read(e=!1){this.clearTimer(),this.cancel();let t=this.seq,r=new X.AbortController;this.controller=r,this.stale=!1;let s=this.get(),n=this.description.parent,i=n?this.parentKey():null,o=()=>(this.baseRows=[],this.countKey=null,this.controller=null,this.put({...this.get(),rows:this.mergedRows(),total:0,pageCount:1,status:"ready",error:null,totals:null}),this.settleWaiters(),Promise.resolve());if(n&&i===null)return o();if(this.dependsList().some((S)=>s.params[S.param]===null||s.params[S.param]===void 0))return o();let l=s.params;if(this.events.has("beforeload")){let S=this.events.before("beforeload",{params:l});if(S===!1)return this.controller=null,this.settleWaiters(),Promise.resolve();l={...l,...S}}this.lastParentKey=n?i:this.lastParentKey;let u;try{u=Nt(this.combinedWhere(n?{[n.column]:i}:void 0),l)}catch(S){this.controller=null;let T=E(S);return this.put({...this.get(),status:"error",error:T}),this.events.emit("error",{error:T,during:"load"}),this.settleWaiters(),Promise.resolve()}let c=Ds(u,this.description.include),f=c.where,d=s.search.trim(),h=s.searchColumns,g=d&&h.length?{term:d,columns:h}:void 0,y={table:this.description.table,...f?{where:f}:{},...g?{search:g}:{},...c.include?{include:c.include}:{}};this.lastBase=y;let b=this.computed(),m=s.order.filter((S)=>!b.has(S.column)),k=this.description.aggregate,_={signal:r.signal};if(!e)this.put({...s,status:"loading",error:null});let z=new Promise((S)=>this.waiters.push(S)),L;if(k?.group)L=this.aggregateRows(k,y,m,_).then((S)=>[S,S.length,null]);else{let S={...y,...this.description.select?{select:Es(this.description.select,this.keyColumn,this.writer.versionColumn)}:{},order:m,limit:s.pageSize,offset:(s.page-1)*s.pageSize},T=JSON.stringify(y),$e=T!==this.countKey||s.total===null,je=k&&$e?c.include&&c.include!==this.description.include?Promise.resolve(null):this.aggregateRows(k,y,[],_).then((W)=>W[0]??null):Promise.resolve(s.totals);L=Promise.all([this.transport.find(S,_),$e?this.transport.count(y,_):Promise.resolve(s.total??0),je]).then(([W,ee,Pr])=>{if(t===this.seq)this.countKey=T;return[W,ee,Pr]})}return L.then(([S,T,$e])=>{if(t!==this.seq)return;this.controller=null;let je=this.get();this.baseRows=S,this.loadedOnce=!0,this.lastRead=Date.now();for(let W of this.gone)if(!this.baseRows.some((ee)=>this.keyOf(ee)===W)){let ee=this.writer.base(W);if(ee&&this.writer.all()[W])this.baseRows=[ee,...this.baseRows]}if(this.freshRead=!0,this.put({...je,rows:this.mergedRows(),total:T,pageCount:Oe(T,je.pageSize),status:"ready",error:null,totals:$e}),this.freshRead=!1,this.events.emit("load",{rows:this.get().rows,total:T}),this.settleWaiters(),this.description.cursor==="last"&&!this.cursorMoved)this.cursorMoved=!0,this.last()},(S)=>{if(t!==this.seq)return;this.controller=null,this.countKey=null;let T=E(S);this.put({...this.get(),status:"error",error:T}),this.events.emit("error",{error:T,during:"load"}),this.settleWaiters()}),z}aggregateRows(e,t,r,s){if(typeof this.transport.aggregate!=="function")return Promise.reject(new a("unsupported",`transport "${this.transport.name}" cannot aggregate`,{params:{feature:"aggregate"}}));let n={table:t.table,...t.where?{where:t.where}:{},...t.search?{search:t.search}:{},...e.group?{group:e.group,limit:Re}:{},...e.count?{count:!0}:{},...e.sum?{sum:e.sum}:{},...e.avg?{avg:e.avg}:{},...e.min?{min:e.min}:{},...e.max?{max:e.max}:{},...r.length?{order:r}:{}};return this.transport.aggregate(n,s)}lastBase=null;freshRead=!1;put(e,t=!1){let r=this.state.get(),s=this.cursorOf(e,r),n=s===e.current?e:{...e,current:s};if(t)this.state.replace(n);else this.state.set(n);if(n.rows!==r.rows)this.events.emit("change",{rows:n.rows});let i=(o)=>o.row===null?null:this.keyOf(o.row);if(n.current.index!==r.current.index||i(n.current)!==i(r.current))this.events.emit("current",{index:n.current.index,row:n.current.row})}cursorKey=null;cursorLocal=-1;cursorPage=1;cursorTarget=null;cursorActive=!1;cursorMoved=!1;cursorOf(e,t){let r=e.rows,s=-1;if(r.length>0){let h=this.cursorTarget;if(h&&this.freshRead&&e.page===h.page)s=h.local==="last"?r.length-1:Math.min(h.local,r.length-1),this.cursorTarget=null;else if(this.cursorKey!==null){let g=r.findIndex((y)=>this.keyOf(y)===this.cursorKey);if(g>=0)s=g;else if(e.page===this.cursorPage&&(e.status!=="loading"||r===t.rows)&&e.page===t.page)if(e.status==="loading")s=Math.min(this.cursorLocal,r.length-1);else{let y=(e.page-1)*e.pageSize,b=e.total!==null&&y+this.cursorLocal<e.total;if(this.cursorLocal>=r.length&&b&&!this.freshRead)this.cursorTarget={page:e.page,local:this.cursorLocal};s=Math.min(this.cursorLocal,r.length-1)}else s=0}else if(this.cursorTarget)s=-1;else s=this.description.cursor==="none"&&!this.cursorMoved?-1:0}if(e.status==="loading"&&r===t.rows&&t.current.row!==null&&this.cursorKey!==null&&s<0)return t.current;this.cursorLocal=s,this.cursorPage=e.page;let n=s>=0?r[s]:null;this.cursorKey=n===null?r.length===0?this.cursorKey:null:this.keyOf(n);let i=(e.page-1)*e.pageSize,o=s>=0?i+s:-1,l=e.page>=e.pageCount,u=s<=0&&(e.page<=1||s<0),c=r.length===0||s>=r.length-1&&(e.filtered||e.total===null?l:o>=e.total-1),f=this.cursorActive,d=t.current;if(d.index===o&&d.row===n&&d.bof===u&&d.eof===c&&d.active===f)return d;return{index:o,row:n,bof:u,eof:c,active:f}}setCursor(e){let t=this.get(),r=t.rows[e];if(r===void 0)return;this.cursorActive=!0,this.cursorMoved=!0,this.cursorTarget=null,this.cursorKey=this.keyOf(r),this.cursorLocal=e,this.cursorPage=t.page,this.put({...t})}async leaveCurrent(){let e=this.get().current.row;if(e===null)return!0;let t=this.keyOf(e),r=this.get().edits[t];if(!r?.dirty||r.saving||this.mode!=="batch")return!0;let s=await this.save(t);if(!s){let n=this.get().edits[t],i=n?.error??Object.values(n?.errors??{})[0]??null;if(i)this.events.emit("error",{error:i,during:"move"})}return s}async goTo(e,t){let r=this.get();if(this.cursorActive=!0,this.cursorMoved=!0,e===r.page&&r.status==="ready"&&!this.stale){let n=t==="last"?r.rows.length-1:t;if(n<0||n>=r.rows.length)return!1;return this.setCursor(n),!0}if(this.cursorTarget={page:e,local:t},e!==r.page)this.change({page:e});else this.stale=!0;await this.loadReady().catch(()=>{return});let s=this.get();if(this.cursorTarget&&s.page===e&&s.status==="ready"){let n=t==="last"?s.rows.length-1:Math.min(t,s.rows.length-1);if(this.cursorTarget=null,n>=0)this.setCursor(n)}return s.page===e&&s.current.row!==null}useCursor(){if(this.cursorActive)return;this.cursorActive=!0,this.put({...this.get()})}async first(){if(!await this.leaveCurrent())return!1;return this.goTo(1,0)}async last(){if(!await this.leaveCurrent())return!1;let e=this.get();if(e.total===null)e=await this.loadReady().catch(()=>this.get());if(e.total===null||e.total===0)return!1;return this.goTo(this.get().pageCount,"last")}async next(){if(!await this.leaveCurrent())return!1;for(let e=0;e<1000;e++){let t=this.get(),r=t.current.row===null?-1:this.cursorLocal;if(r+1<t.rows.length)return this.setCursor(r+1),!0;if(t.page>=t.pageCount)return!1;let s=await this.goTo(t.page+1,0);if(s||!this.get().filtered)return s}return!1}async prior(){if(!await this.leaveCurrent())return!1;for(let e=0;e<1000;e++){let t=this.get();if(t.current.row!==null&&this.cursorLocal>0)return this.setCursor(this.cursorLocal-1),!0;if(t.page<=1)return!1;let r=await this.goTo(t.page-1,"last");if(r||!this.get().filtered)return r}return!1}async moveTo(e){if(!Number.isInteger(e)||e<0)return!1;let t=this.get();if(t.total!==null&&e>=t.total)return!1;if(!await this.leaveCurrent())return!1;return this.goTo(Math.floor(e/t.pageSize)+1,e%t.pageSize)}async makeCurrent(e){let t=this.get(),r=this.keyOf(e);if(t.rows.findIndex((i)=>i===e||this.keyOf(i)===r)<0)return!1;if(t.current.row!==null&&this.keyOf(t.current.row)===r){if(this.cursorActive=!0,!t.current.active)this.put({...t});return!0}if(!await this.leaveCurrent())return!1;let n=this.get().rows.findIndex((i)=>this.keyOf(i)===r);if(n<0)return!1;return this.setCursor(n),!0}async locate(e){let t=Object.keys(e??{});if(t.length===0)return!1;let r=(m)=>t.every((k)=>Q(j(m,A(k)),e[k])),s=this.get();if(s.rows.findIndex(r)>=0){if(s.current.row!==null&&r(s.current.row))return!0;if(!await this.leaveCurrent())return!1;let m=this.get().rows.findIndex(r);if(m<0)return!1;return this.setCursor(m),!0}if(pe(this.transport)||this.description.aggregate?.group)return!1;if(this.stale||s.status!=="ready")await this.loadReady().catch(()=>{return});let i=this.lastBase;if(!i)return!1;let o={signal:new X.AbortController().signal},l=this.get().order.filter((m)=>!this.computed().has(m.column)),u=t.reduce((m,k)=>ne(m,{[k]:e[k]}),void 0),f=(await this.transport.find({...i,where:i.where?{and:[i.where,u]}:u,order:l,limit:1,offset:0},o).catch(()=>[]))[0];if(!f)return!1;let d=Ts(f,l,this.keyColumn),h=d===null?0:await this.transport.count({...i,where:i.where?{and:[i.where,d]}:d},o).catch(()=>-1);if(h<0)return!1;if(!await this.leaveCurrent())return!1;let g=this.get().pageSize;await this.goTo(Math.floor(h/g)+1,h%g);let y=this.get();if(y.current.row!==null&&r(y.current.row))return!0;let b=y.rows.findIndex(r);if(b>=0)return this.setCursor(b),!0;return!1}filterFn=null;computedCache=new WeakMap;computedRows=new WeakSet;computedFields=null;computed(){if(!this.computedFields){this.computedFields=new Map;for(let e of this.fields.declared())if(e.compute!==void 0)this.computedFields.set(e.field,e.compute)}return this.computedFields}pipeline(e){let t=this.computed(),r=e;if(t.size>0)r=e.map((n)=>{if(n===null||typeof n!=="object"||this.computedRows.has(n))return n;let i=this.computedCache.get(n);if(i)return i;let o={...n};for(let[u,c]of t)o[u]=_t(c,n);let l=this.draftIds.get(n);if(l)this.draftIds.set(o,l);return this.computedRows.add(o),this.computedCache.set(n,o),o});if(this.filterFn){let n=this.filterFn;r=r.filter((i)=>{try{return n(i)}catch{return!1}})}let s=this.get()?.order??[];if(t.size>0&&s.some((n)=>t.has(n.column)))r=Cs(r,s);return r===e&&e.length===0?e:r}filterBy(e){if(typeof e!=="function")throw new a("invalid_description","filterBy takes a function of the row",{path:"filterBy"});this.filterFn=e,this.put({...this.get(),rows:this.mergedRows(),filtered:!0})}clearFilterBy(){if(!this.filterFn)return;this.filterFn=null,this.put({...this.get(),rows:this.mergedRows(),filtered:!1})}on(e,t){return this.events.on(e,t)}setParams(e){let t=this.get(),r={...t.params,...e};if(Q(r,t.params))return;if(pe(this.transport))this.transport.setArgs({...this.transport.args()??{},...e});this.countKey=null,this.change({params:r,page:1})}resolveStore=null;stopDepends=[];linkStores(e){this.resolveStore=e}startDepends(){if(this.stopDepends.length>0||!this.resolveStore)return;for(let e of this.dependsList()){let t=this.resolveStore(e.store);if(!t)continue;let r=A(e.field),s=()=>{let l=t.type==="list"?t.get().current.row:t.get().value,u=l===null||l===void 0?null:j(l,r);return u===void 0?null:u},n=()=>{let l=s();if(Q(l,this.get().params[e.param]??null)&&e.param in this.get().params)return;this.cursorKey=null,this.cursorTarget=null,this.cursorMoved=!1,this.writer.revert(),this.setParams({[e.param]:l})},i=s(),o=this.get();if(!Q(i,o.params[e.param]??null)||!(e.param in o.params)){if(pe(this.transport))this.transport.setArgs({...this.transport.args()??{},[e.param]:i});this.put({...o,params:{...o.params,[e.param]:i}},!0),this.stale=!0,this.countKey=null}this.stopDepends.push(t.subscribe(n))}}stopDepending(){for(let e of this.stopDepends)e();this.stopDepends=[]}alive=null;keepAlive(){this.alive??=this.subscribe(()=>{})}redescribe(e){let t=pe(this.transport),r=new Set(["order","pageSize","search","cursor","dependsOn","autoLoad"]);if(t){for(let o of Object.keys(e))if(!r.has(o))throw new a("invalid_description",`"${o}" is not an option of a function store`,{path:o})}let s={...this.description,...e};for(let[o,l]of Object.entries(e))if(l===void 0)delete s[o];if(this.description=F(s),this.described){let o={...this.described,...e};for(let[l,u]of Object.entries(e))if(u===void 0)delete o[l];this.described=o}let n=this.get(),i={};if("order"in e)i.order=Ie(this.description.order);if("pageSize"in e&&this.description.pageSize)i.pageSize=this.description.pageSize;if("search"in e)i.searchColumns=this.description.search??[];if("params"in e)i.params={...this.description.params??{},...n.params,...e.params};if("cursor"in e)this.cursorActive=!0;if(this.countKey=null,this.change({...i,page:1}),"dependsOn"in e&&this.state.observed)this.stopDepending(),this.startDepends();if("autoLoad"in e&&this.description.autoLoad)Promise.resolve().then(()=>this.keepAlive());return this}select(e){let{select:t,include:r}=Lt(e);return this.redescribe({select:t,include:r})}where(e,t,r){return this.redescribe({where:ne(this.description.where,at(e,t,r))})}or(e){return this.redescribe({where:ne(this.description.where,G("or",U(e)))})}and(e){return this.redescribe({where:ne(this.description.where,G("and",U(e)))})}not(e){return this.redescribe({where:ne(this.description.where,{not:G("and",U(e))})})}order(e,t="asc"){return this.redescribe({order:Mt(this.description.order,It(e,t))})}pageSize(e){return this.redescribe({pageSize:e})}search(...e){return this.redescribe({search:e})}param(e,t){return this.redescribe({params:{...this.description.params??{},[e]:t}})}cursor(e){return this.redescribe({cursor:e})}dependsOn(e,t,r){let s=[...this.dependsList().filter((n)=>n.param!==r),{store:e,field:t,param:r}];return this.redescribe({dependsOn:s.length===1?s[0]:s})}dependsList(){let e=this.description.dependsOn;return e===void 0?[]:Array.isArray(e)?e:[e]}aggregatePatch(e,t){let r={...this.description.aggregate??{}};if(t===!0)r[e]=!0;else r[e]=[...new Set([...r[e]??[],...t])];if(!r.count&&!r.sum&&!r.avg&&!r.min&&!r.max)return this.pendingAggregate=r,this;return this.pendingAggregate=null,this.redescribe({aggregate:r})}pendingAggregate=null;groupBy(...e){let t=this.pendingAggregate??this.description.aggregate??{},r={...t,group:[...new Set([...t.group??[],...e])]};for(let[s,n]of e.entries())if(typeof n!=="string"||!/^[A-Za-z_][A-Za-z0-9_]{0,62}$/.test(n))throw new a("invalid_description",`invalid group column at ${s}`,{path:"aggregate.group"});if(!r.count&&!r.sum&&!r.avg&&!r.min&&!r.max)return this.pendingAggregate=r,this;return this.redescribe({aggregate:r})}count(){if(this.pendingAggregate)this.description={...this.description,aggregate:this.pendingAggregate};return this.aggregatePatch("count",!0)}sum(...e){if(this.pendingAggregate)this.description={...this.description,aggregate:this.pendingAggregate};return this.aggregatePatch("sum",e)}avg(...e){if(this.pendingAggregate)this.description={...this.description,aggregate:this.pendingAggregate};return this.aggregatePatch("avg",e)}min(...e){if(this.pendingAggregate)this.description={...this.description,aggregate:this.pendingAggregate};return this.aggregatePatch("min",e)}max(...e){if(this.pendingAggregate)this.description={...this.description,aggregate:this.pendingAggregate};return this.aggregatePatch("max",e)}pendingBatch(){let e=this.description.parent;if(e){let t=this.parentKey();for(let r of this.writer.inserted())if(r.row[e.column]===void 0||r.row[e.column]===null){if(t===null)return null;this.writer.set(r.id,null,e.column,t)}}return this.writer.batchPrepare((t)=>this.baseRows.find((r)=>this.keyOf(r)===t)??null)}batchStart(e){this.writer.batchStart(e)}batchDone(e,t){if(e.forEach((r,s)=>this.writer.batchDone(r,t[s]??[])),e.length)this.events.emit("saved",{ids:e})}async batchFailed(e,t,r){await Promise.all(e.map((s)=>this.writer.batchFailed(s,t,r===null||r===s))),this.events.emit("error",{error:t,during:"save"})}}var Rs=Object.freeze({index:-1,row:null,bof:!0,eof:!0,active:!1}),js=new Set(["where","order","search","page","pageSize","params"]);function Es(e,t,r){if(e==="*")return e;let s=[...e];if(!s.includes(t))s.unshift(t);if(r&&!s.includes(r))s.push(r);return s}function cr(e){let t=e.fields;if(!t||!t.some((i)=>typeof i==="object"&&i!==null&&typeof i.compute==="function"))return e;let r=t.filter((i)=>!(typeof i==="object"&&i!==null&&typeof i.compute==="function")),{fields:s,...n}=e;return r.length?{...n,fields:r}:n}function Cs(e,t){return[...e].sort((r,s)=>{for(let n of t){let i=r[n.column],o=s[n.column];if(Q(i,o))continue;if(i===null||i===void 0)return 1;if(o===null||o===void 0)return-1;let l=typeof i==="number"&&typeof o==="number"?i-o:String(i).localeCompare(String(o));if(l!==0)return n.direction==="asc"?l:-l}return 0})}function Ts(e,t,r){let s=t.some((o)=>o.column===r)?[...t]:[...t,{column:r,direction:"asc"}],n=(o,l)=>l===null||l===void 0?{[o]:{is:null}}:{[o]:{eq:l}},i=[];return s.forEach((o,l)=>{let u=e[o.column],c;if(u===null||u===void 0)c=o.direction==="asc"?{[o.column]:{not:null}}:null;else c=o.direction==="asc"?{[o.column]:{lt:u}}:{or:[{[o.column]:{gt:u}},{[o.column]:{is:null}}]};if(!c)return;let f=s.slice(0,l).map((d)=>n(d.column,e[d.column]));i.push(f.length?{and:[...f,c]}:c)}),i.length===0?null:i.length===1?i[0]:{or:i}}var Q=(e,t)=>JSON.stringify(e)===JSON.stringify(t),gt=(e,t)=>e===t||e.replace(/^public\./,"")===t.replace(/^public\./,""),fr=(e)=>new Set(e===void 0?[]:Array.isArray(e)?e:Object.entries(e).filter(([,t])=>t!==!1).map(([t])=>t));function xe(e,t,r){if(!r||!t)return e;let s=null;for(let n of fr(r))if(!(n in e)&&n in t)(s??={...e})[n]=t[n];return s??e}function Ps(e,t){let r=null,s=(n)=>Object.entries(n).every(([i,o])=>{if(i==="and"||i==="or")return o.every(s);if(i==="not")return s(o);let l=i.split(".")[0];if(!i.includes(".")||!t.has(l)||r!==null&&r!==l)return!1;return r=l,!0});return s(e)?r:null}function ht(e,t){let r={};for(let[s,n]of Object.entries(e))if(s==="and"||s==="or")r[s]=n.map((i)=>ht(i,t));else if(s==="not")r[s]=ht(n,t);else r[s.slice(t.length+1)]=n;return r}function Ds(e,t){let r=fr(t);if(!e||r.size===0)return{where:e,include:t};let s=e.and&&Object.keys(e).length===1?[...e.and]:[e],n=[],i=new Map;for(let l of s){let u=Ps(l,r);if(u)i.set(u,[...i.get(u)??[],ht(l,u)]);else n.push(l)}if(i.size===0)return{where:e,include:t};let o=Array.isArray(t)?Object.fromEntries(t.map((l)=>[l,!0])):{...t};for(let[l,u]of i){let c=o[l],f=typeof c==="object"?c:{},d=[...f.where?[f.where]:[],...u];o[l]={...f,where:d.length===1?d[0]:{and:d},required:!0}}return{where:n.length===0?void 0:n.length===1?n[0]:{and:n},include:o}}function pt(e,t){for(let[r,s]of Object.entries(e))if(r==="and"||r==="or")for(let n of s)pt(n,t);else if(r==="not")pt(s,t);else t.add(r)}function fe(e,t){return new ur(e,t)}var M=(e)=>typeof e==="object"&&e!==null&&e.kind==="store"&&e.type==="list"&&typeof e.subscribe==="function";var v="record";class dr{description;transport;kind="store";type="record";mode;fields;state;key_;seq=0;controller=null;stale=!0;waiters=[];original;loadStatus;loadError=null;writer;events=new ve;creating=!1;constructor(e,t){this.description=e,this.transport=t;let r="value"in e;if(!r&&!t)throw new a("invalid_description","a remote record needs a transport",{path:"transport"});if(!r&&t&&typeof t.findOne!=="function")throw new a("invalid_description",`transport "${t.name}" cannot read a single record (no findOne)`,{path:"transport"});this.mode=e.save??"batch",this.fields=new ke(e.fields),this.key_=r?null:e.key??null,this.original=r?e.value:null,this.loadStatus=r?"ready":"idle";let s=e,n=this.fields;if(this.writer=new ye({table:r?null:s.table,keyColumn:r?"id":s.keyColumn??"id",get version(){return r?null:s.version??n.versionColumn()??null},transport:r?null:t,mode:()=>this.mode,rule:(i)=>this.fields.rule(i),ruled:()=>this.fields.ruled(),changed:()=>this.publish(),insertedId:()=>v,stored:(i,o)=>{if(this.creating){let u=o[this.keyColumn];if(this.creating=!1,this.key_=typeof u==="number"||typeof u==="string"?u:null,this.original=o,this.loadStatus="ready",this.loadError=null,this.stale=!1,this.key_!==null)for(let c of this.children)c.adopt?.(this.key_);if(this.publish(),!r)this.emitWrite({event:"insert",table:s.table,record:o});return}let l=r?void 0:s.include;if(this.original=xe(o,this.original,l),l&&this.state?.observed)this.read(!0);if(this.publish(),!r)this.emitWrite({event:"update",table:s.table,record:o})},removed:()=>{let i=this.key_;if(this.original=null,this.publish(),!r)this.emitWrite({event:"delete",table:s.table,old:{[s.keyColumn??"id"]:i}})},incoming:(i,o)=>this.receiveRow(o),commitLocal:(i,o)=>{this.original=o}}),this.state=new V(this.compute(),{start:()=>this.start(),stop:()=>this.stop()}),!r&&s.autoLoad)Promise.resolve().then(()=>this.alive??=this.subscribe(()=>{}))}alive=null;on(e,t){return this.events.on(e,t)}resolveStore=null;stopDepends=[];linkStores(e){this.resolveStore=e}deps(){let e=this.local?void 0:this.description.dependsOn;return e===void 0?[]:Array.isArray(e)?e:[e]}startDepends(){if(this.stopDepends.length>0||!this.resolveStore)return;for(let e of this.deps()){let t=this.resolveStore(e.store);if(!t)continue;let r=e.field.split("."),s=()=>{let i=t.type==="list"?t.get().current.row:t.get().value,o=i===null||i===void 0?null:j(i,r);return typeof o==="string"&&o.length>0?o:typeof o==="number"&&Number.isFinite(o)?o:null},n=s();if(n!==this.key_)this.key_=n,this.writer.revert(),this.stale=!0;this.stopDepends.push(t.subscribe(()=>{let i=s();if(i!==this.key_)this.setKey(i)}))}}pendingBatch(){return this.writer.batchPrepare(()=>this.original)}batchStart(e){this.writer.batchStart(e)}batchDone(e,t){if(e.forEach((r,s)=>this.writer.batchDone(r,t[s]??[])),e.length)this.events.emit("saved",{ids:e})}async batchFailed(e,t,r){await Promise.all(e.map((s)=>this.writer.batchFailed(s,t,r===null||r===s))),this.events.emit("error",{error:t,during:"save"})}get keyColumn(){return this.local?"id":this.description.keyColumn??"id"}key(){return this.key_}children=new Set;linkChild(e){return this.children.add(e),this.publish(),()=>{this.children.delete(e),this.publish()}}childChanged(){this.publish()}get local(){return"value"in this.description}get(){return this.state.get()}subscribe(e){return this.state.subscribe(e)}toJSON(){throw new a("not_serializable","a data store cannot be serialised: pass its JSON description instead")}compute(){let e=this.writer.state(v),t=this.original===null?null:this.writer.merge(v,this.original),{dirty:r,saving:s}=e;for(let n of this.children??[])r||=n.dirty(),s||=n.saving();return{value:t,original:this.original,status:this.loadStatus,error:this.loadError,edit:e,dirty:r,saving:s,realtime:this.realtimeStatus}}publish(){let e=this.compute(),t=this.state.get();if(t.value===e.value&&t.original===e.original&&t.status===e.status&&t.error===e.error&&t.edit===e.edit&&t.realtime===e.realtime&&t.dirty===e.dirty&&t.saving===e.saving)return;if(this.state.set(e),e.value!==t.value)this.events.emit("change",{rows:e.value===null?[]:[e.value]})}writeListeners=new Set;onWrite(e){return this.writeListeners.add(e),()=>void this.writeListeners.delete(e)}emitWrite(e){for(let t of[...this.writeListeners])t(e)}realtimeStatus="off";stopRealtime=null;loadedOnce=!1;receive(e){if(this.local||this.key_===null)return;let t=this.description;if(!gt(e.table,t.table))return;let s=(e.event==="delete"?e.old:e.record)?.[t.keyColumn??"id"];if(s===void 0||String(s)!==String(this.key_))return;this.receiveRow(e.event==="delete"?null:e.record)}receiveRow(e){let t=this.writer.incoming(v,e);if(t==="deferred"||t==="stale")return;if(e===null){if(t==="handled")return;this.original=null,this.loadStatus="error",this.loadError=new a("not_found","the record was deleted",{status:404}),this.publish();return}if(t==="none"&&!ge(e,this.original,this.writer.versionColumn))return;let r=this.local?void 0:this.description.include;if(this.original=xe(e,this.original,r),r&&this.state.observed)this.read(!0);this.loadStatus="ready",this.loadError=null,this.publish()}startRealtime(e){let t=this.transport;if(this.local||this.stopRealtime||this.description.realtime===!1||!t||typeof t.subscribe!=="function")return;let r=e;this.setRealtime("connecting",r),this.stopRealtime=t.subscribe({table:this.description.table},{change:(s)=>this.receive(s),status:(s)=>{let n=this.realtimeStatus;if(this.setRealtime(s,r),s==="live"&&n!=="live"&&this.loadedOnce&&this.state.observed)this.read(!0)}}),r=!1}setRealtime(e,t=!1){if(this.realtimeStatus===e)return;if(this.realtimeStatus=e,!this.state)return;if(t)this.state.replace(this.compute());else this.publish()}isNew(){return this.creating}create(e={}){if(this.local)throw new a("invalid_description","a local record is changed with set(), not created",{path:"value"});if(this.transport&&pe(this.transport))throw new a("read_only","a function result cannot be created");this.cancel(),this.writer.revert();for(let t of this.children)t.revert();this.key_=null,this.creating=!0,this.original={},this.loadStatus="ready",this.loadError=null,this.stale=!1,this.writer.insertAs(v,{...e}),this.publish()}setKey(e){if(this.local)throw new a("invalid_description","a local record has no key",{path:"key"});if(e!==null&&!(typeof e==="string"&&e.length>0)&&!(typeof e==="number"&&Number.isFinite(e)))throw new a("invalid_description","key must be a non-empty string or a number",{path:"key"});if(e===this.key_&&!this.creating)return;this.creating=!1,this.key_=e,this.writer.revert();for(let t of this.children)t.revert();if(this.stale=!0,this.state.observed)this.read()}load(e){if(e!==void 0&&this.transport){if(pe(this.transport)){if(this.transport.setArgs(e),this.stale=!0,this.state.observed)this.read()}else if(e&&typeof e==="object"&&"key"in e)this.setKey(e.key)}return this.loadReady()}sync(e){return this.load(e)}described=null;describeAs(e){this.described=e}toDescription(){if(this.described)return this.described;let e=this.description;if("value"in e)return{name:"",source:"data",data:e.value};let{table:t,type:r,...s}=e;return{name:"",source:"table",table:t,...s}}async loadReady(){let e=!1;for(let r=0;!this.local&&this.key_!==null&&r<8;r++)if(this.controller)await new Promise((s)=>this.waiters.push(s));else if(!e&&(this.stale||this.loadStatus==="idle"||this.loadStatus==="error"))e=!0,await this.read();else break;let t=this.get();if(t.status==="error"&&t.error)throw t.error;return t}refresh(){if(this.local||!this.state.observed)return this.stale=!0,Promise.resolve();return this.read()}set(e,t){let r=this.fields.path(e);if(r.length===0)throw new a("read_only","a record is changed field by field: give a path",{path:"field"});let s=this.get().value;if(s===null||typeof s!=="object")throw new a("read_only","nothing to change: the record is not loaded",{path:"field"});if(Array.isArray(s)){this.original=Z(s,r,t),this.publish();return}let n=String(r[0]),i=r.length===1?t:j(Z(s,r,t),[r[0]]);this.writer.set(v,this.original,n,i)}async save(){let e=this.writer.state(v);if(e.dirty&&this.events.has("beforesave")){let r=this.events.before("beforesave",{changes:[{id:v,kind:e.kind,values:e.changes}]});if(r===!1)return!1;for(let[s,n]of Object.entries(r))this.set(s,n)}let t=await this.saveAll();if(t&&e.dirty)this.events.emit("saved",{ids:[v]});if(!t){let r=this.writer.state(v),s=r.error??Object.values(r.errors)[0]??null;if(s)this.events.emit("error",{error:s,during:"save"})}return t}async saveAll(){if(this.creating){let r=this.writer.validate(v,null,!0),s=[...this.children].map((n)=>n.valid?.()??!0);if(!r||s.includes(!1))return!1}if(!await this.writer.save(v,()=>this.original,!0))return!1;return(await Promise.all([...this.children].filter((r)=>r.dirty()).map((r)=>r.save()))).every(Boolean)}revert(e){if(e===void 0){this.writer.revert(v);for(let t of this.children)t.revert();if(this.creating)this.writer.insertAs(v,{})}else this.writer.revert(v,String(this.fields.path(e)[0]))}resolve(e,t){this.writer.resolve(v,e===null?null:String(this.fields.path(e)[0]),t)}dismiss(){this.writer.dismiss(v)}start(){this.startDepends();let e=!this.local&&(this.stale||this.loadStatus==="idle");if(this.startRealtime(e&&this.key_!==null),e)this.read()}stop(){for(let e of this.stopDepends)e();if(this.stopDepends=[],this.cancel(),this.stale=!0,this.stopRealtime?.(),this.stopRealtime=null,this.loadedOnce=!1,this.setRealtime("off"),this.loadStatus==="loading")this.loadStatus=this.original===null?"idle":"ready",this.publish()}cancel(){this.seq++,this.controller?.abort(),this.controller=null;let e=this.waiters;this.waiters=[];for(let t of e)t()}read(e=!1){this.cancel(),this.stale=!1;let t=this.description;if(this.key_===null){if(this.creating)return Promise.resolve();return this.original=null,this.loadStatus="idle",this.loadError=null,this.publish(),Promise.resolve()}let r=this.seq,s=new X.AbortController;this.controller=s;let n={table:t.table,where:{[t.keyColumn??"id"]:this.key_},...t.select?{select:t.select}:{},...t.include?{include:t.include}:{}};if(!e)this.loadStatus="loading",this.loadError=null,this.publish();let i=new Promise((l)=>this.waiters.push(l)),o=(l,u)=>{if(r!==this.seq)return;if(this.controller=null,u)this.loadStatus="error",this.loadError=u,this.events.emit("error",{error:u,during:"load"});else{if(!R(l,this.original))this.original=l;if(this.loadedOnce=!0,l&&this.writer.state(v)!==te)this.writer.incoming(v,l);this.loadStatus=l===null?"error":"ready",this.loadError=l===null?new a("not_found",`no visible row in "${t.table}" for this key`,{status:404}):null}if(this.publish(),!u&&l!==null)this.events.emit("load",{rows:[l],total:1});let c=this.waiters;this.waiters=[];for(let f of c)f()};if(this.events.has("beforeload")&&this.events.before("beforeload",{params:{key:this.key_}})===!1){if(this.controller=null,!e)this.loadStatus=this.original===null?"idle":"ready",this.publish();let l=this.waiters;this.waiters=[];for(let u of l)u();return i}return this.transport.findOne(n,{signal:s.signal}).then((l)=>o(l??null,null),(l)=>o(null,E(l))),i}}function ae(e,t){return new dr(we(e),t??null)}var Ce=(e)=>typeof e==="object"&&e!==null&&e.kind==="store"&&e.type==="record";var tt=(e)=>e.replace(/[\\%_]/g,(t)=>`\\${t}`);function mt(e){let t=[];if(e.where&&Object.keys(e.where).length>0)t.push(e.where);if(e.search&&e.search.term&&e.search.columns.length>0){let r=`%${tt(e.search.term)}%`,s=e.search.columns.map((n)=>({[n]:{ilike:r}}));t.push(s.length===1?s[0]:{or:s})}if(t.length===0)return;return t.length===1?t[0]:{and:t}}function Ns(e){let t=mt(e);return{...e.select?{select:e.select}:{},...t?{where:t}:{},...e.include?{include:e.include}:{},...e.order.length>0?{order:e.order.map((r)=>[r.column,r.direction])}:{},limit:e.limit,offset:e.offset}}function zs(e){return{where:e.where,...e.select?{select:e.select}:{},...e.include?{include:e.include}:{}}}function Ls(e){let t=mt(e);return{...t?{where:t}:{},...e.group?{group:e.group}:{},...e.count?{count:!0}:{},...e.sum?{sum:e.sum}:{},...e.avg?{avg:e.avg}:{},...e.min?{min:e.min}:{},...e.max?{max:e.max}:{},...e.order&&e.order.length>0?{order:e.order.map((r)=>[r.column,r.direction])}:{},...e.limit!==void 0?{limit:e.limit}:{}}}var Be=(e,t)=>new a("unsupported",`the poad data service does not know ${e}: update poad`,{params:{feature:e},status:404,cause:t});function Is(e){let t=mt(e);return{...t?{where:t}:{},...e.include?{include:e.include}:{}}}async function B(e){let{data:t,error:r}=await e;if(r)throw E(r);return t}var q=(e,t,r)=>e.abortable===!0&&r?.signal?{...t,signal:r.signal}:t;function hr(e,t={}){if(!e||typeof e.from!=="function")throw TypeError("poadTransport: expected a data-js or client-js client (with from())");let r=Ms(e,t);if(r.subscribe&&t.followAuth!==!1)Fs(e,r.reconnect);return{subscribe:r.subscribe,reconnectRealtime:r.reconnect,name:"poad",async find(s,n){let i=e.from(s.table);return await B(i.find(q(i,Ns(s),n)))??[]},async count(s,n){let i=e.from(s.table);return await B(i.count(q(i,Is(s),n)))??0},async findOne(s,n){let i=e.from(s.table);return await B(i.findOne(q(i,zs(s),n)))??null},async insert(s,n){let i=e.from(s.table);if(!i.create)throw Ae("create");let l=(await B(i.create({...s.values},q(i,{returning:!0},n))))?.[0];if(!l)throw E({status:403,code:"forbidden",message:"the created row is not visible (returning)"});return l},async update(s,n){let i=e.from(s.table);if(!i.update)throw Ae("update");return await B(i.update(q(i,{where:s.where,set:{...s.set},returning:!0},n)))??[]},async call(s,n){if(s.kind==="pgfn"){if(typeof e.rpc!=="function")throw Ae("rpc");return await B(e.rpc(s.name,s.args))}if(t.invoke)return await B(t.invoke(s.name,s.args,n?.signal));if(typeof e.fn!=="function")throw Ae("fn");return await B(e.fn(s.name,s.args,n?.signal?{signal:n.signal}:{}))},async remove(s,n){let i=e.from(s.table);if(!i.destroy)throw Ae("destroy");return await B(i.destroy(q(i,{where:s.where,returning:!0},n)))??[]},async aggregate(s,n){let i=e.from(s.table);if(typeof i.aggregate!=="function")throw Be("aggregate",null);let{data:o,error:l}=await i.aggregate(q(i,Ls(s),n));if(l){let u=E(l);if(u.status===404&&/opération inconnue|unknown operation|aucune ligne/i.test(u.message))throw Be("aggregate",l);throw u}return o??[]},async batch(s,n){let i=typeof e.call==="function"?e.call.bind(e):typeof e.data?.call==="function"?e.data.call.bind(e.data):void 0;if(!i)throw Be("batch",null);let o={operations:s.map((f)=>({...f,returning:!0}))},{data:l,error:u}=await i("POST","/_batch",o,n?.signal?{signal:n.signal}:{});if(u){let f=E(u);if(/table inconnue : _batch|unknown table:? _batch/i.test(f.message)||f.status===404&&!/_batch :/.test(f.message))throw Be("batch",u);let d=String(u.hint??""),h=/index=(\d+)/.exec(`${d} ${f.message}`)?.[1];throw Object.assign(f,h!==void 0?{batchIndex:Number(h)}:{})}let c=l?.results;if(!Array.isArray(c))throw new a("server","the batch answer has no results");return c.map((f)=>Array.isArray(f)?f:[])}}}function Ms(e,t){let r=t.realtime,s=null,n=()=>{if(r===!1)return null;if(!s)s=typeof r==="function"?r():r??e.realtime??null;return s},i=new Map,o=0,l=(f,d,h)=>{if(f.status=d,h!==void 0)f.error=h;for(let g of[...f.subs])g.status(d,h)},u=(f,d)=>{let h=n();if(!h)return;let[g,y]=f.includes(".")?f.split(".",2):[void 0,f];d.closed=!1;let b=h.channel(`poad-data:${f}:${++o}`);b.on("change",{table:y,...g?{schema:g}:{}},(m)=>{if(d.closed)return;let k={event:m.event,table:f,...m.record!==void 0?{record:m.record}:{},...m.old_record!==void 0?{old:m.old_record}:{}};for(let _ of[...d.subs])_.change(k)}),d.channel=b,b.subscribe((m,k)=>{if(d.closed||d.channel!==b)return;l(d,m==="SUBSCRIBED"?"live":m==="ERROR"?"error":"reconnecting",k)})},c=(f)=>{f.closed=!0;let d=f.channel;f.channel=null,d?.unsubscribe()};return{subscribe:n()===null?void 0:(f,d)=>{let h=i.get(f.table);if(!h)h={channel:null,subs:new Set,status:"connecting",closed:!1},i.set(f.table,h),h.subs.add(d),d.status("connecting"),u(f.table,h);else h.subs.add(d),d.status(h.status,h.error);let g=h,y=!0;return()=>{if(!y)return;if(y=!1,g.subs.delete(d),g.subs.size===0&&i.get(f.table)===g)i.delete(f.table),c(g)}},reconnect(){if(i.size===0)return;for(let f of i.values())c(f);if(s?.disconnect?.(),typeof r==="function")s=null;for(let[f,d]of i)l(d,"reconnecting"),u(f,d)}}}function Fs(e,t){let r=e.auth;if(!r||typeof r.onChange!=="function")return;let s=void 0;r.onChange((n,i)=>{let o=i?.user?.id??null,l=s===void 0,u=s;if(s=o,l?n==="INITIAL_SESSION":o===u)return;t()})}var Ae=(e)=>E({status:400,code:"invalid_request",message:`this client has no ${e}() (data-js >= 0.3.0)`});var yt=(e)=>(typeof e==="object"||typeof e==="function")&&e!==null;function We(e){return yt(e)&&typeof e.find==="function"&&typeof e.count==="function"}function Ks(e){return yt(e)&&typeof e.from==="function"&&!We(e)}var Bs=(e)=>e===null?"null":Array.isArray(e)?"an array":yt(e)?`an object without from() nor find()/count() (keys: ${Object.keys(e).slice(0,6).join(", ")||"none"})`:typeof e;function le(e,t="store.connect"){if(We(e))return e;if(Ks(e))return hr(e);throw new a("invalid_transport",`${t}: expected a poad client (createClient from @poadio/client-js, or a DataClient from @poadio/data-js) or a DataTransport, got ${Bs(e)}`,{path:"transport"})}function Ze(e,t){let r=e.client!==void 0&&e.client!==null,s=e.transport!==void 0&&e.transport!==null;if(r&&s)throw new a("invalid_transport",`${t}: pass either { client } or { transport }, not both`,{path:"transport"});if(r)return le(e.client,`${t}({ client })`);if(s)return le(e.transport,`${t}({ transport })`);return}async function Je(e){let t=[...new Set(e)],r=[],s=[],n=[],i=!0,o=null;for(let u of t){if(!u.transport||u.transport.name==="memory"||pe(u.transport)){if(u.transport===null||u.transport.name==="memory")n.push(u);continue}let c=u.pendingBatch();if(c===null){i=!1;continue}if(c.operations.length===0)continue;if(o&&o!==u.transport)throw new a("invalid_transport","sync: all the stores of a batch use the same poad project (one transport)");o??=u.transport,r.push({store:u,ids:c.ids,from:s.length,to:s.length+c.operations.length}),s.push(...c.operations)}if(!i)return!1;if(s.length>0){let u=o;if(typeof u.batch!=="function")throw new a("unsupported",`transport "${u.name}" cannot write a batch in one transaction`,{params:{feature:"batch"}});for(let f of r)f.store.batchStart(f.ids);let c;try{c=await u.batch(s,{signal:new X.AbortController().signal})}catch(f){let d=E(f),h=typeof f?.batchIndex==="number"?f.batchIndex:null;if(await Promise.all(r.map((g)=>{let y=h!==null&&h>=g.from&&h<g.to?g.ids[h-g.from]:h===null?null:"\x00";return g.store.batchFailed(g.ids,d,y)})),d.code==="unsupported")throw d;return!1}for(let f of r)f.store.batchDone(f.ids,c.slice(f.from,f.to))}return(await Promise.all(n.map((u)=>u.type==="list"?u.save():u.save()))).every(Boolean)}var bt=1,Ws=new Set(["version","store","field","fields","fieldsOnly"]),Zs=/^[A-Za-z_][A-Za-z0-9_-]{0,63}$/,Js=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e)&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null);function ue(e,t="store"){if(typeof e!=="string"||!Zs.test(e))throw new a("invalid_binding",`invalid store name at ${t}: expected a letter then letters, digits, "_" or "-" (64 at most)`,{path:t});return e}function nt(e,t={}){if(!Js(e))throw new a("invalid_binding",'invalid binding: expected { "store": "…", "field"?: "…" }',{path:"$"});for(let o of Object.keys(e))if(!Ws.has(o))throw new a("invalid_binding",`invalid binding at ${o}: unknown key`,{path:o});if(e.version!==void 0&&e.version!==bt)throw new a("invalid_binding",`invalid binding at version: this engine reads version ${bt}`,{path:"version"});let r=ue(e.store);if(e.field!==void 0&&typeof e.field!=="string")throw new a("invalid_binding","invalid binding at field: expected a path",{path:"field"});let s=J(A(e.field)),n={version:bt,store:r,field:s,...e.fields!==void 0?{fields:he(e.fields,t.meta?{meta:t.meta}:{})}:{},fieldsOnly:!1},i=n.fields?.findIndex((o)=>o.compute!==void 0)??-1;if(i>=0)throw new a("invalid_binding",`invalid binding at fields[${i}].compute: a computed field is declared in the store's fields`,{path:`fields[${i}].compute`});if(e.fieldsOnly!==void 0){if(typeof e.fieldsOnly!=="boolean")throw new a("invalid_binding","invalid binding at fieldsOnly: expected true or false",{path:"fieldsOnly"});if(e.fieldsOnly&&n.fields===void 0)throw new a("invalid_binding",'invalid binding at fieldsOnly: needs "fields"',{path:"fieldsOnly"});n.fieldsOnly=e.fieldsOnly}return wt.add(n),n}var wt=new WeakSet,gr=(e)=>typeof e==="object"&&e!==null&&wt.has(e)?e:nt(e),pr=(e)=>("table"in e.description)?e.description.table:null;function mr(e={}){let t=new Map,r=e.client!==void 0&&e.client!==null?Ze(e,"createStoreRegistry"):void 0,s=null,n=()=>{if(r)return r;let c=e.transport;if(c===void 0||c===null)return;if(We(c))return c;if(s?.from!==c)s={from:c,to:le(c,"createStoreRegistry({ transport })")};return s.to},i=(c)=>t.get(c)?.store??null,o=(c)=>{let f=l(c);if(typeof f.store.linkStores==="function")f.store.linkStores(i);return f},l=(c)=>{if(M(c)||Ce(c)){let b=M(c)?c.description.parent:void 0;if(b&&M(c)&&c.parentKey()===null)c.linkParent(()=>{let m=t.get(b.store)?.store??null;return m&&Ce(m)?m:null});return{store:c,key:c}}let f=ft(c),d=JSON.stringify(f);if(f.type==="record"){let b="value"in f,m=n();if(!b&&!m)throw new a("invalid_description","a remote record needs a transport: createStoreRegistry({ client })",{path:"transport"});return{store:ae(f,m??null),key:d}}let h=n();if(!h)throw new a("invalid_description","a list description needs a transport: createStoreRegistry({ client })",{path:"transport"});let g=fe(h,f),y=f.parent;if(y)g.linkParent(()=>{let b=t.get(y.store)?.store??null;return b&&Ce(b)?b:null});return{store:g,key:d}},u={define(c,f){ue(c,"name");let d=t.get(c),h;if(d){if(!(d.source===f||typeof d.source==="string"&&!M(f)&&!Ce(f)&&d.source===JSON.stringify(ft(f))))throw new a("duplicate_store",`a different store is already named "${c}"`,{params:{name:c},path:c});d.refs++,h=d}else{let{store:y,key:b}=o(f);h={store:y,source:b,refs:1},t.set(c,h);let m=h;m.stopWrite=typeof y.onWrite==="function"?y.onWrite((k)=>{let _=pr(y);if(!_)return;for(let z of new Set([...t.values()].map((L)=>L.store))){if(z===y||pr(z)!==_)continue;if(typeof z.receive==="function")z.receive(k);else z.refresh()}}):void 0}let g=!1;return{name:c,store:h.store,release(){if(g)return;if(g=!0,--h.refs===0&&t.get(c)===h)t.delete(c),h.stopWrite?.()}}},get(c){let f=t.get(c);if(!f)throw new a("unknown_store",`no store named "${c}"`,{params:{name:c},path:c});return f.store},has:(c)=>t.has(c),names:()=>[...t.keys()],saveAll:()=>Je([...new Set([...t.values()].map((c)=>c.store))]),field(c){let f=typeof c==="object"&&c!==null&&wt.has(c)?c:nt(c);return kt(u.get(f.store),f.field)}};return u}var Vs=new a("invalid_binding","invalid binding: give either data (JSON) or store (and field), not both",{path:"store"}),Ys=new a("invalid_binding",'invalid binding at field: a field needs a store (store="…" or [store]="…")',{path:"field"}),Us=new a("invalid_binding",'invalid binding at fields: fields need a store (store="…" or [store]="…")',{path:"fields"}),Gs=new a("invalid_binding","invalid binding at fields: expected an array of fields",{path:"fields"}),yr=new a("invalid_binding","invalid binding at store: expected a store object or the name of a store of the registry",{path:"store"}),br=new WeakMap,wr=new Map,kr=new WeakMap,Ne=(e)=>typeof e==="object"&&e!==null&&e.kind==="store-binding";function rt(e,t){if(Ne(e))return{binding:nt({store:"_",...e.field?{field:e.field}:{},fields:e.fields}),store:e.store};let r=gr(e);if(!t)throw new a("invalid_binding","a JSON binding needs a store registry (provide one with your framework adapter)",{path:"store"});return{binding:r,store:t.get(r.store)}}function x(e,t,r,s){let n=t!==null&&t!==void 0&&t!=="",i=r!==null&&r!==void 0&&r!=="",o=s!==null&&s!==void 0;if(!n&&!i&&!o)return e??null;if(e!==null&&e!==void 0)return Vs;if(!n)return i?Ys:Us;if(o){if(typeof s!=="object")return Gs;if(typeof t!=="string"&&!M(t)&&!Ce(t))return yr;let l=kr.get(s);if(!l)kr.set(s,l=new Map);let u=l.get(t);if(!u)l.set(t,u=new Map);let c=i?r:"",f=u.get(c);if(f===void 0)f=typeof t==="string"?{store:t,...i?{field:r}:{},fields:s}:Object.freeze({kind:"store-binding",store:t,field:c,fields:s}),u.set(c,f);return f}if(typeof t==="string"){let l=`${t}\x00${i?r:""}`,u=wr.get(l);if(!u)wr.set(l,u=i?{store:t,field:r}:{store:t});return u}if(M(t)&&!i)return t;if(M(t)||Ce(t)){let l=br.get(t);if(!l)br.set(t,l=new Map);let u=i?r:"",c=l.get(u);if(!c)l.set(u,c=kt(t,u));return c}return yr}var Sr=["select","where","order","pageSize","include","search","keyColumn","version","fields","save","realtime","reference","parent","key","cursor","params","dependsOn","autoLoad","aggregate"],Xs=new Set(["key","keyColumn","select","include","version","fields","save","realtime","dependsOn","autoLoad"]),vr=["args","result","server","order","pageSize","search","fields","keyColumn","cursor","dependsOn","autoLoad"],Hs=/^[A-Za-z0-9_-]{1,63}$/,Qs=/^[A-Za-z_][A-Za-z0-9_]{0,62}$/,Or={data:[],table:Sr,view:[...Sr,"readOnly"],pgfn:vr,fn:vr},xr=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e),P=(e,t)=>{throw new a("invalid_description",`invalid store at ${e}: ${t}`,{path:e})};function Ar(e){if(!xr(e))return P("$",'expected { "name": …, "source": "data" | "table" | "view" | "pgfn" | "fn", … }');let{name:t,source:r,...s}=e;if(ue(t,"name"),typeof r!=="string"||!(r in Or))return P("source",'expected "data", "table", "view", "pgfn" or "fn"');let n=r;if(!(n in s))P(n,`expected the ${n==="data"?"data (an object or an array)":`${n} name`}`);let{[n]:i,...o}=s,l=new Set(Or[n]);for(let g of Object.keys(o))if(!l.has(g))P(g,`unknown key for a "${n}" store`);if(n==="data"){if(!xr(i)&&!Array.isArray(i))P("data","expected an object (a record) or an array (rows)");return e}if(n==="table"||n==="view"){if(typeof i!=="string")return P(n,`expected the ${n} name`);let g=o;if(g.readOnly!==void 0&&typeof g.readOnly!=="boolean")P("readOnly","expected true or false");let{readOnly:y,key:b,...m}=g;if(b!==void 0){for(let k of Object.keys(g))if(k!=="readOnly"&&!Xs.has(k))P(k,"not an option of a single record (key)");we({type:"record",table:i,...b!==null?{key:b}:{},...m})}else F({table:i,...m});return e}if(typeof i!=="string"||!(n==="pgfn"?Qs:Hs).test(i))return P(n,"expected a function name");let u=o;if(u.result!==void 0&&u.result!=="rows"&&u.result!=="record")P("result",'expected "rows" or "record"');if(u.server!==void 0&&typeof u.server!=="boolean")P("server","expected true or false");if(u.args!==void 0)try{JSON.stringify(u.args)}catch{P("args","expected JSON")}let{args:c,result:f,server:d,...h}=u;return F({table:"__fn",...h}),e}var qs=new Set(["data","table","view","pgfn","fn"]),en=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e),_e=(e,t)=>{throw new a("invalid_description",`invalid store at ${e}: ${t}`,{path:e})},tn=(e,t)=>`__${e}_${t.replace(/[^A-Za-z0-9_]/g,"_")}`.slice(0,63),sn=["keyColumn","select","include","version","fields","save","realtime","dependsOn","autoLoad"];function nn(e){return{name:`${e.name}:read-only`,find:(t,r)=>e.find(t,r),count:(t,r)=>e.count(t,r),...e.findOne?{findOne:(t,r)=>e.findOne(t,r)}:{},...e.aggregate?{aggregate:(t,r)=>e.aggregate(t,r)}:{},...e.subscribe?{subscribe:(t,r)=>e.subscribe(t,r)}:{}}}function an(e={}){let t=Ze(e,"createStore")??null,r=mr({get transport(){return t??void 0}}),s=(c)=>t??_e("transport",`${c} needs a transport: store.connect(client) first`),n=new WeakMap,i=(c,f,d)=>{if(ue(c,"name"),r.has(c)){let g=r.get(c);if(n.get(g)===JSON.stringify(f)||typeof g.toDescription==="function"&&JSON.stringify(g.toDescription())===JSON.stringify(f))return g}let h=d();return n.set(h,JSON.stringify(f)),h.describeAs(f),r.define(c,h),h},o=(c,f,d,h={})=>{let g={name:c,source:f,[f]:d,...h};return i(c,g,()=>{let y=s(f),b=f==="view"&&h.readOnly?nn(y):y,{key:m,readOnly:k,..._}=h;if(m!==void 0){let z={type:"record",table:d,...m!==null?{key:m}:{}};for(let L of sn)if(_[L]!==void 0)z[L]=_[L];return ae(z,b)}return fe(b,{table:d,..._})})},l=(c,f,d,h={})=>{let g={name:c,source:f,[f]:d,...h};return i(c,g,()=>{let y=ir(s(f),f,d,h),b=tn(f,d);if(h.result==="record")return ae({type:"record",table:b,key:"*",keyColumn:h.keyColumn??"__fn",realtime:!1,...h.fields?{fields:h.fields}:{}},y);return fe(y,{table:b,realtime:!1,...h.order?{order:h.order}:{},...h.pageSize?{pageSize:h.pageSize}:{},...h.search?{search:h.search}:{},...h.fields?{fields:h.fields}:{},...h.keyColumn?{keyColumn:h.keyColumn}:{},...h.cursor?{cursor:h.cursor}:{},...h.dependsOn?{dependsOn:h.dependsOn}:{},...h.autoLoad?{autoLoad:h.autoLoad}:{}})})},u={registry:r,get transport(){return t},connect(c){return t=le(c,"store.connect"),u},define(c,f){if(Array.isArray(f))return i(c,{name:c,source:"data",data:f},()=>fe(nr(f),{table:`__data_${c.replace(/[^A-Za-z0-9_]/g,"_")}`.slice(0,63),pageSize:Math.min(Math.max(f.length,20),1000)}));if(!en(f))return _e("data","define takes local data: an object (a record) or an array (rows)");return i(c,{name:c,source:"data",data:f},()=>ae({type:"record",value:f}))},table:(c,f,d)=>o(c,"table",f,d),view:(c,f,d)=>o(c,"view",f,d),pgfn:(c,f,d)=>l(c,"pgfn",f,d),fn:(c,f,d)=>l(c,"fn",f,d),fromJSON(c){Ar(c);let{name:f,source:d,...h}=c;if(typeof f!=="string")return _e("name","expected a store name");if(typeof d!=="string"||!qs.has(d))return _e("source",'expected "data", "table", "view", "pgfn" or "fn"');let g=h[d],{[d]:y,...b}=h;if(d==="data")return u.define(f,g);if(typeof g!=="string")return _e(d,`expected the ${d} name`);if(d==="table"||d==="view")return o(f,d,g,b);return l(f,d,g,b)},get:(c)=>r.get(c),has:(c)=>r.has(c),names:()=>r.names(),field:(c)=>r.field(c),sync:(c)=>Je(c.map((f)=>typeof f==="string"?r.get(f):f)),saveAll:()=>r.saveAll()};return u}var ln=an();function ot(){return typeof globalThis.document<"u"?ln.registry:null}var _r=/^[A-Za-z_][A-Za-z0-9_]{0,62}$/,Ve=Object.freeze([]),$r=20,St=(e,t)=>{let r=e;for(let s of t.split(".")){if(r===null||typeof r!=="object")return;r=r[s]}return r},Rr=(e)=>e===null||e===void 0?"":typeof e==="object"?JSON.stringify(e):String(e);function cn(e,t){let r=t.fields??(e.description.fields?he(e.description.fields):[]),s=N(r,"key")[0]?.field??e.keyColumn,n=N(r,"label")[0]?.field??r.find((u)=>u.type==="text"&&u.field!==s)?.field??s,i=N(r,"description")[0]?.field,o=N(r,"search").map((u)=>u.field).filter((u)=>_r.test(u)),l=o.length?o:e.description.search?.length?e.description.search:_r.test(n)?[n]:[];return{key:s,label:n,...i?{description:i}:{},search:l}}var jr=(e,t)=>{let r=t.description?Rr(St(e,t.description)):"";return{value:St(e,t.key),label:Rr(St(e,t.label)),...r?{description:r}:{},row:e}},aa=(e,t)=>e.map((r)=>({value:r.value,label:ce(r.label,t)})),Ee=(e,t)=>e===t||e!==null&&t!==null&&e!==void 0&&t!==void 0&&typeof e!=="object"&&String(e)===String(t)||R(e,t),vt=(e)=>e.normalize("NFD").replace(/[̀-ͯ]/g,"").toLowerCase();function _o(e,t){let r=vt(t.trim());if(!r)return[...e];return e.filter((s)=>vt(s.label).includes(r)||(s.description?vt(s.description).includes(r):!1))}function zt(e,t){return new Er(e,t)}class Er{ref;roles;store;error;cell;stops=[];searchStore=null;stopSearch=null;term="";looked=new Map;asked=new Set;wanted=[];lookupSeq=0;lastRows=null;lastSearchRows=null;baseOptions=Ve;searchOptions=Ve;constructor(e,t){this.ref=e;let r=null,s=null;try{if(!t)throw new a("invalid_binding","a reference store needs a store registry (provide one with your framework adapter)",{path:"options.store"});let n=t.get(e.store);if(!M(n))throw new a("invalid_binding",`the reference "${e.store}" must be a list store`,{path:"options.store"});r=n}catch(n){s=E(n)}this.store=r,this.error=s,this.roles=r?cn(r,e):null,this.cell=new V(this.compute(),{start:()=>this.start(),stop:()=>this.stop()})}get(){if(!this.cell.observed)this.sync();return this.cell.get()}subscribe(e){return this.cell.subscribe(e)}keyOf=(e)=>e!==null&&typeof e==="object"?JSON.stringify(e):String(e);find(e){if(e===null||e===void 0)return;return this.get().options.find((r)=>Ee(r.value,e))??this.baseOptions.find((r)=>Ee(r.value,e))??this.looked.get(this.keyOf(e))}search(e){let t=e.trim();if(t===this.term)return;if(this.term=t,!this.store)return;let r=this.store.get();if(!t||this.complete(r)){this.closeSearch(),this.sync();return}let s=this.roles;if(!this.searchStore){let n=this.store.description;this.searchStore=fe(this.store.transport,{table:n.table,...n.select?{select:n.select}:{},...n.where?{where:n.where}:{},...n.order?{order:n.order}:{},...n.include?{include:n.include}:{},...n.keyColumn?{keyColumn:n.keyColumn}:{},...s.search.length?{search:s.search}:{},pageSize:n.reference?$r:n.pageSize??$r,realtime:!1,debounceMs:0})}if(this.searchStore.update({search:t}),this.cell.observed&&!this.stopSearch)this.stopSearch=this.searchStore.subscribe(()=>this.sync());this.sync()}suggest(e){if(!this.store)return Promise.resolve(Ve);let t=this.store.get();if(this.complete(t)||!e.trim())return this.search(""),this.whenLoaded(this.store).then(()=>_o(this.baseOptionsNow(),e));this.search(e);let r=this.searchStore;return this.whenLoaded(r).then(()=>this.optionsOf(r.get().rows))}whenLoaded(e){let t=()=>e.get().status==="ready"||e.get().status==="error";if(t()&&!(e===this.searchStore&&e.get().search.trim()!==this.term))return Promise.resolve();return new Promise((r)=>{let s=e.subscribe(()=>{if(!t())return;s(),r()})})}baseOptionsNow(){return this.sync(),this.baseOptions}want(e){this.wanted=e.filter((t)=>t!==null&&t!==void 0),this.lookup(),this.sync()}async retry(){await this.store?.refresh()}complete(e){return e.status==="ready"&&e.total!==null&&e.total<=e.rows.length}optionsOf(e){let t=this.roles;return e.map((r)=>jr(r,t))}lookup(){let e=this.store;if(!e||!this.cell.observed||e.get().status!=="ready")return;let t=(l)=>this.baseOptions.some((u)=>Ee(u.value,l))||this.looked.has(this.keyOf(l)),r=this.wanted.filter((l)=>!t(l)&&!this.asked.has(this.keyOf(l))&&typeof l!=="object");if(r.length===0)return;for(let l of r)this.asked.add(this.keyOf(l));let s=this.roles,n=e.description,i=++this.lookupSeq,o=new X.AbortController;e.transport.find({table:n.table,...n.select?{select:n.select}:{},...n.include?{include:n.include}:{},where:{[s.key]:{in:r}},order:[],limit:r.length,offset:0},{signal:o.signal}).then((l)=>{for(let u of l){let c=jr(u,s);this.looked.set(this.keyOf(c.value),c)}this.sync()},()=>{})}start(){if(!this.store)return;if(this.stops.push(this.store.subscribe(()=>{this.sync(),this.lookup()})),this.searchStore&&this.term)this.stopSearch=this.searchStore.subscribe(()=>this.sync());this.sync(),this.lookup()}stop(){let e=this.stops;this.stops=[];for(let t of e)t();this.stopSearch?.(),this.stopSearch=null}closeSearch(){this.stopSearch?.(),this.stopSearch=null}sync(){let e=this.compute(),t=this.cell?.get();if(t&&t.options===e.options&&t.loading===e.loading&&t.error===e.error&&t.complete===e.complete&&t.search===e.search)return;if(this.cell)this.cell.set(e)}compute(){if(!this.store)return{options:Ve,loading:!1,error:this.error,complete:!0,search:""};let e=this.store.get();if(e.rows!==this.lastRows)this.lastRows=e.rows,this.baseOptions=this.optionsOf(e.rows);let t=!!this.term&&!!this.searchStore&&this.stopSearch!==null,r=t?this.searchStore.get():null;if(r&&r.rows!==this.lastSearchRows)this.lastSearchRows=r.rows,this.searchOptions=this.optionsOf(r.rows);let s=r?this.searchOptions:this.baseOptions,n=[];for(let u of this.wanted){if(s.some((f)=>Ee(f.value,u)))continue;let c=this.baseOptions.find((f)=>Ee(f.value,u))??this.looked.get(this.keyOf(u));if(c)n.push(c)}let i=n.length?[...s,...n]:s,o=this.cell?.get();return{options:o&&o.options.length===i.length&&o.options.every((u,c)=>u===i[c])?o.options:i,loading:e.status==="loading"||r?.status==="loading",error:e.error??r?.error??null,complete:this.complete(e),search:t?this.term:""}}}var un=/^\d{4}-\d{2}-\d{2}$/,fn=/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}(:?\d{2})?)?$/,Ye=(e)=>typeof e==="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof Date);function dn(e){if(e===null||e===void 0||e==="")return;if(typeof e==="number"||typeof e==="bigint")return"number";if(typeof e==="boolean")return"boolean";if(e instanceof Date)return"datetime";if(typeof e==="string")return un.test(e)?"date":fn.test(e)?"datetime":"text";if(Array.isArray(e)||typeof e==="object")return"json";return"text"}function Cr(e){let t=e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[\s_\-.]+/).filter(Boolean).map((s)=>s.toLowerCase());if(t.length===0)return e;let r=t.join(" ");return r.charAt(0).toUpperCase()+r.slice(1)}var Tr=/^[A-Za-z_][A-Za-z0-9_.-]{0,127}$/,hn=(e)=>Ye(e)&&Ye(e.columns);function ar(e,t={}){let r=new Map;if(hn(e))for(let[n,i]of Object.entries(e.columns))r.set(n,qe(String(i))??"text");else if(Array.isArray(e)){let n=Math.max(1,t.sample??50);for(let i of e.slice(0,n)){if(!Ye(i))continue;for(let[o,l]of Object.entries(i)){let u=dn(l),c=r.get(o);if(!r.has(o))r.set(o,u);else if(u!==void 0&&c!==u)r.set(o,c===void 0?u:c==="date"&&u==="datetime"||c==="datetime"&&u==="date"?"datetime":"mixed")}}}let s=[...r.entries()].filter(([n])=>Tr.test(n)&&!n.includes(".")).map(([n,i])=>({field:n,header:Cr(n),type:i===void 0||i==="mixed"?"text":i}));if(s.length===0)return[];return he(s.slice(0,200)).map((n)=>({...n,typeSource:"inferred"}))}function rn(e,t,r={}){if(!t||t.length===0)return r.only?[]:e;let s=(l)=>{let u=l.header===l.field?{...l,header:Cr(l.field.split(".").pop()??l.field)}:l;if(u.typeSource!=="default")return u;let c=e.find((f)=>f.field===u.field);if(!c||c.type===u.type)return u;return{...u,type:c.type,typeSource:"inferred",align:u.align==="left"?c.align:u.align,sortable:c.sortable&&u.sortable}};if(r.only)return t.map(s);let n=new Map(t.map((l)=>[l.key,l])),i=new Set,o=e.map((l)=>{let u=n.get(l.key);if(!u)return l;return i.add(u.key),s(u)});for(let l of t)if(!i.has(l.key))o.push(s(l));return o}function la(e,t,r=50){let s=new Set(t.map((n)=>n.field));for(let n of e.slice(0,r)){if(!Ye(n))continue;for(let i of Object.keys(n))if(!s.has(i)&&Tr.test(i)&&!i.includes("."))return!0}return!1}var on=Symbol("poad.storeRegistry");
2
+ export{a,E,R,V,he,ce,sa,N,X,te,kt,Re,pe,fe,M,Ce,tt,nt,Ne,rt,x,ot,aa,Ee,_o,zt,ar,rn,la,on};
@@ -0,0 +1 @@
1
+ import{n}from"./c-ytpw5gj2.js";import{Nt,Ls,Zn,Rs,ho,Ns,Yn,Bs,zs,Fs,Xn,Jn,js}from"./c-4s1xdsjj.js";import{De}from"./c-gqaaq5xd.js";import{I,Z}from"./c-z6dbvc3p.js";import{le}from"./c-1j1xssd8.js";import{x}from"./c-tjk566f2.js";import{o}from"./c-9hk02377.js";import{t,c,s,r,h,u,l,e}from"./c-g0ncg08s.js";var me=r({name:"PoadCombo",props:{data:{type:Object,default:null},store:{type:[Object,String],default:null},field:{type:String,default:null},modelValue:{type:null},suggestions:{type:[Array,Function],default:()=>[]},optionLabel:{type:String,default:"label"},minLength:{type:Number,default:1},delay:{type:Number,default:250},dropdown:Boolean,forceSelection:Boolean,multiple:Boolean,clearable:Boolean,readonly:Boolean,disabled:Boolean,invalid:Boolean,placeholder:{type:String,default:""},emptyMessage:String,size:{type:String,default:"md"},panelMaxHeight:{type:Number,default:260},ariaLabel:String,id:String},emits:{"update:modelValue":(a)=>!0,search:(a)=>!0,openChange:(a)=>!0},setup(a,{emit:H,slots:j}){let{t:M,text:Q}=o(),X=h(),T=()=>`${a.id??`poad-combo-${X}`}-list`,C=le(()=>x(a.data,a.store,a.field),"combo",()=>a.multiple),L=C.model(l(a,"modelValue")),z=()=>!!C.choice.value?.options,p=()=>z()?"label":a.optionLabel,A=()=>a.forceSelection||z(),Y=()=>z()?(i)=>C.choice.value.suggest(i):a.suggestions,P=()=>L.value??(a.multiple?[]:null),f=t(a.multiple?"":ho(L.value,p())),b=t(!1),E=t(!1),S=c([]),y=t(-1),K=t(0),U=t(null),O=t(null),W=t(null),D=t(null),B=null,N=0;s(()=>a.multiple?null:L.value,(i)=>{if(!a.multiple)f.value=ho(i,p())}),u(()=>{if(B)clearTimeout(B)});let w=(i)=>{L.value=i},G=(i)=>{if(b.value=i,i)K.value=O.value?.getBoundingClientRect().width??0;H("openChange",i)},k=()=>{if(!b.value)return;y.value=-1,G(!1)},R=async(i)=>{H("search",i);let m=++N,v=[],d=Y();if(typeof d==="function"){E.value=!0;try{v=await d(i)}catch{v=[]}finally{if(m===N)E.value=!1}}else v=Ls(d,i,p());if(m!==N)return;if(S.value=v,y.value=Bs(v.length).active,!b.value)G(!0)},q=(i)=>{if(f.value=i,!a.multiple&&!A())w(i||null);if(Ns(i,a.minLength)==="close"){k();return}if(B)clearTimeout(B);B=setTimeout(()=>void R(i),a.delay)},J=(i)=>{let m=zs(P(),i,{multiple:a.multiple,labelPath:p()});if(m.changed)w(m.value);f.value=m.text,k()},ee=()=>{let i=Fs(P(),f.value,{forceSelection:A(),multiple:a.multiple,labelPath:p()});if(!i)return;if(i.text!==void 0)f.value=i.text;if("value"in i)w(i.value)},te=(i)=>{i.stopPropagation(),f.value="",w(a.multiple?[]:null),k()},ae=(i)=>{let m=Zn(P(),a.multiple),v=Yn({open:b.value,active:y.value,count:S.value.length,multiple:a.multiple,text:f.value,valuesCount:m.length},i.key);if(v.preventDefault)i.preventDefault();let d=v.action;if(d.type==="search")R(f.value);else if(d.type==="move")y.value=d.active;else if(d.type==="pick")J(S.value[d.index]);else if(d.type==="close")k();else if(d.type==="remove-last")w(m.slice(0,-1))},{style:ne}=I({open:()=>b.value,anchor:O,floating:W,candidates:()=>De,offset:4,shift:!0,deps:()=>S.value});return Z(()=>b.value,[U],()=>k()),()=>{let i=Zn(P(),a.multiple),m=Xn({open:b.value,listId:T(),active:y.value,invalid:C.invalid(a.invalid)}),v=e("input",{ref:D,class:"st__input",role:m.role,placeholder:a.multiple&&i.length?"":a.placeholder,value:f.value,disabled:a.disabled,readonly:!a.multiple&&a.readonly,autocomplete:"off",spellcheck:!1,"aria-autocomplete":m["aria-autocomplete"],"aria-expanded":m["aria-expanded"],"aria-controls":m["aria-controls"],"aria-activedescendant":m["aria-activedescendant"]??void 0,"aria-invalid":a.multiple?void 0:m["aria-invalid"]??void 0,"aria-label":a.ariaLabel,onInput:(d)=>q(d.target.value),onKeydown:ae,onBlur:ee});return e("div",{ref:U,class:["poad-combo",js({...a,invalid:C.invalid(a.invalid),open:b.value}),C.bound.view.value?.classes]},[e("div",{ref:O,class:["st",{"st--multi":a.multiple}],onClick:()=>D.value?.focus()},[a.multiple?e("span",{class:"st__chips"},[...i.map((d,g)=>e("span",{key:g,class:"st__chip"},[Nt(d,p()),e("button",{type:"button",tabindex:-1,"aria-label":M("common.remove"),onClick:(_)=>{if(_.stopPropagation(),!a.disabled)w(i.filter((V,F)=>F!==g))}},[e(n,{name:"x",size:10})])])),v]):v,E.value&&e(n,{name:"loader",size:14,spin:!0,class:"st__spin"}),a.clearable&&(f.value||i.length>0)&&!a.disabled&&e("button",{type:"button",class:"st__clear",tabindex:-1,"aria-label":M("common.clear"),onClick:te},[e(n,{name:"x",size:12})]),a.dropdown&&e("button",{type:"button",class:"st__dd",tabindex:-1,"aria-label":M("select.showSuggestions"),onClick:(d)=>{if(d.stopPropagation(),a.disabled)return;if(b.value){k();return}D.value?.focus(),R("")}},[e(n,{name:"chevron-down",size:13,class:"st__chev"})])]),b.value&&e("div",{ref:W,class:"poad-floating poad-combo-pane",style:ne()},[e("div",{class:"sp",style:{minWidth:`${K.value}px`}},[e("ul",{class:"cb__list",role:"listbox",id:T(),style:{maxHeight:`${a.panelMaxHeight}px`}},S.value.length?S.value.map((d,g)=>{let _=Jn(T(),g,g===y.value,Rs(P(),d,a.multiple)),V=Nt(d,p());return e("li",{key:g,role:_.role,id:_.id,class:_.classes,"aria-selected":_["aria-selected"],onMousedown:(F)=>F.preventDefault(),onMouseenter:()=>{y.value=g},onClick:()=>J(d)},j.option?j.option({option:d,selected:_.classes["is-on"],index:g,label:V}):V)}):!E.value?[e("li",{class:"sp__empty"},Q(a.emptyMessage,"select.noSuggestions"))]:[])])])])}}});export{me as PoadCombo};
@@ -0,0 +1 @@
1
+ import"./c-ytpw5gj2.js";import"./c-pp0qxmbz.js";import"./c-170fz4v2.js";import"./c-yf86vgtz.js";import"./c-qhv2qby2.js";import"./c-8g74gqn9.js";import"./c-00cvgnxc.js";import{Ur}from"./c-dzp10g67.js";import{pn,st}from"./c-4w8c01x6.js";import{$e,at,gr}from"./c-hwgt6amh.js";import{ge,ye}from"./c-q9h7pf4v.js";import{L}from"./c-r7qgrz3b.js";import{Ze,Ae,B,oe}from"./c-6pfxp4ca.js";import"./c-aenj05yt.js";import"./c-zbts8rvw.js";import{k,D}from"./c-x0evjwqg.js";import"./c-z6dbvc3p.js";import{_}from"./c-t8hew4h2.js";import{o}from"./c-9hk02377.js";import{p,t,c,y,s,r,h,f,u,i,e}from"./c-g0ncg08s.js";function Bt(n,a,l){let g=new Map(n.map((x)=>[x.id,x])),m=[],w=(x,S)=>{for(let I of x){let P=g.get(I);if(!P)continue;if(!P.scheduled&&!P.milestone)continue;if(m.push({task:P,level:S}),P.children.length&&l.has(P.id))w(P.children,S+1)}};return w(a,0),m}function zt(n,a,l,g=12,m=17){let w=n.charAt(0)==="F",x=n.charAt(1)==="S",S=w?a.x2:a.x1,I=w?1:-1,P=x?l.x1:l.x2,E=x?-1:1,z=S+I*g,j=P+E*g,R=x?z<=j:z>=j,H=`M${S} ${a.y} H${z}`;if(R)H+=` V${l.y} H${P}`;else{let G=a.y<l.y?l.y-m:l.y+m;H+=` V${G} H${j} V${l.y} H${P}`}return{d:H,fleche:{x:P,y:l.y,sens:x?"right":"left"}}}function Kt(n,a=4.5){let l=n.sens==="right"?n.x-a*1.6:n.x+a*1.6;return`${n.x},${n.y} ${l},${n.y-a} ${l},${n.y+a}`}var jt=(n,a)=>a||(n==="day"?36:n==="week"?90:120),Et={src:void 0,map:new Map};function it(n,a,l,g){let m=new Map(n.src===a?n.map:[]);return m.set(l,g),{src:a,map:m}}function Ht(n,a){if(!n||a.src!==n||!a.map.size)return n??null;return{...n,tasks:(n.tasks??[]).map((l)=>{let g=a.map.get(l.id);return g?{...l,start:g.start,end:g.end,duration:null}:l})}}var we=(n)=>n.tasks.filter((a)=>a.children.length).map((a)=>a.id),bt=(n,a)=>n?[...n]:we(a),Nt=(n,a)=>Bt(n.tasks,n.roots,new Set(a)),Ot=(n)=>n.tasks.filter((a)=>!a.scheduled&&!a.children.length);function Gt(n,a){let l=null,g=null,m=(w)=>{if(!w)return;l=l===null?w.getTime():Math.min(l,w.getTime()),g=g===null?w.getTime():Math.max(g,w.getTime())};for(let w of n.tasks)if(w.scheduled)m(w.start),m(w.end);if(l===null||g===null)return null;for(let w of a??[])m(D(w.date));return{min:new Date(l),max:new Date(g)}}function Lt(n,a,l){if(!n)return{upper:[],lower:[]};let g=a==="day"?3:a==="week"?10:40;return pn(k(n.min,-g),k(n.max,g),a,{locale:l.locale,i18n:l.i18n,firstDay:l.firstDay,calendar:l.calendar??null,today:l.today??new Date})}function Ft(n,a){return{lower:n.lower.map((l)=>({label:l.label,off:l.off,today:l.today})),upper:n.upper.map((l)=>{let g=Math.max(0,a.xOf(l.start)),m=Math.min(a.width,a.xOf(l.end));return{label:l.label,w:Math.max(0,m-g)}}).filter((l)=>l.w>0)}}var Ut=(n,a)=>n.lower.map((l,g)=>({off:l.off,x:g*a,w:a})).filter((l)=>l.off).map(({x:l,w:g})=>({x:l,w:g})),Wt=(n,a)=>n.lower.map((l,g)=>({major:l.major,x:g*a})).filter((l)=>a>=20||l.major).map((l)=>l.x);function qt(n,a){let{start:l,end:g}=a;if(!l||!g)return[];let m=[];for(let w of n??[]){let x=D(w.date);if(!x||x<l||x>=g)continue;m.push({x:a.xOf(x),label:w.label??""})}return m}function Vt(n,a){if(!a.start||!a.end||n<a.start||n>=a.end)return null;return a.xOf(n)}var rt=34;function Yt(n,a){if(a&&a.tops.length===n&&n>0)return{tops:a.tops,heights:a.heights,total:a.tops[n-1]+a.heights[n-1]};return{tops:Array.from({length:n},(l,g)=>g*rt),heights:Array(n).fill(rt),total:n*rt}}function Jt(n){let a=Array.from(n);if(!a.length)return null;let l=a[0].getBoundingClientRect().top,g=[],m=[];for(let w of a){let x=w.getBoundingClientRect();if(x.height<=0)return null;g.push(Math.round(x.top-l)),m.push(Math.round(x.height))}return{tops:g,heights:m}}var dt=(n)=>{try{return Intl.getCanonicalLocales(n)[0]??"en"}catch{return"en"}},q=(n,a)=>a?new Intl.DateTimeFormat(dt(n),{day:"2-digit",month:"2-digit"}).format(a):"",Qt=(n,a,l)=>l("planning.days",{days:new Intl.NumberFormat(dt(a),{maximumFractionDigits:1}).format(n)});function _e(n,a){if(n.milestone)return a.t("planning.milestone");if(!n.start||!n.end)return"";let l=a.calendar.minutesBetween(n.start,n.end)/a.calendar.dailyMinutes;return Qt(Math.round(l*10)/10,a.locale,a.t)}function ct(n,a){if(n.milestone)return`${n.label} — ${q(a.locale,n.start)} (${a.t("planning.milestone")})`;let l=` · ${new Intl.NumberFormat(dt(a.locale),{style:"percent",maximumFractionDigits:0}).format(n.progress)}`,g=n.rolled?" "+a.t("planning.summary"):"";return`${n.label} — ${q(a.locale,n.start)} → ${q(a.locale,n.end)}${l}${g}`}function Xt(n,a){let l=n.lagMinutes?` · ${a.t("planning.lag",{days:Qt(Math.round(n.lagMinutes/a.calendar.dailyMinutes*10)/10,a.locale,a.t)})}`:"";return`${n.from} → ${n.to} · ${n.type}${l}`}function Zt(n,a){return n.tasks.filter((l)=>l.scheduled||l.milestone||l.children.length).map((l)=>({id:l.id,parent:l.parent,label:l.label,start:q(a.locale,l.start),end:l.milestone?"—":q(a.locale,l.end),duration:_e(l,a),pct:String(Math.round(l.progress*100))}))}function te(n,a,l){let g=new Map,m=[];return n.forEach((w,x)=>{let S=w.task;if(!S.start||!S.end)return;let I=l.tops[x]+l.heights[x]/2,P=l.heights[x]/2;if(S.milestone){let R=a.xOf(S.start);m.push({task:S,kind:"milestone",x:R-8,w:16,y:I}),g.set(S.id,{x1:R-8,x2:R+8,y:I,half:P});return}let E=a.spanOf(S.start,S.end),z=E.x,j=Math.max(4,E.width-2);m.push({task:S,kind:S.rolled?"summary":"bar",x:z,w:j,y:I}),g.set(S.id,{x1:z,x2:z+j,y:I,half:P})}),{bars:m,anchors:g}}function ee(n,a,l){let g=[];for(let m of n){let w=a.get(m.from),x=a.get(m.to);if(!w||!x)continue;let S=zt(m.type,w,x,12,x.half);g.push({id:m.id,d:S.d,arrow:Kt(S.fleche),title:l(m),from:m.from,to:m.to})}return g}function ne(n,a){if(!a)return{links:new Set,tasks:new Set};let l=new Set,g=new Set([a]);for(let m of n){if(m.from===a)l.add(m.id),g.add(m.to);if(m.to===a)l.add(m.id),g.add(m.from)}return{links:l,tasks:g}}var ut=(n,a)=>a&&!n.locked&&!n.rolled&&!!n.start&&!!n.end;function ae(n,a,l){return`${n.kind==="milestone"?"gt__jal":n.kind==="summary"?"gt__sum":"gt__b"}${l?" is-hot":""}${ut(n.task,a)?" is-editable":a&&n.kind!=="summary"?" is-verrouille":""}`}var se=(n)=>`poad-gantt is-${n.scale}${n.editable?" is-editable":""}${n.dragging?" is-dragging":""}${n.compact?" is-compact":""}`,Te=86400000;function le(n,a,l,g,m=!1){let w=n==="resize-end"?a.end:a.start,x=g.dateAt(g.xOf(w)+l),S=x?Math.round((x.getTime()-w.getTime())/Te):0;return re(m?"move":n,a,S)}function re(n,a,l){if(n==="resize-end"){let g=k(a.end,l);while(g.getTime()<=a.start.getTime())g=k(g,1);return{start:a.start,end:g}}if(n==="resize-start"){let g=k(a.start,l);while(g.getTime()>=a.end.getTime())g=k(g,-1);return{start:g,end:a.end}}return{start:k(a.start,l),end:k(a.end,l)}}function ie(n,a){if(n!=="ArrowLeft"&&n!=="ArrowRight"||!a.ctrl&&!a.shift||!a.task.start||!a.task.end)return null;let l=a.shift&&!a.ctrl?"resize-end":"move";if(l==="resize-end"&&a.task.milestone)return null;let g={start:a.task.start,end:a.task.end},m=re(l,g,n===(a.rtl?"ArrowLeft":"ArrowRight")?1:-1);if(m.start.getTime()===g.start.getTime()&&m.end.getTime()===g.end.getTime())return null;return{kind:l==="move"?"move":"resize",start:m.start,end:m.end}}var de=(n,a,l,g)=>n==="move"?{key:"planning.announceMoved",params:{label:a.label,date:$e(g,l.start,!0)}}:{key:"planning.announceResized",params:{label:a.label,date:$e(g,l.end,!0)}};function ce(n,a){if(!n)return null;return Array.from(n.querySelectorAll(".gt__corps [data-task]")).find((g)=>g.getAttribute("data-task")===a)??null}function ue(n){let a={start:n.task.start,end:n.task.end};return gr({event:n.event,doc:n.doc,base:a,project:(l)=>le(n.kind,a,n.rtl?-l:l,n.axis,n.task.milestone),onPreview:n.onPreview,onCommit:n.onCommit,onCancel:n.onCancel})}var Ge=r({name:"PoadGantt",inheritAttrs:!1,props:{data:{type:Object,default:null},store:{type:[Object,String],default:null},fields:{type:Array,default:null},plan:{type:Object,default:null},scale:{type:String,default:"week"},expandedKeys:{type:Array,default:null},selectedKey:{type:String,default:null},tickWidth:{type:Number,default:null},workCalendar:{type:Object,default:null},today:{type:Date,default:null},locale:String,firstDay:{type:Number,default:1},emptyText:String,showNow:{type:Boolean,default:!0},showUnplanned:{type:Boolean,default:!0},taskColumnWidth:{type:String,default:"210px"},editable:Boolean},emits:{taskClick:(n)=>!0,taskMove:(n)=>!0,taskResize:(n)=>!0,"update:expandedKeys":(n)=>!0,"update:selectedKey":(n)=>!0},setup(n,{emit:a,attrs:l}){let g=o(),m=B(n),w=i(()=>m.state.value?Ae(m.state.value,{locale:g.locale}):null),x=(v,T)=>{a(v,T);let C=m.binding.value;if(C&&(v==="taskMove"||v==="taskResize")){let A=T;Ze(C,A.task.id,A.start,A.end)}},S=()=>w.value&&!m.given("editable")?w.value.editable:n.editable,I=(v,T)=>g.t(v,T),P=`poad-gantt-${h()}-hint`,E=L(),z=c(null),j=t(null),R=c(Et),H=t(!1),G=t(null),pt=t(""),F=c(null),gt=t(44),b=t(null),ft=at(),V=null,U=null,O=()=>w.value?w.value.plan:n.plan?p(n.plan):null,X=()=>n.locale??g.locale,Z=i(()=>ge(g.locale,g.messages)),pe=i(()=>ye(O(),{i18n:Z.value})),N=i(()=>ye(Ht(O(),R.value),{i18n:Z.value})),mt=i(()=>n.workCalendar??N.value.calendar),ht=i(()=>jt(n.scale,n.tickWidth)),yt=i(()=>bt(n.expandedKeys??z.value,N.value)),vt=()=>n.selectedKey??j.value,xt=i(()=>Nt(N.value,yt.value)),Y=i(()=>Lt(Gt(pe.value,O()?.markers),n.scale,{locale:X(),i18n:Z.value,firstDay:n.firstDay,calendar:mt.value,today:n.today??new Date})),kt=i(()=>new st(Y.value.lower,ht.value)),wt=()=>{let v=b.value;if(!v)return;let T=v.querySelector(".gt__gauche thead")?.getBoundingClientRect().height??0;if(T>0)gt.value=Math.round(T);let C=Jt(v.querySelectorAll(".gt__gauche tbody tr"));if(C&&!(F.value&&F.value.tops.join()===C.tops.join()&&F.value.heights.join()===C.heights.join()))F.value=C},_t=()=>{U?.disconnect(),U=null,wt();let v=b.value?.querySelector(".gt__gauche");if(v&&typeof ResizeObserver<"u")U=new ResizeObserver(wt),U.observe(v)};f(_t),s(()=>[xt.value.length,E.isMobile.value],()=>void y(_t)),u(()=>{V?.(),U?.disconnect()});let J=(v)=>ut(v,S()),$t=(v)=>{j.value=v,x("update:selectedKey",v)},Tt=()=>{V=null,H.value=!1,ft.mark()},Mt=(v,T,C,A=R.value)=>{if(R.value=it(A,O(),T.id,C),v==="move")x("taskMove",{task:T,start:C.start,end:C.end});else x("taskResize",{task:T,start:C.start,end:C.end});let K=de(v,T,C,X());pt.value=g.t(K.key,K.params)},tt=(v,T,C)=>{if(!J(T.task)||C.button!==0||!b.value)return;C.preventDefault(),C.stopPropagation(),V?.();let A=R.value;V=ue({kind:v,event:C,doc:b.value.ownerDocument,task:T.task,axis:kt.value,rtl:_(b.value),onPreview:(K)=>{H.value=!0,R.value=it(A,O(),T.task.id,K)},onCommit:(K)=>{Tt(),Mt(v==="move"?"move":"resize",T.task,K,A)},onCancel:()=>{Tt(),R.value=A}})},fe=(v,T)=>{if(!J(v.task))return;let C=ie(T.key,{task:v.task,ctrl:T.ctrlKey||T.metaKey,shift:T.shiftKey,rtl:_(T.currentTarget)});if(!C)return;T.preventDefault(),Mt(C.kind,v.task,C),y(()=>ce(b.value,v.task.id)?.focus())},me=(v,T)=>{if(T.stopPropagation(),ft.blocked())return;$t(v.id),x("taskClick",{task:v,originalEvent:T})},Ct=(v,T)=>{$t(vt()===v.id?null:v.id),x("taskClick",{task:v,originalEvent:T})};return()=>{let{t:v,text:T}=g,C=X(),A=kt.value,K=ht.value,et=E.isMobile.value,Q=xt.value,W=Yt(Q.length,F.value),{bars:he,anchors:ve}=te(Q,A,W),St={locale:C,t:I,calendar:mt.value},Pt=ee(N.value.links,ve,(d)=>Xt(d,St)),nt=ne(Pt,G.value),At=Ft(Y.value,A),Dt=qt(O()?.markers,A),It=n.showNow?Vt(n.today??new Date,A):null,lt=Ot(N.value),xe=[{field:"label",header:v("planning.columnTask"),width:et?"140px":n.taskColumnWidth},...et?[]:[{field:"start",header:v("planning.columnStart"),width:"60px"},{field:"end",header:v("planning.columnEnd"),width:"60px"},{field:"duration",header:v("planning.columnDuration"),width:"52px"},{field:"pct",header:"%",width:"38px"}]],ot=(d)=>({key:d.task.id,type:"button",class:ae(d,S(),nt.tasks.has(d.task.id)),"data-task":d.task.id,"aria-label":ct(d.task,{locale:C,t:I}),title:ct(d.task,{locale:C,t:I}),onPointerenter:()=>{G.value=d.task.id},onPointerleave:()=>{G.value=null},onClick:(M)=>me(d.task,M)}),Rt=(d)=>({"aria-describedby":J(d.task)?P:void 0,onPointerdown:(M)=>tt("move",d,M),onKeydown:(M)=>fe(d,M)});return oe(m,e("div",{ref:b,role:"region",class:se({scale:n.scale,editable:S(),dragging:H.value,compact:et})},[e("p",{class:"gt__live",role:"status","aria-live":"polite"},pt.value),e("span",{class:"gt__hint",id:P},v("planning.ganttHint")),Q.length?e("div",{class:"gt__scroll"},[e("div",{class:"gt"},[e("div",{class:"gt__gauche"},[e(Ur,{value:Zt(N.value,St),columns:xe,dataKey:"id",parentKey:"parent",treeColumn:"label",dense:!0,showToolbar:!1,expandedNodeKeys:yt.value,"onUpdate:expandedNodeKeys":(d)=>{let M=d.map(String);z.value=M,x("update:expandedKeys",M)},onRowClick:(d)=>{let M=N.value.byId.get(String(d.row.id));if(M)Ct(M,d.event)}})]),e("div",{class:"gt__droite",style:{width:`${A.width}px`}},[e("div",{class:"gt__hd",style:{height:`${gt.value}px`}},[e("div",{class:"gt__hdr is-haut"},At.upper.map((d,M)=>e("div",{key:M,class:"gt__hc",style:{width:`${d.w}px`}},d.label))),e("div",{class:"gt__hdr"},At.lower.map((d,M)=>e("div",{key:M,class:["gt__hc",{"is-off":d.off,"is-auj":d.today}],style:{width:`${K}px`}},d.label))),...Dt.map((d,M)=>e("span",{key:`m${M}`,class:"gt__drapeau",style:{insetInlineStart:`${d.x+4}px`}},d.label))]),e("div",{class:"gt__corps",style:{height:`${W.total}px`}},[...Ut(Y.value,K).map((d,M)=>e("div",{key:`o${M}`,class:"gt__off",style:{insetInlineStart:`${d.x}px`,width:`${d.w}px`}})),...Wt(Y.value,K).map((d,M)=>e("div",{key:`t${M}`,class:"gt__trait",style:{insetInlineStart:`${d}px`}})),...Dt.map((d,M)=>e("div",{key:`m${M}`,class:"gt__marqueur",style:{insetInlineStart:`${d.x}px`}})),It!==null?e("div",{key:"now",class:"gt__now",style:{insetInlineStart:`${It}px`}}):null,...Q.map((d,M)=>e("div",{key:`r${d.task.id}`,class:["gt__row",{"is-sel":vt()===d.task.id}],style:{top:`${W.tops[M]}px`,height:`${W.heights[M]}px`},onClick:(ke)=>Ct(d.task,ke)})),e("svg",{key:"svg",class:"gt__liens",width:A.width,height:W.total,"aria-hidden":"true"},Pt.flatMap((d)=>[e("path",{key:`p${d.id}`,d:d.d,class:{"is-hot":nt.links.has(d.id)}},[e("title",d.title)]),e("polygon",{key:`f${d.id}`,class:["fl",{"is-hot":nt.links.has(d.id)}],points:d.arrow})])),...he.flatMap((d)=>d.kind==="milestone"?[e("button",{...ot(d),...Rt(d),style:{insetInlineStart:`${d.x+d.w/2-6}px`,top:`${d.y-6}px`}}),e("span",{key:`l${d.task.id}`,class:"gt__lbl",style:{insetInlineStart:`${d.x+d.w/2+12}px`,top:`${d.y-8}px`}},d.task.label)]:d.kind==="summary"?[e("button",{...ot(d),style:{insetInlineStart:`${d.x}px`,width:`${d.w}px`,top:`${d.y-5}px`}})]:[e("button",{...ot(d),...Rt(d),style:{"--_c":d.task.color||void 0,"--_p":`${d.task.progress*100}%`,insetInlineStart:`${d.x}px`,width:`${d.w}px`,top:`${d.y-8}px`}},[e("span",{class:"avancement"}),...J(d.task)?[e("span",{class:"poignee is-debut",onPointerdown:(M)=>tt("resize-start",d,M)}),e("span",{class:"poignee is-fin",onPointerdown:(M)=>tt("resize-end",d,M)})]:[]]),e("span",{key:`l${d.task.id}`,class:"gt__lbl",style:{insetInlineStart:`${d.x+d.w+6}px`,top:`${d.y-8}px`}},d.task.label)])])])])]):e("div",{class:"gt__vide"},T(n.emptyText,"planning.ganttEmpty")),n.showUnplanned&&lt.length?e("div",{class:"gt__tray"},[e("span",{class:"gt__trayt"},v("planning.unplanned")),e("span",{class:"gt__trayn"},String(lt.length)),...lt.map((d)=>e("span",{key:d.id,class:"gt__chip"},[d.label,e("i",v("planning.noDates"))]))]):null]),l)}}});export{Ge as PoadGantt};