@markdoc/markdoc 0.5.0 → 0.5.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/dist/react.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/tag.ts", "../src/renderers/react/react.ts"],
4
- "sourcesContent": ["import type { RenderableTreeNode } from './types';\n\nexport default class Tag<\n N extends string = string,\n A extends Record<string, any> = Record<string, any>\n> {\n readonly $$mdtype = 'Tag' as const;\n\n static isTag = (tag: any): tag is Tag => {\n return !!(tag?.$$mdtype === 'Tag');\n };\n\n name: N;\n attributes: A;\n children: RenderableTreeNode[];\n\n constructor(\n name = 'div' as N,\n attributes = {} as A,\n children: RenderableTreeNode[] = []\n ) {\n this.name = name;\n this.attributes = attributes;\n this.children = children;\n }\n}\n", "import Tag from '../../tag';\nimport { RenderableTreeNodes, Scalar } from '../../types';\n\nimport type { createElement, ComponentType, Fragment, ReactNode } from 'react';\n\ntype ReactShape = Readonly<{\n createElement: typeof createElement;\n Fragment: typeof Fragment;\n}>;\n\ntype Component = ComponentType<unknown>;\n\nfunction tagName(\n name: string,\n components: Record<string, Component> | ((string: string) => Component)\n): string | Component {\n return typeof name !== 'string'\n ? name // This can be an object, e.g. when React.forwardRef is used\n : name[0] !== name[0].toUpperCase()\n ? name\n : components instanceof Function\n ? components(name)\n : components[name];\n}\n\nexport type RenderOpts = {\n components?: Record<string, Component> | ((string: string) => Component);\n resolveTagName?: typeof tagName;\n};\nexport default function dynamic(\n node: RenderableTreeNodes,\n React: ReactShape,\n { components = {}, resolveTagName = tagName }: RenderOpts = {}\n) {\n function deepRender(value: any): any {\n if (value == null || typeof value !== 'object') return value;\n\n if (Array.isArray(value)) return value.map((item) => deepRender(item));\n\n if (value.$$mdtype === 'Tag') return render(value);\n\n if (typeof value !== 'object') return value;\n\n const output: Record<string, Scalar> = {};\n for (const [k, v] of Object.entries(value)) output[k] = deepRender(v);\n return output;\n }\n\n function render(node: RenderableTreeNodes): ReactNode {\n if (Array.isArray(node))\n return React.createElement(React.Fragment, null, ...node.map(render));\n\n if (node === null || typeof node !== 'object' || !Tag.isTag(node))\n return node;\n\n const {\n name,\n attributes: { class: className, ...attrs } = {},\n children = [],\n } = node;\n\n if (className) attrs.className = className;\n\n return React.createElement(\n resolveTagName(name, components),\n Object.keys(attrs).length == 0 ? null : deepRender(attrs),\n ...children.map(render)\n );\n }\n\n return render(node);\n}\n"],
4
+ "sourcesContent": ["import type { RenderableTreeNode } from './types';\n\nexport default class Tag<\n N extends string = string,\n A extends Record<string, any> = Record<string, any>\n> {\n readonly $$mdtype = 'Tag' as const;\n\n static isTag = (tag: any): tag is Tag => {\n return !!(tag?.$$mdtype === 'Tag');\n };\n\n name: N;\n attributes: A;\n children: RenderableTreeNode[];\n\n constructor(\n name = 'div' as N,\n attributes = {} as A,\n children: RenderableTreeNode[] = []\n ) {\n this.name = name;\n this.attributes = attributes;\n this.children = children;\n }\n}\n", "import Tag from '../../tag';\nimport { RenderableTreeNodes, Scalar } from '../../types';\n\nimport type { createElement, ComponentType, Fragment, ReactNode } from 'react';\n\ntype ReactShape = Readonly<{\n createElement: typeof createElement;\n Fragment: typeof Fragment;\n}>;\n\ntype Component = ComponentType<any>;\n\nfunction tagName(\n name: string,\n components: Record<string, Component> | ((string: string) => Component)\n): string | Component {\n return typeof name !== 'string'\n ? name // This can be an object, e.g. when React.forwardRef is used\n : name[0] !== name[0].toUpperCase()\n ? name\n : components instanceof Function\n ? components(name)\n : components[name];\n}\n\nexport type RenderOpts = {\n components?: Record<string, Component> | ((string: string) => Component);\n resolveTagName?: typeof tagName;\n};\nexport default function dynamic(\n node: RenderableTreeNodes,\n React: ReactShape,\n { components = {}, resolveTagName = tagName }: RenderOpts = {}\n) {\n function deepRender(value: any): any {\n if (value == null || typeof value !== 'object') return value;\n\n if (Array.isArray(value)) return value.map((item) => deepRender(item));\n\n if (value.$$mdtype === 'Tag') return render(value);\n\n if (typeof value !== 'object') return value;\n\n const output: Record<string, Scalar> = {};\n for (const [k, v] of Object.entries(value)) output[k] = deepRender(v);\n return output;\n }\n\n function render(node: RenderableTreeNodes): ReactNode {\n if (Array.isArray(node))\n return React.createElement(React.Fragment, null, ...node.map(render));\n\n if (node === null || typeof node !== 'object' || !Tag.isTag(node))\n return node;\n\n const {\n name,\n attributes: { class: className, ...attrs } = {},\n children = [],\n } = node;\n\n if (className) attrs.className = className;\n\n return React.createElement(\n resolveTagName(name, components),\n Object.keys(attrs).length == 0 ? null : deepRender(attrs),\n ...children.map(render)\n );\n }\n\n return render(node);\n}\n"],
5
5
  "mappings": ";AAEA,gBAGE;AAAA,EAWA,YACE,OAAO,OACP,aAAa,IACb,WAAiC,IACjC;AAdO,oBAAW;AAelB,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,WAAW;AAAA;AAAA;AAfX,AANT,IAMS,QAAQ,CAAC,QAAyB;AACvC,SAAO,CAAC,CAAE,MAAK,aAAa;AAAA;;;ACGhC,iBACE,MACA,YACoB;AACpB,SAAO,OAAO,SAAS,WACnB,OACA,KAAK,OAAO,KAAK,GAAG,gBACpB,OACA,sBAAsB,WACtB,WAAW,QACX,WAAW;AAAA;AAOF,iBACb,MACA,OACA,EAAE,aAAa,IAAI,iBAAiB,YAAwB,IAC5D;AACA,sBAAoB,OAAiB;AACnC,QAAI,SAAS,QAAQ,OAAO,UAAU;AAAU,aAAO;AAEvD,QAAI,MAAM,QAAQ;AAAQ,aAAO,MAAM,IAAI,CAAC,SAAS,WAAW;AAEhE,QAAI,MAAM,aAAa;AAAO,aAAO,OAAO;AAE5C,QAAI,OAAO,UAAU;AAAU,aAAO;AAEtC,UAAM,SAAiC;AACvC,eAAW,CAAC,GAAG,MAAM,OAAO,QAAQ;AAAQ,aAAO,KAAK,WAAW;AACnE,WAAO;AAAA;AAGT,kBAAgB,OAAsC;AACpD,QAAI,MAAM,QAAQ;AAChB,aAAO,MAAM,cAAc,MAAM,UAAU,MAAM,GAAG,MAAK,IAAI;AAE/D,QAAI,UAAS,QAAQ,OAAO,UAAS,YAAY,CAAC,IAAI,MAAM;AAC1D,aAAO;AAET,UAAM;AAAA,MACJ;AAAA,MACA,YAAY,EAAE,OAAO,cAAc,UAAU;AAAA,MAC7C,WAAW;AAAA,QACT;AAEJ,QAAI;AAAW,YAAM,YAAY;AAEjC,WAAO,MAAM,cACX,eAAe,MAAM,aACrB,OAAO,KAAK,OAAO,UAAU,IAAI,OAAO,WAAW,QACnD,GAAG,SAAS,IAAI;AAAA;AAIpB,SAAO,OAAO;AAAA;",
6
6
  "names": []
7
7
  }
@@ -4,7 +4,7 @@ declare type ReactShape = Readonly<{
4
4
  createElement: typeof createElement;
5
5
  Fragment: typeof Fragment;
6
6
  }>;
7
- declare type Component = ComponentType<unknown>;
7
+ declare type Component = ComponentType<any>;
8
8
  declare function tagName(name: string, components: Record<string, Component> | ((string: string) => Component)): string | Component;
9
9
  export declare type RenderOpts = {
10
10
  components?: Record<string, Component> | ((string: string) => Component);
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../../src/renderers/react/react.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAU,MAAM,aAAa,CAAC;AAE1D,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE/E,aAAK,UAAU,GAAG,QAAQ,CAAC;IACzB,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,QAAQ,EAAE,OAAO,QAAQ,CAAC;CAC3B,CAAC,CAAC;AAEH,aAAK,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AAExC,iBAAS,OAAO,CACd,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,SAAS,CAAC,GACtE,MAAM,GAAG,SAAS,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AAE,UAAe,EAAE,cAAwB,EAAE,GAAE,UAAe,aAuC/D"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@markdoc/markdoc",
3
3
  "author": "Ryan Paul",
4
- "version": "0.5.0",
4
+ "version": "0.5.1",
5
5
  "description": "A text markup language for documentation",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -8,7 +8,7 @@ type ReactShape = Readonly<{
8
8
  Fragment: typeof Fragment;
9
9
  }>;
10
10
 
11
- type Component = ComponentType<unknown>;
11
+ type Component = ComponentType<any>;
12
12
 
13
13
  function tagName(
14
14
  name: string,