@servicetitan/dte-unlayer 0.116.0 → 0.117.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/src/editor.tsx CHANGED
@@ -115,6 +115,12 @@ export const UnlayerEditor = forwardRef<UnlayerRef, UnlayerEditorProps>((props,
115
115
  return () => store.setOnCalcFieldOpen();
116
116
  }, [props.opts.onCalcFieldOpen, store]);
117
117
 
118
+ useEffect(() => {
119
+ store.setOnCalcFieldSelect(props.opts.onCalcFieldSelect);
120
+
121
+ return () => store.setOnCalcFieldSelect();
122
+ }, [props.opts.onCalcFieldSelect, store]);
123
+
118
124
  const { minHeight = 800, style = {} } = props;
119
125
 
120
126
  return (
package/src/store.ts CHANGED
@@ -51,6 +51,7 @@ export class UnlayerStore {
51
51
  private onErrorCB?: (title: string, description?: string) => void;
52
52
  private onFormSelectCB?: (formId: number) => void;
53
53
  private onCalcFieldOpenCB?: (usedFormIds: number[]) => void;
54
+ private onCalcFieldSelectCB?: (fieldKeys: string[]) => void;
54
55
 
55
56
  constructor(readonly props: CreateUnlayerEditorProps) {
56
57
  this.props.eSignFieldTypes = ['Signature', 'Initials', 'Date Signed', 'Full Name'];
@@ -73,6 +74,9 @@ export class UnlayerStore {
73
74
  sendFormFields: (formId, fields) => {
74
75
  this.sendFormFields(formId, fields);
75
76
  },
77
+ sendCalcFieldLabels: labels => {
78
+ this.sendCalcFieldLabels(labels);
79
+ },
76
80
  };
77
81
  }
78
82
 
@@ -156,6 +160,10 @@ export class UnlayerStore {
156
160
  this.onCalcFieldOpenCB = onCalcFieldOpen;
157
161
  };
158
162
 
163
+ setOnCalcFieldSelect = (onCalcFieldSelect?: UnlayerStore['onCalcFieldSelectCB']) => {
164
+ this.onCalcFieldSelectCB = onCalcFieldSelect;
165
+ };
166
+
159
167
  sendFormList = (forms: FormInfo[]) => {
160
168
  this.sendMessage('--form-list', { forms });
161
169
  };
@@ -164,6 +172,10 @@ export class UnlayerStore {
164
172
  this.sendMessage('--form-fields', { formId, fields });
165
173
  };
166
174
 
175
+ sendCalcFieldLabels = (labels: Record<string, string>) => {
176
+ this.sendMessage('--calc-field-labels', { labels });
177
+ };
178
+
167
179
  private onDesignLoaded = () => {
168
180
  if (!this.hasDesign) {
169
181
  this.hasDesign = true;
@@ -240,6 +252,12 @@ export class UnlayerStore {
240
252
  this.onFormSelectCB?.(data?.formId);
241
253
  } else if (type === '--calc-field-open') {
242
254
  this.onCalcFieldOpenCB?.(data?.usedFormIds ?? []);
255
+ } else if (type === '--calc-field-select') {
256
+ if (this.onCalcFieldSelectCB) {
257
+ this.onCalcFieldSelectCB(data?.fieldKeys ?? []);
258
+ } else {
259
+ this.sendCalcFieldLabels({});
260
+ }
243
261
  } else if (type === '--data-loaded') {
244
262
  const data: UnlayerEventRegister = {
245
263
  customTools: this.props.tools.map(tool => ({ key: tool.key })),
@@ -43,6 +43,7 @@ export interface UnlayerRef {
43
43
  exportHtml(cb: (data: UnlayerExport) => void): void;
44
44
  sendFormList(forms: FormInfo[]): void;
45
45
  sendFormFields(formId: number, fields: FormFieldInfo[]): void;
46
+ sendCalcFieldLabels(labels: Record<string, string>): void;
46
47
  }
47
48
 
48
49
  export interface UnlayerEditorMergeTagInfo {
@@ -91,4 +92,5 @@ export interface CreateUnlayerEditorProps {
91
92
  holidays?: string[];
92
93
  onFormSelect?: (formId: number) => void;
93
94
  onCalcFieldOpen?: (usedFormIds: number[]) => void;
95
+ onCalcFieldSelect?: (fieldKeys: string[]) => void;
94
96
  }