ag-common 0.0.268 → 0.0.271

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.
@@ -28,6 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.BorderGradient = void 0;
30
30
  const colours_1 = require("../../styles/colours");
31
+ const object_1 = require("../../../common/helpers/object");
31
32
  const styled_components_1 = __importStar(require("styled-components"));
32
33
  const react_1 = __importDefault(require("react"));
33
34
  const BGcss = (0, styled_components_1.css) `
@@ -66,14 +67,14 @@ const FeatureBoxFill = (0, styled_components_1.default)(Padding) `
66
67
  `;
67
68
  const BorderGradient = ({ left = colours_1.colours.orange, right = colours_1.colours.orangeRed, children, radius = '2rem', fill = false, padding = '2rem', className, onClick, href, target, rel, noGrow = false, disabled = false, canClick = false, }) => {
68
69
  const CCND = canClick && !disabled;
69
- const style = {
70
+ const style = (0, object_1.removeUndefValuesFromObject)({
70
71
  flexGrow: noGrow ? 0 : 1,
71
72
  '--left': left,
72
73
  '--right': right,
73
74
  borderRadius: radius,
74
- filter: !disabled ? '' : 'grayscale(1)',
75
+ filter: !disabled ? null : 'grayscale(1)',
75
76
  cursor: CCND ? 'pointer' : 'default',
76
- };
77
+ });
77
78
  const props = {
78
79
  onClick: (e) => !disabled && onClick && onClick(e),
79
80
  className,
@@ -1,5 +1,9 @@
1
- export declare const CheckboxEdit: ({ defaultValue, onSubmit, noGrow, }: {
1
+ export declare const CheckboxEdit: ({ defaultValue, onSubmit, noGrow, allowUndo, }: {
2
2
  defaultValue: boolean;
3
3
  onSubmit: (val: boolean) => void;
4
4
  noGrow?: boolean | undefined;
5
+ /**
6
+ * if true, will add undo button after changes. if false, will submit after every keypress. default true
7
+ */
8
+ allowUndo?: boolean | undefined;
5
9
  }) => JSX.Element;
@@ -39,7 +39,7 @@ const Icons = (0, styled_components_1.default)(FlexRow_1.FlexRow) `
39
39
  top: 0;
40
40
  right: -2rem;
41
41
  `;
42
- const CheckboxEdit = ({ defaultValue, onSubmit, noGrow = false, }) => {
42
+ const CheckboxEdit = ({ defaultValue, onSubmit, noGrow = false, allowUndo = true, }) => {
43
43
  const ref = (0, react_1.useRef)(null);
44
44
  const [value, setValue] = (0, react_1.useState)(defaultValue);
45
45
  (0, react_1.useEffect)(() => {
@@ -52,11 +52,18 @@ const CheckboxEdit = ({ defaultValue, onSubmit, noGrow = false, }) => {
52
52
  }
53
53
  });
54
54
  return (react_1.default.createElement(common_1.ValueBox, Object.assign({}, common_2.noDrag, { ref: ref, "data-nogrow": noGrow }),
55
- react_1.default.createElement(common_1.ValueInputCB, { type: "checkbox", "data-type": "checkbox", checked: value, onChange: () => setValue(!value), onKeyPress: (e) => e.key === 'Enter' && value !== defaultValue && onSubmit(value) }),
56
- react_1.default.createElement(Icons, { center: true, enableOverflow: true },
55
+ react_1.default.createElement(common_1.ValueInputCB, { type: "checkbox", "data-type": "checkbox", checked: value, onChange: () => {
56
+ if (allowUndo) {
57
+ setValue(!value);
58
+ }
59
+ else {
60
+ onSubmit(!value);
61
+ }
62
+ }, onKeyPress: (e) => e.key === 'Enter' && value !== defaultValue && onSubmit(value) }),
63
+ allowUndo && (react_1.default.createElement(Icons, { center: true, enableOverflow: true },
57
64
  value !== defaultValue && (react_1.default.createElement(common_1.IconD, { style: common_1.iconLeft, onClick: () => value !== defaultValue && onSubmit(value) },
58
65
  react_1.default.createElement(images_1.SaveIcon, null))),
59
66
  value !== defaultValue && (react_1.default.createElement(common_1.IconD, { style: common_1.iconRight, onClick: () => setValue(defaultValue) },
60
- react_1.default.createElement(images_1.UndoIcon, null))))));
67
+ react_1.default.createElement(images_1.UndoIcon, null)))))));
61
68
  };
62
69
  exports.CheckboxEdit = CheckboxEdit;
@@ -1,4 +1,4 @@
1
1
  import { ITextEdit } from './types';
2
2
  import { StyledComponent } from 'styled-components';
3
3
  export declare const ValueReadonly: StyledComponent<"div", any, {}, never>;
4
- export declare const TextEdit: ({ defaultValue, defaultEditing, disableEdit, placeholder, className, singleLine, noGrow, attributes, leftContent, onSubmit, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, allowUndo, onEscape, maxLength, onKeyDown, }: ITextEdit) => JSX.Element;
4
+ export declare const TextEdit: (p: ITextEdit) => JSX.Element;
@@ -29,6 +29,7 @@ const common_1 = require("./common");
29
29
  const LengthBox_1 = require("./LengthBox");
30
30
  const useOnClickOutside_1 = require("../../helpers/useOnClickOutside");
31
31
  const common_2 = require("../../styles/common");
32
+ const dom_1 = require("../../helpers/dom");
32
33
  const styled_components_1 = __importStar(require("styled-components"));
33
34
  const react_1 = __importStar(require("react"));
34
35
  exports.ValueReadonly = styled_components_1.default.div `
@@ -81,7 +82,8 @@ const Icon = styled_components_1.default.div `
81
82
  filter: saturate(3);
82
83
  }
83
84
  `;
84
- const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, placeholder, className, singleLine = false, noGrow = false, attributes, leftContent, onSubmit, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, allowUndo = true, onEscape, maxLength, onKeyDown, }) => {
85
+ const TextEdit = (p) => {
86
+ const { defaultValue = '', defaultEditing, disableEdit = false, placeholder, className, singleLine = false, noGrow = false, leftContent, onSubmit, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, allowUndo = true, onEscape, maxLength, onKeyDown, } = p;
85
87
  const ref = (0, react_1.useRef)(null);
86
88
  const taref = (0, react_1.useRef)(null);
87
89
  const [value, setValue] = (0, react_1.useState)(defaultValue);
@@ -94,17 +96,16 @@ const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, plac
94
96
  }, () => {
95
97
  if (valueChange) {
96
98
  onSubmit(value, false);
99
+ return;
97
100
  }
98
- else {
99
- if (!disableEdit && onClickOutsideWithNoValue) {
100
- onClickOutsideWithNoValue();
101
- }
102
- if (!disableEdit && editing && defaultEditing) {
103
- return;
104
- }
105
- if (editing) {
106
- setEditingRaw(false);
107
- }
101
+ if (!disableEdit && onClickOutsideWithNoValue) {
102
+ onClickOutsideWithNoValue();
103
+ }
104
+ if (!disableEdit && editing && defaultEditing) {
105
+ return;
106
+ }
107
+ if (editing) {
108
+ setEditingRaw(false);
108
109
  }
109
110
  });
110
111
  const setEditing = (0, react_1.useCallback)((b) => {
@@ -124,7 +125,7 @@ const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, plac
124
125
  // eslint-disable-next-line react-hooks/exhaustive-deps
125
126
  }, []);
126
127
  if (!editing || disableEdit) {
127
- return (react_1.default.createElement(common_1.ValueBox, Object.assign({}, common_2.noDrag, { className: className, "data-editing": "false", onClick: () => onClickNotEditing === null || onClickNotEditing === void 0 ? void 0 : onClickNotEditing(), "data-pointer": onClickNotEditing ? 'true' : 'false', "data-nogrow": noGrow }, attributes),
128
+ return (react_1.default.createElement(common_1.ValueBox, Object.assign({}, common_2.noDrag, { className: className, "data-editing": "false", onClick: () => onClickNotEditing === null || onClickNotEditing === void 0 ? void 0 : onClickNotEditing(), "data-pointer": onClickNotEditing ? 'true' : 'false', "data-nogrow": noGrow }, (0, dom_1.filterDataProps)(p)),
128
129
  leftContent || null,
129
130
  react_1.default.createElement(exports.ValueReadonly, { "data-type": "text" }, value || react_1.default.createElement("span", { style: { color: '#ccc' } }, placeholder)),
130
131
  react_1.default.createElement(Right, null, !disableEdit && (react_1.default.createElement(Icon, { style: common_1.iconRight, onClick: (e) => {
@@ -140,7 +141,7 @@ const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, plac
140
141
  : ValueTextArea;
141
142
  return (react_1.default.createElement(ValueBoxEdit, Object.assign({}, common_2.noDrag, { className: className, "data-editing": "true",
142
143
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
- ref: ref, tabIndex: -1, "data-nogrow": noGrow }, attributes),
144
+ ref: ref, tabIndex: -1, "data-nogrow": noGrow }, (0, dom_1.filterDataProps)(p)),
144
145
  leftContent || null,
145
146
  react_1.default.createElement(Comp, { tabIndex: editing ? 0 : undefined, "data-editing": "true", "data-valuechange": valueChange.toString(), ref: taref, "data-type": "text", value: value, onChange: (v) => {
146
147
  setValue(v.currentTarget.value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.268",
3
+ "version": "0.0.271",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",