@shwfed/nuxt 0.11.20 → 0.11.22

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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
3
  "configKey": "shwfed",
4
- "version": "0.11.20",
4
+ "version": "0.11.22",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -63,12 +63,34 @@ function cloneConfig(config2) {
63
63
  function getConfigOrientation(config2) {
64
64
  return config2.orientation ?? "horizontal";
65
65
  }
66
+ function tryEvaluateExpression(source, context) {
67
+ try {
68
+ return {
69
+ ok: true,
70
+ value: $dsl.evaluate`${source}`(context)
71
+ };
72
+ } catch {
73
+ return {
74
+ ok: false
75
+ };
76
+ }
77
+ }
78
+ function evaluateExpression(source, context, fallback) {
79
+ const result = tryEvaluateExpression(source, context);
80
+ if (!result.ok) {
81
+ return fallback;
82
+ }
83
+ return result.value;
84
+ }
66
85
  function getConfigStyle(config2) {
67
86
  const style = {};
68
87
  if (!config2.style) {
69
88
  return style;
70
89
  }
71
- const styleMap = $dsl.evaluate`${config2.style}`({ form: modelValue.value });
90
+ const styleMap = evaluateExpression(config2.style, { form: modelValue.value }, {});
91
+ if (!styleMap || typeof styleMap !== "object" || Array.isArray(styleMap)) {
92
+ return style;
93
+ }
72
94
  for (const [key, value] of Object.entries(styleMap)) {
73
95
  if (typeof value === "string" || typeof value === "number") {
74
96
  Reflect.set(style, key, value);
@@ -80,7 +102,7 @@ function getFieldStyle(field) {
80
102
  if (!field.style) {
81
103
  return {};
82
104
  }
83
- const style = $dsl.evaluate`${field.style}`();
105
+ const style = evaluateExpression(field.style, void 0, {});
84
106
  const normalizedStyle = {};
85
107
  if (!style || typeof style !== "object" || Array.isArray(style)) {
86
108
  return normalizedStyle;
@@ -109,10 +131,10 @@ function displayCalendarValue(stored, displayFormat, valueFormat) {
109
131
  return stored ?? "";
110
132
  }
111
133
  function isFieldHidden(field) {
112
- return $dsl.evaluate`${field.hidden || "false"}`({ form: modelValue.value });
134
+ return evaluateExpression(field.hidden || "false", { form: modelValue.value }, false);
113
135
  }
114
136
  function isFieldDisabled(field) {
115
- return $dsl.evaluate`${field.disabled || "false"}`({ form: modelValue.value });
137
+ return evaluateExpression(field.disabled || "false", { form: modelValue.value }, false);
116
138
  }
117
139
  function getFieldValue(field) {
118
140
  return getProperty(modelValue.value, field.path);
@@ -122,7 +144,11 @@ function initializeFieldValues(config2) {
122
144
  if (isPassiveField(field) || !field.initialValue || hasProperty(modelValue.value, field.path)) {
123
145
  continue;
124
146
  }
125
- const initialValue = $dsl.evaluate`${field.initialValue}`({ form: modelValue.value });
147
+ const initialValueResult = tryEvaluateExpression(field.initialValue, { form: modelValue.value });
148
+ if (!initialValueResult.ok) {
149
+ continue;
150
+ }
151
+ const initialValue = initialValueResult.value;
126
152
  setProperty(
127
153
  modelValue.value,
128
154
  field.path,
@@ -155,12 +181,22 @@ function isSelectValueEqual(left, right) {
155
181
  return leftValue === rightValue;
156
182
  }
157
183
  function getSelectOptions(field) {
158
- return $dsl.evaluate`${field.options}`().map((option) => {
159
- return {
160
- key: $dsl.evaluate`${field.key}`({ option }),
161
- label: $dsl.evaluate`${field.label}`({ option }),
162
- value: $dsl.evaluate`${field.value}`({ option })
163
- };
184
+ const options = evaluateExpression(field.options, void 0, []);
185
+ if (!Array.isArray(options)) {
186
+ return [];
187
+ }
188
+ return options.flatMap((option) => {
189
+ const key = tryEvaluateExpression(field.key, { option });
190
+ const label = tryEvaluateExpression(field.label, { option });
191
+ const value = tryEvaluateExpression(field.value, { option });
192
+ if (!key.ok || !label.ok || !value.ok) {
193
+ return [];
194
+ }
195
+ return [{
196
+ key: key.value,
197
+ label: label.value,
198
+ value: value.value
199
+ }];
164
200
  });
165
201
  }
166
202
  function getSelectFieldState(field) {
@@ -251,7 +287,11 @@ function getValidationFailure(field) {
251
287
  form: modelValue.value
252
288
  };
253
289
  for (const rule of field.validation) {
254
- if (!$dsl.evaluate`${rule.expression}`(context)) {
290
+ const evaluation = tryEvaluateExpression(rule.expression, context);
291
+ if (!evaluation.ok) {
292
+ continue;
293
+ }
294
+ if (!evaluation.value) {
255
295
  return {
256
296
  message: rule.message,
257
297
  context: snapshotValidationContext(field)
@@ -300,6 +340,16 @@ function renderValidationMessage(field) {
300
340
  if (!error) return "";
301
341
  return $md.inline`${error.message}`(error.context);
302
342
  }
343
+ function isCalendarDateDisabled(field, date) {
344
+ if (!field.disableDate) {
345
+ return false;
346
+ }
347
+ return evaluateExpression(
348
+ field.disableDate,
349
+ { date: new TZDate(date.toDate(getLocalTimeZone())) },
350
+ false
351
+ );
352
+ }
303
353
  function handleCalendarOpenChange(field, open) {
304
354
  if (open) {
305
355
  calendarOpen.value[field.path] = true;
@@ -512,7 +562,7 @@ export {
512
562
  :layout="field.mode"
513
563
  :model-value="toCalendarDateValue(getProperty(modelValue, field.path), field.value)"
514
564
  :disabled="isFieldDisabled(field)"
515
- :is-date-disabled="field.disableDate ? (date) => !!$dsl.evaluate`${field.disableDate}`({ date: new TZDate(date.toDate(getLocalTimeZone())) }) : void 0"
565
+ :is-date-disabled="field.disableDate ? (date) => isCalendarDateDisabled(field, date) : void 0"
516
566
  @update:model-value="(value) => {
517
567
  if (value === void 0) {
518
568
  deleteProperty(modelValue, field.path);
@@ -425,7 +425,7 @@ defineTableRenderer(
425
425
  class: "p-1 w-6 h-6 flex items-center justify-center right-1 top-1/2 -translate-y-1/2 transform-3d group-hover:opacity-100 opacity-0 absolute transition-opacity duration-180",
426
426
  size: "xs",
427
427
  onClick: onCopy,
428
- children: /* @__PURE__ */ jsx(Icon, { icon: "fluent:copy-20-regular" })
428
+ children: () => /* @__PURE__ */ jsx(Icon, { icon: "fluent:copy-20-regular" })
429
429
  }
430
430
  ) : null
431
431
  ]
@@ -500,7 +500,7 @@ defineTableRenderer(
500
500
  class: "cursor-pointer hover:bg-transparent text-lg",
501
501
  "aria-label": ctx.row.getIsExpanded() ? getTableRendererConfigText("collapse-row") : getTableRendererConfigText("expand-row"),
502
502
  onClick: ctx.row.getToggleExpandedHandler(),
503
- children: /* @__PURE__ */ jsx(Icon, { icon: ctx.row.getIsExpanded() ? "fluent:subtract-square-20-regular" : "fluent:add-square-20-regular" })
503
+ children: () => /* @__PURE__ */ jsx(Icon, { icon: ctx.row.getIsExpanded() ? "fluent:subtract-square-20-regular" : "fluent:add-square-20-regular" })
504
504
  }
505
505
  ) });
506
506
  },
@@ -512,7 +512,7 @@ defineTableRenderer(
512
512
  class: "cursor-pointer hover:bg-transparent text-lg",
513
513
  "aria-label": ctx.table.getIsAllRowsExpanded() ? getTableRendererConfigText("collapse-all-rows") : getTableRendererConfigText("expand-all-rows"),
514
514
  onClick: ctx.table.getToggleAllRowsExpandedHandler(),
515
- children: /* @__PURE__ */ jsx(Icon, { icon: ctx.table.getIsAllRowsExpanded() ? "fluent:subtract-square-20-regular" : "fluent:add-square-20-regular" })
515
+ children: () => /* @__PURE__ */ jsx(Icon, { icon: ctx.table.getIsAllRowsExpanded() ? "fluent:subtract-square-20-regular" : "fluent:add-square-20-regular" })
516
516
  }
517
517
  ) }),
518
518
  config: NoOptionsConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
- "version": "0.11.20",
3
+ "version": "0.11.22",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",