@valbuild/shared 0.150.12 → 0.150.16
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 +31 -0
- package/client/dist/valbuild-shared-client.cjs.dev.js +2 -1
- package/client/dist/valbuild-shared-client.cjs.prod.js +2 -1
- package/client/dist/valbuild-shared-client.esm.js +1 -1
- package/dist/declarations/src/client/index.d.ts +1 -0
- package/dist/declarations/src/internal/ApiRoutes.d.ts +375 -94
- package/dist/declarations/src/internal/aiTools/toolNames.d.ts +1 -1
- package/dist/declarations/src/internal/index.d.ts +3 -0
- package/dist/declarations/src/internal/localeAt.d.ts +86 -1
- package/dist/declarations/src/internal/localeRelocation.d.ts +46 -0
- package/dist/declarations/src/internal/pageScreenshot.d.ts +40 -0
- package/dist/declarations/src/internal/server/types.d.ts +3 -3
- package/dist/declarations/src/internal/sketchpad/sketchFormat.d.ts +118 -0
- package/dist/declarations/src/internal/valCanvasProtocol.d.ts +21 -0
- package/dist/declarations/src/internal/zod/History.d.ts +7 -7
- package/dist/declarations/src/internal/zod/Patch.d.ts +1 -0
- package/dist/declarations/src/internal/zod/SerializedSchema.d.ts +20 -2
- package/dist/{getSitemapTree-97b3166f.esm.js → getSitemapTree-7c848c94.esm.js} +137 -2
- package/dist/{getSitemapTree-5354ce90.cjs.prod.js → getSitemapTree-97713490.cjs.prod.js} +155 -1
- package/dist/{getSitemapTree-d934ff9c.cjs.dev.js → getSitemapTree-98642b57.cjs.dev.js} +155 -1
- package/internal/dist/valbuild-shared-internal.cjs.dev.js +837 -15
- package/internal/dist/valbuild-shared-internal.cjs.prod.js +837 -15
- package/internal/dist/valbuild-shared-internal.esm.js +821 -17
- package/package.json +2 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { f as _createForOfIteratorHelper, d as _objectSpread2, e as _toConsumableArray, _ as _typeof, g as _defineProperty, b as _asyncToGenerator, c as _regenerator, a as _slicedToArray } from '../../dist/createForOfIteratorHelper-9b80f1a2.esm.js';
|
|
2
|
-
import { Internal, CODE_LANGUAGES, resolveSettingsModule, missingDeclaredKeys, localeOfValue,
|
|
2
|
+
import { Internal, CODE_LANGUAGES, resolveSettingsModule, missingDeclaredKeys, localeOfValue, routePatternOf, matchRoutePattern, discriminatedUnionBranchOf, DEFAULT_COLOR_FORMAT, declaredKeySetOf } from '@valbuild/core';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { _ as _objectWithoutProperties } from '../../dist/protocol-55cfa3cf.esm.js';
|
|
5
5
|
export { P as PublishProtocolError, b as parseArtifacts, p as parseBuildTarget, l as parseCancel, a as parseDeclare, m as parseDiscard, j as parseJob, n as parseNewestCiRun, h as parsePress, g as parseProblems, f as parseProjectSource, d as parsePromote, o as parsePublishToken, k as parseRenew, i as parseRequestStatus, e as parseStatus, q as parseUpdateTarget, c as parseVerify } from '../../dist/protocol-55cfa3cf.esm.js';
|
|
6
6
|
import { fromError } from 'zod-validation-error';
|
|
7
|
-
export { D as DEFAULT_CANVAS_SELECTION, e as DEFAULT_CANVAS_SELECTION_SOFT, Q as QUICK_PREVIEW_PARAM,
|
|
7
|
+
export { D as DEFAULT_CANVAS_SELECTION, e as DEFAULT_CANVAS_SELECTION_SOFT, Q as QUICK_PREVIEW_PARAM, u as QUICK_PREVIEW_SERVICE_WORKER_PATH, y as QUICK_PREVIEW_SERVICE_WORKER_SOURCE, v as QUICK_PREVIEW_STORE_MESSAGE, 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, j as attachElementPicker, k as createPickerOverlay, h as describeElement, l as elementLabel, q as findBySelector, F as formatRoutePattern, G as getNextAppRouterSourceFolder, K as getPageRouterSitemapTree, I as getPageRouterSourceFolder, L as getPatternFromModuleFilePath, H as getTanStackRouterSourceFolder, C as isDesignTabOrigin, x as isQuickPreviewFiles, J as isTanStackRoutesFolder, g as isValCanvasFrame, i as isValCanvasPageMessage, f as isValCanvasStudioMessage, m as modifierLabel, p as pageLocationOf, E as parseRoutePattern, B as quickPreviewSiteOrigin, o as readPageSnapshot, r as restoreScroll, t as screenshotPage, s as startElementPicking, z as storeQuickPreview, n as watchPageLocation, A as withQuickPreviewParam, w as withValCanvasParam } from '../../dist/getSitemapTree-7c848c94.esm.js';
|
|
8
8
|
import FlexSearch from 'flexsearch';
|
|
9
9
|
import { a as _createClass, c as _classCallCheck } from '../../dist/wrapNativeSuper-639b12b7.esm.js';
|
|
10
10
|
import { b as base64DataUrlToUint8Array } from '../../dist/utils-00f3e1df.esm.js';
|
|
@@ -1663,6 +1663,40 @@ var AnalyticsBeacon = z.object({
|
|
|
1663
1663
|
}, {
|
|
1664
1664
|
message: "At most ".concat(MAX_ANALYTICS_PATHS_PER_BEACON, " paths a beacon")
|
|
1665
1665
|
});
|
|
1666
|
+
/**
|
|
1667
|
+
* A Sketchpad, as the server keeps it: a rough page written in the strict
|
|
1668
|
+
* format of `sketchpad/sketchFormat.ts`, owned by the project and nothing
|
|
1669
|
+
* else. Not by an AI session -- the assistant that made it remembers its id,
|
|
1670
|
+
* and any chat can read it again -- and not by a page: `page` is a label for
|
|
1671
|
+
* which page it is about, and can be changed or cleared.
|
|
1672
|
+
*
|
|
1673
|
+
* `version` goes up by one on every change, and a change names the version
|
|
1674
|
+
* it was made against, so two writers cannot overwrite each other unseen.
|
|
1675
|
+
*/
|
|
1676
|
+
var Sketchpad = z.object({
|
|
1677
|
+
id: z.string(),
|
|
1678
|
+
page: z.string().nullable(),
|
|
1679
|
+
/** Its first heading, for a list to name it by. */
|
|
1680
|
+
title: z.string().nullable(),
|
|
1681
|
+
text: z.string(),
|
|
1682
|
+
version: z.number()["int"](),
|
|
1683
|
+
archived: z["boolean"](),
|
|
1684
|
+
createdAt: z.string(),
|
|
1685
|
+
updatedAt: z.string(),
|
|
1686
|
+
/** Profile ids; null where nobody was signed in (local dev, the demo). */
|
|
1687
|
+
createdBy: z.string().nullable(),
|
|
1688
|
+
updatedBy: z.string().nullable()
|
|
1689
|
+
});
|
|
1690
|
+
var SketchpadSummary = Sketchpad.omit({
|
|
1691
|
+
text: true
|
|
1692
|
+
});
|
|
1693
|
+
/** A line of a sketch the server would not take, and why. */
|
|
1694
|
+
var SketchErrorZ = z.object({
|
|
1695
|
+
line: z.number(),
|
|
1696
|
+
message: z.string()
|
|
1697
|
+
});
|
|
1698
|
+
/** The most text a sketchpad holds, in UTF-8 bytes: a page, not a site. */
|
|
1699
|
+
var SKETCHPAD_MAX_TEXT_LENGTH = 256 * 1024;
|
|
1666
1700
|
var Api = {
|
|
1667
1701
|
"/draft/enable": {
|
|
1668
1702
|
GET: {
|
|
@@ -2394,6 +2428,124 @@ var Api = {
|
|
|
2394
2428
|
})
|
|
2395
2429
|
}
|
|
2396
2430
|
},
|
|
2431
|
+
/**
|
|
2432
|
+
* The project's sketchpads: list them, or make one. See `Sketchpad`.
|
|
2433
|
+
* Making one answers with its id, which is what an assistant keeps to
|
|
2434
|
+
* read and change it later.
|
|
2435
|
+
*/
|
|
2436
|
+
"/sketchpads": {
|
|
2437
|
+
GET: {
|
|
2438
|
+
req: {
|
|
2439
|
+
query: {
|
|
2440
|
+
/** `exclude` (the default), `include`, or `only`. */
|
|
2441
|
+
archived: onlyOneStringQueryParam.optional(),
|
|
2442
|
+
/** Only those about this page. */
|
|
2443
|
+
page: onlyOneStringQueryParam.optional()
|
|
2444
|
+
},
|
|
2445
|
+
cookies: {
|
|
2446
|
+
val_session: z.string().optional()
|
|
2447
|
+
}
|
|
2448
|
+
},
|
|
2449
|
+
res: z.union([unauthorizedResponse, z.object({
|
|
2450
|
+
status: z.literal(400),
|
|
2451
|
+
json: GenericError
|
|
2452
|
+
}), z.object({
|
|
2453
|
+
status: z.literal(500),
|
|
2454
|
+
json: GenericError
|
|
2455
|
+
}), z.object({
|
|
2456
|
+
status: z.literal(200),
|
|
2457
|
+
json: z.object({
|
|
2458
|
+
sketchpads: z.array(SketchpadSummary)
|
|
2459
|
+
})
|
|
2460
|
+
})])
|
|
2461
|
+
},
|
|
2462
|
+
POST: {
|
|
2463
|
+
req: {
|
|
2464
|
+
body: z.object({
|
|
2465
|
+
text: z.string(),
|
|
2466
|
+
page: z.string().nullable()
|
|
2467
|
+
}),
|
|
2468
|
+
cookies: {
|
|
2469
|
+
val_session: z.string().optional()
|
|
2470
|
+
}
|
|
2471
|
+
},
|
|
2472
|
+
res: z.union([unauthorizedResponse, z.object({
|
|
2473
|
+
status: z.literal(400),
|
|
2474
|
+
json: z.object({
|
|
2475
|
+
message: z.string(),
|
|
2476
|
+
/** Lines of the text that are not in the sketch format. */
|
|
2477
|
+
errors: z.array(SketchErrorZ).optional()
|
|
2478
|
+
})
|
|
2479
|
+
}), z.object({
|
|
2480
|
+
status: z.literal(500),
|
|
2481
|
+
json: GenericError
|
|
2482
|
+
}), z.object({
|
|
2483
|
+
status: z.literal(201),
|
|
2484
|
+
json: z.object({
|
|
2485
|
+
sketchpad: Sketchpad
|
|
2486
|
+
})
|
|
2487
|
+
})])
|
|
2488
|
+
}
|
|
2489
|
+
},
|
|
2490
|
+
/** One sketchpad: read it, or change its text, its page or whether it is archived. */
|
|
2491
|
+
"/sketchpad": {
|
|
2492
|
+
GET: {
|
|
2493
|
+
req: {
|
|
2494
|
+
query: {
|
|
2495
|
+
id: onlyOneStringQueryParam
|
|
2496
|
+
},
|
|
2497
|
+
cookies: {
|
|
2498
|
+
val_session: z.string().optional()
|
|
2499
|
+
}
|
|
2500
|
+
},
|
|
2501
|
+
res: z.union([unauthorizedResponse, notFoundResponse, z.object({
|
|
2502
|
+
status: z.literal(500),
|
|
2503
|
+
json: GenericError
|
|
2504
|
+
}), z.object({
|
|
2505
|
+
status: z.literal(200),
|
|
2506
|
+
json: z.object({
|
|
2507
|
+
sketchpad: Sketchpad
|
|
2508
|
+
})
|
|
2509
|
+
})])
|
|
2510
|
+
},
|
|
2511
|
+
PATCH: {
|
|
2512
|
+
req: {
|
|
2513
|
+
body: z.object({
|
|
2514
|
+
id: z.string(),
|
|
2515
|
+
/** The version this change was made against. */
|
|
2516
|
+
baseVersion: z.number()["int"](),
|
|
2517
|
+
text: z.string().optional(),
|
|
2518
|
+
page: z.string().nullable().optional(),
|
|
2519
|
+
archived: z["boolean"]().optional()
|
|
2520
|
+
}),
|
|
2521
|
+
cookies: {
|
|
2522
|
+
val_session: z.string().optional()
|
|
2523
|
+
}
|
|
2524
|
+
},
|
|
2525
|
+
res: z.union([unauthorizedResponse, notFoundResponse, z.object({
|
|
2526
|
+
status: z.literal(400),
|
|
2527
|
+
json: z.object({
|
|
2528
|
+
message: z.string(),
|
|
2529
|
+
errors: z.array(SketchErrorZ).optional()
|
|
2530
|
+
})
|
|
2531
|
+
}), /** Changed since `baseVersion`: here is how it is now. */
|
|
2532
|
+
z.object({
|
|
2533
|
+
status: z.literal(409),
|
|
2534
|
+
json: z.object({
|
|
2535
|
+
message: z.string(),
|
|
2536
|
+
sketchpad: Sketchpad
|
|
2537
|
+
})
|
|
2538
|
+
}), z.object({
|
|
2539
|
+
status: z.literal(500),
|
|
2540
|
+
json: GenericError
|
|
2541
|
+
}), z.object({
|
|
2542
|
+
status: z.literal(200),
|
|
2543
|
+
json: z.object({
|
|
2544
|
+
sketchpad: Sketchpad
|
|
2545
|
+
})
|
|
2546
|
+
})])
|
|
2547
|
+
}
|
|
2548
|
+
},
|
|
2397
2549
|
"/upload/patches": {
|
|
2398
2550
|
POST: {
|
|
2399
2551
|
req: {
|
|
@@ -5363,6 +5515,7 @@ function resolveSchemaSourceFixes(validationErrors, snapshot) {
|
|
|
5363
5515
|
* in most projects, and for every project that has not declared any languages.
|
|
5364
5516
|
*/
|
|
5365
5517
|
function localeAt(path, snapshot) {
|
|
5518
|
+
var _localeScopeAt$locale, _localeScopeAt;
|
|
5366
5519
|
var available = declaredLocales(snapshot);
|
|
5367
5520
|
if (available.length === 0) {
|
|
5368
5521
|
// Nothing can be one of no languages. Answering `null` rather than reading
|
|
@@ -5371,18 +5524,66 @@ function localeAt(path, snapshot) {
|
|
|
5371
5524
|
return null;
|
|
5372
5525
|
}
|
|
5373
5526
|
var _Internal$splitModule = Internal.splitModuleFilePathAndModulePath(path),
|
|
5374
|
-
_Internal$splitModule2 = _slicedToArray(_Internal$splitModule,
|
|
5375
|
-
moduleFilePath = _Internal$splitModule2[0]
|
|
5376
|
-
modulePath = _Internal$splitModule2[1];
|
|
5527
|
+
_Internal$splitModule2 = _slicedToArray(_Internal$splitModule, 1),
|
|
5528
|
+
moduleFilePath = _Internal$splitModule2[0];
|
|
5377
5529
|
var schema = snapshot.schemas[moduleFilePath];
|
|
5378
5530
|
var source = snapshot.sources[moduleFilePath];
|
|
5379
5531
|
if (schema === undefined || source === undefined) {
|
|
5380
5532
|
return null;
|
|
5381
5533
|
}
|
|
5534
|
+
return (_localeScopeAt$locale = (_localeScopeAt = localeScopeAt(path, schema, source, available)) === null || _localeScopeAt === void 0 ? void 0 : _localeScopeAt.locale) !== null && _localeScopeAt$locale !== void 0 ? _localeScopeAt$locale : null;
|
|
5535
|
+
}
|
|
5536
|
+
|
|
5537
|
+
/**
|
|
5538
|
+
* Where the scope governing a path opens, and how.
|
|
5539
|
+
*
|
|
5540
|
+
* - `field`: the node `depth` segments down has a locale field. `depth` 0 is the
|
|
5541
|
+
* module root.
|
|
5542
|
+
* - `record-key`: segment `depth` is a key of a locale-keyed record, which sits
|
|
5543
|
+
* `depth` segments down.
|
|
5544
|
+
* - `route-key`: segment `depth` is a route whose parameters name the language,
|
|
5545
|
+
* in the router `depth` segments down (in practice the module root).
|
|
5546
|
+
*
|
|
5547
|
+
* The opener is what decides where an editor goes when the Studio's language
|
|
5548
|
+
* changes under them — the same entry in another language for a key, the
|
|
5549
|
+
* parent for a field. See `relocateForLocale`.
|
|
5550
|
+
*/
|
|
5551
|
+
|
|
5552
|
+
/**
|
|
5553
|
+
* The scope that governs a path, read from that module's schema and source
|
|
5554
|
+
* alone, or `null` where none does.
|
|
5555
|
+
*
|
|
5556
|
+
* {@link localeAt} for a caller that already has the module in hand — the
|
|
5557
|
+
* Studio, which has the project's languages from its own provider and would
|
|
5558
|
+
* otherwise have to assemble a snapshot of every module to ask about one.
|
|
5559
|
+
*/
|
|
5560
|
+
function localeScopeAt(path, schema, source, available) {
|
|
5561
|
+
if (available.length === 0) {
|
|
5562
|
+
return null;
|
|
5563
|
+
}
|
|
5564
|
+
var _Internal$splitModule3 = Internal.splitModuleFilePathAndModulePath(path),
|
|
5565
|
+
_Internal$splitModule4 = _slicedToArray(_Internal$splitModule3, 2),
|
|
5566
|
+
moduleFilePath = _Internal$splitModule4[0],
|
|
5567
|
+
modulePath = _Internal$splitModule4[1];
|
|
5382
5568
|
var segments = modulePath ? Internal.splitModulePath(modulePath) : [];
|
|
5383
5569
|
return walk(schema, source, segments, available, moduleFilePath);
|
|
5384
5570
|
}
|
|
5385
5571
|
|
|
5572
|
+
/**
|
|
5573
|
+
* The language a whole module is in: the one its root's locale field names, or
|
|
5574
|
+
* `null` where its root has none.
|
|
5575
|
+
*
|
|
5576
|
+
* The only way a module is in one language as a whole — a locale-keyed record
|
|
5577
|
+
* or a router at the root is every one of its languages at once. Needs no path,
|
|
5578
|
+
* so a list of modules can ask it of each.
|
|
5579
|
+
*/
|
|
5580
|
+
function localeOfModuleRoot(schema, source, available) {
|
|
5581
|
+
if (available.length === 0) {
|
|
5582
|
+
return null;
|
|
5583
|
+
}
|
|
5584
|
+
return enter(schema, source, available).locale;
|
|
5585
|
+
}
|
|
5586
|
+
|
|
5386
5587
|
/**
|
|
5387
5588
|
* The language a locale schema's value MEANS, or `null` if it means none of
|
|
5388
5589
|
* the project's.
|
|
@@ -5428,11 +5629,32 @@ function isLocaleSchema(schema) {
|
|
|
5428
5629
|
return schema.type === "locale" || schema.type === "enum" && schema.locales !== undefined;
|
|
5429
5630
|
}
|
|
5430
5631
|
|
|
5632
|
+
/**
|
|
5633
|
+
* Whether a router's URLs name the language each page is in — one of its route
|
|
5634
|
+
* parameters is a locale (`s.router(router, { locale: … }, item)`).
|
|
5635
|
+
*/
|
|
5636
|
+
function hasLocaleRouteParam(schema) {
|
|
5637
|
+
return schema.type === "record" && schema.params !== undefined && Object.values(schema.params).some(isLocaleSchema);
|
|
5638
|
+
}
|
|
5639
|
+
|
|
5431
5640
|
/**
|
|
5432
5641
|
* The language a router's key is in, where one of its route parameters is a
|
|
5433
5642
|
* locale — `/nb/blog/hei` is `nb-NO` when `locale` maps `nb` to it.
|
|
5643
|
+
*
|
|
5644
|
+
* Answered from the key alone, with no content read: which is what lets the
|
|
5645
|
+
* Studio's page tree filter every page of a site without loading one of them.
|
|
5434
5646
|
*/
|
|
5435
5647
|
function localeOfRouteKey(schema, moduleFilePath, key, available) {
|
|
5648
|
+
var param = localeParamOfRouteKey(schema, moduleFilePath, key);
|
|
5649
|
+
return param === null ? null : localeMeantBy(param.schema, param.value, available);
|
|
5650
|
+
}
|
|
5651
|
+
|
|
5652
|
+
/**
|
|
5653
|
+
* The route parameters a key gives its router, and which of them is the
|
|
5654
|
+
* language — or `null` where the router has no locale parameter or the key is
|
|
5655
|
+
* not one of its URLs.
|
|
5656
|
+
*/
|
|
5657
|
+
function localeParamOfRouteKey(schema, moduleFilePath, key) {
|
|
5436
5658
|
if (schema.params === undefined || schema.router === undefined) {
|
|
5437
5659
|
return null;
|
|
5438
5660
|
}
|
|
@@ -5449,7 +5671,12 @@ function localeOfRouteKey(schema, moduleFilePath, key, available) {
|
|
|
5449
5671
|
name = _Object$entries$_i[0],
|
|
5450
5672
|
param = _Object$entries$_i[1];
|
|
5451
5673
|
if (isLocaleSchema(param) && Object.prototype.hasOwnProperty.call(values, name)) {
|
|
5452
|
-
return
|
|
5674
|
+
return {
|
|
5675
|
+
name: name,
|
|
5676
|
+
schema: param,
|
|
5677
|
+
value: values[name],
|
|
5678
|
+
values: values
|
|
5679
|
+
};
|
|
5453
5680
|
}
|
|
5454
5681
|
}
|
|
5455
5682
|
return null;
|
|
@@ -5469,16 +5696,22 @@ function localeOfRouteKey(schema, moduleFilePath, key, available) {
|
|
|
5469
5696
|
*/
|
|
5470
5697
|
function walk(schema, source, segments, available, moduleFilePath) {
|
|
5471
5698
|
var entered = enter(schema, source, available);
|
|
5472
|
-
var
|
|
5699
|
+
var scope = entered.locale === null ? null : {
|
|
5700
|
+
kind: "field",
|
|
5701
|
+
locale: entered.locale,
|
|
5702
|
+
depth: 0
|
|
5703
|
+
};
|
|
5473
5704
|
var currentSchema = entered.schema;
|
|
5474
5705
|
var currentSource = source;
|
|
5475
|
-
var _iterator = _createForOfIteratorHelper(segments),
|
|
5706
|
+
var _iterator = _createForOfIteratorHelper(segments.entries()),
|
|
5476
5707
|
_step;
|
|
5477
5708
|
try {
|
|
5478
5709
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
5479
|
-
var
|
|
5710
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
5711
|
+
index = _step$value[0],
|
|
5712
|
+
segment = _step$value[1];
|
|
5480
5713
|
if (currentSchema === undefined) {
|
|
5481
|
-
return
|
|
5714
|
+
return scope;
|
|
5482
5715
|
}
|
|
5483
5716
|
if (currentSchema.type === "record") {
|
|
5484
5717
|
if (currentSchema.key !== undefined && isLocaleSchema(currentSchema.key)) {
|
|
@@ -5487,14 +5720,24 @@ function walk(schema, source, segments, available, moduleFilePath) {
|
|
|
5487
5720
|
// the tag it stands for when the key is an enum with `.locales()`.
|
|
5488
5721
|
var resolved = localeMeantBy(currentSchema.key, segment, available);
|
|
5489
5722
|
if (resolved !== null) {
|
|
5490
|
-
|
|
5723
|
+
scope = {
|
|
5724
|
+
kind: "record-key",
|
|
5725
|
+
locale: resolved,
|
|
5726
|
+
depth: index,
|
|
5727
|
+
keySchema: currentSchema.key
|
|
5728
|
+
};
|
|
5491
5729
|
}
|
|
5492
5730
|
} else if (currentSchema.params !== undefined) {
|
|
5493
5731
|
// A router whose URL names the language: the key is a URL, and one of
|
|
5494
5732
|
// its parameters is the answer.
|
|
5495
5733
|
var _resolved = localeOfRouteKey(currentSchema, moduleFilePath, segment, available);
|
|
5496
5734
|
if (_resolved !== null) {
|
|
5497
|
-
|
|
5735
|
+
scope = {
|
|
5736
|
+
kind: "route-key",
|
|
5737
|
+
locale: _resolved,
|
|
5738
|
+
depth: index,
|
|
5739
|
+
router: currentSchema
|
|
5740
|
+
};
|
|
5498
5741
|
}
|
|
5499
5742
|
}
|
|
5500
5743
|
currentSchema = currentSchema.item;
|
|
@@ -5504,13 +5747,17 @@ function walk(schema, source, segments, available, moduleFilePath) {
|
|
|
5504
5747
|
currentSchema = currentSchema.items[segment];
|
|
5505
5748
|
} else {
|
|
5506
5749
|
// A leaf, or richtext's internal structure. Nothing below opens a scope.
|
|
5507
|
-
return
|
|
5750
|
+
return scope;
|
|
5508
5751
|
}
|
|
5509
5752
|
currentSource = childSource(currentSource, segment);
|
|
5510
5753
|
entered = enter(currentSchema, currentSource, available);
|
|
5511
5754
|
currentSchema = entered.schema;
|
|
5512
5755
|
if (entered.locale !== null) {
|
|
5513
|
-
|
|
5756
|
+
scope = {
|
|
5757
|
+
kind: "field",
|
|
5758
|
+
locale: entered.locale,
|
|
5759
|
+
depth: index + 1
|
|
5760
|
+
};
|
|
5514
5761
|
}
|
|
5515
5762
|
}
|
|
5516
5763
|
} catch (err) {
|
|
@@ -5518,7 +5765,7 @@ function walk(schema, source, segments, available, moduleFilePath) {
|
|
|
5518
5765
|
} finally {
|
|
5519
5766
|
_iterator.f();
|
|
5520
5767
|
}
|
|
5521
|
-
return
|
|
5768
|
+
return scope;
|
|
5522
5769
|
}
|
|
5523
5770
|
|
|
5524
5771
|
/**
|
|
@@ -5608,6 +5855,187 @@ function isJsonObject(source) {
|
|
|
5608
5855
|
return _typeof(source) === "object" && source !== null && !Array.isArray(source);
|
|
5609
5856
|
}
|
|
5610
5857
|
|
|
5858
|
+
/**
|
|
5859
|
+
* Where an editor goes when the Studio's language changes under them.
|
|
5860
|
+
*
|
|
5861
|
+
* - `stay`: the path is in that language, or in none.
|
|
5862
|
+
* - `path`: the same entry in that language (`counterpart`), or the nearest
|
|
5863
|
+
* parent that is not in another language (`parent`).
|
|
5864
|
+
* - `home`: neither exists, so the editor goes to the Studio's start, with
|
|
5865
|
+
* nothing selected.
|
|
5866
|
+
*/
|
|
5867
|
+
|
|
5868
|
+
/**
|
|
5869
|
+
* Where to move a path to when the Studio is switched to `locale`.
|
|
5870
|
+
*
|
|
5871
|
+
* The rule, in the order it is tried:
|
|
5872
|
+
*
|
|
5873
|
+
* 1. **The same entry in `locale`, where Val KNOWS it.** That is two cases:
|
|
5874
|
+
* a locale-keyed record, where the counterpart of `"en-US"` is the
|
|
5875
|
+
* `"nb-NO"` key of the same record; and a router whose URLs name their
|
|
5876
|
+
* language, where `/about` and `/nb/about` differ only in it. Only a key
|
|
5877
|
+
* that exists is taken, and the rest of the path is kept as far as it
|
|
5878
|
+
* still exists, so an editor on a field lands on that field.
|
|
5879
|
+
* 2. **Otherwise the nearest parent that is not in another language.** An
|
|
5880
|
+
* English post in a list of posts gives the list, now showing Norwegian.
|
|
5881
|
+
* 3. **Otherwise the Studio's start**, which is `home`: nothing selected. That
|
|
5882
|
+
* is where an object at the module root opened the scope (the whole module
|
|
5883
|
+
* is in another language), and where the parent would be a router: a list
|
|
5884
|
+
* of pages is not a page, and the Pages tree is how an editor sees one.
|
|
5885
|
+
*
|
|
5886
|
+
* Not the site's root page, and not any other page: which language a page is
|
|
5887
|
+
* in is the page's own business, and `/` can be in the language the editor
|
|
5888
|
+
* just left. The start screen is in no language.
|
|
5889
|
+
*
|
|
5890
|
+
* Never a guess. Two pages whose URLs differ in more than the language — a
|
|
5891
|
+
* Norwegian slug for a Norwegian page — are not known to be translations of
|
|
5892
|
+
* each other, so that is `home` rather than whichever page looks closest.
|
|
5893
|
+
*/
|
|
5894
|
+
function relocateForLocale(path, locale, schema, source, available) {
|
|
5895
|
+
var scope = localeScopeAt(path, schema, source, available);
|
|
5896
|
+
if (scope === null || scope.locale === locale) {
|
|
5897
|
+
return {
|
|
5898
|
+
type: "stay"
|
|
5899
|
+
};
|
|
5900
|
+
}
|
|
5901
|
+
var _Internal$splitModule = Internal.splitModuleFilePathAndModulePath(path),
|
|
5902
|
+
_Internal$splitModule2 = _slicedToArray(_Internal$splitModule, 2),
|
|
5903
|
+
moduleFilePath = _Internal$splitModule2[0],
|
|
5904
|
+
modulePath = _Internal$splitModule2[1];
|
|
5905
|
+
var segments = modulePath ? Internal.splitModulePath(modulePath) : [];
|
|
5906
|
+
var at = function at(parts) {
|
|
5907
|
+
return Internal.joinModuleFilePathAndModulePath(moduleFilePath, Internal.patchPathToModulePath(parts));
|
|
5908
|
+
};
|
|
5909
|
+
var prefix = segments.slice(0, scope.depth);
|
|
5910
|
+
var rest = segments.slice(scope.depth + 1);
|
|
5911
|
+
if (scope.kind === "record-key") {
|
|
5912
|
+
var record = sourceAt(source, prefix);
|
|
5913
|
+
var key = isJsonObject(record) ? Object.keys(record).find(function (candidate) {
|
|
5914
|
+
return localeMeantBy(scope.keySchema, candidate, available) === locale;
|
|
5915
|
+
}) : undefined;
|
|
5916
|
+
if (key !== undefined) {
|
|
5917
|
+
return {
|
|
5918
|
+
type: "path",
|
|
5919
|
+
path: at(existingPart(source, [].concat(_toConsumableArray(prefix), [key]), rest)),
|
|
5920
|
+
reason: "counterpart"
|
|
5921
|
+
};
|
|
5922
|
+
}
|
|
5923
|
+
return {
|
|
5924
|
+
type: "path",
|
|
5925
|
+
path: at(prefix),
|
|
5926
|
+
reason: "parent"
|
|
5927
|
+
};
|
|
5928
|
+
}
|
|
5929
|
+
if (scope.kind === "route-key") {
|
|
5930
|
+
var router = sourceAt(source, prefix);
|
|
5931
|
+
var current = localeParamOfRouteKey(scope.router, moduleFilePath, segments[scope.depth]);
|
|
5932
|
+
if (isJsonObject(router) && current !== null) {
|
|
5933
|
+
var _key = Object.keys(router).find(function (candidate) {
|
|
5934
|
+
var other = localeParamOfRouteKey(scope.router, moduleFilePath, candidate);
|
|
5935
|
+
return other !== null && localeMeantBy(other.schema, other.value, available) === locale && sameRouteExcept(current.values, other.values, current.name);
|
|
5936
|
+
});
|
|
5937
|
+
if (_key !== undefined) {
|
|
5938
|
+
return {
|
|
5939
|
+
type: "path",
|
|
5940
|
+
path: at(existingPart(source, [].concat(_toConsumableArray(prefix), [_key]), rest)),
|
|
5941
|
+
reason: "counterpart"
|
|
5942
|
+
};
|
|
5943
|
+
}
|
|
5944
|
+
}
|
|
5945
|
+
return {
|
|
5946
|
+
type: "home"
|
|
5947
|
+
};
|
|
5948
|
+
}
|
|
5949
|
+
|
|
5950
|
+
// A locale FIELD opened the scope, on the node `depth` segments down.
|
|
5951
|
+
if (scope.depth === 0) {
|
|
5952
|
+
return {
|
|
5953
|
+
type: "home"
|
|
5954
|
+
};
|
|
5955
|
+
}
|
|
5956
|
+
var parent = segments.slice(0, scope.depth - 1);
|
|
5957
|
+
if (parent.length === 0 && schema.type === "record" && schema.router !== undefined) {
|
|
5958
|
+
return {
|
|
5959
|
+
type: "home"
|
|
5960
|
+
};
|
|
5961
|
+
}
|
|
5962
|
+
return {
|
|
5963
|
+
type: "path",
|
|
5964
|
+
path: at(parent),
|
|
5965
|
+
reason: "parent"
|
|
5966
|
+
};
|
|
5967
|
+
}
|
|
5968
|
+
|
|
5969
|
+
/** The source at `parts` below `source`, or `null` where it runs out. */
|
|
5970
|
+
function sourceAt(source, parts) {
|
|
5971
|
+
var current = source;
|
|
5972
|
+
var _iterator = _createForOfIteratorHelper(parts),
|
|
5973
|
+
_step;
|
|
5974
|
+
try {
|
|
5975
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
5976
|
+
var part = _step.value;
|
|
5977
|
+
current = childSource(current, part);
|
|
5978
|
+
}
|
|
5979
|
+
} catch (err) {
|
|
5980
|
+
_iterator.e(err);
|
|
5981
|
+
} finally {
|
|
5982
|
+
_iterator.f();
|
|
5983
|
+
}
|
|
5984
|
+
return current;
|
|
5985
|
+
}
|
|
5986
|
+
|
|
5987
|
+
/**
|
|
5988
|
+
* `base`, followed by as much of `rest` as the source still has.
|
|
5989
|
+
*
|
|
5990
|
+
* The counterpart of a field is the same field in the other language's entry,
|
|
5991
|
+
* but that entry can be `null` — declared and not yet written — or shorter (a
|
|
5992
|
+
* list with fewer items). Landing on the entry then is the right answer: it is
|
|
5993
|
+
* the translation the editor is about to write.
|
|
5994
|
+
*/
|
|
5995
|
+
function existingPart(source, base, rest) {
|
|
5996
|
+
var parts = _toConsumableArray(base);
|
|
5997
|
+
var current = sourceAt(source, base);
|
|
5998
|
+
var _iterator2 = _createForOfIteratorHelper(rest),
|
|
5999
|
+
_step2;
|
|
6000
|
+
try {
|
|
6001
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
6002
|
+
var part = _step2.value;
|
|
6003
|
+
var next = childSource(current, part);
|
|
6004
|
+
if (next === null) {
|
|
6005
|
+
break;
|
|
6006
|
+
}
|
|
6007
|
+
parts.push(part);
|
|
6008
|
+
current = next;
|
|
6009
|
+
}
|
|
6010
|
+
} catch (err) {
|
|
6011
|
+
_iterator2.e(err);
|
|
6012
|
+
} finally {
|
|
6013
|
+
_iterator2.f();
|
|
6014
|
+
}
|
|
6015
|
+
return parts;
|
|
6016
|
+
}
|
|
6017
|
+
|
|
6018
|
+
/** Whether two routes' parameters agree on everything but `ignore`. */
|
|
6019
|
+
function sameRouteExcept(a, b, ignore) {
|
|
6020
|
+
var names = new Set([].concat(_toConsumableArray(Object.keys(a)), _toConsumableArray(Object.keys(b))));
|
|
6021
|
+
var _iterator3 = _createForOfIteratorHelper(names),
|
|
6022
|
+
_step3;
|
|
6023
|
+
try {
|
|
6024
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
6025
|
+
var _a$name, _b$name;
|
|
6026
|
+
var name = _step3.value;
|
|
6027
|
+
if (name !== ignore && ((_a$name = a[name]) !== null && _a$name !== void 0 ? _a$name : null) !== ((_b$name = b[name]) !== null && _b$name !== void 0 ? _b$name : null)) {
|
|
6028
|
+
return false;
|
|
6029
|
+
}
|
|
6030
|
+
}
|
|
6031
|
+
} catch (err) {
|
|
6032
|
+
_iterator3.e(err);
|
|
6033
|
+
} finally {
|
|
6034
|
+
_iterator3.f();
|
|
6035
|
+
}
|
|
6036
|
+
return true;
|
|
6037
|
+
}
|
|
6038
|
+
|
|
5611
6039
|
/**
|
|
5612
6040
|
* Local `yyyy-MM-dd`, which is the one thing this module used `date-fns` for.
|
|
5613
6041
|
*
|
|
@@ -5785,7 +6213,383 @@ function emptyRecord(schema, context) {
|
|
|
5785
6213
|
}));
|
|
5786
6214
|
}
|
|
5787
6215
|
|
|
5788
|
-
var toolNames = ["get_all_schema", "get_source", "search_content", "validate_content", "create_patch", "add_session_image_to_gallery", "remove_image_gallery_entry", "navigate_to", "get_current_context", "get_patches", "get_source_path_from_route", "set_session_name", "show_compare_view", "ask_user_question", "duplicate_source", "empty_at_path", "count_entries", "get_record_keys"];
|
|
6216
|
+
var toolNames = ["get_all_schema", "get_source", "search_content", "validate_content", "create_patch", "add_session_image_to_gallery", "remove_image_gallery_entry", "navigate_to", "get_current_context", "get_patches", "get_source_path_from_route", "set_session_name", "show_compare_view", "ask_user_question", "duplicate_source", "empty_at_path", "count_entries", "get_record_keys", "list_sketchpads", "create_sketchpad", "read_sketchpad", "write_sketchpad"];
|
|
6217
|
+
|
|
6218
|
+
/**
|
|
6219
|
+
* A page sketch: a page written as indented text, with four primitives.
|
|
6220
|
+
*
|
|
6221
|
+
* ```
|
|
6222
|
+
* # Our people text (a heading: #, ## or ###)
|
|
6223
|
+
* We are 40 people in Oslo. text (a paragraph)
|
|
6224
|
+
* [image: Team photo] placeholder: [kind] or [kind: label]
|
|
6225
|
+
* [hero: Roof](image: /a.jpg) a placeholder with an image (or video) in it
|
|
6226
|
+
* icon hero M3 5h18v14H3z how every [hero] box is drawn: SVG path data
|
|
6227
|
+
* row its children side by side
|
|
6228
|
+
* col 2 its children stacked; 2 shares of the row
|
|
6229
|
+
* ## Design
|
|
6230
|
+
* col
|
|
6231
|
+
* [button: Join us]
|
|
6232
|
+
* ```
|
|
6233
|
+
*
|
|
6234
|
+
* It is a scratch pad, not a layout language: it says WHAT is on a page and
|
|
6235
|
+
* roughly WHERE, so an assistant and a person can agree on a page's content
|
|
6236
|
+
* before anyone worries about how it looks. The person never sees this text,
|
|
6237
|
+
* only the page it describes; the assistant never sees the page, only this.
|
|
6238
|
+
* So the two have to be the same thing, and the format is STRICT: there is
|
|
6239
|
+
* exactly one way to write what is on the screen. `checkSketch` is that
|
|
6240
|
+
* rule, and the server refuses a write that breaks it, with the line to fix.
|
|
6241
|
+
*
|
|
6242
|
+
* Parsing is still forgiving, so a sketch that breaks the rule shows what it
|
|
6243
|
+
* can rather than nothing; that is for reading, never for accepting.
|
|
6244
|
+
*
|
|
6245
|
+
* A placeholder's kind is any word, and nothing here knows what one means. The
|
|
6246
|
+
* assistant that writes the sketch also draws each kind's icon, as path data
|
|
6247
|
+
* in a 24 by 24 box, so a kind nobody thought of looks as deliberate as an
|
|
6248
|
+
* image. Media put in a box is written into the text too, so the assistant
|
|
6249
|
+
* that builds the page reads it exactly as the person left it.
|
|
6250
|
+
*/
|
|
6251
|
+
|
|
6252
|
+
var CONTAINER = /^(row|col)(?:\s+(\d+))?$/;
|
|
6253
|
+
var PLACEHOLDER = /^\[([^\]:]*)(?::([^\]]*))?\](?:\((image|video):\s*([^\s)]+)\s*\))?$/;
|
|
6254
|
+
var HAS_MEDIA = /^\[[^\]]*\]\(/;
|
|
6255
|
+
var ICON = /^icon\s+(\S+)\s+([Mm][\d\s.-].*)$/;
|
|
6256
|
+
var PATH_DATA = /^[Mm][MmLlHhVvCcSsQqTtAaZz\d\s.,-]*$/;
|
|
6257
|
+
var HEADING = /^(#{1,3})\s+(.*)$/;
|
|
6258
|
+
function parseSketch(source) {
|
|
6259
|
+
var blocks = [];
|
|
6260
|
+
var errors = [];
|
|
6261
|
+
var icons = {};
|
|
6262
|
+
// The containers that are open at the current line, innermost last.
|
|
6263
|
+
var stack = [{
|
|
6264
|
+
type: "page",
|
|
6265
|
+
indent: -1,
|
|
6266
|
+
children: blocks,
|
|
6267
|
+
lastIndent: null
|
|
6268
|
+
}];
|
|
6269
|
+
source.split(/\r?\n/).forEach(function (raw, index) {
|
|
6270
|
+
var line = index + 1;
|
|
6271
|
+
var expanded = raw.replace(/\t/g, " ");
|
|
6272
|
+
var content = expanded.trim();
|
|
6273
|
+
if (content === "") {
|
|
6274
|
+
return;
|
|
6275
|
+
}
|
|
6276
|
+
var indent = expanded.length - expanded.trimStart().length;
|
|
6277
|
+
|
|
6278
|
+
// An icon is not a block, so it can go anywhere and closes nothing.
|
|
6279
|
+
var icon = ICON.exec(content);
|
|
6280
|
+
if (icon) {
|
|
6281
|
+
var path = icon[2].trim();
|
|
6282
|
+
if (PATH_DATA.test(path)) {
|
|
6283
|
+
icons[icon[1].toLowerCase()] = path;
|
|
6284
|
+
} else {
|
|
6285
|
+
errors.push({
|
|
6286
|
+
line: line,
|
|
6287
|
+
message: 'An icon is SVG path data for a 24 by 24 box, like "icon stat M3 17l6-6 4 4 8-8". Only path commands and numbers are allowed.'
|
|
6288
|
+
});
|
|
6289
|
+
}
|
|
6290
|
+
return;
|
|
6291
|
+
}
|
|
6292
|
+
while (stack.length > 1 && indent <= stack[stack.length - 1].indent) {
|
|
6293
|
+
stack.pop();
|
|
6294
|
+
}
|
|
6295
|
+
var parent = stack[stack.length - 1];
|
|
6296
|
+
var node = parseContent(content, line, errors);
|
|
6297
|
+
|
|
6298
|
+
// Indented further than the block above it, and that block is not a
|
|
6299
|
+
// container. Keep it as that block's sibling rather than dropping it.
|
|
6300
|
+
if (parent.lastIndent !== null && indent > parent.lastIndent) {
|
|
6301
|
+
errors.push({
|
|
6302
|
+
line: line,
|
|
6303
|
+
message: "Only row and col can hold other blocks. Indent this as much as the line above it."
|
|
6304
|
+
});
|
|
6305
|
+
} else {
|
|
6306
|
+
parent.lastIndent = indent;
|
|
6307
|
+
}
|
|
6308
|
+
if (node.type === "col" && parent.type !== "row") {
|
|
6309
|
+
errors.push({
|
|
6310
|
+
line: line,
|
|
6311
|
+
message: "A col only goes directly inside a row."
|
|
6312
|
+
});
|
|
6313
|
+
}
|
|
6314
|
+
if (node.type === "row" && parent.type === "row") {
|
|
6315
|
+
errors.push({
|
|
6316
|
+
line: line,
|
|
6317
|
+
message: "A row goes in a col, not directly in another row."
|
|
6318
|
+
});
|
|
6319
|
+
}
|
|
6320
|
+
parent.children.push(node);
|
|
6321
|
+
if (node.type === "row" || node.type === "col") {
|
|
6322
|
+
stack.push({
|
|
6323
|
+
type: node.type,
|
|
6324
|
+
indent: indent,
|
|
6325
|
+
children: node.children,
|
|
6326
|
+
lastIndent: null
|
|
6327
|
+
});
|
|
6328
|
+
}
|
|
6329
|
+
});
|
|
6330
|
+
return {
|
|
6331
|
+
blocks: blocks,
|
|
6332
|
+
icons: icons,
|
|
6333
|
+
errors: errors
|
|
6334
|
+
};
|
|
6335
|
+
}
|
|
6336
|
+
function parseContent(content, line, errors) {
|
|
6337
|
+
// A leading backslash keeps a line that looks like a keyword as text.
|
|
6338
|
+
if (content.startsWith("\\")) {
|
|
6339
|
+
return {
|
|
6340
|
+
type: "text",
|
|
6341
|
+
line: line,
|
|
6342
|
+
level: 0,
|
|
6343
|
+
text: content.slice(1)
|
|
6344
|
+
};
|
|
6345
|
+
}
|
|
6346
|
+
var container = CONTAINER.exec(content);
|
|
6347
|
+
if (container) {
|
|
6348
|
+
if (container[1] === "row") {
|
|
6349
|
+
if (container[2] !== undefined) {
|
|
6350
|
+
errors.push({
|
|
6351
|
+
line: line,
|
|
6352
|
+
message: "A row takes no number. Put it on a col: \"col ".concat(container[2], "\".")
|
|
6353
|
+
});
|
|
6354
|
+
}
|
|
6355
|
+
return {
|
|
6356
|
+
type: "row",
|
|
6357
|
+
line: line,
|
|
6358
|
+
children: []
|
|
6359
|
+
};
|
|
6360
|
+
}
|
|
6361
|
+
var weight = container[2] === undefined ? 1 : Number(container[2]);
|
|
6362
|
+
if (weight === 0) {
|
|
6363
|
+
errors.push({
|
|
6364
|
+
line: line,
|
|
6365
|
+
message: "A col needs a weight of 1 or more."
|
|
6366
|
+
});
|
|
6367
|
+
}
|
|
6368
|
+
return {
|
|
6369
|
+
type: "col",
|
|
6370
|
+
line: line,
|
|
6371
|
+
weight: Math.max(weight, 1),
|
|
6372
|
+
children: []
|
|
6373
|
+
};
|
|
6374
|
+
}
|
|
6375
|
+
if (content.startsWith("[")) {
|
|
6376
|
+
var placeholder = PLACEHOLDER.exec(content);
|
|
6377
|
+
if (placeholder) {
|
|
6378
|
+
var _placeholder$;
|
|
6379
|
+
var kind = placeholder[1].trim();
|
|
6380
|
+
var label = (_placeholder$ = placeholder[2]) === null || _placeholder$ === void 0 ? void 0 : _placeholder$.trim();
|
|
6381
|
+
if (/\s/.test(kind)) {
|
|
6382
|
+
// An icon line names a kind by one word, so a kind has to be one.
|
|
6383
|
+
errors.push({
|
|
6384
|
+
line: line,
|
|
6385
|
+
message: "A box's kind is one word: \"[".concat(kind.replace(/\s+/g, "-")).concat(label ? ": ".concat(label) : "", "]\".")
|
|
6386
|
+
});
|
|
6387
|
+
}
|
|
6388
|
+
var mediaType = placeholder[3];
|
|
6389
|
+
return {
|
|
6390
|
+
type: "placeholder",
|
|
6391
|
+
line: line,
|
|
6392
|
+
kind: kind === "" ? "block" : kind,
|
|
6393
|
+
label: label ? label : null,
|
|
6394
|
+
media: mediaType === "image" || mediaType === "video" ? {
|
|
6395
|
+
type: mediaType,
|
|
6396
|
+
src: placeholder[4]
|
|
6397
|
+
} : null
|
|
6398
|
+
};
|
|
6399
|
+
}
|
|
6400
|
+
if (HAS_MEDIA.test(content)) {
|
|
6401
|
+
errors.push({
|
|
6402
|
+
line: line,
|
|
6403
|
+
message: 'Media in a box is written after it as (image: url) or (video: url), like "[hero: Team photo](image: /public/val/team.jpg)".'
|
|
6404
|
+
});
|
|
6405
|
+
return {
|
|
6406
|
+
type: "text",
|
|
6407
|
+
line: line,
|
|
6408
|
+
level: 0,
|
|
6409
|
+
text: content
|
|
6410
|
+
};
|
|
6411
|
+
}
|
|
6412
|
+
errors.push({
|
|
6413
|
+
line: line,
|
|
6414
|
+
message: 'A placeholder is written [kind] or [kind: label], on a line of its own, like "[image: Team photo]".'
|
|
6415
|
+
});
|
|
6416
|
+
return {
|
|
6417
|
+
type: "text",
|
|
6418
|
+
line: line,
|
|
6419
|
+
level: 0,
|
|
6420
|
+
text: content
|
|
6421
|
+
};
|
|
6422
|
+
}
|
|
6423
|
+
var heading = HEADING.exec(content);
|
|
6424
|
+
if (heading) {
|
|
6425
|
+
var level = heading[1].length === 1 ? 1 : heading[1].length === 2 ? 2 : 3;
|
|
6426
|
+
return {
|
|
6427
|
+
type: "text",
|
|
6428
|
+
line: line,
|
|
6429
|
+
level: level,
|
|
6430
|
+
text: heading[2]
|
|
6431
|
+
};
|
|
6432
|
+
}
|
|
6433
|
+
return {
|
|
6434
|
+
type: "text",
|
|
6435
|
+
line: line,
|
|
6436
|
+
level: 0,
|
|
6437
|
+
text: content
|
|
6438
|
+
};
|
|
6439
|
+
}
|
|
6440
|
+
|
|
6441
|
+
/**
|
|
6442
|
+
* The line a text block is written as. Line breaks become spaces, and a
|
|
6443
|
+
* paragraph that would read as something else is kept as text with `\`.
|
|
6444
|
+
*/
|
|
6445
|
+
function formatSketchText(level, text) {
|
|
6446
|
+
var flat = text.replace(/\s+/g, " ").trim();
|
|
6447
|
+
if (level > 0) {
|
|
6448
|
+
return "#".repeat(level) + " " + flat;
|
|
6449
|
+
}
|
|
6450
|
+
var ambiguous = flat.startsWith("\\") || flat.startsWith("[") || CONTAINER.test(flat) || HEADING.test(flat) || ICON.test(flat);
|
|
6451
|
+
return ambiguous ? "\\" + flat : flat;
|
|
6452
|
+
}
|
|
6453
|
+
|
|
6454
|
+
/** The line a placeholder is written as. */
|
|
6455
|
+
function formatSketchBox(placeholder) {
|
|
6456
|
+
var clean = function clean(text) {
|
|
6457
|
+
return text.replace(/[[\]]/g, "").replace(/\s+/g, " ").trim();
|
|
6458
|
+
};
|
|
6459
|
+
var kind = clean(placeholder.kind).replace(/:/g, "") || "block";
|
|
6460
|
+
var label = placeholder.label === null ? "" : clean(placeholder.label);
|
|
6461
|
+
var media = placeholder.media ? "(".concat(placeholder.media.type, ": ").concat(placeholder.media.src.replace(/[\s)]/g, encodeURIComponent), ")") : "";
|
|
6462
|
+
return "[".concat(kind).concat(label ? ": ".concat(label) : "", "]").concat(media);
|
|
6463
|
+
}
|
|
6464
|
+
|
|
6465
|
+
/**
|
|
6466
|
+
* The ONE way of writing `blocks` and `icons`: what `checkSketch` holds every
|
|
6467
|
+
* other text to, and what the Studio's editor writes (its own serializer is
|
|
6468
|
+
* tested against this one). Two spaces per level; an empty row gets an empty
|
|
6469
|
+
* col, so it has somewhere to type; a col outside a row is written as its
|
|
6470
|
+
* contents, which is all it shows; the icons last, after one blank line, and
|
|
6471
|
+
* no blank line anywhere else; a final newline. Empty text is not written --
|
|
6472
|
+
* it is not on the page.
|
|
6473
|
+
*/
|
|
6474
|
+
function formatSketch(blocks, icons) {
|
|
6475
|
+
var lines = [];
|
|
6476
|
+
var _walk = function walk(node, depth, inRow) {
|
|
6477
|
+
var indent = " ".repeat(depth);
|
|
6478
|
+
switch (node.type) {
|
|
6479
|
+
case "text":
|
|
6480
|
+
if (node.text) {
|
|
6481
|
+
lines.push(indent + formatSketchText(node.level, node.text));
|
|
6482
|
+
}
|
|
6483
|
+
return;
|
|
6484
|
+
case "placeholder":
|
|
6485
|
+
lines.push(indent + formatSketchBox(node));
|
|
6486
|
+
return;
|
|
6487
|
+
case "row":
|
|
6488
|
+
lines.push(indent + "row");
|
|
6489
|
+
if (node.children.length === 0) {
|
|
6490
|
+
lines.push(indent + " col");
|
|
6491
|
+
}
|
|
6492
|
+
node.children.forEach(function (child) {
|
|
6493
|
+
return _walk(child, depth + 1, true);
|
|
6494
|
+
});
|
|
6495
|
+
return;
|
|
6496
|
+
case "col":
|
|
6497
|
+
if (!inRow) {
|
|
6498
|
+
node.children.forEach(function (child) {
|
|
6499
|
+
return _walk(child, depth, false);
|
|
6500
|
+
});
|
|
6501
|
+
return;
|
|
6502
|
+
}
|
|
6503
|
+
lines.push(indent + (node.weight === 1 ? "col" : "col ".concat(node.weight)));
|
|
6504
|
+
node.children.forEach(function (child) {
|
|
6505
|
+
return _walk(child, depth + 1, false);
|
|
6506
|
+
});
|
|
6507
|
+
return;
|
|
6508
|
+
}
|
|
6509
|
+
};
|
|
6510
|
+
blocks.forEach(function (block) {
|
|
6511
|
+
return _walk(block, 0, false);
|
|
6512
|
+
});
|
|
6513
|
+
var iconLines = Object.entries(icons).map(function (_ref) {
|
|
6514
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
6515
|
+
kind = _ref2[0],
|
|
6516
|
+
path = _ref2[1];
|
|
6517
|
+
return "icon ".concat(kind, " ").concat(path);
|
|
6518
|
+
});
|
|
6519
|
+
var all = [].concat(lines, _toConsumableArray(iconLines.length > 0 ? [""].concat(_toConsumableArray(iconLines)) : []));
|
|
6520
|
+
return all.length > 0 ? all.join("\n") + "\n" : "";
|
|
6521
|
+
}
|
|
6522
|
+
|
|
6523
|
+
/**
|
|
6524
|
+
* What a list names a sketch by: its first top-level heading, the biggest
|
|
6525
|
+
* one first. Null for a sketch with no heading, which a list then names by
|
|
6526
|
+
* its page.
|
|
6527
|
+
*/
|
|
6528
|
+
function sketchTitle(blocks) {
|
|
6529
|
+
var _loop = function _loop() {
|
|
6530
|
+
var level = _arr[_i];
|
|
6531
|
+
var heading = blocks.find(function (block) {
|
|
6532
|
+
return block.type === "text" && block.level === level && block.text !== "";
|
|
6533
|
+
});
|
|
6534
|
+
if (heading) {
|
|
6535
|
+
return {
|
|
6536
|
+
v: heading.text
|
|
6537
|
+
};
|
|
6538
|
+
}
|
|
6539
|
+
},
|
|
6540
|
+
_ret;
|
|
6541
|
+
for (var _i = 0, _arr = [1, 2, 3]; _i < _arr.length; _i++) {
|
|
6542
|
+
_ret = _loop();
|
|
6543
|
+
if (_ret) return _ret.v;
|
|
6544
|
+
}
|
|
6545
|
+
return null;
|
|
6546
|
+
}
|
|
6547
|
+
|
|
6548
|
+
/**
|
|
6549
|
+
* Everything wrong with `source`, or nothing when it is a sketch exactly as
|
|
6550
|
+
* `formatSketch` writes it.
|
|
6551
|
+
*
|
|
6552
|
+
* Strict on purpose. The person sees the page and the assistant sees the
|
|
6553
|
+
* text, so a text with two spellings of one page -- a tab or two spaces, an
|
|
6554
|
+
* icon line here or there, a blank line or none -- is a text the assistant
|
|
6555
|
+
* cannot trust to be what is on the screen, and that would show it a change
|
|
6556
|
+
* nobody made the next time the Studio writes it back. Holding every write
|
|
6557
|
+
* to the one spelling rules all of that out at once.
|
|
6558
|
+
*
|
|
6559
|
+
* The parse errors come first; past those, the first line that is spelled
|
|
6560
|
+
* differently, with how it should be spelled.
|
|
6561
|
+
*/
|
|
6562
|
+
function checkSketch(source) {
|
|
6563
|
+
var _parseSketch = parseSketch(source),
|
|
6564
|
+
blocks = _parseSketch.blocks,
|
|
6565
|
+
icons = _parseSketch.icons,
|
|
6566
|
+
errors = _parseSketch.errors;
|
|
6567
|
+
if (errors.length > 0) {
|
|
6568
|
+
return errors;
|
|
6569
|
+
}
|
|
6570
|
+
var canonical = formatSketch(blocks, icons);
|
|
6571
|
+
if (canonical === source) {
|
|
6572
|
+
return [];
|
|
6573
|
+
}
|
|
6574
|
+
if (canonical !== "" && !source.endsWith("\n")) {
|
|
6575
|
+
return [{
|
|
6576
|
+
line: source.split("\n").length,
|
|
6577
|
+
message: "A sketch ends with a newline."
|
|
6578
|
+
}];
|
|
6579
|
+
}
|
|
6580
|
+
// Compared without the final newline, so an extra one is an extra line.
|
|
6581
|
+
var given = source.slice(0, -1).split("\n");
|
|
6582
|
+
var wanted = canonical.slice(0, -1).split("\n");
|
|
6583
|
+
for (var i = 0; i < Math.max(given.length, wanted.length); i++) {
|
|
6584
|
+
if (given[i] !== wanted[i]) {
|
|
6585
|
+
return [{
|
|
6586
|
+
line: i + 1,
|
|
6587
|
+
message: wanted[i] === undefined ? "Nothing goes here: the sketch ends on the line before." : given[i] === "" ? "No blank lines: the one blank line in a sketch is before its icons." : given[i] === undefined ? "The sketch goes on: \"".concat(wanted[i], "\".") : "This line is written ".concat(JSON.stringify(wanted[i]), " in a sketch: two spaces per level, the icons last after one blank line, and no other blank lines.")
|
|
6588
|
+
}];
|
|
6589
|
+
}
|
|
6590
|
+
}
|
|
6591
|
+
return [];
|
|
6592
|
+
}
|
|
5789
6593
|
|
|
5790
6594
|
function buildFileRefValue(filePath, metadata) {
|
|
5791
6595
|
return _objectSpread2({
|
|
@@ -8726,4 +9530,4 @@ var messageOf = function messageOf(error) {
|
|
|
8726
9530
|
return error instanceof Error ? error.message : String(error);
|
|
8727
9531
|
};
|
|
8728
9532
|
|
|
8729
|
-
export { AA_LARGE, AA_TEXT, AIToolCallSummaries, AnalyticsBeacon, 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, LOCAL_FILE_IN_REMOTE_PROJECT_HINT, LOCAL_FILE_IN_REMOTE_PROJECT_WARNING, ModuleComparison, NEVER_ENCODED, ParentRef$1 as ParentRef, Patch, PatchBlock, PatchId, PatchJSON, PatchSets, PlanRefusalError, RAMP_STEPS, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, RestoreVerdict, RichTextOptions, SCHEMA_SOURCE_FIXES, SELF_CHECK_VERSION, STUDIO_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, WARNING_FIXES, WASM_ENCODED_MIME_TYPES, accentRamp, buildDuplicatePatch, buildEmptyAtPathPatch, buildFileRefValue, buildImageGalleryPatch, buildRemoveImageGalleryEntryPatch, buildSearchIndex, chainHeadOf, checkCompatibility, chooseEncoded, concatModulePath, contrastRatio, createRegExpFromPattern, createSearchIndex, createValClient, declaredLocales, describeContainerAtPath, emptyOf, enumLocaleTag, explainIncompatible, fallbackMimeType, filterBlockingValidationErrors, filterRoutesByPatterns, findSimilar, fitWithin, flattenRichText, forEachRichTextImage, getErrorMessageFromUnknownJson, getFilenameFromRef, getInlineImgInfo, getKeyOfRecordAt, getRefParts, getRoutesOf, getRoutesWithModulePaths, getSourceAt, getValDemo, indexModule, isInsidePatchSetPath, isLocaleSchema, isMimeTypeAccepted, isRemoteSchema, isRepairedOnSave, isSchemaSourceFixError, isSkippedSource, isStudioFix, isValidationWarning, isWarningFix, joinSharedChanges, keyOfRecordPath, levenshtein, localeAt, localeMeantBy, memoizePerRequest, newestCommitSha, partitionValidationErrors, performSearch, proposalCustomProperties, relativeLuminance, remirrorToRichTextSource, removeModule, resolveEncodeSettings, resolvePairGround, resolveSchemaSourceFixForError, resolveSchemaSourceFixes, resolveSerializedSchemaAtPath, richTextImageSchema, richTextToRemirror, safeParsePatch, schemaErrorsOf, schemaTypesOfPath, selectionClosure, selfCheck, shouldEncodeWithWasm, sideFiles, sideSource, sourcePathOfChild, themeCustomProperties, toolNames, traverseSchemaSource, urlOf, validateRoutePatterns, withExtension };
|
|
9533
|
+
export { AA_LARGE, AA_TEXT, AIToolCallSummaries, AnalyticsBeacon, 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, LOCAL_FILE_IN_REMOTE_PROJECT_HINT, LOCAL_FILE_IN_REMOTE_PROJECT_WARNING, ModuleComparison, NEVER_ENCODED, ParentRef$1 as ParentRef, Patch, PatchBlock, PatchId, PatchJSON, PatchSets, PlanRefusalError, RAMP_STEPS, RemirrorBr, RemirrorBulletList, RemirrorHeading, RemirrorImage, RemirrorJSON, RemirrorLinkMark, RemirrorListItem, RemirrorOrderedList, RemirrorParagraph, RemirrorText, RemirrorTextMark, RestoreVerdict, RichTextOptions, SCHEMA_SOURCE_FIXES, SELF_CHECK_VERSION, SKETCHPAD_MAX_TEXT_LENGTH, STUDIO_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, Sketchpad, SketchpadSummary, VAL_ENABLE_COOKIE_NAME, VAL_GREEN_RAMP, VAL_SESSION_COOKIE, VAL_STATE_COOKIE, VAL_STUDIO_HEADER, ValCommit, ValDeployment, VideoOptions, VideoStreamOption, WARNING_FIXES, WASM_ENCODED_MIME_TYPES, accentRamp, buildDuplicatePatch, buildEmptyAtPathPatch, buildFileRefValue, buildImageGalleryPatch, buildRemoveImageGalleryEntryPatch, buildSearchIndex, chainHeadOf, checkCompatibility, checkSketch, childSource, chooseEncoded, concatModulePath, contrastRatio, createRegExpFromPattern, createSearchIndex, createValClient, declaredLocales, describeContainerAtPath, emptyOf, enumLocaleTag, explainIncompatible, fallbackMimeType, filterBlockingValidationErrors, filterRoutesByPatterns, findSimilar, fitWithin, flattenRichText, forEachRichTextImage, formatSketch, formatSketchBox, formatSketchText, getErrorMessageFromUnknownJson, getFilenameFromRef, getInlineImgInfo, getKeyOfRecordAt, getRefParts, getRoutesOf, getRoutesWithModulePaths, getSourceAt, getValDemo, hasLocaleRouteParam, indexModule, isInsidePatchSetPath, isJsonObject, isLocaleSchema, isMimeTypeAccepted, isRemoteSchema, isRepairedOnSave, isSchemaSourceFixError, isSkippedSource, isStudioFix, isValidationWarning, isWarningFix, joinSharedChanges, keyOfRecordPath, levenshtein, localeAt, localeMeantBy, localeOfModuleRoot, localeOfRouteKey, localeParamOfRouteKey, localeScopeAt, memoizePerRequest, newestCommitSha, parseSketch, partitionValidationErrors, performSearch, proposalCustomProperties, relativeLuminance, relocateForLocale, remirrorToRichTextSource, removeModule, resolveEncodeSettings, resolvePairGround, resolveSchemaSourceFixForError, resolveSchemaSourceFixes, resolveSerializedSchemaAtPath, richTextImageSchema, richTextToRemirror, safeParsePatch, schemaErrorsOf, schemaTypesOfPath, selectionClosure, selfCheck, shouldEncodeWithWasm, sideFiles, sideSource, sketchTitle, sourcePathOfChild, themeCustomProperties, toolNames, traverseSchemaSource, urlOf, validateRoutePatterns, withExtension };
|