d2coreui 21.0.25 → 21.0.26
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.
|
@@ -58,9 +58,14 @@ export default class ContextMenu extends React.Component {
|
|
|
58
58
|
const tableContent = await this.props.getExportContent(progressPopup, this.props);
|
|
59
59
|
const clipboardExport = await spawn(new Worker(clipboardExportUrl));
|
|
60
60
|
const clipboardContent = await clipboardExport(tableContent);
|
|
61
|
-
ClipboardUtils.copyToClipboard(clipboardContent);
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const success = ClipboardUtils.copyToClipboard(clipboardContent);
|
|
62
|
+
if (success) {
|
|
63
|
+
await Thread.terminate(clipboardExport);
|
|
64
|
+
await (progressPopup === null || progressPopup === void 0 ? void 0 : progressPopup.update(100));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
progressPopup === null || progressPopup === void 0 ? void 0 : progressPopup.error();
|
|
68
|
+
}
|
|
64
69
|
break;
|
|
65
70
|
}
|
|
66
71
|
case "pdfExport": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextMenu.js","sourceRoot":"","sources":["../../../../../components/grid/export/contextMenu.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAC,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAChG,OAAO,EAAC,IAAI,EAAE,MAAM,EAAC,MAAM,MAAM,CAAC;AAClC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,EAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAC,MAAM,SAAS,CAAA;AAC7C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAC,cAAc,EAAC,MAAM,8CAA8C,CAAC;AAE5E,OAAO,YAAY,MAAM,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,UAAU,EAClD,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAa,EAAE,EAAE;wBACjC,CAAC,CAAC,eAAe,EAAE,CAAC;wBACnB,CAAS,CAAC,WAAW,CAAC,wBAAwB,EAAE,CAAC;wBAClD,IAAI,CAAC,QAAQ,CAAC,EAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,EAAC,CAAC,CAAC;oBACzE,CAAC,GACH,CAAY;YAClB,oBAAC,IAAI,CAAC,OAAO,IAAC,GAAG,EAAC,UAAU,GAAE;YAC9B,oBAAC,IAAI,CAAC,IAAI,IAAC,GAAG,EAAC,eAAe,EAAC,IAAI,EAAE,oBAAC,YAAY,OAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,IAAG,IAAI,CAAC,mBAAmB,CAAC,CACpG;SACf,CAAC;IACN,CAAC;CACJ","sourcesContent":["import {CopyOutlined, FileOutlined, FilePdfOutlined, FileTextOutlined} from \"@ant-design/icons\";\nimport {Menu, Switch} from \"antd\";\nimport React from \"react\";\nimport i18n from \"d2core/i18n/i18n\";\nimport {spawn, Thread, Worker} from \"threads\"\nimport moment from \"moment\";\nimport ProgressPopup from \"./progressPopup\";\nimport {MenuElement} from \"../dataGrid\";\nimport {ClipboardUtils} from \"d2coreui/components/clipboard/clipboardUtils\";\n// @ts-ignore\nimport txtExportUrl from 'threads-plugin/dist/loader?name=txtExport!d2coreui/components/grid/export/worker/txtExport.ts'\n// @ts-ignore\nimport csvExportUrl from \"threads-plugin/dist/loader?name=csvExport!d2coreui/components/grid/export/worker/csvExport.ts\"\n// @ts-ignore\nimport clipboardExportUrl from \"threads-plugin/dist/loader?name=clipboardExport!d2coreui/components/grid/export/worker/clipboardExport.ts\"\n// @ts-ignore\nimport pdfExportUrl from \"threads-plugin/dist/loader?name=pdfExport!d2coreui/components/grid/export/worker/pdfExport.ts\"\nimport PlatformSpecific from \"d2coreui/components/platformSpecific\";\n\n\nexport interface ContextMenuProps {\n onlySelectedNodes?: boolean\n showMilliseconds: boolean\n showYear: boolean\n hideNotificationOnClipboardCopy?: boolean\n\n getExportContent: (progressPopup: ProgressPopup | null, props: ContextMenuProps) => Promise<string[][]>\n\n // overrides context menu rendering\n renderer?(menuElements: MenuElement[]): MenuElement[]\n\n // handler for custom context menu items click\n onClick?(key: string): void\n}\n\ntype PageOrientation = \"PORTRAIT\" | \"LANDSCAPE\";\n\ninterface ContextMenuState {\n pageOrientation: PageOrientation\n exporting: boolean\n}\n\n\nexport default class ContextMenu extends React.Component<ContextMenuProps, ContextMenuState> {\n constructor(props: Readonly<ContextMenuProps>) {\n super(props);\n this.state = {\n pageOrientation: \"PORTRAIT\",\n exporting: false\n };\n }\n\n async onExportMenuClick(menuKey: string) {\n this.setState({exporting: true});\n switch (menuKey) {\n case \"txtExport\": {\n const progressPopup = new ProgressPopup(i18n(\"Export List to\") + \" TXT\");\n const tableContent = await this.props.getExportContent(progressPopup, this.props);\n const txtExport = await spawn(new Worker(txtExportUrl));\n const textContent = await txtExport(tableContent);\n await Thread.terminate(txtExport);\n await progressPopup.update(100);\n PlatformSpecific.INSTANCE.saveContent(`export_${moment().format(\"YYYYMMDD_HHmm\")}.txt`, textContent, true);\n break;\n }\n case \"csvExport\": {\n const progressPopup = new ProgressPopup(i18n(\"Export List to\") + \" CSV\");\n const tableContent = await this.props.getExportContent(progressPopup, this.props);\n const csvExport = await spawn(new Worker(csvExportUrl));\n const csvContent = await csvExport(tableContent);\n await Thread.terminate(csvExport);\n await progressPopup.update(100);\n PlatformSpecific.INSTANCE.saveContent(`export_${moment().format(\"YYYYMMDD_HHmm\")}.csv`, `\\ufeff${csvContent}`, true);\n break;\n }\n case \"clipboardCopy\": {\n const progressPopup = !this.props.hideNotificationOnClipboardCopy ? new ProgressPopup(i18n(\"Export List to\") + \" \" + i18n(\"Clipboard\")) : null;\n const tableContent = await this.props.getExportContent(progressPopup, this.props);\n const clipboardExport = await spawn(new Worker(clipboardExportUrl));\n const clipboardContent = await clipboardExport(tableContent);\n ClipboardUtils.copyToClipboard(clipboardContent);\n await Thread.terminate(clipboardExport);\n await progressPopup?.update(100);\n break;\n }\n case \"pdfExport\": {\n const progressPopup = new ProgressPopup(i18n(\"Export List to\") + \" PDF\");\n const tableContent = await this.props.getExportContent(progressPopup, this.props);\n const pdfExport = await spawn(new Worker(pdfExportUrl));\n pdfExport.handler().subscribe(async (data: string) => {\n Thread.terminate(pdfExport);\n await progressPopup.update(100);\n PlatformSpecific.INSTANCE.saveContent(`export_${moment().format(\"YYYYMMDD_HHmm\")}.pdf`, data, false);\n });\n pdfExport.export(tableContent, {pageOrientation: this.state.pageOrientation});\n }\n }\n this.setState({exporting: false});\n }\n\n render() {\n const {onlySelectedNodes, showMilliseconds, showYear, hideNotificationOnClipboardCopy, getExportContent, renderer, ...rest} = this.props;\n let menuItems: MenuElement[] = this.renderExportMenuItems();\n if (renderer) {\n menuItems = renderer(menuItems);\n }\n return (\n <Menu {...rest}\n onClick={(item: any) => {\n this.onExportMenuClick(item.key);\n if (this.props.onClick) {\n this.props.onClick(item.key.toString());\n }\n }}>\n {menuItems}\n </Menu>);\n }\n\n renderExportMenuItems() {\n return [\n <Menu.Item icon={<FileOutlined/>} key=\"txtExport\" disabled={this.state.exporting}>{i18n(\"Export List to\") + \" TXT\"}\n </Menu.Item>,\n <Menu.Item icon={<FileTextOutlined/>} key=\"csvExport\"\n disabled={this.state.exporting}>{i18n(\"Export List to\") + \" CSV\"}\n </Menu.Item>,\n <Menu.Item icon={<FilePdfOutlined/>} key=\"pdfExport\"\n disabled={this.state.exporting}>{i18n(\"Export List to\") + \" PDF\"}\n <Switch\n style={{marginLeft: 8}}\n checkedChildren={i18n(\"Landscape\") + \" \"}\n unCheckedChildren={\"\" + i18n(\"Portrait\")}\n checked={this.state.pageOrientation !== \"PORTRAIT\"}\n onChange={(checked, e: MouseEvent) => {\n e.stopPropagation();\n (e as any).nativeEvent.stopImmediatePropagation();\n this.setState({pageOrientation: checked ? \"LANDSCAPE\" : \"PORTRAIT\"});\n }}\n /></Menu.Item>,\n <Menu.Divider key=\"divider1\"/>,\n <Menu.Item key=\"clipboardCopy\" icon={<CopyOutlined/>} disabled={this.state.exporting}>{i18n(\"Copy to Clipboard\")}\n </Menu.Item>\n ];\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"contextMenu.js","sourceRoot":"","sources":["../../../../../components/grid/export/contextMenu.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAC,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAChG,OAAO,EAAC,IAAI,EAAE,MAAM,EAAC,MAAM,MAAM,CAAC;AAClC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,EAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAC,MAAM,SAAS,CAAA;AAC7C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAC,cAAc,EAAC,MAAM,8CAA8C,CAAC;AAE5E,OAAO,YAAY,MAAM,+FAA+F,CAAA;AAExH,OAAO,YAAY,MAAM,+FAA+F,CAAA;AAExH,OAAO,kBAAkB,MAAM,2GAA2G,CAAA;AAE1I,OAAO,YAAY,MAAM,+FAA+F,CAAA;AACxH,OAAO,gBAAgB,MAAM,sCAAsC,CAAC;AA0BpE,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,KAAK,CAAC,SAA6C;IACxF,YAAY,KAAiC;QACzC,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,KAAK,GAAG;YACT,eAAe,EAAE,UAAU;YAC3B,SAAS,EAAE,KAAK;SACnB,CAAC;IACN,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,OAAe;QACnC,IAAI,CAAC,QAAQ,CAAC,EAAC,SAAS,EAA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GAAE;YAC9B,oBAAC,IAAI,CAAC,IAAI,IAAC,GAAG,EAAC,eAAe,EAAC,IAAI,EAAE,oBAAC,YAAY,OAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,IAAG,IAAI,CAAC,mBAAmB,CAAC,CACpG;SACf,CAAC;IACN,CAAC;CACJ","sourcesContent":["import {CopyOutlined, FileOutlined, FilePdfOutlined, FileTextOutlined} from \"@ant-design/icons\";\nimport {Menu, Switch} from \"antd\";\nimport React from \"react\";\nimport i18n from \"d2core/i18n/i18n\";\nimport {spawn, Thread, Worker} from \"threads\"\nimport moment from \"moment\";\nimport ProgressPopup from \"./progressPopup\";\nimport {MenuElement} from \"../dataGrid\";\nimport {ClipboardUtils} from \"d2coreui/components/clipboard/clipboardUtils\";\n// @ts-ignore\nimport txtExportUrl from 'threads-plugin/dist/loader?name=txtExport!d2coreui/components/grid/export/worker/txtExport.ts'\n// @ts-ignore\nimport csvExportUrl from \"threads-plugin/dist/loader?name=csvExport!d2coreui/components/grid/export/worker/csvExport.ts\"\n// @ts-ignore\nimport clipboardExportUrl from \"threads-plugin/dist/loader?name=clipboardExport!d2coreui/components/grid/export/worker/clipboardExport.ts\"\n// @ts-ignore\nimport pdfExportUrl from \"threads-plugin/dist/loader?name=pdfExport!d2coreui/components/grid/export/worker/pdfExport.ts\"\nimport PlatformSpecific from \"d2coreui/components/platformSpecific\";\n\n\nexport interface ContextMenuProps {\n onlySelectedNodes?: boolean\n showMilliseconds: boolean\n showYear: boolean\n hideNotificationOnClipboardCopy?: boolean\n\n getExportContent: (progressPopup: ProgressPopup | null, props: ContextMenuProps) => Promise<string[][]>\n\n // overrides context menu rendering\n renderer?(menuElements: MenuElement[]): MenuElement[]\n\n // handler for custom context menu items click\n onClick?(key: string): void\n}\n\ntype PageOrientation = \"PORTRAIT\" | \"LANDSCAPE\";\n\ninterface ContextMenuState {\n pageOrientation: PageOrientation\n exporting: boolean\n}\n\n\nexport default class ContextMenu extends React.Component<ContextMenuProps, ContextMenuState> {\n constructor(props: Readonly<ContextMenuProps>) {\n super(props);\n this.state = {\n pageOrientation: \"PORTRAIT\",\n exporting: false\n };\n }\n\n async onExportMenuClick(menuKey: string) {\n this.setState({exporting: true});\n switch (menuKey) {\n case \"txtExport\": {\n const progressPopup = new ProgressPopup(i18n(\"Export List to\") + \" TXT\");\n const tableContent = await this.props.getExportContent(progressPopup, this.props);\n const txtExport = await spawn(new Worker(txtExportUrl));\n const textContent = await txtExport(tableContent);\n await Thread.terminate(txtExport);\n await progressPopup.update(100);\n PlatformSpecific.INSTANCE.saveContent(`export_${moment().format(\"YYYYMMDD_HHmm\")}.txt`, textContent, true);\n break;\n }\n case \"csvExport\": {\n const progressPopup = new ProgressPopup(i18n(\"Export List to\") + \" CSV\");\n const tableContent = await this.props.getExportContent(progressPopup, this.props);\n const csvExport = await spawn(new Worker(csvExportUrl));\n const csvContent = await csvExport(tableContent);\n await Thread.terminate(csvExport);\n await progressPopup.update(100);\n PlatformSpecific.INSTANCE.saveContent(`export_${moment().format(\"YYYYMMDD_HHmm\")}.csv`, `\\ufeff${csvContent}`, true);\n break;\n }\n case \"clipboardCopy\": {\n const progressPopup = !this.props.hideNotificationOnClipboardCopy ? new ProgressPopup(i18n(\"Export List to\") + \" \" + i18n(\"Clipboard\")) : null;\n const tableContent = await this.props.getExportContent(progressPopup, this.props);\n const clipboardExport = await spawn(new Worker(clipboardExportUrl));\n const clipboardContent = await clipboardExport(tableContent);\n const success = ClipboardUtils.copyToClipboard(clipboardContent);\n if (success) {\n await Thread.terminate(clipboardExport);\n await progressPopup?.update(100);\n } else {\n progressPopup?.error();\n }\n break;\n }\n case \"pdfExport\": {\n const progressPopup = new ProgressPopup(i18n(\"Export List to\") + \" PDF\");\n const tableContent = await this.props.getExportContent(progressPopup, this.props);\n const pdfExport = await spawn(new Worker(pdfExportUrl));\n pdfExport.handler().subscribe(async (data: string) => {\n Thread.terminate(pdfExport);\n await progressPopup.update(100);\n PlatformSpecific.INSTANCE.saveContent(`export_${moment().format(\"YYYYMMDD_HHmm\")}.pdf`, data, false);\n });\n pdfExport.export(tableContent, {pageOrientation: this.state.pageOrientation});\n }\n }\n this.setState({exporting: false});\n }\n\n render() {\n const {onlySelectedNodes, showMilliseconds, showYear, hideNotificationOnClipboardCopy, getExportContent, renderer, ...rest} = this.props;\n let menuItems: MenuElement[] = this.renderExportMenuItems();\n if (renderer) {\n menuItems = renderer(menuItems);\n }\n return (\n <Menu {...rest}\n onClick={(item: any) => {\n this.onExportMenuClick(item.key);\n if (this.props.onClick) {\n this.props.onClick(item.key.toString());\n }\n }}>\n {menuItems}\n </Menu>);\n }\n\n renderExportMenuItems() {\n return [\n <Menu.Item icon={<FileOutlined/>} key=\"txtExport\" disabled={this.state.exporting}>{i18n(\"Export List to\") + \" TXT\"}\n </Menu.Item>,\n <Menu.Item icon={<FileTextOutlined/>} key=\"csvExport\"\n disabled={this.state.exporting}>{i18n(\"Export List to\") + \" CSV\"}\n </Menu.Item>,\n <Menu.Item icon={<FilePdfOutlined/>} key=\"pdfExport\"\n disabled={this.state.exporting}>{i18n(\"Export List to\") + \" PDF\"}\n <Switch\n style={{marginLeft: 8}}\n checkedChildren={i18n(\"Landscape\") + \" \"}\n unCheckedChildren={\"\" + i18n(\"Portrait\")}\n checked={this.state.pageOrientation !== \"PORTRAIT\"}\n onChange={(checked, e: MouseEvent) => {\n e.stopPropagation();\n (e as any).nativeEvent.stopImmediatePropagation();\n this.setState({pageOrientation: checked ? \"LANDSCAPE\" : \"PORTRAIT\"});\n }}\n /></Menu.Item>,\n <Menu.Divider key=\"divider1\"/>,\n <Menu.Item key=\"clipboardCopy\" icon={<CopyOutlined/>} disabled={this.state.exporting}>{i18n(\"Copy to Clipboard\")}\n </Menu.Item>\n ];\n }\n}"]}
|