@vev/silke 1.2.0 → 1.2.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/.turbo/turbo-build.log +79 -79
- package/CHANGELOG.md +10 -0
- package/dist/index.js +32 -32
- package/dist/index.js.map +4 -4
- package/dist/styles.css +72 -72
- package/dist/types/components/silke-form-schema/fields/utils/generate-preview.spec.d.ts +1 -0
- package/dist/types/components/silke-form-schema/fields/utils/generate-title.d.ts +10 -0
- package/package.json +3 -3
- package/src/components/silke-form-schema/fields/string-field.tsx +8 -6
- package/src/components/silke-form-schema/fields/utils/generate-image.ts +5 -14
- package/src/components/silke-form-schema/fields/utils/generate-preview.spec.ts +49 -0
- package/src/components/silke-form-schema/fields/utils/generate-title.ts +23 -10
package/dist/styles.css
CHANGED
|
@@ -2535,51 +2535,6 @@ img.silke-icon_icon_84f9e9d6b3 {
|
|
|
2535
2535
|
* Get font size base on base font size
|
|
2536
2536
|
* scaling = round(size * 1.200) (Minor Third)
|
|
2537
2537
|
*/
|
|
2538
|
-
.silke-overflow-menu_btnOpen_9d7478ea25 {
|
|
2539
|
-
background-color: var(--color-neutral-20) !important;
|
|
2540
|
-
border: none !important;
|
|
2541
|
-
}
|
|
2542
|
-
.silke-overflow-menu_btnOpen_9d7478ea25::before {
|
|
2543
|
-
display: none !important;
|
|
2544
|
-
}
|
|
2545
|
-
|
|
2546
|
-
.silke-overflow-menu_menu_9d7478ea25 {
|
|
2547
|
-
overflow: hidden;
|
|
2548
|
-
min-width: 70px;
|
|
2549
|
-
background: var(--color-neutral-20);
|
|
2550
|
-
border-radius: var(--border-radius-small);
|
|
2551
|
-
filter: var(--shadow-level-4);
|
|
2552
|
-
}
|
|
2553
|
-
.silke-overflow-menu_menu_9d7478ea25 hr {
|
|
2554
|
-
margin: 8px 0;
|
|
2555
|
-
background: var(--color-neutral-60);
|
|
2556
|
-
}
|
|
2557
|
-
.silke-overflow-menu_menu_9d7478ea25:focus {
|
|
2558
|
-
outline: none;
|
|
2559
|
-
}
|
|
2560
|
-
.silke-overflow-menu_menu_9d7478ea25:focus-visible {
|
|
2561
|
-
box-shadow: 0 0 0 4px var(--color-neutral-100);
|
|
2562
|
-
}
|
|
2563
|
-
.silke-overflow-menu_menu_9d7478ea25 button,
|
|
2564
|
-
.silke-overflow-menu_menu_9d7478ea25 a {
|
|
2565
|
-
justify-content: start !important;
|
|
2566
|
-
}
|
|
2567
|
-
/**********************
|
|
2568
|
-
* SOME MATH
|
|
2569
|
-
************************/
|
|
2570
|
-
/**********************
|
|
2571
|
-
* FONT
|
|
2572
|
-
************************/
|
|
2573
|
-
/**********************
|
|
2574
|
-
* SPACING
|
|
2575
|
-
************************/
|
|
2576
|
-
/**********************
|
|
2577
|
-
* SIZES
|
|
2578
|
-
************************/
|
|
2579
|
-
/**
|
|
2580
|
-
* Get font size base on base font size
|
|
2581
|
-
* scaling = round(size * 1.200) (Minor Third)
|
|
2582
|
-
*/
|
|
2583
2538
|
.silke-image_img_45cd7ad714 {
|
|
2584
2539
|
-o-object-position: center center;
|
|
2585
2540
|
object-position: center center;
|
|
@@ -2625,39 +2580,34 @@ img.silke-icon_icon_84f9e9d6b3 {
|
|
|
2625
2580
|
* Get font size base on base font size
|
|
2626
2581
|
* scaling = round(size * 1.200) (Minor Third)
|
|
2627
2582
|
*/
|
|
2628
|
-
.silke-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
color: var(--color-accent-40);
|
|
2632
|
-
-webkit-user-select: text;
|
|
2633
|
-
-moz-user-select: text;
|
|
2634
|
-
user-select: text;
|
|
2635
|
-
}
|
|
2636
|
-
.silke-link.secondary {
|
|
2637
|
-
color: var(--color-neutral-40);
|
|
2583
|
+
.silke-overflow-menu_btnOpen_9d7478ea25 {
|
|
2584
|
+
background-color: var(--color-neutral-20) !important;
|
|
2585
|
+
border: none !important;
|
|
2638
2586
|
}
|
|
2639
|
-
.silke-
|
|
2640
|
-
|
|
2641
|
-
box-shadow: 0 0 0 2px var(--color-neutral-100);
|
|
2587
|
+
.silke-overflow-menu_btnOpen_9d7478ea25::before {
|
|
2588
|
+
display: none !important;
|
|
2642
2589
|
}
|
|
2643
|
-
|
|
2644
|
-
|
|
2590
|
+
|
|
2591
|
+
.silke-overflow-menu_menu_9d7478ea25 {
|
|
2592
|
+
overflow: hidden;
|
|
2593
|
+
min-width: 70px;
|
|
2594
|
+
background: var(--color-neutral-20);
|
|
2595
|
+
border-radius: var(--border-radius-small);
|
|
2596
|
+
filter: var(--shadow-level-4);
|
|
2645
2597
|
}
|
|
2646
|
-
.silke-
|
|
2647
|
-
|
|
2598
|
+
.silke-overflow-menu_menu_9d7478ea25 hr {
|
|
2599
|
+
margin: 8px 0;
|
|
2600
|
+
background: var(--color-neutral-60);
|
|
2648
2601
|
}
|
|
2649
|
-
.silke-
|
|
2650
|
-
|
|
2602
|
+
.silke-overflow-menu_menu_9d7478ea25:focus {
|
|
2603
|
+
outline: none;
|
|
2651
2604
|
}
|
|
2652
|
-
.silke-
|
|
2653
|
-
|
|
2605
|
+
.silke-overflow-menu_menu_9d7478ea25:focus-visible {
|
|
2606
|
+
box-shadow: 0 0 0 4px var(--color-neutral-100);
|
|
2654
2607
|
}
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
width: auto;
|
|
2659
|
-
text-align: inherit;
|
|
2660
|
-
padding: 0;
|
|
2608
|
+
.silke-overflow-menu_menu_9d7478ea25 button,
|
|
2609
|
+
.silke-overflow-menu_menu_9d7478ea25 a {
|
|
2610
|
+
justify-content: start !important;
|
|
2661
2611
|
}
|
|
2662
2612
|
/**********************
|
|
2663
2613
|
* SOME MATH
|
|
@@ -2724,6 +2674,56 @@ button.silke-link {
|
|
|
2724
2674
|
* Get font size base on base font size
|
|
2725
2675
|
* scaling = round(size * 1.200) (Minor Third)
|
|
2726
2676
|
*/
|
|
2677
|
+
.silke-link {
|
|
2678
|
+
text-decoration: underline;
|
|
2679
|
+
cursor: pointer;
|
|
2680
|
+
color: var(--color-accent-40);
|
|
2681
|
+
-webkit-user-select: text;
|
|
2682
|
+
-moz-user-select: text;
|
|
2683
|
+
user-select: text;
|
|
2684
|
+
}
|
|
2685
|
+
.silke-link.secondary {
|
|
2686
|
+
color: var(--color-neutral-40);
|
|
2687
|
+
}
|
|
2688
|
+
.silke-link:focus-visible {
|
|
2689
|
+
outline: none;
|
|
2690
|
+
box-shadow: 0 0 0 2px var(--color-neutral-100);
|
|
2691
|
+
}
|
|
2692
|
+
.silke-link:hover {
|
|
2693
|
+
text-decoration: none;
|
|
2694
|
+
}
|
|
2695
|
+
.silke-link--standalone {
|
|
2696
|
+
text-decoration: none;
|
|
2697
|
+
}
|
|
2698
|
+
.silke-link--standalone:hover {
|
|
2699
|
+
text-decoration: underline;
|
|
2700
|
+
}
|
|
2701
|
+
.silke-link-icon {
|
|
2702
|
+
margin-left: 0.25em;
|
|
2703
|
+
}
|
|
2704
|
+
button.silke-link {
|
|
2705
|
+
border: 0;
|
|
2706
|
+
background: transparent;
|
|
2707
|
+
width: auto;
|
|
2708
|
+
text-align: inherit;
|
|
2709
|
+
padding: 0;
|
|
2710
|
+
}
|
|
2711
|
+
/**********************
|
|
2712
|
+
* SOME MATH
|
|
2713
|
+
************************/
|
|
2714
|
+
/**********************
|
|
2715
|
+
* FONT
|
|
2716
|
+
************************/
|
|
2717
|
+
/**********************
|
|
2718
|
+
* SPACING
|
|
2719
|
+
************************/
|
|
2720
|
+
/**********************
|
|
2721
|
+
* SIZES
|
|
2722
|
+
************************/
|
|
2723
|
+
/**
|
|
2724
|
+
* Get font size base on base font size
|
|
2725
|
+
* scaling = round(size * 1.200) (Minor Third)
|
|
2726
|
+
*/
|
|
2727
2727
|
.silke-sortable-list_item_cdeed952d0 [data-drag-handle] {
|
|
2728
2728
|
cursor: grab;
|
|
2729
2729
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
1
2
|
import { VevProps } from '@vev/utils';
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the schema's `preview` for an array item. A `preview` function is component code
|
|
5
|
+
* (often AI-generated) that runs for every item as soon as the list renders, so a throw or a
|
|
6
|
+
* missing return value falls back to the derived title/image instead of crashing the form.
|
|
7
|
+
*/
|
|
8
|
+
export declare const getPreview: (data: any, schema?: VevProps | VevProps[] | string) => {
|
|
9
|
+
title?: string;
|
|
10
|
+
image?: string | ReactNode;
|
|
11
|
+
};
|
|
2
12
|
export declare const generateTitle: (data: {
|
|
3
13
|
[key: string]: any;
|
|
4
14
|
} | {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vev/silke",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"prism-react-renderer": "^2.4.1",
|
|
39
39
|
"tinycolor2": "^1.6.0",
|
|
40
40
|
"@vev/interactions": "1.0.2",
|
|
41
|
-
"@vev/react": "0.4.
|
|
42
|
-
"@vev/utils": "1.
|
|
41
|
+
"@vev/react": "0.4.1",
|
|
42
|
+
"@vev/utils": "1.4.0",
|
|
43
43
|
"@vev/variables": "1.0.3"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
@@ -20,7 +20,9 @@ const StringField = ({
|
|
|
20
20
|
}: SchemaFieldProps<StringFieldType>) => {
|
|
21
21
|
const { options } = schema;
|
|
22
22
|
|
|
23
|
-
const [linkItems, setLinkItems] = useState<
|
|
23
|
+
const [linkItems, setLinkItems] = useState<
|
|
24
|
+
{ label: string; value: string; icon?: any; subLabel?: string }[]
|
|
25
|
+
>([]);
|
|
24
26
|
useEffect(() => {
|
|
25
27
|
if (options?.html && context?.actions?.availableLinks) {
|
|
26
28
|
Promise.resolve(context.actions.availableLinks()).then(setLinkItems);
|
|
@@ -36,7 +38,7 @@ const StringField = ({
|
|
|
36
38
|
return suggestion.value === `${value}`;
|
|
37
39
|
});
|
|
38
40
|
|
|
39
|
-
if (schema.options?.suggestions && schema.options?.suggestions.length) {
|
|
41
|
+
if (!schema.secret && schema.options?.suggestions && schema.options?.suggestions.length) {
|
|
40
42
|
if (suggestion) {
|
|
41
43
|
return (
|
|
42
44
|
<SilkeBox column>
|
|
@@ -61,7 +63,7 @@ const StringField = ({
|
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
if (options?.html) {
|
|
66
|
+
if (!schema.secret && options?.html) {
|
|
65
67
|
return (
|
|
66
68
|
<SilkeRichTextField
|
|
67
69
|
disabled={disabled}
|
|
@@ -85,10 +87,10 @@ const StringField = ({
|
|
|
85
87
|
disabled={disabled}
|
|
86
88
|
readOnly={readonly}
|
|
87
89
|
value={value || ''}
|
|
88
|
-
multiline={!!options?.multiline}
|
|
90
|
+
multiline={!schema.secret && !!options?.multiline}
|
|
89
91
|
style={{}}
|
|
90
92
|
label={getTitle(schema)}
|
|
91
|
-
type={options?.type || 'text'}
|
|
93
|
+
type={schema.secret ? 'password' : options?.type || 'text'}
|
|
92
94
|
minLength={options?.minLength}
|
|
93
95
|
maxLength={options?.maxLength}
|
|
94
96
|
onChange={onChange}
|
|
@@ -105,7 +107,7 @@ const StringField = ({
|
|
|
105
107
|
}
|
|
106
108
|
}}
|
|
107
109
|
/>
|
|
108
|
-
{showSuggestions && schema.options?.suggestions && (
|
|
110
|
+
{!schema.secret && showSuggestions && schema.options?.suggestions && (
|
|
109
111
|
<SilkePopover
|
|
110
112
|
anchorOrigin="bottom-center"
|
|
111
113
|
targetOrigin="top-center"
|
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { isObject,
|
|
2
|
+
import { isObject, isArray } from 'lodash';
|
|
3
3
|
import { VevProps } from '@vev/utils';
|
|
4
|
-
import { flattenObject } from './generate-title';
|
|
4
|
+
import { flattenObject, getPreview } from './generate-title';
|
|
5
5
|
|
|
6
6
|
export const generateImage = (
|
|
7
7
|
data: VevProps | VevProps[] | string,
|
|
8
8
|
schema?: VevProps | VevProps[] | string,
|
|
9
9
|
): string | ReactNode | undefined => {
|
|
10
|
-
let image
|
|
11
|
-
|
|
12
|
-
if (Array.isArray(schema)) schema = schema.find((s) => s.preview) || schema[0];
|
|
13
|
-
|
|
14
|
-
if (isObject(schema) && schema?.preview) {
|
|
15
|
-
if (isFunction(schema.preview)) {
|
|
16
|
-
({ image } = schema.preview(data as VevProps));
|
|
17
|
-
} else {
|
|
18
|
-
image = schema?.preview?.image;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
10
|
+
let { image } = getPreview(data, schema);
|
|
21
11
|
|
|
22
12
|
if (!image) {
|
|
23
|
-
|
|
13
|
+
// Items can be null (or a primitive) in stored content — only objects have values to scan.
|
|
14
|
+
const values = isArray(data) ? data : isObject(data) ? flattenObject(data) : [];
|
|
24
15
|
|
|
25
16
|
for (const value of values) {
|
|
26
17
|
const data: string[] = Object.values(value || {}) as string[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { VevProps } from '@vev/utils';
|
|
2
|
+
import { generateImage } from './generate-image';
|
|
3
|
+
import { generateTitle } from './generate-title';
|
|
4
|
+
|
|
5
|
+
const cardsSchema = (preview: any) =>
|
|
6
|
+
({
|
|
7
|
+
type: 'array',
|
|
8
|
+
name: 'cards',
|
|
9
|
+
of: 'object',
|
|
10
|
+
fields: [
|
|
11
|
+
{ type: 'image', name: 'image' },
|
|
12
|
+
{ type: 'string', name: 'title' },
|
|
13
|
+
],
|
|
14
|
+
preview,
|
|
15
|
+
}) as VevProps;
|
|
16
|
+
|
|
17
|
+
describe('array item preview', () => {
|
|
18
|
+
beforeEach(() => jest.spyOn(console, 'warn').mockImplementation(() => undefined));
|
|
19
|
+
afterEach(() => jest.restoreAllMocks());
|
|
20
|
+
|
|
21
|
+
it('uses the preview function when it succeeds', () => {
|
|
22
|
+
const schema = cardsSchema((item: any) => ({ title: item.title, image: item.image.url }));
|
|
23
|
+
const item = { title: 'Paris', image: { url: 'https://cdn/paris.jpg' } };
|
|
24
|
+
|
|
25
|
+
expect(generateTitle(item, schema)).toBe('Paris');
|
|
26
|
+
expect(generateImage(item as any, schema)).toBe('https://cdn/paris.jpg');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('falls back to the item values when the preview function throws', () => {
|
|
30
|
+
const schema = cardsSchema((item: any) => ({ title: item.title, image: item.image.url }));
|
|
31
|
+
const item = { title: 'Card without image' };
|
|
32
|
+
|
|
33
|
+
expect(generateTitle(item, schema)).toBe('Card without image');
|
|
34
|
+
expect(generateImage(item as any, schema)).toBeUndefined();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('falls back to the item values when the preview function returns nothing', () => {
|
|
38
|
+
const schema = cardsSchema(() => undefined);
|
|
39
|
+
const item = { title: 'Rome' };
|
|
40
|
+
|
|
41
|
+
expect(generateTitle(item, schema)).toBe('Rome');
|
|
42
|
+
expect(generateImage(item as any, schema)).toBeUndefined();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('handles null items without a preview', () => {
|
|
46
|
+
expect(generateTitle(null as any, 'object')).toBe('Unknown');
|
|
47
|
+
expect(generateImage(null as any, 'object')).toBeUndefined();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -1,20 +1,33 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
1
2
|
import { isObject, capitalize, isFunction } from 'lodash';
|
|
2
3
|
import { VevProps } from '@vev/utils';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Resolves the schema's `preview` for an array item. A `preview` function is component code
|
|
7
|
+
* (often AI-generated) that runs for every item as soon as the list renders, so a throw or a
|
|
8
|
+
* missing return value falls back to the derived title/image instead of crashing the form.
|
|
9
|
+
*/
|
|
10
|
+
export const getPreview = (
|
|
11
|
+
data: any,
|
|
6
12
|
schema?: VevProps | VevProps[] | string,
|
|
7
|
-
): string |
|
|
13
|
+
): { title?: string; image?: string | ReactNode } => {
|
|
8
14
|
if (Array.isArray(schema)) schema = schema.find((s) => s.preview) || schema[0];
|
|
9
|
-
|
|
15
|
+
if (!isObject(schema) || !schema.preview) return {};
|
|
16
|
+
if (!isFunction(schema.preview)) return schema.preview;
|
|
10
17
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
18
|
+
try {
|
|
19
|
+
return schema.preview(data) || {};
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.warn(`Failed to generate preview for "${schema.name}"`, e);
|
|
22
|
+
return {};
|
|
17
23
|
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const generateTitle = (
|
|
27
|
+
data: { [key: string]: any } | { [key: string]: any }[] | string,
|
|
28
|
+
schema?: VevProps | VevProps[] | string,
|
|
29
|
+
): string | undefined => {
|
|
30
|
+
let { title } = getPreview(data, schema);
|
|
18
31
|
|
|
19
32
|
if (!title) {
|
|
20
33
|
if (typeof data === 'string' || typeof data === 'number') return data.toString();
|