Skip to content

Commit

Permalink
なでしこの変数管理をObjectからMapに変更する #1638 - ブラウザ周りの修正
Browse files Browse the repository at this point in the history
  • Loading branch information
kujirahand committed May 1, 2024
1 parent 7f41c8d commit 5282ff2
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 91 deletions.
2 changes: 1 addition & 1 deletion core
Submodule core updated 1 files
+5 −1 src/plugin_system.mts
38 changes: 19 additions & 19 deletions src/plugin_browser_ajax.mts
Expand Up @@ -41,19 +41,19 @@ export default {
josi: [['の'], ['まで', 'へ', 'に']],
pure: true,
fn: function (callback: any, url: any, sys: any) {
let options = sys.__v0['AJAXオプション']
let options = sys.__getSysVar('AJAXオプション')
if (options === '') { options = { method: 'GET' } }
fetch(url, options).then(res => {
// もし301であれば自動でリダイレクトするため,200だけをチェックすれば良い
if (res.status !== 200) {
return sys.__v0['AJAX:ONERROR'](res.status)
return sys.__getSysVar('AJAX:ONERROR')(res.status)
}
return res.text()
}).then(text => {
sys.__v0['対象'] = text
sys.__setSysVar('対象', text)
callback(text, sys)
}).catch(err => {
sys.__v0['AJAX:ONERROR'](err)
sys.__getSysVar('AJAX:ONERROR')(err)
})
},
return_none: true
Expand All @@ -64,7 +64,7 @@ export default {
josi: [['に', 'へ', 'と']],
pure: true,
fn: function (option: any, sys: any) {
sys.__v0['AJAXオプション'] = option
sys.__setSysVar('AJAXオプション', option)
},
return_none: true
},
Expand All @@ -81,7 +81,7 @@ export default {
},
body: bodyData
}
sys.__v0['AJAXオプション'] = options
sys.__setSysVar('AJAXオプション', options)
},
return_none: true
},
Expand All @@ -90,7 +90,7 @@ export default {
josi: [['の']],
pure: true,
fn: function (callback: any, sys: any) {
sys.__v0['AJAX:ONERROR'] = callback
sys.__setSysVar('AJAX:ONERROR', callback)
}
},
'AJAXテキスト取得': { // @AJAXでURLにアクセスしテキスト形式で結果を得る。送信時『AJAXオプション』の値を参照。 // @AJAXてきすとしゅとく
Expand All @@ -99,7 +99,7 @@ export default {
pure: true,
asyncFn: true,
fn: async function (url: any, sys: any) {
let options = sys.__v0['AJAXオプション']
let options = sys.__getSysVar('AJAXオプション')
if (options === '') { options = { method: 'GET' } }
const res = await fetch(url, options)
const txt = await res.text()
Expand All @@ -113,7 +113,7 @@ export default {
pure: true,
asyncFn: true,
fn: async function (url: any, sys: any) {
let options = sys.__v0['AJAXオプション']
let options = sys.__getSysVar('AJAXオプション')
if (options === '') { options = { method: 'GET' } }
const res = await fetch(url, options)
const txt = await res.json()
Expand All @@ -127,7 +127,7 @@ export default {
pure: true,
asyncFn: true,
fn: async function (url: any, sys: any) {
let options = sys.__v0['AJAXオプション']
let options = sys.__getSysVar('AJAXオプション')
if (options === '') { options = { method: 'GET' } }
const res = await fetch(url, options)
const bin = await res.blob()
Expand Down Expand Up @@ -161,10 +161,10 @@ export default {
fetch(url, options).then(res => {
return res.text()
}).then(text => {
sys.__v0['対象'] = text
sys.__setSysVar('対象', text)
callback(text)
}).catch(err => {
sys.__v0['AJAX:ONERROR'](err)
sys.__getSysVar('AJAX:ONERROR')(err)
})
}
},
Expand All @@ -183,10 +183,10 @@ export default {
fetch(url, options).then(res => {
return res.text()
}).then(text => {
sys.__v0['対象'] = text
sys.__setSysVar('対象', text)
callback(text)
}).catch(err => {
sys.__v0['AJAX:ONERROR'](err)
sys.__getSysVar('AJAX:ONERROR')(err)
})
}
},
Expand Down Expand Up @@ -258,7 +258,7 @@ export default {
josi: [['まで', 'へ', 'に']],
pure: true,
fn: function (url: any, sys: any) {
let options = sys.__v0['AJAXオプション']
let options = sys.__getSysVar('AJAXオプション')
if (options === '') { options = { method: 'GET' } }
return fetch(url, options)
},
Expand Down Expand Up @@ -351,12 +351,12 @@ export default {
sys.resolveCount++
const resolve = sys.resolve
const reject = sys.reject
let options = sys.__v0['AJAXオプション']
let options = sys.__getSysVar('AJAXオプション')
if (options === '') { options = { method: 'GET' } }
fetch(url, options).then(res => {
return res.text()
}).then(text => {
sys.__v0['対象'] = text
sys.__setSysVar('対象', text)
resolve()
}).catch(err => {
reject(err.message)
Expand Down Expand Up @@ -394,7 +394,7 @@ export default {
fetch(url, options).then(res => {
return res.text()
}).then(text => {
sys.__v0['対象'] = text
sys.__setSysVar('対象', text)
resolve(text)
}).catch(err => {
reject(err.message)
Expand All @@ -421,7 +421,7 @@ export default {
fetch(url, options).then(res => {
return res.text()
}).then(text => {
sys.__v0['対象'] = text
sys.__setSysVar('対象', text)
resolve(text)
}).catch(err => {
reject(err.message)
Expand Down
20 changes: 10 additions & 10 deletions src/plugin_browser_canvas.mts
Expand Up @@ -15,8 +15,8 @@ export default {
sys.__ctx = cv.getContext('2d')
sys.__fillStyle = 'black'
sys.__strokeStyle = 'black'
sys.__v0['描画中キャンバス'] = cv
sys.__v0['描画中コンテキスト'] = sys.__ctx
sys.__setSysVar('描画中キャンバス', cv)
sys.__setSysVar('描画中コンテキスト', sys.__ctx)
},
return_none: true
},
Expand Down Expand Up @@ -228,11 +228,11 @@ export default {
img.src = url
img.crossOrigin = 'Anonymous'
img.onload = () => {
sys.__v0['対象'] = img
sys.__setSysVar('対象', img)
sys.resolve()
}
img.onerror = () => {
sys.__v0['対象'] = ''
sys.__setSysVar('対象', '')
sys.reject()
}
return img
Expand All @@ -250,11 +250,11 @@ export default {
img.src = url
img.crossOrigin = 'Anonymous'
img.onload = () => {
sys.__v0['対象'] = img
sys.__setSysVar('対象', img)
func(sys)
}
img.onerror = () => {
sys.__v0['対象'] = ''
sys.__setSysVar('対象', '')
func(sys)
}
},
Expand Down Expand Up @@ -434,7 +434,7 @@ export default {
josi: [],
pure: true,
fn: function (sys: any) {
const cv = sys.__v0['描画中キャンバス']
const cv = sys.__getSysVar('描画中キャンバス')
const url = cv.toDataURL('image/png')
return url
}
Expand All @@ -446,7 +446,7 @@ export default {
asyncFn: true,
fn: function (sys: any) {
return new Promise((resolve, reject) => {
const cv = sys.__v0['描画中キャンバス']
const cv = sys.__getSysVar('描画中キャンバス')
cv.toBlob((result: any) => { resolve(result) }, 'image/png')
})
}
Expand All @@ -458,7 +458,7 @@ export default {
fn: function (dom: any, sys: any) {
if (typeof dom === 'string') { dom = document.querySelector(dom) }
if (!dom) { throw new Error('『描画ダウンロードリンク作成』でDOMが見当たりません。') }
const cv = sys.__v0['描画中キャンバス']
const cv = sys.__getSysVar('描画中キャンバス')
if (!cv) { throw new Error('『描画ダウンロード』で描画中キャンバスが設定されていません。') }
dom.href = cv.toDataURL('image/png')
dom.download = 'canvas.png'
Expand All @@ -470,7 +470,7 @@ export default {
josi: [],
pure: true,
fn: function (sys: any) {
const cv = sys.__v0['描画中キャンバス']
const cv = sys.__getSysVar('描画中キャンバス')
if (!cv) { throw new Error('『描画ダウンロード』で描画中キャンバスが設定されていません。') }
const a = document.createElement('a')
a.href = cv.toDataURL('image/png')
Expand Down
20 changes: 10 additions & 10 deletions src/plugin_browser_chart.mts
Expand Up @@ -47,7 +47,7 @@ export default {
const d = {
type: 'line',
data,
options: sys.__v0['グラフオプション']
options: sys.__getSysVar('グラフオプション')
}
return sys.__exec('グラフ描画', [d, sys])
}
Expand All @@ -59,7 +59,7 @@ export default {
fn: async function (data: any, sys: any) {
// グラフオプションの差分作成
const gopt = Object.assign({},
sys.__v0['グラフオプション'],
sys.__getSysVar('グラフオプション'),
{ 'indexAxis': 'x' })
data = sys.__exec('二次元グラフデータ変形', ['bar', data, sys])
const d = {
Expand All @@ -78,7 +78,7 @@ export default {
fn: async function (data: any, sys: any) {
// グラフオプションの差分作成
const gopt = Object.assign({},
sys.__v0['グラフオプション'],
sys.__getSysVar('グラフオプション'),
{ 'indexAxis': 'y' })
data = sys.__exec('二次元グラフデータ変形', ['bar', data, sys])
const d = {
Expand All @@ -96,7 +96,7 @@ export default {
fn: async function (data: any, sys: any) {
// グラフオプションの差分作成
const gopt = Object.assign({},
sys.__v0['グラフオプション'],
sys.__getSysVar('グラフオプション'),
{
'indexAxis': 'x',
'scales': {
Expand All @@ -120,7 +120,7 @@ export default {
fn: async function (data: any, sys: any) {
// グラフオプションの差分作成
const gopt = Object.assign({},
sys.__v0['グラフオプション'],
sys.__getSysVar('グラフオプション'),
{
'indexAxis': 'y',
'scales': {
Expand All @@ -144,7 +144,7 @@ export default {
fn: async function (data: any, sys: any) {
// グラフオプションの差分作成
const gopt = Object.assign({},
sys.__v0['グラフオプション'],
sys.__getSysVar('グラフオプション'),
{})
data = sys.__exec('二次元グラフデータ変形', ['scatter', data, sys])
const d = {
Expand All @@ -164,7 +164,7 @@ export default {
const d = {
type: 'pie',
data,
options: sys.__v0['グラフオプション']
options: sys.__getSysVar('グラフオプション')
}
return sys.__exec('グラフ描画', [d, sys])
}
Expand All @@ -178,7 +178,7 @@ export default {
const d = {
type: 'doughnut',
data,
options: sys.__v0['グラフオプション']
options: sys.__getSysVar('グラフオプション')
}
return sys.__exec('グラフ描画', [d, sys])
}
Expand All @@ -192,7 +192,7 @@ export default {
const d = {
type: 'polarArea',
data,
options: sys.__v0['グラフオプション']
options: sys.__getSysVar('グラフオプション')
}
return sys.__exec('グラフ描画', [d, sys])
}
Expand All @@ -206,7 +206,7 @@ export default {
const d = {
type: 'radar',
data,
options: sys.__v0['グラフオプション']
options: sys.__getSysVar('グラフオプション')
}
return sys.__exec('グラフ描画', [d, sys])
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugin_browser_crypto.mts
Expand Up @@ -17,7 +17,7 @@ export default {
const pad = '00' + h
codes.push(pad.substr(pad.length - 2, 2))
}
const res = sys.__v0['対象'] = codes.join('')
const res = sys.__setSysVar('対象', codes.join(''))
func(res)
})
},
Expand Down
4 changes: 2 additions & 2 deletions src/plugin_browser_dialog.mts
Expand Up @@ -18,7 +18,7 @@ export default {
fn: function (s: any, sys: any) {
const r = window.prompt(s)
if (r === null) {
return sys.__v0['ダイアログキャンセル値']
return sys.__getSysVar('ダイアログキャンセル値')
}
if (/^[-+]?[0-9]+(\.[0-9]+)?$/.test(r)) {
return parseFloat(r)
Expand All @@ -38,7 +38,7 @@ export default {
fn: function (s: any, sys: any) {
const r = window.prompt(s)
if (r === null) {
return sys.__v0['ダイアログキャンセル値']
return sys.__getSysVar('ダイアログキャンセル値')
}
return r
}
Expand Down
12 changes: 6 additions & 6 deletions src/plugin_browser_dom_basic.mts
Expand Up @@ -170,7 +170,7 @@ export default {
pure: true,
fn: function (dom: any, s: any, v: any, sys: any) {
dom = sys.__query(dom, 'DOM属性設定', false)
const wa = sys.__v0['DOM和属性']
const wa = sys.__getSysVar('DOM和属性')
if (wa[s]) { s = wa[s] }
// domのプロパティを確認して存在すればその値を設定する #1392
if (s in dom) {
Expand All @@ -189,7 +189,7 @@ export default {
fn: function (dom: any, s: any, sys: any) {
dom = sys.__query(dom, 'DOM属性取得', true)
if (!dom) { return '' }
const wa = sys.__v0['DOM和属性']
const wa = sys.__getSysVar('DOM和属性')
if (wa[s]) { s = wa[s] }
// domのプロパティを確認して存在すればその値を取得する #1392
if (s in dom) {
Expand Down Expand Up @@ -246,7 +246,7 @@ export default {
pure: true,
fn: function (dom: any, s: any, v: any, sys: any) {
dom = sys.__query(dom, 'DOMスタイル設定', false)
const wa = sys.__v0['DOM和スタイル']
const wa = sys.__getSysVar('DOM和スタイル')
if (wa[s] !== undefined) { s = wa[s] }
if (wa[v] !== undefined) { v = wa[v] }
dom.style[s] = v
Expand All @@ -261,7 +261,7 @@ export default {
fn: function (dom: any, values: any, sys: any) {
dom = sys.__query(dom, 'DOMスタイル一括設定', false)
if (dom instanceof window.HTMLElement) { dom = [dom] }
const wa = sys.__v0['DOM和スタイル']
const wa = sys.__getSysVar('DOM和スタイル')
// 列挙したDOM一覧を全てスタイル変更する
for (let i = 0; i < dom.length; i++) {
const e = dom[i]
Expand All @@ -284,7 +284,7 @@ export default {
fn: function (dom: any, style: any, sys: any) {
dom = sys.__query(dom, 'DOMスタイル取得', true)
if (!dom) { return '' }
const wa = sys.__v0['DOM和スタイル']
const wa = sys.__getSysVar('DOM和スタイル')
if (wa[style]) { style = wa[style] }
return dom.style[style]
}
Expand All @@ -300,7 +300,7 @@ export default {
if (!dom) { return res }
if (style instanceof String) { style = [style] }

const wa = sys.__v0['DOM和スタイル']
const wa = sys.__getSysVar('DOM和スタイル')
if (style instanceof Array) {
style.forEach((key) => {
if (wa[key]) { key = wa[key] }
Expand Down

0 comments on commit 5282ff2

Please sign in to comment.