weml-monaco 0.9.0 → 0.9.1

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/CHANGELOG.md CHANGED
@@ -8,6 +8,15 @@ This package shares the language logic of the VS Code extension (`weml-support`)
8
8
  entries below track the port catching up with its provider changes; since the shared language
9
9
  features, both take the same code.
10
10
 
11
+ ## [0.9.1] — 2026-10-14
12
+
13
+ ### Fixed
14
+ - `createWemlEditor`: an editor opened after the last one on the same Monaco closed has the language
15
+ again — highlighting, completion, hover, diagnostics, formatting. The `weml` id outlives the
16
+ disposed registration (Monaco cannot unregister a language) and was taken for someone else's.
17
+ - The paragraph mode keeps the host's `readOnly` (`editorOptions`, the Settings view) and its
18
+ `readOnlyMessage`: the wrapper guard only adds its own lock, while the selection touches the wrapper.
19
+
11
20
  ## [0.9.0] — 2026-10-13
12
21
 
13
22
  ### Added
package/dist/editor.cjs CHANGED
@@ -38220,10 +38220,13 @@ function injectEditorStyles(doc = document) {
38220
38220
  // src/editor/wrapperGuard.ts
38221
38221
  var HIDDEN_AREAS_SOURCE = "weml-editor.wrapper";
38222
38222
  var WRAPPER_LINE_CLASS = "weml-editor-wrapper-line";
38223
- function guardWrapper(m2, editor, hideWrapper) {
38223
+ var WRAPPER_MESSAGE = { value: "The `<div id>` wrapper is not part of the paragraph and cannot be edited." };
38224
+ function guardWrapper(m2, editor, hideWrapper, hostOptions) {
38224
38225
  const model = editor.getModel();
38225
38226
  if (!model) return { dispose() {
38227
+ }, setHostOptions() {
38226
38228
  } };
38229
+ let host = hostOptions;
38227
38230
  const disposables = [];
38228
38231
  const touchesWrapper = (selection) => selection.startLineNumber < 2 || selection.endLineNumber > model.getLineCount() - 1;
38229
38232
  const clampSelections = () => {
@@ -38240,15 +38243,17 @@ function guardWrapper(m2, editor, hideWrapper) {
38240
38243
  })
38241
38244
  );
38242
38245
  };
38246
+ let applied;
38243
38247
  const syncReadOnly = () => {
38244
- const readOnly = (editor.getSelections() ?? []).some(touchesWrapper);
38245
- if (editor.getOption(m2.editor.EditorOption.readOnly) !== readOnly) editor.updateOptions({ readOnly });
38248
+ const locked = (editor.getSelections() ?? []).some(touchesWrapper);
38249
+ const readOnly = host.readOnly === true || locked;
38250
+ const readOnlyMessage = locked && host.readOnly !== true ? WRAPPER_MESSAGE : host.readOnlyMessage;
38251
+ if (applied?.readOnly === readOnly && applied.readOnlyMessage === readOnlyMessage) return;
38252
+ applied = { readOnly, readOnlyMessage };
38253
+ editor.updateOptions({ readOnly, readOnlyMessage });
38246
38254
  };
38247
38255
  const offset = contentLineOffset("paragraph", hideWrapper);
38248
- editor.updateOptions({
38249
- readOnlyMessage: { value: "The `<div id>` wrapper is not part of the paragraph and cannot be edited." },
38250
- lineNumbers: (lineNumber) => String(lineNumber - offset)
38251
- });
38256
+ editor.updateOptions({ lineNumbers: (lineNumber) => String(lineNumber - offset) });
38252
38257
  disposables.push(
38253
38258
  editor.onDidChangeCursorSelection(() => {
38254
38259
  if (hideWrapper) clampSelections();
@@ -38313,6 +38318,11 @@ function guardWrapper(m2, editor, hideWrapper) {
38313
38318
  })
38314
38319
  );
38315
38320
  return {
38321
+ setHostOptions(options) {
38322
+ host = options;
38323
+ applied = void 0;
38324
+ syncReadOnly();
38325
+ },
38316
38326
  dispose() {
38317
38327
  for (const disposable of disposables) disposable.dispose();
38318
38328
  wrapperLines.clear();
@@ -38352,6 +38362,7 @@ function jsonOptions(options) {
38352
38362
  return Object.fromEntries(Object.entries(options).filter(([key, value]) => !NOT_SETTINGS.has(key) && value !== void 0 && plain(value)));
38353
38363
  }
38354
38364
  var sharedLanguage = /* @__PURE__ */ new WeakMap();
38365
+ var ownLanguageId = /* @__PURE__ */ new WeakSet();
38355
38366
  var editorCount = 0;
38356
38367
  function acquireLanguage(m2, options) {
38357
38368
  if (options.language) return { registration: options.language, release() {
@@ -38361,12 +38372,13 @@ function acquireLanguage(m2, options) {
38361
38372
  shared.users++;
38362
38373
  return { registration: shared.registration, release: () => releaseShared(m2) };
38363
38374
  }
38364
- if (m2.languages.getLanguages().some((language) => language.id === "weml")) {
38375
+ if (!ownLanguageId.has(m2) && m2.languages.getLanguages().some((language) => language.id === "weml")) {
38365
38376
  return { registration: { analysis: localAnalysis, formatter: localFormatter, dispose() {
38366
38377
  } }, release() {
38367
38378
  } };
38368
38379
  }
38369
38380
  const registration = options.workers ? registerWemlWorker(m2, { ...options.languageOptions, worker: options.workers.analysis, formatWorker: options.workers.format }) : registerWeml(m2, options.languageOptions);
38381
+ ownLanguageId.add(m2);
38370
38382
  sharedLanguage.set(m2, { registration, users: 1 });
38371
38383
  return { registration, release: () => releaseShared(m2) };
38372
38384
  }
@@ -38458,7 +38470,12 @@ function createWemlEditor(m2, container, options = {}) {
38458
38470
  const editorHost = element("div", { className: "wb-editor wb-part" });
38459
38471
  const baseOptions = { ...EDITOR_OPTIONS, ...options.editorOptions };
38460
38472
  const editor = m2.editor.create(editorHost, { ...baseOptions, ...layout.editorOptions, model });
38461
- if (mode === "paragraph") disposables.push(guardWrapper(m2, editor, options.hideWrapper ?? false));
38473
+ const wrapperGuard = mode === "paragraph" ? guardWrapper(m2, editor, options.hideWrapper ?? false, { ...baseOptions, ...layout.editorOptions }) : void 0;
38474
+ if (wrapperGuard) disposables.push(wrapperGuard);
38475
+ const applyEditorOptions = (next) => {
38476
+ editor.updateOptions(next);
38477
+ wrapperGuard?.setHostOptions(next);
38478
+ };
38462
38479
  const content = createContentApi(editor, mode, lineOffset, initialValue);
38463
38480
  const valueListeners = /* @__PURE__ */ new Set();
38464
38481
  const problemListeners = /* @__PURE__ */ new Set();
@@ -38814,12 +38831,12 @@ function createWemlEditor(m2, container, options = {}) {
38814
38831
  const own = Object.fromEntries(Object.entries(jsonOptions(parsed)).filter(([key, value]) => JSON.stringify(value) !== JSON.stringify(base[key])));
38815
38832
  if (JSON.stringify(own) === JSON.stringify(layout.editorOptions ?? {})) return;
38816
38833
  layout.editorOptions = own;
38817
- editor.updateOptions({ ...base, ...own });
38834
+ applyEditorOptions({ ...base, ...own });
38818
38835
  saveLayout();
38819
38836
  }
38820
38837
  function resetSettings() {
38821
38838
  layout.editorOptions = {};
38822
- editor.updateOptions(jsonOptions(baseOptions));
38839
+ applyEditorOptions(jsonOptions(baseOptions));
38823
38840
  saveLayout();
38824
38841
  views.get("settings")?.settings?.setText(settingsText());
38825
38842
  }