d2coreui 21.0.33 → 23.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/clipboard/clipboardUtils.d.ts +4 -3
- package/components/clipboard/clipboardUtils.js +47 -22
- package/components/clipboard/clipboardUtils.js.map +1 -1
- package/components/codemirror/SyntaxHighlighter.d.ts +21 -21
- package/components/codemirror/SyntaxHighlighter.js +45 -44
- package/components/codemirror/SyntaxHighlighter.js.map +1 -1
- package/components/collapse/expandable.d.ts +13 -12
- package/components/collapse/expandable.js +20 -20
- package/components/collapse/expandable.js.map +1 -1
- package/components/color/colorPicker.d.ts +20 -20
- package/components/color/colorPicker.js +53 -53
- package/components/color/colorPicker.js.map +1 -1
- package/components/color/colorSwatch.d.ts +13 -12
- package/components/color/colorSwatch.js +62 -62
- package/components/color/colorSwatch.js.map +1 -1
- package/components/color/colorUtils.d.ts +7 -7
- package/components/color/colorUtils.js +43 -43
- package/components/color/colorUtils.js.map +1 -1
- package/components/date/dateRangeInput.d.ts +66 -64
- package/components/date/dateRangeInput.js +292 -297
- package/components/date/dateRangeInput.js.map +1 -1
- package/components/date/dateRangeInputAdvancedPanel.d.ts +27 -26
- package/components/date/dateRangeInputAdvancedPanel.js +130 -115
- package/components/date/dateRangeInputAdvancedPanel.js.map +1 -1
- package/components/date/dateRangeInputConfirm.d.ts +31 -29
- package/components/date/dateRangeInputConfirm.js +132 -121
- package/components/date/dateRangeInputConfirm.js.map +1 -1
- package/components/date/dateTimeInput.d.ts +72 -69
- package/components/date/dateTimeInput.js +440 -412
- package/components/date/dateTimeInput.js.map +1 -1
- package/components/date/durationInput.d.ts +59 -56
- package/components/date/durationInput.js +269 -280
- package/components/date/durationInput.js.map +1 -1
- package/components/form/NiceFormItem.d.ts +14 -14
- package/components/form/NiceFormItem.js +28 -31
- package/components/form/NiceFormItem.js.map +1 -1
- package/components/grid/cell/beanAccessor.d.ts +9 -0
- package/components/grid/cell/beanAccessor.js +13 -0
- package/components/grid/cell/beanAccessor.js.map +1 -0
- package/components/grid/cell/cellEditorUtils.d.ts +4 -4
- package/components/grid/cell/cellEditorUtils.js +8 -8
- package/components/grid/cell/customEnumCellEditor.d.ts +4 -26
- package/components/grid/cell/customEnumCellEditor.js +82 -91
- package/components/grid/cell/customEnumCellEditor.js.map +1 -1
- package/components/grid/cell/dataGridCellEditorComponent.d.ts +14 -0
- package/components/grid/cell/dataGridCellEditorComponent.js +49 -0
- package/components/grid/cell/dataGridCellEditorComponent.js.map +1 -0
- package/components/grid/cell/dateCellEditor.d.ts +4 -25
- package/components/grid/cell/dateCellEditor.js +53 -72
- package/components/grid/cell/dateCellEditor.js.map +1 -1
- package/components/grid/cell/durationCellEditor.d.ts +4 -24
- package/components/grid/cell/durationCellEditor.js +74 -97
- package/components/grid/cell/durationCellEditor.js.map +1 -1
- package/components/grid/cell/hexaOctetStringCellEditor.d.ts +4 -24
- package/components/grid/cell/hexaOctetStringCellEditor.js +70 -94
- package/components/grid/cell/hexaOctetStringCellEditor.js.map +1 -1
- package/components/grid/cell/hexaValueCellEditor.d.ts +4 -24
- package/components/grid/cell/hexaValueCellEditor.js +65 -89
- package/components/grid/cell/hexaValueCellEditor.js.map +1 -1
- package/components/grid/cell/numberCellEditor.d.ts +4 -27
- package/components/grid/cell/numberCellEditor.js +73 -95
- package/components/grid/cell/numberCellEditor.js.map +1 -1
- package/components/grid/cell/rangeSelector.d.ts +78 -78
- package/components/grid/cell/rangeSelector.js +526 -518
- package/components/grid/cell/rangeSelector.js.map +1 -1
- package/components/grid/cell/simpleStatusTextCellEditor.d.ts +4 -32
- package/components/grid/cell/simpleStatusTextCellEditor.js +106 -116
- package/components/grid/cell/simpleStatusTextCellEditor.js.map +1 -1
- package/components/grid/cell/statusTextCellEditor.d.ts +4 -32
- package/components/grid/cell/statusTextCellEditor.js +136 -159
- package/components/grid/cell/statusTextCellEditor.js.map +1 -1
- package/components/grid/cell/tableDefaultRowStyleRules.d.ts +20 -20
- package/components/grid/cell/tableDefaultRowStyleRules.js +29 -18
- package/components/grid/cell/tableDefaultRowStyleRules.js.map +1 -1
- package/components/grid/cell/textCellEditor.d.ts +4 -21
- package/components/grid/cell/textCellEditor.js +63 -85
- package/components/grid/cell/textCellEditor.js.map +1 -1
- package/components/grid/cell/withAgGridHooks.d.ts +3 -0
- package/components/grid/cell/withAgGridHooks.js +15 -0
- package/components/grid/cell/withAgGridHooks.js.map +1 -0
- package/components/grid/columnUtils.d.ts +5 -5
- package/components/grid/columnUtils.js +26 -26
- package/components/grid/columnUtils.js.map +1 -1
- package/components/grid/config/columnTransfer.d.ts +21 -22
- package/components/grid/config/columnTransfer.js +205 -201
- package/components/grid/config/columnTransfer.js.map +1 -1
- package/components/grid/config/dataGridEditor.d.ts +41 -41
- package/components/grid/config/dataGridEditor.js +181 -160
- package/components/grid/config/dataGridEditor.js.map +1 -1
- package/components/grid/config/rowHeightCalculator.d.ts +8 -0
- package/components/grid/config/rowHeightCalculator.js +20 -0
- package/components/grid/config/rowHeightCalculator.js.map +1 -0
- package/components/grid/config/rowStylePicker.d.ts +27 -25
- package/components/grid/config/rowStylePicker.js +127 -109
- package/components/grid/config/rowStylePicker.js.map +1 -1
- package/components/grid/dataGrid.d.ts +218 -206
- package/components/grid/dataGrid.js +1629 -1538
- package/components/grid/dataGrid.js.map +1 -1
- package/components/grid/detail/detailHeaderPanel.d.ts +13 -13
- package/components/grid/detail/detailHeaderPanel.js +25 -25
- package/components/grid/detail/detailHeaderPanel.js.map +1 -1
- package/components/grid/export/contextMenu.d.ts +18 -24
- package/components/grid/export/contextMenu.js +116 -113
- package/components/grid/export/contextMenu.js.map +1 -1
- package/components/grid/export/progressPopup.d.ts +29 -29
- package/components/grid/export/progressPopup.js +93 -93
- package/components/grid/export/progressPopup.js.map +1 -1
- package/components/grid/export/worker/clipboardExport.d.ts +1 -1
- package/components/grid/export/worker/clipboardExport.js +8 -8
- package/components/grid/export/worker/csvExport.d.ts +1 -1
- package/components/grid/export/worker/csvExport.js +8 -8
- package/components/grid/export/worker/pdfExport.d.ts +1 -1
- package/components/grid/export/worker/pdfExport.js +81 -81
- package/components/grid/export/worker/pdfExport.js.map +1 -1
- package/components/grid/export/worker/txtExport.d.ts +1 -1
- package/components/grid/export/worker/txtExport.js +19 -19
- package/components/grid/extendedDataGrid.d.ts +140 -140
- package/components/grid/extendedDataGrid.js +704 -695
- package/components/grid/extendedDataGrid.js.map +1 -1
- package/components/grid/filter/customColumnFilter.d.ts +5 -21
- package/components/grid/filter/customColumnFilter.js +11 -82
- package/components/grid/filter/customColumnFilter.js.map +1 -1
- package/components/grid/filter/dataGridColumnFilter.d.ts +17 -0
- package/components/grid/filter/dataGridColumnFilter.js +49 -0
- package/components/grid/filter/dataGridColumnFilter.js.map +1 -0
- package/components/grid/filter/dateColumnFilter.d.ts +7 -11
- package/components/grid/filter/dateColumnFilter.js +22 -56
- package/components/grid/filter/dateColumnFilter.js.map +1 -1
- package/components/grid/filter/textColumnFilter.d.ts +8 -20
- package/components/grid/filter/textColumnFilter.js +24 -76
- package/components/grid/filter/textColumnFilter.js.map +1 -1
- package/components/grid/filter/wildcardQuickFilterEngine.d.ts +7 -0
- package/components/grid/filter/wildcardQuickFilterEngine.js +48 -0
- package/components/grid/filter/wildcardQuickFilterEngine.js.map +1 -0
- package/components/grid/header/simpleHeader.d.ts +17 -16
- package/components/grid/header/simpleHeader.js +230 -186
- package/components/grid/header/simpleHeader.js.map +1 -1
- package/components/grid/panel/dataGridPagination.d.ts +16 -16
- package/components/grid/panel/dataGridPagination.js +58 -58
- package/components/grid/panel/dataGridPagination.js.map +1 -1
- package/components/grid/panel/loadingOverlay.d.ts +6 -6
- package/components/grid/panel/loadingOverlay.js +10 -10
- package/components/grid/panel/loadingOverlay.js.map +1 -1
- package/components/grid/panel/noRecordsOverlay.d.ts +6 -6
- package/components/grid/panel/noRecordsOverlay.js +10 -10
- package/components/grid/panel/noRecordsOverlay.js.map +1 -1
- package/components/grid/panel/tablePagination.d.ts +10 -10
- package/components/grid/panel/tablePagination.js +45 -45
- package/components/grid/panel/tablePagination.js.map +1 -1
- package/components/icons/dropdownArrow.d.ts +8 -0
- package/components/icons/dropdownArrow.js +59 -0
- package/components/icons/dropdownArrow.js.map +1 -0
- package/components/icons/undoIcon.d.ts +8 -8
- package/components/icons/undoIcon.js +6 -6
- package/components/input/autoCompleteInput.d.ts +35 -35
- package/components/input/autoCompleteInput.js +122 -121
- package/components/input/autoCompleteInput.js.map +1 -1
- package/components/input/draftUtils.d.ts +4 -4
- package/components/input/draftUtils.js +48 -48
- package/components/input/draftUtils.js.map +1 -1
- package/components/input/draftail.d.ts +1 -1
- package/components/input/draftail.js +1 -1
- package/components/input/hexaFormattedInput.d.ts +16 -16
- package/components/input/hexaFormattedInput.js +54 -54
- package/components/input/hexaFormattedInput.js.map +1 -1
- package/components/input/mask/helpers.d.ts +28 -28
- package/components/input/mask/helpers.js +112 -112
- package/components/input/mask/helpers.js.map +1 -1
- package/components/input/mask/inputMaskCore.d.ts +46 -46
- package/components/input/mask/inputMaskCore.js +278 -278
- package/components/input/mask/inputMaskCore.js.map +1 -1
- package/components/input/mask/pattern.d.ts +20 -20
- package/components/input/mask/pattern.js +78 -78
- package/components/input/mask/pattern.js.map +1 -1
- package/components/input/maskedInput.d.ts +373 -351
- package/components/input/maskedInput.js +224 -224
- package/components/input/maskedInput.js.map +1 -1
- package/components/input/passwordInput.d.ts +9 -9
- package/components/input/passwordInput.js +55 -55
- package/components/input/passwordInput.js.map +1 -1
- package/components/input/simpleAutoComplete.d.ts +12 -12
- package/components/input/simpleAutoComplete.js +41 -43
- package/components/input/simpleAutoComplete.js.map +1 -1
- package/components/input/textarea/extractSpansOfClasses.d.ts +15 -15
- package/components/input/textarea/extractSpansOfClasses.js +96 -96
- package/components/input/textarea/extractSpansOfClasses.js.map +1 -1
- package/components/input/textarea/getRanges.d.ts +1 -1
- package/components/input/textarea/getRanges.js +73 -73
- package/components/input/textarea/getRanges.js.map +1 -1
- package/components/input/textarea/getType.d.ts +1 -1
- package/components/input/textarea/getType.js +26 -26
- package/components/input/textarea/getType.js.map +1 -1
- package/components/input/textarea/highlighedContents.d.ts +6 -6
- package/components/input/textarea/highlighedContents.js +10 -10
- package/components/input/textarea/mentionsWithHighlighting.d.ts +27 -27
- package/components/input/textarea/mentionsWithHighlighting.js +60 -60
- package/components/input/textarea/mentionsWithHighlighting.js.map +1 -1
- package/components/keyboard/keyboardUtils.d.ts +5 -5
- package/components/keyboard/keyboardUtils.js +32 -32
- package/components/modal/draggableModalProvider.d.ts +4 -4
- package/components/modal/draggableModalProvider.js +21 -21
- package/components/modal/draggableModalProvider.js.map +1 -1
- package/components/modal/impl/clamp.d.ts +1 -1
- package/components/modal/impl/clamp.js +1 -1
- package/components/modal/impl/clamp.js.map +1 -1
- package/components/modal/impl/draggableModal.d.ts +12 -12
- package/components/modal/impl/draggableModal.js +17 -17
- package/components/modal/impl/draggableModal.js.map +1 -1
- package/components/modal/impl/draggableModalContext.d.ts +9 -9
- package/components/modal/impl/draggableModalContext.js +2 -2
- package/components/modal/impl/draggableModalContext.js.map +1 -1
- package/components/modal/impl/draggableModalInner.d.ts +15 -13
- package/components/modal/impl/draggableModalInner.js +57 -55
- package/components/modal/impl/draggableModalInner.js.map +1 -1
- package/components/modal/impl/draggableModalReducer.d.ts +66 -62
- package/components/modal/impl/draggableModalReducer.js +77 -78
- package/components/modal/impl/draggableModalReducer.js.map +1 -1
- package/components/modal/impl/getWindowSize.d.ts +4 -4
- package/components/modal/impl/getWindowSize.js +4 -4
- package/components/modal/impl/getWindowSize.js.map +1 -1
- package/components/modal/impl/index.d.ts +3 -3
- package/components/modal/impl/index.js +3 -3
- package/components/modal/impl/index.js.map +1 -1
- package/components/modal/impl/resizeHandle.d.ts +3 -3
- package/components/modal/impl/resizeHandle.js +4 -4
- package/components/modal/impl/resizeHandle.js.map +1 -1
- package/components/modal/impl/useDrag.d.ts +5 -5
- package/components/modal/impl/useDrag.js +42 -42
- package/components/modal/impl/useDrag.js.map +1 -1
- package/components/modal/impl/usePrevious.d.ts +1 -1
- package/components/modal/impl/usePrevious.js +8 -8
- package/components/modal/impl/usePrevious.js.map +1 -1
- package/components/modal/impl/useResize.d.ts +7 -7
- package/components/modal/impl/useResize.js +46 -46
- package/components/modal/impl/useResize.js.map +1 -1
- package/components/modal/modalDialog.d.ts +49 -49
- package/components/modal/modalDialog.js +152 -152
- package/components/modal/modalDialog.js.map +1 -1
- package/components/picker/enumValuePicker.d.ts +16 -16
- package/components/picker/enumValuePicker.js +34 -34
- package/components/picker/enumValuePicker.js.map +1 -1
- package/components/platformSpecific.d.ts +10 -10
- package/components/platformSpecific.js +27 -27
- package/components/scrollTo/onlyText.d.ts +4 -4
- package/components/scrollTo/onlyText.js +30 -30
- package/components/scrollTo/onlyText.js.map +1 -1
- package/components/scrollTo/scrollTo.d.ts +41 -39
- package/components/scrollTo/scrollTo.js +264 -264
- package/components/scrollTo/scrollTo.js.map +1 -1
- package/components/style/withCss.d.ts +9 -0
- package/components/style/withCss.js +6 -0
- package/components/style/withCss.js.map +1 -0
- package/components/style/withInputNumberCss.d.ts +6 -0
- package/components/style/withInputNumberCss.js +13 -0
- package/components/style/withInputNumberCss.js.map +1 -0
- package/components/table/dragSortingTable.d.ts +13 -14
- package/components/table/dragSortingTable.js +96 -82
- package/components/table/dragSortingTable.js.map +1 -1
- package/components/text/impl/innerSize.d.ts +2 -2
- package/components/text/impl/innerSize.js +12 -12
- package/components/text/impl/series.d.ts +1 -1
- package/components/text/impl/series.js +28 -28
- package/components/text/impl/shallowEqual.d.ts +1 -1
- package/components/text/impl/shallowEqual.js +18 -18
- package/components/text/impl/shallowEqual.js.map +1 -1
- package/components/text/impl/uniqueId.d.ts +1 -1
- package/components/text/impl/uniqueId.js +4 -4
- package/components/text/impl/whilst.d.ts +1 -1
- package/components/text/impl/whilst.js +19 -19
- package/components/text/impl/whilst.js.map +1 -1
- package/components/text/textFit.d.ts +38 -38
- package/components/text/textFit.js +165 -168
- package/components/text/textFit.js.map +1 -1
- package/i18n/components.cs.json +101 -100
- package/i18n/components.sk.json +101 -100
- package/i18n/components.uk.json +101 -100
- package/i18n/componentsLocaleHolder.d.ts +3 -3
- package/i18n/componentsLocaleHolder.js +28 -28
- package/i18n/componentsLocaleHolder.js.map +1 -1
- package/package.json +71 -70
- package/style/index.less +274 -298
- package/style/modal/DraggableModal.css +43 -40
- package/style/modal/ResizeHandle.css +27 -19
- package/tsconfig.build.json +24 -24
- package/tsconfig.json +11 -11
- package/components/grid/cell/wildcardQuickFilter.d.ts +0 -11
- package/components/grid/cell/wildcardQuickFilter.js +0 -61
- package/components/grid/cell/wildcardQuickFilter.js.map +0 -1
- package/components/table/dataTable.d.ts +0 -17
- package/components/table/dataTable.js +0 -79
- package/components/table/dataTable.js.map +0 -1
- package/style/antd/antd-tree-showline.css +0 -25
- package/style/antd/full-height-tabs.scss +0 -63
- package/style/draftail/draftail-editor.css +0 -179
- package/style/table/dragSortingTable.css +0 -7
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
const noop = () => { };
|
|
2
|
-
export default function whilst(test, iterator, callback = noop) {
|
|
3
|
-
if (test()) {
|
|
4
|
-
iterator(function next(err, ...args) {
|
|
5
|
-
if (err) {
|
|
6
|
-
callback(err);
|
|
7
|
-
}
|
|
8
|
-
else if (test.apply(this, args)) {
|
|
9
|
-
iterator(next);
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
callback(null);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
callback(null);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
1
|
+
const noop = () => { };
|
|
2
|
+
export default function whilst(test, iterator, callback = noop) {
|
|
3
|
+
if (test()) {
|
|
4
|
+
iterator(function next(err, ...args) {
|
|
5
|
+
if (err) {
|
|
6
|
+
callback(err);
|
|
7
|
+
}
|
|
8
|
+
else if (test.apply(this, args)) {
|
|
9
|
+
iterator(next);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
callback(null);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
callback(null);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
20
|
//# sourceMappingURL=whilst.js.map
|
|
@@ -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;
|
|
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 = () => {};\n\n/**\n * Repeatedly call fn, while test returns true. Calls callback when stopped, or an error occurs.\n *\n * @param {Function} test Synchronous truth test to perform before each execution of fn.\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.\n * @param {Function} callback A callback which is called after the test fails and repeated execution of fn has stopped.\n */\n\nexport default function whilst(test: ()=>boolean, iterator:Function, callback:Function= noop) {\n if (test()) {\n iterator(function next(this: any, err:string, ...args:any) {\n if (err) {\n callback(err);\n } else if (test.apply(this, args)) {\n iterator(next);\n } else {\n callback(null);\n }\n });\n } else {\n callback(null);\n }\n}\n"]}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
declare function noop(): void;
|
|
3
|
-
interface TextFitProperties extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
|
|
4
|
-
text?: string;
|
|
5
|
-
min: number;
|
|
6
|
-
max: number;
|
|
7
|
-
mode: 'single' | 'multi';
|
|
8
|
-
forceSingleModeWidth: boolean;
|
|
9
|
-
throttle: number;
|
|
10
|
-
onReady: (mid: number) => void;
|
|
11
|
-
autoResize?: boolean;
|
|
12
|
-
}
|
|
13
|
-
interface TextFitState {
|
|
14
|
-
fontSize: number | null;
|
|
15
|
-
ready: boolean;
|
|
16
|
-
}
|
|
17
|
-
export default class TextFit extends React.Component<TextFitProperties, TextFitState> {
|
|
18
|
-
pid?: number;
|
|
19
|
-
static defaultProps: {
|
|
20
|
-
min: number;
|
|
21
|
-
max: number;
|
|
22
|
-
mode: string;
|
|
23
|
-
forceSingleModeWidth: boolean;
|
|
24
|
-
throttle: number;
|
|
25
|
-
autoResize: boolean;
|
|
26
|
-
onReady: typeof noop;
|
|
27
|
-
};
|
|
28
|
-
private _parent;
|
|
29
|
-
private _child;
|
|
30
|
-
constructor(props: Readonly<TextFitProperties>);
|
|
31
|
-
componentDidMount(): void;
|
|
32
|
-
componentDidUpdate(prevProps: Readonly<TextFitProperties>): void;
|
|
33
|
-
componentWillUnmount(): void;
|
|
34
|
-
handleWindowResize: () => void;
|
|
35
|
-
process(): void;
|
|
36
|
-
render(): JSX.Element;
|
|
37
|
-
}
|
|
38
|
-
export {};
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare function noop(): void;
|
|
3
|
+
interface TextFitProperties extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
|
|
4
|
+
text?: string;
|
|
5
|
+
min: number;
|
|
6
|
+
max: number;
|
|
7
|
+
mode: 'single' | 'multi';
|
|
8
|
+
forceSingleModeWidth: boolean;
|
|
9
|
+
throttle: number;
|
|
10
|
+
onReady: (mid: number) => void;
|
|
11
|
+
autoResize?: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface TextFitState {
|
|
14
|
+
fontSize: number | null;
|
|
15
|
+
ready: boolean;
|
|
16
|
+
}
|
|
17
|
+
export default class TextFit extends React.Component<TextFitProperties, TextFitState> {
|
|
18
|
+
pid?: number;
|
|
19
|
+
static defaultProps: {
|
|
20
|
+
min: number;
|
|
21
|
+
max: number;
|
|
22
|
+
mode: string;
|
|
23
|
+
forceSingleModeWidth: boolean;
|
|
24
|
+
throttle: number;
|
|
25
|
+
autoResize: boolean;
|
|
26
|
+
onReady: typeof noop;
|
|
27
|
+
};
|
|
28
|
+
private _parent;
|
|
29
|
+
private _child;
|
|
30
|
+
constructor(props: Readonly<TextFitProperties>);
|
|
31
|
+
componentDidMount(): void;
|
|
32
|
+
componentDidUpdate(prevProps: Readonly<TextFitProperties>): void;
|
|
33
|
+
componentWillUnmount(): void;
|
|
34
|
+
handleWindowResize: () => void;
|
|
35
|
+
process(): void;
|
|
36
|
+
render(): React.JSX.Element;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -1,169 +1,166 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import React from 'react';
|
|
13
|
-
import shallowEqual from 'd2coreui/components/text/impl/shallowEqual';
|
|
14
|
-
import series from 'd2coreui/components/text/impl/series';
|
|
15
|
-
import whilst from 'd2coreui/components/text/impl/whilst';
|
|
16
|
-
import debounce from 'lodash/debounce';
|
|
17
|
-
import uniqueId from 'd2coreui/components/text/impl/uniqueId';
|
|
18
|
-
import { innerHeight, innerWidth } from 'd2coreui/components/text/impl/innerSize';
|
|
19
|
-
function assertElementFitsWidth(el, width) {
|
|
20
|
-
return el && el.scrollWidth - 1 <= width;
|
|
21
|
-
}
|
|
22
|
-
function assertElementFitsHeight(el, height) {
|
|
23
|
-
return el && el.scrollHeight - 1 <= height;
|
|
24
|
-
}
|
|
25
|
-
function noop() {
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
constructor(props) {
|
|
29
|
-
super(props);
|
|
30
|
-
this._parent = null;
|
|
31
|
-
this._child = null;
|
|
32
|
-
this.handleWindowResize = () => {
|
|
33
|
-
this.process();
|
|
34
|
-
};
|
|
35
|
-
this.state = {
|
|
36
|
-
fontSize: null,
|
|
37
|
-
ready: false
|
|
38
|
-
};
|
|
39
|
-
this.handleWindowResize = debounce(this.handleWindowResize, this.props.throttle);
|
|
40
|
-
}
|
|
41
|
-
componentDidMount() {
|
|
42
|
-
const { autoResize } = this.props;
|
|
43
|
-
if (autoResize) {
|
|
44
|
-
window.addEventListener('resize', this.handleWindowResize);
|
|
45
|
-
}
|
|
46
|
-
this.process();
|
|
47
|
-
}
|
|
48
|
-
componentDidUpdate(prevProps) {
|
|
49
|
-
const { ready } = this.state;
|
|
50
|
-
if (!ready)
|
|
51
|
-
return;
|
|
52
|
-
if (shallowEqual(this.props, prevProps))
|
|
53
|
-
return;
|
|
54
|
-
this.process();
|
|
55
|
-
}
|
|
56
|
-
componentWillUnmount() {
|
|
57
|
-
const { autoResize } = this.props;
|
|
58
|
-
if (autoResize) {
|
|
59
|
-
window.removeEventListener('resize', this.handleWindowResize);
|
|
60
|
-
}
|
|
61
|
-
this.pid = uniqueId();
|
|
62
|
-
}
|
|
63
|
-
process() {
|
|
64
|
-
const { min, max, mode, forceSingleModeWidth, onReady } = this.props;
|
|
65
|
-
const el = this._parent;
|
|
66
|
-
const wrapper = this._child;
|
|
67
|
-
const originalWidth = el ? innerWidth(el) : 0;
|
|
68
|
-
const originalHeight = el ? innerHeight(el) : 0;
|
|
69
|
-
if (originalHeight <= 0 || isNaN(originalHeight)) {
|
|
70
|
-
console.warn('Can not process element without height. Make sure the element is displayed and has a static height.');
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (originalWidth <= 0 || isNaN(originalWidth)) {
|
|
74
|
-
console.warn('Can not process element without width. Make sure the element is displayed and has a static width.');
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const pid = uniqueId();
|
|
78
|
-
this.pid = pid;
|
|
79
|
-
const shouldCancelProcess = () => pid !== this.pid;
|
|
80
|
-
const testPrimary = mode === 'multi'
|
|
81
|
-
? () => assertElementFitsHeight(wrapper, originalHeight)
|
|
82
|
-
: () => assertElementFitsWidth(wrapper, originalWidth);
|
|
83
|
-
const testSecondary = mode === 'multi'
|
|
84
|
-
? () => assertElementFitsWidth(wrapper, originalWidth)
|
|
85
|
-
: () => assertElementFitsHeight(wrapper, originalHeight);
|
|
86
|
-
let mid;
|
|
87
|
-
let low = min;
|
|
88
|
-
let high = max;
|
|
89
|
-
this.setState({ ready: false });
|
|
90
|
-
series([
|
|
91
|
-
(stepCallback) => whilst(() => low <= high, (whilstCallback) => {
|
|
92
|
-
if (shouldCancelProcess())
|
|
93
|
-
return whilstCallback(true);
|
|
94
|
-
mid = parseInt("" + ((low + high) / 2), 10);
|
|
95
|
-
this.setState({ fontSize: mid }, () => {
|
|
96
|
-
if (shouldCancelProcess())
|
|
97
|
-
return whilstCallback(true);
|
|
98
|
-
if (testPrimary())
|
|
99
|
-
low = mid + 1;
|
|
100
|
-
else
|
|
101
|
-
high = mid - 1;
|
|
102
|
-
return whilstCallback();
|
|
103
|
-
});
|
|
104
|
-
}, stepCallback),
|
|
105
|
-
(stepCallback) => {
|
|
106
|
-
if (mode === 'single' && forceSingleModeWidth)
|
|
107
|
-
return stepCallback();
|
|
108
|
-
if (testSecondary())
|
|
109
|
-
return stepCallback();
|
|
110
|
-
low = min;
|
|
111
|
-
high = mid;
|
|
112
|
-
return whilst(() => low < high, (whilstCallback) => {
|
|
113
|
-
if (shouldCancelProcess()) {
|
|
114
|
-
return whilstCallback(true);
|
|
115
|
-
}
|
|
116
|
-
mid = parseInt("" + ((low + high) / 2), 10);
|
|
117
|
-
this.setState({ fontSize: mid }, () => {
|
|
118
|
-
if (pid !== this.pid)
|
|
119
|
-
return whilstCallback(true);
|
|
120
|
-
if (testSecondary())
|
|
121
|
-
low = mid + 1;
|
|
122
|
-
else
|
|
123
|
-
high = mid - 1;
|
|
124
|
-
return whilstCallback();
|
|
125
|
-
});
|
|
126
|
-
}, stepCallback);
|
|
127
|
-
},
|
|
128
|
-
(stepCallback) => {
|
|
129
|
-
mid = Math.min(low, high);
|
|
130
|
-
mid = Math.max(mid, min);
|
|
131
|
-
mid = Math.min(mid, max);
|
|
132
|
-
mid = Math.max(mid, 0);
|
|
133
|
-
if (shouldCancelProcess())
|
|
134
|
-
return stepCallback(true);
|
|
135
|
-
this.setState({ fontSize: mid }, stepCallback);
|
|
136
|
-
}
|
|
137
|
-
], (err) => {
|
|
138
|
-
if (err || shouldCancelProcess())
|
|
139
|
-
return;
|
|
140
|
-
this.setState({ ready: true }, () => onReady(mid));
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
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"]);
|
|
145
|
-
const { fontSize, ready } = this.state;
|
|
146
|
-
const finalStyle = Object.assign(Object.assign({}, style), { fontSize: fontSize ? fontSize : undefined });
|
|
147
|
-
const wrapperStyle = {
|
|
148
|
-
display: ready ? 'block' : 'inline-block'
|
|
149
|
-
};
|
|
150
|
-
if (mode === 'single')
|
|
151
|
-
wrapperStyle.whiteSpace = 'nowrap';
|
|
152
|
-
return (React.createElement("div", Object.assign({ ref: c => this._parent = c, style: finalStyle }, props),
|
|
153
|
-
React.createElement("div", { ref: c => this._child = c, style: wrapperStyle }, text
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
autoResize: true,
|
|
167
|
-
onReady: noop
|
|
168
|
-
};
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import shallowEqual from 'd2coreui/components/text/impl/shallowEqual';
|
|
14
|
+
import series from 'd2coreui/components/text/impl/series';
|
|
15
|
+
import whilst from 'd2coreui/components/text/impl/whilst';
|
|
16
|
+
import debounce from 'lodash/debounce';
|
|
17
|
+
import uniqueId from 'd2coreui/components/text/impl/uniqueId';
|
|
18
|
+
import { innerHeight, innerWidth } from 'd2coreui/components/text/impl/innerSize';
|
|
19
|
+
function assertElementFitsWidth(el, width) {
|
|
20
|
+
return el && el.scrollWidth - 1 <= width;
|
|
21
|
+
}
|
|
22
|
+
function assertElementFitsHeight(el, height) {
|
|
23
|
+
return el && el.scrollHeight - 1 <= height;
|
|
24
|
+
}
|
|
25
|
+
function noop() {
|
|
26
|
+
}
|
|
27
|
+
class TextFit extends React.Component {
|
|
28
|
+
constructor(props) {
|
|
29
|
+
super(props);
|
|
30
|
+
this._parent = null;
|
|
31
|
+
this._child = null;
|
|
32
|
+
this.handleWindowResize = () => {
|
|
33
|
+
this.process();
|
|
34
|
+
};
|
|
35
|
+
this.state = {
|
|
36
|
+
fontSize: null,
|
|
37
|
+
ready: false
|
|
38
|
+
};
|
|
39
|
+
this.handleWindowResize = debounce(this.handleWindowResize, this.props.throttle);
|
|
40
|
+
}
|
|
41
|
+
componentDidMount() {
|
|
42
|
+
const { autoResize } = this.props;
|
|
43
|
+
if (autoResize) {
|
|
44
|
+
window.addEventListener('resize', this.handleWindowResize);
|
|
45
|
+
}
|
|
46
|
+
this.process();
|
|
47
|
+
}
|
|
48
|
+
componentDidUpdate(prevProps) {
|
|
49
|
+
const { ready } = this.state;
|
|
50
|
+
if (!ready)
|
|
51
|
+
return;
|
|
52
|
+
if (shallowEqual(this.props, prevProps))
|
|
53
|
+
return;
|
|
54
|
+
this.process();
|
|
55
|
+
}
|
|
56
|
+
componentWillUnmount() {
|
|
57
|
+
const { autoResize } = this.props;
|
|
58
|
+
if (autoResize) {
|
|
59
|
+
window.removeEventListener('resize', this.handleWindowResize);
|
|
60
|
+
}
|
|
61
|
+
this.pid = uniqueId();
|
|
62
|
+
}
|
|
63
|
+
process() {
|
|
64
|
+
const { min, max, mode, forceSingleModeWidth, onReady } = this.props;
|
|
65
|
+
const el = this._parent;
|
|
66
|
+
const wrapper = this._child;
|
|
67
|
+
const originalWidth = el ? innerWidth(el) : 0;
|
|
68
|
+
const originalHeight = el ? innerHeight(el) : 0;
|
|
69
|
+
if (originalHeight <= 0 || isNaN(originalHeight)) {
|
|
70
|
+
console.warn('Can not process element without height. Make sure the element is displayed and has a static height.');
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (originalWidth <= 0 || isNaN(originalWidth)) {
|
|
74
|
+
console.warn('Can not process element without width. Make sure the element is displayed and has a static width.');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const pid = uniqueId();
|
|
78
|
+
this.pid = pid;
|
|
79
|
+
const shouldCancelProcess = () => pid !== this.pid;
|
|
80
|
+
const testPrimary = mode === 'multi'
|
|
81
|
+
? () => assertElementFitsHeight(wrapper, originalHeight)
|
|
82
|
+
: () => assertElementFitsWidth(wrapper, originalWidth);
|
|
83
|
+
const testSecondary = mode === 'multi'
|
|
84
|
+
? () => assertElementFitsWidth(wrapper, originalWidth)
|
|
85
|
+
: () => assertElementFitsHeight(wrapper, originalHeight);
|
|
86
|
+
let mid;
|
|
87
|
+
let low = min;
|
|
88
|
+
let high = max;
|
|
89
|
+
this.setState({ ready: false });
|
|
90
|
+
series([
|
|
91
|
+
(stepCallback) => whilst(() => low <= high, (whilstCallback) => {
|
|
92
|
+
if (shouldCancelProcess())
|
|
93
|
+
return whilstCallback(true);
|
|
94
|
+
mid = parseInt("" + ((low + high) / 2), 10);
|
|
95
|
+
this.setState({ fontSize: mid }, () => {
|
|
96
|
+
if (shouldCancelProcess())
|
|
97
|
+
return whilstCallback(true);
|
|
98
|
+
if (testPrimary())
|
|
99
|
+
low = mid + 1;
|
|
100
|
+
else
|
|
101
|
+
high = mid - 1;
|
|
102
|
+
return whilstCallback();
|
|
103
|
+
});
|
|
104
|
+
}, stepCallback),
|
|
105
|
+
(stepCallback) => {
|
|
106
|
+
if (mode === 'single' && forceSingleModeWidth)
|
|
107
|
+
return stepCallback();
|
|
108
|
+
if (testSecondary())
|
|
109
|
+
return stepCallback();
|
|
110
|
+
low = min;
|
|
111
|
+
high = mid;
|
|
112
|
+
return whilst(() => low < high, (whilstCallback) => {
|
|
113
|
+
if (shouldCancelProcess()) {
|
|
114
|
+
return whilstCallback(true);
|
|
115
|
+
}
|
|
116
|
+
mid = parseInt("" + ((low + high) / 2), 10);
|
|
117
|
+
this.setState({ fontSize: mid }, () => {
|
|
118
|
+
if (pid !== this.pid)
|
|
119
|
+
return whilstCallback(true);
|
|
120
|
+
if (testSecondary())
|
|
121
|
+
low = mid + 1;
|
|
122
|
+
else
|
|
123
|
+
high = mid - 1;
|
|
124
|
+
return whilstCallback();
|
|
125
|
+
});
|
|
126
|
+
}, stepCallback);
|
|
127
|
+
},
|
|
128
|
+
(stepCallback) => {
|
|
129
|
+
mid = Math.min(low, high);
|
|
130
|
+
mid = Math.max(mid, min);
|
|
131
|
+
mid = Math.min(mid, max);
|
|
132
|
+
mid = Math.max(mid, 0);
|
|
133
|
+
if (shouldCancelProcess())
|
|
134
|
+
return stepCallback(true);
|
|
135
|
+
this.setState({ fontSize: mid }, stepCallback);
|
|
136
|
+
}
|
|
137
|
+
], (err) => {
|
|
138
|
+
if (err || shouldCancelProcess())
|
|
139
|
+
return;
|
|
140
|
+
this.setState({ ready: true }, () => onReady(mid));
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
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"]);
|
|
145
|
+
const { fontSize, ready } = this.state;
|
|
146
|
+
const finalStyle = Object.assign(Object.assign({}, style), { fontSize: fontSize ? fontSize : undefined });
|
|
147
|
+
const wrapperStyle = {
|
|
148
|
+
display: ready ? 'block' : 'inline-block'
|
|
149
|
+
};
|
|
150
|
+
if (mode === 'single')
|
|
151
|
+
wrapperStyle.whiteSpace = 'nowrap';
|
|
152
|
+
return (React.createElement("div", Object.assign({ ref: c => this._parent = c, style: finalStyle }, props),
|
|
153
|
+
React.createElement("div", { ref: c => this._child = c, style: wrapperStyle }, text ? text : children)));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
TextFit.defaultProps = {
|
|
157
|
+
min: 1,
|
|
158
|
+
max: 100,
|
|
159
|
+
mode: 'multi',
|
|
160
|
+
forceSingleModeWidth: true,
|
|
161
|
+
throttle: 50,
|
|
162
|
+
autoResize: true,
|
|
163
|
+
onReady: noop
|
|
164
|
+
};
|
|
165
|
+
export default TextFit;
|
|
169
166
|
//# sourceMappingURL=textFit.js.map
|
|
@@ -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,MAAM,CAAC,OAAO,OAAO,OAAQ,SAAQ,KAAK,CAAC,SAA0C;IAejF,YAAY,KAAkC;QAC1C,K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l/shallowEqual';\nimport series from 'd2coreui/components/text/impl/series';\nimport whilst from 'd2coreui/components/text/impl/whilst';\nimport debounce from 'lodash/debounce';\nimport uniqueId from 'd2coreui/components/text/impl/uniqueId';\nimport {innerHeight, innerWidth} from 'd2coreui/components/text/impl/innerSize';\n\nfunction assertElementFitsWidth(el: HTMLElement | null, width: number) {\n // -1: temporary bugfix, will be refactored soon\n return el && el.scrollWidth - 1 <= width;\n}\n\nfunction assertElementFitsHeight(el: HTMLElement | null, height: number) {\n // -1: temporary bugfix, will be refactored soon\n return el && el.scrollHeight - 1 <= height;\n}\n\nfunction noop() {\n}\n\ninterface TextFitProperties extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {\n text?: string\n min: number\n max: number\n mode: 'single' | 'multi'\n forceSingleModeWidth: boolean,\n throttle: number,\n onReady: (mid:number) => void\n autoResize?: boolean\n}\n\ninterface TextFitState {\n fontSize: number | null\n ready: boolean\n}\n\nexport default class TextFit extends React.Component<TextFitProperties, TextFitState> {\n pid?: number\n\n static defaultProps = {\n min: 1,\n max: 100,\n mode: 'multi',\n forceSingleModeWidth: true,\n throttle: 50,\n autoResize: true,\n onReady: noop\n }\n private _parent: HTMLDivElement | null = null;\n private _child: HTMLDivElement | null = null;\n\n constructor(props: Readonly<TextFitProperties>) {\n super(props);\n this.state = {\n fontSize: null,\n ready: false\n }\n this.handleWindowResize = debounce(this.handleWindowResize, this.props.throttle);\n }\n\n componentDidMount() {\n const {autoResize} = this.props;\n if (autoResize) {\n window.addEventListener('resize', this.handleWindowResize);\n }\n this.process();\n }\n\n componentDidUpdate(prevProps: Readonly<TextFitProperties>) {\n const {ready} = this.state;\n if (!ready) return;\n if (shallowEqual(this.props, prevProps)) return;\n this.process();\n }\n\n componentWillUnmount() {\n const {autoResize} = this.props;\n if (autoResize) {\n window.removeEventListener('resize', this.handleWindowResize);\n }\n // Setting a new pid will cancel all running processes\n this.pid = uniqueId();\n }\n\n handleWindowResize = () => {\n this.process();\n }\n\n process() {\n const {min, max, mode, forceSingleModeWidth, onReady} = this.props;\n const el = this._parent;\n const wrapper = this._child;\n\n const originalWidth = el ? innerWidth(el) : 0;\n const originalHeight = el ? innerHeight(el) : 0;\n\n if (originalHeight <= 0 || isNaN(originalHeight)) {\n console.warn('Can not process element without height. Make sure the element is displayed and has a static height.');\n return;\n }\n\n if (originalWidth <= 0 || isNaN(originalWidth)) {\n console.warn('Can not process element without width. Make sure the element is displayed and has a static width.');\n return;\n }\n\n const pid = uniqueId();\n this.pid = pid;\n\n const shouldCancelProcess = () => pid !== this.pid;\n\n const testPrimary = mode === 'multi'\n ? () => assertElementFitsHeight(wrapper, originalHeight)\n : () => assertElementFitsWidth(wrapper, originalWidth);\n\n const testSecondary = mode === 'multi'\n ? () => assertElementFitsWidth(wrapper, originalWidth)\n : () => assertElementFitsHeight(wrapper, originalHeight);\n\n let mid: number;\n let low = min;\n let high = max;\n\n this.setState({ready: false});\n\n series([\n // Step 1:\n // Binary search to fit the element's height (multi line) / width (single line)\n (stepCallback: Function) => whilst(\n () => low <= high,\n (whilstCallback: Function) => {\n if (shouldCancelProcess()) return whilstCallback(true);\n mid = parseInt(\"\" + ((low + high) / 2), 10);\n this.setState({fontSize: mid}, () => {\n if (shouldCancelProcess()) return whilstCallback(true);\n if (testPrimary()) low = mid + 1;\n else high = mid - 1;\n return whilstCallback();\n });\n },\n stepCallback\n ),\n // Step 2:\n // Binary search to fit the element's width (multi line) / height (single line)\n // If mode is single and forceSingleModeWidth is true, skip this step\n // in order to not fit the elements height and decrease the width\n (stepCallback: Function) => {\n if (mode === 'single' && forceSingleModeWidth) return stepCallback();\n if (testSecondary()) return stepCallback();\n low = min;\n high = mid;\n return whilst(\n () => low < high,\n (whilstCallback: Function):any => {\n if (shouldCancelProcess()) {\n return whilstCallback(true);\n }\n mid = parseInt(\"\"+((low + high) / 2), 10);\n this.setState({fontSize: mid}, () => {\n if (pid !== this.pid) return whilstCallback(true);\n if (testSecondary()) low = mid + 1;\n else high = mid - 1;\n return whilstCallback();\n });\n },\n stepCallback\n );\n },\n // Step 3\n // Limits\n (stepCallback:Function) => {\n // We break the previous loop without updating mid for the final time,\n // so we do it here:\n mid = Math.min(low, high);\n\n // Ensure we hit the user-supplied limits\n mid = Math.max(mid, min);\n mid = Math.min(mid, max);\n\n // Sanity check:\n mid = Math.max(mid, 0);\n\n if (shouldCancelProcess()) return stepCallback(true);\n this.setState({fontSize: mid}, stepCallback as ()=>void);\n }\n ], (err:Function) => {\n // err will be true, if another process was triggered\n if (err || shouldCancelProcess()) return;\n this.setState({ready: true}, () => onReady(mid));\n });\n }\n\n render() {\n const {\n children,\n text,\n style,\n min,\n max,\n mode,\n forceSingleModeWidth,\n /* eslint-disable no-shadow */\n throttle,\n /* eslint-enable no-shadow */\n autoResize,\n onReady,\n ...props\n } = this.props;\n const {fontSize, ready} = this.state;\n const finalStyle:CSSProperties = {\n ...style,\n fontSize: fontSize ? fontSize : undefined\n };\n\n const wrapperStyle:CSSProperties = {\n display: ready ? 'block' : 'inline-block'\n };\n if (mode === 'single') wrapperStyle.whiteSpace = 'nowrap';\n\n return (\n <div ref={c => this._parent = c} style={finalStyle} {...props}>\n <div ref={c => this._child = c} style={wrapperStyle}>\n {text && typeof children === 'function'\n ? ready\n ? children(text)\n : text\n : children\n }\n </div>\n </div>\n );\n }\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,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;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I,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}"]}
|