@pdfme/ui 1.0.0-beta.8 → 1.0.1

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 (52) hide show
  1. package/README.md +0 -2
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.LICENSE.txt +2 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/types/class.d.ts +5 -4
  6. package/dist/types/components/Designer/Sidebar/DetailView/ExampleInputEditor.d.ts +4 -1
  7. package/dist/types/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.d.ts +4 -1
  8. package/dist/types/components/Designer/Sidebar/DetailView/TextPropEditor.d.ts +4 -1
  9. package/dist/types/components/Designer/Sidebar/DetailView/TypeAndKeyEditor.d.ts +4 -1
  10. package/dist/types/components/Designer/Sidebar/DetailView/index.d.ts +4 -1
  11. package/dist/types/components/Designer/Sidebar/ListView/Item.d.ts +25 -0
  12. package/dist/types/components/Designer/Sidebar/ListView/SelectableSortableContainer.d.ts +3 -0
  13. package/dist/types/components/Designer/Sidebar/ListView/SelectableSortableItem.d.ts +14 -0
  14. package/dist/types/components/Designer/Sidebar/ListView/index.d.ts +3 -0
  15. package/dist/types/components/Designer/Sidebar/index.d.ts +2 -7
  16. package/dist/types/contexts.d.ts +1 -1
  17. package/dist/types/helper.d.ts +1 -1
  18. package/dist/types/hooks.d.ts +1 -0
  19. package/dist/types/i18n.d.ts +5 -2
  20. package/package.json +4 -3
  21. package/src/Designer.tsx +2 -1
  22. package/src/assets/icons/align-horizontal-center.svg +1 -0
  23. package/src/assets/icons/align-horizontal-left.svg +1 -0
  24. package/src/assets/icons/align-horizontal-right.svg +1 -0
  25. package/src/assets/icons/align-vertical-bottom.svg +1 -0
  26. package/src/assets/icons/align-vertical-middle.svg +1 -0
  27. package/src/assets/icons/align-vertical-top.svg +1 -0
  28. package/src/assets/icons/horizontal-distribute.svg +1 -0
  29. package/src/assets/icons/vertical-distribute.svg +1 -0
  30. package/src/class.ts +22 -2
  31. package/src/components/Designer/Main/index.tsx +16 -8
  32. package/src/components/Designer/Sidebar/DetailView/ExampleInputEditor.tsx +4 -1
  33. package/src/components/Designer/Sidebar/DetailView/PositionAndSizeEditor.tsx +107 -24
  34. package/src/components/Designer/Sidebar/DetailView/TextPropEditor.tsx +4 -1
  35. package/src/components/Designer/Sidebar/DetailView/TypeAndKeyEditor.tsx +2 -2
  36. package/src/components/Designer/Sidebar/DetailView/index.tsx +6 -3
  37. package/src/components/Designer/Sidebar/ListView/Item.tsx +113 -0
  38. package/src/components/Designer/Sidebar/ListView/SelectableSortableContainer.tsx +162 -0
  39. package/src/components/Designer/Sidebar/ListView/SelectableSortableItem.tsx +78 -0
  40. package/src/components/Designer/Sidebar/ListView/index.tsx +119 -0
  41. package/src/components/Designer/Sidebar/index.tsx +22 -8
  42. package/src/components/Designer/index.tsx +8 -22
  43. package/src/components/Error.tsx +2 -2
  44. package/src/components/Paper.tsx +10 -0
  45. package/src/components/Preview/index.tsx +1 -1
  46. package/src/components/Schemas/BarcodeSchema.tsx +13 -13
  47. package/src/components/Schemas/TextSchema.tsx +5 -2
  48. package/src/helper.ts +12 -10
  49. package/src/hooks.ts +11 -0
  50. package/src/i18n.ts +12 -7
  51. package/dist/types/components/Designer/Sidebar/ListView.d.ts +0 -3
  52. package/src/components/Designer/Sidebar/ListView.tsx +0 -202
@@ -41,7 +41,7 @@ const SampleBarcode = ({ schema }: { schema: BarcodeSchema }) => (
41
41
 
42
42
  const ErrorBarcode = () => (
43
43
  <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%' }}>
44
- <p
44
+ <span
45
45
  style={{
46
46
  color: 'white',
47
47
  background: 'red',
@@ -52,17 +52,23 @@ const ErrorBarcode = () => (
52
52
  }}
53
53
  >
54
54
  ERROR
55
- </p>
55
+ </span>
56
56
  </div>
57
57
  );
58
58
 
59
- const ErrorOrSampleBarcode = ({ schema, value }: { schema: BarcodeSchema; value: string }) =>
60
- validateBarcodeInput(schema.type as BarCodeType, value) ? (
59
+ const BarcodePreview = (props: { schema: BarcodeSchema; value: string }) => {
60
+ const { schema, value } = props;
61
+
62
+ if (value.length === 0) {
63
+ return null;
64
+ }
65
+
66
+ return validateBarcodeInput(schema.type as BarCodeType, value) ? (
61
67
  <SampleBarcode schema={schema} />
62
68
  ) : (
63
69
  <ErrorBarcode />
64
70
  );
65
-
71
+ };
66
72
  type Props = SchemaUIProps & { schema: BarcodeSchema };
67
73
 
68
74
  const BarcodeSchemaUI = (
@@ -95,6 +101,7 @@ const BarcodeSchemaUI = (
95
101
  display: 'flex',
96
102
  alignItems: 'center',
97
103
  justifyContent: 'center',
104
+ fontFamily: "'Open Sans', sans-serif",
98
105
  }}
99
106
  >
100
107
  {editable ? (
@@ -111,14 +118,7 @@ const BarcodeSchemaUI = (
111
118
  <span>{value}</span>
112
119
  </div>
113
120
  )}
114
-
115
- {value ? (
116
- <ErrorOrSampleBarcode value={value} schema={schema} />
117
- ) : editable ? (
118
- <SampleBarcode schema={schema} />
119
- ) : (
120
- <ErrorBarcode />
121
- )}
121
+ <BarcodePreview value={value} schema={schema} />
122
122
  </div>
123
123
  );
124
124
  };
@@ -17,19 +17,22 @@ const TextSchemaUI = (
17
17
  ref: Ref<HTMLTextAreaElement>
18
18
  ) => {
19
19
  const style: React.CSSProperties = {
20
+ padding: 0,
20
21
  resize: 'none',
22
+ position: 'absolute',
21
23
  fontFamily: schema.fontName ?? 'inherit',
22
24
  height: schema.height * ZOOM,
23
- width: schema.width * ZOOM,
25
+ // Increase the width by 1 point. (0.75 pixels)
26
+ width: (schema.width + (schema.characterSpacing ?? DEFAULT_CHARACTER_SPACING) * 0.75) * ZOOM,
24
27
  textAlign: schema.alignment ?? DEFAULT_ALIGNMENT,
25
28
  fontSize: `${schema.fontSize ?? DEFAULT_FONT_SIZE}pt`,
26
29
  letterSpacing: `${schema.characterSpacing ?? DEFAULT_CHARACTER_SPACING}pt`,
27
- fontFeatureSettings: `"palt"`,
28
30
  lineHeight: `${schema.lineHeight ?? DEFAULT_LINE_HEIGHT}em`,
29
31
  whiteSpace: 'pre-line',
30
32
  wordBreak: 'break-all',
31
33
  background: 'transparent',
32
34
  border: 'none',
35
+ outline: 'none',
33
36
  color: schema.fontColor ? schema.fontColor : DEFAULT_FONT_COLOR,
34
37
  };
35
38
 
package/src/helper.ts CHANGED
@@ -61,15 +61,6 @@ export const round = (number: number, precision: number) => {
61
61
  return shift(Math.round(shift(number, precision, false)), precision, true);
62
62
  };
63
63
 
64
- export const arrayMove = <T>(array: T[], from: number, to: number): T[] => {
65
- array = array.slice();
66
- const startIndex = to < 0 ? array.length + to : to;
67
- const [item] = array.splice(from, 1);
68
- array.splice(startIndex, 0, item);
69
-
70
- return array;
71
- };
72
-
73
64
  export const cloneDeep = <T>(value: T): T => JSON.parse(JSON.stringify(value));
74
65
 
75
66
  export const flatten = <T>(arr: T[][]): T[] => ([] as T[]).concat(...arr);
@@ -96,6 +87,8 @@ const undoWin = 'ctrl+z';
96
87
  const undoMac = 'command+z';
97
88
  const saveWin = 'ctrl+s';
98
89
  const saveMac = 'command+s';
90
+ const selectAllWin = 'ctrl+a';
91
+ const selectAllMac = 'command+a';
99
92
 
100
93
  const keys = [
101
94
  up,
@@ -119,6 +112,8 @@ const keys = [
119
112
  undoMac,
120
113
  saveWin,
121
114
  saveMac,
115
+ selectAllWin,
116
+ selectAllMac,
122
117
  ];
123
118
 
124
119
  export const initShortCuts = (arg: {
@@ -130,6 +125,7 @@ export const initShortCuts = (arg: {
130
125
  redo: () => void;
131
126
  undo: () => void;
132
127
  save: () => void;
128
+ selectAll: () => void;
133
129
  }) => {
134
130
  hotkeys(keys.join(), (e, handler) => {
135
131
  switch (handler.shortcut) {
@@ -181,6 +177,11 @@ export const initShortCuts = (arg: {
181
177
  e.preventDefault();
182
178
  arg.save();
183
179
  break;
180
+ case selectAllWin:
181
+ case selectAllMac:
182
+ e.preventDefault();
183
+ arg.selectAll();
184
+ break;
184
185
  default:
185
186
  break;
186
187
  }
@@ -351,6 +352,7 @@ export const templateSchemas2SchemasList = async (_template: Template) => {
351
352
 
352
353
  export const fmtTemplate = (template: Template, schemasList: SchemaForUI[][]): Template => {
353
354
  const schemaAddedTemplate: Template = {
355
+ ...template,
354
356
  schemas: cloneDeep(schemasList).map((schema) =>
355
357
  schema.reduce((acc, cur) => {
356
358
  const k = cur.key;
@@ -503,7 +505,7 @@ export const moveCommandToChangeSchemasArg = (props: {
503
505
  break;
504
506
  }
505
507
 
506
- return value;
508
+ return value > 0 ? value : 0;
507
509
  };
508
510
 
509
511
  return activeSchemas.map((as) => {
package/src/hooks.ts CHANGED
@@ -105,3 +105,14 @@ export const useScrollPageCursor = ({
105
105
  };
106
106
  }, [rootRef, onScroll]);
107
107
  };
108
+
109
+ export const useMountStatus = () => {
110
+ const [isMounted, setIsMounted] = useState(false);
111
+
112
+ useEffect(() => {
113
+ const timeout = setTimeout(() => setIsMounted(true), 500);
114
+ return () => clearTimeout(timeout);
115
+ }, []);
116
+
117
+ return isMounted;
118
+ };
package/src/i18n.ts CHANGED
@@ -4,6 +4,7 @@ import { DEFAULT_LANG } from './constants';
4
4
  type DictEn = typeof dictEn;
5
5
 
6
6
  const dictEn = {
7
+ cancel: 'Cancel',
7
8
  field: 'field',
8
9
  fieldName: 'Name',
9
10
  require: 'Required',
@@ -20,17 +21,20 @@ const dictEn = {
20
21
  addNewField: 'Add new field',
21
22
  editField: 'Edit Field',
22
23
  type: 'Type',
23
- previewWarnMsg: 'Preview is not available on iOS devices.',
24
- previewErrMsg:
25
- 'An error occurred during the PDF creation process. (Characters that are not in the Helvetica font are not available)',
26
24
  goToFirst: 'Go to first',
27
25
  goToPrevious: 'Back',
28
26
  goToNext: 'Next',
29
27
  goToEnd: 'Go to end',
30
- errorOccurred: 'An error occurred.',
28
+ select: 'Select',
29
+ errorOccurred: 'An error occurred',
30
+ errorBulkUpdateFieldName:
31
+ 'Cannot commit the change because the number of items has been changed.',
32
+ commitBulkUpdateFieldName: 'Commit Changes',
33
+ bulkUpdateFieldName: 'Bulk update field names',
31
34
  };
32
35
 
33
36
  const dictJa: { [key in keyof DictEn]: string } = {
37
+ cancel: 'キャンセル',
34
38
  field: '入力項目',
35
39
  fieldName: '項目名',
36
40
  require: '必須',
@@ -47,14 +51,15 @@ const dictJa: { [key in keyof DictEn]: string } = {
47
51
  addNewField: '入力項目を追加',
48
52
  editField: '入力項目を編集',
49
53
  type: 'タイプ',
50
- previewWarnMsg: 'iOS端末ではプレビューができません。',
51
- previewErrMsg:
52
- 'PDF作成処理でエラーが発生しました。お手数ですがコンタクトからお問い合わせください。',
53
54
  goToFirst: '最初に戻る',
54
55
  goToPrevious: '1つ戻る',
55
56
  goToNext: '1つ進む',
56
57
  goToEnd: '最後に進む',
58
+ select: '選択',
57
59
  errorOccurred: 'エラーが発生しました',
60
+ errorBulkUpdateFieldName: '項目数が変更されているため変更をコミットできません。',
61
+ commitBulkUpdateFieldName: '変更を反映',
62
+ bulkUpdateFieldName: '項目名を一括変更',
58
63
  };
59
64
 
60
65
  const i18n = (lang: Lang, key: keyof DictEn) => (lang === DEFAULT_LANG ? dictEn[key] : dictJa[key]);
@@ -1,3 +0,0 @@
1
- import { SidebarProps } from '.';
2
- declare const ListView: (props: Pick<SidebarProps, 'scale' | 'schemas' | 'onSortEnd' | 'onEdit' | 'size' | 'hoveringSchemaId' | 'onChangeHoveringSchemaId'>) => JSX.Element;
3
- export default ListView;
@@ -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;