kss-modern 1.7.0-beta.4 → 1.7.0-beta.5
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/dist/node/lib/index.d.mts +1 -1
- package/dist/node/lib/index.d.ts +1 -1
- package/dist/node/lib/index.mjs +17 -13
- package/dist/node/lib/pug/worker.d.mts +7 -2
- package/dist/node/lib/pug/worker.d.ts +7 -2
- package/dist/node/lib/pug/worker.mjs +2 -2
- package/dist/node/shared/{kss-modern.Blhbay-v.d.mts → kss-modern.Dxz_7Er0.d.mts} +4 -4
- package/dist/node/shared/{kss-modern.Blhbay-v.d.ts → kss-modern.Dxz_7Er0.d.ts} +4 -4
- package/dist/node/shared/{kss-modern.tLBfjOgj.mjs → kss-modern.hOgSyD-B.mjs} +103 -16
- package/dist/styleguide-assets/.vite/manifest.json +7 -7
- package/dist/styleguide-assets/{controller-drB07Xo_.js → controller-C41gMz7o.js} +111 -82
- package/dist/styleguide-assets/{explorer-BivD2FYm.js → explorer-ot20sEqT.js} +1 -1
- package/dist/styleguide-assets/{playground-BBMnDZ8b.js → playground-hMDIk1M2.js} +1 -1
- package/dist/styleguide-assets/{preview-BkKvdDnK.js → preview-W4yWMS_A.js} +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export { B as BuildAllOptions, L as LogBox, a as Logger, P as PreviewTheme, R as ResolvedStyleguideConfiguration, b as StyleguideBrandColor, c as StyleguideChange, S as StyleguideConfiguration, d as StyleguideContext, e as buildAll, f as buildStyleguide, g as createLogger, l as logger, p as parseStyleguide, r as rebuildSections, h as resolveConfiguration, w as watchStyleguide } from '../shared/kss-modern.
|
|
1
|
+
export { B as BuildAllOptions, L as LogBox, a as Logger, P as PreviewTheme, R as ResolvedStyleguideConfiguration, b as StyleguideBrandColor, c as StyleguideChange, S as StyleguideConfiguration, d as StyleguideContext, e as buildAll, f as buildStyleguide, g as createLogger, l as logger, p as parseStyleguide, r as rebuildSections, h as resolveConfiguration, w as watchStyleguide } from '../shared/kss-modern.Dxz_7Er0.mjs';
|
package/dist/node/lib/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { B as BuildAllOptions, L as LogBox, a as Logger, P as PreviewTheme, R as ResolvedStyleguideConfiguration, b as StyleguideBrandColor, c as StyleguideChange, S as StyleguideConfiguration, d as StyleguideContext, e as buildAll, f as buildStyleguide, g as createLogger, l as logger, p as parseStyleguide, r as rebuildSections, h as resolveConfiguration, w as watchStyleguide } from '../shared/kss-modern.
|
|
1
|
+
export { B as BuildAllOptions, L as LogBox, a as Logger, P as PreviewTheme, R as ResolvedStyleguideConfiguration, b as StyleguideBrandColor, c as StyleguideChange, S as StyleguideConfiguration, d as StyleguideContext, e as buildAll, f as buildStyleguide, g as createLogger, l as logger, p as parseStyleguide, r as rebuildSections, h as resolveConfiguration, w as watchStyleguide } from '../shared/kss-modern.Dxz_7Er0.js';
|
package/dist/node/lib/index.mjs
CHANGED
|
@@ -3,8 +3,8 @@ import process from 'node:process';
|
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
import { glob } from 'tinyglobby';
|
|
6
|
-
import { l as logger, s as sanitizeSpecialCharacters, P as PUG_ERROR_OVERLAY_TAG, r as requireZod, e as evaluateMixinSchema, c as compileMixinModule, p as pugErrorFile, a as compileMarkup, g as getZodVersion, d as discoverMixins, M as MIXIN_COMPILE_OPTIONS, b as getMixinWrapperSource, f as slugify, I as INSERT_VITE_PUG_TAG_RE, h as PUG_SRC_RE, t as themeClassList, i as ensureStartingSlash, j as sectionSanitizeId, k as stripPugErrorOverlay, m as generateId, n as replaceWrapperContent, o as formatSourceCode, q as htmlToSearchText } from '../shared/kss-modern.
|
|
7
|
-
export { u as createLogger } from '../shared/kss-modern.
|
|
6
|
+
import { l as logger, s as sanitizeSpecialCharacters, P as PUG_ERROR_OVERLAY_TAG, r as requireZod, e as evaluateMixinSchema, c as compileMixinModule, p as pugErrorFile, a as compileMarkup, g as getZodVersion, d as discoverMixins, M as MIXIN_COMPILE_OPTIONS, b as getMixinWrapperSource, f as slugify, I as INSERT_VITE_PUG_TAG_RE, h as PUG_SRC_RE, t as themeClassList, i as ensureStartingSlash, j as sectionSanitizeId, k as stripPugErrorOverlay, m as generateId, n as replaceWrapperContent, o as formatSourceCode, q as htmlToSearchText } from '../shared/kss-modern.hOgSyD-B.mjs';
|
|
7
|
+
export { u as createLogger } from '../shared/kss-modern.hOgSyD-B.mjs';
|
|
8
8
|
import { existsSync, readFileSync } from 'node:fs';
|
|
9
9
|
import fs$1 from 'node:fs/promises';
|
|
10
10
|
import { createHash } from 'node:crypto';
|
|
@@ -553,7 +553,7 @@ async function evaluateSchemaJobs(jobs) {
|
|
|
553
553
|
await Promise.all(jobs.map(async (job) => {
|
|
554
554
|
if (!workerFilePathResolved) {
|
|
555
555
|
const z = requireZod();
|
|
556
|
-
results.set(job.id, z ? evaluateMixinSchema(z, job.source) : { error: "zod 4 is not installed" });
|
|
556
|
+
results.set(job.id, z ? evaluateMixinSchema(z, job.source, job.form) : { error: "zod 4 is not installed" });
|
|
557
557
|
return;
|
|
558
558
|
}
|
|
559
559
|
try {
|
|
@@ -599,7 +599,7 @@ function getMixinStandaloneFileName(id) {
|
|
|
599
599
|
return `mixins-${id}-standalone.html`;
|
|
600
600
|
}
|
|
601
601
|
|
|
602
|
-
const CACHE_FORMAT =
|
|
602
|
+
const CACHE_FORMAT = 4;
|
|
603
603
|
const DEFAULT_CACHE_DIR = "node_modules/.cache/kss-modern";
|
|
604
604
|
const MIXIN_GRAPH_PREFIX = "mixin:";
|
|
605
605
|
let kssModernVersion;
|
|
@@ -754,16 +754,18 @@ function createMixinPipeline(config) {
|
|
|
754
754
|
}));
|
|
755
755
|
const discovered = [...pugFiles].sort().flatMap((file) => (data.files[file]?.mixins ?? []).map((mixin) => ({ file, mixin })));
|
|
756
756
|
const ids = assignIds(discovered);
|
|
757
|
-
const
|
|
757
|
+
const getSchemaForm = (mixin) => mixin.isDefineComponent ? "defineComponent" : "mixinSchema";
|
|
758
|
+
const schemaKeys = discovered.map(({ mixin }) => mixin.schemaSource === void 0 ? void 0 : hashContent(`${getSchemaForm(mixin)}
|
|
759
|
+
${mixin.schemaSource}
|
|
758
760
|
${zodVersion}`));
|
|
759
761
|
const usedSchemaKeys = new Set(schemaKeys.filter((key) => key !== void 0));
|
|
760
762
|
const schemaMisses = /* @__PURE__ */ new Map();
|
|
761
763
|
discovered.forEach(({ mixin }, index) => {
|
|
762
764
|
const schemaKey = schemaKeys[index];
|
|
763
765
|
if (schemaKey !== void 0 && !data.schemas[schemaKey])
|
|
764
|
-
schemaMisses.set(schemaKey, mixin.schemaSource);
|
|
766
|
+
schemaMisses.set(schemaKey, { source: mixin.schemaSource, form: getSchemaForm(mixin) });
|
|
765
767
|
});
|
|
766
|
-
const evaluated = await evaluateSchemaJobs([...schemaMisses].map(([id,
|
|
768
|
+
const evaluated = await evaluateSchemaJobs([...schemaMisses].map(([id, job]) => ({ id, ...job })));
|
|
767
769
|
for (const [schemaKey, schema] of evaluated) {
|
|
768
770
|
data.schemas[schemaKey] = schema;
|
|
769
771
|
isCacheDirty = true;
|
|
@@ -785,11 +787,13 @@ ${zodVersion}`));
|
|
|
785
787
|
const schema = data.schemas[schemaKey];
|
|
786
788
|
if ("error" in schema) {
|
|
787
789
|
if (evaluated.has(schemaKey))
|
|
788
|
-
logger.warn(`The
|
|
790
|
+
logger.warn(`The schema of "${mixin.name}" (${entry.file}:${mixin.line}) cannot be used, the mixin gets no playground:
|
|
789
791
|
${schema.error}`);
|
|
790
792
|
entry.schemaError = schema.error;
|
|
791
793
|
return entry;
|
|
792
794
|
}
|
|
795
|
+
if (schema.name !== void 0)
|
|
796
|
+
entry.path = getMixinPath(mixin.name, schema.name);
|
|
793
797
|
entry.hasSchema = true;
|
|
794
798
|
entry.jsonSchema = schema.jsonSchema;
|
|
795
799
|
if (typeof schema.jsonSchema.description === "string")
|
|
@@ -875,7 +879,7 @@ ${result2.error}`);
|
|
|
875
879
|
const schemaFailures = entries.filter((entry) => entry.schemaError !== void 0).map((entry) => ` \u2022 ${entry.name} (${entry.file}:${entry.line})
|
|
876
880
|
${entry.schemaError}`);
|
|
877
881
|
const problems = [
|
|
878
|
-
...schemaFailures.length > 0 ? [`Invalid
|
|
882
|
+
...schemaFailures.length > 0 ? [`Invalid schema in ${schemaFailures.length} mixin(s):
|
|
879
883
|
|
|
880
884
|
${schemaFailures.join("\n\n")}`] : [],
|
|
881
885
|
...failures.length > 0 ? [`Pug compilation failed for ${failures.length} mixin(s):
|
|
@@ -1810,7 +1814,7 @@ async function generateFullPageFile(data) {
|
|
|
1810
1814
|
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="${data.brandColor.dark}">
|
|
1811
1815
|
` : `<meta name="theme-color" content="${data.brandColor}">`}
|
|
1812
1816
|
<script type="module" src="styleguide-assets/fullpage-aWqc0gjm.js"><\/script>
|
|
1813
|
-
${data.playgroundConfig ? '<script type="module" src="styleguide-assets/playground-
|
|
1817
|
+
${data.playgroundConfig ? '<script type="module" src="styleguide-assets/playground-hMDIk1M2.js"><\/script>' : ""}
|
|
1814
1818
|
${computedStyleTags}
|
|
1815
1819
|
${computedThemeStyleTags}
|
|
1816
1820
|
</head>
|
|
@@ -2921,7 +2925,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
|
2921
2925
|
//#endregion
|
|
2922
2926
|
;
|
|
2923
2927
|
<\/script>
|
|
2924
|
-
<script type="module" src="styleguide-assets/preview-
|
|
2928
|
+
<script type="module" src="styleguide-assets/preview-W4yWMS_A.js"><\/script>
|
|
2925
2929
|
<link rel="preload" href="styleguide-assets/fonts/geist-mono-latin-400-normal.woff2" as="font" type="font/woff2" crossorigin="anonymous">
|
|
2926
2930
|
<link rel="preload" href="styleguide-assets/fonts/geist-mono-latin-600-normal.woff2" as="font" type="font/woff2" crossorigin="anonymous">
|
|
2927
2931
|
<link rel="preload" href="styleguide-assets/fonts/geist-mono-latin-300-normal.woff2" as="font" type="font/woff2" crossorigin="anonymous">
|
|
@@ -3162,7 +3166,7 @@ function getMixinExplorerHtml(manifest, config) {
|
|
|
3162
3166
|
></iframe>
|
|
3163
3167
|
<div class="absolute inset-0 hidden overflow-auto p-6 md:p-10" data-explorer-no-schema>
|
|
3164
3168
|
<div class="max-w-[65ch]">
|
|
3165
|
-
<p class="text-styleguide-highlight">The
|
|
3169
|
+
<p class="text-styleguide-highlight">The schema of <code class="font-mono font-semibold" data-explorer-no-schema-signature></code> could not be evaluated, so it has no playground. The <code class="font-mono">defineComponent</code> or <code class="font-mono">mixinSchema</code> block may only use <code class="font-mono">z</code>.</p>
|
|
3166
3170
|
<pre class="mt-3 overflow-x-auto whitespace-pre-wrap rounded-lg border p-4 font-mono text-xs text-red-700 border-styleguide-border bg-styleguide-bg dark:text-red-400" data-explorer-schema-error></pre>
|
|
3167
3171
|
</div>
|
|
3168
3172
|
</div>
|
|
@@ -3190,7 +3194,7 @@ function getMixinExplorerHtml(manifest, config) {
|
|
|
3190
3194
|
|
|
3191
3195
|
<div id="mixin-explorer-panel-controls" class="min-h-0 grow overflow-y-auto" role="tabpanel" aria-labelledby="mixin-explorer-tab-controls" tabindex="0">
|
|
3192
3196
|
<div aria-label="Props" data-playground-panel></div>
|
|
3193
|
-
<p class="hidden p-6 text-sm" data-explorer-no-controls>No controls: the
|
|
3197
|
+
<p class="hidden p-6 text-sm" data-explorer-no-controls>No controls: the schema could not be evaluated.</p>
|
|
3194
3198
|
</div>
|
|
3195
3199
|
<div id="mixin-explorer-panel-code" class="hidden min-h-0 grow overflow-auto p-4 text-sm" role="tabpanel" aria-labelledby="mixin-explorer-tab-code" tabindex="-1">
|
|
3196
3200
|
<div
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { S as StyleguideConfiguration, M as MixinUsageNode } from '../../shared/kss-modern.
|
|
1
|
+
import { S as StyleguideConfiguration, M as MixinUsageNode } from '../../shared/kss-modern.Dxz_7Er0.mjs';
|
|
2
2
|
|
|
3
3
|
type MixinSchemaResult = {
|
|
4
4
|
jsonSchema: Record<string, unknown>;
|
|
5
|
+
/** `name` passed to `defineComponent`, the mixin's place in the explorer. */
|
|
6
|
+
name?: string;
|
|
5
7
|
} | {
|
|
6
8
|
error: string;
|
|
7
9
|
};
|
|
10
|
+
/** How a mixin declares its schema, see `./discovery.ts`. */
|
|
11
|
+
type MixinSchemaForm = 'defineComponent' | 'mixinSchema';
|
|
8
12
|
|
|
9
13
|
type Mode = StyleguideConfiguration['mode'];
|
|
10
14
|
|
|
@@ -22,11 +26,12 @@ interface PugMixinJob {
|
|
|
22
26
|
file: string;
|
|
23
27
|
name: string;
|
|
24
28
|
}
|
|
25
|
-
/** Evaluate one
|
|
29
|
+
/** Evaluate one schema block and convert it to JSON Schema (see `lib/mixins/schema.ts`). */
|
|
26
30
|
interface PugSchemaJob {
|
|
27
31
|
kind: 'schema';
|
|
28
32
|
id: string;
|
|
29
33
|
source: string;
|
|
34
|
+
form: MixinSchemaForm;
|
|
30
35
|
}
|
|
31
36
|
type PugWorkerInput = PugSectionJob | PugMixinJob | PugSchemaJob;
|
|
32
37
|
interface PugWorkerSuccess {
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { S as StyleguideConfiguration, M as MixinUsageNode } from '../../shared/kss-modern.
|
|
1
|
+
import { S as StyleguideConfiguration, M as MixinUsageNode } from '../../shared/kss-modern.Dxz_7Er0.js';
|
|
2
2
|
|
|
3
3
|
type MixinSchemaResult = {
|
|
4
4
|
jsonSchema: Record<string, unknown>;
|
|
5
|
+
/** `name` passed to `defineComponent`, the mixin's place in the explorer. */
|
|
6
|
+
name?: string;
|
|
5
7
|
} | {
|
|
6
8
|
error: string;
|
|
7
9
|
};
|
|
10
|
+
/** How a mixin declares its schema, see `./discovery.ts`. */
|
|
11
|
+
type MixinSchemaForm = 'defineComponent' | 'mixinSchema';
|
|
8
12
|
|
|
9
13
|
type Mode = StyleguideConfiguration['mode'];
|
|
10
14
|
|
|
@@ -22,11 +26,12 @@ interface PugMixinJob {
|
|
|
22
26
|
file: string;
|
|
23
27
|
name: string;
|
|
24
28
|
}
|
|
25
|
-
/** Evaluate one
|
|
29
|
+
/** Evaluate one schema block and convert it to JSON Schema (see `lib/mixins/schema.ts`). */
|
|
26
30
|
interface PugSchemaJob {
|
|
27
31
|
kind: 'schema';
|
|
28
32
|
id: string;
|
|
29
33
|
source: string;
|
|
34
|
+
form: MixinSchemaForm;
|
|
30
35
|
}
|
|
31
36
|
type PugWorkerInput = PugSectionJob | PugMixinJob | PugSchemaJob;
|
|
32
37
|
interface PugWorkerSuccess {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parentPort } from 'node:worker_threads';
|
|
2
|
-
import { r as requireZod, e as evaluateMixinSchema, c as compileMixinModule, a as compileMarkup, p as pugErrorFile } from '../../shared/kss-modern.
|
|
2
|
+
import { r as requireZod, e as evaluateMixinSchema, c as compileMixinModule, a as compileMarkup, p as pugErrorFile } from '../../shared/kss-modern.hOgSyD-B.mjs';
|
|
3
3
|
import 'node:path';
|
|
4
4
|
import 'pug';
|
|
5
5
|
import 'node:fs';
|
|
@@ -20,7 +20,7 @@ parentPort.on("message", async (data) => {
|
|
|
20
20
|
try {
|
|
21
21
|
if (data.kind === "schema") {
|
|
22
22
|
const z = requireZod();
|
|
23
|
-
const schema = z ? evaluateMixinSchema(z, data.source) : { error: "zod 4 is not installed" };
|
|
23
|
+
const schema = z ? evaluateMixinSchema(z, data.source, data.form) : { error: "zod 4 is not installed" };
|
|
24
24
|
parentPort.postMessage({ id, schema });
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
@@ -13,7 +13,7 @@ interface MixinManifestEntry {
|
|
|
13
13
|
id: string;
|
|
14
14
|
name: string;
|
|
15
15
|
/**
|
|
16
|
-
* Where the mixin sits in the explorer: the segments of its `mixinName` (`'atoms/button'` ->
|
|
16
|
+
* Where the mixin sits in the explorer: the segments of its `defineComponent` `name` or `mixinName` (`'atoms/button'` ->
|
|
17
17
|
* `['atoms', 'button']`), or just its Pug name without one. The last segment is its label.
|
|
18
18
|
*/
|
|
19
19
|
path: string[];
|
|
@@ -23,13 +23,13 @@ interface MixinManifestEntry {
|
|
|
23
23
|
file: string;
|
|
24
24
|
/** 1-based line of the `mixin` keyword. */
|
|
25
25
|
line: number;
|
|
26
|
-
/** The mixin declares a usable `mixinSchema
|
|
26
|
+
/** The mixin declares a usable schema (`defineComponent` or `mixinSchema`), so it gets a playground. */
|
|
27
27
|
hasSchema: boolean;
|
|
28
28
|
/** `.describe()` of the schema itself, shown under the mixin's name. */
|
|
29
29
|
description?: string;
|
|
30
30
|
/** The schema as JSON Schema (`io: 'input'`), present when `hasSchema`. */
|
|
31
31
|
jsonSchema?: Record<string, unknown>;
|
|
32
|
-
/** Why a declared
|
|
32
|
+
/** Why a declared schema could not be used. The mixin is then treated as schema-less. */
|
|
33
33
|
schemaError?: string;
|
|
34
34
|
/** Render module, relative to the output directory. Content-hashed, so a URL never goes stale. */
|
|
35
35
|
module?: string;
|
|
@@ -40,7 +40,7 @@ interface MixinManifestEntry {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
* Only mixins that declare a `
|
|
43
|
+
* Only mixins that declare a schema, with `defineComponent` or `mixinSchema`, are public. All others are internal building blocks and
|
|
44
44
|
* stay out of the manifest and the styleguide. A schema that fails to evaluate still counts, so the
|
|
45
45
|
* broken schema shows up instead of the mixin silently vanishing.
|
|
46
46
|
*/
|
|
@@ -13,7 +13,7 @@ interface MixinManifestEntry {
|
|
|
13
13
|
id: string;
|
|
14
14
|
name: string;
|
|
15
15
|
/**
|
|
16
|
-
* Where the mixin sits in the explorer: the segments of its `mixinName` (`'atoms/button'` ->
|
|
16
|
+
* Where the mixin sits in the explorer: the segments of its `defineComponent` `name` or `mixinName` (`'atoms/button'` ->
|
|
17
17
|
* `['atoms', 'button']`), or just its Pug name without one. The last segment is its label.
|
|
18
18
|
*/
|
|
19
19
|
path: string[];
|
|
@@ -23,13 +23,13 @@ interface MixinManifestEntry {
|
|
|
23
23
|
file: string;
|
|
24
24
|
/** 1-based line of the `mixin` keyword. */
|
|
25
25
|
line: number;
|
|
26
|
-
/** The mixin declares a usable `mixinSchema
|
|
26
|
+
/** The mixin declares a usable schema (`defineComponent` or `mixinSchema`), so it gets a playground. */
|
|
27
27
|
hasSchema: boolean;
|
|
28
28
|
/** `.describe()` of the schema itself, shown under the mixin's name. */
|
|
29
29
|
description?: string;
|
|
30
30
|
/** The schema as JSON Schema (`io: 'input'`), present when `hasSchema`. */
|
|
31
31
|
jsonSchema?: Record<string, unknown>;
|
|
32
|
-
/** Why a declared
|
|
32
|
+
/** Why a declared schema could not be used. The mixin is then treated as schema-less. */
|
|
33
33
|
schemaError?: string;
|
|
34
34
|
/** Render module, relative to the output directory. Content-hashed, so a URL never goes stale. */
|
|
35
35
|
module?: string;
|
|
@@ -40,7 +40,7 @@ interface MixinManifestEntry {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
* Only mixins that declare a `
|
|
43
|
+
* Only mixins that declare a schema, with `defineComponent` or `mixinSchema`, are public. All others are internal building blocks and
|
|
44
44
|
* stay out of the manifest and the styleguide. A schema that fails to evaluate still counts, so the
|
|
45
45
|
* broken schema shows up instead of the mixin silently vanishing.
|
|
46
46
|
*/
|
|
@@ -100,23 +100,35 @@ function generateId() {
|
|
|
100
100
|
return value;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
const DEFINE_COMPONENT_RE = /\bdefineComponent\s*\(/;
|
|
103
104
|
const MIXIN_SCHEMA_RE = /\bmixinSchema\s*=/;
|
|
104
105
|
const MIXIN_NAME_RE = /^\s*(?:var|let|const)\s+mixinName\s*=\s*(['"])([^'"\n]*)\1\s*(?:;\s*)?$/;
|
|
106
|
+
const DEFINE_NAME_RE = /\bdefineComponent\s*\(\s*\{\s*name\s*:\s*(['"])([^'"\n]*)\1/;
|
|
107
|
+
const DEFINE_NAME_LINE_RE = /^\s*name\s*:\s*(['"])([^'"\n]*)\1\s*(?:,\s*)?$/m;
|
|
105
108
|
const MIXIN_KEYWORD_RE = /^\s*mixin\s/m;
|
|
109
|
+
function readDefineComponentName(source) {
|
|
110
|
+
return (DEFINE_NAME_RE.exec(source) ?? DEFINE_NAME_LINE_RE.exec(source))?.[2];
|
|
111
|
+
}
|
|
106
112
|
function findMixinCode(block) {
|
|
107
|
-
|
|
113
|
+
let defineSource;
|
|
114
|
+
let schemaSource;
|
|
115
|
+
let mixinName;
|
|
108
116
|
walk(block, (node) => {
|
|
109
117
|
if (node.type === "Mixin")
|
|
110
118
|
return false;
|
|
111
119
|
if (node.type !== "Code" || node.buffer)
|
|
112
120
|
return;
|
|
113
|
-
if (
|
|
114
|
-
|
|
121
|
+
if (defineSource === void 0 && DEFINE_COMPONENT_RE.test(node.val))
|
|
122
|
+
defineSource = node.val;
|
|
123
|
+
if (schemaSource === void 0 && MIXIN_SCHEMA_RE.test(node.val))
|
|
124
|
+
schemaSource = node.val;
|
|
115
125
|
const name = MIXIN_NAME_RE.exec(node.val)?.[2];
|
|
116
|
-
if (
|
|
117
|
-
|
|
126
|
+
if (mixinName === void 0 && name !== void 0)
|
|
127
|
+
mixinName = name;
|
|
118
128
|
});
|
|
119
|
-
|
|
129
|
+
if (defineSource !== void 0)
|
|
130
|
+
return { schemaSource: defineSource, isDefineComponent: true, mixinName: readDefineComponentName(defineSource) ?? mixinName };
|
|
131
|
+
return { schemaSource, mixinName };
|
|
120
132
|
}
|
|
121
133
|
function discoverMixins(source, filename) {
|
|
122
134
|
if (!MIXIN_KEYWORD_RE.test(source))
|
|
@@ -146,16 +158,30 @@ function createComment(val, node) {
|
|
|
146
158
|
function hasStartMarker(nodes) {
|
|
147
159
|
return nodes.some((node) => node.type === "Comment" && node.buffer === true && node.val?.trim().startsWith("START "));
|
|
148
160
|
}
|
|
161
|
+
const DEFINE_COMPONENT_CALL_RE = /\bdefineComponent\s*\(/;
|
|
162
|
+
function passMixinName(block, name) {
|
|
163
|
+
let isPassed = false;
|
|
164
|
+
walk(block, (node) => {
|
|
165
|
+
if (isPassed || node.type === "Mixin")
|
|
166
|
+
return false;
|
|
167
|
+
if (node.type !== "Code" || node.buffer || typeof node.val !== "string" || !DEFINE_COMPONENT_CALL_RE.test(node.val))
|
|
168
|
+
return;
|
|
169
|
+
node.val = node.val.replace(DEFINE_COMPONENT_CALL_RE, `defineComponent.call(${JSON.stringify({ mixin: name })}, `);
|
|
170
|
+
isPassed = true;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
149
173
|
const mixinMarkerPlugin = {
|
|
150
174
|
preCodeGen(ast) {
|
|
151
175
|
return walk(ast, (node) => {
|
|
152
176
|
if (node.type !== "Mixin" || node.call || !node.block || typeof node.name !== "string")
|
|
153
177
|
return;
|
|
154
|
-
|
|
155
|
-
return;
|
|
156
|
-
const { schemaSource, mixinName } = findMixinCode(node.block);
|
|
178
|
+
const { schemaSource, isDefineComponent, mixinName } = findMixinCode(node.block);
|
|
157
179
|
if (schemaSource === void 0)
|
|
158
180
|
return;
|
|
181
|
+
if (isDefineComponent)
|
|
182
|
+
passMixinName(node.block, node.name);
|
|
183
|
+
if (hasStartMarker(node.block.nodes))
|
|
184
|
+
return;
|
|
159
185
|
const markerName = getMixinMarkerName(node.name, mixinName);
|
|
160
186
|
node.block.nodes = [
|
|
161
187
|
createComment(` START ${markerName}`, node),
|
|
@@ -353,7 +379,7 @@ function checkValue(schema, position) {
|
|
|
353
379
|
}
|
|
354
380
|
function checkSchemaSupport(schema) {
|
|
355
381
|
if (schema.type !== "object" || !isObject(schema.properties))
|
|
356
|
-
return ["
|
|
382
|
+
return ["the schema must be a z.object({ \u2026 }) of props"];
|
|
357
383
|
const errors = checkKeys(schema, ROOT_KEYS).map((error) => `the schema ${error}`);
|
|
358
384
|
if (schema.additionalProperties !== void 0 && schema.additionalProperties !== false)
|
|
359
385
|
errors.push("the schema allows unknown keys (z.looseObject or .catchall()), which is not supported");
|
|
@@ -364,12 +390,35 @@ function checkSchemaSupport(schema) {
|
|
|
364
390
|
return errors;
|
|
365
391
|
}
|
|
366
392
|
|
|
367
|
-
function
|
|
393
|
+
function runMixinSchemaBlock(z, source) {
|
|
394
|
+
return { schema: new Function("z", `${source}
|
|
395
|
+
return mixinSchema`)(z) };
|
|
396
|
+
}
|
|
397
|
+
function runDefineComponentBlock(z, source) {
|
|
398
|
+
let definition;
|
|
399
|
+
let isCalled = false;
|
|
400
|
+
const recordDefinition = (value) => {
|
|
401
|
+
if (!isCalled) {
|
|
402
|
+
definition = value;
|
|
403
|
+
isCalled = true;
|
|
404
|
+
}
|
|
405
|
+
return {};
|
|
406
|
+
};
|
|
407
|
+
new Function("z", "defineComponent", "props", source)(z, recordDefinition, void 0);
|
|
408
|
+
if (!isCalled)
|
|
409
|
+
throw new Error("The block does not call `defineComponent`");
|
|
410
|
+
if (!definition || typeof definition !== "object")
|
|
411
|
+
throw new Error("`defineComponent` expects an object `{ name, schema }`");
|
|
412
|
+
const { name, schema } = definition;
|
|
413
|
+
if (name !== void 0 && typeof name !== "string")
|
|
414
|
+
throw new Error("`name` of `defineComponent` must be a string");
|
|
415
|
+
return { schema, name };
|
|
416
|
+
}
|
|
417
|
+
function evaluateMixinSchema(z, source, form = "mixinSchema") {
|
|
368
418
|
try {
|
|
369
|
-
const schema =
|
|
370
|
-
return mixinSchema`)(z);
|
|
419
|
+
const { schema, name } = form === "defineComponent" ? runDefineComponentBlock(z, source) : runMixinSchemaBlock(z, source);
|
|
371
420
|
if (!schema || typeof schema !== "object" || !("_zod" in schema))
|
|
372
|
-
return { error: "`mixinSchema` is not a zod schema" };
|
|
421
|
+
return { error: form === "defineComponent" ? "`schema` of `defineComponent` is not a zod schema" : "`mixinSchema` is not a zod schema" };
|
|
373
422
|
const jsonSchema = z.toJSONSchema(schema, {
|
|
374
423
|
io: "input",
|
|
375
424
|
// a type JSON Schema cannot describe (dates, maps, …) cannot get a control either
|
|
@@ -379,7 +428,7 @@ return mixinSchema`)(z);
|
|
|
379
428
|
if (unsupported.length > 0)
|
|
380
429
|
return { error: `The schema uses zod features the playground does not support:
|
|
381
430
|
${unsupported.map((line) => `- ${line}`).join("\n")}` };
|
|
382
|
-
return { jsonSchema };
|
|
431
|
+
return name === void 0 ? { jsonSchema } : { jsonSchema, name };
|
|
383
432
|
} catch (error) {
|
|
384
433
|
return { error: error instanceof Error ? error.message : String(error) };
|
|
385
434
|
}
|
|
@@ -409,6 +458,44 @@ function requireZod() {
|
|
|
409
458
|
return zodNamespace;
|
|
410
459
|
}
|
|
411
460
|
|
|
461
|
+
class ComponentPropsError extends Error {
|
|
462
|
+
issues;
|
|
463
|
+
constructor(message, issues) {
|
|
464
|
+
super(message);
|
|
465
|
+
this.name = "ComponentPropsError";
|
|
466
|
+
this.issues = issues;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
function formatIssuePath(path) {
|
|
470
|
+
return path.reduce((formatted, segment) => {
|
|
471
|
+
if (typeof segment === "number")
|
|
472
|
+
return `${formatted}[${segment}]`;
|
|
473
|
+
if (typeof segment === "symbol")
|
|
474
|
+
return formatted;
|
|
475
|
+
return formatted ? `${formatted}.${segment}` : segment;
|
|
476
|
+
}, "");
|
|
477
|
+
}
|
|
478
|
+
function getErrorPrefix(name, mixin) {
|
|
479
|
+
return [name, mixin ? `(+${mixin})` : void 0].filter(Boolean).join(" ") || "defineComponent";
|
|
480
|
+
}
|
|
481
|
+
function formatComponentPropsError(issues, name, mixin) {
|
|
482
|
+
const prefix = getErrorPrefix(name, mixin);
|
|
483
|
+
return issues.map((issue) => {
|
|
484
|
+
const path = formatIssuePath(issue.path);
|
|
485
|
+
return path ? `${prefix}: ${path}: ${issue.message}` : `${prefix}: ${issue.message}`;
|
|
486
|
+
}).join("\n");
|
|
487
|
+
}
|
|
488
|
+
function defineComponent(definition, props) {
|
|
489
|
+
const mixin = this && typeof this.mixin === "string" ? this.mixin : void 0;
|
|
490
|
+
const name = typeof definition?.name === "string" ? definition.name : void 0;
|
|
491
|
+
if (typeof definition?.schema?.safeParse !== "function")
|
|
492
|
+
throw new TypeError(`${getErrorPrefix(name, mixin)}: \`schema\` must be a zod schema`);
|
|
493
|
+
const result = definition.schema.safeParse(props);
|
|
494
|
+
if (result.success)
|
|
495
|
+
return result.data;
|
|
496
|
+
throw new ComponentPropsError(formatComponentPropsError(result.error.issues, name, mixin), result.error.issues);
|
|
497
|
+
}
|
|
498
|
+
|
|
412
499
|
function createUseId(sectionId) {
|
|
413
500
|
const namespace = `id-${sectionSanitizeId(sectionId)}`;
|
|
414
501
|
let autoCounter = 0;
|
|
@@ -532,7 +619,7 @@ function compilePugFile(pugFilePath, mode, sectionId, extraLocals = {}) {
|
|
|
532
619
|
plugins: [mixinMarkerPlugin, mixinTracePlugin]
|
|
533
620
|
});
|
|
534
621
|
const dependencies = [path.resolve(pugFilePath), ...pugFn.dependencies.map((dep) => path.resolve(dep))];
|
|
535
|
-
const locals = { modifierClass: "{{modifier_class}}", ...extraLocals, useId: createUseId(sectionId) };
|
|
622
|
+
const locals = { modifierClass: "{{modifier_class}}", ...extraLocals, useId: createUseId(sectionId), defineComponent };
|
|
536
623
|
Object.defineProperty(locals, "z", { enumerable: true, get: requireZod });
|
|
537
624
|
const trace = createMixinTrace();
|
|
538
625
|
locals[MIXIN_TRACE_LOCAL] = trace;
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"file": "code-highlight-Fm7cxf-E.js",
|
|
22
22
|
"name": "code-highlight"
|
|
23
23
|
},
|
|
24
|
-
"_controller-
|
|
25
|
-
"file": "controller-
|
|
24
|
+
"_controller-C41gMz7o.js": {
|
|
25
|
+
"file": "controller-C41gMz7o.js",
|
|
26
26
|
"name": "controller",
|
|
27
27
|
"imports": [
|
|
28
28
|
"_utils-DtB-AzJa.js",
|
|
@@ -147,14 +147,14 @@
|
|
|
147
147
|
]
|
|
148
148
|
},
|
|
149
149
|
"client/lib/playground/explorer.ts": {
|
|
150
|
-
"file": "explorer-
|
|
150
|
+
"file": "explorer-ot20sEqT.js",
|
|
151
151
|
"name": "explorer",
|
|
152
152
|
"src": "client/lib/playground/explorer.ts",
|
|
153
153
|
"isDynamicEntry": true,
|
|
154
154
|
"imports": [
|
|
155
155
|
"_code-highlight-Fm7cxf-E.js",
|
|
156
156
|
"_utils-DtB-AzJa.js",
|
|
157
|
-
"_controller-
|
|
157
|
+
"_controller-C41gMz7o.js",
|
|
158
158
|
"_alerts-DIQ8TeZB.js"
|
|
159
159
|
]
|
|
160
160
|
},
|
|
@@ -169,13 +169,13 @@
|
|
|
169
169
|
]
|
|
170
170
|
},
|
|
171
171
|
"client/playground.ts": {
|
|
172
|
-
"file": "playground-
|
|
172
|
+
"file": "playground-hMDIk1M2.js",
|
|
173
173
|
"name": "playground",
|
|
174
174
|
"src": "client/playground.ts",
|
|
175
175
|
"isEntry": true,
|
|
176
176
|
"imports": [
|
|
177
177
|
"_shared-hGcWlnRM.js",
|
|
178
|
-
"_controller-
|
|
178
|
+
"_controller-C41gMz7o.js"
|
|
179
179
|
]
|
|
180
180
|
},
|
|
181
181
|
"client/preview-inline.ts": {
|
|
@@ -185,7 +185,7 @@
|
|
|
185
185
|
"isEntry": true
|
|
186
186
|
},
|
|
187
187
|
"client/preview.ts": {
|
|
188
|
-
"file": "preview-
|
|
188
|
+
"file": "preview-W4yWMS_A.js",
|
|
189
189
|
"name": "preview",
|
|
190
190
|
"src": "client/preview.ts",
|
|
191
191
|
"isEntry": true,
|
|
@@ -193,7 +193,7 @@ function S(e, t, n, r, i, a) {
|
|
|
193
193
|
function C(e) {
|
|
194
194
|
return e instanceof HTMLInputElement && e.type === "checkbox" ? v("span", { class: "c-checkbox-row" }, [e]) : e;
|
|
195
195
|
}
|
|
196
|
-
function
|
|
196
|
+
function ee(e, t, n, r, i, a) {
|
|
197
197
|
let o = typeof t == "object" && t && !Array.isArray(t) ? { ...t } : {}, s = [], c = e.fields.map((e) => {
|
|
198
198
|
let t = `${n}-${e.key}`, r = S(e, o[e.key], e.isOptional, {
|
|
199
199
|
id: t,
|
|
@@ -216,7 +216,7 @@ function w(e, t, n, r, i, a) {
|
|
|
216
216
|
controls: s
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
|
-
function
|
|
219
|
+
function w(e, t, n, r, i) {
|
|
220
220
|
if (e.values.length === 1) {
|
|
221
221
|
let a = S(e.values[0], t, !1, { "aria-label": n }, r, i);
|
|
222
222
|
return {
|
|
@@ -240,7 +240,7 @@ function T(e, t, n, r, i) {
|
|
|
240
240
|
controls: [l, ...u.values()]
|
|
241
241
|
};
|
|
242
242
|
}
|
|
243
|
-
function
|
|
243
|
+
function T(e) {
|
|
244
244
|
let { host: t, name: n, isStandalone: r = !1 } = e, i = new AbortController(), { signal: a } = i, o = t.shadowRoot ?? t.attachShadow({ mode: "open" });
|
|
245
245
|
o.replaceChildren(), r && t.setAttribute("data-standalone", "");
|
|
246
246
|
let s = v("style", {}, [_]), c = v("div", { class: "c-panel__header" }, [v("h2", { class: "c-panel__title" }, ["Props ", v("span", { class: "c-field__type" }, [`+${n}`])])]), l = v("p", {
|
|
@@ -267,12 +267,12 @@ function E(e) {
|
|
|
267
267
|
m
|
|
268
268
|
]);
|
|
269
269
|
o.append(s, h);
|
|
270
|
-
let g = e.fields, y = structuredClone(e.values), b = /* @__PURE__ */ new Map(), x = () => e.onChange(structuredClone(y)),
|
|
270
|
+
let g = e.fields, y = structuredClone(e.values), b = /* @__PURE__ */ new Map(), x = () => e.onChange(structuredClone(y)), T = (e, t) => {
|
|
271
271
|
y[e] = t, x();
|
|
272
|
-
},
|
|
272
|
+
}, E = (e, t) => {
|
|
273
273
|
let n = b.get(e);
|
|
274
274
|
n && (n.error.textContent = t ?? "", n.error.hidden = !t, n.controls().forEach((e) => e.setAttribute("aria-invalid", String(!!t))));
|
|
275
|
-
},
|
|
275
|
+
}, D = (e, t, n, r) => {
|
|
276
276
|
let i = v("ol", { class: "c-list" }), o = v("button", {
|
|
277
277
|
class: "c-button",
|
|
278
278
|
type: "button"
|
|
@@ -281,7 +281,7 @@ function E(e) {
|
|
|
281
281
|
role: "group",
|
|
282
282
|
"aria-labelledby": n,
|
|
283
283
|
"aria-describedby": r
|
|
284
|
-
}, [i, o]), c = [], l = new AbortController(), u = () => Array.isArray(y[e.key]) ? y[e.key] : [], d = (t) =>
|
|
284
|
+
}, [i, o]), c = [], l = new AbortController(), u = () => Array.isArray(y[e.key]) ? y[e.key] : [], d = (t) => T(e.key, e.isOptional && t.length === 0 ? void 0 : t), f = (n) => {
|
|
285
285
|
let r = (e, t) => {
|
|
286
286
|
d(e), f(t);
|
|
287
287
|
};
|
|
@@ -295,7 +295,7 @@ function E(e) {
|
|
|
295
295
|
t[i] = e, d(t);
|
|
296
296
|
}, m;
|
|
297
297
|
if (o.kind === "object") {
|
|
298
|
-
let e =
|
|
298
|
+
let e = ee(o, n, `${t}-${i}`, f, p, l.signal);
|
|
299
299
|
m = e.element, c.push(...e.controls), s.push(e.controls[0] ?? m);
|
|
300
300
|
} else {
|
|
301
301
|
let e = S(o, n, !1, { "aria-label": f }, p, l.signal);
|
|
@@ -337,7 +337,7 @@ function E(e) {
|
|
|
337
337
|
group: s,
|
|
338
338
|
controls: () => [...c, o]
|
|
339
339
|
};
|
|
340
|
-
},
|
|
340
|
+
}, O = (e, t, n) => {
|
|
341
341
|
let r = e.record, i = v("ol", { class: "c-list" }), o = v("button", {
|
|
342
342
|
class: "c-button",
|
|
343
343
|
type: "button"
|
|
@@ -351,7 +351,7 @@ function E(e) {
|
|
|
351
351
|
value: t
|
|
352
352
|
})), u = [], d = new AbortController(), f = () => {
|
|
353
353
|
let t = Object.fromEntries(l.filter((e) => e.key !== "").map((e) => [e.key, e.value]));
|
|
354
|
-
|
|
354
|
+
T(e.key, e.isOptional && Object.keys(t).length === 0 ? void 0 : t);
|
|
355
355
|
}, m = (t) => {
|
|
356
356
|
d.abort(), d = new AbortController(), u = [];
|
|
357
357
|
let n = [];
|
|
@@ -370,7 +370,7 @@ function E(e) {
|
|
|
370
370
|
key: a.value
|
|
371
371
|
}, f();
|
|
372
372
|
}, { signal: d.signal });
|
|
373
|
-
let o =
|
|
373
|
+
let o = w(r, t.value, `${e.key} value ${i + 1}`, (e) => {
|
|
374
374
|
l[i] = {
|
|
375
375
|
...l[i],
|
|
376
376
|
value: e
|
|
@@ -399,20 +399,20 @@ function E(e) {
|
|
|
399
399
|
group: s,
|
|
400
400
|
controls: () => [...u, o]
|
|
401
401
|
};
|
|
402
|
-
},
|
|
402
|
+
}, k = (e, t) => {
|
|
403
403
|
let n = `field-${t}`, r = `${n}-label`, i = `${n}-help`, o = `${n}-error`, s = [e.description ? i : "", o].filter(Boolean).join(" "), c, l;
|
|
404
404
|
if (e.kind === "record") {
|
|
405
|
-
let t =
|
|
405
|
+
let t = O(e, r, s);
|
|
406
406
|
c = t.group, l = t.controls;
|
|
407
407
|
} else if (e.kind === "array") {
|
|
408
|
-
let t =
|
|
408
|
+
let t = D(e, n, r, s);
|
|
409
409
|
c = t.group, l = t.controls;
|
|
410
410
|
} else {
|
|
411
411
|
let t = S(e, y[e.key], e.isOptional, {
|
|
412
412
|
id: n,
|
|
413
413
|
"aria-describedby": s,
|
|
414
414
|
"aria-required": String(!e.isOptional)
|
|
415
|
-
}, (t) =>
|
|
415
|
+
}, (t) => T(e.key, t), a);
|
|
416
416
|
c = C(t), l = () => [t];
|
|
417
417
|
}
|
|
418
418
|
let u = e.kind === "array" || e.kind === "record" ? v("span", {
|
|
@@ -443,14 +443,14 @@ function E(e) {
|
|
|
443
443
|
d,
|
|
444
444
|
f
|
|
445
445
|
]);
|
|
446
|
-
},
|
|
447
|
-
b = /* @__PURE__ */ new Map(), u.replaceChildren(...g.map(
|
|
446
|
+
}, A = () => {
|
|
447
|
+
b = /* @__PURE__ */ new Map(), u.replaceChildren(...g.map(k));
|
|
448
448
|
};
|
|
449
|
-
return
|
|
449
|
+
return A(), u.addEventListener("submit", (e) => e.preventDefault(), { signal: a }), f.addEventListener("click", () => e.onReset(), { signal: a }), {
|
|
450
450
|
shadowRoot: o,
|
|
451
451
|
header: c,
|
|
452
452
|
setFields: (e, t) => {
|
|
453
|
-
g = e, y = structuredClone(t),
|
|
453
|
+
g = e, y = structuredClone(t), A();
|
|
454
454
|
},
|
|
455
455
|
setIssues: (e) => {
|
|
456
456
|
let t = /* @__PURE__ */ new Map(), n = [];
|
|
@@ -462,7 +462,7 @@ function E(e) {
|
|
|
462
462
|
let [e, i] = r.path.slice(1), a = `${e === void 0 ? "" : `Entry ${Number(e) + 1}: ${i === void 0 ? "" : `${String(i)}: `}`}${r.message}`;
|
|
463
463
|
t.set(r.key, [...t.get(r.key) ?? [], a]);
|
|
464
464
|
}
|
|
465
|
-
for (let e of b.keys())
|
|
465
|
+
for (let e of b.keys()) E(e, t.get(e)?.join("\n"));
|
|
466
466
|
l.textContent = n.join("\n"), l.hidden = n.length === 0;
|
|
467
467
|
},
|
|
468
468
|
setMessage: (e) => {
|
|
@@ -477,8 +477,36 @@ function E(e) {
|
|
|
477
477
|
};
|
|
478
478
|
}
|
|
479
479
|
//#endregion
|
|
480
|
+
//#region lib/mixins/define-component.ts
|
|
481
|
+
var E = class extends Error {
|
|
482
|
+
issues;
|
|
483
|
+
constructor(e, t) {
|
|
484
|
+
super(e), this.name = "ComponentPropsError", this.issues = t;
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
function D(e) {
|
|
488
|
+
return e.reduce((e, t) => typeof t == "number" ? `${e}[${t}]` : typeof t == "symbol" ? e : e ? `${e}.${t}` : t, "");
|
|
489
|
+
}
|
|
490
|
+
function O(e, t) {
|
|
491
|
+
return [e, t ? `(+${t})` : void 0].filter(Boolean).join(" ") || "defineComponent";
|
|
492
|
+
}
|
|
493
|
+
function k(e, t, n) {
|
|
494
|
+
let r = O(t, n);
|
|
495
|
+
return e.map((e) => {
|
|
496
|
+
let t = D(e.path);
|
|
497
|
+
return t ? `${r}: ${t}: ${e.message}` : `${r}: ${e.message}`;
|
|
498
|
+
}).join("\n");
|
|
499
|
+
}
|
|
500
|
+
function A(e, t) {
|
|
501
|
+
let n = this && typeof this.mixin == "string" ? this.mixin : void 0, r = typeof e?.name == "string" ? e.name : void 0;
|
|
502
|
+
if (typeof e?.schema?.safeParse != "function") throw TypeError(`${O(r, n)}: \`schema\` must be a zod schema`);
|
|
503
|
+
let i = e.schema.safeParse(t);
|
|
504
|
+
if (i.success) return i.data;
|
|
505
|
+
throw new E(k(i.error.issues, r, n), i.error.issues);
|
|
506
|
+
}
|
|
507
|
+
//#endregion
|
|
480
508
|
//#region lib/use-id.ts
|
|
481
|
-
function
|
|
509
|
+
function te(t) {
|
|
482
510
|
let n = `id-${e(t)}`, r = 0;
|
|
483
511
|
return (e) => {
|
|
484
512
|
if (e === void 0) return `${n}-${r++}`;
|
|
@@ -488,39 +516,40 @@ function D(t) {
|
|
|
488
516
|
}
|
|
489
517
|
//#endregion
|
|
490
518
|
//#region client/lib/playground/runtime.ts
|
|
491
|
-
async function
|
|
519
|
+
async function j(e, t) {
|
|
492
520
|
let n = await fetch(new URL(e, document.baseURI), { cache: t ? "no-store" : "default" });
|
|
493
521
|
if (!n.ok) throw Error(`Could not load the mixin manifest (${n.status} ${n.statusText})`);
|
|
494
522
|
return n.json();
|
|
495
523
|
}
|
|
496
|
-
var
|
|
497
|
-
function
|
|
524
|
+
var M = /* @__PURE__ */ new Map();
|
|
525
|
+
function N(e) {
|
|
498
526
|
if (!e.module) return Promise.reject(/* @__PURE__ */ Error(`Mixin "${e.name}" has no render module`));
|
|
499
|
-
let t = new URL(e.module, document.baseURI).href, n =
|
|
527
|
+
let t = new URL(e.module, document.baseURI).href, n = M.get(t);
|
|
500
528
|
return n || (n = import(
|
|
501
529
|
/* @vite-ignore */
|
|
502
530
|
t
|
|
503
531
|
).then((t) => {
|
|
504
532
|
if (typeof t.render != "function") throw TypeError(`${e.module} does not export render()`);
|
|
505
533
|
return t.render;
|
|
506
|
-
}),
|
|
534
|
+
}), M.set(t, n)), n;
|
|
507
535
|
}
|
|
508
|
-
function
|
|
536
|
+
function P(e) {
|
|
509
537
|
return typeof e == "object" && !!e && Array.isArray(e.issues);
|
|
510
538
|
}
|
|
511
|
-
function
|
|
539
|
+
function F(e, t, r) {
|
|
512
540
|
try {
|
|
513
541
|
return {
|
|
514
542
|
isValid: !0,
|
|
515
543
|
html: e({
|
|
516
544
|
props: r,
|
|
517
545
|
z: n,
|
|
518
|
-
|
|
546
|
+
defineComponent: A,
|
|
547
|
+
useId: te(`mixin-${t}`),
|
|
519
548
|
modifierClass: ""
|
|
520
549
|
})
|
|
521
550
|
};
|
|
522
551
|
} catch (e) {
|
|
523
|
-
return
|
|
552
|
+
return P(e) ? {
|
|
524
553
|
isValid: !1,
|
|
525
554
|
issues: e.issues.map((e) => {
|
|
526
555
|
let t = e.path.filter((e) => typeof e != "symbol");
|
|
@@ -538,8 +567,8 @@ function M(e, t, r) {
|
|
|
538
567
|
}
|
|
539
568
|
//#endregion
|
|
540
569
|
//#region client/lib/playground/state.ts
|
|
541
|
-
var
|
|
542
|
-
function
|
|
570
|
+
var I = "props";
|
|
571
|
+
function L(e) {
|
|
543
572
|
if (e === null || e === "") return {};
|
|
544
573
|
try {
|
|
545
574
|
let t = JSON.parse(e);
|
|
@@ -548,74 +577,74 @@ function P(e) {
|
|
|
548
577
|
return { error: `\`props\` is not valid JSON: ${e instanceof Error ? e.message : String(e)}` };
|
|
549
578
|
}
|
|
550
579
|
}
|
|
551
|
-
var
|
|
552
|
-
function
|
|
553
|
-
return
|
|
580
|
+
var R = /^(?:javascript|vbscript|data):/i;
|
|
581
|
+
function z(e) {
|
|
582
|
+
return R.test([...e].filter((e) => e.charCodeAt(0) > 32).join(""));
|
|
554
583
|
}
|
|
555
|
-
var
|
|
556
|
-
function
|
|
557
|
-
if (typeof e == "string") return e.includes("<") ||
|
|
584
|
+
var B = /^on|[^\w:.-]/i;
|
|
585
|
+
function V(e) {
|
|
586
|
+
if (typeof e == "string") return e.includes("<") || z(e) ? e : void 0;
|
|
558
587
|
if (typeof e == "object" && e) for (let [t, n] of Object.entries(e)) {
|
|
559
|
-
if (!Array.isArray(e) &&
|
|
560
|
-
let r =
|
|
588
|
+
if (!Array.isArray(e) && B.test(t)) return t;
|
|
589
|
+
let r = V(n);
|
|
561
590
|
if (r !== void 0) return r;
|
|
562
591
|
}
|
|
563
592
|
}
|
|
564
|
-
function
|
|
565
|
-
let t =
|
|
593
|
+
function H(e) {
|
|
594
|
+
let t = L(new URLSearchParams(e.hash.slice(1)).get(I) ?? e.searchParams.get(I)), n = t.props ? V(Object.values(t.props)) : void 0;
|
|
566
595
|
return n === void 0 ? t : { error: `The props from the link were not applied: they contain markup, a script URL or an attribute name like onclick (${JSON.stringify(n.slice(0, 40))}). Enter such values in the controls instead.` };
|
|
567
596
|
}
|
|
568
|
-
function
|
|
597
|
+
function U(e, t) {
|
|
569
598
|
let n = new URL(e), r = new URLSearchParams(n.hash.slice(1));
|
|
570
|
-
return r.set(
|
|
599
|
+
return r.set(I, JSON.stringify(t)), n.hash = r.toString(), n;
|
|
571
600
|
}
|
|
572
|
-
function
|
|
601
|
+
function W(e, t) {
|
|
573
602
|
let n = new URL(e);
|
|
574
|
-
return n.searchParams.set(
|
|
603
|
+
return n.searchParams.set(I, JSON.stringify(t)), n.hash = "", n;
|
|
575
604
|
}
|
|
576
|
-
var
|
|
577
|
-
function
|
|
605
|
+
var G = /^[A-Z_$][\w$]*$/i;
|
|
606
|
+
function K(e) {
|
|
578
607
|
if (typeof e == "string") return `'${e.replaceAll("\\", "\\\\").replaceAll("'", "\\'").replaceAll("\n", "\\n")}'`;
|
|
579
|
-
if (Array.isArray(e)) return `[${e.map(
|
|
608
|
+
if (Array.isArray(e)) return `[${e.map(K).join(", ")}]`;
|
|
580
609
|
if (typeof e == "object" && e) {
|
|
581
610
|
let t = Object.entries(e);
|
|
582
|
-
return t.length === 0 ? "{}" : `{ ${t.map(([e, t]) => `${
|
|
611
|
+
return t.length === 0 ? "{}" : `{ ${t.map(([e, t]) => `${G.test(e) ? e : K(e)}: ${K(t)}`).join(", ")} }`;
|
|
583
612
|
}
|
|
584
613
|
return JSON.stringify(e) ?? "undefined";
|
|
585
614
|
}
|
|
586
|
-
function
|
|
615
|
+
function q(e, t) {
|
|
587
616
|
let n = new Map(t.filter((e) => e.hasDefault).map((e) => [e.key, JSON.stringify(e.default)]));
|
|
588
617
|
return Object.fromEntries(Object.entries(e).filter(([e, t]) => n.get(e) !== JSON.stringify(t)));
|
|
589
618
|
}
|
|
590
|
-
function
|
|
591
|
-
let r =
|
|
619
|
+
function J(e, t, n = []) {
|
|
620
|
+
let r = q(t, n);
|
|
592
621
|
for (let e of n) {
|
|
593
622
|
let { items: t } = e;
|
|
594
|
-
t?.kind === "object" && Array.isArray(r[e.key]) && (r[e.key] = r[e.key].map((e) => typeof e == "object" && e ?
|
|
623
|
+
t?.kind === "object" && Array.isArray(r[e.key]) && (r[e.key] = r[e.key].map((e) => typeof e == "object" && e ? q(e, t.fields) : e));
|
|
595
624
|
}
|
|
596
|
-
return `+${e}(${
|
|
625
|
+
return `+${e}(${K(r)})`;
|
|
597
626
|
}
|
|
598
627
|
//#endregion
|
|
599
628
|
//#region client/lib/playground/validate.ts
|
|
600
|
-
var
|
|
601
|
-
function
|
|
629
|
+
var Y = /^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/;
|
|
630
|
+
function X(e) {
|
|
602
631
|
return typeof e == "string" ? `"${e}"` : String(e);
|
|
603
632
|
}
|
|
604
|
-
function
|
|
633
|
+
function ne(e) {
|
|
605
634
|
try {
|
|
606
635
|
return !!new URL(e);
|
|
607
636
|
} catch {
|
|
608
637
|
return !1;
|
|
609
638
|
}
|
|
610
639
|
}
|
|
611
|
-
function
|
|
640
|
+
function Z(e, t) {
|
|
612
641
|
return `${e} ${t}${e === 1 ? "" : "s"}`;
|
|
613
642
|
}
|
|
614
|
-
function
|
|
643
|
+
function Q(e, t) {
|
|
615
644
|
switch (e.kind) {
|
|
616
|
-
case "enum": return e.options?.includes(t) ? void 0 : `Must be one of ${(e.options ?? []).map(
|
|
645
|
+
case "enum": return e.options?.includes(t) ? void 0 : `Must be one of ${(e.options ?? []).map(X).join(", ")}`;
|
|
617
646
|
case "boolean": return typeof t == "boolean" ? void 0 : "Must be true or false";
|
|
618
|
-
case "string": return typeof t == "string" ? e.minLength !== void 0 && t.length < e.minLength ? e.minLength === 1 ? "Must not be empty" : `Must be at least ${
|
|
647
|
+
case "string": return typeof t == "string" ? e.minLength !== void 0 && t.length < e.minLength ? e.minLength === 1 ? "Must not be empty" : `Must be at least ${Z(e.minLength, "character")}` : e.maxLength !== void 0 && t.length > e.maxLength ? `Must be at most ${Z(e.maxLength, "character")}` : e.format === "email" && !Y.test(t) ? "Must be an email address" : e.format === "uri" && !ne(t) ? "Must be a URL" : e.pattern !== void 0 && e.format !== "email" && !new RegExp(e.pattern).test(t) ? `Must match ${e.pattern}` : void 0 : "Must be text";
|
|
619
648
|
case "number":
|
|
620
649
|
case "integer":
|
|
621
650
|
if (typeof t != "number" || Number.isNaN(t)) return "Must be a number";
|
|
@@ -631,37 +660,37 @@ function X(e, t) {
|
|
|
631
660
|
return;
|
|
632
661
|
}
|
|
633
662
|
}
|
|
634
|
-
function
|
|
663
|
+
function re(e, t) {
|
|
635
664
|
return typeof t != "object" || !t || Array.isArray(t) ? ["Must be an object"] : e.fields.flatMap((e) => $(e, t[e.key]).map((t) => `${e.key}: ${t}`));
|
|
636
665
|
}
|
|
637
|
-
function
|
|
666
|
+
function ie(e, t) {
|
|
638
667
|
if (typeof t != "object" || !t || Array.isArray(t)) return ["Must be an object"];
|
|
639
668
|
let n = [];
|
|
640
669
|
for (let [r, i] of Object.entries(t)) {
|
|
641
|
-
e.keyPattern !== void 0 && !new RegExp(e.keyPattern).test(r) ? n.push(`Key "${r}": Must match ${e.keyPattern}`) : e.keyMinLength !== void 0 && r.length < e.keyMinLength ? n.push(`Key "${r}": Must be at least ${
|
|
642
|
-
let t = e.values.map((e) =>
|
|
670
|
+
e.keyPattern !== void 0 && !new RegExp(e.keyPattern).test(r) ? n.push(`Key "${r}": Must match ${e.keyPattern}`) : e.keyMinLength !== void 0 && r.length < e.keyMinLength ? n.push(`Key "${r}": Must be at least ${Z(e.keyMinLength, "character")}`) : e.keyMaxLength !== void 0 && r.length > e.keyMaxLength && n.push(`Key "${r}": Must be at most ${Z(e.keyMaxLength, "character")}`);
|
|
671
|
+
let t = e.values.map((e) => Q(e, i));
|
|
643
672
|
t.every((e) => e !== void 0) && n.push(`"${r}": ${e.values.length === 1 ? t[0] : `Must be ${e.values.map((e) => e.kind).join(" or ")}`}`);
|
|
644
673
|
}
|
|
645
674
|
return n;
|
|
646
675
|
}
|
|
647
676
|
function $(e, t) {
|
|
648
677
|
if (t === void 0) return e.isOptional ? [] : ["Required"];
|
|
649
|
-
if (e.kind === "record") return e.record ?
|
|
678
|
+
if (e.kind === "record") return e.record ? ie(e.record, t) : [];
|
|
650
679
|
if (e.kind !== "array") {
|
|
651
|
-
let n =
|
|
680
|
+
let n = Q(e, t);
|
|
652
681
|
return n ? [n] : [];
|
|
653
682
|
}
|
|
654
683
|
if (!Array.isArray(t)) return ["Must be a list"];
|
|
655
684
|
let n = [];
|
|
656
|
-
e.minItems !== void 0 && t.length < e.minItems && n.push(`Needs at least ${
|
|
685
|
+
e.minItems !== void 0 && t.length < e.minItems && n.push(`Needs at least ${Z(e.minItems, "entry").replace("entrys", "entries")}`), e.maxItems !== void 0 && t.length > e.maxItems && n.push(`Allows at most ${Z(e.maxItems, "entry").replace("entrys", "entries")}`);
|
|
657
686
|
let { items: r } = e;
|
|
658
687
|
return t.forEach((e, t) => {
|
|
659
688
|
if (!r) return;
|
|
660
|
-
let i = r.kind === "object" ?
|
|
689
|
+
let i = r.kind === "object" ? re(r, e) : [Q(r, e)].filter((e) => e !== void 0);
|
|
661
690
|
n.push(...i.map((e) => `Entry ${t + 1}: ${e}`));
|
|
662
691
|
}), n;
|
|
663
692
|
}
|
|
664
|
-
function
|
|
693
|
+
function ae(e, t) {
|
|
665
694
|
let n = /* @__PURE__ */ new Map();
|
|
666
695
|
for (let r of e) {
|
|
667
696
|
let e = $(r, t[r.key]);
|
|
@@ -671,17 +700,17 @@ function ee(e, t) {
|
|
|
671
700
|
}
|
|
672
701
|
//#endregion
|
|
673
702
|
//#region client/lib/playground/controller.ts
|
|
674
|
-
var
|
|
675
|
-
async function
|
|
676
|
-
let i = (await
|
|
703
|
+
var oe = 1e3;
|
|
704
|
+
async function se(e, n, r = {}) {
|
|
705
|
+
let i = (await j(e.manifestUrl, e.isDevelopment)).mixins.find((t) => t.id === e.id);
|
|
677
706
|
if (!i || !i.hasSchema) throw Error(`Mixin "${e.name}" has no playground in ${e.manifestUrl}`);
|
|
678
|
-
let a = d(i.jsonSchema), o = h(a, r.props), s = i.module ? await
|
|
707
|
+
let a = d(i.jsonSchema), o = h(a, r.props), s = i.module ? await N(i) : void 0, c, l = () => g(a, o), u = () => J(i.name, l(), a), f = () => {
|
|
679
708
|
let e = l();
|
|
680
709
|
if (c?.setPugCall(u()), !s) {
|
|
681
710
|
c?.setMessage(i.error?.message ?? "The mixin has not compiled yet.");
|
|
682
711
|
return;
|
|
683
712
|
}
|
|
684
|
-
let t =
|
|
713
|
+
let t = ae(a, o);
|
|
685
714
|
if (t.size > 0) {
|
|
686
715
|
let r = [...t].flatMap(([e, t]) => t.map((t) => ({
|
|
687
716
|
key: e,
|
|
@@ -694,14 +723,14 @@ async function ne(e, n, r = {}) {
|
|
|
694
723
|
}, e);
|
|
695
724
|
return;
|
|
696
725
|
}
|
|
697
|
-
let r =
|
|
726
|
+
let r = F(s, i.id, e);
|
|
698
727
|
if (r.isValid) {
|
|
699
728
|
c?.setIssues([]), n.onRender(r.html, e);
|
|
700
729
|
return;
|
|
701
730
|
}
|
|
702
731
|
"issues" in r ? c?.setIssues(r.issues) : (c?.setIssues([]), c?.setMessage(r.error)), n.onInvalid?.(r, e);
|
|
703
732
|
};
|
|
704
|
-
if (n.panelHost && (c =
|
|
733
|
+
if (n.panelHost && (c = T({
|
|
705
734
|
host: n.panelHost,
|
|
706
735
|
name: i.name,
|
|
707
736
|
fields: a,
|
|
@@ -731,7 +760,7 @@ async function ne(e, n, r = {}) {
|
|
|
731
760
|
if (!r) {
|
|
732
761
|
r = !0;
|
|
733
762
|
try {
|
|
734
|
-
let t = (await
|
|
763
|
+
let t = (await j(e.manifestUrl, !0)).mixins.find((t) => t.id === e.id);
|
|
735
764
|
if (!t || !t.hasSchema) return;
|
|
736
765
|
let r = i;
|
|
737
766
|
i = t;
|
|
@@ -741,14 +770,14 @@ async function ne(e, n, r = {}) {
|
|
|
741
770
|
let e = l(), n = h(a);
|
|
742
771
|
o = Object.fromEntries(a.map((t) => [t.key, t.key in e ? e[t.key] : n[t.key]])), c?.setFields(a, o);
|
|
743
772
|
}
|
|
744
|
-
JSON.stringify(t.error) !== JSON.stringify(r.error) && n.onCompileError?.(t.error), t.module !== r.module && t.module && (s = await
|
|
773
|
+
JSON.stringify(t.error) !== JSON.stringify(r.error) && n.onCompileError?.(t.error), t.module !== r.module && t.module && (s = await N(t)), (t.module !== r.module || u) && f();
|
|
745
774
|
} catch (e) {
|
|
746
775
|
console.warn("[kss-modern] Could not check the mixin manifest for updates", e);
|
|
747
776
|
} finally {
|
|
748
777
|
r = !1;
|
|
749
778
|
}
|
|
750
779
|
}
|
|
751
|
-
},
|
|
780
|
+
}, oe), document.visibilityState === "visible" && p.start(), document.addEventListener("visibilitychange", () => {
|
|
752
781
|
document.visibilityState === "visible" ? p.resume() : p.pause();
|
|
753
782
|
}, { signal: m.signal });
|
|
754
783
|
}
|
|
@@ -768,4 +797,4 @@ async function ne(e, n, r = {}) {
|
|
|
768
797
|
};
|
|
769
798
|
}
|
|
770
799
|
//#endregion
|
|
771
|
-
export {
|
|
800
|
+
export { j as a, o as c, W as i, i as l, H as n, v as o, U as r, a as s, se as t, r as u };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as e } from "./code-highlight-Fm7cxf-E.js";
|
|
2
2
|
import { n as t } from "./utils-DtB-AzJa.js";
|
|
3
|
-
import { a as n, i as r, n as i, r as a, s as o, t as s, u as c } from "./controller-
|
|
3
|
+
import { a as n, i as r, n as i, r as a, s as o, t as s, u as c } from "./controller-C41gMz7o.js";
|
|
4
4
|
import { t as l } from "./alerts-DIQ8TeZB.js";
|
|
5
5
|
//#region client/lib/playground/format-html.ts
|
|
6
6
|
var u = /* @__PURE__ */ new Set([
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as e } from "./shared-hGcWlnRM.js";
|
|
2
|
-
import { c as t, i as n, l as r, n as i, o as a, r as o, t as s } from "./controller-
|
|
2
|
+
import { c as t, i as n, l as r, n as i, o as a, r as o, t as s } from "./controller-C41gMz7o.js";
|
|
3
3
|
//#region client/playground.ts
|
|
4
4
|
var c = "kss-modern:playground-panel", l = {
|
|
5
5
|
dock: "right",
|
|
@@ -1139,7 +1139,7 @@ ot && import("./global-theme-select-CdFgPJ0T.js").then(({ default: e }) => e(ot)
|
|
|
1139
1139
|
var st = document.querySelectorAll("[data-section-theme-select]");
|
|
1140
1140
|
st.length > 0 && import("./section-theme-select-CO65kL5N.js").then(({ default: e }) => e(st)).catch(console.error);
|
|
1141
1141
|
var ct = document.querySelector("[data-mixin-explorer]");
|
|
1142
|
-
ct && import("./explorer-
|
|
1142
|
+
ct && import("./explorer-ot20sEqT.js").then(({ default: e }) => e(ct)).catch(console.error);
|
|
1143
1143
|
var lt = document.querySelector(".editor-select");
|
|
1144
1144
|
lt && import("./editor-select-DIZFtqe7.js").then(({ default: e }) => e(lt)).catch(console.error);
|
|
1145
1145
|
//#endregion
|