dbm 1.4.6 → 1.4.7
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/core/BaseObject.js +36 -0
- package/dbm.js +0 -1
- package/flow/ExternalObjectUpdater.js +65 -0
- package/flow/FlowProperty.js +2 -2
- package/flow/index.js +10 -1
- package/flow/updatefunctions/basic/SetProperty.js +30 -0
- package/flow/updatefunctions/basic/index.js +12 -0
- package/node/communication/PostmarkApiClient.js +5 -0
- package/node/communication/index.js +48 -4
- package/node/index.js +4 -0
- package/package.json +1 -1
- package/react/blocks/index.js +18 -0
- package/repository/index.js +24 -1
- package/startup/index.js +8 -1
- package/utils/KeywordReplace.js +102 -0
- package/utils/index.js +1 -0
package/core/BaseObject.js
CHANGED
|
@@ -20,4 +20,40 @@ export default class BaseObject extends Dbm.core.LifeCycleObject {
|
|
|
20
20
|
|
|
21
21
|
return this;
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
_getScopedCallFunctionCommand(aFunction, aArguments = []) {
|
|
25
|
+
let CallFunction = Dbm.objectPath(Dbm.getRepositoryItem("library"), "Dbm/commands/CallFunction");
|
|
26
|
+
let command = new CallFunction();
|
|
27
|
+
command.item.scopeObject = this;
|
|
28
|
+
command.item.callFunction = aFunction;
|
|
29
|
+
command.item.callArguments = aArguments;
|
|
30
|
+
|
|
31
|
+
return command;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_propertyOrName(aPropertyOrName) {
|
|
35
|
+
if(typeof(aPropertyOrName) === "string") {
|
|
36
|
+
return this.item[aPropertyOrName];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return aPropertyOrName;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
addUpdateCall(aPropertyOrName, aFunction, aArguments = []) {
|
|
43
|
+
let addUpdateCommand = Dbm.objectPath(Dbm.getRepositoryItem("library"), "Dbm/flow/addUpdateCommand");
|
|
44
|
+
addUpdateCommand(this._propertyOrName(aPropertyOrName), aMatchValue, this._getScopedCallFunctionCommand(aFunction, aArguments));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
addUpdateCallWhenMatched(aPropertyOrName, aMatchValue, aFunction, aArguments = []) {
|
|
48
|
+
let addUpdateCommandWhenMatched = Dbm.objectPath(Dbm.getRepositoryItem("library"), "Dbm/flow/addUpdateCommandWhenMatched");
|
|
49
|
+
addUpdateCommandWhenMatched(this._propertyOrName(aPropertyOrName), aMatchValue, this._getScopedCallFunctionCommand(aFunction, aArguments));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
destroy() {
|
|
53
|
+
if(this._item) {
|
|
54
|
+
//METODO: destroy item
|
|
55
|
+
}
|
|
56
|
+
this._item = null;
|
|
57
|
+
super.destroy();
|
|
58
|
+
}
|
|
23
59
|
}
|
package/dbm.js
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import Dbm from "../index.js";
|
|
2
|
+
|
|
3
|
+
export default class ExternalObjectUpdater extends Dbm.core.BaseObject {
|
|
4
|
+
_construct() {
|
|
5
|
+
super._construct();
|
|
6
|
+
|
|
7
|
+
this.item.requireProperty("object", null);
|
|
8
|
+
this.item.requireProperty("updateFunctions", []);
|
|
9
|
+
this.item.requireProperty("running", true);
|
|
10
|
+
|
|
11
|
+
this.addUpdateCallWhenMatched("running", true, this.start);
|
|
12
|
+
this.addUpdateCallWhenMatched("running", false, this.stop);
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get object() {
|
|
17
|
+
return this.item.object;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
addProperty(aName, aValue, aPath = null) {
|
|
21
|
+
if(!aPath) {
|
|
22
|
+
aPath = aName;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let property = this.item.requireProperty(aName, null);
|
|
26
|
+
property.setOrConnect(aValue);
|
|
27
|
+
let updateFunction = Dbm.flow.updatefunctions.basic.setProperty(this.item.properties.object, aPath, property);
|
|
28
|
+
this.item.setValue("update/" + aName, updateFunction);
|
|
29
|
+
this.item.addToArray("updateFunctions", updateFunction);
|
|
30
|
+
|
|
31
|
+
if(this.item.running) {
|
|
32
|
+
updateFunction.output.properties.value.startUpdating();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return property;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
start() {
|
|
39
|
+
let currentArray = this.item.updateFunctions;
|
|
40
|
+
let currentArrayLength = currentArray.length;
|
|
41
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
42
|
+
let updateFunction = currentArray[i];
|
|
43
|
+
updateFunction.output.properties.value.startUpdating();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
stop() {
|
|
50
|
+
let currentArray = this.item.updateFunctions;
|
|
51
|
+
let currentArrayLength = currentArray.length;
|
|
52
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
53
|
+
let updateFunction = currentArray[i];
|
|
54
|
+
updateFunction.output.properties.value.stopUpdating();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
destroy() {
|
|
61
|
+
this.stop();
|
|
62
|
+
|
|
63
|
+
super.destroy();
|
|
64
|
+
}
|
|
65
|
+
}
|
package/flow/FlowProperty.js
CHANGED
|
@@ -137,12 +137,12 @@ export default class FlowProperty extends Dbm.flow.FlowBaseObject {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
startUpdating() {
|
|
140
|
-
Dbm.
|
|
140
|
+
Dbm.getRepositoryItem("propertyUpdater").controller.addProperty(this);
|
|
141
141
|
return this;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
stopUpdating() {
|
|
145
|
-
Dbm.
|
|
145
|
+
Dbm.getRepositoryItem("propertyUpdater").controller.removeProperty(this);
|
|
146
146
|
return this;
|
|
147
147
|
}
|
|
148
148
|
|
package/flow/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export {default as UpdateFunctionInputs} from "./UpdateFunctionInputs.js";
|
|
|
7
7
|
export {default as UpdateFunctionOutputs} from "./UpdateFunctionOutputs.js";
|
|
8
8
|
export {default as DirtyCommands} from "./DirtyCommands.js";
|
|
9
9
|
export {default as FlowPropertyWithExternalInput} from "./FlowPropertyWithExternalInput.js";
|
|
10
|
+
export {default as ExternalObjectUpdater} from "./ExternalObjectUpdater.js";
|
|
10
11
|
|
|
11
12
|
export * as updatefunctions from "./updatefunctions/index.js";
|
|
12
13
|
export * as controllers from "./controllers/index.js";
|
|
@@ -48,7 +49,7 @@ export const addUpdateCommandWhenMatched = function(aProperty, aMatchValue, aCom
|
|
|
48
49
|
|
|
49
50
|
updateData["whenMatched"] = whenMatched;
|
|
50
51
|
|
|
51
|
-
return
|
|
52
|
+
return updateData;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
export const runWhenMatched = function(aProperty, aMatchValue, aCommand) {
|
|
@@ -83,4 +84,12 @@ export const animateValue = function(aValue, aTime = 0.5, aEasing = null) {
|
|
|
83
84
|
returnObject.setValue("updateCommand", updateCommand);
|
|
84
85
|
|
|
85
86
|
return returnObject;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export const externalObject = function(aObject) {
|
|
90
|
+
let returnObject = new Dbm.flow.ExternalObjectUpdater();
|
|
91
|
+
|
|
92
|
+
returnObject.item.properties.object.setOrConnect(aObject);
|
|
93
|
+
|
|
94
|
+
return returnObject;
|
|
86
95
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Dbm from "../../../index.js";
|
|
2
|
+
|
|
3
|
+
export default class SetProperty extends Dbm.flow.FlowUpdateFunction {
|
|
4
|
+
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
|
|
8
|
+
this.input.register("value", "");
|
|
9
|
+
this.input.register("object", null);
|
|
10
|
+
this.input.register("propertyName", null);
|
|
11
|
+
|
|
12
|
+
this.output.register("value", null);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_update() {
|
|
16
|
+
//console.log("_update");
|
|
17
|
+
|
|
18
|
+
let value = this.input.value;
|
|
19
|
+
|
|
20
|
+
let propertyName = this.input.propertyName;
|
|
21
|
+
let object = this.input.object;
|
|
22
|
+
|
|
23
|
+
if(propertyName && object) {
|
|
24
|
+
Dbm.setAtObjectPath(object, propertyName, value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
this.output.value = value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -7,6 +7,7 @@ export {default as PropertyOf} from "./PropertyOf.js";
|
|
|
7
7
|
export {default as PropertyOfWithDefault} from "./PropertyOfWithDefault.js";
|
|
8
8
|
export {default as MappedList} from "./MappedList.js";
|
|
9
9
|
export {default as Translation} from "./Translation.js";
|
|
10
|
+
export {default as SetProperty} from "./SetProperty.js";
|
|
10
11
|
|
|
11
12
|
export const runCommand = function(aValue, aCommand) {
|
|
12
13
|
let updateFunction = new Dbm.flow.updatefunctions.basic.RunCommand();
|
|
@@ -123,4 +124,15 @@ export const translationProperty = function(aId, aDefaultValue = null, aPath = n
|
|
|
123
124
|
let updateFunction = translation(aId, aDefaultValue, aPath, aAdditionalPath, aTranslations);
|
|
124
125
|
|
|
125
126
|
return updateFunction.output.properties.value;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export const setProperty = function(aObject, aPropertyName, aValue = null) {
|
|
130
|
+
let updateFunction = new Dbm.flow.updatefunctions.basic.SetProperty();
|
|
131
|
+
|
|
132
|
+
let properties = updateFunction.input.properties;
|
|
133
|
+
properties.value.setOrConnect(aValue);
|
|
134
|
+
properties.object.setOrConnect(aObject);
|
|
135
|
+
properties.propertyName.setOrConnect(aPropertyName);
|
|
136
|
+
|
|
137
|
+
return updateFunction;
|
|
126
138
|
}
|
|
@@ -33,6 +33,11 @@ export default class PostmarkApiClient extends Dbm.core.BaseObject {
|
|
|
33
33
|
TextBody: aMessageItem.textContent,
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
let replyTo = Dbm.objectPath(aMessageItem, "additionalData.replyTo");
|
|
37
|
+
if(replyTo) {
|
|
38
|
+
emailData["ReplyTo"] = replyTo;
|
|
39
|
+
}
|
|
40
|
+
|
|
36
41
|
let response = await fetch('https://api.postmarkapp.com/email', {
|
|
37
42
|
method: 'POST',
|
|
38
43
|
headers: {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import Dbm from "../../index.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
|
|
2
4
|
export {default as PostmarkApiClient} from "./PostmarkApiClient.js";
|
|
3
5
|
export {default as EmailMessage} from "./EmailMessage.js";
|
|
4
6
|
|
|
@@ -22,17 +24,59 @@ export const createEmailAction = async function(aTo, aSubject, aHtmlContent, aTe
|
|
|
22
24
|
return action;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
export const sendUnformattedEmail =
|
|
27
|
+
export const sendUnformattedEmail = function(aTo, aSubject, aBody, aFrom = null, aAdditionalData = null) {
|
|
26
28
|
return createEmailAction(aTo, aSubject, null, aBody, aFrom, aAdditionalData);
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
export const sendEmail =
|
|
30
|
-
|
|
31
|
-
let textBody = aBody; //METODO: strip tags
|
|
31
|
+
export const sendEmail = function(aTo, aSubject, aBody, aFrom = null, aAdditionalData = null) {
|
|
32
32
|
|
|
33
|
+
let textBody = null;
|
|
34
|
+
let textConverter = Dbm.repository.getControllerIfExists("htmlToTextConverter");
|
|
35
|
+
if(textConverter) {
|
|
36
|
+
textBody = textConverter.convertToText(aBody);
|
|
37
|
+
}
|
|
38
|
+
|
|
33
39
|
return createEmailAction(aTo, aSubject, aBody, textBody, aFrom, aAdditionalData);
|
|
34
40
|
}
|
|
35
41
|
|
|
42
|
+
export const sendEmailTemplate = async function(aTemplateIdentifer, aTo, aKeywordReplace, aLanguage = "default", aDesignFilePath = null, aFrom = null, aAdditionalData = null) {
|
|
43
|
+
let emailTemplate = await Dbm.node.getDatabase().getIdentifiableObjectIfExists("emailTemplate", aTemplateIdentifer);
|
|
44
|
+
|
|
45
|
+
if(emailTemplate) {
|
|
46
|
+
await Dbm.node.forAll(emailTemplate.loadFields(), emailTemplate.loadFieldTranslations("title", "content"));
|
|
47
|
+
|
|
48
|
+
let subject = aKeywordReplace.replaceKeywords(emailTemplate.getTranslatedFieldValue("title", aLanguage));
|
|
49
|
+
let content = aKeywordReplace.replaceKeywords(emailTemplate.getTranslatedFieldValue("content", aLanguage));
|
|
50
|
+
|
|
51
|
+
if(!aDesignFilePath) {
|
|
52
|
+
aDesignFilePath = Dbm.repository.getValueIfExists("emailDesigns", "default/" + aLanguage);
|
|
53
|
+
|
|
54
|
+
if(!aDesignFilePath && (aLanguage !== "default")) {
|
|
55
|
+
aDesignFilePath = Dbm.repository.getValueIfExists("emailDesigns", "default/default");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if(aDesignFilePath) {
|
|
60
|
+
//let assetsDir = Dbm.getInstance().repository.getItem("site").assetsDir;
|
|
61
|
+
let mailContent = await fs.promises.readFile(aDesignFilePath, 'utf8');
|
|
62
|
+
|
|
63
|
+
let designKeywordReplace = new Dbm.utils.KeywordReplace();
|
|
64
|
+
designKeywordReplace.addKeyword("subject", subject);
|
|
65
|
+
designKeywordReplace.addKeyword("content", content);
|
|
66
|
+
designKeywordReplace.addKeyword("language", (aLanguage !== "default") ? aLanguage : ""); //MENOTE: get default language
|
|
67
|
+
|
|
68
|
+
//MENOTE: should we have keywords from settings here
|
|
69
|
+
|
|
70
|
+
content = designKeywordReplace.replaceKeywords(mailContent);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
await sendEmail(aTo, subject, content, aFrom, aAdditionalData);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
console.warn("No email template " + aTemplateIdentifer);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
36
80
|
export const createPostmarkClient = function(aToken, aDefaultFromEmail = null) {
|
|
37
81
|
let client = new Dbm.node.communication.PostmarkApiClient();
|
|
38
82
|
|
package/node/index.js
CHANGED
package/package.json
CHANGED
package/react/blocks/index.js
CHANGED
|
@@ -591,7 +591,25 @@ export let registerAllBlocks = function() {
|
|
|
591
591
|
pageEditors.push(newEditor);
|
|
592
592
|
}
|
|
593
593
|
|
|
594
|
+
{
|
|
595
|
+
let objectTypeEditor = Dbm.getInstance().repository.getItem("admin/objectTypeEditors/emailTemplate");
|
|
596
|
+
if(!objectTypeEditor.editors) {
|
|
597
|
+
objectTypeEditor.setValue("editors", []);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
let newArray = [].concat(objectTypeEditor.editors);
|
|
601
|
+
newArray.push(Dbm.getInstance().repository.getItem("admin/itemEditors/name"));
|
|
602
|
+
newArray.push(Dbm.getInstance().repository.getItem("admin/itemEditors/identifier"));
|
|
603
|
+
newArray.push(Dbm.getInstance().repository.getItem("admin/itemEditors/title"));
|
|
594
604
|
|
|
605
|
+
{
|
|
606
|
+
let itemEditor = new Dbm.repository.Item();
|
|
607
|
+
itemEditor.setValue("element", createElement(Dbm.react.admin.objects.itemeditors.RichTextFieldWithTranslations, {"label": "Content", "fieldName": "content"}));
|
|
608
|
+
newArray.push(itemEditor);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
objectTypeEditor.editors = newArray;
|
|
612
|
+
}
|
|
595
613
|
|
|
596
614
|
admin.pageEditors = pageEditors;
|
|
597
615
|
|
package/repository/index.js
CHANGED
|
@@ -1,2 +1,25 @@
|
|
|
1
|
+
import Dbm from "../index.js";
|
|
2
|
+
|
|
1
3
|
export {default as Item} from "./Item.js";
|
|
2
|
-
export {default as Repository} from "./Repository.js";
|
|
4
|
+
export {default as Repository} from "./Repository.js";
|
|
5
|
+
|
|
6
|
+
export const getItem = function(aName) {
|
|
7
|
+
return Dbm.getInstance().repository.getItem(aName);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const getItemIfExists = function(aName) {
|
|
11
|
+
return Dbm.getInstance().repository.getItemIfExists(aName);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const getValueIfExists = function(aObjectName, aPropertyName) {
|
|
15
|
+
let object = getItemIfExists(aObjectName);
|
|
16
|
+
if(!object) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return Dbm.objectPath(object, aPropertyName);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const getControllerIfExists = function(aObjectName) {
|
|
24
|
+
return getValueIfExists(aObjectName, "controller");
|
|
25
|
+
}
|
package/startup/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import Dbm from "../index.js";
|
|
|
3
3
|
export {default as Runner} from "./Runner.js";
|
|
4
4
|
export {default as Controller} from "./Controller.js";
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export const runStartup = function(aGlobalScope = "dbmstartup", aModulesName = "modules") {
|
|
7
7
|
if(!window[aGlobalScope][aModulesName].isSetup) {
|
|
8
8
|
let controller = new Dbm.startup.Controller();
|
|
9
9
|
|
|
@@ -25,4 +25,11 @@ export let runStartup = function(aGlobalScope = "dbmstartup", aModulesName = "mo
|
|
|
25
25
|
|
|
26
26
|
currentArray.splice(0, currentArrayLength);
|
|
27
27
|
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const setupLibrary = function() {
|
|
31
|
+
let library = Dbm.getRepositoryItem("library");
|
|
32
|
+
library.setValue("Dbm/commands/CallFunction", Dbm.commands.CallFunction);
|
|
33
|
+
library.setValue("Dbm/flow/addUpdateCommand", Dbm.flow.addUpdateCommand);
|
|
34
|
+
library.setValue("Dbm/flow/addUpdateCommandWhenMatched", Dbm.flow.addUpdateCommandWhenMatched);
|
|
28
35
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import Dbm from "../index.js";
|
|
2
|
+
|
|
3
|
+
export default class KeywordReplace extends Dbm.core.BaseObject {
|
|
4
|
+
|
|
5
|
+
_construct() {
|
|
6
|
+
super._construct();
|
|
7
|
+
|
|
8
|
+
this.item.setValue("keywordStart", "{{");
|
|
9
|
+
this.item.setValue("keywordMatch", "[^\\{\\}]*");
|
|
10
|
+
this.item.setValue("keywordEnd", "}}");
|
|
11
|
+
|
|
12
|
+
this.item.setValue("keywordProviders", []);
|
|
13
|
+
this.addKeywordProvider("default", {});
|
|
14
|
+
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
addKeyword(aKeyword, aValue) {
|
|
19
|
+
this.item["keywordProvider/default"][aKeyword.toLowerCase()] = aValue;
|
|
20
|
+
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
addKeywordProvider(aName, aKeywordProvider) {
|
|
25
|
+
this.item.addToArray("keywordProviders", aKeywordProvider);
|
|
26
|
+
this.item.setValue("keywordProvider/" + aName.toLowerCase(), aKeywordProvider);
|
|
27
|
+
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
escapeRegex(aText) {
|
|
32
|
+
return aText.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_getRegex() {
|
|
36
|
+
let keywordStart = this.escapeRegex(this.item.keywordStart);
|
|
37
|
+
let keywordEnd = this.escapeRegex(this.item.keywordEnd);
|
|
38
|
+
|
|
39
|
+
let regex = new RegExp(keywordStart + "\\s*(" + this.item.keywordMatch + ")\\s*" + keywordEnd, "g");
|
|
40
|
+
|
|
41
|
+
return regex;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_trimRegexKey(aRegexResult) {
|
|
45
|
+
let normalizedKey = aRegexResult[1].replace(/\s+/g, "").toLowerCase();
|
|
46
|
+
return normalizedKey;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
findKeywords(aText) {
|
|
50
|
+
|
|
51
|
+
let regex = this._getRegex();
|
|
52
|
+
|
|
53
|
+
let keywords = [...regex].map(this._trimRegexKey);
|
|
54
|
+
|
|
55
|
+
return keywords;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getKeywordValue(aKeyword) {
|
|
59
|
+
|
|
60
|
+
let index = aKeyword.indexOf(":");
|
|
61
|
+
if(index === -1) {
|
|
62
|
+
let currentArray = this.item.keywordProviders;
|
|
63
|
+
let currentArrayLength = currentArray.length;
|
|
64
|
+
for(let i = 0; i < currentArrayLength; i++) {
|
|
65
|
+
let provider = currentArray[i];
|
|
66
|
+
let value = Dbm.objectPath(provider, aKeyword);
|
|
67
|
+
if(value !== undefined) {
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
let group = aKeyword.substring(0, index);
|
|
74
|
+
let keyword = aKeyword.substring(index+1);
|
|
75
|
+
|
|
76
|
+
let value = Dbm.objectPath(this.item["keywordProvider/" + group.toLowerCase()], keyword.toLowerCase());
|
|
77
|
+
if(value !== undefined) {
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
_regexReplaceKeyword(aFullMatch, aKey) {
|
|
86
|
+
let normalizedKey = aKey.replace(/\s+/g, "");
|
|
87
|
+
|
|
88
|
+
let newValue = this.getKeywordValue(normalizedKey);
|
|
89
|
+
if(newValue) {
|
|
90
|
+
return newValue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return aFullMatch;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
replaceKeywords(aText) {
|
|
97
|
+
let newText = aText.replace(this._getRegex(), this._regexReplaceKeyword.bind(this));
|
|
98
|
+
|
|
99
|
+
console.log(newText);
|
|
100
|
+
return newText;
|
|
101
|
+
}
|
|
102
|
+
}
|
package/utils/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * as ObjectFunctions from "./ObjectFunctions.js";
|
|
|
9
9
|
|
|
10
10
|
export {default as MultidimensionalArrayHolder} from "./MultidimensionalArrayHolder.js";
|
|
11
11
|
export {default as ArrayOperationResult} from "./ArrayOperationResult.js";
|
|
12
|
+
export {default as KeywordReplace} from "./KeywordReplace.js";
|
|
12
13
|
|
|
13
14
|
export * as thirdparty from "./thirdparty/index.js";
|
|
14
15
|
export * as svg from "./svg/index.js";
|