@caring-dev/react-notion-x 7.8.8 → 7.8.9

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.
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as types from 'notion-types';
3
- import { N as NotionContext } from '../context--HOSgWjH.js';
3
+ import { N as NotionContext } from '../context-MVPVCXSf.js';
4
4
  import React__default from 'react';
5
5
 
6
6
  interface IPropertyProps {
@@ -393,7 +393,7 @@ var require_format_number = __commonJS({
393
393
  import {
394
394
  getBlockCollectionId,
395
395
  getBlockParentPage as getBlockParentPage2,
396
- getBlockValue as getBlockValue9,
396
+ getBlockValue as getBlockValue10,
397
397
  getTextContent as getTextContent4
398
398
  } from "notion-utils";
399
399
  import React22 from "react";
@@ -5877,7 +5877,7 @@ function isSameMonth(laterDate, earlierDate, options) {
5877
5877
 
5878
5878
  // src/third-party/collection-view-calendar.tsx
5879
5879
  import "notion-types";
5880
- import { getDateValue as getDateValue2 } from "notion-utils";
5880
+ import { getBlockValue as getBlockValue6, getDateValue as getDateValue2, idToUuid, uuidToId } from "notion-utils";
5881
5881
  import React20 from "react";
5882
5882
 
5883
5883
  // src/third-party/collection-week-row.tsx
@@ -5906,18 +5906,21 @@ function CalendarWeekRow({
5906
5906
  const [cardHeights, setCardHeights] = React19.useState(
5907
5907
  /* @__PURE__ */ new Map()
5908
5908
  );
5909
- const propertiesSource = ((_a = collectionView.format) == null ? void 0 : _a.calendar_properties) || ((_b = collectionView.format) == null ? void 0 : _b.list_properties) || [];
5909
+ const calendarFormat = collectionView.type === "calendar" ? collectionView == null ? void 0 : collectionView.format : void 0;
5910
+ const listFormat = collectionView.type === "list" ? collectionView == null ? void 0 : collectionView.format : void 0;
5911
+ const propertiesSource = (_b = (_a = calendarFormat == null ? void 0 : calendarFormat.calendar_properties) != null ? _a : listFormat == null ? void 0 : listFormat.list_properties) != null ? _b : [];
5910
5912
  const visibleProperties = propertiesSource.filter(
5911
5913
  (p) => p.visible === true && p.property !== "title" && (datePropertyId ? p.property !== datePropertyId : true)
5912
5914
  );
5913
- const calendarCover = ((_c = collectionView.format) == null ? void 0 : _c.calendar_cover) || {
5915
+ const calendarCover = (_c = calendarFormat == null ? void 0 : calendarFormat.calendar_cover) != null ? _c : {
5914
5916
  type: "none"
5915
5917
  };
5916
- const calendarCoverSize = ((_d = collectionView.format) == null ? void 0 : _d.calendar_cover_size) || "small";
5917
- const calendarCoverAspect = ((_e = collectionView.format) == null ? void 0 : _e.calendar_cover_aspect) || "cover";
5918
+ const calendarCoverSize = (_d = calendarFormat == null ? void 0 : calendarFormat.calendar_cover_size) != null ? _d : "small";
5919
+ const calendarCoverAspect = (_e = calendarFormat == null ? void 0 : calendarFormat.calendar_cover_aspect) != null ? _e : "cover";
5918
5920
  const MULTIDAY_CARD_MIN_HEIGHT = 44;
5919
5921
  const MULTIDAY_START_OFFSET = 28;
5920
5922
  const { eventsWithAdjustedWidth: allEventsWithWidth, layersPerDay } = React19.useMemo(() => {
5923
+ var _a2;
5921
5924
  const events = [];
5922
5925
  const allEvents = [];
5923
5926
  for (const [dayIndexInWeek, day] of weekDays.entries()) {
@@ -5992,7 +5995,7 @@ function CalendarWeekRow({
5992
5995
  { length: 7 },
5993
5996
  () => []
5994
5997
  );
5995
- const layersPerDay2 = Array.from({ length: 7 }).fill(0);
5998
+ const layersPerDay2 = Array.from({ length: 7 }, () => 0);
5996
5999
  for (const event of sortedEvents) {
5997
6000
  const spanStart = Math.max(0, event.displayStartDayIndex);
5998
6001
  const spanEnd = Math.min(6, event.displayEndDayIndex);
@@ -6013,7 +6016,7 @@ function CalendarWeekRow({
6013
6016
  if (dayLayers) {
6014
6017
  dayLayers[layerIndex] = event;
6015
6018
  layersPerDay2[dayIndex] = Math.max(
6016
- layersPerDay2[dayIndex],
6019
+ (_a2 = layersPerDay2[dayIndex]) != null ? _a2 : 0,
6017
6020
  layerIndex + 1
6018
6021
  );
6019
6022
  }
@@ -6407,53 +6410,110 @@ function CalendarWeekRow({
6407
6410
  // src/third-party/collection-view-calendar.tsx
6408
6411
  import { jsx as jsx55, jsxs as jsxs18 } from "react/jsx-runtime";
6409
6412
  var defaultBlockIds = [];
6413
+ function getBlockById(recordMap, blockId) {
6414
+ var _a, _b, _c;
6415
+ const raw = (_a = recordMap.block) == null ? void 0 : _a[blockId];
6416
+ let block = getBlockValue6(raw);
6417
+ if (block) return block;
6418
+ const noDashes = blockId.replace(/-/g, "");
6419
+ if (noDashes.length === 32) {
6420
+ const withDashes = idToUuid(noDashes);
6421
+ block = getBlockValue6((_b = recordMap.block) == null ? void 0 : _b[withDashes]);
6422
+ if (block) return block;
6423
+ }
6424
+ const asId = uuidToId(blockId);
6425
+ block = getBlockValue6((_c = recordMap.block) == null ? void 0 : _c[asId]);
6426
+ if (block) return block;
6427
+ const norm = noDashes.length === 32 ? noDashes : asId;
6428
+ for (const key of Object.keys(recordMap.block || {})) {
6429
+ const b = getBlockValue6(recordMap.block[key]);
6430
+ if ((b == null ? void 0 : b.id) && uuidToId(b.id) === norm) return b;
6431
+ }
6432
+ return void 0;
6433
+ }
6434
+ function parseDateValue(prop) {
6435
+ const fromUtils = getDateValue2(Array.isArray(prop) ? prop : [prop]);
6436
+ if (fromUtils && typeof fromUtils === "object" && fromUtils.start_date)
6437
+ return fromUtils;
6438
+ if (prop && typeof prop === "object" && !Array.isArray(prop) && "start_date" in prop) {
6439
+ const o = prop;
6440
+ if (o.start_date) return o;
6441
+ }
6442
+ return null;
6443
+ }
6444
+ function getBlockProperties(block) {
6445
+ if (!block) return void 0;
6446
+ const p = block.properties;
6447
+ if (p && typeof p === "object" && !Array.isArray(p)) return p;
6448
+ const v = block.value;
6449
+ if (v && typeof v === "object" && v.properties && typeof v.properties === "object")
6450
+ return v.properties;
6451
+ return void 0;
6452
+ }
6410
6453
  function CollectionViewCalendar({
6411
6454
  collection,
6412
6455
  collectionView,
6413
6456
  collectionData
6414
6457
  }) {
6415
- var _a, _b;
6458
+ var _a, _b, _c, _d, _e, _f, _g;
6459
+ if (typeof window !== "undefined") {
6460
+ console.log("[Calendar] component mounted");
6461
+ fetch("http://127.0.0.1:7682/ingest/84ddabf3-24ba-497f-b790-14e045db9106", { method: "POST", headers: { "Content-Type": "application/json", "X-Debug-Session-Id": "764ae3" }, body: JSON.stringify({ sessionId: "764ae3", location: "collection-view-calendar.tsx:mount", message: "Calendar component mounted", data: {}, timestamp: Date.now(), hypothesisId: "H3" }) }).catch(() => {
6462
+ });
6463
+ }
6416
6464
  const { recordMap } = useNotionContext();
6417
6465
  const [currentMonth, setCurrentMonth] = React20.useState(/* @__PURE__ */ new Date());
6418
- const blockIds = ((_b = (_a = collectionData.collection_group_results) == null ? void 0 : _a.blockIds) != null ? _b : collectionData.blockIds) || defaultBlockIds;
6466
+ const blockIds = (_c = (_b = (_a = collectionData.collection_group_results) == null ? void 0 : _a.blockIds) != null ? _b : collectionData.blockIds) != null ? _c : defaultBlockIds;
6467
+ const collectionSchema = (_f = (_e = collection == null ? void 0 : collection.schema) != null ? _e : (_d = collection == null ? void 0 : collection.value) == null ? void 0 : _d.schema) != null ? _f : {};
6468
+ const schemaDateIds = React20.useMemo(
6469
+ () => Object.entries(collectionSchema).filter(([, s]) => (s == null ? void 0 : s.type) === "date").map(([id]) => id),
6470
+ [collectionSchema]
6471
+ );
6419
6472
  const datePropertyId = React20.useMemo(() => {
6420
6473
  var _a2;
6421
- const calendarBy = (_a2 = collectionView == null ? void 0 : collectionView.query2) == null ? void 0 : _a2.calendar_by;
6474
+ const calendarBy = (_a2 = collectionView.query2) == null ? void 0 : _a2.calendar_by;
6422
6475
  if (calendarBy) {
6423
- const schema2 = collection.schema;
6424
- const propertySchema = schema2[calendarBy];
6476
+ const propertySchema = collectionSchema[calendarBy];
6425
6477
  if (propertySchema && propertySchema.type === "date") {
6426
6478
  return calendarBy;
6427
6479
  }
6428
6480
  }
6429
- const schema = collection.schema;
6430
- for (const [propertyId, propertySchema] of Object.entries(schema)) {
6481
+ for (const [propertyId, propertySchema] of Object.entries(collectionSchema)) {
6431
6482
  if (propertySchema.type === "date") {
6432
6483
  return propertyId;
6433
6484
  }
6434
6485
  }
6435
6486
  return null;
6436
- }, [collection.schema, collectionView]);
6487
+ }, [collectionSchema, collectionView]);
6488
+ const effectiveDatePropertyId = (_g = datePropertyId != null ? datePropertyId : schemaDateIds[0]) != null ? _g : null;
6437
6489
  const eventsByDate = React20.useMemo(() => {
6438
- var _a2, _b2;
6439
6490
  const eventsMap = /* @__PURE__ */ new Map();
6440
- if (!datePropertyId) {
6441
- return eventsMap;
6442
- }
6443
6491
  for (const blockId of blockIds) {
6444
- const block = (_a2 = recordMap.block[blockId]) == null ? void 0 : _a2.value;
6492
+ const block = getBlockById(recordMap, blockId);
6445
6493
  if (!block) continue;
6446
- const dateProperty = (_b2 = block.properties) == null ? void 0 : _b2[datePropertyId];
6494
+ const props = getBlockProperties(block);
6495
+ if (!props) continue;
6496
+ let dateProperty = effectiveDatePropertyId ? props[effectiveDatePropertyId] : void 0;
6497
+ if (!dateProperty && schemaDateIds.length) {
6498
+ for (const pid of schemaDateIds) {
6499
+ const p = props[pid];
6500
+ if (p) {
6501
+ dateProperty = p;
6502
+ break;
6503
+ }
6504
+ }
6505
+ }
6447
6506
  if (!dateProperty) continue;
6448
- const dateValue = getDateValue2(dateProperty);
6507
+ const dateValue = parseDateValue(dateProperty);
6449
6508
  if (!dateValue) continue;
6450
6509
  let startDate;
6451
6510
  let endDate = null;
6452
6511
  let dateRange = null;
6453
- if (dateValue.type === "date" || dateValue.type === "datetime") {
6512
+ const dtype = dateValue.type || "date";
6513
+ if (dtype === "date" || dtype === "datetime") {
6454
6514
  startDate = new Date(dateValue.start_date);
6455
6515
  endDate = null;
6456
- } else if (dateValue.type === "daterange" || dateValue.type === "datetimerange") {
6516
+ } else if (dtype === "daterange" || dtype === "datetimerange") {
6457
6517
  startDate = new Date(dateValue.start_date);
6458
6518
  endDate = dateValue.end_date ? new Date(dateValue.end_date) : null;
6459
6519
  if (endDate) {
@@ -6482,8 +6542,28 @@ function CollectionViewCalendar({
6482
6542
  eventsMap.get(dateKey).push({ block, dateRange: null });
6483
6543
  }
6484
6544
  }
6545
+ if (typeof window !== "undefined" && blockIds.length > 0 && eventsMap.size === 0) {
6546
+ const firstId = blockIds[0];
6547
+ const block = getBlockById(recordMap, firstId);
6548
+ const props = getBlockProperties(block);
6549
+ let dateProp = effectiveDatePropertyId ? props == null ? void 0 : props[effectiveDatePropertyId] : void 0;
6550
+ if (!dateProp && schemaDateIds.length && props) dateProp = props[schemaDateIds[0]];
6551
+ const dv = dateProp ? parseDateValue(dateProp) : null;
6552
+ const diag = {
6553
+ blockIdsLength: blockIds.length,
6554
+ datePropertyId: effectiveDatePropertyId,
6555
+ firstId,
6556
+ blockFound: !!block,
6557
+ propKeys: props ? Object.keys(props) : [],
6558
+ hasDateProp: !!dateProp,
6559
+ dateValue: dv ? { type: dv.type, start_date: dv.start_date } : null
6560
+ };
6561
+ console.warn("[Calendar] no events \u2014 diagnostic:", diag);
6562
+ fetch("http://127.0.0.1:7682/ingest/84ddabf3-24ba-497f-b790-14e045db9106", { method: "POST", headers: { "Content-Type": "application/json", "X-Debug-Session-Id": "764ae3" }, body: JSON.stringify({ sessionId: "764ae3", location: "collection-view-calendar.tsx:noEvents", message: "no events diagnostic", data: diag, timestamp: Date.now(), hypothesisId: "H4" }) }).catch(() => {
6563
+ });
6564
+ }
6485
6565
  return eventsMap;
6486
- }, [blockIds, datePropertyId, recordMap]);
6566
+ }, [blockIds, datePropertyId, recordMap, collectionSchema, effectiveDatePropertyId]);
6487
6567
  const calendarDays = React20.useMemo(() => {
6488
6568
  const weekStartsOn = 1;
6489
6569
  const monthStart = startOfMonth(currentMonth);
@@ -6566,7 +6646,7 @@ function CollectionViewCalendar({
6566
6646
  eventsByDate,
6567
6647
  collection,
6568
6648
  collectionView,
6569
- datePropertyId,
6649
+ datePropertyId: effectiveDatePropertyId,
6570
6650
  currentMonth,
6571
6651
  today
6572
6652
  },
@@ -6578,7 +6658,7 @@ function CollectionViewCalendar({
6578
6658
 
6579
6659
  // src/third-party/collection-view-gallery.tsx
6580
6660
  import "notion-types";
6581
- import { getBlockValue as getBlockValue6 } from "notion-utils";
6661
+ import { getBlockValue as getBlockValue7 } from "notion-utils";
6582
6662
  import { jsx as jsx56 } from "react/jsx-runtime";
6583
6663
  var defaultBlockIds2 = [];
6584
6664
  function CollectionViewGallery({
@@ -6633,7 +6713,7 @@ function Gallery({
6633
6713
  ),
6634
6714
  children: blockIds == null ? void 0 : blockIds.map((blockId) => {
6635
6715
  var _a;
6636
- const block = getBlockValue6(recordMap.block[blockId]);
6716
+ const block = getBlockValue7(recordMap.block[blockId]);
6637
6717
  if (!block) return null;
6638
6718
  return /* @__PURE__ */ jsx56(
6639
6719
  CollectionCard,
@@ -6654,7 +6734,7 @@ function Gallery({
6654
6734
 
6655
6735
  // src/third-party/collection-view-list.tsx
6656
6736
  import "notion-types";
6657
- import { getBlockValue as getBlockValue7 } from "notion-utils";
6737
+ import { getBlockValue as getBlockValue8 } from "notion-utils";
6658
6738
  import { jsx as jsx57, jsxs as jsxs19 } from "react/jsx-runtime";
6659
6739
  var defaultBlockIds3 = [];
6660
6740
  function CollectionViewList({
@@ -6690,7 +6770,7 @@ function List({
6690
6770
  const { components, recordMap, mapPageUrl } = useNotionContext();
6691
6771
  return /* @__PURE__ */ jsx57("div", { className: "notion-list-collection", children: /* @__PURE__ */ jsx57("div", { className: "notion-list-view", children: /* @__PURE__ */ jsx57("div", { className: "notion-list-body", children: blockIds == null ? void 0 : blockIds.map((blockId) => {
6692
6772
  var _a, _b, _c;
6693
- const block = getBlockValue7(recordMap.block[blockId]);
6773
+ const block = getBlockValue8(recordMap.block[blockId]);
6694
6774
  if (!block) return null;
6695
6775
  const titleSchema = collection.schema.title;
6696
6776
  const titleData = (_a = block == null ? void 0 : block.properties) == null ? void 0 : _a.title;
@@ -6752,7 +6832,7 @@ function List({
6752
6832
  }
6753
6833
 
6754
6834
  // src/third-party/collection-view-table.tsx
6755
- import { getBlockValue as getBlockValue8 } from "notion-utils";
6835
+ import { getBlockValue as getBlockValue9 } from "notion-utils";
6756
6836
 
6757
6837
  // src/third-party/react-use.ts
6758
6838
  import {
@@ -6991,7 +7071,7 @@ function Table({
6991
7071
  /* @__PURE__ */ jsx58("div", { className: "notion-table-body", children: blockIds == null ? void 0 : blockIds.map((blockId) => /* @__PURE__ */ jsx58("div", { className: "notion-table-row", children: properties.map((p) => {
6992
7072
  var _a2, _b;
6993
7073
  const schema = (_a2 = collection.schema) == null ? void 0 : _a2[p.property];
6994
- const block = getBlockValue8(recordMap.block[blockId]);
7074
+ const block = getBlockValue9(recordMap.block[blockId]);
6995
7075
  const data = (_b = block == null ? void 0 : block.properties) == null ? void 0 : _b[p.property];
6996
7076
  const isTitle = p.property === "title";
6997
7077
  const style = {};
@@ -7041,6 +7121,11 @@ function CollectionViewImpl(props) {
7041
7121
  case "board":
7042
7122
  return /* @__PURE__ */ jsx59(CollectionViewBoard, { ...props });
7043
7123
  case "calendar":
7124
+ if (typeof window !== "undefined") {
7125
+ console.log("[Calendar] view selected, rendering");
7126
+ fetch("http://127.0.0.1:7682/ingest/84ddabf3-24ba-497f-b790-14e045db9106", { method: "POST", headers: { "Content-Type": "application/json", "X-Debug-Session-Id": "764ae3" }, body: JSON.stringify({ sessionId: "764ae3", location: "collection-view.tsx:calendar", message: "calendar view selected", data: {}, timestamp: Date.now(), hypothesisId: "H2" }) }).catch(() => {
7127
+ });
7128
+ }
7044
7129
  return /* @__PURE__ */ jsx59(CollectionViewCalendar, { ...props });
7045
7130
  default:
7046
7131
  console.warn("unsupported collection view", collectionView);
@@ -7083,7 +7168,7 @@ function CollectionViewBlock({
7083
7168
  block,
7084
7169
  className
7085
7170
  }) {
7086
- var _a, _b, _c;
7171
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
7087
7172
  const { recordMap, showCollectionViewDropdown } = useNotionContext();
7088
7173
  const { view_ids: viewIds } = block;
7089
7174
  const collectionId = getBlockCollectionId(block, recordMap);
@@ -7110,12 +7195,24 @@ function CollectionViewBlock({
7110
7195
  if (isServer2) {
7111
7196
  windowWidth = 1024;
7112
7197
  }
7113
- const collection = getBlockValue9(recordMap.collection[collectionId]);
7114
- const collectionView = getBlockValue9(
7198
+ const collection = getBlockValue10(recordMap.collection[collectionId]);
7199
+ const collectionView = getBlockValue10(
7115
7200
  recordMap.collection_view[collectionViewId]
7116
7201
  );
7117
7202
  const rawCollectionData = (_a = recordMap.collection_query[collectionId]) == null ? void 0 : _a[collectionViewId];
7118
- const collectionData = (_b = rawCollectionData == null ? void 0 : rawCollectionData.reducerResults) != null ? _b : rawCollectionData;
7203
+ const unwrapped = rawCollectionData && typeof rawCollectionData === "object" && "value" in rawCollectionData ? rawCollectionData.value : rawCollectionData;
7204
+ const reducer = unwrapped == null ? void 0 : unwrapped.reducerResults;
7205
+ const collectionData = reducer && typeof reducer === "object" ? {
7206
+ ...reducer,
7207
+ collection_group_results: (_b = unwrapped == null ? void 0 : unwrapped.collection_group_results) != null ? _b : reducer == null ? void 0 : reducer.collection_group_results,
7208
+ blockIds: (_e = (_d = unwrapped == null ? void 0 : unwrapped.blockIds) != null ? _d : (_c = reducer == null ? void 0 : reducer.collection_group_results) == null ? void 0 : _c.blockIds) != null ? _e : unwrapped == null ? void 0 : unwrapped.blockIds
7209
+ } : unwrapped;
7210
+ if (typeof window !== "undefined" && (collectionView == null ? void 0 : collectionView.type) === "calendar") {
7211
+ const len = (_j = (_i = (_g = (_f = collectionData == null ? void 0 : collectionData.collection_group_results) == null ? void 0 : _f.blockIds) == null ? void 0 : _g.length) != null ? _i : (_h = collectionData == null ? void 0 : collectionData.blockIds) == null ? void 0 : _h.length) != null ? _j : 0;
7212
+ console.log("[Collection] calendar view", { viewType: collectionView.type, blockIdsLength: len });
7213
+ fetch("http://127.0.0.1:7682/ingest/84ddabf3-24ba-497f-b790-14e045db9106", { method: "POST", headers: { "Content-Type": "application/json", "X-Debug-Session-Id": "764ae3" }, body: JSON.stringify({ sessionId: "764ae3", location: "collection.tsx:calendar", message: "calendar view", data: { viewType: collectionView == null ? void 0 : collectionView.type, blockIdsLength: len }, timestamp: Date.now(), hypothesisId: "H1" }) }).catch(() => {
7214
+ });
7215
+ }
7119
7216
  const parentPage = getBlockParentPage2(block, recordMap);
7120
7217
  const { width, padding } = React22.useMemo(() => {
7121
7218
  var _a2;
@@ -7155,7 +7252,7 @@ function CollectionViewBlock({
7155
7252
  return null;
7156
7253
  }
7157
7254
  const title = getTextContent4(collection.name).trim();
7158
- const showTitle = ((_c = block.format) == null ? void 0 : _c.hide_inline_collection_name) !== true;
7255
+ const showTitle = ((_k = block.format) == null ? void 0 : _k.hide_inline_collection_name) !== true;
7159
7256
  if (collection.icon) {
7160
7257
  block.format = {
7161
7258
  ...block.format,
@@ -7213,7 +7310,7 @@ function CollectionViewTabs({
7213
7310
  children: /* @__PURE__ */ jsx60(
7214
7311
  CollectionViewColumnDesc,
7215
7312
  {
7216
- collectionView: getBlockValue9(recordMap.collection_view[viewId])
7313
+ collectionView: getBlockValue10(recordMap.collection_view[viewId])
7217
7314
  }
7218
7315
  )
7219
7316
  },