@punica/form 1.1.12 → 1.2.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.
@@ -55,7 +55,8 @@ export declare class FormController<E, F extends FormItem<E>> extends BaseListen
55
55
  */
56
56
  private runStarters;
57
57
  /**
58
- * Creates a deep copy of the form data for the initial state.
58
+ * Keeps a deep copy of the form items for the initial state.
59
+ * Services, readers and starters are shared, not copied.
59
60
  */
60
61
  private deepCopyForm;
61
62
  /**
@@ -54,7 +54,7 @@ class FormController extends common_1.BaseListener {
54
54
  devTools.sendUpdateItem(data);
55
55
  break;
56
56
  case 'REGISTER_ITEMS':
57
- devTools.sendRegisterItems(Array.from(data));
57
+ devTools.sendRegisterItems(data);
58
58
  break;
59
59
  }
60
60
  }
@@ -67,81 +67,62 @@ class FormController extends common_1.BaseListener {
67
67
  if (!devTools.isEnabled()) {
68
68
  return;
69
69
  }
70
- try {
71
- // Try both 'getValues' and 'GetValues' service names
72
- const getValuesService = this.getServices('getValues') || this.getServices('GetValues');
73
- if (getValuesService && typeof getValuesService.run === 'function') {
74
- getValuesService
75
- .run()
76
- .then((entity) => {
77
- devTools.sendEntity(entity);
78
- })
79
- .catch(() => {
80
- // Silently fail
81
- });
82
- }
83
- }
84
- catch (_a) {
85
- // Silently fail
86
- }
70
+ const getValues = this.getServices('getValues');
71
+ // Debugging must never break the form
72
+ getValues === null || getValues === void 0 ? void 0 : getValues.run().then((entity) => devTools.sendEntity(entity)).catch(() => { });
87
73
  };
88
74
  /**
89
75
  * Create a command service for the form.
90
76
  * @returns A CommandService for the form
91
77
  */
92
78
  this.createCommandService = () => {
93
- const self = this;
94
79
  const getItem = (property) => {
95
- const { items } = __classPrivateFieldGet(self, _FormController_form, "f");
96
- const itemIndex = __classPrivateFieldGet(self, _FormController_itemsMap, "f")[property];
97
- if (!Number.isInteger(itemIndex))
98
- return null;
99
- return items[itemIndex];
80
+ const index = __classPrivateFieldGet(this, _FormController_itemsMap, "f")[property];
81
+ return Number.isInteger(index) ? __classPrivateFieldGet(this, _FormController_form, "f").items[index] : null;
100
82
  };
101
- const writeItems = async (arr) => {
102
- for (const item of arr) {
103
- const { items } = __classPrivateFieldGet(self, _FormController_form, "f");
104
- const index = __classPrivateFieldGet(self, _FormController_itemsMap, "f")[item.property];
105
- items[index] = item;
83
+ const writeItems = async (items) => {
84
+ for (const item of items) {
85
+ const index = __classPrivateFieldGet(this, _FormController_itemsMap, "f")[item.property];
86
+ if (Number.isInteger(index)) {
87
+ __classPrivateFieldGet(this, _FormController_form, "f").items[index] = item;
88
+ }
106
89
  }
107
90
  };
108
- const fireEvent = (ev, data) => {
109
- self.fireEvent(ev, data);
110
- };
111
91
  const createCommandItem = async (item) => {
112
- var _a, _b;
92
+ var _a, _b, _c;
113
93
  let itemCustomCommand = {};
114
- for await (const service of (_b = (_a = __classPrivateFieldGet(self, _FormController_form, "f")) === null || _a === void 0 ? void 0 : _a.services) !== null && _b !== void 0 ? _b : []) {
115
- const { addCustomFeaturesForCommandItem } = service;
116
- if (addCustomFeaturesForCommandItem) {
117
- const command = addCustomFeaturesForCommandItem();
118
- itemCustomCommand = { ...itemCustomCommand, ...command };
119
- }
94
+ for (const service of (_a = __classPrivateFieldGet(this, _FormController_form, "f").services) !== null && _a !== void 0 ? _a : []) {
95
+ // Called on the service so that its own state stays reachable
96
+ const command = (_c = (_b = service).addCustomFeaturesForCommandItem) === null || _c === void 0 ? void 0 : _c.call(_b);
97
+ itemCustomCommand = { ...itemCustomCommand, ...command };
120
98
  }
121
99
  return {
122
100
  formItem: item,
123
- initialEntity: __classPrivateFieldGet(self, _FormController_initialEntity, "f"),
101
+ initialEntity: __classPrivateFieldGet(this, _FormController_initialEntity, "f"),
124
102
  getItem,
125
103
  writeItems,
126
104
  ...itemCustomCommand
127
105
  };
128
106
  };
129
- return {
130
- initialForm: __classPrivateFieldGet(self, _FormController_initialForm, "f"),
131
- initialEntity: __classPrivateFieldGet(self, _FormController_initialEntity, "f"),
132
- form: __classPrivateFieldGet(self, _FormController_form, "f"),
133
- itemsMap: __classPrivateFieldGet(self, _FormController_itemsMap, "f"),
107
+ const command = {
108
+ initialEntity: __classPrivateFieldGet(this, _FormController_initialEntity, "f"),
134
109
  getItem,
135
110
  writeItems,
136
- fireEvent,
111
+ fireEvent: this.fireEvent,
137
112
  createCommandItem
138
113
  };
114
+ // Getters keep services in sync with the current state of the controller
115
+ return Object.defineProperties(command, {
116
+ form: { enumerable: true, get: () => __classPrivateFieldGet(this, _FormController_form, "f") },
117
+ initialForm: { enumerable: true, get: () => __classPrivateFieldGet(this, _FormController_initialForm, "f") },
118
+ itemsMap: { enumerable: true, get: () => __classPrivateFieldGet(this, _FormController_itemsMap, "f") }
119
+ });
139
120
  };
140
121
  /**
141
122
  * Registers form items by triggering the REGISTER_ITEMS event.
142
123
  */
143
124
  this.registerFormItems = () => {
144
- this.fireEvent('REGISTER_ITEMS', __1.FormItemRegister.getInstance().getItemKeys());
125
+ this.fireEvent('REGISTER_ITEMS', Array.from(__1.FormItemRegister.getInstance().getItemKeys()));
145
126
  };
146
127
  /**
147
128
  * Maps form items to their properties.
@@ -157,14 +138,13 @@ class FormController extends common_1.BaseListener {
157
138
  * Initializes the services defined in the form data.
158
139
  */
159
140
  this.initializeServices = async () => {
160
- if (__classPrivateFieldGet(this, _FormController_form, "f").services) {
161
- for await (const service of __classPrivateFieldGet(this, _FormController_form, "f").services) {
162
- const command = this.createCommandService();
163
- const serviceControl = service;
164
- __classPrivateFieldGet(this, _FormController_serviceMap, "f")[service.name] = service;
165
- if (serviceControl.initialize) {
166
- await serviceControl.initialize(command);
167
- }
141
+ var _a;
142
+ for (const service of (_a = __classPrivateFieldGet(this, _FormController_form, "f").services) !== null && _a !== void 0 ? _a : []) {
143
+ const command = this.createCommandService();
144
+ const serviceControl = service;
145
+ __classPrivateFieldGet(this, _FormController_serviceMap, "f")[service.name] = service;
146
+ if (serviceControl.initialize) {
147
+ await serviceControl.initialize(command);
168
148
  }
169
149
  }
170
150
  };
@@ -172,27 +152,26 @@ class FormController extends common_1.BaseListener {
172
152
  * Executes the readers defined in the form data.
173
153
  */
174
154
  this.runReaders = async () => {
175
- if (__classPrivateFieldGet(this, _FormController_form, "f").readers) {
176
- for await (const reader of __classPrivateFieldGet(this, _FormController_form, "f").readers) {
177
- reader.read(__classPrivateFieldGet(this, _FormController_initialEntity, "f"), __classPrivateFieldGet(this, _FormController_form, "f"), __classPrivateFieldGet(this, _FormController_itemsMap, "f"));
178
- }
155
+ var _a;
156
+ for (const reader of (_a = __classPrivateFieldGet(this, _FormController_form, "f").readers) !== null && _a !== void 0 ? _a : []) {
157
+ await reader.read(__classPrivateFieldGet(this, _FormController_initialEntity, "f"), __classPrivateFieldGet(this, _FormController_form, "f"), __classPrivateFieldGet(this, _FormController_itemsMap, "f"));
179
158
  }
180
159
  };
181
160
  /**
182
161
  * Executes the starters defined in the form data.
183
162
  */
184
163
  this.runStarters = async () => {
185
- if (__classPrivateFieldGet(this, _FormController_form, "f").starters) {
186
- for await (const starter of __classPrivateFieldGet(this, _FormController_form, "f").starters) {
187
- __classPrivateFieldSet(this, _FormController_form, await starter.run(__classPrivateFieldGet(this, _FormController_form, "f"), __classPrivateFieldGet(this, _FormController_initialEntity, "f")), "f");
188
- }
164
+ var _a;
165
+ for (const starter of (_a = __classPrivateFieldGet(this, _FormController_form, "f").starters) !== null && _a !== void 0 ? _a : []) {
166
+ __classPrivateFieldSet(this, _FormController_form, await starter.run(__classPrivateFieldGet(this, _FormController_form, "f"), __classPrivateFieldGet(this, _FormController_initialEntity, "f")), "f");
189
167
  }
190
168
  };
191
169
  /**
192
- * Creates a deep copy of the form data for the initial state.
170
+ * Keeps a deep copy of the form items for the initial state.
171
+ * Services, readers and starters are shared, not copied.
193
172
  */
194
173
  this.deepCopyForm = () => {
195
- __classPrivateFieldSet(this, _FormController_initialForm, (0, __1.deepCopy)(__classPrivateFieldGet(this, _FormController_form, "f")), "f");
174
+ __classPrivateFieldSet(this, _FormController_initialForm, { ...__classPrivateFieldGet(this, _FormController_form, "f"), items: (0, __1.deepCopy)(__classPrivateFieldGet(this, _FormController_form, "f").items) }, "f");
196
175
  };
197
176
  __classPrivateFieldSet(this, _FormController_serviceMap, {}, "f");
198
177
  __classPrivateFieldSet(this, _FormController_itemsMap, {}, "f");
@@ -201,32 +180,28 @@ class FormController extends common_1.BaseListener {
201
180
  * Static method to initialize the FormController with form data.
202
181
  * @param form The initial form data
203
182
  */
204
- static fromForm(form) {
205
- return new Promise((resolve) => {
206
- const instance = new FormController();
207
- __classPrivateFieldSet(instance, _FormController_form, form, "f");
208
- __classPrivateFieldSet(instance, _FormController_initialEntity, {}, "f");
209
- resolve(instance);
210
- });
183
+ static async fromForm(form) {
184
+ const instance = new FormController();
185
+ __classPrivateFieldSet(instance, _FormController_form, form, "f");
186
+ __classPrivateFieldSet(instance, _FormController_initialEntity, {}, "f");
187
+ return instance;
211
188
  }
212
189
  /**
213
190
  * Static method to initialize the FormController with an entity.
214
191
  * @param entity The entity for the form
215
192
  */
216
- static fromEntity(entity) {
217
- return new Promise(async (resolve) => {
218
- const instance = new FormController();
219
- const initialReader = (0, __1.createInitialReader)();
220
- __classPrivateFieldSet(instance, _FormController_initialEntity, entity, "f");
221
- __classPrivateFieldSet(instance, _FormController_form, {
222
- items: null,
223
- services: null,
224
- starters: null,
225
- readers: null
226
- }, "f");
227
- await initialReader.read(__classPrivateFieldGet(instance, _FormController_initialEntity, "f"), __classPrivateFieldGet(instance, _FormController_form, "f"), {});
228
- resolve(instance);
229
- });
193
+ static async fromEntity(entity) {
194
+ const instance = new FormController();
195
+ const initialReader = (0, __1.createInitialReader)();
196
+ __classPrivateFieldSet(instance, _FormController_initialEntity, entity, "f");
197
+ __classPrivateFieldSet(instance, _FormController_form, {
198
+ items: null,
199
+ services: null,
200
+ starters: null,
201
+ readers: null
202
+ }, "f");
203
+ await initialReader.read(__classPrivateFieldGet(instance, _FormController_initialEntity, "f"), __classPrivateFieldGet(instance, _FormController_form, "f"));
204
+ return instance;
230
205
  }
231
206
  getServices(serviceName, ...additionalServiceNames) {
232
207
  if (additionalServiceNames.length > 0) {
@@ -243,27 +218,20 @@ class FormController extends common_1.BaseListener {
243
218
  * @returns A promise that resolves when the form is fully initialized.
244
219
  */
245
220
  async start() {
246
- try {
247
- this.registerFormItems();
248
- this.mapFormItems();
249
- await this.initializeServices();
250
- await this.runReaders();
251
- await this.runStarters();
252
- this.mapFormItems();
253
- this.deepCopyForm();
254
- // Send initialization event to DevTools
255
- const devTools = (0, __1.getDevToolsBridge)();
256
- if (devTools.isEnabled()) {
257
- devTools.sendInit(__classPrivateFieldGet(this, _FormController_form, "f"));
258
- this.sendEntityToDevTools();
259
- }
260
- // Trigger an update event after the form is fully initialized
261
- return __classPrivateFieldGet(this, _FormController_form, "f");
262
- }
263
- catch (error) {
264
- console.error('Error starting the form controller:', error);
265
- throw error;
221
+ this.registerFormItems();
222
+ this.mapFormItems();
223
+ await this.runReaders();
224
+ await this.runStarters();
225
+ // Services are initialized against the final form produced by starters
226
+ this.mapFormItems();
227
+ await this.initializeServices();
228
+ this.deepCopyForm();
229
+ const devTools = (0, __1.getDevToolsBridge)();
230
+ if (devTools.isEnabled()) {
231
+ devTools.sendInit(__classPrivateFieldGet(this, _FormController_form, "f"));
232
+ this.sendEntityToDevTools();
266
233
  }
234
+ return __classPrivateFieldGet(this, _FormController_form, "f");
267
235
  }
268
236
  }
269
237
  exports.FormController = FormController;
@@ -11,7 +11,7 @@ export type FormItem<E> = {
11
11
  disabled?: boolean;
12
12
  hidden?: boolean;
13
13
  getData?: (params?: any) => Promise<any>;
14
- setValue?: (property: keyof E, value: any) => void;
14
+ setValue?: (property: keyof E, value: any) => Promise<void>;
15
15
  control?: (command: CommandItem<E, any>) => Promise<Array<FormItem<E>>>;
16
16
  submitted?: (command: CommandItem<E, any>) => Promise<void>;
17
17
  initialize?: (command: CommandItem<E, any>) => Promise<Array<FormItem<E>>>;
@@ -47,17 +47,10 @@ class BaseReader {
47
47
  * @returns {CommandItem<E, F>} - The command item.
48
48
  */
49
49
  getCommand(item) {
50
- const self = this;
51
- const getItem = (property) => {
52
- const { items } = __classPrivateFieldGet(self, _BaseReader_form, "f");
53
- const index = __classPrivateFieldGet(self, _BaseReader_itemsMap, "f")[property];
54
- const item = items[index];
55
- return item;
56
- };
57
50
  return {
58
51
  formItem: item,
59
- initialEntity: __classPrivateFieldGet(self, _BaseReader_entity, "f"),
60
- getItem: getItem
52
+ initialEntity: __classPrivateFieldGet(this, _BaseReader_entity, "f"),
53
+ getItem: (property) => __classPrivateFieldGet(this, _BaseReader_form, "f").items[__classPrivateFieldGet(this, _BaseReader_itemsMap, "f")[property]]
61
54
  };
62
55
  }
63
56
  /**
@@ -79,7 +72,9 @@ class BaseReader {
79
72
  for (const item of items) {
80
73
  const { property } = item;
81
74
  const index = __classPrivateFieldGet(this, _BaseReader_itemsMap, "f")[property];
82
- __classPrivateFieldGet(this, _BaseReader_form, "f").items[index] = item;
75
+ if (Number.isInteger(index)) {
76
+ __classPrivateFieldGet(this, _BaseReader_form, "f").items[index] = item;
77
+ }
83
78
  }
84
79
  }
85
80
  }
@@ -24,7 +24,7 @@ class Reader extends base_1.default {
24
24
  * @param items - The array of form items to update.
25
25
  */
26
26
  async readItemsData(entity, items) {
27
- for await (const item of items) {
27
+ for (const item of items) {
28
28
  const data = this.getPropertyData(entity, item);
29
29
  item.value = data;
30
30
  }
@@ -10,13 +10,13 @@ class Reader extends base_1.default {
10
10
  * @param items - Array of form items.
11
11
  */
12
12
  async readItemsData(items) {
13
- for await (const formItem of items) {
13
+ for (const formItem of items) {
14
14
  const { initialize } = formItem;
15
15
  if (initialize) {
16
16
  // Call the 'initialize' function of the form item with a command item.
17
17
  const items = await initialize(super.getCommand(formItem));
18
18
  // Write the updated items back to the form.
19
- this.writeItems(items);
19
+ await this.writeItems(items);
20
20
  }
21
21
  }
22
22
  }
@@ -28,7 +28,7 @@ class Reader extends base_1.default {
28
28
  async read(entity, form) {
29
29
  await super.read(entity, form);
30
30
  // Read and initialize form items.
31
- this.readItemsData(form.items);
31
+ await this.readItemsData(form.items);
32
32
  }
33
33
  }
34
34
  exports.default = Reader;
@@ -3,15 +3,10 @@ import { FormItem, Form, IReader } from '../..';
3
3
  * Class for reading form data.
4
4
  */
5
5
  declare class Reader<E, F extends FormItem<E>> implements IReader<E, F> {
6
- /**
7
- *
8
- */
9
- constructor();
10
6
  /**
11
7
  * Reads the form data from the provided entity.
12
8
  * @param {E} entity - The entity to read form data from.
13
- * @returns {Promise<Form<E, F>>} form - Resolves to the form data.
14
- * @throws {Error} - If the entity is not provided.
9
+ * @param {Form<E, F>} form - The form to write the metadata to.
15
10
  */
16
11
  read(entity: E, form: Form<E, F>): Promise<void>;
17
12
  }
@@ -5,26 +5,15 @@ const __1 = require("../..");
5
5
  * Class for reading form data.
6
6
  */
7
7
  class Reader {
8
- /**
9
- *
10
- */
11
- constructor() { }
12
8
  /**
13
9
  * Reads the form data from the provided entity.
14
10
  * @param {E} entity - The entity to read form data from.
15
- * @returns {Promise<Form<E, F>>} form - Resolves to the form data.
16
- * @throws {Error} - If the entity is not provided.
11
+ * @param {Form<E, F>} form - The form to write the metadata to.
17
12
  */
18
- read(entity, form) {
19
- return new Promise((resolve) => {
20
- // Retrieves services metadata from the entity using reflection
21
- form.services = Reflect.getMetadata(__1.DECORATOR_SERVICES, entity);
22
- // Retrieves starters metadata from the entity using reflection
23
- form.starters = Reflect.getMetadata(__1.DECORATOR_STARTERS, entity);
24
- // Retrieves starters metadata from the entity using reflection
25
- form.readers = Reflect.getMetadata(__1.DECORATOR_READERS, entity);
26
- resolve();
27
- });
13
+ async read(entity, form) {
14
+ form.services = Reflect.getMetadata(__1.DECORATOR_SERVICES, entity);
15
+ form.starters = Reflect.getMetadata(__1.DECORATOR_STARTERS, entity);
16
+ form.readers = Reflect.getMetadata(__1.DECORATOR_READERS, entity);
28
17
  }
29
18
  }
30
19
  exports.default = Reader;
@@ -1,18 +1,8 @@
1
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.
2
+ * Creates a deep copy of the given value.
3
+ * Functions are kept by reference, prototypes are preserved and
4
+ * circular references are supported.
5
+ * @param value - The value to copy
6
+ * @returns The copied value
5
7
  */
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;
8
+ export declare const deepCopy: <T>(value: T, seen?: WeakMap<object, any>) => T;
@@ -1,82 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deepCopy = exports.deepCopyFunction = exports.deepCopySpecialTypes = void 0;
3
+ exports.deepCopy = void 0;
4
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.
5
+ * Creates a deep copy of the given value.
6
+ * Functions are kept by reference, prototypes are preserved and
7
+ * circular references are supported.
8
+ * @param value - The value to copy
9
+ * @returns The copied value
8
10
  */
9
- const deepCopySpecialTypes = (obj) => {
10
- if (obj instanceof Date) {
11
- return new Date(obj.valueOf());
11
+ const deepCopy = (value, seen = new WeakMap()) => {
12
+ if (typeof value !== 'object' || value === null) {
13
+ return value;
12
14
  }
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);
15
+ if (seen.has(value)) {
16
+ return seen.get(value);
18
17
  }
19
- if (obj instanceof Map) {
20
- const mapCopy = new Map();
21
- obj.forEach((v, k) => {
22
- mapCopy.set(k, v);
23
- });
24
- return mapCopy;
18
+ if (value instanceof Date) {
19
+ return new Date(value.getTime());
25
20
  }
26
- if (obj instanceof Set) {
27
- const setCopy = new Set();
28
- obj.forEach((v) => {
29
- setCopy.add(v);
30
- });
31
- return setCopy;
21
+ if (value instanceof RegExp) {
22
+ return new RegExp(value.source, value.flags);
32
23
  }
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);
24
+ if (value instanceof Map) {
25
+ const copy = new Map();
26
+ seen.set(value, copy);
27
+ value.forEach((v, k) => copy.set((0, exports.deepCopy)(k, seen), (0, exports.deepCopy)(v, seen)));
28
+ return copy;
71
29
  }
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
- });
30
+ if (value instanceof Set) {
31
+ const copy = new Set();
32
+ seen.set(value, copy);
33
+ value.forEach((v) => copy.add((0, exports.deepCopy)(v, seen)));
78
34
  return copy;
79
35
  }
80
- return obj;
36
+ const copy = Array.isArray(value)
37
+ ? []
38
+ : Object.create(Object.getPrototypeOf(value));
39
+ seen.set(value, copy);
40
+ for (const key of Object.keys(value)) {
41
+ copy[key] = (0, exports.deepCopy)(value[key], seen);
42
+ }
43
+ return copy;
81
44
  };
82
45
  exports.deepCopy = deepCopy;
@@ -1,4 +1,8 @@
1
1
  import { Form, FormItem } from '../model';
2
+ /**
3
+ * Marker used by the DevTools extension to recognize bridge messages
4
+ */
5
+ export declare const DEVTOOLS_MESSAGE_SOURCE = "punica-form-devtools";
2
6
  /**
3
7
  * DevTools bridge for sending form events to Chrome DevTools extension
4
8
  */
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isDevToolsEnabled = exports.disableDevTools = exports.enableDevTools = exports.getDevToolsBridge = void 0;
3
+ exports.isDevToolsEnabled = exports.disableDevTools = exports.enableDevTools = exports.getDevToolsBridge = exports.DEVTOOLS_MESSAGE_SOURCE = void 0;
4
+ /**
5
+ * Marker used by the DevTools extension to recognize bridge messages
6
+ */
7
+ exports.DEVTOOLS_MESSAGE_SOURCE = 'punica-form-devtools';
4
8
  /**
5
9
  * DevTools bridge for sending form events to Chrome DevTools extension
6
10
  */
@@ -42,25 +46,17 @@ class DevToolsBridge {
42
46
  if (!this.isEnabled()) {
43
47
  return;
44
48
  }
45
- console.log('🔥 DevToolsBridge.sendMessage:', type, data, formItemKey);
46
49
  try {
47
50
  const message = {
51
+ source: exports.DEVTOOLS_MESSAGE_SOURCE,
48
52
  type,
49
- data: JSON.stringify(data)
53
+ data: JSON.stringify(data),
54
+ formItemKey
50
55
  };
51
- // Try multiple ways to send message to ensure it reaches content script
52
- try {
53
- window.postMessage(message, '*');
54
- }
55
- catch (e) {
56
- // Fallback: try with current window
57
- if (typeof window !== 'undefined') {
58
- window.postMessage(message, '*');
59
- }
60
- }
56
+ window.postMessage(message, window.location.origin);
61
57
  }
62
- catch (error) {
63
- // Silently fail in production
58
+ catch (_a) {
59
+ // Debugging must never break the form (e.g. non-serializable data)
64
60
  }
65
61
  }
66
62
  /**
@@ -100,17 +96,13 @@ class DevToolsBridge {
100
96
  * Send register items event
101
97
  */
102
98
  sendRegisterItems(itemKeys) {
103
- this.sendMessage('REGISTER_ITEMS', Array.from(itemKeys));
99
+ this.sendMessage('REGISTER_ITEMS', itemKeys);
104
100
  }
105
101
  /**
106
102
  * Send property value update event
107
103
  */
108
104
  sendUpdatePropertyValue(property, value, item) {
109
- this.sendMessage('UPDATE_PROPERTY_VALUE', {
110
- property,
111
- value,
112
- item
113
- }, property);
105
+ this.sendMessage('UPDATE_PROPERTY_VALUE', { property, value, item }, property);
114
106
  }
115
107
  }
116
108
  DevToolsBridge.instance = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@punica/form",
3
- "version": "1.1.12",
3
+ "version": "1.2.0",
4
4
  "description": "Form",
5
5
  "author": {
6
6
  "name": "Uryan Sezgin TEKE",
@@ -18,23 +18,18 @@
18
18
  "access": "public"
19
19
  },
20
20
  "repository": {
21
- "url": "git@github.com:uryansezginteke/punica-form.git"
21
+ "url": "git+https://github.com/punicalab/punica-form.git"
22
22
  },
23
23
  "files": [
24
24
  "dist"
25
25
  ],
26
- "scripts": {
27
- "build": "scripty",
28
- "clean": "scripty",
29
- "lint": "scripty",
30
- "compile": "scripty"
31
- },
32
- "scripty": {
33
- "path": "../../scripts/packages"
34
- },
35
26
  "dependencies": {
36
27
  "@punica/common": "^1.0.1",
37
28
  "@punica/util": "^1.0.2"
38
29
  },
39
- "gitHead": "b5c408308c84a7f81cbdd77bfaebc8fc6e7d243a"
40
- }
30
+ "scripts": {
31
+ "build": "tsc -p tsconfig.build.json",
32
+ "clean": "rimraf dist",
33
+ "lint": "eslint lib"
34
+ }
35
+ }