@bettercms-ai/kit 4.0.0 → 4.2.0-next.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/dist/adapters/lossy.d.ts +4 -0
- package/dist/adapters/lossy.js +4 -0
- package/dist/adapters/lossy.js.map +1 -1
- package/dist/adapters/prod-types.d.ts +4 -0
- package/dist/adapters/prod-types.js +4 -1
- package/dist/adapters/prod-types.js.map +1 -1
- package/dist/adapters/schema.js +7 -0
- package/dist/adapters/schema.js.map +1 -1
- package/dist/context.d.ts +91 -0
- package/dist/context.js +58 -1
- package/dist/context.js.map +1 -1
- package/dist/controls/choice.d.ts +1 -1
- package/dist/controls/choice.js +21 -2
- package/dist/controls/choice.js.map +1 -1
- package/dist/controls/index.d.ts +1 -0
- package/dist/controls/index.js +3 -2
- package/dist/controls/index.js.map +1 -1
- package/dist/controls/link.d.ts +23 -2
- package/dist/controls/link.js +456 -4
- package/dist/controls/link.js.map +1 -1
- package/dist/controls/media-v16.d.ts +27 -0
- package/dist/controls/media-v16.js +261 -0
- package/dist/controls/media-v16.js.map +1 -0
- package/dist/controls/media.js +63 -1
- package/dist/controls/media.js.map +1 -1
- package/dist/controls/reference-services.d.ts +8 -0
- package/dist/controls/reference.js +78 -2
- package/dist/controls/reference.js.map +1 -1
- package/dist/controls/rich-text/ai-runs.d.ts +13 -0
- package/dist/controls/rich-text/ai-runs.js +71 -0
- package/dist/controls/rich-text/ai-runs.js.map +1 -0
- package/dist/controls/rich-text/block-tool.d.ts +31 -0
- package/dist/controls/rich-text/block-tool.js +62 -0
- package/dist/controls/rich-text/block-tool.js.map +1 -0
- package/dist/controls/rich-text/blocks.d.ts +6 -1
- package/dist/controls/rich-text/blocks.js +406 -24
- package/dist/controls/rich-text/blocks.js.map +1 -1
- package/dist/controls/rich-text/catalog.d.ts +45 -7
- package/dist/controls/rich-text/catalog.js +507 -37
- package/dist/controls/rich-text/catalog.js.map +1 -1
- package/dist/controls/rich-text/code-head.d.ts +30 -0
- package/dist/controls/rich-text/code-head.js +230 -0
- package/dist/controls/rich-text/code-head.js.map +1 -0
- package/dist/controls/rich-text/codec.d.ts +1 -1
- package/dist/controls/rich-text/codec.js +4 -1
- package/dist/controls/rich-text/codec.js.map +1 -1
- package/dist/controls/rich-text/dom.d.ts +27 -0
- package/dist/controls/rich-text/dom.js +77 -7
- package/dist/controls/rich-text/dom.js.map +1 -1
- package/dist/controls/rich-text/editor.js +243 -55
- package/dist/controls/rich-text/editor.js.map +1 -1
- package/dist/controls/rich-text/ops.js +1 -0
- package/dist/controls/rich-text/ops.js.map +1 -1
- package/dist/controls/rich-text/rewriteSelection.d.ts +25 -0
- package/dist/controls/rich-text/rewriteSelection.js +28 -0
- package/dist/controls/rich-text/rewriteSelection.js.map +1 -0
- package/dist/controls/rich-text/slash-preview.d.ts +8 -0
- package/dist/controls/rich-text/slash-preview.js +300 -0
- package/dist/controls/rich-text/slash-preview.js.map +1 -0
- package/dist/controls/rich-text/table-grid.d.ts +22 -0
- package/dist/controls/rich-text/table-grid.js +1057 -0
- package/dist/controls/rich-text/table-grid.js.map +1 -0
- package/dist/controls/rich-text/toolbar.js +61 -18
- package/dist/controls/rich-text/toolbar.js.map +1 -1
- package/dist/controls/text.d.ts +6 -0
- package/dist/controls/text.js +95 -5
- package/dist/controls/text.js.map +1 -1
- package/dist/core/facets.d.ts +1 -0
- package/dist/core/facets.js +1 -0
- package/dist/core/facets.js.map +1 -1
- package/dist/engine/array.d.ts +7 -0
- package/dist/engine/array.js +164 -45
- package/dist/engine/array.js.map +1 -1
- package/dist/engine/field-shell.d.ts +12 -0
- package/dist/engine/field-shell.js +222 -64
- package/dist/engine/field-shell.js.map +1 -1
- package/dist/engine/frame.js +42 -4
- package/dist/engine/frame.js.map +1 -1
- package/dist/engine/grouping.d.ts +71 -10
- package/dist/engine/grouping.js +227 -29
- package/dist/engine/grouping.js.map +1 -1
- package/dist/engine/item-list.js +2 -2
- package/dist/engine/item-list.js.map +1 -1
- package/dist/engine/kit-field.js +38 -4
- package/dist/engine/kit-field.js.map +1 -1
- package/dist/engine/schema-form.d.ts +2 -0
- package/dist/engine/schema-form.js +9 -2
- package/dist/engine/schema-form.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/dist/kit.css +59 -0
- package/dist/lib/reduced-motion.d.ts +1 -0
- package/dist/lib/reduced-motion.js +19 -0
- package/dist/lib/reduced-motion.js.map +1 -0
- package/dist/schema/table.d.ts +2 -1
- package/dist/schema/table.js +5 -0
- package/dist/schema/table.js.map +1 -1
- package/dist/schema/types.d.ts +6 -0
- package/dist/schema/types.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/theme.css +215 -0
- package/dist/tokens.css +274 -0
- package/dist/ui/block-icon-picker.d.ts +38 -0
- package/dist/ui/block-icon-picker.js +141 -0
- package/dist/ui/block-icon-picker.js.map +1 -0
- package/dist/ui/button.js +1 -0
- package/dist/ui/button.js.map +1 -1
- package/dist/ui/code-language-menu.d.ts +24 -0
- package/dist/ui/code-language-menu.js +123 -0
- package/dist/ui/code-language-menu.js.map +1 -0
- package/dist/ui/content-fields.d.ts +47 -0
- package/dist/ui/content-fields.js +279 -0
- package/dist/ui/content-fields.js.map +1 -0
- package/dist/ui/controls.js +3 -2
- package/dist/ui/controls.js.map +1 -1
- package/dist/ui/floating-panel.js +3 -2
- package/dist/ui/floating-panel.js.map +1 -1
- package/dist/ui/foundations.d.ts +118 -0
- package/dist/ui/foundations.js +565 -0
- package/dist/ui/foundations.js.map +1 -0
- package/dist/ui/index.d.ts +6 -0
- package/dist/ui/index.js +7 -1
- package/dist/ui/inspector.d.ts +412 -0
- package/dist/ui/inspector.js +1218 -0
- package/dist/ui/inspector.js.map +1 -0
- package/dist/ui/overlay.d.ts +7 -2
- package/dist/ui/overlay.js +55 -20
- package/dist/ui/overlay.js.map +1 -1
- package/dist/ui/shortcut-hint.js +1 -1
- package/dist/ui/shortcut-hint.js.map +1 -1
- package/dist/ui/tab.js +3 -2
- package/dist/ui/tab.js.map +1 -1
- package/dist/ui/toast.d.ts +5 -3
- package/dist/ui/toast.js +83 -11
- package/dist/ui/toast.js.map +1 -1
- package/dist/ui/tooltip-card.d.ts +45 -0
- package/dist/ui/tooltip-card.js +135 -0
- package/dist/ui/tooltip-card.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { cn } from "../lib/cn.js";
|
|
2
|
+
import { useKitServices } from "../context.js";
|
|
3
|
+
import { Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger, Tooltip } from "../ui/overlay.js";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { IconDots, IconLink, IconScan, IconTrash, IconUpload } from "@tabler/icons-react";
|
|
7
|
+
//#region src/controls/media-v16.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Look "v16": the image control as prototype editor-v16 `MediaField` (inspector.jsx:1080-1136, media.css; REQ-5-6
|
|
10
|
+
* group C, F1369-F1385). The image control (media.tsx ImageControl) draws this inside `KitLookProvider look="v16"`:
|
|
11
|
+
* no image → a 164 high dashed zone ("Drag and drop to upload or select", "PNG, JPG or WEBP · up to 10 MB"),
|
|
12
|
+
* drag-over "Drop to upload", a type / size refusal for 2.6s, the upload's progress round the zone with
|
|
13
|
+
* a % pill, then "Uploaded successfully!" for 0.8s;
|
|
14
|
+
* an image → a card (168 thumb, name, "W × H · size", Replace, ⋯ Replace image / Crop and focal point / Copy image
|
|
15
|
+
* URL / Remove from section);
|
|
16
|
+
* then the "Alternative text" field (where the placement stores alt text).
|
|
17
|
+
* Every action is the real one: the upload goes through `KitServices.uploadMedia`, the crop through the control's own
|
|
18
|
+
* details popover. A service the host does not provide is not offered, in words.
|
|
19
|
+
*/
|
|
20
|
+
var V16_IMAGE_ACCEPT = "image/png,image/jpeg,image/webp";
|
|
21
|
+
var OK_TYPE = /^image\/(png|jpe?g|webp)$/;
|
|
22
|
+
var MAX_BYTES = 10485760;
|
|
23
|
+
var BTN = "grid size-7 shrink-0 place-items-center rounded-[6px] text-kit-insp-label outline-none transition-colors hover:bg-kit-insp-card hover:text-kit-insp-tip-title data-[popup-open]:bg-kit-insp-card data-[popup-open]:text-kit-insp-tip-title focus-visible:shadow-[0_0_0_2px_var(--kit-insp-accent)] [&_svg]:size-3.5";
|
|
24
|
+
function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop, onRemove, onLibrary }) {
|
|
25
|
+
const { toast } = useKitServices();
|
|
26
|
+
const file = React.useRef(null);
|
|
27
|
+
const [over, setOver] = React.useState(false);
|
|
28
|
+
const [refusal, setRefusal] = React.useState(null);
|
|
29
|
+
const [done, setDone] = React.useState(false);
|
|
30
|
+
const busy = upload.progress != null;
|
|
31
|
+
const wasBusy = React.useRef(false);
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
if (wasBusy.current && !busy && !upload.error) {
|
|
34
|
+
setDone(true);
|
|
35
|
+
const t = window.setTimeout(() => setDone(false), 800);
|
|
36
|
+
wasBusy.current = busy;
|
|
37
|
+
return () => window.clearTimeout(t);
|
|
38
|
+
}
|
|
39
|
+
wasBusy.current = busy;
|
|
40
|
+
}, [busy, upload.error]);
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
if (!refusal) return;
|
|
43
|
+
const t = window.setTimeout(() => setRefusal(null), 2600);
|
|
44
|
+
return () => window.clearTimeout(t);
|
|
45
|
+
}, [refusal]);
|
|
46
|
+
const take = (f) => {
|
|
47
|
+
if (!f || !upload.run || busy) return;
|
|
48
|
+
if (!OK_TYPE.test(f.type)) return setRefusal("Only PNG, JPG or WEBP files are supported");
|
|
49
|
+
if (f.size > MAX_BYTES) return setRefusal("That image is over 10 MB");
|
|
50
|
+
setRefusal(null);
|
|
51
|
+
upload.run([f]);
|
|
52
|
+
};
|
|
53
|
+
const pick = () => upload.run ? file.current?.click() : onLibrary?.();
|
|
54
|
+
const input = /* @__PURE__ */ jsx("input", {
|
|
55
|
+
ref: file,
|
|
56
|
+
type: "file",
|
|
57
|
+
hidden: true,
|
|
58
|
+
accept: V16_IMAGE_ACCEPT,
|
|
59
|
+
onChange: (e) => {
|
|
60
|
+
take(e.target.files?.[0]);
|
|
61
|
+
e.target.value = "";
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const showCard = image && !done && !busy;
|
|
65
|
+
const pct = upload.progress ?? 0;
|
|
66
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
67
|
+
className: "flex flex-col gap-4",
|
|
68
|
+
children: [
|
|
69
|
+
showCard ? /* @__PURE__ */ jsxs("div", {
|
|
70
|
+
className: "flex flex-col gap-2 rounded-[10px] border border-kit-insp-line bg-kit-insp-tip-bg p-2",
|
|
71
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
72
|
+
className: "h-[168px] w-full overflow-hidden rounded-[6px] bg-kit-insp-card",
|
|
73
|
+
children: /* @__PURE__ */ jsx("img", {
|
|
74
|
+
src: image.src,
|
|
75
|
+
alt: alt ?? "",
|
|
76
|
+
className: "size-full object-cover"
|
|
77
|
+
})
|
|
78
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
79
|
+
className: "flex items-center gap-1",
|
|
80
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
81
|
+
className: "flex min-w-0 flex-1 flex-col gap-0.5",
|
|
82
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
83
|
+
className: "truncate text-[13px] font-medium leading-4 text-kit-insp-tip-title",
|
|
84
|
+
children: image.name || "image"
|
|
85
|
+
}), image.meta ? /* @__PURE__ */ jsx("span", {
|
|
86
|
+
className: "truncate text-[12px] leading-[15px] text-kit-fg-3 tabular-nums",
|
|
87
|
+
children: image.meta
|
|
88
|
+
}) : null]
|
|
89
|
+
}), readOnly ? null : /* @__PURE__ */ jsxs(Fragment, { children: [upload.run || onLibrary ? /* @__PURE__ */ jsx(Tooltip, {
|
|
90
|
+
content: "Replace image",
|
|
91
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
92
|
+
type: "button",
|
|
93
|
+
"aria-label": "Replace image",
|
|
94
|
+
className: BTN,
|
|
95
|
+
onClick: pick,
|
|
96
|
+
children: /* @__PURE__ */ jsx(IconUpload, {
|
|
97
|
+
stroke: 1.2,
|
|
98
|
+
"aria-hidden": true
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
}) : null, /* @__PURE__ */ jsxs(Menu, { children: [/* @__PURE__ */ jsx(MenuTrigger, {
|
|
102
|
+
"aria-label": "Image actions",
|
|
103
|
+
className: BTN,
|
|
104
|
+
children: /* @__PURE__ */ jsx(IconDots, {
|
|
105
|
+
stroke: 1.5,
|
|
106
|
+
"aria-hidden": true
|
|
107
|
+
})
|
|
108
|
+
}), /* @__PURE__ */ jsxs(MenuContent, {
|
|
109
|
+
align: "end",
|
|
110
|
+
className: "w-[240px] min-w-[240px]",
|
|
111
|
+
children: [
|
|
112
|
+
upload.run || onLibrary ? /* @__PURE__ */ jsx(MenuItem, {
|
|
113
|
+
icon: /* @__PURE__ */ jsx(IconUpload, { stroke: 1.5 }),
|
|
114
|
+
onClick: pick,
|
|
115
|
+
children: "Replace image"
|
|
116
|
+
}) : null,
|
|
117
|
+
onCrop ? /* @__PURE__ */ jsx(MenuItem, {
|
|
118
|
+
icon: /* @__PURE__ */ jsx(IconScan, { stroke: 1.5 }),
|
|
119
|
+
onClick: onCrop,
|
|
120
|
+
children: "Crop and focal point"
|
|
121
|
+
}) : null,
|
|
122
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
123
|
+
icon: /* @__PURE__ */ jsx(IconLink, { stroke: 1.5 }),
|
|
124
|
+
onClick: () => {
|
|
125
|
+
const w = navigator.clipboard?.writeText(image.url);
|
|
126
|
+
if (!w) return toast?.("Copy is not available in this browser");
|
|
127
|
+
w.then(() => toast?.("Image URL copied"), () => toast?.("The browser refused to copy the address"));
|
|
128
|
+
},
|
|
129
|
+
children: "Copy image URL"
|
|
130
|
+
}),
|
|
131
|
+
/* @__PURE__ */ jsx(MenuSeparator, {}),
|
|
132
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
133
|
+
danger: true,
|
|
134
|
+
icon: /* @__PURE__ */ jsx(IconTrash, { stroke: 1.5 }),
|
|
135
|
+
onClick: onRemove,
|
|
136
|
+
children: "Remove from section"
|
|
137
|
+
})
|
|
138
|
+
]
|
|
139
|
+
})] })] })]
|
|
140
|
+
})]
|
|
141
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
142
|
+
id,
|
|
143
|
+
role: "button",
|
|
144
|
+
tabIndex: readOnly ? -1 : 0,
|
|
145
|
+
"aria-busy": busy || void 0,
|
|
146
|
+
"aria-disabled": readOnly || !upload.run && !onLibrary || void 0,
|
|
147
|
+
"aria-label": `${label}: drag and drop to upload or select`,
|
|
148
|
+
onKeyDown: (e) => {
|
|
149
|
+
if (e.target !== e.currentTarget || busy || readOnly) return;
|
|
150
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
151
|
+
e.preventDefault();
|
|
152
|
+
pick();
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
onDragOver: (e) => {
|
|
156
|
+
if (readOnly || busy || !upload.run || !e.dataTransfer.types.includes("Files")) return;
|
|
157
|
+
e.preventDefault();
|
|
158
|
+
setOver(true);
|
|
159
|
+
},
|
|
160
|
+
onDragLeave: () => setOver(false),
|
|
161
|
+
onDrop: (e) => {
|
|
162
|
+
if (readOnly || !upload.run) return;
|
|
163
|
+
e.preventDefault();
|
|
164
|
+
setOver(false);
|
|
165
|
+
take(e.dataTransfer.files[0]);
|
|
166
|
+
},
|
|
167
|
+
className: cn("relative flex h-[164px] w-full flex-col items-center justify-center rounded-[16px] border-2 border-dashed border-kit-insp-line-strong bg-kit-insp-card text-center outline-none transition-[background-color,border-color] duration-150 ease-out focus-visible:border-kit-insp-accent", over && "border-kit-insp-accent bg-kit-insp-zone-over", refusal && "border-kit-insp-error", busy && "border-transparent bg-kit-insp-tip-bg"),
|
|
168
|
+
children: [
|
|
169
|
+
busy ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("svg", {
|
|
170
|
+
"aria-hidden": true,
|
|
171
|
+
className: "pointer-events-none absolute -inset-0.5 h-[calc(100%+4px)] w-[calc(100%+4px)] overflow-visible",
|
|
172
|
+
children: [/* @__PURE__ */ jsx("rect", {
|
|
173
|
+
x: "1",
|
|
174
|
+
y: "1",
|
|
175
|
+
rx: "16",
|
|
176
|
+
style: {
|
|
177
|
+
width: "calc(100% - 2px)",
|
|
178
|
+
height: "calc(100% - 2px)"
|
|
179
|
+
},
|
|
180
|
+
fill: "none",
|
|
181
|
+
stroke: "var(--kit-insp-line)",
|
|
182
|
+
strokeWidth: "1.5"
|
|
183
|
+
}), /* @__PURE__ */ jsx("rect", {
|
|
184
|
+
x: "1",
|
|
185
|
+
y: "1",
|
|
186
|
+
rx: "16",
|
|
187
|
+
style: {
|
|
188
|
+
width: "calc(100% - 2px)",
|
|
189
|
+
height: "calc(100% - 2px)"
|
|
190
|
+
},
|
|
191
|
+
fill: "none",
|
|
192
|
+
stroke: "var(--kit-insp-accent)",
|
|
193
|
+
strokeWidth: "1.5",
|
|
194
|
+
pathLength: 100,
|
|
195
|
+
strokeDasharray: `${pct} 100`,
|
|
196
|
+
className: "transition-[stroke-dasharray] duration-[60ms] ease-linear"
|
|
197
|
+
})]
|
|
198
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
199
|
+
className: "absolute -top-[11px] left-1/2 h-[18px] min-w-[38px] -translate-x-1/2 rounded-full bg-kit-insp-accent px-1.5 text-[11px] font-semibold leading-[18px] text-white tabular-nums",
|
|
200
|
+
children: [pct, "%"]
|
|
201
|
+
})] }) : null,
|
|
202
|
+
/* @__PURE__ */ jsx("span", {
|
|
203
|
+
className: cn("mb-3.5 grid size-10 place-items-center rounded-full bg-kit-insp-zone-over text-kit-insp-accent-fg", busy && "border border-kit-insp-line bg-kit-insp-tip-bg"),
|
|
204
|
+
children: /* @__PURE__ */ jsx(IconUpload, {
|
|
205
|
+
className: "size-5",
|
|
206
|
+
stroke: 1.5,
|
|
207
|
+
"aria-hidden": true
|
|
208
|
+
})
|
|
209
|
+
}),
|
|
210
|
+
/* @__PURE__ */ jsx("span", {
|
|
211
|
+
className: cn("text-[13px] font-medium leading-4 text-kit-insp-tip-body", refusal && "text-kit-insp-count-over"),
|
|
212
|
+
children: refusal ?? (over ? "Drop to upload" : busy ? "Uploading…" : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
213
|
+
"Drag and drop to upload or",
|
|
214
|
+
" ",
|
|
215
|
+
/* @__PURE__ */ jsx("button", {
|
|
216
|
+
type: "button",
|
|
217
|
+
tabIndex: -1,
|
|
218
|
+
disabled: readOnly || !upload.run && !onLibrary,
|
|
219
|
+
onClick: (e) => {
|
|
220
|
+
e.stopPropagation();
|
|
221
|
+
pick();
|
|
222
|
+
},
|
|
223
|
+
className: "font-medium text-kit-insp-zone-link hover:underline disabled:no-underline",
|
|
224
|
+
children: "select"
|
|
225
|
+
})
|
|
226
|
+
] }))
|
|
227
|
+
}),
|
|
228
|
+
/* @__PURE__ */ jsx("span", {
|
|
229
|
+
className: cn("mt-1.5 text-[12px] leading-[15px] text-kit-fg-3", done && "text-kit-insp-zone-done"),
|
|
230
|
+
children: done ? "Uploaded successfully!" : upload.run ? "PNG, JPG or WEBP · up to 10 MB" : onLibrary ? "Pick one from the media library" : "Uploading is not available here"
|
|
231
|
+
})
|
|
232
|
+
]
|
|
233
|
+
}),
|
|
234
|
+
upload.error ? /* @__PURE__ */ jsx("p", {
|
|
235
|
+
role: "alert",
|
|
236
|
+
className: "-mt-2 text-[12px] leading-4 text-kit-insp-error",
|
|
237
|
+
children: upload.error
|
|
238
|
+
}) : null,
|
|
239
|
+
input,
|
|
240
|
+
alt !== void 0 && onAlt ? /* @__PURE__ */ jsxs("div", {
|
|
241
|
+
className: "flex flex-col gap-2",
|
|
242
|
+
children: [/* @__PURE__ */ jsx("label", {
|
|
243
|
+
htmlFor: `${id}-alt`,
|
|
244
|
+
className: "text-[13px] font-medium leading-4 text-kit-insp-tip-body",
|
|
245
|
+
children: "Alternative text"
|
|
246
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
247
|
+
id: `${id}-alt`,
|
|
248
|
+
value: alt,
|
|
249
|
+
readOnly,
|
|
250
|
+
placeholder: "Describe the image for screen readers",
|
|
251
|
+
onChange: (e) => onAlt(e.target.value),
|
|
252
|
+
className: "h-[34px] w-full rounded-[6px] border border-transparent bg-kit-insp-card px-2.5 text-[13px] leading-[18px] tracking-[-0.1625px] text-kit-insp-tip-title outline-none transition-[background-color,border-color] duration-[120ms] ease-out placeholder:text-kit-fg-3 focus:border-kit-insp-accent focus:bg-kit-insp-card-focus"
|
|
253
|
+
})]
|
|
254
|
+
}) : null
|
|
255
|
+
]
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
//#endregion
|
|
259
|
+
export { V16ImageField, V16_IMAGE_ACCEPT };
|
|
260
|
+
|
|
261
|
+
//# sourceMappingURL=media-v16.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media-v16.js","names":[],"sources":["../../src/controls/media-v16.tsx"],"sourcesContent":["/**\n * Look \"v16\": the image control as prototype editor-v16 `MediaField` (inspector.jsx:1080-1136, media.css; REQ-5-6\n * group C, F1369-F1385). The image control (media.tsx ImageControl) draws this inside `KitLookProvider look=\"v16\"`:\n * no image → a 164 high dashed zone (\"Drag and drop to upload or select\", \"PNG, JPG or WEBP · up to 10 MB\"),\n * drag-over \"Drop to upload\", a type / size refusal for 2.6s, the upload's progress round the zone with\n * a % pill, then \"Uploaded successfully!\" for 0.8s;\n * an image → a card (168 thumb, name, \"W × H · size\", Replace, ⋯ Replace image / Crop and focal point / Copy image\n * URL / Remove from section);\n * then the \"Alternative text\" field (where the placement stores alt text).\n * Every action is the real one: the upload goes through `KitServices.uploadMedia`, the crop through the control's own\n * details popover. A service the host does not provide is not offered, in words.\n */\nimport * as React from \"react\";\nimport { IconDots, IconLink, IconScan, IconTrash, IconUpload } from \"@tabler/icons-react\";\nimport { cn } from \"../lib/cn\";\nimport { useKitServices } from \"../context\";\nimport { Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger, Tooltip } from \"../ui/overlay\";\n\nexport const V16_IMAGE_ACCEPT = \"image/png,image/jpeg,image/webp\";\nconst OK_TYPE = /^image\\/(png|jpe?g|webp)$/;\nconst MAX_BYTES = 10 * 1024 * 1024;\n\nexport interface V16ImageFieldProps {\n id: string;\n label: string;\n readOnly?: boolean;\n /** the image, or none */\n image: { src: string; url: string; name: string; meta?: string } | null;\n /** media.tsx useUpload: `run` absent = no upload service */\n upload: { run?: (files: File[]) => void; progress: number | null; error: string | null };\n /** the stored alt text; undefined = this placement keeps no alt text (no field is drawn) */\n alt?: string;\n onAlt?: (alt: string) => void;\n onCrop?: () => void;\n onRemove: () => void;\n /** the media library, where the host has one (offered beside the upload when there is no upload service) */\n onLibrary?: () => void;\n}\n\nconst BTN =\n \"grid size-7 shrink-0 place-items-center rounded-[6px] text-kit-insp-label outline-none transition-colors hover:bg-kit-insp-card hover:text-kit-insp-tip-title data-[popup-open]:bg-kit-insp-card data-[popup-open]:text-kit-insp-tip-title focus-visible:shadow-[0_0_0_2px_var(--kit-insp-accent)] [&_svg]:size-3.5\";\n\nexport function V16ImageField({ id, label, readOnly, image, upload, alt, onAlt, onCrop, onRemove, onLibrary }: V16ImageFieldProps) {\n const { toast } = useKitServices();\n const file = React.useRef<HTMLInputElement>(null);\n const [over, setOver] = React.useState(false);\n const [refusal, setRefusal] = React.useState<string | null>(null);\n const [done, setDone] = React.useState(false);\n const busy = upload.progress != null;\n const wasBusy = React.useRef(false);\n React.useEffect(() => {\n // F1377: the finished upload says so for 800ms before the card replaces the zone\n if (wasBusy.current && !busy && !upload.error) {\n setDone(true);\n const t = window.setTimeout(() => setDone(false), 800);\n wasBusy.current = busy;\n return () => window.clearTimeout(t);\n }\n wasBusy.current = busy;\n }, [busy, upload.error]);\n React.useEffect(() => {\n if (!refusal) return;\n const t = window.setTimeout(() => setRefusal(null), 2600);\n return () => window.clearTimeout(t);\n }, [refusal]);\n\n const take = (f: File | undefined) => {\n if (!f || !upload.run || busy) return;\n if (!OK_TYPE.test(f.type)) return setRefusal(\"Only PNG, JPG or WEBP files are supported\");\n if (f.size > MAX_BYTES) return setRefusal(\"That image is over 10 MB\");\n setRefusal(null);\n upload.run([f]);\n };\n const pick = () => (upload.run ? file.current?.click() : onLibrary?.());\n const input = (\n <input\n ref={file}\n type=\"file\"\n hidden\n accept={V16_IMAGE_ACCEPT}\n onChange={(e) => {\n take(e.target.files?.[0]);\n e.target.value = \"\";\n }}\n />\n );\n\n const showCard = image && !done && !busy;\n const pct = upload.progress ?? 0;\n return (\n <div className=\"flex flex-col gap-4\">\n {showCard ? (\n <div className=\"flex flex-col gap-2 rounded-[10px] border border-kit-insp-line bg-kit-insp-tip-bg p-2\">\n <div className=\"h-[168px] w-full overflow-hidden rounded-[6px] bg-kit-insp-card\">\n <img src={image.src} alt={alt ?? \"\"} className=\"size-full object-cover\" />\n </div>\n <div className=\"flex items-center gap-1\">\n <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n <span className=\"truncate text-[13px] font-medium leading-4 text-kit-insp-tip-title\">{image.name || \"image\"}</span>\n {image.meta ? <span className=\"truncate text-[12px] leading-[15px] text-kit-fg-3 tabular-nums\">{image.meta}</span> : null}\n </div>\n {readOnly ? null : (\n <>\n {upload.run || onLibrary ? (\n <Tooltip content=\"Replace image\">\n <button type=\"button\" aria-label=\"Replace image\" className={BTN} onClick={pick}>\n <IconUpload stroke={1.2} aria-hidden />\n </button>\n </Tooltip>\n ) : null}\n <Menu>\n <MenuTrigger aria-label=\"Image actions\" className={BTN}>\n <IconDots stroke={1.5} aria-hidden />\n </MenuTrigger>\n <MenuContent align=\"end\" className=\"w-[240px] min-w-[240px]\">\n {upload.run || onLibrary ? (\n <MenuItem icon={<IconUpload stroke={1.5} />} onClick={pick}>\n Replace image\n </MenuItem>\n ) : null}\n {onCrop ? (\n <MenuItem icon={<IconScan stroke={1.5} />} onClick={onCrop}>\n Crop and focal point\n </MenuItem>\n ) : null}\n <MenuItem\n icon={<IconLink stroke={1.5} />}\n onClick={() => {\n const w = navigator.clipboard?.writeText(image.url);\n if (!w) return toast?.(\"Copy is not available in this browser\");\n w.then(() => toast?.(\"Image URL copied\"), () => toast?.(\"The browser refused to copy the address\"));\n }}\n >\n Copy image URL\n </MenuItem>\n <MenuSeparator />\n <MenuItem danger icon={<IconTrash stroke={1.5} />} onClick={onRemove}>\n Remove from section\n </MenuItem>\n </MenuContent>\n </Menu>\n </>\n )}\n </div>\n </div>\n ) : (\n <div\n id={id}\n role=\"button\"\n tabIndex={readOnly ? -1 : 0}\n aria-busy={busy || undefined}\n aria-disabled={readOnly || (!upload.run && !onLibrary) || undefined}\n aria-label={`${label}: drag and drop to upload or select`}\n onKeyDown={(e) => {\n if (e.target !== e.currentTarget || busy || readOnly) return;\n if (e.key === \"Enter\" || e.key === \" \") {\n e.preventDefault();\n pick();\n }\n }}\n onDragOver={(e) => {\n if (readOnly || busy || !upload.run || !e.dataTransfer.types.includes(\"Files\")) return;\n e.preventDefault();\n setOver(true);\n }}\n onDragLeave={() => setOver(false)}\n onDrop={(e) => {\n if (readOnly || !upload.run) return;\n e.preventDefault();\n setOver(false);\n take(e.dataTransfer.files[0]);\n }}\n className={cn(\n \"relative flex h-[164px] w-full flex-col items-center justify-center rounded-[16px] border-2 border-dashed border-kit-insp-line-strong bg-kit-insp-card text-center outline-none transition-[background-color,border-color] duration-150 ease-out focus-visible:border-kit-insp-accent\",\n over && \"border-kit-insp-accent bg-kit-insp-zone-over\",\n refusal && \"border-kit-insp-error\",\n busy && \"border-transparent bg-kit-insp-tip-bg\",\n )}\n >\n {busy ? (\n <>\n <svg aria-hidden className=\"pointer-events-none absolute -inset-0.5 h-[calc(100%+4px)] w-[calc(100%+4px)] overflow-visible\">\n <rect x=\"1\" y=\"1\" rx=\"16\" style={{ width: \"calc(100% - 2px)\", height: \"calc(100% - 2px)\" }} fill=\"none\" stroke=\"var(--kit-insp-line)\" strokeWidth=\"1.5\" />\n <rect x=\"1\" y=\"1\" rx=\"16\" style={{ width: \"calc(100% - 2px)\", height: \"calc(100% - 2px)\" }} fill=\"none\" stroke=\"var(--kit-insp-accent)\" strokeWidth=\"1.5\" pathLength={100} strokeDasharray={`${pct} 100`} className=\"transition-[stroke-dasharray] duration-[60ms] ease-linear\" />\n </svg>\n <span className=\"absolute -top-[11px] left-1/2 h-[18px] min-w-[38px] -translate-x-1/2 rounded-full bg-kit-insp-accent px-1.5 text-[11px] font-semibold leading-[18px] text-white tabular-nums\">{pct}%</span>\n </>\n ) : null}\n <span className={cn(\"mb-3.5 grid size-10 place-items-center rounded-full bg-kit-insp-zone-over text-kit-insp-accent-fg\", busy && \"border border-kit-insp-line bg-kit-insp-tip-bg\")}>\n <IconUpload className=\"size-5\" stroke={1.5} aria-hidden />\n </span>\n <span className={cn(\"text-[13px] font-medium leading-4 text-kit-insp-tip-body\", refusal && \"text-kit-insp-count-over\")}>\n {refusal ?? (over ? \"Drop to upload\" : busy ? \"Uploading…\" : (\n <>\n Drag and drop to upload or{\" \"}\n <button\n type=\"button\"\n tabIndex={-1}\n disabled={readOnly || (!upload.run && !onLibrary)}\n onClick={(e) => {\n e.stopPropagation();\n pick();\n }}\n className=\"font-medium text-kit-insp-zone-link hover:underline disabled:no-underline\"\n >\n select\n </button>\n </>\n ))}\n </span>\n <span className={cn(\"mt-1.5 text-[12px] leading-[15px] text-kit-fg-3\", done && \"text-kit-insp-zone-done\")}>\n {done ? \"Uploaded successfully!\" : upload.run ? \"PNG, JPG or WEBP · up to 10 MB\" : onLibrary ? \"Pick one from the media library\" : \"Uploading is not available here\"}\n </span>\n </div>\n )}\n {upload.error ? (\n <p role=\"alert\" className=\"-mt-2 text-[12px] leading-4 text-kit-insp-error\">\n {upload.error}\n </p>\n ) : null}\n {input}\n {alt !== undefined && onAlt ? (\n <div className=\"flex flex-col gap-2\">\n <label htmlFor={`${id}-alt`} className=\"text-[13px] font-medium leading-4 text-kit-insp-tip-body\">\n Alternative text\n </label>\n <input\n id={`${id}-alt`}\n value={alt}\n readOnly={readOnly}\n placeholder=\"Describe the image for screen readers\"\n onChange={(e) => onAlt(e.target.value)}\n className=\"h-[34px] w-full rounded-[6px] border border-transparent bg-kit-insp-card px-2.5 text-[13px] leading-[18px] tracking-[-0.1625px] text-kit-insp-tip-title outline-none transition-[background-color,border-color] duration-[120ms] ease-out placeholder:text-kit-fg-3 focus:border-kit-insp-accent focus:bg-kit-insp-card-focus\"\n />\n </div>\n ) : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAa,mBAAmB;AAChC,IAAM,UAAU;AAChB,IAAM,YAAY;AAmBlB,IAAM,MACJ;AAEF,SAAgB,cAAc,EAAE,IAAI,OAAO,UAAU,OAAO,QAAQ,KAAK,OAAO,QAAQ,UAAU,aAAiC;CACjI,MAAM,EAAE,UAAU,eAAe;CACjC,MAAM,OAAO,MAAM,OAAyB,IAAI;CAChD,MAAM,CAAC,MAAM,WAAW,MAAM,SAAS,KAAK;CAC5C,MAAM,CAAC,SAAS,cAAc,MAAM,SAAwB,IAAI;CAChE,MAAM,CAAC,MAAM,WAAW,MAAM,SAAS,KAAK;CAC5C,MAAM,OAAO,OAAO,YAAY;CAChC,MAAM,UAAU,MAAM,OAAO,KAAK;CAClC,MAAM,gBAAgB;EAEpB,IAAI,QAAQ,WAAW,CAAC,QAAQ,CAAC,OAAO,OAAO;GAC7C,QAAQ,IAAI;GACZ,MAAM,IAAI,OAAO,iBAAiB,QAAQ,KAAK,GAAG,GAAG;GACrD,QAAQ,UAAU;GAClB,aAAa,OAAO,aAAa,CAAC;EACpC;EACA,QAAQ,UAAU;CACpB,GAAG,CAAC,MAAM,OAAO,KAAK,CAAC;CACvB,MAAM,gBAAgB;E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DAAgD;MAC/K,UAAA,oBAAC,YAAD;OAAY,WAAU;OAAS,QAAQ;OAAK,eAAA;MAAa,CAAA;KACrD,CAAA;KACN,oBAAC,QAAD;MAAM,WAAW,GAAG,4DAA4D,WAAW,0BAA0B;MAClH,UAAA,YAAY,OAAO,mBAAmB,OAAO,eAC5C,qBAAA,UAAA,EAAA,UAAA;OAAE;OAC2B;OAC3B,oBAAC,UAAD;QACE,MAAK;QACL,UAAU;QACV,UAAU,YAAa,CAAC,OAAO,OAAO,CAAC;QACvC,UAAU,MAAM;SACd,EAAE,gBAAgB;SAClB,KAAK;QACP;QACA,WAAU;QACX,UAAA;OAEO,CAAA;MACR,EAAA,CAAA;KAEA,CAAA;KACN,oBAAC,QAAD;MAAM,WAAW,GAAG,mDAAmD,QAAQ,yBAAyB;MACrG,UAAA,OAAO,2BAA2B,OAAO,MAAM,mCAAmC,YAAY,oCAAoC;KAC/H,CAAA;IACH;;GAEN,OAAO,QACN,oBAAC,KAAD;IAAG,MAAK;IAAQ,WAAU;IACvB,UAAA,OAAO;GACP,CAAA,IACD;GACH;GACA,QAAQ,KAAA,KAAa,QACpB,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACE,oBAAC,SAAD;KAAO,SAAS,GAAG,GAAG;KAAO,WAAU;KAA2D,UAAA;IAE3F,CAAA,GACP,oBAAC,SAAD;KACE,IAAI,GAAG,GAAG;KACV,OAAO;KACG;KACV,aAAY;KACZ,WAAW,MAAM,MAAM,EAAE,OAAO,KAAK;KACrC,WAAU;IACX,CAAA,CACE;GACH,CAAA,IAAA;EACD;;AAET"}
|
package/dist/controls/media.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isObj } from "../lib/path.js";
|
|
|
2
2
|
import { CHECKER, fitOf, storedSize } from "../lib/media-fit.js";
|
|
3
3
|
import { cropPreset, cropRect, isCropRect } from "../adapters/values.js";
|
|
4
4
|
import { cn } from "../lib/cn.js";
|
|
5
|
-
import { useKitEnv, useKitServices } from "../context.js";
|
|
5
|
+
import { useKitEnv, useKitLook, useKitServices } from "../context.js";
|
|
6
6
|
import { Button, IconButton } from "../ui/button.js";
|
|
7
7
|
import { Progress } from "../ui/controls.js";
|
|
8
8
|
import { Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger, Popover, PopoverAnchor, PopoverContent, Tooltip } from "../ui/overlay.js";
|
|
@@ -11,6 +11,7 @@ import { isIconImage } from "../lib/icon-image.js";
|
|
|
11
11
|
import { Input, Textarea } from "../ui/input.js";
|
|
12
12
|
import { Select } from "../ui/select.js";
|
|
13
13
|
import { useDragReorder } from "../engine/item-list.js";
|
|
14
|
+
import { V16ImageField } from "./media-v16.js";
|
|
14
15
|
import * as React from "react";
|
|
15
16
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
16
17
|
import { IconAlertTriangle, IconCrop, IconDots, IconDownload, IconExternalLink, IconFileText, IconFocusCentered, IconLink, IconPhoto, IconPlayerPlay, IconPlus, IconRefresh, IconReplace, IconTrash, IconUpload, IconVideo, IconWorld, IconX } from "@tabler/icons-react";
|
|
@@ -648,6 +649,7 @@ function IconImageRow({ id, title, url, readOnly, onOpen, onFiles, busy, pickerO
|
|
|
648
649
|
function ImageControl({ field, value, onChange: write, readOnly, id, path }) {
|
|
649
650
|
const { s, useAsset, src } = useMedia();
|
|
650
651
|
const env = useKitEnv();
|
|
652
|
+
const v16 = useKitLook() === "v16";
|
|
651
653
|
const urlOnly = !!s.imageStoresUrl?.(path);
|
|
652
654
|
const altOnly = !urlOnly && !!s.imageAltOnly?.(path);
|
|
653
655
|
const legacyString = typeof value === "string" || field.valueShape === "string";
|
|
@@ -744,6 +746,66 @@ function ImageControl({ field, value, onChange: write, readOnly, id, path }) {
|
|
|
744
746
|
]
|
|
745
747
|
});
|
|
746
748
|
}
|
|
749
|
+
if (v16) {
|
|
750
|
+
const bytes = asset?.size;
|
|
751
|
+
const meta = size ? `${size.w} × ${size.h}${bytes ? ` · ${formatBytes(bytes)}` : ""}` : bytes ? formatBytes(bytes) : void 0;
|
|
752
|
+
return /* @__PURE__ */ jsxs(Popover, {
|
|
753
|
+
open: details,
|
|
754
|
+
onOpenChange: setDetails,
|
|
755
|
+
children: [
|
|
756
|
+
/* @__PURE__ */ jsx(PopoverAnchor, {
|
|
757
|
+
className: "min-w-0",
|
|
758
|
+
children: /* @__PURE__ */ jsx(V16ImageField, {
|
|
759
|
+
id,
|
|
760
|
+
label: field.title,
|
|
761
|
+
readOnly,
|
|
762
|
+
image: v ? {
|
|
763
|
+
src: src(v.url),
|
|
764
|
+
url: v.url,
|
|
765
|
+
name: asset?.name ?? v.name ?? fileNameFromUrl(v.url),
|
|
766
|
+
meta
|
|
767
|
+
} : null,
|
|
768
|
+
upload: up,
|
|
769
|
+
alt: v && !urlOnly ? v.alt ?? "" : void 0,
|
|
770
|
+
onAlt: v && !readOnly ? (a) => onChange({
|
|
771
|
+
...v,
|
|
772
|
+
alt: a
|
|
773
|
+
}) : void 0,
|
|
774
|
+
onCrop: v && !urlOnly && !altOnly ? () => window.setTimeout(() => setDetails(true), 0) : void 0,
|
|
775
|
+
onRemove: () => onChange(null),
|
|
776
|
+
onLibrary: library
|
|
777
|
+
})
|
|
778
|
+
}),
|
|
779
|
+
v ? /* @__PURE__ */ jsx(PopoverContent, {
|
|
780
|
+
className: "w-[320px]",
|
|
781
|
+
align: "start",
|
|
782
|
+
side: "bottom",
|
|
783
|
+
children: /* @__PURE__ */ jsx(ImageDetails, {
|
|
784
|
+
v,
|
|
785
|
+
onChange,
|
|
786
|
+
readOnly,
|
|
787
|
+
label: field.title,
|
|
788
|
+
urlOnly,
|
|
789
|
+
altOnly,
|
|
790
|
+
size,
|
|
791
|
+
asset,
|
|
792
|
+
fit
|
|
793
|
+
})
|
|
794
|
+
}) : null,
|
|
795
|
+
/* @__PURE__ */ jsx(MediaPicker, {
|
|
796
|
+
open: picker,
|
|
797
|
+
onOpenChange: setPicker,
|
|
798
|
+
accept: kinds,
|
|
799
|
+
onPick: (a) => {
|
|
800
|
+
if (!a[0]) return;
|
|
801
|
+
const next = fromAsset(a[0]);
|
|
802
|
+
if (v?.alt && !next.alt) next.alt = "";
|
|
803
|
+
onChange(next);
|
|
804
|
+
}
|
|
805
|
+
})
|
|
806
|
+
]
|
|
807
|
+
});
|
|
808
|
+
}
|
|
747
809
|
if (!v && readOnly) return /* @__PURE__ */ jsx("span", {
|
|
748
810
|
id,
|
|
749
811
|
className: "text-kit-sm text-kit-fg-3",
|