@code0-tech/pictor 0.2.3 → 0.4.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/dist/_virtual/compiler-runtime.js +5 -0
- package/dist/_virtual/compiler-runtime2.js +4 -0
- package/dist/_virtual/react-compiler-runtime.development.js +4 -0
- package/dist/_virtual/react-compiler-runtime.production.js +4 -0
- package/dist/assets/components/alert/Alert.style.css +1 -0
- package/dist/assets/components/aurora/Aurora.style.css +1 -0
- package/dist/assets/components/avatar/Avatar.style.css +1 -0
- package/dist/assets/components/badge/Badge.style.css +1 -0
- package/dist/assets/components/breadcrumb/Breadcrumb.style.css +1 -0
- package/dist/assets/components/button/Button.style.css +1 -0
- package/dist/assets/components/button-group/ButtonGroup.style.css +1 -0
- package/dist/assets/components/card/Card.style.css +1 -0
- package/dist/assets/components/col/Col.style.css +1 -0
- package/dist/assets/components/command/Command.style.css +1 -0
- package/dist/assets/components/container/Container.style.css +1 -0
- package/dist/assets/components/context-menu/ContextMenu.style.css +1 -0
- package/dist/assets/components/data-table/DataTable.style.css +1 -0
- package/dist/assets/components/dialog/Dialog.style.css +1 -0
- package/dist/assets/components/editor/Editor.styles.css +1 -0
- package/dist/assets/components/file-tabs/FileTabs.style.css +1 -0
- package/dist/assets/components/flex/Flex.style.css +1 -0
- package/dist/assets/components/form/Input.style.css +1 -0
- package/dist/assets/components/fullscreen/FullScreen.style.css +1 -0
- package/dist/assets/components/layout/Layout.style.css +1 -0
- package/dist/assets/components/menu/Menu.style.css +1 -0
- package/dist/assets/components/quote/Quote.style.css +1 -0
- package/dist/assets/components/resizable/Resizable.style.css +1 -0
- package/dist/assets/components/row/Row.style.css +1 -0
- package/dist/assets/components/scroll-area/ScrollArea.style.css +1 -0
- package/dist/assets/components/segmented-control/SegmentedControl.style.css +1 -0
- package/dist/assets/components/spacing/Spacing.style.css +1 -0
- package/dist/assets/components/tab/Tab.style.css +1 -0
- package/dist/assets/components/text/Text.style.css +1 -0
- package/dist/assets/components/toast/Toast.style.css +1 -0
- package/dist/assets/components/tooltip/Tooltip.style.css +1 -0
- package/dist/components/alert/Alert.d.ts +7 -0
- package/dist/components/alert/Alert.js +39 -0
- package/dist/components/aurora/Aurora.d.ts +5 -0
- package/dist/components/aurora/Aurora.js +23 -0
- package/dist/components/avatar/Avatar.d.ts +10 -0
- package/dist/components/avatar/Avatar.js +53 -0
- package/dist/components/badge/Badge.d.ts +8 -0
- package/dist/components/badge/Badge.js +63 -0
- package/dist/components/breadcrumb/Breadcrumb.d.ts +7 -0
- package/dist/components/breadcrumb/Breadcrumb.js +19 -0
- package/dist/components/button/Button.d.ts +11 -0
- package/dist/components/button/Button.js +31 -0
- package/dist/components/button-group/ButtonGroup.d.ts +8 -0
- package/dist/components/button-group/ButtonGroup.js +28 -0
- package/dist/components/card/Card.d.ts +15 -0
- package/dist/components/card/Card.js +42 -0
- package/dist/components/card/CardSection.d.ts +10 -0
- package/dist/components/card/CardSection.js +28 -0
- package/dist/{esm/components → components}/col/Col.d.ts +3 -5
- package/dist/components/col/Col.js +27 -0
- package/dist/components/command/Command.d.ts +30 -0
- package/dist/components/command/Command.js +103 -0
- package/dist/components/container/Container.d.ts +6 -0
- package/dist/components/container/Container.js +21 -0
- package/dist/components/context-menu/ContextMenu.d.ts +31 -0
- package/dist/components/context-menu/ContextMenu.js +106 -0
- package/dist/components/data-table/DataTable.d.ts +23 -0
- package/dist/components/data-table/DataTable.js +41 -0
- package/dist/components/data-table/DataTableColumn.d.ts +6 -0
- package/dist/components/data-table/DataTableColumn.js +22 -0
- package/dist/components/data-table/DataTableFilterInput.d.ts +18 -0
- package/dist/components/data-table/DataTableFilterInput.js +212 -0
- package/dist/components/data-table/DataTableFilterSuggestionMenu.d.ts +7 -0
- package/dist/components/data-table/DataTableFilterSuggestionMenu.js +53 -0
- package/dist/components/data-table/index.d.ts +4 -0
- package/dist/components/data-table/index.js +11 -0
- package/dist/components/dialog/Dialog.d.ts +29 -0
- package/dist/components/dialog/Dialog.js +102 -0
- package/dist/components/editor/Editor.d.ts +29 -0
- package/dist/components/editor/Editor.js +337 -0
- package/dist/components/file-tabs/FileTabs.d.ts +17 -0
- package/dist/components/file-tabs/FileTabs.js +71 -0
- package/dist/components/file-tabs/FileTabs.service.d.ts +17 -0
- package/dist/components/file-tabs/FileTabs.service.js +88 -0
- package/dist/components/file-tabs/FileTabs.view.d.ts +10 -0
- package/dist/components/file-tabs/FileTabs.view.js +1 -0
- package/dist/components/file-tabs/index.d.ts +3 -0
- package/dist/components/file-tabs/index.js +9 -0
- package/dist/components/flex/Flex.d.ts +7 -0
- package/dist/components/flex/Flex.js +21 -0
- package/dist/components/form/CheckboxInput.d.ts +5 -0
- package/dist/components/form/CheckboxInput.js +76 -0
- package/dist/components/form/EmailInput.d.ts +8 -0
- package/dist/components/form/EmailInput.js +21 -0
- package/dist/components/form/Input.d.ts +35 -0
- package/dist/components/form/Input.js +434 -0
- package/dist/components/form/Input.syntax.hook.d.ts +10 -0
- package/dist/components/form/Input.syntax.hook.js +14 -0
- package/dist/components/form/Input.utils.d.ts +10 -0
- package/dist/components/form/Input.utils.js +38 -0
- package/dist/components/form/InputContentEditable.hook.d.ts +52 -0
- package/dist/components/form/InputContentEditable.hook.js +449 -0
- package/dist/components/form/InputDescription.d.ts +5 -0
- package/dist/components/form/InputDescription.js +12 -0
- package/dist/components/form/InputLabel.d.ts +5 -0
- package/dist/components/form/InputLabel.js +12 -0
- package/dist/components/form/InputMessage.d.ts +5 -0
- package/dist/components/form/InputMessage.js +18 -0
- package/dist/components/form/InputSuggestion.d.ts +27 -0
- package/dist/components/form/InputSuggestion.js +218 -0
- package/dist/components/form/NumberInput.d.ts +6 -0
- package/dist/components/form/NumberInput.js +20 -0
- package/dist/components/form/PasswordInput.d.ts +8 -0
- package/dist/components/form/PasswordInput.js +19 -0
- package/dist/components/form/PinInput.d.ts +11 -0
- package/dist/components/form/PinInput.js +66 -0
- package/dist/components/form/RadioGroup.d.ts +5 -0
- package/dist/components/form/RadioGroup.js +48 -0
- package/dist/components/form/RadioInput.d.ts +7 -0
- package/dist/components/form/RadioInput.js +27 -0
- package/dist/components/form/SwitchInput.d.ts +6 -0
- package/dist/components/form/SwitchInput.js +19 -0
- package/dist/components/form/TextAreaInput.d.ts +7 -0
- package/dist/components/form/TextAreaInput.js +20 -0
- package/dist/components/form/TextInput.d.ts +7 -0
- package/dist/components/form/TextInput.js +20 -0
- package/dist/components/form/index.d.ts +17 -0
- package/dist/components/form/index.js +40 -0
- package/dist/components/form/useForm.d.ts +30 -0
- package/dist/components/form/useForm.js +78 -0
- package/dist/components/fullscreen/FullScreen.d.ts +6 -0
- package/dist/components/fullscreen/FullScreen.js +26 -0
- package/dist/components/layout/Layout.d.ts +12 -0
- package/dist/components/layout/Layout.js +75 -0
- package/dist/components/menu/Menu.d.ts +35 -0
- package/dist/components/menu/Menu.js +120 -0
- package/dist/components/quote/Quote.d.ts +10 -0
- package/dist/components/quote/Quote.js +44 -0
- package/dist/components/resizable/Resizable.d.ts +12 -0
- package/dist/components/resizable/Resizable.js +34 -0
- package/dist/components/row/Row.d.ts +6 -0
- package/dist/components/row/Row.js +21 -0
- package/dist/components/scroll-area/ScrollArea.d.ts +13 -0
- package/dist/components/scroll-area/ScrollArea.js +43 -0
- package/dist/components/segmented-control/SegmentedControl.d.ts +10 -0
- package/dist/components/segmented-control/SegmentedControl.js +26 -0
- package/dist/components/spacing/Spacing.d.ts +6 -0
- package/dist/components/spacing/Spacing.js +23 -0
- package/dist/components/tab/Tab.d.ts +11 -0
- package/dist/components/tab/Tab.js +40 -0
- package/dist/components/text/Text.d.ts +8 -0
- package/dist/components/text/Text.js +23 -0
- package/dist/components/toast/Toast.d.ts +13 -0
- package/dist/components/toast/Toast.js +66 -0
- package/dist/components/tooltip/Tooltip.d.ts +17 -0
- package/dist/components/tooltip/Tooltip.js +48 -0
- package/dist/index.d.ts +33 -300
- package/dist/index.js +191 -0
- package/dist/node_modules/@lezer/common/dist/index.js +146 -0
- package/dist/node_modules/@lezer/highlight/dist/index.js +543 -0
- package/dist/node_modules/prettier/plugins/babel.js +7157 -0
- package/dist/node_modules/prettier/plugins/estree.js +4453 -0
- package/dist/node_modules/prettier/standalone.js +2429 -0
- package/dist/node_modules/react/cjs/react-compiler-runtime.development.js +21 -0
- package/dist/node_modules/react/cjs/react-compiler-runtime.production.js +14 -0
- package/dist/node_modules/react/compiler-runtime.js +10 -0
- package/dist/utils/arrayService.d.ts +10 -0
- package/dist/utils/arrayService.js +1 -0
- package/dist/utils/contextStore.d.ts +62 -0
- package/dist/utils/contextStore.js +60 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.js +25 -0
- package/dist/utils/inspection.d.ts +15 -0
- package/dist/utils/inspection.js +29 -0
- package/dist/utils/nonReactiveArrayService.d.ts +19 -0
- package/dist/utils/nonReactiveArrayService.js +54 -0
- package/dist/utils/objectStore.d.ts +12 -0
- package/dist/utils/objectStore.js +34 -0
- package/dist/utils/reactiveArrayService.d.ts +23 -0
- package/dist/utils/reactiveArrayService.js +90 -0
- package/dist/{cjs/utils → utils}/types.d.ts +4 -4
- package/dist/utils/types.js +4 -0
- package/dist/utils/utils.d.ts +55 -0
- package/dist/utils/utils.js +159 -0
- package/dist/utils/view.d.ts +8 -0
- package/dist/utils/view.js +28 -0
- package/package.json +130 -54
- package/dist/cjs/components/Text/Text.d.ts +0 -10
- package/dist/cjs/components/alert/Alert.d.ts +0 -16
- package/dist/cjs/components/badge/Badge.d.ts +0 -9
- package/dist/cjs/components/button/Button.d.ts +0 -17
- package/dist/cjs/components/button-group/ButtonGroup.d.ts +0 -9
- package/dist/cjs/components/card/Card.d.ts +0 -20
- package/dist/cjs/components/col/Col.d.ts +0 -15
- package/dist/cjs/components/container/Container.d.ts +0 -8
- package/dist/cjs/components/dropdown/Dropdown.d.ts +0 -24
- package/dist/cjs/components/dropdown/DropdownFooter.d.ts +0 -13
- package/dist/cjs/components/dropdown/DropdownHeader.d.ts +0 -13
- package/dist/cjs/components/dropdown/DropdownItem.d.ts +0 -12
- package/dist/cjs/components/dropdown/DropdownItemGroup.d.ts +0 -12
- package/dist/cjs/components/input/Input.d.ts +0 -37
- package/dist/cjs/components/list-group/ListGroup.d.ts +0 -12
- package/dist/cjs/components/menu/InternalMenu.d.ts +0 -4
- package/dist/cjs/components/menu/Menu.d.ts +0 -41
- package/dist/cjs/components/popover/InternalPopover.d.ts +0 -10
- package/dist/cjs/components/popover/Popover.d.ts +0 -16
- package/dist/cjs/components/quote/Quote.d.ts +0 -12
- package/dist/cjs/components/row/Row.d.ts +0 -8
- package/dist/cjs/components/tooltip/Tooltip.d.ts +0 -18
- package/dist/cjs/index.d.ts +0 -16
- package/dist/cjs/index.js +0 -9275
- package/dist/cjs/utils/utils.d.ts +0 -18
- package/dist/esm/components/Text/Text.d.ts +0 -10
- package/dist/esm/components/alert/Alert.d.ts +0 -16
- package/dist/esm/components/badge/Badge.d.ts +0 -9
- package/dist/esm/components/button/Button.d.ts +0 -17
- package/dist/esm/components/button-group/ButtonGroup.d.ts +0 -9
- package/dist/esm/components/card/Card.d.ts +0 -20
- package/dist/esm/components/container/Container.d.ts +0 -8
- package/dist/esm/components/dropdown/Dropdown.d.ts +0 -24
- package/dist/esm/components/dropdown/DropdownFooter.d.ts +0 -13
- package/dist/esm/components/dropdown/DropdownHeader.d.ts +0 -13
- package/dist/esm/components/dropdown/DropdownItem.d.ts +0 -12
- package/dist/esm/components/dropdown/DropdownItemGroup.d.ts +0 -12
- package/dist/esm/components/input/Input.d.ts +0 -37
- package/dist/esm/components/list-group/ListGroup.d.ts +0 -12
- package/dist/esm/components/menu/InternalMenu.d.ts +0 -4
- package/dist/esm/components/menu/Menu.d.ts +0 -41
- package/dist/esm/components/popover/InternalPopover.d.ts +0 -10
- package/dist/esm/components/popover/Popover.d.ts +0 -16
- package/dist/esm/components/quote/Quote.d.ts +0 -12
- package/dist/esm/components/row/Row.d.ts +0 -8
- package/dist/esm/components/tooltip/Tooltip.d.ts +0 -18
- package/dist/esm/index.d.ts +0 -16
- package/dist/esm/index.js +0 -9251
- package/dist/esm/utils/types.d.ts +0 -57
- package/dist/esm/utils/utils.d.ts +0 -18
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { InputProps } from './Input';
|
|
3
|
+
interface EmailInputProps extends Omit<InputProps<string | null>, "wrapperComponent" | "type"> {
|
|
4
|
+
clearable?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare const emailValidation: (email: string) => boolean;
|
|
7
|
+
export declare const EmailInput: React.ForwardRefExoticComponent<EmailInputProps>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import r from "react";
|
|
3
|
+
import { Input as m } from "./Input.js";
|
|
4
|
+
import { IconX as l } from "@tabler/icons-react";
|
|
5
|
+
import { Button as f } from "../button/Button.js";
|
|
6
|
+
import { clearInputElement as s } from "./Input.utils.js";
|
|
7
|
+
const p = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/, d = (t) => p.test(t), R = r.forwardRef((t, x) => {
|
|
8
|
+
x = x || r.useRef(null);
|
|
9
|
+
const {
|
|
10
|
+
clearable: e = !1,
|
|
11
|
+
right: n,
|
|
12
|
+
...c
|
|
13
|
+
} = t, i = () => {
|
|
14
|
+
s(x.current);
|
|
15
|
+
}, a = [n];
|
|
16
|
+
return e && a.push(/* @__PURE__ */ o(f, { onClick: i, children: /* @__PURE__ */ o(l, { size: 13 }) })), /* @__PURE__ */ o(m, { right: a, type: "email", ref: x, ...c });
|
|
17
|
+
});
|
|
18
|
+
export {
|
|
19
|
+
R as EmailInput,
|
|
20
|
+
d as emailValidation
|
|
21
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { Code0Component } from '../../utils';
|
|
3
|
+
import { ValidationProps } from './useForm';
|
|
4
|
+
import { InputSuggestion } from './InputSuggestion';
|
|
5
|
+
import { InputSyntaxSegment } from './Input.syntax.hook';
|
|
6
|
+
export type Code0Input = Omit<Code0Component<HTMLInputElement>, "left" | "right" | "title" | "defaultValue" | "value">;
|
|
7
|
+
export interface InputProps<T> extends Code0Input, ValidationProps<T> {
|
|
8
|
+
suggestions?: InputSuggestion[];
|
|
9
|
+
suggestionsHeader?: React.ReactNode;
|
|
10
|
+
suggestionsFooter?: React.ReactNode;
|
|
11
|
+
onSuggestionSelect?: (suggestion: InputSuggestion) => void;
|
|
12
|
+
transformSyntax?: (value: T, appliedSyntaxParts?: (InputSuggestion | any)[]) => InputSyntaxSegment[];
|
|
13
|
+
validationUsesSyntax?: boolean;
|
|
14
|
+
disableOnValue?: (value: T) => boolean;
|
|
15
|
+
filterSuggestionsByLastToken?: boolean;
|
|
16
|
+
onLastTokenChange?: (token: string | null) => void;
|
|
17
|
+
enforceUniqueSuggestions?: boolean;
|
|
18
|
+
suggestionsEmptyState?: React.ReactNode;
|
|
19
|
+
wrapperComponent?: Code0Component<HTMLDivElement>;
|
|
20
|
+
right?: React.ReactNode;
|
|
21
|
+
left?: React.ReactNode;
|
|
22
|
+
leftType?: "action" | "placeholder" | "icon";
|
|
23
|
+
rightType?: "action" | "placeholder" | "icon";
|
|
24
|
+
title?: React.ReactNode;
|
|
25
|
+
description?: React.ReactNode;
|
|
26
|
+
}
|
|
27
|
+
export type InputElement = HTMLInputElement | HTMLDivElement;
|
|
28
|
+
export type InputActiveSuggestionSpan = {
|
|
29
|
+
id: number;
|
|
30
|
+
suggestion: InputSuggestion;
|
|
31
|
+
text: string;
|
|
32
|
+
start: number;
|
|
33
|
+
end: number;
|
|
34
|
+
};
|
|
35
|
+
export declare const Input: React.FC<InputProps<any>>;
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import { jsxs as j, jsx as p } from "react/jsx-runtime";
|
|
2
|
+
import l, { useRef as k, useState as q, useMemo as D, useEffect as T, useLayoutEffect as _e } from "react";
|
|
3
|
+
import "../../utils/contextStore.js";
|
|
4
|
+
import { mergeCode0Props as ue } from "../../utils/utils.js";
|
|
5
|
+
import '../../assets/components/form/Input.style.css';/* empty css */
|
|
6
|
+
import { InputLabel as et } from "./InputLabel.js";
|
|
7
|
+
import { InputDescription as tt } from "./InputDescription.js";
|
|
8
|
+
import { InputMessage as nt } from "./InputMessage.js";
|
|
9
|
+
import { Menu as rt, MenuTrigger as ot, MenuPortal as st } from "../menu/Menu.js";
|
|
10
|
+
import { InputSuggestionMenuContent as at, InputSuggestionMenuContentItems as ut } from "./InputSuggestion.js";
|
|
11
|
+
import { buildDefaultSyntax as it } from "./Input.syntax.hook.js";
|
|
12
|
+
import { getSelectionMetrics as lt, setElementKey as ct, setSelectionRangeSafe as ft } from "./Input.utils.js";
|
|
13
|
+
import { Card as dt } from "../card/Card.js";
|
|
14
|
+
import { useContentEditableController as pt, setSelectionOffsetsInValue as gt } from "./InputContentEditable.hook.js";
|
|
15
|
+
const W = (u) => {
|
|
16
|
+
const x = u ?? "";
|
|
17
|
+
return typeof x == "string" ? x : String(x);
|
|
18
|
+
}, ie = (u) => {
|
|
19
|
+
if (u == null) return "";
|
|
20
|
+
if (typeof u == "string") return u;
|
|
21
|
+
try {
|
|
22
|
+
return JSON.stringify(u);
|
|
23
|
+
} catch {
|
|
24
|
+
return String(u ?? "");
|
|
25
|
+
}
|
|
26
|
+
}, ht = (u) => {
|
|
27
|
+
if (u && typeof u == "object") {
|
|
28
|
+
const {
|
|
29
|
+
children: x,
|
|
30
|
+
__contentHtml: G,
|
|
31
|
+
...U
|
|
32
|
+
} = u;
|
|
33
|
+
return U;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
value: u
|
|
37
|
+
};
|
|
38
|
+
}, Ne = (u) => {
|
|
39
|
+
if (!u) return null;
|
|
40
|
+
const x = u.value ?? "", G = u.selectionStart ?? x.length, P = x.slice(0, G).match(/\S+$/);
|
|
41
|
+
if (!P || P.index === void 0) return null;
|
|
42
|
+
const C = P[0], H = P.index, X = H + C.length;
|
|
43
|
+
return {
|
|
44
|
+
token: C,
|
|
45
|
+
start: H,
|
|
46
|
+
end: X
|
|
47
|
+
};
|
|
48
|
+
}, mt = l.forwardRef((u, x) => {
|
|
49
|
+
const {
|
|
50
|
+
wrapperComponent: G = {},
|
|
51
|
+
title: U,
|
|
52
|
+
description: P,
|
|
53
|
+
disabled: C = !1,
|
|
54
|
+
left: H,
|
|
55
|
+
right: X,
|
|
56
|
+
leftType: ze = "icon",
|
|
57
|
+
rightType: je = "action",
|
|
58
|
+
formValidation: L = {
|
|
59
|
+
valid: !0,
|
|
60
|
+
notValidMessage: null,
|
|
61
|
+
setValue: null
|
|
62
|
+
},
|
|
63
|
+
suggestions: f,
|
|
64
|
+
suggestionsHeader: be,
|
|
65
|
+
suggestionsFooter: ve,
|
|
66
|
+
onSuggestionSelect: xe,
|
|
67
|
+
disableOnValue: we = () => !1,
|
|
68
|
+
transformSyntax: Y,
|
|
69
|
+
validationUsesSyntax: le = !1,
|
|
70
|
+
filterSuggestionsByLastToken: b = !1,
|
|
71
|
+
enforceUniqueSuggestions: Ve = !1,
|
|
72
|
+
onLastTokenChange: Ee,
|
|
73
|
+
suggestionsEmptyState: De,
|
|
74
|
+
...qe
|
|
75
|
+
} = u, {
|
|
76
|
+
onFocus: Ie,
|
|
77
|
+
onBlur: Z,
|
|
78
|
+
onKeyDown: _,
|
|
79
|
+
onKeyDownCapture: ce,
|
|
80
|
+
onChange: M,
|
|
81
|
+
onInput: R,
|
|
82
|
+
...h
|
|
83
|
+
} = qe, ee = k(null), m = k(null), $ = k(null), F = k(null), fe = k(null), w = k(!1), de = k(!1), We = k(0), Te = k(null), pe = h.value ?? u.initialValue ?? u.defaultValue, [Pe, Ue] = q(!1), K = k(!1), i = l.useCallback((e) => {
|
|
84
|
+
K.current = e, Ue(e);
|
|
85
|
+
}, []), [y, ge] = q(pe), [Le, Me] = q([]), [B, he] = q([]), [Re, He] = q(null), [A, Je] = q(null), s = !!Y, I = D(() => we(y), [we, y]), v = D(() => s ? $ : m, [s]);
|
|
86
|
+
l.useImperativeHandle(x, () => v.current ?? null);
|
|
87
|
+
const Oe = D(() => ({
|
|
88
|
+
...h
|
|
89
|
+
}), [h]), Qe = D(() => {
|
|
90
|
+
const {
|
|
91
|
+
value: e,
|
|
92
|
+
defaultValue: t,
|
|
93
|
+
...n
|
|
94
|
+
} = h;
|
|
95
|
+
return ue("input__control", n);
|
|
96
|
+
}, [h]), te = l.useCallback(() => {
|
|
97
|
+
const e = v.current;
|
|
98
|
+
!e || C || I || e.focus({
|
|
99
|
+
preventScroll: !0
|
|
100
|
+
});
|
|
101
|
+
}, [v, C, I]), N = l.useCallback(() => {
|
|
102
|
+
f && i(!0);
|
|
103
|
+
}, [f, i]), me = l.useCallback((e) => {
|
|
104
|
+
b && (He(e), e && i(!0), Ee?.(e));
|
|
105
|
+
}, [b, Ee, i]), J = l.useCallback((e, t) => {
|
|
106
|
+
if (!L?.setValue) return;
|
|
107
|
+
const n = h.type !== "checkbox" ? W(e) : e, o = le ? t : n;
|
|
108
|
+
Object.is(Te.current, o) || (Te.current = o, L.setValue(o));
|
|
109
|
+
}, [L?.setValue, h.type, le]), ne = l.useCallback((e) => {
|
|
110
|
+
const t = e.currentTarget, n = h.type === "checkbox" && "checked" in t ? t.checked : t.value;
|
|
111
|
+
ge(n), J(n, null);
|
|
112
|
+
}, [h.type, J]), g = pt({
|
|
113
|
+
editorRef: $,
|
|
114
|
+
transformSyntax: Y,
|
|
115
|
+
filterSuggestionsByLastToken: b,
|
|
116
|
+
onLastTokenChange: me,
|
|
117
|
+
onStateChange: ({
|
|
118
|
+
value: e,
|
|
119
|
+
tokens: t,
|
|
120
|
+
segments: n
|
|
121
|
+
}) => {
|
|
122
|
+
ge(e), he(t), Je(n ?? null), J(e, n ?? null);
|
|
123
|
+
}
|
|
124
|
+
}), $e = k(!1);
|
|
125
|
+
T(() => {
|
|
126
|
+
if (!s || !Y || $e.current) return;
|
|
127
|
+
const e = W(pe);
|
|
128
|
+
g.initializeFromExternalValue(e), $e.current = !0;
|
|
129
|
+
}, [s, Y, pe, le, g]), T(() => {
|
|
130
|
+
s || h.value !== void 0 && ge(h.value);
|
|
131
|
+
}, [h.value, s]), T(() => {
|
|
132
|
+
J(y, A);
|
|
133
|
+
}, [J, A, y]), T(() => {
|
|
134
|
+
if (!f) return;
|
|
135
|
+
const e = (t) => {
|
|
136
|
+
const n = t.target, o = !!$.current?.contains(n), a = !!m.current?.contains(n), r = !!fe.current?.contains(n), S = !!ee.current?.contains(n), c = o || a || r || S;
|
|
137
|
+
w.current = c, !c && K.current && i(!1);
|
|
138
|
+
};
|
|
139
|
+
return document.addEventListener("pointerdown", e, !0), () => document.removeEventListener("pointerdown", e, !0);
|
|
140
|
+
}, [f, i]), T(() => {
|
|
141
|
+
const e = ee.current;
|
|
142
|
+
if (!e) return;
|
|
143
|
+
const t = () => N();
|
|
144
|
+
return e.addEventListener("focusin", t), () => e.removeEventListener("focusin", t);
|
|
145
|
+
}, [N]);
|
|
146
|
+
const Fe = l.useCallback((e, t, n) => {
|
|
147
|
+
if (e.length === 0) return t <= n.length ? t : null;
|
|
148
|
+
let o = n.indexOf(e);
|
|
149
|
+
if (o === -1) return null;
|
|
150
|
+
let a = o;
|
|
151
|
+
for (; a !== -1; )
|
|
152
|
+
Math.abs(a - t) < Math.abs(o - t) && (o = a), a = n.indexOf(e, a + 1);
|
|
153
|
+
return o;
|
|
154
|
+
}, []), re = l.useCallback((e, t) => {
|
|
155
|
+
const n = [];
|
|
156
|
+
return e.forEach((o) => {
|
|
157
|
+
const a = Fe(o.text, o.start, t);
|
|
158
|
+
if (a === null) return;
|
|
159
|
+
const r = a + o.text.length;
|
|
160
|
+
t.slice(a, r) === o.text && n.push({
|
|
161
|
+
...o,
|
|
162
|
+
start: a,
|
|
163
|
+
end: r
|
|
164
|
+
});
|
|
165
|
+
}), n;
|
|
166
|
+
}, [Fe]);
|
|
167
|
+
T(() => {
|
|
168
|
+
if (s) return;
|
|
169
|
+
const e = W(m.current?.value ?? y);
|
|
170
|
+
Me((t) => {
|
|
171
|
+
const n = re(t, e);
|
|
172
|
+
return he(n.map((o) => o.suggestion)), n;
|
|
173
|
+
});
|
|
174
|
+
}, [s, re, y]), T(() => {
|
|
175
|
+
if (!b || s) return;
|
|
176
|
+
const e = m.current;
|
|
177
|
+
if (!e) return;
|
|
178
|
+
const t = () => me(Ne(e)?.token ?? null);
|
|
179
|
+
return e.addEventListener("input", t), e.addEventListener("keyup", t), e.addEventListener("mouseup", t), t(), () => {
|
|
180
|
+
e.removeEventListener("input", t), e.removeEventListener("keyup", t), e.removeEventListener("mouseup", t);
|
|
181
|
+
};
|
|
182
|
+
}, [b, s, me]);
|
|
183
|
+
const z = D(() => {
|
|
184
|
+
if (!b || !f) return f;
|
|
185
|
+
const e = Re?.trim();
|
|
186
|
+
return e?.length ? f.filter((t) => String(t?.value ?? "").toLowerCase().startsWith(e.toLowerCase())) : f;
|
|
187
|
+
}, [b, Re, f]), oe = D(() => {
|
|
188
|
+
if (!Ve || !z) return z;
|
|
189
|
+
if (s) {
|
|
190
|
+
const t = new Set((B ?? []).map((n) => ie(n?.value ?? n)));
|
|
191
|
+
return z.filter((n) => !t.has(ie(n?.value ?? n)));
|
|
192
|
+
}
|
|
193
|
+
const e = new Set(Le.map((t) => t.suggestion));
|
|
194
|
+
return z.filter((t) => !e.has(t));
|
|
195
|
+
}, [Le, B, Ve, z, s]), Ke = l.useCallback((e) => {
|
|
196
|
+
if (!m.current) return;
|
|
197
|
+
const t = typeof y == "object" ? JSON.stringify(e.value) : e.value, n = t == null ? "" : String(t), o = e.insertMode ?? "replace", a = m.current.value ?? "";
|
|
198
|
+
let r = a, S = null, c = 0;
|
|
199
|
+
const V = b ? Ne(m.current) : null;
|
|
200
|
+
if (b && V)
|
|
201
|
+
r = `${a.slice(0, V.start)}${n}${a.slice(V.end)}`, S = V.start + n.length, c = V.start;
|
|
202
|
+
else
|
|
203
|
+
switch (o) {
|
|
204
|
+
case "append":
|
|
205
|
+
r = `${a}${n}`, S = r.length, c = a.length;
|
|
206
|
+
break;
|
|
207
|
+
case "prepend":
|
|
208
|
+
r = `${n}${a}`, S = n.length, c = 0;
|
|
209
|
+
break;
|
|
210
|
+
case "insert": {
|
|
211
|
+
const {
|
|
212
|
+
rawStart: d,
|
|
213
|
+
rawEnd: O
|
|
214
|
+
} = lt(m.current);
|
|
215
|
+
r = `${a.slice(0, d)}${n}${a.slice(O)}`, S = d + n.length, c = d;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
default:
|
|
219
|
+
r = n, S = n.length, c = 0;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
ct(m.current, "value", r, "change"), Me((d) => {
|
|
223
|
+
const O = W(r), se = re(d, O), E = n.length ? {
|
|
224
|
+
id: We.current++,
|
|
225
|
+
suggestion: e,
|
|
226
|
+
text: n,
|
|
227
|
+
start: c,
|
|
228
|
+
end: c + n.length
|
|
229
|
+
} : null, ae = E ? [...se, E] : se;
|
|
230
|
+
return he(ae.map((Ze) => Ze.suggestion)), ae;
|
|
231
|
+
}), S !== null && requestAnimationFrame(() => {
|
|
232
|
+
const d = m.current;
|
|
233
|
+
d && (d.focus({
|
|
234
|
+
preventScroll: !0
|
|
235
|
+
}), ft(d, S, S));
|
|
236
|
+
});
|
|
237
|
+
}, [b, re, y]), Be = l.useCallback((e) => {
|
|
238
|
+
if (s ? g.applySuggestionValueSyntax(e) : Ke(e), xe?.(e), s) {
|
|
239
|
+
const t = v.current;
|
|
240
|
+
requestAnimationFrame(() => {
|
|
241
|
+
if (!t) return;
|
|
242
|
+
const n = {
|
|
243
|
+
type: "change",
|
|
244
|
+
target: t,
|
|
245
|
+
currentTarget: t
|
|
246
|
+
};
|
|
247
|
+
t.dispatchEvent(new Event("input", {
|
|
248
|
+
bubbles: !0
|
|
249
|
+
})), R?.(n), M?.(n);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
i(!1), w.current = !1, requestAnimationFrame(() => {
|
|
253
|
+
te();
|
|
254
|
+
});
|
|
255
|
+
}, [v, Ke, g, te, s, xe, i, M, R]), ye = l.useCallback((e) => {
|
|
256
|
+
N(), Ie?.(e);
|
|
257
|
+
}, [N, Ie]), Q = l.useCallback((e) => {
|
|
258
|
+
if (de.current) {
|
|
259
|
+
de.current = !1, Z?.(e);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (w.current) {
|
|
263
|
+
Z?.(e);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
i(!1), Z?.(e);
|
|
267
|
+
}, [Z, i]), Se = l.useCallback((e) => {
|
|
268
|
+
if (s) {
|
|
269
|
+
g.handleKeyDownCapture(e), ce?.(e);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
(e.key === " " || e.code === "Space") && (e.stopPropagation(), e.nativeEvent?.stopImmediatePropagation?.()), ce?.(e);
|
|
273
|
+
}, [g, s, ce]), Ce = l.useCallback((e) => {
|
|
274
|
+
if (f) {
|
|
275
|
+
if (e.key === "ArrowDown") {
|
|
276
|
+
e.preventDefault(), e.stopPropagation(), K.current ? F.current?.highlightNextItem?.() : (i(!0), setTimeout(() => F.current?.focusFirstItem?.(), 0));
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (e.key === "ArrowUp") {
|
|
280
|
+
e.preventDefault(), e.stopPropagation(), K.current ? F.current?.highlightPreviousItem?.() : (i(!0), setTimeout(() => F.current?.focusLastItem?.(), 0));
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (e.key === "Enter" && K.current) {
|
|
284
|
+
e.preventDefault(), e.stopPropagation(), F.current?.selectActiveItem?.() && i(!1);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (e.key === "Escape" && K.current) {
|
|
288
|
+
e.preventDefault(), e.stopPropagation(), i(!1);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (s && g.handleKeyDown(e)) {
|
|
293
|
+
if (e.key === "Backspace" || e.key === "Delete") {
|
|
294
|
+
const n = v.current;
|
|
295
|
+
if (n) {
|
|
296
|
+
const o = {
|
|
297
|
+
type: "change",
|
|
298
|
+
target: n,
|
|
299
|
+
currentTarget: n
|
|
300
|
+
};
|
|
301
|
+
R?.(o), M?.(o);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
_?.(e);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
if (s && e.key === "Enter") {
|
|
308
|
+
e.preventDefault(), _?.(e);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
_?.(e);
|
|
312
|
+
}, [v, g, s, f, i, M, R, _]), Ae = D(() => {
|
|
313
|
+
if (!s) return null;
|
|
314
|
+
const e = W(y), t = (A ?? []).filter(Boolean).filter((r) => r && (r.type === "text" || r.type === "block") && Number.isFinite(r.start) && Number.isFinite(r.end) && r.start <= r.end), n = t.length ? t : it(e), o = (B ?? []).slice(), a = [];
|
|
315
|
+
return n.forEach((r, S) => {
|
|
316
|
+
const c = r.value ?? e.slice(r.start, r.end);
|
|
317
|
+
if (r.type === "text") {
|
|
318
|
+
const E = typeof r.content == "string" ? r.content : typeof c == "string" ? c : e.slice(r.start, r.end);
|
|
319
|
+
E?.length && a.push(E);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const V = ie(c);
|
|
323
|
+
let d;
|
|
324
|
+
if (o.length) {
|
|
325
|
+
const E = o[0], ae = ie(E?.value ?? E);
|
|
326
|
+
(V === "" || ae === V) && (d = E, o.shift());
|
|
327
|
+
}
|
|
328
|
+
d || (d = {
|
|
329
|
+
value: c
|
|
330
|
+
});
|
|
331
|
+
const O = ht(d), se = r.content && typeof r.content != "string" || typeof r.content == "string" ? r.content : O?.label ?? O?.value ?? "";
|
|
332
|
+
a.push(/* @__PURE__ */ j(l.Fragment, { children: [
|
|
333
|
+
"",
|
|
334
|
+
/* @__PURE__ */ p("span", { className: "input__token", contentEditable: !1, "aria-data": JSON.stringify(O), style: {
|
|
335
|
+
display: "inline-flex",
|
|
336
|
+
alignItems: "center",
|
|
337
|
+
verticalAlign: "middle",
|
|
338
|
+
userSelect: "text",
|
|
339
|
+
WebkitUserSelect: "text"
|
|
340
|
+
}, children: se }),
|
|
341
|
+
""
|
|
342
|
+
] }, `${S}-${V}`));
|
|
343
|
+
}), a;
|
|
344
|
+
}, [B, s, A, y]);
|
|
345
|
+
_e(() => {
|
|
346
|
+
if (!s) return;
|
|
347
|
+
const e = $.current;
|
|
348
|
+
if (!e) return;
|
|
349
|
+
const t = g.takePendingSelection();
|
|
350
|
+
t && gt(e, t.start, t.end);
|
|
351
|
+
}, [g, s, Ae]);
|
|
352
|
+
const Ge = D(() => {
|
|
353
|
+
if (!s) return "plain";
|
|
354
|
+
const e = W(y), t = B?.length ?? 0, n = A?.length ?? 0;
|
|
355
|
+
return `${e}-${t}-${n}`;
|
|
356
|
+
}, [B, s, A, y]), ke = s ? /* @__PURE__ */ p("div", { ref: $, ...Qe, contentEditable: !C && !I, suppressContentEditableWarning: !0, "aria-disabled": C || I, onInput: (e) => {
|
|
357
|
+
g.updateEditorState($.current), f && (w.current = !0, de.current = !0, i(!0), requestAnimationFrame(() => {
|
|
358
|
+
w.current = !1;
|
|
359
|
+
}));
|
|
360
|
+
const t = e.currentTarget, n = {
|
|
361
|
+
type: "change",
|
|
362
|
+
target: t,
|
|
363
|
+
currentTarget: t
|
|
364
|
+
};
|
|
365
|
+
R?.(n), M?.(n);
|
|
366
|
+
}, onChange: (e) => {
|
|
367
|
+
g.handleChange(e);
|
|
368
|
+
}, onPaste: g.handlePaste, onFocus: ye, onBlur: Q, onKeyDownCapture: Se, onKeyDown: Ce, spellCheck: !1, children: Ae }, Ge) : u.type === "textarea" ? /* @__PURE__ */ p("textarea", { ref: m, ...ue("input__control", Oe), onFocus: ye, onBlur: Q, onKeyDownCapture: Se, onKeyDown: Ce, onInput: (e) => {
|
|
369
|
+
ne(e), R?.(e);
|
|
370
|
+
}, onChange: (e) => {
|
|
371
|
+
ne(e), M?.(e);
|
|
372
|
+
}, spellCheck: !1, disabled: C || I }) : /* @__PURE__ */ p("input", { ref: m, ...ue("input__control", Oe), onFocus: ye, onBlur: Q, onKeyDownCapture: Se, onKeyDown: Ce, onInput: (e) => {
|
|
373
|
+
ne(e), R?.(e);
|
|
374
|
+
}, onChange: (e) => {
|
|
375
|
+
ne(e), M?.(e);
|
|
376
|
+
}, spellCheck: !1, disabled: C || I }), Xe = l.useCallback((e) => {
|
|
377
|
+
if (C || I) return;
|
|
378
|
+
const t = e.target;
|
|
379
|
+
fe.current?.contains(t) || (w.current = !0, te(), N());
|
|
380
|
+
}, [C, I, te, N]);
|
|
381
|
+
T(() => {
|
|
382
|
+
const e = ee.current;
|
|
383
|
+
if (!e) return;
|
|
384
|
+
const t = (n) => {
|
|
385
|
+
const o = n.relatedTarget;
|
|
386
|
+
o && e.contains(o) || Q(n);
|
|
387
|
+
};
|
|
388
|
+
return e.addEventListener("focusout", t), () => e.removeEventListener("focusout", t);
|
|
389
|
+
}, [Q]);
|
|
390
|
+
const Ye = D(() => /* @__PURE__ */ j(rt, { open: Pe, modal: !1, onOpenChange: (e) => {
|
|
391
|
+
!e && w.current || i(e);
|
|
392
|
+
}, children: [
|
|
393
|
+
/* @__PURE__ */ p(ot, { asChild: !0, children: /* @__PURE__ */ p("button", { type: "button", tabIndex: -1, "aria-hidden": !0, style: {
|
|
394
|
+
position: "absolute",
|
|
395
|
+
inset: 0,
|
|
396
|
+
opacity: 0,
|
|
397
|
+
pointerEvents: "none"
|
|
398
|
+
}, onMouseDown: (e) => e.preventDefault() }) }),
|
|
399
|
+
ke,
|
|
400
|
+
/* @__PURE__ */ p(st, { children: /* @__PURE__ */ p("div", { ref: fe, onPointerDownCapture: () => {
|
|
401
|
+
w.current = !0;
|
|
402
|
+
}, onMouseDownCapture: (e) => {
|
|
403
|
+
e.preventDefault(), w.current = !0;
|
|
404
|
+
}, children: /* @__PURE__ */ j(at, { color: "secondary", inputRef: v, children: [
|
|
405
|
+
be,
|
|
406
|
+
/* @__PURE__ */ j(dt, { paddingSize: "xxs", mt: -0.2, mx: -0.2, children: [
|
|
407
|
+
oe?.length === 0 && De,
|
|
408
|
+
!!oe?.length && /* @__PURE__ */ p(
|
|
409
|
+
ut,
|
|
410
|
+
{
|
|
411
|
+
ref: F,
|
|
412
|
+
inputRef: v,
|
|
413
|
+
suggestions: oe,
|
|
414
|
+
onSuggestionSelect: Be
|
|
415
|
+
}
|
|
416
|
+
)
|
|
417
|
+
] }),
|
|
418
|
+
ve
|
|
419
|
+
] }) }) })
|
|
420
|
+
] }), [Pe, ke, s, oe, be, ve, De, Be, v, i]);
|
|
421
|
+
return /* @__PURE__ */ j("div", { children: [
|
|
422
|
+
U && /* @__PURE__ */ p(et, { children: U }),
|
|
423
|
+
P && /* @__PURE__ */ p(tt, { children: P }),
|
|
424
|
+
/* @__PURE__ */ j("div", { ref: ee, ...ue(`input ${L?.valid ? "" : "input--not-valid"}`, G), onPointerDown: Xe, children: [
|
|
425
|
+
H && /* @__PURE__ */ p("div", { className: `input__left input__left--${ze}`, children: H }),
|
|
426
|
+
f ? Ye : ke,
|
|
427
|
+
X && /* @__PURE__ */ p("div", { className: `input__right input__right--${je}`, children: X })
|
|
428
|
+
] }),
|
|
429
|
+
!L?.valid && L?.notValidMessage && /* @__PURE__ */ p(nt, { children: L.notValidMessage })
|
|
430
|
+
] });
|
|
431
|
+
}), Lt = mt;
|
|
432
|
+
export {
|
|
433
|
+
Lt as Input
|
|
434
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export type InputSyntaxSegment = {
|
|
3
|
+
type: "text" | "block";
|
|
4
|
+
value?: any;
|
|
5
|
+
start: number;
|
|
6
|
+
end: number;
|
|
7
|
+
visualLength?: number;
|
|
8
|
+
content?: string | React.ReactNode;
|
|
9
|
+
};
|
|
10
|
+
export declare const buildDefaultSyntax: (value: any) => InputSyntaxSegment[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const setElementKey: (element: HTMLElement, key: string, value: any, event: string) => void;
|
|
2
|
+
export declare const clearInputElement: (element: HTMLElement | null) => void;
|
|
3
|
+
export declare const setSelectionRangeSafe: (target: HTMLInputElement, start: number, end: number, direction?: "forward" | "backward" | "none") => void;
|
|
4
|
+
export declare const getSelectionMetrics: (target: HTMLInputElement) => {
|
|
5
|
+
selectionStart: number;
|
|
6
|
+
selectionEnd: number;
|
|
7
|
+
rawStart: number;
|
|
8
|
+
rawEnd: number;
|
|
9
|
+
direction: string;
|
|
10
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const a = (t, e, n, c) => {
|
|
2
|
+
const r = Object.getOwnPropertyDescriptor(t, e)?.set, s = Object.getPrototypeOf(t), o = Object.getOwnPropertyDescriptor(s, e)?.set;
|
|
3
|
+
r && r !== o ? o?.call(t, n) : r?.call(t, n), t.dispatchEvent(new Event(c, {
|
|
4
|
+
bubbles: !0
|
|
5
|
+
}));
|
|
6
|
+
}, i = (t) => {
|
|
7
|
+
if (t) {
|
|
8
|
+
if (t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement) {
|
|
9
|
+
a(t, "value", "", "change");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
t.contentEditable == "true" && (t.innerHTML = "", t.dispatchEvent(new Event("input", {
|
|
13
|
+
bubbles: !0
|
|
14
|
+
})), t.dispatchEvent(new Event("change", {
|
|
15
|
+
bubbles: !0
|
|
16
|
+
})));
|
|
17
|
+
}
|
|
18
|
+
}, p = (t, e, n, c) => {
|
|
19
|
+
try {
|
|
20
|
+
t.setSelectionRange(e, n, c);
|
|
21
|
+
} catch {
|
|
22
|
+
}
|
|
23
|
+
}, b = (t) => {
|
|
24
|
+
const e = t.selectionStart ?? 0, n = t.selectionEnd ?? e;
|
|
25
|
+
return {
|
|
26
|
+
selectionStart: e,
|
|
27
|
+
selectionEnd: n,
|
|
28
|
+
rawStart: Math.min(e, n),
|
|
29
|
+
rawEnd: Math.max(e, n),
|
|
30
|
+
direction: t.selectionDirection === "backward" ? "backward" : "forward"
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
i as clearInputElement,
|
|
35
|
+
b as getSelectionMetrics,
|
|
36
|
+
a as setElementKey,
|
|
37
|
+
p as setSelectionRangeSafe
|
|
38
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { InputSuggestion } from './InputSuggestion';
|
|
3
|
+
import { InputSyntaxSegment } from './Input.syntax.hook';
|
|
4
|
+
/**
|
|
5
|
+
* =========================
|
|
6
|
+
* Types
|
|
7
|
+
* =========================
|
|
8
|
+
*/
|
|
9
|
+
type EditorPart = string | InputSuggestion | any;
|
|
10
|
+
export type UseContentEditableControllerProps = {
|
|
11
|
+
editorRef: React.RefObject<HTMLElement>;
|
|
12
|
+
transformSyntax?: ((value: any, appliedSyntaxParts?: (InputSuggestion | any)[]) => InputSyntaxSegment[]) | undefined;
|
|
13
|
+
filterSuggestionsByLastToken?: boolean;
|
|
14
|
+
onLastTokenChange?: (token: string | null) => void;
|
|
15
|
+
onStateChange?: (payload: {
|
|
16
|
+
value: string;
|
|
17
|
+
tokens: InputSuggestion[];
|
|
18
|
+
segments?: InputSyntaxSegment[] | null;
|
|
19
|
+
}) => void;
|
|
20
|
+
};
|
|
21
|
+
export type UseContentEditableControllerReturn = {
|
|
22
|
+
editorHtml: string;
|
|
23
|
+
setEditorHtml: React.Dispatch<React.SetStateAction<string>>;
|
|
24
|
+
initializeFromExternalValue: (externalValue: string) => string;
|
|
25
|
+
updateEditorState: (rootEl: HTMLElement | null) => void;
|
|
26
|
+
takePendingSelection: () => {
|
|
27
|
+
start: number;
|
|
28
|
+
end: number;
|
|
29
|
+
} | null;
|
|
30
|
+
applySuggestionValueSyntax: (suggestion: InputSuggestion) => void;
|
|
31
|
+
handlePaste: (event: React.ClipboardEvent<HTMLDivElement>) => void;
|
|
32
|
+
handleChange: (event: React.FormEvent<HTMLDivElement>) => void;
|
|
33
|
+
handleKeyDownCapture: (event: React.KeyboardEvent<HTMLDivElement>) => void;
|
|
34
|
+
handleKeyDown: (event: React.KeyboardEvent<HTMLDivElement>) => boolean;
|
|
35
|
+
};
|
|
36
|
+
export declare const serializeEditorParts: (rootEl: HTMLElement | null) => EditorPart[];
|
|
37
|
+
/**
|
|
38
|
+
* ✅ FIX (caret after deleting last token):
|
|
39
|
+
* Selection can have startContainer = ELEMENT_NODE with an offset (i.e. “between childNodes”).
|
|
40
|
+
*/
|
|
41
|
+
export declare const getSelectionOffsetsInValue: (rootEl: HTMLElement) => {
|
|
42
|
+
start: number;
|
|
43
|
+
end: number;
|
|
44
|
+
} | null;
|
|
45
|
+
export declare const setSelectionOffsetsInValue: (rootEl: HTMLElement, start: number, end: number) => void;
|
|
46
|
+
/**
|
|
47
|
+
* =========================
|
|
48
|
+
* Hook
|
|
49
|
+
* =========================
|
|
50
|
+
*/
|
|
51
|
+
export declare const useContentEditableController: (props: UseContentEditableControllerProps) => UseContentEditableControllerReturn;
|
|
52
|
+
export {};
|