@filumo/vue2 0.1.0 → 0.1.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/README.md CHANGED
@@ -10,7 +10,7 @@ Vue 2 document viewer adapter for Filumo, with Options API integration, plugin-b
10
10
 
11
11
  A Filumo adapter for Vue 2.6/2.7 using Options API and native render functions, with the same format plugins as Vue 3 and React.
12
12
 
13
- This documentation covers **0.1.0**. The commands below describe consumption after publication to npm. When using this source workspace, build the packages first as described in the integration guide.
13
+ This documentation covers **0.1.1**. The commands below describe consumption after publication to npm. When using this source workspace, build the packages first as described in the integration guide.
14
14
 
15
15
  ## Features
16
16
 
@@ -118,7 +118,7 @@ The current package is bold. Each package is published independently. Package na
118
118
  | ------------------------------------------------------------------ | ----------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
119
119
  | [@filumo/core](https://www.npmjs.com/package/@filumo/core) | Headless sources, plugin contracts, sessions and shared text utilities | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/core/README.md) |
120
120
  | [@filumo/dom](https://www.npmjs.com/package/@filumo/dom) | Native DOM viewer, toolbars, source views, outlines and shared UI | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/dom/README.md) |
121
- | [@filumo/viewer](https://www.npmjs.com/package/@filumo/viewer) | Standard preset and factories for nine format plugins | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/viewer/README.md) |
121
+ | [@filumo/viewer](https://www.npmjs.com/package/@filumo/viewer) | Standard preset and factories for ten format plugins | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/viewer/README.md) |
122
122
  | [@filumo/office](https://www.npmjs.com/package/@filumo/office) | Word, Excel, PowerPoint and supported legacy formats | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/office/README.md) |
123
123
  | [@filumo/pdf](https://www.npmjs.com/package/@filumo/pdf) | Continuous PDF reading, outlines, thumbnails and search | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/pdf/README.md) |
124
124
  | [@filumo/image](https://www.npmjs.com/package/@filumo/image) | Image preview, zoom, rotation, panning and shared overlays | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/image/README.md) |
@@ -131,6 +131,7 @@ The current package is bold. Each package is published independently. Package na
131
131
  | [@filumo/react](https://www.npmjs.com/package/@filumo/react) | React 18/19 adapter | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/react/README.md) |
132
132
  | [@filumo/vue](https://www.npmjs.com/package/@filumo/vue) | Vue 3 (>=3.3 <4) adapter | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/vue/README.md) |
133
133
  | **[@filumo/vue2](https://www.npmjs.com/package/@filumo/vue2)** | Vue 2 (^2.6.14 or ^2.7.16) adapter | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/vue2/README.md) |
134
+ | [@filumo/archive](https://www.npmjs.com/package/@filumo/archive) | Archive directories, on-demand extraction and child previews | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/archive/README.md) |
134
135
 
135
136
  <!-- filumo-packages:end -->
136
137
 
@@ -145,3 +146,9 @@ The current package is bold. Each package is published independently. Package na
145
146
  - [Changelog](https://github.com/gyxing/filumo-viewer/blob/master/CHANGELOG.md)
146
147
  - [Report an issue](https://github.com/gyxing/filumo-viewer/issues)
147
148
  - [MIT license](https://github.com/gyxing/filumo-viewer/blob/master/packages/vue2/LICENSE)
149
+
150
+ ## Custom toolbar icons
151
+
152
+ Import ToolbarAction from @filumo/vue2 and use icon: (h, context) => h(MyIcon), or pass a native ToolbarIcon object. Each placement creates an independent VNode in a lightweight child component linked to the viewer parent, retaining host injections and reactive render dependencies. Removal and teardown destroy the child and release its DOM. undefined keeps the default, null suppresses the icon. ToolbarIconRenderer and framework-aware configuration/update types are exported. getCapabilities() exposes normalized DOM capabilities.
153
+
154
+ See the Chinese README and exported types for full usage examples.
package/README.zh-CN.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  Vue 2.6/2.7 的 Filumo 适配组件,采用 Options API 和原生渲染函数,使用与 Vue 3、React 相同的格式插件。
10
10
 
11
- 本文档对应 **0.1.0**。以下命令展示 npm 发布后的消费方式;从当前源码工作区使用时,请先按接入指南构建各包。
11
+ 本文档对应 **0.1.1**。以下命令展示 npm 发布后的消费方式;从当前源码工作区使用时,请先按接入指南构建各包。
12
12
 
13
13
  ## 主要能力
14
14
 
@@ -112,7 +112,7 @@ peerDependencies 为 vue ^2.6.14 || ^2.7.16。组件 mounted 时创建,beforeD
112
112
  | ------------------------------------------------------------------ | -------------------------------------------- | ----------------------------------------------------------------------------------------------- |
113
113
  | [@filumo/core](https://www.npmjs.com/package/@filumo/core) | 无 UI 的来源、插件协议、会话和公共文本处理 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/core/README.zh-CN.md) |
114
114
  | [@filumo/dom](https://www.npmjs.com/package/@filumo/dom) | 原生 DOM 查看器、工具栏、原文、大纲和共享 UI | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/dom/README.zh-CN.md) |
115
- | [@filumo/viewer](https://www.npmjs.com/package/@filumo/viewer) | 九类格式插件的标准预设与工厂聚合 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/viewer/README.zh-CN.md) |
115
+ | [@filumo/viewer](https://www.npmjs.com/package/@filumo/viewer) | 十类格式插件的标准预设与工厂聚合 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/viewer/README.zh-CN.md) |
116
116
  | [@filumo/office](https://www.npmjs.com/package/@filumo/office) | Word、Excel、PowerPoint 与受支持的旧格式 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/office/README.zh-CN.md) |
117
117
  | [@filumo/pdf](https://www.npmjs.com/package/@filumo/pdf) | PDF 连续阅读、大纲、缩略图和查找 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/pdf/README.zh-CN.md) |
118
118
  | [@filumo/image](https://www.npmjs.com/package/@filumo/image) | 图片预览、缩放、旋转、拖动及共享弹层 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/image/README.zh-CN.md) |
@@ -125,6 +125,7 @@ peerDependencies 为 vue ^2.6.14 || ^2.7.16。组件 mounted 时创建,beforeD
125
125
  | [@filumo/react](https://www.npmjs.com/package/@filumo/react) | React 18/19 适配组件 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/react/README.zh-CN.md) |
126
126
  | [@filumo/vue](https://www.npmjs.com/package/@filumo/vue) | Vue 3(>=3.3 <4)适配组件 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/vue/README.zh-CN.md) |
127
127
  | **[@filumo/vue2](https://www.npmjs.com/package/@filumo/vue2)** | Vue 2(^2.6.14 或 ^2.7.16)适配组件 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/vue2/README.zh-CN.md) |
128
+ | [@filumo/archive](https://www.npmjs.com/package/@filumo/archive) | 压缩包目录、按需提取与包内预览 | [README](https://github.com/gyxing/filumo-viewer/blob/master/packages/archive/README.zh-CN.md) |
128
129
 
129
130
  <!-- filumo-packages:end -->
130
131
 
@@ -139,3 +140,21 @@ peerDependencies 为 vue ^2.6.14 || ^2.7.16。组件 mounted 时创建,beforeD
139
140
  - [项目变更记录](https://github.com/gyxing/filumo-viewer/blob/master/CHANGELOG.md)
140
141
  - [问题反馈](https://github.com/gyxing/filumo-viewer/issues)
141
142
  - [MIT 许可证](https://github.com/gyxing/filumo-viewer/blob/master/packages/vue2/LICENSE)
143
+
144
+ ## 自定义工具栏图标
145
+
146
+ 从本包导入 `ToolbarAction`,`icon` 使用 `(h, context) => VNode | null` 渲染函数,也支持原生 `ToolbarIcon`。每个位置独立创建 VNode。
147
+
148
+ ```ts
149
+ const actions = [
150
+ {
151
+ id: 'host.retry',
152
+ label: '重新生成',
153
+ kind: 'action',
154
+ icon: (h) => h('i', { class: 'el-icon-refresh' }),
155
+ run: retry,
156
+ },
157
+ ];
158
+ ```
159
+
160
+ 将数组放入 `options.toolbarActions`。图标由关联查看器父实例的轻量子组件渲染,继承宿主注入,响应式依赖在子组件渲染时收集。移除与销毁执行 `$destroy()` 并清理节点。`undefined` 沿用默认图标,`null` 隐藏。公开 `ToolbarIconRenderer` 及框架侧配置、update 类型,`getCapabilities()` 返回归一化后的 DOM 能力。
@@ -1,6 +1,6 @@
1
1
  import type { DocumentInput, DocumentOpenOptions } from '@filumo/core';
2
- import type { ViewOptions, ViewerConfiguration } from '@filumo/dom';
3
2
  import Vue from 'vue';
3
+ import type { ViewOptions, ViewerConfiguration } from './toolbarIcons';
4
4
  /** Vue 2 使用 Options API 适配同一 DOM 查看器,兼容 2.6/2.7。 */
5
5
  export declare const DocumentViewer: import("vue/types/vue").ExtendedVue<Vue<Record<string, any>, Record<string, any>, never, never, (event: string, ...args: any[]) => Vue<Record<string, any>, Record<string, any>, never, never, any>>, unknown, {
6
6
  mountViewer(): Promise<void>;
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
3
  "package": "@filumo/vue2",
4
- "version": "0.1.0",
4
+ "version": "0.1.1",
5
5
  "outputs": [
6
6
  {
7
7
  "file": "index.js",
8
8
  "entryPoint": "src/index.ts",
9
9
  "inputs": [
10
- "src/DocumentViewer.ts"
10
+ "src/DocumentViewer.ts",
11
+ "src/toolbarIcons.ts"
11
12
  ],
12
13
  "imports": [
13
14
  {
@@ -20,6 +21,11 @@
20
21
  "kind": "import-statement",
21
22
  "external": true
22
23
  },
24
+ {
25
+ "path": "vue",
26
+ "kind": "import-statement",
27
+ "external": true
28
+ },
23
29
  {
24
30
  "path": "vue",
25
31
  "kind": "import-statement",
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export type { DocumentInput } from '@filumo/core';
2
- export type { ViewOptions, ViewerCapabilities, ViewerConfiguration, ViewerHandle, ViewerOptions, ViewerPlugin, } from '@filumo/dom';
2
+ export type { ToolbarActionState, ToolbarIcon, ToolbarIconContext, ToolbarIconInstance, ViewerCapabilities, ViewerPlugin, } from '@filumo/dom';
3
3
  export { DocumentViewer } from './DocumentViewer';
4
+ export type { ToolbarAction, ToolbarIconRenderer, ViewOptions, ViewerConfiguration, ViewerHandle, ViewerOptions, } from './toolbarIcons';
package/dist/index.js CHANGED
@@ -1,7 +1,88 @@
1
1
  // packages/vue2/src/DocumentViewer.ts
2
2
  import { notify } from "@filumo/core";
3
3
  import { createViewer } from "@filumo/dom";
4
+ import Vue2 from "vue";
5
+
6
+ // packages/vue2/src/toolbarIcons.ts
4
7
  import Vue from "vue";
8
+ function createToolbarIcons(owner) {
9
+ const records = /* @__PURE__ */ new Map();
10
+ const children = /* @__PURE__ */ new Set();
11
+ const convert = (options) => {
12
+ if (options.toolbarActions === void 0)
13
+ return options;
14
+ const wanted = /* @__PURE__ */ new Set();
15
+ const toolbarActions = options.toolbarActions.map(
16
+ (action) => {
17
+ if (typeof action.icon !== "function")
18
+ return { ...action, icon: action.icon };
19
+ wanted.add(action.id);
20
+ let record = records.get(action.id);
21
+ if (!record) {
22
+ const created = {
23
+ render: action.icon,
24
+ children: /* @__PURE__ */ new Set(),
25
+ icon: {
26
+ mount(container, context) {
27
+ let current = context;
28
+ const child = new Vue({
29
+ parent: owner,
30
+ render: (h) => created.render(h, current) ?? h("span")
31
+ });
32
+ try {
33
+ child.$mount();
34
+ container.appendChild(child.$el);
35
+ } catch (error) {
36
+ child.$destroy();
37
+ child.$el?.parentNode?.removeChild(child.$el);
38
+ throw error;
39
+ }
40
+ children.add(child);
41
+ created.children.add(child);
42
+ return {
43
+ update(next) {
44
+ current = next;
45
+ child.$forceUpdate();
46
+ },
47
+ dispose() {
48
+ created.children.delete(child);
49
+ if (children.delete(child))
50
+ child.$destroy();
51
+ child.$el.parentNode?.removeChild(child.$el);
52
+ }
53
+ };
54
+ }
55
+ }
56
+ };
57
+ records.set(action.id, created);
58
+ record = created;
59
+ } else if (record.render !== action.icon) {
60
+ record.render = action.icon;
61
+ for (const child of record.children)
62
+ child.$forceUpdate();
63
+ }
64
+ return { ...action, icon: record.icon };
65
+ }
66
+ );
67
+ for (const id of records.keys())
68
+ if (!wanted.has(id))
69
+ records.delete(id);
70
+ return { ...options, toolbarActions };
71
+ };
72
+ return {
73
+ convert,
74
+ dispose() {
75
+ for (const child of children) {
76
+ child.$destroy();
77
+ child.$el.parentNode?.removeChild(child.$el);
78
+ }
79
+ children.clear();
80
+ records.clear();
81
+ }
82
+ };
83
+ }
84
+
85
+ // packages/vue2/src/DocumentViewer.ts
5
86
  var states = /* @__PURE__ */ new WeakMap();
6
87
  function getState(instance) {
7
88
  let state = states.get(instance);
@@ -11,13 +92,14 @@ function getState(instance) {
11
92
  closed: false,
12
93
  active: true,
13
94
  listeners: /* @__PURE__ */ new Set(),
14
- capabilityListeners: /* @__PURE__ */ new Set()
95
+ capabilityListeners: /* @__PURE__ */ new Set(),
96
+ icons: createToolbarIcons(instance)
15
97
  };
16
98
  states.set(instance, state);
17
99
  }
18
100
  return state;
19
101
  }
20
- var DocumentViewer = Vue.extend({
102
+ var DocumentViewer = Vue2.extend({
21
103
  name: "FilumoDocumentViewer",
22
104
  props: {
23
105
  source: {
@@ -48,6 +130,7 @@ var DocumentViewer = Vue.extend({
48
130
  beforeDestroy() {
49
131
  const state = getState(this);
50
132
  state.closed = true;
133
+ state.icons.dispose();
51
134
  state.listeners.clear();
52
135
  state.capabilityListeners.clear();
53
136
  state.generation++;
@@ -80,7 +163,7 @@ var DocumentViewer = Vue.extend({
80
163
  );
81
164
  return;
82
165
  }
83
- state.viewer?.update(value);
166
+ state.viewer?.update(state.icons.convert(value));
84
167
  }
85
168
  }
86
169
  },
@@ -99,7 +182,7 @@ var DocumentViewer = Vue.extend({
99
182
  this.options.stylePolicy
100
183
  ]);
101
184
  const viewer = createViewer(this.$el, {
102
- ...this.options,
185
+ ...state.icons.convert(this.options),
103
186
  plugins: this.plugins,
104
187
  onReady: (session) => this.$emit("ready", session),
105
188
  onCapabilitiesChange: (capabilities) => {
@@ -125,7 +208,8 @@ var DocumentViewer = Vue.extend({
125
208
  return getState(this).viewer?.open(input, selection) ?? Promise.reject(new Error("\u67E5\u770B\u5668\u5C1A\u672A\u6302\u8F7D"));
126
209
  },
127
210
  update(options) {
128
- getState(this).viewer?.update(options);
211
+ const state = getState(this);
212
+ state.viewer?.update(state.icons.convert(options));
129
213
  },
130
214
  getSnapshot() {
131
215
  return getState(this).viewer?.getSnapshot() ?? { status: "idle" };
package/dist/styles.css CHANGED
@@ -1 +1 @@
1
- :root { --filumo-style-vue2: 0.1.0; }
1
+ :root { --filumo-style-vue2: 0.1.1; }
@@ -0,0 +1,21 @@
1
+ import type { CapabilityAction, ViewerConfiguration as DomConfiguration, ViewerHandle as DomHandle, ViewerOptions as DomOptions, ViewOptions as DomViewOptions, ToolbarIcon, ToolbarIconContext } from '@filumo/dom';
2
+ import type { CreateElement, VNode } from 'vue';
3
+ import Vue from 'vue';
4
+ /** Vue 2 每个位置独立调用渲染函数,支持组件、SVG 和图标字体。 */
5
+ export type ToolbarIconRenderer = (h: CreateElement, context: ToolbarIconContext) => VNode | null;
6
+ export type ToolbarAction = Omit<CapabilityAction, 'icon'> & {
7
+ icon?: ToolbarIconRenderer | ToolbarIcon | null;
8
+ };
9
+ export type ViewOptions = Omit<DomViewOptions, 'toolbarActions'> & {
10
+ toolbarActions?: readonly ToolbarAction[];
11
+ };
12
+ export type ViewerConfiguration = Omit<DomConfiguration, 'toolbarActions'> & ViewOptions;
13
+ export type ViewerOptions = Omit<DomOptions, 'toolbarActions'> & ViewOptions;
14
+ export type ViewerHandle = Omit<DomHandle, 'update'> & {
15
+ update(options: ViewOptions): void;
16
+ };
17
+ /** 子组件关联查看器实例,继承宿主注入并通过生命周期释放渲染资源。 */
18
+ export declare function createToolbarIcons(owner: Vue): {
19
+ convert: (options: ViewerConfiguration) => DomConfiguration;
20
+ dispose(): void;
21
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@filumo/vue2",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Vue 2 document viewer adapter for Filumo, with Options API integration, plugin-based formats and managed lifecycle cleanup.",
5
5
  "keywords": [
6
6
  "filumo",
@@ -23,22 +23,19 @@
23
23
  "vue2文档预览"
24
24
  ],
25
25
  "homepage": "https://github.com/gyxing/filumo-viewer/tree/master/packages/vue2#readme",
26
+ "bugs": {
27
+ "url": "https://github.com/gyxing/filumo-viewer/issues"
28
+ },
26
29
  "repository": {
27
30
  "type": "git",
28
31
  "url": "git+https://github.com/gyxing/filumo-viewer.git",
29
32
  "directory": "packages/vue2"
30
33
  },
31
- "bugs": {
32
- "url": "https://github.com/gyxing/filumo-viewer/issues"
33
- },
34
+ "license": "MIT",
34
35
  "author": {
35
36
  "name": "gyxing",
36
37
  "url": "https://github.com/gyxing"
37
38
  },
38
- "license": "MIT",
39
- "publishConfig": {
40
- "access": "public"
41
- },
42
39
  "sideEffects": [
43
40
  "**/styles/**",
44
41
  "**/*.css"
@@ -60,13 +57,16 @@
60
57
  "README.zh-CN.md"
61
58
  ],
62
59
  "dependencies": {
63
- "@filumo/dom": "^0.1.0",
64
- "@filumo/core": "^0.1.0"
60
+ "@filumo/dom": "^0.1.1",
61
+ "@filumo/core": "^0.1.1"
65
62
  },
66
63
  "devDependencies": {
67
64
  "vue": "2.7.16"
68
65
  },
69
66
  "peerDependencies": {
70
67
  "vue": "^2.6.14 || ^2.7.16"
68
+ },
69
+ "publishConfig": {
70
+ "access": "public"
71
71
  }
72
72
  }