-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathConfiguration.ts
161 lines (150 loc) · 3.74 KB
/
Configuration.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import type { Configuration } from "./ConfigurationTypes";
import deepmerge from "@fastify/deepmerge";
// TODO: Rework all of this with the formik schema approach
const default_config =
{ // these are the actual values we use
clip2tana: {
webtag: "#website",
markdown: false,
},
helper: {
usetanahelper: false,
helperurl: "http://localhost:8000/"
},
inbox: {
pushinbox: false,
superTags: [
{
id: '',
title: '',
fields: [
{ id: '' }
]
}
],
tanaapikey: '',
},
opengraph: {
useOpenGraph: false,
ogDescription: '',
ogTitle: '',
ogUrl: '',
ogType: '',
ogImage: '',
ogSite_Name: '',
}
};
const default_schema =
[ // and this is the schema to drive the UX
{
key: "clip2tana",
label: "Clipboard control (Tana paste)",
properties: [
{
key: "webtag",
label: "Tana tag for websites", type: "string",
},
{
key: "markdown",
label: "Convert HTML to markdown", type: "boolean",
},
],
},
// ADDING FUNCTIONALITY TO PUSH TO TANA INBOX API
{
key: "inbox",
label: "Inbox settings",
properties: [
{
key: "pushinbox",
label: "Push to inbox by default", type: "boolean",
},
{
key: "superTags",
label: "Super Tags",
type: "superTags",
},
{
key: "tanaapikey",
label: "Tana API key", type: "string",
},
]
},
// OpenGraph field support
{
key: "opengraph",
label: "OpenGraph Field Mapping",
properties: [
{
key: "useOpenGraph",
label: "Copy OpenGraph meta attributes", type: "boolean",
},
{
key: "ogDescription",
label: "OpenGraph Description Field Node ID", type: "string",
},
{
key: "ogTitle",
label: "OpenGraph Title Field Node ID", type: "string",
},
{
key: "ogUrl",
label: "OpenGraph URL Field Node ID", type: "string",
},
{
key: "ogType",
label: "OpenGraph Type Field Node ID", type: "string",
},
{
key: "ogImage",
label: "OpenGraph Image Field Node ID", type: "string",
},
{
key: "ogSite_Name",
label: "OpenGraph Site Name Field Node ID", type: "string",
},
]
},
// ADDING FUNCTIONALITY TO PUSH TO TANA HELPER
{
key: "helper",
label: "Use Tana Helper (not yet implemented)",
disabled: true,
properties: [
{
key: "usetanahelper",
label: "Push to Tana Helper", type: "boolean", disabled: true,
},
{
key: "helperurl",
label: "Tana Helper URL", type: "string", disabled: true,
},
]
},
];
// this complex looking approach is in an effort to get
// a unique object instance every time (to prevent pollution)
export function get_default_configuration():Configuration {
return structuredClone({
config: default_config,
schema: default_schema,
});
}
// helper function for deepmerge
function replaceByClonedSource(options) {
const clone = options.clone
return function (target, source) {
return clone(source)
}
}
export function merge_config(initial, new_config) {
const base = structuredClone(initial);
const merger = deepmerge({ mergeArray: replaceByClonedSource })
new_config = merger(base, new_config);
return new_config;
}
export function configure(configuration) {
// if no config, use default.
configuration = configuration?.config ?? get_default_configuration().config;
return configuration;
}