@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.
- package/.storybook/addons/html-preview/Panel.jsx +80 -29
- package/.storybook/addons/html-preview/preview.js +4 -5
- package/.storybook/manager.js +337 -49
- package/.storybook/preview-head.html +2 -2
- package/.storybook/preview.js +2 -2
- package/README.md +2 -2
- package/dist/pds-reference.json +1916 -267
- package/package.json +2 -2
- package/public/assets/css/app.css +2 -2
- package/public/assets/js/app.js +645 -10574
- package/public/assets/js/lit.js +3 -1048
- package/public/assets/js/pds.js +429 -7368
- package/public/assets/pds/components/pds-calendar.js +1 -1
- package/public/assets/pds/components/{pds-jsonform.js → pds-form.js} +536 -45
- package/public/assets/pds/custom-elements.json +271 -26
- package/public/assets/pds/pds-runtime-config.json +1 -1
- package/public/assets/pds/styles/pds-components.css +83 -221
- package/public/assets/pds/styles/pds-components.css.js +166 -442
- package/public/assets/pds/styles/pds-styles.css +240 -437
- package/public/assets/pds/styles/pds-styles.css.js +479 -881
- package/public/assets/pds/styles/pds-utilities.css +151 -214
- package/public/assets/pds/styles/pds-utilities.css.js +302 -428
- package/public/assets/pds/vscode-custom-data.json +63 -63
- package/scripts/build-pds-reference.mjs +112 -38
- package/scripts/generate-stories.js +2 -2
- package/src/js/common/ask.js +48 -21
- package/src/js/pds-configurator/pds-config-form.js +9 -9
- package/src/js/pds-configurator/pds-demo.js +2 -2
- package/src/js/pds-core/pds-config.js +14 -14
- package/src/js/pds-core/pds-generator.js +113 -50
- package/src/js/pds-core/pds-ontology.js +6 -6
- package/src/js/pds.d.ts +2 -2
- package/stories/GettingStarted.stories.js +3 -0
- package/stories/WhatIsPDS.stories.js +3 -0
- package/stories/components/PdsCalendar.stories.js +2 -2
- package/stories/components/PdsDrawer.stories.js +15 -15
- package/stories/components/PdsForm.stories.js +4356 -0
- package/stories/components/{PdsJsonformUiSchema.md → PdsFormUiSchema.md} +2 -2
- package/stories/components/PdsRichtext.stories.js +4 -17
- package/stories/components/PdsScrollrow.stories.js +224 -72
- package/stories/components/PdsSplitpanel.stories.js +63 -28
- package/stories/components/PdsTabstrip.stories.js +7 -7
- package/stories/enhancements/Accordion.stories.js +2 -2
- package/stories/enhancements/Dropdowns.stories.js +13 -10
- package/stories/enhancements/RangeSliders.stories.js +9 -9
- package/stories/enhancements/RequiredFields.stories.js +8 -8
- package/stories/enhancements/Toggles.stories.js +45 -36
- package/stories/enhancements/_enhancement-header.js +2 -2
- package/stories/foundations/Colors.stories.js +13 -13
- package/stories/foundations/HTMLDefaults.stories.js +4 -4
- package/stories/foundations/Icons.stories.js +123 -288
- package/stories/foundations/MeshGradients.stories.js +161 -250
- package/stories/foundations/SmartSurfaces.stories.js +147 -64
- package/stories/foundations/Spacing.stories.js +30 -30
- package/stories/foundations/Typography.stories.js +352 -723
- package/stories/foundations/ZIndex.stories.js +124 -141
- package/stories/layout/LayoutOverview.stories.js +345 -250
- package/stories/layout/LayoutSystem.stories.js +60 -76
- package/stories/patterns/InteractiveStates.stories.js +29 -29
- package/stories/patterns/Utilities.stories.js +17 -5
- package/stories/primitives/Alerts.stories.js +6 -6
- package/stories/primitives/Cards.stories.js +22 -11
- package/stories/primitives/{Forms.stories.js → FormElements.stories.js} +20 -11
- package/stories/primitives/HtmlFormElements.stories.js +128 -0
- package/stories/primitives/{FormGroups.stories.js → HtmlFormGroups.stories.js} +70 -21
- package/stories/primitives/Media.stories.js +23 -20
- package/stories/utilities/Backdrop.stories.js +68 -27
- package/stories/utils/PdsAsk.stories.js +15 -14
- package/public/assets/js/app.js.map +0 -7
- package/public/assets/js/lit.js.map +0 -7
- package/public/assets/js/pds.js.map +0 -7
- package/stories/components/PdsJsonform.stories.js +0 -1929
- /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: '',
|
|
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:
|
|
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:
|
|
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 || '',
|
|
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
|
-
|
|
210
|
+
forms: Array.isArray(payload.forms) ? payload.forms : []
|
|
170
211
|
});
|
|
171
212
|
return;
|
|
172
213
|
}
|
|
173
214
|
|
|
174
|
-
setSource({ markup: '',
|
|
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.
|
|
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.
|
|
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
|
|
247
|
+
const hasforms = source.forms.length > 0;
|
|
207
248
|
|
|
208
|
-
if (!hasMarkup && !
|
|
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
|
-
{
|
|
229
|
-
const key =
|
|
230
|
-
const
|
|
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
|
-
{
|
|
278
|
+
{sourceForm.jsonSchema && (
|
|
237
279
|
<>
|
|
238
280
|
<Subheading>jsonSchema</Subheading>
|
|
239
|
-
<CodeBlock
|
|
240
|
-
|
|
241
|
-
|
|
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
|
-
{
|
|
290
|
+
{sourceForm.uiSchema && (
|
|
246
291
|
<>
|
|
247
292
|
<Subheading>uiSchema</Subheading>
|
|
248
|
-
<CodeBlock
|
|
249
|
-
|
|
250
|
-
|
|
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
|
-
{
|
|
302
|
+
{sourceForm.options && (
|
|
255
303
|
<>
|
|
256
304
|
<Subheading>options</Subheading>
|
|
257
|
-
<CodeBlock
|
|
258
|
-
|
|
259
|
-
|
|
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-
|
|
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
|
-
(
|
|
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
|
-
|
|
192
|
+
forms
|
|
194
193
|
});
|
|
195
194
|
}
|
|
196
195
|
};
|