@agent-native/core-corpus 0.229.0-nightly-20261116182708 → 0.229.0
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/corpus/README.md +1 -1
- package/corpus/templates/analytics/CHANGELOG.md +13 -34
- package/corpus/templates/clips/CHANGELOG.md +9 -25
- package/corpus/templates/content/CHANGELOG.md +31 -20
- package/corpus/templates/content/app/components/editor/VisualEditor.tsx +58 -3
- package/corpus/templates/content/app/components/editor/spreadsheet-clipboard.ts +230 -0
- package/corpus/templates/design/CHANGELOG.md +53 -120
- package/corpus/templates/dispatch/CHANGELOG.md +6 -0
- package/corpus/templates/mail/CHANGELOG.md +24 -0
- package/corpus/templates/slides/CHANGELOG.md +7 -6
- package/package.json +1 -1
- package/corpus/templates/analytics/.deploy-tmp/agent-native-provided-plugins.mjs +0 -10
- package/corpus/templates/assets/.deploy-tmp/agent-native-provided-plugins.mjs +0 -10
- package/corpus/templates/brain/.deploy-tmp/agent-native-provided-plugins.mjs +0 -10
- package/corpus/templates/calendar/.deploy-tmp/agent-native-provided-plugins.mjs +0 -10
- package/corpus/templates/chat/.deploy-tmp/agent-native-provided-plugins.mjs +0 -10
- package/corpus/templates/clips/.deploy-tmp/agent-native-provided-plugins.mjs +0 -10
- package/corpus/templates/content/.deploy-tmp/agent-native-provided-plugins.mjs +0 -10
- package/corpus/templates/crm/.deploy-tmp/agent-native-provided-plugins.mjs +0 -10
- package/corpus/templates/design/.deploy-tmp/agent-native-provided-plugins.mjs +0 -10
- package/corpus/templates/design/.generated/bridge/native-builtin-metadata.generated.ts +0 -326
- package/corpus/templates/design/.generated/bridge/native-worker-source.generated.ts +0 -6
- package/corpus/templates/dispatch/.deploy-tmp/agent-native-provided-plugins.mjs +0 -10
- package/corpus/templates/forms/.deploy-tmp/agent-native-provided-plugins.mjs +0 -10
- package/corpus/templates/mail/.deploy-tmp/agent-native-provided-plugins.mjs +0 -10
- package/corpus/templates/plan/.deploy-tmp/agent-native-provided-plugins.mjs +0 -10
- package/corpus/templates/slides/.deploy-tmp/agent-native-provided-plugins.mjs +0 -10
package/corpus/README.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
All notable user-facing changes to Agent-Native Analytics are documented here. Open it any
|
|
4
4
|
time from the command menu (Cmd+K → "What's new") or from Settings.
|
|
5
5
|
|
|
6
|
+
## 2026-11-14
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- Clicking a chart's "No value" point no longer opens an empty records list. Panels whose record query handles a missing x value open those records, and the rest show the chart's rows with a note.
|
|
11
|
+
- Shared settings migrations now refresh open analytics views when they finish.
|
|
12
|
+
|
|
13
|
+
## 2026-11-13
|
|
14
|
+
|
|
15
|
+
### Improved
|
|
16
|
+
|
|
17
|
+
- Dashboard panel descriptions stay condensed to a single subtext line by default and expand on click.
|
|
18
|
+
|
|
6
19
|
## 2026-11-10
|
|
7
20
|
|
|
8
21
|
### Fixed
|
|
@@ -1491,38 +1504,4 @@ time from the command menu (Cmd+K → "What's new") or from Settings.
|
|
|
1491
1504
|
- Agent chat can keep working through longer data queries instead of stopping mid-action.
|
|
1492
1505
|
- Session replay playback now preserves the initial page snapshot when an upload needs to retry.
|
|
1493
1506
|
|
|
1494
|
-
## 2026-07-01
|
|
1495
|
-
|
|
1496
|
-
### Added
|
|
1497
|
-
|
|
1498
|
-
- Analytics can now notify inbox, email, Slack, or webhook channels when first-party events spike.
|
|
1499
|
-
|
|
1500
|
-
### Improved
|
|
1501
|
-
|
|
1502
|
-
- Dashboard filters take less space and keep view actions tucked to the side.
|
|
1503
|
-
- Analytics chat responses stream more smoothly during long background runs and guarded final answers.
|
|
1504
|
-
|
|
1505
|
-
### Fixed
|
|
1506
|
-
|
|
1507
|
-
- Dashboard charts no longer show future dates when clients send bad event timestamps.
|
|
1508
|
-
- Session replay recordings upload reliably in production.
|
|
1509
|
-
- Session replay playback keeps rrweb's inlined stylesheet snapshots while stripping live resource loads, reducing blank replay frames for captured pages with external CSS.
|
|
1510
|
-
- Session replays load large production recordings from scoped chunks instead of truncating playback.
|
|
1511
|
-
- Session replays now play back in production instead of showing a blank recording, because chunk downloads no longer rely on a manual gzip content-encoding that serverless hosts corrupted.
|
|
1512
|
-
|
|
1513
|
-
## 2026-06-30
|
|
1514
|
-
|
|
1515
|
-
### Improved
|
|
1516
|
-
|
|
1517
|
-
- Ask opens a fresh chat unless you were just chatting, and dashboard navigation keeps the sidebar closed from an empty Ask state.
|
|
1518
|
-
- Dashboard toolbar controls use a quieter share button and vertical actions menu.
|
|
1519
|
-
- Session replay rows show whole-minute durations in the playlist.
|
|
1520
|
-
|
|
1521
|
-
### Fixed
|
|
1522
|
-
|
|
1523
|
-
- Dashboard charts now use theme-aware tooltip and grid colors in light and dark mode.
|
|
1524
|
-
- Dashboard email reports are more reliable and use cleaner header copy.
|
|
1525
|
-
- Fixed Ask composer spacing so the chat field has a comfortable side inset.
|
|
1526
|
-
- Session replays now render captured styling and keep the event timeline out of compact layouts.
|
|
1527
|
-
|
|
1528
1507
|
For the full list of updates, see the [changelog folder](./changelog/).
|
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
All notable user-facing changes to Clips are documented here. Open it any time
|
|
4
4
|
from the command menu (Cmd+K → "What's new") or from Settings.
|
|
5
5
|
|
|
6
|
+
## 2026-11-13
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
|
|
10
|
+
- Fixed a navigation error when leaving an active recording.
|
|
11
|
+
- Recording recovery reminders now follow the selected interface language.
|
|
12
|
+
|
|
6
13
|
## 2026-11-12
|
|
7
14
|
|
|
8
15
|
### Improved
|
|
@@ -11,6 +18,7 @@ from the command menu (Cmd+K → "What's new") or from Settings.
|
|
|
11
18
|
|
|
12
19
|
### Fixed
|
|
13
20
|
|
|
21
|
+
- The Labs tab in Clips desktop Settings now stays open instead of jumping back to General.
|
|
14
22
|
- Recordings now retry automatically when the upload service has a brief hiccup at the start or end of an upload, instead of failing.
|
|
15
23
|
|
|
16
24
|
## 2026-11-10
|
|
@@ -49,6 +57,7 @@ from the command menu (Cmd+K → "What's new") or from Settings.
|
|
|
49
57
|
|
|
50
58
|
### Fixed
|
|
51
59
|
|
|
60
|
+
- Navigation requests now clearly require a destination.
|
|
52
61
|
- Chrome extension: the popup now switches to Record as soon as sign-in completes, and the website shows an error if the extension handoff fails.
|
|
53
62
|
|
|
54
63
|
## 2026-11-05
|
|
@@ -1436,29 +1445,4 @@ from the command menu (Cmd+K → "What's new") or from Settings.
|
|
|
1436
1445
|
|
|
1437
1446
|
Raw Rewind recordings and the complete local index remain on the Mac. The old Private versus Cloud-assisted mode gate has been removed; the boundary is now the bounded request and, for media, the private Clip handoff.
|
|
1438
1447
|
|
|
1439
|
-
## 2026-07-16
|
|
1440
|
-
|
|
1441
|
-
### Added
|
|
1442
|
-
|
|
1443
|
-
- Organization admins can choose the default visibility for new recordings.
|
|
1444
|
-
|
|
1445
|
-
### Improved
|
|
1446
|
-
|
|
1447
|
-
- Camera bubble hover controls now appear above the face so it can rest flush near the bottom of the screen.
|
|
1448
|
-
- Clips search now matches recording content without requiring exact letter case.
|
|
1449
|
-
- Remove Silences now shows queued, active, completed, and failed progress on the recording page.
|
|
1450
|
-
- Settings no longer repeats the Builder connection status in multiple setup cards.
|
|
1451
|
-
- The desktop app button now shows "Open desktop app" and launches the installed app instead of re-downloading once you've downloaded it.
|
|
1452
|
-
|
|
1453
|
-
### Fixed
|
|
1454
|
-
|
|
1455
|
-
- Authorized viewers can open shared private clips without a misleading sign-in detour.
|
|
1456
|
-
- Chrome extension recordings no longer leave a stale recorder state blocking the next start after a failed launch.
|
|
1457
|
-
- Clips agent chat now stays inline with the recording tabs without a separate Chat or Workspace header.
|
|
1458
|
-
- Meetings you decline no longer trigger Clips desktop reminders.
|
|
1459
|
-
- Failed or delayed desktop saves now reopen Clips with the saved local copy visible in every view, including Settings.
|
|
1460
|
-
- Long desktop Clips now preserve complete playback, synced audio, full transcripts, and local recovery copies until upload verification succeeds.
|
|
1461
|
-
- Long recording lists keep Stitch actions and selected-library actions visible.
|
|
1462
|
-
- Transcripts now appear from native browser speech sooner, with automatic recovery when transcription stalls.
|
|
1463
|
-
|
|
1464
1448
|
For the full list of updates, see the [changelog folder](./changelog/).
|
|
@@ -3,6 +3,35 @@
|
|
|
3
3
|
All notable user-facing changes to Agent-Native Content are documented here. Open it any
|
|
4
4
|
time from the command menu (Cmd+K → "What's new").
|
|
5
5
|
|
|
6
|
+
## 2026-11-14
|
|
7
|
+
|
|
8
|
+
### Improved
|
|
9
|
+
|
|
10
|
+
- The command menu (Cmd+K) now opens as a short list for the page you're on: search inside it, copy its link, pin it, move it or add a sub-page, followed by your recent pages. Start typing and it widens into search, with filters and a preview of the highlighted result. Before you type, press Tab to search only the open page; Backspace goes back to the whole workspace. When nothing fits, the last row asks the agent.
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- A comment whose text was deleted no longer jumps to the same words somewhere else on the page. It shows Highlight unavailable with its quote, unless the text around those words matches what was around the comment's own, as when the paragraph was moved.
|
|
15
|
+
- Personal database view updates now refresh for the account that owns them.
|
|
16
|
+
|
|
17
|
+
## 2026-11-11
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- Mermaid code blocks now show their drawn diagram; click the diagram to edit its source and watch it redraw as you type.
|
|
22
|
+
|
|
23
|
+
### Improved
|
|
24
|
+
|
|
25
|
+
- People who can view or comment on a collection now get each row's ⋯ menu, with Open page, Copy link and, for commenters, Comment.
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- A `<br>` typed in inline code now stays text after you save, instead of becoming a line break. Pages synced with Notion keep Notion's line breaks inside inline code, but a tag typed there still becomes a line break once it reaches Notion. On other pages, a line break saved inside inline code before this change now shows as the tag.
|
|
30
|
+
- A page whose unsaved changes can't be saved now opens and keeps those changes, instead of loading forever.
|
|
31
|
+
- The Files sidebar, the breadcrumb menu and the Move dialog stop showing a space's pages once you lose access to it, and wait for the app to confirm who's signed in before they read. The Move dialog also leaves out a page until its create has reached the server, so you can't pick a destination a move would fail to reach.
|
|
32
|
+
- Times Content's database fills in on its own now use the same format as every other time, so pages and rows sort in the right order by when they were created or edited.
|
|
33
|
+
- Typing -> or => inside code no longer turns into an arrow symbol, so Mermaid edges and code stay as typed.
|
|
34
|
+
|
|
6
35
|
## 2026-11-10
|
|
7
36
|
|
|
8
37
|
### Fixed
|
|
@@ -26,12 +55,14 @@ time from the command menu (Cmd+K → "What's new").
|
|
|
26
55
|
|
|
27
56
|
### Improved
|
|
28
57
|
|
|
58
|
+
- Moving a page to another workspace now brings the collections in it, with their rows, properties, values, row order and views, instead of refusing.
|
|
29
59
|
- Ask AI works on comments in every Blocks field tab, and its edits there are suggestions on that tab
|
|
30
60
|
- Builder sources now read and write only through your Builder.io connection, so deploy keys no longer reach them; the Builder docs sync still uses keys.
|
|
31
61
|
- Collection sort menus name each direction for the column's values: Old → new for dates, Low → high for numbers, A → Z for text, and Unchecked → checked for checkboxes.
|
|
32
62
|
|
|
33
63
|
### Fixed
|
|
34
64
|
|
|
65
|
+
- The agent links every page it creates in its reply.
|
|
35
66
|
- An open collection row page now updates when that row is edited elsewhere, such as by an agent or in another tab, and a retried row edit returns the first result instead of a conflict error
|
|
36
67
|
- Pages created over MCP now appear in the Files sidebar without a reload.
|
|
37
68
|
- Sorting a collection by a checkbox keeps empty boxes with the unchecked rows, and ascending lists unchecked rows first.
|
|
@@ -1280,24 +1311,4 @@ time from the command menu (Cmd+K → "What's new").
|
|
|
1280
1311
|
|
|
1281
1312
|
- The content header no longer shows the global notifications bell.
|
|
1282
1313
|
|
|
1283
|
-
## 2026-07-03
|
|
1284
|
-
|
|
1285
|
-
### Added
|
|
1286
|
-
|
|
1287
|
-
- Agent document edits now appear as a live collaborator — presence avatar, editing indicator, and a brief highlight on the changed text
|
|
1288
|
-
|
|
1289
|
-
### Improved
|
|
1290
|
-
|
|
1291
|
-
- Document search and list views load faster on large workspaces
|
|
1292
|
-
- Content error screens now include a feedback button with debug context and a prefilled GitHub issue fallback.
|
|
1293
|
-
|
|
1294
|
-
## 2026-07-02
|
|
1295
|
-
|
|
1296
|
-
### Fixed
|
|
1297
|
-
|
|
1298
|
-
- Builder source refreshes recover from stalled background row loading.
|
|
1299
|
-
- Builder-sourced database rows now open with sync protection immediately and keep source-field columns stable during background refreshes.
|
|
1300
|
-
- Database rows and pages open faster from recently loaded data.
|
|
1301
|
-
- Preview panels close reliably, narrow sidebar row actions stay reachable, and adding properties now shows progress.
|
|
1302
|
-
|
|
1303
1314
|
For the full list of updates, see the [changelog folder](./changelog/).
|
|
@@ -79,7 +79,7 @@ import {
|
|
|
79
79
|
TextSelection,
|
|
80
80
|
type Transaction,
|
|
81
81
|
} from "@tiptap/pm/state";
|
|
82
|
-
import { CellSelection, cellAround } from "@tiptap/pm/tables";
|
|
82
|
+
import { CellSelection, cellAround, isInTable } from "@tiptap/pm/tables";
|
|
83
83
|
import { Decoration, DecorationSet, type EditorView } from "@tiptap/pm/view";
|
|
84
84
|
import {
|
|
85
85
|
useEditor,
|
|
@@ -239,6 +239,13 @@ import {
|
|
|
239
239
|
} from "./live-body-parity";
|
|
240
240
|
import { imageDisplaySrc } from "./private-media-src";
|
|
241
241
|
import { SlashCommandMenu } from "./SlashCommandMenu";
|
|
242
|
+
import {
|
|
243
|
+
expandColumnSpans,
|
|
244
|
+
isSpreadsheetPicture,
|
|
245
|
+
parseSpreadsheetText,
|
|
246
|
+
spreadsheetTableSlice,
|
|
247
|
+
spreadsheetTextForSlice,
|
|
248
|
+
} from "./spreadsheet-clipboard";
|
|
242
249
|
import { StaticDocumentBody } from "./StaticDocumentBody";
|
|
243
250
|
import { suggestionPlacements } from "./suggestion-placement";
|
|
244
251
|
import { caretAfterPageSwap } from "./suggestions/keep-caret";
|
|
@@ -246,7 +253,10 @@ import {
|
|
|
246
253
|
resolveSuggestionPresentationRange,
|
|
247
254
|
type SuggestionPresentationTransition,
|
|
248
255
|
} from "./suggestions/presentation-rebase";
|
|
249
|
-
import {
|
|
256
|
+
import {
|
|
257
|
+
isSuggestingEdits,
|
|
258
|
+
SuggestingReadOnlyBlocks,
|
|
259
|
+
} from "./suggestions/read-only-blocks";
|
|
250
260
|
import { ContentTableView, contentTableColumnSizing } from "./table-view";
|
|
251
261
|
import { TableHoverControls } from "./TableHoverControls";
|
|
252
262
|
import { WidgetLoadDiagnostic } from "./WidgetLoadDiagnostic";
|
|
@@ -463,6 +473,14 @@ function dispatchLiteralPaste(view: EditorView, slice: Slice): void {
|
|
|
463
473
|
}
|
|
464
474
|
}
|
|
465
475
|
|
|
476
|
+
// A table for cells copied as tab-separated text. Suggesting can't add a
|
|
477
|
+
// table, so while suggesting the cells paste as text.
|
|
478
|
+
function spreadsheetTable(editor: CoreEditor, text: string): Slice | null {
|
|
479
|
+
if (isSuggestingEdits(editor.state)) return null;
|
|
480
|
+
const rows = parseSpreadsheetText(text);
|
|
481
|
+
return rows && spreadsheetTableSlice(editor.schema, rows);
|
|
482
|
+
}
|
|
483
|
+
|
|
466
484
|
const MarkdownPasteDetection = Extension.create({
|
|
467
485
|
name: "markdownPasteDetection",
|
|
468
486
|
addProseMirrorPlugins() {
|
|
@@ -471,8 +489,11 @@ const MarkdownPasteDetection = Extension.create({
|
|
|
471
489
|
new Plugin({
|
|
472
490
|
key: new PluginKey("markdownPasteDetection"),
|
|
473
491
|
props: {
|
|
492
|
+
transformPastedHTML: expandColumnSpans,
|
|
474
493
|
clipboardTextParser(text, _context, plainText) {
|
|
475
494
|
if (!plainText) {
|
|
495
|
+
const table = spreadsheetTable(editor, text);
|
|
496
|
+
if (table) return table;
|
|
476
497
|
const markdown = parseMarkdownClipboardSlice(
|
|
477
498
|
editor,
|
|
478
499
|
text,
|
|
@@ -482,6 +503,23 @@ const MarkdownPasteDetection = Extension.create({
|
|
|
482
503
|
}
|
|
483
504
|
return parsePlainTextClipboardSlice(editor, text, _context);
|
|
484
505
|
},
|
|
506
|
+
// A copied table, or cells of one, goes out as tab-separated text,
|
|
507
|
+
// which spreadsheets paste as cells; anything else as Markdown.
|
|
508
|
+
// This is the only copy serializer: tiptap-markdown's own copy
|
|
509
|
+
// transform is off, since its plugin would run ahead of this one.
|
|
510
|
+
clipboardTextSerializer(slice) {
|
|
511
|
+
const { serializer } = (
|
|
512
|
+
editor.storage as unknown as {
|
|
513
|
+
markdown: {
|
|
514
|
+
serializer: { serialize(content: Fragment): string };
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
).markdown;
|
|
518
|
+
return (
|
|
519
|
+
spreadsheetTextForSlice(slice, editor.schema) ??
|
|
520
|
+
serializer.serialize(slice.content)
|
|
521
|
+
);
|
|
522
|
+
},
|
|
485
523
|
handlePaste(view, event) {
|
|
486
524
|
const context = view.state.selection.$from;
|
|
487
525
|
const input = (
|
|
@@ -499,6 +537,18 @@ const MarkdownPasteDetection = Extension.create({
|
|
|
499
537
|
const html = clipboardData.getData("text/html");
|
|
500
538
|
const plainText = clipboardData.getData("text/plain");
|
|
501
539
|
|
|
540
|
+
// Cells copied as text alone. ProseMirror's table plugin fills a
|
|
541
|
+
// table at the caret from the table clipboardTextParser made;
|
|
542
|
+
// anywhere else the table goes in literally, so Markdown paste
|
|
543
|
+
// rules leave the cells' text as it was.
|
|
544
|
+
const table = html ? null : spreadsheetTable(editor, plainText);
|
|
545
|
+
if (table) {
|
|
546
|
+
if (isInTable(view.state)) return false;
|
|
547
|
+
event.preventDefault();
|
|
548
|
+
dispatchLiteralPaste(view, table);
|
|
549
|
+
return true;
|
|
550
|
+
}
|
|
551
|
+
|
|
502
552
|
if (!html && plainText && !looksLikeMarkdown(plainText)) {
|
|
503
553
|
const slice = parsePlainTextClipboardSlice(
|
|
504
554
|
editor,
|
|
@@ -3407,7 +3457,9 @@ export function createVisualEditorExtensions({
|
|
|
3407
3457
|
Markdown.configure({
|
|
3408
3458
|
html: true,
|
|
3409
3459
|
transformPastedText: false,
|
|
3410
|
-
|
|
3460
|
+
// MarkdownPasteDetection writes copied text, as Markdown or as
|
|
3461
|
+
// tab-separated cells.
|
|
3462
|
+
transformCopiedText: false,
|
|
3411
3463
|
}),
|
|
3412
3464
|
],
|
|
3413
3465
|
});
|
|
@@ -4488,6 +4540,9 @@ export function VisualEditor({
|
|
|
4488
4540
|
handlePaste(view, event) {
|
|
4489
4541
|
if (view.editable) markUserEditIntent();
|
|
4490
4542
|
if (!view.editable || !event.clipboardData) return false;
|
|
4543
|
+
// Excel puts a picture of the copied cells beside them: paste the
|
|
4544
|
+
// cells as a table, not the picture.
|
|
4545
|
+
if (isSpreadsheetPicture(event.clipboardData)) return false;
|
|
4491
4546
|
|
|
4492
4547
|
const imageFiles = getImageFiles(event.clipboardData.files);
|
|
4493
4548
|
const videoFiles = getVideoFiles(event.clipboardData.files);
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Fragment,
|
|
3
|
+
type Node as ProseMirrorNode,
|
|
4
|
+
type NodeType,
|
|
5
|
+
type Schema,
|
|
6
|
+
Slice,
|
|
7
|
+
} from "@tiptap/pm/model";
|
|
8
|
+
import { TableMap } from "@tiptap/pm/tables";
|
|
9
|
+
|
|
10
|
+
// Sheets, Excel and Numbers copy cells as tab-separated text: rows end in a
|
|
11
|
+
// line break, and a cell holding a tab or line break is wrapped in double
|
|
12
|
+
// quotes with its own quotes doubled. This reads that text into a table and
|
|
13
|
+
// writes a copied table back out the same way, also quoting a cell that starts
|
|
14
|
+
// with a quote so it isn't read back as a quoted one.
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The rows of tab-separated text, or null unless it is a grid of at least two
|
|
18
|
+
* rows and two columns with the same number of cells in every row. Prose with
|
|
19
|
+
* a stray tab and indented lines stay text.
|
|
20
|
+
*/
|
|
21
|
+
export function parseSpreadsheetText(text: string): string[][] | null {
|
|
22
|
+
if (!text.includes("\t")) return null;
|
|
23
|
+
|
|
24
|
+
const rows: string[][] = [];
|
|
25
|
+
let row: string[] = [];
|
|
26
|
+
let index = 0;
|
|
27
|
+
while (index <= text.length) {
|
|
28
|
+
const cell = readCell(text, index);
|
|
29
|
+
row.push(cell.value);
|
|
30
|
+
index = cell.end;
|
|
31
|
+
const delimiter = text.charAt(index);
|
|
32
|
+
if (delimiter === "\t") {
|
|
33
|
+
index += 1;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
rows.push(row);
|
|
37
|
+
row = [];
|
|
38
|
+
if (delimiter === "") break;
|
|
39
|
+
index += text.startsWith("\r\n", index) ? 2 : 1;
|
|
40
|
+
// A line break at the very end closes the last row; it isn't a new one.
|
|
41
|
+
if (index === text.length) break;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const width = rows[0]?.length ?? 0;
|
|
45
|
+
if (rows.length < 2 || width < 2) return null;
|
|
46
|
+
if (rows.some((cells) => cells.length !== width)) return null;
|
|
47
|
+
if (rows.every(startsBlank)) return null;
|
|
48
|
+
return rows;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Whether a row's first cell is empty or only spaces, as indentation is. */
|
|
52
|
+
function startsBlank(cells: string[]) {
|
|
53
|
+
for (const cell of cells) return cell.trim() === "";
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function readCell(text: string, start: number) {
|
|
58
|
+
if (text.charAt(start) === '"') {
|
|
59
|
+
let value = "";
|
|
60
|
+
let index = start + 1;
|
|
61
|
+
while (index < text.length) {
|
|
62
|
+
const character = text.charAt(index);
|
|
63
|
+
if (character !== '"') {
|
|
64
|
+
value += character;
|
|
65
|
+
index += 1;
|
|
66
|
+
} else if (text.charAt(index + 1) === '"') {
|
|
67
|
+
value += '"';
|
|
68
|
+
index += 2;
|
|
69
|
+
} else {
|
|
70
|
+
index += 1;
|
|
71
|
+
if (isDelimiter(text.charAt(index))) return { value, end: index };
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Not a quoted cell after all, such as `"Quoted" word`: read it as written.
|
|
76
|
+
}
|
|
77
|
+
let end = start;
|
|
78
|
+
while (!isDelimiter(text.charAt(end))) end += 1;
|
|
79
|
+
return { value: text.slice(start, end), end };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A tab, a line break, or the end of the text, where charAt gives "". */
|
|
83
|
+
function isDelimiter(character: string) {
|
|
84
|
+
return (
|
|
85
|
+
character === "" ||
|
|
86
|
+
character === "\t" ||
|
|
87
|
+
character === "\n" ||
|
|
88
|
+
character === "\r"
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** A table of plain cells, one paragraph each, for the given rows. */
|
|
93
|
+
export function spreadsheetTableSlice(
|
|
94
|
+
schema: Schema,
|
|
95
|
+
rows: string[][],
|
|
96
|
+
): Slice | null {
|
|
97
|
+
const { table, tableRow, tableCell, paragraph, hardBreak } =
|
|
98
|
+
nodeTypes(schema);
|
|
99
|
+
if (!table || !tableRow || !tableCell || !paragraph) return null;
|
|
100
|
+
|
|
101
|
+
const cellContent = (text: string) => {
|
|
102
|
+
const inline: ProseMirrorNode[] = [];
|
|
103
|
+
text.split(/\r\n?|\n/).forEach((line, index) => {
|
|
104
|
+
if (index > 0)
|
|
105
|
+
inline.push(hardBreak ? hardBreak.create() : schema.text(" "));
|
|
106
|
+
if (line) inline.push(schema.text(line));
|
|
107
|
+
});
|
|
108
|
+
return paragraph.create(null, inline);
|
|
109
|
+
};
|
|
110
|
+
const node = table.create(
|
|
111
|
+
null,
|
|
112
|
+
rows.map((cells) =>
|
|
113
|
+
tableRow.create(
|
|
114
|
+
null,
|
|
115
|
+
cells.map((text) => tableCell.create(null, cellContent(text))),
|
|
116
|
+
),
|
|
117
|
+
),
|
|
118
|
+
);
|
|
119
|
+
return new Slice(Fragment.from(node), 0, 0);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Excel writes one `<col span="3">` for three columns of the same width, and
|
|
124
|
+
* a pasted cell takes its width from the `<col>` at its own column's index, so
|
|
125
|
+
* every column after the first lost its width. One `<col>` per column keeps
|
|
126
|
+
* them all.
|
|
127
|
+
*/
|
|
128
|
+
export function expandColumnSpans(html: string): string {
|
|
129
|
+
if (!/<col\b[^>]*\bspan\s*=/i.test(html)) return html;
|
|
130
|
+
const template = document.createElement("template");
|
|
131
|
+
template.innerHTML = html;
|
|
132
|
+
for (const col of Array.from(
|
|
133
|
+
template.content.querySelectorAll("col[span]"),
|
|
134
|
+
)) {
|
|
135
|
+
// Browsers cap a column span at 1000. A span that isn't a number adds no
|
|
136
|
+
// columns.
|
|
137
|
+
const span = Math.min(Number(col.getAttribute("span")), 1000);
|
|
138
|
+
col.removeAttribute("span");
|
|
139
|
+
for (let copy = 1; copy < span; copy++) col.after(col.cloneNode());
|
|
140
|
+
}
|
|
141
|
+
return template.innerHTML;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Whether a paste's files are only a picture of the table in its HTML, as
|
|
146
|
+
* Excel puts beside the cells it copies. HTML with media of its own, such as
|
|
147
|
+
* a table and an image copied from Word, keeps its files.
|
|
148
|
+
*/
|
|
149
|
+
export function isSpreadsheetPicture(clipboardData: DataTransfer) {
|
|
150
|
+
const files = Array.from(clipboardData.files);
|
|
151
|
+
if (files.length === 0) return false;
|
|
152
|
+
if (!files.every((file) => file.type.startsWith("image/"))) return false;
|
|
153
|
+
// A template's content is inert: nothing in it loads or runs.
|
|
154
|
+
const template = document.createElement("template");
|
|
155
|
+
template.innerHTML = clipboardData.getData("text/html");
|
|
156
|
+
const html = template.content;
|
|
157
|
+
return (
|
|
158
|
+
html.querySelector("table") !== null &&
|
|
159
|
+
html.querySelector(
|
|
160
|
+
"img, picture, video, audio, svg, object, embed, iframe",
|
|
161
|
+
) === null
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Tab-separated text for a copied slice that is one table, or rows of one
|
|
167
|
+
* table as a cell selection copies them; null for anything else, such as text
|
|
168
|
+
* selected inside a cell. A merged cell's text goes in its first position and
|
|
169
|
+
* the rest stay empty.
|
|
170
|
+
*/
|
|
171
|
+
export function spreadsheetTextForSlice(
|
|
172
|
+
slice: Slice,
|
|
173
|
+
schema: Schema,
|
|
174
|
+
): string | null {
|
|
175
|
+
// A cell selection's slice is open one level, into its table. Text selected
|
|
176
|
+
// inside a cell comes with the table, row and cell around it, open deeper.
|
|
177
|
+
if (slice.openStart > 1 || slice.openEnd > 1) return null;
|
|
178
|
+
const table = copiedTable(slice.content, schema);
|
|
179
|
+
if (!table) return null;
|
|
180
|
+
|
|
181
|
+
// The map lists each grid position's cell in reading order, so a merged
|
|
182
|
+
// cell's first position is its top-left one.
|
|
183
|
+
const map = TableMap.get(table);
|
|
184
|
+
const written = new Set<number>();
|
|
185
|
+
const cells = map.map.map((position) => {
|
|
186
|
+
if (written.has(position)) return "";
|
|
187
|
+
written.add(position);
|
|
188
|
+
const cell = table.nodeAt(position);
|
|
189
|
+
return cell ? quoteCell(cellText(cell)) : "";
|
|
190
|
+
});
|
|
191
|
+
const lines: string[] = [];
|
|
192
|
+
for (let row = 0; row < map.height; row++) {
|
|
193
|
+
lines.push(cells.slice(row * map.width, (row + 1) * map.width).join("\t"));
|
|
194
|
+
}
|
|
195
|
+
return lines.join("\n");
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function copiedTable(content: Fragment, schema: Schema) {
|
|
199
|
+
const only = content.childCount === 1 ? content.firstChild : null;
|
|
200
|
+
if (only?.type.spec.tableRole === "table") return only;
|
|
201
|
+
const rows = allChildren(content);
|
|
202
|
+
if (rows.length === 0) return null;
|
|
203
|
+
if (!rows.every((node) => node.type.spec.tableRole === "row")) return null;
|
|
204
|
+
return nodeTypes(schema).table?.create(null, content) ?? null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The schema's node types, any of which a schema may leave out. */
|
|
208
|
+
function nodeTypes(schema: Schema) {
|
|
209
|
+
return schema.nodes as Partial<Record<string, NodeType>>;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function allChildren(fragment: Fragment) {
|
|
213
|
+
const nodes: ProseMirrorNode[] = [];
|
|
214
|
+
fragment.forEach((node) => nodes.push(node));
|
|
215
|
+
return nodes;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function cellText(cell: ProseMirrorNode) {
|
|
219
|
+
return cell.textBetween(0, cell.content.size, "\n", (leaf) =>
|
|
220
|
+
leaf.type.name === "hardBreak"
|
|
221
|
+
? "\n"
|
|
222
|
+
: (leaf.type.spec.leafText?.(leaf) ?? ""),
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function quoteCell(text: string) {
|
|
227
|
+
return /[\t\n\r]/.test(text) || text.startsWith('"')
|
|
228
|
+
? `"${text.replace(/"/g, '""')}"`
|
|
229
|
+
: text;
|
|
230
|
+
}
|