@gridui/inline-editor 1.0.3 → 1.0.5
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 +2 -1
- package/dist/index.js.map +2 -2
- package/dist/styles.css +1 -1
- package/docs/catalog.json +34 -0
- package/package.json +7 -6
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/inline-editor/inline-editor.tsx
|
|
2
2
|
import { Button } from "@gridui/button";
|
|
3
3
|
import { Input } from "@gridui/input";
|
|
4
|
+
import { isComposingKeyEvent } from "@gridui/interaction";
|
|
4
5
|
import { cn } from "@gridui/style-utils";
|
|
5
6
|
import { useId, useImperativeHandle, useLayoutEffect, useRef } from "react";
|
|
6
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -97,7 +98,7 @@ var InlineEditor = (props) => {
|
|
|
97
98
|
onValueChange,
|
|
98
99
|
disabled: disabled || busy,
|
|
99
100
|
onKeyDown: (event) => {
|
|
100
|
-
if (event.nativeEvent
|
|
101
|
+
if (isComposingKeyEvent(event.nativeEvent) || busy || disabled) {
|
|
101
102
|
return;
|
|
102
103
|
}
|
|
103
104
|
if (event.key === "Escape") {
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/inline-editor/inline-editor.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace InlineEditor\n * @description Inline Editor\n */\n\nimport { Button, type ButtonProps, type ButtonVariants } from \"@gridui/button\";\nimport { Input, type InputProps } from \"@gridui/input\";\nimport { cn } from \"@gridui/style-utils\";\nimport { type ComponentPropsWithRef, type FC, type ReactNode, useId, useImperativeHandle, useLayoutEffect, useRef } from \"react\";\n\nexport type InlineEditorProps = Omit<ComponentPropsWithRef<\"div\">, \"children\" | \"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 readonly display: ReactNode;\n readonly label: string;\n readonly editLabel: string;\n readonly saveLabel: string;\n readonly cancelLabel: string;\n readonly feedback?: ReactNode;\n readonly editButtonProps?: Omit<ButtonProps, \"children\" | \"disabled\" | \"loading\" | \"onClick\" | \"type\"> & ButtonVariants;\n readonly inputProps?: Omit<InputProps, \"value\" | \"defaultValue\" | \"onValueChange\" | \"disabled\" | \"onKeyDown\">;\n};\n\nexport const InlineEditor: FC<InlineEditorProps> = (props: InlineEditorProps) => {\n const {\n editing,\n onEditingChange,\n value,\n onValueChange,\n onSubmit,\n onCancel,\n busy = false,\n disabled = false,\n submitDisabled = false,\n display,\n label,\n editLabel,\n saveLabel,\n cancelLabel,\n feedback,\n editButtonProps,\n inputProps,\n className,\n ...restProps\n } = props;\n const input = useRef<HTMLInputElement>(null);\n const trigger = useRef<HTMLButtonElement>(null);\n const previousEditing = useRef(false);\n const restoreFocus = useRef(false);\n const generatedId = useId();\n const inputId = inputProps?.id ?? generatedId;\n // The native input is attached before the imperative handle is assigned.\n useImperativeHandle(inputProps?.ref, () => {\n return input.current!;\n });\n useImperativeHandle(editButtonProps?.ref, () => {\n return trigger.current!;\n });\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 const editAppearance: ButtonProps = editButtonProps\n && editButtonProps.variant !== undefined\n && editButtonProps.variant !== null\n ? editButtonProps\n : {\n ...editButtonProps,\n variant: \"quiet\",\n };\n return (<div\n {...restProps}\n className={cn(\"gridui-inline-editor\", className)}\n aria-busy={busy || undefined}\n >\n {editing ? (<>\n <label\n htmlFor={inputId}\n >\n {label}\n </label>\n <Input\n {...inputProps}\n id={inputId}\n ref={input}\n value={value}\n onValueChange={onValueChange}\n disabled={disabled || busy}\n onKeyDown={(event) => {\n if (event.nativeEvent
|
|
5
|
-
"mappings": ";AAOA,SAAS,cAAqD;AAC9D,SAAS,aAA8B;AACvC,SAAS,UAAU;AACnB,SAA8D,OAAO,qBAAqB,iBAAiB,cAAc;AAqGrG,mBACR,KA0BA,YA3BQ;AA/Eb,IAAM,eAAsC,CAAC,UAA6B;AAC7E,QAAM;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP,WAAW;AAAA,IACX,iBAAiB;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACP,IAAI;AACJ,QAAM,QAAQ,OAAyB,IAAI;AAC3C,QAAM,UAAU,OAA0B,IAAI;AAC9C,QAAM,kBAAkB,OAAO,KAAK;AACpC,QAAM,eAAe,OAAO,KAAK;AACjC,QAAM,cAAc,MAAM;AAC1B,QAAM,UAAU,YAAY,MAAM;AAElC,sBAAoB,YAAY,KAAK,MAAM;AACvC,WAAO,MAAM;AAAA,EACjB,CAAC;AACD,sBAAoB,iBAAiB,KAAK,MAAM;AAC5C,WAAO,QAAQ;AAAA,EACnB,CAAC;AACD,kBAAgB,MAAM;AAClB,QAAI,WAAW,CAAC,gBAAgB,SAAS;AACrC,mBAAa,UAAU;AACvB,YAAM,SAAS,MAAM;AAAA,IACzB,WAAW,CAAC,WAAW,gBAAgB,SAAS;AAC5C,mBAAa,UAAU;AAAA,IAC3B;AACA,QAAI,CAAC,WAAW,aAAa,WAAW,CAAC,QAAQ,CAAC,UAAU;AACxD,cAAQ,SAAS,MAAM;AACvB,mBAAa,UAAU;AAAA,IAC3B;AACA,oBAAgB,UAAU;AAAA,EAC9B,GAAG;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,EACJ,CAAC;AACD,QAAM,SAAS,MAAM;AACjB,eAAW;AACX,oBAAgB,KAAK;AAAA,EACzB;AACA,QAAM,SAAS,MAAM;AACjB,UAAM,UAAU,MAAM;AACtB,QAAI,QAAQ,YAAY,kBAAkB,CAAC,WAAW,QAAQ,QAAQ,WAAW,GAAG;AAChF;AAAA,IACJ;AACA,QAAI,CAAC,QAAQ,eAAe,GAAG;AAC3B;AAAA,IACJ;AACA,aAAS,KAAK;AAAA,EAClB;AACA,QAAM,iBAA8B,mBAC7B,gBAAgB,YAAY,UAC5B,gBAAgB,YAAY,OAC7B,kBACA;AAAA,IACE,GAAG;AAAA,IACH,SAAS;AAAA,EACb;AACJ,SAAQ;AAAA,IAAC;AAAA;AAAA,MACJ,GAAG;AAAA,MACJ,WAAW,GAAG,wBAAwB,SAAS;AAAA,MAC/C,aAAW,QAAQ;AAAA,MAElB,oBAAW,iCACR;AAAA;AAAA,UAAC;AAAA;AAAA,YACG,SAAS;AAAA,YAER;AAAA;AAAA,QACL;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACI,GAAG;AAAA,YACJ,IAAI;AAAA,YACJ,KAAK;AAAA,YACL;AAAA,YACA;AAAA,YACA,UAAU,YAAY;AAAA,YACtB,WAAW,CAAC,UAAU;AAClB,kBAAI,MAAM,
|
|
4
|
+
"sourcesContent": ["/**\n * @author WMXPY\n * @package Inline Editor\n * @namespace InlineEditor\n * @description Inline Editor\n */\n\nimport { Button, type ButtonProps, type ButtonVariants } from \"@gridui/button\";\nimport { Input, type InputProps } from \"@gridui/input\";\nimport { isComposingKeyEvent } from \"@gridui/interaction\";\nimport { cn } from \"@gridui/style-utils\";\nimport { type ComponentPropsWithRef, type FC, type ReactNode, useId, useImperativeHandle, useLayoutEffect, useRef } from \"react\";\n\nexport type InlineEditorProps = Omit<ComponentPropsWithRef<\"div\">, \"children\" | \"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 readonly display: ReactNode;\n readonly label: string;\n readonly editLabel: string;\n readonly saveLabel: string;\n readonly cancelLabel: string;\n readonly feedback?: ReactNode;\n readonly editButtonProps?: Omit<ButtonProps, \"children\" | \"disabled\" | \"loading\" | \"onClick\" | \"type\"> & ButtonVariants;\n readonly inputProps?: Omit<InputProps, \"value\" | \"defaultValue\" | \"onValueChange\" | \"disabled\" | \"onKeyDown\">;\n};\n\nexport const InlineEditor: FC<InlineEditorProps> = (props: InlineEditorProps) => {\n const {\n editing,\n onEditingChange,\n value,\n onValueChange,\n onSubmit,\n onCancel,\n busy = false,\n disabled = false,\n submitDisabled = false,\n display,\n label,\n editLabel,\n saveLabel,\n cancelLabel,\n feedback,\n editButtonProps,\n inputProps,\n className,\n ...restProps\n } = props;\n const input = useRef<HTMLInputElement>(null);\n const trigger = useRef<HTMLButtonElement>(null);\n const previousEditing = useRef(false);\n const restoreFocus = useRef(false);\n const generatedId = useId();\n const inputId = inputProps?.id ?? generatedId;\n // The native input is attached before the imperative handle is assigned.\n useImperativeHandle(inputProps?.ref, () => {\n return input.current!;\n });\n useImperativeHandle(editButtonProps?.ref, () => {\n return trigger.current!;\n });\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 const editAppearance: ButtonProps = editButtonProps\n && editButtonProps.variant !== undefined\n && editButtonProps.variant !== null\n ? editButtonProps\n : {\n ...editButtonProps,\n variant: \"quiet\",\n };\n return (<div\n {...restProps}\n className={cn(\"gridui-inline-editor\", className)}\n aria-busy={busy || undefined}\n >\n {editing ? (<>\n <label\n htmlFor={inputId}\n >\n {label}\n </label>\n <Input\n {...inputProps}\n id={inputId}\n ref={input}\n value={value}\n onValueChange={onValueChange}\n disabled={disabled || busy}\n onKeyDown={(event) => {\n if (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 <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 {saveLabel}\n </Button>\n <Button\n type=\"button\"\n size=\"small\"\n variant=\"quiet\"\n disabled={busy}\n onClick={cancel}\n >\n {cancelLabel}\n </Button>\n </div>\n {feedback}\n </>) : (<>\n {display !== null && display !== undefined && (<div\n className=\"gridui-inline-editor-display\"\n >\n {display}\n </div>)}\n <Button\n {...editAppearance}\n type=\"button\"\n ref={trigger}\n size={editButtonProps?.size ?? \"small\"}\n disabled={disabled || busy}\n onClick={() => {\n onEditingChange(true);\n }}\n >\n {editLabel}\n </Button>\n </>)}\n </div>);\n};\n"],
|
|
5
|
+
"mappings": ";AAOA,SAAS,cAAqD;AAC9D,SAAS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L,SAAQ;AAAA,kBACR,UAAU;AAAA,kBACV,SAAS;AAAA,kBAER;AAAA;AAAA,cACL;AAAA;AAAA;AAAA,QACJ;AAAA,QACC;AAAA,SACL,IAAQ,iCACH;AAAA,oBAAY,QAAQ,YAAY,UAAc;AAAA,UAAC;AAAA;AAAA,YAC5C,WAAU;AAAA,YAET;AAAA;AAAA,QACL;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACI,GAAG;AAAA,YACJ,MAAK;AAAA,YACL,KAAK;AAAA,YACL,MAAM,iBAAiB,QAAQ;AAAA,YAC/B,UAAU,YAAY;AAAA,YACtB,SAAS,MAAM;AACX,8BAAgB,IAAI;AAAA,YACxB;AAAA,YAEC;AAAA;AAAA,QACL;AAAA,SACJ;AAAA;AAAA,EACJ;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/styles.css
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"name": "@gridui/inline-editor",
|
|
4
|
+
"version": "1.0.5",
|
|
5
|
+
"category": "core",
|
|
6
|
+
"description": "GridUI React inline editor",
|
|
7
|
+
"usage": "GridUI React inline editor",
|
|
8
|
+
"documentation": [
|
|
9
|
+
"README.md",
|
|
10
|
+
"docs/inline-editor.md"
|
|
11
|
+
],
|
|
12
|
+
"exports": [
|
|
13
|
+
{
|
|
14
|
+
"name": "InlineEditor",
|
|
15
|
+
"kind": "component",
|
|
16
|
+
"importPath": "@gridui/inline-editor"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "InlineEditorProps",
|
|
20
|
+
"kind": "type",
|
|
21
|
+
"importPath": "@gridui/inline-editor"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"styles": [
|
|
25
|
+
"@gridui/theme/styles.css",
|
|
26
|
+
"@gridui/button/styles.css",
|
|
27
|
+
"@gridui/overlay/styles.css",
|
|
28
|
+
"@gridui/input/styles.css",
|
|
29
|
+
"@gridui/inline-editor/styles.css"
|
|
30
|
+
],
|
|
31
|
+
"examples": [
|
|
32
|
+
"https://github.com/sudo-ui/GridUI-React-Monorepo/blob/main/packages-core/inline-editor/stories/inline-editor.stories.tsx"
|
|
33
|
+
]
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gridui/inline-editor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "GridUI React inline editor",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -27,15 +27,16 @@
|
|
|
27
27
|
"react-dom": "^19.2.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@gridui/button": "^3.
|
|
31
|
-
"@gridui/input": "^1.1.
|
|
32
|
-
"@gridui/
|
|
33
|
-
"@gridui/
|
|
30
|
+
"@gridui/button": "^3.1.2",
|
|
31
|
+
"@gridui/input": "^1.1.6",
|
|
32
|
+
"@gridui/interaction": "^1.2.1",
|
|
33
|
+
"@gridui/style-utils": "^2.2.2",
|
|
34
|
+
"@gridui/theme": "^2.5.3"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@gridui-internal/configuration": "0.0.0-internal",
|
|
37
38
|
"@jest/globals": "30.5.2",
|
|
38
|
-
"@storybook/react-vite": "10.6.
|
|
39
|
+
"@storybook/react-vite": "10.6.6",
|
|
39
40
|
"@types/jest": "30.0.0",
|
|
40
41
|
"@types/node": "26.6.6",
|
|
41
42
|
"@types/react": "19.3.0",
|