@gridui/inline-editor 2.1.3 → 3.0.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/README.md +22 -5
- package/dist/index.js +10 -6
- package/dist/index.js.map +2 -2
- package/dist/inline-editor/inline-editor.d.ts +2 -0
- package/dist/inline-editor-actions/inline-editor-actions.d.ts +2 -0
- package/dist/shared/editor-context.d.ts +2 -0
- package/dist/styled.js +4 -0
- package/dist/styles.css +955 -0
- package/dist/styles.local.css +25 -0
- package/docs/catalog.json +7 -6
- package/docs/reference/inline-editor-actions.md +8 -2
- package/docs/reference/inline-editor-display.md +2 -2
- package/docs/reference/inline-editor-field.md +10 -4
- package/docs/reference/inline-editor-textarea.md +8 -6
- package/docs/reference/inline-editor-trigger.md +4 -4
- package/docs/reference/inline-editor.md +10 -2
- package/package.json +12 -7
package/README.md
CHANGED
|
@@ -1,17 +1,34 @@
|
|
|
1
1
|
# @gridui/inline-editor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Controls family. Public API: `InlineEditor`, `InlineEditorDisplay`, `InlineEditorTrigger`, `InlineEditorField`, `InlineEditorTextarea`, and `InlineEditorActions`.
|
|
4
4
|
|
|
5
5
|
Import components from `@gridui/inline-editor` and load `@gridui/inline-editor/styles.css` after Theme.
|
|
6
|
-
|
|
6
|
+
Applications own routes, labels, state persistence, and branding.
|
|
7
|
+
|
|
8
|
+
See [component ownership](https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/docs/component-ownership.md) and [release history](https://github.com/sudo-ui/GridUI-React-Monorepo/tree/main/packages-controls/inline-editor/.changeset/history).
|
|
9
|
+
|
|
10
|
+
## Styles
|
|
11
|
+
|
|
12
|
+
Load Theme once. Use `@gridui/inline-editor/styled` for automatic component CSS in
|
|
13
|
+
CSS-aware bundlers, or keep the CSS-free root import and load `@gridui/inline-editor/styles.css`.
|
|
14
|
+
Both entries expose the same root API. The standalone stylesheet includes component
|
|
15
|
+
dependency styles; Theme/reset remain separate. See the
|
|
16
|
+
[integration guide](https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/docs/usage/integration.md)
|
|
17
|
+
for static HTML loading, SSR limits, and avoiding duplicate CSS.
|
|
7
18
|
|
|
8
|
-
See [component ownership](https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/docs/component-ownership.md) and [release history](https://github.com/sudo-ui/GridUI-React-Monorepo/tree/main/packages-core/inline-editor/.changeset/history).
|
|
9
19
|
|
|
10
20
|
## Controlled inline editing
|
|
11
21
|
|
|
12
22
|
See [InlineEditor](docs/inline-editor.md) for editing state and submission ownership,
|
|
13
|
-
and [Textarea](https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/packages-
|
|
23
|
+
and [Textarea](https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/packages-controls/input/docs/textarea.md#size-and-automatic-height) for optional automatic height.
|
|
14
24
|
|
|
15
|
-
See [common inputs](https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/packages-
|
|
25
|
+
See [common inputs](https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/packages-controls/input/docs/common-inputs.md) for multiple selection, numeric values, sliders, and editable tags.
|
|
16
26
|
|
|
17
27
|
[Component reference](docs/reference/README.md) contains focused API pages for each public component.
|
|
28
|
+
|
|
29
|
+
## Sizing and density
|
|
30
|
+
|
|
31
|
+
InlineEditor size defaults to medium and supplies the trigger, field/textarea and save/cancel action sizes. Explicit part sizes take precedence. Display text remains application content; changing size does not change draft, validation or focus ownership.
|
|
32
|
+
|
|
33
|
+
See the [shared sizing contract](https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/docs/usage/sizing.md)
|
|
34
|
+
for native attributes, scope precedence, tokens and target behavior.
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import { useLayoutEffect, useRef } from "react";
|
|
|
15
15
|
import { jsx } from "react/jsx-runtime";
|
|
16
16
|
var InlineEditor = (props) => {
|
|
17
17
|
const {
|
|
18
|
+
size = "medium",
|
|
18
19
|
editing,
|
|
19
20
|
onEditingChange,
|
|
20
21
|
value,
|
|
@@ -67,6 +68,7 @@ var InlineEditor = (props) => {
|
|
|
67
68
|
editorContext.Provider,
|
|
68
69
|
{
|
|
69
70
|
value: {
|
|
71
|
+
size,
|
|
70
72
|
editing,
|
|
71
73
|
busy,
|
|
72
74
|
disabled,
|
|
@@ -98,7 +100,7 @@ var InlineEditor = (props) => {
|
|
|
98
100
|
import { Button } from "@gridui/button";
|
|
99
101
|
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
100
102
|
var InlineEditorActions = (props) => {
|
|
101
|
-
const { busy, cancel, disabled, editing, submit, submitDisabled } = useEditor();
|
|
103
|
+
const { size, busy, cancel, disabled, editing, submit, submitDisabled } = useEditor();
|
|
102
104
|
if (!editing) {
|
|
103
105
|
return null;
|
|
104
106
|
}
|
|
@@ -111,7 +113,7 @@ var InlineEditorActions = (props) => {
|
|
|
111
113
|
Button,
|
|
112
114
|
{
|
|
113
115
|
type: "button",
|
|
114
|
-
size:
|
|
116
|
+
size: props.size ?? size,
|
|
115
117
|
disabled: disabled || busy || submitDisabled,
|
|
116
118
|
loading: busy,
|
|
117
119
|
onClick: submit,
|
|
@@ -122,7 +124,7 @@ var InlineEditorActions = (props) => {
|
|
|
122
124
|
Button,
|
|
123
125
|
{
|
|
124
126
|
type: "button",
|
|
125
|
-
size:
|
|
127
|
+
size: props.size ?? size,
|
|
126
128
|
variant: "quiet",
|
|
127
129
|
disabled: busy,
|
|
128
130
|
onClick: cancel,
|
|
@@ -160,7 +162,7 @@ import { useId, useImperativeHandle, useRef as useRef2 } from "react";
|
|
|
160
162
|
import { Fragment, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
161
163
|
var InlineEditorField = (props) => {
|
|
162
164
|
const { id, label, onKeyDown, ref, ...restProps } = props;
|
|
163
|
-
const { busy, cancel, disabled, editing, input, onValueChange, submit, value } = useEditor();
|
|
165
|
+
const { busy, cancel, disabled, editing, input, onValueChange, submit, value, size } = useEditor();
|
|
164
166
|
const generatedId = useId();
|
|
165
167
|
const inputId = id ?? generatedId;
|
|
166
168
|
const native = useRef2(null);
|
|
@@ -182,6 +184,7 @@ var InlineEditorField = (props) => {
|
|
|
182
184
|
Input,
|
|
183
185
|
{
|
|
184
186
|
...restProps,
|
|
187
|
+
size: restProps.size ?? size,
|
|
185
188
|
id: inputId,
|
|
186
189
|
ref: (element) => {
|
|
187
190
|
input.current = element;
|
|
@@ -239,6 +242,7 @@ var InlineEditorTextarea = (props) => {
|
|
|
239
242
|
{
|
|
240
243
|
autoSize: true,
|
|
241
244
|
...restProps,
|
|
245
|
+
size: restProps.size ?? editor.size,
|
|
242
246
|
id: inputId,
|
|
243
247
|
ref: (element) => {
|
|
244
248
|
native.current = element;
|
|
@@ -276,7 +280,7 @@ var InlineEditorTrigger = (props) => {
|
|
|
276
280
|
variant: "quiet"
|
|
277
281
|
} : props;
|
|
278
282
|
const { ref, size, ...restProps } = appearance;
|
|
279
|
-
const { busy, disabled, editing, start, trigger } = useEditor();
|
|
283
|
+
const { busy, disabled, editing, start, trigger, size: editorSize } = useEditor();
|
|
280
284
|
useImperativeHandle3(ref, () => {
|
|
281
285
|
return trigger.current;
|
|
282
286
|
});
|
|
@@ -287,7 +291,7 @@ var InlineEditorTrigger = (props) => {
|
|
|
287
291
|
Button2,
|
|
288
292
|
{
|
|
289
293
|
...restProps,
|
|
290
|
-
size: size ??
|
|
294
|
+
size: size ?? editorSize,
|
|
291
295
|
ref: trigger,
|
|
292
296
|
type: "button",
|
|
293
297
|
disabled: disabled || busy,
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/shared/editor-context.ts", "../src/inline-editor/inline-editor.tsx", "../src/inline-editor-actions/inline-editor-actions.tsx", "../src/inline-editor-display/inline-editor-display.tsx", "../src/inline-editor-field/inline-editor-field.tsx", "../src/inline-editor-textarea/inline-editor-textarea.tsx", "../src/inline-editor-trigger/inline-editor-trigger.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace Shared\n * @description Editor Context\n */\n\nimport { createContext, type RefObject, useContext } from \"react\";\n\nexport type EditorContext = {\n readonly editing: boolean;\n readonly busy: boolean;\n readonly disabled: boolean;\n readonly submitDisabled: boolean;\n readonly value: string;\n readonly input: RefObject<HTMLInputElement | HTMLTextAreaElement | null>;\n readonly trigger: RefObject<HTMLButtonElement | null>;\n readonly onValueChange: (value: string) => void;\n readonly start: () => void;\n readonly cancel: () => void;\n readonly submit: () => void;\n};\n\nexport const editorContext = createContext<EditorContext | null>(null);\n\nexport const useEditor = (): EditorContext => {\n const editor = useContext(editorContext);\n if (!editor) {\n throw new Error(\"InlineEditor parts require an InlineEditor.\");\n }\n return editor;\n};\n", "/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace InlineEditor\n * @description Inline Editor\n */\n\nimport { editorContext } from \"../shared/editor-context\";\nimport { cn } from \"@gridui/style-utils\";\nimport { type ComponentPropsWithRef, type FC, useLayoutEffect, useRef } from \"react\";\n\nexport type InlineEditorProps = Omit<ComponentPropsWithRef<\"div\">, \"onSubmit\" | \"onChange\"> & {\n readonly editing: boolean;\n readonly onEditingChange: (editing: boolean) => void;\n readonly value: string;\n readonly onValueChange: (value: string) => void;\n readonly onSubmit: (value: string) => void;\n readonly onCancel?: () => void;\n readonly busy?: boolean;\n readonly disabled?: boolean;\n readonly submitDisabled?: boolean;\n};\n\nexport const InlineEditor: FC<InlineEditorProps> = (props: InlineEditorProps) => {\n const { editing, onEditingChange, value, onValueChange, onSubmit, onCancel,\n busy = false, disabled = false, submitDisabled = false, children, className, ...restProps } = props;\n const input = useRef<HTMLInputElement | HTMLTextAreaElement>(null);\n const trigger = useRef<HTMLButtonElement>(null);\n const previousEditing = useRef(false);\n const restoreFocus = useRef(false);\n useLayoutEffect(() => {\n if (editing && !previousEditing.current) {\n restoreFocus.current = false;\n input.current?.focus();\n } else if (!editing && previousEditing.current) {\n restoreFocus.current = true;\n }\n if (!editing && restoreFocus.current && !busy && !disabled) {\n trigger.current?.focus();\n restoreFocus.current = false;\n }\n previousEditing.current = editing;\n }, [\n editing,\n busy,\n disabled,\n ]);\n const cancel = () => {\n onCancel?.();\n onEditingChange(false);\n };\n const submit = () => {\n const element = input.current;\n if (busy || disabled || submitDisabled || !element || element.matches(\":disabled\")) {\n return;\n }\n if (!element.reportValidity()) {\n return;\n }\n onSubmit(value);\n };\n\n return (<editorContext.Provider\n value={{\n editing,\n busy,\n disabled,\n submitDisabled,\n value,\n input,\n trigger,\n onValueChange,\n cancel,\n submit,\n start: () => {\n onEditingChange(true);\n },\n }}\n >\n <div\n {...restProps}\n className={cn(\"gridui-inline-editor\", className)}\n aria-busy={busy || undefined}\n >\n {children}\n </div>\n </editorContext.Provider>);\n};\n", "/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace InlineEditorActions\n * @description Inline Editor Actions\n */\n\nimport { useEditor } from \"../shared/editor-context\";\nimport { Button } from \"@gridui/button\";\nimport type { FC, ReactNode } from \"react\";\n\nexport type InlineEditorActionsProps = {\n readonly saveLabel: ReactNode;\n readonly cancelLabel: ReactNode;\n};\n\nexport const InlineEditorActions: FC<InlineEditorActionsProps> = (props: InlineEditorActionsProps) => {\n const { busy, cancel, disabled, editing, submit, submitDisabled } = useEditor();\n if (!editing) {\n return null;\n }\n return (<div\n className=\"gridui-inline-editor-actions\"\n >\n <Button\n type=\"button\"\n size=\"small\"\n disabled={disabled || busy || submitDisabled}\n loading={busy}\n onClick={submit}\n >\n {props.saveLabel}\n </Button>\n <Button\n type=\"button\"\n size=\"small\"\n variant=\"quiet\"\n disabled={busy}\n onClick={cancel}\n >\n {props.cancelLabel}\n </Button>\n </div>);\n};\n", "/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace InlineEditorDisplay\n * @description Inline Editor Display\n */\n\nimport { useEditor } from \"../shared/editor-context\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type InlineEditorDisplayProps = ComponentPropsWithRef<\"div\">;\n\nexport const InlineEditorDisplay: FC<InlineEditorDisplayProps> = (props: InlineEditorDisplayProps) => {\n const { editing } = useEditor();\n const { children, className, ...restProps } = props;\n if (editing || children === undefined || children === null) {\n return null;\n }\n return (<div\n {...restProps}\n className={cn(\"gridui-inline-editor-display\", className)}\n >\n {children}\n </div>);\n};\n", "/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace InlineEditorField\n * @description Inline Editor Field\n */\n\nimport { useEditor } from \"../shared/editor-context\";\nimport { Input, type InputProps } from \"@gridui/input\";\nimport { isComposingKeyEvent } from \"@gridui/interaction\";\nimport { type FC, useId, useImperativeHandle, useRef } from \"react\";\n\nexport type InlineEditorFieldProps = Omit<InputProps, \"value\" | \"defaultValue\" | \"onValueChange\" | \"disabled\"> & {\n readonly label: string;\n};\n\nexport const InlineEditorField: FC<InlineEditorFieldProps> = (props: InlineEditorFieldProps) => {\n const { id, label, onKeyDown, ref, ...restProps } = props;\n const { busy, cancel, disabled, editing, input, onValueChange, submit, value } = useEditor();\n const generatedId = useId();\n const inputId = id ?? generatedId;\n const native = useRef<HTMLInputElement>(null);\n useImperativeHandle(ref, () => {\n return native.current!;\n });\n if (!editing) {\n return null;\n }\n return (<>\n <label\n htmlFor={inputId}\n >\n {label}\n </label>\n <Input\n {...restProps}\n id={inputId}\n ref={(element) => {\n input.current = element; native.current = element;\n }}\n value={value}\n onValueChange={onValueChange}\n disabled={disabled || busy}\n onKeyDown={event => {\n onKeyDown?.(event);\n if (event.defaultPrevented || isComposingKeyEvent(event.nativeEvent) || busy || disabled) {\n return;\n }\n if (event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n cancel();\n } else if (event.key === \"Enter\") {\n event.preventDefault();\n submit();\n }\n }}\n />\n </>);\n};\n", "/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace InlineEditorTextarea\n * @description Inline Editor Textarea\n */\n\nimport { useEditor } from \"../shared/editor-context\";\nimport { Textarea, type TextareaProps } from \"@gridui/input\";\nimport { isComposingKeyEvent } from \"@gridui/interaction\";\nimport { type FC, useId, useImperativeHandle, useRef } from \"react\";\n\nexport type InlineEditorTextareaProps = Omit<TextareaProps, \"value\" | \"defaultValue\" | \"onValueChange\" | \"disabled\"> & {\n readonly label: string;\n};\nexport const InlineEditorTextarea: FC<InlineEditorTextareaProps> = (props: InlineEditorTextareaProps) => {\n const { id, label, onKeyDown, ref, ...restProps } = props;\n const editor = useEditor();\n const generatedId = useId();\n const inputId = id ?? generatedId;\n const native = useRef<HTMLTextAreaElement>(null);\n useImperativeHandle(ref, () => {\n return native.current!;\n });\n if (!editor.editing) {\n return null;\n }\n return (<>\n <label\n htmlFor={inputId}\n >\n {label}\n </label>\n <Textarea\n autoSize\n {...restProps}\n id={inputId}\n ref={(element) => {\n native.current = element; editor.input.current = element;\n }}\n value={editor.value}\n onValueChange={editor.onValueChange}\n disabled={editor.disabled || editor.busy}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (event.defaultPrevented || isComposingKeyEvent(event.nativeEvent) || editor.busy || editor.disabled) {\n return;\n }\n if (event.key === \"Escape\") {\n event.preventDefault(); event.stopPropagation(); editor.cancel();\n } else if (event.key === \"Enter\" && (event.ctrlKey || event.metaKey)) {\n event.preventDefault(); editor.submit();\n }\n }}\n />\n </>);\n};\n", "/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace InlineEditorTrigger\n * @description Inline Editor Trigger\n */\n\nimport { useEditor } from \"../shared/editor-context\";\nimport { Button, type ButtonProps, type ButtonVariants } from \"@gridui/button\";\nimport { type FC, useImperativeHandle } from \"react\";\n\nexport type InlineEditorTriggerProps = Omit<ButtonProps, \"disabled\" | \"loading\" | \"onClick\" | \"type\"> & ButtonVariants;\n\nexport const InlineEditorTrigger: FC<InlineEditorTriggerProps> = (props: InlineEditorTriggerProps) => {\n const appearance = props.variant === undefined || props.variant === null ? {\n ...props,\n variant: \"quiet\" as const,\n } : props;\n const { ref, size, ...restProps } = appearance;\n const { busy, disabled, editing, start, trigger } = useEditor();\n useImperativeHandle(ref, () => {\n return trigger.current!;\n });\n if (editing) {\n return null;\n }\n return (<Button\n {...restProps}\n size={size ?? \"small\"}\n ref={trigger}\n type=\"button\"\n disabled={disabled || busy}\n onClick={start}\n />);\n};\n"],
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace Shared\n * @description Editor Context\n */\n\nimport type { Size } from \"@gridui/theme\";\nimport { createContext, type RefObject, useContext } from \"react\";\n\nexport type EditorContext = {\n readonly size: Size;\n readonly editing: boolean;\n readonly busy: boolean;\n readonly disabled: boolean;\n readonly submitDisabled: boolean;\n readonly value: string;\n readonly input: RefObject<HTMLInputElement | HTMLTextAreaElement | null>;\n readonly trigger: RefObject<HTMLButtonElement | null>;\n readonly onValueChange: (value: string) => void;\n readonly start: () => void;\n readonly cancel: () => void;\n readonly submit: () => void;\n};\n\nexport const editorContext = createContext<EditorContext | null>(null);\n\nexport const useEditor = (): EditorContext => {\n const editor = useContext(editorContext);\n if (!editor) {\n throw new Error(\"InlineEditor parts require an InlineEditor.\");\n }\n return editor;\n};\n", "/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace InlineEditor\n * @description Inline Editor\n */\n\nimport type { Size } from \"@gridui/theme\";\nimport { editorContext } from \"../shared/editor-context\";\nimport { cn } from \"@gridui/style-utils\";\nimport { type ComponentPropsWithRef, type FC, useLayoutEffect, useRef } from \"react\";\n\nexport type InlineEditorProps = Omit<ComponentPropsWithRef<\"div\">, \"onSubmit\" | \"onChange\"> & {\n readonly size?: Size;\n readonly editing: boolean;\n readonly onEditingChange: (editing: boolean) => void;\n readonly value: string;\n readonly onValueChange: (value: string) => void;\n readonly onSubmit: (value: string) => void;\n readonly onCancel?: () => void;\n readonly busy?: boolean;\n readonly disabled?: boolean;\n readonly submitDisabled?: boolean;\n};\n\nexport const InlineEditor: FC<InlineEditorProps> = (props: InlineEditorProps) => {\n const { size = \"medium\", editing, onEditingChange, value, onValueChange, onSubmit, onCancel,\n busy = false, disabled = false, submitDisabled = false, children, className, ...restProps } = props;\n const input = useRef<HTMLInputElement | HTMLTextAreaElement>(null);\n const trigger = useRef<HTMLButtonElement>(null);\n const previousEditing = useRef(false);\n const restoreFocus = useRef(false);\n useLayoutEffect(() => {\n if (editing && !previousEditing.current) {\n restoreFocus.current = false;\n input.current?.focus();\n } else if (!editing && previousEditing.current) {\n restoreFocus.current = true;\n }\n if (!editing && restoreFocus.current && !busy && !disabled) {\n trigger.current?.focus();\n restoreFocus.current = false;\n }\n previousEditing.current = editing;\n }, [\n editing,\n busy,\n disabled,\n ]);\n const cancel = () => {\n onCancel?.();\n onEditingChange(false);\n };\n const submit = () => {\n const element = input.current;\n if (busy || disabled || submitDisabled || !element || element.matches(\":disabled\")) {\n return;\n }\n if (!element.reportValidity()) {\n return;\n }\n onSubmit(value);\n };\n\n return (<editorContext.Provider\n value={{\n size,\n editing,\n busy,\n disabled,\n submitDisabled,\n value,\n input,\n trigger,\n onValueChange,\n cancel,\n submit,\n start: () => {\n onEditingChange(true);\n },\n }}\n >\n <div\n {...restProps}\n className={cn(\"gridui-inline-editor\", className)}\n aria-busy={busy || undefined}\n >\n {children}\n </div>\n </editorContext.Provider>);\n};\n", "/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace InlineEditorActions\n * @description Inline Editor Actions\n */\n\nimport type { ActionSize } from \"@gridui/theme\";\nimport { useEditor } from \"../shared/editor-context\";\nimport { Button } from \"@gridui/button\";\nimport type { FC, ReactNode } from \"react\";\n\nexport type InlineEditorActionsProps = {\n readonly size?: ActionSize;\n readonly saveLabel: ReactNode;\n readonly cancelLabel: ReactNode;\n};\n\nexport const InlineEditorActions: FC<InlineEditorActionsProps> = (props: InlineEditorActionsProps) => {\n const { size, busy, cancel, disabled, editing, submit, submitDisabled } = useEditor();\n if (!editing) {\n return null;\n }\n return (<div\n className=\"gridui-inline-editor-actions\"\n >\n <Button\n type=\"button\"\n size={props.size ?? size}\n disabled={disabled || busy || submitDisabled}\n loading={busy}\n onClick={submit}\n >\n {props.saveLabel}\n </Button>\n <Button\n type=\"button\"\n size={props.size ?? size}\n variant=\"quiet\"\n disabled={busy}\n onClick={cancel}\n >\n {props.cancelLabel}\n </Button>\n </div>);\n};\n", "/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace InlineEditorDisplay\n * @description Inline Editor Display\n */\n\nimport { useEditor } from \"../shared/editor-context\";\nimport { cn } from \"@gridui/style-utils\";\nimport type { ComponentPropsWithRef, FC } from \"react\";\n\nexport type InlineEditorDisplayProps = ComponentPropsWithRef<\"div\">;\n\nexport const InlineEditorDisplay: FC<InlineEditorDisplayProps> = (props: InlineEditorDisplayProps) => {\n const { editing } = useEditor();\n const { children, className, ...restProps } = props;\n if (editing || children === undefined || children === null) {\n return null;\n }\n return (<div\n {...restProps}\n className={cn(\"gridui-inline-editor-display\", className)}\n >\n {children}\n </div>);\n};\n", "/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace InlineEditorField\n * @description Inline Editor Field\n */\n\nimport { useEditor } from \"../shared/editor-context\";\nimport { Input, type InputProps } from \"@gridui/input\";\nimport { isComposingKeyEvent } from \"@gridui/interaction\";\nimport { type FC, useId, useImperativeHandle, useRef } from \"react\";\n\nexport type InlineEditorFieldProps = Omit<InputProps, \"value\" | \"defaultValue\" | \"onValueChange\" | \"disabled\"> & {\n readonly label: string;\n};\n\nexport const InlineEditorField: FC<InlineEditorFieldProps> = (props: InlineEditorFieldProps) => {\n const { id, label, onKeyDown, ref, ...restProps } = props;\n const { busy, cancel, disabled, editing, input, onValueChange, submit, value, size } = useEditor();\n const generatedId = useId();\n const inputId = id ?? generatedId;\n const native = useRef<HTMLInputElement>(null);\n useImperativeHandle(ref, () => {\n return native.current!;\n });\n if (!editing) {\n return null;\n }\n return (<>\n <label\n htmlFor={inputId}\n >\n {label}\n </label>\n <Input\n {...restProps}\n size={restProps.size ?? size}\n id={inputId}\n ref={(element) => {\n input.current = element; native.current = element;\n }}\n value={value}\n onValueChange={onValueChange}\n disabled={disabled || busy}\n onKeyDown={event => {\n onKeyDown?.(event);\n if (event.defaultPrevented || isComposingKeyEvent(event.nativeEvent) || busy || disabled) {\n return;\n }\n if (event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n cancel();\n } else if (event.key === \"Enter\") {\n event.preventDefault();\n submit();\n }\n }}\n />\n </>);\n};\n", "/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace InlineEditorTextarea\n * @description Inline Editor Textarea\n */\n\nimport { useEditor } from \"../shared/editor-context\";\nimport { Textarea, type TextareaProps } from \"@gridui/input\";\nimport { isComposingKeyEvent } from \"@gridui/interaction\";\nimport { type FC, useId, useImperativeHandle, useRef } from \"react\";\n\nexport type InlineEditorTextareaProps = Omit<TextareaProps, \"value\" | \"defaultValue\" | \"onValueChange\" | \"disabled\"> & {\n readonly label: string;\n};\nexport const InlineEditorTextarea: FC<InlineEditorTextareaProps> = (props: InlineEditorTextareaProps) => {\n const { id, label, onKeyDown, ref, ...restProps } = props;\n const editor = useEditor();\n const generatedId = useId();\n const inputId = id ?? generatedId;\n const native = useRef<HTMLTextAreaElement>(null);\n useImperativeHandle(ref, () => {\n return native.current!;\n });\n if (!editor.editing) {\n return null;\n }\n return (<>\n <label\n htmlFor={inputId}\n >\n {label}\n </label>\n <Textarea\n autoSize\n {...restProps}\n size={restProps.size ?? editor.size}\n id={inputId}\n ref={(element) => {\n native.current = element; editor.input.current = element;\n }}\n value={editor.value}\n onValueChange={editor.onValueChange}\n disabled={editor.disabled || editor.busy}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (event.defaultPrevented || isComposingKeyEvent(event.nativeEvent) || editor.busy || editor.disabled) {\n return;\n }\n if (event.key === \"Escape\") {\n event.preventDefault(); event.stopPropagation(); editor.cancel();\n } else if (event.key === \"Enter\" && (event.ctrlKey || event.metaKey)) {\n event.preventDefault(); editor.submit();\n }\n }}\n />\n </>);\n};\n", "/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace InlineEditorTrigger\n * @description Inline Editor Trigger\n */\n\nimport { useEditor } from \"../shared/editor-context\";\nimport { Button, type ButtonProps, type ButtonVariants } from \"@gridui/button\";\nimport { type FC, useImperativeHandle } from \"react\";\n\nexport type InlineEditorTriggerProps = Omit<ButtonProps, \"disabled\" | \"loading\" | \"onClick\" | \"type\"> & ButtonVariants;\n\nexport const InlineEditorTrigger: FC<InlineEditorTriggerProps> = (props: InlineEditorTriggerProps) => {\n const appearance = props.variant === undefined || props.variant === null ? {\n ...props,\n variant: \"quiet\" as const,\n } : props;\n const { ref, size, ...restProps } = appearance;\n const { busy, disabled, editing, start, trigger, size: editorSize } = useEditor();\n useImperativeHandle(ref, () => {\n return trigger.current!;\n });\n if (editing) {\n return null;\n }\n return (<Button\n {...restProps}\n size={size ?? editorSize}\n ref={trigger}\n type=\"button\"\n disabled={disabled || busy}\n onClick={start}\n />);\n};\n"],
|
|
5
|
+
"mappings": ";AAQA,SAAS,eAA+B,kBAAkB;AAiBnD,IAAM,gBAAgB,cAAoC,IAAI;AAE9D,IAAM,YAAY,MAAqB;AAC1C,QAAM,SAAS,WAAW,aAAa;AACvC,MAAI,CAAC,QAAQ;AACT,UAAM,IAAI,MAAM,6CAA6C;AAAA,EACjE;AACA,SAAO;AACX;;;ACxBA,SAAS,UAAU;AACnB,SAA8C,iBAAiB,cAAc;AAwErE;AAzDD,IAAM,eAAsC,CAAC,UAA6B;AAC7E,QAAM;AAAA,IAAE,OAAO;AAAA,IAAU;AAAA,IAAS;AAAA,IAAiB;AAAA,IAAO;AAAA,IAAe;AAAA,IAAU;AAAA,IAC/E,OAAO;AAAA,IAAO,WAAW;AAAA,IAAO,iBAAiB;AAAA,IAAO;AAAA,IAAU;AAAA,IAAW,GAAG;AAAA,EAAU,IAAI;AAClG,QAAM,QAAQ,OAA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,UAAU,IAAI;AACpC,QAAM,EAAE,MAAM,UAAU,SAAS,OAAO,SAAS,MAAM,WAAW,IAAI,UAAU;AAChF,EAAAD,qBAAoB,KAAK,MAAM;AAC3B,WAAO,QAAQ;AAAA,EACnB,CAAC;AACD,MAAI,SAAS;AACT,WAAO;AAAA,EACX;AACA,SAAQ,gBAAAC;AAAA,IAACF;AAAA,IAAA;AAAA,MACJ,GAAG;AAAA,MACJ,MAAM,QAAQ;AAAA,MACd,KAAK;AAAA,MACL,MAAK;AAAA,MACL,UAAU,YAAY;AAAA,MACtB,SAAS;AAAA;AAAA,EACb;AACJ;",
|
|
6
6
|
"names": ["jsx", "cn", "jsx", "useRef", "jsx", "jsxs", "isComposingKeyEvent", "useId", "useImperativeHandle", "useRef", "Fragment", "jsx", "jsxs", "Button", "useImperativeHandle", "jsx"]
|
|
7
7
|
}
|
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
* @namespace InlineEditor
|
|
5
5
|
* @description Inline Editor
|
|
6
6
|
*/
|
|
7
|
+
import type { Size } from "@gridui/theme";
|
|
7
8
|
import { type ComponentPropsWithRef, type FC } from "react";
|
|
8
9
|
export type InlineEditorProps = Omit<ComponentPropsWithRef<"div">, "onSubmit" | "onChange"> & {
|
|
10
|
+
readonly size?: Size;
|
|
9
11
|
readonly editing: boolean;
|
|
10
12
|
readonly onEditingChange: (editing: boolean) => void;
|
|
11
13
|
readonly value: string;
|
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
* @namespace InlineEditorActions
|
|
5
5
|
* @description Inline Editor Actions
|
|
6
6
|
*/
|
|
7
|
+
import type { ActionSize } from "@gridui/theme";
|
|
7
8
|
import type { FC, ReactNode } from "react";
|
|
8
9
|
export type InlineEditorActionsProps = {
|
|
10
|
+
readonly size?: ActionSize;
|
|
9
11
|
readonly saveLabel: ReactNode;
|
|
10
12
|
readonly cancelLabel: ReactNode;
|
|
11
13
|
};
|
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
* @namespace Shared
|
|
5
5
|
* @description Editor Context
|
|
6
6
|
*/
|
|
7
|
+
import type { Size } from "@gridui/theme";
|
|
7
8
|
import { type RefObject } from "react";
|
|
8
9
|
export type EditorContext = {
|
|
10
|
+
readonly size: Size;
|
|
9
11
|
readonly editing: boolean;
|
|
10
12
|
readonly busy: boolean;
|
|
11
13
|
readonly disabled: boolean;
|
package/dist/styled.js
ADDED