@backmatter/core 0.0.38 → 0.0.39

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backmatter/core",
3
- "version": "0.0.38",
3
+ "version": "0.0.39",
4
4
  "description": "Experimental Backmatter SDK. APIs will break. Not ready for production.",
5
5
  "type": "module",
6
6
  "publishConfig": {
package/src/fields.ts CHANGED
@@ -49,10 +49,24 @@ export type FieldDef<
49
49
  step?: number;
50
50
  where?: RelationWhere;
51
51
  multiple?: true;
52
+ /** For blocks fields: how Studio's "Add block" picker lays out the blocks. */
53
+ picker?: BlockPickerView;
52
54
  /** Guidance for editors and the AI: what goes here, length, tone. Never rendered. */
53
55
  description?: string;
54
56
  };
55
57
 
58
+ /**
59
+ * Layout of Studio's "Add block" picker. "grouped" opens on the block groups,
60
+ * "flat" shows every block at once, "auto" groups only when there are many.
61
+ */
62
+ export type BlockPickerView = "auto" | "grouped" | "flat";
63
+
64
+ const PICKER_VIEWS: readonly BlockPickerView[] = ["auto", "grouped", "flat"];
65
+
66
+ function isPickerView(value: unknown): value is BlockPickerView {
67
+ return PICKER_VIEWS.includes(value as BlockPickerView);
68
+ }
69
+
56
70
  export type FieldSnapshot = {
57
71
  kind: FieldKind;
58
72
  required?: boolean;
@@ -68,6 +82,7 @@ export type FieldSnapshot = {
68
82
  step?: number;
69
83
  where?: RelationWhere;
70
84
  multiple?: true;
85
+ picker?: BlockPickerView;
71
86
  description?: string;
72
87
  };
73
88
 
@@ -491,7 +506,13 @@ const constructors = {
491
506
  boolean: <const R extends boolean = false>(opts?: Opts<R>) => base("boolean", opts),
492
507
  relation,
493
508
  link,
494
- blocks: <const R extends boolean = false>(opts?: Opts<R>) => base("blocks", opts),
509
+ blocks: <const R extends boolean = false>(opts?: Opts<R> & { picker?: BlockPickerView }) => {
510
+ if (opts?.picker !== undefined && !isPickerView(opts.picker)) {
511
+ throw new Error('field.blocks picker must be "auto", "grouped" or "flat"');
512
+ }
513
+ const def = base("blocks", { required: opts?.required, input: opts?.input });
514
+ return opts?.picker ? { ...def, picker: opts.picker } : def;
515
+ },
495
516
  object: objectField,
496
517
  array: arrayField,
497
518
  };
@@ -524,6 +545,7 @@ export function serializeField(def: FieldDef): FieldSnapshot {
524
545
  ...(def.models ? { models: [...def.models] } : {}),
525
546
  ...(def.where ? { where: def.where } : {}),
526
547
  ...(def.multiple ? { multiple: true as const } : {}),
548
+ ...(def.picker ? { picker: def.picker } : {}),
527
549
  ...(def.description?.trim() ? { description: def.description.trim() } : {}),
528
550
  };
529
551
  if (def.fields) {
@@ -607,6 +629,7 @@ export function parseFieldSnapshot(input: unknown): FieldSnapshot {
607
629
  if (where) {
608
630
  snap.where = where;
609
631
  }
632
+ if (isPickerView(value.picker)) snap.picker = value.picker;
610
633
  if (typeof value.description === "string" && value.description.trim()) {
611
634
  snap.description = value.description.trim();
612
635
  }
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ export type {
6
6
  FieldDef,
7
7
  FieldKind,
8
8
  FieldSnapshot,
9
+ BlockPickerView,
9
10
  } from "./fields";
10
11
  export { field, serializeField, parseFieldSnapshot } from "./fields";
11
12
  export {