@servicetitan/dte-pdf-editor 1.95.0 → 1.96.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.
Files changed (95) hide show
  1. package/README.md +84 -2
  2. package/dist/components/field-config-panel/advanced-settings.d.ts +2 -0
  3. package/dist/components/field-config-panel/advanced-settings.d.ts.map +1 -1
  4. package/dist/components/field-config-panel/advanced-settings.js +5 -4
  5. package/dist/components/field-config-panel/advanced-settings.js.map +1 -1
  6. package/dist/components/field-config-panel/e-sign-options-modal.d.ts +3 -0
  7. package/dist/components/field-config-panel/e-sign-options-modal.d.ts.map +1 -1
  8. package/dist/components/field-config-panel/e-sign-options-modal.js +6 -4
  9. package/dist/components/field-config-panel/e-sign-options-modal.js.map +1 -1
  10. package/dist/components/field-config-panel/field-config-panel-overlay.d.ts +14 -1
  11. package/dist/components/field-config-panel/field-config-panel-overlay.d.ts.map +1 -1
  12. package/dist/components/field-config-panel/field-config-panel-overlay.js +41 -2
  13. package/dist/components/field-config-panel/field-config-panel-overlay.js.map +1 -1
  14. package/dist/components/field-config-panel/field-config-panel.d.ts +6 -0
  15. package/dist/components/field-config-panel/field-config-panel.d.ts.map +1 -1
  16. package/dist/components/field-config-panel/field-config-panel.js +17 -3
  17. package/dist/components/field-config-panel/field-config-panel.js.map +1 -1
  18. package/dist/components/field-config-panel/formula-generator.d.ts +4 -0
  19. package/dist/components/field-config-panel/formula-generator.d.ts.map +1 -1
  20. package/dist/components/field-config-panel/formula-generator.js +2 -2
  21. package/dist/components/field-config-panel/formula-generator.js.map +1 -1
  22. package/dist/components/field-config-panel/formula-modal.d.ts +5 -0
  23. package/dist/components/field-config-panel/formula-modal.d.ts.map +1 -1
  24. package/dist/components/field-config-panel/formula-modal.js +13 -6
  25. package/dist/components/field-config-panel/formula-modal.js.map +1 -1
  26. package/dist/components/field-config-panel/formula-workspace.d.ts +2 -0
  27. package/dist/components/field-config-panel/formula-workspace.d.ts.map +1 -1
  28. package/dist/components/field-config-panel/formula-workspace.js +6 -4
  29. package/dist/components/field-config-panel/formula-workspace.js.map +1 -1
  30. package/dist/components/pdf-editor/pdf-editor.d.ts +52 -1
  31. package/dist/components/pdf-editor/pdf-editor.d.ts.map +1 -1
  32. package/dist/components/pdf-editor/pdf-editor.js +2 -2
  33. package/dist/components/pdf-editor/pdf-editor.js.map +1 -1
  34. package/dist/components/pdf-view/pdf-view-calculated.d.ts +3 -1
  35. package/dist/components/pdf-view/pdf-view-calculated.d.ts.map +1 -1
  36. package/dist/components/pdf-view/pdf-view-calculated.js +14 -4
  37. package/dist/components/pdf-view/pdf-view-calculated.js.map +1 -1
  38. package/dist/components/pdf-view/pdf-view.d.ts +18 -4
  39. package/dist/components/pdf-view/pdf-view.d.ts.map +1 -1
  40. package/dist/components/pdf-view/pdf-view.js +2 -2
  41. package/dist/components/pdf-view/pdf-view.js.map +1 -1
  42. package/dist/constants/calculated.constants.d.ts +6 -0
  43. package/dist/constants/calculated.constants.d.ts.map +1 -1
  44. package/dist/constants/calculated.constants.js +6 -0
  45. package/dist/constants/calculated.constants.js.map +1 -1
  46. package/dist/hooks/usePinchZoom.d.ts.map +1 -1
  47. package/dist/hooks/usePinchZoom.js +1 -1
  48. package/dist/hooks/usePinchZoom.js.map +1 -1
  49. package/dist/interface/types.d.ts +37 -1
  50. package/dist/interface/types.d.ts.map +1 -1
  51. package/dist/interface/types.js.map +1 -1
  52. package/dist/utils/formula/business-days.utils.d.ts +32 -0
  53. package/dist/utils/formula/business-days.utils.d.ts.map +1 -0
  54. package/dist/utils/formula/business-days.utils.js +148 -0
  55. package/dist/utils/formula/business-days.utils.js.map +1 -0
  56. package/dist/utils/formula/caret.utils.js +1 -1
  57. package/dist/utils/formula/caret.utils.js.map +1 -1
  58. package/dist/utils/formula/evaluate-formula.utils.d.ts +25 -6
  59. package/dist/utils/formula/evaluate-formula.utils.d.ts.map +1 -1
  60. package/dist/utils/formula/evaluate-formula.utils.js +61 -101
  61. package/dist/utils/formula/evaluate-formula.utils.js.map +1 -1
  62. package/dist/utils/formula/index.d.ts +1 -0
  63. package/dist/utils/formula/index.d.ts.map +1 -1
  64. package/dist/utils/formula/index.js +1 -0
  65. package/dist/utils/formula/index.js.map +1 -1
  66. package/dist/utils/formula/schedule-bindings.utils.d.ts +12 -0
  67. package/dist/utils/formula/schedule-bindings.utils.d.ts.map +1 -0
  68. package/dist/utils/formula/schedule-bindings.utils.js +17 -0
  69. package/dist/utils/formula/schedule-bindings.utils.js.map +1 -0
  70. package/package.json +2 -1
  71. package/src/__tests__/field-types/date-fields.test.ts +29 -3
  72. package/src/__tests__/field-types/e-sign-fields.test.ts +2 -2
  73. package/src/__tests__/field-types/fillable-fields.test.ts +2 -2
  74. package/src/components/field-config-panel/advanced-settings.tsx +16 -3
  75. package/src/components/field-config-panel/e-sign-options-modal.tsx +13 -2
  76. package/src/components/field-config-panel/field-config-panel-overlay.tsx +97 -1
  77. package/src/components/field-config-panel/field-config-panel.tsx +28 -0
  78. package/src/components/field-config-panel/formula-generator.tsx +8 -1
  79. package/src/components/field-config-panel/formula-modal.tsx +19 -4
  80. package/src/components/field-config-panel/formula-workspace.tsx +31 -6
  81. package/src/components/pdf-editor/pdf-editor.tsx +82 -0
  82. package/src/components/pdf-view/pdf-view-calculated.tsx +28 -3
  83. package/src/components/pdf-view/pdf-view.tsx +23 -3
  84. package/src/constants/calculated.constants.ts +7 -0
  85. package/src/hooks/usePinchZoom.ts +1 -6
  86. package/src/interface/types.ts +47 -0
  87. package/src/utils/field/__tests__/field-background-color.utils.test.ts +8 -8
  88. package/src/utils/field/__tests__/get-field-bounds-style.utils.test.ts +16 -0
  89. package/src/utils/formula/__tests__/evaluate-formula.utils.test.ts +198 -16
  90. package/src/utils/formula/__tests__/schedule-bindings.utils.test.ts +73 -0
  91. package/src/utils/formula/business-days.utils.ts +188 -0
  92. package/src/utils/formula/caret.utils.ts +1 -1
  93. package/src/utils/formula/evaluate-formula.utils.ts +94 -114
  94. package/src/utils/formula/index.ts +1 -0
  95. package/src/utils/formula/schedule-bindings.utils.ts +27 -0
@@ -1,6 +1,7 @@
1
1
  import { Button, Dialog, Divider, Flex } from '@servicetitan/anvil2';
2
2
  import IconRedo from '@servicetitan/anvil2/assets/icons/material/round/redo.svg';
3
3
  import IconUndo from '@servicetitan/anvil2/assets/icons/material/round/undo.svg';
4
+ import { type ScheduleEditorContext } from '@servicetitan/dte-shared';
4
5
  import { FC, useCallback, useEffect, useMemo, useState } from 'react';
5
6
  import {
6
7
  DEFAULT_DATE_CALCULATED_FORMAT,
@@ -18,6 +19,7 @@ import {
18
19
  type StructuredFormula,
19
20
  } from '../../interface/types';
20
21
  import {
22
+ type DateCalcOptions,
21
23
  evaluateFormula,
22
24
  formatCalculatedResult,
23
25
  formFieldInfosToCalculationOptions,
@@ -68,7 +70,10 @@ function setSampleValueAtPath(target: DataModelValues, path: string, value: unkn
68
70
  export interface FormulaModalProps {
69
71
  initialFormula: StructuredFormula | undefined;
70
72
  initialFormat?: CalculatedFieldFormat;
73
+ businessCalendar?: ScheduleEditorContext;
71
74
  dataModelGroups: DataModelFieldGroup[];
75
+ /** The calendar the preview uses: the field's own, or the default one. */
76
+ dateCalcOptions?: DateCalcOptions;
72
77
  fillableFieldsFromDocument?: FieldTypeOption[];
73
78
  formFieldsByFormId?: FormFieldsByFormIdI;
74
79
  forms: FormInfo[];
@@ -79,7 +84,9 @@ export interface FormulaModalProps {
79
84
  }
80
85
 
81
86
  export const FormulaModal: FC<FormulaModalProps> = ({
87
+ businessCalendar,
82
88
  dataModelGroups,
89
+ dateCalcOptions,
83
90
  fillableFieldsFromDocument = [],
84
91
  formFieldsByFormId = {},
85
92
  forms,
@@ -255,21 +262,28 @@ export const FormulaModal: FC<FormulaModalProps> = ({
255
262
  if (parsedTokens.length === 0 || !formulaValidation.valid) {
256
263
  return '';
257
264
  }
258
- return hasDivisionByZero({ tokens: parsedTokens }, sampleData)
265
+ return hasDivisionByZero({ tokens: parsedTokens }, sampleData, dateCalcOptions)
259
266
  ? 'Division by zero is not allowed'
260
267
  : '';
261
- }, [parsedTokens, formulaValidation.valid, sampleData]);
268
+ }, [parsedTokens, formulaValidation.valid, sampleData, dateCalcOptions]);
262
269
 
263
270
  const previewValue = useMemo(() => {
264
271
  if (parsedTokens.length === 0 || !formulaValidation.valid || divisionByZeroError) {
265
272
  return '';
266
273
  }
267
- const computed = evaluateFormula({ tokens: parsedTokens }, sampleData);
274
+ const computed = evaluateFormula({ tokens: parsedTokens }, sampleData, dateCalcOptions);
268
275
  if (computed === null) {
269
276
  return '';
270
277
  }
271
278
  return formatCalculatedResult(computed, format);
272
- }, [parsedTokens, formulaValidation.valid, divisionByZeroError, sampleData, format]);
279
+ }, [
280
+ parsedTokens,
281
+ formulaValidation.valid,
282
+ divisionByZeroError,
283
+ sampleData,
284
+ format,
285
+ dateCalcOptions,
286
+ ]);
273
287
 
274
288
  const handleClose = useCallback(() => {
275
289
  onClose();
@@ -317,6 +331,7 @@ export const FormulaModal: FC<FormulaModalProps> = ({
317
331
  selectedPaths={formulaEditor.selectedFieldPaths}
318
332
  />
319
333
  <FormulaWorkspace
334
+ businessCalendar={businessCalendar}
320
335
  disabledOperators={formulaEditor.disabledOperators}
321
336
  editorRef={formulaEditor.editorRef}
322
337
  isInvalid={isInvalid && formulaEditor.isDirty}
@@ -1,4 +1,8 @@
1
- import { Alert, Button, Flex, LinkButton, Text } from '@servicetitan/anvil2';
1
+ import { Alert, Button, Flex, Text } from '@servicetitan/anvil2';
2
+ import IconExpandMore from '@servicetitan/anvil2/assets/icons/material/round/expand_more.svg';
3
+ import IconArrowForward from '@servicetitan/anvil2/assets/icons/material/round/keyboard_arrow_right.svg';
4
+
5
+ import { type ScheduleEditorContext } from '@servicetitan/dte-shared';
2
6
  import {
3
7
  Dispatch,
4
8
  FC,
@@ -17,6 +21,7 @@ import { ResultTypeSelector } from './result-type-selector';
17
21
  interface FormulaWorkspaceProps {
18
22
  actions: ReactNode;
19
23
  advancedOpen: boolean;
24
+ businessCalendar?: ScheduleEditorContext;
20
25
  disabledOperators?: Set<string>;
21
26
  editorRef: RefObject<HTMLDivElement | null>;
22
27
  format: CalculatedFieldFormat;
@@ -38,6 +43,7 @@ interface FormulaWorkspaceProps {
38
43
  export const FormulaWorkspace: FC<FormulaWorkspaceProps> = ({
39
44
  actions,
40
45
  advancedOpen,
46
+ businessCalendar,
41
47
  disabledOperators,
42
48
  editorRef,
43
49
  format,
@@ -75,7 +81,7 @@ export const FormulaWorkspace: FC<FormulaWorkspaceProps> = ({
75
81
  );
76
82
 
77
83
  return (
78
- <Flex direction="column" flex={1} gap={2} style={{ padding: '12px' }}>
84
+ <Flex direction="column" flex={1} gap={2} style={{ padding: '12px', overflowY: 'auto' }}>
79
85
  <Flex direction="column" gap={1}>
80
86
  <Text variant="body" size="small">
81
87
  Preview (uses demo sample data)
@@ -132,10 +138,29 @@ export const FormulaWorkspace: FC<FormulaWorkspaceProps> = ({
132
138
  })}
133
139
  </Flex>
134
140
  <ResultTypeSelector format={format} onChange={onResultTypeChange} />
135
- <LinkButton appearance="primary" onClick={onToggleAdvanced}>
136
- {advancedOpen ? 'Hide advanced settings' : 'Show advanced settings'}
137
- </LinkButton>
138
- {advancedOpen && <AdvancedSettings format={format} setFormat={setFormat} />}
141
+ <Flex
142
+ role="button"
143
+ onClick={onToggleAdvanced}
144
+ alignItems="center"
145
+ gap={1}
146
+ style={{ cursor: 'pointer', marginTop: 16 }}
147
+ >
148
+ <Text variant="eyebrow" size="small">
149
+ Advanced settings
150
+ </Text>
151
+ {advancedOpen ? (
152
+ <IconExpandMore fontSize="small" />
153
+ ) : (
154
+ <IconArrowForward fontSize="small" />
155
+ )}
156
+ </Flex>
157
+ {advancedOpen && (
158
+ <AdvancedSettings
159
+ format={format}
160
+ setFormat={setFormat}
161
+ businessCalendar={businessCalendar}
162
+ />
163
+ )}
139
164
  </Flex>
140
165
  );
141
166
  };
@@ -2,11 +2,16 @@ import { Flex } from '@servicetitan/anvil2';
2
2
  import { FC, ReactNode, useCallback, useMemo, useRef } from 'react';
3
3
  import { useFormFields, usePdfFieldDnD, usePdfFieldSelection } from '../../hooks';
4
4
  import {
5
+ type BusinessCalendar,
6
+ type BusinessDaySchedule,
5
7
  FieldTypeEnum,
8
+ type FieldScheduleBinding,
6
9
  type FormFieldsByFormIdI,
7
10
  type FormInfo,
11
+ type HolidayCatalog,
8
12
  type PdfField,
9
13
  type RecipientInfo,
14
+ type SaveScheduleRequest,
10
15
  type SchemaObject,
11
16
  } from '../../interface/types';
12
17
  import { extractGroupedFieldsFromDataModel, mapColorsToRecipients } from '../../utils';
@@ -30,10 +35,61 @@ export interface PdfEditorProps {
30
35
  hideConditionalLogic?: boolean;
31
36
  forms?: FormInfo[];
32
37
  zoomProps?: PdfCanvasProps['zoomProps'];
38
+ /**
39
+ * Holidays of the default business-day calendar, as `PdfView`'s `holidays`: the formula
40
+ * builder's preview of a date calculated field without its own calendar skips Saturday,
41
+ * Sunday and these days.
42
+ */
43
+ holidays?: string[];
44
+ /** Calendars of the date calculated fields bound to a schedule, by field id, as `PdfView`'s. */
45
+ fieldCalendars?: Record<string, BusinessCalendar>;
46
+ /**
47
+ * Date calculated fields whose custom business-day exclusion toggle is on, and the schedule
48
+ * each uses (`PdfField.id` as `fieldKey`), as `PdfView`'s. Also drives the Formula Builder's
49
+ * toggle/picker for the selected field.
50
+ */
51
+ scheduleBindings?: FieldScheduleBinding[];
52
+ /** The tenant's known holidays, for the schedule editor's checklist. */
53
+ holidayCatalog?: HolidayCatalog;
54
+ holidayCatalogLoading?: boolean;
55
+ holidayCatalogError?: string;
56
+ /** The schedules the tenant can pick from the Formula Builder's schedule picker. */
57
+ schedules?: BusinessDaySchedule[];
58
+ schedulesLoading?: boolean;
59
+ schedulesError?: string;
33
60
  onFormSelect?: (
34
61
  formIds: number[],
35
62
  sendFormFields: (formFieldsByFormId: FormFieldsByFormIdI) => void,
36
63
  ) => void;
64
+ /**
65
+ * Called with the complete desired `scheduleBindings` whenever the Formula Builder's toggle
66
+ * or schedule picker changes the selected field's binding (full replacement, mirroring DTE's
67
+ * `PUT api/holidays/templates/{id}/bindings`). `PdfEditor` does not persist this itself —
68
+ * the host is expected to save it (and the bindings are typically saved separately from the
69
+ * template's own fields).
70
+ */
71
+ onScheduleBindingsChange?(bindings: FieldScheduleBinding[]): void;
72
+ /**
73
+ * Creates a tenant schedule from the "Create New Schedule" drawer. Always creates a new
74
+ * schedule — it never overwrites a selected one. On success the created schedule is
75
+ * auto-selected in the picker. A rejected promise's `message` is shown as the drawer's error
76
+ * (for example a duplicate-name conflict).
77
+ */
78
+ onCreateSchedule?(request: SaveScheduleRequest): Promise<BusinessDaySchedule>;
79
+ /**
80
+ * Replaces a tenant schedule's name and rules in place, from the picker's "Edit" action
81
+ * (DTE's `PUT api/holidays/schedules/{id}`). Applies from the next conversion of every
82
+ * template using it. On success the updated schedule stays selected.
83
+ */
84
+ onUpdateSchedule?(id: number, request: SaveScheduleRequest): Promise<BusinessDaySchedule>;
85
+ /**
86
+ * Permanently deletes a tenant schedule, from the picker's "Delete" action (DTE's
87
+ * `DELETE api/holidays/schedules/{id}`). Fields still bound to it fall back to the default
88
+ * schedule — `PdfEditor` selects the default schedule for the current field on success, but
89
+ * does not itself update other fields' `scheduleBindings`; the host should drop bindings to
90
+ * a deleted schedule when it next saves them.
91
+ */
92
+ onDeleteSchedule?(id: number): Promise<void>;
37
93
  onLoadSuccess?(numPages: number): void;
38
94
  onFieldsChange(fields: PdfField[]): void;
39
95
  }
@@ -42,17 +98,30 @@ export const PdfEditor: FC<PdfEditorProps> = ({
42
98
  dataModel,
43
99
  errorPlaceholder,
44
100
  errors = {},
101
+ fieldCalendars,
45
102
  fields = [],
46
103
  forms,
47
104
  hideConditionalLogic,
48
105
  hideFields,
106
+ holidayCatalog,
107
+ holidayCatalogError,
108
+ holidayCatalogLoading,
109
+ holidays,
49
110
  loading = false,
50
111
  loadingPlaceholder,
112
+ onCreateSchedule,
113
+ onDeleteSchedule,
51
114
  onFieldsChange,
52
115
  onFormSelect,
53
116
  onLoadSuccess,
117
+ onScheduleBindingsChange,
118
+ onUpdateSchedule,
54
119
  pdfUrl,
55
120
  recipients = [],
121
+ scheduleBindings,
122
+ schedules,
123
+ schedulesError,
124
+ schedulesLoading,
56
125
  zoomProps,
57
126
  zoomable = true,
58
127
  }) => {
@@ -99,6 +168,19 @@ export const PdfEditor: FC<PdfEditorProps> = ({
99
168
  recipients={recipients}
100
169
  onDeselectField={pdfFieldSelection.deselectField}
101
170
  hideConditionalLogic={hideConditionalLogic}
171
+ holidays={holidays}
172
+ fieldCalendars={fieldCalendars}
173
+ scheduleBindings={scheduleBindings}
174
+ onScheduleBindingsChange={onScheduleBindingsChange}
175
+ holidayCatalog={holidayCatalog}
176
+ holidayCatalogLoading={holidayCatalogLoading}
177
+ holidayCatalogError={holidayCatalogError}
178
+ schedules={schedules}
179
+ schedulesLoading={schedulesLoading}
180
+ schedulesError={schedulesError}
181
+ onCreateSchedule={onCreateSchedule}
182
+ onUpdateSchedule={onUpdateSchedule}
183
+ onDeleteSchedule={onDeleteSchedule}
102
184
  onRequestFormFields={formFields.requestFormFieldsById}
103
185
  />
104
186
  )}
@@ -1,8 +1,15 @@
1
1
  import { FC, useMemo } from 'react';
2
- import { type DataModelValues, type PdfField, type PdfViewMode } from '../../interface/types';
2
+ import {
3
+ type BusinessCalendar,
4
+ type DataModelValues,
5
+ type FieldScheduleBinding,
6
+ type PdfField,
7
+ type PdfViewMode,
8
+ } from '../../interface/types';
3
9
  import {
4
10
  evaluateFormula,
5
11
  formatCalculatedResult,
12
+ getFieldDateCalcOptions,
6
13
  getFieldTextClipClassName,
7
14
  resolvePdfDataValues,
8
15
  } from '../../utils';
@@ -11,18 +18,26 @@ interface PdfViewCalculatedProps {
11
18
  field: PdfField;
12
19
  data?: DataModelValues;
13
20
  holidays?: string[];
21
+ fieldCalendars?: Record<string, BusinessCalendar>;
22
+ scheduleBindings?: FieldScheduleBinding[];
14
23
  viewMode?: PdfViewMode;
15
24
  }
16
25
 
17
26
  export const PdfViewCalculated: FC<PdfViewCalculatedProps> = ({
18
27
  data,
19
28
  field,
29
+ fieldCalendars,
20
30
  holidays,
31
+ scheduleBindings,
21
32
  viewMode,
22
33
  }) => {
23
34
  const displayValue = useMemo(() => {
24
35
  if (field.formula?.tokens?.length) {
25
- const value = evaluateFormula(field.formula, data, holidays);
36
+ const value = evaluateFormula(
37
+ field.formula,
38
+ data,
39
+ getFieldDateCalcOptions(field.id, scheduleBindings, holidays, fieldCalendars),
40
+ );
26
41
  if (value === null) {
27
42
  return '';
28
43
  }
@@ -32,7 +47,17 @@ export const PdfViewCalculated: FC<PdfViewCalculatedProps> = ({
32
47
  return resolvePdfDataValues(data, field.path) ?? '';
33
48
  }
34
49
  return field.label ?? '';
35
- }, [data, field.formula, field.formulaFormat, field.label, field.path, holidays]);
50
+ }, [
51
+ data,
52
+ field.formula,
53
+ field.formulaFormat,
54
+ field.id,
55
+ field.label,
56
+ field.path,
57
+ fieldCalendars,
58
+ holidays,
59
+ scheduleBindings,
60
+ ]);
36
61
 
37
62
  const isPreview = viewMode === 'preview';
38
63
  const shouldShowPreviewFallback = isPreview && displayValue === '';
@@ -3,8 +3,10 @@ import { FC, ReactNode, useLayoutEffect, useMemo, useRef, useState } from 'react
3
3
  import { BASE_PAGE_WIDTH } from '../../constants';
4
4
  import { usePinchZoom, useZoom } from '../../hooks';
5
5
  import {
6
+ type BusinessCalendar,
6
7
  type DataChangePayload,
7
8
  type DataModelValues,
9
+ type FieldScheduleBinding,
8
10
  FieldTypeEnum,
9
11
  type PdfField,
10
12
  type PdfViewMode,
@@ -47,11 +49,25 @@ export interface PdfViewProps {
47
49
  */
48
50
  makeFillableFieldsReadonly?: boolean;
49
51
  /**
50
- * UTC date strings (e.g. `'2026-03-17T00:00:00Z'`) treated as non-business days.
51
- * When provided, date-based calculated fields skip weekends and these holidays
52
- * when adding/subtracting days or computing date differences.
52
+ * Holidays of the default business-day calendar, as date strings (`'2026-07-03'`,
53
+ * `'2026-03-17T00:00:00Z'`). Date calculated fields without their own calendar skip
54
+ * Saturday, Sunday and these days when adding/subtracting days or computing date
55
+ * differences, within the current year ± 1.
53
56
  */
54
57
  holidays?: string[];
58
+ /**
59
+ * Calendars of the date calculated fields bound to a business-day schedule, by field id
60
+ * (`PdfField.id`), as DTE's `POST api/holidays/calendar` resolves them. Listed fields use
61
+ * only their calendar; the others use the default one (`holidays`).
62
+ */
63
+ fieldCalendars?: Record<string, BusinessCalendar>;
64
+ /**
65
+ * Date calculated fields whose custom business-day exclusion toggle is on, and the schedule
66
+ * each uses (DTE's bindings, `PdfField.id` as `fieldKey`). A field with no entry here uses
67
+ * plain calendar-day arithmetic — no weekend or holiday skipping — regardless of `holidays`
68
+ * or `fieldCalendars`.
69
+ */
70
+ scheduleBindings?: FieldScheduleBinding[];
55
71
  /**
56
72
  * fillingBy defines the list of recipient names
57
73
  * who are allowed to fill this field.
@@ -71,6 +87,7 @@ export const PdfView: FC<PdfViewProps> = ({
71
87
  enableInputNavigation = true,
72
88
  errorPlaceholder,
73
89
  errors = {},
90
+ fieldCalendars,
74
91
  fields,
75
92
  fillingBy,
76
93
  holidays,
@@ -81,6 +98,7 @@ export const PdfView: FC<PdfViewProps> = ({
81
98
  onLoadSuccess,
82
99
  pdfUrl,
83
100
  recipients,
101
+ scheduleBindings,
84
102
  viewMode,
85
103
  zoomProps,
86
104
  zoomable = true,
@@ -280,6 +298,8 @@ export const PdfView: FC<PdfViewProps> = ({
280
298
  field={field}
281
299
  data={viewMode === 'preview' ? previewData : data}
282
300
  holidays={holidays}
301
+ fieldCalendars={fieldCalendars}
302
+ scheduleBindings={scheduleBindings}
283
303
  viewMode={viewMode}
284
304
  />
285
305
  )}
@@ -4,4 +4,11 @@ export const DEFAULT_DATE_FORMAT = 'MM/DD/YYYY';
4
4
 
5
5
  export const MAX_DATE_CALC_DAYS = 365;
6
6
 
7
+ /**
8
+ * Years either side of the current one that the default business-day calendar covers, as DTE's
9
+ * (`HolidayCheckService.HolidayYearsWindow`): outside them its holidays are unknown, so date
10
+ * arithmetic is blank.
11
+ */
12
+ export const DEFAULT_CALENDAR_YEARS = 1;
13
+
7
14
  export const MAX_DATE_DISPLAY_RANGE_YEARS = 2;
@@ -1,10 +1,5 @@
1
1
  import { RefObject, useEffect, useRef } from 'react';
2
- import {
3
- clampZoom,
4
- getPinchZoomValue,
5
- getTouchDistance,
6
- getWheelZoomFactor,
7
- } from '../utils';
2
+ import { clampZoom, getPinchZoomValue, getTouchDistance, getWheelZoomFactor } from '../utils';
8
3
 
9
4
  interface UsePinchZoomOptions {
10
5
  enabled: boolean;
@@ -86,6 +86,14 @@ export interface ESignDateSignedOffsetSettings {
86
86
  rules:
87
87
  | [ESignDateSignedOffsetSettingsFinalRule]
88
88
  | [...ESignDateSignedOffsetSettingsRule[], ESignDateSignedOffsetSettingsFinalRule];
89
+ /**
90
+ * Whether the day offset skips weekends/holidays per a business-day schedule, same toggle as a
91
+ * calculated field's (`FieldScheduleBinding`) but stored here instead, since - like `rules` -
92
+ * it applies to every `dateSignedOffset` field in the document, not one field at a time.
93
+ */
94
+ businessCalendarEnabled?: boolean;
95
+ /** The schedule to use while `businessCalendarEnabled` is on; undefined for the default schedule. */
96
+ scheduleId?: number;
89
97
  }
90
98
 
91
99
  export interface FillableDropdownItem {
@@ -246,6 +254,45 @@ export interface StructuredFormula {
246
254
  tokens: FormulaToken[];
247
255
  }
248
256
 
257
+ /**
258
+ * Days a date calculated field skips, as DTE resolves a business-day schedule
259
+ * (`POST api/holidays/calendar`). Date arithmetic outside `firstYear`–`lastYear` is blank.
260
+ */
261
+ export interface BusinessCalendar {
262
+ /** Excluded weekend days, as `Date.getUTCDay()` numbers them: 0 = Sunday, 6 = Saturday. */
263
+ weekendDays: number[];
264
+ /** Holiday dates, already moved to their observed days, as `YYYY-MM-DD`. */
265
+ holidays: string[];
266
+ firstYear: number;
267
+ lastYear: number;
268
+ }
269
+
270
+ /**
271
+ * Re-exported from `@servicetitan/dte-shared` so existing imports from this path keep
272
+ * working: the schedule editor UI (`ScheduleDrawer`/`SchedulePicker`) is shared with
273
+ * `@servicetitan/dte-unlayer` and lives there now, these types are its domain model.
274
+ */
275
+ export type {
276
+ BusinessCalendarRules,
277
+ BusinessDaySchedule,
278
+ HolidayCatalog,
279
+ KnownHoliday,
280
+ SaveScheduleRequest,
281
+ WeekendDay,
282
+ } from '@servicetitan/dte-shared';
283
+
284
+ /**
285
+ * A date calculated field whose custom business-day exclusion toggle is on, and the schedule it
286
+ * uses (DTE's bindings, full-replace via `PUT api/holidays/templates/{id}/bindings`). A field with
287
+ * no entry here uses the default calendar with the toggle off (plain calendar-day arithmetic).
288
+ */
289
+ export interface FieldScheduleBinding {
290
+ /** `PdfField.id`. */
291
+ fieldKey: string;
292
+ /** One of the tenant's schedules, or undefined for the default schedule. */
293
+ scheduleId?: number;
294
+ }
295
+
249
296
  /** Format options for a calculated field with a numeric result (number, currency, percent) */
250
297
  export interface CalculatedFormatForNumber {
251
298
  resultType: 'number' | 'currency' | 'percent';
@@ -8,19 +8,19 @@ describe('getFieldColor', () => {
8
8
  expect(subject('signer1', { signer1: '#ff0000', signer2: '#00ff00' })).toBe('#ff0000');
9
9
  });
10
10
 
11
- test('returns "none" when recipient is undefined', () => {
12
- expect(subject(undefined, { signer1: '#ff0000' })).toBe('none');
11
+ test('returns undefined when recipient is undefined', () => {
12
+ expect(subject(undefined, { signer1: '#ff0000' })).toBeUndefined();
13
13
  });
14
14
 
15
- test('returns "none" when recipient is empty string', () => {
16
- expect(subject('', { signer1: '#ff0000' })).toBe('none');
15
+ test('returns undefined when recipient is empty string', () => {
16
+ expect(subject('', { signer1: '#ff0000' })).toBeUndefined();
17
17
  });
18
18
 
19
- test('returns "none" when recipient is not in the color map', () => {
20
- expect(subject('unknown', { signer1: '#ff0000' })).toBe('none');
19
+ test('returns undefined when recipient is not in the color map', () => {
20
+ expect(subject('unknown', { signer1: '#ff0000' })).toBeUndefined();
21
21
  });
22
22
 
23
- test('returns "none" when color map is empty', () => {
24
- expect(subject('signer1', {})).toBe('none');
23
+ test('returns undefined when color map is empty', () => {
24
+ expect(subject('signer1', {})).toBeUndefined();
25
25
  });
26
26
  });
@@ -38,6 +38,22 @@ describe('getFieldBoundsStyle', () => {
38
38
  });
39
39
  });
40
40
 
41
+ test('sets the recipient color variables when a color is given', () => {
42
+ expect(subject(buildField(), { color: '#ff0000' })).toMatchObject({
43
+ '--pdf-field-color': '#ff0000',
44
+ '--pdf-field-color-dark': '#ff0000',
45
+ '--pdf-field-opacity-color': '#ff00001f',
46
+ });
47
+ });
48
+
49
+ test('leaves the color variables unset without a color, so the stylesheet defaults apply', () => {
50
+ const style = subject(buildField(), { color: undefined });
51
+
52
+ expect(style).not.toHaveProperty('--pdf-field-color');
53
+ expect(style).not.toHaveProperty('--pdf-field-color-dark');
54
+ expect(style).not.toHaveProperty('--pdf-field-opacity-color');
55
+ });
56
+
41
57
  test('converts font size from points to editor pixels', () => {
42
58
  const style = subject(buildField({ styles: { fontSize: 12 } }));
43
59
  expect(style.fontSize).toBe(`${pointsToPixels(12)}px`);