@bikdotai/bik-component-library 0.0.852 → 0.0.853

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.
Files changed (79) hide show
  1. package/dist/cjs/components/agent-builder/AgentBuilder.js +1 -1
  2. package/dist/cjs/components/agent-builder/AgentBuilder.js.map +1 -1
  3. package/dist/cjs/components/agent-builder/components/AgentBuilderFooter.js +1 -1
  4. package/dist/cjs/components/agent-builder/components/AgentBuilderFooter.js.map +1 -1
  5. package/dist/cjs/components/agent-builder/components/AgentBuilderTopBar.js +1 -1
  6. package/dist/cjs/components/agent-builder/components/AgentBuilderTopBar.js.map +1 -1
  7. package/dist/cjs/components/agent-builder/components/CreateSubAgentPanel.js +5 -5
  8. package/dist/cjs/components/agent-builder/components/CreateSubAgentPanel.js.map +1 -1
  9. package/dist/cjs/components/agent-builder/components/GoLiveModal.js +1 -1
  10. package/dist/cjs/components/agent-builder/components/GoLiveModal.js.map +1 -1
  11. package/dist/cjs/components/agent-builder/components/MentionPicker.js +24 -24
  12. package/dist/cjs/components/agent-builder/components/MentionPicker.js.map +1 -1
  13. package/dist/cjs/components/agent-builder/components/RequireVerificationModal.js +1 -1
  14. package/dist/cjs/components/agent-builder/components/RequireVerificationModal.js.map +1 -1
  15. package/dist/cjs/components/agent-builder/components/RestApiToolPanel.js +2 -2
  16. package/dist/cjs/components/agent-builder/components/RestApiToolPanel.js.map +1 -1
  17. package/dist/cjs/components/agent-builder/components/SelectableListSection.js +1 -1
  18. package/dist/cjs/components/agent-builder/components/SelectableListSection.js.map +1 -1
  19. package/dist/cjs/components/agent-builder/constants/tools.js +1 -1
  20. package/dist/cjs/components/agent-builder/constants/tools.js.map +1 -1
  21. package/dist/cjs/components/agent-builder/steps/Step3HowItResponds.js +1 -1
  22. package/dist/cjs/components/agent-builder/steps/Step3HowItResponds.js.map +1 -1
  23. package/dist/cjs/components/agent-builder/utils/sourceIcons.js +1 -1
  24. package/dist/cjs/components/agent-builder/utils/sourceIcons.js.map +1 -1
  25. package/dist/cjs/components/agent-listing/AgentTableRow.js +1 -1
  26. package/dist/cjs/components/agent-listing/AgentTableRow.js.map +1 -1
  27. package/dist/cjs/components/agent-listing/AiAgentsEmptyState.js +1 -1
  28. package/dist/cjs/components/agent-listing/AiAgentsEmptyState.js.map +1 -1
  29. package/dist/cjs/components/zeroState/ZeroState.js +3 -3
  30. package/dist/cjs/components/zeroState/ZeroState.js.map +1 -1
  31. package/dist/cjs/editor/BikEditor.js +1 -1
  32. package/dist/cjs/editor/BikEditor.js.map +1 -1
  33. package/dist/cjs/editor/BikEditor.styles.js +22 -16
  34. package/dist/cjs/editor/BikEditor.styles.js.map +1 -1
  35. package/dist/cjs/editor/extensions/jsonHighlight/JsonHighlightExtension.js +3 -3
  36. package/dist/cjs/editor/extensions/jsonHighlight/JsonHighlightExtension.js.map +1 -1
  37. package/dist/esm/components/agent-builder/AgentBuilder.js +146 -136
  38. package/dist/esm/components/agent-builder/AgentBuilder.js.map +1 -1
  39. package/dist/esm/components/agent-builder/AgentBuilder.model.d.ts +7 -2
  40. package/dist/esm/components/agent-builder/components/AgentBuilderFooter.d.ts +2 -0
  41. package/dist/esm/components/agent-builder/components/AgentBuilderFooter.js +29 -26
  42. package/dist/esm/components/agent-builder/components/AgentBuilderFooter.js.map +1 -1
  43. package/dist/esm/components/agent-builder/components/AgentBuilderTopBar.js +30 -29
  44. package/dist/esm/components/agent-builder/components/AgentBuilderTopBar.js.map +1 -1
  45. package/dist/esm/components/agent-builder/components/CreateSubAgentPanel.d.ts +9 -0
  46. package/dist/esm/components/agent-builder/components/CreateSubAgentPanel.js +199 -184
  47. package/dist/esm/components/agent-builder/components/CreateSubAgentPanel.js.map +1 -1
  48. package/dist/esm/components/agent-builder/components/GoLiveModal.js +11 -13
  49. package/dist/esm/components/agent-builder/components/GoLiveModal.js.map +1 -1
  50. package/dist/esm/components/agent-builder/components/MentionPicker.js +174 -150
  51. package/dist/esm/components/agent-builder/components/MentionPicker.js.map +1 -1
  52. package/dist/esm/components/agent-builder/components/RequireVerificationModal.js +8 -8
  53. package/dist/esm/components/agent-builder/components/RequireVerificationModal.js.map +1 -1
  54. package/dist/esm/components/agent-builder/components/RestApiToolPanel.js +54 -51
  55. package/dist/esm/components/agent-builder/components/RestApiToolPanel.js.map +1 -1
  56. package/dist/esm/components/agent-builder/components/SelectableListSection.js +73 -69
  57. package/dist/esm/components/agent-builder/components/SelectableListSection.js.map +1 -1
  58. package/dist/esm/components/agent-builder/constants/tools.d.ts +20 -0
  59. package/dist/esm/components/agent-builder/constants/tools.js +34 -23
  60. package/dist/esm/components/agent-builder/constants/tools.js.map +1 -1
  61. package/dist/esm/components/agent-builder/steps/Step3HowItResponds.js +270 -255
  62. package/dist/esm/components/agent-builder/steps/Step3HowItResponds.js.map +1 -1
  63. package/dist/esm/components/agent-builder/utils/sourceIcons.d.ts +6 -6
  64. package/dist/esm/components/agent-builder/utils/sourceIcons.js +21 -19
  65. package/dist/esm/components/agent-builder/utils/sourceIcons.js.map +1 -1
  66. package/dist/esm/components/agent-listing/AgentTableRow.js +26 -23
  67. package/dist/esm/components/agent-listing/AgentTableRow.js.map +1 -1
  68. package/dist/esm/components/agent-listing/AiAgentsEmptyState.js +3 -2
  69. package/dist/esm/components/agent-listing/AiAgentsEmptyState.js.map +1 -1
  70. package/dist/esm/components/zeroState/ZeroState.d.ts +2 -0
  71. package/dist/esm/components/zeroState/ZeroState.js +18 -17
  72. package/dist/esm/components/zeroState/ZeroState.js.map +1 -1
  73. package/dist/esm/editor/BikEditor.js +236 -223
  74. package/dist/esm/editor/BikEditor.js.map +1 -1
  75. package/dist/esm/editor/BikEditor.styles.js +18 -12
  76. package/dist/esm/editor/BikEditor.styles.js.map +1 -1
  77. package/dist/esm/editor/extensions/jsonHighlight/JsonHighlightExtension.js +62 -60
  78. package/dist/esm/editor/extensions/jsonHighlight/JsonHighlightExtension.js.map +1 -1
  79. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"JsonHighlightExtension.js","sources":["../../../../../src/editor/extensions/jsonHighlight/JsonHighlightExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport type { Node as ProseMirrorNode } from '@tiptap/pm/model';\nimport { Plugin, PluginKey, TextSelection } from '@tiptap/pm/state';\nimport type { NodeView } from '@tiptap/pm/view';\nimport { Decoration, DecorationSet } from '@tiptap/pm/view';\nimport { JsonTokenType, tokenizeJson } from './tokenizeJson';\n\nconst CLASS_BY_TYPE: Record<JsonTokenType, string> = {\n\tkey: 'bik-json-key',\n\tstring: 'bik-json-string',\n\tnumber: 'bik-json-number',\n\tboolean: 'bik-json-boolean',\n\tnull: 'bik-json-null',\n\tpunctuation: 'bik-json-punct',\n};\n\n/**\n * Visual line count of a code block's text (0 → no gutter). Whitespace-only\n * content counts as 0: that's exactly when BikEditor shows the placeholder\n * overlay (`jsonEmpty = !text.trim()`), so the gutter must be empty too —\n * otherwise a blank field shows a stray \"1\" behind the placeholder.\n */\nfunction lineCount(text: string): number {\n\treturn text.trim().length === 0 ? 0 : text.split('\\n').length;\n}\n\n/**\n * Node view for the JSON `codeBlock` that renders the line-number gutter as a\n * `contenteditable=false` sibling of the editable `<code>` — NOT as ProseMirror\n * widget decorations.\n *\n * Why: widget decorations are re-inserted into the content flow on every\n * decoration recompute (i.e. every keystroke). Re-inserting a node next to the\n * caret reset the contenteditable selection to the line start, so typing a JSON\n * key and then its `:` dropped the caret to the start of the line (MAP-7286).\n * A node view lets us update the gutter DOM independently of `contentDOM`, so\n * the caret is never touched — and we only rebuild it when the line count\n * actually changes.\n */\nclass JsonCodeBlockView implements NodeView {\n\tdom: HTMLPreElement;\n\tcontentDOM: HTMLElement;\n\tprivate gutter: HTMLElement;\n\n\tconstructor(node: ProseMirrorNode) {\n\t\tconst pre = document.createElement('pre');\n\t\tconst gutter = document.createElement('div');\n\t\tgutter.className = 'bik-json-gutter';\n\t\tgutter.contentEditable = 'false';\n\t\tconst code = document.createElement('code');\n\t\t// Gutter is absolutely positioned into the reserved left padding, so its\n\t\t// order relative to <code> doesn't affect the code layout.\n\t\tpre.appendChild(gutter);\n\t\tpre.appendChild(code);\n\n\t\tthis.dom = pre;\n\t\tthis.contentDOM = code;\n\t\tthis.gutter = gutter;\n\t\tthis.renderGutter(node);\n\t}\n\n\tprivate renderGutter(node: ProseMirrorNode): void {\n\t\tconst count = lineCount(node.textContent);\n\t\t// Nothing to do while the line count is unchanged — this is the common case\n\t\t// (typing within a line) and skipping it avoids touching the gutter DOM.\n\t\tif (this.gutter.childElementCount === count) {\n\t\t\treturn;\n\t\t}\n\t\tconst numbers: HTMLElement[] = [];\n\t\tfor (let n = 1; n <= count; n++) {\n\t\t\tconst span = document.createElement('span');\n\t\t\tspan.className = 'bik-json-lineno';\n\t\t\tspan.textContent = String(n);\n\t\t\tnumbers.push(span);\n\t\t}\n\t\tthis.gutter.replaceChildren(...numbers);\n\t}\n\n\tupdate(node: ProseMirrorNode): boolean {\n\t\tif (node.type.name !== 'codeBlock') {\n\t\t\treturn false;\n\t\t}\n\t\tthis.renderGutter(node);\n\t\treturn true;\n\t}\n\n\t// The gutter is ours to manage — never let ProseMirror parse it as content.\n\tignoreMutation(mutation: MutationRecord | { target: Node }): boolean {\n\t\treturn (\n\t\t\tthis.gutter === mutation.target || this.gutter.contains(mutation.target)\n\t\t);\n\t}\n}\n\n/**\n * Colours JSON tokens inside `codeBlock` nodes and renders a line-number gutter\n * (via {@link JsonCodeBlockView}). A code block stores its whole multi-line body\n * in a single text node, so token offsets map 1:1 onto document positions\n * (`nodeStart + offset`) — no cross-node bookkeeping needed.\n *\n * Purely decorative: the document text is never rewritten, so undo/redo,\n * character count and the cursor all behave exactly as with plain text.\n */\nexport const JsonHighlightExtension = Extension.create({\n\tname: 'jsonHighlight',\n\t// Above CodeBlock (default 100) so our Backspace handler runs first and can\n\t// veto CodeBlock's own \"clearNodes at start\" shortcut (which would lift the\n\t// block to a paragraph).\n\tpriority: 1000,\n\taddKeyboardShortcuts() {\n\t\treturn {\n\t\t\t// In JSON mode the document is a single code block. A Backspace at its very\n\t\t\t// start would lift it to a plain paragraph (killing the highlight, the\n\t\t\t// line-number gutter and the monospace font). There's nothing to delete\n\t\t\t// before the caret there anyway, so swallow it. Mid-text Backspace (and\n\t\t\t// deleting a leading `\\n` from line 2+) still works — those have\n\t\t\t// parentOffset > 0.\n\t\t\tBackspace: () => {\n\t\t\t\tconst { selection } = this.editor.state;\n\t\t\t\tconst { empty, $from } = selection;\n\t\t\t\treturn (\n\t\t\t\t\tempty &&\n\t\t\t\t\t$from.parent.type.name === 'codeBlock' &&\n\t\t\t\t\t$from.parentOffset === 0\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t},\n\taddProseMirrorPlugins() {\n\t\treturn [\n\t\t\tnew Plugin({\n\t\t\t\tkey: new PluginKey('jsonHighlightGuard'),\n\t\t\t\t// jsonMode invariant: the whole document is ONE codeBlock. Several\n\t\t\t\t// default Backspace paths can lift it to a plain paragraph — and one\n\t\t\t\t// of them, TipTap core's `clearDocument` appendTransaction (fired when\n\t\t\t\t// the whole doc is selected then deleted, e.g. Cmd-A → Backspace),\n\t\t\t\t// runs AFTER our Backspace shortcut, so a keymap veto can't stop it.\n\t\t\t\t// A paragraph has no gutter and no monospace rule, so the line numbers\n\t\t\t\t// and font vanish. Re-wrap the content back into a codeBlock whenever\n\t\t\t\t// something lifts it, restoring the invariant.\n\t\t\t\tappendTransaction(transactions, _oldState, newState) {\n\t\t\t\t\tif (!transactions.some((tr) => tr.docChanged)) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tconst { doc, schema } = newState;\n\t\t\t\t\tconst codeBlock = schema.nodes['codeBlock'];\n\t\t\t\t\tif (!codeBlock) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\t// Common case: already a single codeBlock → nothing to do.\n\t\t\t\t\tif (doc.childCount === 1 && doc.firstChild?.type === codeBlock) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\t// If a codeBlock survives anywhere, leave it alone (don't fight\n\t\t\t\t\t// legitimate multi-node edits that shouldn't happen in jsonMode).\n\t\t\t\t\tlet hasCodeBlock = false;\n\t\t\t\t\tdoc.forEach((node) => {\n\t\t\t\t\t\tif (node.type === codeBlock) {\n\t\t\t\t\t\t\thasCodeBlock = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tif (hasCodeBlock) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\t// A lift happened: rebuild a single codeBlock from the text\n\t\t\t\t\t// (block boundaries preserved as newlines, matching JSON lines).\n\t\t\t\t\tconst text = doc.textBetween(0, doc.content.size, '\\n');\n\t\t\t\t\tconst tr = newState.tr;\n\t\t\t\t\ttr.replaceWith(\n\t\t\t\t\t\t0,\n\t\t\t\t\t\tdoc.content.size,\n\t\t\t\t\t\tcodeBlock.create(null, text ? schema.text(text) : null),\n\t\t\t\t\t);\n\t\t\t\t\ttr.setSelection(TextSelection.create(tr.doc, 1));\n\t\t\t\t\treturn tr;\n\t\t\t\t},\n\t\t\t}),\n\t\t\tnew Plugin({\n\t\t\t\tkey: new PluginKey('jsonHighlight'),\n\t\t\t\tprops: {\n\t\t\t\t\t// The gutter is a node view, not a widget decoration — see\n\t\t\t\t\t// JsonCodeBlockView for why (MAP-7286).\n\t\t\t\t\tnodeViews: {\n\t\t\t\t\t\tcodeBlock: (node) => new JsonCodeBlockView(node),\n\t\t\t\t\t},\n\t\t\t\t\t// Paste beautify: if the clipboard text is valid JSON, drop in a\n\t\t\t\t\t// pretty-printed version (2-space indent, matching the Beautify\n\t\t\t\t\t// button) instead of the raw blob. Non-JSON pastes fall through to\n\t\t\t\t\t// the default handler untouched.\n\t\t\t\t\thandlePaste(view, event) {\n\t\t\t\t\t\tconst raw = event.clipboardData?.getData('text/plain');\n\t\t\t\t\t\tif (!raw || !raw.trim()) {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlet value: unknown;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tvalue = JSON.parse(raw);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst pretty = JSON.stringify(value, null, 2);\n\t\t\t\t\t\t// No-op if it was already beautified (avoids a redundant tx).\n\t\t\t\t\t\tif (pretty === raw) {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst { state, dispatch } = view;\n\t\t\t\t\t\tconst { from, to } = state.selection;\n\t\t\t\t\t\tdispatch(state.tr.insertText(pretty, from, to).scrollIntoView());\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t},\n\t\t\t\t\t// Inline token colours only. Recolouring an inline span does not\n\t\t\t\t\t// disturb the caret (unlike the old gutter widgets).\n\t\t\t\t\tdecorations(state) {\n\t\t\t\t\t\tconst decorations: Decoration[] = [];\n\t\t\t\t\t\tstate.doc.descendants((node, pos) => {\n\t\t\t\t\t\t\tif (node.type.name !== 'codeBlock') return;\n\t\t\t\t\t\t\tconst text = node.textContent;\n\t\t\t\t\t\t\tif (text.length === 0) return;\n\t\t\t\t\t\t\t// +1: step past the code-block node boundary into its text.\n\t\t\t\t\t\t\tconst base = pos + 1;\n\t\t\t\t\t\t\tfor (const tok of tokenizeJson(text)) {\n\t\t\t\t\t\t\t\tdecorations.push(\n\t\t\t\t\t\t\t\t\tDecoration.inline(base + tok.start, base + tok.end, {\n\t\t\t\t\t\t\t\t\t\tclass: CLASS_BY_TYPE[tok.type],\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\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":["CLASS_BY_TYPE","lineCount","text","JsonCodeBlockView","node","pre","gutter","code","count","numbers","n","span","mutation","JsonHighlightExtension","Extension","selection","empty","$from","Plugin","PluginKey","transactions","_oldState","newState","tr","doc","schema","codeBlock","hasCodeBlock","TextSelection","view","event","raw","value","pretty","state","dispatch","from","to","decorations","pos","base","tok","tokenizeJson","Decoration","DecorationSet"],"mappings":";;;;AAOA,MAAMA,IAA+C;AAAA,EACpD,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AAAA,EACN,aAAa;AACd;AAQA,SAASC,EAAUC,GAAsB;AACxC,SAAOA,EAAK,OAAO,WAAW,IAAI,IAAIA,EAAK,MAAM;AAAA,CAAI,EAAE;AACxD;AAeA,MAAMC,EAAsC;AAAA,EAC3C;AAAA,EACA;AAAA,EACQ;AAAA,EAER,YAAYC,GAAuB;AAClC,UAAMC,IAAM,SAAS,cAAc,KAAK,GAClCC,IAAS,SAAS,cAAc,KAAK;AAC3C,IAAAA,EAAO,YAAY,mBACnBA,EAAO,kBAAkB;AACzB,UAAMC,IAAO,SAAS,cAAc,MAAM;AAG1C,IAAAF,EAAI,YAAYC,CAAM,GACtBD,EAAI,YAAYE,CAAI,GAEpB,KAAK,MAAMF,GACX,KAAK,aAAaE,GAClB,KAAK,SAASD,GACd,KAAK,aAAaF,CAAI;AAAA,EACvB;AAAA,EAEQ,aAAaA,GAA6B;AACjD,UAAMI,IAAQP,EAAUG,EAAK,WAAW;AAGxC,QAAI,KAAK,OAAO,sBAAsBI;AACrC;AAED,UAAMC,IAAyB,CAAA;AAC/B,aAASC,IAAI,GAAGA,KAAKF,GAAOE,KAAK;AAChC,YAAMC,IAAO,SAAS,cAAc,MAAM;AAC1C,MAAAA,EAAK,YAAY,mBACjBA,EAAK,cAAc,OAAOD,CAAC,GAC3BD,EAAQ,KAAKE,CAAI;AAAA,IAClB;AACA,SAAK,OAAO,gBAAgB,GAAGF,CAAO;AAAA,EACvC;AAAA,EAEA,OAAOL,GAAgC;AACtC,WAAIA,EA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XK,EAAW,OAAOH,IAAOC,EAAI,OAAOD,IAAOC,EAAI,KAAK;AAAA,oBACnD,OAAOzC,EAAcyC,EAAI,IAAI;AAAA,kBAAA,CAC7B;AAAA,gBAAA;AAAA,YAGJ,CAAC,GACMG,EAAc,OAAOV,EAAM,KAAKI,CAAW;AAAA,UACnD;AAAA,QAAA;AAAA,MACD,CACA;AAAA,IAAA;AAAA,EAEH;AACD,CAAC;"}
1
+ {"version":3,"file":"JsonHighlightExtension.js","sources":["../../../../../src/editor/extensions/jsonHighlight/JsonHighlightExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport type { Node as ProseMirrorNode } from '@tiptap/pm/model';\nimport { Plugin, PluginKey, TextSelection } from '@tiptap/pm/state';\nimport type { NodeView } from '@tiptap/pm/view';\nimport { Decoration, DecorationSet } from '@tiptap/pm/view';\nimport { JsonTokenType, tokenizeJson } from './tokenizeJson';\n\nconst CLASS_BY_TYPE: Record<JsonTokenType, string> = {\n\tkey: 'bik-json-key',\n\tstring: 'bik-json-string',\n\tnumber: 'bik-json-number',\n\tboolean: 'bik-json-boolean',\n\tnull: 'bik-json-null',\n\tpunctuation: 'bik-json-punct',\n};\n\n/**\n * Visual line count of a code block's text (0 → no gutter). Whitespace-only\n * content counts as 0: that's exactly when BikEditor shows the placeholder\n * overlay (`jsonEmpty = !text.trim()`), so the gutter must be empty too —\n * otherwise a blank field shows a stray \"1\" behind the placeholder.\n */\nfunction lineCount(text: string): number {\n\treturn text.trim().length === 0 ? 0 : text.split('\\n').length;\n}\n\n/**\n * Node view for the JSON `codeBlock` that renders the line-number gutter as a\n * `contenteditable=false` sibling of the editable `<code>` — NOT as ProseMirror\n * widget decorations.\n *\n * Why: widget decorations are re-inserted into the content flow on every\n * decoration recompute (i.e. every keystroke). Re-inserting a node next to the\n * caret reset the contenteditable selection to the line start, so typing a JSON\n * key and then its `:` dropped the caret to the start of the line (MAP-7286).\n * A node view lets us update the gutter DOM independently of `contentDOM`, so\n * the caret is never touched — and we only rebuild it when the line count\n * actually changes.\n */\nclass JsonCodeBlockView implements NodeView {\n\tdom: HTMLPreElement;\n\tcontentDOM: HTMLElement;\n\tprivate gutter: HTMLElement;\n\n\tconstructor(node: ProseMirrorNode) {\n\t\tconst pre = document.createElement('pre');\n\t\tconst gutter = document.createElement('div');\n\t\tgutter.className = 'bik-json-gutter';\n\t\tgutter.contentEditable = 'false';\n\t\tconst code = document.createElement('code');\n\t\t// Gutter is absolutely positioned into the reserved left padding, so its\n\t\t// order relative to <code> doesn't affect the code layout.\n\t\tpre.appendChild(gutter);\n\t\tpre.appendChild(code);\n\n\t\tthis.dom = pre;\n\t\tthis.contentDOM = code;\n\t\tthis.gutter = gutter;\n\t\tthis.renderGutter(node);\n\t}\n\n\tprivate renderGutter(node: ProseMirrorNode): void {\n\t\tconst count = lineCount(node.textContent);\n\t\t// Nothing to do while the line count is unchanged — this is the common case\n\t\t// (typing within a line) and skipping it avoids touching the gutter DOM.\n\t\tif (this.gutter.childElementCount === count) {\n\t\t\treturn;\n\t\t}\n\t\t// Reserve only as much left space as the widest line number needs. Floored\n\t\t// at 2 digits so JSON up to 99 lines (virtually all of it) keeps a stable\n\t\t// compact gutter; 100+ / 1000+ lines widen it (and the code's left padding)\n\t\t// a step at a time instead of always paying for 5 digits.\n\t\tconst digits = Math.max(2, String(Math.max(count, 1)).length);\n\t\tconst gutterEm = digits * 0.6 + 1.1;\n\t\tthis.gutter.style.width = `${gutterEm}em`;\n\t\tthis.dom.style.paddingLeft = `${gutterEm + 0.7}em`;\n\t\tconst numbers: HTMLElement[] = [];\n\t\tfor (let n = 1; n <= count; n++) {\n\t\t\tconst span = document.createElement('span');\n\t\t\tspan.className = 'bik-json-lineno';\n\t\t\tspan.textContent = String(n);\n\t\t\tnumbers.push(span);\n\t\t}\n\t\tthis.gutter.replaceChildren(...numbers);\n\t}\n\n\tupdate(node: ProseMirrorNode): boolean {\n\t\tif (node.type.name !== 'codeBlock') {\n\t\t\treturn false;\n\t\t}\n\t\tthis.renderGutter(node);\n\t\treturn true;\n\t}\n\n\t// The gutter is ours to manage — never let ProseMirror parse it as content.\n\tignoreMutation(mutation: MutationRecord | { target: Node }): boolean {\n\t\treturn (\n\t\t\tthis.gutter === mutation.target || this.gutter.contains(mutation.target)\n\t\t);\n\t}\n}\n\n/**\n * Colours JSON tokens inside `codeBlock` nodes and renders a line-number gutter\n * (via {@link JsonCodeBlockView}). A code block stores its whole multi-line body\n * in a single text node, so token offsets map 1:1 onto document positions\n * (`nodeStart + offset`) — no cross-node bookkeeping needed.\n *\n * Purely decorative: the document text is never rewritten, so undo/redo,\n * character count and the cursor all behave exactly as with plain text.\n */\nexport const JsonHighlightExtension = Extension.create({\n\tname: 'jsonHighlight',\n\t// Above CodeBlock (default 100) so our Backspace handler runs first and can\n\t// veto CodeBlock's own \"clearNodes at start\" shortcut (which would lift the\n\t// block to a paragraph).\n\tpriority: 1000,\n\taddKeyboardShortcuts() {\n\t\treturn {\n\t\t\t// In JSON mode the document is a single code block. A Backspace at its very\n\t\t\t// start would lift it to a plain paragraph (killing the highlight, the\n\t\t\t// line-number gutter and the monospace font). There's nothing to delete\n\t\t\t// before the caret there anyway, so swallow it. Mid-text Backspace (and\n\t\t\t// deleting a leading `\\n` from line 2+) still works — those have\n\t\t\t// parentOffset > 0.\n\t\t\tBackspace: () => {\n\t\t\t\tconst { selection } = this.editor.state;\n\t\t\t\tconst { empty, $from } = selection;\n\t\t\t\treturn (\n\t\t\t\t\tempty &&\n\t\t\t\t\t$from.parent.type.name === 'codeBlock' &&\n\t\t\t\t\t$from.parentOffset === 0\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t},\n\taddProseMirrorPlugins() {\n\t\treturn [\n\t\t\tnew Plugin({\n\t\t\t\tkey: new PluginKey('jsonHighlightGuard'),\n\t\t\t\t// jsonMode invariant: the whole document is ONE codeBlock. Several\n\t\t\t\t// default Backspace paths can lift it to a plain paragraph — and one\n\t\t\t\t// of them, TipTap core's `clearDocument` appendTransaction (fired when\n\t\t\t\t// the whole doc is selected then deleted, e.g. Cmd-A → Backspace),\n\t\t\t\t// runs AFTER our Backspace shortcut, so a keymap veto can't stop it.\n\t\t\t\t// A paragraph has no gutter and no monospace rule, so the line numbers\n\t\t\t\t// and font vanish. Re-wrap the content back into a codeBlock whenever\n\t\t\t\t// something lifts it, restoring the invariant.\n\t\t\t\tappendTransaction(transactions, _oldState, newState) {\n\t\t\t\t\tif (!transactions.some((tr) => tr.docChanged)) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tconst { doc, schema } = newState;\n\t\t\t\t\tconst codeBlock = schema.nodes['codeBlock'];\n\t\t\t\t\tif (!codeBlock) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\t// Common case: already a single codeBlock → nothing to do.\n\t\t\t\t\tif (doc.childCount === 1 && doc.firstChild?.type === codeBlock) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\t// If a codeBlock survives anywhere, leave it alone (don't fight\n\t\t\t\t\t// legitimate multi-node edits that shouldn't happen in jsonMode).\n\t\t\t\t\tlet hasCodeBlock = false;\n\t\t\t\t\tdoc.forEach((node) => {\n\t\t\t\t\t\tif (node.type === codeBlock) {\n\t\t\t\t\t\t\thasCodeBlock = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tif (hasCodeBlock) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\t// A lift happened: rebuild a single codeBlock from the text\n\t\t\t\t\t// (block boundaries preserved as newlines, matching JSON lines).\n\t\t\t\t\tconst text = doc.textBetween(0, doc.content.size, '\\n');\n\t\t\t\t\tconst tr = newState.tr;\n\t\t\t\t\ttr.replaceWith(\n\t\t\t\t\t\t0,\n\t\t\t\t\t\tdoc.content.size,\n\t\t\t\t\t\tcodeBlock.create(null, text ? schema.text(text) : null),\n\t\t\t\t\t);\n\t\t\t\t\ttr.setSelection(TextSelection.create(tr.doc, 1));\n\t\t\t\t\treturn tr;\n\t\t\t\t},\n\t\t\t}),\n\t\t\tnew Plugin({\n\t\t\t\tkey: new PluginKey('jsonHighlight'),\n\t\t\t\tprops: {\n\t\t\t\t\t// The gutter is a node view, not a widget decoration — see\n\t\t\t\t\t// JsonCodeBlockView for why (MAP-7286).\n\t\t\t\t\tnodeViews: {\n\t\t\t\t\t\tcodeBlock: (node) => new JsonCodeBlockView(node),\n\t\t\t\t\t},\n\t\t\t\t\t// Paste beautify: if the clipboard text is valid JSON, drop in a\n\t\t\t\t\t// pretty-printed version (2-space indent, matching the Beautify\n\t\t\t\t\t// button) instead of the raw blob. Non-JSON pastes fall through to\n\t\t\t\t\t// the default handler untouched.\n\t\t\t\t\thandlePaste(view, event) {\n\t\t\t\t\t\tconst raw = event.clipboardData?.getData('text/plain');\n\t\t\t\t\t\tif (!raw || !raw.trim()) {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlet value: unknown;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tvalue = JSON.parse(raw);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst pretty = JSON.stringify(value, null, 2);\n\t\t\t\t\t\t// No-op if it was already beautified (avoids a redundant tx).\n\t\t\t\t\t\tif (pretty === raw) {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst { state, dispatch } = view;\n\t\t\t\t\t\tconst { from, to } = state.selection;\n\t\t\t\t\t\tdispatch(state.tr.insertText(pretty, from, to).scrollIntoView());\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t},\n\t\t\t\t\t// Inline token colours only. Recolouring an inline span does not\n\t\t\t\t\t// disturb the caret (unlike the old gutter widgets).\n\t\t\t\t\tdecorations(state) {\n\t\t\t\t\t\tconst decorations: Decoration[] = [];\n\t\t\t\t\t\tstate.doc.descendants((node, pos) => {\n\t\t\t\t\t\t\tif (node.type.name !== 'codeBlock') return;\n\t\t\t\t\t\t\tconst text = node.textContent;\n\t\t\t\t\t\t\tif (text.length === 0) return;\n\t\t\t\t\t\t\t// +1: step past the code-block node boundary into its text.\n\t\t\t\t\t\t\tconst base = pos + 1;\n\t\t\t\t\t\t\tfor (const tok of tokenizeJson(text)) {\n\t\t\t\t\t\t\t\tdecorations.push(\n\t\t\t\t\t\t\t\t\tDecoration.inline(base + tok.start, base + tok.end, {\n\t\t\t\t\t\t\t\t\t\tclass: CLASS_BY_TYPE[tok.type],\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\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":["CLASS_BY_TYPE","lineCount","text","JsonCodeBlockView","node","pre","gutter","code","count","gutterEm","numbers","n","span","mutation","JsonHighlightExtension","Extension","selection","empty","$from","Plugin","PluginKey","transactions","_oldState","newState","tr","doc","schema","codeBlock","hasCodeBlock","TextSelection","view","event","raw","value","pretty","state","dispatch","from","to","decorations","pos","base","tok","tokenizeJson","Decoration","DecorationSet"],"mappings":";;;;AAOA,MAAMA,IAA+C;AAAA,EACpD,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,MAAM;AAAA,EACN,aAAa;AACd;AAQA,SAASC,EAAUC,GAAsB;AACxC,SAAOA,EAAK,OAAO,WAAW,IAAI,IAAIA,EAAK,MAAM;AAAA,CAAI,EAAE;AACxD;AAeA,MAAMC,EAAsC;AAAA,EAC3C;AAAA,EACA;AAAA,EACQ;AAAA,EAER,YAAYC,GAAuB;AAClC,UAAMC,IAAM,SAAS,cAAc,KAAK,GAClCC,IAAS,SAAS,cAAc,KAAK;AAC3C,IAAAA,EAAO,YAAY,mBACnBA,EAAO,kBAAkB;AACzB,U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AMD,EAAM,eAAe,QAAQ,YAAY;AACrD,gBAAI,CAACC,KAAO,CAACA,EAAI;AAChB,qBAAO;AAER,gBAAIC;AACJ,gBAAI;AACH,cAAAA,IAAQ,KAAK,MAAMD,CAAG;AAAA,YACvB,QAAQ;AACP,qBAAO;AAAA,YACR;AACA,kBAAME,IAAS,KAAK,UAAUD,GAAO,MAAM,CAAC;AAE5C,gBAAIC,MAAWF;AACd,qBAAO;AAER,kBAAM,EAAE,OAAAG,GAAO,UAAAC,EAAA,IAAaN,GACtB,EAAE,MAAAO,GAAM,IAAAC,EAAA,IAAOH,EAAM;AAC3B,mBAAAC,EAASD,EAAM,GAAG,WAAWD,GAAQG,GAAMC,CAAE,EAAE,gBAAgB,GACxD;AAAA,UACR;AAAA;AAAA;AAAA,UAGA,YAAYH,GAAO;AAClB,kBAAMI,IAA4B,CAAA;AAClC,mBAAAJ,EAAM,IAAI,YAAY,CAAC/B,GAAMoC,MAAQ;AACpC,kBAAIpC,EAAK,KAAK,SAAS,YAAa;AACpC,oBAAMF,IAAOE,EAAK;AAClB,kBAAIF,EAAK,WAAW,EAAG;AAEvB,oBAAMuC,IAAOD,IAAM;AACnB,yBAAWE,KAAOC,EAAazC,CAAI;AAClC,gBAAAqC,EAAY;AAAA,kBACXK,EAAW,OAAOH,IAAOC,EAAI,OAAOD,IAAOC,EAAI,KAAK;AAAA,oBACnD,OAAO1C,EAAc0C,EAAI,IAAI;AAAA,kBAAA,CAC7B;AAAA,gBAAA;AAAA,YAGJ,CAAC,GACMG,EAAc,OAAOV,EAAM,KAAKI,CAAW;AAAA,UACnD;AAAA,QAAA;AAAA,MACD,CACA;AAAA,IAAA;AAAA,EAEH;AACD,CAAC;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.852",
3
+ "version": "0.0.853",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",