@limetech/lime-elements 38.31.1 → 38.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +1 -1
  3. package/dist/cjs/lime-elements.cjs.js +1 -1
  4. package/dist/cjs/limel-action-bar_2.cjs.entry.js +1 -1
  5. package/dist/cjs/limel-ai-avatar.cjs.entry.js +1 -1
  6. package/dist/cjs/limel-callout.cjs.entry.js +1 -1
  7. package/dist/cjs/limel-chart.cjs.entry.js +1 -1
  8. package/dist/cjs/limel-checkbox.cjs.entry.js.map +1 -1
  9. package/dist/cjs/limel-chip_2.cjs.entry.js +1 -1
  10. package/dist/cjs/limel-collapsible-section.cjs.entry.js +1 -1
  11. package/dist/cjs/limel-color-picker.cjs.entry.js.map +1 -1
  12. package/dist/cjs/limel-drag-handle.cjs.entry.js +34 -0
  13. package/dist/cjs/limel-drag-handle.cjs.entry.js.map +1 -0
  14. package/dist/cjs/limel-file-viewer.cjs.entry.js +1 -1
  15. package/dist/cjs/limel-file.cjs.entry.js +1 -1
  16. package/dist/cjs/limel-flatpickr-adapter.cjs.entry.js +1 -1
  17. package/dist/cjs/limel-form.cjs.entry.js +3227 -307
  18. package/dist/cjs/limel-form.cjs.entry.js.map +1 -1
  19. package/dist/cjs/limel-info-tile.cjs.entry.js +1 -1
  20. package/dist/cjs/limel-info-tile.cjs.entry.js.map +1 -1
  21. package/dist/cjs/limel-linear-progress.cjs.entry.js +1 -1
  22. package/dist/cjs/limel-list-item.cjs.entry.js +1 -1
  23. package/dist/cjs/limel-portal_3.cjs.entry.js.map +1 -1
  24. package/dist/cjs/limel-profile-picture.cjs.entry.js +1 -1
  25. package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +1 -1
  26. package/dist/cjs/limel-snackbar.cjs.entry.js +1 -1
  27. package/dist/cjs/limel-snackbar.cjs.entry.js.map +1 -1
  28. package/dist/cjs/limel-switch.cjs.entry.js.map +1 -1
  29. package/dist/cjs/limel-table.cjs.entry.js +1 -1
  30. package/dist/cjs/loader.cjs.js +1 -1
  31. package/dist/cjs/{translations-d2be6dd7.js → translations-a42886f2.js} +17 -1
  32. package/dist/cjs/translations-a42886f2.js.map +1 -0
  33. package/dist/collection/collection-manifest.json +1 -0
  34. package/dist/collection/components/action-bar/action-bar-item/action-bar-item.css +3 -0
  35. package/dist/collection/components/action-bar/action-bar.css +3 -0
  36. package/dist/collection/components/badge/badge.css +3 -0
  37. package/dist/collection/components/breadcrumbs/breadcrumbs.css +3 -0
  38. package/dist/collection/components/button/button.css +3 -0
  39. package/dist/collection/components/button-group/button-group.css +3 -0
  40. package/dist/collection/components/card/card.css +3 -0
  41. package/dist/collection/components/chart/chart.css +6 -0
  42. package/dist/collection/components/checkbox/checkbox.css +3 -0
  43. package/dist/collection/components/checkbox/checkbox.js +1 -1
  44. package/dist/collection/components/checkbox/checkbox.js.map +1 -1
  45. package/dist/collection/components/chip/chip.css +3 -0
  46. package/dist/collection/components/chip-set/chip-set.css +6 -0
  47. package/dist/collection/components/circular-progress/circular-progress.css +3 -0
  48. package/dist/collection/components/code-editor/code-editor.css +3 -0
  49. package/dist/collection/components/collapsible-section/collapsible-section.css +3 -0
  50. package/dist/collection/components/color-picker/color-picker-palette.css +3 -0
  51. package/dist/collection/components/color-picker/color-picker.css +3 -0
  52. package/dist/collection/components/color-picker/color-picker.js +1 -1
  53. package/dist/collection/components/color-picker/color-picker.js.map +1 -1
  54. package/dist/collection/components/date-picker/flatpickr-adapter/flatpickr-adapter.css +3 -0
  55. package/dist/collection/components/dialog/dialog.css +3 -0
  56. package/dist/collection/components/dock/dock-button/dock-button.css +3 -0
  57. package/dist/collection/components/dock/dock.css +3 -0
  58. package/dist/collection/components/drag-handle/drag-handle.css +174 -0
  59. package/dist/collection/components/drag-handle/drag-handle.js +125 -0
  60. package/dist/collection/components/drag-handle/drag-handle.js.map +1 -0
  61. package/dist/collection/components/file/file.css +3 -0
  62. package/dist/collection/components/file-viewer/file-viewer.css +3 -0
  63. package/dist/collection/components/form/form.css +147 -20
  64. package/dist/collection/components/form/row/row.js +4 -1
  65. package/dist/collection/components/form/row/row.js.map +1 -1
  66. package/dist/collection/components/form/templates/array-field-collapsible-item.js +13 -16
  67. package/dist/collection/components/form/templates/array-field-collapsible-item.js.map +1 -1
  68. package/dist/collection/components/form/templates/array-field-simple-item.js +16 -49
  69. package/dist/collection/components/form/templates/array-field-simple-item.js.map +1 -1
  70. package/dist/collection/components/form/templates/array-field.js +306 -19
  71. package/dist/collection/components/form/templates/array-field.js.map +1 -1
  72. package/dist/collection/components/form/templates/common.js +3 -1
  73. package/dist/collection/components/form/templates/common.js.map +1 -1
  74. package/dist/collection/components/header/header.css +3 -0
  75. package/dist/collection/components/help/help.css +3 -0
  76. package/dist/collection/components/help/limel-help-content.css +3 -0
  77. package/dist/collection/components/icon-button/icon-button.css +3 -0
  78. package/dist/collection/components/info-tile/info-tile.css +3 -0
  79. package/dist/collection/components/input-field/input-field.css +3 -0
  80. package/dist/collection/components/list/list.css +6 -0
  81. package/dist/collection/components/list-item/list-item.css +3 -0
  82. package/dist/collection/components/list-item/menu-item-meta/menu-item-meta.css +3 -0
  83. package/dist/collection/components/markdown/markdown.css +3 -0
  84. package/dist/collection/components/menu-list/menu-list.css +6 -0
  85. package/dist/collection/components/notched-outline/notched-outline.css +3 -0
  86. package/dist/collection/components/popover-surface/popover-surface.css +3 -0
  87. package/dist/collection/components/profile-picture/profile-picture.css +3 -0
  88. package/dist/collection/components/progress-flow/progress-flow-item/progress-flow-item.css +3 -0
  89. package/dist/collection/components/radio-button-group/radio-button.css +3 -0
  90. package/dist/collection/components/select/select.css +6 -0
  91. package/dist/collection/components/shortcut/shortcut.css +3 -0
  92. package/dist/collection/components/slider/slider.css +3 -0
  93. package/dist/collection/components/snackbar/snackbar.js +2 -2
  94. package/dist/collection/components/snackbar/snackbar.js.map +1 -1
  95. package/dist/collection/components/split-button/split-button.css +3 -0
  96. package/dist/collection/components/switch/switch.css +3 -0
  97. package/dist/collection/components/switch/switch.js +1 -1
  98. package/dist/collection/components/switch/switch.js.map +1 -1
  99. package/dist/collection/components/tab-bar/tab-bar.css +3 -0
  100. package/dist/collection/components/table/table.css +12 -0
  101. package/dist/collection/components/text-editor/prosemirror-adapter/prosemirror-adapter.css +3 -0
  102. package/dist/collection/components/text-editor/text-editor.css +3 -0
  103. package/dist/collection/components/tooltip/tooltip.js +2 -2
  104. package/dist/collection/components/tooltip/tooltip.js.map +1 -1
  105. package/dist/collection/style/mixins.scss +53 -0
  106. package/dist/collection/translations/da.js +2 -0
  107. package/dist/collection/translations/da.js.map +1 -1
  108. package/dist/collection/translations/de.js +2 -0
  109. package/dist/collection/translations/de.js.map +1 -1
  110. package/dist/collection/translations/en.js +2 -0
  111. package/dist/collection/translations/en.js.map +1 -1
  112. package/dist/collection/translations/fi.js +2 -0
  113. package/dist/collection/translations/fi.js.map +1 -1
  114. package/dist/collection/translations/fr.js +2 -0
  115. package/dist/collection/translations/fr.js.map +1 -1
  116. package/dist/collection/translations/nl.js +2 -0
  117. package/dist/collection/translations/nl.js.map +1 -1
  118. package/dist/collection/translations/no.js +2 -0
  119. package/dist/collection/translations/no.js.map +1 -1
  120. package/dist/collection/translations/sv.js +2 -0
  121. package/dist/collection/translations/sv.js.map +1 -1
  122. package/dist/esm/lime-elements.js +1 -1
  123. package/dist/esm/limel-action-bar_2.entry.js +1 -1
  124. package/dist/esm/limel-ai-avatar.entry.js +1 -1
  125. package/dist/esm/limel-callout.entry.js +1 -1
  126. package/dist/esm/limel-chart.entry.js +1 -1
  127. package/dist/esm/limel-checkbox.entry.js.map +1 -1
  128. package/dist/esm/limel-chip_2.entry.js +1 -1
  129. package/dist/esm/limel-collapsible-section.entry.js +1 -1
  130. package/dist/esm/limel-color-picker.entry.js.map +1 -1
  131. package/dist/esm/limel-drag-handle.entry.js +30 -0
  132. package/dist/esm/limel-drag-handle.entry.js.map +1 -0
  133. package/dist/esm/limel-file-viewer.entry.js +1 -1
  134. package/dist/esm/limel-file.entry.js +1 -1
  135. package/dist/esm/limel-flatpickr-adapter.entry.js +1 -1
  136. package/dist/esm/limel-form.entry.js +3221 -301
  137. package/dist/esm/limel-form.entry.js.map +1 -1
  138. package/dist/esm/limel-info-tile.entry.js +1 -1
  139. package/dist/esm/limel-info-tile.entry.js.map +1 -1
  140. package/dist/esm/limel-linear-progress.entry.js +1 -1
  141. package/dist/esm/limel-list-item.entry.js +1 -1
  142. package/dist/esm/limel-portal_3.entry.js.map +1 -1
  143. package/dist/esm/limel-profile-picture.entry.js +1 -1
  144. package/dist/esm/limel-prosemirror-adapter.entry.js +1 -1
  145. package/dist/esm/limel-snackbar.entry.js +1 -1
  146. package/dist/esm/limel-snackbar.entry.js.map +1 -1
  147. package/dist/esm/limel-switch.entry.js.map +1 -1
  148. package/dist/esm/limel-table.entry.js +1 -1
  149. package/dist/esm/loader.js +1 -1
  150. package/dist/esm/{translations-91c611da.js → translations-9bfde9f4.js} +17 -1
  151. package/dist/esm/translations-9bfde9f4.js.map +1 -0
  152. package/dist/lime-elements/lime-elements.esm.js +1 -1
  153. package/dist/lime-elements/lime-elements.esm.js.map +1 -1
  154. package/dist/lime-elements/p-309d0652.entry.js +2 -0
  155. package/dist/lime-elements/{p-e6245ef7.entry.js.map → p-309d0652.entry.js.map} +1 -1
  156. package/dist/lime-elements/{p-f507000e.entry.js → p-31f1cb08.entry.js} +2 -2
  157. package/dist/lime-elements/{p-cc7f4c81.entry.js → p-3311eaf3.entry.js} +2 -2
  158. package/dist/lime-elements/{p-aeba4aa4.entry.js → p-40542ccc.entry.js} +2 -2
  159. package/dist/lime-elements/p-40542ccc.entry.js.map +1 -0
  160. package/dist/lime-elements/{p-d349e355.entry.js → p-42e889d8.entry.js} +2 -2
  161. package/dist/lime-elements/p-489d7f63.entry.js.map +1 -1
  162. package/dist/lime-elements/p-51d475d8.entry.js.map +1 -1
  163. package/dist/lime-elements/p-5df2361b.js +2 -0
  164. package/dist/lime-elements/p-5df2361b.js.map +1 -0
  165. package/dist/lime-elements/{p-b5abf284.entry.js → p-5e976a59.entry.js} +2 -2
  166. package/dist/lime-elements/{p-6c60172e.entry.js → p-787be044.entry.js} +2 -2
  167. package/dist/lime-elements/p-8539647d.entry.js.map +1 -1
  168. package/dist/lime-elements/p-8ea3b80a.entry.js +2 -0
  169. package/dist/lime-elements/p-8ea3b80a.entry.js.map +1 -0
  170. package/dist/lime-elements/{p-d1aa44e1.entry.js → p-92aa9610.entry.js} +2 -2
  171. package/dist/lime-elements/p-a1a32893.entry.js +27 -0
  172. package/dist/lime-elements/p-a1a32893.entry.js.map +1 -0
  173. package/dist/lime-elements/{p-8e3c4418.entry.js → p-aa1e7319.entry.js} +2 -2
  174. package/dist/lime-elements/{p-ed04acfc.entry.js → p-b0acf522.entry.js} +2 -2
  175. package/dist/lime-elements/p-b5a96409.entry.js.map +1 -1
  176. package/dist/lime-elements/{p-f83ebd28.entry.js → p-b7bbb6a5.entry.js} +2 -2
  177. package/dist/lime-elements/{p-eb396630.entry.js → p-cd2f780a.entry.js} +2 -2
  178. package/dist/lime-elements/{p-aae161ef.entry.js → p-d79c85e2.entry.js} +2 -2
  179. package/dist/lime-elements/{p-1b036add.entry.js → p-e00465fa.entry.js} +2 -2
  180. package/dist/lime-elements/{p-29c2cdc6.entry.js → p-ee5c4112.entry.js} +2 -2
  181. package/dist/lime-elements/{p-e6bb4d1a.entry.js → p-fbac230b.entry.js} +2 -2
  182. package/dist/lime-elements/style/mixins.scss +53 -0
  183. package/dist/scss/mixins.scss +53 -0
  184. package/dist/types/components/checkbox/checkbox.d.ts +1 -1
  185. package/dist/types/components/color-picker/color-picker.d.ts +1 -1
  186. package/dist/types/components/drag-handle/drag-handle.d.ts +46 -0
  187. package/dist/types/components/form/templates/array-field-collapsible-item.d.ts +3 -1
  188. package/dist/types/components/form/templates/array-field-simple-item.d.ts +5 -9
  189. package/dist/types/components/form/templates/array-field.d.ts +35 -4
  190. package/dist/types/components/form/templates/common.d.ts +3 -3
  191. package/dist/types/components/snackbar/snackbar.d.ts +2 -2
  192. package/dist/types/components/switch/switch.d.ts +1 -1
  193. package/dist/types/components/tooltip/tooltip.d.ts +2 -2
  194. package/dist/types/components.d.ts +141 -28
  195. package/dist/types/translations/da.d.ts +2 -0
  196. package/dist/types/translations/de.d.ts +2 -0
  197. package/dist/types/translations/en.d.ts +2 -0
  198. package/dist/types/translations/fi.d.ts +2 -0
  199. package/dist/types/translations/fr.d.ts +2 -0
  200. package/dist/types/translations/nl.d.ts +2 -0
  201. package/dist/types/translations/no.d.ts +2 -0
  202. package/dist/types/translations/sv.d.ts +2 -0
  203. package/package.json +5 -2
  204. package/dist/cjs/translations-d2be6dd7.js.map +0 -1
  205. package/dist/esm/translations-91c611da.js.map +0 -1
  206. package/dist/lime-elements/p-4c88e5d3.js +0 -2
  207. package/dist/lime-elements/p-4c88e5d3.js.map +0 -1
  208. package/dist/lime-elements/p-aeba4aa4.entry.js.map +0 -1
  209. package/dist/lime-elements/p-d6d66daa.entry.js +0 -21
  210. package/dist/lime-elements/p-d6d66daa.entry.js.map +0 -1
  211. package/dist/lime-elements/p-e6245ef7.entry.js +0 -2
  212. /package/dist/lime-elements/{p-f507000e.entry.js.map → p-31f1cb08.entry.js.map} +0 -0
  213. /package/dist/lime-elements/{p-cc7f4c81.entry.js.map → p-3311eaf3.entry.js.map} +0 -0
  214. /package/dist/lime-elements/{p-d349e355.entry.js.map → p-42e889d8.entry.js.map} +0 -0
  215. /package/dist/lime-elements/{p-b5abf284.entry.js.map → p-5e976a59.entry.js.map} +0 -0
  216. /package/dist/lime-elements/{p-6c60172e.entry.js.map → p-787be044.entry.js.map} +0 -0
  217. /package/dist/lime-elements/{p-d1aa44e1.entry.js.map → p-92aa9610.entry.js.map} +0 -0
  218. /package/dist/lime-elements/{p-8e3c4418.entry.js.map → p-aa1e7319.entry.js.map} +0 -0
  219. /package/dist/lime-elements/{p-ed04acfc.entry.js.map → p-b0acf522.entry.js.map} +0 -0
  220. /package/dist/lime-elements/{p-f83ebd28.entry.js.map → p-b7bbb6a5.entry.js.map} +0 -0
  221. /package/dist/lime-elements/{p-eb396630.entry.js.map → p-cd2f780a.entry.js.map} +0 -0
  222. /package/dist/lime-elements/{p-aae161ef.entry.js.map → p-d79c85e2.entry.js.map} +0 -0
  223. /package/dist/lime-elements/{p-1b036add.entry.js.map → p-e00465fa.entry.js.map} +0 -0
  224. /package/dist/lime-elements/{p-29c2cdc6.entry.js.map → p-ee5c4112.entry.js.map} +0 -0
  225. /package/dist/lime-elements/{p-e6bb4d1a.entry.js.map → p-fbac230b.entry.js.map} +0 -0
@@ -8,14 +8,6 @@ export class SimpleItemTemplate extends React.Component {
8
8
  const { item, index } = this.props;
9
9
  item.onDropIndexClick(index)(event);
10
10
  };
11
- this.handleMoveUp = (event) => {
12
- const { item, index } = this.props;
13
- item.onReorderClick(index, index - 1)(event);
14
- };
15
- this.handleMoveDown = (event) => {
16
- const { item, index } = this.props;
17
- item.onReorderClick(index, index + 1)(event);
18
- };
19
11
  this.setRemoveButton = (button) => {
20
12
  if (this.removeButton) {
21
13
  this.removeButton.removeEventListener('click', this.handleRemove);
@@ -25,39 +17,30 @@ export class SimpleItemTemplate extends React.Component {
25
17
  this.removeButton.addEventListener('click', this.handleRemove);
26
18
  }
27
19
  };
28
- this.setMoveUpButton = (button) => {
29
- if (this.moveUpButton) {
30
- this.moveUpButton.removeEventListener('click', this.handleMoveUp);
31
- }
32
- this.moveUpButton = button || undefined;
33
- if (this.moveUpButton) {
34
- this.moveUpButton.addEventListener('click', this.handleMoveUp);
35
- }
36
- };
37
- this.setMoveDownButton = (button) => {
38
- if (this.moveDownButton) {
39
- this.moveDownButton.removeEventListener('click', this.handleMoveDown);
40
- }
41
- this.moveDownButton = button || undefined;
42
- if (this.moveDownButton) {
43
- this.moveDownButton.addEventListener('click', this.handleMoveDown);
44
- }
45
- };
46
20
  }
47
21
  componentWillUnmount() {
48
22
  this.setRemoveButton(undefined);
49
- this.setMoveUpButton(undefined);
50
- this.setMoveDownButton(undefined);
51
23
  }
52
24
  render() {
53
- const { item } = this.props;
25
+ const { item, allowItemReorder } = this.props;
54
26
  return React.createElement('div', {
55
- className: 'limel-form-array-item--simple',
56
- }, this.props.item.children, this.props.allowItemReorder
57
- ? this.renderMoveDownButton(item)
58
- : null, this.props.allowItemReorder ? this.renderMoveUpButton(item) : null, this.props.allowItemRemoval ? this.renderRemoveButton(item) : null);
27
+ className: 'array-item limel-form-array-item--simple',
28
+ 'data-reorder-id': String(this.props.dataIndex),
29
+ 'data-reorderable': allowItemReorder ? 'true' : 'false',
30
+ }, this.props.item.children, this.renderRemoveButton(item), this.renderDragHandle());
31
+ }
32
+ renderDragHandle() {
33
+ if (!this.props.allowItemReorder) {
34
+ return;
35
+ }
36
+ return React.createElement('limel-drag-handle', {
37
+ class: 'drag-handle',
38
+ });
59
39
  }
60
40
  renderRemoveButton(item) {
41
+ if (!this.props.allowItemRemoval) {
42
+ return;
43
+ }
61
44
  const props = {
62
45
  icon: 'trash',
63
46
  disabled: !item.hasRemove,
@@ -65,21 +48,5 @@ export class SimpleItemTemplate extends React.Component {
65
48
  };
66
49
  return React.createElement(LIMEL_ICON_BUTTON, props);
67
50
  }
68
- renderMoveUpButton(item) {
69
- const props = {
70
- icon: 'up_arrow',
71
- disabled: !item.hasMoveUp,
72
- ref: this.setMoveUpButton,
73
- };
74
- return React.createElement(LIMEL_ICON_BUTTON, props);
75
- }
76
- renderMoveDownButton(item) {
77
- const props = {
78
- icon: 'down_arrow',
79
- disabled: !item.hasMoveDown,
80
- ref: this.setMoveDownButton,
81
- };
82
- return React.createElement(LIMEL_ICON_BUTTON, props);
83
- }
84
51
  }
85
52
  //# sourceMappingURL=array-field-simple-item.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"array-field-simple-item.js","sourceRoot":"","sources":["../../../../src/components/form/templates/array-field-simple-item.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO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IAAI,EACV,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAClE,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CACrE,CAAC;EACN,CAAC;EAEO,kBAAkB,CAAC,IAAoB;IAC3C,MAAM,KAAK,GAAQ;MACf,IAAI,EAAE,OAAO;MACb,QAAQ,EAAE,CAAC,IAAI,CAAC,SAAS;MACzB,GAAG,EAAE,IAAI,CAAC,eAAe;KAC5B,CAAC;IAEF,OAAO,KAAK,CAAC,aAAa,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;EACzD,CAAC;EAEO,kBAAkB,CAAC,IAAoB;IAC3C,MAAM,KAAK,GAAQ;MACf,IAAI,EAAE,UAAU;MAChB,QAAQ,EAAE,CAAC,IAAI,CAAC,SAAS;MACzB,GAAG,EAAE,IAAI,CAAC,eAAe;KAC5B,CAAC;IAEF,OAAO,KAAK,CAAC,aAAa,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;EACzD,CAAC;EAEO,oBAAoB,CAAC,IAAoB;IAC7C,MAAM,KAAK,GAAQ;MACf,IAAI,EAAE,YAAY;MAClB,QAAQ,EAAE,CAAC,IAAI,CAAC,WAAW;MAC3B,GAAG,EAAE,IAAI,CAAC,iBAAiB;KAC9B,CAAC;IAEF,OAAO,KAAK,CAAC,aAAa,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;EACzD,CAAC;CAuDJ","sourcesContent":["import React from 'react';\nimport { ArrayFieldItem } from './types';\n\ninterface SimpleItemProps {\n item: ArrayFieldItem;\n index: number;\n allowItemRemoval: boolean;\n allowItemReorder: boolean;\n}\n\nconst LIMEL_ICON_BUTTON = 'limel-icon-button';\n\nexport class SimpleItemTemplate extends React.Component<SimpleItemProps> {\n constructor(public props: SimpleItemProps) {\n super(props);\n }\n\n private removeButton?: HTMLLimelButtonElement;\n private moveUpButton?: HTMLLimelButtonElement;\n private moveDownButton?: HTMLLimelButtonElement;\n\n public componentWillUnmount() {\n this.setRemoveButton(undefined);\n this.setMoveUpButton(undefined);\n this.setMoveDownButton(undefined);\n }\n\n public render() {\n const { item } = this.props;\n\n return React.createElement(\n 'div',\n {\n className: 'limel-form-array-item--simple',\n },\n this.props.item.children,\n this.props.allowItemReorder\n ? this.renderMoveDownButton(item)\n : null,\n this.props.allowItemReorder ? this.renderMoveUpButton(item) : null,\n this.props.allowItemRemoval ? this.renderRemoveButton(item) : null\n );\n }\n\n private renderRemoveButton(item: ArrayFieldItem) {\n const props: any = {\n icon: 'trash',\n disabled: !item.hasRemove,\n ref: this.setRemoveButton,\n };\n\n return React.createElement(LIMEL_ICON_BUTTON, props);\n }\n\n private renderMoveUpButton(item: ArrayFieldItem) {\n const props: any = {\n icon: 'up_arrow',\n disabled: !item.hasMoveUp,\n ref: this.setMoveUpButton,\n };\n\n return React.createElement(LIMEL_ICON_BUTTON, props);\n }\n\n private renderMoveDownButton(item: ArrayFieldItem) {\n const props: any = {\n icon: 'down_arrow',\n disabled: !item.hasMoveDown,\n ref: this.setMoveDownButton,\n };\n\n return React.createElement(LIMEL_ICON_BUTTON, props);\n }\n\n private handleRemove = (event: PointerEvent): void => {\n const { item, index } = this.props;\n item.onDropIndexClick(index)(event);\n };\n\n private handleMoveUp = (event: PointerEvent): void => {\n const { item, index } = this.props;\n item.onReorderClick(index, index - 1)(event);\n };\n\n private handleMoveDown = (event: PointerEvent): void => {\n const { item, index } = this.props;\n item.onReorderClick(index, index + 1)(event);\n };\n\n private setRemoveButton = (button?: HTMLLimelButtonElement | null) => {\n if (this.removeButton) {\n this.removeButton.removeEventListener('click', this.handleRemove);\n }\n\n this.removeButton = button || undefined;\n\n if (this.removeButton) {\n this.removeButton.addEventListener('click', this.handleRemove);\n }\n };\n\n private setMoveUpButton = (button?: HTMLLimelButtonElement | null) => {\n if (this.moveUpButton) {\n this.moveUpButton.removeEventListener('click', this.handleMoveUp);\n }\n\n this.moveUpButton = button || undefined;\n\n if (this.moveUpButton) {\n this.moveUpButton.addEventListener('click', this.handleMoveUp);\n }\n };\n\n private setMoveDownButton = (button?: HTMLLimelButtonElement | null) => {\n if (this.moveDownButton) {\n this.moveDownButton.removeEventListener(\n 'click',\n this.handleMoveDown\n );\n }\n\n this.moveDownButton = button || undefined;\n\n if (this.moveDownButton) {\n this.moveDownButton.addEventListener('click', this.handleMoveDown);\n }\n };\n}\n"]}
1
+ {"version":3,"file":"array-field-simple-item.js","sourceRoot":"","sources":["../../../../src/components/form/templates/array-field-simple-item.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAW1B,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAE9C,MAAM,OAAO,kBAAmB,SAAQ,KAAK,CAAC,SAA0B;EACpE,YAAmB,KAAsB;IACrC,KAAK,CAAC,KAAK,CAAC,CAAC;IADE,UAAK,GAAL,KAAK,CAAiB;IAkDjC,iBAAY,GAAG,CAAC,KAAmB,EAAQ,EAAE;MACjD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;MACnC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC,CAAC;IAEe,oBAAe,GAAG,CAC/B,MAA0C,EAC5C,EAAE;MACA,IAAI,IAAI,CAAC,YAAY,EAAE;QACnB,IAAI,CAAC,YAAY,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;OACrE;MAED,IAAI,CAAC,YAAY,GAAG,MAAM,IAAI,SAAS,CAAC;MAExC,IAAI,IAAI,CAAC,YAAY,EAAE;QACnB,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;OAClE;IACL,CAAC,CAAC;EAjEF,CAAC;EAIM,oBAAoB;IACvB,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;EACpC,CAAC;EAEM,MAAM;IACT,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;IAE9C,OAAO,KAAK,CAAC,aAAa,CACtB,KAAK,EACL;MACI,SAAS,EAAE,0CAA0C;MACrD,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;MAC/C,kBAAkB,EAAE,gBAAgB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;KAC1D,EACD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EACxB,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAC7B,IAAI,CAAC,gBAAgB,EAAE,CAC1B,CAAC;EACN,CAAC;EAEO,gBAAgB;IACpB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE;MAC9B,OAAO;KACV;IAED,OAAO,KAAK,CAAC,aAAa,CAAC,mBAAmB,EAAE;MAC5C,KAAK,EAAE,aAAa;KACvB,CAAC,CAAC;EACP,CAAC;EAEO,kBAAkB,CAAC,IAAoB;IAC3C,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE;MAC9B,OAAO;KACV;IAED,MAAM,KAAK,GAAQ;MACf,IAAI,EAAE,OAAO;MACb,QAAQ,EAAE,CAAC,IAAI,CAAC,SAAS;MACzB,GAAG,EAAE,IAAI,CAAC,eAAe;KAC5B,CAAC;IAEF,OAAO,KAAK,CAAC,aAAa,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;EACzD,CAAC;CAoBJ","sourcesContent":["import React from 'react';\nimport { ArrayFieldItem } from './types';\n\ninterface SimpleItemProps {\n item: ArrayFieldItem;\n index: number;\n allowItemRemoval: boolean;\n allowItemReorder: boolean;\n dataIndex: number;\n}\n\nconst LIMEL_ICON_BUTTON = 'limel-icon-button';\n\nexport class SimpleItemTemplate extends React.Component<SimpleItemProps> {\n constructor(public props: SimpleItemProps) {\n super(props);\n }\n\n private removeButton?: HTMLLimelIconButtonElement;\n\n public componentWillUnmount() {\n this.setRemoveButton(undefined);\n }\n\n public render() {\n const { item, allowItemReorder } = this.props;\n\n return React.createElement(\n 'div',\n {\n className: 'array-item limel-form-array-item--simple',\n 'data-reorder-id': String(this.props.dataIndex),\n 'data-reorderable': allowItemReorder ? 'true' : 'false',\n },\n this.props.item.children,\n this.renderRemoveButton(item),\n this.renderDragHandle()\n );\n }\n\n private renderDragHandle() {\n if (!this.props.allowItemReorder) {\n return;\n }\n\n return React.createElement('limel-drag-handle', {\n class: 'drag-handle',\n });\n }\n\n private renderRemoveButton(item: ArrayFieldItem) {\n if (!this.props.allowItemRemoval) {\n return;\n }\n\n const props: any = {\n icon: 'trash',\n disabled: !item.hasRemove,\n ref: this.setRemoveButton,\n };\n\n return React.createElement(LIMEL_ICON_BUTTON, props);\n }\n\n private handleRemove = (event: PointerEvent): void => {\n const { item, index } = this.props;\n item.onDropIndexClick(index)(event);\n };\n\n private readonly setRemoveButton = (\n button?: HTMLLimelIconButtonElement | null\n ) => {\n if (this.removeButton) {\n this.removeButton.removeEventListener('click', this.handleRemove);\n }\n\n this.removeButton = button || undefined;\n\n if (this.removeButton) {\n this.removeButton.addEventListener('click', this.handleRemove);\n }\n };\n}\n"]}
@@ -3,15 +3,128 @@ import { isObjectType } from '../schema';
3
3
  import { CollapsibleItemTemplate } from './array-field-collapsible-item';
4
4
  import { SimpleItemTemplate } from './array-field-simple-item';
5
5
  import { renderDescription, renderTitle } from './common';
6
+ import Sortable from 'sortablejs';
7
+ const DRAG_HANDLE_SELECTOR = '[data-drag-handle]';
8
+ const DRAGGABLE_ITEM_SELECTOR = '.array-item[data-reorderable="true"]';
9
+ const DEFAULT_CONTAINER_CLASS = 'has-an-item-which-is-being-dragged';
10
+ const DEFAULT_DROP_ELEVATION_CLASS = 'is-elevated';
11
+ const DROP_ELEVATION_DURATION = 1000;
12
+ const TOUCH_DRAG_DELAY_MS = 200; // Adds a short hold on touch (long-press) so scroll gestures do not reorder items.
6
13
  export class ArrayFieldTemplate extends React.Component {
7
14
  constructor(props) {
8
15
  super(props);
9
- this.props = props;
10
- this.renderItem = this.renderItem.bind(this);
11
- this.handleAddClick = this.handleAddClick.bind(this);
16
+ this.itemByIndex = new Map();
17
+ this.handleAddClick = (event) => {
18
+ event.stopPropagation();
19
+ this.props.onAddClick(event);
20
+ };
21
+ this.setContainer = (element) => {
22
+ if (this.container === element) {
23
+ return;
24
+ }
25
+ this.teardownDragController();
26
+ this.container = element !== null && element !== void 0 ? element : undefined;
27
+ this.setupDragController();
28
+ };
29
+ this.handleSortStart = (event) => {
30
+ if (!this.canReorderItems()) {
31
+ return;
32
+ }
33
+ this.dragSnapshot = [...this.state.order];
34
+ this.draggedItemIndex = this.getReorderId(event.item);
35
+ if (this.container) {
36
+ this.container.classList.add(DEFAULT_CONTAINER_CLASS);
37
+ }
38
+ if (event.item instanceof HTMLElement) {
39
+ this.applyDropElevation(event.item);
40
+ }
41
+ };
42
+ this.handleSortEnd = (event) => {
43
+ var _a;
44
+ if (!this.canReorderItems()) {
45
+ return;
46
+ }
47
+ if (this.container) {
48
+ this.container.classList.remove(DEFAULT_CONTAINER_CLASS);
49
+ }
50
+ const snapshot = this.dragSnapshot;
51
+ const draggedItemIndex = this.draggedItemIndex;
52
+ this.dragSnapshot = undefined;
53
+ this.draggedItemIndex = undefined;
54
+ if (event.item instanceof HTMLElement) {
55
+ this.dropElevationTarget = event.item;
56
+ }
57
+ const finalOrder = this.readOrderFromDom();
58
+ if (!this.arraysEqual(this.state.order, finalOrder)) {
59
+ this.setState({ order: finalOrder });
60
+ }
61
+ if (snapshot === undefined ||
62
+ draggedItemIndex === undefined ||
63
+ !(event.item instanceof HTMLElement)) {
64
+ this.scheduleDropElevationRemoval();
65
+ return;
66
+ }
67
+ const fromPosition = snapshot.indexOf(draggedItemIndex);
68
+ const toPosition = finalOrder.indexOf(draggedItemIndex);
69
+ if (fromPosition === -1 ||
70
+ toPosition === -1 ||
71
+ fromPosition === toPosition) {
72
+ this.scheduleDropElevationRemoval();
73
+ return;
74
+ }
75
+ const targetItem = ((_a = this.props.items) !== null && _a !== void 0 ? _a : []).find((entry) => {
76
+ var _a;
77
+ return ((_a = entry.index) !== null && _a !== void 0 ? _a : -1) === draggedItemIndex;
78
+ });
79
+ if (!targetItem || typeof targetItem.onReorderClick !== 'function') {
80
+ this.scheduleDropElevationRemoval();
81
+ return;
82
+ }
83
+ requestAnimationFrame(() => {
84
+ const reorder = targetItem.onReorderClick(draggedItemIndex, toPosition);
85
+ if (typeof reorder === 'function') {
86
+ reorder();
87
+ }
88
+ });
89
+ this.scheduleDropElevationRemoval();
90
+ };
91
+ this.state = {
92
+ order: this.extractIndices(props.items),
93
+ };
94
+ }
95
+ componentWillUnmount() {
96
+ this.teardownDragController();
97
+ }
98
+ componentDidMount() {
99
+ this.setupDragController();
100
+ }
101
+ componentDidUpdate(previousProps) {
102
+ if (previousProps.items !== this.props.items) {
103
+ const nextOrder = this.extractIndices(this.props.items);
104
+ if (!this.arraysEqual(this.state.order, nextOrder)) {
105
+ this.setState({
106
+ order: nextOrder,
107
+ }, () => {
108
+ this.setupDragController();
109
+ });
110
+ return;
111
+ }
112
+ }
113
+ if (previousProps.items !== this.props.items ||
114
+ previousProps.schema !== this.props.schema ||
115
+ previousProps.disabled !== this.props.disabled ||
116
+ previousProps.readonly !== this.props.readonly) {
117
+ this.setupDragController();
118
+ }
12
119
  }
13
120
  render() {
14
- return React.createElement('div', {}, renderTitle(this.props.title), renderDescription(this.props.schema.description), this.props.items.map(this.renderItem), this.renderAddButton());
121
+ const controls = this.getItemControls();
122
+ const { ordered: orderedItems, byIndex } = this.getOrderedItems();
123
+ this.itemByIndex = byIndex;
124
+ return React.createElement('div', {}, renderTitle(this.props.title), renderDescription(this.props.schema.description), React.createElement('div', {
125
+ className: 'array-items',
126
+ ref: this.setContainer,
127
+ }, orderedItems.map((item, index) => this.renderItem(item, index, controls))), this.renderAddButton());
15
128
  }
16
129
  renderAddButton() {
17
130
  if (!this.props.canAdd) {
@@ -24,40 +137,214 @@ export class ArrayFieldTemplate extends React.Component {
24
137
  class: 'button-add-new',
25
138
  });
26
139
  }
27
- renderItem(item, index) {
140
+ getItemControls() {
141
+ return {
142
+ allowItemRemoval: this.canRemoveItems(),
143
+ };
144
+ }
145
+ renderItem(item, index, controls) {
146
+ var _a;
28
147
  const { schema, formData, formContext } = this.props;
29
- const controls = this.getItemControls();
148
+ const itemIndex = (_a = item.index) !== null && _a !== void 0 ? _a : index;
149
+ const allowItemReorder = this.isItemReorderable(item);
30
150
  if (isObjectType(schema.items)) {
31
151
  return React.createElement(CollapsibleItemTemplate, {
32
152
  key: item.key,
33
153
  item: item,
34
- data: formData[index],
154
+ data: Array.isArray(formData) ? formData[itemIndex] : undefined,
35
155
  schema: schema,
36
156
  formSchema: formContext.schema,
37
- index: index,
157
+ index: itemIndex,
38
158
  allowItemRemoval: controls.allowItemRemoval,
39
- allowItemReorder: controls.allowItemReorder,
159
+ allowItemReorder: allowItemReorder,
40
160
  });
41
161
  }
42
162
  return React.createElement(SimpleItemTemplate, {
43
163
  key: item.key,
44
164
  item: item,
45
- index: index,
165
+ index: itemIndex,
166
+ dataIndex: itemIndex,
46
167
  allowItemRemoval: controls.allowItemRemoval,
47
- allowItemReorder: controls.allowItemReorder,
168
+ allowItemReorder: allowItemReorder,
48
169
  });
49
170
  }
50
- getItemControls() {
51
- var _a;
52
- const limeOptions = ((_a = this.props.schema) === null || _a === void 0 ? void 0 : _a.lime) || {};
171
+ getOrderedItems() {
172
+ var _a, _b;
173
+ const items = (_a = this.props.items) !== null && _a !== void 0 ? _a : [];
174
+ const byIndex = new Map();
175
+ let entryIndex = 0;
176
+ for (const entry of items) {
177
+ byIndex.set((_b = entry.index) !== null && _b !== void 0 ? _b : entryIndex, entry);
178
+ entryIndex += 1;
179
+ }
180
+ const ordered = [];
181
+ const used = new Set();
182
+ for (const index of this.state.order) {
183
+ const entry = byIndex.get(index);
184
+ if (!entry) {
185
+ continue;
186
+ }
187
+ ordered.push(entry);
188
+ used.add(index);
189
+ }
190
+ for (const [index, entry] of byIndex.entries()) {
191
+ if (!used.has(index)) {
192
+ ordered.push(entry);
193
+ }
194
+ }
53
195
  return {
54
- allowItemRemoval: limeOptions.allowItemRemoval !== false,
55
- allowItemReorder: limeOptions.allowItemReorder !== false,
196
+ ordered,
197
+ byIndex,
56
198
  };
57
199
  }
58
- handleAddClick(event) {
59
- event.stopPropagation();
60
- this.props.onAddClick(event);
200
+ setupDragController() {
201
+ if (!this.container || !this.canReorderItems()) {
202
+ this.teardownDragController();
203
+ return;
204
+ }
205
+ const reorderableCount = this.getReorderableOrder().length;
206
+ if (reorderableCount < 2) {
207
+ this.teardownDragController();
208
+ return;
209
+ }
210
+ if (this.sortable) {
211
+ this.sortable.option('handle', DRAG_HANDLE_SELECTOR);
212
+ this.sortable.option('draggable', DRAGGABLE_ITEM_SELECTOR);
213
+ this.sortable.option('disabled', false);
214
+ this.sortable.option('delay', TOUCH_DRAG_DELAY_MS);
215
+ this.sortable.option('delayOnTouchOnly', true);
216
+ return;
217
+ }
218
+ this.sortable = Sortable.create(this.container, {
219
+ animation: 150,
220
+ handle: DRAG_HANDLE_SELECTOR,
221
+ draggable: DRAGGABLE_ITEM_SELECTOR,
222
+ delay: TOUCH_DRAG_DELAY_MS,
223
+ delayOnTouchOnly: true,
224
+ onStart: this.handleSortStart,
225
+ onEnd: this.handleSortEnd,
226
+ });
227
+ }
228
+ teardownDragController() {
229
+ if (this.sortable) {
230
+ this.sortable.destroy();
231
+ this.sortable = undefined;
232
+ }
233
+ this.clearDropElevationTimer();
234
+ if (this.dropElevationTarget) {
235
+ this.dropElevationTarget.classList.remove(DEFAULT_DROP_ELEVATION_CLASS);
236
+ this.dropElevationTarget = undefined;
237
+ }
238
+ if (this.container) {
239
+ this.container.classList.remove(DEFAULT_CONTAINER_CLASS);
240
+ }
241
+ this.dragSnapshot = undefined;
242
+ this.draggedItemIndex = undefined;
243
+ }
244
+ canReorderItems() {
245
+ if (this.props.disabled || this.props.readonly) {
246
+ return false;
247
+ }
248
+ const schema = this.props.schema;
249
+ const limeOptions = (schema === null || schema === void 0 ? void 0 : schema.lime) || {};
250
+ return limeOptions.allowItemReorder !== false;
251
+ }
252
+ canRemoveItems() {
253
+ const schema = this.props.schema;
254
+ const limeOptions = (schema === null || schema === void 0 ? void 0 : schema.lime) || {};
255
+ return limeOptions.allowItemRemoval !== false;
256
+ }
257
+ isItemReorderable(item) {
258
+ return (this.canReorderItems() &&
259
+ Boolean((item === null || item === void 0 ? void 0 : item.hasMoveDown) || (item === null || item === void 0 ? void 0 : item.hasMoveUp)));
260
+ }
261
+ isIndexReorderable(index) {
262
+ const item = this.itemByIndex.get(index);
263
+ if (!item) {
264
+ return false;
265
+ }
266
+ return this.isItemReorderable(item);
267
+ }
268
+ getReorderableOrder(order = this.state.order) {
269
+ const result = [];
270
+ for (const index of order) {
271
+ if (this.isIndexReorderable(index)) {
272
+ result.push(index);
273
+ }
274
+ }
275
+ return result;
276
+ }
277
+ readOrderFromDom() {
278
+ if (!this.container) {
279
+ return [];
280
+ }
281
+ const items = [...this.container.querySelectorAll('.array-item')];
282
+ const order = [];
283
+ for (const element of items) {
284
+ const index = this.getReorderId(element);
285
+ if (index !== undefined) {
286
+ order.push(index);
287
+ }
288
+ }
289
+ return order;
290
+ }
291
+ getReorderId(element) {
292
+ if (!element) {
293
+ return undefined;
294
+ }
295
+ if (!(element instanceof HTMLElement)) {
296
+ return undefined;
297
+ }
298
+ const value = element.dataset.reorderId;
299
+ if (value === undefined) {
300
+ return undefined;
301
+ }
302
+ const parsed = Number.parseInt(value, 10);
303
+ return Number.isNaN(parsed) ? undefined : parsed;
304
+ }
305
+ applyDropElevation(item) {
306
+ if (this.dropElevationTarget && this.dropElevationTarget !== item) {
307
+ this.dropElevationTarget.classList.remove(DEFAULT_DROP_ELEVATION_CLASS);
308
+ }
309
+ this.clearDropElevationTimer();
310
+ item.classList.add(DEFAULT_DROP_ELEVATION_CLASS);
311
+ this.dropElevationTarget = item;
312
+ }
313
+ scheduleDropElevationRemoval() {
314
+ if (!this.dropElevationTarget) {
315
+ return;
316
+ }
317
+ const target = this.dropElevationTarget;
318
+ this.clearDropElevationTimer();
319
+ this.dropElevationTimeout = globalThis.setTimeout(() => {
320
+ target.classList.remove(DEFAULT_DROP_ELEVATION_CLASS);
321
+ if (this.dropElevationTarget === target) {
322
+ this.dropElevationTarget = undefined;
323
+ }
324
+ this.dropElevationTimeout = undefined;
325
+ }, DROP_ELEVATION_DURATION);
326
+ }
327
+ clearDropElevationTimer() {
328
+ if (this.dropElevationTimeout !== undefined) {
329
+ clearTimeout(this.dropElevationTimeout);
330
+ this.dropElevationTimeout = undefined;
331
+ }
332
+ }
333
+ arraysEqual(a, b) {
334
+ if (a.length !== b.length) {
335
+ return false;
336
+ }
337
+ let index = 0;
338
+ for (const value of a) {
339
+ if (value !== b[index]) {
340
+ return false;
341
+ }
342
+ index += 1;
343
+ }
344
+ return true;
345
+ }
346
+ extractIndices(items = []) {
347
+ return (items !== null && items !== void 0 ? items : []).map((item, index) => { var _a; return (_a = item.index) !== null && _a !== void 0 ? _a : index; });
61
348
  }
62
349
  }
63
350
  //# sourceMappingURL=array-field.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"array-field.js","sourceRoot":"","sources":["../../../../src/components/form/templates/array-field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,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B,EAAE;QAChD,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC;QACrB,MAAM,EAAE,MAAM;QACd,UAAU,EAAE,WAAW,CAAC,MAAM;QAC9B,KAAK,EAAE,KAAK;QACZ,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;QAC3C,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;OAC9C,CAAC,CAAC;KACN;IAED,OAAO,KAAK,CAAC,aAAa,CAAC,kBAAkB,EAAE;MAC3C,GAAG,EAAE,IAAI,CAAC,GAAG;MACb,IAAI,EAAE,IAAI;MACV,KAAK,EAAE,KAAK;MACZ,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;MAC3C,gBAAgB,EAAE,QAAQ,CAAC,gBAAgB;KAC9C,CAAC,CAAC;EACP,CAAC;EAEO,eAAe;;IACnB,MAAM,WAAW,GAAG,CAAA,MAAA,IAAI,CAAC,KAAK,CAAC,MAAM,0CAAE,IAAI,KAAI,EAAE,CAAC;IAElD,OAAO;MACH,gBAAgB,EAAE,WAAW,CAAC,gBAAgB,KAAK,KAAK;MACxD,gBAAgB,EAAE,WAAW,CAAC,gBAAgB,KAAK,KAAK;KAC3D,CAAC;EACN,CAAC;EAEO,cAAc,CAAC,KAAiB;IACpC,KAAK,CAAC,eAAe,EAAE,CAAC;IACxB,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;EACjC,CAAC;CACJ","sourcesContent":["import React from 'react';\nimport { isObjectType } from '../schema';\nimport { CollapsibleItemTemplate } from './array-field-collapsible-item';\nimport { SimpleItemTemplate } from './array-field-simple-item';\nimport { renderDescription, renderTitle } from './common';\nimport { ArrayFieldItem, ArrayFieldTemplateProps } from './types';\nimport { FormSchema } from '../form.types';\n\ninterface ArrayItemControls {\n allowItemRemoval: boolean;\n allowItemReorder: boolean;\n}\n\nexport class ArrayFieldTemplate extends React.Component {\n constructor(public props: ArrayFieldTemplateProps) {\n super(props);\n this.renderItem = this.renderItem.bind(this);\n this.handleAddClick = this.handleAddClick.bind(this);\n }\n\n public render() {\n return React.createElement(\n 'div',\n {},\n renderTitle(this.props.title),\n renderDescription(this.props.schema.description),\n this.props.items.map(this.renderItem),\n this.renderAddButton()\n );\n }\n\n private renderAddButton() {\n if (!this.props.canAdd) {\n return;\n }\n\n return React.createElement('limel-button', {\n label: this.props.title || 'Add',\n onClick: this.handleAddClick,\n icon: 'plus_math',\n class: 'button-add-new',\n });\n }\n\n private renderItem(item: ArrayFieldItem, index: number) {\n const { schema, formData, formContext } = this.props;\n const controls = this.getItemControls();\n\n if (isObjectType(schema.items as FormSchema)) {\n return React.createElement(CollapsibleItemTemplate, {\n key: item.key,\n item: item,\n data: formData[index],\n schema: schema,\n formSchema: formContext.schema,\n index: index,\n allowItemRemoval: controls.allowItemRemoval,\n allowItemReorder: controls.allowItemReorder,\n });\n }\n\n return React.createElement(SimpleItemTemplate, {\n key: item.key,\n item: item,\n index: index,\n allowItemRemoval: controls.allowItemRemoval,\n allowItemReorder: controls.allowItemReorder,\n });\n }\n\n private getItemControls(): ArrayItemControls {\n const limeOptions = this.props.schema?.lime || {};\n\n return {\n allowItemRemoval: limeOptions.allowItemRemoval !== false,\n allowItemReorder: limeOptions.allowItemReorder !== false,\n };\n }\n\n private handleAddClick(event: MouseEvent) {\n event.stopPropagation();\n this.props.onAddClick(event);\n }\n}\n"]}
1
+ {"version":3,"file":"array-field.js","sourceRoot":"","sources":["../../../../src/components/form/templates/array-field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAA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C,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE;MACvB,OAAO,KAAK,CAAC;KAChB;IAED,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,KAAK,IAAI,CAAC,EAAE;MACnB,IAAI,KAAK,KAAK,CAAC,CAAC,KAAK,CAAC,EAAE;QACpB,OAAO,KAAK,CAAC;OAChB;MACD,KAAK,IAAI,CAAC,CAAC;KACd;IAED,OAAO,IAAI,CAAC;EAChB,CAAC;EAEO,cAAc,CAAC,QAA0B,EAAE;IAC/C,OAAO,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,WAAC,OAAA,MAAA,IAAI,CAAC,KAAK,mCAAI,KAAK,CAAA,EAAA,CAAC,CAAC;EACnE,CAAC;CACJ","sourcesContent":["import React from 'react';\nimport { isObjectType } from '../schema';\nimport { CollapsibleItemTemplate } from './array-field-collapsible-item';\nimport { SimpleItemTemplate } from './array-field-simple-item';\nimport { renderDescription, renderTitle } from './common';\nimport { ArrayFieldItem, ArrayFieldTemplateProps } from './types';\nimport { FormSchema } from '../form.types';\nimport Sortable, { SortableEvent } from 'sortablejs';\n\ninterface ArrayItemControls {\n allowItemRemoval: boolean;\n}\n\ninterface ArrayFieldTemplateState {\n order: number[];\n}\n\nconst DRAG_HANDLE_SELECTOR = '[data-drag-handle]';\nconst DRAGGABLE_ITEM_SELECTOR = '.array-item[data-reorderable=\"true\"]';\nconst DEFAULT_CONTAINER_CLASS = 'has-an-item-which-is-being-dragged';\nconst DEFAULT_DROP_ELEVATION_CLASS = 'is-elevated';\nconst DROP_ELEVATION_DURATION = 1000;\nconst TOUCH_DRAG_DELAY_MS = 200; // Adds a short hold on touch (long-press) so scroll gestures do not reorder items.\n\nexport class ArrayFieldTemplate extends React.Component<\n ArrayFieldTemplateProps,\n ArrayFieldTemplateState\n> {\n private container?: HTMLDivElement;\n private sortable?: Sortable;\n private dragSnapshot?: number[];\n private draggedItemIndex?: number;\n private dropElevationTimeout?: ReturnType<typeof setTimeout>;\n private dropElevationTarget?: HTMLElement;\n private itemByIndex: Map<number, ArrayFieldItem> = new Map();\n\n public constructor(props: ArrayFieldTemplateProps) {\n super(props);\n\n this.state = {\n order: this.extractIndices(props.items),\n };\n }\n\n public componentWillUnmount() {\n this.teardownDragController();\n }\n\n public componentDidMount() {\n this.setupDragController();\n }\n\n public componentDidUpdate(previousProps: ArrayFieldTemplateProps) {\n if (previousProps.items !== this.props.items) {\n const nextOrder = this.extractIndices(this.props.items);\n\n if (!this.arraysEqual(this.state.order, nextOrder)) {\n this.setState(\n {\n order: nextOrder,\n },\n () => {\n this.setupDragController();\n }\n );\n return;\n }\n }\n\n if (\n previousProps.items !== this.props.items ||\n previousProps.schema !== this.props.schema ||\n previousProps.disabled !== this.props.disabled ||\n previousProps.readonly !== this.props.readonly\n ) {\n this.setupDragController();\n }\n }\n\n public render() {\n const controls = this.getItemControls();\n const { ordered: orderedItems, byIndex } = this.getOrderedItems();\n this.itemByIndex = byIndex;\n\n return React.createElement(\n 'div',\n {},\n renderTitle(this.props.title),\n renderDescription(this.props.schema.description),\n React.createElement(\n 'div',\n {\n className: 'array-items',\n ref: this.setContainer,\n },\n orderedItems.map((item, index) =>\n this.renderItem(item, index, controls)\n )\n ),\n this.renderAddButton()\n );\n }\n\n private renderAddButton() {\n if (!this.props.canAdd) {\n return;\n }\n\n return React.createElement('limel-button', {\n label: this.props.title || 'Add',\n onClick: this.handleAddClick,\n icon: 'plus_math',\n class: 'button-add-new',\n });\n }\n\n private getItemControls(): ArrayItemControls {\n return {\n allowItemRemoval: this.canRemoveItems(),\n };\n }\n\n private readonly handleAddClick = (event: MouseEvent) => {\n event.stopPropagation();\n this.props.onAddClick(event);\n };\n\n private renderItem(\n item: ArrayFieldItem,\n index: number,\n controls: ArrayItemControls\n ) {\n const { schema, formData, formContext } = this.props;\n const itemIndex = item.index ?? index;\n const allowItemReorder = this.isItemReorderable(item);\n\n if (isObjectType(schema.items as FormSchema)) {\n return React.createElement(CollapsibleItemTemplate, {\n key: item.key,\n item: item,\n data: Array.isArray(formData) ? formData[itemIndex] : undefined,\n schema: schema,\n formSchema: formContext.schema,\n index: itemIndex,\n allowItemRemoval: controls.allowItemRemoval,\n allowItemReorder: allowItemReorder,\n });\n }\n\n return React.createElement(SimpleItemTemplate, {\n key: item.key,\n item: item,\n index: itemIndex,\n dataIndex: itemIndex,\n allowItemRemoval: controls.allowItemRemoval,\n allowItemReorder: allowItemReorder,\n });\n }\n\n private readonly setContainer = (element: HTMLDivElement | null) => {\n if (this.container === element) {\n return;\n }\n\n this.teardownDragController();\n this.container = element ?? undefined;\n this.setupDragController();\n };\n\n private getOrderedItems(): {\n ordered: ArrayFieldItem[];\n byIndex: Map<number, ArrayFieldItem>;\n } {\n const items = this.props.items ?? [];\n const byIndex = new Map<number, ArrayFieldItem>();\n\n let entryIndex = 0;\n for (const entry of items) {\n byIndex.set(entry.index ?? entryIndex, entry);\n entryIndex += 1;\n }\n\n const ordered: ArrayFieldItem[] = [];\n const used = new Set<number>();\n\n for (const index of this.state.order) {\n const entry = byIndex.get(index);\n if (!entry) {\n continue;\n }\n\n ordered.push(entry);\n used.add(index);\n }\n\n for (const [index, entry] of byIndex.entries()) {\n if (!used.has(index)) {\n ordered.push(entry);\n }\n }\n\n return {\n ordered,\n byIndex,\n };\n }\n\n private readonly handleSortStart = (event: SortableEvent) => {\n if (!this.canReorderItems()) {\n return;\n }\n\n this.dragSnapshot = [...this.state.order];\n this.draggedItemIndex = this.getReorderId(event.item);\n\n if (this.container) {\n this.container.classList.add(DEFAULT_CONTAINER_CLASS);\n }\n\n if (event.item instanceof HTMLElement) {\n this.applyDropElevation(event.item);\n }\n };\n\n private readonly handleSortEnd = (event: SortableEvent) => {\n if (!this.canReorderItems()) {\n return;\n }\n\n if (this.container) {\n this.container.classList.remove(DEFAULT_CONTAINER_CLASS);\n }\n\n const snapshot = this.dragSnapshot;\n const draggedItemIndex = this.draggedItemIndex;\n this.dragSnapshot = undefined;\n this.draggedItemIndex = undefined;\n\n if (event.item instanceof HTMLElement) {\n this.dropElevationTarget = event.item;\n }\n\n const finalOrder = this.readOrderFromDom();\n\n if (!this.arraysEqual(this.state.order, finalOrder)) {\n this.setState({ order: finalOrder });\n }\n\n if (\n snapshot === undefined ||\n draggedItemIndex === undefined ||\n !(event.item instanceof HTMLElement)\n ) {\n this.scheduleDropElevationRemoval();\n return;\n }\n\n const fromPosition = snapshot.indexOf(draggedItemIndex);\n const toPosition = finalOrder.indexOf(draggedItemIndex);\n\n if (\n fromPosition === -1 ||\n toPosition === -1 ||\n fromPosition === toPosition\n ) {\n this.scheduleDropElevationRemoval();\n return;\n }\n\n const targetItem = (this.props.items ?? []).find((entry) => {\n return (entry.index ?? -1) === draggedItemIndex;\n });\n\n if (!targetItem || typeof targetItem.onReorderClick !== 'function') {\n this.scheduleDropElevationRemoval();\n return;\n }\n\n requestAnimationFrame(() => {\n const reorder = targetItem.onReorderClick(\n draggedItemIndex,\n toPosition\n );\n\n if (typeof reorder === 'function') {\n reorder();\n }\n });\n\n this.scheduleDropElevationRemoval();\n };\n\n private setupDragController() {\n if (!this.container || !this.canReorderItems()) {\n this.teardownDragController();\n return;\n }\n\n const reorderableCount = this.getReorderableOrder().length;\n if (reorderableCount < 2) {\n this.teardownDragController();\n return;\n }\n\n if (this.sortable) {\n this.sortable.option('handle', DRAG_HANDLE_SELECTOR);\n this.sortable.option('draggable', DRAGGABLE_ITEM_SELECTOR);\n this.sortable.option('disabled', false);\n this.sortable.option('delay', TOUCH_DRAG_DELAY_MS);\n this.sortable.option('delayOnTouchOnly', true);\n return;\n }\n\n this.sortable = Sortable.create(this.container, {\n animation: 150,\n handle: DRAG_HANDLE_SELECTOR,\n draggable: DRAGGABLE_ITEM_SELECTOR,\n delay: TOUCH_DRAG_DELAY_MS,\n delayOnTouchOnly: true,\n onStart: this.handleSortStart,\n onEnd: this.handleSortEnd,\n });\n }\n\n private teardownDragController() {\n if (this.sortable) {\n this.sortable.destroy();\n this.sortable = undefined;\n }\n\n this.clearDropElevationTimer();\n\n if (this.dropElevationTarget) {\n this.dropElevationTarget.classList.remove(\n DEFAULT_DROP_ELEVATION_CLASS\n );\n this.dropElevationTarget = undefined;\n }\n\n if (this.container) {\n this.container.classList.remove(DEFAULT_CONTAINER_CLASS);\n }\n\n this.dragSnapshot = undefined;\n this.draggedItemIndex = undefined;\n }\n\n private canReorderItems(): boolean {\n if (this.props.disabled || this.props.readonly) {\n return false;\n }\n\n const schema = this.props.schema as FormSchema;\n const limeOptions = schema?.lime || {};\n\n return limeOptions.allowItemReorder !== false;\n }\n\n private canRemoveItems(): boolean {\n const schema = this.props.schema as FormSchema;\n const limeOptions = schema?.lime || {};\n\n return limeOptions.allowItemRemoval !== false;\n }\n\n private isItemReorderable(item: ArrayFieldItem): boolean {\n return (\n this.canReorderItems() &&\n Boolean(item?.hasMoveDown || item?.hasMoveUp)\n );\n }\n\n private isIndexReorderable(index: number): boolean {\n const item = this.itemByIndex.get(index);\n\n if (!item) {\n return false;\n }\n\n return this.isItemReorderable(item);\n }\n\n private getReorderableOrder(order: number[] = this.state.order): number[] {\n const result: number[] = [];\n\n for (const index of order) {\n if (this.isIndexReorderable(index)) {\n result.push(index);\n }\n }\n\n return result;\n }\n\n private readOrderFromDom(): number[] {\n if (!this.container) {\n return [];\n }\n\n const items = [...this.container.querySelectorAll('.array-item')];\n\n const order: number[] = [];\n\n for (const element of items) {\n const index = this.getReorderId(element);\n if (index !== undefined) {\n order.push(index);\n }\n }\n\n return order;\n }\n\n private getReorderId(element: Element | null): number | undefined {\n if (!element) {\n return undefined;\n }\n\n if (!(element instanceof HTMLElement)) {\n return undefined;\n }\n\n const value = element.dataset.reorderId;\n if (value === undefined) {\n return undefined;\n }\n\n const parsed = Number.parseInt(value, 10);\n return Number.isNaN(parsed) ? undefined : parsed;\n }\n\n private applyDropElevation(item: HTMLElement) {\n if (this.dropElevationTarget && this.dropElevationTarget !== item) {\n this.dropElevationTarget.classList.remove(\n DEFAULT_DROP_ELEVATION_CLASS\n );\n }\n\n this.clearDropElevationTimer();\n item.classList.add(DEFAULT_DROP_ELEVATION_CLASS);\n this.dropElevationTarget = item;\n }\n\n private scheduleDropElevationRemoval() {\n if (!this.dropElevationTarget) {\n return;\n }\n\n const target = this.dropElevationTarget;\n this.clearDropElevationTimer();\n this.dropElevationTimeout = globalThis.setTimeout(() => {\n target.classList.remove(DEFAULT_DROP_ELEVATION_CLASS);\n if (this.dropElevationTarget === target) {\n this.dropElevationTarget = undefined;\n }\n this.dropElevationTimeout = undefined;\n }, DROP_ELEVATION_DURATION);\n }\n\n private clearDropElevationTimer() {\n if (this.dropElevationTimeout !== undefined) {\n clearTimeout(this.dropElevationTimeout);\n this.dropElevationTimeout = undefined;\n }\n }\n\n private arraysEqual(a: number[], b: number[]): boolean {\n if (a.length !== b.length) {\n return false;\n }\n\n let index = 0;\n for (const value of a) {\n if (value !== b[index]) {\n return false;\n }\n index += 1;\n }\n\n return true;\n }\n\n private extractIndices(items: ArrayFieldItem[] = []): number[] {\n return (items ?? []).map((item, index) => item.index ?? index);\n }\n}\n"]}
@@ -19,7 +19,9 @@ export function renderDescription(description) {
19
19
  if (!description) {
20
20
  return;
21
21
  }
22
- return React.createElement('p', { className: 'mdc-typography mdc-typography--body1' }, description);
22
+ return React.createElement('limel-markdown', {
23
+ value: description,
24
+ });
23
25
  }
24
26
  /**
25
27
  * Find a suitable title for a nested structure.
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../src/components/form/templates/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAItD;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KA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C,KAAK,CAAC,0CAC9D,KAAK,KAAI,GAAG,KAAK,uBAAuB,CACjD,CAAC;GACL;EAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { get, isEmpty } from 'lodash-es';\nimport React from 'react';\nimport { isArrayType, isObjectType } from '../schema';\nimport { FormSchema } from '../form.types';\nimport { JSONSchema7 } from 'json-schema';\n\n/**\n *\n * @param title\n */\nexport function renderTitle(title: string) {\n if (!title) {\n return;\n }\n\n return React.createElement(\n 'h1',\n { className: 'mdc-typography mdc-typography--headline1' },\n title\n );\n}\n\n/**\n *\n * @param description\n */\nexport function renderDescription(description: string) {\n if (!description) {\n return;\n }\n\n return React.createElement(\n 'p',\n { className: 'mdc-typography mdc-typography--body1' },\n description\n );\n}\n\n/**\n * Find a suitable title for a nested structure.\n *\n * If an object has the key 'title' it will have priority, followed by the key 'name'.\n * If 'title' nor 'name' is found, a required item will be considered.\n * Otherwise the first occurrence of a nonempty string is chosen.\n *\n * @param data - the data to find the title for\n * @param fieldSchema - schema for the item\n * @param formSchema - schema for the form\n * @returns describing title of the data\n */\nexport function findTitle(\n data: any,\n fieldSchema: JSONSchema7,\n formSchema: JSONSchema7\n) {\n if (!data) {\n return null;\n }\n\n if (Array.isArray(data) && isObjectType(fieldSchema.items as FormSchema)) {\n return findTitle(data[0], fieldSchema, formSchema);\n }\n\n if (Array.isArray(data) || typeof data !== 'object') {\n return findSchemaTitle(data, fieldSchema);\n }\n\n const subSchema = findSubSchema(\n fieldSchema as FormSchema,\n formSchema as FormSchema\n );\n\n data = sortDataByProperties(data, subSchema.properties);\n\n const firstEntry = findFirstEntry(data, subSchema);\n if (!firstEntry) {\n return null;\n }\n\n if (!subSchema.properties) {\n return null;\n }\n\n const [key, value] = firstEntry;\n\n return findTitle(value, subSchema.properties[key], formSchema);\n}\n\nfunction sortDataByProperties(data: any, properties: object) {\n if (!properties || isEmpty(properties)) {\n return data;\n }\n\n const newData = {};\n for (const key of Object.keys(properties)) newData[key] = data[key];\n\n return newData;\n}\n\nfunction findFirstEntry(data: any, subSchema: FormSchema) {\n const entries = [\n ['title', data.title],\n ['name', data.name],\n getRequiredEntry(data, subSchema),\n ...Object.entries(data),\n ];\n\n return entries.find((entry) => {\n const value = entry[1];\n\n return !!value && typeof value !== 'boolean';\n });\n}\n\nfunction getRequiredEntry(data: any, subSchema: FormSchema) {\n if (!('required' in subSchema)) {\n return [null, null];\n }\n\n const firstNonEmptyRequiredKey = Object.keys(data).find((key) =>\n subSchema.required.includes(key)\n );\n if (!firstNonEmptyRequiredKey) {\n return [null, null];\n }\n\n return [firstNonEmptyRequiredKey, data[firstNonEmptyRequiredKey]];\n}\n\nfunction findSubSchema(schema: FormSchema, formSchema: FormSchema) {\n let subSchema = schema;\n if (isArrayType(schema)) {\n subSchema = schema.items as FormSchema;\n }\n\n if (subSchema.$ref) {\n const path = subSchema.$ref.split('/').slice(1).join('.');\n subSchema = get(formSchema, path);\n }\n\n return subSchema;\n}\n\nfunction findSchemaTitle(value: any, schema: JSONSchema7) {\n if (\n isArrayType(schema as FormSchema) &&\n (schema.items as JSONSchema7).anyOf\n ) {\n const titles = ((schema.items as JSONSchema7).anyOf as JSONSchema7[])\n .filter((item) => value.includes(item.const))\n .map((item) => item.title);\n\n return titles.join(', ');\n }\n\n if (schema.oneOf) {\n return (\n (schema.oneOf as JSONSchema7[]).find((item) => value === item.const)\n ?.title || `${value} is an invalid option`\n );\n }\n\n return value;\n}\n"]}
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../../src/components/form/templates/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAItD;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa;EACrC,IAAI,CAAC,KAAK,EAAE;IACR,OAAO;GACV;EAED,OAA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GACL;EAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { get, isEmpty } from 'lodash-es';\nimport React from 'react';\nimport { isArrayType, isObjectType } from '../schema';\nimport { FormSchema } from '../form.types';\nimport { JSONSchema7 } from 'json-schema';\n\n/**\n *\n * @param title\n */\nexport function renderTitle(title: string) {\n if (!title) {\n return;\n }\n\n return React.createElement(\n 'h1',\n { className: 'mdc-typography mdc-typography--headline1' },\n title\n );\n}\n\n/**\n *\n * @param description\n */\nexport function renderDescription(description: string) {\n if (!description) {\n return;\n }\n\n return React.createElement('limel-markdown', {\n value: description,\n });\n}\n\n/**\n * Find a suitable title for a nested structure.\n *\n * If an object has the key 'title' it will have priority, followed by the key 'name'.\n * If 'title' nor 'name' is found, a required item will be considered.\n * Otherwise the first occurrence of a nonempty string is chosen.\n *\n * @param data - the data to find the title for\n * @param fieldSchema - schema for the item\n * @param formSchema - schema for the form\n * @returns describing title of the data\n */\nexport function findTitle(\n data: any,\n fieldSchema: JSONSchema7,\n formSchema: JSONSchema7\n) {\n if (!data) {\n return null;\n }\n\n if (Array.isArray(data) && isObjectType(fieldSchema.items as FormSchema)) {\n return findTitle(data[0], fieldSchema, formSchema);\n }\n\n if (Array.isArray(data) || typeof data !== 'object') {\n return findSchemaTitle(data, fieldSchema);\n }\n\n const subSchema = findSubSchema(\n fieldSchema as FormSchema,\n formSchema as FormSchema\n );\n\n data = sortDataByProperties(data, subSchema.properties);\n\n const firstEntry = findFirstEntry(data, subSchema);\n if (!firstEntry) {\n return null;\n }\n\n if (!subSchema.properties) {\n return null;\n }\n\n const [key, value] = firstEntry;\n\n return findTitle(value, subSchema.properties[key], formSchema);\n}\n\nfunction sortDataByProperties(data: any, properties: object) {\n if (!properties || isEmpty(properties)) {\n return data;\n }\n\n const newData = {};\n for (const key of Object.keys(properties)) newData[key] = data[key];\n\n return newData;\n}\n\nfunction findFirstEntry(data: any, subSchema: FormSchema) {\n const entries = [\n ['title', data.title],\n ['name', data.name],\n getRequiredEntry(data, subSchema),\n ...Object.entries(data),\n ];\n\n return entries.find((entry) => {\n const value = entry[1];\n\n return !!value && typeof value !== 'boolean';\n });\n}\n\nfunction getRequiredEntry(data: any, subSchema: FormSchema) {\n if (!('required' in subSchema)) {\n return [null, null];\n }\n\n const firstNonEmptyRequiredKey = Object.keys(data).find((key) =>\n subSchema.required.includes(key)\n );\n if (!firstNonEmptyRequiredKey) {\n return [null, null];\n }\n\n return [firstNonEmptyRequiredKey, data[firstNonEmptyRequiredKey]];\n}\n\nfunction findSubSchema(schema: FormSchema, formSchema: FormSchema) {\n let subSchema = schema;\n if (isArrayType(schema)) {\n subSchema = schema.items as FormSchema;\n }\n\n if (subSchema.$ref) {\n const path = subSchema.$ref.split('/').slice(1).join('.');\n subSchema = get(formSchema, path);\n }\n\n return subSchema;\n}\n\nfunction findSchemaTitle(value: any, schema: JSONSchema7) {\n if (\n isArrayType(schema as FormSchema) &&\n (schema.items as JSONSchema7).anyOf\n ) {\n const titles = ((schema.items as JSONSchema7).anyOf as JSONSchema7[])\n .filter((item) => value.includes(item.const))\n .map((item) => item.title);\n\n return titles.join(', ');\n }\n\n if (schema.oneOf) {\n return (\n (schema.oneOf as JSONSchema7[]).find((item) => value === item.const)\n ?.title || `${value} is an invalid option`\n );\n }\n\n return value;\n}\n"]}
@@ -67,6 +67,9 @@
67
67
  * of some components, to demonstrate how the component
68
68
  * behaves in a resizable container.
69
69
  */
70
+ /**
71
+ * Drag to reorder mixins
72
+ */
70
73
  /**
71
74
  * The breakpoints below are used to create responsive designs
72
75
  * in Lime's products. Therefore, they are here to get distributed
@@ -67,6 +67,9 @@
67
67
  * of some components, to demonstrate how the component
68
68
  * behaves in a resizable container.
69
69
  */
70
+ /**
71
+ * Drag to reorder mixins
72
+ */
70
73
  /**
71
74
  * The breakpoints below are used to create responsive designs
72
75
  * in Lime's products. Therefore, they are here to get distributed
@@ -67,6 +67,9 @@
67
67
  * of some components, to demonstrate how the component
68
68
  * behaves in a resizable container.
69
69
  */
70
+ /**
71
+ * Drag to reorder mixins
72
+ */
70
73
  /**
71
74
  * The breakpoints below are used to create responsive designs
72
75
  * in Lime's products. Therefore, they are here to get distributed
@@ -67,6 +67,9 @@
67
67
  * of some components, to demonstrate how the component
68
68
  * behaves in a resizable container.
69
69
  */
70
+ /**
71
+ * Drag to reorder mixins
72
+ */
70
73
  /**
71
74
  * The breakpoints below are used to create responsive designs
72
75
  * in Lime's products. Therefore, they are here to get distributed