@coveord/plasma-mantine 47.4.0 → 47.6.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 (41) hide show
  1. package/.turbo/turbo-build.log +3 -3
  2. package/.turbo/turbo-test.log +9 -9
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/cjs/components/code-editor/CodeEditor.js +50 -12
  5. package/dist/cjs/components/code-editor/CodeEditor.js.map +1 -1
  6. package/dist/cjs/components/code-editor/__mocks__/monaco-editor.js +24 -0
  7. package/dist/cjs/components/code-editor/__mocks__/monaco-editor.js.map +1 -0
  8. package/dist/cjs/components/collection/Collection.js +6 -7
  9. package/dist/cjs/components/collection/Collection.js.map +1 -1
  10. package/dist/cjs/components/modal-wizard/index.js.map +1 -1
  11. package/dist/cjs/index.js +0 -3
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/definitions/components/code-editor/CodeEditor.d.ts +7 -0
  14. package/dist/definitions/components/code-editor/CodeEditor.d.ts.map +1 -1
  15. package/dist/definitions/components/code-editor/__mocks__/monaco-editor.d.ts +8 -0
  16. package/dist/definitions/components/code-editor/__mocks__/monaco-editor.d.ts.map +1 -0
  17. package/dist/definitions/components/collection/Collection.d.ts +1 -0
  18. package/dist/definitions/components/collection/Collection.d.ts.map +1 -1
  19. package/dist/definitions/components/modal-wizard/index.d.ts +1 -0
  20. package/dist/definitions/components/modal-wizard/index.d.ts.map +1 -1
  21. package/dist/definitions/index.d.ts +1 -1
  22. package/dist/definitions/index.d.ts.map +1 -1
  23. package/dist/esm/components/code-editor/CodeEditor.js +49 -13
  24. package/dist/esm/components/code-editor/CodeEditor.js.map +1 -1
  25. package/dist/esm/components/code-editor/__mocks__/monaco-editor.js +14 -0
  26. package/dist/esm/components/code-editor/__mocks__/monaco-editor.js.map +1 -0
  27. package/dist/esm/components/collection/Collection.js +6 -7
  28. package/dist/esm/components/collection/Collection.js.map +1 -1
  29. package/dist/esm/components/modal-wizard/index.js.map +1 -1
  30. package/dist/esm/index.js +1 -1
  31. package/dist/esm/index.js.map +1 -1
  32. package/jest.config.js +0 -1
  33. package/package.json +3 -2
  34. package/src/components/code-editor/CodeEditor.tsx +32 -5
  35. package/src/components/code-editor/__mocks__/monaco-editor.ts +9 -0
  36. package/src/components/code-editor/__tests__/CodeEditor.spec.tsx +24 -5
  37. package/src/components/collection/Collection.tsx +5 -4
  38. package/src/components/collection/__tests__/Collection.spec.tsx +10 -6
  39. package/src/components/modal-wizard/index.ts +1 -0
  40. package/src/index.ts +1 -1
  41. package/tsconfig.json +6 -3
@@ -19,12 +19,11 @@ var defaultProps = {
19
19
  required: false
20
20
  };
21
21
  export var Collection = function(props) {
22
- var _ref = useComponentDefaultProps("Collection", defaultProps, props), value = _ref.value, defaultValue = _ref.defaultValue, onChange = _ref.onChange, onFocus = _ref.onFocus, disabled = _ref.disabled, draggable = _ref.draggable, children = _ref.children, spacing = _ref.spacing, required = _ref.required, newItem = _ref.newItem, addLabel = _ref.addLabel, addDisabledTooltip = _ref.addDisabledTooltip, // Style props
22
+ var _ref = useComponentDefaultProps("Collection", defaultProps, props), value = _ref.value, defaultValue = _ref.defaultValue, onChange = _ref.onChange, disabled = _ref.disabled, draggable = _ref.draggable, children = _ref.children, spacing = _ref.spacing, required = _ref.required, newItem = _ref.newItem, addLabel = _ref.addLabel, addDisabledTooltip = _ref.addDisabledTooltip, allowAdd = _ref.allowAdd, // Style props
23
23
  classNames = _ref.classNames, className = _ref.className, styles = _ref.styles, unstyled = _ref.unstyled, others = _object_without_properties(_ref, [
24
24
  "value",
25
25
  "defaultValue",
26
26
  "onChange",
27
- "onFocus",
28
27
  "disabled",
29
28
  "draggable",
30
29
  "children",
@@ -33,6 +32,7 @@ export var Collection = function(props) {
33
32
  "newItem",
34
33
  "addLabel",
35
34
  "addDisabledTooltip",
35
+ "allowAdd",
36
36
  "classNames",
37
37
  "className",
38
38
  "styles",
@@ -64,13 +64,12 @@ export var Collection = function(props) {
64
64
  children: children(item, index)
65
65
  }, index);
66
66
  });
67
- var hasEmptyItem = values.some(function(item) {
68
- return JSON.stringify(item) === JSON.stringify(newItem);
69
- });
67
+ var ref3;
68
+ var addAllowed = (ref3 = allowAdd === null || allowAdd === void 0 ? void 0 : allowAdd(values)) !== null && ref3 !== void 0 ? ref3 : true;
70
69
  var _addButton = disabled ? null : /*#__PURE__*/ _jsx(Group, {
71
70
  children: /*#__PURE__*/ _jsx(Tooltip, {
72
71
  label: addDisabledTooltip,
73
- disabled: !hasEmptyItem,
72
+ disabled: addAllowed,
74
73
  children: /*#__PURE__*/ _jsx(Box, {
75
74
  children: /*#__PURE__*/ _jsx(Button, {
76
75
  variant: "subtle",
@@ -80,7 +79,7 @@ export var Collection = function(props) {
80
79
  onClick: function() {
81
80
  return append(newItem);
82
81
  },
83
- disabled: hasEmptyItem,
82
+ disabled: !addAllowed,
84
83
  children: addLabel
85
84
  })
86
85
  })
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/collection/Collection.tsx"],"sourcesContent":["import {AddSize16Px} from '@coveord/plasma-react-icons';\nimport {\n Box,\n Button,\n DefaultProps,\n Group,\n MantineNumberSize,\n Selectors,\n Stack,\n Tooltip,\n useComponentDefaultProps,\n} from '@mantine/core';\nimport {useId} from '@mantine/hooks';\nimport {ReactNode} from 'react';\nimport {DragDropContext, Droppable} from 'react-beautiful-dnd';\n\nimport {useControlledList} from '../../hooks';\nimport {CollectionItem} from './CollectionItem';\nimport useStyles from './Colllection.styles';\n\ninterface CollectionProps<T> extends DefaultProps<Selectors<typeof useStyles>> {\n newItem: T;\n children: (item: T, index: number) => ReactNode;\n defaultValue?: T[];\n value?: T[];\n onFocus?: () => void;\n onChange?: (value: T[]) => void;\n draggable?: boolean;\n disabled?: boolean;\n addLabel?: string;\n addDisabledTooltip?: string;\n spacing?: MantineNumberSize;\n required?: boolean;\n}\n\nconst defaultProps: Partial<CollectionProps<unknown>> = {\n draggable: false,\n addLabel: 'Add item',\n addDisabledTooltip: 'There is already an empty item',\n disabled: false,\n spacing: 'xs',\n required: false,\n};\n\nexport const Collection = <T,>(props: CollectionProps<T>) => {\n const {\n value,\n defaultValue,\n onChange,\n onFocus,\n disabled,\n draggable,\n children,\n spacing,\n required,\n newItem,\n addLabel,\n addDisabledTooltip,\n\n // Style props\n classNames,\n className,\n styles,\n unstyled,\n\n ...others\n } = useComponentDefaultProps('Collection', defaultProps as CollectionProps<T>, props);\n const {classes, cx} = useStyles(null, {classNames, name: 'Collection', styles, unstyled});\n const collectionID = useId('dnd-droppable');\n\n const [values, {append, remove, reorder}] = useControlledList({value, onChange, defaultValue});\n const hasOnlyOneItem = values.length === 1;\n const items = values.map((item, index) => (\n <CollectionItem\n key={index}\n disabled={disabled}\n draggable={draggable}\n index={index}\n onRemove={() => remove(index)}\n styles={styles}\n removable={!(required && hasOnlyOneItem)}\n >\n {children(item, index)}\n </CollectionItem>\n ));\n\n const hasEmptyItem = values.some((item) => JSON.stringify(item) === JSON.stringify(newItem));\n\n const _addButton = disabled ? null : (\n <Group>\n <Tooltip label={addDisabledTooltip} disabled={!hasEmptyItem}>\n <Box>\n <Button\n variant=\"subtle\"\n leftIcon={<AddSize16Px height={16} />}\n onClick={() => append(newItem)}\n disabled={hasEmptyItem}\n >\n {addLabel}\n </Button>\n </Box>\n </Tooltip>\n </Group>\n );\n\n return (\n <DragDropContext\n onDragEnd={({destination, source}) => reorder({from: source.index, to: destination?.index || 0})}\n >\n <Droppable direction=\"vertical\" droppableId={collectionID}>\n {(provided) => (\n <Box\n {...provided.droppableProps}\n ref={provided.innerRef}\n className={cx(classes.root, className)}\n {...others}\n >\n <Stack spacing={spacing}>\n {items}\n {provided.placeholder}\n {_addButton}\n </Stack>\n </Box>\n )}\n </Droppable>\n </DragDropContext>\n );\n};\n"],"names":["AddSize16Px","Box","Button","Group","Stack","Tooltip","useComponentDefaultProps","useId","DragDropContext","Droppable","useControlledList","CollectionItem","useStyles","defaultProps","draggable","addLabel","addDisabledTooltip","disabled","spacing","required","Collection","props","value","defaultValue","onChange","onFocus","children","newItem","classNames","className","styles","unstyled","others","name","classes","cx","collectionID","values","append","remove","reorder","hasOnlyOneItem","length","items","map","item","index","onRemove","removable","hasEmptyItem","some","JSON","stringify","_addButton","label","variant","leftIcon","height","onClick","onDragEnd","destination","source","from","to","direction","droppableId","provided","droppableProps","ref","innerRef","root","placeholder"],"mappings":"AAAA;;;;;AAAA,SAAQA,WAAW,QAAO,6BAA6B,CAAC;AACxD,SACIC,GAAG,EACHC,MAAM,EAENC,KAAK,EAGLC,KAAK,EACLC,OAAO,EACPC,wBAAwB,QACrB,eAAe,CAAC;AACvB,SAAQC,KAAK,QAAO,gBAAgB,CAAC;AAErC,SAAQC,eAAe,EAAEC,SAAS,QAAO,qBAAqB,CAAC;AAE/D,SAAQC,iBAAiB,QAAO,aAAa,CAAC;AAC9C,SAAQC,cAAc,QAAO,kBAAkB,CAAC;AAChD,OAAOC,SAAS,MAAM,sBAAsB,CAAC;AAiB7C,IAAMC,YAAY,GAAsC;IACpDC,SAAS,EAAE,KAAK;IAChBC,QAAQ,EAAE,UAAU;IACpBC,kBAAkB,EAAE,gCAAgC;IACpDC,QAAQ,EAAE,KAAK;IACfC,OAAO,EAAE,IAAI;IACbC,QAAQ,EAAE,KAAK;CAClB,AAAC;AAEF,OAAO,IAAMC,UAAU,GAAG,SAAKC,KAAyB,EAAK;IACzD,IAqBIf,IAAiF,GAAjFA,wBAAwB,CAAC,YAAY,EAAEO,YAAY,EAAwBQ,KAAK,CAAC,EApBjFC,KAAK,GAoBLhB,IAAiF,CApBjFgB,KAAK,EACLC,YAAY,GAmBZjB,IAAiF,CAnBjFiB,YAAY,EACZC,QAAQ,GAkBRlB,IAAiF,CAlBjFkB,QAAQ,EACRC,OAAO,GAiBPnB,IAAiF,CAjBjFmB,OAAO,EACPR,QAAQ,GAgBRX,IAAiF,CAhBjFW,QAAQ,EACRH,SAAS,GAeTR,IAAiF,CAfjFQ,SAAS,EACTY,QAAQ,GAcRpB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,MAAM,SAANA,MAAM;YAAMrB,OAAAA,OAAO,CAAC;gBAACsB,IAAI,EAAED,MAAM,CAACf,KAAK;gBAAEiB,EAAE,EAAEH,CAAAA,WAAW,aAAXA,WAAW,WAAO,GAAlBA,KAAAA,CAAkB,GAAlBA,WAAW,CAAEd,KAAK,CAAA,IAAI,CAAC;aAAC,CAAC,CAAA;SAAA;kBAEhG,cAAA,KAACrC,SAAS;YAACuD,SAAS,EAAC,UAAU;YAACC,WAAW,EAAE7B,YAAY;sBACpD,SAAC8B,QAAQ;qCACN,KAACjE,GAAG,8EACIiE,QAAQ,CAACC,cAAc;oBAC3BC,GAAG,EAAEF,QAAQ,CAACG,QAAQ;oBACtBxC,SAAS,EAAEM,EAAE,CAACD,OAAO,CAACoC,IAAI,EAAEzC,SAAS,CAAC;oBAClCG,MAAM;8BAEV,cAAA,MAAC5B,KAAK;wBAACc,OAAO,EAAEA,OAAO;;4BAClByB,KAAK;4BACLuB,QAAQ,CAACK,WAAW;4BACpBlB,UAAU;;sBACP;mBACN;aACT;UACO;MACE,CACpB;AACN,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../../../src/components/collection/Collection.tsx"],"sourcesContent":["import {AddSize16Px} from '@coveord/plasma-react-icons';\nimport {\n Box,\n Button,\n DefaultProps,\n Group,\n MantineNumberSize,\n Selectors,\n Stack,\n Tooltip,\n useComponentDefaultProps,\n} from '@mantine/core';\nimport {useId} from '@mantine/hooks';\nimport {ReactNode} from 'react';\nimport {DragDropContext, Droppable} from 'react-beautiful-dnd';\n\nimport {useControlledList} from '../../hooks';\nimport {CollectionItem} from './CollectionItem';\nimport useStyles from './Colllection.styles';\n\ninterface CollectionProps<T> extends DefaultProps<Selectors<typeof useStyles>> {\n newItem: T;\n children: (item: T, index: number) => ReactNode;\n defaultValue?: T[];\n value?: T[];\n onFocus?: () => void;\n onChange?: (value: T[]) => void;\n draggable?: boolean;\n disabled?: boolean;\n allowAdd?: (values: T[]) => boolean;\n addLabel?: string;\n addDisabledTooltip?: string;\n spacing?: MantineNumberSize;\n required?: boolean;\n}\n\nconst defaultProps: Partial<CollectionProps<unknown>> = {\n draggable: false,\n addLabel: 'Add item',\n addDisabledTooltip: 'There is already an empty item',\n disabled: false,\n spacing: 'xs',\n required: false,\n};\n\nexport const Collection = <T,>(props: CollectionProps<T>) => {\n const {\n value,\n defaultValue,\n onChange,\n disabled,\n draggable,\n children,\n spacing,\n required,\n newItem,\n addLabel,\n addDisabledTooltip,\n allowAdd,\n\n // Style props\n classNames,\n className,\n styles,\n unstyled,\n\n ...others\n } = useComponentDefaultProps('Collection', defaultProps as CollectionProps<T>, props);\n const {classes, cx} = useStyles(null, {classNames, name: 'Collection', styles, unstyled});\n const collectionID = useId('dnd-droppable');\n\n const [values, {append, remove, reorder}] = useControlledList({value, onChange, defaultValue});\n const hasOnlyOneItem = values.length === 1;\n const items = values.map((item, index) => (\n <CollectionItem\n key={index}\n disabled={disabled}\n draggable={draggable}\n index={index}\n onRemove={() => remove(index)}\n styles={styles}\n removable={!(required && hasOnlyOneItem)}\n >\n {children(item, index)}\n </CollectionItem>\n ));\n\n const addAllowed = allowAdd?.(values) ?? true;\n\n const _addButton = disabled ? null : (\n <Group>\n <Tooltip label={addDisabledTooltip} disabled={addAllowed}>\n <Box>\n <Button\n variant=\"subtle\"\n leftIcon={<AddSize16Px height={16} />}\n onClick={() => append(newItem)}\n disabled={!addAllowed}\n >\n {addLabel}\n </Button>\n </Box>\n </Tooltip>\n </Group>\n );\n\n return (\n <DragDropContext\n onDragEnd={({destination, source}) => reorder({from: source.index, to: destination?.index || 0})}\n >\n <Droppable direction=\"vertical\" droppableId={collectionID}>\n {(provided) => (\n <Box\n {...provided.droppableProps}\n ref={provided.innerRef}\n className={cx(classes.root, className)}\n {...others}\n >\n <Stack spacing={spacing}>\n {items}\n {provided.placeholder}\n {_addButton}\n </Stack>\n </Box>\n )}\n </Droppable>\n </DragDropContext>\n );\n};\n"],"names":["AddSize16Px","Box","Button","Group","Stack","Tooltip","useComponentDefaultProps","useId","DragDropContext","Droppable","useControlledList","CollectionItem","useStyles","defaultProps","draggable","addLabel","addDisabledTooltip","disabled","spacing","required","Collection","props","value","defaultValue","onChange","children","newItem","allowAdd","classNames","className","styles","unstyled","others","name","classes","cx","collectionID","values","append","remove","reorder","hasOnlyOneItem","length","items","map","item","index","onRemove","removable","addAllowed","_addButton","label","variant","leftIcon","height","onClick","onDragEnd","destination","source","from","to","direction","droppableId","provided","droppableProps","ref","innerRef","root","placeholder"],"mappings":"AAAA;;;;;AAAA,SAAQA,WAAW,QAAO,6BAA6B,CAAC;AACxD,SACIC,GAAG,EACHC,MAAM,EAENC,KAAK,EAGLC,KAAK,EACLC,OAAO,EACPC,wBAAwB,QACrB,eAAe,CAAC;AACvB,SAAQC,KAAK,QAAO,gBAAgB,CAAC;AAErC,SAAQC,eAAe,EAAEC,SAAS,QAAO,qBAAqB,CAAC;AAE/D,SAAQC,iBAAiB,QAAO,aAAa,CAAC;AAC9C,SAAQC,cAAc,QAAO,kBAAkB,CAAC;AAChD,OAAOC,SAAS,MAAM,sBAAsB,CAAC;AAkB7C,IAAMC,YAAY,GAAsC;IACpDC,SAAS,EAAE,KAAK;IAChBC,QAAQ,EAAE,UAAU;IACpBC,kBAAkB,EAAE,gCAAgC;IACpDC,QAAQ,EAAE,KAAK;IACfC,OAAO,EAAE,IAAI;IACbC,QAAQ,EAAE,KAAK;CAClB,AAAC;AAEF,OAAO,IAAMC,UAAU,GAAG,SAAKC,KAAyB,EAAK;IACzD,IAqBIf,IAAiF,GAAjFA,wBAAwB,CAAC,YAAY,EAAEO,YAAY,EAAwBQ,KAAK,CAAC,EApBjFC,KAAK,GAoBLhB,IAAiF,CApBjFgB,KAAK,EACLC,YAAY,GAmBZjB,IAAiF,CAnBjFiB,YAAY,EACZC,QAAQ,GAkBRlB,IAAiF,CAlBjFkB,QAAQ,EACRP,QAAQ,GAiBRX,IAAiF,CAjBjFW,QAAQ,EACRH,SAAS,GAgBTR,IAAiF,C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AAQ;kBACJ;cACP;UACA;MACN,AACX,AAAC;IAEF,qBACI,KAACP,eAAe;QACZgD,SAAS,EAAE;gBAAEC,WAAW,SAAXA,WAAW,EAAEC,MAAM,SAANA,MAAM;YAAMlB,OAAAA,OAAO,CAAC;gBAACmB,IAAI,EAAED,MAAM,CAACZ,KAAK;gBAAEc,EAAE,EAAEH,CAAAA,WAAW,aAAXA,WAAW,WAAO,GAAlBA,KAAAA,CAAkB,GAAlBA,WAAW,CAAEX,KAAK,CAAA,IAAI,CAAC;aAAC,CAAC,CAAA;SAAA;kBAEhG,cAAA,KAACrC,SAAS;YAACoD,SAAS,EAAC,UAAU;YAACC,WAAW,EAAE1B,YAAY;sBACpD,SAAC2B,QAAQ;qCACN,KAAC9D,GAAG,8EACI8D,QAAQ,CAACC,cAAc;oBAC3BC,GAAG,EAAEF,QAAQ,CAACG,QAAQ;oBACtBrC,SAAS,EAAEM,EAAE,CAACD,OAAO,CAACiC,IAAI,EAAEtC,SAAS,CAAC;oBAClCG,MAAM;8BAEV,cAAA,MAAC5B,KAAK;wBAACc,OAAO,EAAEA,OAAO;;4BAClByB,KAAK;4BACLoB,QAAQ,CAACK,WAAW;4BACpBlB,UAAU;;sBACP;mBACN;aACT;UACO;MACE,CACpB;AACN,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/components/modal-wizard/index.ts"],"sourcesContent":["export * from './ModalWizard';\n"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
1
+ {"version":3,"sources":["../../../../src/components/modal-wizard/index.ts"],"sourcesContent":["export * from './ModalWizard';\nexport {type ModalWizardStepProps} from './ModalWizardStep';\n"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { ColumnDef, createColumnHelper } from "@tanstack/table-core";
1
+ export { createColumnHelper } from "@tanstack/table-core";
2
2
  export * from "@mantine/core";
3
3
  export * from "@mantine/form";
4
4
  export * from "@mantine/hooks";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import {Tuple} from '@mantine/core';\n\nimport {PlasmaColors} from './theme/PlasmaColors';\n\nexport {ColumnDef, createColumnHelper} from '@tanstack/table-core';\n\nexport * from '@mantine/core';\nexport * from '@mantine/form';\nexport type {FormValidateInput} from '@mantine/form/lib/types';\nexport * from '@mantine/hooks';\n\nexport * from './components';\nexport * from './theme';\n\n// explicitly overriding mantine components\nexport {Header, Table} from './components';\n\ndeclare module '@mantine/core' {\n export interface MantineThemeColorsOverride {\n // eslint-disable-next-line @typescript-eslint/ban-types\n colors: Record<keyof typeof PlasmaColors | (string & {}), Tuple<string, 10>>;\n }\n}\n"],"names":["ColumnDef","createColumnHelper","Header","Table"],"mappings":"AAIA,SAAQA,SAAS,EAAEC,kBAAkB,QAAO,sBAAsB,CAAC;AAEnE,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAE9B,cAAc,gBAAgB,CAAC;AAE/B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AAExB,2CAA2C;AAC3C,SAAQC,MAAM,EAAEC,KAAK,QAAO,cAAc,CAAC"}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import {Tuple} from '@mantine/core';\n\nimport {PlasmaColors} from './theme/PlasmaColors';\n\nexport {type ColumnDef, createColumnHelper} from '@tanstack/table-core';\n\nexport * from '@mantine/core';\nexport * from '@mantine/form';\nexport type {FormValidateInput} from '@mantine/form/lib/types';\nexport * from '@mantine/hooks';\n\nexport * from './components';\nexport * from './theme';\n\n// explicitly overriding mantine components\nexport {Header, Table} from './components';\n\ndeclare module '@mantine/core' {\n export interface MantineThemeColorsOverride {\n // eslint-disable-next-line @typescript-eslint/ban-types\n colors: Record<keyof typeof PlasmaColors | (string & {}), Tuple<string, 10>>;\n }\n}\n"],"names":["createColumnHelper","Header","Table"],"mappings":"AAIA,SAAwBA,kBAAkB,QAAO,sBAAsB,CAAC;AAExE,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAE9B,cAAc,gBAAgB,CAAC;AAE/B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AAExB,2CAA2C;AAC3C,SAAQC,MAAM,EAAEC,KAAK,QAAO,cAAc,CAAC"}
package/jest.config.js CHANGED
@@ -4,7 +4,6 @@ module.exports = {
4
4
  globalSetup: '<rootDir>/src/__tests__/GlobalSetup.ts',
5
5
  moduleNameMapper: {
6
6
  '^@test-utils$': '<rootDir>/src/__tests__/Utils.tsx',
7
- '^monaco-editor$': 'identity-obj-proxy',
8
7
  },
9
8
  testEnvironment: 'jsdom',
10
9
  transform: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coveord/plasma-mantine",
3
- "version": "47.4.0",
3
+ "version": "47.6.0",
4
4
  "description": "A Plasma flavoured Mantine theme",
5
5
  "keywords": [
6
6
  "plasma",
@@ -80,6 +80,7 @@
80
80
  "build": "node ../../scripts/build",
81
81
  "clean": "rimraf dist",
82
82
  "start": "node ../../scripts/start",
83
- "test": "jest --maxWorkers=65%"
83
+ "test": "jest --maxWorkers=65%",
84
+ "test:watch": "jest --watchAll"
84
85
  }
85
86
  }
@@ -2,12 +2,14 @@ import {CheckSize16Px, CopySize16Px} from '@coveord/plasma-react-icons';
2
2
  import {
3
3
  ActionIcon,
4
4
  Box,
5
+ Center,
5
6
  CopyButton,
6
7
  createStyles,
7
8
  DefaultProps,
8
9
  Group,
9
10
  Input,
10
11
  InputWrapperBaseProps,
12
+ Loader,
11
13
  Selectors,
12
14
  Stack,
13
15
  Tooltip,
@@ -15,13 +17,10 @@ import {
15
17
  } from '@mantine/core';
16
18
  import {useUncontrolled} from '@mantine/hooks';
17
19
  import Editor, {loader} from '@monaco-editor/react';
18
- import * as monaco from 'monaco-editor';
19
- import {FunctionComponent} from 'react';
20
+ import {FunctionComponent, useEffect, useState} from 'react';
20
21
 
21
22
  import {useParentHeight} from '../../hooks';
22
23
 
23
- loader.config({monaco});
24
-
25
24
  const useStyles = createStyles((theme) => ({
26
25
  root: {},
27
26
  editor: {
@@ -66,10 +65,18 @@ interface CodeEditorProps
66
65
  */
67
66
  maxHeight?: number;
68
67
  disabled?: boolean;
68
+ /**
69
+ * Defines how the monaco editor files will be loaded.
70
+ * Note that using `'local'` requires [some additional configuration](https://github.com/suren-atoyan/monaco-react#use-monaco-editor-as-an-npm-package).
71
+ *
72
+ * @default 'local'
73
+ */
74
+ monacoLoader?: 'cdn' | 'local';
69
75
  }
70
76
 
71
77
  const defaultProps: Partial<CodeEditorProps> = {
72
78
  language: 'plaintext',
79
+ monacoLoader: 'local',
73
80
  defaultValue: '',
74
81
  minHeight: 300,
75
82
  };
@@ -91,8 +98,10 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
91
98
  minHeight,
92
99
  maxHeight,
93
100
  disabled,
101
+ monacoLoader,
94
102
  ...others
95
103
  } = useComponentDefaultProps('CodeEditor', defaultProps, props);
104
+ const [loaded, setLoaded] = useState(false);
96
105
  const {classes, theme} = useStyles();
97
106
  const [_value, handleChange] = useUncontrolled<string>({
98
107
  value,
@@ -102,6 +111,20 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
102
111
  });
103
112
  const [parentHeight, ref] = useParentHeight();
104
113
 
114
+ const loadLocalMonaco = async () => {
115
+ const monaco = await import('monaco-editor');
116
+ loader.config({monaco});
117
+ setLoaded(true);
118
+ };
119
+
120
+ useEffect(() => {
121
+ if (monacoLoader === 'local') {
122
+ loadLocalMonaco();
123
+ } else {
124
+ setLoaded(true);
125
+ }
126
+ }, []);
127
+
105
128
  const _label = label ? (
106
129
  <Input.Label required={required} {...labelProps}>
107
130
  {label}
@@ -142,7 +165,7 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
142
165
  </Group>
143
166
  );
144
167
 
145
- const _editor = (
168
+ const _editor = loaded ? (
146
169
  <Box p="md" pl="xs" className={classes.editor}>
147
170
  <Editor
148
171
  defaultLanguage={language}
@@ -167,6 +190,10 @@ export const CodeEditor: FunctionComponent<CodeEditorProps> = (props) => {
167
190
  }}
168
191
  />
169
192
  </Box>
193
+ ) : (
194
+ <Center className={classes.editor}>
195
+ <Loader />
196
+ </Center>
170
197
  );
171
198
 
172
199
  return (
@@ -0,0 +1,9 @@
1
+ const editor = {
2
+ create: () => ({
3
+ dispose: (): void => null,
4
+ }),
5
+ };
6
+
7
+ export const monaco = {
8
+ editor,
9
+ };
@@ -1,22 +1,27 @@
1
1
  import {useForm} from '@mantine/form';
2
- import {render, screen, within} from '@test-utils';
2
+ import {loader} from '@monaco-editor/react';
3
+ import {render, screen, waitForElementToBeRemoved, within} from '@test-utils';
3
4
 
4
5
  import {CodeEditor} from '../CodeEditor';
5
6
 
6
- jest.mock('monaco-editor');
7
- jest.mock('@monaco-editor/react');
8
-
9
7
  describe('CodeEditor', () => {
8
+ beforeEach(() => {
9
+ jest.clearAllMocks();
10
+ });
11
+
10
12
  it('renders the monaco editor and a copy to clipboard button', async () => {
13
+ jest.mock('monaco-editor');
11
14
  render(<CodeEditor label="label" description="description" />);
12
15
 
16
+ await waitForElementToBeRemoved(screen.queryByRole('presentation'));
17
+
13
18
  expect(screen.getByText(/label/)).toBeInTheDocument();
14
19
  expect(screen.getByText(/description/)).toBeInTheDocument();
15
20
  expect(screen.getByTestId('monaco-editor')).toBeInTheDocument();
16
21
  expect(await screen.findByRole('button', {name: /copy/i})).toBeInTheDocument();
17
22
  });
18
23
 
19
- it('shows validation errors underneath the code editor', () => {
24
+ it('shows validation errors underneath the code editor', async () => {
20
25
  const Fixture = () => {
21
26
  const form = useForm({
22
27
  initialValues: {
@@ -29,9 +34,23 @@ describe('CodeEditor', () => {
29
34
  return <CodeEditor {...form.getInputProps('myJsonCode')} />;
30
35
  };
31
36
  render(<Fixture />);
37
+ await waitForElementToBeRemoved(screen.queryByRole('presentation'));
32
38
 
33
39
  const errors = screen.getByRole('alert');
34
40
 
35
41
  expect(within(errors).getByText(/invalid configuration/i)).toBeInTheDocument();
36
42
  });
43
+
44
+ it('loads the monaco editor files from node_modules when monacoLoader prop is "local"', async () => {
45
+ render(<CodeEditor label="label" description="description" monacoLoader="local" />);
46
+ await waitForElementToBeRemoved(screen.queryByRole('presentation'));
47
+ expect(loader.config).toHaveBeenCalledTimes(1);
48
+ expect(screen.getByTestId('monaco-editor')).toBeInTheDocument();
49
+ });
50
+
51
+ it('loads the monaco editor files via CDN when monacoLoader prop is "cnd"', async () => {
52
+ render(<CodeEditor label="label" description="description" monacoLoader="cdn" />);
53
+ expect(loader.config).not.toHaveBeenCalled();
54
+ expect(screen.getByTestId('monaco-editor')).toBeInTheDocument();
55
+ });
37
56
  });
@@ -27,6 +27,7 @@ interface CollectionProps<T> extends DefaultProps<Selectors<typeof useStyles>> {
27
27
  onChange?: (value: T[]) => void;
28
28
  draggable?: boolean;
29
29
  disabled?: boolean;
30
+ allowAdd?: (values: T[]) => boolean;
30
31
  addLabel?: string;
31
32
  addDisabledTooltip?: string;
32
33
  spacing?: MantineNumberSize;
@@ -47,7 +48,6 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
47
48
  value,
48
49
  defaultValue,
49
50
  onChange,
50
- onFocus,
51
51
  disabled,
52
52
  draggable,
53
53
  children,
@@ -56,6 +56,7 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
56
56
  newItem,
57
57
  addLabel,
58
58
  addDisabledTooltip,
59
+ allowAdd,
59
60
 
60
61
  // Style props
61
62
  classNames,
@@ -84,17 +85,17 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
84
85
  </CollectionItem>
85
86
  ));
86
87
 
87
- const hasEmptyItem = values.some((item) => JSON.stringify(item) === JSON.stringify(newItem));
88
+ const addAllowed = allowAdd?.(values) ?? true;
88
89
 
89
90
  const _addButton = disabled ? null : (
90
91
  <Group>
91
- <Tooltip label={addDisabledTooltip} disabled={!hasEmptyItem}>
92
+ <Tooltip label={addDisabledTooltip} disabled={addAllowed}>
92
93
  <Box>
93
94
  <Button
94
95
  variant="subtle"
95
96
  leftIcon={<AddSize16Px height={16} />}
96
97
  onClick={() => append(newItem)}
97
- disabled={hasEmptyItem}
98
+ disabled={!addAllowed}
98
99
  >
99
100
  {addLabel}
100
101
  </Button>
@@ -96,12 +96,13 @@ describe('Collection', () => {
96
96
  expect(screen.getByTestId('form-state')).toHaveTextContent('{"fruits":["banana","orange","new"]}');
97
97
  });
98
98
 
99
- it('disallows from adding more than one new item at once', () => {
99
+ it('disables the add button whenever allowAdd callback returns false', () => {
100
+ const allowAdd = jest.fn().mockImplementation(() => false);
100
101
  const Fixture = () => {
101
102
  const form = useForm({initialValues: {fruits: ['banana', 'orange']}});
102
103
  return (
103
104
  <>
104
- <Collection newItem="new" {...form.getInputProps('fruits')}>
105
+ <Collection newItem="new" {...form.getInputProps('fruits')} allowAdd={allowAdd}>
105
106
  {(name) => <span data-testid="item">{name}</span>}
106
107
  </Collection>
107
108
  <div data-testid="form-state">{JSON.stringify(form.values)}</div>
@@ -109,10 +110,13 @@ describe('Collection', () => {
109
110
  );
110
111
  };
111
112
 
112
- render(<Fixture />);
113
- const addItem = screen.getByRole('button', {name: /add/i});
114
- userEvent.click(addItem);
115
- expect(addItem).toBeDisabled();
113
+ const {rerender} = render(<Fixture />);
114
+ expect(screen.getByRole('button', {name: /add/i})).toBeDisabled();
115
+ expect(allowAdd).toHaveBeenCalledWith(['banana', 'orange']);
116
+
117
+ allowAdd.mockImplementation(() => true);
118
+ rerender(<Fixture />);
119
+ expect(screen.getByRole('button', {name: /add/i})).toBeEnabled();
116
120
  });
117
121
 
118
122
  describe('when required is true', () => {
@@ -1 +1,2 @@
1
1
  export * from './ModalWizard';
2
+ export {type ModalWizardStepProps} from './ModalWizardStep';
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@ import {Tuple} from '@mantine/core';
2
2
 
3
3
  import {PlasmaColors} from './theme/PlasmaColors';
4
4
 
5
- export {ColumnDef, createColumnHelper} from '@tanstack/table-core';
5
+ export {type ColumnDef, createColumnHelper} from '@tanstack/table-core';
6
6
 
7
7
  export * from '@mantine/core';
8
8
  export * from '@mantine/form';
package/tsconfig.json CHANGED
@@ -4,8 +4,11 @@
4
4
  "outDir": "./dist",
5
5
  "declarationDir": "./dist/definitions",
6
6
  "rootDir": "src",
7
- "tsBuildInfoFile": "./dist/.tsbuildinfo"
7
+ "tsBuildInfoFile": "./dist/.tsbuildinfo",
8
+ "baseUrl": ".",
9
+ "paths": {
10
+ "@test-utils": ["./src/__tests__/Utils.tsx"]
11
+ }
8
12
  },
9
- "include": ["src"],
10
- "exclude": ["*.spec.*"]
13
+ "include": ["src"]
11
14
  }