@sendbird/actionbook-core 0.9.1 → 0.9.3

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/ui/index.js CHANGED
@@ -456,6 +456,205 @@ function createPluginArray(plugins) {
456
456
  // src/ui/components/ActionbookRenderer.tsx
457
457
  import React from "react";
458
458
 
459
+ // src/jinja/conditionHighlighter.ts
460
+ var KEYWORDS = {
461
+ and: "AND",
462
+ or: "OR",
463
+ not: "NOT",
464
+ in: "IN",
465
+ is: "IS",
466
+ True: "BOOL",
467
+ False: "BOOL",
468
+ true: "BOOL",
469
+ false: "BOOL",
470
+ None: "NONE",
471
+ null: "NONE"
472
+ };
473
+ var CATEGORY_BY_TYPE = {
474
+ STRING: "value",
475
+ NUMBER: "value",
476
+ BOOL: "value",
477
+ NONE: "value",
478
+ IDENT: "variable",
479
+ AND: "operator",
480
+ OR: "operator",
481
+ NOT: "operator",
482
+ IN: "operator",
483
+ IS: "operator",
484
+ EQ: "operator",
485
+ NEQ: "operator",
486
+ LT: "operator",
487
+ GT: "operator",
488
+ LTE: "operator",
489
+ GTE: "operator",
490
+ LPAREN: "punctuation",
491
+ RPAREN: "punctuation"
492
+ };
493
+ var NEGATIVE_NUMBER_PRECEDERS = /* @__PURE__ */ new Set([
494
+ "AND",
495
+ "OR",
496
+ "NOT",
497
+ "IN",
498
+ "IS",
499
+ "EQ",
500
+ "NEQ",
501
+ "LT",
502
+ "GT",
503
+ "LTE",
504
+ "GTE",
505
+ "LPAREN"
506
+ ]);
507
+ function canStartNegativeNumber(tokens) {
508
+ if (tokens.length === 0) {
509
+ return true;
510
+ }
511
+ const previous = tokens[tokens.length - 1];
512
+ return NEGATIVE_NUMBER_PRECEDERS.has(previous.type);
513
+ }
514
+ function finalizeTokens(input, rawTokens) {
515
+ const highlighted = [];
516
+ for (let i = 0; i < rawTokens.length; i++) {
517
+ const token = rawTokens[i];
518
+ const next = rawTokens[i + 1];
519
+ if (token.type === "IS" && next?.type === "NOT") {
520
+ highlighted.push({
521
+ text: input.slice(token.start, next.end),
522
+ start: token.start,
523
+ end: next.end,
524
+ category: "operator"
525
+ });
526
+ i++;
527
+ continue;
528
+ }
529
+ highlighted.push({
530
+ text: token.text,
531
+ start: token.start,
532
+ end: token.end,
533
+ category: CATEGORY_BY_TYPE[token.type]
534
+ });
535
+ }
536
+ return highlighted;
537
+ }
538
+ function tokenizeCondition(input) {
539
+ const rawTokens = [];
540
+ let i = 0;
541
+ while (i < input.length) {
542
+ const char = input[i];
543
+ if (/\s/.test(char)) {
544
+ i++;
545
+ continue;
546
+ }
547
+ if (char === '"' || char === "'") {
548
+ const start = i;
549
+ const quote = char;
550
+ i++;
551
+ while (i < input.length) {
552
+ if (input[i] === "\\" && i + 1 < input.length) {
553
+ i += 2;
554
+ continue;
555
+ }
556
+ if (input[i] === quote) {
557
+ i++;
558
+ rawTokens.push({
559
+ type: "STRING",
560
+ text: input.slice(start, i),
561
+ start,
562
+ end: i
563
+ });
564
+ break;
565
+ }
566
+ i++;
567
+ }
568
+ if (rawTokens[rawTokens.length - 1]?.start !== start) {
569
+ return finalizeTokens(input, rawTokens);
570
+ }
571
+ continue;
572
+ }
573
+ if (/[0-9]/.test(char) || char === "-" && i + 1 < input.length && /[0-9]/.test(input[i + 1]) && canStartNegativeNumber(rawTokens)) {
574
+ const start = i;
575
+ if (input[i] === "-") {
576
+ i++;
577
+ }
578
+ while (i < input.length && /[0-9]/.test(input[i])) {
579
+ i++;
580
+ }
581
+ if (i < input.length && input[i] === ".") {
582
+ i++;
583
+ while (i < input.length && /[0-9]/.test(input[i])) {
584
+ i++;
585
+ }
586
+ }
587
+ rawTokens.push({
588
+ type: "NUMBER",
589
+ text: input.slice(start, i),
590
+ start,
591
+ end: i
592
+ });
593
+ continue;
594
+ }
595
+ if (/[a-zA-Z_]/.test(char)) {
596
+ const start = i;
597
+ i++;
598
+ while (i < input.length && /[a-zA-Z0-9_.]/.test(input[i])) {
599
+ i++;
600
+ }
601
+ const text2 = input.slice(start, i);
602
+ rawTokens.push({
603
+ type: KEYWORDS[text2] ?? "IDENT",
604
+ text: text2,
605
+ start,
606
+ end: i
607
+ });
608
+ continue;
609
+ }
610
+ if (i + 1 < input.length) {
611
+ const twoChar = input.slice(i, i + 2);
612
+ if (twoChar === "==") {
613
+ rawTokens.push({ type: "EQ", text: twoChar, start: i, end: i + 2 });
614
+ i += 2;
615
+ continue;
616
+ }
617
+ if (twoChar === "!=") {
618
+ rawTokens.push({ type: "NEQ", text: twoChar, start: i, end: i + 2 });
619
+ i += 2;
620
+ continue;
621
+ }
622
+ if (twoChar === "<=") {
623
+ rawTokens.push({ type: "LTE", text: twoChar, start: i, end: i + 2 });
624
+ i += 2;
625
+ continue;
626
+ }
627
+ if (twoChar === ">=") {
628
+ rawTokens.push({ type: "GTE", text: twoChar, start: i, end: i + 2 });
629
+ i += 2;
630
+ continue;
631
+ }
632
+ }
633
+ if (char === "<") {
634
+ rawTokens.push({ type: "LT", text: char, start: i, end: i + 1 });
635
+ i++;
636
+ continue;
637
+ }
638
+ if (char === ">") {
639
+ rawTokens.push({ type: "GT", text: char, start: i, end: i + 1 });
640
+ i++;
641
+ continue;
642
+ }
643
+ if (char === "(") {
644
+ rawTokens.push({ type: "LPAREN", text: char, start: i, end: i + 1 });
645
+ i++;
646
+ continue;
647
+ }
648
+ if (char === ")") {
649
+ rawTokens.push({ type: "RPAREN", text: char, start: i, end: i + 1 });
650
+ i++;
651
+ continue;
652
+ }
653
+ return finalizeTokens(input, rawTokens);
654
+ }
655
+ return finalizeTokens(input, rawTokens);
656
+ }
657
+
459
658
  // src/ui/components/icons.tsx
460
659
  import { jsx, jsxs } from "react/jsx-runtime";
461
660
  function IconTool({ size = 16, fill = "currentColor", style }) {
@@ -740,8 +939,174 @@ function renderInline(node, key2, renderNode) {
740
939
  if (renderNode) return renderNode(node, defaultRender);
741
940
  return defaultRender();
742
941
  }
743
- function renderInlineContent(content, keyPrefix, renderNode) {
744
- return content.map((node, i) => renderInline(node, `${keyPrefix}-${i}`, renderNode));
942
+ function renderInlineContent(content, keyPrefix, renderNode) {
943
+ return content.map((node, i) => renderInline(node, `${keyPrefix}-${i}`, renderNode));
944
+ }
945
+ var JINJA_RENDERER_STYLE_ID = "ab-renderer-jinja-styles";
946
+ var JINJA_RENDERER_STYLES = `
947
+ .ab-r-jinja-block {
948
+ margin: 8px 0;
949
+ }
950
+
951
+ .ab-r-jinja-branch {
952
+ position: relative;
953
+ }
954
+
955
+ .ab-r-jinja-header {
956
+ display: flex;
957
+ align-items: center;
958
+ gap: 12px;
959
+ padding: 8px;
960
+ border: 1px solid #E0E0E0;
961
+ border-radius: 4px;
962
+ background: #FFFFFF;
963
+ }
964
+
965
+ .ab-r-jinja-badge {
966
+ display: inline-flex;
967
+ align-items: center;
968
+ justify-content: center;
969
+ height: 32px;
970
+ padding: 0 8px;
971
+ border-radius: 4px;
972
+ font-family: "Roboto Mono", monospace;
973
+ font-size: 13px;
974
+ font-weight: 700;
975
+ line-height: 20px;
976
+ letter-spacing: -0.3px;
977
+ white-space: nowrap;
978
+ flex-shrink: 0;
979
+ }
980
+
981
+ .ab-r-jinja-badge-if,
982
+ .ab-r-jinja-badge-elif {
983
+ background: #E7F1FF;
984
+ color: #0D0D0D;
985
+ }
986
+
987
+ .ab-r-jinja-badge-else {
988
+ background: #F7F7F7;
989
+ color: #424242;
990
+ }
991
+
992
+ .ab-r-jinja-condition {
993
+ flex: 1;
994
+ min-width: 0;
995
+ display: flex;
996
+ flex-wrap: wrap;
997
+ gap: 8px;
998
+ align-items: center;
999
+ font-family: "Roboto Mono", monospace;
1000
+ font-size: 13px;
1001
+ line-height: 20px;
1002
+ letter-spacing: -0.3px;
1003
+ color: #0D0D0D;
1004
+ }
1005
+
1006
+ .ab-r-jinja-otherwise {
1007
+ flex: 1;
1008
+ color: #858585;
1009
+ font-family: "Roboto Mono", monospace;
1010
+ font-size: 13px;
1011
+ line-height: 20px;
1012
+ letter-spacing: -0.3px;
1013
+ }
1014
+
1015
+ .ab-r-jinja-body {
1016
+ display: flex;
1017
+ gap: 12px;
1018
+ padding: 0 8px;
1019
+ min-height: 32px;
1020
+ }
1021
+
1022
+ .ab-r-jinja-divider-col {
1023
+ width: 32px;
1024
+ flex-shrink: 0;
1025
+ display: flex;
1026
+ align-items: stretch;
1027
+ justify-content: center;
1028
+ }
1029
+
1030
+ .ab-r-jinja-divider {
1031
+ width: 1px;
1032
+ background: #E0E0E0;
1033
+ }
1034
+
1035
+ .ab-r-jinja-branch-last .ab-r-jinja-divider-col {
1036
+ align-items: flex-start;
1037
+ padding-left: 16px;
1038
+ }
1039
+
1040
+ .ab-r-jinja-branch-last .ab-r-jinja-divider {
1041
+ width: 16px;
1042
+ height: 28px;
1043
+ background: none;
1044
+ border-left: 1px solid #E0E0E0;
1045
+ border-bottom: 1px solid #E0E0E0;
1046
+ border-bottom-left-radius: 8px;
1047
+ }
1048
+
1049
+ .ab-r-jinja-content {
1050
+ flex: 1;
1051
+ min-width: 0;
1052
+ padding: 12px 0;
1053
+ }
1054
+
1055
+ .ab-r-jinja-token-variable { color: #4141B2; }
1056
+ .ab-r-jinja-token-operator { color: #858585; }
1057
+ .ab-r-jinja-token-value { color: #0D0D0D; }
1058
+ .ab-r-jinja-token-punctuation { color: #858585; }
1059
+ `;
1060
+ var jinjaRendererStyleRefCount = 0;
1061
+ var jinjaRendererStyleEl = null;
1062
+ function ensureJinjaRendererStyles() {
1063
+ if (jinjaRendererStyleRefCount++ > 0) return;
1064
+ if (typeof document === "undefined") return;
1065
+ const existing = document.getElementById(JINJA_RENDERER_STYLE_ID);
1066
+ if (existing instanceof HTMLStyleElement) {
1067
+ jinjaRendererStyleEl = existing;
1068
+ return;
1069
+ }
1070
+ jinjaRendererStyleEl = document.createElement("style");
1071
+ jinjaRendererStyleEl.id = JINJA_RENDERER_STYLE_ID;
1072
+ jinjaRendererStyleEl.textContent = JINJA_RENDERER_STYLES;
1073
+ document.head.appendChild(jinjaRendererStyleEl);
1074
+ }
1075
+ function renderConditionTokens(condition) {
1076
+ const tokens = tokenizeCondition(condition);
1077
+ return tokens.map((token, i) => /* @__PURE__ */ jsx2("span", { className: `ab-r-jinja-token-${token.category}`, children: token.text }, `t-${i}-${token.start}`));
1078
+ }
1079
+ function renderJinjaBranch(branch, key2, isLast, renderNode) {
1080
+ const branchType = branch.branchType;
1081
+ const badgeLabel = branchType === "elif" ? "ELSE IF" : branchType.toUpperCase();
1082
+ return /* @__PURE__ */ jsxs2(
1083
+ "div",
1084
+ {
1085
+ className: `ab-r-jinja-branch${isLast ? " ab-r-jinja-branch-last" : ""}`,
1086
+ children: [
1087
+ /* @__PURE__ */ jsxs2("div", { className: "ab-r-jinja-header", children: [
1088
+ /* @__PURE__ */ jsx2("span", { className: `ab-r-jinja-badge ab-r-jinja-badge-${branchType}`, children: badgeLabel }),
1089
+ branchType === "else" ? /* @__PURE__ */ jsx2("span", { className: "ab-r-jinja-otherwise", children: "otherwise" }) : /* @__PURE__ */ jsx2("span", { className: "ab-r-jinja-condition", children: branch.condition ? renderConditionTokens(branch.condition) : null })
1090
+ ] }),
1091
+ /* @__PURE__ */ jsxs2("div", { className: "ab-r-jinja-body", children: [
1092
+ /* @__PURE__ */ jsx2("div", { className: "ab-r-jinja-divider-col", children: /* @__PURE__ */ jsx2("div", { className: "ab-r-jinja-divider" }) }),
1093
+ /* @__PURE__ */ jsx2("div", { className: "ab-r-jinja-content", children: branch.content.map((child, i) => renderBlock(child, `${key2}-c${i}`, renderNode)) })
1094
+ ] })
1095
+ ]
1096
+ },
1097
+ key2
1098
+ );
1099
+ }
1100
+ function renderJinjaIfBlock(node, key2, renderNode) {
1101
+ ensureJinjaRendererStyles();
1102
+ return /* @__PURE__ */ jsx2("div", { className: "ab-r-jinja-block", children: node.branches.map(
1103
+ (branch, i) => renderJinjaBranch(
1104
+ branch,
1105
+ `${key2}-b${i}`,
1106
+ i === node.branches.length - 1,
1107
+ renderNode
1108
+ )
1109
+ ) }, key2);
745
1110
  }
746
1111
  function renderBlock(node, key2, renderNode) {
747
1112
  const defaultRender = () => {
@@ -774,6 +1139,8 @@ function renderBlock(node, key2, renderNode) {
774
1139
  return /* @__PURE__ */ jsx2("li", { children: node.content.map((child, i) => renderBlock(child, `${key2}-${i}`, renderNode)) }, key2);
775
1140
  case "blockquote":
776
1141
  return /* @__PURE__ */ jsx2("blockquote", { children: node.content.map((child, i) => renderBlock(child, `${key2}-${i}`, renderNode)) }, key2);
1142
+ case "jinjaIfBlock":
1143
+ return renderJinjaIfBlock(node, key2, renderNode);
777
1144
  case "horizontalRule":
778
1145
  return /* @__PURE__ */ jsx2("hr", {}, key2);
779
1146
  case "table":
@@ -4336,205 +4703,6 @@ function analyzeJinjaBlocks(doc2) {
4336
4703
  });
4337
4704
  }
4338
4705
 
4339
- // src/jinja/conditionHighlighter.ts
4340
- var KEYWORDS = {
4341
- and: "AND",
4342
- or: "OR",
4343
- not: "NOT",
4344
- in: "IN",
4345
- is: "IS",
4346
- True: "BOOL",
4347
- False: "BOOL",
4348
- true: "BOOL",
4349
- false: "BOOL",
4350
- None: "NONE",
4351
- null: "NONE"
4352
- };
4353
- var CATEGORY_BY_TYPE = {
4354
- STRING: "value",
4355
- NUMBER: "value",
4356
- BOOL: "value",
4357
- NONE: "value",
4358
- IDENT: "variable",
4359
- AND: "operator",
4360
- OR: "operator",
4361
- NOT: "operator",
4362
- IN: "operator",
4363
- IS: "operator",
4364
- EQ: "operator",
4365
- NEQ: "operator",
4366
- LT: "operator",
4367
- GT: "operator",
4368
- LTE: "operator",
4369
- GTE: "operator",
4370
- LPAREN: "punctuation",
4371
- RPAREN: "punctuation"
4372
- };
4373
- var NEGATIVE_NUMBER_PRECEDERS = /* @__PURE__ */ new Set([
4374
- "AND",
4375
- "OR",
4376
- "NOT",
4377
- "IN",
4378
- "IS",
4379
- "EQ",
4380
- "NEQ",
4381
- "LT",
4382
- "GT",
4383
- "LTE",
4384
- "GTE",
4385
- "LPAREN"
4386
- ]);
4387
- function canStartNegativeNumber(tokens) {
4388
- if (tokens.length === 0) {
4389
- return true;
4390
- }
4391
- const previous = tokens[tokens.length - 1];
4392
- return NEGATIVE_NUMBER_PRECEDERS.has(previous.type);
4393
- }
4394
- function finalizeTokens(input, rawTokens) {
4395
- const highlighted = [];
4396
- for (let i = 0; i < rawTokens.length; i++) {
4397
- const token = rawTokens[i];
4398
- const next = rawTokens[i + 1];
4399
- if (token.type === "IS" && next?.type === "NOT") {
4400
- highlighted.push({
4401
- text: input.slice(token.start, next.end),
4402
- start: token.start,
4403
- end: next.end,
4404
- category: "operator"
4405
- });
4406
- i++;
4407
- continue;
4408
- }
4409
- highlighted.push({
4410
- text: token.text,
4411
- start: token.start,
4412
- end: token.end,
4413
- category: CATEGORY_BY_TYPE[token.type]
4414
- });
4415
- }
4416
- return highlighted;
4417
- }
4418
- function tokenizeCondition(input) {
4419
- const rawTokens = [];
4420
- let i = 0;
4421
- while (i < input.length) {
4422
- const char = input[i];
4423
- if (/\s/.test(char)) {
4424
- i++;
4425
- continue;
4426
- }
4427
- if (char === '"' || char === "'") {
4428
- const start = i;
4429
- const quote = char;
4430
- i++;
4431
- while (i < input.length) {
4432
- if (input[i] === "\\" && i + 1 < input.length) {
4433
- i += 2;
4434
- continue;
4435
- }
4436
- if (input[i] === quote) {
4437
- i++;
4438
- rawTokens.push({
4439
- type: "STRING",
4440
- text: input.slice(start, i),
4441
- start,
4442
- end: i
4443
- });
4444
- break;
4445
- }
4446
- i++;
4447
- }
4448
- if (rawTokens[rawTokens.length - 1]?.start !== start) {
4449
- return finalizeTokens(input, rawTokens);
4450
- }
4451
- continue;
4452
- }
4453
- if (/[0-9]/.test(char) || char === "-" && i + 1 < input.length && /[0-9]/.test(input[i + 1]) && canStartNegativeNumber(rawTokens)) {
4454
- const start = i;
4455
- if (input[i] === "-") {
4456
- i++;
4457
- }
4458
- while (i < input.length && /[0-9]/.test(input[i])) {
4459
- i++;
4460
- }
4461
- if (i < input.length && input[i] === ".") {
4462
- i++;
4463
- while (i < input.length && /[0-9]/.test(input[i])) {
4464
- i++;
4465
- }
4466
- }
4467
- rawTokens.push({
4468
- type: "NUMBER",
4469
- text: input.slice(start, i),
4470
- start,
4471
- end: i
4472
- });
4473
- continue;
4474
- }
4475
- if (/[a-zA-Z_]/.test(char)) {
4476
- const start = i;
4477
- i++;
4478
- while (i < input.length && /[a-zA-Z0-9_.]/.test(input[i])) {
4479
- i++;
4480
- }
4481
- const text2 = input.slice(start, i);
4482
- rawTokens.push({
4483
- type: KEYWORDS[text2] ?? "IDENT",
4484
- text: text2,
4485
- start,
4486
- end: i
4487
- });
4488
- continue;
4489
- }
4490
- if (i + 1 < input.length) {
4491
- const twoChar = input.slice(i, i + 2);
4492
- if (twoChar === "==") {
4493
- rawTokens.push({ type: "EQ", text: twoChar, start: i, end: i + 2 });
4494
- i += 2;
4495
- continue;
4496
- }
4497
- if (twoChar === "!=") {
4498
- rawTokens.push({ type: "NEQ", text: twoChar, start: i, end: i + 2 });
4499
- i += 2;
4500
- continue;
4501
- }
4502
- if (twoChar === "<=") {
4503
- rawTokens.push({ type: "LTE", text: twoChar, start: i, end: i + 2 });
4504
- i += 2;
4505
- continue;
4506
- }
4507
- if (twoChar === ">=") {
4508
- rawTokens.push({ type: "GTE", text: twoChar, start: i, end: i + 2 });
4509
- i += 2;
4510
- continue;
4511
- }
4512
- }
4513
- if (char === "<") {
4514
- rawTokens.push({ type: "LT", text: char, start: i, end: i + 1 });
4515
- i++;
4516
- continue;
4517
- }
4518
- if (char === ">") {
4519
- rawTokens.push({ type: "GT", text: char, start: i, end: i + 1 });
4520
- i++;
4521
- continue;
4522
- }
4523
- if (char === "(") {
4524
- rawTokens.push({ type: "LPAREN", text: char, start: i, end: i + 1 });
4525
- i++;
4526
- continue;
4527
- }
4528
- if (char === ")") {
4529
- rawTokens.push({ type: "RPAREN", text: char, start: i, end: i + 1 });
4530
- i++;
4531
- continue;
4532
- }
4533
- return finalizeTokens(input, rawTokens);
4534
- }
4535
- return finalizeTokens(input, rawTokens);
4536
- }
4537
-
4538
4706
  // src/tree/documentTree.ts
4539
4707
  var MAX_DEPTH6 = 128;
4540
4708
  function extractInlineItems(content, blockIndex) {
@@ -7185,6 +7353,7 @@ function createTodoNodeViewPlugin() {
7185
7353
  }
7186
7354
 
7187
7355
  // src/ui/plugin/noteBlockPlugin.tsx
7356
+ import { Selection } from "prosemirror-state";
7188
7357
  var NoteBlockView = class {
7189
7358
  dom;
7190
7359
  contentDOM;
@@ -7192,41 +7361,109 @@ var NoteBlockView = class {
7192
7361
  this.dom = document.createElement("div");
7193
7362
  this.dom.setAttribute("data-note-block", "");
7194
7363
  this.dom.className = "ab-note-block";
7195
- this.dom.style.cssText = `
7196
- position: relative;
7197
- margin: 8px 0;
7198
- padding: 12px 16px 12px 16px;
7199
- background: rgba(0, 0, 0, 0.015);
7200
- border-top: 1px solid rgba(0, 0, 0, 0.08);
7201
- color: #999;
7202
- font-style: italic;
7203
- `;
7364
+ this.dom.style.cssText = [
7365
+ "position: relative",
7366
+ "margin: 8px 0",
7367
+ "padding: 16px 24px",
7368
+ "background: #fff",
7369
+ "border: 1px dashed #ccc",
7370
+ "border-radius: 4px",
7371
+ "display: flex",
7372
+ "flex-direction: column",
7373
+ "gap: 4px"
7374
+ ].join(";");
7204
7375
  const label = document.createElement("span");
7205
7376
  label.contentEditable = "false";
7206
7377
  label.textContent = "Note";
7207
- label.style.cssText = `
7208
- display: inline-block;
7209
- font-size: 11px;
7210
- font-weight: 600;
7211
- font-style: normal;
7212
- color: #aaa;
7213
- background: rgba(0, 0, 0, 0.03);
7214
- border: 1px solid rgba(0, 0, 0, 0.1);
7215
- border-radius: 3px;
7216
- padding: 1px 6px;
7217
- margin-bottom: 6px;
7218
- user-select: none;
7219
- line-height: 1.4;
7220
- `;
7378
+ label.style.cssText = [
7379
+ "display: inline-flex",
7380
+ "align-items: center",
7381
+ "justify-content: center",
7382
+ "align-self: flex-start",
7383
+ "font-size: 12px",
7384
+ "font-weight: 400",
7385
+ "font-style: normal",
7386
+ "line-height: 16px",
7387
+ "color: #858585",
7388
+ "background: #f7f7f7",
7389
+ "border: 1px solid #e0e0e0",
7390
+ "border-radius: 4px",
7391
+ "padding: 2px 4px",
7392
+ "user-select: none"
7393
+ ].join(";");
7221
7394
  this.dom.appendChild(label);
7222
7395
  this.contentDOM = document.createElement("div");
7223
7396
  this.contentDOM.className = "ab-note-block-content";
7397
+ this.contentDOM.style.cssText = [
7398
+ "font-size: 14px",
7399
+ "font-style: italic",
7400
+ "font-weight: 400",
7401
+ "line-height: 20px",
7402
+ "letter-spacing: -0.1px",
7403
+ "color: #858585"
7404
+ ].join(";");
7224
7405
  this.dom.appendChild(this.contentDOM);
7225
7406
  }
7226
7407
  };
7408
+ var emptyEnterCount = 0;
7409
+ var lastEnterTime = 0;
7410
+ var exitNoteBlockOnEnter = (state, dispatch) => {
7411
+ const { $from } = state.selection;
7412
+ let noteBlockDepth = -1;
7413
+ for (let d = $from.depth; d > 0; d--) {
7414
+ if ($from.node(d).type.name === "noteBlock") {
7415
+ noteBlockDepth = d;
7416
+ break;
7417
+ }
7418
+ }
7419
+ if (noteBlockDepth < 0) {
7420
+ emptyEnterCount = 0;
7421
+ return false;
7422
+ }
7423
+ const parentNode = $from.parent;
7424
+ if (parentNode.type.name !== "paragraph" || parentNode.content.size !== 0) {
7425
+ emptyEnterCount = 0;
7426
+ return false;
7427
+ }
7428
+ const now = Date.now();
7429
+ if (now - lastEnterTime > 2e3) {
7430
+ emptyEnterCount = 0;
7431
+ }
7432
+ lastEnterTime = now;
7433
+ emptyEnterCount++;
7434
+ if (emptyEnterCount < 2) {
7435
+ return false;
7436
+ }
7437
+ emptyEnterCount = 0;
7438
+ if (!dispatch) return true;
7439
+ const paragraphStart = $from.before($from.depth);
7440
+ const paragraphEnd = $from.after($from.depth);
7441
+ const tr = state.tr.delete(paragraphStart, paragraphEnd);
7442
+ const mappedFrom = tr.mapping.map($from.before($from.depth));
7443
+ const $mapped = tr.doc.resolve(Math.min(mappedFrom, tr.doc.content.size));
7444
+ for (let d = $mapped.depth; d > 0; d--) {
7445
+ if ($mapped.node(d).type.name === "noteBlock") {
7446
+ const lastChild = $mapped.node(d).lastChild;
7447
+ if (lastChild && lastChild.type.name === "paragraph" && lastChild.content.size === 0) {
7448
+ const lastChildPos = $mapped.end(d) - lastChild.nodeSize;
7449
+ tr.delete(lastChildPos, lastChildPos + lastChild.nodeSize);
7450
+ }
7451
+ break;
7452
+ }
7453
+ }
7454
+ const noteBlockEnd = tr.mapping.map($from.after(noteBlockDepth));
7455
+ const newParagraph = state.schema.nodes.paragraph.create();
7456
+ tr.insert(noteBlockEnd, newParagraph);
7457
+ tr.setSelection(Selection.near(tr.doc.resolve(noteBlockEnd + 1)));
7458
+ dispatch(tr.scrollIntoView());
7459
+ return true;
7460
+ };
7227
7461
  function createNoteBlockPlugin() {
7228
7462
  return {
7229
7463
  name: "noteBlockNodeView",
7464
+ keymap: () => ({
7465
+ Enter: exitNoteBlockOnEnter
7466
+ }),
7230
7467
  nodeViews: () => ({
7231
7468
  noteBlock: (node, view, getPos) => new NoteBlockView(node, view, getPos)
7232
7469
  })