@devtools-ui/input 0.4.0 → 0.4.1-next.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 +102 -0
- package/dist/cjs/index.cjs +4 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -13
- package/src/dsl/Input.tsx +1 -1
- package/src/dsl/__tests__/Input.test.tsx +1 -1
- package/types/dsl/Input.d.ts +1 -1
- package/types/types/index.d.ts +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# @devtools-ui/input
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
`@devtools-ui/input` is a component package designed to be leveraged by a [Player-UI assets plugin](https://player-ui.github.io/next/plugins).
|
|
6
|
+
|
|
7
|
+
It provides an `Input` component that can be used to acquire data from the user.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
To install `@devtools-ui/input`, you can use pnpm or yarn:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pnpm i @devtools-ui/input
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
or
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
yarn add @devtools-ui/input
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
You can leverage this asset through the `@devtools-ui/plugin`:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { Input } from "@devtools-ui/plugin";
|
|
29
|
+
|
|
30
|
+
// and use it to define your Player-UI content:
|
|
31
|
+
myFlow = {
|
|
32
|
+
id: "my_flow",
|
|
33
|
+
views: [
|
|
34
|
+
<MyView>
|
|
35
|
+
<Input
|
|
36
|
+
size={"md"}
|
|
37
|
+
placeholder={"User input"}
|
|
38
|
+
maxLength={10}
|
|
39
|
+
binding={b`binding`}
|
|
40
|
+
>
|
|
41
|
+
<Input.Label>Label</Input.Label>
|
|
42
|
+
<Input.Note>Some note</Input.Note>
|
|
43
|
+
</Input>
|
|
44
|
+
</MyView>,
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
For more information on how to author Player-UI content using DSL, please check our [Player-UI docs](https://player-ui.github.io/next/dsl#tsxjsx-content-authoring-player-dsl).
|
|
50
|
+
|
|
51
|
+
Or, your can leverage this asset in your own plugin:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
// TransformPlugin.ts
|
|
55
|
+
import type { Player, PlayerPlugin } from "@player-ui/player";
|
|
56
|
+
import { AssetTransformPlugin } from "@player-ui/asset-transform-plugin";
|
|
57
|
+
import { inputTransform } from "@devtools-ui/input";
|
|
58
|
+
|
|
59
|
+
export class TransformsPlugin implements PlayerPlugin {
|
|
60
|
+
name = "my-plugin-transforms";
|
|
61
|
+
|
|
62
|
+
apply(player: Player) {
|
|
63
|
+
player.registerPlugin(
|
|
64
|
+
new AssetTransformPlugin([[{ type: "input" }, inputTransform]])
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
// AssetRegistryPlugin.ts
|
|
72
|
+
import React from "react";
|
|
73
|
+
import type { Player } from "@player-ui/player";
|
|
74
|
+
import type {
|
|
75
|
+
ExtendedPlayerPlugin,
|
|
76
|
+
ReactPlayer,
|
|
77
|
+
ReactPlayerPlugin,
|
|
78
|
+
} from "@player-ui/react";
|
|
79
|
+
import { AssetProviderPlugin } from "@player-ui/asset-provider-plugin-react";
|
|
80
|
+
import { TransformsPlugin } from "./TransformPlugin";
|
|
81
|
+
import { InputAsset, InputComponent } from "@devtools-ui/input";
|
|
82
|
+
|
|
83
|
+
export class AssetsRegistryPlugin
|
|
84
|
+
implements ReactPlayerPlugin, ExtendedPlayerPlugin<[InputAsset]>
|
|
85
|
+
{
|
|
86
|
+
name = "my-plugin";
|
|
87
|
+
|
|
88
|
+
applyReact(reactPlayer: ReactPlayer) {
|
|
89
|
+
reactPlayer.registerPlugin(
|
|
90
|
+
new AssetProviderPlugin([["input", InputComponent]])
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
apply(player: Player) {
|
|
95
|
+
player.registerPlugin(new TransformsPlugin());
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Contributing
|
|
101
|
+
|
|
102
|
+
We welcome contributions to `@devtools-ui/input`!
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -222,19 +222,19 @@ var InputComponent = (props) => {
|
|
|
222
222
|
|
|
223
223
|
// ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/dsl/Input.tsx
|
|
224
224
|
var import_react5 = __toESM(require("react"));
|
|
225
|
-
var
|
|
225
|
+
var import_react_dsl = require("@player-lang/react-dsl");
|
|
226
226
|
var import_text = require("@devtools-ui/text");
|
|
227
227
|
var Input2 = (props) => {
|
|
228
228
|
const { children, binding, ...rest } = props;
|
|
229
|
-
return /* @__PURE__ */ import_react5.default.createElement(
|
|
229
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react_dsl.Asset, { type: "input", ...rest }, /* @__PURE__ */ import_react5.default.createElement("property", { name: "binding" }, binding.toValue()), children);
|
|
230
230
|
};
|
|
231
|
-
Input2.Label = (0,
|
|
231
|
+
Input2.Label = (0, import_react_dsl.createSlot)({
|
|
232
232
|
name: "label",
|
|
233
233
|
TextComp: import_text.Text,
|
|
234
234
|
isArray: false,
|
|
235
235
|
wrapInAsset: true
|
|
236
236
|
});
|
|
237
|
-
Input2.Note = (0,
|
|
237
|
+
Input2.Note = (0, import_react_dsl.createSlot)({
|
|
238
238
|
name: "note",
|
|
239
239
|
TextComp: import_text.Text,
|
|
240
240
|
isArray: false,
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/components/InputComponent.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/hooks/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/dsl/Input.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/transform/index.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./components\";\nexport * from \"./dsl\";\nexport * from \"./transform\";\n","import React, { useState, useRef } from \"react\";\nimport {\n Input,\n Button,\n FormControl,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n} from \"@chakra-ui/react\";\nimport { TransformedInput } from \"../types\";\nimport { ReactAsset } from \"@player-ui/react\";\nimport { useInputAssetProps, useFileInputAssetProps } from \"../hooks\";\n\nconst FileInputComponent = (props: TransformedInput) => {\n const hiddenFileInput: React.Ref<any> = useRef(null);\n\n const [fileName, setFileName] = useState(\"\");\n\n const handleClick = () => {\n hiddenFileInput.current?.click();\n };\n\n const handleFile = (fileName: string) => {\n setFileName(fileName);\n };\n\n const { id, label } = props;\n\n const inputProps = useFileInputAssetProps({ ...props, handleFile });\n\n return (\n <FormControl>\n <Button className=\"button-file\" onClick={handleClick}>\n <FormLabel style={{ margin: 0 }}>\n {label ? <ReactAsset {...label.asset} /> : <>Select Content</>}\n </FormLabel>\n </Button>\n <Input\n id={id}\n name={id}\n {...inputProps}\n style={{ display: \"none\" }}\n ref={hiddenFileInput}\n />\n {fileName ? <p>Uploaded file: {fileName}</p> : null}\n </FormControl>\n );\n};\n\nexport const InputComponent = (props: TransformedInput) => {\n const { validation, label, id, note, size, maxLength, placeholder, file } =\n props;\n\n const inputProps = useInputAssetProps(props);\n\n return file ? (\n <FileInputComponent {...props} />\n ) : (\n <FormControl isInvalid={Boolean(validation)}>\n {label && (\n <FormLabel htmlFor={id}>\n <ReactAsset {...label.asset} />\n </FormLabel>\n )}\n <Input\n id={id}\n {...inputProps}\n size={size}\n maxLength={maxLength}\n placeholder={placeholder}\n />\n {validation && <FormErrorMessage>{validation.message}</FormErrorMessage>}\n {note && (\n <FormHelperText>\n <ReactAsset {...note.asset} />\n </FormHelperText>\n )}\n </FormControl>\n );\n};\n","import React, { useState, useEffect, useRef } from \"react\";\nimport type { TransformedInput } from \"../types\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype KeyDownHandler = (currentValue: string, props?: TransformedInput) => any;\n\nexport interface InputHookConfig {\n /** Time in ms to wait before formatting the user input for normal keys */\n formatDelay?: number;\n\n /** Symbol to be used for decimal point */\n decimalSymbol?: string;\n\n /** Affix to append to value - does not save to model and is only for display on input */\n prefix?: string;\n\n /** Affix to prepend to value - does not save to model and is only for display on input */\n suffix?: string;\n}\n\n/** Create a valid config mixing in defaults and user overrides */\nexport const getConfig = (\n userConfig: InputHookConfig = {}\n): Required<InputHookConfig> => {\n return {\n decimalSymbol: \".\",\n formatDelay: 200,\n prefix: \"\",\n suffix: \"\",\n ...userConfig,\n };\n};\n\n/**\n * A hook to manage an input html element as an asset.\n * The hook returns an object containing props that are expected to reside on any html input.\n * It will handle formatting, setting values, beaconing, aria-labels, etc.\n *\n * @param props - The output of the input transform\n * @param config - Local config to manage user interaction overrides\n */\nexport const useInputAssetProps = (\n props: TransformedInput,\n config?: InputHookConfig\n) => {\n const [localValue, setLocalValue] = useState(props.value ?? \"\");\n const formatTimerRef = useRef<NodeJS.Timeout | undefined>(undefined);\n\n const { formatDelay, decimalSymbol, prefix, suffix } = getConfig(config);\n\n /** Reset and pending format timers */\n function clearPending() {\n if (formatTimerRef.current) {\n clearTimeout(formatTimerRef.current);\n formatTimerRef.current = undefined;\n }\n }\n\n /** Affix handling logic on focus */\n function handleAffixOnFocus(target: HTMLInputElement) {\n let val = target.value;\n\n if (suffix) val = val.substring(0, val.indexOf(suffix));\n\n if (prefix && !val.includes(prefix)) {\n val = `${prefix}${val}`;\n }\n\n return val;\n }\n\n /** Edge cases handling for prefix */\n function handlePrefixEdgeCases(e: React.KeyboardEvent<HTMLInputElement>) {\n const target = e.target as HTMLInputElement;\n const start = target.selectionStart;\n const end = target.selectionEnd;\n const pl = prefix.length;\n const atStart = start === pl;\n const atEnd = end === pl;\n\n if (start && end && start < pl) {\n e.preventDefault();\n target.setSelectionRange(pl, end - start + pl);\n } else if (\n (e.key === \"ArrowLeft\" && atStart) ||\n (e.key === \"Backspace\" && atStart && atEnd) ||\n e.key === \"Home\"\n ) {\n e.preventDefault();\n target.setSelectionRange(prefix.length, prefix.length);\n }\n }\n\n /** Helper to add affixes to value where appropriate */\n function formatValueWithAffix(value: string | undefined) {\n if (!value) return \"\";\n\n return `${prefix}${value}${suffix}`;\n }\n\n /** Value handling logic on key down */\n const onKeyDownHandler: KeyDownHandler = (currentValue: string) => {\n const symbolPosition = currentValue.indexOf(decimalSymbol);\n const newValue = props.format(currentValue) ?? \"\";\n const newSymbolPosition = newValue.indexOf(decimalSymbol);\n\n if (\n (symbolPosition === -1 || symbolPosition === 0) &&\n newSymbolPosition > 0\n ) {\n // formatting added dot, so set cursor before dot\n return {\n newValue: newValue.includes(prefix)\n ? `${newValue}`\n : `${prefix}${newValue}`,\n newCursorPosition: newValue.includes(prefix)\n ? newSymbolPosition\n : newSymbolPosition + prefix.length,\n };\n }\n\n return {\n newValue: newValue.includes(prefix)\n ? `${newValue}`\n : `${prefix}${newValue}`,\n };\n };\n\n /** On blur, commit the value to the model */\n const onBlur: React.FocusEventHandler<HTMLInputElement> = (e) => {\n clearPending();\n\n const formatted =\n (prefix\n ? e.target.value.replace(prefix, \"\")\n : props.format(e.target.value)) ?? \"\";\n\n if (formatted) {\n props.set(formatted);\n setLocalValue(formatValueWithAffix(formatted));\n } else {\n props.set(\"\");\n setLocalValue(\"\");\n }\n };\n\n /** Keep track of any user changes */\n const onChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {\n setLocalValue(e.target.value);\n };\n\n /** Schedule a format of the current input in the future */\n const onKeyDown: React.KeyboardEventHandler<HTMLInputElement> = (e) => {\n clearPending();\n\n if (prefix) handlePrefixEdgeCases(e);\n\n const target = e.target as HTMLInputElement;\n\n formatTimerRef.current = setTimeout(() => {\n const cursorPosition = target.selectionStart;\n const currentValue = target.value;\n\n /** Skip formatting if we're in the middle of the input */\n if (cursorPosition !== currentValue.length) {\n return;\n }\n\n const obj = onKeyDownHandler(currentValue);\n\n setLocalValue(obj.newValue);\n target.selectionStart = obj.newCursorPosition ?? target.selectionStart;\n target.selectionEnd = obj.newCursorPosition ?? target.selectionEnd;\n }, formatDelay);\n };\n\n /** Format value onFocus if affixes exist */\n const onFocus: React.FocusEventHandler<HTMLInputElement> = (e) => {\n const target = e.target as HTMLInputElement;\n const inputEmpty = target.value === \"\";\n\n if ((!inputEmpty && suffix) || (inputEmpty && prefix)) {\n setLocalValue(handleAffixOnFocus(target));\n }\n };\n\n // Update the stored value if data changes\n const propsValue = props.value;\n useEffect(() => {\n setLocalValue(formatValueWithAffix(propsValue));\n }, [propsValue]);\n\n /** clear anything pending on unmount of input */\n useEffect(() => clearPending, []);\n\n return {\n onBlur,\n onChange,\n onKeyDown,\n onFocus,\n value: localValue,\n };\n};\n\n/** Props for file type Input */\nexport const useFileInputAssetProps = (props: TransformedInput) => {\n const { accept } = props;\n\n const acceptedExtensions = accept\n ? accept.concat(\".json\").join(\", \")\n : \".json\";\n\n /** Parses file content for upload into a string if file type Input */\n const onFileUpload: React.ChangeEventHandler = (e): void => {\n const fileList = (<HTMLInputElement>e.target).files;\n const file = fileList ? fileList[0] : \"\";\n const reader = new FileReader();\n\n reader.addEventListener(\n \"load\",\n () => {\n // this will set the file contents in the data model\n props.set(reader.result as string);\n },\n false\n );\n\n if (file) {\n reader.readAsText(file);\n props.handleFile && props.handleFile(file.name);\n }\n };\n\n return {\n type: \"file\",\n onChange: onFileUpload,\n accept: acceptedExtensions,\n };\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n createSlot,\n BindingTemplateInstance,\n} from \"@player-tools/dsl\";\nimport { InputAsset } from \"../types\";\nimport { Text } from \"@devtools-ui/text\";\n\nexport const Input = (\n props: Omit<AssetPropsWithChildren<InputAsset>, \"binding\"> & {\n /** The binding */\n binding: BindingTemplateInstance;\n }\n) => {\n const { children, binding, ...rest } = props;\n return (\n <Asset type=\"input\" {...rest}>\n <property name=\"binding\">{binding.toValue()}</property>\n {children}\n </Asset>\n );\n};\n\nInput.Label = createSlot({\n name: \"label\",\n TextComp: Text,\n isArray: false,\n wrapInAsset: true,\n});\n\nInput.Note = createSlot({\n name: \"note\",\n TextComp: Text,\n isArray: false,\n wrapInAsset: true,\n});\n","import type { TransformFunction } from \"@player-ui/player\";\nimport { InputAsset, TransformedInput } from \"../types\";\n\nexport const inputTransform: TransformFunction<InputAsset, TransformedInput> = (\n asset,\n options\n) => {\n return {\n ...asset,\n format(val) {\n if (asset.binding === undefined) {\n return val;\n }\n\n return options.data.format(asset.binding, val);\n },\n set(val) {\n if (asset.binding === undefined) {\n return;\n }\n\n return options.data.model.set([[asset.binding, val]], {\n formatted: true,\n });\n },\n value:\n asset.binding === undefined\n ? \"\"\n : options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: true,\n }),\n validation:\n asset.binding === undefined\n ? undefined\n : options.validation?.get(asset.binding, { track: true }),\n dataType:\n asset.binding === undefined\n ? undefined\n : options.validation?.type(asset.binding),\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,eAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAC,gBAAwC;AACxC,IAAAA,gBAOO;AAEP,IAAAA,gBAA2B;;;ACV3B,mBAAmD;AAqB5C,IAAM,YAAY,CACvB,aAA8B,CAAC,MACD;AAC9B,SAAO;AAAA,IACL,eAAe;AAAA,IACf,aAAa;AAAA,I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names":["Input","import_react","fileName","React","import_react","Input","React"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/components/InputComponent.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/hooks/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/dsl/Input.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/transform/index.ts"],"sourcesContent":["export * from \"./types\";\nexport * from \"./components\";\nexport * from \"./dsl\";\nexport * from \"./transform\";\n","import React, { useState, useRef } from \"react\";\nimport {\n Input,\n Button,\n FormControl,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n} from \"@chakra-ui/react\";\nimport { TransformedInput } from \"../types\";\nimport { ReactAsset } from \"@player-ui/react\";\nimport { useInputAssetProps, useFileInputAssetProps } from \"../hooks\";\n\nconst FileInputComponent = (props: TransformedInput) => {\n const hiddenFileInput: React.Ref<any> = useRef(null);\n\n const [fileName, setFileName] = useState(\"\");\n\n const handleClick = () => {\n hiddenFileInput.current?.click();\n };\n\n const handleFile = (fileName: string) => {\n setFileName(fileName);\n };\n\n const { id, label } = props;\n\n const inputProps = useFileInputAssetProps({ ...props, handleFile });\n\n return (\n <FormControl>\n <Button className=\"button-file\" onClick={handleClick}>\n <FormLabel style={{ margin: 0 }}>\n {label ? <ReactAsset {...label.asset} /> : <>Select Content</>}\n </FormLabel>\n </Button>\n <Input\n id={id}\n name={id}\n {...inputProps}\n style={{ display: \"none\" }}\n ref={hiddenFileInput}\n />\n {fileName ? <p>Uploaded file: {fileName}</p> : null}\n </FormControl>\n );\n};\n\nexport const InputComponent = (props: TransformedInput) => {\n const { validation, label, id, note, size, maxLength, placeholder, file } =\n props;\n\n const inputProps = useInputAssetProps(props);\n\n return file ? (\n <FileInputComponent {...props} />\n ) : (\n <FormControl isInvalid={Boolean(validation)}>\n {label && (\n <FormLabel htmlFor={id}>\n <ReactAsset {...label.asset} />\n </FormLabel>\n )}\n <Input\n id={id}\n {...inputProps}\n size={size}\n maxLength={maxLength}\n placeholder={placeholder}\n />\n {validation && <FormErrorMessage>{validation.message}</FormErrorMessage>}\n {note && (\n <FormHelperText>\n <ReactAsset {...note.asset} />\n </FormHelperText>\n )}\n </FormControl>\n );\n};\n","import React, { useState, useEffect, useRef } from \"react\";\nimport type { TransformedInput } from \"../types\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype KeyDownHandler = (currentValue: string, props?: TransformedInput) => any;\n\nexport interface InputHookConfig {\n /** Time in ms to wait before formatting the user input for normal keys */\n formatDelay?: number;\n\n /** Symbol to be used for decimal point */\n decimalSymbol?: string;\n\n /** Affix to append to value - does not save to model and is only for display on input */\n prefix?: string;\n\n /** Affix to prepend to value - does not save to model and is only for display on input */\n suffix?: string;\n}\n\n/** Create a valid config mixing in defaults and user overrides */\nexport const getConfig = (\n userConfig: InputHookConfig = {}\n): Required<InputHookConfig> => {\n return {\n decimalSymbol: \".\",\n formatDelay: 200,\n prefix: \"\",\n suffix: \"\",\n ...userConfig,\n };\n};\n\n/**\n * A hook to manage an input html element as an asset.\n * The hook returns an object containing props that are expected to reside on any html input.\n * It will handle formatting, setting values, beaconing, aria-labels, etc.\n *\n * @param props - The output of the input transform\n * @param config - Local config to manage user interaction overrides\n */\nexport const useInputAssetProps = (\n props: TransformedInput,\n config?: InputHookConfig\n) => {\n const [localValue, setLocalValue] = useState(props.value ?? \"\");\n const formatTimerRef = useRef<NodeJS.Timeout | undefined>(undefined);\n\n const { formatDelay, decimalSymbol, prefix, suffix } = getConfig(config);\n\n /** Reset and pending format timers */\n function clearPending() {\n if (formatTimerRef.current) {\n clearTimeout(formatTimerRef.current);\n formatTimerRef.current = undefined;\n }\n }\n\n /** Affix handling logic on focus */\n function handleAffixOnFocus(target: HTMLInputElement) {\n let val = target.value;\n\n if (suffix) val = val.substring(0, val.indexOf(suffix));\n\n if (prefix && !val.includes(prefix)) {\n val = `${prefix}${val}`;\n }\n\n return val;\n }\n\n /** Edge cases handling for prefix */\n function handlePrefixEdgeCases(e: React.KeyboardEvent<HTMLInputElement>) {\n const target = e.target as HTMLInputElement;\n const start = target.selectionStart;\n const end = target.selectionEnd;\n const pl = prefix.length;\n const atStart = start === pl;\n const atEnd = end === pl;\n\n if (start && end && start < pl) {\n e.preventDefault();\n target.setSelectionRange(pl, end - start + pl);\n } else if (\n (e.key === \"ArrowLeft\" && atStart) ||\n (e.key === \"Backspace\" && atStart && atEnd) ||\n e.key === \"Home\"\n ) {\n e.preventDefault();\n target.setSelectionRange(prefix.length, prefix.length);\n }\n }\n\n /** Helper to add affixes to value where appropriate */\n function formatValueWithAffix(value: string | undefined) {\n if (!value) return \"\";\n\n return `${prefix}${value}${suffix}`;\n }\n\n /** Value handling logic on key down */\n const onKeyDownHandler: KeyDownHandler = (currentValue: string) => {\n const symbolPosition = currentValue.indexOf(decimalSymbol);\n const newValue = props.format(currentValue) ?? \"\";\n const newSymbolPosition = newValue.indexOf(decimalSymbol);\n\n if (\n (symbolPosition === -1 || symbolPosition === 0) &&\n newSymbolPosition > 0\n ) {\n // formatting added dot, so set cursor before dot\n return {\n newValue: newValue.includes(prefix)\n ? `${newValue}`\n : `${prefix}${newValue}`,\n newCursorPosition: newValue.includes(prefix)\n ? newSymbolPosition\n : newSymbolPosition + prefix.length,\n };\n }\n\n return {\n newValue: newValue.includes(prefix)\n ? `${newValue}`\n : `${prefix}${newValue}`,\n };\n };\n\n /** On blur, commit the value to the model */\n const onBlur: React.FocusEventHandler<HTMLInputElement> = (e) => {\n clearPending();\n\n const formatted =\n (prefix\n ? e.target.value.replace(prefix, \"\")\n : props.format(e.target.value)) ?? \"\";\n\n if (formatted) {\n props.set(formatted);\n setLocalValue(formatValueWithAffix(formatted));\n } else {\n props.set(\"\");\n setLocalValue(\"\");\n }\n };\n\n /** Keep track of any user changes */\n const onChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {\n setLocalValue(e.target.value);\n };\n\n /** Schedule a format of the current input in the future */\n const onKeyDown: React.KeyboardEventHandler<HTMLInputElement> = (e) => {\n clearPending();\n\n if (prefix) handlePrefixEdgeCases(e);\n\n const target = e.target as HTMLInputElement;\n\n formatTimerRef.current = setTimeout(() => {\n const cursorPosition = target.selectionStart;\n const currentValue = target.value;\n\n /** Skip formatting if we're in the middle of the input */\n if (cursorPosition !== currentValue.length) {\n return;\n }\n\n const obj = onKeyDownHandler(currentValue);\n\n setLocalValue(obj.newValue);\n target.selectionStart = obj.newCursorPosition ?? target.selectionStart;\n target.selectionEnd = obj.newCursorPosition ?? target.selectionEnd;\n }, formatDelay);\n };\n\n /** Format value onFocus if affixes exist */\n const onFocus: React.FocusEventHandler<HTMLInputElement> = (e) => {\n const target = e.target as HTMLInputElement;\n const inputEmpty = target.value === \"\";\n\n if ((!inputEmpty && suffix) || (inputEmpty && prefix)) {\n setLocalValue(handleAffixOnFocus(target));\n }\n };\n\n // Update the stored value if data changes\n const propsValue = props.value;\n useEffect(() => {\n setLocalValue(formatValueWithAffix(propsValue));\n }, [propsValue]);\n\n /** clear anything pending on unmount of input */\n useEffect(() => clearPending, []);\n\n return {\n onBlur,\n onChange,\n onKeyDown,\n onFocus,\n value: localValue,\n };\n};\n\n/** Props for file type Input */\nexport const useFileInputAssetProps = (props: TransformedInput) => {\n const { accept } = props;\n\n const acceptedExtensions = accept\n ? accept.concat(\".json\").join(\", \")\n : \".json\";\n\n /** Parses file content for upload into a string if file type Input */\n const onFileUpload: React.ChangeEventHandler = (e): void => {\n const fileList = (<HTMLInputElement>e.target).files;\n const file = fileList ? fileList[0] : \"\";\n const reader = new FileReader();\n\n reader.addEventListener(\n \"load\",\n () => {\n // this will set the file contents in the data model\n props.set(reader.result as string);\n },\n false\n );\n\n if (file) {\n reader.readAsText(file);\n props.handleFile && props.handleFile(file.name);\n }\n };\n\n return {\n type: \"file\",\n onChange: onFileUpload,\n accept: acceptedExtensions,\n };\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n createSlot,\n BindingTemplateInstance,\n} from \"@player-lang/react-dsl\";\nimport { InputAsset } from \"../types\";\nimport { Text } from \"@devtools-ui/text\";\n\nexport const Input = (\n props: Omit<AssetPropsWithChildren<InputAsset>, \"binding\"> & {\n /** The binding */\n binding: BindingTemplateInstance;\n }\n) => {\n const { children, binding, ...rest } = props;\n return (\n <Asset type=\"input\" {...rest}>\n <property name=\"binding\">{binding.toValue()}</property>\n {children}\n </Asset>\n );\n};\n\nInput.Label = createSlot({\n name: \"label\",\n TextComp: Text,\n isArray: false,\n wrapInAsset: true,\n});\n\nInput.Note = createSlot({\n name: \"note\",\n TextComp: Text,\n isArray: false,\n wrapInAsset: true,\n});\n","import type { TransformFunction } from \"@player-ui/player\";\nimport { InputAsset, TransformedInput } from \"../types\";\n\nexport const inputTransform: TransformFunction<InputAsset, TransformedInput> = (\n asset,\n options\n) => {\n return {\n ...asset,\n format(val) {\n if (asset.binding === undefined) {\n return val;\n }\n\n return options.data.format(asset.binding, val);\n },\n set(val) {\n if (asset.binding === undefined) {\n return;\n }\n\n return options.data.model.set([[asset.binding, val]], {\n formatted: true,\n });\n },\n value:\n asset.binding === undefined\n ? \"\"\n : options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: true,\n }),\n validation:\n asset.binding === undefined\n ? undefined\n : options.validation?.get(asset.binding, { track: true }),\n dataType:\n asset.binding === undefined\n ? undefined\n : options.validation?.type(asset.binding),\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,eAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAC,gBAAwC;AACxC,IAAAA,gBAOO;AAEP,IAAAA,gBAA2B;;;ACV3B,mBAAmD;AAqB5C,IAAM,YAAY,CACvB,aAA8B,CAAC,MACD;AAC9B,SAAO;AAAA,IACL,eAAe;AAAA,IACf,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EAC9C;AACF;","names":["Input","import_react","fileName","React","import_react","Input","React"]}
|
package/dist/index.legacy-esm.js
CHANGED
|
@@ -194,7 +194,7 @@ import React3 from "react";
|
|
|
194
194
|
import {
|
|
195
195
|
Asset,
|
|
196
196
|
createSlot
|
|
197
|
-
} from "@player-
|
|
197
|
+
} from "@player-lang/react-dsl";
|
|
198
198
|
import { Text } from "@devtools-ui/text";
|
|
199
199
|
var Input2 = (props) => {
|
|
200
200
|
const { children, binding, ...rest } = props;
|
package/dist/index.mjs
CHANGED
|
@@ -194,7 +194,7 @@ import React3 from "react";
|
|
|
194
194
|
import {
|
|
195
195
|
Asset,
|
|
196
196
|
createSlot
|
|
197
|
-
} from "@player-
|
|
197
|
+
} from "@player-lang/react-dsl";
|
|
198
198
|
import { Text } from "@devtools-ui/text";
|
|
199
199
|
var Input2 = (props) => {
|
|
200
200
|
const { children, binding, ...rest } = props;
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/components/InputComponent.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/hooks/index.ts","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/dsl/Input.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/transform/index.ts"],"sourcesContent":["import React, { useState, useRef } from \"react\";\nimport {\n Input,\n Button,\n FormControl,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n} from \"@chakra-ui/react\";\nimport { TransformedInput } from \"../types\";\nimport { ReactAsset } from \"@player-ui/react\";\nimport { useInputAssetProps, useFileInputAssetProps } from \"../hooks\";\n\nconst FileInputComponent = (props: TransformedInput) => {\n const hiddenFileInput: React.Ref<any> = useRef(null);\n\n const [fileName, setFileName] = useState(\"\");\n\n const handleClick = () => {\n hiddenFileInput.current?.click();\n };\n\n const handleFile = (fileName: string) => {\n setFileName(fileName);\n };\n\n const { id, label } = props;\n\n const inputProps = useFileInputAssetProps({ ...props, handleFile });\n\n return (\n <FormControl>\n <Button className=\"button-file\" onClick={handleClick}>\n <FormLabel style={{ margin: 0 }}>\n {label ? <ReactAsset {...label.asset} /> : <>Select Content</>}\n </FormLabel>\n </Button>\n <Input\n id={id}\n name={id}\n {...inputProps}\n style={{ display: \"none\" }}\n ref={hiddenFileInput}\n />\n {fileName ? <p>Uploaded file: {fileName}</p> : null}\n </FormControl>\n );\n};\n\nexport const InputComponent = (props: TransformedInput) => {\n const { validation, label, id, note, size, maxLength, placeholder, file } =\n props;\n\n const inputProps = useInputAssetProps(props);\n\n return file ? (\n <FileInputComponent {...props} />\n ) : (\n <FormControl isInvalid={Boolean(validation)}>\n {label && (\n <FormLabel htmlFor={id}>\n <ReactAsset {...label.asset} />\n </FormLabel>\n )}\n <Input\n id={id}\n {...inputProps}\n size={size}\n maxLength={maxLength}\n placeholder={placeholder}\n />\n {validation && <FormErrorMessage>{validation.message}</FormErrorMessage>}\n {note && (\n <FormHelperText>\n <ReactAsset {...note.asset} />\n </FormHelperText>\n )}\n </FormControl>\n );\n};\n","import React, { useState, useEffect, useRef } from \"react\";\nimport type { TransformedInput } from \"../types\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype KeyDownHandler = (currentValue: string, props?: TransformedInput) => any;\n\nexport interface InputHookConfig {\n /** Time in ms to wait before formatting the user input for normal keys */\n formatDelay?: number;\n\n /** Symbol to be used for decimal point */\n decimalSymbol?: string;\n\n /** Affix to append to value - does not save to model and is only for display on input */\n prefix?: string;\n\n /** Affix to prepend to value - does not save to model and is only for display on input */\n suffix?: string;\n}\n\n/** Create a valid config mixing in defaults and user overrides */\nexport const getConfig = (\n userConfig: InputHookConfig = {}\n): Required<InputHookConfig> => {\n return {\n decimalSymbol: \".\",\n formatDelay: 200,\n prefix: \"\",\n suffix: \"\",\n ...userConfig,\n };\n};\n\n/**\n * A hook to manage an input html element as an asset.\n * The hook returns an object containing props that are expected to reside on any html input.\n * It will handle formatting, setting values, beaconing, aria-labels, etc.\n *\n * @param props - The output of the input transform\n * @param config - Local config to manage user interaction overrides\n */\nexport const useInputAssetProps = (\n props: TransformedInput,\n config?: InputHookConfig\n) => {\n const [localValue, setLocalValue] = useState(props.value ?? \"\");\n const formatTimerRef = useRef<NodeJS.Timeout | undefined>(undefined);\n\n const { formatDelay, decimalSymbol, prefix, suffix } = getConfig(config);\n\n /** Reset and pending format timers */\n function clearPending() {\n if (formatTimerRef.current) {\n clearTimeout(formatTimerRef.current);\n formatTimerRef.current = undefined;\n }\n }\n\n /** Affix handling logic on focus */\n function handleAffixOnFocus(target: HTMLInputElement) {\n let val = target.value;\n\n if (suffix) val = val.substring(0, val.indexOf(suffix));\n\n if (prefix && !val.includes(prefix)) {\n val = `${prefix}${val}`;\n }\n\n return val;\n }\n\n /** Edge cases handling for prefix */\n function handlePrefixEdgeCases(e: React.KeyboardEvent<HTMLInputElement>) {\n const target = e.target as HTMLInputElement;\n const start = target.selectionStart;\n const end = target.selectionEnd;\n const pl = prefix.length;\n const atStart = start === pl;\n const atEnd = end === pl;\n\n if (start && end && start < pl) {\n e.preventDefault();\n target.setSelectionRange(pl, end - start + pl);\n } else if (\n (e.key === \"ArrowLeft\" && atStart) ||\n (e.key === \"Backspace\" && atStart && atEnd) ||\n e.key === \"Home\"\n ) {\n e.preventDefault();\n target.setSelectionRange(prefix.length, prefix.length);\n }\n }\n\n /** Helper to add affixes to value where appropriate */\n function formatValueWithAffix(value: string | undefined) {\n if (!value) return \"\";\n\n return `${prefix}${value}${suffix}`;\n }\n\n /** Value handling logic on key down */\n const onKeyDownHandler: KeyDownHandler = (currentValue: string) => {\n const symbolPosition = currentValue.indexOf(decimalSymbol);\n const newValue = props.format(currentValue) ?? \"\";\n const newSymbolPosition = newValue.indexOf(decimalSymbol);\n\n if (\n (symbolPosition === -1 || symbolPosition === 0) &&\n newSymbolPosition > 0\n ) {\n // formatting added dot, so set cursor before dot\n return {\n newValue: newValue.includes(prefix)\n ? `${newValue}`\n : `${prefix}${newValue}`,\n newCursorPosition: newValue.includes(prefix)\n ? newSymbolPosition\n : newSymbolPosition + prefix.length,\n };\n }\n\n return {\n newValue: newValue.includes(prefix)\n ? `${newValue}`\n : `${prefix}${newValue}`,\n };\n };\n\n /** On blur, commit the value to the model */\n const onBlur: React.FocusEventHandler<HTMLInputElement> = (e) => {\n clearPending();\n\n const formatted =\n (prefix\n ? e.target.value.replace(prefix, \"\")\n : props.format(e.target.value)) ?? \"\";\n\n if (formatted) {\n props.set(formatted);\n setLocalValue(formatValueWithAffix(formatted));\n } else {\n props.set(\"\");\n setLocalValue(\"\");\n }\n };\n\n /** Keep track of any user changes */\n const onChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {\n setLocalValue(e.target.value);\n };\n\n /** Schedule a format of the current input in the future */\n const onKeyDown: React.KeyboardEventHandler<HTMLInputElement> = (e) => {\n clearPending();\n\n if (prefix) handlePrefixEdgeCases(e);\n\n const target = e.target as HTMLInputElement;\n\n formatTimerRef.current = setTimeout(() => {\n const cursorPosition = target.selectionStart;\n const currentValue = target.value;\n\n /** Skip formatting if we're in the middle of the input */\n if (cursorPosition !== currentValue.length) {\n return;\n }\n\n const obj = onKeyDownHandler(currentValue);\n\n setLocalValue(obj.newValue);\n target.selectionStart = obj.newCursorPosition ?? target.selectionStart;\n target.selectionEnd = obj.newCursorPosition ?? target.selectionEnd;\n }, formatDelay);\n };\n\n /** Format value onFocus if affixes exist */\n const onFocus: React.FocusEventHandler<HTMLInputElement> = (e) => {\n const target = e.target as HTMLInputElement;\n const inputEmpty = target.value === \"\";\n\n if ((!inputEmpty && suffix) || (inputEmpty && prefix)) {\n setLocalValue(handleAffixOnFocus(target));\n }\n };\n\n // Update the stored value if data changes\n const propsValue = props.value;\n useEffect(() => {\n setLocalValue(formatValueWithAffix(propsValue));\n }, [propsValue]);\n\n /** clear anything pending on unmount of input */\n useEffect(() => clearPending, []);\n\n return {\n onBlur,\n onChange,\n onKeyDown,\n onFocus,\n value: localValue,\n };\n};\n\n/** Props for file type Input */\nexport const useFileInputAssetProps = (props: TransformedInput) => {\n const { accept } = props;\n\n const acceptedExtensions = accept\n ? accept.concat(\".json\").join(\", \")\n : \".json\";\n\n /** Parses file content for upload into a string if file type Input */\n const onFileUpload: React.ChangeEventHandler = (e): void => {\n const fileList = (<HTMLInputElement>e.target).files;\n const file = fileList ? fileList[0] : \"\";\n const reader = new FileReader();\n\n reader.addEventListener(\n \"load\",\n () => {\n // this will set the file contents in the data model\n props.set(reader.result as string);\n },\n false\n );\n\n if (file) {\n reader.readAsText(file);\n props.handleFile && props.handleFile(file.name);\n }\n };\n\n return {\n type: \"file\",\n onChange: onFileUpload,\n accept: acceptedExtensions,\n };\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n createSlot,\n BindingTemplateInstance,\n} from \"@player-tools/dsl\";\nimport { InputAsset } from \"../types\";\nimport { Text } from \"@devtools-ui/text\";\n\nexport const Input = (\n props: Omit<AssetPropsWithChildren<InputAsset>, \"binding\"> & {\n /** The binding */\n binding: BindingTemplateInstance;\n }\n) => {\n const { children, binding, ...rest } = props;\n return (\n <Asset type=\"input\" {...rest}>\n <property name=\"binding\">{binding.toValue()}</property>\n {children}\n </Asset>\n );\n};\n\nInput.Label = createSlot({\n name: \"label\",\n TextComp: Text,\n isArray: false,\n wrapInAsset: true,\n});\n\nInput.Note = createSlot({\n name: \"note\",\n TextComp: Text,\n isArray: false,\n wrapInAsset: true,\n});\n","import type { TransformFunction } from \"@player-ui/player\";\nimport { InputAsset, TransformedInput } from \"../types\";\n\nexport const inputTransform: TransformFunction<InputAsset, TransformedInput> = (\n asset,\n options\n) => {\n return {\n ...asset,\n format(val) {\n if (asset.binding === undefined) {\n return val;\n }\n\n return options.data.format(asset.binding, val);\n },\n set(val) {\n if (asset.binding === undefined) {\n return;\n }\n\n return options.data.model.set([[asset.binding, val]], {\n formatted: true,\n });\n },\n value:\n asset.binding === undefined\n ? \"\"\n : options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: true,\n }),\n validation:\n asset.binding === undefined\n ? undefined\n : options.validation?.get(asset.binding, { track: true }),\n dataType:\n asset.binding === undefined\n ? undefined\n : options.validation?.type(asset.binding),\n };\n};\n"],"mappings":";AAAA,OAAOA,UAAS,YAAAC,WAAU,UAAAC,eAAc;AACxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,kBAAkB;;;ACV3B,SAAgB,UAAU,WAAW,cAAc;AAqB5C,IAAM,YAAY,CACvB,aAA8B,CAAC,MACD;AAC9B,SAAO;AAAA,IACL,eAAe;AAAA,IACf,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,GAAG;AAAA,EACL;AACF;AAUO,IAAM,qBAAqB,CAChC,OACA,WACG;AACH,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,MAAM,SAAS,EAAE;AAC9D,QAAM,iBAAiB,OAAmC,MAAS;AAEnE,QAAM,EAAE,aAAa,eAAe,QAAQ,OAAO,IAAI,UAAU,MAAM;AAGvE,WAAS,eAAe;AACtB,QAAI,eAAe,SAAS;AAC1B,mBAAa,eAAe,OAAO;AACnC,qBAAe,UAAU;AAAA,IAC3B;AAAA,EACF;AAGA,WAAS,mBAAmB,QAA0B;AACpD,QAAI,MAAM,OAAO;AAEjB,QAAI;AAAQ,YAAM,IAAI,UAAU,GAAG,IAAI,QAAQ,MAAM,CAAC;AAEtD,QAAI,UAAU,CAAC,IAAI,SAAS,MAAM,GAAG;AACnC,YAAM,GAAG,MAAM,GAAG,GAAG;AAAA,IACvB;AAEA,WAAO;AAAA,EACT;AAGA,WAAS,sBAAsB,GAA0C;AACvE,UAAM,SAAS,EAAE;AACjB,UAAM,QAAQ,OAAO;AACrB,UAAM,MAAM,OAAO;AACnB,UAAM,KAAK,OAAO;AAClB,UAAM,UAAU,UAAU;AAC1B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AAI,MAAM,YAAY,QAAW;AAC/B;AAAA,MACF;AAEA,aAAO,QAAQ,KAAK,MAAM,IAAI,CAAC,CAAC,MAAM,SAAS,GAAG,CAAC,GAAG;AAAA,QACpD,WAAW;AAAA,MACb,CAAC;AAAA,IACH;AAAA,IACA,OACE,MAAM,YAAY,SACd,KACA,QAAQ,KAAK,MAAM,IAAI,MAAM,SAAS;AAAA,MACpC,gBAAgB;AAAA,MAChB,WAAW;AAAA,IACb,CAAC;AAAA,IACP,YACE,MAAM,YAAY,SACd,SACA,QAAQ,YAAY,IAAI,MAAM,SAAS,EAAE,OAAO,KAAK,CAAC;AAAA,IAC5D,UACE,MAAM,YAAY,SACd,SACA,QAAQ,YAAY,KAAK,MAAM,OAAO;AAAA,EAC9C;AACF;","names":["React","useState","useRef","useRef","useState","fileName","React","React","Input"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/components/InputComponent.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/hooks/index.ts","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/dsl/Input.tsx","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/input/src/transform/index.ts"],"sourcesContent":["import React, { useState, useRef } from \"react\";\nimport {\n Input,\n Button,\n FormControl,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n} from \"@chakra-ui/react\";\nimport { TransformedInput } from \"../types\";\nimport { ReactAsset } from \"@player-ui/react\";\nimport { useInputAssetProps, useFileInputAssetProps } from \"../hooks\";\n\nconst FileInputComponent = (props: TransformedInput) => {\n const hiddenFileInput: React.Ref<any> = useRef(null);\n\n const [fileName, setFileName] = useState(\"\");\n\n const handleClick = () => {\n hiddenFileInput.current?.click();\n };\n\n const handleFile = (fileName: string) => {\n setFileName(fileName);\n };\n\n const { id, label } = props;\n\n const inputProps = useFileInputAssetProps({ ...props, handleFile });\n\n return (\n <FormControl>\n <Button className=\"button-file\" onClick={handleClick}>\n <FormLabel style={{ margin: 0 }}>\n {label ? <ReactAsset {...label.asset} /> : <>Select Content</>}\n </FormLabel>\n </Button>\n <Input\n id={id}\n name={id}\n {...inputProps}\n style={{ display: \"none\" }}\n ref={hiddenFileInput}\n />\n {fileName ? <p>Uploaded file: {fileName}</p> : null}\n </FormControl>\n );\n};\n\nexport const InputComponent = (props: TransformedInput) => {\n const { validation, label, id, note, size, maxLength, placeholder, file } =\n props;\n\n const inputProps = useInputAssetProps(props);\n\n return file ? (\n <FileInputComponent {...props} />\n ) : (\n <FormControl isInvalid={Boolean(validation)}>\n {label && (\n <FormLabel htmlFor={id}>\n <ReactAsset {...label.asset} />\n </FormLabel>\n )}\n <Input\n id={id}\n {...inputProps}\n size={size}\n maxLength={maxLength}\n placeholder={placeholder}\n />\n {validation && <FormErrorMessage>{validation.message}</FormErrorMessage>}\n {note && (\n <FormHelperText>\n <ReactAsset {...note.asset} />\n </FormHelperText>\n )}\n </FormControl>\n );\n};\n","import React, { useState, useEffect, useRef } from \"react\";\nimport type { TransformedInput } from \"../types\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype KeyDownHandler = (currentValue: string, props?: TransformedInput) => any;\n\nexport interface InputHookConfig {\n /** Time in ms to wait before formatting the user input for normal keys */\n formatDelay?: number;\n\n /** Symbol to be used for decimal point */\n decimalSymbol?: string;\n\n /** Affix to append to value - does not save to model and is only for display on input */\n prefix?: string;\n\n /** Affix to prepend to value - does not save to model and is only for display on input */\n suffix?: string;\n}\n\n/** Create a valid config mixing in defaults and user overrides */\nexport const getConfig = (\n userConfig: InputHookConfig = {}\n): Required<InputHookConfig> => {\n return {\n decimalSymbol: \".\",\n formatDelay: 200,\n prefix: \"\",\n suffix: \"\",\n ...userConfig,\n };\n};\n\n/**\n * A hook to manage an input html element as an asset.\n * The hook returns an object containing props that are expected to reside on any html input.\n * It will handle formatting, setting values, beaconing, aria-labels, etc.\n *\n * @param props - The output of the input transform\n * @param config - Local config to manage user interaction overrides\n */\nexport const useInputAssetProps = (\n props: TransformedInput,\n config?: InputHookConfig\n) => {\n const [localValue, setLocalValue] = useState(props.value ?? \"\");\n const formatTimerRef = useRef<NodeJS.Timeout | undefined>(undefined);\n\n const { formatDelay, decimalSymbol, prefix, suffix } = getConfig(config);\n\n /** Reset and pending format timers */\n function clearPending() {\n if (formatTimerRef.current) {\n clearTimeout(formatTimerRef.current);\n formatTimerRef.current = undefined;\n }\n }\n\n /** Affix handling logic on focus */\n function handleAffixOnFocus(target: HTMLInputElement) {\n let val = target.value;\n\n if (suffix) val = val.substring(0, val.indexOf(suffix));\n\n if (prefix && !val.includes(prefix)) {\n val = `${prefix}${val}`;\n }\n\n return val;\n }\n\n /** Edge cases handling for prefix */\n function handlePrefixEdgeCases(e: React.KeyboardEvent<HTMLInputElement>) {\n const target = e.target as HTMLInputElement;\n const start = target.selectionStart;\n const end = target.selectionEnd;\n const pl = prefix.length;\n const atStart = start === pl;\n const atEnd = end === pl;\n\n if (start && end && start < pl) {\n e.preventDefault();\n target.setSelectionRange(pl, end - start + pl);\n } else if (\n (e.key === \"ArrowLeft\" && atStart) ||\n (e.key === \"Backspace\" && atStart && atEnd) ||\n e.key === \"Home\"\n ) {\n e.preventDefault();\n target.setSelectionRange(prefix.length, prefix.length);\n }\n }\n\n /** Helper to add affixes to value where appropriate */\n function formatValueWithAffix(value: string | undefined) {\n if (!value) return \"\";\n\n return `${prefix}${value}${suffix}`;\n }\n\n /** Value handling logic on key down */\n const onKeyDownHandler: KeyDownHandler = (currentValue: string) => {\n const symbolPosition = currentValue.indexOf(decimalSymbol);\n const newValue = props.format(currentValue) ?? \"\";\n const newSymbolPosition = newValue.indexOf(decimalSymbol);\n\n if (\n (symbolPosition === -1 || symbolPosition === 0) &&\n newSymbolPosition > 0\n ) {\n // formatting added dot, so set cursor before dot\n return {\n newValue: newValue.includes(prefix)\n ? `${newValue}`\n : `${prefix}${newValue}`,\n newCursorPosition: newValue.includes(prefix)\n ? newSymbolPosition\n : newSymbolPosition + prefix.length,\n };\n }\n\n return {\n newValue: newValue.includes(prefix)\n ? `${newValue}`\n : `${prefix}${newValue}`,\n };\n };\n\n /** On blur, commit the value to the model */\n const onBlur: React.FocusEventHandler<HTMLInputElement> = (e) => {\n clearPending();\n\n const formatted =\n (prefix\n ? e.target.value.replace(prefix, \"\")\n : props.format(e.target.value)) ?? \"\";\n\n if (formatted) {\n props.set(formatted);\n setLocalValue(formatValueWithAffix(formatted));\n } else {\n props.set(\"\");\n setLocalValue(\"\");\n }\n };\n\n /** Keep track of any user changes */\n const onChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {\n setLocalValue(e.target.value);\n };\n\n /** Schedule a format of the current input in the future */\n const onKeyDown: React.KeyboardEventHandler<HTMLInputElement> = (e) => {\n clearPending();\n\n if (prefix) handlePrefixEdgeCases(e);\n\n const target = e.target as HTMLInputElement;\n\n formatTimerRef.current = setTimeout(() => {\n const cursorPosition = target.selectionStart;\n const currentValue = target.value;\n\n /** Skip formatting if we're in the middle of the input */\n if (cursorPosition !== currentValue.length) {\n return;\n }\n\n const obj = onKeyDownHandler(currentValue);\n\n setLocalValue(obj.newValue);\n target.selectionStart = obj.newCursorPosition ?? target.selectionStart;\n target.selectionEnd = obj.newCursorPosition ?? target.selectionEnd;\n }, formatDelay);\n };\n\n /** Format value onFocus if affixes exist */\n const onFocus: React.FocusEventHandler<HTMLInputElement> = (e) => {\n const target = e.target as HTMLInputElement;\n const inputEmpty = target.value === \"\";\n\n if ((!inputEmpty && suffix) || (inputEmpty && prefix)) {\n setLocalValue(handleAffixOnFocus(target));\n }\n };\n\n // Update the stored value if data changes\n const propsValue = props.value;\n useEffect(() => {\n setLocalValue(formatValueWithAffix(propsValue));\n }, [propsValue]);\n\n /** clear anything pending on unmount of input */\n useEffect(() => clearPending, []);\n\n return {\n onBlur,\n onChange,\n onKeyDown,\n onFocus,\n value: localValue,\n };\n};\n\n/** Props for file type Input */\nexport const useFileInputAssetProps = (props: TransformedInput) => {\n const { accept } = props;\n\n const acceptedExtensions = accept\n ? accept.concat(\".json\").join(\", \")\n : \".json\";\n\n /** Parses file content for upload into a string if file type Input */\n const onFileUpload: React.ChangeEventHandler = (e): void => {\n const fileList = (<HTMLInputElement>e.target).files;\n const file = fileList ? fileList[0] : \"\";\n const reader = new FileReader();\n\n reader.addEventListener(\n \"load\",\n () => {\n // this will set the file contents in the data model\n props.set(reader.result as string);\n },\n false\n );\n\n if (file) {\n reader.readAsText(file);\n props.handleFile && props.handleFile(file.name);\n }\n };\n\n return {\n type: \"file\",\n onChange: onFileUpload,\n accept: acceptedExtensions,\n };\n};\n","import React from \"react\";\nimport {\n AssetPropsWithChildren,\n Asset,\n createSlot,\n BindingTemplateInstance,\n} from \"@player-lang/react-dsl\";\nimport { InputAsset } from \"../types\";\nimport { Text } from \"@devtools-ui/text\";\n\nexport const Input = (\n props: Omit<AssetPropsWithChildren<InputAsset>, \"binding\"> & {\n /** The binding */\n binding: BindingTemplateInstance;\n }\n) => {\n const { children, binding, ...rest } = props;\n return (\n <Asset type=\"input\" {...rest}>\n <property name=\"binding\">{binding.toValue()}</property>\n {children}\n </Asset>\n );\n};\n\nInput.Label = createSlot({\n name: \"label\",\n TextComp: Text,\n isArray: false,\n wrapInAsset: true,\n});\n\nInput.Note = createSlot({\n name: \"note\",\n TextComp: Text,\n isArray: false,\n wrapInAsset: true,\n});\n","import type { TransformFunction } from \"@player-ui/player\";\nimport { InputAsset, TransformedInput } from \"../types\";\n\nexport const inputTransform: TransformFunction<InputAsset, TransformedInput> = (\n asset,\n options\n) => {\n return {\n ...asset,\n format(val) {\n if (asset.binding === undefined) {\n return val;\n }\n\n return options.data.format(asset.binding, val);\n },\n set(val) {\n if (asset.binding === undefined) {\n return;\n }\n\n return options.data.model.set([[asset.binding, val]], {\n formatted: true,\n });\n },\n value:\n asset.binding === undefined\n ? \"\"\n : options.data.model.get(asset.binding, {\n includeInvalid: true,\n formatted: true,\n }),\n validation:\n asset.binding === undefined\n ? undefined\n : options.validation?.get(asset.binding, { track: true }),\n dataType:\n asset.binding === undefined\n ? undefined\n : options.validation?.type(asset.binding),\n };\n};\n"],"mappings":";AAAA,OAAOA,UAAS,YAAAC,WAAU,UAAAC,eAAc;AACxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,kBAAkB;;;ACV3B,SAAgB,UAAU,WAAW,cAAc;AAqB5C,IAAM,YAAY,CACvB,aAA8B,CAAC,MACD;AAC9B,SAAO;AAAA,IACL,eAAe;AAAA,IACf,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,GAAG;AAAA,EACL;AACF;AAUO,IAAM,qBAAqB,CAChC,OACA,WACG;AACH,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,MAAM,SAAS,EAAE;AAC9D,QAAM,iBAAiB,OAAmC,MAAS;AAEnE,QAAM,EAAE,aAAa,eAAe,QAAQ,OAAO,IAAI,UAAU,MAAM;AAGvE,WAAS,eAAe;AACtB,QAAI,eAAe,SAAS;AAC1B,mBAAa,eAAe,OAAO;AACnC,qBAAe,UAAU;AAAA,IAC3B;AAAA,EACF;AAGA,WAAS,mBAAmB,QAA0B;AACpD,QAAI,MAAM,OAAO;AAEjB,QAAI;AAAQ,YAAM,IAAI,UAAU,GAAG,IAAI,QAAQ,MAAM,CAAC;AAEtD,QAAI,UAAU,CAAC,IAAI,SAAS,MAAM,GAAG;AACnC,YAAM,GAAG,MAAM,GAAG,GAAG;AAAA,IACvB;AAEA,WAAO;AAAA,EACT;AAGA,WAAS,sBAAsB,GAA0C;AACvE,UAAM,SAAS,EAAE;AACjB,UAAM,QAAQ,OAAO;AACrB,UAAM,MAAM,OAAO;AACnB,UAAM,KAAK,OAAO;AAClB,UAAM,UAAU,UAAU;AAC1B,UAAM,QAAQ,QAAQ;AAEtB,QAAI,SAAS,OAAO,QAAQ,IAAI;AAC9B,QAAE,eAAe;AAC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C,CAAC,MAAM,SAAS,GAAG,CAAC,GAAG;AAAA,QACpD,WAAW;AAAA,MACb,CAAC;AAAA,IACH;AAAA,IACA,OACE,MAAM,YAAY,SACd,KACA,QAAQ,KAAK,MAAM,IAAI,MAAM,SAAS;AAAA,MACpC,gBAAgB;AAAA,MAChB,WAAW;AAAA,IACb,CAAC;AAAA,IACP,YACE,MAAM,YAAY,SACd,SACA,QAAQ,YAAY,IAAI,MAAM,SAAS,EAAE,OAAO,KAAK,CAAC;AAAA,IAC5D,UACE,MAAM,YAAY,SACd,SACA,QAAQ,YAAY,KAAK,MAAM,OAAO;AAAA,EAC9C;AACF;","names":["React","useState","useRef","useRef","useState","fileName","React","React","Input"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
+
"sideEffects": false,
|
|
3
|
+
"files": [
|
|
4
|
+
"dist",
|
|
5
|
+
"src",
|
|
6
|
+
"types"
|
|
7
|
+
],
|
|
2
8
|
"name": "@devtools-ui/input",
|
|
3
|
-
"version": "0.4.0",
|
|
9
|
+
"version": "0.4.1-next.0",
|
|
4
10
|
"main": "dist/cjs/index.cjs",
|
|
5
11
|
"dependencies": {
|
|
6
|
-
"@devtools-ui/text": "0.4.0",
|
|
12
|
+
"@devtools-ui/text": "0.4.1-next.0",
|
|
7
13
|
"@chakra-ui/react": "^2.8.2",
|
|
8
14
|
"@emotion/react": "^11.11.4",
|
|
9
15
|
"@emotion/styled": "^11.11.0",
|
|
@@ -15,7 +21,6 @@
|
|
|
15
21
|
},
|
|
16
22
|
"module": "dist/index.legacy-esm.js",
|
|
17
23
|
"types": "types/index.d.ts",
|
|
18
|
-
"sideEffects": false,
|
|
19
24
|
"exports": {
|
|
20
25
|
"./package.json": "./package.json",
|
|
21
26
|
"./dist/index.css": "./dist/index.css",
|
|
@@ -25,16 +30,11 @@
|
|
|
25
30
|
"default": "./dist/cjs/index.cjs"
|
|
26
31
|
}
|
|
27
32
|
},
|
|
28
|
-
"files": [
|
|
29
|
-
"dist",
|
|
30
|
-
"src",
|
|
31
|
-
"types"
|
|
32
|
-
],
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@player-
|
|
35
|
-
"@player-ui/types": "0.
|
|
36
|
-
"@player-ui/player": "0.
|
|
37
|
-
"@player-ui/react": "0.
|
|
38
|
-
"@player-ui/asset-transform-plugin": "0.
|
|
34
|
+
"@player-lang/react-dsl": "1.0.1",
|
|
35
|
+
"@player-ui/types": "0.15.5",
|
|
36
|
+
"@player-ui/player": "0.15.5",
|
|
37
|
+
"@player-ui/react": "0.15.5",
|
|
38
|
+
"@player-ui/asset-transform-plugin": "0.15.5"
|
|
39
39
|
}
|
|
40
40
|
}
|
package/src/dsl/Input.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { describe, expect, test } from "vitest";
|
|
3
|
-
import { render, binding as b } from "@player-
|
|
3
|
+
import { render, binding as b } from "@player-lang/react-dsl";
|
|
4
4
|
import { Input } from "../Input";
|
|
5
5
|
|
|
6
6
|
describe("DSL: Input", () => {
|
package/types/dsl/Input.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { AssetPropsWithChildren, BindingTemplateInstance } from "@player-
|
|
2
|
+
import { AssetPropsWithChildren, BindingTemplateInstance } from "@player-lang/react-dsl";
|
|
3
3
|
import { InputAsset } from "../types";
|
|
4
4
|
export declare const Input: {
|
|
5
5
|
(props: Omit<AssetPropsWithChildren<InputAsset>, "binding"> & {
|
package/types/types/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { TextAsset } from "@devtools-ui/text";
|
|
2
2
|
import { Asset, Schema, AssetWrapper } from "@player-ui/types";
|
|
3
3
|
import { ValidationResponse } from "@player-ui/player";
|
|
4
|
-
export type InputSize = "xs" | "sm" | "md" | "lg";
|
|
5
|
-
type ValueType = string | undefined;
|
|
4
|
+
export declare type InputSize = "xs" | "sm" | "md" | "lg";
|
|
5
|
+
declare type ValueType = string | undefined;
|
|
6
6
|
export interface InputAsset extends Asset<"input"> {
|
|
7
7
|
/** The location in the data-model to store the data */
|
|
8
8
|
binding: ValueType;
|