@satoshibits/react-json-schema-builder 1.0.1 → 1.0.2

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 (437) hide show
  1. package/dist/index.cjs10.js +1 -1
  2. package/dist/index.cjs10.js.map +1 -1
  3. package/dist/index.cjs100.js +1 -1
  4. package/dist/index.cjs100.js.map +1 -1
  5. package/dist/index.cjs101.js +1 -38
  6. package/dist/index.cjs101.js.map +1 -1
  7. package/dist/index.cjs102.js +1 -1
  8. package/dist/index.cjs102.js.map +1 -1
  9. package/dist/index.cjs103.js +1 -1
  10. package/dist/index.cjs103.js.map +1 -1
  11. package/dist/index.cjs11.js +1 -1
  12. package/dist/index.cjs11.js.map +1 -1
  13. package/dist/index.cjs12.js +1 -1
  14. package/dist/index.cjs12.js.map +1 -1
  15. package/dist/index.cjs13.js +1 -1
  16. package/dist/index.cjs13.js.map +1 -1
  17. package/dist/index.cjs14.js +1 -1
  18. package/dist/index.cjs14.js.map +1 -1
  19. package/dist/index.cjs15.js +1 -1
  20. package/dist/index.cjs15.js.map +1 -1
  21. package/dist/index.cjs16.js +1 -1
  22. package/dist/index.cjs16.js.map +1 -1
  23. package/dist/index.cjs17.js +1 -1
  24. package/dist/index.cjs17.js.map +1 -1
  25. package/dist/index.cjs18.js +1 -1
  26. package/dist/index.cjs18.js.map +1 -1
  27. package/dist/index.cjs19.js +1 -1
  28. package/dist/index.cjs19.js.map +1 -1
  29. package/dist/index.cjs2.js +1 -1
  30. package/dist/index.cjs2.js.map +1 -1
  31. package/dist/index.cjs20.js +1 -1
  32. package/dist/index.cjs20.js.map +1 -1
  33. package/dist/index.cjs21.js +1 -1
  34. package/dist/index.cjs21.js.map +1 -1
  35. package/dist/index.cjs22.js +6 -1
  36. package/dist/index.cjs22.js.map +1 -1
  37. package/dist/index.cjs23.js +2 -2
  38. package/dist/index.cjs23.js.map +1 -1
  39. package/dist/index.cjs24.js +2 -2
  40. package/dist/index.cjs24.js.map +1 -1
  41. package/dist/index.cjs25.js +2 -2
  42. package/dist/index.cjs25.js.map +1 -1
  43. package/dist/index.cjs26.js +2 -2
  44. package/dist/index.cjs26.js.map +1 -1
  45. package/dist/index.cjs27.js +1 -6
  46. package/dist/index.cjs27.js.map +1 -1
  47. package/dist/index.cjs28.js +1 -1
  48. package/dist/index.cjs28.js.map +1 -1
  49. package/dist/index.cjs29.js +6 -1
  50. package/dist/index.cjs29.js.map +1 -1
  51. package/dist/index.cjs3.js +1 -1
  52. package/dist/index.cjs3.js.map +1 -1
  53. package/dist/index.cjs30.js +1 -6
  54. package/dist/index.cjs30.js.map +1 -1
  55. package/dist/index.cjs31.js +1 -1
  56. package/dist/index.cjs31.js.map +1 -1
  57. package/dist/index.cjs32.js +1 -1
  58. package/dist/index.cjs32.js.map +1 -1
  59. package/dist/index.cjs33.js +1 -9
  60. package/dist/index.cjs33.js.map +1 -1
  61. package/dist/index.cjs34.js +1 -22
  62. package/dist/index.cjs34.js.map +1 -1
  63. package/dist/index.cjs35.js +1 -1
  64. package/dist/index.cjs35.js.map +1 -1
  65. package/dist/index.cjs36.js +1 -1
  66. package/dist/index.cjs36.js.map +1 -1
  67. package/dist/index.cjs37.js +1 -1
  68. package/dist/index.cjs37.js.map +1 -1
  69. package/dist/index.cjs38.js +1 -1
  70. package/dist/index.cjs38.js.map +1 -1
  71. package/dist/index.cjs39.js +1 -1
  72. package/dist/index.cjs39.js.map +1 -1
  73. package/dist/index.cjs4.js +1 -1
  74. package/dist/index.cjs4.js.map +1 -1
  75. package/dist/index.cjs40.js +1 -1
  76. package/dist/index.cjs40.js.map +1 -1
  77. package/dist/index.cjs41.js +1 -1
  78. package/dist/index.cjs41.js.map +1 -1
  79. package/dist/index.cjs42.js +1 -6
  80. package/dist/index.cjs42.js.map +1 -1
  81. package/dist/index.cjs43.js +2 -2
  82. package/dist/index.cjs43.js.map +1 -1
  83. package/dist/index.cjs44.js +2 -2
  84. package/dist/index.cjs44.js.map +1 -1
  85. package/dist/index.cjs45.js +6 -1
  86. package/dist/index.cjs45.js.map +1 -1
  87. package/dist/index.cjs46.js +7 -1
  88. package/dist/index.cjs46.js.map +1 -1
  89. package/dist/index.cjs47.js +1 -1
  90. package/dist/index.cjs47.js.map +1 -1
  91. package/dist/index.cjs48.js +6 -1
  92. package/dist/index.cjs48.js.map +1 -1
  93. package/dist/index.cjs49.js +6 -1
  94. package/dist/index.cjs49.js.map +1 -1
  95. package/dist/index.cjs5.js +1 -1
  96. package/dist/index.cjs5.js.map +1 -1
  97. package/dist/index.cjs50.js +6 -1
  98. package/dist/index.cjs50.js.map +1 -1
  99. package/dist/index.cjs51.js +6 -7
  100. package/dist/index.cjs51.js.map +1 -1
  101. package/dist/index.cjs52.js +1 -1
  102. package/dist/index.cjs52.js.map +1 -1
  103. package/dist/index.cjs53.js +1 -1
  104. package/dist/index.cjs53.js.map +1 -1
  105. package/dist/index.cjs54.js +5 -1
  106. package/dist/index.cjs54.js.map +1 -1
  107. package/dist/index.cjs55.js +1 -6
  108. package/dist/index.cjs55.js.map +1 -1
  109. package/dist/index.cjs56.js +1 -6
  110. package/dist/index.cjs56.js.map +1 -1
  111. package/dist/index.cjs57.js +1 -6
  112. package/dist/index.cjs57.js.map +1 -1
  113. package/dist/index.cjs58.js +1 -6
  114. package/dist/index.cjs58.js.map +1 -1
  115. package/dist/index.cjs59.js +1 -1
  116. package/dist/index.cjs59.js.map +1 -1
  117. package/dist/index.cjs6.js +1 -1
  118. package/dist/index.cjs6.js.map +1 -1
  119. package/dist/index.cjs60.js +1 -1
  120. package/dist/index.cjs60.js.map +1 -1
  121. package/dist/index.cjs61.js +1 -5
  122. package/dist/index.cjs61.js.map +1 -1
  123. package/dist/index.cjs62.js +1 -1
  124. package/dist/index.cjs62.js.map +1 -1
  125. package/dist/index.cjs63.js +1 -1
  126. package/dist/index.cjs63.js.map +1 -1
  127. package/dist/index.cjs64.js +1 -1
  128. package/dist/index.cjs64.js.map +1 -1
  129. package/dist/index.cjs65.js +1 -1
  130. package/dist/index.cjs65.js.map +1 -1
  131. package/dist/index.cjs66.js +1 -1
  132. package/dist/index.cjs66.js.map +1 -1
  133. package/dist/index.cjs67.js +1 -1
  134. package/dist/index.cjs67.js.map +1 -1
  135. package/dist/index.cjs68.js +1 -1
  136. package/dist/index.cjs68.js.map +1 -1
  137. package/dist/index.cjs69.js +1 -1
  138. package/dist/index.cjs69.js.map +1 -1
  139. package/dist/index.cjs7.js +1 -1
  140. package/dist/index.cjs7.js.map +1 -1
  141. package/dist/index.cjs70.js +1 -1
  142. package/dist/index.cjs70.js.map +1 -1
  143. package/dist/index.cjs71.js +1 -1
  144. package/dist/index.cjs71.js.map +1 -1
  145. package/dist/index.cjs72.js +1 -1
  146. package/dist/index.cjs72.js.map +1 -1
  147. package/dist/index.cjs73.js +1 -1
  148. package/dist/index.cjs73.js.map +1 -1
  149. package/dist/index.cjs74.js +1 -1
  150. package/dist/index.cjs74.js.map +1 -1
  151. package/dist/index.cjs75.js +1 -1
  152. package/dist/index.cjs75.js.map +1 -1
  153. package/dist/index.cjs76.js +1 -1
  154. package/dist/index.cjs76.js.map +1 -1
  155. package/dist/index.cjs77.js +1 -1
  156. package/dist/index.cjs77.js.map +1 -1
  157. package/dist/index.cjs78.js +1 -1
  158. package/dist/index.cjs78.js.map +1 -1
  159. package/dist/index.cjs79.js +1 -1
  160. package/dist/index.cjs79.js.map +1 -1
  161. package/dist/index.cjs8.js +1 -1
  162. package/dist/index.cjs8.js.map +1 -1
  163. package/dist/index.cjs80.js +1 -1
  164. package/dist/index.cjs80.js.map +1 -1
  165. package/dist/index.cjs81.js +1 -1
  166. package/dist/index.cjs81.js.map +1 -1
  167. package/dist/index.cjs82.js +1 -1
  168. package/dist/index.cjs82.js.map +1 -1
  169. package/dist/index.cjs83.js +1 -1
  170. package/dist/index.cjs83.js.map +1 -1
  171. package/dist/index.cjs84.js +1 -1
  172. package/dist/index.cjs84.js.map +1 -1
  173. package/dist/index.cjs85.js +1 -1
  174. package/dist/index.cjs85.js.map +1 -1
  175. package/dist/index.cjs86.js +1 -1
  176. package/dist/index.cjs86.js.map +1 -1
  177. package/dist/index.cjs87.js +1 -1
  178. package/dist/index.cjs87.js.map +1 -1
  179. package/dist/index.cjs88.js +4 -1
  180. package/dist/index.cjs88.js.map +1 -1
  181. package/dist/index.cjs89.js +1 -1
  182. package/dist/index.cjs89.js.map +1 -1
  183. package/dist/index.cjs9.js +1 -1
  184. package/dist/index.cjs9.js.map +1 -1
  185. package/dist/index.cjs90.js +1 -1
  186. package/dist/index.cjs90.js.map +1 -1
  187. package/dist/index.cjs91.js +1 -1
  188. package/dist/index.cjs91.js.map +1 -1
  189. package/dist/index.cjs92.js +1 -1
  190. package/dist/index.cjs92.js.map +1 -1
  191. package/dist/index.cjs93.js +1 -1
  192. package/dist/index.cjs93.js.map +1 -1
  193. package/dist/index.cjs94.js +38 -1
  194. package/dist/index.cjs94.js.map +1 -1
  195. package/dist/index.cjs95.js +1 -4
  196. package/dist/index.cjs95.js.map +1 -1
  197. package/dist/index.cjs96.js +1 -1
  198. package/dist/index.cjs96.js.map +1 -1
  199. package/dist/index.cjs97.js +1 -1
  200. package/dist/index.cjs97.js.map +1 -1
  201. package/dist/index.cjs98.js +1 -1
  202. package/dist/index.cjs98.js.map +1 -1
  203. package/dist/index.cjs99.js +1 -1
  204. package/dist/index.cjs99.js.map +1 -1
  205. package/dist/index.es10.js +46 -22
  206. package/dist/index.es10.js.map +1 -1
  207. package/dist/index.es100.js +22 -64
  208. package/dist/index.es100.js.map +1 -1
  209. package/dist/index.es101.js +12 -68
  210. package/dist/index.es101.js.map +1 -1
  211. package/dist/index.es102.js +26 -7
  212. package/dist/index.es102.js.map +1 -1
  213. package/dist/index.es103.js +5 -14
  214. package/dist/index.es103.js.map +1 -1
  215. package/dist/index.es11.js +57 -39
  216. package/dist/index.es11.js.map +1 -1
  217. package/dist/index.es12.js +23 -61
  218. package/dist/index.es12.js.map +1 -1
  219. package/dist/index.es13.js +126 -21
  220. package/dist/index.es13.js.map +1 -1
  221. package/dist/index.es14.js +12 -126
  222. package/dist/index.es14.js.map +1 -1
  223. package/dist/index.es15.js +132 -17
  224. package/dist/index.es15.js.map +1 -1
  225. package/dist/index.es16.js +133 -130
  226. package/dist/index.es16.js.map +1 -1
  227. package/dist/index.es17.js +43 -117
  228. package/dist/index.es17.js.map +1 -1
  229. package/dist/index.es18.js +9 -62
  230. package/dist/index.es18.js.map +1 -1
  231. package/dist/index.es19.js +23 -11
  232. package/dist/index.es19.js.map +1 -1
  233. package/dist/index.es2.js +5 -5
  234. package/dist/index.es2.js.map +1 -1
  235. package/dist/index.es20.js +422 -20
  236. package/dist/index.es20.js.map +1 -1
  237. package/dist/index.es21.js +5 -424
  238. package/dist/index.es21.js.map +1 -1
  239. package/dist/index.es22.js +13 -6
  240. package/dist/index.es22.js.map +1 -1
  241. package/dist/index.es23.js +10 -7
  242. package/dist/index.es23.js.map +1 -1
  243. package/dist/index.es24.js +7 -10
  244. package/dist/index.es24.js.map +1 -1
  245. package/dist/index.es25.js +12 -6
  246. package/dist/index.es25.js.map +1 -1
  247. package/dist/index.es26.js +4 -13
  248. package/dist/index.es26.js.map +1 -1
  249. package/dist/index.es27.js +19 -10
  250. package/dist/index.es27.js.map +1 -1
  251. package/dist/index.es28.js +22 -18
  252. package/dist/index.es28.js.map +1 -1
  253. package/dist/index.es29.js +13 -23
  254. package/dist/index.es29.js.map +1 -1
  255. package/dist/index.es3.js +206 -206
  256. package/dist/index.es3.js.map +1 -1
  257. package/dist/index.es30.js +17 -13
  258. package/dist/index.es30.js.map +1 -1
  259. package/dist/index.es31.js +14 -7
  260. package/dist/index.es31.js.map +1 -1
  261. package/dist/index.es32.js +2477 -2
  262. package/dist/index.es32.js.map +1 -1
  263. package/dist/index.es33.js +39 -24
  264. package/dist/index.es33.js.map +1 -1
  265. package/dist/index.es34.js +33 -602
  266. package/dist/index.es34.js.map +1 -1
  267. package/dist/index.es35.js +115 -16
  268. package/dist/index.es35.js.map +1 -1
  269. package/dist/index.es36.js +113 -14
  270. package/dist/index.es36.js.map +1 -1
  271. package/dist/index.es37.js +52 -2473
  272. package/dist/index.es37.js.map +1 -1
  273. package/dist/index.es38.js +23 -40
  274. package/dist/index.es38.js.map +1 -1
  275. package/dist/index.es39.js +45 -33
  276. package/dist/index.es39.js.map +1 -1
  277. package/dist/index.es4.js +5 -5
  278. package/dist/index.es4.js.map +1 -1
  279. package/dist/index.es40.js +79 -109
  280. package/dist/index.es40.js.map +1 -1
  281. package/dist/index.es41.js +49 -821
  282. package/dist/index.es41.js.map +1 -1
  283. package/dist/index.es42.js +832 -10
  284. package/dist/index.es42.js.map +1 -1
  285. package/dist/index.es43.js +3 -3
  286. package/dist/index.es43.js.map +1 -1
  287. package/dist/index.es44.js +3 -3
  288. package/dist/index.es44.js.map +1 -1
  289. package/dist/index.es45.js +10 -114
  290. package/dist/index.es45.js.map +1 -1
  291. package/dist/index.es46.js +122 -55
  292. package/dist/index.es46.js.map +1 -1
  293. package/dist/index.es47.js +62 -23
  294. package/dist/index.es47.js.map +1 -1
  295. package/dist/index.es48.js +21 -45
  296. package/dist/index.es48.js.map +1 -1
  297. package/dist/index.es49.js +9 -86
  298. package/dist/index.es49.js.map +1 -1
  299. package/dist/index.es5.js +62 -62
  300. package/dist/index.es5.js.map +1 -1
  301. package/dist/index.es50.js +37 -59
  302. package/dist/index.es50.js.map +1 -1
  303. package/dist/index.es51.js +17 -122
  304. package/dist/index.es51.js.map +1 -1
  305. package/dist/index.es52.js +7 -62
  306. package/dist/index.es52.js.map +1 -1
  307. package/dist/index.es53.js +5 -2
  308. package/dist/index.es53.js.map +1 -1
  309. package/dist/index.es54.js +255 -2
  310. package/dist/index.es54.js.map +1 -1
  311. package/dist/index.es55.js +21 -20
  312. package/dist/index.es55.js.map +1 -1
  313. package/dist/index.es56.js +27 -9
  314. package/dist/index.es56.js.map +1 -1
  315. package/dist/index.es57.js +7 -38
  316. package/dist/index.es57.js.map +1 -1
  317. package/dist/index.es58.js +66 -18
  318. package/dist/index.es58.js.map +1 -1
  319. package/dist/index.es59.js +29 -7
  320. package/dist/index.es59.js.map +1 -1
  321. package/dist/index.es6.js +37 -37
  322. package/dist/index.es6.js.map +1 -1
  323. package/dist/index.es60.js +5 -4
  324. package/dist/index.es60.js.map +1 -1
  325. package/dist/index.es61.js +24 -254
  326. package/dist/index.es61.js.map +1 -1
  327. package/dist/index.es62.js +32 -21
  328. package/dist/index.es62.js.map +1 -1
  329. package/dist/index.es63.js +3 -26
  330. package/dist/index.es63.js.map +1 -1
  331. package/dist/index.es64.js +44 -5
  332. package/dist/index.es64.js.map +1 -1
  333. package/dist/index.es65.js +7 -65
  334. package/dist/index.es65.js.map +1 -1
  335. package/dist/index.es66.js +121 -26
  336. package/dist/index.es66.js.map +1 -1
  337. package/dist/index.es67.js +14 -5
  338. package/dist/index.es67.js.map +1 -1
  339. package/dist/index.es68.js +133 -24
  340. package/dist/index.es68.js.map +1 -1
  341. package/dist/index.es69.js +10 -32
  342. package/dist/index.es69.js.map +1 -1
  343. package/dist/index.es7.js +33 -33
  344. package/dist/index.es7.js.map +1 -1
  345. package/dist/index.es70.js +215 -3
  346. package/dist/index.es70.js.map +1 -1
  347. package/dist/index.es71.js +13 -46
  348. package/dist/index.es71.js.map +1 -1
  349. package/dist/index.es72.js +7 -7
  350. package/dist/index.es72.js.map +1 -1
  351. package/dist/index.es73.js +4 -125
  352. package/dist/index.es73.js.map +1 -1
  353. package/dist/index.es74.js +28 -15
  354. package/dist/index.es74.js.map +1 -1
  355. package/dist/index.es75.js +48 -132
  356. package/dist/index.es75.js.map +1 -1
  357. package/dist/index.es76.js +9 -11
  358. package/dist/index.es76.js.map +1 -1
  359. package/dist/index.es77.js +65 -213
  360. package/dist/index.es77.js.map +1 -1
  361. package/dist/index.es78.js +12 -13
  362. package/dist/index.es78.js.map +1 -1
  363. package/dist/index.es79.js +204 -7
  364. package/dist/index.es79.js.map +1 -1
  365. package/dist/index.es8.js +87 -87
  366. package/dist/index.es8.js.map +1 -1
  367. package/dist/index.es80.js +22 -4
  368. package/dist/index.es80.js.map +1 -1
  369. package/dist/index.es81.js +391 -26
  370. package/dist/index.es81.js.map +1 -1
  371. package/dist/index.es82.js +24 -49
  372. package/dist/index.es82.js.map +1 -1
  373. package/dist/index.es83.js +28 -8
  374. package/dist/index.es83.js.map +1 -1
  375. package/dist/index.es84.js +5 -68
  376. package/dist/index.es84.js.map +1 -1
  377. package/dist/index.es85.js +5 -12
  378. package/dist/index.es85.js.map +1 -1
  379. package/dist/index.es86.js +3 -205
  380. package/dist/index.es86.js.map +1 -1
  381. package/dist/index.es87.js +23 -21
  382. package/dist/index.es87.js.map +1 -1
  383. package/dist/index.es88.js +105 -388
  384. package/dist/index.es88.js.map +1 -1
  385. package/dist/index.es89.js +14 -23
  386. package/dist/index.es89.js.map +1 -1
  387. package/dist/index.es9.js +23 -3
  388. package/dist/index.es9.js.map +1 -1
  389. package/dist/index.es90.js +521 -27
  390. package/dist/index.es90.js.map +1 -1
  391. package/dist/index.es91.js +127 -5
  392. package/dist/index.es91.js.map +1 -1
  393. package/dist/index.es92.js +129 -5
  394. package/dist/index.es92.js.map +1 -1
  395. package/dist/index.es93.js +65 -3
  396. package/dist/index.es93.js.map +1 -1
  397. package/dist/index.es94.js +69 -24
  398. package/dist/index.es94.js.map +1 -1
  399. package/dist/index.es95.js +9 -110
  400. package/dist/index.es95.js.map +1 -1
  401. package/dist/index.es96.js +14 -16
  402. package/dist/index.es96.js.map +1 -1
  403. package/dist/index.es97.js +60 -521
  404. package/dist/index.es97.js.map +1 -1
  405. package/dist/index.es98.js +3 -126
  406. package/dist/index.es98.js.map +1 -1
  407. package/dist/index.es99.js +22 -128
  408. package/dist/index.es99.js.map +1 -1
  409. package/package.json +1 -1
  410. package/dist/index.cjs104.js +0 -2
  411. package/dist/index.cjs104.js.map +0 -1
  412. package/dist/index.cjs105.js +0 -2
  413. package/dist/index.cjs105.js.map +0 -1
  414. package/dist/index.cjs106.js +0 -2
  415. package/dist/index.cjs106.js.map +0 -1
  416. package/dist/index.cjs107.js +0 -2
  417. package/dist/index.cjs107.js.map +0 -1
  418. package/dist/index.cjs108.js +0 -2
  419. package/dist/index.cjs108.js.map +0 -1
  420. package/dist/index.cjs109.js +0 -2
  421. package/dist/index.cjs109.js.map +0 -1
  422. package/dist/index.cjs110.js +0 -2
  423. package/dist/index.cjs110.js.map +0 -1
  424. package/dist/index.es104.js +0 -65
  425. package/dist/index.es104.js.map +0 -1
  426. package/dist/index.es105.js +0 -7
  427. package/dist/index.es105.js.map +0 -1
  428. package/dist/index.es106.js +0 -26
  429. package/dist/index.es106.js.map +0 -1
  430. package/dist/index.es107.js +0 -26
  431. package/dist/index.es107.js.map +0 -1
  432. package/dist/index.es108.js +0 -16
  433. package/dist/index.es108.js.map +0 -1
  434. package/dist/index.es109.js +0 -31
  435. package/dist/index.es109.js.map +0 -1
  436. package/dist/index.es110.js +0 -8
  437. package/dist/index.es110.js.map +0 -1
@@ -1,14 +1,26 @@
1
- import t from "ajv";
2
- const s = new t({ allErrors: !0 });
3
- function i(e) {
4
- const a = s.getSchema("http://json-schema.org/draft-07/schema#");
5
- if (!a?.(e)) {
6
- const o = a?.errors?.map((r) => `${r.instancePath} ${r.message}`).join(", ");
7
- throw new Error(`Schema validation error: ${o}`);
8
- }
9
- }
1
+ import { jsx as m } from "react/jsx-runtime";
2
+ import { forwardRef as c, useState as i, useEffect as d } from "react";
3
+ import { useDebounce as l } from "./index.es47.js";
4
+ import { Input as b } from "./index.es27.js";
5
+ const I = c(({ onDebounce: u, type: n, delay: r = 200, value: t, ...a }, p) => {
6
+ const [o, s] = i(t), [e] = l(o, r);
7
+ return d(() => {
8
+ typeof e == "string" && e !== t && u?.(e);
9
+ }, [e]), /* @__PURE__ */ m(
10
+ b,
11
+ {
12
+ ...a,
13
+ type: n,
14
+ value: o,
15
+ ref: p,
16
+ onChange: (f) => {
17
+ s(f.target.value);
18
+ }
19
+ }
20
+ );
21
+ });
22
+ I.displayName = "DebouncedInput";
10
23
  export {
11
- s as ajv,
12
- i as validateSchema
24
+ I as DebouncedInput
13
25
  };
14
26
  //# sourceMappingURL=index.es19.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.es19.js","sources":["../src/packages/builder/utils.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { faker } from \"@faker-js/faker\";\nimport Ajv from \"ajv\";\n\nimport type { JSONSchema7 } from \"json-schema\";\n\n// Export AJV instance for reuse\nexport const ajv = new Ajv({ allErrors: true });\n\n/**\n * Validates a JSON schema against the JSON Schema Draft 7 specification\n * @param schema Schema to validate\n * @throws Error if the schema is invalid\n */\nexport function validateSchema(schema: JSONSchema7) {\n const validate = ajv.getSchema(\"http://json-schema.org/draft-07/schema#\");\n const valid = validate?.(schema);\n\n if (!valid) {\n const errorMessages = validate?.errors\n ?.map((err) => `${err.instancePath} ${err.message}`)\n .join(\", \");\n\n throw new Error(`Schema validation error: ${errorMessages}`);\n }\n}\n\n// Test helpers\nexport const createTestSchema = (overrides = {}): JSONSchema7 => ({\n $schema: \"http://json-schema.org/draft-07/schema#\",\n type: \"object\",\n title: \"Test Schema\",\n properties: {\n name: {\n type: \"string\",\n title: \"Name\",\n },\n age: {\n type: \"integer\",\n title: \"Age\",\n },\n address: {\n type: \"object\",\n title: \"Address\",\n properties: {\n street: {\n type: \"string\",\n title: \"Street\",\n },\n city: {\n type: \"string\",\n title: \"City\",\n },\n },\n },\n tags: {\n type: \"array\",\n title: \"Tags\",\n items: {\n type: \"string\",\n },\n },\n },\n required: [\"name\"],\n ...overrides,\n});\n\ntype SampleDataType =\n | string\n | number\n | boolean\n | undefined\n | null\n | Record<string, any>;\n\n/**\n * Generate sample data for a JSON schema\n * @param schema JSON Schema to generate data for\n * @returns Sample data that conforms to the schema\n */\nexport const generateSampleData = (\n schema: JSONSchema7,\n): SampleDataType | SampleDataType[] => {\n if (!schema) return undefined;\n\n // Handle schema references (not implemented in this basic version)\n if (schema.$ref) {\n // In a complete implementation, this would resolve the reference\n return \"Reference not resolved\";\n }\n\n // Handle different types\n switch (schema.type) {\n case \"object\":\n return generateObjectData(schema);\n case \"array\":\n return generateArrayData(schema);\n case \"string\":\n return generateStringData(schema);\n case \"number\":\n case \"integer\":\n return generateNumberData(schema);\n case \"boolean\":\n return generateBooleanData();\n case \"null\":\n return null;\n default:\n // Handle schemas with multiple types or no type specified\n if (Array.isArray(schema.type) && schema.type.length > 0) {\n // Use the first type as default\n const primaryType = schema.type[0];\n const newSchema = { ...schema, type: primaryType };\n return generateSampleData(newSchema);\n }\n // If no type is specified, default to object\n if (schema.properties) {\n return generateObjectData({ ...schema, type: \"object\" });\n }\n // Fall back to a string if we can't determine the type\n return faker.lorem.word();\n }\n};\n\n/**\n * Generate sample data for an object schema\n */\nconst generateObjectData = (schema: JSONSchema7): Record<string, any> => {\n const result: Record<string, any> = {};\n\n if (!schema.properties) return result;\n\n // Process each property in the schema\n Object.entries(schema.properties).forEach(([key, propSchema]) => {\n // Only include required fields and some random non-required fields\n const isRequired =\n Array.isArray(schema.required) && schema.required.includes(key);\n const includeField = isRequired ?? Math.random() > 0.3; // 70% chance to include non-required fields\n\n if (includeField && typeof propSchema !== \"boolean\") {\n // Handle default values\n if (propSchema.default !== undefined) {\n result[key] = propSchema.default;\n } else {\n result[key] = generateSampleData(propSchema);\n }\n }\n });\n\n return result;\n};\n\n/**\n * Generate sample data for an array schema\n */\nconst generateArrayData = (schema: JSONSchema7) => {\n if (!schema.items) return [];\n\n // Determine array length\n const minItems = schema.minItems ?? 1;\n const maxItems = schema.maxItems ?? minItems + 3;\n const count = faker.number.int({ min: minItems, max: maxItems });\n\n const result = [];\n const itemSchema = Array.isArray(schema.items)\n ? schema.items[0]\n : schema.items;\n\n // Generate items\n if (typeof itemSchema !== \"boolean\" && itemSchema) {\n for (let i = 0; i < count; i++) {\n result.push(generateSampleData(itemSchema));\n }\n }\n\n return result;\n};\n\n/**\n * Generate sample data for a string schema\n */\nconst generateStringData = (schema: JSONSchema7): string => {\n if (schema.enum && Array.isArray(schema.enum)) {\n // Pick a random value from the enum\n return schema.enum[\n Math.floor(Math.random() * schema.enum.length)\n ] as string;\n }\n\n // Handle string formats\n if (schema.format) {\n switch (schema.format) {\n case \"email\":\n return faker.internet.email();\n case \"uri\":\n case \"url\":\n return faker.internet.url();\n case \"date\":\n return faker.date.past().toISOString().split(\"T\")[0]!;\n case \"date-time\":\n return faker.date.past().toISOString();\n case \"uuid\":\n return faker.string.uuid();\n case \"hostname\":\n return faker.internet.domainName();\n case \"ipv4\":\n return faker.internet.ip();\n case \"ipv6\":\n return faker.internet.ipv6();\n case \"phone\":\n return faker.phone.number();\n default:\n return faker.lorem.word();\n }\n }\n\n // Handle patterns\n if (schema.pattern) {\n try {\n // Basic implementation for simple patterns\n // For complex patterns, consider using a library like randexp\n if (schema.pattern.includes(\"\\\\d\")) {\n return faker.string.alphanumeric(10);\n }\n return faker.lorem.word();\n } catch {\n return faker.lorem.word();\n }\n }\n\n // Handle length constraints\n const minLength = schema.minLength ?? 3;\n const maxLength = schema.maxLength ?? 12;\n\n return faker.string.alphanumeric({\n length: { min: minLength, max: maxLength },\n });\n};\n\n/**\n * Generate sample data for a number schema\n */\nconst generateNumberData = (schema: JSONSchema7): number => {\n if (schema.enum && Array.isArray(schema.enum)) {\n return schema.enum[\n Math.floor(Math.random() * schema.enum.length)\n ] as number;\n }\n\n const isInteger = schema.type === \"integer\";\n const minimum =\n typeof schema.minimum === \"number\" ? schema.minimum : isInteger ? 0 : 0.0;\n const maximum =\n typeof schema.maximum === \"number\"\n ? schema.maximum\n : isInteger\n ? 100\n : 100.0;\n\n if (isInteger) {\n return faker.number.int({ min: minimum, max: maximum });\n }\n\n return faker.number.float({ min: minimum, max: maximum, fractionDigits: 2 });\n};\n\n/**\n * Generate sample data for a boolean schema\n */\nconst generateBooleanData = (): boolean => {\n return faker.datatype.boolean();\n};\n"],"names":["ajv","Ajv","validateSchema","schema","validate","errorMessages","err"],"mappings":";AAOO,MAAMA,IAAM,IAAIC,EAAI,EAAE,WAAW,GAAM,CAAA;AAOvC,SAASC,EAAeC,GAAqB;AAC5C,QAAAC,IAAWJ,EAAI,UAAU,yCAAyC;AAGxE,MAAI,CAFUI,IAAWD,CAAM,GAEnB;AACV,UAAME,IAAgBD,GAAU,QAC5B,IAAI,CAACE,MAAQ,GAAGA,EAAI,YAAY,IAAIA,EAAI,OAAO,EAAE,EAClD,KAAK,IAAI;AAEZ,UAAM,IAAI,MAAM,4BAA4BD,CAAa,EAAE;AAAA,EAAA;AAE/D;"}
1
+ {"version":3,"file":"index.es19.js","sources":["../src/components/depounced-input.tsx"],"sourcesContent":["import { forwardRef, useState, useEffect } from \"react\";\nimport { useDebounce } from \"use-debounce\";\nimport { Input } from \"@/components/ui/input\";\n\nexport const DebouncedInput = forwardRef<\n HTMLInputElement,\n React.ComponentProps<\"input\"> & {\n onDebounce?: (newVal: string) => void;\n delay?: number;\n }\n>(({ onDebounce, type, delay = 200, value, ...props }, ref) => {\n const [inputValue, setInputValue] = useState(value);\n\n const [debouncedValue] = useDebounce(inputValue, delay);\n\n useEffect(() => {\n //prevents the initial value from being sent\n if (typeof debouncedValue === \"string\" && debouncedValue !== value) {\n onDebounce?.(debouncedValue);\n }\n }, [debouncedValue]);\n\n return (\n <Input\n {...props}\n type={type}\n value={inputValue}\n ref={ref}\n onChange={(e) => {\n setInputValue(e.target.value);\n }}\n />\n );\n});\nDebouncedInput.displayName = \"DebouncedInput\";\n"],"names":["DebouncedInput","forwardRef","onDebounce","type","delay","value","props","ref","inputValue","setInputValue","useState","debouncedValue","useDebounce","useEffect","jsx","Input","e"],"mappings":";;;;AAIO,MAAMA,IAAiBC,EAM5B,CAAC,EAAE,YAAAC,GAAY,MAAAC,GAAM,OAAAC,IAAQ,KAAK,OAAAC,GAAO,GAAGC,EAAM,GAAGC,MAAQ;AAC7D,QAAM,CAACC,GAAYC,CAAa,IAAIC,EAASL,CAAK,GAE5C,CAACM,CAAc,IAAIC,EAAYJ,GAAYJ,CAAK;AAEtD,SAAAS,EAAU,MAAM;AAEd,IAAI,OAAOF,KAAmB,YAAYA,MAAmBN,KAC3DH,IAAaS,CAAc;AAAA,EAC7B,GACC,CAACA,CAAc,CAAC,GAGjB,gBAAAG;AAAA,IAACC;AAAA,IAAA;AAAA,MACE,GAAGT;AAAA,MACJ,MAAAH;AAAA,MACA,OAAOK;AAAA,MACP,KAAAD;AAAA,MACA,UAAU,CAACS,MAAM;AACD,QAAAP,EAAAO,EAAE,OAAO,KAAK;AAAA,MAAA;AAAA,IAC9B;AAAA,EACF;AAEJ,CAAC;AACDhB,EAAe,cAAc;"}
package/dist/index.es2.js CHANGED
@@ -1,6 +1,6 @@
1
- import { j as y } from "./index.es9.js";
1
+ import { jsx as y } from "react/jsx-runtime";
2
2
  import { createContext as q, useState as m, useContext as b } from "react";
3
- import { a as f } from "./index.es10.js";
3
+ import { a as f } from "./index.es9.js";
4
4
  const d = q(void 0), j = {
5
5
  $schema: "http://json-schema.org/draft-07/schema#",
6
6
  type: "object",
@@ -16,9 +16,9 @@ function B({
16
16
  const [n, a] = m(
17
17
  c ?? j
18
18
  ), [u, p] = m([]);
19
- return /* @__PURE__ */ y.jsx(d.Provider, { value: { schema: n, setSchema: a, path: u, setPath: p }, children: l });
19
+ return /* @__PURE__ */ y(d.Provider, { value: { schema: n, setSchema: a, path: u, setPath: p }, children: l });
20
20
  }
21
- function E() {
21
+ function D() {
22
22
  const l = b(d);
23
23
  if (l === void 0)
24
24
  throw new Error("useSchema must be used within a SchemaProvider");
@@ -103,6 +103,6 @@ function E() {
103
103
  export {
104
104
  d as SchemaContext,
105
105
  B as SchemaProvider,
106
- E as useSchema
106
+ D as useSchema
107
107
  };
108
108
  //# sourceMappingURL=index.es2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.es2.js","sources":["../src/packages/builder/context.tsx"],"sourcesContent":["import { createContext, useContext, useState } from \"react\";\n\nimport type { PropsWithChildren, SetStateAction } from \"react\";\nimport type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\nimport { clone } from \"remeda\";\nimport type { OperationError } from \"./shared-types\";\n\ninterface ContextState<T extends JSONSchema7> {\n schema: T;\n setSchema: React.Dispatch<T>;\n path: string[];\n setPath: React.Dispatch<SetStateAction<string[]>>;\n}\n\nexport const SchemaContext = createContext<\n ContextState<JSONSchema7> | undefined\n>(undefined);\n\nconst defaultSchema: JSONSchema7 = {\n $schema: \"http://json-schema.org/draft-07/schema#\",\n type: \"object\",\n title: \"title\",\n description: \"\",\n properties: {},\n required: [],\n};\n\nfunction SchemaProvider({\n children,\n initialSchema,\n}: PropsWithChildren<{ initialSchema?: JSONSchema7 }>) {\n const [schema, setSchema] = useState<JSONSchema7>(\n initialSchema ?? defaultSchema,\n );\n\n /**\n * Path represents the path to a nested property in the schema.\n * It should only contain property keys.\n * An empty path means the current schema is the root schema since\n * the path only represents nested properties.\n */\n const [path, setPath] = useState<string[]>([]);\n\n // NOTE: you *might* need to memoize your values\n // Learn more in http://kcd.im/optimize-context\n\n return (\n <SchemaContext.Provider value={{ schema, setSchema, path, setPath }}>\n {children}\n </SchemaContext.Provider>\n );\n}\n\nexport type PropertyAddError = OperationError & {\n status: \"error\";\n};\n\nexport interface PropertyAddSuccess {\n status: \"success\";\n property: JSONSchema7;\n}\n\nexport interface PropertyChangeSuccess {\n status: \"success\";\n property: JSONSchema7Definition;\n}\n\nfunction useSchema() {\n const context = useContext(SchemaContext);\n\n if (context === undefined) {\n throw new Error(\"useSchema must be used within a SchemaProvider\");\n }\n\n const { path, schema, setSchema } = context;\n\n /**\n * Navigates to the correct property schema of the latest key in the provided path.\n *\n * It will traverse both \"properties\" and \"items\" to find the correct property schema.\n *\n * It will only return a property schema if the provided path is valid i.e. it\n * correctly follows the schema's nesting structure.\n *\n * It will only return a parent schema if the provided path is valid i.e. it\n * correctly follows the schema's nesting structure.\n */\n const navigateToCorrectNesting = (\n providedSchema: JSONSchema7,\n providedPath: string[],\n ) => {\n let current = providedSchema;\n let propertySchema: JSONSchema7 | null = null;\n // Should be the schema of type \"object\" containing the property in its properties key\n let parentSchema: JSONSchema7 | null = null;\n\n for (const p of providedPath) {\n if (\n current.type === \"array\" &&\n current.items &&\n !Array.isArray(current.items) &&\n typeof current.items === \"object\" &&\n current.items.type === \"object\" &&\n typeof current.items.properties?.[p] === \"object\"\n ) {\n parentSchema = current.items;\n propertySchema = current.items.properties[p];\n current = current.items;\n } else if (\n current.type === \"object\" &&\n current.properties &&\n !Array.isArray(current.properties) &&\n typeof current.properties[p] === \"object\"\n ) {\n parentSchema = current;\n propertySchema = current.properties[p];\n current = current.properties[p];\n }\n }\n\n return { propertySchema, parentSchema };\n };\n\n /**\n * Gets the current schema of the latest key in the path.\n * If path is empty, it will return the root schema.\n *\n * It should always return the \"object\" schema of the current path.\n */\n const getCurrentSchema = (initialSchema?: JSONSchema7) => {\n // Gets the correct object schema if under nesting\n // Otherwise, return the root schema\n const { propertySchema } = navigateToCorrectNesting(\n initialSchema ?? schema,\n path,\n );\n\n if (propertySchema) {\n if (propertySchema.type === \"array\") {\n return propertySchema.items as JSONSchema7;\n }\n\n return propertySchema;\n }\n\n return initialSchema ?? schema;\n };\n\n /**\n * Gets the correct property schema of the latest key in the path.\n * If no path is provided, it will return null.\n */\n const getCurrentProperty = () => {\n const { propertySchema } = navigateToCorrectNesting(schema, path);\n\n return propertySchema;\n };\n\n /**\n * Change the key of a property in the schema. It expects\n * the find the key at the current path.\n */\n const handleKeyChange = (key: string, newKey: string) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to change\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n if (current.properties?.[key]) {\n //Important: maintain order as to not confuse users\n const newProperties = Object.entries(current.properties).map(\n ([k, val]) => {\n return [k === key ? newKey : k, val];\n },\n );\n\n current.properties = Object.fromEntries(\n newProperties,\n ) as JSONSchema7[\"properties\"];\n }\n\n if (current.required?.includes(key)) {\n current.required = current.required.map((item) =>\n item === key ? newKey : item,\n );\n }\n\n setSchema(newSchema);\n };\n\n const handlePropertyChange = (\n key: string,\n updates: Partial<JSONSchema7Definition> & { isRequired?: boolean },\n ): PropertyChangeSuccess | undefined => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to change\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Handle required field updates\n if (typeof updates === \"object\" && \"isRequired\" in updates) {\n if (current.type === \"object\") {\n if (!current.required) {\n current.required = [];\n }\n if (updates.isRequired) {\n if (!current.required.includes(key)) {\n current.required.push(key);\n }\n } else {\n current.required = current.required.filter((item) => item !== key);\n }\n }\n delete updates.isRequired;\n }\n\n let isUpdated = false;\n\n // Update the property\n if (current.type === \"object\" && current.properties) {\n const originalProperty = current.properties[key];\n // Ensure the property exists and is not a boolean\n if (typeof originalProperty !== \"boolean\" && originalProperty) {\n if (typeof updates !== \"boolean\") {\n //if updates changes the type of the property,\n //only the title, description, and default properties should remain\n //from the original property\n if (updates.type && updates.type !== originalProperty.type) {\n updates = {\n title: originalProperty.title,\n description: originalProperty.description,\n default: originalProperty.default,\n ...updates,\n };\n } else if (updates.enum) {\n //if the property is an enum, only the title and description should remain\n //from the original property\n delete updates.type;\n delete updates.items;\n delete updates.properties;\n updates = {\n title: originalProperty.title,\n description: originalProperty.description,\n ...updates,\n };\n } else {\n updates = { ...originalProperty, ...updates };\n }\n\n current.properties[key] = updates;\n }\n }\n isUpdated = true;\n }\n\n setSchema(newSchema);\n\n if (isUpdated) {\n return { status: \"success\", property: current.properties![key]! };\n }\n };\n\n /**\n * Adds a sibling property to the current schema.\n */\n const handleAddProperty = (\n key: string,\n propertyToAdd: JSONSchema7,\n isRequired: boolean,\n ) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to add\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Ensure the current schema has a properties object\n if (current.type !== \"object\") {\n current.type = \"object\";\n }\n if (!current.properties) {\n current.properties = {};\n }\n\n //Ensure there's no existing property with the same key\n if (current.properties[key]) {\n return {\n status: \"error\",\n code: \"key-exists\" as const,\n message: `Property with key ${key} already exists`,\n } satisfies PropertyAddError;\n }\n\n if (propertyToAdd.enum) {\n //ensure that only the enum property is present\n delete propertyToAdd.type;\n delete propertyToAdd.items;\n delete propertyToAdd.properties;\n }\n\n // Add the new property\n current.properties[key] = propertyToAdd;\n\n // Handle required field\n if (isRequired) {\n if (!current.required) {\n current.required = [];\n }\n if (!current.required.includes(key)) {\n current.required.push(key);\n }\n }\n\n setSchema(newSchema);\n\n return {\n status: \"success\" as const,\n property: current.properties[key],\n } satisfies PropertyAddSuccess;\n };\n\n const handleDeleteProperty = (key: string) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to delete\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Handle required field updates\n if (current.type === \"object\") {\n if (current.required) {\n current.required = current.required.filter((item) => item !== key);\n }\n }\n\n // Delete the property\n if (current.type === \"object\" && current.properties) {\n delete current.properties[key];\n }\n\n setSchema(newSchema);\n };\n\n // const handleDuplicateProperty = (key: string) => {\n // const currentProperties = getCurrentSchema().properties;\n // if (!currentProperties || typeof currentProperties[key] === \"boolean\") {\n // return;\n // }\n\n // const propertyToDuplicate = currentProperties[key]!;\n // const newKey = `${key}_copy`;\n // const newProperty = clone(propertyToDuplicate);\n\n // // Add the duplicated property\n // const result = handleAddProperty(\n // newKey,\n // newProperty,\n // isPropertyRequired(key),\n // );\n\n // // Notify if needed\n // if (result.status === \"error\") {\n // props.onPropertyAddError?.(result);\n // } else {\n // props.onPropertyAddSuccess?.(result);\n // }\n // };\n\n const isPropertyRequired = (key: string) => {\n if (path.length) {\n const { propertySchema } = navigateToCorrectNesting(schema, path);\n\n if (\n propertySchema?.type === \"array\" &&\n propertySchema.items &&\n typeof propertySchema.items !== \"boolean\" &&\n !Array.isArray(propertySchema.items) &&\n propertySchema.items?.type === \"object\"\n ) {\n return Boolean(propertySchema.items?.required?.includes(key));\n } else {\n return Boolean(propertySchema?.required?.includes(key));\n }\n }\n\n return Boolean(schema?.required?.includes(key));\n };\n\n return {\n ...context,\n getCurrentSchema,\n getCurrentProperty,\n handlePropertyChange,\n handleAddProperty,\n handleKeyChange,\n navigateToCorrectNesting,\n handleDeleteProperty,\n isPropertyRequired,\n };\n}\n\nexport { SchemaProvider, useSchema };\n"],"names":["SchemaContext","createContext","defaultSchema","SchemaProvider","children","initialSchema","schema","setSchema","useState","path","setPath","jsx","useSchema","context","useContext","navigateToCorrectNesting","providedSchema","providedPath","current","propertySchema","parentSchema","p","getCurrentSchema","key","updates","newSchema","clone","item","isUpdated","originalProperty","propertyToAdd","isRequired","newKey","newProperties","k","val"],"mappings":";;;AAca,MAAAA,IAAgBC,EAE3B,MAAS,GAELC,IAA6B;AAAA,EACjC,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,YAAY,CAAC;AAAA,EACb,UAAU,CAAA;AACZ;AAEA,SAASC,EAAe;AAAA,EACtB,UAAAC;AAAA,EACA,eAAAC;AACF,GAAuD;AAC/C,QAAA,CAACC,GAAQC,CAAS,IAAIC;AAAA,IAC1BH,KAAiBH;AAAA,EACnB,GAQM,CAACO,GAAMC,CAAO,IAAIF,EAAmB,CAAA,CAAE;AAM3C,SAAAG,gBAAAA,MAACX,EAAc,UAAd,EAAuB,OAAO,EAAE,QAAAM,GAAQ,WAAAC,GAAW,MAAAE,GAAM,SAAAC,EAAQ,GAC/D,UAAAN,EACH,CAAA;AAEJ;AAgBA,SAASQ,IAAY;AACb,QAAAC,IAAUC,EAAWd,CAAa;AAExC,MAAIa,MAAY;AACR,UAAA,IAAI,MAAM,gDAAgD;AAGlE,QAAM,EAAE,MAAAJ,GAAM,QAAAH,GAAQ,WAAAC,EAAc,IAAAM,GAa9BE,IAA2B,CAC/BC,GACAC,MACG;AACH,QAAIC,IAAUF,GACVG,IAAqC,MAErCC,IAAmC;AAEvC,eAAWC,KAAKJ;AAEZ,MAAAC,EAAQ,SAAS,WACjBA,EAAQ,SACR,CAAC,MAAM,Q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AAQA,EAAe,OAAO,UAAU,SAASI,CAAG,IAEpD,EAAQJ,GAAgB,UAAU,SAASI,CAAG;AAAA,MACvD;AAGF,aAAO,EAAQjB,GAAQ,UAAU,SAASiB,CAAG;AAAA,IAC/C;AAAA,EAYA;AACF;"}
1
+ {"version":3,"file":"index.es2.js","sources":["../src/packages/builder/context.tsx"],"sourcesContent":["import { createContext, useContext, useState } from \"react\";\n\nimport type { PropsWithChildren, SetStateAction } from \"react\";\nimport type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\nimport { clone } from \"remeda\";\nimport type { OperationError } from \"./shared-types\";\n\ninterface ContextState<T extends JSONSchema7> {\n schema: T;\n setSchema: React.Dispatch<T>;\n path: string[];\n setPath: React.Dispatch<SetStateAction<string[]>>;\n}\n\nexport const SchemaContext = createContext<\n ContextState<JSONSchema7> | undefined\n>(undefined);\n\nconst defaultSchema: JSONSchema7 = {\n $schema: \"http://json-schema.org/draft-07/schema#\",\n type: \"object\",\n title: \"title\",\n description: \"\",\n properties: {},\n required: [],\n};\n\nfunction SchemaProvider({\n children,\n initialSchema,\n}: PropsWithChildren<{ initialSchema?: JSONSchema7 }>) {\n const [schema, setSchema] = useState<JSONSchema7>(\n initialSchema ?? defaultSchema,\n );\n\n /**\n * Path represents the path to a nested property in the schema.\n * It should only contain property keys.\n * An empty path means the current schema is the root schema since\n * the path only represents nested properties.\n */\n const [path, setPath] = useState<string[]>([]);\n\n // NOTE: you *might* need to memoize your values\n // Learn more in http://kcd.im/optimize-context\n\n return (\n <SchemaContext.Provider value={{ schema, setSchema, path, setPath }}>\n {children}\n </SchemaContext.Provider>\n );\n}\n\nexport type PropertyAddError = OperationError & {\n status: \"error\";\n};\n\nexport interface PropertyAddSuccess {\n status: \"success\";\n property: JSONSchema7;\n}\n\nexport interface PropertyChangeSuccess {\n status: \"success\";\n property: JSONSchema7Definition;\n}\n\nfunction useSchema() {\n const context = useContext(SchemaContext);\n\n if (context === undefined) {\n throw new Error(\"useSchema must be used within a SchemaProvider\");\n }\n\n const { path, schema, setSchema } = context;\n\n /**\n * Navigates to the correct property schema of the latest key in the provided path.\n *\n * It will traverse both \"properties\" and \"items\" to find the correct property schema.\n *\n * It will only return a property schema if the provided path is valid i.e. it\n * correctly follows the schema's nesting structure.\n *\n * It will only return a parent schema if the provided path is valid i.e. it\n * correctly follows the schema's nesting structure.\n */\n const navigateToCorrectNesting = (\n providedSchema: JSONSchema7,\n providedPath: string[],\n ) => {\n let current = providedSchema;\n let propertySchema: JSONSchema7 | null = null;\n // Should be the schema of type \"object\" containing the property in its properties key\n let parentSchema: JSONSchema7 | null = null;\n\n for (const p of providedPath) {\n if (\n current.type === \"array\" &&\n current.items &&\n !Array.isArray(current.items) &&\n typeof current.items === \"object\" &&\n current.items.type === \"object\" &&\n typeof current.items.properties?.[p] === \"object\"\n ) {\n parentSchema = current.items;\n propertySchema = current.items.properties[p];\n current = current.items;\n } else if (\n current.type === \"object\" &&\n current.properties &&\n !Array.isArray(current.properties) &&\n typeof current.properties[p] === \"object\"\n ) {\n parentSchema = current;\n propertySchema = current.properties[p];\n current = current.properties[p];\n }\n }\n\n return { propertySchema, parentSchema };\n };\n\n /**\n * Gets the current schema of the latest key in the path.\n * If path is empty, it will return the root schema.\n *\n * It should always return the \"object\" schema of the current path.\n */\n const getCurrentSchema = (initialSchema?: JSONSchema7) => {\n // Gets the correct object schema if under nesting\n // Otherwise, return the root schema\n const { propertySchema } = navigateToCorrectNesting(\n initialSchema ?? schema,\n path,\n );\n\n if (propertySchema) {\n if (propertySchema.type === \"array\") {\n return propertySchema.items as JSONSchema7;\n }\n\n return propertySchema;\n }\n\n return initialSchema ?? schema;\n };\n\n /**\n * Gets the correct property schema of the latest key in the path.\n * If no path is provided, it will return null.\n */\n const getCurrentProperty = () => {\n const { propertySchema } = navigateToCorrectNesting(schema, path);\n\n return propertySchema;\n };\n\n /**\n * Change the key of a property in the schema. It expects\n * the find the key at the current path.\n */\n const handleKeyChange = (key: string, newKey: string) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to change\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n if (current.properties?.[key]) {\n //Important: maintain order as to not confuse users\n const newProperties = Object.entries(current.properties).map(\n ([k, val]) => {\n return [k === key ? newKey : k, val];\n },\n );\n\n current.properties = Object.fromEntries(\n newProperties,\n ) as JSONSchema7[\"properties\"];\n }\n\n if (current.required?.includes(key)) {\n current.required = current.required.map((item) =>\n item === key ? newKey : item,\n );\n }\n\n setSchema(newSchema);\n };\n\n const handlePropertyChange = (\n key: string,\n updates: Partial<JSONSchema7Definition> & { isRequired?: boolean },\n ): PropertyChangeSuccess | undefined => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to change\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Handle required field updates\n if (typeof updates === \"object\" && \"isRequired\" in updates) {\n if (current.type === \"object\") {\n if (!current.required) {\n current.required = [];\n }\n if (updates.isRequired) {\n if (!current.required.includes(key)) {\n current.required.push(key);\n }\n } else {\n current.required = current.required.filter((item) => item !== key);\n }\n }\n delete updates.isRequired;\n }\n\n let isUpdated = false;\n\n // Update the property\n if (current.type === \"object\" && current.properties) {\n const originalProperty = current.properties[key];\n // Ensure the property exists and is not a boolean\n if (typeof originalProperty !== \"boolean\" && originalProperty) {\n if (typeof updates !== \"boolean\") {\n //if updates changes the type of the property,\n //only the title, description, and default properties should remain\n //from the original property\n if (updates.type && updates.type !== originalProperty.type) {\n updates = {\n title: originalProperty.title,\n description: originalProperty.description,\n default: originalProperty.default,\n ...updates,\n };\n } else if (updates.enum) {\n //if the property is an enum, only the title and description should remain\n //from the original property\n delete updates.type;\n delete updates.items;\n delete updates.properties;\n updates = {\n title: originalProperty.title,\n description: originalProperty.description,\n ...updates,\n };\n } else {\n updates = { ...originalProperty, ...updates };\n }\n\n current.properties[key] = updates;\n }\n }\n isUpdated = true;\n }\n\n setSchema(newSchema);\n\n if (isUpdated) {\n return { status: \"success\", property: current.properties![key]! };\n }\n };\n\n /**\n * Adds a sibling property to the current schema.\n */\n const handleAddProperty = (\n key: string,\n propertyToAdd: JSONSchema7,\n isRequired: boolean,\n ) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to add\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Ensure the current schema has a properties object\n if (current.type !== \"object\") {\n current.type = \"object\";\n }\n if (!current.properties) {\n current.properties = {};\n }\n\n //Ensure there's no existing property with the same key\n if (current.properties[key]) {\n return {\n status: \"error\",\n code: \"key-exists\" as const,\n message: `Property with key ${key} already exists`,\n } satisfies PropertyAddError;\n }\n\n if (propertyToAdd.enum) {\n //ensure that only the enum property is present\n delete propertyToAdd.type;\n delete propertyToAdd.items;\n delete propertyToAdd.properties;\n }\n\n // Add the new property\n current.properties[key] = propertyToAdd;\n\n // Handle required field\n if (isRequired) {\n if (!current.required) {\n current.required = [];\n }\n if (!current.required.includes(key)) {\n current.required.push(key);\n }\n }\n\n setSchema(newSchema);\n\n return {\n status: \"success\" as const,\n property: current.properties[key],\n } satisfies PropertyAddSuccess;\n };\n\n const handleDeleteProperty = (key: string) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to delete\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Handle required field updates\n if (current.type === \"object\") {\n if (current.required) {\n current.required = current.required.filter((item) => item !== key);\n }\n }\n\n // Delete the property\n if (current.type === \"object\" && current.properties) {\n delete current.properties[key];\n }\n\n setSchema(newSchema);\n };\n\n // const handleDuplicateProperty = (key: string) => {\n // const currentProperties = getCurrentSchema().properties;\n // if (!currentProperties || typeof currentProperties[key] === \"boolean\") {\n // return;\n // }\n\n // const propertyToDuplicate = currentProperties[key]!;\n // const newKey = `${key}_copy`;\n // const newProperty = clone(propertyToDuplicate);\n\n // // Add the duplicated property\n // const result = handleAddProperty(\n // newKey,\n // newProperty,\n // isPropertyRequired(key),\n // );\n\n // // Notify if needed\n // if (result.status === \"error\") {\n // props.onPropertyAddError?.(result);\n // } else {\n // props.onPropertyAddSuccess?.(result);\n // }\n // };\n\n const isPropertyRequired = (key: string) => {\n if (path.length) {\n const { propertySchema } = navigateToCorrectNesting(schema, path);\n\n if (\n propertySchema?.type === \"array\" &&\n propertySchema.items &&\n typeof propertySchema.items !== \"boolean\" &&\n !Array.isArray(propertySchema.items) &&\n propertySchema.items?.type === \"object\"\n ) {\n return Boolean(propertySchema.items?.required?.includes(key));\n } else {\n return Boolean(propertySchema?.required?.includes(key));\n }\n }\n\n return Boolean(schema?.required?.includes(key));\n };\n\n return {\n ...context,\n getCurrentSchema,\n getCurrentProperty,\n handlePropertyChange,\n handleAddProperty,\n handleKeyChange,\n navigateToCorrectNesting,\n handleDeleteProperty,\n isPropertyRequired,\n };\n}\n\nexport { SchemaProvider, useSchema };\n"],"names":["SchemaContext","createContext","defaultSchema","SchemaProvider","children","initialSchema","schema","setSchema","useState","path","setPath","jsx","useSchema","context","useContext","navigateToCorrectNesting","providedSchema","providedPath","current","propertySchema","parentSchema","p","getCurrentSchema","key","updates","newSchema","clone","item","isUpdated","originalProperty","propertyToAdd","isRequired","newKey","newProperties","k","val"],"mappings":";;;AAca,MAAAA,IAAgBC,EAE3B,MAAS,GAELC,IAA6B;AAAA,EACjC,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,YAAY,CAAC;AAAA,EACb,UAAU,CAAA;AACZ;AAEA,SAASC,EAAe;AAAA,EACtB,UAAAC;AAAA,EACA,eAAAC;AACF,GAAuD;AAC/C,QAAA,CAACC,GAAQC,CAAS,IAAIC;AAAA,IAC1BH,KAAiBH;AAAA,EACnB,GAQM,CAACO,GAAMC,CAAO,IAAIF,EAAmB,CAAA,CAAE;AAM3C,SAAA,gBAAAG,EAACX,EAAc,UAAd,EAAuB,OAAO,EAAE,QAAAM,GAAQ,WAAAC,GAAW,MAAAE,GAAM,SAAAC,EAAQ,GAC/D,UAAAN,EACH,CAAA;AAEJ;AAgBA,SAASQ,IAAY;AACb,QAAAC,IAAUC,EAAWd,C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hB,EAAUkB,CAAS;AAAA,IACrB;AAAA,IAwDE,oBA7ByB,CAACF,MAAgB;AAC1C,UAAId,EAAK,QAAQ;AACf,cAAM,EAAE,gBAAAU,EAAmB,IAAAJ,EAAyBT,GAAQG,CAAI;AAEhE,eACEU,GAAgB,SAAS,WACzBA,EAAe,SACf,OAAOA,EAAe,SAAU,aAChC,CAAC,MAAM,QAAQA,EAAe,KAAK,KACnCA,EAAe,OAAO,SAAS,WAExB,EAAQA,EAAe,OAAO,UAAU,SAASI,CAAG,IAEpD,EAAQJ,GAAgB,UAAU,SAASI,CAAG;AAAA,MACvD;AAGF,aAAO,EAAQjB,GAAQ,UAAU,SAASiB,CAAG;AAAA,IAC/C;AAAA,EAYA;AACF;"}
@@ -1,26 +1,428 @@
1
- import { j as m } from "./index.es9.js";
2
- import { forwardRef as i, useState as c, useEffect as d } from "react";
3
- import { useDebounce as l } from "./index.es52.js";
4
- import { Input as b } from "./index.es28.js";
5
- const x = i(({ onDebounce: u, type: n, delay: r = 200, value: t, ...s }, a) => {
6
- const [o, p] = c(t), [e] = l(o, r);
7
- return d(() => {
8
- typeof e == "string" && e !== t && u?.(e);
9
- }, [e]), /* @__PURE__ */ m.jsx(
10
- b,
11
- {
12
- ...s,
13
- type: n,
14
- value: o,
15
- ref: a,
16
- onChange: (f) => {
17
- p(f.target.value);
1
+ import { jsx as e, jsxs as i } from "react/jsx-runtime";
2
+ import { Button as x } from "./index.es10.js";
3
+ import { zodResolver as K } from "./index.es39.js";
4
+ import { Dialog as M, DialogContent as _, DialogHeader as B, DialogTitle as H, DialogDescription as J, DialogFooter as G } from "./index.es36.js";
5
+ import { Input as O } from "./index.es27.js";
6
+ import { Label as Q } from "./index.es14.js";
7
+ import { Select as A, SelectTrigger as j, SelectValue as F, SelectContent as N, SelectItem as s } from "./index.es13.js";
8
+ import { Switch as U } from "./index.es12.js";
9
+ import { DebouncedInput as V } from "./index.es19.js";
10
+ import { a as f } from "./index.es9.js";
11
+ import W from "./index.es41.js";
12
+ import { useConstraints as X } from "./index.es4.js";
13
+ import Y from "./index.es37.js";
14
+ import { Separator as Z } from "./index.es38.js";
15
+ import { z as t } from "zod";
16
+ import { useForm as ee } from "react-hook-form";
17
+ import { Form as re, FormField as u, FormItem as d, FormLabel as p, FormControl as h, FormMessage as y } from "./index.es40.js";
18
+ const g = t.enum([
19
+ "string",
20
+ "number",
21
+ "integer",
22
+ "boolean",
23
+ "object",
24
+ "array",
25
+ "null"
26
+ ]), ne = t.object({
27
+ key: t.string().trim().min(1, { message: "Key must be at least 1 character long" }),
28
+ property: t.object({
29
+ title: t.string().trim().min(1, { message: "Title must be at least 1 character long" }),
30
+ type: g.or(t.array(g)),
31
+ description: t.string().optional(),
32
+ enum: t.array(
33
+ t.string().or(t.number()).or(t.null()).or(t.boolean()).or(t.record(t.string(), t.any()))
34
+ ).optional(),
35
+ items: t.object({
36
+ type: g.or(t.array(g))
37
+ }).or(
38
+ t.array(
39
+ t.object({ type: g.or(t.array(g)) }).or(t.boolean())
40
+ )
41
+ ).or(t.boolean()).optional()
42
+ }),
43
+ required: t.boolean().default(!1),
44
+ constraints: t.array(
45
+ t.custom(() => ({
46
+ name: t.string().trim().min(1),
47
+ value: t.any()
48
+ }))
49
+ ).optional()
50
+ });
51
+ function Ce({
52
+ open: T,
53
+ onOpenChange: E,
54
+ onSubmit: R
55
+ }) {
56
+ const n = ee({
57
+ resolver: K(ne),
58
+ defaultValues: {
59
+ key: "",
60
+ property: {
61
+ title: ""
18
62
  }
19
63
  }
64
+ }), v = n.watch("constraints"), C = n.watch("property"), I = n.watch("property.enum"), w = n.watch("property.type"), {
65
+ getConstraintDefinitionsForType: k,
66
+ getRendererForConstraint: q,
67
+ validateConstraintValue: P
68
+ } = X(), $ = (r) => {
69
+ const { key: o, property: a, required: l, constraints: c } = r, m = {
70
+ ...a,
71
+ ...c?.reduce((b, D) => ({
72
+ ...b,
73
+ [D.name]: D.value
74
+ }), {})
75
+ };
76
+ R(o, m, l), n.reset();
77
+ }, z = (r, o) => {
78
+ const a = f(v), l = a?.[r];
79
+ if (!l) {
80
+ n.setError(`constraints.${r}`, {
81
+ message: "The constraint was not found",
82
+ type: "constraint_not_found"
83
+ });
84
+ return;
85
+ }
86
+ const c = P(
87
+ l.name,
88
+ o
89
+ );
90
+ if (c.status === "error") {
91
+ let m = c.message;
92
+ c.code === "invalid" && (m = `${m}: ${c.error?.map((b) => b.message).join(", ")}`), n.setError(`constraints.${r}`, {
93
+ type: c.code,
94
+ message: m
95
+ });
96
+ return;
97
+ }
98
+ l.value = o, n.setValue("constraints", a), n.clearErrors(`constraints.${r}`);
99
+ }, L = (r) => {
100
+ if (!v) return;
101
+ const a = f(v).filter((l) => l.name !== r);
102
+ n.setValue("constraints", a);
103
+ }, S = k(
104
+ typeof C?.type == "string" ? C.type : ""
20
105
  );
21
- });
22
- x.displayName = "DebouncedInput";
106
+ return /* @__PURE__ */ e(M, { open: T, onOpenChange: E, children: /* @__PURE__ */ i(_, { "data-testid": "add-property-dialog", children: [
107
+ /* @__PURE__ */ i(B, { children: [
108
+ /* @__PURE__ */ e(H, { children: "Add" }),
109
+ /* @__PURE__ */ e(J, { children: "Required property values and constraints" })
110
+ ] }),
111
+ /* @__PURE__ */ e(re, { ...n, children: /* @__PURE__ */ i(
112
+ "form",
113
+ {
114
+ onSubmit: n.handleSubmit($),
115
+ className: "space-y-4",
116
+ "data-testid": "add-property-form",
117
+ children: [
118
+ /* @__PURE__ */ e("div", { className: "space-y-2", children: /* @__PURE__ */ e(
119
+ u,
120
+ {
121
+ control: n.control,
122
+ name: "key",
123
+ render: ({ field: r }) => {
124
+ const { onChange: o, ...a } = r;
125
+ return /* @__PURE__ */ i(d, { children: [
126
+ /* @__PURE__ */ e(p, { children: "Property Key" }),
127
+ /* @__PURE__ */ e(h, { children: /* @__PURE__ */ e(
128
+ V,
129
+ {
130
+ ...a,
131
+ onDebounce: (l) => o(l)
132
+ }
133
+ ) }),
134
+ /* @__PURE__ */ e(y, {})
135
+ ] });
136
+ }
137
+ }
138
+ ) }),
139
+ /* @__PURE__ */ e("div", { className: "space-y-2", children: /* @__PURE__ */ e(
140
+ u,
141
+ {
142
+ control: n.control,
143
+ name: "property.title",
144
+ render: ({ field: r }) => {
145
+ const { onChange: o, ...a } = r;
146
+ return /* @__PURE__ */ i(d, { children: [
147
+ /* @__PURE__ */ e(p, { children: "Property Title" }),
148
+ /* @__PURE__ */ e(h, { children: /* @__PURE__ */ e(
149
+ V,
150
+ {
151
+ ...a,
152
+ onDebounce: (l) => o(l)
153
+ }
154
+ ) }),
155
+ /* @__PURE__ */ e(y, {})
156
+ ] });
157
+ }
158
+ }
159
+ ) }),
160
+ /* @__PURE__ */ e("div", { className: "space-y-2", children: /* @__PURE__ */ e(
161
+ u,
162
+ {
163
+ control: n.control,
164
+ name: "property.type",
165
+ render: ({ field: r }) => /* @__PURE__ */ i(d, { children: [
166
+ /* @__PURE__ */ e(p, { children: "Type" }),
167
+ /* @__PURE__ */ e(h, { children: /* @__PURE__ */ i(
168
+ A,
169
+ {
170
+ value: Array.isArray(r.value) ? void 0 : r.value,
171
+ onValueChange: (o) => {
172
+ o === "enum" ? n.setValue("property.enum", []) : n.setValue("property.enum", void 0), r.value === "array" && o !== "array" && (n.clearErrors("property.items"), n.setValue("property.items", void 0)), r.onChange(o);
173
+ },
174
+ children: [
175
+ /* @__PURE__ */ e(
176
+ j,
177
+ {
178
+ className: "w-full",
179
+ "aria-label": "Select type",
180
+ children: /* @__PURE__ */ e(F, {})
181
+ }
182
+ ),
183
+ /* @__PURE__ */ i(N, { children: [
184
+ /* @__PURE__ */ e(
185
+ s,
186
+ {
187
+ value: "string",
188
+ children: "string"
189
+ }
190
+ ),
191
+ /* @__PURE__ */ e(
192
+ s,
193
+ {
194
+ value: "number",
195
+ children: "number"
196
+ }
197
+ ),
198
+ /* @__PURE__ */ e(
199
+ s,
200
+ {
201
+ value: "integer",
202
+ children: "integer"
203
+ }
204
+ ),
205
+ /* @__PURE__ */ e(
206
+ s,
207
+ {
208
+ value: "boolean",
209
+ children: "boolean"
210
+ }
211
+ ),
212
+ /* @__PURE__ */ e(
213
+ s,
214
+ {
215
+ value: "object",
216
+ children: "object"
217
+ }
218
+ ),
219
+ /* @__PURE__ */ e(
220
+ s,
221
+ {
222
+ value: "array",
223
+ children: "array"
224
+ }
225
+ ),
226
+ /* @__PURE__ */ e(
227
+ s,
228
+ {
229
+ value: "null",
230
+ children: "null"
231
+ }
232
+ )
233
+ ] })
234
+ ]
235
+ }
236
+ ) }),
237
+ /* @__PURE__ */ e(y, {})
238
+ ] })
239
+ }
240
+ ) }),
241
+ w === "array" && /* @__PURE__ */ e("div", { className: "space-y-2", children: /* @__PURE__ */ e(
242
+ u,
243
+ {
244
+ control: n.control,
245
+ name: "property.items.type",
246
+ render: ({ field: r }) => /* @__PURE__ */ i(d, { children: [
247
+ /* @__PURE__ */ e(p, { children: "Items of type" }),
248
+ /* @__PURE__ */ e(h, { children: /* @__PURE__ */ i(
249
+ A,
250
+ {
251
+ value: Array.isArray(r.value) ? void 0 : r.value,
252
+ onValueChange: (o) => {
253
+ n.clearErrors("property.items.type"), n.setValue(
254
+ "property.items.type",
255
+ o
256
+ );
257
+ },
258
+ children: [
259
+ /* @__PURE__ */ e(
260
+ j,
261
+ {
262
+ className: "w-full",
263
+ "aria-label": "Select items of type",
264
+ children: /* @__PURE__ */ e(F, { placeholder: "Select item type" })
265
+ }
266
+ ),
267
+ /* @__PURE__ */ i(N, { children: [
268
+ /* @__PURE__ */ e(
269
+ s,
270
+ {
271
+ value: "string",
272
+ children: "string"
273
+ }
274
+ ),
275
+ /* @__PURE__ */ e(
276
+ s,
277
+ {
278
+ value: "number",
279
+ children: "number"
280
+ }
281
+ ),
282
+ /* @__PURE__ */ e(
283
+ s,
284
+ {
285
+ value: "integer",
286
+ children: "integer"
287
+ }
288
+ ),
289
+ /* @__PURE__ */ e(
290
+ s,
291
+ {
292
+ value: "boolean",
293
+ children: "boolean"
294
+ }
295
+ ),
296
+ /* @__PURE__ */ e(
297
+ s,
298
+ {
299
+ value: "object",
300
+ children: "object"
301
+ }
302
+ ),
303
+ /* @__PURE__ */ e(
304
+ s,
305
+ {
306
+ value: "array",
307
+ children: "array"
308
+ }
309
+ ),
310
+ /* @__PURE__ */ e(
311
+ s,
312
+ {
313
+ value: "null",
314
+ children: "null"
315
+ }
316
+ )
317
+ ] })
318
+ ]
319
+ }
320
+ ) }),
321
+ /* @__PURE__ */ e(y, {})
322
+ ] })
323
+ }
324
+ ) }),
325
+ /* @__PURE__ */ e("div", { className: "flex items-center space-x-2", children: /* @__PURE__ */ e(
326
+ u,
327
+ {
328
+ control: n.control,
329
+ name: "required",
330
+ render: ({ field: r }) => /* @__PURE__ */ i(d, { children: [
331
+ /* @__PURE__ */ e(h, { children: /* @__PURE__ */ e(
332
+ U,
333
+ {
334
+ checked: r.value,
335
+ onCheckedChange: (o) => r.onChange(o)
336
+ }
337
+ ) }),
338
+ /* @__PURE__ */ e(p, { children: "Required" }),
339
+ /* @__PURE__ */ e(y, {})
340
+ ] })
341
+ }
342
+ ) }),
343
+ /* @__PURE__ */ e("div", { className: "space-y-2", children: /* @__PURE__ */ e(
344
+ u,
345
+ {
346
+ control: n.control,
347
+ name: "property.description",
348
+ render: ({ field: r }) => /* @__PURE__ */ i(d, { children: [
349
+ /* @__PURE__ */ e(p, { children: "Description" }),
350
+ /* @__PURE__ */ e(h, { children: /* @__PURE__ */ e(O, { ...r }) }),
351
+ /* @__PURE__ */ e(y, {})
352
+ ] })
353
+ }
354
+ ) }),
355
+ I ? /* @__PURE__ */ e(
356
+ u,
357
+ {
358
+ control: n.control,
359
+ name: "property.enum",
360
+ render: ({ field: r }) => /* @__PURE__ */ i(d, { children: [
361
+ /* @__PURE__ */ e(p, { children: "Enum" }),
362
+ /* @__PURE__ */ e(h, { children: /* @__PURE__ */ e(
363
+ W,
364
+ {
365
+ values: r.value?.filter((o) => typeof o == "string") ?? [],
366
+ onAddValue: (o) => {
367
+ const a = [];
368
+ r.value && a.push(...r.value), a.push(o), r.onChange(a);
369
+ },
370
+ onRemoveValue: (o) => {
371
+ const a = f(r.value ?? []);
372
+ a.splice(o, 1), r.onChange(a);
373
+ }
374
+ }
375
+ ) }),
376
+ /* @__PURE__ */ e(y, {})
377
+ ] })
378
+ }
379
+ ) : null,
380
+ S.length ? /* @__PURE__ */ i("div", { className: "space-y-2", children: [
381
+ /* @__PURE__ */ e(Q, { children: "Constraints" }),
382
+ /* @__PURE__ */ e(
383
+ Y,
384
+ {
385
+ addedConstraints: v ?? [],
386
+ availableDefinitions: S,
387
+ onAdd: (r) => {
388
+ n.setValue("constraints", r);
389
+ }
390
+ }
391
+ ),
392
+ /* @__PURE__ */ e(Z, {}),
393
+ v?.map((r, o) => {
394
+ const a = q(r.name);
395
+ if (!a) return null;
396
+ const l = n.formState.errors.constraints?.[o];
397
+ let c;
398
+ return l && (c = {
399
+ code: l?.type ?? "INVALID",
400
+ message: l.message ?? "An error occurred"
401
+ }), /* @__PURE__ */ e(
402
+ a,
403
+ {
404
+ constraintName: r.name,
405
+ value: r.value,
406
+ onConstraintChange: (m) => {
407
+ z(o, m);
408
+ },
409
+ onRemoveConstraint: () => {
410
+ L(r.name);
411
+ },
412
+ error: c
413
+ },
414
+ r.name
415
+ );
416
+ })
417
+ ] }) : null,
418
+ /* @__PURE__ */ e(G, { children: /* @__PURE__ */ e(x, { type: "submit", children: "Add Property" }) })
419
+ ]
420
+ }
421
+ ) })
422
+ ] }) });
423
+ }
23
424
  export {
24
- x as DebouncedInput
425
+ ne as AddFormSchema,
426
+ Ce as AddPropertyDialog
25
427
  };
26
428
  //# sourceMappingURL=index.es20.js.map