@coveord/plasma-mantine 48.28.3 → 49.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/.turbo/turbo-build.log +3 -3
  2. package/.turbo/turbo-test.log +7 -7
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/cjs/components/collection/Collection.js +21 -23
  5. package/dist/cjs/components/collection/Collection.js.map +1 -1
  6. package/dist/cjs/form/FormProvider.js +38 -0
  7. package/dist/cjs/form/FormProvider.js.map +1 -0
  8. package/dist/cjs/form/index.js +9 -0
  9. package/dist/cjs/form/index.js.map +1 -0
  10. package/dist/cjs/form/useForm.js +43 -0
  11. package/dist/cjs/form/useForm.js.map +1 -0
  12. package/dist/cjs/index.js +8 -1
  13. package/dist/cjs/index.js.map +1 -1
  14. package/dist/definitions/components/collection/Collection.d.ts +14 -4
  15. package/dist/definitions/components/collection/Collection.d.ts.map +1 -1
  16. package/dist/definitions/form/FormProvider.d.ts +8 -0
  17. package/dist/definitions/form/FormProvider.d.ts.map +1 -0
  18. package/dist/definitions/form/index.d.ts +3 -0
  19. package/dist/definitions/form/index.d.ts.map +1 -0
  20. package/dist/definitions/form/useForm.d.ts +3 -0
  21. package/dist/definitions/form/useForm.d.ts.map +1 -0
  22. package/dist/definitions/index.d.ts +2 -1
  23. package/dist/definitions/index.d.ts.map +1 -1
  24. package/dist/esm/components/collection/Collection.js +22 -24
  25. package/dist/esm/components/collection/Collection.js.map +1 -1
  26. package/dist/esm/form/FormProvider.js +27 -0
  27. package/dist/esm/form/FormProvider.js.map +1 -0
  28. package/dist/esm/form/index.js +4 -0
  29. package/dist/esm/form/index.js.map +1 -0
  30. package/dist/esm/form/useForm.js +33 -0
  31. package/dist/esm/form/useForm.js.map +1 -0
  32. package/dist/esm/index.js +2 -1
  33. package/dist/esm/index.js.map +1 -1
  34. package/package.json +3 -2
  35. package/src/components/collection/Collection.tsx +32 -19
  36. package/src/components/collection/__tests__/Collection.spec.tsx +1 -1
  37. package/src/form/FormProvider.tsx +38 -0
  38. package/src/form/index.ts +2 -0
  39. package/src/form/useForm.ts +26 -0
  40. package/src/index.ts +3 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/form/FormProvider.tsx"],"sourcesContent":["/* eslint-disable prefer-arrow/prefer-arrow-functions */\nimport {_TransformValues, UseForm, UseFormReturnType} from '@mantine/form/lib/types';\nimport React, {createContext, useContext} from 'react';\n\nimport {useForm} from './useForm';\n\nexport interface FormProviderProps<Form> {\n form: Form;\n children: React.ReactNode;\n}\n\nexport function createFormContext<\n Values,\n TransformValues extends _TransformValues<Values> = (values: Values) => Values\n>() {\n type Form = UseFormReturnType<Values, TransformValues>;\n\n const FormContext = createContext<Form>(null);\n\n function FormProvider({form, children}: FormProviderProps<Form>) {\n return <FormContext.Provider value={form}>{children}</FormContext.Provider>;\n }\n\n function useFormContext() {\n const ctx = useContext(FormContext);\n if (!ctx) {\n throw new Error('useFormContext was called outside of FormProvider context');\n }\n\n return ctx;\n }\n\n return [FormProvider, useFormContext, useForm] as [\n React.FC<FormProviderProps<Form>>,\n () => Form,\n UseForm<Values, TransformValues>\n ];\n}\n"],"names":["React","createContext","useContext","useForm","createFormContext","FormProvider","form","children","FormContext","Provider","value","useFormContext","ctx","Error"],"mappings":"AAAA,sDAAsD,GACtD;AACA,OAAOA,SAAQC,aAAa,EAAEC,UAAU,QAAO,QAAQ;AAEvD,SAAQC,OAAO,QAAO,YAAY;AAOlC,OAAO,SAASC,oBAGZ;QAKSC,eAAT,SAASA,aAAa,KAAyC,EAAE;YAA1CC,OAAD,MAACA,MAAMC,WAAP,MAAOA;QACzB,qBAAO,KAACC,YAAYC,QAAQ;YAACC,OAAOJ;sBAAOC;;IAC/C;QAESI,iBAAT,SAASA,iBAAiB;QACtB,IAAMC,MAAMV,WAAWM;QACvB,IAAI,CAACI,KAAK;YACN,MAAM,IAAIC,MAAM,6DAA6D;QACjF,CAAC;QAED,OAAOD;IACX;IAbA,IAAMJ,4BAAcP,cAAoB,IAAI;IAe5C,OAAO;QAACI;QAAcM;QAAgBR;KAAQ;AAKlD,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./useForm";
2
+ export * from "./FormProvider";
3
+
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/form/index.ts"],"sourcesContent":["export * from './useForm';\nexport * from './FormProvider';\n"],"names":[],"mappings":"AAAA,cAAc,YAAY;AAC1B,cAAc,iBAAiB"}
@@ -0,0 +1,33 @@
1
+ import _object_spread from "@swc/helpers/src/_object_spread.mjs";
2
+ import _object_spread_props from "@swc/helpers/src/_object_spread_props.mjs";
3
+ import { useForm as useMantineForm } from "@mantine/form";
4
+ export var useForm = function(options) {
5
+ var form = useMantineForm(options);
6
+ var getInputProps = function(path) {
7
+ var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, _ref_type = _ref.type, type = _ref_type === void 0 ? "input" : _ref_type, _ref_withError = _ref.withError, withError = _ref_withError === void 0 ? type === "input" : _ref_withError, _ref_withFocus = _ref.withFocus, withFocus = _ref_withFocus === void 0 ? true : _ref_withFocus;
8
+ var originalPayload = form.getInputProps(path, {
9
+ type: type,
10
+ withError: withError,
11
+ withFocus: withFocus
12
+ });
13
+ if (Array.isArray(originalPayload.value)) {
14
+ return _object_spread_props(_object_spread({}, originalPayload), {
15
+ onReorderItem: function(payload) {
16
+ return form.reorderListItem(path, payload);
17
+ },
18
+ onRemoveItem: function(index) {
19
+ return form.removeListItem(path, index);
20
+ },
21
+ onInsertItem: function(valueToInsert, index) {
22
+ return form.insertListItem(path, valueToInsert, index);
23
+ }
24
+ });
25
+ }
26
+ return originalPayload;
27
+ };
28
+ return _object_spread_props(_object_spread({}, form), {
29
+ getInputProps: getInputProps
30
+ });
31
+ };
32
+
33
+ //# sourceMappingURL=useForm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/form/useForm.ts"],"sourcesContent":["import {useForm as useMantineForm} from '@mantine/form';\nimport {GetInputProps} from '@mantine/form/lib/types';\n\nexport const useForm: typeof useMantineForm = (options) => {\n const form = useMantineForm(options);\n\n const getInputProps: GetInputProps<Record<string, unknown>> = (\n path,\n {type = 'input', withError = type === 'input', withFocus = true} = {}\n ) => {\n const originalPayload = form.getInputProps(path, {type, withError, withFocus});\n if (Array.isArray(originalPayload.value)) {\n return {\n ...originalPayload,\n onReorderItem: (payload: Record<'from' | 'to', number>) => form.reorderListItem(path, payload),\n onRemoveItem: (index: number) => form.removeListItem(path, index),\n onInsertItem: (valueToInsert: unknown, index: number) =>\n form.insertListItem(path, valueToInsert, index),\n };\n }\n\n return originalPayload;\n };\n\n return {...form, getInputProps};\n};\n"],"names":["useForm","useMantineForm","options","form","getInputProps","path","type","withError","withFocus","originalPayload","Array","isArray","value","onReorderItem","payload","reorderListItem","onRemoveItem","index","removeListItem","onInsertItem","valueToInsert","insertListItem"],"mappings":"AAAA;;AAAA,SAAQA,WAAWC,cAAc,QAAO,gBAAgB;AAGxD,OAAO,IAAMD,UAAiC,SAACE,SAAY;IACvD,IAAMC,OAAOF,eAAeC;IAE5B,IAAME,gBAAwD,SAC1DC,MAEC;oFADkE,CAAC,oBAAnEC,MAAAA,8BAAO,2CAASC,WAAAA,wCAAYD,SAAS,gDAASE,WAAAA,wCAAY,IAAI;QAE/D,IAAMC,kBAAkBN,KAAKC,aAAa,CAACC,MAAM;YAACC,MAAAA;YAAMC,WAAAA;YAAWC,WAAAA;QAAS;QAC5E,IAAIE,MAAMC,OAAO,CAACF,gBAAgBG,KAAK,GAAG;YACtC,OAAO,wCACAH;gBACHI,eAAe,SAACC;2BAA2CX,KAAKY,eAAe,CAACV,MAAMS;;gBACtFE,cAAc,SAACC;2BAAkBd,KAAKe,cAAc,CAACb,MAAMY;;gBAC3DE,cAAc,SAACC,eAAwBH;2BACnCd,KAAKkB,cAAc,CAAChB,MAAMe,eAAeH;;;QAErD,CAAC;QAED,OAAOR;IACX;IAEA,OAAO,wCAAIN;QAAMC,eAAAA;;AACrB,EAAE"}
package/dist/esm/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  export * from "@mantine/carousel";
2
2
  export * from "@mantine/core";
3
- export * from "@mantine/form";
4
3
  export * from "@mantine/hooks";
5
4
  export { createColumnHelper } from "@tanstack/table-core";
6
5
  export * from "./components";
6
+ export * from "@mantine/form";
7
7
  // explicitly overriding mantine components
8
8
  export { Header, Table, Modal } from "./components";
9
+ export { useForm, createFormContext } from "./form";
9
10
  export * from "./theme";
10
11
 
11
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import {Tuple} from '@mantine/core';\n\nimport {PlasmaColors} from './theme/PlasmaColors';\n\nexport * from '@mantine/carousel';\nexport * from '@mantine/core';\nexport * from '@mantine/form';\nexport type {FormValidateInput} from '@mantine/form/lib/types';\nexport * from '@mantine/hooks';\nexport {createColumnHelper, type ColumnDef} from '@tanstack/table-core';\nexport * from './components';\n// explicitly overriding mantine components\nexport {Header, Table, type HeaderProps, Modal} from './components';\nexport * from './theme';\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","Modal"],"mappings":"AAIA,cAAc,oBAAoB;AAClC,cAAc,gBAAgB;AAC9B,cAAc,gBAAgB;AAE9B,cAAc,iBAAiB;AAC/B,SAAQA,kBAAkB,QAAuB,uBAAuB;AACxE,cAAc,eAAe;AAC7B,2CAA2C;AAC3C,SAAQC,MAAM,EAAEC,KAAK,EAAoBC,KAAK,QAAO,eAAe;AACpE,cAAc,UAAU"}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["import {Tuple} from '@mantine/core';\n\nimport {PlasmaColors} from './theme/PlasmaColors';\n\nexport * from '@mantine/carousel';\nexport * from '@mantine/core';\nexport type {FormValidateInput} from '@mantine/form/lib/types';\nexport * from '@mantine/hooks';\nexport {createColumnHelper, type ColumnDef} from '@tanstack/table-core';\nexport * from './components';\nexport * from '@mantine/form';\n// explicitly overriding mantine components\nexport {Header, Table, type HeaderProps, Modal} from './components';\nexport {useForm, createFormContext} from './form';\n\nexport * from './theme';\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","Modal","useForm","createFormContext"],"mappings":"AAIA,cAAc,oBAAoB;AAClC,cAAc,gBAAgB;AAE9B,cAAc,iBAAiB;AAC/B,SAAQA,kBAAkB,QAAuB,uBAAuB;AACxE,cAAc,eAAe;AAC7B,cAAc,gBAAgB;AAC9B,2CAA2C;AAC3C,SAAQC,MAAM,EAAEC,KAAK,EAAoBC,KAAK,QAAO,eAAe;AACpE,SAAQC,OAAO,EAAEC,iBAAiB,QAAO,SAAS;AAElD,cAAc,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coveord/plasma-mantine",
3
- "version": "48.28.3",
3
+ "version": "49.0.0",
4
4
  "description": "A Plasma flavoured Mantine theme",
5
5
  "keywords": [
6
6
  "plasma",
@@ -77,6 +77,7 @@
77
77
  "clean": "rimraf dist",
78
78
  "start": "node ../../scripts/start",
79
79
  "test": "jest --maxWorkers=65%",
80
- "test:watch": "jest --watchAll"
80
+ "test:watch": "jest --watchAll",
81
+ "test:debug": "node --inspect-brk node_modules/jest/bin/jest --runInBand --watchAll --detectOpenHandles --forceExit"
81
82
  }
82
83
  }
@@ -12,12 +12,13 @@ import {
12
12
  Tooltip,
13
13
  useComponentDefaultProps,
14
14
  } from '@mantine/core';
15
- import {useId} from '@mantine/hooks';
15
+ import {ReorderPayload} from '@mantine/form/lib/types';
16
+ import {useDidUpdate, useId} from '@mantine/hooks';
16
17
  import {ReactNode} from 'react';
17
18
  import {DragDropContext, Droppable} from 'react-beautiful-dnd';
18
- import {useControlledList} from '../../hooks';
19
- import {CollectionItem} from './CollectionItem';
19
+
20
20
  import useStyles from './Collection.styles';
21
+ import {CollectionItem} from './CollectionItem';
21
22
 
22
23
  interface CollectionProps<T>
23
24
  extends Omit<InputWrapperBaseProps, 'inputContainer' | 'inputWrapperOrder'>,
@@ -39,10 +40,6 @@ interface CollectionProps<T>
39
40
  * @default []
40
41
  */
41
42
  value?: T[];
42
- /**
43
- * The initial items of the collection (for uncontrolled usage only)
44
- */
45
- defaultValue?: T[];
46
43
  /**
47
44
  * Unused, has no effect
48
45
  */
@@ -59,6 +56,19 @@ interface CollectionProps<T>
59
56
  * @param itemIndex The index of the item that was removed
60
57
  */
61
58
  onRemoveItem?: (itemIndex: number) => void;
59
+ /**
60
+ * Function that gets called whenever a collection item needs to be reordered
61
+ *
62
+ * @param payload The origin and destination index of the item to reorder
63
+ */
64
+ onReorderItem?: (payload: ReorderPayload) => void;
65
+ /**
66
+ * Function that gets called when a new item needs to be added to the collection
67
+ *
68
+ * @param value The the value of the item to insert
69
+ * @param index The index of the new item to insert
70
+ */
71
+ onInsertItem?: (value: T, index: number) => void;
62
72
  /**
63
73
  * Whether the collection should have drag and drop behavior enabled
64
74
  *
@@ -116,9 +126,10 @@ const defaultProps: Partial<CollectionProps<unknown>> = {
116
126
  export const Collection = <T,>(props: CollectionProps<T>) => {
117
127
  const {
118
128
  value,
119
- defaultValue,
120
129
  onChange,
121
130
  onRemoveItem,
131
+ onReorderItem,
132
+ onInsertItem,
122
133
  disabled,
123
134
  draggable,
124
135
  children,
@@ -146,12 +157,14 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
146
157
  const {classes, cx} = useStyles(null, {classNames, name: 'Collection', styles, unstyled});
147
158
  const collectionID = useId('dnd-droppable');
148
159
 
149
- const [values, {append, remove, reorder}] = useControlledList({value, onChange, defaultValue});
150
- const hasOnlyOneItem = values.length === 1;
151
- const removeItem = (index: number) => () => {
152
- remove(index);
153
- onRemoveItem?.(index);
154
- };
160
+ const hasOnlyOneItem = value.length === 1;
161
+
162
+ /**
163
+ * Enforcing onChange when the value is modified will make sure the errors are carried through.
164
+ */
165
+ useDidUpdate(() => {
166
+ onChange?.(value);
167
+ }, [JSON.stringify(value)]);
155
168
 
156
169
  const _label = label ? (
157
170
  <Input.Label required={required} {...labelProps}>
@@ -171,13 +184,13 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
171
184
  </Box>
172
185
  ) : null;
173
186
 
174
- const items = values.map((item, index) => (
187
+ const items = value.map((item, index) => (
175
188
  <CollectionItem
176
189
  key={index}
177
190
  disabled={disabled}
178
191
  draggable={draggable}
179
192
  index={index}
180
- onRemove={removeItem(index)}
193
+ onRemove={() => onRemoveItem?.(index)}
181
194
  styles={styles}
182
195
  removable={!(required && hasOnlyOneItem)}
183
196
  >
@@ -185,7 +198,7 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
185
198
  </CollectionItem>
186
199
  ));
187
200
 
188
- const addAllowed = allowAdd?.(values) ?? true;
201
+ const addAllowed = allowAdd?.(value) ?? true;
189
202
 
190
203
  const _addButton = disabled ? null : (
191
204
  <Group>
@@ -194,7 +207,7 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
194
207
  <Button
195
208
  variant="subtle"
196
209
  leftIcon={<AddSize16Px height={16} />}
197
- onClick={() => append(newItem)}
210
+ onClick={() => onInsertItem(newItem, value?.length ?? 0)}
198
211
  disabled={!addAllowed}
199
212
  >
200
213
  {addLabel}
@@ -206,7 +219,7 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
206
219
 
207
220
  return (
208
221
  <DragDropContext
209
- onDragEnd={({destination, source}) => reorder({from: source.index, to: destination?.index || 0})}
222
+ onDragEnd={({destination, source}) => onReorderItem({from: source.index, to: destination?.index || 0})}
210
223
  >
211
224
  <Droppable direction="vertical" droppableId={collectionID}>
212
225
  {(provided) => (
@@ -1,7 +1,7 @@
1
- import {useForm} from '@mantine/form';
2
1
  import {render, screen, userEvent, within} from '@test-utils';
3
2
  import {useState} from 'react';
4
3
 
4
+ import {useForm} from '../../../form';
5
5
  import {Collection} from '../Collection';
6
6
 
7
7
  describe('Collection', () => {
@@ -0,0 +1,38 @@
1
+ /* eslint-disable prefer-arrow/prefer-arrow-functions */
2
+ import {_TransformValues, UseForm, UseFormReturnType} from '@mantine/form/lib/types';
3
+ import React, {createContext, useContext} from 'react';
4
+
5
+ import {useForm} from './useForm';
6
+
7
+ export interface FormProviderProps<Form> {
8
+ form: Form;
9
+ children: React.ReactNode;
10
+ }
11
+
12
+ export function createFormContext<
13
+ Values,
14
+ TransformValues extends _TransformValues<Values> = (values: Values) => Values
15
+ >() {
16
+ type Form = UseFormReturnType<Values, TransformValues>;
17
+
18
+ const FormContext = createContext<Form>(null);
19
+
20
+ function FormProvider({form, children}: FormProviderProps<Form>) {
21
+ return <FormContext.Provider value={form}>{children}</FormContext.Provider>;
22
+ }
23
+
24
+ function useFormContext() {
25
+ const ctx = useContext(FormContext);
26
+ if (!ctx) {
27
+ throw new Error('useFormContext was called outside of FormProvider context');
28
+ }
29
+
30
+ return ctx;
31
+ }
32
+
33
+ return [FormProvider, useFormContext, useForm] as [
34
+ React.FC<FormProviderProps<Form>>,
35
+ () => Form,
36
+ UseForm<Values, TransformValues>
37
+ ];
38
+ }
@@ -0,0 +1,2 @@
1
+ export * from './useForm';
2
+ export * from './FormProvider';
@@ -0,0 +1,26 @@
1
+ import {useForm as useMantineForm} from '@mantine/form';
2
+ import {GetInputProps} from '@mantine/form/lib/types';
3
+
4
+ export const useForm: typeof useMantineForm = (options) => {
5
+ const form = useMantineForm(options);
6
+
7
+ const getInputProps: GetInputProps<Record<string, unknown>> = (
8
+ path,
9
+ {type = 'input', withError = type === 'input', withFocus = true} = {}
10
+ ) => {
11
+ const originalPayload = form.getInputProps(path, {type, withError, withFocus});
12
+ if (Array.isArray(originalPayload.value)) {
13
+ return {
14
+ ...originalPayload,
15
+ onReorderItem: (payload: Record<'from' | 'to', number>) => form.reorderListItem(path, payload),
16
+ onRemoveItem: (index: number) => form.removeListItem(path, index),
17
+ onInsertItem: (valueToInsert: unknown, index: number) =>
18
+ form.insertListItem(path, valueToInsert, index),
19
+ };
20
+ }
21
+
22
+ return originalPayload;
23
+ };
24
+
25
+ return {...form, getInputProps};
26
+ };
package/src/index.ts CHANGED
@@ -4,13 +4,15 @@ import {PlasmaColors} from './theme/PlasmaColors';
4
4
 
5
5
  export * from '@mantine/carousel';
6
6
  export * from '@mantine/core';
7
- export * from '@mantine/form';
8
7
  export type {FormValidateInput} from '@mantine/form/lib/types';
9
8
  export * from '@mantine/hooks';
10
9
  export {createColumnHelper, type ColumnDef} from '@tanstack/table-core';
11
10
  export * from './components';
11
+ export * from '@mantine/form';
12
12
  // explicitly overriding mantine components
13
13
  export {Header, Table, type HeaderProps, Modal} from './components';
14
+ export {useForm, createFormContext} from './form';
15
+
14
16
  export * from './theme';
15
17
 
16
18
  declare module '@mantine/core' {