@pure-ds/storybook 0.4.16 → 0.4.19

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 (73) hide show
  1. package/.storybook/addons/html-preview/Panel.jsx +80 -29
  2. package/.storybook/addons/html-preview/preview.js +4 -5
  3. package/.storybook/manager.js +337 -49
  4. package/.storybook/preview-head.html +2 -2
  5. package/.storybook/preview.js +2 -2
  6. package/README.md +2 -2
  7. package/dist/pds-reference.json +1916 -267
  8. package/package.json +2 -2
  9. package/public/assets/css/app.css +2 -2
  10. package/public/assets/js/app.js +645 -10574
  11. package/public/assets/js/lit.js +3 -1048
  12. package/public/assets/js/pds.js +429 -7368
  13. package/public/assets/pds/components/pds-calendar.js +1 -1
  14. package/public/assets/pds/components/{pds-jsonform.js → pds-form.js} +536 -45
  15. package/public/assets/pds/custom-elements.json +271 -26
  16. package/public/assets/pds/pds-runtime-config.json +1 -1
  17. package/public/assets/pds/styles/pds-components.css +83 -221
  18. package/public/assets/pds/styles/pds-components.css.js +166 -442
  19. package/public/assets/pds/styles/pds-styles.css +240 -437
  20. package/public/assets/pds/styles/pds-styles.css.js +479 -881
  21. package/public/assets/pds/styles/pds-utilities.css +151 -214
  22. package/public/assets/pds/styles/pds-utilities.css.js +302 -428
  23. package/public/assets/pds/vscode-custom-data.json +63 -63
  24. package/scripts/build-pds-reference.mjs +112 -38
  25. package/scripts/generate-stories.js +2 -2
  26. package/src/js/common/ask.js +48 -21
  27. package/src/js/pds-configurator/pds-config-form.js +9 -9
  28. package/src/js/pds-configurator/pds-demo.js +2 -2
  29. package/src/js/pds-core/pds-config.js +14 -14
  30. package/src/js/pds-core/pds-generator.js +113 -50
  31. package/src/js/pds-core/pds-ontology.js +6 -6
  32. package/src/js/pds.d.ts +2 -2
  33. package/stories/GettingStarted.stories.js +3 -0
  34. package/stories/WhatIsPDS.stories.js +3 -0
  35. package/stories/components/PdsCalendar.stories.js +2 -2
  36. package/stories/components/PdsDrawer.stories.js +15 -15
  37. package/stories/components/PdsForm.stories.js +4356 -0
  38. package/stories/components/{PdsJsonformUiSchema.md → PdsFormUiSchema.md} +2 -2
  39. package/stories/components/PdsRichtext.stories.js +4 -17
  40. package/stories/components/PdsScrollrow.stories.js +224 -72
  41. package/stories/components/PdsSplitpanel.stories.js +63 -28
  42. package/stories/components/PdsTabstrip.stories.js +7 -7
  43. package/stories/enhancements/Accordion.stories.js +2 -2
  44. package/stories/enhancements/Dropdowns.stories.js +13 -10
  45. package/stories/enhancements/RangeSliders.stories.js +9 -9
  46. package/stories/enhancements/RequiredFields.stories.js +8 -8
  47. package/stories/enhancements/Toggles.stories.js +45 -36
  48. package/stories/enhancements/_enhancement-header.js +2 -2
  49. package/stories/foundations/Colors.stories.js +13 -13
  50. package/stories/foundations/HTMLDefaults.stories.js +4 -4
  51. package/stories/foundations/Icons.stories.js +123 -288
  52. package/stories/foundations/MeshGradients.stories.js +161 -250
  53. package/stories/foundations/SmartSurfaces.stories.js +147 -64
  54. package/stories/foundations/Spacing.stories.js +30 -30
  55. package/stories/foundations/Typography.stories.js +352 -723
  56. package/stories/foundations/ZIndex.stories.js +124 -141
  57. package/stories/layout/LayoutOverview.stories.js +345 -250
  58. package/stories/layout/LayoutSystem.stories.js +60 -76
  59. package/stories/patterns/InteractiveStates.stories.js +29 -29
  60. package/stories/patterns/Utilities.stories.js +17 -5
  61. package/stories/primitives/Alerts.stories.js +6 -6
  62. package/stories/primitives/Cards.stories.js +22 -11
  63. package/stories/primitives/{Forms.stories.js → FormElements.stories.js} +20 -11
  64. package/stories/primitives/HtmlFormElements.stories.js +128 -0
  65. package/stories/primitives/{FormGroups.stories.js → HtmlFormGroups.stories.js} +70 -21
  66. package/stories/primitives/Media.stories.js +23 -20
  67. package/stories/utilities/Backdrop.stories.js +68 -27
  68. package/stories/utils/PdsAsk.stories.js +15 -14
  69. package/public/assets/js/app.js.map +0 -7
  70. package/public/assets/js/lit.js.map +0 -7
  71. package/public/assets/js/pds.js.map +0 -7
  72. package/stories/components/PdsJsonform.stories.js +0 -1929
  73. /package/src/{pds-core → node-api}/pds-api.js +0 -0
@@ -1,8 +1,8 @@
1
- import React, { useState, useCallback, useEffect, useRef } from 'react';
1
+ import React, { useState, useCallback, useEffect, useRef } from 'react';
2
2
  import { useChannel } from '@storybook/manager-api';
3
3
  import { IconButton } from '@storybook/components';
4
4
  import { EVENTS } from './constants.js';
5
- import { styled } from '@storybook/theming';
5
+ import { styled, useTheme } from '@storybook/theming';
6
6
  import { loadShiki, escapeHtml } from '../../shiki.js';
7
7
 
8
8
  const Container = styled.div`
@@ -109,10 +109,15 @@ const CheckIcon = () => (
109
109
  );
110
110
 
111
111
  export const Panel = ({ active }) => {
112
- const [source, setSource] = useState({ markup: '', jsonForms: [] });
112
+ const [source, setSource] = useState({ markup: '', forms: [] });
113
113
  const [copied, setCopied] = useState(false);
114
114
  const [highlightedMarkup, setHighlightedMarkup] = useState('');
115
+ const [highlightedforms, setHighlightedforms] = useState([]);
115
116
  const shikiRef = useRef(null);
117
+
118
+ // Get Storybook theme to detect light/dark mode
119
+ const storybookTheme = useTheme();
120
+ const shikiTheme = storybookTheme.base === 'dark' ? 'github-dark' : 'github-light';
116
121
 
117
122
  // Load Shiki once on mount
118
123
  useEffect(() => {
@@ -121,7 +126,7 @@ export const Panel = ({ active }) => {
121
126
  });
122
127
  }, []);
123
128
 
124
- // Highlight markup when source changes
129
+ // Highlight markup when source or theme changes
125
130
  useEffect(() => {
126
131
  if (!source.markup) {
127
132
  setHighlightedMarkup('');
@@ -133,7 +138,7 @@ export const Panel = ({ active }) => {
133
138
  try {
134
139
  const html = highlighter.codeToHtml(source.markup, {
135
140
  lang: 'html',
136
- theme: 'github-dark'
141
+ theme: shikiTheme
137
142
  });
138
143
  setHighlightedMarkup(html);
139
144
  } catch (err) {
@@ -146,7 +151,7 @@ export const Panel = ({ active }) => {
146
151
  loadShiki().then(hl => {
147
152
  if (hl && source.markup) {
148
153
  try {
149
- const html = hl.codeToHtml(source.markup, { lang: 'html', theme: 'github-dark' });
154
+ const html = hl.codeToHtml(source.markup, { lang: 'html', theme: shikiTheme });
150
155
  setHighlightedMarkup(html);
151
156
  } catch (err) {
152
157
  // Keep fallback
@@ -154,30 +159,66 @@ export const Panel = ({ active }) => {
154
159
  }
155
160
  });
156
161
  }
157
- }, [source.markup]);
162
+ }, [source.markup, shikiTheme]);
163
+
164
+ // Highlight forms schemas when source or theme changes
165
+ useEffect(() => {
166
+ if (!source.forms || source.forms.length === 0) {
167
+ setHighlightedforms([]);
168
+ return;
169
+ }
170
+
171
+ const highlightJsonCode = async (code) => {
172
+ if (!code) return '';
173
+ const highlighter = shikiRef.current || await loadShiki();
174
+ if (highlighter) {
175
+ try {
176
+ return highlighter.codeToHtml(code, { lang: 'json', theme: shikiTheme });
177
+ } catch (err) {
178
+ return `<pre><code>${escapeHtml(code)}</code></pre>`;
179
+ }
180
+ }
181
+ return `<pre><code>${escapeHtml(code)}</code></pre>`;
182
+ };
183
+
184
+ const processforms = async () => {
185
+ const highlighted = await Promise.all(
186
+ source.forms.map(async (form, index) => ({
187
+ id: form.id ?? index,
188
+ label: form.label,
189
+ jsonSchema: await highlightJsonCode(form.jsonSchema),
190
+ uiSchema: await highlightJsonCode(form.uiSchema),
191
+ options: await highlightJsonCode(form.options)
192
+ }))
193
+ );
194
+ setHighlightedforms(highlighted);
195
+ };
196
+
197
+ processforms();
198
+ }, [source.forms, shikiTheme]);
158
199
 
159
200
  useChannel({
160
201
  [EVENTS.UPDATE_HTML]: (payload) => {
161
202
  if (typeof payload === 'string') {
162
- setSource({ markup: payload || '', jsonForms: [] });
203
+ setSource({ markup: payload || '', forms: [] });
163
204
  return;
164
205
  }
165
206
 
166
207
  if (payload && typeof payload === 'object') {
167
208
  setSource({
168
209
  markup: payload.markup || '',
169
- jsonForms: Array.isArray(payload.jsonForms) ? payload.jsonForms : []
210
+ forms: Array.isArray(payload.forms) ? payload.forms : []
170
211
  });
171
212
  return;
172
213
  }
173
214
 
174
- setSource({ markup: '', jsonForms: [] });
215
+ setSource({ markup: '', forms: [] });
175
216
  }
176
217
  });
177
218
 
178
219
  // Request HTML update when panel becomes active
179
220
  React.useEffect(() => {
180
- if (active && !source.markup && source.jsonForms.length === 0) {
221
+ if (active && !source.markup && source.forms.length === 0) {
181
222
  // Trigger a re-extraction by emitting a request event
182
223
  // The decorator will pick this up on the next render cycle
183
224
  const container = document.querySelector('#storybook-root');
@@ -189,7 +230,7 @@ export const Panel = ({ active }) => {
189
230
  }, 100);
190
231
  }
191
232
  }
192
- }, [active, source.markup, source.jsonForms.length]);
233
+ }, [active, source.markup, source.forms.length]);
193
234
 
194
235
  const copyToClipboard = useCallback(async () => {
195
236
  try {
@@ -203,9 +244,9 @@ export const Panel = ({ active }) => {
203
244
  }, [source.markup]);
204
245
 
205
246
  const hasMarkup = Boolean(source.markup);
206
- const hasJsonForms = source.jsonForms.length > 0;
247
+ const hasforms = source.forms.length > 0;
207
248
 
208
- if (!hasMarkup && !hasJsonForms) {
249
+ if (!hasMarkup && !hasforms) {
209
250
  return (
210
251
  <Container>
211
252
  <EmptyState>
@@ -225,38 +266,48 @@ export const Panel = ({ active }) => {
225
266
  </SectionWrapper>
226
267
  )}
227
268
 
228
- {hasJsonForms && source.jsonForms.map((form, index) => {
229
- const key = form.id ?? index;
230
- const heading = source.jsonForms.length > 1 ? (form.label || `Form ${index + 1}`) : 'pds-jsonform';
269
+ {hasforms && source.forms.map((sourceForm, index) => {
270
+ const key = sourceForm.id ?? index;
271
+ const highlightedForm = highlightedforms[index];
272
+ const heading = source.forms.length > 1 ? (sourceForm.label || `Form ${index + 1}`) : 'pds-form';
231
273
 
232
274
  return (
233
275
  <SectionWrapper key={key}>
234
276
  <SectionHeading>{heading}</SectionHeading>
235
277
 
236
- {form.jsonSchema && (
278
+ {sourceForm.jsonSchema && (
237
279
  <>
238
280
  <Subheading>jsonSchema</Subheading>
239
- <CodeBlock $compact>
240
- <code>{form.jsonSchema}</code>
241
- </CodeBlock>
281
+ <CodeBlock
282
+ $compact
283
+ dangerouslySetInnerHTML={{
284
+ __html: highlightedForm?.jsonSchema || `<pre><code>${escapeHtml(sourceForm.jsonSchema)}</code></pre>`
285
+ }}
286
+ />
242
287
  </>
243
288
  )}
244
289
 
245
- {form.uiSchema && (
290
+ {sourceForm.uiSchema && (
246
291
  <>
247
292
  <Subheading>uiSchema</Subheading>
248
- <CodeBlock $compact>
249
- <code>{form.uiSchema}</code>
250
- </CodeBlock>
293
+ <CodeBlock
294
+ $compact
295
+ dangerouslySetInnerHTML={{
296
+ __html: highlightedForm?.uiSchema || `<pre><code>${escapeHtml(sourceForm.uiSchema)}</code></pre>`
297
+ }}
298
+ />
251
299
  </>
252
300
  )}
253
301
 
254
- {form.options && (
302
+ {sourceForm.options && (
255
303
  <>
256
304
  <Subheading>options</Subheading>
257
- <CodeBlock $compact>
258
- <code>{form.options}</code>
259
- </CodeBlock>
305
+ <CodeBlock
306
+ $compact
307
+ dangerouslySetInnerHTML={{
308
+ __html: highlightedForm?.options || `<pre><code>${escapeHtml(sourceForm.options)}</code></pre>`
309
+ }}
310
+ />
260
311
  </>
261
312
  )}
262
313
  </SectionWrapper>
@@ -1,4 +1,4 @@
1
- import { useEffect } from '@storybook/preview-api';
1
+ import { useEffect } from '@storybook/preview-api';
2
2
  import { addons } from '@storybook/preview-api';
3
3
  import { EVENTS } from './constants.js';
4
4
  import { render as litRender } from 'lit';
@@ -166,13 +166,12 @@ export const withHTMLExtractor = (storyFn, context) => {
166
166
  html = formatHTML(extractHTML(container));
167
167
  }
168
168
 
169
- const forms = Array.from(container.querySelectorAll('pds-jsonform'));
170
- const jsonForms = forms
169
+ const forms = Array.from(container.querySelectorAll('pds-form'))
171
170
  .map((form, index) => {
172
171
  const label =
173
172
  form.getAttribute?.('id') ||
174
173
  form.getAttribute?.('name') ||
175
- (forms.length > 1 ? `Form ${index + 1}` : 'Form');
174
+ (Array.from(container.querySelectorAll('pds-form')).length > 1 ? `Form ${index + 1}` : 'Form');
176
175
 
177
176
  const jsonSchema = serializeForDisplay(form.jsonSchema);
178
177
  const uiSchema = serializeForDisplay(form.uiSchema);
@@ -190,7 +189,7 @@ export const withHTMLExtractor = (storyFn, context) => {
190
189
 
191
190
  channel.emit(EVENTS.UPDATE_HTML, {
192
191
  markup: html || '',
193
- jsonForms
192
+ forms
194
193
  });
195
194
  }
196
195
  };