@thedatagrid/docs-kit 0.1.0 → 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.
- package/CHANGELOG.md +19 -0
- package/README.md +106 -3
- package/dist/demos/cli.js +35 -1
- package/dist/demos/cli.js.map +1 -1
- package/dist/demos/pages.d.ts +2 -1
- package/dist/demos/pages.d.ts.map +1 -1
- package/dist/demos/pages.js +26 -1
- package/dist/demos/pages.js.map +1 -1
- package/dist/editor/install.d.ts +15 -0
- package/dist/editor/install.d.ts.map +1 -0
- package/dist/editor/install.js +71 -0
- package/dist/editor/install.js.map +1 -0
- package/dist/react/editor.d.ts +9 -0
- package/dist/react/editor.d.ts.map +1 -1
- package/dist/react/editor.js +111 -5
- package/dist/react/editor.js.map +1 -1
- package/dist/react/styles.css +87 -109
- package/dist/remark/remarkDemoFences.d.ts +14 -3
- package/dist/remark/remarkDemoFences.d.ts.map +1 -1
- package/dist/remark/remarkDemoFences.js +60 -3
- package/dist/remark/remarkDemoFences.js.map +1 -1
- package/editor-extension/README.md +23 -0
- package/editor-extension/extension.js +40 -0
- package/editor-extension/links.js +137 -0
- package/editor-extension/package.json +19 -0
- package/package.json +2 -1
- package/src/demos/cli.ts +34 -1
- package/src/demos/pages.ts +24 -1
- package/src/editor/install.ts +85 -0
- package/src/react/editor.ts +122 -5
- package/src/react/styles.css +87 -109
- package/src/remark/remarkDemoFences.ts +60 -3
|
@@ -91,9 +91,20 @@ type MdxElement = {
|
|
|
91
91
|
* - `height="small|default|large|auto|<px>"`; a live fence defaults to
|
|
92
92
|
* `liveHeight` (`auto`).
|
|
93
93
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
94
|
+
* A `<DemoTitle>` and/or `<DemoDescription>` right before a fence become that
|
|
95
|
+
* fence's card header:
|
|
96
|
+
*
|
|
97
|
+
* <DemoDescription>
|
|
98
|
+
* What the demo shows.
|
|
99
|
+
* </DemoDescription>
|
|
100
|
+
*
|
|
101
|
+
* ```tsx file="basic.demo.tsx" live
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* That's the same as wrapping the three in `<Demo>`, which also works. The
|
|
105
|
+
* fence's props are hoisted onto the `<Demo>`; a fence without `live` there
|
|
106
|
+
* makes a code-only card. A `<DemoTitle>` / `<DemoDescription>` with no fence
|
|
107
|
+
* after it fails the build.
|
|
97
108
|
*/
|
|
98
109
|
export function remarkDemoFences(options: RemarkDemoFencesOptions) {
|
|
99
110
|
const {
|
|
@@ -117,6 +128,7 @@ export function remarkDemoFences(options: RemarkDemoFencesOptions) {
|
|
|
117
128
|
};
|
|
118
129
|
|
|
119
130
|
return () => (tree: any) => {
|
|
131
|
+
wrapLooseHeaders(tree, componentName, folder);
|
|
120
132
|
visit(tree, 'code', (node: any, index: number | undefined, parent: any) => {
|
|
121
133
|
if (index == null || !parent) return;
|
|
122
134
|
|
|
@@ -282,6 +294,51 @@ export function remarkDemoFences(options: RemarkDemoFencesOptions) {
|
|
|
282
294
|
};
|
|
283
295
|
}
|
|
284
296
|
|
|
297
|
+
const HEADER_PARTS = new Set(['DemoTitle', 'DemoDescription']);
|
|
298
|
+
const isHeaderPart = (node: any) => node?.type === 'mdxJsxFlowElement' && HEADER_PARTS.has(node.name);
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Wraps each run of `<DemoTitle>` / `<DemoDescription>` (outside `<Demo>`)
|
|
302
|
+
* and the fence right after it in a `<Demo>`, so the fence handling below
|
|
303
|
+
* sees the same tree as for an explicit wrapper.
|
|
304
|
+
*/
|
|
305
|
+
function wrapLooseHeaders(tree: any, componentName: string, folder: string) {
|
|
306
|
+
visit(tree, (node: any) => {
|
|
307
|
+
if (!Array.isArray(node.children)) return;
|
|
308
|
+
if (node.type === 'mdxJsxFlowElement' && node.name === componentName) return 'skip';
|
|
309
|
+
const children: any[] = node.children;
|
|
310
|
+
for (let index = 0; index < children.length; index++) {
|
|
311
|
+
if (!isHeaderPart(children[index])) continue;
|
|
312
|
+
let end = index;
|
|
313
|
+
while (isHeaderPart(children[end])) end++;
|
|
314
|
+
const parts = children.slice(index, end);
|
|
315
|
+
const where = `"${folder}"${parts[0].position ? ` line ${parts[0].position.start.line}` : ''}`;
|
|
316
|
+
const names = parts.map((part) => part.name as string);
|
|
317
|
+
const repeated = names.find((name, i) => names.indexOf(name) !== i);
|
|
318
|
+
if (repeated) {
|
|
319
|
+
throw new Error(`<${repeated}> in ${where}: one per demo (each fence gets its own title and description)`);
|
|
320
|
+
}
|
|
321
|
+
const fence = children[end];
|
|
322
|
+
if (fence?.type !== 'code') {
|
|
323
|
+
throw new Error(
|
|
324
|
+
`<${names[0]}> in ${where} must come right before the code fence it describes ` +
|
|
325
|
+
`(or sit inside <${componentName}> with it)`,
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
const demo: MdxElement & { position?: unknown } = {
|
|
329
|
+
type: 'mdxJsxFlowElement',
|
|
330
|
+
name: componentName,
|
|
331
|
+
attributes: [],
|
|
332
|
+
children: [...parts, fence],
|
|
333
|
+
};
|
|
334
|
+
if (parts[0].position && fence.position) {
|
|
335
|
+
demo.position = { start: parts[0].position.start, end: fence.position.end };
|
|
336
|
+
}
|
|
337
|
+
children.splice(index, end - index + 1, demo);
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
|
|
285
342
|
function element(name: string, attrs: Record<string, string>): MdxElement {
|
|
286
343
|
return {
|
|
287
344
|
type: 'mdxJsxFlowElement',
|