d2coreui 23.0.52 → 23.0.54

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 (280) hide show
  1. package/CHANGELOG.md +40 -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 +10 -1
  100. package/components/grid/columnUtils.js +11 -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 +45 -29
  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 +361 -12
  115. package/components/grid/dataGrid.js +201 -28
  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 +249 -4
  129. package/components/grid/extendedDataGrid.js +160 -19
  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 +31 -0
  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 +66 -65
@@ -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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U,EACV,OAAO,OAEG,EADP,KAAK,cAbN,gHAcL,CAAa,CAAC;QACf,MAAM,EAAC,QAAQ,EAAE,KAAK,EAAC,GAAG,IAAI,CAAC,KAAK,CAAC;QACrC,MAAM,UAAU,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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EAAC,GAAG,IAAI,CAAC,KAAK,CAAC;QACrC,MAAM,UAAU,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;;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,65 +1,66 @@
1
- {
2
- "name": "d2coreui",
3
- "version": "23.0.52",
4
- "description": "Core UI components and utilities library.",
5
- "author": "Ipesoft s.r.o.",
6
- "license": "MIT",
7
- "resolutions": {
8
- "@types/react": "18.3.7",
9
- "dayjs": "1.11.13"
10
- },
11
- "dependencies": {
12
- "@ant-design/compatible": "5.1.4",
13
- "@ant-design/dark-theme": "2.0.2",
14
- "@ant-design/icons": "5.6.1",
15
- "@types/codemirror": "5.60.15",
16
- "@types/draft-convert": "2.1.8",
17
- "@types/draft-js": "0.11.18",
18
- "@types/lodash": "4.17.5",
19
- "@types/pdfmake": "0.2.13",
20
- "@types/react": "18.3.7",
21
- "@types/react-collapse": "5.0.4",
22
- "@types/react-color": "3.0.12",
23
- "@types/react-dom": "18.3.0",
24
- "@types/react-resizable": "3.0.7",
25
- "ag-grid-community": "34.3.1",
26
- "ag-grid-react": "34.3.1",
27
- "antd": "5.29.3",
28
- "antd-style": "4.1.0",
29
- "codemirror": "5.65.20",
30
- "dayjs": "1.11.13",
31
- "dom-scroll-into-view": "2.0.1",
32
- "draft-convert": "2.1.12",
33
- "draft-js": "0.11.0",
34
- "draftail": "1.4.1",
35
- "filtrex": "2.2.3",
36
- "flexlayout-react": "0.8.18",
37
- "lodash": "4.17.23",
38
- "memoize-one": "6.0.0",
39
- "parse-decimal-number": "1.0.0",
40
- "pdfmake": "0.2.23",
41
- "process": "0.11.10",
42
- "react-codemirror2": "8.0.0",
43
- "react-collapse": "5.1.1",
44
- "react-color": "2.19.3",
45
- "react-dnd": "10.0.2",
46
- "react-dnd-html5-backend": "10.0.2",
47
- "react-drag-listview": "2.0.0",
48
- "react-draggable": "4.4.6",
49
- "react-maskinput": "3.2.0",
50
- "react-resizable": "3.0.5",
51
- "react-uid": "2.3.3",
52
- "threads": "1.7.0",
53
- "ts-key-enum": "2.0.12"
54
- },
55
- "scripts": {
56
- "cleanBuild": "@powershell if (Test-Path \"./lib/esm\") {rm -r ./lib/esm}",
57
- "copyPackageJson": "@powershell copy './package.json' './lib/esm/'",
58
- "copyStyles": "@powershell cp -R './style' './lib/esm/'",
59
- "copyIcons": "@powershell cp -R './components/icons/*.svg' './lib/esm/components/icons/'",
60
- "copyIcons2": "@powershell cp -R './components/icons/*.png' './lib/esm/components/icons/'",
61
- "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"
64
- }
65
- }
1
+ {
2
+ "name": "d2coreui",
3
+ "version": "23.0.54",
4
+ "description": "Core UI components and utilities library.",
5
+ "author": "Ipesoft s.r.o.",
6
+ "license": "MIT",
7
+ "resolutions": {
8
+ "@types/react": "18.3.7",
9
+ "dayjs": "1.11.13"
10
+ },
11
+ "dependencies": {
12
+ "@ant-design/compatible": "5.1.4",
13
+ "@ant-design/dark-theme": "2.0.2",
14
+ "@ant-design/icons": "5.6.1",
15
+ "@types/codemirror": "5.60.15",
16
+ "@types/draft-convert": "2.1.8",
17
+ "@types/draft-js": "0.11.18",
18
+ "@types/lodash": "4.17.5",
19
+ "@types/pdfmake": "0.2.13",
20
+ "@types/react": "18.3.7",
21
+ "@types/react-collapse": "5.0.4",
22
+ "@types/react-color": "3.0.12",
23
+ "@types/react-dom": "18.3.0",
24
+ "@types/react-resizable": "3.0.7",
25
+ "ag-grid-community": "34.3.1",
26
+ "ag-grid-react": "34.3.1",
27
+ "antd": "5.29.3",
28
+ "antd-style": "4.1.0",
29
+ "codemirror": "5.65.20",
30
+ "dayjs": "1.11.13",
31
+ "dom-scroll-into-view": "2.0.1",
32
+ "draft-convert": "2.1.12",
33
+ "draft-js": "0.11.0",
34
+ "draftail": "1.4.1",
35
+ "filtrex": "2.2.3",
36
+ "flexlayout-react": "0.8.18",
37
+ "lodash": "4.17.23",
38
+ "memoize-one": "6.0.0",
39
+ "parse-decimal-number": "1.0.0",
40
+ "pdfmake": "0.2.23",
41
+ "process": "0.11.10",
42
+ "react-codemirror2": "8.0.0",
43
+ "react-collapse": "5.1.1",
44
+ "react-color": "2.19.3",
45
+ "react-dnd": "10.0.2",
46
+ "react-dnd-html5-backend": "10.0.2",
47
+ "react-drag-listview": "2.0.0",
48
+ "react-draggable": "4.4.6",
49
+ "react-maskinput": "3.2.0",
50
+ "react-resizable": "3.0.5",
51
+ "react-uid": "2.3.3",
52
+ "threads": "1.7.0",
53
+ "ts-key-enum": "2.0.12"
54
+ },
55
+ "scripts": {
56
+ "cleanBuild": "@powershell if (Test-Path \"./lib/esm\") {rm -r ./lib/esm}",
57
+ "copyPackageJson": "@powershell copy './package.json' './lib/esm/'",
58
+ "copyDocs": "@powershell copy './README.md','./CHANGELOG.md' './lib/esm/'",
59
+ "copyStyles": "@powershell cp -R './style' './lib/esm/'",
60
+ "copyIcons": "@powershell cp -R './components/icons/*.svg' './lib/esm/components/icons/'",
61
+ "copyIcons2": "@powershell cp -R './components/icons/*.png' './lib/esm/components/icons/'",
62
+ "build": "tsc -P tsconfig.build.json",
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"
65
+ }
66
+ }