@reacteditor/field-tailwind 0.0.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/dist/index.js ADDED
@@ -0,0 +1,581 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // index.tsx
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ TAILWIND_CLASSES: () => TAILWIND_CLASSES,
34
+ TailwindCombobox: () => TailwindCombobox,
35
+ createFieldTailwind: () => createFieldTailwind
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+
39
+ // ../tsup-config/react-import.js
40
+ var import_react = __toESM(require("react"));
41
+
42
+ // index.tsx
43
+ var import_core = require("@reacteditor/core");
44
+
45
+ // combobox.tsx
46
+ var React2 = __toESM(require("react"));
47
+ var import_react2 = require("react");
48
+ var import_combobox = require("@base-ui/react/combobox");
49
+ var import_lucide_react = require("lucide-react");
50
+ var import_jsx_runtime = require("react/jsx-runtime");
51
+ var STYLE_ID = "reacteditor-field-tailwind";
52
+ var STYLES = `
53
+ .rtw-chips:focus-within { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,0.2); }
54
+ .rtw-input:focus { outline: none; }
55
+ .rtw-input::placeholder { color: #9ca3af; }
56
+ .rtw-item[data-highlighted] { background: #eef2ff; }
57
+ .rtw-item[data-selected] { font-weight: 500; }
58
+ .rtw-chip-remove:hover { opacity: 1; }
59
+ .rtw-list { scrollbar-width: thin; }
60
+ `;
61
+ var ensureStyles = () => {
62
+ if (typeof document === "undefined") return;
63
+ if (document.getElementById(STYLE_ID)) return;
64
+ const el = document.createElement("style");
65
+ el.id = STYLE_ID;
66
+ el.textContent = STYLES;
67
+ document.head.appendChild(el);
68
+ };
69
+ var s = {
70
+ chips: {
71
+ display: "flex",
72
+ flexWrap: "wrap",
73
+ alignItems: "center",
74
+ gap: 4,
75
+ minHeight: 34,
76
+ width: "100%",
77
+ padding: "4px 6px",
78
+ borderRadius: 6,
79
+ border: "1px solid #d1d5db",
80
+ background: "#fff",
81
+ boxSizing: "border-box",
82
+ transition: "border-color 120ms, box-shadow 120ms"
83
+ },
84
+ chip: {
85
+ display: "inline-flex",
86
+ alignItems: "center",
87
+ gap: 4,
88
+ height: 22,
89
+ padding: "0 4px 0 8px",
90
+ borderRadius: 4,
91
+ background: "#f1f5f9",
92
+ color: "#111827",
93
+ fontSize: 12,
94
+ fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
95
+ whiteSpace: "nowrap"
96
+ },
97
+ chipRemove: {
98
+ display: "inline-flex",
99
+ alignItems: "center",
100
+ justifyContent: "center",
101
+ width: 16,
102
+ height: 16,
103
+ padding: 0,
104
+ border: "none",
105
+ background: "transparent",
106
+ color: "inherit",
107
+ cursor: "pointer",
108
+ opacity: 0.5,
109
+ transition: "opacity 120ms"
110
+ },
111
+ input: {
112
+ flex: 1,
113
+ minWidth: 80,
114
+ height: 22,
115
+ border: "none",
116
+ background: "transparent",
117
+ fontSize: 13,
118
+ color: "#111827",
119
+ padding: 0
120
+ },
121
+ popup: {
122
+ boxSizing: "border-box",
123
+ width: "var(--anchor-width)",
124
+ maxHeight: "min(280px, var(--available-height))",
125
+ overflowY: "auto",
126
+ background: "#fff",
127
+ border: "1px solid #e5e7eb",
128
+ borderRadius: 8,
129
+ boxShadow: "0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1)",
130
+ padding: 4,
131
+ zIndex: 9999
132
+ },
133
+ list: { display: "flex", flexDirection: "column" },
134
+ item: {
135
+ display: "flex",
136
+ alignItems: "center",
137
+ justifyContent: "space-between",
138
+ gap: 8,
139
+ padding: "6px 8px",
140
+ borderRadius: 4,
141
+ fontSize: 13,
142
+ fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
143
+ color: "#111827",
144
+ cursor: "default",
145
+ userSelect: "none"
146
+ },
147
+ indicator: {
148
+ display: "inline-flex",
149
+ alignItems: "center",
150
+ color: "#6366f1"
151
+ },
152
+ empty: {
153
+ padding: "8px",
154
+ fontSize: 13,
155
+ color: "#6b7280",
156
+ textAlign: "center"
157
+ },
158
+ create: { color: "#6366f1" }
159
+ };
160
+ function TailwindCombobox({
161
+ value,
162
+ onValueChange,
163
+ items,
164
+ placeholder = "Add classes\u2026",
165
+ disabled,
166
+ id
167
+ }) {
168
+ ensureStyles();
169
+ const anchor = (0, import_react2.useRef)(null);
170
+ const [query, setQuery] = (0, import_react2.useState)("");
171
+ const filteredItems = (0, import_react2.useMemo)(() => {
172
+ const q = query.trim();
173
+ const lower = q.toLowerCase();
174
+ const matches = items.filter((c) => c.toLowerCase().includes(lower));
175
+ const isKnown = items.includes(q) || value.includes(q);
176
+ return q && !isKnown ? [q, ...matches] : matches;
177
+ }, [query, items, value]);
178
+ const isCreate = (item) => !items.includes(item);
179
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
180
+ import_combobox.Combobox.Root,
181
+ {
182
+ multiple: true,
183
+ items,
184
+ value,
185
+ filteredItems,
186
+ onValueChange: (next) => onValueChange(next != null ? next : []),
187
+ onInputValueChange: (next) => setQuery(next),
188
+ children: [
189
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_combobox.Combobox.Chips, { ref: anchor, className: "rtw-chips", style: s.chips, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_combobox.Combobox.Value, { children: (values) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(React2.Fragment, { children: [
190
+ values.map((v) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_combobox.Combobox.Chip, { style: s.chip, children: [
191
+ v,
192
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
193
+ import_combobox.Combobox.ChipRemove,
194
+ {
195
+ className: "rtw-chip-remove",
196
+ style: s.chipRemove,
197
+ "aria-label": `Remove ${v}`,
198
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.X, { size: 12 })
199
+ }
200
+ )
201
+ ] }, v)),
202
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
203
+ import_combobox.Combobox.Input,
204
+ {
205
+ id,
206
+ disabled,
207
+ placeholder: values.length === 0 ? placeholder : "",
208
+ className: "rtw-input",
209
+ style: s.input
210
+ }
211
+ )
212
+ ] }) }) }),
213
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_combobox.Combobox.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_combobox.Combobox.Positioner, { anchor, sideOffset: 4, style: { zIndex: 9999 }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_combobox.Combobox.Popup, { style: s.popup, children: [
214
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_combobox.Combobox.Empty, { style: s.empty, children: "No classes found." }),
215
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_combobox.Combobox.List, { className: "rtw-list", style: s.list, children: (item) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
216
+ import_combobox.Combobox.Item,
217
+ {
218
+ value: item,
219
+ className: "rtw-item",
220
+ style: s.item,
221
+ children: [
222
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: isCreate(item) ? s.create : void 0, children: isCreate(item) ? `Add "${item}"` : item }),
223
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_combobox.Combobox.ItemIndicator, { style: s.indicator, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Check, { size: 14 }) })
224
+ ]
225
+ },
226
+ item
227
+ ) })
228
+ ] }) }) })
229
+ ]
230
+ }
231
+ );
232
+ }
233
+
234
+ // tailwind-classes.ts
235
+ var COLORS = [
236
+ "slate",
237
+ "gray",
238
+ "zinc",
239
+ "neutral",
240
+ "stone",
241
+ "red",
242
+ "orange",
243
+ "amber",
244
+ "yellow",
245
+ "lime",
246
+ "green",
247
+ "emerald",
248
+ "teal",
249
+ "cyan",
250
+ "sky",
251
+ "blue",
252
+ "indigo",
253
+ "violet",
254
+ "purple",
255
+ "fuchsia",
256
+ "pink",
257
+ "rose"
258
+ ];
259
+ var COLOR_STEPS = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
260
+ var SPACING = [
261
+ "0",
262
+ "0.5",
263
+ "1",
264
+ "1.5",
265
+ "2",
266
+ "2.5",
267
+ "3",
268
+ "4",
269
+ "5",
270
+ "6",
271
+ "8",
272
+ "10",
273
+ "12",
274
+ "16",
275
+ "20",
276
+ "24",
277
+ "px"
278
+ ];
279
+ var expand = (prefixes, values) => prefixes.flatMap((prefix) => values.map((value) => `${prefix}-${value}`));
280
+ var colorUtilities = (prefixes) => prefixes.flatMap((prefix) => [
281
+ `${prefix}-white`,
282
+ `${prefix}-black`,
283
+ `${prefix}-transparent`,
284
+ `${prefix}-current`,
285
+ ...COLORS.flatMap(
286
+ (color) => COLOR_STEPS.map((step) => `${prefix}-${color}-${step}`)
287
+ )
288
+ ]);
289
+ var layout = [
290
+ "block",
291
+ "inline-block",
292
+ "inline",
293
+ "flex",
294
+ "inline-flex",
295
+ "grid",
296
+ "inline-grid",
297
+ "hidden",
298
+ "table",
299
+ "contents"
300
+ ];
301
+ var flexbox = [
302
+ "flex-row",
303
+ "flex-row-reverse",
304
+ "flex-col",
305
+ "flex-col-reverse",
306
+ "flex-wrap",
307
+ "flex-nowrap",
308
+ "flex-1",
309
+ "flex-auto",
310
+ "flex-initial",
311
+ "flex-none",
312
+ "grow",
313
+ "grow-0",
314
+ "shrink",
315
+ "shrink-0",
316
+ "items-start",
317
+ "items-center",
318
+ "items-end",
319
+ "items-stretch",
320
+ "items-baseline",
321
+ "justify-start",
322
+ "justify-center",
323
+ "justify-end",
324
+ "justify-between",
325
+ "justify-around",
326
+ "justify-evenly",
327
+ "content-start",
328
+ "content-center",
329
+ "content-end",
330
+ "content-between",
331
+ "self-start",
332
+ "self-center",
333
+ "self-end",
334
+ "self-stretch"
335
+ ];
336
+ var grid = [
337
+ "grid-cols-1",
338
+ "grid-cols-2",
339
+ "grid-cols-3",
340
+ "grid-cols-4",
341
+ "grid-cols-5",
342
+ "grid-cols-6",
343
+ "grid-cols-12",
344
+ "col-span-1",
345
+ "col-span-2",
346
+ "col-span-3",
347
+ "col-span-full",
348
+ "grid-rows-1",
349
+ "grid-rows-2",
350
+ "grid-rows-3",
351
+ "place-items-center",
352
+ "place-content-center"
353
+ ];
354
+ var sizing = [
355
+ "w-full",
356
+ "w-auto",
357
+ "w-screen",
358
+ "w-fit",
359
+ "w-min",
360
+ "w-max",
361
+ "w-1/2",
362
+ "w-1/3",
363
+ "w-2/3",
364
+ "w-1/4",
365
+ "w-3/4",
366
+ "h-full",
367
+ "h-auto",
368
+ "h-screen",
369
+ "h-fit",
370
+ "min-h-screen",
371
+ "min-h-full",
372
+ "min-w-0",
373
+ "min-w-full",
374
+ "max-w-xs",
375
+ "max-w-sm",
376
+ "max-w-md",
377
+ "max-w-lg",
378
+ "max-w-xl",
379
+ "max-w-2xl",
380
+ "max-w-3xl",
381
+ "max-w-4xl",
382
+ "max-w-5xl",
383
+ "max-w-6xl",
384
+ "max-w-7xl",
385
+ "max-w-prose",
386
+ "max-w-full",
387
+ "max-w-none",
388
+ "size-full",
389
+ "size-4",
390
+ "size-6",
391
+ "size-8"
392
+ ];
393
+ var typography = [
394
+ "text-xs",
395
+ "text-sm",
396
+ "text-base",
397
+ "text-lg",
398
+ "text-xl",
399
+ "text-2xl",
400
+ "text-3xl",
401
+ "text-4xl",
402
+ "text-5xl",
403
+ "text-6xl",
404
+ "font-thin",
405
+ "font-light",
406
+ "font-normal",
407
+ "font-medium",
408
+ "font-semibold",
409
+ "font-bold",
410
+ "font-extrabold",
411
+ "font-black",
412
+ "text-left",
413
+ "text-center",
414
+ "text-right",
415
+ "text-justify",
416
+ "leading-none",
417
+ "leading-tight",
418
+ "leading-snug",
419
+ "leading-normal",
420
+ "leading-relaxed",
421
+ "leading-loose",
422
+ "tracking-tighter",
423
+ "tracking-tight",
424
+ "tracking-normal",
425
+ "tracking-wide",
426
+ "tracking-wider",
427
+ "uppercase",
428
+ "lowercase",
429
+ "capitalize",
430
+ "normal-case",
431
+ "italic",
432
+ "not-italic",
433
+ "underline",
434
+ "line-through",
435
+ "no-underline",
436
+ "truncate"
437
+ ];
438
+ var borders = [
439
+ "border",
440
+ "border-0",
441
+ "border-2",
442
+ "border-4",
443
+ "border-8",
444
+ "border-t",
445
+ "border-r",
446
+ "border-b",
447
+ "border-l",
448
+ "border-solid",
449
+ "border-dashed",
450
+ "border-dotted",
451
+ "rounded-none",
452
+ "rounded-sm",
453
+ "rounded",
454
+ "rounded-md",
455
+ "rounded-lg",
456
+ "rounded-xl",
457
+ "rounded-2xl",
458
+ "rounded-3xl",
459
+ "rounded-full",
460
+ "divide-y",
461
+ "divide-x"
462
+ ];
463
+ var effects = [
464
+ "shadow-none",
465
+ "shadow-sm",
466
+ "shadow",
467
+ "shadow-md",
468
+ "shadow-lg",
469
+ "shadow-xl",
470
+ "shadow-2xl",
471
+ "shadow-inner",
472
+ "opacity-0",
473
+ "opacity-25",
474
+ "opacity-50",
475
+ "opacity-75",
476
+ "opacity-100",
477
+ "ring",
478
+ "ring-0",
479
+ "ring-1",
480
+ "ring-2",
481
+ "ring-inset",
482
+ "blur",
483
+ "blur-sm",
484
+ "backdrop-blur"
485
+ ];
486
+ var positioning = [
487
+ "static",
488
+ "relative",
489
+ "absolute",
490
+ "fixed",
491
+ "sticky",
492
+ "inset-0",
493
+ "inset-x-0",
494
+ "inset-y-0",
495
+ "top-0",
496
+ "right-0",
497
+ "bottom-0",
498
+ "left-0",
499
+ "z-0",
500
+ "z-10",
501
+ "z-20",
502
+ "z-30",
503
+ "z-40",
504
+ "z-50",
505
+ "overflow-auto",
506
+ "overflow-hidden",
507
+ "overflow-scroll",
508
+ "overflow-x-auto",
509
+ "overflow-y-auto"
510
+ ];
511
+ var misc = [
512
+ "object-contain",
513
+ "object-cover",
514
+ "object-fill",
515
+ "object-center",
516
+ "cursor-pointer",
517
+ "cursor-default",
518
+ "select-none",
519
+ "pointer-events-none",
520
+ "transition",
521
+ "transition-all",
522
+ "transition-colors",
523
+ "duration-150",
524
+ "duration-300",
525
+ "ease-in-out",
526
+ "antialiased",
527
+ "container",
528
+ "mx-auto",
529
+ "my-auto"
530
+ ];
531
+ var TAILWIND_CLASSES = Array.from(
532
+ /* @__PURE__ */ new Set([
533
+ ...layout,
534
+ ...flexbox,
535
+ ...grid,
536
+ ...sizing,
537
+ ...typography,
538
+ ...borders,
539
+ ...effects,
540
+ ...positioning,
541
+ ...misc,
542
+ // spacing scales
543
+ ...expand(["p", "px", "py", "pt", "pr", "pb", "pl"], SPACING),
544
+ ...expand(["m", "mx", "my", "mt", "mr", "mb", "ml"], SPACING),
545
+ ...expand(["gap", "gap-x", "gap-y", "space-x", "space-y"], SPACING),
546
+ // colors
547
+ ...colorUtilities(["text", "bg", "border", "ring", "from", "to", "via"])
548
+ ])
549
+ );
550
+
551
+ // index.tsx
552
+ var import_jsx_runtime2 = require("react/jsx-runtime");
553
+ var splitClasses = (value) => (value != null ? value : "").split(/\s+/).filter(Boolean);
554
+ function createFieldTailwind(options = {}) {
555
+ const { classes, extraClasses, placeholder, label } = options;
556
+ const items = classes ? classes : Array.from(/* @__PURE__ */ new Set([...TAILWIND_CLASSES, ...extraClasses != null ? extraClasses : []]));
557
+ return {
558
+ type: "custom",
559
+ label,
560
+ render: ({ value, onChange, readOnly, id }) => {
561
+ const combobox = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
562
+ TailwindCombobox,
563
+ {
564
+ id,
565
+ items,
566
+ placeholder,
567
+ disabled: readOnly,
568
+ value: splitClasses(value),
569
+ onValueChange: (tags) => onChange(tags.join(" "))
570
+ }
571
+ );
572
+ return label ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core.FieldLabel, { label, readOnly, el: "div", children: combobox }) : combobox;
573
+ }
574
+ };
575
+ }
576
+ // Annotate the CommonJS export names for ESM import in node:
577
+ 0 && (module.exports = {
578
+ TAILWIND_CLASSES,
579
+ TailwindCombobox,
580
+ createFieldTailwind
581
+ });