@octane-xplat/richtext 0.11.0 → 0.12.0

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.
@@ -135,7 +135,8 @@ var RichTextEditor = defineUniversalComponent("nativescript", function RichTextE
135
135
  }
136
136
  },
137
137
  apply: (format) => {
138
- if (format === "link") return;
138
+ if (format === "link") throw new RangeError("Use linkTo(url, anchor) to apply a link");
139
+ if (!FORMATS[format]) throw new RangeError(`[richtext] Unsupported format: ${format}`);
139
140
  e.toggleFormatting(formatOf(format));
140
141
  emitChange();
141
142
  },
@@ -211,11 +212,12 @@ var RichTextEditor = defineUniversalComponent("nativescript", function RichTextE
211
212
  end,
212
213
  active: activeFormats(e)
213
214
  }) }));
214
- e.addTextChangedListener(new androidText.TextWatcher({
215
+ const watcher = new androidText.TextWatcher({
215
216
  beforeTextChanged: () => {},
216
217
  onTextChanged: () => {},
217
218
  afterTextChanged: () => emitChange()
218
- }));
219
+ });
220
+ e.addTextChangedListener(watcher);
219
221
  e.setOnFocusChangeListener(new androidView.View.OnFocusChangeListener({ onFocusChange: (_v, focused) => focused ? props.onFocus?.() : props.onBlur?.() }));
220
222
  if (props.placeholder !== void 0) e.setHint(props.placeholder);
221
223
  setEditable(props.editable !== false);
@@ -233,6 +235,11 @@ var RichTextEditor = defineUniversalComponent("nativescript", function RichTextE
233
235
  }
234
236
  if (props.android) Object.assign(e, props.android);
235
237
  props.onReady?.();
238
+ return () => {
239
+ clearTimeout(emitTimer.current);
240
+ e.removeTextChangedListener(watcher);
241
+ e.setOnFocusChangeListener(null);
242
+ };
236
243
  }, [], _h$7);
237
244
  useEffect(() => {
238
245
  const e = editor();
@@ -1,7 +1,7 @@
1
1
  import { defineUniversalComponent, hookSlots, registerElement, universalPlan, universalValue, useCallback, useEffect, useImperativeHandle, useRef } from "@nativescript-community/octane";
2
2
  import { View } from "@nativescript/core";
3
3
  //#region src/RichTextEditor.ios.tsrx
4
- var _hs$ = /* @__PURE__ */ hookSlots(11);
4
+ var _hs$ = /* @__PURE__ */ hookSlots(10);
5
5
  var _h$0 = /* @__PURE__ */ Symbol(_hs$);
6
6
  var _h$1 = /* @__PURE__ */ Symbol(_hs$ + 1);
7
7
  var _h$2 = /* @__PURE__ */ Symbol(_hs$ + 2);
@@ -12,7 +12,6 @@ var _h$6 = /* @__PURE__ */ Symbol(_hs$ + 6);
12
12
  var _h$7 = /* @__PURE__ */ Symbol(_hs$ + 7);
13
13
  var _h$8 = /* @__PURE__ */ Symbol(_hs$ + 8);
14
14
  var _h$9 = /* @__PURE__ */ Symbol(_hs$ + 9);
15
- var _h$10 = /* @__PURE__ */ Symbol(_hs$ + 10);
16
15
  var __octaneUniversalPlan0 = universalPlan("nativescript", {
17
16
  "kind": "host",
18
17
  "type": "xplatrichtext",
@@ -52,11 +51,10 @@ var RichTextEditor = defineUniversalComponent("nativescript", function RichTextE
52
51
  const lastEmitted = useRef(void 0, _h$1);
53
52
  const applyingValue = useRef(false, _h$2);
54
53
  const emitTimer = useRef(null, _h$3);
55
- const warned = useRef(/* @__PURE__ */ new Set(), _h$4);
56
- useImperativeHandle(props.ref, () => handle(editor()), [], _h$5);
54
+ useImperativeHandle(props.ref, () => handle(editor()), [], _h$4);
57
55
  const bindHost = useCallback((v) => {
58
56
  host.current = v;
59
- }, [], _h$6);
57
+ }, [], _h$5);
60
58
  const editor = () => host.current?.ios;
61
59
  const emitChange = () => {
62
60
  if (!editor() || applyingValue.current) return;
@@ -69,11 +67,6 @@ var RichTextEditor = defineUniversalComponent("nativescript", function RichTextE
69
67
  props.onChange?.(html);
70
68
  }, 150);
71
69
  };
72
- const reportUnsupported = (format) => {
73
- if (warned.current.has(format)) return;
74
- warned.current.add(format);
75
- console.warn(`[richtext] apply('${format}') is not supported by the iOS Aztec surface`);
76
- };
77
70
  const handle = (e) => ({
78
71
  getHTML: () => e.getHTML(),
79
72
  setHTML: (html) => {
@@ -86,11 +79,8 @@ var RichTextEditor = defineUniversalComponent("nativescript", function RichTextE
86
79
  }
87
80
  },
88
81
  apply: (format) => {
89
- if (format === "link") return;
90
- if (UNSUPPORTED.has(format) || !e.applyFormat(format)) {
91
- reportUnsupported(format);
92
- return;
93
- }
82
+ if (format === "link") throw new RangeError("Use linkTo(url, anchor) to apply a link");
83
+ if (UNSUPPORTED.has(format) || !e.applyFormat(format)) throw new RangeError(`[richtext] apply('${format}') is not supported by the iOS Aztec surface`);
94
84
  emitChange();
95
85
  },
96
86
  linkTo: (url, anchor) => {
@@ -161,12 +151,13 @@ var RichTextEditor = defineUniversalComponent("nativescript", function RichTextE
161
151
  if (props.ios) Object.assign(e, props.ios);
162
152
  props.onReady?.();
163
153
  return () => {
154
+ clearTimeout(emitTimer.current);
164
155
  e.onTextChange = null;
165
156
  e.onSelectionChange = null;
166
157
  e.onFocus = null;
167
158
  e.onBlur = null;
168
159
  };
169
- }, [], _h$7);
160
+ }, [], _h$6);
170
161
  useEffect(() => {
171
162
  const e = editor();
172
163
  if (!e || props.value === void 0) return;
@@ -177,15 +168,15 @@ var RichTextEditor = defineUniversalComponent("nativescript", function RichTextE
177
168
  } finally {
178
169
  applyingValue.current = false;
179
170
  }
180
- }, [props.value], _h$8);
171
+ }, [props.value], _h$7);
181
172
  useEffect(() => {
182
173
  const e = editor();
183
174
  if (e) e.editable = props.editable !== false;
184
- }, [props.editable], _h$9);
175
+ }, [props.editable], _h$8);
185
176
  useEffect(() => {
186
177
  const e = editor();
187
178
  if (e && props.placeholder !== void 0) e.placeholder = props.placeholder;
188
- }, [props.placeholder], _h$10);
179
+ }, [props.placeholder], _h$9);
189
180
  return universalValue(__octaneUniversalPlan0, [
190
181
  bindHost,
191
182
  props.id,
@@ -0,0 +1,22 @@
1
+ import { defineUniversalComponent, universalPlan, universalValue } from "@nativescript-community/octane";
2
+ //#region src/RichTextEditor.windows.tsrx
3
+ var __octaneUniversalPlan0 = universalPlan("nativescript", {
4
+ "kind": "host",
5
+ "type": "label",
6
+ "props": { "text": "Rich text editing is not supported on Windows yet." },
7
+ "bindings": [
8
+ ["id", 0],
9
+ ["className", 1],
10
+ ["style", 2]
11
+ ]
12
+ });
13
+ var supported = false;
14
+ var RichTextEditor = defineUniversalComponent("nativescript", function RichTextEditor(props) {
15
+ return universalValue(__octaneUniversalPlan0, [
16
+ props.id,
17
+ props.className,
18
+ props.style
19
+ ]);
20
+ }, { "module": "@nativescript-community/octane" });
21
+ //#endregion
22
+ export { RichTextEditor, supported };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 1,
3
- "buildId": "933ede86-144c-4cb6-9763-762ae7aea462",
3
+ "buildId": "1e491876-e757-4510-a222-e7a7770d579a",
4
4
  "mode": "production",
5
5
  "capabilities": {
6
6
  "independentHydration": false
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 1,
3
- "buildId": "10dfc210-9d43-431b-bdf5-f06486fddbf1",
3
+ "buildId": "da936b6d-7379-4ae6-adb2-03a3273dc88b",
4
4
  "mode": "production",
5
5
  "capabilities": {
6
6
  "independentHydration": false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octane-xplat/richtext",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Native rich-text editing leaf for Octane xplat — Android Aztec and AppKit WKWebView StarterKit",
5
5
  "keywords": [
6
6
  "android",
@@ -58,12 +58,12 @@
58
58
  },
59
59
  "devDependencies": {
60
60
  "@nativescript-community/octane": "0.2.4",
61
- "@nativescript/core": "9.1.2",
62
- "@octane-xplat/macos-renderer": "0.11.0",
61
+ "@nativescript/core": "9.1.3",
62
+ "@octane-xplat/macos-renderer": "0.12.0",
63
63
  "@octanejs/vite-plugin": "0.1.61",
64
64
  "@tiptap/core": "3.28.0",
65
65
  "@tiptap/starter-kit": "3.28.0",
66
- "octane": "0.6.3",
66
+ "octane": "0.10.2",
67
67
  "typescript": "5.9.3",
68
68
  "vite": "8.3.0"
69
69
  },
@@ -154,7 +154,8 @@ export function RichTextEditor(props: RichTextEditorProps) @{
154
154
  }
155
155
  },
156
156
  apply: (format: RichTextFormat) => {
157
- if (format === 'link') return
157
+ if (format === 'link') throw new RangeError('Use linkTo(url, anchor) to apply a link')
158
+ if (!FORMATS[format]) throw new RangeError(`[richtext] Unsupported format: ${format}`)
158
159
  e.toggleFormatting(formatOf(format))
159
160
  emitChange()
160
161
  },
@@ -241,13 +242,13 @@ export function RichTextEditor(props: RichTextEditorProps) @{
241
242
  }),
242
243
  )
243
244
 
244
- e.addTextChangedListener(
245
- new androidText.TextWatcher({
246
- beforeTextChanged: () => {},
247
- onTextChanged: () => {},
248
- afterTextChanged: () => emitChange(),
249
- }),
250
- )
245
+ const watcher = new androidText.TextWatcher({
246
+ beforeTextChanged: () => {},
247
+ onTextChanged: () => {},
248
+ afterTextChanged: () => emitChange(),
249
+ })
250
+
251
+ e.addTextChangedListener(watcher)
251
252
 
252
253
  e.setOnFocusChangeListener(
253
254
  new androidView.View.OnFocusChangeListener({
@@ -275,6 +276,12 @@ export function RichTextEditor(props: RichTextEditorProps) @{
275
276
 
276
277
  if (props.android) Object.assign(e, props.android)
277
278
  props.onReady?.()
279
+
280
+ return () => {
281
+ clearTimeout(emitTimer.current)
282
+ e.removeTextChangedListener(watcher)
283
+ e.setOnFocusChangeListener(null)
284
+ }
278
285
  }, [])
279
286
 
280
287
  // `value` lands like a controlled prop, minus the loop: text the editor
@@ -49,7 +49,6 @@ export function RichTextEditor(props: RichTextEditorProps) @{
49
49
  const lastEmitted = useRef<string | undefined>(undefined)
50
50
  const applyingValue = useRef(false)
51
51
  const emitTimer = useRef<any>(null)
52
- const warned = useRef<Set<string>>(new Set())
53
52
 
54
53
  // Stable identity — an inline closure re-fires ref(null)/ref(v) per
55
54
  // render, which would bounce host.current around the effects below.
@@ -74,13 +73,6 @@ export function RichTextEditor(props: RichTextEditorProps) @{
74
73
  }, 150)
75
74
  }
76
75
 
77
- const reportUnsupported = (format: RichTextFormat) => {
78
- if (warned.current.has(format)) return
79
- warned.current.add(format)
80
- console.warn(
81
- `[richtext] apply('${format}') is not supported by the iOS Aztec surface`,
82
- )
83
- }
84
76
 
85
77
  const handle = (e: any): RichTextEditorHandle => ({
86
78
  getHTML: () => e.getHTML(),
@@ -94,10 +86,9 @@ export function RichTextEditor(props: RichTextEditorProps) @{
94
86
  }
95
87
  },
96
88
  apply: (format: RichTextFormat) => {
97
- if (format === 'link') return
89
+ if (format === 'link') throw new RangeError('Use linkTo(url, anchor) to apply a link')
98
90
  if (UNSUPPORTED.has(format) || !e.applyFormat(format)) {
99
- reportUnsupported(format)
100
- return
91
+ throw new RangeError(`[richtext] apply('${format}') is not supported by the iOS Aztec surface`)
101
92
  }
102
93
 
103
94
  emitChange()
@@ -178,6 +169,7 @@ export function RichTextEditor(props: RichTextEditorProps) @{
178
169
  props.onReady?.()
179
170
 
180
171
  return () => {
172
+ clearTimeout(emitTimer.current)
181
173
  e.onTextChange = null
182
174
  e.onSelectionChange = null
183
175
  e.onFocus = null
package/src/types.ts CHANGED
@@ -41,8 +41,8 @@ export interface RichTextEditorHandle {
41
41
  setHTML(html: string): void
42
42
  /** Toggle a format at the current selection. `link` needs
43
43
  * `linkTo(url, anchor)` instead. iOS has no taskList or text-alignment
44
- * engine support — those calls report a console warning and do not
45
- * change the document. */
44
+ * engine support — those calls throw RangeError before changing
45
+ * the document. apply('link') also throws; use linkTo instead. */
46
46
  apply(format: RichTextFormat): void
47
47
  /** Insert or re-target a link over the current selection. */
48
48
  linkTo(url: string, anchor?: string): void
package/types/types.d.ts CHANGED
@@ -14,8 +14,8 @@ export interface RichTextEditorHandle {
14
14
  setHTML(html: string): void;
15
15
  /** Toggle a format at the current selection. `link` needs
16
16
  * `linkTo(url, anchor)` instead. iOS has no taskList or text-alignment
17
- * engine support — those calls report a console warning and do not
18
- * change the document. */
17
+ * engine support — those calls throw RangeError before changing
18
+ * the document. apply('link') also throws; use linkTo instead. */
19
19
  apply(format: RichTextFormat): void;
20
20
  /** Insert or re-target a link over the current selection. */
21
21
  linkTo(url: string, anchor?: string): void;