@ouroboros/mouth-mui 1.0.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/LICENSE +8 -0
- package/README.md +15 -0
- package/package.json +55 -0
- package/src/components/pages/Locales.d.ts +35 -0
- package/src/components/pages/Locales.js +188 -0
- package/src/components/pages/Locales.tsx +254 -0
- package/src/components/pages/Templates/Create.d.ts +36 -0
- package/src/components/pages/Templates/Create.js +98 -0
- package/src/components/pages/Templates/Create.tsx +139 -0
- package/src/components/pages/Templates/Template/Content/Create/Email.d.ts +39 -0
- package/src/components/pages/Templates/Template/Content/Create/Email.js +51 -0
- package/src/components/pages/Templates/Template/Content/Create/Email.tsx +96 -0
- package/src/components/pages/Templates/Template/Content/Create/SMS.d.ts +37 -0
- package/src/components/pages/Templates/Template/Content/Create/SMS.js +42 -0
- package/src/components/pages/Templates/Template/Content/Create/SMS.tsx +68 -0
- package/src/components/pages/Templates/Template/Content/Create/index.d.ts +42 -0
- package/src/components/pages/Templates/Template/Content/Create/index.js +177 -0
- package/src/components/pages/Templates/Template/Content/Create/index.tsx +257 -0
- package/src/components/pages/Templates/Template/Content/Preview/Email.d.ts +37 -0
- package/src/components/pages/Templates/Template/Content/Preview/Email.js +51 -0
- package/src/components/pages/Templates/Template/Content/Preview/Email.tsx +78 -0
- package/src/components/pages/Templates/Template/Content/Preview/SMS.d.ts +32 -0
- package/src/components/pages/Templates/Template/Content/Preview/SMS.js +38 -0
- package/src/components/pages/Templates/Template/Content/Preview/SMS.tsx +59 -0
- package/src/components/pages/Templates/Template/Content/Preview/index.d.ts +42 -0
- package/src/components/pages/Templates/Template/Content/Preview/index.js +63 -0
- package/src/components/pages/Templates/Template/Content/Preview/index.tsx +107 -0
- package/src/components/pages/Templates/Template/Content/Update/Email.d.ts +39 -0
- package/src/components/pages/Templates/Template/Content/Update/Email.js +51 -0
- package/src/components/pages/Templates/Template/Content/Update/Email.tsx +96 -0
- package/src/components/pages/Templates/Template/Content/Update/SMS.d.ts +37 -0
- package/src/components/pages/Templates/Template/Content/Update/SMS.js +42 -0
- package/src/components/pages/Templates/Template/Content/Update/SMS.tsx +68 -0
- package/src/components/pages/Templates/Template/Content/Update/index.d.ts +42 -0
- package/src/components/pages/Templates/Template/Content/Update/index.js +117 -0
- package/src/components/pages/Templates/Template/Content/Update/index.tsx +162 -0
- package/src/components/pages/Templates/Template/Content/View/Email.d.ts +43 -0
- package/src/components/pages/Templates/Template/Content/View/Email.js +57 -0
- package/src/components/pages/Templates/Template/Content/View/Email.tsx +80 -0
- package/src/components/pages/Templates/Template/Content/View/SMS.d.ts +41 -0
- package/src/components/pages/Templates/Template/Content/View/SMS.js +46 -0
- package/src/components/pages/Templates/Template/Content/View/SMS.tsx +64 -0
- package/src/components/pages/Templates/Template/Content/View/index.d.ts +39 -0
- package/src/components/pages/Templates/Template/Content/View/index.js +50 -0
- package/src/components/pages/Templates/Template/Content/View/index.tsx +78 -0
- package/src/components/pages/Templates/Template/Variables.d.ts +34 -0
- package/src/components/pages/Templates/Template/Variables.js +91 -0
- package/src/components/pages/Templates/Template/Variables.tsx +138 -0
- package/src/components/pages/Templates/Template/index.d.ts +90 -0
- package/src/components/pages/Templates/Template/index.js +207 -0
- package/src/components/pages/Templates/Template/index.tsx +337 -0
- package/src/components/pages/Templates/index.d.ts +35 -0
- package/src/components/pages/Templates/index.js +112 -0
- package/src/components/pages/Templates/index.tsx +165 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +5 -0
- package/src/index.ts +8 -0
- package/src/locales.d.ts +72 -0
- package/src/locales.js +160 -0
- package/src/locales.ts +200 -0
package/src/locales.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locales
|
|
3
|
+
*
|
|
4
|
+
* Keeps track of the locales available
|
|
5
|
+
*
|
|
6
|
+
* @author Chris Nasr <chris@ouroboroscoding.com>
|
|
7
|
+
* @copyright Ouroboros Coding Inc.
|
|
8
|
+
* @created 2021-03-17
|
|
9
|
+
*/
|
|
10
|
+
import Subscribe, { SubscribeCallback, SubscribeReturn } from '@ouroboros/subscribe';
|
|
11
|
+
export type Option = {
|
|
12
|
+
id: string;
|
|
13
|
+
text: string;
|
|
14
|
+
};
|
|
15
|
+
export type Options = Record<string, Option[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Locales
|
|
18
|
+
*
|
|
19
|
+
* Extends the Subscribe class to be created once and exported
|
|
20
|
+
*
|
|
21
|
+
* @name Locales
|
|
22
|
+
* @extends Subscribe
|
|
23
|
+
*/
|
|
24
|
+
declare class Locales extends Subscribe {
|
|
25
|
+
private running;
|
|
26
|
+
/**
|
|
27
|
+
* Constructor
|
|
28
|
+
*
|
|
29
|
+
* Creates a new instance
|
|
30
|
+
*
|
|
31
|
+
* @name Locales
|
|
32
|
+
* @access public
|
|
33
|
+
* @returns a new instance
|
|
34
|
+
*/
|
|
35
|
+
constructor();
|
|
36
|
+
/**
|
|
37
|
+
* Array Sort
|
|
38
|
+
*
|
|
39
|
+
* Splits the records so they are stored by locale and then orders them
|
|
40
|
+
* alphabetically
|
|
41
|
+
*
|
|
42
|
+
* @name arraySort
|
|
43
|
+
* @param records The records to sort
|
|
44
|
+
* @param idKey The primary key of the records to sort
|
|
45
|
+
* @param valueKey The value with locale data in the records
|
|
46
|
+
*/
|
|
47
|
+
static arraySort(records: Record<string, any>[], idKey?: string, valueKey?: string): Options;
|
|
48
|
+
/**
|
|
49
|
+
* Object Sort
|
|
50
|
+
*
|
|
51
|
+
* Splits the records so they are stored by locale and then orders them
|
|
52
|
+
* alphabetically
|
|
53
|
+
*
|
|
54
|
+
* @name objectSort
|
|
55
|
+
* @access public
|
|
56
|
+
* @param records The records to re-order
|
|
57
|
+
* @returns an object of locale keys to option records sorted by the display
|
|
58
|
+
* text
|
|
59
|
+
*/
|
|
60
|
+
static objectSort(records: Record<string, Record<string, string>>): Options;
|
|
61
|
+
/**
|
|
62
|
+
* Subscribe
|
|
63
|
+
*
|
|
64
|
+
* Override the subscribe method to initiate the fetching process
|
|
65
|
+
*
|
|
66
|
+
* @name subscribe
|
|
67
|
+
* @access public
|
|
68
|
+
*/
|
|
69
|
+
subscribe(callback: SubscribeCallback): SubscribeReturn;
|
|
70
|
+
}
|
|
71
|
+
declare const locale: Locales;
|
|
72
|
+
export default locale;
|
package/src/locales.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locales
|
|
3
|
+
*
|
|
4
|
+
* Keeps track of the locales available
|
|
5
|
+
*
|
|
6
|
+
* @author Chris Nasr <chris@ouroboroscoding.com>
|
|
7
|
+
* @copyright Ouroboros Coding Inc.
|
|
8
|
+
* @created 2021-03-17
|
|
9
|
+
*/
|
|
10
|
+
// Ouroboros modules
|
|
11
|
+
import Subscribe from '@ouroboros/subscribe';
|
|
12
|
+
// Local modules
|
|
13
|
+
import mouth from '@ouroboros/mouth';
|
|
14
|
+
/**
|
|
15
|
+
* Locales
|
|
16
|
+
*
|
|
17
|
+
* Extends the Subscribe class to be created once and exported
|
|
18
|
+
*
|
|
19
|
+
* @name Locales
|
|
20
|
+
* @extends Subscribe
|
|
21
|
+
*/
|
|
22
|
+
class Locales extends Subscribe {
|
|
23
|
+
// Keeps the state of if the rest request is taking place
|
|
24
|
+
running;
|
|
25
|
+
/**
|
|
26
|
+
* Constructor
|
|
27
|
+
*
|
|
28
|
+
* Creates a new instance
|
|
29
|
+
*
|
|
30
|
+
* @name Locales
|
|
31
|
+
* @access public
|
|
32
|
+
* @returns a new instance
|
|
33
|
+
*/
|
|
34
|
+
constructor() {
|
|
35
|
+
// Call the Subscribe constructor with empty data
|
|
36
|
+
super([]);
|
|
37
|
+
// Init the running flag
|
|
38
|
+
this.running = false;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Array Sort
|
|
42
|
+
*
|
|
43
|
+
* Splits the records so they are stored by locale and then orders them
|
|
44
|
+
* alphabetically
|
|
45
|
+
*
|
|
46
|
+
* @name arraySort
|
|
47
|
+
* @param records The records to sort
|
|
48
|
+
* @param idKey The primary key of the records to sort
|
|
49
|
+
* @param valueKey The value with locale data in the records
|
|
50
|
+
*/
|
|
51
|
+
static arraySort(records, idKey = '_id', valueKey = 'name') {
|
|
52
|
+
// Init the return
|
|
53
|
+
const oRet = {};
|
|
54
|
+
// Go through each record
|
|
55
|
+
for (const oRecord of records) {
|
|
56
|
+
// Go through each locale
|
|
57
|
+
for (const sLocale of Object.keys(oRecord[valueKey])) {
|
|
58
|
+
// If we don't have the locale
|
|
59
|
+
if (!(sLocale in oRet)) {
|
|
60
|
+
oRet[sLocale] = [];
|
|
61
|
+
}
|
|
62
|
+
// Add the ID and text to the list
|
|
63
|
+
oRet[sLocale].push({
|
|
64
|
+
id: oRecord[idKey],
|
|
65
|
+
text: oRecord[valueKey][sLocale]
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Go through each locale
|
|
70
|
+
for (const sLocale of Object.keys(oRet)) {
|
|
71
|
+
// Sort it alphabetically
|
|
72
|
+
oRet[sLocale].sort((a, b) => {
|
|
73
|
+
if (a.text.normalize('NFD') === b.text.normalize('NFD'))
|
|
74
|
+
return 0;
|
|
75
|
+
else
|
|
76
|
+
return (a.text.normalize('NFD') < b.text.normalize('NFD')) ? -1 : 1;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
// Return the new structure
|
|
80
|
+
return oRet;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Object Sort
|
|
84
|
+
*
|
|
85
|
+
* Splits the records so they are stored by locale and then orders them
|
|
86
|
+
* alphabetically
|
|
87
|
+
*
|
|
88
|
+
* @name objectSort
|
|
89
|
+
* @access public
|
|
90
|
+
* @param records The records to re-order
|
|
91
|
+
* @returns an object of locale keys to option records sorted by the display
|
|
92
|
+
* text
|
|
93
|
+
*/
|
|
94
|
+
static objectSort(records) {
|
|
95
|
+
// Init the return
|
|
96
|
+
const oRet = {};
|
|
97
|
+
// Go through each record
|
|
98
|
+
for (const sID of Object.keys(records)) {
|
|
99
|
+
// Go through each locale
|
|
100
|
+
for (const sLocale of Object.keys(records[sID])) {
|
|
101
|
+
// If we don't have the locale
|
|
102
|
+
if (!(sLocale in oRet)) {
|
|
103
|
+
oRet[sLocale] = [];
|
|
104
|
+
}
|
|
105
|
+
// Add the ID and text to the list
|
|
106
|
+
oRet[sLocale].push({
|
|
107
|
+
id: sID,
|
|
108
|
+
text: records[sID][sLocale]
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Go through each locale
|
|
113
|
+
for (const sLocale of Object.keys(oRet)) {
|
|
114
|
+
// Sort it alphabetically
|
|
115
|
+
oRet[sLocale].sort((a, b) => {
|
|
116
|
+
if (a.text.normalize('NFD') === b.text.normalize('NFD'))
|
|
117
|
+
return 0;
|
|
118
|
+
else
|
|
119
|
+
return (a.text.normalize('NFD') < b.text.normalize('NFD')) ? -1 : 1;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
// Return the new structure
|
|
123
|
+
return oRet;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Subscribe
|
|
127
|
+
*
|
|
128
|
+
* Override the subscribe method to initiate the fetching process
|
|
129
|
+
*
|
|
130
|
+
* @name subscribe
|
|
131
|
+
* @access public
|
|
132
|
+
*/
|
|
133
|
+
subscribe(callback) {
|
|
134
|
+
// Call the Subscribe subscribe
|
|
135
|
+
const oReturn = super.subscribe(callback);
|
|
136
|
+
// If we don't have a value yet and it's not running
|
|
137
|
+
if (oReturn.data.length === 0 && this.running === false) {
|
|
138
|
+
// Mark us as running
|
|
139
|
+
this.running = true;
|
|
140
|
+
// Fetch the data from the server
|
|
141
|
+
mouth.read('locale').then((list) => {
|
|
142
|
+
// If there's data
|
|
143
|
+
if (list) {
|
|
144
|
+
// Trigger all callbacks
|
|
145
|
+
this.set(list);
|
|
146
|
+
}
|
|
147
|
+
// Finish running
|
|
148
|
+
this.running = false;
|
|
149
|
+
});
|
|
150
|
+
// Overwrite the data
|
|
151
|
+
oReturn.data = [];
|
|
152
|
+
}
|
|
153
|
+
// Return the Subscribe result
|
|
154
|
+
return oReturn;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// Create an instance of the class
|
|
158
|
+
const locale = new Locales();
|
|
159
|
+
// Default export
|
|
160
|
+
export default locale;
|
package/src/locales.ts
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locales
|
|
3
|
+
*
|
|
4
|
+
* Keeps track of the locales available
|
|
5
|
+
*
|
|
6
|
+
* @author Chris Nasr <chris@ouroboroscoding.com>
|
|
7
|
+
* @copyright Ouroboros Coding Inc.
|
|
8
|
+
* @created 2021-03-17
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// Ouroboros modules
|
|
12
|
+
import Subscribe, { SubscribeCallback, SubscribeReturn } from '@ouroboros/subscribe';
|
|
13
|
+
|
|
14
|
+
// Local modules
|
|
15
|
+
import mouth from '@ouroboros/mouth';
|
|
16
|
+
|
|
17
|
+
// Types
|
|
18
|
+
export type Option = {
|
|
19
|
+
id: string,
|
|
20
|
+
text: string
|
|
21
|
+
}
|
|
22
|
+
export type Options = Record<string, Option[]>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Locales
|
|
26
|
+
*
|
|
27
|
+
* Extends the Subscribe class to be created once and exported
|
|
28
|
+
*
|
|
29
|
+
* @name Locales
|
|
30
|
+
* @extends Subscribe
|
|
31
|
+
*/
|
|
32
|
+
class Locales extends Subscribe {
|
|
33
|
+
|
|
34
|
+
// Keeps the state of if the rest request is taking place
|
|
35
|
+
private running: boolean;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Constructor
|
|
39
|
+
*
|
|
40
|
+
* Creates a new instance
|
|
41
|
+
*
|
|
42
|
+
* @name Locales
|
|
43
|
+
* @access public
|
|
44
|
+
* @returns a new instance
|
|
45
|
+
*/
|
|
46
|
+
constructor() {
|
|
47
|
+
|
|
48
|
+
// Call the Subscribe constructor with empty data
|
|
49
|
+
super([]);
|
|
50
|
+
|
|
51
|
+
// Init the running flag
|
|
52
|
+
this.running = false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Array Sort
|
|
57
|
+
*
|
|
58
|
+
* Splits the records so they are stored by locale and then orders them
|
|
59
|
+
* alphabetically
|
|
60
|
+
*
|
|
61
|
+
* @name arraySort
|
|
62
|
+
* @param records The records to sort
|
|
63
|
+
* @param idKey The primary key of the records to sort
|
|
64
|
+
* @param valueKey The value with locale data in the records
|
|
65
|
+
*/
|
|
66
|
+
static arraySort(records: Record<string, any>[], idKey='_id', valueKey='name'): Options {
|
|
67
|
+
|
|
68
|
+
// Init the return
|
|
69
|
+
const oRet: Options = {};
|
|
70
|
+
|
|
71
|
+
// Go through each record
|
|
72
|
+
for(const oRecord of records) {
|
|
73
|
+
|
|
74
|
+
// Go through each locale
|
|
75
|
+
for(const sLocale of Object.keys(oRecord[valueKey])) {
|
|
76
|
+
|
|
77
|
+
// If we don't have the locale
|
|
78
|
+
if(!(sLocale in oRet)) {
|
|
79
|
+
oRet[sLocale] = [];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Add the ID and text to the list
|
|
83
|
+
oRet[sLocale].push({
|
|
84
|
+
id: oRecord[idKey],
|
|
85
|
+
text: oRecord[valueKey][sLocale]
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Go through each locale
|
|
91
|
+
for(const sLocale of Object.keys(oRet)) {
|
|
92
|
+
|
|
93
|
+
// Sort it alphabetically
|
|
94
|
+
oRet[sLocale].sort((a, b) => {
|
|
95
|
+
if(a.text.normalize('NFD') === b.text.normalize('NFD')) return 0;
|
|
96
|
+
else return (a.text.normalize('NFD') < b.text.normalize('NFD')) ? -1 : 1;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Return the new structure
|
|
101
|
+
return oRet;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Object Sort
|
|
106
|
+
*
|
|
107
|
+
* Splits the records so they are stored by locale and then orders them
|
|
108
|
+
* alphabetically
|
|
109
|
+
*
|
|
110
|
+
* @name objectSort
|
|
111
|
+
* @access public
|
|
112
|
+
* @param records The records to re-order
|
|
113
|
+
* @returns an object of locale keys to option records sorted by the display
|
|
114
|
+
* text
|
|
115
|
+
*/
|
|
116
|
+
static objectSort(records: Record<string, Record<string, string>>): Options {
|
|
117
|
+
|
|
118
|
+
// Init the return
|
|
119
|
+
const oRet: Options = {};
|
|
120
|
+
|
|
121
|
+
// Go through each record
|
|
122
|
+
for(const sID of Object.keys(records)) {
|
|
123
|
+
|
|
124
|
+
// Go through each locale
|
|
125
|
+
for(const sLocale of Object.keys(records[sID])) {
|
|
126
|
+
|
|
127
|
+
// If we don't have the locale
|
|
128
|
+
if(!(sLocale in oRet)) {
|
|
129
|
+
oRet[sLocale] = [];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Add the ID and text to the list
|
|
133
|
+
oRet[sLocale].push({
|
|
134
|
+
id: sID,
|
|
135
|
+
text: records[sID][sLocale]
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Go through each locale
|
|
141
|
+
for(const sLocale of Object.keys(oRet)) {
|
|
142
|
+
|
|
143
|
+
// Sort it alphabetically
|
|
144
|
+
oRet[sLocale].sort((a, b) => {
|
|
145
|
+
if(a.text.normalize('NFD') === b.text.normalize('NFD')) return 0;
|
|
146
|
+
else return (a.text.normalize('NFD') < b.text.normalize('NFD')) ? -1 : 1;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Return the new structure
|
|
151
|
+
return oRet;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Subscribe
|
|
156
|
+
*
|
|
157
|
+
* Override the subscribe method to initiate the fetching process
|
|
158
|
+
*
|
|
159
|
+
* @name subscribe
|
|
160
|
+
* @access public
|
|
161
|
+
*/
|
|
162
|
+
subscribe(callback: SubscribeCallback): SubscribeReturn {
|
|
163
|
+
|
|
164
|
+
// Call the Subscribe subscribe
|
|
165
|
+
const oReturn = super.subscribe(callback);
|
|
166
|
+
|
|
167
|
+
// If we don't have a value yet and it's not running
|
|
168
|
+
if(oReturn.data.length === 0 && this.running === false) {
|
|
169
|
+
|
|
170
|
+
// Mark us as running
|
|
171
|
+
this.running = true;
|
|
172
|
+
|
|
173
|
+
// Fetch the data from the server
|
|
174
|
+
mouth.read('locale').then((list: any) => {
|
|
175
|
+
|
|
176
|
+
// If there's data
|
|
177
|
+
if(list) {
|
|
178
|
+
|
|
179
|
+
// Trigger all callbacks
|
|
180
|
+
this.set(list);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Finish running
|
|
184
|
+
this.running = false;
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Overwrite the data
|
|
188
|
+
oReturn.data = [];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Return the Subscribe result
|
|
192
|
+
return oReturn;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Create an instance of the class
|
|
197
|
+
const locale = new Locales();
|
|
198
|
+
|
|
199
|
+
// Default export
|
|
200
|
+
export default locale;
|