Skip to content

Add a shared differential-style list and index pivot formats into it#55

Draft
gthb wants to merge 3 commits into
jsfkit:mainfrom
gthb:dxf-shared-model
Draft

Add a shared differential-style list and index pivot formats into it#55
gthb wants to merge 3 commits into
jsfkit:mainfrom
gthb:dxf-shared-model

Conversation

@gthb

@gthb gthb commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What

Introduce a shared, workbook-level list of differential (partial) styles, referenced by index, as the single home for formatting that overlays a cell's own style instead of replacing it.

  • Add Workbook.diffStyles?: Style[] — an ordered list of partial style overrides. Only the properties present in an entry apply; everything else on the target cell is left as-is. It reuses the existing, already all-optional Style type.
  • Change PivotFormat to reference an entry by index: the inline style is replaced by diffStyleId?: integer (an index into Workbook.diffStyles).

Why

Several features overlay formatting on top of a cell's own style rather than replacing it: pivot table formats today, custom table styles (#54) and dynamic/conditional styles later. They all want the same kind of partial override, and they want to share entries rather than each carrying its own inline copy. A single shared list referenced by index models this directly, mirroring how cells already work — Cell.s indexes Workbook.styles, and now diffStyleId indexes Workbook.diffStyles. This is the foundation the other overlay features build on, so it lands first on its own.

This replaces the inline PivotFormat.style added in #53. Nothing consumes that field yet, so it is a clean replacement.

Design notes

  • diffStyles reuses Style rather than introducing a separate DiffStyle type: Style is already entirely optional, so it is structurally exactly what a partial override needs. The differential reading — an absent property means "leave unchanged", not "use the default" — comes from the list an entry lives in.
  • diffStyleId is a plain index; the first entry is index 0. There is no implicit default entry (unlike Cell.s, where 0 is the default cell style), and an absent diffStyleId means "no overlay".

Open question

How should a pivot format that explicitly blanks formatting be encoded? This PR keeps the existing convention: PivotFormat.action: 'blank' with no diffStyleId. An alternative would be a dedicated empty entry referenced like any other. Feedback welcome.

Follow-ups (not in this PR)

  • Rework Model workbook-defined (custom) table styles #54 (custom table styles) onto this list — TableStyleElement referencing diffStyleId instead of an inline style (prototyped locally).
  • The converters then emit/parse diffStyles, resolve the index references, and dedup equal entries into one shared list.

gthb added 3 commits June 24, 2026 15:51
Introduce a workbook-level list of differential styles (dxf records) that
formatting-overlay features reference by index, instead of each feature
inlining a full Style. This is the differential-overlay analog of
Workbook.styles: where Cell.s indexes a complete cell style, an overlay's
dxfId indexes a partial override.

The list element type reuses the existing Style type, which is already
all-optional; what differs is interpretation (absent property means
"leave unchanged", not "use the default") and the list it lives in, not
the structure. A separate DiffStyle type would duplicate ~25 identical
properties for no structural gain, mirroring OOXML where <dxf> reuses the
same children as <xf>.

- Workbook.diffStyles?: Style[]  (name provisional)
- PivotFormat: replace inline `style?: Style` with `dxfId?: integer`
  indexing into Workbook.diffStyles.

BREAKING: this changes the shipped 2.5.0 PivotFormat.style (inline Style)
to PivotFormat.dxfId (index). Done intentionally to avoid baking the
inline-Style "legacy" deeper before more features depend on it.
Rename the differential-style index field from `dxfId` to `diffStyleId`
(PivotFormat.diffStyleId) and update the Workbook.diffStyles docstring and
@see references to match. The old name echoed a file-format attribute
name; `diffStyleId` keeps the model naming consistent with `diffStyles`
and free of format-specific terms.

Also drop the "name is provisional" note from the diffStyles docstring —
the name is now final.
The formats docstring still said each format carries its differential
style inline and that there is no separate style table, and linked the
removed PivotFormat.style. Both are now false: formats reference a shared
differential style by index. Point at PivotFormat.diffStyleId and
Workbook.diffStyles instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant