@bsky.app/tapper 0.5.1 → 0.5.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/CHANGELOG.md +12 -0
- package/build/facets.d.ts.map +1 -1
- package/build/facets.js +8 -4
- package/build/facets.js.map +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +4 -3
- package/build/index.js.map +1 -1
- package/build/util.d.ts.map +1 -1
- package/build/util.js +29 -6
- package/build/util.js.map +1 -1
- package/eslint.config.js +4 -0
- package/package.json +3 -2
- package/src/facets.ts +8 -4
- package/src/index.ts +5 -3
- package/src/util.ts +29 -6
- package/vitest.config.ts +6 -0
- package/.eslintrc.js +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @bsky.app/tapper
|
|
2
2
|
|
|
3
|
+
## 0.5.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#32](https://github.com/bluesky-social/toolbox/pull/32) [`f90f35f`](https://github.com/bluesky-social/toolbox/commit/f90f35fbcabb0e4c959d60f273ecf6df38a20534) Thanks [@estrattonbailey](https://github.com/estrattonbailey)! - Ensure facets handle leading whitespace/chars before triggering
|
|
8
|
+
|
|
9
|
+
## 0.5.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#30](https://github.com/bluesky-social/toolbox/pull/30) [`846da1c`](https://github.com/bluesky-social/toolbox/commit/846da1c734113a058fac16693c0936d2d74b621b) Thanks [@estrattonbailey](https://github.com/estrattonbailey)! - Do not atomic-delete URL facets
|
|
14
|
+
|
|
3
15
|
## 0.5.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/build/facets.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facets.d.ts","sourceRoot":"","sources":["../src/facets.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"facets.d.ts","sourceRoot":"","sources":["../src/facets.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,OAAO,QAAkC,CAAA;AACtD,eAAO,MAAM,KAAK,QAAgC,CAAA;AAClD,eAAO,MAAM,GAAG,QAC4K,CAAA;AAC5L,eAAO,MAAM,GAAG,QACmE,CAAA"}
|
package/build/facets.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// Each regex begins with a `(^|\s|\()` capture group: a backwards-compatible
|
|
2
|
+
// alternative to lookbehind (Safari < 16.4 throws on lookbehind at parse time).
|
|
3
|
+
// The boundary char is captured into m[1]; util.ts strips it so positions and
|
|
4
|
+
// `raw` reflect the facet itself.
|
|
5
|
+
export const mention = /(^|\s|\()@([a-zA-Z0-9.-]+)\b/g;
|
|
6
|
+
export const emoji = /(^|\s|\():([a-zA-Z0-9_]+):/g;
|
|
7
|
+
export const tag = /(^|\s|\()[##]((?!\ufe0f)[^\s\u00AD\u2060\u200A\u200B\u200C\u200D\u20e2]*[^\d\s\p{P}\u00AD\u2060\u200A\u200B\u200C\u200D\u20e2]+[^\s\u00AD\u2060\u200A\u200B\u200C\u200D\u20e2\p{P}]*)?/gu;
|
|
8
|
+
export const url = /(^|\s|\()((https?:\/\/[\S]+)|((?<domain>[a-z][a-z0-9]*(\.[a-z0-9]+)+)[\S]*))/gim;
|
|
5
9
|
//# sourceMappingURL=facets.js.map
|
package/build/facets.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facets.js","sourceRoot":"","sources":["../src/facets.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"facets.js","sourceRoot":"","sources":["../src/facets.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,gFAAgF;AAChF,8EAA8E;AAC9E,kCAAkC;AAClC,MAAM,CAAC,MAAM,OAAO,GAAG,+BAA+B,CAAA;AACtD,MAAM,CAAC,MAAM,KAAK,GAAG,6BAA6B,CAAA;AAClD,MAAM,CAAC,MAAM,GAAG,GACd,0LAA0L,CAAA;AAC5L,MAAM,CAAC,MAAM,GAAG,GACd,iFAAiF,CAAA","sourcesContent":["// Each regex begins with a `(^|\\s|\\()` capture group: a backwards-compatible\n// alternative to lookbehind (Safari < 16.4 throws on lookbehind at parse time).\n// The boundary char is captured into m[1]; util.ts strips it so positions and\n// `raw` reflect the facet itself.\nexport const mention = /(^|\\s|\\()@([a-zA-Z0-9.-]+)\\b/g\nexport const emoji = /(^|\\s|\\():([a-zA-Z0-9_]+):/g\nexport const tag =\n /(^|\\s|\\()[##]((?!\\ufe0f)[^\\s\\u00AD\\u2060\\u200A\\u200B\\u200C\\u200D\\u20e2]*[^\\d\\s\\p{P}\\u00AD\\u2060\\u200A\\u200B\\u200C\\u200D\\u20e2]+[^\\s\\u00AD\\u2060\\u200A\\u200B\\u200C\\u200D\\u20e2\\p{P}]*)?/gu\nexport const url =\n /(^|\\s|\\()((https?:\\/\\/[\\S]+)|((?<domain>[a-z][a-z0-9]*(\\.[a-z0-9]+)+)[\\S]*))/gim\n"]}
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,SAAS,EAAC,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,SAAS,EAAC,MAAM,cAAc,CAAA;AAGhD,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,eAAe,EACf,cAAc,EACf,MAAM,SAAS,CAAA;AAUhB,cAAc,SAAS,CAAA;AACvB,OAAO,KAAK,MAAM,MAAM,UAAU,CAAA;AAIlC,qBAAa,MAAM;IACjB,OAAO,CAAC,YAAY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AAE;gBAAC,SAAS,EAAE;oBAAC,KAAK,EAAE,MAAM,CAAC;oBAAC,GAAG,EAAE,MAAM,CAAA;iBAAC,CAAA;aAAC,CAAA;SACvD;;EAoIF"}
|
package/build/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useRef, useState, useSyncExternalStore } from 'react';
|
|
2
2
|
import { Platform } from 'react-native';
|
|
3
|
-
import { parseNodesFromText, detectActiveFacet, deriveTriggers, nodeToFacet, compileFacetRegexes, } from './util';
|
|
4
3
|
import * as defaultFacets from './facets';
|
|
4
|
+
import { parseNodesFromText, detectActiveFacet, deriveTriggers, nodeToFacet, compileFacetRegexes, } from './util';
|
|
5
5
|
export * from './types';
|
|
6
6
|
export * as facets from './facets';
|
|
7
7
|
const IS_WEB = Platform.OS === 'web';
|
|
@@ -9,7 +9,6 @@ export class Tapper {
|
|
|
9
9
|
facetRegexes;
|
|
10
10
|
triggers;
|
|
11
11
|
// Event emitters
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
12
|
listeners = new Map();
|
|
14
13
|
// Public state
|
|
15
14
|
text = '';
|
|
@@ -140,11 +139,13 @@ export class Tapper {
|
|
|
140
139
|
return;
|
|
141
140
|
const diff = newText.length - this.text.length;
|
|
142
141
|
let newEnd = Math.max(this.selection.end + diff, 0);
|
|
143
|
-
// Atomic deletion: backspace into a facet from outside
|
|
142
|
+
// Atomic deletion: backspace into a facet from outside.
|
|
143
|
+
// URLs are excluded — users typically want to edit them character by character.
|
|
144
144
|
let didAtomicDelete = false;
|
|
145
145
|
if (diff === -1 && newEnd < this.selection.end) {
|
|
146
146
|
for (const node of this.nodes) {
|
|
147
147
|
if (node.type === 'facet' &&
|
|
148
|
+
node.facetType !== 'url' &&
|
|
148
149
|
node.committed &&
|
|
149
150
|
this.selection.end === node.end) {
|
|
150
151
|
const remnant = node.end - node.start - 1;
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
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;SACL;QACD,UAAU,EAAE;YACV,GAAG,EAAE,cAAc;YACnB,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;YACtC,YAAY,EAAE,KAAK,CAAC,gBAAgB;YACpC,iBAAiB,EAAE,KAAK,CAAC,qBAAqB;SAC/C;KACF,CAAA;AACH,CAAC","sourcesContent":["import {useCallback, useRef, useState, useSyncExternalStore} from 'react'\nimport {Platform, TextInput} from 'react-native'\n\nimport {\n TapperConfig,\n TapperEvents,\n TapperNode,\n TapperActiveFacet,\n TapperSelection,\n TapperSnapshot,\n} from './types'\nimport {\n parseNodesFromText,\n detectActiveFacet,\n deriveTriggers,\n nodeToFacet,\n compileFacetRegexes,\n type CompiledFacetRegexes,\n} from './util'\nimport * as defaultFacets from './facets'\n\nexport * from './types'\nexport * as facets from './facets'\n\nconst IS_WEB = Platform.OS === 'web'\n\nexport class Tapper {\n private facetRegexes: CompiledFacetRegexes\n private triggers: Map<string, string>\n\n // Event emitters\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private listeners = new Map<keyof TapperEvents, Set<(data: any) => void>>()\n\n // Public state\n text = ''\n selection: TapperSelection = {start: 0, end: 0}\n nodes: TapperNode[] = []\n activeFacet: TapperActiveFacet | null = null\n\n private inputRef: TextInput | null = null\n private updating = false\n\n // useSyncExternalStore plumbing\n private storeListeners = new Set<() => void>()\n private snapshot: TapperSnapshot\n\n constructor(config?: TapperConfig) {\n const facets = config?.facets || defaultFacets\n this.facetRegexes = compileFacetRegexes(facets)\n this.triggers = deriveTriggers(facets)\n this.snapshot = {\n text: this.text,\n selection: this.selection,\n nodes: this.nodes,\n activeFacet: this.activeFacet,\n }\n if (config?.initialText) {\n this.replaceText(config.initialText)\n }\n }\n\n setInputRef = (node: TextInput | null) => {\n this.inputRef = node\n }\n\n private setInputSelection(start: number, end: number) {\n const el = this.inputRef as any\n if (!el) return\n if (typeof el.setSelection === 'function') {\n el.setSelection(start, end)\n } else if (typeof el.setSelectionRange === 'function') {\n el.setSelectionRange(start, end)\n }\n }\n\n subscribe = (listener: () => void) => {\n this.storeListeners.add(listener)\n return () => this.storeListeners.delete(listener)\n }\n\n getSnapshot = (): TapperSnapshot => {\n return this.snapshot\n }\n\n on = <K extends keyof TapperEvents>(\n event: K,\n cb: (data: TapperEvents[K]) => void,\n ) => {\n if (!this.listeners.has(event)) this.listeners.set(event, new Set())\n this.listeners.get(event)!.add(cb)\n return () => {\n this.listeners.get(event)?.delete(cb)\n }\n }\n\n private emit<K extends keyof TapperEvents>(event: K, data: TapperEvents[K]) {\n this.listeners.get(event)?.forEach(cb => cb(data))\n }\n\n private notify() {\n this.snapshot = {\n text: this.text,\n selection: this.selection,\n nodes: this.nodes,\n activeFacet: this.activeFacet,\n }\n this.storeListeners.forEach(l => l())\n }\n\n private update(\n newText: string,\n selection: TapperSelection,\n commitAll?: boolean,\n ) {\n // guard against circular updates when insert() is called during an update cycle\n if (this.updating) return\n this.updating = true\n\n const cursor = selection.end\n const isRange = selection.start !== selection.end\n\n const nodes =\n newText === this.text\n ? this.nodes\n : parseNodesFromText(\n newText,\n this.facetRegexes,\n this.nodes,\n cursor,\n this.triggers,\n )\n const prev = this.activeFacet\n const detected =\n isRange || commitAll\n ? null\n : detectActiveFacet(nodes, newText, cursor, this.triggers)\n\n // When cursor leaves a facet, commit it.\n // On paste (commitAll), commit every uncommitted facet.\n const committedNodes: TapperNode[] = []\n if (commitAll) {\n for (const node of nodes) {\n if (node.type === 'facet' && !node.committed) {\n node.committed = true\n committedNodes.push(node)\n }\n }\n } else if (prev && (!detected || detected.type !== prev.type)) {\n for (const node of nodes) {\n if (\n node.type === 'facet' &&\n node.facetType === prev.type &&\n node.start === prev.range.start &&\n node.end === prev.range.end\n ) {\n node.committed = true\n committedNodes.push(node)\n break\n }\n }\n }\n\n // Build activeFacet with insert() baked in\n const active: TapperActiveFacet | null = detected\n ? {...detected, replace: this.replace}\n : null\n\n this.text = newText\n this.selection = selection\n this.nodes = nodes\n this.activeFacet = active\n\n this.updating = false\n this.notify()\n\n // Fire events after state is finalized\n const facetChanged =\n active?.type !== prev?.type ||\n active?.value !== prev?.value ||\n active?.range.start !== prev?.range.start ||\n active?.range.end !== prev?.range.end\n if (facetChanged) {\n this.emit('activeFacet', active)\n }\n for (const node of committedNodes) {\n this.emit('facetCommitted', nodeToFacet(node))\n }\n }\n\n handleTextChange = (newText: string) => {\n if (newText === this.text) return\n\n const diff = newText.length - this.text.length\n let newEnd = Math.max(this.selection.end + diff, 0)\n\n // Atomic deletion: backspace into a facet from outside\n let didAtomicDelete = false\n if (diff === -1 && newEnd < this.selection.end) {\n for (const node of this.nodes) {\n if (\n node.type === 'facet' &&\n node.committed &&\n this.selection.end === node.end\n ) {\n const remnant = node.end - node.start - 1\n newText =\n newText.slice(0, node.start) + newText.slice(node.start + remnant)\n newEnd = node.start\n didAtomicDelete = true\n break\n }\n }\n }\n\n // Paste: commit all facets immediately\n const mayBePaste = diff > 1\n\n this.update(newText, {start: newEnd, end: newEnd}, mayBePaste)\n if (didAtomicDelete) {\n this.setInputSelection(newEnd, newEnd)\n }\n }\n\n handleSelectionChange = (e: {\n nativeEvent: {selection: {start: number; end: number}}\n }) => {\n const {start, end} = e.nativeEvent.selection\n\n if (end > this.text.length) return\n\n if (start === this.selection.start && end === this.selection.end) return\n\n this.selection = {start, end}\n\n /*\n * For selection-only changes (no text change), check if the active facet\n * would change. If not, skip the full update() cycle — just update the\n * selection in the snapshot.\n */\n const isRange = start !== end\n const detected = isRange\n ? null\n : detectActiveFacet(this.nodes, this.text, end, this.triggers)\n const prev = this.activeFacet\n const facetChanged =\n detected?.type !== prev?.type ||\n detected?.value !== prev?.value ||\n detected?.range.start !== prev?.range.start ||\n detected?.range.end !== prev?.range.end\n if (!facetChanged) {\n this.snapshot = {...this.snapshot, selection: this.selection}\n this.storeListeners.forEach(l => l())\n return\n }\n\n this.update(this.text, {start, end})\n }\n\n replaceText = (text: string, cursor?: number) => {\n const prevActive = this.activeFacet\n const nodes = parseNodesFromText(text, this.facetRegexes)\n // Mark all non-text nodes as committed (pre-existing facets)\n const newlyCommitted: TapperNode[] = []\n for (const node of nodes) {\n if (node.type === 'facet') {\n node.committed = true\n newlyCommitted.push(node)\n }\n }\n\n const pos = cursor ?? text.length\n const detected = detectActiveFacet(nodes, text, pos, this.triggers)\n const active: TapperActiveFacet | null = detected\n ? {...detected, replace: this.replace}\n : null\n\n this.text = text\n this.selection = {start: pos, end: pos}\n this.nodes = nodes\n this.activeFacet = active\n\n this.notify()\n\n if (active !== prevActive) {\n this.emit('activeFacet', active)\n }\n for (const node of newlyCommitted) {\n this.emit('facetCommitted', nodeToFacet(node))\n }\n }\n\n private replace = (value: string, options?: {noTrailingSpace?: boolean}) => {\n if (!this.activeFacet) return\n\n const replacement = value + (options?.noTrailingSpace ? '' : ' ')\n const newText =\n this.text.slice(0, this.activeFacet.range.start) +\n replacement +\n this.text.slice(this.activeFacet.range.end)\n const newEnd = this.activeFacet.range.start + replacement.length\n\n if (this.activeFacet) {\n this.activeFacet.raw = value\n this.activeFacet.value = value\n this.activeFacet.range = {\n start: this.activeFacet.range.start,\n end: this.activeFacet.range.start + value.length,\n }\n this.emit('afterInsert', this.activeFacet)\n }\n\n this.update(newText, {start: newEnd, end: newEnd})\n this.setInputSelection(newEnd, newEnd)\n }\n\n insert = (text: string) => {\n const pos = this.selection.end\n const newText = this.text.slice(0, pos) + text + this.text.slice(pos)\n const newEnd = pos + text.length\n this.update(newText, {start: newEnd, end: newEnd})\n this.setInputSelection(newEnd, newEnd)\n }\n}\n\nexport function useTapper(config: TapperConfig) {\n const [store] = useState(() => new Tapper(config))\n const state = useSyncExternalStore(store.subscribe, store.getSnapshot)\n const [input, setInput] = useState<TextInput | null>(null)\n const inputRef = useRef<{focus(): void}>(null)\n\n const handleSetInput = useCallback(\n (node: TextInput | null) => {\n inputRef.current = node\n store.setInputRef(node)\n setInput(node)\n },\n [store],\n )\n const focus = useCallback(() => input?.focus(), [input])\n const blur = useCallback(() => input?.blur(), [input])\n\n return {\n state,\n on: store.on,\n insert: store.insert,\n input: {\n element: input,\n focus,\n blur,\n },\n inputProps: {\n ref: handleSetInput,\n value: IS_WEB ? state.text : undefined,\n onChangeText: store.handleTextChange,\n onSelectionChange: store.handleSelectionChange,\n },\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAC,MAAM,OAAO,CAAA;AACzE,OAAO,EAAC,QAAQ,EAAY,MAAM,cAAc,CAAA;AAEhD,OAAO,KAAK,aAAa,MAAM,UAAU,CAAA;AASzC,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,mBAAmB,GAEpB,MAAM,QAAQ,CAAA;AAEf,cAAc,SAAS,CAAA;AACvB,OAAO,KAAK,MAAM,MAAM,UAAU,CAAA;AAElC,MAAM,MAAM,GAAG,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAA;AAEpC,MAAM,OAAO,MAAM;IACT,YAAY,CAAsB;IAClC,QAAQ,CAAqB;IAErC,iBAAiB;IAET,SAAS,GAAG,IAAI,GAAG,EAAgD,CAAA;IAE3E,eAAe;IACf,IAAI,GAAG,EAAE,CAAA;IACT,SAAS,GAAoB,EAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAC,CAAA;IAC/C,KAAK,GAAiB,EAAE,CAAA;IACxB,WAAW,GAA6B,IAAI,CAAA;IAEpC,QAAQ,GAAqB,IAAI,CAAA;IACjC,QAAQ,GAAG,KAAK,CAAA;IAExB,gCAAgC;IACxB,cAAc,GAAG,IAAI,GAAG,EAAc,CAAA;IACtC,QAAQ,CAAgB;IAEhC,YAAY,MAAqB;QAC/B,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,IAAI,aAAa,CAAA;QAC9C,IAAI,C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AI,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEtD,OAAO;QACL,KAAK;QACL,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE;YACL,OAAO,EAAE,KAAK;YACd,KAAK;YACL,IAAI;SACL;QACD,UAAU,EAAE;YACV,GAAG,EAAE,cAAc;YACnB,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;YACtC,YAAY,EAAE,KAAK,CAAC,gBAAgB;YACpC,iBAAiB,EAAE,KAAK,CAAC,qBAAqB;SAC/C;KACF,CAAA;AACH,CAAC","sourcesContent":["import {useCallback, useRef, useState, useSyncExternalStore} from 'react'\nimport {Platform, TextInput} from 'react-native'\n\nimport * as defaultFacets from './facets'\nimport {\n TapperConfig,\n TapperEvents,\n TapperNode,\n TapperActiveFacet,\n TapperSelection,\n TapperSnapshot,\n} from './types'\nimport {\n parseNodesFromText,\n detectActiveFacet,\n deriveTriggers,\n nodeToFacet,\n compileFacetRegexes,\n type CompiledFacetRegexes,\n} from './util'\n\nexport * from './types'\nexport * as facets from './facets'\n\nconst IS_WEB = Platform.OS === 'web'\n\nexport class Tapper {\n private facetRegexes: CompiledFacetRegexes\n private triggers: Map<string, string>\n\n // Event emitters\n\n private listeners = new Map<keyof TapperEvents, Set<(data: any) => void>>()\n\n // Public state\n text = ''\n selection: TapperSelection = {start: 0, end: 0}\n nodes: TapperNode[] = []\n activeFacet: TapperActiveFacet | null = null\n\n private inputRef: TextInput | null = null\n private updating = false\n\n // useSyncExternalStore plumbing\n private storeListeners = new Set<() => void>()\n private snapshot: TapperSnapshot\n\n constructor(config?: TapperConfig) {\n const facets = config?.facets || defaultFacets\n this.facetRegexes = compileFacetRegexes(facets)\n this.triggers = deriveTriggers(facets)\n this.snapshot = {\n text: this.text,\n selection: this.selection,\n nodes: this.nodes,\n activeFacet: this.activeFacet,\n }\n if (config?.initialText) {\n this.replaceText(config.initialText)\n }\n }\n\n setInputRef = (node: TextInput | null) => {\n this.inputRef = node\n }\n\n private setInputSelection(start: number, end: number) {\n const el = this.inputRef as any\n if (!el) return\n if (typeof el.setSelection === 'function') {\n el.setSelection(start, end)\n } else if (typeof el.setSelectionRange === 'function') {\n el.setSelectionRange(start, end)\n }\n }\n\n subscribe = (listener: () => void) => {\n this.storeListeners.add(listener)\n return () => this.storeListeners.delete(listener)\n }\n\n getSnapshot = (): TapperSnapshot => {\n return this.snapshot\n }\n\n on = <K extends keyof TapperEvents>(\n event: K,\n cb: (data: TapperEvents[K]) => void,\n ) => {\n if (!this.listeners.has(event)) this.listeners.set(event, new Set())\n this.listeners.get(event)!.add(cb)\n return () => {\n this.listeners.get(event)?.delete(cb)\n }\n }\n\n private emit<K extends keyof TapperEvents>(event: K, data: TapperEvents[K]) {\n this.listeners.get(event)?.forEach(cb => cb(data))\n }\n\n private notify() {\n this.snapshot = {\n text: this.text,\n selection: this.selection,\n nodes: this.nodes,\n activeFacet: this.activeFacet,\n }\n this.storeListeners.forEach(l => l())\n }\n\n private update(\n newText: string,\n selection: TapperSelection,\n commitAll?: boolean,\n ) {\n // guard against circular updates when insert() is called during an update cycle\n if (this.updating) return\n this.updating = true\n\n const cursor = selection.end\n const isRange = selection.start !== selection.end\n\n const nodes =\n newText === this.text\n ? this.nodes\n : parseNodesFromText(\n newText,\n this.facetRegexes,\n this.nodes,\n cursor,\n this.triggers,\n )\n const prev = this.activeFacet\n const detected =\n isRange || commitAll\n ? null\n : detectActiveFacet(nodes, newText, cursor, this.triggers)\n\n // When cursor leaves a facet, commit it.\n // On paste (commitAll), commit every uncommitted facet.\n const committedNodes: TapperNode[] = []\n if (commitAll) {\n for (const node of nodes) {\n if (node.type === 'facet' && !node.committed) {\n node.committed = true\n committedNodes.push(node)\n }\n }\n } else if (prev && (!detected || detected.type !== prev.type)) {\n for (const node of nodes) {\n if (\n node.type === 'facet' &&\n node.facetType === prev.type &&\n node.start === prev.range.start &&\n node.end === prev.range.end\n ) {\n node.committed = true\n committedNodes.push(node)\n break\n }\n }\n }\n\n // Build activeFacet with insert() baked in\n const active: TapperActiveFacet | null = detected\n ? {...detected, replace: this.replace}\n : null\n\n this.text = newText\n this.selection = selection\n this.nodes = nodes\n this.activeFacet = active\n\n this.updating = false\n this.notify()\n\n // Fire events after state is finalized\n const facetChanged =\n active?.type !== prev?.type ||\n active?.value !== prev?.value ||\n active?.range.start !== prev?.range.start ||\n active?.range.end !== prev?.range.end\n if (facetChanged) {\n this.emit('activeFacet', active)\n }\n for (const node of committedNodes) {\n this.emit('facetCommitted', nodeToFacet(node))\n }\n }\n\n handleTextChange = (newText: string) => {\n if (newText === this.text) return\n\n const diff = newText.length - this.text.length\n let newEnd = Math.max(this.selection.end + diff, 0)\n\n // Atomic deletion: backspace into a facet from outside.\n // URLs are excluded — users typically want to edit them character by character.\n let didAtomicDelete = false\n if (diff === -1 && newEnd < this.selection.end) {\n for (const node of this.nodes) {\n if (\n node.type === 'facet' &&\n node.facetType !== 'url' &&\n node.committed &&\n this.selection.end === node.end\n ) {\n const remnant = node.end - node.start - 1\n newText =\n newText.slice(0, node.start) + newText.slice(node.start + remnant)\n newEnd = node.start\n didAtomicDelete = true\n break\n }\n }\n }\n\n // Paste: commit all facets immediately\n const mayBePaste = diff > 1\n\n this.update(newText, {start: newEnd, end: newEnd}, mayBePaste)\n if (didAtomicDelete) {\n this.setInputSelection(newEnd, newEnd)\n }\n }\n\n handleSelectionChange = (e: {\n nativeEvent: {selection: {start: number; end: number}}\n }) => {\n const {start, end} = e.nativeEvent.selection\n\n if (end > this.text.length) return\n\n if (start === this.selection.start && end === this.selection.end) return\n\n this.selection = {start, end}\n\n /*\n * For selection-only changes (no text change), check if the active facet\n * would change. If not, skip the full update() cycle — just update the\n * selection in the snapshot.\n */\n const isRange = start !== end\n const detected = isRange\n ? null\n : detectActiveFacet(this.nodes, this.text, end, this.triggers)\n const prev = this.activeFacet\n const facetChanged =\n detected?.type !== prev?.type ||\n detected?.value !== prev?.value ||\n detected?.range.start !== prev?.range.start ||\n detected?.range.end !== prev?.range.end\n if (!facetChanged) {\n this.snapshot = {...this.snapshot, selection: this.selection}\n this.storeListeners.forEach(l => l())\n return\n }\n\n this.update(this.text, {start, end})\n }\n\n replaceText = (text: string, cursor?: number) => {\n const prevActive = this.activeFacet\n const nodes = parseNodesFromText(text, this.facetRegexes)\n // Mark all non-text nodes as committed (pre-existing facets)\n const newlyCommitted: TapperNode[] = []\n for (const node of nodes) {\n if (node.type === 'facet') {\n node.committed = true\n newlyCommitted.push(node)\n }\n }\n\n const pos = cursor ?? text.length\n const detected = detectActiveFacet(nodes, text, pos, this.triggers)\n const active: TapperActiveFacet | null = detected\n ? {...detected, replace: this.replace}\n : null\n\n this.text = text\n this.selection = {start: pos, end: pos}\n this.nodes = nodes\n this.activeFacet = active\n\n this.notify()\n\n if (active !== prevActive) {\n this.emit('activeFacet', active)\n }\n for (const node of newlyCommitted) {\n this.emit('facetCommitted', nodeToFacet(node))\n }\n }\n\n private replace = (value: string, options?: {noTrailingSpace?: boolean}) => {\n if (!this.activeFacet) return\n\n const replacement = value + (options?.noTrailingSpace ? '' : ' ')\n const newText =\n this.text.slice(0, this.activeFacet.range.start) +\n replacement +\n this.text.slice(this.activeFacet.range.end)\n const newEnd = this.activeFacet.range.start + replacement.length\n\n if (this.activeFacet) {\n this.activeFacet.raw = value\n this.activeFacet.value = value\n this.activeFacet.range = {\n start: this.activeFacet.range.start,\n end: this.activeFacet.range.start + value.length,\n }\n this.emit('afterInsert', this.activeFacet)\n }\n\n this.update(newText, {start: newEnd, end: newEnd})\n this.setInputSelection(newEnd, newEnd)\n }\n\n insert = (text: string) => {\n const pos = this.selection.end\n const newText = this.text.slice(0, pos) + text + this.text.slice(pos)\n const newEnd = pos + text.length\n this.update(newText, {start: newEnd, end: newEnd})\n this.setInputSelection(newEnd, newEnd)\n }\n}\n\nexport function useTapper(config: TapperConfig) {\n const [store] = useState(() => new Tapper(config))\n const state = useSyncExternalStore(store.subscribe, store.getSnapshot)\n const [input, setInput] = useState<TextInput | null>(null)\n const inputRef = useRef<{focus(): void}>(null)\n\n const handleSetInput = useCallback(\n (node: TextInput | null) => {\n inputRef.current = node\n store.setInputRef(node)\n setInput(node)\n },\n [store],\n )\n const focus = useCallback(() => input?.focus(), [input])\n const blur = useCallback(() => input?.blur(), [input])\n\n return {\n state,\n on: store.on,\n insert: store.insert,\n input: {\n element: input,\n focus,\n blur,\n },\n inputProps: {\n ref: handleSetInput,\n value: IS_WEB ? state.text : undefined,\n onChangeText: store.handleTextChange,\n onSelectionChange: store.handleSelectionChange,\n },\n }\n}\n"]}
|
package/build/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAC,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAC,MAAM,SAAS,CAAA;AAmBlE,MAAM,MAAM,oBAAoB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAEtD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,iBAAiB,GACxB,oBAAoB,CAMtB;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,oBAAoB,EAC7B,SAAS,CAAC,EAAE,UAAU,EAAE,EACxB,MAAM,CAAC,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,UAAU,EAAE,CA6Kd;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,iBAAiB,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAW7E;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,WAAW,CAOzD;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,UAAU,EAAE,EACnB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,WAAW,GAAG,IAAI,CAkDpB"}
|
package/build/util.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
const WHITESPACE = /\s/;
|
|
2
|
+
// Regexes whose source starts with this prefix use a leading capture group
|
|
3
|
+
// to gate matches on a boundary (start-of-string, whitespace, or `(`) without
|
|
4
|
+
// lookbehind. The captured boundary char is stripped from the match so
|
|
5
|
+
// positions and `raw` reflect the facet itself.
|
|
6
|
+
const BOUNDARY_PREFIX = '(^|\\s|\\()';
|
|
7
|
+
// Mirror the regex's `(^|\s|\()` gate so trigger detection (for chars typed
|
|
8
|
+
// before any regex match exists) doesn't fire mid-word — e.g. the `@` inside
|
|
9
|
+
// `eric@blueskyweb.xyz` should not synthesize a mention trigger.
|
|
10
|
+
function isBoundaryBefore(text, i) {
|
|
11
|
+
if (i === 0)
|
|
12
|
+
return true;
|
|
13
|
+
const prev = text[i - 1];
|
|
14
|
+
return prev === '(' || WHITESPACE.test(prev);
|
|
15
|
+
}
|
|
2
16
|
let nextNodeId = 0;
|
|
3
17
|
/**
|
|
4
18
|
* Pre-compile facet regexes once at init time. This avoids re-creating
|
|
@@ -19,12 +33,17 @@ export function parseNodesFromText(text, regexes, prevNodes, cursor, triggers) {
|
|
|
19
33
|
// Reset lastIndex so stateful (global) regexes don't carry over
|
|
20
34
|
// match positions from the previous parse call.
|
|
21
35
|
re.lastIndex = 0;
|
|
36
|
+
// Boundary-gated regexes shift the effective start past the captured
|
|
37
|
+
// boundary char (m[1]) and bump the value capture index by one.
|
|
38
|
+
const hasBoundary = re.source.startsWith(BOUNDARY_PREFIX);
|
|
22
39
|
for (const m of text.matchAll(re)) {
|
|
40
|
+
const boundaryLen = hasBoundary ? (m[1]?.length ?? 0) : 0;
|
|
41
|
+
const fullMatch = m[0].slice(boundaryLen);
|
|
23
42
|
allMatches.push({
|
|
24
43
|
facetName: name,
|
|
25
|
-
fullMatch
|
|
26
|
-
capture: m[
|
|
27
|
-
index: m.index,
|
|
44
|
+
fullMatch,
|
|
45
|
+
capture: (hasBoundary ? m[2] : m[1]) ?? fullMatch,
|
|
46
|
+
index: m.index + boundaryLen,
|
|
28
47
|
});
|
|
29
48
|
}
|
|
30
49
|
}
|
|
@@ -81,7 +100,7 @@ export function parseNodesFromText(text, regexes, prevNodes, cursor, triggers) {
|
|
|
81
100
|
if (WHITESPACE.test(ch))
|
|
82
101
|
break;
|
|
83
102
|
const facetType = triggers.get(ch);
|
|
84
|
-
if (facetType) {
|
|
103
|
+
if (facetType && isBoundaryBefore(text, i)) {
|
|
85
104
|
// Only create a trigger node if the trigger is inside a text node
|
|
86
105
|
// (i.e. the regex didn't already match it as a facet)
|
|
87
106
|
const textNodeIdx = nodes.findIndex(n => n.type === 'text' && n.start <= i && n.end > i);
|
|
@@ -170,7 +189,11 @@ export function parseNodesFromText(text, regexes, prevNodes, cursor, triggers) {
|
|
|
170
189
|
export function deriveTriggers(config) {
|
|
171
190
|
const triggers = new Map();
|
|
172
191
|
for (const [name, re] of Object.entries(config)) {
|
|
173
|
-
|
|
192
|
+
// Skip the boundary prefix (if present) before extracting the trigger char.
|
|
193
|
+
const src = re.source.startsWith(BOUNDARY_PREFIX)
|
|
194
|
+
? re.source.slice(BOUNDARY_PREFIX.length)
|
|
195
|
+
: re.source;
|
|
196
|
+
const m = src.match(/^[^\\([\]{}.*+?^$|]+/);
|
|
174
197
|
if (m)
|
|
175
198
|
triggers.set(m[0], name);
|
|
176
199
|
}
|
|
@@ -216,7 +239,7 @@ export function detectActiveFacet(nodes, text, cursor, triggers) {
|
|
|
216
239
|
if (WHITESPACE.test(ch))
|
|
217
240
|
break;
|
|
218
241
|
const type = triggers.get(ch);
|
|
219
|
-
if (type) {
|
|
242
|
+
if (type && isBoundaryBefore(text, i)) {
|
|
220
243
|
const raw = text.slice(i, cursor);
|
|
221
244
|
return {
|
|
222
245
|
type,
|
package/build/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,IAAI,UAAU,GAAG,CAAC,CAAA;AAIlB;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAyB;IAEzB,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAA;IAC1C,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAChD,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IACrD,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,IAAY,EACZ,OAA6B,EAC7B,SAAwB,EACxB,MAAe,EACf,QAA8B;IAE9B,MAAM,UAAU,GAKV,EAAE,CAAA;IAER,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,OAAO,EAAE,CAAC;QACjC,gEAAgE;QAChE,gDAAgD;QAChD,EAAE,CAAC,SAAS,GAAG,CAAC,CAAA;QAChB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;YAClC,UAAU,CAAC,IAAI,CAAC;gBACd,SAAS,EAAE,IAAI;gBACf,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;gBACf,OAAO,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C3E,CAAA;IACD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,KAAK,IAAI,CAAC,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;YAClB,wDAAwD;YACxD,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;gBAAE,MAAK;YAC9B,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;YAC7B,IAAI,IAAI,EAAE,CAAC;gBACT,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;gBACjC,OAAO;oBACL,IAAI;oBACJ,GAAG;oBACH,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;oBAChC,KAAK,EAAE,EAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAC;iBAC/B,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import {TapperFacetConfig, TapperNode, TapperFacet} from './types'\n\nconst WHITESPACE = /\\s/\nlet nextNodeId = 0\n\nexport type CompiledFacetRegexes = Map<string, RegExp>\n\n/**\n * Pre-compile facet regexes once at init time. This avoids re-creating\n * RegExp objects on every keystroke in parseNodesFromText. Each Tapper\n * instance gets its own compiled copy so lastIndex state can't leak\n * between instances.\n */\nexport function compileFacetRegexes(\n config: TapperFacetConfig,\n): CompiledFacetRegexes {\n const compiled = new Map<string, RegExp>()\n for (const [name, re] of Object.entries(config)) {\n compiled.set(name, new RegExp(re.source, re.flags))\n }\n return compiled\n}\n\nexport function parseNodesFromText(\n text: string,\n regexes: CompiledFacetRegexes,\n prevNodes?: TapperNode[],\n cursor?: number,\n triggers?: Map<string, string>,\n): TapperNode[] {\n const allMatches: {\n facetName: string\n fullMatch: string\n capture: string\n index: number\n }[] = []\n\n for (const [name, re] of regexes) {\n // Reset lastIndex so stateful (global) regexes don't carry over\n // match positions from the previous parse call.\n re.lastIndex = 0\n for (const m of text.matchAll(re)) {\n allMatches.push({\n facetName: name,\n fullMatch: m[0],\n capture: m[1] ?? m[0],\n index: m.index,\n })\n }\n }\n\n allMatches.sort(\n (a, b) => a.index - b.index || b.fullMatch.length - a.fullMatch.length,\n )\n\n const accepted: typeof allMatches = []\n let lastEnd = 0\n for (const m of allMatches) {\n if (m.index >= lastEnd) {\n accepted.push(m)\n lastEnd = m.index + m.fullMatch.length\n }\n }\n\n const nodes: TapperNode[] = []\n let pos = 0\n\n for (const m of accepted) {\n if (m.index > pos) {\n const raw = text.slice(pos, m.index)\n nodes.push({\n id: nextNodeId++,\n type: 'text',\n raw,\n value: raw,\n start: pos,\n end: m.index,\n })\n }\n nodes.push({\n id: nextNodeId++,\n type: 'facet',\n facetType: m.facetName,\n raw: m.fullMatch,\n value: m.capture,\n start: m.index,\n end: m.index + m.fullMatch.length,\n })\n pos = m.index + m.fullMatch.length\n }\n\n if (pos < text.length) {\n const raw = text.slice(pos)\n nodes.push({\n id: nextNodeId++,\n type: 'text',\n raw,\n value: raw,\n start: pos,\n end: text.length,\n })\n }\n\n // If the cursor is right after a trigger char that the regex didn't match,\n // splice a 'trigger' node out of the containing text node.\n if (cursor != null && triggers) {\n for (let i = cursor - 1; i >= 0; i--) {\n const ch = text[i]\n if (WHITESPACE.test(ch)) break\n const facetType = triggers.get(ch)\n if (facetType) {\n // Only create a trigger node if the trigger is inside a text node\n // (i.e. the regex didn't already match it as a facet)\n const textNodeIdx = nodes.findIndex(\n n => n.type === 'text' && n.start <= i && n.end > i,\n )\n if (textNodeIdx !== -1) {\n const node = nodes[textNodeIdx]\n const spliced: TapperNode[] = []\n if (node.start < i) {\n const raw = text.slice(node.start, i)\n spliced.push({\n id: nextNodeId++,\n type: 'text',\n raw,\n value: raw,\n start: node.start,\n end: i,\n })\n }\n const triggerRaw = text.slice(i, cursor)\n spliced.push({\n id: nextNodeId++,\n type: 'trigger',\n facetType,\n raw: triggerRaw,\n value: text.slice(i + ch.length, cursor),\n start: i,\n end: cursor,\n })\n if (cursor < node.end) {\n const raw = text.slice(cursor, node.end)\n spliced.push({\n id: nextNodeId++,\n type: 'text',\n raw,\n value: raw,\n start: cursor,\n end: node.end,\n })\n }\n nodes.splice(textNodeIdx, 1, ...spliced)\n }\n break\n }\n }\n }\n\n // Transfer committed flags and stable IDs from previous nodes\n if (prevNodes) {\n // Facet nodes: match by facetType + occurrence index\n const counts = new Map<string, number>()\n const prevFacetsByTypeIndex = new Map<string, TapperNode>()\n\n for (const node of prevNodes) {\n if (node.type !== 'facet') continue\n const idx = counts.get(node.facetType!) ?? 0\n counts.set(node.facetType!, idx + 1)\n prevFacetsByTypeIndex.set(`${node.facetType}:${idx}`, node)\n }\n\n counts.clear()\n for (const node of nodes) {\n if (node.type !== 'facet') continue\n const idx = counts.get(node.facetType!) ?? 0\n counts.set(node.facetType!, idx + 1)\n const prev = prevFacetsByTypeIndex.get(`${node.facetType}:${idx}`)\n if (prev) {\n node.id = prev.id\n if (prev.committed) node.committed = true\n }\n }\n\n // Text nodes: match by start position\n const prevTextByStart = new Map<number, TapperNode>()\n for (const node of prevNodes) {\n if (node.type === 'text') prevTextByStart.set(node.start, node)\n }\n for (const node of nodes) {\n if (node.type === 'text') {\n const prev = prevTextByStart.get(node.start)\n if (prev) node.id = prev.id\n }\n }\n }\n\n return nodes\n}\n\nexport function deriveTriggers(config: TapperFacetConfig): Map<string, string> {\n const triggers = new Map<string, string>()\n for (const [name, re] of Object.entries(config)) {\n const m = re.source.match(/^[^\\\\([\\]{}.*+?^$|]+/)\n if (m) triggers.set(m[0], name)\n }\n return triggers\n}\n\nexport function nodeToFacet(node: TapperNode): TapperFacet {\n return {\n type: node.facetType!,\n raw: node.raw,\n value: node.value,\n range: {start: node.start, end: node.end},\n }\n}\n\nexport function detectActiveFacet(\n nodes: TapperNode[],\n text: string,\n cursor: number,\n triggers: Map<string, string>,\n): TapperFacet | null {\n for (const node of nodes) {\n if (node.type === 'trigger' && node.start < cursor && cursor <= node.end) {\n return {\n type: node.facetType,\n raw: node.raw,\n value: node.value,\n range: {start: node.start, end: node.end},\n }\n }\n if (\n node.type === 'facet' &&\n !node.committed &&\n node.start < cursor &&\n cursor <= node.end\n ) {\n return {\n type: node.facetType,\n raw: node.raw,\n value: node.value,\n range: {start: node.start, end: node.end},\n }\n }\n }\n\n // Scan backward from cursor for a trigger char (partial facet not yet matched by regex).\n // Skip if the cursor is inside or at the end of a committed facet.\n const inCommitted = nodes.some(\n n =>\n n.type === 'facet' && n.committed && n.start < cursor && cursor <= n.end,\n )\n if (!inCommitted) {\n for (let i = cursor - 1; i >= 0; i--) {\n const ch = text[i]\n // Stop at whitespace — triggers don't span across words\n if (WHITESPACE.test(ch)) break\n const type = triggers.get(ch)\n if (type) {\n const raw = text.slice(i, cursor)\n return {\n type,\n raw,\n value: text.slice(i + 1, cursor),\n range: {start: i, end: cursor},\n }\n }\n }\n }\n\n return null\n}\n"]}
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,2EAA2E;AAC3E,8EAA8E;AAC9E,uEAAuE;AACvE,gDAAgD;AAChD,MAAM,eAAe,GAAG,aAAa,CAAA;AAErC,4EAA4E;AAC5E,6EAA6E;AAC7E,iEAAiE;AACjE,SAAS,gBAAgB,CAAC,IAAY,EAAE,CAAS;IAC/C,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACxB,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IACxB,OAAO,IAAI,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC9C,CAAC;AACD,IAAI,UAAU,GAAG,CAAC,CAA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ED,yFAAyF;IACzF,mEAAmE;IACnE,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAC5B,CAAC,CAAC,EAAE,CACF,CAAC,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,KAAK,GAAG,MAAM,IAAI,MAAM,IAAI,CAAC,CAAC,GAAG,CAC3E,CAAA;IACD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,KAAK,IAAI,CAAC,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;YAClB,wDAAwD;YACxD,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;gBAAE,MAAK;YAC9B,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;YAC7B,IAAI,IAAI,IAAI,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;gBACtC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;gBACjC,OAAO;oBACL,IAAI;oBACJ,GAAG;oBACH,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;oBAChC,KAAK,EAAE,EAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAC;iBAC/B,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import {TapperFacetConfig, TapperNode, TapperFacet} from './types'\n\nconst WHITESPACE = /\\s/\n// Regexes whose source starts with this prefix use a leading capture group\n// to gate matches on a boundary (start-of-string, whitespace, or `(`) without\n// lookbehind. The captured boundary char is stripped from the match so\n// positions and `raw` reflect the facet itself.\nconst BOUNDARY_PREFIX = '(^|\\\\s|\\\\()'\n\n// Mirror the regex's `(^|\\s|\\()` gate so trigger detection (for chars typed\n// before any regex match exists) doesn't fire mid-word — e.g. the `@` inside\n// `eric@blueskyweb.xyz` should not synthesize a mention trigger.\nfunction isBoundaryBefore(text: string, i: number) {\n if (i === 0) return true\n const prev = text[i - 1]\n return prev === '(' || WHITESPACE.test(prev)\n}\nlet nextNodeId = 0\n\nexport type CompiledFacetRegexes = Map<string, RegExp>\n\n/**\n * Pre-compile facet regexes once at init time. This avoids re-creating\n * RegExp objects on every keystroke in parseNodesFromText. Each Tapper\n * instance gets its own compiled copy so lastIndex state can't leak\n * between instances.\n */\nexport function compileFacetRegexes(\n config: TapperFacetConfig,\n): CompiledFacetRegexes {\n const compiled = new Map<string, RegExp>()\n for (const [name, re] of Object.entries(config)) {\n compiled.set(name, new RegExp(re.source, re.flags))\n }\n return compiled\n}\n\nexport function parseNodesFromText(\n text: string,\n regexes: CompiledFacetRegexes,\n prevNodes?: TapperNode[],\n cursor?: number,\n triggers?: Map<string, string>,\n): TapperNode[] {\n const allMatches: {\n facetName: string\n fullMatch: string\n capture: string\n index: number\n }[] = []\n\n for (const [name, re] of regexes) {\n // Reset lastIndex so stateful (global) regexes don't carry over\n // match positions from the previous parse call.\n re.lastIndex = 0\n // Boundary-gated regexes shift the effective start past the captured\n // boundary char (m[1]) and bump the value capture index by one.\n const hasBoundary = re.source.startsWith(BOUNDARY_PREFIX)\n for (const m of text.matchAll(re)) {\n const boundaryLen = hasBoundary ? (m[1]?.length ?? 0) : 0\n const fullMatch = m[0].slice(boundaryLen)\n allMatches.push({\n facetName: name,\n fullMatch,\n capture: (hasBoundary ? m[2] : m[1]) ?? fullMatch,\n index: m.index + boundaryLen,\n })\n }\n }\n\n allMatches.sort(\n (a, b) => a.index - b.index || b.fullMatch.length - a.fullMatch.length,\n )\n\n const accepted: typeof allMatches = []\n let lastEnd = 0\n for (const m of allMatches) {\n if (m.index >= lastEnd) {\n accepted.push(m)\n lastEnd = m.index + m.fullMatch.length\n }\n }\n\n const nodes: TapperNode[] = []\n let pos = 0\n\n for (const m of accepted) {\n if (m.index > pos) {\n const raw = text.slice(pos, m.index)\n nodes.push({\n id: nextNodeId++,\n type: 'text',\n raw,\n value: raw,\n start: pos,\n end: m.index,\n })\n }\n nodes.push({\n id: nextNodeId++,\n type: 'facet',\n facetType: m.facetName,\n raw: m.fullMatch,\n value: m.capture,\n start: m.index,\n end: m.index + m.fullMatch.length,\n })\n pos = m.index + m.fullMatch.length\n }\n\n if (pos < text.length) {\n const raw = text.slice(pos)\n nodes.push({\n id: nextNodeId++,\n type: 'text',\n raw,\n value: raw,\n start: pos,\n end: text.length,\n })\n }\n\n // If the cursor is right after a trigger char that the regex didn't match,\n // splice a 'trigger' node out of the containing text node.\n if (cursor != null && triggers) {\n for (let i = cursor - 1; i >= 0; i--) {\n const ch = text[i]\n if (WHITESPACE.test(ch)) break\n const facetType = triggers.get(ch)\n if (facetType && isBoundaryBefore(text, i)) {\n // Only create a trigger node if the trigger is inside a text node\n // (i.e. the regex didn't already match it as a facet)\n const textNodeIdx = nodes.findIndex(\n n => n.type === 'text' && n.start <= i && n.end > i,\n )\n if (textNodeIdx !== -1) {\n const node = nodes[textNodeIdx]\n const spliced: TapperNode[] = []\n if (node.start < i) {\n const raw = text.slice(node.start, i)\n spliced.push({\n id: nextNodeId++,\n type: 'text',\n raw,\n value: raw,\n start: node.start,\n end: i,\n })\n }\n const triggerRaw = text.slice(i, cursor)\n spliced.push({\n id: nextNodeId++,\n type: 'trigger',\n facetType,\n raw: triggerRaw,\n value: text.slice(i + ch.length, cursor),\n start: i,\n end: cursor,\n })\n if (cursor < node.end) {\n const raw = text.slice(cursor, node.end)\n spliced.push({\n id: nextNodeId++,\n type: 'text',\n raw,\n value: raw,\n start: cursor,\n end: node.end,\n })\n }\n nodes.splice(textNodeIdx, 1, ...spliced)\n }\n break\n }\n }\n }\n\n // Transfer committed flags and stable IDs from previous nodes\n if (prevNodes) {\n // Facet nodes: match by facetType + occurrence index\n const counts = new Map<string, number>()\n const prevFacetsByTypeIndex = new Map<string, TapperNode>()\n\n for (const node of prevNodes) {\n if (node.type !== 'facet') continue\n const idx = counts.get(node.facetType!) ?? 0\n counts.set(node.facetType!, idx + 1)\n prevFacetsByTypeIndex.set(`${node.facetType}:${idx}`, node)\n }\n\n counts.clear()\n for (const node of nodes) {\n if (node.type !== 'facet') continue\n const idx = counts.get(node.facetType!) ?? 0\n counts.set(node.facetType!, idx + 1)\n const prev = prevFacetsByTypeIndex.get(`${node.facetType}:${idx}`)\n if (prev) {\n node.id = prev.id\n if (prev.committed) node.committed = true\n }\n }\n\n // Text nodes: match by start position\n const prevTextByStart = new Map<number, TapperNode>()\n for (const node of prevNodes) {\n if (node.type === 'text') prevTextByStart.set(node.start, node)\n }\n for (const node of nodes) {\n if (node.type === 'text') {\n const prev = prevTextByStart.get(node.start)\n if (prev) node.id = prev.id\n }\n }\n }\n\n return nodes\n}\n\nexport function deriveTriggers(config: TapperFacetConfig): Map<string, string> {\n const triggers = new Map<string, string>()\n for (const [name, re] of Object.entries(config)) {\n // Skip the boundary prefix (if present) before extracting the trigger char.\n const src = re.source.startsWith(BOUNDARY_PREFIX)\n ? re.source.slice(BOUNDARY_PREFIX.length)\n : re.source\n const m = src.match(/^[^\\\\([\\]{}.*+?^$|]+/)\n if (m) triggers.set(m[0], name)\n }\n return triggers\n}\n\nexport function nodeToFacet(node: TapperNode): TapperFacet {\n return {\n type: node.facetType!,\n raw: node.raw,\n value: node.value,\n range: {start: node.start, end: node.end},\n }\n}\n\nexport function detectActiveFacet(\n nodes: TapperNode[],\n text: string,\n cursor: number,\n triggers: Map<string, string>,\n): TapperFacet | null {\n for (const node of nodes) {\n if (node.type === 'trigger' && node.start < cursor && cursor <= node.end) {\n return {\n type: node.facetType,\n raw: node.raw,\n value: node.value,\n range: {start: node.start, end: node.end},\n }\n }\n if (\n node.type === 'facet' &&\n !node.committed &&\n node.start < cursor &&\n cursor <= node.end\n ) {\n return {\n type: node.facetType,\n raw: node.raw,\n value: node.value,\n range: {start: node.start, end: node.end},\n }\n }\n }\n\n // Scan backward from cursor for a trigger char (partial facet not yet matched by regex).\n // Skip if the cursor is inside or at the end of a committed facet.\n const inCommitted = nodes.some(\n n =>\n n.type === 'facet' && n.committed && n.start < cursor && cursor <= n.end,\n )\n if (!inCommitted) {\n for (let i = cursor - 1; i >= 0; i--) {\n const ch = text[i]\n // Stop at whitespace — triggers don't span across words\n if (WHITESPACE.test(ch)) break\n const type = triggers.get(ch)\n if (type && isBoundaryBefore(text, i)) {\n const raw = text.slice(i, cursor)\n return {\n type,\n raw,\n value: text.slice(i + 1, cursor),\n range: {start: i, end: cursor},\n }\n }\n }\n }\n\n return null\n}\n"]}
|
package/eslint.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsky.app/tapper",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "A minimal rich text editor for React Native and web.",
|
|
6
6
|
"repository": "https://github.com/bluesky-social/toolbox",
|
|
@@ -28,9 +28,10 @@
|
|
|
28
28
|
"react-native": "*"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
|
-
"build": "expo-module clean && expo-module build",
|
|
31
|
+
"build": "expo-module clean && EXPO_NONINTERACTIVE=1 expo-module build",
|
|
32
32
|
"clean": "expo-module clean",
|
|
33
33
|
"lint": "expo-module lint",
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
34
35
|
"test": "vitest run",
|
|
35
36
|
"expo-module": "expo-module",
|
|
36
37
|
"open:ios": "xed example/ios",
|
package/src/facets.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// Each regex begins with a `(^|\s|\()` capture group: a backwards-compatible
|
|
2
|
+
// alternative to lookbehind (Safari < 16.4 throws on lookbehind at parse time).
|
|
3
|
+
// The boundary char is captured into m[1]; util.ts strips it so positions and
|
|
4
|
+
// `raw` reflect the facet itself.
|
|
5
|
+
export const mention = /(^|\s|\()@([a-zA-Z0-9.-]+)\b/g
|
|
6
|
+
export const emoji = /(^|\s|\():([a-zA-Z0-9_]+):/g
|
|
3
7
|
export const tag =
|
|
4
|
-
/[##]((?!\ufe0f)[^\s\u00AD\u2060\u200A\u200B\u200C\u200D\u20e2]*[^\d\s\p{P}\u00AD\u2060\u200A\u200B\u200C\u200D\u20e2]+[^\s\u00AD\u2060\u200A\u200B\u200C\u200D\u20e2\p{P}]*)?/gu
|
|
8
|
+
/(^|\s|\()[##]((?!\ufe0f)[^\s\u00AD\u2060\u200A\u200B\u200C\u200D\u20e2]*[^\d\s\p{P}\u00AD\u2060\u200A\u200B\u200C\u200D\u20e2]+[^\s\u00AD\u2060\u200A\u200B\u200C\u200D\u20e2\p{P}]*)?/gu
|
|
5
9
|
export const url =
|
|
6
|
-
/((https?:\/\/[\S]+)|((?<domain>[a-z][a-z0-9]*(\.[a-z0-9]+)+)[\S]*))/gim
|
|
10
|
+
/(^|\s|\()((https?:\/\/[\S]+)|((?<domain>[a-z][a-z0-9]*(\.[a-z0-9]+)+)[\S]*))/gim
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {useCallback, useRef, useState, useSyncExternalStore} from 'react'
|
|
2
2
|
import {Platform, TextInput} from 'react-native'
|
|
3
3
|
|
|
4
|
+
import * as defaultFacets from './facets'
|
|
4
5
|
import {
|
|
5
6
|
TapperConfig,
|
|
6
7
|
TapperEvents,
|
|
@@ -17,7 +18,6 @@ import {
|
|
|
17
18
|
compileFacetRegexes,
|
|
18
19
|
type CompiledFacetRegexes,
|
|
19
20
|
} from './util'
|
|
20
|
-
import * as defaultFacets from './facets'
|
|
21
21
|
|
|
22
22
|
export * from './types'
|
|
23
23
|
export * as facets from './facets'
|
|
@@ -29,7 +29,7 @@ export class Tapper {
|
|
|
29
29
|
private triggers: Map<string, string>
|
|
30
30
|
|
|
31
31
|
// Event emitters
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
private listeners = new Map<keyof TapperEvents, Set<(data: any) => void>>()
|
|
34
34
|
|
|
35
35
|
// Public state
|
|
@@ -194,12 +194,14 @@ export class Tapper {
|
|
|
194
194
|
const diff = newText.length - this.text.length
|
|
195
195
|
let newEnd = Math.max(this.selection.end + diff, 0)
|
|
196
196
|
|
|
197
|
-
// Atomic deletion: backspace into a facet from outside
|
|
197
|
+
// Atomic deletion: backspace into a facet from outside.
|
|
198
|
+
// URLs are excluded — users typically want to edit them character by character.
|
|
198
199
|
let didAtomicDelete = false
|
|
199
200
|
if (diff === -1 && newEnd < this.selection.end) {
|
|
200
201
|
for (const node of this.nodes) {
|
|
201
202
|
if (
|
|
202
203
|
node.type === 'facet' &&
|
|
204
|
+
node.facetType !== 'url' &&
|
|
203
205
|
node.committed &&
|
|
204
206
|
this.selection.end === node.end
|
|
205
207
|
) {
|
package/src/util.ts
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import {TapperFacetConfig, TapperNode, TapperFacet} from './types'
|
|
2
2
|
|
|
3
3
|
const WHITESPACE = /\s/
|
|
4
|
+
// Regexes whose source starts with this prefix use a leading capture group
|
|
5
|
+
// to gate matches on a boundary (start-of-string, whitespace, or `(`) without
|
|
6
|
+
// lookbehind. The captured boundary char is stripped from the match so
|
|
7
|
+
// positions and `raw` reflect the facet itself.
|
|
8
|
+
const BOUNDARY_PREFIX = '(^|\\s|\\()'
|
|
9
|
+
|
|
10
|
+
// Mirror the regex's `(^|\s|\()` gate so trigger detection (for chars typed
|
|
11
|
+
// before any regex match exists) doesn't fire mid-word — e.g. the `@` inside
|
|
12
|
+
// `eric@blueskyweb.xyz` should not synthesize a mention trigger.
|
|
13
|
+
function isBoundaryBefore(text: string, i: number) {
|
|
14
|
+
if (i === 0) return true
|
|
15
|
+
const prev = text[i - 1]
|
|
16
|
+
return prev === '(' || WHITESPACE.test(prev)
|
|
17
|
+
}
|
|
4
18
|
let nextNodeId = 0
|
|
5
19
|
|
|
6
20
|
export type CompiledFacetRegexes = Map<string, RegExp>
|
|
@@ -39,12 +53,17 @@ export function parseNodesFromText(
|
|
|
39
53
|
// Reset lastIndex so stateful (global) regexes don't carry over
|
|
40
54
|
// match positions from the previous parse call.
|
|
41
55
|
re.lastIndex = 0
|
|
56
|
+
// Boundary-gated regexes shift the effective start past the captured
|
|
57
|
+
// boundary char (m[1]) and bump the value capture index by one.
|
|
58
|
+
const hasBoundary = re.source.startsWith(BOUNDARY_PREFIX)
|
|
42
59
|
for (const m of text.matchAll(re)) {
|
|
60
|
+
const boundaryLen = hasBoundary ? (m[1]?.length ?? 0) : 0
|
|
61
|
+
const fullMatch = m[0].slice(boundaryLen)
|
|
43
62
|
allMatches.push({
|
|
44
63
|
facetName: name,
|
|
45
|
-
fullMatch
|
|
46
|
-
capture: m[
|
|
47
|
-
index: m.index,
|
|
64
|
+
fullMatch,
|
|
65
|
+
capture: (hasBoundary ? m[2] : m[1]) ?? fullMatch,
|
|
66
|
+
index: m.index + boundaryLen,
|
|
48
67
|
})
|
|
49
68
|
}
|
|
50
69
|
}
|
|
@@ -108,7 +127,7 @@ export function parseNodesFromText(
|
|
|
108
127
|
const ch = text[i]
|
|
109
128
|
if (WHITESPACE.test(ch)) break
|
|
110
129
|
const facetType = triggers.get(ch)
|
|
111
|
-
if (facetType) {
|
|
130
|
+
if (facetType && isBoundaryBefore(text, i)) {
|
|
112
131
|
// Only create a trigger node if the trigger is inside a text node
|
|
113
132
|
// (i.e. the regex didn't already match it as a facet)
|
|
114
133
|
const textNodeIdx = nodes.findIndex(
|
|
@@ -200,7 +219,11 @@ export function parseNodesFromText(
|
|
|
200
219
|
export function deriveTriggers(config: TapperFacetConfig): Map<string, string> {
|
|
201
220
|
const triggers = new Map<string, string>()
|
|
202
221
|
for (const [name, re] of Object.entries(config)) {
|
|
203
|
-
|
|
222
|
+
// Skip the boundary prefix (if present) before extracting the trigger char.
|
|
223
|
+
const src = re.source.startsWith(BOUNDARY_PREFIX)
|
|
224
|
+
? re.source.slice(BOUNDARY_PREFIX.length)
|
|
225
|
+
: re.source
|
|
226
|
+
const m = src.match(/^[^\\([\]{}.*+?^$|]+/)
|
|
204
227
|
if (m) triggers.set(m[0], name)
|
|
205
228
|
}
|
|
206
229
|
return triggers
|
|
@@ -257,7 +280,7 @@ export function detectActiveFacet(
|
|
|
257
280
|
// Stop at whitespace — triggers don't span across words
|
|
258
281
|
if (WHITESPACE.test(ch)) break
|
|
259
282
|
const type = triggers.get(ch)
|
|
260
|
-
if (type) {
|
|
283
|
+
if (type && isBoundaryBefore(text, i)) {
|
|
261
284
|
const raw = text.slice(i, cursor)
|
|
262
285
|
return {
|
|
263
286
|
type,
|
package/vitest.config.ts
CHANGED
|
@@ -3,5 +3,11 @@ import {defineConfig} from 'vitest/config'
|
|
|
3
3
|
export default defineConfig({
|
|
4
4
|
test: {
|
|
5
5
|
include: ['src/__tests__/**/*.test.ts'],
|
|
6
|
+
alias: {
|
|
7
|
+
'react-native': new URL(
|
|
8
|
+
'src/__tests__/__mocks__/react-native.ts',
|
|
9
|
+
import.meta.url,
|
|
10
|
+
).pathname,
|
|
11
|
+
},
|
|
6
12
|
},
|
|
7
13
|
})
|