microboard-temp 0.13.79 → 0.13.80

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/cjs/node.js CHANGED
@@ -3638,6 +3638,8 @@ var init_Settings = __esm(() => {
3638
3638
  getDPI: () => 1,
3639
3639
  reactEditorFocus: () => {},
3640
3640
  reactEditorToSlatePoint: () => null,
3641
+ onAuthInvalid: async () => false,
3642
+ onAuthTerminalFailure: () => {},
3641
3643
  planNames: {
3642
3644
  basic: "Basic",
3643
3645
  plus: "Plus",
@@ -14452,6 +14454,11 @@ class Events {
14452
14454
  getOpKey(op) {
14453
14455
  return op.method;
14454
14456
  }
14457
+ refreshIdentity() {
14458
+ const sessionId = this.getSessionId();
14459
+ const authorUserId = this.getAuthorUserId();
14460
+ this.log.refreshUnconfirmedIdentity(sessionId, authorUserId);
14461
+ }
14455
14462
  getSessionId() {
14456
14463
  return getConnectionSessionId(this.connection);
14457
14464
  }
@@ -31962,7 +31969,32 @@ var init_setLink = __esm(() => {
31962
31969
 
31963
31970
  // src/Items/RichText/editorHelpers/common/getSelectionMarks.ts
31964
31971
  function getSelectionMarks(editor) {
31965
- return import_slate41.Editor.marks(editor);
31972
+ const marks = import_slate41.Editor.marks(editor);
31973
+ if (!editor.selection) {
31974
+ return marks;
31975
+ }
31976
+ if (!import_slate41.Range.isExpanded(editor.selection) || marks && Object.keys(marks).length > 0) {
31977
+ return marks;
31978
+ }
31979
+ const textEntries = Array.from(import_slate41.Editor.nodes(editor, {
31980
+ at: editor.selection,
31981
+ match: (node) => import_slate41.Text.isText(node)
31982
+ }));
31983
+ const [firstEntry, ...restEntries] = textEntries;
31984
+ if (!firstEntry) {
31985
+ return marks;
31986
+ }
31987
+ const { text: _firstText, ...firstMarks } = firstEntry[0];
31988
+ const commonMarks = { ...firstMarks };
31989
+ for (const [node] of restEntries) {
31990
+ const { text: _text, ...nodeMarks } = node;
31991
+ for (const key of Object.keys(commonMarks)) {
31992
+ if (commonMarks[key] !== nodeMarks[key]) {
31993
+ delete commonMarks[key];
31994
+ }
31995
+ }
31996
+ }
31997
+ return commonMarks;
31966
31998
  }
31967
31999
  var import_slate41;
31968
32000
  var init_getSelectionMarks = __esm(() => {
@@ -41914,7 +41946,14 @@ function setSelectionFontSize(editor, isAutosize, fontSize, selectionContext) {
41914
41946
  shouldUpdateElement = true;
41915
41947
  }
41916
41948
  } else {
41917
- import_slate52.Editor.addMark(editor, "fontSize", size);
41949
+ if (editor.selection && import_slate52.Range.isExpanded(editor.selection)) {
41950
+ import_slate52.Transforms.setNodes(editor, { fontSize: size }, {
41951
+ match: (n) => import_slate52.Text.isText(n),
41952
+ split: true
41953
+ });
41954
+ } else {
41955
+ import_slate52.Editor.addMark(editor, "fontSize", size);
41956
+ }
41918
41957
  }
41919
41958
  }
41920
41959
  if (selectionContext === "EditTextUnderPointer") {
@@ -41994,7 +42033,14 @@ function setSelectionFontColor(editor, format, selectionContext) {
41994
42033
  return;
41995
42034
  }
41996
42035
  if (marks.fontColor !== format) {
41997
- import_slate54.Editor.addMark(editor, "fontColor", format);
42036
+ if (editor.selection && import_slate54.Range.isExpanded(editor.selection)) {
42037
+ import_slate54.Transforms.setNodes(editor, { fontColor: format }, {
42038
+ match: (n) => import_slate54.Text.isText(n),
42039
+ split: true
42040
+ });
42041
+ } else {
42042
+ import_slate54.Editor.addMark(editor, "fontColor", format);
42043
+ }
41998
42044
  }
41999
42045
  if (selectionContext === "EditTextUnderPointer") {
42000
42046
  try {
@@ -42545,7 +42591,14 @@ function applySelectionFontColor(editor, fontColor) {
42545
42591
  if (!marks) {
42546
42592
  return;
42547
42593
  }
42548
- import_slate56.Editor.addMark(editor, "fontColor", fontColor);
42594
+ if (editor.selection && import_slate56.Range.isExpanded(editor.selection)) {
42595
+ import_slate56.Transforms.setNodes(editor, { fontColor }, {
42596
+ match: (n) => import_slate56.Text.isText(n),
42597
+ split: true
42598
+ });
42599
+ } else {
42600
+ import_slate56.Editor.addMark(editor, "fontColor", fontColor);
42601
+ }
42549
42602
  }
42550
42603
  var import_slate56;
42551
42604
  var init_applySelectionFontColor = __esm(() => {
@@ -42573,7 +42626,14 @@ function applySelectionFontSize(editor, fontSize, selectionContext) {
42573
42626
  focus: import_slate57.Editor.end(editor, [])
42574
42627
  });
42575
42628
  }
42576
- import_slate57.Editor.addMark(editor, "fontSize", size);
42629
+ if (editor.selection && import_slate57.Range.isExpanded(editor.selection)) {
42630
+ import_slate57.Transforms.setNodes(editor, { fontSize: size }, {
42631
+ match: (n) => import_slate57.Text.isText(n),
42632
+ split: true
42633
+ });
42634
+ } else {
42635
+ import_slate57.Editor.addMark(editor, "fontSize", size);
42636
+ }
42577
42637
  if (selectionContext === "EditTextUnderPointer") {}
42578
42638
  }
42579
42639
  var import_slate57;
@@ -44241,6 +44301,35 @@ var init_Audio = __esm(() => {
44241
44301
  };
44242
44302
  });
44243
44303
 
44304
+ // src/api/AuthRequest.ts
44305
+ async function authenticatedFetch(url2, init2 = {}, boardId) {
44306
+ const getAuthInit = (originalInit) => {
44307
+ const token = conf.getAccessToken();
44308
+ if (!token) {
44309
+ return originalInit;
44310
+ }
44311
+ const headers = new Headers(originalInit.headers);
44312
+ headers.set("Authorization", `Bearer ${token}`);
44313
+ return { ...originalInit, headers };
44314
+ };
44315
+ let response = await fetch(url2, getAuthInit(init2));
44316
+ if (response.status === 401) {
44317
+ const body = await response.clone().json().catch(() => ({}));
44318
+ if (body.code === "AUTH_INVALID_ACCESS_TOKEN") {
44319
+ const refreshed = await conf.onAuthInvalid(boardId);
44320
+ if (refreshed) {
44321
+ response = await fetch(url2, getAuthInit(init2));
44322
+ } else {
44323
+ conf.onAuthTerminalFailure(boardId, body.code);
44324
+ }
44325
+ }
44326
+ }
44327
+ return response;
44328
+ }
44329
+ var init_AuthRequest = __esm(() => {
44330
+ init_Settings();
44331
+ });
44332
+
44244
44333
  // src/api/MediaHelpers.ts
44245
44334
  function getAccessTypeFromUrl(url2) {
44246
44335
  try {
@@ -44258,15 +44347,14 @@ function getAccessTypeFromUrl(url2) {
44258
44347
  }
44259
44348
  return null;
44260
44349
  }
44261
- var uploadSvgDirectly = async (blob, accessToken, boardId, baseUrl) => {
44262
- const response = await fetch(`${baseUrl || ""}/svg/${boardId}`, {
44350
+ var uploadSvgDirectly = async (blob, boardId, baseUrl) => {
44351
+ const response = await authenticatedFetch(`${baseUrl || ""}/svg/${boardId}`, {
44263
44352
  method: "POST",
44264
44353
  headers: {
44265
- "Content-Type": "image/svg+xml",
44266
- Authorization: `Bearer ${accessToken}`
44354
+ "Content-Type": "image/svg+xml"
44267
44355
  },
44268
44356
  body: blob
44269
- });
44357
+ }, boardId);
44270
44358
  if (!response.ok) {
44271
44359
  conf.hooks.onUploadMediaError(response, "image");
44272
44360
  throw new Error(`Failed to upload SVG. Status: ${response.status}`);
@@ -44276,19 +44364,18 @@ var uploadSvgDirectly = async (blob, accessToken, boardId, baseUrl) => {
44276
44364
  throw new Error("Server did not provide a key for the uploaded SVG.");
44277
44365
  }
44278
44366
  return data.url;
44279
- }, uploadWithPresignedUrl = async (blob, accessToken, boardId, type, baseUrl) => {
44280
- const generateUrlResponse = await fetch(`${baseUrl || ""}/media/upload`, {
44367
+ }, uploadWithPresignedUrl = async (blob, boardId, type, baseUrl) => {
44368
+ const generateUrlResponse = await authenticatedFetch(`${baseUrl || ""}/media/upload`, {
44281
44369
  method: "POST",
44282
44370
  headers: {
44283
- "Content-Type": "application/json",
44284
- Authorization: `Bearer ${accessToken}`
44371
+ "Content-Type": "application/json"
44285
44372
  },
44286
44373
  body: JSON.stringify({
44287
44374
  fileSize: blob.size,
44288
44375
  fileType: blob.type,
44289
44376
  boardId
44290
44377
  })
44291
- });
44378
+ }, boardId);
44292
44379
  if (!generateUrlResponse.ok) {
44293
44380
  conf.hooks.onUploadMediaError(generateUrlResponse, type);
44294
44381
  throw new Error(`Failed to get presigned URL. Status: ${generateUrlResponse.status}`);
@@ -44310,18 +44397,18 @@ var uploadSvgDirectly = async (blob, accessToken, boardId, baseUrl) => {
44310
44397
  throw new Error(`Direct upload to storage failed. Status: ${uploadResponse.status}`);
44311
44398
  }
44312
44399
  return url2;
44313
- }, uploadMediaToStorage = async (blob, accessToken, boardId, type, baseUrl) => {
44400
+ }, uploadMediaToStorage = async (blob, boardId, type, baseUrl) => {
44314
44401
  try {
44315
44402
  if (blob.type === "image/svg+xml") {
44316
- return await uploadSvgDirectly(blob, accessToken, boardId, baseUrl);
44403
+ return await uploadSvgDirectly(blob, boardId, baseUrl);
44317
44404
  } else {
44318
- return await uploadWithPresignedUrl(blob, accessToken, boardId, type, baseUrl);
44405
+ return await uploadWithPresignedUrl(blob, boardId, type, baseUrl);
44319
44406
  }
44320
44407
  } catch (error48) {
44321
44408
  console.error("Media upload process error:", error48);
44322
44409
  throw error48;
44323
44410
  }
44324
- }, getMediaSignedUrl = async (url2, accessToken) => {
44411
+ }, getMediaSignedUrl = async (url2) => {
44325
44412
  const accessType = getAccessTypeFromUrl(url2);
44326
44413
  if (!accessType) {
44327
44414
  return null;
@@ -44329,15 +44416,9 @@ var uploadSvgDirectly = async (blob, accessToken, boardId, baseUrl) => {
44329
44416
  if (accessType === "anonymous") {
44330
44417
  return url2;
44331
44418
  }
44332
- if (!accessToken) {
44333
- return null;
44334
- }
44335
44419
  try {
44336
- const response = await fetch(url2, {
44337
- method: "GET",
44338
- headers: {
44339
- Authorization: `Bearer ${accessToken}`
44340
- }
44420
+ const response = await authenticatedFetch(url2, {
44421
+ method: "GET"
44341
44422
  });
44342
44423
  if (!response.ok) {
44343
44424
  console.error("Failed to get media signed url:", response.status, response.statusText);
@@ -44352,15 +44433,16 @@ var uploadSvgDirectly = async (blob, accessToken, boardId, baseUrl) => {
44352
44433
  };
44353
44434
  var init_MediaHelpers = __esm(() => {
44354
44435
  init_Settings();
44436
+ init_AuthRequest();
44355
44437
  });
44356
44438
 
44357
44439
  // src/Items/Audio/AudioHelpers.ts
44358
- var prepareAudio = (file2, accessToken, boardId, baseUrl) => {
44440
+ var prepareAudio = (file2, boardId, baseUrl) => {
44359
44441
  return new Promise((resolve, reject) => {
44360
44442
  const audio = document.createElement("audio");
44361
44443
  audio.src = URL.createObjectURL(file2);
44362
44444
  audio.onloadedmetadata = () => {
44363
- uploadMediaToStorage(file2, accessToken, boardId, "audio", baseUrl).then((url2) => {
44445
+ uploadMediaToStorage(file2, boardId, "audio", baseUrl).then((url2) => {
44364
44446
  resolve(url2);
44365
44447
  }).catch(reject);
44366
44448
  };
@@ -62887,7 +62969,7 @@ var init_Video = __esm(() => {
62887
62969
  async setPreviewUrl(url2) {
62888
62970
  if (this.isStorageUrl) {
62889
62971
  try {
62890
- this.preview.src = await getMediaSignedUrl(url2, this.board.getAccount()?.accessToken || null) || "";
62972
+ this.preview.src = await getMediaSignedUrl(url2) || "";
62891
62973
  } catch (err) {
62892
62974
  console.error(err);
62893
62975
  this.onError();
@@ -63247,9 +63329,9 @@ var getBlobFromDataURL = (dataURL) => {
63247
63329
  };
63248
63330
  }
63249
63331
  });
63250
- }, prepareImage = (inp, accessToken, boardId, baseUrl) => resizeAndConvertToPng(inp).then(({ width: width2, height: height2, dataURL, hash: hash2 }) => {
63332
+ }, prepareImage = (inp, boardId, baseUrl) => resizeAndConvertToPng(inp).then(({ width: width2, height: height2, dataURL, hash: hash2 }) => {
63251
63333
  const { blob, mimeType } = getBlobFromDataURL(dataURL);
63252
- return uploadMediaToStorage(blob, accessToken, boardId, "image", baseUrl).then((src) => {
63334
+ return uploadMediaToStorage(blob, boardId, "image", baseUrl).then((src) => {
63253
63335
  return {
63254
63336
  imageDimension: { width: width2, height: height2 },
63255
63337
  base64: dataURL,
@@ -63290,15 +63372,15 @@ var getVideoMetadata = (file2) => {
63290
63372
  board.selection.add(boardVideo);
63291
63373
  onLoadCb(boardVideo);
63292
63374
  });
63293
- }, prepareVideo = (file2, accessToken, boardId, baseUrl) => {
63375
+ }, prepareVideo = (file2, boardId, baseUrl) => {
63294
63376
  return new Promise((resolve2, reject) => {
63295
63377
  const video = document.createElement("video");
63296
63378
  video.src = URL.createObjectURL(file2);
63297
63379
  video.onloadedmetadata = () => {
63298
63380
  video.onseeked = () => {
63299
63381
  video.onseeked = null;
63300
- prepareImage(captureFrame(0.1, video)?.src, accessToken, boardId, baseUrl).then((imageData) => {
63301
- uploadMediaToStorage(file2, accessToken, boardId, "video", baseUrl).then((url2) => {
63382
+ prepareImage(captureFrame(0.1, video)?.src, boardId, baseUrl).then((imageData) => {
63383
+ uploadMediaToStorage(file2, boardId, "video", baseUrl).then((url2) => {
63302
63384
  resolve2({
63303
63385
  url: url2,
63304
63386
  previewUrl: imageData.storageLink
@@ -69286,8 +69368,8 @@ var init_Card = __esm(() => {
69286
69368
  async createImages() {
69287
69369
  this.face = conf.documentFactory.createElement("img");
69288
69370
  this.backside = conf.documentFactory.createElement("img");
69289
- this.face.src = await getMediaSignedUrl(this.faceUrl, this.board.getAccount()?.accessToken || null) || "";
69290
- this.backside.src = await getMediaSignedUrl(this.backsideUrl, this.board.getAccount()?.accessToken || null) || "";
69371
+ this.face.src = await getMediaSignedUrl(this.faceUrl) || "";
69372
+ this.backside.src = await getMediaSignedUrl(this.backsideUrl) || "";
69291
69373
  this.face.onload = () => {
69292
69374
  this.subject.publish(this);
69293
69375
  };
@@ -69988,7 +70070,7 @@ var init_Dice = __esm(() => {
69988
70070
  this.renderValues[index2] = value;
69989
70071
  } else {
69990
70072
  const image2 = conf.documentFactory.createElement("img");
69991
- image2.src = await getMediaSignedUrl(value, this.board.getAccount()?.accessToken || null) || "";
70073
+ image2.src = await getMediaSignedUrl(value) || "";
69992
70074
  this.renderValues[index2] = image2;
69993
70075
  image2.onload = () => {
69994
70076
  this.subject.publish(this);
@@ -70443,7 +70525,7 @@ var init_Screen = __esm(() => {
70443
70525
  this.backgroundUrl = url2 || "";
70444
70526
  if (url2) {
70445
70527
  this.backgroundImage = conf.documentFactory.createElement("img");
70446
- this.backgroundImage.src = await getMediaSignedUrl(url2, this.board.getAccount()?.accessToken || null) || "";
70528
+ this.backgroundImage.src = await getMediaSignedUrl(url2) || "";
70447
70529
  this.applyBackgroundColor("none");
70448
70530
  this.backgroundImage.onload = () => {
70449
70531
  this.subject.publish(this);
@@ -72305,7 +72387,7 @@ var init_Image = __esm(() => {
72305
72387
  }
72306
72388
  async setStorageLink(link2) {
72307
72389
  this.storageLink = link2;
72308
- this.signedUrl = await getMediaSignedUrl(link2, this.board.getAccount()?.accessToken || null) || "";
72390
+ this.signedUrl = await getMediaSignedUrl(link2) || "";
72309
72391
  if (!this.signedUrl) {
72310
72392
  const canvas = conf.documentFactory.createElement("canvas");
72311
72393
  canvas.width = 100;
@@ -72726,7 +72808,7 @@ function handleAudioGenerate(response, board) {
72726
72808
  }
72727
72809
  function handleImageGenerate(response, board) {
72728
72810
  if (response.status === "completed" && response.base64) {
72729
- prepareImage(response.base64, conf.getAccessToken(), board.getBoardId()).then((imageData) => {
72811
+ prepareImage(response.base64, board.getBoardId()).then((imageData) => {
72730
72812
  const placeholderId = board.aiImagePlaceholder?.getId();
72731
72813
  if (placeholderId) {
72732
72814
  const placeholderNode = board.items.getById(placeholderId);