-
Notifications
You must be signed in to change notification settings - Fork 1
fix: update field ID type and improve field handling #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: update field ID type and improve field handling #14
Conversation
This commit modifies the TemplateField interface to allow the ID to be either a string or a number. It also updates the SuperDocTemplateBuilder component to handle the new ID type, ensuring that field insertion, deletion, and selection functions correctly accommodate both types. This change enhances flexibility in managing template fields.
SD-548 Use numeric IDs for fields (XML/Word compatibility)
SummaryRemove ID generation from template-builder and let SuperDoc library handle it automatically using its proper Tasks
NotesCurrent problem (src/index.tsx): const fieldId = `field_${Date.now()}`; // ❌ Template builder generates string ID
editor.commands.insertStructuredContentInline?.({
attrs: {
id: fieldId, // ❌ Passes ID to SuperDoc, bypassing auto-generation
alias: field.alias,SuperDoc already handles this (structured-content-commands.js): const attrs = {
...options.attrs,
id: options.attrs?.id || generateRandomSigned32BitIntStrId(), // ✅ Auto-generates if not provided
tag: 'inline_text_sdt',
alias: options.attrs?.alias || 'Structured content',
};The fix - just delete the ID code: // DELETE: const fieldId = `field_${Date.now()}`;
editor.commands.insertStructuredContentInline?.({
attrs: {
// DELETE: id: fieldId,
alias: field.alias,
tag: field.category,
},
text: field.defaultValue || field.alias,
});Why this is better:
After the fix: SuperDoc will automatically generate proper numeric IDs for all new fields Testing: Create fields → export to .docx → open in Microsoft Word → verify SDT tags work correctly |
This commit simplifies the mapping logic in the getTemplateFieldsFromEditor function by removing unnecessary filtering. The function now directly returns the mapped tags, enhancing readability and maintainability of the code.
|
🎉 This PR is included in version 0.2.0-next.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [0.2.0](v0.1.0...v0.2.0) (2025-11-13) ### Bug Fixes * force pre-release ([f752754](f752754)) * improve cleanup logic ([#11](#11)) ([01f0bf9](01f0bf9)) * update field ID type and improve field handling ([#14](#14)) ([e0e6d31](e0e6d31)) * update field IDs and categories in README and App component ([61a473d](61a473d)) ### Features * add import functionality for .docx files in the template builder ([#15](#15)) ([42faccc](42faccc)) * enhance exportTemplate functionality with configurable options ([#17](#17)) ([7e2a03d](7e2a03d)) * enhance field handling with mode support in template builder ([#16](#16)) ([d46ab5d](d46ab5d)) * implement viewport clamping for menu positioning in SuperDocTemplateBuilder ([#10](#10)) ([09e82ee](09e82ee))
|
🎉 This PR is included in version 0.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This commit modifies the TemplateField interface to allow the ID to be either a string or a number. It also updates the SuperDocTemplateBuilder component to handle the new ID type, ensuring that field insertion, deletion, and selection functions correctly accommodate both types. This change enhances flexibility in managing template fields.