{"version":3,"sources":["jsdelivr-header.js","/npm/@udecode/plate-comments@49.0.0/src/index.ts","/npm/@udecode/plate-comments@49.0.0/src/lib/BaseCommentPlugin.ts","/npm/@udecode/plate-comments@49.0.0/src/lib/utils/getDraftCommentKey.ts","/npm/@udecode/plate-comments@49.0.0/src/lib/utils/isCommentKey.ts","/npm/@udecode/plate-comments@49.0.0/src/lib/utils/getCommentCount.ts","/npm/@udecode/plate-comments@49.0.0/src/lib/utils/getCommentKey.ts","/npm/@udecode/plate-comments@49.0.0/src/lib/utils/getCommentKeyId.ts","/npm/@udecode/plate-comments@49.0.0/src/lib/utils/getCommentKeys.ts","/npm/@udecode/plate-comments@49.0.0/src/lib/utils/isCommentNodeById.ts","/npm/@udecode/plate-comments@49.0.0/src/lib/utils/isCommentText.ts","/npm/@udecode/plate-comments@49.0.0/src/lib/withComments.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,8iBCNA,cAAA,GAAA,SAAA,cAAA,CAAA,kBAAA,IAAA,kBAAA,gBAAA,IAAA,gBAAA,cAAA,IAAA,cAAA,gBAAA,IAAA,gBAAA,eAAA,IAAA,eAAA,mBAAA,IAAA,mBAAA,aAAA,IAAA,aAAA,kBAAA,IAAA,kBAAA,cAAA,IAAA,cAAA,YAAA,IAAA,cAAA,OAAA,QAAA,aAAA,eCAA,IAAA,cASO,QAAA,kBCTP,aAAqB,QAAA,kBAER,mBAAqB,IAAM,GAAG,aAAA,KAAK,gBCFhD,cAAqB,QAAA,kBAER,aAAgB,GAAgB,EAAI,WAAW,GAAG,cAAA,KAAK,YCGvD,gBAAmB,IAC9B,IAAI,EAAe,EAKnB,OAJA,OAAO,KAAK,GAAM,SAAS,IACrB,aAAa,IAAQ,IAAQ,sBAAsB,GAAA,IAGlD,CAAA,ECXT,cAAqB,QAAA,kBAER,cAAiB,GAAe,GAAG,cAAA,KAAK,WAAW,ICFhE,cAAqB,QAAA,kBAER,gBAAmB,GAC9B,EAAI,QAAQ,GAA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jB,MAAM,GAAE,EAAA,QAAI,KAAY,GAAS,EAEjC,MAAO,IACF,EAAO,IAAI,MAAoB,IAC7B,EACH,MAAQ,GACF,EAAgB,EAAE,IAAS,EAAE,sBAC1B,EAAK,kBAAkB,EAAG,GAAM,EAAE,KAG/C,MAGH,kBACC,EAAG,MAAK,SAAQ,KAAI,WAAK,CACvB,WAAY,KACV,MAAM,EAAY,EAAI,QAAQ,OAE9B,IAAK,EAAW,OAEhB,MAAM,EAAO,eAAe,EAAU,IAEtC,EAAO,GAAG,oBAAmB,KAC3B,EAAK,SAAS,IACZ,EAAO,GAAG,WAAW,EAAG,IAG1B,EAAO,GAAG,WAAW,cAAA,KAAK,QAAO,GAClC,EAEH,SAAU,CAAC,EAAU,CAAC,KACpB,EAAG,SACD,CACE,CAAC,uBAAuB,EACxB,CAAC,IAAO,GAEV,CAAE,MAAO,cAAA,QAAQ,OAAQ,OAAO,KAAS,GAC3C,EAEF,UAAY,IACV,MAAM,GAAE,GAAO,EAET,EAAQ,EAAI,QAAQ,MAAM,CAAE,KAAI,GAAI,KAErC,GAEL,EAAM,SAAQ,EAAE,MAGd,IAAI,EAAsB,GAGxB,EALoB,gBAAgB,GAAQ,EAKhC,CAAC,qBAAsB,cAAc,IAErC,CAAC,cAAA,KAAK,QAAS,qBAAsB,cAAc,IAGjE,EAAO,GAAG,WAAyB,EAAW,CAC5C,GAAI,GACJ,MAAQ,GAAM,IAAM,GACrB,GACF","file":"/npm/@udecode/plate-comments@49.0.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@udecode/plate-comments@49.0.0/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from './lib/index';\n","import {\n  type EditorNodesOptions,\n  type NodeEntry,\n  type PluginConfig,\n  type SetNodesOptions,\n  type TCommentText,\n  createTSlatePlugin,\n  KEYS,\n  TextApi,\n} from '@udecode/plate';\n\nimport {\n  getCommentCount,\n  getCommentKey,\n  getCommentKeyId,\n  getCommentKeys,\n  getDraftCommentKey,\n  isCommentKey,\n  isCommentNodeById,\n} from './utils';\nimport { withComment } from './withComments';\n\nexport type BaseCommentConfig = PluginConfig<\n  'comment',\n  {},\n  {\n    comment: {\n      has: (options: { id: string }) => boolean;\n      node: (\n        options?: EditorNodesOptions & { id?: string; isDraft?: boolean }\n      ) => NodeEntry<TCommentText> | undefined;\n      nodeId: (leaf: TCommentText) => string | undefined;\n      nodes: (\n        options?: EditorNodesOptions & { id?: string; isDraft?: boolean }\n      ) => NodeEntry<TCommentText>[];\n    };\n  },\n  {\n    comment: {\n      removeMark: () => void;\n      setDraft: (options?: SetNodesOptions) => void;\n      unsetMark: (options: { id: string }) => void;\n    };\n  }\n>;\n\nexport const BaseCommentPlugin = createTSlatePlugin<BaseCommentConfig>({\n  key: KEYS.comment,\n  node: {\n    isLeaf: true,\n  },\n  rules: { selection: { affinity: 'outward' } },\n})\n  .overrideEditor(withComment)\n  .extendApi<BaseCommentConfig['api']['comment']>(({ editor, type }) => ({\n    has: (options: { id: string }): boolean => {\n      const { id } = options;\n\n      const regex = new RegExp(`\"${getCommentKey(id)}\":true`);\n\n      // TODO perf\n      return regex.test(JSON.stringify(editor.children));\n    },\n    node: (options = {}) => {\n      const { id, isDraft, ...rest } = options;\n\n      return editor.api.node<TCommentText>({\n        ...rest,\n        match: (n) => {\n          if (isDraft) return n[type] && n[getDraftCommentKey()];\n\n          return id ? isCommentNodeById(n, id) : n[type];\n        },\n      });\n    },\n    nodeId: (leaf) => {\n      const ids: string[] = [];\n      const keys = Object.keys(leaf);\n\n      if (keys.includes(getDraftCommentKey())) return;\n\n      keys.forEach((key) => {\n        if (!isCommentKey(key) || key === getDraftCommentKey()) return;\n\n        // block the resolved id\n\n        const id = getCommentKeyId(key);\n        ids.push(id);\n      });\n\n      return ids.at(-1);\n    },\n    nodes: (options = {}) => {\n      const { id, isDraft, ...rest } = options;\n\n      return [\n        ...editor.api.nodes<TCommentText>({\n          ...rest,\n          match: (n) => {\n            if (isDraft) return n[type] && n[getDraftCommentKey()];\n            return id ? isCommentNodeById(n, id) : n[type];\n          },\n        }),\n      ];\n    },\n  }))\n  .extendTransforms<BaseCommentConfig['transforms']['comment']>(\n    ({ api, editor, tf, type }) => ({\n      removeMark: () => {\n        const nodeEntry = api.comment.node();\n\n        if (!nodeEntry) return;\n\n        const keys = getCommentKeys(nodeEntry[0]);\n\n        editor.tf.withoutNormalizing(() => {\n          keys.forEach((key) => {\n            editor.tf.removeMark(key);\n          });\n\n          editor.tf.removeMark(KEYS.comment);\n        });\n      },\n      setDraft: (options = {}) => {\n        tf.setNodes(\n          {\n            [getDraftCommentKey()]: true,\n            [type]: true,\n          },\n          { match: TextApi.isText, split: true, ...options }\n        );\n      },\n      unsetMark: (options) => {\n        const { id } = options;\n\n        const nodes = api.comment.nodes({ id, at: [] });\n\n        if (!nodes) return;\n\n        nodes.forEach(([node]) => {\n          const isOverlapping = getCommentCount(node) > 1;\n\n          let unsetKeys: string[] = [];\n\n          if (isOverlapping) {\n            unsetKeys = [getDraftCommentKey(), getCommentKey(id)];\n          } else {\n            unsetKeys = [KEYS.comment, getDraftCommentKey(), getCommentKey(id)];\n          }\n\n          editor.tf.unsetNodes<TCommentText>(unsetKeys, {\n            at: [],\n            match: (n) => n === node,\n          });\n        });\n      },\n    })\n  );\n","import { KEYS } from '@udecode/plate';\n\nexport const getDraftCommentKey = () => `${KEYS.comment}_draft`;\n","import { KEYS } from '@udecode/plate';\n\nexport const isCommentKey = (key: string) => key.startsWith(`${KEYS.comment}_`);\n","import type { TCommentText } from '@udecode/plate';\n\nimport { getDraftCommentKey } from './getDraftCommentKey';\nimport { isCommentKey } from './isCommentKey';\n\nexport const getCommentCount = (node: TCommentText) => {\n  let commentCount = 0;\n  Object.keys(node).forEach((key) => {\n    if (isCommentKey(key) && key !== getDraftCommentKey()) commentCount++;\n  });\n\n  return commentCount;\n};\n","import { KEYS } from '@udecode/plate';\n\nexport const getCommentKey = (id: string) => `${KEYS.comment}_${id}`;\n","import { KEYS } from '@udecode/plate';\n\nexport const getCommentKeyId = (key: string) =>\n  key.replace(`${KEYS.comment}_`, '');\n","import type { TCommentText } from '@udecode/plate';\n\nimport { isCommentKey } from './isCommentKey';\n\nexport const getCommentKeys = (node: TCommentText) => {\n  const keys: string[] = [];\n\n  Object.keys(node).forEach((key) => {\n    if (isCommentKey(key)) keys.push(key);\n  });\n\n  return keys;\n};\n","import type { TNode } from '@udecode/plate';\n\nimport { getCommentKey } from './getCommentKey';\n\n/** Whether the node has a comment id. */\nexport const isCommentNodeById = (node: TNode, id: string) =>\n  !!node[getCommentKey(id)];\n","import type { TCommentText, TNode } from '@udecode/plate';\n\nimport { KEYS } from '@udecode/plate';\n\nexport const isCommentText = (node: TNode): node is TCommentText => {\n  return !!node[KEYS.comment];\n};\n","import type { OverrideEditor, TCommentText } from '@udecode/plate';\n\nimport { KEYS } from '@udecode/plate';\n\nimport type { BaseCommentConfig } from './BaseCommentPlugin';\n\nimport { getCommentCount, getDraftCommentKey } from './utils';\n\nexport const withComment: OverrideEditor<BaseCommentConfig> = ({\n  editor,\n  tf: { normalizeNode },\n}) => ({\n  transforms: {\n    normalizeNode(entry) {\n      const [node, path] = entry;\n\n      if (\n        node[KEYS.comment] &&\n        !node[getDraftCommentKey()] &&\n        getCommentCount(node as TCommentText) < 1\n      ) {\n        editor.tf.unsetNodes(KEYS.comment, { at: path });\n\n        return;\n      }\n\n      return normalizeNode(entry);\n    },\n  },\n});\n"]}