@voiceflow/utils-designer 1.1.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/README.md +9 -0
- package/build/cjs/entity.util.d.ts +4 -0
- package/build/cjs/entity.util.d.ts.map +1 -0
- package/build/cjs/entity.util.js +7 -0
- package/build/cjs/intent.util.d.ts +2 -0
- package/build/cjs/intent.util.d.ts.map +1 -0
- package/build/cjs/intent.util.js +5 -0
- package/build/cjs/main.d.ts +4 -0
- package/build/cjs/main.d.ts.map +1 -0
- package/build/cjs/main.js +19 -0
- package/build/cjs/markup.util.d.ts +58 -0
- package/build/cjs/markup.util.d.ts.map +1 -0
- package/build/cjs/markup.util.js +235 -0
- package/build/cjs/package.json +1 -0
- package/build/esm/entity.util.d.ts +4 -0
- package/build/esm/entity.util.d.ts.map +1 -0
- package/build/esm/entity.util.js +2 -0
- package/build/esm/intent.util.d.ts +2 -0
- package/build/esm/intent.util.d.ts.map +1 -0
- package/build/esm/intent.util.js +1 -0
- package/build/esm/main.d.ts +4 -0
- package/build/esm/main.d.ts.map +1 -0
- package/build/esm/main.js +3 -0
- package/build/esm/markup.util.d.ts +58 -0
- package/build/esm/markup.util.d.ts.map +1 -0
- package/build/esm/markup.util.js +217 -0
- package/build/esm/package.json +1 -0
- package/package.json +54 -0
package/README.md
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
import type { EntityVariant } from '@voiceflow/dtos';
|
2
|
+
export declare const isDefaultEntityName: (name?: string | null) => boolean;
|
3
|
+
export declare const isEntityVariantLikeEmpty: ({ value, synonyms }: Pick<EntityVariant, 'value' | 'synonyms'>) => boolean;
|
4
|
+
//# sourceMappingURL=entity.util.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"entity.util.d.ts","sourceRoot":"","sources":["../../src/entity.util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,eAAO,MAAM,mBAAmB,UAAW,MAAM,GAAG,IAAI,YAAqD,CAAC;AAE9G,eAAO,MAAM,wBAAwB,wBAAyB,KAAK,aAAa,EAAE,OAAO,GAAG,UAAU,CAAC,YACxC,CAAC"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isEntityVariantLikeEmpty = exports.isDefaultEntityName = void 0;
|
4
|
+
const isDefaultEntityName = (name) => !name || name.toLowerCase().startsWith('entity');
|
5
|
+
exports.isDefaultEntityName = isDefaultEntityName;
|
6
|
+
const isEntityVariantLikeEmpty = ({ value, synonyms }) => !value.trim() && synonyms.every((synonym) => !synonym.trim());
|
7
|
+
exports.isEntityVariantLikeEmpty = isEntityVariantLikeEmpty;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"intent.util.d.ts","sourceRoot":"","sources":["../../src/intent.util.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,UAAW,MAAM,GAAG,IAAI,YAAqD,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./entity.util"), exports);
|
18
|
+
__exportStar(require("./intent.util"), exports);
|
19
|
+
__exportStar(require("./markup.util"), exports);
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import type { Entity, Markup, MarkupSpan, Variable } from '@voiceflow/dtos';
|
2
|
+
import type { MultiAdapter } from 'bidirectional-adapter';
|
3
|
+
import type { Descendant } from 'slate';
|
4
|
+
type MarkupItem = Markup[number];
|
5
|
+
interface MarkupSpanText extends Omit<MarkupSpan, 'text'> {
|
6
|
+
text: [string];
|
7
|
+
attributes: {
|
8
|
+
__type: 'text';
|
9
|
+
};
|
10
|
+
}
|
11
|
+
interface MarkupSpanLink extends MarkupSpan {
|
12
|
+
attributes: {
|
13
|
+
__type: 'link';
|
14
|
+
url: string;
|
15
|
+
};
|
16
|
+
}
|
17
|
+
export declare const isMarkupVariableReference: (markupItem: Markup[number]) => markupItem is {
|
18
|
+
variableID: string;
|
19
|
+
};
|
20
|
+
export declare const isMarkupEntityReference: (markupItem: Markup[number]) => markupItem is {
|
21
|
+
entityID: string;
|
22
|
+
};
|
23
|
+
export declare const markupFactory: (text?: string) => Markup;
|
24
|
+
export declare const isMarkupSpan: (value: MarkupItem) => value is MarkupSpan;
|
25
|
+
export declare const isMarkupSpanText: (value: MarkupSpan) => value is MarkupSpanText;
|
26
|
+
export declare const isMarkupSpanLink: (value: MarkupSpan) => value is MarkupSpanLink;
|
27
|
+
export declare const isMarkupEntity: (value: MarkupItem) => value is {
|
28
|
+
entityID: string;
|
29
|
+
};
|
30
|
+
export declare const isMarkupString: (value: MarkupItem) => value is string;
|
31
|
+
export declare const isMarkupVariable: (value: MarkupItem) => value is {
|
32
|
+
variableID: string;
|
33
|
+
};
|
34
|
+
export declare const isMarkupEmpty: (markup: Markup) => boolean;
|
35
|
+
export declare const isMarkupWithEntities: (markup: Markup) => boolean;
|
36
|
+
interface MarkupToStringFromOptions {
|
37
|
+
entitiesMapByID: Partial<Record<string, Entity>>;
|
38
|
+
variablesMapByID: Partial<Record<string, Variable>>;
|
39
|
+
ignoreMissingEntities?: boolean;
|
40
|
+
ignoreMissingVariables?: boolean;
|
41
|
+
}
|
42
|
+
interface MarkupToStringToOptions {
|
43
|
+
entitiesMapByName: Partial<Record<string, Entity>>;
|
44
|
+
variablesMapByName: Partial<Record<string, Variable>>;
|
45
|
+
}
|
46
|
+
export declare const getMarkupEntityIDs: (markup: Markup) => string[];
|
47
|
+
export declare const getMarkupVariableIDs: (markup: Markup) => string[];
|
48
|
+
export declare const replaceMarkupEntity: (markup: Markup, { oldEntityID, newEntityID }: {
|
49
|
+
oldEntityID: string;
|
50
|
+
newEntityID: string;
|
51
|
+
}) => Markup;
|
52
|
+
export declare const fillMarkupWithVariablesValues: (promptText: string, variables: Record<string, string>) => string;
|
53
|
+
export declare const markupToString: MultiAdapter<Markup, string, [MarkupToStringFromOptions], [MarkupToStringToOptions]>;
|
54
|
+
export declare const markupToSlate: MultiAdapter<Markup, Descendant[], [] | [{
|
55
|
+
iteration?: number | undefined;
|
56
|
+
}], []>;
|
57
|
+
export {};
|
58
|
+
//# sourceMappingURL=markup.util.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"markup.util.d.ts","sourceRoot":"","sources":["../../src/markup.util.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAIxC,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAIjC,UAAU,cAAe,SAAQ,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC;IACvD,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC;IACf,UAAU,EAAE;QACV,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,UAAU,cAAe,SAAQ,UAAU;IACzC,UAAU,EAAE;QACV,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH;AAED,eAAO,MAAM,yBAAyB,eAAgB,MAAM,CAAC,MAAM,CAAC;gBAA+B,MAAM;CAExG,CAAC;AAEF,eAAO,MAAM,uBAAuB,eAAgB,MAAM,CAAC,MAAM,CAAC;cAA6B,MAAM;CAEpG,CAAC;AAEF,eAAO,MAAM,aAAa,2BAA4C,CAAC;AAEvE,eAAO,MAAM,YAAY,UAAW,UAAU,wBAC2B,CAAC;AAE1E,eAAO,MAAM,gBAAgB,UAAW,UAAU,4BAIf,CAAC;AAEpC,eAAO,MAAM,gBAAgB,UAAW,UAAU,4BACa,CAAC;AAEhE,eAAO,MAAM,cAAc,UAAW,UAAU;cAAwB,MAAM;CACD,CAAC;AAE9E,eAAO,MAAM,cAAc,UAAW,UAAU,oBAA+C,CAAC;AAEhG,eAAO,MAAM,gBAAgB,UAAW,UAAU;gBAA0B,MAAM;CACH,CAAC;AAEhF,eAAO,MAAM,aAAa,sBAAqB,OAI5C,CAAC;AAEJ,eAAO,MAAM,oBAAoB,sBAAqB,OAYrD,CAAC;AAEF,UAAU,yBAAyB;IACjC,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACjD,gBAAgB,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,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;iBAEe,MAAM;iBAAe,MAAM;YAWzE,CAAC;AAEF,eAAO,MAAM,6BAA6B,eAAgB,MAAM,aAAa,OAAO,MAAM,EAAE,MAAM,CAAC,WAOlG,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,yBAAyB,CAAC,EAAE,CAAC,uBAAuB,CAAC,CA8E7G,CAAC;AAEJ,eAAO,MAAM,aAAa;;OAkHzB,CAAC"}
|
@@ -0,0 +1,235 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
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
|
+
const common_1 = require("@voiceflow/common");
|
5
|
+
const ui_next_1 = require("@voiceflow/ui-next");
|
6
|
+
const bidirectional_adapter_1 = require("bidirectional-adapter");
|
7
|
+
const slate_1 = require("slate");
|
8
|
+
const ts_pattern_1 = require("ts-pattern");
|
9
|
+
const ENTITY_OR_VARIABLE_TEXT_REGEXP = /{(\w*)}/g;
|
10
|
+
const isMarkupVariableReference = (markupItem) => {
|
11
|
+
return markupItem.variableID !== undefined;
|
12
|
+
};
|
13
|
+
exports.isMarkupVariableReference = isMarkupVariableReference;
|
14
|
+
const isMarkupEntityReference = (markupItem) => {
|
15
|
+
return markupItem.entityID !== undefined;
|
16
|
+
};
|
17
|
+
exports.isMarkupEntityReference = isMarkupEntityReference;
|
18
|
+
const markupFactory = (text = '') => [{ text: [text] }];
|
19
|
+
exports.markupFactory = markupFactory;
|
20
|
+
const isMarkupSpan = (value) => common_1.Utils.object.isObject(value) && common_1.Utils.object.hasProperty(value, 'text');
|
21
|
+
exports.isMarkupSpan = isMarkupSpan;
|
22
|
+
const isMarkupSpanText = (value) => value.attributes?.__type === 'text' &&
|
23
|
+
Array.isArray(value.text) &&
|
24
|
+
value.text.length === 1 &&
|
25
|
+
typeof value.text[0] === 'string';
|
26
|
+
exports.isMarkupSpanText = isMarkupSpanText;
|
27
|
+
const isMarkupSpanLink = (value) => value.attributes?.__type === 'link' && !!value.attributes.url;
|
28
|
+
exports.isMarkupSpanLink = isMarkupSpanLink;
|
29
|
+
const isMarkupEntity = (value) => common_1.Utils.object.isObject(value) && common_1.Utils.object.hasProperty(value, 'entityID');
|
30
|
+
exports.isMarkupEntity = isMarkupEntity;
|
31
|
+
const isMarkupString = (value) => typeof value === 'string';
|
32
|
+
exports.isMarkupString = isMarkupString;
|
33
|
+
const isMarkupVariable = (value) => common_1.Utils.object.isObject(value) && common_1.Utils.object.hasProperty(value, 'variableID');
|
34
|
+
exports.isMarkupVariable = isMarkupVariable;
|
35
|
+
const isMarkupEmpty = (markup) => !markup.length ||
|
36
|
+
markup.every((text) => (0, exports.isMarkupString)(text) ? !text.trim() : !(0, exports.isMarkupEntity)(text) && !(0, exports.isMarkupVariable)(text) && (0, exports.isMarkupEmpty)(text.text));
|
37
|
+
exports.isMarkupEmpty = isMarkupEmpty;
|
38
|
+
const isMarkupWithEntities = (markup) => {
|
39
|
+
return markup.some((item) => {
|
40
|
+
if ((0, exports.isMarkupSpan)(item)) {
|
41
|
+
return (0, exports.isMarkupWithEntities)(item.text);
|
42
|
+
}
|
43
|
+
if (Array.isArray(item)) {
|
44
|
+
return (0, exports.isMarkupWithEntities)(item);
|
45
|
+
}
|
46
|
+
return (0, exports.isMarkupEntity)(item);
|
47
|
+
});
|
48
|
+
};
|
49
|
+
exports.isMarkupWithEntities = isMarkupWithEntities;
|
50
|
+
const getMarkupAllEntityIDs = (markup) => markup.reduce((acc, item) => {
|
51
|
+
if ((0, exports.isMarkupSpan)(item)) {
|
52
|
+
return [...acc, ...getMarkupAllEntityIDs(item.text)];
|
53
|
+
}
|
54
|
+
if (Array.isArray(item)) {
|
55
|
+
return [...acc, ...getMarkupAllEntityIDs(item)];
|
56
|
+
}
|
57
|
+
if ((0, exports.isMarkupEntity)(item)) {
|
58
|
+
return [...acc, item.entityID];
|
59
|
+
}
|
60
|
+
return acc;
|
61
|
+
}, []);
|
62
|
+
const getMarkupEntityIDs = (markup) => common_1.Utils.array.unique(getMarkupAllEntityIDs(markup));
|
63
|
+
exports.getMarkupEntityIDs = getMarkupEntityIDs;
|
64
|
+
const getMarkupAllVariableIDs = (markup) => markup.reduce((acc, item) => {
|
65
|
+
if ((0, exports.isMarkupSpan)(item)) {
|
66
|
+
return [...acc, ...getMarkupAllVariableIDs(item.text)];
|
67
|
+
}
|
68
|
+
if (Array.isArray(item)) {
|
69
|
+
return [...acc, ...getMarkupAllVariableIDs(item)];
|
70
|
+
}
|
71
|
+
if ((0, exports.isMarkupVariable)(item)) {
|
72
|
+
return [...acc, item.variableID];
|
73
|
+
}
|
74
|
+
return acc;
|
75
|
+
}, []);
|
76
|
+
const getMarkupVariableIDs = (markup) => common_1.Utils.array.unique(getMarkupAllVariableIDs(markup));
|
77
|
+
exports.getMarkupVariableIDs = getMarkupVariableIDs;
|
78
|
+
const replaceMarkupEntity = (markup, { oldEntityID, newEntityID }) => {
|
79
|
+
return markup.reduce((acc, item) => {
|
80
|
+
if ((0, exports.isMarkupEntity)(item) && item.entityID === oldEntityID) {
|
81
|
+
return [...acc, { entityID: newEntityID }];
|
82
|
+
}
|
83
|
+
if ((0, exports.isMarkupSpan)(item)) {
|
84
|
+
return [...acc, { ...item, text: (0, exports.replaceMarkupEntity)(item.text, { oldEntityID, newEntityID }) }];
|
85
|
+
}
|
86
|
+
return [...acc, item];
|
87
|
+
}, []);
|
88
|
+
};
|
89
|
+
exports.replaceMarkupEntity = replaceMarkupEntity;
|
90
|
+
const fillMarkupWithVariablesValues = (promptText, variables) => {
|
91
|
+
let s = promptText;
|
92
|
+
// eslint-disable-next-line guard-for-in
|
93
|
+
for (const prop in variables) {
|
94
|
+
s = s.replace(new RegExp(`{${prop}}`, 'g'), variables[prop]);
|
95
|
+
}
|
96
|
+
return s;
|
97
|
+
};
|
98
|
+
exports.fillMarkupWithVariablesValues = fillMarkupWithVariablesValues;
|
99
|
+
exports.markupToString = (0, bidirectional_adapter_1.createMultiAdapter)((markup, { entitiesMapByID, variablesMapByID, ignoreMissingEntities, ignoreMissingVariables } = {
|
100
|
+
entitiesMapByID: {},
|
101
|
+
variablesMapByID: {},
|
102
|
+
}) => markup.reduce((acc, item) => acc +
|
103
|
+
(0, ts_pattern_1.match)(item)
|
104
|
+
.when(exports.isMarkupSpan, ({ text }) => exports.markupToString.fromDB(text, { entitiesMapByID, variablesMapByID }))
|
105
|
+
.when(exports.isMarkupString, (item) => item)
|
106
|
+
.when(exports.isMarkupEntity, ({ entityID }) => !entitiesMapByID[entityID] && ignoreMissingEntities
|
107
|
+
? ''
|
108
|
+
: `{${entitiesMapByID[entityID]?.name ?? entityID}}`)
|
109
|
+
.when(exports.isMarkupVariable, ({ variableID }) => !variablesMapByID[variableID] && ignoreMissingVariables
|
110
|
+
? ''
|
111
|
+
: `{${variablesMapByID[variableID]?.name ?? variableID}}`)
|
112
|
+
.exhaustive(), ''), (text, { entitiesMapByName, variablesMapByName }) => {
|
113
|
+
const matches = [...text.matchAll(ENTITY_OR_VARIABLE_TEXT_REGEXP)];
|
114
|
+
if (!matches.length)
|
115
|
+
return [{ text: [text] }];
|
116
|
+
const span = {
|
117
|
+
text: [],
|
118
|
+
};
|
119
|
+
let prevMatch = null;
|
120
|
+
for (const match of matches) {
|
121
|
+
const entity = entitiesMapByName[match[1]];
|
122
|
+
const variable = variablesMapByName[match[1]];
|
123
|
+
let substring;
|
124
|
+
if (!prevMatch) {
|
125
|
+
substring = text.substring(0, match.index);
|
126
|
+
}
|
127
|
+
else {
|
128
|
+
substring = text.substring(prevMatch.index + prevMatch[0].length, match.index);
|
129
|
+
}
|
130
|
+
if (substring) {
|
131
|
+
span.text.push(substring);
|
132
|
+
}
|
133
|
+
if (entity) {
|
134
|
+
span.text.push({ entityID: entity.id });
|
135
|
+
}
|
136
|
+
else if (variable) {
|
137
|
+
span.text.push({ variableID: variable.id });
|
138
|
+
}
|
139
|
+
else {
|
140
|
+
span.text.push(match[0]);
|
141
|
+
}
|
142
|
+
prevMatch = match;
|
143
|
+
}
|
144
|
+
if (!prevMatch) {
|
145
|
+
return [span];
|
146
|
+
}
|
147
|
+
const substring = text.substring(prevMatch.index + prevMatch[0].length, text.length);
|
148
|
+
if (substring) {
|
149
|
+
span.text.push(substring);
|
150
|
+
}
|
151
|
+
return [span];
|
152
|
+
});
|
153
|
+
exports.markupToSlate = (0, bidirectional_adapter_1.createMultiAdapter)((markup, { iteration = 0 } = {}) => {
|
154
|
+
if (!markup.length)
|
155
|
+
return iteration === 0 ? ui_next_1.SlateEditor.StaticEditor.createTextState('') : [{ text: '' }];
|
156
|
+
if (markup.length === 1 && typeof markup[0] === 'string')
|
157
|
+
return iteration === 0 ? ui_next_1.SlateEditor.StaticEditor.createTextState(markup[0]) : [{ text: markup[0] }];
|
158
|
+
return markup.reduce((acc, item) => [
|
159
|
+
...acc,
|
160
|
+
(0, ts_pattern_1.match)(item)
|
161
|
+
.when(exports.isMarkupString, (item) => ({ text: item }))
|
162
|
+
.when(exports.isMarkupEntity, ({ entityID }) => ({
|
163
|
+
type: ui_next_1.SlateEditor.ElementType.VARIABLE,
|
164
|
+
children: [{ text: '' }],
|
165
|
+
variableID: entityID,
|
166
|
+
variableVariant: ui_next_1.SlateEditor.VariableElementVariant.ENTITY,
|
167
|
+
}))
|
168
|
+
.when(exports.isMarkupVariable, ({ variableID }) => ({
|
169
|
+
type: ui_next_1.SlateEditor.ElementType.VARIABLE,
|
170
|
+
children: [{ text: '' }],
|
171
|
+
variableID,
|
172
|
+
variableVariant: ui_next_1.SlateEditor.VariableElementVariant.VARIABLE,
|
173
|
+
}))
|
174
|
+
.when(exports.isMarkupSpan, (span) => (0, ts_pattern_1.match)(span)
|
175
|
+
.when(exports.isMarkupSpanText, ({ text: [text], attributes: { __type, ...attrs } }) => ({ ...attrs, text }))
|
176
|
+
.when(exports.isMarkupSpanLink, ({ text, attributes: { url } }) => ({
|
177
|
+
url,
|
178
|
+
type: ui_next_1.SlateEditor.ElementType.LINK,
|
179
|
+
children: exports.markupToSlate.fromDB(text, { iteration: iteration + 1 }),
|
180
|
+
}))
|
181
|
+
.otherwise(({ text, attributes: { __type, ...attrs } = {} }) => ({
|
182
|
+
...attrs,
|
183
|
+
children: exports.markupToSlate.fromDB(text, { iteration: iteration + 1 }),
|
184
|
+
})))
|
185
|
+
.exhaustive(),
|
186
|
+
], []);
|
187
|
+
},
|
188
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
189
|
+
(slate) => {
|
190
|
+
if (ui_next_1.SlateEditor.StaticEditor.isEmptyState(slate))
|
191
|
+
return (0, exports.markupFactory)();
|
192
|
+
return slate.reduce((acc, item) => [
|
193
|
+
...acc,
|
194
|
+
(0, ts_pattern_1.match)(item)
|
195
|
+
.when(ui_next_1.SlateEditor.StaticEditor.isLink, (item) => {
|
196
|
+
const { url = '', children } = item;
|
197
|
+
return {
|
198
|
+
text: exports.markupToSlate.toDB(children),
|
199
|
+
attributes: { __type: 'link', url },
|
200
|
+
};
|
201
|
+
})
|
202
|
+
.when(ui_next_1.SlateEditor.StaticEditor.isVariable, (item) => {
|
203
|
+
const { variableID, variableVariant } = item;
|
204
|
+
return variableVariant === ui_next_1.SlateEditor.VariableElementVariant.VARIABLE
|
205
|
+
? { variableID }
|
206
|
+
: { entityID: variableID };
|
207
|
+
})
|
208
|
+
.when(slate_1.Text.isText, (item) => {
|
209
|
+
// TODO: fix any
|
210
|
+
const { text, color, italic, underline, fontWeight, fontFamily, strikeThrough, backgroundColor } = item;
|
211
|
+
if (!color && !italic && !underline && !fontWeight && !fontFamily && !strikeThrough && !backgroundColor) {
|
212
|
+
return text;
|
213
|
+
}
|
214
|
+
return {
|
215
|
+
text: [text],
|
216
|
+
attributes: {
|
217
|
+
__type: 'text',
|
218
|
+
...(color && { color }),
|
219
|
+
...(italic && { italic }),
|
220
|
+
...(underline && { underline }),
|
221
|
+
...(fontWeight && { fontWeight }),
|
222
|
+
...(fontFamily && { fontFamily }),
|
223
|
+
...(strikeThrough && { strikeThrough }),
|
224
|
+
...(backgroundColor && { backgroundColor }),
|
225
|
+
},
|
226
|
+
};
|
227
|
+
})
|
228
|
+
.otherwise(
|
229
|
+
// TODO: fix any
|
230
|
+
({ type: _, children, textAlign }) => ({
|
231
|
+
text: exports.markupToSlate.toDB(children),
|
232
|
+
...(textAlign && { attributes: { textAlign } }),
|
233
|
+
})),
|
234
|
+
], []);
|
235
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "type": "commonjs" }
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import type { EntityVariant } from '@voiceflow/dtos';
|
2
|
+
export declare const isDefaultEntityName: (name?: string | null) => boolean;
|
3
|
+
export declare const isEntityVariantLikeEmpty: ({ value, synonyms }: Pick<EntityVariant, 'value' | 'synonyms'>) => boolean;
|
4
|
+
//# sourceMappingURL=entity.util.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"entity.util.d.ts","sourceRoot":"","sources":["../../src/entity.util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,eAAO,MAAM,mBAAmB,UAAW,MAAM,GAAG,IAAI,YAAqD,CAAC;AAE9G,eAAO,MAAM,wBAAwB,wBAAyB,KAAK,aAAa,EAAE,OAAO,GAAG,UAAU,CAAC,YACxC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"intent.util.d.ts","sourceRoot":"","sources":["../../src/intent.util.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,UAAW,MAAM,GAAG,IAAI,YAAqD,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export const isDefaultIntentName = (name) => !name || name.toLowerCase().startsWith('intent');
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import type { Entity, Markup, MarkupSpan, Variable } from '@voiceflow/dtos';
|
2
|
+
import type { MultiAdapter } from 'bidirectional-adapter';
|
3
|
+
import type { Descendant } from 'slate';
|
4
|
+
type MarkupItem = Markup[number];
|
5
|
+
interface MarkupSpanText extends Omit<MarkupSpan, 'text'> {
|
6
|
+
text: [string];
|
7
|
+
attributes: {
|
8
|
+
__type: 'text';
|
9
|
+
};
|
10
|
+
}
|
11
|
+
interface MarkupSpanLink extends MarkupSpan {
|
12
|
+
attributes: {
|
13
|
+
__type: 'link';
|
14
|
+
url: string;
|
15
|
+
};
|
16
|
+
}
|
17
|
+
export declare const isMarkupVariableReference: (markupItem: Markup[number]) => markupItem is {
|
18
|
+
variableID: string;
|
19
|
+
};
|
20
|
+
export declare const isMarkupEntityReference: (markupItem: Markup[number]) => markupItem is {
|
21
|
+
entityID: string;
|
22
|
+
};
|
23
|
+
export declare const markupFactory: (text?: string) => Markup;
|
24
|
+
export declare const isMarkupSpan: (value: MarkupItem) => value is MarkupSpan;
|
25
|
+
export declare const isMarkupSpanText: (value: MarkupSpan) => value is MarkupSpanText;
|
26
|
+
export declare const isMarkupSpanLink: (value: MarkupSpan) => value is MarkupSpanLink;
|
27
|
+
export declare const isMarkupEntity: (value: MarkupItem) => value is {
|
28
|
+
entityID: string;
|
29
|
+
};
|
30
|
+
export declare const isMarkupString: (value: MarkupItem) => value is string;
|
31
|
+
export declare const isMarkupVariable: (value: MarkupItem) => value is {
|
32
|
+
variableID: string;
|
33
|
+
};
|
34
|
+
export declare const isMarkupEmpty: (markup: Markup) => boolean;
|
35
|
+
export declare const isMarkupWithEntities: (markup: Markup) => boolean;
|
36
|
+
interface MarkupToStringFromOptions {
|
37
|
+
entitiesMapByID: Partial<Record<string, Entity>>;
|
38
|
+
variablesMapByID: Partial<Record<string, Variable>>;
|
39
|
+
ignoreMissingEntities?: boolean;
|
40
|
+
ignoreMissingVariables?: boolean;
|
41
|
+
}
|
42
|
+
interface MarkupToStringToOptions {
|
43
|
+
entitiesMapByName: Partial<Record<string, Entity>>;
|
44
|
+
variablesMapByName: Partial<Record<string, Variable>>;
|
45
|
+
}
|
46
|
+
export declare const getMarkupEntityIDs: (markup: Markup) => string[];
|
47
|
+
export declare const getMarkupVariableIDs: (markup: Markup) => string[];
|
48
|
+
export declare const replaceMarkupEntity: (markup: Markup, { oldEntityID, newEntityID }: {
|
49
|
+
oldEntityID: string;
|
50
|
+
newEntityID: string;
|
51
|
+
}) => Markup;
|
52
|
+
export declare const fillMarkupWithVariablesValues: (promptText: string, variables: Record<string, string>) => string;
|
53
|
+
export declare const markupToString: MultiAdapter<Markup, string, [MarkupToStringFromOptions], [MarkupToStringToOptions]>;
|
54
|
+
export declare const markupToSlate: MultiAdapter<Markup, Descendant[], [] | [{
|
55
|
+
iteration?: number | undefined;
|
56
|
+
}], []>;
|
57
|
+
export {};
|
58
|
+
//# sourceMappingURL=markup.util.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"markup.util.d.ts","sourceRoot":"","sources":["../../src/markup.util.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAIxC,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AAIjC,UAAU,cAAe,SAAQ,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC;IACvD,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC;IACf,UAAU,EAAE;QACV,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,UAAU,cAAe,SAAQ,UAAU;IACzC,UAAU,EAAE;QACV,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH;AAED,eAAO,MAAM,yBAAyB,eAAgB,MAAM,CAAC,MAAM,CAAC;gBAA+B,MAAM;CAExG,CAAC;AAEF,eAAO,MAAM,uBAAuB,eAAgB,MAAM,CAAC,MAAM,CAAC;cAA6B,MAAM;CAEpG,CAAC;AAEF,eAAO,MAAM,aAAa,2BAA4C,CAAC;AAEvE,eAAO,MAAM,YAAY,UAAW,UAAU,wBAC2B,CAAC;AAE1E,eAAO,MAAM,gBAAgB,UAAW,UAAU,4BAIf,CAAC;AAEpC,eAAO,MAAM,gBAAgB,UAAW,UAAU,4BACa,CAAC;AAEhE,eAAO,MAAM,cAAc,UAAW,UAAU;cAAwB,MAAM;CACD,CAAC;AAE9E,eAAO,MAAM,cAAc,UAAW,UAAU,oBAA+C,CAAC;AAEhG,eAAO,MAAM,gBAAgB,UAAW,UAAU;gBAA0B,MAAM;CACH,CAAC;AAEhF,eAAO,MAAM,aAAa,sBAAqB,OAI5C,CAAC;AAEJ,eAAO,MAAM,oBAAoB,sBAAqB,OAYrD,CAAC;AAEF,UAAU,yBAAyB;IACjC,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACjD,gBAAgB,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,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;iBAEe,MAAM;iBAAe,MAAM;YAWzE,CAAC;AAEF,eAAO,MAAM,6BAA6B,eAAgB,MAAM,aAAa,OAAO,MAAM,EAAE,MAAM,CAAC,WAOlG,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,yBAAyB,CAAC,EAAE,CAAC,uBAAuB,CAAC,CA8E7G,CAAC;AAEJ,eAAO,MAAM,aAAa;;OAkHzB,CAAC"}
|
@@ -0,0 +1,217 @@
|
|
1
|
+
import { Utils } from '@voiceflow/common';
|
2
|
+
import { SlateEditor } from '@voiceflow/ui-next';
|
3
|
+
import { createMultiAdapter } from 'bidirectional-adapter';
|
4
|
+
import { Text } from 'slate';
|
5
|
+
import { match } from 'ts-pattern';
|
6
|
+
const ENTITY_OR_VARIABLE_TEXT_REGEXP = /{(\w*)}/g;
|
7
|
+
export const isMarkupVariableReference = (markupItem) => {
|
8
|
+
return markupItem.variableID !== undefined;
|
9
|
+
};
|
10
|
+
export const isMarkupEntityReference = (markupItem) => {
|
11
|
+
return markupItem.entityID !== undefined;
|
12
|
+
};
|
13
|
+
export const markupFactory = (text = '') => [{ text: [text] }];
|
14
|
+
export const isMarkupSpan = (value) => Utils.object.isObject(value) && Utils.object.hasProperty(value, 'text');
|
15
|
+
export const isMarkupSpanText = (value) => value.attributes?.__type === 'text' &&
|
16
|
+
Array.isArray(value.text) &&
|
17
|
+
value.text.length === 1 &&
|
18
|
+
typeof value.text[0] === 'string';
|
19
|
+
export const isMarkupSpanLink = (value) => value.attributes?.__type === 'link' && !!value.attributes.url;
|
20
|
+
export const isMarkupEntity = (value) => Utils.object.isObject(value) && Utils.object.hasProperty(value, 'entityID');
|
21
|
+
export const isMarkupString = (value) => typeof value === 'string';
|
22
|
+
export const isMarkupVariable = (value) => Utils.object.isObject(value) && Utils.object.hasProperty(value, 'variableID');
|
23
|
+
export const isMarkupEmpty = (markup) => !markup.length ||
|
24
|
+
markup.every((text) => isMarkupString(text) ? !text.trim() : !isMarkupEntity(text) && !isMarkupVariable(text) && isMarkupEmpty(text.text));
|
25
|
+
export const isMarkupWithEntities = (markup) => {
|
26
|
+
return markup.some((item) => {
|
27
|
+
if (isMarkupSpan(item)) {
|
28
|
+
return isMarkupWithEntities(item.text);
|
29
|
+
}
|
30
|
+
if (Array.isArray(item)) {
|
31
|
+
return isMarkupWithEntities(item);
|
32
|
+
}
|
33
|
+
return isMarkupEntity(item);
|
34
|
+
});
|
35
|
+
};
|
36
|
+
const getMarkupAllEntityIDs = (markup) => markup.reduce((acc, item) => {
|
37
|
+
if (isMarkupSpan(item)) {
|
38
|
+
return [...acc, ...getMarkupAllEntityIDs(item.text)];
|
39
|
+
}
|
40
|
+
if (Array.isArray(item)) {
|
41
|
+
return [...acc, ...getMarkupAllEntityIDs(item)];
|
42
|
+
}
|
43
|
+
if (isMarkupEntity(item)) {
|
44
|
+
return [...acc, item.entityID];
|
45
|
+
}
|
46
|
+
return acc;
|
47
|
+
}, []);
|
48
|
+
export const getMarkupEntityIDs = (markup) => Utils.array.unique(getMarkupAllEntityIDs(markup));
|
49
|
+
const getMarkupAllVariableIDs = (markup) => markup.reduce((acc, item) => {
|
50
|
+
if (isMarkupSpan(item)) {
|
51
|
+
return [...acc, ...getMarkupAllVariableIDs(item.text)];
|
52
|
+
}
|
53
|
+
if (Array.isArray(item)) {
|
54
|
+
return [...acc, ...getMarkupAllVariableIDs(item)];
|
55
|
+
}
|
56
|
+
if (isMarkupVariable(item)) {
|
57
|
+
return [...acc, item.variableID];
|
58
|
+
}
|
59
|
+
return acc;
|
60
|
+
}, []);
|
61
|
+
export const getMarkupVariableIDs = (markup) => Utils.array.unique(getMarkupAllVariableIDs(markup));
|
62
|
+
export const replaceMarkupEntity = (markup, { oldEntityID, newEntityID }) => {
|
63
|
+
return markup.reduce((acc, item) => {
|
64
|
+
if (isMarkupEntity(item) && item.entityID === oldEntityID) {
|
65
|
+
return [...acc, { entityID: newEntityID }];
|
66
|
+
}
|
67
|
+
if (isMarkupSpan(item)) {
|
68
|
+
return [...acc, { ...item, text: replaceMarkupEntity(item.text, { oldEntityID, newEntityID }) }];
|
69
|
+
}
|
70
|
+
return [...acc, item];
|
71
|
+
}, []);
|
72
|
+
};
|
73
|
+
export const fillMarkupWithVariablesValues = (promptText, variables) => {
|
74
|
+
let s = promptText;
|
75
|
+
// eslint-disable-next-line guard-for-in
|
76
|
+
for (const prop in variables) {
|
77
|
+
s = s.replace(new RegExp(`{${prop}}`, 'g'), variables[prop]);
|
78
|
+
}
|
79
|
+
return s;
|
80
|
+
};
|
81
|
+
export const markupToString = createMultiAdapter((markup, { entitiesMapByID, variablesMapByID, ignoreMissingEntities, ignoreMissingVariables } = {
|
82
|
+
entitiesMapByID: {},
|
83
|
+
variablesMapByID: {},
|
84
|
+
}) => markup.reduce((acc, item) => acc +
|
85
|
+
match(item)
|
86
|
+
.when(isMarkupSpan, ({ text }) => markupToString.fromDB(text, { entitiesMapByID, variablesMapByID }))
|
87
|
+
.when(isMarkupString, (item) => item)
|
88
|
+
.when(isMarkupEntity, ({ entityID }) => !entitiesMapByID[entityID] && ignoreMissingEntities
|
89
|
+
? ''
|
90
|
+
: `{${entitiesMapByID[entityID]?.name ?? entityID}}`)
|
91
|
+
.when(isMarkupVariable, ({ variableID }) => !variablesMapByID[variableID] && ignoreMissingVariables
|
92
|
+
? ''
|
93
|
+
: `{${variablesMapByID[variableID]?.name ?? variableID}}`)
|
94
|
+
.exhaustive(), ''), (text, { entitiesMapByName, variablesMapByName }) => {
|
95
|
+
const matches = [...text.matchAll(ENTITY_OR_VARIABLE_TEXT_REGEXP)];
|
96
|
+
if (!matches.length)
|
97
|
+
return [{ text: [text] }];
|
98
|
+
const span = {
|
99
|
+
text: [],
|
100
|
+
};
|
101
|
+
let prevMatch = null;
|
102
|
+
for (const match of matches) {
|
103
|
+
const entity = entitiesMapByName[match[1]];
|
104
|
+
const variable = variablesMapByName[match[1]];
|
105
|
+
let substring;
|
106
|
+
if (!prevMatch) {
|
107
|
+
substring = text.substring(0, match.index);
|
108
|
+
}
|
109
|
+
else {
|
110
|
+
substring = text.substring(prevMatch.index + prevMatch[0].length, match.index);
|
111
|
+
}
|
112
|
+
if (substring) {
|
113
|
+
span.text.push(substring);
|
114
|
+
}
|
115
|
+
if (entity) {
|
116
|
+
span.text.push({ entityID: entity.id });
|
117
|
+
}
|
118
|
+
else if (variable) {
|
119
|
+
span.text.push({ variableID: variable.id });
|
120
|
+
}
|
121
|
+
else {
|
122
|
+
span.text.push(match[0]);
|
123
|
+
}
|
124
|
+
prevMatch = match;
|
125
|
+
}
|
126
|
+
if (!prevMatch) {
|
127
|
+
return [span];
|
128
|
+
}
|
129
|
+
const substring = text.substring(prevMatch.index + prevMatch[0].length, text.length);
|
130
|
+
if (substring) {
|
131
|
+
span.text.push(substring);
|
132
|
+
}
|
133
|
+
return [span];
|
134
|
+
});
|
135
|
+
export const markupToSlate = createMultiAdapter((markup, { iteration = 0 } = {}) => {
|
136
|
+
if (!markup.length)
|
137
|
+
return iteration === 0 ? SlateEditor.StaticEditor.createTextState('') : [{ text: '' }];
|
138
|
+
if (markup.length === 1 && typeof markup[0] === 'string')
|
139
|
+
return iteration === 0 ? SlateEditor.StaticEditor.createTextState(markup[0]) : [{ text: markup[0] }];
|
140
|
+
return markup.reduce((acc, item) => [
|
141
|
+
...acc,
|
142
|
+
match(item)
|
143
|
+
.when(isMarkupString, (item) => ({ text: item }))
|
144
|
+
.when(isMarkupEntity, ({ entityID }) => ({
|
145
|
+
type: SlateEditor.ElementType.VARIABLE,
|
146
|
+
children: [{ text: '' }],
|
147
|
+
variableID: entityID,
|
148
|
+
variableVariant: SlateEditor.VariableElementVariant.ENTITY,
|
149
|
+
}))
|
150
|
+
.when(isMarkupVariable, ({ variableID }) => ({
|
151
|
+
type: SlateEditor.ElementType.VARIABLE,
|
152
|
+
children: [{ text: '' }],
|
153
|
+
variableID,
|
154
|
+
variableVariant: SlateEditor.VariableElementVariant.VARIABLE,
|
155
|
+
}))
|
156
|
+
.when(isMarkupSpan, (span) => match(span)
|
157
|
+
.when(isMarkupSpanText, ({ text: [text], attributes: { __type, ...attrs } }) => ({ ...attrs, text }))
|
158
|
+
.when(isMarkupSpanLink, ({ text, attributes: { url } }) => ({
|
159
|
+
url,
|
160
|
+
type: SlateEditor.ElementType.LINK,
|
161
|
+
children: markupToSlate.fromDB(text, { iteration: iteration + 1 }),
|
162
|
+
}))
|
163
|
+
.otherwise(({ text, attributes: { __type, ...attrs } = {} }) => ({
|
164
|
+
...attrs,
|
165
|
+
children: markupToSlate.fromDB(text, { iteration: iteration + 1 }),
|
166
|
+
})))
|
167
|
+
.exhaustive(),
|
168
|
+
], []);
|
169
|
+
},
|
170
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
171
|
+
(slate) => {
|
172
|
+
if (SlateEditor.StaticEditor.isEmptyState(slate))
|
173
|
+
return markupFactory();
|
174
|
+
return slate.reduce((acc, item) => [
|
175
|
+
...acc,
|
176
|
+
match(item)
|
177
|
+
.when(SlateEditor.StaticEditor.isLink, (item) => {
|
178
|
+
const { url = '', children } = item;
|
179
|
+
return {
|
180
|
+
text: markupToSlate.toDB(children),
|
181
|
+
attributes: { __type: 'link', url },
|
182
|
+
};
|
183
|
+
})
|
184
|
+
.when(SlateEditor.StaticEditor.isVariable, (item) => {
|
185
|
+
const { variableID, variableVariant } = item;
|
186
|
+
return variableVariant === SlateEditor.VariableElementVariant.VARIABLE
|
187
|
+
? { variableID }
|
188
|
+
: { entityID: variableID };
|
189
|
+
})
|
190
|
+
.when(Text.isText, (item) => {
|
191
|
+
// TODO: fix any
|
192
|
+
const { text, color, italic, underline, fontWeight, fontFamily, strikeThrough, backgroundColor } = item;
|
193
|
+
if (!color && !italic && !underline && !fontWeight && !fontFamily && !strikeThrough && !backgroundColor) {
|
194
|
+
return text;
|
195
|
+
}
|
196
|
+
return {
|
197
|
+
text: [text],
|
198
|
+
attributes: {
|
199
|
+
__type: 'text',
|
200
|
+
...(color && { color }),
|
201
|
+
...(italic && { italic }),
|
202
|
+
...(underline && { underline }),
|
203
|
+
...(fontWeight && { fontWeight }),
|
204
|
+
...(fontFamily && { fontFamily }),
|
205
|
+
...(strikeThrough && { strikeThrough }),
|
206
|
+
...(backgroundColor && { backgroundColor }),
|
207
|
+
},
|
208
|
+
};
|
209
|
+
})
|
210
|
+
.otherwise(
|
211
|
+
// TODO: fix any
|
212
|
+
({ type: _, children, textAlign }) => ({
|
213
|
+
text: markupToSlate.toDB(children),
|
214
|
+
...(textAlign && { attributes: { textAlign } }),
|
215
|
+
})),
|
216
|
+
], []);
|
217
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "type": "module" }
|
package/package.json
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
{
|
2
|
+
"name": "@voiceflow/utils-designer",
|
3
|
+
"version": "1.1.0",
|
4
|
+
"exports": {
|
5
|
+
".": {
|
6
|
+
"types": "./build/cjs/main.d.ts",
|
7
|
+
"import": "./build/esm/main.js",
|
8
|
+
"default": "./build/cjs/main.js"
|
9
|
+
}
|
10
|
+
},
|
11
|
+
"main": "build/cjs/main.js",
|
12
|
+
"module": "build/esm/main.js",
|
13
|
+
"types": "build/cjs/main.d.ts",
|
14
|
+
"files": [
|
15
|
+
"build"
|
16
|
+
],
|
17
|
+
"scripts": {
|
18
|
+
"build": "yarn g:run-p build:cjs build:esm",
|
19
|
+
"prebuild:cjs": "yarn g:rimraf build/cjs",
|
20
|
+
"build:cjs": "yarn prebuild:cjs && yarn g:tsc -p tsconfig.build.cjs.json && yarn g:tsc-alias -p tsconfig.build.cjs.json && yarn postbuild:cjs",
|
21
|
+
"postbuild:cjs": "touch build/cjs/package.json && echo '{ \"type\": \"commonjs\" }' > build/cjs/package.json",
|
22
|
+
"prebuild:esm": "yarn g:rimraf build/esm",
|
23
|
+
"build:esm": "yarn prebuild:esm && yarn g:tsc -p tsconfig.build.esm.json && yarn g:tsc-alias -p tsconfig.build.esm.json && yarn postbuild:esm",
|
24
|
+
"postbuild:esm": "touch build/esm/package.json && echo '{ \"type\": \"module\" }' > build/esm/package.json",
|
25
|
+
"lint": "yarn g:run-p lint:eslint \"lint:prettier --check\"",
|
26
|
+
"lint:eslint": "yarn g:eslint \"src/**/*.{js,ts}\"",
|
27
|
+
"lint:fix": "yarn g:run-p \"lint:eslint --fix\" \"lint:prettier --write\"",
|
28
|
+
"lint:prettier": "yarn g:prettier . \"!**/*.{js,ts}\"",
|
29
|
+
"lint:report": "yarn g:eslint-output \"./src/**/*.{js,ts}\"",
|
30
|
+
"test:dependencies": "depcheck",
|
31
|
+
"test:types": "yarn g:tsd"
|
32
|
+
},
|
33
|
+
"prettier": "@voiceflow-meta/prettier-config",
|
34
|
+
"eslintConfig": {
|
35
|
+
"extends": "@voiceflow-meta/eslint-config"
|
36
|
+
},
|
37
|
+
"dependencies": {
|
38
|
+
"@voiceflow/common": "8.2.2",
|
39
|
+
"@voiceflow/dtos": "1.7.0",
|
40
|
+
"@voiceflow/ui-next": "npm:@voiceflow/ui@2.114.0",
|
41
|
+
"bidirectional-adapter": "1.2.1",
|
42
|
+
"slate": "0.94.1",
|
43
|
+
"ts-pattern": "^5.0.5"
|
44
|
+
},
|
45
|
+
"devDependencies": {
|
46
|
+
"@voiceflow-meta/eslint-config": "2.1.0",
|
47
|
+
"@voiceflow-meta/prettier-config": "2.1.0",
|
48
|
+
"@voiceflow-meta/typescript-config": "2.1.0"
|
49
|
+
},
|
50
|
+
"tsd": {
|
51
|
+
"directory": "src"
|
52
|
+
},
|
53
|
+
"gitHead": "fbbc4623e9e635f31d2de9c8d047bc4d1613e051"
|
54
|
+
}
|