@gravity-ui/page-constructor 8.5.0-alpha.1 → 8.5.0-alpha.4

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 (258) hide show
  1. package/build/cjs/containers/PageConstructor/PageConstructor.d.ts +0 -1
  2. package/build/cjs/containers/PageConstructor/PageConstructor.js +0 -1
  3. package/build/cjs/containers/PageConstructor/PageConstructor.js.map +1 -1
  4. package/build/cjs/form-builder-v2/CanvasContentContext.d.ts +18 -0
  5. package/build/cjs/form-builder-v2/CanvasContentContext.js +21 -0
  6. package/build/cjs/form-builder-v2/CanvasContentContext.js.map +1 -0
  7. package/build/cjs/form-builder-v2/FormBuilderV2.css +93 -0
  8. package/build/cjs/form-builder-v2/FormBuilderV2.d.ts +10 -0
  9. package/build/cjs/form-builder-v2/FormBuilderV2.js +123 -0
  10. package/build/cjs/form-builder-v2/FormBuilderV2.js.map +1 -0
  11. package/build/cjs/form-builder-v2/components/Canvas/Canvas.css +15 -0
  12. package/build/cjs/form-builder-v2/components/Canvas/Canvas.d.ts +8 -0
  13. package/build/cjs/form-builder-v2/components/Canvas/Canvas.js +17 -0
  14. package/build/cjs/form-builder-v2/components/Canvas/Canvas.js.map +1 -0
  15. package/build/cjs/form-builder-v2/components/CanvasCard/CanvasCard.css +133 -0
  16. package/build/cjs/form-builder-v2/components/CanvasCard/CanvasCard.d.ts +9 -0
  17. package/build/cjs/form-builder-v2/components/CanvasCard/CanvasCard.js +72 -0
  18. package/build/cjs/form-builder-v2/components/CanvasCard/CanvasCard.js.map +1 -0
  19. package/build/cjs/form-builder-v2/components/CanvasCard/components/FieldPreview.d.ts +6 -0
  20. package/build/cjs/form-builder-v2/components/CanvasCard/components/FieldPreview.js +44 -0
  21. package/build/cjs/form-builder-v2/components/CanvasCard/components/FieldPreview.js.map +1 -0
  22. package/build/cjs/form-builder-v2/components/CanvasCard/components/SectionChildrenDropZone.d.ts +9 -0
  23. package/build/cjs/form-builder-v2/components/CanvasCard/components/SectionChildrenDropZone.js +20 -0
  24. package/build/cjs/form-builder-v2/components/CanvasCard/components/SectionChildrenDropZone.js.map +1 -0
  25. package/build/cjs/form-builder-v2/components/ContentTab/ContentTab.css +22 -0
  26. package/build/cjs/form-builder-v2/components/ContentTab/ContentTab.d.ts +1 -0
  27. package/build/cjs/form-builder-v2/components/ContentTab/ContentTab.js +21 -0
  28. package/build/cjs/form-builder-v2/components/ContentTab/ContentTab.js.map +1 -0
  29. package/build/cjs/form-builder-v2/components/DragOverlayPreview/DragOverlayPreview.css +13 -0
  30. package/build/cjs/form-builder-v2/components/DragOverlayPreview/DragOverlayPreview.d.ts +7 -0
  31. package/build/cjs/form-builder-v2/components/DragOverlayPreview/DragOverlayPreview.js +24 -0
  32. package/build/cjs/form-builder-v2/components/DragOverlayPreview/DragOverlayPreview.js.map +1 -0
  33. package/build/cjs/form-builder-v2/components/FieldSettings/FieldSettings.css +30 -0
  34. package/build/cjs/form-builder-v2/components/FieldSettings/FieldSettings.d.ts +6 -0
  35. package/build/cjs/form-builder-v2/components/FieldSettings/FieldSettings.js +49 -0
  36. package/build/cjs/form-builder-v2/components/FieldSettings/FieldSettings.js.map +1 -0
  37. package/build/cjs/form-builder-v2/components/FieldSettings/fields/ColorInputSettings.d.ts +12 -0
  38. package/build/cjs/form-builder-v2/components/FieldSettings/fields/ColorInputSettings.js +11 -0
  39. package/build/cjs/form-builder-v2/components/FieldSettings/fields/ColorInputSettings.js.map +1 -0
  40. package/build/cjs/form-builder-v2/components/FieldSettings/fields/OptionsSettings.d.ts +12 -0
  41. package/build/cjs/form-builder-v2/components/FieldSettings/fields/OptionsSettings.js +38 -0
  42. package/build/cjs/form-builder-v2/components/FieldSettings/fields/OptionsSettings.js.map +1 -0
  43. package/build/cjs/form-builder-v2/components/FieldSettings/fields/Row.d.ts +7 -0
  44. package/build/cjs/form-builder-v2/components/FieldSettings/fields/Row.js +9 -0
  45. package/build/cjs/form-builder-v2/components/FieldSettings/fields/Row.js.map +1 -0
  46. package/build/cjs/form-builder-v2/components/FieldSettings/fields/SectionSettings.d.ts +9 -0
  47. package/build/cjs/form-builder-v2/components/FieldSettings/fields/SectionSettings.js +40 -0
  48. package/build/cjs/form-builder-v2/components/FieldSettings/fields/SectionSettings.js.map +1 -0
  49. package/build/cjs/form-builder-v2/components/FieldSettings/fields/SwitchSettings.d.ts +12 -0
  50. package/build/cjs/form-builder-v2/components/FieldSettings/fields/SwitchSettings.js +11 -0
  51. package/build/cjs/form-builder-v2/components/FieldSettings/fields/SwitchSettings.js.map +1 -0
  52. package/build/cjs/form-builder-v2/components/FieldSettings/fields/TextFieldSettings.d.ts +12 -0
  53. package/build/cjs/form-builder-v2/components/FieldSettings/fields/TextFieldSettings.js +11 -0
  54. package/build/cjs/form-builder-v2/components/FieldSettings/fields/TextFieldSettings.js.map +1 -0
  55. package/build/cjs/form-builder-v2/components/FieldSettings/fields/TextSettings.d.ts +11 -0
  56. package/build/cjs/form-builder-v2/components/FieldSettings/fields/TextSettings.js +53 -0
  57. package/build/cjs/form-builder-v2/components/FieldSettings/fields/TextSettings.js.map +1 -0
  58. package/build/cjs/form-builder-v2/components/Inspector/Inspector.css +20 -0
  59. package/build/cjs/form-builder-v2/components/Inspector/Inspector.d.ts +1 -0
  60. package/build/cjs/form-builder-v2/components/Inspector/Inspector.js +20 -0
  61. package/build/cjs/form-builder-v2/components/Inspector/Inspector.js.map +1 -0
  62. package/build/cjs/form-builder-v2/components/Palette/Palette.css +56 -0
  63. package/build/cjs/form-builder-v2/components/Palette/Palette.d.ts +4 -0
  64. package/build/cjs/form-builder-v2/components/Palette/Palette.js +62 -0
  65. package/build/cjs/form-builder-v2/components/Palette/Palette.js.map +1 -0
  66. package/build/cjs/form-builder-v2/components/ResizeHandle/ResizeHandle.css +29 -0
  67. package/build/cjs/form-builder-v2/components/ResizeHandle/ResizeHandle.d.ts +9 -0
  68. package/build/cjs/form-builder-v2/components/ResizeHandle/ResizeHandle.js +98 -0
  69. package/build/cjs/form-builder-v2/components/ResizeHandle/ResizeHandle.js.map +1 -0
  70. package/build/cjs/form-builder-v2/components/SchemaPopup/SchemaPopup.css +49 -0
  71. package/build/cjs/form-builder-v2/components/SchemaPopup/SchemaPopup.d.ts +11 -0
  72. package/build/cjs/form-builder-v2/components/SchemaPopup/SchemaPopup.js +82 -0
  73. package/build/cjs/form-builder-v2/components/SchemaPopup/SchemaPopup.js.map +1 -0
  74. package/build/cjs/form-builder-v2/components/WhenEditor/WhenEditor.css +24 -0
  75. package/build/cjs/form-builder-v2/components/WhenEditor/WhenEditor.d.ts +8 -0
  76. package/build/cjs/form-builder-v2/components/WhenEditor/WhenEditor.js +50 -0
  77. package/build/cjs/form-builder-v2/components/WhenEditor/WhenEditor.js.map +1 -0
  78. package/build/cjs/form-builder-v2/components/WhenEditor/utils.d.ts +24 -0
  79. package/build/cjs/form-builder-v2/components/WhenEditor/utils.js +83 -0
  80. package/build/cjs/form-builder-v2/components/WhenEditor/utils.js.map +1 -0
  81. package/build/cjs/form-builder-v2/hooks/FormContext.d.ts +11 -0
  82. package/build/cjs/form-builder-v2/hooks/FormContext.js +22 -0
  83. package/build/cjs/form-builder-v2/hooks/FormContext.js.map +1 -0
  84. package/build/cjs/form-builder-v2/hooks/useFormFields.d.ts +23 -0
  85. package/build/cjs/form-builder-v2/hooks/useFormFields.js +144 -0
  86. package/build/cjs/form-builder-v2/hooks/useFormFields.js.map +1 -0
  87. package/build/cjs/form-builder-v2/index.d.ts +2 -0
  88. package/build/cjs/form-builder-v2/index.js +6 -0
  89. package/build/cjs/form-builder-v2/index.js.map +1 -0
  90. package/build/cjs/form-builder-v2/styles/variables.css +0 -0
  91. package/build/cjs/form-builder-v2/types.d.ts +32 -0
  92. package/build/cjs/form-builder-v2/types.js +3 -0
  93. package/build/cjs/form-builder-v2/types.js.map +1 -0
  94. package/build/cjs/form-builder-v2/utils/cn.d.ts +2 -0
  95. package/build/cjs/form-builder-v2/utils/cn.js +7 -0
  96. package/build/cjs/form-builder-v2/utils/cn.js.map +1 -0
  97. package/build/cjs/form-builder-v2/utils/dragData.d.ts +18 -0
  98. package/build/cjs/form-builder-v2/utils/dragData.js +18 -0
  99. package/build/cjs/form-builder-v2/utils/dragData.js.map +1 -0
  100. package/build/cjs/form-builder-v2/utils/fieldDefaults.d.ts +2 -0
  101. package/build/cjs/form-builder-v2/utils/fieldDefaults.js +51 -0
  102. package/build/cjs/form-builder-v2/utils/fieldDefaults.js.map +1 -0
  103. package/build/cjs/form-builder-v2/utils/fieldGroups.d.ts +3 -0
  104. package/build/cjs/form-builder-v2/utils/fieldGroups.js +26 -0
  105. package/build/cjs/form-builder-v2/utils/fieldGroups.js.map +1 -0
  106. package/build/cjs/form-builder-v2/utils/fieldMeta.d.ts +6 -0
  107. package/build/cjs/form-builder-v2/utils/fieldMeta.js +45 -0
  108. package/build/cjs/form-builder-v2/utils/fieldMeta.js.map +1 -0
  109. package/build/cjs/form-builder-v2/utils/fieldNames.d.ts +8 -0
  110. package/build/cjs/form-builder-v2/utils/fieldNames.js +75 -0
  111. package/build/cjs/form-builder-v2/utils/fieldNames.js.map +1 -0
  112. package/build/cjs/form-builder-v2/utils/fieldTree.d.ts +2 -0
  113. package/build/cjs/form-builder-v2/utils/fieldTree.js +7 -0
  114. package/build/cjs/form-builder-v2/utils/fieldTree.js.map +1 -0
  115. package/build/cjs/form-builder-v2/utils/fieldTreeOps.d.ts +13 -0
  116. package/build/cjs/form-builder-v2/utils/fieldTreeOps.js +80 -0
  117. package/build/cjs/form-builder-v2/utils/fieldTreeOps.js.map +1 -0
  118. package/build/cjs/form-builder-v2/utils/parseSchema.d.ts +9 -0
  119. package/build/cjs/form-builder-v2/utils/parseSchema.js +102 -0
  120. package/build/cjs/form-builder-v2/utils/parseSchema.js.map +1 -0
  121. package/build/cjs/form-builder-v2/utils/stripIds.d.ts +3 -0
  122. package/build/cjs/form-builder-v2/utils/stripIds.js +12 -0
  123. package/build/cjs/form-builder-v2/utils/stripIds.js.map +1 -0
  124. package/build/cjs/form-builder-v2/utils/treeWalk.d.ts +4 -0
  125. package/build/cjs/form-builder-v2/utils/treeWalk.js +45 -0
  126. package/build/cjs/form-builder-v2/utils/treeWalk.js.map +1 -0
  127. package/build/cjs/hooks/usePCEditorInitializeEvents.js +2 -2
  128. package/build/cjs/hooks/usePCEditorInitializeEvents.js.map +1 -1
  129. package/build/esm/containers/PageConstructor/PageConstructor.d.ts +0 -1
  130. package/build/esm/containers/PageConstructor/PageConstructor.js +0 -1
  131. package/build/esm/containers/PageConstructor/PageConstructor.js.map +1 -1
  132. package/build/esm/form-builder-v2/CanvasContentContext.d.ts +18 -0
  133. package/build/esm/form-builder-v2/CanvasContentContext.js +15 -0
  134. package/build/esm/form-builder-v2/CanvasContentContext.js.map +1 -0
  135. package/build/esm/form-builder-v2/FormBuilderV2.css +93 -0
  136. package/build/esm/form-builder-v2/FormBuilderV2.d.ts +11 -0
  137. package/build/esm/form-builder-v2/FormBuilderV2.js +119 -0
  138. package/build/esm/form-builder-v2/FormBuilderV2.js.map +1 -0
  139. package/build/esm/form-builder-v2/components/Canvas/Canvas.css +15 -0
  140. package/build/esm/form-builder-v2/components/Canvas/Canvas.d.ts +9 -0
  141. package/build/esm/form-builder-v2/components/Canvas/Canvas.js +14 -0
  142. package/build/esm/form-builder-v2/components/Canvas/Canvas.js.map +1 -0
  143. package/build/esm/form-builder-v2/components/CanvasCard/CanvasCard.css +133 -0
  144. package/build/esm/form-builder-v2/components/CanvasCard/CanvasCard.d.ts +10 -0
  145. package/build/esm/form-builder-v2/components/CanvasCard/CanvasCard.js +68 -0
  146. package/build/esm/form-builder-v2/components/CanvasCard/CanvasCard.js.map +1 -0
  147. package/build/esm/form-builder-v2/components/CanvasCard/components/FieldPreview.d.ts +6 -0
  148. package/build/esm/form-builder-v2/components/CanvasCard/components/FieldPreview.js +39 -0
  149. package/build/esm/form-builder-v2/components/CanvasCard/components/FieldPreview.js.map +1 -0
  150. package/build/esm/form-builder-v2/components/CanvasCard/components/SectionChildrenDropZone.d.ts +9 -0
  151. package/build/esm/form-builder-v2/components/CanvasCard/components/SectionChildrenDropZone.js +16 -0
  152. package/build/esm/form-builder-v2/components/CanvasCard/components/SectionChildrenDropZone.js.map +1 -0
  153. package/build/esm/form-builder-v2/components/ContentTab/ContentTab.css +22 -0
  154. package/build/esm/form-builder-v2/components/ContentTab/ContentTab.d.ts +2 -0
  155. package/build/esm/form-builder-v2/components/ContentTab/ContentTab.js +17 -0
  156. package/build/esm/form-builder-v2/components/ContentTab/ContentTab.js.map +1 -0
  157. package/build/esm/form-builder-v2/components/DragOverlayPreview/DragOverlayPreview.css +13 -0
  158. package/build/esm/form-builder-v2/components/DragOverlayPreview/DragOverlayPreview.d.ts +8 -0
  159. package/build/esm/form-builder-v2/components/DragOverlayPreview/DragOverlayPreview.js +21 -0
  160. package/build/esm/form-builder-v2/components/DragOverlayPreview/DragOverlayPreview.js.map +1 -0
  161. package/build/esm/form-builder-v2/components/FieldSettings/FieldSettings.css +30 -0
  162. package/build/esm/form-builder-v2/components/FieldSettings/FieldSettings.d.ts +7 -0
  163. package/build/esm/form-builder-v2/components/FieldSettings/FieldSettings.js +45 -0
  164. package/build/esm/form-builder-v2/components/FieldSettings/FieldSettings.js.map +1 -0
  165. package/build/esm/form-builder-v2/components/FieldSettings/fields/ColorInputSettings.d.ts +12 -0
  166. package/build/esm/form-builder-v2/components/FieldSettings/fields/ColorInputSettings.js +6 -0
  167. package/build/esm/form-builder-v2/components/FieldSettings/fields/ColorInputSettings.js.map +1 -0
  168. package/build/esm/form-builder-v2/components/FieldSettings/fields/OptionsSettings.d.ts +12 -0
  169. package/build/esm/form-builder-v2/components/FieldSettings/fields/OptionsSettings.js +33 -0
  170. package/build/esm/form-builder-v2/components/FieldSettings/fields/OptionsSettings.js.map +1 -0
  171. package/build/esm/form-builder-v2/components/FieldSettings/fields/Row.d.ts +7 -0
  172. package/build/esm/form-builder-v2/components/FieldSettings/fields/Row.js +5 -0
  173. package/build/esm/form-builder-v2/components/FieldSettings/fields/Row.js.map +1 -0
  174. package/build/esm/form-builder-v2/components/FieldSettings/fields/SectionSettings.d.ts +9 -0
  175. package/build/esm/form-builder-v2/components/FieldSettings/fields/SectionSettings.js +35 -0
  176. package/build/esm/form-builder-v2/components/FieldSettings/fields/SectionSettings.js.map +1 -0
  177. package/build/esm/form-builder-v2/components/FieldSettings/fields/SwitchSettings.d.ts +12 -0
  178. package/build/esm/form-builder-v2/components/FieldSettings/fields/SwitchSettings.js +6 -0
  179. package/build/esm/form-builder-v2/components/FieldSettings/fields/SwitchSettings.js.map +1 -0
  180. package/build/esm/form-builder-v2/components/FieldSettings/fields/TextFieldSettings.d.ts +12 -0
  181. package/build/esm/form-builder-v2/components/FieldSettings/fields/TextFieldSettings.js +6 -0
  182. package/build/esm/form-builder-v2/components/FieldSettings/fields/TextFieldSettings.js.map +1 -0
  183. package/build/esm/form-builder-v2/components/FieldSettings/fields/TextSettings.d.ts +11 -0
  184. package/build/esm/form-builder-v2/components/FieldSettings/fields/TextSettings.js +48 -0
  185. package/build/esm/form-builder-v2/components/FieldSettings/fields/TextSettings.js.map +1 -0
  186. package/build/esm/form-builder-v2/components/Inspector/Inspector.css +20 -0
  187. package/build/esm/form-builder-v2/components/Inspector/Inspector.d.ts +2 -0
  188. package/build/esm/form-builder-v2/components/Inspector/Inspector.js +16 -0
  189. package/build/esm/form-builder-v2/components/Inspector/Inspector.js.map +1 -0
  190. package/build/esm/form-builder-v2/components/Palette/Palette.css +56 -0
  191. package/build/esm/form-builder-v2/components/Palette/Palette.d.ts +5 -0
  192. package/build/esm/form-builder-v2/components/Palette/Palette.js +58 -0
  193. package/build/esm/form-builder-v2/components/Palette/Palette.js.map +1 -0
  194. package/build/esm/form-builder-v2/components/ResizeHandle/ResizeHandle.css +29 -0
  195. package/build/esm/form-builder-v2/components/ResizeHandle/ResizeHandle.d.ts +10 -0
  196. package/build/esm/form-builder-v2/components/ResizeHandle/ResizeHandle.js +94 -0
  197. package/build/esm/form-builder-v2/components/ResizeHandle/ResizeHandle.js.map +1 -0
  198. package/build/esm/form-builder-v2/components/SchemaPopup/SchemaPopup.css +49 -0
  199. package/build/esm/form-builder-v2/components/SchemaPopup/SchemaPopup.d.ts +12 -0
  200. package/build/esm/form-builder-v2/components/SchemaPopup/SchemaPopup.js +78 -0
  201. package/build/esm/form-builder-v2/components/SchemaPopup/SchemaPopup.js.map +1 -0
  202. package/build/esm/form-builder-v2/components/WhenEditor/WhenEditor.css +24 -0
  203. package/build/esm/form-builder-v2/components/WhenEditor/WhenEditor.d.ts +9 -0
  204. package/build/esm/form-builder-v2/components/WhenEditor/WhenEditor.js +46 -0
  205. package/build/esm/form-builder-v2/components/WhenEditor/WhenEditor.js.map +1 -0
  206. package/build/esm/form-builder-v2/components/WhenEditor/utils.d.ts +24 -0
  207. package/build/esm/form-builder-v2/components/WhenEditor/utils.js +76 -0
  208. package/build/esm/form-builder-v2/components/WhenEditor/utils.js.map +1 -0
  209. package/build/esm/form-builder-v2/hooks/FormContext.d.ts +11 -0
  210. package/build/esm/form-builder-v2/hooks/FormContext.js +16 -0
  211. package/build/esm/form-builder-v2/hooks/FormContext.js.map +1 -0
  212. package/build/esm/form-builder-v2/hooks/useFormFields.d.ts +23 -0
  213. package/build/esm/form-builder-v2/hooks/useFormFields.js +139 -0
  214. package/build/esm/form-builder-v2/hooks/useFormFields.js.map +1 -0
  215. package/build/esm/form-builder-v2/index.d.ts +2 -0
  216. package/build/esm/form-builder-v2/index.js +3 -0
  217. package/build/esm/form-builder-v2/index.js.map +1 -0
  218. package/build/esm/form-builder-v2/styles/variables.css +0 -0
  219. package/build/esm/form-builder-v2/types.d.ts +32 -0
  220. package/build/esm/form-builder-v2/types.js +2 -0
  221. package/build/esm/form-builder-v2/types.js.map +1 -0
  222. package/build/esm/form-builder-v2/utils/cn.d.ts +2 -0
  223. package/build/esm/form-builder-v2/utils/cn.js +4 -0
  224. package/build/esm/form-builder-v2/utils/cn.js.map +1 -0
  225. package/build/esm/form-builder-v2/utils/dragData.d.ts +18 -0
  226. package/build/esm/form-builder-v2/utils/dragData.js +11 -0
  227. package/build/esm/form-builder-v2/utils/dragData.js.map +1 -0
  228. package/build/esm/form-builder-v2/utils/fieldDefaults.d.ts +2 -0
  229. package/build/esm/form-builder-v2/utils/fieldDefaults.js +47 -0
  230. package/build/esm/form-builder-v2/utils/fieldDefaults.js.map +1 -0
  231. package/build/esm/form-builder-v2/utils/fieldGroups.d.ts +3 -0
  232. package/build/esm/form-builder-v2/utils/fieldGroups.js +21 -0
  233. package/build/esm/form-builder-v2/utils/fieldGroups.js.map +1 -0
  234. package/build/esm/form-builder-v2/utils/fieldMeta.d.ts +6 -0
  235. package/build/esm/form-builder-v2/utils/fieldMeta.js +42 -0
  236. package/build/esm/form-builder-v2/utils/fieldMeta.js.map +1 -0
  237. package/build/esm/form-builder-v2/utils/fieldNames.d.ts +8 -0
  238. package/build/esm/form-builder-v2/utils/fieldNames.js +66 -0
  239. package/build/esm/form-builder-v2/utils/fieldNames.js.map +1 -0
  240. package/build/esm/form-builder-v2/utils/fieldTree.d.ts +2 -0
  241. package/build/esm/form-builder-v2/utils/fieldTree.js +3 -0
  242. package/build/esm/form-builder-v2/utils/fieldTree.js.map +1 -0
  243. package/build/esm/form-builder-v2/utils/fieldTreeOps.d.ts +13 -0
  244. package/build/esm/form-builder-v2/utils/fieldTreeOps.js +69 -0
  245. package/build/esm/form-builder-v2/utils/fieldTreeOps.js.map +1 -0
  246. package/build/esm/form-builder-v2/utils/parseSchema.d.ts +9 -0
  247. package/build/esm/form-builder-v2/utils/parseSchema.js +98 -0
  248. package/build/esm/form-builder-v2/utils/parseSchema.js.map +1 -0
  249. package/build/esm/form-builder-v2/utils/stripIds.d.ts +3 -0
  250. package/build/esm/form-builder-v2/utils/stripIds.js +8 -0
  251. package/build/esm/form-builder-v2/utils/stripIds.js.map +1 -0
  252. package/build/esm/form-builder-v2/utils/treeWalk.d.ts +4 -0
  253. package/build/esm/form-builder-v2/utils/treeWalk.js +39 -0
  254. package/build/esm/form-builder-v2/utils/treeWalk.js.map +1 -0
  255. package/build/esm/hooks/usePCEditorInitializeEvents.js +2 -2
  256. package/build/esm/hooks/usePCEditorInitializeEvents.js.map +1 -1
  257. package/package.json +13 -1
  258. package/widget/index.js +1 -1
@@ -0,0 +1,11 @@
1
+ import type { Fields } from "../../../form-generator-v2/types.js";
2
+ import type { FormField } from "../../types.js";
3
+ interface SchemaPopupProps {
4
+ schema: Fields;
5
+ onApply: (fields: FormField[]) => void;
6
+ open: boolean;
7
+ onOpenChange: (open: boolean) => void;
8
+ anchorElement: HTMLElement | null;
9
+ }
10
+ export declare const SchemaPopup: ({ schema, onApply, open, onOpenChange, anchorElement, }: SchemaPopupProps) => import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaPopup = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const React = tslib_1.__importStar(require("react"));
7
+ const uikit_1 = require("@gravity-ui/uikit");
8
+ const cn_1 = require("../../utils/cn.js");
9
+ const parseSchema_1 = require("../../utils/parseSchema.js");
10
+ const b = (0, cn_1.formBuilderV2Cn)('schema-popup');
11
+ const stringify = (schema) => JSON.stringify(schema, null, 2);
12
+ const SchemaPopup = ({ schema, onApply, open, onOpenChange, anchorElement, }) => {
13
+ const textareaRef = React.useRef(null);
14
+ const copyTimeoutRef = React.useRef(null);
15
+ const [draft, setDraft] = React.useState(() => stringify(schema));
16
+ const [error, setError] = React.useState(null);
17
+ const [copied, setCopied] = React.useState(false);
18
+ const [isFocused, setIsFocused] = React.useState(false);
19
+ React.useEffect(() => {
20
+ if (!isFocused) {
21
+ setDraft(stringify(schema));
22
+ setError(null);
23
+ }
24
+ }, [schema, isFocused]);
25
+ React.useEffect(() => () => {
26
+ if (copyTimeoutRef.current)
27
+ clearTimeout(copyTimeoutRef.current);
28
+ }, []);
29
+ const applyDraft = (value) => {
30
+ setDraft(value);
31
+ const result = (0, parseSchema_1.parseSchema)(value);
32
+ if (result.ok) {
33
+ setError(null);
34
+ onApply(result.fields);
35
+ }
36
+ else {
37
+ setError(result.error);
38
+ }
39
+ };
40
+ const replaceSelection = (insert, caretOffset) => {
41
+ const t = textareaRef.current;
42
+ if (!t)
43
+ return;
44
+ const { selectionStart, selectionEnd } = t;
45
+ const next = draft.slice(0, selectionStart) + insert + draft.slice(selectionEnd);
46
+ const nextCaret = selectionStart + caretOffset;
47
+ applyDraft(next);
48
+ requestAnimationFrame(() => {
49
+ t.selectionStart = nextCaret;
50
+ t.selectionEnd = nextCaret;
51
+ });
52
+ };
53
+ const handleKeyDown = (event) => {
54
+ if (event.key === 'Tab') {
55
+ event.preventDefault();
56
+ replaceSelection(' ', 2);
57
+ return;
58
+ }
59
+ if (event.key === 'Enter') {
60
+ event.preventDefault();
61
+ const t = event.currentTarget;
62
+ const before = draft.slice(0, t.selectionStart);
63
+ const lineStart = before.lastIndexOf('\n') + 1;
64
+ const indent = before.slice(lineStart).match(/^[ \t]*/)?.[0] ?? '';
65
+ const insert = `\n${indent}`;
66
+ replaceSelection(insert, insert.length);
67
+ }
68
+ };
69
+ const handleCopy = React.useCallback(async () => {
70
+ try {
71
+ await navigator.clipboard.writeText(draft);
72
+ setCopied(true);
73
+ if (copyTimeoutRef.current)
74
+ clearTimeout(copyTimeoutRef.current);
75
+ copyTimeoutRef.current = setTimeout(() => setCopied(false), 1500);
76
+ }
77
+ catch { }
78
+ }, [draft]);
79
+ return ((0, jsx_runtime_1.jsx)(uikit_1.Popup, { anchorElement: anchorElement, open: open, onOpenChange: onOpenChange, placement: "bottom-end", children: (0, jsx_runtime_1.jsxs)(uikit_1.Card, { className: b(), view: "outlined", children: [(0, jsx_runtime_1.jsxs)("div", { className: b('header'), children: [(0, jsx_runtime_1.jsx)(uikit_1.Text, { variant: "subheader-2", children: "Form schema" }), (0, jsx_runtime_1.jsx)(uikit_1.Text, { variant: "caption-1", color: "hint", children: "Edit JSON directly \u2014 the canvas updates live. Paste your own schema to load it. Selection on canvas resets after each edit." })] }), (0, jsx_runtime_1.jsx)("textarea", { ref: textareaRef, className: b('textarea', { error: Boolean(error) }), value: draft, onChange: (event) => applyDraft(event.target.value), onKeyDown: handleKeyDown, onFocus: () => setIsFocused(true), onBlur: () => setIsFocused(false), spellCheck: false, wrap: "off" }), error && ((0, jsx_runtime_1.jsx)("div", { className: b('error-message'), children: (0, jsx_runtime_1.jsx)(uikit_1.Text, { variant: "caption-1", color: "danger", children: error }) })), (0, jsx_runtime_1.jsxs)("div", { className: b('actions'), children: [(0, jsx_runtime_1.jsx)(uikit_1.Button, { view: "action", size: "m", onClick: handleCopy, children: copied ? '✓ Copied' : 'Copy' }), (0, jsx_runtime_1.jsx)(uikit_1.Button, { view: "flat", size: "m", onClick: () => onOpenChange(false), children: "Close" })] })] }) }));
80
+ };
81
+ exports.SchemaPopup = SchemaPopup;
82
+ //# sourceMappingURL=SchemaPopup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SchemaPopup.js","sourceRoot":"../../../../../src","sources":["form-builder-v2/components/SchemaPopup/SchemaPopup.tsx"],"names":[],"mappings":";;;;;AAAA,qDAA+B;AAE/B,6CAA4D;AAI5D,0CAA+C;AAC/C,4DAAoD;AAIpD,MAAM,CAAC,GAAG,IAAA,oBAAe,EAAC,cAAc,CAAC,CAAC;AAE1C,MAAM,SAAS,GAAG,CAAC,MAAc,EAAU,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAUvE,MAAM,WAAW,GAAG,CAAC,EACxB,MAAM,EACN,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,aAAa,GACE,EAAE,EAAE;IACnB,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAsB,IAAI,CAAC,CAAC;IAC5D,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CAA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AC,EACnD,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,EACjC,MAAM,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,EACjC,UAAU,EAAE,KAAK,EACjB,IAAI,EAAC,KAAK,GACZ,EACD,KAAK,IAAI,CACN,gCAAK,SAAS,EAAE,CAAC,CAAC,eAAe,CAAC,YAC9B,uBAAC,YAAI,IAAC,OAAO,EAAC,WAAW,EAAC,KAAK,EAAC,QAAQ,YACnC,KAAK,GACH,GACL,CACT,EACD,iCAAK,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,aACxB,uBAAC,cAAM,IAAC,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAC,GAAG,EAAC,OAAO,EAAE,UAAU,YAC7C,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,GACxB,EACT,uBAAC,cAAM,IAAC,IAAI,EAAC,MAAM,EAAC,IAAI,EAAC,GAAG,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,sBAEtD,IACP,IACH,GACH,CACX,CAAC;AACN,CAAC,CAAC;AA1HW,QAAA,WAAW,eA0HtB","sourcesContent":["import * as React from 'react';\n\nimport {Button, Card, Popup, Text} from '@gravity-ui/uikit';\n\nimport type {Fields} from '../../../form-generator-v2/types';\nimport type {FormField} from '../../types';\nimport {formBuilderV2Cn} from '../../utils/cn';\nimport {parseSchema} from '../../utils/parseSchema';\n\nimport './SchemaPopup.scss';\n\nconst b = formBuilderV2Cn('schema-popup');\n\nconst stringify = (schema: Fields): string => JSON.stringify(schema, null, 2);\n\ninterface SchemaPopupProps {\n schema: Fields;\n onApply: (fields: FormField[]) => void;\n open: boolean;\n onOpenChange: (open: boolean) => void;\n anchorElement: HTMLElement | null;\n}\n\nexport const SchemaPopup = ({\n schema,\n onApply,\n open,\n onOpenChange,\n anchorElement,\n}: SchemaPopupProps) => {\n const textareaRef = React.useRef<HTMLTextAreaElement>(null);\n const copyTimeoutRef = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n const [draft, setDraft] = React.useState<string>(() => stringify(schema));\n const [error, setError] = React.useState<string | null>(null);\n const [copied, setCopied] = React.useState(false);\n const [isFocused, setIsFocused] = React.useState(false);\n\n React.useEffect(() => {\n if (!isFocused) {\n setDraft(stringify(schema));\n setError(null);\n }\n }, [schema, isFocused]);\n\n React.useEffect(\n () => () => {\n if (copyTimeoutRef.current) clearTimeout(copyTimeoutRef.current);\n },\n [],\n );\n\n const applyDraft = (value: string) => {\n setDraft(value);\n const result = parseSchema(value);\n if (result.ok) {\n setError(null);\n onApply(result.fields);\n } else {\n setError(result.error);\n }\n };\n\n const replaceSelection = (insert: string, caretOffset: number) => {\n const t = textareaRef.current;\n if (!t) return;\n const {selectionStart, selectionEnd} = t;\n const next = draft.slice(0, selectionStart) + insert + draft.slice(selectionEnd);\n const nextCaret = selectionStart + caretOffset;\n applyDraft(next);\n requestAnimationFrame(() => {\n t.selectionStart = nextCaret;\n t.selectionEnd = nextCaret;\n });\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {\n if (event.key === 'Tab') {\n event.preventDefault();\n replaceSelection(' ', 2);\n return;\n }\n if (event.key === 'Enter') {\n event.preventDefault();\n const t = event.currentTarget;\n const before = draft.slice(0, t.selectionStart);\n const lineStart = before.lastIndexOf('\\n') + 1;\n const indent = before.slice(lineStart).match(/^[ \\t]*/)?.[0] ?? '';\n const insert = `\\n${indent}`;\n replaceSelection(insert, insert.length);\n }\n };\n\n const handleCopy = React.useCallback(async () => {\n try {\n await navigator.clipboard.writeText(draft);\n setCopied(true);\n if (copyTimeoutRef.current) clearTimeout(copyTimeoutRef.current);\n copyTimeoutRef.current = setTimeout(() => setCopied(false), 1500);\n } catch {}\n }, [draft]);\n\n return (\n <Popup\n anchorElement={anchorElement}\n open={open}\n onOpenChange={onOpenChange}\n placement=\"bottom-end\"\n >\n <Card className={b()} view=\"outlined\">\n <div className={b('header')}>\n <Text variant=\"subheader-2\">Form schema</Text>\n <Text variant=\"caption-1\" color=\"hint\">\n Edit JSON directly — the canvas updates live. Paste your own schema to load\n it. Selection on canvas resets after each edit.\n </Text>\n </div>\n <textarea\n ref={textareaRef}\n className={b('textarea', {error: Boolean(error)})}\n value={draft}\n onChange={(event) => applyDraft(event.target.value)}\n onKeyDown={handleKeyDown}\n onFocus={() => setIsFocused(true)}\n onBlur={() => setIsFocused(false)}\n spellCheck={false}\n wrap=\"off\"\n />\n {error && (\n <div className={b('error-message')}>\n <Text variant=\"caption-1\" color=\"danger\">\n {error}\n </Text>\n </div>\n )}\n <div className={b('actions')}>\n <Button view=\"action\" size=\"m\" onClick={handleCopy}>\n {copied ? '✓ Copied' : 'Copy'}\n </Button>\n <Button view=\"flat\" size=\"m\" onClick={() => onOpenChange(false)}>\n Close\n </Button>\n </div>\n </Card>\n </Popup>\n );\n};\n"]}
@@ -0,0 +1,24 @@
1
+ .pcformbuilderv2-when-editor {
2
+ display: flex;
3
+ flex-direction: column;
4
+ gap: 6px;
5
+ padding: var(--g-spacing-2);
6
+ border: 1px solid var(--g-color-line-generic);
7
+ border-radius: var(--g-border-radius-m);
8
+ }
9
+ .pcformbuilderv2-when-editor__condition {
10
+ display: grid;
11
+ grid-template-columns: minmax(0, 1fr) 80px minmax(0, 1fr) auto;
12
+ gap: 6px;
13
+ align-items: center;
14
+ }
15
+ .pcformbuilderv2-when-editor__combinator {
16
+ display: flex;
17
+ align-items: center;
18
+ }
19
+ .pcformbuilderv2-when-editor__actions {
20
+ display: flex;
21
+ gap: var(--g-spacing-2);
22
+ align-items: center;
23
+ margin-top: var(--g-spacing-1);
24
+ }
@@ -0,0 +1,8 @@
1
+ import type { When } from "../../../form-generator-v2/types.js";
2
+ interface WhenEditorProps {
3
+ when: When | undefined;
4
+ availableFields: string[];
5
+ onChange: (next: When | undefined) => void;
6
+ }
7
+ export declare const WhenEditor: ({ when, availableFields, onChange }: WhenEditorProps) => import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WhenEditor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const React = tslib_1.__importStar(require("react"));
7
+ const icons_1 = require("@gravity-ui/icons");
8
+ const uikit_1 = require("@gravity-ui/uikit");
9
+ const cn_1 = require("../../utils/cn.js");
10
+ const utils_1 = require("./utils.js");
11
+ const b = (0, cn_1.formBuilderV2Cn)('when-editor');
12
+ const WhenEditor = ({ when, availableFields, onChange }) => {
13
+ const { conditions, combinators } = (0, utils_1.parse)(when);
14
+ const fieldOptions = React.useMemo(() => availableFields.map((name) => ({ value: name, content: name })), [availableFields]);
15
+ const commit = (nextConditions, nextCombinators) => {
16
+ onChange((0, utils_1.serialize)(nextConditions, nextCombinators));
17
+ };
18
+ const addCondition = () => {
19
+ const nextConditions = [
20
+ ...conditions,
21
+ { field: availableFields[0] ?? '', operator: '===', value: '' },
22
+ ];
23
+ const nextCombinators = conditions.length === 0 ? combinators : [...combinators, { operator: '&&' }];
24
+ commit(nextConditions, nextCombinators);
25
+ };
26
+ const removeCondition = (index) => {
27
+ const nextConditions = conditions.filter((_, i) => i !== index);
28
+ const nextCombinators = index === 0
29
+ ? combinators.slice(1)
30
+ : [...combinators.slice(0, index - 1), ...combinators.slice(index)];
31
+ commit(nextConditions, nextCombinators);
32
+ };
33
+ const updateCondition = (index, patch) => {
34
+ const nextConditions = conditions.map((c, i) => (i === index ? { ...c, ...patch } : c));
35
+ commit(nextConditions, combinators);
36
+ };
37
+ const updateCombinator = (index, op) => {
38
+ const nextCombinators = combinators.map((c, i) => (i === index ? { operator: op } : c));
39
+ commit(conditions, nextCombinators);
40
+ };
41
+ const clearAll = () => {
42
+ onChange(undefined);
43
+ };
44
+ if (conditions.length === 0) {
45
+ return ((0, jsx_runtime_1.jsx)("div", { className: b(), children: (0, jsx_runtime_1.jsx)(uikit_1.Button, { view: "normal", size: "s", onClick: addCondition, children: "+ Add condition" }) }));
46
+ }
47
+ return ((0, jsx_runtime_1.jsxs)("div", { className: b(), children: [conditions.map((cond, i) => ((0, jsx_runtime_1.jsxs)(React.Fragment, { children: [i > 0 && ((0, jsx_runtime_1.jsx)("div", { className: b('combinator'), children: (0, jsx_runtime_1.jsx)(uikit_1.Select, { size: "s", value: [combinators[i - 1]?.operator ?? '&&'], options: utils_1.COMBINATOR_OPTIONS, onUpdate: (next) => updateCombinator(i - 1, next[0]), width: 80 }) })), (0, jsx_runtime_1.jsxs)("div", { className: b('condition'), children: [(0, jsx_runtime_1.jsx)(uikit_1.Select, { size: "s", value: [cond.field], options: fieldOptions, onUpdate: (next) => updateCondition(i, { field: next[0] ?? '' }), placeholder: "field", filterable: true, width: "max" }), (0, jsx_runtime_1.jsx)(uikit_1.Select, { size: "s", value: [cond.operator], options: utils_1.OPERATOR_OPTIONS, onUpdate: (next) => updateCondition(i, { operator: next[0] }), width: 80 }), (0, jsx_runtime_1.jsx)(uikit_1.TextInput, { size: "s", value: (0, utils_1.displayValue)(cond.value), onUpdate: (value) => updateCondition(i, { value: (0, utils_1.coerceValue)(value) }), placeholder: 'value ("true"/"false" \u2192 bool)' }), (0, jsx_runtime_1.jsx)(uikit_1.Button, { view: "flat-danger", size: "s", onClick: () => removeCondition(i), title: "Remove condition", children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.TrashBin, size: 12 }) })] })] }, i))), (0, jsx_runtime_1.jsxs)("div", { className: b('actions'), children: [(0, jsx_runtime_1.jsx)(uikit_1.Button, { view: "normal", size: "s", onClick: addCondition, children: "+ Add condition" }), (0, jsx_runtime_1.jsx)(uikit_1.Button, { view: "flat", size: "s", onClick: clearAll, children: "Clear" })] })] }));
48
+ };
49
+ exports.WhenEditor = WhenEditor;
50
+ //# sourceMappingURL=WhenEditor.js.map
@@ -0,0 +1 @@
1
+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,IAAI,CAAC,QAAQ,CAAC,EACtB,OAAO,EAAE,wBAAgB,EACzB,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CACf,eAAe,CAAC,CAAC,EAAE,EAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAkB,EAAC,CAAC,EAE5D,KAAK,EAAE,EAAE,GACX,EACF,uBAAC,iBAAS,IACN,IAAI,EAAC,GAAG,EACR,KAAK,EAAE,IAAA,oBAAY,EAAC,IAAI,CAAC,KAAK,CAAC,EAC/B,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,EAAE,EAAC,KAAK,EAAE,IAAA,mBAAW,EAAC,KAAK,CAAC,EAAC,CAAC,EACpE,WAAW,EAAC,oCAA+B,GAC7C,EACF,uBAAC,cAAM,IACH,IAAI,EAAC,aAAa,EAClB,IAAI,EAAC,GAAG,EACR,OAAO,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,EACjC,KAAK,EAAC,kBAAkB,YAExB,uBAAC,YAAI,IAAC,IAAI,EAAE,gBAAQ,EAAE,IAAI,EAAE,EAAE,GAAI,GAC7B,IACP,KA7CW,CAAC,CA8CL,CACpB,CAAC,EACF,iCAAK,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,aACxB,uBAAC,cAAM,IAAC,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAC,GAAG,EAAC,OAAO,EAAE,YAAY,gCAE3C,EACT,uBAAC,cAAM,IAAC,IAAI,EAAC,MAAM,EAAC,IAAI,EAAC,GAAG,EAAC,OAAO,EAAE,QAAQ,sBAErC,IACP,IACJ,CACT,CAAC;AACN,CAAC,CAAC;AApHW,QAAA,UAAU,cAoHrB","sourcesContent":["import * as React from 'react';\n\nimport {TrashBin} from '@gravity-ui/icons';\nimport {Button, Icon, Select, TextInput} from '@gravity-ui/uikit';\n\nimport type {When} from '../../../form-generator-v2/types';\nimport {formBuilderV2Cn} from '../../utils/cn';\n\nimport {\n COMBINATOR_OPTIONS,\n Combinator,\n Condition,\n OPERATOR_OPTIONS,\n coerceValue,\n displayValue,\n parse,\n serialize,\n} from './utils';\n\nimport './WhenEditor.scss';\n\nconst b = formBuilderV2Cn('when-editor');\n\ninterface WhenEditorProps {\n when: When | undefined;\n availableFields: string[];\n onChange: (next: When | undefined) => void;\n}\n\nexport const WhenEditor = ({when, availableFields, onChange}: WhenEditorProps) => {\n const {conditions, combinators} = parse(when);\n\n const fieldOptions = React.useMemo(\n () => availableFields.map((name) => ({value: name, content: name})),\n [availableFields],\n );\n\n const commit = (nextConditions: Condition[], nextCombinators: Combinator[]) => {\n onChange(serialize(nextConditions, nextCombinators));\n };\n\n const addCondition = () => {\n const nextConditions: Condition[] = [\n ...conditions,\n {field: availableFields[0] ?? '', operator: '===', value: ''},\n ];\n const nextCombinators: Combinator[] =\n conditions.length === 0 ? combinators : [...combinators, {operator: '&&'}];\n commit(nextConditions, nextCombinators);\n };\n\n const removeCondition = (index: number) => {\n const nextConditions = conditions.filter((_, i) => i !== index);\n const nextCombinators =\n index === 0\n ? combinators.slice(1)\n : [...combinators.slice(0, index - 1), ...combinators.slice(index)];\n commit(nextConditions, nextCombinators);\n };\n\n const updateCondition = (index: number, patch: Partial<Condition>) => {\n const nextConditions = conditions.map((c, i) => (i === index ? {...c, ...patch} : c));\n commit(nextConditions, combinators);\n };\n\n const updateCombinator = (index: number, op: '&&' | '||') => {\n const nextCombinators = combinators.map((c, i) => (i === index ? {operator: op} : c));\n commit(conditions, nextCombinators);\n };\n\n const clearAll = () => {\n onChange(undefined);\n };\n\n if (conditions.length === 0) {\n return (\n <div className={b()}>\n <Button view=\"normal\" size=\"s\" onClick={addCondition}>\n + Add condition\n </Button>\n </div>\n );\n }\n\n return (\n <div className={b()}>\n {conditions.map((cond, i) => (\n <React.Fragment key={i}>\n {i > 0 && (\n <div className={b('combinator')}>\n <Select\n size=\"s\"\n value={[combinators[i - 1]?.operator ?? '&&']}\n options={COMBINATOR_OPTIONS}\n onUpdate={(next) => updateCombinator(i - 1, next[0] as '&&' | '||')}\n width={80}\n />\n </div>\n )}\n <div className={b('condition')}>\n <Select\n size=\"s\"\n value={[cond.field]}\n options={fieldOptions}\n onUpdate={(next) => updateCondition(i, {field: next[0] ?? ''})}\n placeholder=\"field\"\n filterable\n width=\"max\"\n />\n <Select\n size=\"s\"\n value={[cond.operator]}\n options={OPERATOR_OPTIONS}\n onUpdate={(next) =>\n updateCondition(i, {operator: next[0] as '===' | '!=='})\n }\n width={80}\n />\n <TextInput\n size=\"s\"\n value={displayValue(cond.value)}\n onUpdate={(value) => updateCondition(i, {value: coerceValue(value)})}\n placeholder='value (\"true\"/\"false\" → bool)'\n />\n <Button\n view=\"flat-danger\"\n size=\"s\"\n onClick={() => removeCondition(i)}\n title=\"Remove condition\"\n >\n <Icon data={TrashBin} size={12} />\n </Button>\n </div>\n </React.Fragment>\n ))}\n <div className={b('actions')}>\n <Button view=\"normal\" size=\"s\" onClick={addCondition}>\n + Add condition\n </Button>\n <Button view=\"flat\" size=\"s\" onClick={clearAll}>\n Clear\n </Button>\n </div>\n </div>\n );\n};\n"]}
@@ -0,0 +1,24 @@
1
+ import type { When } from "../../../form-generator-v2/types.js";
2
+ export type Condition = {
3
+ field: string;
4
+ operator: '===' | '!==';
5
+ value: string | boolean;
6
+ };
7
+ export type Combinator = {
8
+ operator: '&&' | '||';
9
+ };
10
+ export declare const OPERATOR_OPTIONS: {
11
+ value: string;
12
+ content: string;
13
+ }[];
14
+ export declare const COMBINATOR_OPTIONS: {
15
+ value: string;
16
+ content: string;
17
+ }[];
18
+ export declare const parse: (when: When | undefined) => {
19
+ conditions: Condition[];
20
+ combinators: Combinator[];
21
+ };
22
+ export declare const serialize: (conditions: Condition[], combinators: Combinator[]) => When | undefined;
23
+ export declare const coerceValue: (raw: string) => string | boolean;
24
+ export declare const displayValue: (value: string | boolean | undefined) => string;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.displayValue = exports.coerceValue = exports.serialize = exports.parse = exports.COMBINATOR_OPTIONS = exports.OPERATOR_OPTIONS = void 0;
4
+ exports.OPERATOR_OPTIONS = [
5
+ { value: '===', content: 'is' },
6
+ { value: '!==', content: 'is not' },
7
+ ];
8
+ exports.COMBINATOR_OPTIONS = [
9
+ { value: '&&', content: 'AND' },
10
+ { value: '||', content: 'OR' },
11
+ ];
12
+ const parse = (when) => {
13
+ const conditions = [];
14
+ const combinators = [];
15
+ if (!when)
16
+ return { conditions, combinators };
17
+ let lastWasCombinator = false;
18
+ for (const entry of when) {
19
+ const isCondition = Boolean(entry.field) && (entry.operator === '===' || entry.operator === '!==');
20
+ const isCombinator = !entry.field && (entry.operator === '&&' || entry.operator === '||');
21
+ if (isCondition) {
22
+ conditions.push({
23
+ field: entry.field,
24
+ operator: entry.operator,
25
+ value: entry.value ?? '',
26
+ });
27
+ lastWasCombinator = false;
28
+ continue;
29
+ }
30
+ if (isCombinator) {
31
+ if (conditions.length === 0 || lastWasCombinator)
32
+ continue;
33
+ combinators.push({ operator: entry.operator });
34
+ lastWasCombinator = true;
35
+ }
36
+ }
37
+ if (lastWasCombinator) {
38
+ combinators.pop();
39
+ }
40
+ while (combinators.length < conditions.length - 1) {
41
+ combinators.push({ operator: '&&' });
42
+ }
43
+ if (combinators.length > Math.max(0, conditions.length - 1)) {
44
+ combinators.length = Math.max(0, conditions.length - 1);
45
+ }
46
+ return { conditions, combinators };
47
+ };
48
+ exports.parse = parse;
49
+ const serialize = (conditions, combinators) => {
50
+ if (conditions.length === 0)
51
+ return undefined;
52
+ const out = [];
53
+ conditions.forEach((cond, i) => {
54
+ if (i > 0) {
55
+ const combinator = combinators[i - 1] ?? { operator: '&&' };
56
+ out.push({ operator: combinator.operator });
57
+ }
58
+ out.push({
59
+ field: cond.field,
60
+ operator: cond.operator,
61
+ value: cond.value,
62
+ });
63
+ });
64
+ return out;
65
+ };
66
+ exports.serialize = serialize;
67
+ const coerceValue = (raw) => {
68
+ if (raw === 'true')
69
+ return true;
70
+ if (raw === 'false')
71
+ return false;
72
+ return raw;
73
+ };
74
+ exports.coerceValue = coerceValue;
75
+ const displayValue = (value) => {
76
+ if (value === true)
77
+ return 'true';
78
+ if (value === false)
79
+ return 'false';
80
+ return value ?? '';
81
+ };
82
+ exports.displayValue = displayValue;
83
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"../../../../../src","sources":["form-builder-v2/components/WhenEditor/utils.ts"],"names":[],"mappings":";;;AAKa,QAAA,gBAAgB,GAAG;IAC5B,EAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAC;IAC7B,EAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAC;CACpC,CAAC;AAEW,QAAA,kBAAkB,GAAG;IAC9B,EAAC,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAC;IAC7B,EAAC,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAC;CAC/B,CAAC;AAEK,MAAM,KAAK,GAAG,CACjB,IAAsB,EAC8B,EAAE;IACtD,MAAM,UAAU,GAAgB,EAAE,CAAC;IACnC,MAAM,WAAW,GAAiB,EAAE,CAAC;IACrC,IAAI,CAAC,IAAI;QAAE,OAAO,EAAC,UAAU,EAAE,WAAW,EAAC,CAAC;IAE5C,IAAI,iBAAiB,GAAG,KAAK,CAAC;IAE9B,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,WAAW,GACb,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,KAAK,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,CAAC;QACnF,MAAM,YAAY,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,IAAI,IAAI,KAAK,CAAC,QAAQ,KAAK,I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C9C,MAAM,GAAG,GAAS,EAAE,CAAC;IACrB,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;QAC3B,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACR,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;YAC1D,GAAG,CAAC,IAAI,CAAC,EAAC,QAAQ,EAAE,UAAU,CAAC,QAAQ,EAAC,CAAC,CAAC;QAC9C,CAAC;QACD,GAAG,CAAC,IAAI,CAAC;YACL,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK;SACpB,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACf,CAAC,CAAC;AAfW,QAAA,SAAS,aAepB;AAEK,MAAM,WAAW,GAAG,CAAC,GAAW,EAAoB,EAAE;IACzD,IAAI,GAAG,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAChC,IAAI,GAAG,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IAClC,OAAO,GAAG,CAAC;AACf,CAAC,CAAC;AAJW,QAAA,WAAW,eAItB;AAEK,MAAM,YAAY,GAAG,CAAC,KAAmC,EAAU,EAAE;IACxE,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IAClC,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,OAAO,CAAC;IACpC,OAAO,KAAK,IAAI,EAAE,CAAC;AACvB,CAAC,CAAC;AAJW,QAAA,YAAY,gBAIvB","sourcesContent":["import type {When} from '../../../form-generator-v2/types';\n\nexport type Condition = {field: string; operator: '===' | '!=='; value: string | boolean};\nexport type Combinator = {operator: '&&' | '||'};\n\nexport const OPERATOR_OPTIONS = [\n {value: '===', content: 'is'},\n {value: '!==', content: 'is not'},\n];\n\nexport const COMBINATOR_OPTIONS = [\n {value: '&&', content: 'AND'},\n {value: '||', content: 'OR'},\n];\n\nexport const parse = (\n when: When | undefined,\n): {conditions: Condition[]; combinators: Combinator[]} => {\n const conditions: Condition[] = [];\n const combinators: Combinator[] = [];\n if (!when) return {conditions, combinators};\n\n let lastWasCombinator = false;\n\n for (const entry of when) {\n const isCondition =\n Boolean(entry.field) && (entry.operator === '===' || entry.operator === '!==');\n const isCombinator = !entry.field && (entry.operator === '&&' || entry.operator === '||');\n\n if (isCondition) {\n conditions.push({\n field: entry.field as string,\n operator: entry.operator as '===' | '!==',\n value: entry.value ?? '',\n });\n lastWasCombinator = false;\n continue;\n }\n\n if (isCombinator) {\n if (conditions.length === 0 || lastWasCombinator) continue;\n combinators.push({operator: entry.operator as '&&' | '||'});\n lastWasCombinator = true;\n }\n }\n\n if (lastWasCombinator) {\n combinators.pop();\n }\n\n while (combinators.length < conditions.length - 1) {\n combinators.push({operator: '&&'});\n }\n\n if (combinators.length > Math.max(0, conditions.length - 1)) {\n combinators.length = Math.max(0, conditions.length - 1);\n }\n\n return {conditions, combinators};\n};\n\nexport const serialize = (conditions: Condition[], combinators: Combinator[]): When | undefined => {\n if (conditions.length === 0) return undefined;\n const out: When = [];\n conditions.forEach((cond, i) => {\n if (i > 0) {\n const combinator = combinators[i - 1] ?? {operator: '&&'};\n out.push({operator: combinator.operator});\n }\n out.push({\n field: cond.field,\n operator: cond.operator,\n value: cond.value,\n });\n });\n return out;\n};\n\nexport const coerceValue = (raw: string): string | boolean => {\n if (raw === 'true') return true;\n if (raw === 'false') return false;\n return raw;\n};\n\nexport const displayValue = (value: string | boolean | undefined): string => {\n if (value === true) return 'true';\n if (value === false) return 'false';\n return value ?? '';\n};\n"]}
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ import { FormContextType, FormField } from "../types.js";
3
+ export declare const FormContext: React.Context<FormContextType | null>;
4
+ interface FormProviderProps {
5
+ children: React.ReactNode;
6
+ formFields: FormField[];
7
+ onChange?: (fields: FormField[]) => void;
8
+ }
9
+ export declare const FormProvider: ({ children, formFields, onChange }: FormProviderProps) => import("react/jsx-runtime").JSX.Element;
10
+ export declare const useFormContext: () => FormContextType;
11
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useFormContext = exports.FormProvider = exports.FormContext = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const React = tslib_1.__importStar(require("react"));
7
+ const useFormFields_1 = require("./useFormFields.js");
8
+ exports.FormContext = React.createContext(null);
9
+ const FormProvider = ({ children, formFields, onChange }) => {
10
+ const value = (0, useFormFields_1.useFormFields)({ initialFields: formFields, onChange });
11
+ return (0, jsx_runtime_1.jsx)(exports.FormContext.Provider, { value: value, children: children });
12
+ };
13
+ exports.FormProvider = FormProvider;
14
+ const useFormContext = () => {
15
+ const context = React.useContext(exports.FormContext);
16
+ if (!context) {
17
+ throw new Error('useFormContext must be used within a FormProvider');
18
+ }
19
+ return context;
20
+ };
21
+ exports.useFormContext = useFormContext;
22
+ //# sourceMappingURL=FormContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormContext.js","sourceRoot":"../../../../src","sources":["form-builder-v2/hooks/FormContext.tsx"],"names":[],"mappings":";;;;;AAAA,qDAA+B;AAI/B,sDAA8C;AAEjC,QAAA,WAAW,GAAG,KAAK,CAAC,aAAa,CAAyB,IAAI,CAAC,CAAC;AAQtE,MAAM,YAAY,GAAG,CAAC,EAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAoB,EAAE,EAAE;IAChF,MAAM,KAAK,GAAG,IAAA,6BAAa,EAAC,EAAC,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAC,CAAC,CAAC;IACnE,OAAO,uBAAC,mBAAW,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAwB,CAAC;AACjF,CAAC,CAAC;AAHW,QAAA,YAAY,gBAGvB;AAEK,MAAM,cAAc,GAAG,GAAoB,EAAE;IAChD,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,mBAAW,CAAC,CAAC;IAC9C,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AANW,QAAA,cAAc,kBAMzB","sourcesContent":["import * as React from 'react';\n\nimport {FormContextType, FormField} from '../types';\n\nimport {useFormFields} from './useFormFields';\n\nexport const FormContext = React.createContext<FormContextType | null>(null);\n\ninterface FormProviderProps {\n children: React.ReactNode;\n formFields: FormField[];\n onChange?: (fields: FormField[]) => void;\n}\n\nexport const FormProvider = ({children, formFields, onChange}: FormProviderProps) => {\n const value = useFormFields({initialFields: formFields, onChange});\n return <FormContext.Provider value={value}>{children}</FormContext.Provider>;\n};\n\nexport const useFormContext = (): FormContextType => {\n const context = React.useContext(FormContext);\n if (!context) {\n throw new Error('useFormContext must be used within a FormProvider');\n }\n return context;\n};\n"]}
@@ -0,0 +1,23 @@
1
+ import { BuilderFieldType, FieldUpdate, FormField } from "../types.js";
2
+ interface UseFormFieldsProps {
3
+ initialFields: FormField[];
4
+ onChange?: (fields: FormField[]) => void;
5
+ }
6
+ export declare const useFormFields: ({ initialFields, onChange }: UseFormFieldsProps) => {
7
+ formFields: FormField[];
8
+ selectedFieldId: string | null;
9
+ addField: (type: BuilderFieldType) => void;
10
+ addFieldToSection: (sectionId: string, type: BuilderFieldType) => void;
11
+ insertFieldBefore: (targetId: string, type: BuilderFieldType) => void;
12
+ insertFieldAfter: (targetId: string, type: BuilderFieldType) => void;
13
+ moveFieldToSection: (fieldId: string, targetSectionId: string) => void;
14
+ removeField: (fieldId: string) => void;
15
+ duplicateField: (fieldId: string) => void;
16
+ updateField: (fieldId: string, updates: FieldUpdate) => void;
17
+ moveFieldUp: (fieldId: string) => void;
18
+ moveFieldDown: (fieldId: string) => void;
19
+ setAllFields: (next: FormField[]) => void;
20
+ resetForm: () => void;
21
+ selectField: (fieldId: string | null) => void;
22
+ };
23
+ export {};
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useFormFields = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const React = tslib_1.__importStar(require("react"));
6
+ const fieldDefaults_1 = require("../utils/fieldDefaults.js");
7
+ const fieldNames_1 = require("../utils/fieldNames.js");
8
+ const fieldTree_1 = require("../utils/fieldTree.js");
9
+ const fieldTreeOps_1 = require("../utils/fieldTreeOps.js");
10
+ const useFormFields = ({ initialFields, onChange }) => {
11
+ const [formFields, setFormFields] = React.useState(initialFields);
12
+ const [selectedFieldId, setSelectedFieldId] = React.useState(null);
13
+ const idCounter = React.useRef((0, fieldNames_1.maxIdNumericSuffix)(initialFields) + 1);
14
+ const generateId = React.useCallback(() => {
15
+ const id = `fb2_${idCounter.current}`;
16
+ idCounter.current += 1;
17
+ return id;
18
+ }, []);
19
+ const generateName = React.useCallback(() => `field_${idCounter.current}`, []);
20
+ const commit = React.useCallback((next) => {
21
+ setFormFields(next);
22
+ onChange?.(next);
23
+ }, [onChange]);
24
+ const addField = React.useCallback((type) => {
25
+ const id = generateId();
26
+ const name = generateName();
27
+ const newField = (0, fieldDefaults_1.createDefaultField)(type, name, id);
28
+ commit([...formFields, newField]);
29
+ }, [commit, formFields, generateId, generateName]);
30
+ const addFieldToSection = React.useCallback((sectionId, type) => {
31
+ const id = generateId();
32
+ const baseName = generateName();
33
+ const arrayMode = (0, fieldTreeOps_1.isArrayModeSection)(formFields, sectionId);
34
+ const name = arrayMode ? (0, fieldNames_1.prefixNameForArrayMode)(baseName) : baseName;
35
+ const newChild = (0, fieldDefaults_1.createDefaultField)(type, name, id);
36
+ commit((0, fieldTreeOps_1.addChildToSectionDeep)(formFields, sectionId, newChild));
37
+ }, [commit, formFields, generateId, generateName]);
38
+ const insertFieldRelative = React.useCallback((targetId, type, offset) => {
39
+ const makeField = (arrayMode) => {
40
+ const id = generateId();
41
+ const baseName = generateName();
42
+ const name = arrayMode ? (0, fieldNames_1.prefixNameForArrayMode)(baseName) : baseName;
43
+ return (0, fieldDefaults_1.createDefaultField)(type, name, id);
44
+ };
45
+ const result = (0, fieldTreeOps_1.insertAtTargetDeep)(formFields, targetId, offset, makeField);
46
+ if (result === null) {
47
+ const fallback = makeField(false);
48
+ commit([...formFields, fallback]);
49
+ return;
50
+ }
51
+ commit(result);
52
+ }, [commit, formFields, generateId, generateName]);
53
+ const insertFieldBefore = React.useCallback((targetId, type) => insertFieldRelative(targetId, type, 0), [insertFieldRelative]);
54
+ const insertFieldAfter = React.useCallback((targetId, type) => insertFieldRelative(targetId, type, 1), [insertFieldRelative]);
55
+ const removeField = React.useCallback((fieldId) => {
56
+ commit((0, fieldTreeOps_1.removeFieldDeep)(formFields, fieldId));
57
+ }, [commit, formFields]);
58
+ const moveFieldToSection = React.useCallback((fieldId, targetSectionId) => {
59
+ if (fieldId === targetSectionId)
60
+ return;
61
+ const sourceField = (0, fieldTree_1.findFieldById)(formFields, fieldId);
62
+ if (!sourceField)
63
+ return;
64
+ const targetField = (0, fieldTree_1.findFieldById)(formFields, targetSectionId);
65
+ if (!targetField || targetField.type !== 'section') {
66
+ return;
67
+ }
68
+ if (sourceField.type === 'section' && (0, fieldTreeOps_1.containsId)(sourceField, targetSectionId)) {
69
+ return;
70
+ }
71
+ const withoutField = (0, fieldTreeOps_1.removeFieldDeep)(formFields, fieldId);
72
+ const targetIsArray = (0, fieldTreeOps_1.isArrayModeSection)(withoutField, targetSectionId);
73
+ let movedField = sourceField;
74
+ if (sourceField.type !== 'section' && sourceField.type !== 'text') {
75
+ const currentHasIndex = sourceField.name.includes('{{index}}');
76
+ if (targetIsArray && !currentHasIndex) {
77
+ movedField = {
78
+ ...sourceField,
79
+ name: (0, fieldNames_1.prefixNameForArrayMode)(sourceField.name),
80
+ };
81
+ }
82
+ else if (!targetIsArray && currentHasIndex) {
83
+ movedField = {
84
+ ...sourceField,
85
+ name: (0, fieldNames_1.stripArrayModePrefix)(sourceField.name),
86
+ };
87
+ }
88
+ }
89
+ const result = (0, fieldTreeOps_1.addChildToSectionDeep)(withoutField, targetSectionId, movedField);
90
+ commit(result);
91
+ }, [commit, formFields]);
92
+ const duplicateField = React.useCallback((fieldId) => {
93
+ const existingNames = (0, fieldNames_1.collectNames)(formFields);
94
+ const result = (0, fieldTreeOps_1.duplicateFieldDeep)(formFields, fieldId, generateId, existingNames);
95
+ if (result !== null) {
96
+ commit(result);
97
+ }
98
+ }, [commit, formFields, generateId]);
99
+ const updateField = React.useCallback((fieldId, updates) => {
100
+ commit((0, fieldTreeOps_1.updateFieldDeep)(formFields, fieldId, updates));
101
+ }, [commit, formFields]);
102
+ const moveFieldUp = React.useCallback((fieldId) => {
103
+ const result = (0, fieldTreeOps_1.swapInListDeep)(formFields, fieldId, -1);
104
+ if (result.handled) {
105
+ commit(result.fields);
106
+ }
107
+ }, [commit, formFields]);
108
+ const moveFieldDown = React.useCallback((fieldId) => {
109
+ const result = (0, fieldTreeOps_1.swapInListDeep)(formFields, fieldId, 1);
110
+ if (result.handled) {
111
+ commit(result.fields);
112
+ }
113
+ }, [commit, formFields]);
114
+ const setAllFields = React.useCallback((next) => {
115
+ idCounter.current = Math.max(idCounter.current, (0, fieldNames_1.maxIdNumericSuffix)(next) + 1);
116
+ commit(next);
117
+ }, [commit]);
118
+ const resetForm = React.useCallback(() => {
119
+ commit([]);
120
+ setSelectedFieldId(null);
121
+ }, [commit]);
122
+ const selectField = React.useCallback((fieldId) => {
123
+ setSelectedFieldId(fieldId);
124
+ }, []);
125
+ return {
126
+ formFields,
127
+ selectedFieldId,
128
+ addField,
129
+ addFieldToSection,
130
+ insertFieldBefore,
131
+ insertFieldAfter,
132
+ moveFieldToSection,
133
+ removeField,
134
+ duplicateField,
135
+ updateField,
136
+ moveFieldUp,
137
+ moveFieldDown,
138
+ setAllFields,
139
+ resetForm,
140
+ selectField,
141
+ };
142
+ };
143
+ exports.useFormFields = useFormFields;
144
+ //# sourceMappingURL=useFormFields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormFields.js","sourceRoot":"../../../../src","sources":["form-builder-v2/hooks/useFormFields.ts"],"names":[],"mappings":";;;;AAAA,qDAA+B;AAG/B,6DAA0D;AAC1D,uDAK6B;AAC7B,qDAAiD;AACjD,2DAS+B;AAOxB,MAAM,aAAa,GAAG,CAAC,EAAC,aAAa,EAAE,QAAQ,EAAqB,EAAE,EAAE;IAC3E,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAc,aAAa,CAAC,CAAC;IAC/E,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAgB,IAAI,CAAC,CAAC;IAClF,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAS,IAAA,+BAAkB,EAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;IAE9E,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QACtC,MAAM,EAAE,GAAG,OAAO,SAAS,CAAC,OAAO,EAAE,CAAC;QACtC,SAAS,CAAC,OAAO,IAAI,CAAC,CAAC;QACvB,OAAO,EAAE,CAAC;IACd,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,SAAS,SAAS,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;IAE/E,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,CAC5B,CAAC,IAAiB,EAAE,EAAE;QAClB,aAAa,CAAC,IAAI,CAAC,CAAC;QACpB,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC,EACD,CAAC,QAAQ,CAAC,CACb,CAAC;IAEF,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW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C,CAAC,CAAC;QACtD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC;IACL,CAAC,EACD,CAAC,MAAM,EAAE,UAAU,CAAC,CACvB,CAAC;IAEF,MAAM,YAAY,GAAG,KAAK,CAAC,WAAW,CAClC,CAAC,IAAiB,EAAE,EAAE;QAClB,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE,IAAA,+BAAkB,EAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9E,MAAM,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC,EACD,CAAC,MAAM,CAAC,CACX,CAAC;IAEF,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QACrC,MAAM,CAAC,EAAE,CAAC,CAAC;QACX,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,OAAsB,EAAE,EAAE;QAC7D,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACH,UAAU;QACV,eAAe;QACf,QAAQ;QACR,iBAAiB;QACjB,iBAAiB;QACjB,gBAAgB;QAChB,kBAAkB;QAClB,WAAW;QACX,cAAc;QACd,WAAW;QACX,WAAW;QACX,aAAa;QACb,YAAY;QACZ,SAAS;QACT,WAAW;KACd,CAAC;AACN,CAAC,CAAC;AAhMW,QAAA,aAAa,iBAgMxB","sourcesContent":["import * as React from 'react';\n\nimport {BuilderFieldType, FieldUpdate, FormField} from '../types';\nimport {createDefaultField} from '../utils/fieldDefaults';\nimport {\n collectNames,\n maxIdNumericSuffix,\n prefixNameForArrayMode,\n stripArrayModePrefix,\n} from '../utils/fieldNames';\nimport {findFieldById} from '../utils/fieldTree';\nimport {\n addChildToSectionDeep,\n containsId,\n duplicateFieldDeep,\n insertAtTargetDeep,\n isArrayModeSection,\n removeFieldDeep,\n swapInListDeep,\n updateFieldDeep,\n} from '../utils/fieldTreeOps';\n\ninterface UseFormFieldsProps {\n initialFields: FormField[];\n onChange?: (fields: FormField[]) => void;\n}\n\nexport const useFormFields = ({initialFields, onChange}: UseFormFieldsProps) => {\n const [formFields, setFormFields] = React.useState<FormField[]>(initialFields);\n const [selectedFieldId, setSelectedFieldId] = React.useState<string | null>(null);\n const idCounter = React.useRef<number>(maxIdNumericSuffix(initialFields) + 1);\n\n const generateId = React.useCallback(() => {\n const id = `fb2_${idCounter.current}`;\n idCounter.current += 1;\n return id;\n }, []);\n\n const generateName = React.useCallback(() => `field_${idCounter.current}`, []);\n\n const commit = React.useCallback(\n (next: FormField[]) => {\n setFormFields(next);\n onChange?.(next);\n },\n [onChange],\n );\n\n const addField = React.useCallback(\n (type: BuilderFieldType) => {\n const id = generateId();\n const name = generateName();\n const newField = createDefaultField(type, name, id);\n commit([...formFields, newField]);\n },\n [commit, formFields, generateId, generateName],\n );\n\n const addFieldToSection = React.useCallback(\n (sectionId: string, type: BuilderFieldType) => {\n const id = generateId();\n const baseName = generateName();\n const arrayMode = isArrayModeSection(formFields, sectionId);\n const name = arrayMode ? prefixNameForArrayMode(baseName) : baseName;\n const newChild = createDefaultField(type, name, id);\n commit(addChildToSectionDeep(formFields, sectionId, newChild));\n },\n [commit, formFields, generateId, generateName],\n );\n\n const insertFieldRelative = React.useCallback(\n (targetId: string, type: BuilderFieldType, offset: 0 | 1) => {\n const makeField = (arrayMode: boolean): FormField => {\n const id = generateId();\n const baseName = generateName();\n const name = arrayMode ? prefixNameForArrayMode(baseName) : baseName;\n return createDefaultField(type, name, id);\n };\n const result = insertAtTargetDeep(formFields, targetId, offset, makeField);\n if (result === null) {\n const fallback = makeField(false);\n commit([...formFields, fallback]);\n return;\n }\n commit(result);\n },\n [commit, formFields, generateId, generateName],\n );\n\n const insertFieldBefore = React.useCallback(\n (targetId: string, type: BuilderFieldType) => insertFieldRelative(targetId, type, 0),\n [insertFieldRelative],\n );\n\n const insertFieldAfter = React.useCallback(\n (targetId: string, type: BuilderFieldType) => insertFieldRelative(targetId, type, 1),\n [insertFieldRelative],\n );\n\n const removeField = React.useCallback(\n (fieldId: string) => {\n commit(removeFieldDeep(formFields, fieldId));\n },\n [commit, formFields],\n );\n\n const moveFieldToSection = React.useCallback(\n (fieldId: string, targetSectionId: string) => {\n if (fieldId === targetSectionId) return;\n\n const sourceField = findFieldById(formFields, fieldId);\n if (!sourceField) return;\n\n const targetField = findFieldById(formFields, targetSectionId);\n if (!targetField || targetField.type !== 'section') {\n return;\n }\n\n if (sourceField.type === 'section' && containsId(sourceField, targetSectionId)) {\n return;\n }\n\n const withoutField = removeFieldDeep(formFields, fieldId);\n const targetIsArray = isArrayModeSection(withoutField, targetSectionId);\n\n let movedField = sourceField;\n if (sourceField.type !== 'section' && sourceField.type !== 'text') {\n const currentHasIndex = sourceField.name.includes('{{index}}');\n if (targetIsArray && !currentHasIndex) {\n movedField = {\n ...sourceField,\n name: prefixNameForArrayMode(sourceField.name),\n };\n } else if (!targetIsArray && currentHasIndex) {\n movedField = {\n ...sourceField,\n name: stripArrayModePrefix(sourceField.name),\n };\n }\n }\n\n const result = addChildToSectionDeep(withoutField, targetSectionId, movedField);\n commit(result);\n },\n [commit, formFields],\n );\n\n const duplicateField = React.useCallback(\n (fieldId: string) => {\n const existingNames = collectNames(formFields);\n const result = duplicateFieldDeep(formFields, fieldId, generateId, existingNames);\n if (result !== null) {\n commit(result);\n }\n },\n [commit, formFields, generateId],\n );\n\n const updateField = React.useCallback(\n (fieldId: string, updates: FieldUpdate) => {\n commit(updateFieldDeep(formFields, fieldId, updates));\n },\n [commit, formFields],\n );\n\n const moveFieldUp = React.useCallback(\n (fieldId: string) => {\n const result = swapInListDeep(formFields, fieldId, -1);\n if (result.handled) {\n commit(result.fields);\n }\n },\n [commit, formFields],\n );\n\n const moveFieldDown = React.useCallback(\n (fieldId: string) => {\n const result = swapInListDeep(formFields, fieldId, 1);\n if (result.handled) {\n commit(result.fields);\n }\n },\n [commit, formFields],\n );\n\n const setAllFields = React.useCallback(\n (next: FormField[]) => {\n idCounter.current = Math.max(idCounter.current, maxIdNumericSuffix(next) + 1);\n commit(next);\n },\n [commit],\n );\n\n const resetForm = React.useCallback(() => {\n commit([]);\n setSelectedFieldId(null);\n }, [commit]);\n\n const selectField = React.useCallback((fieldId: string | null) => {\n setSelectedFieldId(fieldId);\n }, []);\n\n return {\n formFields,\n selectedFieldId,\n addField,\n addFieldToSection,\n insertFieldBefore,\n insertFieldAfter,\n moveFieldToSection,\n removeField,\n duplicateField,\n updateField,\n moveFieldUp,\n moveFieldDown,\n setAllFields,\n resetForm,\n selectField,\n };\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export * from "./FormBuilderV2.js";
2
+ export * from "./types.js";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./FormBuilderV2.js"), exports);
5
+ tslib_1.__exportStar(require("./types.js"), exports);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"../../../src","sources":["form-builder-v2/index.ts"],"names":[],"mappings":";;;AAAA,6DAAgC;AAChC,qDAAwB","sourcesContent":["export * from './FormBuilderV2';\nexport * from './types';\n"]}
File without changes