@mui/internal-docs-infra 0.2.3-canary.7 → 0.2.3-canary.9

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.
Files changed (2) hide show
  1. package/esm/useCode/Pre.js +31 -45
  2. package/package.json +3 -3
@@ -9,6 +9,35 @@ import { decompressSync, strFromU8 } from 'fflate';
9
9
  import { decode } from 'uint8-to-base64';
10
10
  import { hastToJsx } from "../pipeline/hastUtils/index.js";
11
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
+ var hastChildrenCache = new WeakMap();
13
+ var textChildrenCache = new WeakMap();
14
+ function renderCode(hastChildren, renderHast, text) {
15
+ if (renderHast) {
16
+ var jsx = hastChildrenCache.get(hastChildren);
17
+ if (!jsx) {
18
+ jsx = hastToJsx({
19
+ type: 'root',
20
+ children: hastChildren
21
+ });
22
+ hastChildrenCache.set(hastChildren, jsx);
23
+ }
24
+ return jsx;
25
+ }
26
+ if (text !== undefined) {
27
+ return text;
28
+ }
29
+ var txt = textChildrenCache.get(hastChildren);
30
+ if (!txt) {
31
+ txt = toText({
32
+ type: 'root',
33
+ children: hastChildren
34
+ }, {
35
+ whitespace: 'pre'
36
+ });
37
+ textChildrenCache.set(hastChildren, txt);
38
+ }
39
+ return txt;
40
+ }
12
41
  export function Pre(_ref) {
13
42
  var children = _ref.children,
14
43
  className = _ref.className,
@@ -96,49 +125,6 @@ export function Pre(_ref) {
96
125
  observer.current.observe(node);
97
126
  }
98
127
  }, []);
99
- var hastChildrenCache = React.useMemo(function () {
100
- return hast == null ? void 0 : hast.children.map(function () {
101
- return null;
102
- });
103
- }, [hast]);
104
- var textChildrenCache = React.useMemo(function () {
105
- return hast == null ? void 0 : hast.children.map(function () {
106
- return null;
107
- });
108
- }, [hast]);
109
- var renderCode = React.useCallback(function (index, hastChildren, renderHast, text) {
110
- if (renderHast) {
111
- var _cached = hastChildrenCache == null ? void 0 : hastChildrenCache[index];
112
- if (_cached) {
113
- return _cached;
114
- }
115
- var jsx = hastToJsx({
116
- type: 'root',
117
- children: hastChildren
118
- });
119
- if (hastChildrenCache) {
120
- hastChildrenCache[index] = jsx;
121
- }
122
- return jsx;
123
- }
124
- if (text !== undefined) {
125
- return text;
126
- }
127
- var cached = textChildrenCache == null ? void 0 : textChildrenCache[index];
128
- if (cached) {
129
- return cached;
130
- }
131
- var txt = toText({
132
- type: 'root',
133
- children: hastChildren
134
- }, {
135
- whitespace: 'pre'
136
- });
137
- if (textChildrenCache) {
138
- textChildrenCache[index] = txt;
139
- }
140
- return txt;
141
- }, [hastChildrenCache, textChildrenCache]);
142
128
  var frames = React.useMemo(function () {
143
129
  return hast == null ? void 0 : hast.children.map(function (child, index) {
144
130
  if (child.type !== 'element') {
@@ -151,7 +137,7 @@ export function Pre(_ref) {
151
137
  className: "frame",
152
138
  "data-frame": index,
153
139
  ref: observeFrame,
154
- children: renderCode(index, child.children, shouldHighlight && isVisible, (_child$properties = child.properties) != null && _child$properties.dataAsString ? String((_child$properties2 = child.properties) == null ? void 0 : _child$properties2.dataAsString) : undefined)
140
+ children: renderCode(child.children, shouldHighlight && isVisible, (_child$properties = child.properties) != null && _child$properties.dataAsString ? String((_child$properties2 = child.properties) == null ? void 0 : _child$properties2.dataAsString) : undefined)
155
141
  }, index);
156
142
  }
157
143
  return /*#__PURE__*/_jsx(React.Fragment, {
@@ -160,7 +146,7 @@ export function Pre(_ref) {
160
146
  })
161
147
  }, index);
162
148
  });
163
- }, [hast, renderCode, observeFrame, shouldHighlight, visibleFrames]);
149
+ }, [hast, observeFrame, shouldHighlight, visibleFrames]);
164
150
  return /*#__PURE__*/_jsx("pre", {
165
151
  ref: bindIntersectionObserver,
166
152
  className: className,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-docs-infra",
3
- "version": "0.2.3-canary.7",
3
+ "version": "0.2.3-canary.9",
4
4
  "author": "MUI Team",
5
5
  "description": "MUI Infra - internal documentation creation tools.",
6
6
  "keywords": [
@@ -22,7 +22,7 @@
22
22
  "homepage": "https://github.com/mui/mui-public/tree/master/packages/docs-infra",
23
23
  "dependencies": {
24
24
  "@babel/runtime": "^7.28.4",
25
- "@babel/standalone": "^7.28.4",
25
+ "@babel/standalone": "^7.28.5",
26
26
  "@wooorm/starry-night": "^3.8.0",
27
27
  "clipboard-copy": "^4.0.1",
28
28
  "fflate": "^0.8.2",
@@ -56,7 +56,7 @@
56
56
  "engines": {
57
57
  "node": ">=22.12.0"
58
58
  },
59
- "gitSha": "57bff51a86f4e6cc6b4497e9b4a857d628598ec0",
59
+ "gitSha": "5e2086fe1de7af3c8403a2052ed42a98b66a4ab9",
60
60
  "type": "commonjs",
61
61
  "exports": {
62
62
  "./package.json": "./package.json",