mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-09-24 04:26:14 +00:00
Compare commits
No commits in common. "ba6c8a30a5bc98d811f0e9ddaf683d67224f3309" and "9c31d5599cdc3eaee8f79969881fb6d04901252a" have entirely different histories.
ba6c8a30a5
...
9c31d5599c
@ -683,76 +683,7 @@
|
|||||||
"8": "Document #6: Page 10"
|
"8": "Document #6: Page 10"
|
||||||
},
|
},
|
||||||
"splitPages": "Enter pages to split on:",
|
"splitPages": "Enter pages to split on:",
|
||||||
"submit": "Split",
|
"submit": "Split"
|
||||||
"error": {
|
|
||||||
"failed": "An error occurred while splitting the PDF."
|
|
||||||
},
|
|
||||||
"method": {
|
|
||||||
"label": "Choose split method",
|
|
||||||
"placeholder": "Select how to split the PDF"
|
|
||||||
},
|
|
||||||
"methods": {
|
|
||||||
"byPages": "Split at Page Numbers",
|
|
||||||
"bySections": "Split by Sections",
|
|
||||||
"bySize": "Split by File Size",
|
|
||||||
"byPageCount": "Split by Page Count",
|
|
||||||
"byDocCount": "Split by Document Count",
|
|
||||||
"byChapters": "Split by Chapters"
|
|
||||||
},
|
|
||||||
"value": {
|
|
||||||
"fileSize": {
|
|
||||||
"label": "File Size",
|
|
||||||
"placeholder": "e.g. 10MB, 500KB"
|
|
||||||
},
|
|
||||||
"pageCount": {
|
|
||||||
"label": "Pages per File",
|
|
||||||
"placeholder": "e.g. 5, 10"
|
|
||||||
},
|
|
||||||
"docCount": {
|
|
||||||
"label": "Number of Files",
|
|
||||||
"placeholder": "e.g. 3, 5"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"tooltip": {
|
|
||||||
"header": {
|
|
||||||
"title": "Split Methods Overview"
|
|
||||||
},
|
|
||||||
"byPages": {
|
|
||||||
"title": "Split at Page Numbers",
|
|
||||||
"text": "Split your PDF at specific page numbers. Using 'n' splits after page n. Using 'n-m' splits before page n and after page m.",
|
|
||||||
"bullet1": "Single split points: 3,7 (splits after pages 3 and 7)",
|
|
||||||
"bullet2": "Range split points: 3-8 (splits before page 3 and after page 8)",
|
|
||||||
"bullet3": "Mixed: 2,5-10,15 (splits after page 2, before page 5, after page 10, and after page 15)"
|
|
||||||
},
|
|
||||||
"bySections": {
|
|
||||||
"title": "Split by Grid Sections",
|
|
||||||
"text": "Divide each page into a grid of sections. Useful for splitting documents with multiple columns or extracting specific areas.",
|
|
||||||
"bullet1": "Horizontal: Number of rows to create",
|
|
||||||
"bullet2": "Vertical: Number of columns to create",
|
|
||||||
"bullet3": "Merge: Combine all sections into one PDF"
|
|
||||||
},
|
|
||||||
"bySize": {
|
|
||||||
"title": "Split by File Size",
|
|
||||||
"text": "Create multiple PDFs that don't exceed a specified file size. Ideal for file size limitations or email attachments.",
|
|
||||||
"bullet1": "Use MB for larger files (e.g., 10MB)",
|
|
||||||
"bullet2": "Use KB for smaller files (e.g., 500KB)",
|
|
||||||
"bullet3": "System will split at page boundaries"
|
|
||||||
},
|
|
||||||
"byCount": {
|
|
||||||
"title": "Split by Count",
|
|
||||||
"text": "Create multiple PDFs with a specific number of pages or documents each.",
|
|
||||||
"bullet1": "Page Count: Fixed number of pages per file",
|
|
||||||
"bullet2": "Document Count: Fixed number of output files",
|
|
||||||
"bullet3": "Useful for batch processing workflows"
|
|
||||||
},
|
|
||||||
"byChapters": {
|
|
||||||
"title": "Split by Chapters",
|
|
||||||
"text": "Use PDF bookmarks to automatically split at chapter boundaries. Requires PDFs with bookmark structure.",
|
|
||||||
"bullet1": "Bookmark Level: Which level to split on (1=top level)",
|
|
||||||
"bullet2": "Include Metadata: Preserve document properties",
|
|
||||||
"bullet3": "Allow Duplicates: Handle repeated bookmark names"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"rotate": {
|
"rotate": {
|
||||||
"tags": "server side",
|
"tags": "server side",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Stack, TextInput, Select, Checkbox } from '@mantine/core';
|
import { Stack, TextInput, Select, Checkbox } from '@mantine/core';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { isSplitMethod, SPLIT_METHODS } from '../../../constants/splitConstants';
|
import { isSplitMode, isSplitType, SPLIT_MODES, SPLIT_TYPES } from '../../../constants/splitConstants';
|
||||||
import { SplitParameters } from '../../../hooks/tools/split/useSplitParameters';
|
import { SplitParameters } from '../../../hooks/tools/split/useSplitParameters';
|
||||||
|
|
||||||
export interface SplitSettingsProps {
|
export interface SplitSettingsProps {
|
||||||
@ -57,37 +57,28 @@ const SplitSettings = ({
|
|||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderSplitValueForm = () => {
|
const renderBySizeOrCountForm = () => (
|
||||||
let label, placeholder;
|
<Stack gap="sm">
|
||||||
|
<Select
|
||||||
switch (parameters.method) {
|
label={t("split-by-size-or-count.type.label", "Split Type")}
|
||||||
case SPLIT_METHODS.BY_SIZE:
|
value={parameters.splitType}
|
||||||
label = t("split.value.fileSize.label", "File Size");
|
onChange={(v) => isSplitType(v) && onParameterChange('splitType', v)}
|
||||||
placeholder = t("split.value.fileSize.placeholder", "e.g. 10MB, 500KB");
|
disabled={disabled}
|
||||||
break;
|
data={[
|
||||||
case SPLIT_METHODS.BY_PAGE_COUNT:
|
{ value: SPLIT_TYPES.SIZE, label: t("split-by-size-or-count.type.size", "By Size") },
|
||||||
label = t("split.value.pageCount.label", "Pages per File");
|
{ value: SPLIT_TYPES.PAGES, label: t("split-by-size-or-count.type.pageCount", "By Page Count") },
|
||||||
placeholder = t("split.value.pageCount.placeholder", "e.g. 5, 10");
|
{ value: SPLIT_TYPES.DOCS, label: t("split-by-size-or-count.type.docCount", "By Document Count") },
|
||||||
break;
|
]}
|
||||||
case SPLIT_METHODS.BY_DOC_COUNT:
|
/>
|
||||||
label = t("split.value.docCount.label", "Number of Files");
|
|
||||||
placeholder = t("split.value.docCount.placeholder", "e.g. 3, 5");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
label = t("split-by-size-or-count.value.label", "Split Value");
|
|
||||||
placeholder = t("split-by-size-or-count.value.placeholder", "e.g. 10MB or 5 pages");
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<TextInput
|
<TextInput
|
||||||
label={label}
|
label={t("split-by-size-or-count.value.label", "Split Value")}
|
||||||
placeholder={placeholder}
|
placeholder={t("split-by-size-or-count.value.placeholder", "e.g. 10MB or 5 pages")}
|
||||||
value={parameters.splitValue}
|
value={parameters.splitValue}
|
||||||
onChange={(e) => onParameterChange('splitValue', e.target.value)}
|
onChange={(e) => onParameterChange('splitValue', e.target.value)}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
const renderByChaptersForm = () => (
|
const renderByChaptersForm = () => (
|
||||||
<Stack gap="sm">
|
<Stack gap="sm">
|
||||||
@ -115,30 +106,26 @@ const SplitSettings = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap="md">
|
<Stack gap="md">
|
||||||
{/* Method Selector */}
|
{/* Mode Selector */}
|
||||||
<Select
|
<Select
|
||||||
label={t("split.method.label", "Choose split method")}
|
label="Choose split method"
|
||||||
placeholder={t("split.method.placeholder", "Select how to split the PDF")}
|
placeholder="Select how to split the PDF"
|
||||||
value={parameters.method}
|
value={parameters.mode}
|
||||||
onChange={(v) => isSplitMethod(v) && onParameterChange('method', v)}
|
onChange={(v) => isSplitMode(v) && onParameterChange('mode', v)}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
data={[
|
data={[
|
||||||
{ value: SPLIT_METHODS.BY_PAGES, label: t("split.methods.byPages", "Split at Pages Numbers") },
|
{ value: SPLIT_MODES.BY_PAGES, label: t("split.header", "Split by Pages") + " (e.g. 1,3,5-10)" },
|
||||||
{ value: SPLIT_METHODS.BY_SECTIONS, label: t("split.methods.bySections", "Split by Sections") },
|
{ value: SPLIT_MODES.BY_SECTIONS, label: t("split-by-sections.title", "Split by Grid Sections") },
|
||||||
{ value: SPLIT_METHODS.BY_SIZE, label: t("split.methods.bySize", "Split by Size") },
|
{ value: SPLIT_MODES.BY_SIZE_OR_COUNT, label: t("split-by-size-or-count.title", "Split by Size or Count") },
|
||||||
{ value: SPLIT_METHODS.BY_PAGE_COUNT, label: t("split.methods.byPageCount", "Split by Page Count") },
|
{ value: SPLIT_MODES.BY_CHAPTERS, label: t("splitByChapters.title", "Split by Chapters") },
|
||||||
{ value: SPLIT_METHODS.BY_DOC_COUNT, label: t("split.methods.byDocCount", "Split by Document Count") },
|
|
||||||
{ value: SPLIT_METHODS.BY_CHAPTERS, label: t("split.methods.byChapters", "Split by Chapters") },
|
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Parameter Form */}
|
{/* Parameter Form */}
|
||||||
{parameters.method === SPLIT_METHODS.BY_PAGES && renderByPagesForm()}
|
{parameters.mode === SPLIT_MODES.BY_PAGES && renderByPagesForm()}
|
||||||
{parameters.method === SPLIT_METHODS.BY_SECTIONS && renderBySectionsForm()}
|
{parameters.mode === SPLIT_MODES.BY_SECTIONS && renderBySectionsForm()}
|
||||||
{(parameters.method === SPLIT_METHODS.BY_SIZE ||
|
{parameters.mode === SPLIT_MODES.BY_SIZE_OR_COUNT && renderBySizeOrCountForm()}
|
||||||
parameters.method === SPLIT_METHODS.BY_PAGE_COUNT ||
|
{parameters.mode === SPLIT_MODES.BY_CHAPTERS && renderByChaptersForm()}
|
||||||
parameters.method === SPLIT_METHODS.BY_DOC_COUNT) && renderSplitValueForm()}
|
|
||||||
{parameters.method === SPLIT_METHODS.BY_CHAPTERS && renderByChaptersForm()}
|
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { TooltipContent } from '../../types/tips';
|
|
||||||
|
|
||||||
export const useSplitTips = (): TooltipContent => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
return {
|
|
||||||
header: {
|
|
||||||
title: t("split.tooltip.header.title", "Split Methods Overview")
|
|
||||||
},
|
|
||||||
tips: [
|
|
||||||
{
|
|
||||||
title: t("split.tooltip.byPages.title", "Split at Page Numbers"),
|
|
||||||
description: t("split.tooltip.byPages.text", "Extract specific pages or ranges from your PDF. Use commas to separate individual pages and hyphens for ranges."),
|
|
||||||
bullets: [
|
|
||||||
t("split.tooltip.byPages.bullet1", "Single pages: 1,3,5"),
|
|
||||||
t("split.tooltip.byPages.bullet2", "Page ranges: 1-5,10-15"),
|
|
||||||
t("split.tooltip.byPages.bullet3", "Mixed: 1,3-7,12,15-20")
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: t("split.tooltip.bySections.title", "Split by Grid Sections"),
|
|
||||||
description: t("split.tooltip.bySections.text", "Divide each page into a grid of sections. Useful for splitting documents with multiple columns or extracting specific areas."),
|
|
||||||
bullets: [
|
|
||||||
t("split.tooltip.bySections.bullet1", "Horizontal: Number of rows to create"),
|
|
||||||
t("split.tooltip.bySections.bullet2", "Vertical: Number of columns to create"),
|
|
||||||
t("split.tooltip.bySections.bullet3", "Merge: Combine all sections into one PDF")
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: t("split.tooltip.bySize.title", "Split by File Size"),
|
|
||||||
description: t("split.tooltip.bySize.text", "Create multiple PDFs that don't exceed a specified file size. Ideal for file size limitations or email attachments."),
|
|
||||||
bullets: [
|
|
||||||
t("split.tooltip.bySize.bullet1", "Use MB for larger files (e.g., 10MB)"),
|
|
||||||
t("split.tooltip.bySize.bullet2", "Use KB for smaller files (e.g., 500KB)"),
|
|
||||||
t("split.tooltip.bySize.bullet3", "System will split at page boundaries")
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: t("split.tooltip.byCount.title", "Split by Count"),
|
|
||||||
description: t("split.tooltip.byCount.text", "Create multiple PDFs with a specific number of pages or documents each."),
|
|
||||||
bullets: [
|
|
||||||
t("split.tooltip.byCount.bullet1", "Page Count: Fixed number of pages per file"),
|
|
||||||
t("split.tooltip.byCount.bullet2", "Document Count: Fixed number of output files"),
|
|
||||||
t("split.tooltip.byCount.bullet3", "Useful for batch processing workflows")
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: t("split.tooltip.byChapters.title", "Split by Chapters"),
|
|
||||||
description: t("split.tooltip.byChapters.text", "Use PDF bookmarks to automatically split at chapter boundaries. Requires PDFs with bookmark structure."),
|
|
||||||
bullets: [
|
|
||||||
t("split.tooltip.byChapters.bullet1", "Bookmark Level: Which level to split on (1=top level)"),
|
|
||||||
t("split.tooltip.byChapters.bullet2", "Include Metadata: Preserve document properties"),
|
|
||||||
t("split.tooltip.byChapters.bullet3", "Allow Duplicates: Handle repeated bookmark names")
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
};
|
|
@ -1,25 +1,30 @@
|
|||||||
export const SPLIT_METHODS = {
|
export const SPLIT_MODES = {
|
||||||
BY_PAGES: 'byPages',
|
BY_PAGES: 'byPages',
|
||||||
BY_SECTIONS: 'bySections',
|
BY_SECTIONS: 'bySections',
|
||||||
BY_SIZE: 'bySize',
|
BY_SIZE_OR_COUNT: 'bySizeOrCount',
|
||||||
BY_PAGE_COUNT: 'byPageCount',
|
|
||||||
BY_DOC_COUNT: 'byDocCount',
|
|
||||||
BY_CHAPTERS: 'byChapters'
|
BY_CHAPTERS: 'byChapters'
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
export const SPLIT_TYPES = {
|
||||||
export const ENDPOINTS = {
|
SIZE: 'size',
|
||||||
[SPLIT_METHODS.BY_PAGES]: 'split-pages',
|
PAGES: 'pages',
|
||||||
[SPLIT_METHODS.BY_SECTIONS]: 'split-pdf-by-sections',
|
DOCS: 'docs'
|
||||||
[SPLIT_METHODS.BY_SIZE]: 'split-by-size-or-count',
|
|
||||||
[SPLIT_METHODS.BY_PAGE_COUNT]: 'split-by-size-or-count',
|
|
||||||
[SPLIT_METHODS.BY_DOC_COUNT]: 'split-by-size-or-count',
|
|
||||||
[SPLIT_METHODS.BY_CHAPTERS]: 'split-pdf-by-chapters'
|
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type SplitMethod = typeof SPLIT_METHODS[keyof typeof SPLIT_METHODS];
|
export const ENDPOINTS = {
|
||||||
export const isSplitMethod = (value: string | null): value is SplitMethod => {
|
[SPLIT_MODES.BY_PAGES]: 'split-pages',
|
||||||
return Object.values(SPLIT_METHODS).includes(value as SplitMethod);
|
[SPLIT_MODES.BY_SECTIONS]: 'split-pdf-by-sections',
|
||||||
|
[SPLIT_MODES.BY_SIZE_OR_COUNT]: 'split-by-size-or-count',
|
||||||
|
[SPLIT_MODES.BY_CHAPTERS]: 'split-pdf-by-chapters'
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type SplitMode = typeof SPLIT_MODES[keyof typeof SPLIT_MODES];
|
||||||
|
export type SplitType = typeof SPLIT_TYPES[keyof typeof SPLIT_TYPES];
|
||||||
|
|
||||||
|
export const isSplitMode = (value: string | null): value is SplitMode => {
|
||||||
|
return Object.values(SPLIT_MODES).includes(value as SplitMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const isSplitType = (value: string | null): value is SplitType => {
|
||||||
|
return Object.values(SPLIT_TYPES).includes(value as SplitType);
|
||||||
|
}
|
||||||
|
@ -27,7 +27,7 @@ export const useRemoveBlanksOperation = () => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { extractZipFiles } = useToolResources();
|
const { extractZipFiles } = useToolResources();
|
||||||
|
|
||||||
const responseHandler = useCallback(async (blob: Blob, _originalFiles: File[]): Promise<File[]> => {
|
const responseHandler = useCallback(async (blob: Blob, originalFiles: File[]): Promise<File[]> => {
|
||||||
// Backend always returns a ZIP file containing the processed PDFs
|
// Backend always returns a ZIP file containing the processed PDFs
|
||||||
const files = await extractZipFiles(blob);
|
const files = await extractZipFiles(blob);
|
||||||
if (files.length > 0) return files;
|
if (files.length > 0) return files;
|
||||||
|
@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { ToolType, useToolOperation, ToolOperationConfig } from '../shared/useToolOperation';
|
import { ToolType, useToolOperation, ToolOperationConfig } from '../shared/useToolOperation';
|
||||||
import { createStandardErrorHandler } from '../../../utils/toolErrorHandler';
|
import { createStandardErrorHandler } from '../../../utils/toolErrorHandler';
|
||||||
import { SplitParameters, defaultParameters } from './useSplitParameters';
|
import { SplitParameters, defaultParameters } from './useSplitParameters';
|
||||||
import { SPLIT_METHODS } from '../../../constants/splitConstants';
|
import { SPLIT_MODES } from '../../../constants/splitConstants';
|
||||||
import { useToolResources } from '../shared/useToolResources';
|
import { useToolResources } from '../shared/useToolResources';
|
||||||
|
|
||||||
// Static functions that can be used by both the hook and automation executor
|
// Static functions that can be used by both the hook and automation executor
|
||||||
@ -12,53 +12,46 @@ export const buildSplitFormData = (parameters: SplitParameters, file: File): For
|
|||||||
|
|
||||||
formData.append("fileInput", file);
|
formData.append("fileInput", file);
|
||||||
|
|
||||||
switch (parameters.method) {
|
switch (parameters.mode) {
|
||||||
case SPLIT_METHODS.BY_PAGES:
|
case SPLIT_MODES.BY_PAGES:
|
||||||
formData.append("pageNumbers", parameters.pages);
|
formData.append("pageNumbers", parameters.pages);
|
||||||
break;
|
break;
|
||||||
case SPLIT_METHODS.BY_SECTIONS:
|
case SPLIT_MODES.BY_SECTIONS:
|
||||||
formData.append("horizontalDivisions", parameters.hDiv);
|
formData.append("horizontalDivisions", parameters.hDiv);
|
||||||
formData.append("verticalDivisions", parameters.vDiv);
|
formData.append("verticalDivisions", parameters.vDiv);
|
||||||
formData.append("merge", parameters.merge.toString());
|
formData.append("merge", parameters.merge.toString());
|
||||||
break;
|
break;
|
||||||
case SPLIT_METHODS.BY_SIZE:
|
case SPLIT_MODES.BY_SIZE_OR_COUNT:
|
||||||
formData.append("splitType", "0");
|
formData.append(
|
||||||
|
"splitType",
|
||||||
|
parameters.splitType === "size" ? "0" : parameters.splitType === "pages" ? "1" : "2"
|
||||||
|
);
|
||||||
formData.append("splitValue", parameters.splitValue);
|
formData.append("splitValue", parameters.splitValue);
|
||||||
break;
|
break;
|
||||||
case SPLIT_METHODS.BY_PAGE_COUNT:
|
case SPLIT_MODES.BY_CHAPTERS:
|
||||||
formData.append("splitType", "1");
|
|
||||||
formData.append("splitValue", parameters.splitValue);
|
|
||||||
break;
|
|
||||||
case SPLIT_METHODS.BY_DOC_COUNT:
|
|
||||||
formData.append("splitType", "2");
|
|
||||||
formData.append("splitValue", parameters.splitValue);
|
|
||||||
break;
|
|
||||||
case SPLIT_METHODS.BY_CHAPTERS:
|
|
||||||
formData.append("bookmarkLevel", parameters.bookmarkLevel);
|
formData.append("bookmarkLevel", parameters.bookmarkLevel);
|
||||||
formData.append("includeMetadata", parameters.includeMetadata.toString());
|
formData.append("includeMetadata", parameters.includeMetadata.toString());
|
||||||
formData.append("allowDuplicates", parameters.allowDuplicates.toString());
|
formData.append("allowDuplicates", parameters.allowDuplicates.toString());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown split method: ${parameters.method}`);
|
throw new Error(`Unknown split mode: ${parameters.mode}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return formData;
|
return formData;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getSplitEndpoint = (parameters: SplitParameters): string => {
|
export const getSplitEndpoint = (parameters: SplitParameters): string => {
|
||||||
switch (parameters.method) {
|
switch (parameters.mode) {
|
||||||
case SPLIT_METHODS.BY_PAGES:
|
case SPLIT_MODES.BY_PAGES:
|
||||||
return "/api/v1/general/split-pages";
|
return "/api/v1/general/split-pages";
|
||||||
case SPLIT_METHODS.BY_SECTIONS:
|
case SPLIT_MODES.BY_SECTIONS:
|
||||||
return "/api/v1/general/split-pdf-by-sections";
|
return "/api/v1/general/split-pdf-by-sections";
|
||||||
case SPLIT_METHODS.BY_SIZE:
|
case SPLIT_MODES.BY_SIZE_OR_COUNT:
|
||||||
case SPLIT_METHODS.BY_PAGE_COUNT:
|
|
||||||
case SPLIT_METHODS.BY_DOC_COUNT:
|
|
||||||
return "/api/v1/general/split-by-size-or-count";
|
return "/api/v1/general/split-by-size-or-count";
|
||||||
case SPLIT_METHODS.BY_CHAPTERS:
|
case SPLIT_MODES.BY_CHAPTERS:
|
||||||
return "/api/v1/general/split-pdf-by-chapters";
|
return "/api/v1/general/split-pdf-by-chapters";
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown split method: ${parameters.method}`);
|
throw new Error(`Unknown split mode: ${parameters.mode}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
import { SPLIT_METHODS, ENDPOINTS, type SplitMethod } from '../../../constants/splitConstants';
|
import { SPLIT_MODES, SPLIT_TYPES, ENDPOINTS, type SplitMode, SplitType } from '../../../constants/splitConstants';
|
||||||
import { BaseParameters } from '../../../types/parameters';
|
import { BaseParameters } from '../../../types/parameters';
|
||||||
import { useBaseParameters, BaseParametersHook } from '../shared/useBaseParameters';
|
import { useBaseParameters, BaseParametersHook } from '../shared/useBaseParameters';
|
||||||
|
|
||||||
export interface SplitParameters extends BaseParameters {
|
export interface SplitParameters extends BaseParameters {
|
||||||
method: SplitMethod | '';
|
mode: SplitMode | '';
|
||||||
pages: string;
|
pages: string;
|
||||||
hDiv: string;
|
hDiv: string;
|
||||||
vDiv: string;
|
vDiv: string;
|
||||||
merge: boolean;
|
merge: boolean;
|
||||||
|
splitType: SplitType | '';
|
||||||
splitValue: string;
|
splitValue: string;
|
||||||
bookmarkLevel: string;
|
bookmarkLevel: string;
|
||||||
includeMetadata: boolean;
|
includeMetadata: boolean;
|
||||||
@ -17,11 +18,12 @@ export interface SplitParameters extends BaseParameters {
|
|||||||
export type SplitParametersHook = BaseParametersHook<SplitParameters>;
|
export type SplitParametersHook = BaseParametersHook<SplitParameters>;
|
||||||
|
|
||||||
export const defaultParameters: SplitParameters = {
|
export const defaultParameters: SplitParameters = {
|
||||||
method: '',
|
mode: '',
|
||||||
pages: '',
|
pages: '',
|
||||||
hDiv: '2',
|
hDiv: '2',
|
||||||
vDiv: '2',
|
vDiv: '2',
|
||||||
merge: false,
|
merge: false,
|
||||||
|
splitType: SPLIT_TYPES.SIZE,
|
||||||
splitValue: '',
|
splitValue: '',
|
||||||
bookmarkLevel: '1',
|
bookmarkLevel: '1',
|
||||||
includeMetadata: false,
|
includeMetadata: false,
|
||||||
@ -32,22 +34,20 @@ export const useSplitParameters = (): SplitParametersHook => {
|
|||||||
return useBaseParameters({
|
return useBaseParameters({
|
||||||
defaultParameters,
|
defaultParameters,
|
||||||
endpointName: (params) => {
|
endpointName: (params) => {
|
||||||
if (!params.method) return ENDPOINTS[SPLIT_METHODS.BY_PAGES];
|
if (!params.mode) return ENDPOINTS[SPLIT_MODES.BY_PAGES];
|
||||||
return ENDPOINTS[params.method as SplitMethod];
|
return ENDPOINTS[params.mode as SplitMode];
|
||||||
},
|
},
|
||||||
validateFn: (params) => {
|
validateFn: (params) => {
|
||||||
if (!params.method) return false;
|
if (!params.mode) return false;
|
||||||
|
|
||||||
switch (params.method) {
|
switch (params.mode) {
|
||||||
case SPLIT_METHODS.BY_PAGES:
|
case SPLIT_MODES.BY_PAGES:
|
||||||
return params.pages.trim() !== "";
|
return params.pages.trim() !== "";
|
||||||
case SPLIT_METHODS.BY_SECTIONS:
|
case SPLIT_MODES.BY_SECTIONS:
|
||||||
return params.hDiv !== "" && params.vDiv !== "";
|
return params.hDiv !== "" && params.vDiv !== "";
|
||||||
case SPLIT_METHODS.BY_SIZE:
|
case SPLIT_MODES.BY_SIZE_OR_COUNT:
|
||||||
case SPLIT_METHODS.BY_PAGE_COUNT:
|
|
||||||
case SPLIT_METHODS.BY_DOC_COUNT:
|
|
||||||
return params.splitValue.trim() !== "";
|
return params.splitValue.trim() !== "";
|
||||||
case SPLIT_METHODS.BY_CHAPTERS:
|
case SPLIT_MODES.BY_CHAPTERS:
|
||||||
return params.bookmarkLevel !== "";
|
return params.bookmarkLevel !== "";
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -183,10 +183,10 @@ export const mantineTheme = createTheme({
|
|||||||
},
|
},
|
||||||
option: {
|
option: {
|
||||||
color: 'var(--text-primary)',
|
color: 'var(--text-primary)',
|
||||||
'&[dataHovered]': {
|
'&[data-hovered]': {
|
||||||
backgroundColor: 'var(--hover-bg)',
|
backgroundColor: 'var(--hover-bg)',
|
||||||
},
|
},
|
||||||
'&[dataSelected]': {
|
'&[data-selected]': {
|
||||||
backgroundColor: 'var(--color-primary-100)',
|
backgroundColor: 'var(--color-primary-100)',
|
||||||
color: 'var(--color-primary-900)',
|
color: 'var(--color-primary-900)',
|
||||||
},
|
},
|
||||||
|
@ -4,12 +4,10 @@ import SplitSettings from "../components/tools/split/SplitSettings";
|
|||||||
import { useSplitParameters } from "../hooks/tools/split/useSplitParameters";
|
import { useSplitParameters } from "../hooks/tools/split/useSplitParameters";
|
||||||
import { useSplitOperation } from "../hooks/tools/split/useSplitOperation";
|
import { useSplitOperation } from "../hooks/tools/split/useSplitOperation";
|
||||||
import { useBaseTool } from "../hooks/tools/shared/useBaseTool";
|
import { useBaseTool } from "../hooks/tools/shared/useBaseTool";
|
||||||
import { useSplitTips } from "../components/tooltips/useSplitTips";
|
|
||||||
import { BaseToolProps, ToolComponent } from "../types/tool";
|
import { BaseToolProps, ToolComponent } from "../types/tool";
|
||||||
|
|
||||||
const Split = (props: BaseToolProps) => {
|
const Split = (props: BaseToolProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const splitTips = useSplitTips();
|
|
||||||
|
|
||||||
const base = useBaseTool(
|
const base = useBaseTool(
|
||||||
'split',
|
'split',
|
||||||
@ -28,7 +26,6 @@ const Split = (props: BaseToolProps) => {
|
|||||||
title: "Settings",
|
title: "Settings",
|
||||||
isCollapsed: base.settingsCollapsed,
|
isCollapsed: base.settingsCollapsed,
|
||||||
onCollapsedClick: base.hasResults ? base.handleSettingsReset : undefined,
|
onCollapsedClick: base.hasResults ? base.handleSettingsReset : undefined,
|
||||||
tooltip: splitTips,
|
|
||||||
content: (
|
content: (
|
||||||
<SplitSettings
|
<SplitSettings
|
||||||
parameters={base.params.parameters}
|
parameters={base.params.parameters}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user