@punica/form 1.1.6 → 1.1.8
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/controller/index.d.ts +7 -4
- package/dist/controller/index.js +54 -11
- package/dist/utils/deepCopy.d.ts +18 -0
- package/dist/utils/deepCopy.js +82 -0
- package/dist/utils/devtools.d.ts +74 -0
- package/dist/utils/devtools.js +150 -0
- package/dist/utils/index.d.ts +2 -18
- package/dist/utils/index.js +16 -80
- package/package.json +2 -2
|
@@ -25,6 +25,10 @@ export declare class FormController<E, F extends FormItem<E>> extends BaseListen
|
|
|
25
25
|
* @param data Data associated with the event
|
|
26
26
|
*/
|
|
27
27
|
private fireEvent;
|
|
28
|
+
/**
|
|
29
|
+
* Send entity data to DevTools
|
|
30
|
+
*/
|
|
31
|
+
private sendEntityToDevTools;
|
|
28
32
|
/**
|
|
29
33
|
* Create a command service for the form.
|
|
30
34
|
* @returns A CommandService for the form
|
|
@@ -56,11 +60,10 @@ export declare class FormController<E, F extends FormItem<E>> extends BaseListen
|
|
|
56
60
|
private deepCopyForm;
|
|
57
61
|
/**
|
|
58
62
|
* Get services by their names.
|
|
59
|
-
*
|
|
60
|
-
* @param additionalServiceNames Additional names of services
|
|
61
|
-
* @returns The requested services
|
|
63
|
+
* Overloads to return a single item or an array based on provided names.
|
|
62
64
|
*/
|
|
63
|
-
getServices<T = IServiceInitialize<E, F> & IServiceControl & IServiceCommand
|
|
65
|
+
getServices<T = IServiceInitialize<E, F> & IServiceControl & IServiceCommand>(serviceName: string): T;
|
|
66
|
+
getServices<T = IServiceInitialize<E, F> & IServiceControl & IServiceCommand>(serviceName: string, ...additionalServiceNames: string[]): T[];
|
|
64
67
|
/**
|
|
65
68
|
* Starts the form controller by executing all necessary steps to initialize the form.
|
|
66
69
|
* @returns A promise that resolves when the form is fully initialized.
|
package/dist/controller/index.js
CHANGED
|
@@ -38,6 +38,50 @@ class FormController extends common_1.BaseListener {
|
|
|
38
38
|
*/
|
|
39
39
|
this.fireEvent = (eventType, data) => {
|
|
40
40
|
this.trigger(eventType, data);
|
|
41
|
+
const devTools = (0, __1.getDevToolsBridge)();
|
|
42
|
+
if (devTools.isEnabled()) {
|
|
43
|
+
switch (eventType) {
|
|
44
|
+
case 'UPDATE_FORM':
|
|
45
|
+
devTools.sendUpdate(__classPrivateFieldGet(this, _FormController_form, "f"));
|
|
46
|
+
this.sendEntityToDevTools();
|
|
47
|
+
break;
|
|
48
|
+
case 'RESET':
|
|
49
|
+
devTools.sendReset(__classPrivateFieldGet(this, _FormController_form, "f"));
|
|
50
|
+
break;
|
|
51
|
+
case 'UPDATE_ITEM':
|
|
52
|
+
devTools.sendUpdateItem(data);
|
|
53
|
+
break;
|
|
54
|
+
case 'REGISTER_ITEMS':
|
|
55
|
+
devTools.sendRegisterItems(Array.from(data));
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Send entity data to DevTools
|
|
62
|
+
*/
|
|
63
|
+
this.sendEntityToDevTools = () => {
|
|
64
|
+
const devTools = (0, __1.getDevToolsBridge)();
|
|
65
|
+
if (!devTools.isEnabled()) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
// Try both 'getValues' and 'GetValues' service names
|
|
70
|
+
const getValuesService = this.getServices('getValues') || this.getServices('GetValues');
|
|
71
|
+
if (getValuesService && typeof getValuesService.run === 'function') {
|
|
72
|
+
getValuesService
|
|
73
|
+
.run()
|
|
74
|
+
.then((entity) => {
|
|
75
|
+
devTools.sendEntity(entity);
|
|
76
|
+
})
|
|
77
|
+
.catch(() => {
|
|
78
|
+
// Silently fail
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (_a) {
|
|
83
|
+
// Silently fail
|
|
84
|
+
}
|
|
41
85
|
};
|
|
42
86
|
/**
|
|
43
87
|
* Create a command service for the form.
|
|
@@ -60,7 +104,7 @@ class FormController extends common_1.BaseListener {
|
|
|
60
104
|
}
|
|
61
105
|
};
|
|
62
106
|
const fireEvent = (ev, data) => {
|
|
63
|
-
self.
|
|
107
|
+
self.fireEvent(ev, data);
|
|
64
108
|
};
|
|
65
109
|
const createCommandItem = async (item) => {
|
|
66
110
|
var _a, _b;
|
|
@@ -182,20 +226,13 @@ class FormController extends common_1.BaseListener {
|
|
|
182
226
|
resolve(instance);
|
|
183
227
|
});
|
|
184
228
|
}
|
|
185
|
-
/**
|
|
186
|
-
* Get services by their names.
|
|
187
|
-
* @param serviceName The name of the service
|
|
188
|
-
* @param additionalServiceNames Additional names of services
|
|
189
|
-
* @returns The requested services
|
|
190
|
-
*/
|
|
191
229
|
getServices(serviceName, ...additionalServiceNames) {
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
const services = [
|
|
230
|
+
if (additionalServiceNames.length > 0) {
|
|
231
|
+
const list = [
|
|
195
232
|
__classPrivateFieldGet(this, _FormController_serviceMap, "f")[serviceName],
|
|
196
233
|
...additionalServiceNames.map((name) => __classPrivateFieldGet(this, _FormController_serviceMap, "f")[name])
|
|
197
234
|
];
|
|
198
|
-
return
|
|
235
|
+
return list;
|
|
199
236
|
}
|
|
200
237
|
return __classPrivateFieldGet(this, _FormController_serviceMap, "f")[serviceName];
|
|
201
238
|
}
|
|
@@ -212,6 +249,12 @@ class FormController extends common_1.BaseListener {
|
|
|
212
249
|
await this.runStarters();
|
|
213
250
|
this.mapFormItems();
|
|
214
251
|
this.deepCopyForm();
|
|
252
|
+
// Send initialization event to DevTools
|
|
253
|
+
const devTools = (0, __1.getDevToolsBridge)();
|
|
254
|
+
if (devTools.isEnabled()) {
|
|
255
|
+
devTools.sendInit(__classPrivateFieldGet(this, _FormController_form, "f"));
|
|
256
|
+
this.sendEntityToDevTools();
|
|
257
|
+
}
|
|
215
258
|
// Trigger an update event after the form is fully initialized
|
|
216
259
|
return __classPrivateFieldGet(this, _FormController_form, "f");
|
|
217
260
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performs a deep copy of special types (Date, RegExp, Map, Set).
|
|
3
|
+
* @param obj - The object to be copied.
|
|
4
|
+
* @returns The deep copy of the object.
|
|
5
|
+
*/
|
|
6
|
+
export declare const deepCopySpecialTypes: (obj: any) => any;
|
|
7
|
+
/**
|
|
8
|
+
* Performs a deep copy of a function.
|
|
9
|
+
* @param func - The function to be copied.
|
|
10
|
+
* @returns The deep copy of the function.
|
|
11
|
+
*/
|
|
12
|
+
export declare const deepCopyFunction: (func: Function) => any;
|
|
13
|
+
/**
|
|
14
|
+
* Performs a deep copy of an object.
|
|
15
|
+
* @param obj - The object to be copied.
|
|
16
|
+
* @returns The deep copy of the object.
|
|
17
|
+
*/
|
|
18
|
+
export declare const deepCopy: (obj: any) => any;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deepCopy = exports.deepCopyFunction = exports.deepCopySpecialTypes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Performs a deep copy of special types (Date, RegExp, Map, Set).
|
|
6
|
+
* @param obj - The object to be copied.
|
|
7
|
+
* @returns The deep copy of the object.
|
|
8
|
+
*/
|
|
9
|
+
const deepCopySpecialTypes = (obj) => {
|
|
10
|
+
if (obj instanceof Date) {
|
|
11
|
+
return new Date(obj.valueOf());
|
|
12
|
+
}
|
|
13
|
+
if (obj instanceof RegExp) {
|
|
14
|
+
const pattern = obj.valueOf().toString();
|
|
15
|
+
const flags = pattern.substring(pattern.lastIndexOf('/') + 1);
|
|
16
|
+
const realPattern = pattern.substring(1, pattern.lastIndexOf('/'));
|
|
17
|
+
return new RegExp(realPattern, flags);
|
|
18
|
+
}
|
|
19
|
+
if (obj instanceof Map) {
|
|
20
|
+
const mapCopy = new Map();
|
|
21
|
+
obj.forEach((v, k) => {
|
|
22
|
+
mapCopy.set(k, v);
|
|
23
|
+
});
|
|
24
|
+
return mapCopy;
|
|
25
|
+
}
|
|
26
|
+
if (obj instanceof Set) {
|
|
27
|
+
const setCopy = new Set();
|
|
28
|
+
obj.forEach((v) => {
|
|
29
|
+
setCopy.add(v);
|
|
30
|
+
});
|
|
31
|
+
return setCopy;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.deepCopySpecialTypes = deepCopySpecialTypes;
|
|
35
|
+
/**
|
|
36
|
+
* Performs a deep copy of a function.
|
|
37
|
+
* @param func - The function to be copied.
|
|
38
|
+
* @returns The deep copy of the function.
|
|
39
|
+
*/
|
|
40
|
+
const deepCopyFunction = (func) => {
|
|
41
|
+
const funcStr = func.toString();
|
|
42
|
+
if (func.prototype) {
|
|
43
|
+
const paramArr = funcStr.match(/\((.*?)\)/)[1].split(', ');
|
|
44
|
+
const funcBody = funcStr.match(/\{([\s\S]*)\}/)[1];
|
|
45
|
+
const funcCopy = new Function(...paramArr, funcBody);
|
|
46
|
+
funcCopy.prototype = Object.assign({}, func.prototype);
|
|
47
|
+
return funcCopy;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return eval(funcStr);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.deepCopyFunction = deepCopyFunction;
|
|
54
|
+
/**
|
|
55
|
+
* Performs a deep copy of an object.
|
|
56
|
+
* @param obj - The object to be copied.
|
|
57
|
+
* @returns The deep copy of the object.
|
|
58
|
+
*/
|
|
59
|
+
const deepCopy = (obj) => {
|
|
60
|
+
//if (obj instanceof Function) {
|
|
61
|
+
// return deepCopyFunction(obj);
|
|
62
|
+
//}
|
|
63
|
+
if (obj instanceof Date ||
|
|
64
|
+
obj instanceof RegExp ||
|
|
65
|
+
obj instanceof Map ||
|
|
66
|
+
obj instanceof Set) {
|
|
67
|
+
return (0, exports.deepCopySpecialTypes)(obj);
|
|
68
|
+
}
|
|
69
|
+
if (obj instanceof Array) {
|
|
70
|
+
return obj.map(exports.deepCopy);
|
|
71
|
+
}
|
|
72
|
+
if (obj instanceof Object) {
|
|
73
|
+
const copy = {};
|
|
74
|
+
Object.keys(obj).forEach((key) => {
|
|
75
|
+
//@ts-ignore
|
|
76
|
+
copy[key] = (0, exports.deepCopy)(obj[key]);
|
|
77
|
+
});
|
|
78
|
+
return copy;
|
|
79
|
+
}
|
|
80
|
+
return obj;
|
|
81
|
+
};
|
|
82
|
+
exports.deepCopy = deepCopy;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Form, FormItem } from '../model';
|
|
2
|
+
/**
|
|
3
|
+
* DevTools bridge for sending form events to Chrome DevTools extension
|
|
4
|
+
*/
|
|
5
|
+
declare class DevToolsBridge {
|
|
6
|
+
private static instance;
|
|
7
|
+
private enabled;
|
|
8
|
+
private constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Get singleton instance
|
|
11
|
+
*/
|
|
12
|
+
static getInstance(): DevToolsBridge;
|
|
13
|
+
/**
|
|
14
|
+
* Enable DevTools bridge
|
|
15
|
+
*/
|
|
16
|
+
enable(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Disable DevTools bridge
|
|
19
|
+
*/
|
|
20
|
+
disable(): void;
|
|
21
|
+
/**
|
|
22
|
+
* Check if DevTools bridge is enabled
|
|
23
|
+
*/
|
|
24
|
+
isEnabled(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Send message to DevTools extension
|
|
27
|
+
*/
|
|
28
|
+
private sendMessage;
|
|
29
|
+
/**
|
|
30
|
+
* Send initialization event
|
|
31
|
+
*/
|
|
32
|
+
sendInit<E, F extends FormItem<E>>(form: Form<E, F>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Send entity data
|
|
35
|
+
*/
|
|
36
|
+
sendEntity<E>(entity: E): void;
|
|
37
|
+
/**
|
|
38
|
+
* Send form update event
|
|
39
|
+
*/
|
|
40
|
+
sendUpdate<E, F extends FormItem<E>>(form: Form<E, F>): void;
|
|
41
|
+
/**
|
|
42
|
+
* Send form reset event
|
|
43
|
+
*/
|
|
44
|
+
sendReset<E, F extends FormItem<E>>(form: Form<E, F>): void;
|
|
45
|
+
/**
|
|
46
|
+
* Send item update event
|
|
47
|
+
*/
|
|
48
|
+
sendUpdateItem<E, F extends FormItem<E>>(item: F | F[]): void;
|
|
49
|
+
/**
|
|
50
|
+
* Send register items event
|
|
51
|
+
*/
|
|
52
|
+
sendRegisterItems(itemKeys: string[]): void;
|
|
53
|
+
/**
|
|
54
|
+
* Send property value update event
|
|
55
|
+
*/
|
|
56
|
+
sendUpdatePropertyValue<E, F extends FormItem<E>>(property: keyof E, value: any, item: F): void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get DevTools bridge instance
|
|
60
|
+
*/
|
|
61
|
+
export declare const getDevToolsBridge: () => DevToolsBridge;
|
|
62
|
+
/**
|
|
63
|
+
* Enable DevTools bridge
|
|
64
|
+
*/
|
|
65
|
+
export declare const enableDevTools: () => void;
|
|
66
|
+
/**
|
|
67
|
+
* Disable DevTools bridge
|
|
68
|
+
*/
|
|
69
|
+
export declare const disableDevTools: () => void;
|
|
70
|
+
/**
|
|
71
|
+
* Check if DevTools bridge is enabled
|
|
72
|
+
*/
|
|
73
|
+
export declare const isDevToolsEnabled: () => boolean;
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDevToolsEnabled = exports.disableDevTools = exports.enableDevTools = exports.getDevToolsBridge = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* DevTools bridge for sending form events to Chrome DevTools extension
|
|
6
|
+
*/
|
|
7
|
+
class DevToolsBridge {
|
|
8
|
+
constructor() {
|
|
9
|
+
var _a;
|
|
10
|
+
this.enabled = false;
|
|
11
|
+
// Check if we're in a browser environment
|
|
12
|
+
if (typeof window !== 'undefined') {
|
|
13
|
+
// Enable by default in development
|
|
14
|
+
// Check for NODE_ENV or global flag
|
|
15
|
+
const isDevelopment = (typeof process !== 'undefined' &&
|
|
16
|
+
((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'development') ||
|
|
17
|
+
window.__PUNICA_FORM_DEVTOOLS__ === true;
|
|
18
|
+
this.enabled = isDevelopment;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get singleton instance
|
|
23
|
+
*/
|
|
24
|
+
static getInstance() {
|
|
25
|
+
if (!DevToolsBridge.instance) {
|
|
26
|
+
DevToolsBridge.instance = new DevToolsBridge();
|
|
27
|
+
}
|
|
28
|
+
return DevToolsBridge.instance;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Enable DevTools bridge
|
|
32
|
+
*/
|
|
33
|
+
enable() {
|
|
34
|
+
this.enabled = true;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Disable DevTools bridge
|
|
38
|
+
*/
|
|
39
|
+
disable() {
|
|
40
|
+
this.enabled = false;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Check if DevTools bridge is enabled
|
|
44
|
+
*/
|
|
45
|
+
isEnabled() {
|
|
46
|
+
return this.enabled && typeof window !== 'undefined';
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Send message to DevTools extension
|
|
50
|
+
*/
|
|
51
|
+
sendMessage(type, data, formItemKey) {
|
|
52
|
+
var _a;
|
|
53
|
+
if (!this.isEnabled()) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const message = {
|
|
58
|
+
type,
|
|
59
|
+
data,
|
|
60
|
+
...(formItemKey && { formItemKey })
|
|
61
|
+
};
|
|
62
|
+
window.postMessage(message, '*');
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
// Silently fail in production
|
|
66
|
+
if (typeof process !== 'undefined' &&
|
|
67
|
+
((_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV) === 'development') {
|
|
68
|
+
console.warn('Punica Form DevTools: Failed to send message', error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Send initialization event
|
|
74
|
+
*/
|
|
75
|
+
sendInit(form) {
|
|
76
|
+
this.sendMessage('@@INIT', form);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Send entity data
|
|
80
|
+
*/
|
|
81
|
+
sendEntity(entity) {
|
|
82
|
+
this.sendMessage('ENTITY', entity);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Send form update event
|
|
86
|
+
*/
|
|
87
|
+
sendUpdate(form) {
|
|
88
|
+
this.sendMessage('UPDATE', form);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Send form reset event
|
|
92
|
+
*/
|
|
93
|
+
sendReset(form) {
|
|
94
|
+
this.sendMessage('RESET', form);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Send item update event
|
|
98
|
+
*/
|
|
99
|
+
sendUpdateItem(item) {
|
|
100
|
+
const items = Array.isArray(item) ? item : [item];
|
|
101
|
+
items.forEach((formItem) => {
|
|
102
|
+
this.sendMessage('UPDATE_ITEM', formItem, formItem.property);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Send register items event
|
|
107
|
+
*/
|
|
108
|
+
sendRegisterItems(itemKeys) {
|
|
109
|
+
this.sendMessage('REGISTER_ITEMS', Array.from(itemKeys));
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Send property value update event
|
|
113
|
+
*/
|
|
114
|
+
sendUpdatePropertyValue(property, value, item) {
|
|
115
|
+
this.sendMessage('UPDATE_PROPERTY_VALUE', {
|
|
116
|
+
property,
|
|
117
|
+
value,
|
|
118
|
+
item
|
|
119
|
+
}, property);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
DevToolsBridge.instance = null;
|
|
123
|
+
/**
|
|
124
|
+
* Get DevTools bridge instance
|
|
125
|
+
*/
|
|
126
|
+
const getDevToolsBridge = () => {
|
|
127
|
+
return DevToolsBridge.getInstance();
|
|
128
|
+
};
|
|
129
|
+
exports.getDevToolsBridge = getDevToolsBridge;
|
|
130
|
+
/**
|
|
131
|
+
* Enable DevTools bridge
|
|
132
|
+
*/
|
|
133
|
+
const enableDevTools = () => {
|
|
134
|
+
(0, exports.getDevToolsBridge)().enable();
|
|
135
|
+
};
|
|
136
|
+
exports.enableDevTools = enableDevTools;
|
|
137
|
+
/**
|
|
138
|
+
* Disable DevTools bridge
|
|
139
|
+
*/
|
|
140
|
+
const disableDevTools = () => {
|
|
141
|
+
(0, exports.getDevToolsBridge)().disable();
|
|
142
|
+
};
|
|
143
|
+
exports.disableDevTools = disableDevTools;
|
|
144
|
+
/**
|
|
145
|
+
* Check if DevTools bridge is enabled
|
|
146
|
+
*/
|
|
147
|
+
const isDevToolsEnabled = () => {
|
|
148
|
+
return (0, exports.getDevToolsBridge)().isEnabled();
|
|
149
|
+
};
|
|
150
|
+
exports.isDevToolsEnabled = isDevToolsEnabled;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
* @param obj - The object to be copied.
|
|
4
|
-
* @returns The deep copy of the object.
|
|
5
|
-
*/
|
|
6
|
-
export declare const deepCopySpecialTypes: (obj: any) => any;
|
|
7
|
-
/**
|
|
8
|
-
* Performs a deep copy of a function.
|
|
9
|
-
* @param func - The function to be copied.
|
|
10
|
-
* @returns The deep copy of the function.
|
|
11
|
-
*/
|
|
12
|
-
export declare const deepCopyFunction: (func: Function) => any;
|
|
13
|
-
/**
|
|
14
|
-
* Performs a deep copy of an object.
|
|
15
|
-
* @param obj - The object to be copied.
|
|
16
|
-
* @returns The deep copy of the object.
|
|
17
|
-
*/
|
|
18
|
-
export declare const deepCopy: (obj: any) => any;
|
|
1
|
+
export * from './devtools';
|
|
2
|
+
export * from './deepCopy';
|
package/dist/utils/index.js
CHANGED
|
@@ -1,82 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const flags = pattern.substring(pattern.lastIndexOf('/') + 1);
|
|
16
|
-
const realPattern = pattern.substring(1, pattern.lastIndexOf('/'));
|
|
17
|
-
return new RegExp(realPattern, flags);
|
|
18
|
-
}
|
|
19
|
-
if (obj instanceof Map) {
|
|
20
|
-
const mapCopy = new Map();
|
|
21
|
-
obj.forEach((v, k) => {
|
|
22
|
-
mapCopy.set(k, v);
|
|
23
|
-
});
|
|
24
|
-
return mapCopy;
|
|
25
|
-
}
|
|
26
|
-
if (obj instanceof Set) {
|
|
27
|
-
const setCopy = new Set();
|
|
28
|
-
obj.forEach((v) => {
|
|
29
|
-
setCopy.add(v);
|
|
30
|
-
});
|
|
31
|
-
return setCopy;
|
|
32
|
-
}
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
33
15
|
};
|
|
34
|
-
exports
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* @param func - The function to be copied.
|
|
38
|
-
* @returns The deep copy of the function.
|
|
39
|
-
*/
|
|
40
|
-
const deepCopyFunction = (func) => {
|
|
41
|
-
const funcStr = func.toString();
|
|
42
|
-
if (func.prototype) {
|
|
43
|
-
const paramArr = funcStr.match(/\((.*?)\)/)[1].split(', ');
|
|
44
|
-
const funcBody = funcStr.match(/\{([\s\S]*)\}/)[1];
|
|
45
|
-
const funcCopy = new Function(...paramArr, funcBody);
|
|
46
|
-
funcCopy.prototype = Object.assign({}, func.prototype);
|
|
47
|
-
return funcCopy;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
return eval(funcStr);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
exports.deepCopyFunction = deepCopyFunction;
|
|
54
|
-
/**
|
|
55
|
-
* Performs a deep copy of an object.
|
|
56
|
-
* @param obj - The object to be copied.
|
|
57
|
-
* @returns The deep copy of the object.
|
|
58
|
-
*/
|
|
59
|
-
const deepCopy = (obj) => {
|
|
60
|
-
//if (obj instanceof Function) {
|
|
61
|
-
// return deepCopyFunction(obj);
|
|
62
|
-
//}
|
|
63
|
-
if (obj instanceof Date ||
|
|
64
|
-
obj instanceof RegExp ||
|
|
65
|
-
obj instanceof Map ||
|
|
66
|
-
obj instanceof Set) {
|
|
67
|
-
return (0, exports.deepCopySpecialTypes)(obj);
|
|
68
|
-
}
|
|
69
|
-
if (obj instanceof Array) {
|
|
70
|
-
return obj.map(exports.deepCopy);
|
|
71
|
-
}
|
|
72
|
-
if (obj instanceof Object) {
|
|
73
|
-
const copy = {};
|
|
74
|
-
Object.keys(obj).forEach((key) => {
|
|
75
|
-
//@ts-ignore
|
|
76
|
-
copy[key] = (0, exports.deepCopy)(obj[key]);
|
|
77
|
-
});
|
|
78
|
-
return copy;
|
|
79
|
-
}
|
|
80
|
-
return obj;
|
|
81
|
-
};
|
|
82
|
-
exports.deepCopy = deepCopy;
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./devtools"), exports);
|
|
18
|
+
__exportStar(require("./deepCopy"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@punica/form",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "Form",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Uryan Sezgin TEKE",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"@punica/common": "^1.0.1",
|
|
37
37
|
"@punica/util": "^1.0.2"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "20706951fac4dd26c2686e378812bc607973ac51"
|
|
40
40
|
}
|