@pdfme/ui 1.0.0-beta.8 → 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.
Files changed (44) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/index.js.LICENSE.txt +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/types/class.d.ts +1 -1
  5. package/dist/types/components/Designer/Sidebar/DetailView/ExampleInputEditor.d.ts +4 -1
  6. package/dist/types/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.d.ts +4 -1
  7. package/dist/types/components/Designer/Sidebar/DetailView/TextPropEditor.d.ts +4 -1
  8. package/dist/types/components/Designer/Sidebar/DetailView/TypeAndKeyEditor.d.ts +4 -1
  9. package/dist/types/components/Designer/Sidebar/DetailView/index.d.ts +4 -1
  10. package/dist/types/components/Designer/Sidebar/ListView/Item.d.ts +25 -0
  11. package/dist/types/components/Designer/Sidebar/ListView/SelectableSortableContainer.d.ts +3 -0
  12. package/dist/types/components/Designer/Sidebar/ListView/SelectableSortableItem.d.ts +14 -0
  13. package/dist/types/components/Designer/Sidebar/ListView/index.d.ts +3 -0
  14. package/dist/types/components/Designer/Sidebar/index.d.ts +2 -7
  15. package/dist/types/contexts.d.ts +1 -1
  16. package/dist/types/helper.d.ts +1 -1
  17. package/dist/types/hooks.d.ts +1 -0
  18. package/dist/types/i18n.d.ts +5 -2
  19. package/package.json +4 -3
  20. package/src/assets/icons/align-horizontal-center.svg +1 -0
  21. package/src/assets/icons/align-horizontal-left.svg +1 -0
  22. package/src/assets/icons/align-horizontal-right.svg +1 -0
  23. package/src/assets/icons/align-vertical-bottom.svg +1 -0
  24. package/src/assets/icons/align-vertical-middle.svg +1 -0
  25. package/src/assets/icons/align-vertical-top.svg +1 -0
  26. package/src/assets/icons/horizontal-distribute.svg +1 -0
  27. package/src/assets/icons/vertical-distribute.svg +1 -0
  28. package/src/components/Designer/Main/index.tsx +15 -7
  29. package/src/components/Designer/Sidebar/DetailView/ExampleInputEditor.tsx +4 -1
  30. package/src/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.tsx +107 -24
  31. package/src/components/Designer/Sidebar/DetailView/TextPropEditor.tsx +4 -1
  32. package/src/components/Designer/Sidebar/DetailView/TypeAndKeyEditor.tsx +2 -2
  33. package/src/components/Designer/Sidebar/DetailView/index.tsx +4 -1
  34. package/src/components/Designer/Sidebar/ListView/Item.tsx +113 -0
  35. package/src/components/Designer/Sidebar/ListView/SelectableSortableContainer.tsx +162 -0
  36. package/src/components/Designer/Sidebar/ListView/SelectableSortableItem.tsx +78 -0
  37. package/src/components/Designer/Sidebar/ListView/index.tsx +118 -0
  38. package/src/components/Designer/Sidebar/index.tsx +18 -6
  39. package/src/components/Designer/index.tsx +8 -22
  40. package/src/helper.ts +11 -10
  41. package/src/hooks.ts +11 -0
  42. package/src/i18n.ts +12 -7
  43. package/dist/types/components/Designer/Sidebar/ListView.d.ts +0 -3
  44. package/src/components/Designer/Sidebar/ListView.tsx +0 -202
@@ -1,202 +0,0 @@
1
- import React, { useContext, useState } from 'react';
2
- import { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc';
3
- import { SchemaForUI, Size } from '@pdfme/common';
4
- import { ZOOM, RULER_HEIGHT, SIDEBAR_WIDTH } from '../../../constants';
5
- import { I18nContext } from '../../../contexts';
6
- import Divider from '../../Divider';
7
- import dragIcon from '../../../assets/icons/drag.svg';
8
- import warningIcon from '../../../assets/icons/warning.svg';
9
- import { SidebarProps } from '.';
10
-
11
- const isTouchable = () => true;
12
-
13
- const DragHandle = SortableHandle(() => (
14
- <button style={{ padding: 0, background: 'none', border: 'none', display: 'flex' }}>
15
- <img style={{ cursor: 'grab' }} src={dragIcon} width={15} alt="Drag icon" />
16
- </button>
17
- ));
18
-
19
- const SortableItem = SortableElement(
20
- (props: { schemas: SchemaForUI[]; schema: SchemaForUI; onEdit: (id: string) => void }) => {
21
- const { schemas, schema, onEdit } = props;
22
- const i18n = useContext(I18nContext);
23
-
24
- const sc = schema;
25
- let status: '' | 'is-warning' | 'is-danger' = '';
26
- if (!sc.key) {
27
- status = 'is-warning';
28
- } else if (schemas.find((s) => sc.key && s.key === sc.key && s.id !== sc.id)) {
29
- status = 'is-danger';
30
- }
31
-
32
- const touchable = isTouchable();
33
-
34
- const getTitle = () => {
35
- if (status === 'is-warning') {
36
- return i18n('plsInputName');
37
- }
38
- if (status === 'is-danger') {
39
- return i18n('fieldMustUniq');
40
- }
41
-
42
- return i18n('edit');
43
- };
44
-
45
- return (
46
- <div
47
- key={sc.id}
48
- style={{
49
- paddingLeft: 5,
50
- display: 'flex',
51
- alignItems: 'center',
52
- justifyContent: 'space-between',
53
- }}
54
- >
55
- <DragHandle />
56
- <button
57
- disabled={!touchable}
58
- className={`${status}`}
59
- style={{
60
- padding: 5,
61
- margin: 5,
62
- width: '100%',
63
- display: 'flex',
64
- background: 'none',
65
- border: 'none',
66
- textAlign: 'left',
67
- cursor: 'pointer',
68
- }}
69
- onClick={() => onEdit(sc.id)}
70
- title={getTitle()}
71
- >
72
- <span
73
- style={{
74
- marginRight: '1rem',
75
- width: 180,
76
- color: '#333',
77
- overflow: 'hidden',
78
- whiteSpace: 'nowrap',
79
- textOverflow: 'ellipsis',
80
- }}
81
- >
82
- {status === '' ? (
83
- sc.key
84
- ) : (
85
- <span style={{ display: 'flex', alignItems: 'center' }}>
86
- <img
87
- alt="Warning icon"
88
- src={warningIcon}
89
- width={15}
90
- style={{ marginRight: '0.5rem' }}
91
- />
92
- {status === 'is-warning' ? i18n('noKeyName') : sc.key}
93
- {status === 'is-danger' ? i18n('notUniq') : ''}
94
- </span>
95
- )}
96
- </span>
97
- </button>
98
- </div>
99
- );
100
- }
101
- );
102
-
103
- const SortableList = SortableContainer(
104
- (props: {
105
- scale: number;
106
- schemas: SchemaForUI[];
107
- onEdit: (id: string) => void;
108
- size: Size;
109
- hoveringSchemaId: string | null;
110
- onChangeHoveringSchemaId: (id: string | null) => void;
111
- }) => {
112
- const { scale, schemas, onEdit, size, hoveringSchemaId, onChangeHoveringSchemaId } = props;
113
- const i18n = useContext(I18nContext);
114
-
115
- return (
116
- <div style={{ height: size.height - RULER_HEIGHT * ZOOM - 125, overflowY: 'auto' }}>
117
- {schemas.length > 0 ? (
118
- schemas.map((s, i) => (
119
- <div
120
- key={s.id}
121
- style={{
122
- border: `1px solid ${s.id === hoveringSchemaId ? '#18a0fb' : 'transparent'}`,
123
- // Reasons for adapting transform
124
- // https://github.com/clauderic/react-sortable-hoc/issues/386
125
- width: SIDEBAR_WIDTH * scale,
126
- transform: `scale(${1 - scale + 1})`,
127
- transformOrigin: 'top left',
128
- }}
129
- onMouseEnter={() => onChangeHoveringSchemaId(s.id)}
130
- onMouseLeave={() => onChangeHoveringSchemaId(null)}
131
- >
132
- <SortableItem
133
- disabled={!isTouchable()}
134
- index={i}
135
- schemas={schemas}
136
- schema={s}
137
- onEdit={onEdit}
138
- />
139
- </div>
140
- ))
141
- ) : (
142
- <p style={{ textAlign: 'center' }}>{i18n('plsAddNewField')}</p>
143
- )}
144
- </div>
145
- );
146
- }
147
- );
148
-
149
- const ListView = (
150
- props: Pick<
151
- SidebarProps,
152
- | 'scale'
153
- | 'schemas'
154
- | 'onSortEnd'
155
- | 'onEdit'
156
- | 'size'
157
- | 'hoveringSchemaId'
158
- | 'onChangeHoveringSchemaId'
159
- >
160
- ) => {
161
- const { scale, schemas, onSortEnd, onEdit, size, hoveringSchemaId, onChangeHoveringSchemaId } =
162
- props;
163
- const i18n = useContext(I18nContext);
164
- const [sorting, setSorting] = useState(false);
165
-
166
- return (
167
- <div>
168
- <div style={{ height: 40, display: 'flex', alignItems: 'center' }}>
169
- <p style={{ textAlign: 'center', width: '100%', fontWeight: 'bold' }}>
170
- {i18n('fieldsList')}
171
- </p>
172
- </div>
173
- <Divider />
174
- <div style={{ fontSize: '0.9rem' }}>
175
- <SortableList
176
- scale={scale}
177
- size={size}
178
- hoveringSchemaId={sorting ? null : hoveringSchemaId}
179
- onChangeHoveringSchemaId={(arg) => !sorting && onChangeHoveringSchemaId(arg)}
180
- updateBeforeSortStart={(node: any) => {
181
- if (node.node.style) {
182
- node.node.style.zIndex = '9999';
183
- }
184
- }}
185
- useDragHandle
186
- axis="y"
187
- lockAxis="y"
188
- schemas={schemas}
189
- onSortStart={() => setSorting(true)}
190
- onSortEnd={(arg) => {
191
- setSorting(false);
192
- onSortEnd(arg);
193
- }}
194
- onEdit={onEdit}
195
- />
196
- <Divider />
197
- </div>
198
- </div>
199
- );
200
- };
201
-
202
- export default ListView;