hyperapp-is 0.1.50 → 0.2.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 +220 -1557
- package/dist/{hyperapp-is/animation → animation}/easing.d.ts +4 -0
- package/dist/{hyperapp-is/animation → animation}/easing.js +4 -4
- package/dist/{hyperapp-is/animation → animation}/properties.d.ts +9 -16
- package/dist/{hyperapp-is/animation → animation}/properties.js +13 -12
- package/dist/{hyperapp-is/animation → animation}/raf.d.ts +11 -12
- package/dist/animation/raf.js +192 -0
- package/dist/core/component.d.ts +23 -0
- package/dist/core/component.js +52 -0
- package/dist/core/effects.d.ts +10 -0
- package/dist/core/effects.js +34 -0
- package/dist/core/state.d.ts +21 -0
- package/dist/{hyperapp-is/core → core}/state.js +15 -20
- package/dist/dom/dialog.d.ts +6 -0
- package/dist/dom/dialog.js +85 -0
- package/dist/dom/utils.d.ts +15 -0
- package/dist/dom/utils.js +19 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +10 -0
- package/dist/services/google.d.ts +69 -0
- package/dist/services/google.js +170 -0
- package/package.json +13 -39
- package/dist/hyperapp-is/animation/raf.js +0 -209
- package/dist/hyperapp-is/animationView/carousel.d.ts +0 -48
- package/dist/hyperapp-is/animationView/carousel.js +0 -461
- package/dist/hyperapp-is/core/component.d.ts +0 -65
- package/dist/hyperapp-is/core/component.js +0 -242
- package/dist/hyperapp-is/core/navigator.d.ts +0 -115
- package/dist/hyperapp-is/core/navigator.js +0 -615
- package/dist/hyperapp-is/core/state.d.ts +0 -27
- package/dist/hyperapp-is/dom/utils.d.ts +0 -37
- package/dist/hyperapp-is/dom/utils.js +0 -69
- package/dist/hyperapp-is/index.d.ts +0 -16
- package/dist/hyperapp-is/index.js +0 -10
- package/dist/hyperapp-is/services/google.d.ts +0 -89
- package/dist/hyperapp-is/services/google.js +0 -178
|
@@ -1,615 +0,0 @@
|
|
|
1
|
-
// hyperapp-is / core / navigator.ts
|
|
2
|
-
import { getValue, setValue, getLocalState, setLocalState, createLocalKey, } from "./state";
|
|
3
|
-
import { HistoryInput } from "./component";
|
|
4
|
-
import { getScrollMargin } from "../dom/utils";
|
|
5
|
-
import { el, deleteKeys, SelectButton } from "./component";
|
|
6
|
-
// ---------- ---------- ---------- ---------- ----------
|
|
7
|
-
// convertJsonToNavigatorItem
|
|
8
|
-
// ---------- ---------- ---------- ---------- ----------
|
|
9
|
-
export const convertJsonToNavigatorItem = function (props) {
|
|
10
|
-
const { parent, name, data, getEntries, isNode, depth = 0, extension } = props;
|
|
11
|
-
const result = {
|
|
12
|
-
parent,
|
|
13
|
-
name,
|
|
14
|
-
path: parent ? parent.path + "/" + name : "/" + name
|
|
15
|
-
};
|
|
16
|
-
if (extension) {
|
|
17
|
-
const ext = extension(result, data, depth);
|
|
18
|
-
if (ext)
|
|
19
|
-
result.extension = ext;
|
|
20
|
-
}
|
|
21
|
-
let properties = {};
|
|
22
|
-
let hasProperties = false;
|
|
23
|
-
const children = [];
|
|
24
|
-
getEntries(data, depth).forEach(entry => {
|
|
25
|
-
const isProperty = typeof entry.data !== "object" || Array.isArray(entry.data);
|
|
26
|
-
if (isProperty) {
|
|
27
|
-
properties[entry.name] = entry.data;
|
|
28
|
-
hasProperties = true;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
children.push(convertJsonToNavigatorItem({
|
|
32
|
-
parent: result,
|
|
33
|
-
name: entry.name,
|
|
34
|
-
data: entry.data,
|
|
35
|
-
getEntries,
|
|
36
|
-
isNode: entry.isNode,
|
|
37
|
-
depth: depth + 1,
|
|
38
|
-
extension
|
|
39
|
-
}));
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
if (hasProperties)
|
|
43
|
-
result.properties = properties;
|
|
44
|
-
if (isNode)
|
|
45
|
-
result.children = children;
|
|
46
|
-
return result;
|
|
47
|
-
};
|
|
48
|
-
// ---------- ---------- ---------- ---------- ----------
|
|
49
|
-
// getParentItems
|
|
50
|
-
// ---------- ---------- ---------- ---------- ----------
|
|
51
|
-
export const getParentItems = (item) => {
|
|
52
|
-
if (!item)
|
|
53
|
-
return [];
|
|
54
|
-
const result = [];
|
|
55
|
-
let cd = item.parent;
|
|
56
|
-
while (cd) {
|
|
57
|
-
result.push(cd);
|
|
58
|
-
cd = cd.parent;
|
|
59
|
-
}
|
|
60
|
-
return result.reverse();
|
|
61
|
-
};
|
|
62
|
-
// ---------- ---------- ---------- ---------- ----------
|
|
63
|
-
// vnodes
|
|
64
|
-
// ---------- ---------- ---------- ---------- ----------
|
|
65
|
-
const div = el("div");
|
|
66
|
-
const table = el("table");
|
|
67
|
-
const thead = el("thead");
|
|
68
|
-
const tbody = el("tbody");
|
|
69
|
-
const tr = el("tr");
|
|
70
|
-
const th = el("th");
|
|
71
|
-
const td = el("td");
|
|
72
|
-
const ol = el("ol");
|
|
73
|
-
const ul = el("ul");
|
|
74
|
-
const li = el("li");
|
|
75
|
-
const button = el("button");
|
|
76
|
-
const input = el("input");
|
|
77
|
-
const span = el("span");
|
|
78
|
-
const svg = el("svg");
|
|
79
|
-
const rect = el("rect");
|
|
80
|
-
const path = el("path");
|
|
81
|
-
// ---------- ---------- ---------- ---------- ----------
|
|
82
|
-
// NavigatorFinder Component
|
|
83
|
-
// ---------- ---------- ---------- ---------- ----------
|
|
84
|
-
/**
|
|
85
|
-
* ファインダー
|
|
86
|
-
*
|
|
87
|
-
* - 必須項目
|
|
88
|
-
* state, id, currentKeys
|
|
89
|
-
*
|
|
90
|
-
* - 拡張項目
|
|
91
|
-
* columns, plugIn, afterRender
|
|
92
|
-
*
|
|
93
|
-
* - columns
|
|
94
|
-
* カラムの表示設定
|
|
95
|
-
*
|
|
96
|
-
* - plugIn
|
|
97
|
-
* プラグインの追加
|
|
98
|
-
*
|
|
99
|
-
* - afterRender
|
|
100
|
-
* レンダーフック
|
|
101
|
-
*/
|
|
102
|
-
export const NavigatorFinder = function (props) {
|
|
103
|
-
var _a, _b;
|
|
104
|
-
const { state, id, currentKeys, plugIn, afterRender } = props;
|
|
105
|
-
// current
|
|
106
|
-
const current = getValue(state, currentKeys, undefined);
|
|
107
|
-
// localState
|
|
108
|
-
const localState = getLocalState(state, id, {
|
|
109
|
-
searchText: "", // 検索テキスト
|
|
110
|
-
selected: [], // 選択されているボタン名
|
|
111
|
-
sortType: undefined, // ソート用比較関数: (a: NavigatorItem, b: NavigatorItem) => number
|
|
112
|
-
reverse: false, // ソートを逆順にするか
|
|
113
|
-
sortKey: undefined // 使用されているソート名 (column.name)
|
|
114
|
-
});
|
|
115
|
-
// selected filter
|
|
116
|
-
const isFilter = localState.selected.includes(`${createLocalKey(id)}_filter`);
|
|
117
|
-
// ---------- ---------- ----------
|
|
118
|
-
// createColumns
|
|
119
|
-
// ---------- ---------- ----------
|
|
120
|
-
const createColumns = (_a = props.columns) !== null && _a !== void 0 ? _a : ((directory) => {
|
|
121
|
-
const result = [];
|
|
122
|
-
if (!directory)
|
|
123
|
-
return result;
|
|
124
|
-
result.push({
|
|
125
|
-
name: "name",
|
|
126
|
-
val: (item) => item.name,
|
|
127
|
-
compare: (a, b) => {
|
|
128
|
-
return a.name.localeCompare(b.name);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
const children = directory.children;
|
|
132
|
-
if (children) {
|
|
133
|
-
const names = [];
|
|
134
|
-
// 子アイテムのプロパティをすべて抽出
|
|
135
|
-
children.forEach(child => {
|
|
136
|
-
if (child.properties) {
|
|
137
|
-
Object.keys(child.properties).forEach(key => names.push(key));
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
// add NavigatorColumn
|
|
141
|
-
Array.from(new Set(names)).forEach(name => {
|
|
142
|
-
result.push({
|
|
143
|
-
name,
|
|
144
|
-
val: (item) => {
|
|
145
|
-
var _a;
|
|
146
|
-
const p = item.properties;
|
|
147
|
-
return p
|
|
148
|
-
? (_a = p[name]) !== null && _a !== void 0 ? _a : ""
|
|
149
|
-
: "";
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
return result;
|
|
155
|
-
}); // end createColumns
|
|
156
|
-
// columns
|
|
157
|
-
const columns = createColumns(current);
|
|
158
|
-
// parentItems
|
|
159
|
-
const parentItems = getParentItems(current);
|
|
160
|
-
if (current)
|
|
161
|
-
parentItems.push(current);
|
|
162
|
-
// ---------- ---------- ----------
|
|
163
|
-
// hitTest
|
|
164
|
-
// ---------- ---------- ----------
|
|
165
|
-
const hitTest = (text) => {
|
|
166
|
-
if (typeof text !== "string")
|
|
167
|
-
return false;
|
|
168
|
-
const S = localState.searchText.trim().toLowerCase();
|
|
169
|
-
if (S === "")
|
|
170
|
-
return false;
|
|
171
|
-
const keys = S.replace(/[ ]+/g, " ").split(" ").filter(Boolean);
|
|
172
|
-
if (keys.length === 0)
|
|
173
|
-
return false;
|
|
174
|
-
const sText = text.toLowerCase();
|
|
175
|
-
return keys.every(key => sText.includes(key));
|
|
176
|
-
}; // end hitTest
|
|
177
|
-
// ---------- ---------- ----------
|
|
178
|
-
// getItems
|
|
179
|
-
// ---------- ---------- ----------
|
|
180
|
-
const getItems = (item) => {
|
|
181
|
-
if (!item || item.children === undefined)
|
|
182
|
-
return [];
|
|
183
|
-
// filter
|
|
184
|
-
const result = isFilter && localState.searchText !== ""
|
|
185
|
-
? item.children.filter(child => {
|
|
186
|
-
return columns.some(col => hitTest(col.text ? col.text(child) : col.val(child)));
|
|
187
|
-
})
|
|
188
|
-
: item.children;
|
|
189
|
-
return result;
|
|
190
|
-
}; // end getItems
|
|
191
|
-
// items
|
|
192
|
-
const items = getItems(current);
|
|
193
|
-
// sort
|
|
194
|
-
if (localState.sortType) {
|
|
195
|
-
items.sort(localState.sortType);
|
|
196
|
-
if (localState.reverse)
|
|
197
|
-
items.reverse();
|
|
198
|
-
}
|
|
199
|
-
// items count
|
|
200
|
-
const count = current
|
|
201
|
-
? (_b = current.children) === null || _b === void 0 ? void 0 : _b.length
|
|
202
|
-
: 0;
|
|
203
|
-
// items hitCount
|
|
204
|
-
const hitCount = isFilter
|
|
205
|
-
? items.length
|
|
206
|
-
: items.filter(item => columns.some(col => hitTest(col.text ? col.text(item) : col.val(item)))).length;
|
|
207
|
-
// message
|
|
208
|
-
const message = `hit items = ${hitCount} / ${count}`;
|
|
209
|
-
// ---------- ---------- ----------
|
|
210
|
-
// action_parentClick
|
|
211
|
-
// ---------- ---------- ----------
|
|
212
|
-
const action_parentClick = (state, item) => {
|
|
213
|
-
return setLocalState(setValue(state, currentKeys, item), id, {
|
|
214
|
-
selected: []
|
|
215
|
-
});
|
|
216
|
-
};
|
|
217
|
-
// ---------- ---------- ----------
|
|
218
|
-
// action_itemClick
|
|
219
|
-
// ---------- ---------- ----------
|
|
220
|
-
const action_itemClick = (state, item) => {
|
|
221
|
-
// 子アイテムがすべてプロパティのときは移動しない
|
|
222
|
-
const children = item.children;
|
|
223
|
-
if (!children || children.length === 0)
|
|
224
|
-
return state;
|
|
225
|
-
// filterは解除
|
|
226
|
-
return setLocalState(setValue(state, currentKeys, item), id, {
|
|
227
|
-
selected: []
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
// ---------- ---------- ----------
|
|
231
|
-
// action_inputSearchText
|
|
232
|
-
// ---------- ---------- ----------
|
|
233
|
-
const action_inputSearchText = (state, e) => {
|
|
234
|
-
const input = e.currentTarget;
|
|
235
|
-
if (!input)
|
|
236
|
-
return state;
|
|
237
|
-
return setLocalState(state, id, {
|
|
238
|
-
searchText: input.value
|
|
239
|
-
});
|
|
240
|
-
}; // end action_inputSearchText
|
|
241
|
-
// ---------- ---------- ----------
|
|
242
|
-
// action_sort
|
|
243
|
-
// ---------- ---------- ----------
|
|
244
|
-
const action_sort = (state, column) => {
|
|
245
|
-
if (column.compare === undefined)
|
|
246
|
-
return state;
|
|
247
|
-
return setLocalState(state, id, {
|
|
248
|
-
sortType: column.compare,
|
|
249
|
-
reverse: localState.sortKey === column.name ? !localState.reverse : false,
|
|
250
|
-
sortKey: column.name
|
|
251
|
-
});
|
|
252
|
-
}; // end action_sort
|
|
253
|
-
// ---------- ---------- ----------
|
|
254
|
-
// VNode
|
|
255
|
-
// ---------- ---------- ----------
|
|
256
|
-
// toolBarNode
|
|
257
|
-
const toolBarNode = div({
|
|
258
|
-
class: "toolBar"
|
|
259
|
-
}, HistoryInput({
|
|
260
|
-
state,
|
|
261
|
-
id: `${id}_searchText`,
|
|
262
|
-
keyNames: [createLocalKey(id), "searchText"],
|
|
263
|
-
placeholder: "search keys",
|
|
264
|
-
oninput: action_inputSearchText
|
|
265
|
-
}), button({
|
|
266
|
-
type: "button",
|
|
267
|
-
title: "delete keys",
|
|
268
|
-
onclick: (state) => {
|
|
269
|
-
return setLocalState(state, id, {
|
|
270
|
-
searchText: ""
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
}, icon_trashBox), SelectButton({
|
|
274
|
-
state: state,
|
|
275
|
-
id: `${createLocalKey(id)}_filter`,
|
|
276
|
-
keyNames: [createLocalKey(id), "selected"],
|
|
277
|
-
title: "filter"
|
|
278
|
-
}, icon_filter));
|
|
279
|
-
// parentItemsNode
|
|
280
|
-
const parentItemsNode = div({
|
|
281
|
-
class: "parentItems"
|
|
282
|
-
}, ol({}, parentItems.map(parent => li({
|
|
283
|
-
key: parent.path,
|
|
284
|
-
onclick: [action_parentClick, parent]
|
|
285
|
-
}, parent.name))));
|
|
286
|
-
// itemsNode
|
|
287
|
-
const itemsNode = div({
|
|
288
|
-
class: "items"
|
|
289
|
-
}, table({}, thead({}, tr({}, columns.map(col => th({
|
|
290
|
-
class: col.compare ? "sort" : "",
|
|
291
|
-
onclick: [action_sort, col]
|
|
292
|
-
}, col.name + (localState.sortKey === col.name
|
|
293
|
-
? (localState.reverse ? " ▼" : " ▲")
|
|
294
|
-
: ""))))), tbody({}, items.map(item => tr({
|
|
295
|
-
key: item.path,
|
|
296
|
-
class: item.children === undefined
|
|
297
|
-
? "file"
|
|
298
|
-
: "directory",
|
|
299
|
-
onclick: item.children === undefined
|
|
300
|
-
? undefined
|
|
301
|
-
: [action_itemClick, item]
|
|
302
|
-
}, columns.map(col => {
|
|
303
|
-
const v = col.val(item);
|
|
304
|
-
const t = col.text ? col.text(item) : typeof v === "string" ? v : "";
|
|
305
|
-
return td({
|
|
306
|
-
title: t
|
|
307
|
-
}, span({
|
|
308
|
-
class: hitTest(t) ? "hit" : ""
|
|
309
|
-
}, v));
|
|
310
|
-
}))))));
|
|
311
|
-
// statusBarNode
|
|
312
|
-
const statusBarNode = div({ class: "statusBar" }, message);
|
|
313
|
-
// vnode
|
|
314
|
-
const vnode = div({
|
|
315
|
-
...deleteKeys(props, "state", "currentKeys", "columns", "plugIn", "toolBarNode", "parentItemsNode", "statusBarNode", "afterRender")
|
|
316
|
-
}, div({
|
|
317
|
-
class: "rapper"
|
|
318
|
-
}, props.toolBarNode ? props.toolBarNode(state, localState, toolBarNode) : toolBarNode, props.parentItemsNode ? props.parentItemsNode(state, localState, parentItemsNode) : parentItemsNode, itemsNode, props.statusBarNode ? props.statuBarNode(state, localState, statusBarNode) : statusBarNode),
|
|
319
|
-
// plugIn
|
|
320
|
-
plugIn
|
|
321
|
-
? plugIn(state, localState)
|
|
322
|
-
: []);
|
|
323
|
-
// ---------- ---------- ----------
|
|
324
|
-
// afterRender
|
|
325
|
-
// ---------- ---------- ----------
|
|
326
|
-
return afterRender ? afterRender(state, localState, vnode) : vnode;
|
|
327
|
-
};
|
|
328
|
-
// ---------- ---------- ---------- ---------- ----------
|
|
329
|
-
// svg icon
|
|
330
|
-
// ---------- ---------- ---------- ---------- ----------
|
|
331
|
-
// icon_depth
|
|
332
|
-
export const icon_depth = svg({
|
|
333
|
-
width: 24,
|
|
334
|
-
height: 24,
|
|
335
|
-
viewBox: "0 0 24 24",
|
|
336
|
-
fill: "none",
|
|
337
|
-
stroke: "currentColor",
|
|
338
|
-
strokeWidth: 2,
|
|
339
|
-
strokeLinecap: "round",
|
|
340
|
-
strokeLinejoin: "round"
|
|
341
|
-
}, rect({
|
|
342
|
-
x: 9,
|
|
343
|
-
y: 3,
|
|
344
|
-
width: 6,
|
|
345
|
-
height: 4,
|
|
346
|
-
rx: 1
|
|
347
|
-
}), rect({
|
|
348
|
-
x: 3,
|
|
349
|
-
y: 15,
|
|
350
|
-
width: 6,
|
|
351
|
-
height: 4,
|
|
352
|
-
rx: 1
|
|
353
|
-
}), rect({
|
|
354
|
-
x: 15,
|
|
355
|
-
y: 15,
|
|
356
|
-
width: 6,
|
|
357
|
-
height: 4,
|
|
358
|
-
rx: 1
|
|
359
|
-
}), path({
|
|
360
|
-
d: "M12 7v4"
|
|
361
|
-
}), path({
|
|
362
|
-
d: "M6 15v-4h12v4"
|
|
363
|
-
}));
|
|
364
|
-
// icon_name
|
|
365
|
-
export const icon_name = svg({
|
|
366
|
-
width: 24,
|
|
367
|
-
height: 24,
|
|
368
|
-
viewBox: "0 0 24 24",
|
|
369
|
-
fill: "none",
|
|
370
|
-
stroke: "currentColor",
|
|
371
|
-
strokeWidth: 2,
|
|
372
|
-
strokeLinecap: "round",
|
|
373
|
-
strokeLinejoin: "round"
|
|
374
|
-
}, path({ d: "M4 18l2-8 2 8M5 14h2" }), path({ d: "M10 10h6l-6 8h6" }), path({ d: "M20 6v12" }), path({ d: "M17 15l3 3 3-3" }));
|
|
375
|
-
// icon_directory
|
|
376
|
-
export const icon_directory = svg({
|
|
377
|
-
width: 24,
|
|
378
|
-
height: 24,
|
|
379
|
-
viewBox: "0 0 24 24",
|
|
380
|
-
fill: "none",
|
|
381
|
-
stroke: "currentColor",
|
|
382
|
-
strokeWidth: 2,
|
|
383
|
-
strokeLinecap: "round",
|
|
384
|
-
strokeLinejoin: "round"
|
|
385
|
-
}, path({ d: "M3 7h6l2 2h10v8a2 2 0 0 1-2 2H3z" }));
|
|
386
|
-
// icon_file
|
|
387
|
-
export const icon_file = svg({
|
|
388
|
-
width: 24,
|
|
389
|
-
height: 24,
|
|
390
|
-
viewBox: "0 0 24 24",
|
|
391
|
-
fill: "none",
|
|
392
|
-
stroke: "currentColor",
|
|
393
|
-
strokeWidth: 2,
|
|
394
|
-
strokeLinecap: "round",
|
|
395
|
-
strokeLinejoin: "round"
|
|
396
|
-
}, path({ d: "M6 2h9l5 5v15a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z" }), path({ d: "M14 2v6h6" }));
|
|
397
|
-
// icon_trashBox
|
|
398
|
-
export const icon_trashBox = svg({
|
|
399
|
-
viewBox: "0 0 24 24",
|
|
400
|
-
width: 24,
|
|
401
|
-
height: 24,
|
|
402
|
-
fill: "none",
|
|
403
|
-
stroke: "currentColor",
|
|
404
|
-
strokeWidth: 2,
|
|
405
|
-
strokeLinecap: "round",
|
|
406
|
-
strokeLinejoin: "round"
|
|
407
|
-
}, path({ d: "M3 6h18" }), path({ d: "M8 6V4h8v2" }), path({ d: "M6 6l1 14h10l1-14" }), path({ d: "M10 11v6" }), path({ d: "M14 11v6" }));
|
|
408
|
-
// icon_filter
|
|
409
|
-
export const icon_filter = svg({
|
|
410
|
-
viewBox: "0 0 24 24",
|
|
411
|
-
width: 24,
|
|
412
|
-
height: 24,
|
|
413
|
-
fill: "none",
|
|
414
|
-
stroke: "currentColor",
|
|
415
|
-
strokeWidth: 2,
|
|
416
|
-
strokeLinecap: "round",
|
|
417
|
-
strokeLinejoin: "round"
|
|
418
|
-
}, path({ d: "M3 5h18" }), path({ d: "M6 12h12" }), path({ d: "M10 19h4" }));
|
|
419
|
-
// icon_copy
|
|
420
|
-
export const icon_copy = svg({
|
|
421
|
-
viewBox: "0 0 24 24",
|
|
422
|
-
width: 24,
|
|
423
|
-
height: 24,
|
|
424
|
-
fill: "none",
|
|
425
|
-
stroke: "currentColor",
|
|
426
|
-
strokeWidth: 2,
|
|
427
|
-
strokeLinecap: "round",
|
|
428
|
-
strokeLinejoin: "round"
|
|
429
|
-
}, path({ d: "M9 9h11v11H9z" }), path({ d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" }));
|
|
430
|
-
// ---------- ---------- ---------- ---------- ----------
|
|
431
|
-
// NavigatorSearch Component (NavigatorFinder plugIn)
|
|
432
|
-
// ---------- ---------- ---------- ---------- ----------
|
|
433
|
-
/**
|
|
434
|
-
* ファイルサーチ - NavigatorFinder プラグイン
|
|
435
|
-
*
|
|
436
|
-
* - 必須項目
|
|
437
|
-
* state, id, currentKeys, searchResult, hitTest, maxItemsCount
|
|
438
|
-
*
|
|
439
|
-
* - searchResult
|
|
440
|
-
* カードとして表示するVNode
|
|
441
|
-
*
|
|
442
|
-
* - hitTest
|
|
443
|
-
* 抽出条件
|
|
444
|
-
*
|
|
445
|
-
* - maxItemsCount
|
|
446
|
-
* 最初に表示させるカードの最大数
|
|
447
|
-
*
|
|
448
|
-
* - 拡張項目
|
|
449
|
-
* afterRender
|
|
450
|
-
*
|
|
451
|
-
* - afterRender
|
|
452
|
-
* レンダーフック
|
|
453
|
-
*/
|
|
454
|
-
export const NavigatorSearch = function (props) {
|
|
455
|
-
const { state, id, currentKeys, searchResult, hitTest, afterRender } = props;
|
|
456
|
-
// localKey
|
|
457
|
-
const localKey = createLocalKey(id);
|
|
458
|
-
// localState
|
|
459
|
-
const localState = getLocalState(state, id, {
|
|
460
|
-
maxItemsCount: props.maxItemsCount, // カードの最大表示数
|
|
461
|
-
sortName: undefined, // ソート名
|
|
462
|
-
sortFn: undefined, // 比較関数
|
|
463
|
-
isDirectory: true, // ディレクトリを表示
|
|
464
|
-
isFile: true // ファイルを表示
|
|
465
|
-
});
|
|
466
|
-
// current
|
|
467
|
-
const current = getValue(state, currentKeys, undefined);
|
|
468
|
-
// ---------- ---------- ----------
|
|
469
|
-
// searchItems
|
|
470
|
-
// ---------- ---------- ----------
|
|
471
|
-
/**
|
|
472
|
-
* アイテムの検索
|
|
473
|
-
* 検索アイテムのフラット化をしていないので、速度によっては拡張を検討
|
|
474
|
-
*/
|
|
475
|
-
const searchItems = (item, depth) => {
|
|
476
|
-
if (!item)
|
|
477
|
-
return [];
|
|
478
|
-
const result = [];
|
|
479
|
-
if (hitTest(item))
|
|
480
|
-
result.push({ item, depth });
|
|
481
|
-
if (item.children && item.children.length !== 0) {
|
|
482
|
-
item.children.forEach(child => {
|
|
483
|
-
const r = searchItems(child, depth + 1);
|
|
484
|
-
if (r.length !== 0)
|
|
485
|
-
result.push(...r);
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
return result;
|
|
489
|
-
}; // end searchItems
|
|
490
|
-
// get items
|
|
491
|
-
const items = current
|
|
492
|
-
? searchItems(current, 0)
|
|
493
|
-
: [];
|
|
494
|
-
// sort
|
|
495
|
-
if (localState.sortFn !== undefined)
|
|
496
|
-
items.sort(localState.sortFn);
|
|
497
|
-
// drawItems (filter, maxItemsCount の適用)
|
|
498
|
-
const drawItems = items.filter(item => {
|
|
499
|
-
return item.item.children
|
|
500
|
-
? localState.isDirectory
|
|
501
|
-
: localState.isFile;
|
|
502
|
-
}).slice(0, localState.maxItemsCount);
|
|
503
|
-
// get parentItems
|
|
504
|
-
const parentItems = current
|
|
505
|
-
? getParentItems(current).concat(current)
|
|
506
|
-
: [];
|
|
507
|
-
// message
|
|
508
|
-
const message = `hit ${items.length} items`;
|
|
509
|
-
// ---------- ---------- ----------
|
|
510
|
-
// action_itemsScroll
|
|
511
|
-
// ---------- ---------- ----------
|
|
512
|
-
/**
|
|
513
|
-
* items のスクロール状況で、maxItemsCount を追加
|
|
514
|
-
*/
|
|
515
|
-
const action_itemsScroll = (state, e) => {
|
|
516
|
-
const margin = getScrollMargin(e);
|
|
517
|
-
return setLocalState(state, id, {
|
|
518
|
-
maxItemsCount: margin.bottom < 10
|
|
519
|
-
? localState.maxItemsCount + 10 < items.length
|
|
520
|
-
? localState.maxItemsCount + 10
|
|
521
|
-
: Math.max(10, items.length)
|
|
522
|
-
: localState.maxItemsCount
|
|
523
|
-
});
|
|
524
|
-
};
|
|
525
|
-
// ---------- ---------- ----------
|
|
526
|
-
// action_setSort
|
|
527
|
-
// ---------- ---------- ----------
|
|
528
|
-
/**
|
|
529
|
-
* 仕様するソート名をセット
|
|
530
|
-
* sortFn をステートに持つように変更する場合、ここも修正
|
|
531
|
-
*/
|
|
532
|
-
const action_setSort = (state, newSortName) => {
|
|
533
|
-
const reverse = localState.sortName === newSortName;
|
|
534
|
-
const obj = {
|
|
535
|
-
"depth": (a, b) => a.depth - b.depth,
|
|
536
|
-
"name": (a, b) => {
|
|
537
|
-
if (a.item.name === b.item.name)
|
|
538
|
-
return 0;
|
|
539
|
-
return a.item.name < b.item.name ? -1 : 1;
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
const fn = obj[newSortName] !== undefined
|
|
543
|
-
? reverse
|
|
544
|
-
? (a, b) => obj[newSortName](b, a)
|
|
545
|
-
: (a, b) => obj[newSortName](a, b)
|
|
546
|
-
: (a, b) => {
|
|
547
|
-
return a.depth === b.depth
|
|
548
|
-
? obj["name"](a, b)
|
|
549
|
-
: obj["depth"](a, b);
|
|
550
|
-
};
|
|
551
|
-
return setLocalState(state, id, {
|
|
552
|
-
sortName: reverse ? `r_${newSortName}` : newSortName,
|
|
553
|
-
sortFn: fn
|
|
554
|
-
});
|
|
555
|
-
};
|
|
556
|
-
// ---------- ---------- ----------
|
|
557
|
-
// vnode
|
|
558
|
-
// ---------- ---------- ----------
|
|
559
|
-
const toolBarNode = div({
|
|
560
|
-
class: "toolBar"
|
|
561
|
-
},
|
|
562
|
-
// sort
|
|
563
|
-
button({
|
|
564
|
-
type: "button",
|
|
565
|
-
title: "sort depth",
|
|
566
|
-
onclick: [action_setSort, "depth"]
|
|
567
|
-
}, icon_depth), button({
|
|
568
|
-
type: "button",
|
|
569
|
-
title: "sort name",
|
|
570
|
-
onclick: [action_setSort, "name"]
|
|
571
|
-
}, icon_name),
|
|
572
|
-
// filter
|
|
573
|
-
button({
|
|
574
|
-
type: "button",
|
|
575
|
-
class: localState.isDirectory ? "" : "ignore",
|
|
576
|
-
title: "directory",
|
|
577
|
-
onclick: (state) => setLocalState(state, id, {
|
|
578
|
-
isDirectory: !localState.isDirectory
|
|
579
|
-
})
|
|
580
|
-
}, icon_directory), button({
|
|
581
|
-
type: "button",
|
|
582
|
-
class: localState.isFile ? "" : "ignore",
|
|
583
|
-
title: "file",
|
|
584
|
-
onclick: (state) => setLocalState(state, id, {
|
|
585
|
-
isFile: !localState.isFile
|
|
586
|
-
})
|
|
587
|
-
}, icon_file));
|
|
588
|
-
// parentItemsNode
|
|
589
|
-
const parentItemsNode = div({
|
|
590
|
-
class: "parentItems"
|
|
591
|
-
}, ol({}, parentItems.map(item => li({
|
|
592
|
-
onclick: (state) => setValue(state, currentKeys, item)
|
|
593
|
-
}, item.name))));
|
|
594
|
-
// itemsNode
|
|
595
|
-
const itemsNode = div({
|
|
596
|
-
class: "items",
|
|
597
|
-
onscroll: action_itemsScroll
|
|
598
|
-
}, ul({}, drawItems.map(item => li({
|
|
599
|
-
class: "item",
|
|
600
|
-
key: item.item.path,
|
|
601
|
-
title: item.item.path
|
|
602
|
-
}, searchResult(item.item, item.depth)))));
|
|
603
|
-
// statusBarNode
|
|
604
|
-
const statusBarNode = div({
|
|
605
|
-
class: "statusBar"
|
|
606
|
-
}, message);
|
|
607
|
-
// vnode
|
|
608
|
-
const vnode = div({
|
|
609
|
-
...deleteKeys(props, "state", "currentKeys", "searchResult", "hitTest", "maxItemsCount", "toolBarNode", "parentItemsNode", "statusBarNode", "afterRender")
|
|
610
|
-
}, props.toolBarNode ? props.toolBarNode(state, localState, toolBarNode) : toolBarNode, props.parentItemsNode ? props.parentItemsNode(state, localState, parentItemsNode) : parentItemsNode, itemsNode, props.statusBarNode ? props.statusBarNode(state, localState, statusBarNode) : statusBarNode);
|
|
611
|
-
// ---------- ---------- ----------
|
|
612
|
-
// afterRender
|
|
613
|
-
// ---------- ---------- ----------
|
|
614
|
-
return afterRender ? afterRender(state, localState, vnode) : vnode;
|
|
615
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export type Keys = readonly string[];
|
|
2
|
-
export type Keys_String = Keys;
|
|
3
|
-
export type Keys_ArrayString = Keys;
|
|
4
|
-
export type Keys_Number = Keys;
|
|
5
|
-
export type Keys_ArrayNumber = Keys;
|
|
6
|
-
export type Keys_ArrayRAFTask = Keys;
|
|
7
|
-
export type Keys_NavigatorItem = Keys;
|
|
8
|
-
/**
|
|
9
|
-
* パスを辿って、ステートから値を取得する
|
|
10
|
-
*/
|
|
11
|
-
export declare const getValue: <S, D>(state: S, keyNames: Keys, def: D) => D;
|
|
12
|
-
/**
|
|
13
|
-
* パスを辿って、ステートに値を設定して返す
|
|
14
|
-
*/
|
|
15
|
-
export declare const setValue: <S>(state: S, keyNames: Keys, value: any) => S;
|
|
16
|
-
/**
|
|
17
|
-
* IDからユニーク文字列を作成する
|
|
18
|
-
*/
|
|
19
|
-
export declare const createLocalKey: (id: string) => string;
|
|
20
|
-
/**
|
|
21
|
-
* ステートから、ローカルステートを取得する
|
|
22
|
-
*/
|
|
23
|
-
export declare const getLocalState: <S, T>(state: S, id: string, def: T) => T;
|
|
24
|
-
/**
|
|
25
|
-
* ローカルステートを更新してステートを返す
|
|
26
|
-
*/
|
|
27
|
-
export declare const setLocalState: <S, T>(state: S, id: string, value: T) => S;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* スクロールの余白
|
|
3
|
-
*/
|
|
4
|
-
export interface ScrollMargin {
|
|
5
|
-
top: number;
|
|
6
|
-
left: number;
|
|
7
|
-
right: number;
|
|
8
|
-
bottom: number;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* スクロールの余白を取得する
|
|
12
|
-
*/
|
|
13
|
-
export declare const getScrollMargin: (e: Event) => ScrollMargin;
|
|
14
|
-
/**
|
|
15
|
-
* transform 情報
|
|
16
|
-
*/
|
|
17
|
-
export interface MatrixState {
|
|
18
|
-
translate: {
|
|
19
|
-
x: number;
|
|
20
|
-
y: number;
|
|
21
|
-
z: number;
|
|
22
|
-
};
|
|
23
|
-
scale: {
|
|
24
|
-
x: number;
|
|
25
|
-
y: number;
|
|
26
|
-
z: number;
|
|
27
|
-
};
|
|
28
|
-
rotate: {
|
|
29
|
-
x: number;
|
|
30
|
-
y: number;
|
|
31
|
-
z: number;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* DOM から transfrom 情報を取得する
|
|
36
|
-
*/
|
|
37
|
-
export declare const getMatrixState: (dom: HTMLElement) => MatrixState | null;
|