@sendbird/actionbook-core 0.9.7 → 0.9.8
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 +131 -17
- package/dist/ui/index.js.map +1 -1
- package/package.json +1 -1
package/dist/ui/index.js
CHANGED
|
@@ -2745,27 +2745,52 @@ function findParentList(state, pos) {
|
|
|
2745
2745
|
}
|
|
2746
2746
|
return null;
|
|
2747
2747
|
}
|
|
2748
|
+
var NOOP = /* @__PURE__ */ Symbol("noop");
|
|
2748
2749
|
function handleListInputRule(state, start, end, listType, attrs) {
|
|
2749
2750
|
const resolvePos = Math.max(start, end - 1);
|
|
2750
2751
|
const parentList = findParentList(state, resolvePos);
|
|
2751
2752
|
if (!parentList) return null;
|
|
2752
2753
|
const $from = state.doc.resolve(resolvePos);
|
|
2753
|
-
const { depth, node: listNode } = parentList;
|
|
2754
|
+
const { depth: listDepth, node: listNode } = parentList;
|
|
2754
2755
|
const paraContentSize = $from.parent.content.size;
|
|
2755
2756
|
const matchedLen = end - start;
|
|
2756
2757
|
if (paraContentSize !== matchedLen) return null;
|
|
2757
|
-
const listStart = $from.before(depth);
|
|
2758
|
-
const listEnd = $from.after(depth);
|
|
2759
2758
|
if (listNode.type === listType) {
|
|
2760
|
-
|
|
2761
|
-
tr.setSelection(TextSelection.near(tr.doc.resolve(listStart)));
|
|
2762
|
-
return tr;
|
|
2763
|
-
} else {
|
|
2764
|
-
const tr = state.tr.delete(start, end);
|
|
2765
|
-
const mappedListPos = tr.mapping.map(listStart);
|
|
2766
|
-
tr.setNodeMarkup(mappedListPos, listType, attrs ?? null);
|
|
2767
|
-
return tr;
|
|
2759
|
+
return NOOP;
|
|
2768
2760
|
}
|
|
2761
|
+
const { listItem: liType } = actionbookSchema.nodes;
|
|
2762
|
+
const tr = state.tr.delete(start, end);
|
|
2763
|
+
const $pos = tr.doc.resolve(tr.mapping.map(resolvePos));
|
|
2764
|
+
let liDepth = -1;
|
|
2765
|
+
for (let d = $pos.depth; d > 0; d--) {
|
|
2766
|
+
if ($pos.node(d).type === liType) {
|
|
2767
|
+
liDepth = d;
|
|
2768
|
+
break;
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
if (liDepth < 0) return null;
|
|
2772
|
+
const parentListAfterDelete = $pos.node(liDepth - 1);
|
|
2773
|
+
const liIndex = $pos.index(liDepth - 1);
|
|
2774
|
+
const liNode = parentListAfterDelete.child(liIndex);
|
|
2775
|
+
const parentListStart = $pos.before(liDepth - 1);
|
|
2776
|
+
const parentListEnd = $pos.after(liDepth - 1);
|
|
2777
|
+
const fragments = [];
|
|
2778
|
+
if (liIndex > 0) {
|
|
2779
|
+
const beforeItems = [];
|
|
2780
|
+
for (let i = 0; i < liIndex; i++) beforeItems.push(parentListAfterDelete.child(i));
|
|
2781
|
+
fragments.push(parentListAfterDelete.type.create(parentListAfterDelete.attrs, beforeItems));
|
|
2782
|
+
}
|
|
2783
|
+
fragments.push(listType.create(attrs ?? null, liNode));
|
|
2784
|
+
if (liIndex < parentListAfterDelete.childCount - 1) {
|
|
2785
|
+
const afterItems = [];
|
|
2786
|
+
for (let i = liIndex + 1; i < parentListAfterDelete.childCount; i++) {
|
|
2787
|
+
afterItems.push(parentListAfterDelete.child(i));
|
|
2788
|
+
}
|
|
2789
|
+
fragments.push(parentListAfterDelete.type.create(parentListAfterDelete.attrs, afterItems));
|
|
2790
|
+
}
|
|
2791
|
+
tr.replaceWith(parentListStart, parentListEnd, fragments);
|
|
2792
|
+
tr.setSelection(TextSelection.near(tr.doc.resolve(tr.mapping.map(start))));
|
|
2793
|
+
return tr;
|
|
2769
2794
|
}
|
|
2770
2795
|
function markInputRule(pattern, markType, markerLen) {
|
|
2771
2796
|
return new InputRule(pattern, (state, match, start, end) => {
|
|
@@ -2836,8 +2861,9 @@ function createInputRulesPlugin() {
|
|
|
2836
2861
|
const fallback = wrappingInputRule(BULLET_LIST_RE, blType);
|
|
2837
2862
|
rules.push(
|
|
2838
2863
|
new InputRule(BULLET_LIST_RE, (state, match, start, end) => {
|
|
2839
|
-
const
|
|
2840
|
-
if (
|
|
2864
|
+
const result = handleListInputRule(state, start, end, blType);
|
|
2865
|
+
if (result === NOOP) return null;
|
|
2866
|
+
if (result) return result;
|
|
2841
2867
|
const handler = fallback.handler;
|
|
2842
2868
|
return handler(state, match, start, end);
|
|
2843
2869
|
})
|
|
@@ -2848,8 +2874,9 @@ function createInputRulesPlugin() {
|
|
|
2848
2874
|
const fallback = wrappingInputRule(ORDERED_LIST_RE, olType, (m) => ({ start: +m[1] }));
|
|
2849
2875
|
rules.push(
|
|
2850
2876
|
new InputRule(ORDERED_LIST_RE, (state, match, start, end) => {
|
|
2851
|
-
const
|
|
2852
|
-
if (
|
|
2877
|
+
const result = handleListInputRule(state, start, end, olType, { start: +match[1] });
|
|
2878
|
+
if (result === NOOP) return null;
|
|
2879
|
+
if (result) return result;
|
|
2853
2880
|
const handler = fallback.handler;
|
|
2854
2881
|
return handler(state, match, start, end);
|
|
2855
2882
|
})
|
|
@@ -3071,6 +3098,69 @@ var backspaceDeleteEmptyBlock = (state, dispatch) => {
|
|
|
3071
3098
|
}
|
|
3072
3099
|
return false;
|
|
3073
3100
|
};
|
|
3101
|
+
var joinListItemBackward = (state, dispatch) => {
|
|
3102
|
+
const { $from } = state.selection;
|
|
3103
|
+
if (!state.selection.empty) return false;
|
|
3104
|
+
if ($from.parentOffset !== 0) return false;
|
|
3105
|
+
if (!cursorDirectlyInListItem(state)) return false;
|
|
3106
|
+
if ($from.index($from.depth - 1) !== 0) return false;
|
|
3107
|
+
const liDepth = $from.depth - 1;
|
|
3108
|
+
const listDepth = liDepth - 1;
|
|
3109
|
+
if (listDepth < 0) return false;
|
|
3110
|
+
const listNode = $from.node(listDepth);
|
|
3111
|
+
if (listNode.type !== bulletList && listNode.type !== orderedList) return false;
|
|
3112
|
+
const liIndex = $from.index(listDepth);
|
|
3113
|
+
if (liIndex > 0) {
|
|
3114
|
+
if (dispatch) {
|
|
3115
|
+
const joinPos = $from.before(liDepth);
|
|
3116
|
+
const tr = state.tr.join(joinPos);
|
|
3117
|
+
const mappedPos = tr.mapping.map(joinPos);
|
|
3118
|
+
if (tr.doc.resolve(mappedPos).nodeBefore?.isTextblock && tr.doc.resolve(mappedPos).nodeAfter?.isTextblock) {
|
|
3119
|
+
tr.join(mappedPos);
|
|
3120
|
+
}
|
|
3121
|
+
dispatch(tr.scrollIntoView());
|
|
3122
|
+
}
|
|
3123
|
+
return true;
|
|
3124
|
+
}
|
|
3125
|
+
const listStart = $from.before(listDepth);
|
|
3126
|
+
const parentOfList = $from.node(listDepth - 1);
|
|
3127
|
+
const listIndexInParent = $from.index(listDepth - 1);
|
|
3128
|
+
if (listIndexInParent > 0) {
|
|
3129
|
+
const prevBlock = parentOfList.child(listIndexInParent - 1);
|
|
3130
|
+
if (prevBlock.isTextblock) {
|
|
3131
|
+
if (dispatch) {
|
|
3132
|
+
const liNode = listNode.child(0);
|
|
3133
|
+
const firstPara = liNode.firstChild;
|
|
3134
|
+
const liStart = $from.before(liDepth);
|
|
3135
|
+
const liEnd = $from.after(liDepth);
|
|
3136
|
+
const tr = state.tr;
|
|
3137
|
+
if (listNode.childCount === 1) {
|
|
3138
|
+
tr.delete(listStart, $from.after(listDepth));
|
|
3139
|
+
} else {
|
|
3140
|
+
tr.delete(liStart, liEnd);
|
|
3141
|
+
}
|
|
3142
|
+
const prevBlockEnd = tr.mapping.map(listStart) - 1;
|
|
3143
|
+
if (firstPara.content.size > 0) {
|
|
3144
|
+
tr.insert(prevBlockEnd, firstPara.content);
|
|
3145
|
+
}
|
|
3146
|
+
if (liNode.childCount > 1) {
|
|
3147
|
+
const nestedContent = [];
|
|
3148
|
+
for (let i = 1; i < liNode.childCount; i++) {
|
|
3149
|
+
nestedContent.push(liNode.child(i));
|
|
3150
|
+
}
|
|
3151
|
+
const insertPos = tr.mapping.map(listStart);
|
|
3152
|
+
for (const node of nestedContent) {
|
|
3153
|
+
tr.insert(insertPos, node);
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3156
|
+
tr.setSelection(TextSelection2.near(tr.doc.resolve(prevBlockEnd)));
|
|
3157
|
+
dispatch(tr.scrollIntoView());
|
|
3158
|
+
}
|
|
3159
|
+
return true;
|
|
3160
|
+
}
|
|
3161
|
+
}
|
|
3162
|
+
return liftListItem(listItem)(state, dispatch);
|
|
3163
|
+
};
|
|
3074
3164
|
var backspaceCommand = chainCommands(
|
|
3075
3165
|
backspaceDeleteEmptyBlock,
|
|
3076
3166
|
backspaceAfterList,
|
|
@@ -3082,7 +3172,13 @@ var backspaceCommand = chainCommands(
|
|
|
3082
3172
|
if ($from.parent.type === heading) {
|
|
3083
3173
|
return setBlockType(paragraph)(state, dispatch);
|
|
3084
3174
|
}
|
|
3175
|
+
return false;
|
|
3176
|
+
},
|
|
3177
|
+
joinListItemBackward,
|
|
3178
|
+
(state, dispatch) => {
|
|
3085
3179
|
if (!cursorDirectlyInListItem(state)) return false;
|
|
3180
|
+
const { $from } = state.selection;
|
|
3181
|
+
if ($from.parentOffset !== 0) return false;
|
|
3086
3182
|
if ($from.index($from.depth - 1) !== 0) return false;
|
|
3087
3183
|
return liftListItem(listItem)(state, dispatch);
|
|
3088
3184
|
},
|
|
@@ -3168,9 +3264,27 @@ var exitBlockOnDoubleEnter = (state, dispatch) => {
|
|
|
3168
3264
|
dispatch(tr.scrollIntoView());
|
|
3169
3265
|
return true;
|
|
3170
3266
|
};
|
|
3267
|
+
var exitCodeBlockOnEnter = (state, dispatch) => {
|
|
3268
|
+
const { $from } = state.selection;
|
|
3269
|
+
if ($from.parent.type.name !== "codeBlock") return false;
|
|
3270
|
+
const codeBlock = $from.parent;
|
|
3271
|
+
const text2 = codeBlock.textContent;
|
|
3272
|
+
if ($from.parentOffset !== text2.length) return false;
|
|
3273
|
+
if (!text2.endsWith("\n")) return false;
|
|
3274
|
+
if (dispatch) {
|
|
3275
|
+
const codeBlockPos = $from.before($from.depth);
|
|
3276
|
+
const tr = state.tr.delete($from.pos - 1, $from.pos);
|
|
3277
|
+
const blockEnd = tr.mapping.map(codeBlockPos + codeBlock.nodeSize);
|
|
3278
|
+
tr.insert(blockEnd, paragraph.create());
|
|
3279
|
+
tr.setSelection(TextSelection2.near(tr.doc.resolve(blockEnd + 1)));
|
|
3280
|
+
dispatch(tr.scrollIntoView());
|
|
3281
|
+
}
|
|
3282
|
+
return true;
|
|
3283
|
+
};
|
|
3171
3284
|
var enterCommand = chainCommands(
|
|
3172
3285
|
exitNoteBlockOnEnter,
|
|
3173
3286
|
exitBlockOnDoubleEnter,
|
|
3287
|
+
exitCodeBlockOnEnter,
|
|
3174
3288
|
newlineInCode,
|
|
3175
3289
|
// Split list item on Enter; lift empty list item out of list
|
|
3176
3290
|
splitListItem(listItem),
|
|
@@ -6486,7 +6600,7 @@ function JinjaBranchHeader({
|
|
|
6486
6600
|
) : null
|
|
6487
6601
|
] }) : null
|
|
6488
6602
|
] }),
|
|
6489
|
-
isLastBranch ? /* @__PURE__ */ jsx6("div", { className: "jinja-add-footer", children: /* @__PURE__ */ jsx6("div", { className: "jinja-add-footer-col", children: /* @__PURE__ */ jsxs5("div", { className: "jinja-add-footer-actions", ref: footerRef, children: [
|
|
6603
|
+
isLastBranch && editable ? /* @__PURE__ */ jsx6("div", { className: "jinja-add-footer", children: /* @__PURE__ */ jsx6("div", { className: "jinja-add-footer-col", children: /* @__PURE__ */ jsxs5("div", { className: "jinja-add-footer-actions", ref: footerRef, children: [
|
|
6490
6604
|
/* @__PURE__ */ jsx6(
|
|
6491
6605
|
"button",
|
|
6492
6606
|
{
|
|
@@ -6661,7 +6775,7 @@ var JinjaIfBranchView = class {
|
|
|
6661
6775
|
return target != null && this.headerContainer.contains(target);
|
|
6662
6776
|
}
|
|
6663
6777
|
ignoreMutation(mutation) {
|
|
6664
|
-
return this.headerContainer.contains(mutation.target);
|
|
6778
|
+
return mutation.target === this.dom || this.headerContainer.contains(mutation.target);
|
|
6665
6779
|
}
|
|
6666
6780
|
destroy() {
|
|
6667
6781
|
if (this._onSiblingsChanged) {
|