@kedataindo/docflow-core 0.0.86 → 0.0.87

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.cjs CHANGED
@@ -34,6 +34,7 @@ __export(index_exports, {
34
34
  CONTEXT_CHAR_CAP: () => CONTEXT_CHAR_CAP,
35
35
  DOCUMENT_MODES: () => DOCUMENT_MODES,
36
36
  EditorContextExtension: () => EditorContextExtension,
37
+ FontFamilyExtension: () => FontFamilyExtension,
37
38
  FontSizeExtension: () => FontSizeExtension,
38
39
  LOCAL_STORAGE_KEY: () => LOCAL_STORAGE_KEY,
39
40
  PAGE_SIZES: () => PAGE_SIZES,
@@ -2223,7 +2224,6 @@ var FontSizeExtension = import_core7.Extension.create({
2223
2224
  addCommands() {
2224
2225
  return {
2225
2226
  setFontSize: (fontSize) => ({ tr, state, dispatch }) => {
2226
- console.log("[FontSizeExt] setFontSize called, fontSize:", fontSize, "empty:", state.selection.empty);
2227
2227
  const textStyleType = state.schema.marks.textStyle;
2228
2228
  const { from, to, empty } = state.selection;
2229
2229
  if (empty) {
@@ -2299,6 +2299,111 @@ var FontSizeExtension = import_core7.Extension.create({
2299
2299
  }
2300
2300
  });
2301
2301
 
2302
+ // src/FontFamily.ts
2303
+ var import_core8 = require("@tiptap/core");
2304
+ function mergeFontFamily(textStyleType, existing, fontFamily) {
2305
+ if (fontFamily === null) {
2306
+ const { fontFamily: _removed, ...rest } = existing?.attrs ?? {};
2307
+ return textStyleType.create(rest);
2308
+ }
2309
+ return textStyleType.create({ ...existing?.attrs, fontFamily });
2310
+ }
2311
+ function hasAttrs2(mark) {
2312
+ return Object.values(mark.attrs).some((v) => v != null);
2313
+ }
2314
+ var FontFamilyExtension = import_core8.Extension.create({
2315
+ name: "fontFamily",
2316
+ addGlobalAttributes() {
2317
+ return [
2318
+ {
2319
+ types: ["textStyle"],
2320
+ attributes: {
2321
+ fontFamily: {
2322
+ default: null,
2323
+ parseHTML: (el) => el.style.fontFamily || null,
2324
+ renderHTML: (attrs) => {
2325
+ if (!attrs.fontFamily) return {};
2326
+ return { style: `font-family: ${attrs.fontFamily}` };
2327
+ }
2328
+ }
2329
+ }
2330
+ }
2331
+ ];
2332
+ },
2333
+ addCommands() {
2334
+ return {
2335
+ setFontFamily: (fontFamily) => ({ tr, state, dispatch }) => {
2336
+ const textStyleType = state.schema.marks.textStyle;
2337
+ const { from, to, empty } = state.selection;
2338
+ if (empty) {
2339
+ const stored = tr.storedMarks ? [...tr.storedMarks] : [...state.storedMarks ?? []];
2340
+ const idx = stored.findIndex((m) => m.type === textStyleType);
2341
+ const existing = idx >= 0 ? stored[idx] : void 0;
2342
+ const merged = mergeFontFamily(textStyleType, existing, fontFamily);
2343
+ if (idx >= 0) {
2344
+ if (hasAttrs2(merged)) {
2345
+ stored[idx] = merged;
2346
+ } else {
2347
+ stored.splice(idx, 1);
2348
+ }
2349
+ } else {
2350
+ stored.push(merged);
2351
+ }
2352
+ tr.setStoredMarks(stored);
2353
+ } else {
2354
+ state.doc.nodesBetween(from, to, (node, pos) => {
2355
+ if (!node.isText) return;
2356
+ const fromPos = Math.max(pos, from);
2357
+ const toPos = Math.min(pos + node.nodeSize, to);
2358
+ const existingTextStyle = node.marks.find((m) => m.type === textStyleType);
2359
+ const merged = mergeFontFamily(textStyleType, existingTextStyle, fontFamily);
2360
+ if (hasAttrs2(merged)) {
2361
+ tr.addMark(fromPos, toPos, merged);
2362
+ } else if (existingTextStyle) {
2363
+ tr.removeMark(fromPos, toPos, existingTextStyle);
2364
+ }
2365
+ });
2366
+ }
2367
+ if (dispatch) dispatch(tr);
2368
+ return true;
2369
+ },
2370
+ unsetFontFamily: () => ({ tr, state, dispatch }) => {
2371
+ const textStyleType = state.schema.marks.textStyle;
2372
+ const { from, to, empty } = state.selection;
2373
+ if (empty) {
2374
+ const stored = tr.storedMarks ? [...tr.storedMarks] : [...state.storedMarks ?? []];
2375
+ const idx = stored.findIndex((m) => m.type === textStyleType);
2376
+ if (idx >= 0) {
2377
+ const merged = mergeFontFamily(textStyleType, stored[idx], null);
2378
+ if (hasAttrs2(merged)) {
2379
+ stored[idx] = merged;
2380
+ } else {
2381
+ stored.splice(idx, 1);
2382
+ }
2383
+ tr.setStoredMarks(stored);
2384
+ }
2385
+ } else {
2386
+ state.doc.nodesBetween(from, to, (node, pos) => {
2387
+ if (!node.isText) return;
2388
+ const fromPos = Math.max(pos, from);
2389
+ const toPos = Math.min(pos + node.nodeSize, to);
2390
+ const existingTextStyle = node.marks.find((m) => m.type === textStyleType);
2391
+ if (!existingTextStyle) return;
2392
+ const merged = mergeFontFamily(textStyleType, existingTextStyle, null);
2393
+ if (hasAttrs2(merged)) {
2394
+ tr.addMark(fromPos, toPos, merged);
2395
+ } else {
2396
+ tr.removeMark(fromPos, toPos, existingTextStyle);
2397
+ }
2398
+ });
2399
+ }
2400
+ if (dispatch) dispatch(tr);
2401
+ return true;
2402
+ }
2403
+ };
2404
+ }
2405
+ });
2406
+
2302
2407
  // src/modes.ts
2303
2408
  var DOCUMENT_MODES = ["editing", "suggesting", "viewing"];
2304
2409
 
@@ -2821,6 +2926,7 @@ function claudeProvider(config) {
2821
2926
  CONTEXT_CHAR_CAP,
2822
2927
  DOCUMENT_MODES,
2823
2928
  EditorContextExtension,
2929
+ FontFamilyExtension,
2824
2930
  FontSizeExtension,
2825
2931
  LOCAL_STORAGE_KEY,
2826
2932
  PAGE_SIZES,
package/dist/index.d.cts CHANGED
@@ -280,6 +280,28 @@ declare module '@tiptap/core' {
280
280
  */
281
281
  declare const FontSizeExtension: Extension<any, any>;
282
282
 
283
+ declare module '@tiptap/core' {
284
+ interface Commands<ReturnType> {
285
+ fontFamily: {
286
+ /** Set font family on the current selection, e.g. 'Georgia, serif'. */
287
+ setFontFamily: (fontFamily: string) => ReturnType;
288
+ /** Remove font family from the current selection. */
289
+ unsetFontFamily: () => ReturnType;
290
+ };
291
+ }
292
+ }
293
+ /**
294
+ * FontFamilyExtension — adds a `fontFamily` attribute onto TextStyle marks.
295
+ * Requires TextStyle to be registered separately (done in Editor.ts).
296
+ *
297
+ * Mirrors FontSizeExtension: it manipulates the transaction directly
298
+ * (tr.setStoredMarks for a collapsed caret / tr.addMark over a selection) so it
299
+ * merges cleanly with the other TextStyle attributes (fontSize, color) instead
300
+ * of clobbering them. The attribute round-trips through HTML, so the chosen
301
+ * font is stored with the document.
302
+ */
303
+ declare const FontFamilyExtension: Extension<any, any>;
304
+
283
305
  interface EditorContextOptions {
284
306
  onImageUpload?: ImageUploadHandler;
285
307
  citation?: CitationPort;
@@ -412,4 +434,4 @@ declare class SubdocumentProvider {
412
434
  destroy(): void;
413
435
  }
414
436
 
415
- export { AIDraftFn, AIStreamFn, type AwarenessState, BlockAttributesExtension, CitationPort, type ClipboardSource, type CollaborationOptions, type CollaborationSetup, DOCUMENT_MODES, type DocsEditor, type DocsEditorPlugin, type DocumentMode, EditorContextExtension, type EditorContextOptions, type EditorOptions, FontSizeExtension, ImageUploadHandler, type MonitorMetric, PerformanceMonitor, type PerformanceMonitorOptions, SearchAndReplaceExtension, type SearchMatch, type SearchState, type SlashCommand, type SubdocState, SubdocumentProvider, type SubdocumentProviderOptions, type ToolbarItem, clearSearch, collaborationExtensions, collectExtensions, createActionMap, createCollaboration, createEditor, createPerformanceMonitor, definePlugin, detectClipboardSource, findMatches, getSearchState, normalizeClipboardHTML, replaceAll, replaceCurrent, resolveAction, sanitizeInlineHTML, sanitizePastedHTML, searchAndReplaceKey, searchNext, searchPrev, setSearchQuery };
437
+ export { AIDraftFn, AIStreamFn, type AwarenessState, BlockAttributesExtension, CitationPort, type ClipboardSource, type CollaborationOptions, type CollaborationSetup, DOCUMENT_MODES, type DocsEditor, type DocsEditorPlugin, type DocumentMode, EditorContextExtension, type EditorContextOptions, type EditorOptions, FontFamilyExtension, FontSizeExtension, ImageUploadHandler, type MonitorMetric, PerformanceMonitor, type PerformanceMonitorOptions, SearchAndReplaceExtension, type SearchMatch, type SearchState, type SlashCommand, type SubdocState, SubdocumentProvider, type SubdocumentProviderOptions, type ToolbarItem, clearSearch, collaborationExtensions, collectExtensions, createActionMap, createCollaboration, createEditor, createPerformanceMonitor, definePlugin, detectClipboardSource, findMatches, getSearchState, normalizeClipboardHTML, replaceAll, replaceCurrent, resolveAction, sanitizeInlineHTML, sanitizePastedHTML, searchAndReplaceKey, searchNext, searchPrev, setSearchQuery };
package/dist/index.d.ts CHANGED
@@ -280,6 +280,28 @@ declare module '@tiptap/core' {
280
280
  */
281
281
  declare const FontSizeExtension: Extension<any, any>;
282
282
 
283
+ declare module '@tiptap/core' {
284
+ interface Commands<ReturnType> {
285
+ fontFamily: {
286
+ /** Set font family on the current selection, e.g. 'Georgia, serif'. */
287
+ setFontFamily: (fontFamily: string) => ReturnType;
288
+ /** Remove font family from the current selection. */
289
+ unsetFontFamily: () => ReturnType;
290
+ };
291
+ }
292
+ }
293
+ /**
294
+ * FontFamilyExtension — adds a `fontFamily` attribute onto TextStyle marks.
295
+ * Requires TextStyle to be registered separately (done in Editor.ts).
296
+ *
297
+ * Mirrors FontSizeExtension: it manipulates the transaction directly
298
+ * (tr.setStoredMarks for a collapsed caret / tr.addMark over a selection) so it
299
+ * merges cleanly with the other TextStyle attributes (fontSize, color) instead
300
+ * of clobbering them. The attribute round-trips through HTML, so the chosen
301
+ * font is stored with the document.
302
+ */
303
+ declare const FontFamilyExtension: Extension<any, any>;
304
+
283
305
  interface EditorContextOptions {
284
306
  onImageUpload?: ImageUploadHandler;
285
307
  citation?: CitationPort;
@@ -412,4 +434,4 @@ declare class SubdocumentProvider {
412
434
  destroy(): void;
413
435
  }
414
436
 
415
- export { AIDraftFn, AIStreamFn, type AwarenessState, BlockAttributesExtension, CitationPort, type ClipboardSource, type CollaborationOptions, type CollaborationSetup, DOCUMENT_MODES, type DocsEditor, type DocsEditorPlugin, type DocumentMode, EditorContextExtension, type EditorContextOptions, type EditorOptions, FontSizeExtension, ImageUploadHandler, type MonitorMetric, PerformanceMonitor, type PerformanceMonitorOptions, SearchAndReplaceExtension, type SearchMatch, type SearchState, type SlashCommand, type SubdocState, SubdocumentProvider, type SubdocumentProviderOptions, type ToolbarItem, clearSearch, collaborationExtensions, collectExtensions, createActionMap, createCollaboration, createEditor, createPerformanceMonitor, definePlugin, detectClipboardSource, findMatches, getSearchState, normalizeClipboardHTML, replaceAll, replaceCurrent, resolveAction, sanitizeInlineHTML, sanitizePastedHTML, searchAndReplaceKey, searchNext, searchPrev, setSearchQuery };
437
+ export { AIDraftFn, AIStreamFn, type AwarenessState, BlockAttributesExtension, CitationPort, type ClipboardSource, type CollaborationOptions, type CollaborationSetup, DOCUMENT_MODES, type DocsEditor, type DocsEditorPlugin, type DocumentMode, EditorContextExtension, type EditorContextOptions, type EditorOptions, FontFamilyExtension, FontSizeExtension, ImageUploadHandler, type MonitorMetric, PerformanceMonitor, type PerformanceMonitorOptions, SearchAndReplaceExtension, type SearchMatch, type SearchState, type SlashCommand, type SubdocState, SubdocumentProvider, type SubdocumentProviderOptions, type ToolbarItem, clearSearch, collaborationExtensions, collectExtensions, createActionMap, createCollaboration, createEditor, createPerformanceMonitor, definePlugin, detectClipboardSource, findMatches, getSearchState, normalizeClipboardHTML, replaceAll, replaceCurrent, resolveAction, sanitizeInlineHTML, sanitizePastedHTML, searchAndReplaceKey, searchNext, searchPrev, setSearchQuery };
package/dist/index.js CHANGED
@@ -2161,7 +2161,6 @@ var FontSizeExtension = Extension6.create({
2161
2161
  addCommands() {
2162
2162
  return {
2163
2163
  setFontSize: (fontSize) => ({ tr, state, dispatch }) => {
2164
- console.log("[FontSizeExt] setFontSize called, fontSize:", fontSize, "empty:", state.selection.empty);
2165
2164
  const textStyleType = state.schema.marks.textStyle;
2166
2165
  const { from, to, empty } = state.selection;
2167
2166
  if (empty) {
@@ -2237,6 +2236,111 @@ var FontSizeExtension = Extension6.create({
2237
2236
  }
2238
2237
  });
2239
2238
 
2239
+ // src/FontFamily.ts
2240
+ import { Extension as Extension7 } from "@tiptap/core";
2241
+ function mergeFontFamily(textStyleType, existing, fontFamily) {
2242
+ if (fontFamily === null) {
2243
+ const { fontFamily: _removed, ...rest } = existing?.attrs ?? {};
2244
+ return textStyleType.create(rest);
2245
+ }
2246
+ return textStyleType.create({ ...existing?.attrs, fontFamily });
2247
+ }
2248
+ function hasAttrs2(mark) {
2249
+ return Object.values(mark.attrs).some((v) => v != null);
2250
+ }
2251
+ var FontFamilyExtension = Extension7.create({
2252
+ name: "fontFamily",
2253
+ addGlobalAttributes() {
2254
+ return [
2255
+ {
2256
+ types: ["textStyle"],
2257
+ attributes: {
2258
+ fontFamily: {
2259
+ default: null,
2260
+ parseHTML: (el) => el.style.fontFamily || null,
2261
+ renderHTML: (attrs) => {
2262
+ if (!attrs.fontFamily) return {};
2263
+ return { style: `font-family: ${attrs.fontFamily}` };
2264
+ }
2265
+ }
2266
+ }
2267
+ }
2268
+ ];
2269
+ },
2270
+ addCommands() {
2271
+ return {
2272
+ setFontFamily: (fontFamily) => ({ tr, state, dispatch }) => {
2273
+ const textStyleType = state.schema.marks.textStyle;
2274
+ const { from, to, empty } = state.selection;
2275
+ if (empty) {
2276
+ const stored = tr.storedMarks ? [...tr.storedMarks] : [...state.storedMarks ?? []];
2277
+ const idx = stored.findIndex((m) => m.type === textStyleType);
2278
+ const existing = idx >= 0 ? stored[idx] : void 0;
2279
+ const merged = mergeFontFamily(textStyleType, existing, fontFamily);
2280
+ if (idx >= 0) {
2281
+ if (hasAttrs2(merged)) {
2282
+ stored[idx] = merged;
2283
+ } else {
2284
+ stored.splice(idx, 1);
2285
+ }
2286
+ } else {
2287
+ stored.push(merged);
2288
+ }
2289
+ tr.setStoredMarks(stored);
2290
+ } else {
2291
+ state.doc.nodesBetween(from, to, (node, pos) => {
2292
+ if (!node.isText) return;
2293
+ const fromPos = Math.max(pos, from);
2294
+ const toPos = Math.min(pos + node.nodeSize, to);
2295
+ const existingTextStyle = node.marks.find((m) => m.type === textStyleType);
2296
+ const merged = mergeFontFamily(textStyleType, existingTextStyle, fontFamily);
2297
+ if (hasAttrs2(merged)) {
2298
+ tr.addMark(fromPos, toPos, merged);
2299
+ } else if (existingTextStyle) {
2300
+ tr.removeMark(fromPos, toPos, existingTextStyle);
2301
+ }
2302
+ });
2303
+ }
2304
+ if (dispatch) dispatch(tr);
2305
+ return true;
2306
+ },
2307
+ unsetFontFamily: () => ({ tr, state, dispatch }) => {
2308
+ const textStyleType = state.schema.marks.textStyle;
2309
+ const { from, to, empty } = state.selection;
2310
+ if (empty) {
2311
+ const stored = tr.storedMarks ? [...tr.storedMarks] : [...state.storedMarks ?? []];
2312
+ const idx = stored.findIndex((m) => m.type === textStyleType);
2313
+ if (idx >= 0) {
2314
+ const merged = mergeFontFamily(textStyleType, stored[idx], null);
2315
+ if (hasAttrs2(merged)) {
2316
+ stored[idx] = merged;
2317
+ } else {
2318
+ stored.splice(idx, 1);
2319
+ }
2320
+ tr.setStoredMarks(stored);
2321
+ }
2322
+ } else {
2323
+ state.doc.nodesBetween(from, to, (node, pos) => {
2324
+ if (!node.isText) return;
2325
+ const fromPos = Math.max(pos, from);
2326
+ const toPos = Math.min(pos + node.nodeSize, to);
2327
+ const existingTextStyle = node.marks.find((m) => m.type === textStyleType);
2328
+ if (!existingTextStyle) return;
2329
+ const merged = mergeFontFamily(textStyleType, existingTextStyle, null);
2330
+ if (hasAttrs2(merged)) {
2331
+ tr.addMark(fromPos, toPos, merged);
2332
+ } else {
2333
+ tr.removeMark(fromPos, toPos, existingTextStyle);
2334
+ }
2335
+ });
2336
+ }
2337
+ if (dispatch) dispatch(tr);
2338
+ return true;
2339
+ }
2340
+ };
2341
+ }
2342
+ });
2343
+
2240
2344
  // src/modes.ts
2241
2345
  var DOCUMENT_MODES = ["editing", "suggesting", "viewing"];
2242
2346
 
@@ -2351,6 +2455,7 @@ export {
2351
2455
  CONTEXT_CHAR_CAP,
2352
2456
  DOCUMENT_MODES,
2353
2457
  EditorContextExtension,
2458
+ FontFamilyExtension,
2354
2459
  FontSizeExtension,
2355
2460
  LOCAL_STORAGE_KEY,
2356
2461
  PAGE_SIZES,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kedataindo/docflow-core",
3
3
  "license": "Apache-2.0",
4
- "version": "0.0.86",
4
+ "version": "0.0.87",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",