@voiceflow/utils-designer 1.25.18 → 1.26.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.
@@ -2,8 +2,6 @@ import { BaseText } from '@voiceflow/base-types';
|
|
2
2
|
import type { Entity, Markup, MarkupSpan, Variable } from '@voiceflow/dtos';
|
3
3
|
import type { MultiAdapter } from 'bidirectional-adapter';
|
4
4
|
export type MarkupItem = Markup[number];
|
5
|
-
export declare const ENTITY_OR_VARIABLE_TEXT_REGEXP: RegExp;
|
6
|
-
export declare const EXPRESSION_VARIABLE_TEXT_REGEXP: RegExp;
|
7
5
|
export interface MarkupSpanText extends Omit<MarkupSpan, 'text'> {
|
8
6
|
text: [string];
|
9
7
|
attributes: {
|
@@ -53,15 +51,6 @@ export declare const replaceMarkupEntity: (markup: Markup, { oldEntityID, newEnt
|
|
53
51
|
}) => Markup;
|
54
52
|
export declare const fillMarkupWithVariablesValues: (promptText: string, variables: Record<string, string>) => string;
|
55
53
|
export declare const markupToString: MultiAdapter<Markup, string, [MarkupToStringFromOptions], [MarkupToStringToOptions]>;
|
56
|
-
interface MarkupToExpressionOptions {
|
57
|
-
entitiesMapByID: Partial<Record<string, Entity>>;
|
58
|
-
variablesMapByID: Partial<Record<string, Variable>>;
|
59
|
-
}
|
60
|
-
export declare const markupToExpression: MultiAdapter<Markup, string, [
|
61
|
-
MarkupToExpressionOptions
|
62
|
-
], [
|
63
|
-
MarkupToExpressionOptions
|
64
|
-
]>;
|
65
54
|
export declare const markupToSlate: MultiAdapter<Markup, BaseText.SlateTextValue, [{
|
66
55
|
iteration?: number | undefined;
|
67
56
|
entitiesMapByID: Partial<Record<string, Entity>>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"markup.util.d.ts","sourceRoot":"","sources":["../../src/markup.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,MAAM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C;OA2HxD,CAAC"}
|
package/build/cjs/markup.util.js
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.markupToSlate = exports.
|
3
|
+
exports.markupToSlate = exports.markupToString = exports.fillMarkupWithVariablesValues = exports.replaceMarkupEntity = exports.getMarkupVariableIDs = exports.getMarkupEntityIDs = exports.isMarkupWithEntities = exports.isMarkupEmpty = exports.isMarkupVariable = exports.isMarkupString = exports.isMarkupEntity = exports.isMarkupSpanLink = exports.isMarkupSpanText = exports.isMarkupSpan = exports.markupFactory = exports.isMarkupEntityReference = exports.isMarkupVariableReference = void 0;
|
4
4
|
const base_types_1 = require("@voiceflow/base-types");
|
5
5
|
const common_1 = require("@voiceflow/common");
|
6
6
|
const bidirectional_adapter_1 = require("bidirectional-adapter");
|
7
7
|
const slate_1 = require("slate");
|
8
8
|
const ts_pattern_1 = require("ts-pattern");
|
9
|
-
|
10
|
-
exports.EXPRESSION_VARIABLE_TEXT_REGEXP = /{{\[(\w*)]\.(\w*)}}/g;
|
9
|
+
const ENTITY_OR_VARIABLE_TEXT_REGEXP = /{(\w*)}/g;
|
11
10
|
const isMarkupVariableReference = (markupItem) => {
|
12
11
|
return markupItem.variableID !== undefined;
|
13
12
|
};
|
@@ -88,14 +87,7 @@ const replaceMarkupEntity = (markup, { oldEntityID, newEntityID }) => {
|
|
88
87
|
}, []);
|
89
88
|
};
|
90
89
|
exports.replaceMarkupEntity = replaceMarkupEntity;
|
91
|
-
const fillMarkupWithVariablesValues = (promptText, variables) => {
|
92
|
-
let s = promptText;
|
93
|
-
// eslint-disable-next-line guard-for-in
|
94
|
-
for (const prop in variables) {
|
95
|
-
s = s.replace(new RegExp(`{${prop}}`, 'g'), variables[prop]);
|
96
|
-
}
|
97
|
-
return s;
|
98
|
-
};
|
90
|
+
const fillMarkupWithVariablesValues = (promptText, variables) => Object.keys(variables).reduce((acc, prop) => acc.replace(new RegExp(`{${prop}}`, 'g'), variables[prop]), promptText);
|
99
91
|
exports.fillMarkupWithVariablesValues = fillMarkupWithVariablesValues;
|
100
92
|
exports.markupToString = (0, bidirectional_adapter_1.createMultiAdapter)((markup, { entitiesMapByID, variablesMapByID, ignoreMissingEntities, ignoreMissingVariables } = {
|
101
93
|
entitiesMapByID: {},
|
@@ -114,7 +106,7 @@ exports.markupToString = (0, bidirectional_adapter_1.createMultiAdapter)((markup
|
|
114
106
|
return `{${variablesMapByID[variableID]?.name ?? variableID}}`;
|
115
107
|
})
|
116
108
|
.exhaustive(), ''), (text, { entitiesMapByName, variablesMapByName }) => {
|
117
|
-
const matches = [...text.matchAll(
|
109
|
+
const matches = [...text.matchAll(ENTITY_OR_VARIABLE_TEXT_REGEXP)];
|
118
110
|
if (!matches.length)
|
119
111
|
return [{ text: [text] }];
|
120
112
|
const span = {
|
@@ -154,53 +146,6 @@ exports.markupToString = (0, bidirectional_adapter_1.createMultiAdapter)((markup
|
|
154
146
|
}
|
155
147
|
return [span];
|
156
148
|
});
|
157
|
-
exports.markupToExpression = (0, bidirectional_adapter_1.createMultiAdapter)((markup, { entitiesMapByID, variablesMapByID } = { entitiesMapByID: {}, variablesMapByID: {} }) => markup.reduce((acc, item) => acc +
|
158
|
-
(0, ts_pattern_1.match)(item)
|
159
|
-
.when(exports.isMarkupSpan, ({ text }) => exports.markupToExpression.fromDB(text, { entitiesMapByID, variablesMapByID }))
|
160
|
-
.when(exports.isMarkupString, (item) => item)
|
161
|
-
.when(exports.isMarkupEntity, ({ entityID }) => `{{[${entitiesMapByID[entityID]?.name ?? entityID}].${entityID}}}`)
|
162
|
-
.when(exports.isMarkupVariable, ({ variableID }) => `{{[${variablesMapByID[variableID]?.name ?? variableID}].${variableID}}}`)
|
163
|
-
.exhaustive(), ''), (text, { entitiesMapByID, variablesMapByID }) => {
|
164
|
-
const matches = [...text.matchAll(exports.EXPRESSION_VARIABLE_TEXT_REGEXP)];
|
165
|
-
if (!matches.length)
|
166
|
-
return [{ text: [text] }];
|
167
|
-
const span = {
|
168
|
-
text: [],
|
169
|
-
};
|
170
|
-
let prevMatch = null;
|
171
|
-
for (const match of matches) {
|
172
|
-
const entity = entitiesMapByID[match[2]];
|
173
|
-
const variable = variablesMapByID[match[2]];
|
174
|
-
let substring;
|
175
|
-
if (!prevMatch) {
|
176
|
-
substring = text.substring(0, match.index);
|
177
|
-
}
|
178
|
-
else {
|
179
|
-
substring = text.substring(prevMatch.index + prevMatch[0].length, match.index);
|
180
|
-
}
|
181
|
-
if (substring) {
|
182
|
-
span.text.push(substring);
|
183
|
-
}
|
184
|
-
if (entity) {
|
185
|
-
span.text.push({ entityID: entity.id });
|
186
|
-
}
|
187
|
-
else if (variable) {
|
188
|
-
span.text.push({ variableID: variable.id });
|
189
|
-
}
|
190
|
-
else {
|
191
|
-
span.text.push(match[0]);
|
192
|
-
}
|
193
|
-
prevMatch = match;
|
194
|
-
}
|
195
|
-
if (!prevMatch) {
|
196
|
-
return [span];
|
197
|
-
}
|
198
|
-
const substring = text.substring(prevMatch.index + prevMatch[0].length, text.length);
|
199
|
-
if (substring) {
|
200
|
-
span.text.push(substring);
|
201
|
-
}
|
202
|
-
return [span];
|
203
|
-
});
|
204
149
|
const isEmptyState = (nodes) => nodes.every((element) => slate_1.Text.isText(element) ? !element.text.trim() : element.type !== 'variable' && isEmptyState(element.children));
|
205
150
|
exports.markupToSlate = (0, bidirectional_adapter_1.createMultiAdapter)((markup, { iteration = 0, entitiesMapByID, variablesMapByID }) => {
|
206
151
|
if (!markup?.length)
|
@@ -2,8 +2,6 @@ import { BaseText } from '@voiceflow/base-types';
|
|
2
2
|
import type { Entity, Markup, MarkupSpan, Variable } from '@voiceflow/dtos';
|
3
3
|
import type { MultiAdapter } from 'bidirectional-adapter';
|
4
4
|
export type MarkupItem = Markup[number];
|
5
|
-
export declare const ENTITY_OR_VARIABLE_TEXT_REGEXP: RegExp;
|
6
|
-
export declare const EXPRESSION_VARIABLE_TEXT_REGEXP: RegExp;
|
7
5
|
export interface MarkupSpanText extends Omit<MarkupSpan, 'text'> {
|
8
6
|
text: [string];
|
9
7
|
attributes: {
|
@@ -53,15 +51,6 @@ export declare const replaceMarkupEntity: (markup: Markup, { oldEntityID, newEnt
|
|
53
51
|
}) => Markup;
|
54
52
|
export declare const fillMarkupWithVariablesValues: (promptText: string, variables: Record<string, string>) => string;
|
55
53
|
export declare const markupToString: MultiAdapter<Markup, string, [MarkupToStringFromOptions], [MarkupToStringToOptions]>;
|
56
|
-
interface MarkupToExpressionOptions {
|
57
|
-
entitiesMapByID: Partial<Record<string, Entity>>;
|
58
|
-
variablesMapByID: Partial<Record<string, Variable>>;
|
59
|
-
}
|
60
|
-
export declare const markupToExpression: MultiAdapter<Markup, string, [
|
61
|
-
MarkupToExpressionOptions
|
62
|
-
], [
|
63
|
-
MarkupToExpressionOptions
|
64
|
-
]>;
|
65
54
|
export declare const markupToSlate: MultiAdapter<Markup, BaseText.SlateTextValue, [{
|
66
55
|
iteration?: number | undefined;
|
67
56
|
entitiesMapByID: Partial<Record<string, Entity>>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"markup.util.d.ts","sourceRoot":"","sources":["../../src/markup.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAK1D,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;
|
1
|
+
{"version":3,"file":"markup.util.d.ts","sourceRoot":"","sources":["../../src/markup.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,M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QAAQ,CAAC,CAAC,CAAC;IACpD,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,UAAU,uBAAuB;IAC/B,iBAAiB,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,kBAAkB,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;CACvD;AAiBD,eAAO,MAAM,kBAAkB,8BAAwE,CAAC;AAiBxG,eAAO,MAAM,oBAAoB,8BAA0E,CAAC;AAE5G,eAAO,MAAM,mBAAmB,iDAEA;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,WAW3E,CAAC;AAEF,eAAO,MAAM,6BAA6B,eAAgB,MAAM,aAAa,OAAO,MAAM,EAAE,MAAM,CAAC,WACmB,CAAC;AAEvH,eAAO,MAAM,cAAc,EAAE,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,yBAAyB,CAAC,EAAE,CAAC,uBAAuB,CAAC,CA+E7G,CAAC;AAOJ,eAAO,MAAM,aAAa;;qBAMH,QAAQ,OAAO,MAAM,EAAE,MAAM,CAAC,CAAC;sBAC9B,QAAQ,OAAO,MAAM,EAAE,QAAQ,CAAC,CAAC;OA2HxD,CAAC"}
|
package/build/esm/markup.util.js
CHANGED
@@ -3,8 +3,7 @@ import { Utils } from '@voiceflow/common';
|
|
3
3
|
import { createMultiAdapter } from 'bidirectional-adapter';
|
4
4
|
import { Text } from 'slate';
|
5
5
|
import { match } from 'ts-pattern';
|
6
|
-
|
7
|
-
export const EXPRESSION_VARIABLE_TEXT_REGEXP = /{{\[(\w*)]\.(\w*)}}/g;
|
6
|
+
const ENTITY_OR_VARIABLE_TEXT_REGEXP = /{(\w*)}/g;
|
8
7
|
export const isMarkupVariableReference = (markupItem) => {
|
9
8
|
return markupItem.variableID !== undefined;
|
10
9
|
};
|
@@ -71,14 +70,7 @@ export const replaceMarkupEntity = (markup, { oldEntityID, newEntityID }) => {
|
|
71
70
|
return [...acc, item];
|
72
71
|
}, []);
|
73
72
|
};
|
74
|
-
export const fillMarkupWithVariablesValues = (promptText, variables) => {
|
75
|
-
let s = promptText;
|
76
|
-
// eslint-disable-next-line guard-for-in
|
77
|
-
for (const prop in variables) {
|
78
|
-
s = s.replace(new RegExp(`{${prop}}`, 'g'), variables[prop]);
|
79
|
-
}
|
80
|
-
return s;
|
81
|
-
};
|
73
|
+
export const fillMarkupWithVariablesValues = (promptText, variables) => Object.keys(variables).reduce((acc, prop) => acc.replace(new RegExp(`{${prop}}`, 'g'), variables[prop]), promptText);
|
82
74
|
export const markupToString = createMultiAdapter((markup, { entitiesMapByID, variablesMapByID, ignoreMissingEntities, ignoreMissingVariables } = {
|
83
75
|
entitiesMapByID: {},
|
84
76
|
variablesMapByID: {},
|
@@ -136,53 +128,6 @@ export const markupToString = createMultiAdapter((markup, { entitiesMapByID, var
|
|
136
128
|
}
|
137
129
|
return [span];
|
138
130
|
});
|
139
|
-
export const markupToExpression = createMultiAdapter((markup, { entitiesMapByID, variablesMapByID } = { entitiesMapByID: {}, variablesMapByID: {} }) => markup.reduce((acc, item) => acc +
|
140
|
-
match(item)
|
141
|
-
.when(isMarkupSpan, ({ text }) => markupToExpression.fromDB(text, { entitiesMapByID, variablesMapByID }))
|
142
|
-
.when(isMarkupString, (item) => item)
|
143
|
-
.when(isMarkupEntity, ({ entityID }) => `{{[${entitiesMapByID[entityID]?.name ?? entityID}].${entityID}}}`)
|
144
|
-
.when(isMarkupVariable, ({ variableID }) => `{{[${variablesMapByID[variableID]?.name ?? variableID}].${variableID}}}`)
|
145
|
-
.exhaustive(), ''), (text, { entitiesMapByID, variablesMapByID }) => {
|
146
|
-
const matches = [...text.matchAll(EXPRESSION_VARIABLE_TEXT_REGEXP)];
|
147
|
-
if (!matches.length)
|
148
|
-
return [{ text: [text] }];
|
149
|
-
const span = {
|
150
|
-
text: [],
|
151
|
-
};
|
152
|
-
let prevMatch = null;
|
153
|
-
for (const match of matches) {
|
154
|
-
const entity = entitiesMapByID[match[2]];
|
155
|
-
const variable = variablesMapByID[match[2]];
|
156
|
-
let substring;
|
157
|
-
if (!prevMatch) {
|
158
|
-
substring = text.substring(0, match.index);
|
159
|
-
}
|
160
|
-
else {
|
161
|
-
substring = text.substring(prevMatch.index + prevMatch[0].length, match.index);
|
162
|
-
}
|
163
|
-
if (substring) {
|
164
|
-
span.text.push(substring);
|
165
|
-
}
|
166
|
-
if (entity) {
|
167
|
-
span.text.push({ entityID: entity.id });
|
168
|
-
}
|
169
|
-
else if (variable) {
|
170
|
-
span.text.push({ variableID: variable.id });
|
171
|
-
}
|
172
|
-
else {
|
173
|
-
span.text.push(match[0]);
|
174
|
-
}
|
175
|
-
prevMatch = match;
|
176
|
-
}
|
177
|
-
if (!prevMatch) {
|
178
|
-
return [span];
|
179
|
-
}
|
180
|
-
const substring = text.substring(prevMatch.index + prevMatch[0].length, text.length);
|
181
|
-
if (substring) {
|
182
|
-
span.text.push(substring);
|
183
|
-
}
|
184
|
-
return [span];
|
185
|
-
});
|
186
131
|
const isEmptyState = (nodes) => nodes.every((element) => Text.isText(element) ? !element.text.trim() : element.type !== 'variable' && isEmptyState(element.children));
|
187
132
|
export const markupToSlate = createMultiAdapter((markup, { iteration = 0, entitiesMapByID, variablesMapByID }) => {
|
188
133
|
if (!markup?.length)
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@voiceflow/utils-designer",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.26.0",
|
4
4
|
"exports": {
|
5
5
|
".": {
|
6
6
|
"types": "./build/cjs/main.d.ts",
|
@@ -31,7 +31,7 @@
|
|
31
31
|
},
|
32
32
|
"dependencies": {
|
33
33
|
"@voiceflow/common": "8.3.0",
|
34
|
-
"@voiceflow/dtos": "1.
|
34
|
+
"@voiceflow/dtos": "1.121.0",
|
35
35
|
"bidirectional-adapter": "1.2.1",
|
36
36
|
"slate": "^0.103.0",
|
37
37
|
"ts-pattern": "5.0.5",
|
@@ -43,5 +43,5 @@
|
|
43
43
|
"volta": {
|
44
44
|
"extends": "../../package.json"
|
45
45
|
},
|
46
|
-
"gitHead": "
|
46
|
+
"gitHead": "f07dc306a5c5598361627243d1bb27274f1827da"
|
47
47
|
}
|