@fuaran-ui/ops 0.2.0 → 0.3.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.cjs CHANGED
@@ -937,6 +937,25 @@ var formFieldKind = (autoBind, k) => {
937
937
  if (k.constraints.step !== void 0) fields.push(["step", num(k.constraints.step)]);
938
938
  return caseObj("Date", fields);
939
939
  }
940
+ case "DateRange": {
941
+ const staticPair = (p) => jObject([
942
+ ["from", str(p[0])],
943
+ ["to", str(p[1])]
944
+ ]);
945
+ const fields = [
946
+ ...handlerField("onChange", k.onChange),
947
+ ...valueField(
948
+ k.value,
949
+ schema.controlValueDefaults.dateRange,
950
+ (v) => v.kind === "Static" ? staticPair(v.value) : binding(v, staticPair)
951
+ ),
952
+ ["variant", str(k.variant)]
953
+ ];
954
+ if (k.constraints.min !== void 0) fields.push(["min", str(k.constraints.min)]);
955
+ if (k.constraints.max !== void 0) fields.push(["max", str(k.constraints.max)]);
956
+ if (k.constraints.step !== void 0) fields.push(["step", num(k.constraints.step)]);
957
+ return caseObj("DateRange", fields);
958
+ }
940
959
  default:
941
960
  return assertNever(k);
942
961
  }
@@ -4339,6 +4358,41 @@ var decodeBindingFloatPair = (p, j) => {
4339
4358
  }
4340
4359
  return decodeBinding(p, j, parseStaticFloatPair, [0, 0]);
4341
4360
  };
4361
+ var parseStaticStringPair = (p, v) => {
4362
+ const ordered = (a, b) => a > b ? makeError(
4363
+ "WRONG_TYPE",
4364
+ p,
4365
+ `date-range start '${a}' is after end '${b}' \u2014 a DateRange pair is ordered (from <= to); ISO-8601 strings of one variant compare lexicographically, so swap the two values`,
4366
+ 'ordered ISO-8601 pair ({"from": <iso>, "to": <iso>} with from <= to)'
4367
+ ) : ok([a, b]);
4368
+ if (v.kind === "JObject") {
4369
+ const from = v.fields.get("from");
4370
+ const to = v.fields.get("to");
4371
+ if (from !== void 0 && to !== void 0) {
4372
+ const a = requireString(`${p}.from`, from);
4373
+ if (!a.ok) return a;
4374
+ const b = requireString(`${p}.to`, to);
4375
+ if (!b.ok) return b;
4376
+ return ordered(a.value, b.value);
4377
+ }
4378
+ return wrongType(p, "object with from and to ISO-8601 strings");
4379
+ }
4380
+ if (v.kind === "JArray" && v.items.length === 2) {
4381
+ const a = requireString(`${p}[0]`, v.items[0]);
4382
+ if (!a.ok) return a;
4383
+ const b = requireString(`${p}[1]`, v.items[1]);
4384
+ if (!b.ok) return b;
4385
+ return ordered(a.value, b.value);
4386
+ }
4387
+ return wrongType(p, "date-range pair ({from, to} object or [from, to] array)");
4388
+ };
4389
+ var decodeBindingStringPair = (p, j) => {
4390
+ if (j.kind === "JObject" && j.fields.get("$type") === void 0 && j.fields.get("from") !== void 0 && j.fields.get("to") !== void 0) {
4391
+ const parsed = parseStaticStringPair(p, j);
4392
+ return parsed.ok ? ok({ kind: "Static", value: parsed.value }) : parsed;
4393
+ }
4394
+ return decodeBinding(p, j, parseStaticStringPair, ["", ""]);
4395
+ };
4342
4396
  var parseStaticStringList = (p, v) => {
4343
4397
  if (v.kind === "JNull") return ok([]);
4344
4398
  if (v.kind === "JString" && v.value === OPAQUE2) return ok([OPAQUE2]);
@@ -5186,6 +5240,7 @@ var decodeDisplayKind = (path, j) => {
5186
5240
  );
5187
5241
  }
5188
5242
  };
5243
+ var WRONG_FORM_FIELD_KIND_HINT = schema.FORM_FIELD_KIND_NAMES.join(" | ");
5189
5244
  var decodeFormFieldKind = (autoBind, path, j) => {
5190
5245
  const fo = requireObject(path, j);
5191
5246
  if (!fo.ok) return fo;
@@ -5335,12 +5390,35 @@ var decodeFormFieldKind = (autoBind, path, j) => {
5335
5390
  }
5336
5391
  });
5337
5392
  }
5338
- default:
5339
- return unknownDuCase(
5340
- path,
5341
- d.value,
5342
- "Text | Number | Checkbox | Choice | Range | RangedNumber | SegmentedChoice | TextArea | Date"
5393
+ case "DateRange": {
5394
+ const value = valueOr(
5395
+ decodeBindingStringPair,
5396
+ schema.controlValueDefaults.dateRange,
5397
+ "Binding<[from, to]> ISO-8601 pair value"
5343
5398
  );
5399
+ if (!value.ok) return value;
5400
+ const variant = reqField(path, f, "variant", "DateVariant", decodeDateVariant);
5401
+ if (!variant.ok) return variant;
5402
+ const min = optField(path, f, "min", requireString);
5403
+ if (!min.ok) return min;
5404
+ const max = optField(path, f, "max", requireString);
5405
+ if (!max.ok) return max;
5406
+ const step = optField(path, f, "step", requireFloat);
5407
+ if (!step.ok) return step;
5408
+ return ok({
5409
+ kind: "DateRange",
5410
+ value: value.value,
5411
+ ...onChangeField,
5412
+ variant: variant.value,
5413
+ constraints: {
5414
+ ...min.value !== void 0 ? { min: min.value } : {},
5415
+ ...max.value !== void 0 ? { max: max.value } : {},
5416
+ ...step.value !== void 0 ? { step: step.value } : {}
5417
+ }
5418
+ });
5419
+ }
5420
+ default:
5421
+ return unknownDuCase(path, d.value, WRONG_FORM_FIELD_KIND_HINT);
5344
5422
  }
5345
5423
  };
5346
5424
  var decodeFormField = (path, j) => {
@@ -6302,6 +6380,13 @@ var decodeEffectClass = (path, j) => {
6302
6380
  );
6303
6381
  return ok({ hostEffect: host.value, determinism: det.value });
6304
6382
  };
6383
+ var WRONG_NODE_KIND_HINT = (() => {
6384
+ const primitives = schema.NODE_KIND_GROUPS.filter((g) => g.label !== "Structural").map(
6385
+ (g) => `${"AEIOU".includes(g.label[0]) ? "an" : "a"} ${g.label} primitive (${g.kinds.join(" | ")})`
6386
+ ).join(", ");
6387
+ const structural = schema.NODE_KIND_GROUPS.find((g) => g.label === "Structural")?.kinds ?? [];
6388
+ return `${primitives}, or ${structural.join(" | ")}`;
6389
+ })();
6305
6390
  var decodeNodeKind = (path, j) => {
6306
6391
  const fo = requireObject(path, j);
6307
6392
  if (!fo.ok) return fo;
@@ -6556,7 +6641,7 @@ var decodeNodeKind = (path, j) => {
6556
6641
  "WRONG_NODE_KIND",
6557
6642
  `${path}.$type`,
6558
6643
  `unknown NodeKind discriminator '${d.value}'`,
6559
- "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"
6644
+ WRONG_NODE_KIND_HINT
6560
6645
  );
6561
6646
  }
6562
6647
  };