@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/README.md +38 -0
- package/dist/index.d.mts +131 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.js +581 -0
- package/dist/index.mjs +542 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @reacteditor/field-tailwind
|
|
2
|
+
|
|
3
|
+
A custom React Editor field that edits a `className` string as searchable,
|
|
4
|
+
multi-add **Tailwind class tags** instead of a plain text input. Built on the
|
|
5
|
+
[`@base-ui/react`](https://base-ui.com) Combobox — type to filter a curated
|
|
6
|
+
catalog of common utilities, select to add chips, and add arbitrary classes
|
|
7
|
+
(e.g. `gap-[7px]`) via the "Add …" entry.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { createFieldTailwind } from "@reacteditor/field-tailwind";
|
|
13
|
+
|
|
14
|
+
export const myEditor = {
|
|
15
|
+
// …
|
|
16
|
+
fields: {
|
|
17
|
+
className: createFieldTailwind({ label: "Class name" }),
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The field value is a single space-separated string, so it drops straight onto a
|
|
23
|
+
component's `className` prop.
|
|
24
|
+
|
|
25
|
+
## Options
|
|
26
|
+
|
|
27
|
+
| Option | Type | Description |
|
|
28
|
+
| -------------- | ---------- | ------------------------------------------------------------------ |
|
|
29
|
+
| `classes` | `string[]` | Replace the built-in catalog entirely with your own list. |
|
|
30
|
+
| `extraClasses` | `string[]` | Append extra classes to the built-in catalog (ignored if `classes`).|
|
|
31
|
+
| `placeholder` | `string` | Input placeholder. Defaults to `"Add classes…"`. |
|
|
32
|
+
| `label` | `string` | Field label shown in the sidebar. |
|
|
33
|
+
|
|
34
|
+
## Exports
|
|
35
|
+
|
|
36
|
+
- `createFieldTailwind(options?)` — the field factory.
|
|
37
|
+
- `TAILWIND_CLASSES` — the built-in class catalog (`string[]`).
|
|
38
|
+
- `TailwindCombobox` — the underlying combobox component, if you want to reuse it.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
type ItemSelector = {
|
|
5
|
+
index: number;
|
|
6
|
+
zone?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
interface BaseField {
|
|
10
|
+
label?: string;
|
|
11
|
+
labelIcon?: ReactElement;
|
|
12
|
+
metadata?: FieldMetadata;
|
|
13
|
+
visible?: boolean;
|
|
14
|
+
}
|
|
15
|
+
type CustomFieldRender<Value extends any> = (props: {
|
|
16
|
+
field: CustomField<Value>;
|
|
17
|
+
name: string;
|
|
18
|
+
id: string;
|
|
19
|
+
value: Value;
|
|
20
|
+
onChange: (value: Value, uiState?: Partial<UiState>) => void;
|
|
21
|
+
readOnly?: boolean;
|
|
22
|
+
}) => ReactElement;
|
|
23
|
+
interface CustomField<Value extends any> extends BaseField {
|
|
24
|
+
type: "custom";
|
|
25
|
+
render: CustomFieldRender<Value>;
|
|
26
|
+
contentEditable?: boolean;
|
|
27
|
+
key?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type Metadata = {
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
};
|
|
33
|
+
interface FieldMetadata extends Metadata {
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type ItemWithId = {
|
|
37
|
+
_arrayId: string;
|
|
38
|
+
_originalIndex: number;
|
|
39
|
+
_currentIndex: number;
|
|
40
|
+
};
|
|
41
|
+
type ArrayState = {
|
|
42
|
+
items: ItemWithId[];
|
|
43
|
+
openId: string;
|
|
44
|
+
};
|
|
45
|
+
type UiState = {
|
|
46
|
+
leftSideBarVisible: boolean;
|
|
47
|
+
rightSideBarVisible: boolean;
|
|
48
|
+
leftSideBarWidth?: number | null;
|
|
49
|
+
rightSideBarWidth?: number | null;
|
|
50
|
+
/** Runtime: when true, the canvas overlays the entire editor area
|
|
51
|
+
* (sidebars stay mounted underneath). Toggled by the BrowserBar fullscreen
|
|
52
|
+
* button. Distinct from the static `fullScreenCanvas` Editor prop, which
|
|
53
|
+
* removes canvas padding for a chromeless render. */
|
|
54
|
+
canvasFullScreen?: boolean;
|
|
55
|
+
mobilePanelExpanded?: boolean;
|
|
56
|
+
itemSelector: ItemSelector | null;
|
|
57
|
+
arrayState: Record<string, ArrayState | undefined>;
|
|
58
|
+
previewMode: "interactive" | "edit";
|
|
59
|
+
componentList: Record<string, {
|
|
60
|
+
components?: string[];
|
|
61
|
+
title?: string;
|
|
62
|
+
visible?: boolean;
|
|
63
|
+
expanded?: boolean;
|
|
64
|
+
}>;
|
|
65
|
+
isDragging: boolean;
|
|
66
|
+
viewports: {
|
|
67
|
+
current: {
|
|
68
|
+
width: number | "100%";
|
|
69
|
+
height: number | "auto";
|
|
70
|
+
};
|
|
71
|
+
controlsVisible: boolean;
|
|
72
|
+
options: Viewport[];
|
|
73
|
+
};
|
|
74
|
+
field: {
|
|
75
|
+
focus?: string | null;
|
|
76
|
+
metadata?: Record<string, any>;
|
|
77
|
+
};
|
|
78
|
+
plugin: {
|
|
79
|
+
current: string | null;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
type iconTypes = "Smartphone" | "Monitor" | "Tablet";
|
|
84
|
+
type Viewport = {
|
|
85
|
+
width: number | "100%";
|
|
86
|
+
height?: number | "auto";
|
|
87
|
+
label?: string;
|
|
88
|
+
icon?: iconTypes | ReactNode;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
declare const TAILWIND_CLASSES: string[];
|
|
92
|
+
|
|
93
|
+
type TailwindComboboxProps = {
|
|
94
|
+
value: string[];
|
|
95
|
+
onValueChange: (value: string[]) => void;
|
|
96
|
+
items: string[];
|
|
97
|
+
placeholder?: string;
|
|
98
|
+
disabled?: boolean;
|
|
99
|
+
id?: string;
|
|
100
|
+
};
|
|
101
|
+
declare function TailwindCombobox({ value, onValueChange, items, placeholder, disabled, id, }: TailwindComboboxProps): react_jsx_runtime.JSX.Element;
|
|
102
|
+
|
|
103
|
+
type Options = {
|
|
104
|
+
/**
|
|
105
|
+
* Replace the built-in catalog entirely with your own class list.
|
|
106
|
+
*/
|
|
107
|
+
classes?: string[];
|
|
108
|
+
/**
|
|
109
|
+
* Append extra classes (e.g. project-specific utilities) to the built-in
|
|
110
|
+
* catalog. Ignored when `classes` is provided.
|
|
111
|
+
*/
|
|
112
|
+
extraClasses?: string[];
|
|
113
|
+
/** Input placeholder. Defaults to "Add classes…". */
|
|
114
|
+
placeholder?: string;
|
|
115
|
+
/** Field label shown in the sidebar. */
|
|
116
|
+
label?: string;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Creates a `custom` field that edits a `className` string as searchable,
|
|
120
|
+
* multi-add Tailwind class tags. Use it in place of a `{ type: "text" }`
|
|
121
|
+
* className field:
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* fields: {
|
|
125
|
+
* className: createFieldTailwind(),
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare function createFieldTailwind(options?: Options): CustomField<string | undefined>;
|
|
130
|
+
|
|
131
|
+
export { TAILWIND_CLASSES, TailwindCombobox, createFieldTailwind };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
type ItemSelector = {
|
|
5
|
+
index: number;
|
|
6
|
+
zone?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
interface BaseField {
|
|
10
|
+
label?: string;
|
|
11
|
+
labelIcon?: ReactElement;
|
|
12
|
+
metadata?: FieldMetadata;
|
|
13
|
+
visible?: boolean;
|
|
14
|
+
}
|
|
15
|
+
type CustomFieldRender<Value extends any> = (props: {
|
|
16
|
+
field: CustomField<Value>;
|
|
17
|
+
name: string;
|
|
18
|
+
id: string;
|
|
19
|
+
value: Value;
|
|
20
|
+
onChange: (value: Value, uiState?: Partial<UiState>) => void;
|
|
21
|
+
readOnly?: boolean;
|
|
22
|
+
}) => ReactElement;
|
|
23
|
+
interface CustomField<Value extends any> extends BaseField {
|
|
24
|
+
type: "custom";
|
|
25
|
+
render: CustomFieldRender<Value>;
|
|
26
|
+
contentEditable?: boolean;
|
|
27
|
+
key?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type Metadata = {
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
};
|
|
33
|
+
interface FieldMetadata extends Metadata {
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type ItemWithId = {
|
|
37
|
+
_arrayId: string;
|
|
38
|
+
_originalIndex: number;
|
|
39
|
+
_currentIndex: number;
|
|
40
|
+
};
|
|
41
|
+
type ArrayState = {
|
|
42
|
+
items: ItemWithId[];
|
|
43
|
+
openId: string;
|
|
44
|
+
};
|
|
45
|
+
type UiState = {
|
|
46
|
+
leftSideBarVisible: boolean;
|
|
47
|
+
rightSideBarVisible: boolean;
|
|
48
|
+
leftSideBarWidth?: number | null;
|
|
49
|
+
rightSideBarWidth?: number | null;
|
|
50
|
+
/** Runtime: when true, the canvas overlays the entire editor area
|
|
51
|
+
* (sidebars stay mounted underneath). Toggled by the BrowserBar fullscreen
|
|
52
|
+
* button. Distinct from the static `fullScreenCanvas` Editor prop, which
|
|
53
|
+
* removes canvas padding for a chromeless render. */
|
|
54
|
+
canvasFullScreen?: boolean;
|
|
55
|
+
mobilePanelExpanded?: boolean;
|
|
56
|
+
itemSelector: ItemSelector | null;
|
|
57
|
+
arrayState: Record<string, ArrayState | undefined>;
|
|
58
|
+
previewMode: "interactive" | "edit";
|
|
59
|
+
componentList: Record<string, {
|
|
60
|
+
components?: string[];
|
|
61
|
+
title?: string;
|
|
62
|
+
visible?: boolean;
|
|
63
|
+
expanded?: boolean;
|
|
64
|
+
}>;
|
|
65
|
+
isDragging: boolean;
|
|
66
|
+
viewports: {
|
|
67
|
+
current: {
|
|
68
|
+
width: number | "100%";
|
|
69
|
+
height: number | "auto";
|
|
70
|
+
};
|
|
71
|
+
controlsVisible: boolean;
|
|
72
|
+
options: Viewport[];
|
|
73
|
+
};
|
|
74
|
+
field: {
|
|
75
|
+
focus?: string | null;
|
|
76
|
+
metadata?: Record<string, any>;
|
|
77
|
+
};
|
|
78
|
+
plugin: {
|
|
79
|
+
current: string | null;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
type iconTypes = "Smartphone" | "Monitor" | "Tablet";
|
|
84
|
+
type Viewport = {
|
|
85
|
+
width: number | "100%";
|
|
86
|
+
height?: number | "auto";
|
|
87
|
+
label?: string;
|
|
88
|
+
icon?: iconTypes | ReactNode;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
declare const TAILWIND_CLASSES: string[];
|
|
92
|
+
|
|
93
|
+
type TailwindComboboxProps = {
|
|
94
|
+
value: string[];
|
|
95
|
+
onValueChange: (value: string[]) => void;
|
|
96
|
+
items: string[];
|
|
97
|
+
placeholder?: string;
|
|
98
|
+
disabled?: boolean;
|
|
99
|
+
id?: string;
|
|
100
|
+
};
|
|
101
|
+
declare function TailwindCombobox({ value, onValueChange, items, placeholder, disabled, id, }: TailwindComboboxProps): react_jsx_runtime.JSX.Element;
|
|
102
|
+
|
|
103
|
+
type Options = {
|
|
104
|
+
/**
|
|
105
|
+
* Replace the built-in catalog entirely with your own class list.
|
|
106
|
+
*/
|
|
107
|
+
classes?: string[];
|
|
108
|
+
/**
|
|
109
|
+
* Append extra classes (e.g. project-specific utilities) to the built-in
|
|
110
|
+
* catalog. Ignored when `classes` is provided.
|
|
111
|
+
*/
|
|
112
|
+
extraClasses?: string[];
|
|
113
|
+
/** Input placeholder. Defaults to "Add classes…". */
|
|
114
|
+
placeholder?: string;
|
|
115
|
+
/** Field label shown in the sidebar. */
|
|
116
|
+
label?: string;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Creates a `custom` field that edits a `className` string as searchable,
|
|
120
|
+
* multi-add Tailwind class tags. Use it in place of a `{ type: "text" }`
|
|
121
|
+
* className field:
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* fields: {
|
|
125
|
+
* className: createFieldTailwind(),
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare function createFieldTailwind(options?: Options): CustomField<string | undefined>;
|
|
130
|
+
|
|
131
|
+
export { TAILWIND_CLASSES, TailwindCombobox, createFieldTailwind };
|