@fuaran-ui/ops 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/dist/index.cjs +686 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +184 -2
- package/dist/index.d.ts +184 -2
- package/dist/index.js +676 -53
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -61,6 +61,38 @@ if (result.ok) {
|
|
|
61
61
|
`EMPTY_NODE_ID` — byte-identical to the F# decoder's codes, surfaced at a `$`-rooted
|
|
62
62
|
dotted path.
|
|
63
63
|
|
|
64
|
+
## Placement helpers
|
|
65
|
+
|
|
66
|
+
`placeOp` / `moveOp` / `nudgeOp` / `canPlace` (plus the clone verbs
|
|
67
|
+
`duplicateOp` / `pasteOp` and their `…With` variants taking an injectable
|
|
68
|
+
fresh-id strategy) derive the ops that put a node **at a stated position** —
|
|
69
|
+
first, last, before or after a named sibling — from the positionless op
|
|
70
|
+
vocabulary.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { placeOp, moveOp, nudgeOp, canPlace, apply } from '@fuaran-ui/ops';
|
|
74
|
+
|
|
75
|
+
// Insert `child` immediately before sibling "b" under parent "left".
|
|
76
|
+
const r = placeOp(tree, child, {
|
|
77
|
+
parentId: 'left',
|
|
78
|
+
placement: { kind: 'Before', anchor: 'b' },
|
|
79
|
+
}); // Result<TreeOp, PlaceError>
|
|
80
|
+
if (r.ok) apply(tree, r.value);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**These helpers emit only existing `TreeOp` shapes** — a bare `InsertChild` /
|
|
84
|
+
`MoveNode` when appending already yields the wanted order, otherwise
|
|
85
|
+
`Batch [InsertChild|MoveNode, ReorderChildren]`, and `ReorderChildren` alone
|
|
86
|
+
for a nudge. There is no new op case and **no wire-format change**; anything
|
|
87
|
+
they emit encodes, decodes, and applies exactly as if a consumer had assembled
|
|
88
|
+
it by hand. Pre-checks mirror the apply engine's own rejections (absent or
|
|
89
|
+
childless parent, move-into-self, move-into-descendant, duplicate id), so a
|
|
90
|
+
helper refusal and an apply refusal always agree; an anchor that is not among
|
|
91
|
+
the destination's children is refused (`UnknownAnchor`) rather than silently
|
|
92
|
+
appended. The clone verbs remap colliding ids across the whole traversal
|
|
93
|
+
surface before insert, so a duplicate or paste never trips the tree-wide
|
|
94
|
+
duplicate-id check.
|
|
95
|
+
|
|
64
96
|
## Storage-shape erasure
|
|
65
97
|
|
|
66
98
|
Decode is **storage-shape erased**: it always yields `Node<unknown>` / `TreeOp<unknown>`,
|