@servicetitan/dte-pdf-editor 1.55.0 → 1.57.0
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/README.md +25 -1
- package/dist/components/display-conditions/condition-row.d.ts.map +1 -1
- package/dist/components/display-conditions/condition-row.js +5 -1
- package/dist/components/display-conditions/condition-row.js.map +1 -1
- package/dist/components/display-conditions/condition-value-control.d.ts +14 -2
- package/dist/components/display-conditions/condition-value-control.d.ts.map +1 -1
- package/dist/components/display-conditions/condition-value-control.js +84 -13
- package/dist/components/display-conditions/condition-value-control.js.map +1 -1
- package/dist/components/pdf-fields-overlay/pdf-overlay-field-calculated.d.ts.map +1 -1
- package/dist/components/pdf-fields-overlay/pdf-overlay-field-calculated.js +2 -2
- package/dist/components/pdf-fields-overlay/pdf-overlay-field-calculated.js.map +1 -1
- package/dist/components/pdf-fields-overlay/pdf-overlay-field-data-model.d.ts.map +1 -1
- package/dist/components/pdf-fields-overlay/pdf-overlay-field-data-model.js +2 -1
- package/dist/components/pdf-fields-overlay/pdf-overlay-field-data-model.js.map +1 -1
- package/dist/components/pdf-fields-overlay/pdf-overlay-field-e-sign.d.ts.map +1 -1
- package/dist/components/pdf-fields-overlay/pdf-overlay-field-e-sign.js +1 -1
- package/dist/components/pdf-fields-overlay/pdf-overlay-field-e-sign.js.map +1 -1
- package/dist/components/pdf-fields-overlay/pdf-overlay-field-fillable.d.ts.map +1 -1
- package/dist/components/pdf-fields-overlay/pdf-overlay-field-fillable.js +14 -7
- package/dist/components/pdf-fields-overlay/pdf-overlay-field-fillable.js.map +1 -1
- package/dist/components/pdf-fields-overlay/pdf-overlay-field-generic.js +9 -1
- package/dist/components/pdf-fields-overlay/pdf-overlay-field-generic.js.map +1 -1
- package/dist/components/pdf-fields-overlay/pdf-overlay-field.d.ts.map +1 -1
- package/dist/components/pdf-fields-overlay/pdf-overlay-field.js +5 -11
- package/dist/components/pdf-fields-overlay/pdf-overlay-field.js.map +1 -1
- package/dist/components/pdf-view/pdf-view-calculated.d.ts.map +1 -1
- package/dist/components/pdf-view/pdf-view-calculated.js +2 -2
- package/dist/components/pdf-view/pdf-view-calculated.js.map +1 -1
- package/dist/components/pdf-view/pdf-view-data-model.js +2 -2
- package/dist/components/pdf-view/pdf-view-data-model.js.map +1 -1
- package/dist/components/pdf-view/pdf-view-e-sign.d.ts.map +1 -1
- package/dist/components/pdf-view/pdf-view-e-sign.js +1 -1
- package/dist/components/pdf-view/pdf-view-e-sign.js.map +1 -1
- package/dist/components/pdf-view/pdf-view-field-container.d.ts.map +1 -1
- package/dist/components/pdf-view/pdf-view-field-container.js +5 -15
- package/dist/components/pdf-view/pdf-view-field-container.js.map +1 -1
- package/dist/components/pdf-view/pdf-view-fillable.d.ts.map +1 -1
- package/dist/components/pdf-view/pdf-view-fillable.js +22 -33
- package/dist/components/pdf-view/pdf-view-fillable.js.map +1 -1
- package/dist/components/pdf-view/pdf-view-generic.js +1 -1
- package/dist/components/pdf-view/pdf-view-generic.js.map +1 -1
- package/dist/components/pdf-view/pdf-view.d.ts.map +1 -1
- package/dist/components/pdf-view/pdf-view.js +1 -1
- package/dist/components/pdf-view/pdf-view.js.map +1 -1
- package/dist/constants/field.constants.d.ts +3 -0
- package/dist/constants/field.constants.d.ts.map +1 -1
- package/dist/constants/field.constants.js +3 -0
- package/dist/constants/field.constants.js.map +1 -1
- package/dist/hooks/useLookupOptions.d.ts +24 -8
- package/dist/hooks/useLookupOptions.d.ts.map +1 -1
- package/dist/hooks/useLookupOptions.js +47 -9
- package/dist/hooks/useLookupOptions.js.map +1 -1
- package/dist/interface/host-events.d.ts +27 -10
- package/dist/interface/host-events.d.ts.map +1 -1
- package/dist/interface/host-events.js +10 -10
- package/dist/interface/host-events.js.map +1 -1
- package/dist/interface/types.d.ts +8 -0
- package/dist/interface/types.d.ts.map +1 -1
- package/dist/interface/types.js.map +1 -1
- package/dist/utils/field/get-field-bounds-style.utils.d.ts +20 -0
- package/dist/utils/field/get-field-bounds-style.utils.d.ts.map +1 -0
- package/dist/utils/field/get-field-bounds-style.utils.js +53 -0
- package/dist/utils/field/get-field-bounds-style.utils.js.map +1 -0
- package/dist/utils/field/get-field-text-clip.utils.d.ts +13 -0
- package/dist/utils/field/get-field-text-clip.utils.d.ts.map +1 -0
- package/dist/utils/field/get-field-text-clip.utils.js +25 -0
- package/dist/utils/field/get-field-text-clip.utils.js.map +1 -0
- package/dist/utils/field/get-field-typography.utils.d.ts +10 -0
- package/dist/utils/field/get-field-typography.utils.d.ts.map +1 -0
- package/dist/utils/field/get-field-typography.utils.js +20 -0
- package/dist/utils/field/get-field-typography.utils.js.map +1 -0
- package/dist/utils/field/index.d.ts +3 -0
- package/dist/utils/field/index.d.ts.map +1 -1
- package/dist/utils/field/index.js +3 -0
- package/dist/utils/field/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/display-conditions/condition-row.tsx +8 -1
- package/src/components/display-conditions/condition-value-control.tsx +126 -39
- package/src/components/pdf-fields-overlay/pdf-overlay-field-calculated.tsx +5 -2
- package/src/components/pdf-fields-overlay/pdf-overlay-field-data-model.tsx +2 -1
- package/src/components/pdf-fields-overlay/pdf-overlay-field-e-sign.tsx +3 -1
- package/src/components/pdf-fields-overlay/pdf-overlay-field-fillable.tsx +28 -8
- package/src/components/pdf-fields-overlay/pdf-overlay-field-generic.tsx +9 -1
- package/src/components/pdf-fields-overlay/pdf-overlay-field.tsx +9 -13
- package/src/components/pdf-view/pdf-view-calculated.tsx +9 -2
- package/src/components/pdf-view/pdf-view-data-model.tsx +2 -2
- package/src/components/pdf-view/pdf-view-e-sign.tsx +3 -4
- package/src/components/pdf-view/pdf-view-field-container.tsx +6 -16
- package/src/components/pdf-view/pdf-view-fillable.tsx +29 -28
- package/src/components/pdf-view/pdf-view-generic.tsx +1 -1
- package/src/components/pdf-view/pdf-view.tsx +4 -1
- package/src/constants/field.constants.ts +5 -0
- package/src/hooks/useLookupOptions.ts +76 -14
- package/src/interface/host-events.ts +27 -15
- package/src/interface/types.ts +8 -0
- package/src/styles/inline-editable.css +1 -0
- package/src/styles/pdf-field-overlay.css +80 -27
- package/src/utils/field/__tests__/get-field-bounds-style.utils.test.ts +50 -0
- package/src/utils/field/__tests__/get-field-text-clip.utils.test.ts +43 -0
- package/src/utils/field/__tests__/get-field-typography.utils.test.ts +56 -0
- package/src/utils/field/get-field-bounds-style.utils.ts +65 -0
- package/src/utils/field/get-field-text-clip.utils.ts +31 -0
- package/src/utils/field/get-field-typography.utils.ts +23 -0
- package/src/utils/field/index.ts +3 -0
|
@@ -11,38 +11,34 @@
|
|
|
11
11
|
pointer-events: auto;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
font-size: var(--typescale-1, 14px);
|
|
20
|
-
padding: var(--spacing-half, 4px);
|
|
21
|
-
box-sizing: content-box;
|
|
14
|
+
/* Editor-only chrome. Layout metrics come from getFieldBoundsStyle. */
|
|
15
|
+
.dte-pdf-field-editor {
|
|
16
|
+
outline: 1px dashed #999;
|
|
17
|
+
outline-offset: 0;
|
|
18
|
+
border: none;
|
|
22
19
|
pointer-events: auto;
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
.dte-pdf-field.--selected {
|
|
26
|
-
|
|
22
|
+
.dte-pdf-field-editor.--selected {
|
|
23
|
+
outline: 2px solid var(--border-color-active);
|
|
27
24
|
cursor: move;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
|
-
.dte-pdf-field.--unselected {
|
|
27
|
+
.dte-pdf-field-editor.--unselected {
|
|
31
28
|
cursor: pointer;
|
|
32
29
|
}
|
|
33
30
|
|
|
34
|
-
.dte-pdf-field.--dragging {
|
|
31
|
+
.dte-pdf-field-editor.--dragging {
|
|
35
32
|
opacity: 0.5;
|
|
36
|
-
will-change: left, top;
|
|
37
33
|
}
|
|
38
34
|
|
|
39
|
-
.dte-pdf-field.--colored:not(.--selected) {
|
|
40
|
-
|
|
35
|
+
.dte-pdf-field-editor.--colored:not(.--selected) {
|
|
36
|
+
outline-color: var(--border-color-active) !important;
|
|
41
37
|
box-shadow: 0 0 2px 0 var(--border-color-active);
|
|
42
38
|
}
|
|
43
39
|
|
|
44
|
-
.dte-pdf-field.--error {
|
|
45
|
-
|
|
40
|
+
.dte-pdf-field-editor.--error {
|
|
41
|
+
outline-color: var(--danger) !important;
|
|
46
42
|
box-shadow: 0 0 4px 0 var(--danger);
|
|
47
43
|
}
|
|
48
44
|
|
|
@@ -82,38 +78,95 @@
|
|
|
82
78
|
height: 20px;
|
|
83
79
|
}
|
|
84
80
|
|
|
85
|
-
.dte-pdf-field:hover .dte-add-field-button {
|
|
81
|
+
.dte-pdf-field-editor:hover .dte-add-field-button {
|
|
86
82
|
display: block;
|
|
87
83
|
}
|
|
88
84
|
|
|
89
85
|
.dte-pdf-field-view {
|
|
90
86
|
border: none;
|
|
87
|
+
outline: none;
|
|
91
88
|
cursor: default;
|
|
89
|
+
pointer-events: auto;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.dte-pdf-field-content {
|
|
93
|
+
width: 100%;
|
|
94
|
+
min-width: 0;
|
|
95
|
+
min-height: 0;
|
|
92
96
|
overflow: hidden;
|
|
97
|
+
line-height: 1;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/*
|
|
101
|
+
* Printed PDF text modes (no ellipsis — hard clip like PdfSharp).
|
|
102
|
+
*/
|
|
103
|
+
.dte-pdf-field-text--single-line {
|
|
104
|
+
width: 100%;
|
|
105
|
+
min-width: 0;
|
|
106
|
+
line-height: 1;
|
|
93
107
|
white-space: nowrap;
|
|
94
|
-
|
|
95
|
-
justify-content: left;
|
|
96
|
-
text-overflow: ellipsis;
|
|
108
|
+
overflow: hidden;
|
|
97
109
|
}
|
|
98
110
|
|
|
99
|
-
.dte-pdf-field-
|
|
100
|
-
|
|
101
|
-
|
|
111
|
+
.dte-pdf-field-text--multiline {
|
|
112
|
+
width: 100%;
|
|
113
|
+
height: 100%;
|
|
114
|
+
min-width: 0;
|
|
115
|
+
min-height: 0;
|
|
116
|
+
line-height: 1;
|
|
117
|
+
white-space: pre-wrap;
|
|
118
|
+
overflow-wrap: break-word;
|
|
119
|
+
overflow: hidden;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.dte-pdf-field-text--wrapped {
|
|
123
|
+
width: 100%;
|
|
124
|
+
min-width: 0;
|
|
125
|
+
line-height: 1;
|
|
102
126
|
white-space: normal;
|
|
127
|
+
overflow-wrap: break-word;
|
|
103
128
|
overflow: hidden;
|
|
104
|
-
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.dte-pdf-field-value {
|
|
132
|
+
color: #333;
|
|
133
|
+
font: inherit;
|
|
105
134
|
}
|
|
106
135
|
|
|
107
136
|
.dte-pdf-field-fillable {
|
|
108
137
|
width: 100%;
|
|
109
138
|
height: 100%;
|
|
139
|
+
min-width: 0;
|
|
140
|
+
min-height: 0;
|
|
141
|
+
box-sizing: border-box;
|
|
110
142
|
background: inherit;
|
|
111
143
|
border: none;
|
|
112
|
-
|
|
113
|
-
margin: var(--spacing-0
|
|
144
|
+
padding: var(--spacing-0);
|
|
145
|
+
margin: var(--spacing-0);
|
|
146
|
+
line-height: 1;
|
|
114
147
|
font-size: inherit;
|
|
115
148
|
}
|
|
116
149
|
|
|
150
|
+
.dte-pdf-field-editor .dte-pdf-field-fillable {
|
|
151
|
+
pointer-events: none;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.dte-pdf-field-view .dte-pdf-field-fillable {
|
|
155
|
+
pointer-events: auto;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.dte-pdf-field-fillable.dte-pdf-field-text--single-line {
|
|
159
|
+
white-space: nowrap;
|
|
160
|
+
overflow: hidden;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.dte-pdf-field-fillable.dte-pdf-field-text--multiline {
|
|
164
|
+
white-space: pre-wrap;
|
|
165
|
+
overflow-wrap: break-word;
|
|
166
|
+
overflow: hidden;
|
|
167
|
+
resize: none;
|
|
168
|
+
}
|
|
169
|
+
|
|
117
170
|
.dte-pdf-field-generic-table {
|
|
118
171
|
padding: var(--spacing-0, 0);
|
|
119
172
|
margin: var(--spacing-0, 0);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { FieldTypeEnum, PdfField } from '../../../interface/types';
|
|
2
|
+
import { getFieldBoundsStyle } from '../get-field-bounds-style.utils';
|
|
3
|
+
|
|
4
|
+
const buildField = (overrides: Partial<PdfField> = {}): PdfField => ({
|
|
5
|
+
id: 'field-1',
|
|
6
|
+
type: FieldTypeEnum.fillable,
|
|
7
|
+
subType: 'text',
|
|
8
|
+
x: 10,
|
|
9
|
+
y: 20,
|
|
10
|
+
page: 1,
|
|
11
|
+
label: 'Label',
|
|
12
|
+
width: 200,
|
|
13
|
+
height: 25,
|
|
14
|
+
...overrides,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('getFieldBoundsStyle', () => {
|
|
18
|
+
const subject = (field: PdfField, options?: Parameters<typeof getFieldBoundsStyle>[1]) =>
|
|
19
|
+
getFieldBoundsStyle(field, options);
|
|
20
|
+
|
|
21
|
+
test('positions the field using page offset and field coordinates', () => {
|
|
22
|
+
expect(subject(buildField(), { pageOffset: { left: 5, top: 15 } })).toMatchObject({
|
|
23
|
+
left: 15,
|
|
24
|
+
top: 35,
|
|
25
|
+
width: 200,
|
|
26
|
+
height: 25,
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('matches printed PDF clip rect layout', () => {
|
|
31
|
+
expect(subject(buildField())).toMatchObject({
|
|
32
|
+
boxSizing: 'border-box',
|
|
33
|
+
padding: 0,
|
|
34
|
+
alignItems: 'flex-start',
|
|
35
|
+
justifyContent: 'flex-start',
|
|
36
|
+
overflow: 'hidden',
|
|
37
|
+
lineHeight: 1,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('converts font size from points to editor pixels', () => {
|
|
42
|
+
const style = subject(buildField({ styles: { fontSize: 12 } }));
|
|
43
|
+
expect(style.fontSize).toBe(`${(12 * 980) / 612}px`);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('omits font size for field types that do not support it', () => {
|
|
47
|
+
const style = subject(buildField({ type: FieldTypeEnum.eSign, subType: 'signature' }));
|
|
48
|
+
expect(style.fontSize).toBeUndefined();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { FieldTypeEnum, PdfField } from '../../../interface/types';
|
|
2
|
+
import { getFieldTextClipClassName, getFieldTextClipMode } from '../get-field-text-clip.utils';
|
|
3
|
+
|
|
4
|
+
const buildField = (overrides: Partial<PdfField> = {}): PdfField => ({
|
|
5
|
+
id: 'field-1',
|
|
6
|
+
type: FieldTypeEnum.fillable,
|
|
7
|
+
subType: 'text',
|
|
8
|
+
x: 0,
|
|
9
|
+
y: 0,
|
|
10
|
+
page: 1,
|
|
11
|
+
label: 'Label',
|
|
12
|
+
width: 200,
|
|
13
|
+
height: 25,
|
|
14
|
+
...overrides,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('getFieldTextClipMode', () => {
|
|
18
|
+
const subject = (field: PdfField) => getFieldTextClipMode(field);
|
|
19
|
+
|
|
20
|
+
test('uses multiline for multiline fillable fields', () => {
|
|
21
|
+
expect(subject(buildField({ multiline: true }))).toBe('multiline');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('uses single-line for standard fillable fields', () => {
|
|
25
|
+
expect(subject(buildField())).toBe('single-line');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('uses wrapped for data model and generic text fields', () => {
|
|
29
|
+
expect(subject(buildField({ type: FieldTypeEnum.dataModel }))).toBe('wrapped');
|
|
30
|
+
expect(
|
|
31
|
+
subject(buildField({ type: FieldTypeEnum.generic, subType: 'text' })),
|
|
32
|
+
).toBe('wrapped');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('getFieldTextClipClassName', () => {
|
|
37
|
+
const subject = (field: PdfField) => getFieldTextClipClassName(field);
|
|
38
|
+
|
|
39
|
+
test('maps mode to css class', () => {
|
|
40
|
+
expect(subject(buildField())).toBe('dte-pdf-field-text--single-line');
|
|
41
|
+
expect(subject(buildField({ multiline: true }))).toBe('dte-pdf-field-text--multiline');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { FieldTypeEnum, PdfField } from '../../../interface/types';
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_FIELD_FONT_FAMILY,
|
|
4
|
+
DEFAULT_FIELD_FONT_WEIGHT,
|
|
5
|
+
} from '../../../constants/field.constants';
|
|
6
|
+
import { getFieldTypographyStyle } from '../get-field-typography.utils';
|
|
7
|
+
|
|
8
|
+
const buildField = (overrides: Partial<PdfField> = {}): PdfField => ({
|
|
9
|
+
id: 'field-1',
|
|
10
|
+
type: FieldTypeEnum.fillable,
|
|
11
|
+
subType: 'text',
|
|
12
|
+
x: 0,
|
|
13
|
+
y: 0,
|
|
14
|
+
page: 1,
|
|
15
|
+
label: 'Label',
|
|
16
|
+
width: 200,
|
|
17
|
+
height: 25,
|
|
18
|
+
...overrides,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('getFieldTypographyStyle', () => {
|
|
22
|
+
const subject = (field: PdfField) => getFieldTypographyStyle(field);
|
|
23
|
+
|
|
24
|
+
test('applies backend default font family and weight', () => {
|
|
25
|
+
expect(subject(buildField())).toEqual({
|
|
26
|
+
fontFamily: DEFAULT_FIELD_FONT_FAMILY,
|
|
27
|
+
fontWeight: DEFAULT_FIELD_FONT_WEIGHT,
|
|
28
|
+
fontSize: `${(8 * 980) / 612}px`,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('uses per-field typography overrides when provided', () => {
|
|
33
|
+
expect(
|
|
34
|
+
subject(
|
|
35
|
+
buildField({
|
|
36
|
+
styles: {
|
|
37
|
+
fontSize: 12,
|
|
38
|
+
fontFamily: 'Times New Roman',
|
|
39
|
+
fontWeight: 'bold',
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
),
|
|
43
|
+
).toEqual({
|
|
44
|
+
fontFamily: 'Times New Roman',
|
|
45
|
+
fontWeight: 'bold',
|
|
46
|
+
fontSize: `${(12 * 980) / 612}px`,
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('omits font size for unsupported field types', () => {
|
|
51
|
+
expect(subject(buildField({ type: FieldTypeEnum.eSign, subType: 'signature' }))).toEqual({
|
|
52
|
+
fontFamily: DEFAULT_FIELD_FONT_FAMILY,
|
|
53
|
+
fontWeight: DEFAULT_FIELD_FONT_WEIGHT,
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import { FieldTypeEnum, PdfField, PdfFieldSubType } from '../../interface/types';
|
|
3
|
+
import { getFieldTypographyStyle } from './get-field-typography.utils';
|
|
4
|
+
|
|
5
|
+
interface FieldBoundsStyleOptions {
|
|
6
|
+
pageOffset?: { left: number; top: number };
|
|
7
|
+
backgroundColor?: string;
|
|
8
|
+
borderColor?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const getFieldTypeSpecificStyle = (field: PdfField): CSSProperties => {
|
|
12
|
+
if (!field.subType) {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
const styles = {
|
|
16
|
+
[FieldTypeEnum.fillable]: {
|
|
17
|
+
checkbox: {
|
|
18
|
+
width: 'unset',
|
|
19
|
+
height: 'unset',
|
|
20
|
+
},
|
|
21
|
+
radio: {
|
|
22
|
+
width: 'unset',
|
|
23
|
+
height: 'unset',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
} as Record<FieldTypeEnum, Record<PdfFieldSubType, CSSProperties>>;
|
|
27
|
+
|
|
28
|
+
return styles[field.type]?.[field.subType] ?? {};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Shared absolute-position style for PDF field overlays.
|
|
33
|
+
*
|
|
34
|
+
* Matches the backend `/conversions/templatetopdf` clip rectangle and
|
|
35
|
+
* `PdfView` preview: content-box sizing, top-left alignment,
|
|
36
|
+
* and shared typography (font size / family / weight).
|
|
37
|
+
*/
|
|
38
|
+
export const getFieldBoundsStyle = (
|
|
39
|
+
field: PdfField,
|
|
40
|
+
options?: FieldBoundsStyleOptions,
|
|
41
|
+
): CSSProperties => {
|
|
42
|
+
const { backgroundColor, borderColor, pageOffset = { left: 0, top: 0 } } = options ?? {};
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
position: 'absolute',
|
|
46
|
+
left: pageOffset.left + field.x,
|
|
47
|
+
top: pageOffset.top + field.y,
|
|
48
|
+
width: field.width,
|
|
49
|
+
height: field.height,
|
|
50
|
+
display: 'flex',
|
|
51
|
+
alignItems: 'flex-start',
|
|
52
|
+
justifyContent: 'flex-start',
|
|
53
|
+
boxSizing: 'content-box',
|
|
54
|
+
padding: 4,
|
|
55
|
+
margin: 0,
|
|
56
|
+
minWidth: 0,
|
|
57
|
+
minHeight: 0,
|
|
58
|
+
overflow: 'hidden',
|
|
59
|
+
lineHeight: 1,
|
|
60
|
+
...getFieldTypeSpecificStyle(field),
|
|
61
|
+
...getFieldTypographyStyle(field),
|
|
62
|
+
...(backgroundColor ? { backgroundColor } : {}),
|
|
63
|
+
...(borderColor ? { borderColor } : {}),
|
|
64
|
+
};
|
|
65
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FieldTypeEnum, PdfField } from '../../interface/types';
|
|
2
|
+
|
|
3
|
+
export type FieldTextClipMode = 'single-line' | 'multiline' | 'wrapped';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Text layout mode for a field overlay.
|
|
7
|
+
*
|
|
8
|
+
* Mirrors the backend PDF renderer:
|
|
9
|
+
* - single-line: no wrap, hard clip at the field rect (no ellipsis)
|
|
10
|
+
* - multiline: pre-wrap with word breaks, clip overflow vertically
|
|
11
|
+
* - wrapped: word-wrap for HTML / long prose blocks
|
|
12
|
+
*/
|
|
13
|
+
export const getFieldTextClipMode = (field: PdfField): FieldTextClipMode => {
|
|
14
|
+
if (field.type === FieldTypeEnum.fillable && field.multiline) {
|
|
15
|
+
return 'multiline';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (field.type === FieldTypeEnum.generic && field.subType === 'text') {
|
|
19
|
+
return 'wrapped';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (field.type === FieldTypeEnum.dataModel || field.type === FieldTypeEnum.forms) {
|
|
23
|
+
return 'wrapped';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return 'single-line';
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const getFieldTextClipClassName = (field: PdfField) => {
|
|
30
|
+
return `dte-pdf-field-text--${getFieldTextClipMode(field)}`;
|
|
31
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import { DEFAULT_FIELD_FONT_FAMILY, DEFAULT_FIELD_FONT_WEIGHT } from '../../constants';
|
|
3
|
+
import { PdfField } from '../../interface/types';
|
|
4
|
+
import { getFieldFontSizeInPixels, supportsFieldFontSize } from './get-field-font-size.utils';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Typography styles for a field overlay, aligned with the backend PDF renderer.
|
|
8
|
+
*
|
|
9
|
+
* - fontSize is stored in points on `field.styles.fontSize` and converted to pixels
|
|
10
|
+
* - fontFamily / fontWeight use backend defaults unless set per field
|
|
11
|
+
*/
|
|
12
|
+
export const getFieldTypographyStyle = (field: PdfField): CSSProperties => {
|
|
13
|
+
const typography: CSSProperties = {
|
|
14
|
+
fontFamily: field.styles?.fontFamily ?? DEFAULT_FIELD_FONT_FAMILY,
|
|
15
|
+
fontWeight: field.styles?.fontWeight ?? DEFAULT_FIELD_FONT_WEIGHT,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
if (supportsFieldFontSize(field)) {
|
|
19
|
+
typography.fontSize = `${getFieldFontSizeInPixels(field)}px`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return typography;
|
|
23
|
+
};
|
package/src/utils/field/index.ts
CHANGED
|
@@ -4,4 +4,7 @@ export * from './field-coordinates.utils';
|
|
|
4
4
|
export * from './field-drag.utils';
|
|
5
5
|
export * from './field-placeholder-text.utils';
|
|
6
6
|
export * from './field-resize.utils';
|
|
7
|
+
export * from './get-field-bounds-style.utils';
|
|
7
8
|
export * from './get-field-font-size.utils';
|
|
9
|
+
export * from './get-field-text-clip.utils';
|
|
10
|
+
export * from './get-field-typography.utils';
|