@djangocfg/ui-tools 2.1.289 → 2.1.291

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 (98) hide show
  1. package/README.md +14 -3
  2. package/dist/{DocsLayout-YDR7DSMM.cjs → DocsLayout-IKH7BLSU.cjs} +1537 -682
  3. package/dist/DocsLayout-IKH7BLSU.cjs.map +1 -0
  4. package/dist/{DocsLayout-TKJQ5W5E.mjs → DocsLayout-JPXFUKAR.mjs} +1429 -574
  5. package/dist/DocsLayout-JPXFUKAR.mjs.map +1 -0
  6. package/dist/{PrettyCode.client-5GABIN2I.cjs → PrettyCode.client-RPDIE5CH.cjs} +104 -3
  7. package/dist/PrettyCode.client-RPDIE5CH.cjs.map +1 -0
  8. package/dist/{PrettyCode.client-IZTXXYHG.mjs → PrettyCode.client-SPMTQEG4.mjs} +106 -5
  9. package/dist/PrettyCode.client-SPMTQEG4.mjs.map +1 -0
  10. package/dist/{chunk-IULI4XII.cjs → chunk-5Q4UMSWB.cjs} +355 -9
  11. package/dist/chunk-5Q4UMSWB.cjs.map +1 -0
  12. package/dist/{chunk-VZGQC3NG.mjs → chunk-EFWOJPA6.mjs} +349 -9
  13. package/dist/chunk-EFWOJPA6.mjs.map +1 -0
  14. package/dist/index.cjs +18 -10
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +35 -1
  17. package/dist/index.d.ts +35 -1
  18. package/dist/index.mjs +13 -5
  19. package/dist/index.mjs.map +1 -1
  20. package/package.json +20 -15
  21. package/src/components/markdown/MarkdownMessage.tsx +46 -0
  22. package/src/tools/MarkdownEditor/MarkdownEditor.tsx +42 -1
  23. package/src/tools/OpenapiViewer/OpenapiViewer.story.tsx +87 -178
  24. package/src/tools/OpenapiViewer/README.md +114 -6
  25. package/src/tools/OpenapiViewer/components/DocsLayout/ApiIntroSection.tsx +20 -6
  26. package/src/tools/OpenapiViewer/components/DocsLayout/DocsView.tsx +6 -0
  27. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/CodeSamples/LanguageTabs.tsx +36 -0
  28. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/CodeSamples/index.tsx +56 -0
  29. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/CodeSamples/useCodeSnippet.ts +77 -0
  30. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Header/MetaActions.tsx +146 -0
  31. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Header/MethodBadge.tsx +6 -0
  32. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Header/PathDisplay.tsx +26 -0
  33. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Header/index.tsx +87 -0
  34. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Parameters/ParamGroup.tsx +30 -0
  35. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Parameters/ParamRow.tsx +36 -0
  36. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Parameters/index.tsx +22 -0
  37. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/RequestBody/index.tsx +33 -0
  38. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Responses/ResponseBody.tsx +76 -0
  39. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Responses/ResponseRow.tsx +80 -0
  40. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Responses/StatusTag.tsx +32 -0
  41. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Responses/index.tsx +21 -0
  42. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/SchemaFields/FieldRow.tsx +106 -0
  43. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/SchemaFields/buildTree.ts +127 -0
  44. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/SchemaFields/index.tsx +31 -0
  45. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/SchemaFields/types.ts +28 -0
  46. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Section/SectionHeader.tsx +87 -0
  47. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Section/defaults.ts +27 -0
  48. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Section/index.tsx +45 -0
  49. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/context.tsx +56 -0
  50. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/hooks/useSectionHash.ts +63 -0
  51. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/index.tsx +96 -0
  52. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/store/index.ts +133 -0
  53. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/store/selectors.ts +40 -0
  54. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/types.ts +17 -0
  55. package/src/tools/OpenapiViewer/components/DocsLayout/SchemaCopyMenu.tsx +8 -2
  56. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/BrandHeader.tsx +48 -0
  57. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/CategoryBlock.tsx +33 -0
  58. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/EndpointRow.tsx +73 -0
  59. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/MethodChips.tsx +43 -0
  60. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/SchemaSection.tsx +27 -0
  61. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/SearchInput.tsx +45 -0
  62. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/SidebarBody.tsx +50 -0
  63. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/Toolbar.tsx +64 -0
  64. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/buildVM.ts +126 -0
  65. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/index.tsx +112 -0
  66. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/types.ts +42 -0
  67. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/useDebouncedValue.ts +14 -0
  68. package/src/tools/OpenapiViewer/components/DocsLayout/SlideInPlayground.tsx +10 -7
  69. package/src/tools/OpenapiViewer/components/DocsLayout/TryItSheet.tsx +9 -6
  70. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/PrettyView.tsx +55 -0
  71. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/PreviewView.tsx +115 -0
  72. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/RawView.tsx +24 -0
  73. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/StatusBar.tsx +63 -0
  74. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/ViewTabs.tsx +45 -0
  75. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/detectContent.ts +97 -0
  76. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/index.tsx +93 -0
  77. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/types.ts +26 -0
  78. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/useResponseView.ts +62 -0
  79. package/src/tools/OpenapiViewer/hooks/useOpenApiSchema.ts +41 -71
  80. package/src/tools/OpenapiViewer/types.ts +10 -0
  81. package/src/tools/OpenapiViewer/utils/codeSamples.ts +287 -0
  82. package/src/tools/OpenapiViewer/utils/index.ts +3 -0
  83. package/src/tools/OpenapiViewer/utils/operationToHar.ts +119 -0
  84. package/src/tools/OpenapiViewer/utils/sampler.ts +72 -0
  85. package/src/tools/PrettyCode/PrettyCode.client.tsx +88 -1
  86. package/src/tools/PrettyCode/PrettyCode.story.tsx +114 -361
  87. package/src/tools/PrettyCode/index.tsx +13 -0
  88. package/src/tools/PrettyCode/lazy.tsx +5 -0
  89. package/src/tools/PrettyCode/registerPrismLanguages.ts +111 -0
  90. package/dist/DocsLayout-TKJQ5W5E.mjs.map +0 -1
  91. package/dist/DocsLayout-YDR7DSMM.cjs.map +0 -1
  92. package/dist/PrettyCode.client-5GABIN2I.cjs.map +0 -1
  93. package/dist/PrettyCode.client-IZTXXYHG.mjs.map +0 -1
  94. package/dist/chunk-IULI4XII.cjs.map +0 -1
  95. package/dist/chunk-VZGQC3NG.mjs.map +0 -1
  96. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc.tsx +0 -273
  97. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar.tsx +0 -439
  98. package/src/tools/OpenapiViewer/components/shared/ResponsePanel.tsx +0 -127
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Register extra Prism language grammars onto the vendored Prism
3
+ * instance that ``prism-react-renderer`` ships.
4
+ *
5
+ * Why this file exists:
6
+ * ``prism-react-renderer@2.x`` bundles only a small set of core
7
+ * languages (javascript, typescript, python, go, json, css,
8
+ * markup, clike, …). Anything else — ``bash``, ``ruby``, ``java``,
9
+ * ``php`` — isn't in the bundle, so passing ``language="bash"`` to
10
+ * ``<Highlight>`` silently renders as plain text.
11
+ *
12
+ * Canonical solution (per the official README):
13
+ * - Grab the exported ``Prism`` instance.
14
+ * - Hang it off ``globalThis`` so that ``prismjs`` language
15
+ * components can find it when they self-register (they read
16
+ * ``window.Prism`` / ``global.Prism`` at module-evaluation time).
17
+ * - Load each grammar via dynamic ``import()`` — bare ``require``
18
+ * doesn't work in ESM/Vite and static ``import 'prismjs/…'``
19
+ * runs before we can hang Prism on the global.
20
+ *
21
+ * Runs once on module load, with a guard so repeated imports in
22
+ * different bundles are a no-op. Safe for SSR: the grammars don't
23
+ * touch the DOM and the dynamic import is awaited asynchronously —
24
+ * server renders just miss the extra grammars, client renders pick
25
+ * them up after hydration which is when the <Highlight> components
26
+ * actually render anyway.
27
+ */
28
+
29
+ /* eslint-disable @typescript-eslint/no-explicit-any */
30
+
31
+ import { useSyncExternalStore } from 'react';
32
+ import { Prism } from 'prism-react-renderer';
33
+
34
+ // Hang the vendored Prism on the global so ``prismjs`` language
35
+ // components can find it when their self-registration runs.
36
+ const globalScope: any = typeof globalThis !== 'undefined' ? globalThis : {};
37
+ if (!globalScope.Prism) {
38
+ globalScope.Prism = Prism;
39
+ }
40
+
41
+ // Ready-state machinery: one-shot boolean + subscribers. When loading
42
+ // finishes we flip ``ready`` and notify listeners so components that
43
+ // rendered before the grammars loaded can re-render and pick them up.
44
+ let ready = false;
45
+ let loading: Promise<void> | null = null;
46
+ const listeners = new Set<() => void>();
47
+
48
+ function subscribe(cb: () => void): () => void {
49
+ listeners.add(cb);
50
+ return () => listeners.delete(cb);
51
+ }
52
+
53
+ function getSnapshot(): boolean {
54
+ return ready;
55
+ }
56
+
57
+ // Server snapshot — always ``true`` so SSR doesn't trip the
58
+ // ``server ≠ client`` warning. The actual registration only runs on
59
+ // the client; server renders fall back to the bundled Prism set,
60
+ // which for the OpenAPI viewer means JS / Python / Go highlight
61
+ // server-side and bash / java / ruby / php render plain until hydration.
62
+ function getServerSnapshot(): boolean {
63
+ return true;
64
+ }
65
+
66
+ export async function ensurePrismLanguages(): Promise<void> {
67
+ if (ready) return;
68
+ if (loading) return loading;
69
+
70
+ loading = (async () => {
71
+ // Dynamic imports so these modules evaluate AFTER we've
72
+ // attached Prism to the global scope above.
73
+ //
74
+ // Load order matters: ``prism-php`` calls
75
+ // ``Prism.languages.markup.tokenizePlaceholders`` at module
76
+ // evaluation time, which is only defined after
77
+ // ``markup-templating`` loads — so that must come first.
78
+ // ``bash`` / ``java`` / ``ruby`` only depend on ``clike``
79
+ // which is already bundled in ``prism-react-renderer``.
80
+ await import('prismjs/components/prism-markup-templating' as string);
81
+ await Promise.all([
82
+ import('prismjs/components/prism-bash' as string),
83
+ import('prismjs/components/prism-java' as string),
84
+ import('prismjs/components/prism-ruby' as string),
85
+ import('prismjs/components/prism-php' as string),
86
+ ]);
87
+ ready = true;
88
+ listeners.forEach((cb) => cb());
89
+ })();
90
+
91
+ return loading;
92
+ }
93
+
94
+ /** Hook that triggers a re-render when the extra grammars finish
95
+ * loading. Used by ``PrettyCode`` so the first render (which might
96
+ * happen before loading completes) gets re-highlighted once the
97
+ * grammars are available. */
98
+ export function useEnsurePrismLanguages(): boolean {
99
+ const loaded = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
100
+ if (!loaded) {
101
+ // Kick off loading (idempotent — re-entry is cheap) so the
102
+ // next store update flips ``ready`` and we re-render.
103
+ void ensurePrismLanguages();
104
+ }
105
+ return loaded;
106
+ }
107
+
108
+ // Also kick off on module load so the grammars start loading as
109
+ // early as possible — by the time the user clicks a code-sample tab
110
+ // they've usually finished.
111
+ void ensurePrismLanguages();