@bikdotai/bik-component-library 0.0.850-beta.2 → 0.0.850-beta.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/cjs/assets/icons/ShipStation.svg.js +1 -1
- package/dist/cjs/assets/icons/ShipStation.svg.js.map +1 -1
- package/dist/cjs/components/agent-builder/AgentBuilder.styled.js +0 -1
- package/dist/cjs/components/agent-builder/AgentBuilder.styled.js.map +1 -1
- package/dist/cjs/components/agent-builder/components/DiscardModal.js +1 -1
- package/dist/cjs/components/agent-builder/components/DiscardModal.js.map +1 -1
- package/dist/cjs/components/agent-builder/components/GoLiveModal.js +1 -1
- package/dist/cjs/components/agent-builder/components/GoLiveModal.js.map +1 -1
- package/dist/cjs/components/agent-builder/components/MentionEditor.js +1 -1
- package/dist/cjs/components/agent-builder/components/MentionEditor.js.map +1 -1
- package/dist/cjs/components/agent-builder/components/MentionPicker.js +32 -24
- package/dist/cjs/components/agent-builder/components/MentionPicker.js.map +1 -1
- package/dist/cjs/editor/BikEditor.js +1 -1
- package/dist/cjs/editor/BikEditor.js.map +1 -1
- package/dist/cjs/editor/BikEditor.styles.js +17 -12
- package/dist/cjs/editor/BikEditor.styles.js.map +1 -1
- package/dist/cjs/editor/BikEditor.types.js.map +1 -1
- package/dist/cjs/editor/extensions/buildExtensions.js +2 -2
- package/dist/cjs/editor/extensions/buildExtensions.js.map +1 -1
- package/dist/cjs/editor/extensions/characterLimit/CharacterLimitExtension.js +3 -3
- package/dist/cjs/editor/extensions/characterLimit/CharacterLimitExtension.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/esm/assets/icons/ShipStation.svg.js +2 -2
- package/dist/esm/assets/icons/ShipStation.svg.js.map +1 -1
- package/dist/esm/assets/icons/index.d.ts +1 -0
- package/dist/esm/components/agent-builder/AgentBuilder.styled.js +4 -5
- package/dist/esm/components/agent-builder/AgentBuilder.styled.js.map +1 -1
- package/dist/esm/components/agent-builder/components/DiscardModal.js +57 -49
- package/dist/esm/components/agent-builder/components/DiscardModal.js.map +1 -1
- package/dist/esm/components/agent-builder/components/GoLiveModal.js +26 -22
- package/dist/esm/components/agent-builder/components/GoLiveModal.js.map +1 -1
- package/dist/esm/components/agent-builder/components/MentionEditor.js +24 -23
- package/dist/esm/components/agent-builder/components/MentionEditor.js.map +1 -1
- package/dist/esm/components/agent-builder/components/MentionPicker.js +81 -73
- package/dist/esm/components/agent-builder/components/MentionPicker.js.map +1 -1
- package/dist/esm/editor/BikEditor.js +70 -68
- package/dist/esm/editor/BikEditor.js.map +1 -1
- package/dist/esm/editor/BikEditor.styles.js +20 -15
- package/dist/esm/editor/BikEditor.styles.js.map +1 -1
- package/dist/esm/editor/BikEditor.types.d.ts +10 -0
- package/dist/esm/editor/BikEditor.types.js.map +1 -1
- package/dist/esm/editor/extensions/buildExtensions.d.ts +6 -0
- package/dist/esm/editor/extensions/buildExtensions.js +20 -15
- package/dist/esm/editor/extensions/buildExtensions.js.map +1 -1
- package/dist/esm/editor/extensions/characterLimit/CharacterLimitExtension.d.ts +20 -3
- package/dist/esm/editor/extensions/characterLimit/CharacterLimitExtension.js +40 -25
- package/dist/esm/editor/extensions/characterLimit/CharacterLimitExtension.js.map +1 -1
- package/dist/esm/index.js +761 -759
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,55 +1,70 @@
|
|
|
1
|
-
import { Extension as
|
|
2
|
-
import { Plugin as
|
|
3
|
-
import { Decoration as
|
|
4
|
-
const
|
|
1
|
+
import { Extension as m } from "../../../node_modules/@tiptap/core/dist/index.js";
|
|
2
|
+
import { Plugin as p, PluginKey as x } from "@tiptap/pm/state";
|
|
3
|
+
import { Decoration as f, DecorationSet as g } from "@tiptap/pm/view";
|
|
4
|
+
const y = m.create({
|
|
5
5
|
name: "characterLimitOverflow",
|
|
6
6
|
addOptions() {
|
|
7
|
-
return { limit: 0 };
|
|
7
|
+
return { limit: 0, hard: !1 };
|
|
8
8
|
},
|
|
9
9
|
addProseMirrorPlugins() {
|
|
10
10
|
const n = this.options.limit;
|
|
11
11
|
if (!n || n <= 0) return [];
|
|
12
|
-
const
|
|
12
|
+
const u = this.options.hard, a = (e) => e.textBetween(0, e.content.size, `
|
|
13
13
|
|
|
14
14
|
`, `
|
|
15
15
|
`).length;
|
|
16
16
|
return [
|
|
17
|
-
new
|
|
17
|
+
new p({
|
|
18
18
|
key: new x("characterLimitOverflow"),
|
|
19
|
+
// Hard cap. Initial content is loaded at editor creation (not a
|
|
20
|
+
// transaction), so it is never filtered here — content loaded over the
|
|
21
|
+
// limit is preserved.
|
|
22
|
+
...u ? {
|
|
23
|
+
filterTransaction(e, s) {
|
|
24
|
+
if (!e.docChanged) return !0;
|
|
25
|
+
const t = a(e.doc);
|
|
26
|
+
if (t <= n) return !0;
|
|
27
|
+
const r = a(s.doc);
|
|
28
|
+
if (t <= r) return !0;
|
|
29
|
+
if (r > n) return !1;
|
|
30
|
+
const o = t - n, i = e.selection.$head.pos, c = i - o;
|
|
31
|
+
return c <= 0 ? !1 : (e.delete(c, i), a(e.doc) <= n);
|
|
32
|
+
}
|
|
33
|
+
} : {},
|
|
19
34
|
props: {
|
|
20
35
|
// Block typed/composed input that would exceed the limit. Replacing
|
|
21
36
|
// a selection is allowed as long as the result still fits.
|
|
22
|
-
handleTextInput(
|
|
23
|
-
const
|
|
37
|
+
handleTextInput(e, s, t, r) {
|
|
38
|
+
const o = e.state.doc, i = a(o), c = o.textBetween(s, t, `
|
|
24
39
|
|
|
25
40
|
`, `
|
|
26
41
|
`).length;
|
|
27
|
-
return
|
|
42
|
+
return i - c + r.length > n;
|
|
28
43
|
},
|
|
29
|
-
decorations(
|
|
44
|
+
decorations(e) {
|
|
30
45
|
const s = [];
|
|
31
|
-
let t = 0,
|
|
32
|
-
return
|
|
33
|
-
if (!
|
|
34
|
-
const
|
|
35
|
-
if (
|
|
46
|
+
let t = 0, r = !1;
|
|
47
|
+
return e.doc.descendants((o, i, c, d) => {
|
|
48
|
+
if (!r && c && c.type.name === "doc" && d > 0 && (t += 2, t > n && (r = !0)), o.isText && o.text) {
|
|
49
|
+
const l = o.text.length;
|
|
50
|
+
if (r)
|
|
36
51
|
s.push(
|
|
37
|
-
|
|
52
|
+
f.inline(i, i + l, {
|
|
38
53
|
class: "bik-editor-overflow"
|
|
39
54
|
})
|
|
40
55
|
);
|
|
41
|
-
else if (t +
|
|
42
|
-
const
|
|
56
|
+
else if (t + l > n) {
|
|
57
|
+
const h = Math.max(0, n - t);
|
|
43
58
|
s.push(
|
|
44
|
-
|
|
59
|
+
f.inline(i + h, i + l, {
|
|
45
60
|
class: "bik-editor-overflow"
|
|
46
61
|
})
|
|
47
|
-
),
|
|
62
|
+
), r = !0;
|
|
48
63
|
}
|
|
49
|
-
t +=
|
|
50
|
-
} else
|
|
64
|
+
t += l;
|
|
65
|
+
} else o.type.name === "hardBreak" && (t += 1, !r && t > n && (r = !0));
|
|
51
66
|
return !0;
|
|
52
|
-
}),
|
|
67
|
+
}), g.create(e.doc, s);
|
|
53
68
|
}
|
|
54
69
|
}
|
|
55
70
|
})
|
|
@@ -57,6 +72,6 @@ const k = d.create({
|
|
|
57
72
|
}
|
|
58
73
|
});
|
|
59
74
|
export {
|
|
60
|
-
|
|
75
|
+
y as CharacterLimitExtension
|
|
61
76
|
};
|
|
62
77
|
//# sourceMappingURL=CharacterLimitExtension.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CharacterLimitExtension.js","sources":["../../../../../src/editor/extensions/characterLimit/CharacterLimitExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport type { Node as PMNode } from '@tiptap/pm/model';\nimport { Plugin, PluginKey } from '@tiptap/pm/state';\nimport { Decoration, DecorationSet } from '@tiptap/pm/view';\n\nexport interface CharacterLimitOptions {\n\t/** Soft character limit. 0 / undefined disables the extension entirely. */\n\tlimit: number;\n}\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"CharacterLimitExtension.js","sources":["../../../../../src/editor/extensions/characterLimit/CharacterLimitExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport type { Node as PMNode } from '@tiptap/pm/model';\nimport { Plugin, PluginKey } from '@tiptap/pm/state';\nimport { Decoration, DecorationSet } from '@tiptap/pm/view';\n\nexport interface CharacterLimitOptions {\n\t/** Soft character limit. 0 / undefined disables the extension entirely. */\n\tlimit: number;\n\t/**\n\t * Hard mode. When true, NO edit may push the content past the limit — typing,\n\t * Enter, drag-drop and any paste the consumer didn't pre-trim are all rejected\n\t * (a paste is trimmed to fit by the consumer's `onPaste`; anything that still\n\t * overflows is dropped). Content LOADED over the limit is preserved (initial\n\t * content isn't a transaction) and stays editable, but can only shrink — so the\n\t * user can never ADD past the cap, only trim down. Defaults to the soft\n\t * behaviour (typing blocked, paste allowed to overflow grey) for the CRM.\n\t */\n\thard?: boolean;\n}\n\n/**\n * Character limit with two flavours over the SAME metric (see CRM design):\n *\n * Soft (default):\n * 1. Typing is BLOCKED once the content is at/over the limit — `handleTextInput`\n * rejects the insertion. This never fires for paste (paste flows through the\n * clipboard pipeline), so paste is free to push the content over the limit.\n * 2. Every character BEYOND the limit is decorated with `bik-editor-overflow`\n * (rendered grey) so pasted overflow is visible but clearly marked.\n *\n * Hard (`hard: true`): additionally a `filterTransaction` rejects ANY transaction\n * that grows the count past the limit (paste, Enter, drop, IME — every path\n * `handleTextInput` misses), while still allowing shrink/no-growth edits so\n * already-over-limit loaded content stays editable. The grey decoration then only\n * ever marks that loaded overflow (a \"trim me\" hint), never freshly-added text.\n *\n * Counting mirrors `extractContent` exactly — `doc.textBetween(0, size, '\\n\\n',\n * '\\n')` — so the grey boundary AND the hard cap line up with the `characterCount`\n * the consumer shows (paragraph break = 2 chars, soft break = 1 char).\n */\nexport const CharacterLimitExtension = Extension.create<CharacterLimitOptions>({\n\tname: 'characterLimitOverflow',\n\n\taddOptions() {\n\t\treturn { limit: 0, hard: false };\n\t},\n\n\taddProseMirrorPlugins() {\n\t\tconst limit = this.options.limit;\n\t\tif (!limit || limit <= 0) return [];\n\t\tconst hard = this.options.hard;\n\n\t\t// Same metric as BikEditor.utils.extractContent → keeps the grey boundary\n\t\t// and the consumer's characterCount in sync.\n\t\tconst countChars = (doc: PMNode) =>\n\t\t\tdoc.textBetween(0, doc.content.size, '\\n\\n', '\\n').length;\n\n\t\treturn [\n\t\t\tnew Plugin({\n\t\t\t\tkey: new PluginKey('characterLimitOverflow'),\n\t\t\t\t// Hard cap. Initial content is loaded at editor creation (not a\n\t\t\t\t// transaction), so it is never filtered here — content loaded over the\n\t\t\t\t// limit is preserved.\n\t\t\t\t...(hard\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tfilterTransaction(tr, state) {\n\t\t\t\t\t\t\t\tif (!tr.docChanged) return true;\n\t\t\t\t\t\t\t\tconst next = countChars(tr.doc);\n\t\t\t\t\t\t\t\tif (next <= limit) return true;\n\t\t\t\t\t\t\t\tconst prev = countChars(state.doc);\n\t\t\t\t\t\t\t\t// Shrinking / no net growth always passes, so content already\n\t\t\t\t\t\t\t\t// over the limit can be trimmed DOWN (never up).\n\t\t\t\t\t\t\t\tif (next <= prev) return true;\n\t\t\t\t\t\t\t\t// Already over → block any growth outright; never delete the\n\t\t\t\t\t\t\t\t// user's existing over-limit content to make room.\n\t\t\t\t\t\t\t\tif (prev > limit) return false;\n\t\t\t\t\t\t\t\t// A single edit crossed under→over — a paste. Keep the part that\n\t\t\t\t\t\t\t\t// fits and drop the excess tail (paste truncates to the cap)\n\t\t\t\t\t\t\t\t// instead of rejecting the whole paste. Deleting `over` POSITIONS\n\t\t\t\t\t\t\t\t// ending at the caret removes >= `over` characters (a block break\n\t\t\t\t\t\t\t\t// is 2 chars but 1 position), so the result lands <= limit; the\n\t\t\t\t\t\t\t\t// re-check blocks the rare case it somehow didn't.\n\t\t\t\t\t\t\t\tconst over = next - limit;\n\t\t\t\t\t\t\t\tconst head = tr.selection.$head.pos;\n\t\t\t\t\t\t\t\tconst from = head - over;\n\t\t\t\t\t\t\t\tif (from <= 0) return false;\n\t\t\t\t\t\t\t\ttr.delete(from, head);\n\t\t\t\t\t\t\t\treturn countChars(tr.doc) <= limit;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t }\n\t\t\t\t\t: {}),\n\t\t\t\tprops: {\n\t\t\t\t\t// Block typed/composed input that would exceed the limit. Replacing\n\t\t\t\t\t// a selection is allowed as long as the result still fits.\n\t\t\t\t\thandleTextInput(view, from, to, text) {\n\t\t\t\t\t\tconst doc = view.state.doc;\n\t\t\t\t\t\tconst current = countChars(doc);\n\t\t\t\t\t\tconst removed = doc.textBetween(from, to, '\\n\\n', '\\n').length;\n\t\t\t\t\t\treturn current - removed + text.length > limit;\n\t\t\t\t\t},\n\t\t\t\t\tdecorations(state) {\n\t\t\t\t\t\tconst decorations: Decoration[] = [];\n\t\t\t\t\t\tlet count = 0;\n\t\t\t\t\t\tlet overflowing = false;\n\n\t\t\t\t\t\tstate.doc.descendants((node, pos, parent, index) => {\n\t\t\t\t\t\t\t// Account for the \"\\n\\n\" separator inserted between top-level\n\t\t\t\t\t\t\t// blocks so the boundary matches textBetween's counting.\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t!overflowing &&\n\t\t\t\t\t\t\t\tparent &&\n\t\t\t\t\t\t\t\tparent.type.name === 'doc' &&\n\t\t\t\t\t\t\t\tindex > 0\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tcount += 2;\n\t\t\t\t\t\t\t\tif (count > limit) overflowing = true;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (node.isText && node.text) {\n\t\t\t\t\t\t\t\tconst len = node.text.length;\n\t\t\t\t\t\t\t\tif (overflowing) {\n\t\t\t\t\t\t\t\t\tdecorations.push(\n\t\t\t\t\t\t\t\t\t\tDecoration.inline(pos, pos + len, {\n\t\t\t\t\t\t\t\t\t\t\tclass: 'bik-editor-overflow',\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} else if (count + len > limit) {\n\t\t\t\t\t\t\t\t\tconst startOffset = Math.max(0, limit - count);\n\t\t\t\t\t\t\t\t\tdecorations.push(\n\t\t\t\t\t\t\t\t\t\tDecoration.inline(pos + startOffset, pos + len, {\n\t\t\t\t\t\t\t\t\t\t\tclass: 'bik-editor-overflow',\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\toverflowing = true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcount += len;\n\t\t\t\t\t\t\t} else if (node.type.name === 'hardBreak') {\n\t\t\t\t\t\t\t\t// Soft line break → \"\\n\" (1 char) in textBetween.\n\t\t\t\t\t\t\t\tcount += 1;\n\t\t\t\t\t\t\t\tif (!overflowing && count > limit) overflowing = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\treturn DecorationSet.create(state.doc, decorations);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t];\n\t},\n});\n"],"names":["CharacterLimitExtension","Extension","limit","hard","countChars","doc","Plugin","PluginKey","tr","state","next","prev","over","head","from","view","to","text","current","removed","decorations","count","overflowing","node","pos","parent","index","len","Decoration","startOffset","DecorationSet"],"mappings":";;;AAwCO,MAAMA,IAA0BC,EAAU,OAA8B;AAAA,EAC9E,MAAM;AAAA,EAEN,aAAa;AACZ,WAAO,EAAE,OAAO,GAAG,MAAM,GAAA;AAAA,EAC1B;AAAA,EAEA,wBAAwB;AACvB,UAAMC,IAAQ,KAAK,QAAQ;AAC3B,QAAI,CAACA,KAASA,KAAS,UAAU,CAAA;AACjC,UAAMC,IAAO,KAAK,QAAQ,MAIpBC,IAAa,CAACC,MACnBA,EAAI,YAAY,GAAGA,EAAI,QAAQ,MAAM;AAAA;AAAA,GAAQ;AAAA,CAAI,EAAE;AAEpD,WAAO;AAAA,MACN,IAAIC,E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