• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import { AsyncCallback } from './basic';
16import { Want } from './ability/want';
17
18/**
19 * systemPasteboard
20 * @sysCap SystemCapability.Miscservices.Pasteboard
21 * @devices phone, tablet, tv, wearable, car
22 * @import import pasteboard from '@ohos.pasteboard';
23 */
24declare namespace pasteboard {
25  /**
26   * Indicates the maximum number of records allowed in a PasteData object.
27   * @since 7
28   */
29  const MAX_RECORD_NUM: number;
30  /**
31   * Indicates MIME types of HTML text.
32   * @since 7
33   */
34  const MIMETYPE_TEXT_HTML: string;
35  /**
36   * Indicates MIME types of wants.
37   * @since 7
38   */
39  const MIMETYPE_TEXT_WANT: string;
40  /**
41   * Indicates MIME types of plain text.
42   * @since 7
43   */
44  const MIMETYPE_TEXT_PLAIN: string;
45  /**
46   * Indicates MIME types of URIs.
47   * @since 7
48   */
49  const MIMETYPE_TEXT_URI: string;
50
51  /**
52   * Creates a PasteData object for PasteData#MIMETYPE_TEXT_HTML.
53   * @param htmlText To save the Html text content.
54   * @return Containing the contents of the clipboard content object.
55   * @since 7
56   */
57  function createHtmlData(htmlText: string): PasteData;
58
59  /**
60   * Creates a PasteData object for PasteData#MIMETYPE_TEXT_WANT.
61   * @param want To save the want of content.
62   * @return Containing the contents of the clipboard content object.
63   * @since 7
64   */
65  function createWantData(want: Want): PasteData;
66
67  /**
68   * Creates a PasteData object for PasteData#MIMETYPE_TEXT_PLAIN.
69   * @param text To save the text of content.
70   * @return Containing the contents of the clipboard content object.
71   * @since 6
72   */
73  function createPlainTextData(text: string): PasteData;
74
75  /**
76   * Creates a PasteData object for PasteData#MIMETYPE_TEXT_URI.
77   * @param uri To save the uri of content.
78   * @return Containing the contents of the clipboard content object.
79   * @since 7
80   */
81  function createUriData(uri: string): PasteData;
82
83  /**
84   * Creates a Record object for PasteData#MIMETYPE_TEXT_HTML.
85   * @param htmlText To save the Html text content.
86   * @return The content of a new record
87   * @since 7
88   */
89  function createHtmlTextRecord(htmlText: string): PasteDataRecord;
90
91  /**
92   * Creates a Record object for PasteData#MIMETYPE_TEXT_WANT.
93   * @param want To save the want of content.
94   * @return The content of a new record
95   * @since 7
96   */
97  function createWantRecord(want: Want): PasteDataRecord;
98
99  /**
100   * Creates a Record object for PasteData#MIMETYPE_TEXT_PLAIN.
101   * @param text To save the text of content.
102   * @return The content of a new record
103   * @since 7
104   */
105  function createPlainTextRecord(text: string): PasteDataRecord;
106
107  /**
108   * Creates a Record object for PasteData#MIMETYPE_TEXT_URI.
109   * @param uri To save the uri of content.
110   * @return The content of a new record
111   * @since 7
112   */
113  function createUriRecord(uri: string): PasteDataRecord;
114
115  /**
116   * get SystemPasteboard
117   * @return The system clipboard object
118   * @since 6
119   */
120  function getSystemPasteboard(): SystemPasteboard;
121
122  interface PasteDataProperty {
123    /**
124     * additional property data. key-value pairs.
125     * @since 7
126     */
127    additions: {
128      [key: string]: object
129    }
130    /**
131     * non-repeating MIME types of all records in PasteData.
132     * @since 7
133     */
134    readonly mimeTypes: Array<string>;
135    /**
136     * the user-defined tag of a PasteData object.
137     * @since 7
138     */
139    tag: string;
140    /**
141     * a timestamp, which indicates when data is written to the system pasteboard.
142     * @since 7
143     */
144    readonly timestamp: number;
145    /**
146     * Checks whether PasteData is set for local access only.
147     * @since 7
148     */
149  }
150
151  interface PasteDataRecord {
152    /**
153     * HTML text in a record.
154     * @since 7
155     */
156    htmlText: string;
157    /**
158     * an want in a record.
159     * @since 7
160     */
161    want: Want;
162    /**
163     * MIME types of a record.
164     * @since 7
165     */
166    mimeType: string;
167    /**
168     * plain text in a record.
169     * @since 7
170     */
171    plainText: string;
172    /**
173     * an URI in a record.
174     * @since 7
175     */
176    uri: string;
177
178    /**
179     * Will a PasteData cast to the content of text content
180     * @return callback Type string callback function
181     * @since 7
182     */
183    convertToText(callback: AsyncCallback<string>): void;
184    convertToText(): Promise<string>;
185  }
186
187  interface PasteData {
188    /**
189     * Adds a Record for HTML text to a PasteData object, and updates the MIME type to PasteData#MIMETYPE_TEXT_HTML in DataProperty.
190     * @param htmlText To save the Html text content.
191     * @since 7
192     */
193    addHtmlRecord(htmlText: string): void;
194
195    /**
196     * Adds an want Record to a PasteData object, and updates the MIME type to PasteData#MIMETYPE_TEXT_WANT in DataProperty.
197     * @param want To save the want content.
198     * @since 7
199     */
200    addWantRecord(want: Want): void;
201
202    /**
203     * Adds a PasteRecord to a PasteData object and updates MIME types in DataProperty.
204     * @param record The content of a new record.
205     * @since 7
206     */
207    addRecord(record: PasteDataRecord): void;
208
209    /**
210     * Adds a Record for plain text to a PasteData object, and updates the MIME type to PasteData#MIMETYPE_TEXT_PLAIN in DataProperty.
211     * @param text To save the text of content.
212     * @since 7
213     */
214    addTextRecord(text: string): void;
215
216    /**
217     * Adds a URI Record to a PasteData object, and updates the MIME type to PasteData#MIMETYPE_TEXT_URI in DataProperty.
218     * @param uri To save the uri of content.
219     * @since 7
220     */
221    addUriRecord(uri: string): void;
222
223    /**
224     * MIME types of all content on the pasteboard.
225     * @return string type of array
226     * @since 7
227     */
228    getMimeTypes(): Array<string>;
229
230    /**
231     * HTML text of the primary record in a PasteData object.
232     * @return string type of htmltext
233     * @since 7
234     */
235    getPrimaryHtml(): string;
236
237    /**
238     * the want of the primary record in a PasteData object.
239     * @return want type of want
240     * @since 7
241     */
242    getPrimaryWant(): Want;
243
244    /**
245     * the MIME type of the primary record in a PasteData object.
246     * @return string type of mimetype
247     * @since 7
248     */
249    getPrimaryMimeType(): string;
250
251    /**
252     * the plain text of the primary record in a PasteData object.
253     * @return string type of text
254     * @since 6
255     */
256    getPrimaryText(): string;
257
258    /**
259     * the URI of the primary record in a PasteData object.
260     * @return string type of uri
261     * @since 7
262     */
263    getPrimaryUri(): string;
264
265    /**
266     * DataProperty of a PasteData object.
267     * @return PasteDataProperty type of PasteDataProperty
268     * @since 7
269     */
270    getProperty(): PasteDataProperty;
271
272    /**
273     * a Record based on a specified index.
274     * @param index The index to specify the content item
275     * @return PasteDataRecord type of PasteDataRecord
276     * @since 7
277     */
278    getRecordAt(index: number): PasteDataRecord;
279
280    /**
281     * the number of records in a PasteData object.
282     * @return The number of the clipboard contents
283     * @since 7
284     */
285    getRecordCount(): number;
286
287    /**
288     * the user-defined tag of a PasteData object.
289     * @return string type of tag
290     * @since 7
291     */
292    getTag(): string;
293
294    /**
295     * Checks whether there is a specified MIME type of data in DataProperty.
296     * @param mimeType To query data types.
297     * @return The query returns True on success, or False on failure.
298     * @since 7
299     */
300    hasMimeType(mimeType: string): boolean;
301
302    /**
303     * Removes a Record based on a specified index.
304     * @param index The index to specify the content item.
305     * @return The query returns True on success, or False on failure.
306     * @since 7
307     */
308    removeRecordAt(index: number): boolean;
309
310    /**
311     * Replaces a specified record with a new one.
312     * @param index The index to specify the content item. record record The content of a new record.
313     * @return The query returns True on success, or False on failure.
314     * @since 7
315     */
316    replaceRecordAt(index: number, record: PasteDataRecord): boolean;
317  }
318
319  interface SystemPasteboard {
320    /**
321     * Callback invoked when pasteboard content changes.
322     * @param type 'update'
323     * @since 7
324     */
325    on(type: 'update', callback: () => void): void;
326    /**
327     * Callback invoked when pasteboard content changes.
328     * @param type 'update'
329     * @since 7
330     */
331    off(type: 'update', callback?: () => void): void;
332
333    /**
334     * Clears the pasteboard.
335     * @since 7
336     */
337    clear(callback: AsyncCallback<void>): void;
338    clear(): Promise<void>;
339
340    /**
341     * data in a PasteData object.
342     * @return PasteData callback data in a PasteData object.
343     * @since 6
344     */
345    getPasteData(callback: AsyncCallback<PasteData>): void;
346    getPasteData(): Promise<PasteData>;
347
348    /**
349     * Checks whether there is content in the pasteboard.
350     * @return boolean The callback success to true to false failure
351     * @since 7
352     */
353    hasPasteData(callback: AsyncCallback<boolean>): void;
354    hasPasteData(): Promise<boolean>;
355
356    /**
357     * Writes PasteData to the pasteboard.
358     * @param  data Containing the contents of the clipboard content object.
359     * @since 6
360     */
361    setPasteData(data: PasteData, callback: AsyncCallback<void>): void;
362    setPasteData(data: PasteData): Promise<void>;
363  }
364}
365
366export default pasteboard;
367