@jbrowse/plugin-config 2.0.1 → 2.1.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.
Files changed (68) hide show
  1. package/dist/ConfigurationEditorWidget/components/CallbackEditor.js +28 -19
  2. package/dist/ConfigurationEditorWidget/components/CallbackEditor.js.map +1 -1
  3. package/dist/ConfigurationEditorWidget/components/ColorEditor.js +6 -21
  4. package/dist/ConfigurationEditorWidget/components/ColorEditor.js.map +1 -1
  5. package/dist/ConfigurationEditorWidget/components/ConfigurationEditor.js +5 -1
  6. package/dist/ConfigurationEditorWidget/components/ConfigurationEditor.js.map +1 -1
  7. package/dist/ConfigurationEditorWidget/components/JsonEditor.d.ts +9 -7
  8. package/dist/ConfigurationEditorWidget/components/JsonEditor.js +34 -18
  9. package/dist/ConfigurationEditorWidget/components/JsonEditor.js.map +1 -1
  10. package/dist/ConfigurationEditorWidget/components/SlotEditor.d.ts +7 -5
  11. package/dist/ConfigurationEditorWidget/components/SlotEditor.js +28 -18
  12. package/dist/ConfigurationEditorWidget/components/SlotEditor.js.map +1 -1
  13. package/dist/ConfigurationEditorWidget/index.d.ts +10 -3
  14. package/dist/ConfigurationEditorWidget/index.js +4 -3
  15. package/dist/ConfigurationEditorWidget/index.js.map +1 -1
  16. package/dist/ConfigurationEditorWidget/model.d.ts +3 -2
  17. package/dist/ConfigurationEditorWidget/model.js +1 -0
  18. package/dist/ConfigurationEditorWidget/model.js.map +1 -1
  19. package/dist/FromConfigAdapter/FromConfigSequenceAdapter.js +1 -9
  20. package/dist/FromConfigAdapter/FromConfigSequenceAdapter.js.map +1 -1
  21. package/esm/ConfigurationEditorWidget/components/CallbackEditor.js +28 -19
  22. package/esm/ConfigurationEditorWidget/components/CallbackEditor.js.map +1 -1
  23. package/esm/ConfigurationEditorWidget/components/ColorEditor.js +6 -21
  24. package/esm/ConfigurationEditorWidget/components/ColorEditor.js.map +1 -1
  25. package/esm/ConfigurationEditorWidget/components/ConfigurationEditor.js +5 -1
  26. package/esm/ConfigurationEditorWidget/components/ConfigurationEditor.js.map +1 -1
  27. package/esm/ConfigurationEditorWidget/components/JsonEditor.d.ts +9 -7
  28. package/esm/ConfigurationEditorWidget/components/JsonEditor.js +38 -22
  29. package/esm/ConfigurationEditorWidget/components/JsonEditor.js.map +1 -1
  30. package/esm/ConfigurationEditorWidget/components/SlotEditor.d.ts +7 -5
  31. package/esm/ConfigurationEditorWidget/components/SlotEditor.js +33 -27
  32. package/esm/ConfigurationEditorWidget/components/SlotEditor.js.map +1 -1
  33. package/esm/ConfigurationEditorWidget/index.d.ts +10 -3
  34. package/esm/ConfigurationEditorWidget/index.js +4 -3
  35. package/esm/ConfigurationEditorWidget/index.js.map +1 -1
  36. package/esm/ConfigurationEditorWidget/model.d.ts +3 -2
  37. package/esm/ConfigurationEditorWidget/model.js +2 -1
  38. package/esm/ConfigurationEditorWidget/model.js.map +1 -1
  39. package/esm/FromConfigAdapter/FromConfigSequenceAdapter.js +1 -9
  40. package/esm/FromConfigAdapter/FromConfigSequenceAdapter.js.map +1 -1
  41. package/package.json +3 -4
  42. package/src/ConfigurationEditorWidget/components/CallbackEditor.tsx +44 -45
  43. package/src/ConfigurationEditorWidget/components/ColorEditor.tsx +6 -28
  44. package/src/ConfigurationEditorWidget/components/{ConfigurationEditor.test.js → ConfigurationEditor.test.tsx} +0 -0
  45. package/src/ConfigurationEditorWidget/components/ConfigurationEditor.tsx +5 -1
  46. package/src/ConfigurationEditorWidget/components/JsonEditor.tsx +84 -0
  47. package/src/ConfigurationEditorWidget/components/SlotEditor.tsx +484 -0
  48. package/src/ConfigurationEditorWidget/components/__snapshots__/{ConfigurationEditor.test.js.snap → ConfigurationEditor.test.tsx.snap} +120 -101
  49. package/src/ConfigurationEditorWidget/index.tsx +25 -0
  50. package/src/ConfigurationEditorWidget/{model.js → model.ts} +4 -2
  51. package/src/FromConfigAdapter/FromConfigSequenceAdapter.ts +1 -9
  52. package/dist/ConfigurationEditorWidget/components/CodeEditor.d.ts +0 -5
  53. package/dist/ConfigurationEditorWidget/components/CodeEditor.js +0 -85
  54. package/dist/ConfigurationEditorWidget/components/CodeEditor.js.map +0 -1
  55. package/dist/ConfigurationEditorWidget/components/ColorPicker.d.ts +0 -7
  56. package/dist/ConfigurationEditorWidget/components/ColorPicker.js +0 -69
  57. package/dist/ConfigurationEditorWidget/components/ColorPicker.js.map +0 -1
  58. package/esm/ConfigurationEditorWidget/components/CodeEditor.d.ts +0 -5
  59. package/esm/ConfigurationEditorWidget/components/CodeEditor.js +0 -42
  60. package/esm/ConfigurationEditorWidget/components/CodeEditor.js.map +0 -1
  61. package/esm/ConfigurationEditorWidget/components/ColorPicker.d.ts +0 -7
  62. package/esm/ConfigurationEditorWidget/components/ColorPicker.js +0 -26
  63. package/esm/ConfigurationEditorWidget/components/ColorPicker.js.map +0 -1
  64. package/src/ConfigurationEditorWidget/components/CodeEditor.tsx +0 -59
  65. package/src/ConfigurationEditorWidget/components/ColorPicker.tsx +0 -43
  66. package/src/ConfigurationEditorWidget/components/JsonEditor.js +0 -52
  67. package/src/ConfigurationEditorWidget/components/SlotEditor.js +0 -376
  68. package/src/ConfigurationEditorWidget/index.js +0 -20
@@ -9,16 +9,8 @@ export default class FromConfigSequenceAdapter extends FromConfigAdapter {
9
9
  * @returns Observable of Feature objects in the region
10
10
  */
11
11
  getFeatures(region) {
12
- // TODO: restore commented version below once TSDX supports Rollup v2
13
- // xref: https://github.com/rollup/rollup/blob/master/CHANGELOG.md#bug-fixes-45
14
- // return ObservableCreate<Feature>(async observer => {
15
- // const feats = await super.getFeatures(region).pipe(toArray()).toPromise()
16
- const superGetFeatures = super.getFeatures;
17
12
  return ObservableCreate(async (observer) => {
18
- const feats = await superGetFeatures
19
- .call(this, region)
20
- .pipe(toArray())
21
- .toPromise();
13
+ const feats = await super.getFeatures(region).pipe(toArray()).toPromise();
22
14
  const feat = feats[0];
23
15
  observer.next(new SimpleFeature({
24
16
  ...feat.toJSON(),
@@ -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M,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAC5C;aACJ,CAAC,CACH,CAAA;YAED,QAAQ,CAAC,QAAQ,EAAE,CAAA;QACrB,CAAC,CAAC,CAAA;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU;QACd,MAAM,OAAO,GAAG,EAAE,CAAA;QAElB,wEAAwE;QACxE,KAAK,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE;YAC/C,IAAI,aAAa,CAAA;YACjB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;gBAC9B,IACE,aAAa;oBACb,aAAa,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;oBACzC,aAAa,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EACzC;oBACA,aAAa,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;iBACvC;qBAAM;oBACL,IAAI,aAAa,EAAE;wBACjB,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;qBAC5B;oBACD,aAAa,GAAG;wBACd,OAAO;wBACP,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;wBAC3B,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;qBACxB,CAAA;iBACF;aACF;YACD,IAAI,aAAa,EAAE;gBACjB,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;aAC5B;SACF;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;IAED;;;;OAIG;IACH,aAAa,EAAC,gBAAgB,IAAS,CAAC;CACzC"}
1
+ {"version":3,"file":"FromConfigSequenceAdapter.js","sourceRoot":"","sources":["../../src/FromConfigAdapter/FromConfigSequenceAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,aAA0B,MAAM,kCAAkC,CAAA;AACzE,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,OAAO,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE;YAC/C,IAAI,aAAa,CAAA;YACjB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;gBAC9B,IACE,aAAa;oBACb,aAAa,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;oBACzC,aAAa,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EACzC;oBACA,aAAa,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;iBACvC;qBAAM;oBACL,IAAI,aAAa,EAAE;wBACjB,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;qBAC5B;oBACD,aAAa,GAAG;wBACd,OAAO;wBACP,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;wBAC3B,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC;qBACxB,CAAA;iBACF;aACF;YACD,IAAI,aAAa,EAAE;gBACjB,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;aAC5B;SACF;QAED,OAAO,OAAO,CAAA;IAChB,CAAC;IAED;;;;OAIG;IACH,aAAa,EAAC,gBAAgB,IAAS,CAAC;CACzC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jbrowse/plugin-config",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "JBrowse 2 config utilities",
5
5
  "keywords": [
6
6
  "jbrowse",
@@ -39,8 +39,7 @@
39
39
  "dependencies": {
40
40
  "@babel/runtime": "^7.17.9",
41
41
  "@mui/icons-material": "^5.0.1",
42
- "pluralize": "^8.0.0",
43
- "react-color": "^2.19.3"
42
+ "pluralize": "^8.0.0"
44
43
  },
45
44
  "peerDependencies": {
46
45
  "@jbrowse/core": "^2.0.0",
@@ -60,5 +59,5 @@
60
59
  "distModule": "esm/index.js",
61
60
  "srcModule": "src/index.ts",
62
61
  "module": "esm/index.js",
63
- "gitHead": "ed935bf5612af3818abdc8ef52d100d5d81d33a2"
62
+ "gitHead": "0db0462fa1f9f15ab4869da085bcab032b9483c3"
64
63
  }
@@ -1,18 +1,13 @@
1
1
  import React, { useEffect, useState } from 'react'
2
+ import { Tooltip, IconButton, TextField } from '@mui/material'
2
3
  import { useDebounce } from '@jbrowse/core/util'
3
4
  import { stringToJexlExpression } from '@jbrowse/core/util/jexlStrings'
4
- import {
5
- FormControl,
6
- FormHelperText,
7
- InputLabel,
8
- Tooltip,
9
- IconButton,
10
- TextField,
11
- } from '@mui/material'
12
- import { makeStyles } from 'tss-react/mui'
13
- import HelpIcon from '@mui/icons-material/Help'
14
5
  import { getEnv } from 'mobx-state-tree'
15
6
  import { observer } from 'mobx-react'
7
+ import { makeStyles } from 'tss-react/mui'
8
+
9
+ // icons
10
+ import HelpIcon from '@mui/icons-material/Help'
16
11
 
17
12
  // Optimize by using system default fonts:
18
13
  // https://css-tricks.com/snippets/css/font-stacks/
@@ -23,11 +18,21 @@ const useStyles = makeStyles()(theme => ({
23
18
  callbackEditor: {
24
19
  marginTop: '16px',
25
20
  borderBottom: `1px solid ${theme.palette.divider}`,
21
+ width: '100%',
26
22
  fontFamily,
27
23
  },
28
24
  textAreaFont: {
29
25
  fontFamily,
30
26
  },
27
+ callbackContainer: {
28
+ width: '100%',
29
+ overflowX: 'auto',
30
+ },
31
+
32
+ error: {
33
+ color: 'red',
34
+ fontSize: '0.8em',
35
+ },
31
36
  }))
32
37
 
33
38
  function CallbackEditor({
@@ -72,10 +77,8 @@ function CallbackEditor({
72
77
  // do this last
73
78
  return (
74
79
  <>
75
- <FormControl>
76
- <InputLabel shrink htmlFor="callback-editor">
77
- {slot.name}
78
- </InputLabel>
80
+ {error ? <p className={classes.error}>{`${error}`}</p> : null}
81
+ <div className={classes.callbackContainer}>
79
82
  <TextField
80
83
  multiline
81
84
  className={classes.callbackEditor}
@@ -88,38 +91,34 @@ function CallbackEditor({
88
91
  },
89
92
  }}
90
93
  />
91
- {error ? (
92
- <FormHelperText
93
- style={{ color: '#f00' }}
94
- >{`${error}`}</FormHelperText>
95
- ) : null}
96
- <FormHelperText>{slot.description}</FormHelperText>
97
- </FormControl>
98
- <Tooltip
99
- title={
100
- <div>
101
- Callbacks are written in Jexl format. Click to learn more.
102
- <br /> Names of available context items: {slot.contextVariable}
103
- </div>
104
- }
105
- arrow
106
- >
107
- <IconButton
108
- color="primary"
109
- onClick={() => {
110
- const newWindow = window.open(
111
- 'https://github.com/TomFrost/Jexl',
112
- '_blank',
113
- 'noopener,noreferrer',
114
- )
115
- if (newWindow) {
116
- newWindow.opener = null
117
- }
118
- }}
94
+
95
+ <p>{slot.description}</p>
96
+ <Tooltip
97
+ title={
98
+ <div>
99
+ Callbacks are written in Jexl format. Click to learn more.
100
+ <br /> Names of available context items: {slot.contextVariable}
101
+ </div>
102
+ }
103
+ arrow
119
104
  >
120
- <HelpIcon />
121
- </IconButton>
122
- </Tooltip>
105
+ <IconButton
106
+ color="primary"
107
+ onClick={() => {
108
+ const newWindow = window.open(
109
+ 'https://github.com/TomFrost/Jexl',
110
+ '_blank',
111
+ 'noopener,noreferrer',
112
+ )
113
+ if (newWindow) {
114
+ newWindow.opener = null
115
+ }
116
+ }}
117
+ >
118
+ <HelpIcon />
119
+ </IconButton>
120
+ </Tooltip>
121
+ </div>
123
122
  </>
124
123
  )
125
124
  }
@@ -1,19 +1,8 @@
1
1
  import React, { lazy, useState } from 'react'
2
2
  import { observer } from 'mobx-react'
3
3
  import { TextField } from '@mui/material'
4
- import { Color, RGBColor } from 'react-color'
5
4
 
6
- const ColorPicker = lazy(() => import('./ColorPicker'))
7
-
8
- // this is needed because passing a entire color object into the react-color
9
- // for alpha, can't pass in an rgba string for example
10
- function serializeColor(color: Color) {
11
- if (color instanceof Object) {
12
- const { r, g, b, a } = color as RGBColor
13
- return a === undefined ? `rgb(${r},${g},${b})` : `rgba(${r},${g},${b},${a})`
14
- }
15
- return color
16
- }
5
+ const ColorPicker = lazy(() => import('@jbrowse/core/ui/ColorPicker'))
17
6
 
18
7
  export const ColorSlot = (props: {
19
8
  value: string
@@ -28,31 +17,20 @@ export const ColorSlot = (props: {
28
17
  const [displayed, setDisplayed] = useState(false)
29
18
 
30
19
  return (
31
- <>
20
+ <div style={{ display: 'flex' }}>
32
21
  <TextField
33
22
  value={value}
34
23
  label={label}
35
- InputProps={{
36
- style: {
37
- color: value,
38
- borderRightWidth: '25px',
39
- borderRightStyle: 'solid',
40
- borderRightColor: value,
41
- },
42
- }}
43
24
  onClick={() => setDisplayed(!displayed)}
44
25
  onChange={event => onChange(event.target.value)}
45
26
  {...TextFieldProps}
46
27
  />
47
- {displayed ? (
28
+ <div style={{ marginTop: 10 }}>
48
29
  <React.Suspense fallback={<div />}>
49
- <ColorPicker
50
- color={value}
51
- onChange={event => onChange(serializeColor(event.rgb))}
52
- />
30
+ <ColorPicker color={value} onChange={event => onChange(event)} />
53
31
  </React.Suspense>
54
- ) : null}
55
- </>
32
+ </div>
33
+ </div>
56
34
  )
57
35
  }
58
36
 
@@ -40,6 +40,10 @@ const useStyles = makeStyles()(theme => ({
40
40
  accordion: {
41
41
  border: `1px solid ${theme.palette.text.primary}`,
42
42
  },
43
+ noOverflow: {
44
+ width: '100%',
45
+ overflowX: 'auto',
46
+ },
43
47
  }))
44
48
 
45
49
  const Member = observer(
@@ -92,7 +96,7 @@ const Member = observer(
92
96
  </AccordionSummary>
93
97
  <AccordionDetails className={classes.expansionPanelDetails}>
94
98
  {typeSelector}
95
- <FormGroup>
99
+ <FormGroup className={classes.noOverflow}>
96
100
  <Schema schema={slot} path={[...path, slotName]} />
97
101
  </FormGroup>
98
102
  </AccordionDetails>
@@ -0,0 +1,84 @@
1
+ import React, { useEffect, useState } from 'react'
2
+ import { InputLabel, TextField } from '@mui/material'
3
+ import { makeStyles } from 'tss-react/mui'
4
+ import { observer } from 'mobx-react'
5
+
6
+ // fontSize and fontFamily have to match between Editor and SyntaxHighlighter
7
+ const fontSize = '12px'
8
+ // Optimize by using system default fonts: https://css-tricks.com/snippets/css/font-stacks/
9
+ const fontFamily =
10
+ 'Consolas, "Andale Mono WT", "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Liberation Mono", "Nimbus Mono L", Monaco, "Courier New", Courier, monospace'
11
+
12
+ const useStyles = makeStyles()(theme => ({
13
+ error: {
14
+ color: 'red',
15
+ fontSize: '0.8em',
16
+ },
17
+ callbackEditor: {
18
+ fontFamily,
19
+ fontSize,
20
+ background: theme.palette.background.default,
21
+ width: 800,
22
+ marginTop: '16px',
23
+ border: '1px solid rgba(0,0,0,0.42)',
24
+ },
25
+ callbackContainer: {
26
+ width: '100%',
27
+ overflowX: 'auto',
28
+ },
29
+ textAreaFont: {
30
+ fontFamily,
31
+ },
32
+ }))
33
+
34
+ function JsonEditor({
35
+ slot,
36
+ }: {
37
+ slot: {
38
+ name: string
39
+ description: string
40
+ value: unknown
41
+ set: (arg: unknown) => void
42
+ }
43
+ }) {
44
+ const { classes } = useStyles()
45
+ const [contents, setContents] = useState(JSON.stringify(slot.value, null, 2))
46
+ const [error, setError] = useState<unknown>()
47
+
48
+ useEffect(() => {
49
+ try {
50
+ setError(undefined)
51
+ slot.set(JSON.parse(contents))
52
+ } catch (e) {
53
+ console.error({ e })
54
+ setError(e)
55
+ }
56
+ }, [contents, slot])
57
+
58
+ return (
59
+ <>
60
+ {error ? <p className={classes.error}>{`${error}`}</p> : null}
61
+ <div className={classes.callbackContainer}>
62
+ <InputLabel shrink htmlFor="json-editor">
63
+ {slot.name}
64
+ </InputLabel>
65
+ <TextField
66
+ id="json-editor"
67
+ className={classes.callbackEditor}
68
+ value={contents}
69
+ helperText={slot.description}
70
+ multiline
71
+ onChange={event => setContents(event.target.value)}
72
+ style={{ background: error ? '#fdd' : undefined }}
73
+ InputProps={{
74
+ classes: {
75
+ input: classes.textAreaFont,
76
+ },
77
+ }}
78
+ />
79
+ </div>
80
+ </>
81
+ )
82
+ }
83
+
84
+ export default observer(JsonEditor)