@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.
- package/dist/index.cjs10.js +1 -1
- package/dist/index.cjs10.js.map +1 -1
- package/dist/index.cjs100.js +1 -1
- package/dist/index.cjs100.js.map +1 -1
- package/dist/index.cjs101.js +1 -38
- package/dist/index.cjs101.js.map +1 -1
- package/dist/index.cjs102.js +1 -1
- package/dist/index.cjs102.js.map +1 -1
- package/dist/index.cjs103.js +1 -1
- package/dist/index.cjs103.js.map +1 -1
- package/dist/index.cjs11.js +1 -1
- package/dist/index.cjs11.js.map +1 -1
- package/dist/index.cjs12.js +1 -1
- package/dist/index.cjs12.js.map +1 -1
- package/dist/index.cjs13.js +1 -1
- package/dist/index.cjs13.js.map +1 -1
- package/dist/index.cjs14.js +1 -1
- package/dist/index.cjs14.js.map +1 -1
- package/dist/index.cjs15.js +1 -1
- package/dist/index.cjs15.js.map +1 -1
- package/dist/index.cjs16.js +1 -1
- package/dist/index.cjs16.js.map +1 -1
- package/dist/index.cjs17.js +1 -1
- package/dist/index.cjs17.js.map +1 -1
- package/dist/index.cjs18.js +1 -1
- package/dist/index.cjs18.js.map +1 -1
- package/dist/index.cjs19.js +1 -1
- package/dist/index.cjs19.js.map +1 -1
- package/dist/index.cjs2.js +1 -1
- package/dist/index.cjs2.js.map +1 -1
- package/dist/index.cjs20.js +1 -1
- package/dist/index.cjs20.js.map +1 -1
- package/dist/index.cjs21.js +1 -1
- package/dist/index.cjs21.js.map +1 -1
- package/dist/index.cjs22.js +6 -1
- package/dist/index.cjs22.js.map +1 -1
- package/dist/index.cjs23.js +2 -2
- package/dist/index.cjs23.js.map +1 -1
- package/dist/index.cjs24.js +2 -2
- package/dist/index.cjs24.js.map +1 -1
- package/dist/index.cjs25.js +2 -2
- package/dist/index.cjs25.js.map +1 -1
- package/dist/index.cjs26.js +2 -2
- package/dist/index.cjs26.js.map +1 -1
- package/dist/index.cjs27.js +1 -6
- package/dist/index.cjs27.js.map +1 -1
- package/dist/index.cjs28.js +1 -1
- package/dist/index.cjs28.js.map +1 -1
- package/dist/index.cjs29.js +6 -1
- package/dist/index.cjs29.js.map +1 -1
- package/dist/index.cjs3.js +1 -1
- package/dist/index.cjs3.js.map +1 -1
- package/dist/index.cjs30.js +1 -6
- package/dist/index.cjs30.js.map +1 -1
- package/dist/index.cjs31.js +1 -1
- package/dist/index.cjs31.js.map +1 -1
- package/dist/index.cjs32.js +1 -1
- package/dist/index.cjs32.js.map +1 -1
- package/dist/index.cjs33.js +1 -9
- package/dist/index.cjs33.js.map +1 -1
- package/dist/index.cjs34.js +1 -22
- package/dist/index.cjs34.js.map +1 -1
- package/dist/index.cjs35.js +1 -1
- package/dist/index.cjs35.js.map +1 -1
- package/dist/index.cjs36.js +1 -1
- package/dist/index.cjs36.js.map +1 -1
- package/dist/index.cjs37.js +1 -1
- package/dist/index.cjs37.js.map +1 -1
- package/dist/index.cjs38.js +1 -1
- package/dist/index.cjs38.js.map +1 -1
- package/dist/index.cjs39.js +1 -1
- package/dist/index.cjs39.js.map +1 -1
- package/dist/index.cjs4.js +1 -1
- package/dist/index.cjs4.js.map +1 -1
- package/dist/index.cjs40.js +1 -1
- package/dist/index.cjs40.js.map +1 -1
- package/dist/index.cjs41.js +1 -1
- package/dist/index.cjs41.js.map +1 -1
- package/dist/index.cjs42.js +1 -6
- package/dist/index.cjs42.js.map +1 -1
- package/dist/index.cjs43.js +2 -2
- package/dist/index.cjs43.js.map +1 -1
- package/dist/index.cjs44.js +2 -2
- package/dist/index.cjs44.js.map +1 -1
- package/dist/index.cjs45.js +6 -1
- package/dist/index.cjs45.js.map +1 -1
- package/dist/index.cjs46.js +7 -1
- package/dist/index.cjs46.js.map +1 -1
- package/dist/index.cjs47.js +1 -1
- package/dist/index.cjs47.js.map +1 -1
- package/dist/index.cjs48.js +6 -1
- package/dist/index.cjs48.js.map +1 -1
- package/dist/index.cjs49.js +6 -1
- package/dist/index.cjs49.js.map +1 -1
- package/dist/index.cjs5.js +1 -1
- package/dist/index.cjs5.js.map +1 -1
- package/dist/index.cjs50.js +6 -1
- package/dist/index.cjs50.js.map +1 -1
- package/dist/index.cjs51.js +6 -7
- package/dist/index.cjs51.js.map +1 -1
- package/dist/index.cjs52.js +1 -1
- package/dist/index.cjs52.js.map +1 -1
- package/dist/index.cjs53.js +1 -1
- package/dist/index.cjs53.js.map +1 -1
- package/dist/index.cjs54.js +5 -1
- package/dist/index.cjs54.js.map +1 -1
- package/dist/index.cjs55.js +1 -6
- package/dist/index.cjs55.js.map +1 -1
- package/dist/index.cjs56.js +1 -6
- package/dist/index.cjs56.js.map +1 -1
- package/dist/index.cjs57.js +1 -6
- package/dist/index.cjs57.js.map +1 -1
- package/dist/index.cjs58.js +1 -6
- package/dist/index.cjs58.js.map +1 -1
- package/dist/index.cjs59.js +1 -1
- package/dist/index.cjs59.js.map +1 -1
- package/dist/index.cjs6.js +1 -1
- package/dist/index.cjs6.js.map +1 -1
- package/dist/index.cjs60.js +1 -1
- package/dist/index.cjs60.js.map +1 -1
- package/dist/index.cjs61.js +1 -5
- package/dist/index.cjs61.js.map +1 -1
- package/dist/index.cjs62.js +1 -1
- package/dist/index.cjs62.js.map +1 -1
- package/dist/index.cjs63.js +1 -1
- package/dist/index.cjs63.js.map +1 -1
- package/dist/index.cjs64.js +1 -1
- package/dist/index.cjs64.js.map +1 -1
- package/dist/index.cjs65.js +1 -1
- package/dist/index.cjs65.js.map +1 -1
- package/dist/index.cjs66.js +1 -1
- package/dist/index.cjs66.js.map +1 -1
- package/dist/index.cjs67.js +1 -1
- package/dist/index.cjs67.js.map +1 -1
- package/dist/index.cjs68.js +1 -1
- package/dist/index.cjs68.js.map +1 -1
- package/dist/index.cjs69.js +1 -1
- package/dist/index.cjs69.js.map +1 -1
- package/dist/index.cjs7.js +1 -1
- package/dist/index.cjs7.js.map +1 -1
- package/dist/index.cjs70.js +1 -1
- package/dist/index.cjs70.js.map +1 -1
- package/dist/index.cjs71.js +1 -1
- package/dist/index.cjs71.js.map +1 -1
- package/dist/index.cjs72.js +1 -1
- package/dist/index.cjs72.js.map +1 -1
- package/dist/index.cjs73.js +1 -1
- package/dist/index.cjs73.js.map +1 -1
- package/dist/index.cjs74.js +1 -1
- package/dist/index.cjs74.js.map +1 -1
- package/dist/index.cjs75.js +1 -1
- package/dist/index.cjs75.js.map +1 -1
- package/dist/index.cjs76.js +1 -1
- package/dist/index.cjs76.js.map +1 -1
- package/dist/index.cjs77.js +1 -1
- package/dist/index.cjs77.js.map +1 -1
- package/dist/index.cjs78.js +1 -1
- package/dist/index.cjs78.js.map +1 -1
- package/dist/index.cjs79.js +1 -1
- package/dist/index.cjs79.js.map +1 -1
- package/dist/index.cjs8.js +1 -1
- package/dist/index.cjs8.js.map +1 -1
- package/dist/index.cjs80.js +1 -1
- package/dist/index.cjs80.js.map +1 -1
- package/dist/index.cjs81.js +1 -1
- package/dist/index.cjs81.js.map +1 -1
- package/dist/index.cjs82.js +1 -1
- package/dist/index.cjs82.js.map +1 -1
- package/dist/index.cjs83.js +1 -1
- package/dist/index.cjs83.js.map +1 -1
- package/dist/index.cjs84.js +1 -1
- package/dist/index.cjs84.js.map +1 -1
- package/dist/index.cjs85.js +1 -1
- package/dist/index.cjs85.js.map +1 -1
- package/dist/index.cjs86.js +1 -1
- package/dist/index.cjs86.js.map +1 -1
- package/dist/index.cjs87.js +1 -1
- package/dist/index.cjs87.js.map +1 -1
- package/dist/index.cjs88.js +4 -1
- package/dist/index.cjs88.js.map +1 -1
- package/dist/index.cjs89.js +1 -1
- package/dist/index.cjs89.js.map +1 -1
- package/dist/index.cjs9.js +1 -1
- package/dist/index.cjs9.js.map +1 -1
- package/dist/index.cjs90.js +1 -1
- package/dist/index.cjs90.js.map +1 -1
- package/dist/index.cjs91.js +1 -1
- package/dist/index.cjs91.js.map +1 -1
- package/dist/index.cjs92.js +1 -1
- package/dist/index.cjs92.js.map +1 -1
- package/dist/index.cjs93.js +1 -1
- package/dist/index.cjs93.js.map +1 -1
- package/dist/index.cjs94.js +38 -1
- package/dist/index.cjs94.js.map +1 -1
- package/dist/index.cjs95.js +1 -4
- package/dist/index.cjs95.js.map +1 -1
- package/dist/index.cjs96.js +1 -1
- package/dist/index.cjs96.js.map +1 -1
- package/dist/index.cjs97.js +1 -1
- package/dist/index.cjs97.js.map +1 -1
- package/dist/index.cjs98.js +1 -1
- package/dist/index.cjs98.js.map +1 -1
- package/dist/index.cjs99.js +1 -1
- package/dist/index.cjs99.js.map +1 -1
- package/dist/index.es10.js +46 -22
- package/dist/index.es10.js.map +1 -1
- package/dist/index.es100.js +22 -64
- package/dist/index.es100.js.map +1 -1
- package/dist/index.es101.js +12 -68
- package/dist/index.es101.js.map +1 -1
- package/dist/index.es102.js +26 -7
- package/dist/index.es102.js.map +1 -1
- package/dist/index.es103.js +5 -14
- package/dist/index.es103.js.map +1 -1
- package/dist/index.es11.js +57 -39
- package/dist/index.es11.js.map +1 -1
- package/dist/index.es12.js +23 -61
- package/dist/index.es12.js.map +1 -1
- package/dist/index.es13.js +126 -21
- package/dist/index.es13.js.map +1 -1
- package/dist/index.es14.js +12 -126
- package/dist/index.es14.js.map +1 -1
- package/dist/index.es15.js +132 -17
- package/dist/index.es15.js.map +1 -1
- package/dist/index.es16.js +133 -130
- package/dist/index.es16.js.map +1 -1
- package/dist/index.es17.js +43 -117
- package/dist/index.es17.js.map +1 -1
- package/dist/index.es18.js +9 -62
- package/dist/index.es18.js.map +1 -1
- package/dist/index.es19.js +23 -11
- package/dist/index.es19.js.map +1 -1
- package/dist/index.es2.js +5 -5
- package/dist/index.es2.js.map +1 -1
- package/dist/index.es20.js +422 -20
- package/dist/index.es20.js.map +1 -1
- package/dist/index.es21.js +5 -424
- package/dist/index.es21.js.map +1 -1
- package/dist/index.es22.js +13 -6
- package/dist/index.es22.js.map +1 -1
- package/dist/index.es23.js +10 -7
- package/dist/index.es23.js.map +1 -1
- package/dist/index.es24.js +7 -10
- package/dist/index.es24.js.map +1 -1
- package/dist/index.es25.js +12 -6
- package/dist/index.es25.js.map +1 -1
- package/dist/index.es26.js +4 -13
- package/dist/index.es26.js.map +1 -1
- package/dist/index.es27.js +19 -10
- package/dist/index.es27.js.map +1 -1
- package/dist/index.es28.js +22 -18
- package/dist/index.es28.js.map +1 -1
- package/dist/index.es29.js +13 -23
- package/dist/index.es29.js.map +1 -1
- package/dist/index.es3.js +206 -206
- package/dist/index.es3.js.map +1 -1
- package/dist/index.es30.js +17 -13
- package/dist/index.es30.js.map +1 -1
- package/dist/index.es31.js +14 -7
- package/dist/index.es31.js.map +1 -1
- package/dist/index.es32.js +2477 -2
- package/dist/index.es32.js.map +1 -1
- package/dist/index.es33.js +39 -24
- package/dist/index.es33.js.map +1 -1
- package/dist/index.es34.js +33 -602
- package/dist/index.es34.js.map +1 -1
- package/dist/index.es35.js +115 -16
- package/dist/index.es35.js.map +1 -1
- package/dist/index.es36.js +113 -14
- package/dist/index.es36.js.map +1 -1
- package/dist/index.es37.js +52 -2473
- package/dist/index.es37.js.map +1 -1
- package/dist/index.es38.js +23 -40
- package/dist/index.es38.js.map +1 -1
- package/dist/index.es39.js +45 -33
- package/dist/index.es39.js.map +1 -1
- package/dist/index.es4.js +5 -5
- package/dist/index.es4.js.map +1 -1
- package/dist/index.es40.js +79 -109
- package/dist/index.es40.js.map +1 -1
- package/dist/index.es41.js +49 -821
- package/dist/index.es41.js.map +1 -1
- package/dist/index.es42.js +832 -10
- package/dist/index.es42.js.map +1 -1
- package/dist/index.es43.js +3 -3
- package/dist/index.es43.js.map +1 -1
- package/dist/index.es44.js +3 -3
- package/dist/index.es44.js.map +1 -1
- package/dist/index.es45.js +10 -114
- package/dist/index.es45.js.map +1 -1
- package/dist/index.es46.js +122 -55
- package/dist/index.es46.js.map +1 -1
- package/dist/index.es47.js +62 -23
- package/dist/index.es47.js.map +1 -1
- package/dist/index.es48.js +21 -45
- package/dist/index.es48.js.map +1 -1
- package/dist/index.es49.js +9 -86
- package/dist/index.es49.js.map +1 -1
- package/dist/index.es5.js +62 -62
- package/dist/index.es5.js.map +1 -1
- package/dist/index.es50.js +37 -59
- package/dist/index.es50.js.map +1 -1
- package/dist/index.es51.js +17 -122
- package/dist/index.es51.js.map +1 -1
- package/dist/index.es52.js +7 -62
- package/dist/index.es52.js.map +1 -1
- package/dist/index.es53.js +5 -2
- package/dist/index.es53.js.map +1 -1
- package/dist/index.es54.js +255 -2
- package/dist/index.es54.js.map +1 -1
- package/dist/index.es55.js +21 -20
- package/dist/index.es55.js.map +1 -1
- package/dist/index.es56.js +27 -9
- package/dist/index.es56.js.map +1 -1
- package/dist/index.es57.js +7 -38
- package/dist/index.es57.js.map +1 -1
- package/dist/index.es58.js +66 -18
- package/dist/index.es58.js.map +1 -1
- package/dist/index.es59.js +29 -7
- package/dist/index.es59.js.map +1 -1
- package/dist/index.es6.js +37 -37
- package/dist/index.es6.js.map +1 -1
- package/dist/index.es60.js +5 -4
- package/dist/index.es60.js.map +1 -1
- package/dist/index.es61.js +24 -254
- package/dist/index.es61.js.map +1 -1
- package/dist/index.es62.js +32 -21
- package/dist/index.es62.js.map +1 -1
- package/dist/index.es63.js +3 -26
- package/dist/index.es63.js.map +1 -1
- package/dist/index.es64.js +44 -5
- package/dist/index.es64.js.map +1 -1
- package/dist/index.es65.js +7 -65
- package/dist/index.es65.js.map +1 -1
- package/dist/index.es66.js +121 -26
- package/dist/index.es66.js.map +1 -1
- package/dist/index.es67.js +14 -5
- package/dist/index.es67.js.map +1 -1
- package/dist/index.es68.js +133 -24
- package/dist/index.es68.js.map +1 -1
- package/dist/index.es69.js +10 -32
- package/dist/index.es69.js.map +1 -1
- package/dist/index.es7.js +33 -33
- package/dist/index.es7.js.map +1 -1
- package/dist/index.es70.js +215 -3
- package/dist/index.es70.js.map +1 -1
- package/dist/index.es71.js +13 -46
- package/dist/index.es71.js.map +1 -1
- package/dist/index.es72.js +7 -7
- package/dist/index.es72.js.map +1 -1
- package/dist/index.es73.js +4 -125
- package/dist/index.es73.js.map +1 -1
- package/dist/index.es74.js +28 -15
- package/dist/index.es74.js.map +1 -1
- package/dist/index.es75.js +48 -132
- package/dist/index.es75.js.map +1 -1
- package/dist/index.es76.js +9 -11
- package/dist/index.es76.js.map +1 -1
- package/dist/index.es77.js +65 -213
- package/dist/index.es77.js.map +1 -1
- package/dist/index.es78.js +12 -13
- package/dist/index.es78.js.map +1 -1
- package/dist/index.es79.js +204 -7
- package/dist/index.es79.js.map +1 -1
- package/dist/index.es8.js +87 -87
- package/dist/index.es8.js.map +1 -1
- package/dist/index.es80.js +22 -4
- package/dist/index.es80.js.map +1 -1
- package/dist/index.es81.js +391 -26
- package/dist/index.es81.js.map +1 -1
- package/dist/index.es82.js +24 -49
- package/dist/index.es82.js.map +1 -1
- package/dist/index.es83.js +28 -8
- package/dist/index.es83.js.map +1 -1
- package/dist/index.es84.js +5 -68
- package/dist/index.es84.js.map +1 -1
- package/dist/index.es85.js +5 -12
- package/dist/index.es85.js.map +1 -1
- package/dist/index.es86.js +3 -205
- package/dist/index.es86.js.map +1 -1
- package/dist/index.es87.js +23 -21
- package/dist/index.es87.js.map +1 -1
- package/dist/index.es88.js +105 -388
- package/dist/index.es88.js.map +1 -1
- package/dist/index.es89.js +14 -23
- package/dist/index.es89.js.map +1 -1
- package/dist/index.es9.js +23 -3
- package/dist/index.es9.js.map +1 -1
- package/dist/index.es90.js +521 -27
- package/dist/index.es90.js.map +1 -1
- package/dist/index.es91.js +127 -5
- package/dist/index.es91.js.map +1 -1
- package/dist/index.es92.js +129 -5
- package/dist/index.es92.js.map +1 -1
- package/dist/index.es93.js +65 -3
- package/dist/index.es93.js.map +1 -1
- package/dist/index.es94.js +69 -24
- package/dist/index.es94.js.map +1 -1
- package/dist/index.es95.js +9 -110
- package/dist/index.es95.js.map +1 -1
- package/dist/index.es96.js +14 -16
- package/dist/index.es96.js.map +1 -1
- package/dist/index.es97.js +60 -521
- package/dist/index.es97.js.map +1 -1
- package/dist/index.es98.js +3 -126
- package/dist/index.es98.js.map +1 -1
- package/dist/index.es99.js +22 -128
- package/dist/index.es99.js.map +1 -1
- package/package.json +1 -1
- package/dist/index.cjs104.js +0 -2
- package/dist/index.cjs104.js.map +0 -1
- package/dist/index.cjs105.js +0 -2
- package/dist/index.cjs105.js.map +0 -1
- package/dist/index.cjs106.js +0 -2
- package/dist/index.cjs106.js.map +0 -1
- package/dist/index.cjs107.js +0 -2
- package/dist/index.cjs107.js.map +0 -1
- package/dist/index.cjs108.js +0 -2
- package/dist/index.cjs108.js.map +0 -1
- package/dist/index.cjs109.js +0 -2
- package/dist/index.cjs109.js.map +0 -1
- package/dist/index.cjs110.js +0 -2
- package/dist/index.cjs110.js.map +0 -1
- package/dist/index.es104.js +0 -65
- package/dist/index.es104.js.map +0 -1
- package/dist/index.es105.js +0 -7
- package/dist/index.es105.js.map +0 -1
- package/dist/index.es106.js +0 -26
- package/dist/index.es106.js.map +0 -1
- package/dist/index.es107.js +0 -26
- package/dist/index.es107.js.map +0 -1
- package/dist/index.es108.js +0 -16
- package/dist/index.es108.js.map +0 -1
- package/dist/index.es109.js +0 -31
- package/dist/index.es109.js.map +0 -1
- package/dist/index.es110.js +0 -8
- package/dist/index.es110.js.map +0 -1
package/dist/index.es19.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
12
|
-
i as validateSchema
|
|
24
|
+
I as DebouncedInput
|
|
13
25
|
};
|
|
14
26
|
//# sourceMappingURL=index.es19.js.map
|
package/dist/index.es19.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es19.js","sources":["../src/
|
|
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 {
|
|
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.
|
|
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
|
|
19
|
+
return /* @__PURE__ */ y(d.Provider, { value: { schema: n, setSchema: a, path: u, setPath: p }, children: l });
|
|
20
20
|
}
|
|
21
|
-
function
|
|
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
|
-
|
|
106
|
+
D as useSchema
|
|
107
107
|
};
|
|
108
108
|
//# sourceMappingURL=index.es2.js.map
|
package/dist/index.es2.js.map
CHANGED
|
@@ -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,IAAU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AAG,GAG/BhB,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
|
+
{"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,C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B;AAAA,IA6ME,0BAAAV;AAAA,IACA,sBA1E2B,CAACQ,MAAgB;AACtC,YAAAE,IAAYC,EAAMpB,CAAM,GAGxBY,IAAuBI,EAAiBG,CAAS;AAGnD,MAAAP,EAAQ,SAAS,YACfA,EAAQ,aACVA,EAAQ,WAAWA,EAAQ,SAAS,OAAO,CAACS,MAASA,MAASJ,CAAG,IAKjEL,EAAQ,SAAS,YAAYA,EAAQ,cAChC,OAAAA,EAAQ,WAAWK,CAAG,GAG/BhB,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;"}
|
package/dist/index.es20.js
CHANGED
|
@@ -1,26 +1,428 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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
|
-
|
|
425
|
+
ne as AddFormSchema,
|
|
426
|
+
Ce as AddPropertyDialog
|
|
25
427
|
};
|
|
26
428
|
//# sourceMappingURL=index.es20.js.map
|