pgo-ui 1.1.13 → 1.1.16
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/Radio-C69Y0KPR.js +4 -0
- package/dist/index-DJX1IK1P.js +66771 -0
- package/dist/index.es.js +73 -66711
- package/dist/index.umd.js +75 -76
- package/dist/pgo-ui.css +1 -1
- package/package.json +1 -1
- package/src/components/pgo/AppBar.vue +1 -1
- package/src/components/pgo/DataTable.vue +15 -6
- package/src/components/pgo/forms/DynamicForm.vue +642 -442
- package/src/pgo-components/lib/componentConfig.js +100 -16
|
@@ -270,20 +270,104 @@ export function createSafeFunction(params, body, context) {
|
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
// Example: initializeFunctions utility
|
|
273
|
-
export function initializeFunctions(functionsObj, context) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
273
|
+
// export function initializeFunctions(functionsObj, context) {
|
|
274
|
+
// const compiledFunctions = {};
|
|
275
|
+
// if (functionsObj) {
|
|
276
|
+
// Object.keys(functionsObj).forEach(funcName => {
|
|
277
|
+
// const funcString = functionsObj[funcName];
|
|
278
|
+
// try {
|
|
279
|
+
// compiledFunctions[funcName] = createSafeFunction(['response'], funcString, context);
|
|
280
|
+
// } catch (error) {
|
|
281
|
+
// console.error(`Error compiling function ${funcName}:`, error);
|
|
282
|
+
// compiledFunctions[funcName] = (response) => {
|
|
283
|
+
// console.warn(`Function ${funcName} failed to compile, received:`, response);
|
|
284
|
+
// };
|
|
285
|
+
// }
|
|
286
|
+
// });
|
|
287
|
+
// }
|
|
288
|
+
// return compiledFunctions;
|
|
289
|
+
// }
|
|
290
|
+
|
|
291
|
+
// Reusable safe eval helper
|
|
292
|
+
const safeEval = (expression, context) => {
|
|
293
|
+
const functionKeys = []
|
|
294
|
+
const functionValues = []
|
|
295
|
+
const varDeclarations = []
|
|
296
|
+
|
|
297
|
+
Object.keys(context)
|
|
298
|
+
.filter(key => /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key))
|
|
299
|
+
.forEach(key => {
|
|
300
|
+
const value = context[key]
|
|
301
|
+
|
|
302
|
+
if (typeof value === 'function') {
|
|
303
|
+
// Pass functions as parameters
|
|
304
|
+
functionKeys.push(key)
|
|
305
|
+
functionValues.push(value)
|
|
306
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
307
|
+
// Pass ALL objects as parameters (preserves reactivity, avoids JSON issues)
|
|
308
|
+
functionKeys.push(key)
|
|
309
|
+
functionValues.push(value)
|
|
310
|
+
} else if (value === null || value === undefined) {
|
|
311
|
+
varDeclarations.push(`var ${key} = null;`)
|
|
312
|
+
} else if (typeof value === 'string') {
|
|
313
|
+
varDeclarations.push(`var ${key} = ${JSON.stringify(value)};`)
|
|
314
|
+
} else if (typeof value === 'boolean') {
|
|
315
|
+
varDeclarations.push(`var ${key} = ${value};`)
|
|
316
|
+
} else if (typeof value === 'number') {
|
|
317
|
+
varDeclarations.push(`var ${key} = ${value};`)
|
|
318
|
+
} else {
|
|
319
|
+
varDeclarations.push(`var ${key} = null;`)
|
|
320
|
+
}
|
|
321
|
+
})
|
|
322
|
+
|
|
323
|
+
// expression is used as-is — caller decides whether to add "return (...)"
|
|
324
|
+
const body = varDeclarations.join('\n') + `\n${expression}`
|
|
325
|
+
const fn = new Function(...functionKeys, body)
|
|
326
|
+
return fn(...functionValues)
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const initializeFunctions = (functions, baseContext = {}) => {
|
|
330
|
+
const compiled = {}
|
|
331
|
+
|
|
332
|
+
if (!functions || typeof functions !== 'object') {
|
|
333
|
+
return compiled
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
Object.entries(functions).forEach(([name, functionBody]) => {
|
|
337
|
+
if (typeof functionBody !== 'string') return
|
|
338
|
+
|
|
339
|
+
try {
|
|
340
|
+
compiled[name] = (...args) => {
|
|
341
|
+
// Create a fresh context merging base with call-time args
|
|
342
|
+
const context = { ...baseContext }
|
|
343
|
+
|
|
344
|
+
// Add common function-specific arguments
|
|
345
|
+
if (args[0] !== undefined) context.response = args[0]
|
|
346
|
+
if (args[1] !== undefined) context.item = args[1]
|
|
347
|
+
if (args[2] !== undefined) context.event = args[2]
|
|
348
|
+
|
|
349
|
+
// Add positional args
|
|
350
|
+
args.forEach((arg, index) => {
|
|
351
|
+
context[`arg${index}`] = arg
|
|
352
|
+
})
|
|
353
|
+
|
|
354
|
+
try {
|
|
355
|
+
return safeEval(functionBody, context)
|
|
356
|
+
} catch (error) {
|
|
357
|
+
console.warn(`Error executing function "${name}":`, error.message)
|
|
358
|
+
console.warn('Function body was:', functionBody)
|
|
359
|
+
return null
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
} catch (error) {
|
|
363
|
+
console.warn(`Error compiling function "${name}":`, error.message)
|
|
364
|
+
}
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
return compiled
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export {
|
|
371
|
+
safeEval,
|
|
372
|
+
initializeFunctions,
|
|
289
373
|
}
|