@pie-lib/graphing 2.4.3-next.414 → 2.4.3-next.462
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/CHANGELOG.md +42 -0
- package/lib/graph-with-controls.js +11 -1
- package/lib/graph-with-controls.js.map +1 -1
- package/lib/toggle-bar.js +156 -13
- package/lib/toggle-bar.js.map +1 -1
- package/lib/tool-menu.js +30 -2
- package/lib/tool-menu.js.map +1 -1
- package/package.json +4 -3
- package/src/graph-with-controls.jsx +10 -0
- package/src/toggle-bar.jsx +143 -13
- package/src/tool-menu.jsx +15 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,48 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.8.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing@2.8.0...@pie-lib/graphing@2.8.1) (2022-07-18)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @pie-lib/graphing
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [2.8.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing@2.7.0...@pie-lib/graphing@2.8.0) (2022-07-18)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* **graphing:** added drag and drop sorting for toolbar tools PD-1607 ([2463c86](https://github.com/pie-framework/pie-lib/commit/2463c86bf6ff42222e98e4344fc6c9fd040d9774))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# [2.7.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing@2.6.3...@pie-lib/graphing@2.7.0) (2022-06-27)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* **graphing:** added collapsible panel for graph toolbar PD-1693 ([4268bb0](https://github.com/pie-framework/pie-lib/commit/4268bb06093d1fabf82d9f5c2d8fd81f9788a4fe))
|
|
31
|
+
* **graphing:** Added default value for current drawing tool PD-1689 ([bc9b1b0](https://github.com/pie-framework/pie-lib/commit/bc9b1b00d64d50d138f3ab0991957d9fecaed17b))
|
|
32
|
+
* **graphing:** Added the ability to control the fields displayed into Grid Setup PD-1688 ([1f0f3eb](https://github.com/pie-framework/pie-lib/commit/1f0f3eb58c5dcd923e2452a0071bf1de40535bb2))
|
|
33
|
+
* added support for graph configuration constraints PD-1683 PD-1684 PD-1686 ([8da7426](https://github.com/pie-framework/pie-lib/commit/8da74260b28332b976fa1c50796e74679fd46a13))
|
|
34
|
+
* created setup panel and added basic functionalities PD-1679 ([183eda1](https://github.com/pie-framework/pie-lib/commit/183eda10b2f4128cd831c5b27f14ebccb6b3e7b2))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## [2.6.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing@2.6.2...@pie-lib/graphing@2.6.3) (2022-06-13)
|
|
41
|
+
|
|
42
|
+
**Note:** Version bump only for package @pie-lib/graphing
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
6
48
|
## [2.6.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing@2.6.1...@pie-lib/graphing@2.6.2) (2022-05-30)
|
|
7
49
|
|
|
8
50
|
|
|
@@ -137,6 +137,12 @@ var Collapsible = function Collapsible(_ref) {
|
|
|
137
137
|
}, children));
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
+
Collapsible.propTypes = {
|
|
141
|
+
classes: _propTypes["default"].object,
|
|
142
|
+
children: _propTypes["default"].array,
|
|
143
|
+
title: _propTypes["default"].string
|
|
144
|
+
};
|
|
145
|
+
|
|
140
146
|
var GraphWithControls = /*#__PURE__*/function (_React$Component) {
|
|
141
147
|
(0, _inherits2["default"])(GraphWithControls, _React$Component);
|
|
142
148
|
|
|
@@ -197,8 +203,10 @@ var GraphWithControls = /*#__PURE__*/function (_React$Component) {
|
|
|
197
203
|
collapsibleToolbarTitle = _this$props.collapsibleToolbarTitle,
|
|
198
204
|
disabled = _this$props.disabled,
|
|
199
205
|
domain = _this$props.domain,
|
|
206
|
+
draggableTools = _this$props.draggableTools,
|
|
200
207
|
labels = _this$props.labels,
|
|
201
208
|
onChangeMarks = _this$props.onChangeMarks,
|
|
209
|
+
onChangeTools = _this$props.onChangeTools,
|
|
202
210
|
onUndo = _this$props.onUndo,
|
|
203
211
|
onRedo = _this$props.onRedo,
|
|
204
212
|
onReset = _this$props.onReset,
|
|
@@ -226,12 +234,14 @@ var GraphWithControls = /*#__PURE__*/function (_React$Component) {
|
|
|
226
234
|
var graphActions = /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_toolMenu["default"], {
|
|
227
235
|
currentToolType: currentTool && currentTool.type,
|
|
228
236
|
disabled: !!disabled,
|
|
237
|
+
draggableTools: draggableTools,
|
|
229
238
|
labelModeEnabled: labelModeEnabled,
|
|
230
239
|
onChange: function onChange(tool) {
|
|
231
240
|
return _this2.changeCurrentTool(tool, tools);
|
|
232
241
|
},
|
|
233
242
|
onToggleLabelMode: this.toggleLabelMode,
|
|
234
|
-
toolbarTools: toolbarTools
|
|
243
|
+
toolbarTools: toolbarTools,
|
|
244
|
+
onChangeTools: onChangeTools
|
|
235
245
|
}), !disabled && /*#__PURE__*/_react["default"].createElement(_undoRedo["default"], {
|
|
236
246
|
onUndo: onUndo,
|
|
237
247
|
onRedo: onRedo,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-with-controls.js","names":["setToolbarAvailability","toolbarTools","toolsArr","map","tA","toolbar","find","t","type","toolIsAvailable","tools","currentTool","tool","getAvailableTool","filterByValidToolTypes","backgroundMarks","filter","bM","allTools","filterByVisibleToolTypes","marks","getDefaultCurrentTool","toolType","Collapsible","classes","children","title","expansionPanel","root","summaryRoot","content","summaryContent","details","GraphWithControls","props","setState","state","labelModeEnabled","defaultTool","prevProps","axesSettings","className","coordinatesOnHover","collapsibleToolbar","collapsibleToolbarTitle","disabled","domain","labels","onChangeMarks","onUndo","onRedo","onReset","range","size","uniq","tT","isString","graphActions","changeCurrentTool","toggleLabelMode","classNames","graphWithControls","controls","r","labelNode","undefined","React","Component","graphPropTypes","PropTypes","func","arrayOf","string","styles","theme","width","display","justifyContent","padding","spacing","unit","color","text","backgroundColor","primaryLight","borderTop","primaryDark","borderBottom","borderLeft","borderRight","fontSize","typography","minHeight","margin","marginTop","withStyles"],"sources":["../src/graph-with-controls.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport classNames from 'classnames';\nimport uniq from 'lodash/uniq';\nimport isString from 'lodash/isString';\nimport { color } from '@pie-lib/render-ui';\n\nimport ToolMenu from './tool-menu';\nimport Graph, { graphPropTypes } from './graph';\nimport UndoRedo from './undo-redo';\nimport { allTools, toolsArr } from './tools';\nimport {\n ExpansionPanel,\n ExpansionPanelDetails,\n ExpansionPanelSummary,\n Typography\n} from '@material-ui/core';\nimport ExpandMoreIcon from '@material-ui/icons/ExpandMore';\n\nexport const setToolbarAvailability = toolbarTools =>\n toolsArr.map(tA => ({ ...tA, toolbar: !!toolbarTools.find(t => t === tA.type) })) || [];\n\nexport const toolIsAvailable = (tools, currentTool) =>\n currentTool && tools && (tools.find(tool => tool.type === currentTool.type) || {}).toolbar;\n\nexport const getAvailableTool = tools => tools.find(tool => tool.toolbar);\n\nexport const filterByValidToolTypes = backgroundMarks =>\n backgroundMarks.filter(bM => !!allTools.find(tool => tool === bM.type));\n\nexport const filterByVisibleToolTypes = (toolbarTools, marks) =>\n marks.filter(bM => !!toolbarTools.find(tool => tool === bM.type));\n\nconst getDefaultCurrentTool = toolType => toolsArr.find(tool => tool.type === toolType) || null;\n\nconst Collapsible = ({ classes, children, title }) => (\n <ExpansionPanel\n elevation={0}\n className={classes.expansionPanel}\n disabledGutters={true}\n square={true}\n >\n <ExpansionPanelSummary\n classes={{\n root: classes.summaryRoot,\n content: classes.summaryContent\n }}\n expandIcon={<ExpandMoreIcon />}\n >\n <Typography variant=\"subheading\">{title}</Typography>\n </ExpansionPanelSummary>\n <ExpansionPanelDetails className={classes.details}>{children}</ExpansionPanelDetails>\n </ExpansionPanel>\n);\n\nexport class GraphWithControls extends React.Component {\n static propTypes = {\n ...graphPropTypes,\n onUndo: PropTypes.func,\n onRedo: PropTypes.func,\n onReset: PropTypes.func,\n toolbarTools: PropTypes.arrayOf(PropTypes.string) // array of tool types that have to be displayed in the toolbar, same shape as 'allTools'\n };\n\n static defaultProps = {\n collapsibleToolbar: false,\n collapsibleToolbarTitle: '',\n toolbarTools: []\n };\n\n constructor(props) {\n super(props);\n\n this.state = {\n currentTool: getDefaultCurrentTool(props.defaultTool),\n labelModeEnabled: false\n };\n }\n\n componentDidUpdate(prevProps) {\n const { defaultTool } = this.props;\n\n if (prevProps.defaultTool !== defaultTool) {\n const currentTool = getDefaultCurrentTool(defaultTool);\n\n this.setState({ currentTool });\n }\n }\n\n changeCurrentTool = (tool, tools) =>\n this.setState({ currentTool: tools.find(t => t.type === tool) });\n\n toggleLabelMode = () => this.setState(state => ({ labelModeEnabled: !state.labelModeEnabled }));\n\n render() {\n let { currentTool, labelModeEnabled } = this.state;\n const {\n axesSettings,\n classes,\n className,\n coordinatesOnHover,\n collapsibleToolbar,\n collapsibleToolbarTitle,\n disabled,\n domain,\n labels,\n onChangeMarks,\n onUndo,\n onRedo,\n onReset,\n range,\n size,\n title\n } = this.props;\n let { backgroundMarks, marks, toolbarTools } = this.props;\n\n // make sure only valid tool types are kept (string) and without duplicates\n toolbarTools = uniq(toolbarTools || []).filter(tT => !!isString(tT)) || [];\n\n // keep only the backgroundMarks that have valid types\n backgroundMarks = filterByValidToolTypes(backgroundMarks || []);\n\n // keep only the marks that have types which appear in toolbar\n marks = filterByVisibleToolTypes(toolbarTools, marks || []);\n\n const tools = setToolbarAvailability(toolbarTools);\n\n // set current tool if there's no current tool or if the existing one is no longer available\n if (!currentTool || !toolIsAvailable(tools, currentTool)) {\n currentTool = getAvailableTool(tools);\n }\n\n const graphActions = (\n <React.Fragment>\n <ToolMenu\n currentToolType={currentTool && currentTool.type}\n disabled={!!disabled}\n labelModeEnabled={labelModeEnabled}\n onChange={tool => this.changeCurrentTool(tool, tools)}\n onToggleLabelMode={this.toggleLabelMode}\n toolbarTools={toolbarTools}\n />\n\n {!disabled && <UndoRedo onUndo={onUndo} onRedo={onRedo} onReset={onReset} />}\n </React.Fragment>\n );\n\n return (\n <div className={classNames(classes.graphWithControls, className)}>\n <div className={classes.controls}>\n {collapsibleToolbar ? (\n <Collapsible classes={classes} title={collapsibleToolbarTitle}>\n {graphActions}\n </Collapsible>\n ) : (\n graphActions\n )}\n </div>\n\n <div ref={r => (this.labelNode = r)} />\n\n <Graph\n axesSettings={axesSettings}\n backgroundMarks={backgroundMarks}\n coordinatesOnHover={coordinatesOnHover}\n currentTool={currentTool}\n domain={domain}\n labels={labels}\n labelModeEnabled={labelModeEnabled}\n marks={marks}\n onChangeMarks={!disabled ? onChangeMarks : undefined}\n range={range}\n size={size}\n title={title}\n tools={tools}\n />\n </div>\n );\n }\n}\n\nconst styles = theme => ({\n graphWithControls: {},\n controls: {\n width: 'inherit',\n display: 'flex',\n justifyContent: 'space-between',\n padding: theme.spacing.unit,\n color: color.text(),\n backgroundColor: color.primaryLight(),\n borderTop: `solid 1px ${color.primaryDark()}`,\n borderBottom: `solid 0px ${color.primaryDark()}`,\n borderLeft: `solid 1px ${color.primaryDark()}`,\n borderRight: `solid 1px ${color.primaryDark()}`,\n '& button': {\n fontSize: theme.typography.fontSize\n }\n },\n expansionPanel: {\n backgroundColor: color.primaryLight()\n },\n summaryRoot: {\n padding: `0 ${theme.spacing.unit}px`,\n minHeight: '32px !important'\n },\n summaryContent: {\n margin: '4px 0 !important'\n },\n details: {\n padding: 0,\n marginTop: theme.spacing.unit\n }\n});\n\nexport default withStyles(styles)(GraphWithControls);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAMA;;;;;;;;;;;;;;AAEO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAyB,CAAAC,YAAY;EAAA,OAChDC,eAAA,CAASC,GAAT,CAAa,UAAAC,EAAE;IAAA,uCAAUA,EAAV;MAAcC,OAAO,EAAE,CAAC,CAACJ,YAAY,CAACK,IAAb,CAAkB,UAAAC,CAAC;QAAA,OAAIA,CAAC,KAAKH,EAAE,CAACI,IAAb;MAAA,CAAnB;IAAzB;EAAA,CAAf,KAAqF,EADrC;AAAA,CAA3C;;;;AAGA,IAAMC,eAAe,GAAG,SAAlBA,eAAkB,CAACC,KAAD,EAAQC,WAAR;EAAA,OAC7BA,WAAW,IAAID,KAAf,IAAwB,CAACA,KAAK,CAACJ,IAAN,CAAW,UAAAM,IAAI;IAAA,OAAIA,IAAI,CAACJ,IAAL,KAAcG,WAAW,CAACH,IAA9B;EAAA,CAAf,KAAsD,EAAvD,EAA2DH,OADtD;AAAA,CAAxB;;;;AAGA,IAAMQ,gBAAgB,GAAG,SAAnBA,gBAAmB,CAAAH,KAAK;EAAA,OAAIA,KAAK,CAACJ,IAAN,CAAW,UAAAM,IAAI;IAAA,OAAIA,IAAI,CAACP,OAAT;EAAA,CAAf,CAAJ;AAAA,CAA9B;;;;AAEA,IAAMS,sBAAsB,GAAG,SAAzBA,sBAAyB,CAAAC,eAAe;EAAA,OACnDA,eAAe,CAACC,MAAhB,CAAuB,UAAAC,EAAE;IAAA,OAAI,CAAC,CAACC,eAAA,CAASZ,IAAT,CAAc,UAAAM,IAAI;MAAA,OAAIA,IAAI,KAAKK,EAAE,CAACT,IAAhB;IAAA,C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barTools","toolsArr","map","tA","toolbar","find","t","type","toolIsAvailable","tools","currentTool","tool","getAvailableTool","filterByValidToolTypes","backgroundMarks","filter","bM","allTools","filterByVisibleToolTypes","marks","getDefaultCurrentTool","toolType","Collapsible","classes","children","title","expansionPanel","root","summaryRoot","content","summaryContent","details","propTypes","PropTypes","object","array","string","GraphWithControls","props","setState","state","labelModeEnabled","defaultTool","prevProps","axesSettings","className","coordinatesOnHover","collapsibleToolbar","collapsibleToolbarTitle","disabled","domain","draggableTools","labels","onChangeMarks","onChangeTools","onUndo","onRedo","onReset","range","size","uniq","tT","isString","graphActions","changeCurrentTool","toggleLabelMode","classNames","graphWithControls","controls","r","labelNode","undefined","React","Component","graphPropTypes","func","arrayOf","styles","theme","width","display","justifyContent","padding","spacing","unit","color","text","backgroundColor","primaryLight","borderTop","primaryDark","borderBottom","borderLeft","borderRight","fontSize","typography","minHeight","margin","marginTop","withStyles"],"sources":["../src/graph-with-controls.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport classNames from 'classnames';\nimport uniq from 'lodash/uniq';\nimport isString from 'lodash/isString';\nimport { color } from '@pie-lib/render-ui';\n\nimport ToolMenu from './tool-menu';\nimport Graph, { graphPropTypes } from './graph';\nimport UndoRedo from './undo-redo';\nimport { allTools, toolsArr } from './tools';\nimport {\n ExpansionPanel,\n ExpansionPanelDetails,\n ExpansionPanelSummary,\n Typography\n} from '@material-ui/core';\nimport ExpandMoreIcon from '@material-ui/icons/ExpandMore';\n\nexport const setToolbarAvailability = toolbarTools =>\n toolsArr.map(tA => ({ ...tA, toolbar: !!toolbarTools.find(t => t === tA.type) })) || [];\n\nexport const toolIsAvailable = (tools, currentTool) =>\n currentTool && tools && (tools.find(tool => tool.type === currentTool.type) || {}).toolbar;\n\nexport const getAvailableTool = tools => tools.find(tool => tool.toolbar);\n\nexport const filterByValidToolTypes = backgroundMarks =>\n backgroundMarks.filter(bM => !!allTools.find(tool => tool === bM.type));\n\nexport const filterByVisibleToolTypes = (toolbarTools, marks) =>\n marks.filter(bM => !!toolbarTools.find(tool => tool === bM.type));\n\nconst getDefaultCurrentTool = toolType => toolsArr.find(tool => tool.type === toolType) || null;\n\nconst Collapsible = ({ classes, children, title }) => (\n <ExpansionPanel\n elevation={0}\n className={classes.expansionPanel}\n disabledGutters={true}\n square={true}\n >\n <ExpansionPanelSummary\n classes={{\n root: classes.summaryRoot,\n content: classes.summaryContent\n }}\n expandIcon={<ExpandMoreIcon />}\n >\n <Typography variant=\"subheading\">{title}</Typography>\n </ExpansionPanelSummary>\n <ExpansionPanelDetails className={classes.details}>{children}</ExpansionPanelDetails>\n </ExpansionPanel>\n);\n\nCollapsible.propTypes = {\n classes: PropTypes.object,\n children: PropTypes.array,\n title: PropTypes.string\n};\n\nexport class GraphWithControls extends React.Component {\n static propTypes = {\n ...graphPropTypes,\n onUndo: PropTypes.func,\n onRedo: PropTypes.func,\n onReset: PropTypes.func,\n toolbarTools: PropTypes.arrayOf(PropTypes.string) // array of tool types that have to be displayed in the toolbar, same shape as 'allTools'\n };\n\n static defaultProps = {\n collapsibleToolbar: false,\n collapsibleToolbarTitle: '',\n toolbarTools: []\n };\n\n constructor(props) {\n super(props);\n\n this.state = {\n currentTool: getDefaultCurrentTool(props.defaultTool),\n labelModeEnabled: false\n };\n }\n\n componentDidUpdate(prevProps) {\n const { defaultTool } = this.props;\n\n if (prevProps.defaultTool !== defaultTool) {\n const currentTool = getDefaultCurrentTool(defaultTool);\n\n this.setState({ currentTool });\n }\n }\n\n changeCurrentTool = (tool, tools) =>\n this.setState({ currentTool: tools.find(t => t.type === tool) });\n\n toggleLabelMode = () => this.setState(state => ({ labelModeEnabled: !state.labelModeEnabled }));\n\n render() {\n let { currentTool, labelModeEnabled } = this.state;\n const {\n axesSettings,\n classes,\n className,\n coordinatesOnHover,\n collapsibleToolbar,\n collapsibleToolbarTitle,\n disabled,\n domain,\n draggableTools,\n labels,\n onChangeMarks,\n onChangeTools,\n onUndo,\n onRedo,\n onReset,\n range,\n size,\n title\n } = this.props;\n let { backgroundMarks, marks, toolbarTools } = this.props;\n\n // make sure only valid tool types are kept (string) and without duplicates\n toolbarTools = uniq(toolbarTools || []).filter(tT => !!isString(tT)) || [];\n\n // keep only the backgroundMarks that have valid types\n backgroundMarks = filterByValidToolTypes(backgroundMarks || []);\n\n // keep only the marks that have types which appear in toolbar\n marks = filterByVisibleToolTypes(toolbarTools, marks || []);\n\n const tools = setToolbarAvailability(toolbarTools);\n\n // set current tool if there's no current tool or if the existing one is no longer available\n if (!currentTool || !toolIsAvailable(tools, currentTool)) {\n currentTool = getAvailableTool(tools);\n }\n\n const graphActions = (\n <React.Fragment>\n <ToolMenu\n currentToolType={currentTool && currentTool.type}\n disabled={!!disabled}\n draggableTools={draggableTools}\n labelModeEnabled={labelModeEnabled}\n onChange={tool => this.changeCurrentTool(tool, tools)}\n onToggleLabelMode={this.toggleLabelMode}\n toolbarTools={toolbarTools}\n onChangeTools={onChangeTools}\n />\n\n {!disabled && <UndoRedo onUndo={onUndo} onRedo={onRedo} onReset={onReset} />}\n </React.Fragment>\n );\n\n return (\n <div className={classNames(classes.graphWithControls, className)}>\n <div className={classes.controls}>\n {collapsibleToolbar ? (\n <Collapsible classes={classes} title={collapsibleToolbarTitle}>\n {graphActions}\n </Collapsible>\n ) : (\n graphActions\n )}\n </div>\n\n <div ref={r => (this.labelNode = r)} />\n\n <Graph\n axesSettings={axesSettings}\n backgroundMarks={backgroundMarks}\n coordinatesOnHover={coordinatesOnHover}\n currentTool={currentTool}\n domain={domain}\n labels={labels}\n labelModeEnabled={labelModeEnabled}\n marks={marks}\n onChangeMarks={!disabled ? onChangeMarks : undefined}\n range={range}\n size={size}\n title={title}\n tools={tools}\n />\n </div>\n );\n }\n}\n\nconst styles = theme => ({\n graphWithControls: {},\n controls: {\n width: 'inherit',\n display: 'flex',\n justifyContent: 'space-between',\n padding: theme.spacing.unit,\n color: color.text(),\n backgroundColor: color.primaryLight(),\n borderTop: `solid 1px ${color.primaryDark()}`,\n borderBottom: `solid 0px ${color.primaryDark()}`,\n borderLeft: `solid 1px ${color.primaryDark()}`,\n borderRight: `solid 1px ${color.primaryDark()}`,\n '& button': {\n fontSize: theme.typography.fontSize\n }\n },\n expansionPanel: {\n backgroundColor: color.primaryLight()\n },\n summaryRoot: {\n padding: `0 ${theme.spacing.unit}px`,\n minHeight: '32px !important'\n },\n summaryContent: {\n margin: '4px 0 !important'\n },\n details: {\n padding: 0,\n marginTop: theme.spacing.unit\n }\n});\n\nexport default withStyles(styles)(GraphWithControls);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAMA;;;;;;;;;;;;;;AAEO,IAAMA,sBAAsB,GAAG,SAAzBA,sBAAyB,CAAAC,YAAY;EAAA,OAChDC,eAAA,CAASC,GAAT,CAAa,UAAAC,EAAE;IAAA,uCAAUA,EAAV;MAAcC,OAAO,EAAE,CAAC,CAACJ,YAAY,CAACK,IAAb,CAAkB,UAAAC,CAAC;QAAA,OAAIA,CAAC,KAAKH,EAAE,CAACI,IAAb;MAAA,CAAnB;IAAzB;EAAA,CAAf,KAAqF,EADrC;AAAA,CAA3C;;;;AAGA,IAAMC,eAAe,GAAG,SAAlBA,eAAkB,CAACC,KAAD,EAAQC,WAAR;EAAA,OAC7BA,WAAW,IAAID,KAAf,IAAwB,CAACA,KAAK,CAACJ,IAAN,CAAW,UAAAM,IAAI;IAAA,OAAIA,IAAI,CAACJ,IAAL,KAAcG,WAAW,CAACH,IAA9B;EAAA,CAAf,KAAsD,EAAvD,EAA2DH,OADtD;AAAA,CAAxB;;;;AAGA,IAAMQ,gBAAgB,GAAG,SAAnBA,gBAAmB,CAAAH,KAAK;EAAA,OAAIA,KAAK,CAACJ,IAAN,CAAW,UAAAM,IAAI;IAAA,OAAIA,IAAI,CAACP,OAAT;EAAA,CAAf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QACVI,QAAQ,EAAEhB,KAAK,CAACiB,UAAN,CAAiBD;MADjB;IAXJ,CAFa;IAiBvBpE,cAAc,EAAE;MACd6D,eAAe,EAAEF,eAAA,CAAMG,YAAN;IADH,CAjBO;IAoBvB5D,WAAW,EAAE;MACXsD,OAAO,cAAOJ,KAAK,CAACK,OAAN,CAAcC,IAArB,OADI;MAEXY,SAAS,EAAE;IAFA,CApBU;IAwBvBlE,cAAc,EAAE;MACdmE,MAAM,EAAE;IADM,CAxBO;IA2BvBlE,OAAO,EAAE;MACPmD,OAAO,EAAE,CADF;MAEPgB,SAAS,EAAEpB,KAAK,CAACK,OAAN,CAAcC;IAFlB;EA3Bc,CAAL;AAAA,CAApB;;eAiCe,IAAAe,kBAAA,EAAWtB,MAAX,EAAmBxC,iBAAnB,C"}
|
package/lib/toggle-bar.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports["default"] = exports.ToggleBar = exports.MiniButton = void 0;
|
|
8
|
+
exports["default"] = exports.ToggleBar = exports.MiniButton = exports.Item = void 0;
|
|
9
9
|
|
|
10
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
11
|
|
|
@@ -35,6 +35,8 @@ var _renderUi = require("@pie-lib/render-ui");
|
|
|
35
35
|
|
|
36
36
|
var _index = require("./tools/index");
|
|
37
37
|
|
|
38
|
+
var _drag = require("@pie-lib/drag");
|
|
39
|
+
|
|
38
40
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
39
41
|
|
|
40
42
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
@@ -89,6 +91,7 @@ var MiniButton = (0, _styles.withStyles)(buttonStyles)(function (props) {
|
|
|
89
91
|
exports.MiniButton = MiniButton;
|
|
90
92
|
MiniButton.propTypes = {
|
|
91
93
|
disabled: _propTypes["default"].bool,
|
|
94
|
+
classes: _propTypes["default"].object,
|
|
92
95
|
className: _propTypes["default"].string,
|
|
93
96
|
disabledClassName: _propTypes["default"].string,
|
|
94
97
|
selected: _propTypes["default"].bool,
|
|
@@ -114,6 +117,15 @@ var ToggleBar = /*#__PURE__*/function (_React$Component) {
|
|
|
114
117
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "select", function (e) {
|
|
115
118
|
return _this.props.onChange(e.target.textContent);
|
|
116
119
|
});
|
|
120
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "moveTool", function (dragIndex, hoverIndex) {
|
|
121
|
+
var _this$props = _this.props,
|
|
122
|
+
options = _this$props.options,
|
|
123
|
+
onChangeToolsOrder = _this$props.onChangeToolsOrder;
|
|
124
|
+
var dragged = options[dragIndex];
|
|
125
|
+
options.splice(dragIndex, 1);
|
|
126
|
+
options.splice(hoverIndex, 0, dragged);
|
|
127
|
+
onChangeToolsOrder(options);
|
|
128
|
+
});
|
|
117
129
|
return _this;
|
|
118
130
|
}
|
|
119
131
|
|
|
@@ -122,26 +134,36 @@ var ToggleBar = /*#__PURE__*/function (_React$Component) {
|
|
|
122
134
|
value: function render() {
|
|
123
135
|
var _this2 = this;
|
|
124
136
|
|
|
125
|
-
var _this$
|
|
126
|
-
classes = _this$
|
|
127
|
-
className = _this$
|
|
128
|
-
disabled = _this$
|
|
129
|
-
options = _this$
|
|
130
|
-
selectedToolType = _this$
|
|
137
|
+
var _this$props2 = this.props,
|
|
138
|
+
classes = _this$props2.classes,
|
|
139
|
+
className = _this$props2.className,
|
|
140
|
+
disabled = _this$props2.disabled,
|
|
141
|
+
options = _this$props2.options,
|
|
142
|
+
selectedToolType = _this$props2.selectedToolType,
|
|
143
|
+
draggableTools = _this$props2.draggableTools;
|
|
131
144
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
132
|
-
className: (0, _classnames["default"])(className)
|
|
133
|
-
}, (options || []).map(function (option) {
|
|
145
|
+
className: (0, _classnames["default"])(className, classes.toolsContainer)
|
|
146
|
+
}, (options || []).map(function (option, index) {
|
|
134
147
|
if ((_index.allTools || []).includes(option)) {
|
|
135
148
|
var isSelected = option === selectedToolType;
|
|
136
|
-
|
|
149
|
+
|
|
150
|
+
var toolRef = /*#__PURE__*/_react["default"].createRef();
|
|
151
|
+
|
|
152
|
+
return /*#__PURE__*/_react["default"].createElement(DragTool, {
|
|
137
153
|
key: option,
|
|
154
|
+
index: index,
|
|
155
|
+
draggable: draggableTools,
|
|
156
|
+
moveTool: _this2.moveTool,
|
|
157
|
+
classes: classes,
|
|
158
|
+
toolRef: toolRef
|
|
159
|
+
}, /*#__PURE__*/_react["default"].createElement(MiniButton, {
|
|
138
160
|
className: (0, _classnames["default"])(classes.button, isSelected && classes.selected),
|
|
139
161
|
disabled: disabled,
|
|
140
162
|
disableRipple: true,
|
|
141
163
|
onClick: _this2.select,
|
|
142
164
|
value: option,
|
|
143
165
|
selected: isSelected
|
|
144
|
-
});
|
|
166
|
+
}));
|
|
145
167
|
}
|
|
146
168
|
}));
|
|
147
169
|
}
|
|
@@ -156,22 +178,143 @@ exports.ToggleBar = ToggleBar;
|
|
|
156
178
|
options: _propTypes["default"].arrayOf(_propTypes["default"].string),
|
|
157
179
|
selectedToolType: _propTypes["default"].string,
|
|
158
180
|
disabled: _propTypes["default"].bool,
|
|
159
|
-
|
|
181
|
+
draggableTools: _propTypes["default"].bool,
|
|
182
|
+
onChange: _propTypes["default"].func,
|
|
183
|
+
onChangeToolsOrder: _propTypes["default"].func
|
|
160
184
|
});
|
|
161
185
|
(0, _defineProperty2["default"])(ToggleBar, "defaultProps", {});
|
|
162
186
|
|
|
163
187
|
var styles = function styles(theme) {
|
|
164
188
|
return {
|
|
189
|
+
toolsContainer: {
|
|
190
|
+
display: 'flex',
|
|
191
|
+
flexWrap: 'wrap'
|
|
192
|
+
},
|
|
165
193
|
button: {
|
|
166
194
|
marginRight: theme.spacing.unit / 2,
|
|
167
195
|
marginBottom: theme.spacing.unit / 2,
|
|
168
196
|
color: _renderUi.color.text(),
|
|
169
197
|
backgroundColor: _renderUi.color.background()
|
|
198
|
+
},
|
|
199
|
+
under: {
|
|
200
|
+
position: 'absolute',
|
|
201
|
+
top: 0,
|
|
202
|
+
left: 0,
|
|
203
|
+
zIndex: -1,
|
|
204
|
+
pointerEvents: 'none'
|
|
205
|
+
},
|
|
206
|
+
wrapper: {
|
|
207
|
+
position: 'relative'
|
|
208
|
+
},
|
|
209
|
+
hidden: {
|
|
210
|
+
opacity: 0
|
|
170
211
|
}
|
|
171
212
|
};
|
|
172
213
|
};
|
|
173
214
|
|
|
174
|
-
var _default = (0, _styles.withStyles)(styles)(ToggleBar);
|
|
215
|
+
var _default = (0, _drag.withDragContext)((0, _styles.withStyles)(styles)(ToggleBar));
|
|
175
216
|
|
|
176
217
|
exports["default"] = _default;
|
|
218
|
+
var DRAG_TYPE = 'tool';
|
|
219
|
+
|
|
220
|
+
var Item = /*#__PURE__*/function (_React$Component2) {
|
|
221
|
+
(0, _inherits2["default"])(Item, _React$Component2);
|
|
222
|
+
|
|
223
|
+
var _super2 = _createSuper(Item);
|
|
224
|
+
|
|
225
|
+
function Item() {
|
|
226
|
+
(0, _classCallCheck2["default"])(this, Item);
|
|
227
|
+
return _super2.apply(this, arguments);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
(0, _createClass2["default"])(Item, [{
|
|
231
|
+
key: "render",
|
|
232
|
+
value: function render() {
|
|
233
|
+
var _this$props3 = this.props,
|
|
234
|
+
classes = _this$props3.classes,
|
|
235
|
+
children = _this$props3.children,
|
|
236
|
+
connectDragSource = _this$props3.connectDragSource,
|
|
237
|
+
connectDropTarget = _this$props3.connectDropTarget,
|
|
238
|
+
connectDragPreview = _this$props3.connectDragPreview,
|
|
239
|
+
isDragging = _this$props3.isDragging,
|
|
240
|
+
toolRef = _this$props3.toolRef;
|
|
241
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
242
|
+
className: classes.wrapper,
|
|
243
|
+
ref: toolRef
|
|
244
|
+
}, connectDragSource(connectDropTarget( /*#__PURE__*/_react["default"].createElement("div", {
|
|
245
|
+
className: isDragging && classes.hidden
|
|
246
|
+
}, children))), connectDragPreview( /*#__PURE__*/_react["default"].createElement("div", {
|
|
247
|
+
className: classes.under
|
|
248
|
+
}, children)));
|
|
249
|
+
}
|
|
250
|
+
}]);
|
|
251
|
+
return Item;
|
|
252
|
+
}(_react["default"].Component);
|
|
253
|
+
|
|
254
|
+
exports.Item = Item;
|
|
255
|
+
(0, _defineProperty2["default"])(Item, "propTypes", {
|
|
256
|
+
classes: _propTypes["default"].object.isRequired,
|
|
257
|
+
className: _propTypes["default"].string,
|
|
258
|
+
children: _propTypes["default"].oneOfType([_propTypes["default"].arrayOf(_propTypes["default"].node), _propTypes["default"].node]),
|
|
259
|
+
connectDragSource: _propTypes["default"].func.isRequired,
|
|
260
|
+
connectDragPreview: _propTypes["default"].func.isRequired,
|
|
261
|
+
connectDropTarget: _propTypes["default"].func.isRequired,
|
|
262
|
+
isDragging: _propTypes["default"].bool
|
|
263
|
+
});
|
|
264
|
+
(0, _defineProperty2["default"])(Item, "defaultProps", {});
|
|
265
|
+
var itemSource = {
|
|
266
|
+
canDrag: function canDrag(props) {
|
|
267
|
+
return props.draggable;
|
|
268
|
+
},
|
|
269
|
+
beginDrag: function beginDrag(props) {
|
|
270
|
+
return {
|
|
271
|
+
index: props.index
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
var itemTarget = {
|
|
276
|
+
hover: function hover(props, monitor) {
|
|
277
|
+
var _toolRef$current;
|
|
278
|
+
|
|
279
|
+
var dragIndex = monitor.getItem().index;
|
|
280
|
+
var toolRef = props.toolRef,
|
|
281
|
+
hoverIndex = props.index;
|
|
282
|
+
|
|
283
|
+
if (dragIndex === hoverIndex || !toolRef.current) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
var hoverBoundingRect = (_toolRef$current = toolRef.current) === null || _toolRef$current === void 0 ? void 0 : _toolRef$current.getBoundingClientRect();
|
|
288
|
+
var hoverMiddleX = (hoverBoundingRect.right - hoverBoundingRect.left) / 2;
|
|
289
|
+
var clientOffset = monitor.getClientOffset();
|
|
290
|
+
var hoverClientX = clientOffset.x - hoverBoundingRect.left;
|
|
291
|
+
|
|
292
|
+
if (dragIndex < hoverIndex && hoverClientX < hoverMiddleX) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (dragIndex > hoverIndex && hoverClientX > hoverMiddleX) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
props.moveTool(dragIndex, hoverIndex);
|
|
301
|
+
monitor.getItem().index = hoverIndex;
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
var collectTarget = function collectTarget(connect) {
|
|
306
|
+
return {
|
|
307
|
+
connectDropTarget: connect.dropTarget()
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
var collectSource = function collectSource(connect, monitor) {
|
|
312
|
+
return {
|
|
313
|
+
connectDragSource: connect.dragSource(),
|
|
314
|
+
connectDragPreview: connect.dragPreview(),
|
|
315
|
+
isDragging: monitor.isDragging()
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
var DragTool = (0, _drag.DropTarget)(DRAG_TYPE, itemTarget, collectTarget)((0, _drag.DragSource)(DRAG_TYPE, itemSource, collectSource)(Item));
|
|
177
320
|
//# sourceMappingURL=toggle-bar.js.map
|
package/lib/toggle-bar.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-bar.js","names":["buttonStyles","root","color","text","backgroundColor","primary","selected","background","border","secondary","notSelected","disabled","MiniButton","withStyles","props","classes","className","value","onClick","cn","propTypes","PropTypes","bool","string","disabledClassName","func","ToggleBar","e","onChange","target","textContent","options","selectedToolType","map","option","allTools","includes","isSelected","button","select","React","Component","object","isRequired","arrayOf","styles","theme","marginRight","spacing","unit","marginBottom"],"sources":["../src/toggle-bar.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport cn from 'classnames';\nimport Button from '@material-ui/core/Button';\nimport { color } from '@pie-lib/render-ui';\nimport { allTools } from './tools/index';\n\nconst buttonStyles = () => ({\n root: {\n color: color.text(),\n '&:hover': {\n backgroundColor: color.primary()\n }\n },\n selected: {\n backgroundColor: color.background(),\n border: `1px solid ${color.secondary()}`\n },\n notSelected: {\n '& span': {\n color: color.primary()\n },\n backgroundColor: color.background()\n },\n disabled: {\n '& span': {\n color: color.primary()\n },\n backgroundColor: color.disabled()\n }\n});\n\nexport const MiniButton = withStyles(buttonStyles)(props => {\n const { disabled, classes, className, selected, value, onClick } = props;\n\n return (\n <Button\n size=\"small\"\n disabled={disabled}\n className={cn(classes.root, selected && classes.selected, className)}\n classes={{ disabled: cn(disabled && classes.disabled) }}\n value={value}\n key={value}\n variant=\"outlined\"\n onClick={onClick}\n >\n {value}\n </Button>\n );\n});\n\nMiniButton.propTypes = {\n disabled: PropTypes.bool,\n className: PropTypes.string,\n disabledClassName: PropTypes.string,\n selected: PropTypes.bool,\n value: PropTypes.string,\n onClick: PropTypes.func\n};\n\nexport class ToggleBar extends React.Component {\n static propTypes = {\n classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n options: PropTypes.arrayOf(PropTypes.string),\n selectedToolType: PropTypes.string,\n disabled: PropTypes.bool,\n onChange: PropTypes.func\n };\n\n static defaultProps = {};\n\n select = e => this.props.onChange(e.target.textContent);\n\n render() {\n const { classes, className, disabled, options, selectedToolType } = this.props;\n return (\n <div className={cn(className)}>\n {(options || []).map(option => {\n if ((allTools || []).includes(option)) {\n const isSelected = option === selectedToolType;\n\n return (\n <MiniButton\n key={option}\n className={cn(classes.button, isSelected && classes.selected)}\n disabled={disabled}\n disableRipple={true}\n onClick={this.select}\n value={option}\n selected={isSelected}\n />\n );\n }\n })}\n </div>\n );\n }\n}\n\nconst styles = theme => ({\n button: {\n marginRight: theme.spacing.unit / 2,\n marginBottom: theme.spacing.unit / 2,\n color: color.text(),\n backgroundColor: color.background()\n }\n});\n\nexport default withStyles(styles)(ToggleBar);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,YAAY,GAAG,SAAfA,YAAe;EAAA,OAAO;IAC1BC,IAAI,EAAE;MACJC,KAAK,EAAEA,eAAA,CAAMC,IAAN,EADH;MAEJ,WAAW;QACTC,eAAe,EAAEF,eAAA,CAAMG,OAAN;MADR;IAFP,CADoB;IAO1BC,QAAQ,EAAE;MACRF,eAAe,EAAEF,eAAA,CAAMK,UAAN,EADT;MAERC,MAAM,sBAAeN,eAAA,CAAMO,SAAN,EAAf;IAFE,CAPgB;IAW1BC,WAAW,EAAE;MACX,UAAU;QACRR,KAAK,EAAEA,eAAA,CAAMG,OAAN;MADC,CADC;MAIXD,eAAe,EAAEF,eAAA,CAAMK,UAAN;IAJN,CAXa;IAiB1BI,QAAQ,EAAE;MACR,UAAU;QACRT,KAAK,EAAEA,eAAA,CAAMG,OAAN;MADC,CADF;MAIRD,eAAe,EAAEF,eAAA,CAAMS,QAAN;IAJT;EAjBgB,CAAP;AAAA,CAArB;;AAyBO,IAAMC,UAAU,G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C,S,kBAUW,E;;AA8BxB,IAAMmB,MAAM,GAAG,SAATA,MAAS,CAAAC,KAAK;EAAA,OAAK;IACvBR,MAAM,EAAE;MACNS,WAAW,EAAED,KAAK,CAACE,OAAN,CAAcC,IAAd,GAAqB,CAD5B;MAENC,YAAY,EAAEJ,KAAK,CAACE,OAAN,CAAcC,IAAd,GAAqB,CAF7B;MAGN/C,KAAK,EAAEA,eAAA,CAAMC,IAAN,EAHD;MAINC,eAAe,EAAEF,eAAA,CAAMK,UAAN;IAJX;EADe,CAAL;AAAA,CAApB;;eASe,IAAAM,kBAAA,EAAWgC,MAAX,EAAmBnB,SAAnB,C"}
|
|
1
|
+
{"version":3,"file":"toggle-bar.js","names":["buttonStyles","root","color","text","backgroundColor","primary","selected","background","border","secondary","notSelected","disabled","MiniButton","withStyles","props","classes","className","value","onClick","cn","propTypes","PropTypes","bool","object","string","disabledClassName","func","ToggleBar","e","onChange","target","textContent","dragIndex","hoverIndex","options","onChangeToolsOrder","dragged","splice","selectedToolType","draggableTools","toolsContainer","map","option","index","allTools","includes","isSelected","toolRef","React","createRef","moveTool","button","select","Component","isRequired","arrayOf","styles","theme","display","flexWrap","marginRight","spacing","unit","marginBottom","under","position","top","left","zIndex","pointerEvents","wrapper","hidden","opacity","withDragContext","DRAG_TYPE","Item","children","connectDragSource","connectDropTarget","connectDragPreview","isDragging","oneOfType","node","itemSource","canDrag","draggable","beginDrag","itemTarget","hover","monitor","getItem","current","hoverBoundingRect","getBoundingClientRect","hoverMiddleX","right","clientOffset","getClientOffset","hoverClientX","x","collectTarget","connect","dropTarget","collectSource","dragSource","dragPreview","DragTool","DropTarget","DragSource"],"sources":["../src/toggle-bar.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport cn from 'classnames';\nimport Button from '@material-ui/core/Button';\nimport { color } from '@pie-lib/render-ui';\nimport { allTools } from './tools/index';\nimport { withDragContext, DragSource, DropTarget } from '@pie-lib/drag';\n\nconst buttonStyles = () => ({\n root: {\n color: color.text(),\n '&:hover': {\n backgroundColor: color.primary()\n }\n },\n selected: {\n backgroundColor: color.background(),\n border: `1px solid ${color.secondary()}`\n },\n notSelected: {\n '& span': {\n color: color.primary()\n },\n backgroundColor: color.background()\n },\n disabled: {\n '& span': {\n color: color.primary()\n },\n backgroundColor: color.disabled()\n }\n});\n\nexport const MiniButton = withStyles(buttonStyles)(props => {\n const { disabled, classes, className, selected, value, onClick } = props;\n\n return (\n <Button\n size=\"small\"\n disabled={disabled}\n className={cn(classes.root, selected && classes.selected, className)}\n classes={{ disabled: cn(disabled && classes.disabled) }}\n value={value}\n key={value}\n variant=\"outlined\"\n onClick={onClick}\n >\n {value}\n </Button>\n );\n});\n\nMiniButton.propTypes = {\n disabled: PropTypes.bool,\n classes: PropTypes.object,\n className: PropTypes.string,\n disabledClassName: PropTypes.string,\n selected: PropTypes.bool,\n value: PropTypes.string,\n onClick: PropTypes.func\n};\n\nexport class ToggleBar extends React.Component {\n static propTypes = {\n classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n options: PropTypes.arrayOf(PropTypes.string),\n selectedToolType: PropTypes.string,\n disabled: PropTypes.bool,\n draggableTools: PropTypes.bool,\n onChange: PropTypes.func,\n onChangeToolsOrder: PropTypes.func\n };\n\n static defaultProps = {};\n\n select = e => this.props.onChange(e.target.textContent);\n\n moveTool = (dragIndex, hoverIndex) => {\n const { options, onChangeToolsOrder } = this.props;\n const dragged = options[dragIndex];\n\n options.splice(dragIndex, 1);\n options.splice(hoverIndex, 0, dragged);\n\n onChangeToolsOrder(options);\n };\n\n render() {\n const { classes, className, disabled, options, selectedToolType, draggableTools } = this.props;\n\n return (\n <div className={cn(className, classes.toolsContainer)}>\n {(options || []).map((option, index) => {\n if ((allTools || []).includes(option)) {\n const isSelected = option === selectedToolType;\n const toolRef = React.createRef();\n\n return (\n <DragTool\n key={option}\n index={index}\n draggable={draggableTools}\n moveTool={this.moveTool}\n classes={classes}\n toolRef={toolRef}\n >\n <MiniButton\n className={cn(classes.button, isSelected && classes.selected)}\n disabled={disabled}\n disableRipple={true}\n onClick={this.select}\n value={option}\n selected={isSelected}\n />\n </DragTool>\n );\n }\n })}\n </div>\n );\n }\n}\n\nconst styles = theme => ({\n toolsContainer: {\n display: 'flex',\n flexWrap: 'wrap'\n },\n button: {\n marginRight: theme.spacing.unit / 2,\n marginBottom: theme.spacing.unit / 2,\n color: color.text(),\n backgroundColor: color.background()\n },\n under: {\n position: 'absolute',\n top: 0,\n left: 0,\n zIndex: -1,\n pointerEvents: 'none'\n },\n wrapper: {\n position: 'relative'\n },\n hidden: {\n opacity: 0\n }\n});\n\nexport default withDragContext(withStyles(styles)(ToggleBar));\n\nconst DRAG_TYPE = 'tool';\n\nexport class Item extends React.Component {\n static propTypes = {\n classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),\n connectDragSource: PropTypes.func.isRequired,\n connectDragPreview: PropTypes.func.isRequired,\n connectDropTarget: PropTypes.func.isRequired,\n isDragging: PropTypes.bool\n };\n\n static defaultProps = {};\n\n render() {\n const {\n classes,\n children,\n connectDragSource,\n connectDropTarget,\n connectDragPreview,\n isDragging,\n toolRef\n } = this.props;\n\n return (\n <div className={classes.wrapper} ref={toolRef}>\n {connectDragSource(\n connectDropTarget(<div className={isDragging && classes.hidden}>{children}</div>)\n )}\n {connectDragPreview(<div className={classes.under}>{children}</div>)}\n </div>\n );\n }\n}\n\nconst itemSource = {\n canDrag(props) {\n return props.draggable;\n },\n beginDrag(props) {\n return {\n index: props.index\n };\n }\n};\n\nconst itemTarget = {\n hover(props, monitor) {\n const dragIndex = monitor.getItem().index;\n const { toolRef, index: hoverIndex } = props;\n\n if (dragIndex === hoverIndex || !toolRef.current) {\n return;\n }\n\n const hoverBoundingRect = toolRef.current?.getBoundingClientRect();\n const hoverMiddleX = (hoverBoundingRect.right - hoverBoundingRect.left) / 2;\n const clientOffset = monitor.getClientOffset();\n const hoverClientX = clientOffset.x - hoverBoundingRect.left;\n\n if (dragIndex < hoverIndex && hoverClientX < hoverMiddleX) {\n return;\n }\n\n if (dragIndex > hoverIndex && hoverClientX > hoverMiddleX) {\n return;\n }\n\n props.moveTool(dragIndex, hoverIndex);\n monitor.getItem().index = hoverIndex;\n }\n};\n\nconst collectTarget = connect => ({ connectDropTarget: connect.dropTarget() });\n\nconst collectSource = (connect, monitor) => ({\n connectDragSource: connect.dragSource(),\n connectDragPreview: connect.dragPreview(),\n isDragging: monitor.isDragging()\n});\n\nconst DragTool = DropTarget(\n DRAG_TYPE,\n itemTarget,\n collectTarget\n)(DragSource(DRAG_TYPE, itemSource, collectSource)(Item));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,YAAY,GAAG,SAAfA,YAAe;EAAA,OAAO;IAC1BC,IAAI,EAAE;MACJC,KAAK,EAAEA,eAAA,CAAMC,IAAN,EADH;MAEJ,WAAW;QACTC,eAAe,EAAEF,eAAA,CAAMG,OAAN;MADR;IAFP,CADoB;IAO1BC,QAAQ,EAAE;MACRF,eAAe,EAAEF,eAAA,CAAMK,UAAN,EADT;MAERC,MAAM,sBAAeN,eAAA,CAAMO,SAAN,EAAf;IAFE,CAPgB;IAW1BC,WAAW,EAAE;MACX,UAAU;QACRR,KAAK,EAAEA,eAAA,CAAMG,OAAN;MADC,CADC;MAIXD,eAAe,EAAEF,eAAA,CAAMK,UAAN;IAJN,CAXa;IAiB1BI,QAAQ,EAAE;MACR,UAAU;QACRT,KAAK,EAAEA,eAAA,CAAMG,OAAN;MADC,CADF;MAIRD,eAAe,EAAEF,eAAA,CAAMS,QAAN;IAJT;EAjBgB,CAAP;AAAA,CAArB;;AAyBO,IAAMC,UAAU,GAAG,IAAAC,kBAAA,EAAWb,YAAX,EAAyB,UAAAc,KAAK,EAAI;EAC1D,IAAQH,QAA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GJ,YAA7C,EAA2D;MACzD;IACD;;IAEDhF,KAAK,CAACoC,QAAN,CAAelB,SAAf,EAA0BC,UAA1B;IACAwD,OAAO,CAACC,OAAR,GAAkB/C,KAAlB,GAA0BV,UAA1B;EACD;AAxBgB,CAAnB;;AA2BA,IAAMmE,aAAa,GAAG,SAAhBA,aAAgB,CAAAC,OAAO;EAAA,OAAK;IAAEvB,iBAAiB,EAAEuB,OAAO,CAACC,UAAR;EAArB,CAAL;AAAA,CAA7B;;AAEA,IAAMC,aAAa,GAAG,SAAhBA,aAAgB,CAACF,OAAD,EAAUZ,OAAV;EAAA,OAAuB;IAC3CZ,iBAAiB,EAAEwB,OAAO,CAACG,UAAR,EADwB;IAE3CzB,kBAAkB,EAAEsB,OAAO,CAACI,WAAR,EAFuB;IAG3CzB,UAAU,EAAES,OAAO,CAACT,UAAR;EAH+B,CAAvB;AAAA,CAAtB;;AAMA,IAAM0B,QAAQ,GAAG,IAAAC,gBAAA,EACfjC,SADe,EAEfa,UAFe,EAGfa,aAHe,EAIf,IAAAQ,gBAAA,EAAWlC,SAAX,EAAsBS,UAAtB,EAAkCoB,aAAlC,EAAiD5B,IAAjD,CAJe,CAAjB"}
|
package/lib/tool-menu.js
CHANGED
|
@@ -13,6 +13,8 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
|
|
|
13
13
|
|
|
14
14
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
15
|
|
|
16
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
17
|
+
|
|
16
18
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
19
|
|
|
18
20
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
@@ -43,17 +45,37 @@ var ToolMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
43
45
|
var _super = _createSuper(ToolMenu);
|
|
44
46
|
|
|
45
47
|
function ToolMenu() {
|
|
48
|
+
var _this;
|
|
49
|
+
|
|
46
50
|
(0, _classCallCheck2["default"])(this, ToolMenu);
|
|
47
|
-
|
|
51
|
+
|
|
52
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
53
|
+
args[_key] = arguments[_key];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
57
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "updateToolsOrder", function (tools, showLabel) {
|
|
58
|
+
var onChangeTools = _this.props.onChangeTools;
|
|
59
|
+
|
|
60
|
+
if (showLabel) {
|
|
61
|
+
tools.push('label');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
onChangeTools(tools);
|
|
65
|
+
});
|
|
66
|
+
return _this;
|
|
48
67
|
}
|
|
49
68
|
|
|
50
69
|
(0, _createClass2["default"])(ToolMenu, [{
|
|
51
70
|
key: "render",
|
|
52
71
|
value: function render() {
|
|
72
|
+
var _this2 = this;
|
|
73
|
+
|
|
53
74
|
var _this$props = this.props,
|
|
54
75
|
className = _this$props.className,
|
|
55
76
|
currentToolType = _this$props.currentToolType,
|
|
56
77
|
disabled = _this$props.disabled,
|
|
78
|
+
draggableTools = _this$props.draggableTools,
|
|
57
79
|
labelModeEnabled = _this$props.labelModeEnabled,
|
|
58
80
|
onToggleLabelMode = _this$props.onToggleLabelMode,
|
|
59
81
|
onChange = _this$props.onChange;
|
|
@@ -68,9 +90,13 @@ var ToolMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
68
90
|
className: (0, _classnames["default"])(className)
|
|
69
91
|
}, /*#__PURE__*/_react["default"].createElement(_toggleBar["default"], {
|
|
70
92
|
disabled: disabled,
|
|
93
|
+
draggableTools: draggableTools,
|
|
71
94
|
options: toolbarTools,
|
|
72
95
|
selectedToolType: currentToolType,
|
|
73
|
-
onChange: onChange
|
|
96
|
+
onChange: onChange,
|
|
97
|
+
onChangeToolsOrder: function onChangeToolsOrder(tools) {
|
|
98
|
+
return _this2.updateToolsOrder(tools, showLabel);
|
|
99
|
+
}
|
|
74
100
|
}), showLabel && /*#__PURE__*/_react["default"].createElement(_toggleBar.MiniButton, {
|
|
75
101
|
disabled: disabled,
|
|
76
102
|
value: 'Label',
|
|
@@ -87,9 +113,11 @@ exports.ToolMenu = ToolMenu;
|
|
|
87
113
|
className: _propTypes["default"].string,
|
|
88
114
|
currentToolType: _propTypes["default"].string,
|
|
89
115
|
disabled: _propTypes["default"].bool,
|
|
116
|
+
draggableTools: _propTypes["default"].bool,
|
|
90
117
|
labelModeEnabled: _propTypes["default"].bool,
|
|
91
118
|
onChange: _propTypes["default"].func,
|
|
92
119
|
onToggleLabelMode: _propTypes["default"].func,
|
|
120
|
+
onChangeTools: _propTypes["default"].func,
|
|
93
121
|
toolbarTools: _propTypes["default"].arrayOf(_propTypes["default"].string)
|
|
94
122
|
});
|
|
95
123
|
(0, _defineProperty2["default"])(ToolMenu, "defaultProps", {
|
package/lib/tool-menu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-menu.js","names":["ToolMenu","props","className","currentToolType","disabled","labelModeEnabled","onToggleLabelMode","onChange","toolbarTools","
|
|
1
|
+
{"version":3,"file":"tool-menu.js","names":["ToolMenu","tools","showLabel","onChangeTools","props","push","className","currentToolType","disabled","draggableTools","labelModeEnabled","onToggleLabelMode","onChange","toolbarTools","some","t","filter","tT","classNames","updateToolsOrder","React","Component","PropTypes","string","bool","func","arrayOf"],"sources":["../src/tool-menu.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport classNames from 'classnames';\n\nimport ToggleBar, { MiniButton } from './toggle-bar';\n\nexport class ToolMenu extends React.Component {\n static propTypes = {\n className: PropTypes.string,\n currentToolType: PropTypes.string,\n disabled: PropTypes.bool,\n draggableTools: PropTypes.bool,\n labelModeEnabled: PropTypes.bool,\n onChange: PropTypes.func,\n onToggleLabelMode: PropTypes.func,\n onChangeTools: PropTypes.func,\n toolbarTools: PropTypes.arrayOf(PropTypes.string)\n };\n\n static defaultProps = {\n toolbarTools: []\n };\n\n updateToolsOrder = (tools, showLabel) => {\n const { onChangeTools } = this.props;\n\n if (showLabel) {\n tools.push('label');\n }\n\n onChangeTools(tools);\n };\n\n render() {\n const {\n className,\n currentToolType,\n disabled,\n draggableTools,\n labelModeEnabled,\n onToggleLabelMode,\n onChange\n } = this.props;\n let { toolbarTools } = this.props;\n\n const showLabel = toolbarTools && toolbarTools.some(t => t === 'label');\n\n toolbarTools = (toolbarTools || []).filter(tT => tT !== 'label');\n\n return (\n <div className={classNames(className)}>\n <ToggleBar\n disabled={disabled}\n draggableTools={draggableTools}\n options={toolbarTools}\n selectedToolType={currentToolType}\n onChange={onChange}\n onChangeToolsOrder={tools => this.updateToolsOrder(tools, showLabel)}\n />\n\n {showLabel && (\n <MiniButton\n disabled={disabled}\n value={'Label'}\n onClick={onToggleLabelMode}\n selected={labelModeEnabled}\n />\n )}\n </div>\n );\n }\n}\n\nexport default ToolMenu;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;;;;;;;IAEaA,Q;;;;;;;;;;;;;;;yGAiBQ,UAACC,KAAD,EAAQC,SAAR,EAAsB;MACvC,IAAQC,aAAR,GAA0B,MAAKC,KAA/B,CAAQD,aAAR;;MAEA,IAAID,SAAJ,EAAe;QACbD,KAAK,CAACI,IAAN,CAAW,OAAX;MACD;;MAEDF,aAAa,CAACF,KAAD,CAAb;IACD,C;;;;;;WAED,kBAAS;MAAA;;MACP,kBAQI,KAAKG,KART;MAAA,IACEE,SADF,eACEA,SADF;MAAA,IAEEC,eAFF,eAEEA,eAFF;MAAA,IAGEC,QAHF,eAGEA,QAHF;MAAA,IAIEC,cAJF,eAIEA,cAJF;MAAA,IAKEC,gBALF,eAKEA,gBALF;MAAA,IAMEC,iBANF,eAM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qBAAA,CAAUG,IARR;EASjBZ,YAAY,EAAES,qBAAA,CAAUI,OAAV,CAAkBJ,qBAAA,CAAUC,MAA5B;AATG,C;iCADRvB,Q,kBAaW;EACpBa,YAAY,EAAE;AADM,C;eAsDTb,Q"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "2.4.3-next.
|
|
6
|
+
"version": "2.4.3-next.462+88f0fb88",
|
|
7
7
|
"description": "Graphing components",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"react",
|
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@mapbox/point-geometry": "^0.1.0",
|
|
20
20
|
"@material-ui/core": "^3.8.3",
|
|
21
|
+
"@pie-lib/drag": "^1.1.52",
|
|
21
22
|
"@pie-lib/graphing-utils": "^1.1.20",
|
|
22
23
|
"@pie-lib/plot": "^2.2.0",
|
|
23
|
-
"@pie-lib/render-ui": "^4.12.1-next.
|
|
24
|
+
"@pie-lib/render-ui": "^4.12.1-next.462+88f0fb88",
|
|
24
25
|
"@vx/axis": "^0.0.189",
|
|
25
26
|
"@vx/clip-path": "^0.0.189",
|
|
26
27
|
"@vx/event": "^0.0.189",
|
|
@@ -43,6 +44,6 @@
|
|
|
43
44
|
"peerDependencies": {
|
|
44
45
|
"react": "^16.8.1"
|
|
45
46
|
},
|
|
46
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "88f0fb88c7a98ceaa2336add0301b176c59355b7",
|
|
47
48
|
"scripts": {}
|
|
48
49
|
}
|
|
@@ -54,6 +54,12 @@ const Collapsible = ({ classes, children, title }) => (
|
|
|
54
54
|
</ExpansionPanel>
|
|
55
55
|
);
|
|
56
56
|
|
|
57
|
+
Collapsible.propTypes = {
|
|
58
|
+
classes: PropTypes.object,
|
|
59
|
+
children: PropTypes.array,
|
|
60
|
+
title: PropTypes.string
|
|
61
|
+
};
|
|
62
|
+
|
|
57
63
|
export class GraphWithControls extends React.Component {
|
|
58
64
|
static propTypes = {
|
|
59
65
|
...graphPropTypes,
|
|
@@ -104,8 +110,10 @@ export class GraphWithControls extends React.Component {
|
|
|
104
110
|
collapsibleToolbarTitle,
|
|
105
111
|
disabled,
|
|
106
112
|
domain,
|
|
113
|
+
draggableTools,
|
|
107
114
|
labels,
|
|
108
115
|
onChangeMarks,
|
|
116
|
+
onChangeTools,
|
|
109
117
|
onUndo,
|
|
110
118
|
onRedo,
|
|
111
119
|
onReset,
|
|
@@ -136,10 +144,12 @@ export class GraphWithControls extends React.Component {
|
|
|
136
144
|
<ToolMenu
|
|
137
145
|
currentToolType={currentTool && currentTool.type}
|
|
138
146
|
disabled={!!disabled}
|
|
147
|
+
draggableTools={draggableTools}
|
|
139
148
|
labelModeEnabled={labelModeEnabled}
|
|
140
149
|
onChange={tool => this.changeCurrentTool(tool, tools)}
|
|
141
150
|
onToggleLabelMode={this.toggleLabelMode}
|
|
142
151
|
toolbarTools={toolbarTools}
|
|
152
|
+
onChangeTools={onChangeTools}
|
|
143
153
|
/>
|
|
144
154
|
|
|
145
155
|
{!disabled && <UndoRedo onUndo={onUndo} onRedo={onRedo} onReset={onReset} />}
|
package/src/toggle-bar.jsx
CHANGED
|
@@ -5,6 +5,7 @@ import cn from 'classnames';
|
|
|
5
5
|
import Button from '@material-ui/core/Button';
|
|
6
6
|
import { color } from '@pie-lib/render-ui';
|
|
7
7
|
import { allTools } from './tools/index';
|
|
8
|
+
import { withDragContext, DragSource, DropTarget } from '@pie-lib/drag';
|
|
8
9
|
|
|
9
10
|
const buttonStyles = () => ({
|
|
10
11
|
root: {
|
|
@@ -52,6 +53,7 @@ export const MiniButton = withStyles(buttonStyles)(props => {
|
|
|
52
53
|
|
|
53
54
|
MiniButton.propTypes = {
|
|
54
55
|
disabled: PropTypes.bool,
|
|
56
|
+
classes: PropTypes.object,
|
|
55
57
|
className: PropTypes.string,
|
|
56
58
|
disabledClassName: PropTypes.string,
|
|
57
59
|
selected: PropTypes.bool,
|
|
@@ -66,31 +68,53 @@ export class ToggleBar extends React.Component {
|
|
|
66
68
|
options: PropTypes.arrayOf(PropTypes.string),
|
|
67
69
|
selectedToolType: PropTypes.string,
|
|
68
70
|
disabled: PropTypes.bool,
|
|
69
|
-
|
|
71
|
+
draggableTools: PropTypes.bool,
|
|
72
|
+
onChange: PropTypes.func,
|
|
73
|
+
onChangeToolsOrder: PropTypes.func
|
|
70
74
|
};
|
|
71
75
|
|
|
72
76
|
static defaultProps = {};
|
|
73
77
|
|
|
74
78
|
select = e => this.props.onChange(e.target.textContent);
|
|
75
79
|
|
|
80
|
+
moveTool = (dragIndex, hoverIndex) => {
|
|
81
|
+
const { options, onChangeToolsOrder } = this.props;
|
|
82
|
+
const dragged = options[dragIndex];
|
|
83
|
+
|
|
84
|
+
options.splice(dragIndex, 1);
|
|
85
|
+
options.splice(hoverIndex, 0, dragged);
|
|
86
|
+
|
|
87
|
+
onChangeToolsOrder(options);
|
|
88
|
+
};
|
|
89
|
+
|
|
76
90
|
render() {
|
|
77
|
-
const { classes, className, disabled, options, selectedToolType } = this.props;
|
|
91
|
+
const { classes, className, disabled, options, selectedToolType, draggableTools } = this.props;
|
|
92
|
+
|
|
78
93
|
return (
|
|
79
|
-
<div className={cn(className)}>
|
|
80
|
-
{(options || []).map(option => {
|
|
94
|
+
<div className={cn(className, classes.toolsContainer)}>
|
|
95
|
+
{(options || []).map((option, index) => {
|
|
81
96
|
if ((allTools || []).includes(option)) {
|
|
82
97
|
const isSelected = option === selectedToolType;
|
|
98
|
+
const toolRef = React.createRef();
|
|
83
99
|
|
|
84
100
|
return (
|
|
85
|
-
<
|
|
101
|
+
<DragTool
|
|
86
102
|
key={option}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
103
|
+
index={index}
|
|
104
|
+
draggable={draggableTools}
|
|
105
|
+
moveTool={this.moveTool}
|
|
106
|
+
classes={classes}
|
|
107
|
+
toolRef={toolRef}
|
|
108
|
+
>
|
|
109
|
+
<MiniButton
|
|
110
|
+
className={cn(classes.button, isSelected && classes.selected)}
|
|
111
|
+
disabled={disabled}
|
|
112
|
+
disableRipple={true}
|
|
113
|
+
onClick={this.select}
|
|
114
|
+
value={option}
|
|
115
|
+
selected={isSelected}
|
|
116
|
+
/>
|
|
117
|
+
</DragTool>
|
|
94
118
|
);
|
|
95
119
|
}
|
|
96
120
|
})}
|
|
@@ -100,12 +124,118 @@ export class ToggleBar extends React.Component {
|
|
|
100
124
|
}
|
|
101
125
|
|
|
102
126
|
const styles = theme => ({
|
|
127
|
+
toolsContainer: {
|
|
128
|
+
display: 'flex',
|
|
129
|
+
flexWrap: 'wrap'
|
|
130
|
+
},
|
|
103
131
|
button: {
|
|
104
132
|
marginRight: theme.spacing.unit / 2,
|
|
105
133
|
marginBottom: theme.spacing.unit / 2,
|
|
106
134
|
color: color.text(),
|
|
107
135
|
backgroundColor: color.background()
|
|
136
|
+
},
|
|
137
|
+
under: {
|
|
138
|
+
position: 'absolute',
|
|
139
|
+
top: 0,
|
|
140
|
+
left: 0,
|
|
141
|
+
zIndex: -1,
|
|
142
|
+
pointerEvents: 'none'
|
|
143
|
+
},
|
|
144
|
+
wrapper: {
|
|
145
|
+
position: 'relative'
|
|
146
|
+
},
|
|
147
|
+
hidden: {
|
|
148
|
+
opacity: 0
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
export default withDragContext(withStyles(styles)(ToggleBar));
|
|
153
|
+
|
|
154
|
+
const DRAG_TYPE = 'tool';
|
|
155
|
+
|
|
156
|
+
export class Item extends React.Component {
|
|
157
|
+
static propTypes = {
|
|
158
|
+
classes: PropTypes.object.isRequired,
|
|
159
|
+
className: PropTypes.string,
|
|
160
|
+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
|
|
161
|
+
connectDragSource: PropTypes.func.isRequired,
|
|
162
|
+
connectDragPreview: PropTypes.func.isRequired,
|
|
163
|
+
connectDropTarget: PropTypes.func.isRequired,
|
|
164
|
+
isDragging: PropTypes.bool
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
static defaultProps = {};
|
|
168
|
+
|
|
169
|
+
render() {
|
|
170
|
+
const {
|
|
171
|
+
classes,
|
|
172
|
+
children,
|
|
173
|
+
connectDragSource,
|
|
174
|
+
connectDropTarget,
|
|
175
|
+
connectDragPreview,
|
|
176
|
+
isDragging,
|
|
177
|
+
toolRef
|
|
178
|
+
} = this.props;
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<div className={classes.wrapper} ref={toolRef}>
|
|
182
|
+
{connectDragSource(
|
|
183
|
+
connectDropTarget(<div className={isDragging && classes.hidden}>{children}</div>)
|
|
184
|
+
)}
|
|
185
|
+
{connectDragPreview(<div className={classes.under}>{children}</div>)}
|
|
186
|
+
</div>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const itemSource = {
|
|
192
|
+
canDrag(props) {
|
|
193
|
+
return props.draggable;
|
|
194
|
+
},
|
|
195
|
+
beginDrag(props) {
|
|
196
|
+
return {
|
|
197
|
+
index: props.index
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const itemTarget = {
|
|
203
|
+
hover(props, monitor) {
|
|
204
|
+
const dragIndex = monitor.getItem().index;
|
|
205
|
+
const { toolRef, index: hoverIndex } = props;
|
|
206
|
+
|
|
207
|
+
if (dragIndex === hoverIndex || !toolRef.current) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const hoverBoundingRect = toolRef.current?.getBoundingClientRect();
|
|
212
|
+
const hoverMiddleX = (hoverBoundingRect.right - hoverBoundingRect.left) / 2;
|
|
213
|
+
const clientOffset = monitor.getClientOffset();
|
|
214
|
+
const hoverClientX = clientOffset.x - hoverBoundingRect.left;
|
|
215
|
+
|
|
216
|
+
if (dragIndex < hoverIndex && hoverClientX < hoverMiddleX) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (dragIndex > hoverIndex && hoverClientX > hoverMiddleX) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
props.moveTool(dragIndex, hoverIndex);
|
|
225
|
+
monitor.getItem().index = hoverIndex;
|
|
108
226
|
}
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const collectTarget = connect => ({ connectDropTarget: connect.dropTarget() });
|
|
230
|
+
|
|
231
|
+
const collectSource = (connect, monitor) => ({
|
|
232
|
+
connectDragSource: connect.dragSource(),
|
|
233
|
+
connectDragPreview: connect.dragPreview(),
|
|
234
|
+
isDragging: monitor.isDragging()
|
|
109
235
|
});
|
|
110
236
|
|
|
111
|
-
|
|
237
|
+
const DragTool = DropTarget(
|
|
238
|
+
DRAG_TYPE,
|
|
239
|
+
itemTarget,
|
|
240
|
+
collectTarget
|
|
241
|
+
)(DragSource(DRAG_TYPE, itemSource, collectSource)(Item));
|
package/src/tool-menu.jsx
CHANGED
|
@@ -9,9 +9,11 @@ export class ToolMenu extends React.Component {
|
|
|
9
9
|
className: PropTypes.string,
|
|
10
10
|
currentToolType: PropTypes.string,
|
|
11
11
|
disabled: PropTypes.bool,
|
|
12
|
+
draggableTools: PropTypes.bool,
|
|
12
13
|
labelModeEnabled: PropTypes.bool,
|
|
13
14
|
onChange: PropTypes.func,
|
|
14
15
|
onToggleLabelMode: PropTypes.func,
|
|
16
|
+
onChangeTools: PropTypes.func,
|
|
15
17
|
toolbarTools: PropTypes.arrayOf(PropTypes.string)
|
|
16
18
|
};
|
|
17
19
|
|
|
@@ -19,11 +21,22 @@ export class ToolMenu extends React.Component {
|
|
|
19
21
|
toolbarTools: []
|
|
20
22
|
};
|
|
21
23
|
|
|
24
|
+
updateToolsOrder = (tools, showLabel) => {
|
|
25
|
+
const { onChangeTools } = this.props;
|
|
26
|
+
|
|
27
|
+
if (showLabel) {
|
|
28
|
+
tools.push('label');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
onChangeTools(tools);
|
|
32
|
+
};
|
|
33
|
+
|
|
22
34
|
render() {
|
|
23
35
|
const {
|
|
24
36
|
className,
|
|
25
37
|
currentToolType,
|
|
26
38
|
disabled,
|
|
39
|
+
draggableTools,
|
|
27
40
|
labelModeEnabled,
|
|
28
41
|
onToggleLabelMode,
|
|
29
42
|
onChange
|
|
@@ -38,9 +51,11 @@ export class ToolMenu extends React.Component {
|
|
|
38
51
|
<div className={classNames(className)}>
|
|
39
52
|
<ToggleBar
|
|
40
53
|
disabled={disabled}
|
|
54
|
+
draggableTools={draggableTools}
|
|
41
55
|
options={toolbarTools}
|
|
42
56
|
selectedToolType={currentToolType}
|
|
43
57
|
onChange={onChange}
|
|
58
|
+
onChangeToolsOrder={tools => this.updateToolsOrder(tools, showLabel)}
|
|
44
59
|
/>
|
|
45
60
|
|
|
46
61
|
{showLabel && (
|