rivia 0.0.98 → 0.0.100
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/index.js +109 -29
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4362,8 +4362,12 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4362
4362
|
// ✅ store API data
|
|
4363
4363
|
titleFontSize: null,
|
|
4364
4364
|
// for dynamic spacing when preview styles are applied
|
|
4365
|
-
workspaceId: null
|
|
4365
|
+
workspaceId: null,
|
|
4366
4366
|
// to track current workspace for dynamic updates
|
|
4367
|
+
new_feature: null,
|
|
4368
|
+
// store new feature flag from user sync for potential use in widget (e.g. show "new" badge)
|
|
4369
|
+
triggerBtn: null
|
|
4370
|
+
// store the button that triggered the widget
|
|
4367
4371
|
};
|
|
4368
4372
|
function mergeConfig(cfg) {
|
|
4369
4373
|
state.config = Object.assign({}, defaults, cfg || {});
|
|
@@ -4520,8 +4524,30 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4520
4524
|
riviaBtn.innerText = "See all changes";
|
|
4521
4525
|
footerRow.appendChild(riviaLabel);
|
|
4522
4526
|
footerRow.appendChild(riviaBtn);
|
|
4523
|
-
riviaBtn.addEventListener("click", () => {
|
|
4524
|
-
|
|
4527
|
+
riviaBtn.addEventListener("click", async () => {
|
|
4528
|
+
try {
|
|
4529
|
+
const buttons = document.querySelectorAll(state.config.buttonSelector);
|
|
4530
|
+
buttons.forEach((btn) => {
|
|
4531
|
+
const existingDot = btn.querySelector(".pm-dot");
|
|
4532
|
+
if (existingDot) {
|
|
4533
|
+
existingDot.remove();
|
|
4534
|
+
}
|
|
4535
|
+
});
|
|
4536
|
+
const response = await fetch(`https://demoapi.rivia.ai/pm_users/${state.pmUserId || ""}`, {
|
|
4537
|
+
method: "PUT",
|
|
4538
|
+
headers: {
|
|
4539
|
+
"Content-Type": "application/json"
|
|
4540
|
+
},
|
|
4541
|
+
body: JSON.stringify({
|
|
4542
|
+
new_feature: false
|
|
4543
|
+
})
|
|
4544
|
+
});
|
|
4545
|
+
const data = await response.json();
|
|
4546
|
+
console.log("Success:", data);
|
|
4547
|
+
} catch (error) {
|
|
4548
|
+
console.error("Error:", error);
|
|
4549
|
+
}
|
|
4550
|
+
const baseUrl = `https://${state.config.workspace}.rivia.ai/users/changelog?userId=${state.pmUserId || ""}`;
|
|
4525
4551
|
const url = new URL(baseUrl);
|
|
4526
4552
|
window.open(url.toString(), "_blank");
|
|
4527
4553
|
});
|
|
@@ -4545,25 +4571,37 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4545
4571
|
}
|
|
4546
4572
|
function positionWidget() {
|
|
4547
4573
|
if (!state.widgetEl) return;
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
state.widgetEl.style.bottom =
|
|
4557
|
-
|
|
4558
|
-
state.widgetEl.style.top = offset + "px";
|
|
4559
|
-
}
|
|
4560
|
-
if (align === "left") {
|
|
4561
|
-
state.widgetEl.style.left = offset + "px";
|
|
4562
|
-
} else if (align === "center") {
|
|
4563
|
-
state.widgetEl.style.left = "50%";
|
|
4564
|
-
state.widgetEl.style.transform = "translateX(-50%)";
|
|
4574
|
+
if (state.triggerBtn) {
|
|
4575
|
+
const widgetRect = state.widgetEl.getBoundingClientRect();
|
|
4576
|
+
const triggerRect = state.triggerBtn.getBoundingClientRect();
|
|
4577
|
+
const { top, left } = computePlacement(triggerRect, widgetRect, state.config);
|
|
4578
|
+
state.widgetEl.style.position = "fixed";
|
|
4579
|
+
state.widgetEl.style.top = Math.round(top) + "px";
|
|
4580
|
+
state.widgetEl.style.left = Math.round(left) + "px";
|
|
4581
|
+
state.widgetEl.style.right = "auto";
|
|
4582
|
+
state.widgetEl.style.bottom = "auto";
|
|
4583
|
+
state.widgetEl.style.transform = "none";
|
|
4565
4584
|
} else {
|
|
4566
|
-
|
|
4585
|
+
const { position, align } = state.config;
|
|
4586
|
+
const offset = 20;
|
|
4587
|
+
state.widgetEl.style.bottom = "";
|
|
4588
|
+
state.widgetEl.style.top = "";
|
|
4589
|
+
state.widgetEl.style.left = "";
|
|
4590
|
+
state.widgetEl.style.right = "";
|
|
4591
|
+
state.widgetEl.style.transform = "";
|
|
4592
|
+
if (position === "bottom") {
|
|
4593
|
+
state.widgetEl.style.bottom = offset + "px";
|
|
4594
|
+
} else {
|
|
4595
|
+
state.widgetEl.style.top = offset + "px";
|
|
4596
|
+
}
|
|
4597
|
+
if (align === "left") {
|
|
4598
|
+
state.widgetEl.style.left = offset + "px";
|
|
4599
|
+
} else if (align === "center") {
|
|
4600
|
+
state.widgetEl.style.left = "50%";
|
|
4601
|
+
state.widgetEl.style.transform = "translateX(-50%)";
|
|
4602
|
+
} else {
|
|
4603
|
+
state.widgetEl.style.right = offset + "px";
|
|
4604
|
+
}
|
|
4567
4605
|
}
|
|
4568
4606
|
}
|
|
4569
4607
|
async function fetchChangelog(id) {
|
|
@@ -4666,6 +4704,8 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4666
4704
|
if (!state.widgetEl) return;
|
|
4667
4705
|
state.backdropEl.style.display = "none";
|
|
4668
4706
|
state.widgetEl.style.display = "none";
|
|
4707
|
+
window.removeEventListener("scroll", positionWidget);
|
|
4708
|
+
state.triggerBtn = null;
|
|
4669
4709
|
}
|
|
4670
4710
|
function computePlacement(triggerRect, widgetRect, cfg) {
|
|
4671
4711
|
const offset = cfg && cfg.attachOffset || 8;
|
|
@@ -4696,15 +4736,12 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4696
4736
|
state.widgetBody.innerHTML = '<div class="pm-lite-loading">Loading\u2026</div>';
|
|
4697
4737
|
const data = await fetchChangelog(id);
|
|
4698
4738
|
renderChangelog(data);
|
|
4699
|
-
|
|
4700
|
-
const selector = state.config.buttonSelector || "[data-pm-changelog]";
|
|
4701
|
-
const isTrigger = active && active instanceof Element && active.matches && active.matches(selector);
|
|
4702
|
-
if (isTrigger) {
|
|
4739
|
+
if (state.triggerBtn) {
|
|
4703
4740
|
state.widgetEl.style.visibility = "hidden";
|
|
4704
4741
|
state.widgetEl.style.display = "block";
|
|
4705
4742
|
await new Promise((r) => requestAnimationFrame(r));
|
|
4706
4743
|
const widgetRect = state.widgetEl.getBoundingClientRect();
|
|
4707
|
-
const triggerRect =
|
|
4744
|
+
const triggerRect = state.triggerBtn.getBoundingClientRect();
|
|
4708
4745
|
const { top, left } = computePlacement(triggerRect, widgetRect, state.config);
|
|
4709
4746
|
state.widgetEl.style.position = "fixed";
|
|
4710
4747
|
state.widgetEl.style.top = Math.round(top) + "px";
|
|
@@ -4713,6 +4750,7 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4713
4750
|
state.widgetEl.style.bottom = "auto";
|
|
4714
4751
|
state.widgetEl.style.transform = "none";
|
|
4715
4752
|
state.widgetEl.style.visibility = "visible";
|
|
4753
|
+
window.addEventListener("scroll", positionWidget);
|
|
4716
4754
|
} else {
|
|
4717
4755
|
positionWidget();
|
|
4718
4756
|
}
|
|
@@ -4726,6 +4764,7 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4726
4764
|
const el = e.target.closest(state.config.buttonSelector);
|
|
4727
4765
|
if (!el) return;
|
|
4728
4766
|
e.preventDefault();
|
|
4767
|
+
state.triggerBtn = el;
|
|
4729
4768
|
const id = el.getAttribute("data-pm-changelog");
|
|
4730
4769
|
openWidgetFor(state.config.workspace || id);
|
|
4731
4770
|
});
|
|
@@ -4761,19 +4800,60 @@ var ProductManagement = /* @__PURE__ */ function() {
|
|
|
4761
4800
|
} else {
|
|
4762
4801
|
state.pmUserId = cfg.pm_user_id;
|
|
4763
4802
|
}
|
|
4803
|
+
if (data?.pm_user?.new_feature) {
|
|
4804
|
+
state.new_feature = data.pm_user.new_feature;
|
|
4805
|
+
console.log("state.new_feature", state.new_feature);
|
|
4806
|
+
}
|
|
4764
4807
|
} catch (err) {
|
|
4765
4808
|
console.error("ProductManagement user sync failed:", err);
|
|
4766
4809
|
}
|
|
4767
4810
|
}
|
|
4811
|
+
function attachDotToButtons() {
|
|
4812
|
+
const buttons = document.querySelectorAll(state.config.buttonSelector);
|
|
4813
|
+
buttons.forEach((btn) => {
|
|
4814
|
+
if (btn.querySelector(".pm-dot")) return;
|
|
4815
|
+
const dot = document.createElement("span");
|
|
4816
|
+
dot.className = "pm-dot";
|
|
4817
|
+
const style = window.getComputedStyle(btn);
|
|
4818
|
+
if (style.position === "static") {
|
|
4819
|
+
btn.style.position = "relative";
|
|
4820
|
+
}
|
|
4821
|
+
btn.appendChild(dot);
|
|
4822
|
+
});
|
|
4823
|
+
}
|
|
4824
|
+
function injectDotStyles() {
|
|
4825
|
+
if (document.getElementById("pm-dot-style")) return;
|
|
4826
|
+
const style = document.createElement("style");
|
|
4827
|
+
style.id = "pm-dot-style";
|
|
4828
|
+
style.innerHTML = `
|
|
4829
|
+
.pm-dot {
|
|
4830
|
+
position: absolute;
|
|
4831
|
+
top: 6px;
|
|
4832
|
+
right: 6px;
|
|
4833
|
+
width: 8px;
|
|
4834
|
+
height: 8px;
|
|
4835
|
+
background-color: red;
|
|
4836
|
+
border-radius: 50%;
|
|
4837
|
+
z-index: 10;
|
|
4838
|
+
}
|
|
4839
|
+
`;
|
|
4840
|
+
document.head.appendChild(style);
|
|
4841
|
+
}
|
|
4768
4842
|
function init(cfg) {
|
|
4769
4843
|
if (state.initialized) {
|
|
4770
4844
|
console.warn("ProductManagement already initialized \u2014 ignoring subsequent init call.");
|
|
4771
4845
|
return;
|
|
4772
4846
|
}
|
|
4773
4847
|
mergeConfig(cfg);
|
|
4774
|
-
syncUserFromConfig()
|
|
4775
|
-
|
|
4776
|
-
|
|
4848
|
+
syncUserFromConfig().then(() => {
|
|
4849
|
+
console.log("Initial config:", state.config);
|
|
4850
|
+
console.log("state.new_feature", state.new_feature);
|
|
4851
|
+
if (state.new_feature)
|
|
4852
|
+
attachDotToButtons();
|
|
4853
|
+
injectDotStyles();
|
|
4854
|
+
bindClicks();
|
|
4855
|
+
state.initialized = true;
|
|
4856
|
+
});
|
|
4777
4857
|
}
|
|
4778
4858
|
function setConfig(cfg) {
|
|
4779
4859
|
mergeConfig(Object.assign({}, state.config, cfg));
|