hyperapp-is 0.1.27 → 0.1.30

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
@@ -144,6 +144,7 @@ npm で非公開の関数 (実験用)は、解説に記載します
144
144
  - [Route](#route)
145
145
  - [SelectButton](#selectbutton)
146
146
  - [OptionButton](#optionbutton)
147
+ - [HistoryInput](#historyinput)
147
148
 
148
149
  **core / navigator.ts**
149
150
  - [Keys_NavigatorItem](#keys_navigatoritem)
@@ -502,6 +503,32 @@ export const OptionButton = function <S> (
502
503
 
503
504
  ---
504
505
 
506
+ ### HistoryInput
507
+ 履歴付きインプットボックス
508
+
509
+ ```ts
510
+ export const HistoryInput = function <S> (
511
+ props: {
512
+ state : S
513
+ id : string
514
+ keyNames : Keys_String
515
+ historyLimit?: number
516
+ [key: string]: any
517
+ }
518
+ ): VNode<S>
519
+ ```
520
+
521
+ - props : props
522
+ - props.state : ステート
523
+ - props.id : ユニークID
524
+ - props.keyNames: ステート内の文字までのパス
525
+ - props.historyLimit: 保持する履歴の最大数 (default = 10)
526
+
527
+ 履歴は `[props.id].histories` に保存されます
528
+ 履歴を動的にクリアしたい場合 `setLocalState(state, id, { histories: [] })` などとして下さい
529
+
530
+ ---
531
+
505
532
  ### Keys_NavigatorItem
506
533
  ステートの任意の値までのパスを表す、文字配列の型エイリアス
507
534
 
@@ -49,3 +49,17 @@ export declare const OptionButton: <S>(props: {
49
49
  reverse?: boolean;
50
50
  [key: string]: any;
51
51
  }, children: any) => VNode<S>;
52
+ /**
53
+ * 履歴付きインプット
54
+ *
55
+ * div
56
+ * ├ input
57
+ * └ datalist
58
+ */
59
+ export declare const HistoryInput: <S>(props: {
60
+ state: S;
61
+ id: string;
62
+ keyNames: Keys_String;
63
+ historyLimit?: number;
64
+ [key: string]: any;
65
+ }) => VNode<S>;
@@ -3,7 +3,7 @@
3
3
  // import
4
4
  // ---------- ---------- ---------- ---------- ----------
5
5
  import { h, text } from "hyperapp";
6
- import { getValue, setValue } from "./state";
6
+ import { getValue, setValue, getLocalState, setLocalState } from "./state";
7
7
  // ---------- ---------- ---------- ---------- ----------
8
8
  // el
9
9
  // ---------- ---------- ---------- ---------- ----------
@@ -13,7 +13,9 @@ import { getValue, setValue } from "./state";
13
13
  */
14
14
  export const el = (tag) => (props, ...children) => h(tag, props !== null && props !== void 0 ? props : {}, children
15
15
  .flat()
16
- .map((child) => typeof child === "object" ? child : text(child)));
16
+ .filter(child => child !== null &&
17
+ child !== undefined)
18
+ .map((child) => typeof child === "object" ? child : text(`${child}`)));
17
19
  // ---------- ---------- ---------- ---------- ----------
18
20
  // concatAction
19
21
  // ---------- ---------- ---------- ---------- ----------
@@ -68,6 +70,10 @@ export const Route = function (props, children) {
68
70
  // vnodes
69
71
  // ---------- ---------- ---------- ---------- ----------
70
72
  const button = el("button");
73
+ const div = el("div");
74
+ const input = el("input");
75
+ const datalist = el("datalist");
76
+ const option = el("option");
71
77
  // ---------- ---------- ---------- ---------- ----------
72
78
  // SelectButton Component
73
79
  // ---------- ---------- ---------- ---------- ----------
@@ -151,3 +157,69 @@ export const OptionButton = function (props, children) {
151
157
  onclick: action
152
158
  }, children);
153
159
  };
160
+ // ---------- ---------- ---------- ---------- ----------
161
+ // HistoryInput
162
+ // ---------- ---------- ---------- ---------- ----------
163
+ /**
164
+ * 履歴付きインプット
165
+ *
166
+ * div
167
+ * ├ input
168
+ * └ datalist
169
+ */
170
+ export const HistoryInput = function (props) {
171
+ const { state, id, keyNames, historyLimit = 10 } = props;
172
+ const value = getValue(state, keyNames, "");
173
+ const localState = getLocalState(state, id, {
174
+ histories: []
175
+ });
176
+ const histories = localState.histories
177
+ .filter(item => item.toLowerCase().includes(value.toLowerCase()));
178
+ // ---------- ---------- ----------
179
+ // oninput
180
+ // ---------- ---------- ----------
181
+ const oninput = (state, e) => {
182
+ const element = e.target;
183
+ if (!element)
184
+ return state;
185
+ return concatAction(props.oninput, setValue(state, keyNames, element.value), e);
186
+ };
187
+ // ---------- ---------- ----------
188
+ // onkeydown
189
+ // ---------- ---------- ----------
190
+ const onkeydown = (state, e) => {
191
+ if (e.key !== "Enter")
192
+ return state;
193
+ const element = e.target;
194
+ if (!element)
195
+ return state;
196
+ const val = element.value.trim();
197
+ if (!val)
198
+ return state;
199
+ const items = getLocalState(state, id, {
200
+ histories: []
201
+ }).histories;
202
+ const newHistories = items
203
+ .filter(item => item !== val)
204
+ .concat(val)
205
+ .slice(-historyLimit);
206
+ return concatAction(props.onkeydown, setLocalState(state, id, {
207
+ histories: newHistories
208
+ }), e);
209
+ };
210
+ // ---------- ---------- ----------
211
+ // VNode
212
+ // ---------- ---------- ----------
213
+ return div({}, input({
214
+ type: "text",
215
+ ...deleteKeys(props, "state", "keyNames", "historyLimit"),
216
+ list: `${id}-history`,
217
+ value,
218
+ oninput,
219
+ onkeydown,
220
+ }), datalist({
221
+ id: `${id}-history`
222
+ }, histories.map(item => option({
223
+ value: item
224
+ }))));
225
+ };
@@ -59,6 +59,13 @@ export declare const NavigatorFinder: <S>(props: {
59
59
  afterRender?: (state: S, localState: Record<string, any>, vnode: VNode<S>) => VNode<S>;
60
60
  [key: string]: any;
61
61
  }) => VNode<S>;
62
+ export declare const icon_depth: VNode<any>;
63
+ export declare const icon_name: VNode<any>;
64
+ export declare const icon_directory: VNode<any>;
65
+ export declare const icon_file: VNode<any>;
66
+ export declare const icon_trashBox: VNode<any>;
67
+ export declare const icon_filter: VNode<any>;
68
+ export declare const icon_copy: VNode<any>;
62
69
  /**
63
70
  * 検索結果
64
71
  *
@@ -327,7 +327,7 @@ export const NavigatorFinder = function (props) {
327
327
  // svg icon
328
328
  // ---------- ---------- ---------- ---------- ----------
329
329
  // icon_depth
330
- const icon_depth = svg({
330
+ export const icon_depth = svg({
331
331
  width: 24,
332
332
  height: 24,
333
333
  viewBox: "0 0 24 24",
@@ -360,7 +360,7 @@ const icon_depth = svg({
360
360
  d: "M6 15v-4h12v4"
361
361
  }));
362
362
  // icon_name
363
- const icon_name = svg({
363
+ export const icon_name = svg({
364
364
  width: 24,
365
365
  height: 24,
366
366
  viewBox: "0 0 24 24",
@@ -371,7 +371,7 @@ const icon_name = svg({
371
371
  strokeLinejoin: "round"
372
372
  }, 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" }));
373
373
  // icon_directory
374
- const icon_directory = svg({
374
+ export const icon_directory = svg({
375
375
  width: 24,
376
376
  height: 24,
377
377
  viewBox: "0 0 24 24",
@@ -382,7 +382,7 @@ const icon_directory = svg({
382
382
  strokeLinejoin: "round"
383
383
  }, path({ d: "M3 7h6l2 2h10v8a2 2 0 0 1-2 2H3z" }));
384
384
  // icon_file
385
- const icon_file = svg({
385
+ export const icon_file = svg({
386
386
  width: 24,
387
387
  height: 24,
388
388
  viewBox: "0 0 24 24",
@@ -393,7 +393,7 @@ const icon_file = svg({
393
393
  strokeLinejoin: "round"
394
394
  }, 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" }));
395
395
  // icon_trashBox
396
- const icon_trashBox = svg({
396
+ export const icon_trashBox = svg({
397
397
  viewBox: "0 0 24 24",
398
398
  width: 24,
399
399
  height: 24,
@@ -404,7 +404,7 @@ const icon_trashBox = svg({
404
404
  strokeLinejoin: "round"
405
405
  }, path({ d: "M3 6h18" }), path({ d: "M8 6V4h8v2" }), path({ d: "M6 6l1 14h10l1-14" }), path({ d: "M10 11v6" }), path({ d: "M14 11v6" }));
406
406
  // icon_filter
407
- const icon_filter = svg({
407
+ export const icon_filter = svg({
408
408
  viewBox: "0 0 24 24",
409
409
  width: 24,
410
410
  height: 24,
@@ -415,7 +415,7 @@ const icon_filter = svg({
415
415
  strokeLinejoin: "round"
416
416
  }, path({ d: "M3 5h18" }), path({ d: "M6 12h12" }), path({ d: "M10 19h4" }));
417
417
  // icon_copy
418
- const icon_copy = svg({
418
+ export const icon_copy = svg({
419
419
  viewBox: "0 0 24 24",
420
420
  width: 24,
421
421
  height: 24,
@@ -1,8 +1,8 @@
1
1
  export type { Keys, Keys_String, Keys_ArrayString, Keys_Number, Keys_ArrayNumber, Keys_ArrayRAFTask, Keys_NavigatorItem, } from "./core/state";
2
2
  export type { NavigatorItem, JsonEntry, NavigatorColumn, SearchResult } from "./core/navigator";
3
3
  export { getValue, setValue, getLocalState, setLocalState, createLocalKey } from "./core/state";
4
- export { el, concatAction, getClassList, deleteKeys, Route, SelectButton, OptionButton } from "./core/component";
5
- export { convertJsonToNavigatorItem, getParentItems, NavigatorFinder, NavigatorSearch } from "./core/navigator";
4
+ export { el, concatAction, getClassList, deleteKeys, Route, SelectButton, OptionButton, HistoryInput } from "./core/component";
5
+ export { convertJsonToNavigatorItem, getParentItems, NavigatorFinder, NavigatorSearch, icon_depth, icon_name, icon_directory, icon_file, icon_trashBox, icon_filter, icon_copy } from "./core/navigator";
6
6
  export type { InternalEffect, RAFEvent } from "./animation/raf";
7
7
  export type { CSSProperty } from "./animation/properties";
8
8
  export { RAFTask, subscription_RAFManager } from "./animation/raf";
@@ -1,7 +1,7 @@
1
1
  // hyperapp-is / index.ts
2
2
  export { getValue, setValue, getLocalState, setLocalState, createLocalKey } from "./core/state";
3
- export { el, concatAction, getClassList, deleteKeys, Route, SelectButton, OptionButton } from "./core/component";
4
- export { convertJsonToNavigatorItem, getParentItems, NavigatorFinder, NavigatorSearch } from "./core/navigator";
3
+ export { el, concatAction, getClassList, deleteKeys, Route, SelectButton, OptionButton, HistoryInput } from "./core/component";
4
+ export { convertJsonToNavigatorItem, getParentItems, NavigatorFinder, NavigatorSearch, icon_depth, icon_name, icon_directory, icon_file, icon_trashBox, icon_filter, icon_copy } from "./core/navigator";
5
5
  export { RAFTask, subscription_RAFManager } from "./animation/raf";
6
6
  export { progress_easing } from "./animation/easing";
7
7
  export { createUnits, createRAFProperties, effect_RAFProperties } from "./animation/properties";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperapp-is",
3
- "version": "0.1.27",
3
+ "version": "0.1.30",
4
4
  "description": "UI foundation library for Hyperapp by is4416",
5
5
  "license": "MIT",
6
6
  "type": "module",