d2coreui 23.0.51 → 23.0.53

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 (281) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +154 -0
  3. package/components/clipboard/clipboardUtils.d.ts +11 -0
  4. package/components/clipboard/clipboardUtils.js +16 -4
  5. package/components/clipboard/clipboardUtils.js.map +1 -1
  6. package/components/codemirror/SyntaxHighlighter.d.ts +13 -0
  7. package/components/codemirror/SyntaxHighlighter.js +6 -1
  8. package/components/codemirror/SyntaxHighlighter.js.map +1 -1
  9. package/components/collapse/expandable.d.ts +10 -0
  10. package/components/collapse/expandable.js +4 -0
  11. package/components/collapse/expandable.js.map +1 -1
  12. package/components/color/colorPicker.d.ts +16 -0
  13. package/components/color/colorPicker.js +4 -0
  14. package/components/color/colorPicker.js.map +1 -1
  15. package/components/color/colorSwatch.d.ts +16 -0
  16. package/components/color/colorSwatch.js +23 -2
  17. package/components/color/colorSwatch.js.map +1 -1
  18. package/components/color/colorUtils.d.ts +9 -0
  19. package/components/color/colorUtils.js +15 -0
  20. package/components/color/colorUtils.js.map +1 -1
  21. package/components/date/dateRangeInput.d.ts +76 -0
  22. package/components/date/dateRangeInput.js +63 -12
  23. package/components/date/dateRangeInput.js.map +1 -1
  24. package/components/date/dateRangeInputAdvancedPanel.d.ts +27 -0
  25. package/components/date/dateRangeInputAdvancedPanel.js +7 -0
  26. package/components/date/dateRangeInputAdvancedPanel.js.map +1 -1
  27. package/components/date/dateRangeInputConfirm.d.ts +18 -0
  28. package/components/date/dateRangeInputConfirm.js +12 -0
  29. package/components/date/dateRangeInputConfirm.js.map +1 -1
  30. package/components/date/dateTimeInput.d.ts +99 -0
  31. package/components/date/dateTimeInput.js +78 -6
  32. package/components/date/dateTimeInput.js.map +1 -1
  33. package/components/date/durationInput.d.ts +37 -0
  34. package/components/date/durationInput.js +26 -3
  35. package/components/date/durationInput.js.map +1 -1
  36. package/components/date/savedIntervals.d.ts +63 -0
  37. package/components/date/savedIntervals.js +37 -0
  38. package/components/date/savedIntervals.js.map +1 -1
  39. package/components/date/savedIntervalsDialog.d.ts +13 -0
  40. package/components/date/savedIntervalsDialog.js +7 -2
  41. package/components/date/savedIntervalsDialog.js.map +1 -1
  42. package/components/form/NiceFormItem.d.ts +9 -0
  43. package/components/form/NiceFormItem.js +4 -0
  44. package/components/form/NiceFormItem.js.map +1 -1
  45. package/components/grid/cell/beanAccessor.d.ts +12 -0
  46. package/components/grid/cell/beanAccessor.js +8 -0
  47. package/components/grid/cell/beanAccessor.js.map +1 -1
  48. package/components/grid/cell/bigNumberCellEditor.d.ts +9 -0
  49. package/components/grid/cell/bigNumberCellEditor.js +19 -0
  50. package/components/grid/cell/bigNumberCellEditor.js.map +1 -1
  51. package/components/grid/cell/cellControl.d.ts +4 -0
  52. package/components/grid/cell/cellControl.js +14 -0
  53. package/components/grid/cell/cellControl.js.map +1 -1
  54. package/components/grid/cell/cellEditorUtils.d.ts +6 -0
  55. package/components/grid/cell/cellEditorUtils.js +6 -0
  56. package/components/grid/cell/cellEditorUtils.js.map +1 -1
  57. package/components/grid/cell/customEnumCellEditor.d.ts +6 -0
  58. package/components/grid/cell/customEnumCellEditor.js +10 -0
  59. package/components/grid/cell/customEnumCellEditor.js.map +1 -1
  60. package/components/grid/cell/dataGridCellEditorComponent.d.ts +26 -0
  61. package/components/grid/cell/dataGridCellEditorComponent.js +21 -0
  62. package/components/grid/cell/dataGridCellEditorComponent.js.map +1 -1
  63. package/components/grid/cell/dateCellEditor.d.ts +6 -0
  64. package/components/grid/cell/dateCellEditor.js +10 -0
  65. package/components/grid/cell/dateCellEditor.js.map +1 -1
  66. package/components/grid/cell/dragListenerFeature.d.ts +6 -0
  67. package/components/grid/cell/dragListenerFeature.js +6 -0
  68. package/components/grid/cell/dragListenerFeature.js.map +1 -1
  69. package/components/grid/cell/durationCellEditor.d.ts +6 -0
  70. package/components/grid/cell/durationCellEditor.js +14 -0
  71. package/components/grid/cell/durationCellEditor.js.map +1 -1
  72. package/components/grid/cell/hexaOctetStringCellEditor.d.ts +6 -0
  73. package/components/grid/cell/hexaOctetStringCellEditor.js +14 -0
  74. package/components/grid/cell/hexaOctetStringCellEditor.js.map +1 -1
  75. package/components/grid/cell/hexaValueCellEditor.d.ts +6 -0
  76. package/components/grid/cell/hexaValueCellEditor.js +14 -0
  77. package/components/grid/cell/hexaValueCellEditor.js.map +1 -1
  78. package/components/grid/cell/numberCellEditor.d.ts +6 -0
  79. package/components/grid/cell/numberCellEditor.js +15 -0
  80. package/components/grid/cell/numberCellEditor.js.map +1 -1
  81. package/components/grid/cell/rangeSelector.d.ts +7 -0
  82. package/components/grid/cell/rangeSelector.js +59 -5
  83. package/components/grid/cell/rangeSelector.js.map +1 -1
  84. package/components/grid/cell/simpleStatusTextCellEditor.d.ts +7 -0
  85. package/components/grid/cell/simpleStatusTextCellEditor.js +11 -0
  86. package/components/grid/cell/simpleStatusTextCellEditor.js.map +1 -1
  87. package/components/grid/cell/statusTextCellEditor.d.ts +7 -0
  88. package/components/grid/cell/statusTextCellEditor.js +17 -0
  89. package/components/grid/cell/statusTextCellEditor.js.map +1 -1
  90. package/components/grid/cell/tableDefaultRowStyleRules.d.ts +31 -0
  91. package/components/grid/cell/tableDefaultRowStyleRules.js +5 -0
  92. package/components/grid/cell/tableDefaultRowStyleRules.js.map +1 -1
  93. package/components/grid/cell/textCellEditor.d.ts +6 -0
  94. package/components/grid/cell/textCellEditor.js +15 -0
  95. package/components/grid/cell/textCellEditor.js.map +1 -1
  96. package/components/grid/cell/withAgGridHooks.d.ts +8 -0
  97. package/components/grid/cell/withAgGridHooks.js +8 -0
  98. package/components/grid/cell/withAgGridHooks.js.map +1 -1
  99. package/components/grid/columnUtils.d.ts +7 -0
  100. package/components/grid/columnUtils.js +7 -0
  101. package/components/grid/columnUtils.js.map +1 -1
  102. package/components/grid/config/columnTransfer.d.ts +18 -0
  103. package/components/grid/config/columnTransfer.js +14 -3
  104. package/components/grid/config/columnTransfer.js.map +1 -1
  105. package/components/grid/config/dataGridEditor.d.ts +31 -0
  106. package/components/grid/config/dataGridEditor.js +14 -2
  107. package/components/grid/config/dataGridEditor.js.map +1 -1
  108. package/components/grid/config/rowHeightCalculator.d.ts +11 -0
  109. package/components/grid/config/rowHeightCalculator.js +11 -0
  110. package/components/grid/config/rowHeightCalculator.js.map +1 -1
  111. package/components/grid/config/rowStylePicker.d.ts +19 -0
  112. package/components/grid/config/rowStylePicker.js +12 -0
  113. package/components/grid/config/rowStylePicker.js.map +1 -1
  114. package/components/grid/dataGrid.d.ts +331 -0
  115. package/components/grid/dataGrid.js +168 -11
  116. package/components/grid/dataGrid.js.map +1 -1
  117. package/components/grid/detail/detailHeaderPanel.d.ts +11 -0
  118. package/components/grid/detail/detailHeaderPanel.js +5 -0
  119. package/components/grid/detail/detailHeaderPanel.js.map +1 -1
  120. package/components/grid/export/contextMenu.d.ts +31 -0
  121. package/components/grid/export/contextMenu.js +8 -0
  122. package/components/grid/export/contextMenu.js.map +1 -1
  123. package/components/grid/export/progressPopup.d.ts +21 -0
  124. package/components/grid/export/progressPopup.js +17 -0
  125. package/components/grid/export/progressPopup.js.map +1 -1
  126. package/components/grid/export/worker/pdfExport.js +5 -0
  127. package/components/grid/export/worker/pdfExport.js.map +1 -1
  128. package/components/grid/extendedDataGrid.d.ts +241 -0
  129. package/components/grid/extendedDataGrid.js +121 -2
  130. package/components/grid/extendedDataGrid.js.map +1 -1
  131. package/components/grid/filter/customColumnFilter.d.ts +5 -0
  132. package/components/grid/filter/customColumnFilter.js +5 -0
  133. package/components/grid/filter/customColumnFilter.js.map +1 -1
  134. package/components/grid/filter/dataGridColumnFilter.d.ts +19 -0
  135. package/components/grid/filter/dataGridColumnFilter.js +19 -0
  136. package/components/grid/filter/dataGridColumnFilter.js.map +1 -1
  137. package/components/grid/filter/dateColumnFilter.d.ts +6 -0
  138. package/components/grid/filter/dateColumnFilter.js +6 -0
  139. package/components/grid/filter/dateColumnFilter.js.map +1 -1
  140. package/components/grid/filter/textColumnFilter.d.ts +6 -0
  141. package/components/grid/filter/textColumnFilter.js +6 -0
  142. package/components/grid/filter/textColumnFilter.js.map +1 -1
  143. package/components/grid/filter/wildcardQuickFilterEngine.d.ts +21 -0
  144. package/components/grid/filter/wildcardQuickFilterEngine.js +21 -0
  145. package/components/grid/filter/wildcardQuickFilterEngine.js.map +1 -1
  146. package/components/grid/header/simpleHeader.d.ts +17 -0
  147. package/components/grid/header/simpleHeader.js +20 -0
  148. package/components/grid/header/simpleHeader.js.map +1 -1
  149. package/components/grid/panel/dataGridPagination.d.ts +10 -0
  150. package/components/grid/panel/dataGridPagination.js +5 -0
  151. package/components/grid/panel/dataGridPagination.js.map +1 -1
  152. package/components/grid/panel/loadingOverlay.d.ts +5 -0
  153. package/components/grid/panel/loadingOverlay.js +4 -0
  154. package/components/grid/panel/loadingOverlay.js.map +1 -1
  155. package/components/grid/panel/noRecordsOverlay.d.ts +6 -0
  156. package/components/grid/panel/noRecordsOverlay.js +5 -0
  157. package/components/grid/panel/noRecordsOverlay.js.map +1 -1
  158. package/components/grid/panel/tablePagination.d.ts +4 -0
  159. package/components/grid/panel/tablePagination.js +4 -0
  160. package/components/grid/panel/tablePagination.js.map +1 -1
  161. package/components/icons/dropdownArrow.d.ts +3 -0
  162. package/components/icons/dropdownArrow.js +2 -0
  163. package/components/icons/dropdownArrow.js.map +1 -1
  164. package/components/icons/undoIcon.d.ts +2 -0
  165. package/components/icons/undoIcon.js +2 -0
  166. package/components/icons/undoIcon.js.map +1 -1
  167. package/components/input/autoCompleteInput.d.ts +29 -0
  168. package/components/input/autoCompleteInput.js +7 -0
  169. package/components/input/autoCompleteInput.js.map +1 -1
  170. package/components/input/draftUtils.d.ts +7 -0
  171. package/components/input/draftUtils.js +9 -0
  172. package/components/input/draftUtils.js.map +1 -1
  173. package/components/input/hexaFormattedInput.d.ts +9 -0
  174. package/components/input/hexaFormattedInput.js +3 -0
  175. package/components/input/hexaFormattedInput.js.map +1 -1
  176. package/components/input/mask/helpers.d.ts +27 -0
  177. package/components/input/mask/helpers.js +27 -0
  178. package/components/input/mask/helpers.js.map +1 -1
  179. package/components/input/mask/inputMaskCore.d.ts +80 -0
  180. package/components/input/mask/inputMaskCore.js +90 -0
  181. package/components/input/mask/inputMaskCore.js.map +1 -1
  182. package/components/input/mask/pattern.d.ts +24 -0
  183. package/components/input/mask/pattern.js +26 -0
  184. package/components/input/mask/pattern.js.map +1 -1
  185. package/components/input/maskedInput.d.ts +53 -0
  186. package/components/input/maskedInput.js +44 -4
  187. package/components/input/maskedInput.js.map +1 -1
  188. package/components/input/passwordInput.d.ts +7 -0
  189. package/components/input/passwordInput.js +8 -0
  190. package/components/input/passwordInput.js.map +1 -1
  191. package/components/input/simpleAutoComplete.d.ts +6 -0
  192. package/components/input/simpleAutoComplete.js +6 -0
  193. package/components/input/simpleAutoComplete.js.map +1 -1
  194. package/components/input/textarea/extractSpansOfClasses.d.ts +17 -0
  195. package/components/input/textarea/extractSpansOfClasses.js +26 -1
  196. package/components/input/textarea/extractSpansOfClasses.js.map +1 -1
  197. package/components/input/textarea/getRanges.d.ts +7 -0
  198. package/components/input/textarea/getRanges.js +11 -0
  199. package/components/input/textarea/getRanges.js.map +1 -1
  200. package/components/input/textarea/getType.d.ts +5 -0
  201. package/components/input/textarea/getType.js +5 -0
  202. package/components/input/textarea/getType.js.map +1 -1
  203. package/components/input/textarea/highlighedContents.d.ts +4 -0
  204. package/components/input/textarea/highlighedContents.js +5 -0
  205. package/components/input/textarea/highlighedContents.js.map +1 -1
  206. package/components/input/textarea/mentionsWithHighlighting.d.ts +25 -0
  207. package/components/input/textarea/mentionsWithHighlighting.js +14 -0
  208. package/components/input/textarea/mentionsWithHighlighting.js.map +1 -1
  209. package/components/keyboard/keyboardUtils.d.ts +6 -0
  210. package/components/keyboard/keyboardUtils.js +6 -0
  211. package/components/keyboard/keyboardUtils.js.map +1 -1
  212. package/components/modal/draggableModalProvider.d.ts +6 -0
  213. package/components/modal/draggableModalProvider.js +7 -0
  214. package/components/modal/draggableModalProvider.js.map +1 -1
  215. package/components/modal/impl/clamp.js +1 -0
  216. package/components/modal/impl/clamp.js.map +1 -1
  217. package/components/modal/impl/draggableModal.d.ts +1 -0
  218. package/components/modal/impl/draggableModal.js +6 -0
  219. package/components/modal/impl/draggableModal.js.map +1 -1
  220. package/components/modal/impl/draggableModalContext.js +1 -0
  221. package/components/modal/impl/draggableModalContext.js.map +1 -1
  222. package/components/modal/impl/draggableModalInner.js +12 -1
  223. package/components/modal/impl/draggableModalInner.js.map +1 -1
  224. package/components/modal/impl/draggableModalReducer.d.ts +7 -1
  225. package/components/modal/impl/draggableModalReducer.js +6 -1
  226. package/components/modal/impl/draggableModalReducer.js.map +1 -1
  227. package/components/modal/impl/draggableModalStyles.d.ts +17 -0
  228. package/components/modal/impl/draggableModalStyles.js +157 -126
  229. package/components/modal/impl/draggableModalStyles.js.map +1 -1
  230. package/components/modal/impl/getWindowSize.js +1 -0
  231. package/components/modal/impl/getWindowSize.js.map +1 -1
  232. package/components/modal/impl/index.js +1 -0
  233. package/components/modal/impl/index.js.map +1 -1
  234. package/components/modal/impl/resizeHandle.d.ts +1 -0
  235. package/components/modal/impl/resizeHandle.js +4 -1
  236. package/components/modal/impl/resizeHandle.js.map +1 -1
  237. package/components/modal/impl/useDrag.js +1 -0
  238. package/components/modal/impl/useDrag.js.map +1 -1
  239. package/components/modal/impl/usePrevious.js +1 -0
  240. package/components/modal/impl/usePrevious.js.map +1 -1
  241. package/components/modal/impl/useResize.js +1 -0
  242. package/components/modal/impl/useResize.js.map +1 -1
  243. package/components/modal/modalDialog.d.ts +85 -0
  244. package/components/modal/modalDialog.js +80 -10
  245. package/components/modal/modalDialog.js.map +1 -1
  246. package/components/picker/enumValuePicker.d.ts +17 -0
  247. package/components/picker/enumValuePicker.js +4 -0
  248. package/components/picker/enumValuePicker.js.map +1 -1
  249. package/components/platformSpecific.d.ts +17 -0
  250. package/components/platformSpecific.js +16 -0
  251. package/components/platformSpecific.js.map +1 -1
  252. package/components/scrollTo/onlyText.d.ts +5 -0
  253. package/components/scrollTo/onlyText.js +5 -0
  254. package/components/scrollTo/onlyText.js.map +1 -1
  255. package/components/scrollTo/scrollTo.d.ts +56 -0
  256. package/components/scrollTo/scrollTo.js +40 -3
  257. package/components/scrollTo/scrollTo.js.map +1 -1
  258. package/components/style/withCss.d.ts +15 -0
  259. package/components/style/withCss.js +6 -0
  260. package/components/style/withCss.js.map +1 -1
  261. package/components/table/dragSortingTable.d.ts +15 -0
  262. package/components/table/dragSortingTable.js +12 -0
  263. package/components/table/dragSortingTable.js.map +1 -1
  264. package/components/text/impl/innerSize.js +2 -0
  265. package/components/text/impl/innerSize.js.map +1 -1
  266. package/components/text/impl/series.d.ts +10 -0
  267. package/components/text/impl/series.js +10 -0
  268. package/components/text/impl/series.js.map +1 -1
  269. package/components/text/impl/shallowEqual.js +1 -0
  270. package/components/text/impl/shallowEqual.js.map +1 -1
  271. package/components/text/impl/whilst.d.ts +7 -0
  272. package/components/text/impl/whilst.js +7 -0
  273. package/components/text/impl/whilst.js.map +1 -1
  274. package/components/text/textFit.d.ts +24 -0
  275. package/components/text/textFit.js +29 -1
  276. package/components/text/textFit.js.map +1 -1
  277. package/i18n/componentsLocaleHolder.d.ts +9 -0
  278. package/i18n/componentsLocaleHolder.js +9 -0
  279. package/i18n/componentsLocaleHolder.js.map +1 -1
  280. package/package.json +4 -3
  281. package/style/index.less +240 -240
@@ -57,10 +57,16 @@ const rowTarget = {
57
57
  drop(props, monitor) {
58
58
  const dragIndex = monitor.getItem().index;
59
59
  const hoverIndex = props.index;
60
+ // Don't replace items with themselves
60
61
  if (dragIndex === hoverIndex) {
61
62
  return;
62
63
  }
64
+ // Time to actually perform the action
63
65
  props.moveRow(dragIndex, hoverIndex);
66
+ // Note: we're mutating the monitor item here!
67
+ // Generally it's better to avoid mutations,
68
+ // but it's good here for the sake of performance
69
+ // to avoid expensive index searches.
64
70
  monitor.getItem().index = hoverIndex;
65
71
  },
66
72
  };
@@ -70,6 +76,10 @@ const DragableBodyRow = DropTarget('row', rowTarget, (connect, monitor) => ({
70
76
  }))(DragSource('row', rowSource, connect => ({
71
77
  connectDragSource: connect.dragSource(),
72
78
  }))(BodyRow));
79
+ /**
80
+ * antd `Table` whose rows can be reordered by drag and drop (react-dnd, HTML5 backend, its own `DndProvider`).
81
+ * The drop position is indicated by a dashed line. Custom `components` are shallow-merged over the draggable body row.
82
+ */
73
83
  export default class DragSortingTable extends React.Component {
74
84
  constructor(props) {
75
85
  super(props);
@@ -80,6 +90,7 @@ export default class DragSortingTable extends React.Component {
80
90
  };
81
91
  this.moveRow = this.moveRow.bind(this);
82
92
  }
93
+ /** Calls {@link DragSortingTableProps.onMoveRow} for the row at `dragIndex`. */
83
94
  moveRow(dragIndex, hoverIndex) {
84
95
  const dragRow = this.props.dataSource[dragIndex];
85
96
  this.props.onMoveRow(dragRow, dragIndex, hoverIndex);
@@ -87,6 +98,7 @@ export default class DragSortingTable extends React.Component {
87
98
  ;
88
99
  render() {
89
100
  const _a = this.props, { onMoveRow, components } = _a, restProps = __rest(_a, ["onMoveRow", "components"]);
101
+ //@ts-ignore
90
102
  return (React.createElement(DndProvider, { backend: HTML5Backend },
91
103
  React.createElement(WithCss, { useStyles: useStyles }, (css) => (React.createElement(Table, Object.assign({ className: css.styles.dragSortingTable }, restProps, { components: components ? Object.assign({}, this.components, components) : this.components, onRow: (_, index) => {
92
104
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"dragSortingTable.js","sourceRoot":"","sources":["../../../../components/table/dragSortingTable.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,KAAK,EAAC,MAAM,MAAM,CAAC;AAC3B,OAAO,EAAC,WAAW,EAAE,UAAU,EAAE,UAAU,EAAC,MAAM,WAAW,CAAC;AAC9D,OAAO,YAAY,MAAM,yBAAyB,CAAC;AAEn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AC;IAEF,MAAM;QACF,MAAM,KAAwC,IAAI,CAAC,KAAK,EAAlD,EAAC,SAAS,EAAE,UAAU,OAA4B,EAAvB,SAAS,cAApC,2BAAqC,CAAa,CAAC;QAEzD,OAAO,CAAC,oBAAC,WAAW,IAAC,OAAO,EAAE,YAAY;YAClC,oBAAC,OAAO,IAAC,SAAS,EAAE,SAAS,IACzB,CAAC,GAAG,EAAC,EAAE,CAAA,CAAC,oBAAC,KAAK,kBACd,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,gBAAgB,IAClC,SAAS,IACb,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EACzF,KAAK,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;oBAChB,OAAO;wBACH,KAAK;wBACL,OAAO,EAAE,IAAI,CAAC,OAAO;qBACa,CAAA;gBAC1C,CAAC,IACH,CAAC,CACO,CACA,CACjB,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React from 'react';\r\nimport {Table} from 'antd';\r\nimport {DndProvider, DragSource, DropTarget} from 'react-dnd';\r\nimport HTML5Backend from 'react-dnd-html5-backend';\r\nimport {TableProps} from \"antd/es/table\";\r\nimport {createStyles} from \"antd-style\";\r\nimport WithCss from \"d2coreui/components/style/withCss\";\r\n\r\nconst useStyles = createStyles(({css}) => {\r\n return {\r\n dragSortingTable: css`\r\n tr.drop-over-downward td {\r\n border-bottom: 2px dashed #1890ff !important;\r\n }\r\n\r\n tr.drop-over-upward td {\r\n border-top: 2px dashed #1890ff !important;\r\n }\r\n `,\r\n }\r\n});\r\n\r\nlet dragingIndex = -1;\r\n\r\nclass BodyRow extends React.Component<any> {\r\n render() {\r\n const {isOver, connectDragSource, connectDropTarget, moveRow, ...restProps} = this.props;\r\n const style = {...restProps.style, cursor: 'move'};\r\n let {className} = restProps;\r\n if (isOver) {\r\n if (restProps.index > dragingIndex) {\r\n className += ' drop-over-downward';\r\n }\r\n if (restProps.index < dragingIndex) {\r\n className += ' drop-over-upward';\r\n }\r\n }\r\n return connectDragSource(\r\n connectDropTarget(<tr {...restProps} className={className} style={style}/>),\r\n );\r\n }\r\n}\r\n\r\nconst rowSource = {\r\n beginDrag(props: any) {\r\n dragingIndex = props.index;\r\n return {\r\n index: props.index,\r\n };\r\n },\r\n};\r\n\r\nconst rowTarget = {\r\n drop(props: any, monitor: any) {\r\n const dragIndex = monitor.getItem().index;\r\n const hoverIndex = props.index;\r\n // Don't replace items with themselves\r\n if (dragIndex === hoverIndex) {\r\n return;\r\n }\r\n // Time to actually perform the action\r\n props.moveRow(dragIndex, hoverIndex);\r\n // Note: we're mutating the monitor item here!\r\n // Generally it's better to avoid mutations,\r\n // but it's good here for the sake of performance\r\n // to avoid expensive index searches.\r\n monitor.getItem().index = hoverIndex;\r\n },\r\n};\r\n\r\nconst DragableBodyRow = DropTarget('row', rowTarget, (connect, monitor) => ({\r\n connectDropTarget: connect.dropTarget(),\r\n isOver: monitor.isOver(),\r\n}))(\r\n DragSource('row', rowSource, connect => ({\r\n connectDragSource: connect.dragSource(),\r\n }))(BodyRow),\r\n);\r\n\r\ninterface DragSortingTableProps<T> extends TableProps<T> {\r\n dataSource: T[]\r\n onMoveRow: (dragRow: T, dragIndex: number, hoverIndex: number) => void\r\n}\r\n\r\nexport default class DragSortingTable<T extends object> extends React.Component<DragSortingTableProps<T>> {\r\n components: any;\r\n\r\n constructor(props: Readonly<DragSortingTableProps<T>>) {\r\n super(props);\r\n this.components = {\r\n body: {\r\n row: DragableBodyRow,\r\n },\r\n };\r\n this.moveRow = this.moveRow.bind(this);\r\n }\r\n\r\n moveRow(dragIndex: number, hoverIndex: number) {\r\n const dragRow = this.props.dataSource[dragIndex];\r\n this.props.onMoveRow(dragRow, dragIndex, hoverIndex);\r\n };\r\n\r\n render() {\r\n const {onMoveRow, components, ...restProps} = this.props;\r\n //@ts-ignore\r\n return (<DndProvider backend={HTML5Backend}>\r\n <WithCss useStyles={useStyles}>{\r\n (css)=>(<Table<T>\r\n className={css.styles.dragSortingTable}\r\n {...restProps}\r\n components={components ? Object.assign({}, this.components, components) : this.components}\r\n onRow={(_, index) => {\r\n return {\r\n index,\r\n moveRow: this.moveRow,\r\n } as React.HTMLAttributes<HTMLElement>\r\n }}\r\n />)}\r\n </WithCss>\r\n </DndProvider>\r\n );\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"dragSortingTable.js","sourceRoot":"","sources":["../../../../components/table/dragSortingTable.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,KAAK,EAAC,MAAM,MAAM,CAAC;AAC3B,OAAO,EAAC,WAAW,EAAE,UAAU,EAAE,UAAU,EAAC,MAAM,WAAW,CAAC;AAC9D,OAAO,YAAY,MAAM,yBAAyB,CAAC;AAEnD,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AACxC,OAAO,OAAO,MAAM,mCAAmC,CAAC;AAExD,MAAM,SAAS,GAAG,YAAY,CAAC,CAAC,EAAC,GAAG,EAAC,EAAE,EAAE;IACrC,OAAO;QACH,gBAAgB,EAAE,GAAG,CAAA;;;;;;;;SAQpB;KACJ,CAAA;AACL,CAAC,CAAC,CAAC;AAEH,IAAI,YAAY,GAAG,CAAC,CAAC,CAAC;AAEtB,MAAM,OAAQ,SAAQ,KAAK,CAAC,SAAc;IACtC,MAAM;QACF,MAAM,KAAwE,IAAI,CAAC,KAAK,EAAlF,EAAC,MAAM,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,OAAO,OAA4B,EAAvB,SAAS,cAApE,+DAAqE,CAAa,CAAC;QACzF,MAAM,KAAK,mCAAO,SAAS,CAAC,KAAK,KAAE,MAAM,EAAE,MAAM,GAAC,CAAC;QACnD,IAAI,EAAC,SAAS,EAAC,GAAG,SAAS,CAAC;QAC5B,IAA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KAAK,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;oBAChB,OAAO;wBACH,KAAK;wBACL,OAAO,EAAE,IAAI,CAAC,OAAO;qBACa,CAAA;gBAC1C,CAAC,IACH,CAAC,CACO,CACA,CACjB,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React from 'react';\r\nimport {Table} from 'antd';\r\nimport {DndProvider, DragSource, DropTarget} from 'react-dnd';\r\nimport HTML5Backend from 'react-dnd-html5-backend';\r\nimport {TableProps} from \"antd/es/table\";\r\nimport {createStyles} from \"antd-style\";\r\nimport WithCss from \"d2coreui/components/style/withCss\";\r\n\r\nconst useStyles = createStyles(({css}) => {\r\n return {\r\n dragSortingTable: css`\r\n tr.drop-over-downward td {\r\n border-bottom: 2px dashed #1890ff !important;\r\n }\r\n\r\n tr.drop-over-upward td {\r\n border-top: 2px dashed #1890ff !important;\r\n }\r\n `,\r\n }\r\n});\r\n\r\nlet dragingIndex = -1;\r\n\r\nclass BodyRow extends React.Component<any> {\r\n render() {\r\n const {isOver, connectDragSource, connectDropTarget, moveRow, ...restProps} = this.props;\r\n const style = {...restProps.style, cursor: 'move'};\r\n let {className} = restProps;\r\n if (isOver) {\r\n if (restProps.index > dragingIndex) {\r\n className += ' drop-over-downward';\r\n }\r\n if (restProps.index < dragingIndex) {\r\n className += ' drop-over-upward';\r\n }\r\n }\r\n return connectDragSource(\r\n connectDropTarget(<tr {...restProps} className={className} style={style}/>),\r\n );\r\n }\r\n}\r\n\r\nconst rowSource = {\r\n beginDrag(props: any) {\r\n dragingIndex = props.index;\r\n return {\r\n index: props.index,\r\n };\r\n },\r\n};\r\n\r\nconst rowTarget = {\r\n drop(props: any, monitor: any) {\r\n const dragIndex = monitor.getItem().index;\r\n const hoverIndex = props.index;\r\n // Don't replace items with themselves\r\n if (dragIndex === hoverIndex) {\r\n return;\r\n }\r\n // Time to actually perform the action\r\n props.moveRow(dragIndex, hoverIndex);\r\n // Note: we're mutating the monitor item here!\r\n // Generally it's better to avoid mutations,\r\n // but it's good here for the sake of performance\r\n // to avoid expensive index searches.\r\n monitor.getItem().index = hoverIndex;\r\n },\r\n};\r\n\r\nconst DragableBodyRow = DropTarget('row', rowTarget, (connect, monitor) => ({\r\n connectDropTarget: connect.dropTarget(),\r\n isOver: monitor.isOver(),\r\n}))(\r\n DragSource('row', rowSource, connect => ({\r\n connectDragSource: connect.dragSource(),\r\n }))(BodyRow),\r\n);\r\n\r\n/** Props of {@link DragSortingTable}; other props are passed to antd `Table` (`onRow` is overridden). */\r\ninterface DragSortingTableProps<T> extends TableProps<T> {\r\n /** Table rows. */\r\n dataSource: T[]\r\n /**\r\n * Called when a row is dropped onto another row. The table does not reorder the rows itself;\r\n * update `dataSource` accordingly.\r\n * @param dragRow the dragged row\r\n * @param dragIndex original index of the dragged row\r\n * @param hoverIndex index of the row it was dropped on (its new index)\r\n */\r\n onMoveRow: (dragRow: T, dragIndex: number, hoverIndex: number) => void\r\n}\r\n\r\n/**\r\n * antd `Table` whose rows can be reordered by drag and drop (react-dnd, HTML5 backend, its own `DndProvider`).\r\n * The drop position is indicated by a dashed line. Custom `components` are shallow-merged over the draggable body row.\r\n */\r\nexport default class DragSortingTable<T extends object> extends React.Component<DragSortingTableProps<T>> {\r\n /** Table `components` override providing the draggable body row. */\r\n components: any;\r\n\r\n constructor(props: Readonly<DragSortingTableProps<T>>) {\r\n super(props);\r\n this.components = {\r\n body: {\r\n row: DragableBodyRow,\r\n },\r\n };\r\n this.moveRow = this.moveRow.bind(this);\r\n }\r\n\r\n /** Calls {@link DragSortingTableProps.onMoveRow} for the row at `dragIndex`. */\r\n moveRow(dragIndex: number, hoverIndex: number) {\r\n const dragRow = this.props.dataSource[dragIndex];\r\n this.props.onMoveRow(dragRow, dragIndex, hoverIndex);\r\n };\r\n\r\n render() {\r\n const {onMoveRow, components, ...restProps} = this.props;\r\n //@ts-ignore\r\n return (<DndProvider backend={HTML5Backend}>\r\n <WithCss useStyles={useStyles}>{\r\n (css)=>(<Table<T>\r\n className={css.styles.dragSortingTable}\r\n {...restProps}\r\n components={components ? Object.assign({}, this.components, components) : this.components}\r\n onRow={(_, index) => {\r\n return {\r\n index,\r\n moveRow: this.moveRow,\r\n } as React.HTMLAttributes<HTMLElement>\r\n }}\r\n />)}\r\n </WithCss>\r\n </DndProvider>\r\n );\r\n }\r\n}\r\n"]}
@@ -1,9 +1,11 @@
1
+ // Calculate height without padding.
1
2
  export function innerHeight(el) {
2
3
  const style = window.getComputedStyle(el, null);
3
4
  return el.clientHeight -
4
5
  parseInt(style.getPropertyValue('padding-top'), 10) -
5
6
  parseInt(style.getPropertyValue('padding-bottom'), 10);
6
7
  }
8
+ // Calculate width without padding.
7
9
  export function innerWidth(el) {
8
10
  const style = window.getComputedStyle(el, null);
9
11
  return el.clientWidth -
@@ -1 +1 @@
1
- {"version":3,"file":"innerSize.js","sourceRoot":"","sources":["../../../../../components/text/impl/innerSize.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,WAAW,CAAC,EAAc;IACtC,MAAM,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAChD,OAAO,EAAE,CAAC,YAAY;QAClB,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;QACnD,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/D,CAAC;AAGD,MAAM,UAAU,UAAU,CAAC,EAAc;IACrC,MAAM,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAChD,OAAO,EAAE,CAAC,WAAW;QACjB,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC;QACpD,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,eAAe,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["// Calculate height without padding.\r\nexport function innerHeight(el:HTMLElement) {\r\n const style = window.getComputedStyle(el, null);\r\n return el.clientHeight -\r\n parseInt(style.getPropertyValue('padding-top'), 10) -\r\n parseInt(style.getPropertyValue('padding-bottom'), 10);\r\n}\r\n\r\n// Calculate width without padding.\r\nexport function innerWidth(el:HTMLElement) {\r\n const style = window.getComputedStyle(el, null);\r\n return el.clientWidth -\r\n parseInt(style.getPropertyValue('padding-left'), 10) -\r\n parseInt(style.getPropertyValue('padding-right'), 10);\r\n}\r\n"]}
1
+ {"version":3,"file":"innerSize.js","sourceRoot":"","sources":["../../../../../components/text/impl/innerSize.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,MAAM,UAAU,WAAW,CAAC,EAAc;IACtC,MAAM,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAChD,OAAO,EAAE,CAAC,YAAY;QAClB,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;QACnD,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/D,CAAC;AAED,mCAAmC;AACnC,MAAM,UAAU,UAAU,CAAC,EAAc;IACrC,MAAM,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAChD,OAAO,EAAE,CAAC,WAAW;QACjB,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC;QACpD,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,eAAe,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["// Calculate height without padding.\r\nexport function innerHeight(el:HTMLElement) {\r\n const style = window.getComputedStyle(el, null);\r\n return el.clientHeight -\r\n parseInt(style.getPropertyValue('padding-top'), 10) -\r\n parseInt(style.getPropertyValue('padding-bottom'), 10);\r\n}\r\n\r\n// Calculate width without padding.\r\nexport function innerWidth(el:HTMLElement) {\r\n const style = window.getComputedStyle(el, null);\r\n return el.clientWidth -\r\n parseInt(style.getPropertyValue('padding-left'), 10) -\r\n parseInt(style.getPropertyValue('padding-right'), 10);\r\n}\r\n"]}
@@ -1 +1,11 @@
1
+ /**
2
+ * Run the functions in the tasks array in series, each one running once the previous function has completed.
3
+ * If any functions in the series pass an error to its callback, no more functions are run,
4
+ * and callback is immediately called with the value of the error. Otherwise, callback receives an array of results
5
+ * when tasks have completed.
6
+ * Taken from https://github.com/feross/run-series
7
+ *
8
+ * @params {Array} tasks An array containing functions to run, each function is passed a callback(err, result) which it must call on completion with an error err (which can be null) and an optional result value.
9
+ * @params {Function} callback(err, results) - An optional callback to run once all the functions have completed. This function gets a results array containing all the result arguments passed to the task callbacks.
10
+ */
1
11
  export default function series(tasks: Function[], cb: Function): void;
@@ -1,3 +1,13 @@
1
+ /**
2
+ * Run the functions in the tasks array in series, each one running once the previous function has completed.
3
+ * If any functions in the series pass an error to its callback, no more functions are run,
4
+ * and callback is immediately called with the value of the error. Otherwise, callback receives an array of results
5
+ * when tasks have completed.
6
+ * Taken from https://github.com/feross/run-series
7
+ *
8
+ * @params {Array} tasks An array containing functions to run, each function is passed a callback(err, result) which it must call on completion with an error err (which can be null) and an optional result value.
9
+ * @params {Function} callback(err, results) - An optional callback to run once all the functions have completed. This function gets a results array containing all the result arguments passed to the task callbacks.
10
+ */
1
11
  import process from 'process';
2
12
  export default function series(tasks, cb) {
3
13
  const results = [];
@@ -1 +1 @@
1
- {"version":3,"file":"series.js","sourceRoot":"","sources":["../../../../../components/text/impl/series.ts"],"names":[],"mappings":"AAWA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAiB,EAAE,EAAW;IACzD,MAAM,OAAO,GAAS,EAAE,CAAC;IACzB,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,MAAM,GAAG,IAAI,CAAC;IAElB,SAAS,IAAI,CAAC,GAAO;QACjB,SAAS,GAAG;YACR,IAAI,EAAE;gBAAE,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC7B,CAAC;QACD,IAAI,MAAM;YAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;;YAC7B,GAAG,EAAE,CAAC;IACf,CAAC;IAED,SAAS,IAAI,CAAC,GAAO,EAAE,MAAU;QAC7B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrB,IAAI,EAAE,OAAO,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG;YAAE,IAAI,CAAC,GAAG,CAAC,CAAC;;YAC3C,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;;QAChC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEhB,MAAM,GAAG,KAAK,CAAC;AACnB,CAAC","sourcesContent":["/**\r\n * Run the functions in the tasks array in series, each one running once the previous function has completed.\r\n * If any functions in the series pass an error to its callback, no more functions are run,\r\n * and callback is immediately called with the value of the error. Otherwise, callback receives an array of results\r\n * when tasks have completed.\r\n * Taken from https://github.com/feross/run-series\r\n *\r\n * @params {Array} tasks An array containing functions to run, each function is passed a callback(err, result) which it must call on completion with an error err (which can be null) and an optional result value.\r\n * @params {Function} callback(err, results) - An optional callback to run once all the functions have completed. This function gets a results array containing all the result arguments passed to the task callbacks.\r\n */\r\n\r\nimport process from 'process';\r\n\r\nexport default function series(tasks: Function[], cb:Function) {\r\n const results:any[] = [];\r\n let current = 0;\r\n let isSync = true;\r\n\r\n function done(err:any) {\r\n function end() {\r\n if (cb) cb(err, results);\r\n }\r\n if (isSync) process.nextTick(end);\r\n else end();\r\n }\r\n\r\n function each(err:any, result:any) {\r\n results.push(result);\r\n if (++current >= tasks.length || err) done(err);\r\n else tasks[current](each);\r\n }\r\n\r\n if (tasks.length > 0) tasks[0](each);\r\n else done(null);\r\n\r\n isSync = false;\r\n}\r\n"]}
1
+ {"version":3,"file":"series.js","sourceRoot":"","sources":["../../../../../components/text/impl/series.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAiB,EAAE,EAAW;IACzD,MAAM,OAAO,GAAS,EAAE,CAAC;IACzB,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,MAAM,GAAG,IAAI,CAAC;IAElB,SAAS,IAAI,CAAC,GAAO;QACjB,SAAS,GAAG;YACR,IAAI,EAAE;gBAAE,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC7B,CAAC;QACD,IAAI,MAAM;YAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;;YAC7B,GAAG,EAAE,CAAC;IACf,CAAC;IAED,SAAS,IAAI,CAAC,GAAO,EAAE,MAAU;QAC7B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrB,IAAI,EAAE,OAAO,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG;YAAE,IAAI,CAAC,GAAG,CAAC,CAAC;;YAC3C,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;;QAChC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEhB,MAAM,GAAG,KAAK,CAAC;AACnB,CAAC","sourcesContent":["/**\r\n * Run the functions in the tasks array in series, each one running once the previous function has completed.\r\n * If any functions in the series pass an error to its callback, no more functions are run,\r\n * and callback is immediately called with the value of the error. Otherwise, callback receives an array of results\r\n * when tasks have completed.\r\n * Taken from https://github.com/feross/run-series\r\n *\r\n * @params {Array} tasks An array containing functions to run, each function is passed a callback(err, result) which it must call on completion with an error err (which can be null) and an optional result value.\r\n * @params {Function} callback(err, results) - An optional callback to run once all the functions have completed. This function gets a results array containing all the result arguments passed to the task callbacks.\r\n */\r\n\r\nimport process from 'process';\r\n\r\nexport default function series(tasks: Function[], cb:Function) {\r\n const results:any[] = [];\r\n let current = 0;\r\n let isSync = true;\r\n\r\n function done(err:any) {\r\n function end() {\r\n if (cb) cb(err, results);\r\n }\r\n if (isSync) process.nextTick(end);\r\n else end();\r\n }\r\n\r\n function each(err:any, result:any) {\r\n results.push(result);\r\n if (++current >= tasks.length || err) done(err);\r\n else tasks[current](each);\r\n }\r\n\r\n if (tasks.length > 0) tasks[0](each);\r\n else done(null);\r\n\r\n isSync = false;\r\n}\r\n"]}
@@ -7,6 +7,7 @@ export default function shallowEqual(objA, objB) {
7
7
  if (keysA.length !== keysB.length) {
8
8
  return false;
9
9
  }
10
+ // Test for A's keys different from B.
10
11
  const hasOwn = Object.prototype.hasOwnProperty;
11
12
  for (let i = 0; i < keysA.length; i++) {
12
13
  if (!hasOwn.call(objB, keysA[i]) ||
@@ -1 +1 @@
1
- {"version":3,"file":"shallowEqual.js","sourceRoot":"","sources":["../../../../../components/text/impl/shallowEqual.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,IAAQ,EAAE,IAAQ;IACnD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;IAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;YAC5B,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACpC,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["export default function shallowEqual(objA:any, objB:any) {\r\n if (objA === objB) {\r\n return true;\r\n }\r\n const keysA = Object.keys(objA);\r\n const keysB = Object.keys(objB);\r\n if (keysA.length !== keysB.length) {\r\n return false;\r\n }\r\n // Test for A's keys different from B.\r\n const hasOwn = Object.prototype.hasOwnProperty;\r\n for (let i = 0; i < keysA.length; i++) {\r\n if (!hasOwn.call(objB, keysA[i]) ||\r\n objA[keysA[i]] !== objB[keysA[i]]) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n}\r\n"]}
1
+ {"version":3,"file":"shallowEqual.js","sourceRoot":"","sources":["../../../../../components/text/impl/shallowEqual.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,IAAQ,EAAE,IAAQ;IACnD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,sCAAsC;IACtC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;IAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;YAC5B,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACpC,OAAO,KAAK,CAAC;QACjB,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["export default function shallowEqual(objA:any, objB:any) {\r\n if (objA === objB) {\r\n return true;\r\n }\r\n const keysA = Object.keys(objA);\r\n const keysB = Object.keys(objB);\r\n if (keysA.length !== keysB.length) {\r\n return false;\r\n }\r\n // Test for A's keys different from B.\r\n const hasOwn = Object.prototype.hasOwnProperty;\r\n for (let i = 0; i < keysA.length; i++) {\r\n if (!hasOwn.call(objB, keysA[i]) ||\r\n objA[keysA[i]] !== objB[keysA[i]]) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n}\r\n"]}
@@ -1 +1,8 @@
1
+ /**
2
+ * Repeatedly call fn, while test returns true. Calls callback when stopped, or an error occurs.
3
+ *
4
+ * @param {Function} test Synchronous truth test to perform before each execution of fn.
5
+ * @param {Function} fn A function which is called each time test passes. The function is passed a callback(err), which must be called once it has completed with an optional err argument.
6
+ * @param {Function} callback A callback which is called after the test fails and repeated execution of fn has stopped.
7
+ */
1
8
  export default function whilst(test: () => boolean, iterator: Function, callback?: Function): void;
@@ -1,4 +1,11 @@
1
1
  const noop = () => { };
2
+ /**
3
+ * Repeatedly call fn, while test returns true. Calls callback when stopped, or an error occurs.
4
+ *
5
+ * @param {Function} test Synchronous truth test to perform before each execution of fn.
6
+ * @param {Function} fn A function which is called each time test passes. The function is passed a callback(err), which must be called once it has completed with an optional err argument.
7
+ * @param {Function} callback A callback which is called after the test fails and repeated execution of fn has stopped.
8
+ */
2
9
  export default function whilst(test, iterator, callback = noop) {
3
10
  if (test()) {
4
11
  iterator(function next(err, ...args) {
@@ -1 +1 @@
1
- {"version":3,"file":"whilst.js","sourceRoot":"","sources":["../../../../../components/text/impl/whilst.ts"],"names":[],"mappings":"AAAA,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAUtB,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,IAAiB,EAAE,QAAiB,EAAE,WAAmB,IAAI;IACxF,IAAI,IAAI,EAAE,EAAE,CAAC;QACT,QAAQ,CAAC,SAAS,IAAI,CAAY,GAAU,EAAE,GAAG,IAAQ;YACrD,IAAI,GAAG,EAAE,CAAC;gBACN,QAAQ,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC;iBAAM,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;gBAChC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACnB,CAAC;iBAAM,CAAC;gBACJ,QAAQ,CAAC,IAAI,CAAC,CAAC;YACnB,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;SAAM,CAAC;QACJ,QAAQ,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;AACL,CAAC","sourcesContent":["const noop = () => {};\r\n\r\n/**\r\n * Repeatedly call fn, while test returns true. Calls callback when stopped, or an error occurs.\r\n *\r\n * @param {Function} test Synchronous truth test to perform before each execution of fn.\r\n * @param {Function} fn A function which is called each time test passes. The function is passed a callback(err), which must be called once it has completed with an optional err argument.\r\n * @param {Function} callback A callback which is called after the test fails and repeated execution of fn has stopped.\r\n */\r\n\r\nexport default function whilst(test: ()=>boolean, iterator:Function, callback:Function= noop) {\r\n if (test()) {\r\n iterator(function next(this: any, err:string, ...args:any) {\r\n if (err) {\r\n callback(err);\r\n } else if (test.apply(this, args)) {\r\n iterator(next);\r\n } else {\r\n callback(null);\r\n }\r\n });\r\n } else {\r\n callback(null);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"whilst.js","sourceRoot":"","sources":["../../../../../components/text/impl/whilst.ts"],"names":[],"mappings":"AAAA,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAEtB;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,IAAiB,EAAE,QAAiB,EAAE,WAAmB,IAAI;IACxF,IAAI,IAAI,EAAE,EAAE,CAAC;QACT,QAAQ,CAAC,SAAS,IAAI,CAAY,GAAU,EAAE,GAAG,IAAQ;YACrD,IAAI,GAAG,EAAE,CAAC;gBACN,QAAQ,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC;iBAAM,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;gBAChC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACnB,CAAC;iBAAM,CAAC;gBACJ,QAAQ,CAAC,IAAI,CAAC,CAAC;YACnB,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;SAAM,CAAC;QACJ,QAAQ,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;AACL,CAAC","sourcesContent":["const noop = () => {};\r\n\r\n/**\r\n * Repeatedly call fn, while test returns true. Calls callback when stopped, or an error occurs.\r\n *\r\n * @param {Function} test Synchronous truth test to perform before each execution of fn.\r\n * @param {Function} fn A function which is called each time test passes. The function is passed a callback(err), which must be called once it has completed with an optional err argument.\r\n * @param {Function} callback A callback which is called after the test fails and repeated execution of fn has stopped.\r\n */\r\n\r\nexport default function whilst(test: ()=>boolean, iterator:Function, callback:Function= noop) {\r\n if (test()) {\r\n iterator(function next(this: any, err:string, ...args:any) {\r\n if (err) {\r\n callback(err);\r\n } else if (test.apply(this, args)) {\r\n iterator(next);\r\n } else {\r\n callback(null);\r\n }\r\n });\r\n } else {\r\n callback(null);\r\n }\r\n}\r\n"]}
@@ -1,21 +1,43 @@
1
1
  import React from 'react';
2
2
  declare function noop(): void;
3
+ /** Props of {@link TextFit}; other props are passed to the outer `div`. */
3
4
  interface TextFitProperties extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
5
+ /** Text to fit; when not set, `children` are rendered instead. */
4
6
  text?: string;
7
+ /** Minimum font size in px. @default 1 */
5
8
  min: number;
9
+ /** Maximum font size in px. @default 100 */
6
10
  max: number;
11
+ /**
12
+ * `'single'` fits one line (no wrapping) to the width; `'multi'` fits wrapped text to the height and then the width.
13
+ * @default 'multi'
14
+ */
7
15
  mode: 'single' | 'multi';
16
+ /** In `'single'` mode, fits only the width and ignores the height. @default true */
8
17
  forceSingleModeWidth: boolean;
18
+ /** Debounce delay of refitting on window resize, in ms; read only when the component is created. @default 50 */
9
19
  throttle: number;
20
+ /** Called with the final font size (px) after each fitting completes. */
10
21
  onReady: (mid: number) => void;
22
+ /** Refits the text when the window is resized; read on mount only. @default true */
11
23
  autoResize?: boolean;
12
24
  }
25
+ /** State of {@link TextFit}. */
13
26
  interface TextFitState {
27
+ /** Currently applied font size in px; `null` before the first fitting. */
14
28
  fontSize: number | null;
29
+ /** Whether the last fitting has completed. */
15
30
  ready: boolean;
16
31
  }
32
+ /**
33
+ * Container that adjusts its font size (binary search between `min` and `max`) so that the content fits its box.
34
+ * The element must be displayed and have a fixed width and height. The text is refitted on mount, when any prop
35
+ * changes (shallow comparison) and optionally on window resize; a newer fitting cancels a running one.
36
+ */
17
37
  export default class TextFit extends React.Component<TextFitProperties, TextFitState> {
38
+ /** Id of the currently running fitting; changing it cancels that fitting. */
18
39
  pid?: number;
40
+ /** Default prop values. */
19
41
  static defaultProps: {
20
42
  min: number;
21
43
  max: number;
@@ -31,7 +53,9 @@ export default class TextFit extends React.Component<TextFitProperties, TextFitS
31
53
  componentDidMount(): void;
32
54
  componentDidUpdate(prevProps: Readonly<TextFitProperties>): void;
33
55
  componentWillUnmount(): void;
56
+ /** Window resize handler (debounced by {@link TextFitProperties.throttle}); refits the text. */
34
57
  handleWindowResize: () => void;
58
+ /** Starts fitting the font size to the current size of the element; does nothing if it has no width or height. */
35
59
  process(): void;
36
60
  render(): React.JSX.Element;
37
61
  }
@@ -17,18 +17,26 @@ import debounce from 'lodash/debounce';
17
17
  import uniqueId from 'd2coreui/components/text/impl/uniqueId';
18
18
  import { innerHeight, innerWidth } from 'd2coreui/components/text/impl/innerSize';
19
19
  function assertElementFitsWidth(el, width) {
20
+ // -1: temporary bugfix, will be refactored soon
20
21
  return el && el.scrollWidth - 1 <= width;
21
22
  }
22
23
  function assertElementFitsHeight(el, height) {
24
+ // -1: temporary bugfix, will be refactored soon
23
25
  return el && el.scrollHeight - 1 <= height;
24
26
  }
25
27
  function noop() {
26
28
  }
29
+ /**
30
+ * Container that adjusts its font size (binary search between `min` and `max`) so that the content fits its box.
31
+ * The element must be displayed and have a fixed width and height. The text is refitted on mount, when any prop
32
+ * changes (shallow comparison) and optionally on window resize; a newer fitting cancels a running one.
33
+ */
27
34
  class TextFit extends React.Component {
28
35
  constructor(props) {
29
36
  super(props);
30
37
  this._parent = null;
31
38
  this._child = null;
39
+ /** Window resize handler (debounced by {@link TextFitProperties.throttle}); refits the text. */
32
40
  this.handleWindowResize = () => {
33
41
  this.process();
34
42
  };
@@ -58,8 +66,10 @@ class TextFit extends React.Component {
58
66
  if (autoResize) {
59
67
  window.removeEventListener('resize', this.handleWindowResize);
60
68
  }
69
+ // Setting a new pid will cancel all running processes
61
70
  this.pid = uniqueId();
62
71
  }
72
+ /** Starts fitting the font size to the current size of the element; does nothing if it has no width or height. */
63
73
  process() {
64
74
  const { min, max, mode, forceSingleModeWidth, onReady } = this.props;
65
75
  const el = this._parent;
@@ -88,6 +98,8 @@ class TextFit extends React.Component {
88
98
  let high = max;
89
99
  this.setState({ ready: false });
90
100
  series([
101
+ // Step 1:
102
+ // Binary search to fit the element's height (multi line) / width (single line)
91
103
  (stepCallback) => whilst(() => low <= high, (whilstCallback) => {
92
104
  if (shouldCancelProcess())
93
105
  return whilstCallback(true);
@@ -102,6 +114,10 @@ class TextFit extends React.Component {
102
114
  return whilstCallback();
103
115
  });
104
116
  }, stepCallback),
117
+ // Step 2:
118
+ // Binary search to fit the element's width (multi line) / height (single line)
119
+ // If mode is single and forceSingleModeWidth is true, skip this step
120
+ // in order to not fit the elements height and decrease the width
105
121
  (stepCallback) => {
106
122
  if (mode === 'single' && forceSingleModeWidth)
107
123
  return stepCallback();
@@ -125,23 +141,34 @@ class TextFit extends React.Component {
125
141
  });
126
142
  }, stepCallback);
127
143
  },
144
+ // Step 3
145
+ // Limits
128
146
  (stepCallback) => {
147
+ // We break the previous loop without updating mid for the final time,
148
+ // so we do it here:
129
149
  mid = Math.min(low, high);
150
+ // Ensure we hit the user-supplied limits
130
151
  mid = Math.max(mid, min);
131
152
  mid = Math.min(mid, max);
153
+ // Sanity check:
132
154
  mid = Math.max(mid, 0);
133
155
  if (shouldCancelProcess())
134
156
  return stepCallback(true);
135
157
  this.setState({ fontSize: mid }, stepCallback);
136
158
  }
137
159
  ], (err) => {
160
+ // err will be true, if another process was triggered
138
161
  if (err || shouldCancelProcess())
139
162
  return;
140
163
  this.setState({ ready: true }, () => onReady(mid));
141
164
  });
142
165
  }
143
166
  render() {
144
- const _a = this.props, { children, text, style, min, max, mode, forceSingleModeWidth, throttle, autoResize, onReady } = _a, props = __rest(_a, ["children", "text", "style", "min", "max", "mode", "forceSingleModeWidth", "throttle", "autoResize", "onReady"]);
167
+ const _a = this.props, { children, text, style, min, max, mode, forceSingleModeWidth,
168
+ /* eslint-disable no-shadow */
169
+ throttle,
170
+ /* eslint-enable no-shadow */
171
+ autoResize, onReady } = _a, props = __rest(_a, ["children", "text", "style", "min", "max", "mode", "forceSingleModeWidth", "throttle", "autoResize", "onReady"]);
145
172
  const { fontSize, ready } = this.state;
146
173
  const finalStyle = Object.assign(Object.assign({}, style), { fontSize: fontSize ? fontSize : undefined });
147
174
  const wrapperStyle = {
@@ -153,6 +180,7 @@ class TextFit extends React.Component {
153
180
  React.createElement("div", { ref: c => this._child = c, style: wrapperStyle }, text ? text : children)));
154
181
  }
155
182
  }
183
+ /** Default prop values. */
156
184
  TextFit.defaultProps = {
157
185
  min: 1,
158
186
  max: 100,
@@ -1 +1 @@
1
- {"version":3,"file":"textFit.js","sourceRoot":"","sources":["../../../../components/text/textFit.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAC3C,OAAO,YAAY,MAAM,4CAA4C,CAAC;AACtE,OAAO,MAAM,MAAM,sCAAsC,CAAC;AAC1D,OAAO,MAAM,MAAM,sCAAsC,CAAC;AAC1D,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,QAAQ,MAAM,wCAAwC,CAAC;AAC9D,OAAO,EAAC,WAAW,EAAE,UAAU,EAAC,MAAM,yCAAyC,CAAC;AAEhF,SAAS,sBAAsB,CAAC,EAAsB,EAAE,KAAa;IAEjE,OAAO,EAAE,IAAI,EAAE,CAAC,WAAW,GAAG,CAAC,IAAI,KAAK,CAAC;AAC7C,CAAC;AAED,SAAS,uBAAuB,CAAC,EAAsB,EAAE,MAAc;IAEnE,OAAO,EAAE,IAAI,EAAE,CAAC,YAAY,GAAG,CAAC,IAAI,MAAM,CAAC;AAC/C,CAAC;AAED,SAAS,IAAI;AACb,CAAC;AAkBD,MAAqB,OAAQ,SAAQ,KAAK,CAAC,SAA0C;IAejF,YAAY,KAAkC;QAC1C,KAAK,CAAC,KAAK,CAAC,CAAC;QAJT,YAAO,GAA0B,IAAI,CAAC;QACtC,WAAM,GAA0B,IAAI,CAAC;QAmC7C,uBAAkB,GAAG,GAAG,EAAE;YACtB,IAAI,CAAC,OAAO,EAAE,CAAC;QACnB,CAAC,CAAA;QAjCG,IAAI,CAAC,KAAK,GAAG;YACT,QAAQ,EAAE,IAAI;YACd,KAAK,EAAE,KAAK;SACf,CAAA;QACD,IAAI,CAAC,kBAAkB,GAAG,QAAQ,CA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U,mCACT,KAAK,KACR,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,GAC5C,CAAC;QAEF,MAAM,YAAY,GAAiB;YAC/B,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc;SAC5C,CAAC;QACF,IAAI,IAAI,KAAK,QAAQ;YAAE,YAAY,CAAC,UAAU,GAAG,QAAQ,CAAC;QAE1D,OAAO,CACH,2CAAK,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,EAAE,KAAK,EAAE,UAAU,IAAM,KAAK;YACzD,6BAAK,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,EAAE,YAAY,IAC9C,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CACrB,CACJ,CACT,CAAC;IACN,CAAC;;AA3LM,oBAAY,GAAG;IAClB,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,GAAG;IACR,IAAI,EAAE,OAAO;IACb,oBAAoB,EAAE,IAAI;IAC1B,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,IAAI;CAChB,AARkB,CAQlB;eAXgB,OAAO","sourcesContent":["import React, {CSSProperties} from 'react';\r\nimport shallowEqual from 'd2coreui/components/text/impl/shallowEqual';\r\nimport series from 'd2coreui/components/text/impl/series';\r\nimport whilst from 'd2coreui/components/text/impl/whilst';\r\nimport debounce from 'lodash/debounce';\r\nimport uniqueId from 'd2coreui/components/text/impl/uniqueId';\r\nimport {innerHeight, innerWidth} from 'd2coreui/components/text/impl/innerSize';\r\n\r\nfunction assertElementFitsWidth(el: HTMLElement | null, width: number) {\r\n // -1: temporary bugfix, will be refactored soon\r\n return el && el.scrollWidth - 1 <= width;\r\n}\r\n\r\nfunction assertElementFitsHeight(el: HTMLElement | null, height: number) {\r\n // -1: temporary bugfix, will be refactored soon\r\n return el && el.scrollHeight - 1 <= height;\r\n}\r\n\r\nfunction noop() {\r\n}\r\n\r\ninterface TextFitProperties extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {\r\n text?: string\r\n min: number\r\n max: number\r\n mode: 'single' | 'multi'\r\n forceSingleModeWidth: boolean,\r\n throttle: number,\r\n onReady: (mid:number) => void\r\n autoResize?: boolean\r\n}\r\n\r\ninterface TextFitState {\r\n fontSize: number | null\r\n ready: boolean\r\n}\r\n\r\nexport default class TextFit extends React.Component<TextFitProperties, TextFitState> {\r\n pid?: number\r\n\r\n static defaultProps = {\r\n min: 1,\r\n max: 100,\r\n mode: 'multi',\r\n forceSingleModeWidth: true,\r\n throttle: 50,\r\n autoResize: true,\r\n onReady: noop\r\n }\r\n private _parent: HTMLDivElement | null = null;\r\n private _child: HTMLDivElement | null = null;\r\n\r\n constructor(props: Readonly<TextFitProperties>) {\r\n super(props);\r\n this.state = {\r\n fontSize: null,\r\n ready: false\r\n }\r\n this.handleWindowResize = debounce(this.handleWindowResize, this.props.throttle);\r\n }\r\n\r\n componentDidMount() {\r\n const {autoResize} = this.props;\r\n if (autoResize) {\r\n window.addEventListener('resize', this.handleWindowResize);\r\n }\r\n this.process();\r\n }\r\n\r\n componentDidUpdate(prevProps: Readonly<TextFitProperties>) {\r\n const {ready} = this.state;\r\n if (!ready) return;\r\n if (shallowEqual(this.props, prevProps)) return;\r\n this.process();\r\n }\r\n\r\n componentWillUnmount() {\r\n const {autoResize} = this.props;\r\n if (autoResize) {\r\n window.removeEventListener('resize', this.handleWindowResize);\r\n }\r\n // Setting a new pid will cancel all running processes\r\n this.pid = uniqueId();\r\n }\r\n\r\n handleWindowResize = () => {\r\n this.process();\r\n }\r\n\r\n process() {\r\n const {min, max, mode, forceSingleModeWidth, onReady} = this.props;\r\n const el = this._parent;\r\n const wrapper = this._child;\r\n\r\n const originalWidth = el ? innerWidth(el) : 0;\r\n const originalHeight = el ? innerHeight(el) : 0;\r\n\r\n if (originalHeight <= 0 || isNaN(originalHeight)) {\r\n console.warn('Can not process element without height. Make sure the element is displayed and has a static height.');\r\n return;\r\n }\r\n\r\n if (originalWidth <= 0 || isNaN(originalWidth)) {\r\n console.warn('Can not process element without width. Make sure the element is displayed and has a static width.');\r\n return;\r\n }\r\n\r\n const pid = uniqueId();\r\n this.pid = pid;\r\n\r\n const shouldCancelProcess = () => pid !== this.pid;\r\n\r\n const testPrimary = mode === 'multi'\r\n ? () => assertElementFitsHeight(wrapper, originalHeight)\r\n : () => assertElementFitsWidth(wrapper, originalWidth);\r\n\r\n const testSecondary = mode === 'multi'\r\n ? () => assertElementFitsWidth(wrapper, originalWidth)\r\n : () => assertElementFitsHeight(wrapper, originalHeight);\r\n\r\n let mid: number;\r\n let low = min;\r\n let high = max;\r\n\r\n this.setState({ready: false});\r\n\r\n series([\r\n // Step 1:\r\n // Binary search to fit the element's height (multi line) / width (single line)\r\n (stepCallback: Function) => whilst(\r\n () => low <= high,\r\n (whilstCallback: Function) => {\r\n if (shouldCancelProcess()) return whilstCallback(true);\r\n mid = parseInt(\"\" + ((low + high) / 2), 10);\r\n this.setState({fontSize: mid}, () => {\r\n if (shouldCancelProcess()) return whilstCallback(true);\r\n if (testPrimary()) low = mid + 1;\r\n else high = mid - 1;\r\n return whilstCallback();\r\n });\r\n },\r\n stepCallback\r\n ),\r\n // Step 2:\r\n // Binary search to fit the element's width (multi line) / height (single line)\r\n // If mode is single and forceSingleModeWidth is true, skip this step\r\n // in order to not fit the elements height and decrease the width\r\n (stepCallback: Function) => {\r\n if (mode === 'single' && forceSingleModeWidth) return stepCallback();\r\n if (testSecondary()) return stepCallback();\r\n low = min;\r\n high = mid;\r\n return whilst(\r\n () => low < high,\r\n (whilstCallback: Function):any => {\r\n if (shouldCancelProcess()) {\r\n return whilstCallback(true);\r\n }\r\n mid = parseInt(\"\"+((low + high) / 2), 10);\r\n this.setState({fontSize: mid}, () => {\r\n if (pid !== this.pid) return whilstCallback(true);\r\n if (testSecondary()) low = mid + 1;\r\n else high = mid - 1;\r\n return whilstCallback();\r\n });\r\n },\r\n stepCallback\r\n );\r\n },\r\n // Step 3\r\n // Limits\r\n (stepCallback:Function) => {\r\n // We break the previous loop without updating mid for the final time,\r\n // so we do it here:\r\n mid = Math.min(low, high);\r\n\r\n // Ensure we hit the user-supplied limits\r\n mid = Math.max(mid, min);\r\n mid = Math.min(mid, max);\r\n\r\n // Sanity check:\r\n mid = Math.max(mid, 0);\r\n\r\n if (shouldCancelProcess()) return stepCallback(true);\r\n this.setState({fontSize: mid}, stepCallback as ()=>void);\r\n }\r\n ], (err:Function) => {\r\n // err will be true, if another process was triggered\r\n if (err || shouldCancelProcess()) return;\r\n this.setState({ready: true}, () => onReady(mid));\r\n });\r\n }\r\n\r\n render() {\r\n const {\r\n children,\r\n text,\r\n style,\r\n min,\r\n max,\r\n mode,\r\n forceSingleModeWidth,\r\n /* eslint-disable no-shadow */\r\n throttle,\r\n /* eslint-enable no-shadow */\r\n autoResize,\r\n onReady,\r\n ...props\r\n } = this.props;\r\n const {fontSize, ready} = this.state;\r\n const finalStyle:CSSProperties = {\r\n ...style,\r\n fontSize: fontSize ? fontSize : undefined\r\n };\r\n\r\n const wrapperStyle:CSSProperties = {\r\n display: ready ? 'block' : 'inline-block'\r\n };\r\n if (mode === 'single') wrapperStyle.whiteSpace = 'nowrap';\r\n\r\n return (\r\n <div ref={c => this._parent = c} style={finalStyle} {...props}>\r\n <div ref={c => this._child = c} style={wrapperStyle}>\r\n {text ? text : children}\r\n </div>\r\n </div>\r\n );\r\n }\r\n}"]}
1
+ {"version":3,"file":"textFit.js","sourceRoot":"","sources":["../../../../components/text/textFit.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAC3C,OAAO,YAAY,MAAM,4CAA4C,CAAC;AACtE,OAAO,MAAM,MAAM,sCAAsC,CAAC;AAC1D,OAAO,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C5C,CAAC;QAEF,MAAM,YAAY,GAAiB;YAC/B,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc;SAC5C,CAAC;QACF,IAAI,IAAI,KAAK,QAAQ;YAAE,YAAY,CAAC,UAAU,GAAG,QAAQ,CAAC;QAE1D,OAAO,CACH,2CAAK,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,EAAE,KAAK,EAAE,UAAU,IAAM,KAAK;YACzD,6BAAK,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,EAAE,YAAY,IAC9C,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CACrB,CACJ,CACT,CAAC;IACN,CAAC;;AA9LD,2BAA2B;AACpB,oBAAY,GAAG;IAClB,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,GAAG;IACR,IAAI,EAAE,OAAO;IACb,oBAAoB,EAAE,IAAI;IAC1B,QAAQ,EAAE,EAAE;IACZ,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,IAAI;CAChB,AARkB,CAQlB;eAbgB,OAAO","sourcesContent":["import React, {CSSProperties} from 'react';\r\nimport shallowEqual from 'd2coreui/components/text/impl/shallowEqual';\r\nimport series from 'd2coreui/components/text/impl/series';\r\nimport whilst from 'd2coreui/components/text/impl/whilst';\r\nimport debounce from 'lodash/debounce';\r\nimport uniqueId from 'd2coreui/components/text/impl/uniqueId';\r\nimport {innerHeight, innerWidth} from 'd2coreui/components/text/impl/innerSize';\r\n\r\nfunction assertElementFitsWidth(el: HTMLElement | null, width: number) {\r\n // -1: temporary bugfix, will be refactored soon\r\n return el && el.scrollWidth - 1 <= width;\r\n}\r\n\r\nfunction assertElementFitsHeight(el: HTMLElement | null, height: number) {\r\n // -1: temporary bugfix, will be refactored soon\r\n return el && el.scrollHeight - 1 <= height;\r\n}\r\n\r\nfunction noop() {\r\n}\r\n\r\n/** Props of {@link TextFit}; other props are passed to the outer `div`. */\r\ninterface TextFitProperties extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {\r\n /** Text to fit; when not set, `children` are rendered instead. */\r\n text?: string\r\n /** Minimum font size in px. @default 1 */\r\n min: number\r\n /** Maximum font size in px. @default 100 */\r\n max: number\r\n /**\r\n * `'single'` fits one line (no wrapping) to the width; `'multi'` fits wrapped text to the height and then the width.\r\n * @default 'multi'\r\n */\r\n mode: 'single' | 'multi'\r\n /** In `'single'` mode, fits only the width and ignores the height. @default true */\r\n forceSingleModeWidth: boolean,\r\n /** Debounce delay of refitting on window resize, in ms; read only when the component is created. @default 50 */\r\n throttle: number,\r\n /** Called with the final font size (px) after each fitting completes. */\r\n onReady: (mid:number) => void\r\n /** Refits the text when the window is resized; read on mount only. @default true */\r\n autoResize?: boolean\r\n}\r\n\r\n/** State of {@link TextFit}. */\r\ninterface TextFitState {\r\n /** Currently applied font size in px; `null` before the first fitting. */\r\n fontSize: number | null\r\n /** Whether the last fitting has completed. */\r\n ready: boolean\r\n}\r\n\r\n/**\r\n * Container that adjusts its font size (binary search between `min` and `max`) so that the content fits its box.\r\n * The element must be displayed and have a fixed width and height. The text is refitted on mount, when any prop\r\n * changes (shallow comparison) and optionally on window resize; a newer fitting cancels a running one.\r\n */\r\nexport default class TextFit extends React.Component<TextFitProperties, TextFitState> {\r\n /** Id of the currently running fitting; changing it cancels that fitting. */\r\n pid?: number\r\n\r\n /** Default prop values. */\r\n static defaultProps = {\r\n min: 1,\r\n max: 100,\r\n mode: 'multi',\r\n forceSingleModeWidth: true,\r\n throttle: 50,\r\n autoResize: true,\r\n onReady: noop\r\n }\r\n private _parent: HTMLDivElement | null = null;\r\n private _child: HTMLDivElement | null = null;\r\n\r\n constructor(props: Readonly<TextFitProperties>) {\r\n super(props);\r\n this.state = {\r\n fontSize: null,\r\n ready: false\r\n }\r\n this.handleWindowResize = debounce(this.handleWindowResize, this.props.throttle);\r\n }\r\n\r\n componentDidMount() {\r\n const {autoResize} = this.props;\r\n if (autoResize) {\r\n window.addEventListener('resize', this.handleWindowResize);\r\n }\r\n this.process();\r\n }\r\n\r\n componentDidUpdate(prevProps: Readonly<TextFitProperties>) {\r\n const {ready} = this.state;\r\n if (!ready) return;\r\n if (shallowEqual(this.props, prevProps)) return;\r\n this.process();\r\n }\r\n\r\n componentWillUnmount() {\r\n const {autoResize} = this.props;\r\n if (autoResize) {\r\n window.removeEventListener('resize', this.handleWindowResize);\r\n }\r\n // Setting a new pid will cancel all running processes\r\n this.pid = uniqueId();\r\n }\r\n\r\n /** Window resize handler (debounced by {@link TextFitProperties.throttle}); refits the text. */\r\n handleWindowResize = () => {\r\n this.process();\r\n }\r\n\r\n /** Starts fitting the font size to the current size of the element; does nothing if it has no width or height. */\r\n process() {\r\n const {min, max, mode, forceSingleModeWidth, onReady} = this.props;\r\n const el = this._parent;\r\n const wrapper = this._child;\r\n\r\n const originalWidth = el ? innerWidth(el) : 0;\r\n const originalHeight = el ? innerHeight(el) : 0;\r\n\r\n if (originalHeight <= 0 || isNaN(originalHeight)) {\r\n console.warn('Can not process element without height. Make sure the element is displayed and has a static height.');\r\n return;\r\n }\r\n\r\n if (originalWidth <= 0 || isNaN(originalWidth)) {\r\n console.warn('Can not process element without width. Make sure the element is displayed and has a static width.');\r\n return;\r\n }\r\n\r\n const pid = uniqueId();\r\n this.pid = pid;\r\n\r\n const shouldCancelProcess = () => pid !== this.pid;\r\n\r\n const testPrimary = mode === 'multi'\r\n ? () => assertElementFitsHeight(wrapper, originalHeight)\r\n : () => assertElementFitsWidth(wrapper, originalWidth);\r\n\r\n const testSecondary = mode === 'multi'\r\n ? () => assertElementFitsWidth(wrapper, originalWidth)\r\n : () => assertElementFitsHeight(wrapper, originalHeight);\r\n\r\n let mid: number;\r\n let low = min;\r\n let high = max;\r\n\r\n this.setState({ready: false});\r\n\r\n series([\r\n // Step 1:\r\n // Binary search to fit the element's height (multi line) / width (single line)\r\n (stepCallback: Function) => whilst(\r\n () => low <= high,\r\n (whilstCallback: Function) => {\r\n if (shouldCancelProcess()) return whilstCallback(true);\r\n mid = parseInt(\"\" + ((low + high) / 2), 10);\r\n this.setState({fontSize: mid}, () => {\r\n if (shouldCancelProcess()) return whilstCallback(true);\r\n if (testPrimary()) low = mid + 1;\r\n else high = mid - 1;\r\n return whilstCallback();\r\n });\r\n },\r\n stepCallback\r\n ),\r\n // Step 2:\r\n // Binary search to fit the element's width (multi line) / height (single line)\r\n // If mode is single and forceSingleModeWidth is true, skip this step\r\n // in order to not fit the elements height and decrease the width\r\n (stepCallback: Function) => {\r\n if (mode === 'single' && forceSingleModeWidth) return stepCallback();\r\n if (testSecondary()) return stepCallback();\r\n low = min;\r\n high = mid;\r\n return whilst(\r\n () => low < high,\r\n (whilstCallback: Function):any => {\r\n if (shouldCancelProcess()) {\r\n return whilstCallback(true);\r\n }\r\n mid = parseInt(\"\"+((low + high) / 2), 10);\r\n this.setState({fontSize: mid}, () => {\r\n if (pid !== this.pid) return whilstCallback(true);\r\n if (testSecondary()) low = mid + 1;\r\n else high = mid - 1;\r\n return whilstCallback();\r\n });\r\n },\r\n stepCallback\r\n );\r\n },\r\n // Step 3\r\n // Limits\r\n (stepCallback:Function) => {\r\n // We break the previous loop without updating mid for the final time,\r\n // so we do it here:\r\n mid = Math.min(low, high);\r\n\r\n // Ensure we hit the user-supplied limits\r\n mid = Math.max(mid, min);\r\n mid = Math.min(mid, max);\r\n\r\n // Sanity check:\r\n mid = Math.max(mid, 0);\r\n\r\n if (shouldCancelProcess()) return stepCallback(true);\r\n this.setState({fontSize: mid}, stepCallback as ()=>void);\r\n }\r\n ], (err:Function) => {\r\n // err will be true, if another process was triggered\r\n if (err || shouldCancelProcess()) return;\r\n this.setState({ready: true}, () => onReady(mid));\r\n });\r\n }\r\n\r\n render() {\r\n const {\r\n children,\r\n text,\r\n style,\r\n min,\r\n max,\r\n mode,\r\n forceSingleModeWidth,\r\n /* eslint-disable no-shadow */\r\n throttle,\r\n /* eslint-enable no-shadow */\r\n autoResize,\r\n onReady,\r\n ...props\r\n } = this.props;\r\n const {fontSize, ready} = this.state;\r\n const finalStyle:CSSProperties = {\r\n ...style,\r\n fontSize: fontSize ? fontSize : undefined\r\n };\r\n\r\n const wrapperStyle:CSSProperties = {\r\n display: ready ? 'block' : 'inline-block'\r\n };\r\n if (mode === 'single') wrapperStyle.whiteSpace = 'nowrap';\r\n\r\n return (\r\n <div ref={c => this._parent = c} style={finalStyle} {...props}>\r\n <div ref={c => this._child = c} style={wrapperStyle}>\r\n {text ? text : children}\r\n </div>\r\n </div>\r\n );\r\n }\r\n}"]}
@@ -1,3 +1,12 @@
1
+ /** Sets up the locale of the d2coreui components. */
1
2
  export class ComponentsLocaleHolder {
3
+ /**
4
+ * Calls `LocaleHolder.setLocale` from `d2core/i18n/localeHolder` and then adds the d2coreui component
5
+ * translations for the language (currently `sk`, `cs` and `uk`; other languages use the built-in English texts)
6
+ * to the global `i18n` translator.
7
+ * @param language UI language (`LanguageIsoCode`)
8
+ * @param formattingLocale locale used for number and date formatting; defaults to `language`
9
+ * @returns a promise resolved once both the core locale and the component translations are loaded
10
+ */
2
11
  static setLocale(language: any, formattingLocale: any): Promise<void>;
3
12
  }
@@ -1,6 +1,15 @@
1
1
  import i18n from "d2core/i18n/i18n";
2
2
  import { LocaleHolder } from "d2core/i18n/localeHolder";
3
+ /** Sets up the locale of the d2coreui components. */
3
4
  export class ComponentsLocaleHolder {
5
+ /**
6
+ * Calls `LocaleHolder.setLocale` from `d2core/i18n/localeHolder` and then adds the d2coreui component
7
+ * translations for the language (currently `sk`, `cs` and `uk`; other languages use the built-in English texts)
8
+ * to the global `i18n` translator.
9
+ * @param language UI language (`LanguageIsoCode`)
10
+ * @param formattingLocale locale used for number and date formatting; defaults to `language`
11
+ * @returns a promise resolved once both the core locale and the component translations are loaded
12
+ */
4
13
  static async setLocale(language, formattingLocale) {
5
14
  await LocaleHolder.setLocale(language, formattingLocale);
6
15
  let localizationJsonPromise;
@@ -1 +1 @@
1
- {"version":3,"file":"componentsLocaleHolder.js","sourceRoot":"","sources":["../../../i18n/componentsLocaleHolder.js"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAEtD,MAAM,OAAO,sBAAsB;IAC/B,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,gBAAgB;QAC7C,MAAM,YAAY,CAAC,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QACzD,IAAI,uBAAuB,CAAC;QAE5B,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACpB,uBAAuB,GAAG,MAAM,CAAE,kCAAkC,CAAC,CAAC;QAC1E,CAAC;aAAM,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC3B,uBAAuB,GAAG,MAAM,CAAE,kCAAkC,CAAC,CAAC;QAC1E,CAAC;aAAM,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC3B,uBAAuB,GAAG,MAAM,CAAE,kCAAkC,CAAC,CAAC;QAC1E,CAAC;aAAM,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC/B,CAAC;aAAM,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC/B,CAAC;aAAM,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC/B,CAAC;aAAM,CAAC;QACR,CAAC;QACD,IAAI,uBAAuB,EAAE,CAAC;YAC1B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAC,MAAM,EAAE,CAAC,MAAM,uBAAuB,CAAC,CAAC,OAAO,EAAC,CAAC,CAAC;QAC3E,CAAC;IACL,CAAC;CACJ","sourcesContent":["import i18n from \"d2core/i18n/i18n\";\r\nimport {LocaleHolder} from \"d2core/i18n/localeHolder\";\r\n\r\nexport class ComponentsLocaleHolder {\r\n static async setLocale(language, formattingLocale) {\r\n await LocaleHolder.setLocale(language, formattingLocale);\r\n let localizationJsonPromise;\r\n\r\n if (language === \"sk\") {\r\n localizationJsonPromise = import (\"d2coreui/i18n/components.sk.json\");\r\n } else if (language === \"cs\") {\r\n localizationJsonPromise = import (\"d2coreui/i18n/components.cs.json\");\r\n } else if (language === \"uk\") {\r\n localizationJsonPromise = import (\"d2coreui/i18n/components.uk.json\");\r\n } else if (language === \"ru\") {\r\n } else if (language === \"kk\") {\r\n } else if (language === \"sr\") {\r\n } else {\r\n }\r\n if (localizationJsonPromise) {\r\n i18n.translator.add({values: (await localizationJsonPromise).default});\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"componentsLocaleHolder.js","sourceRoot":"","sources":["../../../i18n/componentsLocaleHolder.js"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,EAAC,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAEtD,qDAAqD;AACrD,MAAM,OAAO,sBAAsB;IAC/B;;;;;;;OAOG;IACH,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,gBAAgB;QAC7C,MAAM,YAAY,CAAC,SAAS,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QACzD,IAAI,uBAAuB,CAAC;QAE5B,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACpB,uBAAuB,GAAG,MAAM,CAAE,kCAAkC,CAAC,CAAC;QAC1E,CAAC;aAAM,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC3B,uBAAuB,GAAG,MAAM,CAAE,kCAAkC,CAAC,CAAC;QAC1E,CAAC;aAAM,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC3B,uBAAuB,GAAG,MAAM,CAAE,kCAAkC,CAAC,CAAC;QAC1E,CAAC;aAAM,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC/B,CAAC;aAAM,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC/B,CAAC;aAAM,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC/B,CAAC;aAAM,CAAC;QACR,CAAC;QACD,IAAI,uBAAuB,EAAE,CAAC;YAC1B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAC,MAAM,EAAE,CAAC,MAAM,uBAAuB,CAAC,CAAC,OAAO,EAAC,CAAC,CAAC;QAC3E,CAAC;IACL,CAAC;CACJ","sourcesContent":["import i18n from \"d2core/i18n/i18n\";\r\nimport {LocaleHolder} from \"d2core/i18n/localeHolder\";\r\n\r\n/** Sets up the locale of the d2coreui components. */\r\nexport class ComponentsLocaleHolder {\r\n /**\r\n * Calls `LocaleHolder.setLocale` from `d2core/i18n/localeHolder` and then adds the d2coreui component\r\n * translations for the language (currently `sk`, `cs` and `uk`; other languages use the built-in English texts)\r\n * to the global `i18n` translator.\r\n * @param language UI language (`LanguageIsoCode`)\r\n * @param formattingLocale locale used for number and date formatting; defaults to `language`\r\n * @returns a promise resolved once both the core locale and the component translations are loaded\r\n */\r\n static async setLocale(language, formattingLocale) {\r\n await LocaleHolder.setLocale(language, formattingLocale);\r\n let localizationJsonPromise;\r\n\r\n if (language === \"sk\") {\r\n localizationJsonPromise = import (\"d2coreui/i18n/components.sk.json\");\r\n } else if (language === \"cs\") {\r\n localizationJsonPromise = import (\"d2coreui/i18n/components.cs.json\");\r\n } else if (language === \"uk\") {\r\n localizationJsonPromise = import (\"d2coreui/i18n/components.uk.json\");\r\n } else if (language === \"ru\") {\r\n } else if (language === \"kk\") {\r\n } else if (language === \"sr\") {\r\n } else {\r\n }\r\n if (localizationJsonPromise) {\r\n i18n.translator.add({values: (await localizationJsonPromise).default});\r\n }\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "d2coreui",
3
- "version": "23.0.51",
3
+ "version": "23.0.53",
4
4
  "description": "Core UI components and utilities library.",
5
5
  "author": "Ipesoft s.r.o.",
6
6
  "license": "MIT",
@@ -55,11 +55,12 @@
55
55
  "scripts": {
56
56
  "cleanBuild": "@powershell if (Test-Path \"./lib/esm\") {rm -r ./lib/esm}",
57
57
  "copyPackageJson": "@powershell copy './package.json' './lib/esm/'",
58
+ "copyDocs": "@powershell copy './README.md','./CHANGELOG.md' './lib/esm/'",
58
59
  "copyStyles": "@powershell cp -R './style' './lib/esm/'",
59
60
  "copyIcons": "@powershell cp -R './components/icons/*.svg' './lib/esm/components/icons/'",
60
61
  "copyIcons2": "@powershell cp -R './components/icons/*.png' './lib/esm/components/icons/'",
61
62
  "build": "tsc -P tsconfig.build.json",
62
- "publish-lib": "yarn cleanBuild && yarn build && yarn copyPackageJson && yarn copyStyles && yarn copyIcons && yarn copyIcons2 && yarn publish ./lib/esm",
63
- "publish-dryrun": "yarn cleanBuild && yarn build && yarn copyPackageJson && yarn copyStyles && yarn copyIcons && yarn copyIcons2 && yarn publish ./lib/esm --dry-run"
63
+ "publish-lib": "yarn cleanBuild && yarn build && yarn copyPackageJson && yarn copyStyles && yarn copyIcons && yarn copyIcons2 && yarn copyDocs && yarn publish ./lib/esm",
64
+ "publish-dryrun": "yarn cleanBuild && yarn build && yarn copyPackageJson && yarn copyStyles && yarn copyIcons && yarn copyIcons2 && yarn copyDocs && npm publish ./lib/esm --dry-run"
64
65
  }
65
66
  }