@valbuild/shared 0.143.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @valbuild/shared
2
2
 
3
+ ## 0.144.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#788](https://github.com/valbuild/val/pull/788) [`a84271c`](https://github.com/valbuild/val/commit/a84271c534822071c1e428cf9990602459682d25) Thanks [@freekh](https://github.com/freekh)! - Fixes to `npx val validate` for `s.imagedir()` and `s.filedir()`, and the `s.image(galleryVal)` / `s.file(filesVal)` fields that use them:
8
+
9
+ - **`--fix` now updates every field that uses an uploaded image or file.** When `--fix` moves an entry of an `s.imagedir(dir).remote()` or `s.filedir(dir, options).remote()` to Val Remote, the entry's key changes from the local path to the remote URL. Fields that held the old path were left pointing at it, and reported "The gallery does not have an image at …" with nothing to fix it. Now `s.image(galleryVal)` and `s.file(filesVal)` fields, and images in rich text (`s.richtext({ img: s.image(galleryVal) })`), are updated in the same run. The VS Code extension's "upload to Val Remote" updates them in the same edit, including fields inside `.jsonValues()` entries, which live in their own `*.val.json` files.
10
+ - **A field that uses an image or file from a `.remote()` gallery is no longer reported as "Expected local image, but found remote".** The gallery decides whether its files are on Val Remote; the field only has to name a file the gallery has. Before, `--fix` would download the file and point the field at a path the gallery did not have.
11
+ - **Images uploaded through a field into a `.remote()` gallery.** When you upload an image through an `s.image(galleryVal)` field in Val Studio, the field stores the remote URL and the gallery stores the image under its local path. Validation now accepts this, and `useVal` / `fetchVal` now fill in the image's `width`, `height` and `mimeType` from the gallery for it, as they do for every other gallery image.
12
+ - **Errors in a gallery's keys are reported.** A remote URL in a gallery that is not `.remote()`, a remote URL that is not valid, or one outside the gallery's `dir` was silently ignored by `npx val validate`. It is now reported as an error. `--fix` does not change it: you decide whether the key or the gallery's options are wrong.
13
+ - **A file is no longer reported as valid when it still has an error.** When `--fix` fixed one error in a file and another error was left, the file could be printed as "✔ valid".
14
+
15
+ - Updated dependencies [[`a84271c`](https://github.com/valbuild/val/commit/a84271c534822071c1e428cf9990602459682d25), [`860ab2b`](https://github.com/valbuild/val/commit/860ab2b87333daf95a48215b0e4a1b44f441c878)]:
16
+ - @valbuild/core@0.144.0
17
+
3
18
  ## 0.143.0
4
19
 
5
20
  ### Patch Changes
@@ -881,14 +881,14 @@ export declare const Api: {
881
881
  patch: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
882
882
  op: z.ZodLiteral<"add">;
883
883
  path: z.ZodArray<z.ZodString>;
884
- value: z.ZodType<JSONValueT, unknown, z.core.$ZodTypeInternals<JSONValueT, unknown>>;
884
+ value: z.ZodType<import("@valbuild/core/patch").JSONValue, unknown, z.core.$ZodTypeInternals<import("@valbuild/core/patch").JSONValue, unknown>>;
885
885
  }, z.core.$strict>, z.ZodObject<{
886
886
  op: z.ZodLiteral<"remove">;
887
887
  path: z.ZodTuple<[z.ZodString], z.ZodString>;
888
888
  }, z.core.$strict>, z.ZodObject<{
889
889
  op: z.ZodLiteral<"replace">;
890
890
  path: z.ZodArray<z.ZodString>;
891
- value: z.ZodType<JSONValueT, unknown, z.core.$ZodTypeInternals<JSONValueT, unknown>>;
891
+ value: z.ZodType<import("@valbuild/core/patch").JSONValue, unknown, z.core.$ZodTypeInternals<import("@valbuild/core/patch").JSONValue, unknown>>;
892
892
  }, z.core.$strict>, z.ZodObject<{
893
893
  op: z.ZodLiteral<"move">;
894
894
  from: z.ZodTuple<[z.ZodString], z.ZodString>;
@@ -900,15 +900,15 @@ export declare const Api: {
900
900
  }, z.core.$strict>, z.ZodObject<{
901
901
  op: z.ZodLiteral<"test">;
902
902
  path: z.ZodArray<z.ZodString>;
903
- value: z.ZodType<JSONValueT, unknown, z.core.$ZodTypeInternals<JSONValueT, unknown>>;
903
+ value: z.ZodType<import("@valbuild/core/patch").JSONValue, unknown, z.core.$ZodTypeInternals<import("@valbuild/core/patch").JSONValue, unknown>>;
904
904
  }, z.core.$strict>, z.ZodObject<{
905
905
  op: z.ZodLiteral<"file">;
906
906
  path: z.ZodArray<z.ZodString>;
907
907
  filePath: z.ZodString;
908
- value: z.ZodType<JSONValueT, unknown, z.core.$ZodTypeInternals<JSONValueT, unknown>>;
908
+ value: z.ZodType<import("@valbuild/core/patch").JSONValue, unknown, z.core.$ZodTypeInternals<import("@valbuild/core/patch").JSONValue, unknown>>;
909
909
  remote: z.ZodBoolean;
910
910
  nestedFilePath: z.ZodOptional<z.ZodArray<z.ZodString>>;
911
- metadata: z.ZodOptional<z.ZodType<JSONValueT, unknown, z.core.$ZodTypeInternals<JSONValueT, unknown>>>;
911
+ metadata: z.ZodOptional<z.ZodType<import("@valbuild/core/patch").JSONValue, unknown, z.core.$ZodTypeInternals<import("@valbuild/core/patch").JSONValue, unknown>>>;
912
912
  }, z.core.$strict>], "op">>>;
913
913
  patchId: z.ZodString & z.ZodType<import("@valbuild/core").PatchId, string, z.core.$ZodTypeInternals<import("@valbuild/core").PatchId, string>>;
914
914
  createdAt: z.ZodString;
@@ -1051,7 +1051,7 @@ export declare const Api: {
1051
1051
  status: z.ZodLiteral<200>;
1052
1052
  json: z.ZodObject<{
1053
1053
  schemaSha: z.ZodString;
1054
- schemas: z.ZodRecord<z.ZodString & z.ZodType<ModuleFilePath, string, z.core.$ZodTypeInternals<ModuleFilePath, string>>, z.ZodType<SerializedSchemaT, unknown, z.core.$ZodTypeInternals<SerializedSchemaT, unknown>>>;
1054
+ schemas: z.ZodRecord<z.ZodString & z.ZodType<ModuleFilePath, string, z.core.$ZodTypeInternals<ModuleFilePath, string>>, z.ZodType<import("@valbuild/core").SerializedSchema, unknown, z.core.$ZodTypeInternals<import("@valbuild/core").SerializedSchema, unknown>>>;
1055
1055
  }, z.core.$strip>;
1056
1056
  }, z.core.$strip>]>;
1057
1057
  };
@@ -1152,7 +1152,7 @@ export declare const Api: {
1152
1152
  message: z.ZodString;
1153
1153
  value: z.ZodOptional<z.ZodUnknown>;
1154
1154
  fatal: z.ZodOptional<z.ZodBoolean>;
1155
- fixes: z.ZodOptional<z.ZodArray<z.ZodType<ValidationFix, unknown, z.core.$ZodTypeInternals<ValidationFix, unknown>>>>;
1155
+ fixes: z.ZodOptional<z.ZodArray<z.ZodType<"image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "images:check-remote" | "images:upload-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "files:check-remote" | "files:upload-remote" | "video:add-metadata" | "video:upload-remote" | "video:download-remote" | "videos:add-metadata" | "videos:check-remote" | "videos:upload-remote" | "keyof:check-keys" | "router:check-route" | "locale:check-locale" | "images:check-unique-folder" | "files:check-unique-folder" | "images:check-all-files" | "files:check-all-files" | "videos:check-unique-folder" | "videos:check-all-files" | "jsonValues:extract-entry" | "record:fill-keys" | "external:upload" | "view:check-module", unknown, z.core.$ZodTypeInternals<"image:add-metadata" | "image:check-metadata" | "image:upload-remote" | "image:download-remote" | "image:check-remote" | "images:check-remote" | "images:upload-remote" | "file:add-metadata" | "file:check-metadata" | "file:upload-remote" | "file:download-remote" | "file:check-remote" | "files:check-remote" | "files:upload-remote" | "video:add-metadata" | "video:upload-remote" | "video:download-remote" | "videos:add-metadata" | "videos:check-remote" | "videos:upload-remote" | "keyof:check-keys" | "router:check-route" | "locale:check-locale" | "images:check-unique-folder" | "files:check-unique-folder" | "images:check-all-files" | "files:check-all-files" | "videos:check-unique-folder" | "videos:check-all-files" | "jsonValues:extract-entry" | "record:fill-keys" | "external:upload" | "view:check-module", unknown>>>>;
1156
1156
  }, z.core.$strip>>>>;
1157
1157
  }, z.core.$strip>>;
1158
1158
  }, z.core.$strip>;
@@ -1482,8 +1482,8 @@ export declare const Api: {
1482
1482
  hasArchive: z.ZodBoolean;
1483
1483
  }, z.core.$strip>;
1484
1484
  modules: z.ZodRecord<z.ZodString, z.ZodObject<{
1485
- source: z.ZodNullable<z.ZodType<JSONValueT, unknown, z.core.$ZodTypeInternals<JSONValueT, unknown>>>;
1486
- schema: z.ZodNullable<z.ZodType<SerializedSchemaT, unknown, z.core.$ZodTypeInternals<SerializedSchemaT, unknown>>>;
1485
+ source: z.ZodNullable<z.ZodType<import("@valbuild/core/patch").JSONValue, unknown, z.core.$ZodTypeInternals<import("@valbuild/core/patch").JSONValue, unknown>>>;
1486
+ schema: z.ZodNullable<z.ZodType<import("@valbuild/core").SerializedSchema, unknown, z.core.$ZodTypeInternals<import("@valbuild/core").SerializedSchema, unknown>>>;
1487
1487
  patchIds: z.ZodArray<z.ZodString & z.ZodType<import("@valbuild/core").PatchId, string, z.core.$ZodTypeInternals<import("@valbuild/core").PatchId, string>>>;
1488
1488
  changedPaths: z.ZodArray<z.ZodString>;
1489
1489
  failures: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -1602,8 +1602,8 @@ export declare const Api: {
1602
1602
  json: z.ZodObject<{
1603
1603
  moduleFilePath: z.ZodString;
1604
1604
  module: z.ZodNullable<z.ZodObject<{
1605
- source: z.ZodNullable<z.ZodType<JSONValueT, unknown, z.core.$ZodTypeInternals<JSONValueT, unknown>>>;
1606
- schema: z.ZodNullable<z.ZodType<SerializedSchemaT, unknown, z.core.$ZodTypeInternals<SerializedSchemaT, unknown>>>;
1605
+ source: z.ZodNullable<z.ZodType<import("@valbuild/core/patch").JSONValue, unknown, z.core.$ZodTypeInternals<import("@valbuild/core/patch").JSONValue, unknown>>>;
1606
+ schema: z.ZodNullable<z.ZodType<import("@valbuild/core").SerializedSchema, unknown, z.core.$ZodTypeInternals<import("@valbuild/core").SerializedSchema, unknown>>>;
1607
1607
  patchIds: z.ZodArray<z.ZodString & z.ZodType<import("@valbuild/core").PatchId, string, z.core.$ZodTypeInternals<import("@valbuild/core").PatchId, string>>>;
1608
1608
  changedPaths: z.ZodArray<z.ZodString>;
1609
1609
  failures: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -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;
@@ -64,8 +64,8 @@ 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>>>;
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
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<{
@@ -109,8 +109,8 @@ 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>>>;
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
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<{
@@ -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>;
@@ -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;
@@ -1,6 +1,6 @@
1
- import { Internal, CODE_LANGUAGES, resolveSettingsModule, missingDeclaredKeys, localeOfValue, discriminatedUnionBranchOf, DEFAULT_COLOR_FORMAT, declaredKeySetOf } from '@valbuild/core';
2
1
  import { _ as _createForOfIteratorHelper, o as _objectSpread2, q as _arrayLikeToArray, r as _unsupportedIterableToArray, s as _typeof, t as _defineProperty, u as _toPropertyKey } from '../../dist/getSitemapTree-6fcdf745.esm.js';
3
2
  export { D as DEFAULT_CANVAS_SELECTION, e as DEFAULT_CANVAS_SELECTION_SOFT, b as VAL_AI_SESSION_STORAGE_KEY, d as VAL_CANVAS_MESSAGE, c as VAL_CANVAS_PARAM, V as VAL_CONFIG_SESSION_STORAGE_KEY, a as VAL_THEME_SESSION_STORAGE_KEY, h as getNextAppRouterSourceFolder, m as getPageRouterSitemapTree, k as getPageRouterSourceFolder, n as getPatternFromModuleFilePath, j as getTanStackRouterSourceFolder, l as isTanStackRoutesFolder, g as isValCanvasFrame, i as isValCanvasPageMessage, f as isValCanvasStudioMessage, p as parseRoutePattern, w as withValCanvasParam } from '../../dist/getSitemapTree-6fcdf745.esm.js';
3
+ import { Internal, CODE_LANGUAGES, resolveSettingsModule, missingDeclaredKeys, localeOfValue, discriminatedUnionBranchOf, DEFAULT_COLOR_FORMAT, declaredKeySetOf } from '@valbuild/core';
4
4
  import { z } from 'zod';
5
5
  import { fromError } from 'zod-validation-error';
6
6
  import FlexSearch from 'flexsearch';
@@ -650,6 +650,105 @@ function convertListItemToRemirrorParagraph(rtChildren) {
650
650
  return children;
651
651
  }
652
652
 
653
+ /**
654
+ * The one way to build a child's source path.
655
+ *
656
+ * There were five hand-rolled versions of this, three of them subtly different
657
+ * and two of them wrong, and the wrong ones were wrong in a way that hid: a
658
+ * module path segment has to be JSON-quoted if it is a string and bare if it is
659
+ * an array index, and both broken copies appended the raw key at the module
660
+ * root. An unquoted key parses fine as long as it contains no `.` — so every
661
+ * object field and every ordinary record key still resolved, and only a key with
662
+ * a dot in it broke. That is exactly what a media gallery is keyed by, so
663
+ * clicking a file in the Media panel navigated to
664
+ * `?p=/public/val/red-8x8_bfbd0.png`, which `splitModulePath` reads as the two
665
+ * segments `/public/val/red-8x8_bfbd0` and `png`, and the studio said the module
666
+ * was not found.
667
+ *
668
+ * So: one function, and never a template string. `Internal.createValPathOfItem`
669
+ * is the rule itself — `JSON.stringify` quotes a string and leaves a number
670
+ * bare, which is precisely the module-path grammar — and everything here defers
671
+ * to it rather than restating it.
672
+ */
673
+ function sourcePathOfChild(parent, key) {
674
+ /**
675
+ * A parent that is already `…?p=` gets the key with no separator.
676
+ *
677
+ * The search index walks from `moduleFilePath + "?p="` rather than from the
678
+ * module file path, so that every path it produces has a module path — and
679
+ * `createValPathOfItem` would see the separator and join with a `.`, giving
680
+ * `?p=."title"`.
681
+ */
682
+ if (parent.endsWith(Internal.ModuleFilePathSep)) {
683
+ return "".concat(parent).concat(JSON.stringify(key));
684
+ }
685
+ var path = Internal.createValPathOfItem(parent, key);
686
+ if (path === undefined) {
687
+ // Only when the parent is empty, which callers cannot produce: every walk
688
+ // starts from a module file path. Thrown rather than skipped so a future
689
+ // change that breaks that assumption is loud.
690
+ throw new Error("Could not build a source path for '".concat(key, "' under ").concat(parent));
691
+ }
692
+ return path;
693
+ }
694
+
695
+ /**
696
+ * The same thing, for callers holding the module file path and module path apart.
697
+ *
698
+ * `ModulePath` is empty at the module root, which is the case both broken copies
699
+ * got wrong: there is no separator in the path yet, so the key is the first
700
+ * segment and still has to be quoted.
701
+ */
702
+ function concatModulePath(moduleFilePath, modulePath, key) {
703
+ return sourcePathOfChild(modulePath ? Internal.joinModuleFilePathAndModulePath(moduleFilePath, modulePath) : moduleFilePath, key);
704
+ }
705
+
706
+ /**
707
+ * The image schema a rich text field's inline `img` nodes are validated with,
708
+ * when it is a real schema rather than `img: true`.
709
+ *
710
+ * It is the only way a rich text field can point INTO a gallery
711
+ * (`s.richtext({ img: s.image(galleryVal) })`), which is why every reference
712
+ * scan has to ask: the field's own schema is `richtext`, not `image`, so a walk
713
+ * that only looks for image leaves walks straight past the images in it.
714
+ */
715
+ function richTextImageSchema(schema) {
716
+ var _schema$options;
717
+ var img = (_schema$options = schema.options) === null || _schema$options === void 0 ? void 0 : _schema$options.img;
718
+ return _typeof(img) === "object" && img !== null ? img : null;
719
+ }
720
+
721
+ /**
722
+ * Every inline image in a rich text value, at the path of its `src`.
723
+ *
724
+ * `src` is a media value (`{ path, … }`), so the path handed out is one a
725
+ * patch can address — `field.0."children".1."src"` — and a rename rewrites
726
+ * `[…, "src", "path"]` there with the same op it uses on an image field.
727
+ * Images nest (a list item holds a paragraph holds the image), so the walk
728
+ * follows `children` all the way down.
729
+ */
730
+ function forEachRichTextImage(path, source, visit) {
731
+ if (!Array.isArray(source)) {
732
+ return;
733
+ }
734
+ for (var index = 0; index < source.length; index++) {
735
+ var node = source[index];
736
+ if (_typeof(node) !== "object" || node === null || Array.isArray(node)) {
737
+ continue;
738
+ }
739
+ var nodePath = sourcePathOfChild(path, index);
740
+ if ("tag" in node && node.tag === "img" && "src" in node) {
741
+ var src = node.src;
742
+ if (_typeof(src) === "object" && src !== null && !Array.isArray(src)) {
743
+ visit(sourcePathOfChild(nodePath, "src"), _objectSpread2({}, src));
744
+ }
745
+ }
746
+ if ("children" in node) {
747
+ forEachRichTextImage(sourcePathOfChild(nodePath, "children"), node.children, visit);
748
+ }
749
+ }
750
+ }
751
+
653
752
  var VAL_SESSION_COOKIE = Internal.VAL_SESSION_COOKIE;
654
753
  var VAL_STATE_COOKIE = Internal.VAL_STATE_COOKIE;
655
754
  var VAL_ENABLE_COOKIE_NAME = Internal.VAL_ENABLE_COOKIE_NAME;
@@ -1165,7 +1264,7 @@ var SerializedRecordSchema = z.lazy(function () {
1165
1264
  dir: z.string().optional(),
1166
1265
  remote: z["boolean"]().optional(),
1167
1266
  encode: ImageEncodeOption.optional(),
1168
- // A videoset's: see `VideoStreamOption` below for why it is spelled
1267
+ // A videodir's: see `VideoStreamOption` below for why it is spelled
1169
1268
  // out rather than passed through.
1170
1269
  stream: VideoStreamOption.optional(),
1171
1270
  alt: SerializedSchema.optional(),
@@ -1221,7 +1320,7 @@ var SerializedVideoSchema = z.object(_objectSpread2(_objectSpread2({}, commonSch
1221
1320
  options: VideoOptions.optional(),
1222
1321
  opt: z["boolean"](),
1223
1322
  remote: z["boolean"]().optional(),
1224
- // The `s.videoset()` a set-backed field picks from.
1323
+ // The `s.videodir()` a set-backed field picks from.
1225
1324
  referencedModule: z.string().optional()
1226
1325
  }));
1227
1326
  var DateOptions = z.object({
@@ -5560,7 +5659,7 @@ function getSourceAt(source, path) {
5560
5659
  * Walks `schema` along `path`, returning a structured result:
5561
5660
  * - `leaf`: walked the full path; resolved schema at the end.
5562
5661
  * - `richtext`: hit a richtext mid-walk; richtext is the resolved schema.
5563
- * - `gallery-traversed`: hit an `s.imageset()` record and walked past it (i.e. the
5662
+ * - `gallery-traversed`: hit an `s.imagedir()` record and walked past it (i.e. the
5564
5663
  * path tries to address an entry inside the gallery — a clue the AI should
5565
5664
  * have used the gallery tool instead).
5566
5665
  * - `unresolved`: the path could not be walked.
@@ -5668,7 +5767,7 @@ function checkGallerySchema(moduleSchema) {
5668
5767
  // looks like a gallery from here, and the tool can do nothing with one.
5669
5768
  return {
5670
5769
  kind: "error",
5671
- 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."
5770
+ 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."
5672
5771
  };
5673
5772
  }
5674
5773
  if (moduleSchema.type === "image") {
@@ -5699,7 +5798,7 @@ function buildImageGalleryPatch(args, moduleSchema) {
5699
5798
  op: "add",
5700
5799
  path: [args.filePath],
5701
5800
  value: _objectSpread2(_objectSpread2({}, args.metadata), {}, {
5702
- // `alt` is a REQUIRED field of a gallery entry (`s.imageset()` gives it a
5801
+ // `alt` is a REQUIRED field of a gallery entry (`s.imagedir()` gives it a
5703
5802
  // nullable string schema), so an entry written without one is invalid
5704
5803
  // the moment it lands — and the caller that had no alt to give is the
5705
5804
  // common case, not the odd one. Null is what the Studio's own upload
@@ -5762,7 +5861,7 @@ function buildRemoveImageGalleryEntryPatch(args, moduleSchema, moduleSource) {
5762
5861
  var GALLERY_REDIRECT = {
5763
5862
  kind: "wrong-tool",
5764
5863
  suggestedTool: "add_session_image_to_gallery",
5765
- 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."
5864
+ 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."
5766
5865
  };
5767
5866
 
5768
5867
  /**
@@ -5772,10 +5871,10 @@ var GALLERY_REDIRECT = {
5772
5871
  */
5773
5872
  var VIDEOSET_REFUSAL = {
5774
5873
  kind: "error",
5775
- 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."
5874
+ 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."
5776
5875
  };
5777
5876
 
5778
- /** An `s.imageset()` / `s.fileset()` / `s.videoset()` record: a gallery, not an ordinary record. */
5877
+ /** An `s.imagedir()` / `s.filedir()` / `s.videodir()` record: a gallery, not an ordinary record. */
5779
5878
  function isGallery(schema) {
5780
5879
  return schema.type === "record" && schema.mediaType !== undefined;
5781
5880
  }
@@ -6367,59 +6466,6 @@ function withExtension(filename, ext) {
6367
6466
  return "".concat(base, ".").concat(ext);
6368
6467
  }
6369
6468
 
6370
- /**
6371
- * The one way to build a child's source path.
6372
- *
6373
- * There were five hand-rolled versions of this, three of them subtly different
6374
- * and two of them wrong, and the wrong ones were wrong in a way that hid: a
6375
- * module path segment has to be JSON-quoted if it is a string and bare if it is
6376
- * an array index, and both broken copies appended the raw key at the module
6377
- * root. An unquoted key parses fine as long as it contains no `.` — so every
6378
- * object field and every ordinary record key still resolved, and only a key with
6379
- * a dot in it broke. That is exactly what a media gallery is keyed by, so
6380
- * clicking a file in the Media panel navigated to
6381
- * `?p=/public/val/red-8x8_bfbd0.png`, which `splitModulePath` reads as the two
6382
- * segments `/public/val/red-8x8_bfbd0` and `png`, and the studio said the module
6383
- * was not found.
6384
- *
6385
- * So: one function, and never a template string. `Internal.createValPathOfItem`
6386
- * is the rule itself — `JSON.stringify` quotes a string and leaves a number
6387
- * bare, which is precisely the module-path grammar — and everything here defers
6388
- * to it rather than restating it.
6389
- */
6390
- function sourcePathOfChild(parent, key) {
6391
- /**
6392
- * A parent that is already `…?p=` gets the key with no separator.
6393
- *
6394
- * The search index walks from `moduleFilePath + "?p="` rather than from the
6395
- * module file path, so that every path it produces has a module path — and
6396
- * `createValPathOfItem` would see the separator and join with a `.`, giving
6397
- * `?p=."title"`.
6398
- */
6399
- if (parent.endsWith(Internal.ModuleFilePathSep)) {
6400
- return "".concat(parent).concat(JSON.stringify(key));
6401
- }
6402
- var path = Internal.createValPathOfItem(parent, key);
6403
- if (path === undefined) {
6404
- // Only when the parent is empty, which callers cannot produce: every walk
6405
- // starts from a module file path. Thrown rather than skipped so a future
6406
- // change that breaks that assumption is loud.
6407
- throw new Error("Could not build a source path for '".concat(key, "' under ").concat(parent));
6408
- }
6409
- return path;
6410
- }
6411
-
6412
- /**
6413
- * The same thing, for callers holding the module file path and module path apart.
6414
- *
6415
- * `ModulePath` is empty at the module root, which is the case both broken copies
6416
- * got wrong: there is no separator in the path yet, so the key is the first
6417
- * segment and still has to be quoted.
6418
- */
6419
- function concatModulePath(moduleFilePath, modulePath, key) {
6420
- return sourcePathOfChild(modulePath ? Internal.joinModuleFilePathAndModulePath(moduleFilePath, modulePath) : moduleFilePath, key);
6421
- }
6422
-
6423
6469
  /**
6424
6470
  * Traverses a schema and source pair, calling a callback for each leaf node.
6425
6471
  * Handles all schema types including primitives, objects, arrays, records, unions, richtext, files, images, etc.
@@ -7930,4 +7976,4 @@ function parse(schema, body, call) {
7930
7976
  return parsed.data;
7931
7977
  }
7932
7978
 
7933
- export { AA_LARGE, AA_TEXT, Api, BRAND_CONTRAST_PAIRS, BinaryFileRef, CodeOptions, ColorOptions, DEFAULT_ERROR_MESSAGE, DateOptions, ENCODE_DEFAULTS, ENCODE_MIME_TYPE_OF, FileOptions, HistoricalCommit, HistoricalModule, HistoricalPatchSet, HistoryError, ImageEncodeOption, ImageOptions, JSONValue, JSON_ENTRIES_BATCH_MAX, ModuleComparison, NEVER_ENCODED, ParentRef$1 as ParentRef, Patch, PatchBlock, PatchGroup, PatchId, PatchJSON, PublishProtocolError, RAMP_STEPS, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, RestoreVerdict, RichTextOptions, SCHEMA_SOURCE_FIXES, SerializedArraySchema, SerializedBooleanSchema, SerializedCodeSchema, SerializedColorSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedDiscriminatedUnionSchema, SerializedEnumSchema, SerializedFileSchema, SerializedImageSchema, SerializedKeyOfSchema, SerializedLiteralSchema, SerializedLocaleSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedRecordSchema, SerializedRichTextSchema, SerializedRouteSchema, SerializedSchema, SerializedSettingsSchema, SerializedStringSchema, SerializedValViewSchema, SerializedVideoSchema, SharedValConfig, VAL_ENABLE_COOKIE_NAME, VAL_GREEN_RAMP, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, VAL_STUDIO_HEADER, ValCommit, ValDeployment, VideoOptions, VideoStreamOption, accentRamp, buildDuplicatePatch, buildEmptyAtPathPatch, buildFileRefValue, buildImageGalleryPatch, buildRemoveImageGalleryEntryPatch, buildSearchIndex, chainHeadOf, checkCompatibility, chooseEncoded, concatModulePath, contrastRatio, createRegExpFromPattern, createSearchIndex, createValClient, declaredLocales, describeContainerAtPath, emptyOf, explainIncompatible, filterBlockingValidationErrors, filterRoutesByPatterns, findSimilar, fitWithin, flattenRichText, getErrorMessageFromUnknownJson, getFilenameFromRef, getInlineImgInfo, getKeyOfRecordAt, getRefParts, getRoutesOf, getRoutesWithModulePaths, getSourceAt, indexModule, isMimeTypeAccepted, isRemoteSchema, isSchemaSourceFixError, isSkippedSource, keyOfRecordPath, levenshtein, localeAt, memoizePerRequest, newestCommitSha, parseArtifacts, parseBuildTarget, parseCancel, parseDeclare, parseDiscard, parseJob, parseNewestCiRun, parsePress, parseProblems, parseProjectSource, parsePromote, parsePublishToken, parseRenew, parseRequestStatus, parseStatus, parseUpdateTarget, parseVerify, partitionValidationErrors, performSearch, relativeLuminance, remirrorToRichTextSource, removeModule, resolveEncodeSettings, resolvePairGround, resolveSchemaSourceFixForError, resolveSchemaSourceFixes, resolveSerializedSchemaAtPath, richTextToRemirror, safeParsePatch, sourcePathOfChild, themeCustomProperties, toolNames, traverseSchemaSource, urlOf, validateRoutePatterns, withExtension };
7979
+ export { AA_LARGE, AA_TEXT, Api, BRAND_CONTRAST_PAIRS, BinaryFileRef, CodeOptions, ColorOptions, DEFAULT_ERROR_MESSAGE, DateOptions, ENCODE_DEFAULTS, ENCODE_MIME_TYPE_OF, FileOptions, HistoricalCommit, HistoricalModule, HistoricalPatchSet, HistoryError, ImageEncodeOption, ImageOptions, JSONValue, JSON_ENTRIES_BATCH_MAX, ModuleComparison, NEVER_ENCODED, ParentRef$1 as ParentRef, Patch, PatchBlock, PatchGroup, PatchId, PatchJSON, PublishProtocolError, RAMP_STEPS, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, RestoreVerdict, RichTextOptions, SCHEMA_SOURCE_FIXES, SerializedArraySchema, SerializedBooleanSchema, SerializedCodeSchema, SerializedColorSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedDiscriminatedUnionSchema, SerializedEnumSchema, SerializedFileSchema, SerializedImageSchema, SerializedKeyOfSchema, SerializedLiteralSchema, SerializedLocaleSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedRecordSchema, SerializedRichTextSchema, SerializedRouteSchema, SerializedSchema, SerializedSettingsSchema, SerializedStringSchema, SerializedValViewSchema, SerializedVideoSchema, SharedValConfig, VAL_ENABLE_COOKIE_NAME, VAL_GREEN_RAMP, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, VAL_STUDIO_HEADER, ValCommit, ValDeployment, VideoOptions, VideoStreamOption, accentRamp, buildDuplicatePatch, buildEmptyAtPathPatch, buildFileRefValue, buildImageGalleryPatch, buildRemoveImageGalleryEntryPatch, buildSearchIndex, chainHeadOf, checkCompatibility, chooseEncoded, concatModulePath, contrastRatio, createRegExpFromPattern, createSearchIndex, createValClient, declaredLocales, describeContainerAtPath, emptyOf, explainIncompatible, filterBlockingValidationErrors, filterRoutesByPatterns, findSimilar, fitWithin, flattenRichText, forEachRichTextImage, getErrorMessageFromUnknownJson, getFilenameFromRef, getInlineImgInfo, getKeyOfRecordAt, getRefParts, getRoutesOf, getRoutesWithModulePaths, getSourceAt, indexModule, isMimeTypeAccepted, isRemoteSchema, isSchemaSourceFixError, isSkippedSource, keyOfRecordPath, levenshtein, localeAt, memoizePerRequest, newestCommitSha, parseArtifacts, parseBuildTarget, parseCancel, parseDeclare, parseDiscard, parseJob, parseNewestCiRun, parsePress, parseProblems, parseProjectSource, parsePromote, parsePublishToken, parseRenew, parseRequestStatus, parseStatus, parseUpdateTarget, parseVerify, partitionValidationErrors, performSearch, relativeLuminance, remirrorToRichTextSource, removeModule, resolveEncodeSettings, resolvePairGround, resolveSchemaSourceFixForError, resolveSchemaSourceFixes, resolveSerializedSchemaAtPath, richTextImageSchema, richTextToRemirror, safeParsePatch, sourcePathOfChild, themeCustomProperties, toolNames, traverseSchemaSource, urlOf, validateRoutePatterns, withExtension };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/shared",
3
- "version": "0.143.0",
3
+ "version": "0.144.0",
4
4
  "private": false,
5
5
  "description": "Val shared types and utilities",
6
6
  "repository": {
@@ -37,7 +37,7 @@
37
37
  "flexsearch": "^0.8.212",
38
38
  "zod": "^4.4.3",
39
39
  "zod-validation-error": "^5.0.0",
40
- "@valbuild/core": "0.143.0"
40
+ "@valbuild/core": "0.144.0"
41
41
  },
42
42
  "files": [
43
43
  "CHANGELOG.md",