@portabletext/plugin-character-pair-decorator 8.0.43 → 8.0.45

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.d.ts CHANGED
@@ -1,24 +1,19 @@
1
- import type {EditorContext} from '@portabletext/editor'
2
- import {JSX} from 'react'
3
-
1
+ import { EditorContext } from "@portabletext/editor";
4
2
  /**
5
3
  * @public
6
4
  */
7
- export declare function CharacterPairDecoratorPlugin(props: {
8
- decorator: ({
9
- context,
10
- schema,
11
- }: {
12
- context: Pick<EditorContext, 'schema'>
5
+ declare function CharacterPairDecoratorPlugin(props: {
6
+ decorator: ({ context, schema }: {
7
+ context: Pick<EditorContext, 'schema'>;
13
8
  /**
14
9
  * @deprecated Use `context.schema` instead
15
10
  */
16
- schema: EditorContext['schema']
17
- }) => string | undefined
11
+ schema: EditorContext['schema'];
12
+ }) => string | undefined;
18
13
  pair: {
19
- char: string
20
- amount: number
21
- }
22
- }): JSX.Element
23
-
24
- export {}
14
+ char: string;
15
+ amount: number;
16
+ };
17
+ }): import("react").JSX.Element;
18
+ export { CharacterPairDecoratorPlugin };
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/plugin.character-pair-decorator.tsx"],"mappings":";;;;iBAQgB,6BAA6B;EAC3C,cACE,SACA;IAEA,SAAS,KAAK;;;;IAId,QAAQ;;EAEV;IAAO;IAAc;;oBACtB,IAAA"}
package/dist/index.js CHANGED
@@ -1,109 +1,88 @@
1
- import { jsx } from "react/jsx-runtime";
2
1
  import { c } from "react/compiler-runtime";
3
- import { defineInputRule, InputRulePlugin } from "@portabletext/plugin-input-rule";
2
+ import { InputRulePlugin, defineInputRule } from "@portabletext/plugin-input-rule";
4
3
  import "react";
5
4
  import { raise } from "@portabletext/editor/behaviors";
6
5
  import { getPathSubSchema } from "@portabletext/editor/traversal";
6
+ import { jsx } from "react/jsx-runtime";
7
7
  function createCharacterPairRegex(char, amount) {
8
- const prePrefix = `(?<!\\${char})`, prefix = `\\${char}`.repeat(Math.max(amount, 1)), postPrefix = "(?!\\s)", content = `(?<content>[^${char}\\n]+?)`, preSuffix = "(?<!\\s)", suffix = `\\${char}`.repeat(Math.max(amount, 1)), postSuffix = `(?!\\${char})`;
9
- return `${prePrefix}${prefix}${postPrefix}${content}${preSuffix}${suffix}${postSuffix}`;
8
+ return `${`(?<!\\${char})`}${`\\${char}`.repeat(Math.max(amount, 1))}(?!\\s)${`(?<content>[^${char}\\n]+?)`}(?<!\\s)${`\\${char}`.repeat(Math.max(amount, 1))}${`(?!\\${char})`}`;
10
9
  }
10
+ /**
11
+ * A character pair is an input rule: typing the closing half of a pair
12
+ * (`**bold**`, `_em_`) decorates the content between the markers and deletes
13
+ * the markers. `defineInputRule` supplies the match locations; the
14
+ * `InputRulePlugin` machinery supplies smart-undo on Backspace and the
15
+ * caret-departure tracking the plugin previously hand-rolled.
16
+ */
11
17
  function createCharacterPairRule(config) {
12
- config.pair.amount < 1 && console.warn("The amount of characters in the pair should be greater than 0");
13
- const pairRegex = createCharacterPairRegex(config.pair.char, config.pair.amount);
14
- return defineInputRule({
15
- // `$`-anchored: the pair must close at the insertion point, so at most
16
- // one match fires per insert.
17
- on: new RegExp(`${pairRegex}$`),
18
- // A pair only deletes its markers, so a match whose CONTENT spans an
19
- // inline object is harmless and must decorate (`**bo`, insert an
20
- // object, `ld**`). An inline object anywhere else in the match, between
21
- // the marker characters, means this is not a pair, and the machinery
22
- // drops the match.
23
- inlineObjects: {
24
- allow: ["content"]
25
- },
26
- guard: ({
27
- snapshot,
28
- event
29
- }) => {
30
- if (config.pair.amount < 1)
31
- return !1;
32
- const subSchema = getPathSubSchema(snapshot, event.focusBlock.path), decorator = config.decorator({
33
- context: {
34
- schema: subSchema
35
- },
36
- schema: subSchema
37
- });
38
- if (decorator === void 0)
39
- return !1;
40
- const match = event.matches.at(0);
41
- if (!match)
42
- return !1;
43
- const content = match.groups.content;
44
- if (!content)
45
- return !1;
46
- const prefixOffsets = {
47
- anchor: match.targetOffsets.anchor,
48
- focus: content.targetOffsets.anchor
49
- }, suffixOffsets = {
50
- anchor: content.targetOffsets.focus,
51
- focus: match.targetOffsets.focus
52
- };
53
- return {
54
- decorator,
55
- contentOffsets: {
56
- anchor: content.targetOffsets.anchor,
57
- focus: content.targetOffsets.focus
58
- },
59
- prefixOffsets,
60
- suffixOffsets
61
- };
62
- },
63
- actions: [(_, {
64
- decorator,
65
- contentOffsets,
66
- prefixOffsets,
67
- suffixOffsets
68
- }) => [
69
- // Decorate the text between the prefix and suffix
70
- raise({
71
- type: "decorator.add",
72
- decorator,
73
- at: contentOffsets
74
- }),
75
- // Delete the suffix, then the prefix (suffix first so the prefix
76
- // offsets stay valid)
77
- raise({
78
- type: "delete.text",
79
- at: suffixOffsets
80
- }),
81
- raise({
82
- type: "delete.text",
83
- at: prefixOffsets
84
- }),
85
- // Toggle the decorator off so the next inserted text isn't decorated
86
- raise({
87
- type: "decorator.remove",
88
- decorator
89
- })
90
- ]]
91
- });
18
+ config.pair.amount < 1 && console.warn("The amount of characters in the pair should be greater than 0");
19
+ let pairRegex = createCharacterPairRegex(config.pair.char, config.pair.amount);
20
+ return defineInputRule({
21
+ on: RegExp(`${pairRegex}$`),
22
+ inlineObjects: { allow: ["content"] },
23
+ guard: ({ snapshot, event }) => {
24
+ if (config.pair.amount < 1) return !1;
25
+ let subSchema = getPathSubSchema(snapshot, event.focusBlock.path), decorator = config.decorator({
26
+ context: { schema: subSchema },
27
+ schema: subSchema
28
+ });
29
+ if (decorator === void 0) return !1;
30
+ let match = event.matches.at(0);
31
+ if (!match) return !1;
32
+ let content = match.groups.content;
33
+ if (!content) return !1;
34
+ let prefixOffsets = {
35
+ anchor: match.targetOffsets.anchor,
36
+ focus: content.targetOffsets.anchor
37
+ }, suffixOffsets = {
38
+ anchor: content.targetOffsets.focus,
39
+ focus: match.targetOffsets.focus
40
+ };
41
+ return {
42
+ decorator,
43
+ contentOffsets: {
44
+ anchor: content.targetOffsets.anchor,
45
+ focus: content.targetOffsets.focus
46
+ },
47
+ prefixOffsets,
48
+ suffixOffsets
49
+ };
50
+ },
51
+ actions: [(_, { decorator, contentOffsets, prefixOffsets, suffixOffsets }) => [
52
+ raise({
53
+ type: "decorator.add",
54
+ decorator,
55
+ at: contentOffsets
56
+ }),
57
+ raise({
58
+ type: "delete.text",
59
+ at: suffixOffsets
60
+ }),
61
+ raise({
62
+ type: "delete.text",
63
+ at: prefixOffsets
64
+ }),
65
+ raise({
66
+ type: "decorator.remove",
67
+ decorator
68
+ })
69
+ ]]
70
+ });
92
71
  }
72
+ /**
73
+ * @public
74
+ */
93
75
  function CharacterPairDecoratorPlugin(props) {
94
- const $ = c(7);
95
- let t0;
96
- $[0] !== props.decorator || $[1] !== props.pair ? (t0 = createCharacterPairRule({
97
- decorator: props.decorator,
98
- pair: props.pair
99
- }), $[0] = props.decorator, $[1] = props.pair, $[2] = t0) : t0 = $[2];
100
- let t1;
101
- $[3] !== t0 ? (t1 = [t0], $[3] = t0, $[4] = t1) : t1 = $[4];
102
- const rules = t1;
103
- let t2;
104
- return $[5] !== rules ? (t2 = /* @__PURE__ */ jsx(InputRulePlugin, { rules }), $[5] = rules, $[6] = t2) : t2 = $[6], t2;
76
+ let $ = c(7), t0;
77
+ $[0] !== props.decorator || $[1] !== props.pair ? (t0 = createCharacterPairRule({
78
+ decorator: props.decorator,
79
+ pair: props.pair
80
+ }), $[0] = props.decorator, $[1] = props.pair, $[2] = t0) : t0 = $[2];
81
+ let t1;
82
+ $[3] === t0 ? t1 = $[4] : (t1 = [t0], $[3] = t0, $[4] = t1);
83
+ let rules = t1, t2;
84
+ return $[5] === rules ? t2 = $[6] : (t2 = /* @__PURE__ */ jsx(InputRulePlugin, { rules }), $[5] = rules, $[6] = t2), t2;
105
85
  }
106
- export {
107
- CharacterPairDecoratorPlugin
108
- };
109
- //# sourceMappingURL=index.js.map
86
+ export { CharacterPairDecoratorPlugin };
87
+
88
+ //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","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"],"names":["createCharacterPairRegex","char","amount","prePrefix","prefix","repeat","Math","max","postPrefix","content","preSuffix","suffix","postSuffix","createCharacterPairRule","config","pair","console","warn","pairRegex","defineInputRule","on","RegExp","inlineObjects","allow","guard","snapshot","event","subSchema","getPathSubSchema","focusBlock","path","decorator","context","schema","undefined","match","matches","at","groups","prefixOffsets","anchor","targetOffsets","focus","suffixOffsets","contentOffsets","actions","_","raise","type","CharacterPairDecoratorPlugin","props","$","_c","t0","t1","rules","t2"],"mappings":";;;;;;AAAO,SAASA,yBAAyBC,MAAcC,QAAgB;AAErE,QAAMC,YAAY,SAASF,IAAI,KAGzBG,SAAS,KAAKH,IAAI,GAAGI,OAAOC,KAAKC,IAAIL,QAAQ,CAAC,CAAC,GAG/CM,aAAa,WAGbC,UAAU,gBAAgBR,IAAI,WAG9BS,YAAY,YAGZC,SAAS,KAAKV,IAAI,GAAGI,OAAOC,KAAKC,IAAIL,QAAQ,CAAC,CAAC,GAG/CU,aAAa,QAAQX,IAAI;AAE/B,SAAO,GAAGE,SAAS,GAAGC,MAAM,GAAGI,UAAU,GAAGC,OAAO,GAAGC,SAAS,GAAGC,MAAM,GAAGC,UAAU;AACvF;ACVO,SAASC,wBAAwBC,QAYrC;AACGA,SAAOC,KAAKb,SAAS,KACvBc,QAAQC,KACN,+DACF;AAGF,QAAMC,YAAYlB,yBAChBc,OAAOC,KAAKd,MACZa,OAAOC,KAAKb,MACd;AAEA,SAAOiB,gBA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AAAA,QACAM,IAAIO;AAAAA,MAAAA,CACL;AAAA;AAAA;AAAA,MAGDG,MAAM;AAAA,QACJC,MAAM;AAAA,QACNX,IAAIM;AAAAA,MAAAA,CACL;AAAA,MACDI,MAAM;AAAA,QACJC,MAAM;AAAA,QACNX,IAAIE;AAAAA,MAAAA,CACL;AAAA;AAAA,MAEDQ,MAAM;AAAA,QACJC,MAAM;AAAA,QACNjB;AAAAA,MAAAA,CACD;AAAA,IAAA,CACF;AAAA,EAAA,CAEJ;AACH;AClHO,SAAAkB,6BAAAC,OAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA;AAAA,MAAAC;AAAAF,IAAA,CAAA,MAAAD,MAAAnB,aAAAoB,EAAA,CAAA,MAAAD,MAAAnC,QAeDsC,KAAAxC,wBAAwB;AAAA,IAAAkB,WACXmB,MAAKnB;AAAAA,IAAUhB,MACpBmC,MAAKnC;AAAAA,EAAAA,CACZ,GAACoC,EAAA,CAAA,IAAAD,MAAAnB,WAAAoB,EAAA,CAAA,IAAAD,MAAAnC,MAAAoC,OAAAE,MAAAA,KAAAF,EAAA,CAAA;AAAA,MAAAG;AAAAH,WAAAE,MAJEC,KAAA,CACJD,EAGE,GACHF,OAAAE,IAAAF,OAAAG,MAAAA,KAAAH,EAAA,CAAA;AANH,QAAAI,QACQD;AAOP,MAAAE;AAAA,SAAAL,SAAAI,SAEMC,yBAAC,iBAAA,EAAuBD,OAAK,GAAIJ,OAAAI,OAAAJ,OAAAK,MAAAA,KAAAL,EAAA,CAAA,GAAjCK;AAAiC;"}
1
+ {"version":3,"file":"index.js","names":["createCharacterPairRegex","char","amount","prePrefix","prefix","repeat","Math","max","postPrefix","content","preSuffix","suffix","postSuffix","EditorContext","raise","getPathSubSchema","defineInputRule","createCharacterPairRegex","createCharacterPairRule","config","decorator","context","schema","Pick","pair","char","amount","console","warn","pairRegex","on","RegExp","inlineObjects","allow","guard","snapshot","event","subSchema","focusBlock","path","undefined","match","matches","at","content","groups","prefixOffsets","anchor","targetOffsets","focus","suffixOffsets","contentOffsets","actions","_","type","EditorContext","InputRulePlugin","useMemo","createCharacterPairRule","CharacterPairDecoratorPlugin","props","$","_c","t0","decorator","pair","t1","rules","t2"],"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,SAAgBA,yBAAyBC,MAAcC,QAAgB;CAsBrE,OAAO,GAAGC,SApBiBF,KAAI,KAGhB,KAAKA,OAAOI,OAAOC,KAAKC,IAAIL,QAAQ,CAAC,CAiB9BE,EAAAA,SAAsBK,gBAXZR,KAAI,SAAA,UAMrB,KAAKA,OAAOI,OAAOC,KAAKC,IAAIL,QAAQ,CAAC,CAKcS,IAASC,QAFhDX,KAAI;AAGjC;;;;;;;;ACVA,SAAgBiB,wBAAwBC,QAYrC;CACD,AAAIA,OAAOK,KAAKE,SAAS,KACvBC,QAAQC,KACN,+DACF;CAGF,IAAMC,YAAYZ,yBAChBE,OAAOK,KAAKC,MACZN,OAAOK,KAAKE,MACd;CAEA,OAAOV,gBAAgB;EAGrBc,IAAQC,OAAO,GAAGF,UAAS,EAAG;EAM9BG,eAAe,EAACC,OAAO,CAAC,SAAS,EAAC;EAClCC,QAAQ,EAACC,UAAUC,YAAW;GAC5B,IAAIjB,OAAOK,KAAKE,SAAS,GACvB,OAAO;GAGT,IAAMW,YAAYtB,iBAAiBoB,UAAUC,MAAME,WAAWC,IAAI,GAC5DnB,YAAYD,OAAOC,UAAU;IACjCC,SAAS,EAACC,QAAQe,UAAS;IAC3Bf,QAAQe;GACV,CAAC;GAED,IAAIjB,cAAcoB,KAAAA,GAChB,OAAO;GAGT,IAAMC,QAAQL,MAAMM,QAAQC,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D,EAAwBD,MAAK,CAAA,GAAIN,EAAA,KAAAM,OAAAN,EAAA,KAAAO,KAAjCA;AAAiC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/plugin-character-pair-decorator",
3
- "version": "8.0.43",
3
+ "version": "8.0.45",
4
4
  "description": "Automatically match a pair of characters and decorate the text in between",
5
5
  "keywords": [
6
6
  "behaviors",
@@ -26,19 +26,21 @@
26
26
  "type": "module",
27
27
  "sideEffects": false,
28
28
  "main": "./dist/index.js",
29
+ "module": "./dist/index.js",
29
30
  "types": "./dist/index.d.ts",
30
31
  "exports": {
31
32
  ".": "./dist/index.js",
32
33
  "./package.json": "./package.json"
33
34
  },
34
35
  "dependencies": {
35
- "@portabletext/plugin-input-rule": "^6.0.12"
36
+ "@portabletext/plugin-input-rule": "^6.0.14"
36
37
  },
37
38
  "devDependencies": {
38
- "@sanity/pkg-utils": "^10.8.2",
39
+ "@rolldown/plugin-babel": "^0.2.3",
40
+ "@sanity/pkg-utils": "^12.1.0",
39
41
  "@sanity/tsconfig": "^2.1.0",
40
42
  "@types/react": "^19.2.17",
41
- "@vitejs/plugin-react": "^5.2.0",
43
+ "@vitejs/plugin-react": "^6.0.5",
42
44
  "@vitest/browser": "^4.1.10",
43
45
  "@vitest/browser-playwright": "^4.1.10",
44
46
  "babel-plugin-react-compiler": "^1.0.0",
@@ -47,22 +49,22 @@
47
49
  "react": "^19.2.7",
48
50
  "typescript": "6.0.3",
49
51
  "typescript-eslint": "^8.62.0",
50
- "vite": "^7.3.5",
52
+ "vite": "^8.2.0",
51
53
  "vitest": "^4.1.10",
52
- "@portabletext/editor": "^7.10.15",
53
- "@portabletext/schema": "2.2.3",
54
- "@portabletext/test": "1.0.4",
55
- "racejar": "2.0.10"
54
+ "@portabletext/editor": "^7.10.17",
55
+ "@portabletext/schema": "2.2.4",
56
+ "@portabletext/test": "1.0.5",
57
+ "racejar": "2.0.11"
56
58
  },
57
59
  "peerDependencies": {
58
60
  "react": "^19.2",
59
- "@portabletext/editor": "^7.10.15"
61
+ "@portabletext/editor": "^7.10.17"
60
62
  },
61
63
  "engines": {
62
64
  "node": ">=20.19 <22 || >=22.12"
63
65
  },
64
66
  "scripts": {
65
- "build": "pkg-utils build --strict --check --clean",
67
+ "build": "pkg-utils build --strict --check",
66
68
  "check:lint": "biome lint .",
67
69
  "check:react-compiler": "eslint .",
68
70
  "check:types": "tsc",