@pdfme/ui 1.0.0-beta.5 → 1.0.0-beta.9
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/coverage/clover.xml +6 -0
- package/coverage/coverage-final.json +1 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +101 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov.info +0 -0
- package/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +3 -1
- package/dist/index.js.map +1 -1
- package/dist/types/{ui/src/Designer.d.ts → Designer.d.ts} +0 -0
- package/dist/types/{ui/src/Form.d.ts → Form.d.ts} +0 -0
- package/dist/types/{ui/src/Viewer.d.ts → Viewer.d.ts} +0 -0
- package/dist/types/{ui/src/class.d.ts → class.d.ts} +1 -1
- package/dist/types/{ui/src/components → components}/Designer/Main/Guides.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Designer/Main/Mask.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Designer/Main/Moveable.d.ts +1 -1
- package/dist/types/{ui/src/components → components}/Designer/Main/Selecto.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Designer/Main/index.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Designer/Sidebar/DetailView/ExampleInputEditor.d.ts +4 -1
- package/dist/types/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.d.ts +6 -0
- package/dist/types/{ui/src/components → components}/Designer/Sidebar/DetailView/TextPropEditor.d.ts +4 -1
- package/dist/types/{ui/src/components → components}/Designer/Sidebar/DetailView/TypeAndKeyEditor.d.ts +4 -1
- package/dist/types/components/Designer/Sidebar/DetailView/index.d.ts +6 -0
- package/dist/types/components/Designer/Sidebar/ListView/Item.d.ts +25 -0
- package/dist/types/components/Designer/Sidebar/ListView/SelectableSortableContainer.d.ts +3 -0
- package/dist/types/components/Designer/Sidebar/ListView/SelectableSortableItem.d.ts +14 -0
- package/dist/types/{ui/src/components/Designer/Sidebar/ListView.d.ts → components/Designer/Sidebar/ListView/index.d.ts} +2 -2
- package/dist/types/{ui/src/components → components}/Designer/Sidebar/index.d.ts +2 -7
- package/dist/types/{ui/src/components → components}/Designer/index.d.ts +0 -1
- package/dist/types/{ui/src/components → components}/Divider.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Error.d.ts +0 -1
- package/dist/types/{ui/src/components → components}/Paper.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Preview/Pager/Page.d.ts +0 -1
- package/dist/types/{ui/src/components → components}/Preview/Pager/Unit.d.ts +0 -1
- package/dist/types/{ui/src/components → components}/Preview/index.d.ts +0 -1
- package/dist/types/{ui/src/components → components}/Root.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Schemas/BarcodeSchema.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Schemas/ImageSchema.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Schemas/SchemaUI.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Schemas/TextSchema.d.ts +0 -0
- package/dist/types/{ui/src/components → components}/Spinner.d.ts +0 -0
- package/dist/types/{ui/src/constants.d.ts → constants.d.ts} +1 -0
- package/dist/types/{ui/src/contexts.d.ts → contexts.d.ts} +1 -1
- package/dist/types/{ui/src/helper.d.ts → helper.d.ts} +1 -1
- package/dist/types/{ui/src/hooks.d.ts → hooks.d.ts} +1 -0
- package/dist/types/{ui/src/i18n.d.ts → i18n.d.ts} +4 -2
- package/dist/types/{ui/src/index.d.ts → index.d.ts} +0 -0
- package/package.json +13 -11
- package/src/Designer.tsx +2 -1
- package/src/Form.tsx +1 -0
- package/src/Viewer.tsx +1 -0
- package/src/assets/icons/align-horizontal-center.svg +1 -0
- package/src/assets/icons/align-horizontal-left.svg +1 -0
- package/src/assets/icons/align-horizontal-right.svg +1 -0
- package/src/assets/icons/align-vertical-bottom.svg +1 -0
- package/src/assets/icons/align-vertical-middle.svg +1 -0
- package/src/assets/icons/align-vertical-top.svg +1 -0
- package/src/assets/icons/close.svg +4 -0
- package/src/assets/icons/horizontal-distribute.svg +1 -0
- package/src/assets/icons/vertical-distribute.svg +1 -0
- package/src/assets/imageExample.png +0 -0
- package/src/class.ts +5 -6
- package/src/components/Designer/Main/Moveable.tsx +1 -1
- package/src/components/Designer/Main/index.tsx +21 -15
- package/src/components/Designer/Sidebar/DetailView/ExampleInputEditor.tsx +28 -6
- package/src/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.tsx +115 -24
- package/src/components/Designer/Sidebar/DetailView/TextPropEditor.tsx +36 -6
- package/src/components/Designer/Sidebar/DetailView/TypeAndKeyEditor.tsx +14 -6
- package/src/components/Designer/Sidebar/DetailView/index.tsx +19 -14
- package/src/components/Designer/Sidebar/ListView/Item.tsx +113 -0
- package/src/components/Designer/Sidebar/ListView/SelectableSortableContainer.tsx +162 -0
- package/src/components/Designer/Sidebar/ListView/SelectableSortableItem.tsx +78 -0
- package/src/components/Designer/Sidebar/ListView/index.tsx +118 -0
- package/src/components/Designer/Sidebar/index.tsx +26 -12
- package/src/components/Designer/index.tsx +12 -24
- package/src/components/Paper.tsx +1 -3
- package/src/components/Preview/Pager/Page.tsx +1 -1
- package/src/components/Preview/Pager/Unit.tsx +1 -1
- package/src/components/Preview/index.tsx +3 -4
- package/src/components/Root.tsx +2 -7
- package/src/components/Schemas/BarcodeSchema.tsx +37 -22
- package/src/components/Schemas/ImageSchema.tsx +71 -66
- package/src/components/Schemas/TextSchema.tsx +1 -1
- package/src/constants.ts +2 -0
- package/src/helper.ts +42 -37
- package/src/hooks.ts +11 -0
- package/src/i18n.ts +10 -7
- package/tsconfig.json +1 -1
- package/webpack.config.js +0 -18
- package/dist/types/common/src/constants.d.ts +0 -6
- package/dist/types/common/src/helper.d.ts +0 -15
- package/dist/types/common/src/index.d.ts +0 -6
- package/dist/types/common/src/schema.d.ts +0 -3613
- package/dist/types/common/src/type.d.ts +0 -64
- package/dist/types/ui/src/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.d.ts +0 -3
- package/dist/types/ui/src/components/Designer/Sidebar/DetailView/index.d.ts +0 -3
- package/src/components/Designer/Sidebar/ListView.tsx +0 -180
@@ -0,0 +1,162 @@
|
|
1
|
+
import React, { useState } from 'react';
|
2
|
+
import { createPortal } from 'react-dom';
|
3
|
+
import {
|
4
|
+
closestCorners,
|
5
|
+
DndContext,
|
6
|
+
DragOverlay,
|
7
|
+
KeyboardSensor,
|
8
|
+
PointerSensor,
|
9
|
+
useSensors,
|
10
|
+
useSensor,
|
11
|
+
} from '@dnd-kit/core';
|
12
|
+
import {
|
13
|
+
SortableContext,
|
14
|
+
arrayMove,
|
15
|
+
sortableKeyboardCoordinates,
|
16
|
+
verticalListSortingStrategy,
|
17
|
+
} from '@dnd-kit/sortable';
|
18
|
+
import { SchemaForUI } from '@pdfme/common';
|
19
|
+
import Item from './Item';
|
20
|
+
import SelectableSortableItem from './SelectableSortableItem';
|
21
|
+
import { SidebarProps } from '../';
|
22
|
+
|
23
|
+
const SelectableSortableContainer = (
|
24
|
+
props: Pick<
|
25
|
+
SidebarProps,
|
26
|
+
'schemas' | 'onEdit' | 'onSortEnd' | 'height' | 'hoveringSchemaId' | 'onChangeHoveringSchemaId'
|
27
|
+
>
|
28
|
+
) => {
|
29
|
+
const { schemas, onEdit, onSortEnd, height, hoveringSchemaId, onChangeHoveringSchemaId } = props;
|
30
|
+
const [selectedSchemas, setSelectedSchemas] = useState<SchemaForUI[]>([]);
|
31
|
+
const [dragOverlaydItems, setClonedItems] = useState<SchemaForUI[] | null>(null);
|
32
|
+
const [activeId, setActiveId] = useState<string | null>(null);
|
33
|
+
const sensors = useSensors(
|
34
|
+
useSensor(PointerSensor, { activationConstraint: { distance: 15 } }),
|
35
|
+
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates })
|
36
|
+
);
|
37
|
+
|
38
|
+
const isItemSelected = (itemId: string): boolean =>
|
39
|
+
selectedSchemas.map((i) => i.id).includes(itemId);
|
40
|
+
|
41
|
+
const onSelectionChanged = (id: string, isShiftSelect: boolean) => {
|
42
|
+
if (isShiftSelect) {
|
43
|
+
if (isItemSelected(id)) {
|
44
|
+
const newSelectedSchemas = selectedSchemas.filter((item) => item.id !== id);
|
45
|
+
setSelectedSchemas(newSelectedSchemas);
|
46
|
+
} else {
|
47
|
+
const newSelectedItem = schemas.find((schema) => schema.id === id)!;
|
48
|
+
const newSelectedSchemas = selectedSchemas.concat(newSelectedItem);
|
49
|
+
setSelectedSchemas(newSelectedSchemas);
|
50
|
+
}
|
51
|
+
} else {
|
52
|
+
setSelectedSchemas([]);
|
53
|
+
}
|
54
|
+
};
|
55
|
+
|
56
|
+
return (
|
57
|
+
<DndContext
|
58
|
+
sensors={sensors}
|
59
|
+
collisionDetection={closestCorners}
|
60
|
+
onDragStart={({ active }) => {
|
61
|
+
setActiveId(active.id);
|
62
|
+
setClonedItems(schemas);
|
63
|
+
|
64
|
+
if (!isItemSelected(active.id)) {
|
65
|
+
const newSelectedSchemas: SchemaForUI[] = [];
|
66
|
+
setSelectedSchemas(newSelectedSchemas);
|
67
|
+
} else if (selectedSchemas.length > 0) {
|
68
|
+
onSortEnd(
|
69
|
+
selectedSchemas.reduce((ret, selectedItem) => {
|
70
|
+
if (selectedItem.id === active.id) {
|
71
|
+
return ret;
|
72
|
+
}
|
73
|
+
return ret.filter((schema) => schema !== selectedItem);
|
74
|
+
}, schemas)
|
75
|
+
);
|
76
|
+
}
|
77
|
+
}}
|
78
|
+
onDragEnd={({ active, over }) => {
|
79
|
+
const overId = over?.id || '';
|
80
|
+
|
81
|
+
const activeIndex = schemas.map((i) => i.id).indexOf(active.id);
|
82
|
+
const overIndex = schemas.map((i) => i.id).indexOf(overId);
|
83
|
+
|
84
|
+
if (selectedSchemas.length) {
|
85
|
+
let newSchemas = [...schemas];
|
86
|
+
newSchemas = arrayMove(newSchemas, activeIndex, overIndex);
|
87
|
+
newSchemas.splice(
|
88
|
+
overIndex + 1,
|
89
|
+
0,
|
90
|
+
...selectedSchemas.filter((item) => item.id !== activeId)
|
91
|
+
);
|
92
|
+
onSortEnd(newSchemas);
|
93
|
+
setSelectedSchemas([]);
|
94
|
+
} else if (activeIndex !== overIndex) {
|
95
|
+
onSortEnd(arrayMove(schemas, activeIndex, overIndex));
|
96
|
+
}
|
97
|
+
|
98
|
+
setActiveId(null);
|
99
|
+
}}
|
100
|
+
onDragCancel={() => {
|
101
|
+
if (dragOverlaydItems) {
|
102
|
+
onSortEnd(dragOverlaydItems);
|
103
|
+
}
|
104
|
+
|
105
|
+
setActiveId(null);
|
106
|
+
setClonedItems(null);
|
107
|
+
}}
|
108
|
+
>
|
109
|
+
<div style={{ height, overflowY: 'auto' }}>
|
110
|
+
<SortableContext items={schemas} strategy={verticalListSortingStrategy}>
|
111
|
+
<ul style={{ margin: 0, padding: 0, listStyle: 'none', borderRadius: 5 }}>
|
112
|
+
{schemas.map((schema) => (
|
113
|
+
<SelectableSortableItem
|
114
|
+
key={schema.id}
|
115
|
+
style={{
|
116
|
+
border: `1px solid ${schema.id === hoveringSchemaId ? '#18a0fb' : 'transparent'}`,
|
117
|
+
}}
|
118
|
+
schema={schema}
|
119
|
+
schemas={schemas}
|
120
|
+
isSelected={isItemSelected(schema.id) || activeId === schema.id}
|
121
|
+
onEdit={onEdit}
|
122
|
+
onSelect={onSelectionChanged}
|
123
|
+
onMouseEnter={() => onChangeHoveringSchemaId(schema.id)}
|
124
|
+
onMouseLeave={() => onChangeHoveringSchemaId(null)}
|
125
|
+
/>
|
126
|
+
))}
|
127
|
+
</ul>
|
128
|
+
</SortableContext>
|
129
|
+
</div>
|
130
|
+
{createPortal(
|
131
|
+
<DragOverlay adjustScale>
|
132
|
+
{activeId ? (
|
133
|
+
<>
|
134
|
+
<ul style={{ margin: 0, padding: 0, listStyle: 'none' }}>
|
135
|
+
<Item
|
136
|
+
value={schemas.find((schema) => schema.id === activeId)!.key}
|
137
|
+
style={{ color: '#fff', background: '#18a0fb' }}
|
138
|
+
dragOverlay
|
139
|
+
/>
|
140
|
+
</ul>
|
141
|
+
<ul style={{ margin: 0, padding: 0, listStyle: 'none' }}>
|
142
|
+
{selectedSchemas
|
143
|
+
.filter((item) => item.id !== activeId)
|
144
|
+
.map((item) => (
|
145
|
+
<Item
|
146
|
+
key={item.id}
|
147
|
+
value={item.key}
|
148
|
+
style={{ color: '#fff', background: '#18a0fb' }}
|
149
|
+
dragOverlay
|
150
|
+
/>
|
151
|
+
))}
|
152
|
+
</ul>
|
153
|
+
</>
|
154
|
+
) : null}
|
155
|
+
</DragOverlay>,
|
156
|
+
document.body
|
157
|
+
)}
|
158
|
+
</DndContext>
|
159
|
+
);
|
160
|
+
};
|
161
|
+
|
162
|
+
export default SelectableSortableContainer;
|
@@ -0,0 +1,78 @@
|
|
1
|
+
import React, { useContext } from 'react';
|
2
|
+
import { useSortable } from '@dnd-kit/sortable';
|
3
|
+
import { SchemaForUI } from '@pdfme/common';
|
4
|
+
import { I18nContext } from '../../../../contexts';
|
5
|
+
import Item from './Item';
|
6
|
+
import { useMountStatus } from '../../../../hooks';
|
7
|
+
|
8
|
+
interface Props {
|
9
|
+
isSelected: boolean;
|
10
|
+
style?: React.CSSProperties;
|
11
|
+
onSelect: (id: string, isShiftSelect: boolean) => void;
|
12
|
+
onEdit: (id: string) => void;
|
13
|
+
schema: SchemaForUI;
|
14
|
+
schemas: SchemaForUI[];
|
15
|
+
onMouseEnter: () => void;
|
16
|
+
onMouseLeave: () => void;
|
17
|
+
}
|
18
|
+
const SelectableSortableItem = ({
|
19
|
+
isSelected,
|
20
|
+
style,
|
21
|
+
onSelect,
|
22
|
+
onEdit,
|
23
|
+
schema,
|
24
|
+
schemas,
|
25
|
+
onMouseEnter,
|
26
|
+
onMouseLeave,
|
27
|
+
}: Props) => {
|
28
|
+
const i18n = useContext(I18nContext);
|
29
|
+
const { setNodeRef, listeners, isDragging, isSorting, transform, transition } = useSortable({
|
30
|
+
id: schema.id,
|
31
|
+
});
|
32
|
+
const mounted = useMountStatus();
|
33
|
+
const mountedWhileDragging = isDragging && !mounted;
|
34
|
+
|
35
|
+
const newListeners = {
|
36
|
+
...listeners,
|
37
|
+
onClick: (event: any) => onSelect(schema.id, event.shiftKey),
|
38
|
+
};
|
39
|
+
|
40
|
+
let status: undefined | 'is-warning' | 'is-danger';
|
41
|
+
if (!schema.key) {
|
42
|
+
status = 'is-warning';
|
43
|
+
} else if (schemas.find((s) => schema.key && s.key === schema.key && s.id !== schema.id)) {
|
44
|
+
status = 'is-danger';
|
45
|
+
}
|
46
|
+
|
47
|
+
let title = i18n('edit');
|
48
|
+
if (status === 'is-warning') {
|
49
|
+
title = i18n('plsInputName');
|
50
|
+
} else if (status === 'is-danger') {
|
51
|
+
title = i18n('fieldMustUniq');
|
52
|
+
}
|
53
|
+
|
54
|
+
const selectedStyle = isSelected
|
55
|
+
? { color: '#fff', background: '#18a0fb', opacity: isSorting || isDragging ? 0.5 : 1 }
|
56
|
+
: ({} as React.CSSProperties);
|
57
|
+
|
58
|
+
return (
|
59
|
+
<Item
|
60
|
+
ref={setNodeRef}
|
61
|
+
onMouseEnter={onMouseEnter}
|
62
|
+
onMouseLeave={onMouseLeave}
|
63
|
+
onClick={() => onEdit(schema.id)}
|
64
|
+
value={schema.key}
|
65
|
+
status={status}
|
66
|
+
title={title}
|
67
|
+
style={{ ...selectedStyle, ...style }}
|
68
|
+
dragging={isDragging}
|
69
|
+
sorting={isSorting}
|
70
|
+
transition={transition}
|
71
|
+
transform={transform}
|
72
|
+
fadeIn={mountedWhileDragging}
|
73
|
+
listeners={newListeners}
|
74
|
+
/>
|
75
|
+
);
|
76
|
+
};
|
77
|
+
|
78
|
+
export default SelectableSortableItem;
|
@@ -0,0 +1,118 @@
|
|
1
|
+
import React, { useContext, useState } from 'react';
|
2
|
+
import { ZOOM, RULER_HEIGHT, SIDEBAR_WIDTH } from '../../../../constants';
|
3
|
+
import { I18nContext } from '../../../../contexts';
|
4
|
+
import Divider from '../../../Divider';
|
5
|
+
import SelectableSortableContainer from './SelectableSortableContainer';
|
6
|
+
import { SidebarProps } from '..';
|
7
|
+
|
8
|
+
const ListView = (
|
9
|
+
props: Pick<
|
10
|
+
SidebarProps,
|
11
|
+
| 'schemas'
|
12
|
+
| 'onSortEnd'
|
13
|
+
| 'onEdit'
|
14
|
+
| 'size'
|
15
|
+
| 'hoveringSchemaId'
|
16
|
+
| 'onChangeHoveringSchemaId'
|
17
|
+
| 'changeSchemas'
|
18
|
+
>
|
19
|
+
) => {
|
20
|
+
const {
|
21
|
+
schemas,
|
22
|
+
onSortEnd,
|
23
|
+
onEdit,
|
24
|
+
size,
|
25
|
+
hoveringSchemaId,
|
26
|
+
onChangeHoveringSchemaId,
|
27
|
+
changeSchemas,
|
28
|
+
} = props;
|
29
|
+
const i18n = useContext(I18nContext);
|
30
|
+
const [isBulkUpdateFieldNamesMode, setIsBulkUpdateFieldNamesMode] = useState(false);
|
31
|
+
const [fieldNamesValue, setFieldNamesValue] = useState('');
|
32
|
+
const height = size.height - RULER_HEIGHT * ZOOM - 135;
|
33
|
+
return (
|
34
|
+
<div>
|
35
|
+
<div style={{ height: 40, display: 'flex', alignItems: 'center' }}>
|
36
|
+
<p style={{ textAlign: 'center', width: '100%', fontWeight: 'bold' }}>
|
37
|
+
{i18n('fieldsList')}
|
38
|
+
</p>
|
39
|
+
</div>
|
40
|
+
<Divider />
|
41
|
+
{isBulkUpdateFieldNamesMode ? (
|
42
|
+
<div>
|
43
|
+
<textarea
|
44
|
+
wrap="off"
|
45
|
+
value={fieldNamesValue}
|
46
|
+
onChange={(e) => setFieldNamesValue(e.target.value)}
|
47
|
+
style={{
|
48
|
+
height: height - 5,
|
49
|
+
width: SIDEBAR_WIDTH,
|
50
|
+
fontSize: '1rem',
|
51
|
+
lineHeight: '2.25rem',
|
52
|
+
background: 'transparent',
|
53
|
+
margin: 0,
|
54
|
+
padding: 0,
|
55
|
+
fontFamily: 'inherit',
|
56
|
+
}}
|
57
|
+
></textarea>
|
58
|
+
</div>
|
59
|
+
) : (
|
60
|
+
<SelectableSortableContainer
|
61
|
+
height={height}
|
62
|
+
schemas={schemas}
|
63
|
+
hoveringSchemaId={hoveringSchemaId}
|
64
|
+
onChangeHoveringSchemaId={onChangeHoveringSchemaId}
|
65
|
+
onSortEnd={onSortEnd}
|
66
|
+
onEdit={onEdit}
|
67
|
+
/>
|
68
|
+
)}
|
69
|
+
|
70
|
+
<div
|
71
|
+
style={{
|
72
|
+
display: 'flex',
|
73
|
+
justifyContent: 'flex-end',
|
74
|
+
cursor: 'pointer',
|
75
|
+
fontSize: '0.75rem',
|
76
|
+
}}
|
77
|
+
>
|
78
|
+
{isBulkUpdateFieldNamesMode ? (
|
79
|
+
<>
|
80
|
+
<u
|
81
|
+
onClick={() => {
|
82
|
+
const names = fieldNamesValue.split('\n');
|
83
|
+
if (names.length !== schemas.length) {
|
84
|
+
alert(i18n('errorBulkUpdateFieldName'));
|
85
|
+
} else {
|
86
|
+
changeSchemas(
|
87
|
+
names.map((value, index) => ({
|
88
|
+
key: 'key',
|
89
|
+
value,
|
90
|
+
schemaId: schemas[index].id,
|
91
|
+
}))
|
92
|
+
);
|
93
|
+
setIsBulkUpdateFieldNamesMode(false);
|
94
|
+
}
|
95
|
+
}}
|
96
|
+
>
|
97
|
+
{i18n('commitBulkUpdateFieldName')}
|
98
|
+
</u>
|
99
|
+
<span style={{ margin: '0 1rem' }}>/</span>
|
100
|
+
<u onClick={() => setIsBulkUpdateFieldNamesMode(false)}>{i18n('cancel')}</u>
|
101
|
+
</>
|
102
|
+
) : (
|
103
|
+
<u
|
104
|
+
onClick={() => {
|
105
|
+
setFieldNamesValue(schemas.map((s) => s.key).join('\n'));
|
106
|
+
setIsBulkUpdateFieldNamesMode(true);
|
107
|
+
}}
|
108
|
+
>
|
109
|
+
{i18n('bulkUpdateFieldName')}
|
110
|
+
</u>
|
111
|
+
)}
|
112
|
+
</div>
|
113
|
+
<Divider />
|
114
|
+
</div>
|
115
|
+
);
|
116
|
+
};
|
117
|
+
|
118
|
+
export default ListView;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React, { useState, useContext } from 'react';
|
2
2
|
import { SchemaForUI, Size } from '@pdfme/common';
|
3
|
-
import { ZOOM, RULER_HEIGHT } from '../../../constants';
|
3
|
+
import { ZOOM, RULER_HEIGHT, SIDEBAR_WIDTH } from '../../../constants';
|
4
4
|
import { I18nContext } from '../../../contexts';
|
5
5
|
import backIcon from '../../../assets/icons/back.svg';
|
6
6
|
import forwardIcon from '../../../assets/icons/forward.svg';
|
@@ -13,10 +13,9 @@ export type SidebarProps = {
|
|
13
13
|
onChangeHoveringSchemaId: (id: string | null) => void;
|
14
14
|
size: Size;
|
15
15
|
pageSize: Size;
|
16
|
-
|
17
|
-
activeSchema: SchemaForUI;
|
16
|
+
activeElements: HTMLElement[];
|
18
17
|
schemas: SchemaForUI[];
|
19
|
-
onSortEnd: (
|
18
|
+
onSortEnd: (sortedSchemas: SchemaForUI[]) => void;
|
20
19
|
onEdit: (id: string) => void;
|
21
20
|
onEditEnd: () => void;
|
22
21
|
changeSchemas: (objs: { key: string; value: string | number; schemaId: string }[]) => void;
|
@@ -24,16 +23,27 @@ export type SidebarProps = {
|
|
24
23
|
};
|
25
24
|
|
26
25
|
const Sidebar = (props: SidebarProps) => {
|
27
|
-
const { height, size, addSchema } = props;
|
26
|
+
const { height, size, activeElements, schemas, addSchema } = props;
|
28
27
|
|
29
28
|
const i18n = useContext(I18nContext);
|
30
29
|
const [open, setOpen] = useState(true);
|
31
|
-
const sidebarWidth = 300;
|
32
30
|
const top = 0;
|
33
31
|
|
32
|
+
const getActiveSchemas = () => {
|
33
|
+
const ids = activeElements.map((ae) => ae.id);
|
34
|
+
return schemas.filter((s) => ids.includes(s.id));
|
35
|
+
};
|
36
|
+
|
37
|
+
const getLastActiveSchema = () => {
|
38
|
+
const activeSchemas = getActiveSchemas();
|
39
|
+
return activeSchemas[activeSchemas.length - 1];
|
40
|
+
};
|
41
|
+
|
34
42
|
return (
|
35
|
-
<div
|
36
|
-
|
43
|
+
<div
|
44
|
+
style={{ position: 'absolute', right: 0, zIndex: 1, height, width: open ? SIDEBAR_WIDTH : 0 }}
|
45
|
+
>
|
46
|
+
<div style={{ position: 'sticky', top, zIndex: 1, fontSize: '1rem' }}>
|
37
47
|
<button
|
38
48
|
style={{
|
39
49
|
position: 'absolute',
|
@@ -41,7 +51,7 @@ const Sidebar = (props: SidebarProps) => {
|
|
41
51
|
right: '0.5rem',
|
42
52
|
zIndex: 100,
|
43
53
|
border: 'none',
|
44
|
-
borderRadius:
|
54
|
+
borderRadius: 2,
|
45
55
|
padding: '0.5rem',
|
46
56
|
cursor: 'pointer',
|
47
57
|
background: '#eee',
|
@@ -52,7 +62,7 @@ const Sidebar = (props: SidebarProps) => {
|
|
52
62
|
</button>
|
53
63
|
<div
|
54
64
|
style={{
|
55
|
-
width:
|
65
|
+
width: SIDEBAR_WIDTH,
|
56
66
|
height: size.height - RULER_HEIGHT * ZOOM,
|
57
67
|
display: open ? 'block' : 'none',
|
58
68
|
top,
|
@@ -67,7 +77,11 @@ const Sidebar = (props: SidebarProps) => {
|
|
67
77
|
fontWeight: 400,
|
68
78
|
}}
|
69
79
|
>
|
70
|
-
{
|
80
|
+
{getActiveSchemas().length === 0 ? (
|
81
|
+
<ListView {...props} />
|
82
|
+
) : (
|
83
|
+
<DetailView {...props} activeSchema={getLastActiveSchema()} />
|
84
|
+
)}
|
71
85
|
<div
|
72
86
|
style={{
|
73
87
|
display: 'flex',
|
@@ -85,7 +99,7 @@ const Sidebar = (props: SidebarProps) => {
|
|
85
99
|
color: '#fff',
|
86
100
|
background: '#18a0fb',
|
87
101
|
border: 'none',
|
88
|
-
borderRadius:
|
102
|
+
borderRadius: 2,
|
89
103
|
cursor: 'pointer',
|
90
104
|
}}
|
91
105
|
onClick={addSchema}
|
@@ -7,7 +7,6 @@ import { I18nContext } from '../../contexts';
|
|
7
7
|
import {
|
8
8
|
uuid,
|
9
9
|
set,
|
10
|
-
arrayMove,
|
11
10
|
cloneDeep,
|
12
11
|
initShortCuts,
|
13
12
|
destroyShortCuts,
|
@@ -99,11 +98,12 @@ const TemplateEditor = ({
|
|
99
98
|
// Assign to reference
|
100
99
|
set(tgt, key, value);
|
101
100
|
if (key === 'type') {
|
101
|
+
const type = String(value);
|
102
102
|
// set default value, text or barcode
|
103
|
-
set(tgt, 'data',
|
103
|
+
set(tgt, 'data', getSampleByType(type));
|
104
104
|
// For barcodes, adjust the height to get the correct ratio.
|
105
|
-
if (value !== 'text'
|
106
|
-
set(tgt, 'height', getKeepRatioHeightByWidth(
|
105
|
+
if (value !== 'text') {
|
106
|
+
set(tgt, 'height', getKeepRatioHeightByWidth(type, tgt.width));
|
107
107
|
}
|
108
108
|
}
|
109
109
|
|
@@ -122,12 +122,12 @@ const TemplateEditor = ({
|
|
122
122
|
};
|
123
123
|
const timeTavel = (mode: 'undo' | 'redo') => {
|
124
124
|
const isUndo = mode === 'undo';
|
125
|
-
|
125
|
+
const stack = isUndo ? past : future;
|
126
|
+
if (stack.current.length <= 0) return;
|
126
127
|
(isUndo ? future : past).current.push(cloneDeep(schemasList[pageCursor]));
|
127
128
|
const s = cloneDeep(schemasList);
|
128
|
-
s[pageCursor] =
|
129
|
+
s[pageCursor] = stack.current.pop()!;
|
129
130
|
setSchemasList(s);
|
130
|
-
onEditEnd();
|
131
131
|
};
|
132
132
|
initShortCuts({
|
133
133
|
move: (command, isShift) => {
|
@@ -167,6 +167,7 @@ const TemplateEditor = ({
|
|
167
167
|
save: () => onSaveTemplate && onSaveTemplate(modifiedTemplate),
|
168
168
|
remove: () => removeSchemas(getActiveSchemas().map((s) => s.id)),
|
169
169
|
esc: onEditEnd,
|
170
|
+
selectAll: () => onEdit(schemasList[pageCursor].map((s) => document.getElementById(s.id)!)),
|
170
171
|
});
|
171
172
|
}, [
|
172
173
|
activeElements,
|
@@ -215,24 +216,14 @@ const TemplateEditor = ({
|
|
215
216
|
setTimeout(() => onEdit([document.getElementById(s.id)!]));
|
216
217
|
};
|
217
218
|
|
218
|
-
const onSortEnd = (
|
219
|
-
|
220
|
-
commitSchemas(movedSchema);
|
219
|
+
const onSortEnd = (sortedSchemas: SchemaForUI[]) => {
|
220
|
+
commitSchemas(sortedSchemas);
|
221
221
|
};
|
222
222
|
|
223
223
|
const onChangeHoveringSchemaId = (id: string | null) => {
|
224
224
|
setHoveringSchemaId(id);
|
225
225
|
};
|
226
226
|
|
227
|
-
const getLastActiveSchema = () => {
|
228
|
-
if (activeElements.length === 0) return getInitialSchema();
|
229
|
-
const last = activeElements[activeElements.length - 1];
|
230
|
-
|
231
|
-
return schemasList[pageCursor].find((s) => s.id === last.id) || getInitialSchema();
|
232
|
-
};
|
233
|
-
|
234
|
-
const activeSchema = getLastActiveSchema();
|
235
|
-
|
236
227
|
if (error) {
|
237
228
|
return <Error size={size} error={error} />;
|
238
229
|
}
|
@@ -245,16 +236,13 @@ const TemplateEditor = ({
|
|
245
236
|
height={mainRef.current ? mainRef.current.scrollHeight : 0}
|
246
237
|
size={size}
|
247
238
|
pageSize={pageSizes[pageCursor]}
|
248
|
-
|
239
|
+
activeElements={activeElements}
|
249
240
|
schemas={schemasList[pageCursor]}
|
250
|
-
activeSchema={activeSchema}
|
251
241
|
changeSchemas={changeSchemas}
|
252
242
|
onSortEnd={onSortEnd}
|
253
243
|
onEdit={(id: string) => {
|
254
244
|
const editingElem = document.getElementById(id);
|
255
|
-
|
256
|
-
onEdit([editingElem]);
|
257
|
-
}
|
245
|
+
editingElem && onEdit([editingElem]);
|
258
246
|
}}
|
259
247
|
onEditEnd={onEditEnd}
|
260
248
|
addSchema={addSchema}
|
package/src/components/Paper.tsx
CHANGED
@@ -47,9 +47,7 @@ const Paper = (porps: {
|
|
47
47
|
margin: `${RULER_HEIGHT * scale}px auto`,
|
48
48
|
position: 'relative',
|
49
49
|
backgroundImage: `url(${background})`,
|
50
|
-
backgroundSize:
|
51
|
-
backgroundPosition: 'center',
|
52
|
-
backgroundRepeat: 'no-repeat',
|
50
|
+
backgroundSize: `${paperSize.width}px ${paperSize.height}px`,
|
53
51
|
...paperSize,
|
54
52
|
}}
|
55
53
|
>
|
@@ -80,12 +80,11 @@ const Preview = ({ template, inputs, size, onChangeInput }: PreviewReactProps) =
|
|
80
80
|
backgrounds={backgrounds}
|
81
81
|
renderSchema={({ schema, index }) => {
|
82
82
|
const { key } = schema;
|
83
|
-
const data = input[key]
|
84
|
-
|
83
|
+
const data = input[key] || '';
|
85
84
|
return (
|
86
85
|
<SchemaUI
|
87
|
-
key={
|
88
|
-
schema={Object.assign(schema, {
|
86
|
+
key={schema.id}
|
87
|
+
schema={Object.assign(schema, { data })}
|
89
88
|
editable={editable}
|
90
89
|
placeholder={template.sampledata ? template.sampledata[0][key] : ''}
|
91
90
|
tabIndex={index + 100}
|
package/src/components/Root.tsx
CHANGED
@@ -29,16 +29,11 @@ const Root = ({ size, scale, children }: Props, ref: Ref<HTMLDivElement>) => {
|
|
29
29
|
return (
|
30
30
|
<div
|
31
31
|
ref={ref}
|
32
|
-
style={{
|
33
|
-
fontFamily: 'Arial, Helvetica, sans-serif',
|
34
|
-
position: 'relative',
|
35
|
-
background: 'rgb(74, 74, 74)',
|
36
|
-
overflowY: 'auto',
|
37
|
-
...size,
|
38
|
-
}}
|
32
|
+
style={{ position: 'relative', background: 'rgb(74, 74, 74)', overflowY: 'auto', ...size }}
|
39
33
|
>
|
40
34
|
<div
|
41
35
|
style={{
|
36
|
+
margin: '0 auto',
|
42
37
|
width: size.width - RULER_HEIGHT * scale,
|
43
38
|
height: size.height - RULER_HEIGHT * scale,
|
44
39
|
}}
|