@useinsider/guido 3.21.2 → 3.22.0-beta.0951deb
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 +1 -0
- package/dist/@types/config/schemas.js +41 -39
- package/dist/@types/display-condition.js +25 -0
- package/dist/components/Guido.vue.js +6 -6
- package/dist/components/Guido.vue2.js +81 -79
- package/dist/components/organisms/display-conditions/CodeEditorField.vue.js +20 -0
- package/dist/components/organisms/display-conditions/CodeEditorField.vue2.js +30 -0
- package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.js +30 -0
- package/dist/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue2.js +71 -0
- package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.js +34 -0
- package/dist/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue2.js +57 -0
- package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue.js +17 -0
- package/dist/components/organisms/display-conditions/DisplayConditionsHost.vue2.js +22 -0
- package/dist/composables/useActionsApi.js +22 -21
- package/dist/composables/useBlocksConfig.js +32 -24
- package/dist/composables/useDisplayConditions.js +102 -0
- package/dist/composables/useFullStoryBridge.js +10 -9
- package/dist/composables/useSave.js +75 -68
- package/dist/composables/validators/useHtmlDocumentCountValidator.js +22 -0
- package/dist/config/migrator/fullStoryScriptMigrator.js +5 -0
- package/dist/config/migrator/index.js +11 -10
- package/dist/enums/academy.js +1 -0
- package/dist/enums/display-condition.js +12 -0
- package/dist/extensions/DisplayConditions/bridge.js +17 -0
- package/dist/extensions/DisplayConditions/constants.js +17 -0
- package/dist/extensions/DisplayConditions/control.js +178 -0
- package/dist/extensions/DisplayConditions/display-conditions.css.js +201 -0
- package/dist/extensions/DisplayConditions/extension.js +28 -0
- package/dist/extensions/DisplayConditions/iconsRegistry.js +20 -0
- package/dist/extensions/DisplayConditions/library.js +27 -0
- package/dist/extensions/DisplayConditions/settingsPanel.js +17 -0
- package/dist/guido.css +1 -1
- package/dist/node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js +93 -92
- package/dist/node_modules/valibot/dist/index.js +297 -261
- package/dist/services/displayConditionApi.js +39 -0
- package/dist/services/templateLibraryApi.js +36 -31
- package/dist/src/@types/config/schemas.d.ts +4 -0
- package/dist/src/@types/display-condition.d.ts +59 -0
- package/dist/src/components/organisms/display-conditions/CodeEditorField.vue.d.ts +43 -0
- package/dist/src/components/organisms/display-conditions/DisplayConditionCreateDrawer.vue.d.ts +2 -0
- package/dist/src/components/organisms/display-conditions/DisplayConditionSelectDrawer.vue.d.ts +2 -0
- package/dist/src/components/organisms/display-conditions/DisplayConditionsHost.vue.d.ts +2 -0
- package/dist/src/composables/useConfig.d.ts +2 -0
- package/dist/src/composables/useDisplayConditions.d.ts +16 -0
- package/dist/src/composables/validators/useHtmlDocumentCountValidator.d.ts +3 -0
- package/dist/src/config/migrator/fullStoryScriptMigrator.d.ts +1 -0
- package/dist/src/enums/academy.d.ts +1 -0
- package/dist/src/enums/display-condition.d.ts +15 -0
- package/dist/src/extensions/DisplayConditions/bridge.d.ts +6 -0
- package/dist/src/extensions/DisplayConditions/constants.d.ts +14 -0
- package/dist/src/extensions/DisplayConditions/control.d.ts +23 -0
- package/dist/src/extensions/DisplayConditions/extension.d.ts +2 -0
- package/dist/src/extensions/DisplayConditions/iconsRegistry.d.ts +4 -0
- package/dist/src/extensions/DisplayConditions/library.d.ts +8 -0
- package/dist/src/extensions/DisplayConditions/settingsPanel.d.ts +5 -0
- package/dist/src/mock/api/display-conditions.d.ts +2 -0
- package/dist/src/services/displayConditionApi.d.ts +8 -0
- package/dist/src/stores/config.d.ts +166 -0
- package/dist/src/stores/display-condition.d.ts +81 -0
- package/dist/src/utils/displayCondition.d.ts +10 -0
- package/dist/src/utils/fullStoryScripts.d.ts +6 -0
- package/dist/src/utils/protectTableText.d.ts +2 -0
- package/dist/src/utils/templatePreparation.d.ts +2 -1
- package/dist/stores/config.js +13 -6
- package/dist/stores/display-condition.js +28 -0
- package/dist/utils/displayCondition.js +26 -0
- package/dist/utils/fullStoryScripts.js +8 -0
- package/dist/utils/pairProductVariables.js +99 -90
- package/dist/utils/protectTableText.js +22 -0
- package/dist/utils/templatePreparation.js +30 -30
- package/package.json +1 -1
|
@@ -1,84 +1,91 @@
|
|
|
1
|
-
import { useActionsApi as
|
|
2
|
-
import { useConfig as
|
|
3
|
-
import { useEditorLock as
|
|
4
|
-
import { useSaveStart as
|
|
5
|
-
import { useSaveValidation as
|
|
6
|
-
import { useSaveValidationRollout as
|
|
7
|
-
import { useSyncModuleExtractor as
|
|
8
|
-
import { ToasterTypeOptions as
|
|
9
|
-
import { useStripoApi as
|
|
10
|
-
import { useConfigStore as
|
|
11
|
-
import { useDynamicContentStore as
|
|
12
|
-
import { useSaveValidationStore as
|
|
13
|
-
import { useTemplatePreparation as
|
|
14
|
-
import { useAllowlist as
|
|
15
|
-
import { useHtmlValidator as
|
|
16
|
-
import { useToaster as
|
|
17
|
-
import { useCouponBlockValidator as
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
import { useActionsApi as q } from "./useActionsApi.js";
|
|
2
|
+
import { useConfig as O } from "./useConfig.js";
|
|
3
|
+
import { useEditorLock as D } from "./useEditorLock.js";
|
|
4
|
+
import { useSaveStart as F, useSaveComplete as j } from "./useGuidoActions.js";
|
|
5
|
+
import { useSaveValidation as z } from "./useSaveValidation.js";
|
|
6
|
+
import { useSaveValidationRollout as G } from "./useSaveValidationRollout.js";
|
|
7
|
+
import { useSyncModuleExtractor as I } from "./useSyncModuleExtractor.js";
|
|
8
|
+
import { ToasterTypeOptions as J } from "../enums/toaster.js";
|
|
9
|
+
import { useStripoApi as K } from "../services/stripoApi.js";
|
|
10
|
+
import { useConfigStore as N } from "../stores/config.js";
|
|
11
|
+
import { useDynamicContentStore as Q } from "../stores/dynamic-content.js";
|
|
12
|
+
import { useSaveValidationStore as X } from "../stores/save-validation.js";
|
|
13
|
+
import { useTemplatePreparation as Y, getHtmlReferencedUnsubscribePages as Z } from "../utils/templatePreparation.js";
|
|
14
|
+
import { useAllowlist as _ } from "./useAllowlist.js";
|
|
15
|
+
import { useHtmlValidator as $ } from "./useHtmlValidator.js";
|
|
16
|
+
import { useToaster as tt } from "./useToaster.js";
|
|
17
|
+
import { useCouponBlockValidator as et } from "./validators/useCouponBlockValidator.js";
|
|
18
|
+
import { useHtmlDocumentCountValidator as ot } from "./validators/useHtmlDocumentCountValidator.js";
|
|
19
|
+
import { useLiquidValidator as it } from "./validators/useLiquidValidator.js";
|
|
20
|
+
import { useSyncModuleBlockValidator as st } from "./validators/useSyncModuleBlockValidator.js";
|
|
21
|
+
import { useUnsubscribeBlockValidator as at } from "./validators/useUnsubscribeBlockValidator.js";
|
|
22
|
+
const Pt = () => {
|
|
23
|
+
const n = F(), w = j(), { validateHtml: y } = $(), { validateLiquidSyntax: E } = it(), { validateCouponBlockTags: b } = et(), { validateUnsubscribeBlockUniqueness: g, validateUnsubscribeBlockHasTemplate: H } = at(), { validateSyncModuleBlocks: l } = st(), { validateSingleHtmlDocument: c } = ot(), { callbacks: r, isFeatureEnabled: v } = O(), { extractSyncModuleData: V } = I(), { setSyncModuleUnsubscriptionPages: x } = K(), { editorSave: C, getTemplateData: u } = q(), { showToaster: k } = tt(), { getBlockedDomains: h, resolveToast: B } = _(), { prepareTemplateDetails: p } = Y(), { collectSaveValidationErrors: T } = z(), { isEnabled: P } = G(), L = X(), U = Q(), S = N(), { runExclusive: m } = D(), d = async (t, e, i) => {
|
|
24
|
+
if (!v("allowlistEnabled"))
|
|
24
25
|
return !1;
|
|
25
|
-
const
|
|
26
|
-
if (!
|
|
26
|
+
const o = await h(t, e);
|
|
27
|
+
if (!o.length)
|
|
27
28
|
return !1;
|
|
28
|
-
if (!
|
|
29
|
-
const s = await
|
|
30
|
-
s != null && s.message &&
|
|
31
|
-
type:
|
|
29
|
+
if (!i) {
|
|
30
|
+
const s = await B(o);
|
|
31
|
+
s != null && s.message && k({
|
|
32
|
+
type: J.Warning,
|
|
32
33
|
message: s.message,
|
|
33
34
|
actionButton: s.actionButton
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
return !0;
|
|
37
|
-
},
|
|
38
|
-
if (!await
|
|
38
|
+
}, A = async (t) => !b(t.compiledHtml) || !g(t.compiledHtml) || !H(t.compiledHtml) ? !1 : v("liquidSyntax") ? E(t.compiledHtml) : y(t.compiledHtml, t.dynamicContentList, !0), f = async (t, e) => {
|
|
39
|
+
if (!await C())
|
|
39
40
|
return;
|
|
40
|
-
const { unsubscribePayload:
|
|
41
|
-
if (await
|
|
42
|
-
const
|
|
43
|
-
|
|
41
|
+
const { unsubscribePayload: o, stripoModules: s } = V(t.rawHtml);
|
|
42
|
+
if (await x(o), t.modules = s, !e.suppress) {
|
|
43
|
+
const a = e.blankCompiled ? { compiledHtml: "", ampHtml: "" } : {};
|
|
44
|
+
w({ ...t, ...a, silent: e.silent });
|
|
44
45
|
}
|
|
45
46
|
return t;
|
|
46
|
-
},
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
}, M = async (t, e) => {
|
|
48
|
+
var s;
|
|
49
|
+
n();
|
|
50
|
+
const i = await u();
|
|
51
|
+
if (!c(i.html, e))
|
|
52
|
+
return;
|
|
53
|
+
const o = await p(i);
|
|
54
|
+
if (l(o.rawHtml, e)) {
|
|
55
|
+
if (P.value && !e) {
|
|
56
|
+
const a = await T(
|
|
53
57
|
o.compiledHtml,
|
|
54
58
|
o.dynamicContentList
|
|
55
59
|
);
|
|
56
|
-
if (
|
|
57
|
-
|
|
60
|
+
if (a.length) {
|
|
61
|
+
L.open(a, "save");
|
|
58
62
|
return;
|
|
59
63
|
}
|
|
60
|
-
} else if (!await
|
|
64
|
+
} else if (!await A(o))
|
|
61
65
|
return;
|
|
62
|
-
if (!((
|
|
63
|
-
return
|
|
66
|
+
if (!((s = r.value) != null && s.externalValidation && !await r.value.externalValidation(o)) && !await d(o.compiledHtml, o.css, e))
|
|
67
|
+
return f(o, { silent: e, suppress: t });
|
|
64
68
|
}
|
|
65
|
-
},
|
|
66
|
-
var
|
|
67
|
-
if (!
|
|
69
|
+
}, W = async () => {
|
|
70
|
+
var i;
|
|
71
|
+
if (!S.allowSaveWithErrors)
|
|
72
|
+
return;
|
|
73
|
+
n();
|
|
74
|
+
const t = await u();
|
|
75
|
+
if (!c(t.html, !1))
|
|
68
76
|
return;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (!f.allowSaveWithErrors)
|
|
77
|
+
const e = await p(t);
|
|
78
|
+
if (l(e.rawHtml, !1) && !((i = r.value) != null && i.externalValidation && !await r.value.externalValidation(e)) && !await d(e.compiledHtml, e.css, !1))
|
|
79
|
+
return f(e, { silent: !1, blankCompiled: !0 });
|
|
80
|
+
}, R = async () => {
|
|
81
|
+
if (!S.allowSaveWithErrors)
|
|
75
82
|
return;
|
|
76
|
-
|
|
77
|
-
const { html: t, css: e } = await
|
|
78
|
-
if (!
|
|
83
|
+
n();
|
|
84
|
+
const { html: t, css: e } = await u();
|
|
85
|
+
if (!c(t, !0) || !l(t, !0) || await d(t, e, !0))
|
|
79
86
|
return;
|
|
80
|
-
const
|
|
81
|
-
dynamicContentList:
|
|
87
|
+
const i = Z(t), o = {
|
|
88
|
+
dynamicContentList: U.getSelectedDynamicContentList,
|
|
82
89
|
compiledHtml: "",
|
|
83
90
|
rawHtml: t,
|
|
84
91
|
css: e,
|
|
@@ -88,16 +95,16 @@ const Bt = () => {
|
|
|
88
95
|
// No campaignUrls: hosts overwrite their stored map with any object, and raw HTML can't rebuild it.
|
|
89
96
|
recommendation: { configs: {} },
|
|
90
97
|
unsubscribe: {
|
|
91
|
-
status:
|
|
92
|
-
config:
|
|
98
|
+
status: i.length > 0,
|
|
99
|
+
config: i
|
|
93
100
|
}
|
|
94
101
|
};
|
|
95
|
-
return
|
|
102
|
+
return f(o, { silent: !0 });
|
|
96
103
|
};
|
|
97
|
-
return { save: (t = !1, e = !1) =>
|
|
98
|
-
() =>
|
|
99
|
-
), saveWithErrors: () =>
|
|
104
|
+
return { save: (t = !1, e = !1) => m(
|
|
105
|
+
() => M(t, e)
|
|
106
|
+
), saveWithErrors: () => m(W), saveRawOnly: () => m(R) };
|
|
100
107
|
};
|
|
101
108
|
export {
|
|
102
|
-
|
|
109
|
+
Pt as useSave
|
|
103
110
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useToaster as i } from "../useToaster.js";
|
|
2
|
+
import { useTranslations as m } from "../useTranslations.js";
|
|
3
|
+
import { ToasterTypeOptions as c } from "../../enums/toaster.js";
|
|
4
|
+
const u = "newsletter.multiple-html-designs-detected", r = `(?:[^>"']|"[^"]*"|'[^']*')*`, a = "style|script|noscript|xmp|iframe|noembed|noframes|textarea|title", T = /<html(?=[\s>/])/gi, A = new RegExp(
|
|
5
|
+
`<!--[\\s\\S]*?-->|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>|<(${a})(?=[\\s/>])${r}>[\\s\\S]*?</\\1\\s*>|<([a-zA-Z][\\w:-]*)${r}>`,
|
|
6
|
+
"gi"
|
|
7
|
+
), p = (e) => Array.from(e.matchAll(A)).filter(([, , t]) => (t == null ? void 0 : t.toLowerCase()) === "html").length, g = () => {
|
|
8
|
+
const { showToaster: e } = i(), t = m();
|
|
9
|
+
return { validateSingleHtmlDocument: (o, l = !1) => {
|
|
10
|
+
var n;
|
|
11
|
+
if ((((n = o.match(T)) == null ? void 0 : n.length) ?? 0) < 2)
|
|
12
|
+
return !0;
|
|
13
|
+
const s = p(o);
|
|
14
|
+
return s <= 1 ? !0 : (console.debug("guido:save:blocked", { reason: "multiple-html-documents", htmlRootCount: s }), l || e({
|
|
15
|
+
type: c.Warning,
|
|
16
|
+
message: t(u)
|
|
17
|
+
}), !1);
|
|
18
|
+
} };
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
g as useHtmlDocumentCountValidator
|
|
22
|
+
};
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { migrateCheckbox as i } from "./checkboxMigrator.js";
|
|
2
2
|
import { migrateCouponBlock as e } from "./couponBlockMigrator.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { migrateFullStoryScripts as a } from "./fullStoryScriptMigrator.js";
|
|
4
|
+
import { migrateItemsBlock as n } from "./itemsBlockMigrator.js";
|
|
5
|
+
import { migrateProductNameLink as c } from "./productNameLinkMigrator.js";
|
|
6
|
+
import { migrateRadioButton as g } from "./radioButtonMigrator.js";
|
|
7
|
+
import { migrateRecommendation as p } from "./recommendationMigrator.js";
|
|
7
8
|
import { migrateRecommendationPartnerScope as f } from "./recommendationPartnerMigrator.js";
|
|
8
|
-
import { migrateRecommendationTitle as
|
|
9
|
-
import { migrateSocialIcons as
|
|
10
|
-
import { migrateUnsubscribe as
|
|
11
|
-
const h = async (
|
|
12
|
-
let m =
|
|
13
|
-
return m = i(m), m =
|
|
9
|
+
import { migrateRecommendationTitle as l } from "./recommendationTitleMigrator.js";
|
|
10
|
+
import { migrateSocialIcons as s } from "./socialIconMigrator.js";
|
|
11
|
+
import { migrateUnsubscribe as d } from "./unsubscribeMigrator.js";
|
|
12
|
+
const h = async (o, t = {}, r) => {
|
|
13
|
+
let m = o;
|
|
14
|
+
return m = i(m), m = g(m), m = await d(m), m = e(m), m = p(m, t), r && (m = f(m, r)), m = l(m), m = n(m), m = c(m), m = s(m), m = a(m), m;
|
|
14
15
|
};
|
|
15
16
|
export {
|
|
16
17
|
h as migrate
|
package/dist/enums/academy.js
CHANGED
|
@@ -2,6 +2,7 @@ const e = "https://academy.insiderone.com", o = {
|
|
|
2
2
|
EMAIL_EDITOR: `${e}/docs/email-drag-and-drop-editor`,
|
|
3
3
|
GLOBAL_UNSUBSCRIBE: `${e}/docs/global-unsubscribe-preference-center`,
|
|
4
4
|
AMP_FOR_EMAILS: `${e}/docs/amp-for-emails`,
|
|
5
|
+
EMAIL_DISPLAY_CONDITIONS: `${e}/docs/new-editor-add-display-conditions-to-an-email`,
|
|
5
6
|
EMAIL_RECOMMENDATION_BLOCK: `${e}/docs/new-editor-email-recommendation-block`
|
|
6
7
|
};
|
|
7
8
|
export {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var N = /* @__PURE__ */ ((I) => (I.OPEN = "display-condition:open", I.APPLY = "display-condition:apply", I.CANCEL = "display-condition:cancel", I))(N || {}), A = /* @__PURE__ */ ((I) => (I.INLINE = "inline", I.SAVED = "saved", I))(A || {});
|
|
2
|
+
const M = {
|
|
3
|
+
NAME_MIN: 2,
|
|
4
|
+
NAME_MAX: 40,
|
|
5
|
+
DESCRIPTION_MAX: 200,
|
|
6
|
+
CODE_MAX: 65535
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
M as DISPLAY_CONDITION_LIMITS,
|
|
10
|
+
N as DisplayConditionEvent,
|
|
11
|
+
A as DisplayConditionSourceType
|
|
12
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DisplayConditionEvent as e } from "../../enums/display-condition.js";
|
|
2
|
+
let n = null;
|
|
3
|
+
const p = (E, t) => {
|
|
4
|
+
n == null || n();
|
|
5
|
+
const i = (o) => {
|
|
6
|
+
n == null || n(), t.onApply(o.detail.condition);
|
|
7
|
+
}, m = () => {
|
|
8
|
+
var o;
|
|
9
|
+
n == null || n(), (o = t.onCancel) == null || o.call(t);
|
|
10
|
+
};
|
|
11
|
+
document.addEventListener(e.APPLY, i), document.addEventListener(e.CANCEL, m), n = () => {
|
|
12
|
+
document.removeEventListener(e.APPLY, i), document.removeEventListener(e.CANCEL, m), n = null;
|
|
13
|
+
}, document.dispatchEvent(new CustomEvent(e.OPEN, { detail: E }));
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
p as requestDisplayCondition
|
|
17
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BlockType as o } from "../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
2
|
+
const n = "conditions", t = "guido-display-conditions-control", c = 10, s = [o.STRIPE, o.STRUCTURE, o.CONTAINER], d = {
|
|
3
|
+
PLUS: "guido-display-condition-plus",
|
|
4
|
+
EDIT: "guido-display-condition-edit",
|
|
5
|
+
TRASH: "guido-display-condition-trash",
|
|
6
|
+
CHEVRON: "guido-display-condition-chevron"
|
|
7
|
+
}, e = ["applyConditionSwitcher", "applyCondition", "displayConditions"], I = "You can add Display Condition by selecting an existing condition or creating a new one to show specific content.", O = "You can create or select a display condition to control content visibility based on your recipients' properties or events.";
|
|
8
|
+
export {
|
|
9
|
+
O as APPLIED_DESCRIPTION,
|
|
10
|
+
e as BUILT_IN_CONDITION_CONTROLS,
|
|
11
|
+
t as CONDITIONS_CONTROL_ID,
|
|
12
|
+
n as CONDITIONS_TAB_ID,
|
|
13
|
+
s as CONDITION_BLOCK_TYPES,
|
|
14
|
+
d as CONDITION_ICONS,
|
|
15
|
+
I as EMPTY_DESCRIPTION,
|
|
16
|
+
c as MAX_COLLAPSED_LINES
|
|
17
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
var O = Object.defineProperty;
|
|
2
|
+
var $ = (o, s, i) => s in o ? O(o, s, { enumerable: !0, configurable: !0, writable: !0, value: i }) : o[s] = i;
|
|
3
|
+
var u = (o, s, i) => $(o, typeof s != "symbol" ? s + "" : s, i);
|
|
4
|
+
import { CommonControl as S } from "../Blocks/common-control.js";
|
|
5
|
+
import { toAppliedCondition as w, parseSource as N } from "../../utils/displayCondition.js";
|
|
6
|
+
import { escapeHtml as f } from "../../utils/htmlEscape.js";
|
|
7
|
+
import { ModificationDescription as D, UIElementType as b, UEAttr as I } from "../../node_modules/@stripoinc/ui-editor-extensions/dist/esm/index.js";
|
|
8
|
+
import { requestDisplayCondition as E } from "./bridge.js";
|
|
9
|
+
import { CONDITIONS_CONTROL_ID as x, APPLIED_DESCRIPTION as M, EMPTY_DESCRIPTION as T, MAX_COLLAPSED_LINES as v, CONDITION_ICONS as g } from "./constants.js";
|
|
10
|
+
const r = ".guido-display-conditions", L = { id: 0, name: "", description: "", beforeScript: "", afterScript: "" }, _ = (o) => `<${b.ICON} ${I.ICON.src}="${o}"></${b.ICON}>`, c = (o, s, i, t = !1) => `<button type="button" class="${s}" id="${o}"${t ? " hidden" : ""}>${i}</button>`;
|
|
11
|
+
class B extends S {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
u(this, "expanded", !1);
|
|
15
|
+
u(this, "listeners", []);
|
|
16
|
+
u(this, "resizeObserver", null);
|
|
17
|
+
u(this, "detachOutsideClick", null);
|
|
18
|
+
}
|
|
19
|
+
getId() {
|
|
20
|
+
return x;
|
|
21
|
+
}
|
|
22
|
+
getTemplate() {
|
|
23
|
+
return `
|
|
24
|
+
<div class="guido-display-conditions">
|
|
25
|
+
<div class="guido-display-conditions__header">
|
|
26
|
+
<p class="guido-display-conditions__title">${this.api.translate("Display Conditions")}</p>
|
|
27
|
+
<p class="guido-display-conditions__description" data-dc-description></p>
|
|
28
|
+
</div>
|
|
29
|
+
<div class="guido-display-conditions__empty" data-dc-empty>
|
|
30
|
+
${c(
|
|
31
|
+
"guido__btn-add-display-condition",
|
|
32
|
+
"guido-display-conditions__add",
|
|
33
|
+
`${_(g.PLUS)}<span>${this.api.translate("Add Display Condition")}</span>`
|
|
34
|
+
)}
|
|
35
|
+
<div class="guido-display-conditions__menu" data-dc-menu hidden>
|
|
36
|
+
${c(
|
|
37
|
+
"guido__btn-display-condition-create",
|
|
38
|
+
"guido-display-conditions__menu-item",
|
|
39
|
+
this.api.translate("Create New Condition")
|
|
40
|
+
)}
|
|
41
|
+
${c(
|
|
42
|
+
"guido__btn-display-condition-select",
|
|
43
|
+
"guido-display-conditions__menu-item",
|
|
44
|
+
this.api.translate("Select Saved Condition")
|
|
45
|
+
)}
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
<div class="guido-display-conditions__applied" data-dc-applied hidden>
|
|
49
|
+
<div class="guido-display-conditions__code-box">
|
|
50
|
+
<p class="guido-display-conditions__name" data-dc-name></p>
|
|
51
|
+
<div class="guido-display-conditions__sections" data-dc-sections>
|
|
52
|
+
<p class="guido-display-conditions__section-label">
|
|
53
|
+
${this.api.translate("Code Before Module")}
|
|
54
|
+
</p>
|
|
55
|
+
<pre class="guido-display-conditions__code" data-dc-before></pre>
|
|
56
|
+
<p class="guido-display-conditions__section-label" data-dc-after-label>
|
|
57
|
+
${this.api.translate("Code After Module")}
|
|
58
|
+
</p>
|
|
59
|
+
<pre class="guido-display-conditions__code" data-dc-after></pre>
|
|
60
|
+
</div>
|
|
61
|
+
${c(
|
|
62
|
+
"guido__btn-display-condition-toggle",
|
|
63
|
+
"guido-display-conditions__toggle",
|
|
64
|
+
`${_(g.CHEVRON)}<span data-dc-toggle-label></span>`,
|
|
65
|
+
!0
|
|
66
|
+
)}
|
|
67
|
+
</div>
|
|
68
|
+
<div class="guido-display-conditions__actions">
|
|
69
|
+
${c(
|
|
70
|
+
"guido__btn-edit-display-condition",
|
|
71
|
+
"guido-display-conditions__action guido-display-conditions__action--edit",
|
|
72
|
+
`${_(g.EDIT)}<span>${this.api.translate("Edit")}</span>`
|
|
73
|
+
)}
|
|
74
|
+
${c(
|
|
75
|
+
"guido__btn-remove-display-condition",
|
|
76
|
+
"guido-display-conditions__action guido-display-conditions__action--remove",
|
|
77
|
+
`${_(g.TRASH)}<span>${this.api.translate("Remove")}</span>`
|
|
78
|
+
)}
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
`;
|
|
83
|
+
}
|
|
84
|
+
onRender() {
|
|
85
|
+
this.teardown(), this.wire("#guido__btn-add-display-condition", () => this.toggleMenu()), this.wire("#guido__btn-display-condition-create", () => this.openDrawer("create")), this.wire("#guido__btn-display-condition-select", () => this.openDrawer("select")), this.wire("#guido__btn-edit-display-condition", () => this.openDrawer("edit")), this.wire("#guido__btn-remove-display-condition", () => this.applyCondition(null)), this.wire("#guido__btn-display-condition-toggle", () => {
|
|
86
|
+
this.expanded = !this.expanded, this.paint();
|
|
87
|
+
}), this.observeCodeSize(), this.paint();
|
|
88
|
+
}
|
|
89
|
+
onTemplateNodeUpdated(i) {
|
|
90
|
+
const t = i !== this.currentNode;
|
|
91
|
+
super.onTemplateNodeUpdated(i), t && (this.expanded = !1, this.toggleMenu(!1)), this.paint();
|
|
92
|
+
}
|
|
93
|
+
onDestroy() {
|
|
94
|
+
super.onDestroy(), this.teardown();
|
|
95
|
+
}
|
|
96
|
+
getCondition() {
|
|
97
|
+
var t;
|
|
98
|
+
const i = this.currentNode;
|
|
99
|
+
return w((t = i == null ? void 0 : i.getDisplayCondition) == null ? void 0 : t.call(i));
|
|
100
|
+
}
|
|
101
|
+
toggleMenu(i) {
|
|
102
|
+
var n, d, a;
|
|
103
|
+
const t = (n = this.getContainer()) == null ? void 0 : n.querySelector(`${r} [data-dc-menu]`);
|
|
104
|
+
if (!t)
|
|
105
|
+
return;
|
|
106
|
+
t.hidden = i === void 0 ? !t.hidden : !i, (d = this.detachOutsideClick) == null || d.call(this), t.hidden || this.listenOutsideClick();
|
|
107
|
+
const e = (a = this.getContainer()) == null ? void 0 : a.querySelector(`${r} #guido__btn-add-display-condition`);
|
|
108
|
+
t.style.width = !t.hidden && e ? `${e.getBoundingClientRect().width}px` : "";
|
|
109
|
+
}
|
|
110
|
+
listenOutsideClick() {
|
|
111
|
+
const i = this.getContainer(), t = (e) => {
|
|
112
|
+
e.composedPath().some((d) => d instanceof HTMLElement && d.matches(`${r} [data-dc-menu], ${r} #guido__btn-add-display-condition`)) || this.toggleMenu(!1);
|
|
113
|
+
};
|
|
114
|
+
i == null || i.addEventListener("pointerdown", t, !0), this.detachOutsideClick = () => {
|
|
115
|
+
i == null || i.removeEventListener("pointerdown", t, !0), this.detachOutsideClick = null;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
openDrawer(i) {
|
|
119
|
+
this.toggleMenu(!1), E(
|
|
120
|
+
{ mode: i, current: i === "edit" ? this.getCondition() : null },
|
|
121
|
+
{ onApply: (t) => this.applyCondition(t) }
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
applyCondition(i) {
|
|
125
|
+
if (!this.currentNode)
|
|
126
|
+
return;
|
|
127
|
+
const t = this.api.getDocumentModifier().modifyHtml(this.currentNode);
|
|
128
|
+
i ? t.setDisplayCondition(i) : t.setDisplayCondition(L), t.apply(new D(
|
|
129
|
+
i ? `Set display condition ${i.name}` : "Remove display condition"
|
|
130
|
+
));
|
|
131
|
+
}
|
|
132
|
+
wire(i, t) {
|
|
133
|
+
var n;
|
|
134
|
+
const e = (n = this.getContainer()) == null ? void 0 : n.querySelector(`${r} ${i}`);
|
|
135
|
+
e && (e.addEventListener("click", t), this.listeners.push({ element: e, handler: t }));
|
|
136
|
+
}
|
|
137
|
+
teardown() {
|
|
138
|
+
var i, t;
|
|
139
|
+
this.listeners.forEach(({ element: e, handler: n }) => e.removeEventListener("click", n)), this.listeners = [], (i = this.resizeObserver) == null || i.disconnect(), this.resizeObserver = null, (t = this.detachOutsideClick) == null || t.call(this);
|
|
140
|
+
}
|
|
141
|
+
// Line counts depend on layout: the panel font loads late and the panel can be resized.
|
|
142
|
+
observeCodeSize() {
|
|
143
|
+
var t;
|
|
144
|
+
const i = (t = this.getContainer()) == null ? void 0 : t.querySelectorAll(`${r} .guido-display-conditions__code`);
|
|
145
|
+
!(i != null && i.length) || typeof ResizeObserver > "u" || (this.resizeObserver = new ResizeObserver(() => this.paint()), i.forEach((e) => {
|
|
146
|
+
var n;
|
|
147
|
+
return (n = this.resizeObserver) == null ? void 0 : n.observe(e);
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
paint() {
|
|
151
|
+
var C;
|
|
152
|
+
const i = (C = this.getContainer()) == null ? void 0 : C.querySelector(r);
|
|
153
|
+
if (!i)
|
|
154
|
+
return;
|
|
155
|
+
const t = this.getCondition(), e = (h) => i.querySelector(h);
|
|
156
|
+
if (e("[data-dc-empty]").hidden = !!t, e("[data-dc-applied]").hidden = !t, e("[data-dc-description]").textContent = this.api.translate(t ? M : T), !t)
|
|
157
|
+
return;
|
|
158
|
+
e("[data-dc-name]").textContent = t.name, e("#guido__btn-edit-display-condition").hidden = N(t) !== "inline";
|
|
159
|
+
const n = e("[data-dc-sections]"), d = e("[data-dc-before]"), a = e("[data-dc-after]");
|
|
160
|
+
d.innerHTML = f(t.beforeScript), a.innerHTML = f(t.afterScript), a.hidden = !t.afterScript, e("[data-dc-after-label]").hidden = !t.afterScript, n.style.maxHeight = "";
|
|
161
|
+
const l = parseFloat(getComputedStyle(d).lineHeight) || 24, p = (h) => h.hidden ? 0 : Math.round(h.scrollHeight / l), y = p(d) + p(a) > v, m = e("#guido__btn-display-condition-toggle");
|
|
162
|
+
m.hidden = !y, m.classList.toggle("is-expanded", this.expanded), e("[data-dc-toggle-label]").textContent = this.api.translate(this.expanded ? "Show Less" : "Show More"), y && !this.expanded && (n.style.maxHeight = `${this.collapsedHeight(n, [d, a], l)}px`);
|
|
163
|
+
}
|
|
164
|
+
// Labels do not count toward the line limit, so the cut lands after the 10th rendered code line.
|
|
165
|
+
collapsedHeight(i, t, e) {
|
|
166
|
+
const { top: n } = i.getBoundingClientRect();
|
|
167
|
+
let d = v, a = 0;
|
|
168
|
+
return t.filter((l) => !l.hidden).forEach((l) => {
|
|
169
|
+
if (d <= 0)
|
|
170
|
+
return;
|
|
171
|
+
const p = Math.min(d, Math.round(l.scrollHeight / e));
|
|
172
|
+
a = l.getBoundingClientRect().top - n + p * e, d -= p;
|
|
173
|
+
}), a;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
export {
|
|
177
|
+
B as DisplayConditionsControl
|
|
178
|
+
};
|