@recipe-book/react 0.1.0 → 0.1.2
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 +76 -0
- package/README.md +6 -4
- package/core/package.json +5 -0
- package/core/schema-org/package.json +5 -0
- package/dist/core/schema-org.cjs +25 -0
- package/dist/core/schema-org.cjs.map +1 -0
- package/dist/core/schema-org.d.cts +1 -0
- package/dist/core/schema-org.d.ts +1 -0
- package/dist/core/schema-org.js +3 -0
- package/dist/core/schema-org.js.map +1 -0
- package/dist/core.cjs +25 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +1 -0
- package/dist/core.d.ts +1 -0
- package/dist/core.js +3 -0
- package/dist/core.js.map +1 -0
- package/dist/index.cjs +204 -166
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +744 -109
- package/dist/index.d.ts +744 -109
- package/dist/index.js +164 -140
- package/dist/index.js.map +1 -1
- package/package.json +27 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,81 @@
|
|
|
1
1
|
# @recipe-book/react
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- `docsUrl`, and the link at the end of every error message, now end with a slash, such as `https://recipe-book.siraj.page/errors/unknown_unit/`, so they open the page without a redirect. ([#1377](https://github.com/SirajChokshi/recipe-book/pull/1377) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
8
|
+
|
|
9
|
+
- `RecipeBookError` now sets `cause` from its options in browsers whose built-in `Error` ignores them. ([#1217](https://github.com/SirajChokshi/recipe-book/pull/1217) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
10
|
+
|
|
11
|
+
- In Chrome and Edge before 93, Firefox before 91, and Safari before 15, `error.cause` was `undefined`.
|
|
12
|
+
|
|
13
|
+
- The TSDoc for core's conversion, format, and resolve functions now says which inputs pass through an error thrown by a getter or proxy. ([#1368](https://github.com/SirajChokshi/recipe-book/pull/1368) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
14
|
+
|
|
15
|
+
- The input and options: `resolveIngredient`, `formatQuantity`, `formatQuantityToParts`, `formatIngredient`, `formatServings`, `formatYield`, and `formatTemperature`.
|
|
16
|
+
- The input: `scaleQuantity`, `convert`, `toSystem`, and `convertTemperature`.
|
|
17
|
+
- The options: `segmentStepText`, `formatDuration`, and `toJsonLd`.
|
|
18
|
+
|
|
19
|
+
- Add `isRecipeValidationError`, which checks whether a caught value is a `RecipeValidationError` and narrows its type, so `issues` needs no cast. ([#1266](https://github.com/SirajChokshi/recipe-book/pull/1266) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
20
|
+
|
|
21
|
+
- It checks the error's `name`, `code`, and `issues` rather than using `instanceof`, so it also recognizes errors from another installed copy of `@recipe-book/core`, as `isRecipeBookError` does.
|
|
22
|
+
|
|
23
|
+
- Add `ParsedRecipe`, the same type as `Recipe` under another name. ([#924](https://github.com/SirajChokshi/recipe-book/pull/924) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
24
|
+
|
|
25
|
+
- A file that imports `@recipe-book/react` as `Recipe` can import `ParsedRecipe` from `@recipe-book/react/core` instead of renaming the type with `import type { Recipe as ParsedRecipe }`.
|
|
26
|
+
|
|
27
|
+
- Development warnings and React DevTools name each part as you write it, such as `Recipe.Step`, instead of the name the published build gave it, such as `ForwardRef(Step2)`. ([#1092](https://github.com/SirajChokshi/recipe-book/pull/1092) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
28
|
+
|
|
29
|
+
- Component stacks in React 18 and 19 use the same names, such as `at Recipe.Step` instead of `at Step2`. The provider is `Recipe.RecipeBookProvider`.
|
|
30
|
+
- Warnings about an `asChild` child, such as one that can't take a ref or children without keys, name `Slot` instead of `ForwardRef(Slot2)`.
|
|
31
|
+
- Production builds leave the names out.
|
|
32
|
+
|
|
33
|
+
- `parseRecipe` and `recipeSchema` now list `duplicate_id` warnings in input order when a repeated section id follows repeated item ids in earlier sections. ([#1221](https://github.com/SirajChokshi/recipe-book/pull/1221) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
34
|
+
|
|
35
|
+
- Before, when no other issue came between them, the section's warning came before the items' warnings.
|
|
36
|
+
|
|
37
|
+
- The TSDoc for `ResolvedRecipe.servings` and `yield` now says that at a scale within 1e-9 of 1, including one the `servings` option sets, they're the authored servings and yield. ([#1368](https://github.com/SirajChokshi/recipe-book/pull/1368) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
38
|
+
|
|
39
|
+
- In development, the summary `<Recipe.Root>` logs before its `parse` warnings now links the Issue codes table, which gives the fix for each warning's code. ([#954](https://github.com/SirajChokshi/recipe-book/pull/954) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
40
|
+
|
|
41
|
+
- The summary now reads: `Recipe Book: "Buttermilk pancakes" has 1 warning. It still renders. https://recipe-book.siraj.page/errors/#issue-codes gives the fix for each warning's code.`
|
|
42
|
+
- Only the text changes, and only in development. If a test matches the old summary, update it.
|
|
43
|
+
|
|
44
|
+
- On React 18, a part with `asChild` no longer makes React warn that function components cannot be given refs when its child is a function component and you pass the part no `ref`. ([#1329](https://github.com/SirajChokshi/recipe-book/pull/1329) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
45
|
+
|
|
46
|
+
- The arrow keys in `<Recipe.SystemToggle>` now follow the toggle's computed CSS `direction` instead of the nearest `dir` attribute, so Left Arrow and Right Arrow also swap under CSS `direction: rtl` and under `dir="auto"` on right-to-left text, no longer swap under CSS `direction: ltr` inside `dir="rtl"`, and no longer depend on the focused option's own `dir`. ([#1339](https://github.com/SirajChokshi/recipe-book/pull/1339) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
47
|
+
|
|
48
|
+
- `segmentStepText` no longer reads a "-" right after a number with no unit of its own, or with only a degree sign, as a minus sign. ([#919](https://github.com/SirajChokshi/recipe-book/pull/919) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
49
|
+
|
|
50
|
+
- In `Bake at 350 -375°F.` and `Bake at 350° -375°F.`, it read the second end as a negative temperature, −375 °F. Such a range now stays text, as `350–375°F` does.
|
|
51
|
+
- After a unit, as in `350°F -375°F`, the "-" is still a minus sign.
|
|
52
|
+
|
|
53
|
+
## 0.1.1
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- `<Recipe.Ingredient>` and the function `useFormatIngredient()` returns now throw a `RecipeBookError` with code `invalid_argument` for an item that isn't `{ ingredient, quantity? }`, such as `{}`, `null`, or an authored ingredient, instead of a bare `TypeError`. ([#925](https://github.com/SirajChokshi/recipe-book/pull/925) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
58
|
+
|
|
59
|
+
- The error is the one `formatIngredient` from `@recipe-book/react/core` throws: its message says what it expects and what it received, and links to the error's page.
|
|
60
|
+
|
|
61
|
+
- Passing `dangerouslySetInnerHTML` to a part that always renders content now fails typecheck instead of throwing when React renders it. ([#906](https://github.com/SirajChokshi/recipe-book/pull/906) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
62
|
+
|
|
63
|
+
- That's every part except four. `<Recipe.Root>` and `<Recipe.JsonLd>` already failed typecheck with it. `<Recipe.Image>` and `<Recipe.ServingsInput>` still typecheck with it, as a plain `<img>` or `<input>` does, and React still throws when it renders them.
|
|
64
|
+
- A wrapper that spreads its element's props into a part typechecks as before.
|
|
65
|
+
|
|
66
|
+
- Add `@recipe-book/react/core` and `@recipe-book/react/core/schema-org`, which re-export `@recipe-book/core` and `@recipe-book/core/schema-org`, so a React app installs one package. ([#888](https://github.com/SirajChokshi/recipe-book/pull/888) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
67
|
+
|
|
68
|
+
- The re-exports are core's own values, not copies. While an app's `@recipe-book/core` is on the same version as `@recipe-book/react`, the two packages share one copy of core, so code can mix imports from both. With different versions, the app gets a second copy of core.
|
|
69
|
+
- Neither is a `'use client'` module, so in a Server Component `parseRecipe`, `toJsonLd`, and core's other functions run on the server, as they do from core.
|
|
70
|
+
- `@recipe-book/react` still re-exports nothing from core, and its parts and hooks stay client references.
|
|
71
|
+
- Errors that said to call `parseRecipe()` or `formatIngredient()` from `@recipe-book/core` now name `@recipe-book/react/core`.
|
|
72
|
+
|
|
73
|
+
- `setServings`, `servings`, and `defaultServings` accept a number at either end of the servings window, such as 700000 for a recipe with 0.7 servings, as `resolveRecipe` now does. ([#911](https://github.com/SirajChokshi/recipe-book/pull/911) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
74
|
+
|
|
75
|
+
- The development warning for a number outside the window rounds the bounds it names to six digits inside the window, so it never names a number that's rejected: for a recipe with ⅔ servings, it names 666666 rather than 666667.
|
|
76
|
+
|
|
77
|
+
- `SystemOption` now sets `autoComplete="off"`, so when going back reloads the page, Firefox no longer re-enables an option that the server rendered disabled and the page enabled later, and its new `autoComplete` prop lets you pass your own value. ([#905](https://github.com/SirajChokshi/recipe-book/pull/905) by [@SirajChokshi](https://github.com/SirajChokshi))
|
|
78
|
+
|
|
3
79
|
## 0.1.0
|
|
4
80
|
|
|
5
81
|
- `<Recipe.Root>` holds a parsed recipe's servings and measurement system, controlled or not, and `useRecipe()` reads them. `useRecipeState()` does the same without a Root. With `parse={parseRecipe}`, a Root parses recipe input in the browser.
|
package/README.md
CHANGED
|
@@ -5,15 +5,17 @@ Unstyled React components for recipes. Scale servings, switch between metric and
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
npm i @recipe-book/react
|
|
8
|
+
npm i @recipe-book/react
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
Core's functions and types, such as `parseRecipe`, come from `@recipe-book/react/core`, so you don't install `@recipe-book/core` yourself. If your app also installs `@recipe-book/core`, keep it on the same version as `@recipe-book/react`, or the app gets a second copy of core.
|
|
12
|
+
|
|
11
13
|
## Usage
|
|
12
14
|
|
|
13
|
-
Parse recipe input with `parseRecipe`
|
|
15
|
+
Parse recipe input with `parseRecipe` and pass the parsed recipe to `<Recipe.Root>`. The parts inside it render the recipe at the chosen servings and measurement system.
|
|
14
16
|
|
|
15
17
|
```tsx
|
|
16
|
-
import { parseRecipe } from '@recipe-book/core'
|
|
18
|
+
import { parseRecipe } from '@recipe-book/react/core'
|
|
17
19
|
import * as Recipe from '@recipe-book/react'
|
|
18
20
|
|
|
19
21
|
const result = parseRecipe({
|
|
@@ -47,7 +49,7 @@ export function Pancakes() {
|
|
|
47
49
|
}
|
|
48
50
|
```
|
|
49
51
|
|
|
50
|
-
Parse where you load the recipe, such as in a Server Component or at build time, so the parser stays out of the browser bundle. With Next.js, and with Vite when each page loads as its own chunk, such as a lazy route, a page that parses in the browser with `import { parseRecipe } from '@recipe-book/core'` doesn't put the parser on other pages. Otherwise, such as with esbuild's code splitting or with Vite without lazy routes, parse on the server on every page: one page that parses in the browser can put the parser on other pages. Calling `import('@recipe-book/core')` can also download it, as [Why parse on the server](https://recipe-book.siraj.page/guides/render-a-recipe-in-react/#why-parse-on-the-server) describes.
|
|
52
|
+
Parse where you load the recipe, such as in a Server Component or at build time, so the parser stays out of the browser bundle. [Render a recipe on the server](https://recipe-book.siraj.page/guides/render-a-recipe-on-the-server/) shows how with the Next.js App Router and Pages Router, React Router, Astro, and your own server. With Next.js, and with Vite when each page loads as its own chunk, such as a lazy route, a page that parses in the browser with `import { parseRecipe } from '@recipe-book/react/core'` doesn't put the parser on other pages. Otherwise, such as with esbuild's code splitting or with Vite without lazy routes, parse on the server on every page: one page that parses in the browser can put the parser on other pages. Calling `import('@recipe-book/react/core')` can also download it, as [Why parse on the server](https://recipe-book.siraj.page/guides/render-a-recipe-in-react/#why-parse-on-the-server) describes.
|
|
51
53
|
|
|
52
54
|
## Documentation
|
|
53
55
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
|
|
17
|
+
// src/core/schema-org.ts
|
|
18
|
+
var schema_org_exports = {};
|
|
19
|
+
module.exports = __toCommonJS(schema_org_exports);
|
|
20
|
+
__reExport(schema_org_exports, require("@recipe-book/core/schema-org"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("@recipe-book/core/schema-org")
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=schema-org.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/schema-org.ts"],"sourcesContent":["export * from '@recipe-book/core/schema-org'\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,yCAAd;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@recipe-book/core/schema-org';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@recipe-book/core/schema-org';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/schema-org.ts"],"sourcesContent":["export * from '@recipe-book/core/schema-org'\n"],"mappings":";AAAA,cAAc;","names":[]}
|
package/dist/core.cjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
|
|
17
|
+
// src/core.ts
|
|
18
|
+
var core_exports = {};
|
|
19
|
+
module.exports = __toCommonJS(core_exports);
|
|
20
|
+
__reExport(core_exports, require("@recipe-book/core"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("@recipe-book/core")
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=core.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core.ts"],"sourcesContent":["export * from '@recipe-book/core'\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,yBAAc,8BAAd;","names":[]}
|
package/dist/core.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@recipe-book/core';
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@recipe-book/core';
|
package/dist/core.js
ADDED
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core.ts"],"sourcesContent":["export * from '@recipe-book/core'\n"],"mappings":";AAAA,cAAc;","names":[]}
|