@eldrajs/theme-cli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{validate-C6jB8_Oc.js → validate-DprFpjV7.js} +29 -4
- package/package.json +3 -3
- package/template/.eldra/manifest.json +2 -1
- package/template/.eldra/previews.json +34 -34
- package/template/.storybook/preview.ts +2 -1
- package/template/.storybook/virtual-eldra.d.ts +5 -0
- package/template/README.md +9 -4
- package/template/app/plugins/eldra-ui-messages.ts +1 -1
- package/template/app/storefront/money.ts +18 -17
- package/template/blocks/footer/Block.vue +2 -2
- package/template/blocks/product-detail/__tests__/Block.spec.ts +7 -10
- package/template/nuxt.config.ts +9 -1
- package/template/package.json +1 -0
- package/template/public/apple-touch-icon.png +0 -0
- package/template/public/favicon.ico +0 -0
- package/template/test/inlineEditable.spec.ts +2 -1
- package/template/test/moneyFormatting.spec.ts +4 -8
- package/template/test/pages/ssr.spec.ts +5 -11
- package/template/test/richText.spec.ts +12 -9
- package/template/test/starter.spec.ts +1 -1
- package/template/test/storefront/money.spec.ts +11 -12
- package/template/test/useBlockData.spec.ts +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@ Release-please writes the generated notes from commit messages and does not repl
|
|
|
5
5
|
|
|
6
6
|
## Unreleased
|
|
7
7
|
|
|
8
|
+
- `eldra-theme deploy` explains a 413 whose body is not JSON instead of printing `gateway responded 413`: a proxy or CDN in front of the API may have refused the upload as too large, with the platform's own artifact limits for comparison.
|
|
9
|
+
- `eldra-theme init` scaffolds a starter whose `studioOrigins` default to production Studio (`https://eldra.app`) instead of `https://localhost:4311`, so a deploy that forgets `ELDRA_STUDIO_ORIGIN` still lets production Studio connect to the preview rather than failing silently; `ELDRA_STUDIO_ORIGIN` accepts a comma-separated list.
|
|
10
|
+
- `eldra-theme validate` and the plugin build fail naming `package.json: eldra.themeId` when a theme
|
|
11
|
+
declares no id (or an invalid one); `eldra-theme deploy` refuses a build whose
|
|
12
|
+
`.eldra/manifest.json` is not `manifestVersion: 2` with a valid `theme.id` before uploading
|
|
13
|
+
anything. `eldra-theme init` scaffolds the starter with `"eldra": { "themeId": "starter" }`;
|
|
14
|
+
change it to your own theme's id.
|
|
15
|
+
|
|
8
16
|
- `eldra-theme validate` surfaces the scanner's new message-catalogue errors (an invalid
|
|
9
17
|
`i18n/<tag>.json` key, value, locale file name, or a non-default locale's keys that are not a
|
|
10
18
|
subset of the default locale's) exactly as `@eldrajs/vite-plugin-theme/scan` reports them.
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as initTheme, i as scaffoldBlock, n as generateBlockTypesFile, o as DeployError, r as generateTypes, s as deployTheme, t as validateTheme } from "./validate-
|
|
2
|
+
import { a as initTheme, i as scaffoldBlock, n as generateBlockTypesFile, o as DeployError, r as generateTypes, s as deployTheme, t as validateTheme } from "./validate-DprFpjV7.js";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { defineCommand, runMain } from "citty";
|
|
5
5
|
//#region src/cli.ts
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as initTheme, c as detectCommitSha, i as scaffoldBlock, l as fieldMigrationLines, n as generateBlockTypesFile, o as DeployError, r as generateTypes, s as deployTheme, t as validateTheme } from "./validate-
|
|
1
|
+
import { a as initTheme, c as detectCommitSha, i as scaffoldBlock, l as fieldMigrationLines, n as generateBlockTypesFile, o as DeployError, r as generateTypes, s as deployTheme, t as validateTheme } from "./validate-DprFpjV7.js";
|
|
2
2
|
import { scanTheme } from "@eldrajs/vite-plugin-theme/scan";
|
|
3
3
|
export { DeployError, deployTheme, detectCommitSha, fieldMigrationLines, generateBlockTypesFile, generateTypes, initTheme, scaffoldBlock, scanTheme, validateTheme };
|
|
@@ -2,9 +2,9 @@ import { cpSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, st
|
|
|
2
2
|
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { dirname, join, relative, resolve } from "node:path";
|
|
5
|
+
import { RESERVED_THEME_IDS, THEME_ID_PATTERN, createEldraClient } from "@eldrajs/theme-core";
|
|
5
6
|
import * as tar from "tar";
|
|
6
7
|
import { fileURLToPath } from "node:url";
|
|
7
|
-
import { createEldraClient } from "@eldrajs/theme-core";
|
|
8
8
|
import { generateBlockTypes } from "@eldrajs/vite-plugin-theme";
|
|
9
9
|
import { readPreviousManifest, scanTheme } from "@eldrajs/vite-plugin-theme/scan";
|
|
10
10
|
//#region src/deployReport.ts
|
|
@@ -129,6 +129,25 @@ var DeployError = class extends Error {
|
|
|
129
129
|
function detectCommitSha(env) {
|
|
130
130
|
return env.GITHUB_SHA ?? env.CI_COMMIT_SHA ?? env.BITBUCKET_COMMIT ?? null;
|
|
131
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Refuses a build whose manifest does not declare a theme id before anything is
|
|
134
|
+
* uploaded: Core rejects it too, but this names the file and the fix. A stale
|
|
135
|
+
* build from before manifest v2 reads as "rebuild", not as a server error.
|
|
136
|
+
*/
|
|
137
|
+
async function assertManifestIdentity(manifestPath, cwd) {
|
|
138
|
+
const file = relative(cwd, manifestPath);
|
|
139
|
+
let manifest;
|
|
140
|
+
try {
|
|
141
|
+
manifest = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
142
|
+
} catch {
|
|
143
|
+
throw new DeployError(`deploy: ${file} is not valid JSON — rebuild the theme`);
|
|
144
|
+
}
|
|
145
|
+
const record = (value) => typeof value === "object" && value !== null ? value : {};
|
|
146
|
+
const root = record(manifest);
|
|
147
|
+
if (root.manifestVersion !== 2) throw new DeployError(`deploy: ${file} has manifestVersion ${JSON.stringify(root.manifestVersion)}; this kit emits manifestVersion 2 — rebuild the theme with the current @eldrajs/vite-plugin-theme`);
|
|
148
|
+
const id = record(root.theme).id;
|
|
149
|
+
if (typeof id !== "string" || !THEME_ID_PATTERN.test(id) || RESERVED_THEME_IDS.includes(id)) throw new DeployError(`deploy: ${file} theme.id is missing or invalid (got ${JSON.stringify(id)}); declare "eldra": { "themeId": "<id>" } in package.json and rebuild`);
|
|
150
|
+
}
|
|
132
151
|
async function deployTheme(opts) {
|
|
133
152
|
const cwd = opts.cwd ?? process.cwd();
|
|
134
153
|
const doFetch = opts.fetch ?? globalThis.fetch.bind(globalThis);
|
|
@@ -138,6 +157,7 @@ async function deployTheme(opts) {
|
|
|
138
157
|
const dir = opts.dir !== void 0 ? join(cwd, opts.dir) : detectBuildDir(cwd);
|
|
139
158
|
const manifestPath = join(dir, ".eldra", "manifest.json");
|
|
140
159
|
if (!existsSync(manifestPath)) throw new DeployError(`deploy: ${relative(cwd, manifestPath)} not found — run your build (e.g. \`nuxi generate\`) first; the Eldra vite plugin emits the manifest into the build output`);
|
|
160
|
+
await assertManifestIdentity(manifestPath, cwd);
|
|
141
161
|
preflight(dir, cwd);
|
|
142
162
|
const tmp = await mkdtemp(join(tmpdir(), "eldra-deploy-"));
|
|
143
163
|
const tarPath = join(tmp, "artifact.tar.gz");
|
|
@@ -237,9 +257,12 @@ function preflight(dir, cwd) {
|
|
|
237
257
|
}
|
|
238
258
|
async function toDeployError(res) {
|
|
239
259
|
let body = null;
|
|
260
|
+
let bodyUnparseable = false;
|
|
240
261
|
try {
|
|
241
262
|
body = await res.json();
|
|
242
|
-
} catch {
|
|
263
|
+
} catch {
|
|
264
|
+
bodyUnparseable = true;
|
|
265
|
+
}
|
|
243
266
|
const detail = body?.detail ?? null;
|
|
244
267
|
if (body?.errorId === "THEME_FIELD_INCOMPATIBLE" && body.errors?.activationRefusal?.locations) {
|
|
245
268
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -252,14 +275,16 @@ async function toDeployError(res) {
|
|
|
252
275
|
}
|
|
253
276
|
return new DeployError([`deploy: ${detail ?? "theme content compatibility requires confirmation"}`, ...lines].join("\n"), body.errorId);
|
|
254
277
|
}
|
|
255
|
-
|
|
278
|
+
const messages = {
|
|
256
279
|
SITE_DEPLOY_TOKEN_INVALID: "token invalid or revoked — generate a new token in Studio (Settings → Site → Deploy token)",
|
|
257
280
|
SITE_ARTIFACT_TOO_LARGE: "artifact exceeds limits (≤ 20,000 files, ≤ 25 MiB/file, ≤ 500 MiB unpacked, ≤ 200 MiB compressed)",
|
|
258
281
|
SITE_ARTIFACT_INVALID: "artifact rejected (path traversal or symlink entries)",
|
|
259
282
|
SITE_MANIFEST_INVALID: "manifest rejected by ingest — run `eldra-theme validate` locally",
|
|
260
283
|
SITE_MANIFEST_TOO_LARGE: "manifest exceeds the 2 MiB limit — reduce block metadata and mock content, rebuild, and redeploy",
|
|
261
284
|
SITE_DEPLOY_RATE_LIMITED: "deploy rate limit hit — wait a few minutes, then retry"
|
|
262
|
-
}
|
|
285
|
+
};
|
|
286
|
+
if (res.status === 413 && bodyUnparseable) return new DeployError("deploy: gateway responded 413 (payload too large) with no error body — a proxy/CDN in front of it may have a smaller limit than the app's own (≤ 20,000 files, ≤ 25 MiB/file, ≤ 500 MiB unpacked, ≤ 200 MiB compressed), or the request exceeds one of those; check the artifact size, and if it is within them ask infra about the proxy limit");
|
|
287
|
+
return new DeployError(`deploy: ${messages[detail ?? ""] ?? `gateway responded ${res.status}${detail ? ` (${detail})` : ""}`}`, detail);
|
|
263
288
|
}
|
|
264
289
|
//#endregion
|
|
265
290
|
//#region src/templateExclude.mjs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eldrajs/theme-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "CLI for Eldra themes: init from the starter, scaffold blocks, validate, generate types, deploy a static build to Eldra.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"citty": "^0.1.6",
|
|
44
44
|
"tar": "^7.4.3",
|
|
45
|
-
"@eldrajs/
|
|
46
|
-
"@eldrajs/theme
|
|
45
|
+
"@eldrajs/theme-core": "^0.2.0",
|
|
46
|
+
"@eldrajs/vite-plugin-theme": "^0.2.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"execa": "^9.5.2"
|
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
{
|
|
2
|
-
"announcement-bar": "
|
|
3
|
-
"article": "
|
|
4
|
-
"article-list": "
|
|
5
|
-
"breadcrumbs": "
|
|
6
|
-
"cart": "
|
|
7
|
-
"collection-grid": "
|
|
8
|
-
"collection-header": "
|
|
9
|
-
"contact": "
|
|
10
|
-
"cta": "
|
|
11
|
-
"faq": "
|
|
12
|
-
"feature-grid": "
|
|
13
|
-
"footer": "
|
|
14
|
-
"gallery": "
|
|
15
|
-
"hero": "
|
|
16
|
-
"image": "
|
|
17
|
-
"logo-cloud": "
|
|
18
|
-
"navigation": "
|
|
19
|
-
"newsletter": "
|
|
20
|
-
"order-status": "
|
|
21
|
-
"pricing-table": "
|
|
22
|
-
"product-carousel": "
|
|
23
|
-
"product-detail": "
|
|
24
|
-
"quote": "
|
|
25
|
-
"rich-text": "
|
|
26
|
-
"search": "
|
|
27
|
-
"split-content": "
|
|
28
|
-
"stats": "
|
|
29
|
-
"tabs": "
|
|
30
|
-
"team": "
|
|
31
|
-
"testimonials": "
|
|
32
|
-
"timeline": "
|
|
33
|
-
"trust-strip": "
|
|
34
|
-
"video-embed": "
|
|
35
|
-
"wishlist": "
|
|
2
|
+
"announcement-bar": "8d37df3b0fe577bbc7fa173ee9499f851e1a5d73daa46fabcd12eb337b353e5f",
|
|
3
|
+
"article": "1d7a5e06fc3343d3541ccd3c1ce01632bd9d9653b5533c7031972e384692b1a4",
|
|
4
|
+
"article-list": "c93b3acbeba7b70cb7d638ecde0e35c235b5679631eaf51e3f6eb6dc97d7b5e2",
|
|
5
|
+
"breadcrumbs": "eb7cc0c1df14e2868273cb12c9fae6498aa2ca36b4381bfea762a6139e15c529",
|
|
6
|
+
"cart": "1071c0ae0a92a5ea0d738432147c5be68a573a20fbbf1793e72bd164c9097ec0",
|
|
7
|
+
"collection-grid": "aa5b996e092752941fb3bbfb3a55fc8604378999a4d0e378c310c9fe87e886dd",
|
|
8
|
+
"collection-header": "047894cf0f4bcdcb36b73fc1670540268b356fd65d80f4f19bd66c92a6a5948e",
|
|
9
|
+
"contact": "b7d15012a97185c76bff2efcd5dc9e74361679f27c80944bf220839e447236b6",
|
|
10
|
+
"cta": "818ca4b7f63bf1af0dca904ade1c03d5b7befb69bcfdcd7654d7ab017427b6f5",
|
|
11
|
+
"faq": "b06014c5459c508145f5b110d5d588c48411db85a1f34cf97347eaf02be14378",
|
|
12
|
+
"feature-grid": "026ce22d44c8a73d9dd3fa868e4e51e63ace60a254bbfab27fe186378a4af553",
|
|
13
|
+
"footer": "0b92e05c283f7770d9ba91e03fa86286ffb7725e30e5dfe6f634a20b93a7003b",
|
|
14
|
+
"gallery": "9ec63e4e469b74ea2a764d0f85d38561330aff3e24dfa1677b6e01ac0f217ad4",
|
|
15
|
+
"hero": "e1425e1e784262bb24b138ab196186ead245c6074fec8c665ea1e13f33d6ad12",
|
|
16
|
+
"image": "b70e95bf4244240497323da9b7b2da86a2edb5ea913ef12d1e514242dee18a03",
|
|
17
|
+
"logo-cloud": "08686a256d3f19303cb2fb580ee596ac50d3b3ee789f193e5066361b4e353797",
|
|
18
|
+
"navigation": "9dfa33291af7445896632eb677674a3ce2b625b5407a38ec71069975060dca22",
|
|
19
|
+
"newsletter": "10aa2f5844c2d3075033922a015171c1524c654e9cb5693fb02f5c67d3569097",
|
|
20
|
+
"order-status": "dfe175a03b0b6f5acb0b4335f6ff3f7beeb51922f2cef87618fcf8d052eb3132",
|
|
21
|
+
"pricing-table": "ba3b6e0ce93cc63abddfc6aeac56395ee7eaf724b691cbbf4e6f3cec9ba26d8c",
|
|
22
|
+
"product-carousel": "3cc2f4138a527a5bab2e99dd73545b74e0c3b0e36963e15a0ca5d942625885c6",
|
|
23
|
+
"product-detail": "f563cd6c506a4d7a888132eb6f30958aa17b426da16b473b9db4125c6af44eaf",
|
|
24
|
+
"quote": "2f960fe5afa8d7d38ace8503417d95dc83e9514ab3a27e6823a0863a8032e218",
|
|
25
|
+
"rich-text": "dc46afbe8cbfa71f8a3188f68aa01d44fd25309f159f55c9df7efad9cb555f3e",
|
|
26
|
+
"search": "d348b2e0321bcc61cc13b1bde500d96fe5c6c93df419389c7da849018b2c939d",
|
|
27
|
+
"split-content": "5cc1c0a85762be02ac7082973eb00ad556bd6c6b0985839032d05e0c6d8d09d5",
|
|
28
|
+
"stats": "38445d9d51ddad0e283a6b14fe3d73d01cabbd8e404509af9fd9258deaef991e",
|
|
29
|
+
"tabs": "43eed1d9e5828c1b5cf8f088249a61400cfff9cb0099a4f674a126535e150065",
|
|
30
|
+
"team": "3618206ad3ce50168cb7b23c463558e9fb7b9c1a86764f88df7d77274555795a",
|
|
31
|
+
"testimonials": "fd70feef06b9b0012931a382ae4e3a07c8b95dacb9a6f65e204e4d24dd4a2030",
|
|
32
|
+
"timeline": "8f1a43861e0bad750f475848867558c20829b0544e4fa929b9df0a44818295cb",
|
|
33
|
+
"trust-strip": "04060252ee9fbf3b6aa70cdde3492271addcbd727e1bd1df72cb4a42cab90b38",
|
|
34
|
+
"video-embed": "3607f72680953e795b89aee41ad171d33870e0c65d4199a88bcbdfaf792f142b",
|
|
35
|
+
"wishlist": "6b9e5609a2fae49016652ac570d338977e1ca2697367ec5ad48b8e7656c91f41"
|
|
36
36
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { setup, type Preview } from '@storybook/vue3-vite';
|
|
2
2
|
import { registerBlockFields } from '@eldrajs/theme-vue';
|
|
3
3
|
import blockFields from 'virtual:eldra/block-fields';
|
|
4
|
+
import manifest from 'virtual:eldra/manifest';
|
|
4
5
|
import '../app/assets/main.css';
|
|
5
6
|
// The theme's own `--eldra-color-*` / `--eldra-container-*` custom properties,
|
|
6
7
|
// generated from tokens.json — normally injected by @eldrajs/theme-nuxt's
|
|
@@ -16,7 +17,7 @@ import { NuxtLinkStub } from './nuxt-link-stub';
|
|
|
16
17
|
// Mirrors the runtime plugin: register block field metadata once so
|
|
17
18
|
// `useEldraBlockField` / `EldraRichText` (the `article` block's rich-text
|
|
18
19
|
// field) resolve a field's `localized` flag the same way a real page does.
|
|
19
|
-
registerBlockFields(blockFields);
|
|
20
|
+
registerBlockFields(blockFields, manifest.theme.id);
|
|
20
21
|
|
|
21
22
|
setup((app) => {
|
|
22
23
|
// No gateway, no `virtual:eldra/messages` — every block calls `useI18n()` directly, with no
|
|
@@ -18,6 +18,11 @@ declare module 'virtual:eldra/block-fields' {
|
|
|
18
18
|
export default blockFields;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
declare module 'virtual:eldra/manifest' {
|
|
22
|
+
const manifest: { theme: { id: string } };
|
|
23
|
+
export default manifest;
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
declare module 'virtual:eldra/tokens.css' {}
|
|
22
27
|
|
|
23
28
|
// Plain `tsc` (see shims-vue.d.ts) has no `vite/client` ambient CSS-import
|
package/template/README.md
CHANGED
|
@@ -21,6 +21,11 @@ pnpm install
|
|
|
21
21
|
ELDRA_GATEWAY_URL=https://web-gateway.example.com ELDRA_ORG_ID=<org-id> pnpm dev
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
Set your theme's own id before the first deploy: `package.json` declares `"eldra": { "themeId":
|
|
25
|
+
"starter" }`, and Core files the theme's schemas and entries under that id (`starter:hero`), so two
|
|
26
|
+
themes in one organisation need different ids. Lower-case letters, digits and hyphens; it is the
|
|
27
|
+
theme's identity, so choose it once. See [`docs/themes.md`](../../docs/themes.md).
|
|
28
|
+
|
|
24
29
|
## Commands
|
|
25
30
|
|
|
26
31
|
```sh
|
|
@@ -160,12 +165,12 @@ converts money, and `useMoney()` is what a block calls — the formatted text in
|
|
|
160
165
|
cart · 2.800 kr.") and the `<Price>` beside it therefore always agree.
|
|
161
166
|
|
|
162
167
|
They agree on the **sign**, too, because both come from `@eldrajs/ui`: `formatMoney` is the
|
|
163
|
-
package's `formatCurrency`, so every amount on the page carries the currency's
|
|
164
|
-
(`
|
|
165
|
-
|
|
168
|
+
package's `formatCurrency`, so every amount on the page carries the currency's wide sign
|
|
169
|
+
(`ISK 2,800` on an English page, `2.800 kr.` on an Icelandic one, `$28.00` for dollars), the same text
|
|
170
|
+
on the server and in Chrome, rather than whatever a hand-built `Intl.NumberFormat` prints there. Nothing in
|
|
166
171
|
`app/**` or `blocks/**` may build a currency formatter of its own — `test/moneyFormatting.spec.ts`
|
|
167
172
|
fails the build if anything does. The footer's currency text follows the same sign as well:
|
|
168
|
-
`currencyLabel()` names the store's currency "ISK kr" style, the code plus that sign.
|
|
173
|
+
`currencyLabel()` names the store's currency "ISK kr." style, the code plus that sign.
|
|
169
174
|
|
|
170
175
|
A store that has not configured commerce publishes no currency, and the build says so once:
|
|
171
176
|
|
|
@@ -104,7 +104,7 @@ export default defineNuxtPlugin({
|
|
|
104
104
|
nuxtApp.vueApp.provide(MESSAGES_KEY, messages);
|
|
105
105
|
// The same value is the locale every `Intl` format in the theme runs in — `@eldrajs/ui`'s
|
|
106
106
|
// `Price`/`CurrencyInput` and, through `useEldraUiLocale()`, `app/storefront/money.ts`. So a
|
|
107
|
-
// page served under `/is-IS` prints "2.800 kr." where the same money reads "
|
|
107
|
+
// page served under `/is-IS` prints "2.800 kr." where the same money reads "ISK 2,800" on the
|
|
108
108
|
// English one, while the currency itself stays the store's.
|
|
109
109
|
nuxtApp.vueApp.provide(LOCALE_KEY, activeLocale);
|
|
110
110
|
nuxtApp.vueApp.provide(CURRENCY_KEY, currency);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ComputedRef } from 'vue';
|
|
2
2
|
import {
|
|
3
|
+
createNumberFormat,
|
|
3
4
|
currencyFractionDigits,
|
|
4
5
|
currencySymbol,
|
|
5
6
|
formatCurrency,
|
|
@@ -16,14 +17,14 @@ import {
|
|
|
16
17
|
* read **minor** units (their own `amount` docs say so), so anything handed to one of those
|
|
17
18
|
* components goes through `toMinorUnits` first, while money that has to appear inside a sentence
|
|
18
19
|
* ("Add to cart · 2.800 kr.") is formatted here with `formatMoney`. A third shape names the
|
|
19
|
-
* currency itself rather than an amount in it ("ISK kr"): `currencyLabel`.
|
|
20
|
+
* currency itself rather than an amount in it ("ISK kr."): `currencyLabel`.
|
|
20
21
|
*
|
|
21
22
|
* **Nothing here builds an `Intl.NumberFormat` of its own.** Both money shapes go through
|
|
22
23
|
* `@eldrajs/ui`'s `formatCurrency`/`currencySymbol`, which is the same formatter — and therefore
|
|
23
|
-
* the same
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* the same currency sign — that every `<Price>`, `<ProductCard>` and `<CurrencyInput>` on the page
|
|
25
|
+
* renders with: the **wide** one, so English reads `ISK 2,800` and Icelandic `2.800 kr.`. A second
|
|
26
|
+
* formatter with its own sign is how a button label once read "ISK 2,800" beside a `<Price>`
|
|
27
|
+
* reading "kr 2,800" for the same money.
|
|
27
28
|
*
|
|
28
29
|
* **The currency is the store's, and it is never guessed.** It comes from the platform — the
|
|
29
30
|
* organisation's own commerce settings, read once at build and put on
|
|
@@ -58,11 +59,11 @@ interface MoneyFormat {
|
|
|
58
59
|
* `useMoney().format` is a fresh call on every render of every price and a collection grid renders
|
|
59
60
|
* one or two per card, so what this saves is worth saving: the `currencyFractionDigits` lookup, the
|
|
60
61
|
* one probe that decides whether `Intl` will accept the store's code at all, and — for a store with
|
|
61
|
-
* no currency — the one
|
|
62
|
+
* no currency — the one plain-decimal formatter this module still asks for itself. A store has one
|
|
62
63
|
* currency and a handful of locales, so the cache is a few entries that never need evicting.
|
|
63
64
|
*
|
|
64
65
|
* What it deliberately does **not** cache is a currency formatter. `formatCurrency` is
|
|
65
|
-
* `@eldrajs/ui`'s own, stateless by design, and the single place the
|
|
66
|
+
* `@eldrajs/ui`'s own, stateless by design, and the single place the sign and the
|
|
66
67
|
* fraction-digit rule are decided; a formatter cached here would be a second definition of both,
|
|
67
68
|
* which is precisely the bug this module had. Its per-amount construction is a few microseconds
|
|
68
69
|
* against a render that costs far more.
|
|
@@ -86,7 +87,7 @@ function resolveFormat(currency: string | undefined, locale: string): MoneyForma
|
|
|
86
87
|
* dangling separator would reach the DOM and the accessible text of every price on the page.
|
|
87
88
|
*/
|
|
88
89
|
const decimal = (): MoneyFormat => {
|
|
89
|
-
const formatter =
|
|
90
|
+
const formatter = createNumberFormat({ locale, style: 'decimal' });
|
|
90
91
|
return {
|
|
91
92
|
format: (amount) =>
|
|
92
93
|
code === '' ? formatter.format(amount) : `${formatter.format(amount)} ${code}`,
|
|
@@ -102,15 +103,15 @@ function resolveFormat(currency: string | undefined, locale: string): MoneyForma
|
|
|
102
103
|
// helper it ports does, and this runs inside `computed`s where a throw takes the whole block
|
|
103
104
|
// down. So the code is probed once per pair here rather than guarded once per amount.
|
|
104
105
|
try {
|
|
105
|
-
formatCurrency(0, locale, code,
|
|
106
|
+
formatCurrency(0, locale, code, false, digits, digits);
|
|
106
107
|
resolved = {
|
|
107
|
-
// The
|
|
108
|
-
//
|
|
108
|
+
// The wide sign, as every `<Price>` writes it. The currency's own count goes in twice: as
|
|
109
|
+
// the cap, because the util's default of 2 would
|
|
109
110
|
// print a fractional króna and round a three-decimal currency to two; and as the
|
|
110
111
|
// **minimum**, which is the util's display rule — without it `$96` and `$96.50` sit in the
|
|
111
112
|
// same column. Both are exactly what `<Price>` passes, so a formatted sentence and the
|
|
112
113
|
// `<Price>` beside it cannot disagree about either.
|
|
113
|
-
format: (amount) => formatCurrency(amount, locale, code,
|
|
114
|
+
format: (amount) => formatCurrency(amount, locale, code, false, digits, digits),
|
|
114
115
|
digits,
|
|
115
116
|
};
|
|
116
117
|
} catch {
|
|
@@ -123,8 +124,8 @@ function resolveFormat(currency: string | undefined, locale: string): MoneyForma
|
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
/**
|
|
126
|
-
* A major-unit amount as text, in the currency's own shape and its **
|
|
127
|
-
* `USD`, `2.800 kr.` for `ISK` on an Icelandic page, `
|
|
127
|
+
* A major-unit amount as text, in the currency's own shape and its **wide** sign: `$28.00` for
|
|
128
|
+
* `USD`, `2.800 kr.` for `ISK` on an Icelandic page, `ISK 2,800` for the same money on an English
|
|
128
129
|
* one. The fraction count is the currency's own, as both the maximum and the minimum, so a
|
|
129
130
|
* zero-decimal currency never renders phantom decimals and a two-decimal one never renders a
|
|
130
131
|
* ragged column.
|
|
@@ -147,19 +148,19 @@ export function formatMoney(
|
|
|
147
148
|
|
|
148
149
|
/**
|
|
149
150
|
* A currency *code* as text naming itself, not an amount: `"ISK kr."` on an Icelandic page,
|
|
150
|
-
* `"ISK
|
|
151
|
+
* `"ISK"` on an English one, `"USD $"` — the code plus the sign `formatMoney` prints in front
|
|
151
152
|
* of the amounts on the same page, for a place that names the store's currency rather than
|
|
152
153
|
* formatting a price in it (the footer's currency selector, with one option now that the platform
|
|
153
154
|
* publishes one currency).
|
|
154
155
|
*
|
|
155
|
-
* `@eldrajs/ui`'s `currencySymbol` is where the sign comes from — the **
|
|
156
|
+
* `@eldrajs/ui`'s `currencySymbol` is where the sign comes from — the **wide** one, read out of
|
|
156
157
|
* `formatToParts`, never a hand-maintained code → symbol table — so this label and every price on
|
|
157
158
|
* the page are written with the same character. One fallback, and it is the honest one: the code
|
|
158
159
|
* appended to itself is noise, so a currency with no sign distinct from its code in this locale
|
|
159
160
|
* (which is also what `currencySymbol` answers for a code `Intl` rejects) prints just the code.
|
|
160
161
|
*/
|
|
161
162
|
export function currencyLabel(code: string, locale: string = DEFAULT_LOCALE): string {
|
|
162
|
-
const symbol = currencySymbol(code, locale);
|
|
163
|
+
const symbol = currencySymbol(code, locale, false);
|
|
163
164
|
return symbol === code ? code : `${code} ${symbol}`;
|
|
164
165
|
}
|
|
165
166
|
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
* The currency selector is different: the spec was written for a multi-currency store, but the
|
|
49
49
|
* platform supports exactly one currency per store today. So its options are derived from the
|
|
50
50
|
* store (`useMoney().currency`, `app/storefront/money.ts`), not from a constant list, and there is
|
|
51
|
-
* at most one of them — `currencyLabel()` names it "ISK kr" style (code + the
|
|
51
|
+
* at most one of them — `currencyLabel()` names it "ISK kr." style (code + the sign
|
|
52
52
|
* `@eldrajs/ui` writes the store's prices with in the content locale, falling back to the code
|
|
53
53
|
* alone when the locale has no sign distinct from it). With exactly one option
|
|
54
54
|
* there is nothing to select, so it renders as plain text with the same leading icon and a visually
|
|
@@ -254,7 +254,7 @@ const showCurrency = computed(() => data.value.showCurrency ?? true);
|
|
|
254
254
|
* The currency selector's option list, derived from the store rather than the spec's hard-coded
|
|
255
255
|
* USD/CAD/EUR demo list: the platform supports exactly one currency per store today, so this is
|
|
256
256
|
* either empty (the store publishes none) or a single entry — the store's currency, named "ISK
|
|
257
|
-
* kr" style by `currencyLabel()` (code + the same
|
|
257
|
+
* kr." style by `currencyLabel()` (code + the same sign every price on the page is written
|
|
258
258
|
* with). Kept as a list, not a single value, so the day the platform supports more than one
|
|
259
259
|
* currency, this grows to match and the template's `Select` branch (below) is already there.
|
|
260
260
|
*/
|
|
@@ -495,29 +495,26 @@ describe('product-detail block', () => {
|
|
|
495
495
|
});
|
|
496
496
|
|
|
497
497
|
/**
|
|
498
|
-
* The same store on an **English** page
|
|
499
|
-
* narrow sign for krónur is `kr`, the wide one is the code itself. The button's label and the
|
|
500
|
-
* `<Price>` above it must agree on it, and `kr 2,800` is what the operator's own back office
|
|
501
|
-
* writes — an `ISK 2,800` here beside a `kr 2,800` in a currency field was the defect.
|
|
498
|
+
* The same store on an **English** page: the button's label and the `<Price>` above it both write `ISK 2,800`.
|
|
502
499
|
*/
|
|
503
|
-
it('writes the store currency’s
|
|
500
|
+
it('writes the store currency’s wide sign on a page in another locale', async () => {
|
|
504
501
|
const wrapper = await mountReady(mock, {
|
|
505
502
|
locale: 'en-US',
|
|
506
503
|
commerce: { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 },
|
|
507
504
|
storefront: storefrontWith({ price: { amount: 2800, compareAt: null } }),
|
|
508
505
|
});
|
|
509
506
|
|
|
510
|
-
expect(formatMoney(2800, 'ISK', 'en-US')).toBe('
|
|
507
|
+
expect(formatMoney(2800, 'ISK', 'en-US')).toBe('ISK\u00a02,800');
|
|
511
508
|
expect(addToCart(wrapper).text()).toContain(
|
|
512
|
-
enUS.product.addToCart.replace('{price}', '
|
|
509
|
+
enUS.product.addToCart.replace('{price}', 'ISK\u00a02,800')
|
|
513
510
|
);
|
|
514
511
|
const rendered = wrapper.findAll('[data-part="current"]').map((part) => part.text());
|
|
515
512
|
expect(rendered.length).toBeGreaterThan(0);
|
|
516
513
|
for (const amount of rendered) {
|
|
517
|
-
expect(amount).toBe('
|
|
514
|
+
expect(amount).toBe('ISK\u00a02,800');
|
|
518
515
|
}
|
|
519
|
-
// Not the
|
|
520
|
-
expect(wrapper.text()).not.toContain('
|
|
516
|
+
// Not the narrow sign, in either half.
|
|
517
|
+
expect(wrapper.text()).not.toContain('kr\u00a02,800');
|
|
521
518
|
});
|
|
522
519
|
|
|
523
520
|
/**
|
package/template/nuxt.config.ts
CHANGED
|
@@ -97,8 +97,16 @@ export default defineNuxtConfig({
|
|
|
97
97
|
// Keep these exact origins: they are also emitted into the Pages CSP header. More than one
|
|
98
98
|
// (comma-separated in `ELDRA_STUDIO_ORIGIN`) lets one build serve a Studio whose origin is
|
|
99
99
|
// changing — the old and the new origin both allowed until the old one is retired.
|
|
100
|
+
//
|
|
101
|
+
// Defaults to production Studio (`https://eldra.app`), not a local dev origin: a build that
|
|
102
|
+
// forgets to set `ELDRA_STUDIO_ORIGIN` is far more likely to be a staging/production deploy than
|
|
103
|
+
// someone's local theme dev server, and the old `https://localhost:4311` default made that
|
|
104
|
+
// mistake fail silently — the static page still rendered, so nothing looked wrong, but the
|
|
105
|
+
// preview bridge would never connect and the editor would just report "Preview disconnected"
|
|
106
|
+
// with inline editing dead. Local theme development against a local Studio must set
|
|
107
|
+
// `ELDRA_STUDIO_ORIGIN` explicitly.
|
|
100
108
|
eldra: {
|
|
101
|
-
studioOrigins: (process.env.ELDRA_STUDIO_ORIGIN ?? 'https://
|
|
109
|
+
studioOrigins: (process.env.ELDRA_STUDIO_ORIGIN ?? 'https://eldra.app')
|
|
102
110
|
.split(',')
|
|
103
111
|
.map((origin) => origin.trim())
|
|
104
112
|
.filter((origin) => origin.length > 0),
|
package/template/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
@@ -70,7 +70,8 @@ const mockModules = import.meta.glob<{ default: Record<string, unknown> }>(
|
|
|
70
70
|
registerBlockFields(
|
|
71
71
|
Object.fromEntries(
|
|
72
72
|
manifest.blocks.map((block) => [block.apiId, block.fields])
|
|
73
|
-
) as unknown as BlockFieldsMap
|
|
73
|
+
) as unknown as BlockFieldsMap,
|
|
74
|
+
manifest.theme.id
|
|
74
75
|
);
|
|
75
76
|
|
|
76
77
|
const blocks = Object.entries(blockModules)
|
|
@@ -9,11 +9,7 @@ import { formatMoney } from '../app/storefront/money';
|
|
|
9
9
|
* One formatter for every currency on the storefront, and it is the public one.
|
|
10
10
|
*
|
|
11
11
|
* `@eldrajs/ui`'s `formatCurrency` (and the `<Price>`/`<ProductCard>`/`<CurrencyInput>` components
|
|
12
|
-
* that format through it)
|
|
13
|
-
* `2.800 kr.` on an Icelandic one. A hand-built `Intl.NumberFormat({ style: 'currency' })` writes
|
|
14
|
-
* the *wide* sign instead (`ISK 2,800`), and the two look nothing alike on the same page: that is
|
|
15
|
-
* exactly how this theme came to show `ISK 2,800` in an Add-to-cart label beside a `<Price>`
|
|
16
|
-
* reading `kr 2,800` for the same money.
|
|
12
|
+
* that format through it) is the one formatter, so every price on a page writes the same sign.
|
|
17
13
|
*
|
|
18
14
|
* So no block and no app module may build a currency formatter of its own. `app/storefront/money.ts`
|
|
19
15
|
* is the single exception — it is the module that calls the public util — and it builds only a
|
|
@@ -78,12 +74,12 @@ describe('money is formatted in exactly one place', () => {
|
|
|
78
74
|
expect(offenders).toEqual([]);
|
|
79
75
|
});
|
|
80
76
|
|
|
81
|
-
it('formats through the public util, which is what gives every price the
|
|
77
|
+
it('formats through the public util, which is what gives every price the same sign', () => {
|
|
82
78
|
// The module under the exception, held to the util it exists to call.
|
|
83
79
|
expect(formatMoney(2800, 'ISK', 'en-US')).toBe(
|
|
84
|
-
formatCurrency(2800, 'en-US', 'ISK',
|
|
80
|
+
formatCurrency(2800, 'en-US', 'ISK', false, 0, 0)
|
|
85
81
|
);
|
|
86
|
-
expect(formatMoney(2800, 'ISK', 'en-US')).toBe('
|
|
82
|
+
expect(formatMoney(2800, 'ISK', 'en-US')).toBe('ISK\u00a02,800');
|
|
87
83
|
expect(formatMoney(2800, 'ISK', 'is-IS')).toBe('2.800\u00a0kr.');
|
|
88
84
|
});
|
|
89
85
|
});
|
|
@@ -353,14 +353,9 @@ describe('server rendering', () => {
|
|
|
353
353
|
});
|
|
354
354
|
|
|
355
355
|
/**
|
|
356
|
-
* And the sign is the
|
|
357
|
-
* later. `is-IS` writes `kr.` either way, so the sign is only a choice on a page in another
|
|
358
|
-
* locale: an English page of the same krónur store must prerender `kr 96`, never `ISK 96`.
|
|
359
|
-
* The wide sign is what a hand-built `{ style: 'currency' }` formatter writes, and it reached
|
|
360
|
-
* the HTML of every price on the page — both the `<Price>` elements and the formatted labels
|
|
361
|
-
* beside them.
|
|
356
|
+
* And the sign is the wide one on an English page (`ISK 96`), in every price and label alike.
|
|
362
357
|
*/
|
|
363
|
-
it('server-renders the store’s currency in its
|
|
358
|
+
it('server-renders the store’s currency in its wide sign, never a bare "kr"', async () => {
|
|
364
359
|
const commerce = { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 };
|
|
365
360
|
const html = await renderPageToString(productPage as unknown as PageFixture, {
|
|
366
361
|
[CURRENCY_KEY]: commerce.currency,
|
|
@@ -369,10 +364,9 @@ describe('server rendering', () => {
|
|
|
369
364
|
});
|
|
370
365
|
|
|
371
366
|
expect(html).toContain(formatMoney(96, 'ISK', 'en-US'));
|
|
372
|
-
expect(formatMoney(96, 'ISK', 'en-US')).toBe('
|
|
373
|
-
// Not the
|
|
374
|
-
|
|
375
|
-
expect(html).not.toMatch(/ISK(\s| )\d/);
|
|
367
|
+
expect(formatMoney(96, 'ISK', 'en-US')).toBe('ISK\u00a096');
|
|
368
|
+
// Not the narrow sign in front of an amount, anywhere: not in a price, not in a button label.
|
|
369
|
+
expect(html).not.toMatch(/\bkr(\s| )\d/);
|
|
376
370
|
});
|
|
377
371
|
|
|
378
372
|
it('server-renders product-carousel with real cards, and no skeleton', async () => {
|
|
@@ -49,14 +49,17 @@ const body = {
|
|
|
49
49
|
* not the test's invention.
|
|
50
50
|
*/
|
|
51
51
|
function registerArticleFields(): void {
|
|
52
|
-
registerBlockFields(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
registerBlockFields(
|
|
53
|
+
{
|
|
54
|
+
article: blockManifest.fields.map((field) => ({
|
|
55
|
+
fieldId: field.fieldId,
|
|
56
|
+
type: field.type,
|
|
57
|
+
...(field.localized === true ? { localized: true } : {}),
|
|
58
|
+
...(field.metadata === undefined ? {} : { metadata: field.metadata }),
|
|
59
|
+
})),
|
|
60
|
+
},
|
|
61
|
+
'starter'
|
|
62
|
+
);
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
/** A preview bridge attached with an active content locale. */
|
|
@@ -84,7 +87,7 @@ function mountArticle(context?: unknown, doc: unknown = body) {
|
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
afterEach(() => {
|
|
87
|
-
registerBlockFields({});
|
|
90
|
+
registerBlockFields({}, 'starter');
|
|
88
91
|
});
|
|
89
92
|
|
|
90
93
|
describe('article body renders through EldraRichText', () => {
|
|
@@ -528,7 +528,7 @@ describe('starter theme', () => {
|
|
|
528
528
|
'footer',
|
|
529
529
|
]);
|
|
530
530
|
expect(readFileSync(output('_headers'), 'utf8')).toContain(
|
|
531
|
-
"frame-ancestors 'self' https://
|
|
531
|
+
"frame-ancestors 'self' https://eldra.app"
|
|
532
532
|
);
|
|
533
533
|
// A build with no credentials cannot know what the store sells in, and says so in the one place
|
|
534
534
|
// that matters: the runtime config baked into every page carries no currency, rather than one
|
|
@@ -27,7 +27,7 @@ describe('formatMoney', () => {
|
|
|
27
27
|
expect(formatMoney(28, 'ISK', 'is-IS')).toContain('28');
|
|
28
28
|
// Not even for an amount that has a fraction: krónur have no minor unit to show one in, and
|
|
29
29
|
// so nothing to pad to either.
|
|
30
|
-
expect(formatMoney(28.4, 'ISK', 'en-US')).toBe('
|
|
30
|
+
expect(formatMoney(28.4, 'ISK', 'en-US')).toBe('ISK\u00a028');
|
|
31
31
|
expect(formatMoney(28, 'USD', 'en-US')).toBe('$28.00');
|
|
32
32
|
expect(formatMoney(28.5, 'USD', 'en-US')).toBe('$28.50');
|
|
33
33
|
expect(formatMoney(28.567, 'USD', 'en-US')).toBe('$28.57');
|
|
@@ -48,16 +48,16 @@ describe('formatMoney', () => {
|
|
|
48
48
|
* read "ISK 2,800" beside a `<Price>` reading "kr 2,800" for the same money. Both now go through
|
|
49
49
|
* `@eldrajs/ui`'s `formatCurrency`, so there is one sign on the page.
|
|
50
50
|
*/
|
|
51
|
-
it('writes the currency’s
|
|
52
|
-
expect(formatMoney(2800, 'ISK', 'en-US')).toBe('
|
|
51
|
+
it('writes the currency’s wide sign, the same one every <Price> writes', () => {
|
|
52
|
+
expect(formatMoney(2800, 'ISK', 'en-US')).toBe('ISK\u00a02,800');
|
|
53
53
|
expect(formatMoney(2800, 'ISK', 'is-IS')).toBe('2.800\u00a0kr.');
|
|
54
54
|
expect(formatMoney(28, 'USD', 'en-US')).toBe('$28.00');
|
|
55
|
-
// `is-IS`
|
|
56
|
-
expect(formatMoney(28, 'USD', 'is-IS')).toBe('28,00\
|
|
55
|
+
// `is-IS`'s wide sign for dollars is the code itself.
|
|
56
|
+
expect(formatMoney(28, 'USD', 'is-IS')).toBe('28,00\u00a0USD');
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
it('is `@eldrajs/ui`’s own `formatCurrency`, not a second copy of it', () => {
|
|
60
|
-
// Asserted as an identity across every usable pair the theme can see — with the same
|
|
60
|
+
// Asserted as an identity across every usable pair the theme can see — with the same wide
|
|
61
61
|
// sign and the same fraction arguments this module passes — so the day the package's
|
|
62
62
|
// formatter changes, this module follows it instead of drifting from it.
|
|
63
63
|
for (const [currency, digits] of [
|
|
@@ -67,7 +67,7 @@ describe('formatMoney', () => {
|
|
|
67
67
|
] as const) {
|
|
68
68
|
for (const locale of ['en-US', 'is-IS']) {
|
|
69
69
|
expect(formatMoney(2800.5, currency, locale)).toBe(
|
|
70
|
-
formatCurrency(2800.5, locale, currency,
|
|
70
|
+
formatCurrency(2800.5, locale, currency, false, digits, digits)
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -135,13 +135,12 @@ describe('toMinorUnits', () => {
|
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
describe('currencyLabel', () => {
|
|
138
|
-
it('names the currency as code plus its
|
|
139
|
-
//
|
|
140
|
-
// English one (the narrow sign for krónur — the wide one there *is* the code).
|
|
138
|
+
it('names the currency as code plus the sign its prices carry, in the given locale', () => {
|
|
139
|
+
// English krónur and Icelandic dollars are written with the code itself, so the label is the code.
|
|
141
140
|
expect(currencyLabel('ISK', 'is-IS')).toBe('ISK kr.');
|
|
142
|
-
expect(currencyLabel('ISK', 'en-US')).toBe('ISK
|
|
141
|
+
expect(currencyLabel('ISK', 'en-US')).toBe('ISK');
|
|
143
142
|
expect(currencyLabel('USD', 'en-US')).toBe('USD $');
|
|
144
|
-
expect(currencyLabel('USD', 'is-IS')).toBe('USD
|
|
143
|
+
expect(currencyLabel('USD', 'is-IS')).toBe('USD');
|
|
145
144
|
expect(currencyLabel('EUR', 'en-US')).toBe('EUR €');
|
|
146
145
|
});
|
|
147
146
|
|
|
@@ -19,7 +19,7 @@ describe('useBlockData', () => {
|
|
|
19
19
|
// Block field metadata is a module-level registry (theme-core's
|
|
20
20
|
// registerBlockFields) — reset it so a test that registers a block
|
|
21
21
|
// never leaks into the next one.
|
|
22
|
-
registerBlockFields({});
|
|
22
|
+
registerBlockFields({}, 'starter');
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
it('exposes the typed data and the entry id', () => {
|
|
@@ -31,9 +31,12 @@ describe('useBlockData', () => {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
it('field() wraps useEldraBlockField, threading the block apiId through', () => {
|
|
34
|
-
registerBlockFields(
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
registerBlockFields(
|
|
35
|
+
{
|
|
36
|
+
hero: [{ fieldId: 'heading', type: 'string', localized: true }],
|
|
37
|
+
},
|
|
38
|
+
'starter'
|
|
39
|
+
);
|
|
37
40
|
const { field } = useBlockData({ entry }, 'hero');
|
|
38
41
|
expect(field('heading')).toEqual({ localized: true });
|
|
39
42
|
expect(field('align')).toEqual({ localized: false });
|