@gridui/inline-editor 0.0.0-stage → 1.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 CHANGED
@@ -1,3 +1,15 @@
1
- # Temporary Holding Version
1
+ # @gridui/inline-editor
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Core family. Public API: `InlineEditor`, `InlineEditorProps`.
4
+
5
+ Import components from `@gridui/inline-editor` and load `@gridui/inline-editor/styles.css` after Theme.
6
+ Load styles for any composed dependency used by this family. Applications own routes, labels, state persistence, and branding.
7
+
8
+ See [component ownership](../../docs/component-ownership.md) and [release history](.changeset/history/).
9
+
10
+ ## Controlled inline editing
11
+
12
+ See [InlineEditor](docs/inline-editor.md) for editing state and submission ownership,
13
+ and [Textarea](../input/docs/textarea.md#optional-automatic-height) for optional automatic height.
14
+
15
+ See [common inputs](../input/docs/common-inputs.md) for multiple selection, numeric values, sliders, and editable tags.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package Inline Editor
4
+ * @namespace Root
5
+ * @description Index
6
+ */
7
+ export type { InlineEditorProps } from "./inline-editor/inline-editor";
8
+ export { InlineEditor } from "./inline-editor/inline-editor";
package/dist/index.js ADDED
@@ -0,0 +1,174 @@
1
+ // src/inline-editor/inline-editor.tsx
2
+ import { Button } from "@gridui/button";
3
+ import { Input } from "@gridui/input";
4
+ import { cn } from "@gridui/style-utils";
5
+ import { useId, useImperativeHandle, useLayoutEffect, useRef } from "react";
6
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ var InlineEditor = (props) => {
8
+ const {
9
+ editing,
10
+ onEditingChange,
11
+ value,
12
+ onValueChange,
13
+ onSubmit,
14
+ onCancel,
15
+ busy = false,
16
+ disabled = false,
17
+ submitDisabled = false,
18
+ display,
19
+ label,
20
+ editLabel,
21
+ saveLabel,
22
+ cancelLabel,
23
+ feedback,
24
+ editButtonProps,
25
+ inputProps,
26
+ className,
27
+ ...restProps
28
+ } = props;
29
+ const input = useRef(null);
30
+ const trigger = useRef(null);
31
+ const previousEditing = useRef(false);
32
+ const restoreFocus = useRef(false);
33
+ const generatedId = useId();
34
+ const inputId = inputProps?.id ?? generatedId;
35
+ useImperativeHandle(inputProps?.ref, () => {
36
+ return input.current;
37
+ });
38
+ useImperativeHandle(editButtonProps?.ref, () => {
39
+ return trigger.current;
40
+ });
41
+ useLayoutEffect(() => {
42
+ if (editing && !previousEditing.current) {
43
+ restoreFocus.current = false;
44
+ input.current?.focus();
45
+ } else if (!editing && previousEditing.current) {
46
+ restoreFocus.current = true;
47
+ }
48
+ if (!editing && restoreFocus.current && !busy && !disabled) {
49
+ trigger.current?.focus();
50
+ restoreFocus.current = false;
51
+ }
52
+ previousEditing.current = editing;
53
+ }, [
54
+ editing,
55
+ busy,
56
+ disabled
57
+ ]);
58
+ const cancel = () => {
59
+ onCancel?.();
60
+ onEditingChange(false);
61
+ };
62
+ const submit = () => {
63
+ const element = input.current;
64
+ if (busy || disabled || submitDisabled || !element || element.matches(":disabled")) {
65
+ return;
66
+ }
67
+ if (!element.reportValidity()) {
68
+ return;
69
+ }
70
+ onSubmit(value);
71
+ };
72
+ const editAppearance = editButtonProps && editButtonProps.variant !== void 0 && editButtonProps.variant !== null ? editButtonProps : {
73
+ ...editButtonProps,
74
+ variant: "quiet"
75
+ };
76
+ return /* @__PURE__ */ jsx(
77
+ "div",
78
+ {
79
+ ...restProps,
80
+ className: cn("gridui-inline-editor", className),
81
+ "aria-busy": busy || void 0,
82
+ children: editing ? /* @__PURE__ */ jsxs(Fragment, { children: [
83
+ /* @__PURE__ */ jsx(
84
+ "label",
85
+ {
86
+ htmlFor: inputId,
87
+ children: label
88
+ }
89
+ ),
90
+ /* @__PURE__ */ jsx(
91
+ Input,
92
+ {
93
+ ...inputProps,
94
+ id: inputId,
95
+ ref: input,
96
+ value,
97
+ onValueChange,
98
+ disabled: disabled || busy,
99
+ onKeyDown: (event) => {
100
+ if (event.nativeEvent.isComposing || busy || disabled) {
101
+ return;
102
+ }
103
+ if (event.key === "Escape") {
104
+ event.preventDefault();
105
+ event.stopPropagation();
106
+ cancel();
107
+ } else if (event.key === "Enter") {
108
+ event.preventDefault();
109
+ submit();
110
+ }
111
+ }
112
+ }
113
+ ),
114
+ /* @__PURE__ */ jsxs(
115
+ "div",
116
+ {
117
+ className: "gridui-inline-editor-actions",
118
+ children: [
119
+ /* @__PURE__ */ jsx(
120
+ Button,
121
+ {
122
+ type: "button",
123
+ size: "small",
124
+ disabled: disabled || busy || submitDisabled,
125
+ loading: busy,
126
+ onClick: submit,
127
+ children: saveLabel
128
+ }
129
+ ),
130
+ /* @__PURE__ */ jsx(
131
+ Button,
132
+ {
133
+ type: "button",
134
+ size: "small",
135
+ variant: "quiet",
136
+ disabled: busy,
137
+ onClick: cancel,
138
+ children: cancelLabel
139
+ }
140
+ )
141
+ ]
142
+ }
143
+ ),
144
+ feedback
145
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
146
+ display !== null && display !== void 0 && /* @__PURE__ */ jsx(
147
+ "div",
148
+ {
149
+ className: "gridui-inline-editor-display",
150
+ children: display
151
+ }
152
+ ),
153
+ /* @__PURE__ */ jsx(
154
+ Button,
155
+ {
156
+ ...editAppearance,
157
+ type: "button",
158
+ ref: trigger,
159
+ size: editButtonProps?.size ?? "small",
160
+ disabled: disabled || busy,
161
+ onClick: () => {
162
+ onEditingChange(true);
163
+ },
164
+ children: editLabel
165
+ }
166
+ )
167
+ ] })
168
+ }
169
+ );
170
+ };
171
+ export {
172
+ InlineEditor
173
+ };
174
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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.isComposing || 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,aAA8B;AACvC,SAAS,UAAU;AAC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AAA;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
+ "names": []
7
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package Inline Editor
4
+ * @namespace InlineEditor
5
+ * @description Inline Editor
6
+ */
7
+ import { type ButtonProps, type ButtonVariants } from "@gridui/button";
8
+ import { type InputProps } from "@gridui/input";
9
+ import { type ComponentPropsWithRef, type FC, type ReactNode } from "react";
10
+ export type InlineEditorProps = Omit<ComponentPropsWithRef<"div">, "children" | "onSubmit" | "onChange"> & {
11
+ readonly editing: boolean;
12
+ readonly onEditingChange: (editing: boolean) => void;
13
+ readonly value: string;
14
+ readonly onValueChange: (value: string) => void;
15
+ readonly onSubmit: (value: string) => void;
16
+ readonly onCancel?: () => void;
17
+ readonly busy?: boolean;
18
+ readonly disabled?: boolean;
19
+ readonly submitDisabled?: boolean;
20
+ readonly display: ReactNode;
21
+ readonly label: string;
22
+ readonly editLabel: string;
23
+ readonly saveLabel: string;
24
+ readonly cancelLabel: string;
25
+ readonly feedback?: ReactNode;
26
+ readonly editButtonProps?: Omit<ButtonProps, "children" | "disabled" | "loading" | "onClick" | "type"> & ButtonVariants;
27
+ readonly inputProps?: Omit<InputProps, "value" | "defaultValue" | "onValueChange" | "disabled" | "onKeyDown">;
28
+ };
29
+ export declare const InlineEditor: FC<InlineEditorProps>;
@@ -0,0 +1,25 @@
1
+ /*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */
2
+ @layer theme, base, components, utilities;
3
+ @layer utilities;
4
+ @layer components {
5
+ .gridui-inline-editor {
6
+ display: flex;
7
+ flex-wrap: wrap;
8
+ align-items: center;
9
+ gap: var(--gridui-space-8);
10
+ min-width: 0;
11
+ }
12
+ .gridui-inline-editor > label {
13
+ width: 100%;
14
+ }
15
+ .gridui-inline-editor-display {
16
+ flex: 1;
17
+ min-width: 0;
18
+ overflow-wrap: anywhere;
19
+ }
20
+ .gridui-inline-editor-actions {
21
+ display: flex;
22
+ flex-wrap: wrap;
23
+ gap: var(--gridui-space-8);
24
+ }
25
+ }
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@gridui/inline-editor",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "GridUI React inline editor",
5
+ "license": "UNLICENSED",
6
+ "type": "module",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "sideEffects": [
12
+ "**/*.css"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ },
19
+ "./styles.css": "./dist/styles.css"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "peerDependencies": {
25
+ "react": "^19.2.0",
26
+ "react-dom": "^19.2.0"
27
+ },
28
+ "dependencies": {
29
+ "@gridui/button": "^2.1.1",
30
+ "@gridui/input": "^1.0.0",
31
+ "@gridui/style-utils": "^2.1.2",
32
+ "@gridui/theme": "^2.1.2"
33
+ },
34
+ "devDependencies": {
35
+ "@gridui-internal/configuration": "0.0.0",
36
+ "@jest/globals": "30.5.2",
37
+ "@types/jest": "30.0.0",
38
+ "@types/node": "26.6.5",
39
+ "@types/react": "19.3.0",
40
+ "@types/react-dom": "19.3.0",
41
+ "jest": "30.5.2",
42
+ "react": "19.3.1",
43
+ "react-dom": "19.3.1",
44
+ "typescript": "6.0.3"
45
+ },
46
+ "scripts": {
47
+ "build": "node ../../scripts/compilation/package.ts",
48
+ "compile": "tsc --project tsconfig.json",
49
+ "test": "jest",
50
+ "coverage": "jest --coverage"
51
+ }
6
52
  }