@astryxdesign/cli 0.7.15-canary.gf890983 → 0.7.15
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 +353 -3
- package/api/doctor/_adapter.d.mts +2 -1
- package/api/doctor/_adapter.mjs +6 -1
- package/api/doctor/doctor.mjs +2 -2
- package/api/doctor/theme-checks.mjs +56 -21
- package/api/integration/add-helpers.mjs +5 -0
- package/api/integration/add-theme.mjs +15 -110
- package/api/theme/_adapter.d.mts +37 -5
- package/api/theme/_adapter.mjs +363 -50
- package/api/theme/_fork.d.mts +90 -0
- package/api/theme/_fork.mjs +246 -0
- package/api/theme/build/build.d.mts +25 -1
- package/api/theme/build/build.mjs +352 -41
- package/api/theme/eject/eject.mjs +36 -15
- package/api/theme/list/list.mjs +3 -6
- package/api/theme/palette/generate/generator.d.mts +13 -0
- package/api/theme/palette/generate/generator.mjs +32 -2
- package/api/theme/targets/targets.mjs +10 -3
- package/api/theme/template/template.mjs +48 -2
- package/api/theme/theme.type.d.mts +8 -0
- package/api/theme/theme.type.mjs +5 -1
- package/api/theme/themeBuild.doc.mjs +2 -2
- package/api/theme/themeRemove.doc.mjs +5 -2
- package/api/theme/themeTemplate.doc.mjs +2 -2
- package/api/theme/themeUse.doc.mjs +8 -2
- package/api/theme-edit/_adapter.mjs +157 -36
- package/api/theme-edit/_catalog.d.mts +1 -6
- package/api/theme-edit/_catalog.mjs +5 -268
- package/api/theme-edit/_check.d.mts +3 -1
- package/api/theme-edit/_check.mjs +733 -308
- package/api/theme-edit/_color.d.mts +19 -0
- package/api/theme-edit/_color.mjs +277 -33
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +25 -0
- package/api/theme-edit/_context.d.mts +2 -0
- package/api/theme-edit/_context.mjs +83 -9
- package/api/theme-edit/_css.d.mts +84 -0
- package/api/theme-edit/_css.mjs +700 -0
- package/api/theme-edit/_edit.mjs +370 -85
- package/api/theme-edit/_how-commands.d.mts +5 -0
- package/api/theme-edit/_how-commands.mjs +20 -13
- package/api/theme-edit/_how-question.d.mts +29 -0
- package/api/theme-edit/_how-question.mjs +1573 -182
- package/api/theme-edit/_how.mjs +306 -22
- package/api/theme-edit/_overview.mjs +2 -7
- package/api/theme-edit/_palette.d.mts +27 -5
- package/api/theme-edit/_palette.mjs +231 -97
- package/api/theme-edit/_parts.d.mts +42 -10
- package/api/theme-edit/_parts.mjs +224 -69
- package/api/theme-edit/_preview-app.d.mts +8 -0
- package/api/theme-edit/_preview-app.mjs +549 -96
- package/api/theme-edit/_preview.d.mts +7 -16
- package/api/theme-edit/_preview.mjs +77 -84
- package/api/theme-edit/_project.d.mts +20 -1
- package/api/theme-edit/_project.mjs +43 -13
- package/api/theme-edit/_settings.d.mts +96 -20
- package/api/theme-edit/_settings.mjs +646 -141
- package/api/theme-edit/_tables.d.mts +18 -12
- package/api/theme-edit/_tables.mjs +144 -147
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +3 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
- package/api/theme-edit/themeEditSet.doc.mjs +1 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/assets/docs/tree/publishing.doc.mjs +1 -0
- package/assets/docs.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/experimental/index.mjs +10 -10
- package/clients/cli/commands/experimental/theme.mjs +22 -3
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/integration.mjs +8 -0
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +325 -48
- package/clients/cli/index.mjs +18 -3
- package/clients/cli/lib/cli-error.mjs +118 -3
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/config/project.mjs +34 -8
- package/foundation/config/theme-state.d.mts +16 -0
- package/foundation/config/theme-state.mjs +84 -13
- package/foundation/discovery/template-needs.d.mts +13 -0
- package/foundation/discovery/template-needs.mjs +30 -15
- package/foundation/discovery/theme-discovery.mjs +14 -2
- package/foundation/discovery/theme-imports.d.mts +16 -0
- package/foundation/discovery/theme-imports.mjs +30 -2
- package/foundation/doc-compiler/import.mjs +10 -4
- package/foundation/fs/gather-cache.mjs +82 -23
- package/foundation/fs/jiti-cache.d.mts +21 -0
- package/foundation/fs/jiti-cache.mjs +66 -0
- package/foundation/fs/module-loader.mjs +7 -2
- package/foundation/integrations/autolink.d.mts +1 -24
- package/foundation/integrations/autolink.mjs +7 -60
- package/foundation/integrations/declared-dependencies.d.mts +27 -0
- package/foundation/integrations/declared-dependencies.mjs +73 -0
- package/foundation/integrations/may-have-integrations.d.mts +8 -0
- package/foundation/integrations/may-have-integrations.mjs +47 -0
- package/foundation/release/cache.d.mts +21 -2
- package/foundation/release/cache.mjs +48 -8
- package/foundation/release/folder-lock.d.mts +7 -0
- package/foundation/release/folder-lock.mjs +60 -26
- package/foundation/release/lock-lease.d.mts +2 -1
- package/foundation/release/lock-lease.mjs +7 -2
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +4 -4
- package/package.json +6 -6
- package/api/theme-edit/_css-properties.d.mts +0 -10
- package/api/theme-edit/_css-properties.mjs +0 -556
|
@@ -45,8 +45,13 @@ import {
|
|
|
45
45
|
} from '../../foundation/fs/paths.mjs';
|
|
46
46
|
import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
|
|
47
47
|
import {withFolderLock} from '../../foundation/release/folder-lock.mjs';
|
|
48
|
-
import {
|
|
49
|
-
|
|
48
|
+
import {
|
|
49
|
+
getCliInvocation,
|
|
50
|
+
quoteCommandArgument,
|
|
51
|
+
} from '../../foundation/env/package-manager.mjs';
|
|
52
|
+
import {LIKE, P} from './_tables.mjs';
|
|
53
|
+
import {camel} from './_settings.mjs';
|
|
54
|
+
import {LOCAL_THEME_ROOT} from '../../foundation/config/theme-state.mjs';
|
|
50
55
|
|
|
51
56
|
export {parsePoints} from './_how.mjs';
|
|
52
57
|
import {themeEditHow as howAt} from './_how.mjs';
|
|
@@ -110,7 +115,12 @@ export function projectRoot(cwd) {
|
|
|
110
115
|
} catch {
|
|
111
116
|
throw new AstryxError(
|
|
112
117
|
`${path.relative(start, file) || 'package.json'} is not valid JSON, so the app it belongs to is unknown. Fix it, then run the command again. Nothing was written.`,
|
|
113
|
-
[
|
|
118
|
+
[
|
|
119
|
+
{
|
|
120
|
+
name: runLine(start, 'doctor'),
|
|
121
|
+
reason: 'names the file and what is wrong in it',
|
|
122
|
+
},
|
|
123
|
+
],
|
|
114
124
|
ERROR_CODES.ERR_PROJECT_REQUIRED,
|
|
115
125
|
);
|
|
116
126
|
}
|
|
@@ -160,7 +170,12 @@ function lockDir(root) {
|
|
|
160
170
|
} catch (e) {
|
|
161
171
|
throw new AstryxError(
|
|
162
172
|
`Could not write ${path.relative(root, dir)} (${/** @type {any} */ (e).code ?? String(e)}), where the lock that keeps two commands on one theme apart is kept. Fix its permission, then run the command again. Nothing was changed.`,
|
|
163
|
-
[
|
|
173
|
+
[
|
|
174
|
+
{
|
|
175
|
+
name: `ls -ld ${quoteCommandArgument(dir)}`,
|
|
176
|
+
reason: 'see who owns the lock folder',
|
|
177
|
+
},
|
|
178
|
+
],
|
|
164
179
|
ERROR_CODES.ERR_WRITE_FAILED,
|
|
165
180
|
);
|
|
166
181
|
}
|
|
@@ -225,7 +240,15 @@ async function withLock(root, name, fn, bestEffort = false) {
|
|
|
225
240
|
onBusy: (o, held) => {
|
|
226
241
|
throw new AstryxError(
|
|
227
242
|
`Another command has been changing ${name.replace(/^theme-/, '')} for 30 seconds${o ? ` (process ${o.pid} on ${o.host}${held != null ? `, holding it ${held} s` : ''})` : ''}. Nothing was changed; run this command again. If no astryx command is running, the lock is left from one that stopped: remove the folder ${lock}.`,
|
|
228
|
-
|
|
243
|
+
// A look that takes no lock: the last build as it is.
|
|
244
|
+
[
|
|
245
|
+
{
|
|
246
|
+
name: name.startsWith('theme-')
|
|
247
|
+
? `${P} show ${name.replace(/^theme-/, '')}`
|
|
248
|
+
: 'astryx experimental theme preview list',
|
|
249
|
+
reason: 'see it as it is now',
|
|
250
|
+
},
|
|
251
|
+
],
|
|
229
252
|
ERROR_CODES.ERR_THEME_BUSY,
|
|
230
253
|
);
|
|
231
254
|
},
|
|
@@ -238,7 +261,12 @@ async function withLock(root, name, fn, bestEffort = false) {
|
|
|
238
261
|
if (bestEffort) return fn(false);
|
|
239
262
|
throw new AstryxError(
|
|
240
263
|
`Could not take the lock ${lock} (${code ?? String(e)}). Nothing was changed; fix the folder, then run the command again.`,
|
|
241
|
-
[
|
|
264
|
+
[
|
|
265
|
+
{
|
|
266
|
+
name: `ls -ld ${quoteCommandArgument(path.dirname(lock))}`,
|
|
267
|
+
reason: 'see who owns the lock folder',
|
|
268
|
+
},
|
|
269
|
+
],
|
|
242
270
|
ERROR_CODES.ERR_WRITE_FAILED,
|
|
243
271
|
);
|
|
244
272
|
}
|
|
@@ -247,7 +275,12 @@ async function withLock(root, name, fn, bestEffort = false) {
|
|
|
247
275
|
if (['EACCES', 'EPERM', 'ENOSPC', 'EROFS', 'EIO'].includes(code))
|
|
248
276
|
throw new AstryxError(
|
|
249
277
|
`Could not write ${path.relative(root, /** @type {any} */ (e).path ?? '') || 'the theme files'}: ${code === 'ENOSPC' ? 'the disk is full' : code === 'EROFS' ? 'the disk is read-only' : code === 'EIO' ? 'the disk could not be read or written' : 'no permission'}. ${code === 'EROFS' ? 'Make the folder writable' : code === 'EIO' ? 'Check the disk' : 'Free the space or fix the permission'}, then run the command again; a refused change is undone.`,
|
|
250
|
-
[
|
|
278
|
+
[
|
|
279
|
+
{
|
|
280
|
+
name: `ls -ld ${quoteCommandArgument(path.dirname(/** @type {any} */ (e).path ?? path.join(root, 'themes', 'x')))}`,
|
|
281
|
+
reason: 'see who owns the folder and whether it is writable',
|
|
282
|
+
},
|
|
283
|
+
],
|
|
251
284
|
ERROR_CODES.ERR_WRITE_FAILED,
|
|
252
285
|
);
|
|
253
286
|
throw e;
|
|
@@ -451,20 +484,82 @@ export const themeEditPreviewRemove = (page, options = {}) =>
|
|
|
451
484
|
);
|
|
452
485
|
|
|
453
486
|
/**
|
|
454
|
-
* The
|
|
455
|
-
*
|
|
487
|
+
* The editor theme a path or a name names, with its project, or null: a
|
|
488
|
+
* name is a theme in `root`'s themes/ folder; a path is one in the themes/
|
|
489
|
+
* folder of the project the file belongs to (found from the file, so a
|
|
490
|
+
* path from another folder still names it, and a `src/themes/<slug>` fork
|
|
491
|
+
* does not).
|
|
456
492
|
* @param {string} root
|
|
457
493
|
* @param {string} word a path or a name
|
|
494
|
+
* @returns {{root: string, slug: string} | null}
|
|
458
495
|
*/
|
|
459
|
-
function
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
496
|
+
function editorThemeAt(root, word) {
|
|
497
|
+
const has = (/** @type {string} */ r, /** @type {string} */ slug) =>
|
|
498
|
+
fs.existsSync(path.join(r, 'themes', slug, `${slug}.settings.json`));
|
|
499
|
+
if (/^[a-z][a-z0-9-]*$/.test(word))
|
|
500
|
+
return has(root, word) ? {root, slug: word} : null;
|
|
501
|
+
// Through a link, the real path decides (a linked theme folder is the
|
|
502
|
+
// same folder).
|
|
503
|
+
/** @type {string} */
|
|
504
|
+
let abs = path.resolve(root, word);
|
|
505
|
+
try {
|
|
506
|
+
abs = fs.realpathSync(abs);
|
|
507
|
+
} catch {
|
|
508
|
+
try {
|
|
509
|
+
abs = path.join(fs.realpathSync(path.dirname(abs)), path.basename(abs));
|
|
510
|
+
} catch {
|
|
511
|
+
// Not there: the path as given.
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
// The folder above the last themes/<slug>/ in the path, when that folder
|
|
515
|
+
// is a project's root (src/themes/<slug> is not: its project is above).
|
|
516
|
+
const m = /^(.*)[\\/]themes[\\/]([a-z][a-z0-9-]*)(?:[\\/]|$)/.exec(abs);
|
|
517
|
+
if (!m || !has(m[1], m[2])) return null;
|
|
518
|
+
/** @type {string} */
|
|
519
|
+
let top;
|
|
520
|
+
try {
|
|
521
|
+
top = projectRoot(m[1]);
|
|
522
|
+
} catch {
|
|
523
|
+
top = m[1];
|
|
524
|
+
}
|
|
525
|
+
return path.resolve(top) === path.resolve(m[1])
|
|
526
|
+
? {root: m[1], slug: m[2]}
|
|
465
527
|
: null;
|
|
466
528
|
}
|
|
467
529
|
|
|
530
|
+
/**
|
|
531
|
+
* Whether a file in an editor theme's folder is one of the editor's own
|
|
532
|
+
* (its theme source or settings), which the editor guards; another file
|
|
533
|
+
* there (a template written into the folder) is compiled as any file.
|
|
534
|
+
* @param {string} slug
|
|
535
|
+
* @param {string} file
|
|
536
|
+
*/
|
|
537
|
+
function editorOwnFile(slug, file) {
|
|
538
|
+
return [
|
|
539
|
+
`${slug}.theme.ts`,
|
|
540
|
+
`${slug}.settings.ts`,
|
|
541
|
+
`${slug}.settings.json`,
|
|
542
|
+
].includes(path.basename(file));
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* The editor theme a path or name names in `root`, or null.
|
|
547
|
+
* @param {string} root
|
|
548
|
+
* @param {string} word
|
|
549
|
+
*/
|
|
550
|
+
function editorThemeOf(root, word) {
|
|
551
|
+
return editorThemeAt(root, word)?.slug ?? null;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* A suggested command, started the way this project runs the CLI.
|
|
556
|
+
* @param {string} cwd
|
|
557
|
+
* @param {string} rest the words after `astryx`
|
|
558
|
+
*/
|
|
559
|
+
function runLine(cwd, rest) {
|
|
560
|
+
return `${getCliInvocation(cwd)} ${rest}`;
|
|
561
|
+
}
|
|
562
|
+
|
|
468
563
|
/**
|
|
469
564
|
* A clearer refusal for a theme the editor made, named to list, add, use,
|
|
470
565
|
* remove or eject: those commands work on package themes, and the editor
|
|
@@ -485,11 +580,16 @@ export function editorThemeRefusal(err, cwd) {
|
|
|
485
580
|
const named = /"([a-z][a-z0-9-]*)"|'([a-z][a-z0-9-]*)'/.exec(err.message);
|
|
486
581
|
const slug = named ? editorThemeOf(root, named[1] ?? named[2]) : null;
|
|
487
582
|
if (!slug) return null;
|
|
583
|
+
// A local theme of that name (a fork in the app's own themes folder) is
|
|
584
|
+
// one the stable commands take: their own message stands.
|
|
585
|
+
if (fs.existsSync(path.join(root, LOCAL_THEME_ROOT, slug))) return null;
|
|
586
|
+
const id = `${camel(slug)}Theme`;
|
|
587
|
+
const key = /^[a-z][a-z0-9]*$/i.test(slug) ? slug : JSON.stringify(slug);
|
|
488
588
|
return new AstryxError(
|
|
489
|
-
`${slug} is a theme the editor made (themes/${slug}/), not a theme package, so list, add, use, remove and eject do not take it.
|
|
589
|
+
`${slug} is a theme the editor made (themes/${slug}/), not a theme package, so list, add, use, remove and eject do not take it. To use it, import its module and its stylesheet in a file of your own (import {${id}} from './themes/${slug}/${slug}.js'; import './themes/${slug}/${slug}.css';) and merge it into the themes there ({...themes, ${key}: ${id}}); do not add it to src/astryx-themes.ts, which add, use and remove write again. Change it with the editor.`,
|
|
490
590
|
[
|
|
491
591
|
{
|
|
492
|
-
name: `
|
|
592
|
+
name: runLine(cwd, `experimental theme editor show ${slug}`),
|
|
493
593
|
reason: 'see the theme',
|
|
494
594
|
},
|
|
495
595
|
],
|
|
@@ -507,17 +607,21 @@ export function editorThemeRefusal(err, cwd) {
|
|
|
507
607
|
* @returns {Promise<AstryxError | null>}
|
|
508
608
|
*/
|
|
509
609
|
export async function editorCompileProblem(files, {cwd, check, family}) {
|
|
510
|
-
const
|
|
610
|
+
const cwdRoot = projectRoot(cwd);
|
|
511
611
|
for (const file of files) {
|
|
512
|
-
const
|
|
513
|
-
if (!slug) continue;
|
|
612
|
+
const at = editorThemeAt(cwdRoot, path.resolve(cwd, file));
|
|
613
|
+
if (!at || !editorOwnFile(at.slug, file)) continue;
|
|
614
|
+
const {root, slug} = at;
|
|
514
615
|
const source = `themes/${slug}/${slug}.theme.ts`;
|
|
515
616
|
if (/\.settings\.(ts|json)$/.test(file))
|
|
516
617
|
return new AstryxError(
|
|
517
618
|
`${file} is the editor's own settings for ${slug}, not a theme source; compile the theme source.`,
|
|
518
619
|
[
|
|
519
620
|
{
|
|
520
|
-
name:
|
|
621
|
+
name: runLine(
|
|
622
|
+
cwd,
|
|
623
|
+
`experimental theme compile ${quoteCommandArgument(path.relative(cwd, path.join(root, source)) || source)}`,
|
|
624
|
+
),
|
|
521
625
|
reason: 'do this instead',
|
|
522
626
|
},
|
|
523
627
|
],
|
|
@@ -528,7 +632,10 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
|
|
|
528
632
|
`${slug} is a theme the editor made; --family builds package theme families, not editor themes. Compile it on its own.`,
|
|
529
633
|
[
|
|
530
634
|
{
|
|
531
|
-
name:
|
|
635
|
+
name: runLine(
|
|
636
|
+
cwd,
|
|
637
|
+
`experimental theme compile ${quoteCommandArgument(path.relative(cwd, path.join(root, source)) || source)}`,
|
|
638
|
+
),
|
|
532
639
|
reason: 'do this instead',
|
|
533
640
|
},
|
|
534
641
|
],
|
|
@@ -540,17 +647,26 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
|
|
|
540
647
|
// generated settings: when those no longer match the settings, it
|
|
541
648
|
// would report ok without them.
|
|
542
649
|
// `compile` holds the lock already while it runs (editorThemeHold).
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
)
|
|
650
|
+
/** @type {string | null} */
|
|
651
|
+
let why;
|
|
652
|
+
try {
|
|
653
|
+
why = COMPILE_HELD.has(`${root}\0${slug}`)
|
|
654
|
+
? await edit.editorStale(root, slug)
|
|
655
|
+
: await withLock(root, lockName(slug), () =>
|
|
656
|
+
edit.editorStale(root, slug),
|
|
657
|
+
);
|
|
658
|
+
} catch (e) {
|
|
659
|
+
// A settings file damaged by hand is refused like any refusal,
|
|
660
|
+
// never as a raw error.
|
|
661
|
+
if (e instanceof AstryxError) return e;
|
|
662
|
+
throw e;
|
|
663
|
+
}
|
|
548
664
|
if (why && !check)
|
|
549
665
|
return new AstryxError(
|
|
550
666
|
`${slug}'s generated settings do not match its settings (${why}), so compile would build the old ones. The editor builds it from its settings.`,
|
|
551
667
|
[
|
|
552
668
|
{
|
|
553
|
-
name: `
|
|
669
|
+
name: runLine(cwd, `experimental theme editor show ${slug}`),
|
|
554
670
|
reason: 'do this instead',
|
|
555
671
|
},
|
|
556
672
|
],
|
|
@@ -561,7 +677,7 @@ export async function editorCompileProblem(files, {cwd, check, family}) {
|
|
|
561
677
|
`${slug} is not up to date: ${why}. The editor builds it again from its settings.`,
|
|
562
678
|
[
|
|
563
679
|
{
|
|
564
|
-
name: `
|
|
680
|
+
name: runLine(cwd, `experimental theme editor show ${slug}`),
|
|
565
681
|
reason: 'build it again',
|
|
566
682
|
},
|
|
567
683
|
],
|
|
@@ -589,12 +705,14 @@ let releaseCompileHold = null;
|
|
|
589
705
|
export async function editorThemeHold(files, {cwd}) {
|
|
590
706
|
// Two compiles of one theme in one process: the second waits for the
|
|
591
707
|
// lock like any other command.
|
|
592
|
-
const
|
|
593
|
-
const
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
)
|
|
597
|
-
|
|
708
|
+
const cwdRoot = projectRoot(cwd);
|
|
709
|
+
const found = new Map();
|
|
710
|
+
for (const f of files) {
|
|
711
|
+
const at = editorThemeAt(cwdRoot, path.resolve(cwd, f));
|
|
712
|
+
if (at && editorOwnFile(at.slug, f))
|
|
713
|
+
found.set(`${at.root}\0${at.slug}`, at);
|
|
714
|
+
}
|
|
715
|
+
const themes = [...found.keys()].sort().map(k => found.get(k));
|
|
598
716
|
/** @type {Array<() => Promise<void>>} */
|
|
599
717
|
const releases = [];
|
|
600
718
|
const releaseAll = async () => {
|
|
@@ -602,7 +720,10 @@ export async function editorThemeHold(files, {cwd}) {
|
|
|
602
720
|
for (const r of releases.splice(0).reverse()) await r();
|
|
603
721
|
};
|
|
604
722
|
releaseCompileHold = releaseAll;
|
|
605
|
-
for (const
|
|
723
|
+
for (const {
|
|
724
|
+
root,
|
|
725
|
+
slug,
|
|
726
|
+
} of /** @type {Array<{root: string, slug: string}>} */ (themes)) {
|
|
606
727
|
/** @type {() => void} */
|
|
607
728
|
let release = () => {};
|
|
608
729
|
const held = new Promise(r => {
|
|
@@ -34,14 +34,9 @@ export function pageSource({ items, imports, theme, layout, title }: {
|
|
|
34
34
|
layout: "catalog" | "sheet" | "page";
|
|
35
35
|
title?: string | undefined;
|
|
36
36
|
}): string;
|
|
37
|
-
|
|
38
|
-
export const EXTRA: Array<[string, Array<[string, Tree]>]>;
|
|
39
|
-
/** Overlays rendered open, so their surfaces, borders and shadows show. */
|
|
40
|
-
export const OPEN_OVERLAYS: Array<[string, Array<[string, Tree]>]>;
|
|
37
|
+
export function h(name: string, props?: Record<string, unknown>, ...children: unknown[]): Tree;
|
|
41
38
|
/** The sample app page every preview shows. */
|
|
42
39
|
export const SAMPLE_PAGE: Tree;
|
|
43
|
-
/** Components left off the contact sheet: they cover the page, or only lay out others. */
|
|
44
|
-
export const SHEET_SKIP: Set<string>;
|
|
45
40
|
/** Components first on the contact sheet, in this order. */
|
|
46
41
|
export const SHEET_ORDER: string[];
|
|
47
42
|
/** The light and dark switches, and the contact sheet grid. */
|
|
@@ -20,257 +20,12 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
/** @param {string} name @param {Record<string, unknown>} [props] @param {...unknown} children @returns {Tree} */
|
|
23
|
-
const h = (name, props = {}, ...children) => ({
|
|
23
|
+
export const h = (name, props = {}, ...children) => ({
|
|
24
24
|
__element: name,
|
|
25
25
|
props,
|
|
26
26
|
...(children.length ? {children} : {}),
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
/** Components without playground defaults, set up by hand. @type {Array<[string, Array<[string, Tree]>]>} */
|
|
30
|
-
export const EXTRA = [
|
|
31
|
-
[
|
|
32
|
-
'Heading',
|
|
33
|
-
[1, 2, 3, 4].map(level => [
|
|
34
|
-
`level ${level}`,
|
|
35
|
-
h('Heading', {level}, `Heading ${level}`),
|
|
36
|
-
]),
|
|
37
|
-
],
|
|
38
|
-
[
|
|
39
|
-
'TextInput',
|
|
40
|
-
[
|
|
41
|
-
['', h('TextInput', {label: 'Name', value: 'Jordan'})],
|
|
42
|
-
[
|
|
43
|
-
'disabled',
|
|
44
|
-
h('TextInput', {label: 'Disabled', value: '-', isDisabled: true}),
|
|
45
|
-
],
|
|
46
|
-
],
|
|
47
|
-
],
|
|
48
|
-
[
|
|
49
|
-
'ButtonGroup',
|
|
50
|
-
[
|
|
51
|
-
[
|
|
52
|
-
'',
|
|
53
|
-
h(
|
|
54
|
-
'ButtonGroup',
|
|
55
|
-
{label: 'Actions'},
|
|
56
|
-
h('Button', {label: 'Copy', variant: 'secondary'}),
|
|
57
|
-
h('Button', {label: 'Paste', variant: 'secondary'}),
|
|
58
|
-
h('Button', {label: 'Delete', variant: 'secondary'}),
|
|
59
|
-
),
|
|
60
|
-
],
|
|
61
|
-
],
|
|
62
|
-
],
|
|
63
|
-
['TextArea', [['', h('TextArea', {label: 'Notes', value: 'Some notes'})]]],
|
|
64
|
-
['NumberInput', [['', h('NumberInput', {label: 'Count', value: 3})]]],
|
|
65
|
-
[
|
|
66
|
-
'CheckboxInput',
|
|
67
|
-
[
|
|
68
|
-
['on', h('CheckboxInput', {label: 'Checked', value: true})],
|
|
69
|
-
['off', h('CheckboxInput', {label: 'Unchecked', value: false})],
|
|
70
|
-
],
|
|
71
|
-
],
|
|
72
|
-
[
|
|
73
|
-
'Switch',
|
|
74
|
-
[
|
|
75
|
-
['on', h('Switch', {label: 'On', value: true})],
|
|
76
|
-
['off', h('Switch', {label: 'Off', value: false})],
|
|
77
|
-
],
|
|
78
|
-
],
|
|
79
|
-
[
|
|
80
|
-
'ProgressBar',
|
|
81
|
-
['accent', 'success', 'warning', 'error'].map(v => [
|
|
82
|
-
v,
|
|
83
|
-
h('ProgressBar', {label: v, variant: v, value: 60}),
|
|
84
|
-
]),
|
|
85
|
-
],
|
|
86
|
-
[
|
|
87
|
-
'TabList',
|
|
88
|
-
[
|
|
89
|
-
[
|
|
90
|
-
'',
|
|
91
|
-
h(
|
|
92
|
-
'TabList',
|
|
93
|
-
{value: 'a'},
|
|
94
|
-
h('Tab', {value: 'a', label: 'Selected'}),
|
|
95
|
-
h('Tab', {value: 'b', label: 'Other'}),
|
|
96
|
-
),
|
|
97
|
-
],
|
|
98
|
-
],
|
|
99
|
-
],
|
|
100
|
-
[
|
|
101
|
-
'SegmentedControl',
|
|
102
|
-
[
|
|
103
|
-
[
|
|
104
|
-
'',
|
|
105
|
-
h(
|
|
106
|
-
'SegmentedControl',
|
|
107
|
-
{label: 'Range', value: 'a'},
|
|
108
|
-
h('SegmentedControlItem', {value: 'a', label: 'Day'}),
|
|
109
|
-
h('SegmentedControlItem', {value: 'b', label: 'Week'}),
|
|
110
|
-
),
|
|
111
|
-
],
|
|
112
|
-
],
|
|
113
|
-
],
|
|
114
|
-
[
|
|
115
|
-
'TopNav',
|
|
116
|
-
[
|
|
117
|
-
[
|
|
118
|
-
'',
|
|
119
|
-
h(
|
|
120
|
-
'TopNav',
|
|
121
|
-
{label: 'Top', heading: 'App'},
|
|
122
|
-
h('TopNavItem', {label: 'Selected', href: '#', isSelected: true}),
|
|
123
|
-
h('TopNavItem', {label: 'Other', href: '#'}),
|
|
124
|
-
),
|
|
125
|
-
],
|
|
126
|
-
],
|
|
127
|
-
],
|
|
128
|
-
[
|
|
129
|
-
'SideNav',
|
|
130
|
-
[
|
|
131
|
-
[
|
|
132
|
-
'',
|
|
133
|
-
h(
|
|
134
|
-
'SideNav',
|
|
135
|
-
{label: 'Side'},
|
|
136
|
-
h('SideNavItem', {label: 'Selected', href: '#', isSelected: true}),
|
|
137
|
-
h('SideNavItem', {label: 'Other', href: '#'}),
|
|
138
|
-
),
|
|
139
|
-
],
|
|
140
|
-
],
|
|
141
|
-
],
|
|
142
|
-
[
|
|
143
|
-
'StatusDot',
|
|
144
|
-
['success', 'warning', 'error', 'accent', 'neutral'].map(v => [
|
|
145
|
-
v,
|
|
146
|
-
h('StatusDot', {variant: v, label: v}),
|
|
147
|
-
]),
|
|
148
|
-
],
|
|
149
|
-
];
|
|
150
|
-
|
|
151
|
-
/** Overlays rendered open, so their surfaces, borders and shadows show. */
|
|
152
|
-
export const OPEN_OVERLAYS =
|
|
153
|
-
/** @type {Array<[string, Array<[string, Tree]>]>} */ ([
|
|
154
|
-
[
|
|
155
|
-
'Dialog',
|
|
156
|
-
[
|
|
157
|
-
[
|
|
158
|
-
'open',
|
|
159
|
-
{
|
|
160
|
-
__element: 'Dialog',
|
|
161
|
-
props: {isOpen: true, isInline: true, width: 360},
|
|
162
|
-
children: [
|
|
163
|
-
{
|
|
164
|
-
__element: 'VStack',
|
|
165
|
-
props: {gap: 2},
|
|
166
|
-
children: [
|
|
167
|
-
{
|
|
168
|
-
__element: 'Heading',
|
|
169
|
-
props: {level: 3},
|
|
170
|
-
children: ['Dialog title'],
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
__element: 'Text',
|
|
174
|
-
props: {type: 'body'},
|
|
175
|
-
children: ['Are you sure you want to proceed?'],
|
|
176
|
-
},
|
|
177
|
-
],
|
|
178
|
-
},
|
|
179
|
-
],
|
|
180
|
-
},
|
|
181
|
-
],
|
|
182
|
-
],
|
|
183
|
-
],
|
|
184
|
-
[
|
|
185
|
-
'AlertDialog',
|
|
186
|
-
[
|
|
187
|
-
[
|
|
188
|
-
'open',
|
|
189
|
-
{
|
|
190
|
-
__element: 'AlertDialog',
|
|
191
|
-
props: {
|
|
192
|
-
isOpen: true,
|
|
193
|
-
isInline: true,
|
|
194
|
-
title: 'Delete item?',
|
|
195
|
-
description: 'This cannot be undone.',
|
|
196
|
-
actionLabel: 'Delete',
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
],
|
|
200
|
-
],
|
|
201
|
-
],
|
|
202
|
-
[
|
|
203
|
-
'Popover',
|
|
204
|
-
[
|
|
205
|
-
[
|
|
206
|
-
'open',
|
|
207
|
-
{
|
|
208
|
-
__element: 'Popover',
|
|
209
|
-
props: {
|
|
210
|
-
isOpen: true,
|
|
211
|
-
label: 'Details',
|
|
212
|
-
content: {
|
|
213
|
-
__element: 'Text',
|
|
214
|
-
props: {type: 'body'},
|
|
215
|
-
children: ['Popover content'],
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
children: [
|
|
219
|
-
{
|
|
220
|
-
__element: 'Button',
|
|
221
|
-
props: {label: 'Anchor', variant: 'secondary'},
|
|
222
|
-
},
|
|
223
|
-
],
|
|
224
|
-
},
|
|
225
|
-
],
|
|
226
|
-
],
|
|
227
|
-
],
|
|
228
|
-
[
|
|
229
|
-
'Tooltip',
|
|
230
|
-
[
|
|
231
|
-
[
|
|
232
|
-
'open',
|
|
233
|
-
{
|
|
234
|
-
__element: 'Tooltip',
|
|
235
|
-
props: {isOpen: true, content: 'Tooltip text'},
|
|
236
|
-
children: [
|
|
237
|
-
{
|
|
238
|
-
__element: 'Button',
|
|
239
|
-
props: {label: 'Hover me', variant: 'secondary'},
|
|
240
|
-
},
|
|
241
|
-
],
|
|
242
|
-
},
|
|
243
|
-
],
|
|
244
|
-
],
|
|
245
|
-
],
|
|
246
|
-
[
|
|
247
|
-
'HoverCard',
|
|
248
|
-
[
|
|
249
|
-
[
|
|
250
|
-
'open',
|
|
251
|
-
{
|
|
252
|
-
__element: 'HoverCard',
|
|
253
|
-
props: {
|
|
254
|
-
isOpen: true,
|
|
255
|
-
content: {
|
|
256
|
-
__element: 'Text',
|
|
257
|
-
props: {type: 'body'},
|
|
258
|
-
children: ['More details'],
|
|
259
|
-
},
|
|
260
|
-
},
|
|
261
|
-
children: [
|
|
262
|
-
{
|
|
263
|
-
__element: 'Link',
|
|
264
|
-
props: {href: '#'},
|
|
265
|
-
children: ['Hover for details'],
|
|
266
|
-
},
|
|
267
|
-
],
|
|
268
|
-
},
|
|
269
|
-
],
|
|
270
|
-
],
|
|
271
|
-
],
|
|
272
|
-
]);
|
|
273
|
-
|
|
274
29
|
const ROWS = [
|
|
275
30
|
{id: 1, task: 'Review Q4 roadmap', owner: 'Alex', status: 'In progress'},
|
|
276
31
|
{id: 2, task: 'Ship onboarding flow', owner: 'Sam', status: 'Done'},
|
|
@@ -396,27 +151,6 @@ export const SAMPLE_PAGE = h(
|
|
|
396
151
|
),
|
|
397
152
|
);
|
|
398
153
|
|
|
399
|
-
/** Components left off the contact sheet: they cover the page, or only lay out others. */
|
|
400
|
-
export const SHEET_SKIP = new Set([
|
|
401
|
-
'Lightbox',
|
|
402
|
-
'CommandPalette',
|
|
403
|
-
'Drawer',
|
|
404
|
-
'BottomSheet',
|
|
405
|
-
'Overlay',
|
|
406
|
-
'Toast',
|
|
407
|
-
'Tooltip',
|
|
408
|
-
'HoverCard',
|
|
409
|
-
'Popover',
|
|
410
|
-
'Dialog',
|
|
411
|
-
'AlertDialog',
|
|
412
|
-
'AspectRatio',
|
|
413
|
-
'Center',
|
|
414
|
-
'Layout',
|
|
415
|
-
'ScrollableArea',
|
|
416
|
-
'Grid',
|
|
417
|
-
'Stack',
|
|
418
|
-
]);
|
|
419
|
-
|
|
420
154
|
/** Components first on the contact sheet, in this order. */
|
|
421
155
|
export const SHEET_ORDER = [
|
|
422
156
|
'Heading',
|
|
@@ -502,11 +236,14 @@ export function pageSource({items, imports, theme, layout, title = ''}) {
|
|
|
502
236
|
lines.push(
|
|
503
237
|
'const HANDLERS = ["onChange", "onClick", "onDismiss", "onOpenChange", "onSelect", "onValueChange"];',
|
|
504
238
|
);
|
|
239
|
+
lines.push(
|
|
240
|
+
'const isEl = v => Boolean(v && typeof v === "object" && !Array.isArray(v) && v.__element);',
|
|
241
|
+
);
|
|
505
242
|
lines.push(
|
|
506
243
|
'function el(v) { if (Array.isArray(v)) return v.map(el); if (v && typeof v === "object" && v.__element) { const T = C[v.__element]; if (!T) return null; return React.createElement(T, fix(v.props ?? {}), ...[].concat(v.children ?? []).map(el)); } return v; }',
|
|
507
244
|
);
|
|
508
245
|
lines.push(
|
|
509
|
-
'function fix(p) { const o = {}; for (const [k, v] of Object.entries(p)) o[k] = v
|
|
246
|
+
'function fix(p) { const o = {}; for (const [k, v] of Object.entries(p)) o[k] = isEl(v) || (Array.isArray(v) && v.some(isEl)) ? el(v) : v; for (const k of HANDLERS) if (!(k in o)) o[k] = noop; return o; }',
|
|
510
247
|
);
|
|
511
248
|
lines.push(`const ITEMS = ${JSON.stringify(items)};`);
|
|
512
249
|
lines.push(
|
|
@@ -31,7 +31,9 @@ export function storedProblems(ctx: import("./_settings.mjs").Ctx, slug: string,
|
|
|
31
31
|
*/
|
|
32
32
|
export function exampleOf(type: string, name: string): string;
|
|
33
33
|
/**
|
|
34
|
-
* Check one setting and give it back ready to store, or refuse.
|
|
34
|
+
* Check one setting and give it back ready to store, or refuse. What it
|
|
35
|
+
* accepts, the settings loader takes too: the loader's own check runs last,
|
|
36
|
+
* so a saved setting never blocks the theme.
|
|
35
37
|
* @param {import('./_settings.mjs').Ctx} ctx
|
|
36
38
|
* @param {string} slug
|
|
37
39
|
* @param {import('./_settings.mjs').ThemeData} data
|