@fuaran-ui/ops 0.1.0 → 0.2.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/dist/index.d.cts CHANGED
@@ -59,7 +59,6 @@ type TreeOp<TMsg> = {
59
59
  } | {
60
60
  readonly kind: 'InsertChild';
61
61
  readonly parentId: NodeId;
62
- readonly position: number;
63
62
  readonly child: Node<TMsg>;
64
63
  } | {
65
64
  readonly kind: 'RemoveNode';
@@ -68,7 +67,6 @@ type TreeOp<TMsg> = {
68
67
  readonly kind: 'MoveNode';
69
68
  readonly target: NodeId;
70
69
  readonly newParentId: NodeId;
71
- readonly newPosition: number;
72
70
  } | {
73
71
  readonly kind: 'ReorderChildren';
74
72
  readonly parentId: NodeId;
package/dist/index.d.ts CHANGED
@@ -59,7 +59,6 @@ type TreeOp<TMsg> = {
59
59
  } | {
60
60
  readonly kind: 'InsertChild';
61
61
  readonly parentId: NodeId;
62
- readonly position: number;
63
62
  readonly child: Node<TMsg>;
64
63
  } | {
65
64
  readonly kind: 'RemoveNode';
@@ -68,7 +67,6 @@ type TreeOp<TMsg> = {
68
67
  readonly kind: 'MoveNode';
69
68
  readonly target: NodeId;
70
69
  readonly newParentId: NodeId;
71
- readonly newPosition: number;
72
70
  } | {
73
71
  readonly kind: 'ReorderChildren';
74
72
  readonly parentId: NodeId;
package/dist/index.js CHANGED
@@ -360,8 +360,10 @@ var flushTrigger = (t) => {
360
360
  };
361
361
  var binding = (b, staticEnc = objValue) => {
362
362
  switch (b.kind) {
363
- case "Static":
364
- return caseObj("Static", [["value", staticEnc(b.value)]]);
363
+ case "Static": {
364
+ const valueFields = b.value === null || b.value === void 0 ? [] : [["value", staticEnc(b.value)]];
365
+ return caseObj("Static", valueFields);
366
+ }
365
367
  case "Query": {
366
368
  const dependsOnFields = b.dependsOn !== void 0 && b.dependsOn.length > 0 ? [["dependsOn", jArray(b.dependsOn.map((s) => str(s)))]] : [];
367
369
  return caseObj("Query", [...dependsOnFields, ["name", str(b.name)]]);
@@ -375,11 +377,10 @@ var binding = (b, staticEnc = objValue) => {
375
377
  const fieldField = b.field !== void 0 ? [["field", str(b.field)]] : [];
376
378
  return caseObj("Selection", [...defaultField, ...fieldField, ["nodeId", str(b.nodeId)]]);
377
379
  }
378
- case "State":
379
- return caseObj("State", [
380
- ["defaultValue", staticEnc(b.defaultValue)],
381
- ["key", str(b.key)]
382
- ]);
380
+ case "State": {
381
+ const defaultFields = b.defaultValue === null || b.defaultValue === void 0 ? [] : [["defaultValue", staticEnc(b.defaultValue)]];
382
+ return caseObj("State", [...defaultFields, ["key", str(b.key)]]);
383
+ }
383
384
  case "Computed":
384
385
  return caseObj("Computed", [["fn", CLOSURE]]);
385
386
  case "I18n": {
@@ -1515,15 +1516,13 @@ var treeOp = (op) => {
1515
1516
  case "InsertChild":
1516
1517
  return caseObj("InsertChild", [
1517
1518
  ["child", node(op.child)],
1518
- ["parentId", str(op.parentId)],
1519
- ["position", num(op.position)]
1519
+ ["parentId", str(op.parentId)]
1520
1520
  ]);
1521
1521
  case "RemoveNode":
1522
1522
  return caseObj("RemoveNode", [["target", str(op.target)]]);
1523
1523
  case "MoveNode":
1524
1524
  return caseObj("MoveNode", [
1525
1525
  ["newParentId", str(op.newParentId)],
1526
- ["newPosition", num(op.newPosition)],
1527
1526
  ["target", str(op.target)]
1528
1527
  ]);
1529
1528
  case "ReorderChildren":
@@ -4032,9 +4031,8 @@ var decodeBinding = (path, j, parseStatic = (_p, v) => ok(decodeAstValue(v)), pl
4032
4031
  if (!d.ok) return d;
4033
4032
  switch (d.value) {
4034
4033
  case "Static": {
4035
- const v = requireField(path, f, "value", "Binding.Static value of the slot's expected type");
4036
- if (!v.ok) return v;
4037
- const parsed = parseStatic(`${path}.value`, v.value);
4034
+ const raw = f.get("value") ?? { kind: "JNull" };
4035
+ const parsed = parseStatic(`${path}.value`, raw);
4038
4036
  return parsed.ok ? ok({ kind: "Static", value: parsed.value }) : parsed;
4039
4037
  }
4040
4038
  case "Query": {
@@ -4111,7 +4109,7 @@ var decodeBinding = (path, j, parseStatic = (_p, v) => ok(decodeAstValue(v)), pl
4111
4109
  case "State": {
4112
4110
  const key = reqField(path, f, "key", "state key string", requireString);
4113
4111
  if (!key.ok) return key;
4114
- const dv = fieldAliased(f, "defaultValue", ["initialValue", "default"]);
4112
+ const dv = fieldAliased(f, "defaultValue", ["initialValue", "default"]) ?? { kind: "JNull" };
4115
4113
  let defaultValue = placeholder;
4116
4114
  if (dv !== void 0) {
4117
4115
  const parsed = parseStatic(`${path}.defaultValue`, dv);
@@ -5826,23 +5824,6 @@ var decodeVisKind = (path, j) => {
5826
5824
  const r = decodeChartSpec(path, j);
5827
5825
  return r.ok ? ok({ kind: "Chart", spec: r.value }) : r;
5828
5826
  }
5829
- // Phase 393 — legacy decode-upgrade: a `Table` tag folds into a read-only `Grid`
5830
- // (the `staticRows` mode). Accepted on read but NEVER re-encodes as `Table` (the
5831
- // encoder has no `Table` arm), riding the Phase 390 retired-kind seam.
5832
- case "Table": {
5833
- const r = decodeStaticRows(path, j);
5834
- return r.ok ? ok({
5835
- kind: "Grid",
5836
- spec: {
5837
- // An opaque Static source re-encodes to {"$type":"Static","value":"<opaque>"} —
5838
- // byte-identical to the F# static grid's `Binding.Static Seq.empty`.
5839
- source: { kind: "Static", value: OPAQUE2 },
5840
- columns: [],
5841
- editable: false,
5842
- staticRows: r.value
5843
- }
5844
- }) : r;
5845
- }
5846
5827
  case "Map": {
5847
5828
  const r = decodeMapSpec(path, j);
5848
5829
  return r.ok ? ok({ kind: "Map", spec: r.value }) : r;
@@ -5934,64 +5915,6 @@ var decodeBox = (path, j) => {
5934
5915
  role: role.value
5935
5916
  });
5936
5917
  };
5937
- var decodeLegacyDashboard = (path, j) => {
5938
- const fo = requireObject(path, j);
5939
- if (!fo.ok) return fo;
5940
- const children = decodeChildren(path, fo.value);
5941
- if (!children.ok) return children;
5942
- return ok({ children: children.value, layout: { kind: "Auto" }, role: "Dashboard" });
5943
- };
5944
- var decodeLegacyStack = (path, j) => {
5945
- const fo = requireObject(path, j);
5946
- if (!fo.ok) return fo;
5947
- const f = fo.value;
5948
- const children = decodeChildren(path, f);
5949
- if (!children.ok) return children;
5950
- const orientation = reqField(path, f, "orientation", "Orientation", decodeOrientation);
5951
- if (!orientation.ok) return orientation;
5952
- const wrap = reqField(path, f, "wrap", "wrap bool", requireBool);
5953
- if (!wrap.ok) return wrap;
5954
- return ok({
5955
- children: children.value,
5956
- layout: { kind: "Flex", direction: orientation.value, wrap: wrap.value },
5957
- role: "Group"
5958
- });
5959
- };
5960
- var decodeLegacyGridLayout = (path, j) => {
5961
- const fo = requireObject(path, j);
5962
- if (!fo.ok) return fo;
5963
- const f = fo.value;
5964
- const children = decodeChildren(path, f);
5965
- if (!children.ok) return children;
5966
- const cols = reqFieldAliased(path, f, "cols", ["columns"], "cols integer", requireInt);
5967
- if (!cols.ok) return cols;
5968
- const templateColumns = optField(path, f, "templateColumns", requireString);
5969
- if (!templateColumns.ok) return templateColumns;
5970
- return ok({
5971
- children: children.value,
5972
- layout: {
5973
- kind: "Grid",
5974
- cols: cols.value,
5975
- ...templateColumns.value !== void 0 ? { templateColumns: templateColumns.value } : {}
5976
- },
5977
- role: "Group"
5978
- });
5979
- };
5980
- var decodeLegacyCard = (path, j) => {
5981
- const fo = requireObject(path, j);
5982
- if (!fo.ok) return fo;
5983
- const f = fo.value;
5984
- const children = decodeChildren(path, f);
5985
- if (!children.ok) return children;
5986
- const heading = optFieldAliased(path, f, "heading", ["title"], decodeTextSource);
5987
- if (!heading.ok) return heading;
5988
- return ok({
5989
- children: children.value,
5990
- ...heading.value !== void 0 ? { heading: heading.value } : {},
5991
- layout: { kind: "Flex", direction: "Vertical", wrap: false },
5992
- role: "Card"
5993
- });
5994
- };
5995
5918
  var decodeSplitPanelSpec = (path, j) => {
5996
5919
  const fo = requireObject(path, j);
5997
5920
  if (!fo.ok) return fo;
@@ -6181,22 +6104,6 @@ var decodeLayoutKind = (path, j) => {
6181
6104
  const r = decodeBox(path, j);
6182
6105
  return r.ok ? ok({ kind: "Box", spec: r.value }) : r;
6183
6106
  }
6184
- case "Dashboard": {
6185
- const r = decodeLegacyDashboard(path, j);
6186
- return r.ok ? ok({ kind: "Box", spec: r.value }) : r;
6187
- }
6188
- case "Stack": {
6189
- const r = decodeLegacyStack(path, j);
6190
- return r.ok ? ok({ kind: "Box", spec: r.value }) : r;
6191
- }
6192
- case "GridLayout": {
6193
- const r = decodeLegacyGridLayout(path, j);
6194
- return r.ok ? ok({ kind: "Box", spec: r.value }) : r;
6195
- }
6196
- case "Card": {
6197
- const r = decodeLegacyCard(path, j);
6198
- return r.ok ? ok({ kind: "Box", spec: r.value }) : r;
6199
- }
6200
6107
  case "SplitPanel": {
6201
6108
  const r = decodeSplitPanelSpec(path, j);
6202
6109
  return r.ok ? ok({ kind: "SplitPanel", spec: r.value }) : r;
@@ -6229,7 +6136,7 @@ var decodeLayoutKind = (path, j) => {
6229
6136
  return unknownDuCase(
6230
6137
  path,
6231
6138
  d.value,
6232
- "Box | Dashboard | Stack | GridLayout | SplitPanel | Tabs | Card | Stepper | SummaryList | Disclosure | Modal | ScrollArea"
6139
+ "Box | SplitPanel | Tabs | Stepper | SummaryList | Disclosure | Modal | ScrollArea"
6233
6140
  );
6234
6141
  }
6235
6142
  };
@@ -6405,12 +6312,8 @@ var decodeNodeKind = (path, j) => {
6405
6312
  // each primitive to its inner decoder and recover the category here. These
6406
6313
  // name-sets MUST stay in sync with the four inner decoders + the encoder.
6407
6314
  case "Box":
6408
- case "Dashboard":
6409
- case "Stack":
6410
- case "GridLayout":
6411
6315
  case "SplitPanel":
6412
6316
  case "Tabs":
6413
- case "Card":
6414
6317
  case "Stepper":
6415
6318
  case "SummaryList":
6416
6319
  case "Disclosure":
@@ -6449,7 +6352,6 @@ var decodeNodeKind = (path, j) => {
6449
6352
  }
6450
6353
  case "DataGrid":
6451
6354
  case "Chart":
6452
- case "Table":
6453
6355
  case "Map": {
6454
6356
  const k = decodeVisKind(path, j);
6455
6357
  return k.ok ? ok({ kind: "Visualisation", visualisation: k.value }) : k;
@@ -6652,7 +6554,7 @@ var decodeNodeKind = (path, j) => {
6652
6554
  "WRONG_NODE_KIND",
6653
6555
  `${path}.$type`,
6654
6556
  `unknown NodeKind discriminator '${d.value}'`,
6655
- "a Layout primitive (Dashboard | Stack | GridLayout | SplitPanel | Tabs | Card | Stepper | SummaryList | Disclosure | Modal | ScrollArea), a Display primitive (Heading | Markdown | Metric | Badge | Sparkline | Callout | Progress | Skeleton | LabelValueRow | Link | Image | List | Toast), an Input primitive (Form | Filters | Button | FileUpload | Select), a Visualisation primitive (DataGrid | Chart | Table | Map), or Custom | ErrorBoundary | FragmentDecl | FragmentRef | Mount"
6557
+ "a Layout primitive (Box | SplitPanel | Tabs | Stepper | SummaryList | Disclosure | Modal | ScrollArea), a Display primitive (Heading | Markdown | Metric | Badge | Sparkline | Callout | Progress | Skeleton | LabelValueRow | Link | Image | List | Toast), an Input primitive (Form | Filters | Button | FileUpload | Select), a Visualisation primitive (DataGrid | Chart | Map), or Custom | ErrorBoundary | FragmentDecl | FragmentRef | Mount"
6656
6558
  );
6657
6559
  }
6658
6560
  };
@@ -6823,13 +6725,10 @@ var decodeTreeOpAst = (path, j) => {
6823
6725
  case "InsertChild": {
6824
6726
  const parentJ = reqField(path, f, "parentId", "parent NodeId", requireString);
6825
6727
  if (!parentJ.ok) return parentJ;
6826
- const position = reqField(path, f, "position", "position integer", requireInt);
6827
- if (!position.ok) return position;
6828
6728
  const child = reqField(path, f, "child", "child Node object", decodeNodeAst);
6829
6729
  return child.ok ? ok({
6830
6730
  kind: "InsertChild",
6831
6731
  parentId: parentJ.value,
6832
- position: position.value,
6833
6732
  child: child.value
6834
6733
  }) : child;
6835
6734
  }
@@ -6841,14 +6740,11 @@ var decodeTreeOpAst = (path, j) => {
6841
6740
  const t = target();
6842
6741
  if (!t.ok) return t;
6843
6742
  const newParent = reqField(path, f, "newParentId", "new parent NodeId", requireString);
6844
- if (!newParent.ok) return newParent;
6845
- const newPosition = reqField(path, f, "newPosition", "new position integer", requireInt);
6846
- return newPosition.ok ? ok({
6743
+ return newParent.ok ? ok({
6847
6744
  kind: "MoveNode",
6848
6745
  target: t.value,
6849
- newParentId: newParent.value,
6850
- newPosition: newPosition.value
6851
- }) : newPosition;
6746
+ newParentId: newParent.value
6747
+ }) : newParent;
6852
6748
  }
6853
6749
  case "ReorderChildren": {
6854
6750
  const parentJ = reqField(path, f, "parentId", "parent NodeId", requireString);
@@ -7856,11 +7752,6 @@ var applyOne = (op, root, telem) => {
7856
7752
  "ChildlessKind",
7857
7753
  `Node '${op.parentId}' (kind=${parent.kind.kind}) has no children field \u2014 only Layout kinds accept structural child ops.`
7858
7754
  );
7859
- if (op.position < 0 || op.position > children.length)
7860
- return fail2(
7861
- "PositionOutOfRange",
7862
- `Position ${op.position} is out of range for parent '${op.parentId}' (valid: 0..${children.length}).`
7863
- );
7864
7755
  const existing = new Set(allNodeIds(root));
7865
7756
  const duplicate = allNodeIds(op.child).find((id) => existing.has(id));
7866
7757
  if (duplicate !== void 0)
@@ -7868,11 +7759,7 @@ var applyOne = (op, root, telem) => {
7868
7759
  "DuplicateNodeId",
7869
7760
  `NodeId '${duplicate}' is already present in the tree; ids must be unique.`
7870
7761
  );
7871
- const newChildren = [
7872
- ...children.slice(0, op.position),
7873
- op.child,
7874
- ...children.slice(op.position)
7875
- ];
7762
+ const newChildren = [...children, op.child];
7876
7763
  const newTree = mapNode(op.parentId, (n) => withLayoutChildren(n, newChildren), root);
7877
7764
  if (newTree === void 0)
7878
7765
  return fail2("ParentNotFound", `Parent node '${op.parentId}' not found in tree.`);
@@ -7920,7 +7807,7 @@ var applyOne = (op, root, telem) => {
7920
7807
  const afterRemove = applyOne({ kind: "RemoveNode", target: op.target }, root, []);
7921
7808
  if (!afterRemove.ok) return afterRemove;
7922
7809
  const inserted = applyOne(
7923
- { kind: "InsertChild", parentId: op.newParentId, position: op.newPosition, child: moving },
7810
+ { kind: "InsertChild", parentId: op.newParentId, child: moving },
7924
7811
  afterRemove.value,
7925
7812
  []
7926
7813
  );