@g9tm/lynxcontrols-richtext 2.5.9 → 2.5.11
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/catalog/catalog.json +1 -1
- package/catalog/index.md +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/bidi.js +104 -0
- package/dist/bidi.js.map +1 -0
- package/dist/editor.js +558 -0
- package/dist/editor.js.map +1 -0
- package/dist/element-core.js +175 -0
- package/dist/element-core.js.map +1 -0
- package/dist/element-types.js +1 -0
- package/dist/index.js +8 -0
- package/dist/lines-view.js +102 -0
- package/dist/lines-view.js.map +1 -0
- package/dist/mentions.js +42 -0
- package/dist/mentions.js.map +1 -0
- package/dist/ot.js +308 -0
- package/dist/ot.js.map +1 -0
- package/dist/protocol.js +13 -0
- package/dist/protocol.js.map +1 -0
- package/dist/rich-text.js +188 -0
- package/dist/rich-text.js.map +1 -0
- package/dist/session.js +667 -0
- package/dist/session.js.map +1 -0
- package/dist/yjs.js +2 -0
- package/dist/ymodel.js +1381 -0
- package/dist/ymodel.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.js","sources":["../src/editor.tsx"],"sourcesContent":["// G9RichTextEditor (2.5.8, from G9Hub's DocEditor and Toolbar): one live document over `<g9-richtext>` — the toolbar\n// (undo, redo, the block's style, marks, link, lists with indent, quote, callout and its tone, the direction, insert),\n// suggestions while typing (`/` blocks, `@` people, `[[` links) and everyone's carets (the session's awareness). Readers\n// get the same surface without the toolbar. Phones: the toolbar sits at the bottom while the text has the focus; wide\n// windows: at the top. The session (`@g9tm/lynxcontrols-richtext/yjs`) is the app's: {@link useG9RichTextSession}.\nimport { g9IdProps } from '@g9tm/lynxcontrols/base';\nimport { G9Avatar } from '@g9tm/lynxcontrols/display';\nimport { G9Menu, type G9MenuItem } from '@g9tm/lynxcontrols/popover';\nimport { useG9Direction, useG9Layout } from '@g9tm/lynxcontrols/provider';\nimport { type ReactNode, useEffect, useMemo, useRef, useState } from '@lynx-js/react';\nimport { nextDirection } from './bidi';\nimport type { RtPalette } from './protocol';\nimport { G9RichText, G9RichTextPort } from './rich-text';\nimport type { RichTextSession, SelectionState } from './session';\nimport type { CalloutTone } from './ymodel';\nimport './richtext.css';\n\n/** The editor's words (the app's language); English when left out. */\nexport interface G9RichTextEditorLabels {\n readonly undo?: string;\n readonly redo?: string;\n readonly style?: string;\n readonly text?: string;\n readonly h1?: string;\n readonly h2?: string;\n readonly h3?: string;\n readonly bold?: string;\n readonly italic?: string;\n readonly underline?: string;\n readonly strike?: string;\n readonly code?: string;\n readonly link?: string;\n readonly unlink?: string;\n readonly bullet?: string;\n readonly numbered?: string;\n readonly checklist?: string;\n readonly indent?: string;\n readonly outdent?: string;\n readonly quote?: string;\n readonly callout?: string;\n readonly callouts?: Partial<Readonly<Record<CalloutTone, string>>>;\n readonly directionAuto?: string;\n readonly directionRtl?: string;\n readonly directionLtr?: string;\n readonly insert?: string;\n readonly table?: string;\n readonly image?: string;\n readonly codeBlock?: string;\n readonly divider?: string;\n readonly date?: string;\n readonly mention?: string;\n readonly linkTo?: string;\n readonly close?: string;\n}\n\nconst EN: Required<Omit<G9RichTextEditorLabels, 'callouts'>> & { callouts: Record<CalloutTone, string> } = {\n undo: 'Undo',\n redo: 'Redo',\n style: 'Style',\n text: 'Text',\n h1: 'Heading 1',\n h2: 'Heading 2',\n h3: 'Heading 3',\n bold: 'Bold',\n italic: 'Italic',\n underline: 'Underline',\n strike: 'Strikethrough',\n code: 'Code',\n link: 'Link',\n unlink: 'Remove link',\n bullet: 'Bulleted list',\n numbered: 'Numbered list',\n checklist: 'Checklist',\n indent: 'Indent',\n outdent: 'Outdent',\n quote: 'Quote',\n callout: 'Callout',\n callouts: { info: 'Info', success: 'Success', warning: 'Warning', danger: 'Danger' },\n directionAuto: 'Direction: automatic',\n directionRtl: 'Right to left',\n directionLtr: 'Left to right',\n insert: 'Insert',\n table: 'Table',\n image: 'Picture',\n codeBlock: 'Code block',\n divider: 'Divider',\n date: 'Date',\n mention: 'Mention',\n linkTo: 'Link to…',\n close: 'Close',\n};\n\n/** A person `@` suggests. */\nexport interface G9RichMention {\n readonly id: string;\n readonly name: string;\n readonly image?: string | null;\n}\n\n/** A target `[[` suggests (a task, a document, a meeting). */\nexport interface G9RichLinkOption {\n readonly id: string;\n readonly label: string;\n readonly sub?: string;\n /** What the chip opens. */\n readonly href: string;\n /** Its kind (the chip's look: `task`, `doc` …). */\n readonly kind: string;\n}\n\n/** A session with the port and the toolbar's tick. */\nexport interface G9RichTextSessionHandle<S> {\n readonly session: S | null;\n readonly port: G9RichTextPort;\n /** Grows with every change of the text, the selection or the marks there. */\n readonly version: number;\n /** Call from the session's `onState` (or pass `onState` here to the session). */\n readonly onState: () => void;\n}\n\n/**\n * Makes the app's session after mount (never during a render) with the editor's port and a throttled state callback,\n * and destroys it on unmount or when `deps` change.\n */\nexport function useG9RichTextSession<S extends { destroy?: () => void }>(\n create: (port: G9RichTextPort, onState: () => void) => S,\n deps: readonly unknown[],\n): G9RichTextSessionHandle<S> {\n const port = useMemo(() => new G9RichTextPort(), []);\n const [session, setSession] = useState<S | null>(null);\n const [version, setVersion] = useState(0);\n const timer = useRef<ReturnType<typeof setTimeout> | null>(null);\n const onState = useMemo(\n () => () => {\n if (timer.current) return;\n timer.current = setTimeout(() => {\n timer.current = null;\n setVersion((v) => v + 1);\n }, 30);\n },\n [],\n );\n useEffect(() => {\n const s = create(port, onState);\n setSession(s);\n return () => {\n if (timer.current) clearTimeout(timer.current);\n timer.current = null;\n s.destroy?.();\n setSession(null);\n };\n }, deps);\n return { session, port, version, onState };\n}\n\n/** Props of {@link G9RichTextEditor}. */\nexport interface G9RichTextEditorProps {\n readonly id?: string;\n readonly session: RichTextSession | null;\n readonly port: G9RichTextPort;\n /** The session's version ({@link useG9RichTextSession}): the toolbar and suggestions follow it. */\n readonly version: number;\n readonly editable: boolean;\n readonly placeholder: string;\n readonly labels?: G9RichTextEditorLabels;\n readonly surface?: 'element' | 'drawn';\n /** `'auto'` (default): the bottom on a phone while the text has the focus, else the top. */\n readonly toolbar?: 'auto' | 'top' | 'bottom' | 'none';\n readonly palette?: RtPalette;\n /** `@`: the people to suggest. */\n readonly people?: (query: string) => Promise<readonly G9RichMention[]>;\n /** `[[`: the targets to link. */\n readonly links?: (query: string) => Promise<readonly G9RichLinkOption[]>;\n /** Picks and uploads a picture: its storage key (null when cancelled). */\n readonly uploadImage?: () => Promise<{ readonly key: string; readonly alt: string } | null>;\n /** Asks for a link's address (the app's dialog); null when cancelled. */\n readonly promptLink?: () => Promise<string | null>;\n /** Today as `YYYY-MM-DD` (the date chip). */\n readonly today?: () => string;\n /** A chip tapped. */\n readonly onOpenLink?: (href: string) => void;\n /** Under the text (a word count); on a phone hidden while the toolbar is up. */\n readonly footer?: ReactNode;\n readonly className?: string;\n}\n\ntype Trigger = { kind: 'slash' | 'mention' | 'link'; from: number; to: number; query: string };\n\ninterface Suggestion {\n readonly id: string;\n readonly label: string;\n readonly sub?: string;\n readonly glyph?: string;\n readonly person?: G9RichMention;\n readonly run: () => void;\n}\n\nconst isoToday = () => {\n const d = new Date();\n return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;\n};\n\n/** The live document's editor: the element, the toolbar and the suggestions. */\nexport function G9RichTextEditor(props: G9RichTextEditorProps): ReactNode {\n const { wide } = useG9Layout();\n const rtl = useG9Direction() === 'rtl';\n const L = { ...EN, ...props.labels, callouts: { ...EN.callouts, ...props.labels?.callouts } };\n const session = props.session;\n const [focused, setFocused] = useState(false);\n const [found, setFound] = useState<Suggestion[]>([]);\n const [dismissed, setDismissed] = useState<string | null>(null);\n const today = props.today ?? isoToday;\n\n const trigger = useMemo<Trigger | null>(() => {\n if (!session || !props.editable || !focused) return null;\n const { a, h } = session.sel;\n if (a !== h) return null;\n const text = session.plainText;\n const before = text.slice(text.lastIndexOf('\\n', h - 1) + 1, h);\n if (session.state().block === 'code') return null;\n let m = /\\[\\[([^\\]\\n]{0,40})$/.exec(before);\n if (m && props.links) return { kind: 'link', from: h - m[0].length, to: h, query: m[1] as string };\n m = /(?:^|[\\s(])@([^@\\n]{0,30})$/.exec(before);\n if (m && props.people && !/\\s\\s$/.test(m[1] as string))\n return { kind: 'mention', from: h - (m[1] as string).length - 1, to: h, query: m[1] as string };\n m = /(?:^|\\s)\\/([^\\s/]{0,20})$/.exec(before);\n if (m) return { kind: 'slash', from: h - (m[1] as string).length - 1, to: h, query: m[1] as string };\n return null;\n }, [props.version, focused, props.editable, session]);\n const triggerKey = trigger ? `${trigger.kind}:${trigger.from}` : null;\n\n const range = () => {\n const { a, h } = (session as RichTextSession).sel;\n return [Math.min(a, h), Math.max(a, h)] as const;\n };\n const run = (fn: (from: number, to: number) => void) => () => {\n const [from, to] = range();\n session?.command(() => fn(from, to));\n };\n const insertPicture = async () => {\n const picked = await props.uploadImage?.();\n if (picked && session) session.insertBlock('image', { key: picked.key, alt: picked.alt });\n };\n\n const slashItems = (at: Trigger): Suggestion[] => {\n const s = session as RichTextSession;\n const remove = () => s.replaceText(at.from, at.to, '');\n const block = (fn: (from: number, to: number) => void) => () => {\n remove();\n const [from, to] = range();\n s.command(() => fn(from, to));\n };\n const all: (Suggestion & { keywords: string })[] = [\n {\n id: 'text',\n label: L.text,\n glyph: '¶',\n keywords: 'text paragraph متن',\n run: block((f, t) => s.model.setBlockType(f, t, 'p')),\n },\n {\n id: 'h1',\n label: L.h1,\n glyph: 'H1',\n keywords: 'h1 heading title عنوان',\n run: block((f, t) => s.model.setBlockType(f, t, 'h1')),\n },\n {\n id: 'h2',\n label: L.h2,\n glyph: 'H2',\n keywords: 'h2 heading عنوان',\n run: block((f, t) => s.model.setBlockType(f, t, 'h2')),\n },\n {\n id: 'h3',\n label: L.h3,\n glyph: 'H3',\n keywords: 'h3 heading عنوان',\n run: block((f, t) => s.model.setBlockType(f, t, 'h3')),\n },\n {\n id: 'bullet',\n label: L.bullet,\n glyph: '•',\n keywords: 'bullet list ul فهرست',\n run: block((f, t) => s.model.toggleList(f, t, 'bullet')),\n },\n {\n id: 'numbered',\n label: L.numbered,\n glyph: '1.',\n keywords: 'numbered ordered list شماره',\n run: block((f, t) => s.model.toggleList(f, t, 'ordered')),\n },\n {\n id: 'checklist',\n label: L.checklist,\n glyph: '☑',\n keywords: 'todo task check کار چک',\n run: block((f, t) => s.model.toggleList(f, t, 'task')),\n },\n {\n id: 'quote',\n label: L.quote,\n glyph: '❝',\n keywords: 'quote نقل',\n run: block((f, t) => s.model.toggleQuote(f, t)),\n },\n {\n id: 'callout',\n label: L.callout,\n glyph: 'ⓘ',\n keywords: 'callout note info نکته',\n run: block((f, t) => s.model.toggleCallout(f, t, 'info')),\n },\n {\n id: 'code',\n label: L.codeBlock,\n glyph: '</>',\n keywords: 'code pre کد',\n run: block((f, t) => s.model.setBlockType(f, t, 'code')),\n },\n {\n id: 'table',\n label: L.table,\n glyph: '▦',\n keywords: 'table grid جدول',\n run: () => (remove(), s.insertBlock('table', { rows: 3, cols: 3, header: true })),\n },\n ...(props.uploadImage\n ? [\n {\n id: 'image',\n label: L.image,\n glyph: '🖼',\n keywords: 'image picture photo تصویر عکس',\n run: () => (remove(), void insertPicture()),\n },\n ]\n : []),\n {\n id: 'divider',\n label: L.divider,\n glyph: '—',\n keywords: 'divider hr line خط',\n run: () => (remove(), s.insertBlock('hr')),\n },\n {\n id: 'date',\n label: L.date,\n glyph: '📅',\n keywords: 'date today تاریخ امروز',\n run: () => s.insertInline('dateChip', { date: today() }, { from: at.from, to: at.to }),\n },\n ...(props.people\n ? [\n {\n id: 'mention',\n label: L.mention,\n glyph: '@',\n keywords: 'mention person اشاره',\n run: () => s.replaceText(at.from, at.to, '@'),\n },\n ]\n : []),\n ...(props.links\n ? [\n {\n id: 'link',\n label: L.linkTo,\n glyph: '🔗',\n keywords: 'link task doc پیوند',\n run: () => s.replaceText(at.from, at.to, '[['),\n },\n ]\n : []),\n ];\n const q = at.query.trim().toLowerCase();\n return all.filter((i) => !q || i.label.toLowerCase().includes(q) || i.keywords.includes(q)).slice(0, 12);\n };\n\n useEffect(() => {\n if (!session || !trigger || dismissed === triggerKey) {\n setFound([]);\n return;\n }\n let cancelled = false;\n const go = async () => {\n if (trigger.kind === 'slash') {\n setFound(slashItems(trigger));\n return;\n }\n if (trigger.kind === 'mention') {\n const list = await (props.people as NonNullable<typeof props.people>)(trigger.query).catch(() => []);\n if (!cancelled)\n setFound(\n list.slice(0, 8).map((p) => ({\n id: p.id,\n label: p.name,\n person: p,\n run: () =>\n session.insertInline(\n 'mention',\n { id: p.id, label: p.name, mentionSuggestionChar: '@' },\n { from: trigger.from, to: trigger.to },\n ),\n })),\n );\n return;\n }\n const options = await (props.links as NonNullable<typeof props.links>)(trigger.query).catch(() => []);\n if (!cancelled)\n setFound(\n options.slice(0, 8).map((o) => ({\n id: o.id,\n label: o.label,\n ...(o.sub ? { sub: o.sub } : {}),\n glyph: '🔗',\n run: () =>\n session.insertInline('refChip', { href: o.href, kind: o.kind }, { from: trigger.from, to: trigger.to }),\n })),\n );\n };\n const timer = setTimeout(() => void go(), trigger.kind === 'slash' ? 0 : 150);\n return () => {\n cancelled = true;\n clearTimeout(timer);\n };\n }, [triggerKey, trigger?.query, dismissed]);\n\n const state: SelectionState | null = props.editable && session ? session.state() : null;\n const placement = props.toolbar ?? 'auto';\n const bottom = placement === 'bottom' || (placement === 'auto' && !wide);\n const showToolbar = placement !== 'none' && state && session && (!bottom || placement === 'bottom' || focused);\n const toolbar =\n showToolbar && state && session ? (\n <Toolbar\n {...(props.id ? { id: `${props.id}_Toolbar` } : {})}\n session={session}\n state={state}\n labels={L}\n rtl={rtl}\n run={run}\n today={today}\n {...(props.uploadImage ? { onPicture: () => void insertPicture() } : {})}\n {...(props.promptLink ? { promptLink: props.promptLink } : {})}\n mentions={props.people !== undefined}\n links={props.links !== undefined}\n />\n ) : null;\n const suggestions =\n found.length > 0 && trigger && dismissed !== triggerKey ? (\n <scroll-view className=\"g9-rt-suggest\" scroll-orientation=\"vertical\">\n {found.map((item) => (\n <view\n key={item.id}\n className=\"g9-rt-suggest__row\"\n {...g9IdProps(props.id ? `${props.id}_Suggest_${item.id}` : undefined)}\n style={{ flexDirection: rtl ? 'row-reverse' : 'row', direction: 'ltr' }}\n bindtap={() => item.run()}\n accessibility-element={true}\n accessibility-traits=\"button\"\n accessibility-label={item.sub ? `${item.label}, ${item.sub}` : item.label}\n >\n {item.person ? (\n <G9Avatar name={item.person.name} image={item.person.image ?? null} size={24} />\n ) : (\n <text className=\"g9-rt-suggest__glyph\">{item.glyph ?? ''}</text>\n )}\n <view className=\"g9-rt-suggest__texts\">\n <text className=\"g9-rt-suggest__label\" text-maxline=\"1\" style={{ textAlign: rtl ? 'right' : 'left' }}>\n {item.label}\n </text>\n {item.sub ? (\n <text className=\"g9-rt-suggest__sub\" text-maxline=\"1\" style={{ textAlign: rtl ? 'right' : 'left' }}>\n {item.sub}\n </text>\n ) : null}\n </view>\n </view>\n ))}\n <view\n className=\"g9-rt-suggest__row\"\n {...g9IdProps(props.id ? `${props.id}_Suggest_Close` : undefined)}\n bindtap={() => setDismissed(triggerKey)}\n accessibility-element={true}\n accessibility-traits=\"button\"\n accessibility-label={L.close}\n >\n <text className=\"g9-rt-suggest__sub\">{`✕ ${L.close}`}</text>\n </view>\n </scroll-view>\n ) : null;\n\n if (!session) return <view className=\"g9-rt-editor\" />;\n return (\n <view className={`g9-rt-editor${props.className ? ` ${props.className}` : ''}`} {...g9IdProps(props.id)}>\n {!bottom && toolbar ? <view className=\"g9-rt-toolbar g9-rt-toolbar--top\">{toolbar}</view> : null}\n <G9RichText\n session={session}\n port={props.port}\n editable={props.editable}\n placeholder={props.placeholder}\n className=\"g9-rt-editor__surface\"\n {...(props.surface ? { surface: props.surface } : {})}\n {...(props.palette ? { palette: props.palette } : {})}\n onFocusChange={setFocused}\n onTapObject={(pos) => {\n const inline = session.model.inlineAt(pos);\n if (inline?.name === 'refChip' && typeof inline.attrs.href === 'string')\n props.onOpenLink?.(inline.attrs.href);\n }}\n />\n {suggestions}\n {bottom && toolbar ? <view className=\"g9-rt-toolbar g9-rt-toolbar--bottom\">{toolbar}</view> : props.footer}\n </view>\n );\n}\n\nfunction Tool(props: {\n readonly id?: string | undefined;\n readonly glyph: string;\n readonly label: string;\n readonly active?: boolean;\n readonly disabled?: boolean;\n readonly onPress: () => void;\n readonly className?: string;\n}): ReactNode {\n return (\n <view\n className={`g9-rt-tool${props.active ? ' g9-rt-tool--on' : ''}${props.disabled ? ' g9-rt-tool--off' : ''}`}\n {...g9IdProps(props.id)}\n {...(props.disabled ? {} : { bindtap: props.onPress })}\n accessibility-element={true}\n accessibility-traits=\"button\"\n accessibility-label={props.label}\n {...(props.active ? { 'accessibility-value': '✓' } : {})}\n >\n <text className={`g9-rt-tool__glyph${props.className ? ` ${props.className}` : ''}`}>{props.glyph}</text>\n </view>\n );\n}\n\nfunction Toolbar(props: {\n readonly id?: string;\n readonly session: RichTextSession;\n readonly state: SelectionState;\n readonly labels: typeof EN;\n readonly rtl: boolean;\n readonly run: (fn: (from: number, to: number) => void) => () => void;\n readonly today: () => string;\n readonly onPicture?: () => void;\n readonly promptLink?: () => Promise<string | null>;\n readonly mentions: boolean;\n readonly links: boolean;\n}): ReactNode {\n const { session, state, run } = props;\n const L = props.labels;\n const [menu, setMenu] = useState<'style' | 'insert' | 'tone' | null>(null);\n const id = (s: string) => (props.id ? `${props.id}_${s}` : undefined);\n const has = (mark: string) => mark in state.marks;\n const blockLabel = state.block === 'h1' ? L.h1 : state.block === 'h2' ? L.h2 : state.block === 'h3' ? L.h3 : L.text;\n const link = async () => {\n if (has('link')) {\n session.setLink(null);\n return;\n }\n const href = (await props.promptLink?.())?.trim();\n if (!href) return;\n const clean = /^[a-z][a-z0-9+.-]*:/i.test(href) ? href : `https://${href}`;\n if (/^(https?|mailto|tel):/i.test(clean)) session.setLink(clean);\n };\n const styleItems: G9MenuItem[] = (['p', 'h1', 'h2', 'h3'] as const).map((b) => ({\n key: b,\n label: b === 'p' ? L.text : L[b],\n checked: state.block === b,\n }));\n const insertItems: G9MenuItem[] = [\n { key: 'table', label: L.table },\n ...(props.onPicture ? [{ key: 'image', label: L.image }] : []),\n { key: 'code', label: L.codeBlock },\n { key: 'divider', label: L.divider },\n { key: 'date', label: L.date },\n ...(props.mentions ? [{ key: 'mention', label: L.mention, separatorBefore: true }] : []),\n ...(props.links ? [{ key: 'link', label: L.linkTo, ...(props.mentions ? {} : { separatorBefore: true }) }] : []),\n ];\n const toneItems: G9MenuItem[] = (['info', 'success', 'warning', 'danger'] as const).map((t) => ({\n key: t,\n label: L.callouts[t],\n checked: state.callout === t,\n }));\n const insert = (key: string) => {\n const pos = () => {\n const { a, h } = session.sel;\n return [Math.min(a, h), Math.max(a, h)] as const;\n };\n if (key === 'table') session.insertBlock('table', { rows: 3, cols: 3, header: true });\n else if (key === 'image') props.onPicture?.();\n else if (key === 'code') run((f, t) => session.model.setBlockType(f, t, 'code'))();\n else if (key === 'divider') session.insertBlock('hr');\n else if (key === 'date') session.insertInline('dateChip', { date: props.today() });\n else {\n const [from, to] = pos();\n session.replaceText(from, to, key === 'mention' ? ' @' : ' [[');\n session.focus();\n }\n };\n const dirGlyph = state.dir === 'rtl' ? '⇠¶' : state.dir === 'ltr' ? '¶⇢' : '⇄';\n const dirLabel = state.dir === 'rtl' ? L.directionRtl : state.dir === 'ltr' ? L.directionLtr : L.directionAuto;\n return (\n <view>\n <scroll-view scroll-orientation=\"horizontal\" className=\"g9-rt-toolbar__scroll\">\n <view\n className=\"g9-rt-toolbar__row\"\n style={{ flexDirection: props.rtl ? 'row-reverse' : 'row', direction: 'ltr' }}\n >\n <Tool\n id={id('Undo')}\n glyph={props.rtl ? '↷' : '↶'}\n label={L.undo}\n disabled={!session.canUndo}\n onPress={() => session.undo()}\n />\n <Tool\n id={id('Redo')}\n glyph={props.rtl ? '↶' : '↷'}\n label={L.redo}\n disabled={!session.canRedo}\n onPress={() => session.redo()}\n />\n <view className=\"g9-rt-toolbar__sep\" />\n <view\n className=\"g9-rt-toolbar__style\"\n {...g9IdProps(id('Style'))}\n bindtap={() => setMenu('style')}\n accessibility-element={true}\n accessibility-traits=\"button\"\n accessibility-label={`${L.style}: ${blockLabel}`}\n >\n <text className=\"g9-rt-toolbar__style-text\">{`${blockLabel} ▾`}</text>\n </view>\n <view className=\"g9-rt-toolbar__sep\" />\n <Tool\n id={id('Bold')}\n glyph=\"B\"\n className=\"g9-rt-tool__glyph--b\"\n label={L.bold}\n active={has('bold')}\n onPress={() => session.toggleMark('bold')}\n />\n <Tool\n id={id('Italic')}\n glyph=\"I\"\n className=\"g9-rt-tool__glyph--i\"\n label={L.italic}\n active={has('italic')}\n onPress={() => session.toggleMark('italic')}\n />\n <Tool\n id={id('Underline')}\n glyph=\"U\"\n className=\"g9-rt-tool__glyph--u\"\n label={L.underline}\n active={has('underline')}\n onPress={() => session.toggleMark('underline')}\n />\n <Tool\n id={id('Strike')}\n glyph=\"S\"\n className=\"g9-rt-tool__glyph--s\"\n label={L.strike}\n active={has('strike')}\n onPress={() => session.toggleMark('strike')}\n />\n <Tool\n id={id('Code')}\n glyph=\"</>\"\n label={L.code}\n active={has('code')}\n onPress={() => session.toggleMark('code')}\n />\n {props.promptLink || has('link') ? (\n <Tool\n id={id('Link')}\n glyph=\"🔗\"\n label={has('link') ? L.unlink : L.link}\n active={has('link')}\n onPress={() => void link()}\n />\n ) : null}\n <view className=\"g9-rt-toolbar__sep\" />\n <Tool\n id={id('Bullet')}\n glyph=\"•\"\n label={L.bullet}\n active={state.list === 'bullet'}\n onPress={run((f, t) => session.model.toggleList(f, t, 'bullet'))}\n />\n <Tool\n id={id('Numbered')}\n glyph=\"1.\"\n label={L.numbered}\n active={state.list === 'ordered'}\n onPress={run((f, t) => session.model.toggleList(f, t, 'ordered'))}\n />\n <Tool\n id={id('Checklist')}\n glyph=\"☑\"\n label={L.checklist}\n active={state.list === 'task'}\n onPress={run((f, t) => session.model.toggleList(f, t, 'task'))}\n />\n {state.list ? (\n <>\n <Tool\n id={id('Outdent')}\n glyph={props.rtl ? '⇥' : '⇤'}\n label={L.outdent}\n disabled={!state.canOutdent}\n onPress={run((f, t) => session.model.outdent(f, t))}\n />\n <Tool\n id={id('Indent')}\n glyph={props.rtl ? '⇤' : '⇥'}\n label={L.indent}\n disabled={!state.canIndent}\n onPress={run((f, t) => session.model.indent(f, t))}\n />\n </>\n ) : null}\n <Tool\n id={id('Quote')}\n glyph=\"❝\"\n label={L.quote}\n active={state.quote}\n onPress={run((f, t) => session.model.toggleQuote(f, t))}\n />\n <Tool\n id={id('Callout')}\n glyph=\"ⓘ\"\n label={L.callout}\n active={Boolean(state.callout)}\n onPress={() =>\n state.callout ? setMenu('tone') : run((f, t) => session.model.toggleCallout(f, t, 'info'))()\n }\n />\n <Tool\n id={id('Direction')}\n glyph={dirGlyph}\n label={dirLabel}\n active={state.dir !== null}\n onPress={run((f, t) => session.model.setDirection(f, t, nextDirection(state.dir)))}\n />\n <view className=\"g9-rt-toolbar__sep\" />\n <Tool id={id('Insert')} glyph=\"+\" label={L.insert} onPress={() => setMenu('insert')} />\n </view>\n </scroll-view>\n <G9Menu\n open={menu !== null}\n onClose={() => setMenu(null)}\n {...(props.id ? { id: `${props.id}_Menu` } : {})}\n {...(id(menu === 'style' ? 'Style' : menu === 'tone' ? 'Callout' : 'Insert')\n ? { anchorId: id(menu === 'style' ? 'Style' : menu === 'tone' ? 'Callout' : 'Insert') as string }\n : {})}\n title={menu === 'style' ? L.style : menu === 'tone' ? L.callout : L.insert}\n items={menu === 'style' ? styleItems : menu === 'tone' ? toneItems : insertItems}\n onSelect={(key) => {\n if (menu === 'style') run((f, t) => session.model.setBlockType(f, t, key as 'p' | 'h1' | 'h2' | 'h3'))();\n else if (menu === 'tone')\n session.command(() =>\n session.model.setCalloutTone(Math.max(session.sel.a, session.sel.h), key as CalloutTone),\n );\n else insert(key);\n }}\n />\n </view>\n );\n}\n"],"names":["EN","useG9RichTextSession","create","deps","port","useMemo","G9RichTextPort","session","setSession","useState","version","setVersion","timer","useRef","onState","setTimeout","v","useEffect","s","clearTimeout","isoToday","d","Date","String","G9RichTextEditor","props","_props_today","_props_toolbar","_props_labels","wide","useG9Layout","rtl","useG9Direction","L","focused","setFocused","found","setFound","dismissed","setDismissed","today","trigger","a","h","text1","before","m","triggerKey","range","Math","run","fn","from","to","insertPicture","picked","slashItems","at","remove","block","all","f","t","q","i","cancelled","go","list","p","options","o","state","placement","bottom","showToolbar","toolbar","Toolbar","undefined","suggestions","scroll-view","item","_item_person_image","_item_glyph","view","g9IdProps","G9Avatar","text","G9RichText","pos","inline","Tool","menu","setMenu","id","has","mark","blockLabel","link","_this","href","clean","styleItems","b","insertItems","toneItems","insert","key","dirGlyph","dirLabel","Boolean","nextDirection","G9Menu"],"mappings":";;;;;;;;AAuDA,MAAMA,KAAqG;IACzG,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,MAAM;IACN,QAAQ;IACR,WAAW;IACX,QAAQ;IACR,MAAM;IACN,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,WAAW;IACX,QAAQ;IACR,SAAS;IACT,OAAO;IACP,SAAS;IACT,UAAU;QAAE,MAAM;QAAQ,SAAS;QAAW,SAAS;QAAW,QAAQ;IAAS;IACnF,eAAe;IACf,cAAc;IACd,cAAc;IACd,QAAQ;IACR,OAAO;IACP,OAAO;IACP,WAAW;IACX,SAAS;IACT,MAAM;IACN,SAAS;IACT,QAAQ;IACR,OAAO;AACT;AAkCO,SAASC,qBACdC,MAAwD,EACxDC,IAAwB;IAExB,MAAMC,OAAOC,QAAQ,IAAM,IAAIC,kBAAkB,EAAE;IACnD,MAAM,CAACC,SAASC,WAAW,GAAGC,SAAmB;IACjD,MAAM,CAACC,SAASC,WAAW,GAAGF,SAAS;IACvC,MAAMG,QAAQC,OAA6C;IAC3D,M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AI,GAAGA,MAAM,EAAE,CAAC,KAAK,CAAC;IAAC,IAAI,CAAC,CAAC,GAC9C,GAAIoE,GAAGF,AAAS,YAATA,OAAmB,UAAUA,AAAS,WAATA,OAAkB,YAAY,YAC/D;QAAE,UAAUE,GAAGF,AAAS,YAATA,OAAmB,UAAUA,AAAS,WAATA,OAAkB,YAAY;IAAoB,IAC9F,CAAC,CAAC,EACN,OAAOA,AAAS,YAATA,OAAmB1D,EAAE,KAAK,GAAG0D,AAAS,WAATA,OAAkB1D,EAAE,OAAO,GAAGA,EAAE,MAAM,EAC1E,OAAO0D,AAAS,YAATA,OAAmBU,aAAaV,AAAS,WAATA,OAAkBa,YAAYD,aACrE,UAAU,CAACG;QACT,IAAIf,AAAS,YAATA,MAAkBzC,IAAI,CAACW,GAAGC,IAAMvD,QAAQ,KAAK,CAAC,YAAY,CAACsD,GAAGC,GAAG4C;aAChE,IAAIf,AAAS,WAATA,MACPpF,QAAQ,OAAO,CAAC,IACdA,QAAQ,KAAK,CAAC,cAAc,CAAC0C,KAAK,GAAG,CAAC1C,QAAQ,GAAG,CAAC,CAAC,EAAEA,QAAQ,GAAG,CAAC,CAAC,GAAGmG;aAEpED,OAAOC;IACd,IACA;IACJ,EAAEvB;AAEN"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
3
|
+
value: value,
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true
|
|
7
|
+
});
|
|
8
|
+
else obj[key] = value;
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
class ElementCore {
|
|
12
|
+
edit(from, to, text) {
|
|
13
|
+
const event = {
|
|
14
|
+
seq: ++this.seq,
|
|
15
|
+
base: this.rev,
|
|
16
|
+
from,
|
|
17
|
+
to,
|
|
18
|
+
text,
|
|
19
|
+
len: this.text.length
|
|
20
|
+
};
|
|
21
|
+
const removedLines = countLines(this.text.slice(from, to));
|
|
22
|
+
const addedLines = countLines(text);
|
|
23
|
+
this.text = this.text.slice(0, from) + text + this.text.slice(to);
|
|
24
|
+
if (removedLines || addedLines) {
|
|
25
|
+
var _this_lines_line;
|
|
26
|
+
const line = countLines(this.text.slice(0, from));
|
|
27
|
+
const style = null != (_this_lines_line = this.lines[line]) ? _this_lines_line : {
|
|
28
|
+
t: 'p',
|
|
29
|
+
r: []
|
|
30
|
+
};
|
|
31
|
+
const copy = {
|
|
32
|
+
...style,
|
|
33
|
+
r: []
|
|
34
|
+
};
|
|
35
|
+
delete copy.mk;
|
|
36
|
+
this.lines.splice(line + 1, removedLines, ...Array.from({
|
|
37
|
+
length: addedLines
|
|
38
|
+
}, ()=>copy));
|
|
39
|
+
}
|
|
40
|
+
const caret = from + text.length;
|
|
41
|
+
this.sel = {
|
|
42
|
+
a: caret,
|
|
43
|
+
h: caret
|
|
44
|
+
};
|
|
45
|
+
return event;
|
|
46
|
+
}
|
|
47
|
+
select(a, h, focus = this.focused) {
|
|
48
|
+
this.sel = {
|
|
49
|
+
a,
|
|
50
|
+
h
|
|
51
|
+
};
|
|
52
|
+
this.focused = focus;
|
|
53
|
+
return {
|
|
54
|
+
seq: this.seq,
|
|
55
|
+
base: this.rev,
|
|
56
|
+
a,
|
|
57
|
+
h,
|
|
58
|
+
focus
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
apply(message) {
|
|
62
|
+
var _message_ops, _message_sel, _message_ops1;
|
|
63
|
+
var _message_ops2;
|
|
64
|
+
if (message.ack !== this.seq) return null;
|
|
65
|
+
if (message.full) {
|
|
66
|
+
var _message_sel1;
|
|
67
|
+
this.text = message.full.text;
|
|
68
|
+
this.appLines = message.full.lines;
|
|
69
|
+
this.lines = this.appLines.slice();
|
|
70
|
+
this.rev = message.rev;
|
|
71
|
+
const max = this.text.length;
|
|
72
|
+
this.sel = null != (_message_sel1 = message.sel) ? _message_sel1 : {
|
|
73
|
+
a: Math.min(this.sel.a, max),
|
|
74
|
+
h: Math.min(this.sel.h, max)
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
ops: [],
|
|
78
|
+
full: true,
|
|
79
|
+
restyle: [
|
|
80
|
+
0,
|
|
81
|
+
this.lines.length
|
|
82
|
+
],
|
|
83
|
+
sel: this.sel,
|
|
84
|
+
focus: Boolean(message.focus)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (message.lines && message.lines.of !== this.rev) return 'resync';
|
|
88
|
+
let { a, h } = this.sel;
|
|
89
|
+
for (const op of null != (_message_ops = message.ops) ? _message_ops : []){
|
|
90
|
+
if (op.from > this.text.length || op.to > this.text.length) return 'resync';
|
|
91
|
+
this.text = this.text.slice(0, op.from) + op.text + this.text.slice(op.to);
|
|
92
|
+
a = mapPos(a, op);
|
|
93
|
+
h = mapPos(h, op);
|
|
94
|
+
}
|
|
95
|
+
let restyle = null;
|
|
96
|
+
if (message.lines) {
|
|
97
|
+
const { at, del, ins } = message.lines;
|
|
98
|
+
this.appLines = [
|
|
99
|
+
...this.appLines.slice(0, at),
|
|
100
|
+
...ins,
|
|
101
|
+
...this.appLines.slice(at + del)
|
|
102
|
+
];
|
|
103
|
+
restyle = [
|
|
104
|
+
at,
|
|
105
|
+
at + ins.length
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
this.lines = this.appLines.slice();
|
|
109
|
+
if (this.lines.length !== countLines(this.text) + 1) return 'resync';
|
|
110
|
+
this.rev = message.rev;
|
|
111
|
+
this.sel = null != (_message_sel = message.sel) ? _message_sel : {
|
|
112
|
+
a,
|
|
113
|
+
h
|
|
114
|
+
};
|
|
115
|
+
if (null == (_message_ops2 = message.ops) ? void 0 : _message_ops2.length) {
|
|
116
|
+
let first = 1 / 0;
|
|
117
|
+
let last = -1;
|
|
118
|
+
for (const op of message.ops){
|
|
119
|
+
const line = countLines(this.text.slice(0, op.from));
|
|
120
|
+
first = Math.min(first, line);
|
|
121
|
+
last = Math.max(last, line + countLines(op.text) + 1);
|
|
122
|
+
}
|
|
123
|
+
restyle = restyle ? [
|
|
124
|
+
Math.min(restyle[0], first),
|
|
125
|
+
Math.max(restyle[1], last)
|
|
126
|
+
] : [
|
|
127
|
+
first,
|
|
128
|
+
last
|
|
129
|
+
];
|
|
130
|
+
restyle[1] = Math.min(restyle[1], this.lines.length);
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
ops: null != (_message_ops1 = message.ops) ? _message_ops1 : [],
|
|
134
|
+
full: false,
|
|
135
|
+
restyle,
|
|
136
|
+
sel: this.sel,
|
|
137
|
+
focus: Boolean(message.focus)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
constructor(){
|
|
141
|
+
_define_property(this, "text", '');
|
|
142
|
+
_define_property(this, "appLines", [
|
|
143
|
+
{
|
|
144
|
+
t: 'p',
|
|
145
|
+
r: []
|
|
146
|
+
}
|
|
147
|
+
]);
|
|
148
|
+
_define_property(this, "lines", [
|
|
149
|
+
{
|
|
150
|
+
t: 'p',
|
|
151
|
+
r: []
|
|
152
|
+
}
|
|
153
|
+
]);
|
|
154
|
+
_define_property(this, "seq", 0);
|
|
155
|
+
_define_property(this, "rev", 0);
|
|
156
|
+
_define_property(this, "sel", {
|
|
157
|
+
a: 0,
|
|
158
|
+
h: 0
|
|
159
|
+
});
|
|
160
|
+
_define_property(this, "focused", false);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function countLines(text) {
|
|
164
|
+
let n = 0;
|
|
165
|
+
for(let i = 0; i < text.length; i++)if (10 === text.charCodeAt(i)) n++;
|
|
166
|
+
return n;
|
|
167
|
+
}
|
|
168
|
+
function mapPos(pos, op) {
|
|
169
|
+
if (pos <= op.from) return pos;
|
|
170
|
+
if (pos >= op.to) return pos + op.text.length - (op.to - op.from);
|
|
171
|
+
return op.from + op.text.length;
|
|
172
|
+
}
|
|
173
|
+
export { ElementCore, mapPos };
|
|
174
|
+
|
|
175
|
+
//# sourceMappingURL=element-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element-core.js","sources":["../src/element-core.ts"],"sourcesContent":["import type { RtEdit, RtLine, RtMessage, RtSelect } from './protocol';\n\n/**\n * The element's side of the `<g9-richtext>` protocol without any view: what every host's element does with its text,\n * its lines and the app's messages (protocol.ts). The web host's element uses this class as is; the Android element\n * (Kotlin) follows it line by line; tests drive it against a real session.\n *\n * - A local edit changes the text at once, gets the next `seq` and the `base` (the last applied message's `rev`), and\n * the display lines follow the edit roughly (a new line copies its neighbour's style) until the app's answer.\n * - A message is applied only when its `ack` equals the last `seq` (no edit on its way). Then the text gets the\n * message's replacements, the app's lines replace the display lines, the selection follows the replacements (a\n * caret stays before text inserted at it) unless the message moves it.\n * - A line change the element cannot apply (it does not have the state it is based on): ask for `resync`.\n */\nexport interface Applied {\n /** Replacements applied to the text, in order (positions after the previous ones). */\n ops: { from: number; to: number; text: string }[];\n /** The text was replaced as a whole. */\n full: boolean;\n /** Lines `[from, to)` of the new line array changed style (the view restyles them). */\n restyle: [number, number] | null;\n /** The selection after the message. */\n sel: { a: number; h: number };\n /** The message asks for the keyboard. */\n focus: boolean;\n}\n\n/** The `<g9-richtext>` element's model shared by every host: lines, edits, the caret and the app's messages. */\nexport class ElementCore {\n text = '';\n /** The app's lines as of `rev` (the base of the next line change). */\n appLines: RtLine[] = [{ t: 'p', r: [] }];\n /** What is drawn: the app's lines, adjusted for edits the app has not answered yet. */\n lines: RtLine[] = [{ t: 'p', r: [] }];\n seq = 0;\n rev = 0;\n sel = { a: 0, h: 0 };\n focused = false;\n\n /** The user replaced `from..to` with `text` (already done in the view): the event to send. */\n edit(from: number, to: number, text: string): RtEdit {\n const event: RtEdit = { seq: ++this.seq, base: this.rev, from, to, text, len: this.text.length };\n const removedLines = countLines(this.text.slice(from, to));\n const addedLines = countLines(text);\n this.text = this.text.slice(0, from) + text + this.text.slice(to);\n if (removedLines || addedLines) {\n const line = countLines(this.text.slice(0, from));\n const style = this.lines[line] ?? { t: 'p', r: [] };\n const copy: RtLine = { ...style, r: [] };\n delete copy.mk;\n this.lines.splice(line + 1, removedLines, ...Array.from({ length: addedLines }, () => copy));\n }\n const caret = from + text.length;\n this.sel = { a: caret, h: caret };\n return event;\n }\n\n /** The selection moved (or the focus changed): the event to send. */\n select(a: number, h: number, focus = this.focused): RtSelect {\n this.sel = { a, h };\n this.focused = focus;\n return { seq: this.seq, base: this.rev, a, h, focus };\n }\n\n /** A message from the app: what changed, `null` when it waits for the next one, `'resync'` when it cannot be applied. */\n apply(message: RtMessage): Applied | null | 'resync' {\n if (message.ack !== this.seq) return null;\n if (message.full) {\n this.text = message.full.text;\n this.appLines = message.full.lines;\n this.lines = this.appLines.slice();\n this.rev = message.rev;\n const max = this.text.length;\n this.sel = message.sel ?? { a: Math.min(this.sel.a, max), h: Math.min(this.sel.h, max) };\n return { ops: [], full: true, restyle: [0, this.lines.length], sel: this.sel, focus: Boolean(message.focus) };\n }\n if (message.lines && message.lines.of !== this.rev) return 'resync';\n let { a, h } = this.sel;\n for (const op of message.ops ?? []) {\n if (op.from > this.text.length || op.to > this.text.length) return 'resync';\n this.text = this.text.slice(0, op.from) + op.text + this.text.slice(op.to);\n a = mapPos(a, op);\n h = mapPos(h, op);\n }\n let restyle: [number, number] | null = null;\n if (message.lines) {\n const { at, del, ins } = message.lines;\n this.appLines = [...this.appLines.slice(0, at), ...ins, ...this.appLines.slice(at + del)];\n restyle = [at, at + ins.length];\n }\n this.lines = this.appLines.slice();\n if (this.lines.length !== countLines(this.text) + 1) return 'resync';\n this.rev = message.rev;\n this.sel = message.sel ?? { a, h };\n // Replacements touch lines the splice may not cover (same style, new text): restyle those too.\n if (message.ops?.length) {\n let first = Infinity;\n let last = -1;\n for (const op of message.ops) {\n const line = countLines(this.text.slice(0, op.from));\n first = Math.min(first, line);\n last = Math.max(last, line + countLines(op.text) + 1);\n }\n restyle = restyle ? [Math.min(restyle[0], first), Math.max(restyle[1], last)] : [first, last];\n restyle[1] = Math.min(restyle[1], this.lines.length);\n }\n return { ops: message.ops ?? [], full: false, restyle, sel: this.sel, focus: Boolean(message.focus) };\n }\n}\n\nfunction countLines(text: string): number {\n let n = 0;\n for (let i = 0; i < text.length; i++) if (text.charCodeAt(i) === 10) n++;\n return n;\n}\n\n/** A position through a replacement; a caret stays before text inserted right at it. */\nexport function mapPos(pos: number, op: { from: number; to: number; text: string }): number {\n if (pos <= op.from) return pos;\n if (pos >= op.to) return pos + op.text.length - (op.to - op.from);\n return op.from + op.text.length;\n}\n"],"names":["ElementCore","from","to","text","event","removedLines","countLines","addedLines","_this_lines_line","line","style","copy","Array","caret","a","h","focus","message","_message_ops","_message_sel","_message_ops1","_message_ops2","_message_sel1","max","Math","Boolean","op","mapPos","restyle","at","del","ins","first","Infinity","last","n","i","pos"],"mappings":";;;;;;;;;;AA4BO,MAAMA;IAYX,KAAKC,IAAY,EAAEC,EAAU,EAAEC,IAAY,EAAU;QACnD,MAAMC,QAAgB;YAAE,KAAK,EAAE,IAAI,CAAC,GAAG;YAAE,MAAM,IAAI,CAAC,GAAG;YAAEH;YAAMC;YAAIC;YAAM,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM;QAAC;QAC/F,MAAME,eAAeC,WAAW,IAAI,CAAC,IAAI,CAAC,KAAK,CAACL,MAAMC;QACtD,MAAMK,aAAaD,WAAWH;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAGF,QAAQE,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAACD;QAC9D,IAAIG,gBAAgBE,YAAY;gBAEhBC;YADd,MAAMC,OAAOH,WAAW,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAGL;YAC3C,MAAMS,QAAQ,QAAAF,CAAAA,mBAAAA,IAAI,CAAC,KAAK,CAACC,KAAK,AAAD,IAAfD,mBAAoB;gBAAE,GAAG;gBAAK,GAAG,EAAE;YAAC;YAClD,MAAMG,OAAe;gBAAE,GAAGD,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AE,GAAG;YAAG,GAAG;QAAE;QACnB,kCAAU;;AAuEZ;AAEA,SAASX,WAAWH,IAAY;IAC9B,IAAIgC,IAAI;IACR,IAAK,IAAIC,IAAI,GAAGA,IAAIjC,KAAK,MAAM,EAAEiC,IAAK,IAAIjC,AAAuB,OAAvBA,KAAK,UAAU,CAACiC,IAAWD;IACrE,OAAOA;AACT;AAGO,SAASR,OAAOU,GAAW,EAAEX,EAA8C;IAChF,IAAIW,OAAOX,GAAG,IAAI,EAAE,OAAOW;IAC3B,IAAIA,OAAOX,GAAG,EAAE,EAAE,OAAOW,MAAMX,GAAG,IAAI,CAAC,MAAM,GAAIA,CAAAA,GAAG,EAAE,GAAGA,GAAG,IAAG;IAC/D,OAAOA,GAAG,IAAI,GAAGA,GAAG,IAAI,CAAC,MAAM;AACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./protocol.js";
|
|
2
|
+
export { ZWNJ, guillemet, nextDirection, normalizeForSearch, resolvedDirection, wantsZwnj } from "./bidi.js";
|
|
3
|
+
export { G9RichTextEditor, useG9RichTextSession } from "./editor.js";
|
|
4
|
+
export { ElementCore as G9RichElementCore, mapPos } from "./element-core.js";
|
|
5
|
+
export { G9RichLines, lineClass, lineStyle, textClass } from "./lines-view.js";
|
|
6
|
+
export { matchPeople, mentionIds } from "./mentions.js";
|
|
7
|
+
export { TextOp, compose, diff, fromReplacements, transform } from "./ot.js";
|
|
8
|
+
export { G9RichText, G9RichTextPort, g9RichTextPalette } from "./rich-text.js";
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { memo } from "@lynx-js/react";
|
|
2
|
+
import { MARK, OBJ } from "./protocol.js";
|
|
3
|
+
import "./richtext.css";
|
|
4
|
+
function G9RichLines(props) {
|
|
5
|
+
var _props_editing;
|
|
6
|
+
const parts = props.text.split('\n');
|
|
7
|
+
const editing = null != (_props_editing = props.editing) ? _props_editing : -1;
|
|
8
|
+
return <view className={`g9-rt-lines${props.className ? ` ${props.className}` : ''}`}>
|
|
9
|
+
{props.lines.map((line, index)=>{
|
|
10
|
+
var _parts_index, _parts_index1, _line_dir;
|
|
11
|
+
return index === editing && props.renderLine ? <view key={`e${index}`}>{props.renderLine(index, line, null != (_parts_index = parts[index]) ? _parts_index : '')}</view> : <Line key={index} index={index} line={line} text={null != (_parts_index1 = parts[index]) ? _parts_index1 : ''} rtl={(null != (_line_dir = line.dir) ? _line_dir : props.direction) === 'rtl'} {...props.onTapLine ? {
|
|
12
|
+
onTap: props.onTapLine
|
|
13
|
+
} : {}} {...props.onToggleCheck ? {
|
|
14
|
+
onToggleCheck: props.onToggleCheck
|
|
15
|
+
} : {}}/>;
|
|
16
|
+
})}
|
|
17
|
+
</view>;
|
|
18
|
+
}
|
|
19
|
+
const Line = memo(function(props) {
|
|
20
|
+
var _mk_n, _line_ind;
|
|
21
|
+
var _line_img;
|
|
22
|
+
const { line, index } = props;
|
|
23
|
+
const mk = line.mk;
|
|
24
|
+
return <view className={lineClass(line, props.rtl)} style={lineStyle(line, props.rtl)} bindtap={()=>{
|
|
25
|
+
var _props_onTap;
|
|
26
|
+
return null == (_props_onTap = props.onTap) ? void 0 : _props_onTap.call(props, index);
|
|
27
|
+
}}>
|
|
28
|
+
{line.q ? <view className={props.rtl ? 'g9-rt-quote g9-rt-quote--rtl' : 'g9-rt-quote'} style={{
|
|
29
|
+
width: `${14 * line.q}px`
|
|
30
|
+
}}/> : null}
|
|
31
|
+
{mk ? <view className="g9-rt-marker" catchtap={()=>{
|
|
32
|
+
var _props_onToggleCheck;
|
|
33
|
+
return 't' === mk.k && (null == (_props_onToggleCheck = props.onToggleCheck) ? void 0 : _props_onToggleCheck.call(props, index));
|
|
34
|
+
}}>
|
|
35
|
+
{'t' === mk.k ? <view className={mk.c ? 'g9-rt-check g9-rt-check--on' : 'g9-rt-check'}/> : <text className="g9-rt-marker-text">{'n' === mk.k ? null != (_mk_n = mk.n) ? _mk_n : '' : bullet(null != (_line_ind = line.ind) ? _line_ind : 1)}</text>}
|
|
36
|
+
</view> : line.ind ? <view className="g9-rt-marker"/> : null}
|
|
37
|
+
{'hr' === line.t ? <view className="g9-rt-hr"/> : 'img' === line.t ? (null == (_line_img = line.img) ? void 0 : _line_img.src) ? <image src={line.img.src} mode="aspectFit" className="g9-rt-img" {...line.img.alt ? {
|
|
38
|
+
'accessibility-label': line.img.alt
|
|
39
|
+
} : {}}/> : <view className="g9-rt-img g9-rt-img--loading"/> : <text className={textClass(line)}>{runs(line.r, props.text, fontClass(line))}</text>}
|
|
40
|
+
</view>;
|
|
41
|
+
});
|
|
42
|
+
function bullet(depth) {
|
|
43
|
+
return depth % 3 === 1 ? '•' : depth % 3 === 2 ? '◦' : '▪';
|
|
44
|
+
}
|
|
45
|
+
function lineClass(line, rtl = false) {
|
|
46
|
+
return [
|
|
47
|
+
'g9-rt-line',
|
|
48
|
+
`g9-rt-line--${line.t}`,
|
|
49
|
+
line.co ? `g9-rt-callout g9-rt-callout--${line.co}${rtl ? ' g9-rt-callout--rtl' : ''}` : '',
|
|
50
|
+
line.cell ? `g9-rt-cell${line.cell.h ? ' g9-rt-cell--head' : ''}${line.cell.top ? ' g9-rt-cell--top' : ''}${rtl ? ' g9-rt-cell--rtl' : ''}` : '',
|
|
51
|
+
line.cf ? 'g9-rt-line--code-first' : '',
|
|
52
|
+
line.cl ? 'g9-rt-line--code-last' : ''
|
|
53
|
+
].filter(Boolean).join(' ');
|
|
54
|
+
}
|
|
55
|
+
function textClass(line) {
|
|
56
|
+
return `g9-rt-text ${fontClass(line)}`;
|
|
57
|
+
}
|
|
58
|
+
function fontClass(line) {
|
|
59
|
+
return `g9-rt-font g9-rt-text--${line.t}${'code' === line.t ? ' g9-rt-mono' : ''}${line.done ? ' g9-rt-text--done' : ''}`;
|
|
60
|
+
}
|
|
61
|
+
function lineStyle(line, rtl = false) {
|
|
62
|
+
var _line_ind;
|
|
63
|
+
const indent = (null != (_line_ind = line.ind) ? _line_ind : 0) > 1 ? (line.ind - 1) * 22 : 0;
|
|
64
|
+
const style = {};
|
|
65
|
+
if (indent) style[rtl ? 'paddingRight' : 'paddingLeft'] = `${indent}px`;
|
|
66
|
+
if (line.dir) style.direction = line.dir;
|
|
67
|
+
return style;
|
|
68
|
+
}
|
|
69
|
+
const OBJS = new RegExp(OBJ, 'g');
|
|
70
|
+
function runs(list, text1, font) {
|
|
71
|
+
if (!list.length) return '';
|
|
72
|
+
const out = [];
|
|
73
|
+
let at = 0;
|
|
74
|
+
list.forEach((run, index)=>{
|
|
75
|
+
var _run_m;
|
|
76
|
+
const part = text1.slice(at, at + run.n);
|
|
77
|
+
at += run.n;
|
|
78
|
+
if (run.a) return void out.push(<text key={index} className={`${font} g9-rt-atom g9-rt-atom--${run.a.k}${run.a.off ? ' g9-rt-atom--off' : ''}`} style={run.a.c ? {
|
|
79
|
+
color: run.a.c
|
|
80
|
+
} : {}}>
|
|
81
|
+
{` ${run.a.t} `}
|
|
82
|
+
</text>);
|
|
83
|
+
const m = null != (_run_m = run.m) ? _run_m : 0;
|
|
84
|
+
const classes = [
|
|
85
|
+
'g9-rt-run',
|
|
86
|
+
font,
|
|
87
|
+
m & MARK.bold ? 'g9-rt-run--b' : '',
|
|
88
|
+
m & MARK.italic ? 'g9-rt-run--i' : '',
|
|
89
|
+
m & MARK.underline ? 'g9-rt-run--u' : '',
|
|
90
|
+
m & MARK.strike ? 'g9-rt-run--s' : '',
|
|
91
|
+
m & MARK.code ? 'g9-rt-run--c' : '',
|
|
92
|
+
m & MARK.link ? 'g9-rt-run--a' : ''
|
|
93
|
+
].filter(Boolean).join(' ');
|
|
94
|
+
out.push(<text key={index} className={classes}>
|
|
95
|
+
{part.replace(OBJS, '')}
|
|
96
|
+
</text>);
|
|
97
|
+
});
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
export { G9RichLines, fontClass, lineClass, lineStyle, textClass };
|
|
101
|
+
|
|
102
|
+
//# sourceMappingURL=lines-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lines-view.js","sources":["../src/lines-view.tsx"],"sourcesContent":["// A document's styled lines drawn with Lynx views (2.5.8, from G9Hub's LinesView): headings, lists with markers,\n// checklists, quotes, callouts, code, tables' cells, rules, pictures and inline objects — the look of `<g9-richtext>`,\n// for read-only previews (a version, a search hit) and the desktop's editing surface around the line being edited.\nimport { memo, type ReactNode } from '@lynx-js/react';\nimport { MARK, OBJ, type RtLine, type RtRun } from './protocol';\nimport './richtext.css';\n\n/** Props of {@link G9RichLines}. */\nexport interface G9RichLinesProps {\n readonly text: string;\n readonly lines: readonly RtLine[];\n /** The line being edited (drawn by `renderLine`). */\n readonly editing?: number;\n readonly renderLine?: (index: number, line: RtLine, text: string) => ReactNode | null;\n readonly onTapLine?: (index: number) => void;\n readonly onToggleCheck?: (index: number) => void;\n readonly className?: string;\n /** The document's direction (a line without its own takes it). Default `ltr`. */\n readonly direction?: 'ltr' | 'rtl';\n}\n\n/** The styled lines of a text (`text` split at `\\n`, one {@link RtLine} each). */\nexport function G9RichLines(props: G9RichLinesProps): ReactNode {\n const parts = props.text.split('\\n');\n const editing = props.editing ?? -1;\n return (\n <view className={`g9-rt-lines${props.className ? ` ${props.className}` : ''}`}>\n {props.lines.map((line, index) =>\n index === editing && props.renderLine ? (\n <view key={`e${index}`}>{props.renderLine(index, line, parts[index] ?? '')}</view>\n ) : (\n <Line\n key={index}\n index={index}\n line={line}\n text={parts[index] ?? ''}\n rtl={(line.dir ?? props.direction) === 'rtl'}\n {...(props.onTapLine ? { onTap: props.onTapLine } : {})}\n {...(props.onToggleCheck ? { onToggleCheck: props.onToggleCheck } : {})}\n />\n ),\n )}\n </view>\n );\n}\n\nconst Line = memo(function LineRender(props: {\n readonly index: number;\n readonly line: RtLine;\n readonly text: string;\n readonly rtl: boolean;\n readonly onTap?: (index: number) => void;\n readonly onToggleCheck?: (index: number) => void;\n}): ReactNode {\n const { line, index } = props;\n const mk = line.mk;\n return (\n <view\n className={lineClass(line, props.rtl)}\n style={lineStyle(line, props.rtl)}\n bindtap={() => props.onTap?.(index)}\n >\n {line.q ? (\n <view\n className={props.rtl ? 'g9-rt-quote g9-rt-quote--rtl' : 'g9-rt-quote'}\n style={{ width: `${line.q * 14}px` }}\n />\n ) : null}\n {mk ? (\n <view className=\"g9-rt-marker\" catchtap={() => mk.k === 't' && props.onToggleCheck?.(index)}>\n {mk.k === 't' ? (\n <view className={mk.c ? 'g9-rt-check g9-rt-check--on' : 'g9-rt-check'} />\n ) : (\n <text className=\"g9-rt-marker-text\">{mk.k === 'n' ? (mk.n ?? '') : bullet(line.ind ?? 1)}</text>\n )}\n </view>\n ) : line.ind ? (\n <view className=\"g9-rt-marker\" />\n ) : null}\n {line.t === 'hr' ? (\n <view className=\"g9-rt-hr\" />\n ) : line.t === 'img' ? (\n line.img?.src ? (\n <image\n src={line.img.src}\n mode=\"aspectFit\"\n className=\"g9-rt-img\"\n {...(line.img.alt ? { 'accessibility-label': line.img.alt } : {})}\n />\n ) : (\n <view className=\"g9-rt-img g9-rt-img--loading\" />\n )\n ) : (\n <text className={textClass(line)}>{runs(line.r, props.text, fontClass(line))}</text>\n )}\n </view>\n );\n});\n\nfunction bullet(depth: number): string {\n return depth % 3 === 1 ? '•' : depth % 3 === 2 ? '◦' : '▪';\n}\n\n/** A line's box classes (`rtl`: the line reads right to left). */\nexport function lineClass(line: RtLine, rtl = false): string {\n return [\n 'g9-rt-line',\n `g9-rt-line--${line.t}`,\n line.co ? `g9-rt-callout g9-rt-callout--${line.co}${rtl ? ' g9-rt-callout--rtl' : ''}` : '',\n line.cell\n ? `g9-rt-cell${line.cell.h ? ' g9-rt-cell--head' : ''}${line.cell.top ? ' g9-rt-cell--top' : ''}${rtl ? ' g9-rt-cell--rtl' : ''}`\n : '',\n line.cf ? 'g9-rt-line--code-first' : '',\n line.cl ? 'g9-rt-line--code-last' : '',\n ]\n .filter(Boolean)\n .join(' ');\n}\n\n/** A line's text classes (the heading or code size, a done task struck through). */\nexport function textClass(line: RtLine): string {\n return `g9-rt-text ${fontClass(line)}`;\n}\n\n/** A line's font classes, set on its text and on each of its runs (an inline text does not take its parent's font). */\nexport function fontClass(line: RtLine): string {\n return `g9-rt-font g9-rt-text--${line.t}${line.t === 'code' ? ' g9-rt-mono' : ''}${line.done ? ' g9-rt-text--done' : ''}`;\n}\n\n/** A line's indent (on its reading start: physical sides, Lynx has no logical ones) and explicit direction. */\nexport function lineStyle(line: RtLine, rtl = false): Record<string, string> {\n const indent = (line.ind ?? 0) > 1 ? ((line.ind as number) - 1) * 22 : 0;\n const style: Record<string, string> = {};\n if (indent) style[rtl ? 'paddingRight' : 'paddingLeft'] = `${indent}px`;\n if (line.dir) style.direction = line.dir;\n return style;\n}\n\nconst OBJS = new RegExp(OBJ, 'g');\n\nfunction runs(list: readonly RtRun[], text: string, font: string): ReactNode[] | string {\n if (!list.length) return '';\n const out: ReactNode[] = [];\n let at = 0;\n list.forEach((run, index) => {\n const part = text.slice(at, at + run.n);\n at += run.n;\n if (run.a) {\n out.push(\n <text\n key={index}\n className={`${font} g9-rt-atom g9-rt-atom--${run.a.k}${run.a.off ? ' g9-rt-atom--off' : ''}`}\n style={run.a.c ? { color: run.a.c } : {}}\n >\n {` ${run.a.t} `}\n </text>,\n );\n return;\n }\n const m = run.m ?? 0;\n const classes = [\n 'g9-rt-run',\n font,\n m & MARK.bold ? 'g9-rt-run--b' : '',\n m & MARK.italic ? 'g9-rt-run--i' : '',\n m & MARK.underline ? 'g9-rt-run--u' : '',\n m & MARK.strike ? 'g9-rt-run--s' : '',\n m & MARK.code ? 'g9-rt-run--c' : '',\n m & MARK.link ? 'g9-rt-run--a' : '',\n ]\n .filter(Boolean)\n .join(' ');\n out.push(\n <text key={index} className={classes}>\n {part.replace(OBJS, '')}\n </text>,\n );\n });\n return out;\n}\n"],"names":["G9RichLines","props","_props_editing","parts","editing","view","line","index","_parts_index","_parts_index1","_line_dir","Line","memo","_mk_n","_line_ind","_line_img","mk","lineClass","lineStyle","text","bullet","image","textClass","runs","fontClass","depth","rtl","Boolean","indent","style","OBJS","RegExp","OBJ","list","text1","font","out","at","run","_run_m","part","m","classes","MARK"],"mappings":";;;AAsBO,SAASA,YAAYC,KAAuB;QAEjCC;IADhB,MAAMC,QAAQF,MAAM,IAAI,CAAC,KAAK,CAAC;IAC/B,MAAMG,UAAU,QAAAF,CAAAA,iBAAAA,MAAM,OAAO,AAAD,IAAZA,iBAAiB;IACjC,QACGG,KAAK,WAAW,CAAC,WAAW,EAAEJ,MAAM,SAAS,GAAG,CAAC,CAAC,EAAEA,MAAM,SAAS,EAAE,GAAG,IAAI,EAAE;MAC7E,CAACA,MAAM,KAAK,CAAC,GAAG,CAAC,CAACK,MAAMC;YAEmCC,cAM/CC,eACAC;eARVH,UAAUH,WAAWH,MAAM,UAAU,IAClCI,KAAK,KAAK,CAAC,CAAC,EAAEE,OAAO,GAAGN,MAAM,UAAU,CAACM,OAAOD,MAAM,QAAAE,CAAAA,eAAAA,KAAK,CAACD,MAAM,AAAD,IAAXC,eAAgB,MAAMH,SAE5EM,KACC,KAAKJ,OACL,OAAOA,OACP,MAAMD,MACN,MAAM,QAAAG,CAAAA,gBAAAA,KAAK,CAACF,MAAM,AAAD,IAAXE,gBAAgB,IACtB,KAAK,AAAC,SAAAC,CAAAA,YAAAA,KAAK,GAAG,AAAD,IAAPA,YAAYT,MAAM,SAAS,AAAD,MAAO,QACtC,GAAIA,MAAM,SAAS,GAAG;YAAE,OAAOA,MAAM,SAAS;QAAC,IAAI,CAAC,CAAC,GACrD,GAAIA,MAAM,aAAa,GAAG;YAAE,eAAeA,MAAM,aAAa;QAAC,IAAI,CAAC,CAAC;OAG1E;IACJ,EAAEI;AAEN;AAEA,MAAMM,OAAOC,KAAK,SAAoBX,KAOrC;QAoBgEY,OAAqBC;QAS9EC;IA5BN,MAAM,EAAET,IAAI,EAAEC,KAAK,EAAE,GAAGN;IACxB,MAAMe,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M,CAAChB,SACP,IAAI,CAAC;QACRS,IAAI,IAAI,EACLjB,KAAK,KAAKZ,OAAO,WAAWmC,SAAS;QACpC,CAACF,KAAK,OAAO,CAACV,MAAM,IAAI;MAC1B,EAAEX;IAEN;IACA,OAAOiB;AACT"}
|
package/dist/mentions.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { normalizeForSearch } from "./bidi.js";
|
|
2
|
+
const byCode = (a, b)=>Number(a > b) - Number(a < b);
|
|
3
|
+
function mentionIds(node) {
|
|
4
|
+
const ids = [];
|
|
5
|
+
const walk = (current)=>{
|
|
6
|
+
var _current_content;
|
|
7
|
+
var _current_attrs;
|
|
8
|
+
if ('mention' === current.type && 'string' == typeof (null == (_current_attrs = current.attrs) ? void 0 : _current_attrs.id) && !ids.includes(current.attrs.id)) ids.push(current.attrs.id);
|
|
9
|
+
for (const child of null != (_current_content = current.content) ? _current_content : [])walk(child);
|
|
10
|
+
};
|
|
11
|
+
if (node) walk(node);
|
|
12
|
+
return ids;
|
|
13
|
+
}
|
|
14
|
+
function matchPeople(people, query, limit = 8, exclude = null) {
|
|
15
|
+
const q = normalizeForSearch(query.trim());
|
|
16
|
+
const scored = [];
|
|
17
|
+
for (const person of people){
|
|
18
|
+
var _person_userName;
|
|
19
|
+
if (person.id === exclude) continue;
|
|
20
|
+
if (!q) {
|
|
21
|
+
scored.push({
|
|
22
|
+
person,
|
|
23
|
+
score: 1
|
|
24
|
+
});
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const name = normalizeForSearch(person.name);
|
|
28
|
+
const user = normalizeForSearch(null != (_person_userName = person.userName) ? _person_userName : '');
|
|
29
|
+
let score = 0;
|
|
30
|
+
if (name.startsWith(q) || user.startsWith(q)) score = 4;
|
|
31
|
+
else if (name.split(/\s+/).some((word)=>word.startsWith(q))) score = 3;
|
|
32
|
+
else if (name.includes(q) || user.includes(q)) score = 2;
|
|
33
|
+
if (score) scored.push({
|
|
34
|
+
person,
|
|
35
|
+
score
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return scored.sort((a, b)=>b.score - a.score || byCode(a.person.name, b.person.name)).slice(0, limit).map((entry)=>entry.person);
|
|
39
|
+
}
|
|
40
|
+
export { matchPeople, mentionIds };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=mentions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mentions.js","sources":["../src/mentions.ts"],"sourcesContent":["import { normalizeForSearch } from './bidi';\n\n/** Code point order (Lynx has no Intl: no `localeCompare`). */\nconst byCode = (a: string, b: string): number => Number(a > b) - Number(a < b);\n\n/**\n * @mentions in documents: who a document mentions, and the people the @ picker offers. The server notifies from the\n * mention nodes an update really inserts; these helpers serve the editor. Pure — tested in mentions.test.ts.\n */\n\n/** A ProseMirror JSON node (what `editor.getJSON()` returns). */\nexport interface JsonNode {\n type?: string;\n attrs?: Record<string, unknown>;\n content?: JsonNode[];\n marks?: { type: string; attrs?: Record<string, unknown> }[];\n text?: string;\n}\n\n/** The distinct people a document mentions, in order of first appearance. */\nexport function mentionIds(node: JsonNode | null | undefined): string[] {\n const ids: string[] = [];\n const walk = (current: JsonNode) => {\n if (current.type === 'mention' && typeof current.attrs?.id === 'string' && !ids.includes(current.attrs.id))\n ids.push(current.attrs.id);\n for (const child of current.content ?? []) walk(child);\n };\n if (node) walk(node);\n return ids;\n}\n\n/** A person a mention can name. */\nexport interface MentionCandidate {\n id: string;\n name: string;\n userName?: string | null;\n avatarUrl?: string | null;\n}\n\n/**\n * People matching what was typed after @, best first: a name or user name that starts with the query, then a word of\n * the name that does, then anything containing it. Persian spelling variants match (ی/ي, ک/ك, with or without ZWNJ).\n */\nexport function matchPeople(\n people: MentionCandidate[],\n query: string,\n limit = 8,\n exclude: string | null = null,\n): MentionCandidate[] {\n const q = normalizeForSearch(query.trim());\n const scored: { person: MentionCandidate; score: number }[] = [];\n for (const person of people) {\n if (person.id === exclude) continue;\n if (!q) {\n scored.push({ person, score: 1 });\n continue;\n }\n const name = normalizeForSearch(person.name);\n const user = normalizeForSearch(person.userName ?? '');\n let score = 0;\n if (name.startsWith(q) || user.startsWith(q)) score = 4;\n else if (name.split(/\\s+/).some((word) => word.startsWith(q))) score = 3;\n else if (name.includes(q) || user.includes(q)) score = 2;\n if (score) scored.push({ person, score });\n }\n return scored\n .sort((a, b) => b.score - a.score || byCode(a.person.name, b.person.name))\n .slice(0, limit)\n .map((entry) => entry.person);\n}\n"],"names":["byCode","a","b","Number","mentionIds","node","ids","walk","current","_current_content","_current_attrs","child","matchPeople","people","query","limit","exclude","q","normalizeForSearch","scored","person","_person_userName","name","user","score","word","entry"],"mappings":";AAGA,MAAMA,SAAS,CAACC,GAAWC,IAAsBC,OAAOF,IAAIC,KAAKC,OAAOF,IAAIC;AAiBrE,SAASE,WAAWC,IAAiC;IAC1D,MAAMC,MAAgB,EAAE;IACxB,MAAMC,OAAO,CAACC;YAGQC;YAFqBC;QAAzC,IAAIF,AAAiB,cAAjBA,QAAQ,IAAI,IAAkB,AAA6B,YAA7B,gBAAOE,CAAAA,iBAAAA,QAAQ,KAAK,AAAD,IAAZA,KAAAA,IAAAA,eAAe,EAAE,AAAD,KAAkB,CAACJ,IAAI,QAAQ,CAACE,QAAQ,KAAK,CAAC,EAAE,GACvGF,IAAI,IAAI,CAACE,QAAQ,KAAK,CAAC,EAAE;QAC3B,KAAK,MAAMG,SAAS,QAAAF,CAAAA,mBAAAA,QAAQ,OAAO,AAAD,IAAdA,mBAAmB,EAAE,CAAEF,KAAKI;IAClD;IACA,IAAIN,MAAME,KAAKF;IACf,OAAOC;AACT;AAcO,SAASM,YACdC,MAA0B,EAC1BC,KAAa,EACbC,QAAQ,CAAC,EACTC,UAAyB,IAAI;IAE7B,MAAMC,IAAIC,mBAAmBJ,MAAM,IAAI;IACvC,MAAMK,SAAwD,EAAE;IAChE,KAAK,MAAMC,UAAUP,OAAQ;YAOKQ;QANhC,IAAID,OAAO,EAAE,KAAKJ,SA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