@tristan2828/ui-foundation 4.71.0 → 4.72.0
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/conventions/docs/add-an-entity.md +21 -15
- package/conventions/docs/cell-patterns.md +210 -37
- package/conventions/docs/design-language.md +52 -24
- package/dist/components/app/edit-in-place-controls.d.ts +34 -0
- package/dist/components/app/edit-in-place-controls.js +92 -0
- package/dist/components/app/edit-in-place-presets.d.ts +187 -0
- package/dist/components/app/edit-in-place-presets.js +409 -0
- package/dist/components/app/edit-in-place-store.d.ts +9 -0
- package/dist/components/app/edit-in-place-store.js +14 -7
- package/dist/components/app/edit-in-place.d.ts +101 -4
- package/dist/components/app/editable-list.js +158 -23
- package/dist/components/app/editable-value.d.ts +2 -2
- package/dist/components/app/editable-value.js +7 -3
- package/dist/components/app/entity-view.d.ts +6 -2
- package/dist/components/app/entity-view.js +11 -2
- package/dist/components/app/row-edit-cells.d.ts +9 -0
- package/dist/components/app/row-edit-cells.js +12 -16
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/lib/link-href.d.ts +28 -0
- package/dist/lib/link-href.js +40 -0
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { ExternalLinkIcon } from 'lucide-react';
|
|
3
3
|
import { Input } from '../ui/input.js';
|
|
4
4
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select.js';
|
|
5
|
-
import { linkHref,
|
|
5
|
+
import { linkHref, linkRule } from '../../lib/link-href.js';
|
|
6
6
|
import { editInPlace } from './edit-in-place.js';
|
|
7
7
|
import { EditableValue } from './editable-value.js';
|
|
8
8
|
/** A name in one line: Enter saves, the form's rule runs first, a taken name's 422 shows in the cell. */
|
|
@@ -32,20 +32,16 @@ export function ChoiceCell({ label, value, options, render, save, triggerClassNa
|
|
|
32
32
|
}
|
|
33
33
|
// A web or email address (`example.com` gains https://), blank for none.
|
|
34
34
|
// Another scheme (`javascript:`) or a space inside the address is refused
|
|
35
|
-
// before anything is sent.
|
|
36
|
-
const LINK_RULE =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
return { success: true, data: href };
|
|
47
|
-
},
|
|
48
|
-
};
|
|
35
|
+
// before anything is sent: `linkRule`, shared with `inPlace.link`.
|
|
36
|
+
const LINK_RULE = linkRule;
|
|
37
|
+
/**
|
|
38
|
+
* A link out of the app as LinkCell shows one at rest: the link tone,
|
|
39
|
+
* underlined, an external-link mark, opening in a new tab (said to a
|
|
40
|
+
* screen reader). `href` must be one `linkHref` returned.
|
|
41
|
+
*/
|
|
42
|
+
export function LinkOut({ href, children }) {
|
|
43
|
+
return (_jsxs("a", { href: href, target: "_blank", rel: "noopener noreferrer", className: "rounded-sm text-link underline underline-offset-4 outline-none focus-visible:ring-3 focus-visible:ring-ring/50", children: [children, _jsx(ExternalLinkIcon, { "aria-hidden": "true", className: "ml-0.5 inline size-3 align-baseline" }), _jsx("span", { className: "sr-only", children: " (opens in a new tab)" })] }));
|
|
44
|
+
}
|
|
49
45
|
function shownLinkText(href, linkText) {
|
|
50
46
|
if (typeof linkText === 'function')
|
|
51
47
|
return linkText(href);
|
|
@@ -62,5 +58,5 @@ export function LinkCell({ label, value, save, linkText, emptyLabel = 'Not set',
|
|
|
62
58
|
schema: LINK_RULE,
|
|
63
59
|
save,
|
|
64
60
|
control: (props) => (_jsx(Input, { id: props.id, type: "url", inputMode: "url", className: inputClassName, value: props.value, placeholder: "https://", readOnly: props.disabled, "aria-invalid": props.invalid || undefined, "aria-label": props.label, "aria-describedby": props.describedBy, onChange: (event) => props.onChange(event.target.value) })),
|
|
65
|
-
}), children: !value ? (_jsx("span", { className: "text-muted-foreground", children: emptyLabel })) : href ? (
|
|
61
|
+
}), children: !value ? (_jsx("span", { className: "text-muted-foreground", children: emptyLabel })) : href ? (_jsx(LinkOut, { href: href, children: shownLinkText(href, linkText) })) : (value) }));
|
|
66
62
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export { usePrinting } from './components/app/print-context.js';
|
|
|
19
19
|
export { RecordDialogRoute, RecordLink, type RecordDialogRouteProps, type RecordLinkProps, } from './components/app/record-dialog.js';
|
|
20
20
|
export { recordDialogState, useOpenRecord, useRecordDialog, type RecordDialogBackground, type RecordDialogContextValue, type RecordDialogState, } from './components/app/record-dialog-context.js';
|
|
21
21
|
export { editInPlace, type EditControlProps, type EditInPlace, type EditInPlaceList, type EditInPlaceListOptions, type EditInPlaceOptions, type EditKind, type EditListAddProps, type EditListItemProps, } from './components/app/edit-in-place.js';
|
|
22
|
+
export { inPlace, type InPlaceDateConfig, type InPlaceFieldsOptions, type InPlaceLinkConfig, type InPlaceLinkValue, type InPlaceMoneyConfig, type InPlaceNumberConfig, type InPlaceOption, type InPlacePart, type InPlaceRecord, type InPlaceReferenceConfig, type InPlaceSaved, type InPlaceSelectConfig, type InPlaceTextConfig, } from './components/app/edit-in-place-presets.js';
|
|
23
|
+
export { linkHost, linkHref, linkRule } from './lib/link-href.js';
|
|
22
24
|
export { DataEnvironmentBanner } from './components/app/data-environment-banner.js';
|
|
23
25
|
export { EditableValue, type EditableValueProps } from './components/app/editable-value.js';
|
|
24
26
|
export { ErrorState } from './components/app/error-state.js';
|
|
@@ -53,7 +55,7 @@ export { EmojiField, type EmojiFieldProps } from './components/app/emoji-field.j
|
|
|
53
55
|
export { ImageField, type ImageFieldProps } from './components/app/image-field.js';
|
|
54
56
|
export { DEFAULT_IMAGE_TYPES, type ImageUpload, type ImageUploadResult } from './lib/image-file.js';
|
|
55
57
|
export { formatPlainDate, type PlainDate } from './lib/plain-date.js';
|
|
56
|
-
export { ChoiceCell, LinkCell, NameCell, type ChoiceCellProps, type LinkCellProps, type NameCellProps, } from './components/app/row-edit-cells.js';
|
|
58
|
+
export { ChoiceCell, LinkCell, LinkOut, NameCell, type ChoiceCellProps, type LinkCellProps, type NameCellProps, } from './components/app/row-edit-cells.js';
|
|
57
59
|
export { ModuleCard, ModuleStrip, type CategorySlot, type ModuleCardLink, type ModuleCardPlace, type ModuleCardProps, type ModuleStripMobile, type ModuleStripProps, } from './components/app/module-card.js';
|
|
58
60
|
export { WidgetCard, WidgetCardGroup, WidgetList, WidgetListItem, type WidgetCardGroupProps, type WidgetCardLink, type WidgetCardProps, type WidgetListItemProps, } from './components/app/widget-card.js';
|
|
59
61
|
export { WidgetLayoutSheet, type WidgetLayoutSheetProps } from './components/app/widget-layout-sheet.js';
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,8 @@ export { usePrinting } from './components/app/print-context.js';
|
|
|
23
23
|
export { RecordDialogRoute, RecordLink, } from './components/app/record-dialog.js';
|
|
24
24
|
export { recordDialogState, useOpenRecord, useRecordDialog, } from './components/app/record-dialog-context.js';
|
|
25
25
|
export { editInPlace, } from './components/app/edit-in-place.js';
|
|
26
|
+
export { inPlace, } from './components/app/edit-in-place-presets.js';
|
|
27
|
+
export { linkHost, linkHref, linkRule } from './lib/link-href.js';
|
|
26
28
|
export { DataEnvironmentBanner } from './components/app/data-environment-banner.js';
|
|
27
29
|
export { EditableValue } from './components/app/editable-value.js';
|
|
28
30
|
export { ErrorState } from './components/app/error-state.js';
|
|
@@ -56,7 +58,7 @@ export { EmojiField } from './components/app/emoji-field.js';
|
|
|
56
58
|
export { ImageField } from './components/app/image-field.js';
|
|
57
59
|
export { DEFAULT_IMAGE_TYPES } from './lib/image-file.js';
|
|
58
60
|
export { formatPlainDate } from './lib/plain-date.js';
|
|
59
|
-
export { ChoiceCell, LinkCell, NameCell, } from './components/app/row-edit-cells.js';
|
|
61
|
+
export { ChoiceCell, LinkCell, LinkOut, NameCell, } from './components/app/row-edit-cells.js';
|
|
60
62
|
export { ModuleCard, ModuleStrip, } from './components/app/module-card.js';
|
|
61
63
|
export { WidgetCard, WidgetCardGroup, WidgetList, WidgetListItem, } from './components/app/widget-card.js';
|
|
62
64
|
export { WidgetLayoutSheet } from './components/app/widget-layout-sheet.js';
|
package/dist/lib/link-href.d.ts
CHANGED
|
@@ -2,3 +2,31 @@
|
|
|
2
2
|
export declare function linkHref(typed: string): string | null;
|
|
3
3
|
/** Why `linkHref` refused what was typed, for the message shown with it. */
|
|
4
4
|
export declare function linkRefusal(typed: string): 'whitespace' | 'scheme';
|
|
5
|
+
type LinkRuleResult = {
|
|
6
|
+
success: true;
|
|
7
|
+
data: string | null;
|
|
8
|
+
} | {
|
|
9
|
+
success: false;
|
|
10
|
+
error: {
|
|
11
|
+
issues: {
|
|
12
|
+
message: string;
|
|
13
|
+
}[];
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The rule for a link field, shaped as a schema (`safeParse`): what was
|
|
18
|
+
* typed becomes the address to save (`linkHref`: `example.com` gains
|
|
19
|
+
* https://), or `null` for a blank box; another scheme (`javascript:`) or
|
|
20
|
+
* a space inside the address is refused with the words to show. LinkCell
|
|
21
|
+
* and the `inPlace.link` preset check with it.
|
|
22
|
+
*/
|
|
23
|
+
export declare const linkRule: {
|
|
24
|
+
safeParse(value: unknown): LinkRuleResult;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A link's text when it has no label of its own: the host of a web
|
|
28
|
+
* address (`docs.example.com`), the address of an email link, the path
|
|
29
|
+
* of a link on this site. `href` is one `linkHref` returned.
|
|
30
|
+
*/
|
|
31
|
+
export declare function linkHost(href: string): string;
|
|
32
|
+
export {};
|
package/dist/lib/link-href.js
CHANGED
|
@@ -32,3 +32,43 @@ export function linkHref(typed) {
|
|
|
32
32
|
export function linkRefusal(typed) {
|
|
33
33
|
return /\s/.test(typed.trim()) ? 'whitespace' : 'scheme';
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* The rule for a link field, shaped as a schema (`safeParse`): what was
|
|
37
|
+
* typed becomes the address to save (`linkHref`: `example.com` gains
|
|
38
|
+
* https://), or `null` for a blank box; another scheme (`javascript:`) or
|
|
39
|
+
* a space inside the address is refused with the words to show. LinkCell
|
|
40
|
+
* and the `inPlace.link` preset check with it.
|
|
41
|
+
*/
|
|
42
|
+
export const linkRule = {
|
|
43
|
+
safeParse(value) {
|
|
44
|
+
const typed = String(value ?? '');
|
|
45
|
+
const href = linkHref(typed);
|
|
46
|
+
if (href === '')
|
|
47
|
+
return { success: true, data: null };
|
|
48
|
+
if (href === null) {
|
|
49
|
+
const message = linkRefusal(typed) === 'whitespace' ? 'An address has no spaces' : 'Use a web or email address';
|
|
50
|
+
return { success: false, error: { issues: [{ message }] } };
|
|
51
|
+
}
|
|
52
|
+
return { success: true, data: href };
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* A link's text when it has no label of its own: the host of a web
|
|
57
|
+
* address (`docs.example.com`), the address of an email link, the path
|
|
58
|
+
* of a link on this site. `href` is one `linkHref` returned.
|
|
59
|
+
*/
|
|
60
|
+
export function linkHost(href) {
|
|
61
|
+
if (/^mailto:/i.test(href))
|
|
62
|
+
return href.slice('mailto:'.length);
|
|
63
|
+
if (/^tel:/i.test(href))
|
|
64
|
+
return href.slice('tel:'.length);
|
|
65
|
+
if (/^https?:\/\//i.test(href)) {
|
|
66
|
+
try {
|
|
67
|
+
return new URL(href).host;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return href.replace(/^https?:\/\//i, '');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return href;
|
|
74
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.72.0",
|
|
4
4
|
"description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|