@servicetitan/dte-unlayer 0.150.0 → 0.152.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/dist/display-conditions/ConditionGroup.d.ts +1 -1
- package/dist/display-conditions/ConditionGroup.d.ts.map +1 -1
- package/dist/display-conditions/ConditionGroupsSection.d.ts +1 -1
- package/dist/display-conditions/ConditionGroupsSection.d.ts.map +1 -1
- package/dist/display-conditions/ConditionRow.d.ts +1 -1
- package/dist/display-conditions/ConditionRow.d.ts.map +1 -1
- package/dist/display-conditions/DisplayConditionModal.d.ts +4 -3
- package/dist/display-conditions/DisplayConditionModal.d.ts.map +1 -1
- package/dist/display-conditions/DisplayConditionModal.js +112 -137
- package/dist/display-conditions/DisplayConditionModal.js.map +1 -1
- package/dist/display-conditions/LookupValueControl.d.ts +1 -1
- package/dist/display-conditions/LookupValueControl.d.ts.map +1 -1
- package/dist/display-conditions/SeparatorWithChip.d.ts +1 -1
- package/dist/display-conditions/SeparatorWithChip.d.ts.map +1 -1
- package/dist/editor-core-source.d.ts +3 -3
- package/dist/editor-core-source.d.ts.map +1 -1
- package/dist/editor-core-source.js +3 -3
- package/dist/editor-core-source.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/merge-tags.d.ts +13 -0
- package/dist/merge-tags.d.ts.map +1 -0
- package/dist/merge-tags.js +39 -0
- package/dist/merge-tags.js.map +1 -0
- package/dist/unlayer-interface.d.ts +6 -1
- package/dist/unlayer-interface.d.ts.map +1 -1
- package/dist/unlayer-interface.js.map +1 -1
- package/dist/unlayer.d.ts.map +1 -1
- package/dist/unlayer.js +2 -7
- package/dist/unlayer.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/merge-tags.test.ts +143 -0
- package/src/display-conditions/DisplayConditionModal.tsx +110 -156
- package/src/editor-core-source.ts +3 -3
- package/src/index.ts +1 -0
- package/src/merge-tags.ts +65 -0
- package/src/unlayer-interface.tsx +6 -1
- package/src/unlayer.tsx +2 -8
package/src/index.ts
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { UnlayerEditorMergeTagInfo } from './unlayer-interface';
|
|
2
|
+
|
|
3
|
+
export interface UnlayerMergeTagLeaf {
|
|
4
|
+
name: string;
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface UnlayerMergeTagGroup {
|
|
9
|
+
name: string;
|
|
10
|
+
mergeTags: Record<string, UnlayerMergeTagLeaf>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type UnlayerMergeTagsConfig = Record<string, UnlayerMergeTagLeaf | UnlayerMergeTagGroup>;
|
|
14
|
+
|
|
15
|
+
export function isUnlayerMergeTagGroup(
|
|
16
|
+
entry: UnlayerMergeTagLeaf | UnlayerMergeTagGroup,
|
|
17
|
+
): entry is UnlayerMergeTagGroup {
|
|
18
|
+
return 'mergeTags' in entry;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const toMergeTagGroupKey = (groupName: string) => {
|
|
22
|
+
const key = groupName
|
|
23
|
+
.toLowerCase()
|
|
24
|
+
.split(/[^a-z0-9]+/)
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.join('_');
|
|
27
|
+
|
|
28
|
+
return key || groupName;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const toUnlayerMergeTags = (tags: UnlayerEditorMergeTagInfo[] | undefined) => {
|
|
32
|
+
if (!tags?.length) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return tags.reduce<UnlayerMergeTagsConfig>((out, tag) => {
|
|
37
|
+
const mergeTag: UnlayerMergeTagLeaf = {
|
|
38
|
+
name: tag.name,
|
|
39
|
+
value: tag.propertyPath,
|
|
40
|
+
};
|
|
41
|
+
const groupName = tag.group?.trim();
|
|
42
|
+
|
|
43
|
+
if (!groupName) {
|
|
44
|
+
out[tag.id] = mergeTag;
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const groupKey = toMergeTagGroupKey(groupName);
|
|
49
|
+
const existing = out[groupKey];
|
|
50
|
+
|
|
51
|
+
if (existing && isUnlayerMergeTagGroup(existing)) {
|
|
52
|
+
existing.mergeTags[tag.id] = mergeTag;
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
out[groupKey] = {
|
|
57
|
+
name: groupName,
|
|
58
|
+
mergeTags: {
|
|
59
|
+
[tag.id]: mergeTag,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return out;
|
|
64
|
+
}, {});
|
|
65
|
+
};
|
|
@@ -51,6 +51,7 @@ export interface UnlayerEditorMergeTagInfo {
|
|
|
51
51
|
id: string;
|
|
52
52
|
name: string;
|
|
53
53
|
propertyPath: string;
|
|
54
|
+
group?: string;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
export interface UnlayerEditorCustomTool {
|
|
@@ -83,7 +84,11 @@ export interface CreateUnlayerEditorProps {
|
|
|
83
84
|
hideContentControls?: boolean;
|
|
84
85
|
hideBodyMenuItem?: boolean;
|
|
85
86
|
displayConditions?: boolean;
|
|
86
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Optional portal target for the display-conditions dialog. Prefer unset so the dialog
|
|
89
|
+
* stays under the host `AnvilProvider` (`.anvil2` CSS scope). When set, content is wrapped
|
|
90
|
+
* in `ThemeProvider` so Anvil2 styles still apply after portaling.
|
|
91
|
+
*/
|
|
87
92
|
displayConditionModalPortalContainer?: Element | DocumentFragment | null;
|
|
88
93
|
enableHTMLEditing?: boolean;
|
|
89
94
|
enableHTMLEditingReadonly?: boolean;
|
package/src/unlayer.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { emitDisplayCondition } from './display-conditions/displayConditionController';
|
|
2
2
|
import { editorCoreScript, editorCoreStyles, editorCoreTools } from './editor-core';
|
|
3
|
+
import { toUnlayerMergeTags } from './merge-tags';
|
|
3
4
|
import { constGenericsEditor } from './shared/const';
|
|
4
5
|
import { unlayerSupportedFonts } from './shared/fonts';
|
|
5
6
|
import {
|
|
@@ -286,14 +287,7 @@ export const createUnlayerEditor = (
|
|
|
286
287
|
tables: true,
|
|
287
288
|
},
|
|
288
289
|
},
|
|
289
|
-
mergeTags: mergeTags
|
|
290
|
-
(out, tag) => {
|
|
291
|
-
out[tag.id] = { name: tag.name, value: tag.propertyPath };
|
|
292
|
-
|
|
293
|
-
return out;
|
|
294
|
-
},
|
|
295
|
-
{} as Record<string, { name: string; value: string }>,
|
|
296
|
-
),
|
|
290
|
+
mergeTags: toUnlayerMergeTags(mergeTags),
|
|
297
291
|
projectId: 5713,
|
|
298
292
|
version: latest ? undefined : versions.unlayer,
|
|
299
293
|
appearance: {
|