@portabletext/plugin-character-pair-decorator 8.0.51 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/package.json +12 -21
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { c } from "react/compiler-runtime";
|
|
2
2
|
import { InputRulePlugin, defineInputRule } from "@portabletext/plugin-input-rule";
|
|
3
|
-
import "react";
|
|
4
3
|
import { raise } from "@portabletext/editor/behaviors";
|
|
5
4
|
import { getPathSubSchema } from "@portabletext/editor/traversal";
|
|
6
5
|
import { jsx } from "react/jsx-runtime";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["createCharacterPairRule({\n decorator: props.decorator,\n pair: props.pair,\n })","decorator","pair","[\n createCharacterPairRule({\n decorator: props.decorator,\n pair: props.pair,\n }),\n ]","useMemo(\n () => [\n createCharacterPairRule({\n decorator: props.decorator,\n pair: props.pair,\n }),\n ],\n [props.decorator, props.pair],\n )","<InputRulePlugin rules={rules} />"],"sources":["../src/regex.character-pair.ts","../src/rule.character-pair.ts","../src/plugin.character-pair-decorator.tsx"],"sourcesContent":["export function createCharacterPairRegex(char: string, amount: number) {\n // Negative lookbehind: Ensures that the matched sequence is not preceded by the same character\n const prePrefix = `(?<!\\\\${char})`\n\n // Repeats the character `amount` times\n const prefix = `\\\\${char}`.repeat(Math.max(amount, 1))\n\n // Negative lookahead: Ensures that the opening pair (**, *, etc.) is not followed by a space\n const postPrefix = `(?!\\\\s)`\n\n // Captures the content inside the pair as the named group `content`\n const content = `(?<content>[^${char}\\\\n]+?)`\n\n // Negative lookbehind: Ensures that the content is not followed by a space\n const preSuffix = `(?<!\\\\s)`\n\n // Repeats the character `amount` times\n const suffix = `\\\\${char}`.repeat(Math.max(amount, 1))\n\n // Negative lookahead: Ensures that the matched sequence is not followed by the same character\n const postSuffix = `(?!\\\\${char})`\n\n return `${prePrefix}${prefix}${postPrefix}${content}${preSuffix}${suffix}${postSuffix}`\n}\n","import type {EditorContext} from '@portabletext/editor'\nimport {raise} from '@portabletext/editor/behaviors'\nimport {getPathSubSchema} from '@portabletext/editor/traversal'\nimport {defineInputRule} from '@portabletext/plugin-input-rule'\nimport {createCharacterPairRegex} from './regex.character-pair'\n\n/**\n * A character pair is an input rule: typing the closing half of a pair\n * (`**bold**`, `_em_`) decorates the content between the markers and deletes\n * the markers. `defineInputRule` supplies the match locations; the\n * `InputRulePlugin` machinery supplies smart-undo on Backspace and the\n * caret-departure tracking the plugin previously hand-rolled.\n */\nexport function createCharacterPairRule(config: {\n decorator: ({\n context,\n schema,\n }: {\n context: Pick<EditorContext, 'schema'>\n /**\n * @deprecated Use `context.schema` instead\n */\n schema: EditorContext['schema']\n }) => string | undefined\n pair: {char: string; amount: number}\n}) {\n if (config.pair.amount < 1) {\n console.warn(\n `The amount of characters in the pair should be greater than 0`,\n )\n }\n\n const pairRegex = createCharacterPairRegex(\n config.pair.char,\n config.pair.amount,\n )\n\n return defineInputRule({\n // `$`-anchored: the pair must close at the insertion point, so at most\n // one match fires per insert.\n on: new RegExp(`${pairRegex}$`),\n // A pair only deletes its markers, so a match whose CONTENT spans an\n // inline object is harmless and must decorate (`**bo`, insert an\n // object, `ld**`). An inline object anywhere else in the match, between\n // the marker characters, means this is not a pair, and the machinery\n // drops the match.\n inlineObjects: {allow: ['content']},\n guard: ({snapshot, event}) => {\n if (config.pair.amount < 1) {\n return false\n }\n\n const subSchema = getPathSubSchema(snapshot, event.focusBlock.path)\n const decorator = config.decorator({\n context: {schema: subSchema},\n schema: subSchema,\n })\n\n if (decorator === undefined) {\n return false\n }\n\n const match = event.matches.at(0)\n\n if (!match) {\n return false\n }\n\n // `createCharacterPairRegex` captures the content between the markers\n // as the named group `content`. Prefix and suffix offsets derive from\n // the whole match and the content group.\n const content = match.groups['content']\n\n if (!content) {\n return false\n }\n\n const prefixOffsets = {\n anchor: match.targetOffsets.anchor,\n focus: content.targetOffsets.anchor,\n }\n const suffixOffsets = {\n anchor: content.targetOffsets.focus,\n focus: match.targetOffsets.focus,\n }\n\n return {\n decorator,\n contentOffsets: {\n anchor: content.targetOffsets.anchor,\n focus: content.targetOffsets.focus,\n },\n prefixOffsets,\n suffixOffsets,\n }\n },\n actions: [\n (_, {decorator, contentOffsets, prefixOffsets, suffixOffsets}) => [\n // Decorate the text between the prefix and suffix\n raise({\n type: 'decorator.add',\n decorator,\n at: contentOffsets,\n }),\n // Delete the suffix, then the prefix (suffix first so the prefix\n // offsets stay valid)\n raise({\n type: 'delete.text',\n at: suffixOffsets,\n }),\n raise({\n type: 'delete.text',\n at: prefixOffsets,\n }),\n // Toggle the decorator off so the next inserted text isn't decorated\n raise({\n type: 'decorator.remove',\n decorator,\n }),\n ],\n ],\n })\n}\n","import type {EditorContext} from '@portabletext/editor'\nimport {InputRulePlugin} from '@portabletext/plugin-input-rule'\nimport {useMemo} from 'react'\nimport {createCharacterPairRule} from './rule.character-pair'\n\n/**\n * @public\n */\nexport function CharacterPairDecoratorPlugin(props: {\n decorator: ({\n context,\n schema,\n }: {\n context: Pick<EditorContext, 'schema'>\n /**\n * @deprecated Use `context.schema` instead\n */\n schema: EditorContext['schema']\n }) => string | undefined\n pair: {char: string; amount: number}\n}) {\n const rules = useMemo(\n () => [\n createCharacterPairRule({\n decorator: props.decorator,\n pair: props.pair,\n }),\n ],\n [props.decorator, props.pair],\n )\n\n return <InputRulePlugin rules={rules} />\n}\n"],"mappings":";;;;;AAAA,SAAgB,yBAAyB,MAAc,QAAgB;CAsBrE,OAAO,GAAG,SApBiB,KAAK,KAGjB,KAAK,OAAO,OAAO,KAAK,IAAI,QAAQ,CAAC,CAiB9B,EAAA,SAAsB,gBAXZ,KAAK,SAAA,UAMtB,KAAK,OAAO,OAAO,KAAK,IAAI,QAAQ,CAAC,CAKc,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EAAAA,OAAAA,MAAAA,aAAAA,EAAAA,OACLC,MAAAA,QAFd,KAAA,wBAAwB;EACtB,WAAW,MAAM;EACjB,MAAM,MAAM;CACd,CAAC,GAFkBD,EAAAA,KAAAA,MAAAA,WACLC,EAAAA,KAAAA,MAAAA;CAHVC,IAAAA;CACJH,AAAAA,EAAAA,OAAAA,kBADI,KAAA,CACJA,EAIF,GAJEA,EAAAA,KAAAA;CAFJ,IAAM,QAAQI,IAUPC;CAAP,OAA+B,EAAA,OAAA,qBAAxB,KAAA,oBAAC,iBAAD,EAAwB,MAAQ,CAAA,GAAR,EAAA,KAAA,mBAAxBA;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/plugin-character-pair-decorator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.1",
|
|
4
4
|
"description": "Automatically match a pair of characters and decorate the text in between",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"behaviors",
|
|
@@ -25,53 +25,44 @@
|
|
|
25
25
|
],
|
|
26
26
|
"type": "module",
|
|
27
27
|
"sideEffects": false,
|
|
28
|
-
"main": "./dist/index.js",
|
|
29
|
-
"module": "./dist/index.js",
|
|
30
28
|
"types": "./dist/index.d.ts",
|
|
31
29
|
"exports": {
|
|
32
30
|
".": "./dist/index.js",
|
|
33
31
|
"./package.json": "./package.json"
|
|
34
32
|
},
|
|
35
33
|
"dependencies": {
|
|
36
|
-
"@portabletext/plugin-input-rule": "^
|
|
34
|
+
"@portabletext/plugin-input-rule": "^7.0.1"
|
|
37
35
|
},
|
|
38
36
|
"devDependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"@sanity/pkg-utils": "^12.1.0",
|
|
37
|
+
"@sanity/pkg-utils": "^12.3.0",
|
|
41
38
|
"@sanity/tsconfig": "^2.1.0",
|
|
42
39
|
"@types/react": "^19.2.17",
|
|
43
|
-
"@vitejs/plugin-react": "^6.0
|
|
40
|
+
"@vitejs/plugin-react": "^6.1.0",
|
|
44
41
|
"@vitest/browser": "^4.1.10",
|
|
45
42
|
"@vitest/browser-playwright": "^4.1.10",
|
|
46
|
-
"
|
|
47
|
-
"eslint": "^9.39.4",
|
|
48
|
-
"eslint-plugin-react-hooks": "^7.1.1",
|
|
43
|
+
"oxc-transform-react": "^0.145.0",
|
|
49
44
|
"react": "^19.2.8",
|
|
50
|
-
"typescript": "
|
|
51
|
-
"typescript-eslint": "^8.62.0",
|
|
45
|
+
"typescript": "^7.0.2",
|
|
52
46
|
"vite": "^8.2.0",
|
|
53
47
|
"vitest": "^4.1.10",
|
|
54
|
-
"@portabletext/editor": "^
|
|
55
|
-
"@portabletext/schema": "
|
|
56
|
-
"@portabletext/test": "
|
|
57
|
-
"racejar": "
|
|
48
|
+
"@portabletext/editor": "^8.0.1",
|
|
49
|
+
"@portabletext/schema": "3.0.0",
|
|
50
|
+
"@portabletext/test": "2.0.0",
|
|
51
|
+
"racejar": "3.0.0"
|
|
58
52
|
},
|
|
59
53
|
"peerDependencies": {
|
|
60
54
|
"react": "^19.2",
|
|
61
|
-
"@portabletext/editor": "^
|
|
55
|
+
"@portabletext/editor": "^8.0.1"
|
|
62
56
|
},
|
|
63
57
|
"engines": {
|
|
64
|
-
"node": ">=
|
|
58
|
+
"node": ">=22.12"
|
|
65
59
|
},
|
|
66
60
|
"scripts": {
|
|
67
61
|
"build": "pkg-utils build --strict --check",
|
|
68
|
-
"check:lint": "biome lint .",
|
|
69
|
-
"check:react-compiler": "eslint .",
|
|
70
62
|
"check:types": "tsc",
|
|
71
63
|
"check:types:watch": "tsc --watch",
|
|
72
64
|
"clean": "del .turbo && del dist && del node_modules",
|
|
73
65
|
"dev": "pkg-utils watch",
|
|
74
|
-
"lint:fix": "biome lint --write .",
|
|
75
66
|
"test:browser:chromium": "vitest run --project \"browser (chromium)\"",
|
|
76
67
|
"test:browser:chromium:watch": "vitest watch --project \"browser (chromium)\"",
|
|
77
68
|
"test:browser:firefox": "vitest run --project \"browser (firefox)\"",
|