Skip to content

fix(site): keep an item's value when its type is switched and switched back - #34

Merged
Mearman merged 6 commits into
mainfrom
fix/site-type-switch-keeps-value
Oct 29, 2026
Merged

Mearman merged 6 commits into
mainfrom
fix/site-type-switch-keeps-value

Conversation

@Mearman

@Mearman Mearman commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Switching a dimension value to a number and back to text lost the text: linux came back as "0". Switching a rule's text literal to a number and back left the text box empty, so the model reported that the rule compared os with an empty text. The form built the new node from whatever the new type could carry and dropped the rest, and every other switch it offers did the same: the kind of a predicate or an expression, a fold's mode, a complex literal's form, a rule's form, and a reference key made not to name a dimension.

The editor now remembers, for the loaded model, what each item last held in each type, keyed by the item's path, and gives that back when the item is switched to that type again. A switch to a type the item has not been in carries the value across only where nothing is lost: a number as its decimal text, canonical numeric text as the number, and true and false as text and back. Anything else starts the new type's default, which the old loose conversions (true to 1, any non-zero number to true, text read as a number by loose parsing) did not.

The memory is not part of the model or its JSON. A replaced model (example, import, link, gist, saved model, a valid edit in the JSON view) starts it empty, and an edit that moves, removes or renames items forgets what was remembered inside them. An edit that adds at the end or types a value leaves it alone, and renaming a dimension forgets all of it because remembered nodes may name the old one.

The rule for what a switch gives is in the header comment of site/src/typeMemory.ts. An item's own value (a scalar, an operator, a function name) comes back as it was last held in the variant being switched to. The children a kind has places for are shared by position between its kinds, so a child edited while the item was in another kind is put into every remembered kind that has a place for it, with what was remembered of its own items, and a child that is only carried across or defaulted does not displace what is remembered. Editing the first operand of an all of as the first side of both and switching back gives the edited operand and the other two from memory, and a trip through not, which has room for one, still gives the third back.

@Mearman
Mearman force-pushed the fix/site-type-switch-keeps-value branch from bc34457 to d00cc15 Compare October 29, 2026 20:26
… value

Switching an item to another type started from the nearest value of the new type,
so true became 1 and text was read as a number by loose parsing.
Now only a value of the same type, the decimal text of a number, and exactly
the texts true and false are carried; everything else starts the new type's default.
Expression literals switched between text, number and true or false follow the same rule.
The scalar helpers move into one module.
…d back

The form replaced a node with one built from what the new type could carry, so switching a
value or an expression to another type and back lost what it was.
The editor now remembers, for the loaded model, what each item last held in each type, keyed by
the item's path, and gives that back when the item is switched to that type again.
This covers the type of a value, the kind of a predicate or expression, a fold's mode,
a complex literal's form, a rule's form and a reference key made not to name a dimension.
The memory is never part of the model or its JSON. A replaced model starts it empty, and an edit
that moves, removes or renames items forgets what was remembered inside them.
…estores the node

The chains run on the editor state without drawing the form, so many more are tried
for the work one drawn chain costs; the drawn form keeps its cases that name a kind.
…e absent

sameJson compares by content whatever the order of an object's keys.
putIn replaces the value at a path, or removes or adds the entry of an object that is the
last step, so an optional part can be put back as it was.
…kind

Switching an item back to a kind it had been in gave the remembered part as it was left,
so a child edited in between was lost, such as the first operand of all of
edited as the first side of both.
The children a kind has places for are now shared by position between its kinds.
A child that differs from what the switch produced is an edit, and is put in every remembered
kind that has a place for it, with what was remembered of its own items.
A child that is only carried or defaulted does not displace what is remembered.
Each vocabulary of variants (predicate and expression kinds, a fold's mode, a complex literal's
form, a rule's statement) names where its children are, and has its own memory at a place.
The form-drawing tests and the generated switch sequences ran under vitest's default timeout,
which a loaded machine exceeds while the work is unchanged.
Each now takes its draws or steps times a named budget, as the library's budget tests do.
@Mearman
Mearman force-pushed the fix/site-type-switch-keeps-value branch from 17e9cbb to 9721153 Compare October 29, 2026 21:00
@Mearman
Mearman marked this pull request as ready for review October 29, 2026 21:15
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ⚠️ Failed 2026-10-29T21:15:39.199037Z
We couldn’t complete this review. Comment @codex security review to try again.
9721153 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

This security review couldn’t start because the paying account has exhausted its Codex allowance and has insufficient available credits. The payer can check their balance and add credits in the Codex usage dashboard, then try again. If you do not manage the paying account, contact this repository's admins.

@Mearman
Mearman merged commit 7f9f841 into main Oct 29, 2026
11 checks passed
@Mearman
Mearman deleted the fix/site-type-switch-keeps-value branch October 29, 2026 21:16
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 2.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant