@conloca/mdx 0.1.16 → 0.2.1

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 (91) hide show
  1. package/README.md +50 -16
  2. package/dist/code-block-frame.js +1 -0
  3. package/dist/code-block-frame.js.map +1 -0
  4. package/dist/editor-core.d.ts +0 -2
  5. package/dist/editor-core.d.ts.map +1 -1
  6. package/dist/editor-core.js +50 -6
  7. package/dist/editor-core.js.map +1 -0
  8. package/dist/esm-passthrough.d.ts +36 -0
  9. package/dist/esm-passthrough.d.ts.map +1 -0
  10. package/dist/esm-passthrough.js +237 -0
  11. package/dist/esm-passthrough.js.map +1 -0
  12. package/dist/fragments.d.ts +37 -0
  13. package/dist/fragments.d.ts.map +1 -0
  14. package/dist/fragments.js +53 -0
  15. package/dist/fragments.js.map +1 -0
  16. package/dist/index.d.ts +0 -2
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/index.js.map +1 -0
  20. package/dist/markdown-options.js +1 -0
  21. package/dist/markdown-options.js.map +1 -0
  22. package/dist/mdx/compile-request.d.ts +5 -0
  23. package/dist/mdx/compile-request.d.ts.map +1 -0
  24. package/dist/mdx/compile-request.js +40 -0
  25. package/dist/mdx/compile-request.js.map +1 -0
  26. package/dist/mdx/compile.d.ts.map +1 -1
  27. package/dist/mdx/compile.js +30 -1
  28. package/dist/mdx/compile.js.map +1 -0
  29. package/dist/mdx/evaluate.d.ts +18 -23
  30. package/dist/mdx/evaluate.d.ts.map +1 -1
  31. package/dist/mdx/evaluate.js +123 -29
  32. package/dist/mdx/evaluate.js.map +1 -0
  33. package/dist/mdx/heading-outline.d.ts +46 -0
  34. package/dist/mdx/heading-outline.d.ts.map +1 -0
  35. package/dist/mdx/heading-outline.js +114 -0
  36. package/dist/mdx/heading-outline.js.map +1 -0
  37. package/dist/mdx/literal-attributes.d.ts +26 -0
  38. package/dist/mdx/literal-attributes.d.ts.map +1 -0
  39. package/dist/mdx/literal-attributes.js +40 -0
  40. package/dist/mdx/literal-attributes.js.map +1 -0
  41. package/dist/mdx/restrict-expressions.d.ts +45 -0
  42. package/dist/mdx/restrict-expressions.d.ts.map +1 -0
  43. package/dist/mdx/restrict-expressions.js +171 -0
  44. package/dist/mdx/restrict-expressions.js.map +1 -0
  45. package/dist/mdx-editor.js +1 -0
  46. package/dist/mdx-editor.js.map +1 -0
  47. package/dist/node.d.ts +3 -2
  48. package/dist/node.d.ts.map +1 -1
  49. package/dist/node.js +3 -1
  50. package/dist/node.js.map +1 -0
  51. package/dist/sandbox-frame.d.ts +114 -0
  52. package/dist/sandbox-frame.d.ts.map +1 -0
  53. package/dist/sandbox-frame.js +253 -0
  54. package/dist/sandbox-frame.js.map +1 -0
  55. package/dist/types.d.ts +7 -4
  56. package/dist/types.d.ts.map +1 -1
  57. package/dist/types.js +1 -0
  58. package/dist/types.js.map +1 -0
  59. package/package.json +58 -41
  60. package/src/code-block-frame.tsx +262 -0
  61. package/src/editor-core.tsx +403 -0
  62. package/src/editor-styles.css +282 -0
  63. package/src/esm-passthrough.ts +269 -0
  64. package/src/fragments.ts +91 -0
  65. package/src/index.ts +5 -0
  66. package/src/markdown-options.ts +21 -0
  67. package/src/mdx/compile-request.ts +53 -0
  68. package/src/mdx/compile.ts +60 -0
  69. package/src/mdx/evaluate.ts +174 -0
  70. package/src/mdx/heading-outline.ts +153 -0
  71. package/src/mdx/literal-attributes.ts +50 -0
  72. package/src/mdx/restrict-expressions.ts +184 -0
  73. package/src/mdx-editor.tsx +15 -0
  74. package/src/node.ts +25 -0
  75. package/src/sandbox-frame.ts +294 -0
  76. package/src/types.ts +23 -0
  77. package/dist/blocks.d.ts +0 -37
  78. package/dist/blocks.d.ts.map +0 -1
  79. package/dist/blocks.js +0 -51
  80. package/dist/hooks/useMDXEvaluation.d.ts +0 -28
  81. package/dist/hooks/useMDXEvaluation.d.ts.map +0 -1
  82. package/dist/hooks/useMDXEvaluation.js +0 -117
  83. package/dist/index.d.mts +0 -127
  84. package/dist/index.d.mts.map +0 -1
  85. package/dist/index.mjs +0 -516
  86. package/dist/index.mjs.map +0 -1
  87. package/dist/node.d.mts +0 -102
  88. package/dist/node.d.mts.map +0 -1
  89. package/dist/node.mjs +0 -140
  90. package/dist/node.mjs.map +0 -1
  91. package/dist/style.css +0 -88
@@ -0,0 +1,253 @@
1
+ /**
2
+ * Opaque-origin MDX preview frame document + runtime. Confines the MDX
3
+ * `'unsafe-eval'` to this frame — see `SANDBOX_FRAME_CSP` below.
4
+ * Shared by the cms-spa ContentSandbox and the server route that serves this
5
+ * frame's HTML at `SANDBOX_FRAME_PATH`.
6
+ */
7
+ export function createSandboxRuntime() {
8
+ // Everything below stays inside this function: the frame receives it as source text.
9
+ const Fragment = Symbol('sandbox.fragment');
10
+ const SVG_NS = 'http://www.w3.org/2000/svg';
11
+ // A child is built before its parent, so an element written inside <svg>
12
+ // starts out as HTML, which a browser does not draw there. The <svg> builds
13
+ // it again as SVG from what each HTML element was made of, kept here, which
14
+ // is the namespace React would have given it.
15
+ const madeOf = new WeakMap();
16
+ const toNodes = (value) => {
17
+ if (value == null || value === true || value === false)
18
+ return [];
19
+ if (Array.isArray(value))
20
+ return value.flatMap(toNodes);
21
+ if (typeof value === 'string' || typeof value === 'number')
22
+ return [document.createTextNode(String(value))];
23
+ if (value instanceof Node)
24
+ return [value];
25
+ return [document.createTextNode(String(value))];
26
+ };
27
+ const element = (type, p, inSvg) => {
28
+ const svg = inSvg || type === 'svg';
29
+ const el = svg ? document.createElementNS(SVG_NS, type) : document.createElement(type);
30
+ if (!svg)
31
+ madeOf.set(el, { type, props: p });
32
+ for (const key in p) {
33
+ if (key === 'children' || key === 'key')
34
+ continue;
35
+ const value = p[key];
36
+ if (/^on/i.test(key))
37
+ continue; // never wire an event handler
38
+ if (key === 'className') {
39
+ el.setAttribute('class', String(value));
40
+ }
41
+ else if (key === 'htmlFor') {
42
+ el.setAttribute('for', String(value));
43
+ }
44
+ else if (key === 'style' && value && typeof value === 'object') {
45
+ Object.assign(el.style, value);
46
+ }
47
+ else if (value === true) {
48
+ el.setAttribute(key, '');
49
+ }
50
+ else if (value != null && value !== false) {
51
+ el.setAttribute(key, String(value));
52
+ }
53
+ }
54
+ // What a <foreignObject> holds is HTML again, as in a browser.
55
+ const svgChildren = svg && type !== 'foreignObject';
56
+ for (const child of toNodes(p.children)) {
57
+ const source = svgChildren ? madeOf.get(child) : undefined;
58
+ el.appendChild(source ? element(source.type, source.props, true) : child);
59
+ }
60
+ return el;
61
+ };
62
+ const jsx = (type, props) => {
63
+ const p = props || {};
64
+ if (type === Fragment) {
65
+ const frag = document.createDocumentFragment();
66
+ for (const child of toNodes(p.children))
67
+ frag.appendChild(child);
68
+ return frag;
69
+ }
70
+ if (typeof type === 'function')
71
+ return type(p);
72
+ if (typeof type === 'string')
73
+ return element(type, p, false);
74
+ const missing = document.createElement('span');
75
+ missing.setAttribute('data-sandbox-unknown', '');
76
+ return missing;
77
+ };
78
+ return { Fragment, jsx, jsxs: jsx, jsxDEV: jsx };
79
+ }
80
+ /**
81
+ * Evaluate a pre-compiled MDX function body. This is the `new AsyncFunction`
82
+ * eval that used to run in the privileged parent (`useMDXEvaluation`) — it now
83
+ * runs only here, inside the sandbox, which is why `'unsafe-eval'` is confined
84
+ * to the frame CSP. Returns the module's default export (the MDX component).
85
+ */
86
+ export function runCompiledMdx(code, runtime) {
87
+ const AsyncFunction = Object.getPrototypeOf(async () => { }).constructor;
88
+ return new AsyncFunction(String(code))(runtime);
89
+ }
90
+ /**
91
+ * The frame entry point. Wires the message listener, height reporting, and
92
+ * link/interaction interception, then announces readiness. Every dependency
93
+ * arrives as `deps` so the serialized source carries no free identifiers a
94
+ * minifier could rename.
95
+ */
96
+ export function sandboxFrameMain(deps) {
97
+ const root = document.getElementById('__sandbox_root');
98
+ if (!root)
99
+ return;
100
+ // Per-instance key from ?k= so the host can accept messages without relying
101
+ // on event.source === iframe.contentWindow (broken for opaque sandboxes in Chromium).
102
+ let frameKey = '';
103
+ try {
104
+ frameKey = new URL(location.href).searchParams.get('k') || '';
105
+ }
106
+ catch {
107
+ frameKey = '';
108
+ }
109
+ const post = (message) => {
110
+ parent.postMessage({ ...message, k: frameKey, __conlocaSandbox: true }, '*');
111
+ };
112
+ let lastHeight = -1;
113
+ const postHeight = () => {
114
+ // Child margins (prose p/h1) collapse out of a normal block root, so
115
+ // getBoundingClientRect(root) under-reports. flow-root on the root
116
+ // contains them; also take scrollHeight so a short iframe cannot
117
+ // circularly clamp the measure.
118
+ const px = Math.ceil(Math.max(root.getBoundingClientRect().height, root.scrollHeight, document.body.scrollHeight, document.documentElement.scrollHeight));
119
+ if (px !== lastHeight) {
120
+ lastHeight = px;
121
+ post({ __conlocaSandbox: true, kind: 'height', px });
122
+ }
123
+ };
124
+ document.addEventListener('click', (event) => {
125
+ const target = event.target;
126
+ const anchor = target && 'closest' in target ? target.closest('a') : null;
127
+ if (anchor) {
128
+ event.preventDefault();
129
+ post({ __conlocaSandbox: true, kind: 'link', href: anchor.getAttribute('href') || '' });
130
+ }
131
+ }, true);
132
+ document.addEventListener('pointerdown', () => post({ __conlocaSandbox: true, kind: 'interact' }), true);
133
+ const applyStyles = (css) => {
134
+ let style = document.getElementById('__sandbox_styles');
135
+ if (!style) {
136
+ style = document.createElement('style');
137
+ style.id = '__sandbox_styles';
138
+ document.head.appendChild(style);
139
+ }
140
+ style.textContent = css;
141
+ };
142
+ const renderMdx = (code) => {
143
+ const runtime = deps.createSandboxRuntime();
144
+ deps
145
+ .runCompiledMdx(code, runtime)
146
+ .then((module) => {
147
+ const Component = module?.default;
148
+ root.textContent = '';
149
+ if (typeof Component === 'function') {
150
+ const output = Component({});
151
+ if (output)
152
+ root.appendChild(output);
153
+ }
154
+ post({ __conlocaSandbox: true, kind: 'rendered' });
155
+ postHeight();
156
+ })
157
+ .catch((error) => {
158
+ post({
159
+ __conlocaSandbox: true,
160
+ kind: 'error',
161
+ message: error instanceof Error ? error.message : String(error),
162
+ });
163
+ });
164
+ };
165
+ const renderHtml = (html) => {
166
+ // Already allowlist-sanitized by the host; the sandbox contains anything
167
+ // that slips through (opaque origin, no privileged globals, strict CSP).
168
+ root.innerHTML = html;
169
+ post({ __conlocaSandbox: true, kind: 'rendered' });
170
+ postHeight();
171
+ };
172
+ window.addEventListener('message', (event) => {
173
+ // Brand + kind only. Requiring event.source === parent drops legitimate
174
+ // host posts under some nested/opaque-origin Chromium cases.
175
+ const data = event.data;
176
+ if (data?.__conlocaSandbox !== true || data.kind !== 'render')
177
+ return;
178
+ if (typeof data.styles === 'string')
179
+ applyStyles(data.styles);
180
+ try {
181
+ if (data.mode === 'mdx')
182
+ renderMdx(data.payload);
183
+ else
184
+ renderHtml(data.payload);
185
+ }
186
+ catch (error) {
187
+ post({ __conlocaSandbox: true, kind: 'error', message: error instanceof Error ? error.message : String(error) });
188
+ }
189
+ });
190
+ const ResizeObs = window.ResizeObserver;
191
+ if (ResizeObs)
192
+ new ResizeObs(postHeight).observe(root);
193
+ post({ __conlocaSandbox: true, kind: 'ready' });
194
+ }
195
+ /**
196
+ * The frame's own Content-Security-Policy. `'unsafe-eval'` is intentional and
197
+ * confined here (the MDX eval lives in the frame). What it does and does NOT
198
+ * close, stated precisely:
199
+ * - The isolation that HOLDS: no `allow-same-origin` gives the frame an opaque
200
+ * origin, so it exposes no cookies, no privileged globals, and no
201
+ * `window.parent` — nothing privileged is reachable to exfiltrate.
202
+ * - Structured-data egress is closed: with no `connect-src`, `fetch`/XHR/
203
+ * WebSocket/`sendBeacon` cannot post data out.
204
+ * - Metadata-only leak channels REMAIN OPEN and are an accepted residual risk.
205
+ * A hostile preview script can still leak the previewing admin's IP/UA/timing
206
+ * (plus author-encoded data) to an external host two ways: (a) passive
207
+ * img/font GETs to `https:` (`img-src`/`font-src`, which `connect-src` does
208
+ * not govern — kept for remote-image/`@font-face` fidelity, CSP-toggleable
209
+ * below); and (b) self-navigation — `location.href`/`location.replace` or a
210
+ * `<meta http-equiv=refresh>` — which is inherent to `allow-scripts` and NOT
211
+ * closeable by CSP (`navigate-to` is unsupported in browsers) or the sandbox
212
+ * flags (same-frame navigation is always allowed), short of dropping
213
+ * `allow-scripts` and the interactive preview with it.
214
+ * Owner toggle: replacing `https:` with just `data: blob:` in `img-src`/`font-src`
215
+ * below closes (a) at a remote-image/-font fidelity cost — but not (b), which has
216
+ * no CSP mitigation. Both leak only request metadata, never privileged content.
217
+ */
218
+ export const SANDBOX_FRAME_CSP = "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval'; style-src 'unsafe-inline'; img-src data: https: blob:; font-src data: https:";
219
+ /**
220
+ * esbuild-style bundlers inject `/* @__PURE__ *\/ __name(fn, "id")` around
221
+ * function expressions when keepNames is on. That helper exists in the bundle
222
+ * scope but NOT inside the iframe document after Function#toString() copy.
223
+ * Provide a no-op so the serialized bootstrap can run in isolation.
224
+ */
225
+ const SANDBOX_BUNDLE_HELPERS = 'var __name=function(fn){return fn};';
226
+ /**
227
+ * Assemble the sandbox frame document. The runtime functions are injected as
228
+ * argument expressions to `sandboxFrameMain` so no cross-function identifier
229
+ * has to survive minification by name.
230
+ *
231
+ * The editor loads this from `GET /api/v1/mdx/sandbox-frame` (own response CSP
232
+ * with unsafe-eval). Do NOT use srcdoc/blob from the parent document: those
233
+ * inherit the parent CSP, which forbids unsafe-inline/unsafe-eval and leaves
234
+ * MDX fragment previews as empty white boxes.
235
+ */
236
+ export function buildSandboxSrcdoc() {
237
+ const bootstrap = `${SANDBOX_BUNDLE_HELPERS}(${sandboxFrameMain.toString()})({createSandboxRuntime:${createSandboxRuntime.toString()},runCompiledMdx:${runCompiledMdx.toString()}})`;
238
+ return [
239
+ '<!doctype html><html><head><meta charset="utf-8">',
240
+ `<meta http-equiv="Content-Security-Policy" content="${SANDBOX_FRAME_CSP}">`,
241
+ '<style>html,body{margin:0;padding:0}#__sandbox_root{box-sizing:border-box;display:flow-root}</style>',
242
+ // `conloca-prose` is the documented scope class for prose surfaces
243
+ // (the MDX editor's contenteditable carries it too). Sites can scope
244
+ // typography to `.conloca-prose <tag>` in their registered styles and
245
+ // it applies inside this sandbox as well as the editor.
246
+ '</head><body><div id="__sandbox_root" class="conloca-prose"></div>',
247
+ `<script>${bootstrap}</script>`,
248
+ '</body></html>',
249
+ ].join('');
250
+ }
251
+ /** Well-known path where a host serves {@link buildSandboxSrcdoc}. */
252
+ export const SANDBOX_FRAME_PATH = '/api/v1/mdx/sandbox-frame';
253
+ //# sourceMappingURL=sandbox-frame.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-frame.js","sourceRoot":"","sources":["../src/sandbox-frame.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6BH,MAAM,UAAU,oBAAoB;IAMlC,qFAAqF;IACrF,MAAM,QAAQ,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,4BAA4B,CAAC;IAC5C,yEAAyE;IACzE,4EAA4E;IAC5E,4EAA4E;IAC5E,8CAA8C;IAC9C,MAAM,MAAM,GAAG,IAAI,OAAO,EAA0D,CAAC;IACrF,MAAM,OAAO,GAAG,CAAC,KAAc,EAAU,EAAE;QACzC,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK;YAAE,OAAO,EAAE,CAAC;QAClE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACxD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC5G,IAAI,KAAK,YAAY,IAAI;YAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QAC1C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;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AE,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAC5B,4IAA4I,CAAC;AAE/I;;;;;GAKG;AACH,MAAM,sBAAsB,GAAG,qCAAqC,CAAC;AAErE;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,SAAS,GAAG,GAAG,sBAAsB,IAAI,gBAAgB,CAAC,QAAQ,EAAE,2BAA2B,oBAAoB,CAAC,QAAQ,EAAE,mBAAmB,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC;IACrL,OAAO;QACL,mDAAmD;QACnD,uDAAuD,iBAAiB,IAAI;QAC5E,sGAAsG;QACtG,mEAAmE;QACnE,qEAAqE;QACrE,sEAAsE;QACtE,wDAAwD;QACxD,oEAAoE;QACpE,WAAW,SAAS,WAAW;QAC/B,gBAAgB;KACjB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACb,CAAC;AAED,sEAAsE;AACtE,MAAM,CAAC,MAAM,kBAAkB,GAAG,2BAA2B,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,16 +1,19 @@
1
1
  import type { ComponentType } from 'react';
2
- export type { MDXCompileResponse as MDXCompileResult } from '@conloca/content-api';
3
- export interface EvaluatedMDXBlock {
2
+ export type { MDXCompileResponse as MDXCompileResult, MDXHeading } from '@conloca/content-api';
3
+ import type { MDXHeading as Heading } from '@conloca/content-api';
4
+ export interface EvaluatedMDXFragment {
4
5
  ok: true;
5
6
  id: string;
6
7
  title: string;
7
8
  Component: ComponentType;
9
+ /** The fragment's headings, for a host block that shows a contents list. */
10
+ outline: readonly Heading[];
8
11
  }
9
- export interface FailedMDXBlockEvaluation {
12
+ export interface FailedMDXFragmentEvaluation {
10
13
  ok: false;
11
14
  id: string;
12
15
  title: string;
13
16
  error: Error;
14
17
  }
15
- export type MDXBlockEvaluationResult = EvaluatedMDXBlock | FailedMDXBlockEvaluation;
18
+ export type MDXFragmentEvaluationResult = EvaluatedMDXFragment | FailedMDXFragmentEvaluation;
16
19
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,YAAY,EAAE,kBAAkB,IAAI,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEnF,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,IAAI,CAAC;IACT,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,aAAa,CAAC;CAC1B;AAED,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,KAAK,CAAC;IACV,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;CACd;AAED,MAAM,MAAM,wBAAwB,GAAG,iBAAiB,GAAG,wBAAwB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,YAAY,EAAE,kBAAkB,IAAI,gBAAgB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE/F,OAAO,KAAK,EAAE,UAAU,IAAI,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAElE,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,IAAI,CAAC;IACT,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,aAAa,CAAC;IACzB,4EAA4E;IAC5E,OAAO,EAAE,SAAS,OAAO,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,2BAA2B;IAC1C,EAAE,EAAE,KAAK,CAAC;IACV,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;CACd;AAED,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,GAAG,2BAA2B,CAAC"}
package/dist/types.js CHANGED
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@conloca/mdx",
3
- "version": "0.1.16",
3
+ "version": "0.2.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -9,53 +9,67 @@
9
9
  "url": "git+https://github.com/conloca/conloca.git",
10
10
  "directory": "packages/mdx"
11
11
  },
12
- "main": "./dist/index.mjs",
13
- "module": "./dist/index.mjs",
12
+ "main": "./dist/index.js",
13
+ "module": "./dist/index.js",
14
14
  "dependencies": {
15
- "@conloca/content-api": "0.1.16",
15
+ "@conloca/content-api": "0.2.1",
16
16
  "@mdx-js/mdx": "^3.1.1",
17
17
  "@mdx-js/react": "^3.1.1",
18
- "@mdxeditor/editor": "^3.55.0",
18
+ "@mdxeditor/editor": "^4.2.3",
19
+ "github-slugger": "^2.0.0",
19
20
  "gray-matter": "^4.0.3",
21
+ "hast-util-to-jsx-runtime": "^2.3.6",
20
22
  "lucide-react": "^0.564.0",
21
23
  "mdast-util-to-markdown": "^2.1.2",
22
24
  "remark-frontmatter": "^5.0.0",
23
- "remark-gfm": "^4.0.0",
25
+ "remark-gfm": "^4.0.1",
26
+ "remark-mdx": "^3.1.1",
24
27
  "remark-mdx-frontmatter": "^5.2.0",
25
- "tslib": "^2.8.1"
28
+ "remark-parse": "^11.0.0",
29
+ "remark-rehype": "^11.1.2",
30
+ "tslib": "^2.8.1",
31
+ "unified": "^11.0.5"
26
32
  },
27
33
  "peerDependencies": {
28
- "react": "^19.2.5",
29
- "react-dom": "^19.2.5"
34
+ "react": "^19.0.0",
35
+ "react-dom": "^19.0.0"
30
36
  },
31
37
  "devDependencies": {
32
- "@happy-dom/global-registrator": "20.6.1",
33
- "@testing-library/react": "^16.3.2",
34
- "@tsdown/css": "^0.22.0",
35
- "@types/react": "19.2.14",
36
- "@types/react-dom": "19.2.3",
37
- "happy-dom": "20.6.1",
38
- "mdast-util-from-markdown": "^2.0.0",
38
+ "@happy-dom/global-registrator": "20.13.2",
39
+ "@testing-library/react": "^16.3.3",
40
+ "@types/mdast": "^4.0.4",
41
+ "@types/react": "19.2.18",
42
+ "@types/react-dom": "19.2.7",
43
+ "happy-dom": "20.13.2",
44
+ "mdast-util-from-markdown": "^2.0.3",
39
45
  "mdast-util-gfm": "^3.1.0",
40
46
  "micromark-extension-gfm": "^3.0.0",
41
- "react": "19.2.4",
42
- "react-dom": "19.2.4"
47
+ "react": "19.2.8",
48
+ "react-dom": "19.2.8"
43
49
  },
44
50
  "exports": {
45
51
  "./package.json": "./package.json",
46
52
  ".": {
47
- "types": "./dist/index.d.mts",
48
- "import": "./dist/index.mjs",
49
- "default": "./dist/index.mjs"
53
+ "types": "./dist/index.d.ts",
54
+ "import": "./dist/index.js",
55
+ "default": "./dist/index.js"
50
56
  },
51
57
  "./node": {
52
- "types": "./dist/node.d.mts",
53
- "import": "./dist/node.mjs",
54
- "default": "./dist/node.mjs"
55
- }
58
+ "types": "./dist/node.d.ts",
59
+ "import": "./dist/node.js",
60
+ "default": "./dist/node.js"
61
+ },
62
+ "./sandbox-frame": {
63
+ "types": "./dist/sandbox-frame.d.ts",
64
+ "import": "./dist/sandbox-frame.js",
65
+ "default": "./dist/sandbox-frame.js"
66
+ },
67
+ "./style.css": "./src/editor-styles.css"
56
68
  },
57
69
  "files": [
58
70
  "dist",
71
+ "src",
72
+ "!src/__tests__",
59
73
  "!**/*.tsbuildinfo"
60
74
  ],
61
75
  "scripts": {
@@ -63,39 +77,42 @@
63
77
  },
64
78
  "nx": {
65
79
  "targets": {
80
+ "clean": {},
66
81
  "test": {
67
82
  "dependsOn": [
68
83
  "typecheck-tests",
69
- "^build"
84
+ "^build",
85
+ "test-packed"
70
86
  ],
71
87
  "executor": "@smoothbricks/nx-plugin:bounded-exec",
72
88
  "options": {
73
89
  "command": "bun --conditions=production test",
74
90
  "cwd": "{projectRoot}",
75
91
  "timeoutMs": 120000,
76
- "killAfterMs": 1e4
92
+ "killAfterMs": 10000
77
93
  }
78
94
  },
79
95
  "lint": {},
80
- "tsdown-js": {
96
+ "test-packed": {
97
+ "//": "The packed shape is a function of the built outputs, the manifest and the locked dependency closure; cached on exactly those.",
81
98
  "executor": "nx:run-commands",
82
99
  "cache": true,
83
- "dependsOn": [
84
- "^build"
85
- ],
86
100
  "inputs": [
87
- "{projectRoot}/src/**/*",
88
- "{projectRoot}/tsdown.config.ts",
89
- "{projectRoot}/tsconfig.lib.json",
90
- "{projectRoot}/package.json"
101
+ {
102
+ "dependentTasksOutputFiles": "**/*",
103
+ "transitive": true
104
+ },
105
+ "{projectRoot}/package.json",
106
+ "{workspaceRoot}/bun.lock",
107
+ "{workspaceRoot}/tooling/packaging/**/*"
91
108
  ],
92
- "outputs": [
93
- "{projectRoot}/dist/**/*.mjs",
94
- "{projectRoot}/dist/**/*.d.mts"
109
+ "dependsOn": [
110
+ "build",
111
+ "^build"
95
112
  ],
96
113
  "options": {
97
- "command": "tsdown",
98
- "cwd": "{projectRoot}"
114
+ "command": "bun tooling/packaging/test-packed.ts mdx",
115
+ "cwd": "{workspaceRoot}"
99
116
  }
100
117
  }
101
118
  },
@@ -105,6 +122,6 @@
105
122
  "name": "mdx"
106
123
  },
107
124
  "type": "module",
108
- "types": "./dist/index.d.mts",
125
+ "types": "./dist/index.d.ts",
109
126
  "license": "FSL-1.1-ALv2"
110
127
  }