@valbuild/react 0.119.0 → 0.120.3

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 CHANGED
@@ -1,5 +1,60 @@
1
1
  # @valbuild/react
2
2
 
3
+ ## 0.120.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`9b96184`](https://github.com/valbuild/val/commit/9b96184cf6ad6d52a714867fb1527eeec6c776f4), [`1a2484a`](https://github.com/valbuild/val/commit/1a2484a309679bd5e963d626466c2828f74d49f8), [`71becc7`](https://github.com/valbuild/val/commit/71becc7e543432e4a57e36d54aaf803e9a447ffd)]:
8
+ - @valbuild/ui@0.120.3
9
+
10
+ ## 0.120.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [#589](https://github.com/valbuild/val/pull/589) [`c2d3c0e`](https://github.com/valbuild/val/commit/c2d3c0e6c2010c0a94c725d9dbaa618998773e8a) Thanks [@freekh](https://github.com/freekh)! - **Breaking:** `s.richtext()` options are flat.
15
+
16
+ The `style`, `block` and `inline` groups are gone — every option is a key of its
17
+ own. The names are unchanged, so updating a schema is only a matter of removing
18
+ the wrappers:
19
+
20
+ ```ts
21
+ // before
22
+ s.richtext({
23
+ style: { bold: true, italic: true },
24
+ block: { h1: true, ul: true },
25
+ inline: { a: true, img: s.image() },
26
+ });
27
+
28
+ // after
29
+ s.richtext({
30
+ bold: true,
31
+ italic: true,
32
+ h1: true,
33
+ ul: true,
34
+ a: true,
35
+ img: s.image(),
36
+ });
37
+ ```
38
+
39
+ The groups never carried any meaning the option names did not already have, and
40
+ they cost something real: an option name and its `ValRichText` theme key were
41
+ spelled differently (`block.h1` vs `theme.h1`), so the type that keeps a theme
42
+ exhaustive had to restate all thirteen options by hand. It is now a mapped type
43
+ over the options themselves — which also fixes an inconsistency in it: enabling
44
+ links with a schema (`a: s.route()`) rather than `a: true` now requires an `a`
45
+ key in the theme, the way `img` always has.
46
+
47
+ `ValRichText` themes were already flat and are unchanged. The serialized schema
48
+ that the server sends the Studio is flat too, so a project must not mix
49
+ `@valbuild/*` versions across this release.
50
+
51
+ ### Patch Changes
52
+
53
+ - Updated dependencies [[`c2d3c0e`](https://github.com/valbuild/val/commit/c2d3c0e6c2010c0a94c725d9dbaa618998773e8a)]:
54
+ - @valbuild/core@0.120.0
55
+ - @valbuild/shared@0.120.0
56
+ - @valbuild/ui@0.120.0
57
+
3
58
  ## 0.119.0
4
59
 
5
60
  ### Patch Changes
@@ -1,11 +1,23 @@
1
1
  import { RichTextNode as RichTextSourceNode, AllRichTextOptions, RichTextOptions, SelectorSource, Schema } from "@valbuild/core";
2
2
  import { CSSProperties, type JSX, ReactNode } from "react";
3
3
  import { RichText, StegaOfRichTextSource } from "../stega/index.js";
4
+ /**
5
+ * The tags that are in every richtext, whatever the options say: no option
6
+ * turns them on, so a theme never has to mention them.
7
+ */
4
8
  type DefaultThemes = Partial<{
5
9
  br: string | null;
6
10
  p: string | null;
7
11
  span: string | null;
8
12
  }>;
13
+ /**
14
+ * The class name of every tag or style that an option turns on. The keys are
15
+ * the option names themselves, which is what makes a theme exhaustive by
16
+ * construction: enable `italic` in the schema and `italic` becomes a required
17
+ * key here.
18
+ *
19
+ * `li` is the one key without an option of its own - it comes with `ul`/`ol`.
20
+ */
9
21
  type OptionalFields = {
10
22
  h1: string | null;
11
23
  h2: string | null;
@@ -22,7 +34,18 @@ type OptionalFields = {
22
34
  bold: string | null;
23
35
  italic: string | null;
24
36
  };
25
- type ThemeOptions<O extends RichTextOptions = AllRichTextOptions> = DefaultThemes & Pick<OptionalFields, (NonNullable<O["inline"]>["img"] extends true | Schema<SelectorSource> ? "img" : never) | (NonNullable<O["inline"]>["a"] extends true ? "a" : never) | (NonNullable<O["block"]>["ul"] extends true ? "ul" | "li" : never) | (NonNullable<O["block"]>["ol"] extends true ? "ol" | "li" : never) | (NonNullable<O["style"]>["lineThrough"] extends true ? "lineThrough" : never) | (NonNullable<O["style"]>["bold"] extends true ? "bold" : never) | (NonNullable<O["style"]>["italic"] extends true ? "italic" : never) | (NonNullable<O["block"]>["h1"] extends true ? "h1" : never) | (NonNullable<O["block"]>["h2"] extends true ? "h2" : never) | (NonNullable<O["block"]>["h3"] extends true ? "h3" : never) | (NonNullable<O["block"]>["h4"] extends true ? "h4" : never) | (NonNullable<O["block"]>["h5"] extends true ? "h5" : never) | (NonNullable<O["block"]>["h6"] extends true ? "h6" : never)>;
37
+ /** `a` and `img` are on when they carry a schema, not only when they are `true`. */
38
+ type IsEnabled<T> = T extends true ? true : T extends Schema<SelectorSource> ? true : false;
39
+ /** Every option name `O` turns on, plus `li` when it has a list. */
40
+ type EnabledThemeKeys<O extends RichTextOptions> = {
41
+ [K in keyof OptionalFields & keyof RichTextOptions]: IsEnabled<O[K]> extends true ? K : never;
42
+ }[keyof OptionalFields & keyof RichTextOptions] | (IsEnabled<O["ul"]> extends true ? "li" : IsEnabled<O["ol"]> extends true ? "li" : never);
43
+ /**
44
+ * The `theme` a `ValRichText` accepts for a given set of richtext options: a
45
+ * class name for every tag or style those options turn on, and nothing more.
46
+ * Every key is required, so forgetting one is a type error naming it.
47
+ */
48
+ export type ThemeOptions<O extends RichTextOptions = AllRichTextOptions> = DefaultThemes & Pick<OptionalFields, EnabledThemeKeys<O>>;
26
49
  type RichTextNode = StegaOfRichTextSource<RichTextSourceNode<AllRichTextOptions>>;
27
50
  /**
28
51
  * Render RichText using JSX
@@ -49,12 +72,8 @@ type RichTextNode = StegaOfRichTextSource<RichTextSourceNode<AllRichTextOptions>
49
72
  * <ValRichText
50
73
  * content={content.myRichText}
51
74
  * theme={{
52
- * block: {
53
- * h1: 'text-4xl font-bold',
54
- * },
55
- * inline: {
56
- * img: 'rounded',
57
- * }
75
+ * h1: 'text-4xl font-bold',
76
+ * img: 'rounded',
58
77
  * }}
59
78
  * transform={(node, className) => {
60
79
  * if (node.tag === 'img') {
@@ -214,7 +214,7 @@ function resolveLiteralUnionSchema(source, schema) {
214
214
  /**
215
215
  * The image schema of a richtext's inline images.
216
216
  *
217
- * `inline.img` serializes as `true` when the author did not pass a schema, so
217
+ * `img` serializes as `true` when the author did not pass a schema, so
218
218
  * there is nothing to hand down; a bare `{type: "image"}` is enough, since all
219
219
  * the media branch needs is to know that it is looking at media.
220
220
  */
@@ -223,7 +223,7 @@ function inlineImageSchemaOf(schema) {
223
223
  if ((schema === null || schema === void 0 ? void 0 : schema.type) !== "richtext") {
224
224
  return undefined;
225
225
  }
226
- var img = (_schema$options = schema.options) === null || _schema$options === void 0 || (_schema$options = _schema$options.inline) === null || _schema$options === void 0 ? void 0 : _schema$options.img;
226
+ var img = (_schema$options = schema.options) === null || _schema$options === void 0 ? void 0 : _schema$options.img;
227
227
  if (!img) {
228
228
  return undefined;
229
229
  }
@@ -216,7 +216,7 @@ function resolveLiteralUnionSchema(source, schema) {
216
216
  /**
217
217
  * The image schema of a richtext's inline images.
218
218
  *
219
- * `inline.img` serializes as `true` when the author did not pass a schema, so
219
+ * `img` serializes as `true` when the author did not pass a schema, so
220
220
  * there is nothing to hand down; a bare `{type: "image"}` is enough, since all
221
221
  * the media branch needs is to know that it is looking at media.
222
222
  */
@@ -225,7 +225,7 @@ function inlineImageSchemaOf(schema) {
225
225
  if ((schema === null || schema === void 0 ? void 0 : schema.type) !== "richtext") {
226
226
  return undefined;
227
227
  }
228
- var img = (_schema$options = schema.options) === null || _schema$options === void 0 || (_schema$options = _schema$options.inline) === null || _schema$options === void 0 ? void 0 : _schema$options.img;
228
+ var img = (_schema$options = schema.options) === null || _schema$options === void 0 ? void 0 : _schema$options.img;
229
229
  if (!img) {
230
230
  return undefined;
231
231
  }
@@ -214,7 +214,7 @@ function resolveLiteralUnionSchema(source, schema) {
214
214
  /**
215
215
  * The image schema of a richtext's inline images.
216
216
  *
217
- * `inline.img` serializes as `true` when the author did not pass a schema, so
217
+ * `img` serializes as `true` when the author did not pass a schema, so
218
218
  * there is nothing to hand down; a bare `{type: "image"}` is enough, since all
219
219
  * the media branch needs is to know that it is looking at media.
220
220
  */
@@ -223,7 +223,7 @@ function inlineImageSchemaOf(schema) {
223
223
  if ((schema === null || schema === void 0 ? void 0 : schema.type) !== "richtext") {
224
224
  return undefined;
225
225
  }
226
- var img = (_schema$options = schema.options) === null || _schema$options === void 0 || (_schema$options = _schema$options.inline) === null || _schema$options === void 0 ? void 0 : _schema$options.img;
226
+ var img = (_schema$options = schema.options) === null || _schema$options === void 0 ? void 0 : _schema$options.img;
227
227
  if (!img) {
228
228
  return undefined;
229
229
  }
@@ -214,7 +214,7 @@ function resolveLiteralUnionSchema(source, schema) {
214
214
  /**
215
215
  * The image schema of a richtext's inline images.
216
216
  *
217
- * `inline.img` serializes as `true` when the author did not pass a schema, so
217
+ * `img` serializes as `true` when the author did not pass a schema, so
218
218
  * there is nothing to hand down; a bare `{type: "image"}` is enough, since all
219
219
  * the media branch needs is to know that it is looking at media.
220
220
  */
@@ -223,7 +223,7 @@ function inlineImageSchemaOf(schema) {
223
223
  if ((schema === null || schema === void 0 ? void 0 : schema.type) !== "richtext") {
224
224
  return undefined;
225
225
  }
226
- var img = (_schema$options = schema.options) === null || _schema$options === void 0 || (_schema$options = _schema$options.inline) === null || _schema$options === void 0 ? void 0 : _schema$options.img;
226
+ var img = (_schema$options = schema.options) === null || _schema$options === void 0 ? void 0 : _schema$options.img;
227
227
  if (!img) {
228
228
  return undefined;
229
229
  }
@@ -216,7 +216,7 @@ function resolveLiteralUnionSchema(source, schema) {
216
216
  /**
217
217
  * The image schema of a richtext's inline images.
218
218
  *
219
- * `inline.img` serializes as `true` when the author did not pass a schema, so
219
+ * `img` serializes as `true` when the author did not pass a schema, so
220
220
  * there is nothing to hand down; a bare `{type: "image"}` is enough, since all
221
221
  * the media branch needs is to know that it is looking at media.
222
222
  */
@@ -225,7 +225,7 @@ function inlineImageSchemaOf(schema) {
225
225
  if ((schema === null || schema === void 0 ? void 0 : schema.type) !== "richtext") {
226
226
  return undefined;
227
227
  }
228
- var img = (_schema$options = schema.options) === null || _schema$options === void 0 || (_schema$options = _schema$options.inline) === null || _schema$options === void 0 ? void 0 : _schema$options.img;
228
+ var img = (_schema$options = schema.options) === null || _schema$options === void 0 ? void 0 : _schema$options.img;
229
229
  if (!img) {
230
230
  return undefined;
231
231
  }
@@ -1,4 +1,4 @@
1
- import { d as _objectSpread2, r as raw, c as attrs, e as _toConsumableArray } from '../../dist/raw-d07598da.browser.esm.js';
1
+ import { d as _objectSpread2, r as raw, c as attrs, e as _toConsumableArray } from '../../dist/raw-76ccee5c.browser.esm.js';
2
2
  import React from 'react';
3
3
  import { jsx } from 'react/jsx-runtime';
4
4
  import '../../dist/slicedToArray-9cce0d9f.browser.esm.js';
@@ -53,12 +53,8 @@ var _excluded = ["className", "style", "theme", "transform"];
53
53
  * <ValRichText
54
54
  * content={content.myRichText}
55
55
  * theme={{
56
- * block: {
57
- * h1: 'text-4xl font-bold',
58
- * },
59
- * inline: {
60
- * img: 'rounded',
61
- * }
56
+ * h1: 'text-4xl font-bold',
57
+ * img: 'rounded',
62
58
  * }}
63
59
  * transform={(node, className) => {
64
60
  * if (node.tag === 'img') {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var raw = require('../../dist/raw-97c845bb.cjs.dev.js');
5
+ var raw = require('../../dist/raw-44cf5d7f.cjs.dev.js');
6
6
  var React = require('react');
7
7
  var ReactJSXRuntime = require('react/jsx-runtime');
8
8
  require('../../dist/slicedToArray-e9e8e991.cjs.dev.js');
@@ -61,12 +61,8 @@ var _excluded = ["className", "style", "theme", "transform"];
61
61
  * <ValRichText
62
62
  * content={content.myRichText}
63
63
  * theme={{
64
- * block: {
65
- * h1: 'text-4xl font-bold',
66
- * },
67
- * inline: {
68
- * img: 'rounded',
69
- * }
64
+ * h1: 'text-4xl font-bold',
65
+ * img: 'rounded',
70
66
  * }}
71
67
  * transform={(node, className) => {
72
68
  * if (node.tag === 'img') {
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var raw = require('../../dist/raw-cb20d03c.cjs.prod.js');
5
+ var raw = require('../../dist/raw-c75f7272.cjs.prod.js');
6
6
  var React = require('react');
7
7
  var ReactJSXRuntime = require('react/jsx-runtime');
8
8
  require('../../dist/slicedToArray-86004d59.cjs.prod.js');
@@ -61,12 +61,8 @@ var _excluded = ["className", "style", "theme", "transform"];
61
61
  * <ValRichText
62
62
  * content={content.myRichText}
63
63
  * theme={{
64
- * block: {
65
- * h1: 'text-4xl font-bold',
66
- * },
67
- * inline: {
68
- * img: 'rounded',
69
- * }
64
+ * h1: 'text-4xl font-bold',
65
+ * img: 'rounded',
70
66
  * }}
71
67
  * transform={(node, className) => {
72
68
  * if (node.tag === 'img') {
@@ -1,4 +1,4 @@
1
- import { d as _objectSpread2, r as raw, c as attrs, e as _toConsumableArray } from '../../dist/raw-e467df42.esm.js';
1
+ import { d as _objectSpread2, r as raw, c as attrs, e as _toConsumableArray } from '../../dist/raw-8453ef90.esm.js';
2
2
  import React from 'react';
3
3
  import { jsx } from 'react/jsx-runtime';
4
4
  import '../../dist/slicedToArray-0c0a3b4a.esm.js';
@@ -53,12 +53,8 @@ var _excluded = ["className", "style", "theme", "transform"];
53
53
  * <ValRichText
54
54
  * content={content.myRichText}
55
55
  * theme={{
56
- * block: {
57
- * h1: 'text-4xl font-bold',
58
- * },
59
- * inline: {
60
- * img: 'rounded',
61
- * }
56
+ * h1: 'text-4xl font-bold',
57
+ * img: 'rounded',
62
58
  * }}
63
59
  * transform={(node, className) => {
64
60
  * if (node.tag === 'img') {
@@ -1,4 +1,4 @@
1
- import { d as _objectSpread2, r as raw, c as attrs, e as _toConsumableArray } from '../../dist/raw-c3e48d09.worker.esm.js';
1
+ import { d as _objectSpread2, r as raw, c as attrs, e as _toConsumableArray } from '../../dist/raw-0c1fab1c.worker.esm.js';
2
2
  import React from 'react';
3
3
  import { jsx } from 'react/jsx-runtime';
4
4
  import '../../dist/slicedToArray-7d0170b6.worker.esm.js';
@@ -53,12 +53,8 @@ var _excluded = ["className", "style", "theme", "transform"];
53
53
  * <ValRichText
54
54
  * content={content.myRichText}
55
55
  * theme={{
56
- * block: {
57
- * h1: 'text-4xl font-bold',
58
- * },
59
- * inline: {
60
- * img: 'rounded',
61
- * }
56
+ * h1: 'text-4xl font-bold',
57
+ * img: 'rounded',
62
58
  * }}
63
59
  * transform={(node, className) => {
64
60
  * if (node.tag === 'img') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/react",
3
- "version": "0.119.0",
3
+ "version": "0.120.3",
4
4
  "private": false,
5
5
  "description": "Val - React internal helpers",
6
6
  "repository": {
@@ -11,9 +11,9 @@
11
11
  "dependencies": {
12
12
  "@vercel/stega": "^1.1.0",
13
13
  "base64-arraybuffer": "^1.0.2",
14
- "@valbuild/core": "0.117.0",
15
- "@valbuild/ui": "0.119.0",
16
- "@valbuild/shared": "0.118.0"
14
+ "@valbuild/ui": "0.120.3",
15
+ "@valbuild/core": "0.120.0",
16
+ "@valbuild/shared": "0.120.0"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@testing-library/react": "^16.3.3",
@@ -1,6 +1,6 @@
1
1
  import { a as _typeof, _ as _slicedToArray } from '../../dist/slicedToArray-9cce0d9f.browser.esm.js';
2
- import { s as stegaDecodeStrings, _ as _createForOfIteratorHelper } from '../../dist/raw-d07598da.browser.esm.js';
3
- export { c as attrs, g as getModuleIds, r as raw, b as stegaClean, s as stegaDecodeStrings, a as stegaEncode } from '../../dist/raw-d07598da.browser.esm.js';
2
+ import { s as stegaDecodeStrings, _ as _createForOfIteratorHelper } from '../../dist/raw-76ccee5c.browser.esm.js';
3
+ export { c as attrs, g as getModuleIds, r as raw, b as stegaClean, s as stegaDecodeStrings, a as stegaEncode } from '../../dist/raw-76ccee5c.browser.esm.js';
4
4
  import ReactJSXRuntime__default from 'react/jsx-runtime';
5
5
  import jsxRuntimeDev__default from 'react/jsx-dev-runtime';
6
6
  import React from 'react';
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var slicedToArray = require('../../dist/slicedToArray-e9e8e991.cjs.dev.js');
6
- var raw = require('../../dist/raw-97c845bb.cjs.dev.js');
6
+ var raw = require('../../dist/raw-44cf5d7f.cjs.dev.js');
7
7
  var ReactJSXRuntime = require('react/jsx-runtime');
8
8
  var jsxRuntimeDev = require('react/jsx-dev-runtime');
9
9
  var React = require('react');
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var slicedToArray = require('../../dist/slicedToArray-86004d59.cjs.prod.js');
6
- var raw = require('../../dist/raw-cb20d03c.cjs.prod.js');
6
+ var raw = require('../../dist/raw-c75f7272.cjs.prod.js');
7
7
  var ReactJSXRuntime = require('react/jsx-runtime');
8
8
  var jsxRuntimeDev = require('react/jsx-dev-runtime');
9
9
  var React = require('react');
@@ -1,6 +1,6 @@
1
1
  import { a as _typeof, _ as _slicedToArray } from '../../dist/slicedToArray-0c0a3b4a.esm.js';
2
- import { s as stegaDecodeStrings, _ as _createForOfIteratorHelper } from '../../dist/raw-e467df42.esm.js';
3
- export { c as attrs, g as getModuleIds, r as raw, b as stegaClean, s as stegaDecodeStrings, a as stegaEncode } from '../../dist/raw-e467df42.esm.js';
2
+ import { s as stegaDecodeStrings, _ as _createForOfIteratorHelper } from '../../dist/raw-8453ef90.esm.js';
3
+ export { c as attrs, g as getModuleIds, r as raw, b as stegaClean, s as stegaDecodeStrings, a as stegaEncode } from '../../dist/raw-8453ef90.esm.js';
4
4
  import ReactJSXRuntime__default from 'react/jsx-runtime';
5
5
  import jsxRuntimeDev__default from 'react/jsx-dev-runtime';
6
6
  import React from 'react';
@@ -1,6 +1,6 @@
1
1
  import { a as _typeof, _ as _slicedToArray } from '../../dist/slicedToArray-7d0170b6.worker.esm.js';
2
- import { s as stegaDecodeStrings, _ as _createForOfIteratorHelper } from '../../dist/raw-c3e48d09.worker.esm.js';
3
- export { c as attrs, g as getModuleIds, r as raw, b as stegaClean, s as stegaDecodeStrings, a as stegaEncode } from '../../dist/raw-c3e48d09.worker.esm.js';
2
+ import { s as stegaDecodeStrings, _ as _createForOfIteratorHelper } from '../../dist/raw-0c1fab1c.worker.esm.js';
3
+ export { c as attrs, g as getModuleIds, r as raw, b as stegaClean, s as stegaDecodeStrings, a as stegaEncode } from '../../dist/raw-0c1fab1c.worker.esm.js';
4
4
  import ReactJSXRuntime__default from 'react/jsx-runtime';
5
5
  import jsxRuntimeDev__default from 'react/jsx-dev-runtime';
6
6
  import React from 'react';