You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* fix(super-converter): bibliography/index/TOA field-code import fidelity (SD-3066)
Real Word documents surfaced several import defects in the block field-code
family (BIBLIOGRAPHY, INDEX, XE, TOA). This addresses them and unifies the
shared shape behind one set of helpers.
Fixes:
- Multi-run instruction aggregation joined fragments with an injected separator
space, corrupting instructions Word splits across runs (e.g.
`XE " Building Standard "`). Join verbatim; literal spacing is preserved.
- Table of Authorities was dropped on import: the v2 importer had no
`sd:tableOfAuthorities` handler, so the node was silently discarded. Register
tableOfAuthoritiesImporter alongside index/bibliography.
- A content control wrapping a block field imported as an inline
`structuredContent` node; inside a block-only documentPartObject this threw
"Invalid content for node type documentPartObject" and the editor failed to
mount. Classify an SDT whose content is a block field as
structuredContentBlock.
- Bibliography neither captured nor replayed instructionTokens (unlike
index/toa), so split BIBLIOGRAPHY instructions did not round-trip. Add the
attribute and wire it through preprocessor, encode and decode.
Refactors (DRY/KISS):
- Extract buildBlockFieldNode (shared by the bibliography/index/toa
preprocessors) and wrapParagraphsAsComplexField (shared by their translator
decoders), mirroring the existing inline-field helpers.
- Centralize BLOCK_FIELD_XML_NAMES so the paragraph importer and SDT classifier
agree on which sd:* nodes are block content.
Adds RED→GREEN unit tests for each fix and the new shared helpers. Full
super-converter suite passes (2990).
Linear: SD-3066 (parent of SD-3005)
* fix(pm-adapter): render bibliography/index/TOA inside documentPartObject (SD-3066) (#3566)
Word wraps a generated bibliography (and other block fields) in a docPartObject
SDT, sometimes via a nested content control. The handler only converted
paragraph and tableOfContents children to flow blocks, so the field's entry
paragraphs were silently dropped — the heading rendered but the entries did
not.
- documentPartObject now renders bibliography/index/tableOfAuthorities children
via the shared paragraph-container handler, and structuredContentBlock
children via their handler.
- structuredContentBlock recurses block-field children (transparent wrapper),
rendering their paragraphs.
Section-counting invariant: findParagraphsWithSectPr recurses bibliography
(so the handler advances currentParagraphIndex per entry) but not
structuredContentBlock (so the scb path renders without advancing). Both paths
were validated against the invariant; the prior code dropped entries AND
under-counted, which could drift section breaks.
Also extracts the shared handleParagraphContainerNode used by the bibliography,
index and tableOfAuthorities handlers (previously three byte-identical copies).
Regression tests cover both nesting shapes and the counter behavior. pm-adapter
suite passes (302); layout corpus comparison shows no regressions attributable
to this change.
Linear: SD-3066
* feat(painter-dom): custom SDT styling variables under chrome:'none' (SD-3322)
Under modules.contentControls.chrome:'none' the painter erased the SDT look
entirely, so a consumer who wanted a custom field/clause appearance had to target
the painted wrapper with !important and reach into internal state classes
(.ProseMirror-selectednode, .sdt-group-hover) to keep it stable across hover and
selection. That's the wrong "best practice" to teach.
Make the chrome-none reset read a --sd-content-controls-custom-* variable layer
with default-preserving fallbacks (0-width transparent border, no background /
radius / padding). chrome:'none' stays visually empty by default - existing
consumers see no change - but a consumer can now paint inline and block controls
by setting variables on a data-sdt-* selector. The painter applies them across
rest, hover, and selected, so the box stays stable (no jitter) and no !important
or state-class selectors are needed. `border` is a full shorthand; block adds a
`-border-left` accent rail; background vars cascade (hover from rest, selected
from hover).
- variables.css: document the custom-* surface; note the built-in chrome still
uses the existing --sd-content-controls-* variables.
- docs: add a "Style the controls in place" section to the custom-UI content
controls guide.
- test: assert the surface is wired and default-preserving; existing chrome-none
selector + source-order tests are unchanged and still pass (painter-dom 1178/1178).
* fix(painter-dom): custom hover wins on locked SDTs under chrome:'none' (SD-3322)
The custom hover background was overridden for LOCKED controls under chrome:'none'.
The base lock-hover rules (a built-in tint on inline, transparent on block) have
equal specificity to the plain custom hover rules but come later in source order,
so they won; the chrome-none lock-hover reset only reset z-index, not background.
Re-assert the custom hover background in that reset block - it carries the extra
.superdoc-cc-chrome-none class, so it outranks the base lock-hover rules. A locked
control now follows --sd-content-controls-custom-*-hover-bg. With no custom var
set the default is empty, so the built-in lock-hover tint no longer leaks under
chrome:'none' for locked controls (consistently empty). Only the contract-templates
demo has locked chrome-none controls, and it wants the custom hover, not the tint.
Add a regression test asserting the custom hover vars are re-asserted after the
base lock-hover rules (source order = it wins). painter-dom 1179/1179 green.
* docs(theming): point chrome:'none' styling at the custom SDT variables (SD-3322)
The content-controls theming table themes the built-in chrome. Add a one-line
note that under chrome:'none' you style controls with the
--sd-content-controls-custom-* variables instead, linking the custom UI guide.
* demo/docs: contract-templates use the custom SDT styling variables (SD-3322)
Rewrite the contract-templates demo's SDT styling onto SuperDoc's public
--sd-content-controls-custom-* variables (from #3590), proving the new API in the
real legal-template use case. The demo now styles its inline fields and block
clauses with zero !important and zero internal state selectors
(.ProseMirror-selectednode, .sdt-group-hover); the painter applies the variables
across rest, hover, selected, and locked-hover. This is the copy-pasteable
pattern for styling custom SDTs under chrome:'none'.
- style.css: replace the per-state !important rules with one variable-setting
rule per tag (inline + block); update the host-owned-styling comment.
- test: add state coverage - the custom hover background drives a painted field
(and wins over the built-in lock-hover tint), the border stays constant across
states (no jitter), and no built-in label/chrome leaks. Demo suite 13/13.
- docs (Document API > Content controls): correct the contentLocked wording (it
rejects Document API content writes too, not just the editor); document the
locked-template pattern (unlock -> write -> relock, incl. a locked parent for
nested fields); add the single-use governed clause-library pattern alongside
versioned reusable sections (kept - it's a valid pattern).
- docs (Custom UI > Content controls): add a "Build a custom field system"
walkthrough; describe the demo as a full custom contract-template UI.
- README: note the demo styles through the public custom variables.
Stacked on #3590 (the painter variable layer); retarget to main once it merges.
Or keep clauses **single-use and governed**: a clause is either in the contract or available to add from a library, and it appears once. Track inclusion by querying `contentControls.list` for the `sectionId` instead of comparing versions, and lock each placed clause (`contentLocked`) so its prose is fixed. A clause can also carry nested smart fields - inline controls inside the block - that fill from one place.
70
+
71
+
The [`demos/contract-templates`](https://github.com/superdoc-dev/superdoc/tree/main/demos/contract-templates) runtime composes the single-use approach: a clause library that inserts locked block clauses (some with nested fields), each filled by tag from a form.
70
72
71
73
## Why `tag`, not `nodeId`
72
74
@@ -134,10 +136,12 @@ Set `lockMode` when you create a control to govern which changes are allowed.
134
136
|---|---|
135
137
|`unlocked`| Content and properties can be updated through the Document API. |
136
138
|`sdtLocked`| The wrapper is preserved through user edits. |
137
-
|`contentLocked`| The content can't be modified through the editor surface. |
139
+
|`contentLocked`| The user can't edit the content, **and** content writes through the Document API (`text.setValue`, `replaceContent`) are rejected too - they return a `LOCK_VIOLATION`. |
138
140
|`sdtContentLocked`| Both wrapper and content are preserved. |
139
141
140
-
For controls your app drives with `text.setValue`, `replaceContent`, or `patch`, use `lockMode: 'unlocked'`.
142
+
For controls your app drives freely with `text.setValue` or `replaceContent`, use `lockMode: 'unlocked'`.
143
+
144
+
For a **locked template** - controls the user can't touch, but your app still updates - keep them `contentLocked` and unlock around each write: `setLockMode({ lockMode: 'unlocked' })`, write, then `setLockMode({ lockMode: 'contentLocked' })`. Use `try`/`finally` so a failed write never leaves a control unlocked. `setLockMode` and `patch` are not blocked by `contentLocked`, so only the content write needs the unlock window. A smart field nested inside a locked block control needs the **parent** unlocked for the write too, since the parent's content lock vetoes writes to anything inside it.
Copy file name to clipboardExpand all lines: apps/docs/editor/custom-ui/content-controls.mdx
+39-1Lines changed: 39 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,33 @@ new SuperDoc({
30
30
31
31
The event tells you *what* is active; `getRect` tells you *where* to draw. `active` is an `SdtRef` with `id`, `tag`, `alias`, `controlType`, and `scope`.
32
32
33
+
## Style the controls in place
34
+
35
+
Turning off chrome erases the built-in look, including hover and selection. To paint your own field and clause look, set `--sd-content-controls-custom-*` variables on the painted wrapper. Target it by your own `data-sdt-*` attributes. No `!important`, and no need to touch SuperDoc's internal state classes: the painter applies your variables across rest, hover, and selected, so the box stays stable and you never write `.ProseMirror-selectednode` or hover rules yourself.
36
+
37
+
```css
38
+
/* A field your app tagged { kind: 'smartField', ... } */
`border` is a full CSS shorthand; `border-left` is an optional accent rail for block clauses. The background variables cascade, so set only what changes: `-hover-bg` defaults to `-bg`, and `-selected-bg` defaults to `-hover-bg`.
57
+
58
+
This is the path for `chrome: 'none'`. To theme the **built-in** chrome instead (`chrome: 'default'`), use the `--sd-content-controls-*` variables (without `custom`).
59
+
33
60
## Pick the right surface
34
61
35
62
| Goal | API |
@@ -55,8 +82,19 @@ The event tells you *what* is active; `getRect` tells you *where* to draw. `acti
55
82
56
83
You build your UI *over* the control, not inside it. SuperDoc owns how the control's content is painted in the document; you turn off its built-in chrome and draw your own (chips, badges, panels) anchored with `getRect`, react with the events, and change content through `editor.doc.contentControls.*`. Custom field types are expressed as a `tag` - for example `{ kind: 'smartField', key: 'party_name' }`, interpreted by your own UI - the underlying control stays a standard Word SDT so it round-trips to `.docx`.
57
84
85
+
## Build a custom field system
86
+
87
+
Putting it together into a fillable template, the way the contract-templates demo does:
88
+
89
+
1.**Define a tag schema.** Give each control a JSON `tag` your app owns - e.g. `{ kind: 'smartField', key }` for inline variables and `{ kind: 'reusableSection', sectionId }` for clauses.
90
+
2.**Insert from a palette.** Drop a control at a point with `editor.doc.create.contentControl({ kind, at, content, tag, lockMode })`, resolving the drop point with `ui.viewport.positionAt({ x, y })`. A clause can wrap its `{ field }` slots as nested inline controls.
91
+
3.**Style it.** Set the `--sd-content-controls-custom-*` variables on a `data-sdt-tag` selector (see [Style the controls in place](#style-the-controls-in-place)). The sidebar chips can reuse the same tokens, so palette and document match.
92
+
4.**React.** Highlight the active control from `content-control:active-change` / `:click`, and anchor overlays with `getRect` + `ui.viewport.observe`.
93
+
5.**Fill by tag.** A form edits a value and fans it to every occurrence: `editor.doc.contentControls.selectByTag({ tag })`, then `text.setValue` per occurrence.
94
+
6.**Govern with locks.** Keep controls `contentLocked` so users can't edit them, and have the form unlock → write → relock (see [Lock modes](/document-api/features/content-controls#lock-modes)). For a field nested in a locked clause, unlock the parent for the write.
95
+
58
96
## See also
59
97
60
-
-[Contract templates demo](https://github.com/superdoc-dev/superdoc/tree/main/demos/contract-templates) - a working field chip built on these APIs.
98
+
-[Contract templates demo](https://github.com/superdoc-dev/superdoc/tree/main/demos/contract-templates) - a full custom contract-template UI: a field + clause library, custom SDT styling, locks, form-driven values, events, insert, and export.
61
99
-[Configuration](/editor/superdoc/configuration) - the `modules.contentControls.chrome` option.
62
100
-[Document API: content controls](/document-api/features/content-controls) - read and change controls.
Copy file name to clipboardExpand all lines: apps/docs/editor/theming/custom-themes.mdx
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -318,6 +318,8 @@ If you also want tracked-change text inside comment threads to match, set `--sd-
318
318
319
319
DOCX content controls (SDTs): form fields, dropdowns, date pickers.
320
320
321
+
These theme the **built-in** chrome (`modules.contentControls.chrome: 'default'`). If you turn the chrome off (`chrome: 'none'`) to draw your own field/clause look, style the controls with the `--sd-content-controls-custom-*` variables instead. See [Custom UI > Content controls](/editor/custom-ui/content-controls).
322
+
321
323
| Variable | Default | Controls |
322
324
|----------|---------|----------|
323
325
|`--sd-content-controls-block-border`|`#629be7`| Block control border |
Copy file name to clipboardExpand all lines: demos/contract-templates/README.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,8 @@ The starting document is `public/nda-template.docx`: inline plain-text fields an
15
15
- Smart-field chips wear the same blue token look as the in-document field (CSS on `.superdoc-structured-content-inline[data-sdt-tag*='smartField']`). Drag a chip onto the document, or click to insert it at the cursor. An unfilled field shows its field-name token (e.g. `DISCLOSING_PARTY`) as a stand-in placeholder. That token is literal text content, not a native SDT placeholder.
16
16
- Clause cards wear the same blue block look as the in-document clause and carry metadata (category, jurisdiction, version) and a status. A clause is single-use, like an inclusion checklist: a card already in the contract reads **In contract** and clicking it reveals the existing clause; an available card reads **Add clause** and drags or clicks in. The catalog includes clauses that aren't in the document yet (e.g. Indemnification, Return of Materials).
17
17
18
+
**Custom styling.** With chrome off, the field and clause look is set entirely through SuperDoc's public `--sd-content-controls-custom-*` CSS variables, on a `data-sdt-tag` selector. SuperDoc applies them across rest, hover, selected, and locked-hover, so the demo's CSS has no `!important` and no internal state classes (`.ProseMirror-selectednode`, `.sdt-group-hover`) - copy these rules to style your own SDTs. See [Custom UI > Content controls](https://docs.superdoc.dev/editor/custom-ui/content-controls).
19
+
18
20
Inserts resolve the drop point with `ui.viewport.positionAt({ x, y })` and create the control with `editor.doc.create.contentControl({ kind, at, content, tag, lockMode })`. A field inserts inline at the exact caret; a clause snaps to a block boundary so it lands as a clean section instead of splitting a paragraph. Clicking a control in the document highlights its chip or card (`content-control:click`).
19
21
20
22
A clause is assembled from structured `parts`: prose plus `{ field }` slots. Inserting "Permitted Use" creates the block and then wraps each slot as a nested, locked inline smart field, so the inserted clause carries real Receiving party and Purpose fields, just like the seeded one. Filling those fields in the Values tab updates the clause and the header sentence together.
0 commit comments