@oxide/design-system 6.3.0 → 6.4.1-canary.dca2986

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.
@@ -1,8 +1,8 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as _oxide_react_asciidoc from '@oxide/react-asciidoc';
3
- import { DocumentSection, Block, DocumentBlock } from '@oxide/react-asciidoc';
3
+ import { DocumentSection, Block, DocumentBlock, InlineOverrides } from '@oxide/react-asciidoc';
4
4
  import * as _asciidoctor_core from '@asciidoctor/core';
5
- import { Document, Registry, Html5Converter, Block as Block$1 } from '@asciidoctor/core';
5
+ import { Document, Registry } from '@asciidoctor/core';
6
6
 
7
7
  declare function useIntersectionObserver(elements: Element[], callback: IntersectionObserverCallback, options: IntersectionObserverInit): IntersectionObserver | null;
8
8
  declare function useActiveSectionTracking(initialSections: Element[], onSectionChange: (element: Element) => void, debug?: boolean): {
@@ -35,6 +35,7 @@ declare const attrs: {
35
35
  sectlinks: string;
36
36
  stem: string;
37
37
  stylesheet: boolean;
38
+ icons: string;
38
39
  };
39
40
  declare const loadAsciidoctor: ({ extensions, }: {
40
41
  extensions?: ((this: Registry) => void)[];
@@ -63,10 +64,19 @@ declare const AsciiDocBlocks: {
63
64
  * '/<wbr/>path/<wbr/>to/<wbr/>long/<wbr/>file.txt'
64
65
  */
65
66
  declare const renderWithBreaks: (text: string) => string;
66
- declare class InlineConverter {
67
- baseConverter: Html5Converter;
68
- constructor();
69
- convert(node: Block$1, transform: string): string;
70
- }
67
+ /**
68
+ * Inline-level overrides for the renderer. Pass these to `<Asciidoc>` as
69
+ * `options.inlineOverrides` to apply our customisations to inline content:
70
+ *
71
+ * <Asciidoc document={doc} options={{ overrides: AsciiDocBlocks, inlineOverrides }} />
72
+ *
73
+ * The only customisation today is inserting `<wbr/>` break opportunities into
74
+ * inline monospaced (`code`) spans so long paths and URLs wrap nicely. Every
75
+ * other quoted subtype is rendered exactly as the renderer would by default —
76
+ * we round-trip the node through `inlineHtml` (the renderer's own serialiser)
77
+ * and `parse` it back into React elements, so there's no risk of drifting from
78
+ * the stock output.
79
+ */
80
+ declare const inlineOverrides: InlineOverrides;
71
81
 
72
- export { AsciiDocBlocks, DesktopOutline, InlineConverter, SmallScreenOutline, attrs, handleDocument, highlight, loadAsciidoctor, renderWithBreaks, useActiveSectionTracking, useDelegatedReactRouterLinks, useIntersectionObserver };
82
+ export { AsciiDocBlocks, DesktopOutline, SmallScreenOutline, attrs, handleDocument, highlight, inlineOverrides, loadAsciidoctor, renderWithBreaks, useActiveSectionTracking, useDelegatedReactRouterLinks, useIntersectionObserver };
@@ -7,11 +7,14 @@ import {
7
7
  } from "../../../chunk-H5ZEQGTH.js";
8
8
 
9
9
  // components/src/asciidoc/index.tsx
10
- import asciidoctor2 from "@asciidoctor/core";
11
- import { Content as Content4 } from "@oxide/react-asciidoc";
10
+ import {
11
+ Content as Content4,
12
+ inlineHtml,
13
+ parse as parse3
14
+ } from "@oxide/react-asciidoc";
12
15
 
13
16
  // components/src/asciidoc/Admonition.tsx
14
- import { Content, parse } from "@oxide/react-asciidoc";
17
+ import { Content, RenderInline } from "@oxide/react-asciidoc";
15
18
  import { jsx, jsxs } from "react/jsx-runtime";
16
19
  var themeForAdmonition = {
17
20
  note: "green-theme",
@@ -36,8 +39,8 @@ var Admonition = ({ node }) => {
36
39
  /* @__PURE__ */ jsxs("div", { className: "admonition-content content", children: [
37
40
  /* @__PURE__ */ jsx("div", { children: titleCase(attrs2.name.toString()) }),
38
41
  /* @__PURE__ */ jsxs("div", { children: [
39
- node.title && /* @__PURE__ */ jsx("div", { className: "admonition-title", children: node.title }),
40
- node.content && parse(node.content),
42
+ node.titleInlines && /* @__PURE__ */ jsx("div", { className: "admonition-title", children: /* @__PURE__ */ jsx(RenderInline, { nodes: node.titleInlines }) }),
43
+ node.inlines && /* @__PURE__ */ jsx(RenderInline, { nodes: node.inlines }),
41
44
  /* @__PURE__ */ jsx(Content, { blocks: node.blocks })
42
45
  ] })
43
46
  ] })
@@ -84,20 +87,20 @@ var Warning12 = ({ className }) => /* @__PURE__ */ jsx(
84
87
  var Admonition_default = Admonition;
85
88
 
86
89
  // components/src/asciidoc/Section.tsx
87
- import { Content as Content2, parse as parse2 } from "@oxide/react-asciidoc";
90
+ import { Content as Content2, parse, RenderInline as RenderInline2 } from "@oxide/react-asciidoc";
88
91
  import cn from "classnames";
89
92
  import { createElement } from "react";
90
93
  import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
91
- var stripAnchors = (str) => str.replace(/<a[^>]*>(.*?)<\/a>/gi, "$1");
92
94
  var Section = ({ node }) => {
93
95
  const level = node.level;
94
96
  let title = "";
95
97
  let sectNum = node.num;
96
98
  sectNum = sectNum && sectNum[0] === "." ? "" : sectNum;
99
+ const titleContent = node.hasCaption ? parse(node.title) : /* @__PURE__ */ jsx2(RenderInline2, { nodes: node.titleInlines });
97
100
  title = /* @__PURE__ */ jsxs2(Fragment, { children: [
98
101
  /* @__PURE__ */ jsx2("span", { className: "anchor", id: node.id || "", "aria-hidden": "true" }),
99
102
  /* @__PURE__ */ jsxs2("a", { className: "link group", href: `#${node.id}`, children: [
100
- parse2(stripAnchors(node.title)),
103
+ titleContent,
101
104
  /* @__PURE__ */ jsx2(Link16Icon_default, { className: "text-accent-secondary ml-2 hidden group-hover:inline-block" })
102
105
  ] })
103
106
  ] });
@@ -106,10 +109,15 @@ var Section = ({ node }) => {
106
109
  /* @__PURE__ */ jsx2("h1", { className: cn("sect0", node.role), "data-sectnum": sectNum, children: title }),
107
110
  /* @__PURE__ */ jsx2(Content2, { blocks: node.blocks })
108
111
  ] });
112
+ } else if (level === 1) {
113
+ return /* @__PURE__ */ jsxs2("div", { className: cn("sect1", node.role), children: [
114
+ createElement("h2", { "data-sectnum": sectNum }, title),
115
+ /* @__PURE__ */ jsx2("div", { className: "sectionbody", children: /* @__PURE__ */ jsx2(Content2, { blocks: node.blocks }) })
116
+ ] });
109
117
  } else {
110
118
  return /* @__PURE__ */ jsxs2("div", { className: cn(`sect${level}`, node.role), children: [
111
119
  createElement(`h${level + 1}`, { "data-sectnum": sectNum }, title),
112
- /* @__PURE__ */ jsx2("div", { className: "sectionbody", children: /* @__PURE__ */ jsx2(Content2, { blocks: node.blocks }) })
120
+ /* @__PURE__ */ jsx2(Content2, { blocks: node.blocks })
113
121
  ] });
114
122
  }
115
123
  };
@@ -122,11 +130,12 @@ var Table = ({ node }) => /* @__PURE__ */ jsx3("div", { className: "table-wrappe
122
130
  var Table_default = Table;
123
131
 
124
132
  // components/src/asciidoc/TableOfContents.tsx
125
- import { parse as parse3 } from "@oxide/react-asciidoc";
133
+ import { parse as parse2 } from "@oxide/react-asciidoc";
126
134
  import * as Accordion from "@radix-ui/react-accordion";
127
135
  import cn2 from "classnames";
128
136
  import { Fragment as Fragment2, useCallback, useEffect, useMemo, useRef, useState } from "react";
129
137
  import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
138
+ var dropAnchors = (html) => html.includes("<a") ? html.replace(/<(?:a\b[^>]*|\/a)>/g, "") : html;
130
139
  function useIntersectionObserver(elements, callback, options) {
131
140
  const [observer, setObserver] = useState(null);
132
141
  useEffect(() => {
@@ -300,7 +309,7 @@ var DesktopOutline = ({
300
309
  style: {
301
310
  paddingLeft: `${0.5 + item.level * 0.5}rem`
302
311
  },
303
- children: parse3(stripAnchors(item.title))
312
+ children: parse2(dropAnchors(item.title))
304
313
  }
305
314
  )
306
315
  }
@@ -338,7 +347,7 @@ var SmallScreenOutline = ({
338
347
  style: {
339
348
  paddingLeft: `${0.5 + item.level * 0.5}rem`
340
349
  },
341
- children: parse3(stripAnchors(item.title))
350
+ children: parse2(dropAnchors(item.title))
342
351
  }
343
352
  )
344
353
  }
@@ -403,6 +412,7 @@ function useDelegatedReactRouterLinks(navigate, nodeRef, key) {
403
412
  // components/src/asciidoc/util.ts
404
413
  import asciidoctor from "@asciidoctor/core";
405
414
  import {
415
+ Inline,
406
416
  prepareDocument,
407
417
  processDocument
408
418
  } from "@oxide/react-asciidoc";
@@ -2005,18 +2015,15 @@ var oxide_syntax_default = {
2005
2015
  };
2006
2016
 
2007
2017
  // components/src/asciidoc/util.ts
2008
- var highlighter = null;
2018
+ var highlighterPromise = null;
2009
2019
  var customLanguages = ["oxql", "p4"];
2010
2020
  var supportedLanguages = [...Object.keys(bundledLanguages), ...customLanguages];
2011
- async function getHighlighter() {
2012
- if (!highlighter) {
2021
+ function getHighlighter() {
2022
+ if (!highlighterPromise) {
2013
2023
  const langs = [{ ...oxql_tmLanguage_default }, { ...p4_tmLanguage_default }];
2014
- highlighter = await createHighlighter({
2015
- themes: [oxide_syntax_default],
2016
- langs
2017
- });
2024
+ highlighterPromise = createHighlighter({ themes: [oxide_syntax_default], langs });
2018
2025
  }
2019
- return highlighter;
2026
+ return highlighterPromise;
2020
2027
  }
2021
2028
  async function highlightCode(code, lang, { inline = false } = {}) {
2022
2029
  const h = await getHighlighter();
@@ -2033,20 +2040,26 @@ async function highlightCode(code, lang, { inline = false } = {}) {
2033
2040
  var highlight = async (block) => {
2034
2041
  if (block.type === "listing") {
2035
2042
  const literalBlock = block;
2036
- if (!literalBlock.content) {
2043
+ if (typeof literalBlock.source !== "string") {
2037
2044
  return block;
2038
2045
  }
2039
- const calloutRegex = /<i class="conum" data-value="\d+"><\/i>/g;
2046
+ const lineComment = literalBlock.attributes["line-comment"];
2047
+ const content = Inline.subCalloutsRaw(
2048
+ literalBlock.source,
2049
+ true,
2050
+ lineComment !== void 0 ? String(lineComment) : void 0
2051
+ );
2052
+ const calloutRegex = /<i class="conum" data-value="\d+"><\/i>(?:<b>\(\d+\)<\/b>)?/g;
2040
2053
  const callouts = [];
2041
- const placeholderContent = literalBlock.content.replace(calloutRegex, (match) => {
2054
+ const placeholderContent = content.replace(calloutRegex, (match) => {
2042
2055
  callouts.push(match);
2043
- return `__CALLOUT_PLACEHOLDER_${callouts.length - 1}__`;
2056
+ return `CALLOUTPLACEHOLDER${callouts.length - 1}END`;
2044
2057
  });
2045
2058
  if (!literalBlock.language) {
2046
2059
  return {
2047
2060
  ...block,
2048
- content: placeholderContent.replace(
2049
- /__CALLOUT_PLACEHOLDER_(\d+)__/g,
2061
+ content: Inline.subSpecialchars(placeholderContent).replace(
2062
+ /CALLOUTPLACEHOLDER(\d+)END/g,
2050
2063
  (_, index) => callouts[parseInt(index)]
2051
2064
  )
2052
2065
  };
@@ -2057,7 +2070,7 @@ var highlight = async (block) => {
2057
2070
  { inline: true }
2058
2071
  );
2059
2072
  const restoredContent = highlightedContent.replace(
2060
- /__CALLOUT_PLACEHOLDER_(\d+)__/g,
2073
+ /CALLOUTPLACEHOLDER(\d+)END/g,
2061
2074
  (_, index) => callouts[parseInt(index)]
2062
2075
  );
2063
2076
  return {
@@ -2070,42 +2083,23 @@ var highlight = async (block) => {
2070
2083
  var attrs = {
2071
2084
  sectlinks: "true",
2072
2085
  stem: "latexmath",
2073
- stylesheet: false
2086
+ stylesheet: false,
2087
+ icons: "font"
2074
2088
  };
2075
2089
  var loadAsciidoctor = ({
2076
2090
  extensions = []
2077
2091
  }) => {
2078
- const ad2 = asciidoctor();
2079
- class InlineConverter2 {
2080
- baseConverter;
2081
- constructor() {
2082
- this.baseConverter = new ad2.Html5Converter();
2083
- }
2084
- convert(node, transform) {
2085
- switch (node.getNodeName()) {
2086
- case "inline_callout":
2087
- return convertInlineCallout(node);
2088
- // We know this is always inline
2089
- default:
2090
- break;
2091
- }
2092
- return this.baseConverter.convert(node, transform);
2093
- }
2094
- }
2095
- extensions.forEach((extension) => ad2.Extensions.register(extension));
2096
- ad2.ConverterFactory.register(new InlineConverter2(), ["html5"]);
2097
- return ad2;
2092
+ const ad = asciidoctor();
2093
+ extensions.forEach((extension) => ad.Extensions.register(extension));
2094
+ return ad;
2098
2095
  };
2099
- function convertInlineCallout(node) {
2100
- return `<i class="conum" data-value="${node.getText()}"></i>`;
2101
- }
2102
2096
  var handleDocument = async (document) => {
2103
2097
  const doc = prepareDocument(document);
2104
2098
  return await processDocument(doc, highlight);
2105
2099
  };
2106
2100
 
2107
2101
  // components/src/asciidoc/index.tsx
2108
- import { jsx as jsx5 } from "react/jsx-runtime";
2102
+ import { Fragment as Fragment3, jsx as jsx5 } from "react/jsx-runtime";
2109
2103
  var MinimalDocument = ({ document }) => /* @__PURE__ */ jsx5("div", { id: "content", className: "asciidoc-body w-full", children: /* @__PURE__ */ jsx5(Content4, { blocks: document.blocks }) });
2110
2104
  var AsciiDocBlocks = {
2111
2105
  Admonition: Admonition_default,
@@ -2121,74 +2115,23 @@ var renderWithBreaks = (text) => {
2121
2115
  return segment.replace(/(?:^|(?<=\S))\/(?=\S)/g, "/<wbr/>");
2122
2116
  }).join("");
2123
2117
  };
2124
- var QUOTE_TAGS = {
2125
- "monospaced": ["<code>", "</code>", true],
2126
- "emphasis": ["<em>", "</em>", true],
2127
- "strong": ["<strong>", "</strong>", true],
2128
- "double": ["&#8220;", "&#8221;"],
2129
- "single": ["&#8216;", "&#8217;"],
2130
- "mark": ["<mark>", "</mark>", true],
2131
- "superscript": ["<sup>", "</sup>", true],
2132
- "subscript": ["<sub>", "</sub>", true],
2133
- "unquoted": ["<span>", "</span>", true],
2134
- "asciimath": ["\\$", "\\$"],
2135
- "latexmath": ["\\(", "\\)"]
2136
- };
2137
- var chop = (str) => str.substring(0, str.length - 1);
2138
- var convertInlineQuoted = (node) => {
2139
- const type = node.getType();
2140
- const quoteTag = QUOTE_TAGS[type];
2141
- const [open, close, tag] = quoteTag || ["", ""];
2142
- let text = node.getText();
2143
- if (type === "monospaced") {
2144
- text = renderWithBreaks(text);
2145
- }
2146
- const id = node.getId();
2147
- const role = node.getRole();
2148
- const idAttr = id ? `id="${id}"` : "";
2149
- const classAttr = role ? `class="${role}"` : "";
2150
- const attrs2 = `${idAttr} ${classAttr}`;
2151
- if (id || role) {
2152
- if (tag) {
2153
- return `${chop(open)} ${attrs2}>${text}${close}`;
2154
- } else {
2155
- return `<span ${attrs2}>${open}${text}${close}</span>`;
2156
- }
2157
- } else {
2158
- return `${open}${text}${close}`;
2159
- }
2160
- };
2161
- function convertInlineCallout2(node) {
2162
- return `<i class="conum" data-value="${node.getText()}"></i>`;
2163
- }
2164
- var ad = asciidoctor2();
2165
- var InlineConverter = class {
2166
- baseConverter;
2167
- constructor() {
2168
- this.baseConverter = new ad.Html5Converter();
2169
- }
2170
- convert(node, transform) {
2171
- switch (node.getNodeName()) {
2172
- case "inline_quoted":
2173
- return convertInlineQuoted(node);
2174
- // We know this is always inline
2175
- case "inline_callout":
2176
- return convertInlineCallout2(node);
2177
- // We know this is always inline
2178
- default:
2179
- break;
2118
+ var inlineOverrides = {
2119
+ quoted: ({ node }) => {
2120
+ let { __html } = inlineHtml([node]);
2121
+ if (node.subtype === "monospaced") {
2122
+ __html = renderWithBreaks(__html);
2180
2123
  }
2181
- return this.baseConverter.convert(node, transform);
2124
+ return /* @__PURE__ */ jsx5(Fragment3, { children: parse3(__html) });
2182
2125
  }
2183
2126
  };
2184
2127
  export {
2185
2128
  AsciiDocBlocks,
2186
2129
  DesktopOutline,
2187
- InlineConverter,
2188
2130
  SmallScreenOutline,
2189
2131
  attrs,
2190
2132
  handleDocument,
2191
2133
  highlight,
2134
+ inlineOverrides,
2192
2135
  loadAsciidoctor,
2193
2136
  renderWithBreaks,
2194
2137
  useActiveSectionTracking,