@inshapardaz/likhari-react 0.1.39-dev.296 → 0.1.39-dev.300
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/EditorRoot.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorRoot.d.ts","sourceRoot":"","sources":["../src/EditorRoot.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAY1D,OAAO,KAAK,EAA8B,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEjF,OAAO,EAAyB,KAAK,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AACvF,OAAO,EAAwB,KAAK,mBAAmB,EAAE,KAAK,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAIzH,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"EditorRoot.d.ts","sourceRoot":"","sources":["../src/EditorRoot.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAY1D,OAAO,KAAK,EAA8B,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEjF,OAAO,EAAyB,KAAK,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AACvF,OAAO,EAAwB,KAAK,mBAAmB,EAAE,KAAK,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAIzH,OAAO,EAAW,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAElE,OAAO,EAAoC,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAO3F,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAIhF,OAAO,EAAgC,KAAK,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACtG,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;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AAe,CAAC,EAAE,mBAAmB,CAAC;IACtC,uGAAuG;IACvG,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC3E,6EAA6E;IAC7E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,SAAS;IACxB,UAAU,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,CAAC;IACrC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAG,IAAI,CAAC;IAClD,iBAAiB,IAAI,OAAO,CAAC;IAC7B,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,KAAK,IAAI,IAAI,CAAC;CACf;AAQD,eAAO,MAAM,UAAU,uGA6erB,CAAC"}
|
package/dist/EditorRoot.js
CHANGED
|
@@ -18,6 +18,7 @@ import { EDITOR_NODES } from './nodes.js';
|
|
|
18
18
|
import { editorTheme } from './theme/editorTheme.js';
|
|
19
19
|
import { EditorThemeProvider } from './theme/EditorThemeProvider.js';
|
|
20
20
|
import { Toolbar } from './components/Toolbar.js';
|
|
21
|
+
import { readFontSettings, writeFontSettings } from './persistence/fontStorage.js';
|
|
21
22
|
import { clampZoom, injectUrduWebFontsCss } from './fonts/index.js';
|
|
22
23
|
import { LinkPastePlugin } from './plugins/LinkPastePlugin.js';
|
|
23
24
|
import { PageBreakPlugin } from './plugins/PageBreakPlugin.js';
|
|
@@ -70,27 +71,36 @@ export const EditorRoot = forwardRef(function EditorRoot({ documentId, autoCorre
|
|
|
70
71
|
const draftId = documentId ?? adoptedDraftId ?? generatedDraftId;
|
|
71
72
|
// The urdu-web-fonts stylesheets are needed for the font dropdown and for
|
|
72
73
|
// RTL content, whose canvas font (editor.css) is one of those families.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
// Uniform font mode: the toolbar and the host's props both drive these. The
|
|
78
|
-
// props seed them and win whenever they change; the toolbar changes them in
|
|
79
|
-
// between and reports through onFontChange.
|
|
74
|
+
// Uniform font mode: the toolbar and the host's props both drive these. They
|
|
75
|
+
// start from the props, else from what the user chose last time (kept in
|
|
76
|
+
// localStorage), and a prop that is given wins whenever it changes. A toolbar
|
|
77
|
+
// change is saved, and reported through onFontChange.
|
|
80
78
|
const uniform = fontMode === 'uniform';
|
|
81
|
-
const [uniformFamily, setUniformFamily] = useState(fontFamily);
|
|
82
|
-
const [uniformZoom, setUniformZoom] = useState(() => clampZoom(zoom));
|
|
83
|
-
useEffect(() =>
|
|
84
|
-
|
|
79
|
+
const [uniformFamily, setUniformFamily] = useState(() => fontFamily ?? readFontSettings(documentId).fontFamily);
|
|
80
|
+
const [uniformZoom, setUniformZoom] = useState(() => clampZoom(zoom ?? readFontSettings(documentId).zoom));
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (fontFamily !== undefined)
|
|
83
|
+
setUniformFamily(fontFamily);
|
|
84
|
+
}, [fontFamily]);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (zoom !== undefined)
|
|
87
|
+
setUniformZoom(clampZoom(zoom));
|
|
88
|
+
}, [zoom]);
|
|
85
89
|
const handleUniformFamily = (family) => {
|
|
86
90
|
setUniformFamily(family);
|
|
91
|
+
writeFontSettings({ fontFamily: family, zoom: uniformZoom }, documentId);
|
|
87
92
|
onFontChange?.({ fontFamily: family, zoom: uniformZoom });
|
|
88
93
|
};
|
|
89
94
|
const handleUniformZoom = (level) => {
|
|
90
95
|
const next = clampZoom(level);
|
|
91
96
|
setUniformZoom(next);
|
|
97
|
+
writeFontSettings({ fontFamily: uniformFamily, zoom: next }, documentId);
|
|
92
98
|
onFontChange?.({ fontFamily: uniformFamily, zoom: next });
|
|
93
99
|
};
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (config.font.family || uniformFamily || locale !== 'en')
|
|
102
|
+
injectUrduWebFontsCss();
|
|
103
|
+
}, [config.font.family, uniformFamily, locale]);
|
|
94
104
|
const imageOptions = useMemo(() => ({
|
|
95
105
|
allowLinked: config.images.linked,
|
|
96
106
|
allowEmbedded: config.images.embedded,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remembers the uniform font mode's font family and zoom in `localStorage`, so a
|
|
3
|
+
* reader's choice survives a reload. They are a view preference, not document
|
|
4
|
+
* content, so they are stored apart from drafts: under `documentId` when the
|
|
5
|
+
* editor has one, otherwise shared by editors on the page. Every function is a
|
|
6
|
+
* no-op (never throws) when `localStorage` is unavailable or holds bad data.
|
|
7
|
+
*/
|
|
8
|
+
export interface StoredFontSettings {
|
|
9
|
+
fontFamily?: string;
|
|
10
|
+
zoom?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function readFontSettings(documentId?: string): StoredFontSettings;
|
|
13
|
+
export declare function writeFontSettings(settings: StoredFontSettings, documentId?: string): void;
|
|
14
|
+
//# sourceMappingURL=fontStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fontStorage.d.ts","sourceRoot":"","sources":["../../src/persistence/fontStorage.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAcD,wBAAgB,gBAAgB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAcxE;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,kBAAkB,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAMzF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remembers the uniform font mode's font family and zoom in `localStorage`, so a
|
|
3
|
+
* reader's choice survives a reload. They are a view preference, not document
|
|
4
|
+
* content, so they are stored apart from drafts: under `documentId` when the
|
|
5
|
+
* editor has one, otherwise shared by editors on the page. Every function is a
|
|
6
|
+
* no-op (never throws) when `localStorage` is unavailable or holds bad data.
|
|
7
|
+
*/
|
|
8
|
+
const KEY_PREFIX = 'likhari:font:';
|
|
9
|
+
const SHARED_ID = '_';
|
|
10
|
+
function storage() {
|
|
11
|
+
try {
|
|
12
|
+
return typeof localStorage === 'undefined' ? null : localStorage;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function keyFor(documentId) {
|
|
19
|
+
return `${KEY_PREFIX}${documentId ?? SHARED_ID}`;
|
|
20
|
+
}
|
|
21
|
+
export function readFontSettings(documentId) {
|
|
22
|
+
try {
|
|
23
|
+
const raw = storage()?.getItem(keyFor(documentId));
|
|
24
|
+
if (!raw)
|
|
25
|
+
return {};
|
|
26
|
+
const parsed = JSON.parse(raw);
|
|
27
|
+
if (!parsed || typeof parsed !== 'object')
|
|
28
|
+
return {};
|
|
29
|
+
const { fontFamily, zoom } = parsed;
|
|
30
|
+
return {
|
|
31
|
+
...(typeof fontFamily === 'string' && fontFamily !== '' && { fontFamily }),
|
|
32
|
+
...(typeof zoom === 'number' && Number.isFinite(zoom) && { zoom }),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function writeFontSettings(settings, documentId) {
|
|
40
|
+
try {
|
|
41
|
+
storage()?.setItem(keyFor(documentId), JSON.stringify(settings));
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Storage full or blocked: the setting still applies for this session.
|
|
45
|
+
}
|
|
46
|
+
}
|