@valbuild/shared 0.142.0 → 0.144.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.
@@ -40,7 +40,7 @@ export type ResolveResult = {
40
40
  * Walks `schema` along `path`, returning a structured result:
41
41
  * - `leaf`: walked the full path; resolved schema at the end.
42
42
  * - `richtext`: hit a richtext mid-walk; richtext is the resolved schema.
43
- * - `gallery-traversed`: hit an `s.imageset()` record and walked past it (i.e. the
43
+ * - `gallery-traversed`: hit an `s.imagedir()` record and walked past it (i.e. the
44
44
  * path tries to address an entry inside the gallery — a clue the AI should
45
45
  * have used the gallery tool instead).
46
46
  * - `unresolved`: the path could not be walked.
@@ -1,4 +1,5 @@
1
1
  export * from "./richtext/conversion/index.js";
2
+ export * from "./richtext/richTextImages.js";
2
3
  export * from "./server/types.js";
3
4
  export * from "./server/requestScopedMemo.js";
4
5
  export * from "./ValClient.js";
@@ -0,0 +1,21 @@
1
+ import type { SerializedImageSchema, SerializedRichTextSchema, SourcePath } from "@valbuild/core";
2
+ /**
3
+ * The image schema a rich text field's inline `img` nodes are validated with,
4
+ * when it is a real schema rather than `img: true`.
5
+ *
6
+ * It is the only way a rich text field can point INTO a gallery
7
+ * (`s.richtext({ img: s.image(galleryVal) })`), which is why every reference
8
+ * scan has to ask: the field's own schema is `richtext`, not `image`, so a walk
9
+ * that only looks for image leaves walks straight past the images in it.
10
+ */
11
+ export declare function richTextImageSchema(schema: SerializedRichTextSchema): SerializedImageSchema | null;
12
+ /**
13
+ * Every inline image in a rich text value, at the path of its `src`.
14
+ *
15
+ * `src` is a media value (`{ path, … }`), so the path handed out is one a
16
+ * patch can address — `field.0."children".1."src"` — and a rename rewrites
17
+ * `[…, "src", "path"]` there with the same op it uses on an image field.
18
+ * Images nest (a list item holds a paragraph holds the image), so the walk
19
+ * follows `children` all the way down.
20
+ */
21
+ export declare function forEachRichTextImage(path: SourcePath, source: unknown, visit: (srcPath: SourcePath, src: Record<string, unknown>) => void): void;
@@ -1,7 +1,7 @@
1
1
  import { Json } from "@valbuild/core";
2
- export declare const VAL_SESSION_COOKIE: any;
3
- export declare const VAL_STATE_COOKIE: any;
4
- export declare const VAL_ENABLE_COOKIE_NAME: any;
2
+ export declare const VAL_SESSION_COOKIE: "val_session";
3
+ export declare const VAL_STATE_COOKIE: "val_state";
4
+ export declare const VAL_ENABLE_COOKIE_NAME: "val_enable";
5
5
  export type VAL_SESSION_COOKIE = typeof VAL_SESSION_COOKIE;
6
6
  export type VAL_STATE_COOKIE = typeof VAL_STATE_COOKIE;
7
7
  export type VAL_ENABLE_COOKIE_NAME = typeof VAL_ENABLE_COOKIE_NAME;
@@ -64,9 +64,9 @@ export declare const BinaryFileRef: z.ZodObject<{
64
64
  }, z.core.$strip>;
65
65
  export type BinaryFileRef = z.infer<typeof BinaryFileRef>;
66
66
  export declare const HistoricalModule: z.ZodObject<{
67
- source: z.ZodNullable<z.ZodType<JSONValueT, unknown, z.core.$ZodTypeInternals<JSONValueT, unknown>>>;
68
- schema: z.ZodNullable<z.ZodType<SerializedSchemaT, unknown, z.core.$ZodTypeInternals<SerializedSchemaT, unknown>>>;
69
- patchIds: z.ZodArray<z.ZodString & z.ZodType<PatchIdT, string, z.core.$ZodTypeInternals<PatchIdT, string>>>;
67
+ source: z.ZodNullable<z.ZodType<import("@valbuild/core/patch").JSONValue, unknown, z.core.$ZodTypeInternals<import("@valbuild/core/patch").JSONValue, unknown>>>;
68
+ schema: z.ZodNullable<z.ZodType<import("@valbuild/core").SerializedSchema, unknown, z.core.$ZodTypeInternals<import("@valbuild/core").SerializedSchema, unknown>>>;
69
+ patchIds: z.ZodArray<z.ZodString & z.ZodType<import("@valbuild/core").PatchId, string, z.core.$ZodTypeInternals<import("@valbuild/core").PatchId, string>>>;
70
70
  changedPaths: z.ZodArray<z.ZodString>;
71
71
  failures: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
72
72
  kind: z.ZodLiteral<"commit-not-found">;
@@ -109,9 +109,9 @@ export declare const HistoricalPatchSet: z.ZodObject<{
109
109
  hasArchive: z.ZodBoolean;
110
110
  }, z.core.$strip>;
111
111
  modules: z.ZodRecord<z.ZodString, z.ZodObject<{
112
- source: z.ZodNullable<z.ZodType<JSONValueT, unknown, z.core.$ZodTypeInternals<JSONValueT, unknown>>>;
113
- schema: z.ZodNullable<z.ZodType<SerializedSchemaT, unknown, z.core.$ZodTypeInternals<SerializedSchemaT, unknown>>>;
114
- patchIds: z.ZodArray<z.ZodString & z.ZodType<PatchIdT, string, z.core.$ZodTypeInternals<PatchIdT, string>>>;
112
+ source: z.ZodNullable<z.ZodType<import("@valbuild/core/patch").JSONValue, unknown, z.core.$ZodTypeInternals<import("@valbuild/core/patch").JSONValue, unknown>>>;
113
+ schema: z.ZodNullable<z.ZodType<import("@valbuild/core").SerializedSchema, unknown, z.core.$ZodTypeInternals<import("@valbuild/core").SerializedSchema, unknown>>>;
114
+ patchIds: z.ZodArray<z.ZodString & z.ZodType<import("@valbuild/core").PatchId, string, z.core.$ZodTypeInternals<import("@valbuild/core").PatchId, string>>>;
115
115
  changedPaths: z.ZodArray<z.ZodString>;
116
116
  failures: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
117
117
  kind: z.ZodLiteral<"commit-not-found">;
@@ -139,7 +139,7 @@ export declare const HistoricalPatchSet: z.ZodObject<{
139
139
  }, z.core.$strip>], "kind">>;
140
140
  }, z.core.$strip>>;
141
141
  patches: z.ZodArray<z.ZodObject<{
142
- patchId: z.ZodString & z.ZodType<PatchIdT, string, z.core.$ZodTypeInternals<PatchIdT, string>>;
142
+ patchId: z.ZodString & z.ZodType<import("@valbuild/core").PatchId, string, z.core.$ZodTypeInternals<import("@valbuild/core").PatchId, string>>;
143
143
  moduleFilePath: z.ZodString;
144
144
  patch: z.ZodUnknown;
145
145
  authorId: z.ZodNullable<z.ZodString>;
@@ -1,4 +1,5 @@
1
1
  import type { JSONValue as JSONValueT, PatchJSON as PatchJSONT, PatchBlock as PatchBlockT, ParentRef as ParentRefT } from "@valbuild/core/patch";
2
+ import type { PatchId as PatchIdT } from "@valbuild/core";
2
3
  import { z } from "zod";
3
4
  /**
4
5
  * JSON, recursively — the shape of a Source over the wire.
@@ -66,7 +66,25 @@ export declare const ColorOptions: z.ZodObject<{
66
66
  export declare const SerializedColorSchema: z.ZodType<SerializedColorSchemaT>;
67
67
  export declare const CodeOptions: z.ZodObject<{
68
68
  language: z.ZodOptional<z.ZodEnum<{
69
- [x: string]: any;
69
+ json: "json";
70
+ typescript: "typescript";
71
+ javascript: "javascript";
72
+ javascriptreact: "javascriptreact";
73
+ typescriptreact: "typescriptreact";
74
+ java: "java";
75
+ html: "html";
76
+ css: "css";
77
+ xml: "xml";
78
+ markdown: "markdown";
79
+ sql: "sql";
80
+ python: "python";
81
+ rust: "rust";
82
+ php: "php";
83
+ go: "go";
84
+ cpp: "cpp";
85
+ sass: "sass";
86
+ vue: "vue";
87
+ angular: "angular";
70
88
  }>>;
71
89
  }, z.core.$strip>;
72
90
  export declare const SerializedCodeSchema: z.ZodType<SerializedCodeSchemaT>;
@@ -83,7 +101,7 @@ export declare const SerializedSettingsSchema: z.ZodType<SerializedSettingsSchem
83
101
  */
84
102
  export declare const SerializedValViewSchema: z.ZodObject<{
85
103
  type: z.ZodLiteral<"view">;
86
- moduleFilePath: z.ZodType<ModuleFilePathT, unknown, z.core.$ZodTypeInternals<ModuleFilePathT, unknown>>;
104
+ moduleFilePath: z.ZodType<import("@valbuild/core").ModuleFilePath, unknown, z.core.$ZodTypeInternals<import("@valbuild/core").ModuleFilePath, unknown>>;
87
105
  opt: z.ZodLiteral<false>;
88
106
  readonly: z.ZodOptional<z.ZodBoolean>;
89
107
  hidden: z.ZodOptional<z.ZodBoolean>;
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var core = require('@valbuild/core');
6
5
  var getSitemapTree = require('../../dist/getSitemapTree-c732e09a.cjs.dev.js');
6
+ var core = require('@valbuild/core');
7
7
  var zod = require('zod');
8
8
  var zodValidationError = require('zod-validation-error');
9
9
  var FlexSearch = require('flexsearch');
@@ -657,6 +657,105 @@ function convertListItemToRemirrorParagraph(rtChildren) {
657
657
  return children;
658
658
  }
659
659
 
660
+ /**
661
+ * The one way to build a child's source path.
662
+ *
663
+ * There were five hand-rolled versions of this, three of them subtly different
664
+ * and two of them wrong, and the wrong ones were wrong in a way that hid: a
665
+ * module path segment has to be JSON-quoted if it is a string and bare if it is
666
+ * an array index, and both broken copies appended the raw key at the module
667
+ * root. An unquoted key parses fine as long as it contains no `.` — so every
668
+ * object field and every ordinary record key still resolved, and only a key with
669
+ * a dot in it broke. That is exactly what a media gallery is keyed by, so
670
+ * clicking a file in the Media panel navigated to
671
+ * `?p=/public/val/red-8x8_bfbd0.png`, which `splitModulePath` reads as the two
672
+ * segments `/public/val/red-8x8_bfbd0` and `png`, and the studio said the module
673
+ * was not found.
674
+ *
675
+ * So: one function, and never a template string. `Internal.createValPathOfItem`
676
+ * is the rule itself — `JSON.stringify` quotes a string and leaves a number
677
+ * bare, which is precisely the module-path grammar — and everything here defers
678
+ * to it rather than restating it.
679
+ */
680
+ function sourcePathOfChild(parent, key) {
681
+ /**
682
+ * A parent that is already `…?p=` gets the key with no separator.
683
+ *
684
+ * The search index walks from `moduleFilePath + "?p="` rather than from the
685
+ * module file path, so that every path it produces has a module path — and
686
+ * `createValPathOfItem` would see the separator and join with a `.`, giving
687
+ * `?p=."title"`.
688
+ */
689
+ if (parent.endsWith(core.Internal.ModuleFilePathSep)) {
690
+ return "".concat(parent).concat(JSON.stringify(key));
691
+ }
692
+ var path = core.Internal.createValPathOfItem(parent, key);
693
+ if (path === undefined) {
694
+ // Only when the parent is empty, which callers cannot produce: every walk
695
+ // starts from a module file path. Thrown rather than skipped so a future
696
+ // change that breaks that assumption is loud.
697
+ throw new Error("Could not build a source path for '".concat(key, "' under ").concat(parent));
698
+ }
699
+ return path;
700
+ }
701
+
702
+ /**
703
+ * The same thing, for callers holding the module file path and module path apart.
704
+ *
705
+ * `ModulePath` is empty at the module root, which is the case both broken copies
706
+ * got wrong: there is no separator in the path yet, so the key is the first
707
+ * segment and still has to be quoted.
708
+ */
709
+ function concatModulePath(moduleFilePath, modulePath, key) {
710
+ return sourcePathOfChild(modulePath ? core.Internal.joinModuleFilePathAndModulePath(moduleFilePath, modulePath) : moduleFilePath, key);
711
+ }
712
+
713
+ /**
714
+ * The image schema a rich text field's inline `img` nodes are validated with,
715
+ * when it is a real schema rather than `img: true`.
716
+ *
717
+ * It is the only way a rich text field can point INTO a gallery
718
+ * (`s.richtext({ img: s.image(galleryVal) })`), which is why every reference
719
+ * scan has to ask: the field's own schema is `richtext`, not `image`, so a walk
720
+ * that only looks for image leaves walks straight past the images in it.
721
+ */
722
+ function richTextImageSchema(schema) {
723
+ var _schema$options;
724
+ var img = (_schema$options = schema.options) === null || _schema$options === void 0 ? void 0 : _schema$options.img;
725
+ return getSitemapTree._typeof(img) === "object" && img !== null ? img : null;
726
+ }
727
+
728
+ /**
729
+ * Every inline image in a rich text value, at the path of its `src`.
730
+ *
731
+ * `src` is a media value (`{ path, … }`), so the path handed out is one a
732
+ * patch can address — `field.0."children".1."src"` — and a rename rewrites
733
+ * `[…, "src", "path"]` there with the same op it uses on an image field.
734
+ * Images nest (a list item holds a paragraph holds the image), so the walk
735
+ * follows `children` all the way down.
736
+ */
737
+ function forEachRichTextImage(path, source, visit) {
738
+ if (!Array.isArray(source)) {
739
+ return;
740
+ }
741
+ for (var index = 0; index < source.length; index++) {
742
+ var node = source[index];
743
+ if (getSitemapTree._typeof(node) !== "object" || node === null || Array.isArray(node)) {
744
+ continue;
745
+ }
746
+ var nodePath = sourcePathOfChild(path, index);
747
+ if ("tag" in node && node.tag === "img" && "src" in node) {
748
+ var src = node.src;
749
+ if (getSitemapTree._typeof(src) === "object" && src !== null && !Array.isArray(src)) {
750
+ visit(sourcePathOfChild(nodePath, "src"), getSitemapTree._objectSpread2({}, src));
751
+ }
752
+ }
753
+ if ("children" in node) {
754
+ forEachRichTextImage(sourcePathOfChild(nodePath, "children"), node.children, visit);
755
+ }
756
+ }
757
+ }
758
+
660
759
  var VAL_SESSION_COOKIE = core.Internal.VAL_SESSION_COOKIE;
661
760
  var VAL_STATE_COOKIE = core.Internal.VAL_STATE_COOKIE;
662
761
  var VAL_ENABLE_COOKIE_NAME = core.Internal.VAL_ENABLE_COOKIE_NAME;
@@ -1172,7 +1271,7 @@ var SerializedRecordSchema = zod.z.lazy(function () {
1172
1271
  dir: zod.z.string().optional(),
1173
1272
  remote: zod.z["boolean"]().optional(),
1174
1273
  encode: ImageEncodeOption.optional(),
1175
- // A videoset's: see `VideoStreamOption` below for why it is spelled
1274
+ // A videodir's: see `VideoStreamOption` below for why it is spelled
1176
1275
  // out rather than passed through.
1177
1276
  stream: VideoStreamOption.optional(),
1178
1277
  alt: SerializedSchema.optional(),
@@ -1228,7 +1327,7 @@ var SerializedVideoSchema = zod.z.object(getSitemapTree._objectSpread2(getSitema
1228
1327
  options: VideoOptions.optional(),
1229
1328
  opt: zod.z["boolean"](),
1230
1329
  remote: zod.z["boolean"]().optional(),
1231
- // The `s.videoset()` a set-backed field picks from.
1330
+ // The `s.videodir()` a set-backed field picks from.
1232
1331
  referencedModule: zod.z.string().optional()
1233
1332
  }));
1234
1333
  var DateOptions = zod.z.object({
@@ -5567,7 +5666,7 @@ function getSourceAt(source, path) {
5567
5666
  * Walks `schema` along `path`, returning a structured result:
5568
5667
  * - `leaf`: walked the full path; resolved schema at the end.
5569
5668
  * - `richtext`: hit a richtext mid-walk; richtext is the resolved schema.
5570
- * - `gallery-traversed`: hit an `s.imageset()` record and walked past it (i.e. the
5669
+ * - `gallery-traversed`: hit an `s.imagedir()` record and walked past it (i.e. the
5571
5670
  * path tries to address an entry inside the gallery — a clue the AI should
5572
5671
  * have used the gallery tool instead).
5573
5672
  * - `unresolved`: the path could not be walked.
@@ -5675,7 +5774,7 @@ function checkGallerySchema(moduleSchema) {
5675
5774
  // looks like a gallery from here, and the tool can do nothing with one.
5676
5775
  return {
5677
5776
  kind: "error",
5678
- message: "Module is a video set (s.videoset()), not an images gallery. Videos cannot be added or removed by this tool: upload them in Val Studio."
5777
+ message: "Module is a video set (s.videodir()), not an images gallery. Videos cannot be added or removed by this tool: upload them in Val Studio."
5679
5778
  };
5680
5779
  }
5681
5780
  if (moduleSchema.type === "image") {
@@ -5706,7 +5805,7 @@ function buildImageGalleryPatch(args, moduleSchema) {
5706
5805
  op: "add",
5707
5806
  path: [args.filePath],
5708
5807
  value: getSitemapTree._objectSpread2(getSitemapTree._objectSpread2({}, args.metadata), {}, {
5709
- // `alt` is a REQUIRED field of a gallery entry (`s.imageset()` gives it a
5808
+ // `alt` is a REQUIRED field of a gallery entry (`s.imagedir()` gives it a
5710
5809
  // nullable string schema), so an entry written without one is invalid
5711
5810
  // the moment it lands — and the caller that had no alt to give is the
5712
5811
  // common case, not the odd one. Null is what the Studio's own upload
@@ -5769,7 +5868,7 @@ function buildRemoveImageGalleryEntryPatch(args, moduleSchema, moduleSource) {
5769
5868
  var GALLERY_REDIRECT = {
5770
5869
  kind: "wrong-tool",
5771
5870
  suggestedTool: "add_session_image_to_gallery",
5772
- reason: "Destination is a media gallery (s.imageset() / s.fileset()). Gallery entries are keyed by file path and carry a file on disk, so they cannot be created with a plain patch. Use add_session_image_to_gallery."
5871
+ reason: "Destination is a media gallery (s.imagedir() / s.filedir()). Gallery entries are keyed by file path and carry a file on disk, so they cannot be created with a plain patch. Use add_session_image_to_gallery."
5773
5872
  };
5774
5873
 
5775
5874
  /**
@@ -5779,10 +5878,10 @@ var GALLERY_REDIRECT = {
5779
5878
  */
5780
5879
  var VIDEOSET_REFUSAL = {
5781
5880
  kind: "error",
5782
- message: "Destination is a video set (s.videoset()). Its entries are keyed by file path and carry video files, so they cannot be created with a plain patch, and no tool here uploads a video: add it in Val Studio."
5881
+ message: "Destination is a video set (s.videodir()). Its entries are keyed by file path and carry video files, so they cannot be created with a plain patch, and no tool here uploads a video: add it in Val Studio."
5783
5882
  };
5784
5883
 
5785
- /** An `s.imageset()` / `s.fileset()` / `s.videoset()` record: a gallery, not an ordinary record. */
5884
+ /** An `s.imagedir()` / `s.filedir()` / `s.videodir()` record: a gallery, not an ordinary record. */
5786
5885
  function isGallery(schema) {
5787
5886
  return schema.type === "record" && schema.mediaType !== undefined;
5788
5887
  }
@@ -6374,59 +6473,6 @@ function withExtension(filename, ext) {
6374
6473
  return "".concat(base, ".").concat(ext);
6375
6474
  }
6376
6475
 
6377
- /**
6378
- * The one way to build a child's source path.
6379
- *
6380
- * There were five hand-rolled versions of this, three of them subtly different
6381
- * and two of them wrong, and the wrong ones were wrong in a way that hid: a
6382
- * module path segment has to be JSON-quoted if it is a string and bare if it is
6383
- * an array index, and both broken copies appended the raw key at the module
6384
- * root. An unquoted key parses fine as long as it contains no `.` — so every
6385
- * object field and every ordinary record key still resolved, and only a key with
6386
- * a dot in it broke. That is exactly what a media gallery is keyed by, so
6387
- * clicking a file in the Media panel navigated to
6388
- * `?p=/public/val/red-8x8_bfbd0.png`, which `splitModulePath` reads as the two
6389
- * segments `/public/val/red-8x8_bfbd0` and `png`, and the studio said the module
6390
- * was not found.
6391
- *
6392
- * So: one function, and never a template string. `Internal.createValPathOfItem`
6393
- * is the rule itself — `JSON.stringify` quotes a string and leaves a number
6394
- * bare, which is precisely the module-path grammar — and everything here defers
6395
- * to it rather than restating it.
6396
- */
6397
- function sourcePathOfChild(parent, key) {
6398
- /**
6399
- * A parent that is already `…?p=` gets the key with no separator.
6400
- *
6401
- * The search index walks from `moduleFilePath + "?p="` rather than from the
6402
- * module file path, so that every path it produces has a module path — and
6403
- * `createValPathOfItem` would see the separator and join with a `.`, giving
6404
- * `?p=."title"`.
6405
- */
6406
- if (parent.endsWith(core.Internal.ModuleFilePathSep)) {
6407
- return "".concat(parent).concat(JSON.stringify(key));
6408
- }
6409
- var path = core.Internal.createValPathOfItem(parent, key);
6410
- if (path === undefined) {
6411
- // Only when the parent is empty, which callers cannot produce: every walk
6412
- // starts from a module file path. Thrown rather than skipped so a future
6413
- // change that breaks that assumption is loud.
6414
- throw new Error("Could not build a source path for '".concat(key, "' under ").concat(parent));
6415
- }
6416
- return path;
6417
- }
6418
-
6419
- /**
6420
- * The same thing, for callers holding the module file path and module path apart.
6421
- *
6422
- * `ModulePath` is empty at the module root, which is the case both broken copies
6423
- * got wrong: there is no separator in the path yet, so the key is the first
6424
- * segment and still has to be quoted.
6425
- */
6426
- function concatModulePath(moduleFilePath, modulePath, key) {
6427
- return sourcePathOfChild(modulePath ? core.Internal.joinModuleFilePathAndModulePath(moduleFilePath, modulePath) : moduleFilePath, key);
6428
- }
6429
-
6430
6476
  /**
6431
6477
  * Traverses a schema and source pair, calling a callback for each leaf node.
6432
6478
  * Handles all schema types including primitives, objects, arrays, records, unions, richtext, files, images, etc.
@@ -8056,6 +8102,7 @@ exports.filterRoutesByPatterns = filterRoutesByPatterns;
8056
8102
  exports.findSimilar = findSimilar;
8057
8103
  exports.fitWithin = fitWithin;
8058
8104
  exports.flattenRichText = flattenRichText;
8105
+ exports.forEachRichTextImage = forEachRichTextImage;
8059
8106
  exports.getErrorMessageFromUnknownJson = getErrorMessageFromUnknownJson;
8060
8107
  exports.getFilenameFromRef = getFilenameFromRef;
8061
8108
  exports.getInlineImgInfo = getInlineImgInfo;
@@ -8101,6 +8148,7 @@ exports.resolvePairGround = resolvePairGround;
8101
8148
  exports.resolveSchemaSourceFixForError = resolveSchemaSourceFixForError;
8102
8149
  exports.resolveSchemaSourceFixes = resolveSchemaSourceFixes;
8103
8150
  exports.resolveSerializedSchemaAtPath = resolveSerializedSchemaAtPath;
8151
+ exports.richTextImageSchema = richTextImageSchema;
8104
8152
  exports.richTextToRemirror = richTextToRemirror;
8105
8153
  exports.safeParsePatch = safeParsePatch;
8106
8154
  exports.sourcePathOfChild = sourcePathOfChild;
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var core = require('@valbuild/core');
6
5
  var getSitemapTree = require('../../dist/getSitemapTree-0ed3deac.cjs.prod.js');
6
+ var core = require('@valbuild/core');
7
7
  var zod = require('zod');
8
8
  var zodValidationError = require('zod-validation-error');
9
9
  var FlexSearch = require('flexsearch');
@@ -657,6 +657,105 @@ function convertListItemToRemirrorParagraph(rtChildren) {
657
657
  return children;
658
658
  }
659
659
 
660
+ /**
661
+ * The one way to build a child's source path.
662
+ *
663
+ * There were five hand-rolled versions of this, three of them subtly different
664
+ * and two of them wrong, and the wrong ones were wrong in a way that hid: a
665
+ * module path segment has to be JSON-quoted if it is a string and bare if it is
666
+ * an array index, and both broken copies appended the raw key at the module
667
+ * root. An unquoted key parses fine as long as it contains no `.` — so every
668
+ * object field and every ordinary record key still resolved, and only a key with
669
+ * a dot in it broke. That is exactly what a media gallery is keyed by, so
670
+ * clicking a file in the Media panel navigated to
671
+ * `?p=/public/val/red-8x8_bfbd0.png`, which `splitModulePath` reads as the two
672
+ * segments `/public/val/red-8x8_bfbd0` and `png`, and the studio said the module
673
+ * was not found.
674
+ *
675
+ * So: one function, and never a template string. `Internal.createValPathOfItem`
676
+ * is the rule itself — `JSON.stringify` quotes a string and leaves a number
677
+ * bare, which is precisely the module-path grammar — and everything here defers
678
+ * to it rather than restating it.
679
+ */
680
+ function sourcePathOfChild(parent, key) {
681
+ /**
682
+ * A parent that is already `…?p=` gets the key with no separator.
683
+ *
684
+ * The search index walks from `moduleFilePath + "?p="` rather than from the
685
+ * module file path, so that every path it produces has a module path — and
686
+ * `createValPathOfItem` would see the separator and join with a `.`, giving
687
+ * `?p=."title"`.
688
+ */
689
+ if (parent.endsWith(core.Internal.ModuleFilePathSep)) {
690
+ return "".concat(parent).concat(JSON.stringify(key));
691
+ }
692
+ var path = core.Internal.createValPathOfItem(parent, key);
693
+ if (path === undefined) {
694
+ // Only when the parent is empty, which callers cannot produce: every walk
695
+ // starts from a module file path. Thrown rather than skipped so a future
696
+ // change that breaks that assumption is loud.
697
+ throw new Error("Could not build a source path for '".concat(key, "' under ").concat(parent));
698
+ }
699
+ return path;
700
+ }
701
+
702
+ /**
703
+ * The same thing, for callers holding the module file path and module path apart.
704
+ *
705
+ * `ModulePath` is empty at the module root, which is the case both broken copies
706
+ * got wrong: there is no separator in the path yet, so the key is the first
707
+ * segment and still has to be quoted.
708
+ */
709
+ function concatModulePath(moduleFilePath, modulePath, key) {
710
+ return sourcePathOfChild(modulePath ? core.Internal.joinModuleFilePathAndModulePath(moduleFilePath, modulePath) : moduleFilePath, key);
711
+ }
712
+
713
+ /**
714
+ * The image schema a rich text field's inline `img` nodes are validated with,
715
+ * when it is a real schema rather than `img: true`.
716
+ *
717
+ * It is the only way a rich text field can point INTO a gallery
718
+ * (`s.richtext({ img: s.image(galleryVal) })`), which is why every reference
719
+ * scan has to ask: the field's own schema is `richtext`, not `image`, so a walk
720
+ * that only looks for image leaves walks straight past the images in it.
721
+ */
722
+ function richTextImageSchema(schema) {
723
+ var _schema$options;
724
+ var img = (_schema$options = schema.options) === null || _schema$options === void 0 ? void 0 : _schema$options.img;
725
+ return getSitemapTree._typeof(img) === "object" && img !== null ? img : null;
726
+ }
727
+
728
+ /**
729
+ * Every inline image in a rich text value, at the path of its `src`.
730
+ *
731
+ * `src` is a media value (`{ path, … }`), so the path handed out is one a
732
+ * patch can address — `field.0."children".1."src"` — and a rename rewrites
733
+ * `[…, "src", "path"]` there with the same op it uses on an image field.
734
+ * Images nest (a list item holds a paragraph holds the image), so the walk
735
+ * follows `children` all the way down.
736
+ */
737
+ function forEachRichTextImage(path, source, visit) {
738
+ if (!Array.isArray(source)) {
739
+ return;
740
+ }
741
+ for (var index = 0; index < source.length; index++) {
742
+ var node = source[index];
743
+ if (getSitemapTree._typeof(node) !== "object" || node === null || Array.isArray(node)) {
744
+ continue;
745
+ }
746
+ var nodePath = sourcePathOfChild(path, index);
747
+ if ("tag" in node && node.tag === "img" && "src" in node) {
748
+ var src = node.src;
749
+ if (getSitemapTree._typeof(src) === "object" && src !== null && !Array.isArray(src)) {
750
+ visit(sourcePathOfChild(nodePath, "src"), getSitemapTree._objectSpread2({}, src));
751
+ }
752
+ }
753
+ if ("children" in node) {
754
+ forEachRichTextImage(sourcePathOfChild(nodePath, "children"), node.children, visit);
755
+ }
756
+ }
757
+ }
758
+
660
759
  var VAL_SESSION_COOKIE = core.Internal.VAL_SESSION_COOKIE;
661
760
  var VAL_STATE_COOKIE = core.Internal.VAL_STATE_COOKIE;
662
761
  var VAL_ENABLE_COOKIE_NAME = core.Internal.VAL_ENABLE_COOKIE_NAME;
@@ -1172,7 +1271,7 @@ var SerializedRecordSchema = zod.z.lazy(function () {
1172
1271
  dir: zod.z.string().optional(),
1173
1272
  remote: zod.z["boolean"]().optional(),
1174
1273
  encode: ImageEncodeOption.optional(),
1175
- // A videoset's: see `VideoStreamOption` below for why it is spelled
1274
+ // A videodir's: see `VideoStreamOption` below for why it is spelled
1176
1275
  // out rather than passed through.
1177
1276
  stream: VideoStreamOption.optional(),
1178
1277
  alt: SerializedSchema.optional(),
@@ -1228,7 +1327,7 @@ var SerializedVideoSchema = zod.z.object(getSitemapTree._objectSpread2(getSitema
1228
1327
  options: VideoOptions.optional(),
1229
1328
  opt: zod.z["boolean"](),
1230
1329
  remote: zod.z["boolean"]().optional(),
1231
- // The `s.videoset()` a set-backed field picks from.
1330
+ // The `s.videodir()` a set-backed field picks from.
1232
1331
  referencedModule: zod.z.string().optional()
1233
1332
  }));
1234
1333
  var DateOptions = zod.z.object({
@@ -5567,7 +5666,7 @@ function getSourceAt(source, path) {
5567
5666
  * Walks `schema` along `path`, returning a structured result:
5568
5667
  * - `leaf`: walked the full path; resolved schema at the end.
5569
5668
  * - `richtext`: hit a richtext mid-walk; richtext is the resolved schema.
5570
- * - `gallery-traversed`: hit an `s.imageset()` record and walked past it (i.e. the
5669
+ * - `gallery-traversed`: hit an `s.imagedir()` record and walked past it (i.e. the
5571
5670
  * path tries to address an entry inside the gallery — a clue the AI should
5572
5671
  * have used the gallery tool instead).
5573
5672
  * - `unresolved`: the path could not be walked.
@@ -5675,7 +5774,7 @@ function checkGallerySchema(moduleSchema) {
5675
5774
  // looks like a gallery from here, and the tool can do nothing with one.
5676
5775
  return {
5677
5776
  kind: "error",
5678
- message: "Module is a video set (s.videoset()), not an images gallery. Videos cannot be added or removed by this tool: upload them in Val Studio."
5777
+ message: "Module is a video set (s.videodir()), not an images gallery. Videos cannot be added or removed by this tool: upload them in Val Studio."
5679
5778
  };
5680
5779
  }
5681
5780
  if (moduleSchema.type === "image") {
@@ -5706,7 +5805,7 @@ function buildImageGalleryPatch(args, moduleSchema) {
5706
5805
  op: "add",
5707
5806
  path: [args.filePath],
5708
5807
  value: getSitemapTree._objectSpread2(getSitemapTree._objectSpread2({}, args.metadata), {}, {
5709
- // `alt` is a REQUIRED field of a gallery entry (`s.imageset()` gives it a
5808
+ // `alt` is a REQUIRED field of a gallery entry (`s.imagedir()` gives it a
5710
5809
  // nullable string schema), so an entry written without one is invalid
5711
5810
  // the moment it lands — and the caller that had no alt to give is the
5712
5811
  // common case, not the odd one. Null is what the Studio's own upload
@@ -5769,7 +5868,7 @@ function buildRemoveImageGalleryEntryPatch(args, moduleSchema, moduleSource) {
5769
5868
  var GALLERY_REDIRECT = {
5770
5869
  kind: "wrong-tool",
5771
5870
  suggestedTool: "add_session_image_to_gallery",
5772
- reason: "Destination is a media gallery (s.imageset() / s.fileset()). Gallery entries are keyed by file path and carry a file on disk, so they cannot be created with a plain patch. Use add_session_image_to_gallery."
5871
+ reason: "Destination is a media gallery (s.imagedir() / s.filedir()). Gallery entries are keyed by file path and carry a file on disk, so they cannot be created with a plain patch. Use add_session_image_to_gallery."
5773
5872
  };
5774
5873
 
5775
5874
  /**
@@ -5779,10 +5878,10 @@ var GALLERY_REDIRECT = {
5779
5878
  */
5780
5879
  var VIDEOSET_REFUSAL = {
5781
5880
  kind: "error",
5782
- message: "Destination is a video set (s.videoset()). Its entries are keyed by file path and carry video files, so they cannot be created with a plain patch, and no tool here uploads a video: add it in Val Studio."
5881
+ message: "Destination is a video set (s.videodir()). Its entries are keyed by file path and carry video files, so they cannot be created with a plain patch, and no tool here uploads a video: add it in Val Studio."
5783
5882
  };
5784
5883
 
5785
- /** An `s.imageset()` / `s.fileset()` / `s.videoset()` record: a gallery, not an ordinary record. */
5884
+ /** An `s.imagedir()` / `s.filedir()` / `s.videodir()` record: a gallery, not an ordinary record. */
5786
5885
  function isGallery(schema) {
5787
5886
  return schema.type === "record" && schema.mediaType !== undefined;
5788
5887
  }
@@ -6374,59 +6473,6 @@ function withExtension(filename, ext) {
6374
6473
  return "".concat(base, ".").concat(ext);
6375
6474
  }
6376
6475
 
6377
- /**
6378
- * The one way to build a child's source path.
6379
- *
6380
- * There were five hand-rolled versions of this, three of them subtly different
6381
- * and two of them wrong, and the wrong ones were wrong in a way that hid: a
6382
- * module path segment has to be JSON-quoted if it is a string and bare if it is
6383
- * an array index, and both broken copies appended the raw key at the module
6384
- * root. An unquoted key parses fine as long as it contains no `.` — so every
6385
- * object field and every ordinary record key still resolved, and only a key with
6386
- * a dot in it broke. That is exactly what a media gallery is keyed by, so
6387
- * clicking a file in the Media panel navigated to
6388
- * `?p=/public/val/red-8x8_bfbd0.png`, which `splitModulePath` reads as the two
6389
- * segments `/public/val/red-8x8_bfbd0` and `png`, and the studio said the module
6390
- * was not found.
6391
- *
6392
- * So: one function, and never a template string. `Internal.createValPathOfItem`
6393
- * is the rule itself — `JSON.stringify` quotes a string and leaves a number
6394
- * bare, which is precisely the module-path grammar — and everything here defers
6395
- * to it rather than restating it.
6396
- */
6397
- function sourcePathOfChild(parent, key) {
6398
- /**
6399
- * A parent that is already `…?p=` gets the key with no separator.
6400
- *
6401
- * The search index walks from `moduleFilePath + "?p="` rather than from the
6402
- * module file path, so that every path it produces has a module path — and
6403
- * `createValPathOfItem` would see the separator and join with a `.`, giving
6404
- * `?p=."title"`.
6405
- */
6406
- if (parent.endsWith(core.Internal.ModuleFilePathSep)) {
6407
- return "".concat(parent).concat(JSON.stringify(key));
6408
- }
6409
- var path = core.Internal.createValPathOfItem(parent, key);
6410
- if (path === undefined) {
6411
- // Only when the parent is empty, which callers cannot produce: every walk
6412
- // starts from a module file path. Thrown rather than skipped so a future
6413
- // change that breaks that assumption is loud.
6414
- throw new Error("Could not build a source path for '".concat(key, "' under ").concat(parent));
6415
- }
6416
- return path;
6417
- }
6418
-
6419
- /**
6420
- * The same thing, for callers holding the module file path and module path apart.
6421
- *
6422
- * `ModulePath` is empty at the module root, which is the case both broken copies
6423
- * got wrong: there is no separator in the path yet, so the key is the first
6424
- * segment and still has to be quoted.
6425
- */
6426
- function concatModulePath(moduleFilePath, modulePath, key) {
6427
- return sourcePathOfChild(modulePath ? core.Internal.joinModuleFilePathAndModulePath(moduleFilePath, modulePath) : moduleFilePath, key);
6428
- }
6429
-
6430
6476
  /**
6431
6477
  * Traverses a schema and source pair, calling a callback for each leaf node.
6432
6478
  * Handles all schema types including primitives, objects, arrays, records, unions, richtext, files, images, etc.
@@ -8056,6 +8102,7 @@ exports.filterRoutesByPatterns = filterRoutesByPatterns;
8056
8102
  exports.findSimilar = findSimilar;
8057
8103
  exports.fitWithin = fitWithin;
8058
8104
  exports.flattenRichText = flattenRichText;
8105
+ exports.forEachRichTextImage = forEachRichTextImage;
8059
8106
  exports.getErrorMessageFromUnknownJson = getErrorMessageFromUnknownJson;
8060
8107
  exports.getFilenameFromRef = getFilenameFromRef;
8061
8108
  exports.getInlineImgInfo = getInlineImgInfo;
@@ -8101,6 +8148,7 @@ exports.resolvePairGround = resolvePairGround;
8101
8148
  exports.resolveSchemaSourceFixForError = resolveSchemaSourceFixForError;
8102
8149
  exports.resolveSchemaSourceFixes = resolveSchemaSourceFixes;
8103
8150
  exports.resolveSerializedSchemaAtPath = resolveSerializedSchemaAtPath;
8151
+ exports.richTextImageSchema = richTextImageSchema;
8104
8152
  exports.richTextToRemirror = richTextToRemirror;
8105
8153
  exports.safeParsePatch = safeParsePatch;
8106
8154
  exports.sourcePathOfChild = sourcePathOfChild;