@valbuild/shared 0.123.0 → 0.123.3

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.
@@ -1,118 +1,10 @@
1
1
  import { Internal, CODE_LANGUAGES, DEFAULT_COLOR_FORMAT } from '@valbuild/core';
2
- import { b as base64DataUrlToUint8Array } from '../../dist/utils-00f3e1df.esm.js';
2
+ import { _ as _createForOfIteratorHelper, k as _objectSpread2, l as _arrayLikeToArray, m as _unsupportedIterableToArray, n as _defineProperty, o as _typeof } from '../../dist/getSitemapTree-d3e98a2e.esm.js';
3
+ export { 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 getNextAppRouterSitemapTree, g as getNextAppRouterSourceFolder, j as getPatternFromModuleFilePath, f as isValCanvasFrame, i as isValCanvasPageMessage, e as isValCanvasStudioMessage, p as parseRoutePattern, w as withValCanvasParam } from '../../dist/getSitemapTree-d3e98a2e.esm.js';
3
4
  import { z } from 'zod';
4
5
  import { fromError } from 'zod-validation-error';
5
6
  import FlexSearch from 'flexsearch';
6
-
7
- function _toPrimitive(t, r) {
8
- if ("object" != typeof t || !t) return t;
9
- var e = t[Symbol.toPrimitive];
10
- if (void 0 !== e) {
11
- var i = e.call(t, r || "default");
12
- if ("object" != typeof i) return i;
13
- throw new TypeError("@@toPrimitive must return a primitive value.");
14
- }
15
- return ("string" === r ? String : Number)(t);
16
- }
17
-
18
- function _toPropertyKey(t) {
19
- var i = _toPrimitive(t, "string");
20
- return "symbol" == typeof i ? i : i + "";
21
- }
22
-
23
- function _defineProperty(e, r, t) {
24
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
25
- value: t,
26
- enumerable: !0,
27
- configurable: !0,
28
- writable: !0
29
- }) : e[r] = t, e;
30
- }
31
-
32
- function ownKeys(e, r) {
33
- var t = Object.keys(e);
34
- if (Object.getOwnPropertySymbols) {
35
- var o = Object.getOwnPropertySymbols(e);
36
- r && (o = o.filter(function (r) {
37
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
38
- })), t.push.apply(t, o);
39
- }
40
- return t;
41
- }
42
- function _objectSpread2(e) {
43
- for (var r = 1; r < arguments.length; r++) {
44
- var t = null != arguments[r] ? arguments[r] : {};
45
- r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
46
- _defineProperty(e, r, t[r]);
47
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
48
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
49
- });
50
- }
51
- return e;
52
- }
53
-
54
- function _arrayLikeToArray(r, a) {
55
- (null == a || a > r.length) && (a = r.length);
56
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
57
- return n;
58
- }
59
-
60
- function _unsupportedIterableToArray(r, a) {
61
- if (r) {
62
- if ("string" == typeof r) return _arrayLikeToArray(r, a);
63
- var t = {}.toString.call(r).slice(8, -1);
64
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
65
- }
66
- }
67
-
68
- function _createForOfIteratorHelper(r, e) {
69
- var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
70
- if (!t) {
71
- if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
72
- t && (r = t);
73
- var n = 0,
74
- F = function () {};
75
- return {
76
- s: F,
77
- n: function () {
78
- return n >= r.length ? {
79
- done: !0
80
- } : {
81
- done: !1,
82
- value: r[n++]
83
- };
84
- },
85
- e: function (r) {
86
- throw r;
87
- },
88
- f: F
89
- };
90
- }
91
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
92
- }
93
- var o,
94
- a = !0,
95
- u = !1;
96
- return {
97
- s: function () {
98
- t = t.call(r);
99
- },
100
- n: function () {
101
- var r = t.next();
102
- return a = r.done, r;
103
- },
104
- e: function (r) {
105
- u = !0, o = r;
106
- },
107
- f: function () {
108
- try {
109
- a || null == t.return || t.return();
110
- } finally {
111
- if (u) throw o;
112
- }
113
- }
114
- };
115
- }
7
+ import { b as base64DataUrlToUint8Array } from '../../dist/utils-00f3e1df.esm.js';
116
8
 
117
9
  function remirrorToRichTextSource(node, configDirectory, remoteOptions) {
118
10
  var files = {};
@@ -1012,97 +904,96 @@ var InlineRender = z.object({
1012
904
  as: z.literal("inline")
1013
905
  });
1014
906
  var FieldRender = InlineRender.optional();
1015
- var SerializedStringSchema = z.object({
1016
- type: z.literal("string"),
907
+
908
+ /**
909
+ * The fields EVERY serialized schema carries, in one place.
910
+ *
911
+ * Spread into each schema below rather than retyped, because retyping them is
912
+ * exactly how they went missing: `customValidate` and `description` were
913
+ * declared on six of the eighteen schemas and silently dropped by the other
914
+ * twelve. A field added to the base of `SerializedSchema` needs adding here and
915
+ * nowhere else.
916
+ *
917
+ * `type`, `opt` and whatever is particular to the schema stay at the call site
918
+ * - those differ per schema, so there is nothing to share.
919
+ */
920
+ var commonSchemaFields = {
1017
921
  render: FieldRender,
922
+ preview: z.literal(true).optional(),
923
+ // Whether the schema declares a `.validate()`. The function cannot serialize,
924
+ // so this flag is what tells the Studio to run the custom validators on the
925
+ // main thread against the real instance - dropped, and they never run at all.
926
+ // See `hasCustomValidate` in `ui/spa/validation/customValidate.ts`.
927
+ customValidate: z["boolean"]().optional(),
928
+ readonly: z["boolean"]().optional(),
929
+ hidden: z["boolean"]().optional(),
930
+ description: z.string().optional()
931
+ };
932
+ var SerializedStringSchema = z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
933
+ type: z.literal("string"),
1018
934
  // `.multiline()`. Stripped like any undeclared key if it goes missing here,
1019
935
  // which is a single-line input where the author asked for a text box.
1020
936
  multiline: z["boolean"]().optional(),
1021
- preview: z.literal(true).optional(),
1022
937
  options: z.object({
1023
938
  maxLength: z.number().optional(),
1024
939
  minLength: z.number().optional(),
1025
940
  regexp: z.object({
941
+ // `.regexp(re, message)`'s message. Written by
942
+ // `StringSchema.executeSerialize`, so omitting it here strips the
943
+ // author's own wording and leaves the generic "Expected string to
944
+ // match reg exp: …" in its place.
945
+ message: z.string().optional(),
1026
946
  source: z.string(),
1027
947
  flags: z.string()
1028
- }).optional()
948
+ }).optional(),
949
+ customValidate: z["boolean"]().optional()
1029
950
  }).optional(),
1030
951
  opt: z["boolean"](),
1031
- raw: z["boolean"](),
1032
- readonly: z["boolean"]().optional(),
1033
- hidden: z["boolean"]().optional()
1034
- });
1035
- var SerializedLiteralSchema = z.object({
952
+ raw: z["boolean"]()
953
+ }));
954
+ var SerializedLiteralSchema = z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1036
955
  type: z.literal("literal"),
1037
- render: FieldRender,
1038
- preview: z.literal(true).optional(),
1039
956
  value: z.string(),
1040
- opt: z["boolean"](),
1041
- readonly: z["boolean"]().optional(),
1042
- hidden: z["boolean"]().optional()
1043
- });
1044
- var SerializedBooleanSchema = z.object({
957
+ opt: z["boolean"]()
958
+ }));
959
+ var SerializedBooleanSchema = z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1045
960
  type: z.literal("boolean"),
1046
- render: FieldRender,
1047
- preview: z.literal(true).optional(),
1048
- opt: z["boolean"](),
1049
- readonly: z["boolean"]().optional(),
1050
- hidden: z["boolean"]().optional()
1051
- });
1052
- var SerializedNumberSchema = z.object({
961
+ opt: z["boolean"]()
962
+ }));
963
+ var SerializedNumberSchema = z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1053
964
  type: z.literal("number"),
1054
- render: FieldRender,
1055
- preview: z.literal(true).optional(),
1056
965
  options: z.object({
1057
966
  max: z.number().optional(),
1058
967
  min: z.number().optional()
1059
968
  }).optional(),
1060
- opt: z["boolean"](),
1061
- readonly: z["boolean"]().optional(),
1062
- hidden: z["boolean"]().optional()
1063
- });
969
+ opt: z["boolean"]()
970
+ }));
1064
971
  var SerializedObjectSchema = z.lazy(function () {
1065
- return z.object({
972
+ return z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1066
973
  type: z.literal("object"),
1067
- render: FieldRender,
1068
- preview: z.literal(true).optional(),
1069
974
  items: z.record(z.string(), SerializedSchema),
1070
- opt: z["boolean"](),
1071
- readonly: z["boolean"]().optional(),
1072
- hidden: z["boolean"]().optional()
1073
- });
975
+ opt: z["boolean"]()
976
+ }));
1074
977
  });
1075
978
  var SerializedArraySchema = z.lazy(function () {
1076
- return z.object({
979
+ return z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1077
980
  type: z.literal("array"),
1078
- render: FieldRender,
1079
- preview: z.literal(true).optional(),
1080
981
  item: SerializedSchema,
1081
- opt: z["boolean"](),
1082
- readonly: z["boolean"]().optional(),
1083
- hidden: z["boolean"]().optional()
1084
- });
982
+ opt: z["boolean"]()
983
+ }));
1085
984
  });
1086
985
  var SerializedUnionSchema = z.lazy(function () {
1087
- return z.union([z.object({
986
+ return z.union([z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1088
987
  type: z.literal("union"),
1089
- render: FieldRender,
1090
- preview: z.literal(true).optional(),
1091
988
  key: SerializedLiteralSchema,
1092
989
  items: z.array(SerializedLiteralSchema),
1093
- opt: z["boolean"](),
1094
- readonly: z["boolean"]().optional(),
1095
- hidden: z["boolean"]().optional()
1096
- }), z.object({
990
+ opt: z["boolean"]()
991
+ })), z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1097
992
  type: z.literal("union"),
1098
- render: FieldRender,
1099
- preview: z.literal(true).optional(),
1100
993
  key: z.string(),
1101
994
  items: z.array(SerializedObjectSchema),
1102
- opt: z["boolean"](),
1103
- readonly: z["boolean"]().optional(),
1104
- hidden: z["boolean"]().optional()
1105
- })]);
995
+ opt: z["boolean"]()
996
+ }))]);
1106
997
  });
1107
998
  var ImageEncodeOption = z.union([z.literal(false), z.object({
1108
999
  type: z.literal("webp"),
@@ -1115,15 +1006,16 @@ var ImageOptions = z.object({
1115
1006
  accept: z.string().optional(),
1116
1007
  encode: ImageEncodeOption.optional()
1117
1008
  });
1118
- var SerializedImageSchema = z.object({
1009
+ var SerializedImageSchema = z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1119
1010
  type: z.literal("image"),
1120
- render: FieldRender,
1121
- preview: z.literal(true).optional(),
1122
1011
  options: ImageOptions.optional(),
1123
1012
  opt: z["boolean"](),
1124
- readonly: z["boolean"]().optional(),
1125
- hidden: z["boolean"]().optional()
1126
- });
1013
+ // `.remote()`, and the gallery a gallery-backed field reads its metadata
1014
+ // from. Neither is cosmetic: dropped, a remote field looks local and a
1015
+ // gallery-backed one looks like it holds its own dimensions.
1016
+ remote: z["boolean"]().optional(),
1017
+ referencedModule: z.string().optional()
1018
+ }));
1127
1019
  var RichTextOptions = z.lazy(function () {
1128
1020
  return z.object({
1129
1021
  // Set by `.maxLength()` / `.minLength()`, not by the options argument.
@@ -1146,20 +1038,14 @@ var RichTextOptions = z.lazy(function () {
1146
1038
  img: z.union([z["boolean"](), SerializedImageSchema]).optional()
1147
1039
  });
1148
1040
  });
1149
- var SerializedRichTextSchema = z.object({
1041
+ var SerializedRichTextSchema = z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1150
1042
  type: z.literal("richtext"),
1151
- render: FieldRender,
1152
- preview: z.literal(true).optional(),
1153
1043
  options: RichTextOptions.optional(),
1154
- opt: z["boolean"](),
1155
- readonly: z["boolean"]().optional(),
1156
- hidden: z["boolean"]().optional()
1157
- });
1044
+ opt: z["boolean"]()
1045
+ }));
1158
1046
  var SerializedRecordSchema = z.lazy(function () {
1159
- return z.object({
1047
+ return z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1160
1048
  type: z.literal("record"),
1161
- render: FieldRender,
1162
- preview: z.literal(true).optional(),
1163
1049
  item: SerializedSchema,
1164
1050
  opt: z["boolean"](),
1165
1051
  // Optional gallery marker for files/images
@@ -1170,16 +1056,12 @@ var SerializedRecordSchema = z.lazy(function () {
1170
1056
  remote: z["boolean"]().optional(),
1171
1057
  encode: ImageEncodeOption.optional(),
1172
1058
  alt: SerializedSchema.optional(),
1173
- moduleMetadata: z.record(z.string(), z.record(z.string(), z.any())).optional(),
1174
- readonly: z["boolean"]().optional(),
1175
- hidden: z["boolean"]().optional()
1176
- }).passthrough();
1059
+ moduleMetadata: z.record(z.string(), z.record(z.string(), z.any())).optional()
1060
+ })).passthrough();
1177
1061
  });
1178
1062
  var SerializedKeyOfSchema = z.lazy(function () {
1179
- return z.object({
1063
+ return z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1180
1064
  type: z.literal("keyOf"),
1181
- render: FieldRender,
1182
- preview: z.literal(true).optional(),
1183
1065
  path: SourcePath,
1184
1066
  schema: z.union([z.object({
1185
1067
  type: z.literal("object"),
@@ -1190,82 +1072,54 @@ var SerializedKeyOfSchema = z.lazy(function () {
1190
1072
  opt: z["boolean"]().optional()
1191
1073
  })]).optional(),
1192
1074
  values: z.union([z.literal("string"), z.array(z.string())]),
1193
- opt: z["boolean"](),
1194
- readonly: z["boolean"]().optional(),
1195
- hidden: z["boolean"]().optional()
1196
- });
1075
+ opt: z["boolean"]()
1076
+ }));
1197
1077
  });
1198
1078
  var FileOptions = z.object({
1199
1079
  accept: z.string().optional()
1200
1080
  });
1201
- var SerializedFileSchema = z.object({
1081
+ var SerializedFileSchema = z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1202
1082
  type: z.literal("file"),
1203
- render: FieldRender,
1204
- preview: z.literal(true).optional(),
1205
1083
  options: FileOptions.optional(),
1206
1084
  opt: z["boolean"](),
1207
- readonly: z["boolean"]().optional(),
1208
- hidden: z["boolean"]().optional()
1209
- });
1085
+ // See `SerializedImageSchema` above: `.remote()` and the gallery a
1086
+ // gallery-backed field reads from.
1087
+ remote: z["boolean"]().optional(),
1088
+ referencedModule: z.string().optional()
1089
+ }));
1210
1090
  var DateOptions = z.object({
1211
1091
  from: z.string().optional(),
1212
1092
  to: z.string().optional()
1213
1093
  });
1214
- var SerializedDateSchema = z.object({
1094
+ var SerializedDateSchema = z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1215
1095
  type: z.literal("date"),
1216
- render: FieldRender,
1217
- preview: z.literal(true).optional(),
1218
1096
  options: DateOptions.optional(),
1219
- opt: z["boolean"](),
1220
- customValidate: z["boolean"]().optional(),
1221
- readonly: z["boolean"]().optional(),
1222
- hidden: z["boolean"]().optional(),
1223
- description: z.string().optional()
1224
- });
1225
- var SerializedDateTimeSchema = z.object({
1097
+ opt: z["boolean"]()
1098
+ }));
1099
+ var SerializedDateTimeSchema = z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1226
1100
  type: z.literal("dateTime"),
1227
- render: FieldRender,
1228
- preview: z.literal(true).optional(),
1229
1101
  options: DateOptions.optional(),
1230
- opt: z["boolean"](),
1231
- customValidate: z["boolean"]().optional(),
1232
- readonly: z["boolean"]().optional(),
1233
- hidden: z["boolean"]().optional(),
1234
- description: z.string().optional()
1235
- });
1102
+ opt: z["boolean"]()
1103
+ }));
1236
1104
  var ColorOptions = z.object({
1237
1105
  format: z["enum"](["hex", "rgb", "hsl", "oklch"]).optional(),
1238
1106
  alpha: z["boolean"]().optional()
1239
1107
  });
1240
- var SerializedColorSchema = z.object({
1108
+ var SerializedColorSchema = z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1241
1109
  type: z.literal("color"),
1242
- render: FieldRender,
1243
- preview: z.literal(true).optional(),
1244
1110
  options: ColorOptions.optional(),
1245
- opt: z["boolean"](),
1246
- customValidate: z["boolean"]().optional(),
1247
- readonly: z["boolean"]().optional(),
1248
- hidden: z["boolean"]().optional(),
1249
- description: z.string().optional()
1250
- });
1111
+ opt: z["boolean"]()
1112
+ }));
1251
1113
  var CodeOptions = z.object({
1252
1114
  language: z["enum"](CODE_LANGUAGES).optional()
1253
1115
  });
1254
- var SerializedCodeSchema = z.object({
1116
+ var SerializedCodeSchema = z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1255
1117
  type: z.literal("code"),
1256
- render: FieldRender,
1257
- preview: z.literal(true).optional(),
1258
1118
  options: CodeOptions.optional(),
1259
- opt: z["boolean"](),
1260
- customValidate: z["boolean"]().optional(),
1261
- readonly: z["boolean"]().optional(),
1262
- hidden: z["boolean"]().optional(),
1263
- description: z.string().optional()
1264
- });
1265
- var SerializedRouteSchema = z.object({
1119
+ opt: z["boolean"]()
1120
+ }));
1121
+ var SerializedRouteSchema = z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1266
1122
  type: z.literal("route"),
1267
- render: FieldRender,
1268
- preview: z.literal(true).optional(),
1269
1123
  options: z.object({
1270
1124
  include: z.object({
1271
1125
  source: z.string(),
@@ -1277,11 +1131,8 @@ var SerializedRouteSchema = z.object({
1277
1131
  }).optional(),
1278
1132
  customValidate: z["boolean"]().optional()
1279
1133
  }).optional(),
1280
- opt: z["boolean"](),
1281
- customValidate: z["boolean"]().optional(),
1282
- readonly: z["boolean"]().optional(),
1283
- hidden: z["boolean"]().optional()
1284
- });
1134
+ opt: z["boolean"]()
1135
+ }));
1285
1136
 
1286
1137
  // A settings module, and each section inside one, serialize as this - the
1287
1138
  // shape is recursive because `items` holds sections which are themselves
@@ -1289,17 +1140,11 @@ var SerializedRouteSchema = z.object({
1289
1140
  // (see core/src/schema/settings.ts), but they are accepted here because they
1290
1141
  // are part of the declared type.
1291
1142
  var SerializedSettingsSchema = z.lazy(function () {
1292
- return z.object({
1143
+ return z.object(_objectSpread2(_objectSpread2({}, commonSchemaFields), {}, {
1293
1144
  type: z.literal("settings"),
1294
- render: FieldRender,
1295
- preview: z.literal(true).optional(),
1296
1145
  items: z.record(z.string(), SerializedSchema),
1297
- opt: z["boolean"](),
1298
- customValidate: z["boolean"]().optional(),
1299
- readonly: z["boolean"]().optional(),
1300
- hidden: z["boolean"]().optional(),
1301
- description: z.string().optional()
1302
- });
1146
+ opt: z["boolean"]()
1147
+ }));
1303
1148
  });
1304
1149
  var SerializedSchema = z.union([SerializedStringSchema, SerializedLiteralSchema, SerializedBooleanSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedArraySchema, SerializedUnionSchema, SerializedRichTextSchema, SerializedRecordSchema, SerializedKeyOfSchema, SerializedRouteSchema, SerializedFileSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedColorSchema, SerializedCodeSchema, SerializedSettingsSchema, SerializedImageSchema]);
1305
1150
 
@@ -2963,16 +2808,6 @@ var Api = {
2963
2808
  // `number` is allowed because the client stringifies every query value before it
2964
2809
  // goes on the URL (see createValClient), so a numeric param round-trips fine.
2965
2810
 
2966
- function _typeof(o) {
2967
- "@babel/helpers - typeof";
2968
-
2969
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
2970
- return typeof o;
2971
- } : function (o) {
2972
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
2973
- }, _typeof(o);
2974
- }
2975
-
2976
2811
  function getErrorMessageFromUnknownJson(json, fallback) {
2977
2812
  if (_typeof(json) === "object" && json !== null && "message" in json && typeof json.message === "string") {
2978
2813
  return json.message;
@@ -3652,10 +3487,6 @@ function newestCommitSha(commits) {
3652
3487
  return (_newest$commitSha = (_newest = newest) === null || _newest === void 0 ? void 0 : _newest.commitSha) !== null && _newest$commitSha !== void 0 ? _newest$commitSha : null;
3653
3488
  }
3654
3489
 
3655
- var VAL_CONFIG_SESSION_STORAGE_KEY = "val-config";
3656
- var VAL_THEME_SESSION_STORAGE_KEY = "val-theme";
3657
- var VAL_AI_SESSION_STORAGE_KEY = "val-ai-session";
3658
-
3659
3490
  var SharedValConfig = z.object({
3660
3491
  contentHostUrl: z.string().optional(),
3661
3492
  appHostUrl: z.string().optional(),
@@ -3683,170 +3514,6 @@ var ValDeployment = z.object({
3683
3514
  createdAt: z.string()
3684
3515
  });
3685
3516
 
3686
- // Strictly speaking this should be in the next package but it's shared, because we want to use it in the ui package. We want to resolve that somehow
3687
- function getNextAppRouterSitemapTree(srcFolder, paths) {
3688
- var root = {
3689
- type: "node",
3690
- name: "/",
3691
- children: []
3692
- };
3693
- var _iterator = _createForOfIteratorHelper(paths),
3694
- _step;
3695
- try {
3696
- var _loop = function _loop() {
3697
- var path = _step.value;
3698
- var urlPath = path.urlPath,
3699
- moduleFilePathS = path.moduleFilePath;
3700
- var moduleFilePath = moduleFilePathS;
3701
- if (!urlPath.startsWith("/")) {
3702
- console.error("urlPath must start with /: ".concat(urlPath));
3703
- return 0; // continue
3704
- }
3705
- var pattern = getPatternFromModuleFilePath(moduleFilePath, srcFolder);
3706
- if (urlPath === "/") {
3707
- var fullPath = "/";
3708
- root.pattern = getPatternFromModuleFilePath(moduleFilePath, srcFolder);
3709
- root.page = {
3710
- fullPath: fullPath
3711
- };
3712
- root.sourcePath = Internal.joinModuleFilePathAndModulePath(moduleFilePath, "\"".concat(fullPath, "\""));
3713
- root.moduleFilePath = moduleFilePath;
3714
- return 0; // continue
3715
- }
3716
- var pathParts = urlPath.split("/").slice(1).filter(Boolean);
3717
- var currentNode = root;
3718
- pathParts.forEach(function (part, index) {
3719
- var hasChildren = index < pathParts.length - 1;
3720
- var isLast = index === pathParts.length - 1;
3721
- var fullPath = "/" + pathParts.slice(0, index + 1).join("/");
3722
- var sourcePath = Internal.joinModuleFilePathAndModulePath(moduleFilePath, "\"".concat(fullPath, "\""));
3723
- var node = hasChildren ? _objectSpread2(_objectSpread2({
3724
- type: "node",
3725
- name: part,
3726
- pattern: pattern,
3727
- moduleFilePath: moduleFilePath
3728
- }, isLast ? {
3729
- page: {
3730
- fullPath: fullPath
3731
- },
3732
- sourcePath: sourcePath
3733
- } : {}), {}, {
3734
- children: []
3735
- }) : {
3736
- type: "leaf",
3737
- name: part,
3738
- pattern: pattern,
3739
- fullPath: fullPath,
3740
- moduleFilePath: moduleFilePath,
3741
- sourcePath: sourcePath,
3742
- children: []
3743
- };
3744
- var existingNodeIndex = currentNode.children.findIndex(function (node) {
3745
- return node.name === part;
3746
- });
3747
- if (existingNodeIndex === -1) {
3748
- currentNode.children.push(node);
3749
- if (currentNode.type === "node") {
3750
- currentNode.isLinear = true;
3751
- if (currentNode.children.length > 1) {
3752
- delete currentNode.isLinear;
3753
- }
3754
- }
3755
- currentNode = node;
3756
- } else {
3757
- var existingNode = currentNode.children[existingNodeIndex];
3758
- if (existingNode.type === "leaf" && hasChildren) {
3759
- var _sourcePath = existingNode.sourcePath;
3760
- // convert leaf to node
3761
- currentNode.children[existingNodeIndex] = {
3762
- type: "node",
3763
- name: part,
3764
- pattern: pattern,
3765
- page: {
3766
- fullPath: fullPath
3767
- },
3768
- sourcePath: _sourcePath,
3769
- children: existingNode.children,
3770
- moduleFilePath: moduleFilePath
3771
- };
3772
- currentNode = currentNode.children[existingNodeIndex];
3773
- } else if (existingNode.type === "node" && isLast) {
3774
- // add page, source path and module file path
3775
- existingNode.page = {
3776
- fullPath: fullPath
3777
- };
3778
- existingNode.sourcePath = sourcePath;
3779
- existingNode.moduleFilePath = moduleFilePath;
3780
- existingNode.pattern = pattern;
3781
- } else {
3782
- currentNode = currentNode.children[existingNodeIndex];
3783
- }
3784
- }
3785
- });
3786
- },
3787
- _ret;
3788
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
3789
- _ret = _loop();
3790
- if (_ret === 0) continue;
3791
- }
3792
- } catch (err) {
3793
- _iterator.e(err);
3794
- } finally {
3795
- _iterator.f();
3796
- }
3797
- return root;
3798
- }
3799
- function getPatternFromModuleFilePath(moduleFilePath, srcFolder) {
3800
- return moduleFilePath.replace(srcFolder, "")
3801
- // TODO: hacky!
3802
- // remove route groups
3803
- .replace(/\/\([^/]+\)/g, "") // not sure we want to do this?
3804
- .replace("/page.val.ts", "").replace("/page.val.js", "");
3805
- }
3806
-
3807
- function parseRoutePattern(pattern) {
3808
- if (pattern === "" || pattern === "/") {
3809
- return [];
3810
- }
3811
- var p = pattern.startsWith("/") ? pattern.slice(1) : pattern;
3812
- return p.split("/").map(function (part) {
3813
- var isOptionalParam = part.startsWith("[[") && part.endsWith("]]");
3814
- var isNonOptionalParam = part.startsWith("[") && part.endsWith("]");
3815
- var nameStart = isOptionalParam ? 2 : isNonOptionalParam ? 1 : 0;
3816
- var nameEnd = part.indexOf("]", nameStart);
3817
- var isArrayParam = part.slice(nameStart, nameStart + 3) === "...";
3818
- var paramName = part.slice(nameStart + (isArrayParam ? 3 : 0), nameEnd);
3819
- if (isOptionalParam || isNonOptionalParam) {
3820
- if (isArrayParam) {
3821
- return {
3822
- type: "array-param",
3823
- paramName: paramName,
3824
- optional: isOptionalParam
3825
- };
3826
- } else {
3827
- return {
3828
- type: "string-param",
3829
- paramName: paramName,
3830
- optional: isOptionalParam
3831
- };
3832
- }
3833
- }
3834
- return {
3835
- type: "literal",
3836
- name: part
3837
- };
3838
- });
3839
- }
3840
-
3841
- function getNextAppRouterSourceFolder(moduleFilePath) {
3842
- if (moduleFilePath.startsWith("/app")) {
3843
- return "/app";
3844
- } else if (moduleFilePath.startsWith("/src/app")) {
3845
- return "/src/app";
3846
- }
3847
- return null;
3848
- }
3849
-
3850
3517
  /**
3851
3518
  * Shared route validation utilities
3852
3519
  */
@@ -4328,84 +3995,6 @@ function resolveSchemaSourceFixes(validationErrors, snapshot) {
4328
3995
  return result;
4329
3996
  }
4330
3997
 
4331
- /**
4332
- * The protocol between the studio's canvas and the page inside it.
4333
- *
4334
- * The canvas shows the running site in a frame. That frame is a different
4335
- * document — the customer's app, rendered by their components — so the studio
4336
- * cannot reach into it, and it cannot reach out. Everything they say to each
4337
- * other goes through `postMessage`, and this is the vocabulary.
4338
- *
4339
- * It lives in `shared` because both halves have to agree on it: the page half
4340
- * ships in `@valbuild/next`, the studio half in `@valbuild/ui`, and a message
4341
- * shape defined twice is a message shape that will differ once.
4342
- *
4343
- * ## Why a query parameter turns it on
4344
- *
4345
- * The frame has to render the page as Val sees it — draft content, with
4346
- * `data-val-path` on every element Val tracks — while *not* showing Val's own
4347
- * overlay, because the studio is already the UI. Nothing about the cookies can
4348
- * express that: they are per-origin, and the studio and the page share an
4349
- * origin, so a cookie would change the customer's own tabs too. A parameter on
4350
- * the frame's URL is scoped to exactly the one document that needs it.
4351
- */
4352
-
4353
- /** Marks a page load as the studio's canvas frame. */
4354
- var VAL_CANVAS_PARAM = "val_canvas";
4355
-
4356
- /**
4357
- * Every message is tagged with this, and the tag is checked on receipt.
4358
- *
4359
- * A window receives messages from anything that has a handle on it —
4360
- * extensions, embeds, other frames — and `event.data` is whatever they chose to
4361
- * send. Checking a discriminator before reading anything else is what keeps a
4362
- * stray message from being read as a canvas instruction.
4363
- */
4364
- var VAL_CANVAS_MESSAGE = "val-canvas";
4365
-
4366
- /** One element on the page that Val has a path for. */
4367
-
4368
- /** What the page tells the studio. */
4369
-
4370
- /** What the studio tells the page. */
4371
-
4372
- /** Narrow an unknown `event.data` to a message from the page. */
4373
- function isValCanvasPageMessage(data) {
4374
- if (_typeof(data) !== "object" || data === null) return false;
4375
- var message = data;
4376
- if (message.val !== VAL_CANVAS_MESSAGE) return false;
4377
- return message.type === "ready" || message.type === "elements" || message.type === "clicked" || message.type === "pinch" || message.type === "zoom" || message.type === "refreshing";
4378
- }
4379
-
4380
- /** Narrow an unknown `event.data` to a message from the studio. */
4381
- function isValCanvasStudioMessage(data) {
4382
- if (_typeof(data) !== "object" || data === null) return false;
4383
- var message = data;
4384
- if (message.val !== VAL_CANVAS_MESSAGE) return false;
4385
- return message.type === "rescan" || message.type === "highlight" || message.type === "setPicking" || message.type === "sourceUpdate" || message.type === "sourcesSynced";
4386
- }
4387
-
4388
- /**
4389
- * Whether this document was loaded as the studio's canvas frame.
4390
- *
4391
- * Reads the location directly rather than taking it as an argument, because
4392
- * every caller wants the answer for the document it is running in, and passing
4393
- * it around is how one of them ends up asking about the wrong one.
4394
- */
4395
- function isValCanvasFrame(search) {
4396
- try {
4397
- return new URLSearchParams(search).get(VAL_CANVAS_PARAM) !== null;
4398
- } catch (_unused) {
4399
- return false;
4400
- }
4401
- }
4402
-
4403
- /** Add the canvas marker to a page URL. */
4404
- function withValCanvasParam(url) {
4405
- var separator = url.includes("?") ? "&" : "?";
4406
- return "".concat(url).concat(separator).concat(VAL_CANVAS_PARAM, "=1");
4407
- }
4408
-
4409
3998
  /**
4410
3999
  * Local `yyyy-MM-dd`, which is the one thing this module used `date-fns` for.
4411
4000
  *
@@ -5686,6 +5275,28 @@ function getRefParts(ref) {
5686
5275
  * them — an agent and an editor searching the same project should find the same
5687
5276
  * things.
5688
5277
  */
5278
+ /**
5279
+ * The parts of FlexSearch's `Index` this module uses.
5280
+ *
5281
+ * Structural, rather than importing flexsearch's own `Index`, because
5282
+ * {@link SearchIndex} is EXPORTED — and a `.d.ts` that names `flexsearch` pulls
5283
+ * that package's `declare module "flexsearch"` into every consumer's TypeScript
5284
+ * program. Ambient module declarations are global to a program, so a consumer
5285
+ * with its own flexsearch at another version then checks its OWN calls against
5286
+ * the copy we dragged in, whichever of the two wins.
5287
+ *
5288
+ * That is not hypothetical: `@valbuild/shared` gained a flexsearch dependency
5289
+ * in 0.123.0 for `search_content`, and valbuild/web — which pins flexsearch
5290
+ * 0.7 and calls `new flexsearch.Document({ language: "en", … })` — stopped
5291
+ * building on 0.123.2, because 0.8's `DocumentOptions` has no `language`. Its
5292
+ * own resolved copy was still 0.7; only the types had been replaced.
5293
+ *
5294
+ * Three methods is all this module calls, and none of their signatures here is
5295
+ * a guess: `add` and `remove` are used in `indexModule`/`removeModule`, and
5296
+ * `search`'s result is only ever `.length`-ed, `.slice`-d and mapped over as
5297
+ * ids. `FlexSearch.Index` is still constructed with the real library in
5298
+ * {@link createSearchIndex} — a value import, which does not reach the `.d.ts`.
5299
+ */
5689
5300
 
5690
5301
  /** An index with nothing in it. Fill it with {@link indexModule}. */
5691
5302
  function createSearchIndex() {
@@ -5787,9 +5398,9 @@ function removeModule(searchIndex, moduleFilePath) {
5787
5398
  _step;
5788
5399
  try {
5789
5400
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
5790
- var id = _step.value;
5791
- index.remove(id);
5792
- pathToLabel["delete"](id);
5401
+ var _id = _step.value;
5402
+ index.remove(_id);
5403
+ pathToLabel["delete"](_id);
5793
5404
  }
5794
5405
  } catch (err) {
5795
5406
  _iterator.e(err);
@@ -5871,4 +5482,4 @@ function performSearch(searchIndex, query) {
5871
5482
  };
5872
5483
  }
5873
5484
 
5874
- export { Api, 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, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, RestoreVerdict, RichTextOptions, SerializedArraySchema, SerializedBooleanSchema, SerializedCodeSchema, SerializedColorSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedFileSchema, SerializedImageSchema, SerializedKeyOfSchema, SerializedLiteralSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedRecordSchema, SerializedRichTextSchema, SerializedRouteSchema, SerializedSchema, SerializedSettingsSchema, SerializedStringSchema, SerializedUnionSchema, SharedValConfig, VAL_AI_SESSION_STORAGE_KEY, VAL_CANVAS_MESSAGE, VAL_CANVAS_PARAM, VAL_CONFIG_SESSION_STORAGE_KEY, VAL_ENABLE_COOKIE_NAME, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, VAL_THEME_SESSION_STORAGE_KEY, ValCommit, ValDeployment, buildDuplicatePatch, buildEmptyAtPathPatch, buildFileRefValue, buildImageGalleryPatch, buildRemoveImageGalleryEntryPatch, buildSearchIndex, checkCompatibility, chooseEncoded, concatModulePath, createRegExpFromPattern, createSearchIndex, createValClient, describeContainerAtPath, emptyOf, explainIncompatible, filterBlockingValidationErrors, filterRoutesByPatterns, findSimilar, fitWithin, flattenRichText, getErrorMessageFromUnknownJson, getFilenameFromRef, getInlineImgInfo, getNextAppRouterSitemapTree, getNextAppRouterSourceFolder, getPatternFromModuleFilePath, getRefParts, getRoutesOf, getRoutesWithModulePaths, getSourceAt, indexModule, isMimeTypeAccepted, isRemoteSchema, isSkippedSource, isValCanvasFrame, isValCanvasPageMessage, isValCanvasStudioMessage, levenshtein, newestCommitSha, parseRoutePattern, partitionValidationErrors, performSearch, remirrorToRichTextSource, removeModule, resolveEncodeSettings, resolveSchemaSourceFixForError, resolveSchemaSourceFixes, resolveSerializedSchemaAtPath, richTextToRemirror, safeParsePatch, sourcePathOfChild, toolNames, traverseSchemaSource, urlOf, validateRoutePatterns, withExtension, withValCanvasParam };
5485
+ export { Api, 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, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, RestoreVerdict, RichTextOptions, SerializedArraySchema, SerializedBooleanSchema, SerializedCodeSchema, SerializedColorSchema, SerializedDateSchema, SerializedDateTimeSchema, SerializedFileSchema, SerializedImageSchema, SerializedKeyOfSchema, SerializedLiteralSchema, SerializedNumberSchema, SerializedObjectSchema, SerializedRecordSchema, SerializedRichTextSchema, SerializedRouteSchema, SerializedSchema, SerializedSettingsSchema, SerializedStringSchema, SerializedUnionSchema, SharedValConfig, VAL_ENABLE_COOKIE_NAME, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, ValCommit, ValDeployment, buildDuplicatePatch, buildEmptyAtPathPatch, buildFileRefValue, buildImageGalleryPatch, buildRemoveImageGalleryEntryPatch, buildSearchIndex, checkCompatibility, chooseEncoded, concatModulePath, createRegExpFromPattern, createSearchIndex, createValClient, describeContainerAtPath, emptyOf, explainIncompatible, filterBlockingValidationErrors, filterRoutesByPatterns, findSimilar, fitWithin, flattenRichText, getErrorMessageFromUnknownJson, getFilenameFromRef, getInlineImgInfo, getRefParts, getRoutesOf, getRoutesWithModulePaths, getSourceAt, indexModule, isMimeTypeAccepted, isRemoteSchema, isSkippedSource, levenshtein, newestCommitSha, partitionValidationErrors, performSearch, remirrorToRichTextSource, removeModule, resolveEncodeSettings, resolveSchemaSourceFixForError, resolveSchemaSourceFixes, resolveSerializedSchemaAtPath, richTextToRemirror, safeParsePatch, sourcePathOfChild, toolNames, traverseSchemaSource, urlOf, validateRoutePatterns, withExtension };