@zakodium/nmrium-core-plugins-ui 0.1.2 → 0.1.4
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/lib/plugins/spectrum_1d_processings_ui/operators/zero_filling.d.ts.map +1 -1
- package/lib/plugins/spectrum_1d_processings_ui/operators/zero_filling.js +2 -30
- package/lib/plugins/spectrum_1d_processings_ui/operators/zero_filling.js.map +1 -1
- package/lib/plugins/spectrum_1d_processings_ui/operators/zero_filling_expand.d.ts +3 -0
- package/lib/plugins/spectrum_1d_processings_ui/operators/zero_filling_expand.d.ts.map +1 -0
- package/lib/plugins/spectrum_1d_processings_ui/operators/zero_filling_expand.js +54 -0
- package/lib/plugins/spectrum_1d_processings_ui/operators/zero_filling_expand.js.map +1 -0
- package/package.json +5 -4
- package/src/plugins/spectrum_1d_processings_ui/operators/zero_filling.tsx +2 -50
- package/src/plugins/spectrum_1d_processings_ui/operators/zero_filling_expand.tsx +90 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zero_filling.d.ts","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/zero_filling.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zero_filling.d.ts","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/zero_filling.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa,qGAKxB,CAAC"}
|
|
@@ -1,37 +1,9 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
1
|
import { defineProcessingOperatorUI } from '@zakodium/nmrium-core';
|
|
3
|
-
import {
|
|
4
|
-
const options = [
|
|
5
|
-
{ label: '256', value: 2 ** 8 },
|
|
6
|
-
{ label: '512', value: 2 ** 9 },
|
|
7
|
-
{ label: '1K', value: 2 ** 10 },
|
|
8
|
-
{ label: '2K', value: 2 ** 11 },
|
|
9
|
-
{ label: '4K', value: 2 ** 12 },
|
|
10
|
-
{ label: '8K', value: 2 ** 13 },
|
|
11
|
-
{ label: '16K', value: 2 ** 14 },
|
|
12
|
-
{ label: '32K', value: 2 ** 15 },
|
|
13
|
-
{ label: '64K', value: 2 ** 16 },
|
|
14
|
-
{ label: '128K', value: 2 ** 17 },
|
|
15
|
-
{ label: '256K', value: 2 ** 18 },
|
|
16
|
-
{ label: '512K', value: 2 ** 19 },
|
|
17
|
-
{ label: '1M', value: 2 ** 20 },
|
|
18
|
-
{ label: '2M', value: 2 ** 21 },
|
|
19
|
-
];
|
|
2
|
+
import { ZeroFillingExpand } from "./zero_filling_expand.js";
|
|
20
3
|
export const zeroFilling1D = defineProcessingOperatorUI({
|
|
21
4
|
id: '@zakodium/nmrium-core-plugins#zeroFilling1D',
|
|
22
5
|
name: 'Zero filling',
|
|
23
6
|
isEditable: true,
|
|
24
|
-
Expanded
|
|
25
|
-
const { operation } = props;
|
|
26
|
-
const { settings } = operation;
|
|
27
|
-
const validOptions = useMemo(() => {
|
|
28
|
-
if (options.some((o) => o.value === settings))
|
|
29
|
-
return options;
|
|
30
|
-
return options
|
|
31
|
-
.concat({ label: String(settings), value: settings })
|
|
32
|
-
.toSorted((a, b) => a.value - b.value);
|
|
33
|
-
}, [settings]);
|
|
34
|
-
return (_jsxs(_Fragment, { children: ["Size:", ' ', _jsx("select", { children: validOptions.map((o) => (_jsx("option", { value: o.value, selected: o.value === settings, children: o.label }, o.value))) })] }));
|
|
35
|
-
},
|
|
7
|
+
Expanded: ZeroFillingExpand,
|
|
36
8
|
});
|
|
37
9
|
//# sourceMappingURL=zero_filling.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zero_filling.js","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/zero_filling.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zero_filling.js","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/zero_filling.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA2B,CAAC;AAE9D,MAAM,CAAC,MAAM,aAAa,GAAG,0BAA0B,CAAC;IACtD,EAAE,EAAE,6CAA6C;IACjD,IAAI,EAAE,cAAc;IACpB,UAAU,EAAE,IAAI;IAChB,QAAQ,EAAE,iBAAiB;CAC5B,CAAC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ProcessingOperatorUIExpandedProps } from '@zakodium/nmrium-core';
|
|
2
|
+
export declare function ZeroFillingExpand(props: ProcessingOperatorUIExpandedProps<'@zakodium/nmrium-core-plugins#zeroFilling1D'>): import("react").JSX.Element;
|
|
3
|
+
//# sourceMappingURL=zero_filling_expand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zero_filling_expand.d.ts","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/zero_filling_expand.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,uBAAuB,CAAC;AAuB/E,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,iCAAiC,CAAC,6CAA6C,CAAC,+BAgExF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { revalidateLogic } from '@tanstack/react-form';
|
|
3
|
+
import { assert, cast } from '@zakodium/utils';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import { AppForm, useForm } from 'react-science/ui';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
const options = [
|
|
8
|
+
{ label: '256', value: 2 ** 8 },
|
|
9
|
+
{ label: '512', value: 2 ** 9 },
|
|
10
|
+
{ label: '1K', value: 2 ** 10 },
|
|
11
|
+
{ label: '2K', value: 2 ** 11 },
|
|
12
|
+
{ label: '4K', value: 2 ** 12 },
|
|
13
|
+
{ label: '8K', value: 2 ** 13 },
|
|
14
|
+
{ label: '16K', value: 2 ** 14 },
|
|
15
|
+
{ label: '32K', value: 2 ** 15 },
|
|
16
|
+
{ label: '64K', value: 2 ** 16 },
|
|
17
|
+
{ label: '128K', value: 2 ** 17 },
|
|
18
|
+
{ label: '256K', value: 2 ** 18 },
|
|
19
|
+
{ label: '512K', value: 2 ** 19 },
|
|
20
|
+
{ label: '1M', value: 2 ** 20 },
|
|
21
|
+
{ label: '2M', value: 2 ** 21 },
|
|
22
|
+
];
|
|
23
|
+
export function ZeroFillingExpand(props) {
|
|
24
|
+
const { operation, onChange, core, children } = props;
|
|
25
|
+
cast(operation.operatorId);
|
|
26
|
+
const operator = core.getOperator(operation.operatorId);
|
|
27
|
+
assert(operator, () => `Operator ${operation.operatorId} related to operation ${JSON.stringify(operation)} is missing`);
|
|
28
|
+
const validator = useMemo(() => z.object({
|
|
29
|
+
size: operator.schemaSettings,
|
|
30
|
+
}), [operator]);
|
|
31
|
+
const defaultValues = useMemo(() => ({ size: operation.settings }), [operation.settings]);
|
|
32
|
+
const form = useForm({
|
|
33
|
+
defaultValues,
|
|
34
|
+
validators: { onDynamic: validator },
|
|
35
|
+
validationLogic: revalidateLogic(),
|
|
36
|
+
onSubmit: ({ value }) => {
|
|
37
|
+
if (!onChange)
|
|
38
|
+
return;
|
|
39
|
+
const { size: settings } = validator.parse(value);
|
|
40
|
+
onChange({ ...operation, settings });
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
const allOptions = useMemo(() => {
|
|
44
|
+
const settings = operation.settings;
|
|
45
|
+
if (options.some((o) => o.value === settings))
|
|
46
|
+
return options;
|
|
47
|
+
return [...options, { label: String(settings), value: settings }].toSorted((a, b) => a.value - b.value);
|
|
48
|
+
}, [operation.settings]);
|
|
49
|
+
const { AppField, SubmitButton } = form;
|
|
50
|
+
return (_jsxs(AppForm, { form: form, layout: "inline", children: [children?.(_jsx(SubmitButton, { variant: "outlined", size: "small", intent: "success", children: "Apply" })), _jsx(AppField, { name: "size", children: ({ Select }) => (_jsx(Select, { label: "Size",
|
|
51
|
+
// @ts-expect-error should support number values
|
|
52
|
+
items: allOptions })) })] }));
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=zero_filling_expand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zero_filling_expand.js","sourceRoot":"","sources":["../../../../src/plugins/spectrum_1d_processings_ui/operators/zero_filling_expand.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,OAAO,GAAG;IACd,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE;IAC/B,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE;IAC/B,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;IAC/B,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;IAC/B,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;IAC/B,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;IAC/B,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;IAChC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;I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,KAAK,EAAC,MAAM;oBACZ,gDAAgD;oBAChD,KAAK,EAAE,UAAU,GACjB,CACH,GACQ,IACH,CACX,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zakodium/nmrium-core-plugins-ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"license": "CC-BY-NC-SA-4.0",
|
|
5
5
|
"description": "UI related plugins needed for cheminfo/nmrium",
|
|
6
6
|
"keywords": [],
|
|
@@ -26,8 +26,9 @@
|
|
|
26
26
|
"@blueprintjs/core": "^6.16.0",
|
|
27
27
|
"@blueprintjs/icons": "^6.11.0",
|
|
28
28
|
"@blueprintjs/select": "^6.3.0",
|
|
29
|
-
"@
|
|
30
|
-
"@zakodium/nmrium-core
|
|
29
|
+
"@tanstack/react-form": "^1.33.0",
|
|
30
|
+
"@zakodium/nmrium-core": "^0.7.36",
|
|
31
|
+
"@zakodium/nmrium-core-plugins": "^0.7.46",
|
|
31
32
|
"fifo-logger": "^2.0.1",
|
|
32
33
|
"react": "^18.3.1",
|
|
33
34
|
"react-dom": "^18.3.1",
|
|
@@ -41,5 +42,5 @@
|
|
|
41
42
|
"typescript": "~6.0.3",
|
|
42
43
|
"vitest": "^4.1.9"
|
|
43
44
|
},
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "b72b67fce506ea7ccd740a536bf4a8e9a4245a1d"
|
|
45
46
|
}
|
|
@@ -1,58 +1,10 @@
|
|
|
1
1
|
import { defineProcessingOperatorUI } from '@zakodium/nmrium-core';
|
|
2
|
-
import { useMemo } from 'react';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
label: string;
|
|
6
|
-
value: number;
|
|
7
|
-
}
|
|
8
|
-
const options: Option[] = [
|
|
9
|
-
{ label: '256', value: 2 ** 8 },
|
|
10
|
-
{ label: '512', value: 2 ** 9 },
|
|
11
|
-
{ label: '1K', value: 2 ** 10 },
|
|
12
|
-
{ label: '2K', value: 2 ** 11 },
|
|
13
|
-
{ label: '4K', value: 2 ** 12 },
|
|
14
|
-
{ label: '8K', value: 2 ** 13 },
|
|
15
|
-
{ label: '16K', value: 2 ** 14 },
|
|
16
|
-
{ label: '32K', value: 2 ** 15 },
|
|
17
|
-
{ label: '64K', value: 2 ** 16 },
|
|
18
|
-
{ label: '128K', value: 2 ** 17 },
|
|
19
|
-
{ label: '256K', value: 2 ** 18 },
|
|
20
|
-
{ label: '512K', value: 2 ** 19 },
|
|
21
|
-
{ label: '1M', value: 2 ** 20 },
|
|
22
|
-
{ label: '2M', value: 2 ** 21 },
|
|
23
|
-
];
|
|
3
|
+
import { ZeroFillingExpand } from './zero_filling_expand.tsx';
|
|
24
4
|
|
|
25
5
|
export const zeroFilling1D = defineProcessingOperatorUI({
|
|
26
6
|
id: '@zakodium/nmrium-core-plugins#zeroFilling1D',
|
|
27
7
|
name: 'Zero filling',
|
|
28
8
|
isEditable: true,
|
|
29
|
-
Expanded
|
|
30
|
-
const { operation } = props;
|
|
31
|
-
const { settings } = operation;
|
|
32
|
-
|
|
33
|
-
const validOptions = useMemo(() => {
|
|
34
|
-
if (options.some((o) => o.value === settings)) return options;
|
|
35
|
-
|
|
36
|
-
return options
|
|
37
|
-
.concat({ label: String(settings), value: settings })
|
|
38
|
-
.toSorted((a, b) => a.value - b.value);
|
|
39
|
-
}, [settings]);
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<>
|
|
43
|
-
Size:{' '}
|
|
44
|
-
<select>
|
|
45
|
-
{validOptions.map((o) => (
|
|
46
|
-
<option
|
|
47
|
-
key={o.value}
|
|
48
|
-
value={o.value}
|
|
49
|
-
selected={o.value === settings}
|
|
50
|
-
>
|
|
51
|
-
{o.label}
|
|
52
|
-
</option>
|
|
53
|
-
))}
|
|
54
|
-
</select>
|
|
55
|
-
</>
|
|
56
|
-
);
|
|
57
|
-
},
|
|
9
|
+
Expanded: ZeroFillingExpand,
|
|
58
10
|
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { revalidateLogic } from '@tanstack/react-form';
|
|
2
|
+
import type { ProcessingOperatorUIExpandedProps } from '@zakodium/nmrium-core';
|
|
3
|
+
import { assert, cast } from '@zakodium/utils';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import { AppForm, useForm } from 'react-science/ui';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
|
|
8
|
+
const options = [
|
|
9
|
+
{ label: '256', value: 2 ** 8 },
|
|
10
|
+
{ label: '512', value: 2 ** 9 },
|
|
11
|
+
{ label: '1K', value: 2 ** 10 },
|
|
12
|
+
{ label: '2K', value: 2 ** 11 },
|
|
13
|
+
{ label: '4K', value: 2 ** 12 },
|
|
14
|
+
{ label: '8K', value: 2 ** 13 },
|
|
15
|
+
{ label: '16K', value: 2 ** 14 },
|
|
16
|
+
{ label: '32K', value: 2 ** 15 },
|
|
17
|
+
{ label: '64K', value: 2 ** 16 },
|
|
18
|
+
{ label: '128K', value: 2 ** 17 },
|
|
19
|
+
{ label: '256K', value: 2 ** 18 },
|
|
20
|
+
{ label: '512K', value: 2 ** 19 },
|
|
21
|
+
{ label: '1M', value: 2 ** 20 },
|
|
22
|
+
{ label: '2M', value: 2 ** 21 },
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export function ZeroFillingExpand(
|
|
26
|
+
props: ProcessingOperatorUIExpandedProps<'@zakodium/nmrium-core-plugins#zeroFilling1D'>,
|
|
27
|
+
) {
|
|
28
|
+
const { operation, onChange, core, children } = props;
|
|
29
|
+
cast<'@zakodium/nmrium-core-plugins#zeroFilling1D'>(operation.operatorId);
|
|
30
|
+
const operator = core.getOperator(operation.operatorId);
|
|
31
|
+
assert(
|
|
32
|
+
operator,
|
|
33
|
+
() =>
|
|
34
|
+
`Operator ${operation.operatorId} related to operation ${JSON.stringify(operation)} is missing`,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const validator = useMemo(
|
|
38
|
+
() =>
|
|
39
|
+
z.object({
|
|
40
|
+
size: operator.schemaSettings,
|
|
41
|
+
}),
|
|
42
|
+
[operator],
|
|
43
|
+
);
|
|
44
|
+
const defaultValues = useMemo(
|
|
45
|
+
() => ({ size: operation.settings }),
|
|
46
|
+
[operation.settings],
|
|
47
|
+
);
|
|
48
|
+
const form = useForm({
|
|
49
|
+
defaultValues,
|
|
50
|
+
validators: { onDynamic: validator },
|
|
51
|
+
validationLogic: revalidateLogic(),
|
|
52
|
+
onSubmit: ({ value }) => {
|
|
53
|
+
if (!onChange) return;
|
|
54
|
+
|
|
55
|
+
const { size: settings } = validator.parse(value);
|
|
56
|
+
onChange({ ...operation, settings });
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const allOptions = useMemo(() => {
|
|
61
|
+
const settings = operation.settings;
|
|
62
|
+
if (options.some((o) => o.value === settings)) return options;
|
|
63
|
+
|
|
64
|
+
return [...options, { label: String(settings), value: settings }].toSorted(
|
|
65
|
+
(a, b) => a.value - b.value,
|
|
66
|
+
);
|
|
67
|
+
}, [operation.settings]);
|
|
68
|
+
|
|
69
|
+
const { AppField, SubmitButton } = form;
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<AppForm form={form} layout="inline">
|
|
73
|
+
{children?.(
|
|
74
|
+
<SubmitButton variant="outlined" size="small" intent="success">
|
|
75
|
+
Apply
|
|
76
|
+
</SubmitButton>,
|
|
77
|
+
)}
|
|
78
|
+
|
|
79
|
+
<AppField name="size">
|
|
80
|
+
{({ Select }) => (
|
|
81
|
+
<Select
|
|
82
|
+
label="Size"
|
|
83
|
+
// @ts-expect-error should support number values
|
|
84
|
+
items={allOptions}
|
|
85
|
+
/>
|
|
86
|
+
)}
|
|
87
|
+
</AppField>
|
|
88
|
+
</AppForm>
|
|
89
|
+
);
|
|
90
|
+
}
|