@pie-lib/render-ui 8.0.6-next.20261015154938 → 8.0.6-next.20261016234357

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.
@@ -19,6 +19,8 @@ export declare class Collapsible extends React.Component {
19
19
  };
20
20
  panelId: string;
21
21
  toggleExpanded: any;
22
+ /** Re-renders once the item language's catalog lands, for an element that did not preload it. */
23
+ relabel: () => void;
22
24
  componentDidMount(): void;
23
25
  componentDidUpdate(): void;
24
26
  render(): React.JSX.Element;
@@ -1,14 +1,14 @@
1
1
  import { tertiary as e } from "../color.js";
2
- import { createUniqueId as t } from "../unique-id.js";
3
- import n from "react";
4
- import r from "prop-types";
5
- import { styled as i } from "@mui/material/styles";
6
- import { jsx as a, jsxs as o } from "react/jsx-runtime";
7
- import s from "@mui/material/Collapse";
8
- import { renderMath as c } from "@pie-element/shared-math-rendering-mathjax";
9
- import l from "@pie-lib/translator";
2
+ import { catalogs as t } from "../i18n/index.js";
3
+ import { createUniqueId as n } from "../unique-id.js";
4
+ import r from "react";
5
+ import i from "prop-types";
6
+ import { styled as a } from "@mui/material/styles";
7
+ import { jsx as o, jsxs as s } from "react/jsx-runtime";
8
+ import c from "@mui/material/Collapse";
9
+ import { renderMath as l } from "@pie-element/shared-math-rendering-mathjax";
10
10
  //#region src/collapsible/index.tsx
11
- var { translator: u } = l, d = i("button")({
11
+ var u = a("button")({
12
12
  display: "inline-block",
13
13
  minHeight: "24px",
14
14
  padding: 0,
@@ -18,53 +18,54 @@ var { translator: u } = l, d = i("button")({
18
18
  textAlign: "inherit",
19
19
  color: e(),
20
20
  cursor: "pointer"
21
- }), f = i("span")({ borderBottom: "1px dotted currentColor" }), p = i(s)(({ theme: e }) => ({ paddingTop: e.spacing(2) })), m = class extends n.Component {
21
+ }), d = a("span")({ borderBottom: "1px dotted currentColor" }), f = a(c)(({ theme: e }) => ({ paddingTop: e.spacing(2) })), p = class extends r.Component {
22
22
  static propTypes = {
23
- className: r.string,
24
- children: r.object,
25
- labels: r.shape({
26
- visible: r.string,
27
- hidden: r.string
23
+ className: i.string,
24
+ children: i.object,
25
+ labels: i.shape({
26
+ visible: i.string,
27
+ hidden: i.string
28
28
  }),
29
- language: r.string
29
+ language: i.string
30
30
  };
31
31
  static defaultProps = { labels: {} };
32
32
  state = { expanded: !1 };
33
- panelId = t("pie-collapsible");
33
+ panelId = n("pie-collapsible");
34
34
  toggleExpanded = () => {
35
35
  this.setState((e) => ({ expanded: !e.expanded }));
36
36
  };
37
+ relabel = () => this.forceUpdate();
37
38
  componentDidMount() {
38
- c(this.root);
39
+ l(this.root);
39
40
  }
40
41
  componentDidUpdate() {
41
- c(this.root);
42
+ l(this.root);
42
43
  }
43
44
  render() {
44
- let { labels: e, children: t, className: n, language: r } = this.props, { expanded: i } = this.state, s = i ? e.visible || u.t("common:hide", { lng: r }) : e.hidden || u.t("common:show", { lng: r });
45
- return /* @__PURE__ */ o("div", {
46
- className: n,
45
+ let { labels: e, children: n, className: r, language: i } = this.props, { expanded: a } = this.state, c = t.forLocale(i, this.relabel), l = a ? e.visible || c.t("hide") : e.hidden || c.t("show");
46
+ return /* @__PURE__ */ s("div", {
47
+ className: r,
47
48
  ref: (e) => this.root = e,
48
- children: [/* @__PURE__ */ a("div", { children: /* @__PURE__ */ a(d, {
49
+ children: [/* @__PURE__ */ o("div", { children: /* @__PURE__ */ o(u, {
49
50
  type: "button",
50
- "aria-expanded": i,
51
+ "aria-expanded": a,
51
52
  "aria-controls": this.panelId,
52
53
  onClick: this.toggleExpanded,
53
- children: /* @__PURE__ */ a(f, { children: s })
54
- }) }), /* @__PURE__ */ a("div", {
54
+ children: /* @__PURE__ */ o(d, { children: l })
55
+ }) }), /* @__PURE__ */ o("div", {
55
56
  id: this.panelId,
56
- children: /* @__PURE__ */ a(p, {
57
- in: i,
57
+ children: /* @__PURE__ */ o(f, {
58
+ in: a,
58
59
  timeout: {
59
60
  enter: 225,
60
61
  exit: 195
61
62
  },
62
63
  unmountOnExit: !0,
63
- children: t
64
+ children: n
64
65
  })
65
66
  })]
66
67
  });
67
68
  }
68
69
  };
69
70
  //#endregion
70
- export { m as Collapsible, m as default };
71
+ export { p as Collapsible, p as default };
@@ -0,0 +1,9 @@
1
+ /** The interface strings `@pie-lib/render-ui` renders itself; the source for every other locale. */
2
+ declare const _default: {
3
+ /** Accessible name of a prompt's custom audio play button. */
4
+ playAudio: string;
5
+ /** Default toggle labels of a collapsed and an expanded `Collapsible`. */
6
+ show: string;
7
+ hide: string;
8
+ };
9
+ export default _default;
@@ -0,0 +1,8 @@
1
+ //#region src/i18n/en-US.ts
2
+ var e = {
3
+ playAudio: "Play audio",
4
+ show: "Show",
5
+ hide: "Hide"
6
+ };
7
+ //#endregion
8
+ export { e as default };
@@ -0,0 +1,6 @@
1
+ declare const _default: {
2
+ playAudio: string;
3
+ show: string;
4
+ hide: string;
5
+ };
6
+ export default _default;
@@ -0,0 +1,8 @@
1
+ //#region src/i18n/es.ts
2
+ var e = {
3
+ playAudio: "Reproducir audio",
4
+ show: "Mostrar",
5
+ hide: "Ocultar"
6
+ };
7
+ //#endregion
8
+ export { e as default };
@@ -0,0 +1,5 @@
1
+ export declare const catalogs: import("@pie-element/shared-i18n").Catalogs<{
2
+ playAudio: string;
3
+ show: string;
4
+ hide: string;
5
+ }>;
@@ -0,0 +1,13 @@
1
+ import e from "./en-US.js";
2
+ import { defineCatalogs as t } from "@pie-element/shared-i18n";
3
+ //#region src/i18n/index.ts
4
+ var n = t({
5
+ packageName: "@pie-lib/render-ui",
6
+ source: e,
7
+ loaders: { es: () => import(
8
+ /* webpackMode: "eager" */
9
+ "./es.js"
10
+ ) }
11
+ });
12
+ //#endregion
13
+ export { n as catalogs };
@@ -8,6 +8,8 @@ export declare class PreviewPrompt extends Component {
8
8
  onClick: PropTypes.Requireable<(...args: any[]) => any>;
9
9
  defaultClassName: PropTypes.Requireable<string>;
10
10
  autoplayAudioEnabled: PropTypes.Requireable<boolean>;
11
+ /** Set by the item player when the toolkit holds autoplay; it outranks `autoplayAudioEnabled`. */
12
+ autoplayAudioHeld: PropTypes.Requireable<boolean>;
11
13
  customAudioButton: PropTypes.Requireable<PropTypes.InferProps<{
12
14
  playImage: PropTypes.Requireable<string>;
13
15
  pauseImage: PropTypes.Requireable<string>;
@@ -22,6 +24,12 @@ export declare class PreviewPrompt extends Component {
22
24
  audioId: string;
23
25
  playButtonId: string;
24
26
  parsedText: any;
27
+ /**
28
+ * Names the custom audio button on the live node. The name stays out of `parsedText`: a
29
+ * catalog landing after the first render would change the prompt's HTML, and React would
30
+ * replace the prompt, audio included, mid-playback.
31
+ */
32
+ labelPlayButton: () => void;
25
33
  addCustomAudioButtonControls(): void;
26
34
  removeCustomAudioButtonListeners(): void;
27
35
  componentDidMount(): void;
@@ -1,14 +1,14 @@
1
1
  import { focusOutline as e, tableGrid as t, tableStripe as n, text as r } from "./color.js";
2
- import { createUniqueId as i } from "./unique-id.js";
3
- import a, { Component as o } from "react";
4
- import s from "prop-types";
5
- import { styled as c } from "@mui/material/styles";
6
- import { PLAY_AUDIO_ATTR as l, sanitizeModelHtml as u } from "@pie-element/shared-utils";
7
- import { jsx as d } from "react/jsx-runtime";
8
- import { renderMath as f } from "@pie-element/shared-math-rendering-mathjax";
9
- import p from "@pie-lib/translator";
2
+ import { catalogs as i } from "./i18n/index.js";
3
+ import { createUniqueId as a } from "./unique-id.js";
4
+ import o, { Component as s } from "react";
5
+ import c from "prop-types";
6
+ import { styled as l } from "@mui/material/styles";
7
+ import { PLAY_AUDIO_ATTR as u, autoplayAudioOn as d, sanitizeModelHtml as f } from "@pie-element/shared-utils";
8
+ import { jsx as p } from "react/jsx-runtime";
9
+ import { renderMath as m } from "@pie-element/shared-math-rendering-mathjax";
10
10
  //#region src/preview-prompt.tsx
11
- var { translator: m } = p, h = "pie-prompt-audio-player", g = "play-audio-button", _ = (e) => `&:not(.MathJax) > table${e}, &:not(.MathJax) > .pie-table-scroll > table${e}`, v = c("div")(({ theme: i, tagName: a }) => ({
11
+ var h = "pie-prompt-audio-player", g = "play-audio-button", _ = (e) => `&:not(.MathJax) > table${e}, &:not(.MathJax) > .pie-table-scroll > table${e}`, v = l("div")(({ theme: i, tagName: a }) => ({
12
12
  [`& .${g}:focus-visible`]: {
13
13
  outline: `2px solid ${e()}`,
14
14
  outlineOffset: "2px"
@@ -45,35 +45,41 @@ var { translator: m } = p, h = "pie-prompt-audio-player", g = "play-audio-button
45
45
  cursor: "pointer",
46
46
  "& > p": { margin: "0 0 0 0 !important" }
47
47
  }
48
- })), y = /\\embed\{newLine\}\[\]/g, b = "\\newline ", x = "preview-prompt", S = class extends o {
48
+ })), y = /\\embed\{newLine\}\[\]/g, b = "\\newline ", x = "preview-prompt", S = class extends s {
49
49
  static propTypes = {
50
- prompt: s.string,
51
- tagName: s.string,
52
- className: s.string,
53
- onClick: s.func,
54
- defaultClassName: s.string,
55
- autoplayAudioEnabled: s.bool,
56
- customAudioButton: s.shape({
57
- playImage: s.string,
58
- pauseImage: s.string
50
+ prompt: c.string,
51
+ tagName: c.string,
52
+ className: c.string,
53
+ onClick: c.func,
54
+ defaultClassName: c.string,
55
+ autoplayAudioEnabled: c.bool,
56
+ autoplayAudioHeld: c.bool,
57
+ customAudioButton: c.shape({
58
+ playImage: c.string,
59
+ pauseImage: c.string
59
60
  }),
60
- language: s.string
61
+ language: c.string
61
62
  };
62
63
  static defaultProps = { onClick: () => {} };
63
- promptRef = a.createRef();
64
- audioId = i(h);
65
- playButtonId = i(g);
64
+ promptRef = o.createRef();
65
+ audioId = a(h);
66
+ playButtonId = a(g);
66
67
  parsedText = (e) => {
67
- let { autoplayAudioEnabled: t, customAudioButton: n, language: r } = this.props, i = document.createElement("div");
68
- i.innerHTML = u(e);
69
- let a = i.querySelector("audio");
70
- if (a) {
71
- let e = document.createElement("source");
72
- if (e.setAttribute("type", "audio/mp3"), e.setAttribute("src", a.getAttribute("src")), a.removeAttribute("src"), a.id) for (let e of i.querySelectorAll(`[${l}]`)) e.getAttribute(l) === a.id && e.setAttribute(l, this.audioId);
73
- if (a.id = this.audioId, a.classList.add(h), a.appendChild(e), n) {
74
- a.style.display = "none";
68
+ let { customAudioButton: t } = this.props, n = d(this.props), r = document.createElement("div");
69
+ r.innerHTML = f(e);
70
+ let i = r.querySelector("audio");
71
+ if (i) {
72
+ let e = i.getAttribute("src");
73
+ if (e) {
74
+ let t = document.createElement("source");
75
+ t.setAttribute("type", "audio/mp3"), t.setAttribute("src", e), i.removeAttribute("src"), i.appendChild(t);
76
+ }
77
+ let a = !1;
78
+ if (i.id) for (let e of r.querySelectorAll(`[${u}]`)) e.getAttribute(u) === i.id && (e.setAttribute(u, this.audioId), a = !0);
79
+ if (i.id = this.audioId, i.classList.add(h), !n && !t && !a && i.setAttribute("controls", ""), t) {
80
+ i.style.display = "none";
75
81
  let e = document.createElement("button");
76
- e.setAttribute("type", "button"), e.setAttribute("aria-label", m.t("common:playAudio", { lng: r })), e.id = this.playButtonId, e.className = g, Object.assign(e.style, {
82
+ e.setAttribute("type", "button"), e.id = this.playButtonId, e.className = g, Object.assign(e.style, {
77
83
  cursor: "pointer",
78
84
  display: "block",
79
85
  width: "128px",
@@ -82,48 +88,51 @@ var { translator: m } = p, h = "pie-prompt-audio-player", g = "play-audio-button
82
88
  padding: "0",
83
89
  font: "inherit",
84
90
  backgroundColor: "transparent",
85
- backgroundImage: `url(${t ? n.pauseImage : n.playImage})`,
91
+ backgroundImage: `url(${n ? t.pauseImage : t.playImage})`,
86
92
  backgroundSize: "cover",
87
93
  borderRadius: "50%",
88
94
  border: "1px solid #326295"
89
- }), a.parentNode.insertBefore(e, a);
95
+ }), i.parentNode.insertBefore(e, i);
90
96
  }
91
97
  }
92
- return i.innerHTML;
98
+ return r.innerHTML;
99
+ };
100
+ labelPlayButton = () => {
101
+ (this.promptRef.current?.querySelector(`.${g}`))?.setAttribute("aria-label", i.forLocale(this.props.language, this.labelPlayButton).t("playAudio"));
93
102
  };
94
103
  addCustomAudioButtonControls() {
95
- let { autoplayAudioEnabled: e, customAudioButton: t } = this.props, n = this.promptRef.current, r = n?.querySelector(`.${g}`), i = n?.querySelector(`.${h}`);
96
- if (e && i && i.play().then(() => {
97
- r && t && i.addEventListener("ended", o);
98
- }).catch((e) => {
99
- r && t && (r.style.backgroundImage = `url(${t.playImage})`), console.error("Error playing audio", e);
100
- }), !r || !i || !t) return;
101
- let a = () => {
102
- i.paused && i.play();
104
+ let { customAudioButton: e } = this.props, t = this.promptRef.current, n = t?.querySelector(`.${g}`), r = t?.querySelector(`.${h}`);
105
+ if (d(this.props) && r && r.play().then(() => {
106
+ n && e && r.addEventListener("ended", a);
107
+ }).catch((t) => {
108
+ n && e && (n.style.backgroundImage = `url(${e.playImage})`), console.error("Error playing audio", t);
109
+ }), !n || !r || !e) return;
110
+ let i = () => {
111
+ r.paused && r.play();
112
+ }, a = () => {
113
+ n.style.backgroundImage = `url(${e.playImage})`;
103
114
  }, o = () => {
104
- r.style.backgroundImage = `url(${t.playImage})`;
105
- }, s = () => {
106
- Object.assign(r.style, {
107
- backgroundImage: `url(${t.pauseImage})`,
115
+ Object.assign(n.style, {
116
+ backgroundImage: `url(${e.pauseImage})`,
108
117
  border: "1px solid #ccc"
109
118
  });
110
- }, c = () => {
111
- Object.assign(r.style, {
112
- backgroundImage: `url(${t.playImage})`,
119
+ }, s = () => {
120
+ Object.assign(n.style, {
121
+ backgroundImage: `url(${e.playImage})`,
113
122
  border: "1px solid #326295"
114
123
  });
115
124
  };
116
- r.addEventListener("click", a), i.addEventListener("play", s), i.addEventListener("pause", c), i.addEventListener("ended", o), this._playButton = r, this._audio = i, this._handlePlayClick = a, this._handleAudioPlay = s, this._handleAudioPause = c, this._handleAudioEnded = o;
125
+ n.addEventListener("click", i), r.addEventListener("play", o), r.addEventListener("pause", s), r.addEventListener("ended", a), this._playButton = n, this._audio = r, this._handlePlayClick = i, this._handleAudioPlay = o, this._handleAudioPause = s, this._handleAudioEnded = a;
117
126
  }
118
127
  removeCustomAudioButtonListeners() {
119
128
  let e = this._playButton, t = this._audio;
120
129
  !e || !t || (e.removeEventListener("click", this._handlePlayClick), t.removeEventListener("play", this._handleAudioPlay), t.removeEventListener("pause", this._handleAudioPause), t.removeEventListener("ended", this._handleAudioEnded));
121
130
  }
122
131
  componentDidMount() {
123
- this.alignImages(), this.addCustomAudioButtonControls(), this.setupMathRendering();
132
+ this.alignImages(), this.labelPlayButton(), this.addCustomAudioButtonControls(), this.setupMathRendering();
124
133
  }
125
134
  componentDidUpdate(e) {
126
- this.alignImages(), e.prompt !== this.props.prompt && this.renderMathContent();
135
+ this.alignImages(), this.labelPlayButton(), e.prompt !== this.props.prompt && this.renderMathContent();
127
136
  }
128
137
  componentWillUnmount() {
129
138
  this.removeCustomAudioButtonListeners();
@@ -133,7 +142,7 @@ var { translator: m } = p, h = "pie-prompt-audio-player", g = "play-audio-button
133
142
  }
134
143
  renderMathContent() {
135
144
  let e = this.promptRef.current;
136
- e && typeof f == "function" && f(e);
145
+ e && typeof m == "function" && m(e);
137
146
  }
138
147
  alignImages() {
139
148
  let e = this.promptRef.current;
@@ -154,7 +163,7 @@ var { translator: m } = p, h = "pie-prompt-audio-player", g = "play-audio-button
154
163
  }
155
164
  render() {
156
165
  let { prompt: e, tagName: t, className: n, onClick: r, defaultClassName: i } = this.props, a = `${n || ""} ${i || ""} ${t === "legend" ? "legend" : ""} ${x}`.trim();
157
- return /* @__PURE__ */ d(v, {
166
+ return /* @__PURE__ */ p(v, {
158
167
  as: t || "div",
159
168
  ref: this.promptRef,
160
169
  onClick: r,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/render-ui",
3
- "version": "8.0.6-next.20261015154938",
3
+ "version": "8.0.6-next.20261016234357",
4
4
  "description": "Some shared ui elements when rendering - but not worthy of their own package yet.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -13,13 +13,13 @@
13
13
  "@mui/icons-material": "^7.3.4",
14
14
  "@mui/material": "^7.3.4",
15
15
  "@pie-lib/icons": "5.0.2-next.20261006160832",
16
- "@pie-lib/translator": "5.0.2-next.20261006160832",
16
+ "@pie-element/shared-i18n": "0.1.1-next.20261016234357",
17
17
  "debug": "^4.1.1",
18
18
  "prop-types": "^15.7.2",
19
19
  "react-transition-group": "^4.4.5",
20
20
  "@pie-element/shared-math-rendering-mathjax": "0.1.7-next.20261015154938",
21
21
  "@pie-element/shared-lodash": "0.1.3-next.20261012213240",
22
- "@pie-element/shared-utils": "0.1.5-next.20261012213240"
22
+ "@pie-element/shared-utils": "0.1.5-next.20261016234357"
23
23
  },
24
24
  "type": "module",
25
25
  "main": "./dist/index.js",