@visactor/vtable-editors 0.1.0-alpha.1

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 ADDED
@@ -0,0 +1,11 @@
1
+ # @visactor/vtable-editors
2
+
3
+ ## Description
4
+
5
+ The extension module for vtable.
6
+
7
+ ## Usage
8
+
9
+ ```typescript
10
+ import { xxx } from '@visactor/vtable-editors';
11
+ ```
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/base-editor.ts"],"names":[],"mappings":"","file":"base-editor.js","sourcesContent":["// import type { InputEditorConfig } from './input-editor';\n// import type { ListEditorConfig } from './list-editor';\n// import type { IEditor, Placement, RectProps } from './types';\n\n// //这个考虑下是否还需要 是直接使用IEditor就行的吗?\n// export class BaseEditor implements IEditor {\n// editorType: string;\n// editorConfig: ListEditorConfig | InputEditorConfig;\n// element: HTMLElement;\n// container: HTMLElement;\n// constructor() {\n// this.editorType = 'base';\n// }\n// createElement() {\n// // do nothing\n// }\n// setValue(value: string) {\n// // do nothing\n// }\n// getValue() {\n// return '';\n// }\n// beginEditing(container: HTMLElement, referencePosition: { rect: RectProps; placement?: Placement }, value?: string) {\n// // do nothing\n// }\n// targetIsOnEditor(target: HTMLElement) {\n// //\n// return false;\n// }\n// endEditing() {\n// // do nothing\n// }\n\n// exit(): void {\n// // do nothing\n// }\n// }\n"]}
@@ -0,0 +1,14 @@
1
+ import { InputEditor } from './input-editor';
2
+ import type { IEditor } from './types';
3
+ export interface DateInputEditorConfig {
4
+ max?: number;
5
+ min?: number;
6
+ }
7
+ export declare class DateInputEditor extends InputEditor implements IEditor {
8
+ editorType: string;
9
+ element: HTMLInputElement;
10
+ successCallback: Function;
11
+ constructor(editorConfig: DateInputEditorConfig);
12
+ createElement(): void;
13
+ bindSuccessCallback(success: Function): void;
14
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.DateInputEditor = void 0;
6
+
7
+ const input_editor_1 = require("./input-editor");
8
+
9
+ class DateInputEditor extends input_editor_1.InputEditor {
10
+ constructor(editorConfig) {
11
+ super(editorConfig), this.editorType = "DateInput", this.editorConfig = editorConfig;
12
+ }
13
+ createElement() {
14
+ const input = document.createElement("input");
15
+ input.setAttribute("type", "date"), input.style.padding = "4px", input.style.width = "100%",
16
+ input.style.boxSizing = "border-box", input.style.position = "absolute", this.element = input,
17
+ this.container.appendChild(input);
18
+ }
19
+ bindSuccessCallback(success) {
20
+ this.successCallback = success;
21
+ }
22
+ }
23
+
24
+ exports.DateInputEditor = DateInputEditor;
25
+ //# sourceMappingURL=date-input-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/date-input-editor.ts"],"names":[],"mappings":";;;AAAA,iDAA6C;AAO7C,MAAa,eAAgB,SAAQ,0BAAW;IAI9C,YAAY,YAAmC;QAC7C,KAAK,CAAC,YAAY,CAAC,CAAC;QAJtB,eAAU,GAAW,WAAW,CAAC;QAK/B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IACD,aAAa;QACX,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAE9C,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAEnC,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC;QAC5B,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC;QAC3B,KAAK,CAAC,KAAK,CAAC,SAAS,GAAG,YAAY,CAAC;QACrC,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,UAAU,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAMpC,CAAC;IACD,mBAAmB,CAAC,OAAiB;QACnC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC;IACjC,CAAC;CACF;AA5BD,0CA4BC","file":"date-input-editor.js","sourcesContent":["import { InputEditor } from './input-editor';\nimport type { IEditor } from './types';\nexport interface DateInputEditorConfig {\n max?: number;\n min?: number;\n}\n\nexport class DateInputEditor extends InputEditor implements IEditor {\n editorType: string = 'DateInput';\n declare element: HTMLInputElement;\n successCallback: Function;\n constructor(editorConfig: DateInputEditorConfig) {\n super(editorConfig);\n this.editorConfig = editorConfig;\n }\n createElement() {\n const input = document.createElement('input');\n\n input.setAttribute('type', 'date');\n\n input.style.padding = '4px';\n input.style.width = '100%';\n input.style.boxSizing = 'border-box';\n input.style.position = 'absolute';\n this.element = input;\n this.container.appendChild(input);\n // 测试successCallback 调用是否正确\n // input.ondblclick = () => {\n // debugger;\n // this.successCallback();\n // };\n }\n bindSuccessCallback(success: Function) {\n this.successCallback = success;\n }\n}\n"]}
package/cjs/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { InputEditor } from './input-editor';
2
+ import { DateInputEditor } from './date-input-editor';
3
+ import { ListEditor } from './list-editor';
4
+ export { InputEditor, DateInputEditor, ListEditor };
5
+ export * from './types';
package/cjs/index.js ADDED
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
4
+ void 0 === k2 && (k2 = k);
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
7
+ enumerable: !0,
8
+ get: function() {
9
+ return m[k];
10
+ }
11
+ }), Object.defineProperty(o, k2, desc);
12
+ } : function(o, m, k, k2) {
13
+ void 0 === k2 && (k2 = k), o[k2] = m[k];
14
+ }), __exportStar = this && this.__exportStar || function(m, exports) {
15
+ for (var p in m) "default" === p || Object.prototype.hasOwnProperty.call(exports, p) || __createBinding(exports, m, p);
16
+ };
17
+
18
+ Object.defineProperty(exports, "__esModule", {
19
+ value: !0
20
+ }), exports.ListEditor = exports.DateInputEditor = exports.InputEditor = void 0;
21
+
22
+ const input_editor_1 = require("./input-editor");
23
+
24
+ Object.defineProperty(exports, "InputEditor", {
25
+ enumerable: !0,
26
+ get: function() {
27
+ return input_editor_1.InputEditor;
28
+ }
29
+ });
30
+
31
+ const date_input_editor_1 = require("./date-input-editor");
32
+
33
+ Object.defineProperty(exports, "DateInputEditor", {
34
+ enumerable: !0,
35
+ get: function() {
36
+ return date_input_editor_1.DateInputEditor;
37
+ }
38
+ });
39
+
40
+ const list_editor_1 = require("./list-editor");
41
+
42
+ Object.defineProperty(exports, "ListEditor", {
43
+ enumerable: !0,
44
+ get: function() {
45
+ return list_editor_1.ListEditor;
46
+ }
47
+ }), __exportStar(require("./types"), exports);
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAA6C;AAGpC,4FAHA,0BAAW,OAGA;AAFpB,2DAAsD;AAEhC,gGAFb,mCAAe,OAEa;AADrC,+CAA2C;AACJ,2FAD9B,wBAAU,OAC8B;AACjD,0CAAwB","file":"index.js","sourcesContent":["import { InputEditor } from './input-editor';\nimport { DateInputEditor } from './date-input-editor';\nimport { ListEditor } from './list-editor';\nexport { InputEditor, DateInputEditor, ListEditor };\nexport * from './types';\n"]}
@@ -0,0 +1,23 @@
1
+ import type { IEditor, Placement, RectProps } from './types';
2
+ export interface InputEditorConfig {
3
+ max?: number;
4
+ min?: number;
5
+ }
6
+ export declare class InputEditor implements IEditor {
7
+ editorType: string;
8
+ editorConfig: InputEditorConfig;
9
+ container: HTMLElement;
10
+ element: HTMLInputElement;
11
+ constructor(editorConfig: InputEditorConfig);
12
+ createElement(): void;
13
+ setValue(value: string): void;
14
+ getValue(): string;
15
+ beginEditing(container: HTMLElement, referencePosition: {
16
+ rect: RectProps;
17
+ placement?: Placement;
18
+ }, value?: string): void;
19
+ adjustPosition(rect: RectProps): void;
20
+ endEditing(): void;
21
+ exit(): void;
22
+ targetIsOnEditor(target: HTMLElement): boolean;
23
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.InputEditor = void 0;
6
+
7
+ class InputEditor {
8
+ constructor(editorConfig) {
9
+ this.editorType = "Input", this.editorConfig = editorConfig;
10
+ }
11
+ createElement() {
12
+ const input = document.createElement("input");
13
+ input.setAttribute("type", "text"), input.style.position = "absolute", input.style.padding = "4px",
14
+ input.style.width = "100%", input.style.boxSizing = "border-box", this.element = input,
15
+ this.container.appendChild(input);
16
+ }
17
+ setValue(value) {
18
+ this.element.value = void 0 !== value ? value : "";
19
+ }
20
+ getValue() {
21
+ return this.element.value;
22
+ }
23
+ beginEditing(container, referencePosition, value) {
24
+ this.container = container, this.createElement(), value && this.setValue(value),
25
+ (null == referencePosition ? void 0 : referencePosition.rect) && this.adjustPosition(referencePosition.rect),
26
+ this.element.focus();
27
+ }
28
+ adjustPosition(rect) {
29
+ this.element.style.top = rect.top + "px", this.element.style.left = rect.left + "px",
30
+ this.element.style.width = rect.width + "px", this.element.style.height = rect.height + "px";
31
+ }
32
+ endEditing() {}
33
+ exit() {
34
+ this.container.removeChild(this.element);
35
+ }
36
+ targetIsOnEditor(target) {
37
+ return target === this.element;
38
+ }
39
+ }
40
+
41
+ exports.InputEditor = InputEditor;
42
+ //# sourceMappingURL=input-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/input-editor.ts"],"names":[],"mappings":";;;AAMA,MAAa,WAAW;IAKtB,YAAY,YAA+B;QAJ3C,eAAU,GAAW,OAAO,CAAC;QAK3B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IACD,aAAa;QACX,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC9C,KAAK,CAAC,YAAY,CAAC,MAAM,E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,CAAC,IAAI,GAAG,IAAI,CAAC;QAC3C,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAC7C,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACjD,CAAC;IACD,UAAU;IAEV,CAAC;IAED,IAAI;QAEF,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IACD,gBAAgB,CAAC,MAAmB;QAClC,IAAI,MAAM,KAAK,IAAI,CAAC,OAAO,EAAE;YAC3B,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA3DD,kCA2DC","file":"input-editor.js","sourcesContent":["import type { IEditor, Placement, RectProps } from './types';\nexport interface InputEditorConfig {\n max?: number;\n min?: number;\n}\n\nexport class InputEditor implements IEditor {\n editorType: string = 'Input';\n editorConfig: InputEditorConfig;\n container: HTMLElement;\n declare element: HTMLInputElement;\n constructor(editorConfig: InputEditorConfig) {\n this.editorConfig = editorConfig;\n }\n createElement() {\n const input = document.createElement('input');\n input.setAttribute('type', 'text');\n input.style.position = 'absolute';\n input.style.padding = '4px';\n input.style.width = '100%';\n input.style.boxSizing = 'border-box';\n this.element = input;\n\n this.container.appendChild(input);\n }\n setValue(value: string) {\n this.element.value = typeof value !== 'undefined' ? value : '';\n }\n getValue() {\n return this.element.value;\n }\n beginEditing(container: HTMLElement, referencePosition: { rect: RectProps; placement?: Placement }, value?: string) {\n console.log('input', 'beginEditing---- ');\n this.container = container;\n\n this.createElement();\n if (value) {\n this.setValue(value);\n }\n if (referencePosition?.rect) {\n this.adjustPosition(referencePosition.rect);\n }\n this.element.focus();\n // do nothing\n }\n adjustPosition(rect: RectProps) {\n this.element.style.top = rect.top + 'px';\n this.element.style.left = rect.left + 'px';\n this.element.style.width = rect.width + 'px';\n this.element.style.height = rect.height + 'px';\n }\n endEditing() {\n // do nothing\n }\n\n exit() {\n // do nothing\n this.container.removeChild(this.element);\n }\n targetIsOnEditor(target: HTMLElement) {\n if (target === this.element) {\n return true;\n }\n return false;\n }\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import type { IEditor, Placement, RectProps } from './types';
2
+ export interface ListEditorConfig {
3
+ values: string[];
4
+ }
5
+ export declare class ListEditor implements IEditor {
6
+ editorType: string;
7
+ input: HTMLInputElement;
8
+ editorConfig: ListEditorConfig;
9
+ container: HTMLElement;
10
+ element: HTMLSelectElement;
11
+ successCallback: Function;
12
+ constructor(editorConfig: ListEditorConfig);
13
+ createElement(value: string): void;
14
+ _bindSelectChangeEvent(): void;
15
+ setValue(value: string): void;
16
+ getValue(): string;
17
+ beginEditing(container: HTMLElement, referencePosition: {
18
+ rect: RectProps;
19
+ placement?: Placement;
20
+ }, value?: string): void;
21
+ adjustPosition(rect: RectProps): void;
22
+ endEditing(): void;
23
+ exit(): void;
24
+ targetIsOnEditor(target: HTMLElement): boolean;
25
+ bindSuccessCallback(success: Function): void;
26
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.ListEditor = void 0;
6
+
7
+ class ListEditor {
8
+ constructor(editorConfig) {
9
+ this.editorType = "Input", this.editorConfig = editorConfig;
10
+ }
11
+ createElement(value) {
12
+ const select = document.createElement("select");
13
+ select.setAttribute("type", "text"), select.style.position = "absolute", select.style.padding = "4px",
14
+ select.style.width = "100%", select.style.boxSizing = "border-box", this.element = select;
15
+ const {values: values} = this.editorConfig;
16
+ let opsStr = "";
17
+ values.forEach((item => {
18
+ opsStr += item === value ? `<option value=${item} selected>${item}</option>` : `<option value=${item} >${item}</option>`;
19
+ })), select.innerHTML = opsStr, this.container.appendChild(select);
20
+ }
21
+ _bindSelectChangeEvent() {
22
+ this.element.addEventListener("change", (() => {}));
23
+ }
24
+ setValue(value) {}
25
+ getValue() {
26
+ return this.element.value;
27
+ }
28
+ beginEditing(container, referencePosition, value) {
29
+ this.container = container, this.createElement(value), value && this.setValue(value),
30
+ (null == referencePosition ? void 0 : referencePosition.rect) && this.adjustPosition(referencePosition.rect),
31
+ this.element.focus();
32
+ }
33
+ adjustPosition(rect) {
34
+ this.element.style.top = rect.top + "px", this.element.style.left = rect.left + "px",
35
+ this.element.style.width = rect.width + "px", this.element.style.height = rect.height + "px";
36
+ }
37
+ endEditing() {}
38
+ exit() {
39
+ this.container.removeChild(this.element);
40
+ }
41
+ targetIsOnEditor(target) {
42
+ return target === this.element;
43
+ }
44
+ bindSuccessCallback(success) {
45
+ this.successCallback = success;
46
+ }
47
+ }
48
+
49
+ exports.ListEditor = ListEditor;
50
+ //# sourceMappingURL=list-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/list-editor.ts"],"names":[],"mappings":";;;AAKA,MAAa,UAAU;IAQrB,YAAY,YAA8B;QAP1C,eAAU,GAAW,OAAO,CAAC;QAQ3B,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACtC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED,aAAa,CAAC,KAAa;QAEzB,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACpC,MAAM,CAAC,KAAK,CAAC,QAAQ,GAAG,UAAU,CAAC;QACnC,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC;QAC7B,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC;QAC5B,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,YAAY,CAAC;QAEtC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QAGtB,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC;QACrC,IAAI,MAAM,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C,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAC7C,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACjD,CAAC;IAED,UAAU;IAEV,CAAC;IAED,IAAI;QACF,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,gBAAgB,CAAC,MAAmB;QAClC,IAAI,MAAM,KAAK,IAAI,CAAC,OAAO,EAAE;YAC3B,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,mBAAmB,CAAC,OAAiB;QACnC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC;IACjC,CAAC;CACF;AA1FD,gCA0FC","file":"list-editor.js","sourcesContent":["import type { IEditor, Placement, RectProps } from './types';\nexport interface ListEditorConfig {\n values: string[];\n}\n\nexport class ListEditor implements IEditor {\n editorType: string = 'Input';\n input: HTMLInputElement;\n editorConfig: ListEditorConfig;\n container: HTMLElement;\n element: HTMLSelectElement;\n successCallback: Function;\n\n constructor(editorConfig: ListEditorConfig) {\n console.log('listEditor constructor');\n this.editorConfig = editorConfig;\n }\n\n createElement(value: string) {\n // create select tag\n const select = document.createElement('select');\n select.setAttribute('type', 'text');\n select.style.position = 'absolute';\n select.style.padding = '4px';\n select.style.width = '100%';\n select.style.boxSizing = 'border-box';\n\n this.element = select;\n\n // create option tags\n const { values } = this.editorConfig;\n let opsStr = '';\n values.forEach(item => {\n opsStr +=\n item === value ? `<option value=${item} selected>${item}</option>` : `<option value=${item} >${item}</option>`;\n });\n select.innerHTML = opsStr;\n\n this.container.appendChild(select);\n // this._bindSelectChangeEvent();\n }\n\n _bindSelectChangeEvent() {\n this.element.addEventListener('change', () => {\n // this.successCallback();\n });\n }\n\n setValue(value: string) {\n // do nothing\n }\n\n getValue() {\n return this.element.value;\n }\n\n beginEditing(container: HTMLElement, referencePosition: { rect: RectProps; placement?: Placement }, value?: string) {\n this.container = container;\n\n this.createElement(value);\n\n if (value) {\n this.setValue(value);\n }\n if (referencePosition?.rect) {\n this.adjustPosition(referencePosition.rect);\n }\n this.element.focus();\n }\n\n adjustPosition(rect: RectProps) {\n this.element.style.top = rect.top + 'px';\n this.element.style.left = rect.left + 'px';\n this.element.style.width = rect.width + 'px';\n this.element.style.height = rect.height + 'px';\n }\n\n endEditing() {\n // do nothing\n }\n\n exit() {\n this.container.removeChild(this.element);\n }\n\n targetIsOnEditor(target: HTMLElement) {\n if (target === this.element) {\n return true;\n }\n return false;\n }\n\n bindSuccessCallback(success: Function) {\n this.successCallback = success;\n }\n}\n"]}
package/cjs/types.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ export interface IEditor {
2
+ editorType?: string;
3
+ editorConfig: any;
4
+ container: HTMLElement;
5
+ successCallback?: Function;
6
+ getValue: () => string | number | null;
7
+ beginEditing: (container: HTMLElement, referencePosition: {
8
+ rect: RectProps;
9
+ placement?: Placement;
10
+ }, value?: string) => void;
11
+ exit: () => void;
12
+ targetIsOnEditor: (target: HTMLElement) => boolean;
13
+ bindSuccessCallback?: (callback: Function) => void;
14
+ }
15
+ export interface RectProps {
16
+ left: number;
17
+ top: number;
18
+ width: number;
19
+ height: number;
20
+ }
21
+ export declare enum Placement {
22
+ top = "top",
23
+ bottom = "bottom",
24
+ left = "left",
25
+ right = "right"
26
+ }
package/cjs/types.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ var Placement;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: !0
7
+ }), exports.Placement = void 0, function(Placement) {
8
+ Placement.top = "top", Placement.bottom = "bottom", Placement.left = "left", Placement.right = "right";
9
+ }(Placement = exports.Placement || (exports.Placement = {}));
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"names":[],"mappings":";;;AA0BA,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,8BAAiB,CAAA;IACjB,0BAAa,CAAA;IACb,4BAAe,CAAA;AACjB,CAAC,EALW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAKpB","file":"types.js","sourcesContent":["export interface IEditor {\n /** 编辑器类型 */\n editorType?: string;\n /** 编辑配置 */\n editorConfig: any;\n container: HTMLElement;\n successCallback?: Function;\n // createElement: () => void;\n // setValue: (value: string) => void;\n getValue: () => string | number | null;\n beginEditing: (\n container: HTMLElement,\n referencePosition: { rect: RectProps; placement?: Placement },\n value?: string\n ) => void;\n // endEditing: () => void;\n exit: () => void;\n targetIsOnEditor: (target: HTMLElement) => boolean;\n bindSuccessCallback?: (callback: Function) => void;\n}\nexport interface RectProps {\n left: number;\n top: number;\n width: number;\n height: number;\n}\nexport enum Placement {\n top = 'top',\n bottom = 'bottom',\n left = 'left',\n right = 'right'\n}\n"]}
@@ -0,0 +1,163 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.VTable = global.VTable || {}, global.VTable.editors = {})));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ class InputEditor {
8
+ editorType = 'Input';
9
+ editorConfig;
10
+ container;
11
+ constructor(editorConfig) {
12
+ this.editorConfig = editorConfig;
13
+ }
14
+ createElement() {
15
+ const input = document.createElement('input');
16
+ input.setAttribute('type', 'text');
17
+ input.style.position = 'absolute';
18
+ input.style.padding = '4px';
19
+ input.style.width = '100%';
20
+ input.style.boxSizing = 'border-box';
21
+ this.element = input;
22
+ this.container.appendChild(input);
23
+ }
24
+ setValue(value) {
25
+ this.element.value = typeof value !== 'undefined' ? value : '';
26
+ }
27
+ getValue() {
28
+ return this.element.value;
29
+ }
30
+ beginEditing(container, referencePosition, value) {
31
+ this.container = container;
32
+ this.createElement();
33
+ if (value) {
34
+ this.setValue(value);
35
+ }
36
+ if (referencePosition?.rect) {
37
+ this.adjustPosition(referencePosition.rect);
38
+ }
39
+ this.element.focus();
40
+ }
41
+ adjustPosition(rect) {
42
+ this.element.style.top = rect.top + 'px';
43
+ this.element.style.left = rect.left + 'px';
44
+ this.element.style.width = rect.width + 'px';
45
+ this.element.style.height = rect.height + 'px';
46
+ }
47
+ endEditing() {
48
+ }
49
+ exit() {
50
+ this.container.removeChild(this.element);
51
+ }
52
+ targetIsOnEditor(target) {
53
+ if (target === this.element) {
54
+ return true;
55
+ }
56
+ return false;
57
+ }
58
+ }
59
+
60
+ class DateInputEditor extends InputEditor {
61
+ editorType = 'DateInput';
62
+ successCallback;
63
+ constructor(editorConfig) {
64
+ super(editorConfig);
65
+ this.editorConfig = editorConfig;
66
+ }
67
+ createElement() {
68
+ const input = document.createElement('input');
69
+ input.setAttribute('type', 'date');
70
+ input.style.padding = '4px';
71
+ input.style.width = '100%';
72
+ input.style.boxSizing = 'border-box';
73
+ input.style.position = 'absolute';
74
+ this.element = input;
75
+ this.container.appendChild(input);
76
+ }
77
+ bindSuccessCallback(success) {
78
+ this.successCallback = success;
79
+ }
80
+ }
81
+
82
+ class ListEditor {
83
+ editorType = 'Input';
84
+ input;
85
+ editorConfig;
86
+ container;
87
+ element;
88
+ successCallback;
89
+ constructor(editorConfig) {
90
+ this.editorConfig = editorConfig;
91
+ }
92
+ createElement(value) {
93
+ const select = document.createElement('select');
94
+ select.setAttribute('type', 'text');
95
+ select.style.position = 'absolute';
96
+ select.style.padding = '4px';
97
+ select.style.width = '100%';
98
+ select.style.boxSizing = 'border-box';
99
+ this.element = select;
100
+ const { values } = this.editorConfig;
101
+ let opsStr = '';
102
+ values.forEach(item => {
103
+ opsStr +=
104
+ item === value ? `<option value=${item} selected>${item}</option>` : `<option value=${item} >${item}</option>`;
105
+ });
106
+ select.innerHTML = opsStr;
107
+ this.container.appendChild(select);
108
+ }
109
+ _bindSelectChangeEvent() {
110
+ this.element.addEventListener('change', () => {
111
+ });
112
+ }
113
+ setValue(value) {
114
+ }
115
+ getValue() {
116
+ return this.element.value;
117
+ }
118
+ beginEditing(container, referencePosition, value) {
119
+ this.container = container;
120
+ this.createElement(value);
121
+ if (value) {
122
+ this.setValue(value);
123
+ }
124
+ if (referencePosition?.rect) {
125
+ this.adjustPosition(referencePosition.rect);
126
+ }
127
+ this.element.focus();
128
+ }
129
+ adjustPosition(rect) {
130
+ this.element.style.top = rect.top + 'px';
131
+ this.element.style.left = rect.left + 'px';
132
+ this.element.style.width = rect.width + 'px';
133
+ this.element.style.height = rect.height + 'px';
134
+ }
135
+ endEditing() {
136
+ }
137
+ exit() {
138
+ this.container.removeChild(this.element);
139
+ }
140
+ targetIsOnEditor(target) {
141
+ if (target === this.element) {
142
+ return true;
143
+ }
144
+ return false;
145
+ }
146
+ bindSuccessCallback(success) {
147
+ this.successCallback = success;
148
+ }
149
+ }
150
+
151
+ exports.Placement = void 0;
152
+ (function (Placement) {
153
+ Placement["top"] = "top";
154
+ Placement["bottom"] = "bottom";
155
+ Placement["left"] = "left";
156
+ Placement["right"] = "right";
157
+ })(exports.Placement || (exports.Placement = {}));
158
+
159
+ exports.DateInputEditor = DateInputEditor;
160
+ exports.InputEditor = InputEditor;
161
+ exports.ListEditor = ListEditor;
162
+
163
+ }));
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).VTable=e.VTable||{},e.VTable.editors={}))}(this,(function(e){"use strict";class t{editorType="Input";editorConfig;container;constructor(e){this.editorConfig=e}createElement(){const e=document.createElement("input");e.setAttribute("type","text"),e.style.position="absolute",e.style.padding="4px",e.style.width="100%",e.style.boxSizing="border-box",this.element=e,this.container.appendChild(e)}setValue(e){this.element.value=void 0!==e?e:""}getValue(){return this.element.value}beginEditing(e,t,i){this.container=e,this.createElement(),i&&this.setValue(i),t?.rect&&this.adjustPosition(t.rect),this.element.focus()}adjustPosition(e){this.element.style.top=e.top+"px",this.element.style.left=e.left+"px",this.element.style.width=e.width+"px",this.element.style.height=e.height+"px"}endEditing(){}exit(){this.container.removeChild(this.element)}targetIsOnEditor(e){return e===this.element}}var i;e.Placement=void 0,(i=e.Placement||(e.Placement={})).top="top",i.bottom="bottom",i.left="left",i.right="right",e.DateInputEditor=class extends t{editorType="DateInput";successCallback;constructor(e){super(e),this.editorConfig=e}createElement(){const e=document.createElement("input");e.setAttribute("type","date"),e.style.padding="4px",e.style.width="100%",e.style.boxSizing="border-box",e.style.position="absolute",this.element=e,this.container.appendChild(e)}bindSuccessCallback(e){this.successCallback=e}},e.InputEditor=t,e.ListEditor=class{editorType="Input";input;editorConfig;container;element;successCallback;constructor(e){this.editorConfig=e}createElement(e){const t=document.createElement("select");t.setAttribute("type","text"),t.style.position="absolute",t.style.padding="4px",t.style.width="100%",t.style.boxSizing="border-box",this.element=t;const{values:i}=this.editorConfig;let n="";i.forEach((t=>{n+=t===e?`<option value=${t} selected>${t}</option>`:`<option value=${t} >${t}</option>`})),t.innerHTML=n,this.container.appendChild(t)}_bindSelectChangeEvent(){this.element.addEventListener("change",(()=>{}))}setValue(e){}getValue(){return this.element.value}beginEditing(e,t,i){this.container=e,this.createElement(i),i&&this.setValue(i),t?.rect&&this.adjustPosition(t.rect),this.element.focus()}adjustPosition(e){this.element.style.top=e.top+"px",this.element.style.left=e.left+"px",this.element.style.width=e.width+"px",this.element.style.height=e.height+"px"}endEditing(){}exit(){this.container.removeChild(this.element)}targetIsOnEditor(e){return e===this.element}bindSuccessCallback(e){this.successCallback=e}}}));
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/base-editor.ts"],"names":[],"mappings":"","file":"base-editor.js","sourcesContent":["// import type { InputEditorConfig } from './input-editor';\n// import type { ListEditorConfig } from './list-editor';\n// import type { IEditor, Placement, RectProps } from './types';\n\n// //这个考虑下是否还需要 是直接使用IEditor就行的吗?\n// export class BaseEditor implements IEditor {\n// editorType: string;\n// editorConfig: ListEditorConfig | InputEditorConfig;\n// element: HTMLElement;\n// container: HTMLElement;\n// constructor() {\n// this.editorType = 'base';\n// }\n// createElement() {\n// // do nothing\n// }\n// setValue(value: string) {\n// // do nothing\n// }\n// getValue() {\n// return '';\n// }\n// beginEditing(container: HTMLElement, referencePosition: { rect: RectProps; placement?: Placement }, value?: string) {\n// // do nothing\n// }\n// targetIsOnEditor(target: HTMLElement) {\n// //\n// return false;\n// }\n// endEditing() {\n// // do nothing\n// }\n\n// exit(): void {\n// // do nothing\n// }\n// }\n"]}
@@ -0,0 +1,14 @@
1
+ import { InputEditor } from './input-editor';
2
+ import type { IEditor } from './types';
3
+ export interface DateInputEditorConfig {
4
+ max?: number;
5
+ min?: number;
6
+ }
7
+ export declare class DateInputEditor extends InputEditor implements IEditor {
8
+ editorType: string;
9
+ element: HTMLInputElement;
10
+ successCallback: Function;
11
+ constructor(editorConfig: DateInputEditorConfig);
12
+ createElement(): void;
13
+ bindSuccessCallback(success: Function): void;
14
+ }
@@ -0,0 +1,17 @@
1
+ import { InputEditor } from "./input-editor";
2
+
3
+ export class DateInputEditor extends InputEditor {
4
+ constructor(editorConfig) {
5
+ super(editorConfig), this.editorType = "DateInput", this.editorConfig = editorConfig;
6
+ }
7
+ createElement() {
8
+ const input = document.createElement("input");
9
+ input.setAttribute("type", "date"), input.style.padding = "4px", input.style.width = "100%",
10
+ input.style.boxSizing = "border-box", input.style.position = "absolute", this.element = input,
11
+ this.container.appendChild(input);
12
+ }
13
+ bindSuccessCallback(success) {
14
+ this.successCallback = success;
15
+ }
16
+ }
17
+ //# sourceMappingURL=date-input-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/date-input-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAO7C,MAAM,OAAO,eAAgB,SAAQ,WAAW;IAI9C,YAAY,YAAmC;QAC7C,KAAK,CAAC,YAAY,CAAC,CAAC;QAJtB,eAAU,GAAW,WAAW,CAAC;QAK/B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IACD,aAAa;QACX,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAE9C,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAEnC,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC;QAC5B,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC;QAC3B,KAAK,CAAC,KAAK,CAAC,SAAS,GAAG,YAAY,CAAC;QACrC,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,UAAU,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAMpC,CAAC;IACD,mBAAmB,CAAC,OAAiB;QACnC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC;IACjC,CAAC;CACF","file":"date-input-editor.js","sourcesContent":["import { InputEditor } from './input-editor';\nimport type { IEditor } from './types';\nexport interface DateInputEditorConfig {\n max?: number;\n min?: number;\n}\n\nexport class DateInputEditor extends InputEditor implements IEditor {\n editorType: string = 'DateInput';\n declare element: HTMLInputElement;\n successCallback: Function;\n constructor(editorConfig: DateInputEditorConfig) {\n super(editorConfig);\n this.editorConfig = editorConfig;\n }\n createElement() {\n const input = document.createElement('input');\n\n input.setAttribute('type', 'date');\n\n input.style.padding = '4px';\n input.style.width = '100%';\n input.style.boxSizing = 'border-box';\n input.style.position = 'absolute';\n this.element = input;\n this.container.appendChild(input);\n // 测试successCallback 调用是否正确\n // input.ondblclick = () => {\n // debugger;\n // this.successCallback();\n // };\n }\n bindSuccessCallback(success: Function) {\n this.successCallback = success;\n }\n}\n"]}
package/es/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { InputEditor } from './input-editor';
2
+ import { DateInputEditor } from './date-input-editor';
3
+ import { ListEditor } from './list-editor';
4
+ export { InputEditor, DateInputEditor, ListEditor };
5
+ export * from './types';
package/es/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import { InputEditor } from "./input-editor";
2
+
3
+ import { DateInputEditor } from "./date-input-editor";
4
+
5
+ import { ListEditor } from "./list-editor";
6
+
7
+ export { InputEditor, DateInputEditor, ListEditor };
8
+
9
+ export * from "./types";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC;AACpD,cAAc,SAAS,CAAC","file":"index.js","sourcesContent":["import { InputEditor } from './input-editor';\nimport { DateInputEditor } from './date-input-editor';\nimport { ListEditor } from './list-editor';\nexport { InputEditor, DateInputEditor, ListEditor };\nexport * from './types';\n"]}
@@ -0,0 +1,23 @@
1
+ import type { IEditor, Placement, RectProps } from './types';
2
+ export interface InputEditorConfig {
3
+ max?: number;
4
+ min?: number;
5
+ }
6
+ export declare class InputEditor implements IEditor {
7
+ editorType: string;
8
+ editorConfig: InputEditorConfig;
9
+ container: HTMLElement;
10
+ element: HTMLInputElement;
11
+ constructor(editorConfig: InputEditorConfig);
12
+ createElement(): void;
13
+ setValue(value: string): void;
14
+ getValue(): string;
15
+ beginEditing(container: HTMLElement, referencePosition: {
16
+ rect: RectProps;
17
+ placement?: Placement;
18
+ }, value?: string): void;
19
+ adjustPosition(rect: RectProps): void;
20
+ endEditing(): void;
21
+ exit(): void;
22
+ targetIsOnEditor(target: HTMLElement): boolean;
23
+ }
@@ -0,0 +1,34 @@
1
+ export class InputEditor {
2
+ constructor(editorConfig) {
3
+ this.editorType = "Input", this.editorConfig = editorConfig;
4
+ }
5
+ createElement() {
6
+ const input = document.createElement("input");
7
+ input.setAttribute("type", "text"), input.style.position = "absolute", input.style.padding = "4px",
8
+ input.style.width = "100%", input.style.boxSizing = "border-box", this.element = input,
9
+ this.container.appendChild(input);
10
+ }
11
+ setValue(value) {
12
+ this.element.value = void 0 !== value ? value : "";
13
+ }
14
+ getValue() {
15
+ return this.element.value;
16
+ }
17
+ beginEditing(container, referencePosition, value) {
18
+ this.container = container, this.createElement(), value && this.setValue(value),
19
+ (null == referencePosition ? void 0 : referencePosition.rect) && this.adjustPosition(referencePosition.rect),
20
+ this.element.focus();
21
+ }
22
+ adjustPosition(rect) {
23
+ this.element.style.top = rect.top + "px", this.element.style.left = rect.left + "px",
24
+ this.element.style.width = rect.width + "px", this.element.style.height = rect.height + "px";
25
+ }
26
+ endEditing() {}
27
+ exit() {
28
+ this.container.removeChild(this.element);
29
+ }
30
+ targetIsOnEditor(target) {
31
+ return target === this.element;
32
+ }
33
+ }
34
+ //# sourceMappingURL=input-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/input-editor.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,WAAW;IAKtB,YAAY,YAA+B;QAJ3C,eAAU,GAAW,OAAO,CAAC;QAK3B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IACD,aAAa;QACX,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC9C,KAAK,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnC,KAAK,CAAC,KAAK,CAAC,QAAQ,GAAG,UAAU,CAAC;QAClC,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC;QAC5B,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC;QAC3B,KAA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AG,IAAI,CAAC;IACjD,CAAC;IACD,UAAU;IAEV,CAAC;IAED,IAAI;QAEF,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IACD,gBAAgB,CAAC,MAAmB;QAClC,IAAI,MAAM,KAAK,IAAI,CAAC,OAAO,EAAE;YAC3B,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF","file":"input-editor.js","sourcesContent":["import type { IEditor, Placement, RectProps } from './types';\nexport interface InputEditorConfig {\n max?: number;\n min?: number;\n}\n\nexport class InputEditor implements IEditor {\n editorType: string = 'Input';\n editorConfig: InputEditorConfig;\n container: HTMLElement;\n declare element: HTMLInputElement;\n constructor(editorConfig: InputEditorConfig) {\n this.editorConfig = editorConfig;\n }\n createElement() {\n const input = document.createElement('input');\n input.setAttribute('type', 'text');\n input.style.position = 'absolute';\n input.style.padding = '4px';\n input.style.width = '100%';\n input.style.boxSizing = 'border-box';\n this.element = input;\n\n this.container.appendChild(input);\n }\n setValue(value: string) {\n this.element.value = typeof value !== 'undefined' ? value : '';\n }\n getValue() {\n return this.element.value;\n }\n beginEditing(container: HTMLElement, referencePosition: { rect: RectProps; placement?: Placement }, value?: string) {\n console.log('input', 'beginEditing---- ');\n this.container = container;\n\n this.createElement();\n if (value) {\n this.setValue(value);\n }\n if (referencePosition?.rect) {\n this.adjustPosition(referencePosition.rect);\n }\n this.element.focus();\n // do nothing\n }\n adjustPosition(rect: RectProps) {\n this.element.style.top = rect.top + 'px';\n this.element.style.left = rect.left + 'px';\n this.element.style.width = rect.width + 'px';\n this.element.style.height = rect.height + 'px';\n }\n endEditing() {\n // do nothing\n }\n\n exit() {\n // do nothing\n this.container.removeChild(this.element);\n }\n targetIsOnEditor(target: HTMLElement) {\n if (target === this.element) {\n return true;\n }\n return false;\n }\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import type { IEditor, Placement, RectProps } from './types';
2
+ export interface ListEditorConfig {
3
+ values: string[];
4
+ }
5
+ export declare class ListEditor implements IEditor {
6
+ editorType: string;
7
+ input: HTMLInputElement;
8
+ editorConfig: ListEditorConfig;
9
+ container: HTMLElement;
10
+ element: HTMLSelectElement;
11
+ successCallback: Function;
12
+ constructor(editorConfig: ListEditorConfig);
13
+ createElement(value: string): void;
14
+ _bindSelectChangeEvent(): void;
15
+ setValue(value: string): void;
16
+ getValue(): string;
17
+ beginEditing(container: HTMLElement, referencePosition: {
18
+ rect: RectProps;
19
+ placement?: Placement;
20
+ }, value?: string): void;
21
+ adjustPosition(rect: RectProps): void;
22
+ endEditing(): void;
23
+ exit(): void;
24
+ targetIsOnEditor(target: HTMLElement): boolean;
25
+ bindSuccessCallback(success: Function): void;
26
+ }
@@ -0,0 +1,42 @@
1
+ export class ListEditor {
2
+ constructor(editorConfig) {
3
+ this.editorType = "Input", this.editorConfig = editorConfig;
4
+ }
5
+ createElement(value) {
6
+ const select = document.createElement("select");
7
+ select.setAttribute("type", "text"), select.style.position = "absolute", select.style.padding = "4px",
8
+ select.style.width = "100%", select.style.boxSizing = "border-box", this.element = select;
9
+ const {values: values} = this.editorConfig;
10
+ let opsStr = "";
11
+ values.forEach((item => {
12
+ opsStr += item === value ? `<option value=${item} selected>${item}</option>` : `<option value=${item} >${item}</option>`;
13
+ })), select.innerHTML = opsStr, this.container.appendChild(select);
14
+ }
15
+ _bindSelectChangeEvent() {
16
+ this.element.addEventListener("change", (() => {}));
17
+ }
18
+ setValue(value) {}
19
+ getValue() {
20
+ return this.element.value;
21
+ }
22
+ beginEditing(container, referencePosition, value) {
23
+ this.container = container, this.createElement(value), value && this.setValue(value),
24
+ (null == referencePosition ? void 0 : referencePosition.rect) && this.adjustPosition(referencePosition.rect),
25
+ this.element.focus();
26
+ }
27
+ adjustPosition(rect) {
28
+ this.element.style.top = rect.top + "px", this.element.style.left = rect.left + "px",
29
+ this.element.style.width = rect.width + "px", this.element.style.height = rect.height + "px";
30
+ }
31
+ endEditing() {}
32
+ exit() {
33
+ this.container.removeChild(this.element);
34
+ }
35
+ targetIsOnEditor(target) {
36
+ return target === this.element;
37
+ }
38
+ bindSuccessCallback(success) {
39
+ this.successCallback = success;
40
+ }
41
+ }
42
+ //# sourceMappingURL=list-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/list-editor.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,UAAU;IAQrB,YAAY,YAA8B;QAP1C,eAAU,GAAW,OAAO,CAAC;QAQ3B,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACtC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED,aAAa,CAAC,KAAa;QAEzB,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACpC,MAAM,CAAC,KAAK,CAAC,QAAQ,GAAG,UAAU,CAAC;QACnC,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC;QAC7B,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC;QAC5B,MAAM,CAAC,KAAK,CAAC,SAAS,GAAG,YAAY,CAAC;QAEtC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QAGtB,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC;QACrC,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACpB,MAAM;gBACJ,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,iBAAiB,IAAI,aAAa,IAAI,WAAW,CAAC,CAAC,CAAC,iBAAiB,IAAI,KAAK,IAAI,WAAW,CAAC;QACnH,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC;QAE1B,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM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AAM,KAAK,IAAI,CAAC,OAAO,EAAE;YAC3B,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,mBAAmB,CAAC,OAAiB;QACnC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC;IACjC,CAAC;CACF","file":"list-editor.js","sourcesContent":["import type { IEditor, Placement, RectProps } from './types';\nexport interface ListEditorConfig {\n values: string[];\n}\n\nexport class ListEditor implements IEditor {\n editorType: string = 'Input';\n input: HTMLInputElement;\n editorConfig: ListEditorConfig;\n container: HTMLElement;\n element: HTMLSelectElement;\n successCallback: Function;\n\n constructor(editorConfig: ListEditorConfig) {\n console.log('listEditor constructor');\n this.editorConfig = editorConfig;\n }\n\n createElement(value: string) {\n // create select tag\n const select = document.createElement('select');\n select.setAttribute('type', 'text');\n select.style.position = 'absolute';\n select.style.padding = '4px';\n select.style.width = '100%';\n select.style.boxSizing = 'border-box';\n\n this.element = select;\n\n // create option tags\n const { values } = this.editorConfig;\n let opsStr = '';\n values.forEach(item => {\n opsStr +=\n item === value ? `<option value=${item} selected>${item}</option>` : `<option value=${item} >${item}</option>`;\n });\n select.innerHTML = opsStr;\n\n this.container.appendChild(select);\n // this._bindSelectChangeEvent();\n }\n\n _bindSelectChangeEvent() {\n this.element.addEventListener('change', () => {\n // this.successCallback();\n });\n }\n\n setValue(value: string) {\n // do nothing\n }\n\n getValue() {\n return this.element.value;\n }\n\n beginEditing(container: HTMLElement, referencePosition: { rect: RectProps; placement?: Placement }, value?: string) {\n this.container = container;\n\n this.createElement(value);\n\n if (value) {\n this.setValue(value);\n }\n if (referencePosition?.rect) {\n this.adjustPosition(referencePosition.rect);\n }\n this.element.focus();\n }\n\n adjustPosition(rect: RectProps) {\n this.element.style.top = rect.top + 'px';\n this.element.style.left = rect.left + 'px';\n this.element.style.width = rect.width + 'px';\n this.element.style.height = rect.height + 'px';\n }\n\n endEditing() {\n // do nothing\n }\n\n exit() {\n this.container.removeChild(this.element);\n }\n\n targetIsOnEditor(target: HTMLElement) {\n if (target === this.element) {\n return true;\n }\n return false;\n }\n\n bindSuccessCallback(success: Function) {\n this.successCallback = success;\n }\n}\n"]}
package/es/types.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ export interface IEditor {
2
+ editorType?: string;
3
+ editorConfig: any;
4
+ container: HTMLElement;
5
+ successCallback?: Function;
6
+ getValue: () => string | number | null;
7
+ beginEditing: (container: HTMLElement, referencePosition: {
8
+ rect: RectProps;
9
+ placement?: Placement;
10
+ }, value?: string) => void;
11
+ exit: () => void;
12
+ targetIsOnEditor: (target: HTMLElement) => boolean;
13
+ bindSuccessCallback?: (callback: Function) => void;
14
+ }
15
+ export interface RectProps {
16
+ left: number;
17
+ top: number;
18
+ width: number;
19
+ height: number;
20
+ }
21
+ export declare enum Placement {
22
+ top = "top",
23
+ bottom = "bottom",
24
+ left = "left",
25
+ right = "right"
26
+ }
package/es/types.js ADDED
@@ -0,0 +1,6 @@
1
+ export var Placement;
2
+
3
+ !function(Placement) {
4
+ Placement.top = "top", Placement.bottom = "bottom", Placement.left = "left", Placement.right = "right";
5
+ }(Placement || (Placement = {}));
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"names":[],"mappings":"AA0BA,MAAM,CAAN,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,8BAAiB,CAAA;IACjB,0BAAa,CAAA;IACb,4BAAe,CAAA;AACjB,CAAC,EALW,SAAS,KAAT,SAAS,QAKpB","file":"types.js","sourcesContent":["export interface IEditor {\n /** 编辑器类型 */\n editorType?: string;\n /** 编辑配置 */\n editorConfig: any;\n container: HTMLElement;\n successCallback?: Function;\n // createElement: () => void;\n // setValue: (value: string) => void;\n getValue: () => string | number | null;\n beginEditing: (\n container: HTMLElement,\n referencePosition: { rect: RectProps; placement?: Placement },\n value?: string\n ) => void;\n // endEditing: () => void;\n exit: () => void;\n targetIsOnEditor: (target: HTMLElement) => boolean;\n bindSuccessCallback?: (callback: Function) => void;\n}\nexport interface RectProps {\n left: number;\n top: number;\n width: number;\n height: number;\n}\nexport enum Placement {\n top = 'top',\n bottom = 'bottom',\n left = 'left',\n right = 'right'\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@visactor/vtable-editors",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "",
5
+ "sideEffects": false,
6
+ "main": "cjs/index.js",
7
+ "module": "es/index.js",
8
+ "types": "es/index.d.ts",
9
+ "files": [
10
+ "cjs",
11
+ "es",
12
+ "dist"
13
+ ],
14
+ "license": "MIT",
15
+ "exports": {
16
+ ".": {
17
+ "require": "./cjs/index.js",
18
+ "import": "./es/index.js"
19
+ }
20
+ },
21
+ "dependencies": {},
22
+ "devDependencies": {
23
+ "@rushstack/eslint-patch": "~1.1.4",
24
+ "eslint": "~8.18.0",
25
+ "vite": "3.2.6",
26
+ "typescript": "4.9.5",
27
+ "@types/jest": "^26.0.0",
28
+ "@types/node": "*",
29
+ "@types/offscreencanvas": "2019.6.4",
30
+ "husky": "7.0.4",
31
+ "jest": "^26.0.0",
32
+ "jest-electron": "^0.1.12",
33
+ "lint-staged": "12.3.7",
34
+ "magic-string": "^0.25.7",
35
+ "react-device-detect": "^2.2.2",
36
+ "ts-jest": "^26.0.0",
37
+ "ts-loader": "9.2.6",
38
+ "ts-node": "10.9.0",
39
+ "tslib": "2.3.1",
40
+ "tslint": "5.12.1",
41
+ "@internal/bundler": "0.0.1",
42
+ "@internal/ts-config": "0.0.1",
43
+ "@internal/eslint-config": "0.0.1"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "homepage": "https://www.visactor.io",
49
+ "bugs": "https://github.com/VisActor/VTable",
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "https://github.com/VisActor/VTable.git",
53
+ "directory": "packages/vtable-editors"
54
+ },
55
+ "author": {
56
+ "name": "VisActor",
57
+ "url": "https://www.visactor.io/"
58
+ },
59
+ "scripts": {
60
+ "compile": "tsc --noEmit",
61
+ "eslint": "eslint --debug --fix src/",
62
+ "build": "bundle",
63
+ "dev": "bundle --clean -f es -w",
64
+ "test-cov": "jest -w 16 --coverage",
65
+ "test-live": "npm run test-watch __tests__/unit/",
66
+ "test-watch": "DEBUG_MODE=1 jest --watch"
67
+ }
68
+ }