@supernova-studio/client 0.48.29 → 0.48.30

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.mjs CHANGED
@@ -177,6 +177,12 @@ import { z as z164 } from "zod";
177
177
  import { z as z165 } from "zod";
178
178
  import { z as z166 } from "zod";
179
179
  import { z as z167 } from "zod";
180
+ var __defProp2 = Object.defineProperty;
181
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
182
+ var __publicField2 = (obj, key, value) => {
183
+ __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
184
+ return value;
185
+ };
180
186
  var AssetDeleteScheduleStatus = z.enum(["InProgress", "Pending"]);
181
187
  var AssetDeleteSchedule = z.object({
182
188
  id: z.string(),
@@ -1789,6 +1795,96 @@ var PageBlockV1 = PageBlockBaseV1.extend({
1789
1795
  () => PageBlockV1.array().nullish().transform((t) => t ?? [])
1790
1796
  )
1791
1797
  });
1798
+ function removeCommentSpans(text) {
1799
+ const { spans, ...rest } = text;
1800
+ const newSpans = spans.map((s) => {
1801
+ return {
1802
+ ...s,
1803
+ attributes: s.attributes.filter((a) => a.type !== "Comment")
1804
+ };
1805
+ });
1806
+ const updatedRichText = {
1807
+ ...rest,
1808
+ spans: newSpans
1809
+ };
1810
+ return joinRepeatingSpans(updatedRichText);
1811
+ }
1812
+ function joinRepeatingSpans(text) {
1813
+ if (text.spans.length < 2)
1814
+ return text;
1815
+ text = sanitizeSpans(text);
1816
+ const { spans, ...rest } = text;
1817
+ let previousSpan = { ...spans[0] };
1818
+ const newSpans = [previousSpan];
1819
+ for (let i = 1; i < spans.length; i++) {
1820
+ const span = spans[i];
1821
+ if (areAttributesEqual(span.attributes, previousSpan.attributes)) {
1822
+ previousSpan.text += span.text;
1823
+ } else {
1824
+ previousSpan = { ...span };
1825
+ newSpans.push(previousSpan);
1826
+ }
1827
+ }
1828
+ return {
1829
+ ...rest,
1830
+ spans: newSpans
1831
+ };
1832
+ }
1833
+ function areAttributesEqual(lhs, rhs) {
1834
+ if (lhs.length !== rhs.length)
1835
+ return false;
1836
+ const lhsMap = mapByUnique(lhs, (i) => i.type);
1837
+ for (const rhsAttribute of rhs) {
1838
+ const lhsAttribute = lhsMap.get(rhsAttribute.type);
1839
+ if (!deepEqual(lhsAttribute, rhsAttribute))
1840
+ return false;
1841
+ }
1842
+ return true;
1843
+ }
1844
+ function sanitizeSpans(text) {
1845
+ const { spans, ...rest } = text;
1846
+ return {
1847
+ ...rest,
1848
+ spans: spans.map((s) => {
1849
+ const { attributes, ...rest2 } = s;
1850
+ return {
1851
+ ...rest2,
1852
+ attributes: attributes.map(sanitizeSpanAttribute)
1853
+ };
1854
+ })
1855
+ };
1856
+ }
1857
+ function sanitizeSpanAttribute(attribute) {
1858
+ switch (attribute.type) {
1859
+ case "Bold":
1860
+ return { type: "Bold" };
1861
+ case "Code":
1862
+ return { type: "Code" };
1863
+ case "Strikethrough":
1864
+ return { type: "Strikethrough" };
1865
+ case "Italic":
1866
+ return { type: "Italic" };
1867
+ case "Comment":
1868
+ const { commentHighlightId, commentIsResolved } = attribute;
1869
+ const isCommentIsResolvedDefined = commentIsResolved !== void 0 && commentIsResolved !== null;
1870
+ return {
1871
+ type: "Comment",
1872
+ ...isCommentIsResolvedDefined && { commentIsResolved },
1873
+ ...commentHighlightId && { commentHighlightId }
1874
+ };
1875
+ case "Link":
1876
+ const { documentationItemId, link, openInNewTab, openInNewWindow } = attribute;
1877
+ const isOpenInNewTabDefined = openInNewTab !== void 0 && openInNewTab !== null;
1878
+ const isOpenInNewWindowDefined = openInNewWindow !== void 0 && openInNewWindow !== null;
1879
+ return {
1880
+ type: "Link",
1881
+ ...isOpenInNewTabDefined && { openInNewTab },
1882
+ ...isOpenInNewWindowDefined && { openInNewWindow },
1883
+ ...documentationItemId && { documentationItemId },
1884
+ ...link && { link }
1885
+ };
1886
+ }
1887
+ }
1792
1888
  var PageBlockLinkType = z40.enum(["DocumentationItem", "PageHeading", "Url"]);
1793
1889
  var PageBlockImageType = z40.enum(["Resource", "FigmaNode"]);
1794
1890
  var PageBlockImageAlignment = z40.enum(["Left", "Center", "Stretch"]);
@@ -2614,6 +2710,60 @@ var Theme = DesignElementBase.extend(DesignElementBrandedPart.shape).extend({
2614
2710
  overrides: z82.array(ThemeOverride),
2615
2711
  codeName: z82.string()
2616
2712
  });
2713
+ function mapPageBlockItemValuesV2(pageItems, definitionsMap, fn) {
2714
+ traversePageBlockItemsV2(pageItems, (block, item) => {
2715
+ Object.entries(item.props).forEach(([propKey, value]) => {
2716
+ const property = definitionsMap.getDefinitionProperty(block.data.packageId, propKey);
2717
+ if (!property)
2718
+ return;
2719
+ item.props[propKey] = fn(block, item, property, value);
2720
+ });
2721
+ });
2722
+ }
2723
+ function traversePageBlockItemsV2(pageItems, fn) {
2724
+ traversePageItemsV2(pageItems, (block) => {
2725
+ block.data.items.forEach((item) => {
2726
+ fn(block, item);
2727
+ });
2728
+ });
2729
+ }
2730
+ function traversePageItemsV2(pageItems, fn) {
2731
+ for (const item of pageItems) {
2732
+ switch (item.type) {
2733
+ case "Block":
2734
+ fn(item);
2735
+ break;
2736
+ case "Section":
2737
+ item.items.forEach((i) => {
2738
+ i.columns.forEach((c) => {
2739
+ traversePageItemsV2(c.blocks, fn);
2740
+ });
2741
+ });
2742
+ break;
2743
+ }
2744
+ }
2745
+ }
2746
+ var PageBlockDefinitionsMap = class {
2747
+ constructor(definitions) {
2748
+ __publicField2(this, "definitionsMap", /* @__PURE__ */ new Map());
2749
+ __publicField2(this, "propertiesMap", /* @__PURE__ */ new Map());
2750
+ definitions.forEach((d) => {
2751
+ this.definitionsMap.set(d.id, d);
2752
+ d.item.properties.forEach((p) => {
2753
+ this.propertiesMap.set(this.propertyKey(d.id, p.id), p);
2754
+ });
2755
+ });
2756
+ }
2757
+ getDefinition(id) {
2758
+ return this.definitionsMap.get(id);
2759
+ }
2760
+ getDefinitionProperty(defId, propId) {
2761
+ return this.propertiesMap.get(this.propertyKey(defId, propId));
2762
+ }
2763
+ propertyKey(defId, propId) {
2764
+ return `${defId}.${propId}`;
2765
+ }
2766
+ };
2617
2767
  var FileStructureStats = z83.object({
2618
2768
  frames: zeroNumberByDefault(),
2619
2769
  components: zeroNumberByDefault(),
@@ -6195,9 +6345,10 @@ var VersionRoomBaseYDoc = class {
6195
6345
  };
6196
6346
 
6197
6347
  // src/yjs/version-room/utils.ts
6198
- function generatePageContentHash(content, debug = false) {
6348
+ function generatePageContentHash(content, definitions, debug = false) {
6199
6349
  let sanitizedContent = content;
6200
- if (isPageContentEmpty(content)) {
6350
+ sanitizedContent = removeCommentSpansFromPage(content, definitions);
6351
+ if (isPageContentEmpty(sanitizedContent)) {
6201
6352
  sanitizedContent = { blocks: [] };
6202
6353
  }
6203
6354
  return generateHash(sanitizedContent, debug);
@@ -6217,6 +6368,27 @@ function isPageContentEmpty(content) {
6217
6368
  const textValue = singleItem.props["text"];
6218
6369
  return !textValue.value.spans.length;
6219
6370
  }
6371
+ function removeCommentSpansFromPage(content, definitions) {
6372
+ const defMap = new PageBlockDefinitionsMap(definitions);
6373
+ mapPageBlockItemValuesV2(content.blocks, defMap, (block, item, prop, value) => {
6374
+ if (prop.type === "RichText") {
6375
+ const richTextValue = value;
6376
+ return {
6377
+ ...richTextValue,
6378
+ value: removeCommentSpans(richTextValue.value)
6379
+ };
6380
+ }
6381
+ if (prop.type === "MultiRichText") {
6382
+ const multiRichTextValue = value;
6383
+ return {
6384
+ ...multiRichTextValue,
6385
+ value: multiRichTextValue.value.map(removeCommentSpans)
6386
+ };
6387
+ }
6388
+ return value;
6389
+ });
6390
+ return content;
6391
+ }
6220
6392
 
6221
6393
  // src/yjs/version-room/frontend.ts
6222
6394
  var FrontendVersionRoomYDoc = class {
@@ -6454,8 +6626,8 @@ var FrontendVersionRoomYDoc = class {
6454
6626
  //
6455
6627
  // Update page content hash
6456
6628
  //
6457
- notifyDocumentationPageContentUpdated(pageId, content) {
6458
- const pageContentHash = generatePageContentHash(content, this.debug);
6629
+ notifyDocumentationPageContentUpdated(pageId, content, definitions) {
6630
+ const pageContentHash = generatePageContentHash(content, definitions, this.debug);
6459
6631
  if (this.debug) {
6460
6632
  console.log(`Will set page content hash: '${pageId}' : '${pageContentHash}'`);
6461
6633
  }