@abpjs/text-template-management 2.7.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.
package/dist/index.js ADDED
@@ -0,0 +1,829 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ TEXT_TEMPLATE_MANAGEMENT_ROUTES: () => TEXT_TEMPLATE_MANAGEMENT_ROUTES,
24
+ TemplateContentService: () => TemplateContentService,
25
+ TemplateContentsComponent: () => TemplateContentsComponent,
26
+ TemplateDefinitionService: () => TemplateDefinitionService,
27
+ TextTemplateManagementStateService: () => TextTemplateManagementStateService,
28
+ TextTemplatesComponent: () => TextTemplatesComponent,
29
+ eTextTemplateManagementComponents: () => eTextTemplateManagementComponents,
30
+ eTextTemplateManagementRouteNames: () => eTextTemplateManagementRouteNames,
31
+ useTextTemplates: () => useTextTemplates
32
+ });
33
+ module.exports = __toCommonJS(index_exports);
34
+
35
+ // src/enums/components.ts
36
+ var eTextTemplateManagementComponents = {
37
+ /**
38
+ * Key for the TextTemplates component.
39
+ * Use this to replace the default TextTemplates list with a custom implementation.
40
+ */
41
+ TextTemplates: "TextTemplateManagement.TextTemplates",
42
+ /**
43
+ * Key for the TemplateContents component.
44
+ * Use this to replace the default template content editor.
45
+ */
46
+ TemplateContents: "TextTemplateManagement.TemplateContents",
47
+ /**
48
+ * Key for the InlineTemplateContent component.
49
+ * Use this to replace the inline template content editor.
50
+ */
51
+ InlineTemplateContent: "TextTemplateManagement.InlineTemplateContent"
52
+ };
53
+
54
+ // src/enums/route-names.ts
55
+ var eTextTemplateManagementRouteNames = {
56
+ /**
57
+ * Administration route name key.
58
+ * Used for the administration menu group.
59
+ */
60
+ Administration: "AbpUiNavigation::Menu:Administration",
61
+ /**
62
+ * Text Templates route name key.
63
+ * Used for the text templates management route.
64
+ */
65
+ TextTemplates: "TextTemplateManagement::Menu:TextTemplates"
66
+ };
67
+
68
+ // src/constants/routes.ts
69
+ var TEXT_TEMPLATE_MANAGEMENT_ROUTES = {
70
+ routes: [
71
+ {
72
+ name: "TextTemplateManagement::Menu:TextTemplates",
73
+ path: "text-template-management",
74
+ layout: "application",
75
+ order: 100,
76
+ parentName: "AbpUiNavigation::Menu:Administration"
77
+ }
78
+ ]
79
+ };
80
+
81
+ // src/services/template-definition.service.ts
82
+ var TemplateDefinitionService = class {
83
+ constructor(restService) {
84
+ this.restService = restService;
85
+ /**
86
+ * API name for multi-API configurations
87
+ * @since 2.7.0
88
+ */
89
+ this.apiName = "default";
90
+ }
91
+ /**
92
+ * Get list of template definitions
93
+ * @param params Query parameters for filtering and pagination
94
+ * @returns Promise with list of template definitions
95
+ */
96
+ async getList(params = {}) {
97
+ return this.restService.request({
98
+ method: "GET",
99
+ url: "/api/text-template-management/template-definitions",
100
+ params
101
+ });
102
+ }
103
+ };
104
+
105
+ // src/services/template-content.service.ts
106
+ var TemplateContentService = class {
107
+ constructor(restService) {
108
+ this.restService = restService;
109
+ /**
110
+ * API name for multi-API configurations
111
+ * @since 2.7.0
112
+ */
113
+ this.apiName = "default";
114
+ }
115
+ /**
116
+ * Get template content by input parameters
117
+ * @param params Input parameters containing template name and optional culture name
118
+ * @returns Promise with template content
119
+ */
120
+ async getByInput(params) {
121
+ return this.restService.request({
122
+ method: "GET",
123
+ url: "/api/text-template-management/template-contents",
124
+ params
125
+ });
126
+ }
127
+ /**
128
+ * Restore template content to default
129
+ * @param body Input containing template name and culture name to restore
130
+ * @returns Promise that resolves when restore is complete
131
+ */
132
+ async restoreToDefaultByInput(body) {
133
+ return this.restService.request({
134
+ method: "PUT",
135
+ url: "/api/text-template-management/template-contents/restore-to-default",
136
+ body
137
+ });
138
+ }
139
+ /**
140
+ * Update template content
141
+ * @param body DTO containing template name, culture name, and new content
142
+ * @returns Promise with updated template content
143
+ */
144
+ async updateByInput(body) {
145
+ return this.restService.request({
146
+ method: "PUT",
147
+ url: "/api/text-template-management/template-contents",
148
+ body
149
+ });
150
+ }
151
+ };
152
+
153
+ // src/services/text-template-management-state.service.ts
154
+ var TextTemplateManagementStateService = class {
155
+ constructor(restService) {
156
+ this._state = {
157
+ templateDefinitions: [],
158
+ totalCount: 0,
159
+ selectedTemplate: null,
160
+ templateContent: null
161
+ };
162
+ this.templateDefinitionService = new TemplateDefinitionService(restService);
163
+ this.templateContentService = new TemplateContentService(restService);
164
+ }
165
+ // ==================== Getters ====================
166
+ /**
167
+ * Get template definitions from state
168
+ * @returns Array of template definitions
169
+ */
170
+ getTemplateDefinitions() {
171
+ return this._state.templateDefinitions;
172
+ }
173
+ /**
174
+ * Get total count of template definitions
175
+ * @returns Total count
176
+ */
177
+ getTotalCount() {
178
+ return this._state.totalCount;
179
+ }
180
+ /**
181
+ * Get the currently selected template
182
+ * @returns Selected template or null
183
+ */
184
+ getSelectedTemplate() {
185
+ return this._state.selectedTemplate;
186
+ }
187
+ /**
188
+ * Get template content from state
189
+ * @returns Template content or null
190
+ */
191
+ getTemplateContent() {
192
+ return this._state.templateContent;
193
+ }
194
+ // ==================== Dispatch Methods ====================
195
+ /**
196
+ * Dispatch action to fetch template definitions
197
+ * @param params Query parameters for filtering and pagination
198
+ * @returns Promise with list result
199
+ */
200
+ async dispatchGetTemplateDefinitions(params = {}) {
201
+ const result = await this.templateDefinitionService.getList(params);
202
+ this._state.templateDefinitions = result.items || [];
203
+ this._state.totalCount = this._state.templateDefinitions.length;
204
+ return result;
205
+ }
206
+ /**
207
+ * Dispatch action to get template content
208
+ * @param params Input containing template name and optional culture name
209
+ * @returns Promise with template content
210
+ */
211
+ async dispatchGetTemplateContent(params) {
212
+ const result = await this.templateContentService.getByInput(params);
213
+ this._state.templateContent = result;
214
+ return result;
215
+ }
216
+ /**
217
+ * Dispatch action to update template content
218
+ * @param body DTO containing template name, culture name, and content
219
+ * @returns Promise with updated template content
220
+ */
221
+ async dispatchUpdateTemplateContent(body) {
222
+ const result = await this.templateContentService.updateByInput(body);
223
+ this._state.templateContent = result;
224
+ return result;
225
+ }
226
+ /**
227
+ * Dispatch action to restore template content to default
228
+ * @param body Input containing template name and culture name
229
+ * @returns Promise that resolves when restore is complete
230
+ */
231
+ async dispatchRestoreToDefault(body) {
232
+ await this.templateContentService.restoreToDefaultByInput(body);
233
+ if (body.cultureName) {
234
+ await this.dispatchGetTemplateContent(body);
235
+ }
236
+ }
237
+ /**
238
+ * Set the selected template
239
+ * @param template Template to select or null to clear
240
+ */
241
+ setSelectedTemplate(template) {
242
+ this._state.selectedTemplate = template;
243
+ }
244
+ /**
245
+ * Clear all state
246
+ */
247
+ reset() {
248
+ this._state = {
249
+ templateDefinitions: [],
250
+ totalCount: 0,
251
+ selectedTemplate: null,
252
+ templateContent: null
253
+ };
254
+ }
255
+ };
256
+
257
+ // src/hooks/useTextTemplates.ts
258
+ var import_react = require("react");
259
+ var import_core = require("@abpjs/core");
260
+ function useTextTemplates() {
261
+ const restService = (0, import_core.useRestService)();
262
+ const templateDefinitionService = (0, import_react.useMemo)(
263
+ () => new TemplateDefinitionService(restService),
264
+ [restService]
265
+ );
266
+ const templateContentService = (0, import_react.useMemo)(
267
+ () => new TemplateContentService(restService),
268
+ [restService]
269
+ );
270
+ const [templateDefinitions, setTemplateDefinitions] = (0, import_react.useState)([]);
271
+ const [totalCount, setTotalCount] = (0, import_react.useState)(0);
272
+ const [selectedTemplate, setSelectedTemplate] = (0, import_react.useState)(null);
273
+ const [templateContent, setTemplateContent] = (0, import_react.useState)(null);
274
+ const [isLoading, setIsLoading] = (0, import_react.useState)(false);
275
+ const [error, setError] = (0, import_react.useState)(null);
276
+ const fetchTemplateDefinitions = (0, import_react.useCallback)(
277
+ async (params = {}) => {
278
+ setIsLoading(true);
279
+ setError(null);
280
+ try {
281
+ const result = await templateDefinitionService.getList(params);
282
+ const items = result.items || [];
283
+ setTemplateDefinitions(items);
284
+ setTotalCount(items.length);
285
+ } catch (err) {
286
+ const message = err instanceof Error ? err.message : "Failed to fetch template definitions";
287
+ setError(message);
288
+ } finally {
289
+ setIsLoading(false);
290
+ }
291
+ },
292
+ [templateDefinitionService]
293
+ );
294
+ const getTemplateContent = (0, import_react.useCallback)(
295
+ async (params) => {
296
+ setIsLoading(true);
297
+ setError(null);
298
+ try {
299
+ const result = await templateContentService.getByInput(params);
300
+ setTemplateContent(result);
301
+ } catch (err) {
302
+ const message = err instanceof Error ? err.message : "Failed to fetch template content";
303
+ setError(message);
304
+ } finally {
305
+ setIsLoading(false);
306
+ }
307
+ },
308
+ [templateContentService]
309
+ );
310
+ const updateTemplateContent = (0, import_react.useCallback)(
311
+ async (body) => {
312
+ setIsLoading(true);
313
+ setError(null);
314
+ try {
315
+ const result = await templateContentService.updateByInput(body);
316
+ setTemplateContent(result);
317
+ return { success: true };
318
+ } catch (err) {
319
+ const message = err instanceof Error ? err.message : "Failed to update template content";
320
+ setError(message);
321
+ return { success: false, error: message };
322
+ } finally {
323
+ setIsLoading(false);
324
+ }
325
+ },
326
+ [templateContentService]
327
+ );
328
+ const restoreToDefault = (0, import_react.useCallback)(
329
+ async (params) => {
330
+ setIsLoading(true);
331
+ setError(null);
332
+ try {
333
+ await templateContentService.restoreToDefaultByInput(params);
334
+ if (params.cultureName) {
335
+ const result = await templateContentService.getByInput(params);
336
+ setTemplateContent(result);
337
+ }
338
+ return { success: true };
339
+ } catch (err) {
340
+ const message = err instanceof Error ? err.message : "Failed to restore template to default";
341
+ setError(message);
342
+ return { success: false, error: message };
343
+ } finally {
344
+ setIsLoading(false);
345
+ }
346
+ },
347
+ [templateContentService]
348
+ );
349
+ const reset = (0, import_react.useCallback)(() => {
350
+ setTemplateDefinitions([]);
351
+ setTotalCount(0);
352
+ setSelectedTemplate(null);
353
+ setTemplateContent(null);
354
+ setError(null);
355
+ }, []);
356
+ return {
357
+ templateDefinitions,
358
+ totalCount,
359
+ selectedTemplate,
360
+ templateContent,
361
+ isLoading,
362
+ error,
363
+ fetchTemplateDefinitions,
364
+ getTemplateContent,
365
+ updateTemplateContent,
366
+ restoreToDefault,
367
+ setSelectedTemplate,
368
+ reset
369
+ };
370
+ }
371
+
372
+ // src/components/TextTemplatesComponent/TextTemplatesComponent.tsx
373
+ var import_react2 = require("react");
374
+ var import_jsx_runtime = require("react/jsx-runtime");
375
+ function TextTemplatesComponent({
376
+ onEditContents,
377
+ className = "",
378
+ pageSize = 10
379
+ }) {
380
+ const {
381
+ templateDefinitions,
382
+ isLoading,
383
+ error,
384
+ fetchTemplateDefinitions,
385
+ setSelectedTemplate
386
+ } = useTextTemplates();
387
+ const [currentPage, setCurrentPage] = (0, import_react2.useState)(1);
388
+ (0, import_react2.useEffect)(() => {
389
+ fetchTemplateDefinitions({
390
+ skipCount: (currentPage - 1) * pageSize,
391
+ maxResultCount: pageSize
392
+ });
393
+ }, [fetchTemplateDefinitions, currentPage, pageSize]);
394
+ const handleEditContents = (template) => {
395
+ setSelectedTemplate(template);
396
+ onEditContents?.(template);
397
+ };
398
+ const handlePageChange = (page) => {
399
+ setCurrentPage(page);
400
+ };
401
+ if (error) {
402
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: `text-templates-error ${className}`, style: styles.error, children: [
403
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
404
+ "Error loading templates: ",
405
+ error
406
+ ] }),
407
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
408
+ "button",
409
+ {
410
+ type: "button",
411
+ onClick: () => fetchTemplateDefinitions(),
412
+ style: styles.retryButton,
413
+ children: "Retry"
414
+ }
415
+ )
416
+ ] });
417
+ }
418
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: `text-templates-component ${className}`, style: styles.container, children: [
419
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "text-templates-header", style: styles.header, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { style: styles.title, children: "Text Templates" }) }),
420
+ isLoading ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: styles.loading, children: "Loading..." }) : templateDefinitions.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: styles.empty, children: "No text templates found." }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: styles.tableWrapper, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("table", { style: styles.table, children: [
421
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", { children: [
422
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { style: styles.th, children: "Name" }),
423
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { style: styles.th, children: "Display Name" }),
424
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { style: styles.th, children: "Is Layout" }),
425
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { style: styles.th, children: "Layout" }),
426
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { style: styles.th, children: "Default Culture" }),
427
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { style: styles.th, children: "Inline Localized" }),
428
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { style: styles.th, children: "Actions" })
429
+ ] }) }),
430
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", { children: templateDefinitions.map((template) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tr", { style: styles.tr, children: [
431
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { style: styles.td, children: template.name }),
432
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { style: styles.td, children: template.displayName }),
433
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { style: styles.td, children: template.isLayout ? "Yes" : "No" }),
434
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { style: styles.td, children: template.layout || "-" }),
435
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { style: styles.td, children: template.defaultCultureName || "-" }),
436
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { style: styles.td, children: template.isInlineLocalized ? "Yes" : "No" }),
437
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { style: styles.td, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
438
+ "button",
439
+ {
440
+ type: "button",
441
+ onClick: () => handleEditContents(template),
442
+ style: styles.actionButton,
443
+ children: "Edit Contents"
444
+ }
445
+ ) })
446
+ ] }, template.name)) })
447
+ ] }) }),
448
+ templateDefinitions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: styles.pagination, children: [
449
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
450
+ "button",
451
+ {
452
+ type: "button",
453
+ onClick: () => handlePageChange(currentPage - 1),
454
+ disabled: currentPage === 1,
455
+ style: styles.pageButton,
456
+ children: "Previous"
457
+ }
458
+ ),
459
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: styles.pageInfo, children: [
460
+ "Page ",
461
+ currentPage
462
+ ] }),
463
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
464
+ "button",
465
+ {
466
+ type: "button",
467
+ onClick: () => handlePageChange(currentPage + 1),
468
+ disabled: templateDefinitions.length < pageSize,
469
+ style: styles.pageButton,
470
+ children: "Next"
471
+ }
472
+ )
473
+ ] })
474
+ ] });
475
+ }
476
+ var styles = {
477
+ container: {
478
+ padding: "16px"
479
+ },
480
+ header: {
481
+ display: "flex",
482
+ justifyContent: "space-between",
483
+ alignItems: "center",
484
+ marginBottom: "16px"
485
+ },
486
+ title: {
487
+ margin: 0,
488
+ fontSize: "24px",
489
+ fontWeight: 600
490
+ },
491
+ loading: {
492
+ padding: "32px",
493
+ textAlign: "center",
494
+ color: "#666"
495
+ },
496
+ empty: {
497
+ padding: "32px",
498
+ textAlign: "center",
499
+ color: "#666"
500
+ },
501
+ error: {
502
+ padding: "32px",
503
+ textAlign: "center",
504
+ color: "#dc2626"
505
+ },
506
+ retryButton: {
507
+ marginTop: "8px",
508
+ padding: "8px 16px",
509
+ border: "none",
510
+ borderRadius: "4px",
511
+ backgroundColor: "#3b82f6",
512
+ color: "white",
513
+ cursor: "pointer"
514
+ },
515
+ tableWrapper: {
516
+ overflowX: "auto"
517
+ },
518
+ table: {
519
+ width: "100%",
520
+ borderCollapse: "collapse",
521
+ fontSize: "14px"
522
+ },
523
+ th: {
524
+ padding: "12px 8px",
525
+ textAlign: "left",
526
+ borderBottom: "2px solid #e5e7eb",
527
+ fontWeight: 600,
528
+ color: "#374151"
529
+ },
530
+ tr: {
531
+ borderBottom: "1px solid #e5e7eb"
532
+ },
533
+ td: {
534
+ padding: "12px 8px",
535
+ color: "#4b5563"
536
+ },
537
+ actionButton: {
538
+ padding: "6px 12px",
539
+ border: "none",
540
+ borderRadius: "4px",
541
+ backgroundColor: "#3b82f6",
542
+ color: "white",
543
+ fontSize: "12px",
544
+ cursor: "pointer"
545
+ },
546
+ pagination: {
547
+ display: "flex",
548
+ justifyContent: "center",
549
+ alignItems: "center",
550
+ gap: "16px",
551
+ marginTop: "16px"
552
+ },
553
+ pageButton: {
554
+ padding: "8px 16px",
555
+ border: "1px solid #e5e7eb",
556
+ borderRadius: "4px",
557
+ backgroundColor: "white",
558
+ cursor: "pointer"
559
+ },
560
+ pageInfo: {
561
+ color: "#6b7280"
562
+ }
563
+ };
564
+
565
+ // src/components/TemplateContentsComponent/TemplateContentsComponent.tsx
566
+ var import_react3 = require("react");
567
+ var import_jsx_runtime2 = require("react/jsx-runtime");
568
+ function TemplateContentsComponent({
569
+ templateName,
570
+ cultures = [],
571
+ defaultCultureName,
572
+ onSave,
573
+ onRestore,
574
+ className = ""
575
+ }) {
576
+ const {
577
+ templateContent,
578
+ isLoading,
579
+ error,
580
+ getTemplateContent,
581
+ updateTemplateContent,
582
+ restoreToDefault
583
+ } = useTextTemplates();
584
+ const [selectedCulture, setSelectedCulture] = (0, import_react3.useState)(defaultCultureName || "");
585
+ const [content, setContent] = (0, import_react3.useState)("");
586
+ const [referenceContent, setReferenceContent] = (0, import_react3.useState)("");
587
+ const [isSaving, setIsSaving] = (0, import_react3.useState)(false);
588
+ (0, import_react3.useEffect)(() => {
589
+ if (templateName && selectedCulture) {
590
+ getTemplateContent({
591
+ templateName,
592
+ cultureName: selectedCulture
593
+ });
594
+ }
595
+ }, [templateName, selectedCulture, getTemplateContent]);
596
+ (0, import_react3.useEffect)(() => {
597
+ if (templateName && defaultCultureName && defaultCultureName !== selectedCulture) {
598
+ setReferenceContent("Reference content would be loaded here");
599
+ }
600
+ }, [templateName, defaultCultureName, selectedCulture]);
601
+ (0, import_react3.useEffect)(() => {
602
+ if (templateContent) {
603
+ setContent(templateContent.content || "");
604
+ }
605
+ }, [templateContent]);
606
+ const handleCultureChange = (0, import_react3.useCallback)((e) => {
607
+ setSelectedCulture(e.target.value);
608
+ }, []);
609
+ const handleContentChange = (0, import_react3.useCallback)((e) => {
610
+ setContent(e.target.value);
611
+ }, []);
612
+ const handleSave = (0, import_react3.useCallback)(async () => {
613
+ if (!templateName || !selectedCulture) return;
614
+ setIsSaving(true);
615
+ const result = await updateTemplateContent({
616
+ templateName,
617
+ cultureName: selectedCulture,
618
+ content
619
+ });
620
+ setIsSaving(false);
621
+ if (result.success && templateContent) {
622
+ onSave?.(templateContent);
623
+ }
624
+ }, [templateName, selectedCulture, content, updateTemplateContent, templateContent, onSave]);
625
+ const handleRestoreToDefault = (0, import_react3.useCallback)(async () => {
626
+ if (!templateName || !selectedCulture) return;
627
+ const confirmed = window.confirm(
628
+ "Are you sure you want to restore this template to its default content?"
629
+ );
630
+ if (!confirmed) return;
631
+ setIsSaving(true);
632
+ const result = await restoreToDefault({
633
+ templateName,
634
+ cultureName: selectedCulture
635
+ });
636
+ setIsSaving(false);
637
+ if (result.success) {
638
+ onRestore?.();
639
+ }
640
+ }, [templateName, selectedCulture, restoreToDefault, onRestore]);
641
+ if (error) {
642
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: `template-contents-error ${className}`, style: styles2.error, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { children: [
643
+ "Error: ",
644
+ error
645
+ ] }) });
646
+ }
647
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: `template-contents-component ${className}`, style: styles2.container, children: [
648
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: styles2.header, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("h2", { style: styles2.title, children: [
649
+ "Edit Template: ",
650
+ templateName
651
+ ] }) }),
652
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: styles2.cultureSelector, children: [
653
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: "culture-select", style: styles2.label, children: "Culture:" }),
654
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
655
+ "select",
656
+ {
657
+ id: "culture-select",
658
+ value: selectedCulture,
659
+ onChange: handleCultureChange,
660
+ style: styles2.select,
661
+ children: [
662
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "", children: "Select a culture" }),
663
+ cultures.map((culture) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: culture.name, children: culture.displayName }, culture.name))
664
+ ]
665
+ }
666
+ )
667
+ ] }),
668
+ isLoading ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: styles2.loading, children: "Loading template content..." }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
669
+ referenceContent && defaultCultureName !== selectedCulture && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: styles2.referenceSection, children: [
670
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("h4", { style: styles2.sectionTitle, children: [
671
+ "Reference Content (",
672
+ defaultCultureName,
673
+ ")"
674
+ ] }),
675
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("pre", { style: styles2.referenceContent, children: referenceContent })
676
+ ] }),
677
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: styles2.editorSection, children: [
678
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("h4", { style: styles2.sectionTitle, children: [
679
+ "Content ",
680
+ selectedCulture ? `(${selectedCulture})` : ""
681
+ ] }),
682
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
683
+ "textarea",
684
+ {
685
+ value: content,
686
+ onChange: handleContentChange,
687
+ style: styles2.textarea,
688
+ rows: 15,
689
+ placeholder: "Enter template content...",
690
+ disabled: !selectedCulture
691
+ }
692
+ )
693
+ ] }),
694
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: styles2.actions, children: [
695
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
696
+ "button",
697
+ {
698
+ type: "button",
699
+ onClick: handleRestoreToDefault,
700
+ disabled: isSaving || !selectedCulture,
701
+ style: styles2.restoreButton,
702
+ children: "Restore to Default"
703
+ }
704
+ ),
705
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
706
+ "button",
707
+ {
708
+ type: "button",
709
+ onClick: handleSave,
710
+ disabled: isSaving || !selectedCulture,
711
+ style: styles2.saveButton,
712
+ children: isSaving ? "Saving..." : "Save"
713
+ }
714
+ )
715
+ ] })
716
+ ] })
717
+ ] });
718
+ }
719
+ var styles2 = {
720
+ container: {
721
+ padding: "16px"
722
+ },
723
+ header: {
724
+ marginBottom: "16px"
725
+ },
726
+ title: {
727
+ margin: 0,
728
+ fontSize: "20px",
729
+ fontWeight: 600
730
+ },
731
+ cultureSelector: {
732
+ marginBottom: "16px",
733
+ display: "flex",
734
+ alignItems: "center",
735
+ gap: "8px"
736
+ },
737
+ label: {
738
+ fontWeight: 500,
739
+ color: "#374151"
740
+ },
741
+ select: {
742
+ padding: "8px 12px",
743
+ borderRadius: "4px",
744
+ border: "1px solid #d1d5db",
745
+ fontSize: "14px",
746
+ minWidth: "200px"
747
+ },
748
+ loading: {
749
+ padding: "32px",
750
+ textAlign: "center",
751
+ color: "#666"
752
+ },
753
+ error: {
754
+ padding: "32px",
755
+ textAlign: "center",
756
+ color: "#dc2626"
757
+ },
758
+ referenceSection: {
759
+ marginBottom: "16px",
760
+ padding: "12px",
761
+ backgroundColor: "#f9fafb",
762
+ borderRadius: "4px"
763
+ },
764
+ sectionTitle: {
765
+ margin: "0 0 8px 0",
766
+ fontSize: "14px",
767
+ fontWeight: 500,
768
+ color: "#6b7280"
769
+ },
770
+ referenceContent: {
771
+ margin: 0,
772
+ padding: "8px",
773
+ backgroundColor: "#f3f4f6",
774
+ borderRadius: "4px",
775
+ fontSize: "13px",
776
+ fontFamily: "monospace",
777
+ whiteSpace: "pre-wrap",
778
+ maxHeight: "200px",
779
+ overflow: "auto"
780
+ },
781
+ editorSection: {
782
+ marginBottom: "16px"
783
+ },
784
+ textarea: {
785
+ width: "100%",
786
+ padding: "12px",
787
+ borderRadius: "4px",
788
+ border: "1px solid #d1d5db",
789
+ fontSize: "14px",
790
+ fontFamily: "monospace",
791
+ resize: "vertical",
792
+ minHeight: "200px"
793
+ },
794
+ actions: {
795
+ display: "flex",
796
+ justifyContent: "flex-end",
797
+ gap: "8px"
798
+ },
799
+ restoreButton: {
800
+ padding: "10px 20px",
801
+ border: "1px solid #d1d5db",
802
+ borderRadius: "4px",
803
+ backgroundColor: "white",
804
+ color: "#374151",
805
+ fontSize: "14px",
806
+ cursor: "pointer"
807
+ },
808
+ saveButton: {
809
+ padding: "10px 20px",
810
+ border: "none",
811
+ borderRadius: "4px",
812
+ backgroundColor: "#3b82f6",
813
+ color: "white",
814
+ fontSize: "14px",
815
+ cursor: "pointer"
816
+ }
817
+ };
818
+ // Annotate the CommonJS export names for ESM import in node:
819
+ 0 && (module.exports = {
820
+ TEXT_TEMPLATE_MANAGEMENT_ROUTES,
821
+ TemplateContentService,
822
+ TemplateContentsComponent,
823
+ TemplateDefinitionService,
824
+ TextTemplateManagementStateService,
825
+ TextTemplatesComponent,
826
+ eTextTemplateManagementComponents,
827
+ eTextTemplateManagementRouteNames,
828
+ useTextTemplates
829
+ });