• 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 * @import import pasteboard from '@ohos.pasteboard';
22 */
23declare namespace pasteboard {
24  /**
25   * Indicates the maximum number of records allowed in a PasteData object.
26   * @since 7
27   */
28  const MAX_RECORD_NUM: number;
29  /**
30   * Indicates MIME types of HTML text.
31   * @since 7
32   */
33  const MIMETYPE_TEXT_HTML: string;
34  /**
35   * Indicates MIME types of wants.
36   * @since 7
37   */
38  const MIMETYPE_TEXT_WANT: string;
39  /**
40   * Indicates MIME types of plain text.
41   * @since 7
42   */
43  const MIMETYPE_TEXT_PLAIN: string;
44  /**
45   * Indicates MIME types of URIs.
46   * @since 7
47   */
48  const MIMETYPE_TEXT_URI: string;
49
50  /**
51   * Creates a PasteData object for PasteData#MIMETYPE_TEXT_HTML.
52   * @param htmlText To save the Html text content.
53   * @return Containing the contents of the clipboard content object.
54   * @since 7
55   */
56  function createHtmlData(htmlText: string): PasteData;
57
58  /**
59   * Creates a PasteData object for PasteData#MIMETYPE_TEXT_WANT.
60   * @param want To save the want of content.
61   * @return Containing the contents of the clipboard content object.
62   * @since 7
63   */
64  function createWantData(want: Want): PasteData;
65
66  /**
67   * Creates a PasteData object for PasteData#MIMETYPE_TEXT_PLAIN.
68   * @param text To save the text of content.
69   * @return Containing the contents of the clipboard content object.
70   * @since 6
71   */
72  function createPlainTextData(text: string): PasteData;
73
74  /**
75   * Creates a PasteData object for PasteData#MIMETYPE_TEXT_URI.
76   * @param uri To save the uri of content.
77   * @return Containing the contents of the clipboard content object.
78   * @since 7
79   */
80  function createUriData(uri: string): PasteData;
81
82  /**
83   * Creates a Record object for PasteData#MIMETYPE_TEXT_HTML.
84   * @param htmlText To save the Html text content.
85   * @return The content of a new record
86   * @since 7
87   */
88  function createHtmlTextRecord(htmlText: string): PasteDataRecord;
89
90  /**
91   * Creates a Record object for PasteData#MIMETYPE_TEXT_WANT.
92   * @param want To save the want of content.
93   * @return The content of a new record
94   * @since 7
95   */
96  function createWantRecord(want: Want): PasteDataRecord;
97
98  /**
99   * Creates a Record object for PasteData#MIMETYPE_TEXT_PLAIN.
100   * @param text To save the text of content.
101   * @return The content of a new record
102   * @since 7
103   */
104  function createPlainTextRecord(text: string): PasteDataRecord;
105
106  /**
107   * Creates a Record object for PasteData#MIMETYPE_TEXT_URI.
108   * @param uri To save the uri of content.
109   * @return The content of a new record
110   * @since 7
111   */
112  function createUriRecord(uri: string): PasteDataRecord;
113
114  /**
115   * get SystemPasteboard
116   * @return The system clipboard object
117   * @since 6
118   */
119  function getSystemPasteboard(): SystemPasteboard;
120
121  interface PasteDataProperty {
122    /**
123     * additional property data. key-value pairs.
124     * @since 7
125     */
126    additions: {
127      [key: string]: object
128    }
129    /**
130     * non-repeating MIME types of all records in PasteData.
131     * @since 7
132     */
133    readonly mimeTypes: Array<string>;
134    /**
135     * the user-defined tag of a PasteData object.
136     * @since 7
137     */
138    tag: string;
139    /**
140     * a timestamp, which indicates when data is written to the system pasteboard.
141     * @since 7
142     */
143     readonly timestamp: number;
144    /**
145     * Checks whether PasteData is set for local access only.
146     * @since 7
147     */
148    localOnly: boolean;
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