Skip to content

Commit 2e7c32c

Browse files
committed
fix: rename CLEAR_FIELDS to REMOVE_FIELDS and clearFields to removeFields
Rename iframe event CLEAR_FIELDS to REMOVE_FIELDS and response field cleared_count to removed_count. Rename React embed action clearFields to removeFields. Update all docs, examples, and tests accordingly.
1 parent 04e8ddd commit 2e7c32c

File tree

10 files changed

+42
-42
lines changed

10 files changed

+42
-42
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ Currently, page manipulation (add/remove/re-arrange/rotate) is only available th
286286
| `goTo` | Navigate to a specific page |
287287
| `selectTool` | Select a tool (`TEXT`, `BOXED_TEXT`, `CHECKBOX`, `PICTURE`, `SIGNATURE`) or `null` for cursor |
288288
| `createField` | Create a field at a specified position |
289-
| `clearFields` | Clear fields by ID, by page, or all fields |
289+
| `removeFields` | Remove fields by ID, by page, or all fields |
290290
| `getDocumentContent` | Extract text content from the document |
291291
| `submit` | Submit the document (with optional device download) |
292292
| `loadDocument` (Iframe)| Load a document programmatically (Iframe API only) |

documentation/IFRAME.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,12 @@ await sendEvent("CREATE_FIELD", {
196196
value: "Hello World",
197197
});
198198

199-
// Clear all fields (or specific ones)
200-
await sendEvent("CLEAR_FIELDS", {}); // Clear all
201-
await sendEvent("CLEAR_FIELDS", { page: 1 }); // Clear page 1 only
202-
await sendEvent("CLEAR_FIELDS", {
199+
// Remove all fields (or specific ones)
200+
await sendEvent("REMOVE_FIELDS", {}); // Remove all
201+
await sendEvent("REMOVE_FIELDS", { page: 1 }); // Remove page 1 only
202+
await sendEvent("REMOVE_FIELDS", {
203203
field_ids: ["f_kj8n2hd9x3m1p", "f_q7v5c4b6a0wyz"],
204-
}); // Clear specific fields
204+
}); // Remove specific fields
205205

206206
// Extract document content
207207
const content = await sendEvent("GET_DOCUMENT_CONTENT", {
@@ -319,20 +319,20 @@ Create a new field on the document.
319319
}
320320
```
321321

322-
#### CLEAR_FIELDS
322+
#### REMOVE_FIELDS
323323

324324
Remove fields from the document.
325325

326326
| Field | Type | Required | Description |
327327
| ----------- | ---------- | -------- | ------------------------------------------------ |
328-
| `field_ids` | `string[]` | No | Specific field IDs to remove (omit to clear all) |
329-
| `page` | `number` | No | Only clear fields on this page |
328+
| `field_ids` | `string[]` | No | Specific field IDs to remove (omit to remove all) |
329+
| `page` | `number` | No | Only remove fields on this page |
330330

331331
**Response data:**
332332

333333
```json
334334
{
335-
"cleared_count": 5
335+
"removed_count": 5
336336
}
337337
```
338338

examples/with-playwright-automation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ The tool uses the SimplePDF editor's iframe postMessage API:
247247

248248
1. Embeds the editor in an iframe
249249
2. Waits for `DOCUMENT_LOADED` event
250-
3. Sends `CLEAR_FIELDS` to remove existing fields
250+
3. Sends `REMOVE_FIELDS` to remove existing fields
251251
4. Sends `CREATE_FIELD` for each configured field
252252
5. Leaves browser open for inspection
253253

examples/with-playwright-automation/src/automation.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { AutomationConfig } from './schema';
66
type AutomationErrorCode =
77
| 'document_load_failed'
88
| 'field_creation_failed'
9-
| 'clear_fields_failed';
9+
| 'remove_fields_failed';
1010

1111
type AutomationResult =
1212
| { success: true; data: null }
@@ -217,17 +217,17 @@ const runAutomation = async ({ config, baseUrl }: RunAutomationArgs): Promise<Au
217217
await waitForDocumentLoaded();
218218
console.log('Document loaded');
219219

220-
console.log('Clearing existing fields...');
221-
const clearRequestId = await sendEvent({ type: 'CLEAR_FIELDS', data: {} });
222-
const clearResult = await waitForEvent('REQUEST_RESULT', { requestId: clearRequestId });
220+
console.log('Removing existing fields...');
221+
const removeRequestId = await sendEvent({ type: 'REMOVE_FIELDS', data: {} });
222+
const removeResult = await waitForEvent('REQUEST_RESULT', { requestId: removeRequestId });
223223

224-
if (!isRequestResultData(clearResult.event.data) || !clearResult.event.data.result.success) {
224+
if (!isRequestResultData(removeResult.event.data) || !removeResult.event.data.result.success) {
225225
return {
226226
success: false,
227-
error: { code: 'clear_fields_failed', message: 'Failed to clear existing fields' },
227+
error: { code: 'remove_fields_failed', message: 'Failed to remove existing fields' },
228228
};
229229
}
230-
console.log('Fields cleared');
230+
console.log('Fields removed');
231231

232232
console.log(`Creating ${config.fields.length} fields...`);
233233
for (let i = 0; i < config.fields.length; i++) {

react/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
### Minor Changes
66

7-
- cae5ce6: Adds new programmatic actions to the React embed component for advanced integrations: goTo, createField, clearFields, getDocumentContent
7+
- cae5ce6: Adds new programmatic actions to the React embed component for advanced integrations: goTo, createField, removeFields, getDocumentContent

react/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Use `const { embedRef, actions } = useEmbed();` to programmatically control the
131131
| `actions.goTo({ page })` | Navigate to a specific page |
132132
| `actions.selectTool(toolType)` | Select a tool: `'TEXT'`, `'BOXED_TEXT'`, `'CHECKBOX'`, `'PICTURE'`, `'SIGNATURE'`, or `null` to deselect (`CURSOR`) |
133133
| `actions.createField(options)` | Create a field at specified position (see below) |
134-
| `actions.clearFields(options?)` | Clear fields by `fieldIds` or `page`, or all fields if no options |
134+
| `actions.removeFields(options?)` | Remove fields by `fieldIds` or `page`, or all fields if no options |
135135
| `actions.getDocumentContent({ extractionMode })` | Extract document content (`extractionMode: 'auto'` or `'ocr'`) |
136136
| `actions.submit({ downloadCopyOnDevice })` | Submit the document |
137137

react/src/hook.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ describe('useEmbed', () => {
260260
expect(actionResult).toEqual(expectedError);
261261
});
262262

263-
it('clearFields returns error when embedRef not attached', async () => {
263+
it('removeFields returns error when embedRef not attached', async () => {
264264
const { result } = renderHook(() => useEmbed());
265-
const actionResult = await result.current.actions.clearFields({});
265+
const actionResult = await result.current.actions.removeFields({});
266266
expect(actionResult).toEqual(expectedError);
267267
});
268268

@@ -288,7 +288,7 @@ describe('useEmbed', () => {
288288
goTo: vi.fn().mockResolvedValue({ success: true }),
289289
selectTool: vi.fn().mockResolvedValue({ success: true }),
290290
createField: vi.fn().mockResolvedValue({ success: true }),
291-
clearFields: vi.fn().mockResolvedValue({ success: true }),
291+
removeFields: vi.fn().mockResolvedValue({ success: true }),
292292
getDocumentContent: vi.fn().mockResolvedValue({ success: true }),
293293
submit: vi.fn().mockResolvedValue({ success: true }),
294294
};
@@ -333,14 +333,14 @@ describe('useEmbed', () => {
333333
expect(actionResult).toEqual({ success: true });
334334
});
335335

336-
it('clearFields delegates to ref.clearFields', async () => {
336+
it('removeFields delegates to ref.removeFields', async () => {
337337
const { result } = renderHook(() => useEmbed());
338338
const { ref, spies } = createMockEmbedRef();
339339
(result.current.embedRef as React.MutableRefObject<EmbedActions>).current = ref;
340340

341-
const actionResult = await result.current.actions.clearFields({});
341+
const actionResult = await result.current.actions.removeFields({});
342342

343-
expect(spies.clearFields).toHaveBeenCalledWith({});
343+
expect(spies.removeFields).toHaveBeenCalledWith({});
344344
expect(actionResult).toEqual({ success: true });
345345
});
346346

@@ -447,12 +447,12 @@ describe('Type assertions', () => {
447447
>();
448448
});
449449

450-
it('clearFields accepts optional { fieldIds?, page? } and returns ActionResult with cleared_count', () => {
451-
expectTypeOf<EmbedActions['clearFields']>()
450+
it('removeFields accepts optional { fieldIds?, page? } and returns ActionResult with removed_count', () => {
451+
expectTypeOf<EmbedActions['removeFields']>()
452452
.parameter(0)
453453
.toEqualTypeOf<{ fieldIds?: string[]; page?: number } | undefined>();
454-
expectTypeOf<EmbedActions['clearFields']>().returns.resolves.toExtend<
455-
ExpectedActionResult<{ cleared_count: number }>
454+
expectTypeOf<EmbedActions['removeFields']>().returns.resolves.toExtend<
455+
ExpectedActionResult<{ removed_count: number }>
456456
>();
457457
});
458458

react/src/hook.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ type DocumentContentResult = {
5858
pages: DocumentContentPage[];
5959
};
6060

61-
type ClearFieldsResult = {
62-
cleared_count: number;
61+
type RemoveFieldsResult = {
62+
removed_count: number;
6363
};
6464

6565
type CreateFieldResult = {
@@ -73,7 +73,7 @@ export type EmbedActions = {
7373

7474
createField: (options: CreateFieldOptions) => Promise<ActionResult<CreateFieldResult>>;
7575

76-
clearFields: (options?: { fieldIds?: string[]; page?: number }) => Promise<ActionResult<ClearFieldsResult>>;
76+
removeFields: (options?: { fieldIds?: string[]; page?: number }) => Promise<ActionResult<RemoveFieldsResult>>;
7777

7878
getDocumentContent: (options: { extractionMode: ExtractionMode }) => Promise<ActionResult<DocumentContentResult>>;
7979

@@ -184,9 +184,9 @@ export const useEmbed = (): { embedRef: React.RefObject<EmbedActions | null>; ac
184184
[],
185185
);
186186

187-
const handleClearFields = React.useCallback(
188-
createAction<[{ fieldIds?: string[]; page?: number }?], ClearFieldsResult>(async (ref, options) => {
189-
return ref.clearFields(options);
187+
const handleRemoveFields = React.useCallback(
188+
createAction<[{ fieldIds?: string[]; page?: number }?], RemoveFieldsResult>(async (ref, options) => {
189+
return ref.removeFields(options);
190190
}),
191191
[],
192192
);
@@ -211,7 +211,7 @@ export const useEmbed = (): { embedRef: React.RefObject<EmbedActions | null>; ac
211211
goTo: handleGoTo,
212212
selectTool: handleSelectTool,
213213
createField: handleCreateField,
214-
clearFields: handleClearFields,
214+
removeFields: handleRemoveFields,
215215
getDocumentContent: handleGetDocumentContent,
216216
submit: handleSubmit,
217217
},

react/src/index.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ describe('EmbedPDF', () => {
312312
expect(typeof ref.current?.goTo).toBe('function');
313313
expect(typeof ref.current?.selectTool).toBe('function');
314314
expect(typeof ref.current?.createField).toBe('function');
315-
expect(typeof ref.current?.clearFields).toBe('function');
315+
expect(typeof ref.current?.removeFields).toBe('function');
316316
expect(typeof ref.current?.getDocumentContent).toBe('function');
317317
expect(typeof ref.current?.submit).toBe('function');
318318
});
@@ -325,7 +325,7 @@ describe('EmbedPDF', () => {
325325
action: 'createField' as const,
326326
args: { type: 'TEXT' as const, page: 1, x: 0, y: 0, width: 100, height: 20 },
327327
},
328-
{ action: 'clearFields' as const, args: {} },
328+
{ action: 'removeFields' as const, args: {} },
329329
{ action: 'getDocumentContent' as const, args: {} },
330330
{ action: 'submit' as const, args: { downloadCopyOnDevice: false } },
331331
])('$action returns error when iframe not available (modal not opened)', async ({ action, args }) => {

react/src/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ export const EmbedPDF = React.forwardRef<EmbedActions, Props>((props, ref) => {
189189
});
190190
}, []);
191191

192-
const clearFields: EmbedActions['clearFields'] = React.useCallback(async (options) => {
192+
const removeFields: EmbedActions['removeFields'] = React.useCallback(async (options) => {
193193
if (!iframeRef.current) {
194194
return { success: false, error: { code: 'unexpected:iframe_not_available', message: 'Iframe not available' } };
195195
}
196196
await ensureEditorReady();
197197
return sendEvent(iframeRef.current, {
198-
type: 'CLEAR_FIELDS',
198+
type: 'REMOVE_FIELDS',
199199
data: { field_ids: options?.fieldIds, page: options?.page },
200200
});
201201
}, []);
@@ -227,7 +227,7 @@ export const EmbedPDF = React.forwardRef<EmbedActions, Props>((props, ref) => {
227227
goTo,
228228
selectTool,
229229
createField,
230-
clearFields,
230+
removeFields,
231231
getDocumentContent,
232232
submit,
233233
}));

0 commit comments

Comments
 (0)