66import { computed , type ComputedRef } from 'vue'
77import { loadState } from '@nextcloud/initial-state'
88import { usePoliciesStore } from '../../../../../store/policies'
9- import { getDefaultSignatureTextPolicyConfig } from './model'
9+ import {
10+ getDefaultSignatureTextPolicyConfig ,
11+ normalizeSignatureTextPolicyConfig ,
12+ type SignatureTextPolicyConfig ,
13+ } from './model'
1014
1115const SIGNATURE_TEXT_DEFAULTS = getDefaultSignatureTextPolicyConfig ( )
1216
13- interface SignatureTextValues {
14- template : string
15- templateFontSize : number
16- signatureFontSize : number
17- signatureWidth : number
18- signatureHeight : number
19- renderMode : string
17+ interface SignatureTextValues extends SignatureTextPolicyConfig {
2018 templateError : string
2119 parsed : string
2220}
2321
24- export interface SignatureTextUiDefaults {
22+ export type SignatureTextUiDefaults = SignatureTextPolicyConfig
23+
24+ function readSignatureTextState ( keys : {
2525 template : string
26- templateFontSize : number
27- signatureFontSize : number
28- signatureWidth : number
29- signatureHeight : number
30- renderMode : string
26+ templateFontSize : string
27+ signatureFontSize : string
28+ signatureWidth : string
29+ signatureHeight : string
30+ renderMode ?: string
31+ } , defaultRenderMode : string ) : SignatureTextPolicyConfig {
32+ return normalizeSignatureTextPolicyConfig ( {
33+ template : loadState < string > ( 'libresign' , keys . template , SIGNATURE_TEXT_DEFAULTS . template ) ,
34+ template_font_size : loadState < number > ( 'libresign' , keys . templateFontSize , SIGNATURE_TEXT_DEFAULTS . templateFontSize ) ,
35+ signature_font_size : loadState < number > ( 'libresign' , keys . signatureFontSize , SIGNATURE_TEXT_DEFAULTS . signatureFontSize ) ,
36+ signature_width : loadState < number > ( 'libresign' , keys . signatureWidth , SIGNATURE_TEXT_DEFAULTS . signatureWidth ) ,
37+ signature_height : loadState < number > ( 'libresign' , keys . signatureHeight , SIGNATURE_TEXT_DEFAULTS . signatureHeight ) ,
38+ render_mode : keys . renderMode
39+ ? loadState < string > ( 'libresign' , keys . renderMode , defaultRenderMode )
40+ : defaultRenderMode ,
41+ } )
3142}
3243
3344export function getSignatureTextUiDefaults ( ) : SignatureTextUiDefaults {
34- return {
35- template : loadState < string > ( 'libresign' , 'default_signature_text_template' , SIGNATURE_TEXT_DEFAULTS . template ) ,
36- templateFontSize : Number ( loadState < number > ( 'libresign' , 'default_template_font_size' , SIGNATURE_TEXT_DEFAULTS . templateFontSize ) ) ,
37- signatureFontSize : Number ( loadState < number > ( 'libresign' , 'default_signature_font_size' , SIGNATURE_TEXT_DEFAULTS . signatureFontSize ) ) ,
38- signatureWidth : Number ( loadState < number > ( 'libresign' , 'default_signature_width' , SIGNATURE_TEXT_DEFAULTS . signatureWidth ) ) ,
39- signatureHeight : Number ( loadState < number > ( 'libresign' , 'default_signature_height' , SIGNATURE_TEXT_DEFAULTS . signatureHeight ) ) ,
40- // Reset must use canonical default, not current effective value.
41- renderMode : 'GRAPHIC_AND_DESCRIPTION' ,
42- }
45+ return readSignatureTextState ( {
46+ template : 'default_signature_text_template' ,
47+ templateFontSize : 'default_template_font_size' ,
48+ signatureFontSize : 'default_signature_font_size' ,
49+ signatureWidth : 'default_signature_width' ,
50+ signatureHeight : 'default_signature_height' ,
51+ } , 'GRAPHIC_AND_DESCRIPTION' )
4352}
4453
4554export function useSignatureTextPolicy ( ) : { values : ComputedRef < SignatureTextValues > } {
@@ -48,32 +57,16 @@ export function useSignatureTextPolicy(): { values: ComputedRef<SignatureTextVal
4857 const values = computed < SignatureTextValues > ( ( ) => {
4958 const signatureTextPolicy = policiesStore . policies . signature_text
5059
51- // Use policy value when present; otherwise fallback to existing initial state values.
52- let policyValue = SIGNATURE_TEXT_DEFAULTS
53-
54- if ( signatureTextPolicy ?. effectiveValue ) {
55- const decoded = typeof signatureTextPolicy . effectiveValue === 'string'
56- ? JSON . parse ( signatureTextPolicy . effectiveValue )
57- : signatureTextPolicy . effectiveValue
58-
59- policyValue = {
60- template : String ( decoded . template ?? SIGNATURE_TEXT_DEFAULTS . template ) ,
61- templateFontSize : Number ( decoded . template_font_size ?? SIGNATURE_TEXT_DEFAULTS . templateFontSize ) ,
62- signatureFontSize : Number ( decoded . signature_font_size ?? SIGNATURE_TEXT_DEFAULTS . signatureFontSize ) ,
63- signatureWidth : Number ( decoded . signature_width ?? SIGNATURE_TEXT_DEFAULTS . signatureWidth ) ,
64- signatureHeight : Number ( decoded . signature_height ?? SIGNATURE_TEXT_DEFAULTS . signatureHeight ) ,
65- renderMode : String ( decoded . render_mode ?? SIGNATURE_TEXT_DEFAULTS . renderMode ) ,
66- }
67- } else {
68- policyValue = {
69- template : loadState < string > ( 'libresign' , 'signature_text_template' , SIGNATURE_TEXT_DEFAULTS . template ) ,
70- templateFontSize : Number ( loadState < number > ( 'libresign' , 'template_font_size' , SIGNATURE_TEXT_DEFAULTS . templateFontSize ) ) ,
71- signatureFontSize : Number ( loadState < number > ( 'libresign' , 'signature_font_size' , SIGNATURE_TEXT_DEFAULTS . signatureFontSize ) ) ,
72- signatureWidth : Number ( loadState < number > ( 'libresign' , 'signature_width' , SIGNATURE_TEXT_DEFAULTS . signatureWidth ) ) ,
73- signatureHeight : Number ( loadState < number > ( 'libresign' , 'signature_height' , SIGNATURE_TEXT_DEFAULTS . signatureHeight ) ) ,
74- renderMode : String ( loadState < string > ( 'libresign' , 'signature_render_mode' , 'GRAPHIC_AND_DESCRIPTION' ) ) ,
75- }
76- }
60+ const policyValue = signatureTextPolicy ?. effectiveValue
61+ ? normalizeSignatureTextPolicyConfig ( signatureTextPolicy . effectiveValue )
62+ : readSignatureTextState ( {
63+ template : 'signature_text_template' ,
64+ templateFontSize : 'template_font_size' ,
65+ signatureFontSize : 'signature_font_size' ,
66+ signatureWidth : 'signature_width' ,
67+ signatureHeight : 'signature_height' ,
68+ renderMode : 'signature_render_mode' ,
69+ } , 'GRAPHIC_AND_DESCRIPTION' )
7770
7871 // Only non-policy values come from loadState (error/parsing results)
7972 return {
0 commit comments